diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb1c3e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Build output +docker-machine-driver-triton \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..f1981c8 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,75 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +This is a Docker Machine driver for Triton (Joyent's container-native infrastructure). It allows users to create and manage Docker hosts on Triton cloud infrastructure through the `docker-machine` CLI tool. + +## Build and Development Commands + +### Building the Driver +```bash +go build -o docker-machine-driver-triton +``` + +### Installing from Source +```bash +go get -u github.com/TritonDataCenter/docker-machine-driver-triton +export PATH=$PATH:$GOPATH/bin +``` + +### Testing +No specific test framework is configured in this project. Use standard Go testing practices: +```bash +go test ./... +``` + +## Architecture + +### Core Components + +**Main Entry Point** (`main.go:8`): Simple plugin registration that registers the Driver with Docker Machine's plugin system. + +**Driver Implementation** (`driver.go`): Contains the main `Driver` struct that implements the Docker Machine driver interface with these key responsibilities: + +- **Authentication**: Supports multiple auth methods (SSH keys, SSH agent, base64-encoded key material) +- **Instance Management**: Creates, starts, stops, restarts, and removes Triton instances +- **Configuration**: Handles all driver-specific flags and environment variables +- **State Management**: Maps Triton instance states to Docker Machine states + +### Key Driver Methods + +- `Create()` (`driver.go:335`): Provisions new Triton instances with support for tags and metadata +- `GetState()` (`driver.go:594`): Maps Triton states (running, stopped, provisioning, etc.) to Docker Machine states +- `client()` (`driver.go:204`): Creates authenticated Triton API client with flexible auth options +- `PreCreateCheck()` (`driver.go:440`): Validates images and packages before instance creation + +### Configuration Flags + +The driver accepts configuration via CLI flags or environment variables (with `SDC_` prefix for historical reasons): + +**Required:** +- `--triton-account` / `SDC_ACCOUNT`: Triton account username +- `--triton-key-id` / `SDC_KEY_ID`: SSH key fingerprint +- `--triton-url` / `SDC_URL`: CloudAPI endpoint URL + +**Authentication Options:** +- `--triton-key-path` / `SDC_KEY_PATH`: Path to SSH private key +- `--triton-key-material`: Base64-encoded SSH private key content (for Rancher integration) + +**Instance Options:** +- `--triton-image`: VM image (defaults to "debian-8") +- `--triton-package`: Instance size (defaults to "k4-highcpu-kvm-250M") +- `--triton-tags` / `SDC_TAGS`: Comma-separated key=value tags +- `--triton-mdata` / `SDC_MDATA`: Comma-separated key=value metadata + +### Dependencies + +- `github.com/docker/machine`: Docker Machine SDK +- `github.com/TritonDataCenter/triton-go`: Official Triton Go SDK for API interactions +- Go 1.19+ + +## Usage Examples + +See README.md for complete usage examples. The driver integrates with `docker-machine create -d triton` commands. \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2b1b65b..fead2d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ ENV DOCKER_MACHINE_PKG github.com/docker/machine RUN git clone --depth 1 -b "$DOCKER_MACHINE_VERSION" https://$DOCKER_MACHINE_PKG.git "$GOPATH/src/$DOCKER_MACHINE_PKG" \ && go build -v -o "$GOPATH/bin/docker-machine" $DOCKER_MACHINE_PKG/cmd -WORKDIR $GOPATH/src/github.com/joyent/docker-machine-driver-triton +WORKDIR $GOPATH/src/github.com/TritonDataCenter/docker-machine-driver-triton COPY *.go ./ COPY ./vendor/ ./vendor/ diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 136a1b4..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,57 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - branch = "master" - name = "github.com/Azure/go-ansiterm" - packages = [".","winterm"] - revision = "d6e3b3328b783f23731bc4d058875b0371ff8109" - -[[projects]] - name = "github.com/Sirupsen/logrus" - packages = ["."] - revision = "f006c2ac4710855cf0f916dd6b77acf6b048dc6e" - version = "v1.0.3" - -[[projects]] - name = "github.com/docker/docker" - packages = ["pkg/term","pkg/term/windows"] - revision = "092cba3727bb9b4a2f0e922cd6c0f93ea270e363" - version = "v1.13.1" - -[[projects]] - name = "github.com/docker/machine" - packages = ["libmachine/drivers","libmachine/drivers/plugin","libmachine/drivers/plugin/localbinary","libmachine/drivers/rpc","libmachine/engine","libmachine/log","libmachine/mcnflag","libmachine/mcnutils","libmachine/ssh","libmachine/state","libmachine/version","version"] - revision = "9ba6da9ebd1140b65eb73e1ce08086ca72764c60" - version = "v0.13.0" - -[[projects]] - branch = "master" - name = "github.com/hashicorp/errwrap" - packages = ["."] - revision = "7554cd9344cec97297fa6649b055a8c98c2a1e55" - -[[projects]] - name = "github.com/joyent/triton-go" - packages = [".","authentication","client","compute"] - revision = "8f217b9dcc618ec8ca755a027a3666c021dd0d16" - version = "0.2.0" - -[[projects]] - branch = "master" - name = "golang.org/x/crypto" - packages = ["curve25519","ed25519","ed25519/internal/edwards25519","ssh","ssh/agent","ssh/terminal"] - revision = "bd6f299fb381e4c3393d1c4b1f0b94f5e77650c8" - -[[projects]] - branch = "master" - name = "golang.org/x/sys" - packages = ["unix","windows"] - revision = "46eaec7899b1dd945c25db17c78ba3f0c58a6613" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "2bbbf529a5b69f7a9f1df648d303de3c34c17e7fe4bdf1c35951a6a9c31f58f4" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 21878b6..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,38 +0,0 @@ - -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - name = "github.com/docker/machine" - version = "0.13.0" - -[[constraint]] - branch = "master" - name = "github.com/joyent/gocommon" - -[[constraint]] - branch = "master" - name = "github.com/joyent/gosdc" - -[[constraint]] - branch = "master" - name = "github.com/joyent/gosign" diff --git a/README.md b/README.md index 3990b61..ce78232 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ You need a Triton account to use this driver. See [this page](https://www.joyent ## Installation from source To get the code and compile the binary, run: ```bash -go get -u github.com/joyent/docker-machine-driver-triton +go get -u github.com/TritonDataCenter/docker-machine-driver-triton ``` Then put the driver in a directory filled in your PATH environment variable or run: diff --git a/driver.go b/driver.go index 0845210..fdfe75b 100644 --- a/driver.go +++ b/driver.go @@ -2,9 +2,10 @@ package main import ( "context" + "encoding/base64" "encoding/pem" + "errors" "fmt" - "io/ioutil" "os" "strings" "time" @@ -13,11 +14,12 @@ import ( "github.com/docker/machine/libmachine/engine" "github.com/docker/machine/libmachine/log" "github.com/docker/machine/libmachine/mcnflag" + "github.com/docker/machine/libmachine/mcnutils" "github.com/docker/machine/libmachine/state" - "github.com/joyent/triton-go" - auth "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/compute" + "github.com/TritonDataCenter/triton-go" + auth "github.com/TritonDataCenter/triton-go/authentication" + "github.com/TritonDataCenter/triton-go/compute" ) const ( @@ -28,25 +30,36 @@ const ( ) var ( - defaultTritonAccount = "" - defaultTritonKeyPath = "" // os.Getenv("HOME") + "/.ssh/id_rsa" - defaultTritonKeyId = "" - defaultTritonUrl = "https://us-east-1.api.joyent.com" + defaultTritonAccount = "" + defaultTritonActAsAccount = "" + defaultTritonKeyPath = "" // os.Getenv("HOME") + "/.ssh/id_rsa" + defaultTritonKeyId = "" + defaultTritonKeyMaterial = "" + defaultTritonUrl = "" + defaultTritonTags = "" + defaultTritonMdata = "" // https://docs.joyent.com/public-cloud/instances/virtual-machines/images/linux/debian#debian-8 - defaultTritonImage = "debian-8" - defaultTritonPackage = "k4-highcpu-kvm-250M" - defaultSSHUser = "root" + defaultTritonImage = "debian-8" + defaultTritonPackage = "k4-highcpu-kvm-250M" + defaultSSHUser = "root" + defaultTritonTLSInsecure = "false" ) type Driver struct { *drivers.BaseDriver // authentication/access parameters - TritonAccount string - TritonKeyPath string - TritonKeyId string - TritonUrl string + TritonAccount string + TritonActAsAccount string + TritonKeyPath string + TritonKeyMaterial string + TritonKeyMaterialDecoded string + TritonKeyId string + TritonUrl string + TritonTags string + TritonMdata string + TritonTLSInsecure string // machine creation parameters TritonImage string @@ -59,15 +72,34 @@ type Driver struct { // SetConfigFromFlags configures the driver with the object that was returned by RegisterCreateFlags func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error { d.TritonAccount = opts.String(flagPrefix + "account") + d.TritonActAsAccount = opts.String(flagPrefix + "act-as") d.TritonKeyPath = opts.String(flagPrefix + "key-path") + + d.TritonKeyMaterial = opts.String(flagPrefix + "key-material") + + // the --triton-key-material argument has to be base-64 encoded since the raw private SSH key content + // contains new lines and the Rancher node template UI doesn't allow multi-line strings + if d.TritonKeyMaterial != "" { + decodedKey, err := base64.StdEncoding.DecodeString(d.TritonKeyMaterial) + if err != nil { + return fmt.Errorf("%s driver failed to base64 decode %skey-material", driverName, flagPrefix) + } + + d.TritonKeyMaterialDecoded = string(decodedKey) + } + d.TritonKeyId = opts.String(flagPrefix + "key-id") d.TritonUrl = opts.String(flagPrefix + "url") + d.TritonTags = opts.String(flagPrefix + "tags") + d.TritonMdata = opts.String(flagPrefix + "mdata") d.TritonImage = opts.String(flagPrefix + "image") d.TritonPackage = opts.String(flagPrefix + "package") d.SSHUser = opts.String(flagPrefix + "ssh-user") + d.TritonTLSInsecure = opts.String(flagPrefix + "tls-insecure") + d.SetSwarmConfigFromFlags(opts) if d.TritonAccount == "" { @@ -108,6 +140,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag { Usage: "Login name/username", Value: defaultTritonAccount, }, + mcnflag.StringFlag{ + EnvVar: envPrefix + "ACT_AS", + Name: flagPrefix + "act-as", + Usage: "Masquerade as the given account login name.", + Value: defaultTritonActAsAccount, + }, mcnflag.StringFlag{ EnvVar: envPrefix + "KEY_ID", Name: flagPrefix + "key-id", @@ -121,6 +159,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag { Value: defaultTritonKeyPath, }, + mcnflag.StringFlag{ + Name: flagPrefix + "key-material", + Usage: fmt.Sprintf("The SSH private key file content (base64 encoded) that has been added to $%sACCOUNT", envPrefix), + Value: defaultTritonKeyMaterial, + }, mcnflag.StringFlag{ Name: flagPrefix + "image", Usage: `VM image to provision ("debian-8", "debian-8@20150527", "ca291f66", etc)`, @@ -137,6 +180,24 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag { Usage: "Triton SSH user", Value: defaultSSHUser, }, + mcnflag.StringFlag{ + EnvVar: envPrefix + "TLS_INSECURE", + Name: flagPrefix + "tls-insecure", + Usage: "Do not validate the CloudAPI SSL certificate", + Value: defaultTritonTLSInsecure, + }, + mcnflag.StringFlag{ + EnvVar: envPrefix + "TAGS", + Name: flagPrefix + "tags", + Usage: "Tags assigned to the VM", + Value: defaultTritonTags, + }, + mcnflag.StringFlag{ + EnvVar: envPrefix + "MDATA", + Name: flagPrefix + "mdata", + Usage: "Metadata assigned to the VM", + Value: defaultTritonMdata, + }, } } @@ -144,8 +205,30 @@ func (d Driver) client() (*compute.ComputeClient, error) { var signer auth.Signer var err error - if d.TritonKeyPath == "" { - signer, err = auth.NewSSHAgentSigner(d.TritonKeyId, d.TritonAccount) + // For "act as" functionality: determine which account to operate as + var authAccount string + if d.TritonActAsAccount != "" { + authAccount = d.TritonActAsAccount + } else { + authAccount = d.TritonAccount + } + + if d.TritonKeyMaterialDecoded != "" { + signer, err = auth.NewPrivateKeySigner(auth.PrivateKeySignerInput{ + KeyID: d.TritonKeyId, + PrivateKeyMaterial: []byte(d.TritonKeyMaterialDecoded), + AccountName: d.TritonAccount, + // Username: d.TritonAccount, // Commented out - may be causing auth issues + }) + if err != nil { + return nil, fmt.Errorf("error creating SSH private key signer: %s", err) + } + } else if d.TritonKeyPath == "" { + signer, err = auth.NewSSHAgentSigner(auth.SSHAgentSignerInput{ + KeyID: d.TritonKeyId, + AccountName: d.TritonAccount, + // Username: d.TritonAccount, // Commented out - may be causing auth issues + }) if err != nil { return nil, fmt.Errorf("error Creating SSH Agent Signer: %s", err) } @@ -156,7 +239,7 @@ func (d Driver) client() (*compute.ComputeClient, error) { } var keyBytes []byte - keyBytes, err = ioutil.ReadFile(d.TritonKeyPath) + keyBytes, err = os.ReadFile(d.TritonKeyPath) if err != nil { return nil, fmt.Errorf("error reading key material from %s: %s", d.TritonKeyPath, err) @@ -173,7 +256,12 @@ func (d Driver) client() (*compute.ComputeClient, error) { d.TritonKeyPath) } - signer, err = auth.NewPrivateKeySigner(d.TritonKeyId, []byte(d.TritonKeyPath), d.TritonAccount) + signer, err = auth.NewPrivateKeySigner(auth.PrivateKeySignerInput{ + KeyID: d.TritonKeyId, + PrivateKeyMaterial: keyBytes, + AccountName: d.TritonAccount, + // Username: d.TritonAccount, // Commented out - may be causing auth issues + }) if err != nil { return nil, fmt.Errorf("error creating SSH private key signer: %s", err) } @@ -181,11 +269,24 @@ func (d Driver) client() (*compute.ComputeClient, error) { config := &triton.ClientConfig{ TritonURL: d.TritonUrl, - AccountName: d.TritonAccount, + AccountName: authAccount, Signers: []auth.Signer{signer}, } - return compute.NewClient(config) + var client *compute.ComputeClient + client, err = compute.NewClient(config) + + if err != nil { + return nil, fmt.Errorf("error creating ComputeClient: %s", err) + } + + log.Debugf("TritonTLSInsecure=%s", d.TritonTLSInsecure) + + if d.TritonTLSInsecure == "true" { + client.Client.InsecureSkipTLSVerify() + } + + return client, nil } func (d *Driver) getMachine() (*compute.Instance, error) { @@ -208,12 +309,17 @@ func (d *Driver) getMachine() (*compute.Instance, error) { return machine, nil } -func NewDriver(hostName, storePath string) Driver { - return Driver{ - TritonAccount: defaultTritonAccount, - TritonKeyPath: defaultTritonKeyPath, - TritonKeyId: defaultTritonKeyId, - TritonUrl: defaultTritonUrl, +func NewDriver(hostName, storePath string) *Driver { + return &Driver{ + TritonAccount: defaultTritonAccount, + TritonActAsAccount: defaultTritonActAsAccount, + TritonKeyPath: defaultTritonKeyPath, + TritonKeyMaterial: defaultTritonKeyMaterial, + TritonKeyId: defaultTritonKeyId, + TritonUrl: defaultTritonUrl, + TritonTags: defaultTritonTags, + TritonMdata: defaultTritonMdata, + TritonTLSInsecure: defaultTritonTLSInsecure, BaseDriver: &drivers.BaseDriver{ MachineName: hostName, @@ -233,10 +339,52 @@ func (d *Driver) Create() error { return err } + /* If a base64 encoded private key was supplied rather than a path to a key + * then write the decoded key to a file so that Rancher can use it to + * connect to the node after it's been provisioned + */ + if d.TritonKeyMaterialDecoded != "" { + log.Infof("creating SSH key...") + + if err := d.createSSHKey(); err != nil { + return err + } + } + + // parse out tags into a map + var tags map[string]string + if d.TritonTags != "" { + tags = make(map[string]string) + splitTags := strings.Split(d.TritonTags, ",") + for _, tagDefinition := range splitTags { + definitionSplit := strings.SplitN(tagDefinition, "=", 2) + if len(definitionSplit) == 2 { + // remove leading and trailing whitespace from tag key and value + tags[strings.TrimSpace(definitionSplit[0])] = strings.TrimSpace(definitionSplit[1]) + } + } + } + + // parse out metadata into a map + var metadata map[string]string + if d.TritonMdata != "" { + metadata = make(map[string]string) + splitMetadata := strings.Split(d.TritonMdata, ",") + for _, metadataDefinition := range splitMetadata { + definitionSplit := strings.SplitN(metadataDefinition, "=", 2) + if len(definitionSplit) == 2 { + // remove leading and trailing whitespace from tag key and value + metadata[strings.TrimSpace(definitionSplit[0])] = strings.TrimSpace(definitionSplit[1]) + } + } + } + input := &compute.CreateInstanceInput{ - Name: d.MachineName, - Image: d.TritonImage, - Package: d.TritonPackage, + Name: d.MachineName, + Image: d.TritonImage, + Package: d.TritonPackage, + Tags: tags, + Metadata: metadata, } machine, err := c.Instances().Create(context.Background(), input) if err != nil { @@ -245,10 +393,42 @@ func (d *Driver) Create() error { d.TritonMachineId = machine.ID + // assign IPAddress property so that Rancher can SSH to the new instance + log.Info("waiting for ip address to become available") + if err := mcnutils.WaitFor(d.instanceIpAvailable); err != nil { + return err + } + + return nil +} + +func (d *Driver) createSSHKey() error { + + // set SSHKeyPath because rancher accesses the property directly + d.SSHKeyPath = d.GetSSHKeyPath() + + // don't do anything if the key was already written to file + if _, err := os.Stat(d.GetSSHKeyPath()); errors.Is(err, os.ErrNotExist) { + file, err := os.OpenFile(d.GetSSHKeyPath(), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600) + if err != nil { + return err + } + + defer file.Close() + + if _, err := file.Write([]byte(d.TritonKeyMaterialDecoded)); err != nil { + return err + } + + if _, err := file.WriteString("\n"); err != nil { + return err + } + } + return nil } -// https://github.com/joyent/node-triton/blob/aeed6d91922ea117a42eac0cef4a3df67fbfed2f/lib/common.js#L306 +// https://github.com/TritonDataCenter/node-triton/blob/aeed6d91922ea117a42eac0cef4a3df67fbfed2f/lib/common.js#L306 func uuidToShortId(s string) string { return strings.SplitN(s, "-", 2)[0] } @@ -275,7 +455,7 @@ func (d *Driver) PreCreateCheck() error { if err != nil { // apparently isn't a valid ID, but might be a name like "debian-8" (so // let's do a lookup) - // https://github.com/joyent/node-triton/blob/aeed6d91922ea117a42eac0cef4a3df67fbfed2f/lib/tritonapi.js#L368 + // https://github.com/TritonDataCenter/node-triton/blob/aeed6d91922ea117a42eac0cef4a3df67fbfed2f/lib/tritonapi.js#L368 nameVersion := strings.SplitN(d.TritonImage, "@", 2) name, version := nameVersion[0], "" if len(nameVersion) == 2 { @@ -358,6 +538,19 @@ func (d *Driver) GetIP() (string, error) { return machine.PrimaryIP, nil } +func (d *Driver) instanceIpAvailable() bool { + ip, err := d.GetIP() + if err != nil { + log.Debug(err) + } + if ip != "" { + d.IPAddress = ip + log.Infof("got the IP Address: %q", d.IPAddress) + return true + } + return false +} + // GetSSHHostname returns hostname for use with ssh func (d *Driver) GetSSHHostname() (string, error) { return d.GetIP() @@ -379,7 +572,21 @@ func (d *Driver) GetURL() (string, error) { } func (d *Driver) GetSSHKeyPath() string { - return d.TritonKeyPath + var keyPath = d.SSHKeyPath + + if keyPath != "" { + return keyPath + } + + if d.TritonKeyMaterialDecoded != "" { + keyPath = d.ResolveStorePath(fmt.Sprintf("id_rsa_triton_%s", d.TritonAccount)) + } else { + keyPath = d.TritonKeyPath + } + + d.SSHKeyPath = keyPath + + return keyPath } // GetState returns the state that the host is in (running, stopped, etc) @@ -391,7 +598,7 @@ func (d *Driver) GetState() (state.State, error) { return state.Error, err } - // https://github.com/joyent/smartos-live/blob/master/src/vm/man/vmadm.1m.md#vm-states + // https://github.com/TritonDataCenter/smartos-live/blob/master/src/vm/man/vmadm.1m.md#vm-states switch machine.State { case "configured", "provisioning": return state.Starting, nil diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b464bcf --- /dev/null +++ b/go.mod @@ -0,0 +1,21 @@ +module github.com/vrcis/docker-machine-driver-triton + +go 1.19 + +require ( + github.com/TritonDataCenter/triton-go v1.8.6 + github.com/docker/machine v0.13.0 +) + +require ( + github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect + github.com/Sirupsen/logrus v1.0.3 // indirect + github.com/docker/docker v1.13.1 // indirect + github.com/pkg/errors v0.8.1 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/stretchr/testify v1.10.0 // indirect + golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 // indirect + golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect + gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect + gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b67bf8d --- /dev/null +++ b/go.sum @@ -0,0 +1,185 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= +github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/Sirupsen/logrus v1.0.3 h1:XbmgH2T0Ow2lAHu3IwQTqtwD2NgFdIj5notkpw3BpUM= +github.com/Sirupsen/logrus v1.0.3/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U= +github.com/TritonDataCenter/triton-go v1.8.6 h1:xS6laXOG6xLexhk7Gj2BDhwGiXZg7pW1hi+ubfbAd8A= +github.com/TritonDataCenter/triton-go v1.8.6/go.mod h1:aUz67P9QMKt205zf6Jzk7/pCTjlmRqm6PBslnC5mvkQ= +github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af h1:DBNMBMuMiWYu0b+8KMJuWmfCkcxl09JwdlqwDZZ6U14= +github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJMsVxt52+i0Ha45fjshj6wxYr1r19tB9bw= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/docker/docker v1.13.1 h1:IkZjBSIc8hBjLpqeAbeE5mca5mNgeatLHBy3GO78BWo= +github.com/docker/docker v1.13.1/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/machine v0.13.0 h1:qXOQLfafxknrwNNa9PNOLcFFqjb/rid9susqEsl6Xs4= +github.com/docker/machine v0.13.0/go.mod h1:I8mPNDeK1uH+JTcUU7X0ZW8KiYz0jyAgNaeSJ1rCfDI= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ= +github.com/jackc/pgx v3.3.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/olekukonko/tablewriter v0.0.0-20180130162743-b8a9be070da4/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rs/zerolog v1.4.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/sean-/conswriter v0.0.0-20180208195008-f5ae3917a627/go.mod h1:7zjs06qF79/FKAJpBvFx3P8Ww4UTIMAe+lpNXDHziac= +github.com/sean-/pager v0.0.0-20180208200047-666be9bf53b5/go.mod h1:BeybITEsBEg6qbIiqJ6/Bqeq25bCLbL7YFmpaFfJDuM= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo= +gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNjB2u4i700xBkIT4e0= +gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/vendor/github.com/Azure/go-ansiterm/LICENSE b/vendor/github.com/Azure/go-ansiterm/LICENSE deleted file mode 100644 index e3d9a64..0000000 --- a/vendor/github.com/Azure/go-ansiterm/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Microsoft Corporation - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/github.com/Azure/go-ansiterm/README.md b/vendor/github.com/Azure/go-ansiterm/README.md deleted file mode 100644 index 261c041..0000000 --- a/vendor/github.com/Azure/go-ansiterm/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# go-ansiterm - -This is a cross platform Ansi Terminal Emulation library. It reads a stream of Ansi characters and produces the appropriate function calls. The results of the function calls are platform dependent. - -For example the parser might receive "ESC, [, A" as a stream of three characters. This is the code for Cursor Up (http://www.vt100.net/docs/vt510-rm/CUU). The parser then calls the cursor up function (CUU()) on an event handler. The event handler determines what platform specific work must be done to cause the cursor to move up one position. - -The parser (parser.go) is a partial implementation of this state machine (http://vt100.net/emu/vt500_parser.png). There are also two event handler implementations, one for tests (test_event_handler.go) to validate that the expected events are being produced and called, the other is a Windows implementation (winterm/win_event_handler.go). - -See parser_test.go for examples exercising the state machine and generating appropriate function calls. - ------ -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. diff --git a/vendor/github.com/Azure/go-ansiterm/constants.go b/vendor/github.com/Azure/go-ansiterm/constants.go deleted file mode 100644 index 96504a3..0000000 --- a/vendor/github.com/Azure/go-ansiterm/constants.go +++ /dev/null @@ -1,188 +0,0 @@ -package ansiterm - -const LogEnv = "DEBUG_TERMINAL" - -// ANSI constants -// References: -// -- http://www.ecma-international.org/publications/standards/Ecma-048.htm -// -- http://man7.org/linux/man-pages/man4/console_codes.4.html -// -- http://manpages.ubuntu.com/manpages/intrepid/man4/console_codes.4.html -// -- http://en.wikipedia.org/wiki/ANSI_escape_code -// -- http://vt100.net/emu/dec_ansi_parser -// -- http://vt100.net/emu/vt500_parser.svg -// -- http://invisible-island.net/xterm/ctlseqs/ctlseqs.html -// -- http://www.inwap.com/pdp10/ansicode.txt -const ( - // ECMA-48 Set Graphics Rendition - // Note: - // -- Constants leading with an underscore (e.g., _ANSI_xxx) are unsupported or reserved - // -- Fonts could possibly be supported via SetCurrentConsoleFontEx - // -- Windows does not expose the per-window cursor (i.e., caret) blink times - ANSI_SGR_RESET = 0 - ANSI_SGR_BOLD = 1 - ANSI_SGR_DIM = 2 - _ANSI_SGR_ITALIC = 3 - ANSI_SGR_UNDERLINE = 4 - _ANSI_SGR_BLINKSLOW = 5 - _ANSI_SGR_BLINKFAST = 6 - ANSI_SGR_REVERSE = 7 - _ANSI_SGR_INVISIBLE = 8 - _ANSI_SGR_LINETHROUGH = 9 - _ANSI_SGR_FONT_00 = 10 - _ANSI_SGR_FONT_01 = 11 - _ANSI_SGR_FONT_02 = 12 - _ANSI_SGR_FONT_03 = 13 - _ANSI_SGR_FONT_04 = 14 - _ANSI_SGR_FONT_05 = 15 - _ANSI_SGR_FONT_06 = 16 - _ANSI_SGR_FONT_07 = 17 - _ANSI_SGR_FONT_08 = 18 - _ANSI_SGR_FONT_09 = 19 - _ANSI_SGR_FONT_10 = 20 - _ANSI_SGR_DOUBLEUNDERLINE = 21 - ANSI_SGR_BOLD_DIM_OFF = 22 - _ANSI_SGR_ITALIC_OFF = 23 - ANSI_SGR_UNDERLINE_OFF = 24 - _ANSI_SGR_BLINK_OFF = 25 - _ANSI_SGR_RESERVED_00 = 26 - ANSI_SGR_REVERSE_OFF = 27 - _ANSI_SGR_INVISIBLE_OFF = 28 - _ANSI_SGR_LINETHROUGH_OFF = 29 - ANSI_SGR_FOREGROUND_BLACK = 30 - ANSI_SGR_FOREGROUND_RED = 31 - ANSI_SGR_FOREGROUND_GREEN = 32 - ANSI_SGR_FOREGROUND_YELLOW = 33 - ANSI_SGR_FOREGROUND_BLUE = 34 - ANSI_SGR_FOREGROUND_MAGENTA = 35 - ANSI_SGR_FOREGROUND_CYAN = 36 - ANSI_SGR_FOREGROUND_WHITE = 37 - _ANSI_SGR_RESERVED_01 = 38 - ANSI_SGR_FOREGROUND_DEFAULT = 39 - ANSI_SGR_BACKGROUND_BLACK = 40 - ANSI_SGR_BACKGROUND_RED = 41 - ANSI_SGR_BACKGROUND_GREEN = 42 - ANSI_SGR_BACKGROUND_YELLOW = 43 - ANSI_SGR_BACKGROUND_BLUE = 44 - ANSI_SGR_BACKGROUND_MAGENTA = 45 - ANSI_SGR_BACKGROUND_CYAN = 46 - ANSI_SGR_BACKGROUND_WHITE = 47 - _ANSI_SGR_RESERVED_02 = 48 - ANSI_SGR_BACKGROUND_DEFAULT = 49 - // 50 - 65: Unsupported - - ANSI_MAX_CMD_LENGTH = 4096 - - MAX_INPUT_EVENTS = 128 - DEFAULT_WIDTH = 80 - DEFAULT_HEIGHT = 24 - - ANSI_BEL = 0x07 - ANSI_BACKSPACE = 0x08 - ANSI_TAB = 0x09 - ANSI_LINE_FEED = 0x0A - ANSI_VERTICAL_TAB = 0x0B - ANSI_FORM_FEED = 0x0C - ANSI_CARRIAGE_RETURN = 0x0D - ANSI_ESCAPE_PRIMARY = 0x1B - ANSI_ESCAPE_SECONDARY = 0x5B - ANSI_OSC_STRING_ENTRY = 0x5D - ANSI_COMMAND_FIRST = 0x40 - ANSI_COMMAND_LAST = 0x7E - DCS_ENTRY = 0x90 - CSI_ENTRY = 0x9B - OSC_STRING = 0x9D - ANSI_PARAMETER_SEP = ";" - ANSI_CMD_G0 = '(' - ANSI_CMD_G1 = ')' - ANSI_CMD_G2 = '*' - ANSI_CMD_G3 = '+' - ANSI_CMD_DECPNM = '>' - ANSI_CMD_DECPAM = '=' - ANSI_CMD_OSC = ']' - ANSI_CMD_STR_TERM = '\\' - - KEY_CONTROL_PARAM_2 = ";2" - KEY_CONTROL_PARAM_3 = ";3" - KEY_CONTROL_PARAM_4 = ";4" - KEY_CONTROL_PARAM_5 = ";5" - KEY_CONTROL_PARAM_6 = ";6" - KEY_CONTROL_PARAM_7 = ";7" - KEY_CONTROL_PARAM_8 = ";8" - KEY_ESC_CSI = "\x1B[" - KEY_ESC_N = "\x1BN" - KEY_ESC_O = "\x1BO" - - FILL_CHARACTER = ' ' -) - -func getByteRange(start byte, end byte) []byte { - bytes := make([]byte, 0, 32) - for i := start; i <= end; i++ { - bytes = append(bytes, byte(i)) - } - - return bytes -} - -var toGroundBytes = getToGroundBytes() -var executors = getExecuteBytes() - -// SPACE 20+A0 hex Always and everywhere a blank space -// Intermediate 20-2F hex !"#$%&'()*+,-./ -var intermeds = getByteRange(0x20, 0x2F) - -// Parameters 30-3F hex 0123456789:;<=>? -// CSI Parameters 30-39, 3B hex 0123456789; -var csiParams = getByteRange(0x30, 0x3F) - -var csiCollectables = append(getByteRange(0x30, 0x39), getByteRange(0x3B, 0x3F)...) - -// Uppercase 40-5F hex @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ -var upperCase = getByteRange(0x40, 0x5F) - -// Lowercase 60-7E hex `abcdefghijlkmnopqrstuvwxyz{|}~ -var lowerCase = getByteRange(0x60, 0x7E) - -// Alphabetics 40-7E hex (all of upper and lower case) -var alphabetics = append(upperCase, lowerCase...) - -var printables = getByteRange(0x20, 0x7F) - -var escapeIntermediateToGroundBytes = getByteRange(0x30, 0x7E) -var escapeToGroundBytes = getEscapeToGroundBytes() - -// See http://www.vt100.net/emu/vt500_parser.png for description of the complex -// byte ranges below - -func getEscapeToGroundBytes() []byte { - escapeToGroundBytes := getByteRange(0x30, 0x4F) - escapeToGroundBytes = append(escapeToGroundBytes, getByteRange(0x51, 0x57)...) - escapeToGroundBytes = append(escapeToGroundBytes, 0x59) - escapeToGroundBytes = append(escapeToGroundBytes, 0x5A) - escapeToGroundBytes = append(escapeToGroundBytes, 0x5C) - escapeToGroundBytes = append(escapeToGroundBytes, getByteRange(0x60, 0x7E)...) - return escapeToGroundBytes -} - -func getExecuteBytes() []byte { - executeBytes := getByteRange(0x00, 0x17) - executeBytes = append(executeBytes, 0x19) - executeBytes = append(executeBytes, getByteRange(0x1C, 0x1F)...) - return executeBytes -} - -func getToGroundBytes() []byte { - groundBytes := []byte{0x18} - groundBytes = append(groundBytes, 0x1A) - groundBytes = append(groundBytes, getByteRange(0x80, 0x8F)...) - groundBytes = append(groundBytes, getByteRange(0x91, 0x97)...) - groundBytes = append(groundBytes, 0x99) - groundBytes = append(groundBytes, 0x9A) - groundBytes = append(groundBytes, 0x9C) - return groundBytes -} - -// Delete 7F hex Always and everywhere ignored -// C1 Control 80-9F hex 32 additional control characters -// G1 Displayable A1-FE hex 94 additional displayable characters -// Special A0+FF hex Same as SPACE and DELETE diff --git a/vendor/github.com/Azure/go-ansiterm/context.go b/vendor/github.com/Azure/go-ansiterm/context.go deleted file mode 100644 index 8d66e77..0000000 --- a/vendor/github.com/Azure/go-ansiterm/context.go +++ /dev/null @@ -1,7 +0,0 @@ -package ansiterm - -type ansiContext struct { - currentChar byte - paramBuffer []byte - interBuffer []byte -} diff --git a/vendor/github.com/Azure/go-ansiterm/csi_entry_state.go b/vendor/github.com/Azure/go-ansiterm/csi_entry_state.go deleted file mode 100644 index bcbe00d..0000000 --- a/vendor/github.com/Azure/go-ansiterm/csi_entry_state.go +++ /dev/null @@ -1,49 +0,0 @@ -package ansiterm - -type csiEntryState struct { - baseState -} - -func (csiState csiEntryState) Handle(b byte) (s state, e error) { - csiState.parser.logf("CsiEntry::Handle %#x", b) - - nextState, err := csiState.baseState.Handle(b) - if nextState != nil || err != nil { - return nextState, err - } - - switch { - case sliceContains(alphabetics, b): - return csiState.parser.ground, nil - case sliceContains(csiCollectables, b): - return csiState.parser.csiParam, nil - case sliceContains(executors, b): - return csiState, csiState.parser.execute() - } - - return csiState, nil -} - -func (csiState csiEntryState) Transition(s state) error { - csiState.parser.logf("CsiEntry::Transition %s --> %s", csiState.Name(), s.Name()) - csiState.baseState.Transition(s) - - switch s { - case csiState.parser.ground: - return csiState.parser.csiDispatch() - case csiState.parser.csiParam: - switch { - case sliceContains(csiParams, csiState.parser.context.currentChar): - csiState.parser.collectParam() - case sliceContains(intermeds, csiState.parser.context.currentChar): - csiState.parser.collectInter() - } - } - - return nil -} - -func (csiState csiEntryState) Enter() error { - csiState.parser.clear() - return nil -} diff --git a/vendor/github.com/Azure/go-ansiterm/csi_param_state.go b/vendor/github.com/Azure/go-ansiterm/csi_param_state.go deleted file mode 100644 index 7ed5e01..0000000 --- a/vendor/github.com/Azure/go-ansiterm/csi_param_state.go +++ /dev/null @@ -1,38 +0,0 @@ -package ansiterm - -type csiParamState struct { - baseState -} - -func (csiState csiParamState) Handle(b byte) (s state, e error) { - csiState.parser.logf("CsiParam::Handle %#x", b) - - nextState, err := csiState.baseState.Handle(b) - if nextState != nil || err != nil { - return nextState, err - } - - switch { - case sliceContains(alphabetics, b): - return csiState.parser.ground, nil - case sliceContains(csiCollectables, b): - csiState.parser.collectParam() - return csiState, nil - case sliceContains(executors, b): - return csiState, csiState.parser.execute() - } - - return csiState, nil -} - -func (csiState csiParamState) Transition(s state) error { - csiState.parser.logf("CsiParam::Transition %s --> %s", csiState.Name(), s.Name()) - csiState.baseState.Transition(s) - - switch s { - case csiState.parser.ground: - return csiState.parser.csiDispatch() - } - - return nil -} diff --git a/vendor/github.com/Azure/go-ansiterm/escape_intermediate_state.go b/vendor/github.com/Azure/go-ansiterm/escape_intermediate_state.go deleted file mode 100644 index 1c719db..0000000 --- a/vendor/github.com/Azure/go-ansiterm/escape_intermediate_state.go +++ /dev/null @@ -1,36 +0,0 @@ -package ansiterm - -type escapeIntermediateState struct { - baseState -} - -func (escState escapeIntermediateState) Handle(b byte) (s state, e error) { - escState.parser.logf("escapeIntermediateState::Handle %#x", b) - nextState, err := escState.baseState.Handle(b) - if nextState != nil || err != nil { - return nextState, err - } - - switch { - case sliceContains(intermeds, b): - return escState, escState.parser.collectInter() - case sliceContains(executors, b): - return escState, escState.parser.execute() - case sliceContains(escapeIntermediateToGroundBytes, b): - return escState.parser.ground, nil - } - - return escState, nil -} - -func (escState escapeIntermediateState) Transition(s state) error { - escState.parser.logf("escapeIntermediateState::Transition %s --> %s", escState.Name(), s.Name()) - escState.baseState.Transition(s) - - switch s { - case escState.parser.ground: - return escState.parser.escDispatch() - } - - return nil -} diff --git a/vendor/github.com/Azure/go-ansiterm/escape_state.go b/vendor/github.com/Azure/go-ansiterm/escape_state.go deleted file mode 100644 index 6390abd..0000000 --- a/vendor/github.com/Azure/go-ansiterm/escape_state.go +++ /dev/null @@ -1,47 +0,0 @@ -package ansiterm - -type escapeState struct { - baseState -} - -func (escState escapeState) Handle(b byte) (s state, e error) { - escState.parser.logf("escapeState::Handle %#x", b) - nextState, err := escState.baseState.Handle(b) - if nextState != nil || err != nil { - return nextState, err - } - - switch { - case b == ANSI_ESCAPE_SECONDARY: - return escState.parser.csiEntry, nil - case b == ANSI_OSC_STRING_ENTRY: - return escState.parser.oscString, nil - case sliceContains(executors, b): - return escState, escState.parser.execute() - case sliceContains(escapeToGroundBytes, b): - return escState.parser.ground, nil - case sliceContains(intermeds, b): - return escState.parser.escapeIntermediate, nil - } - - return escState, nil -} - -func (escState escapeState) Transition(s state) error { - escState.parser.logf("Escape::Transition %s --> %s", escState.Name(), s.Name()) - escState.baseState.Transition(s) - - switch s { - case escState.parser.ground: - return escState.parser.escDispatch() - case escState.parser.escapeIntermediate: - return escState.parser.collectInter() - } - - return nil -} - -func (escState escapeState) Enter() error { - escState.parser.clear() - return nil -} diff --git a/vendor/github.com/Azure/go-ansiterm/event_handler.go b/vendor/github.com/Azure/go-ansiterm/event_handler.go deleted file mode 100644 index 98087b3..0000000 --- a/vendor/github.com/Azure/go-ansiterm/event_handler.go +++ /dev/null @@ -1,90 +0,0 @@ -package ansiterm - -type AnsiEventHandler interface { - // Print - Print(b byte) error - - // Execute C0 commands - Execute(b byte) error - - // CUrsor Up - CUU(int) error - - // CUrsor Down - CUD(int) error - - // CUrsor Forward - CUF(int) error - - // CUrsor Backward - CUB(int) error - - // Cursor to Next Line - CNL(int) error - - // Cursor to Previous Line - CPL(int) error - - // Cursor Horizontal position Absolute - CHA(int) error - - // Vertical line Position Absolute - VPA(int) error - - // CUrsor Position - CUP(int, int) error - - // Horizontal and Vertical Position (depends on PUM) - HVP(int, int) error - - // Text Cursor Enable Mode - DECTCEM(bool) error - - // Origin Mode - DECOM(bool) error - - // 132 Column Mode - DECCOLM(bool) error - - // Erase in Display - ED(int) error - - // Erase in Line - EL(int) error - - // Insert Line - IL(int) error - - // Delete Line - DL(int) error - - // Insert Character - ICH(int) error - - // Delete Character - DCH(int) error - - // Set Graphics Rendition - SGR([]int) error - - // Pan Down - SU(int) error - - // Pan Up - SD(int) error - - // Device Attributes - DA([]string) error - - // Set Top and Bottom Margins - DECSTBM(int, int) error - - // Index - IND() error - - // Reverse Index - RI() error - - // Flush updates from previous commands - Flush() error -} diff --git a/vendor/github.com/Azure/go-ansiterm/ground_state.go b/vendor/github.com/Azure/go-ansiterm/ground_state.go deleted file mode 100644 index 52451e9..0000000 --- a/vendor/github.com/Azure/go-ansiterm/ground_state.go +++ /dev/null @@ -1,24 +0,0 @@ -package ansiterm - -type groundState struct { - baseState -} - -func (gs groundState) Handle(b byte) (s state, e error) { - gs.parser.context.currentChar = b - - nextState, err := gs.baseState.Handle(b) - if nextState != nil || err != nil { - return nextState, err - } - - switch { - case sliceContains(printables, b): - return gs, gs.parser.print() - - case sliceContains(executors, b): - return gs, gs.parser.execute() - } - - return gs, nil -} diff --git a/vendor/github.com/Azure/go-ansiterm/osc_string_state.go b/vendor/github.com/Azure/go-ansiterm/osc_string_state.go deleted file mode 100644 index 593b10a..0000000 --- a/vendor/github.com/Azure/go-ansiterm/osc_string_state.go +++ /dev/null @@ -1,31 +0,0 @@ -package ansiterm - -type oscStringState struct { - baseState -} - -func (oscState oscStringState) Handle(b byte) (s state, e error) { - oscState.parser.logf("OscString::Handle %#x", b) - nextState, err := oscState.baseState.Handle(b) - if nextState != nil || err != nil { - return nextState, err - } - - switch { - case isOscStringTerminator(b): - return oscState.parser.ground, nil - } - - return oscState, nil -} - -// See below for OSC string terminators for linux -// http://man7.org/linux/man-pages/man4/console_codes.4.html -func isOscStringTerminator(b byte) bool { - - if b == ANSI_BEL || b == 0x5C { - return true - } - - return false -} diff --git a/vendor/github.com/Azure/go-ansiterm/parser.go b/vendor/github.com/Azure/go-ansiterm/parser.go deleted file mode 100644 index 03cec7a..0000000 --- a/vendor/github.com/Azure/go-ansiterm/parser.go +++ /dev/null @@ -1,151 +0,0 @@ -package ansiterm - -import ( - "errors" - "log" - "os" -) - -type AnsiParser struct { - currState state - eventHandler AnsiEventHandler - context *ansiContext - csiEntry state - csiParam state - dcsEntry state - escape state - escapeIntermediate state - error state - ground state - oscString state - stateMap []state - - logf func(string, ...interface{}) -} - -type Option func(*AnsiParser) - -func WithLogf(f func(string, ...interface{})) Option { - return func(ap *AnsiParser) { - ap.logf = f - } -} - -func CreateParser(initialState string, evtHandler AnsiEventHandler, opts ...Option) *AnsiParser { - ap := &AnsiParser{ - eventHandler: evtHandler, - context: &ansiContext{}, - } - for _, o := range opts { - o(ap) - } - - if isDebugEnv := os.Getenv(LogEnv); isDebugEnv == "1" { - logFile, _ := os.Create("ansiParser.log") - logger := log.New(logFile, "", log.LstdFlags) - if ap.logf != nil { - l := ap.logf - ap.logf = func(s string, v ...interface{}) { - l(s, v...) - logger.Printf(s, v...) - } - } else { - ap.logf = logger.Printf - } - } - - if ap.logf == nil { - ap.logf = func(string, ...interface{}) {} - } - - ap.csiEntry = csiEntryState{baseState{name: "CsiEntry", parser: ap}} - ap.csiParam = csiParamState{baseState{name: "CsiParam", parser: ap}} - ap.dcsEntry = dcsEntryState{baseState{name: "DcsEntry", parser: ap}} - ap.escape = escapeState{baseState{name: "Escape", parser: ap}} - ap.escapeIntermediate = escapeIntermediateState{baseState{name: "EscapeIntermediate", parser: ap}} - ap.error = errorState{baseState{name: "Error", parser: ap}} - ap.ground = groundState{baseState{name: "Ground", parser: ap}} - ap.oscString = oscStringState{baseState{name: "OscString", parser: ap}} - - ap.stateMap = []state{ - ap.csiEntry, - ap.csiParam, - ap.dcsEntry, - ap.escape, - ap.escapeIntermediate, - ap.error, - ap.ground, - ap.oscString, - } - - ap.currState = getState(initialState, ap.stateMap) - - ap.logf("CreateParser: parser %p", ap) - return ap -} - -func getState(name string, states []state) state { - for _, el := range states { - if el.Name() == name { - return el - } - } - - return nil -} - -func (ap *AnsiParser) Parse(bytes []byte) (int, error) { - for i, b := range bytes { - if err := ap.handle(b); err != nil { - return i, err - } - } - - return len(bytes), ap.eventHandler.Flush() -} - -func (ap *AnsiParser) handle(b byte) error { - ap.context.currentChar = b - newState, err := ap.currState.Handle(b) - if err != nil { - return err - } - - if newState == nil { - ap.logf("WARNING: newState is nil") - return errors.New("New state of 'nil' is invalid.") - } - - if newState != ap.currState { - if err := ap.changeState(newState); err != nil { - return err - } - } - - return nil -} - -func (ap *AnsiParser) changeState(newState state) error { - ap.logf("ChangeState %s --> %s", ap.currState.Name(), newState.Name()) - - // Exit old state - if err := ap.currState.Exit(); err != nil { - ap.logf("Exit state '%s' failed with : '%v'", ap.currState.Name(), err) - return err - } - - // Perform transition action - if err := ap.currState.Transition(newState); err != nil { - ap.logf("Transition from '%s' to '%s' failed with: '%v'", ap.currState.Name(), newState.Name, err) - return err - } - - // Enter new state - if err := newState.Enter(); err != nil { - ap.logf("Enter state '%s' failed with: '%v'", newState.Name(), err) - return err - } - - ap.currState = newState - return nil -} diff --git a/vendor/github.com/Azure/go-ansiterm/parser_action_helpers.go b/vendor/github.com/Azure/go-ansiterm/parser_action_helpers.go deleted file mode 100644 index de0a1f9..0000000 --- a/vendor/github.com/Azure/go-ansiterm/parser_action_helpers.go +++ /dev/null @@ -1,99 +0,0 @@ -package ansiterm - -import ( - "strconv" -) - -func parseParams(bytes []byte) ([]string, error) { - paramBuff := make([]byte, 0, 0) - params := []string{} - - for _, v := range bytes { - if v == ';' { - if len(paramBuff) > 0 { - // Completed parameter, append it to the list - s := string(paramBuff) - params = append(params, s) - paramBuff = make([]byte, 0, 0) - } - } else { - paramBuff = append(paramBuff, v) - } - } - - // Last parameter may not be terminated with ';' - if len(paramBuff) > 0 { - s := string(paramBuff) - params = append(params, s) - } - - return params, nil -} - -func parseCmd(context ansiContext) (string, error) { - return string(context.currentChar), nil -} - -func getInt(params []string, dflt int) int { - i := getInts(params, 1, dflt)[0] - return i -} - -func getInts(params []string, minCount int, dflt int) []int { - ints := []int{} - - for _, v := range params { - i, _ := strconv.Atoi(v) - // Zero is mapped to the default value in VT100. - if i == 0 { - i = dflt - } - ints = append(ints, i) - } - - if len(ints) < minCount { - remaining := minCount - len(ints) - for i := 0; i < remaining; i++ { - ints = append(ints, dflt) - } - } - - return ints -} - -func (ap *AnsiParser) modeDispatch(param string, set bool) error { - switch param { - case "?3": - return ap.eventHandler.DECCOLM(set) - case "?6": - return ap.eventHandler.DECOM(set) - case "?25": - return ap.eventHandler.DECTCEM(set) - } - return nil -} - -func (ap *AnsiParser) hDispatch(params []string) error { - if len(params) == 1 { - return ap.modeDispatch(params[0], true) - } - - return nil -} - -func (ap *AnsiParser) lDispatch(params []string) error { - if len(params) == 1 { - return ap.modeDispatch(params[0], false) - } - - return nil -} - -func getEraseParam(params []string) int { - param := getInt(params, 0) - if param < 0 || 3 < param { - param = 0 - } - - return param -} diff --git a/vendor/github.com/Azure/go-ansiterm/parser_actions.go b/vendor/github.com/Azure/go-ansiterm/parser_actions.go deleted file mode 100644 index 0bb5e51..0000000 --- a/vendor/github.com/Azure/go-ansiterm/parser_actions.go +++ /dev/null @@ -1,119 +0,0 @@ -package ansiterm - -func (ap *AnsiParser) collectParam() error { - currChar := ap.context.currentChar - ap.logf("collectParam %#x", currChar) - ap.context.paramBuffer = append(ap.context.paramBuffer, currChar) - return nil -} - -func (ap *AnsiParser) collectInter() error { - currChar := ap.context.currentChar - ap.logf("collectInter %#x", currChar) - ap.context.paramBuffer = append(ap.context.interBuffer, currChar) - return nil -} - -func (ap *AnsiParser) escDispatch() error { - cmd, _ := parseCmd(*ap.context) - intermeds := ap.context.interBuffer - ap.logf("escDispatch currentChar: %#x", ap.context.currentChar) - ap.logf("escDispatch: %v(%v)", cmd, intermeds) - - switch cmd { - case "D": // IND - return ap.eventHandler.IND() - case "E": // NEL, equivalent to CRLF - err := ap.eventHandler.Execute(ANSI_CARRIAGE_RETURN) - if err == nil { - err = ap.eventHandler.Execute(ANSI_LINE_FEED) - } - return err - case "M": // RI - return ap.eventHandler.RI() - } - - return nil -} - -func (ap *AnsiParser) csiDispatch() error { - cmd, _ := parseCmd(*ap.context) - params, _ := parseParams(ap.context.paramBuffer) - ap.logf("Parsed params: %v with length: %d", params, len(params)) - - ap.logf("csiDispatch: %v(%v)", cmd, params) - - switch cmd { - case "@": - return ap.eventHandler.ICH(getInt(params, 1)) - case "A": - return ap.eventHandler.CUU(getInt(params, 1)) - case "B": - return ap.eventHandler.CUD(getInt(params, 1)) - case "C": - return ap.eventHandler.CUF(getInt(params, 1)) - case "D": - return ap.eventHandler.CUB(getInt(params, 1)) - case "E": - return ap.eventHandler.CNL(getInt(params, 1)) - case "F": - return ap.eventHandler.CPL(getInt(params, 1)) - case "G": - return ap.eventHandler.CHA(getInt(params, 1)) - case "H": - ints := getInts(params, 2, 1) - x, y := ints[0], ints[1] - return ap.eventHandler.CUP(x, y) - case "J": - param := getEraseParam(params) - return ap.eventHandler.ED(param) - case "K": - param := getEraseParam(params) - return ap.eventHandler.EL(param) - case "L": - return ap.eventHandler.IL(getInt(params, 1)) - case "M": - return ap.eventHandler.DL(getInt(params, 1)) - case "P": - return ap.eventHandler.DCH(getInt(params, 1)) - case "S": - return ap.eventHandler.SU(getInt(params, 1)) - case "T": - return ap.eventHandler.SD(getInt(params, 1)) - case "c": - return ap.eventHandler.DA(params) - case "d": - return ap.eventHandler.VPA(getInt(params, 1)) - case "f": - ints := getInts(params, 2, 1) - x, y := ints[0], ints[1] - return ap.eventHandler.HVP(x, y) - case "h": - return ap.hDispatch(params) - case "l": - return ap.lDispatch(params) - case "m": - return ap.eventHandler.SGR(getInts(params, 1, 0)) - case "r": - ints := getInts(params, 2, 1) - top, bottom := ints[0], ints[1] - return ap.eventHandler.DECSTBM(top, bottom) - default: - ap.logf("ERROR: Unsupported CSI command: '%s', with full context: %v", cmd, ap.context) - return nil - } - -} - -func (ap *AnsiParser) print() error { - return ap.eventHandler.Print(ap.context.currentChar) -} - -func (ap *AnsiParser) clear() error { - ap.context = &ansiContext{} - return nil -} - -func (ap *AnsiParser) execute() error { - return ap.eventHandler.Execute(ap.context.currentChar) -} diff --git a/vendor/github.com/Azure/go-ansiterm/parser_test.go b/vendor/github.com/Azure/go-ansiterm/parser_test.go deleted file mode 100644 index cd4888f..0000000 --- a/vendor/github.com/Azure/go-ansiterm/parser_test.go +++ /dev/null @@ -1,141 +0,0 @@ -package ansiterm - -import ( - "fmt" - "testing" -) - -func TestStateTransitions(t *testing.T) { - stateTransitionHelper(t, "CsiEntry", "Ground", alphabetics) - stateTransitionHelper(t, "CsiEntry", "CsiParam", csiCollectables) - stateTransitionHelper(t, "Escape", "CsiEntry", []byte{ANSI_ESCAPE_SECONDARY}) - stateTransitionHelper(t, "Escape", "OscString", []byte{0x5D}) - stateTransitionHelper(t, "Escape", "Ground", escapeToGroundBytes) - stateTransitionHelper(t, "Escape", "EscapeIntermediate", intermeds) - stateTransitionHelper(t, "EscapeIntermediate", "EscapeIntermediate", intermeds) - stateTransitionHelper(t, "EscapeIntermediate", "EscapeIntermediate", executors) - stateTransitionHelper(t, "EscapeIntermediate", "Ground", escapeIntermediateToGroundBytes) - stateTransitionHelper(t, "OscString", "Ground", []byte{ANSI_BEL}) - stateTransitionHelper(t, "OscString", "Ground", []byte{0x5C}) - stateTransitionHelper(t, "Ground", "Ground", executors) -} - -func TestAnyToX(t *testing.T) { - anyToXHelper(t, []byte{ANSI_ESCAPE_PRIMARY}, "Escape") - anyToXHelper(t, []byte{DCS_ENTRY}, "DcsEntry") - anyToXHelper(t, []byte{OSC_STRING}, "OscString") - anyToXHelper(t, []byte{CSI_ENTRY}, "CsiEntry") - anyToXHelper(t, toGroundBytes, "Ground") -} - -func TestCollectCsiParams(t *testing.T) { - parser, _ := createTestParser("CsiEntry") - parser.Parse(csiCollectables) - - buffer := parser.context.paramBuffer - bufferCount := len(buffer) - - if bufferCount != len(csiCollectables) { - t.Errorf("Buffer: %v", buffer) - t.Errorf("CsiParams: %v", csiCollectables) - t.Errorf("Buffer count failure: %d != %d", bufferCount, len(csiParams)) - return - } - - for i, v := range csiCollectables { - if v != buffer[i] { - t.Errorf("Buffer: %v", buffer) - t.Errorf("CsiParams: %v", csiParams) - t.Errorf("Mismatch at buffer[%d] = %d", i, buffer[i]) - } - } -} - -func TestParseParams(t *testing.T) { - parseParamsHelper(t, []byte{}, []string{}) - parseParamsHelper(t, []byte{';'}, []string{}) - parseParamsHelper(t, []byte{';', ';'}, []string{}) - parseParamsHelper(t, []byte{'7'}, []string{"7"}) - parseParamsHelper(t, []byte{'7', ';'}, []string{"7"}) - parseParamsHelper(t, []byte{'7', ';', ';'}, []string{"7"}) - parseParamsHelper(t, []byte{'7', ';', ';', '8'}, []string{"7", "8"}) - parseParamsHelper(t, []byte{'7', ';', '8', ';'}, []string{"7", "8"}) - parseParamsHelper(t, []byte{'7', ';', ';', '8', ';', ';'}, []string{"7", "8"}) - parseParamsHelper(t, []byte{'7', '8'}, []string{"78"}) - parseParamsHelper(t, []byte{'7', '8', ';'}, []string{"78"}) - parseParamsHelper(t, []byte{'7', '8', ';', '9', '0'}, []string{"78", "90"}) - parseParamsHelper(t, []byte{'7', '8', ';', ';', '9', '0'}, []string{"78", "90"}) - parseParamsHelper(t, []byte{'7', '8', ';', '9', '0', ';'}, []string{"78", "90"}) - parseParamsHelper(t, []byte{'7', '8', ';', '9', '0', ';', ';'}, []string{"78", "90"}) -} - -func TestCursor(t *testing.T) { - cursorSingleParamHelper(t, 'A', "CUU") - cursorSingleParamHelper(t, 'B', "CUD") - cursorSingleParamHelper(t, 'C', "CUF") - cursorSingleParamHelper(t, 'D', "CUB") - cursorSingleParamHelper(t, 'E', "CNL") - cursorSingleParamHelper(t, 'F', "CPL") - cursorSingleParamHelper(t, 'G', "CHA") - cursorTwoParamHelper(t, 'H', "CUP") - cursorTwoParamHelper(t, 'f', "HVP") - funcCallParamHelper(t, []byte{'?', '2', '5', 'h'}, "CsiEntry", "Ground", []string{"DECTCEM([true])"}) - funcCallParamHelper(t, []byte{'?', '2', '5', 'l'}, "CsiEntry", "Ground", []string{"DECTCEM([false])"}) -} - -func TestErase(t *testing.T) { - // Erase in Display - eraseHelper(t, 'J', "ED") - - // Erase in Line - eraseHelper(t, 'K', "EL") -} - -func TestSelectGraphicRendition(t *testing.T) { - funcCallParamHelper(t, []byte{'m'}, "CsiEntry", "Ground", []string{"SGR([0])"}) - funcCallParamHelper(t, []byte{'0', 'm'}, "CsiEntry", "Ground", []string{"SGR([0])"}) - funcCallParamHelper(t, []byte{'0', ';', '1', 'm'}, "CsiEntry", "Ground", []string{"SGR([0 1])"}) - funcCallParamHelper(t, []byte{'0', ';', '1', ';', '2', 'm'}, "CsiEntry", "Ground", []string{"SGR([0 1 2])"}) -} - -func TestScroll(t *testing.T) { - scrollHelper(t, 'S', "SU") - scrollHelper(t, 'T', "SD") -} - -func TestPrint(t *testing.T) { - parser, evtHandler := createTestParser("Ground") - parser.Parse(printables) - validateState(t, parser.currState, "Ground") - - for i, v := range printables { - expectedCall := fmt.Sprintf("Print([%s])", string(v)) - actualCall := evtHandler.FunctionCalls[i] - if actualCall != expectedCall { - t.Errorf("Actual != Expected: %v != %v at %d", actualCall, expectedCall, i) - } - } -} - -func TestClear(t *testing.T) { - p, _ := createTestParser("Ground") - fillContext(p.context) - p.clear() - validateEmptyContext(t, p.context) -} - -func TestClearOnStateChange(t *testing.T) { - clearOnStateChangeHelper(t, "Ground", "Escape", []byte{ANSI_ESCAPE_PRIMARY}) - clearOnStateChangeHelper(t, "Ground", "CsiEntry", []byte{CSI_ENTRY}) -} - -func TestC0(t *testing.T) { - expectedCall := "Execute([" + string(ANSI_LINE_FEED) + "])" - c0Helper(t, []byte{ANSI_LINE_FEED}, "Ground", []string{expectedCall}) - expectedCall = "Execute([" + string(ANSI_CARRIAGE_RETURN) + "])" - c0Helper(t, []byte{ANSI_CARRIAGE_RETURN}, "Ground", []string{expectedCall}) -} - -func TestEscDispatch(t *testing.T) { - funcCallParamHelper(t, []byte{'M'}, "Escape", "Ground", []string{"RI([])"}) -} diff --git a/vendor/github.com/Azure/go-ansiterm/parser_test_helpers_test.go b/vendor/github.com/Azure/go-ansiterm/parser_test_helpers_test.go deleted file mode 100644 index 562f215..0000000 --- a/vendor/github.com/Azure/go-ansiterm/parser_test_helpers_test.go +++ /dev/null @@ -1,114 +0,0 @@ -package ansiterm - -import ( - "fmt" - "testing" -) - -func getStateNames() []string { - parser, _ := createTestParser("Ground") - - stateNames := []string{} - for _, state := range parser.stateMap { - stateNames = append(stateNames, state.Name()) - } - - return stateNames -} - -func stateTransitionHelper(t *testing.T, start string, end string, bytes []byte) { - for _, b := range bytes { - bytes := []byte{byte(b)} - parser, _ := createTestParser(start) - parser.Parse(bytes) - validateState(t, parser.currState, end) - } -} - -func anyToXHelper(t *testing.T, bytes []byte, expectedState string) { - for _, s := range getStateNames() { - stateTransitionHelper(t, s, expectedState, bytes) - } -} - -func funcCallParamHelper(t *testing.T, bytes []byte, start string, expected string, expectedCalls []string) { - parser, evtHandler := createTestParser(start) - parser.Parse(bytes) - validateState(t, parser.currState, expected) - validateFuncCalls(t, evtHandler.FunctionCalls, expectedCalls) -} - -func parseParamsHelper(t *testing.T, bytes []byte, expectedParams []string) { - params, err := parseParams(bytes) - - if err != nil { - t.Errorf("Parameter parse error: %v", err) - return - } - - if len(params) != len(expectedParams) { - t.Errorf("Parsed parameters: %v", params) - t.Errorf("Expected parameters: %v", expectedParams) - t.Errorf("Parameter length failure: %d != %d", len(params), len(expectedParams)) - return - } - - for i, v := range expectedParams { - if v != params[i] { - t.Errorf("Parsed parameters: %v", params) - t.Errorf("Expected parameters: %v", expectedParams) - t.Errorf("Parameter parse failure: %s != %s at position %d", v, params[i], i) - } - } -} - -func cursorSingleParamHelper(t *testing.T, command byte, funcName string) { - funcCallParamHelper(t, []byte{command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)}) - funcCallParamHelper(t, []byte{'0', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)}) - funcCallParamHelper(t, []byte{'2', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2])", funcName)}) - funcCallParamHelper(t, []byte{'2', '3', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([23])", funcName)}) - funcCallParamHelper(t, []byte{'2', ';', '3', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2])", funcName)}) - funcCallParamHelper(t, []byte{'2', ';', '3', ';', '4', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2])", funcName)}) -} - -func cursorTwoParamHelper(t *testing.T, command byte, funcName string) { - funcCallParamHelper(t, []byte{command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1 1])", funcName)}) - funcCallParamHelper(t, []byte{'0', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1 1])", funcName)}) - funcCallParamHelper(t, []byte{'2', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2 1])", funcName)}) - funcCallParamHelper(t, []byte{'2', '3', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([23 1])", funcName)}) - funcCallParamHelper(t, []byte{'2', ';', '3', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2 3])", funcName)}) - funcCallParamHelper(t, []byte{'2', ';', '3', ';', '4', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2 3])", funcName)}) -} - -func eraseHelper(t *testing.T, command byte, funcName string) { - funcCallParamHelper(t, []byte{command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([0])", funcName)}) - funcCallParamHelper(t, []byte{'0', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([0])", funcName)}) - funcCallParamHelper(t, []byte{'1', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)}) - funcCallParamHelper(t, []byte{'2', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2])", funcName)}) - funcCallParamHelper(t, []byte{'3', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([3])", funcName)}) - funcCallParamHelper(t, []byte{'4', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([0])", funcName)}) - funcCallParamHelper(t, []byte{'1', ';', '2', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)}) -} - -func scrollHelper(t *testing.T, command byte, funcName string) { - funcCallParamHelper(t, []byte{command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)}) - funcCallParamHelper(t, []byte{'0', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)}) - funcCallParamHelper(t, []byte{'1', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)}) - funcCallParamHelper(t, []byte{'5', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([5])", funcName)}) - funcCallParamHelper(t, []byte{'4', ';', '6', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([4])", funcName)}) -} - -func clearOnStateChangeHelper(t *testing.T, start string, end string, bytes []byte) { - p, _ := createTestParser(start) - fillContext(p.context) - p.Parse(bytes) - validateState(t, p.currState, end) - validateEmptyContext(t, p.context) -} - -func c0Helper(t *testing.T, bytes []byte, expectedState string, expectedCalls []string) { - parser, evtHandler := createTestParser("Ground") - parser.Parse(bytes) - validateState(t, parser.currState, expectedState) - validateFuncCalls(t, evtHandler.FunctionCalls, expectedCalls) -} diff --git a/vendor/github.com/Azure/go-ansiterm/parser_test_utilities_test.go b/vendor/github.com/Azure/go-ansiterm/parser_test_utilities_test.go deleted file mode 100644 index 78b885c..0000000 --- a/vendor/github.com/Azure/go-ansiterm/parser_test_utilities_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package ansiterm - -import ( - "testing" -) - -func createTestParser(s string) (*AnsiParser, *TestAnsiEventHandler) { - evtHandler := CreateTestAnsiEventHandler() - parser := CreateParser(s, evtHandler) - - return parser, evtHandler -} - -func validateState(t *testing.T, actualState state, expectedStateName string) { - actualName := "Nil" - - if actualState != nil { - actualName = actualState.Name() - } - - if actualName != expectedStateName { - t.Errorf("Invalid state: '%s' != '%s'", actualName, expectedStateName) - } -} - -func validateFuncCalls(t *testing.T, actualCalls []string, expectedCalls []string) { - actualCount := len(actualCalls) - expectedCount := len(expectedCalls) - - if actualCount != expectedCount { - t.Errorf("Actual calls: %v", actualCalls) - t.Errorf("Expected calls: %v", expectedCalls) - t.Errorf("Call count error: %d != %d", actualCount, expectedCount) - return - } - - for i, v := range actualCalls { - if v != expectedCalls[i] { - t.Errorf("Actual calls: %v", actualCalls) - t.Errorf("Expected calls: %v", expectedCalls) - t.Errorf("Mismatched calls: %s != %s with lengths %d and %d", v, expectedCalls[i], len(v), len(expectedCalls[i])) - } - } -} - -func fillContext(context *ansiContext) { - context.currentChar = 'A' - context.paramBuffer = []byte{'C', 'D', 'E'} - context.interBuffer = []byte{'F', 'G', 'H'} -} - -func validateEmptyContext(t *testing.T, context *ansiContext) { - var expectedCurrChar byte = 0x0 - if context.currentChar != expectedCurrChar { - t.Errorf("Currentchar mismatch '%#x' != '%#x'", context.currentChar, expectedCurrChar) - } - - if len(context.paramBuffer) != 0 { - t.Errorf("Non-empty parameter buffer: %v", context.paramBuffer) - } - - if len(context.paramBuffer) != 0 { - t.Errorf("Non-empty intermediate buffer: %v", context.interBuffer) - } - -} diff --git a/vendor/github.com/Azure/go-ansiterm/states.go b/vendor/github.com/Azure/go-ansiterm/states.go deleted file mode 100644 index f2ea1fc..0000000 --- a/vendor/github.com/Azure/go-ansiterm/states.go +++ /dev/null @@ -1,71 +0,0 @@ -package ansiterm - -type stateID int - -type state interface { - Enter() error - Exit() error - Handle(byte) (state, error) - Name() string - Transition(state) error -} - -type baseState struct { - name string - parser *AnsiParser -} - -func (base baseState) Enter() error { - return nil -} - -func (base baseState) Exit() error { - return nil -} - -func (base baseState) Handle(b byte) (s state, e error) { - - switch { - case b == CSI_ENTRY: - return base.parser.csiEntry, nil - case b == DCS_ENTRY: - return base.parser.dcsEntry, nil - case b == ANSI_ESCAPE_PRIMARY: - return base.parser.escape, nil - case b == OSC_STRING: - return base.parser.oscString, nil - case sliceContains(toGroundBytes, b): - return base.parser.ground, nil - } - - return nil, nil -} - -func (base baseState) Name() string { - return base.name -} - -func (base baseState) Transition(s state) error { - if s == base.parser.ground { - execBytes := []byte{0x18} - execBytes = append(execBytes, 0x1A) - execBytes = append(execBytes, getByteRange(0x80, 0x8F)...) - execBytes = append(execBytes, getByteRange(0x91, 0x97)...) - execBytes = append(execBytes, 0x99) - execBytes = append(execBytes, 0x9A) - - if sliceContains(execBytes, base.parser.context.currentChar) { - return base.parser.execute() - } - } - - return nil -} - -type dcsEntryState struct { - baseState -} - -type errorState struct { - baseState -} diff --git a/vendor/github.com/Azure/go-ansiterm/test_event_handler_test.go b/vendor/github.com/Azure/go-ansiterm/test_event_handler_test.go deleted file mode 100644 index 60f9f30..0000000 --- a/vendor/github.com/Azure/go-ansiterm/test_event_handler_test.go +++ /dev/null @@ -1,173 +0,0 @@ -package ansiterm - -import ( - "fmt" - "strconv" -) - -type TestAnsiEventHandler struct { - FunctionCalls []string -} - -func CreateTestAnsiEventHandler() *TestAnsiEventHandler { - evtHandler := TestAnsiEventHandler{} - evtHandler.FunctionCalls = make([]string, 0) - return &evtHandler -} - -func (h *TestAnsiEventHandler) recordCall(call string, params []string) { - s := fmt.Sprintf("%s(%v)", call, params) - h.FunctionCalls = append(h.FunctionCalls, s) -} - -func (h *TestAnsiEventHandler) Print(b byte) error { - h.recordCall("Print", []string{string(b)}) - return nil -} - -func (h *TestAnsiEventHandler) Execute(b byte) error { - h.recordCall("Execute", []string{string(b)}) - return nil -} - -func (h *TestAnsiEventHandler) CUU(param int) error { - h.recordCall("CUU", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) CUD(param int) error { - h.recordCall("CUD", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) CUF(param int) error { - h.recordCall("CUF", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) CUB(param int) error { - h.recordCall("CUB", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) CNL(param int) error { - h.recordCall("CNL", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) CPL(param int) error { - h.recordCall("CPL", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) CHA(param int) error { - h.recordCall("CHA", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) VPA(param int) error { - h.recordCall("VPA", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) CUP(x int, y int) error { - xS, yS := strconv.Itoa(x), strconv.Itoa(y) - h.recordCall("CUP", []string{xS, yS}) - return nil -} - -func (h *TestAnsiEventHandler) HVP(x int, y int) error { - xS, yS := strconv.Itoa(x), strconv.Itoa(y) - h.recordCall("HVP", []string{xS, yS}) - return nil -} - -func (h *TestAnsiEventHandler) DECTCEM(visible bool) error { - h.recordCall("DECTCEM", []string{strconv.FormatBool(visible)}) - return nil -} - -func (h *TestAnsiEventHandler) DECOM(visible bool) error { - h.recordCall("DECOM", []string{strconv.FormatBool(visible)}) - return nil -} - -func (h *TestAnsiEventHandler) DECCOLM(use132 bool) error { - h.recordCall("DECOLM", []string{strconv.FormatBool(use132)}) - return nil -} - -func (h *TestAnsiEventHandler) ED(param int) error { - h.recordCall("ED", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) EL(param int) error { - h.recordCall("EL", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) IL(param int) error { - h.recordCall("IL", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) DL(param int) error { - h.recordCall("DL", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) ICH(param int) error { - h.recordCall("ICH", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) DCH(param int) error { - h.recordCall("DCH", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) SGR(params []int) error { - strings := []string{} - for _, v := range params { - strings = append(strings, strconv.Itoa(v)) - } - - h.recordCall("SGR", strings) - return nil -} - -func (h *TestAnsiEventHandler) SU(param int) error { - h.recordCall("SU", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) SD(param int) error { - h.recordCall("SD", []string{strconv.Itoa(param)}) - return nil -} - -func (h *TestAnsiEventHandler) DA(params []string) error { - h.recordCall("DA", params) - return nil -} - -func (h *TestAnsiEventHandler) DECSTBM(top int, bottom int) error { - topS, bottomS := strconv.Itoa(top), strconv.Itoa(bottom) - h.recordCall("DECSTBM", []string{topS, bottomS}) - return nil -} - -func (h *TestAnsiEventHandler) RI() error { - h.recordCall("RI", nil) - return nil -} - -func (h *TestAnsiEventHandler) IND() error { - h.recordCall("IND", nil) - return nil -} - -func (h *TestAnsiEventHandler) Flush() error { - return nil -} diff --git a/vendor/github.com/Azure/go-ansiterm/utilities.go b/vendor/github.com/Azure/go-ansiterm/utilities.go deleted file mode 100644 index 3921144..0000000 --- a/vendor/github.com/Azure/go-ansiterm/utilities.go +++ /dev/null @@ -1,21 +0,0 @@ -package ansiterm - -import ( - "strconv" -) - -func sliceContains(bytes []byte, b byte) bool { - for _, v := range bytes { - if v == b { - return true - } - } - - return false -} - -func convertBytesToInteger(bytes []byte) int { - s := string(bytes) - i, _ := strconv.Atoi(s) - return i -} diff --git a/vendor/github.com/Azure/go-ansiterm/winterm/ansi.go b/vendor/github.com/Azure/go-ansiterm/winterm/ansi.go deleted file mode 100644 index a673279..0000000 --- a/vendor/github.com/Azure/go-ansiterm/winterm/ansi.go +++ /dev/null @@ -1,182 +0,0 @@ -// +build windows - -package winterm - -import ( - "fmt" - "os" - "strconv" - "strings" - "syscall" - - "github.com/Azure/go-ansiterm" -) - -// Windows keyboard constants -// See https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx. -const ( - VK_PRIOR = 0x21 // PAGE UP key - VK_NEXT = 0x22 // PAGE DOWN key - VK_END = 0x23 // END key - VK_HOME = 0x24 // HOME key - VK_LEFT = 0x25 // LEFT ARROW key - VK_UP = 0x26 // UP ARROW key - VK_RIGHT = 0x27 // RIGHT ARROW key - VK_DOWN = 0x28 // DOWN ARROW key - VK_SELECT = 0x29 // SELECT key - VK_PRINT = 0x2A // PRINT key - VK_EXECUTE = 0x2B // EXECUTE key - VK_SNAPSHOT = 0x2C // PRINT SCREEN key - VK_INSERT = 0x2D // INS key - VK_DELETE = 0x2E // DEL key - VK_HELP = 0x2F // HELP key - VK_F1 = 0x70 // F1 key - VK_F2 = 0x71 // F2 key - VK_F3 = 0x72 // F3 key - VK_F4 = 0x73 // F4 key - VK_F5 = 0x74 // F5 key - VK_F6 = 0x75 // F6 key - VK_F7 = 0x76 // F7 key - VK_F8 = 0x77 // F8 key - VK_F9 = 0x78 // F9 key - VK_F10 = 0x79 // F10 key - VK_F11 = 0x7A // F11 key - VK_F12 = 0x7B // F12 key - - RIGHT_ALT_PRESSED = 0x0001 - LEFT_ALT_PRESSED = 0x0002 - RIGHT_CTRL_PRESSED = 0x0004 - LEFT_CTRL_PRESSED = 0x0008 - SHIFT_PRESSED = 0x0010 - NUMLOCK_ON = 0x0020 - SCROLLLOCK_ON = 0x0040 - CAPSLOCK_ON = 0x0080 - ENHANCED_KEY = 0x0100 -) - -type ansiCommand struct { - CommandBytes []byte - Command string - Parameters []string - IsSpecial bool -} - -func newAnsiCommand(command []byte) *ansiCommand { - - if isCharacterSelectionCmdChar(command[1]) { - // Is Character Set Selection commands - return &ansiCommand{ - CommandBytes: command, - Command: string(command), - IsSpecial: true, - } - } - - // last char is command character - lastCharIndex := len(command) - 1 - - ac := &ansiCommand{ - CommandBytes: command, - Command: string(command[lastCharIndex]), - IsSpecial: false, - } - - // more than a single escape - if lastCharIndex != 0 { - start := 1 - // skip if double char escape sequence - if command[0] == ansiterm.ANSI_ESCAPE_PRIMARY && command[1] == ansiterm.ANSI_ESCAPE_SECONDARY { - start++ - } - // convert this to GetNextParam method - ac.Parameters = strings.Split(string(command[start:lastCharIndex]), ansiterm.ANSI_PARAMETER_SEP) - } - - return ac -} - -func (ac *ansiCommand) paramAsSHORT(index int, defaultValue int16) int16 { - if index < 0 || index >= len(ac.Parameters) { - return defaultValue - } - - param, err := strconv.ParseInt(ac.Parameters[index], 10, 16) - if err != nil { - return defaultValue - } - - return int16(param) -} - -func (ac *ansiCommand) String() string { - return fmt.Sprintf("0x%v \"%v\" (\"%v\")", - bytesToHex(ac.CommandBytes), - ac.Command, - strings.Join(ac.Parameters, "\",\"")) -} - -// isAnsiCommandChar returns true if the passed byte falls within the range of ANSI commands. -// See http://manpages.ubuntu.com/manpages/intrepid/man4/console_codes.4.html. -func isAnsiCommandChar(b byte) bool { - switch { - case ansiterm.ANSI_COMMAND_FIRST <= b && b <= ansiterm.ANSI_COMMAND_LAST && b != ansiterm.ANSI_ESCAPE_SECONDARY: - return true - case b == ansiterm.ANSI_CMD_G1 || b == ansiterm.ANSI_CMD_OSC || b == ansiterm.ANSI_CMD_DECPAM || b == ansiterm.ANSI_CMD_DECPNM: - // non-CSI escape sequence terminator - return true - case b == ansiterm.ANSI_CMD_STR_TERM || b == ansiterm.ANSI_BEL: - // String escape sequence terminator - return true - } - return false -} - -func isXtermOscSequence(command []byte, current byte) bool { - return (len(command) >= 2 && command[0] == ansiterm.ANSI_ESCAPE_PRIMARY && command[1] == ansiterm.ANSI_CMD_OSC && current != ansiterm.ANSI_BEL) -} - -func isCharacterSelectionCmdChar(b byte) bool { - return (b == ansiterm.ANSI_CMD_G0 || b == ansiterm.ANSI_CMD_G1 || b == ansiterm.ANSI_CMD_G2 || b == ansiterm.ANSI_CMD_G3) -} - -// bytesToHex converts a slice of bytes to a human-readable string. -func bytesToHex(b []byte) string { - hex := make([]string, len(b)) - for i, ch := range b { - hex[i] = fmt.Sprintf("%X", ch) - } - return strings.Join(hex, "") -} - -// ensureInRange adjusts the passed value, if necessary, to ensure it is within -// the passed min / max range. -func ensureInRange(n int16, min int16, max int16) int16 { - if n < min { - return min - } else if n > max { - return max - } else { - return n - } -} - -func GetStdFile(nFile int) (*os.File, uintptr) { - var file *os.File - switch nFile { - case syscall.STD_INPUT_HANDLE: - file = os.Stdin - case syscall.STD_OUTPUT_HANDLE: - file = os.Stdout - case syscall.STD_ERROR_HANDLE: - file = os.Stderr - default: - panic(fmt.Errorf("Invalid standard handle identifier: %v", nFile)) - } - - fd, err := syscall.GetStdHandle(nFile) - if err != nil { - panic(fmt.Errorf("Invalid standard handle identifier: %v -- %v", nFile, err)) - } - - return file, uintptr(fd) -} diff --git a/vendor/github.com/Azure/go-ansiterm/winterm/api.go b/vendor/github.com/Azure/go-ansiterm/winterm/api.go deleted file mode 100644 index 6055e33..0000000 --- a/vendor/github.com/Azure/go-ansiterm/winterm/api.go +++ /dev/null @@ -1,327 +0,0 @@ -// +build windows - -package winterm - -import ( - "fmt" - "syscall" - "unsafe" -) - -//=========================================================================================================== -// IMPORTANT NOTE: -// -// The methods below make extensive use of the "unsafe" package to obtain the required pointers. -// Beginning in Go 1.3, the garbage collector may release local variables (e.g., incoming arguments, stack -// variables) the pointers reference *before* the API completes. -// -// As a result, in those cases, the code must hint that the variables remain in active by invoking the -// dummy method "use" (see below). Newer versions of Go are planned to change the mechanism to no longer -// require unsafe pointers. -// -// If you add or modify methods, ENSURE protection of local variables through the "use" builtin to inform -// the garbage collector the variables remain in use if: -// -// -- The value is not a pointer (e.g., int32, struct) -// -- The value is not referenced by the method after passing the pointer to Windows -// -// See http://golang.org/doc/go1.3. -//=========================================================================================================== - -var ( - kernel32DLL = syscall.NewLazyDLL("kernel32.dll") - - getConsoleCursorInfoProc = kernel32DLL.NewProc("GetConsoleCursorInfo") - setConsoleCursorInfoProc = kernel32DLL.NewProc("SetConsoleCursorInfo") - setConsoleCursorPositionProc = kernel32DLL.NewProc("SetConsoleCursorPosition") - setConsoleModeProc = kernel32DLL.NewProc("SetConsoleMode") - getConsoleScreenBufferInfoProc = kernel32DLL.NewProc("GetConsoleScreenBufferInfo") - setConsoleScreenBufferSizeProc = kernel32DLL.NewProc("SetConsoleScreenBufferSize") - scrollConsoleScreenBufferProc = kernel32DLL.NewProc("ScrollConsoleScreenBufferA") - setConsoleTextAttributeProc = kernel32DLL.NewProc("SetConsoleTextAttribute") - setConsoleWindowInfoProc = kernel32DLL.NewProc("SetConsoleWindowInfo") - writeConsoleOutputProc = kernel32DLL.NewProc("WriteConsoleOutputW") - readConsoleInputProc = kernel32DLL.NewProc("ReadConsoleInputW") - waitForSingleObjectProc = kernel32DLL.NewProc("WaitForSingleObject") -) - -// Windows Console constants -const ( - // Console modes - // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx. - ENABLE_PROCESSED_INPUT = 0x0001 - ENABLE_LINE_INPUT = 0x0002 - ENABLE_ECHO_INPUT = 0x0004 - ENABLE_WINDOW_INPUT = 0x0008 - ENABLE_MOUSE_INPUT = 0x0010 - ENABLE_INSERT_MODE = 0x0020 - ENABLE_QUICK_EDIT_MODE = 0x0040 - ENABLE_EXTENDED_FLAGS = 0x0080 - ENABLE_AUTO_POSITION = 0x0100 - ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200 - - ENABLE_PROCESSED_OUTPUT = 0x0001 - ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002 - ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004 - DISABLE_NEWLINE_AUTO_RETURN = 0x0008 - ENABLE_LVB_GRID_WORLDWIDE = 0x0010 - - // Character attributes - // Note: - // -- The attributes are combined to produce various colors (e.g., Blue + Green will create Cyan). - // Clearing all foreground or background colors results in black; setting all creates white. - // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms682088(v=vs.85).aspx#_win32_character_attributes. - FOREGROUND_BLUE uint16 = 0x0001 - FOREGROUND_GREEN uint16 = 0x0002 - FOREGROUND_RED uint16 = 0x0004 - FOREGROUND_INTENSITY uint16 = 0x0008 - FOREGROUND_MASK uint16 = 0x000F - - BACKGROUND_BLUE uint16 = 0x0010 - BACKGROUND_GREEN uint16 = 0x0020 - BACKGROUND_RED uint16 = 0x0040 - BACKGROUND_INTENSITY uint16 = 0x0080 - BACKGROUND_MASK uint16 = 0x00F0 - - COMMON_LVB_MASK uint16 = 0xFF00 - COMMON_LVB_REVERSE_VIDEO uint16 = 0x4000 - COMMON_LVB_UNDERSCORE uint16 = 0x8000 - - // Input event types - // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683499(v=vs.85).aspx. - KEY_EVENT = 0x0001 - MOUSE_EVENT = 0x0002 - WINDOW_BUFFER_SIZE_EVENT = 0x0004 - MENU_EVENT = 0x0008 - FOCUS_EVENT = 0x0010 - - // WaitForSingleObject return codes - WAIT_ABANDONED = 0x00000080 - WAIT_FAILED = 0xFFFFFFFF - WAIT_SIGNALED = 0x0000000 - WAIT_TIMEOUT = 0x00000102 - - // WaitForSingleObject wait duration - WAIT_INFINITE = 0xFFFFFFFF - WAIT_ONE_SECOND = 1000 - WAIT_HALF_SECOND = 500 - WAIT_QUARTER_SECOND = 250 -) - -// Windows API Console types -// -- See https://msdn.microsoft.com/en-us/library/windows/desktop/ms682101(v=vs.85).aspx for Console specific types (e.g., COORD) -// -- See https://msdn.microsoft.com/en-us/library/aa296569(v=vs.60).aspx for comments on alignment -type ( - CHAR_INFO struct { - UnicodeChar uint16 - Attributes uint16 - } - - CONSOLE_CURSOR_INFO struct { - Size uint32 - Visible int32 - } - - CONSOLE_SCREEN_BUFFER_INFO struct { - Size COORD - CursorPosition COORD - Attributes uint16 - Window SMALL_RECT - MaximumWindowSize COORD - } - - COORD struct { - X int16 - Y int16 - } - - SMALL_RECT struct { - Left int16 - Top int16 - Right int16 - Bottom int16 - } - - // INPUT_RECORD is a C/C++ union of which KEY_EVENT_RECORD is one case, it is also the largest - // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683499(v=vs.85).aspx. - INPUT_RECORD struct { - EventType uint16 - KeyEvent KEY_EVENT_RECORD - } - - KEY_EVENT_RECORD struct { - KeyDown int32 - RepeatCount uint16 - VirtualKeyCode uint16 - VirtualScanCode uint16 - UnicodeChar uint16 - ControlKeyState uint32 - } - - WINDOW_BUFFER_SIZE struct { - Size COORD - } -) - -// boolToBOOL converts a Go bool into a Windows int32. -func boolToBOOL(f bool) int32 { - if f { - return int32(1) - } else { - return int32(0) - } -} - -// GetConsoleCursorInfo retrieves information about the size and visiblity of the console cursor. -// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683163(v=vs.85).aspx. -func GetConsoleCursorInfo(handle uintptr, cursorInfo *CONSOLE_CURSOR_INFO) error { - r1, r2, err := getConsoleCursorInfoProc.Call(handle, uintptr(unsafe.Pointer(cursorInfo)), 0) - return checkError(r1, r2, err) -} - -// SetConsoleCursorInfo sets the size and visiblity of the console cursor. -// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686019(v=vs.85).aspx. -func SetConsoleCursorInfo(handle uintptr, cursorInfo *CONSOLE_CURSOR_INFO) error { - r1, r2, err := setConsoleCursorInfoProc.Call(handle, uintptr(unsafe.Pointer(cursorInfo)), 0) - return checkError(r1, r2, err) -} - -// SetConsoleCursorPosition location of the console cursor. -// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686025(v=vs.85).aspx. -func SetConsoleCursorPosition(handle uintptr, coord COORD) error { - r1, r2, err := setConsoleCursorPositionProc.Call(handle, coordToPointer(coord)) - use(coord) - return checkError(r1, r2, err) -} - -// GetConsoleMode gets the console mode for given file descriptor -// See http://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx. -func GetConsoleMode(handle uintptr) (mode uint32, err error) { - err = syscall.GetConsoleMode(syscall.Handle(handle), &mode) - return mode, err -} - -// SetConsoleMode sets the console mode for given file descriptor -// See http://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx. -func SetConsoleMode(handle uintptr, mode uint32) error { - r1, r2, err := setConsoleModeProc.Call(handle, uintptr(mode), 0) - use(mode) - return checkError(r1, r2, err) -} - -// GetConsoleScreenBufferInfo retrieves information about the specified console screen buffer. -// See http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx. -func GetConsoleScreenBufferInfo(handle uintptr) (*CONSOLE_SCREEN_BUFFER_INFO, error) { - info := CONSOLE_SCREEN_BUFFER_INFO{} - err := checkError(getConsoleScreenBufferInfoProc.Call(handle, uintptr(unsafe.Pointer(&info)), 0)) - if err != nil { - return nil, err - } - return &info, nil -} - -func ScrollConsoleScreenBuffer(handle uintptr, scrollRect SMALL_RECT, clipRect SMALL_RECT, destOrigin COORD, char CHAR_INFO) error { - r1, r2, err := scrollConsoleScreenBufferProc.Call(handle, uintptr(unsafe.Pointer(&scrollRect)), uintptr(unsafe.Pointer(&clipRect)), coordToPointer(destOrigin), uintptr(unsafe.Pointer(&char))) - use(scrollRect) - use(clipRect) - use(destOrigin) - use(char) - return checkError(r1, r2, err) -} - -// SetConsoleScreenBufferSize sets the size of the console screen buffer. -// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686044(v=vs.85).aspx. -func SetConsoleScreenBufferSize(handle uintptr, coord COORD) error { - r1, r2, err := setConsoleScreenBufferSizeProc.Call(handle, coordToPointer(coord)) - use(coord) - return checkError(r1, r2, err) -} - -// SetConsoleTextAttribute sets the attributes of characters written to the -// console screen buffer by the WriteFile or WriteConsole function. -// See http://msdn.microsoft.com/en-us/library/windows/desktop/ms686047(v=vs.85).aspx. -func SetConsoleTextAttribute(handle uintptr, attribute uint16) error { - r1, r2, err := setConsoleTextAttributeProc.Call(handle, uintptr(attribute), 0) - use(attribute) - return checkError(r1, r2, err) -} - -// SetConsoleWindowInfo sets the size and position of the console screen buffer's window. -// Note that the size and location must be within and no larger than the backing console screen buffer. -// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686125(v=vs.85).aspx. -func SetConsoleWindowInfo(handle uintptr, isAbsolute bool, rect SMALL_RECT) error { - r1, r2, err := setConsoleWindowInfoProc.Call(handle, uintptr(boolToBOOL(isAbsolute)), uintptr(unsafe.Pointer(&rect))) - use(isAbsolute) - use(rect) - return checkError(r1, r2, err) -} - -// WriteConsoleOutput writes the CHAR_INFOs from the provided buffer to the active console buffer. -// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms687404(v=vs.85).aspx. -func WriteConsoleOutput(handle uintptr, buffer []CHAR_INFO, bufferSize COORD, bufferCoord COORD, writeRegion *SMALL_RECT) error { - r1, r2, err := writeConsoleOutputProc.Call(handle, uintptr(unsafe.Pointer(&buffer[0])), coordToPointer(bufferSize), coordToPointer(bufferCoord), uintptr(unsafe.Pointer(writeRegion))) - use(buffer) - use(bufferSize) - use(bufferCoord) - return checkError(r1, r2, err) -} - -// ReadConsoleInput reads (and removes) data from the console input buffer. -// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms684961(v=vs.85).aspx. -func ReadConsoleInput(handle uintptr, buffer []INPUT_RECORD, count *uint32) error { - r1, r2, err := readConsoleInputProc.Call(handle, uintptr(unsafe.Pointer(&buffer[0])), uintptr(len(buffer)), uintptr(unsafe.Pointer(count))) - use(buffer) - return checkError(r1, r2, err) -} - -// WaitForSingleObject waits for the passed handle to be signaled. -// It returns true if the handle was signaled; false otherwise. -// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx. -func WaitForSingleObject(handle uintptr, msWait uint32) (bool, error) { - r1, _, err := waitForSingleObjectProc.Call(handle, uintptr(uint32(msWait))) - switch r1 { - case WAIT_ABANDONED, WAIT_TIMEOUT: - return false, nil - case WAIT_SIGNALED: - return true, nil - } - use(msWait) - return false, err -} - -// String helpers -func (info CONSOLE_SCREEN_BUFFER_INFO) String() string { - return fmt.Sprintf("Size(%v) Cursor(%v) Window(%v) Max(%v)", info.Size, info.CursorPosition, info.Window, info.MaximumWindowSize) -} - -func (coord COORD) String() string { - return fmt.Sprintf("%v,%v", coord.X, coord.Y) -} - -func (rect SMALL_RECT) String() string { - return fmt.Sprintf("(%v,%v),(%v,%v)", rect.Left, rect.Top, rect.Right, rect.Bottom) -} - -// checkError evaluates the results of a Windows API call and returns the error if it failed. -func checkError(r1, r2 uintptr, err error) error { - // Windows APIs return non-zero to indicate success - if r1 != 0 { - return nil - } - - // Return the error if provided, otherwise default to EINVAL - if err != nil { - return err - } - return syscall.EINVAL -} - -// coordToPointer converts a COORD into a uintptr (by fooling the type system). -func coordToPointer(c COORD) uintptr { - // Note: This code assumes the two SHORTs are correctly laid out; the "cast" to uint32 is just to get a pointer to pass. - return uintptr(*((*uint32)(unsafe.Pointer(&c)))) -} - -// use is a no-op, but the compiler cannot see that it is. -// Calling use(p) ensures that p is kept live until that point. -func use(p interface{}) {} diff --git a/vendor/github.com/Azure/go-ansiterm/winterm/attr_translation.go b/vendor/github.com/Azure/go-ansiterm/winterm/attr_translation.go deleted file mode 100644 index cbec8f7..0000000 --- a/vendor/github.com/Azure/go-ansiterm/winterm/attr_translation.go +++ /dev/null @@ -1,100 +0,0 @@ -// +build windows - -package winterm - -import "github.com/Azure/go-ansiterm" - -const ( - FOREGROUND_COLOR_MASK = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE - BACKGROUND_COLOR_MASK = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE -) - -// collectAnsiIntoWindowsAttributes modifies the passed Windows text mode flags to reflect the -// request represented by the passed ANSI mode. -func collectAnsiIntoWindowsAttributes(windowsMode uint16, inverted bool, baseMode uint16, ansiMode int16) (uint16, bool) { - switch ansiMode { - - // Mode styles - case ansiterm.ANSI_SGR_BOLD: - windowsMode = windowsMode | FOREGROUND_INTENSITY - - case ansiterm.ANSI_SGR_DIM, ansiterm.ANSI_SGR_BOLD_DIM_OFF: - windowsMode &^= FOREGROUND_INTENSITY - - case ansiterm.ANSI_SGR_UNDERLINE: - windowsMode = windowsMode | COMMON_LVB_UNDERSCORE - - case ansiterm.ANSI_SGR_REVERSE: - inverted = true - - case ansiterm.ANSI_SGR_REVERSE_OFF: - inverted = false - - case ansiterm.ANSI_SGR_UNDERLINE_OFF: - windowsMode &^= COMMON_LVB_UNDERSCORE - - // Foreground colors - case ansiterm.ANSI_SGR_FOREGROUND_DEFAULT: - windowsMode = (windowsMode &^ FOREGROUND_MASK) | (baseMode & FOREGROUND_MASK) - - case ansiterm.ANSI_SGR_FOREGROUND_BLACK: - windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) - - case ansiterm.ANSI_SGR_FOREGROUND_RED: - windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_RED - - case ansiterm.ANSI_SGR_FOREGROUND_GREEN: - windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_GREEN - - case ansiterm.ANSI_SGR_FOREGROUND_YELLOW: - windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_RED | FOREGROUND_GREEN - - case ansiterm.ANSI_SGR_FOREGROUND_BLUE: - windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_BLUE - - case ansiterm.ANSI_SGR_FOREGROUND_MAGENTA: - windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_RED | FOREGROUND_BLUE - - case ansiterm.ANSI_SGR_FOREGROUND_CYAN: - windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_GREEN | FOREGROUND_BLUE - - case ansiterm.ANSI_SGR_FOREGROUND_WHITE: - windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE - - // Background colors - case ansiterm.ANSI_SGR_BACKGROUND_DEFAULT: - // Black with no intensity - windowsMode = (windowsMode &^ BACKGROUND_MASK) | (baseMode & BACKGROUND_MASK) - - case ansiterm.ANSI_SGR_BACKGROUND_BLACK: - windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) - - case ansiterm.ANSI_SGR_BACKGROUND_RED: - windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_RED - - case ansiterm.ANSI_SGR_BACKGROUND_GREEN: - windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_GREEN - - case ansiterm.ANSI_SGR_BACKGROUND_YELLOW: - windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_RED | BACKGROUND_GREEN - - case ansiterm.ANSI_SGR_BACKGROUND_BLUE: - windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_BLUE - - case ansiterm.ANSI_SGR_BACKGROUND_MAGENTA: - windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_RED | BACKGROUND_BLUE - - case ansiterm.ANSI_SGR_BACKGROUND_CYAN: - windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_GREEN | BACKGROUND_BLUE - - case ansiterm.ANSI_SGR_BACKGROUND_WHITE: - windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE - } - - return windowsMode, inverted -} - -// invertAttributes inverts the foreground and background colors of a Windows attributes value -func invertAttributes(windowsMode uint16) uint16 { - return (COMMON_LVB_MASK & windowsMode) | ((FOREGROUND_MASK & windowsMode) << 4) | ((BACKGROUND_MASK & windowsMode) >> 4) -} diff --git a/vendor/github.com/Azure/go-ansiterm/winterm/cursor_helpers.go b/vendor/github.com/Azure/go-ansiterm/winterm/cursor_helpers.go deleted file mode 100644 index 3ee06ea..0000000 --- a/vendor/github.com/Azure/go-ansiterm/winterm/cursor_helpers.go +++ /dev/null @@ -1,101 +0,0 @@ -// +build windows - -package winterm - -const ( - horizontal = iota - vertical -) - -func (h *windowsAnsiEventHandler) getCursorWindow(info *CONSOLE_SCREEN_BUFFER_INFO) SMALL_RECT { - if h.originMode { - sr := h.effectiveSr(info.Window) - return SMALL_RECT{ - Top: sr.top, - Bottom: sr.bottom, - Left: 0, - Right: info.Size.X - 1, - } - } else { - return SMALL_RECT{ - Top: info.Window.Top, - Bottom: info.Window.Bottom, - Left: 0, - Right: info.Size.X - 1, - } - } -} - -// setCursorPosition sets the cursor to the specified position, bounded to the screen size -func (h *windowsAnsiEventHandler) setCursorPosition(position COORD, window SMALL_RECT) error { - position.X = ensureInRange(position.X, window.Left, window.Right) - position.Y = ensureInRange(position.Y, window.Top, window.Bottom) - err := SetConsoleCursorPosition(h.fd, position) - if err != nil { - return err - } - h.logf("Cursor position set: (%d, %d)", position.X, position.Y) - return err -} - -func (h *windowsAnsiEventHandler) moveCursorVertical(param int) error { - return h.moveCursor(vertical, param) -} - -func (h *windowsAnsiEventHandler) moveCursorHorizontal(param int) error { - return h.moveCursor(horizontal, param) -} - -func (h *windowsAnsiEventHandler) moveCursor(moveMode int, param int) error { - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - - position := info.CursorPosition - switch moveMode { - case horizontal: - position.X += int16(param) - case vertical: - position.Y += int16(param) - } - - if err = h.setCursorPosition(position, h.getCursorWindow(info)); err != nil { - return err - } - - return nil -} - -func (h *windowsAnsiEventHandler) moveCursorLine(param int) error { - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - - position := info.CursorPosition - position.X = 0 - position.Y += int16(param) - - if err = h.setCursorPosition(position, h.getCursorWindow(info)); err != nil { - return err - } - - return nil -} - -func (h *windowsAnsiEventHandler) moveCursorColumn(param int) error { - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - - position := info.CursorPosition - position.X = int16(param) - 1 - - if err = h.setCursorPosition(position, h.getCursorWindow(info)); err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/Azure/go-ansiterm/winterm/erase_helpers.go b/vendor/github.com/Azure/go-ansiterm/winterm/erase_helpers.go deleted file mode 100644 index 244b5fa..0000000 --- a/vendor/github.com/Azure/go-ansiterm/winterm/erase_helpers.go +++ /dev/null @@ -1,84 +0,0 @@ -// +build windows - -package winterm - -import "github.com/Azure/go-ansiterm" - -func (h *windowsAnsiEventHandler) clearRange(attributes uint16, fromCoord COORD, toCoord COORD) error { - // Ignore an invalid (negative area) request - if toCoord.Y < fromCoord.Y { - return nil - } - - var err error - - var coordStart = COORD{} - var coordEnd = COORD{} - - xCurrent, yCurrent := fromCoord.X, fromCoord.Y - xEnd, yEnd := toCoord.X, toCoord.Y - - // Clear any partial initial line - if xCurrent > 0 { - coordStart.X, coordStart.Y = xCurrent, yCurrent - coordEnd.X, coordEnd.Y = xEnd, yCurrent - - err = h.clearRect(attributes, coordStart, coordEnd) - if err != nil { - return err - } - - xCurrent = 0 - yCurrent += 1 - } - - // Clear intervening rectangular section - if yCurrent < yEnd { - coordStart.X, coordStart.Y = xCurrent, yCurrent - coordEnd.X, coordEnd.Y = xEnd, yEnd-1 - - err = h.clearRect(attributes, coordStart, coordEnd) - if err != nil { - return err - } - - xCurrent = 0 - yCurrent = yEnd - } - - // Clear remaining partial ending line - coordStart.X, coordStart.Y = xCurrent, yCurrent - coordEnd.X, coordEnd.Y = xEnd, yEnd - - err = h.clearRect(attributes, coordStart, coordEnd) - if err != nil { - return err - } - - return nil -} - -func (h *windowsAnsiEventHandler) clearRect(attributes uint16, fromCoord COORD, toCoord COORD) error { - region := SMALL_RECT{Top: fromCoord.Y, Left: fromCoord.X, Bottom: toCoord.Y, Right: toCoord.X} - width := toCoord.X - fromCoord.X + 1 - height := toCoord.Y - fromCoord.Y + 1 - size := uint32(width) * uint32(height) - - if size <= 0 { - return nil - } - - buffer := make([]CHAR_INFO, size) - - char := CHAR_INFO{ansiterm.FILL_CHARACTER, attributes} - for i := 0; i < int(size); i++ { - buffer[i] = char - } - - err := WriteConsoleOutput(h.fd, buffer, COORD{X: width, Y: height}, COORD{X: 0, Y: 0}, ®ion) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/Azure/go-ansiterm/winterm/scroll_helper.go b/vendor/github.com/Azure/go-ansiterm/winterm/scroll_helper.go deleted file mode 100644 index 2d27fa1..0000000 --- a/vendor/github.com/Azure/go-ansiterm/winterm/scroll_helper.go +++ /dev/null @@ -1,118 +0,0 @@ -// +build windows - -package winterm - -// effectiveSr gets the current effective scroll region in buffer coordinates -func (h *windowsAnsiEventHandler) effectiveSr(window SMALL_RECT) scrollRegion { - top := addInRange(window.Top, h.sr.top, window.Top, window.Bottom) - bottom := addInRange(window.Top, h.sr.bottom, window.Top, window.Bottom) - if top >= bottom { - top = window.Top - bottom = window.Bottom - } - return scrollRegion{top: top, bottom: bottom} -} - -func (h *windowsAnsiEventHandler) scrollUp(param int) error { - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - - sr := h.effectiveSr(info.Window) - return h.scroll(param, sr, info) -} - -func (h *windowsAnsiEventHandler) scrollDown(param int) error { - return h.scrollUp(-param) -} - -func (h *windowsAnsiEventHandler) deleteLines(param int) error { - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - - start := info.CursorPosition.Y - sr := h.effectiveSr(info.Window) - // Lines cannot be inserted or deleted outside the scrolling region. - if start >= sr.top && start <= sr.bottom { - sr.top = start - return h.scroll(param, sr, info) - } else { - return nil - } -} - -func (h *windowsAnsiEventHandler) insertLines(param int) error { - return h.deleteLines(-param) -} - -// scroll scrolls the provided scroll region by param lines. The scroll region is in buffer coordinates. -func (h *windowsAnsiEventHandler) scroll(param int, sr scrollRegion, info *CONSOLE_SCREEN_BUFFER_INFO) error { - h.logf("scroll: scrollTop: %d, scrollBottom: %d", sr.top, sr.bottom) - h.logf("scroll: windowTop: %d, windowBottom: %d", info.Window.Top, info.Window.Bottom) - - // Copy from and clip to the scroll region (full buffer width) - scrollRect := SMALL_RECT{ - Top: sr.top, - Bottom: sr.bottom, - Left: 0, - Right: info.Size.X - 1, - } - - // Origin to which area should be copied - destOrigin := COORD{ - X: 0, - Y: sr.top - int16(param), - } - - char := CHAR_INFO{ - UnicodeChar: ' ', - Attributes: h.attributes, - } - - if err := ScrollConsoleScreenBuffer(h.fd, scrollRect, scrollRect, destOrigin, char); err != nil { - return err - } - return nil -} - -func (h *windowsAnsiEventHandler) deleteCharacters(param int) error { - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - return h.scrollLine(param, info.CursorPosition, info) -} - -func (h *windowsAnsiEventHandler) insertCharacters(param int) error { - return h.deleteCharacters(-param) -} - -// scrollLine scrolls a line horizontally starting at the provided position by a number of columns. -func (h *windowsAnsiEventHandler) scrollLine(columns int, position COORD, info *CONSOLE_SCREEN_BUFFER_INFO) error { - // Copy from and clip to the scroll region (full buffer width) - scrollRect := SMALL_RECT{ - Top: position.Y, - Bottom: position.Y, - Left: position.X, - Right: info.Size.X - 1, - } - - // Origin to which area should be copied - destOrigin := COORD{ - X: position.X - int16(columns), - Y: position.Y, - } - - char := CHAR_INFO{ - UnicodeChar: ' ', - Attributes: h.attributes, - } - - if err := ScrollConsoleScreenBuffer(h.fd, scrollRect, scrollRect, destOrigin, char); err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/Azure/go-ansiterm/winterm/utilities.go b/vendor/github.com/Azure/go-ansiterm/winterm/utilities.go deleted file mode 100644 index afa7635..0000000 --- a/vendor/github.com/Azure/go-ansiterm/winterm/utilities.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build windows - -package winterm - -// AddInRange increments a value by the passed quantity while ensuring the values -// always remain within the supplied min / max range. -func addInRange(n int16, increment int16, min int16, max int16) int16 { - return ensureInRange(n+increment, min, max) -} diff --git a/vendor/github.com/Azure/go-ansiterm/winterm/win_event_handler.go b/vendor/github.com/Azure/go-ansiterm/winterm/win_event_handler.go deleted file mode 100644 index 2d40fb7..0000000 --- a/vendor/github.com/Azure/go-ansiterm/winterm/win_event_handler.go +++ /dev/null @@ -1,743 +0,0 @@ -// +build windows - -package winterm - -import ( - "bytes" - "log" - "os" - "strconv" - - "github.com/Azure/go-ansiterm" -) - -type windowsAnsiEventHandler struct { - fd uintptr - file *os.File - infoReset *CONSOLE_SCREEN_BUFFER_INFO - sr scrollRegion - buffer bytes.Buffer - attributes uint16 - inverted bool - wrapNext bool - drewMarginByte bool - originMode bool - marginByte byte - curInfo *CONSOLE_SCREEN_BUFFER_INFO - curPos COORD - logf func(string, ...interface{}) -} - -type Option func(*windowsAnsiEventHandler) - -func WithLogf(f func(string, ...interface{})) Option { - return func(w *windowsAnsiEventHandler) { - w.logf = f - } -} - -func CreateWinEventHandler(fd uintptr, file *os.File, opts ...Option) ansiterm.AnsiEventHandler { - infoReset, err := GetConsoleScreenBufferInfo(fd) - if err != nil { - return nil - } - - h := &windowsAnsiEventHandler{ - fd: fd, - file: file, - infoReset: infoReset, - attributes: infoReset.Attributes, - } - for _, o := range opts { - o(h) - } - - if isDebugEnv := os.Getenv(ansiterm.LogEnv); isDebugEnv == "1" { - logFile, _ := os.Create("winEventHandler.log") - logger := log.New(logFile, "", log.LstdFlags) - if h.logf != nil { - l := h.logf - h.logf = func(s string, v ...interface{}) { - l(s, v...) - logger.Printf(s, v...) - } - } else { - h.logf = logger.Printf - } - } - - if h.logf == nil { - h.logf = func(string, ...interface{}) {} - } - - return h -} - -type scrollRegion struct { - top int16 - bottom int16 -} - -// simulateLF simulates a LF or CR+LF by scrolling if necessary to handle the -// current cursor position and scroll region settings, in which case it returns -// true. If no special handling is necessary, then it does nothing and returns -// false. -// -// In the false case, the caller should ensure that a carriage return -// and line feed are inserted or that the text is otherwise wrapped. -func (h *windowsAnsiEventHandler) simulateLF(includeCR bool) (bool, error) { - if h.wrapNext { - if err := h.Flush(); err != nil { - return false, err - } - h.clearWrap() - } - pos, info, err := h.getCurrentInfo() - if err != nil { - return false, err - } - sr := h.effectiveSr(info.Window) - if pos.Y == sr.bottom { - // Scrolling is necessary. Let Windows automatically scroll if the scrolling region - // is the full window. - if sr.top == info.Window.Top && sr.bottom == info.Window.Bottom { - if includeCR { - pos.X = 0 - h.updatePos(pos) - } - return false, nil - } - - // A custom scroll region is active. Scroll the window manually to simulate - // the LF. - if err := h.Flush(); err != nil { - return false, err - } - h.logf("Simulating LF inside scroll region") - if err := h.scrollUp(1); err != nil { - return false, err - } - if includeCR { - pos.X = 0 - if err := SetConsoleCursorPosition(h.fd, pos); err != nil { - return false, err - } - } - return true, nil - - } else if pos.Y < info.Window.Bottom { - // Let Windows handle the LF. - pos.Y++ - if includeCR { - pos.X = 0 - } - h.updatePos(pos) - return false, nil - } else { - // The cursor is at the bottom of the screen but outside the scroll - // region. Skip the LF. - h.logf("Simulating LF outside scroll region") - if includeCR { - if err := h.Flush(); err != nil { - return false, err - } - pos.X = 0 - if err := SetConsoleCursorPosition(h.fd, pos); err != nil { - return false, err - } - } - return true, nil - } -} - -// executeLF executes a LF without a CR. -func (h *windowsAnsiEventHandler) executeLF() error { - handled, err := h.simulateLF(false) - if err != nil { - return err - } - if !handled { - // Windows LF will reset the cursor column position. Write the LF - // and restore the cursor position. - pos, _, err := h.getCurrentInfo() - if err != nil { - return err - } - h.buffer.WriteByte(ansiterm.ANSI_LINE_FEED) - if pos.X != 0 { - if err := h.Flush(); err != nil { - return err - } - h.logf("Resetting cursor position for LF without CR") - if err := SetConsoleCursorPosition(h.fd, pos); err != nil { - return err - } - } - } - return nil -} - -func (h *windowsAnsiEventHandler) Print(b byte) error { - if h.wrapNext { - h.buffer.WriteByte(h.marginByte) - h.clearWrap() - if _, err := h.simulateLF(true); err != nil { - return err - } - } - pos, info, err := h.getCurrentInfo() - if err != nil { - return err - } - if pos.X == info.Size.X-1 { - h.wrapNext = true - h.marginByte = b - } else { - pos.X++ - h.updatePos(pos) - h.buffer.WriteByte(b) - } - return nil -} - -func (h *windowsAnsiEventHandler) Execute(b byte) error { - switch b { - case ansiterm.ANSI_TAB: - h.logf("Execute(TAB)") - // Move to the next tab stop, but preserve auto-wrap if already set. - if !h.wrapNext { - pos, info, err := h.getCurrentInfo() - if err != nil { - return err - } - pos.X = (pos.X + 8) - pos.X%8 - if pos.X >= info.Size.X { - pos.X = info.Size.X - 1 - } - if err := h.Flush(); err != nil { - return err - } - if err := SetConsoleCursorPosition(h.fd, pos); err != nil { - return err - } - } - return nil - - case ansiterm.ANSI_BEL: - h.buffer.WriteByte(ansiterm.ANSI_BEL) - return nil - - case ansiterm.ANSI_BACKSPACE: - if h.wrapNext { - if err := h.Flush(); err != nil { - return err - } - h.clearWrap() - } - pos, _, err := h.getCurrentInfo() - if err != nil { - return err - } - if pos.X > 0 { - pos.X-- - h.updatePos(pos) - h.buffer.WriteByte(ansiterm.ANSI_BACKSPACE) - } - return nil - - case ansiterm.ANSI_VERTICAL_TAB, ansiterm.ANSI_FORM_FEED: - // Treat as true LF. - return h.executeLF() - - case ansiterm.ANSI_LINE_FEED: - // Simulate a CR and LF for now since there is no way in go-ansiterm - // to tell if the LF should include CR (and more things break when it's - // missing than when it's incorrectly added). - handled, err := h.simulateLF(true) - if handled || err != nil { - return err - } - return h.buffer.WriteByte(ansiterm.ANSI_LINE_FEED) - - case ansiterm.ANSI_CARRIAGE_RETURN: - if h.wrapNext { - if err := h.Flush(); err != nil { - return err - } - h.clearWrap() - } - pos, _, err := h.getCurrentInfo() - if err != nil { - return err - } - if pos.X != 0 { - pos.X = 0 - h.updatePos(pos) - h.buffer.WriteByte(ansiterm.ANSI_CARRIAGE_RETURN) - } - return nil - - default: - return nil - } -} - -func (h *windowsAnsiEventHandler) CUU(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("CUU: [%v]", []string{strconv.Itoa(param)}) - h.clearWrap() - return h.moveCursorVertical(-param) -} - -func (h *windowsAnsiEventHandler) CUD(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("CUD: [%v]", []string{strconv.Itoa(param)}) - h.clearWrap() - return h.moveCursorVertical(param) -} - -func (h *windowsAnsiEventHandler) CUF(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("CUF: [%v]", []string{strconv.Itoa(param)}) - h.clearWrap() - return h.moveCursorHorizontal(param) -} - -func (h *windowsAnsiEventHandler) CUB(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("CUB: [%v]", []string{strconv.Itoa(param)}) - h.clearWrap() - return h.moveCursorHorizontal(-param) -} - -func (h *windowsAnsiEventHandler) CNL(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("CNL: [%v]", []string{strconv.Itoa(param)}) - h.clearWrap() - return h.moveCursorLine(param) -} - -func (h *windowsAnsiEventHandler) CPL(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("CPL: [%v]", []string{strconv.Itoa(param)}) - h.clearWrap() - return h.moveCursorLine(-param) -} - -func (h *windowsAnsiEventHandler) CHA(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("CHA: [%v]", []string{strconv.Itoa(param)}) - h.clearWrap() - return h.moveCursorColumn(param) -} - -func (h *windowsAnsiEventHandler) VPA(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("VPA: [[%d]]", param) - h.clearWrap() - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - window := h.getCursorWindow(info) - position := info.CursorPosition - position.Y = window.Top + int16(param) - 1 - return h.setCursorPosition(position, window) -} - -func (h *windowsAnsiEventHandler) CUP(row int, col int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("CUP: [[%d %d]]", row, col) - h.clearWrap() - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - - window := h.getCursorWindow(info) - position := COORD{window.Left + int16(col) - 1, window.Top + int16(row) - 1} - return h.setCursorPosition(position, window) -} - -func (h *windowsAnsiEventHandler) HVP(row int, col int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("HVP: [[%d %d]]", row, col) - h.clearWrap() - return h.CUP(row, col) -} - -func (h *windowsAnsiEventHandler) DECTCEM(visible bool) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("DECTCEM: [%v]", []string{strconv.FormatBool(visible)}) - h.clearWrap() - return nil -} - -func (h *windowsAnsiEventHandler) DECOM(enable bool) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("DECOM: [%v]", []string{strconv.FormatBool(enable)}) - h.clearWrap() - h.originMode = enable - return h.CUP(1, 1) -} - -func (h *windowsAnsiEventHandler) DECCOLM(use132 bool) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("DECCOLM: [%v]", []string{strconv.FormatBool(use132)}) - h.clearWrap() - if err := h.ED(2); err != nil { - return err - } - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - targetWidth := int16(80) - if use132 { - targetWidth = 132 - } - if info.Size.X < targetWidth { - if err := SetConsoleScreenBufferSize(h.fd, COORD{targetWidth, info.Size.Y}); err != nil { - h.logf("set buffer failed: %v", err) - return err - } - } - window := info.Window - window.Left = 0 - window.Right = targetWidth - 1 - if err := SetConsoleWindowInfo(h.fd, true, window); err != nil { - h.logf("set window failed: %v", err) - return err - } - if info.Size.X > targetWidth { - if err := SetConsoleScreenBufferSize(h.fd, COORD{targetWidth, info.Size.Y}); err != nil { - h.logf("set buffer failed: %v", err) - return err - } - } - return SetConsoleCursorPosition(h.fd, COORD{0, 0}) -} - -func (h *windowsAnsiEventHandler) ED(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("ED: [%v]", []string{strconv.Itoa(param)}) - h.clearWrap() - - // [J -- Erases from the cursor to the end of the screen, including the cursor position. - // [1J -- Erases from the beginning of the screen to the cursor, including the cursor position. - // [2J -- Erases the complete display. The cursor does not move. - // Notes: - // -- Clearing the entire buffer, versus just the Window, works best for Windows Consoles - - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - - var start COORD - var end COORD - - switch param { - case 0: - start = info.CursorPosition - end = COORD{info.Size.X - 1, info.Size.Y - 1} - - case 1: - start = COORD{0, 0} - end = info.CursorPosition - - case 2: - start = COORD{0, 0} - end = COORD{info.Size.X - 1, info.Size.Y - 1} - } - - err = h.clearRange(h.attributes, start, end) - if err != nil { - return err - } - - // If the whole buffer was cleared, move the window to the top while preserving - // the window-relative cursor position. - if param == 2 { - pos := info.CursorPosition - window := info.Window - pos.Y -= window.Top - window.Bottom -= window.Top - window.Top = 0 - if err := SetConsoleCursorPosition(h.fd, pos); err != nil { - return err - } - if err := SetConsoleWindowInfo(h.fd, true, window); err != nil { - return err - } - } - - return nil -} - -func (h *windowsAnsiEventHandler) EL(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("EL: [%v]", strconv.Itoa(param)) - h.clearWrap() - - // [K -- Erases from the cursor to the end of the line, including the cursor position. - // [1K -- Erases from the beginning of the line to the cursor, including the cursor position. - // [2K -- Erases the complete line. - - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - - var start COORD - var end COORD - - switch param { - case 0: - start = info.CursorPosition - end = COORD{info.Size.X, info.CursorPosition.Y} - - case 1: - start = COORD{0, info.CursorPosition.Y} - end = info.CursorPosition - - case 2: - start = COORD{0, info.CursorPosition.Y} - end = COORD{info.Size.X, info.CursorPosition.Y} - } - - err = h.clearRange(h.attributes, start, end) - if err != nil { - return err - } - - return nil -} - -func (h *windowsAnsiEventHandler) IL(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("IL: [%v]", strconv.Itoa(param)) - h.clearWrap() - return h.insertLines(param) -} - -func (h *windowsAnsiEventHandler) DL(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("DL: [%v]", strconv.Itoa(param)) - h.clearWrap() - return h.deleteLines(param) -} - -func (h *windowsAnsiEventHandler) ICH(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("ICH: [%v]", strconv.Itoa(param)) - h.clearWrap() - return h.insertCharacters(param) -} - -func (h *windowsAnsiEventHandler) DCH(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("DCH: [%v]", strconv.Itoa(param)) - h.clearWrap() - return h.deleteCharacters(param) -} - -func (h *windowsAnsiEventHandler) SGR(params []int) error { - if err := h.Flush(); err != nil { - return err - } - strings := []string{} - for _, v := range params { - strings = append(strings, strconv.Itoa(v)) - } - - h.logf("SGR: [%v]", strings) - - if len(params) <= 0 { - h.attributes = h.infoReset.Attributes - h.inverted = false - } else { - for _, attr := range params { - - if attr == ansiterm.ANSI_SGR_RESET { - h.attributes = h.infoReset.Attributes - h.inverted = false - continue - } - - h.attributes, h.inverted = collectAnsiIntoWindowsAttributes(h.attributes, h.inverted, h.infoReset.Attributes, int16(attr)) - } - } - - attributes := h.attributes - if h.inverted { - attributes = invertAttributes(attributes) - } - err := SetConsoleTextAttribute(h.fd, attributes) - if err != nil { - return err - } - - return nil -} - -func (h *windowsAnsiEventHandler) SU(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("SU: [%v]", []string{strconv.Itoa(param)}) - h.clearWrap() - return h.scrollUp(param) -} - -func (h *windowsAnsiEventHandler) SD(param int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("SD: [%v]", []string{strconv.Itoa(param)}) - h.clearWrap() - return h.scrollDown(param) -} - -func (h *windowsAnsiEventHandler) DA(params []string) error { - h.logf("DA: [%v]", params) - // DA cannot be implemented because it must send data on the VT100 input stream, - // which is not available to go-ansiterm. - return nil -} - -func (h *windowsAnsiEventHandler) DECSTBM(top int, bottom int) error { - if err := h.Flush(); err != nil { - return err - } - h.logf("DECSTBM: [%d, %d]", top, bottom) - - // Windows is 0 indexed, Linux is 1 indexed - h.sr.top = int16(top - 1) - h.sr.bottom = int16(bottom - 1) - - // This command also moves the cursor to the origin. - h.clearWrap() - return h.CUP(1, 1) -} - -func (h *windowsAnsiEventHandler) RI() error { - if err := h.Flush(); err != nil { - return err - } - h.logf("RI: []") - h.clearWrap() - - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - - sr := h.effectiveSr(info.Window) - if info.CursorPosition.Y == sr.top { - return h.scrollDown(1) - } - - return h.moveCursorVertical(-1) -} - -func (h *windowsAnsiEventHandler) IND() error { - h.logf("IND: []") - return h.executeLF() -} - -func (h *windowsAnsiEventHandler) Flush() error { - h.curInfo = nil - if h.buffer.Len() > 0 { - h.logf("Flush: [%s]", h.buffer.Bytes()) - if _, err := h.buffer.WriteTo(h.file); err != nil { - return err - } - } - - if h.wrapNext && !h.drewMarginByte { - h.logf("Flush: drawing margin byte '%c'", h.marginByte) - - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return err - } - - charInfo := []CHAR_INFO{{UnicodeChar: uint16(h.marginByte), Attributes: info.Attributes}} - size := COORD{1, 1} - position := COORD{0, 0} - region := SMALL_RECT{Left: info.CursorPosition.X, Top: info.CursorPosition.Y, Right: info.CursorPosition.X, Bottom: info.CursorPosition.Y} - if err := WriteConsoleOutput(h.fd, charInfo, size, position, ®ion); err != nil { - return err - } - h.drewMarginByte = true - } - return nil -} - -// cacheConsoleInfo ensures that the current console screen information has been queried -// since the last call to Flush(). It must be called before accessing h.curInfo or h.curPos. -func (h *windowsAnsiEventHandler) getCurrentInfo() (COORD, *CONSOLE_SCREEN_BUFFER_INFO, error) { - if h.curInfo == nil { - info, err := GetConsoleScreenBufferInfo(h.fd) - if err != nil { - return COORD{}, nil, err - } - h.curInfo = info - h.curPos = info.CursorPosition - } - return h.curPos, h.curInfo, nil -} - -func (h *windowsAnsiEventHandler) updatePos(pos COORD) { - if h.curInfo == nil { - panic("failed to call getCurrentInfo before calling updatePos") - } - h.curPos = pos -} - -// clearWrap clears the state where the cursor is in the margin -// waiting for the next character before wrapping the line. This must -// be done before most operations that act on the cursor. -func (h *windowsAnsiEventHandler) clearWrap() { - h.wrapNext = false - h.drewMarginByte = false -} diff --git a/vendor/github.com/Sirupsen/logrus/.gitignore b/vendor/github.com/Sirupsen/logrus/.gitignore deleted file mode 100644 index 66be63a..0000000 --- a/vendor/github.com/Sirupsen/logrus/.gitignore +++ /dev/null @@ -1 +0,0 @@ -logrus diff --git a/vendor/github.com/Sirupsen/logrus/.travis.yml b/vendor/github.com/Sirupsen/logrus/.travis.yml deleted file mode 100644 index a23296a..0000000 --- a/vendor/github.com/Sirupsen/logrus/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: go -go: - - 1.6.x - - 1.7.x - - 1.8.x - - tip -env: - - GOMAXPROCS=4 GORACE=halt_on_error=1 -install: - - go get github.com/stretchr/testify/assert - - go get gopkg.in/gemnasium/logrus-airbrake-hook.v2 - - go get golang.org/x/sys/unix - - go get golang.org/x/sys/windows -script: - - go test -race -v ./... diff --git a/vendor/github.com/Sirupsen/logrus/CHANGELOG.md b/vendor/github.com/Sirupsen/logrus/CHANGELOG.md deleted file mode 100644 index 8236d8b..0000000 --- a/vendor/github.com/Sirupsen/logrus/CHANGELOG.md +++ /dev/null @@ -1,113 +0,0 @@ -# 1.0.3 - -* Replace example files with testable examples - -# 1.0.2 - -* bug: quote non-string values in text formatter (#583) -* Make (*Logger) SetLevel a public method - -# 1.0.1 - -* bug: fix escaping in text formatter (#575) - -# 1.0.0 - -* Officially changed name to lower-case -* bug: colors on Windows 10 (#541) -* bug: fix race in accessing level (#512) - -# 0.11.5 - -* feature: add writer and writerlevel to entry (#372) - -# 0.11.4 - -* bug: fix undefined variable on solaris (#493) - -# 0.11.3 - -* formatter: configure quoting of empty values (#484) -* formatter: configure quoting character (default is `"`) (#484) -* bug: fix not importing io correctly in non-linux environments (#481) - -# 0.11.2 - -* bug: fix windows terminal detection (#476) - -# 0.11.1 - -* bug: fix tty detection with custom out (#471) - -# 0.11.0 - -* performance: Use bufferpool to allocate (#370) -* terminal: terminal detection for app-engine (#343) -* feature: exit handler (#375) - -# 0.10.0 - -* feature: Add a test hook (#180) -* feature: `ParseLevel` is now case-insensitive (#326) -* feature: `FieldLogger` interface that generalizes `Logger` and `Entry` (#308) -* performance: avoid re-allocations on `WithFields` (#335) - -# 0.9.0 - -* logrus/text_formatter: don't emit empty msg -* logrus/hooks/airbrake: move out of main repository -* logrus/hooks/sentry: move out of main repository -* logrus/hooks/papertrail: move out of main repository -* logrus/hooks/bugsnag: move out of main repository -* logrus/core: run tests with `-race` -* logrus/core: detect TTY based on `stderr` -* logrus/core: support `WithError` on logger -* logrus/core: Solaris support - -# 0.8.7 - -* logrus/core: fix possible race (#216) -* logrus/doc: small typo fixes and doc improvements - - -# 0.8.6 - -* hooks/raven: allow passing an initialized client - -# 0.8.5 - -* logrus/core: revert #208 - -# 0.8.4 - -* formatter/text: fix data race (#218) - -# 0.8.3 - -* logrus/core: fix entry log level (#208) -* logrus/core: improve performance of text formatter by 40% -* logrus/core: expose `LevelHooks` type -* logrus/core: add support for DragonflyBSD and NetBSD -* formatter/text: print structs more verbosely - -# 0.8.2 - -* logrus: fix more Fatal family functions - -# 0.8.1 - -* logrus: fix not exiting on `Fatalf` and `Fatalln` - -# 0.8.0 - -* logrus: defaults to stderr instead of stdout -* hooks/sentry: add special field for `*http.Request` -* formatter/text: ignore Windows for colors - -# 0.7.3 - -* formatter/\*: allow configuration of timestamp layout - -# 0.7.2 - -* formatter/text: Add configuration option for time format (#158) diff --git a/vendor/github.com/Sirupsen/logrus/LICENSE b/vendor/github.com/Sirupsen/logrus/LICENSE deleted file mode 100644 index f090cb4..0000000 --- a/vendor/github.com/Sirupsen/logrus/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Simon Eskildsen - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/github.com/Sirupsen/logrus/README.md b/vendor/github.com/Sirupsen/logrus/README.md deleted file mode 100644 index 4f5ce57..0000000 --- a/vendor/github.com/Sirupsen/logrus/README.md +++ /dev/null @@ -1,505 +0,0 @@ -# Logrus :walrus: [![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus) [![GoDoc](https://godoc.org/github.com/sirupsen/logrus?status.svg)](https://godoc.org/github.com/sirupsen/logrus) - -Logrus is a structured logger for Go (golang), completely API compatible with -the standard library logger. - -**Seeing weird case-sensitive problems?** It's in the past been possible to -import Logrus as both upper- and lower-case. Due to the Go package environment, -this caused issues in the community and we needed a standard. Some environments -experienced problems with the upper-case variant, so the lower-case was decided. -Everything using `logrus` will need to use the lower-case: -`github.com/sirupsen/logrus`. Any package that isn't, should be changed. - -To fix Glide, see [these -comments](https://github.com/sirupsen/logrus/issues/553#issuecomment-306591437). -For an in-depth explanation of the casing issue, see [this -comment](https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276). - -**Are you interested in assisting in maintaining Logrus?** Currently I have a -lot of obligations, and I am unable to provide Logrus with the maintainership it -needs. If you'd like to help, please reach out to me at `simon at author's -username dot com`. - -Nicely color-coded in development (when a TTY is attached, otherwise just -plain text): - -![Colored](http://i.imgur.com/PY7qMwd.png) - -With `log.SetFormatter(&log.JSONFormatter{})`, for easy parsing by logstash -or Splunk: - -```json -{"animal":"walrus","level":"info","msg":"A group of walrus emerges from the -ocean","size":10,"time":"2014-03-10 19:57:38.562264131 -0400 EDT"} - -{"level":"warning","msg":"The group's number increased tremendously!", -"number":122,"omg":true,"time":"2014-03-10 19:57:38.562471297 -0400 EDT"} - -{"animal":"walrus","level":"info","msg":"A giant walrus appears!", -"size":10,"time":"2014-03-10 19:57:38.562500591 -0400 EDT"} - -{"animal":"walrus","level":"info","msg":"Tremendously sized cow enters the ocean.", -"size":9,"time":"2014-03-10 19:57:38.562527896 -0400 EDT"} - -{"level":"fatal","msg":"The ice breaks!","number":100,"omg":true, -"time":"2014-03-10 19:57:38.562543128 -0400 EDT"} -``` - -With the default `log.SetFormatter(&log.TextFormatter{})` when a TTY is not -attached, the output is compatible with the -[logfmt](http://godoc.org/github.com/kr/logfmt) format: - -```text -time="2015-03-26T01:27:38-04:00" level=debug msg="Started observing beach" animal=walrus number=8 -time="2015-03-26T01:27:38-04:00" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10 -time="2015-03-26T01:27:38-04:00" level=warning msg="The group's number increased tremendously!" number=122 omg=true -time="2015-03-26T01:27:38-04:00" level=debug msg="Temperature changes" temperature=-4 -time="2015-03-26T01:27:38-04:00" level=panic msg="It's over 9000!" animal=orca size=9009 -time="2015-03-26T01:27:38-04:00" level=fatal msg="The ice breaks!" err=&{0x2082280c0 map[animal:orca size:9009] 2015-03-26 01:27:38.441574009 -0400 EDT panic It's over 9000!} number=100 omg=true -exit status 1 -``` - -#### Case-sensitivity - -The organization's name was changed to lower-case--and this will not be changed -back. If you are getting import conflicts due to case sensitivity, please use -the lower-case import: `github.com/sirupsen/logrus`. - -#### Example - -The simplest way to use Logrus is simply the package-level exported logger: - -```go -package main - -import ( - log "github.com/sirupsen/logrus" -) - -func main() { - log.WithFields(log.Fields{ - "animal": "walrus", - }).Info("A walrus appears") -} -``` - -Note that it's completely api-compatible with the stdlib logger, so you can -replace your `log` imports everywhere with `log "github.com/sirupsen/logrus"` -and you'll now have the flexibility of Logrus. You can customize it all you -want: - -```go -package main - -import ( - "os" - log "github.com/sirupsen/logrus" -) - -func init() { - // Log as JSON instead of the default ASCII formatter. - log.SetFormatter(&log.JSONFormatter{}) - - // Output to stdout instead of the default stderr - // Can be any io.Writer, see below for File example - log.SetOutput(os.Stdout) - - // Only log the warning severity or above. - log.SetLevel(log.WarnLevel) -} - -func main() { - log.WithFields(log.Fields{ - "animal": "walrus", - "size": 10, - }).Info("A group of walrus emerges from the ocean") - - log.WithFields(log.Fields{ - "omg": true, - "number": 122, - }).Warn("The group's number increased tremendously!") - - log.WithFields(log.Fields{ - "omg": true, - "number": 100, - }).Fatal("The ice breaks!") - - // A common pattern is to re-use fields between logging statements by re-using - // the logrus.Entry returned from WithFields() - contextLogger := log.WithFields(log.Fields{ - "common": "this is a common field", - "other": "I also should be logged always", - }) - - contextLogger.Info("I'll be logged with common and other field") - contextLogger.Info("Me too") -} -``` - -For more advanced usage such as logging to multiple locations from the same -application, you can also create an instance of the `logrus` Logger: - -```go -package main - -import ( - "os" - "github.com/sirupsen/logrus" -) - -// Create a new instance of the logger. You can have any number of instances. -var log = logrus.New() - -func main() { - // The API for setting attributes is a little different than the package level - // exported logger. See Godoc. - log.Out = os.Stdout - - // You could set this to any `io.Writer` such as a file - // file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666) - // if err == nil { - // log.Out = file - // } else { - // log.Info("Failed to log to file, using default stderr") - // } - - log.WithFields(logrus.Fields{ - "animal": "walrus", - "size": 10, - }).Info("A group of walrus emerges from the ocean") -} -``` - -#### Fields - -Logrus encourages careful, structured logging through logging fields instead of -long, unparseable error messages. For example, instead of: `log.Fatalf("Failed -to send event %s to topic %s with key %d")`, you should log the much more -discoverable: - -```go -log.WithFields(log.Fields{ - "event": event, - "topic": topic, - "key": key, -}).Fatal("Failed to send event") -``` - -We've found this API forces you to think about logging in a way that produces -much more useful logging messages. We've been in countless situations where just -a single added field to a log statement that was already there would've saved us -hours. The `WithFields` call is optional. - -In general, with Logrus using any of the `printf`-family functions should be -seen as a hint you should add a field, however, you can still use the -`printf`-family functions with Logrus. - -#### Default Fields - -Often it's helpful to have fields _always_ attached to log statements in an -application or parts of one. For example, you may want to always log the -`request_id` and `user_ip` in the context of a request. Instead of writing -`log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})` on -every line, you can create a `logrus.Entry` to pass around instead: - -```go -requestLogger := log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip}) -requestLogger.Info("something happened on that request") # will log request_id and user_ip -requestLogger.Warn("something not great happened") -``` - -#### Hooks - -You can add hooks for logging levels. For example to send errors to an exception -tracking service on `Error`, `Fatal` and `Panic`, info to StatsD or log to -multiple places simultaneously, e.g. syslog. - -Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in -`init`: - -```go -import ( - log "github.com/sirupsen/logrus" - "gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "aibrake" - logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" - "log/syslog" -) - -func init() { - - // Use the Airbrake hook to report errors that have Error severity or above to - // an exception tracker. You can create custom hooks, see the Hooks section. - log.AddHook(airbrake.NewHook(123, "xyz", "production")) - - hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "") - if err != nil { - log.Error("Unable to connect to local syslog daemon") - } else { - log.AddHook(hook) - } -} -``` -Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). For the detail, please check the [syslog hook README](hooks/syslog/README.md). - -| Hook | Description | -| ----- | ----------- | -| [Airbrake "legacy"](https://github.com/gemnasium/logrus-airbrake-legacy-hook) | Send errors to an exception tracking service compatible with the Airbrake API V2. Uses [`airbrake-go`](https://github.com/tobi/airbrake-go) behind the scenes. | -| [Airbrake](https://github.com/gemnasium/logrus-airbrake-hook) | Send errors to the Airbrake API V3. Uses the official [`gobrake`](https://github.com/airbrake/gobrake) behind the scenes. | -| [Amazon Kinesis](https://github.com/evalphobia/logrus_kinesis) | Hook for logging to [Amazon Kinesis](https://aws.amazon.com/kinesis/) | -| [Amqp-Hook](https://github.com/vladoatanasov/logrus_amqp) | Hook for logging to Amqp broker (Like RabbitMQ) | -| [Bugsnag](https://github.com/Shopify/logrus-bugsnag/blob/master/bugsnag.go) | Send errors to the Bugsnag exception tracking service. | -| [DeferPanic](https://github.com/deferpanic/dp-logrus) | Hook for logging to DeferPanic | -| [Discordrus](https://github.com/kz/discordrus) | Hook for logging to [Discord](https://discordapp.com/) | -| [ElasticSearch](https://github.com/sohlich/elogrus) | Hook for logging to ElasticSearch| -| [Firehose](https://github.com/beaubrewer/logrus_firehose) | Hook for logging to [Amazon Firehose](https://aws.amazon.com/kinesis/firehose/) -| [Fluentd](https://github.com/evalphobia/logrus_fluent) | Hook for logging to fluentd | -| [Go-Slack](https://github.com/multiplay/go-slack) | Hook for logging to [Slack](https://slack.com) | -| [Graylog](https://github.com/gemnasium/logrus-graylog-hook) | Hook for logging to [Graylog](http://graylog2.org/) | -| [Hiprus](https://github.com/nubo/hiprus) | Send errors to a channel in hipchat. | -| [Honeybadger](https://github.com/agonzalezro/logrus_honeybadger) | Hook for sending exceptions to Honeybadger | -| [InfluxDB](https://github.com/Abramovic/logrus_influxdb) | Hook for logging to influxdb | -| [Influxus](http://github.com/vlad-doru/influxus) | Hook for concurrently logging to [InfluxDB](http://influxdata.com/) | -| [Journalhook](https://github.com/wercker/journalhook) | Hook for logging to `systemd-journald` | -| [KafkaLogrus](https://github.com/goibibo/KafkaLogrus) | Hook for logging to kafka | -| [LFShook](https://github.com/rifflock/lfshook) | Hook for logging to the local filesystem | -| [Logentries](https://github.com/jcftang/logentriesrus) | Hook for logging to [Logentries](https://logentries.com/) | -| [Logentrus](https://github.com/puddingfactory/logentrus) | Hook for logging to [Logentries](https://logentries.com/) | -| [Logmatic.io](https://github.com/logmatic/logmatic-go) | Hook for logging to [Logmatic.io](http://logmatic.io/) | -| [Logrusly](https://github.com/sebest/logrusly) | Send logs to [Loggly](https://www.loggly.com/) | -| [Logstash](https://github.com/bshuster-repo/logrus-logstash-hook) | Hook for logging to [Logstash](https://www.elastic.co/products/logstash) | -| [Mail](https://github.com/zbindenren/logrus_mail) | Hook for sending exceptions via mail | -| [Mattermost](https://github.com/shuLhan/mattermost-integration/tree/master/hooks/logrus) | Hook for logging to [Mattermost](https://mattermost.com/) | -| [Mongodb](https://github.com/weekface/mgorus) | Hook for logging to mongodb | -| [NATS-Hook](https://github.com/rybit/nats_logrus_hook) | Hook for logging to [NATS](https://nats.io) | -| [Octokit](https://github.com/dorajistyle/logrus-octokit-hook) | Hook for logging to github via octokit | -| [Papertrail](https://github.com/polds/logrus-papertrail-hook) | Send errors to the [Papertrail](https://papertrailapp.com) hosted logging service via UDP. | -| [PostgreSQL](https://github.com/gemnasium/logrus-postgresql-hook) | Send logs to [PostgreSQL](http://postgresql.org) | -| [Pushover](https://github.com/toorop/logrus_pushover) | Send error via [Pushover](https://pushover.net) | -| [Raygun](https://github.com/squirkle/logrus-raygun-hook) | Hook for logging to [Raygun.io](http://raygun.io/) | -| [Redis-Hook](https://github.com/rogierlommers/logrus-redis-hook) | Hook for logging to a ELK stack (through Redis) | -| [Rollrus](https://github.com/heroku/rollrus) | Hook for sending errors to rollbar | -| [Scribe](https://github.com/sagar8192/logrus-scribe-hook) | Hook for logging to [Scribe](https://github.com/facebookarchive/scribe)| -| [Sentry](https://github.com/evalphobia/logrus_sentry) | Send errors to the Sentry error logging and aggregation service. | -| [Slackrus](https://github.com/johntdyer/slackrus) | Hook for Slack chat. | -| [Stackdriver](https://github.com/knq/sdhook) | Hook for logging to [Google Stackdriver](https://cloud.google.com/logging/) | -| [Sumorus](https://github.com/doublefree/sumorus) | Hook for logging to [SumoLogic](https://www.sumologic.com/)| -| [Syslog](https://github.com/sirupsen/logrus/blob/master/hooks/syslog/syslog.go) | Send errors to remote syslog server. Uses standard library `log/syslog` behind the scenes. | -| [Syslog TLS](https://github.com/shinji62/logrus-syslog-ng) | Send errors to remote syslog server with TLS support. | -| [TraceView](https://github.com/evalphobia/logrus_appneta) | Hook for logging to [AppNeta TraceView](https://www.appneta.com/products/traceview/) | -| [Typetalk](https://github.com/dragon3/logrus-typetalk-hook) | Hook for logging to [Typetalk](https://www.typetalk.in/) | -| [logz.io](https://github.com/ripcurld00d/logrus-logzio-hook) | Hook for logging to [logz.io](https://logz.io), a Log as a Service using Logstash | -| [SQS-Hook](https://github.com/tsarpaul/logrus_sqs) | Hook for logging to [Amazon Simple Queue Service (SQS)](https://aws.amazon.com/sqs/) | - -#### Level logging - -Logrus has six logging levels: Debug, Info, Warning, Error, Fatal and Panic. - -```go -log.Debug("Useful debugging information.") -log.Info("Something noteworthy happened!") -log.Warn("You should probably take a look at this.") -log.Error("Something failed but I'm not quitting.") -// Calls os.Exit(1) after logging -log.Fatal("Bye.") -// Calls panic() after logging -log.Panic("I'm bailing.") -``` - -You can set the logging level on a `Logger`, then it will only log entries with -that severity or anything above it: - -```go -// Will log anything that is info or above (warn, error, fatal, panic). Default. -log.SetLevel(log.InfoLevel) -``` - -It may be useful to set `log.Level = logrus.DebugLevel` in a debug or verbose -environment if your application has that. - -#### Entries - -Besides the fields added with `WithField` or `WithFields` some fields are -automatically added to all logging events: - -1. `time`. The timestamp when the entry was created. -2. `msg`. The logging message passed to `{Info,Warn,Error,Fatal,Panic}` after - the `AddFields` call. E.g. `Failed to send event.` -3. `level`. The logging level. E.g. `info`. - -#### Environments - -Logrus has no notion of environment. - -If you wish for hooks and formatters to only be used in specific environments, -you should handle that yourself. For example, if your application has a global -variable `Environment`, which is a string representation of the environment you -could do: - -```go -import ( - log "github.com/sirupsen/logrus" -) - -init() { - // do something here to set environment depending on an environment variable - // or command-line flag - if Environment == "production" { - log.SetFormatter(&log.JSONFormatter{}) - } else { - // The TextFormatter is default, you don't actually have to do this. - log.SetFormatter(&log.TextFormatter{}) - } -} -``` - -This configuration is how `logrus` was intended to be used, but JSON in -production is mostly only useful if you do log aggregation with tools like -Splunk or Logstash. - -#### Formatters - -The built-in logging formatters are: - -* `logrus.TextFormatter`. Logs the event in colors if stdout is a tty, otherwise - without colors. - * *Note:* to force colored output when there is no TTY, set the `ForceColors` - field to `true`. To force no colored output even if there is a TTY set the - `DisableColors` field to `true`. For Windows, see - [github.com/mattn/go-colorable](https://github.com/mattn/go-colorable). - * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#TextFormatter). -* `logrus.JSONFormatter`. Logs fields as JSON. - * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#JSONFormatter). - -Third party logging formatters: - -* [`FluentdFormatter`](https://github.com/joonix/log). Formats entries that can by parsed by Kubernetes and Google Container Engine. -* [`logstash`](https://github.com/bshuster-repo/logrus-logstash-hook). Logs fields as [Logstash](http://logstash.net) Events. -* [`prefixed`](https://github.com/x-cray/logrus-prefixed-formatter). Displays log entry source along with alternative layout. -* [`zalgo`](https://github.com/aybabtme/logzalgo). Invoking the P͉̫o̳̼̊w̖͈̰͎e̬͔̭͂r͚̼̹̲ ̫͓͉̳͈ō̠͕͖̚f̝͍̠ ͕̲̞͖͑Z̖̫̤̫ͪa͉̬͈̗l͖͎g̳̥o̰̥̅!̣͔̲̻͊̄ ̙̘̦̹̦. - -You can define your formatter by implementing the `Formatter` interface, -requiring a `Format` method. `Format` takes an `*Entry`. `entry.Data` is a -`Fields` type (`map[string]interface{}`) with all your fields as well as the -default ones (see Entries section above): - -```go -type MyJSONFormatter struct { -} - -log.SetFormatter(new(MyJSONFormatter)) - -func (f *MyJSONFormatter) Format(entry *Entry) ([]byte, error) { - // Note this doesn't include Time, Level and Message which are available on - // the Entry. Consult `godoc` on information about those fields or read the - // source of the official loggers. - serialized, err := json.Marshal(entry.Data) - if err != nil { - return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err) - } - return append(serialized, '\n'), nil -} -``` - -#### Logger as an `io.Writer` - -Logrus can be transformed into an `io.Writer`. That writer is the end of an `io.Pipe` and it is your responsibility to close it. - -```go -w := logger.Writer() -defer w.Close() - -srv := http.Server{ - // create a stdlib log.Logger that writes to - // logrus.Logger. - ErrorLog: log.New(w, "", 0), -} -``` - -Each line written to that writer will be printed the usual way, using formatters -and hooks. The level for those entries is `info`. - -This means that we can override the standard library logger easily: - -```go -logger := logrus.New() -logger.Formatter = &logrus.JSONFormatter{} - -// Use logrus for standard log output -// Note that `log` here references stdlib's log -// Not logrus imported under the name `log`. -log.SetOutput(logger.Writer()) -``` - -#### Rotation - -Log rotation is not provided with Logrus. Log rotation should be done by an -external program (like `logrotate(8)`) that can compress and delete old log -entries. It should not be a feature of the application-level logger. - -#### Tools - -| Tool | Description | -| ---- | ----------- | -|[Logrus Mate](https://github.com/gogap/logrus_mate)|Logrus mate is a tool for Logrus to manage loggers, you can initial logger's level, hook and formatter by config file, the logger will generated with different config at different environment.| -|[Logrus Viper Helper](https://github.com/heirko/go-contrib/tree/master/logrusHelper)|An Helper around Logrus to wrap with spf13/Viper to load configuration with fangs! And to simplify Logrus configuration use some behavior of [Logrus Mate](https://github.com/gogap/logrus_mate). [sample](https://github.com/heirko/iris-contrib/blob/master/middleware/logrus-logger/example) | - -#### Testing - -Logrus has a built in facility for asserting the presence of log messages. This is implemented through the `test` hook and provides: - -* decorators for existing logger (`test.NewLocal` and `test.NewGlobal`) which basically just add the `test` hook -* a test logger (`test.NewNullLogger`) that just records log messages (and does not output any): - -```go -import( - "github.com/sirupsen/logrus" - "github.com/sirupsen/logrus/hooks/test" - "github.com/stretchr/testify/assert" - "testing" -) - -func TestSomething(t*testing.T){ - logger, hook := test.NewNullLogger() - logger.Error("Helloerror") - - assert.Equal(t, 1, len(hook.Entries)) - assert.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level) - assert.Equal(t, "Helloerror", hook.LastEntry().Message) - - hook.Reset() - assert.Nil(t, hook.LastEntry()) -} -``` - -#### Fatal handlers - -Logrus can register one or more functions that will be called when any `fatal` -level message is logged. The registered handlers will be executed before -logrus performs a `os.Exit(1)`. This behavior may be helpful if callers need -to gracefully shutdown. Unlike a `panic("Something went wrong...")` call which can be intercepted with a deferred `recover` a call to `os.Exit(1)` can not be intercepted. - -``` -... -handler := func() { - // gracefully shutdown something... -} -logrus.RegisterExitHandler(handler) -... -``` - -#### Thread safety - -By default Logger is protected by mutex for concurrent writes, this mutex is invoked when calling hooks and writing logs. -If you are sure such locking is not needed, you can call logger.SetNoLock() to disable the locking. - -Situation when locking is not needed includes: - -* You have no hooks registered, or hooks calling is already thread-safe. - -* Writing to logger.Out is already thread-safe, for example: - - 1) logger.Out is protected by locks. - - 2) logger.Out is a os.File handler opened with `O_APPEND` flag, and every write is smaller than 4k. (This allow multi-thread/multi-process writing) - - (Refer to http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/) diff --git a/vendor/github.com/Sirupsen/logrus/alt_exit.go b/vendor/github.com/Sirupsen/logrus/alt_exit.go deleted file mode 100644 index 8af9063..0000000 --- a/vendor/github.com/Sirupsen/logrus/alt_exit.go +++ /dev/null @@ -1,64 +0,0 @@ -package logrus - -// The following code was sourced and modified from the -// https://github.com/tebeka/atexit package governed by the following license: -// -// Copyright (c) 2012 Miki Tebeka . -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -import ( - "fmt" - "os" -) - -var handlers = []func(){} - -func runHandler(handler func()) { - defer func() { - if err := recover(); err != nil { - fmt.Fprintln(os.Stderr, "Error: Logrus exit handler error:", err) - } - }() - - handler() -} - -func runHandlers() { - for _, handler := range handlers { - runHandler(handler) - } -} - -// Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code) -func Exit(code int) { - runHandlers() - os.Exit(code) -} - -// RegisterExitHandler adds a Logrus Exit handler, call logrus.Exit to invoke -// all handlers. The handlers will also be invoked when any Fatal log entry is -// made. -// -// This method is useful when a caller wishes to use logrus to log a fatal -// message but also needs to gracefully shutdown. An example usecase could be -// closing database connections, or sending a alert that the application is -// closing. -func RegisterExitHandler(handler func()) { - handlers = append(handlers, handler) -} diff --git a/vendor/github.com/Sirupsen/logrus/alt_exit_test.go b/vendor/github.com/Sirupsen/logrus/alt_exit_test.go deleted file mode 100644 index a08b1a8..0000000 --- a/vendor/github.com/Sirupsen/logrus/alt_exit_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package logrus - -import ( - "io/ioutil" - "log" - "os" - "os/exec" - "path/filepath" - "testing" - "time" -) - -func TestRegister(t *testing.T) { - current := len(handlers) - RegisterExitHandler(func() {}) - if len(handlers) != current+1 { - t.Fatalf("expected %d handlers, got %d", current+1, len(handlers)) - } -} - -func TestHandler(t *testing.T) { - tempDir, err := ioutil.TempDir("", "test_handler") - if err != nil { - log.Fatalf("can't create temp dir. %q", err) - } - defer os.RemoveAll(tempDir) - - gofile := filepath.Join(tempDir, "gofile.go") - if err := ioutil.WriteFile(gofile, testprog, 0666); err != nil { - t.Fatalf("can't create go file. %q", err) - } - - outfile := filepath.Join(tempDir, "outfile.out") - arg := time.Now().UTC().String() - err = exec.Command("go", "run", gofile, outfile, arg).Run() - if err == nil { - t.Fatalf("completed normally, should have failed") - } - - data, err := ioutil.ReadFile(outfile) - if err != nil { - t.Fatalf("can't read output file %s. %q", outfile, err) - } - - if string(data) != arg { - t.Fatalf("bad data. Expected %q, got %q", data, arg) - } -} - -var testprog = []byte(` -// Test program for atexit, gets output file and data as arguments and writes -// data to output file in atexit handler. -package main - -import ( - "github.com/sirupsen/logrus" - "flag" - "fmt" - "io/ioutil" -) - -var outfile = "" -var data = "" - -func handler() { - ioutil.WriteFile(outfile, []byte(data), 0666) -} - -func badHandler() { - n := 0 - fmt.Println(1/n) -} - -func main() { - flag.Parse() - outfile = flag.Arg(0) - data = flag.Arg(1) - - logrus.RegisterExitHandler(handler) - logrus.RegisterExitHandler(badHandler) - logrus.Fatal("Bye bye") -} -`) diff --git a/vendor/github.com/Sirupsen/logrus/appveyor.yml b/vendor/github.com/Sirupsen/logrus/appveyor.yml deleted file mode 100644 index 96c2ce1..0000000 --- a/vendor/github.com/Sirupsen/logrus/appveyor.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: "{build}" -platform: x64 -clone_folder: c:\gopath\src\github.com\sirupsen\logrus -environment: - GOPATH: c:\gopath -branches: - only: - - master -install: - - set PATH=%GOPATH%\bin;c:\go\bin;%PATH% - - go version -build_script: - - go get -t - - go test diff --git a/vendor/github.com/Sirupsen/logrus/doc.go b/vendor/github.com/Sirupsen/logrus/doc.go deleted file mode 100644 index da67aba..0000000 --- a/vendor/github.com/Sirupsen/logrus/doc.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Package logrus is a structured logger for Go, completely API compatible with the standard library logger. - - -The simplest way to use Logrus is simply the package-level exported logger: - - package main - - import ( - log "github.com/sirupsen/logrus" - ) - - func main() { - log.WithFields(log.Fields{ - "animal": "walrus", - "number": 1, - "size": 10, - }).Info("A walrus appears") - } - -Output: - time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10 - -For a full guide visit https://github.com/sirupsen/logrus -*/ -package logrus diff --git a/vendor/github.com/Sirupsen/logrus/entry.go b/vendor/github.com/Sirupsen/logrus/entry.go deleted file mode 100644 index 5bf582e..0000000 --- a/vendor/github.com/Sirupsen/logrus/entry.go +++ /dev/null @@ -1,276 +0,0 @@ -package logrus - -import ( - "bytes" - "fmt" - "os" - "sync" - "time" -) - -var bufferPool *sync.Pool - -func init() { - bufferPool = &sync.Pool{ - New: func() interface{} { - return new(bytes.Buffer) - }, - } -} - -// Defines the key when adding errors using WithError. -var ErrorKey = "error" - -// An entry is the final or intermediate Logrus logging entry. It contains all -// the fields passed with WithField{,s}. It's finally logged when Debug, Info, -// Warn, Error, Fatal or Panic is called on it. These objects can be reused and -// passed around as much as you wish to avoid field duplication. -type Entry struct { - Logger *Logger - - // Contains all the fields set by the user. - Data Fields - - // Time at which the log entry was created - Time time.Time - - // Level the log entry was logged at: Debug, Info, Warn, Error, Fatal or Panic - // This field will be set on entry firing and the value will be equal to the one in Logger struct field. - Level Level - - // Message passed to Debug, Info, Warn, Error, Fatal or Panic - Message string - - // When formatter is called in entry.log(), an Buffer may be set to entry - Buffer *bytes.Buffer -} - -func NewEntry(logger *Logger) *Entry { - return &Entry{ - Logger: logger, - // Default is three fields, give a little extra room - Data: make(Fields, 5), - } -} - -// Returns the string representation from the reader and ultimately the -// formatter. -func (entry *Entry) String() (string, error) { - serialized, err := entry.Logger.Formatter.Format(entry) - if err != nil { - return "", err - } - str := string(serialized) - return str, nil -} - -// Add an error as single field (using the key defined in ErrorKey) to the Entry. -func (entry *Entry) WithError(err error) *Entry { - return entry.WithField(ErrorKey, err) -} - -// Add a single field to the Entry. -func (entry *Entry) WithField(key string, value interface{}) *Entry { - return entry.WithFields(Fields{key: value}) -} - -// Add a map of fields to the Entry. -func (entry *Entry) WithFields(fields Fields) *Entry { - data := make(Fields, len(entry.Data)+len(fields)) - for k, v := range entry.Data { - data[k] = v - } - for k, v := range fields { - data[k] = v - } - return &Entry{Logger: entry.Logger, Data: data} -} - -// This function is not declared with a pointer value because otherwise -// race conditions will occur when using multiple goroutines -func (entry Entry) log(level Level, msg string) { - var buffer *bytes.Buffer - entry.Time = time.Now() - entry.Level = level - entry.Message = msg - - if err := entry.Logger.Hooks.Fire(level, &entry); err != nil { - entry.Logger.mu.Lock() - fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err) - entry.Logger.mu.Unlock() - } - buffer = bufferPool.Get().(*bytes.Buffer) - buffer.Reset() - defer bufferPool.Put(buffer) - entry.Buffer = buffer - serialized, err := entry.Logger.Formatter.Format(&entry) - entry.Buffer = nil - if err != nil { - entry.Logger.mu.Lock() - fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err) - entry.Logger.mu.Unlock() - } else { - entry.Logger.mu.Lock() - _, err = entry.Logger.Out.Write(serialized) - if err != nil { - fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) - } - entry.Logger.mu.Unlock() - } - - // To avoid Entry#log() returning a value that only would make sense for - // panic() to use in Entry#Panic(), we avoid the allocation by checking - // directly here. - if level <= PanicLevel { - panic(&entry) - } -} - -func (entry *Entry) Debug(args ...interface{}) { - if entry.Logger.level() >= DebugLevel { - entry.log(DebugLevel, fmt.Sprint(args...)) - } -} - -func (entry *Entry) Print(args ...interface{}) { - entry.Info(args...) -} - -func (entry *Entry) Info(args ...interface{}) { - if entry.Logger.level() >= InfoLevel { - entry.log(InfoLevel, fmt.Sprint(args...)) - } -} - -func (entry *Entry) Warn(args ...interface{}) { - if entry.Logger.level() >= WarnLevel { - entry.log(WarnLevel, fmt.Sprint(args...)) - } -} - -func (entry *Entry) Warning(args ...interface{}) { - entry.Warn(args...) -} - -func (entry *Entry) Error(args ...interface{}) { - if entry.Logger.level() >= ErrorLevel { - entry.log(ErrorLevel, fmt.Sprint(args...)) - } -} - -func (entry *Entry) Fatal(args ...interface{}) { - if entry.Logger.level() >= FatalLevel { - entry.log(FatalLevel, fmt.Sprint(args...)) - } - Exit(1) -} - -func (entry *Entry) Panic(args ...interface{}) { - if entry.Logger.level() >= PanicLevel { - entry.log(PanicLevel, fmt.Sprint(args...)) - } - panic(fmt.Sprint(args...)) -} - -// Entry Printf family functions - -func (entry *Entry) Debugf(format string, args ...interface{}) { - if entry.Logger.level() >= DebugLevel { - entry.Debug(fmt.Sprintf(format, args...)) - } -} - -func (entry *Entry) Infof(format string, args ...interface{}) { - if entry.Logger.level() >= InfoLevel { - entry.Info(fmt.Sprintf(format, args...)) - } -} - -func (entry *Entry) Printf(format string, args ...interface{}) { - entry.Infof(format, args...) -} - -func (entry *Entry) Warnf(format string, args ...interface{}) { - if entry.Logger.level() >= WarnLevel { - entry.Warn(fmt.Sprintf(format, args...)) - } -} - -func (entry *Entry) Warningf(format string, args ...interface{}) { - entry.Warnf(format, args...) -} - -func (entry *Entry) Errorf(format string, args ...interface{}) { - if entry.Logger.level() >= ErrorLevel { - entry.Error(fmt.Sprintf(format, args...)) - } -} - -func (entry *Entry) Fatalf(format string, args ...interface{}) { - if entry.Logger.level() >= FatalLevel { - entry.Fatal(fmt.Sprintf(format, args...)) - } - Exit(1) -} - -func (entry *Entry) Panicf(format string, args ...interface{}) { - if entry.Logger.level() >= PanicLevel { - entry.Panic(fmt.Sprintf(format, args...)) - } -} - -// Entry Println family functions - -func (entry *Entry) Debugln(args ...interface{}) { - if entry.Logger.level() >= DebugLevel { - entry.Debug(entry.sprintlnn(args...)) - } -} - -func (entry *Entry) Infoln(args ...interface{}) { - if entry.Logger.level() >= InfoLevel { - entry.Info(entry.sprintlnn(args...)) - } -} - -func (entry *Entry) Println(args ...interface{}) { - entry.Infoln(args...) -} - -func (entry *Entry) Warnln(args ...interface{}) { - if entry.Logger.level() >= WarnLevel { - entry.Warn(entry.sprintlnn(args...)) - } -} - -func (entry *Entry) Warningln(args ...interface{}) { - entry.Warnln(args...) -} - -func (entry *Entry) Errorln(args ...interface{}) { - if entry.Logger.level() >= ErrorLevel { - entry.Error(entry.sprintlnn(args...)) - } -} - -func (entry *Entry) Fatalln(args ...interface{}) { - if entry.Logger.level() >= FatalLevel { - entry.Fatal(entry.sprintlnn(args...)) - } - Exit(1) -} - -func (entry *Entry) Panicln(args ...interface{}) { - if entry.Logger.level() >= PanicLevel { - entry.Panic(entry.sprintlnn(args...)) - } -} - -// Sprintlnn => Sprint no newline. This is to get the behavior of how -// fmt.Sprintln where spaces are always added between operands, regardless of -// their type. Instead of vendoring the Sprintln implementation to spare a -// string allocation, we do the simplest thing. -func (entry *Entry) sprintlnn(args ...interface{}) string { - msg := fmt.Sprintln(args...) - return msg[:len(msg)-1] -} diff --git a/vendor/github.com/Sirupsen/logrus/entry_test.go b/vendor/github.com/Sirupsen/logrus/entry_test.go deleted file mode 100644 index 99c3b41..0000000 --- a/vendor/github.com/Sirupsen/logrus/entry_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package logrus - -import ( - "bytes" - "fmt" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestEntryWithError(t *testing.T) { - - assert := assert.New(t) - - defer func() { - ErrorKey = "error" - }() - - err := fmt.Errorf("kaboom at layer %d", 4711) - - assert.Equal(err, WithError(err).Data["error"]) - - logger := New() - logger.Out = &bytes.Buffer{} - entry := NewEntry(logger) - - assert.Equal(err, entry.WithError(err).Data["error"]) - - ErrorKey = "err" - - assert.Equal(err, entry.WithError(err).Data["err"]) - -} - -func TestEntryPanicln(t *testing.T) { - errBoom := fmt.Errorf("boom time") - - defer func() { - p := recover() - assert.NotNil(t, p) - - switch pVal := p.(type) { - case *Entry: - assert.Equal(t, "kaboom", pVal.Message) - assert.Equal(t, errBoom, pVal.Data["err"]) - default: - t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal) - } - }() - - logger := New() - logger.Out = &bytes.Buffer{} - entry := NewEntry(logger) - entry.WithField("err", errBoom).Panicln("kaboom") -} - -func TestEntryPanicf(t *testing.T) { - errBoom := fmt.Errorf("boom again") - - defer func() { - p := recover() - assert.NotNil(t, p) - - switch pVal := p.(type) { - case *Entry: - assert.Equal(t, "kaboom true", pVal.Message) - assert.Equal(t, errBoom, pVal.Data["err"]) - default: - t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal) - } - }() - - logger := New() - logger.Out = &bytes.Buffer{} - entry := NewEntry(logger) - entry.WithField("err", errBoom).Panicf("kaboom %v", true) -} diff --git a/vendor/github.com/Sirupsen/logrus/example_basic_test.go b/vendor/github.com/Sirupsen/logrus/example_basic_test.go deleted file mode 100644 index a2acf55..0000000 --- a/vendor/github.com/Sirupsen/logrus/example_basic_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package logrus_test - -import ( - "github.com/sirupsen/logrus" - "os" -) - -func Example_basic() { - var log = logrus.New() - log.Formatter = new(logrus.JSONFormatter) - log.Formatter = new(logrus.TextFormatter) //default - log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output - log.Level = logrus.DebugLevel - log.Out = os.Stdout - - // file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666) - // if err == nil { - // log.Out = file - // } else { - // log.Info("Failed to log to file, using default stderr") - // } - - defer func() { - err := recover() - if err != nil { - entry := err.(*logrus.Entry) - log.WithFields(logrus.Fields{ - "omg": true, - "err_animal": entry.Data["animal"], - "err_size": entry.Data["size"], - "err_level": entry.Level, - "err_message": entry.Message, - "number": 100, - }).Error("The ice breaks!") // or use Fatal() to force the process to exit with a nonzero code - } - }() - - log.WithFields(logrus.Fields{ - "animal": "walrus", - "number": 8, - }).Debug("Started observing beach") - - log.WithFields(logrus.Fields{ - "animal": "walrus", - "size": 10, - }).Info("A group of walrus emerges from the ocean") - - log.WithFields(logrus.Fields{ - "omg": true, - "number": 122, - }).Warn("The group's number increased tremendously!") - - log.WithFields(logrus.Fields{ - "temperature": -4, - }).Debug("Temperature changes") - - log.WithFields(logrus.Fields{ - "animal": "orca", - "size": 9009, - }).Panic("It's over 9000!") - - // Output: - // level=debug msg="Started observing beach" animal=walrus number=8 - // level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10 - // level=warning msg="The group's number increased tremendously!" number=122 omg=true - // level=debug msg="Temperature changes" temperature=-4 - // level=panic msg="It's over 9000!" animal=orca size=9009 - // level=error msg="The ice breaks!" err_animal=orca err_level=panic err_message="It's over 9000!" err_size=9009 number=100 omg=true -} diff --git a/vendor/github.com/Sirupsen/logrus/example_hook_test.go b/vendor/github.com/Sirupsen/logrus/example_hook_test.go deleted file mode 100644 index d4ddffc..0000000 --- a/vendor/github.com/Sirupsen/logrus/example_hook_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package logrus_test - -import ( - "github.com/sirupsen/logrus" - "gopkg.in/gemnasium/logrus-airbrake-hook.v2" - "os" -) - -func Example_hook() { - var log = logrus.New() - log.Formatter = new(logrus.TextFormatter) // default - log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output - log.Hooks.Add(airbrake.NewHook(123, "xyz", "development")) - log.Out = os.Stdout - - log.WithFields(logrus.Fields{ - "animal": "walrus", - "size": 10, - }).Info("A group of walrus emerges from the ocean") - - log.WithFields(logrus.Fields{ - "omg": true, - "number": 122, - }).Warn("The group's number increased tremendously!") - - log.WithFields(logrus.Fields{ - "omg": true, - "number": 100, - }).Error("The ice breaks!") - - // Output: - // level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10 - // level=warning msg="The group's number increased tremendously!" number=122 omg=true - // level=error msg="The ice breaks!" number=100 omg=true -} diff --git a/vendor/github.com/Sirupsen/logrus/exported.go b/vendor/github.com/Sirupsen/logrus/exported.go deleted file mode 100644 index 013183e..0000000 --- a/vendor/github.com/Sirupsen/logrus/exported.go +++ /dev/null @@ -1,193 +0,0 @@ -package logrus - -import ( - "io" -) - -var ( - // std is the name of the standard logger in stdlib `log` - std = New() -) - -func StandardLogger() *Logger { - return std -} - -// SetOutput sets the standard logger output. -func SetOutput(out io.Writer) { - std.mu.Lock() - defer std.mu.Unlock() - std.Out = out -} - -// SetFormatter sets the standard logger formatter. -func SetFormatter(formatter Formatter) { - std.mu.Lock() - defer std.mu.Unlock() - std.Formatter = formatter -} - -// SetLevel sets the standard logger level. -func SetLevel(level Level) { - std.mu.Lock() - defer std.mu.Unlock() - std.SetLevel(level) -} - -// GetLevel returns the standard logger level. -func GetLevel() Level { - std.mu.Lock() - defer std.mu.Unlock() - return std.level() -} - -// AddHook adds a hook to the standard logger hooks. -func AddHook(hook Hook) { - std.mu.Lock() - defer std.mu.Unlock() - std.Hooks.Add(hook) -} - -// WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key. -func WithError(err error) *Entry { - return std.WithField(ErrorKey, err) -} - -// WithField creates an entry from the standard logger and adds a field to -// it. If you want multiple fields, use `WithFields`. -// -// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal -// or Panic on the Entry it returns. -func WithField(key string, value interface{}) *Entry { - return std.WithField(key, value) -} - -// WithFields creates an entry from the standard logger and adds multiple -// fields to it. This is simply a helper for `WithField`, invoking it -// once for each field. -// -// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal -// or Panic on the Entry it returns. -func WithFields(fields Fields) *Entry { - return std.WithFields(fields) -} - -// Debug logs a message at level Debug on the standard logger. -func Debug(args ...interface{}) { - std.Debug(args...) -} - -// Print logs a message at level Info on the standard logger. -func Print(args ...interface{}) { - std.Print(args...) -} - -// Info logs a message at level Info on the standard logger. -func Info(args ...interface{}) { - std.Info(args...) -} - -// Warn logs a message at level Warn on the standard logger. -func Warn(args ...interface{}) { - std.Warn(args...) -} - -// Warning logs a message at level Warn on the standard logger. -func Warning(args ...interface{}) { - std.Warning(args...) -} - -// Error logs a message at level Error on the standard logger. -func Error(args ...interface{}) { - std.Error(args...) -} - -// Panic logs a message at level Panic on the standard logger. -func Panic(args ...interface{}) { - std.Panic(args...) -} - -// Fatal logs a message at level Fatal on the standard logger. -func Fatal(args ...interface{}) { - std.Fatal(args...) -} - -// Debugf logs a message at level Debug on the standard logger. -func Debugf(format string, args ...interface{}) { - std.Debugf(format, args...) -} - -// Printf logs a message at level Info on the standard logger. -func Printf(format string, args ...interface{}) { - std.Printf(format, args...) -} - -// Infof logs a message at level Info on the standard logger. -func Infof(format string, args ...interface{}) { - std.Infof(format, args...) -} - -// Warnf logs a message at level Warn on the standard logger. -func Warnf(format string, args ...interface{}) { - std.Warnf(format, args...) -} - -// Warningf logs a message at level Warn on the standard logger. -func Warningf(format string, args ...interface{}) { - std.Warningf(format, args...) -} - -// Errorf logs a message at level Error on the standard logger. -func Errorf(format string, args ...interface{}) { - std.Errorf(format, args...) -} - -// Panicf logs a message at level Panic on the standard logger. -func Panicf(format string, args ...interface{}) { - std.Panicf(format, args...) -} - -// Fatalf logs a message at level Fatal on the standard logger. -func Fatalf(format string, args ...interface{}) { - std.Fatalf(format, args...) -} - -// Debugln logs a message at level Debug on the standard logger. -func Debugln(args ...interface{}) { - std.Debugln(args...) -} - -// Println logs a message at level Info on the standard logger. -func Println(args ...interface{}) { - std.Println(args...) -} - -// Infoln logs a message at level Info on the standard logger. -func Infoln(args ...interface{}) { - std.Infoln(args...) -} - -// Warnln logs a message at level Warn on the standard logger. -func Warnln(args ...interface{}) { - std.Warnln(args...) -} - -// Warningln logs a message at level Warn on the standard logger. -func Warningln(args ...interface{}) { - std.Warningln(args...) -} - -// Errorln logs a message at level Error on the standard logger. -func Errorln(args ...interface{}) { - std.Errorln(args...) -} - -// Panicln logs a message at level Panic on the standard logger. -func Panicln(args ...interface{}) { - std.Panicln(args...) -} - -// Fatalln logs a message at level Fatal on the standard logger. -func Fatalln(args ...interface{}) { - std.Fatalln(args...) -} diff --git a/vendor/github.com/Sirupsen/logrus/formatter.go b/vendor/github.com/Sirupsen/logrus/formatter.go deleted file mode 100644 index b183ff5..0000000 --- a/vendor/github.com/Sirupsen/logrus/formatter.go +++ /dev/null @@ -1,45 +0,0 @@ -package logrus - -import "time" - -const defaultTimestampFormat = time.RFC3339 - -// The Formatter interface is used to implement a custom Formatter. It takes an -// `Entry`. It exposes all the fields, including the default ones: -// -// * `entry.Data["msg"]`. The message passed from Info, Warn, Error .. -// * `entry.Data["time"]`. The timestamp. -// * `entry.Data["level"]. The level the entry was logged at. -// -// Any additional fields added with `WithField` or `WithFields` are also in -// `entry.Data`. Format is expected to return an array of bytes which are then -// logged to `logger.Out`. -type Formatter interface { - Format(*Entry) ([]byte, error) -} - -// This is to not silently overwrite `time`, `msg` and `level` fields when -// dumping it. If this code wasn't there doing: -// -// logrus.WithField("level", 1).Info("hello") -// -// Would just silently drop the user provided level. Instead with this code -// it'll logged as: -// -// {"level": "info", "fields.level": 1, "msg": "hello", "time": "..."} -// -// It's not exported because it's still using Data in an opinionated way. It's to -// avoid code duplication between the two default formatters. -func prefixFieldClashes(data Fields) { - if t, ok := data["time"]; ok { - data["fields.time"] = t - } - - if m, ok := data["msg"]; ok { - data["fields.msg"] = m - } - - if l, ok := data["level"]; ok { - data["fields.level"] = l - } -} diff --git a/vendor/github.com/Sirupsen/logrus/formatter_bench_test.go b/vendor/github.com/Sirupsen/logrus/formatter_bench_test.go deleted file mode 100644 index d948158..0000000 --- a/vendor/github.com/Sirupsen/logrus/formatter_bench_test.go +++ /dev/null @@ -1,101 +0,0 @@ -package logrus - -import ( - "fmt" - "testing" - "time" -) - -// smallFields is a small size data set for benchmarking -var smallFields = Fields{ - "foo": "bar", - "baz": "qux", - "one": "two", - "three": "four", -} - -// largeFields is a large size data set for benchmarking -var largeFields = Fields{ - "foo": "bar", - "baz": "qux", - "one": "two", - "three": "four", - "five": "six", - "seven": "eight", - "nine": "ten", - "eleven": "twelve", - "thirteen": "fourteen", - "fifteen": "sixteen", - "seventeen": "eighteen", - "nineteen": "twenty", - "a": "b", - "c": "d", - "e": "f", - "g": "h", - "i": "j", - "k": "l", - "m": "n", - "o": "p", - "q": "r", - "s": "t", - "u": "v", - "w": "x", - "y": "z", - "this": "will", - "make": "thirty", - "entries": "yeah", -} - -var errorFields = Fields{ - "foo": fmt.Errorf("bar"), - "baz": fmt.Errorf("qux"), -} - -func BenchmarkErrorTextFormatter(b *testing.B) { - doBenchmark(b, &TextFormatter{DisableColors: true}, errorFields) -} - -func BenchmarkSmallTextFormatter(b *testing.B) { - doBenchmark(b, &TextFormatter{DisableColors: true}, smallFields) -} - -func BenchmarkLargeTextFormatter(b *testing.B) { - doBenchmark(b, &TextFormatter{DisableColors: true}, largeFields) -} - -func BenchmarkSmallColoredTextFormatter(b *testing.B) { - doBenchmark(b, &TextFormatter{ForceColors: true}, smallFields) -} - -func BenchmarkLargeColoredTextFormatter(b *testing.B) { - doBenchmark(b, &TextFormatter{ForceColors: true}, largeFields) -} - -func BenchmarkSmallJSONFormatter(b *testing.B) { - doBenchmark(b, &JSONFormatter{}, smallFields) -} - -func BenchmarkLargeJSONFormatter(b *testing.B) { - doBenchmark(b, &JSONFormatter{}, largeFields) -} - -func doBenchmark(b *testing.B, formatter Formatter, fields Fields) { - logger := New() - - entry := &Entry{ - Time: time.Time{}, - Level: InfoLevel, - Message: "message", - Data: fields, - Logger: logger, - } - var d []byte - var err error - for i := 0; i < b.N; i++ { - d, err = formatter.Format(entry) - if err != nil { - b.Fatal(err) - } - b.SetBytes(int64(len(d))) - } -} diff --git a/vendor/github.com/Sirupsen/logrus/hook_test.go b/vendor/github.com/Sirupsen/logrus/hook_test.go deleted file mode 100644 index 13f34cb..0000000 --- a/vendor/github.com/Sirupsen/logrus/hook_test.go +++ /dev/null @@ -1,122 +0,0 @@ -package logrus - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -type TestHook struct { - Fired bool -} - -func (hook *TestHook) Fire(entry *Entry) error { - hook.Fired = true - return nil -} - -func (hook *TestHook) Levels() []Level { - return []Level{ - DebugLevel, - InfoLevel, - WarnLevel, - ErrorLevel, - FatalLevel, - PanicLevel, - } -} - -func TestHookFires(t *testing.T) { - hook := new(TestHook) - - LogAndAssertJSON(t, func(log *Logger) { - log.Hooks.Add(hook) - assert.Equal(t, hook.Fired, false) - - log.Print("test") - }, func(fields Fields) { - assert.Equal(t, hook.Fired, true) - }) -} - -type ModifyHook struct { -} - -func (hook *ModifyHook) Fire(entry *Entry) error { - entry.Data["wow"] = "whale" - return nil -} - -func (hook *ModifyHook) Levels() []Level { - return []Level{ - DebugLevel, - InfoLevel, - WarnLevel, - ErrorLevel, - FatalLevel, - PanicLevel, - } -} - -func TestHookCanModifyEntry(t *testing.T) { - hook := new(ModifyHook) - - LogAndAssertJSON(t, func(log *Logger) { - log.Hooks.Add(hook) - log.WithField("wow", "elephant").Print("test") - }, func(fields Fields) { - assert.Equal(t, fields["wow"], "whale") - }) -} - -func TestCanFireMultipleHooks(t *testing.T) { - hook1 := new(ModifyHook) - hook2 := new(TestHook) - - LogAndAssertJSON(t, func(log *Logger) { - log.Hooks.Add(hook1) - log.Hooks.Add(hook2) - - log.WithField("wow", "elephant").Print("test") - }, func(fields Fields) { - assert.Equal(t, fields["wow"], "whale") - assert.Equal(t, hook2.Fired, true) - }) -} - -type ErrorHook struct { - Fired bool -} - -func (hook *ErrorHook) Fire(entry *Entry) error { - hook.Fired = true - return nil -} - -func (hook *ErrorHook) Levels() []Level { - return []Level{ - ErrorLevel, - } -} - -func TestErrorHookShouldntFireOnInfo(t *testing.T) { - hook := new(ErrorHook) - - LogAndAssertJSON(t, func(log *Logger) { - log.Hooks.Add(hook) - log.Info("test") - }, func(fields Fields) { - assert.Equal(t, hook.Fired, false) - }) -} - -func TestErrorHookShouldFireOnError(t *testing.T) { - hook := new(ErrorHook) - - LogAndAssertJSON(t, func(log *Logger) { - log.Hooks.Add(hook) - log.Error("test") - }, func(fields Fields) { - assert.Equal(t, hook.Fired, true) - }) -} diff --git a/vendor/github.com/Sirupsen/logrus/hooks.go b/vendor/github.com/Sirupsen/logrus/hooks.go deleted file mode 100644 index 3f151cd..0000000 --- a/vendor/github.com/Sirupsen/logrus/hooks.go +++ /dev/null @@ -1,34 +0,0 @@ -package logrus - -// A hook to be fired when logging on the logging levels returned from -// `Levels()` on your implementation of the interface. Note that this is not -// fired in a goroutine or a channel with workers, you should handle such -// functionality yourself if your call is non-blocking and you don't wish for -// the logging calls for levels returned from `Levels()` to block. -type Hook interface { - Levels() []Level - Fire(*Entry) error -} - -// Internal type for storing the hooks on a logger instance. -type LevelHooks map[Level][]Hook - -// Add a hook to an instance of logger. This is called with -// `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface. -func (hooks LevelHooks) Add(hook Hook) { - for _, level := range hook.Levels() { - hooks[level] = append(hooks[level], hook) - } -} - -// Fire all the hooks for the passed level. Used by `entry.log` to fire -// appropriate hooks for a log entry. -func (hooks LevelHooks) Fire(level Level, entry *Entry) error { - for _, hook := range hooks[level] { - if err := hook.Fire(entry); err != nil { - return err - } - } - - return nil -} diff --git a/vendor/github.com/Sirupsen/logrus/hooks/syslog/README.md b/vendor/github.com/Sirupsen/logrus/hooks/syslog/README.md deleted file mode 100644 index 1bbc0f7..0000000 --- a/vendor/github.com/Sirupsen/logrus/hooks/syslog/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# Syslog Hooks for Logrus :walrus: - -## Usage - -```go -import ( - "log/syslog" - "github.com/sirupsen/logrus" - lSyslog "github.com/sirupsen/logrus/hooks/syslog" -) - -func main() { - log := logrus.New() - hook, err := lSyslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "") - - if err == nil { - log.Hooks.Add(hook) - } -} -``` - -If you want to connect to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). Just assign empty string to the first two parameters of `NewSyslogHook`. It should look like the following. - -```go -import ( - "log/syslog" - "github.com/sirupsen/logrus" - lSyslog "github.com/sirupsen/logrus/hooks/syslog" -) - -func main() { - log := logrus.New() - hook, err := lSyslog.NewSyslogHook("", "", syslog.LOG_INFO, "") - - if err == nil { - log.Hooks.Add(hook) - } -} -``` diff --git a/vendor/github.com/Sirupsen/logrus/hooks/syslog/syslog.go b/vendor/github.com/Sirupsen/logrus/hooks/syslog/syslog.go deleted file mode 100644 index 329ce0d..0000000 --- a/vendor/github.com/Sirupsen/logrus/hooks/syslog/syslog.go +++ /dev/null @@ -1,55 +0,0 @@ -// +build !windows,!nacl,!plan9 - -package syslog - -import ( - "fmt" - "log/syslog" - "os" - - "github.com/sirupsen/logrus" -) - -// SyslogHook to send logs via syslog. -type SyslogHook struct { - Writer *syslog.Writer - SyslogNetwork string - SyslogRaddr string -} - -// Creates a hook to be added to an instance of logger. This is called with -// `hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_DEBUG, "")` -// `if err == nil { log.Hooks.Add(hook) }` -func NewSyslogHook(network, raddr string, priority syslog.Priority, tag string) (*SyslogHook, error) { - w, err := syslog.Dial(network, raddr, priority, tag) - return &SyslogHook{w, network, raddr}, err -} - -func (hook *SyslogHook) Fire(entry *logrus.Entry) error { - line, err := entry.String() - if err != nil { - fmt.Fprintf(os.Stderr, "Unable to read entry, %v", err) - return err - } - - switch entry.Level { - case logrus.PanicLevel: - return hook.Writer.Crit(line) - case logrus.FatalLevel: - return hook.Writer.Crit(line) - case logrus.ErrorLevel: - return hook.Writer.Err(line) - case logrus.WarnLevel: - return hook.Writer.Warning(line) - case logrus.InfoLevel: - return hook.Writer.Info(line) - case logrus.DebugLevel: - return hook.Writer.Debug(line) - default: - return nil - } -} - -func (hook *SyslogHook) Levels() []logrus.Level { - return logrus.AllLevels -} diff --git a/vendor/github.com/Sirupsen/logrus/hooks/syslog/syslog_test.go b/vendor/github.com/Sirupsen/logrus/hooks/syslog/syslog_test.go deleted file mode 100644 index 5ec3a44..0000000 --- a/vendor/github.com/Sirupsen/logrus/hooks/syslog/syslog_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package syslog - -import ( - "log/syslog" - "testing" - - "github.com/sirupsen/logrus" -) - -func TestLocalhostAddAndPrint(t *testing.T) { - log := logrus.New() - hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "") - - if err != nil { - t.Errorf("Unable to connect to local syslog.") - } - - log.Hooks.Add(hook) - - for _, level := range hook.Levels() { - if len(log.Hooks[level]) != 1 { - t.Errorf("SyslogHook was not added. The length of log.Hooks[%v]: %v", level, len(log.Hooks[level])) - } - } - - log.Info("Congratulations!") -} diff --git a/vendor/github.com/Sirupsen/logrus/hooks/test/test.go b/vendor/github.com/Sirupsen/logrus/hooks/test/test.go deleted file mode 100644 index 62c4845..0000000 --- a/vendor/github.com/Sirupsen/logrus/hooks/test/test.go +++ /dev/null @@ -1,95 +0,0 @@ -// The Test package is used for testing logrus. It is here for backwards -// compatibility from when logrus' organization was upper-case. Please use -// lower-case logrus and the `null` package instead of this one. -package test - -import ( - "io/ioutil" - "sync" - - "github.com/sirupsen/logrus" -) - -// Hook is a hook designed for dealing with logs in test scenarios. -type Hook struct { - // Entries is an array of all entries that have been received by this hook. - // For safe access, use the AllEntries() method, rather than reading this - // value directly. - Entries []*logrus.Entry - mu sync.RWMutex -} - -// NewGlobal installs a test hook for the global logger. -func NewGlobal() *Hook { - - hook := new(Hook) - logrus.AddHook(hook) - - return hook - -} - -// NewLocal installs a test hook for a given local logger. -func NewLocal(logger *logrus.Logger) *Hook { - - hook := new(Hook) - logger.Hooks.Add(hook) - - return hook - -} - -// NewNullLogger creates a discarding logger and installs the test hook. -func NewNullLogger() (*logrus.Logger, *Hook) { - - logger := logrus.New() - logger.Out = ioutil.Discard - - return logger, NewLocal(logger) - -} - -func (t *Hook) Fire(e *logrus.Entry) error { - t.mu.Lock() - defer t.mu.Unlock() - t.Entries = append(t.Entries, e) - return nil -} - -func (t *Hook) Levels() []logrus.Level { - return logrus.AllLevels -} - -// LastEntry returns the last entry that was logged or nil. -func (t *Hook) LastEntry() *logrus.Entry { - t.mu.RLock() - defer t.mu.RUnlock() - i := len(t.Entries) - 1 - if i < 0 { - return nil - } - // Make a copy, for safety - e := *t.Entries[i] - return &e -} - -// AllEntries returns all entries that were logged. -func (t *Hook) AllEntries() []*logrus.Entry { - t.mu.RLock() - defer t.mu.RUnlock() - // Make a copy so the returned value won't race with future log requests - entries := make([]*logrus.Entry, len(t.Entries)) - for i, entry := range t.Entries { - // Make a copy, for safety - e := *entry - entries[i] = &e - } - return entries -} - -// Reset removes all Entries from this test hook. -func (t *Hook) Reset() { - t.mu.Lock() - defer t.mu.Unlock() - t.Entries = make([]*logrus.Entry, 0) -} diff --git a/vendor/github.com/Sirupsen/logrus/hooks/test/test_test.go b/vendor/github.com/Sirupsen/logrus/hooks/test/test_test.go deleted file mode 100644 index 3f55cfe..0000000 --- a/vendor/github.com/Sirupsen/logrus/hooks/test/test_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package test - -import ( - "testing" - - "github.com/sirupsen/logrus" - "github.com/stretchr/testify/assert" -) - -func TestAllHooks(t *testing.T) { - - assert := assert.New(t) - - logger, hook := NewNullLogger() - assert.Nil(hook.LastEntry()) - assert.Equal(0, len(hook.Entries)) - - logger.Error("Hello error") - assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level) - assert.Equal("Hello error", hook.LastEntry().Message) - assert.Equal(1, len(hook.Entries)) - - logger.Warn("Hello warning") - assert.Equal(logrus.WarnLevel, hook.LastEntry().Level) - assert.Equal("Hello warning", hook.LastEntry().Message) - assert.Equal(2, len(hook.Entries)) - - hook.Reset() - assert.Nil(hook.LastEntry()) - assert.Equal(0, len(hook.Entries)) - - hook = NewGlobal() - - logrus.Error("Hello error") - assert.Equal(logrus.ErrorLevel, hook.LastEntry().Level) - assert.Equal("Hello error", hook.LastEntry().Message) - assert.Equal(1, len(hook.Entries)) - -} diff --git a/vendor/github.com/Sirupsen/logrus/json_formatter.go b/vendor/github.com/Sirupsen/logrus/json_formatter.go deleted file mode 100644 index fb01c1b..0000000 --- a/vendor/github.com/Sirupsen/logrus/json_formatter.go +++ /dev/null @@ -1,79 +0,0 @@ -package logrus - -import ( - "encoding/json" - "fmt" -) - -type fieldKey string - -// FieldMap allows customization of the key names for default fields. -type FieldMap map[fieldKey]string - -// Default key names for the default fields -const ( - FieldKeyMsg = "msg" - FieldKeyLevel = "level" - FieldKeyTime = "time" -) - -func (f FieldMap) resolve(key fieldKey) string { - if k, ok := f[key]; ok { - return k - } - - return string(key) -} - -// JSONFormatter formats logs into parsable json -type JSONFormatter struct { - // TimestampFormat sets the format used for marshaling timestamps. - TimestampFormat string - - // DisableTimestamp allows disabling automatic timestamps in output - DisableTimestamp bool - - // FieldMap allows users to customize the names of keys for default fields. - // As an example: - // formatter := &JSONFormatter{ - // FieldMap: FieldMap{ - // FieldKeyTime: "@timestamp", - // FieldKeyLevel: "@level", - // FieldKeyMsg: "@message", - // }, - // } - FieldMap FieldMap -} - -// Format renders a single log entry -func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { - data := make(Fields, len(entry.Data)+3) - for k, v := range entry.Data { - switch v := v.(type) { - case error: - // Otherwise errors are ignored by `encoding/json` - // https://github.com/sirupsen/logrus/issues/137 - data[k] = v.Error() - default: - data[k] = v - } - } - prefixFieldClashes(data) - - timestampFormat := f.TimestampFormat - if timestampFormat == "" { - timestampFormat = defaultTimestampFormat - } - - if !f.DisableTimestamp { - data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat) - } - data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message - data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String() - - serialized, err := json.Marshal(data) - if err != nil { - return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err) - } - return append(serialized, '\n'), nil -} diff --git a/vendor/github.com/Sirupsen/logrus/json_formatter_test.go b/vendor/github.com/Sirupsen/logrus/json_formatter_test.go deleted file mode 100644 index 51093a7..0000000 --- a/vendor/github.com/Sirupsen/logrus/json_formatter_test.go +++ /dev/null @@ -1,199 +0,0 @@ -package logrus - -import ( - "encoding/json" - "errors" - "strings" - "testing" -) - -func TestErrorNotLost(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("error", errors.New("wild walrus"))) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - entry := make(map[string]interface{}) - err = json.Unmarshal(b, &entry) - if err != nil { - t.Fatal("Unable to unmarshal formatted entry: ", err) - } - - if entry["error"] != "wild walrus" { - t.Fatal("Error field not set") - } -} - -func TestErrorNotLostOnFieldNotNamedError(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("omg", errors.New("wild walrus"))) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - entry := make(map[string]interface{}) - err = json.Unmarshal(b, &entry) - if err != nil { - t.Fatal("Unable to unmarshal formatted entry: ", err) - } - - if entry["omg"] != "wild walrus" { - t.Fatal("Error field not set") - } -} - -func TestFieldClashWithTime(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("time", "right now!")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - entry := make(map[string]interface{}) - err = json.Unmarshal(b, &entry) - if err != nil { - t.Fatal("Unable to unmarshal formatted entry: ", err) - } - - if entry["fields.time"] != "right now!" { - t.Fatal("fields.time not set to original time field") - } - - if entry["time"] != "0001-01-01T00:00:00Z" { - t.Fatal("time field not set to current time, was: ", entry["time"]) - } -} - -func TestFieldClashWithMsg(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("msg", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - entry := make(map[string]interface{}) - err = json.Unmarshal(b, &entry) - if err != nil { - t.Fatal("Unable to unmarshal formatted entry: ", err) - } - - if entry["fields.msg"] != "something" { - t.Fatal("fields.msg not set to original msg field") - } -} - -func TestFieldClashWithLevel(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - entry := make(map[string]interface{}) - err = json.Unmarshal(b, &entry) - if err != nil { - t.Fatal("Unable to unmarshal formatted entry: ", err) - } - - if entry["fields.level"] != "something" { - t.Fatal("fields.level not set to original level field") - } -} - -func TestJSONEntryEndsWithNewline(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - - if b[len(b)-1] != '\n' { - t.Fatal("Expected JSON log entry to end with a newline") - } -} - -func TestJSONMessageKey(t *testing.T) { - formatter := &JSONFormatter{ - FieldMap: FieldMap{ - FieldKeyMsg: "message", - }, - } - - b, err := formatter.Format(&Entry{Message: "oh hai"}) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - s := string(b) - if !(strings.Contains(s, "message") && strings.Contains(s, "oh hai")) { - t.Fatal("Expected JSON to format message key") - } -} - -func TestJSONLevelKey(t *testing.T) { - formatter := &JSONFormatter{ - FieldMap: FieldMap{ - FieldKeyLevel: "somelevel", - }, - } - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - s := string(b) - if !strings.Contains(s, "somelevel") { - t.Fatal("Expected JSON to format level key") - } -} - -func TestJSONTimeKey(t *testing.T) { - formatter := &JSONFormatter{ - FieldMap: FieldMap{ - FieldKeyTime: "timeywimey", - }, - } - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - s := string(b) - if !strings.Contains(s, "timeywimey") { - t.Fatal("Expected JSON to format time key") - } -} - -func TestJSONDisableTimestamp(t *testing.T) { - formatter := &JSONFormatter{ - DisableTimestamp: true, - } - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - s := string(b) - if strings.Contains(s, FieldKeyTime) { - t.Error("Did not prevent timestamp", s) - } -} - -func TestJSONEnableTimestamp(t *testing.T) { - formatter := &JSONFormatter{} - - b, err := formatter.Format(WithField("level", "something")) - if err != nil { - t.Fatal("Unable to format entry: ", err) - } - s := string(b) - if !strings.Contains(s, FieldKeyTime) { - t.Error("Timestamp not present", s) - } -} diff --git a/vendor/github.com/Sirupsen/logrus/logger.go b/vendor/github.com/Sirupsen/logrus/logger.go deleted file mode 100644 index 2acab05..0000000 --- a/vendor/github.com/Sirupsen/logrus/logger.go +++ /dev/null @@ -1,317 +0,0 @@ -package logrus - -import ( - "io" - "os" - "sync" - "sync/atomic" -) - -type Logger struct { - // The logs are `io.Copy`'d to this in a mutex. It's common to set this to a - // file, or leave it default which is `os.Stderr`. You can also set this to - // something more adventorous, such as logging to Kafka. - Out io.Writer - // Hooks for the logger instance. These allow firing events based on logging - // levels and log entries. For example, to send errors to an error tracking - // service, log to StatsD or dump the core on fatal errors. - Hooks LevelHooks - // All log entries pass through the formatter before logged to Out. The - // included formatters are `TextFormatter` and `JSONFormatter` for which - // TextFormatter is the default. In development (when a TTY is attached) it - // logs with colors, but to a file it wouldn't. You can easily implement your - // own that implements the `Formatter` interface, see the `README` or included - // formatters for examples. - Formatter Formatter - // The logging level the logger should log at. This is typically (and defaults - // to) `logrus.Info`, which allows Info(), Warn(), Error() and Fatal() to be - // logged. - Level Level - // Used to sync writing to the log. Locking is enabled by Default - mu MutexWrap - // Reusable empty entry - entryPool sync.Pool -} - -type MutexWrap struct { - lock sync.Mutex - disabled bool -} - -func (mw *MutexWrap) Lock() { - if !mw.disabled { - mw.lock.Lock() - } -} - -func (mw *MutexWrap) Unlock() { - if !mw.disabled { - mw.lock.Unlock() - } -} - -func (mw *MutexWrap) Disable() { - mw.disabled = true -} - -// Creates a new logger. Configuration should be set by changing `Formatter`, -// `Out` and `Hooks` directly on the default logger instance. You can also just -// instantiate your own: -// -// var log = &Logger{ -// Out: os.Stderr, -// Formatter: new(JSONFormatter), -// Hooks: make(LevelHooks), -// Level: logrus.DebugLevel, -// } -// -// It's recommended to make this a global instance called `log`. -func New() *Logger { - return &Logger{ - Out: os.Stderr, - Formatter: new(TextFormatter), - Hooks: make(LevelHooks), - Level: InfoLevel, - } -} - -func (logger *Logger) newEntry() *Entry { - entry, ok := logger.entryPool.Get().(*Entry) - if ok { - return entry - } - return NewEntry(logger) -} - -func (logger *Logger) releaseEntry(entry *Entry) { - logger.entryPool.Put(entry) -} - -// Adds a field to the log entry, note that it doesn't log until you call -// Debug, Print, Info, Warn, Fatal or Panic. It only creates a log entry. -// If you want multiple fields, use `WithFields`. -func (logger *Logger) WithField(key string, value interface{}) *Entry { - entry := logger.newEntry() - defer logger.releaseEntry(entry) - return entry.WithField(key, value) -} - -// Adds a struct of fields to the log entry. All it does is call `WithField` for -// each `Field`. -func (logger *Logger) WithFields(fields Fields) *Entry { - entry := logger.newEntry() - defer logger.releaseEntry(entry) - return entry.WithFields(fields) -} - -// Add an error as single field to the log entry. All it does is call -// `WithError` for the given `error`. -func (logger *Logger) WithError(err error) *Entry { - entry := logger.newEntry() - defer logger.releaseEntry(entry) - return entry.WithError(err) -} - -func (logger *Logger) Debugf(format string, args ...interface{}) { - if logger.level() >= DebugLevel { - entry := logger.newEntry() - entry.Debugf(format, args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Infof(format string, args ...interface{}) { - if logger.level() >= InfoLevel { - entry := logger.newEntry() - entry.Infof(format, args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Printf(format string, args ...interface{}) { - entry := logger.newEntry() - entry.Printf(format, args...) - logger.releaseEntry(entry) -} - -func (logger *Logger) Warnf(format string, args ...interface{}) { - if logger.level() >= WarnLevel { - entry := logger.newEntry() - entry.Warnf(format, args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Warningf(format string, args ...interface{}) { - if logger.level() >= WarnLevel { - entry := logger.newEntry() - entry.Warnf(format, args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Errorf(format string, args ...interface{}) { - if logger.level() >= ErrorLevel { - entry := logger.newEntry() - entry.Errorf(format, args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Fatalf(format string, args ...interface{}) { - if logger.level() >= FatalLevel { - entry := logger.newEntry() - entry.Fatalf(format, args...) - logger.releaseEntry(entry) - } - Exit(1) -} - -func (logger *Logger) Panicf(format string, args ...interface{}) { - if logger.level() >= PanicLevel { - entry := logger.newEntry() - entry.Panicf(format, args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Debug(args ...interface{}) { - if logger.level() >= DebugLevel { - entry := logger.newEntry() - entry.Debug(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Info(args ...interface{}) { - if logger.level() >= InfoLevel { - entry := logger.newEntry() - entry.Info(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Print(args ...interface{}) { - entry := logger.newEntry() - entry.Info(args...) - logger.releaseEntry(entry) -} - -func (logger *Logger) Warn(args ...interface{}) { - if logger.level() >= WarnLevel { - entry := logger.newEntry() - entry.Warn(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Warning(args ...interface{}) { - if logger.level() >= WarnLevel { - entry := logger.newEntry() - entry.Warn(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Error(args ...interface{}) { - if logger.level() >= ErrorLevel { - entry := logger.newEntry() - entry.Error(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Fatal(args ...interface{}) { - if logger.level() >= FatalLevel { - entry := logger.newEntry() - entry.Fatal(args...) - logger.releaseEntry(entry) - } - Exit(1) -} - -func (logger *Logger) Panic(args ...interface{}) { - if logger.level() >= PanicLevel { - entry := logger.newEntry() - entry.Panic(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Debugln(args ...interface{}) { - if logger.level() >= DebugLevel { - entry := logger.newEntry() - entry.Debugln(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Infoln(args ...interface{}) { - if logger.level() >= InfoLevel { - entry := logger.newEntry() - entry.Infoln(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Println(args ...interface{}) { - entry := logger.newEntry() - entry.Println(args...) - logger.releaseEntry(entry) -} - -func (logger *Logger) Warnln(args ...interface{}) { - if logger.level() >= WarnLevel { - entry := logger.newEntry() - entry.Warnln(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Warningln(args ...interface{}) { - if logger.level() >= WarnLevel { - entry := logger.newEntry() - entry.Warnln(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Errorln(args ...interface{}) { - if logger.level() >= ErrorLevel { - entry := logger.newEntry() - entry.Errorln(args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Fatalln(args ...interface{}) { - if logger.level() >= FatalLevel { - entry := logger.newEntry() - entry.Fatalln(args...) - logger.releaseEntry(entry) - } - Exit(1) -} - -func (logger *Logger) Panicln(args ...interface{}) { - if logger.level() >= PanicLevel { - entry := logger.newEntry() - entry.Panicln(args...) - logger.releaseEntry(entry) - } -} - -//When file is opened with appending mode, it's safe to -//write concurrently to a file (within 4k message on Linux). -//In these cases user can choose to disable the lock. -func (logger *Logger) SetNoLock() { - logger.mu.Disable() -} - -func (logger *Logger) level() Level { - return Level(atomic.LoadUint32((*uint32)(&logger.Level))) -} - -func (logger *Logger) SetLevel(level Level) { - atomic.StoreUint32((*uint32)(&logger.Level), uint32(level)) -} diff --git a/vendor/github.com/Sirupsen/logrus/logger_bench_test.go b/vendor/github.com/Sirupsen/logrus/logger_bench_test.go deleted file mode 100644 index dd23a35..0000000 --- a/vendor/github.com/Sirupsen/logrus/logger_bench_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package logrus - -import ( - "os" - "testing" -) - -// smallFields is a small size data set for benchmarking -var loggerFields = Fields{ - "foo": "bar", - "baz": "qux", - "one": "two", - "three": "four", -} - -func BenchmarkDummyLogger(b *testing.B) { - nullf, err := os.OpenFile("/dev/null", os.O_WRONLY, 0666) - if err != nil { - b.Fatalf("%v", err) - } - defer nullf.Close() - doLoggerBenchmark(b, nullf, &TextFormatter{DisableColors: true}, smallFields) -} - -func BenchmarkDummyLoggerNoLock(b *testing.B) { - nullf, err := os.OpenFile("/dev/null", os.O_WRONLY|os.O_APPEND, 0666) - if err != nil { - b.Fatalf("%v", err) - } - defer nullf.Close() - doLoggerBenchmarkNoLock(b, nullf, &TextFormatter{DisableColors: true}, smallFields) -} - -func doLoggerBenchmark(b *testing.B, out *os.File, formatter Formatter, fields Fields) { - logger := Logger{ - Out: out, - Level: InfoLevel, - Formatter: formatter, - } - entry := logger.WithFields(fields) - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - entry.Info("aaa") - } - }) -} - -func doLoggerBenchmarkNoLock(b *testing.B, out *os.File, formatter Formatter, fields Fields) { - logger := Logger{ - Out: out, - Level: InfoLevel, - Formatter: formatter, - } - logger.SetNoLock() - entry := logger.WithFields(fields) - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - entry.Info("aaa") - } - }) -} diff --git a/vendor/github.com/Sirupsen/logrus/logrus.go b/vendor/github.com/Sirupsen/logrus/logrus.go deleted file mode 100644 index dd38999..0000000 --- a/vendor/github.com/Sirupsen/logrus/logrus.go +++ /dev/null @@ -1,143 +0,0 @@ -package logrus - -import ( - "fmt" - "log" - "strings" -) - -// Fields type, used to pass to `WithFields`. -type Fields map[string]interface{} - -// Level type -type Level uint32 - -// Convert the Level to a string. E.g. PanicLevel becomes "panic". -func (level Level) String() string { - switch level { - case DebugLevel: - return "debug" - case InfoLevel: - return "info" - case WarnLevel: - return "warning" - case ErrorLevel: - return "error" - case FatalLevel: - return "fatal" - case PanicLevel: - return "panic" - } - - return "unknown" -} - -// ParseLevel takes a string level and returns the Logrus log level constant. -func ParseLevel(lvl string) (Level, error) { - switch strings.ToLower(lvl) { - case "panic": - return PanicLevel, nil - case "fatal": - return FatalLevel, nil - case "error": - return ErrorLevel, nil - case "warn", "warning": - return WarnLevel, nil - case "info": - return InfoLevel, nil - case "debug": - return DebugLevel, nil - } - - var l Level - return l, fmt.Errorf("not a valid logrus Level: %q", lvl) -} - -// A constant exposing all logging levels -var AllLevels = []Level{ - PanicLevel, - FatalLevel, - ErrorLevel, - WarnLevel, - InfoLevel, - DebugLevel, -} - -// These are the different logging levels. You can set the logging level to log -// on your instance of logger, obtained with `logrus.New()`. -const ( - // PanicLevel level, highest level of severity. Logs and then calls panic with the - // message passed to Debug, Info, ... - PanicLevel Level = iota - // FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the - // logging level is set to Panic. - FatalLevel - // ErrorLevel level. Logs. Used for errors that should definitely be noted. - // Commonly used for hooks to send errors to an error tracking service. - ErrorLevel - // WarnLevel level. Non-critical entries that deserve eyes. - WarnLevel - // InfoLevel level. General operational entries about what's going on inside the - // application. - InfoLevel - // DebugLevel level. Usually only enabled when debugging. Very verbose logging. - DebugLevel -) - -// Won't compile if StdLogger can't be realized by a log.Logger -var ( - _ StdLogger = &log.Logger{} - _ StdLogger = &Entry{} - _ StdLogger = &Logger{} -) - -// StdLogger is what your logrus-enabled library should take, that way -// it'll accept a stdlib logger and a logrus logger. There's no standard -// interface, this is the closest we get, unfortunately. -type StdLogger interface { - Print(...interface{}) - Printf(string, ...interface{}) - Println(...interface{}) - - Fatal(...interface{}) - Fatalf(string, ...interface{}) - Fatalln(...interface{}) - - Panic(...interface{}) - Panicf(string, ...interface{}) - Panicln(...interface{}) -} - -// The FieldLogger interface generalizes the Entry and Logger types -type FieldLogger interface { - WithField(key string, value interface{}) *Entry - WithFields(fields Fields) *Entry - WithError(err error) *Entry - - Debugf(format string, args ...interface{}) - Infof(format string, args ...interface{}) - Printf(format string, args ...interface{}) - Warnf(format string, args ...interface{}) - Warningf(format string, args ...interface{}) - Errorf(format string, args ...interface{}) - Fatalf(format string, args ...interface{}) - Panicf(format string, args ...interface{}) - - Debug(args ...interface{}) - Info(args ...interface{}) - Print(args ...interface{}) - Warn(args ...interface{}) - Warning(args ...interface{}) - Error(args ...interface{}) - Fatal(args ...interface{}) - Panic(args ...interface{}) - - Debugln(args ...interface{}) - Infoln(args ...interface{}) - Println(args ...interface{}) - Warnln(args ...interface{}) - Warningln(args ...interface{}) - Errorln(args ...interface{}) - Fatalln(args ...interface{}) - Panicln(args ...interface{}) -} diff --git a/vendor/github.com/Sirupsen/logrus/logrus_test.go b/vendor/github.com/Sirupsen/logrus/logrus_test.go deleted file mode 100644 index 78cbc28..0000000 --- a/vendor/github.com/Sirupsen/logrus/logrus_test.go +++ /dev/null @@ -1,386 +0,0 @@ -package logrus - -import ( - "bytes" - "encoding/json" - "strconv" - "strings" - "sync" - "testing" - - "github.com/stretchr/testify/assert" -) - -func LogAndAssertJSON(t *testing.T, log func(*Logger), assertions func(fields Fields)) { - var buffer bytes.Buffer - var fields Fields - - logger := New() - logger.Out = &buffer - logger.Formatter = new(JSONFormatter) - - log(logger) - - err := json.Unmarshal(buffer.Bytes(), &fields) - assert.Nil(t, err) - - assertions(fields) -} - -func LogAndAssertText(t *testing.T, log func(*Logger), assertions func(fields map[string]string)) { - var buffer bytes.Buffer - - logger := New() - logger.Out = &buffer - logger.Formatter = &TextFormatter{ - DisableColors: true, - } - - log(logger) - - fields := make(map[string]string) - for _, kv := range strings.Split(buffer.String(), " ") { - if !strings.Contains(kv, "=") { - continue - } - kvArr := strings.Split(kv, "=") - key := strings.TrimSpace(kvArr[0]) - val := kvArr[1] - if kvArr[1][0] == '"' { - var err error - val, err = strconv.Unquote(val) - assert.NoError(t, err) - } - fields[key] = val - } - assertions(fields) -} - -func TestPrint(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Print("test") - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "test") - assert.Equal(t, fields["level"], "info") - }) -} - -func TestInfo(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Info("test") - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "test") - assert.Equal(t, fields["level"], "info") - }) -} - -func TestWarn(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Warn("test") - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "test") - assert.Equal(t, fields["level"], "warning") - }) -} - -func TestInfolnShouldAddSpacesBetweenStrings(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Infoln("test", "test") - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "test test") - }) -} - -func TestInfolnShouldAddSpacesBetweenStringAndNonstring(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Infoln("test", 10) - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "test 10") - }) -} - -func TestInfolnShouldAddSpacesBetweenTwoNonStrings(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Infoln(10, 10) - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "10 10") - }) -} - -func TestInfoShouldAddSpacesBetweenTwoNonStrings(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Infoln(10, 10) - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "10 10") - }) -} - -func TestInfoShouldNotAddSpacesBetweenStringAndNonstring(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Info("test", 10) - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "test10") - }) -} - -func TestInfoShouldNotAddSpacesBetweenStrings(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.Info("test", "test") - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "testtest") - }) -} - -func TestWithFieldsShouldAllowAssignments(t *testing.T) { - var buffer bytes.Buffer - var fields Fields - - logger := New() - logger.Out = &buffer - logger.Formatter = new(JSONFormatter) - - localLog := logger.WithFields(Fields{ - "key1": "value1", - }) - - localLog.WithField("key2", "value2").Info("test") - err := json.Unmarshal(buffer.Bytes(), &fields) - assert.Nil(t, err) - - assert.Equal(t, "value2", fields["key2"]) - assert.Equal(t, "value1", fields["key1"]) - - buffer = bytes.Buffer{} - fields = Fields{} - localLog.Info("test") - err = json.Unmarshal(buffer.Bytes(), &fields) - assert.Nil(t, err) - - _, ok := fields["key2"] - assert.Equal(t, false, ok) - assert.Equal(t, "value1", fields["key1"]) -} - -func TestUserSuppliedFieldDoesNotOverwriteDefaults(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.WithField("msg", "hello").Info("test") - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "test") - }) -} - -func TestUserSuppliedMsgFieldHasPrefix(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.WithField("msg", "hello").Info("test") - }, func(fields Fields) { - assert.Equal(t, fields["msg"], "test") - assert.Equal(t, fields["fields.msg"], "hello") - }) -} - -func TestUserSuppliedTimeFieldHasPrefix(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.WithField("time", "hello").Info("test") - }, func(fields Fields) { - assert.Equal(t, fields["fields.time"], "hello") - }) -} - -func TestUserSuppliedLevelFieldHasPrefix(t *testing.T) { - LogAndAssertJSON(t, func(log *Logger) { - log.WithField("level", 1).Info("test") - }, func(fields Fields) { - assert.Equal(t, fields["level"], "info") - assert.Equal(t, fields["fields.level"], 1.0) // JSON has floats only - }) -} - -func TestDefaultFieldsAreNotPrefixed(t *testing.T) { - LogAndAssertText(t, func(log *Logger) { - ll := log.WithField("herp", "derp") - ll.Info("hello") - ll.Info("bye") - }, func(fields map[string]string) { - for _, fieldName := range []string{"fields.level", "fields.time", "fields.msg"} { - if _, ok := fields[fieldName]; ok { - t.Fatalf("should not have prefixed %q: %v", fieldName, fields) - } - } - }) -} - -func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) { - - var buffer bytes.Buffer - var fields Fields - - logger := New() - logger.Out = &buffer - logger.Formatter = new(JSONFormatter) - - llog := logger.WithField("context", "eating raw fish") - - llog.Info("looks delicious") - - err := json.Unmarshal(buffer.Bytes(), &fields) - assert.NoError(t, err, "should have decoded first message") - assert.Equal(t, len(fields), 4, "should only have msg/time/level/context fields") - assert.Equal(t, fields["msg"], "looks delicious") - assert.Equal(t, fields["context"], "eating raw fish") - - buffer.Reset() - - llog.Warn("omg it is!") - - err = json.Unmarshal(buffer.Bytes(), &fields) - assert.NoError(t, err, "should have decoded second message") - assert.Equal(t, len(fields), 4, "should only have msg/time/level/context fields") - assert.Equal(t, fields["msg"], "omg it is!") - assert.Equal(t, fields["context"], "eating raw fish") - assert.Nil(t, fields["fields.msg"], "should not have prefixed previous `msg` entry") - -} - -func TestConvertLevelToString(t *testing.T) { - assert.Equal(t, "debug", DebugLevel.String()) - assert.Equal(t, "info", InfoLevel.String()) - assert.Equal(t, "warning", WarnLevel.String()) - assert.Equal(t, "error", ErrorLevel.String()) - assert.Equal(t, "fatal", FatalLevel.String()) - assert.Equal(t, "panic", PanicLevel.String()) -} - -func TestParseLevel(t *testing.T) { - l, err := ParseLevel("panic") - assert.Nil(t, err) - assert.Equal(t, PanicLevel, l) - - l, err = ParseLevel("PANIC") - assert.Nil(t, err) - assert.Equal(t, PanicLevel, l) - - l, err = ParseLevel("fatal") - assert.Nil(t, err) - assert.Equal(t, FatalLevel, l) - - l, err = ParseLevel("FATAL") - assert.Nil(t, err) - assert.Equal(t, FatalLevel, l) - - l, err = ParseLevel("error") - assert.Nil(t, err) - assert.Equal(t, ErrorLevel, l) - - l, err = ParseLevel("ERROR") - assert.Nil(t, err) - assert.Equal(t, ErrorLevel, l) - - l, err = ParseLevel("warn") - assert.Nil(t, err) - assert.Equal(t, WarnLevel, l) - - l, err = ParseLevel("WARN") - assert.Nil(t, err) - assert.Equal(t, WarnLevel, l) - - l, err = ParseLevel("warning") - assert.Nil(t, err) - assert.Equal(t, WarnLevel, l) - - l, err = ParseLevel("WARNING") - assert.Nil(t, err) - assert.Equal(t, WarnLevel, l) - - l, err = ParseLevel("info") - assert.Nil(t, err) - assert.Equal(t, InfoLevel, l) - - l, err = ParseLevel("INFO") - assert.Nil(t, err) - assert.Equal(t, InfoLevel, l) - - l, err = ParseLevel("debug") - assert.Nil(t, err) - assert.Equal(t, DebugLevel, l) - - l, err = ParseLevel("DEBUG") - assert.Nil(t, err) - assert.Equal(t, DebugLevel, l) - - l, err = ParseLevel("invalid") - assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error()) -} - -func TestGetSetLevelRace(t *testing.T) { - wg := sync.WaitGroup{} - for i := 0; i < 100; i++ { - wg.Add(1) - go func(i int) { - defer wg.Done() - if i%2 == 0 { - SetLevel(InfoLevel) - } else { - GetLevel() - } - }(i) - - } - wg.Wait() -} - -func TestLoggingRace(t *testing.T) { - logger := New() - - var wg sync.WaitGroup - wg.Add(100) - - for i := 0; i < 100; i++ { - go func() { - logger.Info("info") - wg.Done() - }() - } - wg.Wait() -} - -// Compile test -func TestLogrusInterface(t *testing.T) { - var buffer bytes.Buffer - fn := func(l FieldLogger) { - b := l.WithField("key", "value") - b.Debug("Test") - } - // test logger - logger := New() - logger.Out = &buffer - fn(logger) - - // test Entry - e := logger.WithField("another", "value") - fn(e) -} - -// Implements io.Writer using channels for synchronization, so we can wait on -// the Entry.Writer goroutine to write in a non-racey way. This does assume that -// there is a single call to Logger.Out for each message. -type channelWriter chan []byte - -func (cw channelWriter) Write(p []byte) (int, error) { - cw <- p - return len(p), nil -} - -func TestEntryWriter(t *testing.T) { - cw := channelWriter(make(chan []byte, 1)) - log := New() - log.Out = cw - log.Formatter = new(JSONFormatter) - log.WithField("foo", "bar").WriterLevel(WarnLevel).Write([]byte("hello\n")) - - bs := <-cw - var fields Fields - err := json.Unmarshal(bs, &fields) - assert.Nil(t, err) - assert.Equal(t, fields["foo"], "bar") - assert.Equal(t, fields["level"], "warning") -} diff --git a/vendor/github.com/Sirupsen/logrus/terminal_bsd.go b/vendor/github.com/Sirupsen/logrus/terminal_bsd.go deleted file mode 100644 index d7b3893..0000000 --- a/vendor/github.com/Sirupsen/logrus/terminal_bsd.go +++ /dev/null @@ -1,10 +0,0 @@ -// +build darwin freebsd openbsd netbsd dragonfly -// +build !appengine - -package logrus - -import "golang.org/x/sys/unix" - -const ioctlReadTermios = unix.TIOCGETA - -type Termios unix.Termios diff --git a/vendor/github.com/Sirupsen/logrus/terminal_linux.go b/vendor/github.com/Sirupsen/logrus/terminal_linux.go deleted file mode 100644 index 88d7298..0000000 --- a/vendor/github.com/Sirupsen/logrus/terminal_linux.go +++ /dev/null @@ -1,14 +0,0 @@ -// Based on ssh/terminal: -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !appengine - -package logrus - -import "golang.org/x/sys/unix" - -const ioctlReadTermios = unix.TCGETS - -type Termios unix.Termios diff --git a/vendor/github.com/Sirupsen/logrus/text_formatter.go b/vendor/github.com/Sirupsen/logrus/text_formatter.go deleted file mode 100644 index be412aa..0000000 --- a/vendor/github.com/Sirupsen/logrus/text_formatter.go +++ /dev/null @@ -1,191 +0,0 @@ -package logrus - -import ( - "bytes" - "fmt" - "io" - "os" - "sort" - "strings" - "sync" - "time" - - "golang.org/x/crypto/ssh/terminal" -) - -const ( - nocolor = 0 - red = 31 - green = 32 - yellow = 33 - blue = 36 - gray = 37 -) - -var ( - baseTimestamp time.Time -) - -func init() { - baseTimestamp = time.Now() -} - -// TextFormatter formats logs into text -type TextFormatter struct { - // Set to true to bypass checking for a TTY before outputting colors. - ForceColors bool - - // Force disabling colors. - DisableColors bool - - // Disable timestamp logging. useful when output is redirected to logging - // system that already adds timestamps. - DisableTimestamp bool - - // Enable logging the full timestamp when a TTY is attached instead of just - // the time passed since beginning of execution. - FullTimestamp bool - - // TimestampFormat to use for display when a full timestamp is printed - TimestampFormat string - - // The fields are sorted by default for a consistent output. For applications - // that log extremely frequently and don't use the JSON formatter this may not - // be desired. - DisableSorting bool - - // QuoteEmptyFields will wrap empty fields in quotes if true - QuoteEmptyFields bool - - // Whether the logger's out is to a terminal - isTerminal bool - - sync.Once -} - -func (f *TextFormatter) init(entry *Entry) { - if entry.Logger != nil { - f.isTerminal = f.checkIfTerminal(entry.Logger.Out) - } -} - -func (f *TextFormatter) checkIfTerminal(w io.Writer) bool { - switch v := w.(type) { - case *os.File: - return terminal.IsTerminal(int(v.Fd())) - default: - return false - } -} - -// Format renders a single log entry -func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { - var b *bytes.Buffer - keys := make([]string, 0, len(entry.Data)) - for k := range entry.Data { - keys = append(keys, k) - } - - if !f.DisableSorting { - sort.Strings(keys) - } - if entry.Buffer != nil { - b = entry.Buffer - } else { - b = &bytes.Buffer{} - } - - prefixFieldClashes(entry.Data) - - f.Do(func() { f.init(entry) }) - - isColored := (f.ForceColors || f.isTerminal) && !f.DisableColors - - timestampFormat := f.TimestampFormat - if timestampFormat == "" { - timestampFormat = defaultTimestampFormat - } - if isColored { - f.printColored(b, entry, keys, timestampFormat) - } else { - if !f.DisableTimestamp { - f.appendKeyValue(b, "time", entry.Time.Format(timestampFormat)) - } - f.appendKeyValue(b, "level", entry.Level.String()) - if entry.Message != "" { - f.appendKeyValue(b, "msg", entry.Message) - } - for _, key := range keys { - f.appendKeyValue(b, key, entry.Data[key]) - } - } - - b.WriteByte('\n') - return b.Bytes(), nil -} - -func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []string, timestampFormat string) { - var levelColor int - switch entry.Level { - case DebugLevel: - levelColor = gray - case WarnLevel: - levelColor = yellow - case ErrorLevel, FatalLevel, PanicLevel: - levelColor = red - default: - levelColor = blue - } - - levelText := strings.ToUpper(entry.Level.String())[0:4] - - if f.DisableTimestamp { - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m %-44s ", levelColor, levelText, entry.Message) - } else if !f.FullTimestamp { - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), entry.Message) - } else { - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), entry.Message) - } - for _, k := range keys { - v := entry.Data[k] - fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=", levelColor, k) - f.appendValue(b, v) - } -} - -func (f *TextFormatter) needsQuoting(text string) bool { - if f.QuoteEmptyFields && len(text) == 0 { - return true - } - for _, ch := range text { - if !((ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || - (ch >= '0' && ch <= '9') || - ch == '-' || ch == '.' || ch == '_' || ch == '/' || ch == '@' || ch == '^' || ch == '+') { - return true - } - } - return false -} - -func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) { - if b.Len() > 0 { - b.WriteByte(' ') - } - b.WriteString(key) - b.WriteByte('=') - f.appendValue(b, value) -} - -func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) { - stringVal, ok := value.(string) - if !ok { - stringVal = fmt.Sprint(value) - } - - if !f.needsQuoting(stringVal) { - b.WriteString(stringVal) - } else { - b.WriteString(fmt.Sprintf("%q", stringVal)) - } -} diff --git a/vendor/github.com/Sirupsen/logrus/text_formatter_test.go b/vendor/github.com/Sirupsen/logrus/text_formatter_test.go deleted file mode 100644 index d93b931..0000000 --- a/vendor/github.com/Sirupsen/logrus/text_formatter_test.go +++ /dev/null @@ -1,141 +0,0 @@ -package logrus - -import ( - "bytes" - "errors" - "fmt" - "strings" - "testing" - "time" -) - -func TestFormatting(t *testing.T) { - tf := &TextFormatter{DisableColors: true} - - testCases := []struct { - value string - expected string - }{ - {`foo`, "time=\"0001-01-01T00:00:00Z\" level=panic test=foo\n"}, - } - - for _, tc := range testCases { - b, _ := tf.Format(WithField("test", tc.value)) - - if string(b) != tc.expected { - t.Errorf("formatting expected for %q (result was %q instead of %q)", tc.value, string(b), tc.expected) - } - } -} - -func TestQuoting(t *testing.T) { - tf := &TextFormatter{DisableColors: true} - - checkQuoting := func(q bool, value interface{}) { - b, _ := tf.Format(WithField("test", value)) - idx := bytes.Index(b, ([]byte)("test=")) - cont := bytes.Contains(b[idx+5:], []byte("\"")) - if cont != q { - if q { - t.Errorf("quoting expected for: %#v", value) - } else { - t.Errorf("quoting not expected for: %#v", value) - } - } - } - - checkQuoting(false, "") - checkQuoting(false, "abcd") - checkQuoting(false, "v1.0") - checkQuoting(false, "1234567890") - checkQuoting(false, "/foobar") - checkQuoting(false, "foo_bar") - checkQuoting(false, "foo@bar") - checkQuoting(false, "foobar^") - checkQuoting(false, "+/-_^@f.oobar") - checkQuoting(true, "foobar$") - checkQuoting(true, "&foobar") - checkQuoting(true, "x y") - checkQuoting(true, "x,y") - checkQuoting(false, errors.New("invalid")) - checkQuoting(true, errors.New("invalid argument")) - - // Test for quoting empty fields. - tf.QuoteEmptyFields = true - checkQuoting(true, "") - checkQuoting(false, "abcd") - checkQuoting(true, errors.New("invalid argument")) -} - -func TestEscaping(t *testing.T) { - tf := &TextFormatter{DisableColors: true} - - testCases := []struct { - value string - expected string - }{ - {`ba"r`, `ba\"r`}, - {`ba'r`, `ba'r`}, - } - - for _, tc := range testCases { - b, _ := tf.Format(WithField("test", tc.value)) - if !bytes.Contains(b, []byte(tc.expected)) { - t.Errorf("escaping expected for %q (result was %q instead of %q)", tc.value, string(b), tc.expected) - } - } -} - -func TestEscaping_Interface(t *testing.T) { - tf := &TextFormatter{DisableColors: true} - - ts := time.Now() - - testCases := []struct { - value interface{} - expected string - }{ - {ts, fmt.Sprintf("\"%s\"", ts.String())}, - {errors.New("error: something went wrong"), "\"error: something went wrong\""}, - } - - for _, tc := range testCases { - b, _ := tf.Format(WithField("test", tc.value)) - if !bytes.Contains(b, []byte(tc.expected)) { - t.Errorf("escaping expected for %q (result was %q instead of %q)", tc.value, string(b), tc.expected) - } - } -} - -func TestTimestampFormat(t *testing.T) { - checkTimeStr := func(format string) { - customFormatter := &TextFormatter{DisableColors: true, TimestampFormat: format} - customStr, _ := customFormatter.Format(WithField("test", "test")) - timeStart := bytes.Index(customStr, ([]byte)("time=")) - timeEnd := bytes.Index(customStr, ([]byte)("level=")) - timeStr := customStr[timeStart+5+len("\"") : timeEnd-1-len("\"")] - if format == "" { - format = time.RFC3339 - } - _, e := time.Parse(format, (string)(timeStr)) - if e != nil { - t.Errorf("time string \"%s\" did not match provided time format \"%s\": %s", timeStr, format, e) - } - } - - checkTimeStr("2006-01-02T15:04:05.000000000Z07:00") - checkTimeStr("Mon Jan _2 15:04:05 2006") - checkTimeStr("") -} - -func TestDisableTimestampWithColoredOutput(t *testing.T) { - tf := &TextFormatter{DisableTimestamp: true, ForceColors: true} - - b, _ := tf.Format(WithField("test", "test")) - if strings.Contains(string(b), "[0000]") { - t.Error("timestamp not expected when DisableTimestamp is true") - } -} - -// TODO add tests for sorting etc., this requires a parser for the text -// formatter output. diff --git a/vendor/github.com/Sirupsen/logrus/writer.go b/vendor/github.com/Sirupsen/logrus/writer.go deleted file mode 100644 index 7bdebed..0000000 --- a/vendor/github.com/Sirupsen/logrus/writer.go +++ /dev/null @@ -1,62 +0,0 @@ -package logrus - -import ( - "bufio" - "io" - "runtime" -) - -func (logger *Logger) Writer() *io.PipeWriter { - return logger.WriterLevel(InfoLevel) -} - -func (logger *Logger) WriterLevel(level Level) *io.PipeWriter { - return NewEntry(logger).WriterLevel(level) -} - -func (entry *Entry) Writer() *io.PipeWriter { - return entry.WriterLevel(InfoLevel) -} - -func (entry *Entry) WriterLevel(level Level) *io.PipeWriter { - reader, writer := io.Pipe() - - var printFunc func(args ...interface{}) - - switch level { - case DebugLevel: - printFunc = entry.Debug - case InfoLevel: - printFunc = entry.Info - case WarnLevel: - printFunc = entry.Warn - case ErrorLevel: - printFunc = entry.Error - case FatalLevel: - printFunc = entry.Fatal - case PanicLevel: - printFunc = entry.Panic - default: - printFunc = entry.Print - } - - go entry.writerScanner(reader, printFunc) - runtime.SetFinalizer(writer, writerFinalizer) - - return writer -} - -func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) { - scanner := bufio.NewScanner(reader) - for scanner.Scan() { - printFunc(scanner.Text()) - } - if err := scanner.Err(); err != nil { - entry.Errorf("Error while reading from Writer: %s", err) - } - reader.Close() -} - -func writerFinalizer(writer *io.PipeWriter) { - writer.Close() -} diff --git a/vendor/github.com/docker/docker/.dockerignore b/vendor/github.com/docker/docker/.dockerignore deleted file mode 100644 index 082cac9..0000000 --- a/vendor/github.com/docker/docker/.dockerignore +++ /dev/null @@ -1,4 +0,0 @@ -bundles -.gopath -vendor/pkg -.go-pkg-cache diff --git a/vendor/github.com/docker/docker/.github/ISSUE_TEMPLATE.md b/vendor/github.com/docker/docker/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 7362480..0000000 --- a/vendor/github.com/docker/docker/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,64 +0,0 @@ - - -**Description** - - - -**Steps to reproduce the issue:** -1. -2. -3. - -**Describe the results you received:** - - -**Describe the results you expected:** - - -**Additional information you deem important (e.g. issue happens only occasionally):** - -**Output of `docker version`:** - -``` -(paste your output here) -``` - -**Output of `docker info`:** - -``` -(paste your output here) -``` - -**Additional environment details (AWS, VirtualBox, physical, etc.):** diff --git a/vendor/github.com/docker/docker/.github/PULL_REQUEST_TEMPLATE.md b/vendor/github.com/docker/docker/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4269818..0000000 --- a/vendor/github.com/docker/docker/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,30 +0,0 @@ - - -**- What I did** - -**- How I did it** - -**- How to verify it** - -**- Description for the changelog** - - - -**- A picture of a cute animal (not mandatory but encouraged)** - diff --git a/vendor/github.com/docker/docker/.gitignore b/vendor/github.com/docker/docker/.gitignore deleted file mode 100644 index be8b03d..0000000 --- a/vendor/github.com/docker/docker/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -# Docker project generated files to ignore -# if you want to ignore files created by your editor/tools, -# please consider a global .gitignore https://help.github.com/articles/ignoring-files -*.exe -*.exe~ -*.orig -*.test -.*.swp -.DS_Store -# a .bashrc may be added to customize the build environment -.bashrc -.editorconfig -.gopath/ -.go-pkg-cache/ -autogen/ -bundles/ -cmd/dockerd/dockerd -cmd/docker/docker -dockerversion/version_autogen.go -dockerversion/version_autogen_unix.go -docs/AWS_S3_BUCKET -docs/GITCOMMIT -docs/GIT_BRANCH -docs/VERSION -docs/_build -docs/_static -docs/_templates -docs/changed-files -# generated by man/md2man-all.sh -man/man1 -man/man5 -man/man8 -vendor/pkg/ diff --git a/vendor/github.com/docker/docker/.mailmap b/vendor/github.com/docker/docker/.mailmap deleted file mode 100644 index fe99e20..0000000 --- a/vendor/github.com/docker/docker/.mailmap +++ /dev/null @@ -1,275 +0,0 @@ -# Generate AUTHORS: hack/generate-authors.sh - -# Tip for finding duplicates (besides scanning the output of AUTHORS for name -# duplicates that aren't also email duplicates): scan the output of: -# git log --format='%aE - %aN' | sort -uf -# -# For explanation on this file format: man git-shortlog - -Patrick Stapleton -Shishir Mahajan -Erwin van der Koogh -Ahmed Kamal -Tejesh Mehta -Cristian Staretu -Cristian Staretu -Cristian Staretu -Marcus Linke -Aleksandrs Fadins -Christopher Latham -Hu Keping -Wayne Chang -Chen Chao -Daehyeok Mun - - - - - - -Guillaume J. Charmes - - - - - -Thatcher Peskens -Thatcher Peskens -Thatcher Peskens dhrp -Jérôme Petazzoni jpetazzo -Jérôme Petazzoni -Joffrey F -Joffrey F -Joffrey F -Tim Terhorst -Andy Smith - - - - - - - - - -Walter Stanish - -Roberto Hashioka -Konstantin Pelykh -David Sissitka -Nolan Darilek - -Benoit Chesneau -Jordan Arentsen -Daniel Garcia -Miguel Angel Fernández -Bhiraj Butala -Faiz Khan -Victor Lyuboslavsky -Jean-Baptiste Barth -Matthew Mueller - -Shih-Yuan Lee -Daniel Mizyrycki root -Jean-Baptiste Dalido - - - - - - - - - - - - - - -Sven Dowideit -Sven Dowideit -Sven Dowideit -Sven Dowideit <¨SvenDowideit@home.org.au¨> -Sven Dowideit -Sven Dowideit -Sven Dowideit - -Alexander Morozov -Alexander Morozov - -O.S. Tezer - -Roberto G. Hashioka - - - - - -Sridhar Ratnakumar -Sridhar Ratnakumar -Liang-Chi Hsieh -Aleksa Sarai -Aleksa Sarai -Aleksa Sarai -Will Weaver -Timothy Hobbs -Nathan LeClaire -Nathan LeClaire - - - - -Matthew Heon - - - - -Francisco Carriedo - - - - -Brian Goff - - - -Hollie Teal - - - -Jessica Frazelle -Jessica Frazelle -Jessica Frazelle -Jessica Frazelle -Jessica Frazelle -Jessica Frazelle -Jessica Frazelle - - - - -Thomas LEVEIL Thomas LÉVEIL - - -Antonio Murdaca -Antonio Murdaca -Antonio Murdaca -Antonio Murdaca -Antonio Murdaca -Darren Shepherd -Deshi Xiao -Deshi Xiao -Doug Davis -Jacob Atzen -Jeff Nickoloff -John Howard (VM) -John Howard (VM) -John Howard (VM) -John Howard (VM) -Madhu Venugopal -Mary Anthony -Mary Anthony moxiegirl -Mary Anthony -mattyw -resouer -AJ Bowen soulshake -AJ Bowen soulshake -Tibor Vass -Tibor Vass -Vincent Bernat -Yestin Sun -bin liu -John Howard (VM) jhowardmsft -Ankush Agarwal -Tangi COLIN tangicolin -Allen Sun -Adrien Gallouët - -Anuj Bahuguna -Anusha Ragunathan -Avi Miller -Brent Salisbury -Chander G -Chun Chen -Ying Li -Daehyeok Mun - -Daniel, Dao Quang Minh -Daniel Nephin -Dave Tucker -Doug Tangren -Frederick F. Kautz IV -Ben Golub -Harold Cooper -hsinko <21551195@zju.edu.cn> -Josh Hawn -Justin Cormack - - -Kamil Domański -Lei Jitang - -Linus Heckemann - -Lynda O'Leary - -Marianna Tessel -Michael Huettermann -Moysés Borges - -Nigel Poulton -Qiang Huang - -Boaz Shuster -Shuwei Hao - -Soshi Katsuta - -Stefan Berger - -Stephen Day - -Toli Kuznets -Tristan Carel - -Vincent Demeester - -Vishnu Kannan -xlgao-zju xlgao -yuchangchun y00277921 - - - - -Hao Shu Wei - - - - - - - -Shengbo Song mYmNeo -Shengbo Song - -Sylvain Bellemare - - - -Arnaud Porterie - -David M. Karr - - - -Kenfe-Mickaël Laventure - - - - - -Runshen Zhu -Tom Barlow -Xianlu Bird -Dan Feldman -Harry Zhang diff --git a/vendor/github.com/docker/docker/AUTHORS b/vendor/github.com/docker/docker/AUTHORS deleted file mode 100644 index 246e2a3..0000000 --- a/vendor/github.com/docker/docker/AUTHORS +++ /dev/null @@ -1,1652 +0,0 @@ -# This file lists all individuals having contributed content to the repository. -# For how it is generated, see `hack/generate-authors.sh`. - -Aanand Prasad -Aaron Davidson -Aaron Feng -Aaron Huslage -Aaron Lehmann -Aaron Welch -Abel Muiño -Abhijeet Kasurde -Abhinav Ajgaonkar -Abhishek Chanda -Abin Shahab -Adam Avilla -Adam Kunk -Adam Miller -Adam Mills -Adam Singer -Adam Walz -Aditi Rajagopal -Aditya -Adolfo Ochagavía -Adria Casas -Adrian Moisey -Adrian Mouat -Adrian Oprea -Adrien Folie -Adrien Gallouët -Ahmed Kamal -Ahmet Alp Balkan -Aidan Feldman -Aidan Hobson Sayers -AJ Bowen -Ajey Charantimath -ajneu -Akihiro Suda -Al Tobey -alambike -Alan Scherger -Alan Thompson -Albert Callarisa -Albert Zhang -Aleksa Sarai -Aleksandrs Fadins -Alena Prokharchyk -Alessandro Boch -Alessio Biancalana -Alex Chan -Alex Coventry -Alex Crawford -Alex Ellis -Alex Gaynor -Alex Olshansky -Alex Samorukov -Alex Warhawk -Alexander Artemenko -Alexander Boyd -Alexander Larsson -Alexander Morozov -Alexander Shopov -Alexandre Beslic -Alexandre González -Alexandru Sfirlogea -Alexey Guskov -Alexey Kotlyarov -Alexey Shamrin -Alexis THOMAS -Ali Dehghani -Allen Madsen -Allen Sun -almoehi -Alvaro Saurin -Alvin Richards -amangoel -Amen Belayneh -Amit Bakshi -Amit Krishnan -Amit Shukla -Amy Lindburg -Anand Patil -AnandkumarPatel -Anatoly Borodin -Anchal Agrawal -Anders Janmyr -Andre Dublin <81dublin@gmail.com> -Andre Granovsky -Andrea Luzzardi -Andrea Turli -Andreas Köhler -Andreas Savvides -Andreas Tiefenthaler -Andrei Gherzan -Andrew C. Bodine -Andrew Clay Shafer -Andrew Duckworth -Andrew France -Andrew Gerrand -Andrew Guenther -Andrew Kuklewicz -Andrew Macgregor -Andrew Macpherson -Andrew Martin -Andrew Munsell -Andrew Po -Andrew Weiss -Andrew Williams -Andrews Medina -Andrey Petrov -Andrey Stolbovsky -André Martins -andy -Andy Chambers -andy diller -Andy Goldstein -Andy Kipp -Andy Rothfusz -Andy Smith -Andy Wilson -Anes Hasicic -Anil Belur -Anil Madhavapeddy -Ankush Agarwal -Anonmily -Anthon van der Neut -Anthony Baire -Anthony Bishopric -Anthony Dahanne -Anton Löfgren -Anton Nikitin -Anton Polonskiy -Anton Tiurin -Antonio Murdaca -Antonis Kalipetis -Antony Messerli -Anuj Bahuguna -Anusha Ragunathan -apocas -ArikaChen -Arnaud Lefebvre -Arnaud Porterie -Arthur Barr -Arthur Gautier -Artur Meyster -Arun Gupta -Asbjørn Enge -averagehuman -Avi Das -Avi Miller -Avi Vaid -ayoshitake -Azat Khuyiyakhmetov -Bardia Keyoumarsi -Barnaby Gray -Barry Allard -Bartłomiej Piotrowski -Bastiaan Bakker -bdevloed -Ben Firshman -Ben Golub -Ben Hall -Ben Sargent -Ben Severson -Ben Toews -Ben Wiklund -Benjamin Atkin -Benoit Chesneau -Bernerd Schaefer -Bert Goethals -Bharath Thiruveedula -Bhiraj Butala -Bilal Amarni -Bill W -bin liu -Blake Geno -Boaz Shuster -bobby abbott -boucher -Bouke Haarsma -Boyd Hemphill -boynux -Bradley Cicenas -Bradley Wright -Brandon Liu -Brandon Philips -Brandon Rhodes -Brendan Dixon -Brent Salisbury -Brett Higgins -Brett Kochendorfer -Brian (bex) Exelbierd -Brian Bland -Brian DeHamer -Brian Dorsey -Brian Flad -Brian Goff -Brian McCallister -Brian Olsen -Brian Shumate -Brian Torres-Gil -Brian Trump -Brice Jaglin -Briehan Lombaard -Bruno Bigras -Bruno Binet -Bruno Gazzera -Bruno Renié -Bryan Bess -Bryan Boreham -Bryan Matsuo -Bryan Murphy -buddhamagnet -Burke Libbey -Byung Kang -Caleb Spare -Calen Pennington -Cameron Boehmer -Cameron Spear -Campbell Allen -Candid Dauth -Cao Weiwei -Carl Henrik Lunde -Carl Loa Odin -Carl X. Su -Carlos Alexandro Becker -Carlos Sanchez -Carol Fager-Higgins -Cary -Casey Bisson -Cedric Davies -Cezar Sa Espinola -Chad Swenson -Chance Zibolski -Chander G -Charles Chan -Charles Hooper -Charles Law -Charles Lindsay -Charles Merriam -Charles Sarrazin -Charles Smith -Charlie Lewis -Chase Bolt -ChaYoung You -Chen Chao -Chen Hanxiao -cheney90 -Chewey -Chia-liang Kao -chli -Cholerae Hu -Chris Alfonso -Chris Armstrong -Chris Dituri -Chris Fordham -Chris Khoo -Chris McKinnel -Chris Seto -Chris Snow -Chris St. Pierre -Chris Stivers -Chris Swan -Chris Wahl -Chris Weyl -chrismckinnel -Christian Berendt -Christian Böhme -Christian Persson -Christian Rotzoll -Christian Simon -Christian Stefanescu -ChristoperBiscardi -Christophe Mehay -Christophe Troestler -Christopher Currie -Christopher Jones -Christopher Latham -Christopher Rigor -Christy Perez -Chun Chen -Ciro S. Costa -Clayton Coleman -Clinton Kitson -Coenraad Loubser -Colin Dunklau -Colin Rice -Colin Walters -Collin Guarino -Colm Hally -companycy -Cory Forsyth -cressie176 -CrimsonGlory -Cristian Staretu -cristiano balducci -Cruceru Calin-Cristian -Cyril F -Daan van Berkel -Daehyeok Mun -Dafydd Crosby -dalanlan -Damian Smyth -Damien Nadé -Damien Nozay -Damjan Georgievski -Dan Anolik -Dan Buch -Dan Cotora -Dan Feldman -Dan Griffin -Dan Hirsch -Dan Keder -Dan Levy -Dan McPherson -Dan Stine -Dan Walsh -Dan Williams -Daniel Antlinger -Daniel Exner -Daniel Farrell -Daniel Garcia -Daniel Gasienica -Daniel Hiltgen -Daniel Menet -Daniel Mizyrycki -Daniel Nephin -Daniel Norberg -Daniel Nordberg -Daniel Robinson -Daniel S -Daniel Von Fange -Daniel X Moore -Daniel YC Lin -Daniel Zhang -Daniel, Dao Quang Minh -Danny Berger -Danny Yates -Darren Coxall -Darren Shepherd -Darren Stahl -Davanum Srinivas -Dave Barboza -Dave Henderson -Dave MacDonald -Dave Tucker -David Anderson -David Calavera -David Corking -David Cramer -David Currie -David Davis -David Dooling -David Gageot -David Gebler -David Lawrence -David Lechner -David M. Karr -David Mackey -David Mat -David Mcanulty -David Pelaez -David R. Jenni -David Röthlisberger -David Sheets -David Sissitka -David Trott -David Xia -David Young -Davide Ceretti -Dawn Chen -dbdd -dcylabs -decadent -deed02392 -Deng Guangxing -Deni Bertovic -Denis Gladkikh -Denis Ollier -Dennis Docter -Derek -Derek -Derek Ch -Derek McGowan -Deric Crago -Deshi Xiao -devmeyster -Devvyn Murphy -Dharmit Shah -Dieter Reuter -Dillon Dixon -Dima Stopel -Dimitri John Ledkov -Dimitris Rozakis -Dimitry Andric -Dinesh Subhraveti -Diogo Monica -DiuDiugirl -Djibril Koné -dkumor -Dmitri Logvinenko -Dmitri Shuralyov -Dmitry Demeshchuk -Dmitry Gusev -Dmitry Smirnov -Dmitry V. Krivenok -Dmitry Vorobev -Dolph Mathews -Dominik Finkbeiner -Dominik Honnef -Don Kirkby -Don Kjer -Don Spaulding -Donald Huang -Dong Chen -Donovan Jones -Doron Podoleanu -Doug Davis -Doug MacEachern -Doug Tangren -Dr Nic Williams -dragon788 -Dražen Lučanin -Drew Erny -Dustin Sallings -Ed Costello -Edmund Wagner -Eiichi Tsukata -Eike Herzbach -Eivin Giske Skaaren -Eivind Uggedal -Elan Ruusamäe -Elias Probst -Elijah Zupancic -eluck -Elvir Kuric -Emil Hernvall -Emily Maier -Emily Rose -Emir Ozer -Enguerran -Eohyung Lee -Eric Barch -Eric Hanchrow -Eric Lee -Eric Myhre -Eric Paris -Eric Rafaloff -Eric Rosenberg -Eric Sage -Eric Windisch -Eric Yang -Eric-Olivier Lamey -Erik Bray -Erik Dubbelboer -Erik Hollensbe -Erik Inge Bolsø -Erik Kristensen -Erik Weathers -Erno Hopearuoho -Erwin van der Koogh -Euan -Eugene Yakubovich -eugenkrizo -evalle -Evan Allrich -Evan Carmi -Evan Hazlett -Evan Krall -Evan Phoenix -Evan Wies -Everett Toews -Evgeny Vereshchagin -Ewa Czechowska -Eystein Måløy Stenberg -ezbercih -Fabiano Rosas -Fabio Falci -Fabio Rapposelli -Fabio Rehm -Fabrizio Regini -Fabrizio Soppelsa -Faiz Khan -falmp -Fangyuan Gao <21551127@zju.edu.cn> -Fareed Dudhia -Fathi Boudra -Federico Gimenez -Felix Geisendörfer -Felix Hupfeld -Felix Rabe -Felix Ruess -Felix Schindler -Ferenc Szabo -Fernando -Fero Volar -Ferran Rodenas -Filipe Brandenburger -Filipe Oliveira -fl0yd -Flavio Castelli -FLGMwt -Florian -Florian Klein -Florian Maier -Florian Weingarten -Florin Asavoaie -fonglh -fortinux -Francesc Campoy -Francis Chuang -Francisco Carriedo -Francisco Souza -Frank Groeneveld -Frank Herrmann -Frank Macreery -Frank Rosquin -Fred Lifton -Frederick F. Kautz IV -Frederik Loeffert -Frederik Nordahl Jul Sabroe -Freek Kalter -frosforever -fy2462 -Félix Baylac-Jacqué -Félix Cantournet -Gabe Rosenhouse -Gabor Nagy -Gabriel Monroy -GabrielNicolasAvellaneda -Galen Sampson -Gareth Rushgrove -Garrett Barboza -Gaurav -gautam, prasanna -GennadySpb -Geoffrey Bachelet -George MacRorie -George Xie -Georgi Hristozov -Gereon Frey -German DZ -Gert van Valkenhoef -Gianluca Borello -Gildas Cuisinier -gissehel -Giuseppe Mazzotta -Gleb Fotengauer-Malinovskiy -Gleb M Borisov -Glyn Normington -GoBella -Goffert van Gool -Gosuke Miyashita -Gou Rao -Govinda Fichtner -Grant Reaber -Graydon Hoare -Greg Fausak -Greg Thornton -grossws -grunny -gs11 -Guilhem Lettron -Guilherme Salgado -Guillaume Dufour -Guillaume J. Charmes -guoxiuyan -Gurjeet Singh -Guruprasad -gwx296173 -Günter Zöchbauer -Hans Kristian Flaatten -Hans Rødtang -Hao Shu Wei -Hao Zhang <21521210@zju.edu.cn> -Harald Albers -Harley Laue -Harold Cooper -Harry Zhang -He Simei -heartlock <21521209@zju.edu.cn> -Hector Castro -Henning Sprang -Hobofan -Hollie Teal -Hong Xu -hsinko <21551195@zju.edu.cn> -Hu Keping -Hu Tao -Huanzhong Zhang -Huayi Zhang -Hugo Duncan -Hugo Marisco <0x6875676f@gmail.com> -Hunter Blanks -huqun -Huu Nguyen -hyeongkyu.lee -hyp3rdino -Hyzhou <1187766782@qq.com> -Ian Babrou -Ian Bishop -Ian Bull -Ian Calvert -Ian Lee -Ian Main -Ian Truslove -Iavael -Icaro Seara -Igor Dolzhikov -Ilkka Laukkanen -Ilya Dmitrichenko -Ilya Gusev -ILYA Khlopotov -imre Fitos -inglesp -Ingo Gottwald -Isaac Dupree -Isabel Jimenez -Isao Jonas -Ivan Babrou -Ivan Fraixedes -Ivan Grcic -J Bruni -J. Nunn -Jack Danger Canty -Jacob Atzen -Jacob Edelman -Jake Champlin -Jake Moshenko -jakedt -James Allen -James Carey -James Carr -James DeFelice -James Harrison Fisher -James Kyburz -James Kyle -James Lal -James Mills -James Nugent -James Turnbull -Jamie Hannaford -Jamshid Afshar -Jan Keromnes -Jan Koprowski -Jan Pazdziora -Jan Toebes -Jan-Gerd Tenberge -Jan-Jaap Driessen -Jana Radhakrishnan -Jannick Fahlbusch -Januar Wayong -Jared Biel -Jared Hocutt -Jaroslaw Zabiello -jaseg -Jasmine Hegman -Jason Divock -Jason Giedymin -Jason Green -Jason Hall -Jason Heiss -Jason Livesay -Jason McVetta -Jason Plum -Jason Shepherd -Jason Smith -Jason Sommer -Jason Stangroome -jaxgeller -Jay -Jay -Jay Kamat -Jean-Baptiste Barth -Jean-Baptiste Dalido -Jean-Paul Calderone -Jean-Tiare Le Bigot -Jeff Anderson -Jeff Johnston -Jeff Lindsay -Jeff Mickey -Jeff Minard -Jeff Nickoloff -Jeff Silberman -Jeff Welch -Jeffrey Bolle -Jeffrey Morgan -Jeffrey van Gogh -Jenny Gebske -Jeremy Grosser -Jeremy Price -Jeremy Qian -Jeremy Unruh -Jeroen Jacobs -Jesse Dearing -Jesse Dubay -Jessica Frazelle -Jezeniel Zapanta -jgeiger -Jhon Honce -Ji.Zhilong -Jian Zhang -jianbosun -Jilles Oldenbeuving -Jim Alateras -Jim Perrin -Jimmy Cuadra -Jimmy Puckett -jimmyxian -Jinsoo Park -Jiri Popelka -Jiří Župka -jjy -jmzwcn -Joao Fernandes -Joe Beda -Joe Doliner -Joe Ferguson -Joe Gordon -Joe Shaw -Joe Van Dyk -Joel Friedly -Joel Handwell -Joel Hansson -Joel Wurtz -Joey Geiger -Joey Gibson -Joffrey F -Johan Euphrosine -Johan Rydberg -Johanan Lieberman -Johannes 'fish' Ziemke -John Costa -John Feminella -John Gardiner Myers -John Gossman -John Howard (VM) -John OBrien III -John Starks -John Tims -John Warwick -John Willis -johnharris85 -Jon Wedaman -Jonas Pfenniger -Jonathan A. Sternberg -Jonathan Boulle -Jonathan Camp -Jonathan Dowland -Jonathan Lebon -Jonathan Lomas -Jonathan McCrohan -Jonathan Mueller -Jonathan Pares -Jonathan Rudenberg -Jonathan Stoppani -Joost Cassee -Jordan -Jordan Arentsen -Jordan Sissel -Jose Diaz-Gonzalez -Joseph Anthony Pasquale Holsten -Joseph Hager -Joseph Kern -Josh -Josh Bodah -Josh Chorlton -Josh Hawn -Josh Horwitz -Josh Poimboeuf -Josiah Kiehl -José Tomás Albornoz -JP -jrabbit -Julian Taylor -Julien Barbier -Julien Bisconti -Julien Bordellier -Julien Dubois -Julien Pervillé -Julio Montes -Jun-Ru Chang -Jussi Nummelin -Justas Brazauskas -Justin Cormack -Justin Force -Justin Plock -Justin Simonelis -Justin Terry -Justyn Temme -Jyrki Puttonen -Jérôme Petazzoni -Jörg Thalheim -Kai Blin -Kai Qiang Wu(Kennan) -Kamil Domański -kamjar gerami -Kanstantsin Shautsou -Kara Alexandra -Karan Lyons -Kareem Khazem -kargakis -Karl Grzeszczak -Karol Duleba -Katie McLaughlin -Kato Kazuyoshi -Katrina Owen -Kawsar Saiyeed -kayrus -Ke Xu -Keith Hudgins -Keli Hu -Ken Cochrane -Ken Herner -Ken ICHIKAWA -Kenfe-Mickaël Laventure -Kenjiro Nakayama -Kent Johnson -Kevin "qwazerty" Houdebert -Kevin Burke -Kevin Clark -Kevin J. Lynagh -Kevin Jing Qiu -Kevin Menard -Kevin P. Kucharczyk -Kevin Richardson -Kevin Shi -Kevin Wallace -Kevin Yap -kevinmeredith -Keyvan Fatehi -kies -Kim BKC Carlbacker -Kim Eik -Kimbro Staken -Kir Kolyshkin -Kiran Gangadharan -Kirill Kolyshkin -Kirill SIbirev -knappe -Kohei Tsuruta -Koichi Shiraishi -Konrad Kleine -Konstantin L -Konstantin Pelykh -Krasimir Georgiev -Kris-Mikael Krister -Kristian Haugene -Kristina Zabunova -krrg -Kun Zhang -Kunal Kushwaha -Kyle Conroy -Kyle Linden -kyu -Lachlan Coote -Lai Jiangshan -Lajos Papp -Lakshan Perera -Lalatendu Mohanty -lalyos -Lance Chen -Lance Kinley -Lars Butler -Lars Kellogg-Stedman -Lars R. Damerow -Laszlo Meszaros -Laurent Erignoux -Laurie Voss -Leandro Siqueira -Lee Chao <932819864@qq.com> -Lee, Meng-Han -leeplay -Lei Jitang -Len Weincier -Lennie -Leszek Kowalski -Levi Blackstone -Levi Gross -Lewis Marshall -Lewis Peckover -Liam Macgillavry -Liana Lo -Liang Mingqiang -Liang-Chi Hsieh -liaoqingwei -limsy -Lin Lu -LingFaKe -Linus Heckemann -Liran Tal -Liron Levin -Liu Bo -Liu Hua -lixiaobing10051267 -LIZAO LI -Lloyd Dewolf -Lokesh Mandvekar -longliqiang88 <394564827@qq.com> -Lorenz Leutgeb -Lorenzo Fontana -Louis Opter -Luca Marturana -Luca Orlandi -Luca-Bogdan Grigorescu -Lucas Chan -Lucas Chi -Luciano Mores -Luis Martínez de Bartolomé Izquierdo -Lukas Waslowski -lukaspustina -Lukasz Zajaczkowski -lukemarsden -Lynda O'Leary -Lénaïc Huard -Ma Shimiao -Mabin -Madhav Puri -Madhu Venugopal -Mageee <21521230.zju.edu.cn> -Mahesh Tiyyagura -malnick -Malte Janduda -manchoz -Manfred Touron -Manfred Zabarauskas -Mansi Nahar -mansinahar -Manuel Meurer -Manuel Woelker -mapk0y -Marc Abramowitz -Marc Kuo -Marc Tamsky -Marcelo Salazar -Marco Hennings -Marcus Farkas -Marcus Linke -Marcus Ramberg -Marek Goldmann -Marian Marinov -Marianna Tessel -Mario Loriedo -Marius Gundersen -Marius Sturm -Marius Voila -Mark Allen -Mark McGranaghan -Mark McKinstry -Mark West -Marko Mikulicic -Marko Tibold -Markus Fix -Martijn Dwars -Martijn van Oosterhout -Martin Honermeyer -Martin Kelly -Martin Mosegaard Amdisen -Martin Redmond -Mary Anthony -Masahito Zembutsu -Mason Malone -Mateusz Sulima -Mathias Monnerville -Mathieu Le Marec - Pasquet -Matt Apperson -Matt Bachmann -Matt Bentley -Matt Haggard -Matt Hoyle -Matt McCormick -Matt Moore -Matt Richardson -Matt Robenolt -Matthew Heon -Matthew Mayer -Matthew Mueller -Matthew Riley -Matthias Klumpp -Matthias Kühnle -Matthias Rampke -Matthieu Hauglustaine -mattymo -mattyw -Mauricio Garavaglia -mauriyouth -Max Shytikov -Maxim Fedchyshyn -Maxim Ivanov -Maxim Kulkin -Maxim Treskin -Maxime Petazzoni -Meaglith Ma -meejah -Megan Kostick -Mehul Kar -Mei ChunTao -Mengdi Gao -Mert Yazıcıoğlu -mgniu -Micah Zoltu -Michael A. Smith -Michael Bridgen -Michael Brown -Michael Chiang -Michael Crosby -Michael Currie -Michael Friis -Michael Gorsuch -Michael Grauer -Michael Holzheu -Michael Hudson-Doyle -Michael Huettermann -Michael Käufl -Michael Neale -Michael Prokop -Michael Scharf -Michael Stapelberg -Michael Steinert -Michael Thies -Michael West -Michal Fojtik -Michal Gebauer -Michal Jemala -Michal Minar -Michal Wieczorek -Michaël Pailloncy -Michał Czeraszkiewicz -Michiel@unhosted -Mickaël FORTUNATO -Miguel Angel Fernández -Miguel Morales -Mihai Borobocea -Mihuleacc Sergiu -Mike Brown -Mike Chelen -Mike Danese -Mike Dillon -Mike Dougherty -Mike Gaffney -Mike Goelzer -Mike Leone -Mike MacCana -Mike Naberezny -Mike Snitzer -mikelinjie <294893458@qq.com> -Mikhail Sobolev -Miloslav Trmač -mingqing -Mingzhen Feng -Misty Stanley-Jones -Mitch Capper -mlarcher -Mohammad Banikazemi -Mohammed Aaqib Ansari -Mohit Soni -Morgan Bauer -Morgante Pell -Morgy93 -Morten Siebuhr -Morton Fox -Moysés Borges -mqliang -Mrunal Patel -msabansal -mschurenko -muge -Mustafa Akın -Muthukumar R -Máximo Cuadros -Médi-Rémi Hashim -Nahum Shalman -Nakul Pathak -Nalin Dahyabhai -Nan Monnand Deng -Naoki Orii -Natalie Parker -Natanael Copa -Nate Brennand -Nate Eagleson -Nate Jones -Nathan Hsieh -Nathan Kleyn -Nathan LeClaire -Nathan McCauley -Nathan Williams -Neal McBurnett -Neil Peterson -Nelson Chen -Neyazul Haque -Nghia Tran -Niall O'Higgins -Nicholas E. Rabenau -nick -Nick DeCoursin -Nick Irvine -Nick Parker -Nick Payne -Nick Stenning -Nick Stinemates -Nicola Kabar -Nicolas Borboën -Nicolas De loof -Nicolas Dudebout -Nicolas Goy -Nicolas Kaiser -Nicolás Hock Isaza -Nigel Poulton -NikolaMandic -nikolas -Nirmal Mehta -Nishant Totla -NIWA Hideyuki -noducks -Nolan Darilek -nponeccop -Nuutti Kotivuori -nzwsch -O.S. Tezer -objectified -OddBloke -odk- -Oguz Bilgic -Oh Jinkyun -Ohad Schneider -ohmystack -Ole Reifschneider -Oliver Neal -Olivier Gambier -Olle Jonsson -Oriol Francès -orkaa -Oskar Niburski -Otto Kekäläinen -oyld -ozlerhakan -paetling -pandrew -panticz -Paolo G. Giarrusso -Pascal Borreli -Pascal Hartig -Patrick Böänziger -Patrick Devine -Patrick Hemmer -Patrick Stapleton -pattichen -Paul -paul -Paul Annesley -Paul Bellamy -Paul Bowsher -Paul Furtado -Paul Hammond -Paul Jimenez -Paul Lietar -Paul Liljenberg -Paul Morie -Paul Nasrat -Paul Weaver -Paulo Ribeiro -Pavel Lobashov -Pavel Pospisil -Pavel Sutyrin -Pavel Tikhomirov -Pavlos Ratis -Pavol Vargovcik -Peeyush Gupta -Peggy Li -Pei Su -Penghan Wang -perhapszzy@sina.com -pestophagous -Peter Bourgon -Peter Braden -Peter Choi -Peter Dave Hello -Peter Edge -Peter Ericson -Peter Esbensen -Peter Malmgren -Peter Salvatore -Peter Volpe -Peter Waller -Petr Švihlík -Phil -Phil Estes -Phil Spitler -Philip Monroe -Philipp Wahala -Philipp Weissensteiner -Phillip Alexander -pidster -Piergiuliano Bossi -Pierre -Pierre Carrier -Pierre Dal-Pra -Pierre Wacrenier -Pierre-Alain RIVIERE -Piotr Bogdan -pixelistik -Porjo -Poul Kjeldager Sørensen -Pradeep Chhetri -Prasanna Gautam -Prayag Verma -Przemek Hejman -pysqz -qg <1373319223@qq.com> -qhuang -Qiang Huang -qq690388648 <690388648@qq.com> -Quentin Brossard -Quentin Perez -Quentin Tayssier -r0n22 -Rafal Jeczalik -Rafe Colton -Raghavendra K T -Raghuram Devarakonda -Rajat Pandit -Rajdeep Dua -Ralf Sippl -Ralle -Ralph Bean -Ramkumar Ramachandra -Ramon Brooker -Ramon van Alteren -Ray Tsang -ReadmeCritic -Recursive Madman -Regan McCooey -Remi Rampin -Renato Riccieri Santos Zannon -resouer -rgstephens -Rhys Hiltner -Rich Moyse -Rich Seymour -Richard -Richard Burnison -Richard Harvey -Richard Mathie -Richard Metzler -Richard Scothern -Richo Healey -Rick Bradley -Rick van de Loo -Rick Wieman -Rik Nijessen -Riku Voipio -Riley Guerin -Ritesh H Shukla -Riyaz Faizullabhoy -Rob Vesse -Robert Bachmann -Robert Bittle -Robert Obryk -Robert Stern -Robert Terhaar -Robert Wallis -Roberto G. Hashioka -Robin Naundorf -Robin Schneider -Robin Speekenbrink -robpc -Rodolfo Carvalho -Rodrigo Vaz -Roel Van Nyen -Roger Peppe -Rohit Jnagal -Rohit Kadam -Roland Huß -Roland Kammerer -Roland Moriz -Roma Sokolov -Roman Strashkin -Ron Smits -Ron Williams -root -root -root -root -root -Rory Hunter -Rory McCune -Ross Boucher -Rovanion Luckey -Rozhnov Alexandr -rsmoorthy -Rudolph Gottesheim -Rui Lopes -Runshen Zhu -Ryan Anderson -Ryan Aslett -Ryan Belgrave -Ryan Detzel -Ryan Fowler -Ryan McLaughlin -Ryan O'Donnell -Ryan Seto -Ryan Thomas -Ryan Trauntvein -Ryan Wallner -RyanDeng -Rémy Greinhofer -s. rannou -s00318865 -Sabin Basyal -Sachin Joshi -Sagar Hani -Sainath Grandhi -sakeven -Sally O'Malley -Sam Abed -Sam Alba -Sam Bailey -Sam J Sharpe -Sam Neirinck -Sam Reis -Sam Rijs -Sambuddha Basu -Sami Wagiaalla -Samuel Andaya -Samuel Dion-Girardeau -Samuel Karp -Samuel PHAN -Sankar சங்கர் -Sanket Saurav -Santhosh Manohar -sapphiredev -Satnam Singh -satoru -Satoshi Amemiya -Satoshi Tagomori -scaleoutsean -Scott Bessler -Scott Collier -Scott Johnston -Scott Stamp -Scott Walls -sdreyesg -Sean Christopherson -Sean Cronin -Sean OMeara -Sean P. Kane -Sebastiaan van Steenis -Sebastiaan van Stijn -Senthil Kumar Selvaraj -Senthil Kumaran -SeongJae Park -Seongyeol Lim -Serge Hallyn -Sergey Alekseev -Sergey Evstifeev -Serhat Gülçiçek -Sevki Hasirci -Shane Canon -Shane da Silva -shaunol -Shawn Landden -Shawn Siefkas -shawnhe -Shekhar Gulati -Sheng Yang -Shengbo Song -Shev Yan -Shih-Yuan Lee -Shijiang Wei -Shishir Mahajan -Shoubhik Bose -Shourya Sarcar -shuai-z -Shukui Yang -Shuwei Hao -Sian Lerk Lau -sidharthamani -Silas Sewell -Simei He -Simon Eskildsen -Simon Leinen -Simon Taranto -Sindhu S -Sjoerd Langkemper -skaasten -Solganik Alexander -Solomon Hykes -Song Gao -Soshi Katsuta -Soulou -Spencer Brown -Spencer Smith -Sridatta Thatipamala -Sridhar Ratnakumar -Srini Brahmaroutu -srinsriv -Steeve Morin -Stefan Berger -Stefan J. Wernli -Stefan Praszalowicz -Stefan Scherer -Stefan Staudenmeyer -Stefan Weil -Stephen Crosby -Stephen Day -Stephen Drake -Stephen Rust -Steve Durrheimer -Steve Francia -Steve Koch -Steven Burgess -Steven Erenst -Steven Iveson -Steven Merrill -Steven Richards -Steven Taylor -Subhajit Ghosh -Sujith Haridasan -Suryakumar Sudar -Sven Dowideit -Swapnil Daingade -Sylvain Baubeau -Sylvain Bellemare -Sébastien -Sébastien Luttringer -Sébastien Stormacq -Tadej Janež -TAGOMORI Satoshi -tang0th -Tangi COLIN -Tatsuki Sugiura -Tatsushi Inagaki -Taylor Jones -tbonza -Ted M. Young -Tehmasp Chaudhri -Tejesh Mehta -terryding77 <550147740@qq.com> -tgic -Thatcher Peskens -theadactyl -Thell 'Bo' Fowler -Thermionix -Thijs Terlouw -Thomas Bikeev -Thomas Frössman -Thomas Gazagnaire -Thomas Grainger -Thomas Hansen -Thomas Leonard -Thomas LEVEIL -Thomas Orozco -Thomas Riccardi -Thomas Schroeter -Thomas Sjögren -Thomas Swift -Thomas Tanaka -Thomas Texier -Tianon Gravi -Tianyi Wang -Tibor Vass -Tiffany Jernigan -Tiffany Low -Tim Bosse -Tim Dettrick -Tim Düsterhus -Tim Hockin -Tim Ruffles -Tim Smith -Tim Terhorst -Tim Wang -Tim Waugh -Tim Wraight -timfeirg -Timothy Hobbs -tjwebb123 -tobe -Tobias Bieniek -Tobias Bradtke -Tobias Gesellchen -Tobias Klauser -Tobias Munk -Tobias Schmidt -Tobias Schwab -Todd Crane -Todd Lunter -Todd Whiteman -Toli Kuznets -Tom Barlow -Tom Denham -Tom Fotherby -Tom Howe -Tom Hulihan -Tom Maaswinkel -Tom X. Tobin -Tomas Tomecek -Tomasz Kopczynski -Tomasz Lipinski -Tomasz Nurkiewicz -Tommaso Visconti -Tomáš Hrčka -Tonis Tiigi -Tonny Xu -Tony Daws -Tony Miller -toogley -Torstein Husebø -tpng -tracylihui <793912329@qq.com> -Travis Cline -Travis Thieman -Trent Ogren -Trevor -Trevor Pounds -trishnaguha -Tristan Carel -Troy Denton -Tyler Brock -Tzu-Jung Lee -Tõnis Tiigi -Ulysse Carion -unknown -vagrant -Vaidas Jablonskis -Veres Lajos -vgeta -Victor Algaze -Victor Coisne -Victor Costan -Victor I. Wood -Victor Lyuboslavsky -Victor Marmol -Victor Palma -Victor Vieux -Victoria Bialas -Vijaya Kumar K -Viktor Stanchev -Viktor Vojnovski -VinayRaghavanKS -Vincent Batts -Vincent Bernat -Vincent Bernat -Vincent Demeester -Vincent Giersch -Vincent Mayers -Vincent Woo -Vinod Kulkarni -Vishal Doshi -Vishnu Kannan -Vitor Monteiro -Vivek Agarwal -Vivek Dasgupta -Vivek Goyal -Vladimir Bulyga -Vladimir Kirillov -Vladimir Pouzanov -Vladimir Rutsky -Vladimir Varankin -VladimirAus -Vojtech Vitek (V-Teq) -waitingkuo -Walter Leibbrandt -Walter Stanish -WANG Chao -Wang Xing -Ward Vandewege -WarheadsSE -Wayne Chang -Wei-Ting Kuo -weiyan -Weiyang Zhu -Wen Cheng Ma -Wendel Fleming -Wenkai Yin -Wenxuan Zhao -Wenyu You <21551128@zju.edu.cn> -Wes Morgan -Will Dietz -Will Rouesnel -Will Weaver -willhf -William Delanoue -William Henry -William Hubbs -William Riancho -William Thurston -WiseTrem -wlan0 -Wolfgang Powisch -wonderflow -Wonjun Kim -xamyzhao -Xianlu Bird -XiaoBing Jiang -Xiaoxu Chen -xiekeyang -Xinzi Zhou -Xiuming Chen -xlgao-zju -xuzhaokui -Yahya -YAMADA Tsuyoshi -Yan Feng -Yang Bai -yangshukui -Yanqiang Miao -Yasunori Mahata -Yestin Sun -Yi EungJun -Yibai Zhang -Yihang Ho -Ying Li -Yohei Ueda -Yong Tang -Yongzhi Pan -yorkie -Youcef YEKHLEF -Yuan Sun -yuchangchun -yuchengxia -yuexiao-wang -YuPengZTE -Yurii Rashkovskii -yuzou -Zac Dover -Zach Borboa -Zachary Jaffee -Zain Memon -Zaiste! -Zane DeGraffenried -Zefan Li -Zen Lin(Zhinan Lin) -Zhang Kun -Zhang Wei -Zhang Wentao -Zhenan Ye <21551168@zju.edu.cn> -zhouhao -Zhu Guihua -Zhuoyun Wei -Zilin Du -zimbatm -Ziming Dong -ZJUshuaizhou <21551191@zju.edu.cn> -zmarouf -Zoltan Tombol -zqh -Zuhayr Elahi -Zunayed Ali -Álex González -Álvaro Lázaro -Átila Camurça Alves -尹吉峰 -搏通 diff --git a/vendor/github.com/docker/docker/CHANGELOG.md b/vendor/github.com/docker/docker/CHANGELOG.md deleted file mode 100644 index 36bb880..0000000 --- a/vendor/github.com/docker/docker/CHANGELOG.md +++ /dev/null @@ -1,3337 +0,0 @@ -# Changelog - -Items starting with `DEPRECATE` are important deprecation notices. For more -information on the list of deprecated flags and APIs please have a look at -https://docs.docker.com/engine/deprecated/ where target removal dates can also -be found. - -## 1.13.1 (2017-02-08) - -**IMPORTANT**: On Linux distributions where `devicemapper` was the default storage driver, -the `overlay2`, or `overlay` is now used by default (if the kernel supports it). -To use devicemapper, you can manually configure the storage driver to use through -the `--storage-driver` daemon option, or by setting "storage-driver" in the `daemon.json` -configuration file. - -**IMPORTANT**: In Docker 1.13, the managed plugin api changed, as compared to the experimental -version introduced in Docker 1.12. You must **uninstall** plugins which you installed with Docker 1.12 -_before_ upgrading to Docker 1.13. You can uninstall plugins using the `docker plugin rm` command. - -If you have already upgraded to Docker 1.13 without uninstalling -previously-installed plugins, you may see this message when the Docker daemon -starts: - - Error starting daemon: json: cannot unmarshal string into Go value of type types.PluginEnv - -To manually remove all plugins and resolve this problem, take the following steps: - -1. Remove plugins.json from: `/var/lib/docker/plugins/`. -2. Restart Docker. Verify that the Docker daemon starts with no errors. -3. Reinstall your plugins. - -### Contrib - -* Do not require a custom build of tini [#28454](https://github.com/docker/docker/pull/28454) -* Upgrade to Go 1.7.5 [#30489](https://github.com/docker/docker/pull/30489) - -### Remote API (v1.26) & Client - -+ Support secrets in docker stack deploy with compose file [#30144](https://github.com/docker/docker/pull/30144) - -### Runtime - -* Fix size issue in `docker system df` [#30378](https://github.com/docker/docker/pull/30378) -* Fix error on `docker inspect` when Swarm certificates were expired. [#29246](https://github.com/docker/docker/pull/29246) -* Fix deadlock on v1 plugin with activate error [#30408](https://github.com/docker/docker/pull/30408) -* Fix SELinux regression [#30649](https://github.com/docker/docker/pull/30649) - -### Plugins - -* Support global scoped network plugins (v2) in swarm mode [#30332](https://github.com/docker/docker/pull/30332) -+ Add `docker plugin upgrade` [#29414](https://github.com/docker/docker/pull/29414) - -### Windows - -* Fix small regression with old plugins in Windows [#30150](https://github.com/docker/docker/pull/30150) -* Fix warning on Windows [#30730](https://github.com/docker/docker/pull/30730) - -## 1.13.0 (2017-01-18) - -**IMPORTANT**: On Linux distributions where `devicemapper` was the default storage driver, -the `overlay2`, or `overlay` is now used by default (if the kernel supports it). -To use devicemapper, you can manually configure the storage driver to use through -the `--storage-driver` daemon option, or by setting "storage-driver" in the `daemon.json` -configuration file. - -**IMPORTANT**: In Docker 1.13, the managed plugin api changed, as compared to the experimental -version introduced in Docker 1.12. You must **uninstall** plugins which you installed with Docker 1.12 -_before_ upgrading to Docker 1.13. You can uninstall plugins using the `docker plugin rm` command. - -If you have already upgraded to Docker 1.13 without uninstalling -previously-installed plugins, you may see this message when the Docker daemon -starts: - - Error starting daemon: json: cannot unmarshal string into Go value of type types.PluginEnv - -To manually remove all plugins and resolve this problem, take the following steps: - -1. Remove plugins.json from: `/var/lib/docker/plugins/`. -2. Restart Docker. Verify that the Docker daemon starts with no errors. -3. Reinstall your plugins. - -### Builder - -+ Add capability to specify images used as a cache source on build. These images do not need to have local parent chain and can be pulled from other registries [#26839](https://github.com/docker/docker/pull/26839) -+ (experimental) Add option to squash image layers to the FROM image after successful builds [#22641](https://github.com/docker/docker/pull/22641) -* Fix dockerfile parser with empty line after escape [#24725](https://github.com/docker/docker/pull/24725) -- Add step number on `docker build` [#24978](https://github.com/docker/docker/pull/24978) -+ Add support for compressing build context during image build [#25837](https://github.com/docker/docker/pull/25837) -+ add `--network` to `docker build` [#27702](https://github.com/docker/docker/pull/27702) -- Fix inconsistent behavior between `--label` flag on `docker build` and `docker run` [#26027](https://github.com/docker/docker/issues/26027) -- Fix image layer inconsistencies when using the overlay storage driver [#27209](https://github.com/docker/docker/pull/27209) -* Unused build-args are now allowed. A warning is presented instead of an error and failed build [#27412](https://github.com/docker/docker/pull/27412) -- Fix builder cache issue on Windows [#27805](https://github.com/docker/docker/pull/27805) -+ Allow `USER` in builder on Windows [#28415](https://github.com/docker/docker/pull/28415) -+ Handle env case-insensitive on Windows [#28725](https://github.com/docker/docker/pull/28725) - -### Contrib - -+ Add support for building docker debs for Ubuntu 16.04 Xenial on PPC64LE [#23438](https://github.com/docker/docker/pull/23438) -+ Add support for building docker debs for Ubuntu 16.04 Xenial on s390x [#26104](https://github.com/docker/docker/pull/26104) -+ Add support for building docker debs for Ubuntu 16.10 Yakkety Yak on PPC64LE [#28046](https://github.com/docker/docker/pull/28046) -- Add RPM builder for VMWare Photon OS [#24116](https://github.com/docker/docker/pull/24116) -+ Add shell completions to tgz [#27735](https://github.com/docker/docker/pull/27735) -* Update the install script to allow using the mirror in China [#27005](https://github.com/docker/docker/pull/27005) -+ Add DEB builder for Ubuntu 16.10 Yakkety Yak [#27993](https://github.com/docker/docker/pull/27993) -+ Add RPM builder for Fedora 25 [#28222](https://github.com/docker/docker/pull/28222) -+ Add `make deb` support for aarch64 [#27625](https://github.com/docker/docker/pull/27625) - -### Distribution - -* Update notary dependency to 0.4.2 (full changelogs [here](https://github.com/docker/notary/releases/tag/v0.4.2)) [#27074](https://github.com/docker/docker/pull/27074) - - Support for compilation on windows [docker/notary#970](https://github.com/docker/notary/pull/970) - - Improved error messages for client authentication errors [docker/notary#972](https://github.com/docker/notary/pull/972) - - Support for finding keys that are anywhere in the `~/.docker/trust/private` directory, not just under `~/.docker/trust/private/root_keys` or `~/.docker/trust/private/tuf_keys` [docker/notary#981](https://github.com/docker/notary/pull/981) - - Previously, on any error updating, the client would fall back on the cache. Now we only do so if there is a network error or if the server is unavailable or missing the TUF data. Invalid TUF data will cause the update to fail - for example if there was an invalid root rotation. [docker/notary#982](https://github.com/docker/notary/pull/982) - - Improve root validation and yubikey debug logging [docker/notary#858](https://github.com/docker/notary/pull/858) [docker/notary#891](https://github.com/docker/notary/pull/891) - - Warn if certificates for root or delegations are near expiry [docker/notary#802](https://github.com/docker/notary/pull/802) - - Warn if role metadata is near expiry [docker/notary#786](https://github.com/docker/notary/pull/786) - - Fix passphrase retrieval attempt counting and terminal detection [docker/notary#906](https://github.com/docker/notary/pull/906) -- Avoid unnecessary blob uploads when different users push same layers to authenticated registry [#26564](https://github.com/docker/docker/pull/26564) -* Allow external storage for registry credentials [#26354](https://github.com/docker/docker/pull/26354) - -### Logging - -* Standardize the default logging tag value in all logging drivers [#22911](https://github.com/docker/docker/pull/22911) -- Improve performance and memory use when logging of long log lines [#22982](https://github.com/docker/docker/pull/22982) -+ Enable syslog driver for windows [#25736](https://github.com/docker/docker/pull/25736) -+ Add Logentries Driver [#27471](https://github.com/docker/docker/pull/27471) -+ Update of AWS log driver to support tags [#27707](https://github.com/docker/docker/pull/27707) -+ Unix socket support for fluentd [#26088](https://github.com/docker/docker/pull/26088) -* Enable fluentd logging driver on Windows [#28189](https://github.com/docker/docker/pull/28189) -- Sanitize docker labels when used as journald field names [#23725](https://github.com/docker/docker/pull/23725) -- Fix an issue where `docker logs --tail` returned less lines than expected [#28203](https://github.com/docker/docker/pull/28203) -- Splunk Logging Driver: performance and reliability improvements [#26207](https://github.com/docker/docker/pull/26207) -- Splunk Logging Driver: configurable formats and skip for verifying connection [#25786](https://github.com/docker/docker/pull/25786) - -### Networking - -+ Add `--attachable` network support to enable `docker run` to work in swarm-mode overlay network [#25962](https://github.com/docker/docker/pull/25962) -+ Add support for host port PublishMode in services using the `--publish` option in `docker service create` [#27917](https://github.com/docker/docker/pull/27917) and [#28943](https://github.com/docker/docker/pull/28943) -+ Add support for Windows server 2016 overlay network driver (requires upcoming ws2016 update) [#28182](https://github.com/docker/docker/pull/28182) -* Change the default `FORWARD` policy to `DROP` [#28257](https://github.com/docker/docker/pull/28257) -+ Add support for specifying static IP addresses for predefined network on windows [#22208](https://github.com/docker/docker/pull/22208) -- Fix `--publish` flag on `docker run` not working with IPv6 addresses [#27860](https://github.com/docker/docker/pull/27860) -- Fix inspect network show gateway with mask [#25564](https://github.com/docker/docker/pull/25564) -- Fix an issue where multiple addresses in a bridge may cause `--fixed-cidr` to not have the correct addresses [#26659](https://github.com/docker/docker/pull/26659) -+ Add creation timestamp to `docker network inspect` [#26130](https://github.com/docker/docker/pull/26130) -- Show peer nodes in `docker network inspect` for swarm overlay networks [#28078](https://github.com/docker/docker/pull/28078) -- Enable ping for service VIP address [#28019](https://github.com/docker/docker/pull/28019) - -### Plugins - -- Move plugins out of experimental [#28226](https://github.com/docker/docker/pull/28226) -- Add `--force` on `docker plugin remove` [#25096](https://github.com/docker/docker/pull/25096) -* Add support for dynamically reloading authorization plugins [#22770](https://github.com/docker/docker/pull/22770) -+ Add description in `docker plugin ls` [#25556](https://github.com/docker/docker/pull/25556) -+ Add `-f`/`--format` to `docker plugin inspect` [#25990](https://github.com/docker/docker/pull/25990) -+ Add `docker plugin create` command [#28164](https://github.com/docker/docker/pull/28164) -* Send request's TLS peer certificates to authorization plugins [#27383](https://github.com/docker/docker/pull/27383) -* Support for global-scoped network and ipam plugins in swarm-mode [#27287](https://github.com/docker/docker/pull/27287) -* Split `docker plugin install` into two API call `/privileges` and `/pull` [#28963](https://github.com/docker/docker/pull/28963) - -### Remote API (v1.25) & Client - -+ Support `docker stack deploy` from a Compose file [#27998](https://github.com/docker/docker/pull/27998) -+ (experimental) Implement checkpoint and restore [#22049](https://github.com/docker/docker/pull/22049) -+ Add `--format` flag to `docker info` [#23808](https://github.com/docker/docker/pull/23808) -* Remove `--name` from `docker volume create` [#23830](https://github.com/docker/docker/pull/23830) -+ Add `docker stack ls` [#23886](https://github.com/docker/docker/pull/23886) -+ Add a new `is-task` ps filter [#24411](https://github.com/docker/docker/pull/24411) -+ Add `--env-file` flag to `docker service create` [#24844](https://github.com/docker/docker/pull/24844) -+ Add `--format` on `docker stats` [#24987](https://github.com/docker/docker/pull/24987) -+ Make `docker node ps` default to `self` in swarm node [#25214](https://github.com/docker/docker/pull/25214) -+ Add `--group` in `docker service create` [#25317](https://github.com/docker/docker/pull/25317) -+ Add `--no-trunc` to service/node/stack ps output [#25337](https://github.com/docker/docker/pull/25337) -+ Add Logs to `ContainerAttachOptions` so go clients can request to retrieve container logs as part of the attach process [#26718](https://github.com/docker/docker/pull/26718) -+ Allow client to talk to an older server [#27745](https://github.com/docker/docker/pull/27745) -* Inform user client-side that a container removal is in progress [#26074](https://github.com/docker/docker/pull/26074) -+ Add `Isolation` to the /info endpoint [#26255](https://github.com/docker/docker/pull/26255) -+ Add `userns` to the /info endpoint [#27840](https://github.com/docker/docker/pull/27840) -- Do not allow more than one mode be requested at once in the services endpoint [#26643](https://github.com/docker/docker/pull/26643) -+ Add capability to /containers/create API to specify mounts in a more granular and safer way [#22373](https://github.com/docker/docker/pull/22373) -+ Add `--format` flag to `network ls` and `volume ls` [#23475](https://github.com/docker/docker/pull/23475) -* Allow the top-level `docker inspect` command to inspect any kind of resource [#23614](https://github.com/docker/docker/pull/23614) -+ Add --cpus flag to control cpu resources for `docker run` and `docker create`, and add `NanoCPUs` to `HostConfig` [#27958](https://github.com/docker/docker/pull/27958) -- Allow unsetting the `--entrypoint` in `docker run` or `docker create` [#23718](https://github.com/docker/docker/pull/23718) -* Restructure CLI commands by adding `docker image` and `docker container` commands for more consistency [#26025](https://github.com/docker/docker/pull/26025) -- Remove `COMMAND` column from `service ls` output [#28029](https://github.com/docker/docker/pull/28029) -+ Add `--format` to `docker events` [#26268](https://github.com/docker/docker/pull/26268) -* Allow specifying multiple nodes on `docker node ps` [#26299](https://github.com/docker/docker/pull/26299) -* Restrict fractional digits to 2 decimals in `docker images` output [#26303](https://github.com/docker/docker/pull/26303) -+ Add `--dns-option` to `docker run` [#28186](https://github.com/docker/docker/pull/28186) -+ Add Image ID to container commit event [#28128](https://github.com/docker/docker/pull/28128) -+ Add external binaries version to docker info [#27955](https://github.com/docker/docker/pull/27955) -+ Add information for `Manager Addresses` in the output of `docker info` [#28042](https://github.com/docker/docker/pull/28042) -+ Add a new reference filter for `docker images` [#27872](https://github.com/docker/docker/pull/27872) - -### Runtime - -+ Add `--experimental` daemon flag to enable experimental features, instead of shipping them in a separate build [#27223](https://github.com/docker/docker/pull/27223) -+ Add a `--shutdown-timeout` daemon flag to specify the default timeout (in seconds) to stop containers gracefully before daemon exit [#23036](https://github.com/docker/docker/pull/23036) -+ Add `--stop-timeout` to specify the timeout value (in seconds) for individual containers to stop [#22566](https://github.com/docker/docker/pull/22566) -+ Add a new daemon flag `--userland-proxy-path` to allow configuring the userland proxy instead of using the hardcoded `docker-proxy` from `$PATH` [#26882](https://github.com/docker/docker/pull/26882) -+ Add boolean flag `--init` on `dockerd` and on `docker run` to use [tini](https://github.com/krallin/tini) a zombie-reaping init process as PID 1 [#26061](https://github.com/docker/docker/pull/26061) [#28037](https://github.com/docker/docker/pull/28037) -+ Add a new daemon flag `--init-path` to allow configuring the path to the `docker-init` binary [#26941](https://github.com/docker/docker/pull/26941) -+ Add support for live reloading insecure registry in configuration [#22337](https://github.com/docker/docker/pull/22337) -+ Add support for storage-opt size on Windows daemons [#23391](https://github.com/docker/docker/pull/23391) -* Improve reliability of `docker run --rm` by moving it from the client to the daemon [#20848](https://github.com/docker/docker/pull/20848) -+ Add support for `--cpu-rt-period` and `--cpu-rt-runtime` flags, allowing containers to run real-time threads when `CONFIG_RT_GROUP_SCHED` is enabled in the kernel [#23430](https://github.com/docker/docker/pull/23430) -* Allow parallel stop, pause, unpause [#24761](https://github.com/docker/docker/pull/24761) / [#26778](https://github.com/docker/docker/pull/26778) -* Implement XFS quota for overlay2 [#24771](https://github.com/docker/docker/pull/24771) -- Fix partial/full filter issue in `service tasks --filter` [#24850](https://github.com/docker/docker/pull/24850) -- Allow engine to run inside a user namespace [#25672](https://github.com/docker/docker/pull/25672) -- Fix a race condition between device deferred removal and resume device, when using the devicemapper graphdriver [#23497](https://github.com/docker/docker/pull/23497) -- Add `docker stats` support in Windows [#25737](https://github.com/docker/docker/pull/25737) -- Allow using `--pid=host` and `--net=host` when `--userns=host` [#25771](https://github.com/docker/docker/pull/25771) -+ (experimental) Add metrics (Prometheus) output for basic `container`, `image`, and `daemon` operations [#25820](https://github.com/docker/docker/pull/25820) -- Fix issue in `docker stats` with `NetworkDisabled=true` [#25905](https://github.com/docker/docker/pull/25905) -+ Add `docker top` support in Windows [#25891](https://github.com/docker/docker/pull/25891) -+ Record pid of exec'd process [#27470](https://github.com/docker/docker/pull/27470) -+ Add support for looking up user/groups via `getent` [#27599](https://github.com/docker/docker/pull/27599) -+ Add new `docker system` command with `df` and `prune` subcommands for system resource management, as well as `docker {container,image,volume,network} prune` subcommands [#26108](https://github.com/docker/docker/pull/26108) [#27525](https://github.com/docker/docker/pull/27525) / [#27525](https://github.com/docker/docker/pull/27525) -- Fix an issue where containers could not be stopped or killed by setting xfs max_retries to 0 upon ENOSPC with devicemapper [#26212](https://github.com/docker/docker/pull/26212) -- Fix `docker cp` failing to copy to a container's volume dir on CentOS with devicemapper [#28047](https://github.com/docker/docker/pull/28047) -* Promote overlay(2) graphdriver [#27932](https://github.com/docker/docker/pull/27932) -+ Add `--seccomp-profile` daemon flag to specify a path to a seccomp profile that overrides the default [#26276](https://github.com/docker/docker/pull/26276) -- Fix ulimits in `docker inspect` when `--default-ulimit` is set on daemon [#26405](https://github.com/docker/docker/pull/26405) -- Add workaround for overlay issues during build in older kernels [#28138](https://github.com/docker/docker/pull/28138) -+ Add `TERM` environment variable on `docker exec -t` [#26461](https://github.com/docker/docker/pull/26461) -* Honor a container’s `--stop-signal` setting upon `docker kill` [#26464](https://github.com/docker/docker/pull/26464) - -### Swarm Mode - -+ Add secret management [#27794](https://github.com/docker/docker/pull/27794) -+ Add support for templating service options (hostname, mounts, and environment variables) [#28025](https://github.com/docker/docker/pull/28025) -* Display the endpoint mode in the output of `docker service inspect --pretty` [#26906](https://github.com/docker/docker/pull/26906) -* Make `docker service ps` output more bearable by shortening service IDs in task names [#28088](https://github.com/docker/docker/pull/28088) -* Make `docker node ps` default to the current node [#25214](https://github.com/docker/docker/pull/25214) -+ Add `--dns`, -`-dns-opt`, and `--dns-search` to service create. [#27567](https://github.com/docker/docker/pull/27567) -+ Add `--force` to `docker service update` [#27596](https://github.com/docker/docker/pull/27596) -+ Add `--health-*` and `--no-healthcheck` flags to `docker service create` and `docker service update` [#27369](https://github.com/docker/docker/pull/27369) -+ Add `-q` to `docker service ps` [#27654](https://github.com/docker/docker/pull/27654) -* Display number of global services in `docker service ls` [#27710](https://github.com/docker/docker/pull/27710) -- Remove `--name` flag from `docker service update`. This flag is only functional on `docker service create`, so was removed from the `update` command [#26988](https://github.com/docker/docker/pull/26988) -- Fix worker nodes failing to recover because of transient networking issues [#26646](https://github.com/docker/docker/issues/26646) -* Add support for health aware load balancing and DNS records [#27279](https://github.com/docker/docker/pull/27279) -+ Add `--hostname` to `docker service create` [#27857](https://github.com/docker/docker/pull/27857) -+ Add `--host` to `docker service create`, and `--host-add`, `--host-rm` to `docker service update` [#28031](https://github.com/docker/docker/pull/28031) -+ Add `--tty` flag to `docker service create`/`update` [#28076](https://github.com/docker/docker/pull/28076) -* Autodetect, store, and expose node IP address as seen by the manager [#27910](https://github.com/docker/docker/pull/27910) -* Encryption at rest of manager keys and raft data [#27967](https://github.com/docker/docker/pull/27967) -+ Add `--update-max-failure-ratio`, `--update-monitor` and `--rollback` flags to `docker service update` [#26421](https://github.com/docker/docker/pull/26421) -- Fix an issue with address autodiscovery on `docker swarm init` running inside a container [#26457](https://github.com/docker/docker/pull/26457) -+ (experimental) Add `docker service logs` command to view logs for a service [#28089](https://github.com/docker/docker/pull/28089) -+ Pin images by digest for `docker service create` and `update` [#28173](https://github.com/docker/docker/pull/28173) -* Add short (`-f`) flag for `docker node rm --force` and `docker swarm leave --force` [#28196](https://github.com/docker/docker/pull/28196) -+ Add options to customize Raft snapshots (`--max-snapshots`, `--snapshot-interval`) [#27997](https://github.com/docker/docker/pull/27997) -- Don't repull image if pinned by digest [#28265](https://github.com/docker/docker/pull/28265) -+ Swarm-mode support for Windows [#27838](https://github.com/docker/docker/pull/27838) -+ Allow hostname to be updated on service [#28771](https://github.com/docker/docker/pull/28771) -+ Support v2 plugins [#29433](https://github.com/docker/docker/pull/29433) -+ Add content trust for services [#29469](https://github.com/docker/docker/pull/29469) - -### Volume - -+ Add support for labels on volumes [#21270](https://github.com/docker/docker/pull/21270) -+ Add support for filtering volumes by label [#25628](https://github.com/docker/docker/pull/25628) -* Add a `--force` flag in `docker volume rm` to forcefully purge the data of the volume that has already been deleted [#23436](https://github.com/docker/docker/pull/23436) -* Enhance `docker volume inspect` to show all options used when creating the volume [#26671](https://github.com/docker/docker/pull/26671) -* Add support for local NFS volumes to resolve hostnames [#27329](https://github.com/docker/docker/pull/27329) - -### Security - -- Fix selinux labeling of volumes shared in a container [#23024](https://github.com/docker/docker/pull/23024) -- Prohibit `/sys/firmware/**` from being accessed with apparmor [#26618](https://github.com/docker/docker/pull/26618) - -### DEPRECATION - -- Marked the `docker daemon` command as deprecated. The daemon is moved to a separate binary (`dockerd`), and should be used instead [#26834](https://github.com/docker/docker/pull/26834) -- Deprecate unversioned API endpoints [#28208](https://github.com/docker/docker/pull/28208) -- Remove Ubuntu 15.10 (Wily Werewolf) as supported platform. Ubuntu 15.10 is EOL, and no longer receives updates [#27042](https://github.com/docker/docker/pull/27042) -- Remove Fedora 22 as supported platform. Fedora 22 is EOL, and no longer receives updates [#27432](https://github.com/docker/docker/pull/27432) -- Remove Fedora 23 as supported platform. Fedora 23 is EOL, and no longer receives updates [#29455](https://github.com/docker/docker/pull/29455) -- Deprecate the `repo:shortid` syntax on `docker pull` [#27207](https://github.com/docker/docker/pull/27207) -- Deprecate backing filesystem without `d_type` for overlay and overlay2 storage drivers [#27433](https://github.com/docker/docker/pull/27433) -- Deprecate `MAINTAINER` in Dockerfile [#25466](https://github.com/docker/docker/pull/25466) -- Deprecate `filter` param for endpoint `/images/json` [#27872](https://github.com/docker/docker/pull/27872) -- Deprecate setting duplicate engine labels [#24533](https://github.com/docker/docker/pull/24533) -- Deprecate "top-level" network information in `NetworkSettings` [#28437](https://github.com/docker/docker/pull/28437) - -## 1.12.6 (2017-01-10) - -**IMPORTANT**: Docker 1.12 ships with an updated systemd unit file for rpm -based installs (which includes RHEL, Fedora, CentOS, and Oracle Linux 7). When -upgrading from an older version of docker, the upgrade process may not -automatically install the updated version of the unit file, or fail to start -the docker service if; - -- the systemd unit file (`/usr/lib/systemd/system/docker.service`) contains local changes, or -- a systemd drop-in file is present, and contains `-H fd://` in the `ExecStart` directive - -Starting the docker service will produce an error: - - Failed to start docker.service: Unit docker.socket failed to load: No such file or directory. - -or - - no sockets found via socket activation: make sure the service was started by systemd. - -To resolve this: - -- Backup the current version of the unit file, and replace the file with the - [version that ships with docker 1.12](https://raw.githubusercontent.com/docker/docker/v1.12.0/contrib/init/systemd/docker.service.rpm) -- Remove the `Requires=docker.socket` directive from the `/usr/lib/systemd/system/docker.service` file if present -- Remove `-H fd://` from the `ExecStart` directive (both in the main unit file, and in any drop-in files present). - -After making those changes, run `sudo systemctl daemon-reload`, and `sudo -systemctl restart docker` to reload changes and (re)start the docker daemon. - -**NOTE**: Docker 1.12.5 will correctly validate that either an IPv6 subnet is provided or -that the IPAM driver can provide one when you specify the `--ipv6` option. - -If you are currently using the `--ipv6` option _without_ specifying the -`--fixed-cidr-v6` option, the Docker daemon will refuse to start with the -following message: - -```none -Error starting daemon: Error initializing network controller: Error creating - default "bridge" network: failed to parse pool request - for address space "LocalDefault" pool " subpool ": - could not find an available, non-overlapping IPv6 address - pool among the defaults to assign to the network -``` - -To resolve this error, either remove the `--ipv6` flag (to preserve the same -behavior as in Docker 1.12.3 and earlier), or provide an IPv6 subnet as the -value of the `--fixed-cidr-v6` flag. - -In a similar way, if you specify the `--ipv6` flag when creating a network -with the default IPAM driver, without providing an IPv6 `--subnet`, network -creation will fail with the following message: - -```none -Error response from daemon: failed to parse pool request for address space - "LocalDefault" pool "" subpool "": could not find an - available, non-overlapping IPv6 address pool among - the defaults to assign to the network -``` - -To resolve this, either remove the `--ipv6` flag (to preserve the same behavior -as in Docker 1.12.3 and earlier), or provide an IPv6 subnet as the value of the -`--subnet` flag. - -The network network creation will instead succeed if you use an external IPAM driver -which supports automatic allocation of IPv6 subnets. - -### Runtime - -- Fix runC privilege escalation (CVE-2016-9962) - -## 1.12.5 (2016-12-15) - -**IMPORTANT**: Docker 1.12 ships with an updated systemd unit file for rpm -based installs (which includes RHEL, Fedora, CentOS, and Oracle Linux 7). When -upgrading from an older version of docker, the upgrade process may not -automatically install the updated version of the unit file, or fail to start -the docker service if; - -- the systemd unit file (`/usr/lib/systemd/system/docker.service`) contains local changes, or -- a systemd drop-in file is present, and contains `-H fd://` in the `ExecStart` directive - -Starting the docker service will produce an error: - - Failed to start docker.service: Unit docker.socket failed to load: No such file or directory. - -or - - no sockets found via socket activation: make sure the service was started by systemd. - -To resolve this: - -- Backup the current version of the unit file, and replace the file with the - [version that ships with docker 1.12](https://raw.githubusercontent.com/docker/docker/v1.12.0/contrib/init/systemd/docker.service.rpm) -- Remove the `Requires=docker.socket` directive from the `/usr/lib/systemd/system/docker.service` file if present -- Remove `-H fd://` from the `ExecStart` directive (both in the main unit file, and in any drop-in files present). - -After making those changes, run `sudo systemctl daemon-reload`, and `sudo -systemctl restart docker` to reload changes and (re)start the docker daemon. - -**NOTE**: Docker 1.12.5 will correctly validate that either an IPv6 subnet is provided or -that the IPAM driver can provide one when you specify the `--ipv6` option. - -If you are currently using the `--ipv6` option _without_ specifying the -`--fixed-cidr-v6` option, the Docker daemon will refuse to start with the -following message: - -```none -Error starting daemon: Error initializing network controller: Error creating - default "bridge" network: failed to parse pool request - for address space "LocalDefault" pool " subpool ": - could not find an available, non-overlapping IPv6 address - pool among the defaults to assign to the network -``` - -To resolve this error, either remove the `--ipv6` flag (to preserve the same -behavior as in Docker 1.12.3 and earlier), or provide an IPv6 subnet as the -value of the `--fixed-cidr-v6` flag. - -In a similar way, if you specify the `--ipv6` flag when creating a network -with the default IPAM driver, without providing an IPv6 `--subnet`, network -creation will fail with the following message: - -```none -Error response from daemon: failed to parse pool request for address space - "LocalDefault" pool "" subpool "": could not find an - available, non-overlapping IPv6 address pool among - the defaults to assign to the network -``` - -To resolve this, either remove the `--ipv6` flag (to preserve the same behavior -as in Docker 1.12.3 and earlier), or provide an IPv6 subnet as the value of the -`--subnet` flag. - -The network network creation will instead succeed if you use an external IPAM driver -which supports automatic allocation of IPv6 subnets. - -### Runtime - -- Fix race on sending stdin close event [#29424](https://github.com/docker/docker/pull/29424) - -### Networking - -- Fix panic in docker network ls when a network was created with `--ipv6` and no ipv6 `--subnet` in older docker versions [#29416](https://github.com/docker/docker/pull/29416) - -### Contrib - -- Fix compilation on Darwin [#29370](https://github.com/docker/docker/pull/29370) - -## 1.12.4 (2016-12-12) - -**IMPORTANT**: Docker 1.12 ships with an updated systemd unit file for rpm -based installs (which includes RHEL, Fedora, CentOS, and Oracle Linux 7). When -upgrading from an older version of docker, the upgrade process may not -automatically install the updated version of the unit file, or fail to start -the docker service if; - -- the systemd unit file (`/usr/lib/systemd/system/docker.service`) contains local changes, or -- a systemd drop-in file is present, and contains `-H fd://` in the `ExecStart` directive - -Starting the docker service will produce an error: - - Failed to start docker.service: Unit docker.socket failed to load: No such file or directory. - -or - - no sockets found via socket activation: make sure the service was started by systemd. - -To resolve this: - -- Backup the current version of the unit file, and replace the file with the - [version that ships with docker 1.12](https://raw.githubusercontent.com/docker/docker/v1.12.0/contrib/init/systemd/docker.service.rpm) -- Remove the `Requires=docker.socket` directive from the `/usr/lib/systemd/system/docker.service` file if present -- Remove `-H fd://` from the `ExecStart` directive (both in the main unit file, and in any drop-in files present). - -After making those changes, run `sudo systemctl daemon-reload`, and `sudo -systemctl restart docker` to reload changes and (re)start the docker daemon. - - -### Runtime - -- Fix issue where volume metadata was not removed [#29083](https://github.com/docker/docker/pull/29083) -- Asynchronously close streams to prevent holding container lock [#29050](https://github.com/docker/docker/pull/29050) -- Fix selinux labels for newly created container volumes [#29050](https://github.com/docker/docker/pull/29050) -- Remove hostname validation [#28990](https://github.com/docker/docker/pull/28990) -- Fix deadlocks caused by IO races [#29095](https://github.com/docker/docker/pull/29095) [#29141](https://github.com/docker/docker/pull/29141) -- Return an empty stats if the container is restarting [#29150](https://github.com/docker/docker/pull/29150) -- Fix volume store locking [#29151](https://github.com/docker/docker/pull/29151) -- Ensure consistent status code in API [#29150](https://github.com/docker/docker/pull/29150) -- Fix incorrect opaque directory permission in overlay2 [#29093](https://github.com/docker/docker/pull/29093) -- Detect plugin content and error out on `docker pull` [#29297](https://github.com/docker/docker/pull/29297) - -### Swarm Mode - -* Update Swarmkit [#29047](https://github.com/docker/docker/pull/29047) - - orchestrator/global: Fix deadlock on updates [docker/swarmkit#1760](https://github.com/docker/swarmkit/pull/1760) - - on leader switchover preserve the vxlan id for existing networks [docker/swarmkit#1773](https://github.com/docker/swarmkit/pull/1773) -- Refuse swarm spec not named "default" [#29152](https://github.com/docker/docker/pull/29152) - -### Networking - -* Update libnetwork [#29004](https://github.com/docker/docker/pull/29004) [#29146](https://github.com/docker/docker/pull/29146) - - Fix panic in embedded DNS [docker/libnetwork#1561](https://github.com/docker/libnetwork/pull/1561) - - Fix unmarhalling panic when passing --link-local-ip on global scope network [docker/libnetwork#1564](https://github.com/docker/libnetwork/pull/1564) - - Fix panic when network plugin returns nil StaticRoutes [docker/libnetwork#1563](https://github.com/docker/libnetwork/pull/1563) - - Fix panic in osl.(*networkNamespace).DeleteNeighbor [docker/libnetwork#1555](https://github.com/docker/libnetwork/pull/1555) - - Fix panic in swarm networking concurrent map read/write [docker/libnetwork#1570](https://github.com/docker/libnetwork/pull/1570) - * Allow encrypted networks when running docker inside a container [docker/libnetwork#1502](https://github.com/docker/libnetwork/pull/1502) - - Do not block autoallocation of IPv6 pool [docker/libnetwork#1538](https://github.com/docker/libnetwork/pull/1538) - - Set timeout for netlink calls [docker/libnetwork#1557](https://github.com/docker/libnetwork/pull/1557) - - Increase networking local store timeout to one minute [docker/libkv#140](https://github.com/docker/libkv/pull/140) - - Fix a panic in libnetwork.(*sandbox).execFunc [docker/libnetwork#1556](https://github.com/docker/libnetwork/pull/1556) - - Honor icc=false for internal networks [docker/libnetwork#1525](https://github.com/docker/libnetwork/pull/1525) - -### Logging - -* Update syslog log driver [#29150](https://github.com/docker/docker/pull/29150) - -### Contrib - -- Run "dnf upgrade" before installing in fedora [#29150](https://github.com/docker/docker/pull/29150) -- Add build-date back to RPM packages [#29150](https://github.com/docker/docker/pull/29150) -- deb package filename changed to include distro to distinguish between distro code names [#27829](https://github.com/docker/docker/pull/27829) - -## 1.12.3 (2016-10-26) - -**IMPORTANT**: Docker 1.12 ships with an updated systemd unit file for rpm -based installs (which includes RHEL, Fedora, CentOS, and Oracle Linux 7). When -upgrading from an older version of docker, the upgrade process may not -automatically install the updated version of the unit file, or fail to start -the docker service if; - -- the systemd unit file (`/usr/lib/systemd/system/docker.service`) contains local changes, or -- a systemd drop-in file is present, and contains `-H fd://` in the `ExecStart` directive - -Starting the docker service will produce an error: - - Failed to start docker.service: Unit docker.socket failed to load: No such file or directory. - -or - - no sockets found via socket activation: make sure the service was started by systemd. - -To resolve this: - -- Backup the current version of the unit file, and replace the file with the - [version that ships with docker 1.12](https://raw.githubusercontent.com/docker/docker/v1.12.0/contrib/init/systemd/docker.service.rpm) -- Remove the `Requires=docker.socket` directive from the `/usr/lib/systemd/system/docker.service` file if present -- Remove `-H fd://` from the `ExecStart` directive (both in the main unit file, and in any drop-in files present). - -After making those changes, run `sudo systemctl daemon-reload`, and `sudo -systemctl restart docker` to reload changes and (re)start the docker daemon. - - -### Runtime - -- Fix ambient capability usage in containers (CVE-2016-8867) [#27610](https://github.com/docker/docker/pull/27610) -- Prevent a deadlock in libcontainerd for Windows [#27136](https://github.com/docker/docker/pull/27136) -- Fix error reporting in CopyFileWithTar [#27075](https://github.com/docker/docker/pull/27075) -* Reset health status to starting when a container is restarted [#27387](https://github.com/docker/docker/pull/27387) -* Properly handle shared mount propagation in storage directory [#27609](https://github.com/docker/docker/pull/27609) -- Fix docker exec [#27610](https://github.com/docker/docker/pull/27610) -- Fix backward compatibility with containerd’s events log [#27693](https://github.com/docker/docker/pull/27693) - -### Swarm Mode - -- Fix conversion of restart-policy [#27062](https://github.com/docker/docker/pull/27062) -* Update Swarmkit [#27554](https://github.com/docker/docker/pull/27554) - * Avoid restarting a task that has already been restarted [docker/swarmkit#1305](https://github.com/docker/swarmkit/pull/1305) - * Allow duplicate published ports when they use different protocols [docker/swarmkit#1632](https://github.com/docker/swarmkit/pull/1632) - * Allow multiple randomly assigned published ports on service [docker/swarmkit#1657](https://github.com/docker/swarmkit/pull/1657) - - Fix panic when allocations happen at init time [docker/swarmkit#1651](https://github.com/docker/swarmkit/pull/1651) - -### Networking - -* Update libnetwork [#27559](https://github.com/docker/docker/pull/27559) - - Fix race in serializing sandbox to string [docker/libnetwork#1495](https://github.com/docker/libnetwork/pull/1495) - - Fix race during deletion [docker/libnetwork#1503](https://github.com/docker/libnetwork/pull/1503) - * Reset endpoint port info on connectivity revoke in bridge driver [docker/libnetwork#1504](https://github.com/docker/libnetwork/pull/1504) - - Fix a deadlock in networking code [docker/libnetwork#1507](https://github.com/docker/libnetwork/pull/1507) - - Fix a race in load balancer state [docker/libnetwork#1512](https://github.com/docker/libnetwork/pull/1512) - -### Logging - -* Update fluent-logger-golang to v1.2.1 [#27474](https://github.com/docker/docker/pull/27474) - -### Contrib - -* Update buildtags for armhf ubuntu-trusty [#27327](https://github.com/docker/docker/pull/27327) -* Add AppArmor to runc buildtags for armhf [#27421](https://github.com/docker/docker/pull/27421) - -## 1.12.2 (2016-10-11) - -**IMPORTANT**: Docker 1.12 ships with an updated systemd unit file for rpm -based installs (which includes RHEL, Fedora, CentOS, and Oracle Linux 7). When -upgrading from an older version of docker, the upgrade process may not -automatically install the updated version of the unit file, or fail to start -the docker service if; - -- the systemd unit file (`/usr/lib/systemd/system/docker.service`) contains local changes, or -- a systemd drop-in file is present, and contains `-H fd://` in the `ExecStart` directive - -Starting the docker service will produce an error: - - Failed to start docker.service: Unit docker.socket failed to load: No such file or directory. - -or - - no sockets found via socket activation: make sure the service was started by systemd. - -To resolve this: - -- Backup the current version of the unit file, and replace the file with the - [version that ships with docker 1.12](https://raw.githubusercontent.com/docker/docker/v1.12.0/contrib/init/systemd/docker.service.rpm) -- Remove the `Requires=docker.socket` directive from the `/usr/lib/systemd/system/docker.service` file if present -- Remove `-H fd://` from the `ExecStart` directive (both in the main unit file, and in any drop-in files present). - -After making those changes, run `sudo systemctl daemon-reload`, and `sudo -systemctl restart docker` to reload changes and (re)start the docker daemon. - - -### Runtime - -- Fix a panic due to a race condition filtering `docker ps` [#26049](https://github.com/docker/docker/pull/26049) -* Implement retry logic to prevent "Unable to remove filesystem" errors when using the aufs storage driver [#26536](https://github.com/docker/docker/pull/26536) -* Prevent devicemapper from removing device symlinks if `dm.use_deferred_removal` is enabled [#24740](https://github.com/docker/docker/pull/24740) -- Fix an issue where the CLI did not return correct exit codes if a command was run with invalid options [#26777](https://github.com/docker/docker/pull/26777) -- Fix a panic due to a bug in stdout / stderr processing in health checks [#26507](https://github.com/docker/docker/pull/26507) -- Fix exec's children handling [#26874](https://github.com/docker/docker/pull/26874) -- Fix exec form of HEALTHCHECK CMD [#26208](https://github.com/docker/docker/pull/26208) - -### Networking - -- Fix a daemon start panic on armv5 [#24315](https://github.com/docker/docker/issues/24315) -* Vendor libnetwork [#26879](https://github.com/docker/docker/pull/26879) [#26953](https://github.com/docker/docker/pull/26953) - * Avoid returning early on agent join failures [docker/libnetwork#1473](https://github.com/docker/libnetwork/pull/1473) - - Fix service published port cleanup issues [docker/libetwork#1432](https://github.com/docker/libnetwork/pull/1432) [docker/libnetwork#1433](https://github.com/docker/libnetwork/pull/1433) - * Recover properly from transient gossip failures [docker/libnetwork#1446](https://github.com/docker/libnetwork/pull/1446) - * Disambiguate node names known to gossip cluster to avoid node name collision [docker/libnetwork#1451](https://github.com/docker/libnetwork/pull/1451) - * Honor user provided listen address for gossip [docker/libnetwork#1460](https://github.com/docker/libnetwork/pull/1460) - * Allow reachability via published port across services on the same host [docker/libnetwork#1398](https://github.com/docker/libnetwork/pull/1398) - * Change the ingress sandbox name from random id to just `ingress_sbox` [docker/libnetwork#1449](https://github.com/docker/libnetwork/pull/1449) - - Disable service discovery in ingress network [docker/libnetwork#1489](https://github.com/docker/libnetwork/pull/1489) - -### Swarm Mode - -* Fix remote detection of a node's address when it joins the cluster [#26211](https://github.com/docker/docker/pull/26211) -* Vendor SwarmKit [#26765](https://github.com/docker/docker/pull/26765) - * Bounce session after failed status update [docker/swarmkit#1539](https://github.com/docker/swarmkit/pull/1539) - - Fix possible raft deadlocks [docker/swarmkit#1537](https://github.com/docker/swarmkit/pull/1537) - - Fix panic and endpoint leak when a service is updated with no endpoints [docker/swarmkit#1481](https://github.com/docker/swarmkit/pull/1481) - * Produce an error if the same port is published twice on `service create` or `service update` [docker/swarmkit#1495](https://github.com/docker/swarmkit/pull/1495) - - Fix an issue where changes to a service were not detected, resulting in the service not being updated [docker/swarmkit#1497](https://github.com/docker/swarmkit/pull/1497) - - Do not allow service creation on ingress network [docker/swarmkit#1600](https://github.com/docker/swarmkit/pull/1600) - -### Contrib - -* Update the debian sysv-init script to use `dockerd` instead of `docker daemon` [#25869](https://github.com/docker/docker/pull/25869) -* Improve stability when running the docker client on MacOS Sierra [#26875](https://github.com/docker/docker/pull/26875) -- Fix installation on debian stretch [#27184](https://github.com/docker/docker/pull/27184) - -### Windows - -- Fix an issue where arrow-navigation did not work when running the docker client in ConEmu [#25578](https://github.com/docker/docker/pull/25578) - -## 1.12.1 (2016-08-18) - -**IMPORTANT**: Docker 1.12 ships with an updated systemd unit file for rpm -based installs (which includes RHEL, Fedora, CentOS, and Oracle Linux 7). When -upgrading from an older version of docker, the upgrade process may not -automatically install the updated version of the unit file, or fail to start -the docker service if; - -- the systemd unit file (`/usr/lib/systemd/system/docker.service`) contains local changes, or -- a systemd drop-in file is present, and contains `-H fd://` in the `ExecStart` directive - -Starting the docker service will produce an error: - - Failed to start docker.service: Unit docker.socket failed to load: No such file or directory. - -or - - no sockets found via socket activation: make sure the service was started by systemd. - -To resolve this: - -- Backup the current version of the unit file, and replace the file with the - [version that ships with docker 1.12](https://raw.githubusercontent.com/docker/docker/v1.12.0/contrib/init/systemd/docker.service.rpm) -- Remove the `Requires=docker.socket` directive from the `/usr/lib/systemd/system/docker.service` file if present -- Remove `-H fd://` from the `ExecStart` directive (both in the main unit file, and in any drop-in files present). - -After making those changes, run `sudo systemctl daemon-reload`, and `sudo -systemctl restart docker` to reload changes and (re)start the docker daemon. - - -### Client - -* Add `Joined at` information in `node inspect --pretty` [#25512](https://github.com/docker/docker/pull/25512) -- Fix a crash on `service inspect` [#25454](https://github.com/docker/docker/pull/25454) -- Fix issue preventing `service update --env-add` to work as intended [#25427](https://github.com/docker/docker/pull/25427) -- Fix issue preventing `service update --publish-add` to work as intended [#25428](https://github.com/docker/docker/pull/25428) -- Remove `service update --network-add` and `service update --network-rm` flags - because this feature is not yet implemented in 1.12, but was inadvertently added - to the client in 1.12.0 [#25646](https://github.com/docker/docker/pull/25646) - -### Contrib - -+ Official ARM installation for Debian Jessie, Ubuntu Trusty, and Raspbian Jessie [#24815](https://github.com/docker/docker/pull/24815) [#25591](https://github.com/docker/docker/pull/25637) -- Add selinux policy per distro/version, fixing issue preventing successful installation on Fedora 24, and Oracle Linux [#25334](https://github.com/docker/docker/pull/25334) [#25593](https://github.com/docker/docker/pull/25593) - -### Networking - -- Fix issue that prevented containers to be accessed by hostname with Docker overlay driver in Swarm Mode [#25603](https://github.com/docker/docker/pull/25603) [#25648](https://github.com/docker/docker/pull/25648) -- Fix random network issues on service with published port [#25603](https://github.com/docker/docker/pull/25603) -- Fix unreliable inter-service communication after scaling down and up [#25603](https://github.com/docker/docker/pull/25603) -- Fix issue where removing all tasks on a node and adding them back breaks connectivity with other services [#25603](https://github.com/docker/docker/pull/25603) -- Fix issue where a task that fails to start results in a race, causing a `network xxx not found` error that masks the actual error [#25550](https://github.com/docker/docker/pull/25550) -- Relax validation of SRV records for external services that use SRV records not formatted according to RFC 2782 [#25739](https://github.com/docker/docker/pull/25739) - -### Plugins (experimental) - -* Make daemon events listen for plugin lifecycle events [#24760](https://github.com/docker/docker/pull/24760) -* Check for plugin state before enabling plugin [#25033](https://github.com/docker/docker/pull/25033) -- Remove plugin root from filesystem on `plugin rm` [#25187](https://github.com/docker/docker/pull/25187) -- Prevent deadlock when more than one plugin is installed [#25384](https://github.com/docker/docker/pull/25384) - -### Runtime - -* Mask join tokens in daemon logs [#25346](https://github.com/docker/docker/pull/25346) -- Fix `docker ps --filter` causing the results to no longer be sorted by creation time [#25387](https://github.com/docker/docker/pull/25387) -- Fix various crashes [#25053](https://github.com/docker/docker/pull/25053) - -### Security - -* Add `/proc/timer_list` to the masked paths list to prevent information leak from the host [#25630](https://github.com/docker/docker/pull/25630) -* Allow systemd to run with only `--cap-add SYS_ADMIN` rather than having to also add `--cap-add DAC_READ_SEARCH` or disabling seccomp filtering [#25567](https://github.com/docker/docker/pull/25567) - -### Swarm - -- Fix an issue where the swarm can get stuck electing a new leader after quorum is lost [#25055](https://github.com/docker/docker/issues/25055) -- Fix unwanted rescheduling of containers after a leader failover [#25017](https://github.com/docker/docker/issues/25017) -- Change swarm root CA key to P256 curve [swarmkit#1376](https://github.com/docker/swarmkit/pull/1376) -- Allow forced removal of a node from a swarm [#25159](https://github.com/docker/docker/pull/25159) -- Fix connection leak when a node leaves a swarm [swarmkit/#1277](https://github.com/docker/swarmkit/pull/1277) -- Backdate swarm certificates by one hour to tolerate more clock skew [swarmkit/#1243](https://github.com/docker/swarmkit/pull/1243) -- Avoid high CPU use with many unschedulable tasks [swarmkit/#1287](https://github.com/docker/swarmkit/pull/1287) -- Fix issue with global tasks not starting up [swarmkit/#1295](https://github.com/docker/swarmkit/pull/1295) -- Garbage collect raft logs [swarmkit/#1327](https://github.com/docker/swarmkit/pull/1327) - -### Volume - -- Persist local volume options after a daemon restart [#25316](https://github.com/docker/docker/pull/25316) -- Fix an issue where the mount ID was not returned on volume unmount [#25333](https://github.com/docker/docker/pull/25333) -- Fix an issue where a volume mount could inadvertently create a bind mount [#25309](https://github.com/docker/docker/pull/25309) -- `docker service create --mount type=bind,...` now correctly validates if the source path exists, instead of creating it [#25494](https://github.com/docker/docker/pull/25494) - -## 1.12.0 (2016-07-28) - - -**IMPORTANT**: Docker 1.12.0 ships with an updated systemd unit file for rpm -based installs (which includes RHEL, Fedora, CentOS, and Oracle Linux 7). When -upgrading from an older version of docker, the upgrade process may not -automatically install the updated version of the unit file, or fail to start -the docker service if; - -- the systemd unit file (`/usr/lib/systemd/system/docker.service`) contains local changes, or -- a systemd drop-in file is present, and contains `-H fd://` in the `ExecStart` directive - -Starting the docker service will produce an error: - - Failed to start docker.service: Unit docker.socket failed to load: No such file or directory. - -or - - no sockets found via socket activation: make sure the service was started by systemd. - -To resolve this: - -- Backup the current version of the unit file, and replace the file with the - [version that ships with docker 1.12](https://raw.githubusercontent.com/docker/docker/v1.12.0/contrib/init/systemd/docker.service.rpm) -- Remove the `Requires=docker.socket` directive from the `/usr/lib/systemd/system/docker.service` file if present -- Remove `-H fd://` from the `ExecStart` directive (both in the main unit file, and in any drop-in files present). - -After making those changes, run `sudo systemctl daemon-reload`, and `sudo -systemctl restart docker` to reload changes and (re)start the docker daemon. - -**IMPORTANT**: With Docker 1.12, a Linux docker installation now has two -additional binaries; `dockerd`, and `docker-proxy`. If you have scripts for -installing docker, please make sure to update them accordingly. - -### Builder - -+ New `HEALTHCHECK` Dockerfile instruction to support user-defined healthchecks [#23218](https://github.com/docker/docker/pull/23218) -+ New `SHELL` Dockerfile instruction to specify the default shell when using the shell form for commands in a Dockerfile [#22489](https://github.com/docker/docker/pull/22489) -+ Add `#escape=` Dockerfile directive to support platform-specific parsing of file paths in Dockerfile [#22268](https://github.com/docker/docker/pull/22268) -+ Add support for comments in `.dockerignore` [#23111](https://github.com/docker/docker/pull/23111) -* Support for UTF-8 in Dockerfiles [#23372](https://github.com/docker/docker/pull/23372) -* Skip UTF-8 BOM bytes from `Dockerfile` and `.dockerignore` if exist [#23234](https://github.com/docker/docker/pull/23234) -* Windows: support for `ARG` to match Linux [#22508](https://github.com/docker/docker/pull/22508) -- Fix error message when building using a daemon with the bridge network disabled [#22932](https://github.com/docker/docker/pull/22932) - -### Contrib - -* Enable seccomp for Centos 7 and Oracle Linux 7 [#22344](https://github.com/docker/docker/pull/22344) -- Remove MountFlags in systemd unit to allow shared mount propagation [#22806](https://github.com/docker/docker/pull/22806) - -### Distribution - -+ Add `--max-concurrent-downloads` and `--max-concurrent-uploads` daemon flags useful for situations where network connections don't support multiple downloads/uploads [#22445](https://github.com/docker/docker/pull/22445) -* Registry operations now honor the `ALL_PROXY` environment variable [#22316](https://github.com/docker/docker/pull/22316) -* Provide more information to the user on `docker load` [#23377](https://github.com/docker/docker/pull/23377) -* Always save registry digest metadata about images pushed and pulled [#23996](https://github.com/docker/docker/pull/23996) - -### Logging - -+ Syslog logging driver now supports DGRAM sockets [#21613](https://github.com/docker/docker/pull/21613) -+ Add `--details` option to `docker logs` to also display log tags [#21889](https://github.com/docker/docker/pull/21889) -+ Enable syslog logger to have access to env and labels [#21724](https://github.com/docker/docker/pull/21724) -+ An additional syslog-format option `rfc5424micro` to allow microsecond resolution in syslog timestamp [#21844](https://github.com/docker/docker/pull/21844) -* Inherit the daemon log options when creating containers [#21153](https://github.com/docker/docker/pull/21153) -* Remove `docker/` prefix from log messages tag and replace it with `{{.DaemonName}}` so that users have the option of changing the prefix [#22384](https://github.com/docker/docker/pull/22384) - -### Networking - -+ Built-in Virtual-IP based internal and ingress load-balancing using IPVS [#23361](https://github.com/docker/docker/pull/23361) -+ Routing Mesh using ingress overlay network [#23361](https://github.com/docker/docker/pull/23361) -+ Secured multi-host overlay networking using encrypted control-plane and Data-plane [#23361](https://github.com/docker/docker/pull/23361) -+ MacVlan driver is out of experimental [#23524](https://github.com/docker/docker/pull/23524) -+ Add `driver` filter to `network ls` [#22319](https://github.com/docker/docker/pull/22319) -+ Adding `network` filter to `docker ps --filter` [#23300](https://github.com/docker/docker/pull/23300) -+ Add `--link-local-ip` flag to `create`, `run` and `network connect` to specify a container's link-local address [#23415](https://github.com/docker/docker/pull/23415) -+ Add network label filter support [#21495](https://github.com/docker/docker/pull/21495) -* Removed dependency on external KV-Store for Overlay networking in Swarm-Mode [#23361](https://github.com/docker/docker/pull/23361) -* Add container's short-id as default network alias [#21901](https://github.com/docker/docker/pull/21901) -* `run` options `--dns` and `--net=host` are no longer mutually exclusive [#22408](https://github.com/docker/docker/pull/22408) -- Fix DNS issue when renaming containers with generated names [#22716](https://github.com/docker/docker/pull/22716) -- Allow both `network inspect -f {{.Id}}` and `network inspect -f {{.ID}}` to address inconsistency with inspect output [#23226](https://github.com/docker/docker/pull/23226) - -### Plugins (experimental) - -+ New `plugin` command to manager plugins with `install`, `enable`, `disable`, `rm`, `inspect`, `set` subcommands [#23446](https://github.com/docker/docker/pull/23446) - -### Remote API (v1.24) & Client - -+ Split the binary into two: `docker` (client) and `dockerd` (daemon) [#20639](https://github.com/docker/docker/pull/20639) -+ Add `before` and `since` filters to `docker images --filter` [#22908](https://github.com/docker/docker/pull/22908) -+ Add `--limit` option to `docker search` [#23107](https://github.com/docker/docker/pull/23107) -+ Add `--filter` option to `docker search` [#22369](https://github.com/docker/docker/pull/22369) -+ Add security options to `docker info` output [#21172](https://github.com/docker/docker/pull/21172) [#23520](https://github.com/docker/docker/pull/23520) -+ Add insecure registries to `docker info` output [#20410](https://github.com/docker/docker/pull/20410) -+ Extend Docker authorization with TLS user information [#21556](https://github.com/docker/docker/pull/21556) -+ devicemapper: expose Mininum Thin Pool Free Space through `docker info` [#21945](https://github.com/docker/docker/pull/21945) -* API now returns a JSON object when an error occurs making it more consistent [#22880](https://github.com/docker/docker/pull/22880) -- Prevent `docker run -i --restart` from hanging on exit [#22777](https://github.com/docker/docker/pull/22777) -- Fix API/CLI discrepancy on hostname validation [#21641](https://github.com/docker/docker/pull/21641) -- Fix discrepancy in the format of sizes in `stats` from HumanSize to BytesSize [#21773](https://github.com/docker/docker/pull/21773) -- authz: when request is denied return forbbiden exit code (403) [#22448](https://github.com/docker/docker/pull/22448) -- Windows: fix tty-related displaying issues [#23878](https://github.com/docker/docker/pull/23878) - -### Runtime - -+ Split the userland proxy to a separate binary (`docker-proxy`) [#23312](https://github.com/docker/docker/pull/23312) -+ Add `--live-restore` daemon flag to keep containers running when daemon shuts down, and regain control on startup [#23213](https://github.com/docker/docker/pull/23213) -+ Ability to add OCI-compatible runtimes (via `--add-runtime` daemon flag) and select one with `--runtime` on `create` and `run` [#22983](https://github.com/docker/docker/pull/22983) -+ New `overlay2` graphdriver for Linux 4.0+ with multiple lower directory support [#22126](https://github.com/docker/docker/pull/22126) -+ New load/save image events [#22137](https://github.com/docker/docker/pull/22137) -+ Add support for reloading daemon configuration through systemd [#22446](https://github.com/docker/docker/pull/22446) -+ Add disk quota support for btrfs [#19651](https://github.com/docker/docker/pull/19651) -+ Add disk quota support for zfs [#21946](https://github.com/docker/docker/pull/21946) -+ Add support for `docker run --pid=container:` [#22481](https://github.com/docker/docker/pull/22481) -+ Align default seccomp profile with selected capabilities [#22554](https://github.com/docker/docker/pull/22554) -+ Add a `daemon reload` event when the daemon reloads its configuration [#22590](https://github.com/docker/docker/pull/22590) -+ Add `trace` capability in the pprof profiler to show execution traces in binary form [#22715](https://github.com/docker/docker/pull/22715) -+ Add a `detach` event [#22898](https://github.com/docker/docker/pull/22898) -+ Add support for setting sysctls with `--sysctl` [#19265](https://github.com/docker/docker/pull/19265) -+ Add `--storage-opt` flag to `create` and `run` allowing to set `size` on devicemapper [#19367](https://github.com/docker/docker/pull/19367) -+ Add `--oom-score-adjust` daemon flag with a default value of `-500` making the daemon less likely to be killed before containers [#24516](https://github.com/docker/docker/pull/24516) -* Undeprecate the `-c` short alias of `--cpu-shares` on `run`, `build`, `create`, `update` [#22621](https://github.com/docker/docker/pull/22621) -* Prevent from using aufs and overlay graphdrivers on an eCryptfs mount [#23121](https://github.com/docker/docker/pull/23121) -- Fix issues with tmpfs mount ordering [#22329](https://github.com/docker/docker/pull/22329) -- Created containers are no longer listed on `docker ps -a -f exited=0` [#21947](https://github.com/docker/docker/pull/21947) -- Fix an issue where containers are stuck in a "Removal In Progress" state [#22423](https://github.com/docker/docker/pull/22423) -- Fix bug that was returning an HTTP 500 instead of a 400 when not specifying a command on run/create [#22762](https://github.com/docker/docker/pull/22762) -- Fix bug with `--detach-keys` whereby input matching a prefix of the detach key was not preserved [#22943](https://github.com/docker/docker/pull/22943) -- SELinux labeling is now disabled when using `--privileged` mode [#22993](https://github.com/docker/docker/pull/22993) -- If volume-mounted into a container, `/etc/hosts`, `/etc/resolv.conf`, `/etc/hostname` are no longer SELinux-relabeled [#22993](https://github.com/docker/docker/pull/22993) -- Fix inconsistency in `--tmpfs` behavior regarding mount options [#22438](https://github.com/docker/docker/pull/22438) -- Fix an issue where daemon hangs at startup [#23148](https://github.com/docker/docker/pull/23148) -- Ignore SIGPIPE events to prevent journald restarts to crash docker in some cases [#22460](https://github.com/docker/docker/pull/22460) -- Containers are not removed from stats list on error [#20835](https://github.com/docker/docker/pull/20835) -- Fix `on-failure` restart policy when daemon restarts [#20853](https://github.com/docker/docker/pull/20853) -- Fix an issue with `stats` when a container is using another container's network [#21904](https://github.com/docker/docker/pull/21904) - -### Swarm Mode - -+ New `swarm` command to manage swarms with `init`, `join`, `join-token`, `leave`, `update` subcommands [#23361](https://github.com/docker/docker/pull/23361) [#24823](https://github.com/docker/docker/pull/24823) -+ New `service` command to manage swarm-wide services with `create`, `inspect`, `update`, `rm`, `ps` subcommands [#23361](https://github.com/docker/docker/pull/23361) [#25140](https://github.com/docker/docker/pull/25140) -+ New `node` command to manage nodes with `accept`, `promote`, `demote`, `inspect`, `update`, `ps`, `ls` and `rm` subcommands [#23361](https://github.com/docker/docker/pull/23361) [#25140](https://github.com/docker/docker/pull/25140) -+ (experimental) New `stack` and `deploy` commands to manage and deploy multi-service applications [#23522](https://github.com/docker/docker/pull/23522) [#25140](https://github.com/docker/docker/pull/25140) - -### Volume - -+ Add support for local and global volume scopes (analogous to network scopes) [#22077](https://github.com/docker/docker/pull/22077) -+ Allow volume drivers to provide a `Status` field [#21006](https://github.com/docker/docker/pull/21006) -+ Add name/driver filter support for volume [#21361](https://github.com/docker/docker/pull/21361) -* Mount/Unmount operations now receives an opaque ID to allow volume drivers to differentiate between two callers [#21015](https://github.com/docker/docker/pull/21015) -- Fix issue preventing to remove a volume in a corner case [#22103](https://github.com/docker/docker/pull/22103) -- Windows: Enable auto-creation of host-path to match Linux [#22094](https://github.com/docker/docker/pull/22094) - - -### DEPRECATION -* Environment variables `DOCKER_CONTENT_TRUST_OFFLINE_PASSPHRASE` and `DOCKER_CONTENT_TRUST_TAGGING_PASSPHRASE` have been renamed - to `DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE` and `DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE` respectively [#22574](https://github.com/docker/docker/pull/22574) -* Remove deprecated `syslog-tag`, `gelf-tag`, `fluentd-tag` log option in favor of the more generic `tag` one [#22620](https://github.com/docker/docker/pull/22620) -* Remove deprecated feature of passing HostConfig at API container start [#22570](https://github.com/docker/docker/pull/22570) -* Remove deprecated `-f`/`--force` flag on docker tag [#23090](https://github.com/docker/docker/pull/23090) -* Remove deprecated `/containers//copy` endpoint [#22149](https://github.com/docker/docker/pull/22149) -* Remove deprecated `docker ps` flags `--since` and `--before` [#22138](https://github.com/docker/docker/pull/22138) -* Deprecate the old 3-args form of `docker import` [#23273](https://github.com/docker/docker/pull/23273) - -## 1.11.2 (2016-05-31) - -### Networking - -- Fix a stale endpoint issue on overlay networks during ungraceful restart ([#23015](https://github.com/docker/docker/pull/23015)) -- Fix an issue where the wrong port could be reported by `docker inspect/ps/port` ([#22997](https://github.com/docker/docker/pull/22997)) - -### Runtime - -- Fix a potential panic when running `docker build` ([#23032](https://github.com/docker/docker/pull/23032)) -- Fix interpretation of `--user` parameter ([#22998](https://github.com/docker/docker/pull/22998)) -- Fix a bug preventing container statistics to be correctly reported ([#22955](https://github.com/docker/docker/pull/22955)) -- Fix an issue preventing container to be restarted after daemon restart ([#22947](https://github.com/docker/docker/pull/22947)) -- Fix issues when running 32 bit binaries on Ubuntu 16.04 ([#22922](https://github.com/docker/docker/pull/22922)) -- Fix a possible deadlock on image deletion and container attach ([#22918](https://github.com/docker/docker/pull/22918)) -- Fix an issue where containers fail to start after a daemon restart if they depend on a containerized cluster store ([#22561](https://github.com/docker/docker/pull/22561)) -- Fix an issue causing `docker ps` to hang on CentOS when using devicemapper ([#22168](https://github.com/docker/docker/pull/22168), [#23067](https://github.com/docker/docker/pull/23067)) -- Fix a bug preventing to `docker exec` into a container when using devicemapper ([#22168](https://github.com/docker/docker/pull/22168), [#23067](https://github.com/docker/docker/pull/23067)) - - -## 1.11.1 (2016-04-26) - -### Distribution - -- Fix schema2 manifest media type to be of type `application/vnd.docker.container.image.v1+json` ([#21949](https://github.com/docker/docker/pull/21949)) - -### Documentation - -+ Add missing API documentation for changes introduced with 1.11.0 ([#22048](https://github.com/docker/docker/pull/22048)) - -### Builder - -* Append label passed to `docker build` as arguments as an implicit `LABEL` command at the end of the processed `Dockerfile` ([#22184](https://github.com/docker/docker/pull/22184)) - -### Networking - -- Fix a panic that would occur when forwarding DNS query ([#22261](https://github.com/docker/docker/pull/22261)) -- Fix an issue where OS threads could end up within an incorrect network namespace when using user defined networks ([#22261](https://github.com/docker/docker/pull/22261)) - -### Runtime - -- Fix a bug preventing labels configuration to be reloaded via the config file ([#22299](https://github.com/docker/docker/pull/22299)) -- Fix a regression where container mounting `/var/run` would prevent other containers from being removed ([#22256](https://github.com/docker/docker/pull/22256)) -- Fix an issue where it would be impossible to update both `memory-swap` and `memory` value together ([#22255](https://github.com/docker/docker/pull/22255)) -- Fix a regression from 1.11.0 where the `/auth` endpoint would not initialize `serveraddress` if it is not provided ([#22254](https://github.com/docker/docker/pull/22254)) -- Add missing cleanup of container temporary files when cancelling a schedule restart ([#22237](https://github.com/docker/docker/pull/22237)) -- Remove scary error message when no restart policy is specified ([#21993](https://github.com/docker/docker/pull/21993)) -- Fix a panic that would occur when the plugins were activated via the json spec ([#22191](https://github.com/docker/docker/pull/22191)) -- Fix restart backoff logic to correctly reset delay if container ran for at least 10secs ([#22125](https://github.com/docker/docker/pull/22125)) -- Remove error message when a container restart get cancelled ([#22123](https://github.com/docker/docker/pull/22123)) -- Fix an issue where `docker` would not correctly clean up after `docker exec` ([#22121](https://github.com/docker/docker/pull/22121)) -- Fix a panic that could occur when serving concurrent `docker stats` commands ([#22120](https://github.com/docker/docker/pull/22120))` -- Revert deprecation of non-existent host directories auto-creation ([#22065](https://github.com/docker/docker/pull/22065)) -- Hide misleading rpc error on daemon shutdown ([#22058](https://github.com/docker/docker/pull/22058)) - -## 1.11.0 (2016-04-13) - -**IMPORTANT**: With Docker 1.11, a Linux docker installation is now made of 4 binaries (`docker`, [`docker-containerd`](https://github.com/docker/containerd), [`docker-containerd-shim`](https://github.com/docker/containerd) and [`docker-runc`](https://github.com/opencontainers/runc)). If you have scripts relying on docker being a single static binaries, please make sure to update them. Interaction with the daemon stay the same otherwise, the usage of the other binaries should be transparent. A Windows docker installation remains a single binary, `docker.exe`. - -### Builder - -- Fix a bug where Docker would not use the correct uid/gid when processing the `WORKDIR` command ([#21033](https://github.com/docker/docker/pull/21033)) -- Fix a bug where copy operations with userns would not use the proper uid/gid ([#20782](https://github.com/docker/docker/pull/20782), [#21162](https://github.com/docker/docker/pull/21162)) - -### Client - -* Usage of the `:` separator for security option has been deprecated. `=` should be used instead ([#21232](https://github.com/docker/docker/pull/21232)) -+ The client user agent is now passed to the registry on `pull`, `build`, `push`, `login` and `search` operations ([#21306](https://github.com/docker/docker/pull/21306), [#21373](https://github.com/docker/docker/pull/21373)) -* Allow setting the Domainname and Hostname separately through the API ([#20200](https://github.com/docker/docker/pull/20200)) -* Docker info will now warn users if it can not detect the kernel version or the operating system ([#21128](https://github.com/docker/docker/pull/21128)) -- Fix an issue where `docker stats --no-stream` output could be all 0s ([#20803](https://github.com/docker/docker/pull/20803)) -- Fix a bug where some newly started container would not appear in a running `docker stats` command ([#20792](https://github.com/docker/docker/pull/20792)) -* Post processing is no longer enabled for linux-cgo terminals ([#20587](https://github.com/docker/docker/pull/20587)) -- Values to `--hostname` are now refused if they do not comply with [RFC1123](https://tools.ietf.org/html/rfc1123) ([#20566](https://github.com/docker/docker/pull/20566)) -+ Docker learned how to use a SOCKS proxy ([#20366](https://github.com/docker/docker/pull/20366), [#18373](https://github.com/docker/docker/pull/18373)) -+ Docker now supports external credential stores ([#20107](https://github.com/docker/docker/pull/20107)) -* `docker ps` now supports displaying the list of volumes mounted inside a container ([#20017](https://github.com/docker/docker/pull/20017)) -* `docker info` now also reports Docker's root directory location ([#19986](https://github.com/docker/docker/pull/19986)) -- Docker now prohibits login in with an empty username (spaces are trimmed) ([#19806](https://github.com/docker/docker/pull/19806)) -* Docker events attributes are now sorted by key ([#19761](https://github.com/docker/docker/pull/19761)) -* `docker ps` no longer shows exported port for stopped containers ([#19483](https://github.com/docker/docker/pull/19483)) -- Docker now cleans after itself if a save/export command fails ([#17849](https://github.com/docker/docker/pull/17849)) -* Docker load learned how to display a progress bar ([#17329](https://github.com/docker/docker/pull/17329), [#120078](https://github.com/docker/docker/pull/20078)) - -### Distribution - -- Fix a panic that occurred when pulling an image with 0 layers ([#21222](https://github.com/docker/docker/pull/21222)) -- Fix a panic that could occur on error while pushing to a registry with a misconfigured token service ([#21212](https://github.com/docker/docker/pull/21212)) -+ All first-level delegation roles are now signed when doing a trusted push ([#21046](https://github.com/docker/docker/pull/21046)) -+ OAuth support for registries was added ([#20970](https://github.com/docker/docker/pull/20970)) -* `docker login` now handles token using the implementation found in [docker/distribution](https://github.com/docker/distribution) ([#20832](https://github.com/docker/docker/pull/20832)) -* `docker login` will no longer prompt for an email ([#20565](https://github.com/docker/docker/pull/20565)) -* Docker will now fallback to registry V1 if no basic auth credentials are available ([#20241](https://github.com/docker/docker/pull/20241)) -* Docker will now try to resume layer download where it left off after a network error/timeout ([#19840](https://github.com/docker/docker/pull/19840)) -- Fix generated manifest mediaType when pushing cross-repository ([#19509](https://github.com/docker/docker/pull/19509)) -- Fix docker requesting additional push credentials when pulling an image if Content Trust is enabled ([#20382](https://github.com/docker/docker/pull/20382)) - -### Logging - -- Fix a race in the journald log driver ([#21311](https://github.com/docker/docker/pull/21311)) -* Docker syslog driver now uses the RFC-5424 format when emitting logs ([#20121](https://github.com/docker/docker/pull/20121)) -* Docker GELF log driver now allows to specify the compression algorithm and level via the `gelf-compression-type` and `gelf-compression-level` options ([#19831](https://github.com/docker/docker/pull/19831)) -* Docker daemon learned to output uncolorized logs via the `--raw-logs` options ([#19794](https://github.com/docker/docker/pull/19794)) -+ Docker, on Windows platform, now includes an ETW (Event Tracing in Windows) logging driver named `etwlogs` ([#19689](https://github.com/docker/docker/pull/19689)) -* Journald log driver learned how to handle tags ([#19564](https://github.com/docker/docker/pull/19564)) -+ The fluentd log driver learned the following options: `fluentd-address`, `fluentd-buffer-limit`, `fluentd-retry-wait`, `fluentd-max-retries` and `fluentd-async-connect` ([#19439](https://github.com/docker/docker/pull/19439)) -+ Docker learned to send log to Google Cloud via the new `gcplogs` logging driver. ([#18766](https://github.com/docker/docker/pull/18766)) - - -### Misc - -+ When saving linked images together with `docker save` a subsequent `docker load` will correctly restore their parent/child relationship ([#21385](https://github.com/docker/docker/pull/21385)) -+ Support for building the Docker cli for OpenBSD was added ([#21325](https://github.com/docker/docker/pull/21325)) -+ Labels can now be applied at network, volume and image creation ([#21270](https://github.com/docker/docker/pull/21270)) -* The `dockremap` is now created as a system user ([#21266](https://github.com/docker/docker/pull/21266)) -- Fix a few response body leaks ([#21258](https://github.com/docker/docker/pull/21258)) -- Docker, when run as a service with systemd, will now properly manage its processes cgroups ([#20633](https://github.com/docker/docker/pull/20633)) -* `docker info` now reports the value of cgroup KernelMemory or emits a warning if it is not supported ([#20863](https://github.com/docker/docker/pull/20863)) -* `docker info` now also reports the cgroup driver in use ([#20388](https://github.com/docker/docker/pull/20388)) -* Docker completion is now available on PowerShell ([#19894](https://github.com/docker/docker/pull/19894)) -* `dockerinit` is no more ([#19490](https://github.com/docker/docker/pull/19490),[#19851](https://github.com/docker/docker/pull/19851)) -+ Support for building Docker on arm64 was added ([#19013](https://github.com/docker/docker/pull/19013)) -+ Experimental support for building docker.exe in a native Windows Docker installation ([#18348](https://github.com/docker/docker/pull/18348)) - -### Networking - -- Fix panic if a node is forcibly removed from the cluster ([#21671](https://github.com/docker/docker/pull/21671)) -- Fix "error creating vxlan interface" when starting a container in a Swarm cluster ([#21671](https://github.com/docker/docker/pull/21671)) -* `docker network inspect` will now report all endpoints whether they have an active container or not ([#21160](https://github.com/docker/docker/pull/21160)) -+ Experimental support for the MacVlan and IPVlan network drivers has been added ([#21122](https://github.com/docker/docker/pull/21122)) -* Output of `docker network ls` is now sorted by network name ([#20383](https://github.com/docker/docker/pull/20383)) -- Fix a bug where Docker would allow a network to be created with the reserved `default` name ([#19431](https://github.com/docker/docker/pull/19431)) -* `docker network inspect` returns whether a network is internal or not ([#19357](https://github.com/docker/docker/pull/19357)) -+ Control IPv6 via explicit option when creating a network (`docker network create --ipv6`). This shows up as a new `EnableIPv6` field in `docker network inspect` ([#17513](https://github.com/docker/docker/pull/17513)) -* Support for AAAA Records (aka IPv6 Service Discovery) in embedded DNS Server ([#21396](https://github.com/docker/docker/pull/21396)) -- Fix to not forward docker domain IPv6 queries to external servers ([#21396](https://github.com/docker/docker/pull/21396)) -* Multiple A/AAAA records from embedded DNS Server for DNS Round robin ([#21019](https://github.com/docker/docker/pull/21019)) -- Fix endpoint count inconsistency after an ungraceful dameon restart ([#21261](https://github.com/docker/docker/pull/21261)) -- Move the ownership of exposed ports and port-mapping options from Endpoint to Sandbox ([#21019](https://github.com/docker/docker/pull/21019)) -- Fixed a bug which prevents docker reload when host is configured with ipv6.disable=1 ([#21019](https://github.com/docker/docker/pull/21019)) -- Added inbuilt nil IPAM driver ([#21019](https://github.com/docker/docker/pull/21019)) -- Fixed bug in iptables.Exists() logic [#21019](https://github.com/docker/docker/pull/21019) -- Fixed a Veth interface leak when using overlay network ([#21019](https://github.com/docker/docker/pull/21019)) -- Fixed a bug which prevents docker reload after a network delete during shutdown ([#20214](https://github.com/docker/docker/pull/20214)) -- Make sure iptables chains are recreated on firewalld reload ([#20419](https://github.com/docker/docker/pull/20419)) -- Allow to pass global datastore during config reload ([#20419](https://github.com/docker/docker/pull/20419)) -- For anonymous containers use the alias name for IP to name mapping, ie:DNS PTR record ([#21019](https://github.com/docker/docker/pull/21019)) -- Fix a panic when deleting an entry from /etc/hosts file ([#21019](https://github.com/docker/docker/pull/21019)) -- Source the forwarded DNS queries from the container net namespace ([#21019](https://github.com/docker/docker/pull/21019)) -- Fix to retain the network internal mode config for bridge networks on daemon reload ([#21780] (https://github.com/docker/docker/pull/21780)) -- Fix to retain IPAM driver option configs on daemon reload ([#21914] (https://github.com/docker/docker/pull/21914)) - -### Plugins - -- Fix a file descriptor leak that would occur every time plugins were enumerated ([#20686](https://github.com/docker/docker/pull/20686)) -- Fix an issue where Authz plugin would corrupt the payload body when faced with a large amount of data ([#20602](https://github.com/docker/docker/pull/20602)) - -### Runtime - -- Fix a panic that could occur when cleanup after a container started with invalid parameters ([#21716](https://github.com/docker/docker/pull/21716)) -- Fix a race with event timers stopping early ([#21692](https://github.com/docker/docker/pull/21692)) -- Fix race conditions in the layer store, potentially corrupting the map and crashing the process ([#21677](https://github.com/docker/docker/pull/21677)) -- Un-deprecate auto-creation of host directories for mounts. This feature was marked deprecated in ([#21666](https://github.com/docker/docker/pull/21666)) - Docker 1.9, but was decided to be too much of a backward-incompatible change, so it was decided to keep the feature. -+ It is now possible for containers to share the NET and IPC namespaces when `userns` is enabled ([#21383](https://github.com/docker/docker/pull/21383)) -+ `docker inspect ` will now expose the rootfs layers ([#21370](https://github.com/docker/docker/pull/21370)) -+ Docker Windows gained a minimal `top` implementation ([#21354](https://github.com/docker/docker/pull/21354)) -* Docker learned to report the faulty exe when a container cannot be started due to its condition ([#21345](https://github.com/docker/docker/pull/21345)) -* Docker with device mapper will now refuse to run if `udev sync` is not available ([#21097](https://github.com/docker/docker/pull/21097)) -- Fix a bug where Docker would not validate the config file upon configuration reload ([#21089](https://github.com/docker/docker/pull/21089)) -- Fix a hang that would happen on attach if initial start was to fail ([#21048](https://github.com/docker/docker/pull/21048)) -- Fix an issue where registry service options in the daemon configuration file were not properly taken into account ([#21045](https://github.com/docker/docker/pull/21045)) -- Fix a race between the exec and resize operations ([#21022](https://github.com/docker/docker/pull/21022)) -- Fix an issue where nanoseconds were not correctly taken in account when filtering Docker events ([#21013](https://github.com/docker/docker/pull/21013)) -- Fix the handling of Docker command when passed a 64 bytes id ([#21002](https://github.com/docker/docker/pull/21002)) -* Docker will now return a `204` (i.e http.StatusNoContent) code when it successfully deleted a network ([#20977](https://github.com/docker/docker/pull/20977)) -- Fix a bug where the daemon would wait indefinitely in case the process it was about to killed had already exited on its own ([#20967](https://github.com/docker/docker/pull/20967) -* The devmapper driver learned the `dm.min_free_space` option. If the mapped device free space reaches the passed value, new device creation will be prohibited. ([#20786](https://github.com/docker/docker/pull/20786)) -+ Docker can now prevent processes in container to gain new privileges via the `--security-opt=no-new-privileges` flag ([#20727](https://github.com/docker/docker/pull/20727)) -- Starting a container with the `--device` option will now correctly resolves symlinks ([#20684](https://github.com/docker/docker/pull/20684)) -+ Docker now relies on [`containerd`](https://github.com/docker/containerd) and [`runc`](https://github.com/opencontainers/runc) to spawn containers. ([#20662](https://github.com/docker/docker/pull/20662)) -- Fix docker configuration reloading to only alter value present in the given config file ([#20604](https://github.com/docker/docker/pull/20604)) -+ Docker now allows setting a container hostname via the `--hostname` flag when `--net=host` ([#20177](https://github.com/docker/docker/pull/20177)) -+ Docker now allows executing privileged container while running with `--userns-remap` if both `--privileged` and the new `--userns=host` flag are specified ([#20111](https://github.com/docker/docker/pull/20111)) -- Fix Docker not cleaning up correctly old containers upon restarting after a crash ([#19679](https://github.com/docker/docker/pull/19679)) -* Docker will now error out if it doesn't recognize a configuration key within the config file ([#19517](https://github.com/docker/docker/pull/19517)) -- Fix container loading, on daemon startup, when they depends on a plugin running within a container ([#19500](https://github.com/docker/docker/pull/19500)) -* `docker update` learned how to change a container restart policy ([#19116](https://github.com/docker/docker/pull/19116)) -* `docker inspect` now also returns a new `State` field containing the container state in a human readable way (i.e. one of `created`, `restarting`, `running`, `paused`, `exited` or `dead`)([#18966](https://github.com/docker/docker/pull/18966)) -+ Docker learned to limit the number of active pids (i.e. processes) within the container via the `pids-limit` flags. NOTE: This requires `CGROUP_PIDS=y` to be in the kernel configuration. ([#18697](https://github.com/docker/docker/pull/18697)) -- `docker load` now has a `--quiet` option to suppress the load output ([#20078](https://github.com/docker/docker/pull/20078)) -- Fix a bug in neighbor discovery for IPv6 peers ([#20842](https://github.com/docker/docker/pull/20842)) -- Fix a panic during cleanup if a container was started with invalid options ([#21802](https://github.com/docker/docker/pull/21802)) -- Fix a situation where a container cannot be stopped if the terminal is closed ([#21840](https://github.com/docker/docker/pull/21840)) - -### Security - -* Object with the `pcp_pmcd_t` selinux type were given management access to `/var/lib/docker(/.*)?` ([#21370](https://github.com/docker/docker/pull/21370)) -* `restart_syscall`, `copy_file_range`, `mlock2` joined the list of allowed calls in the default seccomp profile ([#21117](https://github.com/docker/docker/pull/21117), [#21262](https://github.com/docker/docker/pull/21262)) -* `send`, `recv` and `x32` were added to the list of allowed syscalls and arch in the default seccomp profile ([#19432](https://github.com/docker/docker/pull/19432)) -* Docker Content Trust now requests the server to perform snapshot signing ([#21046](https://github.com/docker/docker/pull/21046)) -* Support for using YubiKeys for Content Trust signing has been moved out of experimental ([#21591](https://github.com/docker/docker/pull/21591)) - -### Volumes - -* Output of `docker volume ls` is now sorted by volume name ([#20389](https://github.com/docker/docker/pull/20389)) -* Local volumes can now accept options similar to the unix `mount` tool ([#20262](https://github.com/docker/docker/pull/20262)) -- Fix an issue where one letter directory name could not be used as source for volumes ([#21106](https://github.com/docker/docker/pull/21106)) -+ `docker run -v` now accepts a new flag `nocopy`. This tells the runtime not to copy the container path content into the volume (which is the default behavior) ([#21223](https://github.com/docker/docker/pull/21223)) - -## 1.10.3 (2016-03-10) - -### Runtime - -- Fix Docker client exiting with an "Unrecognized input header" error [#20706](https://github.com/docker/docker/pull/20706) -- Fix Docker exiting if Exec is started with both `AttachStdin` and `Detach` [#20647](https://github.com/docker/docker/pull/20647) - -### Distribution - -- Fix a crash when pushing multiple images sharing the same layers to the same repository in parallel [#20831](https://github.com/docker/docker/pull/20831) -- Fix a panic when pushing images to a registry which uses a misconfigured token service [#21030](https://github.com/docker/docker/pull/21030) - -### Plugin system - -- Fix issue preventing volume plugins to start when SELinux is enabled [#20834](https://github.com/docker/docker/pull/20834) -- Prevent Docker from exiting if a volume plugin returns a null response for Get requests [#20682](https://github.com/docker/docker/pull/20682) -- Fix plugin system leaking file descriptors if a plugin has an error [#20680](https://github.com/docker/docker/pull/20680) - -### Security - -- Fix linux32 emulation to fail during docker build [#20672](https://github.com/docker/docker/pull/20672) - It was due to the `personality` syscall being blocked by the default seccomp profile. -- Fix Oracle XE 10g failing to start in a container [#20981](https://github.com/docker/docker/pull/20981) - It was due to the `ipc` syscall being blocked by the default seccomp profile. -- Fix user namespaces not working on Linux From Scratch [#20685](https://github.com/docker/docker/pull/20685) -- Fix issue preventing daemon to start if userns is enabled and the `subuid` or `subgid` files contain comments [#20725](https://github.com/docker/docker/pull/20725) - -## 1.10.2 (2016-02-22) - -### Runtime - -- Prevent systemd from deleting containers' cgroups when its configuration is reloaded [#20518](https://github.com/docker/docker/pull/20518) -- Fix SELinux issues by disregarding `--read-only` when mounting `/dev/mqueue` [#20333](https://github.com/docker/docker/pull/20333) -- Fix chown permissions used during `docker cp` when userns is used [#20446](https://github.com/docker/docker/pull/20446) -- Fix configuration loading issue with all booleans defaulting to `true` [#20471](https://github.com/docker/docker/pull/20471) -- Fix occasional panic with `docker logs -f` [#20522](https://github.com/docker/docker/pull/20522) - -### Distribution - -- Keep layer reference if deletion failed to avoid a badly inconsistent state [#20513](https://github.com/docker/docker/pull/20513) -- Handle gracefully a corner case when canceling migration [#20372](https://github.com/docker/docker/pull/20372) -- Fix docker import on compressed data [#20367](https://github.com/docker/docker/pull/20367) -- Fix tar-split files corruption during migration that later cause docker push and docker save to fail [#20458](https://github.com/docker/docker/pull/20458) - -### Networking - -- Fix daemon crash if embedded DNS is sent garbage [#20510](https://github.com/docker/docker/pull/20510) - -### Volumes - -- Fix issue with multiple volume references with same name [#20381](https://github.com/docker/docker/pull/20381) - -### Security - -- Fix potential cache corruption and delegation conflict issues [#20523](https://github.com/docker/docker/pull/20523) - -## 1.10.1 (2016-02-11) - -### Runtime - -* Do not stop daemon on migration hard failure [#20156](https://github.com/docker/docker/pull/20156) -- Fix various issues with migration to content-addressable images [#20058](https://github.com/docker/docker/pull/20058) -- Fix ZFS permission bug with user namespaces [#20045](https://github.com/docker/docker/pull/20045) -- Do not leak /dev/mqueue from the host to all containers, keep it container-specific [#19876](https://github.com/docker/docker/pull/19876) [#20133](https://github.com/docker/docker/pull/20133) -- Fix `docker ps --filter before=...` to not show stopped containers without providing `-a` flag [#20135](https://github.com/docker/docker/pull/20135) - -### Security - -- Fix issue preventing docker events to work properly with authorization plugin [#20002](https://github.com/docker/docker/pull/20002) - -### Distribution - -* Add additional verifications and prevent from uploading invalid data to registries [#20164](https://github.com/docker/docker/pull/20164) -- Fix regression preventing uppercase characters in image reference hostname [#20175](https://github.com/docker/docker/pull/20175) - -### Networking - -- Fix embedded DNS for user-defined networks in the presence of firewalld [#20060](https://github.com/docker/docker/pull/20060) -- Fix issue where removing a network during shutdown left Docker inoperable [#20181](https://github.com/docker/docker/issues/20181) [#20235](https://github.com/docker/docker/issues/20235) -- Embedded DNS is now able to return compressed results [#20181](https://github.com/docker/docker/issues/20181) -- Fix port-mapping issue with `userland-proxy=false` [#20181](https://github.com/docker/docker/issues/20181) - -### Logging - -- Fix bug where tcp+tls protocol would be rejected [#20109](https://github.com/docker/docker/pull/20109) - -### Volumes - -- Fix issue whereby older volume drivers would not receive volume options [#19983](https://github.com/docker/docker/pull/19983) - -### Misc - -- Remove TasksMax from Docker systemd service [#20167](https://github.com/docker/docker/pull/20167) - -## 1.10.0 (2016-02-04) - -**IMPORTANT**: Docker 1.10 uses a new content-addressable storage for images and layers. -A migration is performed the first time docker is run, and can take a significant amount of time depending on the number of images present. -Refer to this page on the wiki for more information: https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration -We also released a cool migration utility that enables you to perform the migration before updating to reduce downtime. -Engine 1.10 migrator can be found on Docker Hub: https://hub.docker.com/r/docker/v1.10-migrator/ - -### Runtime - -+ New `docker update` command that allows updating resource constraints on running containers [#15078](https://github.com/docker/docker/pull/15078) -+ Add `--tmpfs` flag to `docker run` to create a tmpfs mount in a container [#13587](https://github.com/docker/docker/pull/13587) -+ Add `--format` flag to `docker images` command [#17692](https://github.com/docker/docker/pull/17692) -+ Allow to set daemon configuration in a file and hot-reload it with the `SIGHUP` signal [#18587](https://github.com/docker/docker/pull/18587) -+ Updated docker events to include more meta-data and event types [#18888](https://github.com/docker/docker/pull/18888) - This change is backward compatible in the API, but not on the CLI. -+ Add `--blkio-weight-device` flag to `docker run` [#13959](https://github.com/docker/docker/pull/13959) -+ Add `--device-read-bps` and `--device-write-bps` flags to `docker run` [#14466](https://github.com/docker/docker/pull/14466) -+ Add `--device-read-iops` and `--device-write-iops` flags to `docker run` [#15879](https://github.com/docker/docker/pull/15879) -+ Add `--oom-score-adj` flag to `docker run` [#16277](https://github.com/docker/docker/pull/16277) -+ Add `--detach-keys` flag to `attach`, `run`, `start` and `exec` commands to override the default key sequence that detaches from a container [#15666](https://github.com/docker/docker/pull/15666) -+ Add `--shm-size` flag to `run`, `create` and `build` to set the size of `/dev/shm` [#16168](https://github.com/docker/docker/pull/16168) -+ Show the number of running, stopped, and paused containers in `docker info` [#19249](https://github.com/docker/docker/pull/19249) -+ Show the `OSType` and `Architecture` in `docker info` [#17478](https://github.com/docker/docker/pull/17478) -+ Add `--cgroup-parent` flag on `daemon` to set cgroup parent for all containers [#19062](https://github.com/docker/docker/pull/19062) -+ Add `-L` flag to docker cp to follow symlinks [#16613](https://github.com/docker/docker/pull/16613) -+ New `status=dead` filter for `docker ps` [#17908](https://github.com/docker/docker/pull/17908) -* Change `docker run` exit codes to distinguish between runtime and application errors [#14012](https://github.com/docker/docker/pull/14012) -* Enhance `docker events --since` and `--until` to support nanoseconds and timezones [#17495](https://github.com/docker/docker/pull/17495) -* Add `--all`/`-a` flag to `stats` to include both running and stopped containers [#16742](https://github.com/docker/docker/pull/16742) -* Change the default cgroup-driver to `cgroupfs` [#17704](https://github.com/docker/docker/pull/17704) -* Emit a "tag" event when tagging an image with `build -t` [#17115](https://github.com/docker/docker/pull/17115) -* Best effort for linked containers' start order when starting the daemon [#18208](https://github.com/docker/docker/pull/18208) -* Add ability to add multiple tags on `build` [#15780](https://github.com/docker/docker/pull/15780) -* Permit `OPTIONS` request against any url, thus fixing issue with CORS [#19569](https://github.com/docker/docker/pull/19569) -- Fix the `--quiet` flag on `docker build` to actually be quiet [#17428](https://github.com/docker/docker/pull/17428) -- Fix `docker images --filter dangling=false` to now show all non-dangling images [#19326](https://github.com/docker/docker/pull/19326) -- Fix race condition causing autorestart turning off on restart [#17629](https://github.com/docker/docker/pull/17629) -- Recognize GPFS filesystems [#19216](https://github.com/docker/docker/pull/19216) -- Fix obscure bug preventing to start containers [#19751](https://github.com/docker/docker/pull/19751) -- Forbid `exec` during container restart [#19722](https://github.com/docker/docker/pull/19722) -- devicemapper: Increasing `--storage-opt dm.basesize` will now increase the base device size on daemon restart [#19123](https://github.com/docker/docker/pull/19123) - -### Security - -+ Add `--userns-remap` flag to `daemon` to support user namespaces (previously in experimental) [#19187](https://github.com/docker/docker/pull/19187) -+ Add support for custom seccomp profiles in `--security-opt` [#17989](https://github.com/docker/docker/pull/17989) -+ Add default seccomp profile [#18780](https://github.com/docker/docker/pull/18780) -+ Add `--authorization-plugin` flag to `daemon` to customize ACLs [#15365](https://github.com/docker/docker/pull/15365) -+ Docker Content Trust now supports the ability to read and write user delegations [#18887](https://github.com/docker/docker/pull/18887) - This is an optional, opt-in feature that requires the explicit use of the Notary command-line utility in order to be enabled. - Enabling delegation support in a specific repository will break the ability of Docker 1.9 and 1.8 to pull from that repository, if content trust is enabled. -* Allow SELinux to run in a container when using the BTRFS storage driver [#16452](https://github.com/docker/docker/pull/16452) - -### Distribution - -* Use content-addressable storage for images and layers [#17924](https://github.com/docker/docker/pull/17924) - Note that a migration is performed the first time docker is run; it can take a significant amount of time depending on the number of images and containers present. - Images no longer depend on the parent chain but contain a list of layer references. - `docker load`/`docker save` tarballs now also contain content-addressable image configurations. - For more information: https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration -* Add support for the new [manifest format ("schema2")](https://github.com/docker/distribution/blob/master/docs/spec/manifest-v2-2.md) [#18785](https://github.com/docker/docker/pull/18785) -* Lots of improvements for push and pull: performance++, retries on failed downloads, cancelling on client disconnect [#18353](https://github.com/docker/docker/pull/18353), [#18418](https://github.com/docker/docker/pull/18418), [#19109](https://github.com/docker/docker/pull/19109), [#18353](https://github.com/docker/docker/pull/18353) -* Limit v1 protocol fallbacks [#18590](https://github.com/docker/docker/pull/18590) -- Fix issue where docker could hang indefinitely waiting for a nonexistent process to pull an image [#19743](https://github.com/docker/docker/pull/19743) - -### Networking - -+ Use DNS-based discovery instead of `/etc/hosts` [#19198](https://github.com/docker/docker/pull/19198) -+ Support for network-scoped alias using `--net-alias` on `run` and `--alias` on `network connect` [#19242](https://github.com/docker/docker/pull/19242) -+ Add `--ip` and `--ip6` on `run` and `network connect` to support custom IP addresses for a container in a network [#19001](https://github.com/docker/docker/pull/19001) -+ Add `--ipam-opt` to `network create` for passing custom IPAM options [#17316](https://github.com/docker/docker/pull/17316) -+ Add `--internal` flag to `network create` to restrict external access to and from the network [#19276](https://github.com/docker/docker/pull/19276) -+ Add `kv.path` option to `--cluster-store-opt` [#19167](https://github.com/docker/docker/pull/19167) -+ Add `discovery.heartbeat` and `discovery.ttl` options to `--cluster-store-opt` to configure discovery TTL and heartbeat timer [#18204](https://github.com/docker/docker/pull/18204) -+ Add `--format` flag to `network inspect` [#17481](https://github.com/docker/docker/pull/17481) -+ Add `--link` to `network connect` to provide a container-local alias [#19229](https://github.com/docker/docker/pull/19229) -+ Support for Capability exchange with remote IPAM plugins [#18775](https://github.com/docker/docker/pull/18775) -+ Add `--force` to `network disconnect` to force container to be disconnected from network [#19317](https://github.com/docker/docker/pull/19317) -* Support for multi-host networking using built-in overlay driver for all engine supported kernels: 3.10+ [#18775](https://github.com/docker/docker/pull/18775) -* `--link` is now supported on `docker run` for containers in user-defined network [#19229](https://github.com/docker/docker/pull/19229) -* Enhance `docker network rm` to allow removing multiple networks [#17489](https://github.com/docker/docker/pull/17489) -* Include container names in `network inspect` [#17615](https://github.com/docker/docker/pull/17615) -* Include auto-generated subnets for user-defined networks in `network inspect` [#17316](https://github.com/docker/docker/pull/17316) -* Add `--filter` flag to `network ls` to hide predefined networks [#17782](https://github.com/docker/docker/pull/17782) -* Add support for network connect/disconnect to stopped containers [#18906](https://github.com/docker/docker/pull/18906) -* Add network ID to container inspect [#19323](https://github.com/docker/docker/pull/19323) -- Fix MTU issue where Docker would not start with two or more default routes [#18108](https://github.com/docker/docker/pull/18108) -- Fix duplicate IP address for containers [#18106](https://github.com/docker/docker/pull/18106) -- Fix issue preventing sometimes docker from creating the bridge network [#19338](https://github.com/docker/docker/pull/19338) -- Do not substitute 127.0.0.1 name server when using `--net=host` [#19573](https://github.com/docker/docker/pull/19573) - -### Logging - -+ New logging driver for Splunk [#16488](https://github.com/docker/docker/pull/16488) -+ Add support for syslog over TCP+TLS [#18998](https://github.com/docker/docker/pull/18998) -* Enhance `docker logs --since` and `--until` to support nanoseconds and time [#17495](https://github.com/docker/docker/pull/17495) -* Enhance AWS logs to auto-detect region [#16640](https://github.com/docker/docker/pull/16640) - -### Volumes - -+ Add support to set the mount propagation mode for a volume [#17034](https://github.com/docker/docker/pull/17034) -* Add `ls` and `inspect` endpoints to volume plugin API [#16534](https://github.com/docker/docker/pull/16534) - Existing plugins need to make use of these new APIs to satisfy users' expectation - For that, please use the new MIME type `application/vnd.docker.plugins.v1.2+json` [#19549](https://github.com/docker/docker/pull/19549) -- Fix data not being copied to named volumes [#19175](https://github.com/docker/docker/pull/19175) -- Fix issues preventing volume drivers from being containerized [#19500](https://github.com/docker/docker/pull/19500) -- Fix `docker volumes ls --dangling=false` to now show all non-dangling volumes [#19671](https://github.com/docker/docker/pull/19671) -- Do not remove named volumes on container removal [#19568](https://github.com/docker/docker/pull/19568) -- Allow external volume drivers to host anonymous volumes [#19190](https://github.com/docker/docker/pull/19190) - -### Builder - -+ Add support for `**` in `.dockerignore` to wildcard multiple levels of directories [#17090](https://github.com/docker/docker/pull/17090) -- Fix handling of UTF-8 characters in Dockerfiles [#17055](https://github.com/docker/docker/pull/17055) -- Fix permissions problem when reading from STDIN [#19283](https://github.com/docker/docker/pull/19283) - -### Client - -+ Add support for overriding the API version to use via an `DOCKER_API_VERSION` environment-variable [#15964](https://github.com/docker/docker/pull/15964) -- Fix a bug preventing Windows clients to log in to Docker Hub [#19891](https://github.com/docker/docker/pull/19891) - -### Misc - -* systemd: Set TasksMax in addition to LimitNPROC in systemd service file [#19391](https://github.com/docker/docker/pull/19391) - -### Deprecations - -* Remove LXC support. The LXC driver was deprecated in Docker 1.8, and has now been removed [#17700](https://github.com/docker/docker/pull/17700) -* Remove `--exec-driver` daemon flag, because it is no longer in use [#17700](https://github.com/docker/docker/pull/17700) -* Remove old deprecated single-dashed long CLI flags (such as `-rm`; use `--rm` instead) [#17724](https://github.com/docker/docker/pull/17724) -* Deprecate HostConfig at API container start [#17799](https://github.com/docker/docker/pull/17799) -* Deprecate docker packages for newly EOL'd Linux distributions: Fedora 21 and Ubuntu 15.04 (Vivid) [#18794](https://github.com/docker/docker/pull/18794), [#18809](https://github.com/docker/docker/pull/18809) -* Deprecate `-f` flag for docker tag [#18350](https://github.com/docker/docker/pull/18350) - -## 1.9.1 (2015-11-21) - -### Runtime - -- Do not prevent daemon from booting if images could not be restored (#17695) -- Force IPC mount to unmount on daemon shutdown/init (#17539) -- Turn IPC unmount errors into warnings (#17554) -- Fix `docker stats` performance regression (#17638) -- Clarify cryptic error message upon `docker logs` if `--log-driver=none` (#17767) -- Fix seldom panics (#17639, #17634, #17703) -- Fix opq whiteouts problems for files with dot prefix (#17819) -- devicemapper: try defaulting to xfs instead of ext4 for performance reasons (#17903, #17918) -- devicemapper: fix displayed fs in docker info (#17974) -- selinux: only relabel if user requested so with the `z` option (#17450, #17834) -- Do not make network calls when normalizing names (#18014) - -### Client - -- Fix `docker login` on windows (#17738) -- Fix bug with `docker inspect` output when not connected to daemon (#17715) -- Fix `docker inspect -f {{.HostConfig.Dns}} somecontainer` (#17680) - -### Builder - -- Fix regression with symlink behavior in ADD/COPY (#17710) - -### Networking - -- Allow passing a network ID as an argument for `--net` (#17558) -- Fix connect to host and prevent disconnect from host for `host` network (#17476) -- Fix `--fixed-cidr` issue when gateway ip falls in ip-range and ip-range is - not the first block in the network (#17853) -- Restore deterministic `IPv6` generation from `MAC` address on default `bridge` network (#17890) -- Allow port-mapping only for endpoints created on docker run (#17858) -- Fixed an endpoint delete issue with a possible stale sbox (#18102) - -### Distribution - -- Correct parent chain in v2 push when v1Compatibility files on the disk are inconsistent (#18047) - -## 1.9.0 (2015-11-03) - -### Runtime - -+ `docker stats` now returns block IO metrics (#15005) -+ `docker stats` now details network stats per interface (#15786) -+ Add `ancestor=` filter to `docker ps --filter` flag to filter -containers based on their ancestor images (#14570) -+ Add `label=` filter to `docker ps --filter` to filter containers -based on label (#16530) -+ Add `--kernel-memory` flag to `docker run` (#14006) -+ Add `--message` flag to `docker import` allowing to specify an optional -message (#15711) -+ Add `--privileged` flag to `docker exec` (#14113) -+ Add `--stop-signal` flag to `docker run` allowing to replace the container -process stopping signal (#15307) -+ Add a new `unless-stopped` restart policy (#15348) -+ Inspecting an image now returns tags (#13185) -+ Add container size information to `docker inspect` (#15796) -+ Add `RepoTags` and `RepoDigests` field to `/images/{name:.*}/json` (#17275) -- Remove the deprecated `/container/ps` endpoint from the API (#15972) -- Send and document correct HTTP codes for `/exec//start` (#16250) -- Share shm and mqueue between containers sharing IPC namespace (#15862) -- Event stream now shows OOM status when `--oom-kill-disable` is set (#16235) -- Ensure special network files (/etc/hosts etc.) are read-only if bind-mounted -with `ro` option (#14965) -- Improve `rmi` performance (#16890) -- Do not update /etc/hosts for the default bridge network, except for links (#17325) -- Fix conflict with duplicate container names (#17389) -- Fix an issue with incorrect template execution in `docker inspect` (#17284) -- DEPRECATE `-c` short flag variant for `--cpu-shares` in docker run (#16271) - -### Client - -+ Allow `docker import` to import from local files (#11907) - -### Builder - -+ Add a `STOPSIGNAL` Dockerfile instruction allowing to set a different -stop-signal for the container process (#15307) -+ Add an `ARG` Dockerfile instruction and a `--build-arg` flag to `docker build` -that allows to add build-time environment variables (#15182) -- Improve cache miss performance (#16890) - -### Storage - -- devicemapper: Implement deferred deletion capability (#16381) - -## Networking - -+ `docker network` exits experimental and is part of standard release (#16645) -+ New network top-level concept, with associated subcommands and API (#16645) - WARNING: the API is different from the experimental API -+ Support for multiple isolated/micro-segmented networks (#16645) -+ Built-in multihost networking using VXLAN based overlay driver (#14071) -+ Support for third-party network plugins (#13424) -+ Ability to dynamically connect containers to multiple networks (#16645) -+ Support for user-defined IP address management via pluggable IPAM drivers (#16910) -+ Add daemon flags `--cluster-store` and `--cluster-advertise` for built-in nodes discovery (#16229) -+ Add `--cluster-store-opt` for setting up TLS settings (#16644) -+ Add `--dns-opt` to the daemon (#16031) -- DEPRECATE following container `NetworkSettings` fields in API v1.21: `EndpointID`, `Gateway`, - `GlobalIPv6Address`, `GlobalIPv6PrefixLen`, `IPAddress`, `IPPrefixLen`, `IPv6Gateway` and `MacAddress`. - Those are now specific to the `bridge` network. Use `NetworkSettings.Networks` to inspect - the networking settings of a container per network. - -### Volumes - -+ New top-level `volume` subcommand and API (#14242) -- Move API volume driver settings to host-specific config (#15798) -- Print an error message if volume name is not unique (#16009) -- Ensure volumes created from Dockerfiles always use the local volume driver -(#15507) -- DEPRECATE auto-creating missing host paths for bind mounts (#16349) - -### Logging - -+ Add `awslogs` logging driver for Amazon CloudWatch (#15495) -+ Add generic `tag` log option to allow customizing container/image -information passed to driver (e.g. show container names) (#15384) -- Implement the `docker logs` endpoint for the journald driver (#13707) -- DEPRECATE driver-specific log tags (e.g. `syslog-tag`, etc.) (#15384) - -### Distribution - -+ `docker search` now works with partial names (#16509) -- Push optimization: avoid buffering to file (#15493) -- The daemon will display progress for images that were already being pulled -by another client (#15489) -- Only permissions required for the current action being performed are requested (#) -+ Renaming trust keys (and respective environment variables) from `offline` to -`root` and `tagging` to `repository` (#16894) -- DEPRECATE trust key environment variables -`DOCKER_CONTENT_TRUST_OFFLINE_PASSPHRASE` and -`DOCKER_CONTENT_TRUST_TAGGING_PASSPHRASE` (#16894) - -### Security - -+ Add SELinux profiles to the rpm package (#15832) -- Fix various issues with AppArmor profiles provided in the deb package -(#14609) -- Add AppArmor policy that prevents writing to /proc (#15571) - -## 1.8.3 (2015-10-12) - -### Distribution - -- Fix layer IDs lead to local graph poisoning (CVE-2014-8178) -- Fix manifest validation and parsing logic errors allow pull-by-digest validation bypass (CVE-2014-8179) -+ Add `--disable-legacy-registry` to prevent a daemon from using a v1 registry - -## 1.8.2 (2015-09-10) - -### Distribution - -- Fixes rare edge case of handling GNU LongLink and LongName entries. -- Fix ^C on docker pull. -- Fix docker pull issues on client disconnection. -- Fix issue that caused the daemon to panic when loggers weren't configured properly. -- Fix goroutine leak pulling images from registry V2. - -### Runtime - -- Fix a bug mounting cgroups for docker daemons running inside docker containers. -- Initialize log configuration properly. - -### Client: - -- Handle `-q` flag in `docker ps` properly when there is a default format. - -### Networking - -- Fix several corner cases with netlink. - -### Contrib - -- Fix several issues with bash completion. - -## 1.8.1 (2015-08-12) - -### Distribution - -* Fix a bug where pushing multiple tags would result in invalid images - -## 1.8.0 (2015-08-11) - -### Distribution - -+ Trusted pull, push and build, disabled by default -* Make tar layers deterministic between registries -* Don't allow deleting the image of running containers -* Check if a tag name to load is a valid digest -* Allow one character repository names -* Add a more accurate error description for invalid tag name -* Make build cache ignore mtime - -### Cli - -+ Add support for DOCKER_CONFIG/--config to specify config file dir -+ Add --type flag for docker inspect command -+ Add formatting options to `docker ps` with `--format` -+ Replace `docker -d` with new subcommand `docker daemon` -* Zsh completion updates and improvements -* Add some missing events to bash completion -* Support daemon urls with base paths in `docker -H` -* Validate status= filter to docker ps -* Display when a container is in --net=host in docker ps -* Extend docker inspect to export image metadata related to graph driver -* Restore --default-gateway{,-v6} daemon options -* Add missing unpublished ports in docker ps -* Allow duration strings in `docker events` as --since/--until -* Expose more mounts information in `docker inspect` - -### Runtime - -+ Add new Fluentd logging driver -+ Allow `docker import` to load from local files -+ Add logging driver for GELF via UDP -+ Allow to copy files from host to containers with `docker cp` -+ Promote volume drivers from experimental to master -+ Add rollover options to json-file log driver, and --log-driver-opts flag -+ Add memory swappiness tuning options -* Remove cgroup read-only flag when privileged -* Make /proc, /sys, & /dev readonly for readonly containers -* Add cgroup bind mount by default -* Overlay: Export metadata for container and image in `docker inspect` -* Devicemapper: external device activation -* Devicemapper: Compare uuid of base device on startup -* Remove RC4 from the list of registry cipher suites -* Add syslog-facility option -* LXC execdriver compatibility with recent LXC versions -* Mark LXC execriver as deprecated (to be removed with the migration to runc) - -### Plugins - -* Separate plugin sockets and specs locations -* Allow TLS connections to plugins - -### Bug fixes - -- Add missing 'Names' field to /containers/json API output -- Make `docker rmi` of dangling images safe while pulling -- Devicemapper: Change default basesize to 100G -- Go Scheduler issue with sync.Mutex and gcc -- Fix issue where Search API endpoint would panic due to empty AuthConfig -- Set image canonical names correctly -- Check dockerinit only if lxc driver is used -- Fix ulimit usage of nproc -- Always attach STDIN if -i,--interactive is specified -- Show error messages when saving container state fails -- Fixed incorrect assumption on --bridge=none treated as disable network -- Check for invalid port specifications in host configuration -- Fix endpoint leave failure for --net=host mode -- Fix goroutine leak in the stats API if the container is not running -- Check for apparmor file before reading it -- Fix DOCKER_TLS_VERIFY being ignored -- Set umask to the default on startup -- Correct the message of pause and unpause a non-running container -- Adjust disallowed CpuShares in container creation -- ZFS: correctly apply selinux context -- Display empty string instead of when IP opt is nil -- `docker kill` returns error when container is not running -- Fix COPY/ADD quoted/json form -- Fix goroutine leak on logs -f with no output -- Remove panic in nat package on invalid hostport -- Fix container linking in Fedora 22 -- Fix error caused using default gateways outside of the allocated range -- Format times in inspect command with a template as RFC3339Nano -- Make registry client to accept 2xx and 3xx http status responses as successful -- Fix race issue that caused the daemon to crash with certain layer downloads failed in a specific order. -- Fix error when the docker ps format was not valid. -- Remove redundant ip forward check. -- Fix issue trying to push images to repository mirrors. -- Fix error cleaning up network entrypoints when there is an initialization issue. - -## 1.7.1 (2015-07-14) - -#### Runtime - -- Fix default user spawning exec process with `docker exec` -- Make `--bridge=none` not to configure the network bridge -- Publish networking stats properly -- Fix implicit devicemapper selection with static binaries -- Fix socket connections that hung intermittently -- Fix bridge interface creation on CentOS/RHEL 6.6 -- Fix local dns lookups added to resolv.conf -- Fix copy command mounting volumes -- Fix read/write privileges in volumes mounted with --volumes-from - -#### Remote API - -- Fix unmarshalling of Command and Entrypoint -- Set limit for minimum client version supported -- Validate port specification -- Return proper errors when attach/reattach fail - -#### Distribution - -- Fix pulling private images -- Fix fallback between registry V2 and V1 - -## 1.7.0 (2015-06-16) - -#### Runtime -+ Experimental feature: support for out-of-process volume plugins -* The userland proxy can be disabled in favor of hairpin NAT using the daemon’s `--userland-proxy=false` flag -* The `exec` command supports the `-u|--user` flag to specify the new process owner -+ Default gateway for containers can be specified daemon-wide using the `--default-gateway` and `--default-gateway-v6` flags -+ The CPU CFS (Completely Fair Scheduler) quota can be set in `docker run` using `--cpu-quota` -+ Container block IO can be controlled in `docker run` using`--blkio-weight` -+ ZFS support -+ The `docker logs` command supports a `--since` argument -+ UTS namespace can be shared with the host with `docker run --uts=host` - -#### Quality -* Networking stack was entirely rewritten as part of the libnetwork effort -* Engine internals refactoring -* Volumes code was entirely rewritten to support the plugins effort -+ Sending SIGUSR1 to a daemon will dump all goroutines stacks without exiting - -#### Build -+ Support ${variable:-value} and ${variable:+value} syntax for environment variables -+ Support resource management flags `--cgroup-parent`, `--cpu-period`, `--cpu-quota`, `--cpuset-cpus`, `--cpuset-mems` -+ git context changes with branches and directories -* The .dockerignore file support exclusion rules - -#### Distribution -+ Client support for v2 mirroring support for the official registry - -#### Bugfixes -* Firewalld is now supported and will automatically be used when available -* mounting --device recursively - -## 1.6.2 (2015-05-13) - -#### Runtime -- Revert change prohibiting mounting into /sys - -## 1.6.1 (2015-05-07) - -#### Security -- Fix read/write /proc paths (CVE-2015-3630) -- Prohibit VOLUME /proc and VOLUME / (CVE-2015-3631) -- Fix opening of file-descriptor 1 (CVE-2015-3627) -- Fix symlink traversal on container respawn allowing local privilege escalation (CVE-2015-3629) -- Prohibit mount of /sys - -#### Runtime -- Update AppArmor policy to not allow mounts - -## 1.6.0 (2015-04-07) - -#### Builder -+ Building images from an image ID -+ Build containers with resource constraints, ie `docker build --cpu-shares=100 --memory=1024m...` -+ `commit --change` to apply specified Dockerfile instructions while committing the image -+ `import --change` to apply specified Dockerfile instructions while importing the image -+ Builds no longer continue in the background when canceled with CTRL-C - -#### Client -+ Windows Support - -#### Runtime -+ Container and image Labels -+ `--cgroup-parent` for specifying a parent cgroup to place container cgroup within -+ Logging drivers, `json-file`, `syslog`, or `none` -+ Pulling images by ID -+ `--ulimit` to set the ulimit on a container -+ `--default-ulimit` option on the daemon which applies to all created containers (and overwritten by `--ulimit` on run) - -## 1.5.0 (2015-02-10) - -#### Builder -+ Dockerfile to use for a given `docker build` can be specified with the `-f` flag -* Dockerfile and .dockerignore files can be themselves excluded as part of the .dockerignore file, thus preventing modifications to these files invalidating ADD or COPY instructions cache -* ADD and COPY instructions accept relative paths -* Dockerfile `FROM scratch` instruction is now interpreted as a no-base specifier -* Improve performance when exposing a large number of ports - -#### Hack -+ Allow client-side only integration tests for Windows -* Include docker-py integration tests against Docker daemon as part of our test suites - -#### Packaging -+ Support for the new version of the registry HTTP API -* Speed up `docker push` for images with a majority of already existing layers -- Fixed contacting a private registry through a proxy - -#### Remote API -+ A new endpoint will stream live container resource metrics and can be accessed with the `docker stats` command -+ Containers can be renamed using the new `rename` endpoint and the associated `docker rename` command -* Container `inspect` endpoint show the ID of `exec` commands running in this container -* Container `inspect` endpoint show the number of times Docker auto-restarted the container -* New types of event can be streamed by the `events` endpoint: ‘OOM’ (container died with out of memory), ‘exec_create’, and ‘exec_start' -- Fixed returned string fields which hold numeric characters incorrectly omitting surrounding double quotes - -#### Runtime -+ Docker daemon has full IPv6 support -+ The `docker run` command can take the `--pid=host` flag to use the host PID namespace, which makes it possible for example to debug host processes using containerized debugging tools -+ The `docker run` command can take the `--read-only` flag to make the container’s root filesystem mounted as readonly, which can be used in combination with volumes to force a container’s processes to only write to locations that will be persisted -+ Container total memory usage can be limited for `docker run` using the `--memory-swap` flag -* Major stability improvements for devicemapper storage driver -* Better integration with host system: containers will reflect changes to the host's `/etc/resolv.conf` file when restarted -* Better integration with host system: per-container iptable rules are moved to the DOCKER chain -- Fixed container exiting on out of memory to return an invalid exit code - -#### Other -* The HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables are properly taken into account by the client when connecting to the Docker daemon - -## 1.4.1 (2014-12-15) - -#### Runtime -- Fix issue with volumes-from and bind mounts not being honored after create - -## 1.4.0 (2014-12-11) - -#### Notable Features since 1.3.0 -+ Set key=value labels to the daemon (displayed in `docker info`), applied with - new `-label` daemon flag -+ Add support for `ENV` in Dockerfile of the form: - `ENV name=value name2=value2...` -+ New Overlayfs Storage Driver -+ `docker info` now returns an `ID` and `Name` field -+ Filter events by event name, container, or image -+ `docker cp` now supports copying from container volumes -- Fixed `docker tag`, so it honors `--force` when overriding a tag for existing - image. - -## 1.3.3 (2014-12-11) - -#### Security -- Fix path traversal vulnerability in processing of absolute symbolic links (CVE-2014-9356) -- Fix decompression of xz image archives, preventing privilege escalation (CVE-2014-9357) -- Validate image IDs (CVE-2014-9358) - -#### Runtime -- Fix an issue when image archives are being read slowly - -#### Client -- Fix a regression related to stdin redirection -- Fix a regression with `docker cp` when destination is the current directory - -## 1.3.2 (2014-11-20) - -#### Security -- Fix tar breakout vulnerability -* Extractions are now sandboxed chroot -- Security options are no longer committed to images - -#### Runtime -- Fix deadlock in `docker ps -f exited=1` -- Fix a bug when `--volumes-from` references a container that failed to start - -#### Registry -+ `--insecure-registry` now accepts CIDR notation such as 10.1.0.0/16 -* Private registries whose IPs fall in the 127.0.0.0/8 range do no need the `--insecure-registry` flag -- Skip the experimental registry v2 API when mirroring is enabled - -## 1.3.1 (2014-10-28) - -#### Security -* Prevent fallback to SSL protocols < TLS 1.0 for client, daemon and registry -+ Secure HTTPS connection to registries with certificate verification and without HTTP fallback unless `--insecure-registry` is specified - -#### Runtime -- Fix issue where volumes would not be shared - -#### Client -- Fix issue with `--iptables=false` not automatically setting `--ip-masq=false` -- Fix docker run output to non-TTY stdout - -#### Builder -- Fix escaping `$` for environment variables -- Fix issue with lowercase `onbuild` Dockerfile instruction -- Restrict environment variable expansion to `ENV`, `ADD`, `COPY`, `WORKDIR`, `EXPOSE`, `VOLUME` and `USER` - -## 1.3.0 (2014-10-14) - -#### Notable features since 1.2.0 -+ Docker `exec` allows you to run additional processes inside existing containers -+ Docker `create` gives you the ability to create a container via the CLI without executing a process -+ `--security-opts` options to allow user to customize container labels and apparmor profiles -+ Docker `ps` filters -- Wildcard support to COPY/ADD -+ Move production URLs to get.docker.com from get.docker.io -+ Allocate IP address on the bridge inside a valid CIDR -+ Use drone.io for PR and CI testing -+ Ability to setup an official registry mirror -+ Ability to save multiple images with docker `save` - -## 1.2.0 (2014-08-20) - -#### Runtime -+ Make /etc/hosts /etc/resolv.conf and /etc/hostname editable at runtime -+ Auto-restart containers using policies -+ Use /var/lib/docker/tmp for large temporary files -+ `--cap-add` and `--cap-drop` to tweak what linux capability you want -+ `--device` to use devices in containers - -#### Client -+ `docker search` on private registries -+ Add `exited` filter to `docker ps --filter` -* `docker rm -f` now kills instead of stop -+ Support for IPv6 addresses in `--dns` flag - -#### Proxy -+ Proxy instances in separate processes -* Small bug fix on UDP proxy - -## 1.1.2 (2014-07-23) - -#### Runtime -+ Fix port allocation for existing containers -+ Fix containers restart on daemon restart - -#### Packaging -+ Fix /etc/init.d/docker issue on Debian - -## 1.1.1 (2014-07-09) - -#### Builder -* Fix issue with ADD - -## 1.1.0 (2014-07-03) - -#### Notable features since 1.0.1 -+ Add `.dockerignore` support -+ Pause containers during `docker commit` -+ Add `--tail` to `docker logs` - -#### Builder -+ Allow a tar file as context for `docker build` -* Fix issue with white-spaces and multi-lines in `Dockerfiles` - -#### Runtime -* Overall performance improvements -* Allow `/` as source of `docker run -v` -* Fix port allocation -* Fix bug in `docker save` -* Add links information to `docker inspect` - -#### Client -* Improve command line parsing for `docker commit` - -#### Remote API -* Improve status code for the `start` and `stop` endpoints - -## 1.0.1 (2014-06-19) - -#### Notable features since 1.0.0 -* Enhance security for the LXC driver - -#### Builder -* Fix `ONBUILD` instruction passed to grandchildren - -#### Runtime -* Fix events subscription -* Fix /etc/hostname file with host networking -* Allow `-h` and `--net=none` -* Fix issue with hotplug devices in `--privileged` - -#### Client -* Fix artifacts with events -* Fix a panic with empty flags -* Fix `docker cp` on Mac OS X - -#### Miscellaneous -* Fix compilation on Mac OS X -* Fix several races - -## 1.0.0 (2014-06-09) - -#### Notable features since 0.12.0 -* Production support - -## 0.12.0 (2014-06-05) - -#### Notable features since 0.11.0 -* 40+ various improvements to stability, performance and usability -* New `COPY` Dockerfile instruction to allow copying a local file from the context into the container without ever extracting if the file is a tar file -* Inherit file permissions from the host on `ADD` -* New `pause` and `unpause` commands to allow pausing and unpausing of containers using cgroup freezer -* The `images` command has a `-f`/`--filter` option to filter the list of images -* Add `--force-rm` to clean up after a failed build -* Standardize JSON keys in Remote API to CamelCase -* Pull from a docker run now assumes `latest` tag if not specified -* Enhance security on Linux capabilities and device nodes - -## 0.11.1 (2014-05-07) - -#### Registry -- Fix push and pull to private registry - -## 0.11.0 (2014-05-07) - -#### Notable features since 0.10.0 - -* SELinux support for mount and process labels -* Linked containers can be accessed by hostname -* Use the net `--net` flag to allow advanced network configuration such as host networking so that containers can use the host's network interfaces -* Add a ping endpoint to the Remote API to do healthchecks of your docker daemon -* Logs can now be returned with an optional timestamp -* Docker now works with registries that support SHA-512 -* Multiple registry endpoints are supported to allow registry mirrors - -## 0.10.0 (2014-04-08) - -#### Builder -- Fix printing multiple messages on a single line. Fixes broken output during builds. -- Follow symlinks inside container's root for ADD build instructions. -- Fix EXPOSE caching. - -#### Documentation -- Add the new options of `docker ps` to the documentation. -- Add the options of `docker restart` to the documentation. -- Update daemon docs and help messages for --iptables and --ip-forward. -- Updated apt-cacher-ng docs example. -- Remove duplicate description of --mtu from docs. -- Add missing -t and -v for `docker images` to the docs. -- Add fixes to the cli docs. -- Update libcontainer docs. -- Update images in docs to remove references to AUFS and LXC. -- Update the nodejs_web_app in the docs to use the new epel RPM address. -- Fix external link on security of containers. -- Update remote API docs. -- Add image size to history docs. -- Be explicit about binding to all interfaces in redis example. -- Document DisableNetwork flag in the 1.10 remote api. -- Document that `--lxc-conf` is lxc only. -- Add chef usage documentation. -- Add example for an image with multiple for `docker load`. -- Explain what `docker run -a` does in the docs. - -#### Contrib -- Add variable for DOCKER_LOGFILE to sysvinit and use append instead of overwrite in opening the logfile. -- Fix init script cgroup mounting workarounds to be more similar to cgroupfs-mount and thus work properly. -- Remove inotifywait hack from the upstart host-integration example because it's not necessary any more. -- Add check-config script to contrib. -- Fix fish shell completion. - -#### Hack -* Clean up "go test" output from "make test" to be much more readable/scannable. -* Exclude more "definitely not unit tested Go source code" directories from hack/make/test. -+ Generate md5 and sha256 hashes when building, and upload them via hack/release.sh. -- Include contributed completions in Ubuntu PPA. -+ Add cli integration tests. -* Add tweaks to the hack scripts to make them simpler. - -#### Remote API -+ Add TLS auth support for API. -* Move git clone from daemon to client. -- Fix content-type detection in docker cp. -* Split API into 2 go packages. - -#### Runtime -* Support hairpin NAT without going through Docker server. -- devicemapper: succeed immediately when removing non-existent devices. -- devicemapper: improve handling of devicemapper devices (add per device lock, increase sleep time and unlock while sleeping). -- devicemapper: increase timeout in waitClose to 10 seconds. -- devicemapper: ensure we shut down thin pool cleanly. -- devicemapper: pass info, rather than hash to activateDeviceIfNeeded, deactivateDevice, setInitialized, deleteDevice. -- devicemapper: avoid AB-BA deadlock. -- devicemapper: make shutdown better/faster. -- improve alpha sorting in mflag. -- Remove manual http cookie management because the cookiejar is being used. -- Use BSD raw mode on Darwin. Fixes nano, tmux and others. -- Add FreeBSD support for the client. -- Merge auth package into registry. -- Add deprecation warning for -t on `docker pull`. -- Remove goroutine leak on error. -- Update parseLxcInfo to comply with new lxc1.0 format. -- Fix attach exit on darwin. -- Improve deprecation message. -- Retry to retrieve the layer metadata up to 5 times for `docker pull`. -- Only unshare the mount namespace for execin. -- Merge existing config when committing. -- Disable daemon startup timeout. -- Fix issue #4681: add loopback interface when networking is disabled. -- Add failing test case for issue #4681. -- Send SIGTERM to child, instead of SIGKILL. -- Show the driver and the kernel version in `docker info` even when not in debug mode. -- Always symlink /dev/ptmx for libcontainer. This fixes console related problems. -- Fix issue caused by the absence of /etc/apparmor.d. -- Don't leave empty cidFile behind when failing to create the container. -- Mount cgroups automatically if they're not mounted already. -- Use mock for search tests. -- Update to double-dash everywhere. -- Move .dockerenv parsing to lxc driver. -- Move all bind-mounts in the container inside the namespace. -- Don't use separate bind mount for container. -- Always symlink /dev/ptmx for libcontainer. -- Don't kill by pid for other drivers. -- Add initial logging to libcontainer. -* Sort by port in `docker ps`. -- Move networking drivers into runtime top level package. -+ Add --no-prune to `docker rmi`. -+ Add time since exit in `docker ps`. -- graphdriver: add build tags. -- Prevent allocation of previously allocated ports & prevent improve port allocation. -* Add support for --since/--before in `docker ps`. -- Clean up container stop. -+ Add support for configurable dns search domains. -- Add support for relative WORKDIR instructions. -- Add --output flag for docker save. -- Remove duplication of DNS entries in config merging. -- Add cpuset.cpus to cgroups and native driver options. -- Remove docker-ci. -- Promote btrfs. btrfs is no longer considered experimental. -- Add --input flag to `docker load`. -- Return error when existing bridge doesn't match IP address. -- Strip comments before parsing line continuations to avoid interpreting instructions as comments. -- Fix TestOnlyLoopbackExistsWhenUsingDisableNetworkOption to ignore "DOWN" interfaces. -- Add systemd implementation of cgroups and make containers show up as systemd units. -- Fix commit and import when no repository is specified. -- Remount /var/lib/docker as --private to fix scaling issue. -- Use the environment's proxy when pinging the remote registry. -- Reduce error level from harmless errors. -* Allow --volumes-from to be individual files. -- Fix expanding buffer in StdCopy. -- Set error regardless of attach or stdin. This fixes #3364. -- Add support for --env-file to load environment variables from files. -- Symlink /etc/mtab and /proc/mounts. -- Allow pushing a single tag. -- Shut down containers cleanly at shutdown and wait forever for the containers to shut down. This makes container shutdown on daemon shutdown work properly via SIGTERM. -- Don't throw error when starting an already running container. -- Fix dynamic port allocation limit. -- remove setupDev from libcontainer. -- Add API version to `docker version`. -- Return correct exit code when receiving signal and make SIGQUIT quit without cleanup. -- Fix --volumes-from mount failure. -- Allow non-privileged containers to create device nodes. -- Skip login tests because of external dependency on a hosted service. -- Deprecate `docker images --tree` and `docker images --viz`. -- Deprecate `docker insert`. -- Include base abstraction for apparmor. This fixes some apparmor related problems on Ubuntu 14.04. -- Add specific error message when hitting 401 over HTTP on push. -- Fix absolute volume check. -- Remove volumes-from from the config. -- Move DNS options to hostconfig. -- Update the apparmor profile for libcontainer. -- Add deprecation notice for `docker commit -run`. - -## 0.9.1 (2014-03-24) - -#### Builder -- Fix printing multiple messages on a single line. Fixes broken output during builds. - -#### Documentation -- Fix external link on security of containers. - -#### Contrib -- Fix init script cgroup mounting workarounds to be more similar to cgroupfs-mount and thus work properly. -- Add variable for DOCKER_LOGFILE to sysvinit and use append instead of overwrite in opening the logfile. - -#### Hack -- Generate md5 and sha256 hashes when building, and upload them via hack/release.sh. - -#### Remote API -- Fix content-type detection in `docker cp`. - -#### Runtime -- Use BSD raw mode on Darwin. Fixes nano, tmux and others. -- Only unshare the mount namespace for execin. -- Retry to retrieve the layer metadata up to 5 times for `docker pull`. -- Merge existing config when committing. -- Fix panic in monitor. -- Disable daemon startup timeout. -- Fix issue #4681: add loopback interface when networking is disabled. -- Add failing test case for issue #4681. -- Send SIGTERM to child, instead of SIGKILL. -- Show the driver and the kernel version in `docker info` even when not in debug mode. -- Always symlink /dev/ptmx for libcontainer. This fixes console related problems. -- Fix issue caused by the absence of /etc/apparmor.d. -- Don't leave empty cidFile behind when failing to create the container. -- Improve deprecation message. -- Fix attach exit on darwin. -- devicemapper: improve handling of devicemapper devices (add per device lock, increase sleep time, unlock while sleeping). -- devicemapper: succeed immediately when removing non-existent devices. -- devicemapper: increase timeout in waitClose to 10 seconds. -- Remove goroutine leak on error. -- Update parseLxcInfo to comply with new lxc1.0 format. - -## 0.9.0 (2014-03-10) - -#### Builder -- Avoid extra mount/unmount during build. This fixes mount/unmount related errors during build. -- Add error to docker build --rm. This adds missing error handling. -- Forbid chained onbuild, `onbuild from` and `onbuild maintainer` triggers. -- Make `--rm` the default for `docker build`. - -#### Documentation -- Download the docker client binary for Mac over https. -- Update the titles of the install instructions & descriptions. -* Add instructions for upgrading boot2docker. -* Add port forwarding example in OS X install docs. -- Attempt to disentangle repository and registry. -- Update docs to explain more about `docker ps`. -- Update sshd example to use a Dockerfile. -- Rework some examples, including the Python examples. -- Update docs to include instructions for a container's lifecycle. -- Update docs documentation to discuss the docs branch. -- Don't skip cert check for an example & use HTTPS. -- Bring back the memory and swap accounting section which was lost when the kernel page was removed. -- Explain DNS warnings and how to fix them on systems running and using a local nameserver. - -#### Contrib -- Add Tanglu support for mkimage-debootstrap. -- Add SteamOS support for mkimage-debootstrap. - -#### Hack -- Get package coverage when running integration tests. -- Remove the Vagrantfile. This is being replaced with boot2docker. -- Fix tests on systems where aufs isn't available. -- Update packaging instructions and remove the dependency on lxc. - -#### Remote API -* Move code specific to the API to the api package. -- Fix header content type for the API. Makes all endpoints use proper content type. -- Fix registry auth & remove ping calls from CmdPush and CmdPull. -- Add newlines to the JSON stream functions. - -#### Runtime -* Do not ping the registry from the CLI. All requests to registries flow through the daemon. -- Check for nil information return in the lxc driver. This fixes panics with older lxc versions. -- Devicemapper: cleanups and fix for unmount. Fixes two problems which were causing unmount to fail intermittently. -- Devicemapper: remove directory when removing device. Directories don't get left behind when removing the device. -* Devicemapper: enable skip_block_zeroing. Improves performance by not zeroing blocks. -- Devicemapper: fix shutdown warnings. Fixes shutdown warnings concerning pool device removal. -- Ensure docker cp stream is closed properly. Fixes problems with files not being copied by `docker cp`. -- Stop making `tcp://` default to `127.0.0.1:4243` and remove the default port for tcp. -- Fix `--run` in `docker commit`. This makes `docker commit --run` work again. -- Fix custom bridge related options. This makes custom bridges work again. -+ Mount-bind the PTY as container console. This allows tmux/screen to run. -+ Add the pure Go libcontainer library to make it possible to run containers using only features of the Linux kernel. -+ Add native exec driver which uses libcontainer and make it the default exec driver. -- Add support for handling extended attributes in archives. -* Set the container MTU to be the same as the host MTU. -+ Add simple sha256 checksums for layers to speed up `docker push`. -* Improve kernel version parsing. -* Allow flag grouping (`docker run -it`). -- Remove chroot exec driver. -- Fix divide by zero to fix panic. -- Rewrite `docker rmi`. -- Fix docker info with lxc 1.0.0. -- Fix fedora tty with apparmor. -* Don't always append env vars, replace defaults with vars from config. -* Fix a goroutine leak. -* Switch to Go 1.2.1. -- Fix unique constraint error checks. -* Handle symlinks for Docker's data directory and for TMPDIR. -- Add deprecation warnings for flags (-flag is deprecated in favor of --flag) -- Add apparmor profile for the native execution driver. -* Move system specific code from archive to pkg/system. -- Fix duplicate signal for `docker run -i -t` (issue #3336). -- Return correct process pid for lxc. -- Add a -G option to specify the group which unix sockets belong to. -+ Add `-f` flag to `docker rm` to force removal of running containers. -+ Kill ghost containers and restart all ghost containers when the docker daemon restarts. -+ Add `DOCKER_RAMDISK` environment variable to make Docker work when the root is on a ramdisk. - -## 0.8.1 (2014-02-18) - -#### Builder - -- Avoid extra mount/unmount during build. This removes an unneeded mount/unmount operation which was causing problems with devicemapper -- Fix regression with ADD of tar files. This stops Docker from decompressing tarballs added via ADD from the local file system -- Add error to `docker build --rm`. This adds a missing error check to ensure failures to remove containers are detected and reported - -#### Documentation - -* Update issue filing instructions -* Warn against the use of symlinks for Docker's storage folder -* Replace the Firefox example with an IceWeasel example -* Rewrite the PostgreSQL example using a Dockerfile and add more details to it -* Improve the OS X documentation - -#### Remote API - -- Fix broken images API for version less than 1.7 -- Use the right encoding for all API endpoints which return JSON -- Move remote api client to api/ -- Queue calls to the API using generic socket wait - -#### Runtime - -- Fix the use of custom settings for bridges and custom bridges -- Refactor the devicemapper code to avoid many mount/unmount race conditions and failures -- Remove two panics which could make Docker crash in some situations -- Don't ping registry from the CLI client -- Enable skip_block_zeroing for devicemapper. This stops devicemapper from always zeroing entire blocks -- Fix --run in `docker commit`. This makes docker commit store `--run` in the image configuration -- Remove directory when removing devicemapper device. This cleans up leftover mount directories -- Drop NET_ADMIN capability for non-privileged containers. Unprivileged containers can't change their network configuration -- Ensure `docker cp` stream is closed properly -- Avoid extra mount/unmount during container registration. This removes an unneeded mount/unmount operation which was causing problems with devicemapper -- Stop allowing tcp:// as a default tcp bin address which binds to 127.0.0.1:4243 and remove the default port -+ Mount-bind the PTY as container console. This allows tmux and screen to run in a container -- Clean up archive closing. This fixes and improves archive handling -- Fix engine tests on systems where temp directories are symlinked -- Add test methods for save and load -- Avoid temporarily unmounting the container when restarting it. This fixes a race for devicemapper during restart -- Support submodules when building from a GitHub repository -- Quote volume path to allow spaces -- Fix remote tar ADD behavior. This fixes a regression which was causing Docker to extract tarballs - -## 0.8.0 (2014-02-04) - -#### Notable features since 0.7.0 - -* Images and containers can be removed much faster -* Building an image from source with docker build is now much faster -* The Docker daemon starts and stops much faster -* The memory footprint of many common operations has been reduced, by streaming files instead of buffering them in memory, fixing memory leaks, and fixing various suboptimal memory allocations -* Several race conditions were fixed, making Docker more stable under very high concurrency load. This makes Docker more stable and less likely to crash and reduces the memory footprint of many common operations -* All packaging operations are now built on the Go language’s standard tar implementation, which is bundled with Docker itself. This makes packaging more portable across host distributions, and solves several issues caused by quirks and incompatibilities between different distributions of tar -* Docker can now create, remove and modify larger numbers of containers and images graciously thanks to more aggressive releasing of system resources. For example the storage driver API now allows Docker to do reference counting on mounts created by the drivers -With the ongoing changes to the networking and execution subsystems of docker testing these areas have been a focus of the refactoring. By moving these subsystems into separate packages we can test, analyze, and monitor coverage and quality of these packages -* Many components have been separated into smaller sub-packages, each with a dedicated test suite. As a result the code is better-tested, more readable and easier to change - -* The ADD instruction now supports caching, which avoids unnecessarily re-uploading the same source content again and again when it hasn’t changed -* The new ONBUILD instruction adds to your image a “trigger” instruction to be executed at a later time, when the image is used as the base for another build -* Docker now ships with an experimental storage driver which uses the BTRFS filesystem for copy-on-write -* Docker is officially supported on Mac OS X -* The Docker daemon supports systemd socket activation - -## 0.7.6 (2014-01-14) - -#### Builder - -* Do not follow symlink outside of build context - -#### Runtime - -- Remount bind mounts when ro is specified -* Use https for fetching docker version - -#### Other - -* Inline the test.docker.io fingerprint -* Add ca-certificates to packaging documentation - -## 0.7.5 (2014-01-09) - -#### Builder - -* Disable compression for build. More space usage but a much faster upload -- Fix ADD caching for certain paths -- Do not compress archive from git build - -#### Documentation - -- Fix error in GROUP add example -* Make sure the GPG fingerprint is inline in the documentation -* Give more specific advice on setting up signing of commits for DCO - -#### Runtime - -- Fix misspelled container names -- Do not add hostname when networking is disabled -* Return most recent image from the cache by date -- Return all errors from docker wait -* Add Content-Type Header "application/json" to GET /version and /info responses - -#### Other - -* Update DCO to version 1.1 -+ Update Makefile to use "docker:GIT_BRANCH" as the generated image name -* Update Travis to check for new 1.1 DCO version - -## 0.7.4 (2014-01-07) - -#### Builder - -- Fix ADD caching issue with . prefixed path -- Fix docker build on devicemapper by reverting sparse file tar option -- Fix issue with file caching and prevent wrong cache hit -* Use same error handling while unmarshalling CMD and ENTRYPOINT - -#### Documentation - -* Simplify and streamline Amazon Quickstart -* Install instructions use unprefixed Fedora image -* Update instructions for mtu flag for Docker on GCE -+ Add Ubuntu Saucy to installation -- Fix for wrong version warning on master instead of latest - -#### Runtime - -- Only get the image's rootfs when we need to calculate the image size -- Correctly handle unmapping UDP ports -* Make CopyFileWithTar use a pipe instead of a buffer to save memory on docker build -- Fix login message to say pull instead of push -- Fix "docker load" help by removing "SOURCE" prompt and mentioning STDIN -* Make blank -H option default to the same as no -H was sent -* Extract cgroups utilities to own submodule - -#### Other - -+ Add Travis CI configuration to validate DCO and gofmt requirements -+ Add Developer Certificate of Origin Text -* Upgrade VBox Guest Additions -* Check standalone header when pinging a registry server - -## 0.7.3 (2014-01-02) - -#### Builder - -+ Update ADD to use the image cache, based on a hash of the added content -* Add error message for empty Dockerfile - -#### Documentation - -- Fix outdated link to the "Introduction" on www.docker.io -+ Update the docs to get wider when the screen does -- Add information about needing to install LXC when using raw binaries -* Update Fedora documentation to disentangle the docker and docker.io conflict -* Add a note about using the new `-mtu` flag in several GCE zones -+ Add FrugalWare installation instructions -+ Add a more complete example of `docker run` -- Fix API documentation for creating and starting Privileged containers -- Add missing "name" parameter documentation on "/containers/create" -* Add a mention of `lxc-checkconfig` as a way to check for some of the necessary kernel configuration -- Update the 1.8 API documentation with some additions that were added to the docs for 1.7 - -#### Hack - -- Add missing libdevmapper dependency to the packagers documentation -* Update minimum Go requirement to a hard line at Go 1.2+ -* Many minor improvements to the Vagrantfile -+ Add ability to customize dockerinit search locations when compiling (to be used very sparingly only by packagers of platforms who require a nonstandard location) -+ Add coverprofile generation reporting -- Add `-a` to our Go build flags, removing the need for recompiling the stdlib manually -* Update Dockerfile to be more canonical and have less spurious warnings during build -- Fix some miscellaneous `docker pull` progress bar display issues -* Migrate more miscellaneous packages under the "pkg" folder -* Update TextMate highlighting to automatically be enabled for files named "Dockerfile" -* Reorganize syntax highlighting files under a common "contrib/syntax" directory -* Update install.sh script (https://get.docker.io/) to not fail if busybox fails to download or run at the end of the Ubuntu/Debian installation -* Add support for container names in bash completion - -#### Packaging - -+ Add an official Docker client binary for Darwin (Mac OS X) -* Remove empty "Vendor" string and added "License" on deb package -+ Add a stubbed version of "/etc/default/docker" in the deb package - -#### Runtime - -* Update layer application to extract tars in place, avoiding file churn while handling whiteouts -- Fix permissiveness of mtime comparisons in tar handling (since GNU tar and Go tar do not yet support sub-second mtime precision) -* Reimplement `docker top` in pure Go to work more consistently, and even inside Docker-in-Docker (thus removing the shell injection vulnerability present in some versions of `lxc-ps`) -+ Update `-H unix://` to work similarly to `-H tcp://` by inserting the default values for missing portions -- Fix more edge cases regarding dockerinit and deleted or replaced docker or dockerinit files -* Update container name validation to include '.' -- Fix use of a symlink or non-absolute path as the argument to `-g` to work as expected -* Update to handle external mounts outside of LXC, fixing many small mounting quirks and making future execution backends and other features simpler -* Update to use proper box-drawing characters everywhere in `docker images -tree` -* Move MTU setting from LXC configuration to directly use netlink -* Add `-S` option to external tar invocation for more efficient spare file handling -+ Add arch/os info to User-Agent string, especially for registry requests -+ Add `-mtu` option to Docker daemon for configuring MTU -- Fix `docker build` to exit with a non-zero exit code on error -+ Add `DOCKER_HOST` environment variable to configure the client `-H` flag without specifying it manually for every invocation - -## 0.7.2 (2013-12-16) - -#### Runtime - -+ Validate container names on creation with standard regex -* Increase maximum image depth to 127 from 42 -* Continue to move api endpoints to the job api -+ Add -bip flag to allow specification of dynamic bridge IP via CIDR -- Allow bridge creation when ipv6 is not enabled on certain systems -* Set hostname and IP address from within dockerinit -* Drop capabilities from within dockerinit -- Fix volumes on host when symlink is present the image -- Prevent deletion of image if ANY container is depending on it even if the container is not running -* Update docker push to use new progress display -* Use os.Lstat to allow mounting unix sockets when inspecting volumes -- Adjust handling of inactive user login -- Add missing defines in devicemapper for older kernels -- Allow untag operations with no container validation -- Add auth config to docker build - -#### Documentation - -* Add more information about Docker logging -+ Add RHEL documentation -* Add a direct example for changing the CMD that is run in a container -* Update Arch installation documentation -+ Add section on Trusted Builds -+ Add Network documentation page - -#### Other - -+ Add new cover bundle for providing code coverage reporting -* Separate integration tests in bundles -* Make Tianon the hack maintainer -* Update mkimage-debootstrap with more tweaks for keeping images small -* Use https to get the install script -* Remove vendored dotcloud/tar now that Go 1.2 has been released - -## 0.7.1 (2013-12-05) - -#### Documentation - -+ Add @SvenDowideit as documentation maintainer -+ Add links example -+ Add documentation regarding ambassador pattern -+ Add Google Cloud Platform docs -+ Add dockerfile best practices -* Update doc for RHEL -* Update doc for registry -* Update Postgres examples -* Update doc for Ubuntu install -* Improve remote api doc - -#### Runtime - -+ Add hostconfig to docker inspect -+ Implement `docker log -f` to stream logs -+ Add env variable to disable kernel version warning -+ Add -format to `docker inspect` -+ Support bind-mount for files -- Fix bridge creation on RHEL -- Fix image size calculation -- Make sure iptables are called even if the bridge already exists -- Fix issue with stderr only attach -- Remove init layer when destroying a container -- Fix same port binding on different interfaces -- `docker build` now returns the correct exit code -- Fix `docker port` to display correct port -- `docker build` now check that the dockerfile exists client side -- `docker attach` now returns the correct exit code -- Remove the name entry when the container does not exist - -#### Registry - -* Improve progress bars, add ETA for downloads -* Simultaneous pulls now waits for the first to finish instead of failing -- Tag only the top-layer image when pushing to registry -- Fix issue with offline image transfer -- Fix issue preventing using ':' in password for registry - -#### Other - -+ Add pprof handler for debug -+ Create a Makefile -* Use stdlib tar that now includes fix -* Improve make.sh test script -* Handle SIGQUIT on the daemon -* Disable verbose during tests -* Upgrade to go1.2 for official build -* Improve unit tests -* The test suite now runs all tests even if one fails -* Refactor C in Go (Devmapper) -- Fix OS X compilation - -## 0.7.0 (2013-11-25) - -#### Notable features since 0.6.0 - -* Storage drivers: choose from aufs, device-mapper, or vfs. -* Standard Linux support: docker now runs on unmodified Linux kernels and all major distributions. -* Links: compose complex software stacks by connecting containers to each other. -* Container naming: organize your containers by giving them memorable names. -* Advanced port redirects: specify port redirects per interface, or keep sensitive ports private. -* Offline transfer: push and pull images to the filesystem without losing information. -* Quality: numerous bugfixes and small usability improvements. Significant increase in test coverage. - -## 0.6.7 (2013-11-21) - -#### Runtime - -* Improve stability, fixes some race conditions -* Skip the volumes mounted when deleting the volumes of container. -* Fix layer size computation: handle hard links correctly -* Use the work Path for docker cp CONTAINER:PATH -* Fix tmp dir never cleanup -* Speedup docker ps -* More informative error message on name collisions -* Fix nameserver regex -* Always return long id's -* Fix container restart race condition -* Keep published ports on docker stop;docker start -* Fix container networking on Fedora -* Correctly express "any address" to iptables -* Fix network setup when reconnecting to ghost container -* Prevent deletion if image is used by a running container -* Lock around read operations in graph - -#### RemoteAPI - -* Return full ID on docker rmi - -#### Client - -+ Add -tree option to images -+ Offline image transfer -* Exit with status 2 on usage error and display usage on stderr -* Do not forward SIGCHLD to container -* Use string timestamp for docker events -since - -#### Other - -* Update to go 1.2rc5 -+ Add /etc/default/docker support to upstart - -## 0.6.6 (2013-11-06) - -#### Runtime - -* Ensure container name on register -* Fix regression in /etc/hosts -+ Add lock around write operations in graph -* Check if port is valid -* Fix restart runtime error with ghost container networking -+ Add some more colors and animals to increase the pool of generated names -* Fix issues in docker inspect -+ Escape apparmor confinement -+ Set environment variables using a file. -* Prevent docker insert to erase something -+ Prevent DNS server conflicts in CreateBridgeIface -+ Validate bind mounts on the server side -+ Use parent image config in docker build -* Fix regression in /etc/hosts - -#### Client - -+ Add -P flag to publish all exposed ports -+ Add -notrunc and -q flags to docker history -* Fix docker commit, tag and import usage -+ Add stars, trusted builds and library flags in docker search -* Fix docker logs with tty - -#### RemoteAPI - -* Make /events API send headers immediately -* Do not split last column docker top -+ Add size to history - -#### Other - -+ Contrib: Desktop integration. Firefox usecase. -+ Dockerfile: bump to go1.2rc3 - -## 0.6.5 (2013-10-29) - -#### Runtime - -+ Containers can now be named -+ Containers can now be linked together for service discovery -+ 'run -a', 'start -a' and 'attach' can forward signals to the container for better integration with process supervisors -+ Automatically start crashed containers after a reboot -+ Expose IP, port, and proto as separate environment vars for container links -* Allow ports to be published to specific ips -* Prohibit inter-container communication by default -- Ignore ErrClosedPipe for stdin in Container.Attach -- Remove unused field kernelVersion -* Fix issue when mounting subdirectories of /mnt in container -- Fix untag during removal of images -* Check return value of syscall.Chdir when changing working directory inside dockerinit - -#### Client - -- Only pass stdin to hijack when needed to avoid closed pipe errors -* Use less reflection in command-line method invocation -- Monitor the tty size after starting the container, not prior -- Remove useless os.Exit() calls after log.Fatal - -#### Hack - -+ Add initial init scripts library and a safer Ubuntu packaging script that works for Debian -* Add -p option to invoke debootstrap with http_proxy -- Update install.sh with $sh_c to get sudo/su for modprobe -* Update all the mkimage scripts to use --numeric-owner as a tar argument -* Update hack/release.sh process to automatically invoke hack/make.sh and bail on build and test issues - -#### Other - -* Documentation: Fix the flags for nc in example -* Testing: Remove warnings and prevent mount issues -- Testing: Change logic for tty resize to avoid warning in tests -- Builder: Fix race condition in docker build with verbose output -- Registry: Fix content-type for PushImageJSONIndex method -* Contrib: Improve helper tools to generate debian and Arch linux server images - -## 0.6.4 (2013-10-16) - -#### Runtime - -- Add cleanup of container when Start() fails -* Add better comments to utils/stdcopy.go -* Add utils.Errorf for error logging -+ Add -rm to docker run for removing a container on exit -- Remove error messages which are not actually errors -- Fix `docker rm` with volumes -- Fix some error cases where an HTTP body might not be closed -- Fix panic with wrong dockercfg file -- Fix the attach behavior with -i -* Record termination time in state. -- Use empty string so TempDir uses the OS's temp dir automatically -- Make sure to close the network allocators -+ Autorestart containers by default -* Bump vendor kr/pty to commit 3b1f6487b `(syscall.O_NOCTTY)` -* lxc: Allow set_file_cap capability in container -- Move run -rm to the cli only -* Split stdout stderr -* Always create a new session for the container - -#### Testing - -- Add aggregated docker-ci email report -- Add cleanup to remove leftover containers -* Add nightly release to docker-ci -* Add more tests around auth.ResolveAuthConfig -- Remove a few errors in tests -- Catch errClosing error when TCP and UDP proxies are terminated -* Only run certain tests with TESTFLAGS='-run TestName' make.sh -* Prevent docker-ci to test closing PRs -* Replace panic by log.Fatal in tests -- Increase TestRunDetach timeout - -#### Documentation - -* Add initial draft of the Docker infrastructure doc -* Add devenvironment link to CONTRIBUTING.md -* Add `apt-get install curl` to Ubuntu docs -* Add explanation for export restrictions -* Add .dockercfg doc -* Remove Gentoo install notes about #1422 workaround -* Fix help text for -v option -* Fix Ping endpoint documentation -- Fix parameter names in docs for ADD command -- Fix ironic typo in changelog -* Various command fixes in postgres example -* Document how to edit and release docs -- Minor updates to `postgresql_service.rst` -* Clarify LGTM process to contributors -- Corrected error in the package name -* Document what `vagrant up` is actually doing -+ improve doc search results -* Cleanup whitespace in API 1.5 docs -* use angle brackets in MAINTAINER example email -* Update archlinux.rst -+ Changes to a new style for the docs. Includes version switcher. -* Formatting, add information about multiline json -* Improve registry and index REST API documentation -- Replace deprecated upgrading reference to docker-latest.tgz, which hasn't been updated since 0.5.3 -* Update Gentoo installation documentation now that we're in the portage tree proper -* Cleanup and reorganize docs and tooling for contributors and maintainers -- Minor spelling correction of protocoll -> protocol - -#### Contrib - -* Add vim syntax highlighting for Dockerfiles from @honza -* Add mkimage-arch.sh -* Reorganize contributed completion scripts to add zsh completion - -#### Hack - -* Add vagrant user to the docker group -* Add proper bash completion for "docker push" -* Add xz utils as a runtime dep -* Add cleanup/refactor portion of #2010 for hack and Dockerfile updates -+ Add contrib/mkimage-centos.sh back (from #1621), and associated documentation link -* Add several of the small make.sh fixes from #1920, and make the output more consistent and contributor-friendly -+ Add @tianon to hack/MAINTAINERS -* Improve network performance for VirtualBox -* Revamp install.sh to be usable by more people, and to use official install methods whenever possible (apt repo, portage tree, etc.) -- Fix contrib/mkimage-debian.sh apt caching prevention -+ Add Dockerfile.tmLanguage to contrib -* Configured FPM to make /etc/init/docker.conf a config file -* Enable SSH Agent forwarding in Vagrant VM -* Several small tweaks/fixes for contrib/mkimage-debian.sh - -#### Other - -- Builder: Abort build if mergeConfig returns an error and fix duplicate error message -- Packaging: Remove deprecated packaging directory -- Registry: Use correct auth config when logging in. -- Registry: Fix the error message so it is the same as the regex - -## 0.6.3 (2013-09-23) - -#### Packaging - -* Add 'docker' group on install for ubuntu package -* Update tar vendor dependency -* Download apt key over HTTPS - -#### Runtime - -- Only copy and change permissions on non-bindmount volumes -* Allow multiple volumes-from -- Fix HTTP imports from STDIN - -#### Documentation - -* Update section on extracting the docker binary after build -* Update development environment docs for new build process -* Remove 'base' image from documentation - -#### Other - -- Client: Fix detach issue -- Registry: Update regular expression to match index - -## 0.6.2 (2013-09-17) - -#### Runtime - -+ Add domainname support -+ Implement image filtering with path.Match -* Remove unnecessary warnings -* Remove os/user dependency -* Only mount the hostname file when the config exists -* Handle signals within the `docker login` command -- UID and GID are now also applied to volumes -- `docker start` set error code upon error -- `docker run` set the same error code as the process started - -#### Builder - -+ Add -rm option in order to remove intermediate containers -* Allow multiline for the RUN instruction - -#### Registry - -* Implement login with private registry -- Fix push issues - -#### Other - -+ Hack: Vendor all dependencies -* Remote API: Bump to v1.5 -* Packaging: Break down hack/make.sh into small scripts, one per 'bundle': test, binary, ubuntu etc. -* Documentation: General improvements - -## 0.6.1 (2013-08-23) - -#### Registry - -* Pass "meta" headers in API calls to the registry - -#### Packaging - -- Use correct upstart script with new build tool -- Use libffi-dev, don`t build it from sources -- Remove duplicate mercurial install command - -## 0.6.0 (2013-08-22) - -#### Runtime - -+ Add lxc-conf flag to allow custom lxc options -+ Add an option to set the working directory -* Add Image name to LogEvent tests -+ Add -privileged flag and relevant tests, docs, and examples -* Add websocket support to /container//attach/ws -* Add warning when net.ipv4.ip_forwarding = 0 -* Add hostname to environment -* Add last stable version in `docker version` -- Fix race conditions in parallel pull -- Fix Graph ByParent() to generate list of child images per parent image. -- Fix typo: fmt.Sprint -> fmt.Sprintf -- Fix small \n error un docker build -* Fix to "Inject dockerinit at /.dockerinit" -* Fix #910. print user name to docker info output -* Use Go 1.1.2 for dockerbuilder -* Use ranged for loop on channels -- Use utils.ParseRepositoryTag instead of strings.Split(name, ":") in server.ImageDelete -- Improve CMD, ENTRYPOINT, and attach docs. -- Improve connect message with socket error -- Load authConfig only when needed and fix useless WARNING -- Show tag used when image is missing -* Apply volumes-from before creating volumes -- Make docker run handle SIGINT/SIGTERM -- Prevent crash when .dockercfg not readable -- Install script should be fetched over https, not http. -* API, issue 1471: Use groups for socket permissions -- Correctly detect IPv4 forwarding -* Mount /dev/shm as a tmpfs -- Switch from http to https for get.docker.io -* Let userland proxy handle container-bound traffic -* Update the Docker CLI to specify a value for the "Host" header. -- Change network range to avoid conflict with EC2 DNS -- Reduce connect and read timeout when pinging the registry -* Parallel pull -- Handle ip route showing mask-less IP addresses -* Allow ENTRYPOINT without CMD -- Always consider localhost as a domain name when parsing the FQN repos name -* Refactor checksum - -#### Documentation - -* Add MongoDB image example -* Add instructions for creating and using the docker group -* Add sudo to examples and installation to documentation -* Add ufw doc -* Add a reference to ps -a -* Add information about Docker`s high level tools over LXC. -* Fix typo in docs for docker run -dns -* Fix a typo in the ubuntu installation guide -* Fix to docs regarding adding docker groups -* Update default -H docs -* Update readme with dependencies for building -* Update amazon.rst to explain that Vagrant is not necessary for running Docker on ec2 -* PostgreSQL service example in documentation -* Suggest installing linux-headers by default. -* Change the twitter handle -* Clarify Amazon EC2 installation -* 'Base' image is deprecated and should no longer be referenced in the docs. -* Move note about officially supported kernel -- Solved the logo being squished in Safari - -#### Builder - -+ Add USER instruction do Dockerfile -+ Add workdir support for the Buildfile -* Add no cache for docker build -- Fix docker build and docker events output -- Only count known instructions as build steps -- Make sure ENV instruction within build perform a commit each time -- Forbid certain paths within docker build ADD -- Repository name (and optionally a tag) in build usage -- Make sure ADD will create everything in 0755 - -#### Remote API - -* Sort Images by most recent creation date. -* Reworking opaque requests in registry module -* Add image name in /events -* Use mime pkg to parse Content-Type -* 650 http utils and user agent field - -#### Hack - -+ Bash Completion: Limit commands to containers of a relevant state -* Add docker dependencies coverage testing into docker-ci - -#### Packaging - -+ Docker-brew 0.5.2 support and memory footprint reduction -* Add new docker dependencies into docker-ci -- Revert "docker.upstart: avoid spawning a `sh` process" -+ Docker-brew and Docker standard library -+ Release docker with docker -* Fix the upstart script generated by get.docker.io -* Enabled the docs to generate manpages. -* Revert Bind daemon to 0.0.0.0 in Vagrant. - -#### Register - -* Improve auth push -* Registry unit tests + mock registry - -#### Tests - -* Improve TestKillDifferentUser to prevent timeout on buildbot -- Fix typo in TestBindMounts (runContainer called without image) -* Improve TestGetContainersTop so it does not rely on sleep -* Relax the lo interface test to allow iface index != 1 -* Add registry functional test to docker-ci -* Add some tests in server and utils - -#### Other - -* Contrib: bash completion script -* Client: Add docker cp command and copy api endpoint to copy container files/folders to the host -* Don`t read from stdout when only attached to stdin - -## 0.5.3 (2013-08-13) - -#### Runtime - -* Use docker group for socket permissions -- Spawn shell within upstart script -- Handle ip route showing mask-less IP addresses -- Add hostname to environment - -#### Builder - -- Make sure ENV instruction within build perform a commit each time - -## 0.5.2 (2013-08-08) - -* Builder: Forbid certain paths within docker build ADD -- Runtime: Change network range to avoid conflict with EC2 DNS -* API: Change daemon to listen on unix socket by default - -## 0.5.1 (2013-07-30) - -#### Runtime - -+ Add `ps` args to `docker top` -+ Add support for container ID files (pidfile like) -+ Add container=lxc in default env -+ Support networkless containers with `docker run -n` and `docker -d -b=none` -* Stdout/stderr logs are now stored in the same file as JSON -* Allocate a /16 IP range by default, with fallback to /24. Try 12 ranges instead of 3. -* Change .dockercfg format to json and support multiple auth remote -- Do not override volumes from config -- Fix issue with EXPOSE override - -#### API - -+ Docker client now sets useragent (RFC 2616) -+ Add /events endpoint - -#### Builder - -+ ADD command now understands URLs -+ CmdAdd and CmdEnv now respect Dockerfile-set ENV variables -- Create directories with 755 instead of 700 within ADD instruction - -#### Hack - -* Simplify unit tests with helpers -* Improve docker.upstart event -* Add coverage testing into docker-ci - -## 0.5.0 (2013-07-17) - -#### Runtime - -+ List all processes running inside a container with 'docker top' -+ Host directories can be mounted as volumes with 'docker run -v' -+ Containers can expose public UDP ports (eg, '-p 123/udp') -+ Optionally specify an exact public port (eg. '-p 80:4500') -* 'docker login' supports additional options -- Don't save a container`s hostname when committing an image. - -#### Registry - -+ New image naming scheme inspired by Go packaging convention allows arbitrary combinations of registries -- Fix issues when uploading images to a private registry - -#### Builder - -+ ENTRYPOINT instruction sets a default binary entry point to a container -+ VOLUME instruction marks a part of the container as persistent data -* 'docker build' displays the full output of a build by default - -## 0.4.8 (2013-07-01) - -+ Builder: New build operation ENTRYPOINT adds an executable entry point to the container. - Runtime: Fix a bug which caused 'docker run -d' to no longer print the container ID. -- Tests: Fix issues in the test suite - -## 0.4.7 (2013-06-28) - -#### Remote API - -* The progress bar updates faster when downloading and uploading large files -- Fix a bug in the optional unix socket transport - -#### Runtime - -* Improve detection of kernel version -+ Host directories can be mounted as volumes with 'docker run -b' -- fix an issue when only attaching to stdin -* Use 'tar --numeric-owner' to avoid uid mismatch across multiple hosts - -#### Hack - -* Improve test suite and dev environment -* Remove dependency on unit tests on 'os/user' - -#### Other - -* Registry: easier push/pull to a custom registry -+ Documentation: add terminology section - -## 0.4.6 (2013-06-22) - -- Runtime: fix a bug which caused creation of empty images (and volumes) to crash. - -## 0.4.5 (2013-06-21) - -+ Builder: 'docker build git://URL' fetches and builds a remote git repository -* Runtime: 'docker ps -s' optionally prints container size -* Tests: improved and simplified -- Runtime: fix a regression introduced in 0.4.3 which caused the logs command to fail. -- Builder: fix a regression when using ADD with single regular file. - -## 0.4.4 (2013-06-19) - -- Builder: fix a regression introduced in 0.4.3 which caused builds to fail on new clients. - -## 0.4.3 (2013-06-19) - -#### Builder - -+ ADD of a local file will detect tar archives and unpack them -* ADD improvements: use tar for copy + automatically unpack local archives -* ADD uses tar/untar for copies instead of calling 'cp -ar' -* Fix the behavior of ADD to be (mostly) reverse-compatible, predictable and well-documented. -- Fix a bug which caused builds to fail if ADD was the first command -* Nicer output for 'docker build' - -#### Runtime - -* Remove bsdtar dependency -* Add unix socket and multiple -H support -* Prevent rm of running containers -* Use go1.1 cookiejar -- Fix issue detaching from running TTY container -- Forbid parallel push/pull for a single image/repo. Fixes #311 -- Fix race condition within Run command when attaching. - -#### Client - -* HumanReadable ProgressBar sizes in pull -* Fix docker version`s git commit output - -#### API - -* Send all tags on History API call -* Add tag lookup to history command. Fixes #882 - -#### Documentation - -- Fix missing command in irc bouncer example - -## 0.4.2 (2013-06-17) - -- Packaging: Bumped version to work around an Ubuntu bug - -## 0.4.1 (2013-06-17) - -#### Remote Api - -+ Add flag to enable cross domain requests -+ Add images and containers sizes in docker ps and docker images - -#### Runtime - -+ Configure dns configuration host-wide with 'docker -d -dns' -+ Detect faulty DNS configuration and replace it with a public default -+ Allow docker run : -+ You can now specify public port (ex: -p 80:4500) -* Improve image removal to garbage-collect unreferenced parents - -#### Client - -* Allow multiple params in inspect -* Print the container id before the hijack in `docker run` - -#### Registry - -* Add regexp check on repo`s name -* Move auth to the client -- Remove login check on pull - -#### Other - -* Vagrantfile: Add the rest api port to vagrantfile`s port_forward -* Upgrade to Go 1.1 -- Builder: don`t ignore last line in Dockerfile when it doesn`t end with \n - -## 0.4.0 (2013-06-03) - -#### Builder - -+ Introducing Builder -+ 'docker build' builds a container, layer by layer, from a source repository containing a Dockerfile - -#### Remote API - -+ Introducing Remote API -+ control Docker programmatically using a simple HTTP/json API - -#### Runtime - -* Various reliability and usability improvements - -## 0.3.4 (2013-05-30) - -#### Builder - -+ 'docker build' builds a container, layer by layer, from a source repository containing a Dockerfile -+ 'docker build -t FOO' applies the tag FOO to the newly built container. - -#### Runtime - -+ Interactive TTYs correctly handle window resize -* Fix how configuration is merged between layers - -#### Remote API - -+ Split stdout and stderr on 'docker run' -+ Optionally listen on a different IP and port (use at your own risk) - -#### Documentation - -* Improve install instructions. - -## 0.3.3 (2013-05-23) - -- Registry: Fix push regression -- Various bugfixes - -## 0.3.2 (2013-05-09) - -#### Registry - -* Improve the checksum process -* Use the size to have a good progress bar while pushing -* Use the actual archive if it exists in order to speed up the push -- Fix error 400 on push - -#### Runtime - -* Store the actual archive on commit - -## 0.3.1 (2013-05-08) - -#### Builder - -+ Implement the autorun capability within docker builder -+ Add caching to docker builder -+ Add support for docker builder with native API as top level command -+ Implement ENV within docker builder -- Check the command existence prior create and add Unit tests for the case -* use any whitespaces instead of tabs - -#### Runtime - -+ Add go version to debug infos -* Kernel version - don`t show the dash if flavor is empty - -#### Registry - -+ Add docker search top level command in order to search a repository -- Fix pull for official images with specific tag -- Fix issue when login in with a different user and trying to push -* Improve checksum - async calculation - -#### Images - -+ Output graph of images to dot (graphviz) -- Fix ByParent function - -#### Documentation - -+ New introduction and high-level overview -+ Add the documentation for docker builder -- CSS fix for docker documentation to make REST API docs look better. -- Fix CouchDB example page header mistake -- Fix README formatting -* Update www.docker.io website. - -#### Other - -+ Website: new high-level overview -- Makefile: Swap "go get" for "go get -d", especially to compile on go1.1rc -* Packaging: packaging ubuntu; issue #510: Use goland-stable PPA package to build docker - -## 0.3.0 (2013-05-06) - -#### Runtime - -- Fix the command existence check -- strings.Split may return an empty string on no match -- Fix an index out of range crash if cgroup memory is not - -#### Documentation - -* Various improvements -+ New example: sharing data between 2 couchdb databases - -#### Other - -* Vagrant: Use only one deb line in /etc/apt -+ Registry: Implement the new registry - -## 0.2.2 (2013-05-03) - -+ Support for data volumes ('docker run -v=PATH') -+ Share data volumes between containers ('docker run -volumes-from') -+ Improve documentation -* Upgrade to Go 1.0.3 -* Various upgrades to the dev environment for contributors - -## 0.2.1 (2013-05-01) - -+ 'docker commit -run' bundles a layer with default runtime options: command, ports etc. -* Improve install process on Vagrant -+ New Dockerfile operation: "maintainer" -+ New Dockerfile operation: "expose" -+ New Dockerfile operation: "cmd" -+ Contrib script to build a Debian base layer -+ 'docker -d -r': restart crashed containers at daemon startup -* Runtime: improve test coverage - -## 0.2.0 (2013-04-23) - -- Runtime: ghost containers can be killed and waited for -* Documentation: update install instructions -- Packaging: fix Vagrantfile -- Development: automate releasing binaries and ubuntu packages -+ Add a changelog -- Various bugfixes - -## 0.1.8 (2013-04-22) - -- Dynamically detect cgroup capabilities -- Issue stability warning on kernels <3.8 -- 'docker push' buffers on disk instead of memory -- Fix 'docker diff' for removed files -- Fix 'docker stop' for ghost containers -- Fix handling of pidfile -- Various bugfixes and stability improvements - -## 0.1.7 (2013-04-18) - -- Container ports are available on localhost -- 'docker ps' shows allocated TCP ports -- Contributors can run 'make hack' to start a continuous integration VM -- Streamline ubuntu packaging & uploading -- Various bugfixes and stability improvements - -## 0.1.6 (2013-04-17) - -- Record the author an image with 'docker commit -author' - -## 0.1.5 (2013-04-17) - -- Disable standalone mode -- Use a custom DNS resolver with 'docker -d -dns' -- Detect ghost containers -- Improve diagnosis of missing system capabilities -- Allow disabling memory limits at compile time -- Add debian packaging -- Documentation: installing on Arch Linux -- Documentation: running Redis on docker -- Fix lxc 0.9 compatibility -- Automatically load aufs module -- Various bugfixes and stability improvements - -## 0.1.4 (2013-04-09) - -- Full support for TTY emulation -- Detach from a TTY session with the escape sequence `C-p C-q` -- Various bugfixes and stability improvements -- Minor UI improvements -- Automatically create our own bridge interface 'docker0' - -## 0.1.3 (2013-04-04) - -- Choose TCP frontend port with '-p :PORT' -- Layer format is versioned -- Major reliability improvements to the process manager -- Various bugfixes and stability improvements - -## 0.1.2 (2013-04-03) - -- Set container hostname with 'docker run -h' -- Selective attach at run with 'docker run -a [stdin[,stdout[,stderr]]]' -- Various bugfixes and stability improvements -- UI polish -- Progress bar on push/pull -- Use XZ compression by default -- Make IP allocator lazy - -## 0.1.1 (2013-03-31) - -- Display shorthand IDs for convenience -- Stabilize process management -- Layers can include a commit message -- Simplified 'docker attach' -- Fix support for re-attaching -- Various bugfixes and stability improvements -- Auto-download at run -- Auto-login on push -- Beefed up documentation - -## 0.1.0 (2013-03-23) - -Initial public release - -- Implement registry in order to push/pull images -- TCP port allocation -- Fix termcaps on Linux -- Add documentation -- Add Vagrant support with Vagrantfile -- Add unit tests -- Add repository/tags to ease image management -- Improve the layer implementation diff --git a/vendor/github.com/docker/docker/CONTRIBUTING.md b/vendor/github.com/docker/docker/CONTRIBUTING.md deleted file mode 100644 index eb5f8ab..0000000 --- a/vendor/github.com/docker/docker/CONTRIBUTING.md +++ /dev/null @@ -1,401 +0,0 @@ -# Contributing to Docker - -Want to hack on Docker? Awesome! We have a contributor's guide that explains -[setting up a Docker development environment and the contribution -process](https://docs.docker.com/opensource/project/who-written-for/). - -[![Contributors guide](docs/static_files/contributors.png)](https://docs.docker.com/opensource/project/who-written-for/) - -This page contains information about reporting issues as well as some tips and -guidelines useful to experienced open source contributors. Finally, make sure -you read our [community guidelines](#docker-community-guidelines) before you -start participating. - -## Topics - -* [Reporting Security Issues](#reporting-security-issues) -* [Design and Cleanup Proposals](#design-and-cleanup-proposals) -* [Reporting Issues](#reporting-other-issues) -* [Quick Contribution Tips and Guidelines](#quick-contribution-tips-and-guidelines) -* [Community Guidelines](#docker-community-guidelines) - -## Reporting security issues - -The Docker maintainers take security seriously. If you discover a security -issue, please bring it to their attention right away! - -Please **DO NOT** file a public issue, instead send your report privately to -[security@docker.com](mailto:security@docker.com). - -Security reports are greatly appreciated and we will publicly thank you for it. -We also like to send gifts—if you're into Docker schwag, make sure to let -us know. We currently do not offer a paid security bounty program, but are not -ruling it out in the future. - - -## Reporting other issues - -A great way to contribute to the project is to send a detailed report when you -encounter an issue. We always appreciate a well-written, thorough bug report, -and will thank you for it! - -Check that [our issue database](https://github.com/docker/docker/issues) -doesn't already include that problem or suggestion before submitting an issue. -If you find a match, you can use the "subscribe" button to get notified on -updates. Do *not* leave random "+1" or "I have this too" comments, as they -only clutter the discussion, and don't help resolving it. However, if you -have ways to reproduce the issue or have additional information that may help -resolving the issue, please leave a comment. - -When reporting issues, always include: - -* The output of `docker version`. -* The output of `docker info`. - -Also include the steps required to reproduce the problem if possible and -applicable. This information will help us review and fix your issue faster. -When sending lengthy log-files, consider posting them as a gist (https://gist.github.com). -Don't forget to remove sensitive data from your logfiles before posting (you can -replace those parts with "REDACTED"). - -## Quick contribution tips and guidelines - -This section gives the experienced contributor some tips and guidelines. - -### Pull requests are always welcome - -Not sure if that typo is worth a pull request? Found a bug and know how to fix -it? Do it! We will appreciate it. Any significant improvement should be -documented as [a GitHub issue](https://github.com/docker/docker/issues) before -anybody starts working on it. - -We are always thrilled to receive pull requests. We do our best to process them -quickly. If your pull request is not accepted on the first try, -don't get discouraged! Our contributor's guide explains [the review process we -use for simple changes](https://docs.docker.com/opensource/workflow/make-a-contribution/). - -### Design and cleanup proposals - -You can propose new designs for existing Docker features. You can also design -entirely new features. We really appreciate contributors who want to refactor or -otherwise cleanup our project. For information on making these types of -contributions, see [the advanced contribution -section](https://docs.docker.com/opensource/workflow/advanced-contributing/) in -the contributors guide. - -We try hard to keep Docker lean and focused. Docker can't do everything for -everybody. This means that we might decide against incorporating a new feature. -However, there might be a way to implement that feature *on top of* Docker. - -### Talking to other Docker users and contributors - - - - - - - - - - - - - - - - - - - - - - - - -
Forums - A public forum for users to discuss questions and explore current design patterns and - best practices about Docker and related projects in the Docker Ecosystem. To participate, - just log in with your Docker Hub account on https://forums.docker.com. -
Internet Relay Chat (IRC) -

- IRC a direct line to our most knowledgeable Docker users; we have - both the #docker and #docker-dev group on - irc.freenode.net. - IRC is a rich chat protocol but it can overwhelm new users. You can search - our chat archives. -

-

- Read our IRC quickstart guide - for an easy way to get started. -

-
Google Group - The docker-dev - group is for contributors and other people contributing to the Docker project. - You can join them without a google account by sending an email to - docker-dev+subscribe@googlegroups.com. - After receiving the join-request message, you can simply reply to that to confirm the subscription. -
Twitter - You can follow Docker's Twitter feed - to get updates on our products. You can also tweet us questions or just - share blogs or stories. -
Stack Overflow - Stack Overflow has over 17000 Docker questions listed. We regularly - monitor Docker questions - and so do many other knowledgeable Docker users. -
- - -### Conventions - -Fork the repository and make changes on your fork in a feature branch: - -- If it's a bug fix branch, name it XXXX-something where XXXX is the number of - the issue. -- If it's a feature branch, create an enhancement issue to announce - your intentions, and name it XXXX-something where XXXX is the number of the - issue. - -Submit unit tests for your changes. Go has a great test framework built in; use -it! Take a look at existing tests for inspiration. [Run the full test -suite](https://docs.docker.com/opensource/project/test-and-docs/) on your branch before -submitting a pull request. - -Update the documentation when creating or modifying features. Test your -documentation changes for clarity, concision, and correctness, as well as a -clean documentation build. See our contributors guide for [our style -guide](https://docs.docker.com/opensource/doc-style) and instructions on [building -the documentation](https://docs.docker.com/opensource/project/test-and-docs/#build-and-test-the-documentation). - -Write clean code. Universally formatted code promotes ease of writing, reading, -and maintenance. Always run `gofmt -s -w file.go` on each changed file before -committing your changes. Most editors have plug-ins that do this automatically. - -Pull request descriptions should be as clear as possible and include a reference -to all the issues that they address. - -Commit messages must start with a capitalized and short summary (max. 50 chars) -written in the imperative, followed by an optional, more detailed explanatory -text which is separated from the summary by an empty line. - -Code review comments may be added to your pull request. Discuss, then make the -suggested modifications and push additional commits to your feature branch. Post -a comment after pushing. New commits show up in the pull request automatically, -but the reviewers are notified only when you comment. - -Pull requests must be cleanly rebased on top of master without multiple branches -mixed into the PR. - -**Git tip**: If your PR no longer merges cleanly, use `rebase master` in your -feature branch to update your pull request rather than `merge master`. - -Before you make a pull request, squash your commits into logical units of work -using `git rebase -i` and `git push -f`. A logical unit of work is a consistent -set of patches that should be reviewed together: for example, upgrading the -version of a vendored dependency and taking advantage of its now available new -feature constitute two separate units of work. Implementing a new function and -calling it in another file constitute a single logical unit of work. The very -high majority of submissions should have a single commit, so if in doubt: squash -down to one. - -After every commit, [make sure the test suite passes] -(https://docs.docker.com/opensource/project/test-and-docs/). Include documentation -changes in the same pull request so that a revert would remove all traces of -the feature or fix. - -Include an issue reference like `Closes #XXXX` or `Fixes #XXXX` in commits that -close an issue. Including references automatically closes the issue on a merge. - -Please do not add yourself to the `AUTHORS` file, as it is regenerated regularly -from the Git history. - -Please see the [Coding Style](#coding-style) for further guidelines. - -### Merge approval - -Docker maintainers use LGTM (Looks Good To Me) in comments on the code review to -indicate acceptance. - -A change requires LGTMs from an absolute majority of the maintainers of each -component affected. For example, if a change affects `docs/` and `registry/`, it -needs an absolute majority from the maintainers of `docs/` AND, separately, an -absolute majority of the maintainers of `registry/`. - -For more details, see the [MAINTAINERS](MAINTAINERS) page. - -### Sign your work - -The sign-off is a simple line at the end of the explanation for the patch. Your -signature certifies that you wrote the patch or otherwise have the right to pass -it on as an open-source patch. The rules are pretty simple: if you can certify -the below (from [developercertificate.org](http://developercertificate.org/)): - -``` -Developer Certificate of Origin -Version 1.1 - -Copyright (C) 2004, 2006 The Linux Foundation and its contributors. -1 Letterman Drive -Suite D4700 -San Francisco, CA, 94129 - -Everyone is permitted to copy and distribute verbatim copies of this -license document, but changing it is not allowed. - -Developer's Certificate of Origin 1.1 - -By making a contribution to this project, I certify that: - -(a) The contribution was created in whole or in part by me and I - have the right to submit it under the open source license - indicated in the file; or - -(b) The contribution is based upon previous work that, to the best - of my knowledge, is covered under an appropriate open source - license and I have the right under that license to submit that - work with modifications, whether created in whole or in part - by me, under the same open source license (unless I am - permitted to submit under a different license), as indicated - in the file; or - -(c) The contribution was provided directly to me by some other - person who certified (a), (b) or (c) and I have not modified - it. - -(d) I understand and agree that this project and the contribution - are public and that a record of the contribution (including all - personal information I submit with it, including my sign-off) is - maintained indefinitely and may be redistributed consistent with - this project or the open source license(s) involved. -``` - -Then you just add a line to every git commit message: - - Signed-off-by: Joe Smith - -Use your real name (sorry, no pseudonyms or anonymous contributions.) - -If you set your `user.name` and `user.email` git configs, you can sign your -commit automatically with `git commit -s`. - -### How can I become a maintainer? - -The procedures for adding new maintainers are explained in the -global [MAINTAINERS](https://github.com/docker/opensource/blob/master/MAINTAINERS) -file in the [https://github.com/docker/opensource/](https://github.com/docker/opensource/) -repository. - -Don't forget: being a maintainer is a time investment. Make sure you -will have time to make yourself available. You don't have to be a -maintainer to make a difference on the project! - -## Docker community guidelines - -We want to keep the Docker community awesome, growing and collaborative. We need -your help to keep it that way. To help with this we've come up with some general -guidelines for the community as a whole: - -* Be nice: Be courteous, respectful and polite to fellow community members: - no regional, racial, gender, or other abuse will be tolerated. We like - nice people way better than mean ones! - -* Encourage diversity and participation: Make everyone in our community feel - welcome, regardless of their background and the extent of their - contributions, and do everything possible to encourage participation in - our community. - -* Keep it legal: Basically, don't get us in trouble. Share only content that - you own, do not share private or sensitive information, and don't break - the law. - -* Stay on topic: Make sure that you are posting to the correct channel and - avoid off-topic discussions. Remember when you update an issue or respond - to an email you are potentially sending to a large number of people. Please - consider this before you update. Also remember that nobody likes spam. - -* Don't send email to the maintainers: There's no need to send email to the - maintainers to ask them to investigate an issue or to take a look at a - pull request. Instead of sending an email, GitHub mentions should be - used to ping maintainers to review a pull request, a proposal or an - issue. - -### Guideline violations — 3 strikes method - -The point of this section is not to find opportunities to punish people, but we -do need a fair way to deal with people who are making our community suck. - -1. First occurrence: We'll give you a friendly, but public reminder that the - behavior is inappropriate according to our guidelines. - -2. Second occurrence: We will send you a private message with a warning that - any additional violations will result in removal from the community. - -3. Third occurrence: Depending on the violation, we may need to delete or ban - your account. - -**Notes:** - -* Obvious spammers are banned on first occurrence. If we don't do this, we'll - have spam all over the place. - -* Violations are forgiven after 6 months of good behavior, and we won't hold a - grudge. - -* People who commit minor infractions will get some education, rather than - hammering them in the 3 strikes process. - -* The rules apply equally to everyone in the community, no matter how much - you've contributed. - -* Extreme violations of a threatening, abusive, destructive or illegal nature - will be addressed immediately and are not subject to 3 strikes or forgiveness. - -* Contact abuse@docker.com to report abuse or appeal violations. In the case of - appeals, we know that mistakes happen, and we'll work with you to come up with a - fair solution if there has been a misunderstanding. - -## Coding Style - -Unless explicitly stated, we follow all coding guidelines from the Go -community. While some of these standards may seem arbitrary, they somehow seem -to result in a solid, consistent codebase. - -It is possible that the code base does not currently comply with these -guidelines. We are not looking for a massive PR that fixes this, since that -goes against the spirit of the guidelines. All new contributions should make a -best effort to clean up and make the code base better than they left it. -Obviously, apply your best judgement. Remember, the goal here is to make the -code base easier for humans to navigate and understand. Always keep that in -mind when nudging others to comply. - -The rules: - -1. All code should be formatted with `gofmt -s`. -2. All code should pass the default levels of - [`golint`](https://github.com/golang/lint). -3. All code should follow the guidelines covered in [Effective - Go](http://golang.org/doc/effective_go.html) and [Go Code Review - Comments](https://github.com/golang/go/wiki/CodeReviewComments). -4. Comment the code. Tell us the why, the history and the context. -5. Document _all_ declarations and methods, even private ones. Declare - expectations, caveats and anything else that may be important. If a type - gets exported, having the comments already there will ensure it's ready. -6. Variable name length should be proportional to its context and no longer. - `noCommaALongVariableNameLikeThisIsNotMoreClearWhenASimpleCommentWouldDo`. - In practice, short methods will have short variable names and globals will - have longer names. -7. No underscores in package names. If you need a compound name, step back, - and re-examine why you need a compound name. If you still think you need a - compound name, lose the underscore. -8. No utils or helpers packages. If a function is not general enough to - warrant its own package, it has not been written generally enough to be a - part of a util package. Just leave it unexported and well-documented. -9. All tests should run with `go test` and outside tooling should not be - required. No, we don't need another unit testing framework. Assertion - packages are acceptable if they provide _real_ incremental value. -10. Even though we call these "rules" above, they are actually just - guidelines. Since you've read all the rules, you now know that. - -If you are having trouble getting into the mood of idiomatic Go, we recommend -reading through [Effective Go](https://golang.org/doc/effective_go.html). The -[Go Blog](https://blog.golang.org) is also a great resource. Drinking the -kool-aid is a lot easier than going thirsty. diff --git a/vendor/github.com/docker/docker/Dockerfile b/vendor/github.com/docker/docker/Dockerfile deleted file mode 100644 index ce2d702..0000000 --- a/vendor/github.com/docker/docker/Dockerfile +++ /dev/null @@ -1,246 +0,0 @@ -# This file describes the standard way to build Docker, using docker -# -# Usage: -# -# # Assemble the full dev environment. This is slow the first time. -# docker build -t docker . -# -# # Mount your source in an interactive container for quick testing: -# docker run -v `pwd`:/go/src/github.com/docker/docker --privileged -i -t docker bash -# -# # Run the test suite: -# docker run --privileged docker hack/make.sh test-unit test-integration-cli test-docker-py -# -# # Publish a release: -# docker run --privileged \ -# -e AWS_S3_BUCKET=baz \ -# -e AWS_ACCESS_KEY=foo \ -# -e AWS_SECRET_KEY=bar \ -# -e GPG_PASSPHRASE=gloubiboulga \ -# docker hack/release.sh -# -# Note: AppArmor used to mess with privileged mode, but this is no longer -# the case. Therefore, you don't have to disable it anymore. -# - -FROM debian:jessie - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - -# Add zfs ppa -RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys E871F18B51E0147C77796AC81196BA81F6B0FC61 \ - || apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys E871F18B51E0147C77796AC81196BA81F6B0FC61 -RUN echo deb http://ppa.launchpad.net/zfs-native/stable/ubuntu trusty main > /etc/apt/sources.list.d/zfs.list - -# Packaged dependencies -RUN apt-get update && apt-get install -y \ - apparmor \ - apt-utils \ - aufs-tools \ - automake \ - bash-completion \ - binutils-mingw-w64 \ - bsdmainutils \ - btrfs-tools \ - build-essential \ - clang \ - cmake \ - createrepo \ - curl \ - dpkg-sig \ - gcc-mingw-w64 \ - git \ - iptables \ - jq \ - libapparmor-dev \ - libcap-dev \ - libltdl-dev \ - libnl-3-dev \ - libprotobuf-c0-dev \ - libprotobuf-dev \ - libsqlite3-dev \ - libsystemd-journal-dev \ - libtool \ - mercurial \ - net-tools \ - pkg-config \ - protobuf-compiler \ - protobuf-c-compiler \ - python-dev \ - python-mock \ - python-pip \ - python-websocket \ - ubuntu-zfs \ - xfsprogs \ - vim-common \ - libzfs-dev \ - tar \ - zip \ - --no-install-recommends \ - && pip install awscli==1.10.15 -# Get lvm2 source for compiling statically -ENV LVM2_VERSION 2.02.103 -RUN mkdir -p /usr/local/lvm2 \ - && curl -fsSL "https://mirrors.kernel.org/sourceware/lvm2/LVM2.${LVM2_VERSION}.tgz" \ - | tar -xzC /usr/local/lvm2 --strip-components=1 -# See https://git.fedorahosted.org/cgit/lvm2.git/refs/tags for release tags - -# Compile and install lvm2 -RUN cd /usr/local/lvm2 \ - && ./configure \ - --build="$(gcc -print-multiarch)" \ - --enable-static_link \ - && make device-mapper \ - && make install_device-mapper -# See https://git.fedorahosted.org/cgit/lvm2.git/tree/INSTALL - -# Configure the container for OSX cross compilation -ENV OSX_SDK MacOSX10.11.sdk -ENV OSX_CROSS_COMMIT a9317c18a3a457ca0a657f08cc4d0d43c6cf8953 -RUN set -x \ - && export OSXCROSS_PATH="/osxcross" \ - && git clone https://github.com/tpoechtrager/osxcross.git $OSXCROSS_PATH \ - && ( cd $OSXCROSS_PATH && git checkout -q $OSX_CROSS_COMMIT) \ - && curl -sSL https://s3.dockerproject.org/darwin/v2/${OSX_SDK}.tar.xz -o "${OSXCROSS_PATH}/tarballs/${OSX_SDK}.tar.xz" \ - && UNATTENDED=yes OSX_VERSION_MIN=10.6 ${OSXCROSS_PATH}/build.sh -ENV PATH /osxcross/target/bin:$PATH - -# Install seccomp: the version shipped in trusty is too old -ENV SECCOMP_VERSION 2.3.1 -RUN set -x \ - && export SECCOMP_PATH="$(mktemp -d)" \ - && curl -fsSL "https://github.com/seccomp/libseccomp/releases/download/v${SECCOMP_VERSION}/libseccomp-${SECCOMP_VERSION}.tar.gz" \ - | tar -xzC "$SECCOMP_PATH" --strip-components=1 \ - && ( \ - cd "$SECCOMP_PATH" \ - && ./configure --prefix=/usr/local \ - && make \ - && make install \ - && ldconfig \ - ) \ - && rm -rf "$SECCOMP_PATH" - -# Install Go -# IMPORTANT: If the version of Go is updated, the Windows to Linux CI machines -# will need updating, to avoid errors. Ping #docker-maintainers on IRC -# with a heads-up. -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" \ - | tar -xzC /usr/local - -ENV PATH /go/bin:/usr/local/go/bin:$PATH -ENV GOPATH /go - -# Compile Go for cross compilation -ENV DOCKER_CROSSPLATFORMS \ - linux/386 linux/arm \ - darwin/amd64 \ - freebsd/amd64 freebsd/386 freebsd/arm \ - windows/amd64 windows/386 \ - solaris/amd64 - -# Dependency for golint -ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3 -RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ - && (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) - -# Grab Go's lint tool -ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456 -RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ - && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ - && go install -v github.com/golang/lint/golint - -# Install CRIU for checkpoint/restore support -ENV CRIU_VERSION 2.2 -RUN mkdir -p /usr/src/criu \ - && curl -sSL https://github.com/xemul/criu/archive/v${CRIU_VERSION}.tar.gz | tar -v -C /usr/src/criu/ -xz --strip-components=1 \ - && cd /usr/src/criu \ - && make \ - && make install-criu - -# Install two versions of the registry. The first is an older version that -# only supports schema1 manifests. The second is a newer version that supports -# both. This allows integration-cli tests to cover push/pull with both schema1 -# and schema2 manifests. -ENV REGISTRY_COMMIT_SCHEMA1 ec87e9b6971d831f0eff752ddb54fb64693e51cd -ENV REGISTRY_COMMIT 47a064d4195a9b56133891bbb13620c3ac83a827 -RUN set -x \ - && export GOPATH="$(mktemp -d)" \ - && git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \ - && (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \ - && GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \ - && (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT_SCHEMA1") \ - && GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \ - && rm -rf "$GOPATH" - -# Install notary and notary-server -ENV NOTARY_VERSION v0.4.2 -RUN set -x \ - && export GOPATH="$(mktemp -d)" \ - && git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \ - && (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION") \ - && GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \ - go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \ - && GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \ - go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \ - && rm -rf "$GOPATH" - -# Get the "docker-py" source so we can run their integration tests -ENV DOCKER_PY_COMMIT e2655f658408f9ad1f62abdef3eb6ed43c0cf324 -RUN git clone https://github.com/docker/docker-py.git /docker-py \ - && cd /docker-py \ - && git checkout -q $DOCKER_PY_COMMIT \ - && pip install -r test-requirements.txt - -# Install yamllint for validating swagger.yaml -RUN pip install yamllint==1.5.0 - -# Install go-swagger for validating swagger.yaml -ENV GO_SWAGGER_COMMIT c28258affb0b6251755d92489ef685af8d4ff3eb -RUN git clone https://github.com/go-swagger/go-swagger.git /go/src/github.com/go-swagger/go-swagger \ - && (cd /go/src/github.com/go-swagger/go-swagger && git checkout -q $GO_SWAGGER_COMMIT) \ - && go install -v github.com/go-swagger/go-swagger/cmd/swagger - -# Set user.email so crosbymichael's in-container merge commits go smoothly -RUN git config --global user.email 'docker-dummy@example.com' - -# Add an unprivileged user to be used for tests which need it -RUN groupadd -r docker -RUN useradd --create-home --gid docker unprivilegeduser - -VOLUME /var/lib/docker -WORKDIR /go/src/github.com/docker/docker -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux - -# Let us use a .bashrc file -RUN ln -sfv $PWD/.bashrc ~/.bashrc -# Add integration helps to bashrc -RUN echo "source $PWD/hack/make/.integration-test-helpers" >> /etc/bash.bashrc - -# Register Docker's bash completion. -RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker - -# Get useful and necessary Hub images so we can "docker load" locally instead of pulling -COPY contrib/download-frozen-image-v2.sh /go/src/github.com/docker/docker/contrib/ -RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \ - buildpack-deps:jessie@sha256:25785f89240fbcdd8a74bdaf30dd5599a9523882c6dfc567f2e9ef7cf6f79db6 \ - busybox:latest@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0 \ - debian:jessie@sha256:f968f10b4b523737e253a97eac59b0d1420b5c19b69928d35801a6373ffe330e \ - hello-world:latest@sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7 -# See also "hack/make/.ensure-frozen-images" (which needs to be updated any time this list is) - -# Install tomlv, vndr, runc, containerd, tini, docker-proxy -# Please edit hack/dockerfile/install-binaries.sh to update them. -COPY hack/dockerfile/binaries-commits /tmp/binaries-commits -COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh -RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy bindata - -# Wrap all commands in the "docker-in-docker" script to allow nested containers -ENTRYPOINT ["hack/dind"] - -# Upload docker source -COPY . /go/src/github.com/docker/docker diff --git a/vendor/github.com/docker/docker/Dockerfile.aarch64 b/vendor/github.com/docker/docker/Dockerfile.aarch64 deleted file mode 100644 index 6112f80..0000000 --- a/vendor/github.com/docker/docker/Dockerfile.aarch64 +++ /dev/null @@ -1,175 +0,0 @@ -# This file describes the standard way to build Docker on aarch64, using docker -# -# Usage: -# -# # Assemble the full dev environment. This is slow the first time. -# docker build -t docker -f Dockerfile.aarch64 . -# -# # Mount your source in an interactive container for quick testing: -# docker run -v `pwd`:/go/src/github.com/docker/docker --privileged -i -t docker bash -# -# # Run the test suite: -# docker run --privileged docker hack/make.sh test-unit test-integration-cli test-docker-py -# -# Note: AppArmor used to mess with privileged mode, but this is no longer -# the case. Therefore, you don't have to disable it anymore. -# - -FROM aarch64/ubuntu:wily - -# Packaged dependencies -RUN apt-get update && apt-get install -y \ - apparmor \ - aufs-tools \ - automake \ - bash-completion \ - btrfs-tools \ - build-essential \ - cmake \ - createrepo \ - curl \ - dpkg-sig \ - g++ \ - gcc \ - git \ - iptables \ - jq \ - libapparmor-dev \ - libc6-dev \ - libcap-dev \ - libltdl-dev \ - libsqlite3-dev \ - libsystemd-dev \ - mercurial \ - net-tools \ - parallel \ - pkg-config \ - python-dev \ - python-mock \ - python-pip \ - python-websocket \ - gccgo \ - iproute2 \ - iputils-ping \ - vim-common \ - --no-install-recommends - -# Get lvm2 source for compiling statically -ENV LVM2_VERSION 2.02.103 -RUN mkdir -p /usr/local/lvm2 \ - && curl -fsSL "https://mirrors.kernel.org/sourceware/lvm2/LVM2.${LVM2_VERSION}.tgz" \ - | tar -xzC /usr/local/lvm2 --strip-components=1 -# See https://git.fedorahosted.org/cgit/lvm2.git/refs/tags for release tags - -# Fix platform enablement in lvm2 to support aarch64 properly -RUN set -e \ - && for f in config.guess config.sub; do \ - curl -fsSL -o "/usr/local/lvm2/autoconf/$f" "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=$f;hb=HEAD"; \ - done -# "arch.c:78:2: error: #error the arch code needs to know about your machine type" - -# Compile and install lvm2 -RUN cd /usr/local/lvm2 \ - && ./configure \ - --build="$(gcc -print-multiarch)" \ - --enable-static_link \ - && make device-mapper \ - && make install_device-mapper -# See https://git.fedorahosted.org/cgit/lvm2.git/tree/INSTALL - -# Install seccomp: the version shipped in trusty is too old -ENV SECCOMP_VERSION 2.3.1 -RUN set -x \ - && export SECCOMP_PATH="$(mktemp -d)" \ - && curl -fsSL "https://github.com/seccomp/libseccomp/releases/download/v${SECCOMP_VERSION}/libseccomp-${SECCOMP_VERSION}.tar.gz" \ - | tar -xzC "$SECCOMP_PATH" --strip-components=1 \ - && ( \ - cd "$SECCOMP_PATH" \ - && ./configure --prefix=/usr/local \ - && make \ - && make install \ - && ldconfig \ - ) \ - && rm -rf "$SECCOMP_PATH" - -# Install Go -# We don't have official binary tarballs for ARM64, eigher for Go or bootstrap, -# so we use gccgo as bootstrap to build Go from source code. -# We don't use the official ARMv6 released binaries as a GOROOT_BOOTSTRAP, because -# not all ARM64 platforms support 32-bit mode. 32-bit mode is optional for ARMv8. -ENV GO_VERSION 1.7.5 -RUN mkdir /usr/src/go && curl -fsSL https://golang.org/dl/go${GO_VERSION}.src.tar.gz | tar -v -C /usr/src/go -xz --strip-components=1 \ - && cd /usr/src/go/src \ - && GOOS=linux GOARCH=arm64 GOROOT_BOOTSTRAP="$(go env GOROOT)" ./make.bash - -ENV PATH /usr/src/go/bin:$PATH -ENV GOPATH /go - -# Only install one version of the registry, because old version which support -# schema1 manifests is not working on ARM64, we should skip integration-cli -# tests for schema1 manifests on ARM64. -ENV REGISTRY_COMMIT 47a064d4195a9b56133891bbb13620c3ac83a827 -RUN set -x \ - && export GOPATH="$(mktemp -d)" \ - && git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \ - && (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \ - && GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \ - && rm -rf "$GOPATH" - -# Install notary and notary-server -ENV NOTARY_VERSION v0.4.2 -RUN set -x \ - && export GOPATH="$(mktemp -d)" \ - && git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \ - && (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION") \ - && GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \ - go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \ - && GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \ - go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \ - && rm -rf "$GOPATH" - -# Get the "docker-py" source so we can run their integration tests -ENV DOCKER_PY_COMMIT e2655f658408f9ad1f62abdef3eb6ed43c0cf324 -RUN git clone https://github.com/docker/docker-py.git /docker-py \ - && cd /docker-py \ - && git checkout -q $DOCKER_PY_COMMIT \ - && pip install -r test-requirements.txt - -# Set user.email so crosbymichael's in-container merge commits go smoothly -RUN git config --global user.email 'docker-dummy@example.com' - -# Add an unprivileged user to be used for tests which need it -RUN groupadd -r docker -RUN useradd --create-home --gid docker unprivilegeduser - -VOLUME /var/lib/docker -WORKDIR /go/src/github.com/docker/docker -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux - -# Let us use a .bashrc file -RUN ln -sfv $PWD/.bashrc ~/.bashrc - -# Register Docker's bash completion. -RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker - -# Get useful and necessary Hub images so we can "docker load" locally instead of pulling -COPY contrib/download-frozen-image-v2.sh /go/src/github.com/docker/docker/contrib/ -RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \ - aarch64/buildpack-deps:jessie@sha256:6aa1d6910791b7ac78265fd0798e5abd6cb3f27ae992f6f960f6c303ec9535f2 \ - aarch64/busybox:latest@sha256:b23a6a37cf269dff6e46d2473b6e227afa42b037e6d23435f1d2bc40fc8c2828 \ - aarch64/debian:jessie@sha256:4be74a41a7c70ebe887b634b11ffe516cf4fcd56864a54941e56bb49883c3170 \ - aarch64/hello-world:latest@sha256:65a4a158587b307bb02db4de41b836addb0c35175bdc801367b1ac1ddeb9afda -# See also "hack/make/.ensure-frozen-images" (which needs to be updated any time this list is) - -# Install tomlv, vndr, runc, containerd, tini, docker-proxy -# Please edit hack/dockerfile/install-binaries.sh to update them. -COPY hack/dockerfile/binaries-commits /tmp/binaries-commits -COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh -RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy - -# Wrap all commands in the "docker-in-docker" script to allow nested containers -ENTRYPOINT ["hack/dind"] - -# Upload docker source -COPY . /go/src/github.com/docker/docker diff --git a/vendor/github.com/docker/docker/Dockerfile.armhf b/vendor/github.com/docker/docker/Dockerfile.armhf deleted file mode 100644 index 1aebc16..0000000 --- a/vendor/github.com/docker/docker/Dockerfile.armhf +++ /dev/null @@ -1,182 +0,0 @@ -# This file describes the standard way to build Docker on ARMv7, using docker -# -# Usage: -# -# # Assemble the full dev environment. This is slow the first time. -# docker build -t docker -f Dockerfile.armhf . -# -# # Mount your source in an interactive container for quick testing: -# docker run -v `pwd`:/go/src/github.com/docker/docker --privileged -i -t docker bash -# -# # Run the test suite: -# docker run --privileged docker hack/make.sh test-unit test-integration-cli test-docker-py -# -# Note: AppArmor used to mess with privileged mode, but this is no longer -# the case. Therefore, you don't have to disable it anymore. -# - -FROM armhf/debian:jessie - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - -# Packaged dependencies -RUN apt-get update && apt-get install -y \ - apparmor \ - aufs-tools \ - automake \ - bash-completion \ - btrfs-tools \ - build-essential \ - createrepo \ - curl \ - cmake \ - dpkg-sig \ - git \ - iptables \ - jq \ - net-tools \ - libapparmor-dev \ - libcap-dev \ - libltdl-dev \ - libsqlite3-dev \ - libsystemd-journal-dev \ - libtool \ - mercurial \ - pkg-config \ - python-dev \ - python-mock \ - python-pip \ - python-websocket \ - xfsprogs \ - tar \ - vim-common \ - --no-install-recommends \ - && pip install awscli==1.10.15 - -# Get lvm2 source for compiling statically -ENV LVM2_VERSION 2.02.103 -RUN mkdir -p /usr/local/lvm2 \ - && curl -fsSL "https://mirrors.kernel.org/sourceware/lvm2/LVM2.${LVM2_VERSION}.tgz" \ - | tar -xzC /usr/local/lvm2 --strip-components=1 -# See https://git.fedorahosted.org/cgit/lvm2.git/refs/tags for release tags - -# Compile and install lvm2 -RUN cd /usr/local/lvm2 \ - && ./configure \ - --build="$(gcc -print-multiarch)" \ - --enable-static_link \ - && make device-mapper \ - && make install_device-mapper -# See https://git.fedorahosted.org/cgit/lvm2.git/tree/INSTALL - -# Install Go -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" \ - | tar -xzC /usr/local -ENV PATH /go/bin:/usr/local/go/bin:$PATH -ENV GOPATH /go - -# We're building for armhf, which is ARMv7, so let's be explicit about that -ENV GOARCH arm -ENV GOARM 7 - -# Dependency for golint -ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3 -RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ - && (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) - -# Grab Go's lint tool -ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456 -RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ - && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ - && go install -v github.com/golang/lint/golint - -# Install seccomp: the version shipped in trusty is too old -ENV SECCOMP_VERSION 2.3.1 -RUN set -x \ - && export SECCOMP_PATH="$(mktemp -d)" \ - && curl -fsSL "https://github.com/seccomp/libseccomp/releases/download/v${SECCOMP_VERSION}/libseccomp-${SECCOMP_VERSION}.tar.gz" \ - | tar -xzC "$SECCOMP_PATH" --strip-components=1 \ - && ( \ - cd "$SECCOMP_PATH" \ - && ./configure --prefix=/usr/local \ - && make \ - && make install \ - && ldconfig \ - ) \ - && rm -rf "$SECCOMP_PATH" - -# Install two versions of the registry. The first is an older version that -# only supports schema1 manifests. The second is a newer version that supports -# both. This allows integration-cli tests to cover push/pull with both schema1 -# and schema2 manifests. -ENV REGISTRY_COMMIT_SCHEMA1 ec87e9b6971d831f0eff752ddb54fb64693e51cd -ENV REGISTRY_COMMIT cb08de17d74bef86ce6c5abe8b240e282f5750be -RUN set -x \ - && export GOPATH="$(mktemp -d)" \ - && git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \ - && (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \ - && GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \ - && (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT_SCHEMA1") \ - && GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \ - && rm -rf "$GOPATH" - -# Install notary and notary-server -ENV NOTARY_VERSION v0.4.2 -RUN set -x \ - && export GOPATH="$(mktemp -d)" \ - && git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \ - && (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION") \ - && GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \ - go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \ - && GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \ - go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \ - && rm -rf "$GOPATH" - -# Get the "docker-py" source so we can run their integration tests -ENV DOCKER_PY_COMMIT e2655f658408f9ad1f62abdef3eb6ed43c0cf324 -RUN git clone https://github.com/docker/docker-py.git /docker-py \ - && cd /docker-py \ - && git checkout -q $DOCKER_PY_COMMIT \ - && pip install -r test-requirements.txt - -# Set user.email so crosbymichael's in-container merge commits go smoothly -RUN git config --global user.email 'docker-dummy@example.com' - -# Add an unprivileged user to be used for tests which need it -RUN groupadd -r docker -RUN useradd --create-home --gid docker unprivilegeduser - -VOLUME /var/lib/docker -WORKDIR /go/src/github.com/docker/docker -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux - -# Let us use a .bashrc file -RUN ln -sfv $PWD/.bashrc ~/.bashrc - -# Register Docker's bash completion. -RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker - -# Get useful and necessary Hub images so we can "docker load" locally instead of pulling -COPY contrib/download-frozen-image-v2.sh /go/src/github.com/docker/docker/contrib/ -RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \ - armhf/buildpack-deps:jessie@sha256:ca6cce8e5bf5c952129889b5cc15cd6aa8d995d77e55e3749bbaadae50e476cb \ - armhf/busybox:latest@sha256:d98a7343ac750ffe387e3d514f8521ba69846c216778919b01414b8617cfb3d4 \ - armhf/debian:jessie@sha256:4a2187483f04a84f9830910fe3581d69b3c985cc045d9f01d8e2f3795b28107b \ - armhf/hello-world:latest@sha256:161dcecea0225975b2ad5f768058212c1e0d39e8211098666ffa1ac74cfb7791 -# See also "hack/make/.ensure-frozen-images" (which needs to be updated any time this list is) - -# Install tomlv, vndr, runc, containerd, tini, docker-proxy -# Please edit hack/dockerfile/install-binaries.sh to update them. -COPY hack/dockerfile/binaries-commits /tmp/binaries-commits -COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh -RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy - -ENTRYPOINT ["hack/dind"] - -# Upload docker source -COPY . /go/src/github.com/docker/docker diff --git a/vendor/github.com/docker/docker/Dockerfile.ppc64le b/vendor/github.com/docker/docker/Dockerfile.ppc64le deleted file mode 100644 index 1f9f500..0000000 --- a/vendor/github.com/docker/docker/Dockerfile.ppc64le +++ /dev/null @@ -1,188 +0,0 @@ -# This file describes the standard way to build Docker on ppc64le, using docker -# -# Usage: -# -# # Assemble the full dev environment. This is slow the first time. -# docker build -t docker -f Dockerfile.ppc64le . -# -# # Mount your source in an interactive container for quick testing: -# docker run -v `pwd`:/go/src/github.com/docker/docker --privileged -i -t docker bash -# -# # Run the test suite: -# docker run --privileged docker hack/make.sh test-unit test-integration-cli test-docker-py -# -# Note: AppArmor used to mess with privileged mode, but this is no longer -# the case. Therefore, you don't have to disable it anymore. -# - -FROM ppc64le/debian:jessie - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - -# Packaged dependencies -RUN apt-get update && apt-get install -y \ - apparmor \ - aufs-tools \ - automake \ - bash-completion \ - btrfs-tools \ - build-essential \ - cmake \ - createrepo \ - curl \ - dpkg-sig \ - git \ - iptables \ - jq \ - net-tools \ - libapparmor-dev \ - libcap-dev \ - libltdl-dev \ - libsqlite3-dev \ - libsystemd-journal-dev \ - libtool \ - mercurial \ - pkg-config \ - python-dev \ - python-mock \ - python-pip \ - python-websocket \ - xfsprogs \ - tar \ - vim-common \ - --no-install-recommends - -# Get lvm2 source for compiling statically -ENV LVM2_VERSION 2.02.103 -RUN mkdir -p /usr/local/lvm2 \ - && curl -fsSL "https://mirrors.kernel.org/sourceware/lvm2/LVM2.${LVM2_VERSION}.tgz" \ - | tar -xzC /usr/local/lvm2 --strip-components=1 -# See https://git.fedorahosted.org/cgit/lvm2.git/refs/tags for release tags - -# Fix platform enablement in lvm2 to support ppc64le properly -RUN set -e \ - && for f in config.guess config.sub; do \ - curl -fsSL -o "/usr/local/lvm2/autoconf/$f" "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=$f;hb=HEAD"; \ - done -# "arch.c:78:2: error: #error the arch code needs to know about your machine type" - -# Compile and install lvm2 -RUN cd /usr/local/lvm2 \ - && ./configure \ - --build="$(gcc -print-multiarch)" \ - --enable-static_link \ - && make device-mapper \ - && make install_device-mapper -# See https://git.fedorahosted.org/cgit/lvm2.git/tree/INSTALL - -# Install seccomp: the version shipped in jessie is too old -ENV SECCOMP_VERSION 2.3.1 -RUN set -x \ - && export SECCOMP_PATH="$(mktemp -d)" \ - && curl -fsSL "https://github.com/seccomp/libseccomp/releases/download/v${SECCOMP_VERSION}/libseccomp-${SECCOMP_VERSION}.tar.gz" \ - | tar -xzC "$SECCOMP_PATH" --strip-components=1 \ - && ( \ - cd "$SECCOMP_PATH" \ - && ./configure --prefix=/usr/local \ - && make \ - && make install \ - && ldconfig \ - ) \ - && rm -rf "$SECCOMP_PATH" - - -# Install Go -# NOTE: official ppc64le go binaries weren't available until go 1.6.4 and 1.7.4 -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" \ - | tar -xzC /usr/local - -ENV PATH /go/bin:/usr/local/go/bin:$PATH -ENV GOPATH /go - -# Dependency for golint -ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3 -RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ - && (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) - -# Grab Go's lint tool -ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456 -RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ - && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ - && go install -v github.com/golang/lint/golint - -# Install two versions of the registry. The first is an older version that -# only supports schema1 manifests. The second is a newer version that supports -# both. This allows integration-cli tests to cover push/pull with both schema1 -# and schema2 manifests. -ENV REGISTRY_COMMIT_SCHEMA1 ec87e9b6971d831f0eff752ddb54fb64693e51cd -ENV REGISTRY_COMMIT 47a064d4195a9b56133891bbb13620c3ac83a827 -RUN set -x \ - && export GOPATH="$(mktemp -d)" \ - && git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \ - && (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \ - && GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \ - && (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT_SCHEMA1") \ - && GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \ - && rm -rf "$GOPATH" - -# Install notary and notary-server -ENV NOTARY_VERSION v0.4.2 -RUN set -x \ - && export GOPATH="$(mktemp -d)" \ - && git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \ - && (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION") \ - && GOPATH="$GOPATH/src/github.com/docker/notary/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \ - && GOPATH="$GOPATH/src/github.com/docker/notary/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \ - && rm -rf "$GOPATH" - -# Get the "docker-py" source so we can run their integration tests -ENV DOCKER_PY_COMMIT e2655f658408f9ad1f62abdef3eb6ed43c0cf324 -RUN git clone https://github.com/docker/docker-py.git /docker-py \ - && cd /docker-py \ - && git checkout -q $DOCKER_PY_COMMIT \ - && pip install -r test-requirements.txt - -# Set user.email so crosbymichael's in-container merge commits go smoothly -RUN git config --global user.email 'docker-dummy@example.com' - -# Add an unprivileged user to be used for tests which need it -RUN groupadd -r docker -RUN useradd --create-home --gid docker unprivilegeduser - -VOLUME /var/lib/docker -WORKDIR /go/src/github.com/docker/docker -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux - -# Let us use a .bashrc file -RUN ln -sfv $PWD/.bashrc ~/.bashrc - -# Register Docker's bash completion. -RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker - -# Get useful and necessary Hub images so we can "docker load" locally instead of pulling -COPY contrib/download-frozen-image-v2.sh /go/src/github.com/docker/docker/contrib/ -RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \ - ppc64le/buildpack-deps:jessie@sha256:902bfe4ef1389f94d143d64516dd50a2de75bca2e66d4a44b1d73f63ddf05dda \ - ppc64le/busybox:latest@sha256:38bb82085248d5a3c24bd7a5dc146f2f2c191e189da0441f1c2ca560e3fc6f1b \ - ppc64le/debian:jessie@sha256:412845f51b6ab662afba71bc7a716e20fdb9b84f185d180d4c7504f8a75c4f91 \ - ppc64le/hello-world:latest@sha256:186a40a9a02ca26df0b6c8acdfb8ac2f3ae6678996a838f977e57fac9d963974 -# See also "hack/make/.ensure-frozen-images" (which needs to be updated any time this list is) - -# Install tomlv, vndr, runc, containerd, tini, docker-proxy -# Please edit hack/dockerfile/install-binaries.sh to update them. -COPY hack/dockerfile/binaries-commits /tmp/binaries-commits -COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh -RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy - -# Wrap all commands in the "docker-in-docker" script to allow nested containers -ENTRYPOINT ["hack/dind"] - -# Upload docker source -COPY . /go/src/github.com/docker/docker diff --git a/vendor/github.com/docker/docker/Dockerfile.s390x b/vendor/github.com/docker/docker/Dockerfile.s390x deleted file mode 100644 index ba94bc7..0000000 --- a/vendor/github.com/docker/docker/Dockerfile.s390x +++ /dev/null @@ -1,190 +0,0 @@ -# This file describes the standard way to build Docker on s390x, using docker -# -# Usage: -# -# # Assemble the full dev environment. This is slow the first time. -# docker build -t docker -f Dockerfile.s390x . -# -# # Mount your source in an interactive container for quick testing: -# docker run -v `pwd`:/go/src/github.com/docker/docker --privileged -i -t docker bash -# -# # Run the test suite: -# docker run --privileged docker hack/make.sh test-unit test-integration-cli test-docker-py -# -# Note: AppArmor used to mess with privileged mode, but this is no longer -# the case. Therefore, you don't have to disable it anymore. -# - -FROM s390x/gcc:6.1 - -# Packaged dependencies -RUN apt-get update && apt-get install -y \ - apparmor \ - aufs-tools \ - automake \ - bash-completion \ - btrfs-tools \ - build-essential \ - cmake \ - createrepo \ - curl \ - dpkg-sig \ - git \ - iptables \ - jq \ - net-tools \ - libapparmor-dev \ - libcap-dev \ - libltdl-dev \ - libsqlite3-dev \ - libsystemd-journal-dev \ - libtool \ - mercurial \ - pkg-config \ - python-dev \ - python-mock \ - python-pip \ - python-websocket \ - xfsprogs \ - tar \ - vim-common \ - --no-install-recommends - -# glibc in Debian has a bug specific to s390x that won't be fixed until Debian 8.6 is released -# - https://github.com/docker/docker/issues/24748 -# - https://sourceware.org/git/?p=glibc.git;a=commit;h=890b7a4b33d482b5c768ab47d70758b80227e9bc -# - https://sourceware.org/git/?p=glibc.git;a=commit;h=2e807f29595eb5b1e5d0decc6e356a3562ecc58e -RUN echo 'deb http://httpredir.debian.org/debian jessie-proposed-updates main' >> /etc/apt/sources.list.d/pu.list \ - && apt-get update \ - && apt-get install -y libc6 \ - && rm -rf /var/lib/apt/lists/* - -# Install seccomp: the version shipped in jessie is too old -ENV SECCOMP_VERSION 2.3.1 -RUN set -x \ - && export SECCOMP_PATH="$(mktemp -d)" \ - && curl -fsSL "https://github.com/seccomp/libseccomp/releases/download/v${SECCOMP_VERSION}/libseccomp-${SECCOMP_VERSION}.tar.gz" \ - | tar -xzC "$SECCOMP_PATH" --strip-components=1 \ - && ( \ - cd "$SECCOMP_PATH" \ - && ./configure --prefix=/usr/local \ - && make \ - && make install \ - && ldconfig \ - ) \ - && rm -rf "$SECCOMP_PATH" - -# Get lvm2 source for compiling statically -ENV LVM2_VERSION 2.02.103 -RUN mkdir -p /usr/local/lvm2 \ - && curl -fsSL "https://mirrors.kernel.org/sourceware/lvm2/LVM2.${LVM2_VERSION}.tgz" \ - | tar -xzC /usr/local/lvm2 --strip-components=1 -# See https://git.fedorahosted.org/cgit/lvm2.git/refs/tags for release tags - -# Fix platform enablement in lvm2 to support s390x properly -RUN set -e \ - && for f in config.guess config.sub; do \ - curl -fsSL -o "/usr/local/lvm2/autoconf/$f" "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=$f;hb=HEAD"; \ - done -# "arch.c:78:2: error: #error the arch code needs to know about your machine type" - -# Compile and install lvm2 -RUN cd /usr/local/lvm2 \ - && ./configure \ - --build="$(gcc -print-multiarch)" \ - --enable-static_link \ - && make device-mapper \ - && make install_device-mapper -# See https://git.fedorahosted.org/cgit/lvm2.git/tree/INSTALL - -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" \ - | tar -xzC /usr/local - -ENV PATH /go/bin:/usr/local/go/bin:$PATH -ENV GOPATH /go - -# Dependency for golint -ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3 -RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ - && (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) - -# Grab Go's lint tool -ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456 -RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ - && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ - && go install -v github.com/golang/lint/golint - -# Install two versions of the registry. The first is an older version that -# only supports schema1 manifests. The second is a newer version that supports -# both. This allows integration-cli tests to cover push/pull with both schema1 -# and schema2 manifests. -ENV REGISTRY_COMMIT_SCHEMA1 ec87e9b6971d831f0eff752ddb54fb64693e51cd -ENV REGISTRY_COMMIT 47a064d4195a9b56133891bbb13620c3ac83a827 -RUN set -x \ - && export GOPATH="$(mktemp -d)" \ - && git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution" \ - && (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT") \ - && GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry \ - && (cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT_SCHEMA1") \ - && GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \ - go build -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry \ - && rm -rf "$GOPATH" - -# Install notary and notary-server -ENV NOTARY_VERSION v0.4.2 -RUN set -x \ - && export GOPATH="$(mktemp -d)" \ - && git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary" \ - && (cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION") \ - && GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \ - go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server \ - && GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \ - go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary \ - && rm -rf "$GOPATH" - -# Get the "docker-py" source so we can run their integration tests -ENV DOCKER_PY_COMMIT e2655f658408f9ad1f62abdef3eb6ed43c0cf324 -RUN git clone https://github.com/docker/docker-py.git /docker-py \ - && cd /docker-py \ - && git checkout -q $DOCKER_PY_COMMIT \ - && pip install -r test-requirements.txt - -# Set user.email so crosbymichael's in-container merge commits go smoothly -RUN git config --global user.email 'docker-dummy@example.com' - -# Add an unprivileged user to be used for tests which need it -RUN groupadd -r docker -RUN useradd --create-home --gid docker unprivilegeduser - -VOLUME /var/lib/docker -WORKDIR /go/src/github.com/docker/docker -ENV DOCKER_BUILDTAGS apparmor selinux seccomp - -# Let us use a .bashrc file -RUN ln -sfv $PWD/.bashrc ~/.bashrc - -# Register Docker's bash completion. -RUN ln -sv $PWD/contrib/completion/bash/docker /etc/bash_completion.d/docker - -# Get useful and necessary Hub images so we can "docker load" locally instead of pulling -COPY contrib/download-frozen-image-v2.sh /go/src/github.com/docker/docker/contrib/ -RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \ - s390x/buildpack-deps:jessie@sha256:4d1381224acaca6c4bfe3604de3af6972083a8558a99672cb6989c7541780099 \ - s390x/busybox:latest@sha256:dd61522c983884a66ed72d60301925889028c6d2d5e0220a8fe1d9b4c6a4f01b \ - s390x/debian:jessie@sha256:b74c863400909eff3c5e196cac9bfd1f6333ce47aae6a38398d87d5875da170a \ - s390x/hello-world:latest@sha256:780d80b3a7677c3788c0d5cd9168281320c8d4a6d9183892d8ee5cdd610f5699 -# See also "hack/make/.ensure-frozen-images" (which needs to be updated any time this list is) - -# Install tomlv, vndr, runc, containerd, tini, docker-proxy -# Please edit hack/dockerfile/install-binaries.sh to update them. -COPY hack/dockerfile/binaries-commits /tmp/binaries-commits -COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh -RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy - -# Wrap all commands in the "docker-in-docker" script to allow nested containers -ENTRYPOINT ["hack/dind"] - -# Upload docker source -COPY . /go/src/github.com/docker/docker diff --git a/vendor/github.com/docker/docker/Dockerfile.simple b/vendor/github.com/docker/docker/Dockerfile.simple deleted file mode 100644 index 8eeb3d9..0000000 --- a/vendor/github.com/docker/docker/Dockerfile.simple +++ /dev/null @@ -1,73 +0,0 @@ -# docker build -t docker:simple -f Dockerfile.simple . -# docker run --rm docker:simple hack/make.sh dynbinary -# docker run --rm --privileged docker:simple hack/dind hack/make.sh test-unit -# docker run --rm --privileged -v /var/lib/docker docker:simple hack/dind hack/make.sh dynbinary test-integration-cli - -# This represents the bare minimum required to build and test Docker. - -FROM debian:jessie - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - -# Compile and runtime deps -# https://github.com/docker/docker/blob/master/project/PACKAGERS.md#build-dependencies -# https://github.com/docker/docker/blob/master/project/PACKAGERS.md#runtime-dependencies -RUN apt-get update && apt-get install -y --no-install-recommends \ - btrfs-tools \ - build-essential \ - curl \ - cmake \ - gcc \ - git \ - libapparmor-dev \ - libdevmapper-dev \ - libsqlite3-dev \ - \ - ca-certificates \ - e2fsprogs \ - iptables \ - procps \ - xfsprogs \ - xz-utils \ - \ - aufs-tools \ - vim-common \ - && rm -rf /var/lib/apt/lists/* - -# Install seccomp: the version shipped in trusty is too old -ENV SECCOMP_VERSION 2.3.1 -RUN set -x \ - && export SECCOMP_PATH="$(mktemp -d)" \ - && curl -fsSL "https://github.com/seccomp/libseccomp/releases/download/v${SECCOMP_VERSION}/libseccomp-${SECCOMP_VERSION}.tar.gz" \ - | tar -xzC "$SECCOMP_PATH" --strip-components=1 \ - && ( \ - cd "$SECCOMP_PATH" \ - && ./configure --prefix=/usr/local \ - && make \ - && make install \ - && ldconfig \ - ) \ - && rm -rf "$SECCOMP_PATH" - -# Install Go -# IMPORTANT: If the version of Go is updated, the Windows to Linux CI machines -# will need updating, to avoid errors. Ping #docker-maintainers on IRC -# with a heads-up. -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" \ - | tar -xzC /usr/local -ENV PATH /go/bin:/usr/local/go/bin:$PATH -ENV GOPATH /go -ENV CGO_LDFLAGS -L/lib - -# Install runc, containerd, tini and docker-proxy -# Please edit hack/dockerfile/install-binaries.sh to update them. -COPY hack/dockerfile/binaries-commits /tmp/binaries-commits -COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh -RUN /tmp/install-binaries.sh runc containerd tini proxy - -ENV AUTO_GOPATH 1 -WORKDIR /usr/src/docker -COPY . /usr/src/docker diff --git a/vendor/github.com/docker/docker/Dockerfile.solaris b/vendor/github.com/docker/docker/Dockerfile.solaris deleted file mode 100644 index bb342e5..0000000 --- a/vendor/github.com/docker/docker/Dockerfile.solaris +++ /dev/null @@ -1,20 +0,0 @@ -# Defines an image that hosts a native Docker build environment for Solaris -# TODO: Improve stub - -FROM solaris:latest - -# compile and runtime deps -RUN pkg install --accept \ - git \ - gnu-coreutils \ - gnu-make \ - gnu-tar \ - diagnostic/top \ - golang \ - library/golang/* \ - developer/gcc-* - -ENV GOPATH /go/:/usr/lib/gocode/1.5/ -ENV DOCKER_CROSSPLATFORMS solaris/amd64 -WORKDIR /go/src/github.com/docker/docker -COPY . /go/src/github.com/docker/docker diff --git a/vendor/github.com/docker/docker/Dockerfile.windows b/vendor/github.com/docker/docker/Dockerfile.windows deleted file mode 100644 index 652d072..0000000 --- a/vendor/github.com/docker/docker/Dockerfile.windows +++ /dev/null @@ -1,267 +0,0 @@ -# escape=` - -# ----------------------------------------------------------------------------------------- -# This file describes the standard way to build Docker in a container on Windows -# Server 2016 or Windows 10. -# -# Maintainer: @jhowardmsft -# ----------------------------------------------------------------------------------------- - - -# Prerequisites: -# -------------- -# -# 1. Windows Server 2016 or Windows 10 with all Windows updates applied. The major -# build number must be at least 14393. This can be confirmed, for example, by -# running the following from an elevated PowerShell prompt - this sample output -# is from a fully up to date machine as at mid-November 2016: -# -# >> PS C:\> $(gin).WindowsBuildLabEx -# >> 14393.447.amd64fre.rs1_release_inmarket.161102-0100 -# -# 2. Git for Windows (or another git client) must be installed. https://git-scm.com/download/win. -# -# 3. The machine must be configured to run containers. For example, by following -# the quick start guidance at https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/quick_start or -# https://github.com/docker/labs/blob/master/windows/windows-containers/Setup.md -# -# 4. If building in a Hyper-V VM: For Windows Server 2016 using Windows Server -# containers as the default option, it is recommended you have at least 1GB -# of memory assigned; For Windows 10 where Hyper-V Containers are employed, you -# should have at least 4GB of memory assigned. Note also, to run Hyper-V -# containers in a VM, it is necessary to configure the VM for nested virtualization. - -# ----------------------------------------------------------------------------------------- - - -# Usage: -# ----- -# -# The following steps should be run from an (elevated*) Windows PowerShell prompt. -# -# (*In a default installation of containers on Windows following the quick-start guidance at -# https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/quick_start, -# the docker.exe client must run elevated to be able to connect to the daemon). -# -# 1. Clone the sources from github.com: -# -# >> git clone https://github.com/docker/docker.git C:\go\src\github.com\docker\docker -# >> Cloning into 'C:\go\src\github.com\docker\docker'... -# >> remote: Counting objects: 186216, done. -# >> remote: Compressing objects: 100% (21/21), done. -# >> remote: Total 186216 (delta 5), reused 0 (delta 0), pack-reused 186195 -# >> Receiving objects: 100% (186216/186216), 104.32 MiB | 8.18 MiB/s, done. -# >> Resolving deltas: 100% (123139/123139), done. -# >> Checking connectivity... done. -# >> Checking out files: 100% (3912/3912), done. -# >> PS C:\> -# -# -# 2. Change directory to the cloned docker sources: -# -# >> cd C:\go\src\github.com\docker\docker -# -# -# 3. Build a docker image with the components required to build the docker binaries from source -# by running one of the following: -# -# >> docker build -t nativebuildimage -f Dockerfile.windows . -# >> docker build -t nativebuildimage -f Dockerfile.windows -m 2GB . (if using Hyper-V containers) -# -# -# 4. Build the docker executable binaries by running one of the following: -# -# >> docker run --name binaries nativebuildimage hack\make.ps1 -Binary -# >> docker run --name binaries -m 2GB nativebuildimage hack\make.ps1 -Binary (if using Hyper-V containers) -# -# -# 5. Copy the binaries out of the container, replacing HostPath with an appropriate destination -# folder on the host system where you want the binaries to be located. -# -# >> docker cp binaries:C:\go\src\github.com\docker\docker\bundles\docker.exe C:\HostPath\docker.exe -# >> docker cp binaries:C:\go\src\github.com\docker\docker\bundles\dockerd.exe C:\HostPath\dockerd.exe -# -# -# 6. (Optional) Remove the interim container holding the built executable binaries: -# -# >> docker rm binaries -# -# -# 7. (Optional) Remove the image used for the container in which the executable -# binaries are build. Tip - it may be useful to keep this image around if you need to -# build multiple times. Then you can take advantage of the builder cache to have an -# image which has all the components required to build the binaries already installed. -# -# >> docker rmi nativebuildimage -# - -# ----------------------------------------------------------------------------------------- - - -# The validation tests can either run in a container, or directly on the host. To run in a -# container, ensure you have created the nativebuildimage above. Then run one of the -# following from an (elevated) Windows PowerShell prompt: -# -# >> docker run --rm nativebuildimage hack\make.ps1 -DCO -PkgImports -GoFormat -# >> docker run --rm -m 2GB nativebuildimage hack\make.ps1 -DCO -PkgImports -GoFormat (if using Hyper-V containers) - -# To run the validation tests on the host, from the root of the repository, run the -# following from a Windows PowerShell prompt (elevation is not required): (Note Go -# must be installed to run these tests) -# -# >> hack\make.ps1 -DCO -PkgImports -GoFormat - -# ----------------------------------------------------------------------------------------- - - -# To run unit tests, ensure you have created the nativebuildimage above. Then run one of -# the following from an (elevated) Windows PowerShell prompt: -# -# >> docker run --rm nativebuildimage hack\make.ps1 -TestUnit -# >> docker run --rm -m 2GB nativebuildimage hack\make.ps1 -TestUnit (if using Hyper-V containers) - - -# ----------------------------------------------------------------------------------------- - - -# To run all tests and binary build, ensure you have created the nativebuildimage above. Then -# run one of the following from an (elevated) Windows PowerShell prompt: -# -# >> docker run nativebuildimage hack\make.ps1 -All -# >> docker run -m 2GB nativebuildimage hack\make.ps1 -All (if using Hyper-V containers) - -# ----------------------------------------------------------------------------------------- - - -# Important notes: -# --------------- -# -# Don't attempt to use a bind-mount to pass a local directory as the bundles target -# directory. It does not work (golang attempts for follow a mapped folder incorrectly). -# Instead, use docker cp as per the example. -# -# go.zip is not removed from the image as it is used by the Windows CI servers -# to ensure the host and image are running consistent versions of go. -# -# Nanoserver support is a work in progress. Although the image will build if the -# FROM statement is updated, it will not work when running autogen through hack\make.ps1. -# It is suspected that the required GCC utilities (eg gcc, windres, windmc) silently -# quit due to the use of console hooks which are not available. -# -# The docker integration tests do not currently run in a container on Windows, predominantly -# due to Windows not supporting privileged mode, so anything using a volume would fail. -# They (along with the rest of the docker CI suite) can be run using -# https://github.com/jhowardmsft/docker-w2wCIScripts/blob/master/runCI/Invoke-DockerCI.ps1. -# -# ----------------------------------------------------------------------------------------- - - -# The number of build steps below are explicitly minimised to improve performance. -FROM microsoft/windowsservercore - -# Use PowerShell as the default shell -SHELL ["powershell", "-command"] - -# Environment variable notes: -# - GO_VERSION must be consistent with 'Dockerfile' used by Linux. -# - FROM_DOCKERFILE is used for detection of building within a container. -ENV GO_VERSION=1.7.5 ` - GIT_VERSION=2.11.0 ` - GOPATH=C:\go ` - FROM_DOCKERFILE=1 - -RUN ` - $ErrorActionPreference = 'Stop'; ` - $ProgressPreference = 'SilentlyContinue'; ` - ` - Function Test-Nano() { ` - $EditionId = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'EditionID').EditionId; ` - return (($EditionId -eq 'ServerStandardNano') -or ($EditionId -eq 'ServerDataCenterNano') -or ($EditionId -eq 'NanoServer')); ` - }` - ` - Function Download-File([string] $source, [string] $target) { ` - if (Test-Nano) { ` - $handler = New-Object System.Net.Http.HttpClientHandler; ` - $client = New-Object System.Net.Http.HttpClient($handler); ` - $client.Timeout = New-Object System.TimeSpan(0, 30, 0); ` - $cancelTokenSource = [System.Threading.CancellationTokenSource]::new(); ` - $responseMsg = $client.GetAsync([System.Uri]::new($source), $cancelTokenSource.Token); ` - $responseMsg.Wait(); ` - if (!$responseMsg.IsCanceled) { ` - $response = $responseMsg.Result; ` - if ($response.IsSuccessStatusCode) { ` - $downloadedFileStream = [System.IO.FileStream]::new($target, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write); ` - $copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream); ` - $copyStreamOp.Wait(); ` - $downloadedFileStream.Close(); ` - if ($copyStreamOp.Exception -ne $null) { throw $copyStreamOp.Exception } ` - } ` - } else { ` - Throw ("Failed to download " + $source) ` - }` - } else { ` - $webClient = New-Object System.Net.WebClient; ` - $webClient.DownloadFile($source, $target); ` - } ` - } ` - ` - setx /M PATH $('C:\git\bin;C:\git\usr\bin;'+$Env:PATH+';C:\gcc\bin;C:\go\bin'); ` - ` - Write-Host INFO: Downloading git...; ` - $location='https://github.com/git-for-windows/git/releases/download/v'+$env:GIT_VERSION+'.windows.1/PortableGit-'+$env:GIT_VERSION+'-64-bit.7z.exe'; ` - Download-File $location C:\gitsetup.7z.exe; ` - ` - Write-Host INFO: Downloading go...; ` - Download-File $('https://golang.org/dl/go'+$Env:GO_VERSION+'.windows-amd64.zip') C:\go.zip; ` - ` - Write-Host INFO: Downloading compiler 1 of 3...; ` - Download-File https://raw.githubusercontent.com/jhowardmsft/docker-tdmgcc/master/gcc.zip C:\gcc.zip; ` - ` - Write-Host INFO: Downloading compiler 2 of 3...; ` - Download-File https://raw.githubusercontent.com/jhowardmsft/docker-tdmgcc/master/runtime.zip C:\runtime.zip; ` - ` - Write-Host INFO: Downloading compiler 3 of 3...; ` - Download-File https://raw.githubusercontent.com/jhowardmsft/docker-tdmgcc/master/binutils.zip C:\binutils.zip; ` - ` - Write-Host INFO: Installing PS7Zip package...; ` - Install-Package PS7Zip -Force | Out-Null; ` - Write-Host INFO: Importing PS7Zip...; ` - Import-Module PS7Zip -Force; ` - New-Item C:\git -ItemType Directory | Out-Null ; ` - cd C:\git; ` - Write-Host INFO: Extracting git...; ` - Expand-7Zip C:\gitsetup.7z.exe | Out-Null; ` - cd C:\; ` - ` - Write-Host INFO: Expanding go...; ` - Expand-Archive C:\go.zip -DestinationPath C:\; ` - ` - Write-Host INFO: Expanding compiler 1 of 3...; ` - Expand-Archive C:\gcc.zip -DestinationPath C:\gcc -Force; ` - Write-Host INFO: Expanding compiler 2 of 3...; ` - Expand-Archive C:\runtime.zip -DestinationPath C:\gcc -Force; ` - Write-Host INFO: Expanding compiler 3 of 3...; ` - Expand-Archive C:\binutils.zip -DestinationPath C:\gcc -Force; ` - ` - Write-Host INFO: Removing downloaded files...; ` - Remove-Item C:\gcc.zip; ` - Remove-Item C:\runtime.zip; ` - Remove-Item C:\binutils.zip; ` - Remove-Item C:\gitsetup.7z.exe; ` - ` - Write-Host INFO: Creating source directory...; ` - New-Item -ItemType Directory -Path C:\go\src\github.com\docker\docker | Out-Null; ` - ` - Write-Host INFO: Configuring git core.autocrlf...; ` - C:\git\bin\git config --global core.autocrlf true; ` - ` - Write-Host INFO: Completed - -# Make PowerShell the default entrypoint -ENTRYPOINT ["powershell.exe"] - -# Set the working directory to the location of the sources -WORKDIR C:\go\src\github.com\docker\docker - -# Copy the sources into the container -COPY . . diff --git a/vendor/github.com/docker/docker/LICENSE b/vendor/github.com/docker/docker/LICENSE deleted file mode 100644 index 8f3fee6..0000000 --- a/vendor/github.com/docker/docker/LICENSE +++ /dev/null @@ -1,191 +0,0 @@ - - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - Copyright 2013-2016 Docker, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/docker/docker/MAINTAINERS b/vendor/github.com/docker/docker/MAINTAINERS deleted file mode 100644 index 39bb8c1..0000000 --- a/vendor/github.com/docker/docker/MAINTAINERS +++ /dev/null @@ -1,376 +0,0 @@ -# Docker maintainers file -# -# This file describes who runs the docker/docker project and how. -# This is a living document - if you see something out of date or missing, speak up! -# -# It is structured to be consumable by both humans and programs. -# To extract its contents programmatically, use any TOML-compliant -# parser. -# -# This file is compiled into the MAINTAINERS file in docker/opensource. -# -[Org] - - [Org."Core maintainers"] - - # The Core maintainers are the ghostbusters of the project: when there's a problem others - # can't solve, they show up and fix it with bizarre devices and weaponry. - # They have final say on technical implementation and coding style. - # They are ultimately responsible for quality in all its forms: usability polish, - # bugfixes, performance, stability, etc. When ownership can cleanly be passed to - # a subsystem, they are responsible for doing so and holding the - # subsystem maintainers accountable. If ownership is unclear, they are the de facto owners. - - # For each release (including minor releases), a "release captain" is assigned from the - # pool of core maintainers. Rotation is encouraged across all maintainers, to ensure - # the release process is clear and up-to-date. - - people = [ - "aaronlehmann", - "akihirosuda", - "aluzzardi", - "anusha", - "coolljt0725", - "cpuguy83", - "crosbymichael", - "dnephin", - "duglin", - "estesp", - "icecrime", - "jhowardmsft", - "justincormack", - "lk4d4", - "mavenugo", - "mhbauer", - "mlaventure", - "mrjana", - "runcom", - "stevvooe", - "tianon", - "tibor", - "tonistiigi", - "unclejack", - "vdemeester", - "vieux" - ] - - [Org."Docs maintainers"] - - # TODO Describe the docs maintainers role. - - people = [ - "jamtur01", - "misty", - "sven", - "thajeztah" - ] - - [Org.Curators] - - # The curators help ensure that incoming issues and pull requests are properly triaged and - # that our various contribution and reviewing processes are respected. With their knowledge of - # the repository activity, they can also guide contributors to relevant material or - # discussions. - # - # They are neither code nor docs reviewers, so they are never expected to merge. They can - # however: - # - close an issue or pull request when it's an exact duplicate - # - close an issue or pull request when it's inappropriate or off-topic - - people = [ - "aboch", - "andrewhsu", - "ehazlett", - "mgoelzer", - "programmerq", - "thajeztah" - ] - - [Org.Alumni] - - # This list contains maintainers that are no longer active on the project. - # It is thanks to these people that the project has become what it is today. - # Thank you! - - people = [ - # David Calavera contributed many features to Docker, such as an improved - # event system, dynamic configuration reloading, volume plugins, fancy - # new templating options, and an external client credential store. As a - # maintainer, David was release captain for Docker 1.8, and competing - # with Jess Frazelle to be "top dream killer". - # David is now doing amazing stuff as CTO for https://www.netlify.com, - # and tweets as @calavera. - "calavera", - - # As a maintainer, Erik was responsible for the "builder", and - # started the first designs for the new networking model in - # Docker. Erik is now working on all kinds of plugins for Docker - # (https://github.com/contiv) and various open source projects - # in his own repository https://github.com/erikh. You may - # still stumble into him in our issue tracker, or on IRC. - "erikh", - - # Jessica Frazelle, also known as the "Keyser Söze of containers", - # runs *everything* in containers. She started contributing to - # Docker with a (fun fun) change involving both iptables and regular - # expressions (coz, YOLO!) on July 10, 2014 - # https://github.com/docker/docker/pull/6950/commits/f3a68ffa390fb851115c77783fa4031f1d3b2995. - # Jess was Release Captain for Docker 1.4, 1.6 and 1.7, and contributed - # many features and improvement, among which "seccomp profiles" (making - # containers a lot more secure). Besides being a maintainer, she - # set up the CI infrastructure for the project, giving everyone - # something to shout at if a PR failed ("noooo Janky!"). - # Jess is currently working on the DCOS security team at Mesosphere, - # and contributing to various open source projects. - # Be sure you don't miss her talks at a conference near you (a must-see), - # read her blog at https://blog.jessfraz.com (a must-read), and - # check out her open source projects on GitHub https://github.com/jessfraz (a must-try). - "jessfraz", - - # As a docs maintainer, Mary Anthony contributed greatly to the Docker - # docs. She wrote the Docker Contributor Guide and Getting Started - # Guides. She helped create a doc build system independent of - # docker/docker project, and implemented a new docs.docker.com theme and - # nav for 2015 Dockercon. Fun fact: the most inherited layer in DockerHub - # public repositories was originally referenced in - # maryatdocker/docker-whale back in May 2015. - "moxiegirl", - - # Vincent "vbatts!" Batts made his first contribution to the project - # in November 2013, to become a maintainer a few months later, on - # May 10, 2014 (https://github.com/docker/docker/commit/d6e666a87a01a5634c250358a94c814bf26cb778). - # As a maintainer, Vincent made important contributions to core elements - # of Docker, such as "distribution" (tarsum) and graphdrivers (btrfs, devicemapper). - # He also contributed the "tar-split" library, an important element - # for the content-addressable store. - # Vincent is currently a member of the Open Containers Initiative - # Technical Oversight Board (TOB), besides his work at Red Hat and - # Project Atomic. You can still find him regularly hanging out in - # our repository and the #docker-dev and #docker-maintainers IRC channels - # for a chat, as he's always a lot of fun. - "vbatts", - - # Vishnu became a maintainer to help out on the daemon codebase and - # libcontainer integration. He's currently involved in the - # Open Containers Initiative, working on the specifications, - # besides his work on cAdvisor and Kubernetes for Google. - "vishh" - ] - -[people] - -# A reference list of all people associated with the project. -# All other sections should refer to people by their canonical key -# in the people section. - - # ADD YOURSELF HERE IN ALPHABETICAL ORDER - - [people.aaronlehmann] - Name = "Aaron Lehmann" - Email = "aaron.lehmann@docker.com" - GitHub = "aaronlehmann" - - [people.aboch] - Name = "Alessandro Boch" - Email = "aboch@docker.com" - GitHub = "aboch" - - [people.akihirosuda] - Name = "Akihiro Suda" - Email = "suda.akihiro@lab.ntt.co.jp" - GitHub = "AkihiroSuda" - - [people.aluzzardi] - Name = "Andrea Luzzardi" - Email = "al@docker.com" - GitHub = "aluzzardi" - - [people.andrewhsu] - Name = "Andrew Hsu" - Email = "andrewhsu@docker.com" - GitHub = "andrewhsu" - - [people.anusha] - Name = "Anusha Ragunathan" - Email = "anusha@docker.com" - GitHub = "anusha-ragunathan" - - [people.calavera] - Name = "David Calavera" - Email = "david.calavera@gmail.com" - GitHub = "calavera" - - [people.coolljt0725] - Name = "Lei Jitang" - Email = "leijitang@huawei.com" - GitHub = "coolljt0725" - - [people.cpuguy83] - Name = "Brian Goff" - Email = "cpuguy83@gmail.com" - Github = "cpuguy83" - - [people.crosbymichael] - Name = "Michael Crosby" - Email = "crosbymichael@gmail.com" - GitHub = "crosbymichael" - - [people.dnephin] - Name = "Daniel Nephin" - Email = "dnephin@gmail.com" - GitHub = "dnephin" - - [people.duglin] - Name = "Doug Davis" - Email = "dug@us.ibm.com" - GitHub = "duglin" - - [people.ehazlett] - Name = "Evan Hazlett" - Email = "ejhazlett@gmail.com" - GitHub = "ehazlett" - - [people.erikh] - Name = "Erik Hollensbe" - Email = "erik@docker.com" - GitHub = "erikh" - - [people.estesp] - Name = "Phil Estes" - Email = "estesp@linux.vnet.ibm.com" - GitHub = "estesp" - - [people.icecrime] - Name = "Arnaud Porterie" - Email = "arnaud@docker.com" - GitHub = "icecrime" - - [people.jamtur01] - Name = "James Turnbull" - Email = "james@lovedthanlost.net" - GitHub = "jamtur01" - - [people.jhowardmsft] - Name = "John Howard" - Email = "jhoward@microsoft.com" - GitHub = "jhowardmsft" - - [people.jessfraz] - Name = "Jessie Frazelle" - Email = "jess@linux.com" - GitHub = "jessfraz" - - [people.justincormack] - Name = "Justin Cormack" - Email = "justin.cormack@docker.com" - GitHub = "justincormack" - - [people.lk4d4] - Name = "Alexander Morozov" - Email = "lk4d4@docker.com" - GitHub = "lk4d4" - - [people.mavenugo] - Name = "Madhu Venugopal" - Email = "madhu@docker.com" - GitHub = "mavenugo" - - [people.mgoelzer] - Name = "Mike Goelzer" - Email = "mike.goelzer@docker.com" - GitHub = "mgoelzer" - - [people.mhbauer] - Name = "Morgan Bauer" - Email = "mbauer@us.ibm.com" - GitHub = "mhbauer" - - [people.misty] - Name = "Misty Stanley-Jones" - Email = "misty@docker.com" - GitHub = "mstanleyjones" - - [people.mlaventure] - Name = "Kenfe-Mickaël Laventure" - Email = "mickael.laventure@docker.com" - GitHub = "mlaventure" - - [people.moxiegirl] - Name = "Mary Anthony" - Email = "mary.anthony@docker.com" - GitHub = "moxiegirl" - - [people.mrjana] - Name = "Jana Radhakrishnan" - Email = "mrjana@docker.com" - GitHub = "mrjana" - - [people.programmerq] - Name = "Jeff Anderson" - Email = "jeff@docker.com" - GitHub = "programmerq" - - [people.runcom] - Name = "Antonio Murdaca" - Email = "runcom@redhat.com" - GitHub = "runcom" - - [people.shykes] - Name = "Solomon Hykes" - Email = "solomon@docker.com" - GitHub = "shykes" - - [people.stevvooe] - Name = "Stephen Day" - Email = "stephen.day@docker.com" - GitHub = "stevvooe" - - [people.sven] - Name = "Sven Dowideit" - Email = "SvenDowideit@home.org.au" - GitHub = "SvenDowideit" - - [people.thajeztah] - Name = "Sebastiaan van Stijn" - Email = "github@gone.nl" - GitHub = "thaJeztah" - - [people.tianon] - Name = "Tianon Gravi" - Email = "admwiggin@gmail.com" - GitHub = "tianon" - - [people.tibor] - Name = "Tibor Vass" - Email = "tibor@docker.com" - GitHub = "tiborvass" - - [people.tonistiigi] - Name = "Tõnis Tiigi" - Email = "tonis@docker.com" - GitHub = "tonistiigi" - - [people.unclejack] - Name = "Cristian Staretu" - Email = "cristian.staretu@gmail.com" - GitHub = "unclejack" - - [people.vbatts] - Name = "Vincent Batts" - Email = "vbatts@redhat.com" - GitHub = "vbatts" - - [people.vdemeester] - Name = "Vincent Demeester" - Email = "vincent@sbr.pm" - GitHub = "vdemeester" - - [people.vieux] - Name = "Victor Vieux" - Email = "vieux@docker.com" - GitHub = "vieux" - - [people.vishh] - Name = "Vishnu Kannan" - Email = "vishnuk@google.com" - GitHub = "vishh" diff --git a/vendor/github.com/docker/docker/Makefile b/vendor/github.com/docker/docker/Makefile deleted file mode 100644 index 81bde6b..0000000 --- a/vendor/github.com/docker/docker/Makefile +++ /dev/null @@ -1,147 +0,0 @@ -.PHONY: all binary build cross deb help init-go-pkg-cache install manpages rpm run shell test test-docker-py test-integration-cli test-unit tgz validate win - -# set the graph driver as the current graphdriver if not set -DOCKER_GRAPHDRIVER := $(if $(DOCKER_GRAPHDRIVER),$(DOCKER_GRAPHDRIVER),$(shell docker info 2>&1 | grep "Storage Driver" | sed 's/.*: //')) - -# get OS/Arch of docker engine -DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH:-$$DOCKER_CLIENT_OSARCH}') -DOCKERFILE := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKERFILE}') - -# env vars passed through directly to Docker's build scripts -# to allow things like `make KEEPBUNDLE=1 binary` easily -# `project/PACKAGERS.md` have some limited documentation of some of these -DOCKER_ENVS := \ - -e BUILD_APT_MIRROR \ - -e BUILDFLAGS \ - -e KEEPBUNDLE \ - -e DOCKER_BUILD_ARGS \ - -e DOCKER_BUILD_GOGC \ - -e DOCKER_BUILD_PKGS \ - -e DOCKER_DEBUG \ - -e DOCKER_EXPERIMENTAL \ - -e DOCKER_GITCOMMIT \ - -e DOCKER_GRAPHDRIVER=$(DOCKER_GRAPHDRIVER) \ - -e DOCKER_INCREMENTAL_BINARY \ - -e DOCKER_PORT \ - -e DOCKER_REMAP_ROOT \ - -e DOCKER_STORAGE_OPTS \ - -e DOCKER_USERLANDPROXY \ - -e TESTDIRS \ - -e TESTFLAGS \ - -e TIMEOUT \ - -e HTTP_PROXY \ - -e HTTPS_PROXY \ - -e NO_PROXY \ - -e http_proxy \ - -e https_proxy \ - -e no_proxy -# note: we _cannot_ add "-e DOCKER_BUILDTAGS" here because even if it's unset in the shell, that would shadow the "ENV DOCKER_BUILDTAGS" set in our Dockerfile, which is very important for our official builds - -# to allow `make BIND_DIR=. shell` or `make BIND_DIR= test` -# (default to no bind mount if DOCKER_HOST is set) -# note: BINDDIR is supported for backwards-compatibility here -BIND_DIR := $(if $(BINDDIR),$(BINDDIR),$(if $(DOCKER_HOST),,bundles)) -DOCKER_MOUNT := $(if $(BIND_DIR),-v "$(CURDIR)/$(BIND_DIR):/go/src/github.com/docker/docker/$(BIND_DIR)") - -# This allows the test suite to be able to run without worrying about the underlying fs used by the container running the daemon (e.g. aufs-on-aufs), so long as the host running the container is running a supported fs. -# The volume will be cleaned up when the container is removed due to `--rm`. -# Note that `BIND_DIR` will already be set to `bundles` if `DOCKER_HOST` is not set (see above BIND_DIR line), in such case this will do nothing since `DOCKER_MOUNT` will already be set. -DOCKER_MOUNT := $(if $(DOCKER_MOUNT),$(DOCKER_MOUNT),-v /go/src/github.com/docker/docker/bundles) - -# enable .go-pkg-cache if DOCKER_INCREMENTAL_BINARY and DOCKER_MOUNT (i.e.DOCKER_HOST) are set -PKGCACHE_DIR := $(if $(PKGCACHE_DIR),$(PKGCACHE_DIR),.go-pkg-cache) -PKGCACHE_MAP := gopath:/go/pkg goroot-linux_amd64_netgo:/usr/local/go/pkg/linux_amd64_netgo -DOCKER_MOUNT := $(if $(DOCKER_INCREMENTAL_BINARY),$(DOCKER_MOUNT) $(shell echo $(PKGCACHE_MAP) | sed -E 's@([^ ]*)@-v "$(CURDIR)/$(PKGCACHE_DIR)/\1"@g'),$(DOCKER_MOUNT)) - -GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) -GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g") -DOCKER_IMAGE := docker-dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN)) -DOCKER_PORT_FORWARD := $(if $(DOCKER_PORT),-p "$(DOCKER_PORT)",) - -DOCKER_FLAGS := docker run --rm -i --privileged $(DOCKER_ENVS) $(DOCKER_MOUNT) $(DOCKER_PORT_FORWARD) -BUILD_APT_MIRROR := $(if $(DOCKER_BUILD_APT_MIRROR),--build-arg APT_MIRROR=$(DOCKER_BUILD_APT_MIRROR)) -export BUILD_APT_MIRROR - -# if this session isn't interactive, then we don't want to allocate a -# TTY, which would fail, but if it is interactive, we do want to attach -# so that the user can send e.g. ^C through. -INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0) -ifeq ($(INTERACTIVE), 1) - DOCKER_FLAGS += -t -endif - -DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)" - -default: binary - -all: build ## validate all checks, build linux binaries, run all tests\ncross build non-linux binaries and generate archives - $(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh' - -binary: build ## build the linux binaries - $(DOCKER_RUN_DOCKER) hack/make.sh binary - -build: bundles init-go-pkg-cache - docker build ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" . - -bundles: - mkdir bundles - -cross: build ## cross build the binaries for darwin, freebsd and\nwindows - $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary binary cross - -deb: build ## build the deb packages - $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary build-deb - - -help: ## this help - @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) - -init-go-pkg-cache: - mkdir -p $(shell echo $(PKGCACHE_MAP) | sed -E 's@([^: ]*):[^ ]*@$(PKGCACHE_DIR)/\1@g') - -install: ## install the linux binaries - KEEPBUNDLE=1 hack/make.sh install-binary - -manpages: ## Generate man pages from go source and markdown - docker build -t docker-manpage-dev -f "man/$(DOCKERFILE)" ./man - docker run --rm \ - -v $(PWD):/go/src/github.com/docker/docker/ \ - docker-manpage-dev - -rpm: build ## build the rpm packages - $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary build-rpm - -run: build ## run the docker daemon in a container - $(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run" - -shell: build ## start a shell inside the build env - $(DOCKER_RUN_DOCKER) bash - -test: build ## run the unit, integration and docker-py tests - $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary cross test-unit test-integration-cli test-docker-py - -test-docker-py: build ## run the docker-py tests - $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-docker-py - -test-integration-cli: build ## run the integration tests - $(DOCKER_RUN_DOCKER) hack/make.sh build-integration-test-binary dynbinary test-integration-cli - -test-unit: build ## run the unit tests - $(DOCKER_RUN_DOCKER) hack/make.sh test-unit - -tgz: build ## build the archives (.zip on windows and .tgz\notherwise) containing the binaries - $(DOCKER_RUN_DOCKER) hack/make.sh dynbinary binary cross tgz - -validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor - $(DOCKER_RUN_DOCKER) hack/validate/all - -win: build ## cross build the binary for windows - $(DOCKER_RUN_DOCKER) hack/make.sh win - -.PHONY: swagger-gen -swagger-gen: - docker run --rm -v $(PWD):/go/src/github.com/docker/docker \ - -w /go/src/github.com/docker/docker \ - --entrypoint hack/generate-swagger-api.sh \ - -e GOPATH=/go \ - quay.io/goswagger/swagger:0.7.4 diff --git a/vendor/github.com/docker/docker/NOTICE b/vendor/github.com/docker/docker/NOTICE deleted file mode 100644 index 8a37c1c..0000000 --- a/vendor/github.com/docker/docker/NOTICE +++ /dev/null @@ -1,19 +0,0 @@ -Docker -Copyright 2012-2016 Docker, Inc. - -This product includes software developed at Docker, Inc. (https://www.docker.com). - -This product contains software (https://github.com/kr/pty) developed -by Keith Rarick, licensed under the MIT License. - -The following is courtesy of our legal counsel: - - -Use and transfer of Docker may be subject to certain restrictions by the -United States and other governments. -It is your responsibility to ensure that your use and/or transfer does not -violate applicable laws. - -For more information, please see https://www.bis.doc.gov - -See also https://www.apache.org/dev/crypto.html and/or seek legal counsel. diff --git a/vendor/github.com/docker/docker/README.md b/vendor/github.com/docker/docker/README.md deleted file mode 100644 index 0b33bdc..0000000 --- a/vendor/github.com/docker/docker/README.md +++ /dev/null @@ -1,304 +0,0 @@ -Docker: the container engine [![Release](https://img.shields.io/github/release/docker/docker.svg)](https://github.com/docker/docker/releases/latest) -============================ - -Docker is an open source project to pack, ship and run any application -as a lightweight container. - -Docker containers are both *hardware-agnostic* and *platform-agnostic*. -This means they can run anywhere, from your laptop to the largest -cloud compute instance and everything in between - and they don't require -you to use a particular language, framework or packaging system. That -makes them great building blocks for deploying and scaling web apps, -databases, and backend services without depending on a particular stack -or provider. - -Docker began as an open-source implementation of the deployment engine which -powered [dotCloud](http://web.archive.org/web/20130530031104/https://www.dotcloud.com/), -a popular Platform-as-a-Service. It benefits directly from the experience -accumulated over several years of large-scale operation and support of hundreds -of thousands of applications and databases. - -![Docker logo](docs/static_files/docker-logo-compressed.png "Docker") - -## Security Disclosure - -Security is very important to us. If you have any issue regarding security, -please disclose the information responsibly by sending an email to -security@docker.com and not by creating a GitHub issue. - -## Better than VMs - -A common method for distributing applications and sandboxing their -execution is to use virtual machines, or VMs. Typical VM formats are -VMware's vmdk, Oracle VirtualBox's vdi, and Amazon EC2's ami. In theory -these formats should allow every developer to automatically package -their application into a "machine" for easy distribution and deployment. -In practice, that almost never happens, for a few reasons: - - * *Size*: VMs are very large which makes them impractical to store - and transfer. - * *Performance*: running VMs consumes significant CPU and memory, - which makes them impractical in many scenarios, for example local - development of multi-tier applications, and large-scale deployment - of cpu and memory-intensive applications on large numbers of - machines. - * *Portability*: competing VM environments don't play well with each - other. Although conversion tools do exist, they are limited and - add even more overhead. - * *Hardware-centric*: VMs were designed with machine operators in - mind, not software developers. As a result, they offer very - limited tooling for what developers need most: building, testing - and running their software. For example, VMs offer no facilities - for application versioning, monitoring, configuration, logging or - service discovery. - -By contrast, Docker relies on a different sandboxing method known as -*containerization*. Unlike traditional virtualization, containerization -takes place at the kernel level. Most modern operating system kernels -now support the primitives necessary for containerization, including -Linux with [openvz](https://openvz.org), -[vserver](http://linux-vserver.org) and more recently -[lxc](https://linuxcontainers.org/), Solaris with -[zones](https://docs.oracle.com/cd/E26502_01/html/E29024/preface-1.html#scrolltoc), -and FreeBSD with -[Jails](https://www.freebsd.org/doc/handbook/jails.html). - -Docker builds on top of these low-level primitives to offer developers a -portable format and runtime environment that solves all four problems. -Docker containers are small (and their transfer can be optimized with -layers), they have basically zero memory and cpu overhead, they are -completely portable, and are designed from the ground up with an -application-centric design. - -Perhaps best of all, because Docker operates at the OS level, it can still be -run inside a VM! - -## Plays well with others - -Docker does not require you to buy into a particular programming -language, framework, packaging system, or configuration language. - -Is your application a Unix process? Does it use files, tcp connections, -environment variables, standard Unix streams and command-line arguments -as inputs and outputs? Then Docker can run it. - -Can your application's build be expressed as a sequence of such -commands? Then Docker can build it. - -## Escape dependency hell - -A common problem for developers is the difficulty of managing all -their application's dependencies in a simple and automated way. - -This is usually difficult for several reasons: - - * *Cross-platform dependencies*. Modern applications often depend on - a combination of system libraries and binaries, language-specific - packages, framework-specific modules, internal components - developed for another project, etc. These dependencies live in - different "worlds" and require different tools - these tools - typically don't work well with each other, requiring awkward - custom integrations. - - * *Conflicting dependencies*. Different applications may depend on - different versions of the same dependency. Packaging tools handle - these situations with various degrees of ease - but they all - handle them in different and incompatible ways, which again forces - the developer to do extra work. - - * *Custom dependencies*. A developer may need to prepare a custom - version of their application's dependency. Some packaging systems - can handle custom versions of a dependency, others can't - and all - of them handle it differently. - - -Docker solves the problem of dependency hell by giving the developer a simple -way to express *all* their application's dependencies in one place, while -streamlining the process of assembling them. If this makes you think of -[XKCD 927](https://xkcd.com/927/), don't worry. Docker doesn't -*replace* your favorite packaging systems. It simply orchestrates -their use in a simple and repeatable way. How does it do that? With -layers. - -Docker defines a build as running a sequence of Unix commands, one -after the other, in the same container. Build commands modify the -contents of the container (usually by installing new files on the -filesystem), the next command modifies it some more, etc. Since each -build command inherits the result of the previous commands, the -*order* in which the commands are executed expresses *dependencies*. - -Here's a typical Docker build process: - -```bash -FROM ubuntu:12.04 -RUN apt-get update && apt-get install -y python python-pip curl -RUN curl -sSL https://github.com/shykes/helloflask/archive/master.tar.gz | tar -xzv -RUN cd helloflask-master && pip install -r requirements.txt -``` - -Note that Docker doesn't care *how* dependencies are built - as long -as they can be built by running a Unix command in a container. - - -Getting started -=============== - -Docker can be installed either on your computer for building applications or -on servers for running them. To get started, [check out the installation -instructions in the -documentation](https://docs.docker.com/engine/installation/). - -Usage examples -============== - -Docker can be used to run short-lived commands, long-running daemons -(app servers, databases, etc.), interactive shell sessions, etc. - -You can find a [list of real-world -examples](https://docs.docker.com/engine/examples/) in the -documentation. - -Under the hood --------------- - -Under the hood, Docker is built on the following components: - -* The - [cgroups](https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt) - and - [namespaces](http://man7.org/linux/man-pages/man7/namespaces.7.html) - capabilities of the Linux kernel -* The [Go](https://golang.org) programming language -* The [Docker Image Specification](https://github.com/docker/docker/blob/master/image/spec/v1.md) -* The [Libcontainer Specification](https://github.com/opencontainers/runc/blob/master/libcontainer/SPEC.md) - -Contributing to Docker [![GoDoc](https://godoc.org/github.com/docker/docker?status.svg)](https://godoc.org/github.com/docker/docker) -====================== - -| **Master** (Linux) | **Experimental** (Linux) | **Windows** | **FreeBSD** | -|------------------|----------------------|---------|---------| -| [![Jenkins Build Status](https://jenkins.dockerproject.org/view/Docker/job/Docker%20Master/badge/icon)](https://jenkins.dockerproject.org/view/Docker/job/Docker%20Master/) | [![Jenkins Build Status](https://jenkins.dockerproject.org/view/Docker/job/Docker%20Master%20%28experimental%29/badge/icon)](https://jenkins.dockerproject.org/view/Docker/job/Docker%20Master%20%28experimental%29/) | [![Build Status](http://jenkins.dockerproject.org/job/Docker%20Master%20(windows)/badge/icon)](http://jenkins.dockerproject.org/job/Docker%20Master%20(windows)/) | [![Build Status](http://jenkins.dockerproject.org/job/Docker%20Master%20(freebsd)/badge/icon)](http://jenkins.dockerproject.org/job/Docker%20Master%20(freebsd)/) | - -Want to hack on Docker? Awesome! We have [instructions to help you get -started contributing code or documentation](https://docs.docker.com/opensource/project/who-written-for/). - -These instructions are probably not perfect, please let us know if anything -feels wrong or incomplete. Better yet, submit a PR and improve them yourself. - -Getting the development builds -============================== - -Want to run Docker from a master build? You can download -master builds at [master.dockerproject.org](https://master.dockerproject.org). -They are updated with each commit merged into the master branch. - -Don't know how to use that super cool new feature in the master build? Check -out the master docs at -[docs.master.dockerproject.org](http://docs.master.dockerproject.org). - -How the project is run -====================== - -Docker is a very, very active project. If you want to learn more about how it is run, -or want to get more involved, the best place to start is [the project directory](https://github.com/docker/docker/tree/master/project). - -We are always open to suggestions on process improvements, and are always looking for more maintainers. - -### Talking to other Docker users and contributors - - - - - - - - - - - - - - - - - - - - - - - - -
Internet Relay Chat (IRC) -

- IRC is a direct line to our most knowledgeable Docker users; we have - both the #docker and #docker-dev group on - irc.freenode.net. - IRC is a rich chat protocol but it can overwhelm new users. You can search - our chat archives. -

- Read our IRC quickstart guide for an easy way to get started. -
Docker Community Forums - The Docker Engine - group is for users of the Docker Engine project. -
Google Groups - The docker-dev group is for contributors and other people - contributing to the Docker project. You can join this group without a - Google account by sending an email to docker-dev+subscribe@googlegroups.com. - You'll receive a join-request message; simply reply to the message to - confirm your subscription. -
Twitter - You can follow Docker's Twitter feed - to get updates on our products. You can also tweet us questions or just - share blogs or stories. -
Stack Overflow - Stack Overflow has over 7000 Docker questions listed. We regularly - monitor Docker questions - and so do many other knowledgeable Docker users. -
- -### Legal - -*Brought to you courtesy of our legal counsel. For more context, -please see the [NOTICE](https://github.com/docker/docker/blob/master/NOTICE) document in this repo.* - -Use and transfer of Docker may be subject to certain restrictions by the -United States and other governments. - -It is your responsibility to ensure that your use and/or transfer does not -violate applicable laws. - -For more information, please see https://www.bis.doc.gov - - -Licensing -========= -Docker is licensed under the Apache License, Version 2.0. See -[LICENSE](https://github.com/docker/docker/blob/master/LICENSE) for the full -license text. - -Other Docker Related Projects -============================= -There are a number of projects under development that are based on Docker's -core technology. These projects expand the tooling built around the -Docker platform to broaden its application and utility. - -* [Docker Registry](https://github.com/docker/distribution): Registry -server for Docker (hosting/delivery of repositories and images) -* [Docker Machine](https://github.com/docker/machine): Machine management -for a container-centric world -* [Docker Swarm](https://github.com/docker/swarm): A Docker-native clustering -system -* [Docker Compose](https://github.com/docker/compose) (formerly Fig): -Define and run multi-container apps -* [Kitematic](https://github.com/docker/kitematic): The easiest way to use -Docker on Mac and Windows - -If you know of another project underway that should be listed here, please help -us keep this list up-to-date by submitting a PR. - -Awesome-Docker -============== -You can find more projects, tools and articles related to Docker on the [awesome-docker list](https://github.com/veggiemonk/awesome-docker). Add your project there. diff --git a/vendor/github.com/docker/docker/ROADMAP.md b/vendor/github.com/docker/docker/ROADMAP.md deleted file mode 100644 index 21fe06d..0000000 --- a/vendor/github.com/docker/docker/ROADMAP.md +++ /dev/null @@ -1,118 +0,0 @@ -Docker Engine Roadmap -===================== - -### How should I use this document? - -This document provides description of items that the project decided to prioritize. This should -serve as a reference point for Docker contributors to understand where the project is going, and -help determine if a contribution could be conflicting with some longer terms plans. - -The fact that a feature isn't listed here doesn't mean that a patch for it will automatically be -refused (except for those mentioned as "frozen features" below)! We are always happy to receive -patches for new cool features we haven't thought about, or didn't judge priority. Please however -understand that such patches might take longer for us to review. - -### How can I help? - -Short term objectives are listed in the [wiki](https://github.com/docker/docker/wiki) and described -in [Issues](https://github.com/docker/docker/issues?q=is%3Aopen+is%3Aissue+label%3Aroadmap). Our -goal is to split down the workload in such way that anybody can jump in and help. Please comment on -issues if you want to take it to avoid duplicating effort! Similarly, if a maintainer is already -assigned on an issue you'd like to participate in, pinging him on IRC or GitHub to offer your help is -the best way to go. - -### How can I add something to the roadmap? - -The roadmap process is new to the Docker Engine: we are only beginning to structure and document the -project objectives. Our immediate goal is to be more transparent, and work with our community to -focus our efforts on fewer prioritized topics. - -We hope to offer in the near future a process allowing anyone to propose a topic to the roadmap, but -we are not quite there yet. For the time being, the BDFL remains the keeper of the roadmap, and we -won't be accepting pull requests adding or removing items from this file. - -# 1. Features and refactoring - -## 1.1 Runtime improvements - -We recently introduced [`runC`](https://runc.io) as a standalone low-level tool for container -execution. The initial goal was to integrate runC as a replacement in the Engine for the traditional -default libcontainer `execdriver`, but the Engine internals were not ready for this. - -As runC continued evolving, and the OCI specification along with it, we created -[`containerd`](https://containerd.tools/), a daemon to control and monitor multiple `runC`. This is -the new target for Engine integration, as it can entirely replace the whole `execdriver` -architecture, and container monitoring along with it. - -Docker Engine will rely on a long-running `containerd` companion daemon for all container execution -related operations. This could open the door in the future for Engine restarts without interrupting -running containers. - -## 1.2 Plugins improvements - -Docker Engine 1.7.0 introduced plugin support, initially for the use cases of volumes and networks -extensions. The plugin infrastructure was kept minimal as we were collecting use cases and real -world feedback before optimizing for any particular workflow. - -In the future, we'd like plugins to become first class citizens, and encourage an ecosystem of -plugins. This implies in particular making it trivially easy to distribute plugins as containers -through any Registry instance, as well as solving the commonly heard pain points of plugins needing -to be treated as somewhat special (being active at all time, started before any other user -containers, and not as easily dismissed). - -## 1.3 Internal decoupling - -A lot of work has been done in trying to decouple the Docker Engine's internals. In particular, the -API implementation has been refactored, and the Builder side of the daemon is now -[fully independent](https://github.com/docker/docker/tree/master/builder) while still residing in -the same repository. - -We are exploring ways to go further with that decoupling, capitalizing on the work introduced by the -runtime renovation and plugins improvement efforts. Indeed, the combination of `containerd` support -with the concept of "special" containers opens the door for bootstrapping more Engine internals -using the same facilities. - -## 1.4 Cluster capable Engine - -The community has been pushing for a more cluster capable Docker Engine, and a huge effort was spent -adding features such as multihost networking, and node discovery down at the Engine level. Yet, the -Engine is currently incapable of taking scheduling decisions alone, and continues relying on Swarm -for that. - -We plan to complete this effort and make Engine fully cluster capable. Multiple instances of the -Docker Engine being already capable of discovering each other and establish overlay networking for -their container to communicate, the next step is for a given Engine to gain ability to dispatch work -to another node in the cluster. This will be introduced in a backward compatible way, such that a -`docker run` invocation on a particular node remains fully deterministic. - -# 2 Frozen features - -## 2.1 Docker exec - -We won't accept patches expanding the surface of `docker exec`, which we intend to keep as a -*debugging* feature, as well as being strongly dependent on the Runtime ingredient effort. - -## 2.2 Remote Registry Operations - -A large amount of work is ongoing in the area of image distribution and provenance. This includes -moving to the V2 Registry API and heavily refactoring the code that powers these features. The -desired result is more secure, reliable and easier to use image distribution. - -Part of the problem with this part of the code base is the lack of a stable and flexible interface. -If new features are added that access the registry without solidifying these interfaces, achieving -feature parity will continue to be elusive. While we get a handle on this situation, we are imposing -a moratorium on new code that accesses the Registry API in commands that don't already make remote -calls. - -Currently, only the following commands cause interaction with a remote registry: - - - push - - pull - - run - - build - - search - - login - -In the interest of stabilizing the registry access model during this ongoing work, we are not -accepting additions to other commands that will cause remote interaction with the Registry API. This -moratorium will lift when the goals of the distribution project have been met. diff --git a/vendor/github.com/docker/docker/VENDORING.md b/vendor/github.com/docker/docker/VENDORING.md deleted file mode 100644 index 3086f9d..0000000 --- a/vendor/github.com/docker/docker/VENDORING.md +++ /dev/null @@ -1,45 +0,0 @@ -# Vendoring policies - -This document outlines recommended Vendoring policies for Docker repositories. -(Example, libnetwork is a Docker repo and logrus is not.) - -## Vendoring using tags - -Commit ID based vendoring provides little/no information about the updates -vendored. To fix this, vendors will now require that repositories use annotated -tags along with commit ids to snapshot commits. Annotated tags by themselves -are not sufficient, since the same tag can be force updated to reference -different commits. - -Each tag should: -- Follow Semantic Versioning rules (refer to section on "Semantic Versioning") -- Have a corresponding entry in the change tracking document. - -Each repo should: -- Have a change tracking document between tags/releases. Ex: CHANGELOG.md, -github releases file. - -The goal here is for consuming repos to be able to use the tag version and -changelog updates to determine whether the vendoring will cause any breaking or -backward incompatible changes. This also means that repos can specify having -dependency on a package of a specific version or greater up to the next major -release, without encountering breaking changes. - -## Semantic Versioning -Annotated version tags should follow Schema Versioning policies. -According to http://semver.org: - -"Given a version number MAJOR.MINOR.PATCH, increment the: - MAJOR version when you make incompatible API changes, - MINOR version when you add functionality in a backwards-compatible manner, and - PATCH version when you make backwards-compatible bug fixes. -Additional labels for pre-release and build metadata are available as extensions -to the MAJOR.MINOR.PATCH format." - -## Vendoring cadence -In order to avoid huge vendoring changes, it is recommended to have a regular -cadence for vendoring updates. e.g. monthly. - -## Pre-merge vendoring tests -All related repos will be vendored into docker/docker. -CI on docker/docker should catch any breaking changes involving multiple repos. diff --git a/vendor/github.com/docker/docker/VERSION b/vendor/github.com/docker/docker/VERSION deleted file mode 100644 index b50dd27..0000000 --- a/vendor/github.com/docker/docker/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.13.1 diff --git a/vendor/github.com/docker/docker/api/README.md b/vendor/github.com/docker/docker/api/README.md deleted file mode 100644 index 464e056..0000000 --- a/vendor/github.com/docker/docker/api/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# Working on the Engine API - -The Engine API is an HTTP API used by the command-line client to communicate with the daemon. It can also be used by third-party software to control the daemon. - -It consists of various components in this repository: - -- `api/swagger.yaml` A Swagger definition of the API. -- `api/types/` Types shared by both the client and server, representing various objects, options, responses, etc. Most are written manually, but some are automatically generated from the Swagger definition. See [#27919](https://github.com/docker/docker/issues/27919) for progress on this. -- `cli/` The command-line client. -- `client/` The Go client used by the command-line client. It can also be used by third-party Go programs. -- `daemon/` The daemon, which serves the API. - -## Swagger definition - -The API is defined by the [Swagger](http://swagger.io/specification/) definition in `api/swagger.yaml`. This definition can be used to: - -1. To automatically generate documentation. -2. To automatically generate the Go server and client. (A work-in-progress.) -3. Provide a machine readable version of the API for introspecting what it can do, automatically generating clients for other languages, etc. - -## Updating the API documentation - -The API documentation is generated entirely from `api/swagger.yaml`. If you make updates to the API, you'll need to edit this file to represent the change in the documentation. - -The file is split into two main sections: - -- `definitions`, which defines re-usable objects used in requests and responses -- `paths`, which defines the API endpoints (and some inline objects which don't need to be reusable) - -To make an edit, first look for the endpoint you want to edit under `paths`, then make the required edits. Endpoints may reference reusable objects with `$ref`, which can be found in the `definitions` section. - -There is hopefully enough example material in the file for you to copy a similar pattern from elsewhere in the file (e.g. adding new fields or endpoints), but for the full reference, see the [Swagger specification](https://github.com/docker/docker/issues/27919) - -`swagger.yaml` is validated by `hack/validate/swagger` to ensure it is a valid Swagger definition. This is useful for when you are making edits to ensure you are doing the right thing. - -## Viewing the API documentation - -When you make edits to `swagger.yaml`, you may want to check the generated API documentation to ensure it renders correctly. - -All the documentation generation is done in the documentation repository, [docker/docker.github.io](https://github.com/docker/docker.github.io). The Swagger definition is vendored periodically into this repository, but you can manually copy over the Swagger definition to test changes. - -Copy `api/swagger.yaml` in this repository to `engine/api/[VERSION_NUMBER]/swagger.yaml` in the documentation repository, overwriting what is already there. Then, run `docker-compose up` in the documentation repository and browse to [http://localhost:4000/engine/api/](http://localhost:4000/engine/api/) when it finishes rendering. diff --git a/vendor/github.com/docker/docker/api/common.go b/vendor/github.com/docker/docker/api/common.go deleted file mode 100644 index fd065d5..0000000 --- a/vendor/github.com/docker/docker/api/common.go +++ /dev/null @@ -1,166 +0,0 @@ -package api - -import ( - "encoding/json" - "encoding/pem" - "fmt" - "mime" - "os" - "path/filepath" - "sort" - "strconv" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/system" - "github.com/docker/libtrust" -) - -// Common constants for daemon and client. -const ( - // DefaultVersion of Current REST API - DefaultVersion string = "1.26" - - // NoBaseImageSpecifier is the symbol used by the FROM - // command to specify that no base image is to be used. - NoBaseImageSpecifier string = "scratch" -) - -// byPortInfo is a temporary type used to sort types.Port by its fields -type byPortInfo []types.Port - -func (r byPortInfo) Len() int { return len(r) } -func (r byPortInfo) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r byPortInfo) Less(i, j int) bool { - if r[i].PrivatePort != r[j].PrivatePort { - return r[i].PrivatePort < r[j].PrivatePort - } - - if r[i].IP != r[j].IP { - return r[i].IP < r[j].IP - } - - if r[i].PublicPort != r[j].PublicPort { - return r[i].PublicPort < r[j].PublicPort - } - - return r[i].Type < r[j].Type -} - -// DisplayablePorts returns formatted string representing open ports of container -// e.g. "0.0.0.0:80->9090/tcp, 9988/tcp" -// it's used by command 'docker ps' -func DisplayablePorts(ports []types.Port) string { - type portGroup struct { - first uint16 - last uint16 - } - groupMap := make(map[string]*portGroup) - var result []string - var hostMappings []string - var groupMapKeys []string - sort.Sort(byPortInfo(ports)) - for _, port := range ports { - current := port.PrivatePort - portKey := port.Type - if port.IP != "" { - if port.PublicPort != current { - hostMappings = append(hostMappings, fmt.Sprintf("%s:%d->%d/%s", port.IP, port.PublicPort, port.PrivatePort, port.Type)) - continue - } - portKey = fmt.Sprintf("%s/%s", port.IP, port.Type) - } - group := groupMap[portKey] - - if group == nil { - groupMap[portKey] = &portGroup{first: current, last: current} - // record order that groupMap keys are created - groupMapKeys = append(groupMapKeys, portKey) - continue - } - if current == (group.last + 1) { - group.last = current - continue - } - - result = append(result, formGroup(portKey, group.first, group.last)) - groupMap[portKey] = &portGroup{first: current, last: current} - } - for _, portKey := range groupMapKeys { - g := groupMap[portKey] - result = append(result, formGroup(portKey, g.first, g.last)) - } - result = append(result, hostMappings...) - return strings.Join(result, ", ") -} - -func formGroup(key string, start, last uint16) string { - parts := strings.Split(key, "/") - groupType := parts[0] - var ip string - if len(parts) > 1 { - ip = parts[0] - groupType = parts[1] - } - group := strconv.Itoa(int(start)) - if start != last { - group = fmt.Sprintf("%s-%d", group, last) - } - if ip != "" { - group = fmt.Sprintf("%s:%s->%s", ip, group, group) - } - return fmt.Sprintf("%s/%s", group, groupType) -} - -// MatchesContentType validates the content type against the expected one -func MatchesContentType(contentType, expectedType string) bool { - mimetype, _, err := mime.ParseMediaType(contentType) - if err != nil { - logrus.Errorf("Error parsing media type: %s error: %v", contentType, err) - } - return err == nil && mimetype == expectedType -} - -// LoadOrCreateTrustKey attempts to load the libtrust key at the given path, -// otherwise generates a new one -func LoadOrCreateTrustKey(trustKeyPath string) (libtrust.PrivateKey, error) { - err := system.MkdirAll(filepath.Dir(trustKeyPath), 0700) - if err != nil { - return nil, err - } - trustKey, err := libtrust.LoadKeyFile(trustKeyPath) - if err == libtrust.ErrKeyFileDoesNotExist { - trustKey, err = libtrust.GenerateECP256PrivateKey() - if err != nil { - return nil, fmt.Errorf("Error generating key: %s", err) - } - encodedKey, err := serializePrivateKey(trustKey, filepath.Ext(trustKeyPath)) - if err != nil { - return nil, fmt.Errorf("Error serializing key: %s", err) - } - if err := ioutils.AtomicWriteFile(trustKeyPath, encodedKey, os.FileMode(0600)); err != nil { - return nil, fmt.Errorf("Error saving key file: %s", err) - } - } else if err != nil { - return nil, fmt.Errorf("Error loading key file %s: %s", trustKeyPath, err) - } - return trustKey, nil -} - -func serializePrivateKey(key libtrust.PrivateKey, ext string) (encoded []byte, err error) { - if ext == ".json" || ext == ".jwk" { - encoded, err = json.Marshal(key) - if err != nil { - return nil, fmt.Errorf("unable to encode private key JWK: %s", err) - } - } else { - pemBlock, err := key.PEMBlock() - if err != nil { - return nil, fmt.Errorf("unable to encode private key PEM: %s", err) - } - encoded = pem.EncodeToMemory(pemBlock) - } - return -} diff --git a/vendor/github.com/docker/docker/api/common_test.go b/vendor/github.com/docker/docker/api/common_test.go deleted file mode 100644 index 31d6f58..0000000 --- a/vendor/github.com/docker/docker/api/common_test.go +++ /dev/null @@ -1,341 +0,0 @@ -package api - -import ( - "io/ioutil" - "path/filepath" - "testing" - - "os" - - "github.com/docker/docker/api/types" -) - -type ports struct { - ports []types.Port - expected string -} - -// DisplayablePorts -func TestDisplayablePorts(t *testing.T) { - cases := []ports{ - { - []types.Port{ - { - PrivatePort: 9988, - Type: "tcp", - }, - }, - "9988/tcp"}, - { - []types.Port{ - { - PrivatePort: 9988, - Type: "udp", - }, - }, - "9988/udp", - }, - { - []types.Port{ - { - IP: "0.0.0.0", - PrivatePort: 9988, - Type: "tcp", - }, - }, - "0.0.0.0:0->9988/tcp", - }, - { - []types.Port{ - { - PrivatePort: 9988, - PublicPort: 8899, - Type: "tcp", - }, - }, - "9988/tcp", - }, - { - []types.Port{ - { - IP: "4.3.2.1", - PrivatePort: 9988, - PublicPort: 8899, - Type: "tcp", - }, - }, - "4.3.2.1:8899->9988/tcp", - }, - { - []types.Port{ - { - IP: "4.3.2.1", - PrivatePort: 9988, - PublicPort: 9988, - Type: "tcp", - }, - }, - "4.3.2.1:9988->9988/tcp", - }, - { - []types.Port{ - { - PrivatePort: 9988, - Type: "udp", - }, { - PrivatePort: 9988, - Type: "udp", - }, - }, - "9988/udp, 9988/udp", - }, - { - []types.Port{ - { - IP: "1.2.3.4", - PublicPort: 9998, - PrivatePort: 9998, - Type: "udp", - }, { - IP: "1.2.3.4", - PublicPort: 9999, - PrivatePort: 9999, - Type: "udp", - }, - }, - "1.2.3.4:9998-9999->9998-9999/udp", - }, - { - []types.Port{ - { - IP: "1.2.3.4", - PublicPort: 8887, - PrivatePort: 9998, - Type: "udp", - }, { - IP: "1.2.3.4", - PublicPort: 8888, - PrivatePort: 9999, - Type: "udp", - }, - }, - "1.2.3.4:8887->9998/udp, 1.2.3.4:8888->9999/udp", - }, - { - []types.Port{ - { - PrivatePort: 9998, - Type: "udp", - }, { - PrivatePort: 9999, - Type: "udp", - }, - }, - "9998-9999/udp", - }, - { - []types.Port{ - { - IP: "1.2.3.4", - PrivatePort: 6677, - PublicPort: 7766, - Type: "tcp", - }, { - PrivatePort: 9988, - PublicPort: 8899, - Type: "udp", - }, - }, - "9988/udp, 1.2.3.4:7766->6677/tcp", - }, - { - []types.Port{ - { - IP: "1.2.3.4", - PrivatePort: 9988, - PublicPort: 8899, - Type: "udp", - }, { - IP: "1.2.3.4", - PrivatePort: 9988, - PublicPort: 8899, - Type: "tcp", - }, { - IP: "4.3.2.1", - PrivatePort: 2233, - PublicPort: 3322, - Type: "tcp", - }, - }, - "4.3.2.1:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp", - }, - { - []types.Port{ - { - PrivatePort: 9988, - PublicPort: 8899, - Type: "udp", - }, { - IP: "1.2.3.4", - PrivatePort: 6677, - PublicPort: 7766, - Type: "tcp", - }, { - IP: "4.3.2.1", - PrivatePort: 2233, - PublicPort: 3322, - Type: "tcp", - }, - }, - "9988/udp, 4.3.2.1:3322->2233/tcp, 1.2.3.4:7766->6677/tcp", - }, - { - []types.Port{ - { - PrivatePort: 80, - Type: "tcp", - }, { - PrivatePort: 1024, - Type: "tcp", - }, { - PrivatePort: 80, - Type: "udp", - }, { - PrivatePort: 1024, - Type: "udp", - }, { - IP: "1.1.1.1", - PublicPort: 80, - PrivatePort: 1024, - Type: "tcp", - }, { - IP: "1.1.1.1", - PublicPort: 80, - PrivatePort: 1024, - Type: "udp", - }, { - IP: "1.1.1.1", - PublicPort: 1024, - PrivatePort: 80, - Type: "tcp", - }, { - IP: "1.1.1.1", - PublicPort: 1024, - PrivatePort: 80, - Type: "udp", - }, { - IP: "2.1.1.1", - PublicPort: 80, - PrivatePort: 1024, - Type: "tcp", - }, { - IP: "2.1.1.1", - PublicPort: 80, - PrivatePort: 1024, - Type: "udp", - }, { - IP: "2.1.1.1", - PublicPort: 1024, - PrivatePort: 80, - Type: "tcp", - }, { - IP: "2.1.1.1", - PublicPort: 1024, - PrivatePort: 80, - Type: "udp", - }, - }, - "80/tcp, 80/udp, 1024/tcp, 1024/udp, 1.1.1.1:1024->80/tcp, 1.1.1.1:1024->80/udp, 2.1.1.1:1024->80/tcp, 2.1.1.1:1024->80/udp, 1.1.1.1:80->1024/tcp, 1.1.1.1:80->1024/udp, 2.1.1.1:80->1024/tcp, 2.1.1.1:80->1024/udp", - }, - } - - for _, port := range cases { - actual := DisplayablePorts(port.ports) - if port.expected != actual { - t.Fatalf("Expected %s, got %s.", port.expected, actual) - } - } -} - -// MatchesContentType -func TestJsonContentType(t *testing.T) { - if !MatchesContentType("application/json", "application/json") { - t.Fail() - } - - if !MatchesContentType("application/json; charset=utf-8", "application/json") { - t.Fail() - } - - if MatchesContentType("dockerapplication/json", "application/json") { - t.Fail() - } -} - -// LoadOrCreateTrustKey -func TestLoadOrCreateTrustKeyInvalidKeyFile(t *testing.T) { - tmpKeyFolderPath, err := ioutil.TempDir("", "api-trustkey-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpKeyFolderPath) - - tmpKeyFile, err := ioutil.TempFile(tmpKeyFolderPath, "keyfile") - if err != nil { - t.Fatal(err) - } - - if _, err := LoadOrCreateTrustKey(tmpKeyFile.Name()); err == nil { - t.Fatalf("expected an error, got nothing.") - } - -} - -func TestLoadOrCreateTrustKeyCreateKey(t *testing.T) { - tmpKeyFolderPath, err := ioutil.TempDir("", "api-trustkey-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpKeyFolderPath) - - // Without the need to create the folder hierarchy - tmpKeyFile := filepath.Join(tmpKeyFolderPath, "keyfile") - - if key, err := LoadOrCreateTrustKey(tmpKeyFile); err != nil || key == nil { - t.Fatalf("expected a new key file, got : %v and %v", err, key) - } - - if _, err := os.Stat(tmpKeyFile); err != nil { - t.Fatalf("Expected to find a file %s, got %v", tmpKeyFile, err) - } - - // With the need to create the folder hierarchy as tmpKeyFie is in a path - // where some folders do not exist. - tmpKeyFile = filepath.Join(tmpKeyFolderPath, "folder/hierarchy/keyfile") - - if key, err := LoadOrCreateTrustKey(tmpKeyFile); err != nil || key == nil { - t.Fatalf("expected a new key file, got : %v and %v", err, key) - } - - if _, err := os.Stat(tmpKeyFile); err != nil { - t.Fatalf("Expected to find a file %s, got %v", tmpKeyFile, err) - } - - // With no path at all - defer os.Remove("keyfile") - if key, err := LoadOrCreateTrustKey("keyfile"); err != nil || key == nil { - t.Fatalf("expected a new key file, got : %v and %v", err, key) - } - - if _, err := os.Stat("keyfile"); err != nil { - t.Fatalf("Expected to find a file keyfile, got %v", err) - } -} - -func TestLoadOrCreateTrustKeyLoadValidKey(t *testing.T) { - tmpKeyFile := filepath.Join("fixtures", "keyfile") - - if key, err := LoadOrCreateTrustKey(tmpKeyFile); err != nil || key == nil { - t.Fatalf("expected a key file, got : %v and %v", err, key) - } -} diff --git a/vendor/github.com/docker/docker/api/common_unix.go b/vendor/github.com/docker/docker/api/common_unix.go deleted file mode 100644 index 081e61c..0000000 --- a/vendor/github.com/docker/docker/api/common_unix.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build !windows - -package api - -// MinVersion represents Minimum REST API version supported -const MinVersion string = "1.12" diff --git a/vendor/github.com/docker/docker/api/common_windows.go b/vendor/github.com/docker/docker/api/common_windows.go deleted file mode 100644 index d930fa0..0000000 --- a/vendor/github.com/docker/docker/api/common_windows.go +++ /dev/null @@ -1,8 +0,0 @@ -package api - -// MinVersion represents Minimum REST API version supported -// Technically the first daemon API version released on Windows is v1.25 in -// engine version 1.13. However, some clients are explicitly using downlevel -// APIs (eg docker-compose v2.1 file format) and that is just too restrictive. -// Hence also allowing 1.24 on Windows. -const MinVersion string = "1.24" diff --git a/vendor/github.com/docker/docker/api/errors/errors.go b/vendor/github.com/docker/docker/api/errors/errors.go deleted file mode 100644 index 29fd254..0000000 --- a/vendor/github.com/docker/docker/api/errors/errors.go +++ /dev/null @@ -1,47 +0,0 @@ -package errors - -import "net/http" - -// apiError is an error wrapper that also -// holds information about response status codes. -type apiError struct { - error - statusCode int -} - -// HTTPErrorStatusCode returns a status code. -func (e apiError) HTTPErrorStatusCode() int { - return e.statusCode -} - -// NewErrorWithStatusCode allows you to associate -// a specific HTTP Status Code to an error. -// The Server will take that code and set -// it as the response status. -func NewErrorWithStatusCode(err error, code int) error { - return apiError{err, code} -} - -// NewBadRequestError creates a new API error -// that has the 400 HTTP status code associated to it. -func NewBadRequestError(err error) error { - return NewErrorWithStatusCode(err, http.StatusBadRequest) -} - -// NewRequestForbiddenError creates a new API error -// that has the 403 HTTP status code associated to it. -func NewRequestForbiddenError(err error) error { - return NewErrorWithStatusCode(err, http.StatusForbidden) -} - -// NewRequestNotFoundError creates a new API error -// that has the 404 HTTP status code associated to it. -func NewRequestNotFoundError(err error) error { - return NewErrorWithStatusCode(err, http.StatusNotFound) -} - -// NewRequestConflictError creates a new API error -// that has the 409 HTTP status code associated to it. -func NewRequestConflictError(err error) error { - return NewErrorWithStatusCode(err, http.StatusConflict) -} diff --git a/vendor/github.com/docker/docker/api/fixtures/keyfile b/vendor/github.com/docker/docker/api/fixtures/keyfile deleted file mode 100644 index 322f254..0000000 --- a/vendor/github.com/docker/docker/api/fixtures/keyfile +++ /dev/null @@ -1,7 +0,0 @@ ------BEGIN EC PRIVATE KEY----- -keyID: AWX2:I27X:WQFX:IOMK:CNAK:O7PW:VYNB:ZLKC:CVAE:YJP2:SI4A:XXAY - -MHcCAQEEILHTRWdcpKWsnORxSFyBnndJ4ROU41hMtr/GCiLVvwBQoAoGCCqGSM49 -AwEHoUQDQgAElpVFbQ2V2UQKajqdE3fVxJ+/pE/YuEFOxWbOxF2be19BY209/iky -NzeFFK7SLpQ4CBJ7zDVXOHsMzrkY/GquGA== ------END EC PRIVATE KEY----- diff --git a/vendor/github.com/docker/docker/api/server/httputils/decoder.go b/vendor/github.com/docker/docker/api/server/httputils/decoder.go deleted file mode 100644 index 458eac5..0000000 --- a/vendor/github.com/docker/docker/api/server/httputils/decoder.go +++ /dev/null @@ -1,16 +0,0 @@ -package httputils - -import ( - "io" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/network" -) - -// ContainerDecoder specifies how -// to translate an io.Reader into -// container configuration. -type ContainerDecoder interface { - DecodeConfig(src io.Reader) (*container.Config, *container.HostConfig, *network.NetworkingConfig, error) - DecodeHostConfig(src io.Reader) (*container.HostConfig, error) -} diff --git a/vendor/github.com/docker/docker/api/server/httputils/errors.go b/vendor/github.com/docker/docker/api/server/httputils/errors.go deleted file mode 100644 index 59098a9..0000000 --- a/vendor/github.com/docker/docker/api/server/httputils/errors.go +++ /dev/null @@ -1,101 +0,0 @@ -package httputils - -import ( - "net/http" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/versions" - "github.com/gorilla/mux" - "google.golang.org/grpc" -) - -// httpStatusError is an interface -// that errors with custom status codes -// implement to tell the api layer -// which response status to set. -type httpStatusError interface { - HTTPErrorStatusCode() int -} - -// inputValidationError is an interface -// that errors generated by invalid -// inputs can implement to tell the -// api layer to set a 400 status code -// in the response. -type inputValidationError interface { - IsValidationError() bool -} - -// GetHTTPErrorStatusCode retrieves status code from error message -func GetHTTPErrorStatusCode(err error) int { - if err == nil { - logrus.WithFields(logrus.Fields{"error": err}).Error("unexpected HTTP error handling") - return http.StatusInternalServerError - } - - var statusCode int - errMsg := err.Error() - - switch e := err.(type) { - case httpStatusError: - statusCode = e.HTTPErrorStatusCode() - case inputValidationError: - statusCode = http.StatusBadRequest - default: - // FIXME: this is brittle and should not be necessary, but we still need to identify if - // there are errors falling back into this logic. - // If we need to differentiate between different possible error types, - // we should create appropriate error types that implement the httpStatusError interface. - errStr := strings.ToLower(errMsg) - for _, status := range []struct { - keyword string - code int - }{ - {"not found", http.StatusNotFound}, - {"no such", http.StatusNotFound}, - {"bad parameter", http.StatusBadRequest}, - {"no command", http.StatusBadRequest}, - {"conflict", http.StatusConflict}, - {"impossible", http.StatusNotAcceptable}, - {"wrong login/password", http.StatusUnauthorized}, - {"unauthorized", http.StatusUnauthorized}, - {"hasn't been activated", http.StatusForbidden}, - {"this node", http.StatusServiceUnavailable}, - } { - if strings.Contains(errStr, status.keyword) { - statusCode = status.code - break - } - } - } - - if statusCode == 0 { - statusCode = http.StatusInternalServerError - } - - return statusCode -} - -func apiVersionSupportsJSONErrors(version string) bool { - const firstAPIVersionWithJSONErrors = "1.23" - return version == "" || versions.GreaterThan(version, firstAPIVersionWithJSONErrors) -} - -// MakeErrorHandler makes an HTTP handler that decodes a Docker error and -// returns it in the response. -func MakeErrorHandler(err error) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - statusCode := GetHTTPErrorStatusCode(err) - vars := mux.Vars(r) - if apiVersionSupportsJSONErrors(vars["version"]) { - response := &types.ErrorResponse{ - Message: err.Error(), - } - WriteJSON(w, statusCode, response) - } else { - http.Error(w, grpc.ErrorDesc(err), statusCode) - } - } -} diff --git a/vendor/github.com/docker/docker/api/server/httputils/form.go b/vendor/github.com/docker/docker/api/server/httputils/form.go deleted file mode 100644 index 20188c1..0000000 --- a/vendor/github.com/docker/docker/api/server/httputils/form.go +++ /dev/null @@ -1,73 +0,0 @@ -package httputils - -import ( - "fmt" - "net/http" - "path/filepath" - "strconv" - "strings" -) - -// BoolValue transforms a form value in different formats into a boolean type. -func BoolValue(r *http.Request, k string) bool { - s := strings.ToLower(strings.TrimSpace(r.FormValue(k))) - return !(s == "" || s == "0" || s == "no" || s == "false" || s == "none") -} - -// BoolValueOrDefault returns the default bool passed if the query param is -// missing, otherwise it's just a proxy to boolValue above -func BoolValueOrDefault(r *http.Request, k string, d bool) bool { - if _, ok := r.Form[k]; !ok { - return d - } - return BoolValue(r, k) -} - -// Int64ValueOrZero parses a form value into an int64 type. -// It returns 0 if the parsing fails. -func Int64ValueOrZero(r *http.Request, k string) int64 { - val, err := Int64ValueOrDefault(r, k, 0) - if err != nil { - return 0 - } - return val -} - -// Int64ValueOrDefault parses a form value into an int64 type. If there is an -// error, returns the error. If there is no value returns the default value. -func Int64ValueOrDefault(r *http.Request, field string, def int64) (int64, error) { - if r.Form.Get(field) != "" { - value, err := strconv.ParseInt(r.Form.Get(field), 10, 64) - if err != nil { - return value, err - } - return value, nil - } - return def, nil -} - -// ArchiveOptions stores archive information for different operations. -type ArchiveOptions struct { - Name string - Path string -} - -// ArchiveFormValues parses form values and turns them into ArchiveOptions. -// It fails if the archive name and path are not in the request. -func ArchiveFormValues(r *http.Request, vars map[string]string) (ArchiveOptions, error) { - if err := ParseForm(r); err != nil { - return ArchiveOptions{}, err - } - - name := vars["name"] - path := filepath.FromSlash(r.Form.Get("path")) - - switch { - case name == "": - return ArchiveOptions{}, fmt.Errorf("bad parameter: 'name' cannot be empty") - case path == "": - return ArchiveOptions{}, fmt.Errorf("bad parameter: 'path' cannot be empty") - } - - return ArchiveOptions{name, path}, nil -} diff --git a/vendor/github.com/docker/docker/api/server/httputils/form_test.go b/vendor/github.com/docker/docker/api/server/httputils/form_test.go deleted file mode 100644 index c56f7c1..0000000 --- a/vendor/github.com/docker/docker/api/server/httputils/form_test.go +++ /dev/null @@ -1,105 +0,0 @@ -package httputils - -import ( - "net/http" - "net/url" - "testing" -) - -func TestBoolValue(t *testing.T) { - cases := map[string]bool{ - "": false, - "0": false, - "no": false, - "false": false, - "none": false, - "1": true, - "yes": true, - "true": true, - "one": true, - "100": true, - } - - for c, e := range cases { - v := url.Values{} - v.Set("test", c) - r, _ := http.NewRequest("POST", "", nil) - r.Form = v - - a := BoolValue(r, "test") - if a != e { - t.Fatalf("Value: %s, expected: %v, actual: %v", c, e, a) - } - } -} - -func TestBoolValueOrDefault(t *testing.T) { - r, _ := http.NewRequest("GET", "", nil) - if !BoolValueOrDefault(r, "queryparam", true) { - t.Fatal("Expected to get true default value, got false") - } - - v := url.Values{} - v.Set("param", "") - r, _ = http.NewRequest("GET", "", nil) - r.Form = v - if BoolValueOrDefault(r, "param", true) { - t.Fatal("Expected not to get true") - } -} - -func TestInt64ValueOrZero(t *testing.T) { - cases := map[string]int64{ - "": 0, - "asdf": 0, - "0": 0, - "1": 1, - } - - for c, e := range cases { - v := url.Values{} - v.Set("test", c) - r, _ := http.NewRequest("POST", "", nil) - r.Form = v - - a := Int64ValueOrZero(r, "test") - if a != e { - t.Fatalf("Value: %s, expected: %v, actual: %v", c, e, a) - } - } -} - -func TestInt64ValueOrDefault(t *testing.T) { - cases := map[string]int64{ - "": -1, - "-1": -1, - "42": 42, - } - - for c, e := range cases { - v := url.Values{} - v.Set("test", c) - r, _ := http.NewRequest("POST", "", nil) - r.Form = v - - a, err := Int64ValueOrDefault(r, "test", -1) - if a != e { - t.Fatalf("Value: %s, expected: %v, actual: %v", c, e, a) - } - if err != nil { - t.Fatalf("Error should be nil, but received: %s", err) - } - } -} - -func TestInt64ValueOrDefaultWithError(t *testing.T) { - v := url.Values{} - v.Set("test", "invalid") - r, _ := http.NewRequest("POST", "", nil) - r.Form = v - - _, err := Int64ValueOrDefault(r, "test", -1) - if err == nil { - t.Fatalf("Expected an error.") - } -} diff --git a/vendor/github.com/docker/docker/api/server/httputils/httputils.go b/vendor/github.com/docker/docker/api/server/httputils/httputils.go deleted file mode 100644 index 7930ff7..0000000 --- a/vendor/github.com/docker/docker/api/server/httputils/httputils.go +++ /dev/null @@ -1,90 +0,0 @@ -package httputils - -import ( - "fmt" - "io" - "net/http" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api" -) - -// APIVersionKey is the client's requested API version. -const APIVersionKey = "api-version" - -// UAStringKey is used as key type for user-agent string in net/context struct -const UAStringKey = "upstream-user-agent" - -// APIFunc is an adapter to allow the use of ordinary functions as Docker API endpoints. -// Any function that has the appropriate signature can be registered as an API endpoint (e.g. getVersion). -type APIFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error - -// HijackConnection interrupts the http response writer to get the -// underlying connection and operate with it. -func HijackConnection(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) { - conn, _, err := w.(http.Hijacker).Hijack() - if err != nil { - return nil, nil, err - } - // Flush the options to make sure the client sets the raw mode - conn.Write([]byte{}) - return conn, conn, nil -} - -// CloseStreams ensures that a list for http streams are properly closed. -func CloseStreams(streams ...interface{}) { - for _, stream := range streams { - if tcpc, ok := stream.(interface { - CloseWrite() error - }); ok { - tcpc.CloseWrite() - } else if closer, ok := stream.(io.Closer); ok { - closer.Close() - } - } -} - -// CheckForJSON makes sure that the request's Content-Type is application/json. -func CheckForJSON(r *http.Request) error { - ct := r.Header.Get("Content-Type") - - // No Content-Type header is ok as long as there's no Body - if ct == "" { - if r.Body == nil || r.ContentLength == 0 { - return nil - } - } - - // Otherwise it better be json - if api.MatchesContentType(ct, "application/json") { - return nil - } - return fmt.Errorf("Content-Type specified (%s) must be 'application/json'", ct) -} - -// ParseForm ensures the request form is parsed even with invalid content types. -// If we don't do this, POST method without Content-type (even with empty body) will fail. -func ParseForm(r *http.Request) error { - if r == nil { - return nil - } - if err := r.ParseForm(); err != nil && !strings.HasPrefix(err.Error(), "mime:") { - return err - } - return nil -} - -// VersionFromContext returns an API version from the context using APIVersionKey. -// It panics if the context value does not have version.Version type. -func VersionFromContext(ctx context.Context) (ver string) { - if ctx == nil { - return - } - val := ctx.Value(APIVersionKey) - if val == nil { - return - } - return val.(string) -} diff --git a/vendor/github.com/docker/docker/api/server/httputils/httputils_write_json.go b/vendor/github.com/docker/docker/api/server/httputils/httputils_write_json.go deleted file mode 100644 index 4787cc3..0000000 --- a/vendor/github.com/docker/docker/api/server/httputils/httputils_write_json.go +++ /dev/null @@ -1,17 +0,0 @@ -// +build go1.7 - -package httputils - -import ( - "encoding/json" - "net/http" -) - -// WriteJSON writes the value v to the http response stream as json with standard json encoding. -func WriteJSON(w http.ResponseWriter, code int, v interface{}) error { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(code) - enc := json.NewEncoder(w) - enc.SetEscapeHTML(false) - return enc.Encode(v) -} diff --git a/vendor/github.com/docker/docker/api/server/httputils/httputils_write_json_go16.go b/vendor/github.com/docker/docker/api/server/httputils/httputils_write_json_go16.go deleted file mode 100644 index bdc6981..0000000 --- a/vendor/github.com/docker/docker/api/server/httputils/httputils_write_json_go16.go +++ /dev/null @@ -1,16 +0,0 @@ -// +build go1.6,!go1.7 - -package httputils - -import ( - "encoding/json" - "net/http" -) - -// WriteJSON writes the value v to the http response stream as json with standard json encoding. -func WriteJSON(w http.ResponseWriter, code int, v interface{}) error { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(code) - enc := json.NewEncoder(w) - return enc.Encode(v) -} diff --git a/vendor/github.com/docker/docker/api/server/middleware.go b/vendor/github.com/docker/docker/api/server/middleware.go deleted file mode 100644 index 537ce80..0000000 --- a/vendor/github.com/docker/docker/api/server/middleware.go +++ /dev/null @@ -1,24 +0,0 @@ -package server - -import ( - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/server/middleware" -) - -// handlerWithGlobalMiddlewares wraps the handler function for a request with -// the server's global middlewares. The order of the middlewares is backwards, -// meaning that the first in the list will be evaluated last. -func (s *Server) handlerWithGlobalMiddlewares(handler httputils.APIFunc) httputils.APIFunc { - next := handler - - for _, m := range s.middlewares { - next = m.WrapHandler(next) - } - - if s.cfg.Logging && logrus.GetLevel() == logrus.DebugLevel { - next = middleware.DebugRequestMiddleware(next) - } - - return next -} diff --git a/vendor/github.com/docker/docker/api/server/middleware/cors.go b/vendor/github.com/docker/docker/api/server/middleware/cors.go deleted file mode 100644 index ea725db..0000000 --- a/vendor/github.com/docker/docker/api/server/middleware/cors.go +++ /dev/null @@ -1,37 +0,0 @@ -package middleware - -import ( - "net/http" - - "github.com/Sirupsen/logrus" - "golang.org/x/net/context" -) - -// CORSMiddleware injects CORS headers to each request -// when it's configured. -type CORSMiddleware struct { - defaultHeaders string -} - -// NewCORSMiddleware creates a new CORSMiddleware with default headers. -func NewCORSMiddleware(d string) CORSMiddleware { - return CORSMiddleware{defaultHeaders: d} -} - -// WrapHandler returns a new handler function wrapping the previous one in the request chain. -func (c CORSMiddleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - // If "api-cors-header" is not given, but "api-enable-cors" is true, we set cors to "*" - // otherwise, all head values will be passed to HTTP handler - corsHeaders := c.defaultHeaders - if corsHeaders == "" { - corsHeaders = "*" - } - - logrus.Debugf("CORS header is enabled and set to: %s", corsHeaders) - w.Header().Add("Access-Control-Allow-Origin", corsHeaders) - w.Header().Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth") - w.Header().Add("Access-Control-Allow-Methods", "HEAD, GET, POST, DELETE, PUT, OPTIONS") - return handler(ctx, w, r, vars) - } -} diff --git a/vendor/github.com/docker/docker/api/server/middleware/debug.go b/vendor/github.com/docker/docker/api/server/middleware/debug.go deleted file mode 100644 index 8c85676..0000000 --- a/vendor/github.com/docker/docker/api/server/middleware/debug.go +++ /dev/null @@ -1,76 +0,0 @@ -package middleware - -import ( - "bufio" - "encoding/json" - "io" - "net/http" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/pkg/ioutils" - "golang.org/x/net/context" -) - -// DebugRequestMiddleware dumps the request to logger -func DebugRequestMiddleware(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - logrus.Debugf("Calling %s %s", r.Method, r.RequestURI) - - if r.Method != "POST" { - return handler(ctx, w, r, vars) - } - if err := httputils.CheckForJSON(r); err != nil { - return handler(ctx, w, r, vars) - } - maxBodySize := 4096 // 4KB - if r.ContentLength > int64(maxBodySize) { - return handler(ctx, w, r, vars) - } - - body := r.Body - bufReader := bufio.NewReaderSize(body, maxBodySize) - r.Body = ioutils.NewReadCloserWrapper(bufReader, func() error { return body.Close() }) - - b, err := bufReader.Peek(maxBodySize) - if err != io.EOF { - // either there was an error reading, or the buffer is full (in which case the request is too large) - return handler(ctx, w, r, vars) - } - - var postForm map[string]interface{} - if err := json.Unmarshal(b, &postForm); err == nil { - maskSecretKeys(postForm) - formStr, errMarshal := json.Marshal(postForm) - if errMarshal == nil { - logrus.Debugf("form data: %s", string(formStr)) - } else { - logrus.Debugf("form data: %q", postForm) - } - } - - return handler(ctx, w, r, vars) - } -} - -func maskSecretKeys(inp interface{}) { - if arr, ok := inp.([]interface{}); ok { - for _, f := range arr { - maskSecretKeys(f) - } - return - } - if form, ok := inp.(map[string]interface{}); ok { - loop0: - for k, v := range form { - for _, m := range []string{"password", "secret", "jointoken", "unlockkey"} { - if strings.EqualFold(m, k) { - form[k] = "*****" - continue loop0 - } - } - maskSecretKeys(v) - } - } -} diff --git a/vendor/github.com/docker/docker/api/server/middleware/experimental.go b/vendor/github.com/docker/docker/api/server/middleware/experimental.go deleted file mode 100644 index b8f56e8..0000000 --- a/vendor/github.com/docker/docker/api/server/middleware/experimental.go +++ /dev/null @@ -1,29 +0,0 @@ -package middleware - -import ( - "net/http" - - "golang.org/x/net/context" -) - -// ExperimentalMiddleware is a the middleware in charge of adding the -// 'Docker-Experimental' header to every outgoing request -type ExperimentalMiddleware struct { - experimental string -} - -// NewExperimentalMiddleware creates a new ExperimentalMiddleware -func NewExperimentalMiddleware(experimentalEnabled bool) ExperimentalMiddleware { - if experimentalEnabled { - return ExperimentalMiddleware{"true"} - } - return ExperimentalMiddleware{"false"} -} - -// WrapHandler returns a new handler function wrapping the previous one in the request chain. -func (e ExperimentalMiddleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - w.Header().Set("Docker-Experimental", e.experimental) - return handler(ctx, w, r, vars) - } -} diff --git a/vendor/github.com/docker/docker/api/server/middleware/middleware.go b/vendor/github.com/docker/docker/api/server/middleware/middleware.go deleted file mode 100644 index dc1f5bf..0000000 --- a/vendor/github.com/docker/docker/api/server/middleware/middleware.go +++ /dev/null @@ -1,13 +0,0 @@ -package middleware - -import ( - "net/http" - - "golang.org/x/net/context" -) - -// Middleware is an interface to allow the use of ordinary functions as Docker API filters. -// Any struct that has the appropriate signature can be registered as a middleware. -type Middleware interface { - WrapHandler(func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error -} diff --git a/vendor/github.com/docker/docker/api/server/middleware/version.go b/vendor/github.com/docker/docker/api/server/middleware/version.go deleted file mode 100644 index 1101465..0000000 --- a/vendor/github.com/docker/docker/api/server/middleware/version.go +++ /dev/null @@ -1,50 +0,0 @@ -package middleware - -import ( - "fmt" - "net/http" - "runtime" - - "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/types/versions" - "golang.org/x/net/context" -) - -// VersionMiddleware is a middleware that -// validates the client and server versions. -type VersionMiddleware struct { - serverVersion string - defaultVersion string - minVersion string -} - -// NewVersionMiddleware creates a new VersionMiddleware -// with the default versions. -func NewVersionMiddleware(s, d, m string) VersionMiddleware { - return VersionMiddleware{ - serverVersion: s, - defaultVersion: d, - minVersion: m, - } -} - -// WrapHandler returns a new handler function wrapping the previous one in the request chain. -func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - apiVersion := vars["version"] - if apiVersion == "" { - apiVersion = v.defaultVersion - } - - if versions.LessThan(apiVersion, v.minVersion) { - return errors.NewBadRequestError(fmt.Errorf("client version %s is too old. Minimum supported API version is %s, please upgrade your client to a newer version", apiVersion, v.minVersion)) - } - - header := fmt.Sprintf("Docker/%s (%s)", v.serverVersion, runtime.GOOS) - w.Header().Set("Server", header) - w.Header().Set("API-Version", v.defaultVersion) - ctx = context.WithValue(ctx, "api-version", apiVersion) - return handler(ctx, w, r, vars) - } - -} diff --git a/vendor/github.com/docker/docker/api/server/middleware/version_test.go b/vendor/github.com/docker/docker/api/server/middleware/version_test.go deleted file mode 100644 index 9e72efd..0000000 --- a/vendor/github.com/docker/docker/api/server/middleware/version_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package middleware - -import ( - "net/http" - "net/http/httptest" - "strings" - "testing" - - "github.com/docker/docker/api/server/httputils" - "golang.org/x/net/context" -) - -func TestVersionMiddleware(t *testing.T) { - handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if httputils.VersionFromContext(ctx) == "" { - t.Fatalf("Expected version, got empty string") - } - return nil - } - - defaultVersion := "1.10.0" - minVersion := "1.2.0" - m := NewVersionMiddleware(defaultVersion, defaultVersion, minVersion) - h := m.WrapHandler(handler) - - req, _ := http.NewRequest("GET", "/containers/json", nil) - resp := httptest.NewRecorder() - ctx := context.Background() - if err := h(ctx, resp, req, map[string]string{}); err != nil { - t.Fatal(err) - } -} - -func TestVersionMiddlewareWithErrors(t *testing.T) { - handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if httputils.VersionFromContext(ctx) == "" { - t.Fatalf("Expected version, got empty string") - } - return nil - } - - defaultVersion := "1.10.0" - minVersion := "1.2.0" - m := NewVersionMiddleware(defaultVersion, defaultVersion, minVersion) - h := m.WrapHandler(handler) - - req, _ := http.NewRequest("GET", "/containers/json", nil) - resp := httptest.NewRecorder() - ctx := context.Background() - - vars := map[string]string{"version": "0.1"} - err := h(ctx, resp, req, vars) - - if !strings.Contains(err.Error(), "client version 0.1 is too old. Minimum supported API version is 1.2.0") { - t.Fatalf("Expected too old client error, got %v", err) - } -} diff --git a/vendor/github.com/docker/docker/api/server/profiler.go b/vendor/github.com/docker/docker/api/server/profiler.go deleted file mode 100644 index 8bf8384..0000000 --- a/vendor/github.com/docker/docker/api/server/profiler.go +++ /dev/null @@ -1,41 +0,0 @@ -package server - -import ( - "expvar" - "fmt" - "net/http" - "net/http/pprof" - - "github.com/gorilla/mux" -) - -const debugPathPrefix = "/debug/" - -func profilerSetup(mainRouter *mux.Router) { - var r = mainRouter.PathPrefix(debugPathPrefix).Subrouter() - r.HandleFunc("/vars", expVars) - r.HandleFunc("/pprof/", pprof.Index) - r.HandleFunc("/pprof/cmdline", pprof.Cmdline) - r.HandleFunc("/pprof/profile", pprof.Profile) - r.HandleFunc("/pprof/symbol", pprof.Symbol) - r.HandleFunc("/pprof/trace", pprof.Trace) - r.HandleFunc("/pprof/block", pprof.Handler("block").ServeHTTP) - r.HandleFunc("/pprof/heap", pprof.Handler("heap").ServeHTTP) - r.HandleFunc("/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP) - r.HandleFunc("/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP) -} - -// Replicated from expvar.go as not public. -func expVars(w http.ResponseWriter, r *http.Request) { - first := true - w.Header().Set("Content-Type", "application/json; charset=utf-8") - fmt.Fprintf(w, "{\n") - expvar.Do(func(kv expvar.KeyValue) { - if !first { - fmt.Fprintf(w, ",\n") - } - first = false - fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) - }) - fmt.Fprintf(w, "\n}\n") -} diff --git a/vendor/github.com/docker/docker/api/server/router/build/backend.go b/vendor/github.com/docker/docker/api/server/router/build/backend.go deleted file mode 100644 index 0f01c11..0000000 --- a/vendor/github.com/docker/docker/api/server/router/build/backend.go +++ /dev/null @@ -1,20 +0,0 @@ -package build - -import ( - "io" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "golang.org/x/net/context" -) - -// Backend abstracts an image builder whose only purpose is to build an image referenced by an imageID. -type Backend interface { - // Build builds a Docker image referenced by an imageID string. - // - // Note: Tagging an image should not be done by a Builder, it should instead be done - // by the caller. - // - // TODO: make this return a reference instead of string - BuildFromContext(ctx context.Context, src io.ReadCloser, remote string, buildOptions *types.ImageBuildOptions, pg backend.ProgressWriter) (string, error) -} diff --git a/vendor/github.com/docker/docker/api/server/router/build/build.go b/vendor/github.com/docker/docker/api/server/router/build/build.go deleted file mode 100644 index 959498e..0000000 --- a/vendor/github.com/docker/docker/api/server/router/build/build.go +++ /dev/null @@ -1,29 +0,0 @@ -package build - -import "github.com/docker/docker/api/server/router" - -// buildRouter is a router to talk with the build controller -type buildRouter struct { - backend Backend - routes []router.Route -} - -// NewRouter initializes a new build router -func NewRouter(b Backend) router.Router { - r := &buildRouter{ - backend: b, - } - r.initRoutes() - return r -} - -// Routes returns the available routers to the build controller -func (r *buildRouter) Routes() []router.Route { - return r.routes -} - -func (r *buildRouter) initRoutes() { - r.routes = []router.Route{ - router.Cancellable(router.NewPostRoute("/build", r.postBuild)), - } -} diff --git a/vendor/github.com/docker/docker/api/server/router/build/build_routes.go b/vendor/github.com/docker/docker/api/server/router/build/build_routes.go deleted file mode 100644 index 75425b1..0000000 --- a/vendor/github.com/docker/docker/api/server/router/build/build_routes.go +++ /dev/null @@ -1,225 +0,0 @@ -package build - -import ( - "bytes" - "encoding/base64" - "encoding/json" - "fmt" - "io" - "net/http" - "runtime" - "strconv" - "strings" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/streamformatter" - "github.com/docker/go-units" - "golang.org/x/net/context" -) - -func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBuildOptions, error) { - version := httputils.VersionFromContext(ctx) - options := &types.ImageBuildOptions{} - if httputils.BoolValue(r, "forcerm") && versions.GreaterThanOrEqualTo(version, "1.12") { - options.Remove = true - } else if r.FormValue("rm") == "" && versions.GreaterThanOrEqualTo(version, "1.12") { - options.Remove = true - } else { - options.Remove = httputils.BoolValue(r, "rm") - } - if httputils.BoolValue(r, "pull") && versions.GreaterThanOrEqualTo(version, "1.16") { - options.PullParent = true - } - - options.Dockerfile = r.FormValue("dockerfile") - options.SuppressOutput = httputils.BoolValue(r, "q") - options.NoCache = httputils.BoolValue(r, "nocache") - options.ForceRemove = httputils.BoolValue(r, "forcerm") - options.MemorySwap = httputils.Int64ValueOrZero(r, "memswap") - options.Memory = httputils.Int64ValueOrZero(r, "memory") - options.CPUShares = httputils.Int64ValueOrZero(r, "cpushares") - options.CPUPeriod = httputils.Int64ValueOrZero(r, "cpuperiod") - options.CPUQuota = httputils.Int64ValueOrZero(r, "cpuquota") - options.CPUSetCPUs = r.FormValue("cpusetcpus") - options.CPUSetMems = r.FormValue("cpusetmems") - options.CgroupParent = r.FormValue("cgroupparent") - options.NetworkMode = r.FormValue("networkmode") - options.Tags = r.Form["t"] - options.SecurityOpt = r.Form["securityopt"] - options.Squash = httputils.BoolValue(r, "squash") - - if r.Form.Get("shmsize") != "" { - shmSize, err := strconv.ParseInt(r.Form.Get("shmsize"), 10, 64) - if err != nil { - return nil, err - } - options.ShmSize = shmSize - } - - if i := container.Isolation(r.FormValue("isolation")); i != "" { - if !container.Isolation.IsValid(i) { - return nil, fmt.Errorf("Unsupported isolation: %q", i) - } - options.Isolation = i - } - - if runtime.GOOS != "windows" && options.SecurityOpt != nil { - return nil, fmt.Errorf("the daemon on this platform does not support --security-opt to build") - } - - var buildUlimits = []*units.Ulimit{} - ulimitsJSON := r.FormValue("ulimits") - if ulimitsJSON != "" { - if err := json.Unmarshal([]byte(ulimitsJSON), &buildUlimits); err != nil { - return nil, err - } - options.Ulimits = buildUlimits - } - - var buildArgs = map[string]*string{} - buildArgsJSON := r.FormValue("buildargs") - - // Note that there are two ways a --build-arg might appear in the - // json of the query param: - // "foo":"bar" - // and "foo":nil - // The first is the normal case, ie. --build-arg foo=bar - // or --build-arg foo - // where foo's value was picked up from an env var. - // The second ("foo":nil) is where they put --build-arg foo - // but "foo" isn't set as an env var. In that case we can't just drop - // the fact they mentioned it, we need to pass that along to the builder - // so that it can print a warning about "foo" being unused if there is - // no "ARG foo" in the Dockerfile. - if buildArgsJSON != "" { - if err := json.Unmarshal([]byte(buildArgsJSON), &buildArgs); err != nil { - return nil, err - } - options.BuildArgs = buildArgs - } - - var labels = map[string]string{} - labelsJSON := r.FormValue("labels") - if labelsJSON != "" { - if err := json.Unmarshal([]byte(labelsJSON), &labels); err != nil { - return nil, err - } - options.Labels = labels - } - - var cacheFrom = []string{} - cacheFromJSON := r.FormValue("cachefrom") - if cacheFromJSON != "" { - if err := json.Unmarshal([]byte(cacheFromJSON), &cacheFrom); err != nil { - return nil, err - } - options.CacheFrom = cacheFrom - } - - return options, nil -} - -type syncWriter struct { - w io.Writer - mu sync.Mutex -} - -func (s *syncWriter) Write(b []byte) (count int, err error) { - s.mu.Lock() - count, err = s.w.Write(b) - s.mu.Unlock() - return -} - -func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var ( - authConfigs = map[string]types.AuthConfig{} - authConfigsEncoded = r.Header.Get("X-Registry-Config") - notVerboseBuffer = bytes.NewBuffer(nil) - ) - - if authConfigsEncoded != "" { - authConfigsJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authConfigsEncoded)) - if err := json.NewDecoder(authConfigsJSON).Decode(&authConfigs); err != nil { - // for a pull it is not an error if no auth was given - // to increase compatibility with the existing api it is defaulting - // to be empty. - } - } - - w.Header().Set("Content-Type", "application/json") - - output := ioutils.NewWriteFlusher(w) - defer output.Close() - sf := streamformatter.NewJSONStreamFormatter() - errf := func(err error) error { - if httputils.BoolValue(r, "q") && notVerboseBuffer.Len() > 0 { - output.Write(notVerboseBuffer.Bytes()) - } - // Do not write the error in the http output if it's still empty. - // This prevents from writing a 200(OK) when there is an internal error. - if !output.Flushed() { - return err - } - _, err = w.Write(sf.FormatError(err)) - if err != nil { - logrus.Warnf("could not write error response: %v", err) - } - return nil - } - - buildOptions, err := newImageBuildOptions(ctx, r) - if err != nil { - return errf(err) - } - buildOptions.AuthConfigs = authConfigs - - remoteURL := r.FormValue("remote") - - // Currently, only used if context is from a remote url. - // Look at code in DetectContextFromRemoteURL for more information. - createProgressReader := func(in io.ReadCloser) io.ReadCloser { - progressOutput := sf.NewProgressOutput(output, true) - if buildOptions.SuppressOutput { - progressOutput = sf.NewProgressOutput(notVerboseBuffer, true) - } - return progress.NewProgressReader(in, progressOutput, r.ContentLength, "Downloading context", remoteURL) - } - - out := io.Writer(output) - if buildOptions.SuppressOutput { - out = notVerboseBuffer - } - out = &syncWriter{w: out} - stdout := &streamformatter.StdoutFormatter{Writer: out, StreamFormatter: sf} - stderr := &streamformatter.StderrFormatter{Writer: out, StreamFormatter: sf} - - pg := backend.ProgressWriter{ - Output: out, - StdoutFormatter: stdout, - StderrFormatter: stderr, - ProgressReaderFunc: createProgressReader, - } - - imgID, err := br.backend.BuildFromContext(ctx, r.Body, remoteURL, buildOptions, pg) - if err != nil { - return errf(err) - } - - // Everything worked so if -q was provided the output from the daemon - // should be just the image ID and we'll print that to stdout. - if buildOptions.SuppressOutput { - stdout := &streamformatter.StdoutFormatter{Writer: output, StreamFormatter: sf} - fmt.Fprintf(stdout, "%s\n", string(imgID)) - } - - return nil -} diff --git a/vendor/github.com/docker/docker/api/server/router/checkpoint/backend.go b/vendor/github.com/docker/docker/api/server/router/checkpoint/backend.go deleted file mode 100644 index 8810f88..0000000 --- a/vendor/github.com/docker/docker/api/server/router/checkpoint/backend.go +++ /dev/null @@ -1,10 +0,0 @@ -package checkpoint - -import "github.com/docker/docker/api/types" - -// Backend for Checkpoint -type Backend interface { - CheckpointCreate(container string, config types.CheckpointCreateOptions) error - CheckpointDelete(container string, config types.CheckpointDeleteOptions) error - CheckpointList(container string, config types.CheckpointListOptions) ([]types.Checkpoint, error) -} diff --git a/vendor/github.com/docker/docker/api/server/router/checkpoint/checkpoint.go b/vendor/github.com/docker/docker/api/server/router/checkpoint/checkpoint.go deleted file mode 100644 index c1e9392..0000000 --- a/vendor/github.com/docker/docker/api/server/router/checkpoint/checkpoint.go +++ /dev/null @@ -1,36 +0,0 @@ -package checkpoint - -import ( - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/server/router" -) - -// checkpointRouter is a router to talk with the checkpoint controller -type checkpointRouter struct { - backend Backend - decoder httputils.ContainerDecoder - routes []router.Route -} - -// NewRouter initializes a new checkpoint router -func NewRouter(b Backend, decoder httputils.ContainerDecoder) router.Router { - r := &checkpointRouter{ - backend: b, - decoder: decoder, - } - r.initRoutes() - return r -} - -// Routes returns the available routers to the checkpoint controller -func (r *checkpointRouter) Routes() []router.Route { - return r.routes -} - -func (r *checkpointRouter) initRoutes() { - r.routes = []router.Route{ - router.Experimental(router.NewGetRoute("/containers/{name:.*}/checkpoints", r.getContainerCheckpoints)), - router.Experimental(router.NewPostRoute("/containers/{name:.*}/checkpoints", r.postContainerCheckpoint)), - router.Experimental(router.NewDeleteRoute("/containers/{name}/checkpoints/{checkpoint}", r.deleteContainerCheckpoint)), - } -} diff --git a/vendor/github.com/docker/docker/api/server/router/checkpoint/checkpoint_routes.go b/vendor/github.com/docker/docker/api/server/router/checkpoint/checkpoint_routes.go deleted file mode 100644 index f988431..0000000 --- a/vendor/github.com/docker/docker/api/server/router/checkpoint/checkpoint_routes.go +++ /dev/null @@ -1,65 +0,0 @@ -package checkpoint - -import ( - "encoding/json" - "net/http" - - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func (s *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - var options types.CheckpointCreateOptions - - decoder := json.NewDecoder(r.Body) - if err := decoder.Decode(&options); err != nil { - return err - } - - err := s.backend.CheckpointCreate(vars["name"], options) - if err != nil { - return err - } - - w.WriteHeader(http.StatusCreated) - return nil -} - -func (s *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - checkpoints, err := s.backend.CheckpointList(vars["name"], types.CheckpointListOptions{ - CheckpointDir: r.Form.Get("dir"), - }) - - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, checkpoints) -} - -func (s *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - err := s.backend.CheckpointDelete(vars["name"], types.CheckpointDeleteOptions{ - CheckpointDir: r.Form.Get("dir"), - CheckpointID: vars["checkpoint"], - }) - - if err != nil { - return err - } - - w.WriteHeader(http.StatusNoContent) - return nil -} diff --git a/vendor/github.com/docker/docker/api/server/router/container/backend.go b/vendor/github.com/docker/docker/api/server/router/container/backend.go deleted file mode 100644 index 0d20188..0000000 --- a/vendor/github.com/docker/docker/api/server/router/container/backend.go +++ /dev/null @@ -1,79 +0,0 @@ -package container - -import ( - "io" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/pkg/archive" -) - -// execBackend includes functions to implement to provide exec functionality. -type execBackend interface { - ContainerExecCreate(name string, config *types.ExecConfig) (string, error) - ContainerExecInspect(id string) (*backend.ExecInspect, error) - ContainerExecResize(name string, height, width int) error - ContainerExecStart(ctx context.Context, name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error - ExecExists(name string) (bool, error) -} - -// copyBackend includes functions to implement to provide container copy functionality. -type copyBackend interface { - ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error) - ContainerCopy(name string, res string) (io.ReadCloser, error) - ContainerExport(name string, out io.Writer) error - ContainerExtractToDir(name, path string, noOverwriteDirNonDir bool, content io.Reader) error - ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error) -} - -// stateBackend includes functions to implement to provide container state lifecycle functionality. -type stateBackend interface { - ContainerCreate(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error) - ContainerKill(name string, sig uint64) error - ContainerPause(name string) error - ContainerRename(oldName, newName string) error - ContainerResize(name string, height, width int) error - ContainerRestart(name string, seconds *int) error - ContainerRm(name string, config *types.ContainerRmConfig) error - ContainerStart(name string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error - ContainerStop(name string, seconds *int) error - ContainerUnpause(name string) error - ContainerUpdate(name string, hostConfig *container.HostConfig) (container.ContainerUpdateOKBody, error) - ContainerWait(name string, timeout time.Duration) (int, error) -} - -// monitorBackend includes functions to implement to provide containers monitoring functionality. -type monitorBackend interface { - ContainerChanges(name string) ([]archive.Change, error) - ContainerInspect(name string, size bool, version string) (interface{}, error) - ContainerLogs(ctx context.Context, name string, config *backend.ContainerLogsConfig, started chan struct{}) error - ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error - ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) - - Containers(config *types.ContainerListOptions) ([]*types.Container, error) -} - -// attachBackend includes function to implement to provide container attaching functionality. -type attachBackend interface { - ContainerAttach(name string, c *backend.ContainerAttachConfig) error -} - -// systemBackend includes functions to implement to provide system wide containers functionality -type systemBackend interface { - ContainersPrune(pruneFilters filters.Args) (*types.ContainersPruneReport, error) -} - -// Backend is all the methods that need to be implemented to provide container specific functionality. -type Backend interface { - execBackend - copyBackend - stateBackend - monitorBackend - attachBackend - systemBackend -} diff --git a/vendor/github.com/docker/docker/api/server/router/container/container.go b/vendor/github.com/docker/docker/api/server/router/container/container.go deleted file mode 100644 index bbed7e9..0000000 --- a/vendor/github.com/docker/docker/api/server/router/container/container.go +++ /dev/null @@ -1,77 +0,0 @@ -package container - -import ( - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/server/router" -) - -type validationError struct { - error -} - -func (validationError) IsValidationError() bool { - return true -} - -// containerRouter is a router to talk with the container controller -type containerRouter struct { - backend Backend - decoder httputils.ContainerDecoder - routes []router.Route -} - -// NewRouter initializes a new container router -func NewRouter(b Backend, decoder httputils.ContainerDecoder) router.Router { - r := &containerRouter{ - backend: b, - decoder: decoder, - } - r.initRoutes() - return r -} - -// Routes returns the available routes to the container controller -func (r *containerRouter) Routes() []router.Route { - return r.routes -} - -// initRoutes initializes the routes in container router -func (r *containerRouter) initRoutes() { - r.routes = []router.Route{ - // HEAD - router.NewHeadRoute("/containers/{name:.*}/archive", r.headContainersArchive), - // GET - router.NewGetRoute("/containers/json", r.getContainersJSON), - router.NewGetRoute("/containers/{name:.*}/export", r.getContainersExport), - router.NewGetRoute("/containers/{name:.*}/changes", r.getContainersChanges), - router.NewGetRoute("/containers/{name:.*}/json", r.getContainersByName), - router.NewGetRoute("/containers/{name:.*}/top", r.getContainersTop), - router.Cancellable(router.NewGetRoute("/containers/{name:.*}/logs", r.getContainersLogs)), - router.Cancellable(router.NewGetRoute("/containers/{name:.*}/stats", r.getContainersStats)), - router.NewGetRoute("/containers/{name:.*}/attach/ws", r.wsContainersAttach), - router.NewGetRoute("/exec/{id:.*}/json", r.getExecByID), - router.NewGetRoute("/containers/{name:.*}/archive", r.getContainersArchive), - // POST - router.NewPostRoute("/containers/create", r.postContainersCreate), - router.NewPostRoute("/containers/{name:.*}/kill", r.postContainersKill), - router.NewPostRoute("/containers/{name:.*}/pause", r.postContainersPause), - router.NewPostRoute("/containers/{name:.*}/unpause", r.postContainersUnpause), - router.NewPostRoute("/containers/{name:.*}/restart", r.postContainersRestart), - router.NewPostRoute("/containers/{name:.*}/start", r.postContainersStart), - router.NewPostRoute("/containers/{name:.*}/stop", r.postContainersStop), - router.NewPostRoute("/containers/{name:.*}/wait", r.postContainersWait), - router.NewPostRoute("/containers/{name:.*}/resize", r.postContainersResize), - router.NewPostRoute("/containers/{name:.*}/attach", r.postContainersAttach), - router.NewPostRoute("/containers/{name:.*}/copy", r.postContainersCopy), // Deprecated since 1.8, Errors out since 1.12 - router.NewPostRoute("/containers/{name:.*}/exec", r.postContainerExecCreate), - router.NewPostRoute("/exec/{name:.*}/start", r.postContainerExecStart), - router.NewPostRoute("/exec/{name:.*}/resize", r.postContainerExecResize), - router.NewPostRoute("/containers/{name:.*}/rename", r.postContainerRename), - router.NewPostRoute("/containers/{name:.*}/update", r.postContainerUpdate), - router.NewPostRoute("/containers/prune", r.postContainersPrune), - // PUT - router.NewPutRoute("/containers/{name:.*}/archive", r.putContainersArchive), - // DELETE - router.NewDeleteRoute("/containers/{name:.*}", r.deleteContainers), - } -} diff --git a/vendor/github.com/docker/docker/api/server/router/container/container_routes.go b/vendor/github.com/docker/docker/api/server/router/container/container_routes.go deleted file mode 100644 index 9c9bc0f..0000000 --- a/vendor/github.com/docker/docker/api/server/router/container/container_routes.go +++ /dev/null @@ -1,554 +0,0 @@ -package container - -import ( - "encoding/json" - "fmt" - "io" - "net/http" - "strconv" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/signal" - "golang.org/x/net/context" - "golang.org/x/net/websocket" -) - -func (s *containerRouter) getContainersJSON(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - filter, err := filters.FromParam(r.Form.Get("filters")) - if err != nil { - return err - } - - config := &types.ContainerListOptions{ - All: httputils.BoolValue(r, "all"), - Size: httputils.BoolValue(r, "size"), - Since: r.Form.Get("since"), - Before: r.Form.Get("before"), - Filters: filter, - } - - if tmpLimit := r.Form.Get("limit"); tmpLimit != "" { - limit, err := strconv.Atoi(tmpLimit) - if err != nil { - return err - } - config.Limit = limit - } - - containers, err := s.backend.Containers(config) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, containers) -} - -func (s *containerRouter) getContainersStats(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - stream := httputils.BoolValueOrDefault(r, "stream", true) - if !stream { - w.Header().Set("Content-Type", "application/json") - } - - config := &backend.ContainerStatsConfig{ - Stream: stream, - OutStream: w, - Version: string(httputils.VersionFromContext(ctx)), - } - - return s.backend.ContainerStats(ctx, vars["name"], config) -} - -func (s *containerRouter) getContainersLogs(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - // Args are validated before the stream starts because when it starts we're - // sending HTTP 200 by writing an empty chunk of data to tell the client that - // daemon is going to stream. By sending this initial HTTP 200 we can't report - // any error after the stream starts (i.e. container not found, wrong parameters) - // with the appropriate status code. - stdout, stderr := httputils.BoolValue(r, "stdout"), httputils.BoolValue(r, "stderr") - if !(stdout || stderr) { - return fmt.Errorf("Bad parameters: you must choose at least one stream") - } - - containerName := vars["name"] - logsConfig := &backend.ContainerLogsConfig{ - ContainerLogsOptions: types.ContainerLogsOptions{ - Follow: httputils.BoolValue(r, "follow"), - Timestamps: httputils.BoolValue(r, "timestamps"), - Since: r.Form.Get("since"), - Tail: r.Form.Get("tail"), - ShowStdout: stdout, - ShowStderr: stderr, - Details: httputils.BoolValue(r, "details"), - }, - OutStream: w, - } - - chStarted := make(chan struct{}) - if err := s.backend.ContainerLogs(ctx, containerName, logsConfig, chStarted); err != nil { - select { - case <-chStarted: - // The client may be expecting all of the data we're sending to - // be multiplexed, so send it through OutStream, which will - // have been set up to handle that if needed. - fmt.Fprintf(logsConfig.OutStream, "Error running logs job: %v\n", err) - default: - return err - } - } - - return nil -} - -func (s *containerRouter) getContainersExport(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - return s.backend.ContainerExport(vars["name"], w) -} - -func (s *containerRouter) postContainersStart(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - // If contentLength is -1, we can assumed chunked encoding - // or more technically that the length is unknown - // https://golang.org/src/pkg/net/http/request.go#L139 - // net/http otherwise seems to swallow any headers related to chunked encoding - // including r.TransferEncoding - // allow a nil body for backwards compatibility - - version := httputils.VersionFromContext(ctx) - var hostConfig *container.HostConfig - // A non-nil json object is at least 7 characters. - if r.ContentLength > 7 || r.ContentLength == -1 { - if versions.GreaterThanOrEqualTo(version, "1.24") { - return validationError{fmt.Errorf("starting container with non-empty request body was deprecated since v1.10 and removed in v1.12")} - } - - if err := httputils.CheckForJSON(r); err != nil { - return err - } - - c, err := s.decoder.DecodeHostConfig(r.Body) - if err != nil { - return err - } - hostConfig = c - } - - if err := httputils.ParseForm(r); err != nil { - return err - } - - checkpoint := r.Form.Get("checkpoint") - checkpointDir := r.Form.Get("checkpoint-dir") - if err := s.backend.ContainerStart(vars["name"], hostConfig, checkpoint, checkpointDir); err != nil { - return err - } - - w.WriteHeader(http.StatusNoContent) - return nil -} - -func (s *containerRouter) postContainersStop(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - var seconds *int - if tmpSeconds := r.Form.Get("t"); tmpSeconds != "" { - valSeconds, err := strconv.Atoi(tmpSeconds) - if err != nil { - return err - } - seconds = &valSeconds - } - - if err := s.backend.ContainerStop(vars["name"], seconds); err != nil { - return err - } - w.WriteHeader(http.StatusNoContent) - - return nil -} - -type errContainerIsRunning interface { - ContainerIsRunning() bool -} - -func (s *containerRouter) postContainersKill(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - var sig syscall.Signal - name := vars["name"] - - // If we have a signal, look at it. Otherwise, do nothing - if sigStr := r.Form.Get("signal"); sigStr != "" { - var err error - if sig, err = signal.ParseSignal(sigStr); err != nil { - return err - } - } - - if err := s.backend.ContainerKill(name, uint64(sig)); err != nil { - var isStopped bool - if e, ok := err.(errContainerIsRunning); ok { - isStopped = !e.ContainerIsRunning() - } - - // Return error that's not caused because the container is stopped. - // Return error if the container is not running and the api is >= 1.20 - // to keep backwards compatibility. - version := httputils.VersionFromContext(ctx) - if versions.GreaterThanOrEqualTo(version, "1.20") || !isStopped { - return fmt.Errorf("Cannot kill container %s: %v", name, err) - } - } - - w.WriteHeader(http.StatusNoContent) - return nil -} - -func (s *containerRouter) postContainersRestart(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - var seconds *int - if tmpSeconds := r.Form.Get("t"); tmpSeconds != "" { - valSeconds, err := strconv.Atoi(tmpSeconds) - if err != nil { - return err - } - seconds = &valSeconds - } - - if err := s.backend.ContainerRestart(vars["name"], seconds); err != nil { - return err - } - - w.WriteHeader(http.StatusNoContent) - - return nil -} - -func (s *containerRouter) postContainersPause(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - if err := s.backend.ContainerPause(vars["name"]); err != nil { - return err - } - - w.WriteHeader(http.StatusNoContent) - - return nil -} - -func (s *containerRouter) postContainersUnpause(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - if err := s.backend.ContainerUnpause(vars["name"]); err != nil { - return err - } - - w.WriteHeader(http.StatusNoContent) - - return nil -} - -func (s *containerRouter) postContainersWait(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - status, err := s.backend.ContainerWait(vars["name"], -1*time.Second) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, &container.ContainerWaitOKBody{ - StatusCode: int64(status), - }) -} - -func (s *containerRouter) getContainersChanges(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - changes, err := s.backend.ContainerChanges(vars["name"]) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, changes) -} - -func (s *containerRouter) getContainersTop(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - procList, err := s.backend.ContainerTop(vars["name"], r.Form.Get("ps_args")) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, procList) -} - -func (s *containerRouter) postContainerRename(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - name := vars["name"] - newName := r.Form.Get("name") - if err := s.backend.ContainerRename(name, newName); err != nil { - return err - } - w.WriteHeader(http.StatusNoContent) - return nil -} - -func (s *containerRouter) postContainerUpdate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - if err := httputils.CheckForJSON(r); err != nil { - return err - } - - var updateConfig container.UpdateConfig - - decoder := json.NewDecoder(r.Body) - if err := decoder.Decode(&updateConfig); err != nil { - return err - } - - hostConfig := &container.HostConfig{ - Resources: updateConfig.Resources, - RestartPolicy: updateConfig.RestartPolicy, - } - - name := vars["name"] - resp, err := s.backend.ContainerUpdate(name, hostConfig) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, resp) -} - -func (s *containerRouter) postContainersCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - if err := httputils.CheckForJSON(r); err != nil { - return err - } - - name := r.Form.Get("name") - - config, hostConfig, networkingConfig, err := s.decoder.DecodeConfig(r.Body) - if err != nil { - return err - } - version := httputils.VersionFromContext(ctx) - adjustCPUShares := versions.LessThan(version, "1.19") - - ccr, err := s.backend.ContainerCreate(types.ContainerCreateConfig{ - Name: name, - Config: config, - HostConfig: hostConfig, - NetworkingConfig: networkingConfig, - AdjustCPUShares: adjustCPUShares, - }) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusCreated, ccr) -} - -func (s *containerRouter) deleteContainers(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - name := vars["name"] - config := &types.ContainerRmConfig{ - ForceRemove: httputils.BoolValue(r, "force"), - RemoveVolume: httputils.BoolValue(r, "v"), - RemoveLink: httputils.BoolValue(r, "link"), - } - - if err := s.backend.ContainerRm(name, config); err != nil { - return err - } - - w.WriteHeader(http.StatusNoContent) - - return nil -} - -func (s *containerRouter) postContainersResize(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - height, err := strconv.Atoi(r.Form.Get("h")) - if err != nil { - return err - } - width, err := strconv.Atoi(r.Form.Get("w")) - if err != nil { - return err - } - - return s.backend.ContainerResize(vars["name"], height, width) -} - -func (s *containerRouter) postContainersAttach(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - err := httputils.ParseForm(r) - if err != nil { - return err - } - containerName := vars["name"] - - _, upgrade := r.Header["Upgrade"] - detachKeys := r.FormValue("detachKeys") - - hijacker, ok := w.(http.Hijacker) - if !ok { - return fmt.Errorf("error attaching to container %s, hijack connection missing", containerName) - } - - setupStreams := func() (io.ReadCloser, io.Writer, io.Writer, error) { - conn, _, err := hijacker.Hijack() - if err != nil { - return nil, nil, nil, err - } - - // set raw mode - conn.Write([]byte{}) - - if upgrade { - fmt.Fprintf(conn, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n") - } else { - fmt.Fprintf(conn, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n") - } - - closer := func() error { - httputils.CloseStreams(conn) - return nil - } - return ioutils.NewReadCloserWrapper(conn, closer), conn, conn, nil - } - - attachConfig := &backend.ContainerAttachConfig{ - GetStreams: setupStreams, - UseStdin: httputils.BoolValue(r, "stdin"), - UseStdout: httputils.BoolValue(r, "stdout"), - UseStderr: httputils.BoolValue(r, "stderr"), - Logs: httputils.BoolValue(r, "logs"), - Stream: httputils.BoolValue(r, "stream"), - DetachKeys: detachKeys, - MuxStreams: true, - } - - if err = s.backend.ContainerAttach(containerName, attachConfig); err != nil { - logrus.Errorf("Handler for %s %s returned error: %v", r.Method, r.URL.Path, err) - // Remember to close stream if error happens - conn, _, errHijack := hijacker.Hijack() - if errHijack == nil { - statusCode := httputils.GetHTTPErrorStatusCode(err) - statusText := http.StatusText(statusCode) - fmt.Fprintf(conn, "HTTP/1.1 %d %s\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n%s\r\n", statusCode, statusText, err.Error()) - httputils.CloseStreams(conn) - } else { - logrus.Errorf("Error Hijacking: %v", err) - } - } - return nil -} - -func (s *containerRouter) wsContainersAttach(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - containerName := vars["name"] - - var err error - detachKeys := r.FormValue("detachKeys") - - done := make(chan struct{}) - started := make(chan struct{}) - - setupStreams := func() (io.ReadCloser, io.Writer, io.Writer, error) { - wsChan := make(chan *websocket.Conn) - h := func(conn *websocket.Conn) { - wsChan <- conn - <-done - } - - srv := websocket.Server{Handler: h, Handshake: nil} - go func() { - close(started) - srv.ServeHTTP(w, r) - }() - - conn := <-wsChan - return conn, conn, conn, nil - } - - attachConfig := &backend.ContainerAttachConfig{ - GetStreams: setupStreams, - Logs: httputils.BoolValue(r, "logs"), - Stream: httputils.BoolValue(r, "stream"), - DetachKeys: detachKeys, - UseStdin: true, - UseStdout: true, - UseStderr: true, - MuxStreams: false, // TODO: this should be true since it's a single stream for both stdout and stderr - } - - err = s.backend.ContainerAttach(containerName, attachConfig) - close(done) - select { - case <-started: - logrus.Errorf("Error attaching websocket: %s", err) - return nil - default: - } - return err -} - -func (s *containerRouter) postContainersPrune(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - pruneFilters, err := filters.FromParam(r.Form.Get("filters")) - if err != nil { - return err - } - - pruneReport, err := s.backend.ContainersPrune(pruneFilters) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, pruneReport) -} diff --git a/vendor/github.com/docker/docker/api/server/router/container/copy.go b/vendor/github.com/docker/docker/api/server/router/container/copy.go deleted file mode 100644 index ede6dff..0000000 --- a/vendor/github.com/docker/docker/api/server/router/container/copy.go +++ /dev/null @@ -1,119 +0,0 @@ -package container - -import ( - "encoding/base64" - "encoding/json" - "fmt" - "io" - "net/http" - "os" - "strings" - - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/versions" - "golang.org/x/net/context" -) - -// postContainersCopy is deprecated in favor of getContainersArchive. -func (s *containerRouter) postContainersCopy(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - // Deprecated since 1.8, Errors out since 1.12 - version := httputils.VersionFromContext(ctx) - if versions.GreaterThanOrEqualTo(version, "1.24") { - w.WriteHeader(http.StatusNotFound) - return nil - } - if err := httputils.CheckForJSON(r); err != nil { - return err - } - - cfg := types.CopyConfig{} - if err := json.NewDecoder(r.Body).Decode(&cfg); err != nil { - return err - } - - if cfg.Resource == "" { - return fmt.Errorf("Path cannot be empty") - } - - data, err := s.backend.ContainerCopy(vars["name"], cfg.Resource) - if err != nil { - if strings.Contains(strings.ToLower(err.Error()), "no such container") { - w.WriteHeader(http.StatusNotFound) - return nil - } - if os.IsNotExist(err) { - return fmt.Errorf("Could not find the file %s in container %s", cfg.Resource, vars["name"]) - } - return err - } - defer data.Close() - - w.Header().Set("Content-Type", "application/x-tar") - if _, err := io.Copy(w, data); err != nil { - return err - } - - return nil -} - -// // Encode the stat to JSON, base64 encode, and place in a header. -func setContainerPathStatHeader(stat *types.ContainerPathStat, header http.Header) error { - statJSON, err := json.Marshal(stat) - if err != nil { - return err - } - - header.Set( - "X-Docker-Container-Path-Stat", - base64.StdEncoding.EncodeToString(statJSON), - ) - - return nil -} - -func (s *containerRouter) headContainersArchive(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - v, err := httputils.ArchiveFormValues(r, vars) - if err != nil { - return err - } - - stat, err := s.backend.ContainerStatPath(v.Name, v.Path) - if err != nil { - return err - } - - return setContainerPathStatHeader(stat, w.Header()) -} - -func (s *containerRouter) getContainersArchive(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - v, err := httputils.ArchiveFormValues(r, vars) - if err != nil { - return err - } - - tarArchive, stat, err := s.backend.ContainerArchivePath(v.Name, v.Path) - if err != nil { - return err - } - defer tarArchive.Close() - - if err := setContainerPathStatHeader(stat, w.Header()); err != nil { - return err - } - - w.Header().Set("Content-Type", "application/x-tar") - _, err = io.Copy(w, tarArchive) - - return err -} - -func (s *containerRouter) putContainersArchive(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - v, err := httputils.ArchiveFormValues(r, vars) - if err != nil { - return err - } - - noOverwriteDirNonDir := httputils.BoolValue(r, "noOverwriteDirNonDir") - return s.backend.ContainerExtractToDir(v.Name, v.Path, noOverwriteDirNonDir, r.Body) -} diff --git a/vendor/github.com/docker/docker/api/server/router/container/exec.go b/vendor/github.com/docker/docker/api/server/router/container/exec.go deleted file mode 100644 index 1134a0e..0000000 --- a/vendor/github.com/docker/docker/api/server/router/container/exec.go +++ /dev/null @@ -1,140 +0,0 @@ -package container - -import ( - "encoding/json" - "fmt" - "io" - "net/http" - "strconv" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/pkg/stdcopy" - "golang.org/x/net/context" -) - -func (s *containerRouter) getExecByID(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - eConfig, err := s.backend.ContainerExecInspect(vars["id"]) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, eConfig) -} - -func (s *containerRouter) postContainerExecCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - if err := httputils.CheckForJSON(r); err != nil { - return err - } - name := vars["name"] - - execConfig := &types.ExecConfig{} - if err := json.NewDecoder(r.Body).Decode(execConfig); err != nil { - return err - } - - if len(execConfig.Cmd) == 0 { - return fmt.Errorf("No exec command specified") - } - - // Register an instance of Exec in container. - id, err := s.backend.ContainerExecCreate(name, execConfig) - if err != nil { - logrus.Errorf("Error setting up exec command in container %s: %v", name, err) - return err - } - - return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{ - ID: id, - }) -} - -// TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start. -func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - version := httputils.VersionFromContext(ctx) - if versions.GreaterThan(version, "1.21") { - if err := httputils.CheckForJSON(r); err != nil { - return err - } - } - - var ( - execName = vars["name"] - stdin, inStream io.ReadCloser - stdout, stderr, outStream io.Writer - ) - - execStartCheck := &types.ExecStartCheck{} - if err := json.NewDecoder(r.Body).Decode(execStartCheck); err != nil { - return err - } - - if exists, err := s.backend.ExecExists(execName); !exists { - return err - } - - if !execStartCheck.Detach { - var err error - // Setting up the streaming http interface. - inStream, outStream, err = httputils.HijackConnection(w) - if err != nil { - return err - } - defer httputils.CloseStreams(inStream, outStream) - - if _, ok := r.Header["Upgrade"]; ok { - fmt.Fprint(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n") - } else { - fmt.Fprint(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n") - } - - // copy headers that were removed as part of hijack - if err := w.Header().WriteSubset(outStream, nil); err != nil { - return err - } - fmt.Fprint(outStream, "\r\n") - - stdin = inStream - stdout = outStream - if !execStartCheck.Tty { - stderr = stdcopy.NewStdWriter(outStream, stdcopy.Stderr) - stdout = stdcopy.NewStdWriter(outStream, stdcopy.Stdout) - } - } - - // Now run the user process in container. - // Maybe we should we pass ctx here if we're not detaching? - if err := s.backend.ContainerExecStart(context.Background(), execName, stdin, stdout, stderr); err != nil { - if execStartCheck.Detach { - return err - } - stdout.Write([]byte(err.Error() + "\r\n")) - logrus.Errorf("Error running exec in container: %v", err) - } - return nil -} - -func (s *containerRouter) postContainerExecResize(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - height, err := strconv.Atoi(r.Form.Get("h")) - if err != nil { - return err - } - width, err := strconv.Atoi(r.Form.Get("w")) - if err != nil { - return err - } - - return s.backend.ContainerExecResize(vars["name"], height, width) -} diff --git a/vendor/github.com/docker/docker/api/server/router/container/inspect.go b/vendor/github.com/docker/docker/api/server/router/container/inspect.go deleted file mode 100644 index dbbced7..0000000 --- a/vendor/github.com/docker/docker/api/server/router/container/inspect.go +++ /dev/null @@ -1,21 +0,0 @@ -package container - -import ( - "net/http" - - "github.com/docker/docker/api/server/httputils" - "golang.org/x/net/context" -) - -// getContainersByName inspects container's configuration and serializes it as json. -func (s *containerRouter) getContainersByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - displaySize := httputils.BoolValue(r, "size") - - version := httputils.VersionFromContext(ctx) - json, err := s.backend.ContainerInspect(vars["name"], displaySize, version) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, json) -} diff --git a/vendor/github.com/docker/docker/api/server/router/experimental.go b/vendor/github.com/docker/docker/api/server/router/experimental.go deleted file mode 100644 index 51385c2..0000000 --- a/vendor/github.com/docker/docker/api/server/router/experimental.go +++ /dev/null @@ -1,67 +0,0 @@ -package router - -import ( - "errors" - "net/http" - - "golang.org/x/net/context" - - apierrors "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/server/httputils" -) - -var ( - errExperimentalFeature = errors.New("This experimental feature is disabled by default. Start the Docker daemon with --experimental in order to enable it.") -) - -// ExperimentalRoute defines an experimental API route that can be enabled or disabled. -type ExperimentalRoute interface { - Route - - Enable() - Disable() -} - -// experimentalRoute defines an experimental API route that can be enabled or disabled. -// It implements ExperimentalRoute -type experimentalRoute struct { - local Route - handler httputils.APIFunc -} - -// Enable enables this experimental route -func (r *experimentalRoute) Enable() { - r.handler = r.local.Handler() -} - -// Disable disables the experimental route -func (r *experimentalRoute) Disable() { - r.handler = experimentalHandler -} - -func experimentalHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - return apierrors.NewErrorWithStatusCode(errExperimentalFeature, http.StatusNotImplemented) -} - -// Handler returns returns the APIFunc to let the server wrap it in middlewares. -func (r *experimentalRoute) Handler() httputils.APIFunc { - return r.handler -} - -// Method returns the http method that the route responds to. -func (r *experimentalRoute) Method() string { - return r.local.Method() -} - -// Path returns the subpath where the route responds to. -func (r *experimentalRoute) Path() string { - return r.local.Path() -} - -// Experimental will mark a route as experimental. -func Experimental(r Route) Route { - return &experimentalRoute{ - local: r, - handler: experimentalHandler, - } -} diff --git a/vendor/github.com/docker/docker/api/server/router/image/backend.go b/vendor/github.com/docker/docker/api/server/router/image/backend.go deleted file mode 100644 index 19a67a5..0000000 --- a/vendor/github.com/docker/docker/api/server/router/image/backend.go +++ /dev/null @@ -1,45 +0,0 @@ -package image - -import ( - "io" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/registry" - "golang.org/x/net/context" -) - -// Backend is all the methods that need to be implemented -// to provide image specific functionality. -type Backend interface { - containerBackend - imageBackend - importExportBackend - registryBackend -} - -type containerBackend interface { - Commit(name string, config *backend.ContainerCommitConfig) (imageID string, err error) -} - -type imageBackend interface { - ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) - ImageHistory(imageName string) ([]*types.ImageHistory, error) - Images(imageFilters filters.Args, all bool, withExtraAttrs bool) ([]*types.ImageSummary, error) - LookupImage(name string) (*types.ImageInspect, error) - TagImage(imageName, repository, tag string) error - ImagesPrune(pruneFilters filters.Args) (*types.ImagesPruneReport, error) -} - -type importExportBackend interface { - LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error - ImportImage(src string, repository, tag string, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error - ExportImage(names []string, outStream io.Writer) error -} - -type registryBackend interface { - PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error - PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error - SearchRegistryForImages(ctx context.Context, filtersArgs string, term string, limit int, authConfig *types.AuthConfig, metaHeaders map[string][]string) (*registry.SearchResults, error) -} diff --git a/vendor/github.com/docker/docker/api/server/router/image/image.go b/vendor/github.com/docker/docker/api/server/router/image/image.go deleted file mode 100644 index 54a4d51..0000000 --- a/vendor/github.com/docker/docker/api/server/router/image/image.go +++ /dev/null @@ -1,50 +0,0 @@ -package image - -import ( - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/server/router" -) - -// imageRouter is a router to talk with the image controller -type imageRouter struct { - backend Backend - decoder httputils.ContainerDecoder - routes []router.Route -} - -// NewRouter initializes a new image router -func NewRouter(backend Backend, decoder httputils.ContainerDecoder) router.Router { - r := &imageRouter{ - backend: backend, - decoder: decoder, - } - r.initRoutes() - return r -} - -// Routes returns the available routes to the image controller -func (r *imageRouter) Routes() []router.Route { - return r.routes -} - -// initRoutes initializes the routes in the image router -func (r *imageRouter) initRoutes() { - r.routes = []router.Route{ - // GET - router.NewGetRoute("/images/json", r.getImagesJSON), - router.NewGetRoute("/images/search", r.getImagesSearch), - router.NewGetRoute("/images/get", r.getImagesGet), - router.NewGetRoute("/images/{name:.*}/get", r.getImagesGet), - router.NewGetRoute("/images/{name:.*}/history", r.getImagesHistory), - router.NewGetRoute("/images/{name:.*}/json", r.getImagesByName), - // POST - router.NewPostRoute("/commit", r.postCommit), - router.NewPostRoute("/images/load", r.postImagesLoad), - router.Cancellable(router.NewPostRoute("/images/create", r.postImagesCreate)), - router.Cancellable(router.NewPostRoute("/images/{name:.*}/push", r.postImagesPush)), - router.NewPostRoute("/images/{name:.*}/tag", r.postImagesTag), - router.NewPostRoute("/images/prune", r.postImagesPrune), - // DELETE - router.NewDeleteRoute("/images/{name:.*}", r.deleteImages), - } -} diff --git a/vendor/github.com/docker/docker/api/server/router/image/image_routes.go b/vendor/github.com/docker/docker/api/server/router/image/image_routes.go deleted file mode 100644 index 6940365..0000000 --- a/vendor/github.com/docker/docker/api/server/router/image/image_routes.go +++ /dev/null @@ -1,344 +0,0 @@ -package image - -import ( - "encoding/base64" - "encoding/json" - "fmt" - "io" - "net/http" - "strconv" - "strings" - - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/streamformatter" - "github.com/docker/docker/registry" - "golang.org/x/net/context" -) - -func (s *imageRouter) postCommit(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - if err := httputils.CheckForJSON(r); err != nil { - return err - } - - cname := r.Form.Get("container") - - pause := httputils.BoolValue(r, "pause") - version := httputils.VersionFromContext(ctx) - if r.FormValue("pause") == "" && versions.GreaterThanOrEqualTo(version, "1.13") { - pause = true - } - - c, _, _, err := s.decoder.DecodeConfig(r.Body) - if err != nil && err != io.EOF { //Do not fail if body is empty. - return err - } - if c == nil { - c = &container.Config{} - } - - commitCfg := &backend.ContainerCommitConfig{ - ContainerCommitConfig: types.ContainerCommitConfig{ - Pause: pause, - Repo: r.Form.Get("repo"), - Tag: r.Form.Get("tag"), - Author: r.Form.Get("author"), - Comment: r.Form.Get("comment"), - Config: c, - MergeConfigs: true, - }, - Changes: r.Form["changes"], - } - - imgID, err := s.backend.Commit(cname, commitCfg) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{ - ID: string(imgID), - }) -} - -// Creates an image from Pull or from Import -func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - var ( - image = r.Form.Get("fromImage") - repo = r.Form.Get("repo") - tag = r.Form.Get("tag") - message = r.Form.Get("message") - err error - output = ioutils.NewWriteFlusher(w) - ) - defer output.Close() - - w.Header().Set("Content-Type", "application/json") - - if image != "" { //pull - metaHeaders := map[string][]string{} - for k, v := range r.Header { - if strings.HasPrefix(k, "X-Meta-") { - metaHeaders[k] = v - } - } - - authEncoded := r.Header.Get("X-Registry-Auth") - authConfig := &types.AuthConfig{} - if authEncoded != "" { - authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) - if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil { - // for a pull it is not an error if no auth was given - // to increase compatibility with the existing api it is defaulting to be empty - authConfig = &types.AuthConfig{} - } - } - - err = s.backend.PullImage(ctx, image, tag, metaHeaders, authConfig, output) - } else { //import - src := r.Form.Get("fromSrc") - // 'err' MUST NOT be defined within this block, we need any error - // generated from the download to be available to the output - // stream processing below - err = s.backend.ImportImage(src, repo, tag, message, r.Body, output, r.Form["changes"]) - } - if err != nil { - if !output.Flushed() { - return err - } - sf := streamformatter.NewJSONStreamFormatter() - output.Write(sf.FormatError(err)) - } - - return nil -} - -func (s *imageRouter) postImagesPush(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - metaHeaders := map[string][]string{} - for k, v := range r.Header { - if strings.HasPrefix(k, "X-Meta-") { - metaHeaders[k] = v - } - } - if err := httputils.ParseForm(r); err != nil { - return err - } - authConfig := &types.AuthConfig{} - - authEncoded := r.Header.Get("X-Registry-Auth") - if authEncoded != "" { - // the new format is to handle the authConfig as a header - authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) - if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil { - // to increase compatibility to existing api it is defaulting to be empty - authConfig = &types.AuthConfig{} - } - } else { - // the old format is supported for compatibility if there was no authConfig header - if err := json.NewDecoder(r.Body).Decode(authConfig); err != nil { - return fmt.Errorf("Bad parameters and missing X-Registry-Auth: %v", err) - } - } - - image := vars["name"] - tag := r.Form.Get("tag") - - output := ioutils.NewWriteFlusher(w) - defer output.Close() - - w.Header().Set("Content-Type", "application/json") - - if err := s.backend.PushImage(ctx, image, tag, metaHeaders, authConfig, output); err != nil { - if !output.Flushed() { - return err - } - sf := streamformatter.NewJSONStreamFormatter() - output.Write(sf.FormatError(err)) - } - return nil -} - -func (s *imageRouter) getImagesGet(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - w.Header().Set("Content-Type", "application/x-tar") - - output := ioutils.NewWriteFlusher(w) - defer output.Close() - var names []string - if name, ok := vars["name"]; ok { - names = []string{name} - } else { - names = r.Form["names"] - } - - if err := s.backend.ExportImage(names, output); err != nil { - if !output.Flushed() { - return err - } - sf := streamformatter.NewJSONStreamFormatter() - output.Write(sf.FormatError(err)) - } - return nil -} - -func (s *imageRouter) postImagesLoad(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - quiet := httputils.BoolValueOrDefault(r, "quiet", true) - - w.Header().Set("Content-Type", "application/json") - - output := ioutils.NewWriteFlusher(w) - defer output.Close() - if err := s.backend.LoadImage(r.Body, output, quiet); err != nil { - output.Write(streamformatter.NewJSONStreamFormatter().FormatError(err)) - } - return nil -} - -func (s *imageRouter) deleteImages(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - name := vars["name"] - - if strings.TrimSpace(name) == "" { - return fmt.Errorf("image name cannot be blank") - } - - force := httputils.BoolValue(r, "force") - prune := !httputils.BoolValue(r, "noprune") - - list, err := s.backend.ImageDelete(name, force, prune) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, list) -} - -func (s *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - imageInspect, err := s.backend.LookupImage(vars["name"]) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, imageInspect) -} - -func (s *imageRouter) getImagesJSON(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - imageFilters, err := filters.FromParam(r.Form.Get("filters")) - if err != nil { - return err - } - - version := httputils.VersionFromContext(ctx) - filterParam := r.Form.Get("filter") - if versions.LessThan(version, "1.28") && filterParam != "" { - imageFilters.Add("reference", filterParam) - } - - images, err := s.backend.Images(imageFilters, httputils.BoolValue(r, "all"), false) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, images) -} - -func (s *imageRouter) getImagesHistory(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - name := vars["name"] - history, err := s.backend.ImageHistory(name) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, history) -} - -func (s *imageRouter) postImagesTag(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - if err := s.backend.TagImage(vars["name"], r.Form.Get("repo"), r.Form.Get("tag")); err != nil { - return err - } - w.WriteHeader(http.StatusCreated) - return nil -} - -func (s *imageRouter) getImagesSearch(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - var ( - config *types.AuthConfig - authEncoded = r.Header.Get("X-Registry-Auth") - headers = map[string][]string{} - ) - - if authEncoded != "" { - authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) - if err := json.NewDecoder(authJSON).Decode(&config); err != nil { - // for a search it is not an error if no auth was given - // to increase compatibility with the existing api it is defaulting to be empty - config = &types.AuthConfig{} - } - } - for k, v := range r.Header { - if strings.HasPrefix(k, "X-Meta-") { - headers[k] = v - } - } - limit := registry.DefaultSearchLimit - if r.Form.Get("limit") != "" { - limitValue, err := strconv.Atoi(r.Form.Get("limit")) - if err != nil { - return err - } - limit = limitValue - } - query, err := s.backend.SearchRegistryForImages(ctx, r.Form.Get("filters"), r.Form.Get("term"), limit, config, headers) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, query.Results) -} - -func (s *imageRouter) postImagesPrune(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - pruneFilters, err := filters.FromParam(r.Form.Get("filters")) - if err != nil { - return err - } - - pruneReport, err := s.backend.ImagesPrune(pruneFilters) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, pruneReport) -} diff --git a/vendor/github.com/docker/docker/api/server/router/local.go b/vendor/github.com/docker/docker/api/server/router/local.go deleted file mode 100644 index 7cb2a5a..0000000 --- a/vendor/github.com/docker/docker/api/server/router/local.go +++ /dev/null @@ -1,96 +0,0 @@ -package router - -import ( - "net/http" - - "github.com/docker/docker/api/server/httputils" - "golang.org/x/net/context" -) - -// localRoute defines an individual API route to connect -// with the docker daemon. It implements Route. -type localRoute struct { - method string - path string - handler httputils.APIFunc -} - -// Handler returns the APIFunc to let the server wrap it in middlewares. -func (l localRoute) Handler() httputils.APIFunc { - return l.handler -} - -// Method returns the http method that the route responds to. -func (l localRoute) Method() string { - return l.method -} - -// Path returns the subpath where the route responds to. -func (l localRoute) Path() string { - return l.path -} - -// NewRoute initializes a new local route for the router. -func NewRoute(method, path string, handler httputils.APIFunc) Route { - return localRoute{method, path, handler} -} - -// NewGetRoute initializes a new route with the http method GET. -func NewGetRoute(path string, handler httputils.APIFunc) Route { - return NewRoute("GET", path, handler) -} - -// NewPostRoute initializes a new route with the http method POST. -func NewPostRoute(path string, handler httputils.APIFunc) Route { - return NewRoute("POST", path, handler) -} - -// NewPutRoute initializes a new route with the http method PUT. -func NewPutRoute(path string, handler httputils.APIFunc) Route { - return NewRoute("PUT", path, handler) -} - -// NewDeleteRoute initializes a new route with the http method DELETE. -func NewDeleteRoute(path string, handler httputils.APIFunc) Route { - return NewRoute("DELETE", path, handler) -} - -// NewOptionsRoute initializes a new route with the http method OPTIONS. -func NewOptionsRoute(path string, handler httputils.APIFunc) Route { - return NewRoute("OPTIONS", path, handler) -} - -// NewHeadRoute initializes a new route with the http method HEAD. -func NewHeadRoute(path string, handler httputils.APIFunc) Route { - return NewRoute("HEAD", path, handler) -} - -func cancellableHandler(h httputils.APIFunc) httputils.APIFunc { - return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if notifier, ok := w.(http.CloseNotifier); ok { - notify := notifier.CloseNotify() - notifyCtx, cancel := context.WithCancel(ctx) - finished := make(chan struct{}) - defer close(finished) - ctx = notifyCtx - go func() { - select { - case <-notify: - cancel() - case <-finished: - } - }() - } - return h(ctx, w, r, vars) - } -} - -// Cancellable makes new route which embeds http.CloseNotifier feature to -// context.Context of handler. -func Cancellable(r Route) Route { - return localRoute{ - method: r.Method(), - path: r.Path(), - handler: cancellableHandler(r.Handler()), - } -} diff --git a/vendor/github.com/docker/docker/api/server/router/network/backend.go b/vendor/github.com/docker/docker/api/server/router/network/backend.go deleted file mode 100644 index 0d1dfb0..0000000 --- a/vendor/github.com/docker/docker/api/server/router/network/backend.go +++ /dev/null @@ -1,22 +0,0 @@ -package network - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/network" - "github.com/docker/libnetwork" -) - -// Backend is all the methods that need to be implemented -// to provide network specific functionality. -type Backend interface { - FindNetwork(idName string) (libnetwork.Network, error) - GetNetworkByName(idName string) (libnetwork.Network, error) - GetNetworksByID(partialID string) []libnetwork.Network - GetNetworks() []libnetwork.Network - CreateNetwork(nc types.NetworkCreateRequest) (*types.NetworkCreateResponse, error) - ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error - DisconnectContainerFromNetwork(containerName string, networkName string, force bool) error - DeleteNetwork(name string) error - NetworksPrune(pruneFilters filters.Args) (*types.NetworksPruneReport, error) -} diff --git a/vendor/github.com/docker/docker/api/server/router/network/filter.go b/vendor/github.com/docker/docker/api/server/router/network/filter.go deleted file mode 100644 index 94affb8..0000000 --- a/vendor/github.com/docker/docker/api/server/router/network/filter.go +++ /dev/null @@ -1,96 +0,0 @@ -package network - -import ( - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/runconfig" -) - -var ( - // AcceptedFilters is an acceptable filters for validation - AcceptedFilters = map[string]bool{ - "driver": true, - "type": true, - "name": true, - "id": true, - "label": true, - } -) - -func filterNetworkByType(nws []types.NetworkResource, netType string) (retNws []types.NetworkResource, err error) { - switch netType { - case "builtin": - for _, nw := range nws { - if runconfig.IsPreDefinedNetwork(nw.Name) { - retNws = append(retNws, nw) - } - } - case "custom": - for _, nw := range nws { - if !runconfig.IsPreDefinedNetwork(nw.Name) { - retNws = append(retNws, nw) - } - } - default: - return nil, fmt.Errorf("Invalid filter: 'type'='%s'", netType) - } - return retNws, nil -} - -// filterNetworks filters network list according to user specified filter -// and returns user chosen networks -func filterNetworks(nws []types.NetworkResource, filter filters.Args) ([]types.NetworkResource, error) { - // if filter is empty, return original network list - if filter.Len() == 0 { - return nws, nil - } - - if err := filter.Validate(AcceptedFilters); err != nil { - return nil, err - } - - displayNet := []types.NetworkResource{} - for _, nw := range nws { - if filter.Include("driver") { - if !filter.ExactMatch("driver", nw.Driver) { - continue - } - } - if filter.Include("name") { - if !filter.Match("name", nw.Name) { - continue - } - } - if filter.Include("id") { - if !filter.Match("id", nw.ID) { - continue - } - } - if filter.Include("label") { - if !filter.MatchKVList("label", nw.Labels) { - continue - } - } - displayNet = append(displayNet, nw) - } - - if filter.Include("type") { - var typeNet []types.NetworkResource - errFilter := filter.WalkValues("type", func(fval string) error { - passList, err := filterNetworkByType(displayNet, fval) - if err != nil { - return err - } - typeNet = append(typeNet, passList...) - return nil - }) - if errFilter != nil { - return nil, errFilter - } - displayNet = typeNet - } - - return displayNet, nil -} diff --git a/vendor/github.com/docker/docker/api/server/router/network/network.go b/vendor/github.com/docker/docker/api/server/router/network/network.go deleted file mode 100644 index 08a5c8c..0000000 --- a/vendor/github.com/docker/docker/api/server/router/network/network.go +++ /dev/null @@ -1,44 +0,0 @@ -package network - -import ( - "github.com/docker/docker/api/server/router" - "github.com/docker/docker/daemon/cluster" -) - -// networkRouter is a router to talk with the network controller -type networkRouter struct { - backend Backend - clusterProvider *cluster.Cluster - routes []router.Route -} - -// NewRouter initializes a new network router -func NewRouter(b Backend, c *cluster.Cluster) router.Router { - r := &networkRouter{ - backend: b, - clusterProvider: c, - } - r.initRoutes() - return r -} - -// Routes returns the available routes to the network controller -func (r *networkRouter) Routes() []router.Route { - return r.routes -} - -func (r *networkRouter) initRoutes() { - r.routes = []router.Route{ - // GET - router.NewGetRoute("/networks", r.getNetworksList), - router.NewGetRoute("/networks/", r.getNetworksList), - router.NewGetRoute("/networks/{id:.+}", r.getNetwork), - // POST - router.NewPostRoute("/networks/create", r.postNetworkCreate), - router.NewPostRoute("/networks/{id:.*}/connect", r.postNetworkConnect), - router.NewPostRoute("/networks/{id:.*}/disconnect", r.postNetworkDisconnect), - router.NewPostRoute("/networks/prune", r.postNetworksPrune), - // DELETE - router.NewDeleteRoute("/networks/{id:.*}", r.deleteNetwork), - } -} diff --git a/vendor/github.com/docker/docker/api/server/router/network/network_routes.go b/vendor/github.com/docker/docker/api/server/router/network/network_routes.go deleted file mode 100644 index 7bfc499..0000000 --- a/vendor/github.com/docker/docker/api/server/router/network/network_routes.go +++ /dev/null @@ -1,308 +0,0 @@ -package network - -import ( - "encoding/json" - "net/http" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/network" - "github.com/docker/libnetwork" - "github.com/docker/libnetwork/networkdb" -) - -func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - filter := r.Form.Get("filters") - netFilters, err := filters.FromParam(filter) - if err != nil { - return err - } - - list := []types.NetworkResource{} - - if nr, err := n.clusterProvider.GetNetworks(); err == nil { - list = append(list, nr...) - } - - // Combine the network list returned by Docker daemon if it is not already - // returned by the cluster manager -SKIP: - for _, nw := range n.backend.GetNetworks() { - for _, nl := range list { - if nl.ID == nw.ID() { - continue SKIP - } - } - list = append(list, *n.buildNetworkResource(nw)) - } - - list, err = filterNetworks(list, netFilters) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, list) -} - -func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - nw, err := n.backend.FindNetwork(vars["id"]) - if err != nil { - if nr, err := n.clusterProvider.GetNetwork(vars["id"]); err == nil { - return httputils.WriteJSON(w, http.StatusOK, nr) - } - return err - } - return httputils.WriteJSON(w, http.StatusOK, n.buildNetworkResource(nw)) -} - -func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var create types.NetworkCreateRequest - - if err := httputils.ParseForm(r); err != nil { - return err - } - - if err := httputils.CheckForJSON(r); err != nil { - return err - } - - if err := json.NewDecoder(r.Body).Decode(&create); err != nil { - return err - } - - if nws, err := n.clusterProvider.GetNetworksByName(create.Name); err == nil && len(nws) > 0 { - return libnetwork.NetworkNameError(create.Name) - } - - nw, err := n.backend.CreateNetwork(create) - if err != nil { - if _, ok := err.(libnetwork.ManagerRedirectError); !ok { - return err - } - id, err := n.clusterProvider.CreateNetwork(create) - if err != nil { - return err - } - nw = &types.NetworkCreateResponse{ID: id} - } - - return httputils.WriteJSON(w, http.StatusCreated, nw) -} - -func (n *networkRouter) postNetworkConnect(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var connect types.NetworkConnect - if err := httputils.ParseForm(r); err != nil { - return err - } - - if err := httputils.CheckForJSON(r); err != nil { - return err - } - - if err := json.NewDecoder(r.Body).Decode(&connect); err != nil { - return err - } - - return n.backend.ConnectContainerToNetwork(connect.Container, vars["id"], connect.EndpointConfig) -} - -func (n *networkRouter) postNetworkDisconnect(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var disconnect types.NetworkDisconnect - if err := httputils.ParseForm(r); err != nil { - return err - } - - if err := httputils.CheckForJSON(r); err != nil { - return err - } - - if err := json.NewDecoder(r.Body).Decode(&disconnect); err != nil { - return err - } - - return n.backend.DisconnectContainerFromNetwork(disconnect.Container, vars["id"], disconnect.Force) -} - -func (n *networkRouter) deleteNetwork(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - if _, err := n.clusterProvider.GetNetwork(vars["id"]); err == nil { - if err = n.clusterProvider.RemoveNetwork(vars["id"]); err != nil { - return err - } - w.WriteHeader(http.StatusNoContent) - return nil - } - if err := n.backend.DeleteNetwork(vars["id"]); err != nil { - return err - } - w.WriteHeader(http.StatusNoContent) - return nil -} - -func (n *networkRouter) buildNetworkResource(nw libnetwork.Network) *types.NetworkResource { - r := &types.NetworkResource{} - if nw == nil { - return r - } - - info := nw.Info() - r.Name = nw.Name() - r.ID = nw.ID() - r.Created = info.Created() - r.Scope = info.Scope() - if n.clusterProvider.IsManager() { - if _, err := n.clusterProvider.GetNetwork(nw.ID()); err == nil { - r.Scope = "swarm" - } - } else if info.Dynamic() { - r.Scope = "swarm" - } - r.Driver = nw.Type() - r.EnableIPv6 = info.IPv6Enabled() - r.Internal = info.Internal() - r.Attachable = info.Attachable() - r.Options = info.DriverOptions() - r.Containers = make(map[string]types.EndpointResource) - buildIpamResources(r, info) - r.Labels = info.Labels() - - peers := info.Peers() - if len(peers) != 0 { - r.Peers = buildPeerInfoResources(peers) - } - - epl := nw.Endpoints() - for _, e := range epl { - ei := e.Info() - if ei == nil { - continue - } - sb := ei.Sandbox() - tmpID := e.ID() - key := "ep-" + tmpID - if sb != nil { - key = sb.ContainerID() - } - - r.Containers[key] = buildEndpointResource(tmpID, e.Name(), ei) - } - return r -} - -func buildPeerInfoResources(peers []networkdb.PeerInfo) []network.PeerInfo { - peerInfo := make([]network.PeerInfo, 0, len(peers)) - for _, peer := range peers { - peerInfo = append(peerInfo, network.PeerInfo{ - Name: peer.Name, - IP: peer.IP, - }) - } - return peerInfo -} - -func buildIpamResources(r *types.NetworkResource, nwInfo libnetwork.NetworkInfo) { - id, opts, ipv4conf, ipv6conf := nwInfo.IpamConfig() - - ipv4Info, ipv6Info := nwInfo.IpamInfo() - - r.IPAM.Driver = id - - r.IPAM.Options = opts - - r.IPAM.Config = []network.IPAMConfig{} - for _, ip4 := range ipv4conf { - if ip4.PreferredPool == "" { - continue - } - iData := network.IPAMConfig{} - iData.Subnet = ip4.PreferredPool - iData.IPRange = ip4.SubPool - iData.Gateway = ip4.Gateway - iData.AuxAddress = ip4.AuxAddresses - r.IPAM.Config = append(r.IPAM.Config, iData) - } - - if len(r.IPAM.Config) == 0 { - for _, ip4Info := range ipv4Info { - iData := network.IPAMConfig{} - iData.Subnet = ip4Info.IPAMData.Pool.String() - iData.Gateway = ip4Info.IPAMData.Gateway.IP.String() - r.IPAM.Config = append(r.IPAM.Config, iData) - } - } - - hasIpv6Conf := false - for _, ip6 := range ipv6conf { - if ip6.PreferredPool == "" { - continue - } - hasIpv6Conf = true - iData := network.IPAMConfig{} - iData.Subnet = ip6.PreferredPool - iData.IPRange = ip6.SubPool - iData.Gateway = ip6.Gateway - iData.AuxAddress = ip6.AuxAddresses - r.IPAM.Config = append(r.IPAM.Config, iData) - } - - if !hasIpv6Conf { - for _, ip6Info := range ipv6Info { - if ip6Info.IPAMData.Pool == nil { - continue - } - iData := network.IPAMConfig{} - iData.Subnet = ip6Info.IPAMData.Pool.String() - iData.Gateway = ip6Info.IPAMData.Gateway.String() - r.IPAM.Config = append(r.IPAM.Config, iData) - } - } -} - -func buildEndpointResource(id string, name string, info libnetwork.EndpointInfo) types.EndpointResource { - er := types.EndpointResource{} - - er.EndpointID = id - er.Name = name - ei := info - if ei == nil { - return er - } - - if iface := ei.Iface(); iface != nil { - if mac := iface.MacAddress(); mac != nil { - er.MacAddress = mac.String() - } - if ip := iface.Address(); ip != nil && len(ip.IP) > 0 { - er.IPv4Address = ip.String() - } - - if ipv6 := iface.AddressIPv6(); ipv6 != nil && len(ipv6.IP) > 0 { - er.IPv6Address = ipv6.String() - } - } - return er -} - -func (n *networkRouter) postNetworksPrune(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - pruneReport, err := n.backend.NetworksPrune(filters.Args{}) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, pruneReport) -} diff --git a/vendor/github.com/docker/docker/api/server/router/plugin/backend.go b/vendor/github.com/docker/docker/api/server/router/plugin/backend.go deleted file mode 100644 index ab006b2..0000000 --- a/vendor/github.com/docker/docker/api/server/router/plugin/backend.go +++ /dev/null @@ -1,25 +0,0 @@ -package plugin - -import ( - "io" - "net/http" - - enginetypes "github.com/docker/docker/api/types" - "github.com/docker/docker/reference" - "golang.org/x/net/context" -) - -// Backend for Plugin -type Backend interface { - Disable(name string, config *enginetypes.PluginDisableConfig) error - Enable(name string, config *enginetypes.PluginEnableConfig) error - List() ([]enginetypes.Plugin, error) - Inspect(name string) (*enginetypes.Plugin, error) - Remove(name string, config *enginetypes.PluginRmConfig) error - Set(name string, args []string) error - Privileges(ctx context.Context, ref reference.Named, metaHeaders http.Header, authConfig *enginetypes.AuthConfig) (enginetypes.PluginPrivileges, error) - Pull(ctx context.Context, ref reference.Named, name string, metaHeaders http.Header, authConfig *enginetypes.AuthConfig, privileges enginetypes.PluginPrivileges, outStream io.Writer) error - Push(ctx context.Context, name string, metaHeaders http.Header, authConfig *enginetypes.AuthConfig, outStream io.Writer) error - Upgrade(ctx context.Context, ref reference.Named, name string, metaHeaders http.Header, authConfig *enginetypes.AuthConfig, privileges enginetypes.PluginPrivileges, outStream io.Writer) error - CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *enginetypes.PluginCreateOptions) error -} diff --git a/vendor/github.com/docker/docker/api/server/router/plugin/plugin.go b/vendor/github.com/docker/docker/api/server/router/plugin/plugin.go deleted file mode 100644 index e4ea9e2..0000000 --- a/vendor/github.com/docker/docker/api/server/router/plugin/plugin.go +++ /dev/null @@ -1,39 +0,0 @@ -package plugin - -import "github.com/docker/docker/api/server/router" - -// pluginRouter is a router to talk with the plugin controller -type pluginRouter struct { - backend Backend - routes []router.Route -} - -// NewRouter initializes a new plugin router -func NewRouter(b Backend) router.Router { - r := &pluginRouter{ - backend: b, - } - r.initRoutes() - return r -} - -// Routes returns the available routers to the plugin controller -func (r *pluginRouter) Routes() []router.Route { - return r.routes -} - -func (r *pluginRouter) initRoutes() { - r.routes = []router.Route{ - router.NewGetRoute("/plugins", r.listPlugins), - router.NewGetRoute("/plugins/{name:.*}/json", r.inspectPlugin), - router.NewGetRoute("/plugins/privileges", r.getPrivileges), - router.NewDeleteRoute("/plugins/{name:.*}", r.removePlugin), - router.NewPostRoute("/plugins/{name:.*}/enable", r.enablePlugin), // PATCH? - router.NewPostRoute("/plugins/{name:.*}/disable", r.disablePlugin), - router.Cancellable(router.NewPostRoute("/plugins/pull", r.pullPlugin)), - router.Cancellable(router.NewPostRoute("/plugins/{name:.*}/push", r.pushPlugin)), - router.Cancellable(router.NewPostRoute("/plugins/{name:.*}/upgrade", r.upgradePlugin)), - router.NewPostRoute("/plugins/{name:.*}/set", r.setPlugin), - router.NewPostRoute("/plugins/create", r.createPlugin), - } -} diff --git a/vendor/github.com/docker/docker/api/server/router/plugin/plugin_routes.go b/vendor/github.com/docker/docker/api/server/router/plugin/plugin_routes.go deleted file mode 100644 index 693fa95..0000000 --- a/vendor/github.com/docker/docker/api/server/router/plugin/plugin_routes.go +++ /dev/null @@ -1,314 +0,0 @@ -package plugin - -import ( - "encoding/base64" - "encoding/json" - "net/http" - "strconv" - "strings" - - distreference "github.com/docker/distribution/reference" - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/streamformatter" - "github.com/docker/docker/reference" - "github.com/pkg/errors" - "golang.org/x/net/context" -) - -func parseHeaders(headers http.Header) (map[string][]string, *types.AuthConfig) { - - metaHeaders := map[string][]string{} - for k, v := range headers { - if strings.HasPrefix(k, "X-Meta-") { - metaHeaders[k] = v - } - } - - // Get X-Registry-Auth - authEncoded := headers.Get("X-Registry-Auth") - authConfig := &types.AuthConfig{} - if authEncoded != "" { - authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) - if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil { - authConfig = &types.AuthConfig{} - } - } - - return metaHeaders, authConfig -} - -// parseRemoteRef parses the remote reference into a reference.Named -// returning the tag associated with the reference. In the case the -// given reference string includes both digest and tag, the returned -// reference will have the digest without the tag, but the tag will -// be returned. -func parseRemoteRef(remote string) (reference.Named, string, error) { - // Parse remote reference, supporting remotes with name and tag - // NOTE: Using distribution reference to handle references - // containing both a name and digest - remoteRef, err := distreference.ParseNamed(remote) - if err != nil { - return nil, "", err - } - - var tag string - if t, ok := remoteRef.(distreference.Tagged); ok { - tag = t.Tag() - } - - // Convert distribution reference to docker reference - // TODO: remove when docker reference changes reconciled upstream - ref, err := reference.WithName(remoteRef.Name()) - if err != nil { - return nil, "", err - } - if d, ok := remoteRef.(distreference.Digested); ok { - ref, err = reference.WithDigest(ref, d.Digest()) - if err != nil { - return nil, "", err - } - } else if tag != "" { - ref, err = reference.WithTag(ref, tag) - if err != nil { - return nil, "", err - } - } else { - ref = reference.WithDefaultTag(ref) - } - - return ref, tag, nil -} - -func (pr *pluginRouter) getPrivileges(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - metaHeaders, authConfig := parseHeaders(r.Header) - - ref, _, err := parseRemoteRef(r.FormValue("remote")) - if err != nil { - return err - } - - privileges, err := pr.backend.Privileges(ctx, ref, metaHeaders, authConfig) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, privileges) -} - -func (pr *pluginRouter) upgradePlugin(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return errors.Wrap(err, "failed to parse form") - } - - var privileges types.PluginPrivileges - dec := json.NewDecoder(r.Body) - if err := dec.Decode(&privileges); err != nil { - return errors.Wrap(err, "failed to parse privileges") - } - if dec.More() { - return errors.New("invalid privileges") - } - - metaHeaders, authConfig := parseHeaders(r.Header) - ref, tag, err := parseRemoteRef(r.FormValue("remote")) - if err != nil { - return err - } - - name, err := getName(ref, tag, vars["name"]) - if err != nil { - return err - } - w.Header().Set("Docker-Plugin-Name", name) - - w.Header().Set("Content-Type", "application/json") - output := ioutils.NewWriteFlusher(w) - - if err := pr.backend.Upgrade(ctx, ref, name, metaHeaders, authConfig, privileges, output); err != nil { - if !output.Flushed() { - return err - } - output.Write(streamformatter.NewJSONStreamFormatter().FormatError(err)) - } - - return nil -} - -func (pr *pluginRouter) pullPlugin(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return errors.Wrap(err, "failed to parse form") - } - - var privileges types.PluginPrivileges - dec := json.NewDecoder(r.Body) - if err := dec.Decode(&privileges); err != nil { - return errors.Wrap(err, "failed to parse privileges") - } - if dec.More() { - return errors.New("invalid privileges") - } - - metaHeaders, authConfig := parseHeaders(r.Header) - ref, tag, err := parseRemoteRef(r.FormValue("remote")) - if err != nil { - return err - } - - name, err := getName(ref, tag, r.FormValue("name")) - if err != nil { - return err - } - w.Header().Set("Docker-Plugin-Name", name) - - w.Header().Set("Content-Type", "application/json") - output := ioutils.NewWriteFlusher(w) - - if err := pr.backend.Pull(ctx, ref, name, metaHeaders, authConfig, privileges, output); err != nil { - if !output.Flushed() { - return err - } - output.Write(streamformatter.NewJSONStreamFormatter().FormatError(err)) - } - - return nil -} - -func getName(ref reference.Named, tag, name string) (string, error) { - if name == "" { - if _, ok := ref.(reference.Canonical); ok { - trimmed := reference.TrimNamed(ref) - if tag != "" { - nt, err := reference.WithTag(trimmed, tag) - if err != nil { - return "", err - } - name = nt.String() - } else { - name = reference.WithDefaultTag(trimmed).String() - } - } else { - name = ref.String() - } - } else { - localRef, err := reference.ParseNamed(name) - if err != nil { - return "", err - } - if _, ok := localRef.(reference.Canonical); ok { - return "", errors.New("cannot use digest in plugin tag") - } - if distreference.IsNameOnly(localRef) { - // TODO: log change in name to out stream - name = reference.WithDefaultTag(localRef).String() - } - } - return name, nil -} - -func (pr *pluginRouter) createPlugin(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - options := &types.PluginCreateOptions{ - RepoName: r.FormValue("name")} - - if err := pr.backend.CreateFromContext(ctx, r.Body, options); err != nil { - return err - } - //TODO: send progress bar - w.WriteHeader(http.StatusNoContent) - return nil -} - -func (pr *pluginRouter) enablePlugin(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - name := vars["name"] - timeout, err := strconv.Atoi(r.Form.Get("timeout")) - if err != nil { - return err - } - config := &types.PluginEnableConfig{Timeout: timeout} - - return pr.backend.Enable(name, config) -} - -func (pr *pluginRouter) disablePlugin(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - name := vars["name"] - config := &types.PluginDisableConfig{ - ForceDisable: httputils.BoolValue(r, "force"), - } - - return pr.backend.Disable(name, config) -} - -func (pr *pluginRouter) removePlugin(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - name := vars["name"] - config := &types.PluginRmConfig{ - ForceRemove: httputils.BoolValue(r, "force"), - } - return pr.backend.Remove(name, config) -} - -func (pr *pluginRouter) pushPlugin(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return errors.Wrap(err, "failed to parse form") - } - - metaHeaders, authConfig := parseHeaders(r.Header) - - w.Header().Set("Content-Type", "application/json") - output := ioutils.NewWriteFlusher(w) - - if err := pr.backend.Push(ctx, vars["name"], metaHeaders, authConfig, output); err != nil { - if !output.Flushed() { - return err - } - output.Write(streamformatter.NewJSONStreamFormatter().FormatError(err)) - } - return nil -} - -func (pr *pluginRouter) setPlugin(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var args []string - if err := json.NewDecoder(r.Body).Decode(&args); err != nil { - return err - } - if err := pr.backend.Set(vars["name"], args); err != nil { - return err - } - w.WriteHeader(http.StatusNoContent) - return nil -} - -func (pr *pluginRouter) listPlugins(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - l, err := pr.backend.List() - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, l) -} - -func (pr *pluginRouter) inspectPlugin(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - result, err := pr.backend.Inspect(vars["name"]) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, result) -} diff --git a/vendor/github.com/docker/docker/api/server/router/router.go b/vendor/github.com/docker/docker/api/server/router/router.go deleted file mode 100644 index 2de25c2..0000000 --- a/vendor/github.com/docker/docker/api/server/router/router.go +++ /dev/null @@ -1,19 +0,0 @@ -package router - -import "github.com/docker/docker/api/server/httputils" - -// Router defines an interface to specify a group of routes to add to the docker server. -type Router interface { - // Routes returns the list of routes to add to the docker server. - Routes() []Route -} - -// Route defines an individual API route in the docker server. -type Route interface { - // Handler returns the raw function to create the http handler. - Handler() httputils.APIFunc - // Method returns the http method that the route responds to. - Method() string - // Path returns the subpath where the route responds to. - Path() string -} diff --git a/vendor/github.com/docker/docker/api/server/router/swarm/backend.go b/vendor/github.com/docker/docker/api/server/router/swarm/backend.go deleted file mode 100644 index 33840f0..0000000 --- a/vendor/github.com/docker/docker/api/server/router/swarm/backend.go +++ /dev/null @@ -1,36 +0,0 @@ -package swarm - -import ( - basictypes "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - types "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// Backend abstracts an swarm commands manager. -type Backend interface { - Init(req types.InitRequest) (string, error) - Join(req types.JoinRequest) error - Leave(force bool) error - Inspect() (types.Swarm, error) - Update(uint64, types.Spec, types.UpdateFlags) error - GetUnlockKey() (string, error) - UnlockSwarm(req types.UnlockRequest) error - GetServices(basictypes.ServiceListOptions) ([]types.Service, error) - GetService(string) (types.Service, error) - CreateService(types.ServiceSpec, string) (*basictypes.ServiceCreateResponse, error) - UpdateService(string, uint64, types.ServiceSpec, string, string) (*basictypes.ServiceUpdateResponse, error) - RemoveService(string) error - ServiceLogs(context.Context, string, *backend.ContainerLogsConfig, chan struct{}) error - GetNodes(basictypes.NodeListOptions) ([]types.Node, error) - GetNode(string) (types.Node, error) - UpdateNode(string, uint64, types.NodeSpec) error - RemoveNode(string, bool) error - GetTasks(basictypes.TaskListOptions) ([]types.Task, error) - GetTask(string) (types.Task, error) - GetSecrets(opts basictypes.SecretListOptions) ([]types.Secret, error) - CreateSecret(s types.SecretSpec) (string, error) - RemoveSecret(id string) error - GetSecret(id string) (types.Secret, error) - UpdateSecret(id string, version uint64, spec types.SecretSpec) error -} diff --git a/vendor/github.com/docker/docker/api/server/router/swarm/cluster.go b/vendor/github.com/docker/docker/api/server/router/swarm/cluster.go deleted file mode 100644 index e2d5ad1..0000000 --- a/vendor/github.com/docker/docker/api/server/router/swarm/cluster.go +++ /dev/null @@ -1,52 +0,0 @@ -package swarm - -import "github.com/docker/docker/api/server/router" - -// swarmRouter is a router to talk with the build controller -type swarmRouter struct { - backend Backend - routes []router.Route -} - -// NewRouter initializes a new build router -func NewRouter(b Backend) router.Router { - r := &swarmRouter{ - backend: b, - } - r.initRoutes() - return r -} - -// Routes returns the available routers to the swarm controller -func (sr *swarmRouter) Routes() []router.Route { - return sr.routes -} - -func (sr *swarmRouter) initRoutes() { - sr.routes = []router.Route{ - router.NewPostRoute("/swarm/init", sr.initCluster), - router.NewPostRoute("/swarm/join", sr.joinCluster), - router.NewPostRoute("/swarm/leave", sr.leaveCluster), - router.NewGetRoute("/swarm", sr.inspectCluster), - router.NewGetRoute("/swarm/unlockkey", sr.getUnlockKey), - router.NewPostRoute("/swarm/update", sr.updateCluster), - router.NewPostRoute("/swarm/unlock", sr.unlockCluster), - router.NewGetRoute("/services", sr.getServices), - router.NewGetRoute("/services/{id}", sr.getService), - router.NewPostRoute("/services/create", sr.createService), - router.NewPostRoute("/services/{id}/update", sr.updateService), - router.NewDeleteRoute("/services/{id}", sr.removeService), - router.Experimental(router.Cancellable(router.NewGetRoute("/services/{id}/logs", sr.getServiceLogs))), - router.NewGetRoute("/nodes", sr.getNodes), - router.NewGetRoute("/nodes/{id}", sr.getNode), - router.NewDeleteRoute("/nodes/{id}", sr.removeNode), - router.NewPostRoute("/nodes/{id}/update", sr.updateNode), - router.NewGetRoute("/tasks", sr.getTasks), - router.NewGetRoute("/tasks/{id}", sr.getTask), - router.NewGetRoute("/secrets", sr.getSecrets), - router.NewPostRoute("/secrets/create", sr.createSecret), - router.NewDeleteRoute("/secrets/{id}", sr.removeSecret), - router.NewGetRoute("/secrets/{id}", sr.getSecret), - router.NewPostRoute("/secrets/{id}/update", sr.updateSecret), - } -} diff --git a/vendor/github.com/docker/docker/api/server/router/swarm/cluster_routes.go b/vendor/github.com/docker/docker/api/server/router/swarm/cluster_routes.go deleted file mode 100644 index fe97643..0000000 --- a/vendor/github.com/docker/docker/api/server/router/swarm/cluster_routes.go +++ /dev/null @@ -1,418 +0,0 @@ -package swarm - -import ( - "encoding/json" - "fmt" - "net/http" - "strconv" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/server/httputils" - basictypes "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/filters" - types "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func (sr *swarmRouter) initCluster(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var req types.InitRequest - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - return err - } - nodeID, err := sr.backend.Init(req) - if err != nil { - logrus.Errorf("Error initializing swarm: %v", err) - return err - } - return httputils.WriteJSON(w, http.StatusOK, nodeID) -} - -func (sr *swarmRouter) joinCluster(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var req types.JoinRequest - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - return err - } - return sr.backend.Join(req) -} - -func (sr *swarmRouter) leaveCluster(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - force := httputils.BoolValue(r, "force") - return sr.backend.Leave(force) -} - -func (sr *swarmRouter) inspectCluster(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - swarm, err := sr.backend.Inspect() - if err != nil { - logrus.Errorf("Error getting swarm: %v", err) - return err - } - - return httputils.WriteJSON(w, http.StatusOK, swarm) -} - -func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var swarm types.Spec - if err := json.NewDecoder(r.Body).Decode(&swarm); err != nil { - return err - } - - rawVersion := r.URL.Query().Get("version") - version, err := strconv.ParseUint(rawVersion, 10, 64) - if err != nil { - return fmt.Errorf("Invalid swarm version '%s': %s", rawVersion, err.Error()) - } - - var flags types.UpdateFlags - - if value := r.URL.Query().Get("rotateWorkerToken"); value != "" { - rot, err := strconv.ParseBool(value) - if err != nil { - return fmt.Errorf("invalid value for rotateWorkerToken: %s", value) - } - - flags.RotateWorkerToken = rot - } - - if value := r.URL.Query().Get("rotateManagerToken"); value != "" { - rot, err := strconv.ParseBool(value) - if err != nil { - return fmt.Errorf("invalid value for rotateManagerToken: %s", value) - } - - flags.RotateManagerToken = rot - } - - if value := r.URL.Query().Get("rotateManagerUnlockKey"); value != "" { - rot, err := strconv.ParseBool(value) - if err != nil { - return fmt.Errorf("invalid value for rotateManagerUnlockKey: %s", value) - } - - flags.RotateManagerUnlockKey = rot - } - - if err := sr.backend.Update(version, swarm, flags); err != nil { - logrus.Errorf("Error configuring swarm: %v", err) - return err - } - return nil -} - -func (sr *swarmRouter) unlockCluster(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var req types.UnlockRequest - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - return err - } - - if err := sr.backend.UnlockSwarm(req); err != nil { - logrus.Errorf("Error unlocking swarm: %v", err) - return err - } - return nil -} - -func (sr *swarmRouter) getUnlockKey(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - unlockKey, err := sr.backend.GetUnlockKey() - if err != nil { - logrus.WithError(err).Errorf("Error retrieving swarm unlock key") - return err - } - - return httputils.WriteJSON(w, http.StatusOK, &basictypes.SwarmUnlockKeyResponse{ - UnlockKey: unlockKey, - }) -} - -func (sr *swarmRouter) getServices(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - filter, err := filters.FromParam(r.Form.Get("filters")) - if err != nil { - return err - } - - services, err := sr.backend.GetServices(basictypes.ServiceListOptions{Filters: filter}) - if err != nil { - logrus.Errorf("Error getting services: %v", err) - return err - } - - return httputils.WriteJSON(w, http.StatusOK, services) -} - -func (sr *swarmRouter) getService(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - service, err := sr.backend.GetService(vars["id"]) - if err != nil { - logrus.Errorf("Error getting service %s: %v", vars["id"], err) - return err - } - - return httputils.WriteJSON(w, http.StatusOK, service) -} - -func (sr *swarmRouter) createService(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var service types.ServiceSpec - if err := json.NewDecoder(r.Body).Decode(&service); err != nil { - return err - } - - // Get returns "" if the header does not exist - encodedAuth := r.Header.Get("X-Registry-Auth") - - resp, err := sr.backend.CreateService(service, encodedAuth) - if err != nil { - logrus.Errorf("Error creating service %s: %v", service.Name, err) - return err - } - - return httputils.WriteJSON(w, http.StatusCreated, resp) -} - -func (sr *swarmRouter) updateService(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var service types.ServiceSpec - if err := json.NewDecoder(r.Body).Decode(&service); err != nil { - return err - } - - rawVersion := r.URL.Query().Get("version") - version, err := strconv.ParseUint(rawVersion, 10, 64) - if err != nil { - return fmt.Errorf("Invalid service version '%s': %s", rawVersion, err.Error()) - } - - // Get returns "" if the header does not exist - encodedAuth := r.Header.Get("X-Registry-Auth") - - registryAuthFrom := r.URL.Query().Get("registryAuthFrom") - - resp, err := sr.backend.UpdateService(vars["id"], version, service, encodedAuth, registryAuthFrom) - if err != nil { - logrus.Errorf("Error updating service %s: %v", vars["id"], err) - return err - } - return httputils.WriteJSON(w, http.StatusOK, resp) -} - -func (sr *swarmRouter) removeService(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := sr.backend.RemoveService(vars["id"]); err != nil { - logrus.Errorf("Error removing service %s: %v", vars["id"], err) - return err - } - return nil -} - -func (sr *swarmRouter) getServiceLogs(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - // Args are validated before the stream starts because when it starts we're - // sending HTTP 200 by writing an empty chunk of data to tell the client that - // daemon is going to stream. By sending this initial HTTP 200 we can't report - // any error after the stream starts (i.e. container not found, wrong parameters) - // with the appropriate status code. - stdout, stderr := httputils.BoolValue(r, "stdout"), httputils.BoolValue(r, "stderr") - if !(stdout || stderr) { - return fmt.Errorf("Bad parameters: you must choose at least one stream") - } - - serviceName := vars["id"] - logsConfig := &backend.ContainerLogsConfig{ - ContainerLogsOptions: basictypes.ContainerLogsOptions{ - Follow: httputils.BoolValue(r, "follow"), - Timestamps: httputils.BoolValue(r, "timestamps"), - Since: r.Form.Get("since"), - Tail: r.Form.Get("tail"), - ShowStdout: stdout, - ShowStderr: stderr, - Details: httputils.BoolValue(r, "details"), - }, - OutStream: w, - } - - if logsConfig.Details { - return fmt.Errorf("Bad parameters: details is not currently supported") - } - - chStarted := make(chan struct{}) - if err := sr.backend.ServiceLogs(ctx, serviceName, logsConfig, chStarted); err != nil { - select { - case <-chStarted: - // The client may be expecting all of the data we're sending to - // be multiplexed, so send it through OutStream, which will - // have been set up to handle that if needed. - fmt.Fprintf(logsConfig.OutStream, "Error grabbing service logs: %v\n", err) - default: - return err - } - } - - return nil -} - -func (sr *swarmRouter) getNodes(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - filter, err := filters.FromParam(r.Form.Get("filters")) - if err != nil { - return err - } - - nodes, err := sr.backend.GetNodes(basictypes.NodeListOptions{Filters: filter}) - if err != nil { - logrus.Errorf("Error getting nodes: %v", err) - return err - } - - return httputils.WriteJSON(w, http.StatusOK, nodes) -} - -func (sr *swarmRouter) getNode(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - node, err := sr.backend.GetNode(vars["id"]) - if err != nil { - logrus.Errorf("Error getting node %s: %v", vars["id"], err) - return err - } - - return httputils.WriteJSON(w, http.StatusOK, node) -} - -func (sr *swarmRouter) updateNode(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var node types.NodeSpec - if err := json.NewDecoder(r.Body).Decode(&node); err != nil { - return err - } - - rawVersion := r.URL.Query().Get("version") - version, err := strconv.ParseUint(rawVersion, 10, 64) - if err != nil { - return fmt.Errorf("Invalid node version '%s': %s", rawVersion, err.Error()) - } - - if err := sr.backend.UpdateNode(vars["id"], version, node); err != nil { - logrus.Errorf("Error updating node %s: %v", vars["id"], err) - return err - } - return nil -} - -func (sr *swarmRouter) removeNode(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - force := httputils.BoolValue(r, "force") - - if err := sr.backend.RemoveNode(vars["id"], force); err != nil { - logrus.Errorf("Error removing node %s: %v", vars["id"], err) - return err - } - return nil -} - -func (sr *swarmRouter) getTasks(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - filter, err := filters.FromParam(r.Form.Get("filters")) - if err != nil { - return err - } - - tasks, err := sr.backend.GetTasks(basictypes.TaskListOptions{Filters: filter}) - if err != nil { - logrus.Errorf("Error getting tasks: %v", err) - return err - } - - return httputils.WriteJSON(w, http.StatusOK, tasks) -} - -func (sr *swarmRouter) getTask(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - task, err := sr.backend.GetTask(vars["id"]) - if err != nil { - logrus.Errorf("Error getting task %s: %v", vars["id"], err) - return err - } - - return httputils.WriteJSON(w, http.StatusOK, task) -} - -func (sr *swarmRouter) getSecrets(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - filters, err := filters.FromParam(r.Form.Get("filters")) - if err != nil { - return err - } - - secrets, err := sr.backend.GetSecrets(basictypes.SecretListOptions{Filters: filters}) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, secrets) -} - -func (sr *swarmRouter) createSecret(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var secret types.SecretSpec - if err := json.NewDecoder(r.Body).Decode(&secret); err != nil { - return err - } - - id, err := sr.backend.CreateSecret(secret) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusCreated, &basictypes.SecretCreateResponse{ - ID: id, - }) -} - -func (sr *swarmRouter) removeSecret(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := sr.backend.RemoveSecret(vars["id"]); err != nil { - return err - } - w.WriteHeader(http.StatusNoContent) - - return nil -} - -func (sr *swarmRouter) getSecret(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - secret, err := sr.backend.GetSecret(vars["id"]) - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, secret) -} - -func (sr *swarmRouter) updateSecret(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var secret types.SecretSpec - if err := json.NewDecoder(r.Body).Decode(&secret); err != nil { - return errors.NewBadRequestError(err) - } - - rawVersion := r.URL.Query().Get("version") - version, err := strconv.ParseUint(rawVersion, 10, 64) - if err != nil { - return errors.NewBadRequestError(fmt.Errorf("invalid secret version")) - } - - id := vars["id"] - if err := sr.backend.UpdateSecret(id, version, secret); err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/docker/docker/api/server/router/system/backend.go b/vendor/github.com/docker/docker/api/server/router/system/backend.go deleted file mode 100644 index 6946c4e..0000000 --- a/vendor/github.com/docker/docker/api/server/router/system/backend.go +++ /dev/null @@ -1,21 +0,0 @@ -package system - -import ( - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -// Backend is the methods that need to be implemented to provide -// system specific functionality. -type Backend interface { - SystemInfo() (*types.Info, error) - SystemVersion() types.Version - SystemDiskUsage() (*types.DiskUsage, error) - SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan interface{}) - UnsubscribeFromEvents(chan interface{}) - AuthenticateToRegistry(ctx context.Context, authConfig *types.AuthConfig) (string, string, error) -} diff --git a/vendor/github.com/docker/docker/api/server/router/system/system.go b/vendor/github.com/docker/docker/api/server/router/system/system.go deleted file mode 100644 index ed23d3b..0000000 --- a/vendor/github.com/docker/docker/api/server/router/system/system.go +++ /dev/null @@ -1,39 +0,0 @@ -package system - -import ( - "github.com/docker/docker/api/server/router" - "github.com/docker/docker/daemon/cluster" -) - -// systemRouter provides information about the Docker system overall. -// It gathers information about host, daemon and container events. -type systemRouter struct { - backend Backend - clusterProvider *cluster.Cluster - routes []router.Route -} - -// NewRouter initializes a new system router -func NewRouter(b Backend, c *cluster.Cluster) router.Router { - r := &systemRouter{ - backend: b, - clusterProvider: c, - } - - r.routes = []router.Route{ - router.NewOptionsRoute("/{anyroute:.*}", optionsHandler), - router.NewGetRoute("/_ping", pingHandler), - router.Cancellable(router.NewGetRoute("/events", r.getEvents)), - router.NewGetRoute("/info", r.getInfo), - router.NewGetRoute("/version", r.getVersion), - router.NewGetRoute("/system/df", r.getDiskUsage), - router.NewPostRoute("/auth", r.postAuth), - } - - return r -} - -// Routes returns all the API routes dedicated to the docker system -func (s *systemRouter) Routes() []router.Route { - return s.routes -} diff --git a/vendor/github.com/docker/docker/api/server/router/system/system_routes.go b/vendor/github.com/docker/docker/api/server/router/system/system_routes.go deleted file mode 100644 index 0d851b6..0000000 --- a/vendor/github.com/docker/docker/api/server/router/system/system_routes.go +++ /dev/null @@ -1,186 +0,0 @@ -package system - -import ( - "encoding/json" - "fmt" - "net/http" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api" - "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/registry" - timetypes "github.com/docker/docker/api/types/time" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/pkg/ioutils" - "golang.org/x/net/context" -) - -func optionsHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - w.WriteHeader(http.StatusOK) - return nil -} - -func pingHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - _, err := w.Write([]byte{'O', 'K'}) - return err -} - -func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - info, err := s.backend.SystemInfo() - if err != nil { - return err - } - if s.clusterProvider != nil { - info.Swarm = s.clusterProvider.Info() - } - - if versions.LessThan(httputils.VersionFromContext(ctx), "1.25") { - // TODO: handle this conversion in engine-api - type oldInfo struct { - *types.Info - ExecutionDriver string - } - old := &oldInfo{ - Info: info, - ExecutionDriver: "", - } - nameOnlySecurityOptions := []string{} - kvSecOpts, err := types.DecodeSecurityOptions(old.SecurityOptions) - if err != nil { - return err - } - for _, s := range kvSecOpts { - nameOnlySecurityOptions = append(nameOnlySecurityOptions, s.Name) - } - old.SecurityOptions = nameOnlySecurityOptions - return httputils.WriteJSON(w, http.StatusOK, old) - } - return httputils.WriteJSON(w, http.StatusOK, info) -} - -func (s *systemRouter) getVersion(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - info := s.backend.SystemVersion() - info.APIVersion = api.DefaultVersion - - return httputils.WriteJSON(w, http.StatusOK, info) -} - -func (s *systemRouter) getDiskUsage(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - du, err := s.backend.SystemDiskUsage() - if err != nil { - return err - } - - return httputils.WriteJSON(w, http.StatusOK, du) -} - -func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - since, err := eventTime(r.Form.Get("since")) - if err != nil { - return err - } - until, err := eventTime(r.Form.Get("until")) - if err != nil { - return err - } - - var ( - timeout <-chan time.Time - onlyPastEvents bool - ) - if !until.IsZero() { - if until.Before(since) { - return errors.NewBadRequestError(fmt.Errorf("`since` time (%s) cannot be after `until` time (%s)", r.Form.Get("since"), r.Form.Get("until"))) - } - - now := time.Now() - - onlyPastEvents = until.Before(now) - - if !onlyPastEvents { - dur := until.Sub(now) - timeout = time.NewTimer(dur).C - } - } - - ef, err := filters.FromParam(r.Form.Get("filters")) - if err != nil { - return err - } - - w.Header().Set("Content-Type", "application/json") - output := ioutils.NewWriteFlusher(w) - defer output.Close() - output.Flush() - - enc := json.NewEncoder(output) - - buffered, l := s.backend.SubscribeToEvents(since, until, ef) - defer s.backend.UnsubscribeFromEvents(l) - - for _, ev := range buffered { - if err := enc.Encode(ev); err != nil { - return err - } - } - - if onlyPastEvents { - return nil - } - - for { - select { - case ev := <-l: - jev, ok := ev.(events.Message) - if !ok { - logrus.Warnf("unexpected event message: %q", ev) - continue - } - if err := enc.Encode(jev); err != nil { - return err - } - case <-timeout: - return nil - case <-ctx.Done(): - logrus.Debug("Client context cancelled, stop sending events") - return nil - } - } -} - -func (s *systemRouter) postAuth(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var config *types.AuthConfig - err := json.NewDecoder(r.Body).Decode(&config) - r.Body.Close() - if err != nil { - return err - } - status, token, err := s.backend.AuthenticateToRegistry(ctx, config) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, ®istry.AuthenticateOKBody{ - Status: status, - IdentityToken: token, - }) -} - -func eventTime(formTime string) (time.Time, error) { - t, tNano, err := timetypes.ParseTimestamps(formTime, -1) - if err != nil { - return time.Time{}, err - } - if t == -1 { - return time.Time{}, nil - } - return time.Unix(t, tNano), nil -} diff --git a/vendor/github.com/docker/docker/api/server/router/volume/backend.go b/vendor/github.com/docker/docker/api/server/router/volume/backend.go deleted file mode 100644 index 180c06e..0000000 --- a/vendor/github.com/docker/docker/api/server/router/volume/backend.go +++ /dev/null @@ -1,17 +0,0 @@ -package volume - -import ( - // TODO return types need to be refactored into pkg - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" -) - -// Backend is the methods that need to be implemented to provide -// volume specific functionality -type Backend interface { - Volumes(filter string) ([]*types.Volume, []string, error) - VolumeInspect(name string) (*types.Volume, error) - VolumeCreate(name, driverName string, opts, labels map[string]string) (*types.Volume, error) - VolumeRm(name string, force bool) error - VolumesPrune(pruneFilters filters.Args) (*types.VolumesPruneReport, error) -} diff --git a/vendor/github.com/docker/docker/api/server/router/volume/volume.go b/vendor/github.com/docker/docker/api/server/router/volume/volume.go deleted file mode 100644 index 4e9f972..0000000 --- a/vendor/github.com/docker/docker/api/server/router/volume/volume.go +++ /dev/null @@ -1,36 +0,0 @@ -package volume - -import "github.com/docker/docker/api/server/router" - -// volumeRouter is a router to talk with the volumes controller -type volumeRouter struct { - backend Backend - routes []router.Route -} - -// NewRouter initializes a new volume router -func NewRouter(b Backend) router.Router { - r := &volumeRouter{ - backend: b, - } - r.initRoutes() - return r -} - -// Routes returns the available routes to the volumes controller -func (r *volumeRouter) Routes() []router.Route { - return r.routes -} - -func (r *volumeRouter) initRoutes() { - r.routes = []router.Route{ - // GET - router.NewGetRoute("/volumes", r.getVolumesList), - router.NewGetRoute("/volumes/{name:.*}", r.getVolumeByName), - // POST - router.NewPostRoute("/volumes/create", r.postVolumesCreate), - router.NewPostRoute("/volumes/prune", r.postVolumesPrune), - // DELETE - router.NewDeleteRoute("/volumes/{name:.*}", r.deleteVolumes), - } -} diff --git a/vendor/github.com/docker/docker/api/server/router/volume/volume_routes.go b/vendor/github.com/docker/docker/api/server/router/volume/volume_routes.go deleted file mode 100644 index cfd4618..0000000 --- a/vendor/github.com/docker/docker/api/server/router/volume/volume_routes.go +++ /dev/null @@ -1,80 +0,0 @@ -package volume - -import ( - "encoding/json" - "net/http" - - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types/filters" - volumetypes "github.com/docker/docker/api/types/volume" - "golang.org/x/net/context" -) - -func (v *volumeRouter) getVolumesList(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - volumes, warnings, err := v.backend.Volumes(r.Form.Get("filters")) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, &volumetypes.VolumesListOKBody{Volumes: volumes, Warnings: warnings}) -} - -func (v *volumeRouter) getVolumeByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - volume, err := v.backend.VolumeInspect(vars["name"]) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, volume) -} - -func (v *volumeRouter) postVolumesCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - if err := httputils.CheckForJSON(r); err != nil { - return err - } - - var req volumetypes.VolumesCreateBody - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - return err - } - - volume, err := v.backend.VolumeCreate(req.Name, req.Driver, req.DriverOpts, req.Labels) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusCreated, volume) -} - -func (v *volumeRouter) deleteVolumes(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - force := httputils.BoolValue(r, "force") - if err := v.backend.VolumeRm(vars["name"], force); err != nil { - return err - } - w.WriteHeader(http.StatusNoContent) - return nil -} - -func (v *volumeRouter) postVolumesPrune(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if err := httputils.ParseForm(r); err != nil { - return err - } - - pruneReport, err := v.backend.VolumesPrune(filters.Args{}) - if err != nil { - return err - } - return httputils.WriteJSON(w, http.StatusOK, pruneReport) -} diff --git a/vendor/github.com/docker/docker/api/server/router_swapper.go b/vendor/github.com/docker/docker/api/server/router_swapper.go deleted file mode 100644 index 1ecc7a7..0000000 --- a/vendor/github.com/docker/docker/api/server/router_swapper.go +++ /dev/null @@ -1,30 +0,0 @@ -package server - -import ( - "net/http" - "sync" - - "github.com/gorilla/mux" -) - -// routerSwapper is an http.Handler that allows you to swap -// mux routers. -type routerSwapper struct { - mu sync.Mutex - router *mux.Router -} - -// Swap changes the old router with the new one. -func (rs *routerSwapper) Swap(newRouter *mux.Router) { - rs.mu.Lock() - rs.router = newRouter - rs.mu.Unlock() -} - -// ServeHTTP makes the routerSwapper to implement the http.Handler interface. -func (rs *routerSwapper) ServeHTTP(w http.ResponseWriter, r *http.Request) { - rs.mu.Lock() - router := rs.router - rs.mu.Unlock() - router.ServeHTTP(w, r) -} diff --git a/vendor/github.com/docker/docker/api/server/server.go b/vendor/github.com/docker/docker/api/server/server.go deleted file mode 100644 index 60ee075..0000000 --- a/vendor/github.com/docker/docker/api/server/server.go +++ /dev/null @@ -1,210 +0,0 @@ -package server - -import ( - "crypto/tls" - "fmt" - "net" - "net/http" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/server/middleware" - "github.com/docker/docker/api/server/router" - "github.com/gorilla/mux" - "golang.org/x/net/context" -) - -// versionMatcher defines a variable matcher to be parsed by the router -// when a request is about to be served. -const versionMatcher = "/v{version:[0-9.]+}" - -// Config provides the configuration for the API server -type Config struct { - Logging bool - EnableCors bool - CorsHeaders string - Version string - SocketGroup string - TLSConfig *tls.Config -} - -// Server contains instance details for the server -type Server struct { - cfg *Config - servers []*HTTPServer - routers []router.Router - routerSwapper *routerSwapper - middlewares []middleware.Middleware -} - -// New returns a new instance of the server based on the specified configuration. -// It allocates resources which will be needed for ServeAPI(ports, unix-sockets). -func New(cfg *Config) *Server { - return &Server{ - cfg: cfg, - } -} - -// UseMiddleware appends a new middleware to the request chain. -// This needs to be called before the API routes are configured. -func (s *Server) UseMiddleware(m middleware.Middleware) { - s.middlewares = append(s.middlewares, m) -} - -// Accept sets a listener the server accepts connections into. -func (s *Server) Accept(addr string, listeners ...net.Listener) { - for _, listener := range listeners { - httpServer := &HTTPServer{ - srv: &http.Server{ - Addr: addr, - }, - l: listener, - } - s.servers = append(s.servers, httpServer) - } -} - -// Close closes servers and thus stop receiving requests -func (s *Server) Close() { - for _, srv := range s.servers { - if err := srv.Close(); err != nil { - logrus.Error(err) - } - } -} - -// serveAPI loops through all initialized servers and spawns goroutine -// with Serve method for each. It sets createMux() as Handler also. -func (s *Server) serveAPI() error { - var chErrors = make(chan error, len(s.servers)) - for _, srv := range s.servers { - srv.srv.Handler = s.routerSwapper - go func(srv *HTTPServer) { - var err error - logrus.Infof("API listen on %s", srv.l.Addr()) - if err = srv.Serve(); err != nil && strings.Contains(err.Error(), "use of closed network connection") { - err = nil - } - chErrors <- err - }(srv) - } - - for i := 0; i < len(s.servers); i++ { - err := <-chErrors - if err != nil { - return err - } - } - - return nil -} - -// HTTPServer contains an instance of http server and the listener. -// srv *http.Server, contains configuration to create an http server and a mux router with all api end points. -// l net.Listener, is a TCP or Socket listener that dispatches incoming request to the router. -type HTTPServer struct { - srv *http.Server - l net.Listener -} - -// Serve starts listening for inbound requests. -func (s *HTTPServer) Serve() error { - return s.srv.Serve(s.l) -} - -// Close closes the HTTPServer from listening for the inbound requests. -func (s *HTTPServer) Close() error { - return s.l.Close() -} - -func (s *Server) makeHTTPHandler(handler httputils.APIFunc) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - // Define the context that we'll pass around to share info - // like the docker-request-id. - // - // The 'context' will be used for global data that should - // apply to all requests. Data that is specific to the - // immediate function being called should still be passed - // as 'args' on the function call. - ctx := context.WithValue(context.Background(), httputils.UAStringKey, r.Header.Get("User-Agent")) - handlerFunc := s.handlerWithGlobalMiddlewares(handler) - - vars := mux.Vars(r) - if vars == nil { - vars = make(map[string]string) - } - - if err := handlerFunc(ctx, w, r, vars); err != nil { - statusCode := httputils.GetHTTPErrorStatusCode(err) - errFormat := "%v" - if statusCode == http.StatusInternalServerError { - errFormat = "%+v" - } - logrus.Errorf("Handler for %s %s returned error: "+errFormat, r.Method, r.URL.Path, err) - httputils.MakeErrorHandler(err)(w, r) - } - } -} - -// InitRouter initializes the list of routers for the server. -// This method also enables the Go profiler if enableProfiler is true. -func (s *Server) InitRouter(enableProfiler bool, routers ...router.Router) { - s.routers = append(s.routers, routers...) - - m := s.createMux() - if enableProfiler { - profilerSetup(m) - } - s.routerSwapper = &routerSwapper{ - router: m, - } -} - -// createMux initializes the main router the server uses. -func (s *Server) createMux() *mux.Router { - m := mux.NewRouter() - - logrus.Debug("Registering routers") - for _, apiRouter := range s.routers { - for _, r := range apiRouter.Routes() { - f := s.makeHTTPHandler(r.Handler()) - - logrus.Debugf("Registering %s, %s", r.Method(), r.Path()) - m.Path(versionMatcher + r.Path()).Methods(r.Method()).Handler(f) - m.Path(r.Path()).Methods(r.Method()).Handler(f) - } - } - - err := errors.NewRequestNotFoundError(fmt.Errorf("page not found")) - notFoundHandler := httputils.MakeErrorHandler(err) - m.HandleFunc(versionMatcher+"/{path:.*}", notFoundHandler) - m.NotFoundHandler = notFoundHandler - - return m -} - -// Wait blocks the server goroutine until it exits. -// It sends an error message if there is any error during -// the API execution. -func (s *Server) Wait(waitChan chan error) { - if err := s.serveAPI(); err != nil { - logrus.Errorf("ServeAPI error: %v", err) - waitChan <- err - return - } - waitChan <- nil -} - -// DisableProfiler reloads the server mux without adding the profiler routes. -func (s *Server) DisableProfiler() { - s.routerSwapper.Swap(s.createMux()) -} - -// EnableProfiler reloads the server mux adding the profiler routes. -func (s *Server) EnableProfiler() { - m := s.createMux() - profilerSetup(m) - s.routerSwapper.Swap(m) -} diff --git a/vendor/github.com/docker/docker/api/server/server_test.go b/vendor/github.com/docker/docker/api/server/server_test.go deleted file mode 100644 index 11831c1..0000000 --- a/vendor/github.com/docker/docker/api/server/server_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package server - -import ( - "net/http" - "net/http/httptest" - "strings" - "testing" - - "github.com/docker/docker/api" - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/server/middleware" - - "golang.org/x/net/context" -) - -func TestMiddlewares(t *testing.T) { - cfg := &Config{ - Version: "0.1omega2", - } - srv := &Server{ - cfg: cfg, - } - - srv.UseMiddleware(middleware.NewVersionMiddleware("0.1omega2", api.DefaultVersion, api.MinVersion)) - - req, _ := http.NewRequest("GET", "/containers/json", nil) - resp := httptest.NewRecorder() - ctx := context.Background() - - localHandler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if httputils.VersionFromContext(ctx) == "" { - t.Fatalf("Expected version, got empty string") - } - - if sv := w.Header().Get("Server"); !strings.Contains(sv, "Docker/0.1omega2") { - t.Fatalf("Expected server version in the header `Docker/0.1omega2`, got %s", sv) - } - - return nil - } - - handlerFunc := srv.handlerWithGlobalMiddlewares(localHandler) - if err := handlerFunc(ctx, resp, req, map[string]string{}); err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/api/swagger-gen.yaml b/vendor/github.com/docker/docker/api/swagger-gen.yaml deleted file mode 100644 index f07a027..0000000 --- a/vendor/github.com/docker/docker/api/swagger-gen.yaml +++ /dev/null @@ -1,12 +0,0 @@ - -layout: - models: - - name: definition - source: asset:model - target: "{{ joinFilePath .Target .ModelPackage }}" - file_name: "{{ (snakize (pascalize .Name)) }}.go" - operations: - - name: handler - source: asset:serverOperation - target: "{{ joinFilePath .Target .APIPackage .Package }}" - file_name: "{{ (snakize (pascalize .Name)) }}.go" diff --git a/vendor/github.com/docker/docker/api/swagger.yaml b/vendor/github.com/docker/docker/api/swagger.yaml deleted file mode 100644 index d19e8c9..0000000 --- a/vendor/github.com/docker/docker/api/swagger.yaml +++ /dev/null @@ -1,7785 +0,0 @@ -# A Swagger 2.0 (a.k.a. OpenAPI) definition of the Engine API. -# -# This is used for generating API documentation and the types used by the -# client/server. See api/README.md for more information. -# -# Some style notes: -# - This file is used by ReDoc, which allows GitHub Flavored Markdown in -# descriptions. -# - There is no maximum line length, for ease of editing and pretty diffs. -# - operationIds are in the format "NounVerb", with a singular noun. - -swagger: "2.0" -schemes: - - "http" - - "https" -produces: - - "application/json" - - "text/plain" -consumes: - - "application/json" - - "text/plain" -basePath: "/v1.26" -info: - title: "Docker Engine API" - version: "1.26" - x-logo: - url: "https://docs.docker.com/images/logo-docker-main.png" - description: | - The Engine API is an HTTP API served by Docker Engine. It is the API the Docker client uses to communicate with the Engine, so everything the Docker client can do can be done with the API. - - Most of the client's commands map directly to API endpoints (e.g. `docker ps` is `GET /containers/json`). The notable exception is running containers, which consists of several API calls. - - # Errors - - The API uses standard HTTP status codes to indicate the success or failure of the API call. The body of the response will be JSON in the following format: - - ``` - { - "message": "page not found" - } - ``` - - # Versioning - - The API is usually changed in each release of Docker, so API calls are versioned to ensure that clients don't break. - - For Docker Engine >= 1.13.1, the API version is 1.26. To lock to this version, you prefix the URL with `/v1.26`. For example, calling `/info` is the same as calling `/v1.26/info`. - - Engine releases in the near future should support this version of the API, so your client will continue to work even if it is talking to a newer Engine. - - In previous versions of Docker, it was possible to access the API without providing a version. This behaviour is now deprecated will be removed in a future version of Docker. - - The API uses an open schema model, which means server may add extra properties to responses. Likewise, the server will ignore any extra query parameters and request body properties. When you write clients, you need to ignore additional properties in responses to ensure they do not break when talking to newer Docker daemons. - - This documentation is for version 1.26 of the API, which was introduced with Docker 1.13.1. Use this table to find documentation for previous versions of the API: - - Docker version | API version | Changes - ----------------|-------------|--------- - 1.13.0 | [1.25](https://docs.docker.com/engine/api/v1.25/) | [API changes](https://docs.docker.com/engine/api/version-history/#v1-25-api-changes) - 1.12.x | [1.24](https://docs.docker.com/engine/api/v1.24/) | [API changes](https://docs.docker.com/engine/api/version-history/#v1-24-api-changes) - 1.11.x | [1.23](https://docs.docker.com/engine/api/v1.23/) | [API changes](https://docs.docker.com/engine/api/version-history/#v1-23-api-changes) - 1.10.x | [1.22](https://docs.docker.com/engine/api/v1.22/) | [API changes](https://docs.docker.com/engine/api/version-history/#v1-22-api-changes) - 1.9.x | [1.21](https://docs.docker.com/engine/api/v1.21/) | [API changes](https://docs.docker.com/engine/api/version-history/#v1-21-api-changes) - 1.8.x | [1.20](https://docs.docker.com/engine/api/v1.20/) | [API changes](https://docs.docker.com/engine/api/version-history/#v1-20-api-changes) - 1.7.x | [1.19](https://docs.docker.com/engine/api/v1.19/) | [API changes](https://docs.docker.com/engine/api/version-history/#v1-19-api-changes) - 1.6.x | [1.18](https://docs.docker.com/engine/api/v1.18/) | [API changes](https://docs.docker.com/engine/api/version-history/#v1-18-api-changes) - - # Authentication - - Authentication for registries is handled client side. The client has to send authentication details to various endpoints that need to communicate with registries, such as `POST /images/(name)/push`. These are sent as `X-Registry-Auth` header as a Base64 encoded (JSON) string with the following structure: - - ``` - { - "username": "string", - "password": "string", - "email": "string", - "serveraddress": "string" - } - ``` - - The `serveraddress` is a domain/IP without a protocol. Throughout this structure, double quotes are required. - - If you have already got an identity token from the [`/auth` endpoint](#operation/SystemAuth), you can just pass this instead of credentials: - - ``` - { - "identitytoken": "9cbaf023786cd7..." - } - ``` - -# The tags on paths define the menu sections in the ReDoc documentation, so -# the usage of tags must make sense for that: -# - They should be singular, not plural. -# - There should not be too many tags, or the menu becomes unwieldly. For -# example, it is preferable to add a path to the "System" tag instead of -# creating a tag with a single path in it. -# - The order of tags in this list defines the order in the menu. -tags: - # Primary objects - - name: "Container" - x-displayName: "Containers" - description: | - Create and manage containers. - - name: "Image" - x-displayName: "Images" - - name: "Network" - x-displayName: "Networks" - description: | - Networks are user-defined networks that containers can be attached to. See the [networking documentation](https://docs.docker.com/engine/userguide/networking/) for more information. - - name: "Volume" - x-displayName: "Volumes" - description: | - Create and manage persistent storage that can be attached to containers. - - name: "Exec" - x-displayName: "Exec" - description: | - Run new commands inside running containers. See the [command-line reference](https://docs.docker.com/engine/reference/commandline/exec/) for more information. - - To exec a command in a container, you first need to create an exec instance, then start it. These two API endpoints are wrapped up in a single command-line command, `docker exec`. - - name: "Secret" - x-displayName: "Secrets" - # Swarm things - - name: "Swarm" - x-displayName: "Swarm" - description: | - Engines can be clustered together in a swarm. See [the swarm mode documentation](https://docs.docker.com/engine/swarm/) for more information. - - name: "Node" - x-displayName: "Nodes" - description: | - Nodes are instances of the Engine participating in a swarm. Swarm mode must be enabled for these endpoints to work. - - name: "Service" - x-displayName: "Services" - description: | - Services are the definitions of tasks to run on a swarm. Swarm mode must be enabled for these endpoints to work. - - name: "Task" - x-displayName: "Tasks" - description: | - A task is a container running on a swarm. It is the atomic scheduling unit of swarm. Swarm mode must be enabled for these endpoints to work. - # System things - - name: "Plugin" - x-displayName: "Plugins" - - name: "System" - x-displayName: "System" - -definitions: - Port: - type: "object" - description: "An open port on a container" - required: [PrivatePort, Type] - properties: - IP: - type: "string" - format: "ip-address" - PrivatePort: - type: "integer" - format: "uint16" - x-nullable: false - description: "Port on the container" - PublicPort: - type: "integer" - format: "uint16" - description: "Port exposed on the host" - Type: - type: "string" - x-nullable: false - enum: ["tcp", "udp"] - example: - PrivatePort: 8080 - PublicPort: 80 - Type: "tcp" - - MountPoint: - type: "object" - description: "A mount point inside a container" - properties: - Type: - type: "string" - Name: - type: "string" - Source: - type: "string" - Destination: - type: "string" - Driver: - type: "string" - Mode: - type: "string" - RW: - type: "boolean" - Propagation: - type: "string" - - DeviceMapping: - type: "object" - description: "A device mapping between the host and container" - properties: - PathOnHost: - type: "string" - PathInContainer: - type: "string" - CgroupPermissions: - type: "string" - example: - PathOnHost: "/dev/deviceName" - PathInContainer: "/dev/deviceName" - CgroupPermissions: "mrw" - - ThrottleDevice: - type: "object" - properties: - Path: - description: "Device path" - type: "string" - Rate: - description: "Rate" - type: "integer" - format: "int64" - minimum: 0 - - Mount: - type: "object" - properties: - Target: - description: "Container path." - type: "string" - Source: - description: "Mount source (e.g. a volume name, a host path)." - Type: - description: | - The mount type. Available types: - - - `bind` Mounts a file or directory from the host into the container. Must exist prior to creating the container. - - `volume` Creates a volume with the given name and options (or uses a pre-existing volume with the same name and options). These are **not** removed when the container is removed. - - `tmpfs` Create a tmpfs with the given options. The mount source cannot be specified for tmpfs. - type: "string" - enum: - - "bind" - - "volume" - - "tmpfs" - ReadOnly: - description: "Whether the mount should be read-only." - type: "boolean" - BindOptions: - description: "Optional configuration for the `bind` type." - type: "object" - properties: - Propagation: - description: "A propagation mode with the value `[r]private`, `[r]shared`, or `[r]slave`." - enum: - - "private" - - "rprivate" - - "shared" - - "rshared" - - "slave" - - "rslave" - VolumeOptions: - description: "Optional configuration for the `volume` type." - type: "object" - properties: - NoCopy: - description: "Populate volume with data from the target." - type: "boolean" - default: false - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - DriverConfig: - description: "Map of driver specific options" - type: "object" - properties: - Name: - description: "Name of the driver to use to create the volume." - type: "string" - Options: - description: "key/value map of driver specific options." - type: "object" - additionalProperties: - type: "string" - TmpfsOptions: - description: "Optional configuration for the `tmpfs` type." - type: "object" - properties: - SizeBytes: - description: "The size for the tmpfs mount in bytes." - type: "integer" - format: "int64" - Mode: - description: "The permission mode for the tmpfs mount in an integer." - type: "integer" - RestartPolicy: - description: | - The behavior to apply when the container exits. The default is not to restart. - - An ever increasing delay (double the previous delay, starting at 100ms) is added before each restart to prevent flooding the server. - type: "object" - properties: - Name: - type: "string" - description: | - - `always` Always restart - - `unless-stopped` Restart always except when the user has manually stopped the container - - `on-failure` Restart only when the container exit code is non-zero - enum: - - "always" - - "unless-stopped" - - "on-failure" - MaximumRetryCount: - type: "integer" - description: "If `on-failure` is used, the number of times to retry before giving up" - default: {} - - Resources: - description: "A container's resources (cgroups config, ulimits, etc)" - type: "object" - properties: - # Applicable to all platforms - CpuShares: - description: "An integer value representing this container's relative CPU weight versus other containers." - type: "integer" - Memory: - description: "Memory limit in bytes." - type: "integer" - default: 0 - # Applicable to UNIX platforms - CgroupParent: - description: "Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist." - type: "string" - BlkioWeight: - description: "Block IO weight (relative weight)." - type: "integer" - minimum: 0 - maximum: 1000 - BlkioWeightDevice: - description: | - Block IO weight (relative device weight) in the form `[{"Path": "device_path", "Weight": weight}]`. - type: "array" - items: - type: "object" - properties: - Path: - type: "string" - Weight: - type: "integer" - minimum: 0 - BlkioDeviceReadBps: - description: | - Limit read rate (bytes per second) from a device, in the form `[{"Path": "device_path", "Rate": rate}]`. - type: "array" - items: - $ref: "#/definitions/ThrottleDevice" - BlkioDeviceWriteBps: - description: | - Limit write rate (bytes per second) to a device, in the form `[{"Path": "device_path", "Rate": rate}]`. - type: "array" - items: - $ref: "#/definitions/ThrottleDevice" - BlkioDeviceReadIOps: - description: | - Limit read rate (IO per second) from a device, in the form `[{"Path": "device_path", "Rate": rate}]`. - type: "array" - items: - $ref: "#/definitions/ThrottleDevice" - BlkioDeviceWriteIOps: - description: | - Limit write rate (IO per second) to a device, in the form `[{"Path": "device_path", "Rate": rate}]`. - type: "array" - items: - $ref: "#/definitions/ThrottleDevice" - CpuPeriod: - description: "The length of a CPU period in microseconds." - type: "integer" - format: "int64" - CpuQuota: - description: "Microseconds of CPU time that the container can get in a CPU period." - type: "integer" - format: "int64" - CpuRealtimePeriod: - description: "The length of a CPU real-time period in microseconds. Set to 0 to allocate no time allocated to real-time tasks." - type: "integer" - format: "int64" - CpuRealtimeRuntime: - description: "The length of a CPU real-time runtime in microseconds. Set to 0 to allocate no time allocated to real-time tasks." - type: "integer" - format: "int64" - CpusetCpus: - description: "CPUs in which to allow execution (e.g., `0-3`, `0,1`)" - type: "string" - CpusetMems: - description: "Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems." - type: "string" - Devices: - description: "A list of devices to add to the container." - type: "array" - items: - $ref: "#/definitions/DeviceMapping" - DiskQuota: - description: "Disk limit (in bytes)." - type: "integer" - format: "int64" - KernelMemory: - description: "Kernel memory limit in bytes." - type: "integer" - format: "int64" - MemoryReservation: - description: "Memory soft limit in bytes." - type: "integer" - format: "int64" - MemorySwap: - description: "Total memory limit (memory + swap). Set as `-1` to enable unlimited swap." - type: "integer" - format: "int64" - MemorySwappiness: - description: "Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100." - type: "integer" - format: "int64" - minimum: 0 - maximum: 100 - NanoCPUs: - description: "CPU quota in units of 10-9 CPUs." - type: "integer" - format: "int64" - OomKillDisable: - description: "Disable OOM Killer for the container." - type: "boolean" - PidsLimit: - description: "Tune a container's pids limit. Set -1 for unlimited." - type: "integer" - format: "int64" - Ulimits: - description: | - A list of resource limits to set in the container. For example: `{"Name": "nofile", "Soft": 1024, "Hard": 2048}`" - type: "array" - items: - type: "object" - properties: - Name: - description: "Name of ulimit" - type: "string" - Soft: - description: "Soft limit" - type: "integer" - Hard: - description: "Hard limit" - type: "integer" - # Applicable to Windows - CpuCount: - description: | - The number of usable CPUs (Windows only). - - On Windows Server containers, the processor resource controls are mutually exclusive. The order of precedence is `CPUCount` first, then `CPUShares`, and `CPUPercent` last. - type: "integer" - format: "int64" - CpuPercent: - description: | - The usable percentage of the available CPUs (Windows only). - - On Windows Server containers, the processor resource controls are mutually exclusive. The order of precedence is `CPUCount` first, then `CPUShares`, and `CPUPercent` last. - type: "integer" - format: "int64" - IOMaximumIOps: - description: "Maximum IOps for the container system drive (Windows only)" - type: "integer" - format: "int64" - IOMaximumBandwidth: - description: "Maximum IO in bytes per second for the container system drive (Windows only)" - type: "integer" - format: "int64" - - HostConfig: - description: "Container configuration that depends on the host we are running on" - allOf: - - $ref: "#/definitions/Resources" - - type: "object" - properties: - # Applicable to all platforms - Binds: - type: "array" - description: | - A list of volume bindings for this container. Each volume binding is a string in one of these forms: - - - `host-src:container-dest` to bind-mount a host path into the container. Both `host-src`, and `container-dest` must be an _absolute_ path. - - `host-src:container-dest:ro` to make the bind-mount read-only inside the container. Both `host-src`, and `container-dest` must be an _absolute_ path. - - `volume-name:container-dest` to bind-mount a volume managed by a volume driver into the container. `container-dest` must be an _absolute_ path. - - `volume-name:container-dest:ro` to mount the volume read-only inside the container. `container-dest` must be an _absolute_ path. - items: - type: "string" - ContainerIDFile: - type: "string" - description: "Path to a file where the container ID is written" - LogConfig: - type: "object" - description: "The logging configuration for this container" - properties: - Type: - type: "string" - enum: - - "json-file" - - "syslog" - - "journald" - - "gelf" - - "fluentd" - - "awslogs" - - "splunk" - - "etwlogs" - - "none" - Config: - type: "object" - additionalProperties: - type: "string" - NetworkMode: - type: "string" - description: "Network mode to use for this container. Supported standard values are: `bridge`, `host`, `none`, and `container:`. Any other value is taken - as a custom network's name to which this container should connect to." - PortBindings: - type: "object" - description: "A map of exposed container ports and the host port they should map to." - additionalProperties: - type: "object" - properties: - HostIp: - type: "string" - description: "The host IP address" - HostPort: - type: "string" - description: "The host port number, as a string" - RestartPolicy: - $ref: "#/definitions/RestartPolicy" - AutoRemove: - type: "boolean" - description: "Automatically remove the container when the container's process exits. This has no effect if `RestartPolicy` is set." - VolumeDriver: - type: "string" - description: "Driver that this container uses to mount volumes." - VolumesFrom: - type: "array" - description: "A list of volumes to inherit from another container, specified in the form `[:]`." - items: - type: "string" - Mounts: - description: "Specification for mounts to be added to the container." - type: "array" - items: - $ref: "#/definitions/Mount" - - # Applicable to UNIX platforms - CapAdd: - type: "array" - description: "A list of kernel capabilities to add to the container." - items: - type: "string" - CapDrop: - type: "array" - description: "A list of kernel capabilities to drop from the container." - items: - type: "string" - Dns: - type: "array" - description: "A list of DNS servers for the container to use." - items: - type: "string" - DnsOptions: - type: "array" - description: "A list of DNS options." - items: - type: "string" - DnsSearch: - type: "array" - description: "A list of DNS search domains." - items: - type: "string" - ExtraHosts: - type: "array" - description: | - A list of hostnames/IP mappings to add to the container's `/etc/hosts` file. Specified in the form `["hostname:IP"]`. - items: - type: "string" - GroupAdd: - type: "array" - description: "A list of additional groups that the container process will run as." - items: - type: "string" - IpcMode: - type: "string" - description: "IPC namespace to use for the container." - Cgroup: - type: "string" - description: "Cgroup to use for the container." - Links: - type: "array" - description: "A list of links for the container in the form `container_name:alias`." - items: - type: "string" - OomScoreAdj: - type: "integer" - description: "An integer value containing the score given to the container in order to tune OOM killer preferences." - PidMode: - type: "string" - description: | - Set the PID (Process) Namespace mode for the container. It can be either: - - - `"container:"`: joins another container's PID namespace - - `"host"`: use the host's PID namespace inside the container - Privileged: - type: "boolean" - description: "Gives the container full access to the host." - PublishAllPorts: - type: "boolean" - description: "Allocates a random host port for all of a container's exposed ports." - ReadonlyRootfs: - type: "boolean" - description: "Mount the container's root filesystem as read only." - SecurityOpt: - type: "array" - description: "A list of string values to customize labels for MLS - systems, such as SELinux." - items: - type: "string" - StorageOpt: - type: "object" - description: | - Storage driver options for this container, in the form `{"size": "120G"}`. - additionalProperties: - type: "string" - Tmpfs: - type: "object" - description: | - A map of container directories which should be replaced by tmpfs mounts, and their corresponding mount options. For example: `{ "/run": "rw,noexec,nosuid,size=65536k" }`. - additionalProperties: - type: "string" - UTSMode: - type: "string" - description: "UTS namespace to use for the container." - UsernsMode: - type: "string" - description: "Sets the usernamespace mode for the container when usernamespace remapping option is enabled." - ShmSize: - type: "integer" - description: "Size of `/dev/shm` in bytes. If omitted, the system uses 64MB." - minimum: 0 - Sysctls: - type: "object" - description: | - A list of kernel parameters (sysctls) to set in the container. For example: `{"net.ipv4.ip_forward": "1"}` - additionalProperties: - type: "string" - Runtime: - type: "string" - description: "Runtime to use with this container." - # Applicable to Windows - ConsoleSize: - type: "array" - description: "Initial console size, as an `[height, width]` array. (Windows only)" - minItems: 2 - maxItems: 2 - items: - type: "integer" - minimum: 0 - Isolation: - type: "string" - description: "Isolation technology of the container. (Windows only)" - enum: - - "default" - - "process" - - "hyperv" - - Config: - description: "Configuration for a container that is portable between hosts" - type: "object" - properties: - Hostname: - description: "The hostname to use for the container, as a valid RFC 1123 hostname." - type: "string" - Domainname: - description: "The domain name to use for the container." - type: "string" - User: - description: "The user that commands are run as inside the container." - type: "string" - AttachStdin: - description: "Whether to attach to `stdin`." - type: "boolean" - default: false - AttachStdout: - description: "Whether to attach to `stdout`." - type: "boolean" - default: true - AttachStderr: - description: "Whether to attach to `stderr`." - type: "boolean" - default: true - ExposedPorts: - description: | - An object mapping ports to an empty object in the form: - - `{"/": {}}` - type: "object" - additionalProperties: - type: "object" - enum: - - {} - default: {} - Tty: - description: "Attach standard streams to a TTY, including `stdin` if it is not closed." - type: "boolean" - default: false - OpenStdin: - description: "Open `stdin`" - type: "boolean" - default: false - StdinOnce: - description: "Close `stdin` after one attached client disconnects" - type: "boolean" - default: false - Env: - description: | - A list of environment variables to set inside the container in the form `["VAR=value", ...]` - type: "array" - items: - type: "string" - Cmd: - description: "Command to run specified as a string or an array of strings." - type: - - "array" - - "string" - items: - type: "string" - Healthcheck: - description: "A test to perform to check that the container is healthy." - type: "object" - properties: - Test: - description: | - The test to perform. Possible values are: - - - `{}` inherit healthcheck from image or parent image - - `{"NONE"}` disable healthcheck - - `{"CMD", args...}` exec arguments directly - - `{"CMD-SHELL", command}` run command with system's default shell - type: "array" - items: - type: "string" - Interval: - description: "The time to wait between checks in nanoseconds. 0 means inherit." - type: "integer" - Timeout: - description: "The time to wait before considering the check to have hung. 0 means inherit." - type: "integer" - Retries: - description: "The number of consecutive failures needed to consider a container as unhealthy. 0 means inherit." - type: "integer" - ArgsEscaped: - description: "Command is already escaped (Windows only)" - type: "boolean" - Image: - description: "The name of the image to use when creating the container" - type: "string" - Volumes: - description: "An object mapping mount point paths inside the container to empty objects." - type: "object" - properties: - additionalProperties: - type: "object" - enum: - - {} - default: {} - WorkingDir: - description: "The working directory for commands to run in." - type: "string" - Entrypoint: - description: | - The entry point for the container as a string or an array of strings. - - If the array consists of exactly one empty string (`[""]`) then the entry point is reset to system default (i.e., the entry point used by docker when there is no `ENTRYPOINT` instruction in the `Dockerfile`). - type: - - "array" - - "string" - items: - type: "string" - NetworkDisabled: - description: "Disable networking for the container." - type: "boolean" - MacAddress: - description: "MAC address of the container." - type: "string" - OnBuild: - description: "`ONBUILD` metadata that were defined in the image's `Dockerfile`." - type: "array" - items: - type: "string" - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - StopSignal: - description: "Signal to stop a container as a string or unsigned integer." - type: "string" - default: "SIGTERM" - StopTimeout: - description: "Timeout to stop a container in seconds." - type: "integer" - default: 10 - Shell: - description: "Shell for when `RUN`, `CMD`, and `ENTRYPOINT` uses a shell." - type: "array" - items: - type: "string" - - NetworkConfig: - description: "TODO: check is correct" - type: "object" - properties: - Bridge: - type: "string" - Gateway: - type: "string" - Address: - type: "string" - IPPrefixLen: - type: "integer" - MacAddress: - type: "string" - PortMapping: - type: "string" - Ports: - type: "array" - items: - $ref: "#/definitions/Port" - - GraphDriver: - description: "Information about this container's graph driver." - type: "object" - properties: - Name: - type: "string" - Data: - type: "object" - additionalProperties: - type: "string" - - Image: - type: "object" - properties: - Id: - type: "string" - RepoTags: - type: "array" - items: - type: "string" - RepoDigests: - type: "array" - items: - type: "string" - Parent: - type: "string" - Comment: - type: "string" - Created: - type: "string" - Container: - type: "string" - ContainerConfig: - $ref: "#/definitions/Config" - DockerVersion: - type: "string" - Author: - type: "string" - Config: - $ref: "#/definitions/Config" - Architecture: - type: "string" - Os: - type: "string" - Size: - type: "integer" - format: "int64" - VirtualSize: - type: "integer" - format: "int64" - GraphDriver: - $ref: "#/definitions/GraphDriver" - RootFS: - type: "object" - properties: - Type: - type: "string" - Layers: - type: "array" - items: - type: "string" - BaseLayer: - type: "string" - - ImageSummary: - type: "object" - required: - - Id - - ParentId - - RepoTags - - RepoDigests - - Created - - Size - - SharedSize - - VirtualSize - - Labels - - Containers - properties: - Id: - type: "string" - x-nullable: false - ParentId: - type: "string" - x-nullable: false - RepoTags: - type: "array" - x-nullable: false - items: - type: "string" - RepoDigests: - type: "array" - x-nullable: false - items: - type: "string" - Created: - type: "integer" - x-nullable: false - Size: - type: "integer" - x-nullable: false - SharedSize: - type: "integer" - x-nullable: false - VirtualSize: - type: "integer" - x-nullable: false - Labels: - type: "object" - x-nullable: false - additionalProperties: - type: "string" - Containers: - x-nullable: false - type: "integer" - - AuthConfig: - type: "object" - properties: - username: - type: "string" - password: - type: "string" - email: - type: "string" - serveraddress: - type: "string" - example: - username: "hannibal" - password: "xxxx" - serveraddress: "https://index.docker.io/v1/" - - ProcessConfig: - type: "object" - properties: - privileged: - type: "boolean" - user: - type: "string" - tty: - type: "boolean" - entrypoint: - type: "string" - arguments: - type: "array" - items: - type: "string" - - Volume: - type: "object" - required: [Name, Driver, Mountpoint, Labels, Scope, Options] - properties: - Name: - type: "string" - description: "Name of the volume." - x-nullable: false - Driver: - type: "string" - description: "Name of the volume driver used by the volume." - x-nullable: false - Mountpoint: - type: "string" - description: "Mount path of the volume on the host." - x-nullable: false - Status: - type: "object" - description: | - Low-level details about the volume, provided by the volume driver. - Details are returned as a map with key/value pairs: - `{"key":"value","key2":"value2"}`. - - The `Status` field is optional, and is omitted if the volume driver - does not support this feature. - additionalProperties: - type: "object" - Labels: - type: "object" - description: "User-defined key/value metadata." - x-nullable: false - additionalProperties: - type: "string" - Scope: - type: "string" - description: "The level at which the volume exists. Either `global` for cluster-wide, or `local` for machine level." - default: "local" - x-nullable: false - enum: ["local", "global"] - Options: - type: "object" - description: "The driver specific options used when creating the volume." - additionalProperties: - type: "string" - UsageData: - type: "object" - required: [Size, RefCount] - properties: - Size: - type: "integer" - description: "The disk space used by the volume (local driver only)" - default: -1 - x-nullable: false - RefCount: - type: "integer" - default: -1 - description: "The number of containers referencing this volume." - x-nullable: false - - example: - Name: "tardis" - Driver: "custom" - Mountpoint: "/var/lib/docker/volumes/tardis" - Status: - hello: "world" - Labels: - com.example.some-label: "some-value" - com.example.some-other-label: "some-other-value" - Scope: "local" - - Network: - type: "object" - properties: - Name: - type: "string" - Id: - type: "string" - Created: - type: "string" - format: "dateTime" - Scope: - type: "string" - Driver: - type: "string" - EnableIPv6: - type: "boolean" - IPAM: - $ref: "#/definitions/IPAM" - Internal: - type: "boolean" - Containers: - type: "object" - additionalProperties: - $ref: "#/definitions/NetworkContainer" - Options: - type: "object" - additionalProperties: - type: "string" - Labels: - type: "object" - additionalProperties: - type: "string" - example: - Name: "net01" - Id: "7d86d31b1478e7cca9ebed7e73aa0fdeec46c5ca29497431d3007d2d9e15ed99" - Created: "2016-10-19T04:33:30.360899459Z" - Scope: "local" - Driver: "bridge" - EnableIPv6: false - IPAM: - Driver: "default" - Config: - - Subnet: "172.19.0.0/16" - Gateway: "172.19.0.1" - Options: - foo: "bar" - Internal: false - Containers: - 19a4d5d687db25203351ed79d478946f861258f018fe384f229f2efa4b23513c: - Name: "test" - EndpointID: "628cadb8bcb92de107b2a1e516cbffe463e321f548feb37697cce00ad694f21a" - MacAddress: "02:42:ac:13:00:02" - IPv4Address: "172.19.0.2/16" - IPv6Address: "" - Options: - com.docker.network.bridge.default_bridge: "true" - com.docker.network.bridge.enable_icc: "true" - com.docker.network.bridge.enable_ip_masquerade: "true" - com.docker.network.bridge.host_binding_ipv4: "0.0.0.0" - com.docker.network.bridge.name: "docker0" - com.docker.network.driver.mtu: "1500" - Labels: - com.example.some-label: "some-value" - com.example.some-other-label: "some-other-value" - IPAM: - type: "object" - properties: - Driver: - description: "Name of the IPAM driver to use." - type: "string" - default: "default" - Config: - description: "List of IPAM configuration options, specified as a map: `{\"Subnet\": , \"IPRange\": , \"Gateway\": , \"AuxAddress\": }`" - type: "array" - items: - type: "object" - additionalProperties: - type: "string" - Options: - description: "Driver-specific options, specified as a map." - type: "array" - items: - type: "object" - additionalProperties: - type: "string" - NetworkContainer: - type: "object" - properties: - EndpointID: - type: "string" - MacAddress: - type: "string" - IPv4Address: - type: "string" - IPv6Address: - type: "string" - - BuildInfo: - type: "object" - properties: - id: - type: "string" - stream: - type: "string" - error: - type: "string" - errorDetail: - $ref: "#/definitions/ErrorDetail" - status: - type: "string" - progress: - type: "string" - progressDetail: - $ref: "#/definitions/ProgressDetail" - - CreateImageInfo: - type: "object" - properties: - error: - type: "string" - status: - type: "string" - progress: - type: "string" - progressDetail: - $ref: "#/definitions/ProgressDetail" - - PushImageInfo: - type: "object" - properties: - error: - type: "string" - status: - type: "string" - progress: - type: "string" - progressDetail: - $ref: "#/definitions/ProgressDetail" - ErrorDetail: - type: "object" - properties: - code: - type: "integer" - message: - type: "string" - ProgressDetail: - type: "object" - properties: - code: - type: "integer" - message: - type: "integer" - - ErrorResponse: - description: "Represents an error." - type: "object" - required: ["message"] - properties: - message: - description: "The error message." - type: "string" - x-nullable: false - example: - message: "Something went wrong." - - IdResponse: - description: "Response to an API call that returns just an Id" - type: "object" - required: ["Id"] - properties: - Id: - description: "The id of the newly created object." - type: "string" - x-nullable: false - - EndpointSettings: - description: "Configuration for a network endpoint." - type: "object" - properties: - IPAMConfig: - description: "IPAM configurations for the endpoint" - type: "object" - properties: - IPv4Address: - type: "string" - IPv6Address: - type: "string" - LinkLocalIPs: - type: "array" - items: - type: "string" - Links: - type: "array" - items: - type: "string" - Aliases: - type: "array" - items: - type: "string" - NetworkID: - type: "string" - EndpointID: - type: "string" - Gateway: - type: "string" - IPAddress: - type: "string" - IPPrefixLen: - type: "integer" - IPv6Gateway: - type: "string" - GlobalIPv6Address: - type: "string" - GlobalIPv6PrefixLen: - type: "integer" - format: "int64" - MacAddress: - type: "string" - - PluginMount: - type: "object" - x-nullable: false - required: [Name, Description, Settable, Source, Destination, Type, Options] - properties: - Name: - type: "string" - x-nullable: false - Description: - type: "string" - x-nullable: false - Settable: - type: "array" - items: - type: "string" - Source: - type: "string" - Destination: - type: "string" - x-nullable: false - Type: - type: "string" - x-nullable: false - Options: - type: "array" - items: - type: "string" - - PluginDevice: - type: "object" - required: [Name, Description, Settable, Path] - x-nullable: false - properties: - Name: - type: "string" - x-nullable: false - Description: - type: "string" - x-nullable: false - Settable: - type: "array" - items: - type: "string" - Path: - type: "string" - - PluginEnv: - type: "object" - x-nullable: false - required: [Name, Description, Settable, Value] - properties: - Name: - x-nullable: false - type: "string" - Description: - x-nullable: false - type: "string" - Settable: - type: "array" - items: - type: "string" - Value: - type: "string" - - PluginInterfaceType: - type: "object" - x-nullable: false - required: [Prefix, Capability, Version] - properties: - Prefix: - type: "string" - x-nullable: false - Capability: - type: "string" - x-nullable: false - Version: - type: "string" - x-nullable: false - - Plugin: - description: "A plugin for the Engine API" - type: "object" - required: [Settings, Enabled, Config, Name] - properties: - Id: - type: "string" - Name: - type: "string" - x-nullable: false - Enabled: - description: "True when the plugin is running. False when the plugin is not running, only installed." - type: "boolean" - x-nullable: false - Settings: - description: "Settings that can be modified by users." - type: "object" - x-nullable: false - required: [Args, Devices, Env, Mounts] - properties: - Mounts: - type: "array" - items: - $ref: "#/definitions/PluginMount" - Env: - type: "array" - items: - type: "string" - Args: - type: "array" - items: - type: "string" - Devices: - type: "array" - items: - $ref: "#/definitions/PluginDevice" - PluginReference: - description: "plugin remote reference used to push/pull the plugin" - type: "string" - x-nullable: false - Config: - description: "The config of a plugin." - type: "object" - x-nullable: false - required: - - Description - - Documentation - - Interface - - Entrypoint - - WorkDir - - Network - - Linux - - PropagatedMount - - Mounts - - Env - - Args - properties: - Description: - type: "string" - x-nullable: false - Documentation: - type: "string" - x-nullable: false - Interface: - description: "The interface between Docker and the plugin" - x-nullable: false - type: "object" - required: [Types, Socket] - properties: - Types: - type: "array" - items: - $ref: "#/definitions/PluginInterfaceType" - Socket: - type: "string" - x-nullable: false - Entrypoint: - type: "array" - items: - type: "string" - WorkDir: - type: "string" - x-nullable: false - User: - type: "object" - x-nullable: false - properties: - UID: - type: "integer" - format: "uint32" - GID: - type: "integer" - format: "uint32" - Network: - type: "object" - x-nullable: false - required: [Type] - properties: - Type: - x-nullable: false - type: "string" - Linux: - type: "object" - x-nullable: false - required: [Capabilities, AllowAllDevices, Devices] - properties: - Capabilities: - type: "array" - items: - type: "string" - AllowAllDevices: - type: "boolean" - x-nullable: false - Devices: - type: "array" - items: - $ref: "#/definitions/PluginDevice" - PropagatedMount: - type: "string" - x-nullable: false - Mounts: - type: "array" - items: - $ref: "#/definitions/PluginMount" - Env: - type: "array" - items: - $ref: "#/definitions/PluginEnv" - Args: - type: "object" - x-nullable: false - required: [Name, Description, Settable, Value] - properties: - Name: - x-nullable: false - type: "string" - Description: - x-nullable: false - type: "string" - Settable: - type: "array" - items: - type: "string" - Value: - type: "array" - items: - type: "string" - rootfs: - type: "object" - properties: - type: - type: "string" - diff_ids: - type: "array" - items: - type: "string" - example: - Id: "5724e2c8652da337ab2eedd19fc6fc0ec908e4bd907c7421bf6a8dfc70c4c078" - Name: "tiborvass/sample-volume-plugin" - Tag: "latest" - Active: true - Settings: - Env: - - "DEBUG=0" - Args: null - Devices: null - Config: - Description: "A sample volume plugin for Docker" - Documentation: "https://docs.docker.com/engine/extend/plugins/" - Interface: - Types: - - "docker.volumedriver/1.0" - Socket: "plugins.sock" - Entrypoint: - - "/usr/bin/sample-volume-plugin" - - "/data" - WorkDir: "" - User: {} - Network: - Type: "" - Linux: - Capabilities: null - AllowAllDevices: false - Devices: null - Mounts: null - PropagatedMount: "/data" - Env: - - Name: "DEBUG" - Description: "If set, prints debug messages" - Settable: null - Value: "0" - Args: - Name: "args" - Description: "command line arguments" - Settable: null - Value: [] - - NodeSpec: - type: "object" - properties: - Name: - description: "Name for the node." - type: "string" - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - Role: - description: "Role of the node." - type: "string" - enum: - - "worker" - - "manager" - Availability: - description: "Availability of the node." - type: "string" - enum: - - "active" - - "pause" - - "drain" - example: - Availability: "active" - Name: "node-name" - Role: "manager" - Labels: - foo: "bar" - Node: - type: "object" - properties: - ID: - type: "string" - Version: - type: "object" - properties: - Index: - type: "integer" - format: "int64" - CreatedAt: - type: "string" - format: "dateTime" - UpdatedAt: - type: "string" - format: "dateTime" - Spec: - $ref: "#/definitions/NodeSpec" - Description: - type: "object" - properties: - Hostname: - type: "string" - Platform: - type: "object" - properties: - Architecture: - type: "string" - OS: - type: "string" - Resources: - type: "object" - properties: - NanoCPUs: - type: "integer" - format: "int64" - MemoryBytes: - type: "integer" - format: "int64" - Engine: - type: "object" - properties: - EngineVersion: - type: "string" - Labels: - type: "object" - additionalProperties: - type: "string" - Plugins: - type: "array" - items: - type: "object" - properties: - Type: - type: "string" - Name: - type: "string" - example: - ID: "24ifsmvkjbyhk" - Version: - Index: 8 - CreatedAt: "2016-06-07T20:31:11.853781916Z" - UpdatedAt: "2016-06-07T20:31:11.999868824Z" - Spec: - Name: "my-node" - Role: "manager" - Availability: "active" - Labels: - foo: "bar" - Description: - Hostname: "bf3067039e47" - Platform: - Architecture: "x86_64" - OS: "linux" - Resources: - NanoCPUs: 4000000000 - MemoryBytes: 8272408576 - Engine: - EngineVersion: "1.13.0" - Labels: - foo: "bar" - Plugins: - - Type: "Volume" - Name: "local" - - Type: "Network" - Name: "bridge" - - Type: "Network" - Name: "null" - - Type: "Network" - Name: "overlay" - Status: - State: "ready" - Addr: "172.17.0.2" - ManagerStatus: - Leader: true - Reachability: "reachable" - Addr: "172.17.0.2:2377" - SwarmSpec: - description: "User modifiable swarm configuration." - type: "object" - properties: - Name: - description: "Name of the swarm." - type: "string" - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - Orchestration: - description: "Orchestration configuration." - type: "object" - properties: - TaskHistoryRetentionLimit: - description: "The number of historic tasks to keep per instance or node. If negative, never remove completed or failed tasks." - type: "integer" - format: "int64" - Raft: - description: "Raft configuration." - type: "object" - properties: - SnapshotInterval: - description: "The number of log entries between snapshots." - type: "integer" - format: "int64" - KeepOldSnapshots: - description: "The number of snapshots to keep beyond the current snapshot." - type: "integer" - format: "int64" - LogEntriesForSlowFollowers: - description: "The number of log entries to keep around to sync up slow followers after a snapshot is created." - type: "integer" - format: "int64" - ElectionTick: - description: | - The number of ticks that a follower will wait for a message from the leader before becoming a candidate and starting an election. `ElectionTick` must be greater than `HeartbeatTick`. - - A tick currently defaults to one second, so these translate directly to seconds currently, but this is NOT guaranteed. - type: "integer" - HeartbeatTick: - description: | - The number of ticks between heartbeats. Every HeartbeatTick ticks, the leader will send a heartbeat to the followers. - - A tick currently defaults to one second, so these translate directly to seconds currently, but this is NOT guaranteed. - type: "integer" - Dispatcher: - description: "Dispatcher configuration." - type: "object" - properties: - HeartbeatPeriod: - description: "The delay for an agent to send a heartbeat to the dispatcher." - type: "integer" - format: "int64" - CAConfig: - description: "CA configuration." - type: "object" - properties: - NodeCertExpiry: - description: "The duration node certificates are issued for." - type: "integer" - format: "int64" - ExternalCAs: - description: "Configuration for forwarding signing requests to an external certificate authority." - type: "array" - items: - type: "object" - properties: - Protocol: - description: "Protocol for communication with the external CA (currently only `cfssl` is supported)." - type: "string" - enum: - - "cfssl" - default: "cfssl" - URL: - description: "URL where certificate signing requests should be sent." - type: "string" - Options: - description: "An object with key/value pairs that are interpreted as protocol-specific options for the external CA driver." - type: "object" - additionalProperties: - type: "string" - EncryptionConfig: - description: "Parameters related to encryption-at-rest." - type: "object" - properties: - AutoLockManagers: - description: "If set, generate a key and use it to lock data stored on the managers." - type: "boolean" - TaskDefaults: - description: "Defaults for creating tasks in this cluster." - type: "object" - properties: - LogDriver: - description: | - The log driver to use for tasks created in the orchestrator if unspecified by a service. - - Updating this value will only have an affect on new tasks. Old tasks will continue use their previously configured log driver until recreated. - type: "object" - properties: - Name: - type: "string" - Options: - type: "object" - additionalProperties: - type: "string" - example: - Name: "default" - Orchestration: - TaskHistoryRetentionLimit: 10 - Raft: - SnapshotInterval: 10000 - LogEntriesForSlowFollowers: 500 - HeartbeatTick: 1 - ElectionTick: 3 - Dispatcher: - HeartbeatPeriod: 5000000000 - CAConfig: - NodeCertExpiry: 7776000000000000 - JoinTokens: - Worker: "SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx" - Manager: "SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2" - EncryptionConfig: - AutoLockManagers: false - # The Swarm information for `GET /info`. It is the same as `GET /swarm`, but - # without `JoinTokens`. - ClusterInfo: - type: "object" - properties: - ID: - description: "The ID of the swarm." - type: "string" - Version: - type: "object" - properties: - Index: - type: "integer" - format: "int64" - CreatedAt: - type: "string" - format: "dateTime" - UpdatedAt: - type: "string" - format: "dateTime" - Spec: - $ref: "#/definitions/SwarmSpec" - TaskSpec: - description: "User modifiable task configuration." - type: "object" - properties: - ContainerSpec: - type: "object" - properties: - Image: - description: "The image name to use for the container." - type: "string" - Command: - description: "The command to be run in the image." - type: "array" - items: - type: "string" - Args: - description: "Arguments to the command." - type: "array" - items: - type: "string" - Env: - description: "A list of environment variables in the form `VAR=value`." - type: "array" - items: - type: "string" - Dir: - description: "The working directory for commands to run in." - type: "string" - User: - description: "The user inside the container." - type: "string" - Labels: - description: "User-defined key/value data." - type: "object" - additionalProperties: - type: "string" - TTY: - description: "Whether a pseudo-TTY should be allocated." - type: "boolean" - Mounts: - description: "Specification for mounts to be added to containers created as part of the service." - type: "array" - items: - $ref: "#/definitions/Mount" - StopGracePeriod: - description: "Amount of time to wait for the container to terminate before forcefully killing it." - type: "integer" - format: "int64" - DNSConfig: - description: "Specification for DNS related configurations in resolver configuration file (`resolv.conf`)." - type: "object" - properties: - Nameservers: - description: "The IP addresses of the name servers." - type: "array" - items: - type: "string" - Search: - description: "A search list for host-name lookup." - type: "array" - items: - type: "string" - Options: - description: "A list of internal resolver variables to be modified (e.g., `debug`, `ndots:3`, etc.)." - type: "array" - items: - type: "string" - Resources: - description: "Resource requirements which apply to each individual container created as part of the service." - type: "object" - properties: - Limits: - description: "Define resources limits." - type: "object" - properties: - NanoCPUs: - description: "CPU limit in units of 10-9 CPU shares." - type: "integer" - format: "int64" - MemoryBytes: - description: "Memory limit in Bytes." - type: "integer" - format: "int64" - Reservation: - description: "Define resources reservation." - properties: - NanoCPUs: - description: "CPU reservation in units of 10-9 CPU shares." - type: "integer" - format: "int64" - MemoryBytes: - description: "Memory reservation in Bytes." - type: "integer" - format: "int64" - RestartPolicy: - description: "Specification for the restart policy which applies to containers created as part of this service." - type: "object" - properties: - Condition: - description: "Condition for restart." - type: "string" - enum: - - "none" - - "on-failure" - - "any" - Delay: - description: "Delay between restart attempts." - type: "integer" - format: "int64" - MaxAttempts: - description: "Maximum attempts to restart a given container before giving up (default value is 0, which is ignored)." - type: "integer" - format: "int64" - default: 0 - Window: - description: "Windows is the time window used to evaluate the restart policy (default value is 0, which is unbounded)." - type: "integer" - format: "int64" - default: 0 - Placement: - type: "object" - properties: - Constraints: - description: "An array of constraints." - type: "array" - items: - type: "string" - ForceUpdate: - description: "A counter that triggers an update even if no relevant parameters have been changed." - type: "integer" - Networks: - type: "array" - items: - type: "object" - properties: - Target: - type: "string" - Aliases: - type: "array" - items: - type: "string" - LogDriver: - description: "Specifies the log driver to use for tasks created from this spec. If not present, the default one for the swarm will be used, finally falling back to the engine default if not specified." - type: "object" - properties: - Name: - type: "string" - Options: - type: "object" - additionalProperties: - type: "string" - TaskState: - type: "string" - enum: - - "new" - - "allocated" - - "pending" - - "assigned" - - "accepted" - - "preparing" - - "ready" - - "starting" - - "running" - - "complete" - - "shutdown" - - "failed" - - "rejected" - Task: - type: "object" - properties: - ID: - description: "The ID of the task." - type: "string" - Version: - type: "object" - properties: - Index: - type: "integer" - format: "int64" - CreatedAt: - type: "string" - format: "dateTime" - UpdatedAt: - type: "string" - format: "dateTime" - Name: - description: "Name of the task." - type: "string" - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - Spec: - $ref: "#/definitions/TaskSpec" - ServiceID: - description: "The ID of the service this task is part of." - type: "string" - Slot: - type: "integer" - NodeID: - description: "The ID of the node that this task is on." - type: "string" - Status: - type: "object" - properties: - Timestamp: - type: "string" - format: "dateTime" - State: - $ref: "#/definitions/TaskState" - Message: - type: "string" - Err: - type: "string" - ContainerStatus: - type: "object" - properties: - ContainerID: - type: "string" - PID: - type: "integer" - ExitCode: - type: "integer" - DesiredState: - $ref: "#/definitions/TaskState" - example: - ID: "0kzzo1i0y4jz6027t0k7aezc7" - Version: - Index: 71 - CreatedAt: "2016-06-07T21:07:31.171892745Z" - UpdatedAt: "2016-06-07T21:07:31.376370513Z" - Spec: - ContainerSpec: - Image: "redis" - Resources: - Limits: {} - Reservations: {} - RestartPolicy: - Condition: "any" - MaxAttempts: 0 - Placement: {} - ServiceID: "9mnpnzenvg8p8tdbtq4wvbkcz" - Slot: 1 - NodeID: "60gvrl6tm78dmak4yl7srz94v" - Status: - Timestamp: "2016-06-07T21:07:31.290032978Z" - State: "running" - Message: "started" - ContainerStatus: - ContainerID: "e5d62702a1b48d01c3e02ca1e0212a250801fa8d67caca0b6f35919ebc12f035" - PID: 677 - DesiredState: "running" - NetworksAttachments: - - Network: - ID: "4qvuz4ko70xaltuqbt8956gd1" - Version: - Index: 18 - CreatedAt: "2016-06-07T20:31:11.912919752Z" - UpdatedAt: "2016-06-07T21:07:29.955277358Z" - Spec: - Name: "ingress" - Labels: - com.docker.swarm.internal: "true" - DriverConfiguration: {} - IPAMOptions: - Driver: {} - Configs: - - Subnet: "10.255.0.0/16" - Gateway: "10.255.0.1" - DriverState: - Name: "overlay" - Options: - com.docker.network.driver.overlay.vxlanid_list: "256" - IPAMOptions: - Driver: - Name: "default" - Configs: - - Subnet: "10.255.0.0/16" - Gateway: "10.255.0.1" - Addresses: - - "10.255.0.10/16" - ServiceSpec: - description: "User modifiable configuration for a service." - properties: - Name: - description: "Name of the service." - type: "string" - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - TaskTemplate: - $ref: "#/definitions/TaskSpec" - Mode: - description: "Scheduling mode for the service." - type: "object" - properties: - Replicated: - type: "object" - properties: - Replicas: - type: "integer" - format: "int64" - Global: - type: "object" - UpdateConfig: - description: "Specification for the update strategy of the service." - type: "object" - properties: - Parallelism: - description: "Maximum number of tasks to be updated in one iteration (0 means unlimited parallelism)." - type: "integer" - format: "int64" - Delay: - description: "Amount of time between updates, in nanoseconds." - type: "integer" - format: "int64" - FailureAction: - description: "Action to take if an updated task fails to run, or stops running during the update." - type: "string" - enum: - - "continue" - - "pause" - Monitor: - description: "Amount of time to monitor each updated task for failures, in nanoseconds." - type: "integer" - format: "int64" - MaxFailureRatio: - description: "The fraction of tasks that may fail during an update before the failure action is invoked, specified as a floating point number between 0 and 1." - type: "number" - default: 0 - Networks: - description: "Array of network names or IDs to attach the service to." - type: "array" - items: - type: "object" - properties: - Target: - type: "string" - Aliases: - type: "array" - items: - type: "string" - EndpointSpec: - $ref: "#/definitions/EndpointSpec" - EndpointPortConfig: - type: "object" - properties: - Name: - type: "string" - Protocol: - type: "string" - enum: - - "tcp" - - "udp" - TargetPort: - description: "The port inside the container." - type: "integer" - PublishedPort: - description: "The port on the swarm hosts." - type: "integer" - EndpointSpec: - description: "Properties that can be configured to access and load balance a service." - type: "object" - properties: - Mode: - description: "The mode of resolution to use for internal load balancing - between tasks." - type: "string" - enum: - - "vip" - - "dnsrr" - default: "vip" - Ports: - description: "List of exposed ports that this service is accessible on from the outside. Ports can only be provided if `vip` resolution mode is used." - type: "array" - items: - $ref: "#/definitions/EndpointPortConfig" - Service: - type: "object" - properties: - ID: - type: "string" - Version: - type: "object" - properties: - Index: - type: "integer" - format: "int64" - CreatedAt: - type: "string" - format: "dateTime" - UpdatedAt: - type: "string" - format: "dateTime" - Spec: - $ref: "#/definitions/ServiceSpec" - Endpoint: - type: "object" - properties: - Spec: - $ref: "#/definitions/EndpointSpec" - Ports: - type: "array" - items: - $ref: "#/definitions/EndpointPortConfig" - VirtualIPs: - type: "array" - items: - type: "object" - properties: - NetworkID: - type: "string" - Addr: - type: "string" - UpdateStatus: - description: "The status of a service update." - type: "object" - properties: - State: - type: "string" - enum: - - "updating" - - "paused" - - "completed" - StartedAt: - type: "string" - format: "dateTime" - CompletedAt: - type: "string" - format: "dateTime" - Message: - type: "string" - example: - ID: "9mnpnzenvg8p8tdbtq4wvbkcz" - Version: - Index: 19 - CreatedAt: "2016-06-07T21:05:51.880065305Z" - UpdatedAt: "2016-06-07T21:07:29.962229872Z" - Spec: - Name: "hopeful_cori" - TaskTemplate: - ContainerSpec: - Image: "redis" - Resources: - Limits: {} - Reservations: {} - RestartPolicy: - Condition: "any" - MaxAttempts: 0 - Placement: {} - ForceUpdate: 0 - Mode: - Replicated: - Replicas: 1 - UpdateConfig: - Parallelism: 1 - FailureAction: "pause" - Monitor: 15000000000 - MaxFailureRatio: 0.15 - EndpointSpec: - Mode: "vip" - Ports: - - - Protocol: "tcp" - TargetPort: 6379 - PublishedPort: 30001 - Endpoint: - Spec: - Mode: "vip" - Ports: - - - Protocol: "tcp" - TargetPort: 6379 - PublishedPort: 30001 - Ports: - - - Protocol: "tcp" - TargetPort: 6379 - PublishedPort: 30001 - VirtualIPs: - - - NetworkID: "4qvuz4ko70xaltuqbt8956gd1" - Addr: "10.255.0.2/16" - - - NetworkID: "4qvuz4ko70xaltuqbt8956gd1" - Addr: "10.255.0.3/16" - ImageDeleteResponse: - type: "object" - properties: - Untagged: - description: "The image ID of an image that was untagged" - type: "string" - Deleted: - description: "The image ID of an image that was deleted" - type: "string" - ServiceUpdateResponse: - type: "object" - properties: - Warnings: - description: "Optional warning messages" - type: "array" - items: - type: "string" - example: - Warning: "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found" - ContainerSummary: - type: "array" - items: - type: "object" - properties: - Id: - description: "The ID of this container" - type: "string" - x-go-name: "ID" - Names: - description: "The names that this container has been given" - type: "array" - items: - type: "string" - Image: - description: "The name of the image used when creating this container" - type: "string" - ImageID: - description: "The ID of the image that this container was created from" - type: "string" - Command: - description: "Command to run when starting the container" - type: "string" - Created: - description: "When the container was created" - type: "integer" - format: "int64" - Ports: - description: "The ports exposed by this container" - type: "array" - items: - $ref: "#/definitions/Port" - SizeRw: - description: "The size of files that have been created or changed by this container" - type: "integer" - format: "int64" - SizeRootFs: - description: "The total size of all the files in this container" - type: "integer" - format: "int64" - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - State: - description: "The state of this container (e.g. `Exited`)" - type: "string" - Status: - description: "Additional human-readable status of this container (e.g. `Exit 0`)" - type: "string" - HostConfig: - type: "object" - properties: - NetworkMode: - type: "string" - NetworkSettings: - description: "A summary of the container's network settings" - type: "object" - properties: - Networks: - type: "object" - additionalProperties: - $ref: "#/definitions/EndpointSettings" - Mounts: - type: "array" - items: - $ref: "#/definitions/Mount" - SecretSpec: - type: "object" - properties: - Name: - description: "User-defined name of the secret." - type: "string" - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - Data: - description: "Base64-url-safe-encoded secret data" - type: "array" - items: - type: "string" - Secret: - type: "object" - properties: - ID: - type: "string" - Version: - type: "object" - properties: - Index: - type: "integer" - format: "int64" - CreatedAt: - type: "string" - format: "dateTime" - UpdatedAt: - type: "string" - format: "dateTime" - Spec: - $ref: "#/definitions/ServiceSpec" -paths: - /containers/json: - get: - summary: "List containers" - operationId: "ContainerList" - produces: - - "application/json" - parameters: - - name: "all" - in: "query" - description: "Return all containers. By default, only running containers are shown" - type: "boolean" - default: false - - name: "limit" - in: "query" - description: "Return this number of most recently created containers, including non-running ones." - type: "integer" - - name: "size" - in: "query" - description: "Return the size of container as fields `SizeRw` and `SizeRootFs`." - type: "boolean" - default: false - - name: "filters" - in: "query" - description: | - Filters to process on the container list, encoded as JSON (a `map[string][]string`). For example, `{"status": ["paused"]}` will only return paused containers. - - Available filters: - - `exited=` containers with exit code of `` - - `status=`(`created`|`restarting`|`running`|`removing`|`paused`|`exited`|`dead`) - - `label=key` or `label="key=value"` of a container label - - `isolation=`(`default`|`process`|`hyperv`) (Windows daemon only) - - `id=` a container's ID - - `name=` a container's name - - `is-task=`(`true`|`false`) - - `ancestor`=(`[:]`, ``, or ``) - - `before`=(`` or ``) - - `since`=(`` or ``) - - `volume`=(`` or ``) - - `network`=(`` or ``) - - `health`=(`starting`|`healthy`|`unhealthy`|`none`) - type: "string" - responses: - 200: - description: "no error" - schema: - $ref: "#/definitions/ContainerSummary" - examples: - application/json: - - Id: "8dfafdbc3a40" - Names: - - "/boring_feynman" - Image: "ubuntu:latest" - ImageID: "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82" - Command: "echo 1" - Created: 1367854155 - State: "Exited" - Status: "Exit 0" - Ports: - - PrivatePort: 2222 - PublicPort: 3333 - Type: "tcp" - Labels: - com.example.vendor: "Acme" - com.example.license: "GPL" - com.example.version: "1.0" - SizeRw: 12288 - SizeRootFs: 0 - HostConfig: - NetworkMode: "default" - NetworkSettings: - Networks: - bridge: - NetworkID: "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812" - EndpointID: "2cdc4edb1ded3631c81f57966563e5c8525b81121bb3706a9a9a3ae102711f3f" - Gateway: "172.17.0.1" - IPAddress: "172.17.0.2" - IPPrefixLen: 16 - IPv6Gateway: "" - GlobalIPv6Address: "" - GlobalIPv6PrefixLen: 0 - MacAddress: "02:42:ac:11:00:02" - Mounts: - - Name: "fac362...80535" - Source: "/data" - Destination: "/data" - Driver: "local" - Mode: "ro,Z" - RW: false - Propagation: "" - - Id: "9cd87474be90" - Names: - - "/coolName" - Image: "ubuntu:latest" - ImageID: "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82" - Command: "echo 222222" - Created: 1367854155 - State: "Exited" - Status: "Exit 0" - Ports: [] - Labels: {} - SizeRw: 12288 - SizeRootFs: 0 - HostConfig: - NetworkMode: "default" - NetworkSettings: - Networks: - bridge: - NetworkID: "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812" - EndpointID: "88eaed7b37b38c2a3f0c4bc796494fdf51b270c2d22656412a2ca5d559a64d7a" - Gateway: "172.17.0.1" - IPAddress: "172.17.0.8" - IPPrefixLen: 16 - IPv6Gateway: "" - GlobalIPv6Address: "" - GlobalIPv6PrefixLen: 0 - MacAddress: "02:42:ac:11:00:08" - Mounts: [] - - Id: "3176a2479c92" - Names: - - "/sleepy_dog" - Image: "ubuntu:latest" - ImageID: "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82" - Command: "echo 3333333333333333" - Created: 1367854154 - State: "Exited" - Status: "Exit 0" - Ports: [] - Labels: {} - SizeRw: 12288 - SizeRootFs: 0 - HostConfig: - NetworkMode: "default" - NetworkSettings: - Networks: - bridge: - NetworkID: "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812" - EndpointID: "8b27c041c30326d59cd6e6f510d4f8d1d570a228466f956edf7815508f78e30d" - Gateway: "172.17.0.1" - IPAddress: "172.17.0.6" - IPPrefixLen: 16 - IPv6Gateway: "" - GlobalIPv6Address: "" - GlobalIPv6PrefixLen: 0 - MacAddress: "02:42:ac:11:00:06" - Mounts: [] - - Id: "4cb07b47f9fb" - Names: - - "/running_cat" - Image: "ubuntu:latest" - ImageID: "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82" - Command: "echo 444444444444444444444444444444444" - Created: 1367854152 - State: "Exited" - Status: "Exit 0" - Ports: [] - Labels: {} - SizeRw: 12288 - SizeRootFs: 0 - HostConfig: - NetworkMode: "default" - NetworkSettings: - Networks: - bridge: - NetworkID: "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812" - EndpointID: "d91c7b2f0644403d7ef3095985ea0e2370325cd2332ff3a3225c4247328e66e9" - Gateway: "172.17.0.1" - IPAddress: "172.17.0.5" - IPPrefixLen: 16 - IPv6Gateway: "" - GlobalIPv6Address: "" - GlobalIPv6PrefixLen: 0 - MacAddress: "02:42:ac:11:00:05" - Mounts: [] - 400: - description: "bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Container"] - /containers/create: - post: - summary: "Create a container" - operationId: "ContainerCreate" - consumes: - - "application/json" - - "application/octet-stream" - produces: - - "application/json" - parameters: - - name: "name" - in: "query" - description: "Assign the specified name to the container. Must match `/?[a-zA-Z0-9_-]+`." - type: "string" - pattern: "/?[a-zA-Z0-9_-]+" - - name: "body" - in: "body" - description: "Container to create" - schema: - allOf: - - $ref: "#/definitions/Config" - - type: "object" - properties: - HostConfig: - $ref: "#/definitions/HostConfig" - NetworkingConfig: - description: "This container's networking configuration." - type: "object" - properties: - EndpointsConfig: - description: "A mapping of network name to endpoint configuration for that network." - type: "object" - additionalProperties: - $ref: "#/definitions/EndpointSettings" - example: - Hostname: "" - Domainname: "" - User: "" - AttachStdin: false - AttachStdout: true - AttachStderr: true - Tty: false - OpenStdin: false - StdinOnce: false - Env: - - "FOO=bar" - - "BAZ=quux" - Cmd: - - "date" - Entrypoint: "" - Image: "ubuntu" - Labels: - com.example.vendor: "Acme" - com.example.license: "GPL" - com.example.version: "1.0" - Volumes: - /volumes/data: {} - WorkingDir: "" - NetworkDisabled: false - MacAddress: "12:34:56:78:9a:bc" - ExposedPorts: - 22/tcp: {} - StopSignal: "SIGTERM" - StopTimeout: 10 - HostConfig: - Binds: - - "/tmp:/tmp" - Links: - - "redis3:redis" - Memory: 0 - MemorySwap: 0 - MemoryReservation: 0 - KernelMemory: 0 - NanoCPUs: 500000 - CpuPercent: 80 - CpuShares: 512 - CpuPeriod: 100000 - CpuRealtimePeriod: 1000000 - CpuRealtimeRuntime: 10000 - CpuQuota: 50000 - CpusetCpus: "0,1" - CpusetMems: "0,1" - MaximumIOps: 0 - MaximumIOBps: 0 - BlkioWeight: 300 - BlkioWeightDevice: - - {} - BlkioDeviceReadBps: - - {} - BlkioDeviceReadIOps: - - {} - BlkioDeviceWriteBps: - - {} - BlkioDeviceWriteIOps: - - {} - MemorySwappiness: 60 - OomKillDisable: false - OomScoreAdj: 500 - PidMode: "" - PidsLimit: -1 - PortBindings: - 22/tcp: - - HostPort: "11022" - PublishAllPorts: false - Privileged: false - ReadonlyRootfs: false - Dns: - - "8.8.8.8" - DnsOptions: - - "" - DnsSearch: - - "" - VolumesFrom: - - "parent" - - "other:ro" - CapAdd: - - "NET_ADMIN" - CapDrop: - - "MKNOD" - GroupAdd: - - "newgroup" - RestartPolicy: - Name: "" - MaximumRetryCount: 0 - AutoRemove: true - NetworkMode: "bridge" - Devices: [] - Ulimits: - - {} - LogConfig: - Type: "json-file" - Config: {} - SecurityOpt: [] - StorageOpt: {} - CgroupParent: "" - VolumeDriver: "" - ShmSize: 67108864 - NetworkingConfig: - EndpointsConfig: - isolated_nw: - IPAMConfig: - IPv4Address: "172.20.30.33" - IPv6Address: "2001:db8:abcd::3033" - LinkLocalIPs: - - "169.254.34.68" - - "fe80::3468" - Links: - - "container_1" - - "container_2" - Aliases: - - "server_x" - - "server_y" - - required: true - responses: - 201: - description: "Container created successfully" - schema: - type: "object" - required: [Id, Warnings] - properties: - Id: - description: "The ID of the created container" - type: "string" - x-nullable: false - Warnings: - description: "Warnings encountered when creating the container" - type: "array" - x-nullable: false - items: - type: "string" - examples: - application/json: - Id: "e90e34656806" - Warnings: [] - 400: - description: "bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 406: - description: "impossible to attach" - schema: - $ref: "#/definitions/ErrorResponse" - 409: - description: "conflict" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Container"] - /containers/{id}/json: - get: - summary: "Inspect a container" - description: "Return low-level information about a container." - operationId: "ContainerInspect" - produces: - - "application/json" - responses: - 200: - description: "no error" - schema: - type: "object" - properties: - Id: - description: "The ID of the container" - type: "string" - Created: - description: "The time the container was created" - type: "string" - Path: - description: "The path to the command being run" - type: "string" - Args: - description: "The arguments to the command being run" - type: "array" - items: - type: "string" - State: - description: "The state of the container." - type: "object" - properties: - Status: - description: "The status of the container. For example, `running` or `exited`." - type: "string" - Running: - description: "Whether this container is running." - type: "boolean" - Paused: - description: "Whether this container is paused." - type: "boolean" - Restarting: - description: "Whether this container is restarting." - type: "boolean" - OOMKilled: - description: "Whether this container has been killed because it ran out of memory." - type: "boolean" - Dead: - type: "boolean" - Pid: - description: "The process ID of this container" - type: "integer" - ExitCode: - description: "The last exit code of this container" - type: "integer" - Error: - type: "string" - StartedAt: - description: "The time when this container was last started." - type: "string" - FinishedAt: - description: "The time when this container last exited." - type: "string" - Image: - description: "The container's image" - type: "string" - ResolvConfPath: - type: "string" - HostnamePath: - type: "string" - HostsPath: - type: "string" - LogPath: - type: "string" - Node: - description: "TODO" - type: "object" - Name: - type: "string" - RestartCount: - type: "integer" - Driver: - type: "string" - MountLabel: - type: "string" - ProcessLabel: - type: "string" - AppArmorProfile: - type: "string" - ExecIDs: - type: "string" - HostConfig: - $ref: "#/definitions/HostConfig" - GraphDriver: - $ref: "#/definitions/GraphDriver" - SizeRw: - description: "The size of files that have been created or changed by this container." - type: "integer" - format: "int64" - SizeRootFs: - description: "The total size of all the files in this container." - type: "integer" - format: "int64" - Mounts: - type: "array" - items: - $ref: "#/definitions/MountPoint" - Config: - $ref: "#/definitions/Config" - NetworkSettings: - $ref: "#/definitions/NetworkConfig" - examples: - application/json: - AppArmorProfile: "" - Args: - - "-c" - - "exit 9" - Config: - AttachStderr: true - AttachStdin: false - AttachStdout: true - Cmd: - - "/bin/sh" - - "-c" - - "exit 9" - Domainname: "" - Env: - - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - Hostname: "ba033ac44011" - Image: "ubuntu" - Labels: - com.example.vendor: "Acme" - com.example.license: "GPL" - com.example.version: "1.0" - MacAddress: "" - NetworkDisabled: false - OpenStdin: false - StdinOnce: false - Tty: false - User: "" - Volumes: - /volumes/data: {} - WorkingDir: "" - StopSignal: "SIGTERM" - StopTimeout: 10 - Created: "2015-01-06T15:47:31.485331387Z" - Driver: "devicemapper" - HostConfig: - MaximumIOps: 0 - MaximumIOBps: 0 - BlkioWeight: 0 - BlkioWeightDevice: - - {} - BlkioDeviceReadBps: - - {} - BlkioDeviceWriteBps: - - {} - BlkioDeviceReadIOps: - - {} - BlkioDeviceWriteIOps: - - {} - ContainerIDFile: "" - CpusetCpus: "" - CpusetMems: "" - CpuPercent: 80 - CpuShares: 0 - CpuPeriod: 100000 - CpuRealtimePeriod: 1000000 - CpuRealtimeRuntime: 10000 - Devices: [] - IpcMode: "" - LxcConf: [] - Memory: 0 - MemorySwap: 0 - MemoryReservation: 0 - KernelMemory: 0 - OomKillDisable: false - OomScoreAdj: 500 - NetworkMode: "bridge" - PidMode: "" - PortBindings: {} - Privileged: false - ReadonlyRootfs: false - PublishAllPorts: false - RestartPolicy: - MaximumRetryCount: 2 - Name: "on-failure" - LogConfig: - Type: "json-file" - Sysctls: - net.ipv4.ip_forward: "1" - Ulimits: - - {} - VolumeDriver: "" - ShmSize: 67108864 - HostnamePath: "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname" - HostsPath: "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts" - LogPath: "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log" - Id: "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39" - Image: "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2" - MountLabel: "" - Name: "/boring_euclid" - NetworkSettings: - Bridge: "" - SandboxID: "" - HairpinMode: false - LinkLocalIPv6Address: "" - LinkLocalIPv6PrefixLen: 0 - SandboxKey: "" - SecondaryIPAddresses: null - SecondaryIPv6Addresses: null - EndpointID: "" - Gateway: "" - GlobalIPv6Address: "" - GlobalIPv6PrefixLen: 0 - IPAddress: "" - IPPrefixLen: 0 - IPv6Gateway: "" - MacAddress: "" - Networks: - bridge: - NetworkID: "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812" - EndpointID: "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d" - Gateway: "172.17.0.1" - IPAddress: "172.17.0.2" - IPPrefixLen: 16 - IPv6Gateway: "" - GlobalIPv6Address: "" - GlobalIPv6PrefixLen: 0 - MacAddress: "02:42:ac:12:00:02" - Path: "/bin/sh" - ProcessLabel: "" - ResolvConfPath: "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf" - RestartCount: 1 - State: - Error: "" - ExitCode: 9 - FinishedAt: "2015-01-06T15:47:32.080254511Z" - OOMKilled: false - Dead: false - Paused: false - Pid: 0 - Restarting: false - Running: true - StartedAt: "2015-01-06T15:47:32.072697474Z" - Status: "running" - Mounts: - - Name: "fac362...80535" - Source: "/data" - Destination: "/data" - Driver: "local" - Mode: "ro,Z" - RW: false - Propagation: "" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "size" - in: "query" - type: "boolean" - default: false - description: "Return the size of container as fields `SizeRw` and `SizeRootFs`" - tags: ["Container"] - /containers/{id}/top: - get: - summary: "List processes running inside a container" - description: "On Unix systems, this is done by running the `ps` command. This endpoint is not supported on Windows." - operationId: "ContainerTop" - responses: - 200: - description: "no error" - schema: - type: "object" - properties: - Titles: - description: "The ps column titles" - type: "array" - items: - type: "string" - Processes: - description: "Each process running in the container, where each is process is an array of values corresponding to the titles" - type: "array" - items: - type: "array" - items: - type: "string" - examples: - application/json: - Titles: - - "UID" - - "PID" - - "PPID" - - "C" - - "STIME" - - "TTY" - - "TIME" - - "CMD" - Processes: - - - - "root" - - "13642" - - "882" - - "0" - - "17:03" - - "pts/0" - - "00:00:00" - - "/bin/bash" - - - - "root" - - "13735" - - "13642" - - "0" - - "17:06" - - "pts/0" - - "00:00:00" - - "sleep 10" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "ps_args" - in: "query" - description: "The arguments to pass to `ps`. For example, `aux`" - type: "string" - default: "-ef" - tags: ["Container"] - /containers/{id}/logs: - get: - summary: "Get container logs" - description: | - Get `stdout` and `stderr` logs from a container. - - Note: This endpoint works only for containers with the `json-file` or `journald` logging driver. - operationId: "ContainerLogs" - responses: - 101: - description: "logs returned as a stream" - schema: - type: "string" - format: "binary" - 200: - description: "logs returned as a string in response body" - schema: - type: "string" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "follow" - in: "query" - description: | - Return the logs as a stream. - - This will return a `101` HTTP response with a `Connection: upgrade` header, then hijack the HTTP connection to send raw output. For more information about hijacking and the stream format, [see the documentation for the attach endpoint](#operation/ContainerAttach). - type: "boolean" - default: false - - name: "stdout" - in: "query" - description: "Return logs from `stdout`" - type: "boolean" - default: false - - name: "stderr" - in: "query" - description: "Return logs from `stderr`" - type: "boolean" - default: false - - name: "since" - in: "query" - description: "Only return logs since this time, as a UNIX timestamp" - type: "integer" - default: 0 - - name: "timestamps" - in: "query" - description: "Add timestamps to every log line" - type: "boolean" - default: false - - name: "tail" - in: "query" - description: "Only return this number of log lines from the end of the logs. Specify as an integer or `all` to output all log lines." - type: "string" - default: "all" - tags: ["Container"] - /containers/{id}/changes: - get: - summary: "Get changes on a container’s filesystem" - description: | - Returns which files in a container's filesystem have been added, deleted, or modified. The `Kind` of modification can be one of: - - - `0`: Modified - - `1`: Added - - `2`: Deleted - operationId: "ContainerChanges" - produces: - - "application/json" - responses: - 200: - description: "no error" - schema: - type: "array" - items: - type: "object" - properties: - Path: - description: "Path to file that has changed" - type: "string" - Kind: - description: "Kind of change" - type: "integer" - enum: - - 0 - - 1 - - 2 - examples: - application/json: - - Path: "/dev" - Kind: 0 - - Path: "/dev/kmsg" - Kind: 1 - - Path: "/test" - Kind: 1 - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - tags: ["Container"] - /containers/{id}/export: - get: - summary: "Export a container" - description: "Export the contents of a container as a tarball." - operationId: "ContainerExport" - produces: - - "application/octet-stream" - responses: - 200: - description: "no error" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - tags: ["Container"] - /containers/{id}/stats: - get: - summary: "Get container stats based on resource usage" - description: | - This endpoint returns a live stream of a container’s resource usage statistics. - - The `precpu_stats` is the CPU statistic of last read, which is used for calculating the CPU usage percentage. It is not the same as the `cpu_stats` field. - operationId: "ContainerStats" - produces: - - "application/json" - responses: - 200: - description: "no error" - schema: - type: "object" - examples: - application/json: - read: "2015-01-08T22:57:31.547920715Z" - pids_stats: - current: 3 - networks: - eth0: - rx_bytes: 5338 - rx_dropped: 0 - rx_errors: 0 - rx_packets: 36 - tx_bytes: 648 - tx_dropped: 0 - tx_errors: 0 - tx_packets: 8 - eth5: - rx_bytes: 4641 - rx_dropped: 0 - rx_errors: 0 - rx_packets: 26 - tx_bytes: 690 - tx_dropped: 0 - tx_errors: 0 - tx_packets: 9 - memory_stats: - stats: - total_pgmajfault: 0 - cache: 0 - mapped_file: 0 - total_inactive_file: 0 - pgpgout: 414 - rss: 6537216 - total_mapped_file: 0 - writeback: 0 - unevictable: 0 - pgpgin: 477 - total_unevictable: 0 - pgmajfault: 0 - total_rss: 6537216 - total_rss_huge: 6291456 - total_writeback: 0 - total_inactive_anon: 0 - rss_huge: 6291456 - hierarchical_memory_limit: 67108864 - total_pgfault: 964 - total_active_file: 0 - active_anon: 6537216 - total_active_anon: 6537216 - total_pgpgout: 414 - total_cache: 0 - inactive_anon: 0 - active_file: 0 - pgfault: 964 - inactive_file: 0 - total_pgpgin: 477 - max_usage: 6651904 - usage: 6537216 - failcnt: 0 - limit: 67108864 - blkio_stats: {} - cpu_stats: - cpu_usage: - percpu_usage: - - 8646879 - - 24472255 - - 36438778 - - 30657443 - usage_in_usermode: 50000000 - total_usage: 100215355 - usage_in_kernelmode: 30000000 - system_cpu_usage: 739306590000000 - throttling_data: - periods: 0 - throttled_periods: 0 - throttled_time: 0 - precpu_stats: - cpu_usage: - percpu_usage: - - 8646879 - - 24350896 - - 36438778 - - 30657443 - usage_in_usermode: 50000000 - total_usage: 100093996 - usage_in_kernelmode: 30000000 - system_cpu_usage: 9492140000000 - throttling_data: - periods: 0 - throttled_periods: 0 - throttled_time: 0 - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "stream" - in: "query" - description: "Stream the output. If false, the stats will be output once and then it will disconnect." - type: "boolean" - default: true - tags: ["Container"] - /containers/{id}/resize: - post: - summary: "Resize a container TTY" - description: "Resize the TTY for a container. You must restart the container for the resize to take effect." - operationId: "ContainerResize" - consumes: - - "application/octet-stream" - produces: - - "text/plain" - responses: - 200: - description: "no error" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "cannot resize container" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "h" - in: "query" - description: "Height of the tty session in characters" - type: "integer" - - name: "w" - in: "query" - description: "Width of the tty session in characters" - type: "integer" - tags: ["Container"] - /containers/{id}/start: - post: - summary: "Start a container" - operationId: "ContainerStart" - responses: - 204: - description: "no error" - 304: - description: "container already started" - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "detachKeys" - in: "query" - description: "Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-` where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`." - type: "string" - tags: ["Container"] - /containers/{id}/stop: - post: - summary: "Stop a container" - operationId: "ContainerStop" - responses: - 204: - description: "no error" - 304: - description: "container already stopped" - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "t" - in: "query" - description: "Number of seconds to wait before killing the container" - type: "integer" - tags: ["Container"] - /containers/{id}/restart: - post: - summary: "Restart a container" - operationId: "ContainerRestart" - responses: - 204: - description: "no error" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "t" - in: "query" - description: "Number of seconds to wait before killing the container" - type: "integer" - tags: ["Container"] - /containers/{id}/kill: - post: - summary: "Kill a container" - description: "Send a POSIX signal to a container, defaulting to killing to the container." - operationId: "ContainerKill" - responses: - 204: - description: "no error" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "signal" - in: "query" - description: "Signal to send to the container as an integer or string (e.g. `SIGINT`)" - type: "string" - default: "SIGKILL" - tags: ["Container"] - /containers/{id}/update: - post: - summary: "Update a container" - description: "Change various configuration options of a container without having to recreate it." - operationId: "ContainerUpdate" - consumes: ["application/json"] - produces: ["application/json"] - responses: - 200: - description: "The container has been updated." - schema: - type: "object" - properties: - Warnings: - type: "array" - items: - type: "string" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "update" - in: "body" - required: true - schema: - allOf: - - $ref: "#/definitions/Resources" - - type: "object" - properties: - RestartPolicy: - $ref: "#/definitions/RestartPolicy" - example: - BlkioWeight: 300 - CpuShares: 512 - CpuPeriod: 100000 - CpuQuota: 50000 - CpuRealtimePeriod: 1000000 - CpuRealtimeRuntime: 10000 - CpusetCpus: "0,1" - CpusetMems: "0" - Memory: 314572800 - MemorySwap: 514288000 - MemoryReservation: 209715200 - KernelMemory: 52428800 - RestartPolicy: - MaximumRetryCount: 4 - Name: "on-failure" - tags: ["Container"] - /containers/{id}/rename: - post: - summary: "Rename a container" - operationId: "ContainerRename" - responses: - 204: - description: "no error" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 409: - description: "name already in use" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "name" - in: "query" - required: true - description: "New name for the container" - type: "string" - tags: ["Container"] - /containers/{id}/pause: - post: - summary: "Pause a container" - description: | - Use the cgroups freezer to suspend all processes in a container. - - Traditionally, when suspending a process the `SIGSTOP` signal is used, which is observable by the process being suspended. With the cgroups freezer the process is unaware, and unable to capture, that it is being suspended, and subsequently resumed. - operationId: "ContainerPause" - responses: - 204: - description: "no error" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - tags: ["Container"] - /containers/{id}/unpause: - post: - summary: "Unpause a container" - description: "Resume a container which has been paused." - operationId: "ContainerUnpause" - responses: - 204: - description: "no error" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - tags: ["Container"] - /containers/{id}/attach: - post: - summary: "Attach to a container" - description: | - Attach to a container to read its output or send it input. You can attach to the same container multiple times and you can reattach to containers that have been detached. - - Either the `stream` or `logs` parameter must be `true` for this endpoint to do anything. - - See [the documentation for the `docker attach` command](https://docs.docker.com/engine/reference/commandline/attach/) for more details. - - ### Hijacking - - This endpoint hijacks the HTTP connection to transport `stdin`, `stdout`, and `stderr` on the same socket. - - This is the response from the daemon for an attach request: - - ``` - HTTP/1.1 200 OK - Content-Type: application/vnd.docker.raw-stream - - [STREAM] - ``` - - After the headers and two new lines, the TCP connection can now be used for raw, bidirectional communication between the client and server. - - To hint potential proxies about connection hijacking, the Docker client can also optionally send connection upgrade headers. - - For example, the client sends this request to upgrade the connection: - - ``` - POST /containers/16253994b7c4/attach?stream=1&stdout=1 HTTP/1.1 - Upgrade: tcp - Connection: Upgrade - ``` - - The Docker daemon will respond with a `101 UPGRADED` response, and will similarly follow with the raw stream: - - ``` - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - [STREAM] - ``` - - ### Stream format - - When the TTY setting is disabled in [`POST /containers/create`](#operation/ContainerCreate), the stream over the hijacked connected is multiplexed to separate out `stdout` and `stderr`. The stream consists of a series of frames, each containing a header and a payload. - - The header contains the information which the stream writes (`stdout` or `stderr`). It also contains the size of the associated frame encoded in the last four bytes (`uint32`). - - It is encoded on the first eight bytes like this: - - ```go - header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} - ``` - - `STREAM_TYPE` can be: - - - 0: `stdin` (is written on `stdout`) - - 1: `stdout` - - 2: `stderr` - - `SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of the `uint32` size encoded as big endian. - - Following the header is the payload, which is the specified number of bytes of `STREAM_TYPE`. - - The simplest way to implement this protocol is the following: - - 1. Read 8 bytes. - 2. Choose `stdout` or `stderr` depending on the first byte. - 3. Extract the frame size from the last four bytes. - 4. Read the extracted size and output it on the correct output. - 5. Goto 1. - - ### Stream format when using a TTY - - When the TTY setting is enabled in [`POST /containers/create`](#operation/ContainerCreate), the stream is not multiplexed. The data exchanged over the hijacked connection is simply the raw data from the process PTY and client's `stdin`. - - operationId: "ContainerAttach" - produces: - - "application/vnd.docker.raw-stream" - responses: - 101: - description: "no error, hints proxy about hijacking" - 200: - description: "no error, no upgrade header found" - 400: - description: "bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "detachKeys" - in: "query" - description: "Override the key sequence for detaching a container.Format is a single character `[a-Z]` or `ctrl-` where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`." - type: "string" - - name: "logs" - in: "query" - description: | - Replay previous logs from the container. - - This is useful for attaching to a container that has started and you want to output everything since the container started. - - If `stream` is also enabled, once all the previous output has been returned, it will seamlessly transition into streaming current output. - type: "boolean" - default: false - - name: "stream" - in: "query" - description: "Stream attached streams from the the time the request was made onwards" - type: "boolean" - default: false - - name: "stdin" - in: "query" - description: "Attach to `stdin`" - type: "boolean" - default: false - - name: "stdout" - in: "query" - description: "Attach to `stdout`" - type: "boolean" - default: false - - name: "stderr" - in: "query" - description: "Attach to `stderr`" - type: "boolean" - default: false - tags: ["Container"] - /containers/{id}/attach/ws: - get: - summary: "Attach to a container via a websocket" - operationId: "ContainerAttachWebsocket" - responses: - 101: - description: "no error, hints proxy about hijacking" - 200: - description: "no error, no upgrade header found" - 400: - description: "bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "detachKeys" - in: "query" - description: "Override the key sequence for detaching a container.Format is a single character `[a-Z]` or `ctrl-` where `` is one of: `a-z`, `@`, `^`, `[`, `,`, or `_`." - type: "string" - - name: "logs" - in: "query" - description: "Return logs" - type: "boolean" - default: false - - name: "stream" - in: "query" - description: "Return stream" - type: "boolean" - default: false - - name: "stdin" - in: "query" - description: "Attach to `stdin`" - type: "boolean" - default: false - - name: "stdout" - in: "query" - description: "Attach to `stdout`" - type: "boolean" - default: false - - name: "stderr" - in: "query" - description: "Attach to `stderr`" - type: "boolean" - default: false - tags: ["Container"] - /containers/{id}/wait: - post: - summary: "Wait for a container" - description: "Block until a container stops, then returns the exit code." - operationId: "ContainerWait" - produces: ["application/json"] - responses: - 200: - description: "The container has exit." - schema: - type: "object" - required: [StatusCode] - properties: - StatusCode: - description: "Exit code of the container" - type: "integer" - x-nullable: false - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - tags: ["Container"] - /containers/{id}: - delete: - summary: "Remove a container" - operationId: "ContainerDelete" - responses: - 204: - description: "no error" - 400: - description: "bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "v" - in: "query" - description: "Remove the volumes associated with the container." - type: "boolean" - default: false - - name: "force" - in: "query" - description: "If the container is running, kill it before removing it." - type: "boolean" - default: false - tags: ["Container"] - /containers/{id}/archive: - head: - summary: "Get information about files in a container" - description: "A response header `X-Docker-Container-Path-Stat` is return containing a base64 - encoded JSON object with some filesystem header information about the path." - operationId: "ContainerArchiveHead" - responses: - 200: - description: "no error" - headers: - X-Docker-Container-Path-Stat: - type: "string" - description: "TODO" - 400: - description: "Bad parameter" - schema: - allOf: - - $ref: "#/definitions/ErrorResponse" - - type: "object" - properties: - message: - description: "The error message. Either \"must specify path parameter\" (path cannot be empty) or \"not a directory\" (path was asserted to be a directory but exists as a file)." - type: "string" - x-nullable: false - 404: - description: "Container or path does not exist" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "path" - in: "query" - required: true - description: "Resource in the container’s filesystem to archive." - type: "string" - tags: ["Container"] - get: - summary: "Get an archive of a filesystem resource in a container" - description: "Get an tar archive of a resource in the filesystem of container id." - operationId: "ContainerGetArchive" - produces: - - "application/x-tar" - responses: - 200: - description: "no error" - 400: - description: "Bad parameter" - schema: - allOf: - - $ref: "#/definitions/ErrorResponse" - - type: "object" - properties: - message: - description: "The error message. Either \"must specify path parameter\" (path cannot be empty) or \"not a directory\" (path was asserted to be a directory but exists as a file)." - type: "string" - x-nullable: false - 404: - description: "Container or path does not exist" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "path" - in: "query" - required: true - description: "Resource in the container’s filesystem to archive." - type: "string" - tags: ["Container"] - put: - summary: "Extract an archive of files or folders to a directory in a container" - description: "Upload a tar archive to be extracted to a path in the filesystem of container id." - operationId: "ContainerPutArchive" - consumes: - - "application/x-tar" - - "application/octet-stream" - responses: - 200: - description: "The content was extracted successfully" - 400: - description: "Bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 403: - description: "Permission denied, the volume or container rootfs is marked as read-only." - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "No such container or path does not exist inside the container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "path" - in: "query" - required: true - description: "Path to a directory in the container to extract the archive’s contents into. " - type: "string" - - name: "noOverwriteDirNonDir" - in: "query" - description: "If “1”, “true”, or “True” then it will be an error if unpacking the given content would cause an existing directory to be replaced with a non-directory and vice versa." - type: "string" - - name: "inputStream" - in: "body" - required: true - description: "The input stream must be a tar archive compressed with one of the following algorithms: identity (no compression), gzip, bzip2, xz." - schema: - type: "string" - tags: ["Container"] - /containers/prune: - post: - summary: "Delete stopped containers" - produces: - - "application/json" - operationId: "ContainerPrune" - parameters: - - name: "filters" - in: "query" - description: | - Filters to process on the prune list, encoded as JSON (a `map[string][]string`). - - Available filters: - type: "string" - responses: - 200: - description: "No error" - schema: - type: "object" - properties: - ContainersDeleted: - description: "Container IDs that were deleted" - type: "array" - items: - type: "string" - SpaceReclaimed: - description: "Disk space reclaimed in bytes" - type: "integer" - format: "int64" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Container"] - /images/json: - get: - summary: "List Images" - description: "Returns a list of images on the server. Note that it uses a different, smaller representation of an image than inspecting a single image." - operationId: "ImageList" - produces: - - "application/json" - responses: - 200: - description: "Summary image data for the images matching the query" - schema: - type: "array" - items: - $ref: "#/definitions/ImageSummary" - examples: - application/json: - - Id: "sha256:e216a057b1cb1efc11f8a268f37ef62083e70b1b38323ba252e25ac88904a7e8" - ParentId: "" - RepoTags: - - "ubuntu:12.04" - - "ubuntu:precise" - RepoDigests: - - "ubuntu@sha256:992069aee4016783df6345315302fa59681aae51a8eeb2f889dea59290f21787" - Created: 1474925151 - Size: 103579269 - VirtualSize: 103579269 - SharedSize: 0 - Labels: {} - Containers: 2 - - Id: "sha256:3e314f95dcace0f5e4fd37b10862fe8398e3c60ed36600bc0ca5fda78b087175" - ParentId: "" - RepoTags: - - "ubuntu:12.10" - - "ubuntu:quantal" - RepoDigests: - - "ubuntu@sha256:002fba3e3255af10be97ea26e476692a7ebed0bb074a9ab960b2e7a1526b15d7" - - "ubuntu@sha256:68ea0200f0b90df725d99d823905b04cf844f6039ef60c60bf3e019915017bd3" - Created: 1403128455 - Size: 172064416 - VirtualSize: 172064416 - SharedSize: 0 - Labels: {} - Containers: 5 - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "all" - in: "query" - description: "Show all images. Only images from a final layer (no children) are shown by default." - type: "boolean" - default: false - - name: "filters" - in: "query" - description: | - A JSON encoded value of the filters (a `map[string][]string`) to process on the images list. - - Available filters: - - `dangling=true` - - `label=key` or `label="key=value"` of an image label - - `before`=(`[:]`, `` or ``) - - `since`=(`[:]`, `` or ``) - - `reference`=(`[:]`) - type: "string" - - name: "digests" - in: "query" - description: "Show digest information as a `RepoDigests` field on each image." - type: "boolean" - default: false - tags: ["Image"] - /build: - post: - summary: "Build an image" - description: | - Build an image from a tar archive with a `Dockerfile` in it. - - The `Dockerfile` specifies how the image is built from the tar archive. It is typically in the archive's root, but can be at a different path or have a different name by specifying the `dockerfile` parameter. [See the `Dockerfile` reference for more information](https://docs.docker.com/engine/reference/builder/). - - The Docker daemon performs a preliminary validation of the `Dockerfile` before starting the build, and returns an error if the syntax is incorrect. After that, each instruction is run one-by-one until the ID of the new image is output. - - The build is canceled if the client drops the connection by quitting or being killed. - operationId: "ImageBuild" - consumes: - - "application/octet-stream" - produces: - - "application/json" - parameters: - - name: "inputStream" - in: "body" - description: "A tar archive compressed with one of the following algorithms: identity (no compression), gzip, bzip2, xz." - schema: - type: "string" - format: "binary" - - name: "dockerfile" - in: "query" - description: "Path within the build context to the `Dockerfile`. This is ignored if `remote` is specified and points to an external `Dockerfile`." - type: "string" - default: "Dockerfile" - - name: "t" - in: "query" - description: "A name and optional tag to apply to the image in the `name:tag` format. If you omit the tag the default `latest` value is assumed. You can provide several `t` parameters." - type: "string" - - name: "remote" - in: "query" - description: "A Git repository URI or HTTP/HTTPS context URI. If the URI points to a single text file, the file’s contents are placed into a file called `Dockerfile` and the image is built from that file. If the URI points to a tarball, the file is downloaded by the daemon and the contents therein used as the context for the build. If the URI points to a tarball and the `dockerfile` parameter is also specified, there must be a file with the corresponding path inside the tarball." - type: "string" - - name: "q" - in: "query" - description: "Suppress verbose build output." - type: "boolean" - default: false - - name: "nocache" - in: "query" - description: "Do not use the cache when building the image." - type: "boolean" - default: false - - name: "cachefrom" - in: "query" - description: "JSON array of images used for build cache resolution." - type: "string" - - name: "pull" - in: "query" - description: "Attempt to pull the image even if an older image exists locally." - type: "string" - - name: "rm" - in: "query" - description: "Remove intermediate containers after a successful build." - type: "boolean" - default: true - - name: "forcerm" - in: "query" - description: "Always remove intermediate containers, even upon failure." - type: "boolean" - default: false - - name: "memory" - in: "query" - description: "Set memory limit for build." - type: "integer" - - name: "memswap" - in: "query" - description: "Total memory (memory + swap). Set as `-1` to disable swap." - type: "integer" - - name: "cpushares" - in: "query" - description: "CPU shares (relative weight)." - type: "integer" - - name: "cpusetcpus" - in: "query" - description: "CPUs in which to allow execution (e.g., `0-3`, `0,1`)." - type: "string" - - name: "cpuperiod" - in: "query" - description: "The length of a CPU period in microseconds." - type: "integer" - - name: "cpuquota" - in: "query" - description: "Microseconds of CPU time that the container can get in a CPU period." - type: "integer" - - name: "buildargs" - in: "query" - description: "JSON map of string pairs for build-time variables. Users pass these values at build-time. Docker uses the buildargs as the environment context for commands run via the `Dockerfile` RUN instruction, or for variable expansion in other `Dockerfile` instructions. This is not meant for passing secret values. [Read more about the buildargs instruction.](https://docs.docker.com/engine/reference/builder/#arg)" - type: "integer" - - name: "shmsize" - in: "query" - description: "Size of `/dev/shm` in bytes. The size must be greater than 0. If omitted the system uses 64MB." - type: "integer" - - name: "squash" - in: "query" - description: "Squash the resulting images layers into a single layer. *(Experimental release only.)*" - type: "boolean" - - name: "labels" - in: "query" - description: "Arbitrary key/value labels to set on the image, as a JSON map of string pairs." - type: "string" - - name: "networkmode" - in: "query" - description: "Sets the networking mode for the run commands during - build. Supported standard values are: `bridge`, `host`, `none`, and - `container:`. Any other value is taken as a custom network's - name to which this container should connect to." - type: "string" - - name: "Content-type" - in: "header" - type: "string" - enum: - - "application/tar" - default: "application/tar" - - name: "X-Registry-Config" - in: "header" - description: | - This is a base64-encoded JSON object with auth configurations for multiple registries that a build may refer to. - - The key is a registry URL, and the value is an auth configuration object, [as described in the authentication section](#section/Authentication). For example: - - ``` - { - "docker.example.com": { - "username": "janedoe", - "password": "hunter2" - }, - "https://index.docker.io/v1/": { - "username": "mobydock", - "password": "conta1n3rize14" - } - } - ``` - - Only the registry domain name (and port if not the default 443) are required. However, for legacy reasons, the Docker Hub registry must be specified with both a `https://` prefix and a `/v1/` suffix even though Docker will prefer to use the v2 registry API. - type: "string" - responses: - 200: - description: "no error" - 400: - description: "Bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Image"] - /images/create: - post: - summary: "Create an image" - description: "Create an image by either pulling it from a registry or importing it." - operationId: "ImageCreate" - consumes: - - "text/plain" - - "application/octet-stream" - produces: - - "application/json" - responses: - 200: - description: "no error" - 404: - description: "repository does not exist or no read access" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "fromImage" - in: "query" - description: "Name of the image to pull. The name may include a tag or digest. This parameter may only be used when pulling an image. The pull is cancelled if the HTTP connection is closed." - type: "string" - - name: "fromSrc" - in: "query" - description: "Source to import. The value may be a URL from which the image can be retrieved or `-` to read the image from the request body. This parameter may only be used when importing an image." - type: "string" - - name: "repo" - in: "query" - description: "Repository name given to an image when it is imported. The repo may include a tag. This parameter may only be used when importing an image." - type: "string" - - name: "tag" - in: "query" - description: "Tag or digest. If empty when pulling an image, this causes all tags for the given image to be pulled." - type: "string" - - name: "inputImage" - in: "body" - description: "Image content if the value `-` has been specified in fromSrc query parameter" - schema: - type: "string" - required: false - - name: "X-Registry-Auth" - in: "header" - description: "A base64-encoded auth configuration. [See the authentication section for details.](#section/Authentication)" - type: "string" - tags: ["Image"] - /images/{name}/json: - get: - summary: "Inspect an image" - description: "Return low-level information about an image." - operationId: "ImageInspect" - produces: - - "application/json" - responses: - 200: - description: "No error" - schema: - $ref: "#/definitions/Image" - examples: - application/json: - Id: "sha256:85f05633ddc1c50679be2b16a0479ab6f7637f8884e0cfe0f4d20e1ebb3d6e7c" - Container: "cb91e48a60d01f1e27028b4fc6819f4f290b3cf12496c8176ec714d0d390984a" - Comment: "" - Os: "linux" - Architecture: "amd64" - Parent: "sha256:91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c" - ContainerConfig: - Tty: false - Hostname: "e611e15f9c9d" - Domainname: "" - AttachStdout: false - PublishService: "" - AttachStdin: false - OpenStdin: false - StdinOnce: false - NetworkDisabled: false - OnBuild: [] - Image: "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c" - User: "" - WorkingDir: "" - MacAddress: "" - AttachStderr: false - Labels: - com.example.license: "GPL" - com.example.version: "1.0" - com.example.vendor: "Acme" - Env: - - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - Cmd: - - "/bin/sh" - - "-c" - - "#(nop) LABEL com.example.vendor=Acme com.example.license=GPL com.example.version=1.0" - DockerVersion: "1.9.0-dev" - VirtualSize: 188359297 - Size: 0 - Author: "" - Created: "2015-09-10T08:30:53.26995814Z" - GraphDriver: - Name: "aufs" - RepoDigests: - - "localhost:5000/test/busybox/example@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - RepoTags: - - "example:1.0" - - "example:latest" - - "example:stable" - Config: - Image: "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c" - NetworkDisabled: false - OnBuild: [] - StdinOnce: false - PublishService: "" - AttachStdin: false - OpenStdin: false - Domainname: "" - AttachStdout: false - Tty: false - Hostname: "e611e15f9c9d" - Cmd: - - "/bin/bash" - Env: - - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - Labels: - com.example.vendor: "Acme" - com.example.version: "1.0" - com.example.license: "GPL" - MacAddress: "" - AttachStderr: false - WorkingDir: "" - User: "" - RootFS: - Type: "layers" - Layers: - - "sha256:1834950e52ce4d5a88a1bbd131c537f4d0e56d10ff0dd69e66be3b7dfa9df7e6" - - "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef" - 404: - description: "No such image" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such image: someimage (tag: latest)" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "Image name or id" - type: "string" - required: true - tags: ["Image"] - /images/{name}/history: - get: - summary: "Get the history of an image" - description: "Return parent layers of an image." - operationId: "ImageHistory" - produces: - - "application/json" - responses: - 200: - description: "No error" - schema: - type: "array" - items: - type: "object" - properties: - Id: - type: "string" - Created: - type: "integer" - format: "int64" - CreatedBy: - type: "string" - Tags: - type: "array" - items: - type: "string" - Size: - type: "integer" - format: "int64" - Comment: - type: "string" - examples: - application/json: - - Id: "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710" - Created: 1398108230 - CreatedBy: "/bin/sh -c #(nop) ADD file:eb15dbd63394e063b805a3c32ca7bf0266ef64676d5a6fab4801f2e81e2a5148 in /" - Tags: - - "ubuntu:lucid" - - "ubuntu:10.04" - Size: 182964289 - Comment: "" - - Id: "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8" - Created: 1398108222 - CreatedBy: "/bin/sh -c #(nop) MAINTAINER Tianon Gravi - mkimage-debootstrap.sh -i iproute,iputils-ping,ubuntu-minimal -t lucid.tar.xz lucid http://archive.ubuntu.com/ubuntu/" - Tags: [] - Size: 0 - Comment: "" - - Id: "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158" - Created: 1371157430 - CreatedBy: "" - Tags: - - "scratch12:latest" - - "scratch:latest" - Size: 0 - Comment: "Imported from -" - 404: - description: "No such image" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "Image name or ID" - type: "string" - required: true - tags: ["Image"] - /images/{name}/push: - post: - summary: "Push an image" - description: | - Push an image to a registry. - - If you wish to push an image on to a private registry, that image must already have a tag which references the registry. For example, `registry.example.com/myimage:latest`. - - The push is cancelled if the HTTP connection is closed. - operationId: "ImagePush" - consumes: - - "application/octet-stream" - responses: - 200: - description: "No error" - 404: - description: "No such image" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "Image name or ID." - type: "string" - required: true - - name: "tag" - in: "query" - description: "The tag to associate with the image on the registry." - type: "string" - - name: "X-Registry-Auth" - in: "header" - description: "A base64-encoded auth configuration. [See the authentication section for details.](#section/Authentication)" - type: "string" - required: true - tags: ["Image"] - /images/{name}/tag: - post: - summary: "Tag an image" - description: "Tag an image so that it becomes part of a repository." - operationId: "ImageTag" - responses: - 201: - description: "No error" - 400: - description: "Bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "No such image" - schema: - $ref: "#/definitions/ErrorResponse" - 409: - description: "Conflict" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "Image name or ID to tag." - type: "string" - required: true - - name: "repo" - in: "query" - description: "The repository to tag in. For example, `someuser/someimage`." - type: "string" - - name: "tag" - in: "query" - description: "The name of the new tag." - type: "string" - tags: ["Image"] - /images/{name}: - delete: - summary: "Remove an image" - description: | - Remove an image, along with any untagged parent images that were referenced by that image. - - Images can't be removed if they have descendant images, are being used by a running container or are being used by a build. - operationId: "ImageDelete" - produces: - - "application/json" - responses: - 200: - description: "No error" - schema: - type: "array" - items: - $ref: "#/definitions/ImageDeleteResponse" - examples: - application/json: - - Untagged: "3e2f21a89f" - - Deleted: "3e2f21a89f" - - Deleted: "53b4f83ac9" - 404: - description: "No such image" - schema: - $ref: "#/definitions/ErrorResponse" - 409: - description: "Conflict" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "Image name or ID" - type: "string" - required: true - - name: "force" - in: "query" - description: "Remove the image even if it is being used by stopped containers or has other tags" - type: "boolean" - default: false - - name: "noprune" - in: "query" - description: "Do not delete untagged parent images" - type: "boolean" - default: false - tags: ["Image"] - /images/search: - get: - summary: "Search images" - description: "Search for an image on Docker Hub." - operationId: "ImageSearch" - produces: - - "application/json" - responses: - 200: - description: "No error" - schema: - type: "array" - items: - type: "object" - properties: - description: - type: "string" - is_official: - type: "boolean" - is_automated: - type: "boolean" - name: - type: "string" - star_count: - type: "integer" - examples: - application/json: - - description: "" - is_official: false - is_automated: false - name: "wma55/u1210sshd" - star_count: 0 - - description: "" - is_official: false - is_automated: false - name: "jdswinbank/sshd" - star_count: 0 - - description: "" - is_official: false - is_automated: false - name: "vgauthier/sshd" - star_count: 0 - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "term" - in: "query" - description: "Term to search" - type: "string" - required: true - - name: "limit" - in: "query" - description: "Maximum number of results to return" - type: "integer" - - name: "filters" - in: "query" - description: | - A JSON encoded value of the filters (a `map[string][]string`) to process on the images list. Available filters: - - - `stars=` - - `is-automated=(true|false)` - - `is-official=(true|false)` - type: "string" - tags: ["Image"] - /images/prune: - post: - summary: "Delete unused images" - produces: - - "application/json" - operationId: "ImagePrune" - parameters: - - name: "filters" - in: "query" - description: | - Filters to process on the prune list, encoded as JSON (a `map[string][]string`). - - Available filters: - - `dangling=` When set to `true` (or `1`), prune only - unused *and* untagged images. When set to `false` - (or `0`), all unused images are pruned. - type: "string" - responses: - 200: - description: "No error" - schema: - type: "object" - properties: - ImagesDeleted: - description: "Images that were deleted" - type: "array" - items: - $ref: "#/definitions/ImageDeleteResponse" - SpaceReclaimed: - description: "Disk space reclaimed in bytes" - type: "integer" - format: "int64" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Image"] - /auth: - post: - summary: "Check auth configuration" - description: "Validate credentials for a registry and, if available, get an identity token for accessing the registry without password." - operationId: "SystemAuth" - consumes: ["application/json"] - produces: ["application/json"] - responses: - 200: - description: "An identity token was generated successfully." - schema: - type: "object" - required: [Status] - properties: - Status: - description: "The status of the authentication" - type: "string" - x-nullable: false - IdentityToken: - description: "An opaque token used to authenticate a user after a successful login" - type: "string" - x-nullable: false - examples: - application/json: - Status: "Login Succeeded" - IdentityToken: "9cbaf023786cd7..." - 204: - description: "No error" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "authConfig" - in: "body" - description: "Authentication to check" - schema: - $ref: "#/definitions/AuthConfig" - tags: ["System"] - /info: - get: - summary: "Get system information" - operationId: "SystemInfo" - produces: - - "application/json" - responses: - 200: - description: "No error" - schema: - type: "object" - properties: - Architecture: - type: "string" - Containers: - type: "integer" - ContainersRunning: - type: "integer" - ContainersStopped: - type: "integer" - ContainersPaused: - type: "integer" - CpuCfsPeriod: - type: "boolean" - CpuCfsQuota: - type: "boolean" - Debug: - type: "boolean" - DiscoveryBackend: - type: "string" - DockerRootDir: - type: "string" - Driver: - type: "string" - DriverStatus: - type: "array" - items: - type: "array" - items: - type: "string" - SystemStatus: - type: "array" - items: - type: "array" - items: - type: "string" - Plugins: - type: "object" - properties: - Volume: - type: "array" - items: - type: "string" - Network: - type: "array" - items: - type: "string" - ExperimentalBuild: - type: "boolean" - HttpProxy: - type: "string" - HttpsProxy: - type: "string" - ID: - type: "string" - IPv4Forwarding: - type: "boolean" - Images: - type: "integer" - IndexServerAddress: - type: "string" - InitPath: - type: "string" - InitSha1: - type: "string" - KernelVersion: - type: "string" - Labels: - type: "array" - items: - type: "string" - MemTotal: - type: "integer" - MemoryLimit: - type: "boolean" - NCPU: - type: "integer" - NEventsListener: - type: "integer" - NFd: - type: "integer" - NGoroutines: - type: "integer" - Name: - type: "string" - NoProxy: - type: "string" - OomKillDisable: - type: "boolean" - OSType: - type: "string" - OomScoreAdj: - type: "integer" - OperatingSystem: - type: "string" - RegistryConfig: - type: "object" - properties: - IndexConfigs: - type: "object" - additionalProperties: - type: "object" - properties: - Mirrors: - type: "array" - items: - type: "string" - Name: - type: "string" - Official: - type: "boolean" - Secure: - type: "boolean" - InsecureRegistryCIDRs: - type: "array" - items: - type: "string" - SwapLimit: - type: "boolean" - SystemTime: - type: "string" - ServerVersion: - type: "string" - examples: - application/json: - Architecture: "x86_64" - ClusterStore: "etcd://localhost:2379" - CgroupDriver: "cgroupfs" - Containers: 11 - ContainersRunning: 7 - ContainersStopped: 3 - ContainersPaused: 1 - CpuCfsPeriod: true - CpuCfsQuota: true - Debug: false - DockerRootDir: "/var/lib/docker" - Driver: "btrfs" - DriverStatus: - - - - "" - ExperimentalBuild: false - HttpProxy: "http://test:test@localhost:8080" - HttpsProxy: "https://test:test@localhost:8080" - ID: "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS" - IPv4Forwarding: true - Images: 16 - IndexServerAddress: "https://index.docker.io/v1/" - InitPath: "/usr/bin/docker" - InitSha1: "" - KernelMemory: true - KernelVersion: "3.12.0-1-amd64" - Labels: - - "storage=ssd" - MemTotal: 2099236864 - MemoryLimit: true - NCPU: 1 - NEventsListener: 0 - NFd: 11 - NGoroutines: 21 - Name: "prod-server-42" - NoProxy: "9.81.1.160" - OomKillDisable: true - OSType: "linux" - OperatingSystem: "Boot2Docker" - Plugins: - Volume: - - "local" - Network: - - "null" - - "host" - - "bridge" - RegistryConfig: - IndexConfigs: - docker.io: - Name: "docker.io" - Official: true - Secure: true - InsecureRegistryCIDRs: - - "127.0.0.0/8" - SecurityOptions: - - Key: "Name" - Value: "seccomp" - - Key: "Profile" - Value: "default" - - Key: "Name" - Value: "apparmor" - - Key: "Name" - Value: "selinux" - - Key: "Name" - Value: "userns" - ServerVersion: "1.9.0" - SwapLimit: false - SystemStatus: - - - - "State" - - "Healthy" - SystemTime: "2015-03-10T11:11:23.730591467-07:00" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["System"] - /version: - get: - summary: "Get version" - description: "Returns the version of Docker that is running and various information about the system that Docker is running on." - operationId: "SystemVersion" - produces: - - "application/json" - responses: - 200: - description: "no error" - schema: - type: "object" - properties: - Version: - type: "string" - ApiVersion: - type: "string" - MinAPIVersion: - type: "string" - GitCommit: - type: "string" - GoVersion: - type: "string" - Os: - type: "string" - Arch: - type: "string" - KernelVersion: - type: "string" - Experimental: - type: "boolean" - BuildTime: - type: "string" - examples: - application/json: - Version: "1.13.0" - Os: "linux" - KernelVersion: "3.19.0-23-generic" - GoVersion: "go1.6.3" - GitCommit: "deadbee" - Arch: "amd64" - ApiVersion: "1.25" - MinAPIVersion: "1.12" - BuildTime: "2016-06-14T07:09:13.444803460+00:00" - Experimental: true - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["System"] - /_ping: - get: - summary: "Ping" - description: "This is a dummy endpoint you can use to test if the server is accessible." - operationId: "SystemPing" - produces: - - "text/plain" - responses: - 200: - description: "no error" - schema: - type: "string" - example: "OK" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["System"] - /commit: - post: - summary: "Create a new image from a container" - operationId: "ImageCommit" - consumes: - - "application/json" - produces: - - "application/json" - responses: - 201: - description: "no error" - schema: - $ref: "#/definitions/IdResponse" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "containerConfig" - in: "body" - description: "The container configuration" - schema: - $ref: "#/definitions/Config" - - name: "container" - in: "query" - description: "The ID or name of the container to commit" - type: "string" - - name: "repo" - in: "query" - description: "Repository name for the created image" - type: "string" - - name: "tag" - in: "query" - description: "Tag name for the create image" - type: "string" - - name: "comment" - in: "query" - description: "Commit message" - type: "string" - - name: "author" - in: "query" - description: "Author of the image (e.g., `John Hannibal Smith `)" - type: "string" - - name: "pause" - in: "query" - description: "Whether to pause the container before committing" - type: "boolean" - default: true - - name: "changes" - in: "query" - description: "`Dockerfile` instructions to apply while committing" - type: "string" - tags: ["Image"] - /events: - get: - summary: "Monitor events" - description: | - Stream real-time events from the server. - - Various objects within Docker report events when something happens to them. - - Containers report these events: `attach, commit, copy, create, destroy, detach, die, exec_create, exec_detach, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update` - - Images report these events: `delete, import, load, pull, push, save, tag, untag` - - Volumes report these events: `create, mount, unmount, destroy` - - Networks report these events: `create, connect, disconnect, destroy` - - The Docker daemon reports these events: `reload` - - operationId: "SystemEvents" - produces: - - "application/json" - responses: - 200: - description: "no error" - schema: - type: "object" - properties: - Type: - description: "The type of object emitting the event" - type: "string" - Action: - description: "The type of event" - type: "string" - Actor: - type: "object" - properties: - ID: - description: "The ID of the object emitting the event" - type: "string" - Attributes: - description: "Various key/value attributes of the object, depending on its type" - type: "object" - additionalProperties: - type: "string" - time: - description: "Timestamp of event" - type: "integer" - timeNano: - description: "Timestamp of event, with nanosecond accuracy" - type: "integer" - format: "int64" - examples: - application/json: - Type: "container" - Action: "create" - Actor: - ID: "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743" - Attributes: - com.example.some-label: "some-label-value" - image: "alpine" - name: "my-container" - time: 1461943101 - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "since" - in: "query" - description: "Show events created since this timestamp then stream new events." - type: "string" - - name: "until" - in: "query" - description: "Show events created until this timestamp then stop streaming." - type: "string" - - name: "filters" - in: "query" - description: | - A JSON encoded value of filters (a `map[string][]string`) to process on the event list. Available filters: - - - `container=` container name or ID - - `event=` event type - - `image=` image name or ID - - `label=` image or container label - - `type=` object to filter by, one of `container`, `image`, `volume`, `network`, or `daemon` - - `volume=` volume name or ID - - `network=` network name or ID - - `daemon=` daemon name or ID - type: "string" - tags: ["System"] - /system/df: - get: - summary: "Get data usage information" - operationId: "SystemDataUsage" - responses: - 200: - description: "no error" - schema: - type: "object" - properties: - LayersSize: - type: "integer" - format: "int64" - Images: - type: "array" - items: - $ref: "#/definitions/ImageSummary" - Containers: - type: "array" - items: - $ref: "#/definitions/ContainerSummary" - Volumes: - type: "array" - items: - $ref: "#/definitions/Volume" - example: - LayersSize: 1092588 - Images: - - - Id: "sha256:2b8fd9751c4c0f5dd266fcae00707e67a2545ef34f9a29354585f93dac906749" - ParentId: "" - RepoTags: - - "busybox:latest" - RepoDigests: - - "busybox@sha256:a59906e33509d14c036c8678d687bd4eec81ed7c4b8ce907b888c607f6a1e0e6" - Created: 1466724217 - Size: 1092588 - SharedSize: 0 - VirtualSize: 1092588 - Labels: {} - Containers: 1 - Containers: - - - Id: "e575172ed11dc01bfce087fb27bee502db149e1a0fad7c296ad300bbff178148" - Names: - - "/top" - Image: "busybox" - ImageID: "sha256:2b8fd9751c4c0f5dd266fcae00707e67a2545ef34f9a29354585f93dac906749" - Command: "top" - Created: 1472592424 - Ports: [] - SizeRootFs: 1092588 - Labels: {} - State: "exited" - Status: "Exited (0) 56 minutes ago" - HostConfig: - NetworkMode: "default" - NetworkSettings: - Networks: - bridge: - IPAMConfig: null - Links: null - Aliases: null - NetworkID: "d687bc59335f0e5c9ee8193e5612e8aee000c8c62ea170cfb99c098f95899d92" - EndpointID: "8ed5115aeaad9abb174f68dcf135b49f11daf597678315231a32ca28441dec6a" - Gateway: "172.18.0.1" - IPAddress: "172.18.0.2" - IPPrefixLen: 16 - IPv6Gateway: "" - GlobalIPv6Address: "" - GlobalIPv6PrefixLen: 0 - MacAddress: "02:42:ac:12:00:02" - Mounts: [] - Volumes: - - - Name: "my-volume" - Driver: "local" - Mountpoint: "" - Labels: null - Scope: "" - Options: null - UsageData: - Size: 0 - RefCount: 0 - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["System"] - /images/{name}/get: - get: - summary: "Export an image" - description: | - Get a tarball containing all images and metadata for a repository. - - If `name` is a specific name and tag (e.g. `ubuntu:latest`), then only that image (and its parents) are returned. If `name` is an image ID, similarly only that image (and its parents) are returned, but with the exclusion of the `repositories` file in the tarball, as there were no image names referenced. - - ### Image tarball format - - An image tarball contains one directory per image layer (named using its long ID), each containing these files: - - - `VERSION`: currently `1.0` - the file format version - - `json`: detailed layer information, similar to `docker inspect layer_id` - - `layer.tar`: A tarfile containing the filesystem changes in this layer - - The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories for storing attribute changes and deletions. - - If the tarball defines a repository, the tarball should also include a `repositories` file at the root that contains a list of repository and tag names mapped to layer IDs. - - ```json - { - "hello-world": { - "latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1" - } - } - ``` - operationId: "ImageGet" - produces: - - "application/x-tar" - responses: - 200: - description: "no error" - schema: - type: "string" - format: "binary" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "Image name or ID" - type: "string" - required: true - tags: ["Image"] - /images/get: - get: - summary: "Export several images" - description: | - Get a tarball containing all images and metadata for several image repositories. - - For each value of the `names` parameter: if it is a specific name and tag (e.g. `ubuntu:latest`), then only that image (and its parents) are returned; if it is an image ID, similarly only that image (and its parents) are returned and there would be no names referenced in the 'repositories' file for this image ID. - - For details on the format, see [the export image endpoint](#operation/ImageGet). - operationId: "ImageGetAll" - produces: - - "application/x-tar" - responses: - 200: - description: "no error" - schema: - type: "string" - format: "binary" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "names" - in: "query" - description: "Image names to filter by" - type: "array" - items: - type: "string" - tags: ["Image"] - /images/load: - post: - summary: "Import images" - description: | - Load a set of images and tags into a repository. - - For details on the format, see [the export image endpoint](#operation/ImageGet). - operationId: "ImageLoad" - consumes: - - "application/x-tar" - produces: - - "application/json" - responses: - 200: - description: "no error" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "imagesTarball" - in: "body" - description: "Tar archive containing images" - schema: - type: "string" - format: "binary" - - name: "quiet" - in: "query" - description: "Suppress progress details during load." - type: "boolean" - default: false - tags: ["Image"] - /containers/{id}/exec: - post: - summary: "Create an exec instance" - description: "Run a command inside a running container." - operationId: "ContainerExec" - consumes: - - "application/json" - produces: - - "application/json" - responses: - 201: - description: "no error" - schema: - $ref: "#/definitions/IdResponse" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 409: - description: "container is paused" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "execConfig" - in: "body" - description: "Exec configuration" - schema: - type: "object" - properties: - AttachStdin: - type: "boolean" - description: "Attach to `stdin` of the exec command." - AttachStdout: - type: "boolean" - description: "Attach to `stdout` of the exec command." - AttachStderr: - type: "boolean" - description: "Attach to `stderr` of the exec command." - DetachKeys: - type: "string" - description: "Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-` where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`." - Tty: - type: "boolean" - description: "Allocate a pseudo-TTY." - Env: - description: "A list of environment variables in the form `[\"VAR=value\", ...]`." - type: "array" - items: - type: "string" - Cmd: - type: "array" - description: "Command to run, as a string or array of strings." - items: - type: "string" - Privileged: - type: "boolean" - description: "Runs the exec process with extended privileges." - default: false - User: - type: "string" - description: "The user, and optionally, group to run the exec process inside the container. Format is one of: `user`, `user:group`, `uid`, or `uid:gid`." - example: - AttachStdin: false - AttachStdout: true - AttachStderr: true - DetachKeys: "ctrl-p,ctrl-q" - Tty: false - Cmd: - - "date" - Env: - - "FOO=bar" - - "BAZ=quux" - required: true - - name: "id" - in: "path" - description: "ID or name of container" - type: "string" - required: true - tags: ["Exec"] - /exec/{id}/start: - post: - summary: "Start an exec instance" - description: "Starts a previously set up exec instance. If detach is true, this endpoint returns immediately after starting the command. Otherwise, it sets up an interactive session with the command." - operationId: "ExecStart" - consumes: - - "application/json" - produces: - - "application/vnd.docker.raw-stream" - responses: - 200: - description: "No error" - 404: - description: "No such exec instance" - schema: - $ref: "#/definitions/ErrorResponse" - 409: - description: "Container is stopped or paused" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "execStartConfig" - in: "body" - schema: - type: "object" - properties: - Detach: - type: "boolean" - description: "Detach from the command." - Tty: - type: "boolean" - description: "Allocate a pseudo-TTY." - example: - Detach: false - Tty: false - - name: "id" - in: "path" - description: "Exec instance ID" - required: true - type: "string" - tags: ["Exec"] - /exec/{id}/resize: - post: - summary: "Resize an exec instance" - description: "Resize the TTY session used by an exec instance. This endpoint only works if `tty` was specified as part of creating and starting the exec instance." - operationId: "ExecResize" - responses: - 201: - description: "No error" - 404: - description: "No such exec instance" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "Exec instance ID" - required: true - type: "string" - - name: "h" - in: "query" - description: "Height of the TTY session in characters" - type: "integer" - - name: "w" - in: "query" - description: "Width of the TTY session in characters" - type: "integer" - tags: ["Exec"] - /exec/{id}/json: - get: - summary: "Inspect an exec instance" - description: "Return low-level information about an exec instance." - operationId: "ExecInspect" - produces: - - "application/json" - responses: - 200: - description: "No error" - schema: - type: "object" - properties: - ID: - type: "string" - Running: - type: "boolean" - ExitCode: - type: "integer" - ProcessConfig: - $ref: "#/definitions/ProcessConfig" - OpenStdin: - type: "boolean" - OpenStderr: - type: "boolean" - OpenStdout: - type: "boolean" - ContainerID: - type: "string" - Pid: - type: "integer" - description: "The system process ID for the exec process." - examples: - application/json: - CanRemove: false - ContainerID: "b53ee82b53a40c7dca428523e34f741f3abc51d9f297a14ff874bf761b995126" - DetachKeys: "" - ExitCode: 2 - ID: "f33bbfb39f5b142420f4759b2348913bd4a8d1a6d7fd56499cb41a1bb91d7b3b" - OpenStderr: true - OpenStdin: true - OpenStdout: true - ProcessConfig: - arguments: - - "-c" - - "exit 2" - entrypoint: "sh" - privileged: false - tty: true - user: "1000" - Running: false - Pid: 42000 - 404: - description: "No such exec instance" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "Exec instance ID" - required: true - type: "string" - tags: ["Exec"] - - /volumes: - get: - summary: "List volumes" - operationId: "VolumeList" - produces: ["application/json"] - responses: - 200: - description: "Summary volume data that matches the query" - schema: - type: "object" - required: [Volumes, Warnings] - properties: - Volumes: - type: "array" - x-nullable: false - description: "List of volumes" - items: - $ref: "#/definitions/Volume" - Warnings: - type: "array" - x-nullable: false - description: "Warnings that occurred when fetching the list of volumes" - items: - type: "string" - - examples: - application/json: - Volumes: - - Name: "tardis" - Driver: "local" - Mountpoint: "/var/lib/docker/volumes/tardis" - Labels: - com.example.some-label: "some-value" - com.example.some-other-label: "some-other-value" - Scope: "local" - Options: - device: "tmpfs" - o: "size=100m,uid=1000" - type: "tmpfs" - Warnings: [] - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "filters" - in: "query" - description: | - JSON encoded value of the filters (a `map[string][]string`) to - process on the volumes list. Available filters: - - - `name=` Matches all or part of a volume name. - - `dangling=` When set to `true` (or `1`), returns all - volumes that are not in use by a container. When set to `false` - (or `0`), only volumes that are in use by one or more - containers are returned. - - `driver=` Matches all or part of a volume - driver name. - type: "string" - format: "json" - tags: ["Volume"] - - /volumes/create: - post: - summary: "Create a volume" - operationId: "VolumeCreate" - consumes: ["application/json"] - produces: ["application/json"] - responses: - 201: - description: "The volume was created successfully" - schema: - $ref: "#/definitions/Volume" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "volumeConfig" - in: "body" - required: true - description: "Volume configuration" - schema: - type: "object" - properties: - Name: - description: "The new volume's name. If not specified, Docker generates a name." - type: "string" - x-nullable: false - Driver: - description: "Name of the volume driver to use." - type: "string" - default: "local" - x-nullable: false - DriverOpts: - description: "A mapping of driver options and values. These options are passed directly to the driver and are driver specific." - type: "object" - additionalProperties: - type: "string" - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - example: - Name: "tardis" - Labels: - com.example.some-label: "some-value" - com.example.some-other-label: "some-other-value" - Driver: "custom" - tags: ["Volume"] - - /volumes/{name}: - get: - summary: "Inspect a volume" - operationId: "VolumeInspect" - produces: ["application/json"] - responses: - 200: - description: "No error" - schema: - $ref: "#/definitions/Volume" - 404: - description: "No such volume" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - required: true - description: "Volume name or ID" - type: "string" - tags: ["Volume"] - - delete: - summary: "Remove a volume" - description: "Instruct the driver to remove the volume." - operationId: "VolumeDelete" - responses: - 204: - description: "The volume was removed" - 404: - description: "No such volume or volume driver" - schema: - $ref: "#/definitions/ErrorResponse" - 409: - description: "Volume is in use and cannot be removed" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - required: true - description: "Volume name or ID" - type: "string" - - name: "force" - in: "query" - description: "Force the removal of the volume" - type: "boolean" - default: false - tags: ["Volume"] - /volumes/prune: - post: - summary: "Delete unused volumes" - produces: - - "application/json" - operationId: "VolumePrune" - parameters: - - name: "filters" - in: "query" - description: | - Filters to process on the prune list, encoded as JSON (a `map[string][]string`). - - Available filters: - type: "string" - responses: - 200: - description: "No error" - schema: - type: "object" - properties: - VolumesDeleted: - description: "Volumes that were deleted" - type: "array" - items: - type: "string" - SpaceReclaimed: - description: "Disk space reclaimed in bytes" - type: "integer" - format: "int64" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Volume"] - /networks: - get: - summary: "List networks" - operationId: "NetworkList" - produces: - - "application/json" - responses: - 200: - description: "No error" - schema: - type: "array" - items: - $ref: "#/definitions/Network" - examples: - application/json: - - Name: "bridge" - Id: "f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566" - Created: "2016-10-19T06:21:00.416543526Z" - Scope: "local" - Driver: "bridge" - EnableIPv6: false - Internal: false - IPAM: - Driver: "default" - Config: - - - Subnet: "172.17.0.0/16" - Containers: - 39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867: - EndpointID: "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda" - MacAddress: "02:42:ac:11:00:02" - IPv4Address: "172.17.0.2/16" - IPv6Address: "" - Options: - com.docker.network.bridge.default_bridge: "true" - com.docker.network.bridge.enable_icc: "true" - com.docker.network.bridge.enable_ip_masquerade: "true" - com.docker.network.bridge.host_binding_ipv4: "0.0.0.0" - com.docker.network.bridge.name: "docker0" - com.docker.network.driver.mtu: "1500" - - Name: "none" - Id: "e086a3893b05ab69242d3c44e49483a3bbbd3a26b46baa8f61ab797c1088d794" - Created: "0001-01-01T00:00:00Z" - Scope: "local" - Driver: "null" - EnableIPv6: false - Internal: false - IPAM: - Driver: "default" - Config: [] - Containers: {} - Options: {} - - Name: "host" - Id: "13e871235c677f196c4e1ecebb9dc733b9b2d2ab589e30c539efeda84a24215e" - Created: "0001-01-01T00:00:00Z" - Scope: "local" - Driver: "host" - EnableIPv6: false - Internal: false - IPAM: - Driver: "default" - Config: [] - Containers: {} - Options: {} - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "filters" - in: "query" - description: | - JSON encoded value of the filters (a `map[string][]string`) to process on the networks list. Available filters: - - - `driver=` Matches a network's driver. - - `id=` Matches all or part of a network ID. - - `label=` or `label==` of a network label. - - `name=` Matches all or part of a network name. - - `type=["custom"|"builtin"]` Filters networks by type. The `custom` keyword returns all user-defined networks. - type: "string" - tags: ["Network"] - - /networks/{id}: - get: - summary: "Inspect a network" - operationId: "NetworkInspect" - produces: - - "application/json" - responses: - 200: - description: "No error" - schema: - $ref: "#/definitions/Network" - 404: - description: "Network not found" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "Network ID or name" - required: true - type: "string" - tags: ["Network"] - - delete: - summary: "Remove a network" - operationId: "NetworkDelete" - responses: - 204: - description: "No error" - 404: - description: "no such network" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "Network ID or name" - required: true - type: "string" - tags: ["Network"] - - /networks/create: - post: - summary: "Create a network" - operationId: "NetworkCreate" - consumes: - - "application/json" - produces: - - "application/json" - responses: - 201: - description: "No error" - schema: - type: "object" - properties: - Id: - description: "The ID of the created network." - type: "string" - Warning: - type: "string" - example: - Id: "22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30" - Warning: "" - 403: - description: "operation not supported for pre-defined networks" - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "plugin not found" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "networkConfig" - in: "body" - description: "Network configuration" - required: true - schema: - type: "object" - required: ["Name"] - properties: - Name: - description: "The network's name." - type: "string" - CheckDuplicate: - description: "Check for networks with duplicate names." - type: "boolean" - Driver: - description: "Name of the network driver plugin to use." - type: "string" - default: "bridge" - Internal: - description: "Restrict external access to the network." - type: "boolean" - IPAM: - description: "Optional custom IP scheme for the network." - $ref: "#/definitions/IPAM" - EnableIPv6: - description: "Enable IPv6 on the network." - type: "boolean" - Options: - description: "Network specific options to be used by the drivers." - type: "object" - additionalProperties: - type: "string" - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - example: - Name: "isolated_nw" - CheckDuplicate: false - Driver: "bridge" - EnableIPv6: true - IPAM: - Driver: "default" - Config: - - Subnet: "172.20.0.0/16" - IPRange: "172.20.10.0/24" - Gateway: "172.20.10.11" - - Subnet: "2001:db8:abcd::/64" - Gateway: "2001:db8:abcd::1011" - Options: - foo: "bar" - Internal: true - Options: - com.docker.network.bridge.default_bridge: "true" - com.docker.network.bridge.enable_icc: "true" - com.docker.network.bridge.enable_ip_masquerade: "true" - com.docker.network.bridge.host_binding_ipv4: "0.0.0.0" - com.docker.network.bridge.name: "docker0" - com.docker.network.driver.mtu: "1500" - Labels: - com.example.some-label: "some-value" - com.example.some-other-label: "some-other-value" - tags: ["Network"] - - /networks/{id}/connect: - post: - summary: "Connect a container to a network" - operationId: "NetworkConnect" - consumes: - - "application/octet-stream" - responses: - 200: - description: "No error" - 403: - description: "Operation not supported for swarm scoped networks" - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "Network or container not found" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "Network ID or name" - required: true - type: "string" - - name: "container" - in: "body" - required: true - schema: - type: "object" - properties: - Container: - type: "string" - description: "The ID or name of the container to connect to the network." - EndpointConfig: - $ref: "#/definitions/EndpointSettings" - example: - Container: "3613f73ba0e4" - EndpointConfig: - IPAMConfig: - IPv4Address: "172.24.56.89" - IPv6Address: "2001:db8::5689" - tags: ["Network"] - - /networks/{id}/disconnect: - post: - summary: "Disconnect a container from a network" - operationId: "NetworkDisconnect" - consumes: - - "application/json" - responses: - 200: - description: "No error" - 403: - description: "Operation not supported for swarm scoped networks" - schema: - $ref: "#/definitions/ErrorResponse" - 404: - description: "Network or container not found" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "Network ID or name" - required: true - type: "string" - - name: "container" - in: "body" - required: true - schema: - type: "object" - properties: - Container: - type: "string" - description: "The ID or name of the container to disconnect from the network." - Force: - type: "boolean" - description: "Force the container to disconnect from the network." - tags: ["Network"] - /networks/prune: - post: - summary: "Delete unused networks" - consumes: - - "application/json" - produces: - - "application/json" - operationId: "NetworkPrune" - parameters: - - name: "filters" - in: "query" - description: | - Filters to process on the prune list, encoded as JSON (a `map[string][]string`). - - Available filters: - type: "string" - responses: - 200: - description: "No error" - schema: - type: "object" - properties: - NetworksDeleted: - description: "Networks that were deleted" - type: "array" - items: - type: "string" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Network"] - /plugins: - get: - summary: "List plugins" - operationId: "PluginList" - description: "Returns information about installed plugins." - produces: ["application/json"] - responses: - 200: - description: "No error" - schema: - type: "array" - items: - $ref: "#/definitions/Plugin" - example: - - Id: "5724e2c8652da337ab2eedd19fc6fc0ec908e4bd907c7421bf6a8dfc70c4c078" - Name: "tiborvass/sample-volume-plugin" - Tag: "latest" - Active: true - Settings: - Env: - - "DEBUG=0" - Args: null - Devices: null - Config: - Description: "A sample volume plugin for Docker" - Documentation: "https://docs.docker.com/engine/extend/plugins/" - Interface: - Types: - - "docker.volumedriver/1.0" - Socket: "plugins.sock" - Entrypoint: - - "/usr/bin/sample-volume-plugin" - - "/data" - WorkDir: "" - User: {} - Network: - Type: "" - Linux: - Capabilities: null - AllowAllDevices: false - Devices: null - Mounts: null - PropagatedMount: "/data" - Env: - - Name: "DEBUG" - Description: "If set, prints debug messages" - Settable: null - Value: "0" - Args: - Name: "args" - Description: "command line arguments" - Settable: null - Value: [] - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Plugin"] - - /plugins/privileges: - get: - summary: "Get plugin privileges" - operationId: "GetPluginPrivileges" - responses: - 200: - description: "no error" - schema: - type: "array" - items: - description: "Describes a permission the user has to accept upon installing the plugin." - type: "object" - properties: - Name: - type: "string" - Description: - type: "string" - Value: - type: "array" - items: - type: "string" - example: - - Name: "network" - Description: "" - Value: - - "host" - - Name: "mount" - Description: "" - Value: - - "/data" - - Name: "device" - Description: "" - Value: - - "/dev/cpu_dma_latency" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "query" - description: "The name of the plugin. The `:latest` tag is optional, and is the default if omitted." - required: true - type: "string" - tags: - - "Plugin" - - /plugins/pull: - post: - summary: "Install a plugin" - operationId: "PluginPull" - description: | - Pulls and installs a plugin. After the plugin is installed, it can be enabled using the [`POST /plugins/{name}/enable` endpoint](#operation/PostPluginsEnable). - produces: - - "application/json" - responses: - 204: - description: "no error" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "remote" - in: "query" - description: | - Remote reference for plugin to install. - - The `:latest` tag is optional, and is used as the default if omitted. - required: true - type: "string" - - name: "name" - in: "query" - description: | - Local name for the pulled plugin. - - The `:latest` tag is optional, and is used as the default if omitted. - required: false - type: "string" - - name: "X-Registry-Auth" - in: "header" - description: "A base64-encoded auth configuration to use when pulling a plugin from a registry. [See the authentication section for details.](#section/Authentication)" - type: "string" - - name: "body" - in: "body" - schema: - type: "array" - items: - description: "Describes a permission accepted by the user upon installing the plugin." - type: "object" - properties: - Name: - type: "string" - Description: - type: "string" - Value: - type: "array" - items: - type: "string" - example: - - Name: "network" - Description: "" - Value: - - "host" - - Name: "mount" - Description: "" - Value: - - "/data" - - Name: "device" - Description: "" - Value: - - "/dev/cpu_dma_latency" - tags: ["Plugin"] - /plugins/{name}/json: - get: - summary: "Inspect a plugin" - operationId: "PluginInspect" - responses: - 200: - description: "no error" - schema: - $ref: "#/definitions/Plugin" - 404: - description: "plugin is not installed" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "The name of the plugin. The `:latest` tag is optional, and is the default if omitted." - required: true - type: "string" - tags: ["Plugin"] - /plugins/{name}: - delete: - summary: "Remove a plugin" - operationId: "PluginDelete" - responses: - 200: - description: "no error" - schema: - $ref: "#/definitions/Plugin" - 404: - description: "plugin is not installed" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "The name of the plugin. The `:latest` tag is optional, and is the default if omitted." - required: true - type: "string" - - name: "force" - in: "query" - description: "Disable the plugin before removing. This may result in issues if the plugin is in use by a container." - type: "boolean" - default: false - tags: ["Plugin"] - /plugins/{name}/enable: - post: - summary: "Enable a plugin" - operationId: "PluginEnable" - responses: - 200: - description: "no error" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "The name of the plugin. The `:latest` tag is optional, and is the default if omitted." - required: true - type: "string" - - name: "timeout" - in: "query" - description: "Set the HTTP client timeout (in seconds)" - type: "integer" - default: 0 - tags: ["Plugin"] - /plugins/{name}/disable: - post: - summary: "Disable a plugin" - operationId: "PluginDisable" - responses: - 200: - description: "no error" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "The name of the plugin. The `:latest` tag is optional, and is the default if omitted." - required: true - type: "string" - tags: ["Plugin"] - /plugins/{name}/upgrade: - post: - summary: "Upgrade a plugin" - operationId: "PluginUpgrade" - responses: - 204: - description: "no error" - 404: - description: "plugin not installed" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "path" - description: "The name of the plugin. The `:latest` tag is optional, and is the default if omitted." - required: true - type: "string" - - name: "remote" - in: "query" - description: | - Remote reference to upgrade to. - - The `:latest` tag is optional, and is used as the default if omitted. - required: true - type: "string" - - name: "X-Registry-Auth" - in: "header" - description: "A base64-encoded auth configuration to use when pulling a plugin from a registry. [See the authentication section for details.](#section/Authentication)" - type: "string" - - name: "body" - in: "body" - schema: - type: "array" - items: - description: "Describes a permission accepted by the user upon installing the plugin." - type: "object" - properties: - Name: - type: "string" - Description: - type: "string" - Value: - type: "array" - items: - type: "string" - example: - - Name: "network" - Description: "" - Value: - - "host" - - Name: "mount" - Description: "" - Value: - - "/data" - - Name: "device" - Description: "" - Value: - - "/dev/cpu_dma_latency" - tags: ["Plugin"] - /plugins/create: - post: - summary: "Create a plugin" - operationId: "PluginCreate" - consumes: - - "application/x-tar" - responses: - 204: - description: "no error" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "name" - in: "query" - description: "The name of the plugin. The `:latest` tag is optional, and is the default if omitted." - required: true - type: "string" - - name: "tarContext" - in: "body" - description: "Path to tar containing plugin rootfs and manifest" - schema: - type: "string" - format: "binary" - tags: ["Plugin"] - /plugins/{name}/push: - post: - summary: "Push a plugin" - operationId: "PluginPush" - description: | - Push a plugin to the registry. - parameters: - - name: "name" - in: "path" - description: "The name of the plugin. The `:latest` tag is optional, and is the default if omitted." - required: true - type: "string" - responses: - 200: - description: "no error" - 404: - description: "plugin not installed" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Plugin"] - /plugins/{name}/set: - post: - summary: "Configure a plugin" - operationId: "PluginSet" - consumes: - - "application/json" - parameters: - - name: "name" - in: "path" - description: "The name of the plugin. The `:latest` tag is optional, and is the default if omitted." - required: true - type: "string" - - name: "body" - in: "body" - schema: - type: "array" - items: - type: "string" - example: ["DEBUG=1"] - responses: - 204: - description: "No error" - 404: - description: "Plugin not installed" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "Server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Plugin"] - /nodes: - get: - summary: "List nodes" - operationId: "NodeList" - responses: - 200: - description: "no error" - schema: - type: "array" - items: - $ref: "#/definitions/Node" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "filters" - in: "query" - description: | - Filters to process on the nodes list, encoded as JSON (a `map[string][]string`). - - Available filters: - - `id=` - - `label=` - - `membership=`(`accepted`|`pending`)` - - `name=` - - `role=`(`manager`|`worker`)` - type: "string" - tags: ["Node"] - /nodes/{id}: - get: - summary: "Inspect a node" - operationId: "NodeInspect" - responses: - 200: - description: "no error" - schema: - $ref: "#/definitions/Node" - 404: - description: "no such node" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "The ID or name of the node" - type: "string" - required: true - tags: ["Node"] - delete: - summary: "Delete a node" - operationId: "NodeDelete" - responses: - 200: - description: "no error" - 404: - description: "no such node" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "The ID or name of the node" - type: "string" - required: true - - name: "force" - in: "query" - description: "Force remove a node from the swarm" - default: false - type: "boolean" - tags: ["Node"] - /nodes/{id}/update: - post: - summary: "Update a node" - operationId: "NodeUpdate" - responses: - 200: - description: "no error" - 404: - description: "no such node" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "The ID of the node" - type: "string" - required: true - - name: "body" - in: "body" - schema: - $ref: "#/definitions/NodeSpec" - - name: "version" - in: "query" - description: "The version number of the node object being updated. This is required to avoid conflicting writes." - type: "integer" - format: "int64" - required: true - tags: ["Node"] - /swarm: - get: - summary: "Inspect swarm" - operationId: "SwarmInspect" - responses: - 200: - description: "no error" - schema: - allOf: - - $ref: "#/definitions/ClusterInfo" - - type: "object" - properties: - JoinTokens: - description: "The tokens workers and managers need to join the swarm." - type: "object" - properties: - Worker: - description: "The token workers can use to join the swarm." - type: "string" - Manager: - description: "The token managers can use to join the swarm." - type: "string" - example: - CreatedAt: "2016-08-15T16:00:20.349727406Z" - Spec: - Dispatcher: - HeartbeatPeriod: 5000000000 - Orchestration: - TaskHistoryRetentionLimit: 10 - CAConfig: - NodeCertExpiry: 7776000000000000 - Raft: - LogEntriesForSlowFollowers: 500 - HeartbeatTick: 1 - SnapshotInterval: 10000 - ElectionTick: 3 - TaskDefaults: {} - EncryptionConfig: - AutoLockManagers: false - Name: "default" - JoinTokens: - Worker: "SWMTKN-1-1h8aps2yszaiqmz2l3oc5392pgk8e49qhx2aj3nyv0ui0hez2a-6qmn92w6bu3jdvnglku58u11a" - Manager: "SWMTKN-1-1h8aps2yszaiqmz2l3oc5392pgk8e49qhx2aj3nyv0ui0hez2a-8llk83c4wm9lwioey2s316r9l" - ID: "70ilmkj2f6sp2137c753w2nmt" - UpdatedAt: "2016-08-15T16:32:09.623207604Z" - Version: - Index: 51 - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Swarm"] - /swarm/init: - post: - summary: "Initialize a new swarm" - operationId: "SwarmInit" - produces: - - "application/json" - - "text/plain" - responses: - 200: - description: "no error" - schema: - description: "The node ID" - type: "string" - example: "7v2t30z9blmxuhnyo6s4cpenp" - 400: - description: "bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 406: - description: "node is already part of a swarm" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "body" - in: "body" - required: true - schema: - type: "object" - properties: - ListenAddr: - description: "Listen address used for inter-manager communication, as well as determining the networking interface used for the VXLAN Tunnel Endpoint (VTEP). This can either be an address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port number, like `eth0:4567`. If the port number is omitted, the default swarm listening port is used." - type: "string" - AdvertiseAddr: - description: "Externally reachable address advertised to other nodes. This can either be an address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port number, like `eth0:4567`. If the port number is omitted, the port number from the listen address is used. If `AdvertiseAddr` is not specified, it will be automatically detected when possible." - type: "string" - ForceNewCluster: - description: "Force creation of a new swarm." - type: "boolean" - Spec: - $ref: "#/definitions/SwarmSpec" - example: - ListenAddr: "0.0.0.0:2377" - AdvertiseAddr: "192.168.1.1:2377" - ForceNewCluster: false - Spec: - Orchestration: {} - Raft: {} - Dispatcher: {} - CAConfig: {} - EncryptionConfig: - AutoLockManagers: false - tags: ["Swarm"] - /swarm/join: - post: - summary: "Join an existing swarm" - operationId: "SwarmJoin" - responses: - 200: - description: "no error" - 400: - description: "bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - 503: - description: "node is already part of a swarm" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "body" - in: "body" - required: true - schema: - type: "object" - properties: - ListenAddr: - description: "Listen address used for inter-manager communication if the node gets promoted to manager, as well as determining the networking interface used for the VXLAN Tunnel Endpoint (VTEP)." - type: "string" - AdvertiseAddr: - description: "Externally reachable address advertised to other nodes. This can either be an address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port number, like `eth0:4567`. If the port number is omitted, the port number from the listen address is used. If `AdvertiseAddr` is not specified, it will be automatically detected when possible." - type: "string" - RemoteAddrs: - description: "Addresses of manager nodes already participating in the swarm." - type: "string" - JoinToken: - description: "Secret token for joining this swarm." - type: "string" - example: - ListenAddr: "0.0.0.0:2377" - AdvertiseAddr: "192.168.1.1:2377" - RemoteAddrs: - - "node1:2377" - JoinToken: "SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2" - tags: ["Swarm"] - /swarm/leave: - post: - summary: "Leave a swarm" - operationId: "SwarmLeave" - responses: - 200: - description: "no error" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - 503: - description: "node is not part of a swarm" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "force" - description: "Force leave swarm, even if this is the last manager or that it will break the cluster." - in: "query" - type: "boolean" - default: false - tags: ["Swarm"] - /swarm/update: - post: - summary: "Update a swarm" - operationId: "SwarmUpdate" - responses: - 200: - description: "no error" - 400: - description: "bad parameter" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - 503: - description: "node is not part of a swarm" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "body" - in: "body" - required: true - schema: - $ref: "#/definitions/SwarmSpec" - - name: "version" - in: "query" - description: "The version number of the swarm object being updated. This is required to avoid conflicting writes." - type: "integer" - format: "int64" - required: true - - name: "rotateWorkerToken" - in: "query" - description: "Rotate the worker join token." - type: "boolean" - default: false - - name: "rotateManagerToken" - in: "query" - description: "Rotate the manager join token." - type: "boolean" - default: false - - name: "rotateManagerUnlockKey" - in: "query" - description: "Rotate the manager unlock key." - type: "boolean" - default: false - tags: ["Swarm"] - /swarm/unlockkey: - get: - summary: "Get the unlock key" - operationId: "SwarmUnlockkey" - consumes: - - "application/json" - responses: - 200: - description: "no error" - schema: - type: "object" - properties: - UnlockKey: - description: "The swarm's unlock key." - type: "string" - example: - UnlockKey: "SWMKEY-1-7c37Cc8654o6p38HnroywCi19pllOnGtbdZEgtKxZu8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Swarm"] - /swarm/unlock: - post: - summary: "Unlock a locked manager" - operationId: "SwarmUnlock" - consumes: - - "application/json" - produces: - - "application/json" - parameters: - - name: "body" - in: "body" - required: true - schema: - type: "object" - properties: - UnlockKey: - description: "The swarm's unlock key." - type: "string" - example: - UnlockKey: "SWMKEY-1-7c37Cc8654o6p38HnroywCi19pllOnGtbdZEgtKxZu8" - responses: - 200: - description: "no error" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - tags: ["Swarm"] - /services: - get: - summary: "List services" - operationId: "ServiceList" - responses: - 200: - description: "no error" - schema: - type: "array" - items: - $ref: "#/definitions/Service" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "filters" - in: "query" - type: "string" - description: | - A JSON encoded value of the filters (a `map[string][]string`) to process on the services list. Available filters: - - - `id=` - - `name=` - - `label=` - tags: ["Service"] - /services/create: - post: - summary: "Create a service" - operationId: "ServiceCreate" - consumes: - - "application/json" - produces: - - "application/json" - responses: - 201: - description: "no error" - schema: - type: "object" - properties: - ID: - description: "The ID of the created service." - type: "string" - Warning: - description: "Optional warning message" - type: "string" - example: - ID: "ak7w3gjqoa3kuz8xcpnyy0pvl" - Warning: "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found" - 403: - description: "network is not eligible for services" - schema: - $ref: "#/definitions/ErrorResponse" - 409: - description: "name conflicts with an existing service" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - 503: - description: "server error or node is not part of a swarm" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "body" - in: "body" - required: true - schema: - allOf: - - $ref: "#/definitions/ServiceSpec" - - type: "object" - example: - Name: "web" - TaskTemplate: - ContainerSpec: - Image: "nginx:alpine" - Mounts: - - - ReadOnly: true - Source: "web-data" - Target: "/usr/share/nginx/html" - Type: "volume" - VolumeOptions: - DriverConfig: {} - Labels: - com.example.something: "something-value" - User: "33" - DNSConfig: - Nameservers: ["8.8.8.8"] - Search: ["example.org"] - Options: ["timeout:3"] - LogDriver: - Name: "json-file" - Options: - max-file: "3" - max-size: "10M" - Placement: {} - Resources: - Limits: - MemoryBytes: 104857600 - Reservations: {} - RestartPolicy: - Condition: "on-failure" - Delay: 10000000000 - MaxAttempts: 10 - Mode: - Replicated: - Replicas: 4 - UpdateConfig: - Delay: 30000000000 - Parallelism: 2 - FailureAction: "pause" - EndpointSpec: - Ports: - - - Protocol: "tcp" - PublishedPort: 8080 - TargetPort: 80 - Labels: - foo: "bar" - - name: "X-Registry-Auth" - in: "header" - description: "A base64-encoded auth configuration for pulling from private registries. [See the authentication section for details.](#section/Authentication)" - type: "string" - tags: ["Service"] - /services/{id}: - get: - summary: "Inspect a service" - operationId: "ServiceInspect" - responses: - 200: - description: "no error" - schema: - $ref: "#/definitions/Service" - 404: - description: "no such service" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "ID or name of service." - required: true - type: "string" - tags: ["Service"] - delete: - summary: "Delete a service" - operationId: "ServiceDelete" - responses: - 200: - description: "no error" - 404: - description: "no such service" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "ID or name of service." - required: true - type: "string" - tags: ["Service"] - /services/{id}/update: - post: - summary: "Update a service" - operationId: "ServiceUpdate" - consumes: ["application/json"] - produces: ["application/json"] - responses: - 200: - description: "no error" - schema: - $ref: "#/definitions/ImageDeleteResponse" - 404: - description: "no such service" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "ID or name of service." - required: true - type: "string" - - name: "body" - in: "body" - required: true - schema: - allOf: - - $ref: "#/definitions/ServiceSpec" - - type: "object" - example: - Name: "top" - TaskTemplate: - ContainerSpec: - Image: "busybox" - Args: - - "top" - Resources: - Limits: {} - Reservations: {} - RestartPolicy: - Condition: "any" - MaxAttempts: 0 - Placement: {} - ForceUpdate: 0 - Mode: - Replicated: - Replicas: 1 - UpdateConfig: - Parallelism: 1 - Monitor: 15000000000 - MaxFailureRatio: 0.15 - EndpointSpec: - Mode: "vip" - - - name: "version" - in: "query" - description: "The version number of the service object being updated. This is required to avoid conflicting writes." - required: true - type: "integer" - - name: "registryAuthFrom" - in: "query" - type: "string" - description: "If the X-Registry-Auth header is not specified, this - parameter indicates where to find registry authorization credentials. The - valid values are `spec` and `previous-spec`." - default: "spec" - - name: "X-Registry-Auth" - in: "header" - description: "A base64-encoded auth configuration for pulling from private registries. [See the authentication section for details.](#section/Authentication)" - type: "string" - - tags: ["Service"] - /services/{id}/logs: - get: - summary: "Get service logs" - description: | - Get `stdout` and `stderr` logs from a service. - - **Note**: This endpoint works only for services with the `json-file` or `journald` logging drivers. - operationId: "ServiceLogs" - produces: - - "application/vnd.docker.raw-stream" - - "application/json" - responses: - 101: - description: "logs returned as a stream" - schema: - type: "string" - format: "binary" - 200: - description: "logs returned as a string in response body" - schema: - type: "string" - 404: - description: "no such container" - schema: - $ref: "#/definitions/ErrorResponse" - examples: - application/json: - message: "No such container: c2ada9df5af8" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - description: "ID or name of the container" - type: "string" - - name: "details" - in: "query" - description: "Show extra details provided to logs." - type: "boolean" - default: false - - name: "follow" - in: "query" - description: | - Return the logs as a stream. - - This will return a `101` HTTP response with a `Connection: upgrade` header, then hijack the HTTP connection to send raw output. For more information about hijacking and the stream format, [see the documentation for the attach endpoint](#operation/ContainerAttach). - type: "boolean" - default: false - - name: "stdout" - in: "query" - description: "Return logs from `stdout`" - type: "boolean" - default: false - - name: "stderr" - in: "query" - description: "Return logs from `stderr`" - type: "boolean" - default: false - - name: "since" - in: "query" - description: "Only return logs since this time, as a UNIX timestamp" - type: "integer" - default: 0 - - name: "timestamps" - in: "query" - description: "Add timestamps to every log line" - type: "boolean" - default: false - - name: "tail" - in: "query" - description: "Only return this number of log lines from the end of the logs. Specify as an integer or `all` to output all log lines." - type: "string" - default: "all" - tags: ["Service"] - /tasks: - get: - summary: "List tasks" - operationId: "TaskList" - produces: - - "application/json" - responses: - 200: - description: "no error" - schema: - type: "array" - items: - $ref: "#/definitions/Task" - example: - - ID: "0kzzo1i0y4jz6027t0k7aezc7" - Version: - Index: 71 - CreatedAt: "2016-06-07T21:07:31.171892745Z" - UpdatedAt: "2016-06-07T21:07:31.376370513Z" - Spec: - ContainerSpec: - Image: "redis" - Resources: - Limits: {} - Reservations: {} - RestartPolicy: - Condition: "any" - MaxAttempts: 0 - Placement: {} - ServiceID: "9mnpnzenvg8p8tdbtq4wvbkcz" - Slot: 1 - NodeID: "60gvrl6tm78dmak4yl7srz94v" - Status: - Timestamp: "2016-06-07T21:07:31.290032978Z" - State: "running" - Message: "started" - ContainerStatus: - ContainerID: "e5d62702a1b48d01c3e02ca1e0212a250801fa8d67caca0b6f35919ebc12f035" - PID: 677 - DesiredState: "running" - NetworksAttachments: - - Network: - ID: "4qvuz4ko70xaltuqbt8956gd1" - Version: - Index: 18 - CreatedAt: "2016-06-07T20:31:11.912919752Z" - UpdatedAt: "2016-06-07T21:07:29.955277358Z" - Spec: - Name: "ingress" - Labels: - com.docker.swarm.internal: "true" - DriverConfiguration: {} - IPAMOptions: - Driver: {} - Configs: - - Subnet: "10.255.0.0/16" - Gateway: "10.255.0.1" - DriverState: - Name: "overlay" - Options: - com.docker.network.driver.overlay.vxlanid_list: "256" - IPAMOptions: - Driver: - Name: "default" - Configs: - - Subnet: "10.255.0.0/16" - Gateway: "10.255.0.1" - Addresses: - - "10.255.0.10/16" - - ID: "1yljwbmlr8er2waf8orvqpwms" - Version: - Index: 30 - CreatedAt: "2016-06-07T21:07:30.019104782Z" - UpdatedAt: "2016-06-07T21:07:30.231958098Z" - Name: "hopeful_cori" - Spec: - ContainerSpec: - Image: "redis" - Resources: - Limits: {} - Reservations: {} - RestartPolicy: - Condition: "any" - MaxAttempts: 0 - Placement: {} - ServiceID: "9mnpnzenvg8p8tdbtq4wvbkcz" - Slot: 1 - NodeID: "60gvrl6tm78dmak4yl7srz94v" - Status: - Timestamp: "2016-06-07T21:07:30.202183143Z" - State: "shutdown" - Message: "shutdown" - ContainerStatus: - ContainerID: "1cf8d63d18e79668b0004a4be4c6ee58cddfad2dae29506d8781581d0688a213" - DesiredState: "shutdown" - NetworksAttachments: - - Network: - ID: "4qvuz4ko70xaltuqbt8956gd1" - Version: - Index: 18 - CreatedAt: "2016-06-07T20:31:11.912919752Z" - UpdatedAt: "2016-06-07T21:07:29.955277358Z" - Spec: - Name: "ingress" - Labels: - com.docker.swarm.internal: "true" - DriverConfiguration: {} - IPAMOptions: - Driver: {} - Configs: - - Subnet: "10.255.0.0/16" - Gateway: "10.255.0.1" - DriverState: - Name: "overlay" - Options: - com.docker.network.driver.overlay.vxlanid_list: "256" - IPAMOptions: - Driver: - Name: "default" - Configs: - - Subnet: "10.255.0.0/16" - Gateway: "10.255.0.1" - Addresses: - - "10.255.0.5/16" - - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "filters" - in: "query" - type: "string" - description: | - A JSON encoded value of the filters (a `map[string][]string`) to process on the tasks list. Available filters: - - - `id=` - - `name=` - - `service=` - - `node=` - - `label=key` or `label="key=value"` - - `desired-state=(running | shutdown | accepted)` - tags: ["Task"] - /tasks/{id}: - get: - summary: "Inspect a task" - operationId: "TaskInspect" - produces: - - "application/json" - responses: - 200: - description: "no error" - schema: - $ref: "#/definitions/Task" - 404: - description: "no such task" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "ID of the task" - required: true - type: "string" - tags: ["Task"] - /secrets: - get: - summary: "List secrets" - operationId: "SecretList" - produces: - - "application/json" - responses: - 200: - description: "no error" - schema: - type: "array" - items: - $ref: "#/definitions/Secret" - example: - - ID: "ktnbjxoalbkvbvedmg1urrz8h" - Version: - Index: 11 - CreatedAt: "2016-11-05T01:20:17.327670065Z" - UpdatedAt: "2016-11-05T01:20:17.327670065Z" - Spec: - Name: "app-dev.crt" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "filters" - in: "query" - type: "string" - description: | - A JSON encoded value of the filters (a `map[string][]string`) to process on the secrets list. Available filters: - - - `names=` - tags: ["Secret"] - /secrets/create: - post: - summary: "Create a secret" - operationId: "SecretCreate" - consumes: - - "application/json" - produces: - - "application/json" - responses: - 201: - description: "no error" - schema: - type: "object" - properties: - ID: - description: "The ID of the created secret." - type: "string" - example: - ID: "ktnbjxoalbkvbvedmg1urrz8h" - 406: - description: "server error or node is not part of a swarm" - schema: - $ref: "#/definitions/ErrorResponse" - 409: - description: "name conflicts with an existing object" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "body" - in: "body" - schema: - allOf: - - $ref: "#/definitions/SecretSpec" - - type: "object" - example: - Name: "app-key.crt" - Labels: - foo: "bar" - Data: "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg==" - tags: ["Secret"] - /secrets/{id}: - get: - summary: "Inspect a secret" - operationId: "SecretInspect" - produces: - - "application/json" - responses: - 200: - description: "no error" - schema: - $ref: "#/definitions/Secret" - example: - ID: "ktnbjxoalbkvbvedmg1urrz8h" - Version: - Index: 11 - CreatedAt: "2016-11-05T01:20:17.327670065Z" - UpdatedAt: "2016-11-05T01:20:17.327670065Z" - Spec: - Name: "app-dev.crt" - 404: - description: "secret not found" - schema: - $ref: "#/definitions/ErrorResponse" - 406: - description: "node is not part of a swarm" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - type: "string" - description: "ID of the secret" - tags: ["Secret"] - delete: - summary: "Delete a secret" - operationId: "SecretDelete" - produces: - - "application/json" - responses: - 204: - description: "no error" - 404: - description: "secret not found" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - required: true - type: "string" - description: "ID of the secret" - tags: ["Secret"] - /secrets/{id}/update: - post: - summary: "Update a Secret" - operationId: "SecretUpdate" - responses: - 200: - description: "no error" - 404: - description: "no such secret" - schema: - $ref: "#/definitions/ErrorResponse" - 500: - description: "server error" - schema: - $ref: "#/definitions/ErrorResponse" - parameters: - - name: "id" - in: "path" - description: "The ID of the secret" - type: "string" - required: true - - name: "body" - in: "body" - schema: - $ref: "#/definitions/SecretSpec" - description: "The spec of the secret to update. Currently, only the Labels field can be updated. All other fields must remain unchanged from the [SecretInspect endpoint](#operation/SecretInspect) response values." - - name: "version" - in: "query" - description: "The version number of the secret object being updated. This is required to avoid conflicting writes." - type: "integer" - format: "int64" - required: true - tags: ["Secret"] diff --git a/vendor/github.com/docker/docker/api/templates/server/operation.gotmpl b/vendor/github.com/docker/docker/api/templates/server/operation.gotmpl deleted file mode 100644 index 3a3d752..0000000 --- a/vendor/github.com/docker/docker/api/templates/server/operation.gotmpl +++ /dev/null @@ -1,26 +0,0 @@ -package {{ .Package }} - -// ---------------------------------------------------------------------------- -// DO NOT EDIT THIS FILE -// This file was generated by `swagger generate operation` -// -// See hack/swagger-gen.sh -// ---------------------------------------------------------------------------- - -import ( - "net/http" - - context "golang.org/x/net/context" - - {{ range .DefaultImports }}{{ printf "%q" . }} - {{ end }} - {{ range $key, $value := .Imports }}{{ $key }} {{ printf "%q" $value }} - {{ end }} -) - - -{{ range .ExtraSchemas }} -// {{ .Name }} {{ template "docstring" . }} -// swagger:model {{ .Name }} -{{ template "schema" . }} -{{ end }} diff --git a/vendor/github.com/docker/docker/api/types/auth.go b/vendor/github.com/docker/docker/api/types/auth.go deleted file mode 100644 index 056af6b..0000000 --- a/vendor/github.com/docker/docker/api/types/auth.go +++ /dev/null @@ -1,22 +0,0 @@ -package types - -// AuthConfig contains authorization information for connecting to a Registry -type AuthConfig struct { - Username string `json:"username,omitempty"` - Password string `json:"password,omitempty"` - Auth string `json:"auth,omitempty"` - - // Email is an optional value associated with the username. - // This field is deprecated and will be removed in a later - // version of docker. - Email string `json:"email,omitempty"` - - ServerAddress string `json:"serveraddress,omitempty"` - - // IdentityToken is used to authenticate the user and get - // an access token for the registry. - IdentityToken string `json:"identitytoken,omitempty"` - - // RegistryToken is a bearer token to be sent to a registry - RegistryToken string `json:"registrytoken,omitempty"` -} diff --git a/vendor/github.com/docker/docker/api/types/backend/backend.go b/vendor/github.com/docker/docker/api/types/backend/backend.go deleted file mode 100644 index abc0bba..0000000 --- a/vendor/github.com/docker/docker/api/types/backend/backend.go +++ /dev/null @@ -1,84 +0,0 @@ -// Package backend includes types to send information to server backends. -package backend - -import ( - "io" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/streamformatter" -) - -// ContainerAttachConfig holds the streams to use when connecting to a container to view logs. -type ContainerAttachConfig struct { - GetStreams func() (io.ReadCloser, io.Writer, io.Writer, error) - UseStdin bool - UseStdout bool - UseStderr bool - Logs bool - Stream bool - DetachKeys string - - // Used to signify that streams are multiplexed and therefore need a StdWriter to encode stdout/sderr messages accordingly. - // TODO @cpuguy83: This shouldn't be needed. It was only added so that http and websocket endpoints can use the same function, and the websocket function was not using a stdwriter prior to this change... - // HOWEVER, the websocket endpoint is using a single stream and SHOULD be encoded with stdout/stderr as is done for HTTP since it is still just a single stream. - // Since such a change is an API change unrelated to the current changeset we'll keep it as is here and change separately. - MuxStreams bool -} - -// ContainerLogsConfig holds configs for logging operations. Exists -// for users of the backend to to pass it a logging configuration. -type ContainerLogsConfig struct { - types.ContainerLogsOptions - OutStream io.Writer -} - -// ContainerStatsConfig holds information for configuring the runtime -// behavior of a backend.ContainerStats() call. -type ContainerStatsConfig struct { - Stream bool - OutStream io.Writer - Version string -} - -// ExecInspect holds information about a running process started -// with docker exec. -type ExecInspect struct { - ID string - Running bool - ExitCode *int - ProcessConfig *ExecProcessConfig - OpenStdin bool - OpenStderr bool - OpenStdout bool - CanRemove bool - ContainerID string - DetachKeys []byte - Pid int -} - -// ExecProcessConfig holds information about the exec process -// running on the host. -type ExecProcessConfig struct { - Tty bool `json:"tty"` - Entrypoint string `json:"entrypoint"` - Arguments []string `json:"arguments"` - Privileged *bool `json:"privileged,omitempty"` - User string `json:"user,omitempty"` -} - -// ContainerCommitConfig is a wrapper around -// types.ContainerCommitConfig that also -// transports configuration changes for a container. -type ContainerCommitConfig struct { - types.ContainerCommitConfig - Changes []string -} - -// ProgressWriter is an interface -// to transport progress streams. -type ProgressWriter struct { - Output io.Writer - StdoutFormatter *streamformatter.StdoutFormatter - StderrFormatter *streamformatter.StderrFormatter - ProgressReaderFunc func(io.ReadCloser) io.ReadCloser -} diff --git a/vendor/github.com/docker/docker/api/types/blkiodev/blkio.go b/vendor/github.com/docker/docker/api/types/blkiodev/blkio.go deleted file mode 100644 index 931ae10..0000000 --- a/vendor/github.com/docker/docker/api/types/blkiodev/blkio.go +++ /dev/null @@ -1,23 +0,0 @@ -package blkiodev - -import "fmt" - -// WeightDevice is a structure that holds device:weight pair -type WeightDevice struct { - Path string - Weight uint16 -} - -func (w *WeightDevice) String() string { - return fmt.Sprintf("%s:%d", w.Path, w.Weight) -} - -// ThrottleDevice is a structure that holds device:rate_per_second pair -type ThrottleDevice struct { - Path string - Rate uint64 -} - -func (t *ThrottleDevice) String() string { - return fmt.Sprintf("%s:%d", t.Path, t.Rate) -} diff --git a/vendor/github.com/docker/docker/api/types/client.go b/vendor/github.com/docker/docker/api/types/client.go deleted file mode 100644 index 7900d64..0000000 --- a/vendor/github.com/docker/docker/api/types/client.go +++ /dev/null @@ -1,378 +0,0 @@ -package types - -import ( - "bufio" - "io" - "net" - "os" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/filters" - "github.com/docker/go-units" -) - -// CheckpointCreateOptions holds parameters to create a checkpoint from a container -type CheckpointCreateOptions struct { - CheckpointID string - CheckpointDir string - Exit bool -} - -// CheckpointListOptions holds parameters to list checkpoints for a container -type CheckpointListOptions struct { - CheckpointDir string -} - -// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container -type CheckpointDeleteOptions struct { - CheckpointID string - CheckpointDir string -} - -// ContainerAttachOptions holds parameters to attach to a container. -type ContainerAttachOptions struct { - Stream bool - Stdin bool - Stdout bool - Stderr bool - DetachKeys string - Logs bool -} - -// ContainerCommitOptions holds parameters to commit changes into a container. -type ContainerCommitOptions struct { - Reference string - Comment string - Author string - Changes []string - Pause bool - Config *container.Config -} - -// ContainerExecInspect holds information returned by exec inspect. -type ContainerExecInspect struct { - ExecID string - ContainerID string - Running bool - ExitCode int - Pid int -} - -// ContainerListOptions holds parameters to list containers with. -type ContainerListOptions struct { - Quiet bool - Size bool - All bool - Latest bool - Since string - Before string - Limit int - Filters filters.Args -} - -// ContainerLogsOptions holds parameters to filter logs with. -type ContainerLogsOptions struct { - ShowStdout bool - ShowStderr bool - Since string - Timestamps bool - Follow bool - Tail string - Details bool -} - -// ContainerRemoveOptions holds parameters to remove containers. -type ContainerRemoveOptions struct { - RemoveVolumes bool - RemoveLinks bool - Force bool -} - -// ContainerStartOptions holds parameters to start containers. -type ContainerStartOptions struct { - CheckpointID string - CheckpointDir string -} - -// CopyToContainerOptions holds information -// about files to copy into a container -type CopyToContainerOptions struct { - AllowOverwriteDirWithFile bool -} - -// EventsOptions holds parameters to filter events with. -type EventsOptions struct { - Since string - Until string - Filters filters.Args -} - -// NetworkListOptions holds parameters to filter the list of networks with. -type NetworkListOptions struct { - Filters filters.Args -} - -// HijackedResponse holds connection information for a hijacked request. -type HijackedResponse struct { - Conn net.Conn - Reader *bufio.Reader -} - -// Close closes the hijacked connection and reader. -func (h *HijackedResponse) Close() { - h.Conn.Close() -} - -// CloseWriter is an interface that implements structs -// that close input streams to prevent from writing. -type CloseWriter interface { - CloseWrite() error -} - -// CloseWrite closes a readWriter for writing. -func (h *HijackedResponse) CloseWrite() error { - if conn, ok := h.Conn.(CloseWriter); ok { - return conn.CloseWrite() - } - return nil -} - -// ImageBuildOptions holds the information -// necessary to build images. -type ImageBuildOptions struct { - Tags []string - SuppressOutput bool - RemoteContext string - NoCache bool - Remove bool - ForceRemove bool - PullParent bool - Isolation container.Isolation - CPUSetCPUs string - CPUSetMems string - CPUShares int64 - CPUQuota int64 - CPUPeriod int64 - Memory int64 - MemorySwap int64 - CgroupParent string - NetworkMode string - ShmSize int64 - Dockerfile string - Ulimits []*units.Ulimit - // See the parsing of buildArgs in api/server/router/build/build_routes.go - // for an explaination of why BuildArgs needs to use *string instead of - // just a string - BuildArgs map[string]*string - AuthConfigs map[string]AuthConfig - Context io.Reader - Labels map[string]string - // squash the resulting image's layers to the parent - // preserves the original image and creates a new one from the parent with all - // the changes applied to a single layer - Squash bool - // CacheFrom specifies images that are used for matching cache. Images - // specified here do not need to have a valid parent chain to match cache. - CacheFrom []string - SecurityOpt []string -} - -// ImageBuildResponse holds information -// returned by a server after building -// an image. -type ImageBuildResponse struct { - Body io.ReadCloser - OSType string -} - -// ImageCreateOptions holds information to create images. -type ImageCreateOptions struct { - RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry -} - -// ImageImportSource holds source information for ImageImport -type ImageImportSource struct { - Source io.Reader // Source is the data to send to the server to create this image from (mutually exclusive with SourceName) - SourceName string // SourceName is the name of the image to pull (mutually exclusive with Source) -} - -// ImageImportOptions holds information to import images from the client host. -type ImageImportOptions struct { - Tag string // Tag is the name to tag this image with. This attribute is deprecated. - Message string // Message is the message to tag the image with - Changes []string // Changes are the raw changes to apply to this image -} - -// ImageListOptions holds parameters to filter the list of images with. -type ImageListOptions struct { - All bool - Filters filters.Args -} - -// ImageLoadResponse returns information to the client about a load process. -type ImageLoadResponse struct { - // Body must be closed to avoid a resource leak - Body io.ReadCloser - JSON bool -} - -// ImagePullOptions holds information to pull images. -type ImagePullOptions struct { - All bool - RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry - PrivilegeFunc RequestPrivilegeFunc -} - -// RequestPrivilegeFunc is a function interface that -// clients can supply to retry operations after -// getting an authorization error. -// This function returns the registry authentication -// header value in base 64 format, or an error -// if the privilege request fails. -type RequestPrivilegeFunc func() (string, error) - -//ImagePushOptions holds information to push images. -type ImagePushOptions ImagePullOptions - -// ImageRemoveOptions holds parameters to remove images. -type ImageRemoveOptions struct { - Force bool - PruneChildren bool -} - -// ImageSearchOptions holds parameters to search images with. -type ImageSearchOptions struct { - RegistryAuth string - PrivilegeFunc RequestPrivilegeFunc - Filters filters.Args - Limit int -} - -// ResizeOptions holds parameters to resize a tty. -// It can be used to resize container ttys and -// exec process ttys too. -type ResizeOptions struct { - Height uint - Width uint -} - -// VersionResponse holds version information for the client and the server -type VersionResponse struct { - Client *Version - Server *Version -} - -// ServerOK returns true when the client could connect to the docker server -// and parse the information received. It returns false otherwise. -func (v VersionResponse) ServerOK() bool { - return v.Server != nil -} - -// NodeListOptions holds parameters to list nodes with. -type NodeListOptions struct { - Filters filters.Args -} - -// NodeRemoveOptions holds parameters to remove nodes with. -type NodeRemoveOptions struct { - Force bool -} - -// ServiceCreateOptions contains the options to use when creating a service. -type ServiceCreateOptions struct { - // EncodedRegistryAuth is the encoded registry authorization credentials to - // use when updating the service. - // - // This field follows the format of the X-Registry-Auth header. - EncodedRegistryAuth string -} - -// ServiceCreateResponse contains the information returned to a client -// on the creation of a new service. -type ServiceCreateResponse struct { - // ID is the ID of the created service. - ID string - // Warnings is a set of non-fatal warning messages to pass on to the user. - Warnings []string `json:",omitempty"` -} - -// Values for RegistryAuthFrom in ServiceUpdateOptions -const ( - RegistryAuthFromSpec = "spec" - RegistryAuthFromPreviousSpec = "previous-spec" -) - -// ServiceUpdateOptions contains the options to be used for updating services. -type ServiceUpdateOptions struct { - // EncodedRegistryAuth is the encoded registry authorization credentials to - // use when updating the service. - // - // This field follows the format of the X-Registry-Auth header. - EncodedRegistryAuth string - - // TODO(stevvooe): Consider moving the version parameter of ServiceUpdate - // into this field. While it does open API users up to racy writes, most - // users may not need that level of consistency in practice. - - // RegistryAuthFrom specifies where to find the registry authorization - // credentials if they are not given in EncodedRegistryAuth. Valid - // values are "spec" and "previous-spec". - RegistryAuthFrom string -} - -// ServiceListOptions holds parameters to list services with. -type ServiceListOptions struct { - Filters filters.Args -} - -// TaskListOptions holds parameters to list tasks with. -type TaskListOptions struct { - Filters filters.Args -} - -// PluginRemoveOptions holds parameters to remove plugins. -type PluginRemoveOptions struct { - Force bool -} - -// PluginEnableOptions holds parameters to enable plugins. -type PluginEnableOptions struct { - Timeout int -} - -// PluginDisableOptions holds parameters to disable plugins. -type PluginDisableOptions struct { - Force bool -} - -// PluginInstallOptions holds parameters to install a plugin. -type PluginInstallOptions struct { - Disabled bool - AcceptAllPermissions bool - RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry - RemoteRef string // RemoteRef is the plugin name on the registry - PrivilegeFunc RequestPrivilegeFunc - AcceptPermissionsFunc func(PluginPrivileges) (bool, error) - Args []string -} - -// SecretRequestOption is a type for requesting secrets -type SecretRequestOption struct { - Source string - Target string - UID string - GID string - Mode os.FileMode -} - -// SwarmUnlockKeyResponse contains the response for Engine API: -// GET /swarm/unlockkey -type SwarmUnlockKeyResponse struct { - // UnlockKey is the unlock key in ASCII-armored format. - UnlockKey string -} - -// PluginCreateOptions hold all options to plugin create. -type PluginCreateOptions struct { - RepoName string -} diff --git a/vendor/github.com/docker/docker/api/types/configs.go b/vendor/github.com/docker/docker/api/types/configs.go deleted file mode 100644 index 20c19f2..0000000 --- a/vendor/github.com/docker/docker/api/types/configs.go +++ /dev/null @@ -1,69 +0,0 @@ -package types - -import ( - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/network" -) - -// configs holds structs used for internal communication between the -// frontend (such as an http server) and the backend (such as the -// docker daemon). - -// ContainerCreateConfig is the parameter set to ContainerCreate() -type ContainerCreateConfig struct { - Name string - Config *container.Config - HostConfig *container.HostConfig - NetworkingConfig *network.NetworkingConfig - AdjustCPUShares bool -} - -// ContainerRmConfig holds arguments for the container remove -// operation. This struct is used to tell the backend what operations -// to perform. -type ContainerRmConfig struct { - ForceRemove, RemoveVolume, RemoveLink bool -} - -// ContainerCommitConfig contains build configs for commit operation, -// and is used when making a commit with the current state of the container. -type ContainerCommitConfig struct { - Pause bool - Repo string - Tag string - Author string - Comment string - // merge container config into commit config before commit - MergeConfigs bool - Config *container.Config -} - -// ExecConfig is a small subset of the Config struct that holds the configuration -// for the exec feature of docker. -type ExecConfig struct { - User string // User that will run the command - Privileged bool // Is the container in privileged mode - Tty bool // Attach standard streams to a tty. - AttachStdin bool // Attach the standard input, makes possible user interaction - AttachStderr bool // Attach the standard error - AttachStdout bool // Attach the standard output - Detach bool // Execute in detach mode - DetachKeys string // Escape keys for detach - Env []string // Environment variables - Cmd []string // Execution commands and args -} - -// PluginRmConfig holds arguments for plugin remove. -type PluginRmConfig struct { - ForceRemove bool -} - -// PluginEnableConfig holds arguments for plugin enable -type PluginEnableConfig struct { - Timeout int -} - -// PluginDisableConfig holds arguments for plugin disable. -type PluginDisableConfig struct { - ForceDisable bool -} diff --git a/vendor/github.com/docker/docker/api/types/container/config.go b/vendor/github.com/docker/docker/api/types/container/config.go deleted file mode 100644 index fc050e5..0000000 --- a/vendor/github.com/docker/docker/api/types/container/config.go +++ /dev/null @@ -1,62 +0,0 @@ -package container - -import ( - "time" - - "github.com/docker/docker/api/types/strslice" - "github.com/docker/go-connections/nat" -) - -// HealthConfig holds configuration settings for the HEALTHCHECK feature. -type HealthConfig struct { - // Test is the test to perform to check that the container is healthy. - // An empty slice means to inherit the default. - // The options are: - // {} : inherit healthcheck - // {"NONE"} : disable healthcheck - // {"CMD", args...} : exec arguments directly - // {"CMD-SHELL", command} : run command with system's default shell - Test []string `json:",omitempty"` - - // Zero means to inherit. Durations are expressed as integer nanoseconds. - Interval time.Duration `json:",omitempty"` // Interval is the time to wait between checks. - Timeout time.Duration `json:",omitempty"` // Timeout is the time to wait before considering the check to have hung. - - // Retries is the number of consecutive failures needed to consider a container as unhealthy. - // Zero means inherit. - Retries int `json:",omitempty"` -} - -// Config contains the configuration data about a container. -// It should hold only portable information about the container. -// Here, "portable" means "independent from the host we are running on". -// Non-portable information *should* appear in HostConfig. -// All fields added to this struct must be marked `omitempty` to keep getting -// predictable hashes from the old `v1Compatibility` configuration. -type Config struct { - Hostname string // Hostname - Domainname string // Domainname - User string // User that will run the command(s) inside the container, also support user:group - AttachStdin bool // Attach the standard input, makes possible user interaction - AttachStdout bool // Attach the standard output - AttachStderr bool // Attach the standard error - ExposedPorts nat.PortSet `json:",omitempty"` // List of exposed ports - Tty bool // Attach standard streams to a tty, including stdin if it is not closed. - OpenStdin bool // Open stdin - StdinOnce bool // If true, close stdin after the 1 attached client disconnects. - Env []string // List of environment variable to set in the container - Cmd strslice.StrSlice // Command to run when starting the container - Healthcheck *HealthConfig `json:",omitempty"` // Healthcheck describes how to check the container is healthy - ArgsEscaped bool `json:",omitempty"` // True if command is already escaped (Windows specific) - Image string // Name of the image as it was passed by the operator (e.g. could be symbolic) - Volumes map[string]struct{} // List of volumes (mounts) used for the container - WorkingDir string // Current directory (PWD) in the command will be launched - Entrypoint strslice.StrSlice // Entrypoint to run when starting the container - NetworkDisabled bool `json:",omitempty"` // Is network disabled - MacAddress string `json:",omitempty"` // Mac Address of the container - OnBuild []string // ONBUILD metadata that were defined on the image Dockerfile - Labels map[string]string // List of labels set to this container - StopSignal string `json:",omitempty"` // Signal to stop a container - StopTimeout *int `json:",omitempty"` // Timeout (in seconds) to stop a container - Shell strslice.StrSlice `json:",omitempty"` // Shell for shell-form of RUN, CMD, ENTRYPOINT -} diff --git a/vendor/github.com/docker/docker/api/types/container/container_create.go b/vendor/github.com/docker/docker/api/types/container/container_create.go deleted file mode 100644 index d028e3b..0000000 --- a/vendor/github.com/docker/docker/api/types/container/container_create.go +++ /dev/null @@ -1,21 +0,0 @@ -package container - -// ---------------------------------------------------------------------------- -// DO NOT EDIT THIS FILE -// This file was generated by `swagger generate operation` -// -// See hack/swagger-gen.sh -// ---------------------------------------------------------------------------- - -// ContainerCreateCreatedBody container create created body -// swagger:model ContainerCreateCreatedBody -type ContainerCreateCreatedBody struct { - - // The ID of the created container - // Required: true - ID string `json:"Id"` - - // Warnings encountered when creating the container - // Required: true - Warnings []string `json:"Warnings"` -} diff --git a/vendor/github.com/docker/docker/api/types/container/container_update.go b/vendor/github.com/docker/docker/api/types/container/container_update.go deleted file mode 100644 index 81ee12c..0000000 --- a/vendor/github.com/docker/docker/api/types/container/container_update.go +++ /dev/null @@ -1,17 +0,0 @@ -package container - -// ---------------------------------------------------------------------------- -// DO NOT EDIT THIS FILE -// This file was generated by `swagger generate operation` -// -// See hack/swagger-gen.sh -// ---------------------------------------------------------------------------- - -// ContainerUpdateOKBody container update o k body -// swagger:model ContainerUpdateOKBody -type ContainerUpdateOKBody struct { - - // warnings - // Required: true - Warnings []string `json:"Warnings"` -} diff --git a/vendor/github.com/docker/docker/api/types/container/container_wait.go b/vendor/github.com/docker/docker/api/types/container/container_wait.go deleted file mode 100644 index 16cf335..0000000 --- a/vendor/github.com/docker/docker/api/types/container/container_wait.go +++ /dev/null @@ -1,17 +0,0 @@ -package container - -// ---------------------------------------------------------------------------- -// DO NOT EDIT THIS FILE -// This file was generated by `swagger generate operation` -// -// See hack/swagger-gen.sh -// ---------------------------------------------------------------------------- - -// ContainerWaitOKBody container wait o k body -// swagger:model ContainerWaitOKBody -type ContainerWaitOKBody struct { - - // Exit code of the container - // Required: true - StatusCode int64 `json:"StatusCode"` -} diff --git a/vendor/github.com/docker/docker/api/types/container/host_config.go b/vendor/github.com/docker/docker/api/types/container/host_config.go deleted file mode 100644 index 0c82d62..0000000 --- a/vendor/github.com/docker/docker/api/types/container/host_config.go +++ /dev/null @@ -1,333 +0,0 @@ -package container - -import ( - "strings" - - "github.com/docker/docker/api/types/blkiodev" - "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/api/types/strslice" - "github.com/docker/go-connections/nat" - "github.com/docker/go-units" -) - -// NetworkMode represents the container network stack. -type NetworkMode string - -// Isolation represents the isolation technology of a container. The supported -// values are platform specific -type Isolation string - -// IsDefault indicates the default isolation technology of a container. On Linux this -// is the native driver. On Windows, this is a Windows Server Container. -func (i Isolation) IsDefault() bool { - return strings.ToLower(string(i)) == "default" || string(i) == "" -} - -// IpcMode represents the container ipc stack. -type IpcMode string - -// IsPrivate indicates whether the container uses its private ipc stack. -func (n IpcMode) IsPrivate() bool { - return !(n.IsHost() || n.IsContainer()) -} - -// IsHost indicates whether the container uses the host's ipc stack. -func (n IpcMode) IsHost() bool { - return n == "host" -} - -// IsContainer indicates whether the container uses a container's ipc stack. -func (n IpcMode) IsContainer() bool { - parts := strings.SplitN(string(n), ":", 2) - return len(parts) > 1 && parts[0] == "container" -} - -// Valid indicates whether the ipc stack is valid. -func (n IpcMode) Valid() bool { - parts := strings.Split(string(n), ":") - switch mode := parts[0]; mode { - case "", "host": - case "container": - if len(parts) != 2 || parts[1] == "" { - return false - } - default: - return false - } - return true -} - -// Container returns the name of the container ipc stack is going to be used. -func (n IpcMode) Container() string { - parts := strings.SplitN(string(n), ":", 2) - if len(parts) > 1 { - return parts[1] - } - return "" -} - -// UsernsMode represents userns mode in the container. -type UsernsMode string - -// IsHost indicates whether the container uses the host's userns. -func (n UsernsMode) IsHost() bool { - return n == "host" -} - -// IsPrivate indicates whether the container uses the a private userns. -func (n UsernsMode) IsPrivate() bool { - return !(n.IsHost()) -} - -// Valid indicates whether the userns is valid. -func (n UsernsMode) Valid() bool { - parts := strings.Split(string(n), ":") - switch mode := parts[0]; mode { - case "", "host": - default: - return false - } - return true -} - -// CgroupSpec represents the cgroup to use for the container. -type CgroupSpec string - -// IsContainer indicates whether the container is using another container cgroup -func (c CgroupSpec) IsContainer() bool { - parts := strings.SplitN(string(c), ":", 2) - return len(parts) > 1 && parts[0] == "container" -} - -// Valid indicates whether the cgroup spec is valid. -func (c CgroupSpec) Valid() bool { - return c.IsContainer() || c == "" -} - -// Container returns the name of the container whose cgroup will be used. -func (c CgroupSpec) Container() string { - parts := strings.SplitN(string(c), ":", 2) - if len(parts) > 1 { - return parts[1] - } - return "" -} - -// UTSMode represents the UTS namespace of the container. -type UTSMode string - -// IsPrivate indicates whether the container uses its private UTS namespace. -func (n UTSMode) IsPrivate() bool { - return !(n.IsHost()) -} - -// IsHost indicates whether the container uses the host's UTS namespace. -func (n UTSMode) IsHost() bool { - return n == "host" -} - -// Valid indicates whether the UTS namespace is valid. -func (n UTSMode) Valid() bool { - parts := strings.Split(string(n), ":") - switch mode := parts[0]; mode { - case "", "host": - default: - return false - } - return true -} - -// PidMode represents the pid namespace of the container. -type PidMode string - -// IsPrivate indicates whether the container uses its own new pid namespace. -func (n PidMode) IsPrivate() bool { - return !(n.IsHost() || n.IsContainer()) -} - -// IsHost indicates whether the container uses the host's pid namespace. -func (n PidMode) IsHost() bool { - return n == "host" -} - -// IsContainer indicates whether the container uses a container's pid namespace. -func (n PidMode) IsContainer() bool { - parts := strings.SplitN(string(n), ":", 2) - return len(parts) > 1 && parts[0] == "container" -} - -// Valid indicates whether the pid namespace is valid. -func (n PidMode) Valid() bool { - parts := strings.Split(string(n), ":") - switch mode := parts[0]; mode { - case "", "host": - case "container": - if len(parts) != 2 || parts[1] == "" { - return false - } - default: - return false - } - return true -} - -// Container returns the name of the container whose pid namespace is going to be used. -func (n PidMode) Container() string { - parts := strings.SplitN(string(n), ":", 2) - if len(parts) > 1 { - return parts[1] - } - return "" -} - -// DeviceMapping represents the device mapping between the host and the container. -type DeviceMapping struct { - PathOnHost string - PathInContainer string - CgroupPermissions string -} - -// RestartPolicy represents the restart policies of the container. -type RestartPolicy struct { - Name string - MaximumRetryCount int -} - -// IsNone indicates whether the container has the "no" restart policy. -// This means the container will not automatically restart when exiting. -func (rp *RestartPolicy) IsNone() bool { - return rp.Name == "no" || rp.Name == "" -} - -// IsAlways indicates whether the container has the "always" restart policy. -// This means the container will automatically restart regardless of the exit status. -func (rp *RestartPolicy) IsAlways() bool { - return rp.Name == "always" -} - -// IsOnFailure indicates whether the container has the "on-failure" restart policy. -// This means the container will automatically restart of exiting with a non-zero exit status. -func (rp *RestartPolicy) IsOnFailure() bool { - return rp.Name == "on-failure" -} - -// IsUnlessStopped indicates whether the container has the -// "unless-stopped" restart policy. This means the container will -// automatically restart unless user has put it to stopped state. -func (rp *RestartPolicy) IsUnlessStopped() bool { - return rp.Name == "unless-stopped" -} - -// IsSame compares two RestartPolicy to see if they are the same -func (rp *RestartPolicy) IsSame(tp *RestartPolicy) bool { - return rp.Name == tp.Name && rp.MaximumRetryCount == tp.MaximumRetryCount -} - -// LogConfig represents the logging configuration of the container. -type LogConfig struct { - Type string - Config map[string]string -} - -// Resources contains container's resources (cgroups config, ulimits...) -type Resources struct { - // Applicable to all platforms - CPUShares int64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers) - Memory int64 // Memory limit (in bytes) - NanoCPUs int64 `json:"NanoCpus"` // CPU quota in units of 10-9 CPUs. - - // Applicable to UNIX platforms - CgroupParent string // Parent cgroup. - BlkioWeight uint16 // Block IO weight (relative weight vs. other containers) - BlkioWeightDevice []*blkiodev.WeightDevice - BlkioDeviceReadBps []*blkiodev.ThrottleDevice - BlkioDeviceWriteBps []*blkiodev.ThrottleDevice - BlkioDeviceReadIOps []*blkiodev.ThrottleDevice - BlkioDeviceWriteIOps []*blkiodev.ThrottleDevice - CPUPeriod int64 `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period - CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota - CPURealtimePeriod int64 `json:"CpuRealtimePeriod"` // CPU real-time period - CPURealtimeRuntime int64 `json:"CpuRealtimeRuntime"` // CPU real-time runtime - CpusetCpus string // CpusetCpus 0-2, 0,1 - CpusetMems string // CpusetMems 0-2, 0,1 - Devices []DeviceMapping // List of devices to map inside the container - DiskQuota int64 // Disk limit (in bytes) - KernelMemory int64 // Kernel memory limit (in bytes) - MemoryReservation int64 // Memory soft limit (in bytes) - MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap - MemorySwappiness *int64 // Tuning container memory swappiness behaviour - OomKillDisable *bool // Whether to disable OOM Killer or not - PidsLimit int64 // Setting pids limit for a container - Ulimits []*units.Ulimit // List of ulimits to be set in the container - - // Applicable to Windows - CPUCount int64 `json:"CpuCount"` // CPU count - CPUPercent int64 `json:"CpuPercent"` // CPU percent - IOMaximumIOps uint64 // Maximum IOps for the container system drive - IOMaximumBandwidth uint64 // Maximum IO in bytes per second for the container system drive -} - -// UpdateConfig holds the mutable attributes of a Container. -// Those attributes can be updated at runtime. -type UpdateConfig struct { - // Contains container's resources (cgroups, ulimits) - Resources - RestartPolicy RestartPolicy -} - -// HostConfig the non-portable Config structure of a container. -// Here, "non-portable" means "dependent of the host we are running on". -// Portable information *should* appear in Config. -type HostConfig struct { - // Applicable to all platforms - Binds []string // List of volume bindings for this container - ContainerIDFile string // File (path) where the containerId is written - LogConfig LogConfig // Configuration of the logs for this container - NetworkMode NetworkMode // Network mode to use for the container - PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host - RestartPolicy RestartPolicy // Restart policy to be used for the container - AutoRemove bool // Automatically remove container when it exits - VolumeDriver string // Name of the volume driver used to mount volumes - VolumesFrom []string // List of volumes to take from other container - - // Applicable to UNIX platforms - CapAdd strslice.StrSlice // List of kernel capabilities to add to the container - CapDrop strslice.StrSlice // List of kernel capabilities to remove from the container - DNS []string `json:"Dns"` // List of DNS server to lookup - DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for - DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for - ExtraHosts []string // List of extra hosts - GroupAdd []string // List of additional groups that the container process will run as - IpcMode IpcMode // IPC namespace to use for the container - Cgroup CgroupSpec // Cgroup to use for the container - Links []string // List of links (in the name:alias form) - OomScoreAdj int // Container preference for OOM-killing - PidMode PidMode // PID namespace to use for the container - Privileged bool // Is the container in privileged mode - PublishAllPorts bool // Should docker publish all exposed port for the container - ReadonlyRootfs bool // Is the container root filesystem in read-only - SecurityOpt []string // List of string values to customize labels for MLS systems, such as SELinux. - StorageOpt map[string]string `json:",omitempty"` // Storage driver options per container. - Tmpfs map[string]string `json:",omitempty"` // List of tmpfs (mounts) used for the container - UTSMode UTSMode // UTS namespace to use for the container - UsernsMode UsernsMode // The user namespace to use for the container - ShmSize int64 // Total shm memory usage - Sysctls map[string]string `json:",omitempty"` // List of Namespaced sysctls used for the container - Runtime string `json:",omitempty"` // Runtime to use with this container - - // Applicable to Windows - ConsoleSize [2]uint // Initial console size (height,width) - Isolation Isolation // Isolation technology of the container (eg default, hyperv) - - // Contains container's resources (cgroups, ulimits) - Resources - - // Mounts specs used by the container - Mounts []mount.Mount `json:",omitempty"` - - // Run a custom init inside the container, if null, use the daemon's configured settings - Init *bool `json:",omitempty"` - - // Custom init path - InitPath string `json:",omitempty"` -} diff --git a/vendor/github.com/docker/docker/api/types/container/hostconfig_unix.go b/vendor/github.com/docker/docker/api/types/container/hostconfig_unix.go deleted file mode 100644 index 9fb79be..0000000 --- a/vendor/github.com/docker/docker/api/types/container/hostconfig_unix.go +++ /dev/null @@ -1,81 +0,0 @@ -// +build !windows - -package container - -import "strings" - -// IsValid indicates if an isolation technology is valid -func (i Isolation) IsValid() bool { - return i.IsDefault() -} - -// IsPrivate indicates whether container uses its private network stack. -func (n NetworkMode) IsPrivate() bool { - return !(n.IsHost() || n.IsContainer()) -} - -// IsDefault indicates whether container uses the default network stack. -func (n NetworkMode) IsDefault() bool { - return n == "default" -} - -// NetworkName returns the name of the network stack. -func (n NetworkMode) NetworkName() string { - if n.IsBridge() { - return "bridge" - } else if n.IsHost() { - return "host" - } else if n.IsContainer() { - return "container" - } else if n.IsNone() { - return "none" - } else if n.IsDefault() { - return "default" - } else if n.IsUserDefined() { - return n.UserDefined() - } - return "" -} - -// IsBridge indicates whether container uses the bridge network stack -func (n NetworkMode) IsBridge() bool { - return n == "bridge" -} - -// IsHost indicates whether container uses the host network stack. -func (n NetworkMode) IsHost() bool { - return n == "host" -} - -// IsContainer indicates whether container uses a container network stack. -func (n NetworkMode) IsContainer() bool { - parts := strings.SplitN(string(n), ":", 2) - return len(parts) > 1 && parts[0] == "container" -} - -// IsNone indicates whether container isn't using a network stack. -func (n NetworkMode) IsNone() bool { - return n == "none" -} - -// ConnectedContainer is the id of the container which network this container is connected to. -func (n NetworkMode) ConnectedContainer() string { - parts := strings.SplitN(string(n), ":", 2) - if len(parts) > 1 { - return parts[1] - } - return "" -} - -// IsUserDefined indicates user-created network -func (n NetworkMode) IsUserDefined() bool { - return !n.IsDefault() && !n.IsBridge() && !n.IsHost() && !n.IsNone() && !n.IsContainer() -} - -//UserDefined indicates user-created network -func (n NetworkMode) UserDefined() string { - if n.IsUserDefined() { - return string(n) - } - return "" -} diff --git a/vendor/github.com/docker/docker/api/types/container/hostconfig_windows.go b/vendor/github.com/docker/docker/api/types/container/hostconfig_windows.go deleted file mode 100644 index 0ee332b..0000000 --- a/vendor/github.com/docker/docker/api/types/container/hostconfig_windows.go +++ /dev/null @@ -1,87 +0,0 @@ -package container - -import ( - "strings" -) - -// IsDefault indicates whether container uses the default network stack. -func (n NetworkMode) IsDefault() bool { - return n == "default" -} - -// IsNone indicates whether container isn't using a network stack. -func (n NetworkMode) IsNone() bool { - return n == "none" -} - -// IsContainer indicates whether container uses a container network stack. -// Returns false as windows doesn't support this mode -func (n NetworkMode) IsContainer() bool { - return false -} - -// IsBridge indicates whether container uses the bridge network stack -// in windows it is given the name NAT -func (n NetworkMode) IsBridge() bool { - return n == "nat" -} - -// IsHost indicates whether container uses the host network stack. -// returns false as this is not supported by windows -func (n NetworkMode) IsHost() bool { - return false -} - -// IsPrivate indicates whether container uses its private network stack. -func (n NetworkMode) IsPrivate() bool { - return !(n.IsHost() || n.IsContainer()) -} - -// ConnectedContainer is the id of the container which network this container is connected to. -// Returns blank string on windows -func (n NetworkMode) ConnectedContainer() string { - return "" -} - -// IsUserDefined indicates user-created network -func (n NetworkMode) IsUserDefined() bool { - return !n.IsDefault() && !n.IsNone() && !n.IsBridge() -} - -// IsHyperV indicates the use of a Hyper-V partition for isolation -func (i Isolation) IsHyperV() bool { - return strings.ToLower(string(i)) == "hyperv" -} - -// IsProcess indicates the use of process isolation -func (i Isolation) IsProcess() bool { - return strings.ToLower(string(i)) == "process" -} - -// IsValid indicates if an isolation technology is valid -func (i Isolation) IsValid() bool { - return i.IsDefault() || i.IsHyperV() || i.IsProcess() -} - -// NetworkName returns the name of the network stack. -func (n NetworkMode) NetworkName() string { - if n.IsDefault() { - return "default" - } else if n.IsBridge() { - return "nat" - } else if n.IsNone() { - return "none" - } else if n.IsUserDefined() { - return n.UserDefined() - } - - return "" -} - -//UserDefined indicates user-created network -func (n NetworkMode) UserDefined() string { - if n.IsUserDefined() { - return string(n) - } - return "" -} diff --git a/vendor/github.com/docker/docker/api/types/error_response.go b/vendor/github.com/docker/docker/api/types/error_response.go deleted file mode 100644 index dc942d9..0000000 --- a/vendor/github.com/docker/docker/api/types/error_response.go +++ /dev/null @@ -1,13 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// ErrorResponse Represents an error. -// swagger:model ErrorResponse -type ErrorResponse struct { - - // The error message. - // Required: true - Message string `json:"message"` -} diff --git a/vendor/github.com/docker/docker/api/types/events/events.go b/vendor/github.com/docker/docker/api/types/events/events.go deleted file mode 100644 index 7129a65..0000000 --- a/vendor/github.com/docker/docker/api/types/events/events.go +++ /dev/null @@ -1,42 +0,0 @@ -package events - -const ( - // ContainerEventType is the event type that containers generate - ContainerEventType = "container" - // DaemonEventType is the event type that daemon generate - DaemonEventType = "daemon" - // ImageEventType is the event type that images generate - ImageEventType = "image" - // NetworkEventType is the event type that networks generate - NetworkEventType = "network" - // PluginEventType is the event type that plugins generate - PluginEventType = "plugin" - // VolumeEventType is the event type that volumes generate - VolumeEventType = "volume" -) - -// Actor describes something that generates events, -// like a container, or a network, or a volume. -// It has a defined name and a set or attributes. -// The container attributes are its labels, other actors -// can generate these attributes from other properties. -type Actor struct { - ID string - Attributes map[string]string -} - -// Message represents the information an event contains -type Message struct { - // Deprecated information from JSONMessage. - // With data only in container events. - Status string `json:"status,omitempty"` - ID string `json:"id,omitempty"` - From string `json:"from,omitempty"` - - Type string - Action string - Actor Actor - - Time int64 `json:"time,omitempty"` - TimeNano int64 `json:"timeNano,omitempty"` -} diff --git a/vendor/github.com/docker/docker/api/types/filters/parse.go b/vendor/github.com/docker/docker/api/types/filters/parse.go deleted file mode 100644 index e01a41d..0000000 --- a/vendor/github.com/docker/docker/api/types/filters/parse.go +++ /dev/null @@ -1,310 +0,0 @@ -// Package filters provides helper function to parse and handle command line -// filter, used for example in docker ps or docker images commands. -package filters - -import ( - "encoding/json" - "errors" - "fmt" - "regexp" - "strings" - - "github.com/docker/docker/api/types/versions" -) - -// Args stores filter arguments as map key:{map key: bool}. -// It contains an aggregation of the map of arguments (which are in the form -// of -f 'key=value') based on the key, and stores values for the same key -// in a map with string keys and boolean values. -// e.g given -f 'label=label1=1' -f 'label=label2=2' -f 'image.name=ubuntu' -// the args will be {"image.name":{"ubuntu":true},"label":{"label1=1":true,"label2=2":true}} -type Args struct { - fields map[string]map[string]bool -} - -// NewArgs initializes a new Args struct. -func NewArgs() Args { - return Args{fields: map[string]map[string]bool{}} -} - -// ParseFlag parses the argument to the filter flag. Like -// -// `docker ps -f 'created=today' -f 'image.name=ubuntu*'` -// -// If prev map is provided, then it is appended to, and returned. By default a new -// map is created. -func ParseFlag(arg string, prev Args) (Args, error) { - filters := prev - if len(arg) == 0 { - return filters, nil - } - - if !strings.Contains(arg, "=") { - return filters, ErrBadFormat - } - - f := strings.SplitN(arg, "=", 2) - - name := strings.ToLower(strings.TrimSpace(f[0])) - value := strings.TrimSpace(f[1]) - - filters.Add(name, value) - - return filters, nil -} - -// ErrBadFormat is an error returned in case of bad format for a filter. -var ErrBadFormat = errors.New("bad format of filter (expected name=value)") - -// ToParam packs the Args into a string for easy transport from client to server. -func ToParam(a Args) (string, error) { - // this way we don't URL encode {}, just empty space - if a.Len() == 0 { - return "", nil - } - - buf, err := json.Marshal(a.fields) - if err != nil { - return "", err - } - return string(buf), nil -} - -// ToParamWithVersion packs the Args into a string for easy transport from client to server. -// The generated string will depend on the specified version (corresponding to the API version). -func ToParamWithVersion(version string, a Args) (string, error) { - // this way we don't URL encode {}, just empty space - if a.Len() == 0 { - return "", nil - } - - // for daemons older than v1.10, filter must be of the form map[string][]string - buf := []byte{} - err := errors.New("") - if version != "" && versions.LessThan(version, "1.22") { - buf, err = json.Marshal(convertArgsToSlice(a.fields)) - } else { - buf, err = json.Marshal(a.fields) - } - if err != nil { - return "", err - } - return string(buf), nil -} - -// FromParam unpacks the filter Args. -func FromParam(p string) (Args, error) { - if len(p) == 0 { - return NewArgs(), nil - } - - r := strings.NewReader(p) - d := json.NewDecoder(r) - - m := map[string]map[string]bool{} - if err := d.Decode(&m); err != nil { - r.Seek(0, 0) - - // Allow parsing old arguments in slice format. - // Because other libraries might be sending them in this format. - deprecated := map[string][]string{} - if deprecatedErr := d.Decode(&deprecated); deprecatedErr == nil { - m = deprecatedArgs(deprecated) - } else { - return NewArgs(), err - } - } - return Args{m}, nil -} - -// Get returns the list of values associates with a field. -// It returns a slice of strings to keep backwards compatibility with old code. -func (filters Args) Get(field string) []string { - values := filters.fields[field] - if values == nil { - return make([]string, 0) - } - slice := make([]string, 0, len(values)) - for key := range values { - slice = append(slice, key) - } - return slice -} - -// Add adds a new value to a filter field. -func (filters Args) Add(name, value string) { - if _, ok := filters.fields[name]; ok { - filters.fields[name][value] = true - } else { - filters.fields[name] = map[string]bool{value: true} - } -} - -// Del removes a value from a filter field. -func (filters Args) Del(name, value string) { - if _, ok := filters.fields[name]; ok { - delete(filters.fields[name], value) - if len(filters.fields[name]) == 0 { - delete(filters.fields, name) - } - } -} - -// Len returns the number of fields in the arguments. -func (filters Args) Len() int { - return len(filters.fields) -} - -// MatchKVList returns true if the values for the specified field matches the ones -// from the sources. -// e.g. given Args are {'label': {'label1=1','label2=1'}, 'image.name', {'ubuntu'}}, -// field is 'label' and sources are {'label1': '1', 'label2': '2'} -// it returns true. -func (filters Args) MatchKVList(field string, sources map[string]string) bool { - fieldValues := filters.fields[field] - - //do not filter if there is no filter set or cannot determine filter - if len(fieldValues) == 0 { - return true - } - - if len(sources) == 0 { - return false - } - - for name2match := range fieldValues { - testKV := strings.SplitN(name2match, "=", 2) - - v, ok := sources[testKV[0]] - if !ok { - return false - } - if len(testKV) == 2 && testKV[1] != v { - return false - } - } - - return true -} - -// Match returns true if the values for the specified field matches the source string -// e.g. given Args are {'label': {'label1=1','label2=1'}, 'image.name', {'ubuntu'}}, -// field is 'image.name' and source is 'ubuntu' -// it returns true. -func (filters Args) Match(field, source string) bool { - if filters.ExactMatch(field, source) { - return true - } - - fieldValues := filters.fields[field] - for name2match := range fieldValues { - match, err := regexp.MatchString(name2match, source) - if err != nil { - continue - } - if match { - return true - } - } - return false -} - -// ExactMatch returns true if the source matches exactly one of the filters. -func (filters Args) ExactMatch(field, source string) bool { - fieldValues, ok := filters.fields[field] - //do not filter if there is no filter set or cannot determine filter - if !ok || len(fieldValues) == 0 { - return true - } - - // try to match full name value to avoid O(N) regular expression matching - return fieldValues[source] -} - -// UniqueExactMatch returns true if there is only one filter and the source matches exactly this one. -func (filters Args) UniqueExactMatch(field, source string) bool { - fieldValues := filters.fields[field] - //do not filter if there is no filter set or cannot determine filter - if len(fieldValues) == 0 { - return true - } - if len(filters.fields[field]) != 1 { - return false - } - - // try to match full name value to avoid O(N) regular expression matching - return fieldValues[source] -} - -// FuzzyMatch returns true if the source matches exactly one of the filters, -// or the source has one of the filters as a prefix. -func (filters Args) FuzzyMatch(field, source string) bool { - if filters.ExactMatch(field, source) { - return true - } - - fieldValues := filters.fields[field] - for prefix := range fieldValues { - if strings.HasPrefix(source, prefix) { - return true - } - } - return false -} - -// Include returns true if the name of the field to filter is in the filters. -func (filters Args) Include(field string) bool { - _, ok := filters.fields[field] - return ok -} - -// Validate ensures that all the fields in the filter are valid. -// It returns an error as soon as it finds an invalid field. -func (filters Args) Validate(accepted map[string]bool) error { - for name := range filters.fields { - if !accepted[name] { - return fmt.Errorf("Invalid filter '%s'", name) - } - } - return nil -} - -// WalkValues iterates over the list of filtered values for a field. -// It stops the iteration if it finds an error and it returns that error. -func (filters Args) WalkValues(field string, op func(value string) error) error { - if _, ok := filters.fields[field]; !ok { - return nil - } - for v := range filters.fields[field] { - if err := op(v); err != nil { - return err - } - } - return nil -} - -func deprecatedArgs(d map[string][]string) map[string]map[string]bool { - m := map[string]map[string]bool{} - for k, v := range d { - values := map[string]bool{} - for _, vv := range v { - values[vv] = true - } - m[k] = values - } - return m -} - -func convertArgsToSlice(f map[string]map[string]bool) map[string][]string { - m := map[string][]string{} - for k, v := range f { - values := []string{} - for kk := range v { - if v[kk] { - values = append(values, kk) - } - } - m[k] = values - } - return m -} diff --git a/vendor/github.com/docker/docker/api/types/filters/parse_test.go b/vendor/github.com/docker/docker/api/types/filters/parse_test.go deleted file mode 100644 index b2ed27b..0000000 --- a/vendor/github.com/docker/docker/api/types/filters/parse_test.go +++ /dev/null @@ -1,417 +0,0 @@ -package filters - -import ( - "fmt" - "testing" -) - -func TestParseArgs(t *testing.T) { - // equivalent of `docker ps -f 'created=today' -f 'image.name=ubuntu*' -f 'image.name=*untu'` - flagArgs := []string{ - "created=today", - "image.name=ubuntu*", - "image.name=*untu", - } - var ( - args = NewArgs() - err error - ) - for i := range flagArgs { - args, err = ParseFlag(flagArgs[i], args) - if err != nil { - t.Errorf("failed to parse %s: %s", flagArgs[i], err) - } - } - if len(args.Get("created")) != 1 { - t.Errorf("failed to set this arg") - } - if len(args.Get("image.name")) != 2 { - t.Errorf("the args should have collapsed") - } -} - -func TestParseArgsEdgeCase(t *testing.T) { - var filters Args - args, err := ParseFlag("", filters) - if err != nil { - t.Fatal(err) - } - if args.Len() != 0 { - t.Fatalf("Expected an empty Args (map), got %v", args) - } - if args, err = ParseFlag("anything", args); err == nil || err != ErrBadFormat { - t.Fatalf("Expected ErrBadFormat, got %v", err) - } -} - -func TestToParam(t *testing.T) { - fields := map[string]map[string]bool{ - "created": {"today": true}, - "image.name": {"ubuntu*": true, "*untu": true}, - } - a := Args{fields: fields} - - _, err := ToParam(a) - if err != nil { - t.Errorf("failed to marshal the filters: %s", err) - } -} - -func TestToParamWithVersion(t *testing.T) { - fields := map[string]map[string]bool{ - "created": {"today": true}, - "image.name": {"ubuntu*": true, "*untu": true}, - } - a := Args{fields: fields} - - str1, err := ToParamWithVersion("1.21", a) - if err != nil { - t.Errorf("failed to marshal the filters with version < 1.22: %s", err) - } - str2, err := ToParamWithVersion("1.22", a) - if err != nil { - t.Errorf("failed to marshal the filters with version >= 1.22: %s", err) - } - if str1 != `{"created":["today"],"image.name":["*untu","ubuntu*"]}` && - str1 != `{"created":["today"],"image.name":["ubuntu*","*untu"]}` { - t.Errorf("incorrectly marshaled the filters: %s", str1) - } - if str2 != `{"created":{"today":true},"image.name":{"*untu":true,"ubuntu*":true}}` && - str2 != `{"created":{"today":true},"image.name":{"ubuntu*":true,"*untu":true}}` { - t.Errorf("incorrectly marshaled the filters: %s", str2) - } -} - -func TestFromParam(t *testing.T) { - invalids := []string{ - "anything", - "['a','list']", - "{'key': 'value'}", - `{"key": "value"}`, - } - valid := map[*Args][]string{ - &Args{fields: map[string]map[string]bool{"key": {"value": true}}}: { - `{"key": ["value"]}`, - `{"key": {"value": true}}`, - }, - &Args{fields: map[string]map[string]bool{"key": {"value1": true, "value2": true}}}: { - `{"key": ["value1", "value2"]}`, - `{"key": {"value1": true, "value2": true}}`, - }, - &Args{fields: map[string]map[string]bool{"key1": {"value1": true}, "key2": {"value2": true}}}: { - `{"key1": ["value1"], "key2": ["value2"]}`, - `{"key1": {"value1": true}, "key2": {"value2": true}}`, - }, - } - - for _, invalid := range invalids { - if _, err := FromParam(invalid); err == nil { - t.Fatalf("Expected an error with %v, got nothing", invalid) - } - } - - for expectedArgs, matchers := range valid { - for _, json := range matchers { - args, err := FromParam(json) - if err != nil { - t.Fatal(err) - } - if args.Len() != expectedArgs.Len() { - t.Fatalf("Expected %v, go %v", expectedArgs, args) - } - for key, expectedValues := range expectedArgs.fields { - values := args.Get(key) - - if len(values) != len(expectedValues) { - t.Fatalf("Expected %v, go %v", expectedArgs, args) - } - - for _, v := range values { - if !expectedValues[v] { - t.Fatalf("Expected %v, go %v", expectedArgs, args) - } - } - } - } - } -} - -func TestEmpty(t *testing.T) { - a := Args{} - v, err := ToParam(a) - if err != nil { - t.Errorf("failed to marshal the filters: %s", err) - } - v1, err := FromParam(v) - if err != nil { - t.Errorf("%s", err) - } - if a.Len() != v1.Len() { - t.Errorf("these should both be empty sets") - } -} - -func TestArgsMatchKVListEmptySources(t *testing.T) { - args := NewArgs() - if !args.MatchKVList("created", map[string]string{}) { - t.Fatalf("Expected true for (%v,created), got true", args) - } - - args = Args{map[string]map[string]bool{"created": {"today": true}}} - if args.MatchKVList("created", map[string]string{}) { - t.Fatalf("Expected false for (%v,created), got true", args) - } -} - -func TestArgsMatchKVList(t *testing.T) { - // Not empty sources - sources := map[string]string{ - "key1": "value1", - "key2": "value2", - "key3": "value3", - } - - matches := map[*Args]string{ - &Args{}: "field", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"today": true}, - "labels": map[string]bool{"key1": true}}, - }: "labels", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"today": true}, - "labels": map[string]bool{"key1=value1": true}}, - }: "labels", - } - - for args, field := range matches { - if args.MatchKVList(field, sources) != true { - t.Fatalf("Expected true for %v on %v, got false", sources, args) - } - } - - differs := map[*Args]string{ - &Args{map[string]map[string]bool{ - "created": map[string]bool{"today": true}}, - }: "created", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"today": true}, - "labels": map[string]bool{"key4": true}}, - }: "labels", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"today": true}, - "labels": map[string]bool{"key1=value3": true}}, - }: "labels", - } - - for args, field := range differs { - if args.MatchKVList(field, sources) != false { - t.Fatalf("Expected false for %v on %v, got true", sources, args) - } - } -} - -func TestArgsMatch(t *testing.T) { - source := "today" - - matches := map[*Args]string{ - &Args{}: "field", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"today": true}}, - }: "today", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"to*": true}}, - }: "created", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"to(.*)": true}}, - }: "created", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"tod": true}}, - }: "created", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"anyting": true, "to*": true}}, - }: "created", - } - - for args, field := range matches { - if args.Match(field, source) != true { - t.Fatalf("Expected true for %v on %v, got false", source, args) - } - } - - differs := map[*Args]string{ - &Args{map[string]map[string]bool{ - "created": map[string]bool{"tomorrow": true}}, - }: "created", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"to(day": true}}, - }: "created", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"tom(.*)": true}}, - }: "created", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"tom": true}}, - }: "created", - &Args{map[string]map[string]bool{ - "created": map[string]bool{"today1": true}, - "labels": map[string]bool{"today": true}}, - }: "created", - } - - for args, field := range differs { - if args.Match(field, source) != false { - t.Fatalf("Expected false for %v on %v, got true", source, args) - } - } -} - -func TestAdd(t *testing.T) { - f := NewArgs() - f.Add("status", "running") - v := f.fields["status"] - if len(v) != 1 || !v["running"] { - t.Fatalf("Expected to include a running status, got %v", v) - } - - f.Add("status", "paused") - if len(v) != 2 || !v["paused"] { - t.Fatalf("Expected to include a paused status, got %v", v) - } -} - -func TestDel(t *testing.T) { - f := NewArgs() - f.Add("status", "running") - f.Del("status", "running") - v := f.fields["status"] - if v["running"] { - t.Fatalf("Expected to not include a running status filter, got true") - } -} - -func TestLen(t *testing.T) { - f := NewArgs() - if f.Len() != 0 { - t.Fatalf("Expected to not include any field") - } - f.Add("status", "running") - if f.Len() != 1 { - t.Fatalf("Expected to include one field") - } -} - -func TestExactMatch(t *testing.T) { - f := NewArgs() - - if !f.ExactMatch("status", "running") { - t.Fatalf("Expected to match `running` when there are no filters, got false") - } - - f.Add("status", "running") - f.Add("status", "pause*") - - if !f.ExactMatch("status", "running") { - t.Fatalf("Expected to match `running` with one of the filters, got false") - } - - if f.ExactMatch("status", "paused") { - t.Fatalf("Expected to not match `paused` with one of the filters, got true") - } -} - -func TestOnlyOneExactMatch(t *testing.T) { - f := NewArgs() - - if !f.UniqueExactMatch("status", "running") { - t.Fatalf("Expected to match `running` when there are no filters, got false") - } - - f.Add("status", "running") - - if !f.UniqueExactMatch("status", "running") { - t.Fatalf("Expected to match `running` with one of the filters, got false") - } - - if f.UniqueExactMatch("status", "paused") { - t.Fatalf("Expected to not match `paused` with one of the filters, got true") - } - - f.Add("status", "pause") - if f.UniqueExactMatch("status", "running") { - t.Fatalf("Expected to not match only `running` with two filters, got true") - } -} - -func TestInclude(t *testing.T) { - f := NewArgs() - if f.Include("status") { - t.Fatalf("Expected to not include a status key, got true") - } - f.Add("status", "running") - if !f.Include("status") { - t.Fatalf("Expected to include a status key, got false") - } -} - -func TestValidate(t *testing.T) { - f := NewArgs() - f.Add("status", "running") - - valid := map[string]bool{ - "status": true, - "dangling": true, - } - - if err := f.Validate(valid); err != nil { - t.Fatal(err) - } - - f.Add("bogus", "running") - if err := f.Validate(valid); err == nil { - t.Fatalf("Expected to return an error, got nil") - } -} - -func TestWalkValues(t *testing.T) { - f := NewArgs() - f.Add("status", "running") - f.Add("status", "paused") - - f.WalkValues("status", func(value string) error { - if value != "running" && value != "paused" { - t.Fatalf("Unexpected value %s", value) - } - return nil - }) - - err := f.WalkValues("status", func(value string) error { - return fmt.Errorf("return") - }) - if err == nil { - t.Fatalf("Expected to get an error, got nil") - } - - err = f.WalkValues("foo", func(value string) error { - return fmt.Errorf("return") - }) - if err != nil { - t.Fatalf("Expected to not iterate when the field doesn't exist, got %v", err) - } -} - -func TestFuzzyMatch(t *testing.T) { - f := NewArgs() - f.Add("container", "foo") - - cases := map[string]bool{ - "foo": true, - "foobar": true, - "barfoo": false, - "bar": false, - } - for source, match := range cases { - got := f.FuzzyMatch("container", source) - if got != match { - t.Fatalf("Expected %v, got %v: %s", match, got, source) - } - } -} diff --git a/vendor/github.com/docker/docker/api/types/id_response.go b/vendor/github.com/docker/docker/api/types/id_response.go deleted file mode 100644 index 7592d2f..0000000 --- a/vendor/github.com/docker/docker/api/types/id_response.go +++ /dev/null @@ -1,13 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// IDResponse Response to an API call that returns just an Id -// swagger:model IdResponse -type IDResponse struct { - - // The id of the newly created object. - // Required: true - ID string `json:"Id"` -} diff --git a/vendor/github.com/docker/docker/api/types/image_summary.go b/vendor/github.com/docker/docker/api/types/image_summary.go deleted file mode 100644 index e145b3d..0000000 --- a/vendor/github.com/docker/docker/api/types/image_summary.go +++ /dev/null @@ -1,49 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// ImageSummary image summary -// swagger:model ImageSummary -type ImageSummary struct { - - // containers - // Required: true - Containers int64 `json:"Containers"` - - // created - // Required: true - Created int64 `json:"Created"` - - // Id - // Required: true - ID string `json:"Id"` - - // labels - // Required: true - Labels map[string]string `json:"Labels"` - - // parent Id - // Required: true - ParentID string `json:"ParentId"` - - // repo digests - // Required: true - RepoDigests []string `json:"RepoDigests"` - - // repo tags - // Required: true - RepoTags []string `json:"RepoTags"` - - // shared size - // Required: true - SharedSize int64 `json:"SharedSize"` - - // size - // Required: true - Size int64 `json:"Size"` - - // virtual size - // Required: true - VirtualSize int64 `json:"VirtualSize"` -} diff --git a/vendor/github.com/docker/docker/api/types/mount/mount.go b/vendor/github.com/docker/docker/api/types/mount/mount.go deleted file mode 100644 index 31f2365..0000000 --- a/vendor/github.com/docker/docker/api/types/mount/mount.go +++ /dev/null @@ -1,113 +0,0 @@ -package mount - -import ( - "os" -) - -// Type represents the type of a mount. -type Type string - -// Type constants -const ( - // TypeBind is the type for mounting host dir - TypeBind Type = "bind" - // TypeVolume is the type for remote storage volumes - TypeVolume Type = "volume" - // TypeTmpfs is the type for mounting tmpfs - TypeTmpfs Type = "tmpfs" -) - -// Mount represents a mount (volume). -type Mount struct { - Type Type `json:",omitempty"` - // Source specifies the name of the mount. Depending on mount type, this - // may be a volume name or a host path, or even ignored. - // Source is not supported for tmpfs (must be an empty value) - Source string `json:",omitempty"` - Target string `json:",omitempty"` - ReadOnly bool `json:",omitempty"` - - BindOptions *BindOptions `json:",omitempty"` - VolumeOptions *VolumeOptions `json:",omitempty"` - TmpfsOptions *TmpfsOptions `json:",omitempty"` -} - -// Propagation represents the propagation of a mount. -type Propagation string - -const ( - // PropagationRPrivate RPRIVATE - PropagationRPrivate Propagation = "rprivate" - // PropagationPrivate PRIVATE - PropagationPrivate Propagation = "private" - // PropagationRShared RSHARED - PropagationRShared Propagation = "rshared" - // PropagationShared SHARED - PropagationShared Propagation = "shared" - // PropagationRSlave RSLAVE - PropagationRSlave Propagation = "rslave" - // PropagationSlave SLAVE - PropagationSlave Propagation = "slave" -) - -// Propagations is the list of all valid mount propagations -var Propagations = []Propagation{ - PropagationRPrivate, - PropagationPrivate, - PropagationRShared, - PropagationShared, - PropagationRSlave, - PropagationSlave, -} - -// BindOptions defines options specific to mounts of type "bind". -type BindOptions struct { - Propagation Propagation `json:",omitempty"` -} - -// VolumeOptions represents the options for a mount of type volume. -type VolumeOptions struct { - NoCopy bool `json:",omitempty"` - Labels map[string]string `json:",omitempty"` - DriverConfig *Driver `json:",omitempty"` -} - -// Driver represents a volume driver. -type Driver struct { - Name string `json:",omitempty"` - Options map[string]string `json:",omitempty"` -} - -// TmpfsOptions defines options specific to mounts of type "tmpfs". -type TmpfsOptions struct { - // Size sets the size of the tmpfs, in bytes. - // - // This will be converted to an operating system specific value - // depending on the host. For example, on linux, it will be convered to - // use a 'k', 'm' or 'g' syntax. BSD, though not widely supported with - // docker, uses a straight byte value. - // - // Percentages are not supported. - SizeBytes int64 `json:",omitempty"` - // Mode of the tmpfs upon creation - Mode os.FileMode `json:",omitempty"` - - // TODO(stevvooe): There are several more tmpfs flags, specified in the - // daemon, that are accepted. Only the most basic are added for now. - // - // From docker/docker/pkg/mount/flags.go: - // - // var validFlags = map[string]bool{ - // "": true, - // "size": true, X - // "mode": true, X - // "uid": true, - // "gid": true, - // "nr_inodes": true, - // "nr_blocks": true, - // "mpol": true, - // } - // - // Some of these may be straightforward to add, but others, such as - // uid/gid have implications in a clustered system. -} diff --git a/vendor/github.com/docker/docker/api/types/network/network.go b/vendor/github.com/docker/docker/api/types/network/network.go deleted file mode 100644 index 832b3ed..0000000 --- a/vendor/github.com/docker/docker/api/types/network/network.go +++ /dev/null @@ -1,59 +0,0 @@ -package network - -// Address represents an IP address -type Address struct { - Addr string - PrefixLen int -} - -// IPAM represents IP Address Management -type IPAM struct { - Driver string - Options map[string]string //Per network IPAM driver options - Config []IPAMConfig -} - -// IPAMConfig represents IPAM configurations -type IPAMConfig struct { - Subnet string `json:",omitempty"` - IPRange string `json:",omitempty"` - Gateway string `json:",omitempty"` - AuxAddress map[string]string `json:"AuxiliaryAddresses,omitempty"` -} - -// EndpointIPAMConfig represents IPAM configurations for the endpoint -type EndpointIPAMConfig struct { - IPv4Address string `json:",omitempty"` - IPv6Address string `json:",omitempty"` - LinkLocalIPs []string `json:",omitempty"` -} - -// PeerInfo represents one peer of a overlay network -type PeerInfo struct { - Name string - IP string -} - -// EndpointSettings stores the network endpoint details -type EndpointSettings struct { - // Configurations - IPAMConfig *EndpointIPAMConfig - Links []string - Aliases []string - // Operational data - NetworkID string - EndpointID string - Gateway string - IPAddress string - IPPrefixLen int - IPv6Gateway string - GlobalIPv6Address string - GlobalIPv6PrefixLen int - MacAddress string -} - -// NetworkingConfig represents the container's networking configuration for each of its interfaces -// Carries the networking configs specified in the `docker run` and `docker network connect` commands -type NetworkingConfig struct { - EndpointsConfig map[string]*EndpointSettings // Endpoint configs for each connecting network -} diff --git a/vendor/github.com/docker/docker/api/types/plugin.go b/vendor/github.com/docker/docker/api/types/plugin.go deleted file mode 100644 index 6cc7a23..0000000 --- a/vendor/github.com/docker/docker/api/types/plugin.go +++ /dev/null @@ -1,189 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// Plugin A plugin for the Engine API -// swagger:model Plugin -type Plugin struct { - - // config - // Required: true - Config PluginConfig `json:"Config"` - - // True when the plugin is running. False when the plugin is not running, only installed. - // Required: true - Enabled bool `json:"Enabled"` - - // Id - ID string `json:"Id,omitempty"` - - // name - // Required: true - Name string `json:"Name"` - - // plugin remote reference used to push/pull the plugin - PluginReference string `json:"PluginReference,omitempty"` - - // settings - // Required: true - Settings PluginSettings `json:"Settings"` -} - -// PluginConfig The config of a plugin. -// swagger:model PluginConfig -type PluginConfig struct { - - // args - // Required: true - Args PluginConfigArgs `json:"Args"` - - // description - // Required: true - Description string `json:"Description"` - - // documentation - // Required: true - Documentation string `json:"Documentation"` - - // entrypoint - // Required: true - Entrypoint []string `json:"Entrypoint"` - - // env - // Required: true - Env []PluginEnv `json:"Env"` - - // interface - // Required: true - Interface PluginConfigInterface `json:"Interface"` - - // linux - // Required: true - Linux PluginConfigLinux `json:"Linux"` - - // mounts - // Required: true - Mounts []PluginMount `json:"Mounts"` - - // network - // Required: true - Network PluginConfigNetwork `json:"Network"` - - // propagated mount - // Required: true - PropagatedMount string `json:"PropagatedMount"` - - // user - User PluginConfigUser `json:"User,omitempty"` - - // work dir - // Required: true - WorkDir string `json:"WorkDir"` - - // rootfs - Rootfs *PluginConfigRootfs `json:"rootfs,omitempty"` -} - -// PluginConfigArgs plugin config args -// swagger:model PluginConfigArgs -type PluginConfigArgs struct { - - // description - // Required: true - Description string `json:"Description"` - - // name - // Required: true - Name string `json:"Name"` - - // settable - // Required: true - Settable []string `json:"Settable"` - - // value - // Required: true - Value []string `json:"Value"` -} - -// PluginConfigInterface The interface between Docker and the plugin -// swagger:model PluginConfigInterface -type PluginConfigInterface struct { - - // socket - // Required: true - Socket string `json:"Socket"` - - // types - // Required: true - Types []PluginInterfaceType `json:"Types"` -} - -// PluginConfigLinux plugin config linux -// swagger:model PluginConfigLinux -type PluginConfigLinux struct { - - // allow all devices - // Required: true - AllowAllDevices bool `json:"AllowAllDevices"` - - // capabilities - // Required: true - Capabilities []string `json:"Capabilities"` - - // devices - // Required: true - Devices []PluginDevice `json:"Devices"` -} - -// PluginConfigNetwork plugin config network -// swagger:model PluginConfigNetwork -type PluginConfigNetwork struct { - - // type - // Required: true - Type string `json:"Type"` -} - -// PluginConfigRootfs plugin config rootfs -// swagger:model PluginConfigRootfs -type PluginConfigRootfs struct { - - // diff ids - DiffIds []string `json:"diff_ids"` - - // type - Type string `json:"type,omitempty"` -} - -// PluginConfigUser plugin config user -// swagger:model PluginConfigUser -type PluginConfigUser struct { - - // g ID - GID uint32 `json:"GID,omitempty"` - - // UID - UID uint32 `json:"UID,omitempty"` -} - -// PluginSettings Settings that can be modified by users. -// swagger:model PluginSettings -type PluginSettings struct { - - // args - // Required: true - Args []string `json:"Args"` - - // devices - // Required: true - Devices []PluginDevice `json:"Devices"` - - // env - // Required: true - Env []string `json:"Env"` - - // mounts - // Required: true - Mounts []PluginMount `json:"Mounts"` -} diff --git a/vendor/github.com/docker/docker/api/types/plugin_device.go b/vendor/github.com/docker/docker/api/types/plugin_device.go deleted file mode 100644 index 5699010..0000000 --- a/vendor/github.com/docker/docker/api/types/plugin_device.go +++ /dev/null @@ -1,25 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// PluginDevice plugin device -// swagger:model PluginDevice -type PluginDevice struct { - - // description - // Required: true - Description string `json:"Description"` - - // name - // Required: true - Name string `json:"Name"` - - // path - // Required: true - Path *string `json:"Path"` - - // settable - // Required: true - Settable []string `json:"Settable"` -} diff --git a/vendor/github.com/docker/docker/api/types/plugin_env.go b/vendor/github.com/docker/docker/api/types/plugin_env.go deleted file mode 100644 index 32962dc..0000000 --- a/vendor/github.com/docker/docker/api/types/plugin_env.go +++ /dev/null @@ -1,25 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// PluginEnv plugin env -// swagger:model PluginEnv -type PluginEnv struct { - - // description - // Required: true - Description string `json:"Description"` - - // name - // Required: true - Name string `json:"Name"` - - // settable - // Required: true - Settable []string `json:"Settable"` - - // value - // Required: true - Value *string `json:"Value"` -} diff --git a/vendor/github.com/docker/docker/api/types/plugin_interface_type.go b/vendor/github.com/docker/docker/api/types/plugin_interface_type.go deleted file mode 100644 index c82f204..0000000 --- a/vendor/github.com/docker/docker/api/types/plugin_interface_type.go +++ /dev/null @@ -1,21 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// PluginInterfaceType plugin interface type -// swagger:model PluginInterfaceType -type PluginInterfaceType struct { - - // capability - // Required: true - Capability string `json:"Capability"` - - // prefix - // Required: true - Prefix string `json:"Prefix"` - - // version - // Required: true - Version string `json:"Version"` -} diff --git a/vendor/github.com/docker/docker/api/types/plugin_mount.go b/vendor/github.com/docker/docker/api/types/plugin_mount.go deleted file mode 100644 index 5c031cf..0000000 --- a/vendor/github.com/docker/docker/api/types/plugin_mount.go +++ /dev/null @@ -1,37 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// PluginMount plugin mount -// swagger:model PluginMount -type PluginMount struct { - - // description - // Required: true - Description string `json:"Description"` - - // destination - // Required: true - Destination string `json:"Destination"` - - // name - // Required: true - Name string `json:"Name"` - - // options - // Required: true - Options []string `json:"Options"` - - // settable - // Required: true - Settable []string `json:"Settable"` - - // source - // Required: true - Source *string `json:"Source"` - - // type - // Required: true - Type string `json:"Type"` -} diff --git a/vendor/github.com/docker/docker/api/types/plugin_responses.go b/vendor/github.com/docker/docker/api/types/plugin_responses.go deleted file mode 100644 index d6f7553..0000000 --- a/vendor/github.com/docker/docker/api/types/plugin_responses.go +++ /dev/null @@ -1,64 +0,0 @@ -package types - -import ( - "encoding/json" - "fmt" -) - -// PluginsListResponse contains the response for the Engine API -type PluginsListResponse []*Plugin - -const ( - authzDriver = "AuthzDriver" - graphDriver = "GraphDriver" - ipamDriver = "IpamDriver" - networkDriver = "NetworkDriver" - volumeDriver = "VolumeDriver" -) - -// UnmarshalJSON implements json.Unmarshaler for PluginInterfaceType -func (t *PluginInterfaceType) UnmarshalJSON(p []byte) error { - versionIndex := len(p) - prefixIndex := 0 - if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' { - return fmt.Errorf("%q is not a plugin interface type", p) - } - p = p[1 : len(p)-1] -loop: - for i, b := range p { - switch b { - case '.': - prefixIndex = i - case '/': - versionIndex = i - break loop - } - } - t.Prefix = string(p[:prefixIndex]) - t.Capability = string(p[prefixIndex+1 : versionIndex]) - if versionIndex < len(p) { - t.Version = string(p[versionIndex+1:]) - } - return nil -} - -// MarshalJSON implements json.Marshaler for PluginInterfaceType -func (t *PluginInterfaceType) MarshalJSON() ([]byte, error) { - return json.Marshal(t.String()) -} - -// String implements fmt.Stringer for PluginInterfaceType -func (t PluginInterfaceType) String() string { - return fmt.Sprintf("%s.%s/%s", t.Prefix, t.Capability, t.Version) -} - -// PluginPrivilege describes a permission the user has to accept -// upon installing a plugin. -type PluginPrivilege struct { - Name string - Description string - Value []string -} - -// PluginPrivileges is a list of PluginPrivilege -type PluginPrivileges []PluginPrivilege diff --git a/vendor/github.com/docker/docker/api/types/port.go b/vendor/github.com/docker/docker/api/types/port.go deleted file mode 100644 index ad52d46..0000000 --- a/vendor/github.com/docker/docker/api/types/port.go +++ /dev/null @@ -1,23 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// Port An open port on a container -// swagger:model Port -type Port struct { - - // IP - IP string `json:"IP,omitempty"` - - // Port on the container - // Required: true - PrivatePort uint16 `json:"PrivatePort"` - - // Port exposed on the host - PublicPort uint16 `json:"PublicPort,omitempty"` - - // type - // Required: true - Type string `json:"Type"` -} diff --git a/vendor/github.com/docker/docker/api/types/reference/image_reference.go b/vendor/github.com/docker/docker/api/types/reference/image_reference.go deleted file mode 100644 index be9cf8e..0000000 --- a/vendor/github.com/docker/docker/api/types/reference/image_reference.go +++ /dev/null @@ -1,34 +0,0 @@ -package reference - -import ( - distreference "github.com/docker/distribution/reference" -) - -// Parse parses the given references and returns the repository and -// tag (if present) from it. If there is an error during parsing, it will -// return an error. -func Parse(ref string) (string, string, error) { - distributionRef, err := distreference.ParseNamed(ref) - if err != nil { - return "", "", err - } - - tag := GetTagFromNamedRef(distributionRef) - return distributionRef.Name(), tag, nil -} - -// GetTagFromNamedRef returns a tag from the specified reference. -// This function is necessary as long as the docker "server" api makes the distinction between repository -// and tags. -func GetTagFromNamedRef(ref distreference.Named) string { - var tag string - switch x := ref.(type) { - case distreference.Digested: - tag = x.Digest().String() - case distreference.NamedTagged: - tag = x.Tag() - default: - tag = "latest" - } - return tag -} diff --git a/vendor/github.com/docker/docker/api/types/reference/image_reference_test.go b/vendor/github.com/docker/docker/api/types/reference/image_reference_test.go deleted file mode 100644 index 61fb676..0000000 --- a/vendor/github.com/docker/docker/api/types/reference/image_reference_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package reference - -import ( - "testing" -) - -func TestParse(t *testing.T) { - testCases := []struct { - ref string - expectedName string - expectedTag string - expectedError bool - }{ - { - ref: "", - expectedName: "", - expectedTag: "", - expectedError: true, - }, - { - ref: "repository", - expectedName: "repository", - expectedTag: "latest", - expectedError: false, - }, - { - ref: "repository:tag", - expectedName: "repository", - expectedTag: "tag", - expectedError: false, - }, - { - ref: "test.com/repository", - expectedName: "test.com/repository", - expectedTag: "latest", - expectedError: false, - }, - { - ref: "test.com:5000/test/repository", - expectedName: "test.com:5000/test/repository", - expectedTag: "latest", - expectedError: false, - }, - { - ref: "test.com:5000/repo@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - expectedName: "test.com:5000/repo", - expectedTag: "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - expectedError: false, - }, - { - ref: "test.com:5000/repo:tag@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - expectedName: "test.com:5000/repo", - expectedTag: "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - expectedError: false, - }, - } - - for _, c := range testCases { - name, tag, err := Parse(c.ref) - if err != nil && c.expectedError { - continue - } else if err != nil { - t.Fatalf("error with %s: %s", c.ref, err.Error()) - } - if name != c.expectedName { - t.Fatalf("expected name %s, got %s", c.expectedName, name) - } - if tag != c.expectedTag { - t.Fatalf("expected tag %s, got %s", c.expectedTag, tag) - } - } -} diff --git a/vendor/github.com/docker/docker/api/types/registry/authenticate.go b/vendor/github.com/docker/docker/api/types/registry/authenticate.go deleted file mode 100644 index 5e37d19..0000000 --- a/vendor/github.com/docker/docker/api/types/registry/authenticate.go +++ /dev/null @@ -1,21 +0,0 @@ -package registry - -// ---------------------------------------------------------------------------- -// DO NOT EDIT THIS FILE -// This file was generated by `swagger generate operation` -// -// See hack/swagger-gen.sh -// ---------------------------------------------------------------------------- - -// AuthenticateOKBody authenticate o k body -// swagger:model AuthenticateOKBody -type AuthenticateOKBody struct { - - // An opaque token used to authenticate a user after a successful login - // Required: true - IdentityToken string `json:"IdentityToken"` - - // The status of the authentication - // Required: true - Status string `json:"Status"` -} diff --git a/vendor/github.com/docker/docker/api/types/registry/registry.go b/vendor/github.com/docker/docker/api/types/registry/registry.go deleted file mode 100644 index 28fafab..0000000 --- a/vendor/github.com/docker/docker/api/types/registry/registry.go +++ /dev/null @@ -1,104 +0,0 @@ -package registry - -import ( - "encoding/json" - "net" -) - -// ServiceConfig stores daemon registry services configuration. -type ServiceConfig struct { - InsecureRegistryCIDRs []*NetIPNet `json:"InsecureRegistryCIDRs"` - IndexConfigs map[string]*IndexInfo `json:"IndexConfigs"` - Mirrors []string -} - -// NetIPNet is the net.IPNet type, which can be marshalled and -// unmarshalled to JSON -type NetIPNet net.IPNet - -// String returns the CIDR notation of ipnet -func (ipnet *NetIPNet) String() string { - return (*net.IPNet)(ipnet).String() -} - -// MarshalJSON returns the JSON representation of the IPNet -func (ipnet *NetIPNet) MarshalJSON() ([]byte, error) { - return json.Marshal((*net.IPNet)(ipnet).String()) -} - -// UnmarshalJSON sets the IPNet from a byte array of JSON -func (ipnet *NetIPNet) UnmarshalJSON(b []byte) (err error) { - var ipnetStr string - if err = json.Unmarshal(b, &ipnetStr); err == nil { - var cidr *net.IPNet - if _, cidr, err = net.ParseCIDR(ipnetStr); err == nil { - *ipnet = NetIPNet(*cidr) - } - } - return -} - -// IndexInfo contains information about a registry -// -// RepositoryInfo Examples: -// { -// "Index" : { -// "Name" : "docker.io", -// "Mirrors" : ["https://registry-2.docker.io/v1/", "https://registry-3.docker.io/v1/"], -// "Secure" : true, -// "Official" : true, -// }, -// "RemoteName" : "library/debian", -// "LocalName" : "debian", -// "CanonicalName" : "docker.io/debian" -// "Official" : true, -// } -// -// { -// "Index" : { -// "Name" : "127.0.0.1:5000", -// "Mirrors" : [], -// "Secure" : false, -// "Official" : false, -// }, -// "RemoteName" : "user/repo", -// "LocalName" : "127.0.0.1:5000/user/repo", -// "CanonicalName" : "127.0.0.1:5000/user/repo", -// "Official" : false, -// } -type IndexInfo struct { - // Name is the name of the registry, such as "docker.io" - Name string - // Mirrors is a list of mirrors, expressed as URIs - Mirrors []string - // Secure is set to false if the registry is part of the list of - // insecure registries. Insecure registries accept HTTP and/or accept - // HTTPS with certificates from unknown CAs. - Secure bool - // Official indicates whether this is an official registry - Official bool -} - -// SearchResult describes a search result returned from a registry -type SearchResult struct { - // StarCount indicates the number of stars this repository has - StarCount int `json:"star_count"` - // IsOfficial is true if the result is from an official repository. - IsOfficial bool `json:"is_official"` - // Name is the name of the repository - Name string `json:"name"` - // IsAutomated indicates whether the result is automated - IsAutomated bool `json:"is_automated"` - // Description is a textual description of the repository - Description string `json:"description"` -} - -// SearchResults lists a collection search results returned from a registry -type SearchResults struct { - // Query contains the query string that generated the search results - Query string `json:"query"` - // NumResults indicates the number of results the query returned - NumResults int `json:"num_results"` - // Results is a slice containing the actual results for the search - Results []SearchResult `json:"results"` -} diff --git a/vendor/github.com/docker/docker/api/types/seccomp.go b/vendor/github.com/docker/docker/api/types/seccomp.go deleted file mode 100644 index 4f02ef3..0000000 --- a/vendor/github.com/docker/docker/api/types/seccomp.go +++ /dev/null @@ -1,93 +0,0 @@ -package types - -// Seccomp represents the config for a seccomp profile for syscall restriction. -type Seccomp struct { - DefaultAction Action `json:"defaultAction"` - // Architectures is kept to maintain backward compatibility with the old - // seccomp profile. - Architectures []Arch `json:"architectures,omitempty"` - ArchMap []Architecture `json:"archMap,omitempty"` - Syscalls []*Syscall `json:"syscalls"` -} - -// Architecture is used to represent an specific architecture -// and its sub-architectures -type Architecture struct { - Arch Arch `json:"architecture"` - SubArches []Arch `json:"subArchitectures"` -} - -// Arch used for architectures -type Arch string - -// Additional architectures permitted to be used for system calls -// By default only the native architecture of the kernel is permitted -const ( - ArchX86 Arch = "SCMP_ARCH_X86" - ArchX86_64 Arch = "SCMP_ARCH_X86_64" - ArchX32 Arch = "SCMP_ARCH_X32" - ArchARM Arch = "SCMP_ARCH_ARM" - ArchAARCH64 Arch = "SCMP_ARCH_AARCH64" - ArchMIPS Arch = "SCMP_ARCH_MIPS" - ArchMIPS64 Arch = "SCMP_ARCH_MIPS64" - ArchMIPS64N32 Arch = "SCMP_ARCH_MIPS64N32" - ArchMIPSEL Arch = "SCMP_ARCH_MIPSEL" - ArchMIPSEL64 Arch = "SCMP_ARCH_MIPSEL64" - ArchMIPSEL64N32 Arch = "SCMP_ARCH_MIPSEL64N32" - ArchPPC Arch = "SCMP_ARCH_PPC" - ArchPPC64 Arch = "SCMP_ARCH_PPC64" - ArchPPC64LE Arch = "SCMP_ARCH_PPC64LE" - ArchS390 Arch = "SCMP_ARCH_S390" - ArchS390X Arch = "SCMP_ARCH_S390X" -) - -// Action taken upon Seccomp rule match -type Action string - -// Define actions for Seccomp rules -const ( - ActKill Action = "SCMP_ACT_KILL" - ActTrap Action = "SCMP_ACT_TRAP" - ActErrno Action = "SCMP_ACT_ERRNO" - ActTrace Action = "SCMP_ACT_TRACE" - ActAllow Action = "SCMP_ACT_ALLOW" -) - -// Operator used to match syscall arguments in Seccomp -type Operator string - -// Define operators for syscall arguments in Seccomp -const ( - OpNotEqual Operator = "SCMP_CMP_NE" - OpLessThan Operator = "SCMP_CMP_LT" - OpLessEqual Operator = "SCMP_CMP_LE" - OpEqualTo Operator = "SCMP_CMP_EQ" - OpGreaterEqual Operator = "SCMP_CMP_GE" - OpGreaterThan Operator = "SCMP_CMP_GT" - OpMaskedEqual Operator = "SCMP_CMP_MASKED_EQ" -) - -// Arg used for matching specific syscall arguments in Seccomp -type Arg struct { - Index uint `json:"index"` - Value uint64 `json:"value"` - ValueTwo uint64 `json:"valueTwo"` - Op Operator `json:"op"` -} - -// Filter is used to conditionally apply Seccomp rules -type Filter struct { - Caps []string `json:"caps,omitempty"` - Arches []string `json:"arches,omitempty"` -} - -// Syscall is used to match a group of syscalls in Seccomp -type Syscall struct { - Name string `json:"name,omitempty"` - Names []string `json:"names,omitempty"` - Action Action `json:"action"` - Args []*Arg `json:"args"` - Comment string `json:"comment"` - Includes Filter `json:"includes"` - Excludes Filter `json:"excludes"` -} diff --git a/vendor/github.com/docker/docker/api/types/service_update_response.go b/vendor/github.com/docker/docker/api/types/service_update_response.go deleted file mode 100644 index 74ea64b..0000000 --- a/vendor/github.com/docker/docker/api/types/service_update_response.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// ServiceUpdateResponse service update response -// swagger:model ServiceUpdateResponse -type ServiceUpdateResponse struct { - - // Optional warning messages - Warnings []string `json:"Warnings"` -} diff --git a/vendor/github.com/docker/docker/api/types/stats.go b/vendor/github.com/docker/docker/api/types/stats.go deleted file mode 100644 index 9bf1928..0000000 --- a/vendor/github.com/docker/docker/api/types/stats.go +++ /dev/null @@ -1,178 +0,0 @@ -// Package types is used for API stability in the types and response to the -// consumers of the API stats endpoint. -package types - -import "time" - -// ThrottlingData stores CPU throttling stats of one running container. -// Not used on Windows. -type ThrottlingData struct { - // Number of periods with throttling active - Periods uint64 `json:"periods"` - // Number of periods when the container hits its throttling limit. - ThrottledPeriods uint64 `json:"throttled_periods"` - // Aggregate time the container was throttled for in nanoseconds. - ThrottledTime uint64 `json:"throttled_time"` -} - -// CPUUsage stores All CPU stats aggregated since container inception. -type CPUUsage struct { - // Total CPU time consumed. - // Units: nanoseconds (Linux) - // Units: 100's of nanoseconds (Windows) - TotalUsage uint64 `json:"total_usage"` - - // Total CPU time consumed per core (Linux). Not used on Windows. - // Units: nanoseconds. - PercpuUsage []uint64 `json:"percpu_usage,omitempty"` - - // Time spent by tasks of the cgroup in kernel mode (Linux). - // Time spent by all container processes in kernel mode (Windows). - // Units: nanoseconds (Linux). - // Units: 100's of nanoseconds (Windows). Not populated for Hyper-V Containers. - UsageInKernelmode uint64 `json:"usage_in_kernelmode"` - - // Time spent by tasks of the cgroup in user mode (Linux). - // Time spent by all container processes in user mode (Windows). - // Units: nanoseconds (Linux). - // Units: 100's of nanoseconds (Windows). Not populated for Hyper-V Containers - UsageInUsermode uint64 `json:"usage_in_usermode"` -} - -// CPUStats aggregates and wraps all CPU related info of container -type CPUStats struct { - // CPU Usage. Linux and Windows. - CPUUsage CPUUsage `json:"cpu_usage"` - - // System Usage. Linux only. - SystemUsage uint64 `json:"system_cpu_usage,omitempty"` - - // Throttling Data. Linux only. - ThrottlingData ThrottlingData `json:"throttling_data,omitempty"` -} - -// MemoryStats aggregates all memory stats since container inception on Linux. -// Windows returns stats for commit and private working set only. -type MemoryStats struct { - // Linux Memory Stats - - // current res_counter usage for memory - Usage uint64 `json:"usage,omitempty"` - // maximum usage ever recorded. - MaxUsage uint64 `json:"max_usage,omitempty"` - // TODO(vishh): Export these as stronger types. - // all the stats exported via memory.stat. - Stats map[string]uint64 `json:"stats,omitempty"` - // number of times memory usage hits limits. - Failcnt uint64 `json:"failcnt,omitempty"` - Limit uint64 `json:"limit,omitempty"` - - // Windows Memory Stats - // See https://technet.microsoft.com/en-us/magazine/ff382715.aspx - - // committed bytes - Commit uint64 `json:"commitbytes,omitempty"` - // peak committed bytes - CommitPeak uint64 `json:"commitpeakbytes,omitempty"` - // private working set - PrivateWorkingSet uint64 `json:"privateworkingset,omitempty"` -} - -// BlkioStatEntry is one small entity to store a piece of Blkio stats -// Not used on Windows. -type BlkioStatEntry struct { - Major uint64 `json:"major"` - Minor uint64 `json:"minor"` - Op string `json:"op"` - Value uint64 `json:"value"` -} - -// BlkioStats stores All IO service stats for data read and write. -// This is a Linux specific structure as the differences between expressing -// block I/O on Windows and Linux are sufficiently significant to make -// little sense attempting to morph into a combined structure. -type BlkioStats struct { - // number of bytes transferred to and from the block device - IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive"` - IoServicedRecursive []BlkioStatEntry `json:"io_serviced_recursive"` - IoQueuedRecursive []BlkioStatEntry `json:"io_queue_recursive"` - IoServiceTimeRecursive []BlkioStatEntry `json:"io_service_time_recursive"` - IoWaitTimeRecursive []BlkioStatEntry `json:"io_wait_time_recursive"` - IoMergedRecursive []BlkioStatEntry `json:"io_merged_recursive"` - IoTimeRecursive []BlkioStatEntry `json:"io_time_recursive"` - SectorsRecursive []BlkioStatEntry `json:"sectors_recursive"` -} - -// StorageStats is the disk I/O stats for read/write on Windows. -type StorageStats struct { - ReadCountNormalized uint64 `json:"read_count_normalized,omitempty"` - ReadSizeBytes uint64 `json:"read_size_bytes,omitempty"` - WriteCountNormalized uint64 `json:"write_count_normalized,omitempty"` - WriteSizeBytes uint64 `json:"write_size_bytes,omitempty"` -} - -// NetworkStats aggregates the network stats of one container -type NetworkStats struct { - // Bytes received. Windows and Linux. - RxBytes uint64 `json:"rx_bytes"` - // Packets received. Windows and Linux. - RxPackets uint64 `json:"rx_packets"` - // Received errors. Not used on Windows. Note that we dont `omitempty` this - // field as it is expected in the >=v1.21 API stats structure. - RxErrors uint64 `json:"rx_errors"` - // Incoming packets dropped. Windows and Linux. - RxDropped uint64 `json:"rx_dropped"` - // Bytes sent. Windows and Linux. - TxBytes uint64 `json:"tx_bytes"` - // Packets sent. Windows and Linux. - TxPackets uint64 `json:"tx_packets"` - // Sent errors. Not used on Windows. Note that we dont `omitempty` this - // field as it is expected in the >=v1.21 API stats structure. - TxErrors uint64 `json:"tx_errors"` - // Outgoing packets dropped. Windows and Linux. - TxDropped uint64 `json:"tx_dropped"` - // Endpoint ID. Not used on Linux. - EndpointID string `json:"endpoint_id,omitempty"` - // Instance ID. Not used on Linux. - InstanceID string `json:"instance_id,omitempty"` -} - -// PidsStats contains the stats of a container's pids -type PidsStats struct { - // Current is the number of pids in the cgroup - Current uint64 `json:"current,omitempty"` - // Limit is the hard limit on the number of pids in the cgroup. - // A "Limit" of 0 means that there is no limit. - Limit uint64 `json:"limit,omitempty"` -} - -// Stats is Ultimate struct aggregating all types of stats of one container -type Stats struct { - // Common stats - Read time.Time `json:"read"` - PreRead time.Time `json:"preread"` - - // Linux specific stats, not populated on Windows. - PidsStats PidsStats `json:"pids_stats,omitempty"` - BlkioStats BlkioStats `json:"blkio_stats,omitempty"` - - // Windows specific stats, not populated on Linux. - NumProcs uint32 `json:"num_procs"` - StorageStats StorageStats `json:"storage_stats,omitempty"` - - // Shared stats - CPUStats CPUStats `json:"cpu_stats,omitempty"` - PreCPUStats CPUStats `json:"precpu_stats,omitempty"` // "Pre"="Previous" - MemoryStats MemoryStats `json:"memory_stats,omitempty"` -} - -// StatsJSON is newly used Networks -type StatsJSON struct { - Stats - - Name string `json:"name,omitempty"` - ID string `json:"id,omitempty"` - - // Networks request version >=1.21 - Networks map[string]NetworkStats `json:"networks,omitempty"` -} diff --git a/vendor/github.com/docker/docker/api/types/strslice/strslice.go b/vendor/github.com/docker/docker/api/types/strslice/strslice.go deleted file mode 100644 index bad493f..0000000 --- a/vendor/github.com/docker/docker/api/types/strslice/strslice.go +++ /dev/null @@ -1,30 +0,0 @@ -package strslice - -import "encoding/json" - -// StrSlice represents a string or an array of strings. -// We need to override the json decoder to accept both options. -type StrSlice []string - -// UnmarshalJSON decodes the byte slice whether it's a string or an array of -// strings. This method is needed to implement json.Unmarshaler. -func (e *StrSlice) UnmarshalJSON(b []byte) error { - if len(b) == 0 { - // With no input, we preserve the existing value by returning nil and - // leaving the target alone. This allows defining default values for - // the type. - return nil - } - - p := make([]string, 0, 1) - if err := json.Unmarshal(b, &p); err != nil { - var s string - if err := json.Unmarshal(b, &s); err != nil { - return err - } - p = append(p, s) - } - - *e = p - return nil -} diff --git a/vendor/github.com/docker/docker/api/types/strslice/strslice_test.go b/vendor/github.com/docker/docker/api/types/strslice/strslice_test.go deleted file mode 100644 index 1163b36..0000000 --- a/vendor/github.com/docker/docker/api/types/strslice/strslice_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package strslice - -import ( - "encoding/json" - "reflect" - "testing" -) - -func TestStrSliceMarshalJSON(t *testing.T) { - for _, testcase := range []struct { - input StrSlice - expected string - }{ - // MADNESS(stevvooe): No clue why nil would be "" but empty would be - // "null". Had to make a change here that may affect compatibility. - {input: nil, expected: "null"}, - {StrSlice{}, "[]"}, - {StrSlice{"/bin/sh", "-c", "echo"}, `["/bin/sh","-c","echo"]`}, - } { - data, err := json.Marshal(testcase.input) - if err != nil { - t.Fatal(err) - } - if string(data) != testcase.expected { - t.Fatalf("%#v: expected %v, got %v", testcase.input, testcase.expected, string(data)) - } - } -} - -func TestStrSliceUnmarshalJSON(t *testing.T) { - parts := map[string][]string{ - "": {"default", "values"}, - "[]": {}, - `["/bin/sh","-c","echo"]`: {"/bin/sh", "-c", "echo"}, - } - for json, expectedParts := range parts { - strs := StrSlice{"default", "values"} - if err := strs.UnmarshalJSON([]byte(json)); err != nil { - t.Fatal(err) - } - - actualParts := []string(strs) - if !reflect.DeepEqual(actualParts, expectedParts) { - t.Fatalf("%#v: expected %v, got %v", json, expectedParts, actualParts) - } - - } -} - -func TestStrSliceUnmarshalString(t *testing.T) { - var e StrSlice - echo, err := json.Marshal("echo") - if err != nil { - t.Fatal(err) - } - if err := json.Unmarshal(echo, &e); err != nil { - t.Fatal(err) - } - - if len(e) != 1 { - t.Fatalf("expected 1 element after unmarshal: %q", e) - } - - if e[0] != "echo" { - t.Fatalf("expected `echo`, got: %q", e[0]) - } -} - -func TestStrSliceUnmarshalSlice(t *testing.T) { - var e StrSlice - echo, err := json.Marshal([]string{"echo"}) - if err != nil { - t.Fatal(err) - } - if err := json.Unmarshal(echo, &e); err != nil { - t.Fatal(err) - } - - if len(e) != 1 { - t.Fatalf("expected 1 element after unmarshal: %q", e) - } - - if e[0] != "echo" { - t.Fatalf("expected `echo`, got: %q", e[0]) - } -} diff --git a/vendor/github.com/docker/docker/api/types/swarm/common.go b/vendor/github.com/docker/docker/api/types/swarm/common.go deleted file mode 100644 index 64a648b..0000000 --- a/vendor/github.com/docker/docker/api/types/swarm/common.go +++ /dev/null @@ -1,27 +0,0 @@ -package swarm - -import "time" - -// Version represents the internal object version. -type Version struct { - Index uint64 `json:",omitempty"` -} - -// Meta is a base object inherited by most of the other once. -type Meta struct { - Version Version `json:",omitempty"` - CreatedAt time.Time `json:",omitempty"` - UpdatedAt time.Time `json:",omitempty"` -} - -// Annotations represents how to describe an object. -type Annotations struct { - Name string `json:",omitempty"` - Labels map[string]string `json:",omitempty"` -} - -// Driver represents a driver (network, logging). -type Driver struct { - Name string `json:",omitempty"` - Options map[string]string `json:",omitempty"` -} diff --git a/vendor/github.com/docker/docker/api/types/swarm/container.go b/vendor/github.com/docker/docker/api/types/swarm/container.go deleted file mode 100644 index 4ab476c..0000000 --- a/vendor/github.com/docker/docker/api/types/swarm/container.go +++ /dev/null @@ -1,46 +0,0 @@ -package swarm - -import ( - "time" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/mount" -) - -// DNSConfig specifies DNS related configurations in resolver configuration file (resolv.conf) -// Detailed documentation is available in: -// http://man7.org/linux/man-pages/man5/resolv.conf.5.html -// `nameserver`, `search`, `options` have been supported. -// TODO: `domain` is not supported yet. -type DNSConfig struct { - // Nameservers specifies the IP addresses of the name servers - Nameservers []string `json:",omitempty"` - // Search specifies the search list for host-name lookup - Search []string `json:",omitempty"` - // Options allows certain internal resolver variables to be modified - Options []string `json:",omitempty"` -} - -// ContainerSpec represents the spec of a container. -type ContainerSpec struct { - Image string `json:",omitempty"` - Labels map[string]string `json:",omitempty"` - Command []string `json:",omitempty"` - Args []string `json:",omitempty"` - Hostname string `json:",omitempty"` - Env []string `json:",omitempty"` - Dir string `json:",omitempty"` - User string `json:",omitempty"` - Groups []string `json:",omitempty"` - TTY bool `json:",omitempty"` - OpenStdin bool `json:",omitempty"` - Mounts []mount.Mount `json:",omitempty"` - StopGracePeriod *time.Duration `json:",omitempty"` - Healthcheck *container.HealthConfig `json:",omitempty"` - // The format of extra hosts on swarmkit is specified in: - // http://man7.org/linux/man-pages/man5/hosts.5.html - // IP_address canonical_hostname [aliases...] - Hosts []string `json:",omitempty"` - DNSConfig *DNSConfig `json:",omitempty"` - Secrets []*SecretReference `json:",omitempty"` -} diff --git a/vendor/github.com/docker/docker/api/types/swarm/network.go b/vendor/github.com/docker/docker/api/types/swarm/network.go deleted file mode 100644 index 5a5e11b..0000000 --- a/vendor/github.com/docker/docker/api/types/swarm/network.go +++ /dev/null @@ -1,111 +0,0 @@ -package swarm - -// Endpoint represents an endpoint. -type Endpoint struct { - Spec EndpointSpec `json:",omitempty"` - Ports []PortConfig `json:",omitempty"` - VirtualIPs []EndpointVirtualIP `json:",omitempty"` -} - -// EndpointSpec represents the spec of an endpoint. -type EndpointSpec struct { - Mode ResolutionMode `json:",omitempty"` - Ports []PortConfig `json:",omitempty"` -} - -// ResolutionMode represents a resolution mode. -type ResolutionMode string - -const ( - // ResolutionModeVIP VIP - ResolutionModeVIP ResolutionMode = "vip" - // ResolutionModeDNSRR DNSRR - ResolutionModeDNSRR ResolutionMode = "dnsrr" -) - -// PortConfig represents the config of a port. -type PortConfig struct { - Name string `json:",omitempty"` - Protocol PortConfigProtocol `json:",omitempty"` - // TargetPort is the port inside the container - TargetPort uint32 `json:",omitempty"` - // PublishedPort is the port on the swarm hosts - PublishedPort uint32 `json:",omitempty"` - // PublishMode is the mode in which port is published - PublishMode PortConfigPublishMode `json:",omitempty"` -} - -// PortConfigPublishMode represents the mode in which the port is to -// be published. -type PortConfigPublishMode string - -const ( - // PortConfigPublishModeIngress is used for ports published - // for ingress load balancing using routing mesh. - PortConfigPublishModeIngress PortConfigPublishMode = "ingress" - // PortConfigPublishModeHost is used for ports published - // for direct host level access on the host where the task is running. - PortConfigPublishModeHost PortConfigPublishMode = "host" -) - -// PortConfigProtocol represents the protocol of a port. -type PortConfigProtocol string - -const ( - // TODO(stevvooe): These should be used generally, not just for PortConfig. - - // PortConfigProtocolTCP TCP - PortConfigProtocolTCP PortConfigProtocol = "tcp" - // PortConfigProtocolUDP UDP - PortConfigProtocolUDP PortConfigProtocol = "udp" -) - -// EndpointVirtualIP represents the virtual ip of a port. -type EndpointVirtualIP struct { - NetworkID string `json:",omitempty"` - Addr string `json:",omitempty"` -} - -// Network represents a network. -type Network struct { - ID string - Meta - Spec NetworkSpec `json:",omitempty"` - DriverState Driver `json:",omitempty"` - IPAMOptions *IPAMOptions `json:",omitempty"` -} - -// NetworkSpec represents the spec of a network. -type NetworkSpec struct { - Annotations - DriverConfiguration *Driver `json:",omitempty"` - IPv6Enabled bool `json:",omitempty"` - Internal bool `json:",omitempty"` - Attachable bool `json:",omitempty"` - IPAMOptions *IPAMOptions `json:",omitempty"` -} - -// NetworkAttachmentConfig represents the configuration of a network attachment. -type NetworkAttachmentConfig struct { - Target string `json:",omitempty"` - Aliases []string `json:",omitempty"` -} - -// NetworkAttachment represents a network attachment. -type NetworkAttachment struct { - Network Network `json:",omitempty"` - Addresses []string `json:",omitempty"` -} - -// IPAMOptions represents ipam options. -type IPAMOptions struct { - Driver Driver `json:",omitempty"` - Configs []IPAMConfig `json:",omitempty"` -} - -// IPAMConfig represents ipam configuration. -type IPAMConfig struct { - Subnet string `json:",omitempty"` - Range string `json:",omitempty"` - Gateway string `json:",omitempty"` -} diff --git a/vendor/github.com/docker/docker/api/types/swarm/node.go b/vendor/github.com/docker/docker/api/types/swarm/node.go deleted file mode 100644 index 379e17a..0000000 --- a/vendor/github.com/docker/docker/api/types/swarm/node.go +++ /dev/null @@ -1,114 +0,0 @@ -package swarm - -// Node represents a node. -type Node struct { - ID string - Meta - // Spec defines the desired state of the node as specified by the user. - // The system will honor this and will *never* modify it. - Spec NodeSpec `json:",omitempty"` - // Description encapsulates the properties of the Node as reported by the - // agent. - Description NodeDescription `json:",omitempty"` - // Status provides the current status of the node, as seen by the manager. - Status NodeStatus `json:",omitempty"` - // ManagerStatus provides the current status of the node's manager - // component, if the node is a manager. - ManagerStatus *ManagerStatus `json:",omitempty"` -} - -// NodeSpec represents the spec of a node. -type NodeSpec struct { - Annotations - Role NodeRole `json:",omitempty"` - Availability NodeAvailability `json:",omitempty"` -} - -// NodeRole represents the role of a node. -type NodeRole string - -const ( - // NodeRoleWorker WORKER - NodeRoleWorker NodeRole = "worker" - // NodeRoleManager MANAGER - NodeRoleManager NodeRole = "manager" -) - -// NodeAvailability represents the availability of a node. -type NodeAvailability string - -const ( - // NodeAvailabilityActive ACTIVE - NodeAvailabilityActive NodeAvailability = "active" - // NodeAvailabilityPause PAUSE - NodeAvailabilityPause NodeAvailability = "pause" - // NodeAvailabilityDrain DRAIN - NodeAvailabilityDrain NodeAvailability = "drain" -) - -// NodeDescription represents the description of a node. -type NodeDescription struct { - Hostname string `json:",omitempty"` - Platform Platform `json:",omitempty"` - Resources Resources `json:",omitempty"` - Engine EngineDescription `json:",omitempty"` -} - -// Platform represents the platform (Arch/OS). -type Platform struct { - Architecture string `json:",omitempty"` - OS string `json:",omitempty"` -} - -// EngineDescription represents the description of an engine. -type EngineDescription struct { - EngineVersion string `json:",omitempty"` - Labels map[string]string `json:",omitempty"` - Plugins []PluginDescription `json:",omitempty"` -} - -// PluginDescription represents the description of an engine plugin. -type PluginDescription struct { - Type string `json:",omitempty"` - Name string `json:",omitempty"` -} - -// NodeStatus represents the status of a node. -type NodeStatus struct { - State NodeState `json:",omitempty"` - Message string `json:",omitempty"` - Addr string `json:",omitempty"` -} - -// Reachability represents the reachability of a node. -type Reachability string - -const ( - // ReachabilityUnknown UNKNOWN - ReachabilityUnknown Reachability = "unknown" - // ReachabilityUnreachable UNREACHABLE - ReachabilityUnreachable Reachability = "unreachable" - // ReachabilityReachable REACHABLE - ReachabilityReachable Reachability = "reachable" -) - -// ManagerStatus represents the status of a manager. -type ManagerStatus struct { - Leader bool `json:",omitempty"` - Reachability Reachability `json:",omitempty"` - Addr string `json:",omitempty"` -} - -// NodeState represents the state of a node. -type NodeState string - -const ( - // NodeStateUnknown UNKNOWN - NodeStateUnknown NodeState = "unknown" - // NodeStateDown DOWN - NodeStateDown NodeState = "down" - // NodeStateReady READY - NodeStateReady NodeState = "ready" - // NodeStateDisconnected DISCONNECTED - NodeStateDisconnected NodeState = "disconnected" -) diff --git a/vendor/github.com/docker/docker/api/types/swarm/secret.go b/vendor/github.com/docker/docker/api/types/swarm/secret.go deleted file mode 100644 index fdb2388..0000000 --- a/vendor/github.com/docker/docker/api/types/swarm/secret.go +++ /dev/null @@ -1,31 +0,0 @@ -package swarm - -import "os" - -// Secret represents a secret. -type Secret struct { - ID string - Meta - Spec SecretSpec -} - -// SecretSpec represents a secret specification from a secret in swarm -type SecretSpec struct { - Annotations - Data []byte `json:",omitempty"` -} - -// SecretReferenceFileTarget is a file target in a secret reference -type SecretReferenceFileTarget struct { - Name string - UID string - GID string - Mode os.FileMode -} - -// SecretReference is a reference to a secret in swarm -type SecretReference struct { - File *SecretReferenceFileTarget - SecretID string - SecretName string -} diff --git a/vendor/github.com/docker/docker/api/types/swarm/service.go b/vendor/github.com/docker/docker/api/types/swarm/service.go deleted file mode 100644 index 2cf2642..0000000 --- a/vendor/github.com/docker/docker/api/types/swarm/service.go +++ /dev/null @@ -1,105 +0,0 @@ -package swarm - -import "time" - -// Service represents a service. -type Service struct { - ID string - Meta - Spec ServiceSpec `json:",omitempty"` - PreviousSpec *ServiceSpec `json:",omitempty"` - Endpoint Endpoint `json:",omitempty"` - UpdateStatus UpdateStatus `json:",omitempty"` -} - -// ServiceSpec represents the spec of a service. -type ServiceSpec struct { - Annotations - - // TaskTemplate defines how the service should construct new tasks when - // orchestrating this service. - TaskTemplate TaskSpec `json:",omitempty"` - Mode ServiceMode `json:",omitempty"` - UpdateConfig *UpdateConfig `json:",omitempty"` - - // Networks field in ServiceSpec is deprecated. The - // same field in TaskSpec should be used instead. - // This field will be removed in a future release. - Networks []NetworkAttachmentConfig `json:",omitempty"` - EndpointSpec *EndpointSpec `json:",omitempty"` -} - -// ServiceMode represents the mode of a service. -type ServiceMode struct { - Replicated *ReplicatedService `json:",omitempty"` - Global *GlobalService `json:",omitempty"` -} - -// UpdateState is the state of a service update. -type UpdateState string - -const ( - // UpdateStateUpdating is the updating state. - UpdateStateUpdating UpdateState = "updating" - // UpdateStatePaused is the paused state. - UpdateStatePaused UpdateState = "paused" - // UpdateStateCompleted is the completed state. - UpdateStateCompleted UpdateState = "completed" -) - -// UpdateStatus reports the status of a service update. -type UpdateStatus struct { - State UpdateState `json:",omitempty"` - StartedAt time.Time `json:",omitempty"` - CompletedAt time.Time `json:",omitempty"` - Message string `json:",omitempty"` -} - -// ReplicatedService is a kind of ServiceMode. -type ReplicatedService struct { - Replicas *uint64 `json:",omitempty"` -} - -// GlobalService is a kind of ServiceMode. -type GlobalService struct{} - -const ( - // UpdateFailureActionPause PAUSE - UpdateFailureActionPause = "pause" - // UpdateFailureActionContinue CONTINUE - UpdateFailureActionContinue = "continue" -) - -// UpdateConfig represents the update configuration. -type UpdateConfig struct { - // Maximum number of tasks to be updated in one iteration. - // 0 means unlimited parallelism. - Parallelism uint64 - - // Amount of time between updates. - Delay time.Duration `json:",omitempty"` - - // FailureAction is the action to take when an update failures. - FailureAction string `json:",omitempty"` - - // Monitor indicates how long to monitor a task for failure after it is - // created. If the task fails by ending up in one of the states - // REJECTED, COMPLETED, or FAILED, within Monitor from its creation, - // this counts as a failure. If it fails after Monitor, it does not - // count as a failure. If Monitor is unspecified, a default value will - // be used. - Monitor time.Duration `json:",omitempty"` - - // MaxFailureRatio is the fraction of tasks that may fail during - // an update before the failure action is invoked. Any task created by - // the current update which ends up in one of the states REJECTED, - // COMPLETED or FAILED within Monitor from its creation counts as a - // failure. The number of failures is divided by the number of tasks - // being updated, and if this fraction is greater than - // MaxFailureRatio, the failure action is invoked. - // - // If the failure action is CONTINUE, there is no effect. - // If the failure action is PAUSE, no more tasks will be updated until - // another update is started. - MaxFailureRatio float32 -} diff --git a/vendor/github.com/docker/docker/api/types/swarm/swarm.go b/vendor/github.com/docker/docker/api/types/swarm/swarm.go deleted file mode 100644 index 0b42219..0000000 --- a/vendor/github.com/docker/docker/api/types/swarm/swarm.go +++ /dev/null @@ -1,197 +0,0 @@ -package swarm - -import "time" - -// ClusterInfo represents info about the cluster for outputing in "info" -// it contains the same information as "Swarm", but without the JoinTokens -type ClusterInfo struct { - ID string - Meta - Spec Spec -} - -// Swarm represents a swarm. -type Swarm struct { - ClusterInfo - JoinTokens JoinTokens -} - -// JoinTokens contains the tokens workers and managers need to join the swarm. -type JoinTokens struct { - // Worker is the join token workers may use to join the swarm. - Worker string - // Manager is the join token managers may use to join the swarm. - Manager string -} - -// Spec represents the spec of a swarm. -type Spec struct { - Annotations - - Orchestration OrchestrationConfig `json:",omitempty"` - Raft RaftConfig `json:",omitempty"` - Dispatcher DispatcherConfig `json:",omitempty"` - CAConfig CAConfig `json:",omitempty"` - TaskDefaults TaskDefaults `json:",omitempty"` - EncryptionConfig EncryptionConfig `json:",omitempty"` -} - -// OrchestrationConfig represents orchestration configuration. -type OrchestrationConfig struct { - // TaskHistoryRetentionLimit is the number of historic tasks to keep per instance or - // node. If negative, never remove completed or failed tasks. - TaskHistoryRetentionLimit *int64 `json:",omitempty"` -} - -// TaskDefaults parameterizes cluster-level task creation with default values. -type TaskDefaults struct { - // LogDriver selects the log driver to use for tasks created in the - // orchestrator if unspecified by a service. - // - // Updating this value will only have an affect on new tasks. Old tasks - // will continue use their previously configured log driver until - // recreated. - LogDriver *Driver `json:",omitempty"` -} - -// EncryptionConfig controls at-rest encryption of data and keys. -type EncryptionConfig struct { - // AutoLockManagers specifies whether or not managers TLS keys and raft data - // should be encrypted at rest in such a way that they must be unlocked - // before the manager node starts up again. - AutoLockManagers bool -} - -// RaftConfig represents raft configuration. -type RaftConfig struct { - // SnapshotInterval is the number of log entries between snapshots. - SnapshotInterval uint64 `json:",omitempty"` - - // KeepOldSnapshots is the number of snapshots to keep beyond the - // current snapshot. - KeepOldSnapshots *uint64 `json:",omitempty"` - - // LogEntriesForSlowFollowers is the number of log entries to keep - // around to sync up slow followers after a snapshot is created. - LogEntriesForSlowFollowers uint64 `json:",omitempty"` - - // ElectionTick is the number of ticks that a follower will wait for a message - // from the leader before becoming a candidate and starting an election. - // ElectionTick must be greater than HeartbeatTick. - // - // A tick currently defaults to one second, so these translate directly to - // seconds currently, but this is NOT guaranteed. - ElectionTick int - - // HeartbeatTick is the number of ticks between heartbeats. Every - // HeartbeatTick ticks, the leader will send a heartbeat to the - // followers. - // - // A tick currently defaults to one second, so these translate directly to - // seconds currently, but this is NOT guaranteed. - HeartbeatTick int -} - -// DispatcherConfig represents dispatcher configuration. -type DispatcherConfig struct { - // HeartbeatPeriod defines how often agent should send heartbeats to - // dispatcher. - HeartbeatPeriod time.Duration `json:",omitempty"` -} - -// CAConfig represents CA configuration. -type CAConfig struct { - // NodeCertExpiry is the duration certificates should be issued for - NodeCertExpiry time.Duration `json:",omitempty"` - - // ExternalCAs is a list of CAs to which a manager node will make - // certificate signing requests for node certificates. - ExternalCAs []*ExternalCA `json:",omitempty"` -} - -// ExternalCAProtocol represents type of external CA. -type ExternalCAProtocol string - -// ExternalCAProtocolCFSSL CFSSL -const ExternalCAProtocolCFSSL ExternalCAProtocol = "cfssl" - -// ExternalCA defines external CA to be used by the cluster. -type ExternalCA struct { - // Protocol is the protocol used by this external CA. - Protocol ExternalCAProtocol - - // URL is the URL where the external CA can be reached. - URL string - - // Options is a set of additional key/value pairs whose interpretation - // depends on the specified CA type. - Options map[string]string `json:",omitempty"` -} - -// InitRequest is the request used to init a swarm. -type InitRequest struct { - ListenAddr string - AdvertiseAddr string - ForceNewCluster bool - Spec Spec - AutoLockManagers bool -} - -// JoinRequest is the request used to join a swarm. -type JoinRequest struct { - ListenAddr string - AdvertiseAddr string - RemoteAddrs []string - JoinToken string // accept by secret -} - -// UnlockRequest is the request used to unlock a swarm. -type UnlockRequest struct { - // UnlockKey is the unlock key in ASCII-armored format. - UnlockKey string -} - -// LocalNodeState represents the state of the local node. -type LocalNodeState string - -const ( - // LocalNodeStateInactive INACTIVE - LocalNodeStateInactive LocalNodeState = "inactive" - // LocalNodeStatePending PENDING - LocalNodeStatePending LocalNodeState = "pending" - // LocalNodeStateActive ACTIVE - LocalNodeStateActive LocalNodeState = "active" - // LocalNodeStateError ERROR - LocalNodeStateError LocalNodeState = "error" - // LocalNodeStateLocked LOCKED - LocalNodeStateLocked LocalNodeState = "locked" -) - -// Info represents generic information about swarm. -type Info struct { - NodeID string - NodeAddr string - - LocalNodeState LocalNodeState - ControlAvailable bool - Error string - - RemoteManagers []Peer - Nodes int - Managers int - - Cluster ClusterInfo -} - -// Peer represents a peer. -type Peer struct { - NodeID string - Addr string -} - -// UpdateFlags contains flags for SwarmUpdate. -type UpdateFlags struct { - RotateWorkerToken bool - RotateManagerToken bool - RotateManagerUnlockKey bool -} diff --git a/vendor/github.com/docker/docker/api/types/swarm/task.go b/vendor/github.com/docker/docker/api/types/swarm/task.go deleted file mode 100644 index ace12cc..0000000 --- a/vendor/github.com/docker/docker/api/types/swarm/task.go +++ /dev/null @@ -1,128 +0,0 @@ -package swarm - -import "time" - -// TaskState represents the state of a task. -type TaskState string - -const ( - // TaskStateNew NEW - TaskStateNew TaskState = "new" - // TaskStateAllocated ALLOCATED - TaskStateAllocated TaskState = "allocated" - // TaskStatePending PENDING - TaskStatePending TaskState = "pending" - // TaskStateAssigned ASSIGNED - TaskStateAssigned TaskState = "assigned" - // TaskStateAccepted ACCEPTED - TaskStateAccepted TaskState = "accepted" - // TaskStatePreparing PREPARING - TaskStatePreparing TaskState = "preparing" - // TaskStateReady READY - TaskStateReady TaskState = "ready" - // TaskStateStarting STARTING - TaskStateStarting TaskState = "starting" - // TaskStateRunning RUNNING - TaskStateRunning TaskState = "running" - // TaskStateComplete COMPLETE - TaskStateComplete TaskState = "complete" - // TaskStateShutdown SHUTDOWN - TaskStateShutdown TaskState = "shutdown" - // TaskStateFailed FAILED - TaskStateFailed TaskState = "failed" - // TaskStateRejected REJECTED - TaskStateRejected TaskState = "rejected" -) - -// Task represents a task. -type Task struct { - ID string - Meta - Annotations - - Spec TaskSpec `json:",omitempty"` - ServiceID string `json:",omitempty"` - Slot int `json:",omitempty"` - NodeID string `json:",omitempty"` - Status TaskStatus `json:",omitempty"` - DesiredState TaskState `json:",omitempty"` - NetworksAttachments []NetworkAttachment `json:",omitempty"` -} - -// TaskSpec represents the spec of a task. -type TaskSpec struct { - ContainerSpec ContainerSpec `json:",omitempty"` - Resources *ResourceRequirements `json:",omitempty"` - RestartPolicy *RestartPolicy `json:",omitempty"` - Placement *Placement `json:",omitempty"` - Networks []NetworkAttachmentConfig `json:",omitempty"` - - // LogDriver specifies the LogDriver to use for tasks created from this - // spec. If not present, the one on cluster default on swarm.Spec will be - // used, finally falling back to the engine default if not specified. - LogDriver *Driver `json:",omitempty"` - - // ForceUpdate is a counter that triggers an update even if no relevant - // parameters have been changed. - ForceUpdate uint64 -} - -// Resources represents resources (CPU/Memory). -type Resources struct { - NanoCPUs int64 `json:",omitempty"` - MemoryBytes int64 `json:",omitempty"` -} - -// ResourceRequirements represents resources requirements. -type ResourceRequirements struct { - Limits *Resources `json:",omitempty"` - Reservations *Resources `json:",omitempty"` -} - -// Placement represents orchestration parameters. -type Placement struct { - Constraints []string `json:",omitempty"` -} - -// RestartPolicy represents the restart policy. -type RestartPolicy struct { - Condition RestartPolicyCondition `json:",omitempty"` - Delay *time.Duration `json:",omitempty"` - MaxAttempts *uint64 `json:",omitempty"` - Window *time.Duration `json:",omitempty"` -} - -// RestartPolicyCondition represents when to restart. -type RestartPolicyCondition string - -const ( - // RestartPolicyConditionNone NONE - RestartPolicyConditionNone RestartPolicyCondition = "none" - // RestartPolicyConditionOnFailure ON_FAILURE - RestartPolicyConditionOnFailure RestartPolicyCondition = "on-failure" - // RestartPolicyConditionAny ANY - RestartPolicyConditionAny RestartPolicyCondition = "any" -) - -// TaskStatus represents the status of a task. -type TaskStatus struct { - Timestamp time.Time `json:",omitempty"` - State TaskState `json:",omitempty"` - Message string `json:",omitempty"` - Err string `json:",omitempty"` - ContainerStatus ContainerStatus `json:",omitempty"` - PortStatus PortStatus `json:",omitempty"` -} - -// ContainerStatus represents the status of a container. -type ContainerStatus struct { - ContainerID string `json:",omitempty"` - PID int `json:",omitempty"` - ExitCode int `json:",omitempty"` -} - -// PortStatus represents the port status of a task's host ports whose -// service has published host ports -type PortStatus struct { - Ports []PortConfig `json:",omitempty"` -} diff --git a/vendor/github.com/docker/docker/api/types/time/duration_convert.go b/vendor/github.com/docker/docker/api/types/time/duration_convert.go deleted file mode 100644 index 63e1eec..0000000 --- a/vendor/github.com/docker/docker/api/types/time/duration_convert.go +++ /dev/null @@ -1,12 +0,0 @@ -package time - -import ( - "strconv" - "time" -) - -// DurationToSecondsString converts the specified duration to the number -// seconds it represents, formatted as a string. -func DurationToSecondsString(duration time.Duration) string { - return strconv.FormatFloat(duration.Seconds(), 'f', 0, 64) -} diff --git a/vendor/github.com/docker/docker/api/types/time/duration_convert_test.go b/vendor/github.com/docker/docker/api/types/time/duration_convert_test.go deleted file mode 100644 index 869c08f..0000000 --- a/vendor/github.com/docker/docker/api/types/time/duration_convert_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package time - -import ( - "testing" - "time" -) - -func TestDurationToSecondsString(t *testing.T) { - cases := []struct { - in time.Duration - expected string - }{ - {0 * time.Second, "0"}, - {1 * time.Second, "1"}, - {1 * time.Minute, "60"}, - {24 * time.Hour, "86400"}, - } - - for _, c := range cases { - s := DurationToSecondsString(c.in) - if s != c.expected { - t.Errorf("wrong value for input `%v`: expected `%s`, got `%s`", c.in, c.expected, s) - t.Fail() - } - } -} diff --git a/vendor/github.com/docker/docker/api/types/time/timestamp.go b/vendor/github.com/docker/docker/api/types/time/timestamp.go deleted file mode 100644 index d3695ba..0000000 --- a/vendor/github.com/docker/docker/api/types/time/timestamp.go +++ /dev/null @@ -1,124 +0,0 @@ -package time - -import ( - "fmt" - "math" - "strconv" - "strings" - "time" -) - -// These are additional predefined layouts for use in Time.Format and Time.Parse -// with --since and --until parameters for `docker logs` and `docker events` -const ( - rFC3339Local = "2006-01-02T15:04:05" // RFC3339 with local timezone - rFC3339NanoLocal = "2006-01-02T15:04:05.999999999" // RFC3339Nano with local timezone - dateWithZone = "2006-01-02Z07:00" // RFC3339 with time at 00:00:00 - dateLocal = "2006-01-02" // RFC3339 with local timezone and time at 00:00:00 -) - -// GetTimestamp tries to parse given string as golang duration, -// then RFC3339 time and finally as a Unix timestamp. If -// any of these were successful, it returns a Unix timestamp -// as string otherwise returns the given value back. -// In case of duration input, the returned timestamp is computed -// as the given reference time minus the amount of the duration. -func GetTimestamp(value string, reference time.Time) (string, error) { - if d, err := time.ParseDuration(value); value != "0" && err == nil { - return strconv.FormatInt(reference.Add(-d).Unix(), 10), nil - } - - var format string - var parseInLocation bool - - // if the string has a Z or a + or three dashes use parse otherwise use parseinlocation - parseInLocation = !(strings.ContainsAny(value, "zZ+") || strings.Count(value, "-") == 3) - - if strings.Contains(value, ".") { - if parseInLocation { - format = rFC3339NanoLocal - } else { - format = time.RFC3339Nano - } - } else if strings.Contains(value, "T") { - // we want the number of colons in the T portion of the timestamp - tcolons := strings.Count(value, ":") - // if parseInLocation is off and we have a +/- zone offset (not Z) then - // there will be an extra colon in the input for the tz offset subtract that - // colon from the tcolons count - if !parseInLocation && !strings.ContainsAny(value, "zZ") && tcolons > 0 { - tcolons-- - } - if parseInLocation { - switch tcolons { - case 0: - format = "2006-01-02T15" - case 1: - format = "2006-01-02T15:04" - default: - format = rFC3339Local - } - } else { - switch tcolons { - case 0: - format = "2006-01-02T15Z07:00" - case 1: - format = "2006-01-02T15:04Z07:00" - default: - format = time.RFC3339 - } - } - } else if parseInLocation { - format = dateLocal - } else { - format = dateWithZone - } - - var t time.Time - var err error - - if parseInLocation { - t, err = time.ParseInLocation(format, value, time.FixedZone(reference.Zone())) - } else { - t, err = time.Parse(format, value) - } - - if err != nil { - // if there is a `-` then its an RFC3339 like timestamp otherwise assume unixtimestamp - if strings.Contains(value, "-") { - return "", err // was probably an RFC3339 like timestamp but the parser failed with an error - } - return value, nil // unixtimestamp in and out case (meaning: the value passed at the command line is already in the right format for passing to the server) - } - - return fmt.Sprintf("%d.%09d", t.Unix(), int64(t.Nanosecond())), nil -} - -// ParseTimestamps returns seconds and nanoseconds from a timestamp that has the -// format "%d.%09d", time.Unix(), int64(time.Nanosecond())) -// if the incoming nanosecond portion is longer or shorter than 9 digits it is -// converted to nanoseconds. The expectation is that the seconds and -// seconds will be used to create a time variable. For example: -// seconds, nanoseconds, err := ParseTimestamp("1136073600.000000001",0) -// if err == nil since := time.Unix(seconds, nanoseconds) -// returns seconds as def(aultSeconds) if value == "" -func ParseTimestamps(value string, def int64) (int64, int64, error) { - if value == "" { - return def, 0, nil - } - sa := strings.SplitN(value, ".", 2) - s, err := strconv.ParseInt(sa[0], 10, 64) - if err != nil { - return s, 0, err - } - if len(sa) != 2 { - return s, 0, nil - } - n, err := strconv.ParseInt(sa[1], 10, 64) - if err != nil { - return s, n, err - } - // should already be in nanoseconds but just in case convert n to nanoseonds - n = int64(float64(n) * math.Pow(float64(10), float64(9-len(sa[1])))) - return s, n, nil -} diff --git a/vendor/github.com/docker/docker/api/types/time/timestamp_test.go b/vendor/github.com/docker/docker/api/types/time/timestamp_test.go deleted file mode 100644 index a165130..0000000 --- a/vendor/github.com/docker/docker/api/types/time/timestamp_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package time - -import ( - "fmt" - "testing" - "time" -) - -func TestGetTimestamp(t *testing.T) { - now := time.Now().In(time.UTC) - cases := []struct { - in, expected string - expectedErr bool - }{ - // Partial RFC3339 strings get parsed with second precision - {"2006-01-02T15:04:05.999999999+07:00", "1136189045.999999999", false}, - {"2006-01-02T15:04:05.999999999Z", "1136214245.999999999", false}, - {"2006-01-02T15:04:05.999999999", "1136214245.999999999", false}, - {"2006-01-02T15:04:05Z", "1136214245.000000000", false}, - {"2006-01-02T15:04:05", "1136214245.000000000", false}, - {"2006-01-02T15:04:0Z", "", true}, - {"2006-01-02T15:04:0", "", true}, - {"2006-01-02T15:04Z", "1136214240.000000000", false}, - {"2006-01-02T15:04+00:00", "1136214240.000000000", false}, - {"2006-01-02T15:04-00:00", "1136214240.000000000", false}, - {"2006-01-02T15:04", "1136214240.000000000", false}, - {"2006-01-02T15:0Z", "", true}, - {"2006-01-02T15:0", "", true}, - {"2006-01-02T15Z", "1136214000.000000000", false}, - {"2006-01-02T15+00:00", "1136214000.000000000", false}, - {"2006-01-02T15-00:00", "1136214000.000000000", false}, - {"2006-01-02T15", "1136214000.000000000", false}, - {"2006-01-02T1Z", "1136163600.000000000", false}, - {"2006-01-02T1", "1136163600.000000000", false}, - {"2006-01-02TZ", "", true}, - {"2006-01-02T", "", true}, - {"2006-01-02+00:00", "1136160000.000000000", false}, - {"2006-01-02-00:00", "1136160000.000000000", false}, - {"2006-01-02-00:01", "1136160060.000000000", false}, - {"2006-01-02Z", "1136160000.000000000", false}, - {"2006-01-02", "1136160000.000000000", false}, - {"2015-05-13T20:39:09Z", "1431549549.000000000", false}, - - // unix timestamps returned as is - {"1136073600", "1136073600", false}, - {"1136073600.000000001", "1136073600.000000001", false}, - // Durations - {"1m", fmt.Sprintf("%d", now.Add(-1*time.Minute).Unix()), false}, - {"1.5h", fmt.Sprintf("%d", now.Add(-90*time.Minute).Unix()), false}, - {"1h30m", fmt.Sprintf("%d", now.Add(-90*time.Minute).Unix()), false}, - - // String fallback - {"invalid", "invalid", false}, - } - - for _, c := range cases { - o, err := GetTimestamp(c.in, now) - if o != c.expected || - (err == nil && c.expectedErr) || - (err != nil && !c.expectedErr) { - t.Errorf("wrong value for '%s'. expected:'%s' got:'%s' with error: `%s`", c.in, c.expected, o, err) - t.Fail() - } - } -} - -func TestParseTimestamps(t *testing.T) { - cases := []struct { - in string - def, expectedS, expectedN int64 - expectedErr bool - }{ - // unix timestamps - {"1136073600", 0, 1136073600, 0, false}, - {"1136073600.000000001", 0, 1136073600, 1, false}, - {"1136073600.0000000010", 0, 1136073600, 1, false}, - {"1136073600.00000001", 0, 1136073600, 10, false}, - {"foo.bar", 0, 0, 0, true}, - {"1136073600.bar", 0, 1136073600, 0, true}, - {"", -1, -1, 0, false}, - } - - for _, c := range cases { - s, n, err := ParseTimestamps(c.in, c.def) - if s != c.expectedS || - n != c.expectedN || - (err == nil && c.expectedErr) || - (err != nil && !c.expectedErr) { - t.Errorf("wrong values for input `%s` with default `%d` expected:'%d'seconds and `%d`nanosecond got:'%d'seconds and `%d`nanoseconds with error: `%s`", c.in, c.def, c.expectedS, c.expectedN, s, n, err) - t.Fail() - } - } -} diff --git a/vendor/github.com/docker/docker/api/types/types.go b/vendor/github.com/docker/docker/api/types/types.go deleted file mode 100644 index a82c3e8..0000000 --- a/vendor/github.com/docker/docker/api/types/types.go +++ /dev/null @@ -1,549 +0,0 @@ -package types - -import ( - "errors" - "fmt" - "io" - "os" - "strings" - "time" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/api/types/network" - "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/go-connections/nat" -) - -// ContainerChange contains response of Engine API: -// GET "/containers/{name:.*}/changes" -type ContainerChange struct { - Kind int - Path string -} - -// ImageHistory contains response of Engine API: -// GET "/images/{name:.*}/history" -type ImageHistory struct { - ID string `json:"Id"` - Created int64 - CreatedBy string - Tags []string - Size int64 - Comment string -} - -// ImageDelete contains response of Engine API: -// DELETE "/images/{name:.*}" -type ImageDelete struct { - Untagged string `json:",omitempty"` - Deleted string `json:",omitempty"` -} - -// GraphDriverData returns Image's graph driver config info -// when calling inspect command -type GraphDriverData struct { - Name string - Data map[string]string -} - -// RootFS returns Image's RootFS description including the layer IDs. -type RootFS struct { - Type string - Layers []string `json:",omitempty"` - BaseLayer string `json:",omitempty"` -} - -// ImageInspect contains response of Engine API: -// GET "/images/{name:.*}/json" -type ImageInspect struct { - ID string `json:"Id"` - RepoTags []string - RepoDigests []string - Parent string - Comment string - Created string - Container string - ContainerConfig *container.Config - DockerVersion string - Author string - Config *container.Config - Architecture string - Os string - OsVersion string `json:",omitempty"` - Size int64 - VirtualSize int64 - GraphDriver GraphDriverData - RootFS RootFS -} - -// Container contains response of Engine API: -// GET "/containers/json" -type Container struct { - ID string `json:"Id"` - Names []string - Image string - ImageID string - Command string - Created int64 - Ports []Port - SizeRw int64 `json:",omitempty"` - SizeRootFs int64 `json:",omitempty"` - Labels map[string]string - State string - Status string - HostConfig struct { - NetworkMode string `json:",omitempty"` - } - NetworkSettings *SummaryNetworkSettings - Mounts []MountPoint -} - -// CopyConfig contains request body of Engine API: -// POST "/containers/"+containerID+"/copy" -type CopyConfig struct { - Resource string -} - -// ContainerPathStat is used to encode the header from -// GET "/containers/{name:.*}/archive" -// "Name" is the file or directory name. -type ContainerPathStat struct { - Name string `json:"name"` - Size int64 `json:"size"` - Mode os.FileMode `json:"mode"` - Mtime time.Time `json:"mtime"` - LinkTarget string `json:"linkTarget"` -} - -// ContainerStats contains response of Engine API: -// GET "/stats" -type ContainerStats struct { - Body io.ReadCloser `json:"body"` - OSType string `json:"ostype"` -} - -// ContainerProcessList contains response of Engine API: -// GET "/containers/{name:.*}/top" -type ContainerProcessList struct { - Processes [][]string - Titles []string -} - -// Ping contains response of Engine API: -// GET "/_ping" -type Ping struct { - APIVersion string - Experimental bool -} - -// Version contains response of Engine API: -// GET "/version" -type Version struct { - Version string - APIVersion string `json:"ApiVersion"` - MinAPIVersion string `json:"MinAPIVersion,omitempty"` - GitCommit string - GoVersion string - Os string - Arch string - KernelVersion string `json:",omitempty"` - Experimental bool `json:",omitempty"` - BuildTime string `json:",omitempty"` -} - -// Commit records a external tool actual commit id version along the -// one expect by dockerd as set at build time -type Commit struct { - ID string - Expected string -} - -// Info contains response of Engine API: -// GET "/info" -type Info struct { - ID string - Containers int - ContainersRunning int - ContainersPaused int - ContainersStopped int - Images int - Driver string - DriverStatus [][2]string - SystemStatus [][2]string - Plugins PluginsInfo - MemoryLimit bool - SwapLimit bool - KernelMemory bool - CPUCfsPeriod bool `json:"CpuCfsPeriod"` - CPUCfsQuota bool `json:"CpuCfsQuota"` - CPUShares bool - CPUSet bool - IPv4Forwarding bool - BridgeNfIptables bool - BridgeNfIP6tables bool `json:"BridgeNfIp6tables"` - Debug bool - NFd int - OomKillDisable bool - NGoroutines int - SystemTime string - LoggingDriver string - CgroupDriver string - NEventsListener int - KernelVersion string - OperatingSystem string - OSType string - Architecture string - IndexServerAddress string - RegistryConfig *registry.ServiceConfig - NCPU int - MemTotal int64 - DockerRootDir string - HTTPProxy string `json:"HttpProxy"` - HTTPSProxy string `json:"HttpsProxy"` - NoProxy string - Name string - Labels []string - ExperimentalBuild bool - ServerVersion string - ClusterStore string - ClusterAdvertise string - Runtimes map[string]Runtime - DefaultRuntime string - Swarm swarm.Info - // LiveRestoreEnabled determines whether containers should be kept - // running when the daemon is shutdown or upon daemon start if - // running containers are detected - LiveRestoreEnabled bool - Isolation container.Isolation - InitBinary string - ContainerdCommit Commit - RuncCommit Commit - InitCommit Commit - SecurityOptions []string -} - -// KeyValue holds a key/value pair -type KeyValue struct { - Key, Value string -} - -// SecurityOpt contains the name and options of a security option -type SecurityOpt struct { - Name string - Options []KeyValue -} - -// DecodeSecurityOptions decodes a security options string slice to a type safe -// SecurityOpt -func DecodeSecurityOptions(opts []string) ([]SecurityOpt, error) { - so := []SecurityOpt{} - for _, opt := range opts { - // support output from a < 1.13 docker daemon - if !strings.Contains(opt, "=") { - so = append(so, SecurityOpt{Name: opt}) - continue - } - secopt := SecurityOpt{} - split := strings.Split(opt, ",") - for _, s := range split { - kv := strings.SplitN(s, "=", 2) - if len(kv) != 2 { - return nil, fmt.Errorf("invalid security option %q", s) - } - if kv[0] == "" || kv[1] == "" { - return nil, errors.New("invalid empty security option") - } - if kv[0] == "name" { - secopt.Name = kv[1] - continue - } - secopt.Options = append(secopt.Options, KeyValue{Key: kv[0], Value: kv[1]}) - } - so = append(so, secopt) - } - return so, nil -} - -// PluginsInfo is a temp struct holding Plugins name -// registered with docker daemon. It is used by Info struct -type PluginsInfo struct { - // List of Volume plugins registered - Volume []string - // List of Network plugins registered - Network []string - // List of Authorization plugins registered - Authorization []string -} - -// ExecStartCheck is a temp struct used by execStart -// Config fields is part of ExecConfig in runconfig package -type ExecStartCheck struct { - // ExecStart will first check if it's detached - Detach bool - // Check if there's a tty - Tty bool -} - -// HealthcheckResult stores information about a single run of a healthcheck probe -type HealthcheckResult struct { - Start time.Time // Start is the time this check started - End time.Time // End is the time this check ended - ExitCode int // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe - Output string // Output from last check -} - -// Health states -const ( - NoHealthcheck = "none" // Indicates there is no healthcheck - Starting = "starting" // Starting indicates that the container is not yet ready - Healthy = "healthy" // Healthy indicates that the container is running correctly - Unhealthy = "unhealthy" // Unhealthy indicates that the container has a problem -) - -// Health stores information about the container's healthcheck results -type Health struct { - Status string // Status is one of Starting, Healthy or Unhealthy - FailingStreak int // FailingStreak is the number of consecutive failures - Log []*HealthcheckResult // Log contains the last few results (oldest first) -} - -// ContainerState stores container's running state -// it's part of ContainerJSONBase and will return by "inspect" command -type ContainerState struct { - Status string - Running bool - Paused bool - Restarting bool - OOMKilled bool - Dead bool - Pid int - ExitCode int - Error string - StartedAt string - FinishedAt string - Health *Health `json:",omitempty"` -} - -// ContainerNode stores information about the node that a container -// is running on. It's only available in Docker Swarm -type ContainerNode struct { - ID string - IPAddress string `json:"IP"` - Addr string - Name string - Cpus int - Memory int64 - Labels map[string]string -} - -// ContainerJSONBase contains response of Engine API: -// GET "/containers/{name:.*}/json" -type ContainerJSONBase struct { - ID string `json:"Id"` - Created string - Path string - Args []string - State *ContainerState - Image string - ResolvConfPath string - HostnamePath string - HostsPath string - LogPath string - Node *ContainerNode `json:",omitempty"` - Name string - RestartCount int - Driver string - MountLabel string - ProcessLabel string - AppArmorProfile string - ExecIDs []string - HostConfig *container.HostConfig - GraphDriver GraphDriverData - SizeRw *int64 `json:",omitempty"` - SizeRootFs *int64 `json:",omitempty"` -} - -// ContainerJSON is newly used struct along with MountPoint -type ContainerJSON struct { - *ContainerJSONBase - Mounts []MountPoint - Config *container.Config - NetworkSettings *NetworkSettings -} - -// NetworkSettings exposes the network settings in the api -type NetworkSettings struct { - NetworkSettingsBase - DefaultNetworkSettings - Networks map[string]*network.EndpointSettings -} - -// SummaryNetworkSettings provides a summary of container's networks -// in /containers/json -type SummaryNetworkSettings struct { - Networks map[string]*network.EndpointSettings -} - -// NetworkSettingsBase holds basic information about networks -type NetworkSettingsBase struct { - Bridge string // Bridge is the Bridge name the network uses(e.g. `docker0`) - SandboxID string // SandboxID uniquely represents a container's network stack - HairpinMode bool // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface - LinkLocalIPv6Address string // LinkLocalIPv6Address is an IPv6 unicast address using the link-local prefix - LinkLocalIPv6PrefixLen int // LinkLocalIPv6PrefixLen is the prefix length of an IPv6 unicast address - Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port - SandboxKey string // SandboxKey identifies the sandbox - SecondaryIPAddresses []network.Address - SecondaryIPv6Addresses []network.Address -} - -// DefaultNetworkSettings holds network information -// during the 2 release deprecation period. -// It will be removed in Docker 1.11. -type DefaultNetworkSettings struct { - EndpointID string // EndpointID uniquely represents a service endpoint in a Sandbox - Gateway string // Gateway holds the gateway address for the network - GlobalIPv6Address string // GlobalIPv6Address holds network's global IPv6 address - GlobalIPv6PrefixLen int // GlobalIPv6PrefixLen represents mask length of network's global IPv6 address - IPAddress string // IPAddress holds the IPv4 address for the network - IPPrefixLen int // IPPrefixLen represents mask length of network's IPv4 address - IPv6Gateway string // IPv6Gateway holds gateway address specific for IPv6 - MacAddress string // MacAddress holds the MAC address for the network -} - -// MountPoint represents a mount point configuration inside the container. -// This is used for reporting the mountpoints in use by a container. -type MountPoint struct { - Type mount.Type `json:",omitempty"` - Name string `json:",omitempty"` - Source string - Destination string - Driver string `json:",omitempty"` - Mode string - RW bool - Propagation mount.Propagation -} - -// NetworkResource is the body of the "get network" http response message -type NetworkResource struct { - Name string // Name is the requested name of the network - ID string `json:"Id"` // ID uniquely identifies a network on a single machine - Created time.Time // Created is the time the network created - Scope string // Scope describes the level at which the network exists (e.g. `global` for cluster-wide or `local` for machine level) - Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`) - EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6 - IPAM network.IPAM // IPAM is the network's IP Address Management - Internal bool // Internal represents if the network is used internal only - Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode. - Containers map[string]EndpointResource // Containers contains endpoints belonging to the network - Options map[string]string // Options holds the network specific options to use for when creating the network - Labels map[string]string // Labels holds metadata specific to the network being created - Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network -} - -// EndpointResource contains network resources allocated and used for a container in a network -type EndpointResource struct { - Name string - EndpointID string - MacAddress string - IPv4Address string - IPv6Address string -} - -// NetworkCreate is the expected body of the "create network" http request message -type NetworkCreate struct { - CheckDuplicate bool - Driver string - EnableIPv6 bool - IPAM *network.IPAM - Internal bool - Attachable bool - Options map[string]string - Labels map[string]string -} - -// NetworkCreateRequest is the request message sent to the server for network create call. -type NetworkCreateRequest struct { - NetworkCreate - Name string -} - -// NetworkCreateResponse is the response message sent by the server for network create call -type NetworkCreateResponse struct { - ID string `json:"Id"` - Warning string -} - -// NetworkConnect represents the data to be used to connect a container to the network -type NetworkConnect struct { - Container string - EndpointConfig *network.EndpointSettings `json:",omitempty"` -} - -// NetworkDisconnect represents the data to be used to disconnect a container from the network -type NetworkDisconnect struct { - Container string - Force bool -} - -// Checkpoint represents the details of a checkpoint -type Checkpoint struct { - Name string // Name is the name of the checkpoint -} - -// Runtime describes an OCI runtime -type Runtime struct { - Path string `json:"path"` - Args []string `json:"runtimeArgs,omitempty"` -} - -// DiskUsage contains response of Engine API: -// GET "/system/df" -type DiskUsage struct { - LayersSize int64 - Images []*ImageSummary - Containers []*Container - Volumes []*Volume -} - -// ContainersPruneReport contains the response for Engine API: -// POST "/containers/prune" -type ContainersPruneReport struct { - ContainersDeleted []string - SpaceReclaimed uint64 -} - -// VolumesPruneReport contains the response for Engine API: -// POST "/volumes/prune" -type VolumesPruneReport struct { - VolumesDeleted []string - SpaceReclaimed uint64 -} - -// ImagesPruneReport contains the response for Engine API: -// POST "/images/prune" -type ImagesPruneReport struct { - ImagesDeleted []ImageDelete - SpaceReclaimed uint64 -} - -// NetworksPruneReport contains the response for Engine API: -// POST "/networks/prune" -type NetworksPruneReport struct { - NetworksDeleted []string -} - -// SecretCreateResponse contains the information returned to a client -// on the creation of a new secret. -type SecretCreateResponse struct { - // ID is the id of the created secret. - ID string -} - -// SecretListOptions holds parameters to list secrets -type SecretListOptions struct { - Filters filters.Args -} diff --git a/vendor/github.com/docker/docker/api/types/versions/README.md b/vendor/github.com/docker/docker/api/types/versions/README.md deleted file mode 100644 index cdac50a..0000000 --- a/vendor/github.com/docker/docker/api/types/versions/README.md +++ /dev/null @@ -1,14 +0,0 @@ -## Legacy API type versions - -This package includes types for legacy API versions. The stable version of the API types live in `api/types/*.go`. - -Consider moving a type here when you need to keep backwards compatibility in the API. This legacy types are organized by the latest API version they appear in. For instance, types in the `v1p19` package are valid for API versions below or equal `1.19`. Types in the `v1p20` package are valid for the API version `1.20`, since the versions below that will use the legacy types in `v1p19`. - -### Package name conventions - -The package name convention is to use `v` as a prefix for the version number and `p`(patch) as a separator. We use this nomenclature due to a few restrictions in the Go package name convention: - -1. We cannot use `.` because it's interpreted by the language, think of `v1.20.CallFunction`. -2. We cannot use `_` because golint complains about it. The code is actually valid, but it looks probably more weird: `v1_20.CallFunction`. - -For instance, if you want to modify a type that was available in the version `1.21` of the API but it will have different fields in the version `1.22`, you want to create a new package under `api/types/versions/v1p21`. diff --git a/vendor/github.com/docker/docker/api/types/versions/compare.go b/vendor/github.com/docker/docker/api/types/versions/compare.go deleted file mode 100644 index 611d4fe..0000000 --- a/vendor/github.com/docker/docker/api/types/versions/compare.go +++ /dev/null @@ -1,62 +0,0 @@ -package versions - -import ( - "strconv" - "strings" -) - -// compare compares two version strings -// returns -1 if v1 < v2, 1 if v1 > v2, 0 otherwise. -func compare(v1, v2 string) int { - var ( - currTab = strings.Split(v1, ".") - otherTab = strings.Split(v2, ".") - ) - - max := len(currTab) - if len(otherTab) > max { - max = len(otherTab) - } - for i := 0; i < max; i++ { - var currInt, otherInt int - - if len(currTab) > i { - currInt, _ = strconv.Atoi(currTab[i]) - } - if len(otherTab) > i { - otherInt, _ = strconv.Atoi(otherTab[i]) - } - if currInt > otherInt { - return 1 - } - if otherInt > currInt { - return -1 - } - } - return 0 -} - -// LessThan checks if a version is less than another -func LessThan(v, other string) bool { - return compare(v, other) == -1 -} - -// LessThanOrEqualTo checks if a version is less than or equal to another -func LessThanOrEqualTo(v, other string) bool { - return compare(v, other) <= 0 -} - -// GreaterThan checks if a version is greater than another -func GreaterThan(v, other string) bool { - return compare(v, other) == 1 -} - -// GreaterThanOrEqualTo checks if a version is greater than or equal to another -func GreaterThanOrEqualTo(v, other string) bool { - return compare(v, other) >= 0 -} - -// Equal checks if a version is equal to another -func Equal(v, other string) bool { - return compare(v, other) == 0 -} diff --git a/vendor/github.com/docker/docker/api/types/versions/compare_test.go b/vendor/github.com/docker/docker/api/types/versions/compare_test.go deleted file mode 100644 index c2b9686..0000000 --- a/vendor/github.com/docker/docker/api/types/versions/compare_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package versions - -import ( - "testing" -) - -func assertVersion(t *testing.T, a, b string, result int) { - if r := compare(a, b); r != result { - t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result) - } -} - -func TestCompareVersion(t *testing.T) { - assertVersion(t, "1.12", "1.12", 0) - assertVersion(t, "1.0.0", "1", 0) - assertVersion(t, "1", "1.0.0", 0) - assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1) - assertVersion(t, "1", "1.0.1", -1) - assertVersion(t, "1.0.1", "1", 1) - assertVersion(t, "1.0.1", "1.0.2", -1) - assertVersion(t, "1.0.2", "1.0.3", -1) - assertVersion(t, "1.0.3", "1.1", -1) - assertVersion(t, "1.1", "1.1.1", -1) - assertVersion(t, "1.1.1", "1.1.2", -1) - assertVersion(t, "1.1.2", "1.2", -1) -} diff --git a/vendor/github.com/docker/docker/api/types/versions/v1p19/types.go b/vendor/github.com/docker/docker/api/types/versions/v1p19/types.go deleted file mode 100644 index dc13150..0000000 --- a/vendor/github.com/docker/docker/api/types/versions/v1p19/types.go +++ /dev/null @@ -1,35 +0,0 @@ -// Package v1p19 provides specific API types for the API version 1, patch 19. -package v1p19 - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/versions/v1p20" - "github.com/docker/go-connections/nat" -) - -// ContainerJSON is a backcompatibility struct for APIs prior to 1.20. -// Note this is not used by the Windows daemon. -type ContainerJSON struct { - *types.ContainerJSONBase - Volumes map[string]string - VolumesRW map[string]bool - Config *ContainerConfig - NetworkSettings *v1p20.NetworkSettings -} - -// ContainerConfig is a backcompatibility struct for APIs prior to 1.20. -type ContainerConfig struct { - *container.Config - - MacAddress string - NetworkDisabled bool - ExposedPorts map[nat.Port]struct{} - - // backward compatibility, they now live in HostConfig - VolumeDriver string - Memory int64 - MemorySwap int64 - CPUShares int64 `json:"CpuShares"` - CPUSet string `json:"Cpuset"` -} diff --git a/vendor/github.com/docker/docker/api/types/versions/v1p20/types.go b/vendor/github.com/docker/docker/api/types/versions/v1p20/types.go deleted file mode 100644 index 94a06d7..0000000 --- a/vendor/github.com/docker/docker/api/types/versions/v1p20/types.go +++ /dev/null @@ -1,40 +0,0 @@ -// Package v1p20 provides specific API types for the API version 1, patch 20. -package v1p20 - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/go-connections/nat" -) - -// ContainerJSON is a backcompatibility struct for the API 1.20 -type ContainerJSON struct { - *types.ContainerJSONBase - Mounts []types.MountPoint - Config *ContainerConfig - NetworkSettings *NetworkSettings -} - -// ContainerConfig is a backcompatibility struct used in ContainerJSON for the API 1.20 -type ContainerConfig struct { - *container.Config - - MacAddress string - NetworkDisabled bool - ExposedPorts map[nat.Port]struct{} - - // backward compatibility, they now live in HostConfig - VolumeDriver string -} - -// StatsJSON is a backcompatibility struct used in Stats for APIs prior to 1.21 -type StatsJSON struct { - types.Stats - Network types.NetworkStats `json:"network,omitempty"` -} - -// NetworkSettings is a backward compatible struct for APIs prior to 1.21 -type NetworkSettings struct { - types.NetworkSettingsBase - types.DefaultNetworkSettings -} diff --git a/vendor/github.com/docker/docker/api/types/volume.go b/vendor/github.com/docker/docker/api/types/volume.go deleted file mode 100644 index da4f8eb..0000000 --- a/vendor/github.com/docker/docker/api/types/volume.go +++ /dev/null @@ -1,58 +0,0 @@ -package types - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -// Volume volume -// swagger:model Volume -type Volume struct { - - // Name of the volume driver used by the volume. - // Required: true - Driver string `json:"Driver"` - - // User-defined key/value metadata. - // Required: true - Labels map[string]string `json:"Labels"` - - // Mount path of the volume on the host. - // Required: true - Mountpoint string `json:"Mountpoint"` - - // Name of the volume. - // Required: true - Name string `json:"Name"` - - // The driver specific options used when creating the volume. - // Required: true - Options map[string]string `json:"Options"` - - // The level at which the volume exists. Either `global` for cluster-wide, or `local` for machine level. - // Required: true - Scope string `json:"Scope"` - - // Low-level details about the volume, provided by the volume driver. - // Details are returned as a map with key/value pairs: - // `{"key":"value","key2":"value2"}`. - // - // The `Status` field is optional, and is omitted if the volume driver - // does not support this feature. - // - Status map[string]interface{} `json:"Status,omitempty"` - - // usage data - UsageData *VolumeUsageData `json:"UsageData,omitempty"` -} - -// VolumeUsageData volume usage data -// swagger:model VolumeUsageData -type VolumeUsageData struct { - - // The number of containers referencing this volume. - // Required: true - RefCount int64 `json:"RefCount"` - - // The disk space used by the volume (local driver only) - // Required: true - Size int64 `json:"Size"` -} diff --git a/vendor/github.com/docker/docker/api/types/volume/volumes_create.go b/vendor/github.com/docker/docker/api/types/volume/volumes_create.go deleted file mode 100644 index 679c160..0000000 --- a/vendor/github.com/docker/docker/api/types/volume/volumes_create.go +++ /dev/null @@ -1,29 +0,0 @@ -package volume - -// ---------------------------------------------------------------------------- -// DO NOT EDIT THIS FILE -// This file was generated by `swagger generate operation` -// -// See hack/swagger-gen.sh -// ---------------------------------------------------------------------------- - -// VolumesCreateBody volumes create body -// swagger:model VolumesCreateBody -type VolumesCreateBody struct { - - // Name of the volume driver to use. - // Required: true - Driver string `json:"Driver"` - - // A mapping of driver options and values. These options are passed directly to the driver and are driver specific. - // Required: true - DriverOpts map[string]string `json:"DriverOpts"` - - // User-defined key/value metadata. - // Required: true - Labels map[string]string `json:"Labels"` - - // The new volume's name. If not specified, Docker generates a name. - // Required: true - Name string `json:"Name"` -} diff --git a/vendor/github.com/docker/docker/api/types/volume/volumes_list.go b/vendor/github.com/docker/docker/api/types/volume/volumes_list.go deleted file mode 100644 index 7770bcb..0000000 --- a/vendor/github.com/docker/docker/api/types/volume/volumes_list.go +++ /dev/null @@ -1,23 +0,0 @@ -package volume - -// ---------------------------------------------------------------------------- -// DO NOT EDIT THIS FILE -// This file was generated by `swagger generate operation` -// -// See hack/swagger-gen.sh -// ---------------------------------------------------------------------------- - -import "github.com/docker/docker/api/types" - -// VolumesListOKBody volumes list o k body -// swagger:model VolumesListOKBody -type VolumesListOKBody struct { - - // List of volumes - // Required: true - Volumes []*types.Volume `json:"Volumes"` - - // Warnings that occurred when fetching the list of volumes - // Required: true - Warnings []string `json:"Warnings"` -} diff --git a/vendor/github.com/docker/docker/builder/builder.go b/vendor/github.com/docker/docker/builder/builder.go deleted file mode 100644 index ced19e8..0000000 --- a/vendor/github.com/docker/docker/builder/builder.go +++ /dev/null @@ -1,169 +0,0 @@ -// Package builder defines interfaces for any Docker builder to implement. -// -// Historically, only server-side Dockerfile interpreters existed. -// This package allows for other implementations of Docker builders. -package builder - -import ( - "io" - "os" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/image" - "github.com/docker/docker/reference" - "golang.org/x/net/context" -) - -const ( - // DefaultDockerfileName is the Default filename with Docker commands, read by docker build - DefaultDockerfileName string = "Dockerfile" -) - -// Context represents a file system tree. -type Context interface { - // Close allows to signal that the filesystem tree won't be used anymore. - // For Context implementations using a temporary directory, it is recommended to - // delete the temporary directory in Close(). - Close() error - // Stat returns an entry corresponding to path if any. - // It is recommended to return an error if path was not found. - // If path is a symlink it also returns the path to the target file. - Stat(path string) (string, FileInfo, error) - // Open opens path from the context and returns a readable stream of it. - Open(path string) (io.ReadCloser, error) - // Walk walks the tree of the context with the function passed to it. - Walk(root string, walkFn WalkFunc) error -} - -// WalkFunc is the type of the function called for each file or directory visited by Context.Walk(). -type WalkFunc func(path string, fi FileInfo, err error) error - -// ModifiableContext represents a modifiable Context. -// TODO: remove this interface once we can get rid of Remove() -type ModifiableContext interface { - Context - // Remove deletes the entry specified by `path`. - // It is usual for directory entries to delete all its subentries. - Remove(path string) error -} - -// FileInfo extends os.FileInfo to allow retrieving an absolute path to the file. -// TODO: remove this interface once pkg/archive exposes a walk function that Context can use. -type FileInfo interface { - os.FileInfo - Path() string -} - -// PathFileInfo is a convenience struct that implements the FileInfo interface. -type PathFileInfo struct { - os.FileInfo - // FilePath holds the absolute path to the file. - FilePath string - // Name holds the basename for the file. - FileName string -} - -// Path returns the absolute path to the file. -func (fi PathFileInfo) Path() string { - return fi.FilePath -} - -// Name returns the basename of the file. -func (fi PathFileInfo) Name() string { - if fi.FileName != "" { - return fi.FileName - } - return fi.FileInfo.Name() -} - -// Hashed defines an extra method intended for implementations of os.FileInfo. -type Hashed interface { - // Hash returns the hash of a file. - Hash() string - SetHash(string) -} - -// HashedFileInfo is a convenient struct that augments FileInfo with a field. -type HashedFileInfo struct { - FileInfo - // FileHash represents the hash of a file. - FileHash string -} - -// Hash returns the hash of a file. -func (fi HashedFileInfo) Hash() string { - return fi.FileHash -} - -// SetHash sets the hash of a file. -func (fi *HashedFileInfo) SetHash(h string) { - fi.FileHash = h -} - -// Backend abstracts calls to a Docker Daemon. -type Backend interface { - // TODO: use digest reference instead of name - - // GetImageOnBuild looks up a Docker image referenced by `name`. - GetImageOnBuild(name string) (Image, error) - // TagImage tags an image with newTag - TagImageWithReference(image.ID, reference.Named) error - // PullOnBuild tells Docker to pull image referenced by `name`. - PullOnBuild(ctx context.Context, name string, authConfigs map[string]types.AuthConfig, output io.Writer) (Image, error) - // ContainerAttachRaw attaches to container. - ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error - // ContainerCreate creates a new Docker container and returns potential warnings - ContainerCreate(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error) - // ContainerRm removes a container specified by `id`. - ContainerRm(name string, config *types.ContainerRmConfig) error - // Commit creates a new Docker image from an existing Docker container. - Commit(string, *backend.ContainerCommitConfig) (string, error) - // ContainerKill stops the container execution abruptly. - ContainerKill(containerID string, sig uint64) error - // ContainerStart starts a new container - ContainerStart(containerID string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error - // ContainerWait stops processing until the given container is stopped. - ContainerWait(containerID string, timeout time.Duration) (int, error) - // ContainerUpdateCmdOnBuild updates container.Path and container.Args - ContainerUpdateCmdOnBuild(containerID string, cmd []string) error - // ContainerCreateWorkdir creates the workdir (currently only used on Windows) - ContainerCreateWorkdir(containerID string) error - - // ContainerCopy copies/extracts a source FileInfo to a destination path inside a container - // specified by a container object. - // TODO: make an Extract method instead of passing `decompress` - // TODO: do not pass a FileInfo, instead refactor the archive package to export a Walk function that can be used - // with Context.Walk - // ContainerCopy(name string, res string) (io.ReadCloser, error) - // TODO: use copyBackend api - CopyOnBuild(containerID string, destPath string, src FileInfo, decompress bool) error - - // HasExperimental checks if the backend supports experimental features - HasExperimental() bool - - // SquashImage squashes the fs layers from the provided image down to the specified `to` image - SquashImage(from string, to string) (string, error) -} - -// Image represents a Docker image used by the builder. -type Image interface { - ImageID() string - RunConfig() *container.Config -} - -// ImageCacheBuilder represents a generator for stateful image cache. -type ImageCacheBuilder interface { - // MakeImageCache creates a stateful image cache. - MakeImageCache(cacheFrom []string) ImageCache -} - -// ImageCache abstracts an image cache. -// (parent image, child runconfig) -> child image -type ImageCache interface { - // GetCachedImageOnBuild returns a reference to a cached image whose parent equals `parent` - // and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error. - GetCache(parentID string, cfg *container.Config) (imageID string, err error) -} diff --git a/vendor/github.com/docker/docker/builder/context.go b/vendor/github.com/docker/docker/builder/context.go deleted file mode 100644 index 600f423..0000000 --- a/vendor/github.com/docker/docker/builder/context.go +++ /dev/null @@ -1,260 +0,0 @@ -package builder - -import ( - "bufio" - "fmt" - "io" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "runtime" - "strings" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/fileutils" - "github.com/docker/docker/pkg/gitutils" - "github.com/docker/docker/pkg/httputils" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/streamformatter" -) - -// ValidateContextDirectory checks if all the contents of the directory -// can be read and returns an error if some files can't be read -// symlinks which point to non-existing files don't trigger an error -func ValidateContextDirectory(srcPath string, excludes []string) error { - contextRoot, err := getContextRoot(srcPath) - if err != nil { - return err - } - return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error { - if err != nil { - if os.IsPermission(err) { - return fmt.Errorf("can't stat '%s'", filePath) - } - if os.IsNotExist(err) { - return nil - } - return err - } - - // skip this directory/file if it's not in the path, it won't get added to the context - if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil { - return err - } else if skip, err := fileutils.Matches(relFilePath, excludes); err != nil { - return err - } else if skip { - if f.IsDir() { - return filepath.SkipDir - } - return nil - } - - // skip checking if symlinks point to non-existing files, such symlinks can be useful - // also skip named pipes, because they hanging on open - if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 { - return nil - } - - if !f.IsDir() { - currentFile, err := os.Open(filePath) - if err != nil && os.IsPermission(err) { - return fmt.Errorf("no permission to read from '%s'", filePath) - } - currentFile.Close() - } - return nil - }) -} - -// GetContextFromReader will read the contents of the given reader as either a -// Dockerfile or tar archive. Returns a tar archive used as a context and a -// path to the Dockerfile inside the tar. -func GetContextFromReader(r io.ReadCloser, dockerfileName string) (out io.ReadCloser, relDockerfile string, err error) { - buf := bufio.NewReader(r) - - magic, err := buf.Peek(archive.HeaderSize) - if err != nil && err != io.EOF { - return nil, "", fmt.Errorf("failed to peek context header from STDIN: %v", err) - } - - if archive.IsArchive(magic) { - return ioutils.NewReadCloserWrapper(buf, func() error { return r.Close() }), dockerfileName, nil - } - - // Input should be read as a Dockerfile. - tmpDir, err := ioutil.TempDir("", "docker-build-context-") - if err != nil { - return nil, "", fmt.Errorf("unbale to create temporary context directory: %v", err) - } - - f, err := os.Create(filepath.Join(tmpDir, DefaultDockerfileName)) - if err != nil { - return nil, "", err - } - _, err = io.Copy(f, buf) - if err != nil { - f.Close() - return nil, "", err - } - - if err := f.Close(); err != nil { - return nil, "", err - } - if err := r.Close(); err != nil { - return nil, "", err - } - - tar, err := archive.Tar(tmpDir, archive.Uncompressed) - if err != nil { - return nil, "", err - } - - return ioutils.NewReadCloserWrapper(tar, func() error { - err := tar.Close() - os.RemoveAll(tmpDir) - return err - }), DefaultDockerfileName, nil - -} - -// GetContextFromGitURL uses a Git URL as context for a `docker build`. The -// git repo is cloned into a temporary directory used as the context directory. -// Returns the absolute path to the temporary context directory, the relative -// path of the dockerfile in that context directory, and a non-nil error on -// success. -func GetContextFromGitURL(gitURL, dockerfileName string) (absContextDir, relDockerfile string, err error) { - if _, err := exec.LookPath("git"); err != nil { - return "", "", fmt.Errorf("unable to find 'git': %v", err) - } - if absContextDir, err = gitutils.Clone(gitURL); err != nil { - return "", "", fmt.Errorf("unable to 'git clone' to temporary context directory: %v", err) - } - - return getDockerfileRelPath(absContextDir, dockerfileName) -} - -// GetContextFromURL uses a remote URL as context for a `docker build`. The -// remote resource is downloaded as either a Dockerfile or a tar archive. -// Returns the tar archive used for the context and a path of the -// dockerfile inside the tar. -func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.ReadCloser, string, error) { - response, err := httputils.Download(remoteURL) - if err != nil { - return nil, "", fmt.Errorf("unable to download remote context %s: %v", remoteURL, err) - } - progressOutput := streamformatter.NewStreamFormatter().NewProgressOutput(out, true) - - // Pass the response body through a progress reader. - progReader := progress.NewProgressReader(response.Body, progressOutput, response.ContentLength, "", fmt.Sprintf("Downloading build context from remote url: %s", remoteURL)) - - return GetContextFromReader(ioutils.NewReadCloserWrapper(progReader, func() error { return response.Body.Close() }), dockerfileName) -} - -// GetContextFromLocalDir uses the given local directory as context for a -// `docker build`. Returns the absolute path to the local context directory, -// the relative path of the dockerfile in that context directory, and a non-nil -// error on success. -func GetContextFromLocalDir(localDir, dockerfileName string) (absContextDir, relDockerfile string, err error) { - // When using a local context directory, when the Dockerfile is specified - // with the `-f/--file` option then it is considered relative to the - // current directory and not the context directory. - if dockerfileName != "" { - if dockerfileName, err = filepath.Abs(dockerfileName); err != nil { - return "", "", fmt.Errorf("unable to get absolute path to Dockerfile: %v", err) - } - } - - return getDockerfileRelPath(localDir, dockerfileName) -} - -// getDockerfileRelPath uses the given context directory for a `docker build` -// and returns the absolute path to the context directory, the relative path of -// the dockerfile in that context directory, and a non-nil error on success. -func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDir, relDockerfile string, err error) { - if absContextDir, err = filepath.Abs(givenContextDir); err != nil { - return "", "", fmt.Errorf("unable to get absolute context directory of given context directory %q: %v", givenContextDir, err) - } - - // The context dir might be a symbolic link, so follow it to the actual - // target directory. - // - // FIXME. We use isUNC (always false on non-Windows platforms) to workaround - // an issue in golang. On Windows, EvalSymLinks does not work on UNC file - // paths (those starting with \\). This hack means that when using links - // on UNC paths, they will not be followed. - if !isUNC(absContextDir) { - absContextDir, err = filepath.EvalSymlinks(absContextDir) - if err != nil { - return "", "", fmt.Errorf("unable to evaluate symlinks in context path: %v", err) - } - } - - stat, err := os.Lstat(absContextDir) - if err != nil { - return "", "", fmt.Errorf("unable to stat context directory %q: %v", absContextDir, err) - } - - if !stat.IsDir() { - return "", "", fmt.Errorf("context must be a directory: %s", absContextDir) - } - - absDockerfile := givenDockerfile - if absDockerfile == "" { - // No -f/--file was specified so use the default relative to the - // context directory. - absDockerfile = filepath.Join(absContextDir, DefaultDockerfileName) - - // Just to be nice ;-) look for 'dockerfile' too but only - // use it if we found it, otherwise ignore this check - if _, err = os.Lstat(absDockerfile); os.IsNotExist(err) { - altPath := filepath.Join(absContextDir, strings.ToLower(DefaultDockerfileName)) - if _, err = os.Lstat(altPath); err == nil { - absDockerfile = altPath - } - } - } - - // If not already an absolute path, the Dockerfile path should be joined to - // the base directory. - if !filepath.IsAbs(absDockerfile) { - absDockerfile = filepath.Join(absContextDir, absDockerfile) - } - - // Evaluate symlinks in the path to the Dockerfile too. - // - // FIXME. We use isUNC (always false on non-Windows platforms) to workaround - // an issue in golang. On Windows, EvalSymLinks does not work on UNC file - // paths (those starting with \\). This hack means that when using links - // on UNC paths, they will not be followed. - if !isUNC(absDockerfile) { - absDockerfile, err = filepath.EvalSymlinks(absDockerfile) - if err != nil { - return "", "", fmt.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err) - } - } - - if _, err := os.Lstat(absDockerfile); err != nil { - if os.IsNotExist(err) { - return "", "", fmt.Errorf("Cannot locate Dockerfile: %q", absDockerfile) - } - return "", "", fmt.Errorf("unable to stat Dockerfile: %v", err) - } - - if relDockerfile, err = filepath.Rel(absContextDir, absDockerfile); err != nil { - return "", "", fmt.Errorf("unable to get relative Dockerfile path: %v", err) - } - - if strings.HasPrefix(relDockerfile, ".."+string(filepath.Separator)) { - return "", "", fmt.Errorf("The Dockerfile (%s) must be within the build context (%s)", givenDockerfile, givenContextDir) - } - - return absContextDir, relDockerfile, nil -} - -// isUNC returns true if the path is UNC (one starting \\). It always returns -// false on Linux. -func isUNC(path string) bool { - return runtime.GOOS == "windows" && strings.HasPrefix(path, `\\`) -} diff --git a/vendor/github.com/docker/docker/builder/context_test.go b/vendor/github.com/docker/docker/builder/context_test.go deleted file mode 100644 index 27d29d7..0000000 --- a/vendor/github.com/docker/docker/builder/context_test.go +++ /dev/null @@ -1,307 +0,0 @@ -package builder - -import ( - "archive/tar" - "bytes" - "io" - "io/ioutil" - "path/filepath" - "runtime" - "strings" - "testing" - - "github.com/docker/docker/pkg/archive" -) - -var prepareEmpty = func(t *testing.T) (string, func()) { - return "", func() {} -} - -var prepareNoFiles = func(t *testing.T) (string, func()) { - return createTestTempDir(t, "", "builder-context-test") -} - -var prepareOneFile = func(t *testing.T) (string, func()) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - return contextDir, cleanup -} - -func testValidateContextDirectory(t *testing.T, prepare func(t *testing.T) (string, func()), excludes []string) { - contextDir, cleanup := prepare(t) - defer cleanup() - - err := ValidateContextDirectory(contextDir, excludes) - - if err != nil { - t.Fatalf("Error should be nil, got: %s", err) - } -} - -func TestGetContextFromLocalDirNoDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") - defer cleanup() - - absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "") - - if err == nil { - t.Fatalf("Error should not be nil") - } - - if absContextDir != "" { - t.Fatalf("Absolute directory path should be empty, got: %s", absContextDir) - } - - if relDockerfile != "" { - t.Fatalf("Relative path to Dockerfile should be empty, got: %s", relDockerfile) - } -} - -func TestGetContextFromLocalDirNotExistingDir(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") - defer cleanup() - - fakePath := filepath.Join(contextDir, "fake") - - absContextDir, relDockerfile, err := GetContextFromLocalDir(fakePath, "") - - if err == nil { - t.Fatalf("Error should not be nil") - } - - if absContextDir != "" { - t.Fatalf("Absolute directory path should be empty, got: %s", absContextDir) - } - - if relDockerfile != "" { - t.Fatalf("Relative path to Dockerfile should be empty, got: %s", relDockerfile) - } -} - -func TestGetContextFromLocalDirNotExistingDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") - defer cleanup() - - fakePath := filepath.Join(contextDir, "fake") - - absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, fakePath) - - if err == nil { - t.Fatalf("Error should not be nil") - } - - if absContextDir != "" { - t.Fatalf("Absolute directory path should be empty, got: %s", absContextDir) - } - - if relDockerfile != "" { - t.Fatalf("Relative path to Dockerfile should be empty, got: %s", relDockerfile) - } -} - -func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) { - contextDir, dirCleanup := createTestTempDir(t, "", "builder-context-test") - defer dirCleanup() - - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - - chdirCleanup := chdir(t, contextDir) - defer chdirCleanup() - - absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "") - - if err != nil { - t.Fatalf("Error when getting context from local dir: %s", err) - } - - if absContextDir != contextDir { - t.Fatalf("Absolute directory path should be equal to %s, got: %s", contextDir, absContextDir) - } - - if relDockerfile != DefaultDockerfileName { - t.Fatalf("Relative path to dockerfile should be equal to %s, got: %s", DefaultDockerfileName, relDockerfile) - } -} - -func TestGetContextFromLocalDirWithDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") - defer cleanup() - - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - - absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "") - - if err != nil { - t.Fatalf("Error when getting context from local dir: %s", err) - } - - if absContextDir != contextDir { - t.Fatalf("Absolute directory path should be equal to %s, got: %s", contextDir, absContextDir) - } - - if relDockerfile != DefaultDockerfileName { - t.Fatalf("Relative path to dockerfile should be equal to %s, got: %s", DefaultDockerfileName, relDockerfile) - } -} - -func TestGetContextFromLocalDirLocalFile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") - defer cleanup() - - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - testFilename := createTestTempFile(t, contextDir, "tmpTest", "test", 0777) - - absContextDir, relDockerfile, err := GetContextFromLocalDir(testFilename, "") - - if err == nil { - t.Fatalf("Error should not be nil") - } - - if absContextDir != "" { - t.Fatalf("Absolute directory path should be empty, got: %s", absContextDir) - } - - if relDockerfile != "" { - t.Fatalf("Relative path to Dockerfile should be empty, got: %s", relDockerfile) - } -} - -func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") - defer cleanup() - - chdirCleanup := chdir(t, contextDir) - defer chdirCleanup() - - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - - absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, DefaultDockerfileName) - - if err != nil { - t.Fatalf("Error when getting context from local dir: %s", err) - } - - if absContextDir != contextDir { - t.Fatalf("Absolute directory path should be equal to %s, got: %s", contextDir, absContextDir) - } - - if relDockerfile != DefaultDockerfileName { - t.Fatalf("Relative path to dockerfile should be equal to %s, got: %s", DefaultDockerfileName, relDockerfile) - } - -} - -func TestGetContextFromReaderString(t *testing.T) { - tarArchive, relDockerfile, err := GetContextFromReader(ioutil.NopCloser(strings.NewReader(dockerfileContents)), "") - - if err != nil { - t.Fatalf("Error when executing GetContextFromReader: %s", err) - } - - tarReader := tar.NewReader(tarArchive) - - _, err = tarReader.Next() - - if err != nil { - t.Fatalf("Error when reading tar archive: %s", err) - } - - buff := new(bytes.Buffer) - buff.ReadFrom(tarReader) - contents := buff.String() - - _, err = tarReader.Next() - - if err != io.EOF { - t.Fatalf("Tar stream too long: %s", err) - } - - if err = tarArchive.Close(); err != nil { - t.Fatalf("Error when closing tar stream: %s", err) - } - - if dockerfileContents != contents { - t.Fatalf("Uncompressed tar archive does not equal: %s, got: %s", dockerfileContents, contents) - } - - if relDockerfile != DefaultDockerfileName { - t.Fatalf("Relative path not equals %s, got: %s", DefaultDockerfileName, relDockerfile) - } -} - -func TestGetContextFromReaderTar(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") - defer cleanup() - - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - - tarStream, err := archive.Tar(contextDir, archive.Uncompressed) - - if err != nil { - t.Fatalf("Error when creating tar: %s", err) - } - - tarArchive, relDockerfile, err := GetContextFromReader(tarStream, DefaultDockerfileName) - - if err != nil { - t.Fatalf("Error when executing GetContextFromReader: %s", err) - } - - tarReader := tar.NewReader(tarArchive) - - header, err := tarReader.Next() - - if err != nil { - t.Fatalf("Error when reading tar archive: %s", err) - } - - if header.Name != DefaultDockerfileName { - t.Fatalf("Dockerfile name should be: %s, got: %s", DefaultDockerfileName, header.Name) - } - - buff := new(bytes.Buffer) - buff.ReadFrom(tarReader) - contents := buff.String() - - _, err = tarReader.Next() - - if err != io.EOF { - t.Fatalf("Tar stream too long: %s", err) - } - - if err = tarArchive.Close(); err != nil { - t.Fatalf("Error when closing tar stream: %s", err) - } - - if dockerfileContents != contents { - t.Fatalf("Uncompressed tar archive does not equal: %s, got: %s", dockerfileContents, contents) - } - - if relDockerfile != DefaultDockerfileName { - t.Fatalf("Relative path not equals %s, got: %s", DefaultDockerfileName, relDockerfile) - } -} - -func TestValidateContextDirectoryEmptyContext(t *testing.T) { - // This isn't a valid test on Windows. See https://play.golang.org/p/RR6z6jxR81. - // The test will ultimately end up calling filepath.Abs(""). On Windows, - // golang will error. On Linux, golang will return /. Due to there being - // drive letters on Windows, this is probably the correct behaviour for - // Windows. - if runtime.GOOS == "windows" { - t.Skip("Invalid test on Windows") - } - testValidateContextDirectory(t, prepareEmpty, []string{}) -} - -func TestValidateContextDirectoryContextWithNoFiles(t *testing.T) { - testValidateContextDirectory(t, prepareNoFiles, []string{}) -} - -func TestValidateContextDirectoryWithOneFile(t *testing.T) { - testValidateContextDirectory(t, prepareOneFile, []string{}) -} - -func TestValidateContextDirectoryWithOneFileExcludes(t *testing.T) { - testValidateContextDirectory(t, prepareOneFile, []string{DefaultDockerfileName}) -} diff --git a/vendor/github.com/docker/docker/builder/context_unix.go b/vendor/github.com/docker/docker/builder/context_unix.go deleted file mode 100644 index d1f72e0..0000000 --- a/vendor/github.com/docker/docker/builder/context_unix.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !windows - -package builder - -import ( - "path/filepath" -) - -func getContextRoot(srcPath string) (string, error) { - return filepath.Join(srcPath, "."), nil -} diff --git a/vendor/github.com/docker/docker/builder/context_windows.go b/vendor/github.com/docker/docker/builder/context_windows.go deleted file mode 100644 index b8ba2ba..0000000 --- a/vendor/github.com/docker/docker/builder/context_windows.go +++ /dev/null @@ -1,17 +0,0 @@ -// +build windows - -package builder - -import ( - "path/filepath" - - "github.com/docker/docker/pkg/longpath" -) - -func getContextRoot(srcPath string) (string, error) { - cr, err := filepath.Abs(srcPath) - if err != nil { - return "", err - } - return longpath.AddPrefix(cr), nil -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/bflag.go b/vendor/github.com/docker/docker/builder/dockerfile/bflag.go deleted file mode 100644 index 1e03693..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/bflag.go +++ /dev/null @@ -1,176 +0,0 @@ -package dockerfile - -import ( - "fmt" - "strings" -) - -// FlagType is the type of the build flag -type FlagType int - -const ( - boolType FlagType = iota - stringType -) - -// BFlags contains all flags information for the builder -type BFlags struct { - Args []string // actual flags/args from cmd line - flags map[string]*Flag - used map[string]*Flag - Err error -} - -// Flag contains all information for a flag -type Flag struct { - bf *BFlags - name string - flagType FlagType - Value string -} - -// NewBFlags returns the new BFlags struct -func NewBFlags() *BFlags { - return &BFlags{ - flags: make(map[string]*Flag), - used: make(map[string]*Flag), - } -} - -// AddBool adds a bool flag to BFlags -// Note, any error will be generated when Parse() is called (see Parse). -func (bf *BFlags) AddBool(name string, def bool) *Flag { - flag := bf.addFlag(name, boolType) - if flag == nil { - return nil - } - if def { - flag.Value = "true" - } else { - flag.Value = "false" - } - return flag -} - -// AddString adds a string flag to BFlags -// Note, any error will be generated when Parse() is called (see Parse). -func (bf *BFlags) AddString(name string, def string) *Flag { - flag := bf.addFlag(name, stringType) - if flag == nil { - return nil - } - flag.Value = def - return flag -} - -// addFlag is a generic func used by the other AddXXX() func -// to add a new flag to the BFlags struct. -// Note, any error will be generated when Parse() is called (see Parse). -func (bf *BFlags) addFlag(name string, flagType FlagType) *Flag { - if _, ok := bf.flags[name]; ok { - bf.Err = fmt.Errorf("Duplicate flag defined: %s", name) - return nil - } - - newFlag := &Flag{ - bf: bf, - name: name, - flagType: flagType, - } - bf.flags[name] = newFlag - - return newFlag -} - -// IsUsed checks if the flag is used -func (fl *Flag) IsUsed() bool { - if _, ok := fl.bf.used[fl.name]; ok { - return true - } - return false -} - -// IsTrue checks if a bool flag is true -func (fl *Flag) IsTrue() bool { - if fl.flagType != boolType { - // Should never get here - panic(fmt.Errorf("Trying to use IsTrue on a non-boolean: %s", fl.name)) - } - return fl.Value == "true" -} - -// Parse parses and checks if the BFlags is valid. -// Any error noticed during the AddXXX() funcs will be generated/returned -// here. We do this because an error during AddXXX() is more like a -// compile time error so it doesn't matter too much when we stop our -// processing as long as we do stop it, so this allows the code -// around AddXXX() to be just: -// defFlag := AddString("description", "") -// w/o needing to add an if-statement around each one. -func (bf *BFlags) Parse() error { - // If there was an error while defining the possible flags - // go ahead and bubble it back up here since we didn't do it - // earlier in the processing - if bf.Err != nil { - return fmt.Errorf("Error setting up flags: %s", bf.Err) - } - - for _, arg := range bf.Args { - if !strings.HasPrefix(arg, "--") { - return fmt.Errorf("Arg should start with -- : %s", arg) - } - - if arg == "--" { - return nil - } - - arg = arg[2:] - value := "" - - index := strings.Index(arg, "=") - if index >= 0 { - value = arg[index+1:] - arg = arg[:index] - } - - flag, ok := bf.flags[arg] - if !ok { - return fmt.Errorf("Unknown flag: %s", arg) - } - - if _, ok = bf.used[arg]; ok { - return fmt.Errorf("Duplicate flag specified: %s", arg) - } - - bf.used[arg] = flag - - switch flag.flagType { - case boolType: - // value == "" is only ok if no "=" was specified - if index >= 0 && value == "" { - return fmt.Errorf("Missing a value on flag: %s", arg) - } - - lower := strings.ToLower(value) - if lower == "" { - flag.Value = "true" - } else if lower == "true" || lower == "false" { - flag.Value = lower - } else { - return fmt.Errorf("Expecting boolean value for flag %s, not: %s", arg, value) - } - - case stringType: - if index < 0 { - return fmt.Errorf("Missing a value on flag: %s", arg) - } - flag.Value = value - - default: - panic(fmt.Errorf("No idea what kind of flag we have! Should never get here!")) - } - - } - - return nil -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/bflag_test.go b/vendor/github.com/docker/docker/builder/dockerfile/bflag_test.go deleted file mode 100644 index 65cfcea..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/bflag_test.go +++ /dev/null @@ -1,187 +0,0 @@ -package dockerfile - -import ( - "testing" -) - -func TestBuilderFlags(t *testing.T) { - var expected string - var err error - - // --- - - bf := NewBFlags() - bf.Args = []string{} - if err := bf.Parse(); err != nil { - t.Fatalf("Test1 of %q was supposed to work: %s", bf.Args, err) - } - - // --- - - bf = NewBFlags() - bf.Args = []string{"--"} - if err := bf.Parse(); err != nil { - t.Fatalf("Test2 of %q was supposed to work: %s", bf.Args, err) - } - - // --- - - bf = NewBFlags() - flStr1 := bf.AddString("str1", "") - flBool1 := bf.AddBool("bool1", false) - bf.Args = []string{} - if err = bf.Parse(); err != nil { - t.Fatalf("Test3 of %q was supposed to work: %s", bf.Args, err) - } - - if flStr1.IsUsed() == true { - t.Fatalf("Test3 - str1 was not used!") - } - if flBool1.IsUsed() == true { - t.Fatalf("Test3 - bool1 was not used!") - } - - // --- - - bf = NewBFlags() - flStr1 = bf.AddString("str1", "HI") - flBool1 = bf.AddBool("bool1", false) - bf.Args = []string{} - - if err = bf.Parse(); err != nil { - t.Fatalf("Test4 of %q was supposed to work: %s", bf.Args, err) - } - - if flStr1.Value != "HI" { - t.Fatalf("Str1 was supposed to default to: HI") - } - if flBool1.IsTrue() { - t.Fatalf("Bool1 was supposed to default to: false") - } - if flStr1.IsUsed() == true { - t.Fatalf("Str1 was not used!") - } - if flBool1.IsUsed() == true { - t.Fatalf("Bool1 was not used!") - } - - // --- - - bf = NewBFlags() - flStr1 = bf.AddString("str1", "HI") - bf.Args = []string{"--str1"} - - if err = bf.Parse(); err == nil { - t.Fatalf("Test %q was supposed to fail", bf.Args) - } - - // --- - - bf = NewBFlags() - flStr1 = bf.AddString("str1", "HI") - bf.Args = []string{"--str1="} - - if err = bf.Parse(); err != nil { - t.Fatalf("Test %q was supposed to work: %s", bf.Args, err) - } - - expected = "" - if flStr1.Value != expected { - t.Fatalf("Str1 (%q) should be: %q", flStr1.Value, expected) - } - - // --- - - bf = NewBFlags() - flStr1 = bf.AddString("str1", "HI") - bf.Args = []string{"--str1=BYE"} - - if err = bf.Parse(); err != nil { - t.Fatalf("Test %q was supposed to work: %s", bf.Args, err) - } - - expected = "BYE" - if flStr1.Value != expected { - t.Fatalf("Str1 (%q) should be: %q", flStr1.Value, expected) - } - - // --- - - bf = NewBFlags() - flBool1 = bf.AddBool("bool1", false) - bf.Args = []string{"--bool1"} - - if err = bf.Parse(); err != nil { - t.Fatalf("Test %q was supposed to work: %s", bf.Args, err) - } - - if !flBool1.IsTrue() { - t.Fatalf("Test-b1 Bool1 was supposed to be true") - } - - // --- - - bf = NewBFlags() - flBool1 = bf.AddBool("bool1", false) - bf.Args = []string{"--bool1=true"} - - if err = bf.Parse(); err != nil { - t.Fatalf("Test %q was supposed to work: %s", bf.Args, err) - } - - if !flBool1.IsTrue() { - t.Fatalf("Test-b2 Bool1 was supposed to be true") - } - - // --- - - bf = NewBFlags() - flBool1 = bf.AddBool("bool1", false) - bf.Args = []string{"--bool1=false"} - - if err = bf.Parse(); err != nil { - t.Fatalf("Test %q was supposed to work: %s", bf.Args, err) - } - - if flBool1.IsTrue() { - t.Fatalf("Test-b3 Bool1 was supposed to be false") - } - - // --- - - bf = NewBFlags() - flBool1 = bf.AddBool("bool1", false) - bf.Args = []string{"--bool1=false1"} - - if err = bf.Parse(); err == nil { - t.Fatalf("Test %q was supposed to fail", bf.Args) - } - - // --- - - bf = NewBFlags() - flBool1 = bf.AddBool("bool1", false) - bf.Args = []string{"--bool2"} - - if err = bf.Parse(); err == nil { - t.Fatalf("Test %q was supposed to fail", bf.Args) - } - - // --- - - bf = NewBFlags() - flStr1 = bf.AddString("str1", "HI") - flBool1 = bf.AddBool("bool1", false) - bf.Args = []string{"--bool1", "--str1=BYE"} - - if err = bf.Parse(); err != nil { - t.Fatalf("Test %q was supposed to work: %s", bf.Args, err) - } - - if flStr1.Value != "BYE" { - t.Fatalf("Teset %s, str1 should be BYE", bf.Args) - } - if !flBool1.IsTrue() { - t.Fatalf("Teset %s, bool1 should be true", bf.Args) - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/builder.go b/vendor/github.com/docker/docker/builder/dockerfile/builder.go deleted file mode 100644 index da43513..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/builder.go +++ /dev/null @@ -1,370 +0,0 @@ -package dockerfile - -import ( - "bytes" - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "strings" - - "github.com/Sirupsen/logrus" - apierrors "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/builder" - "github.com/docker/docker/builder/dockerfile/parser" - "github.com/docker/docker/image" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/reference" - perrors "github.com/pkg/errors" - "golang.org/x/net/context" -) - -var validCommitCommands = map[string]bool{ - "cmd": true, - "entrypoint": true, - "healthcheck": true, - "env": true, - "expose": true, - "label": true, - "onbuild": true, - "user": true, - "volume": true, - "workdir": true, -} - -// BuiltinAllowedBuildArgs is list of built-in allowed build args -var BuiltinAllowedBuildArgs = map[string]bool{ - "HTTP_PROXY": true, - "http_proxy": true, - "HTTPS_PROXY": true, - "https_proxy": true, - "FTP_PROXY": true, - "ftp_proxy": true, - "NO_PROXY": true, - "no_proxy": true, -} - -// Builder is a Dockerfile builder -// It implements the builder.Backend interface. -type Builder struct { - options *types.ImageBuildOptions - - Stdout io.Writer - Stderr io.Writer - Output io.Writer - - docker builder.Backend - context builder.Context - clientCtx context.Context - cancel context.CancelFunc - - dockerfile *parser.Node - runConfig *container.Config // runconfig for cmd, run, entrypoint etc. - flags *BFlags - tmpContainers map[string]struct{} - image string // imageID - noBaseImage bool - maintainer string - cmdSet bool - disableCommit bool - cacheBusted bool - allowedBuildArgs map[string]bool // list of build-time args that are allowed for expansion/substitution and passing to commands in 'run'. - directive parser.Directive - - // TODO: remove once docker.Commit can receive a tag - id string - - imageCache builder.ImageCache - from builder.Image -} - -// BuildManager implements builder.Backend and is shared across all Builder objects. -type BuildManager struct { - backend builder.Backend -} - -// NewBuildManager creates a BuildManager. -func NewBuildManager(b builder.Backend) (bm *BuildManager) { - return &BuildManager{backend: b} -} - -// BuildFromContext builds a new image from a given context. -func (bm *BuildManager) BuildFromContext(ctx context.Context, src io.ReadCloser, remote string, buildOptions *types.ImageBuildOptions, pg backend.ProgressWriter) (string, error) { - if buildOptions.Squash && !bm.backend.HasExperimental() { - return "", apierrors.NewBadRequestError(errors.New("squash is only supported with experimental mode")) - } - buildContext, dockerfileName, err := builder.DetectContextFromRemoteURL(src, remote, pg.ProgressReaderFunc) - if err != nil { - return "", err - } - defer func() { - if err := buildContext.Close(); err != nil { - logrus.Debugf("[BUILDER] failed to remove temporary context: %v", err) - } - }() - - if len(dockerfileName) > 0 { - buildOptions.Dockerfile = dockerfileName - } - b, err := NewBuilder(ctx, buildOptions, bm.backend, builder.DockerIgnoreContext{ModifiableContext: buildContext}, nil) - if err != nil { - return "", err - } - return b.build(pg.StdoutFormatter, pg.StderrFormatter, pg.Output) -} - -// NewBuilder creates a new Dockerfile builder from an optional dockerfile and a Config. -// If dockerfile is nil, the Dockerfile specified by Config.DockerfileName, -// will be read from the Context passed to Build(). -func NewBuilder(clientCtx context.Context, config *types.ImageBuildOptions, backend builder.Backend, buildContext builder.Context, dockerfile io.ReadCloser) (b *Builder, err error) { - if config == nil { - config = new(types.ImageBuildOptions) - } - if config.BuildArgs == nil { - config.BuildArgs = make(map[string]*string) - } - ctx, cancel := context.WithCancel(clientCtx) - b = &Builder{ - clientCtx: ctx, - cancel: cancel, - options: config, - Stdout: os.Stdout, - Stderr: os.Stderr, - docker: backend, - context: buildContext, - runConfig: new(container.Config), - tmpContainers: map[string]struct{}{}, - id: stringid.GenerateNonCryptoID(), - allowedBuildArgs: make(map[string]bool), - directive: parser.Directive{ - EscapeSeen: false, - LookingForDirectives: true, - }, - } - if icb, ok := backend.(builder.ImageCacheBuilder); ok { - b.imageCache = icb.MakeImageCache(config.CacheFrom) - } - - parser.SetEscapeToken(parser.DefaultEscapeToken, &b.directive) // Assume the default token for escape - - if dockerfile != nil { - b.dockerfile, err = parser.Parse(dockerfile, &b.directive) - if err != nil { - return nil, err - } - } - - return b, nil -} - -// sanitizeRepoAndTags parses the raw "t" parameter received from the client -// to a slice of repoAndTag. -// It also validates each repoName and tag. -func sanitizeRepoAndTags(names []string) ([]reference.Named, error) { - var ( - repoAndTags []reference.Named - // This map is used for deduplicating the "-t" parameter. - uniqNames = make(map[string]struct{}) - ) - for _, repo := range names { - if repo == "" { - continue - } - - ref, err := reference.ParseNamed(repo) - if err != nil { - return nil, err - } - - ref = reference.WithDefaultTag(ref) - - if _, isCanonical := ref.(reference.Canonical); isCanonical { - return nil, errors.New("build tag cannot contain a digest") - } - - if _, isTagged := ref.(reference.NamedTagged); !isTagged { - ref, err = reference.WithTag(ref, reference.DefaultTag) - if err != nil { - return nil, err - } - } - - nameWithTag := ref.String() - - if _, exists := uniqNames[nameWithTag]; !exists { - uniqNames[nameWithTag] = struct{}{} - repoAndTags = append(repoAndTags, ref) - } - } - return repoAndTags, nil -} - -// build runs the Dockerfile builder from a context and a docker object that allows to make calls -// to Docker. -// -// This will (barring errors): -// -// * read the dockerfile from context -// * parse the dockerfile if not already parsed -// * walk the AST and execute it by dispatching to handlers. If Remove -// or ForceRemove is set, additional cleanup around containers happens after -// processing. -// * Tag image, if applicable. -// * Print a happy message and return the image ID. -// -func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (string, error) { - b.Stdout = stdout - b.Stderr = stderr - b.Output = out - - // If Dockerfile was not parsed yet, extract it from the Context - if b.dockerfile == nil { - if err := b.readDockerfile(); err != nil { - return "", err - } - } - - repoAndTags, err := sanitizeRepoAndTags(b.options.Tags) - if err != nil { - return "", err - } - - if len(b.options.Labels) > 0 { - line := "LABEL " - for k, v := range b.options.Labels { - line += fmt.Sprintf("%q='%s' ", k, v) - } - _, node, err := parser.ParseLine(line, &b.directive, false) - if err != nil { - return "", err - } - b.dockerfile.Children = append(b.dockerfile.Children, node) - } - - var shortImgID string - total := len(b.dockerfile.Children) - for _, n := range b.dockerfile.Children { - if err := b.checkDispatch(n, false); err != nil { - return "", err - } - } - - for i, n := range b.dockerfile.Children { - select { - case <-b.clientCtx.Done(): - logrus.Debug("Builder: build cancelled!") - fmt.Fprintf(b.Stdout, "Build cancelled") - return "", fmt.Errorf("Build cancelled") - default: - // Not cancelled yet, keep going... - } - - if err := b.dispatch(i, total, n); err != nil { - if b.options.ForceRemove { - b.clearTmp() - } - return "", err - } - - shortImgID = stringid.TruncateID(b.image) - fmt.Fprintf(b.Stdout, " ---> %s\n", shortImgID) - if b.options.Remove { - b.clearTmp() - } - } - - // check if there are any leftover build-args that were passed but not - // consumed during build. Return a warning, if there are any. - leftoverArgs := []string{} - for arg := range b.options.BuildArgs { - if !b.isBuildArgAllowed(arg) { - leftoverArgs = append(leftoverArgs, arg) - } - } - - if len(leftoverArgs) > 0 { - fmt.Fprintf(b.Stderr, "[Warning] One or more build-args %v were not consumed\n", leftoverArgs) - } - - if b.image == "" { - return "", fmt.Errorf("No image was generated. Is your Dockerfile empty?") - } - - if b.options.Squash { - var fromID string - if b.from != nil { - fromID = b.from.ImageID() - } - b.image, err = b.docker.SquashImage(b.image, fromID) - if err != nil { - return "", perrors.Wrap(err, "error squashing image") - } - } - - imageID := image.ID(b.image) - for _, rt := range repoAndTags { - if err := b.docker.TagImageWithReference(imageID, rt); err != nil { - return "", err - } - } - - fmt.Fprintf(b.Stdout, "Successfully built %s\n", shortImgID) - return b.image, nil -} - -// Cancel cancels an ongoing Dockerfile build. -func (b *Builder) Cancel() { - b.cancel() -} - -// BuildFromConfig builds directly from `changes`, treating it as if it were the contents of a Dockerfile -// It will: -// - Call parse.Parse() to get an AST root for the concatenated Dockerfile entries. -// - Do build by calling builder.dispatch() to call all entries' handling routines -// -// BuildFromConfig is used by the /commit endpoint, with the changes -// coming from the query parameter of the same name. -// -// TODO: Remove? -func BuildFromConfig(config *container.Config, changes []string) (*container.Config, error) { - b, err := NewBuilder(context.Background(), nil, nil, nil, nil) - if err != nil { - return nil, err - } - - ast, err := parser.Parse(bytes.NewBufferString(strings.Join(changes, "\n")), &b.directive) - if err != nil { - return nil, err - } - - // ensure that the commands are valid - for _, n := range ast.Children { - if !validCommitCommands[n.Value] { - return nil, fmt.Errorf("%s is not a valid change command", n.Value) - } - } - - b.runConfig = config - b.Stdout = ioutil.Discard - b.Stderr = ioutil.Discard - b.disableCommit = true - - total := len(ast.Children) - for _, n := range ast.Children { - if err := b.checkDispatch(n, false); err != nil { - return nil, err - } - } - - for i, n := range ast.Children { - if err := b.dispatch(i, total, n); err != nil { - return nil, err - } - } - - return b.runConfig, nil -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/builder_unix.go b/vendor/github.com/docker/docker/builder/dockerfile/builder_unix.go deleted file mode 100644 index 76a7ce7..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/builder_unix.go +++ /dev/null @@ -1,5 +0,0 @@ -// +build !windows - -package dockerfile - -var defaultShell = []string{"/bin/sh", "-c"} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/builder_windows.go b/vendor/github.com/docker/docker/builder/dockerfile/builder_windows.go deleted file mode 100644 index 37e9fbc..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/builder_windows.go +++ /dev/null @@ -1,3 +0,0 @@ -package dockerfile - -var defaultShell = []string{"cmd", "/S", "/C"} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/command/command.go b/vendor/github.com/docker/docker/builder/dockerfile/command/command.go deleted file mode 100644 index f23c687..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/command/command.go +++ /dev/null @@ -1,46 +0,0 @@ -// Package command contains the set of Dockerfile commands. -package command - -// Define constants for the command strings -const ( - Add = "add" - Arg = "arg" - Cmd = "cmd" - Copy = "copy" - Entrypoint = "entrypoint" - Env = "env" - Expose = "expose" - From = "from" - Healthcheck = "healthcheck" - Label = "label" - Maintainer = "maintainer" - Onbuild = "onbuild" - Run = "run" - Shell = "shell" - StopSignal = "stopsignal" - User = "user" - Volume = "volume" - Workdir = "workdir" -) - -// Commands is list of all Dockerfile commands -var Commands = map[string]struct{}{ - Add: {}, - Arg: {}, - Cmd: {}, - Copy: {}, - Entrypoint: {}, - Env: {}, - Expose: {}, - From: {}, - Healthcheck: {}, - Label: {}, - Maintainer: {}, - Onbuild: {}, - Run: {}, - Shell: {}, - StopSignal: {}, - User: {}, - Volume: {}, - Workdir: {}, -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers.go b/vendor/github.com/docker/docker/builder/dockerfile/dispatchers.go deleted file mode 100644 index 3e78abd..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers.go +++ /dev/null @@ -1,821 +0,0 @@ -package dockerfile - -// This file contains the dispatchers for each command. Note that -// `nullDispatch` is not actually a command, but support for commands we parse -// but do nothing with. -// -// See evaluator.go for a higher level discussion of the whole evaluator -// package. - -import ( - "fmt" - "regexp" - "runtime" - "sort" - "strconv" - "strings" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/strslice" - "github.com/docker/docker/builder" - "github.com/docker/docker/pkg/signal" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/docker/go-connections/nat" -) - -// ENV foo bar -// -// Sets the environment variable foo to bar, also makes interpolation -// in the dockerfile available from the next statement on via ${foo}. -// -func env(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) == 0 { - return errAtLeastOneArgument("ENV") - } - - if len(args)%2 != 0 { - // should never get here, but just in case - return errTooManyArguments("ENV") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - // TODO/FIXME/NOT USED - // Just here to show how to use the builder flags stuff within the - // context of a builder command. Will remove once we actually add - // a builder command to something! - /* - flBool1 := b.flags.AddBool("bool1", false) - flStr1 := b.flags.AddString("str1", "HI") - - if err := b.flags.Parse(); err != nil { - return err - } - - fmt.Printf("Bool1:%v\n", flBool1) - fmt.Printf("Str1:%v\n", flStr1) - */ - - commitStr := "ENV" - - for j := 0; j < len(args); j++ { - // name ==> args[j] - // value ==> args[j+1] - - if len(args[j]) == 0 { - return errBlankCommandNames("ENV") - } - newVar := args[j] + "=" + args[j+1] + "" - commitStr += " " + newVar - - gotOne := false - for i, envVar := range b.runConfig.Env { - envParts := strings.SplitN(envVar, "=", 2) - compareFrom := envParts[0] - compareTo := args[j] - if runtime.GOOS == "windows" { - // Case insensitive environment variables on Windows - compareFrom = strings.ToUpper(compareFrom) - compareTo = strings.ToUpper(compareTo) - } - if compareFrom == compareTo { - b.runConfig.Env[i] = newVar - gotOne = true - break - } - } - if !gotOne { - b.runConfig.Env = append(b.runConfig.Env, newVar) - } - j++ - } - - return b.commit("", b.runConfig.Cmd, commitStr) -} - -// MAINTAINER some text -// -// Sets the maintainer metadata. -func maintainer(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) != 1 { - return errExactlyOneArgument("MAINTAINER") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - b.maintainer = args[0] - return b.commit("", b.runConfig.Cmd, fmt.Sprintf("MAINTAINER %s", b.maintainer)) -} - -// LABEL some json data describing the image -// -// Sets the Label variable foo to bar, -// -func label(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) == 0 { - return errAtLeastOneArgument("LABEL") - } - if len(args)%2 != 0 { - // should never get here, but just in case - return errTooManyArguments("LABEL") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - commitStr := "LABEL" - - if b.runConfig.Labels == nil { - b.runConfig.Labels = map[string]string{} - } - - for j := 0; j < len(args); j++ { - // name ==> args[j] - // value ==> args[j+1] - - if len(args[j]) == 0 { - return errBlankCommandNames("LABEL") - } - - newVar := args[j] + "=" + args[j+1] + "" - commitStr += " " + newVar - - b.runConfig.Labels[args[j]] = args[j+1] - j++ - } - return b.commit("", b.runConfig.Cmd, commitStr) -} - -// ADD foo /path -// -// Add the file 'foo' to '/path'. Tarball and Remote URL (git, http) handling -// exist here. If you do not wish to have this automatic handling, use COPY. -// -func add(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) < 2 { - return errAtLeastTwoArguments("ADD") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - return b.runContextCommand(args, true, true, "ADD") -} - -// COPY foo /path -// -// Same as 'ADD' but without the tar and remote url handling. -// -func dispatchCopy(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) < 2 { - return errAtLeastTwoArguments("COPY") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - return b.runContextCommand(args, false, false, "COPY") -} - -// FROM imagename -// -// This sets the image the dockerfile will build on top of. -// -func from(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) != 1 { - return errExactlyOneArgument("FROM") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - name := args[0] - - var ( - image builder.Image - err error - ) - - // Windows cannot support a container with no base image. - if name == api.NoBaseImageSpecifier { - if runtime.GOOS == "windows" { - return fmt.Errorf("Windows does not support FROM scratch") - } - b.image = "" - b.noBaseImage = true - } else { - // TODO: don't use `name`, instead resolve it to a digest - if !b.options.PullParent { - image, err = b.docker.GetImageOnBuild(name) - // TODO: shouldn't we error out if error is different from "not found" ? - } - if image == nil { - image, err = b.docker.PullOnBuild(b.clientCtx, name, b.options.AuthConfigs, b.Output) - if err != nil { - return err - } - } - } - b.from = image - - return b.processImageFrom(image) -} - -// ONBUILD RUN echo yo -// -// ONBUILD triggers run when the image is used in a FROM statement. -// -// ONBUILD handling has a lot of special-case functionality, the heading in -// evaluator.go and comments around dispatch() in the same file explain the -// special cases. search for 'OnBuild' in internals.go for additional special -// cases. -// -func onbuild(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) == 0 { - return errAtLeastOneArgument("ONBUILD") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - triggerInstruction := strings.ToUpper(strings.TrimSpace(args[0])) - switch triggerInstruction { - case "ONBUILD": - return fmt.Errorf("Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed") - case "MAINTAINER", "FROM": - return fmt.Errorf("%s isn't allowed as an ONBUILD trigger", triggerInstruction) - } - - original = regexp.MustCompile(`(?i)^\s*ONBUILD\s*`).ReplaceAllString(original, "") - - b.runConfig.OnBuild = append(b.runConfig.OnBuild, original) - return b.commit("", b.runConfig.Cmd, fmt.Sprintf("ONBUILD %s", original)) -} - -// WORKDIR /tmp -// -// Set the working directory for future RUN/CMD/etc statements. -// -func workdir(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) != 1 { - return errExactlyOneArgument("WORKDIR") - } - - err := b.flags.Parse() - if err != nil { - return err - } - - // This is from the Dockerfile and will not necessarily be in platform - // specific semantics, hence ensure it is converted. - b.runConfig.WorkingDir, err = normaliseWorkdir(b.runConfig.WorkingDir, args[0]) - if err != nil { - return err - } - - // For performance reasons, we explicitly do a create/mkdir now - // This avoids having an unnecessary expensive mount/unmount calls - // (on Windows in particular) during each container create. - // Prior to 1.13, the mkdir was deferred and not executed at this step. - if b.disableCommit { - // Don't call back into the daemon if we're going through docker commit --change "WORKDIR /foo". - // We've already updated the runConfig and that's enough. - return nil - } - b.runConfig.Image = b.image - - cmd := b.runConfig.Cmd - comment := "WORKDIR " + b.runConfig.WorkingDir - // reset the command for cache detection - b.runConfig.Cmd = strslice.StrSlice(append(getShell(b.runConfig), "#(nop) "+comment)) - defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd) - - if hit, err := b.probeCache(); err != nil { - return err - } else if hit { - return nil - } - - container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig}) - if err != nil { - return err - } - b.tmpContainers[container.ID] = struct{}{} - if err := b.docker.ContainerCreateWorkdir(container.ID); err != nil { - return err - } - - return b.commit(container.ID, cmd, comment) -} - -// RUN some command yo -// -// run a command and commit the image. Args are automatically prepended with -// the current SHELL which defaults to 'sh -c' under linux or 'cmd /S /C' under -// Windows, in the event there is only one argument The difference in processing: -// -// RUN echo hi # sh -c echo hi (Linux) -// RUN echo hi # cmd /S /C echo hi (Windows) -// RUN [ "echo", "hi" ] # echo hi -// -func run(b *Builder, args []string, attributes map[string]bool, original string) error { - if b.image == "" && !b.noBaseImage { - return fmt.Errorf("Please provide a source image with `from` prior to run") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - args = handleJSONArgs(args, attributes) - - if !attributes["json"] { - args = append(getShell(b.runConfig), args...) - } - config := &container.Config{ - Cmd: strslice.StrSlice(args), - Image: b.image, - } - - // stash the cmd - cmd := b.runConfig.Cmd - if len(b.runConfig.Entrypoint) == 0 && len(b.runConfig.Cmd) == 0 { - b.runConfig.Cmd = config.Cmd - } - - // stash the config environment - env := b.runConfig.Env - - defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd) - defer func(env []string) { b.runConfig.Env = env }(env) - - // derive the net build-time environment for this run. We let config - // environment override the build time environment. - // This means that we take the b.buildArgs list of env vars and remove - // any of those variables that are defined as part of the container. In other - // words, anything in b.Config.Env. What's left is the list of build-time env - // vars that we need to add to each RUN command - note the list could be empty. - // - // We don't persist the build time environment with container's config - // environment, but just sort and prepend it to the command string at time - // of commit. - // This helps with tracing back the image's actual environment at the time - // of RUN, without leaking it to the final image. It also aids cache - // lookup for same image built with same build time environment. - cmdBuildEnv := []string{} - configEnv := runconfigopts.ConvertKVStringsToMap(b.runConfig.Env) - for key, val := range b.options.BuildArgs { - if !b.isBuildArgAllowed(key) { - // skip build-args that are not in allowed list, meaning they have - // not been defined by an "ARG" Dockerfile command yet. - // This is an error condition but only if there is no "ARG" in the entire - // Dockerfile, so we'll generate any necessary errors after we parsed - // the entire file (see 'leftoverArgs' processing in evaluator.go ) - continue - } - if _, ok := configEnv[key]; !ok && val != nil { - cmdBuildEnv = append(cmdBuildEnv, fmt.Sprintf("%s=%s", key, *val)) - } - } - - // derive the command to use for probeCache() and to commit in this container. - // Note that we only do this if there are any build-time env vars. Also, we - // use the special argument "|#" at the start of the args array. This will - // avoid conflicts with any RUN command since commands can not - // start with | (vertical bar). The "#" (number of build envs) is there to - // help ensure proper cache matches. We don't want a RUN command - // that starts with "foo=abc" to be considered part of a build-time env var. - saveCmd := config.Cmd - if len(cmdBuildEnv) > 0 { - sort.Strings(cmdBuildEnv) - tmpEnv := append([]string{fmt.Sprintf("|%d", len(cmdBuildEnv))}, cmdBuildEnv...) - saveCmd = strslice.StrSlice(append(tmpEnv, saveCmd...)) - } - - b.runConfig.Cmd = saveCmd - hit, err := b.probeCache() - if err != nil { - return err - } - if hit { - return nil - } - - // set Cmd manually, this is special case only for Dockerfiles - b.runConfig.Cmd = config.Cmd - // set build-time environment for 'run'. - b.runConfig.Env = append(b.runConfig.Env, cmdBuildEnv...) - // set config as already being escaped, this prevents double escaping on windows - b.runConfig.ArgsEscaped = true - - logrus.Debugf("[BUILDER] Command to be executed: %v", b.runConfig.Cmd) - - cID, err := b.create() - if err != nil { - return err - } - - if err := b.run(cID); err != nil { - return err - } - - // revert to original config environment and set the command string to - // have the build-time env vars in it (if any) so that future cache look-ups - // properly match it. - b.runConfig.Env = env - b.runConfig.Cmd = saveCmd - return b.commit(cID, cmd, "run") -} - -// CMD foo -// -// Set the default command to run in the container (which may be empty). -// Argument handling is the same as RUN. -// -func cmd(b *Builder, args []string, attributes map[string]bool, original string) error { - if err := b.flags.Parse(); err != nil { - return err - } - - cmdSlice := handleJSONArgs(args, attributes) - - if !attributes["json"] { - cmdSlice = append(getShell(b.runConfig), cmdSlice...) - } - - b.runConfig.Cmd = strslice.StrSlice(cmdSlice) - // set config as already being escaped, this prevents double escaping on windows - b.runConfig.ArgsEscaped = true - - if err := b.commit("", b.runConfig.Cmd, fmt.Sprintf("CMD %q", cmdSlice)); err != nil { - return err - } - - if len(args) != 0 { - b.cmdSet = true - } - - return nil -} - -// parseOptInterval(flag) is the duration of flag.Value, or 0 if -// empty. An error is reported if the value is given and is not positive. -func parseOptInterval(f *Flag) (time.Duration, error) { - s := f.Value - if s == "" { - return 0, nil - } - d, err := time.ParseDuration(s) - if err != nil { - return 0, err - } - if d <= 0 { - return 0, fmt.Errorf("Interval %#v must be positive", f.name) - } - return d, nil -} - -// HEALTHCHECK foo -// -// Set the default healthcheck command to run in the container (which may be empty). -// Argument handling is the same as RUN. -// -func healthcheck(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) == 0 { - return errAtLeastOneArgument("HEALTHCHECK") - } - typ := strings.ToUpper(args[0]) - args = args[1:] - if typ == "NONE" { - if len(args) != 0 { - return fmt.Errorf("HEALTHCHECK NONE takes no arguments") - } - test := strslice.StrSlice{typ} - b.runConfig.Healthcheck = &container.HealthConfig{ - Test: test, - } - } else { - if b.runConfig.Healthcheck != nil { - oldCmd := b.runConfig.Healthcheck.Test - if len(oldCmd) > 0 && oldCmd[0] != "NONE" { - fmt.Fprintf(b.Stdout, "Note: overriding previous HEALTHCHECK: %v\n", oldCmd) - } - } - - healthcheck := container.HealthConfig{} - - flInterval := b.flags.AddString("interval", "") - flTimeout := b.flags.AddString("timeout", "") - flRetries := b.flags.AddString("retries", "") - - if err := b.flags.Parse(); err != nil { - return err - } - - switch typ { - case "CMD": - cmdSlice := handleJSONArgs(args, attributes) - if len(cmdSlice) == 0 { - return fmt.Errorf("Missing command after HEALTHCHECK CMD") - } - - if !attributes["json"] { - typ = "CMD-SHELL" - } - - healthcheck.Test = strslice.StrSlice(append([]string{typ}, cmdSlice...)) - default: - return fmt.Errorf("Unknown type %#v in HEALTHCHECK (try CMD)", typ) - } - - interval, err := parseOptInterval(flInterval) - if err != nil { - return err - } - healthcheck.Interval = interval - - timeout, err := parseOptInterval(flTimeout) - if err != nil { - return err - } - healthcheck.Timeout = timeout - - if flRetries.Value != "" { - retries, err := strconv.ParseInt(flRetries.Value, 10, 32) - if err != nil { - return err - } - if retries < 1 { - return fmt.Errorf("--retries must be at least 1 (not %d)", retries) - } - healthcheck.Retries = int(retries) - } else { - healthcheck.Retries = 0 - } - - b.runConfig.Healthcheck = &healthcheck - } - - return b.commit("", b.runConfig.Cmd, fmt.Sprintf("HEALTHCHECK %q", b.runConfig.Healthcheck)) -} - -// ENTRYPOINT /usr/sbin/nginx -// -// Set the entrypoint to /usr/sbin/nginx. Will accept the CMD as the arguments -// to /usr/sbin/nginx. Uses the default shell if not in JSON format. -// -// Handles command processing similar to CMD and RUN, only b.runConfig.Entrypoint -// is initialized at NewBuilder time instead of through argument parsing. -// -func entrypoint(b *Builder, args []string, attributes map[string]bool, original string) error { - if err := b.flags.Parse(); err != nil { - return err - } - - parsed := handleJSONArgs(args, attributes) - - switch { - case attributes["json"]: - // ENTRYPOINT ["echo", "hi"] - b.runConfig.Entrypoint = strslice.StrSlice(parsed) - case len(parsed) == 0: - // ENTRYPOINT [] - b.runConfig.Entrypoint = nil - default: - // ENTRYPOINT echo hi - b.runConfig.Entrypoint = strslice.StrSlice(append(getShell(b.runConfig), parsed[0])) - } - - // when setting the entrypoint if a CMD was not explicitly set then - // set the command to nil - if !b.cmdSet { - b.runConfig.Cmd = nil - } - - if err := b.commit("", b.runConfig.Cmd, fmt.Sprintf("ENTRYPOINT %q", b.runConfig.Entrypoint)); err != nil { - return err - } - - return nil -} - -// EXPOSE 6667/tcp 7000/tcp -// -// Expose ports for links and port mappings. This all ends up in -// b.runConfig.ExposedPorts for runconfig. -// -func expose(b *Builder, args []string, attributes map[string]bool, original string) error { - portsTab := args - - if len(args) == 0 { - return errAtLeastOneArgument("EXPOSE") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - if b.runConfig.ExposedPorts == nil { - b.runConfig.ExposedPorts = make(nat.PortSet) - } - - ports, _, err := nat.ParsePortSpecs(portsTab) - if err != nil { - return err - } - - // instead of using ports directly, we build a list of ports and sort it so - // the order is consistent. This prevents cache burst where map ordering - // changes between builds - portList := make([]string, len(ports)) - var i int - for port := range ports { - if _, exists := b.runConfig.ExposedPorts[port]; !exists { - b.runConfig.ExposedPorts[port] = struct{}{} - } - portList[i] = string(port) - i++ - } - sort.Strings(portList) - return b.commit("", b.runConfig.Cmd, fmt.Sprintf("EXPOSE %s", strings.Join(portList, " "))) -} - -// USER foo -// -// Set the user to 'foo' for future commands and when running the -// ENTRYPOINT/CMD at container run time. -// -func user(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) != 1 { - return errExactlyOneArgument("USER") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - b.runConfig.User = args[0] - return b.commit("", b.runConfig.Cmd, fmt.Sprintf("USER %v", args)) -} - -// VOLUME /foo -// -// Expose the volume /foo for use. Will also accept the JSON array form. -// -func volume(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) == 0 { - return errAtLeastOneArgument("VOLUME") - } - - if err := b.flags.Parse(); err != nil { - return err - } - - if b.runConfig.Volumes == nil { - b.runConfig.Volumes = map[string]struct{}{} - } - for _, v := range args { - v = strings.TrimSpace(v) - if v == "" { - return fmt.Errorf("VOLUME specified can not be an empty string") - } - b.runConfig.Volumes[v] = struct{}{} - } - if err := b.commit("", b.runConfig.Cmd, fmt.Sprintf("VOLUME %v", args)); err != nil { - return err - } - return nil -} - -// STOPSIGNAL signal -// -// Set the signal that will be used to kill the container. -func stopSignal(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) != 1 { - return errExactlyOneArgument("STOPSIGNAL") - } - - sig := args[0] - _, err := signal.ParseSignal(sig) - if err != nil { - return err - } - - b.runConfig.StopSignal = sig - return b.commit("", b.runConfig.Cmd, fmt.Sprintf("STOPSIGNAL %v", args)) -} - -// ARG name[=value] -// -// Adds the variable foo to the trusted list of variables that can be passed -// to builder using the --build-arg flag for expansion/subsitution or passing to 'run'. -// Dockerfile author may optionally set a default value of this variable. -func arg(b *Builder, args []string, attributes map[string]bool, original string) error { - if len(args) != 1 { - return errExactlyOneArgument("ARG") - } - - var ( - name string - newValue string - hasDefault bool - ) - - arg := args[0] - // 'arg' can just be a name or name-value pair. Note that this is different - // from 'env' that handles the split of name and value at the parser level. - // The reason for doing it differently for 'arg' is that we support just - // defining an arg and not assign it a value (while 'env' always expects a - // name-value pair). If possible, it will be good to harmonize the two. - if strings.Contains(arg, "=") { - parts := strings.SplitN(arg, "=", 2) - if len(parts[0]) == 0 { - return errBlankCommandNames("ARG") - } - - name = parts[0] - newValue = parts[1] - hasDefault = true - } else { - name = arg - hasDefault = false - } - // add the arg to allowed list of build-time args from this step on. - b.allowedBuildArgs[name] = true - - // If there is a default value associated with this arg then add it to the - // b.buildArgs if one is not already passed to the builder. The args passed - // to builder override the default value of 'arg'. Note that a 'nil' for - // a value means that the user specified "--build-arg FOO" and "FOO" wasn't - // defined as an env var - and in that case we DO want to use the default - // value specified in the ARG cmd. - if baValue, ok := b.options.BuildArgs[name]; (!ok || baValue == nil) && hasDefault { - b.options.BuildArgs[name] = &newValue - } - - return b.commit("", b.runConfig.Cmd, fmt.Sprintf("ARG %s", arg)) -} - -// SHELL powershell -command -// -// Set the non-default shell to use. -func shell(b *Builder, args []string, attributes map[string]bool, original string) error { - if err := b.flags.Parse(); err != nil { - return err - } - shellSlice := handleJSONArgs(args, attributes) - switch { - case len(shellSlice) == 0: - // SHELL [] - return errAtLeastOneArgument("SHELL") - case attributes["json"]: - // SHELL ["powershell", "-command"] - b.runConfig.Shell = strslice.StrSlice(shellSlice) - default: - // SHELL powershell -command - not JSON - return errNotJSON("SHELL", original) - } - return b.commit("", b.runConfig.Cmd, fmt.Sprintf("SHELL %v", shellSlice)) -} - -func errAtLeastOneArgument(command string) error { - return fmt.Errorf("%s requires at least one argument", command) -} - -func errExactlyOneArgument(command string) error { - return fmt.Errorf("%s requires exactly one argument", command) -} - -func errAtLeastTwoArguments(command string) error { - return fmt.Errorf("%s requires at least two arguments", command) -} - -func errBlankCommandNames(command string) error { - return fmt.Errorf("%s names can not be blank", command) -} - -func errTooManyArguments(command string) error { - return fmt.Errorf("Bad input to %s, too many arguments", command) -} - -// getShell is a helper function which gets the right shell for prefixing the -// shell-form of RUN, ENTRYPOINT and CMD instructions -func getShell(c *container.Config) []string { - if 0 == len(c.Shell) { - return defaultShell[:] - } - return c.Shell[:] -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_test.go b/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_test.go deleted file mode 100644 index f7c57f7..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_test.go +++ /dev/null @@ -1,517 +0,0 @@ -package dockerfile - -import ( - "fmt" - "runtime" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/strslice" - "github.com/docker/go-connections/nat" -) - -type commandWithFunction struct { - name string - function func(args []string) error -} - -func TestCommandsExactlyOneArgument(t *testing.T) { - commands := []commandWithFunction{ - {"MAINTAINER", func(args []string) error { return maintainer(nil, args, nil, "") }}, - {"FROM", func(args []string) error { return from(nil, args, nil, "") }}, - {"WORKDIR", func(args []string) error { return workdir(nil, args, nil, "") }}, - {"USER", func(args []string) error { return user(nil, args, nil, "") }}, - {"STOPSIGNAL", func(args []string) error { return stopSignal(nil, args, nil, "") }}} - - for _, command := range commands { - err := command.function([]string{}) - - if err == nil { - t.Fatalf("Error should be present for %s command", command.name) - } - - expectedError := errExactlyOneArgument(command.name) - - if err.Error() != expectedError.Error() { - t.Fatalf("Wrong error message for %s. Got: %s. Should be: %s", command.name, err.Error(), expectedError) - } - } -} - -func TestCommandsAtLeastOneArgument(t *testing.T) { - commands := []commandWithFunction{ - {"ENV", func(args []string) error { return env(nil, args, nil, "") }}, - {"LABEL", func(args []string) error { return label(nil, args, nil, "") }}, - {"ONBUILD", func(args []string) error { return onbuild(nil, args, nil, "") }}, - {"HEALTHCHECK", func(args []string) error { return healthcheck(nil, args, nil, "") }}, - {"EXPOSE", func(args []string) error { return expose(nil, args, nil, "") }}, - {"VOLUME", func(args []string) error { return volume(nil, args, nil, "") }}} - - for _, command := range commands { - err := command.function([]string{}) - - if err == nil { - t.Fatalf("Error should be present for %s command", command.name) - } - - expectedError := errAtLeastOneArgument(command.name) - - if err.Error() != expectedError.Error() { - t.Fatalf("Wrong error message for %s. Got: %s. Should be: %s", command.name, err.Error(), expectedError) - } - } -} - -func TestCommandsAtLeastTwoArguments(t *testing.T) { - commands := []commandWithFunction{ - {"ADD", func(args []string) error { return add(nil, args, nil, "") }}, - {"COPY", func(args []string) error { return dispatchCopy(nil, args, nil, "") }}} - - for _, command := range commands { - err := command.function([]string{"arg1"}) - - if err == nil { - t.Fatalf("Error should be present for %s command", command.name) - } - - expectedError := errAtLeastTwoArguments(command.name) - - if err.Error() != expectedError.Error() { - t.Fatalf("Wrong error message for %s. Got: %s. Should be: %s", command.name, err.Error(), expectedError) - } - } -} - -func TestCommandsTooManyArguments(t *testing.T) { - commands := []commandWithFunction{ - {"ENV", func(args []string) error { return env(nil, args, nil, "") }}, - {"LABEL", func(args []string) error { return label(nil, args, nil, "") }}} - - for _, command := range commands { - err := command.function([]string{"arg1", "arg2", "arg3"}) - - if err == nil { - t.Fatalf("Error should be present for %s command", command.name) - } - - expectedError := errTooManyArguments(command.name) - - if err.Error() != expectedError.Error() { - t.Fatalf("Wrong error message for %s. Got: %s. Should be: %s", command.name, err.Error(), expectedError) - } - } -} - -func TestCommandseBlankNames(t *testing.T) { - bflags := &BFlags{} - config := &container.Config{} - - b := &Builder{flags: bflags, runConfig: config, disableCommit: true} - - commands := []commandWithFunction{ - {"ENV", func(args []string) error { return env(b, args, nil, "") }}, - {"LABEL", func(args []string) error { return label(b, args, nil, "") }}, - } - - for _, command := range commands { - err := command.function([]string{"", ""}) - - if err == nil { - t.Fatalf("Error should be present for %s command", command.name) - } - - expectedError := errBlankCommandNames(command.name) - - if err.Error() != expectedError.Error() { - t.Fatalf("Wrong error message for %s. Got: %s. Should be: %s", command.name, err.Error(), expectedError) - } - } -} - -func TestEnv2Variables(t *testing.T) { - variables := []string{"var1", "val1", "var2", "val2"} - - bflags := &BFlags{} - config := &container.Config{} - - b := &Builder{flags: bflags, runConfig: config, disableCommit: true} - - if err := env(b, variables, nil, ""); err != nil { - t.Fatalf("Error when executing env: %s", err.Error()) - } - - expectedVar1 := fmt.Sprintf("%s=%s", variables[0], variables[1]) - expectedVar2 := fmt.Sprintf("%s=%s", variables[2], variables[3]) - - if b.runConfig.Env[0] != expectedVar1 { - t.Fatalf("Wrong env output for first variable. Got: %s. Should be: %s", b.runConfig.Env[0], expectedVar1) - } - - if b.runConfig.Env[1] != expectedVar2 { - t.Fatalf("Wrong env output for second variable. Got: %s, Should be: %s", b.runConfig.Env[1], expectedVar2) - } -} - -func TestMaintainer(t *testing.T) { - maintainerEntry := "Some Maintainer " - - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - if err := maintainer(b, []string{maintainerEntry}, nil, ""); err != nil { - t.Fatalf("Error when executing maintainer: %s", err.Error()) - } - - if b.maintainer != maintainerEntry { - t.Fatalf("Maintainer in builder should be set to %s. Got: %s", maintainerEntry, b.maintainer) - } -} - -func TestLabel(t *testing.T) { - labelName := "label" - labelValue := "value" - - labelEntry := []string{labelName, labelValue} - - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - if err := label(b, labelEntry, nil, ""); err != nil { - t.Fatalf("Error when executing label: %s", err.Error()) - } - - if val, ok := b.runConfig.Labels[labelName]; ok { - if val != labelValue { - t.Fatalf("Label %s should have value %s, had %s instead", labelName, labelValue, val) - } - } else { - t.Fatalf("Label %s should be present but it is not", labelName) - } -} - -func TestFrom(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - err := from(b, []string{"scratch"}, nil, "") - - if runtime.GOOS == "windows" { - if err == nil { - t.Fatalf("Error not set on Windows") - } - - expectedError := "Windows does not support FROM scratch" - - if !strings.Contains(err.Error(), expectedError) { - t.Fatalf("Error message not correct on Windows. Should be: %s, got: %s", expectedError, err.Error()) - } - } else { - if err != nil { - t.Fatalf("Error when executing from: %s", err.Error()) - } - - if b.image != "" { - t.Fatalf("Image shoule be empty, got: %s", b.image) - } - - if b.noBaseImage != true { - t.Fatalf("Image should not have any base image, got: %v", b.noBaseImage) - } - } -} - -func TestOnbuildIllegalTriggers(t *testing.T) { - triggers := []struct{ command, expectedError string }{ - {"ONBUILD", "Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed"}, - {"MAINTAINER", "MAINTAINER isn't allowed as an ONBUILD trigger"}, - {"FROM", "FROM isn't allowed as an ONBUILD trigger"}} - - for _, trigger := range triggers { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - err := onbuild(b, []string{trigger.command}, nil, "") - - if err == nil { - t.Fatalf("Error should not be nil") - } - - if !strings.Contains(err.Error(), trigger.expectedError) { - t.Fatalf("Error message not correct. Should be: %s, got: %s", trigger.expectedError, err.Error()) - } - } -} - -func TestOnbuild(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - err := onbuild(b, []string{"ADD", ".", "/app/src"}, nil, "ONBUILD ADD . /app/src") - - if err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - expectedOnbuild := "ADD . /app/src" - - if b.runConfig.OnBuild[0] != expectedOnbuild { - t.Fatalf("Wrong ONBUILD command. Expected: %s, got: %s", expectedOnbuild, b.runConfig.OnBuild[0]) - } -} - -func TestWorkdir(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - workingDir := "/app" - - if runtime.GOOS == "windows" { - workingDir = "C:\app" - } - - err := workdir(b, []string{workingDir}, nil, "") - - if err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - if b.runConfig.WorkingDir != workingDir { - t.Fatalf("WorkingDir should be set to %s, got %s", workingDir, b.runConfig.WorkingDir) - } - -} - -func TestCmd(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - command := "./executable" - - err := cmd(b, []string{command}, nil, "") - - if err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - var expectedCommand strslice.StrSlice - - if runtime.GOOS == "windows" { - expectedCommand = strslice.StrSlice(append([]string{"cmd"}, "/S", "/C", command)) - } else { - expectedCommand = strslice.StrSlice(append([]string{"/bin/sh"}, "-c", command)) - } - - if !compareStrSlice(b.runConfig.Cmd, expectedCommand) { - t.Fatalf("Command should be set to %s, got %s", command, b.runConfig.Cmd) - } - - if !b.cmdSet { - t.Fatalf("Command should be marked as set") - } -} - -func compareStrSlice(slice1, slice2 strslice.StrSlice) bool { - if len(slice1) != len(slice2) { - return false - } - - for i := range slice1 { - if slice1[i] != slice2[i] { - return false - } - } - - return true -} - -func TestHealthcheckNone(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - if err := healthcheck(b, []string{"NONE"}, nil, ""); err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - if b.runConfig.Healthcheck == nil { - t.Fatal("Healthcheck should be set, got nil") - } - - expectedTest := strslice.StrSlice(append([]string{"NONE"})) - - if !compareStrSlice(expectedTest, b.runConfig.Healthcheck.Test) { - t.Fatalf("Command should be set to %s, got %s", expectedTest, b.runConfig.Healthcheck.Test) - } -} - -func TestHealthcheckCmd(t *testing.T) { - b := &Builder{flags: &BFlags{flags: make(map[string]*Flag)}, runConfig: &container.Config{}, disableCommit: true} - - if err := healthcheck(b, []string{"CMD", "curl", "-f", "http://localhost/", "||", "exit", "1"}, nil, ""); err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - if b.runConfig.Healthcheck == nil { - t.Fatal("Healthcheck should be set, got nil") - } - - expectedTest := strslice.StrSlice(append([]string{"CMD-SHELL"}, "curl -f http://localhost/ || exit 1")) - - if !compareStrSlice(expectedTest, b.runConfig.Healthcheck.Test) { - t.Fatalf("Command should be set to %s, got %s", expectedTest, b.runConfig.Healthcheck.Test) - } -} - -func TestEntrypoint(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - entrypointCmd := "/usr/sbin/nginx" - - if err := entrypoint(b, []string{entrypointCmd}, nil, ""); err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - if b.runConfig.Entrypoint == nil { - t.Fatalf("Entrypoint should be set") - } - - var expectedEntrypoint strslice.StrSlice - - if runtime.GOOS == "windows" { - expectedEntrypoint = strslice.StrSlice(append([]string{"cmd"}, "/S", "/C", entrypointCmd)) - } else { - expectedEntrypoint = strslice.StrSlice(append([]string{"/bin/sh"}, "-c", entrypointCmd)) - } - - if !compareStrSlice(expectedEntrypoint, b.runConfig.Entrypoint) { - t.Fatalf("Entrypoint command should be set to %s, got %s", expectedEntrypoint, b.runConfig.Entrypoint) - } -} - -func TestExpose(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - exposedPort := "80" - - if err := expose(b, []string{exposedPort}, nil, ""); err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - if b.runConfig.ExposedPorts == nil { - t.Fatalf("ExposedPorts should be set") - } - - if len(b.runConfig.ExposedPorts) != 1 { - t.Fatalf("ExposedPorts should contain only 1 element. Got %s", b.runConfig.ExposedPorts) - } - - portsMapping, err := nat.ParsePortSpec(exposedPort) - - if err != nil { - t.Fatalf("Error when parsing port spec: %s", err.Error()) - } - - if _, ok := b.runConfig.ExposedPorts[portsMapping[0].Port]; !ok { - t.Fatalf("Port %s should be present. Got %s", exposedPort, b.runConfig.ExposedPorts) - } -} - -func TestUser(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - userCommand := "foo" - - if err := user(b, []string{userCommand}, nil, ""); err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - if b.runConfig.User != userCommand { - t.Fatalf("User should be set to %s, got %s", userCommand, b.runConfig.User) - } -} - -func TestVolume(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - exposedVolume := "/foo" - - if err := volume(b, []string{exposedVolume}, nil, ""); err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - if b.runConfig.Volumes == nil { - t.Fatalf("Volumes should be set") - } - - if len(b.runConfig.Volumes) != 1 { - t.Fatalf("Volumes should contain only 1 element. Got %s", b.runConfig.Volumes) - } - - if _, ok := b.runConfig.Volumes[exposedVolume]; !ok { - t.Fatalf("Volume %s should be present. Got %s", exposedVolume, b.runConfig.Volumes) - } -} - -func TestStopSignal(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - signal := "SIGKILL" - - if err := stopSignal(b, []string{signal}, nil, ""); err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - if b.runConfig.StopSignal != signal { - t.Fatalf("StopSignal should be set to %s, got %s", signal, b.runConfig.StopSignal) - } -} - -func TestArg(t *testing.T) { - buildOptions := &types.ImageBuildOptions{BuildArgs: make(map[string]*string)} - - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true, allowedBuildArgs: make(map[string]bool), options: buildOptions} - - argName := "foo" - argVal := "bar" - argDef := fmt.Sprintf("%s=%s", argName, argVal) - - if err := arg(b, []string{argDef}, nil, ""); err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - allowed, ok := b.allowedBuildArgs[argName] - - if !ok { - t.Fatalf("%s argument should be allowed as a build arg", argName) - } - - if !allowed { - t.Fatalf("%s argument was present in map but disallowed as a build arg", argName) - } - - val, ok := b.options.BuildArgs[argName] - - if !ok { - t.Fatalf("%s argument should be a build arg", argName) - } - - if *val != "bar" { - t.Fatalf("%s argument should have default value 'bar', got %s", argName, val) - } -} - -func TestShell(t *testing.T) { - b := &Builder{flags: &BFlags{}, runConfig: &container.Config{}, disableCommit: true} - - shellCmd := "powershell" - - attrs := make(map[string]bool) - attrs["json"] = true - - if err := shell(b, []string{shellCmd}, attrs, ""); err != nil { - t.Fatalf("Error should be empty, got: %s", err.Error()) - } - - if b.runConfig.Shell == nil { - t.Fatalf("Shell should be set") - } - - expectedShell := strslice.StrSlice([]string{shellCmd}) - - if !compareStrSlice(expectedShell, b.runConfig.Shell) { - t.Fatalf("Shell should be set to %s, got %s", expectedShell, b.runConfig.Shell) - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_unix.go b/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_unix.go deleted file mode 100644 index 8b0dfc3..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_unix.go +++ /dev/null @@ -1,27 +0,0 @@ -// +build !windows - -package dockerfile - -import ( - "fmt" - "os" - "path/filepath" -) - -// normaliseWorkdir normalises a user requested working directory in a -// platform sematically consistent way. -func normaliseWorkdir(current string, requested string) (string, error) { - if requested == "" { - return "", fmt.Errorf("cannot normalise nothing") - } - current = filepath.FromSlash(current) - requested = filepath.FromSlash(requested) - if !filepath.IsAbs(requested) { - return filepath.Join(string(os.PathSeparator), current, requested), nil - } - return requested, nil -} - -func errNotJSON(command, _ string) error { - return fmt.Errorf("%s requires the arguments to be in JSON form", command) -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_unix_test.go b/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_unix_test.go deleted file mode 100644 index 4aae6b4..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_unix_test.go +++ /dev/null @@ -1,33 +0,0 @@ -// +build !windows - -package dockerfile - -import ( - "testing" -) - -func TestNormaliseWorkdir(t *testing.T) { - testCases := []struct{ current, requested, expected, expectedError string }{ - {``, ``, ``, `cannot normalise nothing`}, - {``, `foo`, `/foo`, ``}, - {``, `/foo`, `/foo`, ``}, - {`/foo`, `bar`, `/foo/bar`, ``}, - {`/foo`, `/bar`, `/bar`, ``}, - } - - for _, test := range testCases { - normalised, err := normaliseWorkdir(test.current, test.requested) - - if test.expectedError != "" && err == nil { - t.Fatalf("NormaliseWorkdir should return an error %s, got nil", test.expectedError) - } - - if test.expectedError != "" && err.Error() != test.expectedError { - t.Fatalf("NormaliseWorkdir returned wrong error. Expected %s, got %s", test.expectedError, err.Error()) - } - - if normalised != test.expected { - t.Fatalf("NormaliseWorkdir error. Expected %s for current %s and requested %s, got %s", test.expected, test.current, test.requested, normalised) - } - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_windows.go b/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_windows.go deleted file mode 100644 index e890c3a..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_windows.go +++ /dev/null @@ -1,86 +0,0 @@ -package dockerfile - -import ( - "fmt" - "os" - "path/filepath" - "regexp" - "strings" - - "github.com/docker/docker/pkg/system" -) - -var pattern = regexp.MustCompile(`^[a-zA-Z]:\.$`) - -// normaliseWorkdir normalises a user requested working directory in a -// platform sematically consistent way. -func normaliseWorkdir(current string, requested string) (string, error) { - if requested == "" { - return "", fmt.Errorf("cannot normalise nothing") - } - - // `filepath.Clean` will replace "" with "." so skip in that case - if current != "" { - current = filepath.Clean(current) - } - if requested != "" { - requested = filepath.Clean(requested) - } - - // If either current or requested in Windows is: - // C: - // C:. - // then an error will be thrown as the definition for the above - // refers to `current directory on drive C:` - // Since filepath.Clean() will automatically normalize the above - // to `C:.`, we only need to check the last format - if pattern.MatchString(current) { - return "", fmt.Errorf("%s is not a directory. If you are specifying a drive letter, please add a trailing '\\'", current) - } - if pattern.MatchString(requested) { - return "", fmt.Errorf("%s is not a directory. If you are specifying a drive letter, please add a trailing '\\'", requested) - } - - // Target semantics is C:\somefolder, specifically in the format: - // UPPERCASEDriveLetter-Colon-Backslash-FolderName. We are already - // guaranteed that `current`, if set, is consistent. This allows us to - // cope correctly with any of the following in a Dockerfile: - // WORKDIR a --> C:\a - // WORKDIR c:\\foo --> C:\foo - // WORKDIR \\foo --> C:\foo - // WORKDIR /foo --> C:\foo - // WORKDIR c:\\foo \ WORKDIR bar --> C:\foo --> C:\foo\bar - // WORKDIR C:/foo \ WORKDIR bar --> C:\foo --> C:\foo\bar - // WORKDIR C:/foo \ WORKDIR \\bar --> C:\foo --> C:\bar - // WORKDIR /foo \ WORKDIR c:/bar --> C:\foo --> C:\bar - if len(current) == 0 || system.IsAbs(requested) { - if (requested[0] == os.PathSeparator) || - (len(requested) > 1 && string(requested[1]) != ":") || - (len(requested) == 1) { - requested = filepath.Join(`C:\`, requested) - } - } else { - requested = filepath.Join(current, requested) - } - // Upper-case drive letter - return (strings.ToUpper(string(requested[0])) + requested[1:]), nil -} - -func errNotJSON(command, original string) error { - // For Windows users, give a hint if it looks like it might contain - // a path which hasn't been escaped such as ["c:\windows\system32\prog.exe", "-param"], - // as JSON must be escaped. Unfortunate... - // - // Specifically looking for quote-driveletter-colon-backslash, there's no - // double backslash and a [] pair. No, this is not perfect, but it doesn't - // have to be. It's simply a hint to make life a little easier. - extra := "" - original = filepath.FromSlash(strings.ToLower(strings.Replace(strings.ToLower(original), strings.ToLower(command)+" ", "", -1))) - if len(regexp.MustCompile(`"[a-z]:\\.*`).FindStringSubmatch(original)) > 0 && - !strings.Contains(original, `\\`) && - strings.Contains(original, "[") && - strings.Contains(original, "]") { - extra = fmt.Sprintf(`. It looks like '%s' includes a file path without an escaped back-slash. JSON requires back-slashes to be escaped such as ["c:\\path\\to\\file.exe", "/parameter"]`, original) - } - return fmt.Errorf("%s requires the arguments to be in JSON form%s", command, extra) -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_windows_test.go b/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_windows_test.go deleted file mode 100644 index 3319c06..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/dispatchers_windows_test.go +++ /dev/null @@ -1,40 +0,0 @@ -// +build windows - -package dockerfile - -import "testing" - -func TestNormaliseWorkdir(t *testing.T) { - tests := []struct{ current, requested, expected, etext string }{ - {``, ``, ``, `cannot normalise nothing`}, - {``, `C:`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, - {``, `C:.`, ``, `C:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, - {`c:`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, - {`c:.`, `\a`, ``, `c:. is not a directory. If you are specifying a drive letter, please add a trailing '\'`}, - {``, `a`, `C:\a`, ``}, - {``, `c:\foo`, `C:\foo`, ``}, - {``, `c:\\foo`, `C:\foo`, ``}, - {``, `\foo`, `C:\foo`, ``}, - {``, `\\foo`, `C:\foo`, ``}, - {``, `/foo`, `C:\foo`, ``}, - {``, `C:/foo`, `C:\foo`, ``}, - {`C:\foo`, `bar`, `C:\foo\bar`, ``}, - {`C:\foo`, `/bar`, `C:\bar`, ``}, - {`C:\foo`, `\bar`, `C:\bar`, ``}, - } - for _, i := range tests { - r, e := normaliseWorkdir(i.current, i.requested) - - if i.etext != "" && e == nil { - t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got no error", i.etext, i.current, i.requested) - } - - if i.etext != "" && e.Error() != i.etext { - t.Fatalf("TestNormaliseWorkingDir Expected error %s for '%s' '%s', got %s", i.etext, i.current, i.requested, e.Error()) - } - - if r != i.expected { - t.Fatalf("TestNormaliseWorkingDir Expected '%s' for '%s' '%s', got '%s'", i.expected, i.current, i.requested, r) - } - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/envVarTest b/vendor/github.com/docker/docker/builder/dockerfile/envVarTest deleted file mode 100644 index 067dca9..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/envVarTest +++ /dev/null @@ -1,116 +0,0 @@ -A|hello | hello -A|he'll'o | hello -A|he'llo | hello -A|he\'llo | he'llo -A|he\\'llo | he\llo -A|abc\tdef | abctdef -A|"abc\tdef" | abc\tdef -A|'abc\tdef' | abc\tdef -A|hello\ | hello -A|hello\\ | hello\ -A|"hello | hello -A|"hello\" | hello" -A|"hel'lo" | hel'lo -A|'hello | hello -A|'hello\' | hello\ -A|"''" | '' -A|$. | $. -A|$1 | -A|he$1x | hex -A|he$.x | he$.x -# Next one is different on Windows as $pwd==$PWD -U|he$pwd. | he. -W|he$pwd. | he/home. -A|he$PWD | he/home -A|he\$PWD | he$PWD -A|he\\$PWD | he\/home -A|he\${} | he${} -A|he\${}xx | he${}xx -A|he${} | he -A|he${}xx | hexx -A|he${hi} | he -A|he${hi}xx | hexx -A|he${PWD} | he/home -A|he${.} | error -A|he${XXX:-000}xx | he000xx -A|he${PWD:-000}xx | he/homexx -A|he${XXX:-$PWD}xx | he/homexx -A|he${XXX:-${PWD:-yyy}}xx | he/homexx -A|he${XXX:-${YYY:-yyy}}xx | heyyyxx -A|he${XXX:YYY} | error -A|he${XXX:+${PWD}}xx | hexx -A|he${PWD:+${XXX}}xx | hexx -A|he${PWD:+${SHELL}}xx | hebashxx -A|he${XXX:+000}xx | hexx -A|he${PWD:+000}xx | he000xx -A|'he${XX}' | he${XX} -A|"he${PWD}" | he/home -A|"he'$PWD'" | he'/home' -A|"$PWD" | /home -A|'$PWD' | $PWD -A|'\$PWD' | \$PWD -A|'"hello"' | "hello" -A|he\$PWD | he$PWD -A|"he\$PWD" | he$PWD -A|'he\$PWD' | he\$PWD -A|he${PWD | error -A|he${PWD:=000}xx | error -A|he${PWD:+${PWD}:}xx | he/home:xx -A|he${XXX:-\$PWD:}xx | he$PWD:xx -A|he${XXX:-\${PWD}z}xx | he${PWDz}xx -A|안녕하세요 | 안녕하세요 -A|안'녕'하세요 | 안녕하세요 -A|안'녕하세요 | 안녕하세요 -A|안녕\'하세요 | 안녕'하세요 -A|안\\'녕하세요 | 안\녕하세요 -A|안녕\t하세요 | 안녕t하세요 -A|"안녕\t하세요" | 안녕\t하세요 -A|'안녕\t하세요 | 안녕\t하세요 -A|안녕하세요\ | 안녕하세요 -A|안녕하세요\\ | 안녕하세요\ -A|"안녕하세요 | 안녕하세요 -A|"안녕하세요\" | 안녕하세요" -A|"안녕'하세요" | 안녕'하세요 -A|'안녕하세요 | 안녕하세요 -A|'안녕하세요\' | 안녕하세요\ -A|안녕$1x | 안녕x -A|안녕$.x | 안녕$.x -# Next one is different on Windows as $pwd==$PWD -U|안녕$pwd. | 안녕. -W|안녕$pwd. | 안녕/home. -A|안녕$PWD | 안녕/home -A|안녕\$PWD | 안녕$PWD -A|안녕\\$PWD | 안녕\/home -A|안녕\${} | 안녕${} -A|안녕\${}xx | 안녕${}xx -A|안녕${} | 안녕 -A|안녕${}xx | 안녕xx -A|안녕${hi} | 안녕 -A|안녕${hi}xx | 안녕xx -A|안녕${PWD} | 안녕/home -A|안녕${.} | error -A|안녕${XXX:-000}xx | 안녕000xx -A|안녕${PWD:-000}xx | 안녕/homexx -A|안녕${XXX:-$PWD}xx | 안녕/homexx -A|안녕${XXX:-${PWD:-yyy}}xx | 안녕/homexx -A|안녕${XXX:-${YYY:-yyy}}xx | 안녕yyyxx -A|안녕${XXX:YYY} | error -A|안녕${XXX:+${PWD}}xx | 안녕xx -A|안녕${PWD:+${XXX}}xx | 안녕xx -A|안녕${PWD:+${SHELL}}xx | 안녕bashxx -A|안녕${XXX:+000}xx | 안녕xx -A|안녕${PWD:+000}xx | 안녕000xx -A|'안녕${XX}' | 안녕${XX} -A|"안녕${PWD}" | 안녕/home -A|"안녕'$PWD'" | 안녕'/home' -A|'"안녕"' | "안녕" -A|안녕\$PWD | 안녕$PWD -A|"안녕\$PWD" | 안녕$PWD -A|'안녕\$PWD' | 안녕\$PWD -A|안녕${PWD | error -A|안녕${PWD:=000}xx | error -A|안녕${PWD:+${PWD}:}xx | 안녕/home:xx -A|안녕${XXX:-\$PWD:}xx | 안녕$PWD:xx -A|안녕${XXX:-\${PWD}z}xx | 안녕${PWDz}xx -A|$KOREAN | 한국어 -A|안녕$KOREAN | 안녕한국어 diff --git a/vendor/github.com/docker/docker/builder/dockerfile/evaluator.go b/vendor/github.com/docker/docker/builder/dockerfile/evaluator.go deleted file mode 100644 index f5997c9..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/evaluator.go +++ /dev/null @@ -1,244 +0,0 @@ -// Package dockerfile is the evaluation step in the Dockerfile parse/evaluate pipeline. -// -// It incorporates a dispatch table based on the parser.Node values (see the -// parser package for more information) that are yielded from the parser itself. -// Calling NewBuilder with the BuildOpts struct can be used to customize the -// experience for execution purposes only. Parsing is controlled in the parser -// package, and this division of responsibility should be respected. -// -// Please see the jump table targets for the actual invocations, most of which -// will call out to the functions in internals.go to deal with their tasks. -// -// ONBUILD is a special case, which is covered in the onbuild() func in -// dispatchers.go. -// -// The evaluator uses the concept of "steps", which are usually each processable -// line in the Dockerfile. Each step is numbered and certain actions are taken -// before and after each step, such as creating an image ID and removing temporary -// containers and images. Note that ONBUILD creates a kinda-sorta "sub run" which -// includes its own set of steps (usually only one of them). -package dockerfile - -import ( - "fmt" - "strings" - - "github.com/docker/docker/builder/dockerfile/command" - "github.com/docker/docker/builder/dockerfile/parser" -) - -// Environment variable interpolation will happen on these statements only. -var replaceEnvAllowed = map[string]bool{ - command.Env: true, - command.Label: true, - command.Add: true, - command.Copy: true, - command.Workdir: true, - command.Expose: true, - command.Volume: true, - command.User: true, - command.StopSignal: true, - command.Arg: true, -} - -// Certain commands are allowed to have their args split into more -// words after env var replacements. Meaning: -// ENV foo="123 456" -// EXPOSE $foo -// should result in the same thing as: -// EXPOSE 123 456 -// and not treat "123 456" as a single word. -// Note that: EXPOSE "$foo" and EXPOSE $foo are not the same thing. -// Quotes will cause it to still be treated as single word. -var allowWordExpansion = map[string]bool{ - command.Expose: true, -} - -var evaluateTable map[string]func(*Builder, []string, map[string]bool, string) error - -func init() { - evaluateTable = map[string]func(*Builder, []string, map[string]bool, string) error{ - command.Add: add, - command.Arg: arg, - command.Cmd: cmd, - command.Copy: dispatchCopy, // copy() is a go builtin - command.Entrypoint: entrypoint, - command.Env: env, - command.Expose: expose, - command.From: from, - command.Healthcheck: healthcheck, - command.Label: label, - command.Maintainer: maintainer, - command.Onbuild: onbuild, - command.Run: run, - command.Shell: shell, - command.StopSignal: stopSignal, - command.User: user, - command.Volume: volume, - command.Workdir: workdir, - } -} - -// This method is the entrypoint to all statement handling routines. -// -// Almost all nodes will have this structure: -// Child[Node, Node, Node] where Child is from parser.Node.Children and each -// node comes from parser.Node.Next. This forms a "line" with a statement and -// arguments and we process them in this normalized form by hitting -// evaluateTable with the leaf nodes of the command and the Builder object. -// -// ONBUILD is a special case; in this case the parser will emit: -// Child[Node, Child[Node, Node...]] where the first node is the literal -// "onbuild" and the child entrypoint is the command of the ONBUILD statement, -// such as `RUN` in ONBUILD RUN foo. There is special case logic in here to -// deal with that, at least until it becomes more of a general concern with new -// features. -func (b *Builder) dispatch(stepN int, stepTotal int, ast *parser.Node) error { - cmd := ast.Value - upperCasedCmd := strings.ToUpper(cmd) - - // To ensure the user is given a decent error message if the platform - // on which the daemon is running does not support a builder command. - if err := platformSupports(strings.ToLower(cmd)); err != nil { - return err - } - - attrs := ast.Attributes - original := ast.Original - flags := ast.Flags - strList := []string{} - msg := fmt.Sprintf("Step %d/%d : %s", stepN+1, stepTotal, upperCasedCmd) - - if len(ast.Flags) > 0 { - msg += " " + strings.Join(ast.Flags, " ") - } - - if cmd == "onbuild" { - if ast.Next == nil { - return fmt.Errorf("ONBUILD requires at least one argument") - } - ast = ast.Next.Children[0] - strList = append(strList, ast.Value) - msg += " " + ast.Value - - if len(ast.Flags) > 0 { - msg += " " + strings.Join(ast.Flags, " ") - } - - } - - // count the number of nodes that we are going to traverse first - // so we can pre-create the argument and message array. This speeds up the - // allocation of those list a lot when they have a lot of arguments - cursor := ast - var n int - for cursor.Next != nil { - cursor = cursor.Next - n++ - } - msgList := make([]string, n) - - var i int - // Append the build-time args to config-environment. - // This allows builder config to override the variables, making the behavior similar to - // a shell script i.e. `ENV foo bar` overrides value of `foo` passed in build - // context. But `ENV foo $foo` will use the value from build context if one - // isn't already been defined by a previous ENV primitive. - // Note, we get this behavior because we know that ProcessWord() will - // stop on the first occurrence of a variable name and not notice - // a subsequent one. So, putting the buildArgs list after the Config.Env - // list, in 'envs', is safe. - envs := b.runConfig.Env - for key, val := range b.options.BuildArgs { - if !b.isBuildArgAllowed(key) { - // skip build-args that are not in allowed list, meaning they have - // not been defined by an "ARG" Dockerfile command yet. - // This is an error condition but only if there is no "ARG" in the entire - // Dockerfile, so we'll generate any necessary errors after we parsed - // the entire file (see 'leftoverArgs' processing in evaluator.go ) - continue - } - envs = append(envs, fmt.Sprintf("%s=%s", key, *val)) - } - for ast.Next != nil { - ast = ast.Next - var str string - str = ast.Value - if replaceEnvAllowed[cmd] { - var err error - var words []string - - if allowWordExpansion[cmd] { - words, err = ProcessWords(str, envs, b.directive.EscapeToken) - if err != nil { - return err - } - strList = append(strList, words...) - } else { - str, err = ProcessWord(str, envs, b.directive.EscapeToken) - if err != nil { - return err - } - strList = append(strList, str) - } - } else { - strList = append(strList, str) - } - msgList[i] = ast.Value - i++ - } - - msg += " " + strings.Join(msgList, " ") - fmt.Fprintln(b.Stdout, msg) - - // XXX yes, we skip any cmds that are not valid; the parser should have - // picked these out already. - if f, ok := evaluateTable[cmd]; ok { - b.flags = NewBFlags() - b.flags.Args = flags - return f(b, strList, attrs, original) - } - - return fmt.Errorf("Unknown instruction: %s", upperCasedCmd) -} - -// checkDispatch does a simple check for syntax errors of the Dockerfile. -// Because some of the instructions can only be validated through runtime, -// arg, env, etc., this syntax check will not be complete and could not replace -// the runtime check. Instead, this function is only a helper that allows -// user to find out the obvious error in Dockerfile earlier on. -// onbuild bool: indicate if instruction XXX is part of `ONBUILD XXX` trigger -func (b *Builder) checkDispatch(ast *parser.Node, onbuild bool) error { - cmd := ast.Value - upperCasedCmd := strings.ToUpper(cmd) - - // To ensure the user is given a decent error message if the platform - // on which the daemon is running does not support a builder command. - if err := platformSupports(strings.ToLower(cmd)); err != nil { - return err - } - - // The instruction itself is ONBUILD, we will make sure it follows with at - // least one argument - if upperCasedCmd == "ONBUILD" { - if ast.Next == nil { - return fmt.Errorf("ONBUILD requires at least one argument") - } - } - - // The instruction is part of ONBUILD trigger (not the instruction itself) - if onbuild { - switch upperCasedCmd { - case "ONBUILD": - return fmt.Errorf("Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed") - case "MAINTAINER", "FROM": - return fmt.Errorf("%s isn't allowed as an ONBUILD trigger", upperCasedCmd) - } - } - - if _, ok := evaluateTable[cmd]; ok { - return nil - } - - return fmt.Errorf("Unknown instruction: %s", upperCasedCmd) -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/evaluator_test.go b/vendor/github.com/docker/docker/builder/dockerfile/evaluator_test.go deleted file mode 100644 index 4340a2f..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/evaluator_test.go +++ /dev/null @@ -1,197 +0,0 @@ -package dockerfile - -import ( - "io/ioutil" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/builder" - "github.com/docker/docker/builder/dockerfile/parser" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/reexec" -) - -type dispatchTestCase struct { - name, dockerfile, expectedError string - files map[string]string -} - -func init() { - reexec.Init() -} - -func initDispatchTestCases() []dispatchTestCase { - dispatchTestCases := []dispatchTestCase{{ - name: "copyEmptyWhitespace", - dockerfile: `COPY - quux \ - bar`, - expectedError: "COPY requires at least two arguments", - }, - { - name: "ONBUILD forbidden FROM", - dockerfile: "ONBUILD FROM scratch", - expectedError: "FROM isn't allowed as an ONBUILD trigger", - files: nil, - }, - { - name: "ONBUILD forbidden MAINTAINER", - dockerfile: "ONBUILD MAINTAINER docker.io", - expectedError: "MAINTAINER isn't allowed as an ONBUILD trigger", - files: nil, - }, - { - name: "ARG two arguments", - dockerfile: "ARG foo bar", - expectedError: "ARG requires exactly one argument", - files: nil, - }, - { - name: "MAINTAINER unknown flag", - dockerfile: "MAINTAINER --boo joe@example.com", - expectedError: "Unknown flag: boo", - files: nil, - }, - { - name: "ADD multiple files to file", - dockerfile: "ADD file1.txt file2.txt test", - expectedError: "When using ADD with more than one source file, the destination must be a directory and end with a /", - files: map[string]string{"file1.txt": "test1", "file2.txt": "test2"}, - }, - { - name: "JSON ADD multiple files to file", - dockerfile: `ADD ["file1.txt", "file2.txt", "test"]`, - expectedError: "When using ADD with more than one source file, the destination must be a directory and end with a /", - files: map[string]string{"file1.txt": "test1", "file2.txt": "test2"}, - }, - { - name: "Wildcard ADD multiple files to file", - dockerfile: "ADD file*.txt test", - expectedError: "When using ADD with more than one source file, the destination must be a directory and end with a /", - files: map[string]string{"file1.txt": "test1", "file2.txt": "test2"}, - }, - { - name: "Wildcard JSON ADD multiple files to file", - dockerfile: `ADD ["file*.txt", "test"]`, - expectedError: "When using ADD with more than one source file, the destination must be a directory and end with a /", - files: map[string]string{"file1.txt": "test1", "file2.txt": "test2"}, - }, - { - name: "COPY multiple files to file", - dockerfile: "COPY file1.txt file2.txt test", - expectedError: "When using COPY with more than one source file, the destination must be a directory and end with a /", - files: map[string]string{"file1.txt": "test1", "file2.txt": "test2"}, - }, - { - name: "JSON COPY multiple files to file", - dockerfile: `COPY ["file1.txt", "file2.txt", "test"]`, - expectedError: "When using COPY with more than one source file, the destination must be a directory and end with a /", - files: map[string]string{"file1.txt": "test1", "file2.txt": "test2"}, - }, - { - name: "ADD multiple files to file with whitespace", - dockerfile: `ADD [ "test file1.txt", "test file2.txt", "test" ]`, - expectedError: "When using ADD with more than one source file, the destination must be a directory and end with a /", - files: map[string]string{"test file1.txt": "test1", "test file2.txt": "test2"}, - }, - { - name: "COPY multiple files to file with whitespace", - dockerfile: `COPY [ "test file1.txt", "test file2.txt", "test" ]`, - expectedError: "When using COPY with more than one source file, the destination must be a directory and end with a /", - files: map[string]string{"test file1.txt": "test1", "test file2.txt": "test2"}, - }, - { - name: "COPY wildcard no files", - dockerfile: `COPY file*.txt /tmp/`, - expectedError: "No source files were specified", - files: nil, - }, - { - name: "COPY url", - dockerfile: `COPY https://index.docker.io/robots.txt /`, - expectedError: "Source can't be a URL for COPY", - files: nil, - }, - { - name: "Chaining ONBUILD", - dockerfile: `ONBUILD ONBUILD RUN touch foobar`, - expectedError: "Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed", - files: nil, - }, - { - name: "Invalid instruction", - dockerfile: `foo bar`, - expectedError: "Unknown instruction: FOO", - files: nil, - }} - - return dispatchTestCases -} - -func TestDispatch(t *testing.T) { - testCases := initDispatchTestCases() - - for _, testCase := range testCases { - executeTestCase(t, testCase) - } -} - -func executeTestCase(t *testing.T, testCase dispatchTestCase) { - contextDir, cleanup := createTestTempDir(t, "", "builder-dockerfile-test") - defer cleanup() - - for filename, content := range testCase.files { - createTestTempFile(t, contextDir, filename, content, 0777) - } - - tarStream, err := archive.Tar(contextDir, archive.Uncompressed) - - if err != nil { - t.Fatalf("Error when creating tar stream: %s", err) - } - - defer func() { - if err = tarStream.Close(); err != nil { - t.Fatalf("Error when closing tar stream: %s", err) - } - }() - - context, err := builder.MakeTarSumContext(tarStream) - - if err != nil { - t.Fatalf("Error when creating tar context: %s", err) - } - - defer func() { - if err = context.Close(); err != nil { - t.Fatalf("Error when closing tar context: %s", err) - } - }() - - r := strings.NewReader(testCase.dockerfile) - d := parser.Directive{} - parser.SetEscapeToken(parser.DefaultEscapeToken, &d) - n, err := parser.Parse(r, &d) - - if err != nil { - t.Fatalf("Error when parsing Dockerfile: %s", err) - } - - config := &container.Config{} - options := &types.ImageBuildOptions{} - - b := &Builder{runConfig: config, options: options, Stdout: ioutil.Discard, context: context} - - err = b.dispatch(0, len(n.Children), n.Children[0]) - - if err == nil { - t.Fatalf("No error when executing test %s", testCase.name) - } - - if !strings.Contains(err.Error(), testCase.expectedError) { - t.Fatalf("Wrong error message. Should be \"%s\". Got \"%s\"", testCase.expectedError, err.Error()) - } - -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/evaluator_unix.go b/vendor/github.com/docker/docker/builder/dockerfile/evaluator_unix.go deleted file mode 100644 index 28fd5b1..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/evaluator_unix.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build !windows - -package dockerfile - -// platformSupports is a short-term function to give users a quality error -// message if a Dockerfile uses a command not supported on the platform. -func platformSupports(command string) error { - return nil -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/evaluator_windows.go b/vendor/github.com/docker/docker/builder/dockerfile/evaluator_windows.go deleted file mode 100644 index 72483a2..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/evaluator_windows.go +++ /dev/null @@ -1,13 +0,0 @@ -package dockerfile - -import "fmt" - -// platformSupports is gives users a quality error message if a Dockerfile uses -// a command not supported on the platform. -func platformSupports(command string) error { - switch command { - case "stopsignal": - return fmt.Errorf("The daemon on this platform does not support the command '%s'", command) - } - return nil -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/internals.go b/vendor/github.com/docker/docker/builder/dockerfile/internals.go deleted file mode 100644 index 6f0a367..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/internals.go +++ /dev/null @@ -1,669 +0,0 @@ -package dockerfile - -// internals for handling commands. Covers many areas and a lot of -// non-contiguous functionality. Please read the comments. - -import ( - "crypto/sha256" - "encoding/hex" - "errors" - "fmt" - "io" - "io/ioutil" - "net/http" - "net/url" - "os" - "path/filepath" - "sort" - "strings" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/strslice" - "github.com/docker/docker/builder" - "github.com/docker/docker/builder/dockerfile/parser" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/httputils" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/streamformatter" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/system" - "github.com/docker/docker/pkg/tarsum" - "github.com/docker/docker/pkg/urlutil" - "github.com/docker/docker/runconfig/opts" -) - -func (b *Builder) commit(id string, autoCmd strslice.StrSlice, comment string) error { - if b.disableCommit { - return nil - } - if b.image == "" && !b.noBaseImage { - return fmt.Errorf("Please provide a source image with `from` prior to commit") - } - b.runConfig.Image = b.image - - if id == "" { - cmd := b.runConfig.Cmd - b.runConfig.Cmd = strslice.StrSlice(append(getShell(b.runConfig), "#(nop) ", comment)) - defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd) - - hit, err := b.probeCache() - if err != nil { - return err - } else if hit { - return nil - } - id, err = b.create() - if err != nil { - return err - } - } - - // Note: Actually copy the struct - autoConfig := *b.runConfig - autoConfig.Cmd = autoCmd - - commitCfg := &backend.ContainerCommitConfig{ - ContainerCommitConfig: types.ContainerCommitConfig{ - Author: b.maintainer, - Pause: true, - Config: &autoConfig, - }, - } - - // Commit the container - imageID, err := b.docker.Commit(id, commitCfg) - if err != nil { - return err - } - - b.image = imageID - return nil -} - -type copyInfo struct { - builder.FileInfo - decompress bool -} - -func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalDecompression bool, cmdName string) error { - if b.context == nil { - return fmt.Errorf("No context given. Impossible to use %s", cmdName) - } - - if len(args) < 2 { - return fmt.Errorf("Invalid %s format - at least two arguments required", cmdName) - } - - // Work in daemon-specific filepath semantics - dest := filepath.FromSlash(args[len(args)-1]) // last one is always the dest - - b.runConfig.Image = b.image - - var infos []copyInfo - - // Loop through each src file and calculate the info we need to - // do the copy (e.g. hash value if cached). Don't actually do - // the copy until we've looked at all src files - var err error - for _, orig := range args[0 : len(args)-1] { - var fi builder.FileInfo - decompress := allowLocalDecompression - if urlutil.IsURL(orig) { - if !allowRemote { - return fmt.Errorf("Source can't be a URL for %s", cmdName) - } - fi, err = b.download(orig) - if err != nil { - return err - } - defer os.RemoveAll(filepath.Dir(fi.Path())) - decompress = false - infos = append(infos, copyInfo{fi, decompress}) - continue - } - // not a URL - subInfos, err := b.calcCopyInfo(cmdName, orig, allowLocalDecompression, true) - if err != nil { - return err - } - - infos = append(infos, subInfos...) - } - - if len(infos) == 0 { - return fmt.Errorf("No source files were specified") - } - if len(infos) > 1 && !strings.HasSuffix(dest, string(os.PathSeparator)) { - return fmt.Errorf("When using %s with more than one source file, the destination must be a directory and end with a /", cmdName) - } - - // For backwards compat, if there's just one info then use it as the - // cache look-up string, otherwise hash 'em all into one - var srcHash string - var origPaths string - - if len(infos) == 1 { - fi := infos[0].FileInfo - origPaths = fi.Name() - if hfi, ok := fi.(builder.Hashed); ok { - srcHash = hfi.Hash() - } - } else { - var hashs []string - var origs []string - for _, info := range infos { - fi := info.FileInfo - origs = append(origs, fi.Name()) - if hfi, ok := fi.(builder.Hashed); ok { - hashs = append(hashs, hfi.Hash()) - } - } - hasher := sha256.New() - hasher.Write([]byte(strings.Join(hashs, ","))) - srcHash = "multi:" + hex.EncodeToString(hasher.Sum(nil)) - origPaths = strings.Join(origs, " ") - } - - cmd := b.runConfig.Cmd - b.runConfig.Cmd = strslice.StrSlice(append(getShell(b.runConfig), fmt.Sprintf("#(nop) %s %s in %s ", cmdName, srcHash, dest))) - defer func(cmd strslice.StrSlice) { b.runConfig.Cmd = cmd }(cmd) - - if hit, err := b.probeCache(); err != nil { - return err - } else if hit { - return nil - } - - container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig}) - if err != nil { - return err - } - b.tmpContainers[container.ID] = struct{}{} - - comment := fmt.Sprintf("%s %s in %s", cmdName, origPaths, dest) - - // Twiddle the destination when its a relative path - meaning, make it - // relative to the WORKINGDIR - if dest, err = normaliseDest(cmdName, b.runConfig.WorkingDir, dest); err != nil { - return err - } - - for _, info := range infos { - if err := b.docker.CopyOnBuild(container.ID, dest, info.FileInfo, info.decompress); err != nil { - return err - } - } - - return b.commit(container.ID, cmd, comment) -} - -func (b *Builder) download(srcURL string) (fi builder.FileInfo, err error) { - // get filename from URL - u, err := url.Parse(srcURL) - if err != nil { - return - } - path := filepath.FromSlash(u.Path) // Ensure in platform semantics - if strings.HasSuffix(path, string(os.PathSeparator)) { - path = path[:len(path)-1] - } - parts := strings.Split(path, string(os.PathSeparator)) - filename := parts[len(parts)-1] - if filename == "" { - err = fmt.Errorf("cannot determine filename from url: %s", u) - return - } - - // Initiate the download - resp, err := httputils.Download(srcURL) - if err != nil { - return - } - - // Prepare file in a tmp dir - tmpDir, err := ioutils.TempDir("", "docker-remote") - if err != nil { - return - } - defer func() { - if err != nil { - os.RemoveAll(tmpDir) - } - }() - tmpFileName := filepath.Join(tmpDir, filename) - tmpFile, err := os.OpenFile(tmpFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) - if err != nil { - return - } - - stdoutFormatter := b.Stdout.(*streamformatter.StdoutFormatter) - progressOutput := stdoutFormatter.StreamFormatter.NewProgressOutput(stdoutFormatter.Writer, true) - progressReader := progress.NewProgressReader(resp.Body, progressOutput, resp.ContentLength, "", "Downloading") - // Download and dump result to tmp file - if _, err = io.Copy(tmpFile, progressReader); err != nil { - tmpFile.Close() - return - } - fmt.Fprintln(b.Stdout) - // ignoring error because the file was already opened successfully - tmpFileSt, err := tmpFile.Stat() - if err != nil { - tmpFile.Close() - return - } - - // Set the mtime to the Last-Modified header value if present - // Otherwise just remove atime and mtime - mTime := time.Time{} - - lastMod := resp.Header.Get("Last-Modified") - if lastMod != "" { - // If we can't parse it then just let it default to 'zero' - // otherwise use the parsed time value - if parsedMTime, err := http.ParseTime(lastMod); err == nil { - mTime = parsedMTime - } - } - - tmpFile.Close() - - if err = system.Chtimes(tmpFileName, mTime, mTime); err != nil { - return - } - - // Calc the checksum, even if we're using the cache - r, err := archive.Tar(tmpFileName, archive.Uncompressed) - if err != nil { - return - } - tarSum, err := tarsum.NewTarSum(r, true, tarsum.Version1) - if err != nil { - return - } - if _, err = io.Copy(ioutil.Discard, tarSum); err != nil { - return - } - hash := tarSum.Sum(nil) - r.Close() - return &builder.HashedFileInfo{FileInfo: builder.PathFileInfo{FileInfo: tmpFileSt, FilePath: tmpFileName}, FileHash: hash}, nil -} - -func (b *Builder) calcCopyInfo(cmdName, origPath string, allowLocalDecompression, allowWildcards bool) ([]copyInfo, error) { - - // Work in daemon-specific OS filepath semantics - origPath = filepath.FromSlash(origPath) - - if origPath != "" && origPath[0] == os.PathSeparator && len(origPath) > 1 { - origPath = origPath[1:] - } - origPath = strings.TrimPrefix(origPath, "."+string(os.PathSeparator)) - - // Deal with wildcards - if allowWildcards && containsWildcards(origPath) { - var copyInfos []copyInfo - if err := b.context.Walk("", func(path string, info builder.FileInfo, err error) error { - if err != nil { - return err - } - if info.Name() == "" { - // Why are we doing this check? - return nil - } - if match, _ := filepath.Match(origPath, path); !match { - return nil - } - - // Note we set allowWildcards to false in case the name has - // a * in it - subInfos, err := b.calcCopyInfo(cmdName, path, allowLocalDecompression, false) - if err != nil { - return err - } - copyInfos = append(copyInfos, subInfos...) - return nil - }); err != nil { - return nil, err - } - return copyInfos, nil - } - - // Must be a dir or a file - - statPath, fi, err := b.context.Stat(origPath) - if err != nil { - return nil, err - } - - copyInfos := []copyInfo{{FileInfo: fi, decompress: allowLocalDecompression}} - - hfi, handleHash := fi.(builder.Hashed) - if !handleHash { - return copyInfos, nil - } - - // Deal with the single file case - if !fi.IsDir() { - hfi.SetHash("file:" + hfi.Hash()) - return copyInfos, nil - } - // Must be a dir - var subfiles []string - err = b.context.Walk(statPath, func(path string, info builder.FileInfo, err error) error { - if err != nil { - return err - } - // we already checked handleHash above - subfiles = append(subfiles, info.(builder.Hashed).Hash()) - return nil - }) - if err != nil { - return nil, err - } - - sort.Strings(subfiles) - hasher := sha256.New() - hasher.Write([]byte(strings.Join(subfiles, ","))) - hfi.SetHash("dir:" + hex.EncodeToString(hasher.Sum(nil))) - - return copyInfos, nil -} - -func (b *Builder) processImageFrom(img builder.Image) error { - if img != nil { - b.image = img.ImageID() - - if img.RunConfig() != nil { - b.runConfig = img.RunConfig() - } - } - - // Check to see if we have a default PATH, note that windows won't - // have one as its set by HCS - if system.DefaultPathEnv != "" { - // Convert the slice of strings that represent the current list - // of env vars into a map so we can see if PATH is already set. - // If its not set then go ahead and give it our default value - configEnv := opts.ConvertKVStringsToMap(b.runConfig.Env) - if _, ok := configEnv["PATH"]; !ok { - b.runConfig.Env = append(b.runConfig.Env, - "PATH="+system.DefaultPathEnv) - } - } - - if img == nil { - // Typically this means they used "FROM scratch" - return nil - } - - // Process ONBUILD triggers if they exist - if nTriggers := len(b.runConfig.OnBuild); nTriggers != 0 { - word := "trigger" - if nTriggers > 1 { - word = "triggers" - } - fmt.Fprintf(b.Stderr, "# Executing %d build %s...\n", nTriggers, word) - } - - // Copy the ONBUILD triggers, and remove them from the config, since the config will be committed. - onBuildTriggers := b.runConfig.OnBuild - b.runConfig.OnBuild = []string{} - - // parse the ONBUILD triggers by invoking the parser - for _, step := range onBuildTriggers { - ast, err := parser.Parse(strings.NewReader(step), &b.directive) - if err != nil { - return err - } - - total := len(ast.Children) - for _, n := range ast.Children { - if err := b.checkDispatch(n, true); err != nil { - return err - } - } - for i, n := range ast.Children { - if err := b.dispatch(i, total, n); err != nil { - return err - } - } - } - - return nil -} - -// probeCache checks if cache match can be found for current build instruction. -// If an image is found, probeCache returns `(true, nil)`. -// If no image is found, it returns `(false, nil)`. -// If there is any error, it returns `(false, err)`. -func (b *Builder) probeCache() (bool, error) { - c := b.imageCache - if c == nil || b.options.NoCache || b.cacheBusted { - return false, nil - } - cache, err := c.GetCache(b.image, b.runConfig) - if err != nil { - return false, err - } - if len(cache) == 0 { - logrus.Debugf("[BUILDER] Cache miss: %s", b.runConfig.Cmd) - b.cacheBusted = true - return false, nil - } - - fmt.Fprintf(b.Stdout, " ---> Using cache\n") - logrus.Debugf("[BUILDER] Use cached version: %s", b.runConfig.Cmd) - b.image = string(cache) - - return true, nil -} - -func (b *Builder) create() (string, error) { - if b.image == "" && !b.noBaseImage { - return "", fmt.Errorf("Please provide a source image with `from` prior to run") - } - b.runConfig.Image = b.image - - resources := container.Resources{ - CgroupParent: b.options.CgroupParent, - CPUShares: b.options.CPUShares, - CPUPeriod: b.options.CPUPeriod, - CPUQuota: b.options.CPUQuota, - CpusetCpus: b.options.CPUSetCPUs, - CpusetMems: b.options.CPUSetMems, - Memory: b.options.Memory, - MemorySwap: b.options.MemorySwap, - Ulimits: b.options.Ulimits, - } - - // TODO: why not embed a hostconfig in builder? - hostConfig := &container.HostConfig{ - SecurityOpt: b.options.SecurityOpt, - Isolation: b.options.Isolation, - ShmSize: b.options.ShmSize, - Resources: resources, - NetworkMode: container.NetworkMode(b.options.NetworkMode), - } - - config := *b.runConfig - - // Create the container - c, err := b.docker.ContainerCreate(types.ContainerCreateConfig{ - Config: b.runConfig, - HostConfig: hostConfig, - }) - if err != nil { - return "", err - } - for _, warning := range c.Warnings { - fmt.Fprintf(b.Stdout, " ---> [Warning] %s\n", warning) - } - - b.tmpContainers[c.ID] = struct{}{} - fmt.Fprintf(b.Stdout, " ---> Running in %s\n", stringid.TruncateID(c.ID)) - - // override the entry point that may have been picked up from the base image - if err := b.docker.ContainerUpdateCmdOnBuild(c.ID, config.Cmd); err != nil { - return "", err - } - - return c.ID, nil -} - -var errCancelled = errors.New("build cancelled") - -func (b *Builder) run(cID string) (err error) { - errCh := make(chan error) - go func() { - errCh <- b.docker.ContainerAttachRaw(cID, nil, b.Stdout, b.Stderr, true) - }() - - finished := make(chan struct{}) - cancelErrCh := make(chan error, 1) - go func() { - select { - case <-b.clientCtx.Done(): - logrus.Debugln("Build cancelled, killing and removing container:", cID) - b.docker.ContainerKill(cID, 0) - b.removeContainer(cID) - cancelErrCh <- errCancelled - case <-finished: - cancelErrCh <- nil - } - }() - - if err := b.docker.ContainerStart(cID, nil, "", ""); err != nil { - close(finished) - if cancelErr := <-cancelErrCh; cancelErr != nil { - logrus.Debugf("Build cancelled (%v) and got an error from ContainerStart: %v", - cancelErr, err) - } - return err - } - - // Block on reading output from container, stop on err or chan closed - if err := <-errCh; err != nil { - close(finished) - if cancelErr := <-cancelErrCh; cancelErr != nil { - logrus.Debugf("Build cancelled (%v) and got an error from errCh: %v", - cancelErr, err) - } - return err - } - - if ret, _ := b.docker.ContainerWait(cID, -1); ret != 0 { - close(finished) - if cancelErr := <-cancelErrCh; cancelErr != nil { - logrus.Debugf("Build cancelled (%v) and got a non-zero code from ContainerWait: %d", - cancelErr, ret) - } - // TODO: change error type, because jsonmessage.JSONError assumes HTTP - return &jsonmessage.JSONError{ - Message: fmt.Sprintf("The command '%s' returned a non-zero code: %d", strings.Join(b.runConfig.Cmd, " "), ret), - Code: ret, - } - } - close(finished) - return <-cancelErrCh -} - -func (b *Builder) removeContainer(c string) error { - rmConfig := &types.ContainerRmConfig{ - ForceRemove: true, - RemoveVolume: true, - } - if err := b.docker.ContainerRm(c, rmConfig); err != nil { - fmt.Fprintf(b.Stdout, "Error removing intermediate container %s: %v\n", stringid.TruncateID(c), err) - return err - } - return nil -} - -func (b *Builder) clearTmp() { - for c := range b.tmpContainers { - if err := b.removeContainer(c); err != nil { - return - } - delete(b.tmpContainers, c) - fmt.Fprintf(b.Stdout, "Removing intermediate container %s\n", stringid.TruncateID(c)) - } -} - -// readDockerfile reads a Dockerfile from the current context. -func (b *Builder) readDockerfile() error { - // If no -f was specified then look for 'Dockerfile'. If we can't find - // that then look for 'dockerfile'. If neither are found then default - // back to 'Dockerfile' and use that in the error message. - if b.options.Dockerfile == "" { - b.options.Dockerfile = builder.DefaultDockerfileName - if _, _, err := b.context.Stat(b.options.Dockerfile); os.IsNotExist(err) { - lowercase := strings.ToLower(b.options.Dockerfile) - if _, _, err := b.context.Stat(lowercase); err == nil { - b.options.Dockerfile = lowercase - } - } - } - - err := b.parseDockerfile() - - if err != nil { - return err - } - - // After the Dockerfile has been parsed, we need to check the .dockerignore - // file for either "Dockerfile" or ".dockerignore", and if either are - // present then erase them from the build context. These files should never - // have been sent from the client but we did send them to make sure that - // we had the Dockerfile to actually parse, and then we also need the - // .dockerignore file to know whether either file should be removed. - // Note that this assumes the Dockerfile has been read into memory and - // is now safe to be removed. - if dockerIgnore, ok := b.context.(builder.DockerIgnoreContext); ok { - dockerIgnore.Process([]string{b.options.Dockerfile}) - } - return nil -} - -func (b *Builder) parseDockerfile() error { - f, err := b.context.Open(b.options.Dockerfile) - if err != nil { - if os.IsNotExist(err) { - return fmt.Errorf("Cannot locate specified Dockerfile: %s", b.options.Dockerfile) - } - return err - } - defer f.Close() - if f, ok := f.(*os.File); ok { - // ignoring error because Open already succeeded - fi, err := f.Stat() - if err != nil { - return fmt.Errorf("Unexpected error reading Dockerfile: %v", err) - } - if fi.Size() == 0 { - return fmt.Errorf("The Dockerfile (%s) cannot be empty", b.options.Dockerfile) - } - } - b.dockerfile, err = parser.Parse(f, &b.directive) - if err != nil { - return err - } - - return nil -} - -// determine if build arg is part of built-in args or user -// defined args in Dockerfile at any point in time. -func (b *Builder) isBuildArgAllowed(arg string) bool { - if _, ok := BuiltinAllowedBuildArgs[arg]; ok { - return true - } - if _, ok := b.allowedBuildArgs[arg]; ok { - return true - } - return false -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/internals_test.go b/vendor/github.com/docker/docker/builder/dockerfile/internals_test.go deleted file mode 100644 index d170d8e..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/internals_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package dockerfile - -import ( - "fmt" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/builder" - "github.com/docker/docker/pkg/archive" -) - -func TestEmptyDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-dockerfile-test") - defer cleanup() - - createTestTempFile(t, contextDir, builder.DefaultDockerfileName, "", 0777) - - readAndCheckDockerfile(t, "emptyDockefile", contextDir, "", "The Dockerfile (Dockerfile) cannot be empty") -} - -func TestSymlinkDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-dockerfile-test") - defer cleanup() - - createTestSymlink(t, contextDir, builder.DefaultDockerfileName, "/etc/passwd") - - // The reason the error is "Cannot locate specified Dockerfile" is because - // in the builder, the symlink is resolved within the context, therefore - // Dockerfile -> /etc/passwd becomes etc/passwd from the context which is - // a nonexistent file. - expectedError := fmt.Sprintf("Cannot locate specified Dockerfile: %s", builder.DefaultDockerfileName) - - readAndCheckDockerfile(t, "symlinkDockerfile", contextDir, builder.DefaultDockerfileName, expectedError) -} - -func TestDockerfileOutsideTheBuildContext(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-dockerfile-test") - defer cleanup() - - expectedError := "Forbidden path outside the build context" - - readAndCheckDockerfile(t, "DockerfileOutsideTheBuildContext", contextDir, "../../Dockerfile", expectedError) -} - -func TestNonExistingDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-dockerfile-test") - defer cleanup() - - expectedError := "Cannot locate specified Dockerfile: Dockerfile" - - readAndCheckDockerfile(t, "NonExistingDockerfile", contextDir, "Dockerfile", expectedError) -} - -func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath, expectedError string) { - tarStream, err := archive.Tar(contextDir, archive.Uncompressed) - - if err != nil { - t.Fatalf("Error when creating tar stream: %s", err) - } - - defer func() { - if err = tarStream.Close(); err != nil { - t.Fatalf("Error when closing tar stream: %s", err) - } - }() - - context, err := builder.MakeTarSumContext(tarStream) - - if err != nil { - t.Fatalf("Error when creating tar context: %s", err) - } - - defer func() { - if err = context.Close(); err != nil { - t.Fatalf("Error when closing tar context: %s", err) - } - }() - - options := &types.ImageBuildOptions{ - Dockerfile: dockerfilePath, - } - - b := &Builder{options: options, context: context} - - err = b.readDockerfile() - - if err == nil { - t.Fatalf("No error when executing test: %s", testName) - } - - if !strings.Contains(err.Error(), expectedError) { - t.Fatalf("Wrong error message. Should be \"%s\". Got \"%s\"", expectedError, err.Error()) - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/internals_unix.go b/vendor/github.com/docker/docker/builder/dockerfile/internals_unix.go deleted file mode 100644 index a8a47c3..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/internals_unix.go +++ /dev/null @@ -1,38 +0,0 @@ -// +build !windows - -package dockerfile - -import ( - "os" - "path/filepath" - "strings" - - "github.com/docker/docker/pkg/system" -) - -// normaliseDest normalises the destination of a COPY/ADD command in a -// platform semantically consistent way. -func normaliseDest(cmdName, workingDir, requested string) (string, error) { - dest := filepath.FromSlash(requested) - endsInSlash := strings.HasSuffix(requested, string(os.PathSeparator)) - if !system.IsAbs(requested) { - dest = filepath.Join(string(os.PathSeparator), filepath.FromSlash(workingDir), dest) - // Make sure we preserve any trailing slash - if endsInSlash { - dest += string(os.PathSeparator) - } - } - return dest, nil -} - -func containsWildcards(name string) bool { - for i := 0; i < len(name); i++ { - ch := name[i] - if ch == '\\' { - i++ - } else if ch == '*' || ch == '?' || ch == '[' { - return true - } - } - return false -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/internals_windows.go b/vendor/github.com/docker/docker/builder/dockerfile/internals_windows.go deleted file mode 100644 index f60b112..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/internals_windows.go +++ /dev/null @@ -1,66 +0,0 @@ -package dockerfile - -import ( - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/docker/docker/pkg/system" -) - -// normaliseDest normalises the destination of a COPY/ADD command in a -// platform semantically consistent way. -func normaliseDest(cmdName, workingDir, requested string) (string, error) { - dest := filepath.FromSlash(requested) - endsInSlash := strings.HasSuffix(dest, string(os.PathSeparator)) - - // We are guaranteed that the working directory is already consistent, - // However, Windows also has, for now, the limitation that ADD/COPY can - // only be done to the system drive, not any drives that might be present - // as a result of a bind mount. - // - // So... if the path requested is Linux-style absolute (/foo or \\foo), - // we assume it is the system drive. If it is a Windows-style absolute - // (DRIVE:\\foo), error if DRIVE is not C. And finally, ensure we - // strip any configured working directories drive letter so that it - // can be subsequently legitimately converted to a Windows volume-style - // pathname. - - // Not a typo - filepath.IsAbs, not system.IsAbs on this next check as - // we only want to validate where the DriveColon part has been supplied. - if filepath.IsAbs(dest) { - if strings.ToUpper(string(dest[0])) != "C" { - return "", fmt.Errorf("Windows does not support %s with a destinations not on the system drive (C:)", cmdName) - } - dest = dest[2:] // Strip the drive letter - } - - // Cannot handle relative where WorkingDir is not the system drive. - if len(workingDir) > 0 { - if ((len(workingDir) > 1) && !system.IsAbs(workingDir[2:])) || (len(workingDir) == 1) { - return "", fmt.Errorf("Current WorkingDir %s is not platform consistent", workingDir) - } - if !system.IsAbs(dest) { - if string(workingDir[0]) != "C" { - return "", fmt.Errorf("Windows does not support %s with relative paths when WORKDIR is not the system drive", cmdName) - } - dest = filepath.Join(string(os.PathSeparator), workingDir[2:], dest) - // Make sure we preserve any trailing slash - if endsInSlash { - dest += string(os.PathSeparator) - } - } - } - return dest, nil -} - -func containsWildcards(name string) bool { - for i := 0; i < len(name); i++ { - ch := name[i] - if ch == '*' || ch == '?' || ch == '[' { - return true - } - } - return false -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/internals_windows_test.go b/vendor/github.com/docker/docker/builder/dockerfile/internals_windows_test.go deleted file mode 100644 index 868a667..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/internals_windows_test.go +++ /dev/null @@ -1,51 +0,0 @@ -// +build windows - -package dockerfile - -import "testing" - -func TestNormaliseDest(t *testing.T) { - tests := []struct{ current, requested, expected, etext string }{ - {``, `D:\`, ``, `Windows does not support TEST with a destinations not on the system drive (C:)`}, - {``, `e:/`, ``, `Windows does not support TEST with a destinations not on the system drive (C:)`}, - {`invalid`, `./c1`, ``, `Current WorkingDir invalid is not platform consistent`}, - {`C:`, ``, ``, `Current WorkingDir C: is not platform consistent`}, - {`C`, ``, ``, `Current WorkingDir C is not platform consistent`}, - {`D:\`, `.`, ``, "Windows does not support TEST with relative paths when WORKDIR is not the system drive"}, - {``, `D`, `D`, ``}, - {``, `./a1`, `.\a1`, ``}, - {``, `.\b1`, `.\b1`, ``}, - {``, `/`, `\`, ``}, - {``, `\`, `\`, ``}, - {``, `c:/`, `\`, ``}, - {``, `c:\`, `\`, ``}, - {``, `.`, `.`, ``}, - {`C:\wdd`, `./a1`, `\wdd\a1`, ``}, - {`C:\wde`, `.\b1`, `\wde\b1`, ``}, - {`C:\wdf`, `/`, `\`, ``}, - {`C:\wdg`, `\`, `\`, ``}, - {`C:\wdh`, `c:/`, `\`, ``}, - {`C:\wdi`, `c:\`, `\`, ``}, - {`C:\wdj`, `.`, `\wdj`, ``}, - {`C:\wdk`, `foo/bar`, `\wdk\foo\bar`, ``}, - {`C:\wdl`, `foo\bar`, `\wdl\foo\bar`, ``}, - {`C:\wdm`, `foo/bar/`, `\wdm\foo\bar\`, ``}, - {`C:\wdn`, `foo\bar/`, `\wdn\foo\bar\`, ``}, - } - for _, i := range tests { - got, err := normaliseDest("TEST", i.current, i.requested) - if err != nil && i.etext == "" { - t.Fatalf("TestNormaliseDest Got unexpected error %q for %s %s. ", err.Error(), i.current, i.requested) - } - if i.etext != "" && ((err == nil) || (err != nil && err.Error() != i.etext)) { - if err == nil { - t.Fatalf("TestNormaliseDest Expected an error for %s %s but didn't get one", i.current, i.requested) - } else { - t.Fatalf("TestNormaliseDest Wrong error text for %s %s - %s", i.current, i.requested, err.Error()) - } - } - if i.etext == "" && got != i.expected { - t.Fatalf("TestNormaliseDest Expected %q for %q and %q. Got %q", i.expected, i.current, i.requested, got) - } - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/dumper/main.go b/vendor/github.com/docker/docker/builder/dockerfile/parser/dumper/main.go deleted file mode 100644 index fff3046..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/dumper/main.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/docker/docker/builder/dockerfile/parser" -) - -func main() { - var f *os.File - var err error - - if len(os.Args) < 2 { - fmt.Println("please supply filename(s)") - os.Exit(1) - } - - for _, fn := range os.Args[1:] { - f, err = os.Open(fn) - if err != nil { - panic(err) - } - defer f.Close() - - d := parser.Directive{LookingForDirectives: true} - parser.SetEscapeToken(parser.DefaultEscapeToken, &d) - - ast, err := parser.Parse(f, &d) - if err != nil { - panic(err) - } else { - fmt.Println(ast.Dump()) - } - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/json_test.go b/vendor/github.com/docker/docker/builder/dockerfile/parser/json_test.go deleted file mode 100644 index 60d74d9..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/json_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package parser - -import ( - "testing" -) - -var invalidJSONArraysOfStrings = []string{ - `["a",42,"b"]`, - `["a",123.456,"b"]`, - `["a",{},"b"]`, - `["a",{"c": "d"},"b"]`, - `["a",["c"],"b"]`, - `["a",true,"b"]`, - `["a",false,"b"]`, - `["a",null,"b"]`, -} - -var validJSONArraysOfStrings = map[string][]string{ - `[]`: {}, - `[""]`: {""}, - `["a"]`: {"a"}, - `["a","b"]`: {"a", "b"}, - `[ "a", "b" ]`: {"a", "b"}, - `[ "a", "b" ]`: {"a", "b"}, - ` [ "a", "b" ] `: {"a", "b"}, - `["abc 123", "♥", "☃", "\" \\ \/ \b \f \n \r \t \u0000"]`: {"abc 123", "♥", "☃", "\" \\ / \b \f \n \r \t \u0000"}, -} - -func TestJSONArraysOfStrings(t *testing.T) { - for json, expected := range validJSONArraysOfStrings { - d := Directive{} - SetEscapeToken(DefaultEscapeToken, &d) - - if node, _, err := parseJSON(json, &d); err != nil { - t.Fatalf("%q should be a valid JSON array of strings, but wasn't! (err: %q)", json, err) - } else { - i := 0 - for node != nil { - if i >= len(expected) { - t.Fatalf("expected result is shorter than parsed result (%d vs %d+) in %q", len(expected), i+1, json) - } - if node.Value != expected[i] { - t.Fatalf("expected %q (not %q) in %q at pos %d", expected[i], node.Value, json, i) - } - node = node.Next - i++ - } - if i != len(expected) { - t.Fatalf("expected result is longer than parsed result (%d vs %d) in %q", len(expected), i+1, json) - } - } - } - for _, json := range invalidJSONArraysOfStrings { - d := Directive{} - SetEscapeToken(DefaultEscapeToken, &d) - - if _, _, err := parseJSON(json, &d); err != errDockerfileNotStringArray { - t.Fatalf("%q should be an invalid JSON array of strings, but wasn't!", json) - } - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/line_parsers.go b/vendor/github.com/docker/docker/builder/dockerfile/parser/line_parsers.go deleted file mode 100644 index d2bf2b0..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/line_parsers.go +++ /dev/null @@ -1,361 +0,0 @@ -package parser - -// line parsers are dispatch calls that parse a single unit of text into a -// Node object which contains the whole statement. Dockerfiles have varied -// (but not usually unique, see ONBUILD for a unique example) parsing rules -// per-command, and these unify the processing in a way that makes it -// manageable. - -import ( - "encoding/json" - "errors" - "fmt" - "strings" - "unicode" - "unicode/utf8" -) - -var ( - errDockerfileNotStringArray = errors.New("When using JSON array syntax, arrays must be comprised of strings only.") -) - -// ignore the current argument. This will still leave a command parsed, but -// will not incorporate the arguments into the ast. -func parseIgnore(rest string, d *Directive) (*Node, map[string]bool, error) { - return &Node{}, nil, nil -} - -// used for onbuild. Could potentially be used for anything that represents a -// statement with sub-statements. -// -// ONBUILD RUN foo bar -> (onbuild (run foo bar)) -// -func parseSubCommand(rest string, d *Directive) (*Node, map[string]bool, error) { - if rest == "" { - return nil, nil, nil - } - - _, child, err := ParseLine(rest, d, false) - if err != nil { - return nil, nil, err - } - - return &Node{Children: []*Node{child}}, nil, nil -} - -// helper to parse words (i.e space delimited or quoted strings) in a statement. -// The quotes are preserved as part of this function and they are stripped later -// as part of processWords(). -func parseWords(rest string, d *Directive) []string { - const ( - inSpaces = iota // looking for start of a word - inWord - inQuote - ) - - words := []string{} - phase := inSpaces - word := "" - quote := '\000' - blankOK := false - var ch rune - var chWidth int - - for pos := 0; pos <= len(rest); pos += chWidth { - if pos != len(rest) { - ch, chWidth = utf8.DecodeRuneInString(rest[pos:]) - } - - if phase == inSpaces { // Looking for start of word - if pos == len(rest) { // end of input - break - } - if unicode.IsSpace(ch) { // skip spaces - continue - } - phase = inWord // found it, fall through - } - if (phase == inWord || phase == inQuote) && (pos == len(rest)) { - if blankOK || len(word) > 0 { - words = append(words, word) - } - break - } - if phase == inWord { - if unicode.IsSpace(ch) { - phase = inSpaces - if blankOK || len(word) > 0 { - words = append(words, word) - } - word = "" - blankOK = false - continue - } - if ch == '\'' || ch == '"' { - quote = ch - blankOK = true - phase = inQuote - } - if ch == d.EscapeToken { - if pos+chWidth == len(rest) { - continue // just skip an escape token at end of line - } - // If we're not quoted and we see an escape token, then always just - // add the escape token plus the char to the word, even if the char - // is a quote. - word += string(ch) - pos += chWidth - ch, chWidth = utf8.DecodeRuneInString(rest[pos:]) - } - word += string(ch) - continue - } - if phase == inQuote { - if ch == quote { - phase = inWord - } - // The escape token is special except for ' quotes - can't escape anything for ' - if ch == d.EscapeToken && quote != '\'' { - if pos+chWidth == len(rest) { - phase = inWord - continue // just skip the escape token at end - } - pos += chWidth - word += string(ch) - ch, chWidth = utf8.DecodeRuneInString(rest[pos:]) - } - word += string(ch) - } - } - - return words -} - -// parse environment like statements. Note that this does *not* handle -// variable interpolation, which will be handled in the evaluator. -func parseNameVal(rest string, key string, d *Directive) (*Node, map[string]bool, error) { - // This is kind of tricky because we need to support the old - // variant: KEY name value - // as well as the new one: KEY name=value ... - // The trigger to know which one is being used will be whether we hit - // a space or = first. space ==> old, "=" ==> new - - words := parseWords(rest, d) - if len(words) == 0 { - return nil, nil, nil - } - - var rootnode *Node - - // Old format (KEY name value) - if !strings.Contains(words[0], "=") { - node := &Node{} - rootnode = node - strs := tokenWhitespace.Split(rest, 2) - - if len(strs) < 2 { - return nil, nil, fmt.Errorf(key + " must have two arguments") - } - - node.Value = strs[0] - node.Next = &Node{} - node.Next.Value = strs[1] - } else { - var prevNode *Node - for i, word := range words { - if !strings.Contains(word, "=") { - return nil, nil, fmt.Errorf("Syntax error - can't find = in %q. Must be of the form: name=value", word) - } - parts := strings.SplitN(word, "=", 2) - - name := &Node{} - value := &Node{} - - name.Next = value - name.Value = parts[0] - value.Value = parts[1] - - if i == 0 { - rootnode = name - } else { - prevNode.Next = name - } - prevNode = value - } - } - - return rootnode, nil, nil -} - -func parseEnv(rest string, d *Directive) (*Node, map[string]bool, error) { - return parseNameVal(rest, "ENV", d) -} - -func parseLabel(rest string, d *Directive) (*Node, map[string]bool, error) { - return parseNameVal(rest, "LABEL", d) -} - -// parses a statement containing one or more keyword definition(s) and/or -// value assignments, like `name1 name2= name3="" name4=value`. -// Note that this is a stricter format than the old format of assignment, -// allowed by parseNameVal(), in a way that this only allows assignment of the -// form `keyword=[]` like `name2=`, `name3=""`, and `name4=value` above. -// In addition, a keyword definition alone is of the form `keyword` like `name1` -// above. And the assignments `name2=` and `name3=""` are equivalent and -// assign an empty value to the respective keywords. -func parseNameOrNameVal(rest string, d *Directive) (*Node, map[string]bool, error) { - words := parseWords(rest, d) - if len(words) == 0 { - return nil, nil, nil - } - - var ( - rootnode *Node - prevNode *Node - ) - for i, word := range words { - node := &Node{} - node.Value = word - if i == 0 { - rootnode = node - } else { - prevNode.Next = node - } - prevNode = node - } - - return rootnode, nil, nil -} - -// parses a whitespace-delimited set of arguments. The result is effectively a -// linked list of string arguments. -func parseStringsWhitespaceDelimited(rest string, d *Directive) (*Node, map[string]bool, error) { - if rest == "" { - return nil, nil, nil - } - - node := &Node{} - rootnode := node - prevnode := node - for _, str := range tokenWhitespace.Split(rest, -1) { // use regexp - prevnode = node - node.Value = str - node.Next = &Node{} - node = node.Next - } - - // XXX to get around regexp.Split *always* providing an empty string at the - // end due to how our loop is constructed, nil out the last node in the - // chain. - prevnode.Next = nil - - return rootnode, nil, nil -} - -// parsestring just wraps the string in quotes and returns a working node. -func parseString(rest string, d *Directive) (*Node, map[string]bool, error) { - if rest == "" { - return nil, nil, nil - } - n := &Node{} - n.Value = rest - return n, nil, nil -} - -// parseJSON converts JSON arrays to an AST. -func parseJSON(rest string, d *Directive) (*Node, map[string]bool, error) { - rest = strings.TrimLeftFunc(rest, unicode.IsSpace) - if !strings.HasPrefix(rest, "[") { - return nil, nil, fmt.Errorf(`Error parsing "%s" as a JSON array`, rest) - } - - var myJSON []interface{} - if err := json.NewDecoder(strings.NewReader(rest)).Decode(&myJSON); err != nil { - return nil, nil, err - } - - var top, prev *Node - for _, str := range myJSON { - s, ok := str.(string) - if !ok { - return nil, nil, errDockerfileNotStringArray - } - - node := &Node{Value: s} - if prev == nil { - top = node - } else { - prev.Next = node - } - prev = node - } - - return top, map[string]bool{"json": true}, nil -} - -// parseMaybeJSON determines if the argument appears to be a JSON array. If -// so, passes to parseJSON; if not, quotes the result and returns a single -// node. -func parseMaybeJSON(rest string, d *Directive) (*Node, map[string]bool, error) { - if rest == "" { - return nil, nil, nil - } - - node, attrs, err := parseJSON(rest, d) - - if err == nil { - return node, attrs, nil - } - if err == errDockerfileNotStringArray { - return nil, nil, err - } - - node = &Node{} - node.Value = rest - return node, nil, nil -} - -// parseMaybeJSONToList determines if the argument appears to be a JSON array. If -// so, passes to parseJSON; if not, attempts to parse it as a whitespace -// delimited string. -func parseMaybeJSONToList(rest string, d *Directive) (*Node, map[string]bool, error) { - node, attrs, err := parseJSON(rest, d) - - if err == nil { - return node, attrs, nil - } - if err == errDockerfileNotStringArray { - return nil, nil, err - } - - return parseStringsWhitespaceDelimited(rest, d) -} - -// The HEALTHCHECK command is like parseMaybeJSON, but has an extra type argument. -func parseHealthConfig(rest string, d *Directive) (*Node, map[string]bool, error) { - // Find end of first argument - var sep int - for ; sep < len(rest); sep++ { - if unicode.IsSpace(rune(rest[sep])) { - break - } - } - next := sep - for ; next < len(rest); next++ { - if !unicode.IsSpace(rune(rest[next])) { - break - } - } - - if sep == 0 { - return nil, nil, nil - } - - typ := rest[:sep] - cmd, attrs, err := parseMaybeJSON(rest[next:], d) - if err != nil { - return nil, nil, err - } - - return &Node{Value: typ, Next: cmd}, attrs, err -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/parser.go b/vendor/github.com/docker/docker/builder/dockerfile/parser/parser.go deleted file mode 100644 index e534644..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/parser.go +++ /dev/null @@ -1,221 +0,0 @@ -// Package parser implements a parser and parse tree dumper for Dockerfiles. -package parser - -import ( - "bufio" - "bytes" - "fmt" - "io" - "regexp" - "strings" - "unicode" - - "github.com/docker/docker/builder/dockerfile/command" -) - -// Node is a structure used to represent a parse tree. -// -// In the node there are three fields, Value, Next, and Children. Value is the -// current token's string value. Next is always the next non-child token, and -// children contains all the children. Here's an example: -// -// (value next (child child-next child-next-next) next-next) -// -// This data structure is frankly pretty lousy for handling complex languages, -// but lucky for us the Dockerfile isn't very complicated. This structure -// works a little more effectively than a "proper" parse tree for our needs. -// -type Node struct { - Value string // actual content - Next *Node // the next item in the current sexp - Children []*Node // the children of this sexp - Attributes map[string]bool // special attributes for this node - Original string // original line used before parsing - Flags []string // only top Node should have this set - StartLine int // the line in the original dockerfile where the node begins - EndLine int // the line in the original dockerfile where the node ends -} - -// Directive is the structure used during a build run to hold the state of -// parsing directives. -type Directive struct { - EscapeToken rune // Current escape token - LineContinuationRegex *regexp.Regexp // Current line contination regex - LookingForDirectives bool // Whether we are currently looking for directives - EscapeSeen bool // Whether the escape directive has been seen -} - -var ( - dispatch map[string]func(string, *Directive) (*Node, map[string]bool, error) - tokenWhitespace = regexp.MustCompile(`[\t\v\f\r ]+`) - tokenEscapeCommand = regexp.MustCompile(`^#[ \t]*escape[ \t]*=[ \t]*(?P.).*$`) - tokenComment = regexp.MustCompile(`^#.*$`) -) - -// DefaultEscapeToken is the default escape token -const DefaultEscapeToken = "\\" - -// SetEscapeToken sets the default token for escaping characters in a Dockerfile. -func SetEscapeToken(s string, d *Directive) error { - if s != "`" && s != "\\" { - return fmt.Errorf("invalid ESCAPE '%s'. Must be ` or \\", s) - } - d.EscapeToken = rune(s[0]) - d.LineContinuationRegex = regexp.MustCompile(`\` + s + `[ \t]*$`) - return nil -} - -func init() { - // Dispatch Table. see line_parsers.go for the parse functions. - // The command is parsed and mapped to the line parser. The line parser - // receives the arguments but not the command, and returns an AST after - // reformulating the arguments according to the rules in the parser - // functions. Errors are propagated up by Parse() and the resulting AST can - // be incorporated directly into the existing AST as a next. - dispatch = map[string]func(string, *Directive) (*Node, map[string]bool, error){ - command.Add: parseMaybeJSONToList, - command.Arg: parseNameOrNameVal, - command.Cmd: parseMaybeJSON, - command.Copy: parseMaybeJSONToList, - command.Entrypoint: parseMaybeJSON, - command.Env: parseEnv, - command.Expose: parseStringsWhitespaceDelimited, - command.From: parseString, - command.Healthcheck: parseHealthConfig, - command.Label: parseLabel, - command.Maintainer: parseString, - command.Onbuild: parseSubCommand, - command.Run: parseMaybeJSON, - command.Shell: parseMaybeJSON, - command.StopSignal: parseString, - command.User: parseString, - command.Volume: parseMaybeJSONToList, - command.Workdir: parseString, - } -} - -// ParseLine parses a line and returns the remainder. -func ParseLine(line string, d *Directive, ignoreCont bool) (string, *Node, error) { - // Handle the parser directive '# escape=. Parser directives must precede - // any builder instruction or other comments, and cannot be repeated. - if d.LookingForDirectives { - tecMatch := tokenEscapeCommand.FindStringSubmatch(strings.ToLower(line)) - if len(tecMatch) > 0 { - if d.EscapeSeen == true { - return "", nil, fmt.Errorf("only one escape parser directive can be used") - } - for i, n := range tokenEscapeCommand.SubexpNames() { - if n == "escapechar" { - if err := SetEscapeToken(tecMatch[i], d); err != nil { - return "", nil, err - } - d.EscapeSeen = true - return "", nil, nil - } - } - } - } - - d.LookingForDirectives = false - - if line = stripComments(line); line == "" { - return "", nil, nil - } - - if !ignoreCont && d.LineContinuationRegex.MatchString(line) { - line = d.LineContinuationRegex.ReplaceAllString(line, "") - return line, nil, nil - } - - cmd, flags, args, err := splitCommand(line) - if err != nil { - return "", nil, err - } - - node := &Node{} - node.Value = cmd - - sexp, attrs, err := fullDispatch(cmd, args, d) - if err != nil { - return "", nil, err - } - - node.Next = sexp - node.Attributes = attrs - node.Original = line - node.Flags = flags - - return "", node, nil -} - -// Parse is the main parse routine. -// It handles an io.ReadWriteCloser and returns the root of the AST. -func Parse(rwc io.Reader, d *Directive) (*Node, error) { - currentLine := 0 - root := &Node{} - root.StartLine = -1 - scanner := bufio.NewScanner(rwc) - - utf8bom := []byte{0xEF, 0xBB, 0xBF} - for scanner.Scan() { - scannedBytes := scanner.Bytes() - // We trim UTF8 BOM - if currentLine == 0 { - scannedBytes = bytes.TrimPrefix(scannedBytes, utf8bom) - } - scannedLine := strings.TrimLeftFunc(string(scannedBytes), unicode.IsSpace) - currentLine++ - line, child, err := ParseLine(scannedLine, d, false) - if err != nil { - return nil, err - } - startLine := currentLine - - if line != "" && child == nil { - for scanner.Scan() { - newline := scanner.Text() - currentLine++ - - if stripComments(strings.TrimSpace(newline)) == "" { - continue - } - - line, child, err = ParseLine(line+newline, d, false) - if err != nil { - return nil, err - } - - if child != nil { - break - } - } - if child == nil && line != "" { - // When we call ParseLine we'll pass in 'true' for - // the ignoreCont param if we're at the EOF. This will - // prevent the func from returning immediately w/o - // parsing the line thinking that there's more input - // to come. - - _, child, err = ParseLine(line, d, scanner.Err() == nil) - if err != nil { - return nil, err - } - } - } - - if child != nil { - // Update the line information for the current child. - child.StartLine = startLine - child.EndLine = currentLine - // Update the line information for the root. The starting line of the root is always the - // starting line of the first child and the ending line is the ending line of the last child. - if root.StartLine < 0 { - root.StartLine = currentLine - } - root.EndLine = currentLine - root.Children = append(root.Children, child) - } - } - - return root, nil -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/parser_test.go b/vendor/github.com/docker/docker/builder/dockerfile/parser/parser_test.go deleted file mode 100644 index e8e2696..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/parser_test.go +++ /dev/null @@ -1,173 +0,0 @@ -package parser - -import ( - "bytes" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "runtime" - "testing" -) - -const testDir = "testfiles" -const negativeTestDir = "testfiles-negative" -const testFileLineInfo = "testfile-line/Dockerfile" - -func getDirs(t *testing.T, dir string) []string { - f, err := os.Open(dir) - if err != nil { - t.Fatal(err) - } - - defer f.Close() - - dirs, err := f.Readdirnames(0) - if err != nil { - t.Fatal(err) - } - - return dirs -} - -func TestTestNegative(t *testing.T) { - for _, dir := range getDirs(t, negativeTestDir) { - dockerfile := filepath.Join(negativeTestDir, dir, "Dockerfile") - - df, err := os.Open(dockerfile) - if err != nil { - t.Fatalf("Dockerfile missing for %s: %v", dir, err) - } - defer df.Close() - - d := Directive{LookingForDirectives: true} - SetEscapeToken(DefaultEscapeToken, &d) - _, err = Parse(df, &d) - if err == nil { - t.Fatalf("No error parsing broken dockerfile for %s", dir) - } - } -} - -func TestTestData(t *testing.T) { - for _, dir := range getDirs(t, testDir) { - dockerfile := filepath.Join(testDir, dir, "Dockerfile") - resultfile := filepath.Join(testDir, dir, "result") - - df, err := os.Open(dockerfile) - if err != nil { - t.Fatalf("Dockerfile missing for %s: %v", dir, err) - } - defer df.Close() - - d := Directive{LookingForDirectives: true} - SetEscapeToken(DefaultEscapeToken, &d) - ast, err := Parse(df, &d) - if err != nil { - t.Fatalf("Error parsing %s's dockerfile: %v", dir, err) - } - - content, err := ioutil.ReadFile(resultfile) - if err != nil { - t.Fatalf("Error reading %s's result file: %v", dir, err) - } - - if runtime.GOOS == "windows" { - // CRLF --> CR to match Unix behavior - content = bytes.Replace(content, []byte{'\x0d', '\x0a'}, []byte{'\x0a'}, -1) - } - - if ast.Dump()+"\n" != string(content) { - fmt.Fprintln(os.Stderr, "Result:\n"+ast.Dump()) - fmt.Fprintln(os.Stderr, "Expected:\n"+string(content)) - t.Fatalf("%s: AST dump of dockerfile does not match result", dir) - } - } -} - -func TestParseWords(t *testing.T) { - tests := []map[string][]string{ - { - "input": {"foo"}, - "expect": {"foo"}, - }, - { - "input": {"foo bar"}, - "expect": {"foo", "bar"}, - }, - { - "input": {"foo\\ bar"}, - "expect": {"foo\\ bar"}, - }, - { - "input": {"foo=bar"}, - "expect": {"foo=bar"}, - }, - { - "input": {"foo bar 'abc xyz'"}, - "expect": {"foo", "bar", "'abc xyz'"}, - }, - { - "input": {`foo bar "abc xyz"`}, - "expect": {"foo", "bar", `"abc xyz"`}, - }, - { - "input": {"àöû"}, - "expect": {"àöû"}, - }, - { - "input": {`föo bàr "âbc xÿz"`}, - "expect": {"föo", "bàr", `"âbc xÿz"`}, - }, - } - - for _, test := range tests { - d := Directive{LookingForDirectives: true} - SetEscapeToken(DefaultEscapeToken, &d) - words := parseWords(test["input"][0], &d) - if len(words) != len(test["expect"]) { - t.Fatalf("length check failed. input: %v, expect: %q, output: %q", test["input"][0], test["expect"], words) - } - for i, word := range words { - if word != test["expect"][i] { - t.Fatalf("word check failed for word: %q. input: %q, expect: %q, output: %q", word, test["input"][0], test["expect"], words) - } - } - } -} - -func TestLineInformation(t *testing.T) { - df, err := os.Open(testFileLineInfo) - if err != nil { - t.Fatalf("Dockerfile missing for %s: %v", testFileLineInfo, err) - } - defer df.Close() - - d := Directive{LookingForDirectives: true} - SetEscapeToken(DefaultEscapeToken, &d) - ast, err := Parse(df, &d) - if err != nil { - t.Fatalf("Error parsing dockerfile %s: %v", testFileLineInfo, err) - } - - if ast.StartLine != 5 || ast.EndLine != 31 { - fmt.Fprintf(os.Stderr, "Wrong root line information: expected(%d-%d), actual(%d-%d)\n", 5, 31, ast.StartLine, ast.EndLine) - t.Fatalf("Root line information doesn't match result.") - } - if len(ast.Children) != 3 { - fmt.Fprintf(os.Stderr, "Wrong number of child: expected(%d), actual(%d)\n", 3, len(ast.Children)) - t.Fatalf("Root line information doesn't match result for %s", testFileLineInfo) - } - expected := [][]int{ - {5, 5}, - {11, 12}, - {17, 31}, - } - for i, child := range ast.Children { - if child.StartLine != expected[i][0] || child.EndLine != expected[i][1] { - t.Logf("Wrong line information for child %d: expected(%d-%d), actual(%d-%d)\n", - i, expected[i][0], expected[i][1], child.StartLine, child.EndLine) - t.Fatalf("Root line information doesn't match result.") - } - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfile-line/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfile-line/Dockerfile deleted file mode 100644 index c7601c9..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfile-line/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -# ESCAPE=\ - - - -FROM brimstone/ubuntu:14.04 - - -# TORUN -v /var/run/docker.sock:/var/run/docker.sock - - -ENV GOPATH \ -/go - - - -# Install the packages we need, clean up after them and us -RUN apt-get update \ - && dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.clean \ - - - && apt-get install -y --no-install-recommends git golang ca-certificates \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists \ - - && go get -v github.com/brimstone/consuldock \ - && mv $GOPATH/bin/consuldock /usr/local/bin/consuldock \ - - && dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \ - && apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \ - && rm /tmp/dpkg.* \ - && rm -rf $GOPATH - - - - diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles-negative/env_no_value/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles-negative/env_no_value/Dockerfile deleted file mode 100644 index 1d65578..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles-negative/env_no_value/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM busybox - -ENV PATH diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles-negative/shykes-nested-json/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles-negative/shykes-nested-json/Dockerfile deleted file mode 100644 index d1be459..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles-negative/shykes-nested-json/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -CMD [ "echo", [ "nested json" ] ] diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/ADD-COPY-with-JSON/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/ADD-COPY-with-JSON/Dockerfile deleted file mode 100644 index 00b444c..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/ADD-COPY-with-JSON/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM ubuntu:14.04 -MAINTAINER Seongyeol Lim - -COPY . /go/src/github.com/docker/docker -ADD . / -ADD null / -COPY nullfile /tmp -ADD [ "vimrc", "/tmp" ] -COPY [ "bashrc", "/tmp" ] -COPY [ "test file", "/tmp" ] -ADD [ "test file", "/tmp/test file" ] diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/ADD-COPY-with-JSON/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/ADD-COPY-with-JSON/result deleted file mode 100644 index 85aee64..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/ADD-COPY-with-JSON/result +++ /dev/null @@ -1,10 +0,0 @@ -(from "ubuntu:14.04") -(maintainer "Seongyeol Lim ") -(copy "." "/go/src/github.com/docker/docker") -(add "." "/") -(add "null" "/") -(copy "nullfile" "/tmp") -(add "vimrc" "/tmp") -(copy "bashrc" "/tmp") -(copy "test file" "/tmp") -(add "test file" "/tmp/test file") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-consuldock/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-consuldock/Dockerfile deleted file mode 100644 index 0364ef9..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-consuldock/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -#escape=\ -FROM brimstone/ubuntu:14.04 - -MAINTAINER brimstone@the.narro.ws - -# TORUN -v /var/run/docker.sock:/var/run/docker.sock - -ENV GOPATH /go - -# Set our command -ENTRYPOINT ["/usr/local/bin/consuldock"] - -# Install the packages we need, clean up after them and us -RUN apt-get update \ - && dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.clean \ - && apt-get install -y --no-install-recommends git golang ca-certificates \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists \ - - && go get -v github.com/brimstone/consuldock \ - && mv $GOPATH/bin/consuldock /usr/local/bin/consuldock \ - - && dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \ - && apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \ - && rm /tmp/dpkg.* \ - && rm -rf $GOPATH diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-consuldock/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-consuldock/result deleted file mode 100644 index 227f748..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-consuldock/result +++ /dev/null @@ -1,5 +0,0 @@ -(from "brimstone/ubuntu:14.04") -(maintainer "brimstone@the.narro.ws") -(env "GOPATH" "/go") -(entrypoint "/usr/local/bin/consuldock") -(run "apt-get update \t&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.clean && apt-get install -y --no-install-recommends git golang ca-certificates && apt-get clean && rm -rf /var/lib/apt/lists \t&& go get -v github.com/brimstone/consuldock && mv $GOPATH/bin/consuldock /usr/local/bin/consuldock \t&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \t&& apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \t&& rm /tmp/dpkg.* \t&& rm -rf $GOPATH") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-docker-consul/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-docker-consul/Dockerfile deleted file mode 100644 index 25ae352..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-docker-consul/Dockerfile +++ /dev/null @@ -1,52 +0,0 @@ -FROM brimstone/ubuntu:14.04 - -CMD [] - -ENTRYPOINT ["/usr/bin/consul", "agent", "-server", "-data-dir=/consul", "-client=0.0.0.0", "-ui-dir=/webui"] - -EXPOSE 8500 8600 8400 8301 8302 - -RUN apt-get update \ - && apt-get install -y unzip wget \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists - -RUN cd /tmp \ - && wget https://dl.bintray.com/mitchellh/consul/0.3.1_web_ui.zip \ - -O web_ui.zip \ - && unzip web_ui.zip \ - && mv dist /webui \ - && rm web_ui.zip - -RUN apt-get update \ - && dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.clean \ - && apt-get install -y --no-install-recommends unzip wget \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists \ - - && cd /tmp \ - && wget https://dl.bintray.com/mitchellh/consul/0.3.1_web_ui.zip \ - -O web_ui.zip \ - && unzip web_ui.zip \ - && mv dist /webui \ - && rm web_ui.zip \ - - && dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \ - && apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \ - && rm /tmp/dpkg.* - -ENV GOPATH /go - -RUN apt-get update \ - && dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.clean \ - && apt-get install -y --no-install-recommends git golang ca-certificates build-essential \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists \ - - && go get -v github.com/hashicorp/consul \ - && mv $GOPATH/bin/consul /usr/bin/consul \ - - && dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \ - && apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \ - && rm /tmp/dpkg.* \ - && rm -rf $GOPATH diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-docker-consul/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-docker-consul/result deleted file mode 100644 index 16492e5..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/brimstone-docker-consul/result +++ /dev/null @@ -1,9 +0,0 @@ -(from "brimstone/ubuntu:14.04") -(cmd) -(entrypoint "/usr/bin/consul" "agent" "-server" "-data-dir=/consul" "-client=0.0.0.0" "-ui-dir=/webui") -(expose "8500" "8600" "8400" "8301" "8302") -(run "apt-get update && apt-get install -y unzip wget \t&& apt-get clean \t&& rm -rf /var/lib/apt/lists") -(run "cd /tmp && wget https://dl.bintray.com/mitchellh/consul/0.3.1_web_ui.zip -O web_ui.zip && unzip web_ui.zip && mv dist /webui && rm web_ui.zip") -(run "apt-get update \t&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.clean && apt-get install -y --no-install-recommends unzip wget && apt-get clean && rm -rf /var/lib/apt/lists && cd /tmp && wget https://dl.bintray.com/mitchellh/consul/0.3.1_web_ui.zip -O web_ui.zip && unzip web_ui.zip && mv dist /webui && rm web_ui.zip \t&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \t&& apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \t&& rm /tmp/dpkg.*") -(env "GOPATH" "/go") -(run "apt-get update \t&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.clean && apt-get install -y --no-install-recommends git golang ca-certificates build-essential && apt-get clean && rm -rf /var/lib/apt/lists \t&& go get -v github.com/hashicorp/consul \t&& mv $GOPATH/bin/consul /usr/bin/consul \t&& dpkg -l | awk '/^ii/ {print $2}' > /tmp/dpkg.dirty \t&& apt-get remove --purge -y $(diff /tmp/dpkg.clean /tmp/dpkg.dirty | awk '/^>/ {print $2}') \t&& rm /tmp/dpkg.* \t&& rm -rf $GOPATH") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/continueIndent/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/continueIndent/Dockerfile deleted file mode 100644 index 42b324e..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/continueIndent/Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -FROM ubuntu:14.04 - -RUN echo hello\ - world\ - goodnight \ - moon\ - light\ -ning -RUN echo hello \ - world -RUN echo hello \ -world -RUN echo hello \ -goodbye\ -frog -RUN echo hello \ -world -RUN echo hi \ - \ - world \ -\ - good\ -\ -night -RUN echo goodbye\ -frog -RUN echo good\ -bye\ -frog - -RUN echo hello \ -# this is a comment - -# this is a comment with a blank line surrounding it - -this is some more useful stuff diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/continueIndent/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/continueIndent/result deleted file mode 100644 index 268ae07..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/continueIndent/result +++ /dev/null @@ -1,10 +0,0 @@ -(from "ubuntu:14.04") -(run "echo hello world goodnight moon lightning") -(run "echo hello world") -(run "echo hello world") -(run "echo hello goodbyefrog") -(run "echo hello world") -(run "echo hi world goodnight") -(run "echo goodbyefrog") -(run "echo goodbyefrog") -(run "echo hello this is some more useful stuff") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/cpuguy83-nagios/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/cpuguy83-nagios/Dockerfile deleted file mode 100644 index 8ccb71a..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/cpuguy83-nagios/Dockerfile +++ /dev/null @@ -1,54 +0,0 @@ -FROM cpuguy83/ubuntu -ENV NAGIOS_HOME /opt/nagios -ENV NAGIOS_USER nagios -ENV NAGIOS_GROUP nagios -ENV NAGIOS_CMDUSER nagios -ENV NAGIOS_CMDGROUP nagios -ENV NAGIOSADMIN_USER nagiosadmin -ENV NAGIOSADMIN_PASS nagios -ENV APACHE_RUN_USER nagios -ENV APACHE_RUN_GROUP nagios -ENV NAGIOS_TIMEZONE UTC - -RUN sed -i 's/universe/universe multiverse/' /etc/apt/sources.list -RUN apt-get update && apt-get install -y iputils-ping netcat build-essential snmp snmpd snmp-mibs-downloader php5-cli apache2 libapache2-mod-php5 runit bc postfix bsd-mailx -RUN ( egrep -i "^${NAGIOS_GROUP}" /etc/group || groupadd $NAGIOS_GROUP ) && ( egrep -i "^${NAGIOS_CMDGROUP}" /etc/group || groupadd $NAGIOS_CMDGROUP ) -RUN ( id -u $NAGIOS_USER || useradd --system $NAGIOS_USER -g $NAGIOS_GROUP -d $NAGIOS_HOME ) && ( id -u $NAGIOS_CMDUSER || useradd --system -d $NAGIOS_HOME -g $NAGIOS_CMDGROUP $NAGIOS_CMDUSER ) - -ADD http://downloads.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz?r=http%3A%2F%2Fwww.nagios.org%2Fdownload%2Fcore%2Fthanks%2F%3Ft%3D1398863696&ts=1398863718&use_mirror=superb-dca3 /tmp/nagios.tar.gz -RUN cd /tmp && tar -zxvf nagios.tar.gz && cd nagios && ./configure --prefix=${NAGIOS_HOME} --exec-prefix=${NAGIOS_HOME} --enable-event-broker --with-nagios-command-user=${NAGIOS_CMDUSER} --with-command-group=${NAGIOS_CMDGROUP} --with-nagios-user=${NAGIOS_USER} --with-nagios-group=${NAGIOS_GROUP} && make all && make install && make install-config && make install-commandmode && cp sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf -ADD http://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz /tmp/ -RUN cd /tmp && tar -zxvf nagios-plugins-1.5.tar.gz && cd nagios-plugins-1.5 && ./configure --prefix=${NAGIOS_HOME} && make && make install - -RUN sed -i.bak 's/.*\=www\-data//g' /etc/apache2/envvars -RUN export DOC_ROOT="DocumentRoot $(echo $NAGIOS_HOME/share)"; sed -i "s,DocumentRoot.*,$DOC_ROOT," /etc/apache2/sites-enabled/000-default - -RUN ln -s ${NAGIOS_HOME}/bin/nagios /usr/local/bin/nagios && mkdir -p /usr/share/snmp/mibs && chmod 0755 /usr/share/snmp/mibs && touch /usr/share/snmp/mibs/.foo - -RUN echo "use_timezone=$NAGIOS_TIMEZONE" >> ${NAGIOS_HOME}/etc/nagios.cfg && echo "SetEnv TZ \"${NAGIOS_TIMEZONE}\"" >> /etc/apache2/conf.d/nagios.conf - -RUN mkdir -p ${NAGIOS_HOME}/etc/conf.d && mkdir -p ${NAGIOS_HOME}/etc/monitor && ln -s /usr/share/snmp/mibs ${NAGIOS_HOME}/libexec/mibs -RUN echo "cfg_dir=${NAGIOS_HOME}/etc/conf.d" >> ${NAGIOS_HOME}/etc/nagios.cfg -RUN echo "cfg_dir=${NAGIOS_HOME}/etc/monitor" >> ${NAGIOS_HOME}/etc/nagios.cfg -RUN download-mibs && echo "mibs +ALL" > /etc/snmp/snmp.conf - -RUN sed -i 's,/bin/mail,/usr/bin/mail,' /opt/nagios/etc/objects/commands.cfg && \ - sed -i 's,/usr/usr,/usr,' /opt/nagios/etc/objects/commands.cfg -RUN cp /etc/services /var/spool/postfix/etc/ - -RUN mkdir -p /etc/sv/nagios && mkdir -p /etc/sv/apache && rm -rf /etc/sv/getty-5 && mkdir -p /etc/sv/postfix -ADD nagios.init /etc/sv/nagios/run -ADD apache.init /etc/sv/apache/run -ADD postfix.init /etc/sv/postfix/run -ADD postfix.stop /etc/sv/postfix/finish - -ADD start.sh /usr/local/bin/start_nagios - -ENV APACHE_LOCK_DIR /var/run -ENV APACHE_LOG_DIR /var/log/apache2 - -EXPOSE 80 - -VOLUME ["/opt/nagios/var", "/opt/nagios/etc", "/opt/nagios/libexec", "/var/log/apache2", "/usr/share/snmp/mibs"] - -CMD ["/usr/local/bin/start_nagios"] diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/cpuguy83-nagios/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/cpuguy83-nagios/result deleted file mode 100644 index 25dd3dd..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/cpuguy83-nagios/result +++ /dev/null @@ -1,40 +0,0 @@ -(from "cpuguy83/ubuntu") -(env "NAGIOS_HOME" "/opt/nagios") -(env "NAGIOS_USER" "nagios") -(env "NAGIOS_GROUP" "nagios") -(env "NAGIOS_CMDUSER" "nagios") -(env "NAGIOS_CMDGROUP" "nagios") -(env "NAGIOSADMIN_USER" "nagiosadmin") -(env "NAGIOSADMIN_PASS" "nagios") -(env "APACHE_RUN_USER" "nagios") -(env "APACHE_RUN_GROUP" "nagios") -(env "NAGIOS_TIMEZONE" "UTC") -(run "sed -i 's/universe/universe multiverse/' /etc/apt/sources.list") -(run "apt-get update && apt-get install -y iputils-ping netcat build-essential snmp snmpd snmp-mibs-downloader php5-cli apache2 libapache2-mod-php5 runit bc postfix bsd-mailx") -(run "( egrep -i \"^${NAGIOS_GROUP}\" /etc/group || groupadd $NAGIOS_GROUP ) && ( egrep -i \"^${NAGIOS_CMDGROUP}\" /etc/group || groupadd $NAGIOS_CMDGROUP )") -(run "( id -u $NAGIOS_USER || useradd --system $NAGIOS_USER -g $NAGIOS_GROUP -d $NAGIOS_HOME ) && ( id -u $NAGIOS_CMDUSER || useradd --system -d $NAGIOS_HOME -g $NAGIOS_CMDGROUP $NAGIOS_CMDUSER )") -(add "http://downloads.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz?r=http%3A%2F%2Fwww.nagios.org%2Fdownload%2Fcore%2Fthanks%2F%3Ft%3D1398863696&ts=1398863718&use_mirror=superb-dca3" "/tmp/nagios.tar.gz") -(run "cd /tmp && tar -zxvf nagios.tar.gz && cd nagios && ./configure --prefix=${NAGIOS_HOME} --exec-prefix=${NAGIOS_HOME} --enable-event-broker --with-nagios-command-user=${NAGIOS_CMDUSER} --with-command-group=${NAGIOS_CMDGROUP} --with-nagios-user=${NAGIOS_USER} --with-nagios-group=${NAGIOS_GROUP} && make all && make install && make install-config && make install-commandmode && cp sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf") -(add "http://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz" "/tmp/") -(run "cd /tmp && tar -zxvf nagios-plugins-1.5.tar.gz && cd nagios-plugins-1.5 && ./configure --prefix=${NAGIOS_HOME} && make && make install") -(run "sed -i.bak 's/.*\\=www\\-data//g' /etc/apache2/envvars") -(run "export DOC_ROOT=\"DocumentRoot $(echo $NAGIOS_HOME/share)\"; sed -i \"s,DocumentRoot.*,$DOC_ROOT,\" /etc/apache2/sites-enabled/000-default") -(run "ln -s ${NAGIOS_HOME}/bin/nagios /usr/local/bin/nagios && mkdir -p /usr/share/snmp/mibs && chmod 0755 /usr/share/snmp/mibs && touch /usr/share/snmp/mibs/.foo") -(run "echo \"use_timezone=$NAGIOS_TIMEZONE\" >> ${NAGIOS_HOME}/etc/nagios.cfg && echo \"SetEnv TZ \\\"${NAGIOS_TIMEZONE}\\\"\" >> /etc/apache2/conf.d/nagios.conf") -(run "mkdir -p ${NAGIOS_HOME}/etc/conf.d && mkdir -p ${NAGIOS_HOME}/etc/monitor && ln -s /usr/share/snmp/mibs ${NAGIOS_HOME}/libexec/mibs") -(run "echo \"cfg_dir=${NAGIOS_HOME}/etc/conf.d\" >> ${NAGIOS_HOME}/etc/nagios.cfg") -(run "echo \"cfg_dir=${NAGIOS_HOME}/etc/monitor\" >> ${NAGIOS_HOME}/etc/nagios.cfg") -(run "download-mibs && echo \"mibs +ALL\" > /etc/snmp/snmp.conf") -(run "sed -i 's,/bin/mail,/usr/bin/mail,' /opt/nagios/etc/objects/commands.cfg && sed -i 's,/usr/usr,/usr,' /opt/nagios/etc/objects/commands.cfg") -(run "cp /etc/services /var/spool/postfix/etc/") -(run "mkdir -p /etc/sv/nagios && mkdir -p /etc/sv/apache && rm -rf /etc/sv/getty-5 && mkdir -p /etc/sv/postfix") -(add "nagios.init" "/etc/sv/nagios/run") -(add "apache.init" "/etc/sv/apache/run") -(add "postfix.init" "/etc/sv/postfix/run") -(add "postfix.stop" "/etc/sv/postfix/finish") -(add "start.sh" "/usr/local/bin/start_nagios") -(env "APACHE_LOCK_DIR" "/var/run") -(env "APACHE_LOG_DIR" "/var/log/apache2") -(expose "80") -(volume "/opt/nagios/var" "/opt/nagios/etc" "/opt/nagios/libexec" "/var/log/apache2" "/usr/share/snmp/mibs") -(cmd "/usr/local/bin/start_nagios") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/docker/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/docker/Dockerfile deleted file mode 100644 index 99fbe55..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/docker/Dockerfile +++ /dev/null @@ -1,103 +0,0 @@ -# This file describes the standard way to build Docker, using docker -# -# Usage: -# -# # Assemble the full dev environment. This is slow the first time. -# docker build -t docker . -# -# # Mount your source in an interactive container for quick testing: -# docker run -v `pwd`:/go/src/github.com/docker/docker --privileged -i -t docker bash -# -# # Run the test suite: -# docker run --privileged docker hack/make.sh test-unit test-integration-cli test-docker-py -# -# # Publish a release: -# docker run --privileged \ -# -e AWS_S3_BUCKET=baz \ -# -e AWS_ACCESS_KEY=foo \ -# -e AWS_SECRET_KEY=bar \ -# -e GPG_PASSPHRASE=gloubiboulga \ -# docker hack/release.sh -# -# Note: AppArmor used to mess with privileged mode, but this is no longer -# the case. Therefore, you don't have to disable it anymore. -# - -FROM ubuntu:14.04 -MAINTAINER Tianon Gravi (@tianon) - -# Packaged dependencies -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -yq \ - apt-utils \ - aufs-tools \ - automake \ - btrfs-tools \ - build-essential \ - curl \ - dpkg-sig \ - git \ - iptables \ - libapparmor-dev \ - libcap-dev \ - libsqlite3-dev \ - mercurial \ - pandoc \ - parallel \ - reprepro \ - ruby1.9.1 \ - ruby1.9.1-dev \ - s3cmd=1.1.0* \ - --no-install-recommends - -# Get lvm2 source for compiling statically -RUN git clone --no-checkout https://git.fedorahosted.org/git/lvm2.git /usr/local/lvm2 && cd /usr/local/lvm2 && git checkout -q v2_02_103 -# see https://git.fedorahosted.org/cgit/lvm2.git/refs/tags for release tags -# note: we don't use "git clone -b" above because it then spews big nasty warnings about 'detached HEAD' state that we can't silence as easily as we can silence them using "git checkout" directly - -# Compile and install lvm2 -RUN cd /usr/local/lvm2 && ./configure --enable-static_link && make device-mapper && make install_device-mapper -# see https://git.fedorahosted.org/cgit/lvm2.git/tree/INSTALL - -# Install Go -RUN curl -sSL https://golang.org/dl/go1.3.src.tar.gz | tar -v -C /usr/local -xz -ENV PATH /usr/local/go/bin:$PATH -ENV GOPATH /go:/go/src/github.com/docker/docker/vendor -RUN cd /usr/local/go/src && ./make.bash --no-clean 2>&1 - -# Compile Go for cross compilation -ENV DOCKER_CROSSPLATFORMS \ - linux/386 linux/arm \ - darwin/amd64 darwin/386 \ - freebsd/amd64 freebsd/386 freebsd/arm -# (set an explicit GOARM of 5 for maximum compatibility) -ENV GOARM 5 -RUN cd /usr/local/go/src && bash -xc 'for platform in $DOCKER_CROSSPLATFORMS; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean 2>&1; done' - -# Grab Go's cover tool for dead-simple code coverage testing -RUN go get golang.org/x/tools/cmd/cover - -# TODO replace FPM with some very minimal debhelper stuff -RUN gem install --no-rdoc --no-ri fpm --version 1.0.2 - -# Get the "busybox" image source so we can build locally instead of pulling -RUN git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox - -# Setup s3cmd config -RUN /bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEY' > /.s3cfg - -# Set user.email so crosbymichael's in-container merge commits go smoothly -RUN git config --global user.email 'docker-dummy@example.com' - -# Add an unprivileged user to be used for tests which need it -RUN groupadd -r docker -RUN useradd --create-home --gid docker unprivilegeduser - -VOLUME /var/lib/docker -WORKDIR /go/src/github.com/docker/docker -ENV DOCKER_BUILDTAGS apparmor selinux - -# Wrap all commands in the "docker-in-docker" script to allow nested containers -ENTRYPOINT ["hack/dind"] - -# Upload docker source -COPY . /go/src/github.com/docker/docker diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/docker/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/docker/result deleted file mode 100644 index d032f9b..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/docker/result +++ /dev/null @@ -1,24 +0,0 @@ -(from "ubuntu:14.04") -(maintainer "Tianon Gravi (@tianon)") -(run "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -yq \tapt-utils \taufs-tools \tautomake \tbtrfs-tools \tbuild-essential \tcurl \tdpkg-sig \tgit \tiptables \tlibapparmor-dev \tlibcap-dev \tlibsqlite3-dev \tmercurial \tpandoc \tparallel \treprepro \truby1.9.1 \truby1.9.1-dev \ts3cmd=1.1.0* \t--no-install-recommends") -(run "git clone --no-checkout https://git.fedorahosted.org/git/lvm2.git /usr/local/lvm2 && cd /usr/local/lvm2 && git checkout -q v2_02_103") -(run "cd /usr/local/lvm2 && ./configure --enable-static_link && make device-mapper && make install_device-mapper") -(run "curl -sSL https://golang.org/dl/go1.3.src.tar.gz | tar -v -C /usr/local -xz") -(env "PATH" "/usr/local/go/bin:$PATH") -(env "GOPATH" "/go:/go/src/github.com/docker/docker/vendor") -(run "cd /usr/local/go/src && ./make.bash --no-clean 2>&1") -(env "DOCKER_CROSSPLATFORMS" "linux/386 linux/arm \tdarwin/amd64 darwin/386 \tfreebsd/amd64 freebsd/386 freebsd/arm") -(env "GOARM" "5") -(run "cd /usr/local/go/src && bash -xc 'for platform in $DOCKER_CROSSPLATFORMS; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean 2>&1; done'") -(run "go get golang.org/x/tools/cmd/cover") -(run "gem install --no-rdoc --no-ri fpm --version 1.0.2") -(run "git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox") -(run "/bin/echo -e '[default]\\naccess_key=$AWS_ACCESS_KEY\\nsecret_key=$AWS_SECRET_KEY' > /.s3cfg") -(run "git config --global user.email 'docker-dummy@example.com'") -(run "groupadd -r docker") -(run "useradd --create-home --gid docker unprivilegeduser") -(volume "/var/lib/docker") -(workdir "/go/src/github.com/docker/docker") -(env "DOCKER_BUILDTAGS" "apparmor selinux") -(entrypoint "hack/dind") -(copy "." "/go/src/github.com/docker/docker") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/env/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/env/Dockerfile deleted file mode 100644 index 08fa18a..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/env/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -FROM ubuntu -ENV name value -ENV name=value -ENV name=value name2=value2 -ENV name="value value1" -ENV name=value\ value2 -ENV name="value'quote space'value2" -ENV name='value"double quote"value2' -ENV name=value\ value2 name2=value2\ value3 -ENV name="a\"b" -ENV name="a\'b" -ENV name='a\'b' -ENV name='a\'b'' -ENV name='a\"b' -ENV name="''" -# don't put anything after the next line - it must be the last line of the -# Dockerfile and it must end with \ -ENV name=value \ - name1=value1 \ - name2="value2a \ - value2b" \ - name3="value3a\n\"value3b\"" \ - name4="value4a\\nvalue4b" \ diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/env/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/env/result deleted file mode 100644 index ba0a6dd..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/env/result +++ /dev/null @@ -1,16 +0,0 @@ -(from "ubuntu") -(env "name" "value") -(env "name" "value") -(env "name" "value" "name2" "value2") -(env "name" "\"value value1\"") -(env "name" "value\\ value2") -(env "name" "\"value'quote space'value2\"") -(env "name" "'value\"double quote\"value2'") -(env "name" "value\\ value2" "name2" "value2\\ value3") -(env "name" "\"a\\\"b\"") -(env "name" "\"a\\'b\"") -(env "name" "'a\\'b'") -(env "name" "'a\\'b''") -(env "name" "'a\\\"b'") -(env "name" "\"''\"") -(env "name" "value" "name1" "value1" "name2" "\"value2a value2b\"" "name3" "\"value3a\\n\\\"value3b\\\"\"" "name4" "\"value4a\\\\nvalue4b\"") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-after-comment/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-after-comment/Dockerfile deleted file mode 100644 index 6def7ef..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-after-comment/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -# Comment here. Should not be looking for the following parser directive. -# Hence the following line will be ignored, and the subsequent backslash -# continuation will be the default. -# escape = ` - -FROM image -MAINTAINER foo@bar.com -ENV GOPATH \ -\go \ No newline at end of file diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-after-comment/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-after-comment/result deleted file mode 100644 index 21522a8..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-after-comment/result +++ /dev/null @@ -1,3 +0,0 @@ -(from "image") -(maintainer "foo@bar.com") -(env "GOPATH" "\\go") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-nonewline/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-nonewline/Dockerfile deleted file mode 100644 index 08a8cc4..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-nonewline/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -# escape = `` -# There is no white space line after the directives. This still succeeds, but goes -# against best practices. -FROM image -MAINTAINER foo@bar.com -ENV GOPATH ` -\go \ No newline at end of file diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-nonewline/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-nonewline/result deleted file mode 100644 index 21522a8..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape-nonewline/result +++ /dev/null @@ -1,3 +0,0 @@ -(from "image") -(maintainer "foo@bar.com") -(env "GOPATH" "\\go") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape/Dockerfile deleted file mode 100644 index ef30414..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -#escape = ` - -FROM image -MAINTAINER foo@bar.com -ENV GOPATH ` -\go \ No newline at end of file diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape/result deleted file mode 100644 index 21522a8..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escape/result +++ /dev/null @@ -1,3 +0,0 @@ -(from "image") -(maintainer "foo@bar.com") -(env "GOPATH" "\\go") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escapes/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escapes/Dockerfile deleted file mode 100644 index 1ffb17e..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escapes/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM ubuntu:14.04 -MAINTAINER Erik \\Hollensbe \" - -RUN apt-get \update && \ - apt-get \"install znc -y -ADD \conf\\" /.znc - -RUN foo \ - -bar \ - -baz - -CMD [ "\/usr\\\"/bin/znc", "-f", "-r" ] diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escapes/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escapes/result deleted file mode 100644 index 13e409c..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/escapes/result +++ /dev/null @@ -1,6 +0,0 @@ -(from "ubuntu:14.04") -(maintainer "Erik \\\\Hollensbe \\\"") -(run "apt-get \\update && apt-get \\\"install znc -y") -(add "\\conf\\\\\"" "/.znc") -(run "foo bar baz") -(cmd "/usr\\\"/bin/znc" "-f" "-r") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/flags/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/flags/Dockerfile deleted file mode 100644 index 2418e0f..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/flags/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM scratch -COPY foo /tmp/ -COPY --user=me foo /tmp/ -COPY --doit=true foo /tmp/ -COPY --user=me --doit=true foo /tmp/ -COPY --doit=true -- foo /tmp/ -COPY -- foo /tmp/ -CMD --doit [ "a", "b" ] -CMD --doit=true -- [ "a", "b" ] -CMD --doit -- [ ] diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/flags/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/flags/result deleted file mode 100644 index 4578f4c..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/flags/result +++ /dev/null @@ -1,10 +0,0 @@ -(from "scratch") -(copy "foo" "/tmp/") -(copy ["--user=me"] "foo" "/tmp/") -(copy ["--doit=true"] "foo" "/tmp/") -(copy ["--user=me" "--doit=true"] "foo" "/tmp/") -(copy ["--doit=true"] "foo" "/tmp/") -(copy "foo" "/tmp/") -(cmd ["--doit"] "a" "b") -(cmd ["--doit=true"] "a" "b") -(cmd ["--doit"]) diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/health/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/health/Dockerfile deleted file mode 100644 index 081e442..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/health/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM debian -ADD check.sh main.sh /app/ -CMD /app/main.sh -HEALTHCHECK -HEALTHCHECK --interval=5s --timeout=3s --retries=3 \ - CMD /app/check.sh --quiet -HEALTHCHECK CMD -HEALTHCHECK CMD a b -HEALTHCHECK --timeout=3s CMD ["foo"] -HEALTHCHECK CONNECT TCP 7000 diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/health/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/health/result deleted file mode 100644 index 092924f..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/health/result +++ /dev/null @@ -1,9 +0,0 @@ -(from "debian") -(add "check.sh" "main.sh" "/app/") -(cmd "/app/main.sh") -(healthcheck) -(healthcheck ["--interval=5s" "--timeout=3s" "--retries=3"] "CMD" "/app/check.sh --quiet") -(healthcheck "CMD") -(healthcheck "CMD" "a b") -(healthcheck ["--timeout=3s"] "CMD" "foo") -(healthcheck "CONNECT" "TCP 7000") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/influxdb/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/influxdb/Dockerfile deleted file mode 100644 index 587fb9b..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/influxdb/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM ubuntu:14.04 - -RUN apt-get update && apt-get install wget -y -RUN wget http://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb -RUN dpkg -i influxdb_latest_amd64.deb -RUN rm -r /opt/influxdb/shared - -VOLUME /opt/influxdb/shared - -CMD /usr/bin/influxdb --pidfile /var/run/influxdb.pid -config /opt/influxdb/shared/config.toml - -EXPOSE 8083 -EXPOSE 8086 -EXPOSE 8090 -EXPOSE 8099 diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/influxdb/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/influxdb/result deleted file mode 100644 index 0998e87..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/influxdb/result +++ /dev/null @@ -1,11 +0,0 @@ -(from "ubuntu:14.04") -(run "apt-get update && apt-get install wget -y") -(run "wget http://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb") -(run "dpkg -i influxdb_latest_amd64.deb") -(run "rm -r /opt/influxdb/shared") -(volume "/opt/influxdb/shared") -(cmd "/usr/bin/influxdb --pidfile /var/run/influxdb.pid -config /opt/influxdb/shared/config.toml") -(expose "8083") -(expose "8086") -(expose "8090") -(expose "8099") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string-double/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string-double/Dockerfile deleted file mode 100644 index 39fe27d..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string-double/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -CMD "[\"echo\", \"Phew, I just managed to escaped those double quotes\"]" diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string-double/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string-double/result deleted file mode 100644 index afc220c..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string-double/result +++ /dev/null @@ -1 +0,0 @@ -(cmd "\"[\\\"echo\\\", \\\"Phew, I just managed to escaped those double quotes\\\"]\"") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string/Dockerfile deleted file mode 100644 index eaae081..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -CMD '["echo", "Well, JSON in a string is JSON too?"]' diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string/result deleted file mode 100644 index 484804e..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-json-inside-string/result +++ /dev/null @@ -1 +0,0 @@ -(cmd "'[\"echo\", \"Well, JSON in a string is JSON too?\"]'") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-single-quotes/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-single-quotes/Dockerfile deleted file mode 100644 index c3ac63c..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-single-quotes/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -CMD ['echo','single quotes are invalid JSON'] diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-single-quotes/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-single-quotes/result deleted file mode 100644 index 6147891..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-single-quotes/result +++ /dev/null @@ -1 +0,0 @@ -(cmd "['echo','single quotes are invalid JSON']") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-bracket/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-bracket/Dockerfile deleted file mode 100644 index 5fd4afa..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-bracket/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -CMD ["echo", "Please, close the brackets when you're done" diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-bracket/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-bracket/result deleted file mode 100644 index 1ffbb8f..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-bracket/result +++ /dev/null @@ -1 +0,0 @@ -(cmd "[\"echo\", \"Please, close the brackets when you're done\"") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-string/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-string/Dockerfile deleted file mode 100644 index 30cc4bb..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-string/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -CMD ["echo", "look ma, no quote!] diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-string/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-string/result deleted file mode 100644 index 3204814..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/jeztah-invalid-json-unterminated-string/result +++ /dev/null @@ -1 +0,0 @@ -(cmd "[\"echo\", \"look ma, no quote!]") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/json/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/json/Dockerfile deleted file mode 100644 index a586917..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/json/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -CMD [] -CMD [""] -CMD ["a"] -CMD ["a","b"] -CMD [ "a", "b" ] -CMD [ "a", "b" ] -CMD [ "a", "b" ] -CMD ["abc 123", "♥", "☃", "\" \\ \/ \b \f \n \r \t \u0000"] diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/json/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/json/result deleted file mode 100644 index c6553e6..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/json/result +++ /dev/null @@ -1,8 +0,0 @@ -(cmd) -(cmd "") -(cmd "a") -(cmd "a" "b") -(cmd "a" "b") -(cmd "a" "b") -(cmd "a" "b") -(cmd "abc 123" "♥" "☃" "\" \\ / \b \f \n \r \t \x00") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/kartar-entrypoint-oddities/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/kartar-entrypoint-oddities/Dockerfile deleted file mode 100644 index 35f9c24..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/kartar-entrypoint-oddities/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM ubuntu:14.04 -MAINTAINER James Turnbull "james@example.com" -ENV REFRESHED_AT 2014-06-01 -RUN apt-get update -RUN apt-get -y install redis-server redis-tools -EXPOSE 6379 -ENTRYPOINT [ "/usr/bin/redis-server" ] diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/kartar-entrypoint-oddities/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/kartar-entrypoint-oddities/result deleted file mode 100644 index b5ac6fe..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/kartar-entrypoint-oddities/result +++ /dev/null @@ -1,7 +0,0 @@ -(from "ubuntu:14.04") -(maintainer "James Turnbull \"james@example.com\"") -(env "REFRESHED_AT" "2014-06-01") -(run "apt-get update") -(run "apt-get -y install redis-server redis-tools") -(expose "6379") -(entrypoint "/usr/bin/redis-server") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/lk4d4-the-edge-case-generator/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/lk4d4-the-edge-case-generator/Dockerfile deleted file mode 100644 index 188395f..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/lk4d4-the-edge-case-generator/Dockerfile +++ /dev/null @@ -1,48 +0,0 @@ -FROM busybox:buildroot-2014.02 - -MAINTAINER docker - -ONBUILD RUN ["echo", "test"] -ONBUILD RUN echo test -ONBUILD COPY . / - - -# RUN Commands \ -# linebreak in comment \ -RUN ["ls", "-la"] -RUN ["echo", "'1234'"] -RUN echo "1234" -RUN echo 1234 -RUN echo '1234' && \ - echo "456" && \ - echo 789 -RUN sh -c 'echo root:testpass \ - > /tmp/passwd' -RUN mkdir -p /test /test2 /test3/test - -# ENV \ -ENV SCUBA 1 DUBA 3 -ENV SCUBA "1 DUBA 3" - -# CMD \ -CMD ["echo", "test"] -CMD echo test -CMD echo "test" -CMD echo 'test' -CMD echo 'test' | wc - - -#EXPOSE\ -EXPOSE 3000 -EXPOSE 9000 5000 6000 - -USER docker -USER docker:root - -VOLUME ["/test"] -VOLUME ["/test", "/test2"] -VOLUME /test3 - -WORKDIR /test - -ADD . / -COPY . copy diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/lk4d4-the-edge-case-generator/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/lk4d4-the-edge-case-generator/result deleted file mode 100644 index 6f7d57a..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/lk4d4-the-edge-case-generator/result +++ /dev/null @@ -1,29 +0,0 @@ -(from "busybox:buildroot-2014.02") -(maintainer "docker ") -(onbuild (run "echo" "test")) -(onbuild (run "echo test")) -(onbuild (copy "." "/")) -(run "ls" "-la") -(run "echo" "'1234'") -(run "echo \"1234\"") -(run "echo 1234") -(run "echo '1234' && echo \"456\" && echo 789") -(run "sh -c 'echo root:testpass > /tmp/passwd'") -(run "mkdir -p /test /test2 /test3/test") -(env "SCUBA" "1 DUBA 3") -(env "SCUBA" "\"1 DUBA 3\"") -(cmd "echo" "test") -(cmd "echo test") -(cmd "echo \"test\"") -(cmd "echo 'test'") -(cmd "echo 'test' | wc -") -(expose "3000") -(expose "9000" "5000" "6000") -(user "docker") -(user "docker:root") -(volume "/test") -(volume "/test" "/test2") -(volume "/test3") -(workdir "/test") -(add "." "/") -(copy "." "copy") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mail/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mail/Dockerfile deleted file mode 100644 index f64c116..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mail/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM ubuntu:14.04 - -RUN apt-get update -qy && apt-get install mutt offlineimap vim-nox abook elinks curl tmux cron zsh -y -ADD .muttrc / -ADD .offlineimaprc / -ADD .tmux.conf / -ADD mutt /.mutt -ADD vim /.vim -ADD vimrc /.vimrc -ADD crontab /etc/crontab -RUN chmod 644 /etc/crontab -RUN mkdir /Mail -RUN mkdir /.offlineimap -RUN echo "export TERM=screen-256color" >/.zshenv - -CMD setsid cron; tmux -2 diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mail/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mail/result deleted file mode 100644 index a0efcf0..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mail/result +++ /dev/null @@ -1,14 +0,0 @@ -(from "ubuntu:14.04") -(run "apt-get update -qy && apt-get install mutt offlineimap vim-nox abook elinks curl tmux cron zsh -y") -(add ".muttrc" "/") -(add ".offlineimaprc" "/") -(add ".tmux.conf" "/") -(add "mutt" "/.mutt") -(add "vim" "/.vim") -(add "vimrc" "/.vimrc") -(add "crontab" "/etc/crontab") -(run "chmod 644 /etc/crontab") -(run "mkdir /Mail") -(run "mkdir /.offlineimap") -(run "echo \"export TERM=screen-256color\" >/.zshenv") -(cmd "setsid cron; tmux -2") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/multiple-volumes/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/multiple-volumes/Dockerfile deleted file mode 100644 index 57bb597..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/multiple-volumes/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM foo - -VOLUME /opt/nagios/var /opt/nagios/etc /opt/nagios/libexec /var/log/apache2 /usr/share/snmp/mibs diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/multiple-volumes/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/multiple-volumes/result deleted file mode 100644 index 18dbdee..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/multiple-volumes/result +++ /dev/null @@ -1,2 +0,0 @@ -(from "foo") -(volume "/opt/nagios/var" "/opt/nagios/etc" "/opt/nagios/libexec" "/var/log/apache2" "/usr/share/snmp/mibs") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mumble/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mumble/Dockerfile deleted file mode 100644 index 5b9ec06..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mumble/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM ubuntu:14.04 - -RUN apt-get update && apt-get install libcap2-bin mumble-server -y - -ADD ./mumble-server.ini /etc/mumble-server.ini - -CMD /usr/sbin/murmurd diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mumble/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mumble/result deleted file mode 100644 index a0036a9..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/mumble/result +++ /dev/null @@ -1,4 +0,0 @@ -(from "ubuntu:14.04") -(run "apt-get update && apt-get install libcap2-bin mumble-server -y") -(add "./mumble-server.ini" "/etc/mumble-server.ini") -(cmd "/usr/sbin/murmurd") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/nginx/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/nginx/Dockerfile deleted file mode 100644 index bf8368e..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/nginx/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM ubuntu:14.04 -MAINTAINER Erik Hollensbe - -RUN apt-get update && apt-get install nginx-full -y -RUN rm -rf /etc/nginx -ADD etc /etc/nginx -RUN chown -R root:root /etc/nginx -RUN /usr/sbin/nginx -qt -RUN mkdir /www - -CMD ["/usr/sbin/nginx"] - -VOLUME /www -EXPOSE 80 diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/nginx/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/nginx/result deleted file mode 100644 index 56ddb6f..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/nginx/result +++ /dev/null @@ -1,11 +0,0 @@ -(from "ubuntu:14.04") -(maintainer "Erik Hollensbe ") -(run "apt-get update && apt-get install nginx-full -y") -(run "rm -rf /etc/nginx") -(add "etc" "/etc/nginx") -(run "chown -R root:root /etc/nginx") -(run "/usr/sbin/nginx -qt") -(run "mkdir /www") -(cmd "/usr/sbin/nginx") -(volume "/www") -(expose "80") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/tf2/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/tf2/Dockerfile deleted file mode 100644 index 72b79bd..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/tf2/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -FROM ubuntu:12.04 - -EXPOSE 27015 -EXPOSE 27005 -EXPOSE 26901 -EXPOSE 27020 - -RUN apt-get update && apt-get install libc6-dev-i386 curl unzip -y -RUN mkdir -p /steam -RUN curl http://media.steampowered.com/client/steamcmd_linux.tar.gz | tar vxz -C /steam -ADD ./script /steam/script -RUN /steam/steamcmd.sh +runscript /steam/script -RUN curl http://mirror.pointysoftware.net/alliedmodders/mmsource-1.10.0-linux.tar.gz | tar vxz -C /steam/tf2/tf -RUN curl http://mirror.pointysoftware.net/alliedmodders/sourcemod-1.5.3-linux.tar.gz | tar vxz -C /steam/tf2/tf -ADD ./server.cfg /steam/tf2/tf/cfg/server.cfg -ADD ./ctf_2fort.cfg /steam/tf2/tf/cfg/ctf_2fort.cfg -ADD ./sourcemod.cfg /steam/tf2/tf/cfg/sourcemod/sourcemod.cfg -RUN rm -r /steam/tf2/tf/addons/sourcemod/configs -ADD ./configs /steam/tf2/tf/addons/sourcemod/configs -RUN mkdir -p /steam/tf2/tf/addons/sourcemod/translations/en -RUN cp /steam/tf2/tf/addons/sourcemod/translations/*.txt /steam/tf2/tf/addons/sourcemod/translations/en - -CMD cd /steam/tf2 && ./srcds_run -port 27015 +ip 0.0.0.0 +map ctf_2fort -autoupdate -steam_dir /steam -steamcmd_script /steam/script +tf_bot_quota 12 +tf_bot_quota_mode fill diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/tf2/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/tf2/result deleted file mode 100644 index d4f94cd..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/tf2/result +++ /dev/null @@ -1,20 +0,0 @@ -(from "ubuntu:12.04") -(expose "27015") -(expose "27005") -(expose "26901") -(expose "27020") -(run "apt-get update && apt-get install libc6-dev-i386 curl unzip -y") -(run "mkdir -p /steam") -(run "curl http://media.steampowered.com/client/steamcmd_linux.tar.gz | tar vxz -C /steam") -(add "./script" "/steam/script") -(run "/steam/steamcmd.sh +runscript /steam/script") -(run "curl http://mirror.pointysoftware.net/alliedmodders/mmsource-1.10.0-linux.tar.gz | tar vxz -C /steam/tf2/tf") -(run "curl http://mirror.pointysoftware.net/alliedmodders/sourcemod-1.5.3-linux.tar.gz | tar vxz -C /steam/tf2/tf") -(add "./server.cfg" "/steam/tf2/tf/cfg/server.cfg") -(add "./ctf_2fort.cfg" "/steam/tf2/tf/cfg/ctf_2fort.cfg") -(add "./sourcemod.cfg" "/steam/tf2/tf/cfg/sourcemod/sourcemod.cfg") -(run "rm -r /steam/tf2/tf/addons/sourcemod/configs") -(add "./configs" "/steam/tf2/tf/addons/sourcemod/configs") -(run "mkdir -p /steam/tf2/tf/addons/sourcemod/translations/en") -(run "cp /steam/tf2/tf/addons/sourcemod/translations/*.txt /steam/tf2/tf/addons/sourcemod/translations/en") -(cmd "cd /steam/tf2 && ./srcds_run -port 27015 +ip 0.0.0.0 +map ctf_2fort -autoupdate -steam_dir /steam -steamcmd_script /steam/script +tf_bot_quota 12 +tf_bot_quota_mode fill") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/weechat/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/weechat/Dockerfile deleted file mode 100644 index 4842088..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/weechat/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM ubuntu:14.04 - -RUN apt-get update -qy && apt-get install tmux zsh weechat-curses -y - -ADD .weechat /.weechat -ADD .tmux.conf / -RUN echo "export TERM=screen-256color" >/.zshenv - -CMD zsh -c weechat diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/weechat/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/weechat/result deleted file mode 100644 index c3abb4c..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/weechat/result +++ /dev/null @@ -1,6 +0,0 @@ -(from "ubuntu:14.04") -(run "apt-get update -qy && apt-get install tmux zsh weechat-curses -y") -(add ".weechat" "/.weechat") -(add ".tmux.conf" "/") -(run "echo \"export TERM=screen-256color\" >/.zshenv") -(cmd "zsh -c weechat") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/znc/Dockerfile b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/znc/Dockerfile deleted file mode 100644 index 3a4da6e..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/znc/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM ubuntu:14.04 -MAINTAINER Erik Hollensbe - -RUN apt-get update && apt-get install znc -y -ADD conf /.znc - -CMD [ "/usr/bin/znc", "-f", "-r" ] diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/znc/result b/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/znc/result deleted file mode 100644 index 5493b25..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/testfiles/znc/result +++ /dev/null @@ -1,5 +0,0 @@ -(from "ubuntu:14.04") -(maintainer "Erik Hollensbe ") -(run "apt-get update && apt-get install znc -y") -(add "conf" "/.znc") -(cmd "/usr/bin/znc" "-f" "-r") diff --git a/vendor/github.com/docker/docker/builder/dockerfile/parser/utils.go b/vendor/github.com/docker/docker/builder/dockerfile/parser/utils.go deleted file mode 100644 index cd7af75..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/parser/utils.go +++ /dev/null @@ -1,176 +0,0 @@ -package parser - -import ( - "fmt" - "strconv" - "strings" - "unicode" -) - -// Dump dumps the AST defined by `node` as a list of sexps. -// Returns a string suitable for printing. -func (node *Node) Dump() string { - str := "" - str += node.Value - - if len(node.Flags) > 0 { - str += fmt.Sprintf(" %q", node.Flags) - } - - for _, n := range node.Children { - str += "(" + n.Dump() + ")\n" - } - - if node.Next != nil { - for n := node.Next; n != nil; n = n.Next { - if len(n.Children) > 0 { - str += " " + n.Dump() - } else { - str += " " + strconv.Quote(n.Value) - } - } - } - - return strings.TrimSpace(str) -} - -// performs the dispatch based on the two primal strings, cmd and args. Please -// look at the dispatch table in parser.go to see how these dispatchers work. -func fullDispatch(cmd, args string, d *Directive) (*Node, map[string]bool, error) { - fn := dispatch[cmd] - - // Ignore invalid Dockerfile instructions - if fn == nil { - fn = parseIgnore - } - - sexp, attrs, err := fn(args, d) - if err != nil { - return nil, nil, err - } - - return sexp, attrs, nil -} - -// splitCommand takes a single line of text and parses out the cmd and args, -// which are used for dispatching to more exact parsing functions. -func splitCommand(line string) (string, []string, string, error) { - var args string - var flags []string - - // Make sure we get the same results irrespective of leading/trailing spaces - cmdline := tokenWhitespace.Split(strings.TrimSpace(line), 2) - cmd := strings.ToLower(cmdline[0]) - - if len(cmdline) == 2 { - var err error - args, flags, err = extractBuilderFlags(cmdline[1]) - if err != nil { - return "", nil, "", err - } - } - - return cmd, flags, strings.TrimSpace(args), nil -} - -// covers comments and empty lines. Lines should be trimmed before passing to -// this function. -func stripComments(line string) string { - // string is already trimmed at this point - if tokenComment.MatchString(line) { - return tokenComment.ReplaceAllString(line, "") - } - - return line -} - -func extractBuilderFlags(line string) (string, []string, error) { - // Parses the BuilderFlags and returns the remaining part of the line - - const ( - inSpaces = iota // looking for start of a word - inWord - inQuote - ) - - words := []string{} - phase := inSpaces - word := "" - quote := '\000' - blankOK := false - var ch rune - - for pos := 0; pos <= len(line); pos++ { - if pos != len(line) { - ch = rune(line[pos]) - } - - if phase == inSpaces { // Looking for start of word - if pos == len(line) { // end of input - break - } - if unicode.IsSpace(ch) { // skip spaces - continue - } - - // Only keep going if the next word starts with -- - if ch != '-' || pos+1 == len(line) || rune(line[pos+1]) != '-' { - return line[pos:], words, nil - } - - phase = inWord // found someting with "--", fall through - } - if (phase == inWord || phase == inQuote) && (pos == len(line)) { - if word != "--" && (blankOK || len(word) > 0) { - words = append(words, word) - } - break - } - if phase == inWord { - if unicode.IsSpace(ch) { - phase = inSpaces - if word == "--" { - return line[pos:], words, nil - } - if blankOK || len(word) > 0 { - words = append(words, word) - } - word = "" - blankOK = false - continue - } - if ch == '\'' || ch == '"' { - quote = ch - blankOK = true - phase = inQuote - continue - } - if ch == '\\' { - if pos+1 == len(line) { - continue // just skip \ at end - } - pos++ - ch = rune(line[pos]) - } - word += string(ch) - continue - } - if phase == inQuote { - if ch == quote { - phase = inWord - continue - } - if ch == '\\' { - if pos+1 == len(line) { - phase = inWord - continue // just skip \ at end - } - pos++ - ch = rune(line[pos]) - } - word += string(ch) - } - } - - return "", words, nil -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/shell_parser.go b/vendor/github.com/docker/docker/builder/dockerfile/shell_parser.go deleted file mode 100644 index 189afd1..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/shell_parser.go +++ /dev/null @@ -1,329 +0,0 @@ -package dockerfile - -// This will take a single word and an array of env variables and -// process all quotes (" and ') as well as $xxx and ${xxx} env variable -// tokens. Tries to mimic bash shell process. -// It doesn't support all flavors of ${xx:...} formats but new ones can -// be added by adding code to the "special ${} format processing" section - -import ( - "fmt" - "runtime" - "strings" - "text/scanner" - "unicode" -) - -type shellWord struct { - word string - scanner scanner.Scanner - envs []string - pos int - escapeToken rune -} - -// ProcessWord will use the 'env' list of environment variables, -// and replace any env var references in 'word'. -func ProcessWord(word string, env []string, escapeToken rune) (string, error) { - sw := &shellWord{ - word: word, - envs: env, - pos: 0, - escapeToken: escapeToken, - } - sw.scanner.Init(strings.NewReader(word)) - word, _, err := sw.process() - return word, err -} - -// ProcessWords will use the 'env' list of environment variables, -// and replace any env var references in 'word' then it will also -// return a slice of strings which represents the 'word' -// split up based on spaces - taking into account quotes. Note that -// this splitting is done **after** the env var substitutions are done. -// Note, each one is trimmed to remove leading and trailing spaces (unless -// they are quoted", but ProcessWord retains spaces between words. -func ProcessWords(word string, env []string, escapeToken rune) ([]string, error) { - sw := &shellWord{ - word: word, - envs: env, - pos: 0, - escapeToken: escapeToken, - } - sw.scanner.Init(strings.NewReader(word)) - _, words, err := sw.process() - return words, err -} - -func (sw *shellWord) process() (string, []string, error) { - return sw.processStopOn(scanner.EOF) -} - -type wordsStruct struct { - word string - words []string - inWord bool -} - -func (w *wordsStruct) addChar(ch rune) { - if unicode.IsSpace(ch) && w.inWord { - if len(w.word) != 0 { - w.words = append(w.words, w.word) - w.word = "" - w.inWord = false - } - } else if !unicode.IsSpace(ch) { - w.addRawChar(ch) - } -} - -func (w *wordsStruct) addRawChar(ch rune) { - w.word += string(ch) - w.inWord = true -} - -func (w *wordsStruct) addString(str string) { - var scan scanner.Scanner - scan.Init(strings.NewReader(str)) - for scan.Peek() != scanner.EOF { - w.addChar(scan.Next()) - } -} - -func (w *wordsStruct) addRawString(str string) { - w.word += str - w.inWord = true -} - -func (w *wordsStruct) getWords() []string { - if len(w.word) > 0 { - w.words = append(w.words, w.word) - - // Just in case we're called again by mistake - w.word = "" - w.inWord = false - } - return w.words -} - -// Process the word, starting at 'pos', and stop when we get to the -// end of the word or the 'stopChar' character -func (sw *shellWord) processStopOn(stopChar rune) (string, []string, error) { - var result string - var words wordsStruct - - var charFuncMapping = map[rune]func() (string, error){ - '\'': sw.processSingleQuote, - '"': sw.processDoubleQuote, - '$': sw.processDollar, - } - - for sw.scanner.Peek() != scanner.EOF { - ch := sw.scanner.Peek() - - if stopChar != scanner.EOF && ch == stopChar { - sw.scanner.Next() - break - } - if fn, ok := charFuncMapping[ch]; ok { - // Call special processing func for certain chars - tmp, err := fn() - if err != nil { - return "", []string{}, err - } - result += tmp - - if ch == rune('$') { - words.addString(tmp) - } else { - words.addRawString(tmp) - } - } else { - // Not special, just add it to the result - ch = sw.scanner.Next() - - if ch == sw.escapeToken { - // '\' (default escape token, but ` allowed) escapes, except end of line - - ch = sw.scanner.Next() - - if ch == scanner.EOF { - break - } - - words.addRawChar(ch) - } else { - words.addChar(ch) - } - - result += string(ch) - } - } - - return result, words.getWords(), nil -} - -func (sw *shellWord) processSingleQuote() (string, error) { - // All chars between single quotes are taken as-is - // Note, you can't escape ' - var result string - - sw.scanner.Next() - - for { - ch := sw.scanner.Next() - if ch == '\'' || ch == scanner.EOF { - break - } - result += string(ch) - } - - return result, nil -} - -func (sw *shellWord) processDoubleQuote() (string, error) { - // All chars up to the next " are taken as-is, even ', except any $ chars - // But you can escape " with a \ (or ` if escape token set accordingly) - var result string - - sw.scanner.Next() - - for sw.scanner.Peek() != scanner.EOF { - ch := sw.scanner.Peek() - if ch == '"' { - sw.scanner.Next() - break - } - if ch == '$' { - tmp, err := sw.processDollar() - if err != nil { - return "", err - } - result += tmp - } else { - ch = sw.scanner.Next() - if ch == sw.escapeToken { - chNext := sw.scanner.Peek() - - if chNext == scanner.EOF { - // Ignore \ at end of word - continue - } - - if chNext == '"' || chNext == '$' { - // \" and \$ can be escaped, all other \'s are left as-is - ch = sw.scanner.Next() - } - } - result += string(ch) - } - } - - return result, nil -} - -func (sw *shellWord) processDollar() (string, error) { - sw.scanner.Next() - ch := sw.scanner.Peek() - if ch == '{' { - sw.scanner.Next() - name := sw.processName() - ch = sw.scanner.Peek() - if ch == '}' { - // Normal ${xx} case - sw.scanner.Next() - return sw.getEnv(name), nil - } - if ch == ':' { - // Special ${xx:...} format processing - // Yes it allows for recursive $'s in the ... spot - - sw.scanner.Next() // skip over : - modifier := sw.scanner.Next() - - word, _, err := sw.processStopOn('}') - if err != nil { - return "", err - } - - // Grab the current value of the variable in question so we - // can use to to determine what to do based on the modifier - newValue := sw.getEnv(name) - - switch modifier { - case '+': - if newValue != "" { - newValue = word - } - return newValue, nil - - case '-': - if newValue == "" { - newValue = word - } - return newValue, nil - - default: - return "", fmt.Errorf("Unsupported modifier (%c) in substitution: %s", modifier, sw.word) - } - } - return "", fmt.Errorf("Missing ':' in substitution: %s", sw.word) - } - // $xxx case - name := sw.processName() - if name == "" { - return "$", nil - } - return sw.getEnv(name), nil -} - -func (sw *shellWord) processName() string { - // Read in a name (alphanumeric or _) - // If it starts with a numeric then just return $# - var name string - - for sw.scanner.Peek() != scanner.EOF { - ch := sw.scanner.Peek() - if len(name) == 0 && unicode.IsDigit(ch) { - ch = sw.scanner.Next() - return string(ch) - } - if !unicode.IsLetter(ch) && !unicode.IsDigit(ch) && ch != '_' { - break - } - ch = sw.scanner.Next() - name += string(ch) - } - - return name -} - -func (sw *shellWord) getEnv(name string) string { - if runtime.GOOS == "windows" { - // Case-insensitive environment variables on Windows - name = strings.ToUpper(name) - } - for _, env := range sw.envs { - i := strings.Index(env, "=") - if i < 0 { - if runtime.GOOS == "windows" { - env = strings.ToUpper(env) - } - if name == env { - // Should probably never get here, but just in case treat - // it like "var" and "var=" are the same - return "" - } - continue - } - compareName := env[:i] - if runtime.GOOS == "windows" { - compareName = strings.ToUpper(compareName) - } - if name != compareName { - continue - } - return env[i+1:] - } - return "" -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/shell_parser_test.go b/vendor/github.com/docker/docker/builder/dockerfile/shell_parser_test.go deleted file mode 100644 index 6cf691c..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/shell_parser_test.go +++ /dev/null @@ -1,155 +0,0 @@ -package dockerfile - -import ( - "bufio" - "os" - "runtime" - "strings" - "testing" -) - -func TestShellParser4EnvVars(t *testing.T) { - fn := "envVarTest" - lineCount := 0 - - file, err := os.Open(fn) - if err != nil { - t.Fatalf("Can't open '%s': %s", err, fn) - } - defer file.Close() - - scanner := bufio.NewScanner(file) - envs := []string{"PWD=/home", "SHELL=bash", "KOREAN=한국어"} - for scanner.Scan() { - line := scanner.Text() - lineCount++ - - // Trim comments and blank lines - i := strings.Index(line, "#") - if i >= 0 { - line = line[:i] - } - line = strings.TrimSpace(line) - - if line == "" { - continue - } - - words := strings.Split(line, "|") - if len(words) != 3 { - t.Fatalf("Error in '%s' - should be exactly one | in:%q", fn, line) - } - - words[0] = strings.TrimSpace(words[0]) - words[1] = strings.TrimSpace(words[1]) - words[2] = strings.TrimSpace(words[2]) - - // Key W=Windows; A=All; U=Unix - if (words[0] != "W") && (words[0] != "A") && (words[0] != "U") { - t.Fatalf("Invalid tag %s at line %d of %s. Must be W, A or U", words[0], lineCount, fn) - } - - if ((words[0] == "W" || words[0] == "A") && runtime.GOOS == "windows") || - ((words[0] == "U" || words[0] == "A") && runtime.GOOS != "windows") { - newWord, err := ProcessWord(words[1], envs, '\\') - - if err != nil { - newWord = "error" - } - - if newWord != words[2] { - t.Fatalf("Error. Src: %s Calc: %s Expected: %s at line %d", words[1], newWord, words[2], lineCount) - } - } - } -} - -func TestShellParser4Words(t *testing.T) { - fn := "wordsTest" - - file, err := os.Open(fn) - if err != nil { - t.Fatalf("Can't open '%s': %s", err, fn) - } - defer file.Close() - - envs := []string{} - scanner := bufio.NewScanner(file) - for scanner.Scan() { - line := scanner.Text() - - if strings.HasPrefix(line, "#") { - continue - } - - if strings.HasPrefix(line, "ENV ") { - line = strings.TrimLeft(line[3:], " ") - envs = append(envs, line) - continue - } - - words := strings.Split(line, "|") - if len(words) != 2 { - t.Fatalf("Error in '%s' - should be exactly one | in: %q", fn, line) - } - test := strings.TrimSpace(words[0]) - expected := strings.Split(strings.TrimLeft(words[1], " "), ",") - - result, err := ProcessWords(test, envs, '\\') - - if err != nil { - result = []string{"error"} - } - - if len(result) != len(expected) { - t.Fatalf("Error. %q was suppose to result in %q, but got %q instead", test, expected, result) - } - for i, w := range expected { - if w != result[i] { - t.Fatalf("Error. %q was suppose to result in %q, but got %q instead", test, expected, result) - } - } - } -} - -func TestGetEnv(t *testing.T) { - sw := &shellWord{ - word: "", - envs: nil, - pos: 0, - } - - sw.envs = []string{} - if sw.getEnv("foo") != "" { - t.Fatalf("2 - 'foo' should map to ''") - } - - sw.envs = []string{"foo"} - if sw.getEnv("foo") != "" { - t.Fatalf("3 - 'foo' should map to ''") - } - - sw.envs = []string{"foo="} - if sw.getEnv("foo") != "" { - t.Fatalf("4 - 'foo' should map to ''") - } - - sw.envs = []string{"foo=bar"} - if sw.getEnv("foo") != "bar" { - t.Fatalf("5 - 'foo' should map to 'bar'") - } - - sw.envs = []string{"foo=bar", "car=hat"} - if sw.getEnv("foo") != "bar" { - t.Fatalf("6 - 'foo' should map to 'bar'") - } - if sw.getEnv("car") != "hat" { - t.Fatalf("7 - 'car' should map to 'hat'") - } - - // Make sure we grab the first 'car' in the list - sw.envs = []string{"foo=bar", "car=hat", "car=bike"} - if sw.getEnv("car") != "hat" { - t.Fatalf("8 - 'car' should map to 'hat'") - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/support.go b/vendor/github.com/docker/docker/builder/dockerfile/support.go deleted file mode 100644 index e875889..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/support.go +++ /dev/null @@ -1,19 +0,0 @@ -package dockerfile - -import "strings" - -// handleJSONArgs parses command passed to CMD, ENTRYPOINT, RUN and SHELL instruction in Dockerfile -// for exec form it returns untouched args slice -// for shell form it returns concatenated args as the first element of a slice -func handleJSONArgs(args []string, attributes map[string]bool) []string { - if len(args) == 0 { - return []string{} - } - - if attributes != nil && attributes["json"] { - return args - } - - // literal string command, not an exec array - return []string{strings.Join(args, " ")} -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/support_test.go b/vendor/github.com/docker/docker/builder/dockerfile/support_test.go deleted file mode 100644 index 7cc6fe9..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/support_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package dockerfile - -import "testing" - -type testCase struct { - name string - args []string - attributes map[string]bool - expected []string -} - -func initTestCases() []testCase { - testCases := []testCase{} - - testCases = append(testCases, testCase{ - name: "empty args", - args: []string{}, - attributes: make(map[string]bool), - expected: []string{}, - }) - - jsonAttributes := make(map[string]bool) - jsonAttributes["json"] = true - - testCases = append(testCases, testCase{ - name: "json attribute with one element", - args: []string{"foo"}, - attributes: jsonAttributes, - expected: []string{"foo"}, - }) - - testCases = append(testCases, testCase{ - name: "json attribute with two elements", - args: []string{"foo", "bar"}, - attributes: jsonAttributes, - expected: []string{"foo", "bar"}, - }) - - testCases = append(testCases, testCase{ - name: "no attributes", - args: []string{"foo", "bar"}, - attributes: nil, - expected: []string{"foo bar"}, - }) - - return testCases -} - -func TestHandleJSONArgs(t *testing.T) { - testCases := initTestCases() - - for _, test := range testCases { - arguments := handleJSONArgs(test.args, test.attributes) - - if len(arguments) != len(test.expected) { - t.Fatalf("In test \"%s\": length of returned slice is incorrect. Expected: %d, got: %d", test.name, len(test.expected), len(arguments)) - } - - for i := range test.expected { - if arguments[i] != test.expected[i] { - t.Fatalf("In test \"%s\": element as position %d is incorrect. Expected: %s, got: %s", test.name, i, test.expected[i], arguments[i]) - } - } - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/utils_test.go b/vendor/github.com/docker/docker/builder/dockerfile/utils_test.go deleted file mode 100644 index 80a3f1b..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/utils_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package dockerfile - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -// createTestTempDir creates a temporary directory for testing. -// It returns the created path and a cleanup function which is meant to be used as deferred call. -// When an error occurs, it terminates the test. -func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) { - path, err := ioutil.TempDir(dir, prefix) - - if err != nil { - t.Fatalf("Error when creating directory %s with prefix %s: %s", dir, prefix, err) - } - - return path, func() { - err = os.RemoveAll(path) - - if err != nil { - t.Fatalf("Error when removing directory %s: %s", path, err) - } - } -} - -// createTestTempFile creates a temporary file within dir with specific contents and permissions. -// When an error occurs, it terminates the test -func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.FileMode) string { - filePath := filepath.Join(dir, filename) - err := ioutil.WriteFile(filePath, []byte(contents), perm) - - if err != nil { - t.Fatalf("Error when creating %s file: %s", filename, err) - } - - return filePath -} - -// createTestSymlink creates a symlink file within dir which points to oldname -func createTestSymlink(t *testing.T, dir, filename, oldname string) string { - filePath := filepath.Join(dir, filename) - if err := os.Symlink(oldname, filePath); err != nil { - t.Fatalf("Error when creating %s symlink to %s: %s", filename, oldname, err) - } - - return filePath -} diff --git a/vendor/github.com/docker/docker/builder/dockerfile/wordsTest b/vendor/github.com/docker/docker/builder/dockerfile/wordsTest deleted file mode 100644 index fa916c6..0000000 --- a/vendor/github.com/docker/docker/builder/dockerfile/wordsTest +++ /dev/null @@ -1,25 +0,0 @@ -hello | hello -hello${hi}bye | hellobye -ENV hi=hi -hello${hi}bye | hellohibye -ENV space=abc def -hello${space}bye | helloabc,defbye -hello"${space}"bye | helloabc defbye -hello "${space}"bye | hello,abc defbye -ENV leading= ab c -hello${leading}def | hello,ab,cdef -hello"${leading}" def | hello ab c,def -hello"${leading}" | hello ab c -hello${leading} | hello,ab,c -# next line MUST have 3 trailing spaces, don't erase them! -ENV trailing=ab c -hello${trailing} | helloab,c -hello${trailing}d | helloab,c,d -hello"${trailing}"d | helloab c d -# next line MUST have 3 trailing spaces, don't erase them! -hel"lo${trailing}" | helloab c -hello" there " | hello there -hello there | hello,there -hello\ there | hello there -hello" there | hello there -hello\" there | hello",there diff --git a/vendor/github.com/docker/docker/builder/dockerignore.go b/vendor/github.com/docker/docker/builder/dockerignore.go deleted file mode 100644 index 3da7913..0000000 --- a/vendor/github.com/docker/docker/builder/dockerignore.go +++ /dev/null @@ -1,48 +0,0 @@ -package builder - -import ( - "os" - - "github.com/docker/docker/builder/dockerignore" - "github.com/docker/docker/pkg/fileutils" -) - -// DockerIgnoreContext wraps a ModifiableContext to add a method -// for handling the .dockerignore file at the root of the context. -type DockerIgnoreContext struct { - ModifiableContext -} - -// Process reads the .dockerignore file at the root of the embedded context. -// If .dockerignore does not exist in the context, then nil is returned. -// -// It can take a list of files to be removed after .dockerignore is removed. -// This is used for server-side implementations of builders that need to send -// the .dockerignore file as well as the special files specified in filesToRemove, -// but expect them to be excluded from the context after they were processed. -// -// For example, server-side Dockerfile builders are expected to pass in the name -// of the Dockerfile to be removed after it was parsed. -// -// TODO: Don't require a ModifiableContext (use Context instead) and don't remove -// files, instead handle a list of files to be excluded from the context. -func (c DockerIgnoreContext) Process(filesToRemove []string) error { - f, err := c.Open(".dockerignore") - // Note that a missing .dockerignore file isn't treated as an error - if err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - excludes, _ := dockerignore.ReadAll(f) - f.Close() - filesToRemove = append([]string{".dockerignore"}, filesToRemove...) - for _, fileToRemove := range filesToRemove { - rm, _ := fileutils.Matches(fileToRemove, excludes) - if rm { - c.Remove(fileToRemove) - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/builder/dockerignore/dockerignore.go b/vendor/github.com/docker/docker/builder/dockerignore/dockerignore.go deleted file mode 100644 index 2db67be..0000000 --- a/vendor/github.com/docker/docker/builder/dockerignore/dockerignore.go +++ /dev/null @@ -1,49 +0,0 @@ -package dockerignore - -import ( - "bufio" - "bytes" - "fmt" - "io" - "path/filepath" - "strings" -) - -// ReadAll reads a .dockerignore file and returns the list of file patterns -// to ignore. Note this will trim whitespace from each line as well -// as use GO's "clean" func to get the shortest/cleanest path for each. -func ReadAll(reader io.Reader) ([]string, error) { - if reader == nil { - return nil, nil - } - - scanner := bufio.NewScanner(reader) - var excludes []string - currentLine := 0 - - utf8bom := []byte{0xEF, 0xBB, 0xBF} - for scanner.Scan() { - scannedBytes := scanner.Bytes() - // We trim UTF8 BOM - if currentLine == 0 { - scannedBytes = bytes.TrimPrefix(scannedBytes, utf8bom) - } - pattern := string(scannedBytes) - currentLine++ - // Lines starting with # (comments) are ignored before processing - if strings.HasPrefix(pattern, "#") { - continue - } - pattern = strings.TrimSpace(pattern) - if pattern == "" { - continue - } - pattern = filepath.Clean(pattern) - pattern = filepath.ToSlash(pattern) - excludes = append(excludes, pattern) - } - if err := scanner.Err(); err != nil { - return nil, fmt.Errorf("Error reading .dockerignore: %v", err) - } - return excludes, nil -} diff --git a/vendor/github.com/docker/docker/builder/dockerignore/dockerignore_test.go b/vendor/github.com/docker/docker/builder/dockerignore/dockerignore_test.go deleted file mode 100644 index 612a139..0000000 --- a/vendor/github.com/docker/docker/builder/dockerignore/dockerignore_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package dockerignore - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func TestReadAll(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "dockerignore-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpDir) - - di, err := ReadAll(nil) - if err != nil { - t.Fatalf("Expected not to have error, got %v", err) - } - - if diLen := len(di); diLen != 0 { - t.Fatalf("Expected to have zero dockerignore entry, got %d", diLen) - } - - diName := filepath.Join(tmpDir, ".dockerignore") - content := fmt.Sprintf("test1\n/test2\n/a/file/here\n\nlastfile") - err = ioutil.WriteFile(diName, []byte(content), 0777) - if err != nil { - t.Fatal(err) - } - - diFd, err := os.Open(diName) - if err != nil { - t.Fatal(err) - } - defer diFd.Close() - - di, err = ReadAll(diFd) - if err != nil { - t.Fatal(err) - } - - if di[0] != "test1" { - t.Fatalf("First element is not test1") - } - if di[1] != "/test2" { - t.Fatalf("Second element is not /test2") - } - if di[2] != "/a/file/here" { - t.Fatalf("Third element is not /a/file/here") - } - if di[3] != "lastfile" { - t.Fatalf("Fourth element is not lastfile") - } -} diff --git a/vendor/github.com/docker/docker/builder/dockerignore_test.go b/vendor/github.com/docker/docker/builder/dockerignore_test.go deleted file mode 100644 index 3c0ceda..0000000 --- a/vendor/github.com/docker/docker/builder/dockerignore_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package builder - -import ( - "io/ioutil" - "log" - "os" - "sort" - "testing" -) - -const shouldStayFilename = "should_stay" - -func extractFilenames(files []os.FileInfo) []string { - filenames := make([]string, len(files), len(files)) - - for i, file := range files { - filenames[i] = file.Name() - } - - return filenames -} - -func checkDirectory(t *testing.T, dir string, expectedFiles []string) { - files, err := ioutil.ReadDir(dir) - - if err != nil { - t.Fatalf("Could not read directory: %s", err) - } - - if len(files) != len(expectedFiles) { - log.Fatalf("Directory should contain exactly %d file(s), got %d", len(expectedFiles), len(files)) - } - - filenames := extractFilenames(files) - sort.Strings(filenames) - sort.Strings(expectedFiles) - - for i, filename := range filenames { - if filename != expectedFiles[i] { - t.Fatalf("File %s should be in the directory, got: %s", expectedFiles[i], filename) - } - } -} - -func executeProcess(t *testing.T, contextDir string) { - modifiableCtx := &tarSumContext{root: contextDir} - ctx := DockerIgnoreContext{ModifiableContext: modifiableCtx} - - err := ctx.Process([]string{DefaultDockerfileName}) - - if err != nil { - t.Fatalf("Error when executing Process: %s", err) - } -} - -func TestProcessShouldRemoveDockerfileDockerignore(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-dockerignore-process-test") - defer cleanup() - - createTestTempFile(t, contextDir, shouldStayFilename, testfileContents, 0777) - createTestTempFile(t, contextDir, dockerignoreFilename, "Dockerfile\n.dockerignore", 0777) - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - - executeProcess(t, contextDir) - - checkDirectory(t, contextDir, []string{shouldStayFilename}) - -} - -func TestProcessNoDockerignore(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-dockerignore-process-test") - defer cleanup() - - createTestTempFile(t, contextDir, shouldStayFilename, testfileContents, 0777) - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - - executeProcess(t, contextDir) - - checkDirectory(t, contextDir, []string{shouldStayFilename, DefaultDockerfileName}) - -} - -func TestProcessShouldLeaveAllFiles(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-dockerignore-process-test") - defer cleanup() - - createTestTempFile(t, contextDir, shouldStayFilename, testfileContents, 0777) - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - createTestTempFile(t, contextDir, dockerignoreFilename, "input1\ninput2", 0777) - - executeProcess(t, contextDir) - - checkDirectory(t, contextDir, []string{shouldStayFilename, DefaultDockerfileName, dockerignoreFilename}) - -} diff --git a/vendor/github.com/docker/docker/builder/git.go b/vendor/github.com/docker/docker/builder/git.go deleted file mode 100644 index 74df244..0000000 --- a/vendor/github.com/docker/docker/builder/git.go +++ /dev/null @@ -1,28 +0,0 @@ -package builder - -import ( - "os" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/gitutils" -) - -// MakeGitContext returns a Context from gitURL that is cloned in a temporary directory. -func MakeGitContext(gitURL string) (ModifiableContext, error) { - root, err := gitutils.Clone(gitURL) - if err != nil { - return nil, err - } - - c, err := archive.Tar(root, archive.Uncompressed) - if err != nil { - return nil, err - } - - defer func() { - // TODO: print errors? - c.Close() - os.RemoveAll(root) - }() - return MakeTarSumContext(c) -} diff --git a/vendor/github.com/docker/docker/builder/remote.go b/vendor/github.com/docker/docker/builder/remote.go deleted file mode 100644 index f3a4329..0000000 --- a/vendor/github.com/docker/docker/builder/remote.go +++ /dev/null @@ -1,157 +0,0 @@ -package builder - -import ( - "bytes" - "errors" - "fmt" - "io" - "io/ioutil" - "regexp" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/httputils" - "github.com/docker/docker/pkg/urlutil" -) - -// When downloading remote contexts, limit the amount (in bytes) -// to be read from the response body in order to detect its Content-Type -const maxPreambleLength = 100 - -const acceptableRemoteMIME = `(?:application/(?:(?:x\-)?tar|octet\-stream|((?:x\-)?(?:gzip|bzip2?|xz)))|(?:text/plain))` - -var mimeRe = regexp.MustCompile(acceptableRemoteMIME) - -// MakeRemoteContext downloads a context from remoteURL and returns it. -// -// If contentTypeHandlers is non-nil, then the Content-Type header is read along with a maximum of -// maxPreambleLength bytes from the body to help detecting the MIME type. -// Look at acceptableRemoteMIME for more details. -// -// If a match is found, then the body is sent to the contentType handler and a (potentially compressed) tar stream is expected -// to be returned. If no match is found, it is assumed the body is a tar stream (compressed or not). -// In either case, an (assumed) tar stream is passed to MakeTarSumContext whose result is returned. -func MakeRemoteContext(remoteURL string, contentTypeHandlers map[string]func(io.ReadCloser) (io.ReadCloser, error)) (ModifiableContext, error) { - f, err := httputils.Download(remoteURL) - if err != nil { - return nil, fmt.Errorf("error downloading remote context %s: %v", remoteURL, err) - } - defer f.Body.Close() - - var contextReader io.ReadCloser - if contentTypeHandlers != nil { - contentType := f.Header.Get("Content-Type") - clen := f.ContentLength - - contentType, contextReader, err = inspectResponse(contentType, f.Body, clen) - if err != nil { - return nil, fmt.Errorf("error detecting content type for remote %s: %v", remoteURL, err) - } - defer contextReader.Close() - - // This loop tries to find a content-type handler for the detected content-type. - // If it could not find one from the caller-supplied map, it tries the empty content-type `""` - // which is interpreted as a fallback handler (usually used for raw tar contexts). - for _, ct := range []string{contentType, ""} { - if fn, ok := contentTypeHandlers[ct]; ok { - defer contextReader.Close() - if contextReader, err = fn(contextReader); err != nil { - return nil, err - } - break - } - } - } - - // Pass through - this is a pre-packaged context, presumably - // with a Dockerfile with the right name inside it. - return MakeTarSumContext(contextReader) -} - -// DetectContextFromRemoteURL returns a context and in certain cases the name of the dockerfile to be used -// irrespective of user input. -// progressReader is only used if remoteURL is actually a URL (not empty, and not a Git endpoint). -func DetectContextFromRemoteURL(r io.ReadCloser, remoteURL string, createProgressReader func(in io.ReadCloser) io.ReadCloser) (context ModifiableContext, dockerfileName string, err error) { - switch { - case remoteURL == "": - context, err = MakeTarSumContext(r) - case urlutil.IsGitURL(remoteURL): - context, err = MakeGitContext(remoteURL) - case urlutil.IsURL(remoteURL): - context, err = MakeRemoteContext(remoteURL, map[string]func(io.ReadCloser) (io.ReadCloser, error){ - httputils.MimeTypes.TextPlain: func(rc io.ReadCloser) (io.ReadCloser, error) { - dockerfile, err := ioutil.ReadAll(rc) - if err != nil { - return nil, err - } - - // dockerfileName is set to signal that the remote was interpreted as a single Dockerfile, in which case the caller - // should use dockerfileName as the new name for the Dockerfile, irrespective of any other user input. - dockerfileName = DefaultDockerfileName - - // TODO: return a context without tarsum - r, err := archive.Generate(dockerfileName, string(dockerfile)) - if err != nil { - return nil, err - } - - return ioutil.NopCloser(r), nil - }, - // fallback handler (tar context) - "": func(rc io.ReadCloser) (io.ReadCloser, error) { - return createProgressReader(rc), nil - }, - }) - default: - err = fmt.Errorf("remoteURL (%s) could not be recognized as URL", remoteURL) - } - return -} - -// inspectResponse looks into the http response data at r to determine whether its -// content-type is on the list of acceptable content types for remote build contexts. -// This function returns: -// - a string representation of the detected content-type -// - an io.Reader for the response body -// - an error value which will be non-nil either when something goes wrong while -// reading bytes from r or when the detected content-type is not acceptable. -func inspectResponse(ct string, r io.ReadCloser, clen int64) (string, io.ReadCloser, error) { - plen := clen - if plen <= 0 || plen > maxPreambleLength { - plen = maxPreambleLength - } - - preamble := make([]byte, plen, plen) - rlen, err := r.Read(preamble) - if rlen == 0 { - return ct, r, errors.New("empty response") - } - if err != nil && err != io.EOF { - return ct, r, err - } - - preambleR := bytes.NewReader(preamble) - bodyReader := ioutil.NopCloser(io.MultiReader(preambleR, r)) - // Some web servers will use application/octet-stream as the default - // content type for files without an extension (e.g. 'Dockerfile') - // so if we receive this value we better check for text content - contentType := ct - if len(ct) == 0 || ct == httputils.MimeTypes.OctetStream { - contentType, _, err = httputils.DetectContentType(preamble) - if err != nil { - return contentType, bodyReader, err - } - } - - contentType = selectAcceptableMIME(contentType) - var cterr error - if len(contentType) == 0 { - cterr = fmt.Errorf("unsupported Content-Type %q", ct) - contentType = ct - } - - return contentType, bodyReader, cterr -} - -func selectAcceptableMIME(ct string) string { - return mimeRe.FindString(ct) -} diff --git a/vendor/github.com/docker/docker/builder/remote_test.go b/vendor/github.com/docker/docker/builder/remote_test.go deleted file mode 100644 index 691a084..0000000 --- a/vendor/github.com/docker/docker/builder/remote_test.go +++ /dev/null @@ -1,213 +0,0 @@ -package builder - -import ( - "bytes" - "io" - "io/ioutil" - "net/http" - "net/http/httptest" - "net/url" - "testing" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/httputils" -) - -var binaryContext = []byte{0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00} //xz magic - -func TestSelectAcceptableMIME(t *testing.T) { - validMimeStrings := []string{ - "application/x-bzip2", - "application/bzip2", - "application/gzip", - "application/x-gzip", - "application/x-xz", - "application/xz", - "application/tar", - "application/x-tar", - "application/octet-stream", - "text/plain", - } - - invalidMimeStrings := []string{ - "", - "application/octet", - "application/json", - } - - for _, m := range invalidMimeStrings { - if len(selectAcceptableMIME(m)) > 0 { - t.Fatalf("Should not have accepted %q", m) - } - } - - for _, m := range validMimeStrings { - if str := selectAcceptableMIME(m); str == "" { - t.Fatalf("Should have accepted %q", m) - } - } -} - -func TestInspectEmptyResponse(t *testing.T) { - ct := "application/octet-stream" - br := ioutil.NopCloser(bytes.NewReader([]byte(""))) - contentType, bReader, err := inspectResponse(ct, br, 0) - if err == nil { - t.Fatalf("Should have generated an error for an empty response") - } - if contentType != "application/octet-stream" { - t.Fatalf("Content type should be 'application/octet-stream' but is %q", contentType) - } - body, err := ioutil.ReadAll(bReader) - if err != nil { - t.Fatal(err) - } - if len(body) != 0 { - t.Fatal("response body should remain empty") - } -} - -func TestInspectResponseBinary(t *testing.T) { - ct := "application/octet-stream" - br := ioutil.NopCloser(bytes.NewReader(binaryContext)) - contentType, bReader, err := inspectResponse(ct, br, int64(len(binaryContext))) - if err != nil { - t.Fatal(err) - } - if contentType != "application/octet-stream" { - t.Fatalf("Content type should be 'application/octet-stream' but is %q", contentType) - } - body, err := ioutil.ReadAll(bReader) - if err != nil { - t.Fatal(err) - } - if len(body) != len(binaryContext) { - t.Fatalf("Wrong response size %d, should be == len(binaryContext)", len(body)) - } - for i := range body { - if body[i] != binaryContext[i] { - t.Fatalf("Corrupted response body at byte index %d", i) - } - } -} - -func TestResponseUnsupportedContentType(t *testing.T) { - content := []byte(dockerfileContents) - ct := "application/json" - br := ioutil.NopCloser(bytes.NewReader(content)) - contentType, bReader, err := inspectResponse(ct, br, int64(len(dockerfileContents))) - - if err == nil { - t.Fatal("Should have returned an error on content-type 'application/json'") - } - if contentType != ct { - t.Fatalf("Should not have altered content-type: orig: %s, altered: %s", ct, contentType) - } - body, err := ioutil.ReadAll(bReader) - if err != nil { - t.Fatal(err) - } - if string(body) != dockerfileContents { - t.Fatalf("Corrupted response body %s", body) - } -} - -func TestInspectResponseTextSimple(t *testing.T) { - content := []byte(dockerfileContents) - ct := "text/plain" - br := ioutil.NopCloser(bytes.NewReader(content)) - contentType, bReader, err := inspectResponse(ct, br, int64(len(content))) - if err != nil { - t.Fatal(err) - } - if contentType != "text/plain" { - t.Fatalf("Content type should be 'text/plain' but is %q", contentType) - } - body, err := ioutil.ReadAll(bReader) - if err != nil { - t.Fatal(err) - } - if string(body) != dockerfileContents { - t.Fatalf("Corrupted response body %s", body) - } -} - -func TestInspectResponseEmptyContentType(t *testing.T) { - content := []byte(dockerfileContents) - br := ioutil.NopCloser(bytes.NewReader(content)) - contentType, bodyReader, err := inspectResponse("", br, int64(len(content))) - if err != nil { - t.Fatal(err) - } - if contentType != "text/plain" { - t.Fatalf("Content type should be 'text/plain' but is %q", contentType) - } - body, err := ioutil.ReadAll(bodyReader) - if err != nil { - t.Fatal(err) - } - if string(body) != dockerfileContents { - t.Fatalf("Corrupted response body %s", body) - } -} - -func TestMakeRemoteContext(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") - defer cleanup() - - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - - mux := http.NewServeMux() - server := httptest.NewServer(mux) - serverURL, _ := url.Parse(server.URL) - - serverURL.Path = "/" + DefaultDockerfileName - remoteURL := serverURL.String() - - mux.Handle("/", http.FileServer(http.Dir(contextDir))) - - remoteContext, err := MakeRemoteContext(remoteURL, map[string]func(io.ReadCloser) (io.ReadCloser, error){ - httputils.MimeTypes.TextPlain: func(rc io.ReadCloser) (io.ReadCloser, error) { - dockerfile, err := ioutil.ReadAll(rc) - if err != nil { - return nil, err - } - - r, err := archive.Generate(DefaultDockerfileName, string(dockerfile)) - if err != nil { - return nil, err - } - return ioutil.NopCloser(r), nil - }, - }) - - if err != nil { - t.Fatalf("Error when executing DetectContextFromRemoteURL: %s", err) - } - - if remoteContext == nil { - t.Fatalf("Remote context should not be nil") - } - - tarSumCtx, ok := remoteContext.(*tarSumContext) - - if !ok { - t.Fatalf("Cast error, remote context should be casted to tarSumContext") - } - - fileInfoSums := tarSumCtx.sums - - if fileInfoSums.Len() != 1 { - t.Fatalf("Size of file info sums should be 1, got: %d", fileInfoSums.Len()) - } - - fileInfo := fileInfoSums.GetFile(DefaultDockerfileName) - - if fileInfo == nil { - t.Fatalf("There should be file named %s in fileInfoSums", DefaultDockerfileName) - } - - if fileInfo.Pos() != 0 { - t.Fatalf("File %s should have position 0, got %d", DefaultDockerfileName, fileInfo.Pos()) - } -} diff --git a/vendor/github.com/docker/docker/builder/tarsum.go b/vendor/github.com/docker/docker/builder/tarsum.go deleted file mode 100644 index 35054dc..0000000 --- a/vendor/github.com/docker/docker/builder/tarsum.go +++ /dev/null @@ -1,158 +0,0 @@ -package builder - -import ( - "fmt" - "io" - "os" - "path/filepath" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/chrootarchive" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/symlink" - "github.com/docker/docker/pkg/tarsum" -) - -type tarSumContext struct { - root string - sums tarsum.FileInfoSums -} - -func (c *tarSumContext) Close() error { - return os.RemoveAll(c.root) -} - -func convertPathError(err error, cleanpath string) error { - if err, ok := err.(*os.PathError); ok { - err.Path = cleanpath - return err - } - return err -} - -func (c *tarSumContext) Open(path string) (io.ReadCloser, error) { - cleanpath, fullpath, err := c.normalize(path) - if err != nil { - return nil, err - } - r, err := os.Open(fullpath) - if err != nil { - return nil, convertPathError(err, cleanpath) - } - return r, nil -} - -func (c *tarSumContext) Stat(path string) (string, FileInfo, error) { - cleanpath, fullpath, err := c.normalize(path) - if err != nil { - return "", nil, err - } - - st, err := os.Lstat(fullpath) - if err != nil { - return "", nil, convertPathError(err, cleanpath) - } - - rel, err := filepath.Rel(c.root, fullpath) - if err != nil { - return "", nil, convertPathError(err, cleanpath) - } - - // We set sum to path by default for the case where GetFile returns nil. - // The usual case is if relative path is empty. - sum := path - // Use the checksum of the followed path(not the possible symlink) because - // this is the file that is actually copied. - if tsInfo := c.sums.GetFile(filepath.ToSlash(rel)); tsInfo != nil { - sum = tsInfo.Sum() - } - fi := &HashedFileInfo{PathFileInfo{st, fullpath, filepath.Base(cleanpath)}, sum} - return rel, fi, nil -} - -// MakeTarSumContext returns a build Context from a tar stream. -// -// It extracts the tar stream to a temporary folder that is deleted as soon as -// the Context is closed. -// As the extraction happens, a tarsum is calculated for every file, and the set of -// all those sums then becomes the source of truth for all operations on this Context. -// -// Closing tarStream has to be done by the caller. -func MakeTarSumContext(tarStream io.Reader) (ModifiableContext, error) { - root, err := ioutils.TempDir("", "docker-builder") - if err != nil { - return nil, err - } - - tsc := &tarSumContext{root: root} - - // Make sure we clean-up upon error. In the happy case the caller - // is expected to manage the clean-up - defer func() { - if err != nil { - tsc.Close() - } - }() - - decompressedStream, err := archive.DecompressStream(tarStream) - if err != nil { - return nil, err - } - - sum, err := tarsum.NewTarSum(decompressedStream, true, tarsum.Version1) - if err != nil { - return nil, err - } - - if err := chrootarchive.Untar(sum, root, nil); err != nil { - return nil, err - } - - tsc.sums = sum.GetSums() - - return tsc, nil -} - -func (c *tarSumContext) normalize(path string) (cleanpath, fullpath string, err error) { - cleanpath = filepath.Clean(string(os.PathSeparator) + path)[1:] - fullpath, err = symlink.FollowSymlinkInScope(filepath.Join(c.root, path), c.root) - if err != nil { - return "", "", fmt.Errorf("Forbidden path outside the build context: %s (%s)", path, fullpath) - } - _, err = os.Lstat(fullpath) - if err != nil { - return "", "", convertPathError(err, path) - } - return -} - -func (c *tarSumContext) Walk(root string, walkFn WalkFunc) error { - root = filepath.Join(c.root, filepath.Join(string(filepath.Separator), root)) - return filepath.Walk(root, func(fullpath string, info os.FileInfo, err error) error { - rel, err := filepath.Rel(c.root, fullpath) - if err != nil { - return err - } - if rel == "." { - return nil - } - - sum := rel - if tsInfo := c.sums.GetFile(filepath.ToSlash(rel)); tsInfo != nil { - sum = tsInfo.Sum() - } - fi := &HashedFileInfo{PathFileInfo{FileInfo: info, FilePath: fullpath}, sum} - if err := walkFn(rel, fi, nil); err != nil { - return err - } - return nil - }) -} - -func (c *tarSumContext) Remove(path string) error { - _, fullpath, err := c.normalize(path) - if err != nil { - return err - } - return os.RemoveAll(fullpath) -} diff --git a/vendor/github.com/docker/docker/builder/tarsum_test.go b/vendor/github.com/docker/docker/builder/tarsum_test.go deleted file mode 100644 index 278e583..0000000 --- a/vendor/github.com/docker/docker/builder/tarsum_test.go +++ /dev/null @@ -1,265 +0,0 @@ -package builder - -import ( - "bufio" - "bytes" - "io/ioutil" - "os" - "path/filepath" - "testing" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/reexec" -) - -const ( - filename = "test" - contents = "contents test" -) - -func init() { - reexec.Init() -} - -func TestCloseRootDirectory(t *testing.T) { - contextDir, err := ioutil.TempDir("", "builder-tarsum-test") - - if err != nil { - t.Fatalf("Error with creating temporary directory: %s", err) - } - - tarsum := &tarSumContext{root: contextDir} - - err = tarsum.Close() - - if err != nil { - t.Fatalf("Error while executing Close: %s", err) - } - - _, err = os.Stat(contextDir) - - if !os.IsNotExist(err) { - t.Fatalf("Directory should not exist at this point") - defer os.RemoveAll(contextDir) - } -} - -func TestOpenFile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") - defer cleanup() - - createTestTempFile(t, contextDir, filename, contents, 0777) - - tarSum := &tarSumContext{root: contextDir} - - file, err := tarSum.Open(filename) - - if err != nil { - t.Fatalf("Error when executing Open: %s", err) - } - - defer file.Close() - - scanner := bufio.NewScanner(file) - buff := bytes.NewBufferString("") - - for scanner.Scan() { - buff.WriteString(scanner.Text()) - } - - if contents != buff.String() { - t.Fatalf("Contents are not equal. Expected: %s, got: %s", contents, buff.String()) - } - -} - -func TestOpenNotExisting(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") - defer cleanup() - - tarSum := &tarSumContext{root: contextDir} - - file, err := tarSum.Open("not-existing") - - if file != nil { - t.Fatal("Opened file should be nil") - } - - if !os.IsNotExist(err) { - t.Fatalf("Error when executing Open: %s", err) - } -} - -func TestStatFile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") - defer cleanup() - - testFilename := createTestTempFile(t, contextDir, filename, contents, 0777) - - tarSum := &tarSumContext{root: contextDir} - - relPath, fileInfo, err := tarSum.Stat(filename) - - if err != nil { - t.Fatalf("Error when executing Stat: %s", err) - } - - if relPath != filename { - t.Fatalf("Relative path should be equal to %s, got %s", filename, relPath) - } - - if fileInfo.Path() != testFilename { - t.Fatalf("Full path should be equal to %s, got %s", testFilename, fileInfo.Path()) - } -} - -func TestStatSubdir(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") - defer cleanup() - - contextSubdir := createTestTempSubdir(t, contextDir, "builder-tarsum-test-subdir") - - testFilename := createTestTempFile(t, contextSubdir, filename, contents, 0777) - - tarSum := &tarSumContext{root: contextDir} - - relativePath, err := filepath.Rel(contextDir, testFilename) - - if err != nil { - t.Fatalf("Error when getting relative path: %s", err) - } - - relPath, fileInfo, err := tarSum.Stat(relativePath) - - if err != nil { - t.Fatalf("Error when executing Stat: %s", err) - } - - if relPath != relativePath { - t.Fatalf("Relative path should be equal to %s, got %s", relativePath, relPath) - } - - if fileInfo.Path() != testFilename { - t.Fatalf("Full path should be equal to %s, got %s", testFilename, fileInfo.Path()) - } -} - -func TestStatNotExisting(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") - defer cleanup() - - tarSum := &tarSumContext{root: contextDir} - - relPath, fileInfo, err := tarSum.Stat("not-existing") - - if relPath != "" { - t.Fatal("Relative path should be nil") - } - - if fileInfo != nil { - t.Fatalf("File info should be nil") - } - - if !os.IsNotExist(err) { - t.Fatalf("This file should not exist: %s", err) - } -} - -func TestRemoveDirectory(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") - defer cleanup() - - contextSubdir := createTestTempSubdir(t, contextDir, "builder-tarsum-test-subdir") - - relativePath, err := filepath.Rel(contextDir, contextSubdir) - - if err != nil { - t.Fatalf("Error when getting relative path: %s", err) - } - - tarSum := &tarSumContext{root: contextDir} - - err = tarSum.Remove(relativePath) - - if err != nil { - t.Fatalf("Error when executing Remove: %s", err) - } - - _, err = os.Stat(contextSubdir) - - if !os.IsNotExist(err) { - t.Fatalf("Directory should not exist at this point") - } -} - -func TestMakeTarSumContext(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") - defer cleanup() - - createTestTempFile(t, contextDir, filename, contents, 0777) - - tarStream, err := archive.Tar(contextDir, archive.Uncompressed) - - if err != nil { - t.Fatalf("error: %s", err) - } - - defer tarStream.Close() - - tarSum, err := MakeTarSumContext(tarStream) - - if err != nil { - t.Fatalf("Error when executing MakeTarSumContext: %s", err) - } - - if tarSum == nil { - t.Fatalf("Tar sum context should not be nil") - } -} - -func TestWalkWithoutError(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") - defer cleanup() - - contextSubdir := createTestTempSubdir(t, contextDir, "builder-tarsum-test-subdir") - - createTestTempFile(t, contextSubdir, filename, contents, 0777) - - tarSum := &tarSumContext{root: contextDir} - - walkFun := func(path string, fi FileInfo, err error) error { - return nil - } - - err := tarSum.Walk(contextSubdir, walkFun) - - if err != nil { - t.Fatalf("Error when executing Walk: %s", err) - } -} - -type WalkError struct { -} - -func (we WalkError) Error() string { - return "Error when executing Walk" -} - -func TestWalkWithError(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test") - defer cleanup() - - contextSubdir := createTestTempSubdir(t, contextDir, "builder-tarsum-test-subdir") - - tarSum := &tarSumContext{root: contextDir} - - walkFun := func(path string, fi FileInfo, err error) error { - return WalkError{} - } - - err := tarSum.Walk(contextSubdir, walkFun) - - if err == nil { - t.Fatalf("Error should not be nil") - } -} diff --git a/vendor/github.com/docker/docker/builder/utils_test.go b/vendor/github.com/docker/docker/builder/utils_test.go deleted file mode 100644 index 1101ff1..0000000 --- a/vendor/github.com/docker/docker/builder/utils_test.go +++ /dev/null @@ -1,87 +0,0 @@ -package builder - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -const ( - dockerfileContents = "FROM busybox" - dockerignoreFilename = ".dockerignore" - testfileContents = "test" -) - -// createTestTempDir creates a temporary directory for testing. -// It returns the created path and a cleanup function which is meant to be used as deferred call. -// When an error occurs, it terminates the test. -func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) { - path, err := ioutil.TempDir(dir, prefix) - - if err != nil { - t.Fatalf("Error when creating directory %s with prefix %s: %s", dir, prefix, err) - } - - return path, func() { - err = os.RemoveAll(path) - - if err != nil { - t.Fatalf("Error when removing directory %s: %s", path, err) - } - } -} - -// createTestTempSubdir creates a temporary directory for testing. -// It returns the created path but doesn't provide a cleanup function, -// so createTestTempSubdir should be used only for creating temporary subdirectories -// whose parent directories are properly cleaned up. -// When an error occurs, it terminates the test. -func createTestTempSubdir(t *testing.T, dir, prefix string) string { - path, err := ioutil.TempDir(dir, prefix) - - if err != nil { - t.Fatalf("Error when creating directory %s with prefix %s: %s", dir, prefix, err) - } - - return path -} - -// createTestTempFile creates a temporary file within dir with specific contents and permissions. -// When an error occurs, it terminates the test -func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.FileMode) string { - filePath := filepath.Join(dir, filename) - err := ioutil.WriteFile(filePath, []byte(contents), perm) - - if err != nil { - t.Fatalf("Error when creating %s file: %s", filename, err) - } - - return filePath -} - -// chdir changes current working directory to dir. -// It returns a function which changes working directory back to the previous one. -// This function is meant to be executed as a deferred call. -// When an error occurs, it terminates the test. -func chdir(t *testing.T, dir string) func() { - workingDirectory, err := os.Getwd() - - if err != nil { - t.Fatalf("Error when retrieving working directory: %s", err) - } - - err = os.Chdir(dir) - - if err != nil { - t.Fatalf("Error when changing directory to %s: %s", dir, err) - } - - return func() { - err = os.Chdir(workingDirectory) - - if err != nil { - t.Fatalf("Error when changing back to working directory (%s): %s", workingDirectory, err) - } - } -} diff --git a/vendor/github.com/docker/docker/cli/cobra.go b/vendor/github.com/docker/docker/cli/cobra.go deleted file mode 100644 index 139845c..0000000 --- a/vendor/github.com/docker/docker/cli/cobra.go +++ /dev/null @@ -1,139 +0,0 @@ -package cli - -import ( - "fmt" - "strings" - - "github.com/spf13/cobra" -) - -// SetupRootCommand sets default usage, help, and error handling for the -// root command. -func SetupRootCommand(rootCmd *cobra.Command) { - cobra.AddTemplateFunc("hasSubCommands", hasSubCommands) - cobra.AddTemplateFunc("hasManagementSubCommands", hasManagementSubCommands) - cobra.AddTemplateFunc("operationSubCommands", operationSubCommands) - cobra.AddTemplateFunc("managementSubCommands", managementSubCommands) - - rootCmd.SetUsageTemplate(usageTemplate) - rootCmd.SetHelpTemplate(helpTemplate) - rootCmd.SetFlagErrorFunc(FlagErrorFunc) - rootCmd.SetHelpCommand(helpCommand) - - rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage") - rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help") -} - -// FlagErrorFunc prints an error message which matches the format of the -// docker/docker/cli error messages -func FlagErrorFunc(cmd *cobra.Command, err error) error { - if err == nil { - return err - } - - usage := "" - if cmd.HasSubCommands() { - usage = "\n\n" + cmd.UsageString() - } - return StatusError{ - Status: fmt.Sprintf("%s\nSee '%s --help'.%s", err, cmd.CommandPath(), usage), - StatusCode: 125, - } -} - -var helpCommand = &cobra.Command{ - Use: "help [command]", - Short: "Help about the command", - PersistentPreRun: func(cmd *cobra.Command, args []string) {}, - PersistentPostRun: func(cmd *cobra.Command, args []string) {}, - RunE: func(c *cobra.Command, args []string) error { - cmd, args, e := c.Root().Find(args) - if cmd == nil || e != nil || len(args) > 0 { - return fmt.Errorf("unknown help topic: %v", strings.Join(args, " ")) - } - - helpFunc := cmd.HelpFunc() - helpFunc(cmd, args) - return nil - }, -} - -func hasSubCommands(cmd *cobra.Command) bool { - return len(operationSubCommands(cmd)) > 0 -} - -func hasManagementSubCommands(cmd *cobra.Command) bool { - return len(managementSubCommands(cmd)) > 0 -} - -func operationSubCommands(cmd *cobra.Command) []*cobra.Command { - cmds := []*cobra.Command{} - for _, sub := range cmd.Commands() { - if sub.IsAvailableCommand() && !sub.HasSubCommands() { - cmds = append(cmds, sub) - } - } - return cmds -} - -func managementSubCommands(cmd *cobra.Command) []*cobra.Command { - cmds := []*cobra.Command{} - for _, sub := range cmd.Commands() { - if sub.IsAvailableCommand() && sub.HasSubCommands() { - cmds = append(cmds, sub) - } - } - return cmds -} - -var usageTemplate = `Usage: - -{{- if not .HasSubCommands}} {{.UseLine}}{{end}} -{{- if .HasSubCommands}} {{ .CommandPath}} COMMAND{{end}} - -{{ .Short | trim }} - -{{- if gt .Aliases 0}} - -Aliases: - {{.NameAndAliases}} - -{{- end}} -{{- if .HasExample}} - -Examples: -{{ .Example }} - -{{- end}} -{{- if .HasFlags}} - -Options: -{{.Flags.FlagUsages | trimRightSpace}} - -{{- end}} -{{- if hasManagementSubCommands . }} - -Management Commands: - -{{- range managementSubCommands . }} - {{rpad .Name .NamePadding }} {{.Short}} -{{- end}} - -{{- end}} -{{- if hasSubCommands .}} - -Commands: - -{{- range operationSubCommands . }} - {{rpad .Name .NamePadding }} {{.Short}} -{{- end}} -{{- end}} - -{{- if .HasSubCommands }} - -Run '{{.CommandPath}} COMMAND --help' for more information on a command. -{{- end}} -` - -var helpTemplate = ` -{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}` diff --git a/vendor/github.com/docker/docker/cli/command/bundlefile/bundlefile.go b/vendor/github.com/docker/docker/cli/command/bundlefile/bundlefile.go deleted file mode 100644 index 7fd1e4f..0000000 --- a/vendor/github.com/docker/docker/cli/command/bundlefile/bundlefile.go +++ /dev/null @@ -1,69 +0,0 @@ -package bundlefile - -import ( - "encoding/json" - "fmt" - "io" -) - -// Bundlefile stores the contents of a bundlefile -type Bundlefile struct { - Version string - Services map[string]Service -} - -// Service is a service from a bundlefile -type Service struct { - Image string - Command []string `json:",omitempty"` - Args []string `json:",omitempty"` - Env []string `json:",omitempty"` - Labels map[string]string `json:",omitempty"` - Ports []Port `json:",omitempty"` - WorkingDir *string `json:",omitempty"` - User *string `json:",omitempty"` - Networks []string `json:",omitempty"` -} - -// Port is a port as defined in a bundlefile -type Port struct { - Protocol string - Port uint32 -} - -// LoadFile loads a bundlefile from a path to the file -func LoadFile(reader io.Reader) (*Bundlefile, error) { - bundlefile := &Bundlefile{} - - decoder := json.NewDecoder(reader) - if err := decoder.Decode(bundlefile); err != nil { - switch jsonErr := err.(type) { - case *json.SyntaxError: - return nil, fmt.Errorf( - "JSON syntax error at byte %v: %s", - jsonErr.Offset, - jsonErr.Error()) - case *json.UnmarshalTypeError: - return nil, fmt.Errorf( - "Unexpected type at byte %v. Expected %s but received %s.", - jsonErr.Offset, - jsonErr.Type, - jsonErr.Value) - } - return nil, err - } - - return bundlefile, nil -} - -// Print writes the contents of the bundlefile to the output writer -// as human readable json -func Print(out io.Writer, bundle *Bundlefile) error { - bytes, err := json.MarshalIndent(*bundle, "", " ") - if err != nil { - return err - } - - _, err = out.Write(bytes) - return err -} diff --git a/vendor/github.com/docker/docker/cli/command/bundlefile/bundlefile_test.go b/vendor/github.com/docker/docker/cli/command/bundlefile/bundlefile_test.go deleted file mode 100644 index c343410..0000000 --- a/vendor/github.com/docker/docker/cli/command/bundlefile/bundlefile_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package bundlefile - -import ( - "bytes" - "strings" - "testing" - - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestLoadFileV01Success(t *testing.T) { - reader := strings.NewReader(`{ - "Version": "0.1", - "Services": { - "redis": { - "Image": "redis@sha256:4b24131101fa0117bcaa18ac37055fffd9176aa1a240392bb8ea85e0be50f2ce", - "Networks": ["default"] - }, - "web": { - "Image": "dockercloud/hello-world@sha256:fe79a2cfbd17eefc344fb8419420808df95a1e22d93b7f621a7399fd1e9dca1d", - "Networks": ["default"], - "User": "web" - } - } - }`) - - bundle, err := LoadFile(reader) - assert.NilError(t, err) - assert.Equal(t, bundle.Version, "0.1") - assert.Equal(t, len(bundle.Services), 2) -} - -func TestLoadFileSyntaxError(t *testing.T) { - reader := strings.NewReader(`{ - "Version": "0.1", - "Services": unquoted string - }`) - - _, err := LoadFile(reader) - assert.Error(t, err, "syntax error at byte 37: invalid character 'u'") -} - -func TestLoadFileTypeError(t *testing.T) { - reader := strings.NewReader(`{ - "Version": "0.1", - "Services": { - "web": { - "Image": "redis", - "Networks": "none" - } - } - }`) - - _, err := LoadFile(reader) - assert.Error(t, err, "Unexpected type at byte 94. Expected []string but received string") -} - -func TestPrint(t *testing.T) { - var buffer bytes.Buffer - bundle := &Bundlefile{ - Version: "0.1", - Services: map[string]Service{ - "web": { - Image: "image", - Command: []string{"echo", "something"}, - }, - }, - } - assert.NilError(t, Print(&buffer, bundle)) - output := buffer.String() - assert.Contains(t, output, "\"Image\": \"image\"") - assert.Contains(t, output, - `"Command": [ - "echo", - "something" - ]`) -} diff --git a/vendor/github.com/docker/docker/cli/command/checkpoint/cmd.go b/vendor/github.com/docker/docker/cli/command/checkpoint/cmd.go deleted file mode 100644 index d5705a4..0000000 --- a/vendor/github.com/docker/docker/cli/command/checkpoint/cmd.go +++ /dev/null @@ -1,24 +0,0 @@ -package checkpoint - -import ( - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -// NewCheckpointCommand returns the `checkpoint` subcommand (only in experimental) -func NewCheckpointCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "checkpoint", - Short: "Manage checkpoints", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - Tags: map[string]string{"experimental": "", "version": "1.25"}, - } - cmd.AddCommand( - newCreateCommand(dockerCli), - newListCommand(dockerCli), - newRemoveCommand(dockerCli), - ) - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/checkpoint/create.go b/vendor/github.com/docker/docker/cli/command/checkpoint/create.go deleted file mode 100644 index 473a941..0000000 --- a/vendor/github.com/docker/docker/cli/command/checkpoint/create.go +++ /dev/null @@ -1,58 +0,0 @@ -package checkpoint - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type createOptions struct { - container string - checkpoint string - checkpointDir string - leaveRunning bool -} - -func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts createOptions - - cmd := &cobra.Command{ - Use: "create [OPTIONS] CONTAINER CHECKPOINT", - Short: "Create a checkpoint from a running container", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - opts.checkpoint = args[1] - return runCreate(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.BoolVar(&opts.leaveRunning, "leave-running", false, "Leave the container running after checkpoint") - flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "Use a custom checkpoint storage directory") - - return cmd -} - -func runCreate(dockerCli *command.DockerCli, opts createOptions) error { - client := dockerCli.Client() - - checkpointOpts := types.CheckpointCreateOptions{ - CheckpointID: opts.checkpoint, - CheckpointDir: opts.checkpointDir, - Exit: !opts.leaveRunning, - } - - err := client.CheckpointCreate(context.Background(), opts.container, checkpointOpts) - if err != nil { - return err - } - - fmt.Fprintf(dockerCli.Out(), "%s\n", opts.checkpoint) - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/checkpoint/list.go b/vendor/github.com/docker/docker/cli/command/checkpoint/list.go deleted file mode 100644 index daf8349..0000000 --- a/vendor/github.com/docker/docker/cli/command/checkpoint/list.go +++ /dev/null @@ -1,62 +0,0 @@ -package checkpoint - -import ( - "fmt" - "text/tabwriter" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type listOptions struct { - checkpointDir string -} - -func newListCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts listOptions - - cmd := &cobra.Command{ - Use: "ls [OPTIONS] CONTAINER", - Aliases: []string{"list"}, - Short: "List checkpoints for a container", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runList(dockerCli, args[0], opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "Use a custom checkpoint storage directory") - - return cmd - -} - -func runList(dockerCli *command.DockerCli, container string, opts listOptions) error { - client := dockerCli.Client() - - listOpts := types.CheckpointListOptions{ - CheckpointDir: opts.checkpointDir, - } - - checkpoints, err := client.CheckpointList(context.Background(), container, listOpts) - if err != nil { - return err - } - - w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0) - fmt.Fprintf(w, "CHECKPOINT NAME") - fmt.Fprintf(w, "\n") - - for _, checkpoint := range checkpoints { - fmt.Fprintf(w, "%s\t", checkpoint.Name) - fmt.Fprint(w, "\n") - } - - w.Flush() - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/checkpoint/remove.go b/vendor/github.com/docker/docker/cli/command/checkpoint/remove.go deleted file mode 100644 index ec39fa7..0000000 --- a/vendor/github.com/docker/docker/cli/command/checkpoint/remove.go +++ /dev/null @@ -1,44 +0,0 @@ -package checkpoint - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type removeOptions struct { - checkpointDir string -} - -func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts removeOptions - - cmd := &cobra.Command{ - Use: "rm [OPTIONS] CONTAINER CHECKPOINT", - Aliases: []string{"remove"}, - Short: "Remove a checkpoint", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - return runRemove(dockerCli, args[0], args[1], opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "Use a custom checkpoint storage directory") - - return cmd -} - -func runRemove(dockerCli *command.DockerCli, container string, checkpoint string, opts removeOptions) error { - client := dockerCli.Client() - - removeOpts := types.CheckpointDeleteOptions{ - CheckpointID: checkpoint, - CheckpointDir: opts.checkpointDir, - } - - return client.CheckpointDelete(context.Background(), container, removeOpts) -} diff --git a/vendor/github.com/docker/docker/cli/command/cli.go b/vendor/github.com/docker/docker/cli/command/cli.go deleted file mode 100644 index 6d1dd74..0000000 --- a/vendor/github.com/docker/docker/cli/command/cli.go +++ /dev/null @@ -1,260 +0,0 @@ -package command - -import ( - "errors" - "fmt" - "io" - "net/http" - "os" - "path/filepath" - "runtime" - - "github.com/docker/docker/api" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/versions" - cliflags "github.com/docker/docker/cli/flags" - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/cliconfig/configfile" - "github.com/docker/docker/cliconfig/credentials" - "github.com/docker/docker/client" - "github.com/docker/docker/dockerversion" - dopts "github.com/docker/docker/opts" - "github.com/docker/go-connections/sockets" - "github.com/docker/go-connections/tlsconfig" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -// Streams is an interface which exposes the standard input and output streams -type Streams interface { - In() *InStream - Out() *OutStream - Err() io.Writer -} - -// DockerCli represents the docker command line client. -// Instances of the client can be returned from NewDockerCli. -type DockerCli struct { - configFile *configfile.ConfigFile - in *InStream - out *OutStream - err io.Writer - keyFile string - client client.APIClient - hasExperimental bool - defaultVersion string -} - -// HasExperimental returns true if experimental features are accessible. -func (cli *DockerCli) HasExperimental() bool { - return cli.hasExperimental -} - -// DefaultVersion returns api.defaultVersion of DOCKER_API_VERSION if specified. -func (cli *DockerCli) DefaultVersion() string { - return cli.defaultVersion -} - -// Client returns the APIClient -func (cli *DockerCli) Client() client.APIClient { - return cli.client -} - -// Out returns the writer used for stdout -func (cli *DockerCli) Out() *OutStream { - return cli.out -} - -// Err returns the writer used for stderr -func (cli *DockerCli) Err() io.Writer { - return cli.err -} - -// In returns the reader used for stdin -func (cli *DockerCli) In() *InStream { - return cli.in -} - -// ShowHelp shows the command help. -func (cli *DockerCli) ShowHelp(cmd *cobra.Command, args []string) error { - cmd.SetOutput(cli.err) - cmd.HelpFunc()(cmd, args) - return nil -} - -// ConfigFile returns the ConfigFile -func (cli *DockerCli) ConfigFile() *configfile.ConfigFile { - return cli.configFile -} - -// GetAllCredentials returns all of the credentials stored in all of the -// configured credential stores. -func (cli *DockerCli) GetAllCredentials() (map[string]types.AuthConfig, error) { - auths := make(map[string]types.AuthConfig) - for registry := range cli.configFile.CredentialHelpers { - helper := cli.CredentialsStore(registry) - newAuths, err := helper.GetAll() - if err != nil { - return nil, err - } - addAll(auths, newAuths) - } - defaultStore := cli.CredentialsStore("") - newAuths, err := defaultStore.GetAll() - if err != nil { - return nil, err - } - addAll(auths, newAuths) - return auths, nil -} - -func addAll(to, from map[string]types.AuthConfig) { - for reg, ac := range from { - to[reg] = ac - } -} - -// CredentialsStore returns a new credentials store based -// on the settings provided in the configuration file. Empty string returns -// the default credential store. -func (cli *DockerCli) CredentialsStore(serverAddress string) credentials.Store { - if helper := getConfiguredCredentialStore(cli.configFile, serverAddress); helper != "" { - return credentials.NewNativeStore(cli.configFile, helper) - } - return credentials.NewFileStore(cli.configFile) -} - -// getConfiguredCredentialStore returns the credential helper configured for the -// given registry, the default credsStore, or the empty string if neither are -// configured. -func getConfiguredCredentialStore(c *configfile.ConfigFile, serverAddress string) string { - if c.CredentialHelpers != nil && serverAddress != "" { - if helper, exists := c.CredentialHelpers[serverAddress]; exists { - return helper - } - } - return c.CredentialsStore -} - -// Initialize the dockerCli runs initialization that must happen after command -// line flags are parsed. -func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error { - cli.configFile = LoadDefaultConfigFile(cli.err) - - var err error - cli.client, err = NewAPIClientFromFlags(opts.Common, cli.configFile) - if err != nil { - return err - } - - cli.defaultVersion = cli.client.ClientVersion() - - if opts.Common.TrustKey == "" { - cli.keyFile = filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile) - } else { - cli.keyFile = opts.Common.TrustKey - } - - if ping, err := cli.client.Ping(context.Background()); err == nil { - cli.hasExperimental = ping.Experimental - - // since the new header was added in 1.25, assume server is 1.24 if header is not present. - if ping.APIVersion == "" { - ping.APIVersion = "1.24" - } - - // if server version is lower than the current cli, downgrade - if versions.LessThan(ping.APIVersion, cli.client.ClientVersion()) { - cli.client.UpdateClientVersion(ping.APIVersion) - } - } - return nil -} - -// NewDockerCli returns a DockerCli instance with IO output and error streams set by in, out and err. -func NewDockerCli(in io.ReadCloser, out, err io.Writer) *DockerCli { - return &DockerCli{in: NewInStream(in), out: NewOutStream(out), err: err} -} - -// LoadDefaultConfigFile attempts to load the default config file and returns -// an initialized ConfigFile struct if none is found. -func LoadDefaultConfigFile(err io.Writer) *configfile.ConfigFile { - configFile, e := cliconfig.Load(cliconfig.ConfigDir()) - if e != nil { - fmt.Fprintf(err, "WARNING: Error loading config file:%v\n", e) - } - if !configFile.ContainsAuth() { - credentials.DetectDefaultStore(configFile) - } - return configFile -} - -// NewAPIClientFromFlags creates a new APIClient from command line flags -func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.ConfigFile) (client.APIClient, error) { - host, err := getServerHost(opts.Hosts, opts.TLSOptions) - if err != nil { - return &client.Client{}, err - } - - customHeaders := configFile.HTTPHeaders - if customHeaders == nil { - customHeaders = map[string]string{} - } - customHeaders["User-Agent"] = UserAgent() - - verStr := api.DefaultVersion - if tmpStr := os.Getenv("DOCKER_API_VERSION"); tmpStr != "" { - verStr = tmpStr - } - - httpClient, err := newHTTPClient(host, opts.TLSOptions) - if err != nil { - return &client.Client{}, err - } - - return client.NewClient(host, verStr, httpClient, customHeaders) -} - -func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (host string, err error) { - switch len(hosts) { - case 0: - host = os.Getenv("DOCKER_HOST") - case 1: - host = hosts[0] - default: - return "", errors.New("Please specify only one -H") - } - - host, err = dopts.ParseHost(tlsOptions != nil, host) - return -} - -func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) { - if tlsOptions == nil { - // let the api client configure the default transport. - return nil, nil - } - - config, err := tlsconfig.Client(*tlsOptions) - if err != nil { - return nil, err - } - tr := &http.Transport{ - TLSClientConfig: config, - } - proto, addr, _, err := client.ParseHost(host) - if err != nil { - return nil, err - } - - sockets.ConfigureTransport(tr, proto, addr) - - return &http.Client{ - Transport: tr, - }, nil -} - -// UserAgent returns the user agent string used for making API requests -func UserAgent() string { - return "Docker-Client/" + dockerversion.Version + " (" + runtime.GOOS + ")" -} diff --git a/vendor/github.com/docker/docker/cli/command/commands/commands.go b/vendor/github.com/docker/docker/cli/command/commands/commands.go deleted file mode 100644 index d64d568..0000000 --- a/vendor/github.com/docker/docker/cli/command/commands/commands.go +++ /dev/null @@ -1,91 +0,0 @@ -package commands - -import ( - "os" - - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/checkpoint" - "github.com/docker/docker/cli/command/container" - "github.com/docker/docker/cli/command/image" - "github.com/docker/docker/cli/command/network" - "github.com/docker/docker/cli/command/node" - "github.com/docker/docker/cli/command/plugin" - "github.com/docker/docker/cli/command/registry" - "github.com/docker/docker/cli/command/secret" - "github.com/docker/docker/cli/command/service" - "github.com/docker/docker/cli/command/stack" - "github.com/docker/docker/cli/command/swarm" - "github.com/docker/docker/cli/command/system" - "github.com/docker/docker/cli/command/volume" - "github.com/spf13/cobra" -) - -// AddCommands adds all the commands from cli/command to the root command -func AddCommands(cmd *cobra.Command, dockerCli *command.DockerCli) { - cmd.AddCommand( - node.NewNodeCommand(dockerCli), - service.NewServiceCommand(dockerCli), - swarm.NewSwarmCommand(dockerCli), - secret.NewSecretCommand(dockerCli), - container.NewContainerCommand(dockerCli), - image.NewImageCommand(dockerCli), - system.NewSystemCommand(dockerCli), - container.NewRunCommand(dockerCli), - image.NewBuildCommand(dockerCli), - network.NewNetworkCommand(dockerCli), - hide(system.NewEventsCommand(dockerCli)), - registry.NewLoginCommand(dockerCli), - registry.NewLogoutCommand(dockerCli), - registry.NewSearchCommand(dockerCli), - system.NewVersionCommand(dockerCli), - volume.NewVolumeCommand(dockerCli), - hide(system.NewInfoCommand(dockerCli)), - hide(container.NewAttachCommand(dockerCli)), - hide(container.NewCommitCommand(dockerCli)), - hide(container.NewCopyCommand(dockerCli)), - hide(container.NewCreateCommand(dockerCli)), - hide(container.NewDiffCommand(dockerCli)), - hide(container.NewExecCommand(dockerCli)), - hide(container.NewExportCommand(dockerCli)), - hide(container.NewKillCommand(dockerCli)), - hide(container.NewLogsCommand(dockerCli)), - hide(container.NewPauseCommand(dockerCli)), - hide(container.NewPortCommand(dockerCli)), - hide(container.NewPsCommand(dockerCli)), - hide(container.NewRenameCommand(dockerCli)), - hide(container.NewRestartCommand(dockerCli)), - hide(container.NewRmCommand(dockerCli)), - hide(container.NewStartCommand(dockerCli)), - hide(container.NewStatsCommand(dockerCli)), - hide(container.NewStopCommand(dockerCli)), - hide(container.NewTopCommand(dockerCli)), - hide(container.NewUnpauseCommand(dockerCli)), - hide(container.NewUpdateCommand(dockerCli)), - hide(container.NewWaitCommand(dockerCli)), - hide(image.NewHistoryCommand(dockerCli)), - hide(image.NewImagesCommand(dockerCli)), - hide(image.NewImportCommand(dockerCli)), - hide(image.NewLoadCommand(dockerCli)), - hide(image.NewPullCommand(dockerCli)), - hide(image.NewPushCommand(dockerCli)), - hide(image.NewRemoveCommand(dockerCli)), - hide(image.NewSaveCommand(dockerCli)), - hide(image.NewTagCommand(dockerCli)), - hide(system.NewInspectCommand(dockerCli)), - stack.NewStackCommand(dockerCli), - stack.NewTopLevelDeployCommand(dockerCli), - checkpoint.NewCheckpointCommand(dockerCli), - plugin.NewPluginCommand(dockerCli), - ) - -} - -func hide(cmd *cobra.Command) *cobra.Command { - if os.Getenv("DOCKER_HIDE_LEGACY_COMMANDS") == "" { - return cmd - } - cmdCopy := *cmd - cmdCopy.Hidden = true - cmdCopy.Aliases = []string{} - return &cmdCopy -} diff --git a/vendor/github.com/docker/docker/cli/command/container/attach.go b/vendor/github.com/docker/docker/cli/command/container/attach.go deleted file mode 100644 index 31bb109..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/attach.go +++ /dev/null @@ -1,130 +0,0 @@ -package container - -import ( - "fmt" - "io" - "net/http/httputil" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/signal" - "github.com/spf13/cobra" -) - -type attachOptions struct { - noStdin bool - proxy bool - detachKeys string - - container string -} - -// NewAttachCommand creates a new cobra.Command for `docker attach` -func NewAttachCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts attachOptions - - cmd := &cobra.Command{ - Use: "attach [OPTIONS] CONTAINER", - Short: "Attach to a running container", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - return runAttach(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.BoolVar(&opts.noStdin, "no-stdin", false, "Do not attach STDIN") - flags.BoolVar(&opts.proxy, "sig-proxy", true, "Proxy all received signals to the process") - flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container") - return cmd -} - -func runAttach(dockerCli *command.DockerCli, opts *attachOptions) error { - ctx := context.Background() - client := dockerCli.Client() - - c, err := client.ContainerInspect(ctx, opts.container) - if err != nil { - return err - } - - if !c.State.Running { - return fmt.Errorf("You cannot attach to a stopped container, start it first") - } - - if c.State.Paused { - return fmt.Errorf("You cannot attach to a paused container, unpause it first") - } - - if err := dockerCli.In().CheckTty(!opts.noStdin, c.Config.Tty); err != nil { - return err - } - - if opts.detachKeys != "" { - dockerCli.ConfigFile().DetachKeys = opts.detachKeys - } - - options := types.ContainerAttachOptions{ - Stream: true, - Stdin: !opts.noStdin && c.Config.OpenStdin, - Stdout: true, - Stderr: true, - DetachKeys: dockerCli.ConfigFile().DetachKeys, - } - - var in io.ReadCloser - if options.Stdin { - in = dockerCli.In() - } - - if opts.proxy && !c.Config.Tty { - sigc := ForwardAllSignals(ctx, dockerCli, opts.container) - defer signal.StopCatch(sigc) - } - - resp, errAttach := client.ContainerAttach(ctx, opts.container, options) - if errAttach != nil && errAttach != httputil.ErrPersistEOF { - // ContainerAttach returns an ErrPersistEOF (connection closed) - // means server met an error and put it in Hijacked connection - // keep the error and read detailed error message from hijacked connection later - return errAttach - } - defer resp.Close() - - if c.Config.Tty && dockerCli.Out().IsTerminal() { - height, width := dockerCli.Out().GetTtySize() - // To handle the case where a user repeatedly attaches/detaches without resizing their - // terminal, the only way to get the shell prompt to display for attaches 2+ is to artificially - // resize it, then go back to normal. Without this, every attach after the first will - // require the user to manually resize or hit enter. - resizeTtyTo(ctx, client, opts.container, height+1, width+1, false) - - // After the above resizing occurs, the call to MonitorTtySize below will handle resetting back - // to the actual size. - if err := MonitorTtySize(ctx, dockerCli, opts.container, false); err != nil { - logrus.Debugf("Error monitoring TTY size: %s", err) - } - } - if err := holdHijackedConnection(ctx, dockerCli, c.Config.Tty, in, dockerCli.Out(), dockerCli.Err(), resp); err != nil { - return err - } - - if errAttach != nil { - return errAttach - } - - _, status, err := getExitCode(ctx, dockerCli, opts.container) - if err != nil { - return err - } - if status != 0 { - return cli.StatusError{StatusCode: status} - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/cmd.go b/vendor/github.com/docker/docker/cli/command/container/cmd.go deleted file mode 100644 index 3e9b488..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/cmd.go +++ /dev/null @@ -1,46 +0,0 @@ -package container - -import ( - "github.com/spf13/cobra" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" -) - -// NewContainerCommand returns a cobra command for `container` subcommands -func NewContainerCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "container", - Short: "Manage containers", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - } - cmd.AddCommand( - NewAttachCommand(dockerCli), - NewCommitCommand(dockerCli), - NewCopyCommand(dockerCli), - NewCreateCommand(dockerCli), - NewDiffCommand(dockerCli), - NewExecCommand(dockerCli), - NewExportCommand(dockerCli), - NewKillCommand(dockerCli), - NewLogsCommand(dockerCli), - NewPauseCommand(dockerCli), - NewPortCommand(dockerCli), - NewRenameCommand(dockerCli), - NewRestartCommand(dockerCli), - NewRmCommand(dockerCli), - NewRunCommand(dockerCli), - NewStartCommand(dockerCli), - NewStatsCommand(dockerCli), - NewStopCommand(dockerCli), - NewTopCommand(dockerCli), - NewUnpauseCommand(dockerCli), - NewUpdateCommand(dockerCli), - NewWaitCommand(dockerCli), - newListCommand(dockerCli), - newInspectCommand(dockerCli), - NewPruneCommand(dockerCli), - ) - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/container/commit.go b/vendor/github.com/docker/docker/cli/command/container/commit.go deleted file mode 100644 index cf8d010..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/commit.go +++ /dev/null @@ -1,76 +0,0 @@ -package container - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - dockeropts "github.com/docker/docker/opts" - "github.com/spf13/cobra" -) - -type commitOptions struct { - container string - reference string - - pause bool - comment string - author string - changes dockeropts.ListOpts -} - -// NewCommitCommand creates a new cobra.Command for `docker commit` -func NewCommitCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts commitOptions - - cmd := &cobra.Command{ - Use: "commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]", - Short: "Create a new image from a container's changes", - Args: cli.RequiresRangeArgs(1, 2), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - if len(args) > 1 { - opts.reference = args[1] - } - return runCommit(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.SetInterspersed(false) - - flags.BoolVarP(&opts.pause, "pause", "p", true, "Pause container during commit") - flags.StringVarP(&opts.comment, "message", "m", "", "Commit message") - flags.StringVarP(&opts.author, "author", "a", "", "Author (e.g., \"John Hannibal Smith \")") - - opts.changes = dockeropts.NewListOpts(nil) - flags.VarP(&opts.changes, "change", "c", "Apply Dockerfile instruction to the created image") - - return cmd -} - -func runCommit(dockerCli *command.DockerCli, opts *commitOptions) error { - ctx := context.Background() - - name := opts.container - reference := opts.reference - - options := types.ContainerCommitOptions{ - Reference: reference, - Comment: opts.comment, - Author: opts.author, - Changes: opts.changes.GetAll(), - Pause: opts.pause, - } - - response, err := dockerCli.Client().ContainerCommit(ctx, name, options) - if err != nil { - return err - } - - fmt.Fprintln(dockerCli.Out(), response.ID) - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/cp.go b/vendor/github.com/docker/docker/cli/command/container/cp.go deleted file mode 100644 index 17ab2ac..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/cp.go +++ /dev/null @@ -1,303 +0,0 @@ -package container - -import ( - "fmt" - "io" - "os" - "path/filepath" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/system" - "github.com/spf13/cobra" -) - -type copyOptions struct { - source string - destination string - followLink bool -} - -type copyDirection int - -const ( - fromContainer copyDirection = (1 << iota) - toContainer - acrossContainers = fromContainer | toContainer -) - -type cpConfig struct { - followLink bool -} - -// NewCopyCommand creates a new `docker cp` command -func NewCopyCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts copyOptions - - cmd := &cobra.Command{ - Use: `cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- - docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH`, - Short: "Copy files/folders between a container and the local filesystem", - Long: strings.Join([]string{ - "Copy files/folders between a container and the local filesystem\n", - "\nUse '-' as the source to read a tar archive from stdin\n", - "and extract it to a directory destination in a container.\n", - "Use '-' as the destination to stream a tar archive of a\n", - "container source to stdout.", - }, ""), - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - if args[0] == "" { - return fmt.Errorf("source can not be empty") - } - if args[1] == "" { - return fmt.Errorf("destination can not be empty") - } - opts.source = args[0] - opts.destination = args[1] - return runCopy(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symbol link in SRC_PATH") - - return cmd -} - -func runCopy(dockerCli *command.DockerCli, opts copyOptions) error { - srcContainer, srcPath := splitCpArg(opts.source) - dstContainer, dstPath := splitCpArg(opts.destination) - - var direction copyDirection - if srcContainer != "" { - direction |= fromContainer - } - if dstContainer != "" { - direction |= toContainer - } - - cpParam := &cpConfig{ - followLink: opts.followLink, - } - - ctx := context.Background() - - switch direction { - case fromContainer: - return copyFromContainer(ctx, dockerCli, srcContainer, srcPath, dstPath, cpParam) - case toContainer: - return copyToContainer(ctx, dockerCli, srcPath, dstContainer, dstPath, cpParam) - case acrossContainers: - // Copying between containers isn't supported. - return fmt.Errorf("copying between containers is not supported") - default: - // User didn't specify any container. - return fmt.Errorf("must specify at least one container source") - } -} - -func statContainerPath(ctx context.Context, dockerCli *command.DockerCli, containerName, path string) (types.ContainerPathStat, error) { - return dockerCli.Client().ContainerStatPath(ctx, containerName, path) -} - -func resolveLocalPath(localPath string) (absPath string, err error) { - if absPath, err = filepath.Abs(localPath); err != nil { - return - } - - return archive.PreserveTrailingDotOrSeparator(absPath, localPath), nil -} - -func copyFromContainer(ctx context.Context, dockerCli *command.DockerCli, srcContainer, srcPath, dstPath string, cpParam *cpConfig) (err error) { - if dstPath != "-" { - // Get an absolute destination path. - dstPath, err = resolveLocalPath(dstPath) - if err != nil { - return err - } - } - - // if client requests to follow symbol link, then must decide target file to be copied - var rebaseName string - if cpParam.followLink { - srcStat, err := statContainerPath(ctx, dockerCli, srcContainer, srcPath) - - // If the destination is a symbolic link, we should follow it. - if err == nil && srcStat.Mode&os.ModeSymlink != 0 { - linkTarget := srcStat.LinkTarget - if !system.IsAbs(linkTarget) { - // Join with the parent directory. - srcParent, _ := archive.SplitPathDirEntry(srcPath) - linkTarget = filepath.Join(srcParent, linkTarget) - } - - linkTarget, rebaseName = archive.GetRebaseName(srcPath, linkTarget) - srcPath = linkTarget - } - - } - - content, stat, err := dockerCli.Client().CopyFromContainer(ctx, srcContainer, srcPath) - if err != nil { - return err - } - defer content.Close() - - if dstPath == "-" { - // Send the response to STDOUT. - _, err = io.Copy(os.Stdout, content) - - return err - } - - // Prepare source copy info. - srcInfo := archive.CopyInfo{ - Path: srcPath, - Exists: true, - IsDir: stat.Mode.IsDir(), - RebaseName: rebaseName, - } - - preArchive := content - if len(srcInfo.RebaseName) != 0 { - _, srcBase := archive.SplitPathDirEntry(srcInfo.Path) - preArchive = archive.RebaseArchiveEntries(content, srcBase, srcInfo.RebaseName) - } - // See comments in the implementation of `archive.CopyTo` for exactly what - // goes into deciding how and whether the source archive needs to be - // altered for the correct copy behavior. - return archive.CopyTo(preArchive, srcInfo, dstPath) -} - -func copyToContainer(ctx context.Context, dockerCli *command.DockerCli, srcPath, dstContainer, dstPath string, cpParam *cpConfig) (err error) { - if srcPath != "-" { - // Get an absolute source path. - srcPath, err = resolveLocalPath(srcPath) - if err != nil { - return err - } - } - - // In order to get the copy behavior right, we need to know information - // about both the source and destination. The API is a simple tar - // archive/extract API but we can use the stat info header about the - // destination to be more informed about exactly what the destination is. - - // Prepare destination copy info by stat-ing the container path. - dstInfo := archive.CopyInfo{Path: dstPath} - dstStat, err := statContainerPath(ctx, dockerCli, dstContainer, dstPath) - - // If the destination is a symbolic link, we should evaluate it. - if err == nil && dstStat.Mode&os.ModeSymlink != 0 { - linkTarget := dstStat.LinkTarget - if !system.IsAbs(linkTarget) { - // Join with the parent directory. - dstParent, _ := archive.SplitPathDirEntry(dstPath) - linkTarget = filepath.Join(dstParent, linkTarget) - } - - dstInfo.Path = linkTarget - dstStat, err = statContainerPath(ctx, dockerCli, dstContainer, linkTarget) - } - - // Ignore any error and assume that the parent directory of the destination - // path exists, in which case the copy may still succeed. If there is any - // type of conflict (e.g., non-directory overwriting an existing directory - // or vice versa) the extraction will fail. If the destination simply did - // not exist, but the parent directory does, the extraction will still - // succeed. - if err == nil { - dstInfo.Exists, dstInfo.IsDir = true, dstStat.Mode.IsDir() - } - - var ( - content io.Reader - resolvedDstPath string - ) - - if srcPath == "-" { - // Use STDIN. - content = os.Stdin - resolvedDstPath = dstInfo.Path - if !dstInfo.IsDir { - return fmt.Errorf("destination %q must be a directory", fmt.Sprintf("%s:%s", dstContainer, dstPath)) - } - } else { - // Prepare source copy info. - srcInfo, err := archive.CopyInfoSourcePath(srcPath, cpParam.followLink) - if err != nil { - return err - } - - srcArchive, err := archive.TarResource(srcInfo) - if err != nil { - return err - } - defer srcArchive.Close() - - // With the stat info about the local source as well as the - // destination, we have enough information to know whether we need to - // alter the archive that we upload so that when the server extracts - // it to the specified directory in the container we get the desired - // copy behavior. - - // See comments in the implementation of `archive.PrepareArchiveCopy` - // for exactly what goes into deciding how and whether the source - // archive needs to be altered for the correct copy behavior when it is - // extracted. This function also infers from the source and destination - // info which directory to extract to, which may be the parent of the - // destination that the user specified. - dstDir, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, dstInfo) - if err != nil { - return err - } - defer preparedArchive.Close() - - resolvedDstPath = dstDir - content = preparedArchive - } - - options := types.CopyToContainerOptions{ - AllowOverwriteDirWithFile: false, - } - - return dockerCli.Client().CopyToContainer(ctx, dstContainer, resolvedDstPath, content, options) -} - -// We use `:` as a delimiter between CONTAINER and PATH, but `:` could also be -// in a valid LOCALPATH, like `file:name.txt`. We can resolve this ambiguity by -// requiring a LOCALPATH with a `:` to be made explicit with a relative or -// absolute path: -// `/path/to/file:name.txt` or `./file:name.txt` -// -// This is apparently how `scp` handles this as well: -// http://www.cyberciti.biz/faq/rsync-scp-file-name-with-colon-punctuation-in-it/ -// -// We can't simply check for a filepath separator because container names may -// have a separator, e.g., "host0/cname1" if container is in a Docker cluster, -// so we have to check for a `/` or `.` prefix. Also, in the case of a Windows -// client, a `:` could be part of an absolute Windows path, in which case it -// is immediately proceeded by a backslash. -func splitCpArg(arg string) (container, path string) { - if system.IsAbs(arg) { - // Explicit local absolute path, e.g., `C:\foo` or `/foo`. - return "", arg - } - - parts := strings.SplitN(arg, ":", 2) - - if len(parts) == 1 || strings.HasPrefix(parts[0], ".") { - // Either there's no `:` in the arg - // OR it's an explicit local relative path like `./file:name.txt`. - return "", arg - } - - return parts[0], parts[1] -} diff --git a/vendor/github.com/docker/docker/cli/command/container/create.go b/vendor/github.com/docker/docker/cli/command/container/create.go deleted file mode 100644 index d5e63bd..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/create.go +++ /dev/null @@ -1,218 +0,0 @@ -package container - -import ( - "fmt" - "io" - "os" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/image" - "github.com/docker/docker/pkg/jsonmessage" - // FIXME migrate to docker/distribution/reference - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - networktypes "github.com/docker/docker/api/types/network" - apiclient "github.com/docker/docker/client" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -type createOptions struct { - name string -} - -// NewCreateCommand creates a new cobra.Command for `docker create` -func NewCreateCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts createOptions - var copts *runconfigopts.ContainerOptions - - cmd := &cobra.Command{ - Use: "create [OPTIONS] IMAGE [COMMAND] [ARG...]", - Short: "Create a new container", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - copts.Image = args[0] - if len(args) > 1 { - copts.Args = args[1:] - } - return runCreate(dockerCli, cmd.Flags(), &opts, copts) - }, - } - - flags := cmd.Flags() - flags.SetInterspersed(false) - - flags.StringVar(&opts.name, "name", "", "Assign a name to the container") - - // Add an explicit help that doesn't have a `-h` to prevent the conflict - // with hostname - flags.Bool("help", false, "Print usage") - - command.AddTrustedFlags(flags, true) - copts = runconfigopts.AddFlags(flags) - return cmd -} - -func runCreate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *createOptions, copts *runconfigopts.ContainerOptions) error { - config, hostConfig, networkingConfig, err := runconfigopts.Parse(flags, copts) - if err != nil { - reportError(dockerCli.Err(), "create", err.Error(), true) - return cli.StatusError{StatusCode: 125} - } - response, err := createContainer(context.Background(), dockerCli, config, hostConfig, networkingConfig, hostConfig.ContainerIDFile, opts.name) - if err != nil { - return err - } - fmt.Fprintf(dockerCli.Out(), "%s\n", response.ID) - return nil -} - -func pullImage(ctx context.Context, dockerCli *command.DockerCli, image string, out io.Writer) error { - ref, err := reference.ParseNamed(image) - if err != nil { - return err - } - - // Resolve the Repository name from fqn to RepositoryInfo - repoInfo, err := registry.ParseRepositoryInfo(ref) - if err != nil { - return err - } - - authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index) - encodedAuth, err := command.EncodeAuthToBase64(authConfig) - if err != nil { - return err - } - - options := types.ImageCreateOptions{ - RegistryAuth: encodedAuth, - } - - responseBody, err := dockerCli.Client().ImageCreate(ctx, image, options) - if err != nil { - return err - } - defer responseBody.Close() - - return jsonmessage.DisplayJSONMessagesStream( - responseBody, - out, - dockerCli.Out().FD(), - dockerCli.Out().IsTerminal(), - nil) -} - -type cidFile struct { - path string - file *os.File - written bool -} - -func (cid *cidFile) Close() error { - cid.file.Close() - - if !cid.written { - if err := os.Remove(cid.path); err != nil { - return fmt.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err) - } - } - - return nil -} - -func (cid *cidFile) Write(id string) error { - if _, err := cid.file.Write([]byte(id)); err != nil { - return fmt.Errorf("Failed to write the container ID to the file: %s", err) - } - cid.written = true - return nil -} - -func newCIDFile(path string) (*cidFile, error) { - if _, err := os.Stat(path); err == nil { - return nil, fmt.Errorf("Container ID file found, make sure the other container isn't running or delete %s", path) - } - - f, err := os.Create(path) - if err != nil { - return nil, fmt.Errorf("Failed to create the container ID file: %s", err) - } - - return &cidFile{path: path, file: f}, nil -} - -func createContainer(ctx context.Context, dockerCli *command.DockerCli, config *container.Config, hostConfig *container.HostConfig, networkingConfig *networktypes.NetworkingConfig, cidfile, name string) (*container.ContainerCreateCreatedBody, error) { - stderr := dockerCli.Err() - - var containerIDFile *cidFile - if cidfile != "" { - var err error - if containerIDFile, err = newCIDFile(cidfile); err != nil { - return nil, err - } - defer containerIDFile.Close() - } - - var trustedRef reference.Canonical - _, ref, err := reference.ParseIDOrReference(config.Image) - if err != nil { - return nil, err - } - if ref != nil { - ref = reference.WithDefaultTag(ref) - - if ref, ok := ref.(reference.NamedTagged); ok && command.IsTrusted() { - var err error - trustedRef, err = image.TrustedReference(ctx, dockerCli, ref, nil) - if err != nil { - return nil, err - } - config.Image = trustedRef.String() - } - } - - //create the container - response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, name) - - //if image not found try to pull it - if err != nil { - if apiclient.IsErrImageNotFound(err) && ref != nil { - fmt.Fprintf(stderr, "Unable to find image '%s' locally\n", ref.String()) - - // we don't want to write to stdout anything apart from container.ID - if err = pullImage(ctx, dockerCli, config.Image, stderr); err != nil { - return nil, err - } - if ref, ok := ref.(reference.NamedTagged); ok && trustedRef != nil { - if err := image.TagTrusted(ctx, dockerCli, trustedRef, ref); err != nil { - return nil, err - } - } - // Retry - var retryErr error - response, retryErr = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, name) - if retryErr != nil { - return nil, retryErr - } - } else { - return nil, err - } - } - - for _, warning := range response.Warnings { - fmt.Fprintf(stderr, "WARNING: %s\n", warning) - } - if containerIDFile != nil { - if err = containerIDFile.Write(response.ID); err != nil { - return nil, err - } - } - return &response, nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/diff.go b/vendor/github.com/docker/docker/cli/command/container/diff.go deleted file mode 100644 index 12d6591..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/diff.go +++ /dev/null @@ -1,58 +0,0 @@ -package container - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/archive" - "github.com/spf13/cobra" -) - -type diffOptions struct { - container string -} - -// NewDiffCommand creates a new cobra.Command for `docker diff` -func NewDiffCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts diffOptions - - return &cobra.Command{ - Use: "diff CONTAINER", - Short: "Inspect changes on a container's filesystem", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - return runDiff(dockerCli, &opts) - }, - } -} - -func runDiff(dockerCli *command.DockerCli, opts *diffOptions) error { - if opts.container == "" { - return fmt.Errorf("Container name cannot be empty") - } - ctx := context.Background() - - changes, err := dockerCli.Client().ContainerDiff(ctx, opts.container) - if err != nil { - return err - } - - for _, change := range changes { - var kind string - switch change.Kind { - case archive.ChangeModify: - kind = "C" - case archive.ChangeAdd: - kind = "A" - case archive.ChangeDelete: - kind = "D" - } - fmt.Fprintf(dockerCli.Out(), "%s %s\n", kind, change.Path) - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/exec.go b/vendor/github.com/docker/docker/cli/command/container/exec.go deleted file mode 100644 index f038149..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/exec.go +++ /dev/null @@ -1,207 +0,0 @@ -package container - -import ( - "fmt" - "io" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - apiclient "github.com/docker/docker/client" - options "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/promise" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/spf13/cobra" -) - -type execOptions struct { - detachKeys string - interactive bool - tty bool - detach bool - user string - privileged bool - env *options.ListOpts -} - -func newExecOptions() *execOptions { - var values []string - return &execOptions{ - env: options.NewListOptsRef(&values, runconfigopts.ValidateEnv), - } -} - -// NewExecCommand creats a new cobra.Command for `docker exec` -func NewExecCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := newExecOptions() - - cmd := &cobra.Command{ - Use: "exec [OPTIONS] CONTAINER COMMAND [ARG...]", - Short: "Run a command in a running container", - Args: cli.RequiresMinArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - container := args[0] - execCmd := args[1:] - return runExec(dockerCli, opts, container, execCmd) - }, - } - - flags := cmd.Flags() - flags.SetInterspersed(false) - - flags.StringVarP(&opts.detachKeys, "detach-keys", "", "", "Override the key sequence for detaching a container") - flags.BoolVarP(&opts.interactive, "interactive", "i", false, "Keep STDIN open even if not attached") - flags.BoolVarP(&opts.tty, "tty", "t", false, "Allocate a pseudo-TTY") - flags.BoolVarP(&opts.detach, "detach", "d", false, "Detached mode: run command in the background") - flags.StringVarP(&opts.user, "user", "u", "", "Username or UID (format: [:])") - flags.BoolVarP(&opts.privileged, "privileged", "", false, "Give extended privileges to the command") - flags.VarP(opts.env, "env", "e", "Set environment variables") - flags.SetAnnotation("env", "version", []string{"1.25"}) - - return cmd -} - -func runExec(dockerCli *command.DockerCli, opts *execOptions, container string, execCmd []string) error { - execConfig, err := parseExec(opts, execCmd) - // just in case the ParseExec does not exit - if container == "" || err != nil { - return cli.StatusError{StatusCode: 1} - } - - if opts.detachKeys != "" { - dockerCli.ConfigFile().DetachKeys = opts.detachKeys - } - - // Send client escape keys - execConfig.DetachKeys = dockerCli.ConfigFile().DetachKeys - - ctx := context.Background() - client := dockerCli.Client() - - response, err := client.ContainerExecCreate(ctx, container, *execConfig) - if err != nil { - return err - } - - execID := response.ID - if execID == "" { - fmt.Fprintf(dockerCli.Out(), "exec ID empty") - return nil - } - - //Temp struct for execStart so that we don't need to transfer all the execConfig - if !execConfig.Detach { - if err := dockerCli.In().CheckTty(execConfig.AttachStdin, execConfig.Tty); err != nil { - return err - } - } else { - execStartCheck := types.ExecStartCheck{ - Detach: execConfig.Detach, - Tty: execConfig.Tty, - } - - if err := client.ContainerExecStart(ctx, execID, execStartCheck); err != nil { - return err - } - // For now don't print this - wait for when we support exec wait() - // fmt.Fprintf(dockerCli.Out(), "%s\n", execID) - return nil - } - - // Interactive exec requested. - var ( - out, stderr io.Writer - in io.ReadCloser - errCh chan error - ) - - if execConfig.AttachStdin { - in = dockerCli.In() - } - if execConfig.AttachStdout { - out = dockerCli.Out() - } - if execConfig.AttachStderr { - if execConfig.Tty { - stderr = dockerCli.Out() - } else { - stderr = dockerCli.Err() - } - } - - resp, err := client.ContainerExecAttach(ctx, execID, *execConfig) - if err != nil { - return err - } - defer resp.Close() - errCh = promise.Go(func() error { - return holdHijackedConnection(ctx, dockerCli, execConfig.Tty, in, out, stderr, resp) - }) - - if execConfig.Tty && dockerCli.In().IsTerminal() { - if err := MonitorTtySize(ctx, dockerCli, execID, true); err != nil { - fmt.Fprintf(dockerCli.Err(), "Error monitoring TTY size: %s\n", err) - } - } - - if err := <-errCh; err != nil { - logrus.Debugf("Error hijack: %s", err) - return err - } - - var status int - if _, status, err = getExecExitCode(ctx, client, execID); err != nil { - return err - } - - if status != 0 { - return cli.StatusError{StatusCode: status} - } - - return nil -} - -// getExecExitCode perform an inspect on the exec command. It returns -// the running state and the exit code. -func getExecExitCode(ctx context.Context, client apiclient.ContainerAPIClient, execID string) (bool, int, error) { - resp, err := client.ContainerExecInspect(ctx, execID) - if err != nil { - // If we can't connect, then the daemon probably died. - if !apiclient.IsErrConnectionFailed(err) { - return false, -1, err - } - return false, -1, nil - } - - return resp.Running, resp.ExitCode, nil -} - -// parseExec parses the specified args for the specified command and generates -// an ExecConfig from it. -func parseExec(opts *execOptions, execCmd []string) (*types.ExecConfig, error) { - execConfig := &types.ExecConfig{ - User: opts.user, - Privileged: opts.privileged, - Tty: opts.tty, - Cmd: execCmd, - Detach: opts.detach, - } - - // If -d is not set, attach to everything by default - if !opts.detach { - execConfig.AttachStdout = true - execConfig.AttachStderr = true - if opts.interactive { - execConfig.AttachStdin = true - } - } - - if opts.env != nil { - execConfig.Env = opts.env.GetAll() - } - - return execConfig, nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/exec_test.go b/vendor/github.com/docker/docker/cli/command/container/exec_test.go deleted file mode 100644 index baeeaf1..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/exec_test.go +++ /dev/null @@ -1,116 +0,0 @@ -package container - -import ( - "testing" - - "github.com/docker/docker/api/types" -) - -type arguments struct { - options execOptions - execCmd []string -} - -func TestParseExec(t *testing.T) { - valids := map[*arguments]*types.ExecConfig{ - &arguments{ - execCmd: []string{"command"}, - }: { - Cmd: []string{"command"}, - AttachStdout: true, - AttachStderr: true, - }, - &arguments{ - execCmd: []string{"command1", "command2"}, - }: { - Cmd: []string{"command1", "command2"}, - AttachStdout: true, - AttachStderr: true, - }, - &arguments{ - options: execOptions{ - interactive: true, - tty: true, - user: "uid", - }, - execCmd: []string{"command"}, - }: { - User: "uid", - AttachStdin: true, - AttachStdout: true, - AttachStderr: true, - Tty: true, - Cmd: []string{"command"}, - }, - &arguments{ - options: execOptions{ - detach: true, - }, - execCmd: []string{"command"}, - }: { - AttachStdin: false, - AttachStdout: false, - AttachStderr: false, - Detach: true, - Cmd: []string{"command"}, - }, - &arguments{ - options: execOptions{ - tty: true, - interactive: true, - detach: true, - }, - execCmd: []string{"command"}, - }: { - AttachStdin: false, - AttachStdout: false, - AttachStderr: false, - Detach: true, - Tty: true, - Cmd: []string{"command"}, - }, - } - - for valid, expectedExecConfig := range valids { - execConfig, err := parseExec(&valid.options, valid.execCmd) - if err != nil { - t.Fatal(err) - } - if !compareExecConfig(expectedExecConfig, execConfig) { - t.Fatalf("Expected [%v] for %v, got [%v]", expectedExecConfig, valid, execConfig) - } - } -} - -func compareExecConfig(config1 *types.ExecConfig, config2 *types.ExecConfig) bool { - if config1.AttachStderr != config2.AttachStderr { - return false - } - if config1.AttachStdin != config2.AttachStdin { - return false - } - if config1.AttachStdout != config2.AttachStdout { - return false - } - if config1.Detach != config2.Detach { - return false - } - if config1.Privileged != config2.Privileged { - return false - } - if config1.Tty != config2.Tty { - return false - } - if config1.User != config2.User { - return false - } - if len(config1.Cmd) != len(config2.Cmd) { - return false - } - for index, value := range config1.Cmd { - if value != config2.Cmd[index] { - return false - } - } - return true -} diff --git a/vendor/github.com/docker/docker/cli/command/container/export.go b/vendor/github.com/docker/docker/cli/command/container/export.go deleted file mode 100644 index 8fa2e5d..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/export.go +++ /dev/null @@ -1,59 +0,0 @@ -package container - -import ( - "errors" - "io" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type exportOptions struct { - container string - output string -} - -// NewExportCommand creates a new `docker export` command -func NewExportCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts exportOptions - - cmd := &cobra.Command{ - Use: "export [OPTIONS] CONTAINER", - Short: "Export a container's filesystem as a tar archive", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - return runExport(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.StringVarP(&opts.output, "output", "o", "", "Write to a file, instead of STDOUT") - - return cmd -} - -func runExport(dockerCli *command.DockerCli, opts exportOptions) error { - if opts.output == "" && dockerCli.Out().IsTerminal() { - return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.") - } - - clnt := dockerCli.Client() - - responseBody, err := clnt.ContainerExport(context.Background(), opts.container) - if err != nil { - return err - } - defer responseBody.Close() - - if opts.output == "" { - _, err := io.Copy(dockerCli.Out(), responseBody) - return err - } - - return command.CopyToFile(opts.output, responseBody) -} diff --git a/vendor/github.com/docker/docker/cli/command/container/hijack.go b/vendor/github.com/docker/docker/cli/command/container/hijack.go deleted file mode 100644 index ca136f0..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/hijack.go +++ /dev/null @@ -1,116 +0,0 @@ -package container - -import ( - "io" - "runtime" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/stdcopy" - "golang.org/x/net/context" -) - -// holdHijackedConnection handles copying input to and output from streams to the -// connection -func holdHijackedConnection(ctx context.Context, streams command.Streams, tty bool, inputStream io.ReadCloser, outputStream, errorStream io.Writer, resp types.HijackedResponse) error { - var ( - err error - restoreOnce sync.Once - ) - if inputStream != nil && tty { - if err := setRawTerminal(streams); err != nil { - return err - } - defer func() { - restoreOnce.Do(func() { - restoreTerminal(streams, inputStream) - }) - }() - } - - receiveStdout := make(chan error, 1) - if outputStream != nil || errorStream != nil { - go func() { - // When TTY is ON, use regular copy - if tty && outputStream != nil { - _, err = io.Copy(outputStream, resp.Reader) - // we should restore the terminal as soon as possible once connection end - // so any following print messages will be in normal type. - if inputStream != nil { - restoreOnce.Do(func() { - restoreTerminal(streams, inputStream) - }) - } - } else { - _, err = stdcopy.StdCopy(outputStream, errorStream, resp.Reader) - } - - logrus.Debug("[hijack] End of stdout") - receiveStdout <- err - }() - } - - stdinDone := make(chan struct{}) - go func() { - if inputStream != nil { - io.Copy(resp.Conn, inputStream) - // we should restore the terminal as soon as possible once connection end - // so any following print messages will be in normal type. - if tty { - restoreOnce.Do(func() { - restoreTerminal(streams, inputStream) - }) - } - logrus.Debug("[hijack] End of stdin") - } - - if err := resp.CloseWrite(); err != nil { - logrus.Debugf("Couldn't send EOF: %s", err) - } - close(stdinDone) - }() - - select { - case err := <-receiveStdout: - if err != nil { - logrus.Debugf("Error receiveStdout: %s", err) - return err - } - case <-stdinDone: - if outputStream != nil || errorStream != nil { - select { - case err := <-receiveStdout: - if err != nil { - logrus.Debugf("Error receiveStdout: %s", err) - return err - } - case <-ctx.Done(): - } - } - case <-ctx.Done(): - } - - return nil -} - -func setRawTerminal(streams command.Streams) error { - if err := streams.In().SetRawTerminal(); err != nil { - return err - } - return streams.Out().SetRawTerminal() -} - -func restoreTerminal(streams command.Streams, in io.Closer) error { - streams.In().RestoreTerminal() - streams.Out().RestoreTerminal() - // WARNING: DO NOT REMOVE THE OS CHECK !!! - // For some reason this Close call blocks on darwin.. - // As the client exists right after, simply discard the close - // until we find a better solution. - if in != nil && runtime.GOOS != "darwin" { - return in.Close() - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/inspect.go b/vendor/github.com/docker/docker/cli/command/container/inspect.go deleted file mode 100644 index 08a8d24..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/inspect.go +++ /dev/null @@ -1,47 +0,0 @@ -package container - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/inspect" - "github.com/spf13/cobra" -) - -type inspectOptions struct { - format string - size bool - refs []string -} - -// newInspectCommand creates a new cobra.Command for `docker container inspect` -func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts inspectOptions - - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Display detailed information on one or more containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.refs = args - return runInspect(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - flags.BoolVarP(&opts.size, "size", "s", false, "Display total file sizes") - - return cmd -} - -func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - getRefFunc := func(ref string) (interface{}, []byte, error) { - return client.ContainerInspectWithRaw(ctx, ref, opts.size) - } - return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRefFunc) -} diff --git a/vendor/github.com/docker/docker/cli/command/container/kill.go b/vendor/github.com/docker/docker/cli/command/container/kill.go deleted file mode 100644 index 6da91a4..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/kill.go +++ /dev/null @@ -1,56 +0,0 @@ -package container - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type killOptions struct { - signal string - - containers []string -} - -// NewKillCommand creates a new cobra.Command for `docker kill` -func NewKillCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts killOptions - - cmd := &cobra.Command{ - Use: "kill [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Kill one or more running containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - return runKill(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.signal, "signal", "s", "KILL", "Signal to send to the container") - return cmd -} - -func runKill(dockerCli *command.DockerCli, opts *killOptions) error { - var errs []string - ctx := context.Background() - errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, container string) error { - return dockerCli.Client().ContainerKill(ctx, container, opts.signal) - }) - for _, name := range opts.containers { - if err := <-errChan; err != nil { - errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", name) - } - } - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/list.go b/vendor/github.com/docker/docker/cli/command/container/list.go deleted file mode 100644 index 5bbf419..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/list.go +++ /dev/null @@ -1,141 +0,0 @@ -package container - -import ( - "io/ioutil" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/formatter" - "github.com/docker/docker/opts" - "github.com/docker/docker/utils/templates" - "github.com/spf13/cobra" -) - -type psOptions struct { - quiet bool - size bool - all bool - noTrunc bool - nLatest bool - last int - format string - filter opts.FilterOpt -} - -// NewPsCommand creates a new cobra.Command for `docker ps` -func NewPsCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := psOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "ps [OPTIONS]", - Short: "List containers", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runPs(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display numeric IDs") - flags.BoolVarP(&opts.size, "size", "s", false, "Display total file sizes") - flags.BoolVarP(&opts.all, "all", "a", false, "Show all containers (default shows just running)") - flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") - flags.BoolVarP(&opts.nLatest, "latest", "l", false, "Show the latest created container (includes all states)") - flags.IntVarP(&opts.last, "last", "n", -1, "Show n last created containers (includes all states)") - flags.StringVarP(&opts.format, "format", "", "", "Pretty-print containers using a Go template") - flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") - - return cmd -} - -func newListCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := *NewPsCommand(dockerCli) - cmd.Aliases = []string{"ps", "list"} - cmd.Use = "ls [OPTIONS]" - return &cmd -} - -// listOptionsProcessor is used to set any container list options which may only -// be embedded in the format template. -// This is passed directly into tmpl.Execute in order to allow the preprocessor -// to set any list options that were not provided by flags (e.g. `.Size`). -// It is using a `map[string]bool` so that unknown fields passed into the -// template format do not cause errors. These errors will get picked up when -// running through the actual template processor. -type listOptionsProcessor map[string]bool - -// Size sets the size of the map when called by a template execution. -func (o listOptionsProcessor) Size() bool { - o["size"] = true - return true -} - -// Label is needed here as it allows the correct pre-processing -// because Label() is a method with arguments -func (o listOptionsProcessor) Label(name string) string { - return "" -} - -func buildContainerListOptions(opts *psOptions) (*types.ContainerListOptions, error) { - options := &types.ContainerListOptions{ - All: opts.all, - Limit: opts.last, - Size: opts.size, - Filters: opts.filter.Value(), - } - - if opts.nLatest && opts.last == -1 { - options.Limit = 1 - } - - tmpl, err := templates.Parse(opts.format) - - if err != nil { - return nil, err - } - - optionsProcessor := listOptionsProcessor{} - // This shouldn't error out but swallowing the error makes it harder - // to track down if preProcessor issues come up. Ref #24696 - if err := tmpl.Execute(ioutil.Discard, optionsProcessor); err != nil { - return nil, err - } - // At the moment all we need is to capture .Size for preprocessor - options.Size = opts.size || optionsProcessor["size"] - - return options, nil -} - -func runPs(dockerCli *command.DockerCli, opts *psOptions) error { - ctx := context.Background() - - listOptions, err := buildContainerListOptions(opts) - if err != nil { - return err - } - - containers, err := dockerCli.Client().ContainerList(ctx, *listOptions) - if err != nil { - return err - } - - format := opts.format - if len(format) == 0 { - if len(dockerCli.ConfigFile().PsFormat) > 0 && !opts.quiet { - format = dockerCli.ConfigFile().PsFormat - } else { - format = formatter.TableFormatKey - } - } - - containerCtx := formatter.Context{ - Output: dockerCli.Out(), - Format: formatter.NewContainerFormat(format, opts.quiet, listOptions.Size), - Trunc: !opts.noTrunc, - } - return formatter.ContainerWrite(containerCtx, containers) -} diff --git a/vendor/github.com/docker/docker/cli/command/container/logs.go b/vendor/github.com/docker/docker/cli/command/container/logs.go deleted file mode 100644 index 3a37ced..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/logs.go +++ /dev/null @@ -1,87 +0,0 @@ -package container - -import ( - "fmt" - "io" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/stdcopy" - "github.com/spf13/cobra" -) - -var validDrivers = map[string]bool{ - "json-file": true, - "journald": true, -} - -type logsOptions struct { - follow bool - since string - timestamps bool - details bool - tail string - - container string -} - -// NewLogsCommand creates a new cobra.Command for `docker logs` -func NewLogsCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts logsOptions - - cmd := &cobra.Command{ - Use: "logs [OPTIONS] CONTAINER", - Short: "Fetch the logs of a container", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - return runLogs(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.follow, "follow", "f", false, "Follow log output") - flags.StringVar(&opts.since, "since", "", "Show logs since timestamp") - flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps") - flags.BoolVar(&opts.details, "details", false, "Show extra details provided to logs") - flags.StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs") - return cmd -} - -func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { - ctx := context.Background() - - c, err := dockerCli.Client().ContainerInspect(ctx, opts.container) - if err != nil { - return err - } - - if !validDrivers[c.HostConfig.LogConfig.Type] { - return fmt.Errorf("\"logs\" command is supported only for \"json-file\" and \"journald\" logging drivers (got: %s)", c.HostConfig.LogConfig.Type) - } - - options := types.ContainerLogsOptions{ - ShowStdout: true, - ShowStderr: true, - Since: opts.since, - Timestamps: opts.timestamps, - Follow: opts.follow, - Tail: opts.tail, - Details: opts.details, - } - responseBody, err := dockerCli.Client().ContainerLogs(ctx, opts.container, options) - if err != nil { - return err - } - defer responseBody.Close() - - if c.Config.Tty { - _, err = io.Copy(dockerCli.Out(), responseBody) - } else { - _, err = stdcopy.StdCopy(dockerCli.Out(), dockerCli.Err(), responseBody) - } - return err -} diff --git a/vendor/github.com/docker/docker/cli/command/container/pause.go b/vendor/github.com/docker/docker/cli/command/container/pause.go deleted file mode 100644 index 6817cf6..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/pause.go +++ /dev/null @@ -1,49 +0,0 @@ -package container - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type pauseOptions struct { - containers []string -} - -// NewPauseCommand creates a new cobra.Command for `docker pause` -func NewPauseCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts pauseOptions - - return &cobra.Command{ - Use: "pause CONTAINER [CONTAINER...]", - Short: "Pause all processes within one or more containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - return runPause(dockerCli, &opts) - }, - } -} - -func runPause(dockerCli *command.DockerCli, opts *pauseOptions) error { - ctx := context.Background() - - var errs []string - errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerPause) - for _, container := range opts.containers { - if err := <-errChan; err != nil { - errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", container) - } - } - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/port.go b/vendor/github.com/docker/docker/cli/command/container/port.go deleted file mode 100644 index ea15290..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/port.go +++ /dev/null @@ -1,78 +0,0 @@ -package container - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/go-connections/nat" - "github.com/spf13/cobra" -) - -type portOptions struct { - container string - - port string -} - -// NewPortCommand creates a new cobra.Command for `docker port` -func NewPortCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts portOptions - - cmd := &cobra.Command{ - Use: "port CONTAINER [PRIVATE_PORT[/PROTO]]", - Short: "List port mappings or a specific mapping for the container", - Args: cli.RequiresRangeArgs(1, 2), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - if len(args) > 1 { - opts.port = args[1] - } - return runPort(dockerCli, &opts) - }, - } - return cmd -} - -func runPort(dockerCli *command.DockerCli, opts *portOptions) error { - ctx := context.Background() - - c, err := dockerCli.Client().ContainerInspect(ctx, opts.container) - if err != nil { - return err - } - - if opts.port != "" { - port := opts.port - proto := "tcp" - parts := strings.SplitN(port, "/", 2) - - if len(parts) == 2 && len(parts[1]) != 0 { - port = parts[0] - proto = parts[1] - } - natPort := port + "/" + proto - newP, err := nat.NewPort(proto, port) - if err != nil { - return err - } - if frontends, exists := c.NetworkSettings.Ports[newP]; exists && frontends != nil { - for _, frontend := range frontends { - fmt.Fprintf(dockerCli.Out(), "%s:%s\n", frontend.HostIP, frontend.HostPort) - } - return nil - } - return fmt.Errorf("Error: No public port '%s' published for %s", natPort, opts.container) - } - - for from, frontends := range c.NetworkSettings.Ports { - for _, frontend := range frontends { - fmt.Fprintf(dockerCli.Out(), "%s -> %s:%s\n", from, frontend.HostIP, frontend.HostPort) - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/prune.go b/vendor/github.com/docker/docker/cli/command/container/prune.go deleted file mode 100644 index 064f4c0..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/prune.go +++ /dev/null @@ -1,75 +0,0 @@ -package container - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - units "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type pruneOptions struct { - force bool -} - -// NewPruneCommand returns a new cobra prune command for containers -func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts pruneOptions - - cmd := &cobra.Command{ - Use: "prune [OPTIONS]", - Short: "Remove all stopped containers", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - spaceReclaimed, output, err := runPrune(dockerCli, opts) - if err != nil { - return err - } - if output != "" { - fmt.Fprintln(dockerCli.Out(), output) - } - fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) - return nil - }, - Tags: map[string]string{"version": "1.25"}, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") - - return cmd -} - -const warning = `WARNING! This will remove all stopped containers. -Are you sure you want to continue?` - -func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { - if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { - return - } - - report, err := dockerCli.Client().ContainersPrune(context.Background(), filters.Args{}) - if err != nil { - return - } - - if len(report.ContainersDeleted) > 0 { - output = "Deleted Containers:\n" - for _, id := range report.ContainersDeleted { - output += id + "\n" - } - spaceReclaimed = report.SpaceReclaimed - } - - return -} - -// RunPrune calls the Container Prune API -// This returns the amount of space reclaimed and a detailed output string -func RunPrune(dockerCli *command.DockerCli) (uint64, string, error) { - return runPrune(dockerCli, pruneOptions{force: true}) -} diff --git a/vendor/github.com/docker/docker/cli/command/container/ps_test.go b/vendor/github.com/docker/docker/cli/command/container/ps_test.go deleted file mode 100644 index 62b0545..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/ps_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package container - -import ( - "testing" - - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestBuildContainerListOptions(t *testing.T) { - filters := opts.NewFilterOpt() - assert.NilError(t, filters.Set("foo=bar")) - assert.NilError(t, filters.Set("baz=foo")) - - contexts := []struct { - psOpts *psOptions - expectedAll bool - expectedSize bool - expectedLimit int - expectedFilters map[string]string - }{ - { - psOpts: &psOptions{ - all: true, - size: true, - last: 5, - filter: filters, - }, - expectedAll: true, - expectedSize: true, - expectedLimit: 5, - expectedFilters: map[string]string{ - "foo": "bar", - "baz": "foo", - }, - }, - { - psOpts: &psOptions{ - all: true, - size: true, - last: -1, - nLatest: true, - }, - expectedAll: true, - expectedSize: true, - expectedLimit: 1, - expectedFilters: make(map[string]string), - }, - { - psOpts: &psOptions{ - all: true, - size: false, - last: 5, - filter: filters, - // With .Size, size should be true - format: "{{.Size}}", - }, - expectedAll: true, - expectedSize: true, - expectedLimit: 5, - expectedFilters: map[string]string{ - "foo": "bar", - "baz": "foo", - }, - }, - { - psOpts: &psOptions{ - all: true, - size: false, - last: 5, - filter: filters, - // With .Size, size should be true - format: "{{.Size}} {{.CreatedAt}} {{.Networks}}", - }, - expectedAll: true, - expectedSize: true, - expectedLimit: 5, - expectedFilters: map[string]string{ - "foo": "bar", - "baz": "foo", - }, - }, - { - psOpts: &psOptions{ - all: true, - size: false, - last: 5, - filter: filters, - // Without .Size, size should be false - format: "{{.CreatedAt}} {{.Networks}}", - }, - expectedAll: true, - expectedSize: false, - expectedLimit: 5, - expectedFilters: map[string]string{ - "foo": "bar", - "baz": "foo", - }, - }, - } - - for _, c := range contexts { - options, err := buildContainerListOptions(c.psOpts) - assert.NilError(t, err) - - assert.Equal(t, c.expectedAll, options.All) - assert.Equal(t, c.expectedSize, options.Size) - assert.Equal(t, c.expectedLimit, options.Limit) - assert.Equal(t, options.Filters.Len(), len(c.expectedFilters)) - - for k, v := range c.expectedFilters { - f := options.Filters - if !f.ExactMatch(k, v) { - t.Fatalf("Expected filter with key %s to be %s but got %s", k, v, f.Get(k)) - } - } - } -} diff --git a/vendor/github.com/docker/docker/cli/command/container/rename.go b/vendor/github.com/docker/docker/cli/command/container/rename.go deleted file mode 100644 index 346fb7b..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/rename.go +++ /dev/null @@ -1,51 +0,0 @@ -package container - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type renameOptions struct { - oldName string - newName string -} - -// NewRenameCommand creates a new cobra.Command for `docker rename` -func NewRenameCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts renameOptions - - cmd := &cobra.Command{ - Use: "rename CONTAINER NEW_NAME", - Short: "Rename a container", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - opts.oldName = args[0] - opts.newName = args[1] - return runRename(dockerCli, &opts) - }, - } - return cmd -} - -func runRename(dockerCli *command.DockerCli, opts *renameOptions) error { - ctx := context.Background() - - oldName := strings.TrimSpace(opts.oldName) - newName := strings.TrimSpace(opts.newName) - - if oldName == "" || newName == "" { - return fmt.Errorf("Error: Neither old nor new names may be empty") - } - - if err := dockerCli.Client().ContainerRename(ctx, oldName, newName); err != nil { - fmt.Fprintf(dockerCli.Err(), "%s\n", err) - return fmt.Errorf("Error: failed to rename container named %s", oldName) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/restart.go b/vendor/github.com/docker/docker/cli/command/container/restart.go deleted file mode 100644 index fc3ba93..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/restart.go +++ /dev/null @@ -1,62 +0,0 @@ -package container - -import ( - "fmt" - "strings" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type restartOptions struct { - nSeconds int - nSecondsChanged bool - - containers []string -} - -// NewRestartCommand creates a new cobra.Command for `docker restart` -func NewRestartCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts restartOptions - - cmd := &cobra.Command{ - Use: "restart [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Restart one or more containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - opts.nSecondsChanged = cmd.Flags().Changed("time") - return runRestart(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.IntVarP(&opts.nSeconds, "time", "t", 10, "Seconds to wait for stop before killing the container") - return cmd -} - -func runRestart(dockerCli *command.DockerCli, opts *restartOptions) error { - ctx := context.Background() - var errs []string - var timeout *time.Duration - if opts.nSecondsChanged { - timeoutValue := time.Duration(opts.nSeconds) * time.Second - timeout = &timeoutValue - } - - for _, name := range opts.containers { - if err := dockerCli.Client().ContainerRestart(ctx, name, timeout); err != nil { - errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", name) - } - } - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/rm.go b/vendor/github.com/docker/docker/cli/command/container/rm.go deleted file mode 100644 index 60724f1..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/rm.go +++ /dev/null @@ -1,73 +0,0 @@ -package container - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type rmOptions struct { - rmVolumes bool - rmLink bool - force bool - - containers []string -} - -// NewRmCommand creates a new cobra.Command for `docker rm` -func NewRmCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts rmOptions - - cmd := &cobra.Command{ - Use: "rm [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Remove one or more containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - return runRm(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.rmVolumes, "volumes", "v", false, "Remove the volumes associated with the container") - flags.BoolVarP(&opts.rmLink, "link", "l", false, "Remove the specified link") - flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of a running container (uses SIGKILL)") - return cmd -} - -func runRm(dockerCli *command.DockerCli, opts *rmOptions) error { - ctx := context.Background() - - var errs []string - options := types.ContainerRemoveOptions{ - RemoveVolumes: opts.rmVolumes, - RemoveLinks: opts.rmLink, - Force: opts.force, - } - - errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, container string) error { - if container == "" { - return fmt.Errorf("Container name cannot be empty") - } - container = strings.Trim(container, "/") - return dockerCli.Client().ContainerRemove(ctx, container, options) - }) - - for _, name := range opts.containers { - if err := <-errChan; err != nil { - errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", name) - } - } - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/run.go b/vendor/github.com/docker/docker/cli/command/container/run.go deleted file mode 100644 index 0fad93e..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/run.go +++ /dev/null @@ -1,285 +0,0 @@ -package container - -import ( - "fmt" - "io" - "net/http/httputil" - "os" - "runtime" - "strings" - "syscall" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - opttypes "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/promise" - "github.com/docker/docker/pkg/signal" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/docker/libnetwork/resolvconf/dns" - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -type runOptions struct { - detach bool - sigProxy bool - name string - detachKeys string -} - -// NewRunCommand create a new `docker run` command -func NewRunCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts runOptions - var copts *runconfigopts.ContainerOptions - - cmd := &cobra.Command{ - Use: "run [OPTIONS] IMAGE [COMMAND] [ARG...]", - Short: "Run a command in a new container", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - copts.Image = args[0] - if len(args) > 1 { - copts.Args = args[1:] - } - return runRun(dockerCli, cmd.Flags(), &opts, copts) - }, - } - - flags := cmd.Flags() - flags.SetInterspersed(false) - - // These are flags not stored in Config/HostConfig - flags.BoolVarP(&opts.detach, "detach", "d", false, "Run container in background and print container ID") - flags.BoolVar(&opts.sigProxy, "sig-proxy", true, "Proxy received signals to the process") - flags.StringVar(&opts.name, "name", "", "Assign a name to the container") - flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container") - - // Add an explicit help that doesn't have a `-h` to prevent the conflict - // with hostname - flags.Bool("help", false, "Print usage") - - command.AddTrustedFlags(flags, true) - copts = runconfigopts.AddFlags(flags) - return cmd -} - -func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions, copts *runconfigopts.ContainerOptions) error { - stdout, stderr, stdin := dockerCli.Out(), dockerCli.Err(), dockerCli.In() - client := dockerCli.Client() - // TODO: pass this as an argument - cmdPath := "run" - - var ( - flAttach *opttypes.ListOpts - ErrConflictAttachDetach = fmt.Errorf("Conflicting options: -a and -d") - ErrConflictRestartPolicyAndAutoRemove = fmt.Errorf("Conflicting options: --restart and --rm") - ) - - config, hostConfig, networkingConfig, err := runconfigopts.Parse(flags, copts) - - // just in case the Parse does not exit - if err != nil { - reportError(stderr, cmdPath, err.Error(), true) - return cli.StatusError{StatusCode: 125} - } - - if hostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() { - return ErrConflictRestartPolicyAndAutoRemove - } - if hostConfig.OomKillDisable != nil && *hostConfig.OomKillDisable && hostConfig.Memory == 0 { - fmt.Fprintf(stderr, "WARNING: Disabling the OOM killer on containers without setting a '-m/--memory' limit may be dangerous.\n") - } - - if len(hostConfig.DNS) > 0 { - // check the DNS settings passed via --dns against - // localhost regexp to warn if they are trying to - // set a DNS to a localhost address - for _, dnsIP := range hostConfig.DNS { - if dns.IsLocalhost(dnsIP) { - fmt.Fprintf(stderr, "WARNING: Localhost DNS setting (--dns=%s) may fail in containers.\n", dnsIP) - break - } - } - } - - config.ArgsEscaped = false - - if !opts.detach { - if err := dockerCli.In().CheckTty(config.AttachStdin, config.Tty); err != nil { - return err - } - } else { - if fl := flags.Lookup("attach"); fl != nil { - flAttach = fl.Value.(*opttypes.ListOpts) - if flAttach.Len() != 0 { - return ErrConflictAttachDetach - } - } - - config.AttachStdin = false - config.AttachStdout = false - config.AttachStderr = false - config.StdinOnce = false - } - - // Disable sigProxy when in TTY mode - if config.Tty { - opts.sigProxy = false - } - - // Telling the Windows daemon the initial size of the tty during start makes - // a far better user experience rather than relying on subsequent resizes - // to cause things to catch up. - if runtime.GOOS == "windows" { - hostConfig.ConsoleSize[0], hostConfig.ConsoleSize[1] = dockerCli.Out().GetTtySize() - } - - ctx, cancelFun := context.WithCancel(context.Background()) - - createResponse, err := createContainer(ctx, dockerCli, config, hostConfig, networkingConfig, hostConfig.ContainerIDFile, opts.name) - if err != nil { - reportError(stderr, cmdPath, err.Error(), true) - return runStartContainerErr(err) - } - if opts.sigProxy { - sigc := ForwardAllSignals(ctx, dockerCli, createResponse.ID) - defer signal.StopCatch(sigc) - } - var ( - waitDisplayID chan struct{} - errCh chan error - ) - if !config.AttachStdout && !config.AttachStderr { - // Make this asynchronous to allow the client to write to stdin before having to read the ID - waitDisplayID = make(chan struct{}) - go func() { - defer close(waitDisplayID) - fmt.Fprintf(stdout, "%s\n", createResponse.ID) - }() - } - attach := config.AttachStdin || config.AttachStdout || config.AttachStderr - if attach { - var ( - out, cerr io.Writer - in io.ReadCloser - ) - if config.AttachStdin { - in = stdin - } - if config.AttachStdout { - out = stdout - } - if config.AttachStderr { - if config.Tty { - cerr = stdout - } else { - cerr = stderr - } - } - - if opts.detachKeys != "" { - dockerCli.ConfigFile().DetachKeys = opts.detachKeys - } - - options := types.ContainerAttachOptions{ - Stream: true, - Stdin: config.AttachStdin, - Stdout: config.AttachStdout, - Stderr: config.AttachStderr, - DetachKeys: dockerCli.ConfigFile().DetachKeys, - } - - resp, errAttach := client.ContainerAttach(ctx, createResponse.ID, options) - if errAttach != nil && errAttach != httputil.ErrPersistEOF { - // ContainerAttach returns an ErrPersistEOF (connection closed) - // means server met an error and put it in Hijacked connection - // keep the error and read detailed error message from hijacked connection later - return errAttach - } - defer resp.Close() - - errCh = promise.Go(func() error { - errHijack := holdHijackedConnection(ctx, dockerCli, config.Tty, in, out, cerr, resp) - if errHijack == nil { - return errAttach - } - return errHijack - }) - } - - statusChan := waitExitOrRemoved(ctx, dockerCli, createResponse.ID, hostConfig.AutoRemove) - - //start the container - if err := client.ContainerStart(ctx, createResponse.ID, types.ContainerStartOptions{}); err != nil { - // If we have holdHijackedConnection, we should notify - // holdHijackedConnection we are going to exit and wait - // to avoid the terminal are not restored. - if attach { - cancelFun() - <-errCh - } - - reportError(stderr, cmdPath, err.Error(), false) - if hostConfig.AutoRemove { - // wait container to be removed - <-statusChan - } - return runStartContainerErr(err) - } - - if (config.AttachStdin || config.AttachStdout || config.AttachStderr) && config.Tty && dockerCli.Out().IsTerminal() { - if err := MonitorTtySize(ctx, dockerCli, createResponse.ID, false); err != nil { - fmt.Fprintf(stderr, "Error monitoring TTY size: %s\n", err) - } - } - - if errCh != nil { - if err := <-errCh; err != nil { - logrus.Debugf("Error hijack: %s", err) - return err - } - } - - // Detached mode: wait for the id to be displayed and return. - if !config.AttachStdout && !config.AttachStderr { - // Detached mode - <-waitDisplayID - return nil - } - - status := <-statusChan - if status != 0 { - return cli.StatusError{StatusCode: status} - } - return nil -} - -// reportError is a utility method that prints a user-friendly message -// containing the error that occurred during parsing and a suggestion to get help -func reportError(stderr io.Writer, name string, str string, withHelp bool) { - if withHelp { - str += ".\nSee '" + os.Args[0] + " " + name + " --help'" - } - fmt.Fprintf(stderr, "%s: %s.\n", os.Args[0], str) -} - -// if container start fails with 'not found'/'no such' error, return 127 -// if container start fails with 'permission denied' error, return 126 -// return 125 for generic docker daemon failures -func runStartContainerErr(err error) error { - trimmedErr := strings.TrimPrefix(err.Error(), "Error response from daemon: ") - statusError := cli.StatusError{StatusCode: 125} - if strings.Contains(trimmedErr, "executable file not found") || - strings.Contains(trimmedErr, "no such file or directory") || - strings.Contains(trimmedErr, "system cannot find the file specified") { - statusError = cli.StatusError{StatusCode: 127} - } else if strings.Contains(trimmedErr, syscall.EACCES.Error()) { - statusError = cli.StatusError{StatusCode: 126} - } - - return statusError -} diff --git a/vendor/github.com/docker/docker/cli/command/container/start.go b/vendor/github.com/docker/docker/cli/command/container/start.go deleted file mode 100644 index 3521a41..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/start.go +++ /dev/null @@ -1,179 +0,0 @@ -package container - -import ( - "fmt" - "io" - "net/http/httputil" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/promise" - "github.com/docker/docker/pkg/signal" - "github.com/spf13/cobra" -) - -type startOptions struct { - attach bool - openStdin bool - detachKeys string - checkpoint string - checkpointDir string - - containers []string -} - -// NewStartCommand creates a new cobra.Command for `docker start` -func NewStartCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts startOptions - - cmd := &cobra.Command{ - Use: "start [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Start one or more stopped containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - return runStart(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.attach, "attach", "a", false, "Attach STDOUT/STDERR and forward signals") - flags.BoolVarP(&opts.openStdin, "interactive", "i", false, "Attach container's STDIN") - flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container") - - flags.StringVar(&opts.checkpoint, "checkpoint", "", "Restore from this checkpoint") - flags.SetAnnotation("checkpoint", "experimental", nil) - flags.StringVar(&opts.checkpointDir, "checkpoint-dir", "", "Use a custom checkpoint storage directory") - flags.SetAnnotation("checkpoint-dir", "experimental", nil) - return cmd -} - -func runStart(dockerCli *command.DockerCli, opts *startOptions) error { - ctx, cancelFun := context.WithCancel(context.Background()) - - if opts.attach || opts.openStdin { - // We're going to attach to a container. - // 1. Ensure we only have one container. - if len(opts.containers) > 1 { - return fmt.Errorf("You cannot start and attach multiple containers at once.") - } - - // 2. Attach to the container. - container := opts.containers[0] - c, err := dockerCli.Client().ContainerInspect(ctx, container) - if err != nil { - return err - } - - // We always use c.ID instead of container to maintain consistency during `docker start` - if !c.Config.Tty { - sigc := ForwardAllSignals(ctx, dockerCli, c.ID) - defer signal.StopCatch(sigc) - } - - if opts.detachKeys != "" { - dockerCli.ConfigFile().DetachKeys = opts.detachKeys - } - - options := types.ContainerAttachOptions{ - Stream: true, - Stdin: opts.openStdin && c.Config.OpenStdin, - Stdout: true, - Stderr: true, - DetachKeys: dockerCli.ConfigFile().DetachKeys, - } - - var in io.ReadCloser - - if options.Stdin { - in = dockerCli.In() - } - - resp, errAttach := dockerCli.Client().ContainerAttach(ctx, c.ID, options) - if errAttach != nil && errAttach != httputil.ErrPersistEOF { - // ContainerAttach return an ErrPersistEOF (connection closed) - // means server met an error and already put it in Hijacked connection, - // we would keep the error and read the detailed error message from hijacked connection - return errAttach - } - defer resp.Close() - cErr := promise.Go(func() error { - errHijack := holdHijackedConnection(ctx, dockerCli, c.Config.Tty, in, dockerCli.Out(), dockerCli.Err(), resp) - if errHijack == nil { - return errAttach - } - return errHijack - }) - - // 3. We should open a channel for receiving status code of the container - // no matter it's detached, removed on daemon side(--rm) or exit normally. - statusChan := waitExitOrRemoved(ctx, dockerCli, c.ID, c.HostConfig.AutoRemove) - startOptions := types.ContainerStartOptions{ - CheckpointID: opts.checkpoint, - CheckpointDir: opts.checkpointDir, - } - - // 4. Start the container. - if err := dockerCli.Client().ContainerStart(ctx, c.ID, startOptions); err != nil { - cancelFun() - <-cErr - if c.HostConfig.AutoRemove { - // wait container to be removed - <-statusChan - } - return err - } - - // 5. Wait for attachment to break. - if c.Config.Tty && dockerCli.Out().IsTerminal() { - if err := MonitorTtySize(ctx, dockerCli, c.ID, false); err != nil { - fmt.Fprintf(dockerCli.Err(), "Error monitoring TTY size: %s\n", err) - } - } - if attchErr := <-cErr; attchErr != nil { - return attchErr - } - - if status := <-statusChan; status != 0 { - return cli.StatusError{StatusCode: status} - } - } else if opts.checkpoint != "" { - if len(opts.containers) > 1 { - return fmt.Errorf("You cannot restore multiple containers at once.") - } - container := opts.containers[0] - startOptions := types.ContainerStartOptions{ - CheckpointID: opts.checkpoint, - CheckpointDir: opts.checkpointDir, - } - return dockerCli.Client().ContainerStart(ctx, container, startOptions) - - } else { - // We're not going to attach to anything. - // Start as many containers as we want. - return startContainersWithoutAttachments(ctx, dockerCli, opts.containers) - } - - return nil -} - -func startContainersWithoutAttachments(ctx context.Context, dockerCli *command.DockerCli, containers []string) error { - var failedContainers []string - for _, container := range containers { - if err := dockerCli.Client().ContainerStart(ctx, container, types.ContainerStartOptions{}); err != nil { - fmt.Fprintf(dockerCli.Err(), "%s\n", err) - failedContainers = append(failedContainers, container) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", container) - } - } - - if len(failedContainers) > 0 { - return fmt.Errorf("Error: failed to start containers: %v", strings.Join(failedContainers, ", ")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/stats.go b/vendor/github.com/docker/docker/cli/command/container/stats.go deleted file mode 100644 index 12d5c68..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/stats.go +++ /dev/null @@ -1,243 +0,0 @@ -package container - -import ( - "fmt" - "io" - "strings" - "sync" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/formatter" - "github.com/spf13/cobra" -) - -type statsOptions struct { - all bool - noStream bool - format string - containers []string -} - -// NewStatsCommand creates a new cobra.Command for `docker stats` -func NewStatsCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts statsOptions - - cmd := &cobra.Command{ - Use: "stats [OPTIONS] [CONTAINER...]", - Short: "Display a live stream of container(s) resource usage statistics", - Args: cli.RequiresMinArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - return runStats(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.all, "all", "a", false, "Show all containers (default shows just running)") - flags.BoolVar(&opts.noStream, "no-stream", false, "Disable streaming stats and only pull the first result") - flags.StringVar(&opts.format, "format", "", "Pretty-print images using a Go template") - return cmd -} - -// runStats displays a live stream of resource usage statistics for one or more containers. -// This shows real-time information on CPU usage, memory usage, and network I/O. -func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { - showAll := len(opts.containers) == 0 - closeChan := make(chan error) - - ctx := context.Background() - - // monitorContainerEvents watches for container creation and removal (only - // used when calling `docker stats` without arguments). - monitorContainerEvents := func(started chan<- struct{}, c chan events.Message) { - f := filters.NewArgs() - f.Add("type", "container") - options := types.EventsOptions{ - Filters: f, - } - - eventq, errq := dockerCli.Client().Events(ctx, options) - - // Whether we successfully subscribed to eventq or not, we can now - // unblock the main goroutine. - close(started) - - for { - select { - case event := <-eventq: - c <- event - case err := <-errq: - closeChan <- err - return - } - } - } - - // Get the daemonOSType if not set already - if daemonOSType == "" { - svctx := context.Background() - sv, err := dockerCli.Client().ServerVersion(svctx) - if err != nil { - return err - } - daemonOSType = sv.Os - } - - // waitFirst is a WaitGroup to wait first stat data's reach for each container - waitFirst := &sync.WaitGroup{} - - cStats := stats{} - // getContainerList simulates creation event for all previously existing - // containers (only used when calling `docker stats` without arguments). - getContainerList := func() { - options := types.ContainerListOptions{ - All: opts.all, - } - cs, err := dockerCli.Client().ContainerList(ctx, options) - if err != nil { - closeChan <- err - } - for _, container := range cs { - s := formatter.NewContainerStats(container.ID[:12], daemonOSType) - if cStats.add(s) { - waitFirst.Add(1) - go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) - } - } - } - - if showAll { - // If no names were specified, start a long running goroutine which - // monitors container events. We make sure we're subscribed before - // retrieving the list of running containers to avoid a race where we - // would "miss" a creation. - started := make(chan struct{}) - eh := command.InitEventHandler() - eh.Handle("create", func(e events.Message) { - if opts.all { - s := formatter.NewContainerStats(e.ID[:12], daemonOSType) - if cStats.add(s) { - waitFirst.Add(1) - go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) - } - } - }) - - eh.Handle("start", func(e events.Message) { - s := formatter.NewContainerStats(e.ID[:12], daemonOSType) - if cStats.add(s) { - waitFirst.Add(1) - go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) - } - }) - - eh.Handle("die", func(e events.Message) { - if !opts.all { - cStats.remove(e.ID[:12]) - } - }) - - eventChan := make(chan events.Message) - go eh.Watch(eventChan) - go monitorContainerEvents(started, eventChan) - defer close(eventChan) - <-started - - // Start a short-lived goroutine to retrieve the initial list of - // containers. - getContainerList() - } else { - // Artificially send creation events for the containers we were asked to - // monitor (same code path than we use when monitoring all containers). - for _, name := range opts.containers { - s := formatter.NewContainerStats(name, daemonOSType) - if cStats.add(s) { - waitFirst.Add(1) - go collect(ctx, s, dockerCli.Client(), !opts.noStream, waitFirst) - } - } - - // We don't expect any asynchronous errors: closeChan can be closed. - close(closeChan) - - // Do a quick pause to detect any error with the provided list of - // container names. - time.Sleep(1500 * time.Millisecond) - var errs []string - cStats.mu.Lock() - for _, c := range cStats.cs { - cErr := c.GetError() - if cErr != nil { - errs = append(errs, fmt.Sprintf("%s: %v", c.Name, cErr)) - } - } - cStats.mu.Unlock() - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, ", ")) - } - } - - // before print to screen, make sure each container get at least one valid stat data - waitFirst.Wait() - format := opts.format - if len(format) == 0 { - if len(dockerCli.ConfigFile().StatsFormat) > 0 { - format = dockerCli.ConfigFile().StatsFormat - } else { - format = formatter.TableFormatKey - } - } - statsCtx := formatter.Context{ - Output: dockerCli.Out(), - Format: formatter.NewStatsFormat(format, daemonOSType), - } - cleanScreen := func() { - if !opts.noStream { - fmt.Fprint(dockerCli.Out(), "\033[2J") - fmt.Fprint(dockerCli.Out(), "\033[H") - } - } - - var err error - for range time.Tick(500 * time.Millisecond) { - cleanScreen() - ccstats := []formatter.StatsEntry{} - cStats.mu.Lock() - for _, c := range cStats.cs { - ccstats = append(ccstats, c.GetStatistics()) - } - cStats.mu.Unlock() - if err = formatter.ContainerStatsWrite(statsCtx, ccstats); err != nil { - break - } - if len(cStats.cs) == 0 && !showAll { - break - } - if opts.noStream { - break - } - select { - case err, ok := <-closeChan: - if ok { - if err != nil { - // this is suppressing "unexpected EOF" in the cli when the - // daemon restarts so it shutdowns cleanly - if err == io.ErrUnexpectedEOF { - return nil - } - return err - } - } - default: - // just skip - } - } - return err -} diff --git a/vendor/github.com/docker/docker/cli/command/container/stats_helpers.go b/vendor/github.com/docker/docker/cli/command/container/stats_helpers.go deleted file mode 100644 index 4b57e3f..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/stats_helpers.go +++ /dev/null @@ -1,226 +0,0 @@ -package container - -import ( - "encoding/json" - "errors" - "io" - "strings" - "sync" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli/command/formatter" - "github.com/docker/docker/client" - "golang.org/x/net/context" -) - -type stats struct { - ostype string - mu sync.Mutex - cs []*formatter.ContainerStats -} - -// daemonOSType is set once we have at least one stat for a container -// from the daemon. It is used to ensure we print the right header based -// on the daemon platform. -var daemonOSType string - -func (s *stats) add(cs *formatter.ContainerStats) bool { - s.mu.Lock() - defer s.mu.Unlock() - if _, exists := s.isKnownContainer(cs.Container); !exists { - s.cs = append(s.cs, cs) - return true - } - return false -} - -func (s *stats) remove(id string) { - s.mu.Lock() - if i, exists := s.isKnownContainer(id); exists { - s.cs = append(s.cs[:i], s.cs[i+1:]...) - } - s.mu.Unlock() -} - -func (s *stats) isKnownContainer(cid string) (int, bool) { - for i, c := range s.cs { - if c.Container == cid { - return i, true - } - } - return -1, false -} - -func collect(ctx context.Context, s *formatter.ContainerStats, cli client.APIClient, streamStats bool, waitFirst *sync.WaitGroup) { - logrus.Debugf("collecting stats for %s", s.Container) - var ( - getFirst bool - previousCPU uint64 - previousSystem uint64 - u = make(chan error, 1) - ) - - defer func() { - // if error happens and we get nothing of stats, release wait group whatever - if !getFirst { - getFirst = true - waitFirst.Done() - } - }() - - response, err := cli.ContainerStats(ctx, s.Container, streamStats) - if err != nil { - s.SetError(err) - return - } - defer response.Body.Close() - - dec := json.NewDecoder(response.Body) - go func() { - for { - var ( - v *types.StatsJSON - memPercent = 0.0 - cpuPercent = 0.0 - blkRead, blkWrite uint64 // Only used on Linux - mem = 0.0 - memLimit = 0.0 - memPerc = 0.0 - pidsStatsCurrent uint64 - ) - - if err := dec.Decode(&v); err != nil { - dec = json.NewDecoder(io.MultiReader(dec.Buffered(), response.Body)) - u <- err - if err == io.EOF { - break - } - time.Sleep(100 * time.Millisecond) - continue - } - - daemonOSType = response.OSType - - if daemonOSType != "windows" { - // MemoryStats.Limit will never be 0 unless the container is not running and we haven't - // got any data from cgroup - if v.MemoryStats.Limit != 0 { - memPercent = float64(v.MemoryStats.Usage) / float64(v.MemoryStats.Limit) * 100.0 - } - previousCPU = v.PreCPUStats.CPUUsage.TotalUsage - previousSystem = v.PreCPUStats.SystemUsage - cpuPercent = calculateCPUPercentUnix(previousCPU, previousSystem, v) - blkRead, blkWrite = calculateBlockIO(v.BlkioStats) - mem = float64(v.MemoryStats.Usage) - memLimit = float64(v.MemoryStats.Limit) - memPerc = memPercent - pidsStatsCurrent = v.PidsStats.Current - } else { - cpuPercent = calculateCPUPercentWindows(v) - blkRead = v.StorageStats.ReadSizeBytes - blkWrite = v.StorageStats.WriteSizeBytes - mem = float64(v.MemoryStats.PrivateWorkingSet) - } - netRx, netTx := calculateNetwork(v.Networks) - s.SetStatistics(formatter.StatsEntry{ - Name: v.Name, - ID: v.ID, - CPUPercentage: cpuPercent, - Memory: mem, - MemoryPercentage: memPerc, - MemoryLimit: memLimit, - NetworkRx: netRx, - NetworkTx: netTx, - BlockRead: float64(blkRead), - BlockWrite: float64(blkWrite), - PidsCurrent: pidsStatsCurrent, - }) - u <- nil - if !streamStats { - return - } - } - }() - for { - select { - case <-time.After(2 * time.Second): - // zero out the values if we have not received an update within - // the specified duration. - s.SetErrorAndReset(errors.New("timeout waiting for stats")) - // if this is the first stat you get, release WaitGroup - if !getFirst { - getFirst = true - waitFirst.Done() - } - case err := <-u: - if err != nil { - s.SetError(err) - continue - } - s.SetError(nil) - // if this is the first stat you get, release WaitGroup - if !getFirst { - getFirst = true - waitFirst.Done() - } - } - if !streamStats { - return - } - } -} - -func calculateCPUPercentUnix(previousCPU, previousSystem uint64, v *types.StatsJSON) float64 { - var ( - cpuPercent = 0.0 - // calculate the change for the cpu usage of the container in between readings - cpuDelta = float64(v.CPUStats.CPUUsage.TotalUsage) - float64(previousCPU) - // calculate the change for the entire system between readings - systemDelta = float64(v.CPUStats.SystemUsage) - float64(previousSystem) - ) - - if systemDelta > 0.0 && cpuDelta > 0.0 { - cpuPercent = (cpuDelta / systemDelta) * float64(len(v.CPUStats.CPUUsage.PercpuUsage)) * 100.0 - } - return cpuPercent -} - -func calculateCPUPercentWindows(v *types.StatsJSON) float64 { - // Max number of 100ns intervals between the previous time read and now - possIntervals := uint64(v.Read.Sub(v.PreRead).Nanoseconds()) // Start with number of ns intervals - possIntervals /= 100 // Convert to number of 100ns intervals - possIntervals *= uint64(v.NumProcs) // Multiple by the number of processors - - // Intervals used - intervalsUsed := v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage - - // Percentage avoiding divide-by-zero - if possIntervals > 0 { - return float64(intervalsUsed) / float64(possIntervals) * 100.0 - } - return 0.00 -} - -func calculateBlockIO(blkio types.BlkioStats) (blkRead uint64, blkWrite uint64) { - for _, bioEntry := range blkio.IoServiceBytesRecursive { - switch strings.ToLower(bioEntry.Op) { - case "read": - blkRead = blkRead + bioEntry.Value - case "write": - blkWrite = blkWrite + bioEntry.Value - } - } - return -} - -func calculateNetwork(network map[string]types.NetworkStats) (float64, float64) { - var rx, tx float64 - - for _, v := range network { - rx += float64(v.RxBytes) - tx += float64(v.TxBytes) - } - return rx, tx -} diff --git a/vendor/github.com/docker/docker/cli/command/container/stats_unit_test.go b/vendor/github.com/docker/docker/cli/command/container/stats_unit_test.go deleted file mode 100644 index 828d634..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/stats_unit_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package container - -import ( - "testing" - - "github.com/docker/docker/api/types" -) - -func TestCalculateBlockIO(t *testing.T) { - blkio := types.BlkioStats{ - IoServiceBytesRecursive: []types.BlkioStatEntry{{8, 0, "read", 1234}, {8, 1, "read", 4567}, {8, 0, "write", 123}, {8, 1, "write", 456}}, - } - blkRead, blkWrite := calculateBlockIO(blkio) - if blkRead != 5801 { - t.Fatalf("blkRead = %d, want 5801", blkRead) - } - if blkWrite != 579 { - t.Fatalf("blkWrite = %d, want 579", blkWrite) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/container/stop.go b/vendor/github.com/docker/docker/cli/command/container/stop.go deleted file mode 100644 index c68ede5..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/stop.go +++ /dev/null @@ -1,67 +0,0 @@ -package container - -import ( - "fmt" - "strings" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type stopOptions struct { - time int - timeChanged bool - - containers []string -} - -// NewStopCommand creates a new cobra.Command for `docker stop` -func NewStopCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts stopOptions - - cmd := &cobra.Command{ - Use: "stop [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Stop one or more running containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - opts.timeChanged = cmd.Flags().Changed("time") - return runStop(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.IntVarP(&opts.time, "time", "t", 10, "Seconds to wait for stop before killing it") - return cmd -} - -func runStop(dockerCli *command.DockerCli, opts *stopOptions) error { - ctx := context.Background() - - var timeout *time.Duration - if opts.timeChanged { - timeoutValue := time.Duration(opts.time) * time.Second - timeout = &timeoutValue - } - - var errs []string - - errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, id string) error { - return dockerCli.Client().ContainerStop(ctx, id, timeout) - }) - for _, container := range opts.containers { - if err := <-errChan; err != nil { - errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", container) - } - } - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/top.go b/vendor/github.com/docker/docker/cli/command/container/top.go deleted file mode 100644 index 160153b..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/top.go +++ /dev/null @@ -1,58 +0,0 @@ -package container - -import ( - "fmt" - "strings" - "text/tabwriter" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type topOptions struct { - container string - - args []string -} - -// NewTopCommand creates a new cobra.Command for `docker top` -func NewTopCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts topOptions - - cmd := &cobra.Command{ - Use: "top CONTAINER [ps OPTIONS]", - Short: "Display the running processes of a container", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.container = args[0] - opts.args = args[1:] - return runTop(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.SetInterspersed(false) - - return cmd -} - -func runTop(dockerCli *command.DockerCli, opts *topOptions) error { - ctx := context.Background() - - procList, err := dockerCli.Client().ContainerTop(ctx, opts.container, opts.args) - if err != nil { - return err - } - - w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0) - fmt.Fprintln(w, strings.Join(procList.Titles, "\t")) - - for _, proc := range procList.Processes { - fmt.Fprintln(w, strings.Join(proc, "\t")) - } - w.Flush() - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/tty.go b/vendor/github.com/docker/docker/cli/command/container/tty.go deleted file mode 100644 index 6af8e2b..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/tty.go +++ /dev/null @@ -1,103 +0,0 @@ -package container - -import ( - "fmt" - "os" - gosignal "os/signal" - "runtime" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/client" - "github.com/docker/docker/pkg/signal" - "golang.org/x/net/context" -) - -// resizeTtyTo resizes tty to specific height and width -func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) { - if height == 0 && width == 0 { - return - } - - options := types.ResizeOptions{ - Height: height, - Width: width, - } - - var err error - if isExec { - err = client.ContainerExecResize(ctx, id, options) - } else { - err = client.ContainerResize(ctx, id, options) - } - - if err != nil { - logrus.Debugf("Error resize: %s", err) - } -} - -// MonitorTtySize updates the container tty size when the terminal tty changes size -func MonitorTtySize(ctx context.Context, cli *command.DockerCli, id string, isExec bool) error { - resizeTty := func() { - height, width := cli.Out().GetTtySize() - resizeTtyTo(ctx, cli.Client(), id, height, width, isExec) - } - - resizeTty() - - if runtime.GOOS == "windows" { - go func() { - prevH, prevW := cli.Out().GetTtySize() - for { - time.Sleep(time.Millisecond * 250) - h, w := cli.Out().GetTtySize() - - if prevW != w || prevH != h { - resizeTty() - } - prevH = h - prevW = w - } - }() - } else { - sigchan := make(chan os.Signal, 1) - gosignal.Notify(sigchan, signal.SIGWINCH) - go func() { - for range sigchan { - resizeTty() - } - }() - } - return nil -} - -// ForwardAllSignals forwards signals to the container -func ForwardAllSignals(ctx context.Context, cli *command.DockerCli, cid string) chan os.Signal { - sigc := make(chan os.Signal, 128) - signal.CatchAll(sigc) - go func() { - for s := range sigc { - if s == signal.SIGCHLD || s == signal.SIGPIPE { - continue - } - var sig string - for sigStr, sigN := range signal.SignalMap { - if sigN == s { - sig = sigStr - break - } - } - if sig == "" { - fmt.Fprintf(cli.Err(), "Unsupported signal: %v. Discarding.\n", s) - continue - } - - if err := cli.Client().ContainerKill(ctx, cid, sig); err != nil { - logrus.Debugf("Error sending signal: %s", err) - } - } - }() - return sigc -} diff --git a/vendor/github.com/docker/docker/cli/command/container/unpause.go b/vendor/github.com/docker/docker/cli/command/container/unpause.go deleted file mode 100644 index c4d8d48..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/unpause.go +++ /dev/null @@ -1,50 +0,0 @@ -package container - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type unpauseOptions struct { - containers []string -} - -// NewUnpauseCommand creates a new cobra.Command for `docker unpause` -func NewUnpauseCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts unpauseOptions - - cmd := &cobra.Command{ - Use: "unpause CONTAINER [CONTAINER...]", - Short: "Unpause all processes within one or more containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - return runUnpause(dockerCli, &opts) - }, - } - return cmd -} - -func runUnpause(dockerCli *command.DockerCli, opts *unpauseOptions) error { - ctx := context.Background() - - var errs []string - errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerUnpause) - for _, container := range opts.containers { - if err := <-errChan; err != nil { - errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", container) - } - } - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/update.go b/vendor/github.com/docker/docker/cli/command/container/update.go deleted file mode 100644 index 7576585..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/update.go +++ /dev/null @@ -1,163 +0,0 @@ -package container - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type updateOptions struct { - blkioWeight uint16 - cpuPeriod int64 - cpuQuota int64 - cpuRealtimePeriod int64 - cpuRealtimeRuntime int64 - cpusetCpus string - cpusetMems string - cpuShares int64 - memoryString string - memoryReservation string - memorySwap string - kernelMemory string - restartPolicy string - - nFlag int - - containers []string -} - -// NewUpdateCommand creates a new cobra.Command for `docker update` -func NewUpdateCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts updateOptions - - cmd := &cobra.Command{ - Use: "update [OPTIONS] CONTAINER [CONTAINER...]", - Short: "Update configuration of one or more containers", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - opts.nFlag = cmd.Flags().NFlag() - return runUpdate(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.Uint16Var(&opts.blkioWeight, "blkio-weight", 0, "Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)") - flags.Int64Var(&opts.cpuPeriod, "cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period") - flags.Int64Var(&opts.cpuQuota, "cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota") - flags.Int64Var(&opts.cpuRealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds") - flags.Int64Var(&opts.cpuRealtimeRuntime, "cpu-rt-runtime", 0, "Limit the CPU real-time runtime in microseconds") - flags.StringVar(&opts.cpusetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)") - flags.StringVar(&opts.cpusetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)") - flags.Int64VarP(&opts.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)") - flags.StringVarP(&opts.memoryString, "memory", "m", "", "Memory limit") - flags.StringVar(&opts.memoryReservation, "memory-reservation", "", "Memory soft limit") - flags.StringVar(&opts.memorySwap, "memory-swap", "", "Swap limit equal to memory plus swap: '-1' to enable unlimited swap") - flags.StringVar(&opts.kernelMemory, "kernel-memory", "", "Kernel memory limit") - flags.StringVar(&opts.restartPolicy, "restart", "", "Restart policy to apply when a container exits") - - return cmd -} - -func runUpdate(dockerCli *command.DockerCli, opts *updateOptions) error { - var err error - - if opts.nFlag == 0 { - return fmt.Errorf("You must provide one or more flags when using this command.") - } - - var memory int64 - if opts.memoryString != "" { - memory, err = units.RAMInBytes(opts.memoryString) - if err != nil { - return err - } - } - - var memoryReservation int64 - if opts.memoryReservation != "" { - memoryReservation, err = units.RAMInBytes(opts.memoryReservation) - if err != nil { - return err - } - } - - var memorySwap int64 - if opts.memorySwap != "" { - if opts.memorySwap == "-1" { - memorySwap = -1 - } else { - memorySwap, err = units.RAMInBytes(opts.memorySwap) - if err != nil { - return err - } - } - } - - var kernelMemory int64 - if opts.kernelMemory != "" { - kernelMemory, err = units.RAMInBytes(opts.kernelMemory) - if err != nil { - return err - } - } - - var restartPolicy containertypes.RestartPolicy - if opts.restartPolicy != "" { - restartPolicy, err = runconfigopts.ParseRestartPolicy(opts.restartPolicy) - if err != nil { - return err - } - } - - resources := containertypes.Resources{ - BlkioWeight: opts.blkioWeight, - CpusetCpus: opts.cpusetCpus, - CpusetMems: opts.cpusetMems, - CPUShares: opts.cpuShares, - Memory: memory, - MemoryReservation: memoryReservation, - MemorySwap: memorySwap, - KernelMemory: kernelMemory, - CPUPeriod: opts.cpuPeriod, - CPUQuota: opts.cpuQuota, - CPURealtimePeriod: opts.cpuRealtimePeriod, - CPURealtimeRuntime: opts.cpuRealtimeRuntime, - } - - updateConfig := containertypes.UpdateConfig{ - Resources: resources, - RestartPolicy: restartPolicy, - } - - ctx := context.Background() - - var ( - warns []string - errs []string - ) - for _, container := range opts.containers { - r, err := dockerCli.Client().ContainerUpdate(ctx, container, updateConfig) - if err != nil { - errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%s\n", container) - } - warns = append(warns, r.Warnings...) - } - if len(warns) > 0 { - fmt.Fprintf(dockerCli.Out(), "%s", strings.Join(warns, "\n")) - } - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/container/utils.go b/vendor/github.com/docker/docker/cli/command/container/utils.go deleted file mode 100644 index 6bef924..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/utils.go +++ /dev/null @@ -1,143 +0,0 @@ -package container - -import ( - "strconv" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/cli/command" - clientapi "github.com/docker/docker/client" -) - -func waitExitOrRemoved(ctx context.Context, dockerCli *command.DockerCli, containerID string, waitRemove bool) chan int { - if len(containerID) == 0 { - // containerID can never be empty - panic("Internal Error: waitExitOrRemoved needs a containerID as parameter") - } - - var removeErr error - statusChan := make(chan int) - exitCode := 125 - - // Get events via Events API - f := filters.NewArgs() - f.Add("type", "container") - f.Add("container", containerID) - options := types.EventsOptions{ - Filters: f, - } - eventCtx, cancel := context.WithCancel(ctx) - eventq, errq := dockerCli.Client().Events(eventCtx, options) - - eventProcessor := func(e events.Message) bool { - stopProcessing := false - switch e.Status { - case "die": - if v, ok := e.Actor.Attributes["exitCode"]; ok { - code, cerr := strconv.Atoi(v) - if cerr != nil { - logrus.Errorf("failed to convert exitcode '%q' to int: %v", v, cerr) - } else { - exitCode = code - } - } - if !waitRemove { - stopProcessing = true - } else { - // If we are talking to an older daemon, `AutoRemove` is not supported. - // We need to fall back to the old behavior, which is client-side removal - if versions.LessThan(dockerCli.Client().ClientVersion(), "1.25") { - go func() { - removeErr = dockerCli.Client().ContainerRemove(ctx, containerID, types.ContainerRemoveOptions{RemoveVolumes: true}) - if removeErr != nil { - logrus.Errorf("error removing container: %v", removeErr) - cancel() // cancel the event Q - } - }() - } - } - case "detach": - exitCode = 0 - stopProcessing = true - case "destroy": - stopProcessing = true - } - return stopProcessing - } - - go func() { - defer func() { - statusChan <- exitCode // must always send an exit code or the caller will block - cancel() - }() - - for { - select { - case <-eventCtx.Done(): - if removeErr != nil { - return - } - case evt := <-eventq: - if eventProcessor(evt) { - return - } - case err := <-errq: - logrus.Errorf("error getting events from daemon: %v", err) - return - } - } - }() - - return statusChan -} - -// getExitCode performs an inspect on the container. It returns -// the running state and the exit code. -func getExitCode(ctx context.Context, dockerCli *command.DockerCli, containerID string) (bool, int, error) { - c, err := dockerCli.Client().ContainerInspect(ctx, containerID) - if err != nil { - // If we can't connect, then the daemon probably died. - if !clientapi.IsErrConnectionFailed(err) { - return false, -1, err - } - return false, -1, nil - } - return c.State.Running, c.State.ExitCode, nil -} - -func parallelOperation(ctx context.Context, containers []string, op func(ctx context.Context, container string) error) chan error { - if len(containers) == 0 { - return nil - } - const defaultParallel int = 50 - sem := make(chan struct{}, defaultParallel) - errChan := make(chan error) - - // make sure result is printed in correct order - output := map[string]chan error{} - for _, c := range containers { - output[c] = make(chan error, 1) - } - go func() { - for _, c := range containers { - err := <-output[c] - errChan <- err - } - }() - - go func() { - for _, c := range containers { - sem <- struct{}{} // Wait for active queue sem to drain. - go func(container string) { - output[container] <- op(ctx, container) - <-sem - }(c) - } - }() - return errChan -} diff --git a/vendor/github.com/docker/docker/cli/command/container/wait.go b/vendor/github.com/docker/docker/cli/command/container/wait.go deleted file mode 100644 index 19ccf7a..0000000 --- a/vendor/github.com/docker/docker/cli/command/container/wait.go +++ /dev/null @@ -1,50 +0,0 @@ -package container - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type waitOptions struct { - containers []string -} - -// NewWaitCommand creates a new cobra.Command for `docker wait` -func NewWaitCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts waitOptions - - cmd := &cobra.Command{ - Use: "wait CONTAINER [CONTAINER...]", - Short: "Block until one or more containers stop, then print their exit codes", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.containers = args - return runWait(dockerCli, &opts) - }, - } - return cmd -} - -func runWait(dockerCli *command.DockerCli, opts *waitOptions) error { - ctx := context.Background() - - var errs []string - for _, container := range opts.containers { - status, err := dockerCli.Client().ContainerWait(ctx, container) - if err != nil { - errs = append(errs, err.Error()) - } else { - fmt.Fprintf(dockerCli.Out(), "%d\n", status) - } - } - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/events_utils.go b/vendor/github.com/docker/docker/cli/command/events_utils.go deleted file mode 100644 index e710c97..0000000 --- a/vendor/github.com/docker/docker/cli/command/events_utils.go +++ /dev/null @@ -1,49 +0,0 @@ -package command - -import ( - "sync" - - "github.com/Sirupsen/logrus" - eventtypes "github.com/docker/docker/api/types/events" -) - -type eventProcessor func(eventtypes.Message, error) error - -// EventHandler is abstract interface for user to customize -// own handle functions of each type of events -type EventHandler interface { - Handle(action string, h func(eventtypes.Message)) - Watch(c <-chan eventtypes.Message) -} - -// InitEventHandler initializes and returns an EventHandler -func InitEventHandler() EventHandler { - return &eventHandler{handlers: make(map[string]func(eventtypes.Message))} -} - -type eventHandler struct { - handlers map[string]func(eventtypes.Message) - mu sync.Mutex -} - -func (w *eventHandler) Handle(action string, h func(eventtypes.Message)) { - w.mu.Lock() - w.handlers[action] = h - w.mu.Unlock() -} - -// Watch ranges over the passed in event chan and processes the events based on the -// handlers created for a given action. -// To stop watching, close the event chan. -func (w *eventHandler) Watch(c <-chan eventtypes.Message) { - for e := range c { - w.mu.Lock() - h, exists := w.handlers[e.Action] - w.mu.Unlock() - if !exists { - continue - } - logrus.Debugf("event handler: received event: %v", e) - go h(e) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/container.go b/vendor/github.com/docker/docker/cli/command/formatter/container.go deleted file mode 100644 index 6273453..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/container.go +++ /dev/null @@ -1,235 +0,0 @@ -package formatter - -import ( - "fmt" - "strconv" - "strings" - "time" - - "github.com/docker/docker/api" - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/stringutils" - units "github.com/docker/go-units" -) - -const ( - defaultContainerTableFormat = "table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.RunningFor}} ago\t{{.Status}}\t{{.Ports}}\t{{.Names}}" - - containerIDHeader = "CONTAINER ID" - namesHeader = "NAMES" - commandHeader = "COMMAND" - runningForHeader = "CREATED" - statusHeader = "STATUS" - portsHeader = "PORTS" - mountsHeader = "MOUNTS" - localVolumes = "LOCAL VOLUMES" - networksHeader = "NETWORKS" -) - -// NewContainerFormat returns a Format for rendering using a Context -func NewContainerFormat(source string, quiet bool, size bool) Format { - switch source { - case TableFormatKey: - if quiet { - return defaultQuietFormat - } - format := defaultContainerTableFormat - if size { - format += `\t{{.Size}}` - } - return Format(format) - case RawFormatKey: - if quiet { - return `container_id: {{.ID}}` - } - format := `container_id: {{.ID}} -image: {{.Image}} -command: {{.Command}} -created_at: {{.CreatedAt}} -status: {{- pad .Status 1 0}} -names: {{.Names}} -labels: {{- pad .Labels 1 0}} -ports: {{- pad .Ports 1 0}} -` - if size { - format += `size: {{.Size}}\n` - } - return Format(format) - } - return Format(source) -} - -// ContainerWrite renders the context for a list of containers -func ContainerWrite(ctx Context, containers []types.Container) error { - render := func(format func(subContext subContext) error) error { - for _, container := range containers { - err := format(&containerContext{trunc: ctx.Trunc, c: container}) - if err != nil { - return err - } - } - return nil - } - return ctx.Write(&containerContext{}, render) -} - -type containerContext struct { - HeaderContext - trunc bool - c types.Container -} - -func (c *containerContext) MarshalJSON() ([]byte, error) { - return marshalJSON(c) -} - -func (c *containerContext) ID() string { - c.AddHeader(containerIDHeader) - if c.trunc { - return stringid.TruncateID(c.c.ID) - } - return c.c.ID -} - -func (c *containerContext) Names() string { - c.AddHeader(namesHeader) - names := stripNamePrefix(c.c.Names) - if c.trunc { - for _, name := range names { - if len(strings.Split(name, "/")) == 1 { - names = []string{name} - break - } - } - } - return strings.Join(names, ",") -} - -func (c *containerContext) Image() string { - c.AddHeader(imageHeader) - if c.c.Image == "" { - return "" - } - if c.trunc { - if trunc := stringid.TruncateID(c.c.ImageID); trunc == stringid.TruncateID(c.c.Image) { - return trunc - } - } - return c.c.Image -} - -func (c *containerContext) Command() string { - c.AddHeader(commandHeader) - command := c.c.Command - if c.trunc { - command = stringutils.Ellipsis(command, 20) - } - return strconv.Quote(command) -} - -func (c *containerContext) CreatedAt() string { - c.AddHeader(createdAtHeader) - return time.Unix(int64(c.c.Created), 0).String() -} - -func (c *containerContext) RunningFor() string { - c.AddHeader(runningForHeader) - createdAt := time.Unix(int64(c.c.Created), 0) - return units.HumanDuration(time.Now().UTC().Sub(createdAt)) -} - -func (c *containerContext) Ports() string { - c.AddHeader(portsHeader) - return api.DisplayablePorts(c.c.Ports) -} - -func (c *containerContext) Status() string { - c.AddHeader(statusHeader) - return c.c.Status -} - -func (c *containerContext) Size() string { - c.AddHeader(sizeHeader) - srw := units.HumanSizeWithPrecision(float64(c.c.SizeRw), 3) - sv := units.HumanSizeWithPrecision(float64(c.c.SizeRootFs), 3) - - sf := srw - if c.c.SizeRootFs > 0 { - sf = fmt.Sprintf("%s (virtual %s)", srw, sv) - } - return sf -} - -func (c *containerContext) Labels() string { - c.AddHeader(labelsHeader) - if c.c.Labels == nil { - return "" - } - - var joinLabels []string - for k, v := range c.c.Labels { - joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v)) - } - return strings.Join(joinLabels, ",") -} - -func (c *containerContext) Label(name string) string { - n := strings.Split(name, ".") - r := strings.NewReplacer("-", " ", "_", " ") - h := r.Replace(n[len(n)-1]) - - c.AddHeader(h) - - if c.c.Labels == nil { - return "" - } - return c.c.Labels[name] -} - -func (c *containerContext) Mounts() string { - c.AddHeader(mountsHeader) - - var name string - var mounts []string - for _, m := range c.c.Mounts { - if m.Name == "" { - name = m.Source - } else { - name = m.Name - } - if c.trunc { - name = stringutils.Ellipsis(name, 15) - } - mounts = append(mounts, name) - } - return strings.Join(mounts, ",") -} - -func (c *containerContext) LocalVolumes() string { - c.AddHeader(localVolumes) - - count := 0 - for _, m := range c.c.Mounts { - if m.Driver == "local" { - count++ - } - } - - return fmt.Sprintf("%d", count) -} - -func (c *containerContext) Networks() string { - c.AddHeader(networksHeader) - - if c.c.NetworkSettings == nil { - return "" - } - - networks := []string{} - for k := range c.c.NetworkSettings.Networks { - networks = append(networks, k) - } - - return strings.Join(networks, ",") -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/container_test.go b/vendor/github.com/docker/docker/cli/command/formatter/container_test.go deleted file mode 100644 index 1613789..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/container_test.go +++ /dev/null @@ -1,398 +0,0 @@ -package formatter - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestContainerPsContext(t *testing.T) { - containerID := stringid.GenerateRandomID() - unix := time.Now().Add(-65 * time.Second).Unix() - - var ctx containerContext - cases := []struct { - container types.Container - trunc bool - expValue string - expHeader string - call func() string - }{ - {types.Container{ID: containerID}, true, stringid.TruncateID(containerID), containerIDHeader, ctx.ID}, - {types.Container{ID: containerID}, false, containerID, containerIDHeader, ctx.ID}, - {types.Container{Names: []string{"/foobar_baz"}}, true, "foobar_baz", namesHeader, ctx.Names}, - {types.Container{Image: "ubuntu"}, true, "ubuntu", imageHeader, ctx.Image}, - {types.Container{Image: "verylongimagename"}, true, "verylongimagename", imageHeader, ctx.Image}, - {types.Container{Image: "verylongimagename"}, false, "verylongimagename", imageHeader, ctx.Image}, - {types.Container{ - Image: "a5a665ff33eced1e0803148700880edab4", - ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5", - }, - true, - "a5a665ff33ec", - imageHeader, - ctx.Image, - }, - {types.Container{ - Image: "a5a665ff33eced1e0803148700880edab4", - ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5", - }, - false, - "a5a665ff33eced1e0803148700880edab4", - imageHeader, - ctx.Image, - }, - {types.Container{Image: ""}, true, "", imageHeader, ctx.Image}, - {types.Container{Command: "sh -c 'ls -la'"}, true, `"sh -c 'ls -la'"`, commandHeader, ctx.Command}, - {types.Container{Created: unix}, true, time.Unix(unix, 0).String(), createdAtHeader, ctx.CreatedAt}, - {types.Container{Ports: []types.Port{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}}, true, "8080/tcp", portsHeader, ctx.Ports}, - {types.Container{Status: "RUNNING"}, true, "RUNNING", statusHeader, ctx.Status}, - {types.Container{SizeRw: 10}, true, "10 B", sizeHeader, ctx.Size}, - {types.Container{SizeRw: 10, SizeRootFs: 20}, true, "10 B (virtual 20 B)", sizeHeader, ctx.Size}, - {types.Container{}, true, "", labelsHeader, ctx.Labels}, - {types.Container{Labels: map[string]string{"cpu": "6", "storage": "ssd"}}, true, "cpu=6,storage=ssd", labelsHeader, ctx.Labels}, - {types.Container{Created: unix}, true, "About a minute", runningForHeader, ctx.RunningFor}, - {types.Container{ - Mounts: []types.MountPoint{ - { - Name: "this-is-a-long-volume-name-and-will-be-truncated-if-trunc-is-set", - Driver: "local", - Source: "/a/path", - }, - }, - }, true, "this-is-a-lo...", mountsHeader, ctx.Mounts}, - {types.Container{ - Mounts: []types.MountPoint{ - { - Driver: "local", - Source: "/a/path", - }, - }, - }, false, "/a/path", mountsHeader, ctx.Mounts}, - {types.Container{ - Mounts: []types.MountPoint{ - { - Name: "733908409c91817de8e92b0096373245f329f19a88e2c849f02460e9b3d1c203", - Driver: "local", - Source: "/a/path", - }, - }, - }, false, "733908409c91817de8e92b0096373245f329f19a88e2c849f02460e9b3d1c203", mountsHeader, ctx.Mounts}, - } - - for _, c := range cases { - ctx = containerContext{c: c.container, trunc: c.trunc} - v := c.call() - if strings.Contains(v, ",") { - compareMultipleValues(t, v, c.expValue) - } else if v != c.expValue { - t.Fatalf("Expected %s, was %s\n", c.expValue, v) - } - - h := ctx.FullHeader() - if h != c.expHeader { - t.Fatalf("Expected %s, was %s\n", c.expHeader, h) - } - } - - c1 := types.Container{Labels: map[string]string{"com.docker.swarm.swarm-id": "33", "com.docker.swarm.node_name": "ubuntu"}} - ctx = containerContext{c: c1, trunc: true} - - sid := ctx.Label("com.docker.swarm.swarm-id") - node := ctx.Label("com.docker.swarm.node_name") - if sid != "33" { - t.Fatalf("Expected 33, was %s\n", sid) - } - - if node != "ubuntu" { - t.Fatalf("Expected ubuntu, was %s\n", node) - } - - h := ctx.FullHeader() - if h != "SWARM ID\tNODE NAME" { - t.Fatalf("Expected %s, was %s\n", "SWARM ID\tNODE NAME", h) - - } - - c2 := types.Container{} - ctx = containerContext{c: c2, trunc: true} - - label := ctx.Label("anything.really") - if label != "" { - t.Fatalf("Expected an empty string, was %s", label) - } - - ctx = containerContext{c: c2, trunc: true} - FullHeader := ctx.FullHeader() - if FullHeader != "" { - t.Fatalf("Expected FullHeader to be empty, was %s", FullHeader) - } - -} - -func TestContainerContextWrite(t *testing.T) { - unixTime := time.Now().AddDate(0, 0, -1).Unix() - expectedTime := time.Unix(unixTime, 0).String() - - cases := []struct { - context Context - expected string - }{ - // Errors - { - Context{Format: "{{InvalidFunction}}"}, - `Template parsing error: template: :1: function "InvalidFunction" not defined -`, - }, - { - Context{Format: "{{nil}}"}, - `Template parsing error: template: :1:2: executing "" at : nil is not a command -`, - }, - // Table Format - { - Context{Format: NewContainerFormat("table", false, true)}, - `CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE -containerID1 ubuntu "" 24 hours ago foobar_baz 0 B -containerID2 ubuntu "" 24 hours ago foobar_bar 0 B -`, - }, - { - Context{Format: NewContainerFormat("table", false, false)}, - `CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -containerID1 ubuntu "" 24 hours ago foobar_baz -containerID2 ubuntu "" 24 hours ago foobar_bar -`, - }, - { - Context{Format: NewContainerFormat("table {{.Image}}", false, false)}, - "IMAGE\nubuntu\nubuntu\n", - }, - { - Context{Format: NewContainerFormat("table {{.Image}}", false, true)}, - "IMAGE\nubuntu\nubuntu\n", - }, - { - Context{Format: NewContainerFormat("table {{.Image}}", true, false)}, - "IMAGE\nubuntu\nubuntu\n", - }, - { - Context{Format: NewContainerFormat("table", true, false)}, - "containerID1\ncontainerID2\n", - }, - // Raw Format - { - Context{Format: NewContainerFormat("raw", false, false)}, - fmt.Sprintf(`container_id: containerID1 -image: ubuntu -command: "" -created_at: %s -status: -names: foobar_baz -labels: -ports: - -container_id: containerID2 -image: ubuntu -command: "" -created_at: %s -status: -names: foobar_bar -labels: -ports: - -`, expectedTime, expectedTime), - }, - { - Context{Format: NewContainerFormat("raw", false, true)}, - fmt.Sprintf(`container_id: containerID1 -image: ubuntu -command: "" -created_at: %s -status: -names: foobar_baz -labels: -ports: -size: 0 B - -container_id: containerID2 -image: ubuntu -command: "" -created_at: %s -status: -names: foobar_bar -labels: -ports: -size: 0 B - -`, expectedTime, expectedTime), - }, - { - Context{Format: NewContainerFormat("raw", true, false)}, - "container_id: containerID1\ncontainer_id: containerID2\n", - }, - // Custom Format - { - Context{Format: "{{.Image}}"}, - "ubuntu\nubuntu\n", - }, - { - Context{Format: NewContainerFormat("{{.Image}}", false, true)}, - "ubuntu\nubuntu\n", - }, - } - - for _, testcase := range cases { - containers := []types.Container{ - {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unixTime}, - {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unixTime}, - } - out := bytes.NewBufferString("") - testcase.context.Output = out - err := ContainerWrite(testcase.context, containers) - if err != nil { - assert.Error(t, err, testcase.expected) - } else { - assert.Equal(t, out.String(), testcase.expected) - } - } -} - -func TestContainerContextWriteWithNoContainers(t *testing.T) { - out := bytes.NewBufferString("") - containers := []types.Container{} - - contexts := []struct { - context Context - expected string - }{ - { - Context{ - Format: "{{.Image}}", - Output: out, - }, - "", - }, - { - Context{ - Format: "table {{.Image}}", - Output: out, - }, - "IMAGE\n", - }, - { - Context{ - Format: NewContainerFormat("{{.Image}}", false, true), - Output: out, - }, - "", - }, - { - Context{ - Format: NewContainerFormat("table {{.Image}}", false, true), - Output: out, - }, - "IMAGE\n", - }, - { - Context{ - Format: "table {{.Image}}\t{{.Size}}", - Output: out, - }, - "IMAGE SIZE\n", - }, - { - Context{ - Format: NewContainerFormat("table {{.Image}}\t{{.Size}}", false, true), - Output: out, - }, - "IMAGE SIZE\n", - }, - } - - for _, context := range contexts { - ContainerWrite(context.context, containers) - assert.Equal(t, context.expected, out.String()) - // Clean buffer - out.Reset() - } -} - -func TestContainerContextWriteJSON(t *testing.T) { - unix := time.Now().Add(-65 * time.Second).Unix() - containers := []types.Container{ - {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unix}, - {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unix}, - } - expectedCreated := time.Unix(unix, 0).String() - expectedJSONs := []map[string]interface{}{ - {"Command": "\"\"", "CreatedAt": expectedCreated, "ID": "containerID1", "Image": "ubuntu", "Labels": "", "LocalVolumes": "0", "Mounts": "", "Names": "foobar_baz", "Networks": "", "Ports": "", "RunningFor": "About a minute", "Size": "0 B", "Status": ""}, - {"Command": "\"\"", "CreatedAt": expectedCreated, "ID": "containerID2", "Image": "ubuntu", "Labels": "", "LocalVolumes": "0", "Mounts": "", "Names": "foobar_bar", "Networks": "", "Ports": "", "RunningFor": "About a minute", "Size": "0 B", "Status": ""}, - } - out := bytes.NewBufferString("") - err := ContainerWrite(Context{Format: "{{json .}}", Output: out}, containers) - if err != nil { - t.Fatal(err) - } - for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") { - t.Logf("Output: line %d: %s", i, line) - var m map[string]interface{} - if err := json.Unmarshal([]byte(line), &m); err != nil { - t.Fatal(err) - } - assert.DeepEqual(t, m, expectedJSONs[i]) - } -} - -func TestContainerContextWriteJSONField(t *testing.T) { - containers := []types.Container{ - {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu"}, - {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu"}, - } - out := bytes.NewBufferString("") - err := ContainerWrite(Context{Format: "{{json .ID}}", Output: out}, containers) - if err != nil { - t.Fatal(err) - } - for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") { - t.Logf("Output: line %d: %s", i, line) - var s string - if err := json.Unmarshal([]byte(line), &s); err != nil { - t.Fatal(err) - } - assert.Equal(t, s, containers[i].ID) - } -} - -func TestContainerBackCompat(t *testing.T) { - containers := []types.Container{{ID: "brewhaha"}} - cases := []string{ - "ID", - "Names", - "Image", - "Command", - "CreatedAt", - "RunningFor", - "Ports", - "Status", - "Size", - "Labels", - "Mounts", - } - buf := bytes.NewBuffer(nil) - for _, c := range cases { - ctx := Context{Format: Format(fmt.Sprintf("{{ .%s }}", c)), Output: buf} - if err := ContainerWrite(ctx, containers); err != nil { - t.Logf("could not render template for field '%s': %v", c, err) - t.Fail() - } - buf.Reset() - } -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/custom.go b/vendor/github.com/docker/docker/cli/command/formatter/custom.go deleted file mode 100644 index df32684..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/custom.go +++ /dev/null @@ -1,51 +0,0 @@ -package formatter - -import ( - "strings" -) - -const ( - imageHeader = "IMAGE" - createdSinceHeader = "CREATED" - createdAtHeader = "CREATED AT" - sizeHeader = "SIZE" - labelsHeader = "LABELS" - nameHeader = "NAME" - driverHeader = "DRIVER" - scopeHeader = "SCOPE" -) - -type subContext interface { - FullHeader() string - AddHeader(header string) -} - -// HeaderContext provides the subContext interface for managing headers -type HeaderContext struct { - header []string -} - -// FullHeader returns the header as a string -func (c *HeaderContext) FullHeader() string { - if c.header == nil { - return "" - } - return strings.Join(c.header, "\t") -} - -// AddHeader adds another column to the header -func (c *HeaderContext) AddHeader(header string) { - if c.header == nil { - c.header = []string{} - } - c.header = append(c.header, strings.ToUpper(header)) -} - -func stripNamePrefix(ss []string) []string { - sss := make([]string, len(ss)) - for i, s := range ss { - sss[i] = s[1:] - } - - return sss -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/custom_test.go b/vendor/github.com/docker/docker/cli/command/formatter/custom_test.go deleted file mode 100644 index da42039..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/custom_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package formatter - -import ( - "reflect" - "strings" - "testing" -) - -func compareMultipleValues(t *testing.T, value, expected string) { - // comma-separated values means probably a map input, which won't - // be guaranteed to have the same order as our expected value - // We'll create maps and use reflect.DeepEquals to check instead: - entriesMap := make(map[string]string) - expMap := make(map[string]string) - entries := strings.Split(value, ",") - expectedEntries := strings.Split(expected, ",") - for _, entry := range entries { - keyval := strings.Split(entry, "=") - entriesMap[keyval[0]] = keyval[1] - } - for _, expected := range expectedEntries { - keyval := strings.Split(expected, "=") - expMap[keyval[0]] = keyval[1] - } - if !reflect.DeepEqual(expMap, entriesMap) { - t.Fatalf("Expected entries: %v, got: %v", expected, value) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/disk_usage.go b/vendor/github.com/docker/docker/cli/command/formatter/disk_usage.go deleted file mode 100644 index 5309d88..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/disk_usage.go +++ /dev/null @@ -1,334 +0,0 @@ -package formatter - -import ( - "bytes" - "fmt" - "strings" - "text/template" - - "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" - units "github.com/docker/go-units" -) - -const ( - defaultDiskUsageImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedSince}} ago\t{{.VirtualSize}}\t{{.SharedSize}}\t{{.UniqueSize}}\t{{.Containers}}" - defaultDiskUsageContainerTableFormat = "table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.LocalVolumes}}\t{{.Size}}\t{{.RunningFor}} ago\t{{.Status}}\t{{.Names}}" - defaultDiskUsageVolumeTableFormat = "table {{.Name}}\t{{.Links}}\t{{.Size}}" - defaultDiskUsageTableFormat = "table {{.Type}}\t{{.TotalCount}}\t{{.Active}}\t{{.Size}}\t{{.Reclaimable}}" - - typeHeader = "TYPE" - totalHeader = "TOTAL" - activeHeader = "ACTIVE" - reclaimableHeader = "RECLAIMABLE" - containersHeader = "CONTAINERS" - sharedSizeHeader = "SHARED SIZE" - uniqueSizeHeader = "UNIQUE SiZE" -) - -// DiskUsageContext contains disk usage specific information required by the formater, encapsulate a Context struct. -type DiskUsageContext struct { - Context - Verbose bool - LayersSize int64 - Images []*types.ImageSummary - Containers []*types.Container - Volumes []*types.Volume -} - -func (ctx *DiskUsageContext) startSubsection(format string) (*template.Template, error) { - ctx.buffer = bytes.NewBufferString("") - ctx.header = "" - ctx.Format = Format(format) - ctx.preFormat() - - return ctx.parseFormat() -} - -func (ctx *DiskUsageContext) Write() { - if ctx.Verbose == false { - ctx.buffer = bytes.NewBufferString("") - ctx.Format = defaultDiskUsageTableFormat - ctx.preFormat() - - tmpl, err := ctx.parseFormat() - if err != nil { - return - } - - err = ctx.contextFormat(tmpl, &diskUsageImagesContext{ - totalSize: ctx.LayersSize, - images: ctx.Images, - }) - if err != nil { - return - } - err = ctx.contextFormat(tmpl, &diskUsageContainersContext{ - containers: ctx.Containers, - }) - if err != nil { - return - } - - err = ctx.contextFormat(tmpl, &diskUsageVolumesContext{ - volumes: ctx.Volumes, - }) - if err != nil { - return - } - - ctx.postFormat(tmpl, &diskUsageContainersContext{containers: []*types.Container{}}) - - return - } - - // First images - tmpl, err := ctx.startSubsection(defaultDiskUsageImageTableFormat) - if err != nil { - return - } - - ctx.Output.Write([]byte("Images space usage:\n\n")) - for _, i := range ctx.Images { - repo := "" - tag := "" - if len(i.RepoTags) > 0 && !isDangling(*i) { - // Only show the first tag - ref, err := reference.ParseNamed(i.RepoTags[0]) - if err != nil { - continue - } - if nt, ok := ref.(reference.NamedTagged); ok { - repo = ref.Name() - tag = nt.Tag() - } - } - - err = ctx.contextFormat(tmpl, &imageContext{ - repo: repo, - tag: tag, - trunc: true, - i: *i, - }) - if err != nil { - return - } - } - ctx.postFormat(tmpl, &imageContext{}) - - // Now containers - ctx.Output.Write([]byte("\nContainers space usage:\n\n")) - tmpl, err = ctx.startSubsection(defaultDiskUsageContainerTableFormat) - if err != nil { - return - } - for _, c := range ctx.Containers { - // Don't display the virtual size - c.SizeRootFs = 0 - err = ctx.contextFormat(tmpl, &containerContext{ - trunc: true, - c: *c, - }) - if err != nil { - return - } - } - ctx.postFormat(tmpl, &containerContext{}) - - // And volumes - ctx.Output.Write([]byte("\nLocal Volumes space usage:\n\n")) - tmpl, err = ctx.startSubsection(defaultDiskUsageVolumeTableFormat) - if err != nil { - return - } - for _, v := range ctx.Volumes { - err = ctx.contextFormat(tmpl, &volumeContext{ - v: *v, - }) - if err != nil { - return - } - } - ctx.postFormat(tmpl, &volumeContext{v: types.Volume{}}) -} - -type diskUsageImagesContext struct { - HeaderContext - totalSize int64 - images []*types.ImageSummary -} - -func (c *diskUsageImagesContext) Type() string { - c.AddHeader(typeHeader) - return "Images" -} - -func (c *diskUsageImagesContext) TotalCount() string { - c.AddHeader(totalHeader) - return fmt.Sprintf("%d", len(c.images)) -} - -func (c *diskUsageImagesContext) Active() string { - c.AddHeader(activeHeader) - used := 0 - for _, i := range c.images { - if i.Containers > 0 { - used++ - } - } - - return fmt.Sprintf("%d", used) -} - -func (c *diskUsageImagesContext) Size() string { - c.AddHeader(sizeHeader) - return units.HumanSize(float64(c.totalSize)) - -} - -func (c *diskUsageImagesContext) Reclaimable() string { - var used int64 - - c.AddHeader(reclaimableHeader) - for _, i := range c.images { - if i.Containers != 0 { - if i.VirtualSize == -1 || i.SharedSize == -1 { - continue - } - used += i.VirtualSize - i.SharedSize - } - } - - reclaimable := c.totalSize - used - if c.totalSize > 0 { - return fmt.Sprintf("%s (%v%%)", units.HumanSize(float64(reclaimable)), (reclaimable*100)/c.totalSize) - } - return fmt.Sprintf("%s", units.HumanSize(float64(reclaimable))) -} - -type diskUsageContainersContext struct { - HeaderContext - verbose bool - containers []*types.Container -} - -func (c *diskUsageContainersContext) Type() string { - c.AddHeader(typeHeader) - return "Containers" -} - -func (c *diskUsageContainersContext) TotalCount() string { - c.AddHeader(totalHeader) - return fmt.Sprintf("%d", len(c.containers)) -} - -func (c *diskUsageContainersContext) isActive(container types.Container) bool { - return strings.Contains(container.State, "running") || - strings.Contains(container.State, "paused") || - strings.Contains(container.State, "restarting") -} - -func (c *diskUsageContainersContext) Active() string { - c.AddHeader(activeHeader) - used := 0 - for _, container := range c.containers { - if c.isActive(*container) { - used++ - } - } - - return fmt.Sprintf("%d", used) -} - -func (c *diskUsageContainersContext) Size() string { - var size int64 - - c.AddHeader(sizeHeader) - for _, container := range c.containers { - size += container.SizeRw - } - - return units.HumanSize(float64(size)) -} - -func (c *diskUsageContainersContext) Reclaimable() string { - var reclaimable int64 - var totalSize int64 - - c.AddHeader(reclaimableHeader) - for _, container := range c.containers { - if !c.isActive(*container) { - reclaimable += container.SizeRw - } - totalSize += container.SizeRw - } - - if totalSize > 0 { - return fmt.Sprintf("%s (%v%%)", units.HumanSize(float64(reclaimable)), (reclaimable*100)/totalSize) - } - - return fmt.Sprintf("%s", units.HumanSize(float64(reclaimable))) -} - -type diskUsageVolumesContext struct { - HeaderContext - verbose bool - volumes []*types.Volume -} - -func (c *diskUsageVolumesContext) Type() string { - c.AddHeader(typeHeader) - return "Local Volumes" -} - -func (c *diskUsageVolumesContext) TotalCount() string { - c.AddHeader(totalHeader) - return fmt.Sprintf("%d", len(c.volumes)) -} - -func (c *diskUsageVolumesContext) Active() string { - c.AddHeader(activeHeader) - - used := 0 - for _, v := range c.volumes { - if v.UsageData.RefCount > 0 { - used++ - } - } - - return fmt.Sprintf("%d", used) -} - -func (c *diskUsageVolumesContext) Size() string { - var size int64 - - c.AddHeader(sizeHeader) - for _, v := range c.volumes { - if v.UsageData.Size != -1 { - size += v.UsageData.Size - } - } - - return units.HumanSize(float64(size)) -} - -func (c *diskUsageVolumesContext) Reclaimable() string { - var reclaimable int64 - var totalSize int64 - - c.AddHeader(reclaimableHeader) - for _, v := range c.volumes { - if v.UsageData.Size != -1 { - if v.UsageData.RefCount == 0 { - reclaimable += v.UsageData.Size - } - totalSize += v.UsageData.Size - } - } - - if totalSize > 0 { - return fmt.Sprintf("%s (%v%%)", units.HumanSize(float64(reclaimable)), (reclaimable*100)/totalSize) - } - - return fmt.Sprintf("%s", units.HumanSize(float64(reclaimable))) -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/formatter.go b/vendor/github.com/docker/docker/cli/command/formatter/formatter.go deleted file mode 100644 index e859a1c..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/formatter.go +++ /dev/null @@ -1,123 +0,0 @@ -package formatter - -import ( - "bytes" - "fmt" - "io" - "strings" - "text/tabwriter" - "text/template" - - "github.com/docker/docker/utils/templates" -) - -// Format keys used to specify certain kinds of output formats -const ( - TableFormatKey = "table" - RawFormatKey = "raw" - PrettyFormatKey = "pretty" - - defaultQuietFormat = "{{.ID}}" -) - -// Format is the format string rendered using the Context -type Format string - -// IsTable returns true if the format is a table-type format -func (f Format) IsTable() bool { - return strings.HasPrefix(string(f), TableFormatKey) -} - -// Contains returns true if the format contains the substring -func (f Format) Contains(sub string) bool { - return strings.Contains(string(f), sub) -} - -// Context contains information required by the formatter to print the output as desired. -type Context struct { - // Output is the output stream to which the formatted string is written. - Output io.Writer - // Format is used to choose raw, table or custom format for the output. - Format Format - // Trunc when set to true will truncate the output of certain fields such as Container ID. - Trunc bool - - // internal element - finalFormat string - header string - buffer *bytes.Buffer -} - -func (c *Context) preFormat() { - c.finalFormat = string(c.Format) - - // TODO: handle this in the Format type - if c.Format.IsTable() { - c.finalFormat = c.finalFormat[len(TableFormatKey):] - } - - c.finalFormat = strings.Trim(c.finalFormat, " ") - r := strings.NewReplacer(`\t`, "\t", `\n`, "\n") - c.finalFormat = r.Replace(c.finalFormat) -} - -func (c *Context) parseFormat() (*template.Template, error) { - tmpl, err := templates.Parse(c.finalFormat) - if err != nil { - return tmpl, fmt.Errorf("Template parsing error: %v\n", err) - } - return tmpl, err -} - -func (c *Context) postFormat(tmpl *template.Template, subContext subContext) { - if c.Format.IsTable() { - if len(c.header) == 0 { - // if we still don't have a header, we didn't have any containers so we need to fake it to get the right headers from the template - tmpl.Execute(bytes.NewBufferString(""), subContext) - c.header = subContext.FullHeader() - } - - t := tabwriter.NewWriter(c.Output, 20, 1, 3, ' ', 0) - t.Write([]byte(c.header)) - t.Write([]byte("\n")) - c.buffer.WriteTo(t) - t.Flush() - } else { - c.buffer.WriteTo(c.Output) - } -} - -func (c *Context) contextFormat(tmpl *template.Template, subContext subContext) error { - if err := tmpl.Execute(c.buffer, subContext); err != nil { - return fmt.Errorf("Template parsing error: %v\n", err) - } - if c.Format.IsTable() && len(c.header) == 0 { - c.header = subContext.FullHeader() - } - c.buffer.WriteString("\n") - return nil -} - -// SubFormat is a function type accepted by Write() -type SubFormat func(func(subContext) error) error - -// Write the template to the buffer using this Context -func (c *Context) Write(sub subContext, f SubFormat) error { - c.buffer = bytes.NewBufferString("") - c.preFormat() - - tmpl, err := c.parseFormat() - if err != nil { - return err - } - - subFormat := func(subContext subContext) error { - return c.contextFormat(tmpl, subContext) - } - if err := f(subFormat); err != nil { - return err - } - - c.postFormat(tmpl, sub) - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/image.go b/vendor/github.com/docker/docker/cli/command/formatter/image.go deleted file mode 100644 index 5c7de82..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/image.go +++ /dev/null @@ -1,259 +0,0 @@ -package formatter - -import ( - "fmt" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/reference" - units "github.com/docker/go-units" -) - -const ( - defaultImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedSince}} ago\t{{.Size}}" - defaultImageTableFormatWithDigest = "table {{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.ID}}\t{{.CreatedSince}} ago\t{{.Size}}" - - imageIDHeader = "IMAGE ID" - repositoryHeader = "REPOSITORY" - tagHeader = "TAG" - digestHeader = "DIGEST" -) - -// ImageContext contains image specific information required by the formater, encapsulate a Context struct. -type ImageContext struct { - Context - Digest bool -} - -func isDangling(image types.ImageSummary) bool { - return len(image.RepoTags) == 1 && image.RepoTags[0] == ":" && len(image.RepoDigests) == 1 && image.RepoDigests[0] == "@" -} - -// NewImageFormat returns a format for rendering an ImageContext -func NewImageFormat(source string, quiet bool, digest bool) Format { - switch source { - case TableFormatKey: - switch { - case quiet: - return defaultQuietFormat - case digest: - return defaultImageTableFormatWithDigest - default: - return defaultImageTableFormat - } - case RawFormatKey: - switch { - case quiet: - return `image_id: {{.ID}}` - case digest: - return `repository: {{ .Repository }} -tag: {{.Tag}} -digest: {{.Digest}} -image_id: {{.ID}} -created_at: {{.CreatedAt}} -virtual_size: {{.Size}} -` - default: - return `repository: {{ .Repository }} -tag: {{.Tag}} -image_id: {{.ID}} -created_at: {{.CreatedAt}} -virtual_size: {{.Size}} -` - } - } - - format := Format(source) - if format.IsTable() && digest && !format.Contains("{{.Digest}}") { - format += "\t{{.Digest}}" - } - return format -} - -// ImageWrite writes the formatter images using the ImageContext -func ImageWrite(ctx ImageContext, images []types.ImageSummary) error { - render := func(format func(subContext subContext) error) error { - return imageFormat(ctx, images, format) - } - return ctx.Write(&imageContext{}, render) -} - -func imageFormat(ctx ImageContext, images []types.ImageSummary, format func(subContext subContext) error) error { - for _, image := range images { - images := []*imageContext{} - if isDangling(image) { - images = append(images, &imageContext{ - trunc: ctx.Trunc, - i: image, - repo: "", - tag: "", - digest: "", - }) - } else { - repoTags := map[string][]string{} - repoDigests := map[string][]string{} - - for _, refString := range append(image.RepoTags) { - ref, err := reference.ParseNamed(refString) - if err != nil { - continue - } - if nt, ok := ref.(reference.NamedTagged); ok { - repoTags[ref.Name()] = append(repoTags[ref.Name()], nt.Tag()) - } - } - for _, refString := range append(image.RepoDigests) { - ref, err := reference.ParseNamed(refString) - if err != nil { - continue - } - if c, ok := ref.(reference.Canonical); ok { - repoDigests[ref.Name()] = append(repoDigests[ref.Name()], c.Digest().String()) - } - } - - for repo, tags := range repoTags { - digests := repoDigests[repo] - - // Do not display digests as their own row - delete(repoDigests, repo) - - if !ctx.Digest { - // Ignore digest references, just show tag once - digests = nil - } - - for _, tag := range tags { - if len(digests) == 0 { - images = append(images, &imageContext{ - trunc: ctx.Trunc, - i: image, - repo: repo, - tag: tag, - digest: "", - }) - continue - } - // Display the digests for each tag - for _, dgst := range digests { - images = append(images, &imageContext{ - trunc: ctx.Trunc, - i: image, - repo: repo, - tag: tag, - digest: dgst, - }) - } - - } - } - - // Show rows for remaining digest only references - for repo, digests := range repoDigests { - // If digests are displayed, show row per digest - if ctx.Digest { - for _, dgst := range digests { - images = append(images, &imageContext{ - trunc: ctx.Trunc, - i: image, - repo: repo, - tag: "", - digest: dgst, - }) - } - } else { - images = append(images, &imageContext{ - trunc: ctx.Trunc, - i: image, - repo: repo, - tag: "", - }) - } - } - } - for _, imageCtx := range images { - if err := format(imageCtx); err != nil { - return err - } - } - } - return nil -} - -type imageContext struct { - HeaderContext - trunc bool - i types.ImageSummary - repo string - tag string - digest string -} - -func (c *imageContext) ID() string { - c.AddHeader(imageIDHeader) - if c.trunc { - return stringid.TruncateID(c.i.ID) - } - return c.i.ID -} - -func (c *imageContext) Repository() string { - c.AddHeader(repositoryHeader) - return c.repo -} - -func (c *imageContext) Tag() string { - c.AddHeader(tagHeader) - return c.tag -} - -func (c *imageContext) Digest() string { - c.AddHeader(digestHeader) - return c.digest -} - -func (c *imageContext) CreatedSince() string { - c.AddHeader(createdSinceHeader) - createdAt := time.Unix(int64(c.i.Created), 0) - return units.HumanDuration(time.Now().UTC().Sub(createdAt)) -} - -func (c *imageContext) CreatedAt() string { - c.AddHeader(createdAtHeader) - return time.Unix(int64(c.i.Created), 0).String() -} - -func (c *imageContext) Size() string { - c.AddHeader(sizeHeader) - return units.HumanSizeWithPrecision(float64(c.i.Size), 3) -} - -func (c *imageContext) Containers() string { - c.AddHeader(containersHeader) - if c.i.Containers == -1 { - return "N/A" - } - return fmt.Sprintf("%d", c.i.Containers) -} - -func (c *imageContext) VirtualSize() string { - c.AddHeader(sizeHeader) - return units.HumanSize(float64(c.i.VirtualSize)) -} - -func (c *imageContext) SharedSize() string { - c.AddHeader(sharedSizeHeader) - if c.i.SharedSize == -1 { - return "N/A" - } - return units.HumanSize(float64(c.i.SharedSize)) -} - -func (c *imageContext) UniqueSize() string { - c.AddHeader(uniqueSizeHeader) - if c.i.VirtualSize == -1 || c.i.SharedSize == -1 { - return "N/A" - } - return units.HumanSize(float64(c.i.VirtualSize - c.i.SharedSize)) -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/image_test.go b/vendor/github.com/docker/docker/cli/command/formatter/image_test.go deleted file mode 100644 index ffe77f6..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/image_test.go +++ /dev/null @@ -1,333 +0,0 @@ -package formatter - -import ( - "bytes" - "fmt" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestImageContext(t *testing.T) { - imageID := stringid.GenerateRandomID() - unix := time.Now().Unix() - - var ctx imageContext - cases := []struct { - imageCtx imageContext - expValue string - expHeader string - call func() string - }{ - {imageContext{ - i: types.ImageSummary{ID: imageID}, - trunc: true, - }, stringid.TruncateID(imageID), imageIDHeader, ctx.ID}, - {imageContext{ - i: types.ImageSummary{ID: imageID}, - trunc: false, - }, imageID, imageIDHeader, ctx.ID}, - {imageContext{ - i: types.ImageSummary{Size: 10, VirtualSize: 10}, - trunc: true, - }, "10 B", sizeHeader, ctx.Size}, - {imageContext{ - i: types.ImageSummary{Created: unix}, - trunc: true, - }, time.Unix(unix, 0).String(), createdAtHeader, ctx.CreatedAt}, - // FIXME - // {imageContext{ - // i: types.ImageSummary{Created: unix}, - // trunc: true, - // }, units.HumanDuration(time.Unix(unix, 0)), createdSinceHeader, ctx.CreatedSince}, - {imageContext{ - i: types.ImageSummary{}, - repo: "busybox", - }, "busybox", repositoryHeader, ctx.Repository}, - {imageContext{ - i: types.ImageSummary{}, - tag: "latest", - }, "latest", tagHeader, ctx.Tag}, - {imageContext{ - i: types.ImageSummary{}, - digest: "sha256:d149ab53f8718e987c3a3024bb8aa0e2caadf6c0328f1d9d850b2a2a67f2819a", - }, "sha256:d149ab53f8718e987c3a3024bb8aa0e2caadf6c0328f1d9d850b2a2a67f2819a", digestHeader, ctx.Digest}, - } - - for _, c := range cases { - ctx = c.imageCtx - v := c.call() - if strings.Contains(v, ",") { - compareMultipleValues(t, v, c.expValue) - } else if v != c.expValue { - t.Fatalf("Expected %s, was %s\n", c.expValue, v) - } - - h := ctx.FullHeader() - if h != c.expHeader { - t.Fatalf("Expected %s, was %s\n", c.expHeader, h) - } - } -} - -func TestImageContextWrite(t *testing.T) { - unixTime := time.Now().AddDate(0, 0, -1).Unix() - expectedTime := time.Unix(unixTime, 0).String() - - cases := []struct { - context ImageContext - expected string - }{ - // Errors - { - ImageContext{ - Context: Context{ - Format: "{{InvalidFunction}}", - }, - }, - `Template parsing error: template: :1: function "InvalidFunction" not defined -`, - }, - { - ImageContext{ - Context: Context{ - Format: "{{nil}}", - }, - }, - `Template parsing error: template: :1:2: executing "" at : nil is not a command -`, - }, - // Table Format - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("table", false, false), - }, - }, - `REPOSITORY TAG IMAGE ID CREATED SIZE -image tag1 imageID1 24 hours ago 0 B -image tag2 imageID2 24 hours ago 0 B - imageID3 24 hours ago 0 B -`, - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("table {{.Repository}}", false, false), - }, - }, - "REPOSITORY\nimage\nimage\n\n", - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("table {{.Repository}}", false, true), - }, - Digest: true, - }, - `REPOSITORY DIGEST -image sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf -image - -`, - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("table {{.Repository}}", true, false), - }, - }, - "REPOSITORY\nimage\nimage\n\n", - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("table", true, false), - }, - }, - "imageID1\nimageID2\nimageID3\n", - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("table", false, true), - }, - Digest: true, - }, - `REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE -image tag1 sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf imageID1 24 hours ago 0 B -image tag2 imageID2 24 hours ago 0 B - imageID3 24 hours ago 0 B -`, - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("table", true, true), - }, - Digest: true, - }, - "imageID1\nimageID2\nimageID3\n", - }, - // Raw Format - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("raw", false, false), - }, - }, - fmt.Sprintf(`repository: image -tag: tag1 -image_id: imageID1 -created_at: %s -virtual_size: 0 B - -repository: image -tag: tag2 -image_id: imageID2 -created_at: %s -virtual_size: 0 B - -repository: -tag: -image_id: imageID3 -created_at: %s -virtual_size: 0 B - -`, expectedTime, expectedTime, expectedTime), - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("raw", false, true), - }, - Digest: true, - }, - fmt.Sprintf(`repository: image -tag: tag1 -digest: sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf -image_id: imageID1 -created_at: %s -virtual_size: 0 B - -repository: image -tag: tag2 -digest: -image_id: imageID2 -created_at: %s -virtual_size: 0 B - -repository: -tag: -digest: -image_id: imageID3 -created_at: %s -virtual_size: 0 B - -`, expectedTime, expectedTime, expectedTime), - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("raw", true, false), - }, - }, - `image_id: imageID1 -image_id: imageID2 -image_id: imageID3 -`, - }, - // Custom Format - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("{{.Repository}}", false, false), - }, - }, - "image\nimage\n\n", - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("{{.Repository}}", false, true), - }, - Digest: true, - }, - "image\nimage\n\n", - }, - } - - for _, testcase := range cases { - images := []types.ImageSummary{ - {ID: "imageID1", RepoTags: []string{"image:tag1"}, RepoDigests: []string{"image@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"}, Created: unixTime}, - {ID: "imageID2", RepoTags: []string{"image:tag2"}, Created: unixTime}, - {ID: "imageID3", RepoTags: []string{":"}, RepoDigests: []string{"@"}, Created: unixTime}, - } - out := bytes.NewBufferString("") - testcase.context.Output = out - err := ImageWrite(testcase.context, images) - if err != nil { - assert.Error(t, err, testcase.expected) - } else { - assert.Equal(t, out.String(), testcase.expected) - } - } -} - -func TestImageContextWriteWithNoImage(t *testing.T) { - out := bytes.NewBufferString("") - images := []types.ImageSummary{} - - contexts := []struct { - context ImageContext - expected string - }{ - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("{{.Repository}}", false, false), - Output: out, - }, - }, - "", - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("table {{.Repository}}", false, false), - Output: out, - }, - }, - "REPOSITORY\n", - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("{{.Repository}}", false, true), - Output: out, - }, - }, - "", - }, - { - ImageContext{ - Context: Context{ - Format: NewImageFormat("table {{.Repository}}", false, true), - Output: out, - }, - }, - "REPOSITORY DIGEST\n", - }, - } - - for _, context := range contexts { - ImageWrite(context.context, images) - assert.Equal(t, out.String(), context.expected) - // Clean buffer - out.Reset() - } -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/network.go b/vendor/github.com/docker/docker/cli/command/formatter/network.go deleted file mode 100644 index 7fbad7d..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/network.go +++ /dev/null @@ -1,117 +0,0 @@ -package formatter - -import ( - "fmt" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/stringid" -) - -const ( - defaultNetworkTableFormat = "table {{.ID}}\t{{.Name}}\t{{.Driver}}\t{{.Scope}}" - - networkIDHeader = "NETWORK ID" - ipv6Header = "IPV6" - internalHeader = "INTERNAL" -) - -// NewNetworkFormat returns a Format for rendering using a network Context -func NewNetworkFormat(source string, quiet bool) Format { - switch source { - case TableFormatKey: - if quiet { - return defaultQuietFormat - } - return defaultNetworkTableFormat - case RawFormatKey: - if quiet { - return `network_id: {{.ID}}` - } - return `network_id: {{.ID}}\nname: {{.Name}}\ndriver: {{.Driver}}\nscope: {{.Scope}}\n` - } - return Format(source) -} - -// NetworkWrite writes the context -func NetworkWrite(ctx Context, networks []types.NetworkResource) error { - render := func(format func(subContext subContext) error) error { - for _, network := range networks { - networkCtx := &networkContext{trunc: ctx.Trunc, n: network} - if err := format(networkCtx); err != nil { - return err - } - } - return nil - } - return ctx.Write(&networkContext{}, render) -} - -type networkContext struct { - HeaderContext - trunc bool - n types.NetworkResource -} - -func (c *networkContext) MarshalJSON() ([]byte, error) { - return marshalJSON(c) -} - -func (c *networkContext) ID() string { - c.AddHeader(networkIDHeader) - if c.trunc { - return stringid.TruncateID(c.n.ID) - } - return c.n.ID -} - -func (c *networkContext) Name() string { - c.AddHeader(nameHeader) - return c.n.Name -} - -func (c *networkContext) Driver() string { - c.AddHeader(driverHeader) - return c.n.Driver -} - -func (c *networkContext) Scope() string { - c.AddHeader(scopeHeader) - return c.n.Scope -} - -func (c *networkContext) IPv6() string { - c.AddHeader(ipv6Header) - return fmt.Sprintf("%v", c.n.EnableIPv6) -} - -func (c *networkContext) Internal() string { - c.AddHeader(internalHeader) - return fmt.Sprintf("%v", c.n.Internal) -} - -func (c *networkContext) Labels() string { - c.AddHeader(labelsHeader) - if c.n.Labels == nil { - return "" - } - - var joinLabels []string - for k, v := range c.n.Labels { - joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v)) - } - return strings.Join(joinLabels, ",") -} - -func (c *networkContext) Label(name string) string { - n := strings.Split(name, ".") - r := strings.NewReplacer("-", " ", "_", " ") - h := r.Replace(n[len(n)-1]) - - c.AddHeader(h) - - if c.n.Labels == nil { - return "" - } - return c.n.Labels[name] -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/network_test.go b/vendor/github.com/docker/docker/cli/command/formatter/network_test.go deleted file mode 100644 index b40a534..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/network_test.go +++ /dev/null @@ -1,208 +0,0 @@ -package formatter - -import ( - "bytes" - "encoding/json" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestNetworkContext(t *testing.T) { - networkID := stringid.GenerateRandomID() - - var ctx networkContext - cases := []struct { - networkCtx networkContext - expValue string - expHeader string - call func() string - }{ - {networkContext{ - n: types.NetworkResource{ID: networkID}, - trunc: false, - }, networkID, networkIDHeader, ctx.ID}, - {networkContext{ - n: types.NetworkResource{ID: networkID}, - trunc: true, - }, stringid.TruncateID(networkID), networkIDHeader, ctx.ID}, - {networkContext{ - n: types.NetworkResource{Name: "network_name"}, - }, "network_name", nameHeader, ctx.Name}, - {networkContext{ - n: types.NetworkResource{Driver: "driver_name"}, - }, "driver_name", driverHeader, ctx.Driver}, - {networkContext{ - n: types.NetworkResource{EnableIPv6: true}, - }, "true", ipv6Header, ctx.IPv6}, - {networkContext{ - n: types.NetworkResource{EnableIPv6: false}, - }, "false", ipv6Header, ctx.IPv6}, - {networkContext{ - n: types.NetworkResource{Internal: true}, - }, "true", internalHeader, ctx.Internal}, - {networkContext{ - n: types.NetworkResource{Internal: false}, - }, "false", internalHeader, ctx.Internal}, - {networkContext{ - n: types.NetworkResource{}, - }, "", labelsHeader, ctx.Labels}, - {networkContext{ - n: types.NetworkResource{Labels: map[string]string{"label1": "value1", "label2": "value2"}}, - }, "label1=value1,label2=value2", labelsHeader, ctx.Labels}, - } - - for _, c := range cases { - ctx = c.networkCtx - v := c.call() - if strings.Contains(v, ",") { - compareMultipleValues(t, v, c.expValue) - } else if v != c.expValue { - t.Fatalf("Expected %s, was %s\n", c.expValue, v) - } - - h := ctx.FullHeader() - if h != c.expHeader { - t.Fatalf("Expected %s, was %s\n", c.expHeader, h) - } - } -} - -func TestNetworkContextWrite(t *testing.T) { - cases := []struct { - context Context - expected string - }{ - - // Errors - { - Context{Format: "{{InvalidFunction}}"}, - `Template parsing error: template: :1: function "InvalidFunction" not defined -`, - }, - { - Context{Format: "{{nil}}"}, - `Template parsing error: template: :1:2: executing "" at : nil is not a command -`, - }, - // Table format - { - Context{Format: NewNetworkFormat("table", false)}, - `NETWORK ID NAME DRIVER SCOPE -networkID1 foobar_baz foo local -networkID2 foobar_bar bar local -`, - }, - { - Context{Format: NewNetworkFormat("table", true)}, - `networkID1 -networkID2 -`, - }, - { - Context{Format: NewNetworkFormat("table {{.Name}}", false)}, - `NAME -foobar_baz -foobar_bar -`, - }, - { - Context{Format: NewNetworkFormat("table {{.Name}}", true)}, - `NAME -foobar_baz -foobar_bar -`, - }, - // Raw Format - { - Context{Format: NewNetworkFormat("raw", false)}, - `network_id: networkID1 -name: foobar_baz -driver: foo -scope: local - -network_id: networkID2 -name: foobar_bar -driver: bar -scope: local - -`, - }, - { - Context{Format: NewNetworkFormat("raw", true)}, - `network_id: networkID1 -network_id: networkID2 -`, - }, - // Custom Format - { - Context{Format: NewNetworkFormat("{{.Name}}", false)}, - `foobar_baz -foobar_bar -`, - }, - } - - for _, testcase := range cases { - networks := []types.NetworkResource{ - {ID: "networkID1", Name: "foobar_baz", Driver: "foo", Scope: "local"}, - {ID: "networkID2", Name: "foobar_bar", Driver: "bar", Scope: "local"}, - } - out := bytes.NewBufferString("") - testcase.context.Output = out - err := NetworkWrite(testcase.context, networks) - if err != nil { - assert.Error(t, err, testcase.expected) - } else { - assert.Equal(t, out.String(), testcase.expected) - } - } -} - -func TestNetworkContextWriteJSON(t *testing.T) { - networks := []types.NetworkResource{ - {ID: "networkID1", Name: "foobar_baz"}, - {ID: "networkID2", Name: "foobar_bar"}, - } - expectedJSONs := []map[string]interface{}{ - {"Driver": "", "ID": "networkID1", "IPv6": "false", "Internal": "false", "Labels": "", "Name": "foobar_baz", "Scope": ""}, - {"Driver": "", "ID": "networkID2", "IPv6": "false", "Internal": "false", "Labels": "", "Name": "foobar_bar", "Scope": ""}, - } - - out := bytes.NewBufferString("") - err := NetworkWrite(Context{Format: "{{json .}}", Output: out}, networks) - if err != nil { - t.Fatal(err) - } - for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") { - t.Logf("Output: line %d: %s", i, line) - var m map[string]interface{} - if err := json.Unmarshal([]byte(line), &m); err != nil { - t.Fatal(err) - } - assert.DeepEqual(t, m, expectedJSONs[i]) - } -} - -func TestNetworkContextWriteJSONField(t *testing.T) { - networks := []types.NetworkResource{ - {ID: "networkID1", Name: "foobar_baz"}, - {ID: "networkID2", Name: "foobar_bar"}, - } - out := bytes.NewBufferString("") - err := NetworkWrite(Context{Format: "{{json .ID}}", Output: out}, networks) - if err != nil { - t.Fatal(err) - } - for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") { - t.Logf("Output: line %d: %s", i, line) - var s string - if err := json.Unmarshal([]byte(line), &s); err != nil { - t.Fatal(err) - } - assert.Equal(t, s, networks[i].ID) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/reflect.go b/vendor/github.com/docker/docker/cli/command/formatter/reflect.go deleted file mode 100644 index d1d8737..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/reflect.go +++ /dev/null @@ -1,65 +0,0 @@ -package formatter - -import ( - "encoding/json" - "fmt" - "reflect" - "unicode" -) - -func marshalJSON(x interface{}) ([]byte, error) { - m, err := marshalMap(x) - if err != nil { - return nil, err - } - return json.Marshal(m) -} - -// marshalMap marshals x to map[string]interface{} -func marshalMap(x interface{}) (map[string]interface{}, error) { - val := reflect.ValueOf(x) - if val.Kind() != reflect.Ptr { - return nil, fmt.Errorf("expected a pointer to a struct, got %v", val.Kind()) - } - if val.IsNil() { - return nil, fmt.Errorf("expxected a pointer to a struct, got nil pointer") - } - valElem := val.Elem() - if valElem.Kind() != reflect.Struct { - return nil, fmt.Errorf("expected a pointer to a struct, got a pointer to %v", valElem.Kind()) - } - typ := val.Type() - m := make(map[string]interface{}) - for i := 0; i < val.NumMethod(); i++ { - k, v, err := marshalForMethod(typ.Method(i), val.Method(i)) - if err != nil { - return nil, err - } - if k != "" { - m[k] = v - } - } - return m, nil -} - -var unmarshallableNames = map[string]struct{}{"FullHeader": {}} - -// marshalForMethod returns the map key and the map value for marshalling the method. -// It returns ("", nil, nil) for valid but non-marshallable parameter. (e.g. "unexportedFunc()") -func marshalForMethod(typ reflect.Method, val reflect.Value) (string, interface{}, error) { - if val.Kind() != reflect.Func { - return "", nil, fmt.Errorf("expected func, got %v", val.Kind()) - } - name, numIn, numOut := typ.Name, val.Type().NumIn(), val.Type().NumOut() - _, blackListed := unmarshallableNames[name] - // FIXME: In text/template, (numOut == 2) is marshallable, - // if the type of the second param is error. - marshallable := unicode.IsUpper(rune(name[0])) && !blackListed && - numIn == 0 && numOut == 1 - if !marshallable { - return "", nil, nil - } - result := val.Call(make([]reflect.Value, numIn)) - intf := result[0].Interface() - return name, intf, nil -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/reflect_test.go b/vendor/github.com/docker/docker/cli/command/formatter/reflect_test.go deleted file mode 100644 index e547b18..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/reflect_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package formatter - -import ( - "reflect" - "testing" -) - -type dummy struct { -} - -func (d *dummy) Func1() string { - return "Func1" -} - -func (d *dummy) func2() string { - return "func2(should not be marshalled)" -} - -func (d *dummy) Func3() (string, int) { - return "Func3(should not be marshalled)", -42 -} - -func (d *dummy) Func4() int { - return 4 -} - -type dummyType string - -func (d *dummy) Func5() dummyType { - return dummyType("Func5") -} - -func (d *dummy) FullHeader() string { - return "FullHeader(should not be marshalled)" -} - -var dummyExpected = map[string]interface{}{ - "Func1": "Func1", - "Func4": 4, - "Func5": dummyType("Func5"), -} - -func TestMarshalMap(t *testing.T) { - d := dummy{} - m, err := marshalMap(&d) - if err != nil { - t.Fatal(err) - } - if !reflect.DeepEqual(dummyExpected, m) { - t.Fatalf("expected %+v, got %+v", - dummyExpected, m) - } -} - -func TestMarshalMapBad(t *testing.T) { - if _, err := marshalMap(nil); err == nil { - t.Fatal("expected an error (argument is nil)") - } - if _, err := marshalMap(dummy{}); err == nil { - t.Fatal("expected an error (argument is non-pointer)") - } - x := 42 - if _, err := marshalMap(&x); err == nil { - t.Fatal("expected an error (argument is a pointer to non-struct)") - } -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/service.go b/vendor/github.com/docker/docker/cli/command/formatter/service.go deleted file mode 100644 index aaa7838..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/service.go +++ /dev/null @@ -1,322 +0,0 @@ -package formatter - -import ( - "fmt" - "strings" - "time" - - mounttypes "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli/command/inspect" - units "github.com/docker/go-units" -) - -const serviceInspectPrettyTemplate Format = ` -ID: {{.ID}} -Name: {{.Name}} -{{- if .Labels }} -Labels: -{{- range $k, $v := .Labels }} - {{ $k }}{{if $v }}={{ $v }}{{ end }} -{{- end }}{{ end }} -Service Mode: -{{- if .IsModeGlobal }} Global -{{- else if .IsModeReplicated }} Replicated -{{- if .ModeReplicatedReplicas }} - Replicas: {{ .ModeReplicatedReplicas }} -{{- end }}{{ end }} -{{- if .HasUpdateStatus }} -UpdateStatus: - State: {{ .UpdateStatusState }} - Started: {{ .UpdateStatusStarted }} -{{- if .UpdateIsCompleted }} - Completed: {{ .UpdateStatusCompleted }} -{{- end }} - Message: {{ .UpdateStatusMessage }} -{{- end }} -Placement: -{{- if .TaskPlacementConstraints -}} - Contraints: {{ .TaskPlacementConstraints }} -{{- end }} -{{- if .HasUpdateConfig }} -UpdateConfig: - Parallelism: {{ .UpdateParallelism }} -{{- if .HasUpdateDelay}} - Delay: {{ .UpdateDelay }} -{{- end }} - On failure: {{ .UpdateOnFailure }} -{{- if .HasUpdateMonitor}} - Monitoring Period: {{ .UpdateMonitor }} -{{- end }} - Max failure ratio: {{ .UpdateMaxFailureRatio }} -{{- end }} -ContainerSpec: - Image: {{ .ContainerImage }} -{{- if .ContainerArgs }} - Args: {{ range $arg := .ContainerArgs }}{{ $arg }} {{ end }} -{{- end -}} -{{- if .ContainerEnv }} - Env: {{ range $env := .ContainerEnv }}{{ $env }} {{ end }} -{{- end -}} -{{- if .ContainerWorkDir }} - Dir: {{ .ContainerWorkDir }} -{{- end -}} -{{- if .ContainerUser }} - User: {{ .ContainerUser }} -{{- end }} -{{- if .ContainerMounts }} -Mounts: -{{- end }} -{{- range $mount := .ContainerMounts }} - Target = {{ $mount.Target }} - Source = {{ $mount.Source }} - ReadOnly = {{ $mount.ReadOnly }} - Type = {{ $mount.Type }} -{{- end -}} -{{- if .HasResources }} -Resources: -{{- if .HasResourceReservations }} - Reservations: -{{- if gt .ResourceReservationNanoCPUs 0.0 }} - CPU: {{ .ResourceReservationNanoCPUs }} -{{- end }} -{{- if .ResourceReservationMemory }} - Memory: {{ .ResourceReservationMemory }} -{{- end }}{{ end }} -{{- if .HasResourceLimits }} - Limits: -{{- if gt .ResourceLimitsNanoCPUs 0.0 }} - CPU: {{ .ResourceLimitsNanoCPUs }} -{{- end }} -{{- if .ResourceLimitMemory }} - Memory: {{ .ResourceLimitMemory }} -{{- end }}{{ end }}{{ end }} -{{- if .Networks }} -Networks: -{{- range $network := .Networks }} {{ $network }}{{ end }} {{ end }} -Endpoint Mode: {{ .EndpointMode }} -{{- if .Ports }} -Ports: -{{- range $port := .Ports }} - PublishedPort {{ $port.PublishedPort }} - Protocol = {{ $port.Protocol }} - TargetPort = {{ $port.TargetPort }} -{{- end }} {{ end -}} -` - -// NewServiceFormat returns a Format for rendering using a Context -func NewServiceFormat(source string) Format { - switch source { - case PrettyFormatKey: - return serviceInspectPrettyTemplate - default: - return Format(strings.TrimPrefix(source, RawFormatKey)) - } -} - -// ServiceInspectWrite renders the context for a list of services -func ServiceInspectWrite(ctx Context, refs []string, getRef inspect.GetRefFunc) error { - if ctx.Format != serviceInspectPrettyTemplate { - return inspect.Inspect(ctx.Output, refs, string(ctx.Format), getRef) - } - render := func(format func(subContext subContext) error) error { - for _, ref := range refs { - serviceI, _, err := getRef(ref) - if err != nil { - return err - } - service, ok := serviceI.(swarm.Service) - if !ok { - return fmt.Errorf("got wrong object to inspect") - } - if err := format(&serviceInspectContext{Service: service}); err != nil { - return err - } - } - return nil - } - return ctx.Write(&serviceInspectContext{}, render) -} - -type serviceInspectContext struct { - swarm.Service - subContext -} - -func (ctx *serviceInspectContext) MarshalJSON() ([]byte, error) { - return marshalJSON(ctx) -} - -func (ctx *serviceInspectContext) ID() string { - return ctx.Service.ID -} - -func (ctx *serviceInspectContext) Name() string { - return ctx.Service.Spec.Name -} - -func (ctx *serviceInspectContext) Labels() map[string]string { - return ctx.Service.Spec.Labels -} - -func (ctx *serviceInspectContext) IsModeGlobal() bool { - return ctx.Service.Spec.Mode.Global != nil -} - -func (ctx *serviceInspectContext) IsModeReplicated() bool { - return ctx.Service.Spec.Mode.Replicated != nil -} - -func (ctx *serviceInspectContext) ModeReplicatedReplicas() *uint64 { - return ctx.Service.Spec.Mode.Replicated.Replicas -} - -func (ctx *serviceInspectContext) HasUpdateStatus() bool { - return ctx.Service.UpdateStatus.State != "" -} - -func (ctx *serviceInspectContext) UpdateStatusState() swarm.UpdateState { - return ctx.Service.UpdateStatus.State -} - -func (ctx *serviceInspectContext) UpdateStatusStarted() string { - return units.HumanDuration(time.Since(ctx.Service.UpdateStatus.StartedAt)) -} - -func (ctx *serviceInspectContext) UpdateIsCompleted() bool { - return ctx.Service.UpdateStatus.State == swarm.UpdateStateCompleted -} - -func (ctx *serviceInspectContext) UpdateStatusCompleted() string { - return units.HumanDuration(time.Since(ctx.Service.UpdateStatus.CompletedAt)) -} - -func (ctx *serviceInspectContext) UpdateStatusMessage() string { - return ctx.Service.UpdateStatus.Message -} - -func (ctx *serviceInspectContext) TaskPlacementConstraints() []string { - if ctx.Service.Spec.TaskTemplate.Placement != nil { - return ctx.Service.Spec.TaskTemplate.Placement.Constraints - } - return nil -} - -func (ctx *serviceInspectContext) HasUpdateConfig() bool { - return ctx.Service.Spec.UpdateConfig != nil -} - -func (ctx *serviceInspectContext) UpdateParallelism() uint64 { - return ctx.Service.Spec.UpdateConfig.Parallelism -} - -func (ctx *serviceInspectContext) HasUpdateDelay() bool { - return ctx.Service.Spec.UpdateConfig.Delay.Nanoseconds() > 0 -} - -func (ctx *serviceInspectContext) UpdateDelay() time.Duration { - return ctx.Service.Spec.UpdateConfig.Delay -} - -func (ctx *serviceInspectContext) UpdateOnFailure() string { - return ctx.Service.Spec.UpdateConfig.FailureAction -} - -func (ctx *serviceInspectContext) HasUpdateMonitor() bool { - return ctx.Service.Spec.UpdateConfig.Monitor.Nanoseconds() > 0 -} - -func (ctx *serviceInspectContext) UpdateMonitor() time.Duration { - return ctx.Service.Spec.UpdateConfig.Monitor -} - -func (ctx *serviceInspectContext) UpdateMaxFailureRatio() float32 { - return ctx.Service.Spec.UpdateConfig.MaxFailureRatio -} - -func (ctx *serviceInspectContext) ContainerImage() string { - return ctx.Service.Spec.TaskTemplate.ContainerSpec.Image -} - -func (ctx *serviceInspectContext) ContainerArgs() []string { - return ctx.Service.Spec.TaskTemplate.ContainerSpec.Args -} - -func (ctx *serviceInspectContext) ContainerEnv() []string { - return ctx.Service.Spec.TaskTemplate.ContainerSpec.Env -} - -func (ctx *serviceInspectContext) ContainerWorkDir() string { - return ctx.Service.Spec.TaskTemplate.ContainerSpec.Dir -} - -func (ctx *serviceInspectContext) ContainerUser() string { - return ctx.Service.Spec.TaskTemplate.ContainerSpec.User -} - -func (ctx *serviceInspectContext) ContainerMounts() []mounttypes.Mount { - return ctx.Service.Spec.TaskTemplate.ContainerSpec.Mounts -} - -func (ctx *serviceInspectContext) HasResources() bool { - return ctx.Service.Spec.TaskTemplate.Resources != nil -} - -func (ctx *serviceInspectContext) HasResourceReservations() bool { - if ctx.Service.Spec.TaskTemplate.Resources == nil || ctx.Service.Spec.TaskTemplate.Resources.Reservations == nil { - return false - } - return ctx.Service.Spec.TaskTemplate.Resources.Reservations.NanoCPUs > 0 || ctx.Service.Spec.TaskTemplate.Resources.Reservations.MemoryBytes > 0 -} - -func (ctx *serviceInspectContext) ResourceReservationNanoCPUs() float64 { - if ctx.Service.Spec.TaskTemplate.Resources.Reservations.NanoCPUs == 0 { - return float64(0) - } - return float64(ctx.Service.Spec.TaskTemplate.Resources.Reservations.NanoCPUs) / 1e9 -} - -func (ctx *serviceInspectContext) ResourceReservationMemory() string { - if ctx.Service.Spec.TaskTemplate.Resources.Reservations.MemoryBytes == 0 { - return "" - } - return units.BytesSize(float64(ctx.Service.Spec.TaskTemplate.Resources.Reservations.MemoryBytes)) -} - -func (ctx *serviceInspectContext) HasResourceLimits() bool { - if ctx.Service.Spec.TaskTemplate.Resources == nil || ctx.Service.Spec.TaskTemplate.Resources.Limits == nil { - return false - } - return ctx.Service.Spec.TaskTemplate.Resources.Limits.NanoCPUs > 0 || ctx.Service.Spec.TaskTemplate.Resources.Limits.MemoryBytes > 0 -} - -func (ctx *serviceInspectContext) ResourceLimitsNanoCPUs() float64 { - return float64(ctx.Service.Spec.TaskTemplate.Resources.Limits.NanoCPUs) / 1e9 -} - -func (ctx *serviceInspectContext) ResourceLimitMemory() string { - if ctx.Service.Spec.TaskTemplate.Resources.Limits.MemoryBytes == 0 { - return "" - } - return units.BytesSize(float64(ctx.Service.Spec.TaskTemplate.Resources.Limits.MemoryBytes)) -} - -func (ctx *serviceInspectContext) Networks() []string { - var out []string - for _, n := range ctx.Service.Spec.Networks { - out = append(out, n.Target) - } - return out -} - -func (ctx *serviceInspectContext) EndpointMode() string { - if ctx.Service.Spec.EndpointSpec == nil { - return "" - } - - return string(ctx.Service.Spec.EndpointSpec.Mode) -} - -func (ctx *serviceInspectContext) Ports() []swarm.PortConfig { - return ctx.Service.Endpoint.Ports -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/stats.go b/vendor/github.com/docker/docker/cli/command/formatter/stats.go deleted file mode 100644 index 7997f99..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/stats.go +++ /dev/null @@ -1,211 +0,0 @@ -package formatter - -import ( - "fmt" - "sync" - - units "github.com/docker/go-units" -) - -const ( - winOSType = "windows" - defaultStatsTableFormat = "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}" - winDefaultStatsTableFormat = "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}" - - containerHeader = "CONTAINER" - cpuPercHeader = "CPU %" - netIOHeader = "NET I/O" - blockIOHeader = "BLOCK I/O" - memPercHeader = "MEM %" // Used only on Linux - winMemUseHeader = "PRIV WORKING SET" // Used only on Windows - memUseHeader = "MEM USAGE / LIMIT" // Used only on Linux - pidsHeader = "PIDS" // Used only on Linux -) - -// StatsEntry represents represents the statistics data collected from a container -type StatsEntry struct { - Container string - Name string - ID string - CPUPercentage float64 - Memory float64 // On Windows this is the private working set - MemoryLimit float64 // Not used on Windows - MemoryPercentage float64 // Not used on Windows - NetworkRx float64 - NetworkTx float64 - BlockRead float64 - BlockWrite float64 - PidsCurrent uint64 // Not used on Windows - IsInvalid bool - OSType string -} - -// ContainerStats represents an entity to store containers statistics synchronously -type ContainerStats struct { - mutex sync.Mutex - StatsEntry - err error -} - -// GetError returns the container statistics error. -// This is used to determine whether the statistics are valid or not -func (cs *ContainerStats) GetError() error { - cs.mutex.Lock() - defer cs.mutex.Unlock() - return cs.err -} - -// SetErrorAndReset zeroes all the container statistics and store the error. -// It is used when receiving time out error during statistics collecting to reduce lock overhead -func (cs *ContainerStats) SetErrorAndReset(err error) { - cs.mutex.Lock() - defer cs.mutex.Unlock() - cs.CPUPercentage = 0 - cs.Memory = 0 - cs.MemoryPercentage = 0 - cs.MemoryLimit = 0 - cs.NetworkRx = 0 - cs.NetworkTx = 0 - cs.BlockRead = 0 - cs.BlockWrite = 0 - cs.PidsCurrent = 0 - cs.err = err - cs.IsInvalid = true -} - -// SetError sets container statistics error -func (cs *ContainerStats) SetError(err error) { - cs.mutex.Lock() - defer cs.mutex.Unlock() - cs.err = err - if err != nil { - cs.IsInvalid = true - } -} - -// SetStatistics set the container statistics -func (cs *ContainerStats) SetStatistics(s StatsEntry) { - cs.mutex.Lock() - defer cs.mutex.Unlock() - s.Container = cs.Container - s.OSType = cs.OSType - cs.StatsEntry = s -} - -// GetStatistics returns container statistics with other meta data such as the container name -func (cs *ContainerStats) GetStatistics() StatsEntry { - cs.mutex.Lock() - defer cs.mutex.Unlock() - return cs.StatsEntry -} - -// NewStatsFormat returns a format for rendering an CStatsContext -func NewStatsFormat(source, osType string) Format { - if source == TableFormatKey { - if osType == winOSType { - return Format(winDefaultStatsTableFormat) - } - return Format(defaultStatsTableFormat) - } - return Format(source) -} - -// NewContainerStats returns a new ContainerStats entity and sets in it the given name -func NewContainerStats(container, osType string) *ContainerStats { - return &ContainerStats{ - StatsEntry: StatsEntry{Container: container, OSType: osType}, - } -} - -// ContainerStatsWrite renders the context for a list of containers statistics -func ContainerStatsWrite(ctx Context, containerStats []StatsEntry) error { - render := func(format func(subContext subContext) error) error { - for _, cstats := range containerStats { - containerStatsCtx := &containerStatsContext{ - s: cstats, - } - if err := format(containerStatsCtx); err != nil { - return err - } - } - return nil - } - return ctx.Write(&containerStatsContext{}, render) -} - -type containerStatsContext struct { - HeaderContext - s StatsEntry -} - -func (c *containerStatsContext) Container() string { - c.AddHeader(containerHeader) - return c.s.Container -} - -func (c *containerStatsContext) Name() string { - c.AddHeader(nameHeader) - name := c.s.Name[1:] - return name -} - -func (c *containerStatsContext) ID() string { - c.AddHeader(containerIDHeader) - return c.s.ID -} - -func (c *containerStatsContext) CPUPerc() string { - c.AddHeader(cpuPercHeader) - if c.s.IsInvalid { - return fmt.Sprintf("--") - } - return fmt.Sprintf("%.2f%%", c.s.CPUPercentage) -} - -func (c *containerStatsContext) MemUsage() string { - header := memUseHeader - if c.s.OSType == winOSType { - header = winMemUseHeader - } - c.AddHeader(header) - if c.s.IsInvalid { - return fmt.Sprintf("-- / --") - } - if c.s.OSType == winOSType { - return fmt.Sprintf("%s", units.BytesSize(c.s.Memory)) - } - return fmt.Sprintf("%s / %s", units.BytesSize(c.s.Memory), units.BytesSize(c.s.MemoryLimit)) -} - -func (c *containerStatsContext) MemPerc() string { - header := memPercHeader - c.AddHeader(header) - if c.s.IsInvalid || c.s.OSType == winOSType { - return fmt.Sprintf("--") - } - return fmt.Sprintf("%.2f%%", c.s.MemoryPercentage) -} - -func (c *containerStatsContext) NetIO() string { - c.AddHeader(netIOHeader) - if c.s.IsInvalid { - return fmt.Sprintf("--") - } - return fmt.Sprintf("%s / %s", units.HumanSizeWithPrecision(c.s.NetworkRx, 3), units.HumanSizeWithPrecision(c.s.NetworkTx, 3)) -} - -func (c *containerStatsContext) BlockIO() string { - c.AddHeader(blockIOHeader) - if c.s.IsInvalid { - return fmt.Sprintf("--") - } - return fmt.Sprintf("%s / %s", units.HumanSizeWithPrecision(c.s.BlockRead, 3), units.HumanSizeWithPrecision(c.s.BlockWrite, 3)) -} - -func (c *containerStatsContext) PIDs() string { - c.AddHeader(pidsHeader) - if c.s.IsInvalid || c.s.OSType == winOSType { - return fmt.Sprintf("--") - } - return fmt.Sprintf("%d", c.s.PidsCurrent) -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/stats_test.go b/vendor/github.com/docker/docker/cli/command/formatter/stats_test.go deleted file mode 100644 index d5a17cc..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/stats_test.go +++ /dev/null @@ -1,228 +0,0 @@ -package formatter - -import ( - "bytes" - "testing" - - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestContainerStatsContext(t *testing.T) { - containerID := stringid.GenerateRandomID() - - var ctx containerStatsContext - tt := []struct { - stats StatsEntry - expValue string - expHeader string - call func() string - }{ - {StatsEntry{Container: containerID}, containerID, containerHeader, ctx.Container}, - {StatsEntry{CPUPercentage: 5.5}, "5.50%", cpuPercHeader, ctx.CPUPerc}, - {StatsEntry{CPUPercentage: 5.5, IsInvalid: true}, "--", cpuPercHeader, ctx.CPUPerc}, - {StatsEntry{NetworkRx: 0.31, NetworkTx: 12.3}, "0.31 B / 12.3 B", netIOHeader, ctx.NetIO}, - {StatsEntry{NetworkRx: 0.31, NetworkTx: 12.3, IsInvalid: true}, "--", netIOHeader, ctx.NetIO}, - {StatsEntry{BlockRead: 0.1, BlockWrite: 2.3}, "0.1 B / 2.3 B", blockIOHeader, ctx.BlockIO}, - {StatsEntry{BlockRead: 0.1, BlockWrite: 2.3, IsInvalid: true}, "--", blockIOHeader, ctx.BlockIO}, - {StatsEntry{MemoryPercentage: 10.2}, "10.20%", memPercHeader, ctx.MemPerc}, - {StatsEntry{MemoryPercentage: 10.2, IsInvalid: true}, "--", memPercHeader, ctx.MemPerc}, - {StatsEntry{MemoryPercentage: 10.2, OSType: "windows"}, "--", memPercHeader, ctx.MemPerc}, - {StatsEntry{Memory: 24, MemoryLimit: 30}, "24 B / 30 B", memUseHeader, ctx.MemUsage}, - {StatsEntry{Memory: 24, MemoryLimit: 30, IsInvalid: true}, "-- / --", memUseHeader, ctx.MemUsage}, - {StatsEntry{Memory: 24, MemoryLimit: 30, OSType: "windows"}, "24 B", winMemUseHeader, ctx.MemUsage}, - {StatsEntry{PidsCurrent: 10}, "10", pidsHeader, ctx.PIDs}, - {StatsEntry{PidsCurrent: 10, IsInvalid: true}, "--", pidsHeader, ctx.PIDs}, - {StatsEntry{PidsCurrent: 10, OSType: "windows"}, "--", pidsHeader, ctx.PIDs}, - } - - for _, te := range tt { - ctx = containerStatsContext{s: te.stats} - if v := te.call(); v != te.expValue { - t.Fatalf("Expected %q, got %q", te.expValue, v) - } - - h := ctx.FullHeader() - if h != te.expHeader { - t.Fatalf("Expected %q, got %q", te.expHeader, h) - } - } -} - -func TestContainerStatsContextWrite(t *testing.T) { - tt := []struct { - context Context - expected string - }{ - { - Context{Format: "{{InvalidFunction}}"}, - `Template parsing error: template: :1: function "InvalidFunction" not defined -`, - }, - { - Context{Format: "{{nil}}"}, - `Template parsing error: template: :1:2: executing "" at : nil is not a command -`, - }, - { - Context{Format: "table {{.MemUsage}}"}, - `MEM USAGE / LIMIT -20 B / 20 B --- / -- -`, - }, - { - Context{Format: "{{.Container}} {{.CPUPerc}}"}, - `container1 20.00% -container2 -- -`, - }, - } - - for _, te := range tt { - stats := []StatsEntry{ - { - Container: "container1", - CPUPercentage: 20, - Memory: 20, - MemoryLimit: 20, - MemoryPercentage: 20, - NetworkRx: 20, - NetworkTx: 20, - BlockRead: 20, - BlockWrite: 20, - PidsCurrent: 2, - IsInvalid: false, - OSType: "linux", - }, - { - Container: "container2", - CPUPercentage: 30, - Memory: 30, - MemoryLimit: 30, - MemoryPercentage: 30, - NetworkRx: 30, - NetworkTx: 30, - BlockRead: 30, - BlockWrite: 30, - PidsCurrent: 3, - IsInvalid: true, - OSType: "linux", - }, - } - var out bytes.Buffer - te.context.Output = &out - err := ContainerStatsWrite(te.context, stats) - if err != nil { - assert.Error(t, err, te.expected) - } else { - assert.Equal(t, out.String(), te.expected) - } - } -} - -func TestContainerStatsContextWriteWindows(t *testing.T) { - tt := []struct { - context Context - expected string - }{ - { - Context{Format: "table {{.MemUsage}}"}, - `PRIV WORKING SET -20 B --- / -- -`, - }, - { - Context{Format: "{{.Container}} {{.CPUPerc}}"}, - `container1 20.00% -container2 -- -`, - }, - { - Context{Format: "{{.Container}} {{.MemPerc}} {{.PIDs}}"}, - `container1 -- -- -container2 -- -- -`, - }, - } - - for _, te := range tt { - stats := []StatsEntry{ - { - Container: "container1", - CPUPercentage: 20, - Memory: 20, - MemoryLimit: 20, - MemoryPercentage: 20, - NetworkRx: 20, - NetworkTx: 20, - BlockRead: 20, - BlockWrite: 20, - PidsCurrent: 2, - IsInvalid: false, - OSType: "windows", - }, - { - Container: "container2", - CPUPercentage: 30, - Memory: 30, - MemoryLimit: 30, - MemoryPercentage: 30, - NetworkRx: 30, - NetworkTx: 30, - BlockRead: 30, - BlockWrite: 30, - PidsCurrent: 3, - IsInvalid: true, - OSType: "windows", - }, - } - var out bytes.Buffer - te.context.Output = &out - err := ContainerStatsWrite(te.context, stats) - if err != nil { - assert.Error(t, err, te.expected) - } else { - assert.Equal(t, out.String(), te.expected) - } - } -} - -func TestContainerStatsContextWriteWithNoStats(t *testing.T) { - var out bytes.Buffer - - contexts := []struct { - context Context - expected string - }{ - { - Context{ - Format: "{{.Container}}", - Output: &out, - }, - "", - }, - { - Context{ - Format: "table {{.Container}}", - Output: &out, - }, - "CONTAINER\n", - }, - { - Context{ - Format: "table {{.Container}}\t{{.CPUPerc}}", - Output: &out, - }, - "CONTAINER CPU %\n", - }, - } - - for _, context := range contexts { - ContainerStatsWrite(context.context, []StatsEntry{}) - assert.Equal(t, context.expected, out.String()) - // Clean buffer - out.Reset() - } -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/volume.go b/vendor/github.com/docker/docker/cli/command/formatter/volume.go deleted file mode 100644 index 90c9b13..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/volume.go +++ /dev/null @@ -1,121 +0,0 @@ -package formatter - -import ( - "fmt" - "strings" - - "github.com/docker/docker/api/types" - units "github.com/docker/go-units" -) - -const ( - defaultVolumeQuietFormat = "{{.Name}}" - defaultVolumeTableFormat = "table {{.Driver}}\t{{.Name}}" - - volumeNameHeader = "VOLUME NAME" - mountpointHeader = "MOUNTPOINT" - linksHeader = "LINKS" - // Status header ? -) - -// NewVolumeFormat returns a format for use with a volume Context -func NewVolumeFormat(source string, quiet bool) Format { - switch source { - case TableFormatKey: - if quiet { - return defaultVolumeQuietFormat - } - return defaultVolumeTableFormat - case RawFormatKey: - if quiet { - return `name: {{.Name}}` - } - return `name: {{.Name}}\ndriver: {{.Driver}}\n` - } - return Format(source) -} - -// VolumeWrite writes formatted volumes using the Context -func VolumeWrite(ctx Context, volumes []*types.Volume) error { - render := func(format func(subContext subContext) error) error { - for _, volume := range volumes { - if err := format(&volumeContext{v: *volume}); err != nil { - return err - } - } - return nil - } - return ctx.Write(&volumeContext{}, render) -} - -type volumeContext struct { - HeaderContext - v types.Volume -} - -func (c *volumeContext) MarshalJSON() ([]byte, error) { - return marshalJSON(c) -} - -func (c *volumeContext) Name() string { - c.AddHeader(volumeNameHeader) - return c.v.Name -} - -func (c *volumeContext) Driver() string { - c.AddHeader(driverHeader) - return c.v.Driver -} - -func (c *volumeContext) Scope() string { - c.AddHeader(scopeHeader) - return c.v.Scope -} - -func (c *volumeContext) Mountpoint() string { - c.AddHeader(mountpointHeader) - return c.v.Mountpoint -} - -func (c *volumeContext) Labels() string { - c.AddHeader(labelsHeader) - if c.v.Labels == nil { - return "" - } - - var joinLabels []string - for k, v := range c.v.Labels { - joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v)) - } - return strings.Join(joinLabels, ",") -} - -func (c *volumeContext) Label(name string) string { - - n := strings.Split(name, ".") - r := strings.NewReplacer("-", " ", "_", " ") - h := r.Replace(n[len(n)-1]) - - c.AddHeader(h) - - if c.v.Labels == nil { - return "" - } - return c.v.Labels[name] -} - -func (c *volumeContext) Links() string { - c.AddHeader(linksHeader) - if c.v.UsageData == nil { - return "N/A" - } - return fmt.Sprintf("%d", c.v.UsageData.RefCount) -} - -func (c *volumeContext) Size() string { - c.AddHeader(sizeHeader) - if c.v.UsageData == nil { - return "N/A" - } - return units.HumanSize(float64(c.v.UsageData.Size)) -} diff --git a/vendor/github.com/docker/docker/cli/command/formatter/volume_test.go b/vendor/github.com/docker/docker/cli/command/formatter/volume_test.go deleted file mode 100644 index 9ec18b6..0000000 --- a/vendor/github.com/docker/docker/cli/command/formatter/volume_test.go +++ /dev/null @@ -1,189 +0,0 @@ -package formatter - -import ( - "bytes" - "encoding/json" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestVolumeContext(t *testing.T) { - volumeName := stringid.GenerateRandomID() - - var ctx volumeContext - cases := []struct { - volumeCtx volumeContext - expValue string - expHeader string - call func() string - }{ - {volumeContext{ - v: types.Volume{Name: volumeName}, - }, volumeName, volumeNameHeader, ctx.Name}, - {volumeContext{ - v: types.Volume{Driver: "driver_name"}, - }, "driver_name", driverHeader, ctx.Driver}, - {volumeContext{ - v: types.Volume{Scope: "local"}, - }, "local", scopeHeader, ctx.Scope}, - {volumeContext{ - v: types.Volume{Mountpoint: "mountpoint"}, - }, "mountpoint", mountpointHeader, ctx.Mountpoint}, - {volumeContext{ - v: types.Volume{}, - }, "", labelsHeader, ctx.Labels}, - {volumeContext{ - v: types.Volume{Labels: map[string]string{"label1": "value1", "label2": "value2"}}, - }, "label1=value1,label2=value2", labelsHeader, ctx.Labels}, - } - - for _, c := range cases { - ctx = c.volumeCtx - v := c.call() - if strings.Contains(v, ",") { - compareMultipleValues(t, v, c.expValue) - } else if v != c.expValue { - t.Fatalf("Expected %s, was %s\n", c.expValue, v) - } - - h := ctx.FullHeader() - if h != c.expHeader { - t.Fatalf("Expected %s, was %s\n", c.expHeader, h) - } - } -} - -func TestVolumeContextWrite(t *testing.T) { - cases := []struct { - context Context - expected string - }{ - - // Errors - { - Context{Format: "{{InvalidFunction}}"}, - `Template parsing error: template: :1: function "InvalidFunction" not defined -`, - }, - { - Context{Format: "{{nil}}"}, - `Template parsing error: template: :1:2: executing "" at : nil is not a command -`, - }, - // Table format - { - Context{Format: NewVolumeFormat("table", false)}, - `DRIVER VOLUME NAME -foo foobar_baz -bar foobar_bar -`, - }, - { - Context{Format: NewVolumeFormat("table", true)}, - `foobar_baz -foobar_bar -`, - }, - { - Context{Format: NewVolumeFormat("table {{.Name}}", false)}, - `VOLUME NAME -foobar_baz -foobar_bar -`, - }, - { - Context{Format: NewVolumeFormat("table {{.Name}}", true)}, - `VOLUME NAME -foobar_baz -foobar_bar -`, - }, - // Raw Format - { - Context{Format: NewVolumeFormat("raw", false)}, - `name: foobar_baz -driver: foo - -name: foobar_bar -driver: bar - -`, - }, - { - Context{Format: NewVolumeFormat("raw", true)}, - `name: foobar_baz -name: foobar_bar -`, - }, - // Custom Format - { - Context{Format: NewVolumeFormat("{{.Name}}", false)}, - `foobar_baz -foobar_bar -`, - }, - } - - for _, testcase := range cases { - volumes := []*types.Volume{ - {Name: "foobar_baz", Driver: "foo"}, - {Name: "foobar_bar", Driver: "bar"}, - } - out := bytes.NewBufferString("") - testcase.context.Output = out - err := VolumeWrite(testcase.context, volumes) - if err != nil { - assert.Error(t, err, testcase.expected) - } else { - assert.Equal(t, out.String(), testcase.expected) - } - } -} - -func TestVolumeContextWriteJSON(t *testing.T) { - volumes := []*types.Volume{ - {Driver: "foo", Name: "foobar_baz"}, - {Driver: "bar", Name: "foobar_bar"}, - } - expectedJSONs := []map[string]interface{}{ - {"Driver": "foo", "Labels": "", "Links": "N/A", "Mountpoint": "", "Name": "foobar_baz", "Scope": "", "Size": "N/A"}, - {"Driver": "bar", "Labels": "", "Links": "N/A", "Mountpoint": "", "Name": "foobar_bar", "Scope": "", "Size": "N/A"}, - } - out := bytes.NewBufferString("") - err := VolumeWrite(Context{Format: "{{json .}}", Output: out}, volumes) - if err != nil { - t.Fatal(err) - } - for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") { - t.Logf("Output: line %d: %s", i, line) - var m map[string]interface{} - if err := json.Unmarshal([]byte(line), &m); err != nil { - t.Fatal(err) - } - assert.DeepEqual(t, m, expectedJSONs[i]) - } -} - -func TestVolumeContextWriteJSONField(t *testing.T) { - volumes := []*types.Volume{ - {Driver: "foo", Name: "foobar_baz"}, - {Driver: "bar", Name: "foobar_bar"}, - } - out := bytes.NewBufferString("") - err := VolumeWrite(Context{Format: "{{json .Name}}", Output: out}, volumes) - if err != nil { - t.Fatal(err) - } - for i, line := range strings.Split(strings.TrimSpace(out.String()), "\n") { - t.Logf("Output: line %d: %s", i, line) - var s string - if err := json.Unmarshal([]byte(line), &s); err != nil { - t.Fatal(err) - } - assert.Equal(t, s, volumes[i].Name) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/idresolver/idresolver.go b/vendor/github.com/docker/docker/cli/command/idresolver/idresolver.go deleted file mode 100644 index 511b1a8..0000000 --- a/vendor/github.com/docker/docker/cli/command/idresolver/idresolver.go +++ /dev/null @@ -1,90 +0,0 @@ -package idresolver - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/client" - "github.com/docker/docker/pkg/stringid" -) - -// IDResolver provides ID to Name resolution. -type IDResolver struct { - client client.APIClient - noResolve bool - cache map[string]string -} - -// New creates a new IDResolver. -func New(client client.APIClient, noResolve bool) *IDResolver { - return &IDResolver{ - client: client, - noResolve: noResolve, - cache: make(map[string]string), - } -} - -func (r *IDResolver) get(ctx context.Context, t interface{}, id string) (string, error) { - switch t := t.(type) { - case swarm.Node: - node, _, err := r.client.NodeInspectWithRaw(ctx, id) - if err != nil { - return id, nil - } - if node.Spec.Annotations.Name != "" { - return node.Spec.Annotations.Name, nil - } - if node.Description.Hostname != "" { - return node.Description.Hostname, nil - } - return id, nil - case swarm.Service: - service, _, err := r.client.ServiceInspectWithRaw(ctx, id) - if err != nil { - return id, nil - } - return service.Spec.Annotations.Name, nil - case swarm.Task: - // If the caller passes the full task there's no need to do a lookup. - if t.ID == "" { - var err error - - t, _, err = r.client.TaskInspectWithRaw(ctx, id) - if err != nil { - return id, nil - } - } - taskID := stringid.TruncateID(t.ID) - if t.ServiceID == "" { - return taskID, nil - } - service, err := r.Resolve(ctx, swarm.Service{}, t.ServiceID) - if err != nil { - return "", err - } - return fmt.Sprintf("%s.%d.%s", service, t.Slot, taskID), nil - default: - return "", fmt.Errorf("unsupported type") - } - -} - -// Resolve will attempt to resolve an ID to a Name by querying the manager. -// Results are stored into a cache. -// If the `-n` flag is used in the command-line, resolution is disabled. -func (r *IDResolver) Resolve(ctx context.Context, t interface{}, id string) (string, error) { - if r.noResolve { - return id, nil - } - if name, ok := r.cache[id]; ok { - return name, nil - } - name, err := r.get(ctx, t, id) - if err != nil { - return "", err - } - r.cache[id] = name - return name, nil -} diff --git a/vendor/github.com/docker/docker/cli/command/image/build.go b/vendor/github.com/docker/docker/cli/command/image/build.go deleted file mode 100644 index 0c88af5..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/build.go +++ /dev/null @@ -1,477 +0,0 @@ -package image - -import ( - "archive/tar" - "bufio" - "bytes" - "fmt" - "io" - "os" - "path/filepath" - "regexp" - "runtime" - - "golang.org/x/net/context" - - "github.com/docker/docker/api" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/builder" - "github.com/docker/docker/builder/dockerignore" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/fileutils" - "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/streamformatter" - "github.com/docker/docker/pkg/urlutil" - "github.com/docker/docker/reference" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type buildOptions struct { - context string - dockerfileName string - tags opts.ListOpts - labels opts.ListOpts - buildArgs opts.ListOpts - ulimits *runconfigopts.UlimitOpt - memory string - memorySwap string - shmSize string - cpuShares int64 - cpuPeriod int64 - cpuQuota int64 - cpuSetCpus string - cpuSetMems string - cgroupParent string - isolation string - quiet bool - noCache bool - rm bool - forceRm bool - pull bool - cacheFrom []string - compress bool - securityOpt []string - networkMode string - squash bool -} - -// NewBuildCommand creates a new `docker build` command -func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command { - ulimits := make(map[string]*units.Ulimit) - options := buildOptions{ - tags: opts.NewListOpts(validateTag), - buildArgs: opts.NewListOpts(runconfigopts.ValidateEnv), - ulimits: runconfigopts.NewUlimitOpt(&ulimits), - labels: opts.NewListOpts(runconfigopts.ValidateEnv), - } - - cmd := &cobra.Command{ - Use: "build [OPTIONS] PATH | URL | -", - Short: "Build an image from a Dockerfile", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - options.context = args[0] - return runBuild(dockerCli, options) - }, - } - - flags := cmd.Flags() - - flags.VarP(&options.tags, "tag", "t", "Name and optionally a tag in the 'name:tag' format") - flags.Var(&options.buildArgs, "build-arg", "Set build-time variables") - flags.Var(options.ulimits, "ulimit", "Ulimit options") - flags.StringVarP(&options.dockerfileName, "file", "f", "", "Name of the Dockerfile (Default is 'PATH/Dockerfile')") - flags.StringVarP(&options.memory, "memory", "m", "", "Memory limit") - flags.StringVar(&options.memorySwap, "memory-swap", "", "Swap limit equal to memory plus swap: '-1' to enable unlimited swap") - flags.StringVar(&options.shmSize, "shm-size", "", "Size of /dev/shm, default value is 64MB") - flags.Int64VarP(&options.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)") - flags.Int64Var(&options.cpuPeriod, "cpu-period", 0, "Limit the CPU CFS (Completely Fair Scheduler) period") - flags.Int64Var(&options.cpuQuota, "cpu-quota", 0, "Limit the CPU CFS (Completely Fair Scheduler) quota") - flags.StringVar(&options.cpuSetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)") - flags.StringVar(&options.cpuSetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)") - flags.StringVar(&options.cgroupParent, "cgroup-parent", "", "Optional parent cgroup for the container") - flags.StringVar(&options.isolation, "isolation", "", "Container isolation technology") - flags.Var(&options.labels, "label", "Set metadata for an image") - flags.BoolVar(&options.noCache, "no-cache", false, "Do not use cache when building the image") - flags.BoolVar(&options.rm, "rm", true, "Remove intermediate containers after a successful build") - flags.BoolVar(&options.forceRm, "force-rm", false, "Always remove intermediate containers") - flags.BoolVarP(&options.quiet, "quiet", "q", false, "Suppress the build output and print image ID on success") - flags.BoolVar(&options.pull, "pull", false, "Always attempt to pull a newer version of the image") - flags.StringSliceVar(&options.cacheFrom, "cache-from", []string{}, "Images to consider as cache sources") - flags.BoolVar(&options.compress, "compress", false, "Compress the build context using gzip") - flags.StringSliceVar(&options.securityOpt, "security-opt", []string{}, "Security options") - flags.StringVar(&options.networkMode, "network", "default", "Set the networking mode for the RUN instructions during build") - - command.AddTrustedFlags(flags, true) - - flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer") - flags.SetAnnotation("squash", "experimental", nil) - flags.SetAnnotation("squash", "version", []string{"1.25"}) - - return cmd -} - -// lastProgressOutput is the same as progress.Output except -// that it only output with the last update. It is used in -// non terminal scenarios to depresss verbose messages -type lastProgressOutput struct { - output progress.Output -} - -// WriteProgress formats progress information from a ProgressReader. -func (out *lastProgressOutput) WriteProgress(prog progress.Progress) error { - if !prog.LastUpdate { - return nil - } - - return out.output.WriteProgress(prog) -} - -func runBuild(dockerCli *command.DockerCli, options buildOptions) error { - - var ( - buildCtx io.ReadCloser - err error - contextDir string - tempDir string - relDockerfile string - progBuff io.Writer - buildBuff io.Writer - ) - - specifiedContext := options.context - progBuff = dockerCli.Out() - buildBuff = dockerCli.Out() - if options.quiet { - progBuff = bytes.NewBuffer(nil) - buildBuff = bytes.NewBuffer(nil) - } - - switch { - case specifiedContext == "-": - buildCtx, relDockerfile, err = builder.GetContextFromReader(dockerCli.In(), options.dockerfileName) - case urlutil.IsGitURL(specifiedContext): - tempDir, relDockerfile, err = builder.GetContextFromGitURL(specifiedContext, options.dockerfileName) - case urlutil.IsURL(specifiedContext): - buildCtx, relDockerfile, err = builder.GetContextFromURL(progBuff, specifiedContext, options.dockerfileName) - default: - contextDir, relDockerfile, err = builder.GetContextFromLocalDir(specifiedContext, options.dockerfileName) - } - - if err != nil { - if options.quiet && urlutil.IsURL(specifiedContext) { - fmt.Fprintln(dockerCli.Err(), progBuff) - } - return fmt.Errorf("unable to prepare context: %s", err) - } - - if tempDir != "" { - defer os.RemoveAll(tempDir) - contextDir = tempDir - } - - if buildCtx == nil { - // And canonicalize dockerfile name to a platform-independent one - relDockerfile, err = archive.CanonicalTarNameForPath(relDockerfile) - if err != nil { - return fmt.Errorf("cannot canonicalize dockerfile path %s: %v", relDockerfile, err) - } - - f, err := os.Open(filepath.Join(contextDir, ".dockerignore")) - if err != nil && !os.IsNotExist(err) { - return err - } - defer f.Close() - - var excludes []string - if err == nil { - excludes, err = dockerignore.ReadAll(f) - if err != nil { - return err - } - } - - if err := builder.ValidateContextDirectory(contextDir, excludes); err != nil { - return fmt.Errorf("Error checking context: '%s'.", err) - } - - // If .dockerignore mentions .dockerignore or the Dockerfile - // then make sure we send both files over to the daemon - // because Dockerfile is, obviously, needed no matter what, and - // .dockerignore is needed to know if either one needs to be - // removed. The daemon will remove them for us, if needed, after it - // parses the Dockerfile. Ignore errors here, as they will have been - // caught by validateContextDirectory above. - var includes = []string{"."} - keepThem1, _ := fileutils.Matches(".dockerignore", excludes) - keepThem2, _ := fileutils.Matches(relDockerfile, excludes) - if keepThem1 || keepThem2 { - includes = append(includes, ".dockerignore", relDockerfile) - } - - compression := archive.Uncompressed - if options.compress { - compression = archive.Gzip - } - buildCtx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{ - Compression: compression, - ExcludePatterns: excludes, - IncludeFiles: includes, - }) - if err != nil { - return err - } - } - - ctx := context.Background() - - var resolvedTags []*resolvedTag - if command.IsTrusted() { - translator := func(ctx context.Context, ref reference.NamedTagged) (reference.Canonical, error) { - return TrustedReference(ctx, dockerCli, ref, nil) - } - // Wrap the tar archive to replace the Dockerfile entry with the rewritten - // Dockerfile which uses trusted pulls. - buildCtx = replaceDockerfileTarWrapper(ctx, buildCtx, relDockerfile, translator, &resolvedTags) - } - - // Setup an upload progress bar - progressOutput := streamformatter.NewStreamFormatter().NewProgressOutput(progBuff, true) - if !dockerCli.Out().IsTerminal() { - progressOutput = &lastProgressOutput{output: progressOutput} - } - - var body io.Reader = progress.NewProgressReader(buildCtx, progressOutput, 0, "", "Sending build context to Docker daemon") - - var memory int64 - if options.memory != "" { - parsedMemory, err := units.RAMInBytes(options.memory) - if err != nil { - return err - } - memory = parsedMemory - } - - var memorySwap int64 - if options.memorySwap != "" { - if options.memorySwap == "-1" { - memorySwap = -1 - } else { - parsedMemorySwap, err := units.RAMInBytes(options.memorySwap) - if err != nil { - return err - } - memorySwap = parsedMemorySwap - } - } - - var shmSize int64 - if options.shmSize != "" { - shmSize, err = units.RAMInBytes(options.shmSize) - if err != nil { - return err - } - } - - authConfigs, _ := dockerCli.GetAllCredentials() - buildOptions := types.ImageBuildOptions{ - Memory: memory, - MemorySwap: memorySwap, - Tags: options.tags.GetAll(), - SuppressOutput: options.quiet, - NoCache: options.noCache, - Remove: options.rm, - ForceRemove: options.forceRm, - PullParent: options.pull, - Isolation: container.Isolation(options.isolation), - CPUSetCPUs: options.cpuSetCpus, - CPUSetMems: options.cpuSetMems, - CPUShares: options.cpuShares, - CPUQuota: options.cpuQuota, - CPUPeriod: options.cpuPeriod, - CgroupParent: options.cgroupParent, - Dockerfile: relDockerfile, - ShmSize: shmSize, - Ulimits: options.ulimits.GetList(), - BuildArgs: runconfigopts.ConvertKVStringsToMapWithNil(options.buildArgs.GetAll()), - AuthConfigs: authConfigs, - Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()), - CacheFrom: options.cacheFrom, - SecurityOpt: options.securityOpt, - NetworkMode: options.networkMode, - Squash: options.squash, - } - - response, err := dockerCli.Client().ImageBuild(ctx, body, buildOptions) - if err != nil { - if options.quiet { - fmt.Fprintf(dockerCli.Err(), "%s", progBuff) - } - return err - } - defer response.Body.Close() - - err = jsonmessage.DisplayJSONMessagesStream(response.Body, buildBuff, dockerCli.Out().FD(), dockerCli.Out().IsTerminal(), nil) - if err != nil { - if jerr, ok := err.(*jsonmessage.JSONError); ok { - // If no error code is set, default to 1 - if jerr.Code == 0 { - jerr.Code = 1 - } - if options.quiet { - fmt.Fprintf(dockerCli.Err(), "%s%s", progBuff, buildBuff) - } - return cli.StatusError{Status: jerr.Message, StatusCode: jerr.Code} - } - } - - // Windows: show error message about modified file permissions if the - // daemon isn't running Windows. - if response.OSType != "windows" && runtime.GOOS == "windows" && !options.quiet { - fmt.Fprintln(dockerCli.Err(), `SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.`) - } - - // Everything worked so if -q was provided the output from the daemon - // should be just the image ID and we'll print that to stdout. - if options.quiet { - fmt.Fprintf(dockerCli.Out(), "%s", buildBuff) - } - - if command.IsTrusted() { - // Since the build was successful, now we must tag any of the resolved - // images from the above Dockerfile rewrite. - for _, resolved := range resolvedTags { - if err := TagTrusted(ctx, dockerCli, resolved.digestRef, resolved.tagRef); err != nil { - return err - } - } - } - - return nil -} - -type translatorFunc func(context.Context, reference.NamedTagged) (reference.Canonical, error) - -// validateTag checks if the given image name can be resolved. -func validateTag(rawRepo string) (string, error) { - _, err := reference.ParseNamed(rawRepo) - if err != nil { - return "", err - } - - return rawRepo, nil -} - -var dockerfileFromLinePattern = regexp.MustCompile(`(?i)^[\s]*FROM[ \f\r\t\v]+(?P[^ \f\r\t\v\n#]+)`) - -// resolvedTag records the repository, tag, and resolved digest reference -// from a Dockerfile rewrite. -type resolvedTag struct { - digestRef reference.Canonical - tagRef reference.NamedTagged -} - -// rewriteDockerfileFrom rewrites the given Dockerfile by resolving images in -// "FROM " instructions to a digest reference. `translator` is a -// function that takes a repository name and tag reference and returns a -// trusted digest reference. -func rewriteDockerfileFrom(ctx context.Context, dockerfile io.Reader, translator translatorFunc) (newDockerfile []byte, resolvedTags []*resolvedTag, err error) { - scanner := bufio.NewScanner(dockerfile) - buf := bytes.NewBuffer(nil) - - // Scan the lines of the Dockerfile, looking for a "FROM" line. - for scanner.Scan() { - line := scanner.Text() - - matches := dockerfileFromLinePattern.FindStringSubmatch(line) - if matches != nil && matches[1] != api.NoBaseImageSpecifier { - // Replace the line with a resolved "FROM repo@digest" - ref, err := reference.ParseNamed(matches[1]) - if err != nil { - return nil, nil, err - } - ref = reference.WithDefaultTag(ref) - if ref, ok := ref.(reference.NamedTagged); ok && command.IsTrusted() { - trustedRef, err := translator(ctx, ref) - if err != nil { - return nil, nil, err - } - - line = dockerfileFromLinePattern.ReplaceAllLiteralString(line, fmt.Sprintf("FROM %s", trustedRef.String())) - resolvedTags = append(resolvedTags, &resolvedTag{ - digestRef: trustedRef, - tagRef: ref, - }) - } - } - - _, err := fmt.Fprintln(buf, line) - if err != nil { - return nil, nil, err - } - } - - return buf.Bytes(), resolvedTags, scanner.Err() -} - -// replaceDockerfileTarWrapper wraps the given input tar archive stream and -// replaces the entry with the given Dockerfile name with the contents of the -// new Dockerfile. Returns a new tar archive stream with the replaced -// Dockerfile. -func replaceDockerfileTarWrapper(ctx context.Context, inputTarStream io.ReadCloser, dockerfileName string, translator translatorFunc, resolvedTags *[]*resolvedTag) io.ReadCloser { - pipeReader, pipeWriter := io.Pipe() - go func() { - tarReader := tar.NewReader(inputTarStream) - tarWriter := tar.NewWriter(pipeWriter) - - defer inputTarStream.Close() - - for { - hdr, err := tarReader.Next() - if err == io.EOF { - // Signals end of archive. - tarWriter.Close() - pipeWriter.Close() - return - } - if err != nil { - pipeWriter.CloseWithError(err) - return - } - - content := io.Reader(tarReader) - if hdr.Name == dockerfileName { - // This entry is the Dockerfile. Since the tar archive was - // generated from a directory on the local filesystem, the - // Dockerfile will only appear once in the archive. - var newDockerfile []byte - newDockerfile, *resolvedTags, err = rewriteDockerfileFrom(ctx, content, translator) - if err != nil { - pipeWriter.CloseWithError(err) - return - } - hdr.Size = int64(len(newDockerfile)) - content = bytes.NewBuffer(newDockerfile) - } - - if err := tarWriter.WriteHeader(hdr); err != nil { - pipeWriter.CloseWithError(err) - return - } - - if _, err := io.Copy(tarWriter, content); err != nil { - pipeWriter.CloseWithError(err) - return - } - } - }() - - return pipeReader -} diff --git a/vendor/github.com/docker/docker/cli/command/image/cmd.go b/vendor/github.com/docker/docker/cli/command/image/cmd.go deleted file mode 100644 index c3ca61f..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/cmd.go +++ /dev/null @@ -1,33 +0,0 @@ -package image - -import ( - "github.com/spf13/cobra" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" -) - -// NewImageCommand returns a cobra command for `image` subcommands -func NewImageCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "image", - Short: "Manage images", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - } - cmd.AddCommand( - NewBuildCommand(dockerCli), - NewHistoryCommand(dockerCli), - NewImportCommand(dockerCli), - NewLoadCommand(dockerCli), - NewPullCommand(dockerCli), - NewPushCommand(dockerCli), - NewSaveCommand(dockerCli), - NewTagCommand(dockerCli), - newListCommand(dockerCli), - newRemoveCommand(dockerCli), - newInspectCommand(dockerCli), - NewPruneCommand(dockerCli), - ) - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/image/history.go b/vendor/github.com/docker/docker/cli/command/image/history.go deleted file mode 100644 index 91c8f75..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/history.go +++ /dev/null @@ -1,99 +0,0 @@ -package image - -import ( - "fmt" - "strconv" - "strings" - "text/tabwriter" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/stringutils" - "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type historyOptions struct { - image string - - human bool - quiet bool - noTrunc bool -} - -// NewHistoryCommand creates a new `docker history` command -func NewHistoryCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts historyOptions - - cmd := &cobra.Command{ - Use: "history [OPTIONS] IMAGE", - Short: "Show the history of an image", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.image = args[0] - return runHistory(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.BoolVarP(&opts.human, "human", "H", true, "Print sizes and dates in human readable format") - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only show numeric IDs") - flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") - - return cmd -} - -func runHistory(dockerCli *command.DockerCli, opts historyOptions) error { - ctx := context.Background() - - history, err := dockerCli.Client().ImageHistory(ctx, opts.image) - if err != nil { - return err - } - - w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0) - - if opts.quiet { - for _, entry := range history { - if opts.noTrunc { - fmt.Fprintf(w, "%s\n", entry.ID) - } else { - fmt.Fprintf(w, "%s\n", stringid.TruncateID(entry.ID)) - } - } - w.Flush() - return nil - } - - var imageID string - var createdBy string - var created string - var size string - - fmt.Fprintln(w, "IMAGE\tCREATED\tCREATED BY\tSIZE\tCOMMENT") - for _, entry := range history { - imageID = entry.ID - createdBy = strings.Replace(entry.CreatedBy, "\t", " ", -1) - if !opts.noTrunc { - createdBy = stringutils.Ellipsis(createdBy, 45) - imageID = stringid.TruncateID(entry.ID) - } - - if opts.human { - created = units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))) + " ago" - size = units.HumanSizeWithPrecision(float64(entry.Size), 3) - } else { - created = time.Unix(entry.Created, 0).Format(time.RFC3339) - size = strconv.FormatInt(entry.Size, 10) - } - - fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", imageID, created, createdBy, size, entry.Comment) - } - w.Flush() - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/image/import.go b/vendor/github.com/docker/docker/cli/command/image/import.go deleted file mode 100644 index 60024fb..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/import.go +++ /dev/null @@ -1,88 +0,0 @@ -package image - -import ( - "io" - "os" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - dockeropts "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/pkg/urlutil" - "github.com/spf13/cobra" -) - -type importOptions struct { - source string - reference string - changes dockeropts.ListOpts - message string -} - -// NewImportCommand creates a new `docker import` command -func NewImportCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts importOptions - - cmd := &cobra.Command{ - Use: "import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]", - Short: "Import the contents from a tarball to create a filesystem image", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.source = args[0] - if len(args) > 1 { - opts.reference = args[1] - } - return runImport(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - opts.changes = dockeropts.NewListOpts(nil) - flags.VarP(&opts.changes, "change", "c", "Apply Dockerfile instruction to the created image") - flags.StringVarP(&opts.message, "message", "m", "", "Set commit message for imported image") - - return cmd -} - -func runImport(dockerCli *command.DockerCli, opts importOptions) error { - var ( - in io.Reader - srcName = opts.source - ) - - if opts.source == "-" { - in = dockerCli.In() - } else if !urlutil.IsURL(opts.source) { - srcName = "-" - file, err := os.Open(opts.source) - if err != nil { - return err - } - defer file.Close() - in = file - } - - source := types.ImageImportSource{ - Source: in, - SourceName: srcName, - } - - options := types.ImageImportOptions{ - Message: opts.message, - Changes: opts.changes.GetAll(), - } - - clnt := dockerCli.Client() - - responseBody, err := clnt.ImageImport(context.Background(), source, opts.reference, options) - if err != nil { - return err - } - defer responseBody.Close() - - return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil) -} diff --git a/vendor/github.com/docker/docker/cli/command/image/inspect.go b/vendor/github.com/docker/docker/cli/command/image/inspect.go deleted file mode 100644 index 217863c..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/inspect.go +++ /dev/null @@ -1,44 +0,0 @@ -package image - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/inspect" - "github.com/spf13/cobra" -) - -type inspectOptions struct { - format string - refs []string -} - -// newInspectCommand creates a new cobra.Command for `docker image inspect` -func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts inspectOptions - - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] IMAGE [IMAGE...]", - Short: "Display detailed information on one or more images", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.refs = args - return runInspect(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - return cmd -} - -func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - getRefFunc := func(ref string) (interface{}, []byte, error) { - return client.ImageInspectWithRaw(ctx, ref) - } - return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRefFunc) -} diff --git a/vendor/github.com/docker/docker/cli/command/image/list.go b/vendor/github.com/docker/docker/cli/command/image/list.go deleted file mode 100644 index 679604f..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/list.go +++ /dev/null @@ -1,96 +0,0 @@ -package image - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/formatter" - "github.com/docker/docker/opts" - "github.com/spf13/cobra" -) - -type imagesOptions struct { - matchName string - - quiet bool - all bool - noTrunc bool - showDigests bool - format string - filter opts.FilterOpt -} - -// NewImagesCommand creates a new `docker images` command -func NewImagesCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := imagesOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "images [OPTIONS] [REPOSITORY[:TAG]]", - Short: "List images", - Args: cli.RequiresMaxArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) > 0 { - opts.matchName = args[0] - } - return runImages(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only show numeric IDs") - flags.BoolVarP(&opts.all, "all", "a", false, "Show all images (default hides intermediate images)") - flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") - flags.BoolVar(&opts.showDigests, "digests", false, "Show digests") - flags.StringVar(&opts.format, "format", "", "Pretty-print images using a Go template") - flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") - - return cmd -} - -func newListCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := *NewImagesCommand(dockerCli) - cmd.Aliases = []string{"images", "list"} - cmd.Use = "ls [OPTIONS] [REPOSITORY[:TAG]]" - return &cmd -} - -func runImages(dockerCli *command.DockerCli, opts imagesOptions) error { - ctx := context.Background() - - filters := opts.filter.Value() - if opts.matchName != "" { - filters.Add("reference", opts.matchName) - } - - options := types.ImageListOptions{ - All: opts.all, - Filters: filters, - } - - images, err := dockerCli.Client().ImageList(ctx, options) - if err != nil { - return err - } - - format := opts.format - if len(format) == 0 { - if len(dockerCli.ConfigFile().ImagesFormat) > 0 && !opts.quiet { - format = dockerCli.ConfigFile().ImagesFormat - } else { - format = formatter.TableFormatKey - } - } - - imageCtx := formatter.ImageContext{ - Context: formatter.Context{ - Output: dockerCli.Out(), - Format: formatter.NewImageFormat(format, opts.quiet, opts.showDigests), - Trunc: !opts.noTrunc, - }, - Digest: opts.showDigests, - } - return formatter.ImageWrite(imageCtx, images) -} diff --git a/vendor/github.com/docker/docker/cli/command/image/load.go b/vendor/github.com/docker/docker/cli/command/image/load.go deleted file mode 100644 index 988f510..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/load.go +++ /dev/null @@ -1,77 +0,0 @@ -package image - -import ( - "fmt" - "io" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/pkg/system" - "github.com/spf13/cobra" -) - -type loadOptions struct { - input string - quiet bool -} - -// NewLoadCommand creates a new `docker load` command -func NewLoadCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts loadOptions - - cmd := &cobra.Command{ - Use: "load [OPTIONS]", - Short: "Load an image from a tar archive or STDIN", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runLoad(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.StringVarP(&opts.input, "input", "i", "", "Read from tar archive file, instead of STDIN") - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress the load output") - - return cmd -} - -func runLoad(dockerCli *command.DockerCli, opts loadOptions) error { - - var input io.Reader = dockerCli.In() - if opts.input != "" { - // We use system.OpenSequential to use sequential file access on Windows, avoiding - // depleting the standby list un-necessarily. On Linux, this equates to a regular os.Open. - file, err := system.OpenSequential(opts.input) - if err != nil { - return err - } - defer file.Close() - input = file - } - - // To avoid getting stuck, verify that a tar file is given either in - // the input flag or through stdin and if not display an error message and exit. - if opts.input == "" && dockerCli.In().IsTerminal() { - return fmt.Errorf("requested load from stdin, but stdin is empty") - } - - if !dockerCli.Out().IsTerminal() { - opts.quiet = true - } - response, err := dockerCli.Client().ImageLoad(context.Background(), input, opts.quiet) - if err != nil { - return err - } - defer response.Body.Close() - - if response.Body != nil && response.JSON { - return jsonmessage.DisplayJSONMessagesToStream(response.Body, dockerCli.Out(), nil) - } - - _, err = io.Copy(dockerCli.Out(), response.Body) - return err -} diff --git a/vendor/github.com/docker/docker/cli/command/image/prune.go b/vendor/github.com/docker/docker/cli/command/image/prune.go deleted file mode 100644 index 82c28fc..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/prune.go +++ /dev/null @@ -1,92 +0,0 @@ -package image - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - units "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type pruneOptions struct { - force bool - all bool -} - -// NewPruneCommand returns a new cobra prune command for images -func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts pruneOptions - - cmd := &cobra.Command{ - Use: "prune [OPTIONS]", - Short: "Remove unused images", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - spaceReclaimed, output, err := runPrune(dockerCli, opts) - if err != nil { - return err - } - if output != "" { - fmt.Fprintln(dockerCli.Out(), output) - } - fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) - return nil - }, - Tags: map[string]string{"version": "1.25"}, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") - flags.BoolVarP(&opts.all, "all", "a", false, "Remove all unused images, not just dangling ones") - - return cmd -} - -const ( - allImageWarning = `WARNING! This will remove all images without at least one container associated to them. -Are you sure you want to continue?` - danglingWarning = `WARNING! This will remove all dangling images. -Are you sure you want to continue?` -) - -func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { - pruneFilters := filters.NewArgs() - pruneFilters.Add("dangling", fmt.Sprintf("%v", !opts.all)) - - warning := danglingWarning - if opts.all { - warning = allImageWarning - } - if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { - return - } - - report, err := dockerCli.Client().ImagesPrune(context.Background(), pruneFilters) - if err != nil { - return - } - - if len(report.ImagesDeleted) > 0 { - output = "Deleted Images:\n" - for _, st := range report.ImagesDeleted { - if st.Untagged != "" { - output += fmt.Sprintln("untagged:", st.Untagged) - } else { - output += fmt.Sprintln("deleted:", st.Deleted) - } - } - spaceReclaimed = report.SpaceReclaimed - } - - return -} - -// RunPrune calls the Image Prune API -// This returns the amount of space reclaimed and a detailed output string -func RunPrune(dockerCli *command.DockerCli, all bool) (uint64, string, error) { - return runPrune(dockerCli, pruneOptions{force: true, all: all}) -} diff --git a/vendor/github.com/docker/docker/cli/command/image/pull.go b/vendor/github.com/docker/docker/cli/command/image/pull.go deleted file mode 100644 index 24933fe..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/pull.go +++ /dev/null @@ -1,84 +0,0 @@ -package image - -import ( - "errors" - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "github.com/spf13/cobra" -) - -type pullOptions struct { - remote string - all bool -} - -// NewPullCommand creates a new `docker pull` command -func NewPullCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts pullOptions - - cmd := &cobra.Command{ - Use: "pull [OPTIONS] NAME[:TAG|@DIGEST]", - Short: "Pull an image or a repository from a registry", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.remote = args[0] - return runPull(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.BoolVarP(&opts.all, "all-tags", "a", false, "Download all tagged images in the repository") - command.AddTrustedFlags(flags, true) - - return cmd -} - -func runPull(dockerCli *command.DockerCli, opts pullOptions) error { - distributionRef, err := reference.ParseNamed(opts.remote) - if err != nil { - return err - } - if opts.all && !reference.IsNameOnly(distributionRef) { - return errors.New("tag can't be used with --all-tags/-a") - } - - if !opts.all && reference.IsNameOnly(distributionRef) { - distributionRef = reference.WithDefaultTag(distributionRef) - fmt.Fprintf(dockerCli.Out(), "Using default tag: %s\n", reference.DefaultTag) - } - - // Resolve the Repository name from fqn to RepositoryInfo - repoInfo, err := registry.ParseRepositoryInfo(distributionRef) - if err != nil { - return err - } - - ctx := context.Background() - - authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index) - requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, "pull") - - // Check if reference has a digest - _, isCanonical := distributionRef.(reference.Canonical) - if command.IsTrusted() && !isCanonical { - err = trustedPull(ctx, dockerCli, repoInfo, distributionRef, authConfig, requestPrivilege) - } else { - err = imagePullPrivileged(ctx, dockerCli, authConfig, distributionRef.String(), requestPrivilege, opts.all) - } - if err != nil { - if strings.Contains(err.Error(), "target is plugin") { - return errors.New(err.Error() + " - Use `docker plugin install`") - } - return err - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/image/push.go b/vendor/github.com/docker/docker/cli/command/image/push.go deleted file mode 100644 index a8ce494..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/push.go +++ /dev/null @@ -1,61 +0,0 @@ -package image - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "github.com/spf13/cobra" -) - -// NewPushCommand creates a new `docker push` command -func NewPushCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "push [OPTIONS] NAME[:TAG]", - Short: "Push an image or a repository to a registry", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runPush(dockerCli, args[0]) - }, - } - - flags := cmd.Flags() - - command.AddTrustedFlags(flags, true) - - return cmd -} - -func runPush(dockerCli *command.DockerCli, remote string) error { - ref, err := reference.ParseNamed(remote) - if err != nil { - return err - } - - // Resolve the Repository name from fqn to RepositoryInfo - repoInfo, err := registry.ParseRepositoryInfo(ref) - if err != nil { - return err - } - - ctx := context.Background() - - // Resolve the Auth config relevant for this server - authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index) - requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, "push") - - if command.IsTrusted() { - return trustedPush(ctx, dockerCli, repoInfo, ref, authConfig, requestPrivilege) - } - - responseBody, err := imagePushPrivileged(ctx, dockerCli, authConfig, ref.String(), requestPrivilege) - if err != nil { - return err - } - - defer responseBody.Close() - return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil) -} diff --git a/vendor/github.com/docker/docker/cli/command/image/remove.go b/vendor/github.com/docker/docker/cli/command/image/remove.go deleted file mode 100644 index c79ceba..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/remove.go +++ /dev/null @@ -1,77 +0,0 @@ -package image - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type removeOptions struct { - force bool - noPrune bool -} - -// NewRemoveCommand creates a new `docker remove` command -func NewRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts removeOptions - - cmd := &cobra.Command{ - Use: "rmi [OPTIONS] IMAGE [IMAGE...]", - Short: "Remove one or more images", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runRemove(dockerCli, opts, args) - }, - } - - flags := cmd.Flags() - - flags.BoolVarP(&opts.force, "force", "f", false, "Force removal of the image") - flags.BoolVar(&opts.noPrune, "no-prune", false, "Do not delete untagged parents") - - return cmd -} - -func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := *NewRemoveCommand(dockerCli) - cmd.Aliases = []string{"rmi", "remove"} - cmd.Use = "rm [OPTIONS] IMAGE [IMAGE...]" - return &cmd -} - -func runRemove(dockerCli *command.DockerCli, opts removeOptions, images []string) error { - client := dockerCli.Client() - ctx := context.Background() - - options := types.ImageRemoveOptions{ - Force: opts.force, - PruneChildren: !opts.noPrune, - } - - var errs []string - for _, image := range images { - dels, err := client.ImageRemove(ctx, image, options) - if err != nil { - errs = append(errs, err.Error()) - } else { - for _, del := range dels { - if del.Deleted != "" { - fmt.Fprintf(dockerCli.Out(), "Deleted: %s\n", del.Deleted) - } else { - fmt.Fprintf(dockerCli.Out(), "Untagged: %s\n", del.Untagged) - } - } - } - } - - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/image/save.go b/vendor/github.com/docker/docker/cli/command/image/save.go deleted file mode 100644 index bbe82d2..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/save.go +++ /dev/null @@ -1,57 +0,0 @@ -package image - -import ( - "errors" - "io" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type saveOptions struct { - images []string - output string -} - -// NewSaveCommand creates a new `docker save` command -func NewSaveCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts saveOptions - - cmd := &cobra.Command{ - Use: "save [OPTIONS] IMAGE [IMAGE...]", - Short: "Save one or more images to a tar archive (streamed to STDOUT by default)", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.images = args - return runSave(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.StringVarP(&opts.output, "output", "o", "", "Write to a file, instead of STDOUT") - - return cmd -} - -func runSave(dockerCli *command.DockerCli, opts saveOptions) error { - if opts.output == "" && dockerCli.Out().IsTerminal() { - return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.") - } - - responseBody, err := dockerCli.Client().ImageSave(context.Background(), opts.images) - if err != nil { - return err - } - defer responseBody.Close() - - if opts.output == "" { - _, err := io.Copy(dockerCli.Out(), responseBody) - return err - } - - return command.CopyToFile(opts.output, responseBody) -} diff --git a/vendor/github.com/docker/docker/cli/command/image/tag.go b/vendor/github.com/docker/docker/cli/command/image/tag.go deleted file mode 100644 index fb2b703..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/tag.go +++ /dev/null @@ -1,41 +0,0 @@ -package image - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type tagOptions struct { - image string - name string -} - -// NewTagCommand creates a new `docker tag` command -func NewTagCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts tagOptions - - cmd := &cobra.Command{ - Use: "tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]", - Short: "Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - opts.image = args[0] - opts.name = args[1] - return runTag(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.SetInterspersed(false) - - return cmd -} - -func runTag(dockerCli *command.DockerCli, opts tagOptions) error { - ctx := context.Background() - - return dockerCli.Client().ImageTag(ctx, opts.image, opts.name) -} diff --git a/vendor/github.com/docker/docker/cli/command/image/trust.go b/vendor/github.com/docker/docker/cli/command/image/trust.go deleted file mode 100644 index 5136a22..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/trust.go +++ /dev/null @@ -1,381 +0,0 @@ -package image - -import ( - "encoding/hex" - "encoding/json" - "errors" - "fmt" - "io" - "path" - "sort" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/trust" - "github.com/docker/docker/distribution" - "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "github.com/docker/notary/client" - "github.com/docker/notary/tuf/data" -) - -type target struct { - name string - digest digest.Digest - size int64 -} - -// trustedPush handles content trust pushing of an image -func trustedPush(ctx context.Context, cli *command.DockerCli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error { - responseBody, err := imagePushPrivileged(ctx, cli, authConfig, ref.String(), requestPrivilege) - if err != nil { - return err - } - - defer responseBody.Close() - - return PushTrustedReference(cli, repoInfo, ref, authConfig, responseBody) -} - -// PushTrustedReference pushes a canonical reference to the trust server. -func PushTrustedReference(cli *command.DockerCli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, in io.Reader) error { - // If it is a trusted push we would like to find the target entry which match the - // tag provided in the function and then do an AddTarget later. - target := &client.Target{} - // Count the times of calling for handleTarget, - // if it is called more that once, that should be considered an error in a trusted push. - cnt := 0 - handleTarget := func(aux *json.RawMessage) { - cnt++ - if cnt > 1 { - // handleTarget should only be called one. This will be treated as an error. - return - } - - var pushResult distribution.PushResult - err := json.Unmarshal(*aux, &pushResult) - if err == nil && pushResult.Tag != "" && pushResult.Digest.Validate() == nil { - h, err := hex.DecodeString(pushResult.Digest.Hex()) - if err != nil { - target = nil - return - } - target.Name = pushResult.Tag - target.Hashes = data.Hashes{string(pushResult.Digest.Algorithm()): h} - target.Length = int64(pushResult.Size) - } - } - - var tag string - switch x := ref.(type) { - case reference.Canonical: - return errors.New("cannot push a digest reference") - case reference.NamedTagged: - tag = x.Tag() - default: - // We want trust signatures to always take an explicit tag, - // otherwise it will act as an untrusted push. - if err := jsonmessage.DisplayJSONMessagesToStream(in, cli.Out(), nil); err != nil { - return err - } - fmt.Fprintln(cli.Out(), "No tag specified, skipping trust metadata push") - return nil - } - - if err := jsonmessage.DisplayJSONMessagesToStream(in, cli.Out(), handleTarget); err != nil { - return err - } - - if cnt > 1 { - return fmt.Errorf("internal error: only one call to handleTarget expected") - } - - if target == nil { - fmt.Fprintln(cli.Out(), "No targets found, please provide a specific tag in order to sign it") - return nil - } - - fmt.Fprintln(cli.Out(), "Signing and pushing trust metadata") - - repo, err := trust.GetNotaryRepository(cli, repoInfo, authConfig, "push", "pull") - if err != nil { - fmt.Fprintf(cli.Out(), "Error establishing connection to notary repository: %s\n", err) - return err - } - - // get the latest repository metadata so we can figure out which roles to sign - err = repo.Update(false) - - switch err.(type) { - case client.ErrRepoNotInitialized, client.ErrRepositoryNotExist: - keys := repo.CryptoService.ListKeys(data.CanonicalRootRole) - var rootKeyID string - // always select the first root key - if len(keys) > 0 { - sort.Strings(keys) - rootKeyID = keys[0] - } else { - rootPublicKey, err := repo.CryptoService.Create(data.CanonicalRootRole, "", data.ECDSAKey) - if err != nil { - return err - } - rootKeyID = rootPublicKey.ID() - } - - // Initialize the notary repository with a remotely managed snapshot key - if err := repo.Initialize([]string{rootKeyID}, data.CanonicalSnapshotRole); err != nil { - return trust.NotaryError(repoInfo.FullName(), err) - } - fmt.Fprintf(cli.Out(), "Finished initializing %q\n", repoInfo.FullName()) - err = repo.AddTarget(target, data.CanonicalTargetsRole) - case nil: - // already initialized and we have successfully downloaded the latest metadata - err = addTargetToAllSignableRoles(repo, target) - default: - return trust.NotaryError(repoInfo.FullName(), err) - } - - if err == nil { - err = repo.Publish() - } - - if err != nil { - fmt.Fprintf(cli.Out(), "Failed to sign %q:%s - %s\n", repoInfo.FullName(), tag, err.Error()) - return trust.NotaryError(repoInfo.FullName(), err) - } - - fmt.Fprintf(cli.Out(), "Successfully signed %q:%s\n", repoInfo.FullName(), tag) - return nil -} - -// Attempt to add the image target to all the top level delegation roles we can -// (based on whether we have the signing key and whether the role's path allows -// us to). -// If there are no delegation roles, we add to the targets role. -func addTargetToAllSignableRoles(repo *client.NotaryRepository, target *client.Target) error { - var signableRoles []string - - // translate the full key names, which includes the GUN, into just the key IDs - allCanonicalKeyIDs := make(map[string]struct{}) - for fullKeyID := range repo.CryptoService.ListAllKeys() { - allCanonicalKeyIDs[path.Base(fullKeyID)] = struct{}{} - } - - allDelegationRoles, err := repo.GetDelegationRoles() - if err != nil { - return err - } - - // if there are no delegation roles, then just try to sign it into the targets role - if len(allDelegationRoles) == 0 { - return repo.AddTarget(target, data.CanonicalTargetsRole) - } - - // there are delegation roles, find every delegation role we have a key for, and - // attempt to sign into into all those roles. - for _, delegationRole := range allDelegationRoles { - // We do not support signing any delegation role that isn't a direct child of the targets role. - // Also don't bother checking the keys if we can't add the target - // to this role due to path restrictions - if path.Dir(delegationRole.Name) != data.CanonicalTargetsRole || !delegationRole.CheckPaths(target.Name) { - continue - } - - for _, canonicalKeyID := range delegationRole.KeyIDs { - if _, ok := allCanonicalKeyIDs[canonicalKeyID]; ok { - signableRoles = append(signableRoles, delegationRole.Name) - break - } - } - } - - if len(signableRoles) == 0 { - return fmt.Errorf("no valid signing keys for delegation roles") - } - - return repo.AddTarget(target, signableRoles...) -} - -// imagePushPrivileged push the image -func imagePushPrivileged(ctx context.Context, cli *command.DockerCli, authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc) (io.ReadCloser, error) { - encodedAuth, err := command.EncodeAuthToBase64(authConfig) - if err != nil { - return nil, err - } - options := types.ImagePushOptions{ - RegistryAuth: encodedAuth, - PrivilegeFunc: requestPrivilege, - } - - return cli.Client().ImagePush(ctx, ref, options) -} - -// trustedPull handles content trust pulling of an image -func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error { - var refs []target - - notaryRepo, err := trust.GetNotaryRepository(cli, repoInfo, authConfig, "pull") - if err != nil { - fmt.Fprintf(cli.Out(), "Error establishing connection to trust repository: %s\n", err) - return err - } - - if tagged, isTagged := ref.(reference.NamedTagged); !isTagged { - // List all targets - targets, err := notaryRepo.ListTargets(trust.ReleasesRole, data.CanonicalTargetsRole) - if err != nil { - return trust.NotaryError(repoInfo.FullName(), err) - } - for _, tgt := range targets { - t, err := convertTarget(tgt.Target) - if err != nil { - fmt.Fprintf(cli.Out(), "Skipping target for %q\n", repoInfo.Name()) - continue - } - // Only list tags in the top level targets role or the releases delegation role - ignore - // all other delegation roles - if tgt.Role != trust.ReleasesRole && tgt.Role != data.CanonicalTargetsRole { - continue - } - refs = append(refs, t) - } - if len(refs) == 0 { - return trust.NotaryError(repoInfo.FullName(), fmt.Errorf("No trusted tags for %s", repoInfo.FullName())) - } - } else { - t, err := notaryRepo.GetTargetByName(tagged.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole) - if err != nil { - return trust.NotaryError(repoInfo.FullName(), err) - } - // Only get the tag if it's in the top level targets role or the releases delegation role - // ignore it if it's in any other delegation roles - if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole { - return trust.NotaryError(repoInfo.FullName(), fmt.Errorf("No trust data for %s", tagged.Tag())) - } - - logrus.Debugf("retrieving target for %s role\n", t.Role) - r, err := convertTarget(t.Target) - if err != nil { - return err - - } - refs = append(refs, r) - } - - for i, r := range refs { - displayTag := r.name - if displayTag != "" { - displayTag = ":" + displayTag - } - fmt.Fprintf(cli.Out(), "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), repoInfo.Name(), displayTag, r.digest) - - ref, err := reference.WithDigest(reference.TrimNamed(repoInfo), r.digest) - if err != nil { - return err - } - if err := imagePullPrivileged(ctx, cli, authConfig, ref.String(), requestPrivilege, false); err != nil { - return err - } - - tagged, err := reference.WithTag(repoInfo, r.name) - if err != nil { - return err - } - trustedRef, err := reference.WithDigest(reference.TrimNamed(repoInfo), r.digest) - if err != nil { - return err - } - if err := TagTrusted(ctx, cli, trustedRef, tagged); err != nil { - return err - } - } - return nil -} - -// imagePullPrivileged pulls the image and displays it to the output -func imagePullPrivileged(ctx context.Context, cli *command.DockerCli, authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc, all bool) error { - - encodedAuth, err := command.EncodeAuthToBase64(authConfig) - if err != nil { - return err - } - options := types.ImagePullOptions{ - RegistryAuth: encodedAuth, - PrivilegeFunc: requestPrivilege, - All: all, - } - - responseBody, err := cli.Client().ImagePull(ctx, ref, options) - if err != nil { - return err - } - defer responseBody.Close() - - return jsonmessage.DisplayJSONMessagesToStream(responseBody, cli.Out(), nil) -} - -// TrustedReference returns the canonical trusted reference for an image reference -func TrustedReference(ctx context.Context, cli *command.DockerCli, ref reference.NamedTagged, rs registry.Service) (reference.Canonical, error) { - var ( - repoInfo *registry.RepositoryInfo - err error - ) - if rs != nil { - repoInfo, err = rs.ResolveRepository(ref) - } else { - repoInfo, err = registry.ParseRepositoryInfo(ref) - } - if err != nil { - return nil, err - } - - // Resolve the Auth config relevant for this server - authConfig := command.ResolveAuthConfig(ctx, cli, repoInfo.Index) - - notaryRepo, err := trust.GetNotaryRepository(cli, repoInfo, authConfig, "pull") - if err != nil { - fmt.Fprintf(cli.Out(), "Error establishing connection to trust repository: %s\n", err) - return nil, err - } - - t, err := notaryRepo.GetTargetByName(ref.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole) - if err != nil { - return nil, trust.NotaryError(repoInfo.FullName(), err) - } - // Only list tags in the top level targets role or the releases delegation role - ignore - // all other delegation roles - if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole { - return nil, trust.NotaryError(repoInfo.FullName(), fmt.Errorf("No trust data for %s", ref.Tag())) - } - r, err := convertTarget(t.Target) - if err != nil { - return nil, err - - } - - return reference.WithDigest(reference.TrimNamed(ref), r.digest) -} - -func convertTarget(t client.Target) (target, error) { - h, ok := t.Hashes["sha256"] - if !ok { - return target{}, errors.New("no valid hash, expecting sha256") - } - return target{ - name: t.Name, - digest: digest.NewDigestFromHex("sha256", hex.EncodeToString(h)), - size: t.Length, - }, nil -} - -// TagTrusted tags a trusted ref -func TagTrusted(ctx context.Context, cli *command.DockerCli, trustedRef reference.Canonical, ref reference.NamedTagged) error { - fmt.Fprintf(cli.Out(), "Tagging %s as %s\n", trustedRef.String(), ref.String()) - - return cli.Client().ImageTag(ctx, trustedRef.String(), ref.String()) -} diff --git a/vendor/github.com/docker/docker/cli/command/image/trust_test.go b/vendor/github.com/docker/docker/cli/command/image/trust_test.go deleted file mode 100644 index 7814646..0000000 --- a/vendor/github.com/docker/docker/cli/command/image/trust_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package image - -import ( - "os" - "testing" - - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/cli/trust" - "github.com/docker/docker/registry" -) - -func unsetENV() { - os.Unsetenv("DOCKER_CONTENT_TRUST") - os.Unsetenv("DOCKER_CONTENT_TRUST_SERVER") -} - -func TestENVTrustServer(t *testing.T) { - defer unsetENV() - indexInfo := ®istrytypes.IndexInfo{Name: "testserver"} - if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "https://notary-test.com:5000"); err != nil { - t.Fatal("Failed to set ENV variable") - } - output, err := trust.Server(indexInfo) - expectedStr := "https://notary-test.com:5000" - if err != nil || output != expectedStr { - t.Fatalf("Expected server to be %s, got %s", expectedStr, output) - } -} - -func TestHTTPENVTrustServer(t *testing.T) { - defer unsetENV() - indexInfo := ®istrytypes.IndexInfo{Name: "testserver"} - if err := os.Setenv("DOCKER_CONTENT_TRUST_SERVER", "http://notary-test.com:5000"); err != nil { - t.Fatal("Failed to set ENV variable") - } - _, err := trust.Server(indexInfo) - if err == nil { - t.Fatal("Expected error with invalid scheme") - } -} - -func TestOfficialTrustServer(t *testing.T) { - indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: true} - output, err := trust.Server(indexInfo) - if err != nil || output != registry.NotaryServer { - t.Fatalf("Expected server to be %s, got %s", registry.NotaryServer, output) - } -} - -func TestNonOfficialTrustServer(t *testing.T) { - indexInfo := ®istrytypes.IndexInfo{Name: "testserver", Official: false} - output, err := trust.Server(indexInfo) - expectedStr := "https://" + indexInfo.Name - if err != nil || output != expectedStr { - t.Fatalf("Expected server to be %s, got %s", expectedStr, output) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/in.go b/vendor/github.com/docker/docker/cli/command/in.go deleted file mode 100644 index 7204b7a..0000000 --- a/vendor/github.com/docker/docker/cli/command/in.go +++ /dev/null @@ -1,75 +0,0 @@ -package command - -import ( - "errors" - "io" - "os" - "runtime" - - "github.com/docker/docker/pkg/term" -) - -// InStream is an input stream used by the DockerCli to read user input -type InStream struct { - in io.ReadCloser - fd uintptr - isTerminal bool - state *term.State -} - -func (i *InStream) Read(p []byte) (int, error) { - return i.in.Read(p) -} - -// Close implements the Closer interface -func (i *InStream) Close() error { - return i.in.Close() -} - -// FD returns the file descriptor number for this stream -func (i *InStream) FD() uintptr { - return i.fd -} - -// IsTerminal returns true if this stream is connected to a terminal -func (i *InStream) IsTerminal() bool { - return i.isTerminal -} - -// SetRawTerminal sets raw mode on the input terminal -func (i *InStream) SetRawTerminal() (err error) { - if os.Getenv("NORAW") != "" || !i.isTerminal { - return nil - } - i.state, err = term.SetRawTerminal(i.fd) - return err -} - -// RestoreTerminal restores normal mode to the terminal -func (i *InStream) RestoreTerminal() { - if i.state != nil { - term.RestoreTerminal(i.fd, i.state) - } -} - -// CheckTty checks if we are trying to attach to a container tty -// from a non-tty client input stream, and if so, returns an error. -func (i *InStream) CheckTty(attachStdin, ttyMode bool) error { - // In order to attach to a container tty, input stream for the client must - // be a tty itself: redirecting or piping the client standard input is - // incompatible with `docker run -t`, `docker exec -t` or `docker attach`. - if ttyMode && attachStdin && !i.isTerminal { - eText := "the input device is not a TTY" - if runtime.GOOS == "windows" { - return errors.New(eText + ". If you are using mintty, try prefixing the command with 'winpty'") - } - return errors.New(eText) - } - return nil -} - -// NewInStream returns a new InStream object from a ReadCloser -func NewInStream(in io.ReadCloser) *InStream { - fd, isTerminal := term.GetFdInfo(in) - return &InStream{in: in, fd: fd, isTerminal: isTerminal} -} diff --git a/vendor/github.com/docker/docker/cli/command/inspect/inspector.go b/vendor/github.com/docker/docker/cli/command/inspect/inspector.go deleted file mode 100644 index 1d81643..0000000 --- a/vendor/github.com/docker/docker/cli/command/inspect/inspector.go +++ /dev/null @@ -1,195 +0,0 @@ -package inspect - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "text/template" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/cli" - "github.com/docker/docker/utils/templates" -) - -// Inspector defines an interface to implement to process elements -type Inspector interface { - Inspect(typedElement interface{}, rawElement []byte) error - Flush() error -} - -// TemplateInspector uses a text template to inspect elements. -type TemplateInspector struct { - outputStream io.Writer - buffer *bytes.Buffer - tmpl *template.Template -} - -// NewTemplateInspector creates a new inspector with a template. -func NewTemplateInspector(outputStream io.Writer, tmpl *template.Template) Inspector { - return &TemplateInspector{ - outputStream: outputStream, - buffer: new(bytes.Buffer), - tmpl: tmpl, - } -} - -// NewTemplateInspectorFromString creates a new TemplateInspector from a string -// which is compiled into a template. -func NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, error) { - if tmplStr == "" { - return NewIndentedInspector(out), nil - } - - tmpl, err := templates.Parse(tmplStr) - if err != nil { - return nil, fmt.Errorf("Template parsing error: %s", err) - } - return NewTemplateInspector(out, tmpl), nil -} - -// GetRefFunc is a function which used by Inspect to fetch an object from a -// reference -type GetRefFunc func(ref string) (interface{}, []byte, error) - -// Inspect fetches objects by reference using GetRefFunc and writes the json -// representation to the output writer. -func Inspect(out io.Writer, references []string, tmplStr string, getRef GetRefFunc) error { - inspector, err := NewTemplateInspectorFromString(out, tmplStr) - if err != nil { - return cli.StatusError{StatusCode: 64, Status: err.Error()} - } - - var inspectErr error - for _, ref := range references { - element, raw, err := getRef(ref) - if err != nil { - inspectErr = err - break - } - - if err := inspector.Inspect(element, raw); err != nil { - inspectErr = err - break - } - } - - if err := inspector.Flush(); err != nil { - logrus.Errorf("%s\n", err) - } - - if inspectErr != nil { - return cli.StatusError{StatusCode: 1, Status: inspectErr.Error()} - } - return nil -} - -// Inspect executes the inspect template. -// It decodes the raw element into a map if the initial execution fails. -// This allows docker cli to parse inspect structs injected with Swarm fields. -func (i *TemplateInspector) Inspect(typedElement interface{}, rawElement []byte) error { - buffer := new(bytes.Buffer) - if err := i.tmpl.Execute(buffer, typedElement); err != nil { - if rawElement == nil { - return fmt.Errorf("Template parsing error: %v", err) - } - return i.tryRawInspectFallback(rawElement) - } - i.buffer.Write(buffer.Bytes()) - i.buffer.WriteByte('\n') - return nil -} - -// tryRawInspectFallback executes the inspect template with a raw interface. -// This allows docker cli to parse inspect structs injected with Swarm fields. -func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte) error { - var raw interface{} - buffer := new(bytes.Buffer) - rdr := bytes.NewReader(rawElement) - dec := json.NewDecoder(rdr) - - if rawErr := dec.Decode(&raw); rawErr != nil { - return fmt.Errorf("unable to read inspect data: %v", rawErr) - } - - tmplMissingKey := i.tmpl.Option("missingkey=error") - if rawErr := tmplMissingKey.Execute(buffer, raw); rawErr != nil { - return fmt.Errorf("Template parsing error: %v", rawErr) - } - - i.buffer.Write(buffer.Bytes()) - i.buffer.WriteByte('\n') - return nil -} - -// Flush writes the result of inspecting all elements into the output stream. -func (i *TemplateInspector) Flush() error { - if i.buffer.Len() == 0 { - _, err := io.WriteString(i.outputStream, "\n") - return err - } - _, err := io.Copy(i.outputStream, i.buffer) - return err -} - -// IndentedInspector uses a buffer to stop the indented representation of an element. -type IndentedInspector struct { - outputStream io.Writer - elements []interface{} - rawElements [][]byte -} - -// NewIndentedInspector generates a new IndentedInspector. -func NewIndentedInspector(outputStream io.Writer) Inspector { - return &IndentedInspector{ - outputStream: outputStream, - } -} - -// Inspect writes the raw element with an indented json format. -func (i *IndentedInspector) Inspect(typedElement interface{}, rawElement []byte) error { - if rawElement != nil { - i.rawElements = append(i.rawElements, rawElement) - } else { - i.elements = append(i.elements, typedElement) - } - return nil -} - -// Flush writes the result of inspecting all elements into the output stream. -func (i *IndentedInspector) Flush() error { - if len(i.elements) == 0 && len(i.rawElements) == 0 { - _, err := io.WriteString(i.outputStream, "[]\n") - return err - } - - var buffer io.Reader - if len(i.rawElements) > 0 { - bytesBuffer := new(bytes.Buffer) - bytesBuffer.WriteString("[") - for idx, r := range i.rawElements { - bytesBuffer.Write(r) - if idx < len(i.rawElements)-1 { - bytesBuffer.WriteString(",") - } - } - bytesBuffer.WriteString("]") - indented := new(bytes.Buffer) - if err := json.Indent(indented, bytesBuffer.Bytes(), "", " "); err != nil { - return err - } - buffer = indented - } else { - b, err := json.MarshalIndent(i.elements, "", " ") - if err != nil { - return err - } - buffer = bytes.NewReader(b) - } - - if _, err := io.Copy(i.outputStream, buffer); err != nil { - return err - } - _, err := io.WriteString(i.outputStream, "\n") - return err -} diff --git a/vendor/github.com/docker/docker/cli/command/inspect/inspector_test.go b/vendor/github.com/docker/docker/cli/command/inspect/inspector_test.go deleted file mode 100644 index 1ce1593..0000000 --- a/vendor/github.com/docker/docker/cli/command/inspect/inspector_test.go +++ /dev/null @@ -1,221 +0,0 @@ -package inspect - -import ( - "bytes" - "strings" - "testing" - - "github.com/docker/docker/utils/templates" -) - -type testElement struct { - DNS string `json:"Dns"` -} - -func TestTemplateInspectorDefault(t *testing.T) { - b := new(bytes.Buffer) - tmpl, err := templates.Parse("{{.DNS}}") - if err != nil { - t.Fatal(err) - } - i := NewTemplateInspector(b, tmpl) - if err := i.Inspect(testElement{"0.0.0.0"}, nil); err != nil { - t.Fatal(err) - } - - if err := i.Flush(); err != nil { - t.Fatal(err) - } - if b.String() != "0.0.0.0\n" { - t.Fatalf("Expected `0.0.0.0\\n`, got `%s`", b.String()) - } -} - -func TestTemplateInspectorEmpty(t *testing.T) { - b := new(bytes.Buffer) - tmpl, err := templates.Parse("{{.DNS}}") - if err != nil { - t.Fatal(err) - } - i := NewTemplateInspector(b, tmpl) - - if err := i.Flush(); err != nil { - t.Fatal(err) - } - if b.String() != "\n" { - t.Fatalf("Expected `\\n`, got `%s`", b.String()) - } -} - -func TestTemplateInspectorTemplateError(t *testing.T) { - b := new(bytes.Buffer) - tmpl, err := templates.Parse("{{.Foo}}") - if err != nil { - t.Fatal(err) - } - i := NewTemplateInspector(b, tmpl) - - err = i.Inspect(testElement{"0.0.0.0"}, nil) - if err == nil { - t.Fatal("Expected error got nil") - } - - if !strings.HasPrefix(err.Error(), "Template parsing error") { - t.Fatalf("Expected template error, got %v", err) - } -} - -func TestTemplateInspectorRawFallback(t *testing.T) { - b := new(bytes.Buffer) - tmpl, err := templates.Parse("{{.Dns}}") - if err != nil { - t.Fatal(err) - } - i := NewTemplateInspector(b, tmpl) - if err := i.Inspect(testElement{"0.0.0.0"}, []byte(`{"Dns": "0.0.0.0"}`)); err != nil { - t.Fatal(err) - } - - if err := i.Flush(); err != nil { - t.Fatal(err) - } - if b.String() != "0.0.0.0\n" { - t.Fatalf("Expected `0.0.0.0\\n`, got `%s`", b.String()) - } -} - -func TestTemplateInspectorRawFallbackError(t *testing.T) { - b := new(bytes.Buffer) - tmpl, err := templates.Parse("{{.Dns}}") - if err != nil { - t.Fatal(err) - } - i := NewTemplateInspector(b, tmpl) - err = i.Inspect(testElement{"0.0.0.0"}, []byte(`{"Foo": "0.0.0.0"}`)) - if err == nil { - t.Fatal("Expected error got nil") - } - - if !strings.HasPrefix(err.Error(), "Template parsing error") { - t.Fatalf("Expected template error, got %v", err) - } -} - -func TestTemplateInspectorMultiple(t *testing.T) { - b := new(bytes.Buffer) - tmpl, err := templates.Parse("{{.DNS}}") - if err != nil { - t.Fatal(err) - } - i := NewTemplateInspector(b, tmpl) - - if err := i.Inspect(testElement{"0.0.0.0"}, nil); err != nil { - t.Fatal(err) - } - if err := i.Inspect(testElement{"1.1.1.1"}, nil); err != nil { - t.Fatal(err) - } - - if err := i.Flush(); err != nil { - t.Fatal(err) - } - if b.String() != "0.0.0.0\n1.1.1.1\n" { - t.Fatalf("Expected `0.0.0.0\\n1.1.1.1\\n`, got `%s`", b.String()) - } -} - -func TestIndentedInspectorDefault(t *testing.T) { - b := new(bytes.Buffer) - i := NewIndentedInspector(b) - if err := i.Inspect(testElement{"0.0.0.0"}, nil); err != nil { - t.Fatal(err) - } - - if err := i.Flush(); err != nil { - t.Fatal(err) - } - - expected := `[ - { - "Dns": "0.0.0.0" - } -] -` - if b.String() != expected { - t.Fatalf("Expected `%s`, got `%s`", expected, b.String()) - } -} - -func TestIndentedInspectorMultiple(t *testing.T) { - b := new(bytes.Buffer) - i := NewIndentedInspector(b) - if err := i.Inspect(testElement{"0.0.0.0"}, nil); err != nil { - t.Fatal(err) - } - - if err := i.Inspect(testElement{"1.1.1.1"}, nil); err != nil { - t.Fatal(err) - } - - if err := i.Flush(); err != nil { - t.Fatal(err) - } - - expected := `[ - { - "Dns": "0.0.0.0" - }, - { - "Dns": "1.1.1.1" - } -] -` - if b.String() != expected { - t.Fatalf("Expected `%s`, got `%s`", expected, b.String()) - } -} - -func TestIndentedInspectorEmpty(t *testing.T) { - b := new(bytes.Buffer) - i := NewIndentedInspector(b) - - if err := i.Flush(); err != nil { - t.Fatal(err) - } - - expected := "[]\n" - if b.String() != expected { - t.Fatalf("Expected `%s`, got `%s`", expected, b.String()) - } -} - -func TestIndentedInspectorRawElements(t *testing.T) { - b := new(bytes.Buffer) - i := NewIndentedInspector(b) - if err := i.Inspect(testElement{"0.0.0.0"}, []byte(`{"Dns": "0.0.0.0", "Node": "0"}`)); err != nil { - t.Fatal(err) - } - - if err := i.Inspect(testElement{"1.1.1.1"}, []byte(`{"Dns": "1.1.1.1", "Node": "1"}`)); err != nil { - t.Fatal(err) - } - - if err := i.Flush(); err != nil { - t.Fatal(err) - } - - expected := `[ - { - "Dns": "0.0.0.0", - "Node": "0" - }, - { - "Dns": "1.1.1.1", - "Node": "1" - } -] -` - if b.String() != expected { - t.Fatalf("Expected `%s`, got `%s`", expected, b.String()) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/network/cmd.go b/vendor/github.com/docker/docker/cli/command/network/cmd.go deleted file mode 100644 index ab8393c..0000000 --- a/vendor/github.com/docker/docker/cli/command/network/cmd.go +++ /dev/null @@ -1,28 +0,0 @@ -package network - -import ( - "github.com/spf13/cobra" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" -) - -// NewNetworkCommand returns a cobra command for `network` subcommands -func NewNetworkCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "network", - Short: "Manage networks", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - } - cmd.AddCommand( - newConnectCommand(dockerCli), - newCreateCommand(dockerCli), - newDisconnectCommand(dockerCli), - newInspectCommand(dockerCli), - newListCommand(dockerCli), - newRemoveCommand(dockerCli), - NewPruneCommand(dockerCli), - ) - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/network/connect.go b/vendor/github.com/docker/docker/cli/command/network/connect.go deleted file mode 100644 index c4b676e..0000000 --- a/vendor/github.com/docker/docker/cli/command/network/connect.go +++ /dev/null @@ -1,64 +0,0 @@ -package network - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/network" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/opts" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/spf13/cobra" -) - -type connectOptions struct { - network string - container string - ipaddress string - ipv6address string - links opts.ListOpts - aliases []string - linklocalips []string -} - -func newConnectCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := connectOptions{ - links: opts.NewListOpts(runconfigopts.ValidateLink), - } - - cmd := &cobra.Command{ - Use: "connect [OPTIONS] NETWORK CONTAINER", - Short: "Connect a container to a network", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - opts.network = args[0] - opts.container = args[1] - return runConnect(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.StringVar(&opts.ipaddress, "ip", "", "IP Address") - flags.StringVar(&opts.ipv6address, "ip6", "", "IPv6 Address") - flags.Var(&opts.links, "link", "Add link to another container") - flags.StringSliceVar(&opts.aliases, "alias", []string{}, "Add network-scoped alias for the container") - flags.StringSliceVar(&opts.linklocalips, "link-local-ip", []string{}, "Add a link-local address for the container") - - return cmd -} - -func runConnect(dockerCli *command.DockerCli, opts connectOptions) error { - client := dockerCli.Client() - - epConfig := &network.EndpointSettings{ - IPAMConfig: &network.EndpointIPAMConfig{ - IPv4Address: opts.ipaddress, - IPv6Address: opts.ipv6address, - LinkLocalIPs: opts.linklocalips, - }, - Links: opts.links.GetAll(), - Aliases: opts.aliases, - } - - return client.NetworkConnect(context.Background(), opts.network, opts.container, epConfig) -} diff --git a/vendor/github.com/docker/docker/cli/command/network/create.go b/vendor/github.com/docker/docker/cli/command/network/create.go deleted file mode 100644 index abc494e..0000000 --- a/vendor/github.com/docker/docker/cli/command/network/create.go +++ /dev/null @@ -1,226 +0,0 @@ -package network - -import ( - "fmt" - "net" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/network" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/opts" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/spf13/cobra" -) - -type createOptions struct { - name string - driver string - driverOpts opts.MapOpts - labels opts.ListOpts - internal bool - ipv6 bool - attachable bool - - ipamDriver string - ipamSubnet []string - ipamIPRange []string - ipamGateway []string - ipamAux opts.MapOpts - ipamOpt opts.MapOpts -} - -func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := createOptions{ - driverOpts: *opts.NewMapOpts(nil, nil), - labels: opts.NewListOpts(runconfigopts.ValidateEnv), - ipamAux: *opts.NewMapOpts(nil, nil), - ipamOpt: *opts.NewMapOpts(nil, nil), - } - - cmd := &cobra.Command{ - Use: "create [OPTIONS] NETWORK", - Short: "Create a network", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.name = args[0] - return runCreate(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.driver, "driver", "d", "bridge", "Driver to manage the Network") - flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options") - flags.Var(&opts.labels, "label", "Set metadata on a network") - flags.BoolVar(&opts.internal, "internal", false, "Restrict external access to the network") - flags.BoolVar(&opts.ipv6, "ipv6", false, "Enable IPv6 networking") - flags.BoolVar(&opts.attachable, "attachable", false, "Enable manual container attachment") - - flags.StringVar(&opts.ipamDriver, "ipam-driver", "default", "IP Address Management Driver") - flags.StringSliceVar(&opts.ipamSubnet, "subnet", []string{}, "Subnet in CIDR format that represents a network segment") - flags.StringSliceVar(&opts.ipamIPRange, "ip-range", []string{}, "Allocate container ip from a sub-range") - flags.StringSliceVar(&opts.ipamGateway, "gateway", []string{}, "IPv4 or IPv6 Gateway for the master subnet") - - flags.Var(&opts.ipamAux, "aux-address", "Auxiliary IPv4 or IPv6 addresses used by Network driver") - flags.Var(&opts.ipamOpt, "ipam-opt", "Set IPAM driver specific options") - - return cmd -} - -func runCreate(dockerCli *command.DockerCli, opts createOptions) error { - client := dockerCli.Client() - - ipamCfg, err := consolidateIpam(opts.ipamSubnet, opts.ipamIPRange, opts.ipamGateway, opts.ipamAux.GetAll()) - if err != nil { - return err - } - - // Construct network create request body - nc := types.NetworkCreate{ - Driver: opts.driver, - Options: opts.driverOpts.GetAll(), - IPAM: &network.IPAM{ - Driver: opts.ipamDriver, - Config: ipamCfg, - Options: opts.ipamOpt.GetAll(), - }, - CheckDuplicate: true, - Internal: opts.internal, - EnableIPv6: opts.ipv6, - Attachable: opts.attachable, - Labels: runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()), - } - - resp, err := client.NetworkCreate(context.Background(), opts.name, nc) - if err != nil { - return err - } - fmt.Fprintf(dockerCli.Out(), "%s\n", resp.ID) - return nil -} - -// Consolidates the ipam configuration as a group from different related configurations -// user can configure network with multiple non-overlapping subnets and hence it is -// possible to correlate the various related parameters and consolidate them. -// consoidateIpam consolidates subnets, ip-ranges, gateways and auxiliary addresses into -// structured ipam data. -func consolidateIpam(subnets, ranges, gateways []string, auxaddrs map[string]string) ([]network.IPAMConfig, error) { - if len(subnets) < len(ranges) || len(subnets) < len(gateways) { - return nil, fmt.Errorf("every ip-range or gateway must have a corresponding subnet") - } - iData := map[string]*network.IPAMConfig{} - - // Populate non-overlapping subnets into consolidation map - for _, s := range subnets { - for k := range iData { - ok1, err := subnetMatches(s, k) - if err != nil { - return nil, err - } - ok2, err := subnetMatches(k, s) - if err != nil { - return nil, err - } - if ok1 || ok2 { - return nil, fmt.Errorf("multiple overlapping subnet configuration is not supported") - } - } - iData[s] = &network.IPAMConfig{Subnet: s, AuxAddress: map[string]string{}} - } - - // Validate and add valid ip ranges - for _, r := range ranges { - match := false - for _, s := range subnets { - ok, err := subnetMatches(s, r) - if err != nil { - return nil, err - } - if !ok { - continue - } - if iData[s].IPRange != "" { - return nil, fmt.Errorf("cannot configure multiple ranges (%s, %s) on the same subnet (%s)", r, iData[s].IPRange, s) - } - d := iData[s] - d.IPRange = r - match = true - } - if !match { - return nil, fmt.Errorf("no matching subnet for range %s", r) - } - } - - // Validate and add valid gateways - for _, g := range gateways { - match := false - for _, s := range subnets { - ok, err := subnetMatches(s, g) - if err != nil { - return nil, err - } - if !ok { - continue - } - if iData[s].Gateway != "" { - return nil, fmt.Errorf("cannot configure multiple gateways (%s, %s) for the same subnet (%s)", g, iData[s].Gateway, s) - } - d := iData[s] - d.Gateway = g - match = true - } - if !match { - return nil, fmt.Errorf("no matching subnet for gateway %s", g) - } - } - - // Validate and add aux-addresses - for key, aa := range auxaddrs { - match := false - for _, s := range subnets { - ok, err := subnetMatches(s, aa) - if err != nil { - return nil, err - } - if !ok { - continue - } - iData[s].AuxAddress[key] = aa - match = true - } - if !match { - return nil, fmt.Errorf("no matching subnet for aux-address %s", aa) - } - } - - idl := []network.IPAMConfig{} - for _, v := range iData { - idl = append(idl, *v) - } - return idl, nil -} - -func subnetMatches(subnet, data string) (bool, error) { - var ( - ip net.IP - ) - - _, s, err := net.ParseCIDR(subnet) - if err != nil { - return false, fmt.Errorf("Invalid subnet %s : %v", s, err) - } - - if strings.Contains(data, "/") { - ip, _, err = net.ParseCIDR(data) - if err != nil { - return false, fmt.Errorf("Invalid cidr %s : %v", data, err) - } - } else { - ip = net.ParseIP(data) - } - - return s.Contains(ip), nil -} diff --git a/vendor/github.com/docker/docker/cli/command/network/disconnect.go b/vendor/github.com/docker/docker/cli/command/network/disconnect.go deleted file mode 100644 index c9d9c14..0000000 --- a/vendor/github.com/docker/docker/cli/command/network/disconnect.go +++ /dev/null @@ -1,41 +0,0 @@ -package network - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type disconnectOptions struct { - network string - container string - force bool -} - -func newDisconnectCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := disconnectOptions{} - - cmd := &cobra.Command{ - Use: "disconnect [OPTIONS] NETWORK CONTAINER", - Short: "Disconnect a container from a network", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - opts.network = args[0] - opts.container = args[1] - return runDisconnect(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.force, "force", "f", false, "Force the container to disconnect from a network") - - return cmd -} - -func runDisconnect(dockerCli *command.DockerCli, opts disconnectOptions) error { - client := dockerCli.Client() - - return client.NetworkDisconnect(context.Background(), opts.network, opts.container, opts.force) -} diff --git a/vendor/github.com/docker/docker/cli/command/network/inspect.go b/vendor/github.com/docker/docker/cli/command/network/inspect.go deleted file mode 100644 index 1a86855..0000000 --- a/vendor/github.com/docker/docker/cli/command/network/inspect.go +++ /dev/null @@ -1,45 +0,0 @@ -package network - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/inspect" - "github.com/spf13/cobra" -) - -type inspectOptions struct { - format string - names []string -} - -func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts inspectOptions - - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] NETWORK [NETWORK...]", - Short: "Display detailed information on one or more networks", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.names = args - return runInspect(dockerCli, opts) - }, - } - - cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - - return cmd -} - -func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { - client := dockerCli.Client() - - ctx := context.Background() - - getNetFunc := func(name string) (interface{}, []byte, error) { - return client.NetworkInspectWithRaw(ctx, name) - } - - return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getNetFunc) -} diff --git a/vendor/github.com/docker/docker/cli/command/network/list.go b/vendor/github.com/docker/docker/cli/command/network/list.go deleted file mode 100644 index 1a5d285..0000000 --- a/vendor/github.com/docker/docker/cli/command/network/list.go +++ /dev/null @@ -1,76 +0,0 @@ -package network - -import ( - "sort" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/formatter" - "github.com/docker/docker/opts" - "github.com/spf13/cobra" -) - -type byNetworkName []types.NetworkResource - -func (r byNetworkName) Len() int { return len(r) } -func (r byNetworkName) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r byNetworkName) Less(i, j int) bool { return r[i].Name < r[j].Name } - -type listOptions struct { - quiet bool - noTrunc bool - format string - filter opts.FilterOpt -} - -func newListCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := listOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "ls [OPTIONS]", - Aliases: []string{"list"}, - Short: "List networks", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runList(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display network IDs") - flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate the output") - flags.StringVar(&opts.format, "format", "", "Pretty-print networks using a Go template") - flags.VarP(&opts.filter, "filter", "f", "Provide filter values (e.g. 'driver=bridge')") - - return cmd -} - -func runList(dockerCli *command.DockerCli, opts listOptions) error { - client := dockerCli.Client() - options := types.NetworkListOptions{Filters: opts.filter.Value()} - networkResources, err := client.NetworkList(context.Background(), options) - if err != nil { - return err - } - - format := opts.format - if len(format) == 0 { - if len(dockerCli.ConfigFile().NetworksFormat) > 0 && !opts.quiet { - format = dockerCli.ConfigFile().NetworksFormat - } else { - format = formatter.TableFormatKey - } - } - - sort.Sort(byNetworkName(networkResources)) - - networksCtx := formatter.Context{ - Output: dockerCli.Out(), - Format: formatter.NewNetworkFormat(format, opts.quiet), - Trunc: !opts.noTrunc, - } - return formatter.NetworkWrite(networksCtx, networkResources) -} diff --git a/vendor/github.com/docker/docker/cli/command/network/prune.go b/vendor/github.com/docker/docker/cli/command/network/prune.go deleted file mode 100644 index 9f1979e..0000000 --- a/vendor/github.com/docker/docker/cli/command/network/prune.go +++ /dev/null @@ -1,73 +0,0 @@ -package network - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type pruneOptions struct { - force bool -} - -// NewPruneCommand returns a new cobra prune command for networks -func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts pruneOptions - - cmd := &cobra.Command{ - Use: "prune [OPTIONS]", - Short: "Remove all unused networks", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - output, err := runPrune(dockerCli, opts) - if err != nil { - return err - } - if output != "" { - fmt.Fprintln(dockerCli.Out(), output) - } - return nil - }, - Tags: map[string]string{"version": "1.25"}, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") - - return cmd -} - -const warning = `WARNING! This will remove all networks not used by at least one container. -Are you sure you want to continue?` - -func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (output string, err error) { - if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { - return - } - - report, err := dockerCli.Client().NetworksPrune(context.Background(), filters.Args{}) - if err != nil { - return - } - - if len(report.NetworksDeleted) > 0 { - output = "Deleted Networks:\n" - for _, id := range report.NetworksDeleted { - output += id + "\n" - } - } - - return -} - -// RunPrune calls the Network Prune API -// This returns the amount of space reclaimed and a detailed output string -func RunPrune(dockerCli *command.DockerCli) (uint64, string, error) { - output, err := runPrune(dockerCli, pruneOptions{force: true}) - return 0, output, err -} diff --git a/vendor/github.com/docker/docker/cli/command/network/remove.go b/vendor/github.com/docker/docker/cli/command/network/remove.go deleted file mode 100644 index 2034b87..0000000 --- a/vendor/github.com/docker/docker/cli/command/network/remove.go +++ /dev/null @@ -1,43 +0,0 @@ -package network - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { - return &cobra.Command{ - Use: "rm NETWORK [NETWORK...]", - Aliases: []string{"remove"}, - Short: "Remove one or more networks", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runRemove(dockerCli, args) - }, - } -} - -func runRemove(dockerCli *command.DockerCli, networks []string) error { - client := dockerCli.Client() - ctx := context.Background() - status := 0 - - for _, name := range networks { - if err := client.NetworkRemove(ctx, name); err != nil { - fmt.Fprintf(dockerCli.Err(), "%s\n", err) - status = 1 - continue - } - fmt.Fprintf(dockerCli.Out(), "%s\n", name) - } - - if status != 0 { - return cli.StatusError{StatusCode: status} - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/node/cmd.go b/vendor/github.com/docker/docker/cli/command/node/cmd.go deleted file mode 100644 index e71b919..0000000 --- a/vendor/github.com/docker/docker/cli/command/node/cmd.go +++ /dev/null @@ -1,43 +0,0 @@ -package node - -import ( - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - apiclient "github.com/docker/docker/client" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -// NewNodeCommand returns a cobra command for `node` subcommands -func NewNodeCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "node", - Short: "Manage Swarm nodes", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - } - cmd.AddCommand( - newDemoteCommand(dockerCli), - newInspectCommand(dockerCli), - newListCommand(dockerCli), - newPromoteCommand(dockerCli), - newRemoveCommand(dockerCli), - newPsCommand(dockerCli), - newUpdateCommand(dockerCli), - ) - return cmd -} - -// Reference returns the reference of a node. The special value "self" for a node -// reference is mapped to the current node, hence the node ID is retrieved using -// the `/info` endpoint. -func Reference(ctx context.Context, client apiclient.APIClient, ref string) (string, error) { - if ref == "self" { - info, err := client.Info(ctx) - if err != nil { - return "", err - } - return info.Swarm.NodeID, nil - } - return ref, nil -} diff --git a/vendor/github.com/docker/docker/cli/command/node/demote.go b/vendor/github.com/docker/docker/cli/command/node/demote.go deleted file mode 100644 index 33f86c6..0000000 --- a/vendor/github.com/docker/docker/cli/command/node/demote.go +++ /dev/null @@ -1,36 +0,0 @@ -package node - -import ( - "fmt" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -func newDemoteCommand(dockerCli *command.DockerCli) *cobra.Command { - return &cobra.Command{ - Use: "demote NODE [NODE...]", - Short: "Demote one or more nodes from manager in the swarm", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runDemote(dockerCli, args) - }, - } -} - -func runDemote(dockerCli *command.DockerCli, nodes []string) error { - demote := func(node *swarm.Node) error { - if node.Spec.Role == swarm.NodeRoleWorker { - fmt.Fprintf(dockerCli.Out(), "Node %s is already a worker.\n", node.ID) - return errNoRoleChange - } - node.Spec.Role = swarm.NodeRoleWorker - return nil - } - success := func(nodeID string) { - fmt.Fprintf(dockerCli.Out(), "Manager %s demoted in the swarm.\n", nodeID) - } - return updateNodes(dockerCli, nodes, demote, success) -} diff --git a/vendor/github.com/docker/docker/cli/command/node/inspect.go b/vendor/github.com/docker/docker/cli/command/node/inspect.go deleted file mode 100644 index fde7018..0000000 --- a/vendor/github.com/docker/docker/cli/command/node/inspect.go +++ /dev/null @@ -1,144 +0,0 @@ -package node - -import ( - "fmt" - "io" - "sort" - "strings" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/inspect" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/go-units" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type inspectOptions struct { - nodeIds []string - format string - pretty bool -} - -func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts inspectOptions - - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] self|NODE [NODE...]", - Short: "Display detailed information on one or more nodes", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.nodeIds = args - return runInspect(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - flags.BoolVar(&opts.pretty, "pretty", false, "Print the information in a human friendly format.") - return cmd -} - -func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { - client := dockerCli.Client() - ctx := context.Background() - getRef := func(ref string) (interface{}, []byte, error) { - nodeRef, err := Reference(ctx, client, ref) - if err != nil { - return nil, nil, err - } - node, _, err := client.NodeInspectWithRaw(ctx, nodeRef) - return node, nil, err - } - - if !opts.pretty { - return inspect.Inspect(dockerCli.Out(), opts.nodeIds, opts.format, getRef) - } - return printHumanFriendly(dockerCli.Out(), opts.nodeIds, getRef) -} - -func printHumanFriendly(out io.Writer, refs []string, getRef inspect.GetRefFunc) error { - for idx, ref := range refs { - obj, _, err := getRef(ref) - if err != nil { - return err - } - printNode(out, obj.(swarm.Node)) - - // TODO: better way to do this? - // print extra space between objects, but not after the last one - if idx+1 != len(refs) { - fmt.Fprintf(out, "\n\n") - } else { - fmt.Fprintf(out, "\n") - } - } - return nil -} - -// TODO: use a template -func printNode(out io.Writer, node swarm.Node) { - fmt.Fprintf(out, "ID:\t\t\t%s\n", node.ID) - ioutils.FprintfIfNotEmpty(out, "Name:\t\t\t%s\n", node.Spec.Name) - if node.Spec.Labels != nil { - fmt.Fprintln(out, "Labels:") - for k, v := range node.Spec.Labels { - fmt.Fprintf(out, " - %s = %s\n", k, v) - } - } - - ioutils.FprintfIfNotEmpty(out, "Hostname:\t\t%s\n", node.Description.Hostname) - fmt.Fprintf(out, "Joined at:\t\t%s\n", command.PrettyPrint(node.CreatedAt)) - fmt.Fprintln(out, "Status:") - fmt.Fprintf(out, " State:\t\t\t%s\n", command.PrettyPrint(node.Status.State)) - ioutils.FprintfIfNotEmpty(out, " Message:\t\t%s\n", command.PrettyPrint(node.Status.Message)) - fmt.Fprintf(out, " Availability:\t\t%s\n", command.PrettyPrint(node.Spec.Availability)) - ioutils.FprintfIfNotEmpty(out, " Address:\t\t%s\n", command.PrettyPrint(node.Status.Addr)) - - if node.ManagerStatus != nil { - fmt.Fprintln(out, "Manager Status:") - fmt.Fprintf(out, " Address:\t\t%s\n", node.ManagerStatus.Addr) - fmt.Fprintf(out, " Raft Status:\t\t%s\n", command.PrettyPrint(node.ManagerStatus.Reachability)) - leader := "No" - if node.ManagerStatus.Leader { - leader = "Yes" - } - fmt.Fprintf(out, " Leader:\t\t%s\n", leader) - } - - fmt.Fprintln(out, "Platform:") - fmt.Fprintf(out, " Operating System:\t%s\n", node.Description.Platform.OS) - fmt.Fprintf(out, " Architecture:\t\t%s\n", node.Description.Platform.Architecture) - - fmt.Fprintln(out, "Resources:") - fmt.Fprintf(out, " CPUs:\t\t\t%d\n", node.Description.Resources.NanoCPUs/1e9) - fmt.Fprintf(out, " Memory:\t\t%s\n", units.BytesSize(float64(node.Description.Resources.MemoryBytes))) - - var pluginTypes []string - pluginNamesByType := map[string][]string{} - for _, p := range node.Description.Engine.Plugins { - // append to pluginTypes only if not done previously - if _, ok := pluginNamesByType[p.Type]; !ok { - pluginTypes = append(pluginTypes, p.Type) - } - pluginNamesByType[p.Type] = append(pluginNamesByType[p.Type], p.Name) - } - - if len(pluginTypes) > 0 { - fmt.Fprintln(out, "Plugins:") - sort.Strings(pluginTypes) // ensure stable output - for _, pluginType := range pluginTypes { - fmt.Fprintf(out, " %s:\t\t%s\n", pluginType, strings.Join(pluginNamesByType[pluginType], ", ")) - } - } - fmt.Fprintf(out, "Engine Version:\t\t%s\n", node.Description.Engine.EngineVersion) - - if len(node.Description.Engine.Labels) != 0 { - fmt.Fprintln(out, "Engine Labels:") - for k, v := range node.Description.Engine.Labels { - fmt.Fprintf(out, " - %s = %s\n", k, v) - } - } -} diff --git a/vendor/github.com/docker/docker/cli/command/node/list.go b/vendor/github.com/docker/docker/cli/command/node/list.go deleted file mode 100644 index 9cacdcf..0000000 --- a/vendor/github.com/docker/docker/cli/command/node/list.go +++ /dev/null @@ -1,115 +0,0 @@ -package node - -import ( - "fmt" - "io" - "text/tabwriter" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/opts" - "github.com/spf13/cobra" -) - -const ( - listItemFmt = "%s\t%s\t%s\t%s\t%s\n" -) - -type listOptions struct { - quiet bool - filter opts.FilterOpt -} - -func newListCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := listOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "ls [OPTIONS]", - Aliases: []string{"list"}, - Short: "List nodes in the swarm", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runList(dockerCli, opts) - }, - } - flags := cmd.Flags() - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") - flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") - - return cmd -} - -func runList(dockerCli *command.DockerCli, opts listOptions) error { - client := dockerCli.Client() - out := dockerCli.Out() - ctx := context.Background() - - nodes, err := client.NodeList( - ctx, - types.NodeListOptions{Filters: opts.filter.Value()}) - if err != nil { - return err - } - - if len(nodes) > 0 && !opts.quiet { - // only non-empty nodes and not quiet, should we call /info api - info, err := client.Info(ctx) - if err != nil { - return err - } - printTable(out, nodes, info) - } else if !opts.quiet { - // no nodes and not quiet, print only one line with columns ID, HOSTNAME, ... - printTable(out, nodes, types.Info{}) - } else { - printQuiet(out, nodes) - } - - return nil -} - -func printTable(out io.Writer, nodes []swarm.Node, info types.Info) { - writer := tabwriter.NewWriter(out, 0, 4, 2, ' ', 0) - - // Ignore flushing errors - defer writer.Flush() - - fmt.Fprintf(writer, listItemFmt, "ID", "HOSTNAME", "STATUS", "AVAILABILITY", "MANAGER STATUS") - for _, node := range nodes { - name := node.Description.Hostname - availability := string(node.Spec.Availability) - - reachability := "" - if node.ManagerStatus != nil { - if node.ManagerStatus.Leader { - reachability = "Leader" - } else { - reachability = string(node.ManagerStatus.Reachability) - } - } - - ID := node.ID - if node.ID == info.Swarm.NodeID { - ID = ID + " *" - } - - fmt.Fprintf( - writer, - listItemFmt, - ID, - name, - command.PrettyPrint(string(node.Status.State)), - command.PrettyPrint(availability), - command.PrettyPrint(reachability)) - } -} - -func printQuiet(out io.Writer, nodes []swarm.Node) { - for _, node := range nodes { - fmt.Fprintln(out, node.ID) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/node/opts.go b/vendor/github.com/docker/docker/cli/command/node/opts.go deleted file mode 100644 index 7e6c55d..0000000 --- a/vendor/github.com/docker/docker/cli/command/node/opts.go +++ /dev/null @@ -1,60 +0,0 @@ -package node - -import ( - "fmt" - "strings" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/opts" - runconfigopts "github.com/docker/docker/runconfig/opts" -) - -type nodeOptions struct { - annotations - role string - availability string -} - -type annotations struct { - name string - labels opts.ListOpts -} - -func newNodeOptions() *nodeOptions { - return &nodeOptions{ - annotations: annotations{ - labels: opts.NewListOpts(nil), - }, - } -} - -func (opts *nodeOptions) ToNodeSpec() (swarm.NodeSpec, error) { - var spec swarm.NodeSpec - - spec.Annotations.Name = opts.annotations.name - spec.Annotations.Labels = runconfigopts.ConvertKVStringsToMap(opts.annotations.labels.GetAll()) - - switch swarm.NodeRole(strings.ToLower(opts.role)) { - case swarm.NodeRoleWorker: - spec.Role = swarm.NodeRoleWorker - case swarm.NodeRoleManager: - spec.Role = swarm.NodeRoleManager - case "": - default: - return swarm.NodeSpec{}, fmt.Errorf("invalid role %q, only worker and manager are supported", opts.role) - } - - switch swarm.NodeAvailability(strings.ToLower(opts.availability)) { - case swarm.NodeAvailabilityActive: - spec.Availability = swarm.NodeAvailabilityActive - case swarm.NodeAvailabilityPause: - spec.Availability = swarm.NodeAvailabilityPause - case swarm.NodeAvailabilityDrain: - spec.Availability = swarm.NodeAvailabilityDrain - case "": - default: - return swarm.NodeSpec{}, fmt.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability) - } - - return spec, nil -} diff --git a/vendor/github.com/docker/docker/cli/command/node/promote.go b/vendor/github.com/docker/docker/cli/command/node/promote.go deleted file mode 100644 index f47d783..0000000 --- a/vendor/github.com/docker/docker/cli/command/node/promote.go +++ /dev/null @@ -1,36 +0,0 @@ -package node - -import ( - "fmt" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -func newPromoteCommand(dockerCli *command.DockerCli) *cobra.Command { - return &cobra.Command{ - Use: "promote NODE [NODE...]", - Short: "Promote one or more nodes to manager in the swarm", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runPromote(dockerCli, args) - }, - } -} - -func runPromote(dockerCli *command.DockerCli, nodes []string) error { - promote := func(node *swarm.Node) error { - if node.Spec.Role == swarm.NodeRoleManager { - fmt.Fprintf(dockerCli.Out(), "Node %s is already a manager.\n", node.ID) - return errNoRoleChange - } - node.Spec.Role = swarm.NodeRoleManager - return nil - } - success := func(nodeID string) { - fmt.Fprintf(dockerCli.Out(), "Node %s promoted to a manager in the swarm.\n", nodeID) - } - return updateNodes(dockerCli, nodes, promote, success) -} diff --git a/vendor/github.com/docker/docker/cli/command/node/ps.go b/vendor/github.com/docker/docker/cli/command/node/ps.go deleted file mode 100644 index a034721..0000000 --- a/vendor/github.com/docker/docker/cli/command/node/ps.go +++ /dev/null @@ -1,93 +0,0 @@ -package node - -import ( - "fmt" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/idresolver" - "github.com/docker/docker/cli/command/task" - "github.com/docker/docker/opts" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type psOptions struct { - nodeIDs []string - noResolve bool - noTrunc bool - filter opts.FilterOpt -} - -func newPsCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := psOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "ps [OPTIONS] [NODE...]", - Short: "List tasks running on one or more nodes, defaults to current node", - Args: cli.RequiresMinArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - opts.nodeIDs = []string{"self"} - - if len(args) != 0 { - opts.nodeIDs = args - } - - return runPs(dockerCli, opts) - }, - } - flags := cmd.Flags() - flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") - flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") - flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") - - return cmd -} - -func runPs(dockerCli *command.DockerCli, opts psOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - var ( - errs []string - tasks []swarm.Task - ) - - for _, nodeID := range opts.nodeIDs { - nodeRef, err := Reference(ctx, client, nodeID) - if err != nil { - errs = append(errs, err.Error()) - continue - } - - node, _, err := client.NodeInspectWithRaw(ctx, nodeRef) - if err != nil { - errs = append(errs, err.Error()) - continue - } - - filter := opts.filter.Value() - filter.Add("node", node.ID) - - nodeTasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter}) - if err != nil { - errs = append(errs, err.Error()) - continue - } - - tasks = append(tasks, nodeTasks...) - } - - if err := task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), opts.noTrunc); err != nil { - errs = append(errs, err.Error()) - } - - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/node/remove.go b/vendor/github.com/docker/docker/cli/command/node/remove.go deleted file mode 100644 index 19b4a96..0000000 --- a/vendor/github.com/docker/docker/cli/command/node/remove.go +++ /dev/null @@ -1,56 +0,0 @@ -package node - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type removeOptions struct { - force bool -} - -func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := removeOptions{} - - cmd := &cobra.Command{ - Use: "rm [OPTIONS] NODE [NODE...]", - Aliases: []string{"remove"}, - Short: "Remove one or more nodes from the swarm", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runRemove(dockerCli, args, opts) - }, - } - flags := cmd.Flags() - flags.BoolVarP(&opts.force, "force", "f", false, "Force remove a node from the swarm") - return cmd -} - -func runRemove(dockerCli *command.DockerCli, args []string, opts removeOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - var errs []string - - for _, nodeID := range args { - err := client.NodeRemove(ctx, nodeID, types.NodeRemoveOptions{Force: opts.force}) - if err != nil { - errs = append(errs, err.Error()) - continue - } - fmt.Fprintf(dockerCli.Out(), "%s\n", nodeID) - } - - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/node/update.go b/vendor/github.com/docker/docker/cli/command/node/update.go deleted file mode 100644 index 65339e1..0000000 --- a/vendor/github.com/docker/docker/cli/command/node/update.go +++ /dev/null @@ -1,121 +0,0 @@ -package node - -import ( - "errors" - "fmt" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/opts" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "golang.org/x/net/context" -) - -var ( - errNoRoleChange = errors.New("role was already set to the requested value") -) - -func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command { - nodeOpts := newNodeOptions() - - cmd := &cobra.Command{ - Use: "update [OPTIONS] NODE", - Short: "Update a node", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runUpdate(dockerCli, cmd.Flags(), args[0]) - }, - } - - flags := cmd.Flags() - flags.StringVar(&nodeOpts.role, flagRole, "", "Role of the node (worker/manager)") - flags.StringVar(&nodeOpts.availability, flagAvailability, "", "Availability of the node (active/pause/drain)") - flags.Var(&nodeOpts.annotations.labels, flagLabelAdd, "Add or update a node label (key=value)") - labelKeys := opts.NewListOpts(nil) - flags.Var(&labelKeys, flagLabelRemove, "Remove a node label if exists") - return cmd -} - -func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, nodeID string) error { - success := func(_ string) { - fmt.Fprintln(dockerCli.Out(), nodeID) - } - return updateNodes(dockerCli, []string{nodeID}, mergeNodeUpdate(flags), success) -} - -func updateNodes(dockerCli *command.DockerCli, nodes []string, mergeNode func(node *swarm.Node) error, success func(nodeID string)) error { - client := dockerCli.Client() - ctx := context.Background() - - for _, nodeID := range nodes { - node, _, err := client.NodeInspectWithRaw(ctx, nodeID) - if err != nil { - return err - } - - err = mergeNode(&node) - if err != nil { - if err == errNoRoleChange { - continue - } - return err - } - err = client.NodeUpdate(ctx, node.ID, node.Version, node.Spec) - if err != nil { - return err - } - success(nodeID) - } - return nil -} - -func mergeNodeUpdate(flags *pflag.FlagSet) func(*swarm.Node) error { - return func(node *swarm.Node) error { - spec := &node.Spec - - if flags.Changed(flagRole) { - str, err := flags.GetString(flagRole) - if err != nil { - return err - } - spec.Role = swarm.NodeRole(str) - } - if flags.Changed(flagAvailability) { - str, err := flags.GetString(flagAvailability) - if err != nil { - return err - } - spec.Availability = swarm.NodeAvailability(str) - } - if spec.Annotations.Labels == nil { - spec.Annotations.Labels = make(map[string]string) - } - if flags.Changed(flagLabelAdd) { - labels := flags.Lookup(flagLabelAdd).Value.(*opts.ListOpts).GetAll() - for k, v := range runconfigopts.ConvertKVStringsToMap(labels) { - spec.Annotations.Labels[k] = v - } - } - if flags.Changed(flagLabelRemove) { - keys := flags.Lookup(flagLabelRemove).Value.(*opts.ListOpts).GetAll() - for _, k := range keys { - // if a key doesn't exist, fail the command explicitly - if _, exists := spec.Annotations.Labels[k]; !exists { - return fmt.Errorf("key %s doesn't exist in node's labels", k) - } - delete(spec.Annotations.Labels, k) - } - } - return nil - } -} - -const ( - flagRole = "role" - flagAvailability = "availability" - flagLabelAdd = "label-add" - flagLabelRemove = "label-rm" -) diff --git a/vendor/github.com/docker/docker/cli/command/out.go b/vendor/github.com/docker/docker/cli/command/out.go deleted file mode 100644 index 85718d7..0000000 --- a/vendor/github.com/docker/docker/cli/command/out.go +++ /dev/null @@ -1,69 +0,0 @@ -package command - -import ( - "io" - "os" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/term" -) - -// OutStream is an output stream used by the DockerCli to write normal program -// output. -type OutStream struct { - out io.Writer - fd uintptr - isTerminal bool - state *term.State -} - -func (o *OutStream) Write(p []byte) (int, error) { - return o.out.Write(p) -} - -// FD returns the file descriptor number for this stream -func (o *OutStream) FD() uintptr { - return o.fd -} - -// IsTerminal returns true if this stream is connected to a terminal -func (o *OutStream) IsTerminal() bool { - return o.isTerminal -} - -// SetRawTerminal sets raw mode on the output terminal -func (o *OutStream) SetRawTerminal() (err error) { - if os.Getenv("NORAW") != "" || !o.isTerminal { - return nil - } - o.state, err = term.SetRawTerminalOutput(o.fd) - return err -} - -// RestoreTerminal restores normal mode to the terminal -func (o *OutStream) RestoreTerminal() { - if o.state != nil { - term.RestoreTerminal(o.fd, o.state) - } -} - -// GetTtySize returns the height and width in characters of the tty -func (o *OutStream) GetTtySize() (uint, uint) { - if !o.isTerminal { - return 0, 0 - } - ws, err := term.GetWinsize(o.fd) - if err != nil { - logrus.Debugf("Error getting size: %s", err) - if ws == nil { - return 0, 0 - } - } - return uint(ws.Height), uint(ws.Width) -} - -// NewOutStream returns a new OutStream object from a Writer -func NewOutStream(out io.Writer) *OutStream { - fd, isTerminal := term.GetFdInfo(out) - return &OutStream{out: out, fd: fd, isTerminal: isTerminal} -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/cmd.go b/vendor/github.com/docker/docker/cli/command/plugin/cmd.go deleted file mode 100644 index 92c990a..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/cmd.go +++ /dev/null @@ -1,31 +0,0 @@ -package plugin - -import ( - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -// NewPluginCommand returns a cobra command for `plugin` subcommands -func NewPluginCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "plugin", - Short: "Manage plugins", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - } - - cmd.AddCommand( - newDisableCommand(dockerCli), - newEnableCommand(dockerCli), - newInspectCommand(dockerCli), - newInstallCommand(dockerCli), - newListCommand(dockerCli), - newRemoveCommand(dockerCli), - newSetCommand(dockerCli), - newPushCommand(dockerCli), - newCreateCommand(dockerCli), - newUpgradeCommand(dockerCli), - ) - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/create.go b/vendor/github.com/docker/docker/cli/command/plugin/create.go deleted file mode 100644 index 2aab1e9..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/create.go +++ /dev/null @@ -1,125 +0,0 @@ -package plugin - -import ( - "encoding/json" - "fmt" - "io" - "os" - "path/filepath" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/reference" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -// validateTag checks if the given repoName can be resolved. -func validateTag(rawRepo string) error { - _, err := reference.ParseNamed(rawRepo) - - return err -} - -// validateConfig ensures that a valid config.json is available in the given path -func validateConfig(path string) error { - dt, err := os.Open(filepath.Join(path, "config.json")) - if err != nil { - return err - } - - m := types.PluginConfig{} - err = json.NewDecoder(dt).Decode(&m) - dt.Close() - - return err -} - -// validateContextDir validates the given dir and returns abs path on success. -func validateContextDir(contextDir string) (string, error) { - absContextDir, err := filepath.Abs(contextDir) - - stat, err := os.Lstat(absContextDir) - if err != nil { - return "", err - } - - if !stat.IsDir() { - return "", fmt.Errorf("context must be a directory") - } - - return absContextDir, nil -} - -type pluginCreateOptions struct { - repoName string - context string - compress bool -} - -func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { - options := pluginCreateOptions{} - - cmd := &cobra.Command{ - Use: "create [OPTIONS] PLUGIN PLUGIN-DATA-DIR", - Short: "Create a plugin from a rootfs and configuration. Plugin data directory must contain config.json and rootfs directory.", - Args: cli.RequiresMinArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - options.repoName = args[0] - options.context = args[1] - return runCreate(dockerCli, options) - }, - } - - flags := cmd.Flags() - - flags.BoolVar(&options.compress, "compress", false, "Compress the context using gzip") - - return cmd -} - -func runCreate(dockerCli *command.DockerCli, options pluginCreateOptions) error { - var ( - createCtx io.ReadCloser - err error - ) - - if err := validateTag(options.repoName); err != nil { - return err - } - - absContextDir, err := validateContextDir(options.context) - if err != nil { - return err - } - - if err := validateConfig(options.context); err != nil { - return err - } - - compression := archive.Uncompressed - if options.compress { - logrus.Debugf("compression enabled") - compression = archive.Gzip - } - - createCtx, err = archive.TarWithOptions(absContextDir, &archive.TarOptions{ - Compression: compression, - }) - - if err != nil { - return err - } - - ctx := context.Background() - - createOptions := types.PluginCreateOptions{RepoName: options.repoName} - if err = dockerCli.Client().PluginCreate(ctx, createCtx, createOptions); err != nil { - return err - } - fmt.Fprintln(dockerCli.Out(), options.repoName) - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/disable.go b/vendor/github.com/docker/docker/cli/command/plugin/disable.go deleted file mode 100644 index 07b0ec2..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/disable.go +++ /dev/null @@ -1,36 +0,0 @@ -package plugin - -import ( - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -func newDisableCommand(dockerCli *command.DockerCli) *cobra.Command { - var force bool - - cmd := &cobra.Command{ - Use: "disable [OPTIONS] PLUGIN", - Short: "Disable a plugin", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runDisable(dockerCli, args[0], force) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&force, "force", "f", false, "Force the disable of an active plugin") - return cmd -} - -func runDisable(dockerCli *command.DockerCli, name string, force bool) error { - if err := dockerCli.Client().PluginDisable(context.Background(), name, types.PluginDisableOptions{Force: force}); err != nil { - return err - } - fmt.Fprintln(dockerCli.Out(), name) - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/enable.go b/vendor/github.com/docker/docker/cli/command/plugin/enable.go deleted file mode 100644 index 77762f4..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/enable.go +++ /dev/null @@ -1,47 +0,0 @@ -package plugin - -import ( - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type enableOpts struct { - timeout int - name string -} - -func newEnableCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts enableOpts - - cmd := &cobra.Command{ - Use: "enable [OPTIONS] PLUGIN", - Short: "Enable a plugin", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.name = args[0] - return runEnable(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.IntVar(&opts.timeout, "timeout", 0, "HTTP client timeout (in seconds)") - return cmd -} - -func runEnable(dockerCli *command.DockerCli, opts *enableOpts) error { - name := opts.name - if opts.timeout < 0 { - return fmt.Errorf("negative timeout %d is invalid", opts.timeout) - } - - if err := dockerCli.Client().PluginEnable(context.Background(), name, types.PluginEnableOptions{Timeout: opts.timeout}); err != nil { - return err - } - fmt.Fprintln(dockerCli.Out(), name) - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/inspect.go b/vendor/github.com/docker/docker/cli/command/plugin/inspect.go deleted file mode 100644 index c2c7a0d..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/inspect.go +++ /dev/null @@ -1,42 +0,0 @@ -package plugin - -import ( - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/inspect" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type inspectOptions struct { - pluginNames []string - format string -} - -func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts inspectOptions - - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] PLUGIN [PLUGIN...]", - Short: "Display detailed information on one or more plugins", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.pluginNames = args - return runInspect(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - return cmd -} - -func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { - client := dockerCli.Client() - ctx := context.Background() - getRef := func(ref string) (interface{}, []byte, error) { - return client.PluginInspectWithRaw(ctx, ref) - } - - return inspect.Inspect(dockerCli.Out(), opts.pluginNames, opts.format, getRef) -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/install.go b/vendor/github.com/docker/docker/cli/command/plugin/install.go deleted file mode 100644 index 2c3170c..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/install.go +++ /dev/null @@ -1,208 +0,0 @@ -package plugin - -import ( - "bufio" - "errors" - "fmt" - "strings" - - distreference "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/image" - "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "golang.org/x/net/context" -) - -type pluginOptions struct { - remote string - localName string - grantPerms bool - disable bool - args []string - skipRemoteCheck bool -} - -func loadPullFlags(opts *pluginOptions, flags *pflag.FlagSet) { - flags.BoolVar(&opts.grantPerms, "grant-all-permissions", false, "Grant all permissions necessary to run the plugin") - command.AddTrustedFlags(flags, true) -} - -func newInstallCommand(dockerCli *command.DockerCli) *cobra.Command { - var options pluginOptions - cmd := &cobra.Command{ - Use: "install [OPTIONS] PLUGIN [KEY=VALUE...]", - Short: "Install a plugin", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - options.remote = args[0] - if len(args) > 1 { - options.args = args[1:] - } - return runInstall(dockerCli, options) - }, - } - - flags := cmd.Flags() - loadPullFlags(&options, flags) - flags.BoolVar(&options.disable, "disable", false, "Do not enable the plugin on install") - flags.StringVar(&options.localName, "alias", "", "Local name for plugin") - return cmd -} - -func getRepoIndexFromUnnormalizedRef(ref distreference.Named) (*registrytypes.IndexInfo, error) { - named, err := reference.ParseNamed(ref.Name()) - if err != nil { - return nil, err - } - - repoInfo, err := registry.ParseRepositoryInfo(named) - if err != nil { - return nil, err - } - - return repoInfo.Index, nil -} - -type pluginRegistryService struct { - registry.Service -} - -func (s pluginRegistryService) ResolveRepository(name reference.Named) (repoInfo *registry.RepositoryInfo, err error) { - repoInfo, err = s.Service.ResolveRepository(name) - if repoInfo != nil { - repoInfo.Class = "plugin" - } - return -} - -func newRegistryService() registry.Service { - return pluginRegistryService{ - Service: registry.NewService(registry.ServiceOptions{V2Only: true}), - } -} - -func buildPullConfig(ctx context.Context, dockerCli *command.DockerCli, opts pluginOptions, cmdName string) (types.PluginInstallOptions, error) { - // Parse name using distribution reference package to support name - // containing both tag and digest. Names with both tag and digest - // will be treated by the daemon as a pull by digest with - // an alias for the tag (if no alias is provided). - ref, err := distreference.ParseNamed(opts.remote) - if err != nil { - return types.PluginInstallOptions{}, err - } - - index, err := getRepoIndexFromUnnormalizedRef(ref) - if err != nil { - return types.PluginInstallOptions{}, err - } - - repoInfoIndex, err := getRepoIndexFromUnnormalizedRef(ref) - if err != nil { - return types.PluginInstallOptions{}, err - } - remote := ref.String() - - _, isCanonical := ref.(distreference.Canonical) - if command.IsTrusted() && !isCanonical { - var nt reference.NamedTagged - named, err := reference.ParseNamed(ref.Name()) - if err != nil { - return types.PluginInstallOptions{}, err - } - if tagged, ok := ref.(distreference.Tagged); ok { - nt, err = reference.WithTag(named, tagged.Tag()) - if err != nil { - return types.PluginInstallOptions{}, err - } - } else { - named = reference.WithDefaultTag(named) - nt = named.(reference.NamedTagged) - } - - ctx := context.Background() - trusted, err := image.TrustedReference(ctx, dockerCli, nt, newRegistryService()) - if err != nil { - return types.PluginInstallOptions{}, err - } - remote = trusted.String() - } - - authConfig := command.ResolveAuthConfig(ctx, dockerCli, index) - - encodedAuth, err := command.EncodeAuthToBase64(authConfig) - if err != nil { - return types.PluginInstallOptions{}, err - } - - registryAuthFunc := command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfoIndex, cmdName) - - options := types.PluginInstallOptions{ - RegistryAuth: encodedAuth, - RemoteRef: remote, - Disabled: opts.disable, - AcceptAllPermissions: opts.grantPerms, - AcceptPermissionsFunc: acceptPrivileges(dockerCli, opts.remote), - // TODO: Rename PrivilegeFunc, it has nothing to do with privileges - PrivilegeFunc: registryAuthFunc, - Args: opts.args, - } - return options, nil -} - -func runInstall(dockerCli *command.DockerCli, opts pluginOptions) error { - var localName string - if opts.localName != "" { - aref, err := reference.ParseNamed(opts.localName) - if err != nil { - return err - } - aref = reference.WithDefaultTag(aref) - if _, ok := aref.(reference.NamedTagged); !ok { - return fmt.Errorf("invalid name: %s", opts.localName) - } - localName = aref.String() - } - - ctx := context.Background() - options, err := buildPullConfig(ctx, dockerCli, opts, "plugin install") - if err != nil { - return err - } - responseBody, err := dockerCli.Client().PluginInstall(ctx, localName, options) - if err != nil { - if strings.Contains(err.Error(), "target is image") { - return errors.New(err.Error() + " - Use `docker image pull`") - } - return err - } - defer responseBody.Close() - if err := jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil); err != nil { - return err - } - fmt.Fprintf(dockerCli.Out(), "Installed plugin %s\n", opts.remote) // todo: return proper values from the API for this result - return nil -} - -func acceptPrivileges(dockerCli *command.DockerCli, name string) func(privileges types.PluginPrivileges) (bool, error) { - return func(privileges types.PluginPrivileges) (bool, error) { - fmt.Fprintf(dockerCli.Out(), "Plugin %q is requesting the following privileges:\n", name) - for _, privilege := range privileges { - fmt.Fprintf(dockerCli.Out(), " - %s: %v\n", privilege.Name, privilege.Value) - } - - fmt.Fprint(dockerCli.Out(), "Do you grant the above permissions? [y/N] ") - reader := bufio.NewReader(dockerCli.In()) - line, _, err := reader.ReadLine() - if err != nil { - return false, err - } - return strings.ToLower(string(line)) == "y", nil - } -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/list.go b/vendor/github.com/docker/docker/cli/command/plugin/list.go deleted file mode 100644 index 8fd16da..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/list.go +++ /dev/null @@ -1,63 +0,0 @@ -package plugin - -import ( - "fmt" - "strings" - "text/tabwriter" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/stringutils" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type listOptions struct { - noTrunc bool -} - -func newListCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts listOptions - - cmd := &cobra.Command{ - Use: "ls [OPTIONS]", - Short: "List plugins", - Aliases: []string{"list"}, - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runList(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") - - return cmd -} - -func runList(dockerCli *command.DockerCli, opts listOptions) error { - plugins, err := dockerCli.Client().PluginList(context.Background()) - if err != nil { - return err - } - - w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0) - fmt.Fprintf(w, "ID \tNAME \tDESCRIPTION\tENABLED") - fmt.Fprintf(w, "\n") - - for _, p := range plugins { - id := p.ID - desc := strings.Replace(p.Config.Description, "\n", " ", -1) - desc = strings.Replace(desc, "\r", " ", -1) - if !opts.noTrunc { - id = stringid.TruncateID(p.ID) - desc = stringutils.Ellipsis(desc, 45) - } - - fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", id, p.Name, desc, p.Enabled) - } - w.Flush() - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/push.go b/vendor/github.com/docker/docker/cli/command/plugin/push.go deleted file mode 100644 index 9abb38e..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/push.go +++ /dev/null @@ -1,71 +0,0 @@ -package plugin - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/image" - "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "github.com/spf13/cobra" -) - -func newPushCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "push [OPTIONS] PLUGIN[:TAG]", - Short: "Push a plugin to a registry", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runPush(dockerCli, args[0]) - }, - } - - flags := cmd.Flags() - - command.AddTrustedFlags(flags, true) - - return cmd -} - -func runPush(dockerCli *command.DockerCli, name string) error { - named, err := reference.ParseNamed(name) // FIXME: validate - if err != nil { - return err - } - if reference.IsNameOnly(named) { - named = reference.WithDefaultTag(named) - } - ref, ok := named.(reference.NamedTagged) - if !ok { - return fmt.Errorf("invalid name: %s", named.String()) - } - - ctx := context.Background() - - repoInfo, err := registry.ParseRepositoryInfo(named) - if err != nil { - return err - } - authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index) - - encodedAuth, err := command.EncodeAuthToBase64(authConfig) - if err != nil { - return err - } - responseBody, err := dockerCli.Client().PluginPush(ctx, ref.String(), encodedAuth) - if err != nil { - return err - } - defer responseBody.Close() - - if command.IsTrusted() { - repoInfo.Class = "plugin" - return image.PushTrustedReference(dockerCli, repoInfo, named, authConfig, responseBody) - } - - return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil) -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/remove.go b/vendor/github.com/docker/docker/cli/command/plugin/remove.go deleted file mode 100644 index 9f3aba9..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/remove.go +++ /dev/null @@ -1,55 +0,0 @@ -package plugin - -import ( - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type rmOptions struct { - force bool - - plugins []string -} - -func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts rmOptions - - cmd := &cobra.Command{ - Use: "rm [OPTIONS] PLUGIN [PLUGIN...]", - Short: "Remove one or more plugins", - Aliases: []string{"remove"}, - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.plugins = args - return runRemove(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of an active plugin") - return cmd -} - -func runRemove(dockerCli *command.DockerCli, opts *rmOptions) error { - ctx := context.Background() - - var errs cli.Errors - for _, name := range opts.plugins { - // TODO: pass names to api instead of making multiple api calls - if err := dockerCli.Client().PluginRemove(ctx, name, types.PluginRemoveOptions{Force: opts.force}); err != nil { - errs = append(errs, err) - continue - } - fmt.Fprintln(dockerCli.Out(), name) - } - // Do not simplify to `return errs` because even if errs == nil, it is not a nil-error interface value. - if errs != nil { - return errs - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/set.go b/vendor/github.com/docker/docker/cli/command/plugin/set.go deleted file mode 100644 index 52b09fb..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/set.go +++ /dev/null @@ -1,22 +0,0 @@ -package plugin - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -func newSetCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "set PLUGIN KEY=VALUE [KEY=VALUE...]", - Short: "Change settings for a plugin", - Args: cli.RequiresMinArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - return dockerCli.Client().PluginSet(context.Background(), args[0], args[1:]) - }, - } - - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/plugin/upgrade.go b/vendor/github.com/docker/docker/cli/command/plugin/upgrade.go deleted file mode 100644 index d212cd7..0000000 --- a/vendor/github.com/docker/docker/cli/command/plugin/upgrade.go +++ /dev/null @@ -1,100 +0,0 @@ -package plugin - -import ( - "bufio" - "context" - "fmt" - "strings" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/reference" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -func newUpgradeCommand(dockerCli *command.DockerCli) *cobra.Command { - var options pluginOptions - cmd := &cobra.Command{ - Use: "upgrade [OPTIONS] PLUGIN [REMOTE]", - Short: "Upgrade an existing plugin", - Args: cli.RequiresRangeArgs(1, 2), - RunE: func(cmd *cobra.Command, args []string) error { - options.localName = args[0] - if len(args) == 2 { - options.remote = args[1] - } - return runUpgrade(dockerCli, options) - }, - } - - flags := cmd.Flags() - loadPullFlags(&options, flags) - flags.BoolVar(&options.skipRemoteCheck, "skip-remote-check", false, "Do not check if specified remote plugin matches existing plugin image") - return cmd -} - -func runUpgrade(dockerCli *command.DockerCli, opts pluginOptions) error { - ctx := context.Background() - p, _, err := dockerCli.Client().PluginInspectWithRaw(ctx, opts.localName) - if err != nil { - return fmt.Errorf("error reading plugin data: %v", err) - } - - if p.Enabled { - return fmt.Errorf("the plugin must be disabled before upgrading") - } - - opts.localName = p.Name - if opts.remote == "" { - opts.remote = p.PluginReference - } - remote, err := reference.ParseNamed(opts.remote) - if err != nil { - return errors.Wrap(err, "error parsing remote upgrade image reference") - } - remote = reference.WithDefaultTag(remote) - - old, err := reference.ParseNamed(p.PluginReference) - if err != nil { - return errors.Wrap(err, "error parsing current image reference") - } - old = reference.WithDefaultTag(old) - - fmt.Fprintf(dockerCli.Out(), "Upgrading plugin %s from %s to %s\n", p.Name, old, remote) - if !opts.skipRemoteCheck && remote.String() != old.String() { - _, err := fmt.Fprint(dockerCli.Out(), "Plugin images do not match, are you sure? ") - if err != nil { - return errors.Wrap(err, "error writing to stdout") - } - - rdr := bufio.NewReader(dockerCli.In()) - line, _, err := rdr.ReadLine() - if err != nil { - return errors.Wrap(err, "error reading from stdin") - } - if strings.ToLower(string(line)) != "y" { - return errors.New("canceling upgrade request") - } - } - - options, err := buildPullConfig(ctx, dockerCli, opts, "plugin upgrade") - if err != nil { - return err - } - - responseBody, err := dockerCli.Client().PluginUpgrade(ctx, opts.localName, options) - if err != nil { - if strings.Contains(err.Error(), "target is image") { - return errors.New(err.Error() + " - Use `docker image pull`") - } - return err - } - defer responseBody.Close() - if err := jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil); err != nil { - return err - } - fmt.Fprintf(dockerCli.Out(), "Upgraded plugin %s to %s\n", opts.localName, opts.remote) // todo: return proper values from the API for this result - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/prune/prune.go b/vendor/github.com/docker/docker/cli/command/prune/prune.go deleted file mode 100644 index a022487..0000000 --- a/vendor/github.com/docker/docker/cli/command/prune/prune.go +++ /dev/null @@ -1,50 +0,0 @@ -package prune - -import ( - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/container" - "github.com/docker/docker/cli/command/image" - "github.com/docker/docker/cli/command/network" - "github.com/docker/docker/cli/command/volume" - "github.com/spf13/cobra" -) - -// NewContainerPruneCommand returns a cobra prune command for containers -func NewContainerPruneCommand(dockerCli *command.DockerCli) *cobra.Command { - return container.NewPruneCommand(dockerCli) -} - -// NewVolumePruneCommand returns a cobra prune command for volumes -func NewVolumePruneCommand(dockerCli *command.DockerCli) *cobra.Command { - return volume.NewPruneCommand(dockerCli) -} - -// NewImagePruneCommand returns a cobra prune command for images -func NewImagePruneCommand(dockerCli *command.DockerCli) *cobra.Command { - return image.NewPruneCommand(dockerCli) -} - -// NewNetworkPruneCommand returns a cobra prune command for Networks -func NewNetworkPruneCommand(dockerCli *command.DockerCli) *cobra.Command { - return network.NewPruneCommand(dockerCli) -} - -// RunContainerPrune executes a prune command for containers -func RunContainerPrune(dockerCli *command.DockerCli) (uint64, string, error) { - return container.RunPrune(dockerCli) -} - -// RunVolumePrune executes a prune command for volumes -func RunVolumePrune(dockerCli *command.DockerCli) (uint64, string, error) { - return volume.RunPrune(dockerCli) -} - -// RunImagePrune executes a prune command for images -func RunImagePrune(dockerCli *command.DockerCli, all bool) (uint64, string, error) { - return image.RunPrune(dockerCli, all) -} - -// RunNetworkPrune executes a prune command for networks -func RunNetworkPrune(dockerCli *command.DockerCli) (uint64, string, error) { - return network.RunPrune(dockerCli) -} diff --git a/vendor/github.com/docker/docker/cli/command/registry.go b/vendor/github.com/docker/docker/cli/command/registry.go deleted file mode 100644 index 65f6b33..0000000 --- a/vendor/github.com/docker/docker/cli/command/registry.go +++ /dev/null @@ -1,186 +0,0 @@ -package command - -import ( - "bufio" - "encoding/base64" - "encoding/json" - "fmt" - "io" - "os" - "runtime" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/pkg/term" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" -) - -// ElectAuthServer returns the default registry to use (by asking the daemon) -func ElectAuthServer(ctx context.Context, cli *DockerCli) string { - // The daemon `/info` endpoint informs us of the default registry being - // used. This is essential in cross-platforms environment, where for - // example a Linux client might be interacting with a Windows daemon, hence - // the default registry URL might be Windows specific. - serverAddress := registry.IndexServer - if info, err := cli.Client().Info(ctx); err != nil { - fmt.Fprintf(cli.Out(), "Warning: failed to get default registry endpoint from daemon (%v). Using system default: %s\n", err, serverAddress) - } else { - serverAddress = info.IndexServerAddress - } - return serverAddress -} - -// EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload -func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) { - buf, err := json.Marshal(authConfig) - if err != nil { - return "", err - } - return base64.URLEncoding.EncodeToString(buf), nil -} - -// RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info -// for the given command. -func RegistryAuthenticationPrivilegedFunc(cli *DockerCli, index *registrytypes.IndexInfo, cmdName string) types.RequestPrivilegeFunc { - return func() (string, error) { - fmt.Fprintf(cli.Out(), "\nPlease login prior to %s:\n", cmdName) - indexServer := registry.GetAuthConfigKey(index) - isDefaultRegistry := indexServer == ElectAuthServer(context.Background(), cli) - authConfig, err := ConfigureAuth(cli, "", "", indexServer, isDefaultRegistry) - if err != nil { - return "", err - } - return EncodeAuthToBase64(authConfig) - } -} - -// ResolveAuthConfig is like registry.ResolveAuthConfig, but if using the -// default index, it uses the default index name for the daemon's platform, -// not the client's platform. -func ResolveAuthConfig(ctx context.Context, cli *DockerCli, index *registrytypes.IndexInfo) types.AuthConfig { - configKey := index.Name - if index.Official { - configKey = ElectAuthServer(ctx, cli) - } - - a, _ := cli.CredentialsStore(configKey).Get(configKey) - return a -} - -// ConfigureAuth returns an AuthConfig from the specified user, password and server. -func ConfigureAuth(cli *DockerCli, flUser, flPassword, serverAddress string, isDefaultRegistry bool) (types.AuthConfig, error) { - // On Windows, force the use of the regular OS stdin stream. Fixes #14336/#14210 - if runtime.GOOS == "windows" { - cli.in = NewInStream(os.Stdin) - } - - if !isDefaultRegistry { - serverAddress = registry.ConvertToHostname(serverAddress) - } - - authconfig, err := cli.CredentialsStore(serverAddress).Get(serverAddress) - if err != nil { - return authconfig, err - } - - // Some links documenting this: - // - https://code.google.com/archive/p/mintty/issues/56 - // - https://github.com/docker/docker/issues/15272 - // - https://mintty.github.io/ (compatibility) - // Linux will hit this if you attempt `cat | docker login`, and Windows - // will hit this if you attempt docker login from mintty where stdin - // is a pipe, not a character based console. - if flPassword == "" && !cli.In().IsTerminal() { - return authconfig, fmt.Errorf("Error: Cannot perform an interactive login from a non TTY device") - } - - authconfig.Username = strings.TrimSpace(authconfig.Username) - - if flUser = strings.TrimSpace(flUser); flUser == "" { - if isDefaultRegistry { - // if this is a default registry (docker hub), then display the following message. - fmt.Fprintln(cli.Out(), "Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.") - } - promptWithDefault(cli.Out(), "Username", authconfig.Username) - flUser = readInput(cli.In(), cli.Out()) - flUser = strings.TrimSpace(flUser) - if flUser == "" { - flUser = authconfig.Username - } - } - if flUser == "" { - return authconfig, fmt.Errorf("Error: Non-null Username Required") - } - if flPassword == "" { - oldState, err := term.SaveState(cli.In().FD()) - if err != nil { - return authconfig, err - } - fmt.Fprintf(cli.Out(), "Password: ") - term.DisableEcho(cli.In().FD(), oldState) - - flPassword = readInput(cli.In(), cli.Out()) - fmt.Fprint(cli.Out(), "\n") - - term.RestoreTerminal(cli.In().FD(), oldState) - if flPassword == "" { - return authconfig, fmt.Errorf("Error: Password Required") - } - } - - authconfig.Username = flUser - authconfig.Password = flPassword - authconfig.ServerAddress = serverAddress - authconfig.IdentityToken = "" - - return authconfig, nil -} - -func readInput(in io.Reader, out io.Writer) string { - reader := bufio.NewReader(in) - line, _, err := reader.ReadLine() - if err != nil { - fmt.Fprintln(out, err.Error()) - os.Exit(1) - } - return string(line) -} - -func promptWithDefault(out io.Writer, prompt string, configDefault string) { - if configDefault == "" { - fmt.Fprintf(out, "%s: ", prompt) - } else { - fmt.Fprintf(out, "%s (%s): ", prompt, configDefault) - } -} - -// RetrieveAuthTokenFromImage retrieves an encoded auth token given a complete image -func RetrieveAuthTokenFromImage(ctx context.Context, cli *DockerCli, image string) (string, error) { - // Retrieve encoded auth token from the image reference - authConfig, err := resolveAuthConfigFromImage(ctx, cli, image) - if err != nil { - return "", err - } - encodedAuth, err := EncodeAuthToBase64(authConfig) - if err != nil { - return "", err - } - return encodedAuth, nil -} - -// resolveAuthConfigFromImage retrieves that AuthConfig using the image string -func resolveAuthConfigFromImage(ctx context.Context, cli *DockerCli, image string) (types.AuthConfig, error) { - registryRef, err := reference.ParseNamed(image) - if err != nil { - return types.AuthConfig{}, err - } - repoInfo, err := registry.ParseRepositoryInfo(registryRef) - if err != nil { - return types.AuthConfig{}, err - } - return ResolveAuthConfig(ctx, cli, repoInfo.Index), nil -} diff --git a/vendor/github.com/docker/docker/cli/command/registry/login.go b/vendor/github.com/docker/docker/cli/command/registry/login.go deleted file mode 100644 index 05b3bb0..0000000 --- a/vendor/github.com/docker/docker/cli/command/registry/login.go +++ /dev/null @@ -1,85 +0,0 @@ -package registry - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type loginOptions struct { - serverAddress string - user string - password string - email string -} - -// NewLoginCommand creates a new `docker login` command -func NewLoginCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts loginOptions - - cmd := &cobra.Command{ - Use: "login [OPTIONS] [SERVER]", - Short: "Log in to a Docker registry", - Long: "Log in to a Docker registry.\nIf no server is specified, the default is defined by the daemon.", - Args: cli.RequiresMaxArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) > 0 { - opts.serverAddress = args[0] - } - return runLogin(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.StringVarP(&opts.user, "username", "u", "", "Username") - flags.StringVarP(&opts.password, "password", "p", "", "Password") - - // Deprecated in 1.11: Should be removed in docker 1.14 - flags.StringVarP(&opts.email, "email", "e", "", "Email") - flags.MarkDeprecated("email", "will be removed in 1.14.") - - return cmd -} - -func runLogin(dockerCli *command.DockerCli, opts loginOptions) error { - ctx := context.Background() - clnt := dockerCli.Client() - - var ( - serverAddress string - authServer = command.ElectAuthServer(ctx, dockerCli) - ) - if opts.serverAddress != "" { - serverAddress = opts.serverAddress - } else { - serverAddress = authServer - } - - isDefaultRegistry := serverAddress == authServer - - authConfig, err := command.ConfigureAuth(dockerCli, opts.user, opts.password, serverAddress, isDefaultRegistry) - if err != nil { - return err - } - response, err := clnt.RegistryLogin(ctx, authConfig) - if err != nil { - return err - } - if response.IdentityToken != "" { - authConfig.Password = "" - authConfig.IdentityToken = response.IdentityToken - } - if err := dockerCli.CredentialsStore(serverAddress).Store(authConfig); err != nil { - return fmt.Errorf("Error saving credentials: %v", err) - } - - if response.Status != "" { - fmt.Fprintln(dockerCli.Out(), response.Status) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/registry/logout.go b/vendor/github.com/docker/docker/cli/command/registry/logout.go deleted file mode 100644 index 877e60e..0000000 --- a/vendor/github.com/docker/docker/cli/command/registry/logout.go +++ /dev/null @@ -1,77 +0,0 @@ -package registry - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/registry" - "github.com/spf13/cobra" -) - -// NewLogoutCommand creates a new `docker login` command -func NewLogoutCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "logout [SERVER]", - Short: "Log out from a Docker registry", - Long: "Log out from a Docker registry.\nIf no server is specified, the default is defined by the daemon.", - Args: cli.RequiresMaxArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - var serverAddress string - if len(args) > 0 { - serverAddress = args[0] - } - return runLogout(dockerCli, serverAddress) - }, - } - - return cmd -} - -func runLogout(dockerCli *command.DockerCli, serverAddress string) error { - ctx := context.Background() - var isDefaultRegistry bool - - if serverAddress == "" { - serverAddress = command.ElectAuthServer(ctx, dockerCli) - isDefaultRegistry = true - } - - var ( - loggedIn bool - regsToLogout []string - hostnameAddress = serverAddress - regsToTry = []string{serverAddress} - ) - if !isDefaultRegistry { - hostnameAddress = registry.ConvertToHostname(serverAddress) - // the tries below are kept for backward compatibility where a user could have - // saved the registry in one of the following format. - regsToTry = append(regsToTry, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress) - } - - // check if we're logged in based on the records in the config file - // which means it couldn't have user/pass cause they may be in the creds store - for _, s := range regsToTry { - if _, ok := dockerCli.ConfigFile().AuthConfigs[s]; ok { - loggedIn = true - regsToLogout = append(regsToLogout, s) - } - } - - if !loggedIn { - fmt.Fprintf(dockerCli.Out(), "Not logged in to %s\n", hostnameAddress) - return nil - } - - fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress) - for _, r := range regsToLogout { - if err := dockerCli.CredentialsStore(r).Erase(r); err != nil { - fmt.Fprintf(dockerCli.Err(), "WARNING: could not erase credentials: %v\n", err) - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/registry/search.go b/vendor/github.com/docker/docker/cli/command/registry/search.go deleted file mode 100644 index 124b4ae..0000000 --- a/vendor/github.com/docker/docker/cli/command/registry/search.go +++ /dev/null @@ -1,126 +0,0 @@ -package registry - -import ( - "fmt" - "sort" - "strings" - "text/tabwriter" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/stringutils" - "github.com/docker/docker/registry" - "github.com/spf13/cobra" -) - -type searchOptions struct { - term string - noTrunc bool - limit int - filter opts.FilterOpt - - // Deprecated - stars uint - automated bool -} - -// NewSearchCommand creates a new `docker search` command -func NewSearchCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := searchOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "search [OPTIONS] TERM", - Short: "Search the Docker Hub for images", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.term = args[0] - return runSearch(dockerCli, opts) - }, - } - - flags := cmd.Flags() - - flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") - flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") - flags.IntVar(&opts.limit, "limit", registry.DefaultSearchLimit, "Max number of search results") - - flags.BoolVar(&opts.automated, "automated", false, "Only show automated builds") - flags.UintVarP(&opts.stars, "stars", "s", 0, "Only displays with at least x stars") - - flags.MarkDeprecated("automated", "use --filter=automated=true instead") - flags.MarkDeprecated("stars", "use --filter=stars=3 instead") - - return cmd -} - -func runSearch(dockerCli *command.DockerCli, opts searchOptions) error { - indexInfo, err := registry.ParseSearchIndexInfo(opts.term) - if err != nil { - return err - } - - ctx := context.Background() - - authConfig := command.ResolveAuthConfig(ctx, dockerCli, indexInfo) - requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, indexInfo, "search") - - encodedAuth, err := command.EncodeAuthToBase64(authConfig) - if err != nil { - return err - } - - options := types.ImageSearchOptions{ - RegistryAuth: encodedAuth, - PrivilegeFunc: requestPrivilege, - Filters: opts.filter.Value(), - Limit: opts.limit, - } - - clnt := dockerCli.Client() - - unorderedResults, err := clnt.ImageSearch(ctx, opts.term, options) - if err != nil { - return err - } - - results := searchResultsByStars(unorderedResults) - sort.Sort(results) - - w := tabwriter.NewWriter(dockerCli.Out(), 10, 1, 3, ' ', 0) - fmt.Fprintf(w, "NAME\tDESCRIPTION\tSTARS\tOFFICIAL\tAUTOMATED\n") - for _, res := range results { - // --automated and -s, --stars are deprecated since Docker 1.12 - if (opts.automated && !res.IsAutomated) || (int(opts.stars) > res.StarCount) { - continue - } - desc := strings.Replace(res.Description, "\n", " ", -1) - desc = strings.Replace(desc, "\r", " ", -1) - if !opts.noTrunc { - desc = stringutils.Ellipsis(desc, 45) - } - fmt.Fprintf(w, "%s\t%s\t%d\t", res.Name, desc, res.StarCount) - if res.IsOfficial { - fmt.Fprint(w, "[OK]") - - } - fmt.Fprint(w, "\t") - if res.IsAutomated { - fmt.Fprint(w, "[OK]") - } - fmt.Fprint(w, "\n") - } - w.Flush() - return nil -} - -// SearchResultsByStars sorts search results in descending order by number of stars. -type searchResultsByStars []registrytypes.SearchResult - -func (r searchResultsByStars) Len() int { return len(r) } -func (r searchResultsByStars) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r searchResultsByStars) Less(i, j int) bool { return r[j].StarCount < r[i].StarCount } diff --git a/vendor/github.com/docker/docker/cli/command/secret/cmd.go b/vendor/github.com/docker/docker/cli/command/secret/cmd.go deleted file mode 100644 index 79e6698..0000000 --- a/vendor/github.com/docker/docker/cli/command/secret/cmd.go +++ /dev/null @@ -1,25 +0,0 @@ -package secret - -import ( - "github.com/spf13/cobra" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" -) - -// NewSecretCommand returns a cobra command for `secret` subcommands -func NewSecretCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "secret", - Short: "Manage Docker secrets", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - } - cmd.AddCommand( - newSecretListCommand(dockerCli), - newSecretCreateCommand(dockerCli), - newSecretInspectCommand(dockerCli), - newSecretRemoveCommand(dockerCli), - ) - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/secret/create.go b/vendor/github.com/docker/docker/cli/command/secret/create.go deleted file mode 100644 index f4683a6..0000000 --- a/vendor/github.com/docker/docker/cli/command/secret/create.go +++ /dev/null @@ -1,79 +0,0 @@ -package secret - -import ( - "fmt" - "io" - "io/ioutil" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/system" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type createOptions struct { - name string - file string - labels opts.ListOpts -} - -func newSecretCreateCommand(dockerCli *command.DockerCli) *cobra.Command { - createOpts := createOptions{ - labels: opts.NewListOpts(runconfigopts.ValidateEnv), - } - - cmd := &cobra.Command{ - Use: "create [OPTIONS] SECRET file|-", - Short: "Create a secret from a file or STDIN as content", - Args: cli.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - createOpts.name = args[0] - createOpts.file = args[1] - return runSecretCreate(dockerCli, createOpts) - }, - } - flags := cmd.Flags() - flags.VarP(&createOpts.labels, "label", "l", "Secret labels") - - return cmd -} - -func runSecretCreate(dockerCli *command.DockerCli, options createOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - var in io.Reader = dockerCli.In() - if options.file != "-" { - file, err := system.OpenSequential(options.file) - if err != nil { - return err - } - in = file - defer file.Close() - } - - secretData, err := ioutil.ReadAll(in) - if err != nil { - return fmt.Errorf("Error reading content from %q: %v", options.file, err) - } - - spec := swarm.SecretSpec{ - Annotations: swarm.Annotations{ - Name: options.name, - Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()), - }, - Data: secretData, - } - - r, err := client.SecretCreate(ctx, spec) - if err != nil { - return err - } - - fmt.Fprintln(dockerCli.Out(), r.ID) - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/secret/inspect.go b/vendor/github.com/docker/docker/cli/command/secret/inspect.go deleted file mode 100644 index 0a8bd4a..0000000 --- a/vendor/github.com/docker/docker/cli/command/secret/inspect.go +++ /dev/null @@ -1,45 +0,0 @@ -package secret - -import ( - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/inspect" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type inspectOptions struct { - names []string - format string -} - -func newSecretInspectCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := inspectOptions{} - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] SECRET [SECRET...]", - Short: "Display detailed information on one or more secrets", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.names = args - return runSecretInspect(dockerCli, opts) - }, - } - - cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - return cmd -} - -func runSecretInspect(dockerCli *command.DockerCli, opts inspectOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - ids, err := getCliRequestedSecretIDs(ctx, client, opts.names) - if err != nil { - return err - } - getRef := func(id string) (interface{}, []byte, error) { - return client.SecretInspectWithRaw(ctx, id) - } - - return inspect.Inspect(dockerCli.Out(), ids, opts.format, getRef) -} diff --git a/vendor/github.com/docker/docker/cli/command/secret/ls.go b/vendor/github.com/docker/docker/cli/command/secret/ls.go deleted file mode 100644 index faeab31..0000000 --- a/vendor/github.com/docker/docker/cli/command/secret/ls.go +++ /dev/null @@ -1,68 +0,0 @@ -package secret - -import ( - "fmt" - "text/tabwriter" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/go-units" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type listOptions struct { - quiet bool -} - -func newSecretListCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := listOptions{} - - cmd := &cobra.Command{ - Use: "ls [OPTIONS]", - Aliases: []string{"list"}, - Short: "List secrets", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runSecretList(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") - - return cmd -} - -func runSecretList(dockerCli *command.DockerCli, opts listOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - secrets, err := client.SecretList(ctx, types.SecretListOptions{}) - if err != nil { - return err - } - - w := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 3, ' ', 0) - if opts.quiet { - for _, s := range secrets { - fmt.Fprintf(w, "%s\n", s.ID) - } - } else { - fmt.Fprintf(w, "ID\tNAME\tCREATED\tUPDATED") - fmt.Fprintf(w, "\n") - - for _, s := range secrets { - created := units.HumanDuration(time.Now().UTC().Sub(s.Meta.CreatedAt)) + " ago" - updated := units.HumanDuration(time.Now().UTC().Sub(s.Meta.UpdatedAt)) + " ago" - - fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", s.ID, s.Spec.Annotations.Name, created, updated) - } - } - - w.Flush() - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/secret/remove.go b/vendor/github.com/docker/docker/cli/command/secret/remove.go deleted file mode 100644 index f45a619..0000000 --- a/vendor/github.com/docker/docker/cli/command/secret/remove.go +++ /dev/null @@ -1,57 +0,0 @@ -package secret - -import ( - "fmt" - "strings" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type removeOptions struct { - names []string -} - -func newSecretRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { - return &cobra.Command{ - Use: "rm SECRET [SECRET...]", - Aliases: []string{"remove"}, - Short: "Remove one or more secrets", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts := removeOptions{ - names: args, - } - return runSecretRemove(dockerCli, opts) - }, - } -} - -func runSecretRemove(dockerCli *command.DockerCli, opts removeOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - ids, err := getCliRequestedSecretIDs(ctx, client, opts.names) - if err != nil { - return err - } - - var errs []string - - for _, id := range ids { - if err := client.SecretRemove(ctx, id); err != nil { - errs = append(errs, err.Error()) - continue - } - - fmt.Fprintln(dockerCli.Out(), id) - } - - if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, "\n")) - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/secret/utils.go b/vendor/github.com/docker/docker/cli/command/secret/utils.go deleted file mode 100644 index 11d31ff..0000000 --- a/vendor/github.com/docker/docker/cli/command/secret/utils.go +++ /dev/null @@ -1,76 +0,0 @@ -package secret - -import ( - "fmt" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/client" - "golang.org/x/net/context" -) - -// GetSecretsByNameOrIDPrefixes returns secrets given a list of ids or names -func GetSecretsByNameOrIDPrefixes(ctx context.Context, client client.APIClient, terms []string) ([]swarm.Secret, error) { - args := filters.NewArgs() - for _, n := range terms { - args.Add("names", n) - args.Add("id", n) - } - - return client.SecretList(ctx, types.SecretListOptions{ - Filters: args, - }) -} - -func getCliRequestedSecretIDs(ctx context.Context, client client.APIClient, terms []string) ([]string, error) { - secrets, err := GetSecretsByNameOrIDPrefixes(ctx, client, terms) - if err != nil { - return nil, err - } - - if len(secrets) > 0 { - found := make(map[string]struct{}) - next: - for _, term := range terms { - // attempt to lookup secret by full ID - for _, s := range secrets { - if s.ID == term { - found[s.ID] = struct{}{} - continue next - } - } - // attempt to lookup secret by full name - for _, s := range secrets { - if s.Spec.Annotations.Name == term { - found[s.ID] = struct{}{} - continue next - } - } - // attempt to lookup secret by partial ID (prefix) - // return error if more than one matches found (ambiguous) - n := 0 - for _, s := range secrets { - if strings.HasPrefix(s.ID, term) { - found[s.ID] = struct{}{} - n++ - } - } - if n > 1 { - return nil, fmt.Errorf("secret %s is ambiguous (%d matches found)", term, n) - } - } - - // We already collected all the IDs found. - // Now we will remove duplicates by converting the map to slice - ids := []string{} - for id := range found { - ids = append(ids, id) - } - - return ids, nil - } - - return terms, nil -} diff --git a/vendor/github.com/docker/docker/cli/command/service/cmd.go b/vendor/github.com/docker/docker/cli/command/service/cmd.go deleted file mode 100644 index 796fe92..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/cmd.go +++ /dev/null @@ -1,29 +0,0 @@ -package service - -import ( - "github.com/spf13/cobra" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" -) - -// NewServiceCommand returns a cobra command for `service` subcommands -func NewServiceCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "service", - Short: "Manage services", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - } - cmd.AddCommand( - newCreateCommand(dockerCli), - newInspectCommand(dockerCli), - newPsCommand(dockerCli), - newListCommand(dockerCli), - newRemoveCommand(dockerCli), - newScaleCommand(dockerCli), - newUpdateCommand(dockerCli), - newLogsCommand(dockerCli), - ) - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/service/create.go b/vendor/github.com/docker/docker/cli/command/service/create.go deleted file mode 100644 index 1355c19..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/create.go +++ /dev/null @@ -1,100 +0,0 @@ -package service - -import ( - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := newServiceOptions() - - cmd := &cobra.Command{ - Use: "create [OPTIONS] IMAGE [COMMAND] [ARG...]", - Short: "Create a new service", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.image = args[0] - if len(args) > 1 { - opts.args = args[1:] - } - return runCreate(dockerCli, opts) - }, - } - flags := cmd.Flags() - flags.StringVar(&opts.mode, flagMode, "replicated", "Service mode (replicated or global)") - flags.StringVar(&opts.name, flagName, "", "Service name") - - addServiceFlags(cmd, opts) - - flags.VarP(&opts.labels, flagLabel, "l", "Service labels") - flags.Var(&opts.containerLabels, flagContainerLabel, "Container labels") - flags.VarP(&opts.env, flagEnv, "e", "Set environment variables") - flags.Var(&opts.envFile, flagEnvFile, "Read in a file of environment variables") - flags.Var(&opts.mounts, flagMount, "Attach a filesystem mount to the service") - flags.Var(&opts.constraints, flagConstraint, "Placement constraints") - flags.Var(&opts.networks, flagNetwork, "Network attachments") - flags.Var(&opts.secrets, flagSecret, "Specify secrets to expose to the service") - flags.VarP(&opts.endpoint.publishPorts, flagPublish, "p", "Publish a port as a node port") - flags.Var(&opts.groups, flagGroup, "Set one or more supplementary user groups for the container") - flags.Var(&opts.dns, flagDNS, "Set custom DNS servers") - flags.Var(&opts.dnsOption, flagDNSOption, "Set DNS options") - flags.Var(&opts.dnsSearch, flagDNSSearch, "Set custom DNS search domains") - flags.Var(&opts.hosts, flagHost, "Set one or more custom host-to-IP mappings (host:ip)") - - flags.SetInterspersed(false) - return cmd -} - -func runCreate(dockerCli *command.DockerCli, opts *serviceOptions) error { - apiClient := dockerCli.Client() - createOpts := types.ServiceCreateOptions{} - - service, err := opts.ToService() - if err != nil { - return err - } - - specifiedSecrets := opts.secrets.Value() - if len(specifiedSecrets) > 0 { - // parse and validate secrets - secrets, err := ParseSecrets(apiClient, specifiedSecrets) - if err != nil { - return err - } - service.TaskTemplate.ContainerSpec.Secrets = secrets - - } - - ctx := context.Background() - - if err := resolveServiceImageDigest(dockerCli, &service); err != nil { - return err - } - - // only send auth if flag was set - if opts.registryAuth { - // Retrieve encoded auth token from the image reference - encodedAuth, err := command.RetrieveAuthTokenFromImage(ctx, dockerCli, opts.image) - if err != nil { - return err - } - createOpts.EncodedRegistryAuth = encodedAuth - } - - response, err := apiClient.ServiceCreate(ctx, service, createOpts) - if err != nil { - return err - } - - for _, warning := range response.Warnings { - fmt.Fprintln(dockerCli.Err(), warning) - } - - fmt.Fprintf(dockerCli.Out(), "%s\n", response.ID) - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/service/inspect.go b/vendor/github.com/docker/docker/cli/command/service/inspect.go deleted file mode 100644 index deb701b..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/inspect.go +++ /dev/null @@ -1,84 +0,0 @@ -package service - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/formatter" - apiclient "github.com/docker/docker/client" - "github.com/spf13/cobra" -) - -type inspectOptions struct { - refs []string - format string - pretty bool -} - -func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts inspectOptions - - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] SERVICE [SERVICE...]", - Short: "Display detailed information on one or more services", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.refs = args - - if opts.pretty && len(opts.format) > 0 { - return fmt.Errorf("--format is incompatible with human friendly format") - } - return runInspect(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - flags.BoolVar(&opts.pretty, "pretty", false, "Print the information in a human friendly format.") - return cmd -} - -func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - if opts.pretty { - opts.format = "pretty" - } - - getRef := func(ref string) (interface{}, []byte, error) { - service, _, err := client.ServiceInspectWithRaw(ctx, ref) - if err == nil || !apiclient.IsErrServiceNotFound(err) { - return service, nil, err - } - return nil, nil, fmt.Errorf("Error: no such service: %s", ref) - } - - f := opts.format - if len(f) == 0 { - f = "raw" - if len(dockerCli.ConfigFile().ServiceInspectFormat) > 0 { - f = dockerCli.ConfigFile().ServiceInspectFormat - } - } - - // check if the user is trying to apply a template to the pretty format, which - // is not supported - if strings.HasPrefix(f, "pretty") && f != "pretty" { - return fmt.Errorf("Cannot supply extra formatting options to the pretty template") - } - - serviceCtx := formatter.Context{ - Output: dockerCli.Out(), - Format: formatter.NewServiceFormat(f), - } - - if err := formatter.ServiceInspectWrite(serviceCtx, opts.refs, getRef); err != nil { - return cli.StatusError{StatusCode: 1, Status: err.Error()} - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/service/inspect_test.go b/vendor/github.com/docker/docker/cli/command/service/inspect_test.go deleted file mode 100644 index 04a6508..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/inspect_test.go +++ /dev/null @@ -1,129 +0,0 @@ -package service - -import ( - "bytes" - "encoding/json" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli/command/formatter" - "github.com/docker/docker/pkg/testutil/assert" -) - -func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time) string { - b := new(bytes.Buffer) - - endpointSpec := &swarm.EndpointSpec{ - Mode: "vip", - Ports: []swarm.PortConfig{ - { - Protocol: swarm.PortConfigProtocolTCP, - TargetPort: 5000, - }, - }, - } - - two := uint64(2) - - s := swarm.Service{ - ID: "de179gar9d0o7ltdybungplod", - Meta: swarm.Meta{ - Version: swarm.Version{Index: 315}, - CreatedAt: now, - UpdatedAt: now, - }, - Spec: swarm.ServiceSpec{ - Annotations: swarm.Annotations{ - Name: "my_service", - Labels: map[string]string{"com.label": "foo"}, - }, - TaskTemplate: swarm.TaskSpec{ - ContainerSpec: swarm.ContainerSpec{ - Image: "foo/bar@sha256:this_is_a_test", - }, - }, - Mode: swarm.ServiceMode{ - Replicated: &swarm.ReplicatedService{ - Replicas: &two, - }, - }, - UpdateConfig: nil, - Networks: []swarm.NetworkAttachmentConfig{ - { - Target: "5vpyomhb6ievnk0i0o60gcnei", - Aliases: []string{"web"}, - }, - }, - EndpointSpec: endpointSpec, - }, - Endpoint: swarm.Endpoint{ - Spec: *endpointSpec, - Ports: []swarm.PortConfig{ - { - Protocol: swarm.PortConfigProtocolTCP, - TargetPort: 5000, - PublishedPort: 30000, - }, - }, - VirtualIPs: []swarm.EndpointVirtualIP{ - { - NetworkID: "6o4107cj2jx9tihgb0jyts6pj", - Addr: "10.255.0.4/16", - }, - }, - }, - UpdateStatus: swarm.UpdateStatus{ - StartedAt: now, - CompletedAt: now, - }, - } - - ctx := formatter.Context{ - Output: b, - Format: format, - } - - err := formatter.ServiceInspectWrite(ctx, []string{"de179gar9d0o7ltdybungplod"}, func(ref string) (interface{}, []byte, error) { - return s, nil, nil - }) - if err != nil { - t.Fatal(err) - } - return b.String() -} - -func TestPrettyPrintWithNoUpdateConfig(t *testing.T) { - s := formatServiceInspect(t, formatter.NewServiceFormat("pretty"), time.Now()) - if strings.Contains(s, "UpdateStatus") { - t.Fatal("Pretty print failed before parsing UpdateStatus") - } -} - -func TestJSONFormatWithNoUpdateConfig(t *testing.T) { - now := time.Now() - // s1: [{"ID":..}] - // s2: {"ID":..} - s1 := formatServiceInspect(t, formatter.NewServiceFormat(""), now) - t.Log("// s1") - t.Logf("%s", s1) - s2 := formatServiceInspect(t, formatter.NewServiceFormat("{{json .}}"), now) - t.Log("// s2") - t.Logf("%s", s2) - var m1Wrap []map[string]interface{} - if err := json.Unmarshal([]byte(s1), &m1Wrap); err != nil { - t.Fatal(err) - } - if len(m1Wrap) != 1 { - t.Fatalf("strange s1=%s", s1) - } - m1 := m1Wrap[0] - t.Logf("m1=%+v", m1) - var m2 map[string]interface{} - if err := json.Unmarshal([]byte(s2), &m2); err != nil { - t.Fatal(err) - } - t.Logf("m2=%+v", m2) - assert.DeepEqual(t, m2, m1) -} diff --git a/vendor/github.com/docker/docker/cli/command/service/list.go b/vendor/github.com/docker/docker/cli/command/service/list.go deleted file mode 100644 index 7241260..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/list.go +++ /dev/null @@ -1,158 +0,0 @@ -package service - -import ( - "fmt" - "io" - "text/tabwriter" - - distreference "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/stringid" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -const ( - listItemFmt = "%s\t%s\t%s\t%s\t%s\n" -) - -type listOptions struct { - quiet bool - filter opts.FilterOpt -} - -func newListCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := listOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "ls [OPTIONS]", - Aliases: []string{"list"}, - Short: "List services", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runList(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") - flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") - - return cmd -} - -func runList(dockerCli *command.DockerCli, opts listOptions) error { - ctx := context.Background() - client := dockerCli.Client() - out := dockerCli.Out() - - services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: opts.filter.Value()}) - if err != nil { - return err - } - - if len(services) > 0 && !opts.quiet { - // only non-empty services and not quiet, should we call TaskList and NodeList api - taskFilter := filters.NewArgs() - for _, service := range services { - taskFilter.Add("service", service.ID) - } - - tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: taskFilter}) - if err != nil { - return err - } - - nodes, err := client.NodeList(ctx, types.NodeListOptions{}) - if err != nil { - return err - } - - PrintNotQuiet(out, services, nodes, tasks) - } else if !opts.quiet { - // no services and not quiet, print only one line with columns ID, NAME, MODE, REPLICAS... - PrintNotQuiet(out, services, []swarm.Node{}, []swarm.Task{}) - } else { - PrintQuiet(out, services) - } - - return nil -} - -// PrintNotQuiet shows service list in a non-quiet way. -// Besides this, command `docker stack services xxx` will call this, too. -func PrintNotQuiet(out io.Writer, services []swarm.Service, nodes []swarm.Node, tasks []swarm.Task) { - activeNodes := make(map[string]struct{}) - for _, n := range nodes { - if n.Status.State != swarm.NodeStateDown { - activeNodes[n.ID] = struct{}{} - } - } - - running := map[string]int{} - tasksNoShutdown := map[string]int{} - - for _, task := range tasks { - if task.DesiredState != swarm.TaskStateShutdown { - tasksNoShutdown[task.ServiceID]++ - } - - if _, nodeActive := activeNodes[task.NodeID]; nodeActive && task.Status.State == swarm.TaskStateRunning { - running[task.ServiceID]++ - } - } - - printTable(out, services, running, tasksNoShutdown) -} - -func printTable(out io.Writer, services []swarm.Service, running, tasksNoShutdown map[string]int) { - writer := tabwriter.NewWriter(out, 0, 4, 2, ' ', 0) - - // Ignore flushing errors - defer writer.Flush() - - fmt.Fprintf(writer, listItemFmt, "ID", "NAME", "MODE", "REPLICAS", "IMAGE") - - for _, service := range services { - mode := "" - replicas := "" - if service.Spec.Mode.Replicated != nil && service.Spec.Mode.Replicated.Replicas != nil { - mode = "replicated" - replicas = fmt.Sprintf("%d/%d", running[service.ID], *service.Spec.Mode.Replicated.Replicas) - } else if service.Spec.Mode.Global != nil { - mode = "global" - replicas = fmt.Sprintf("%d/%d", running[service.ID], tasksNoShutdown[service.ID]) - } - image := service.Spec.TaskTemplate.ContainerSpec.Image - ref, err := distreference.ParseNamed(image) - if err == nil { - // update image string for display - namedTagged, ok := ref.(distreference.NamedTagged) - if ok { - image = namedTagged.Name() + ":" + namedTagged.Tag() - } - } - - fmt.Fprintf( - writer, - listItemFmt, - stringid.TruncateID(service.ID), - service.Spec.Name, - mode, - replicas, - image) - } -} - -// PrintQuiet shows service list in a quiet way. -// Besides this, command `docker stack services xxx` will call this, too. -func PrintQuiet(out io.Writer, services []swarm.Service) { - for _, service := range services { - fmt.Fprintln(out, service.ID) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/service/logs.go b/vendor/github.com/docker/docker/cli/command/service/logs.go deleted file mode 100644 index 19d3d9a..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/logs.go +++ /dev/null @@ -1,163 +0,0 @@ -package service - -import ( - "bytes" - "fmt" - "io" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/idresolver" - "github.com/docker/docker/pkg/stdcopy" - "github.com/spf13/cobra" -) - -type logsOptions struct { - noResolve bool - follow bool - since string - timestamps bool - details bool - tail string - - service string -} - -func newLogsCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts logsOptions - - cmd := &cobra.Command{ - Use: "logs [OPTIONS] SERVICE", - Short: "Fetch the logs of a service", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.service = args[0] - return runLogs(dockerCli, &opts) - }, - Tags: map[string]string{"experimental": ""}, - } - - flags := cmd.Flags() - flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") - flags.BoolVarP(&opts.follow, "follow", "f", false, "Follow log output") - flags.StringVar(&opts.since, "since", "", "Show logs since timestamp") - flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps") - flags.BoolVar(&opts.details, "details", false, "Show extra details provided to logs") - flags.StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs") - return cmd -} - -func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { - ctx := context.Background() - - options := types.ContainerLogsOptions{ - ShowStdout: true, - ShowStderr: true, - Since: opts.since, - Timestamps: opts.timestamps, - Follow: opts.follow, - Tail: opts.tail, - Details: opts.details, - } - - client := dockerCli.Client() - responseBody, err := client.ServiceLogs(ctx, opts.service, options) - if err != nil { - return err - } - defer responseBody.Close() - - resolver := idresolver.New(client, opts.noResolve) - - stdout := &logWriter{ctx: ctx, opts: opts, r: resolver, w: dockerCli.Out()} - stderr := &logWriter{ctx: ctx, opts: opts, r: resolver, w: dockerCli.Err()} - - // TODO(aluzzardi): Do an io.Copy for services with TTY enabled. - _, err = stdcopy.StdCopy(stdout, stderr, responseBody) - return err -} - -type logWriter struct { - ctx context.Context - opts *logsOptions - r *idresolver.IDResolver - w io.Writer -} - -func (lw *logWriter) Write(buf []byte) (int, error) { - contextIndex := 0 - numParts := 2 - if lw.opts.timestamps { - contextIndex++ - numParts++ - } - - parts := bytes.SplitN(buf, []byte(" "), numParts) - if len(parts) != numParts { - return 0, fmt.Errorf("invalid context in log message: %v", string(buf)) - } - - taskName, nodeName, err := lw.parseContext(string(parts[contextIndex])) - if err != nil { - return 0, err - } - - output := []byte{} - for i, part := range parts { - // First part doesn't get space separation. - if i > 0 { - output = append(output, []byte(" ")...) - } - - if i == contextIndex { - // TODO(aluzzardi): Consider constant padding. - output = append(output, []byte(fmt.Sprintf("%s@%s |", taskName, nodeName))...) - } else { - output = append(output, part...) - } - } - _, err = lw.w.Write(output) - if err != nil { - return 0, err - } - - return len(buf), nil -} - -func (lw *logWriter) parseContext(input string) (string, string, error) { - context := make(map[string]string) - - components := strings.Split(input, ",") - for _, component := range components { - parts := strings.SplitN(component, "=", 2) - if len(parts) != 2 { - return "", "", fmt.Errorf("invalid context: %s", input) - } - context[parts[0]] = parts[1] - } - - taskID, ok := context["com.docker.swarm.task.id"] - if !ok { - return "", "", fmt.Errorf("missing task id in context: %s", input) - } - taskName, err := lw.r.Resolve(lw.ctx, swarm.Task{}, taskID) - if err != nil { - return "", "", err - } - - nodeID, ok := context["com.docker.swarm.node.id"] - if !ok { - return "", "", fmt.Errorf("missing node id in context: %s", input) - } - nodeName, err := lw.r.Resolve(lw.ctx, swarm.Node{}, nodeID) - if err != nil { - return "", "", err - } - - return taskName, nodeName, nil -} diff --git a/vendor/github.com/docker/docker/cli/command/service/opts.go b/vendor/github.com/docker/docker/cli/command/service/opts.go deleted file mode 100644 index cbe544a..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/opts.go +++ /dev/null @@ -1,648 +0,0 @@ -package service - -import ( - "encoding/csv" - "fmt" - "os" - "path/filepath" - "strconv" - "strings" - "time" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/opts" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/docker/go-connections/nat" - units "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type int64Value interface { - Value() int64 -} - -type memBytes int64 - -func (m *memBytes) String() string { - return units.BytesSize(float64(m.Value())) -} - -func (m *memBytes) Set(value string) error { - val, err := units.RAMInBytes(value) - *m = memBytes(val) - return err -} - -func (m *memBytes) Type() string { - return "bytes" -} - -func (m *memBytes) Value() int64 { - return int64(*m) -} - -// PositiveDurationOpt is an option type for time.Duration that uses a pointer. -// It bahave similarly to DurationOpt but only allows positive duration values. -type PositiveDurationOpt struct { - DurationOpt -} - -// Set a new value on the option. Setting a negative duration value will cause -// an error to be returned. -func (d *PositiveDurationOpt) Set(s string) error { - err := d.DurationOpt.Set(s) - if err != nil { - return err - } - if *d.DurationOpt.value < 0 { - return fmt.Errorf("duration cannot be negative") - } - return nil -} - -// DurationOpt is an option type for time.Duration that uses a pointer. This -// allows us to get nil values outside, instead of defaulting to 0 -type DurationOpt struct { - value *time.Duration -} - -// Set a new value on the option -func (d *DurationOpt) Set(s string) error { - v, err := time.ParseDuration(s) - d.value = &v - return err -} - -// Type returns the type of this option, which will be displayed in `--help` output -func (d *DurationOpt) Type() string { - return "duration" -} - -// String returns a string repr of this option -func (d *DurationOpt) String() string { - if d.value != nil { - return d.value.String() - } - return "" -} - -// Value returns the time.Duration -func (d *DurationOpt) Value() *time.Duration { - return d.value -} - -// Uint64Opt represents a uint64. -type Uint64Opt struct { - value *uint64 -} - -// Set a new value on the option -func (i *Uint64Opt) Set(s string) error { - v, err := strconv.ParseUint(s, 0, 64) - i.value = &v - return err -} - -// Type returns the type of this option, which will be displayed in `--help` output -func (i *Uint64Opt) Type() string { - return "uint" -} - -// String returns a string repr of this option -func (i *Uint64Opt) String() string { - if i.value != nil { - return fmt.Sprintf("%v", *i.value) - } - return "" -} - -// Value returns the uint64 -func (i *Uint64Opt) Value() *uint64 { - return i.value -} - -type floatValue float32 - -func (f *floatValue) Set(s string) error { - v, err := strconv.ParseFloat(s, 32) - *f = floatValue(v) - return err -} - -func (f *floatValue) Type() string { - return "float" -} - -func (f *floatValue) String() string { - return strconv.FormatFloat(float64(*f), 'g', -1, 32) -} - -func (f *floatValue) Value() float32 { - return float32(*f) -} - -// SecretRequestSpec is a type for requesting secrets -type SecretRequestSpec struct { - source string - target string - uid string - gid string - mode os.FileMode -} - -// SecretOpt is a Value type for parsing secrets -type SecretOpt struct { - values []*SecretRequestSpec -} - -// Set a new secret value -func (o *SecretOpt) Set(value string) error { - csvReader := csv.NewReader(strings.NewReader(value)) - fields, err := csvReader.Read() - if err != nil { - return err - } - - spec := &SecretRequestSpec{ - source: "", - target: "", - uid: "0", - gid: "0", - mode: 0444, - } - - for _, field := range fields { - parts := strings.SplitN(field, "=", 2) - key := strings.ToLower(parts[0]) - - if len(parts) != 2 { - return fmt.Errorf("invalid field '%s' must be a key=value pair", field) - } - - value := parts[1] - switch key { - case "source", "src": - spec.source = value - case "target": - tDir, _ := filepath.Split(value) - if tDir != "" { - return fmt.Errorf("target must not have a path") - } - spec.target = value - case "uid": - spec.uid = value - case "gid": - spec.gid = value - case "mode": - m, err := strconv.ParseUint(value, 0, 32) - if err != nil { - return fmt.Errorf("invalid mode specified: %v", err) - } - - spec.mode = os.FileMode(m) - default: - return fmt.Errorf("invalid field in secret request: %s", key) - } - } - - if spec.source == "" { - return fmt.Errorf("source is required") - } - - o.values = append(o.values, spec) - return nil -} - -// Type returns the type of this option -func (o *SecretOpt) Type() string { - return "secret" -} - -// String returns a string repr of this option -func (o *SecretOpt) String() string { - secrets := []string{} - for _, secret := range o.values { - repr := fmt.Sprintf("%s -> %s", secret.source, secret.target) - secrets = append(secrets, repr) - } - return strings.Join(secrets, ", ") -} - -// Value returns the secret requests -func (o *SecretOpt) Value() []*SecretRequestSpec { - return o.values -} - -type updateOptions struct { - parallelism uint64 - delay time.Duration - monitor time.Duration - onFailure string - maxFailureRatio floatValue -} - -type resourceOptions struct { - limitCPU opts.NanoCPUs - limitMemBytes memBytes - resCPU opts.NanoCPUs - resMemBytes memBytes -} - -func (r *resourceOptions) ToResourceRequirements() *swarm.ResourceRequirements { - return &swarm.ResourceRequirements{ - Limits: &swarm.Resources{ - NanoCPUs: r.limitCPU.Value(), - MemoryBytes: r.limitMemBytes.Value(), - }, - Reservations: &swarm.Resources{ - NanoCPUs: r.resCPU.Value(), - MemoryBytes: r.resMemBytes.Value(), - }, - } -} - -type restartPolicyOptions struct { - condition string - delay DurationOpt - maxAttempts Uint64Opt - window DurationOpt -} - -func (r *restartPolicyOptions) ToRestartPolicy() *swarm.RestartPolicy { - return &swarm.RestartPolicy{ - Condition: swarm.RestartPolicyCondition(r.condition), - Delay: r.delay.Value(), - MaxAttempts: r.maxAttempts.Value(), - Window: r.window.Value(), - } -} - -func convertNetworks(networks []string) []swarm.NetworkAttachmentConfig { - nets := []swarm.NetworkAttachmentConfig{} - for _, network := range networks { - nets = append(nets, swarm.NetworkAttachmentConfig{Target: network}) - } - return nets -} - -type endpointOptions struct { - mode string - publishPorts opts.PortOpt -} - -func (e *endpointOptions) ToEndpointSpec() *swarm.EndpointSpec { - return &swarm.EndpointSpec{ - Mode: swarm.ResolutionMode(strings.ToLower(e.mode)), - Ports: e.publishPorts.Value(), - } -} - -type logDriverOptions struct { - name string - opts opts.ListOpts -} - -func newLogDriverOptions() logDriverOptions { - return logDriverOptions{opts: opts.NewListOpts(runconfigopts.ValidateEnv)} -} - -func (ldo *logDriverOptions) toLogDriver() *swarm.Driver { - if ldo.name == "" { - return nil - } - - // set the log driver only if specified. - return &swarm.Driver{ - Name: ldo.name, - Options: runconfigopts.ConvertKVStringsToMap(ldo.opts.GetAll()), - } -} - -type healthCheckOptions struct { - cmd string - interval PositiveDurationOpt - timeout PositiveDurationOpt - retries int - noHealthcheck bool -} - -func (opts *healthCheckOptions) toHealthConfig() (*container.HealthConfig, error) { - var healthConfig *container.HealthConfig - haveHealthSettings := opts.cmd != "" || - opts.interval.Value() != nil || - opts.timeout.Value() != nil || - opts.retries != 0 - if opts.noHealthcheck { - if haveHealthSettings { - return nil, fmt.Errorf("--%s conflicts with --health-* options", flagNoHealthcheck) - } - healthConfig = &container.HealthConfig{Test: []string{"NONE"}} - } else if haveHealthSettings { - var test []string - if opts.cmd != "" { - test = []string{"CMD-SHELL", opts.cmd} - } - var interval, timeout time.Duration - if ptr := opts.interval.Value(); ptr != nil { - interval = *ptr - } - if ptr := opts.timeout.Value(); ptr != nil { - timeout = *ptr - } - healthConfig = &container.HealthConfig{ - Test: test, - Interval: interval, - Timeout: timeout, - Retries: opts.retries, - } - } - return healthConfig, nil -} - -// ValidatePort validates a string is in the expected format for a port definition -func ValidatePort(value string) (string, error) { - portMappings, err := nat.ParsePortSpec(value) - for _, portMapping := range portMappings { - if portMapping.Binding.HostIP != "" { - return "", fmt.Errorf("HostIP is not supported by a service.") - } - } - return value, err -} - -// convertExtraHostsToSwarmHosts converts an array of extra hosts in cli -// : -// into a swarmkit host format: -// IP_address canonical_hostname [aliases...] -// This assumes input value (:) has already been validated -func convertExtraHostsToSwarmHosts(extraHosts []string) []string { - hosts := []string{} - for _, extraHost := range extraHosts { - parts := strings.SplitN(extraHost, ":", 2) - hosts = append(hosts, fmt.Sprintf("%s %s", parts[1], parts[0])) - } - return hosts -} - -type serviceOptions struct { - name string - labels opts.ListOpts - containerLabels opts.ListOpts - image string - args []string - hostname string - env opts.ListOpts - envFile opts.ListOpts - workdir string - user string - groups opts.ListOpts - tty bool - mounts opts.MountOpt - dns opts.ListOpts - dnsSearch opts.ListOpts - dnsOption opts.ListOpts - hosts opts.ListOpts - - resources resourceOptions - stopGrace DurationOpt - - replicas Uint64Opt - mode string - - restartPolicy restartPolicyOptions - constraints opts.ListOpts - update updateOptions - networks opts.ListOpts - endpoint endpointOptions - - registryAuth bool - - logDriver logDriverOptions - - healthcheck healthCheckOptions - secrets opts.SecretOpt -} - -func newServiceOptions() *serviceOptions { - return &serviceOptions{ - labels: opts.NewListOpts(runconfigopts.ValidateEnv), - constraints: opts.NewListOpts(nil), - containerLabels: opts.NewListOpts(runconfigopts.ValidateEnv), - env: opts.NewListOpts(runconfigopts.ValidateEnv), - envFile: opts.NewListOpts(nil), - groups: opts.NewListOpts(nil), - logDriver: newLogDriverOptions(), - dns: opts.NewListOpts(opts.ValidateIPAddress), - dnsOption: opts.NewListOpts(nil), - dnsSearch: opts.NewListOpts(opts.ValidateDNSSearch), - hosts: opts.NewListOpts(runconfigopts.ValidateExtraHost), - networks: opts.NewListOpts(nil), - } -} - -func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) { - var service swarm.ServiceSpec - - envVariables, err := runconfigopts.ReadKVStrings(opts.envFile.GetAll(), opts.env.GetAll()) - if err != nil { - return service, err - } - - currentEnv := make([]string, 0, len(envVariables)) - for _, env := range envVariables { // need to process each var, in order - k := strings.SplitN(env, "=", 2)[0] - for i, current := range currentEnv { // remove duplicates - if current == env { - continue // no update required, may hide this behind flag to preserve order of envVariables - } - if strings.HasPrefix(current, k+"=") { - currentEnv = append(currentEnv[:i], currentEnv[i+1:]...) - } - } - currentEnv = append(currentEnv, env) - } - - service = swarm.ServiceSpec{ - Annotations: swarm.Annotations{ - Name: opts.name, - Labels: runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()), - }, - TaskTemplate: swarm.TaskSpec{ - ContainerSpec: swarm.ContainerSpec{ - Image: opts.image, - Args: opts.args, - Env: currentEnv, - Hostname: opts.hostname, - Labels: runconfigopts.ConvertKVStringsToMap(opts.containerLabels.GetAll()), - Dir: opts.workdir, - User: opts.user, - Groups: opts.groups.GetAll(), - TTY: opts.tty, - Mounts: opts.mounts.Value(), - DNSConfig: &swarm.DNSConfig{ - Nameservers: opts.dns.GetAll(), - Search: opts.dnsSearch.GetAll(), - Options: opts.dnsOption.GetAll(), - }, - Hosts: convertExtraHostsToSwarmHosts(opts.hosts.GetAll()), - StopGracePeriod: opts.stopGrace.Value(), - Secrets: nil, - }, - Networks: convertNetworks(opts.networks.GetAll()), - Resources: opts.resources.ToResourceRequirements(), - RestartPolicy: opts.restartPolicy.ToRestartPolicy(), - Placement: &swarm.Placement{ - Constraints: opts.constraints.GetAll(), - }, - LogDriver: opts.logDriver.toLogDriver(), - }, - Networks: convertNetworks(opts.networks.GetAll()), - Mode: swarm.ServiceMode{}, - UpdateConfig: &swarm.UpdateConfig{ - Parallelism: opts.update.parallelism, - Delay: opts.update.delay, - Monitor: opts.update.monitor, - FailureAction: opts.update.onFailure, - MaxFailureRatio: opts.update.maxFailureRatio.Value(), - }, - EndpointSpec: opts.endpoint.ToEndpointSpec(), - } - - healthConfig, err := opts.healthcheck.toHealthConfig() - if err != nil { - return service, err - } - service.TaskTemplate.ContainerSpec.Healthcheck = healthConfig - - switch opts.mode { - case "global": - if opts.replicas.Value() != nil { - return service, fmt.Errorf("replicas can only be used with replicated mode") - } - - service.Mode.Global = &swarm.GlobalService{} - case "replicated": - service.Mode.Replicated = &swarm.ReplicatedService{ - Replicas: opts.replicas.Value(), - } - default: - return service, fmt.Errorf("Unknown mode: %s", opts.mode) - } - return service, nil -} - -// addServiceFlags adds all flags that are common to both `create` and `update`. -// Any flags that are not common are added separately in the individual command -func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) { - flags := cmd.Flags() - - flags.StringVarP(&opts.workdir, flagWorkdir, "w", "", "Working directory inside the container") - flags.StringVarP(&opts.user, flagUser, "u", "", "Username or UID (format: [:])") - flags.StringVar(&opts.hostname, flagHostname, "", "Container hostname") - - flags.Var(&opts.resources.limitCPU, flagLimitCPU, "Limit CPUs") - flags.Var(&opts.resources.limitMemBytes, flagLimitMemory, "Limit Memory") - flags.Var(&opts.resources.resCPU, flagReserveCPU, "Reserve CPUs") - flags.Var(&opts.resources.resMemBytes, flagReserveMemory, "Reserve Memory") - flags.Var(&opts.stopGrace, flagStopGracePeriod, "Time to wait before force killing a container (ns|us|ms|s|m|h)") - - flags.Var(&opts.replicas, flagReplicas, "Number of tasks") - - flags.StringVar(&opts.restartPolicy.condition, flagRestartCondition, "", "Restart when condition is met (none, on-failure, or any)") - flags.Var(&opts.restartPolicy.delay, flagRestartDelay, "Delay between restart attempts (ns|us|ms|s|m|h)") - flags.Var(&opts.restartPolicy.maxAttempts, flagRestartMaxAttempts, "Maximum number of restarts before giving up") - flags.Var(&opts.restartPolicy.window, flagRestartWindow, "Window used to evaluate the restart policy (ns|us|ms|s|m|h)") - - flags.Uint64Var(&opts.update.parallelism, flagUpdateParallelism, 1, "Maximum number of tasks updated simultaneously (0 to update all at once)") - flags.DurationVar(&opts.update.delay, flagUpdateDelay, time.Duration(0), "Delay between updates (ns|us|ms|s|m|h) (default 0s)") - flags.DurationVar(&opts.update.monitor, flagUpdateMonitor, time.Duration(0), "Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s)") - flags.StringVar(&opts.update.onFailure, flagUpdateFailureAction, "pause", "Action on update failure (pause|continue)") - flags.Var(&opts.update.maxFailureRatio, flagUpdateMaxFailureRatio, "Failure rate to tolerate during an update") - - flags.StringVar(&opts.endpoint.mode, flagEndpointMode, "", "Endpoint mode (vip or dnsrr)") - - flags.BoolVar(&opts.registryAuth, flagRegistryAuth, false, "Send registry authentication details to swarm agents") - - flags.StringVar(&opts.logDriver.name, flagLogDriver, "", "Logging driver for service") - flags.Var(&opts.logDriver.opts, flagLogOpt, "Logging driver options") - - flags.StringVar(&opts.healthcheck.cmd, flagHealthCmd, "", "Command to run to check health") - flags.Var(&opts.healthcheck.interval, flagHealthInterval, "Time between running the check (ns|us|ms|s|m|h)") - flags.Var(&opts.healthcheck.timeout, flagHealthTimeout, "Maximum time to allow one check to run (ns|us|ms|s|m|h)") - flags.IntVar(&opts.healthcheck.retries, flagHealthRetries, 0, "Consecutive failures needed to report unhealthy") - flags.BoolVar(&opts.healthcheck.noHealthcheck, flagNoHealthcheck, false, "Disable any container-specified HEALTHCHECK") - - flags.BoolVarP(&opts.tty, flagTTY, "t", false, "Allocate a pseudo-TTY") -} - -const ( - flagConstraint = "constraint" - flagConstraintRemove = "constraint-rm" - flagConstraintAdd = "constraint-add" - flagContainerLabel = "container-label" - flagContainerLabelRemove = "container-label-rm" - flagContainerLabelAdd = "container-label-add" - flagDNS = "dns" - flagDNSRemove = "dns-rm" - flagDNSAdd = "dns-add" - flagDNSOption = "dns-option" - flagDNSOptionRemove = "dns-option-rm" - flagDNSOptionAdd = "dns-option-add" - flagDNSSearch = "dns-search" - flagDNSSearchRemove = "dns-search-rm" - flagDNSSearchAdd = "dns-search-add" - flagEndpointMode = "endpoint-mode" - flagHost = "host" - flagHostAdd = "host-add" - flagHostRemove = "host-rm" - flagHostname = "hostname" - flagEnv = "env" - flagEnvFile = "env-file" - flagEnvRemove = "env-rm" - flagEnvAdd = "env-add" - flagGroup = "group" - flagGroupAdd = "group-add" - flagGroupRemove = "group-rm" - flagLabel = "label" - flagLabelRemove = "label-rm" - flagLabelAdd = "label-add" - flagLimitCPU = "limit-cpu" - flagLimitMemory = "limit-memory" - flagMode = "mode" - flagMount = "mount" - flagMountRemove = "mount-rm" - flagMountAdd = "mount-add" - flagName = "name" - flagNetwork = "network" - flagPublish = "publish" - flagPublishRemove = "publish-rm" - flagPublishAdd = "publish-add" - flagReplicas = "replicas" - flagReserveCPU = "reserve-cpu" - flagReserveMemory = "reserve-memory" - flagRestartCondition = "restart-condition" - flagRestartDelay = "restart-delay" - flagRestartMaxAttempts = "restart-max-attempts" - flagRestartWindow = "restart-window" - flagStopGracePeriod = "stop-grace-period" - flagTTY = "tty" - flagUpdateDelay = "update-delay" - flagUpdateFailureAction = "update-failure-action" - flagUpdateMaxFailureRatio = "update-max-failure-ratio" - flagUpdateMonitor = "update-monitor" - flagUpdateParallelism = "update-parallelism" - flagUser = "user" - flagWorkdir = "workdir" - flagRegistryAuth = "with-registry-auth" - flagLogDriver = "log-driver" - flagLogOpt = "log-opt" - flagHealthCmd = "health-cmd" - flagHealthInterval = "health-interval" - flagHealthRetries = "health-retries" - flagHealthTimeout = "health-timeout" - flagNoHealthcheck = "no-healthcheck" - flagSecret = "secret" - flagSecretAdd = "secret-add" - flagSecretRemove = "secret-rm" -) diff --git a/vendor/github.com/docker/docker/cli/command/service/opts_test.go b/vendor/github.com/docker/docker/cli/command/service/opts_test.go deleted file mode 100644 index 78b956a..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/opts_test.go +++ /dev/null @@ -1,107 +0,0 @@ -package service - -import ( - "reflect" - "testing" - "time" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestMemBytesString(t *testing.T) { - var mem memBytes = 1048576 - assert.Equal(t, mem.String(), "1 MiB") -} - -func TestMemBytesSetAndValue(t *testing.T) { - var mem memBytes - assert.NilError(t, mem.Set("5kb")) - assert.Equal(t, mem.Value(), int64(5120)) -} - -func TestNanoCPUsString(t *testing.T) { - var cpus opts.NanoCPUs = 6100000000 - assert.Equal(t, cpus.String(), "6.100") -} - -func TestNanoCPUsSetAndValue(t *testing.T) { - var cpus opts.NanoCPUs - assert.NilError(t, cpus.Set("0.35")) - assert.Equal(t, cpus.Value(), int64(350000000)) -} - -func TestDurationOptString(t *testing.T) { - dur := time.Duration(300 * 10e8) - duration := DurationOpt{value: &dur} - assert.Equal(t, duration.String(), "5m0s") -} - -func TestDurationOptSetAndValue(t *testing.T) { - var duration DurationOpt - assert.NilError(t, duration.Set("300s")) - assert.Equal(t, *duration.Value(), time.Duration(300*10e8)) - assert.NilError(t, duration.Set("-300s")) - assert.Equal(t, *duration.Value(), time.Duration(-300*10e8)) -} - -func TestPositiveDurationOptSetAndValue(t *testing.T) { - var duration PositiveDurationOpt - assert.NilError(t, duration.Set("300s")) - assert.Equal(t, *duration.Value(), time.Duration(300*10e8)) - assert.Error(t, duration.Set("-300s"), "cannot be negative") -} - -func TestUint64OptString(t *testing.T) { - value := uint64(2345678) - opt := Uint64Opt{value: &value} - assert.Equal(t, opt.String(), "2345678") - - opt = Uint64Opt{} - assert.Equal(t, opt.String(), "") -} - -func TestUint64OptSetAndValue(t *testing.T) { - var opt Uint64Opt - assert.NilError(t, opt.Set("14445")) - assert.Equal(t, *opt.Value(), uint64(14445)) -} - -func TestHealthCheckOptionsToHealthConfig(t *testing.T) { - dur := time.Second - opt := healthCheckOptions{ - cmd: "curl", - interval: PositiveDurationOpt{DurationOpt{value: &dur}}, - timeout: PositiveDurationOpt{DurationOpt{value: &dur}}, - retries: 10, - } - config, err := opt.toHealthConfig() - assert.NilError(t, err) - assert.Equal(t, reflect.DeepEqual(config, &container.HealthConfig{ - Test: []string{"CMD-SHELL", "curl"}, - Interval: time.Second, - Timeout: time.Second, - Retries: 10, - }), true) -} - -func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) { - opt := healthCheckOptions{ - noHealthcheck: true, - } - config, err := opt.toHealthConfig() - assert.NilError(t, err) - assert.Equal(t, reflect.DeepEqual(config, &container.HealthConfig{ - Test: []string{"NONE"}, - }), true) -} - -func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) { - opt := healthCheckOptions{ - cmd: "curl", - noHealthcheck: true, - } - _, err := opt.toHealthConfig() - assert.Error(t, err, "--no-healthcheck conflicts with --health-* options") -} diff --git a/vendor/github.com/docker/docker/cli/command/service/parse.go b/vendor/github.com/docker/docker/cli/command/service/parse.go deleted file mode 100644 index ce9b454..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/parse.go +++ /dev/null @@ -1,68 +0,0 @@ -package service - -import ( - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - swarmtypes "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/client" - "golang.org/x/net/context" -) - -// ParseSecrets retrieves the secrets from the requested names and converts -// them to secret references to use with the spec -func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*types.SecretRequestOption) ([]*swarmtypes.SecretReference, error) { - secretRefs := make(map[string]*swarmtypes.SecretReference) - ctx := context.Background() - - for _, secret := range requestedSecrets { - if _, exists := secretRefs[secret.Target]; exists { - return nil, fmt.Errorf("duplicate secret target for %s not allowed", secret.Source) - } - secretRef := &swarmtypes.SecretReference{ - File: &swarmtypes.SecretReferenceFileTarget{ - Name: secret.Target, - UID: secret.UID, - GID: secret.GID, - Mode: secret.Mode, - }, - SecretName: secret.Source, - } - - secretRefs[secret.Target] = secretRef - } - - args := filters.NewArgs() - for _, s := range secretRefs { - args.Add("names", s.SecretName) - } - - secrets, err := client.SecretList(ctx, types.SecretListOptions{ - Filters: args, - }) - if err != nil { - return nil, err - } - - foundSecrets := make(map[string]string) - for _, secret := range secrets { - foundSecrets[secret.Spec.Annotations.Name] = secret.ID - } - - addedSecrets := []*swarmtypes.SecretReference{} - - for _, ref := range secretRefs { - id, ok := foundSecrets[ref.SecretName] - if !ok { - return nil, fmt.Errorf("secret not found: %s", ref.SecretName) - } - - // set the id for the ref to properly assign in swarm - // since swarm needs the ID instead of the name - ref.SecretID = id - addedSecrets = append(addedSecrets, ref) - } - - return addedSecrets, nil -} diff --git a/vendor/github.com/docker/docker/cli/command/service/ps.go b/vendor/github.com/docker/docker/cli/command/service/ps.go deleted file mode 100644 index cf94ad7..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/ps.go +++ /dev/null @@ -1,76 +0,0 @@ -package service - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/idresolver" - "github.com/docker/docker/cli/command/node" - "github.com/docker/docker/cli/command/task" - "github.com/docker/docker/opts" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type psOptions struct { - serviceID string - quiet bool - noResolve bool - noTrunc bool - filter opts.FilterOpt -} - -func newPsCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := psOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "ps [OPTIONS] SERVICE", - Short: "List the tasks of a service", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.serviceID = args[0] - return runPS(dockerCli, opts) - }, - } - flags := cmd.Flags() - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display task IDs") - flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") - flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") - flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") - - return cmd -} - -func runPS(dockerCli *command.DockerCli, opts psOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - service, _, err := client.ServiceInspectWithRaw(ctx, opts.serviceID) - if err != nil { - return err - } - - filter := opts.filter.Value() - filter.Add("service", service.ID) - if filter.Include("node") { - nodeFilters := filter.Get("node") - for _, nodeFilter := range nodeFilters { - nodeReference, err := node.Reference(ctx, client, nodeFilter) - if err != nil { - return err - } - filter.Del("node", nodeFilter) - filter.Add("node", nodeReference) - } - } - - tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter}) - if err != nil { - return err - } - - if opts.quiet { - return task.PrintQuiet(dockerCli, tasks) - } - return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), opts.noTrunc) -} diff --git a/vendor/github.com/docker/docker/cli/command/service/remove.go b/vendor/github.com/docker/docker/cli/command/service/remove.go deleted file mode 100644 index c3fbbab..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/remove.go +++ /dev/null @@ -1,47 +0,0 @@ -package service - -import ( - "fmt" - "strings" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { - - cmd := &cobra.Command{ - Use: "rm SERVICE [SERVICE...]", - Aliases: []string{"remove"}, - Short: "Remove one or more services", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runRemove(dockerCli, args) - }, - } - cmd.Flags() - - return cmd -} - -func runRemove(dockerCli *command.DockerCli, sids []string) error { - client := dockerCli.Client() - - ctx := context.Background() - - var errs []string - for _, sid := range sids { - err := client.ServiceRemove(ctx, sid) - if err != nil { - errs = append(errs, err.Error()) - continue - } - fmt.Fprintf(dockerCli.Out(), "%s\n", sid) - } - if len(errs) > 0 { - return fmt.Errorf(strings.Join(errs, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/service/scale.go b/vendor/github.com/docker/docker/cli/command/service/scale.go deleted file mode 100644 index cf89e90..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/scale.go +++ /dev/null @@ -1,96 +0,0 @@ -package service - -import ( - "fmt" - "strconv" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -func newScaleCommand(dockerCli *command.DockerCli) *cobra.Command { - return &cobra.Command{ - Use: "scale SERVICE=REPLICAS [SERVICE=REPLICAS...]", - Short: "Scale one or multiple replicated services", - Args: scaleArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runScale(dockerCli, args) - }, - } -} - -func scaleArgs(cmd *cobra.Command, args []string) error { - if err := cli.RequiresMinArgs(1)(cmd, args); err != nil { - return err - } - for _, arg := range args { - if parts := strings.SplitN(arg, "=", 2); len(parts) != 2 { - return fmt.Errorf( - "Invalid scale specifier '%s'.\nSee '%s --help'.\n\nUsage: %s\n\n%s", - arg, - cmd.CommandPath(), - cmd.UseLine(), - cmd.Short, - ) - } - } - return nil -} - -func runScale(dockerCli *command.DockerCli, args []string) error { - var errors []string - for _, arg := range args { - parts := strings.SplitN(arg, "=", 2) - serviceID, scaleStr := parts[0], parts[1] - - // validate input arg scale number - scale, err := strconv.ParseUint(scaleStr, 10, 64) - if err != nil { - errors = append(errors, fmt.Sprintf("%s: invalid replicas value %s: %v", serviceID, scaleStr, err)) - continue - } - - if err := runServiceScale(dockerCli, serviceID, scale); err != nil { - errors = append(errors, fmt.Sprintf("%s: %v", serviceID, err)) - } - } - - if len(errors) == 0 { - return nil - } - return fmt.Errorf(strings.Join(errors, "\n")) -} - -func runServiceScale(dockerCli *command.DockerCli, serviceID string, scale uint64) error { - client := dockerCli.Client() - ctx := context.Background() - - service, _, err := client.ServiceInspectWithRaw(ctx, serviceID) - if err != nil { - return err - } - - serviceMode := &service.Spec.Mode - if serviceMode.Replicated == nil { - return fmt.Errorf("scale can only be used with replicated mode") - } - - serviceMode.Replicated.Replicas = &scale - - response, err := client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, types.ServiceUpdateOptions{}) - if err != nil { - return err - } - - for _, warning := range response.Warnings { - fmt.Fprintln(dockerCli.Err(), warning) - } - - fmt.Fprintf(dockerCli.Out(), "%s scaled to %d\n", serviceID, scale) - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/service/trust.go b/vendor/github.com/docker/docker/cli/command/service/trust.go deleted file mode 100644 index 052d49c..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/trust.go +++ /dev/null @@ -1,96 +0,0 @@ -package service - -import ( - "encoding/hex" - "fmt" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - distreference "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/trust" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "github.com/docker/notary/tuf/data" - "github.com/pkg/errors" - "golang.org/x/net/context" -) - -func resolveServiceImageDigest(dockerCli *command.DockerCli, service *swarm.ServiceSpec) error { - if !command.IsTrusted() { - // Digests are resolved by the daemon when not using content - // trust. - return nil - } - - image := service.TaskTemplate.ContainerSpec.Image - - // We only attempt to resolve the digest if the reference - // could be parsed as a digest reference. Specifying an image ID - // is valid but not resolvable. There is no warning message for - // an image ID because it's valid to use one. - if _, err := digest.ParseDigest(image); err == nil { - return nil - } - - ref, err := reference.ParseNamed(image) - if err != nil { - return fmt.Errorf("Could not parse image reference %s", service.TaskTemplate.ContainerSpec.Image) - } - if _, ok := ref.(reference.Canonical); !ok { - ref = reference.WithDefaultTag(ref) - - taggedRef, ok := ref.(reference.NamedTagged) - if !ok { - // This should never happen because a reference either - // has a digest, or WithDefaultTag would give it a tag. - return errors.New("Failed to resolve image digest using content trust: reference is missing a tag") - } - - resolvedImage, err := trustedResolveDigest(context.Background(), dockerCli, taggedRef) - if err != nil { - return fmt.Errorf("Failed to resolve image digest using content trust: %v", err) - } - logrus.Debugf("resolved image tag to %s using content trust", resolvedImage.String()) - service.TaskTemplate.ContainerSpec.Image = resolvedImage.String() - } - return nil -} - -func trustedResolveDigest(ctx context.Context, cli *command.DockerCli, ref reference.NamedTagged) (distreference.Canonical, error) { - repoInfo, err := registry.ParseRepositoryInfo(ref) - if err != nil { - return nil, err - } - - authConfig := command.ResolveAuthConfig(ctx, cli, repoInfo.Index) - - notaryRepo, err := trust.GetNotaryRepository(cli, repoInfo, authConfig, "pull") - if err != nil { - return nil, errors.Wrap(err, "error establishing connection to trust repository") - } - - t, err := notaryRepo.GetTargetByName(ref.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole) - if err != nil { - return nil, trust.NotaryError(repoInfo.FullName(), err) - } - // Only get the tag if it's in the top level targets role or the releases delegation role - // ignore it if it's in any other delegation roles - if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole { - return nil, trust.NotaryError(repoInfo.FullName(), fmt.Errorf("No trust data for %s", ref.String())) - } - - logrus.Debugf("retrieving target for %s role\n", t.Role) - h, ok := t.Hashes["sha256"] - if !ok { - return nil, errors.New("no valid hash, expecting sha256") - } - - dgst := digest.NewDigestFromHex("sha256", hex.EncodeToString(h)) - - // Using distribution reference package to make sure that adding a - // digest does not erase the tag. When the two reference packages - // are unified, this will no longer be an issue. - return distreference.WithDigest(ref, dgst) -} diff --git a/vendor/github.com/docker/docker/cli/command/service/update.go b/vendor/github.com/docker/docker/cli/command/service/update.go deleted file mode 100644 index d56de10..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/update.go +++ /dev/null @@ -1,849 +0,0 @@ -package service - -import ( - "fmt" - "sort" - "strings" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - mounttypes "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/client" - "github.com/docker/docker/opts" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/docker/go-connections/nat" - shlex "github.com/flynn-archive/go-shlex" - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command { - serviceOpts := newServiceOptions() - - cmd := &cobra.Command{ - Use: "update [OPTIONS] SERVICE", - Short: "Update a service", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - return runUpdate(dockerCli, cmd.Flags(), args[0]) - }, - } - - flags := cmd.Flags() - flags.String("image", "", "Service image tag") - flags.String("args", "", "Service command args") - flags.Bool("rollback", false, "Rollback to previous specification") - flags.Bool("force", false, "Force update even if no changes require it") - addServiceFlags(cmd, serviceOpts) - - flags.Var(newListOptsVar(), flagEnvRemove, "Remove an environment variable") - flags.Var(newListOptsVar(), flagGroupRemove, "Remove a previously added supplementary user group from the container") - flags.Var(newListOptsVar(), flagLabelRemove, "Remove a label by its key") - flags.Var(newListOptsVar(), flagContainerLabelRemove, "Remove a container label by its key") - flags.Var(newListOptsVar(), flagMountRemove, "Remove a mount by its target path") - // flags.Var(newListOptsVar().WithValidator(validatePublishRemove), flagPublishRemove, "Remove a published port by its target port") - flags.Var(&opts.PortOpt{}, flagPublishRemove, "Remove a published port by its target port") - flags.Var(newListOptsVar(), flagConstraintRemove, "Remove a constraint") - flags.Var(newListOptsVar(), flagDNSRemove, "Remove a custom DNS server") - flags.Var(newListOptsVar(), flagDNSOptionRemove, "Remove a DNS option") - flags.Var(newListOptsVar(), flagDNSSearchRemove, "Remove a DNS search domain") - flags.Var(newListOptsVar(), flagHostRemove, "Remove a custom host-to-IP mapping (host:ip)") - flags.Var(&serviceOpts.labels, flagLabelAdd, "Add or update a service label") - flags.Var(&serviceOpts.containerLabels, flagContainerLabelAdd, "Add or update a container label") - flags.Var(&serviceOpts.env, flagEnvAdd, "Add or update an environment variable") - flags.Var(newListOptsVar(), flagSecretRemove, "Remove a secret") - flags.Var(&serviceOpts.secrets, flagSecretAdd, "Add or update a secret on a service") - flags.Var(&serviceOpts.mounts, flagMountAdd, "Add or update a mount on a service") - flags.Var(&serviceOpts.constraints, flagConstraintAdd, "Add or update a placement constraint") - flags.Var(&serviceOpts.endpoint.publishPorts, flagPublishAdd, "Add or update a published port") - flags.Var(&serviceOpts.groups, flagGroupAdd, "Add an additional supplementary user group to the container") - flags.Var(&serviceOpts.dns, flagDNSAdd, "Add or update a custom DNS server") - flags.Var(&serviceOpts.dnsOption, flagDNSOptionAdd, "Add or update a DNS option") - flags.Var(&serviceOpts.dnsSearch, flagDNSSearchAdd, "Add or update a custom DNS search domain") - flags.Var(&serviceOpts.hosts, flagHostAdd, "Add or update a custom host-to-IP mapping (host:ip)") - - return cmd -} - -func newListOptsVar() *opts.ListOpts { - return opts.NewListOptsRef(&[]string{}, nil) -} - -func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, serviceID string) error { - apiClient := dockerCli.Client() - ctx := context.Background() - updateOpts := types.ServiceUpdateOptions{} - - service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID) - if err != nil { - return err - } - - rollback, err := flags.GetBool("rollback") - if err != nil { - return err - } - - spec := &service.Spec - if rollback { - spec = service.PreviousSpec - if spec == nil { - return fmt.Errorf("service does not have a previous specification to roll back to") - } - } - - err = updateService(flags, spec) - if err != nil { - return err - } - - if flags.Changed("image") { - if err := resolveServiceImageDigest(dockerCli, spec); err != nil { - return err - } - } - - updatedSecrets, err := getUpdatedSecrets(apiClient, flags, spec.TaskTemplate.ContainerSpec.Secrets) - if err != nil { - return err - } - - spec.TaskTemplate.ContainerSpec.Secrets = updatedSecrets - - // only send auth if flag was set - sendAuth, err := flags.GetBool(flagRegistryAuth) - if err != nil { - return err - } - if sendAuth { - // Retrieve encoded auth token from the image reference - // This would be the old image if it didn't change in this update - image := spec.TaskTemplate.ContainerSpec.Image - encodedAuth, err := command.RetrieveAuthTokenFromImage(ctx, dockerCli, image) - if err != nil { - return err - } - updateOpts.EncodedRegistryAuth = encodedAuth - } else if rollback { - updateOpts.RegistryAuthFrom = types.RegistryAuthFromPreviousSpec - } else { - updateOpts.RegistryAuthFrom = types.RegistryAuthFromSpec - } - - response, err := apiClient.ServiceUpdate(ctx, service.ID, service.Version, *spec, updateOpts) - if err != nil { - return err - } - - for _, warning := range response.Warnings { - fmt.Fprintln(dockerCli.Err(), warning) - } - - fmt.Fprintf(dockerCli.Out(), "%s\n", serviceID) - return nil -} - -func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error { - updateString := func(flag string, field *string) { - if flags.Changed(flag) { - *field, _ = flags.GetString(flag) - } - } - - updateInt64Value := func(flag string, field *int64) { - if flags.Changed(flag) { - *field = flags.Lookup(flag).Value.(int64Value).Value() - } - } - - updateFloatValue := func(flag string, field *float32) { - if flags.Changed(flag) { - *field = flags.Lookup(flag).Value.(*floatValue).Value() - } - } - - updateDuration := func(flag string, field *time.Duration) { - if flags.Changed(flag) { - *field, _ = flags.GetDuration(flag) - } - } - - updateDurationOpt := func(flag string, field **time.Duration) { - if flags.Changed(flag) { - val := *flags.Lookup(flag).Value.(*DurationOpt).Value() - *field = &val - } - } - - updateUint64 := func(flag string, field *uint64) { - if flags.Changed(flag) { - *field, _ = flags.GetUint64(flag) - } - } - - updateUint64Opt := func(flag string, field **uint64) { - if flags.Changed(flag) { - val := *flags.Lookup(flag).Value.(*Uint64Opt).Value() - *field = &val - } - } - - cspec := &spec.TaskTemplate.ContainerSpec - task := &spec.TaskTemplate - - taskResources := func() *swarm.ResourceRequirements { - if task.Resources == nil { - task.Resources = &swarm.ResourceRequirements{} - } - return task.Resources - } - - updateLabels(flags, &spec.Labels) - updateContainerLabels(flags, &cspec.Labels) - updateString("image", &cspec.Image) - updateStringToSlice(flags, "args", &cspec.Args) - updateEnvironment(flags, &cspec.Env) - updateString(flagWorkdir, &cspec.Dir) - updateString(flagUser, &cspec.User) - updateString(flagHostname, &cspec.Hostname) - if err := updateMounts(flags, &cspec.Mounts); err != nil { - return err - } - - if flags.Changed(flagLimitCPU) || flags.Changed(flagLimitMemory) { - taskResources().Limits = &swarm.Resources{} - updateInt64Value(flagLimitCPU, &task.Resources.Limits.NanoCPUs) - updateInt64Value(flagLimitMemory, &task.Resources.Limits.MemoryBytes) - } - if flags.Changed(flagReserveCPU) || flags.Changed(flagReserveMemory) { - taskResources().Reservations = &swarm.Resources{} - updateInt64Value(flagReserveCPU, &task.Resources.Reservations.NanoCPUs) - updateInt64Value(flagReserveMemory, &task.Resources.Reservations.MemoryBytes) - } - - updateDurationOpt(flagStopGracePeriod, &cspec.StopGracePeriod) - - if anyChanged(flags, flagRestartCondition, flagRestartDelay, flagRestartMaxAttempts, flagRestartWindow) { - if task.RestartPolicy == nil { - task.RestartPolicy = &swarm.RestartPolicy{} - } - - if flags.Changed(flagRestartCondition) { - value, _ := flags.GetString(flagRestartCondition) - task.RestartPolicy.Condition = swarm.RestartPolicyCondition(value) - } - updateDurationOpt(flagRestartDelay, &task.RestartPolicy.Delay) - updateUint64Opt(flagRestartMaxAttempts, &task.RestartPolicy.MaxAttempts) - updateDurationOpt(flagRestartWindow, &task.RestartPolicy.Window) - } - - if anyChanged(flags, flagConstraintAdd, flagConstraintRemove) { - if task.Placement == nil { - task.Placement = &swarm.Placement{} - } - updatePlacement(flags, task.Placement) - } - - if err := updateReplicas(flags, &spec.Mode); err != nil { - return err - } - - if anyChanged(flags, flagUpdateParallelism, flagUpdateDelay, flagUpdateMonitor, flagUpdateFailureAction, flagUpdateMaxFailureRatio) { - if spec.UpdateConfig == nil { - spec.UpdateConfig = &swarm.UpdateConfig{} - } - updateUint64(flagUpdateParallelism, &spec.UpdateConfig.Parallelism) - updateDuration(flagUpdateDelay, &spec.UpdateConfig.Delay) - updateDuration(flagUpdateMonitor, &spec.UpdateConfig.Monitor) - updateString(flagUpdateFailureAction, &spec.UpdateConfig.FailureAction) - updateFloatValue(flagUpdateMaxFailureRatio, &spec.UpdateConfig.MaxFailureRatio) - } - - if flags.Changed(flagEndpointMode) { - value, _ := flags.GetString(flagEndpointMode) - if spec.EndpointSpec == nil { - spec.EndpointSpec = &swarm.EndpointSpec{} - } - spec.EndpointSpec.Mode = swarm.ResolutionMode(value) - } - - if anyChanged(flags, flagGroupAdd, flagGroupRemove) { - if err := updateGroups(flags, &cspec.Groups); err != nil { - return err - } - } - - if anyChanged(flags, flagPublishAdd, flagPublishRemove) { - if spec.EndpointSpec == nil { - spec.EndpointSpec = &swarm.EndpointSpec{} - } - if err := updatePorts(flags, &spec.EndpointSpec.Ports); err != nil { - return err - } - } - - if anyChanged(flags, flagDNSAdd, flagDNSRemove, flagDNSOptionAdd, flagDNSOptionRemove, flagDNSSearchAdd, flagDNSSearchRemove) { - if cspec.DNSConfig == nil { - cspec.DNSConfig = &swarm.DNSConfig{} - } - if err := updateDNSConfig(flags, &cspec.DNSConfig); err != nil { - return err - } - } - - if anyChanged(flags, flagHostAdd, flagHostRemove) { - if err := updateHosts(flags, &cspec.Hosts); err != nil { - return err - } - } - - if err := updateLogDriver(flags, &spec.TaskTemplate); err != nil { - return err - } - - force, err := flags.GetBool("force") - if err != nil { - return err - } - - if force { - spec.TaskTemplate.ForceUpdate++ - } - - if err := updateHealthcheck(flags, cspec); err != nil { - return err - } - - if flags.Changed(flagTTY) { - tty, err := flags.GetBool(flagTTY) - if err != nil { - return err - } - cspec.TTY = tty - } - - return nil -} - -func updateStringToSlice(flags *pflag.FlagSet, flag string, field *[]string) error { - if !flags.Changed(flag) { - return nil - } - - value, _ := flags.GetString(flag) - valueSlice, err := shlex.Split(value) - *field = valueSlice - return err -} - -func anyChanged(flags *pflag.FlagSet, fields ...string) bool { - for _, flag := range fields { - if flags.Changed(flag) { - return true - } - } - return false -} - -func updatePlacement(flags *pflag.FlagSet, placement *swarm.Placement) { - if flags.Changed(flagConstraintAdd) { - values := flags.Lookup(flagConstraintAdd).Value.(*opts.ListOpts).GetAll() - placement.Constraints = append(placement.Constraints, values...) - } - toRemove := buildToRemoveSet(flags, flagConstraintRemove) - - newConstraints := []string{} - for _, constraint := range placement.Constraints { - if _, exists := toRemove[constraint]; !exists { - newConstraints = append(newConstraints, constraint) - } - } - // Sort so that result is predictable. - sort.Strings(newConstraints) - - placement.Constraints = newConstraints -} - -func updateContainerLabels(flags *pflag.FlagSet, field *map[string]string) { - if flags.Changed(flagContainerLabelAdd) { - if *field == nil { - *field = map[string]string{} - } - - values := flags.Lookup(flagContainerLabelAdd).Value.(*opts.ListOpts).GetAll() - for key, value := range runconfigopts.ConvertKVStringsToMap(values) { - (*field)[key] = value - } - } - - if *field != nil && flags.Changed(flagContainerLabelRemove) { - toRemove := flags.Lookup(flagContainerLabelRemove).Value.(*opts.ListOpts).GetAll() - for _, label := range toRemove { - delete(*field, label) - } - } -} - -func updateLabels(flags *pflag.FlagSet, field *map[string]string) { - if flags.Changed(flagLabelAdd) { - if *field == nil { - *field = map[string]string{} - } - - values := flags.Lookup(flagLabelAdd).Value.(*opts.ListOpts).GetAll() - for key, value := range runconfigopts.ConvertKVStringsToMap(values) { - (*field)[key] = value - } - } - - if *field != nil && flags.Changed(flagLabelRemove) { - toRemove := flags.Lookup(flagLabelRemove).Value.(*opts.ListOpts).GetAll() - for _, label := range toRemove { - delete(*field, label) - } - } -} - -func updateEnvironment(flags *pflag.FlagSet, field *[]string) { - envSet := map[string]string{} - for _, v := range *field { - envSet[envKey(v)] = v - } - if flags.Changed(flagEnvAdd) { - value := flags.Lookup(flagEnvAdd).Value.(*opts.ListOpts) - for _, v := range value.GetAll() { - envSet[envKey(v)] = v - } - } - - *field = []string{} - for _, v := range envSet { - *field = append(*field, v) - } - - toRemove := buildToRemoveSet(flags, flagEnvRemove) - *field = removeItems(*field, toRemove, envKey) -} - -func getUpdatedSecrets(apiClient client.SecretAPIClient, flags *pflag.FlagSet, secrets []*swarm.SecretReference) ([]*swarm.SecretReference, error) { - if flags.Changed(flagSecretAdd) { - values := flags.Lookup(flagSecretAdd).Value.(*opts.SecretOpt).Value() - - addSecrets, err := ParseSecrets(apiClient, values) - if err != nil { - return nil, err - } - secrets = append(secrets, addSecrets...) - } - toRemove := buildToRemoveSet(flags, flagSecretRemove) - newSecrets := []*swarm.SecretReference{} - for _, secret := range secrets { - if _, exists := toRemove[secret.SecretName]; !exists { - newSecrets = append(newSecrets, secret) - } - } - - return newSecrets, nil -} - -func envKey(value string) string { - kv := strings.SplitN(value, "=", 2) - return kv[0] -} - -func itemKey(value string) string { - return value -} - -func buildToRemoveSet(flags *pflag.FlagSet, flag string) map[string]struct{} { - var empty struct{} - toRemove := make(map[string]struct{}) - - if !flags.Changed(flag) { - return toRemove - } - - toRemoveSlice := flags.Lookup(flag).Value.(*opts.ListOpts).GetAll() - for _, key := range toRemoveSlice { - toRemove[key] = empty - } - return toRemove -} - -func removeItems( - seq []string, - toRemove map[string]struct{}, - keyFunc func(string) string, -) []string { - newSeq := []string{} - for _, item := range seq { - if _, exists := toRemove[keyFunc(item)]; !exists { - newSeq = append(newSeq, item) - } - } - return newSeq -} - -type byMountSource []mounttypes.Mount - -func (m byMountSource) Len() int { return len(m) } -func (m byMountSource) Swap(i, j int) { m[i], m[j] = m[j], m[i] } -func (m byMountSource) Less(i, j int) bool { - a, b := m[i], m[j] - - if a.Source == b.Source { - return a.Target < b.Target - } - - return a.Source < b.Source -} - -func updateMounts(flags *pflag.FlagSet, mounts *[]mounttypes.Mount) error { - - mountsByTarget := map[string]mounttypes.Mount{} - - if flags.Changed(flagMountAdd) { - values := flags.Lookup(flagMountAdd).Value.(*opts.MountOpt).Value() - for _, mount := range values { - if _, ok := mountsByTarget[mount.Target]; ok { - return fmt.Errorf("duplicate mount target") - } - mountsByTarget[mount.Target] = mount - } - } - - // Add old list of mount points minus updated one. - for _, mount := range *mounts { - if _, ok := mountsByTarget[mount.Target]; !ok { - mountsByTarget[mount.Target] = mount - } - } - - newMounts := []mounttypes.Mount{} - - toRemove := buildToRemoveSet(flags, flagMountRemove) - - for _, mount := range mountsByTarget { - if _, exists := toRemove[mount.Target]; !exists { - newMounts = append(newMounts, mount) - } - } - sort.Sort(byMountSource(newMounts)) - *mounts = newMounts - return nil -} - -func updateGroups(flags *pflag.FlagSet, groups *[]string) error { - if flags.Changed(flagGroupAdd) { - values := flags.Lookup(flagGroupAdd).Value.(*opts.ListOpts).GetAll() - *groups = append(*groups, values...) - } - toRemove := buildToRemoveSet(flags, flagGroupRemove) - - newGroups := []string{} - for _, group := range *groups { - if _, exists := toRemove[group]; !exists { - newGroups = append(newGroups, group) - } - } - // Sort so that result is predictable. - sort.Strings(newGroups) - - *groups = newGroups - return nil -} - -func removeDuplicates(entries []string) []string { - hit := map[string]bool{} - newEntries := []string{} - for _, v := range entries { - if !hit[v] { - newEntries = append(newEntries, v) - hit[v] = true - } - } - return newEntries -} - -func updateDNSConfig(flags *pflag.FlagSet, config **swarm.DNSConfig) error { - newConfig := &swarm.DNSConfig{} - - nameservers := (*config).Nameservers - if flags.Changed(flagDNSAdd) { - values := flags.Lookup(flagDNSAdd).Value.(*opts.ListOpts).GetAll() - nameservers = append(nameservers, values...) - } - nameservers = removeDuplicates(nameservers) - toRemove := buildToRemoveSet(flags, flagDNSRemove) - for _, nameserver := range nameservers { - if _, exists := toRemove[nameserver]; !exists { - newConfig.Nameservers = append(newConfig.Nameservers, nameserver) - - } - } - // Sort so that result is predictable. - sort.Strings(newConfig.Nameservers) - - search := (*config).Search - if flags.Changed(flagDNSSearchAdd) { - values := flags.Lookup(flagDNSSearchAdd).Value.(*opts.ListOpts).GetAll() - search = append(search, values...) - } - search = removeDuplicates(search) - toRemove = buildToRemoveSet(flags, flagDNSSearchRemove) - for _, entry := range search { - if _, exists := toRemove[entry]; !exists { - newConfig.Search = append(newConfig.Search, entry) - } - } - // Sort so that result is predictable. - sort.Strings(newConfig.Search) - - options := (*config).Options - if flags.Changed(flagDNSOptionAdd) { - values := flags.Lookup(flagDNSOptionAdd).Value.(*opts.ListOpts).GetAll() - options = append(options, values...) - } - options = removeDuplicates(options) - toRemove = buildToRemoveSet(flags, flagDNSOptionRemove) - for _, option := range options { - if _, exists := toRemove[option]; !exists { - newConfig.Options = append(newConfig.Options, option) - } - } - // Sort so that result is predictable. - sort.Strings(newConfig.Options) - - *config = newConfig - return nil -} - -type byPortConfig []swarm.PortConfig - -func (r byPortConfig) Len() int { return len(r) } -func (r byPortConfig) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r byPortConfig) Less(i, j int) bool { - // We convert PortConfig into `port/protocol`, e.g., `80/tcp` - // In updatePorts we already filter out with map so there is duplicate entries - return portConfigToString(&r[i]) < portConfigToString(&r[j]) -} - -func portConfigToString(portConfig *swarm.PortConfig) string { - protocol := portConfig.Protocol - mode := portConfig.PublishMode - return fmt.Sprintf("%v:%v/%s/%s", portConfig.PublishedPort, portConfig.TargetPort, protocol, mode) -} - -// FIXME(vdemeester) port to opts.PortOpt -// This validation is only used for `--publish-rm`. -// The `--publish-rm` takes: -// [/] (e.g., 80, 80/tcp, 53/udp) -func validatePublishRemove(val string) (string, error) { - proto, port := nat.SplitProtoPort(val) - if proto != "tcp" && proto != "udp" { - return "", fmt.Errorf("invalid protocol '%s' for %s", proto, val) - } - if strings.Contains(port, ":") { - return "", fmt.Errorf("invalid port format: '%s', should be [/] (e.g., 80, 80/tcp, 53/udp)", port) - } - if _, err := nat.ParsePort(port); err != nil { - return "", err - } - return val, nil -} - -func updatePorts(flags *pflag.FlagSet, portConfig *[]swarm.PortConfig) error { - // The key of the map is `port/protocol`, e.g., `80/tcp` - portSet := map[string]swarm.PortConfig{} - - // Build the current list of portConfig - for _, entry := range *portConfig { - if _, ok := portSet[portConfigToString(&entry)]; !ok { - portSet[portConfigToString(&entry)] = entry - } - } - - newPorts := []swarm.PortConfig{} - - // Clean current ports - toRemove := flags.Lookup(flagPublishRemove).Value.(*opts.PortOpt).Value() -portLoop: - for _, port := range portSet { - for _, pConfig := range toRemove { - if equalProtocol(port.Protocol, pConfig.Protocol) && - port.TargetPort == pConfig.TargetPort && - equalPublishMode(port.PublishMode, pConfig.PublishMode) { - continue portLoop - } - } - - newPorts = append(newPorts, port) - } - - // Check to see if there are any conflict in flags. - if flags.Changed(flagPublishAdd) { - ports := flags.Lookup(flagPublishAdd).Value.(*opts.PortOpt).Value() - - for _, port := range ports { - if v, ok := portSet[portConfigToString(&port)]; ok { - if v != port { - fmt.Println("v", v) - return fmt.Errorf("conflicting port mapping between %v:%v/%s and %v:%v/%s", port.PublishedPort, port.TargetPort, port.Protocol, v.PublishedPort, v.TargetPort, v.Protocol) - } - continue - } - //portSet[portConfigToString(&port)] = port - newPorts = append(newPorts, port) - } - } - - // Sort the PortConfig to avoid unnecessary updates - sort.Sort(byPortConfig(newPorts)) - *portConfig = newPorts - return nil -} - -func equalProtocol(prot1, prot2 swarm.PortConfigProtocol) bool { - return prot1 == prot2 || - (prot1 == swarm.PortConfigProtocol("") && prot2 == swarm.PortConfigProtocolTCP) || - (prot2 == swarm.PortConfigProtocol("") && prot1 == swarm.PortConfigProtocolTCP) -} - -func equalPublishMode(mode1, mode2 swarm.PortConfigPublishMode) bool { - return mode1 == mode2 || - (mode1 == swarm.PortConfigPublishMode("") && mode2 == swarm.PortConfigPublishModeIngress) || - (mode2 == swarm.PortConfigPublishMode("") && mode1 == swarm.PortConfigPublishModeIngress) -} - -func equalPort(targetPort nat.Port, port swarm.PortConfig) bool { - return (string(port.Protocol) == targetPort.Proto() && - port.TargetPort == uint32(targetPort.Int())) -} - -func updateReplicas(flags *pflag.FlagSet, serviceMode *swarm.ServiceMode) error { - if !flags.Changed(flagReplicas) { - return nil - } - - if serviceMode == nil || serviceMode.Replicated == nil { - return fmt.Errorf("replicas can only be used with replicated mode") - } - serviceMode.Replicated.Replicas = flags.Lookup(flagReplicas).Value.(*Uint64Opt).Value() - return nil -} - -func updateHosts(flags *pflag.FlagSet, hosts *[]string) error { - // Combine existing Hosts (in swarmkit format) with the host to add (convert to swarmkit format) - if flags.Changed(flagHostAdd) { - values := convertExtraHostsToSwarmHosts(flags.Lookup(flagHostAdd).Value.(*opts.ListOpts).GetAll()) - *hosts = append(*hosts, values...) - } - // Remove duplicate - *hosts = removeDuplicates(*hosts) - - keysToRemove := make(map[string]struct{}) - if flags.Changed(flagHostRemove) { - var empty struct{} - extraHostsToRemove := flags.Lookup(flagHostRemove).Value.(*opts.ListOpts).GetAll() - for _, entry := range extraHostsToRemove { - key := strings.SplitN(entry, ":", 2)[0] - keysToRemove[key] = empty - } - } - - newHosts := []string{} - for _, entry := range *hosts { - // Since this is in swarmkit format, we need to find the key, which is canonical_hostname of: - // IP_address canonical_hostname [aliases...] - parts := strings.Fields(entry) - if len(parts) > 1 { - key := parts[1] - if _, exists := keysToRemove[key]; !exists { - newHosts = append(newHosts, entry) - } - } else { - newHosts = append(newHosts, entry) - } - } - - // Sort so that result is predictable. - sort.Strings(newHosts) - - *hosts = newHosts - return nil -} - -// updateLogDriver updates the log driver only if the log driver flag is set. -// All options will be replaced with those provided on the command line. -func updateLogDriver(flags *pflag.FlagSet, taskTemplate *swarm.TaskSpec) error { - if !flags.Changed(flagLogDriver) { - return nil - } - - name, err := flags.GetString(flagLogDriver) - if err != nil { - return err - } - - if name == "" { - return nil - } - - taskTemplate.LogDriver = &swarm.Driver{ - Name: name, - Options: runconfigopts.ConvertKVStringsToMap(flags.Lookup(flagLogOpt).Value.(*opts.ListOpts).GetAll()), - } - - return nil -} - -func updateHealthcheck(flags *pflag.FlagSet, containerSpec *swarm.ContainerSpec) error { - if !anyChanged(flags, flagNoHealthcheck, flagHealthCmd, flagHealthInterval, flagHealthRetries, flagHealthTimeout) { - return nil - } - if containerSpec.Healthcheck == nil { - containerSpec.Healthcheck = &container.HealthConfig{} - } - noHealthcheck, err := flags.GetBool(flagNoHealthcheck) - if err != nil { - return err - } - if noHealthcheck { - if !anyChanged(flags, flagHealthCmd, flagHealthInterval, flagHealthRetries, flagHealthTimeout) { - containerSpec.Healthcheck = &container.HealthConfig{ - Test: []string{"NONE"}, - } - return nil - } - return fmt.Errorf("--%s conflicts with --health-* options", flagNoHealthcheck) - } - if len(containerSpec.Healthcheck.Test) > 0 && containerSpec.Healthcheck.Test[0] == "NONE" { - containerSpec.Healthcheck.Test = nil - } - if flags.Changed(flagHealthInterval) { - val := *flags.Lookup(flagHealthInterval).Value.(*PositiveDurationOpt).Value() - containerSpec.Healthcheck.Interval = val - } - if flags.Changed(flagHealthTimeout) { - val := *flags.Lookup(flagHealthTimeout).Value.(*PositiveDurationOpt).Value() - containerSpec.Healthcheck.Timeout = val - } - if flags.Changed(flagHealthRetries) { - containerSpec.Healthcheck.Retries, _ = flags.GetInt(flagHealthRetries) - } - if flags.Changed(flagHealthCmd) { - cmd, _ := flags.GetString(flagHealthCmd) - if cmd != "" { - containerSpec.Healthcheck.Test = []string{"CMD-SHELL", cmd} - } else { - containerSpec.Healthcheck.Test = nil - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/service/update_test.go b/vendor/github.com/docker/docker/cli/command/service/update_test.go deleted file mode 100644 index 08fe248..0000000 --- a/vendor/github.com/docker/docker/cli/command/service/update_test.go +++ /dev/null @@ -1,384 +0,0 @@ -package service - -import ( - "reflect" - "sort" - "testing" - "time" - - "github.com/docker/docker/api/types/container" - mounttypes "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestUpdateServiceArgs(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("args", "the \"new args\"") - - spec := &swarm.ServiceSpec{} - cspec := &spec.TaskTemplate.ContainerSpec - cspec.Args = []string{"old", "args"} - - updateService(flags, spec) - assert.EqualStringSlice(t, cspec.Args, []string{"the", "new args"}) -} - -func TestUpdateLabels(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("label-add", "toadd=newlabel") - flags.Set("label-rm", "toremove") - - labels := map[string]string{ - "toremove": "thelabeltoremove", - "tokeep": "value", - } - - updateLabels(flags, &labels) - assert.Equal(t, len(labels), 2) - assert.Equal(t, labels["tokeep"], "value") - assert.Equal(t, labels["toadd"], "newlabel") -} - -func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("label-rm", "dne") - - labels := map[string]string{"foo": "theoldlabel"} - updateLabels(flags, &labels) - assert.Equal(t, len(labels), 1) -} - -func TestUpdatePlacement(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("constraint-add", "node=toadd") - flags.Set("constraint-rm", "node!=toremove") - - placement := &swarm.Placement{ - Constraints: []string{"node!=toremove", "container=tokeep"}, - } - - updatePlacement(flags, placement) - assert.Equal(t, len(placement.Constraints), 2) - assert.Equal(t, placement.Constraints[0], "container=tokeep") - assert.Equal(t, placement.Constraints[1], "node=toadd") -} - -func TestUpdateEnvironment(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("env-add", "toadd=newenv") - flags.Set("env-rm", "toremove") - - envs := []string{"toremove=theenvtoremove", "tokeep=value"} - - updateEnvironment(flags, &envs) - assert.Equal(t, len(envs), 2) - // Order has been removed in updateEnvironment (map) - sort.Strings(envs) - assert.Equal(t, envs[0], "toadd=newenv") - assert.Equal(t, envs[1], "tokeep=value") -} - -func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("env-add", "foo=newenv") - flags.Set("env-add", "foo=dupe") - flags.Set("env-rm", "foo") - - envs := []string{"foo=value"} - - updateEnvironment(flags, &envs) - assert.Equal(t, len(envs), 0) -} - -func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) { - // Test case for #25404 - flags := newUpdateCommand(nil).Flags() - flags.Set("env-add", "A=b") - - envs := []string{"A=c"} - - updateEnvironment(flags, &envs) - assert.Equal(t, len(envs), 1) - assert.Equal(t, envs[0], "A=b") -} - -func TestUpdateGroups(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("group-add", "wheel") - flags.Set("group-add", "docker") - flags.Set("group-rm", "root") - flags.Set("group-add", "foo") - flags.Set("group-rm", "docker") - - groups := []string{"bar", "root"} - - updateGroups(flags, &groups) - assert.Equal(t, len(groups), 3) - assert.Equal(t, groups[0], "bar") - assert.Equal(t, groups[1], "foo") - assert.Equal(t, groups[2], "wheel") -} - -func TestUpdateDNSConfig(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - - // IPv4, with duplicates - flags.Set("dns-add", "1.1.1.1") - flags.Set("dns-add", "1.1.1.1") - flags.Set("dns-add", "2.2.2.2") - flags.Set("dns-rm", "3.3.3.3") - flags.Set("dns-rm", "2.2.2.2") - // IPv6 - flags.Set("dns-add", "2001:db8:abc8::1") - // Invalid dns record - assert.Error(t, flags.Set("dns-add", "x.y.z.w"), "x.y.z.w is not an ip address") - - // domains with duplicates - flags.Set("dns-search-add", "example.com") - flags.Set("dns-search-add", "example.com") - flags.Set("dns-search-add", "example.org") - flags.Set("dns-search-rm", "example.org") - // Invalid dns search domain - assert.Error(t, flags.Set("dns-search-add", "example$com"), "example$com is not a valid domain") - - flags.Set("dns-option-add", "ndots:9") - flags.Set("dns-option-rm", "timeout:3") - - config := &swarm.DNSConfig{ - Nameservers: []string{"3.3.3.3", "5.5.5.5"}, - Search: []string{"localdomain"}, - Options: []string{"timeout:3"}, - } - - updateDNSConfig(flags, &config) - - assert.Equal(t, len(config.Nameservers), 3) - assert.Equal(t, config.Nameservers[0], "1.1.1.1") - assert.Equal(t, config.Nameservers[1], "2001:db8:abc8::1") - assert.Equal(t, config.Nameservers[2], "5.5.5.5") - - assert.Equal(t, len(config.Search), 2) - assert.Equal(t, config.Search[0], "example.com") - assert.Equal(t, config.Search[1], "localdomain") - - assert.Equal(t, len(config.Options), 1) - assert.Equal(t, config.Options[0], "ndots:9") -} - -func TestUpdateMounts(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("mount-add", "type=volume,source=vol2,target=/toadd") - flags.Set("mount-rm", "/toremove") - - mounts := []mounttypes.Mount{ - {Target: "/toremove", Source: "vol1", Type: mounttypes.TypeBind}, - {Target: "/tokeep", Source: "vol3", Type: mounttypes.TypeBind}, - } - - updateMounts(flags, &mounts) - assert.Equal(t, len(mounts), 2) - assert.Equal(t, mounts[0].Target, "/toadd") - assert.Equal(t, mounts[1].Target, "/tokeep") - -} - -func TestUpdateMountsWithDuplicateMounts(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("mount-add", "type=volume,source=vol4,target=/toadd") - - mounts := []mounttypes.Mount{ - {Target: "/tokeep1", Source: "vol1", Type: mounttypes.TypeBind}, - {Target: "/toadd", Source: "vol2", Type: mounttypes.TypeBind}, - {Target: "/tokeep2", Source: "vol3", Type: mounttypes.TypeBind}, - } - - updateMounts(flags, &mounts) - assert.Equal(t, len(mounts), 3) - assert.Equal(t, mounts[0].Target, "/tokeep1") - assert.Equal(t, mounts[1].Target, "/tokeep2") - assert.Equal(t, mounts[2].Target, "/toadd") -} - -func TestUpdatePorts(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("publish-add", "1000:1000") - flags.Set("publish-rm", "333/udp") - - portConfigs := []swarm.PortConfig{ - {TargetPort: 333, Protocol: swarm.PortConfigProtocolUDP}, - {TargetPort: 555}, - } - - err := updatePorts(flags, &portConfigs) - assert.Equal(t, err, nil) - assert.Equal(t, len(portConfigs), 2) - // Do a sort to have the order (might have changed by map) - targetPorts := []int{int(portConfigs[0].TargetPort), int(portConfigs[1].TargetPort)} - sort.Ints(targetPorts) - assert.Equal(t, targetPorts[0], 555) - assert.Equal(t, targetPorts[1], 1000) -} - -func TestUpdatePortsDuplicate(t *testing.T) { - // Test case for #25375 - flags := newUpdateCommand(nil).Flags() - flags.Set("publish-add", "80:80") - - portConfigs := []swarm.PortConfig{ - { - TargetPort: 80, - PublishedPort: 80, - Protocol: swarm.PortConfigProtocolTCP, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - } - - err := updatePorts(flags, &portConfigs) - assert.Equal(t, err, nil) - assert.Equal(t, len(portConfigs), 1) - assert.Equal(t, portConfigs[0].TargetPort, uint32(80)) -} - -func TestUpdateHealthcheckTable(t *testing.T) { - type test struct { - flags [][2]string - initial *container.HealthConfig - expected *container.HealthConfig - err string - } - testCases := []test{ - { - flags: [][2]string{{"no-healthcheck", "true"}}, - initial: &container.HealthConfig{Test: []string{"CMD-SHELL", "cmd1"}, Retries: 10}, - expected: &container.HealthConfig{Test: []string{"NONE"}}, - }, - { - flags: [][2]string{{"health-cmd", "cmd1"}}, - initial: &container.HealthConfig{Test: []string{"NONE"}}, - expected: &container.HealthConfig{Test: []string{"CMD-SHELL", "cmd1"}}, - }, - { - flags: [][2]string{{"health-retries", "10"}}, - initial: &container.HealthConfig{Test: []string{"NONE"}}, - expected: &container.HealthConfig{Retries: 10}, - }, - { - flags: [][2]string{{"health-retries", "10"}}, - initial: &container.HealthConfig{Test: []string{"CMD", "cmd1"}}, - expected: &container.HealthConfig{Test: []string{"CMD", "cmd1"}, Retries: 10}, - }, - { - flags: [][2]string{{"health-interval", "1m"}}, - initial: &container.HealthConfig{Test: []string{"CMD", "cmd1"}}, - expected: &container.HealthConfig{Test: []string{"CMD", "cmd1"}, Interval: time.Minute}, - }, - { - flags: [][2]string{{"health-cmd", ""}}, - initial: &container.HealthConfig{Test: []string{"CMD", "cmd1"}, Retries: 10}, - expected: &container.HealthConfig{Retries: 10}, - }, - { - flags: [][2]string{{"health-retries", "0"}}, - initial: &container.HealthConfig{Test: []string{"CMD", "cmd1"}, Retries: 10}, - expected: &container.HealthConfig{Test: []string{"CMD", "cmd1"}}, - }, - { - flags: [][2]string{{"health-cmd", "cmd1"}, {"no-healthcheck", "true"}}, - err: "--no-healthcheck conflicts with --health-* options", - }, - { - flags: [][2]string{{"health-interval", "10m"}, {"no-healthcheck", "true"}}, - err: "--no-healthcheck conflicts with --health-* options", - }, - { - flags: [][2]string{{"health-timeout", "1m"}, {"no-healthcheck", "true"}}, - err: "--no-healthcheck conflicts with --health-* options", - }, - } - for i, c := range testCases { - flags := newUpdateCommand(nil).Flags() - for _, flag := range c.flags { - flags.Set(flag[0], flag[1]) - } - cspec := &swarm.ContainerSpec{ - Healthcheck: c.initial, - } - err := updateHealthcheck(flags, cspec) - if c.err != "" { - assert.Error(t, err, c.err) - } else { - assert.NilError(t, err) - if !reflect.DeepEqual(cspec.Healthcheck, c.expected) { - t.Errorf("incorrect result for test %d, expected health config:\n\t%#v\ngot:\n\t%#v", i, c.expected, cspec.Healthcheck) - } - } - } -} - -func TestUpdateHosts(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("host-add", "example.net:2.2.2.2") - flags.Set("host-add", "ipv6.net:2001:db8:abc8::1") - // remove with ipv6 should work - flags.Set("host-rm", "example.net:2001:db8:abc8::1") - // just hostname should work as well - flags.Set("host-rm", "example.net") - // bad format error - assert.Error(t, flags.Set("host-add", "$example.com$"), "bad format for add-host:") - - hosts := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 example.net"} - - updateHosts(flags, &hosts) - assert.Equal(t, len(hosts), 3) - assert.Equal(t, hosts[0], "1.2.3.4 example.com") - assert.Equal(t, hosts[1], "2001:db8:abc8::1 ipv6.net") - assert.Equal(t, hosts[2], "4.3.2.1 example.org") -} - -func TestUpdatePortsRmWithProtocol(t *testing.T) { - flags := newUpdateCommand(nil).Flags() - flags.Set("publish-add", "8081:81") - flags.Set("publish-add", "8082:82") - flags.Set("publish-rm", "80") - flags.Set("publish-rm", "81/tcp") - flags.Set("publish-rm", "82/udp") - - portConfigs := []swarm.PortConfig{ - { - TargetPort: 80, - PublishedPort: 8080, - Protocol: swarm.PortConfigProtocolTCP, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - } - - err := updatePorts(flags, &portConfigs) - assert.Equal(t, err, nil) - assert.Equal(t, len(portConfigs), 2) - assert.Equal(t, portConfigs[0].TargetPort, uint32(81)) - assert.Equal(t, portConfigs[1].TargetPort, uint32(82)) -} - -// FIXME(vdemeester) port to opts.PortOpt -func TestValidatePort(t *testing.T) { - validPorts := []string{"80/tcp", "80", "80/udp"} - invalidPorts := map[string]string{ - "9999999": "out of range", - "80:80/tcp": "invalid port format", - "53:53/udp": "invalid port format", - "80:80": "invalid port format", - "80/xyz": "invalid protocol", - "tcp": "invalid syntax", - "udp": "invalid syntax", - "": "invalid protocol", - } - for _, port := range validPorts { - _, err := validatePublishRemove(port) - assert.Equal(t, err, nil) - } - for port, e := range invalidPorts { - _, err := validatePublishRemove(port) - assert.Error(t, err, e) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/stack/cmd.go b/vendor/github.com/docker/docker/cli/command/stack/cmd.go deleted file mode 100644 index 860bfed..0000000 --- a/vendor/github.com/docker/docker/cli/command/stack/cmd.go +++ /dev/null @@ -1,35 +0,0 @@ -package stack - -import ( - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -// NewStackCommand returns a cobra command for `stack` subcommands -func NewStackCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "stack", - Short: "Manage Docker stacks", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - Tags: map[string]string{"version": "1.25"}, - } - cmd.AddCommand( - newDeployCommand(dockerCli), - newListCommand(dockerCli), - newRemoveCommand(dockerCli), - newServicesCommand(dockerCli), - newPsCommand(dockerCli), - ) - return cmd -} - -// NewTopLevelDeployCommand returns a command for `docker deploy` -func NewTopLevelDeployCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := newDeployCommand(dockerCli) - // Remove the aliases at the top level - cmd.Aliases = []string{} - cmd.Tags = map[string]string{"experimental": "", "version": "1.25"} - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/stack/common.go b/vendor/github.com/docker/docker/cli/command/stack/common.go deleted file mode 100644 index 72719f9..0000000 --- a/vendor/github.com/docker/docker/cli/command/stack/common.go +++ /dev/null @@ -1,60 +0,0 @@ -package stack - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli/compose/convert" - "github.com/docker/docker/client" - "github.com/docker/docker/opts" -) - -func getStackFilter(namespace string) filters.Args { - filter := filters.NewArgs() - filter.Add("label", convert.LabelNamespace+"="+namespace) - return filter -} - -func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args { - filter := opt.Value() - filter.Add("label", convert.LabelNamespace+"="+namespace) - return filter -} - -func getAllStacksFilter() filters.Args { - filter := filters.NewArgs() - filter.Add("label", convert.LabelNamespace) - return filter -} - -func getServices( - ctx context.Context, - apiclient client.APIClient, - namespace string, -) ([]swarm.Service, error) { - return apiclient.ServiceList( - ctx, - types.ServiceListOptions{Filters: getStackFilter(namespace)}) -} - -func getStackNetworks( - ctx context.Context, - apiclient client.APIClient, - namespace string, -) ([]types.NetworkResource, error) { - return apiclient.NetworkList( - ctx, - types.NetworkListOptions{Filters: getStackFilter(namespace)}) -} - -func getStackSecrets( - ctx context.Context, - apiclient client.APIClient, - namespace string, -) ([]swarm.Secret, error) { - return apiclient.SecretList( - ctx, - types.SecretListOptions{Filters: getStackFilter(namespace)}) -} diff --git a/vendor/github.com/docker/docker/cli/command/stack/deploy.go b/vendor/github.com/docker/docker/cli/command/stack/deploy.go deleted file mode 100644 index 980876a..0000000 --- a/vendor/github.com/docker/docker/cli/command/stack/deploy.go +++ /dev/null @@ -1,357 +0,0 @@ -package stack - -import ( - "fmt" - "io/ioutil" - "os" - "sort" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - secretcli "github.com/docker/docker/cli/command/secret" - "github.com/docker/docker/cli/compose/convert" - "github.com/docker/docker/cli/compose/loader" - composetypes "github.com/docker/docker/cli/compose/types" - dockerclient "github.com/docker/docker/client" - "github.com/pkg/errors" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -const ( - defaultNetworkDriver = "overlay" -) - -type deployOptions struct { - bundlefile string - composefile string - namespace string - sendRegistryAuth bool -} - -func newDeployCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts deployOptions - - cmd := &cobra.Command{ - Use: "deploy [OPTIONS] STACK", - Aliases: []string{"up"}, - Short: "Deploy a new stack or update an existing stack", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.namespace = args[0] - return runDeploy(dockerCli, opts) - }, - } - - flags := cmd.Flags() - addBundlefileFlag(&opts.bundlefile, flags) - addComposefileFlag(&opts.composefile, flags) - addRegistryAuthFlag(&opts.sendRegistryAuth, flags) - return cmd -} - -func runDeploy(dockerCli *command.DockerCli, opts deployOptions) error { - ctx := context.Background() - - switch { - case opts.bundlefile == "" && opts.composefile == "": - return fmt.Errorf("Please specify either a bundle file (with --bundle-file) or a Compose file (with --compose-file).") - case opts.bundlefile != "" && opts.composefile != "": - return fmt.Errorf("You cannot specify both a bundle file and a Compose file.") - case opts.bundlefile != "": - return deployBundle(ctx, dockerCli, opts) - default: - return deployCompose(ctx, dockerCli, opts) - } -} - -// checkDaemonIsSwarmManager does an Info API call to verify that the daemon is -// a swarm manager. This is necessary because we must create networks before we -// create services, but the API call for creating a network does not return a -// proper status code when it can't create a network in the "global" scope. -func checkDaemonIsSwarmManager(ctx context.Context, dockerCli *command.DockerCli) error { - info, err := dockerCli.Client().Info(ctx) - if err != nil { - return err - } - if !info.Swarm.ControlAvailable { - return errors.New("This node is not a swarm manager. Use \"docker swarm init\" or \"docker swarm join\" to connect this node to swarm and try again.") - } - return nil -} - -func deployCompose(ctx context.Context, dockerCli *command.DockerCli, opts deployOptions) error { - configDetails, err := getConfigDetails(opts) - if err != nil { - return err - } - - config, err := loader.Load(configDetails) - if err != nil { - if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok { - return fmt.Errorf("Compose file contains unsupported options:\n\n%s\n", - propertyWarnings(fpe.Properties)) - } - - return err - } - - unsupportedProperties := loader.GetUnsupportedProperties(configDetails) - if len(unsupportedProperties) > 0 { - fmt.Fprintf(dockerCli.Err(), "Ignoring unsupported options: %s\n\n", - strings.Join(unsupportedProperties, ", ")) - } - - deprecatedProperties := loader.GetDeprecatedProperties(configDetails) - if len(deprecatedProperties) > 0 { - fmt.Fprintf(dockerCli.Err(), "Ignoring deprecated options:\n\n%s\n\n", - propertyWarnings(deprecatedProperties)) - } - - if err := checkDaemonIsSwarmManager(ctx, dockerCli); err != nil { - return err - } - - namespace := convert.NewNamespace(opts.namespace) - - serviceNetworks := getServicesDeclaredNetworks(config.Services) - networks, externalNetworks := convert.Networks(namespace, config.Networks, serviceNetworks) - if err := validateExternalNetworks(ctx, dockerCli, externalNetworks); err != nil { - return err - } - if err := createNetworks(ctx, dockerCli, namespace, networks); err != nil { - return err - } - - secrets, err := convert.Secrets(namespace, config.Secrets) - if err != nil { - return err - } - if err := createSecrets(ctx, dockerCli, namespace, secrets); err != nil { - return err - } - - services, err := convert.Services(namespace, config, dockerCli.Client()) - if err != nil { - return err - } - return deployServices(ctx, dockerCli, services, namespace, opts.sendRegistryAuth) -} -func getServicesDeclaredNetworks(serviceConfigs []composetypes.ServiceConfig) map[string]struct{} { - serviceNetworks := map[string]struct{}{} - for _, serviceConfig := range serviceConfigs { - if len(serviceConfig.Networks) == 0 { - serviceNetworks["default"] = struct{}{} - continue - } - for network := range serviceConfig.Networks { - serviceNetworks[network] = struct{}{} - } - } - return serviceNetworks -} - -func propertyWarnings(properties map[string]string) string { - var msgs []string - for name, description := range properties { - msgs = append(msgs, fmt.Sprintf("%s: %s", name, description)) - } - sort.Strings(msgs) - return strings.Join(msgs, "\n\n") -} - -func getConfigDetails(opts deployOptions) (composetypes.ConfigDetails, error) { - var details composetypes.ConfigDetails - var err error - - details.WorkingDir, err = os.Getwd() - if err != nil { - return details, err - } - - configFile, err := getConfigFile(opts.composefile) - if err != nil { - return details, err - } - // TODO: support multiple files - details.ConfigFiles = []composetypes.ConfigFile{*configFile} - return details, nil -} - -func getConfigFile(filename string) (*composetypes.ConfigFile, error) { - bytes, err := ioutil.ReadFile(filename) - if err != nil { - return nil, err - } - config, err := loader.ParseYAML(bytes) - if err != nil { - return nil, err - } - return &composetypes.ConfigFile{ - Filename: filename, - Config: config, - }, nil -} - -func validateExternalNetworks( - ctx context.Context, - dockerCli *command.DockerCli, - externalNetworks []string) error { - client := dockerCli.Client() - - for _, networkName := range externalNetworks { - network, err := client.NetworkInspect(ctx, networkName) - if err != nil { - if dockerclient.IsErrNetworkNotFound(err) { - return fmt.Errorf("network %q is declared as external, but could not be found. You need to create the network before the stack is deployed (with overlay driver)", networkName) - } - return err - } - if network.Scope != "swarm" { - return fmt.Errorf("network %q is declared as external, but it is not in the right scope: %q instead of %q", networkName, network.Scope, "swarm") - } - } - - return nil -} - -func createSecrets( - ctx context.Context, - dockerCli *command.DockerCli, - namespace convert.Namespace, - secrets []swarm.SecretSpec, -) error { - client := dockerCli.Client() - - for _, secretSpec := range secrets { - // TODO: fix this after https://github.com/docker/docker/pull/29218 - secrets, err := secretcli.GetSecretsByNameOrIDPrefixes(ctx, client, []string{secretSpec.Name}) - switch { - case err != nil: - return err - case len(secrets) > 1: - return errors.Errorf("ambiguous secret name: %s", secretSpec.Name) - case len(secrets) == 0: - fmt.Fprintf(dockerCli.Out(), "Creating secret %s\n", secretSpec.Name) - _, err = client.SecretCreate(ctx, secretSpec) - default: - secret := secrets[0] - // Update secret to ensure that the local data hasn't changed - err = client.SecretUpdate(ctx, secret.ID, secret.Meta.Version, secretSpec) - } - if err != nil { - return err - } - } - return nil -} - -func createNetworks( - ctx context.Context, - dockerCli *command.DockerCli, - namespace convert.Namespace, - networks map[string]types.NetworkCreate, -) error { - client := dockerCli.Client() - - existingNetworks, err := getStackNetworks(ctx, client, namespace.Name()) - if err != nil { - return err - } - - existingNetworkMap := make(map[string]types.NetworkResource) - for _, network := range existingNetworks { - existingNetworkMap[network.Name] = network - } - - for internalName, createOpts := range networks { - name := namespace.Scope(internalName) - if _, exists := existingNetworkMap[name]; exists { - continue - } - - if createOpts.Driver == "" { - createOpts.Driver = defaultNetworkDriver - } - - fmt.Fprintf(dockerCli.Out(), "Creating network %s\n", name) - if _, err := client.NetworkCreate(ctx, name, createOpts); err != nil { - return err - } - } - - return nil -} - -func deployServices( - ctx context.Context, - dockerCli *command.DockerCli, - services map[string]swarm.ServiceSpec, - namespace convert.Namespace, - sendAuth bool, -) error { - apiClient := dockerCli.Client() - out := dockerCli.Out() - - existingServices, err := getServices(ctx, apiClient, namespace.Name()) - if err != nil { - return err - } - - existingServiceMap := make(map[string]swarm.Service) - for _, service := range existingServices { - existingServiceMap[service.Spec.Name] = service - } - - for internalName, serviceSpec := range services { - name := namespace.Scope(internalName) - - encodedAuth := "" - if sendAuth { - // Retrieve encoded auth token from the image reference - image := serviceSpec.TaskTemplate.ContainerSpec.Image - encodedAuth, err = command.RetrieveAuthTokenFromImage(ctx, dockerCli, image) - if err != nil { - return err - } - } - - if service, exists := existingServiceMap[name]; exists { - fmt.Fprintf(out, "Updating service %s (id: %s)\n", name, service.ID) - - updateOpts := types.ServiceUpdateOptions{} - if sendAuth { - updateOpts.EncodedRegistryAuth = encodedAuth - } - response, err := apiClient.ServiceUpdate( - ctx, - service.ID, - service.Version, - serviceSpec, - updateOpts, - ) - if err != nil { - return err - } - - for _, warning := range response.Warnings { - fmt.Fprintln(dockerCli.Err(), warning) - } - } else { - fmt.Fprintf(out, "Creating service %s\n", name) - - createOpts := types.ServiceCreateOptions{} - if sendAuth { - createOpts.EncodedRegistryAuth = encodedAuth - } - if _, err := apiClient.ServiceCreate(ctx, serviceSpec, createOpts); err != nil { - return err - } - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/stack/deploy_bundlefile.go b/vendor/github.com/docker/docker/cli/command/stack/deploy_bundlefile.go deleted file mode 100644 index 5a178c4..0000000 --- a/vendor/github.com/docker/docker/cli/command/stack/deploy_bundlefile.go +++ /dev/null @@ -1,83 +0,0 @@ -package stack - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/compose/convert" -) - -func deployBundle(ctx context.Context, dockerCli *command.DockerCli, opts deployOptions) error { - bundle, err := loadBundlefile(dockerCli.Err(), opts.namespace, opts.bundlefile) - if err != nil { - return err - } - - if err := checkDaemonIsSwarmManager(ctx, dockerCli); err != nil { - return err - } - - namespace := convert.NewNamespace(opts.namespace) - - networks := make(map[string]types.NetworkCreate) - for _, service := range bundle.Services { - for _, networkName := range service.Networks { - networks[networkName] = types.NetworkCreate{ - Labels: convert.AddStackLabel(namespace, nil), - } - } - } - - services := make(map[string]swarm.ServiceSpec) - for internalName, service := range bundle.Services { - name := namespace.Scope(internalName) - - var ports []swarm.PortConfig - for _, portSpec := range service.Ports { - ports = append(ports, swarm.PortConfig{ - Protocol: swarm.PortConfigProtocol(portSpec.Protocol), - TargetPort: portSpec.Port, - }) - } - - nets := []swarm.NetworkAttachmentConfig{} - for _, networkName := range service.Networks { - nets = append(nets, swarm.NetworkAttachmentConfig{ - Target: namespace.Scope(networkName), - Aliases: []string{networkName}, - }) - } - - serviceSpec := swarm.ServiceSpec{ - Annotations: swarm.Annotations{ - Name: name, - Labels: convert.AddStackLabel(namespace, service.Labels), - }, - TaskTemplate: swarm.TaskSpec{ - ContainerSpec: swarm.ContainerSpec{ - Image: service.Image, - Command: service.Command, - Args: service.Args, - Env: service.Env, - // Service Labels will not be copied to Containers - // automatically during the deployment so we apply - // it here. - Labels: convert.AddStackLabel(namespace, nil), - }, - }, - EndpointSpec: &swarm.EndpointSpec{ - Ports: ports, - }, - Networks: nets, - } - - services[internalName] = serviceSpec - } - - if err := createNetworks(ctx, dockerCli, namespace, networks); err != nil { - return err - } - return deployServices(ctx, dockerCli, services, namespace, opts.sendRegistryAuth) -} diff --git a/vendor/github.com/docker/docker/cli/command/stack/list.go b/vendor/github.com/docker/docker/cli/command/stack/list.go deleted file mode 100644 index 9b6c645..0000000 --- a/vendor/github.com/docker/docker/cli/command/stack/list.go +++ /dev/null @@ -1,113 +0,0 @@ -package stack - -import ( - "fmt" - "io" - "strconv" - "text/tabwriter" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/compose/convert" - "github.com/docker/docker/client" - "github.com/spf13/cobra" -) - -const ( - listItemFmt = "%s\t%s\n" -) - -type listOptions struct { -} - -func newListCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := listOptions{} - - cmd := &cobra.Command{ - Use: "ls", - Aliases: []string{"list"}, - Short: "List stacks", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runList(dockerCli, opts) - }, - } - - return cmd -} - -func runList(dockerCli *command.DockerCli, opts listOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - stacks, err := getStacks(ctx, client) - if err != nil { - return err - } - - out := dockerCli.Out() - printTable(out, stacks) - return nil -} - -func printTable(out io.Writer, stacks []*stack) { - writer := tabwriter.NewWriter(out, 0, 4, 2, ' ', 0) - - // Ignore flushing errors - defer writer.Flush() - - fmt.Fprintf(writer, listItemFmt, "NAME", "SERVICES") - for _, stack := range stacks { - fmt.Fprintf( - writer, - listItemFmt, - stack.Name, - strconv.Itoa(stack.Services), - ) - } -} - -type stack struct { - // Name is the name of the stack - Name string - // Services is the number of the services - Services int -} - -func getStacks( - ctx context.Context, - apiclient client.APIClient, -) ([]*stack, error) { - services, err := apiclient.ServiceList( - ctx, - types.ServiceListOptions{Filters: getAllStacksFilter()}) - if err != nil { - return nil, err - } - m := make(map[string]*stack, 0) - for _, service := range services { - labels := service.Spec.Labels - name, ok := labels[convert.LabelNamespace] - if !ok { - return nil, fmt.Errorf("cannot get label %s for service %s", - convert.LabelNamespace, service.ID) - } - ztack, ok := m[name] - if !ok { - m[name] = &stack{ - Name: name, - Services: 1, - } - } else { - ztack.Services++ - } - } - var stacks []*stack - for _, stack := range m { - stacks = append(stacks, stack) - } - return stacks, nil -} diff --git a/vendor/github.com/docker/docker/cli/command/stack/opts.go b/vendor/github.com/docker/docker/cli/command/stack/opts.go deleted file mode 100644 index 74fe4f5..0000000 --- a/vendor/github.com/docker/docker/cli/command/stack/opts.go +++ /dev/null @@ -1,49 +0,0 @@ -package stack - -import ( - "fmt" - "io" - "os" - - "github.com/docker/docker/cli/command/bundlefile" - "github.com/spf13/pflag" -) - -func addComposefileFlag(opt *string, flags *pflag.FlagSet) { - flags.StringVarP(opt, "compose-file", "c", "", "Path to a Compose file") -} - -func addBundlefileFlag(opt *string, flags *pflag.FlagSet) { - flags.StringVar(opt, "bundle-file", "", "Path to a Distributed Application Bundle file") - flags.SetAnnotation("bundle-file", "experimental", nil) -} - -func addRegistryAuthFlag(opt *bool, flags *pflag.FlagSet) { - flags.BoolVar(opt, "with-registry-auth", false, "Send registry authentication details to Swarm agents") -} - -func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefile.Bundlefile, error) { - defaultPath := fmt.Sprintf("%s.dab", namespace) - - if path == "" { - path = defaultPath - } - if _, err := os.Stat(path); err != nil { - return nil, fmt.Errorf( - "Bundle %s not found. Specify the path with --file", - path) - } - - fmt.Fprintf(stderr, "Loading bundle from %s\n", path) - reader, err := os.Open(path) - if err != nil { - return nil, err - } - defer reader.Close() - - bundle, err := bundlefile.LoadFile(reader) - if err != nil { - return nil, fmt.Errorf("Error reading %s: %v\n", path, err) - } - return bundle, err -} diff --git a/vendor/github.com/docker/docker/cli/command/stack/ps.go b/vendor/github.com/docker/docker/cli/command/stack/ps.go deleted file mode 100644 index e4351bf..0000000 --- a/vendor/github.com/docker/docker/cli/command/stack/ps.go +++ /dev/null @@ -1,61 +0,0 @@ -package stack - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/idresolver" - "github.com/docker/docker/cli/command/task" - "github.com/docker/docker/opts" - "github.com/spf13/cobra" -) - -type psOptions struct { - filter opts.FilterOpt - noTrunc bool - namespace string - noResolve bool -} - -func newPsCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := psOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "ps [OPTIONS] STACK", - Short: "List the tasks in the stack", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.namespace = args[0] - return runPS(dockerCli, opts) - }, - } - flags := cmd.Flags() - flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") - flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") - flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") - - return cmd -} - -func runPS(dockerCli *command.DockerCli, opts psOptions) error { - namespace := opts.namespace - client := dockerCli.Client() - ctx := context.Background() - - filter := getStackFilterFromOpt(opts.namespace, opts.filter) - tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter}) - if err != nil { - return err - } - - if len(tasks) == 0 { - fmt.Fprintf(dockerCli.Out(), "Nothing found in stack: %s\n", namespace) - return nil - } - - return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve), opts.noTrunc) -} diff --git a/vendor/github.com/docker/docker/cli/command/stack/remove.go b/vendor/github.com/docker/docker/cli/command/stack/remove.go deleted file mode 100644 index 966c1aa..0000000 --- a/vendor/github.com/docker/docker/cli/command/stack/remove.go +++ /dev/null @@ -1,112 +0,0 @@ -package stack - -import ( - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type removeOptions struct { - namespace string -} - -func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts removeOptions - - cmd := &cobra.Command{ - Use: "rm STACK", - Aliases: []string{"remove", "down"}, - Short: "Remove the stack", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.namespace = args[0] - return runRemove(dockerCli, opts) - }, - } - return cmd -} - -func runRemove(dockerCli *command.DockerCli, opts removeOptions) error { - namespace := opts.namespace - client := dockerCli.Client() - ctx := context.Background() - - services, err := getServices(ctx, client, namespace) - if err != nil { - return err - } - - networks, err := getStackNetworks(ctx, client, namespace) - if err != nil { - return err - } - - secrets, err := getStackSecrets(ctx, client, namespace) - if err != nil { - return err - } - - if len(services)+len(networks)+len(secrets) == 0 { - fmt.Fprintf(dockerCli.Out(), "Nothing found in stack: %s\n", namespace) - return nil - } - - hasError := removeServices(ctx, dockerCli, services) - hasError = removeSecrets(ctx, dockerCli, secrets) || hasError - hasError = removeNetworks(ctx, dockerCli, networks) || hasError - - if hasError { - return fmt.Errorf("Failed to remove some resources") - } - return nil -} - -func removeServices( - ctx context.Context, - dockerCli *command.DockerCli, - services []swarm.Service, -) bool { - var err error - for _, service := range services { - fmt.Fprintf(dockerCli.Err(), "Removing service %s\n", service.Spec.Name) - if err = dockerCli.Client().ServiceRemove(ctx, service.ID); err != nil { - fmt.Fprintf(dockerCli.Err(), "Failed to remove service %s: %s", service.ID, err) - } - } - return err != nil -} - -func removeNetworks( - ctx context.Context, - dockerCli *command.DockerCli, - networks []types.NetworkResource, -) bool { - var err error - for _, network := range networks { - fmt.Fprintf(dockerCli.Err(), "Removing network %s\n", network.Name) - if err = dockerCli.Client().NetworkRemove(ctx, network.ID); err != nil { - fmt.Fprintf(dockerCli.Err(), "Failed to remove network %s: %s", network.ID, err) - } - } - return err != nil -} - -func removeSecrets( - ctx context.Context, - dockerCli *command.DockerCli, - secrets []swarm.Secret, -) bool { - var err error - for _, secret := range secrets { - fmt.Fprintf(dockerCli.Err(), "Removing secret %s\n", secret.Spec.Name) - if err = dockerCli.Client().SecretRemove(ctx, secret.ID); err != nil { - fmt.Fprintf(dockerCli.Err(), "Failed to remove secret %s: %s", secret.ID, err) - } - } - return err != nil -} diff --git a/vendor/github.com/docker/docker/cli/command/stack/services.go b/vendor/github.com/docker/docker/cli/command/stack/services.go deleted file mode 100644 index a46652d..0000000 --- a/vendor/github.com/docker/docker/cli/command/stack/services.go +++ /dev/null @@ -1,79 +0,0 @@ -package stack - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/service" - "github.com/docker/docker/opts" - "github.com/spf13/cobra" -) - -type servicesOptions struct { - quiet bool - filter opts.FilterOpt - namespace string -} - -func newServicesCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := servicesOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "services [OPTIONS] STACK", - Short: "List the services in the stack", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.namespace = args[0] - return runServices(dockerCli, opts) - }, - } - flags := cmd.Flags() - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs") - flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") - - return cmd -} - -func runServices(dockerCli *command.DockerCli, opts servicesOptions) error { - ctx := context.Background() - client := dockerCli.Client() - - filter := getStackFilterFromOpt(opts.namespace, opts.filter) - services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: filter}) - if err != nil { - return err - } - - out := dockerCli.Out() - - // if no services in this stack, print message and exit 0 - if len(services) == 0 { - fmt.Fprintf(out, "Nothing found in stack: %s\n", opts.namespace) - return nil - } - - if opts.quiet { - service.PrintQuiet(out, services) - } else { - taskFilter := filters.NewArgs() - for _, service := range services { - taskFilter.Add("service", service.ID) - } - - tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: taskFilter}) - if err != nil { - return err - } - nodes, err := client.NodeList(ctx, types.NodeListOptions{}) - if err != nil { - return err - } - service.PrintNotQuiet(out, services, nodes, tasks) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/swarm/cmd.go b/vendor/github.com/docker/docker/cli/command/swarm/cmd.go deleted file mode 100644 index 632679c..0000000 --- a/vendor/github.com/docker/docker/cli/command/swarm/cmd.go +++ /dev/null @@ -1,28 +0,0 @@ -package swarm - -import ( - "github.com/spf13/cobra" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" -) - -// NewSwarmCommand returns a cobra command for `swarm` subcommands -func NewSwarmCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "swarm", - Short: "Manage Swarm", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - } - cmd.AddCommand( - newInitCommand(dockerCli), - newJoinCommand(dockerCli), - newJoinTokenCommand(dockerCli), - newUnlockKeyCommand(dockerCli), - newUpdateCommand(dockerCli), - newLeaveCommand(dockerCli), - newUnlockCommand(dockerCli), - ) - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/swarm/init.go b/vendor/github.com/docker/docker/cli/command/swarm/init.go deleted file mode 100644 index 2550fee..0000000 --- a/vendor/github.com/docker/docker/cli/command/swarm/init.go +++ /dev/null @@ -1,85 +0,0 @@ -package swarm - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/pkg/errors" - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -type initOptions struct { - swarmOptions - listenAddr NodeAddrOption - // Not a NodeAddrOption because it has no default port. - advertiseAddr string - forceNewCluster bool -} - -func newInitCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := initOptions{ - listenAddr: NewListenAddrOption(), - } - - cmd := &cobra.Command{ - Use: "init [OPTIONS]", - Short: "Initialize a swarm", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runInit(dockerCli, cmd.Flags(), opts) - }, - } - - flags := cmd.Flags() - flags.Var(&opts.listenAddr, flagListenAddr, "Listen address (format: [:port])") - flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", "Advertised address (format: [:port])") - flags.BoolVar(&opts.forceNewCluster, "force-new-cluster", false, "Force create a new cluster from current state") - flags.BoolVar(&opts.autolock, flagAutolock, false, "Enable manager autolocking (requiring an unlock key to start a stopped manager)") - addSwarmFlags(flags, &opts.swarmOptions) - return cmd -} - -func runInit(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts initOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - req := swarm.InitRequest{ - ListenAddr: opts.listenAddr.String(), - AdvertiseAddr: opts.advertiseAddr, - ForceNewCluster: opts.forceNewCluster, - Spec: opts.swarmOptions.ToSpec(flags), - AutoLockManagers: opts.swarmOptions.autolock, - } - - nodeID, err := client.SwarmInit(ctx, req) - if err != nil { - if strings.Contains(err.Error(), "could not choose an IP address to advertise") || strings.Contains(err.Error(), "could not find the system's IP address") { - return errors.New(err.Error() + " - specify one with --advertise-addr") - } - return err - } - - fmt.Fprintf(dockerCli.Out(), "Swarm initialized: current node (%s) is now a manager.\n\n", nodeID) - - if err := printJoinCommand(ctx, dockerCli, nodeID, true, false); err != nil { - return err - } - - fmt.Fprint(dockerCli.Out(), "To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.\n\n") - - if req.AutoLockManagers { - unlockKeyResp, err := client.SwarmGetUnlockKey(ctx) - if err != nil { - return errors.Wrap(err, "could not fetch unlock key") - } - printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey) - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/swarm/join.go b/vendor/github.com/docker/docker/cli/command/swarm/join.go deleted file mode 100644 index 004313b..0000000 --- a/vendor/github.com/docker/docker/cli/command/swarm/join.go +++ /dev/null @@ -1,69 +0,0 @@ -package swarm - -import ( - "fmt" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type joinOptions struct { - remote string - listenAddr NodeAddrOption - // Not a NodeAddrOption because it has no default port. - advertiseAddr string - token string -} - -func newJoinCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := joinOptions{ - listenAddr: NewListenAddrOption(), - } - - cmd := &cobra.Command{ - Use: "join [OPTIONS] HOST:PORT", - Short: "Join a swarm as a node and/or manager", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.remote = args[0] - return runJoin(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.Var(&opts.listenAddr, flagListenAddr, "Listen address (format: [:port])") - flags.StringVar(&opts.advertiseAddr, flagAdvertiseAddr, "", "Advertised address (format: [:port])") - flags.StringVar(&opts.token, flagToken, "", "Token for entry into the swarm") - return cmd -} - -func runJoin(dockerCli *command.DockerCli, opts joinOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - req := swarm.JoinRequest{ - JoinToken: opts.token, - ListenAddr: opts.listenAddr.String(), - AdvertiseAddr: opts.advertiseAddr, - RemoteAddrs: []string{opts.remote}, - } - err := client.SwarmJoin(ctx, req) - if err != nil { - return err - } - - info, err := client.Info(ctx) - if err != nil { - return err - } - - if info.Swarm.ControlAvailable { - fmt.Fprintln(dockerCli.Out(), "This node joined a swarm as a manager.") - } else { - fmt.Fprintln(dockerCli.Out(), "This node joined a swarm as a worker.") - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/swarm/join_token.go b/vendor/github.com/docker/docker/cli/command/swarm/join_token.go deleted file mode 100644 index 3a17a80..0000000 --- a/vendor/github.com/docker/docker/cli/command/swarm/join_token.go +++ /dev/null @@ -1,105 +0,0 @@ -package swarm - -import ( - "errors" - "fmt" - - "github.com/spf13/cobra" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "golang.org/x/net/context" -) - -func newJoinTokenCommand(dockerCli *command.DockerCli) *cobra.Command { - var rotate, quiet bool - - cmd := &cobra.Command{ - Use: "join-token [OPTIONS] (worker|manager)", - Short: "Manage join tokens", - Args: cli.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - worker := args[0] == "worker" - manager := args[0] == "manager" - - if !worker && !manager { - return errors.New("unknown role " + args[0]) - } - - client := dockerCli.Client() - ctx := context.Background() - - if rotate { - var flags swarm.UpdateFlags - - swarm, err := client.SwarmInspect(ctx) - if err != nil { - return err - } - - flags.RotateWorkerToken = worker - flags.RotateManagerToken = manager - - err = client.SwarmUpdate(ctx, swarm.Version, swarm.Spec, flags) - if err != nil { - return err - } - if !quiet { - fmt.Fprintf(dockerCli.Out(), "Successfully rotated %s join token.\n\n", args[0]) - } - } - - swarm, err := client.SwarmInspect(ctx) - if err != nil { - return err - } - - if quiet { - if worker { - fmt.Fprintln(dockerCli.Out(), swarm.JoinTokens.Worker) - } else { - fmt.Fprintln(dockerCli.Out(), swarm.JoinTokens.Manager) - } - } else { - info, err := client.Info(ctx) - if err != nil { - return err - } - return printJoinCommand(ctx, dockerCli, info.Swarm.NodeID, worker, manager) - } - return nil - }, - } - - flags := cmd.Flags() - flags.BoolVar(&rotate, flagRotate, false, "Rotate join token") - flags.BoolVarP(&quiet, flagQuiet, "q", false, "Only display token") - - return cmd -} - -func printJoinCommand(ctx context.Context, dockerCli *command.DockerCli, nodeID string, worker bool, manager bool) error { - client := dockerCli.Client() - - swarm, err := client.SwarmInspect(ctx) - if err != nil { - return err - } - - node, _, err := client.NodeInspectWithRaw(ctx, nodeID) - if err != nil { - return err - } - - if node.ManagerStatus != nil { - if worker { - fmt.Fprintf(dockerCli.Out(), "To add a worker to this swarm, run the following command:\n\n docker swarm join \\\n --token %s \\\n %s\n\n", swarm.JoinTokens.Worker, node.ManagerStatus.Addr) - } - if manager { - fmt.Fprintf(dockerCli.Out(), "To add a manager to this swarm, run the following command:\n\n docker swarm join \\\n --token %s \\\n %s\n\n", swarm.JoinTokens.Manager, node.ManagerStatus.Addr) - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/swarm/leave.go b/vendor/github.com/docker/docker/cli/command/swarm/leave.go deleted file mode 100644 index e2cfa0a..0000000 --- a/vendor/github.com/docker/docker/cli/command/swarm/leave.go +++ /dev/null @@ -1,44 +0,0 @@ -package swarm - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type leaveOptions struct { - force bool -} - -func newLeaveCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := leaveOptions{} - - cmd := &cobra.Command{ - Use: "leave [OPTIONS]", - Short: "Leave the swarm", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runLeave(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.force, "force", "f", false, "Force this node to leave the swarm, ignoring warnings") - return cmd -} - -func runLeave(dockerCli *command.DockerCli, opts leaveOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - if err := client.SwarmLeave(ctx, opts.force); err != nil { - return err - } - - fmt.Fprintln(dockerCli.Out(), "Node left the swarm.") - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/swarm/opts.go b/vendor/github.com/docker/docker/cli/command/swarm/opts.go deleted file mode 100644 index 9db46dc..0000000 --- a/vendor/github.com/docker/docker/cli/command/swarm/opts.go +++ /dev/null @@ -1,209 +0,0 @@ -package swarm - -import ( - "encoding/csv" - "errors" - "fmt" - "strings" - "time" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/opts" - "github.com/spf13/pflag" -) - -const ( - defaultListenAddr = "0.0.0.0:2377" - - flagCertExpiry = "cert-expiry" - flagDispatcherHeartbeat = "dispatcher-heartbeat" - flagListenAddr = "listen-addr" - flagAdvertiseAddr = "advertise-addr" - flagQuiet = "quiet" - flagRotate = "rotate" - flagToken = "token" - flagTaskHistoryLimit = "task-history-limit" - flagExternalCA = "external-ca" - flagMaxSnapshots = "max-snapshots" - flagSnapshotInterval = "snapshot-interval" - flagLockKey = "lock-key" - flagAutolock = "autolock" -) - -type swarmOptions struct { - taskHistoryLimit int64 - dispatcherHeartbeat time.Duration - nodeCertExpiry time.Duration - externalCA ExternalCAOption - maxSnapshots uint64 - snapshotInterval uint64 - autolock bool -} - -// NodeAddrOption is a pflag.Value for listening addresses -type NodeAddrOption struct { - addr string -} - -// String prints the representation of this flag -func (a *NodeAddrOption) String() string { - return a.Value() -} - -// Set the value for this flag -func (a *NodeAddrOption) Set(value string) error { - addr, err := opts.ParseTCPAddr(value, a.addr) - if err != nil { - return err - } - a.addr = addr - return nil -} - -// Type returns the type of this flag -func (a *NodeAddrOption) Type() string { - return "node-addr" -} - -// Value returns the value of this option as addr:port -func (a *NodeAddrOption) Value() string { - return strings.TrimPrefix(a.addr, "tcp://") -} - -// NewNodeAddrOption returns a new node address option -func NewNodeAddrOption(addr string) NodeAddrOption { - return NodeAddrOption{addr} -} - -// NewListenAddrOption returns a NodeAddrOption with default values -func NewListenAddrOption() NodeAddrOption { - return NewNodeAddrOption(defaultListenAddr) -} - -// ExternalCAOption is a Value type for parsing external CA specifications. -type ExternalCAOption struct { - values []*swarm.ExternalCA -} - -// Set parses an external CA option. -func (m *ExternalCAOption) Set(value string) error { - parsed, err := parseExternalCA(value) - if err != nil { - return err - } - - m.values = append(m.values, parsed) - return nil -} - -// Type returns the type of this option. -func (m *ExternalCAOption) Type() string { - return "external-ca" -} - -// String returns a string repr of this option. -func (m *ExternalCAOption) String() string { - externalCAs := []string{} - for _, externalCA := range m.values { - repr := fmt.Sprintf("%s: %s", externalCA.Protocol, externalCA.URL) - externalCAs = append(externalCAs, repr) - } - return strings.Join(externalCAs, ", ") -} - -// Value returns the external CAs -func (m *ExternalCAOption) Value() []*swarm.ExternalCA { - return m.values -} - -// parseExternalCA parses an external CA specification from the command line, -// such as protocol=cfssl,url=https://example.com. -func parseExternalCA(caSpec string) (*swarm.ExternalCA, error) { - csvReader := csv.NewReader(strings.NewReader(caSpec)) - fields, err := csvReader.Read() - if err != nil { - return nil, err - } - - externalCA := swarm.ExternalCA{ - Options: make(map[string]string), - } - - var ( - hasProtocol bool - hasURL bool - ) - - for _, field := range fields { - parts := strings.SplitN(field, "=", 2) - - if len(parts) != 2 { - return nil, fmt.Errorf("invalid field '%s' must be a key=value pair", field) - } - - key, value := parts[0], parts[1] - - switch strings.ToLower(key) { - case "protocol": - hasProtocol = true - if strings.ToLower(value) == string(swarm.ExternalCAProtocolCFSSL) { - externalCA.Protocol = swarm.ExternalCAProtocolCFSSL - } else { - return nil, fmt.Errorf("unrecognized external CA protocol %s", value) - } - case "url": - hasURL = true - externalCA.URL = value - default: - externalCA.Options[key] = value - } - } - - if !hasProtocol { - return nil, errors.New("the external-ca option needs a protocol= parameter") - } - if !hasURL { - return nil, errors.New("the external-ca option needs a url= parameter") - } - - return &externalCA, nil -} - -func addSwarmFlags(flags *pflag.FlagSet, opts *swarmOptions) { - flags.Int64Var(&opts.taskHistoryLimit, flagTaskHistoryLimit, 5, "Task history retention limit") - flags.DurationVar(&opts.dispatcherHeartbeat, flagDispatcherHeartbeat, time.Duration(5*time.Second), "Dispatcher heartbeat period (ns|us|ms|s|m|h)") - flags.DurationVar(&opts.nodeCertExpiry, flagCertExpiry, time.Duration(90*24*time.Hour), "Validity period for node certificates (ns|us|ms|s|m|h)") - flags.Var(&opts.externalCA, flagExternalCA, "Specifications of one or more certificate signing endpoints") - flags.Uint64Var(&opts.maxSnapshots, flagMaxSnapshots, 0, "Number of additional Raft snapshots to retain") - flags.Uint64Var(&opts.snapshotInterval, flagSnapshotInterval, 10000, "Number of log entries between Raft snapshots") -} - -func (opts *swarmOptions) mergeSwarmSpec(spec *swarm.Spec, flags *pflag.FlagSet) { - if flags.Changed(flagTaskHistoryLimit) { - spec.Orchestration.TaskHistoryRetentionLimit = &opts.taskHistoryLimit - } - if flags.Changed(flagDispatcherHeartbeat) { - spec.Dispatcher.HeartbeatPeriod = opts.dispatcherHeartbeat - } - if flags.Changed(flagCertExpiry) { - spec.CAConfig.NodeCertExpiry = opts.nodeCertExpiry - } - if flags.Changed(flagExternalCA) { - spec.CAConfig.ExternalCAs = opts.externalCA.Value() - } - if flags.Changed(flagMaxSnapshots) { - spec.Raft.KeepOldSnapshots = &opts.maxSnapshots - } - if flags.Changed(flagSnapshotInterval) { - spec.Raft.SnapshotInterval = opts.snapshotInterval - } - if flags.Changed(flagAutolock) { - spec.EncryptionConfig.AutoLockManagers = opts.autolock - } -} - -func (opts *swarmOptions) ToSpec(flags *pflag.FlagSet) swarm.Spec { - var spec swarm.Spec - opts.mergeSwarmSpec(&spec, flags) - return spec -} diff --git a/vendor/github.com/docker/docker/cli/command/swarm/opts_test.go b/vendor/github.com/docker/docker/cli/command/swarm/opts_test.go deleted file mode 100644 index 568dc87..0000000 --- a/vendor/github.com/docker/docker/cli/command/swarm/opts_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package swarm - -import ( - "testing" - - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestNodeAddrOptionSetHostAndPort(t *testing.T) { - opt := NewNodeAddrOption("old:123") - addr := "newhost:5555" - assert.NilError(t, opt.Set(addr)) - assert.Equal(t, opt.Value(), addr) -} - -func TestNodeAddrOptionSetHostOnly(t *testing.T) { - opt := NewListenAddrOption() - assert.NilError(t, opt.Set("newhost")) - assert.Equal(t, opt.Value(), "newhost:2377") -} - -func TestNodeAddrOptionSetHostOnlyIPv6(t *testing.T) { - opt := NewListenAddrOption() - assert.NilError(t, opt.Set("::1")) - assert.Equal(t, opt.Value(), "[::1]:2377") -} - -func TestNodeAddrOptionSetPortOnly(t *testing.T) { - opt := NewListenAddrOption() - assert.NilError(t, opt.Set(":4545")) - assert.Equal(t, opt.Value(), "0.0.0.0:4545") -} - -func TestNodeAddrOptionSetInvalidFormat(t *testing.T) { - opt := NewListenAddrOption() - assert.Error(t, opt.Set("http://localhost:4545"), "Invalid") -} diff --git a/vendor/github.com/docker/docker/cli/command/swarm/unlock.go b/vendor/github.com/docker/docker/cli/command/swarm/unlock.go deleted file mode 100644 index 048fb56..0000000 --- a/vendor/github.com/docker/docker/cli/command/swarm/unlock.go +++ /dev/null @@ -1,54 +0,0 @@ -package swarm - -import ( - "bufio" - "fmt" - "io" - "strings" - - "github.com/spf13/cobra" - "golang.org/x/crypto/ssh/terminal" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "golang.org/x/net/context" -) - -func newUnlockCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "unlock", - Short: "Unlock swarm", - Args: cli.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - client := dockerCli.Client() - ctx := context.Background() - - key, err := readKey(dockerCli.In(), "Please enter unlock key: ") - if err != nil { - return err - } - req := swarm.UnlockRequest{ - UnlockKey: key, - } - - return client.SwarmUnlock(ctx, req) - }, - } - - return cmd -} - -func readKey(in *command.InStream, prompt string) (string, error) { - if in.IsTerminal() { - fmt.Print(prompt) - dt, err := terminal.ReadPassword(int(in.FD())) - fmt.Println() - return string(dt), err - } - key, err := bufio.NewReader(in).ReadString('\n') - if err == io.EOF { - err = nil - } - return strings.TrimSpace(key), err -} diff --git a/vendor/github.com/docker/docker/cli/command/swarm/unlock_key.go b/vendor/github.com/docker/docker/cli/command/swarm/unlock_key.go deleted file mode 100644 index 96450f5..0000000 --- a/vendor/github.com/docker/docker/cli/command/swarm/unlock_key.go +++ /dev/null @@ -1,79 +0,0 @@ -package swarm - -import ( - "fmt" - - "github.com/spf13/cobra" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/pkg/errors" - "golang.org/x/net/context" -) - -func newUnlockKeyCommand(dockerCli *command.DockerCli) *cobra.Command { - var rotate, quiet bool - - cmd := &cobra.Command{ - Use: "unlock-key [OPTIONS]", - Short: "Manage the unlock key", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - client := dockerCli.Client() - ctx := context.Background() - - if rotate { - flags := swarm.UpdateFlags{RotateManagerUnlockKey: true} - - swarm, err := client.SwarmInspect(ctx) - if err != nil { - return err - } - - if !swarm.Spec.EncryptionConfig.AutoLockManagers { - return errors.New("cannot rotate because autolock is not turned on") - } - - err = client.SwarmUpdate(ctx, swarm.Version, swarm.Spec, flags) - if err != nil { - return err - } - if !quiet { - fmt.Fprintf(dockerCli.Out(), "Successfully rotated manager unlock key.\n\n") - } - } - - unlockKeyResp, err := client.SwarmGetUnlockKey(ctx) - if err != nil { - return errors.Wrap(err, "could not fetch unlock key") - } - - if unlockKeyResp.UnlockKey == "" { - return errors.New("no unlock key is set") - } - - if quiet { - fmt.Fprintln(dockerCli.Out(), unlockKeyResp.UnlockKey) - } else { - printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey) - } - return nil - }, - } - - flags := cmd.Flags() - flags.BoolVar(&rotate, flagRotate, false, "Rotate unlock key") - flags.BoolVarP(&quiet, flagQuiet, "q", false, "Only display token") - - return cmd -} - -func printUnlockCommand(ctx context.Context, dockerCli *command.DockerCli, unlockKey string) { - if len(unlockKey) == 0 { - return - } - - fmt.Fprintf(dockerCli.Out(), "To unlock a swarm manager after it restarts, run the `docker swarm unlock`\ncommand and provide the following key:\n\n %s\n\nPlease remember to store this key in a password manager, since without it you\nwill not be able to restart the manager.\n", unlockKey) - return -} diff --git a/vendor/github.com/docker/docker/cli/command/swarm/update.go b/vendor/github.com/docker/docker/cli/command/swarm/update.go deleted file mode 100644 index dbbd268..0000000 --- a/vendor/github.com/docker/docker/cli/command/swarm/update.go +++ /dev/null @@ -1,72 +0,0 @@ -package swarm - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/pkg/errors" - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := swarmOptions{} - - cmd := &cobra.Command{ - Use: "update [OPTIONS]", - Short: "Update the swarm", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runUpdate(dockerCli, cmd.Flags(), opts) - }, - PreRunE: func(cmd *cobra.Command, args []string) error { - if cmd.Flags().NFlag() == 0 { - return pflag.ErrHelp - } - return nil - }, - } - - cmd.Flags().BoolVar(&opts.autolock, flagAutolock, false, "Change manager autolocking setting (true|false)") - addSwarmFlags(cmd.Flags(), &opts) - return cmd -} - -func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts swarmOptions) error { - client := dockerCli.Client() - ctx := context.Background() - - var updateFlags swarm.UpdateFlags - - swarm, err := client.SwarmInspect(ctx) - if err != nil { - return err - } - - prevAutoLock := swarm.Spec.EncryptionConfig.AutoLockManagers - - opts.mergeSwarmSpec(&swarm.Spec, flags) - - curAutoLock := swarm.Spec.EncryptionConfig.AutoLockManagers - - err = client.SwarmUpdate(ctx, swarm.Version, swarm.Spec, updateFlags) - if err != nil { - return err - } - - fmt.Fprintln(dockerCli.Out(), "Swarm updated.") - - if curAutoLock && !prevAutoLock { - unlockKeyResp, err := client.SwarmGetUnlockKey(ctx) - if err != nil { - return errors.Wrap(err, "could not fetch unlock key") - } - printUnlockCommand(ctx, dockerCli, unlockKeyResp.UnlockKey) - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/system/cmd.go b/vendor/github.com/docker/docker/cli/command/system/cmd.go deleted file mode 100644 index ab3beb8..0000000 --- a/vendor/github.com/docker/docker/cli/command/system/cmd.go +++ /dev/null @@ -1,26 +0,0 @@ -package system - -import ( - "github.com/spf13/cobra" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" -) - -// NewSystemCommand returns a cobra command for `system` subcommands -func NewSystemCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "system", - Short: "Manage Docker", - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - } - cmd.AddCommand( - NewEventsCommand(dockerCli), - NewInfoCommand(dockerCli), - NewDiskUsageCommand(dockerCli), - NewPruneCommand(dockerCli), - ) - - return cmd -} diff --git a/vendor/github.com/docker/docker/cli/command/system/df.go b/vendor/github.com/docker/docker/cli/command/system/df.go deleted file mode 100644 index 9f71248..0000000 --- a/vendor/github.com/docker/docker/cli/command/system/df.go +++ /dev/null @@ -1,56 +0,0 @@ -package system - -import ( - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/formatter" - "github.com/spf13/cobra" - "golang.org/x/net/context" -) - -type diskUsageOptions struct { - verbose bool -} - -// NewDiskUsageCommand creates a new cobra.Command for `docker df` -func NewDiskUsageCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts diskUsageOptions - - cmd := &cobra.Command{ - Use: "df [OPTIONS]", - Short: "Show docker disk usage", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runDiskUsage(dockerCli, opts) - }, - Tags: map[string]string{"version": "1.25"}, - } - - flags := cmd.Flags() - - flags.BoolVarP(&opts.verbose, "verbose", "v", false, "Show detailed information on space usage") - - return cmd -} - -func runDiskUsage(dockerCli *command.DockerCli, opts diskUsageOptions) error { - du, err := dockerCli.Client().DiskUsage(context.Background()) - if err != nil { - return err - } - - duCtx := formatter.DiskUsageContext{ - Context: formatter.Context{ - Output: dockerCli.Out(), - }, - LayersSize: du.LayersSize, - Images: du.Images, - Containers: du.Containers, - Volumes: du.Volumes, - Verbose: opts.verbose, - } - - duCtx.Write() - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/system/events.go b/vendor/github.com/docker/docker/cli/command/system/events.go deleted file mode 100644 index 0875230..0000000 --- a/vendor/github.com/docker/docker/cli/command/system/events.go +++ /dev/null @@ -1,140 +0,0 @@ -package system - -import ( - "fmt" - "io" - "io/ioutil" - "sort" - "strings" - "text/template" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - eventtypes "github.com/docker/docker/api/types/events" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/jsonlog" - "github.com/docker/docker/utils/templates" - "github.com/spf13/cobra" -) - -type eventsOptions struct { - since string - until string - filter opts.FilterOpt - format string -} - -// NewEventsCommand creates a new cobra.Command for `docker events` -func NewEventsCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := eventsOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "events [OPTIONS]", - Short: "Get real time events from the server", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runEvents(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.StringVar(&opts.since, "since", "", "Show all events created since timestamp") - flags.StringVar(&opts.until, "until", "", "Stream events until this timestamp") - flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") - flags.StringVar(&opts.format, "format", "", "Format the output using the given Go template") - - return cmd -} - -func runEvents(dockerCli *command.DockerCli, opts *eventsOptions) error { - tmpl, err := makeTemplate(opts.format) - if err != nil { - return cli.StatusError{ - StatusCode: 64, - Status: "Error parsing format: " + err.Error()} - } - options := types.EventsOptions{ - Since: opts.since, - Until: opts.until, - Filters: opts.filter.Value(), - } - - ctx, cancel := context.WithCancel(context.Background()) - events, errs := dockerCli.Client().Events(ctx, options) - defer cancel() - - out := dockerCli.Out() - - for { - select { - case event := <-events: - if err := handleEvent(out, event, tmpl); err != nil { - return err - } - case err := <-errs: - if err == io.EOF { - return nil - } - return err - } - } -} - -func handleEvent(out io.Writer, event eventtypes.Message, tmpl *template.Template) error { - if tmpl == nil { - return prettyPrintEvent(out, event) - } - - return formatEvent(out, event, tmpl) -} - -func makeTemplate(format string) (*template.Template, error) { - if format == "" { - return nil, nil - } - tmpl, err := templates.Parse(format) - if err != nil { - return tmpl, err - } - // we execute the template for an empty message, so as to validate - // a bad template like "{{.badFieldString}}" - return tmpl, tmpl.Execute(ioutil.Discard, &eventtypes.Message{}) -} - -// prettyPrintEvent prints all types of event information. -// Each output includes the event type, actor id, name and action. -// Actor attributes are printed at the end if the actor has any. -func prettyPrintEvent(out io.Writer, event eventtypes.Message) error { - if event.TimeNano != 0 { - fmt.Fprintf(out, "%s ", time.Unix(0, event.TimeNano).Format(jsonlog.RFC3339NanoFixed)) - } else if event.Time != 0 { - fmt.Fprintf(out, "%s ", time.Unix(event.Time, 0).Format(jsonlog.RFC3339NanoFixed)) - } - - fmt.Fprintf(out, "%s %s %s", event.Type, event.Action, event.Actor.ID) - - if len(event.Actor.Attributes) > 0 { - var attrs []string - var keys []string - for k := range event.Actor.Attributes { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - v := event.Actor.Attributes[k] - attrs = append(attrs, fmt.Sprintf("%s=%s", k, v)) - } - fmt.Fprintf(out, " (%s)", strings.Join(attrs, ", ")) - } - fmt.Fprint(out, "\n") - return nil -} - -func formatEvent(out io.Writer, event eventtypes.Message, tmpl *template.Template) error { - defer out.Write([]byte{'\n'}) - return tmpl.Execute(out, event) -} diff --git a/vendor/github.com/docker/docker/cli/command/system/info.go b/vendor/github.com/docker/docker/cli/command/system/info.go deleted file mode 100644 index e0b8767..0000000 --- a/vendor/github.com/docker/docker/cli/command/system/info.go +++ /dev/null @@ -1,334 +0,0 @@ -package system - -import ( - "fmt" - "sort" - "strings" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/utils" - "github.com/docker/docker/utils/templates" - "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type infoOptions struct { - format string -} - -// NewInfoCommand creates a new cobra.Command for `docker info` -func NewInfoCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts infoOptions - - cmd := &cobra.Command{ - Use: "info [OPTIONS]", - Short: "Display system-wide information", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runInfo(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - - flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - - return cmd -} - -func runInfo(dockerCli *command.DockerCli, opts *infoOptions) error { - ctx := context.Background() - info, err := dockerCli.Client().Info(ctx) - if err != nil { - return err - } - if opts.format == "" { - return prettyPrintInfo(dockerCli, info) - } - return formatInfo(dockerCli, info, opts.format) -} - -func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error { - fmt.Fprintf(dockerCli.Out(), "Containers: %d\n", info.Containers) - fmt.Fprintf(dockerCli.Out(), " Running: %d\n", info.ContainersRunning) - fmt.Fprintf(dockerCli.Out(), " Paused: %d\n", info.ContainersPaused) - fmt.Fprintf(dockerCli.Out(), " Stopped: %d\n", info.ContainersStopped) - fmt.Fprintf(dockerCli.Out(), "Images: %d\n", info.Images) - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Server Version: %s\n", info.ServerVersion) - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Storage Driver: %s\n", info.Driver) - if info.DriverStatus != nil { - for _, pair := range info.DriverStatus { - fmt.Fprintf(dockerCli.Out(), " %s: %s\n", pair[0], pair[1]) - - // print a warning if devicemapper is using a loopback file - if pair[0] == "Data loop file" { - fmt.Fprintln(dockerCli.Err(), " WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.") - } - } - - } - if info.SystemStatus != nil { - for _, pair := range info.SystemStatus { - fmt.Fprintf(dockerCli.Out(), "%s: %s\n", pair[0], pair[1]) - } - } - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Logging Driver: %s\n", info.LoggingDriver) - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Cgroup Driver: %s\n", info.CgroupDriver) - - fmt.Fprintf(dockerCli.Out(), "Plugins: \n") - fmt.Fprintf(dockerCli.Out(), " Volume:") - fmt.Fprintf(dockerCli.Out(), " %s", strings.Join(info.Plugins.Volume, " ")) - fmt.Fprintf(dockerCli.Out(), "\n") - fmt.Fprintf(dockerCli.Out(), " Network:") - fmt.Fprintf(dockerCli.Out(), " %s", strings.Join(info.Plugins.Network, " ")) - fmt.Fprintf(dockerCli.Out(), "\n") - - if len(info.Plugins.Authorization) != 0 { - fmt.Fprintf(dockerCli.Out(), " Authorization:") - fmt.Fprintf(dockerCli.Out(), " %s", strings.Join(info.Plugins.Authorization, " ")) - fmt.Fprintf(dockerCli.Out(), "\n") - } - - fmt.Fprintf(dockerCli.Out(), "Swarm: %v\n", info.Swarm.LocalNodeState) - if info.Swarm.LocalNodeState != swarm.LocalNodeStateInactive && info.Swarm.LocalNodeState != swarm.LocalNodeStateLocked { - fmt.Fprintf(dockerCli.Out(), " NodeID: %s\n", info.Swarm.NodeID) - if info.Swarm.Error != "" { - fmt.Fprintf(dockerCli.Out(), " Error: %v\n", info.Swarm.Error) - } - fmt.Fprintf(dockerCli.Out(), " Is Manager: %v\n", info.Swarm.ControlAvailable) - if info.Swarm.ControlAvailable { - fmt.Fprintf(dockerCli.Out(), " ClusterID: %s\n", info.Swarm.Cluster.ID) - fmt.Fprintf(dockerCli.Out(), " Managers: %d\n", info.Swarm.Managers) - fmt.Fprintf(dockerCli.Out(), " Nodes: %d\n", info.Swarm.Nodes) - fmt.Fprintf(dockerCli.Out(), " Orchestration:\n") - taskHistoryRetentionLimit := int64(0) - if info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit != nil { - taskHistoryRetentionLimit = *info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit - } - fmt.Fprintf(dockerCli.Out(), " Task History Retention Limit: %d\n", taskHistoryRetentionLimit) - fmt.Fprintf(dockerCli.Out(), " Raft:\n") - fmt.Fprintf(dockerCli.Out(), " Snapshot Interval: %d\n", info.Swarm.Cluster.Spec.Raft.SnapshotInterval) - if info.Swarm.Cluster.Spec.Raft.KeepOldSnapshots != nil { - fmt.Fprintf(dockerCli.Out(), " Number of Old Snapshots to Retain: %d\n", *info.Swarm.Cluster.Spec.Raft.KeepOldSnapshots) - } - fmt.Fprintf(dockerCli.Out(), " Heartbeat Tick: %d\n", info.Swarm.Cluster.Spec.Raft.HeartbeatTick) - fmt.Fprintf(dockerCli.Out(), " Election Tick: %d\n", info.Swarm.Cluster.Spec.Raft.ElectionTick) - fmt.Fprintf(dockerCli.Out(), " Dispatcher:\n") - fmt.Fprintf(dockerCli.Out(), " Heartbeat Period: %s\n", units.HumanDuration(time.Duration(info.Swarm.Cluster.Spec.Dispatcher.HeartbeatPeriod))) - fmt.Fprintf(dockerCli.Out(), " CA Configuration:\n") - fmt.Fprintf(dockerCli.Out(), " Expiry Duration: %s\n", units.HumanDuration(info.Swarm.Cluster.Spec.CAConfig.NodeCertExpiry)) - if len(info.Swarm.Cluster.Spec.CAConfig.ExternalCAs) > 0 { - fmt.Fprintf(dockerCli.Out(), " External CAs:\n") - for _, entry := range info.Swarm.Cluster.Spec.CAConfig.ExternalCAs { - fmt.Fprintf(dockerCli.Out(), " %s: %s\n", entry.Protocol, entry.URL) - } - } - } - fmt.Fprintf(dockerCli.Out(), " Node Address: %s\n", info.Swarm.NodeAddr) - managers := []string{} - for _, entry := range info.Swarm.RemoteManagers { - managers = append(managers, entry.Addr) - } - if len(managers) > 0 { - sort.Strings(managers) - fmt.Fprintf(dockerCli.Out(), " Manager Addresses:\n") - for _, entry := range managers { - fmt.Fprintf(dockerCli.Out(), " %s\n", entry) - } - } - } - - if len(info.Runtimes) > 0 { - fmt.Fprintf(dockerCli.Out(), "Runtimes:") - for name := range info.Runtimes { - fmt.Fprintf(dockerCli.Out(), " %s", name) - } - fmt.Fprint(dockerCli.Out(), "\n") - fmt.Fprintf(dockerCli.Out(), "Default Runtime: %s\n", info.DefaultRuntime) - } - - if info.OSType == "linux" { - fmt.Fprintf(dockerCli.Out(), "Init Binary: %v\n", info.InitBinary) - - for _, ci := range []struct { - Name string - Commit types.Commit - }{ - {"containerd", info.ContainerdCommit}, - {"runc", info.RuncCommit}, - {"init", info.InitCommit}, - } { - fmt.Fprintf(dockerCli.Out(), "%s version: %s", ci.Name, ci.Commit.ID) - if ci.Commit.ID != ci.Commit.Expected { - fmt.Fprintf(dockerCli.Out(), " (expected: %s)", ci.Commit.Expected) - } - fmt.Fprintf(dockerCli.Out(), "\n") - } - if len(info.SecurityOptions) != 0 { - kvs, err := types.DecodeSecurityOptions(info.SecurityOptions) - if err != nil { - return err - } - fmt.Fprintf(dockerCli.Out(), "Security Options:\n") - for _, so := range kvs { - fmt.Fprintf(dockerCli.Out(), " %s\n", so.Name) - for _, o := range so.Options { - switch o.Key { - case "profile": - if o.Value != "default" { - fmt.Fprintf(dockerCli.Err(), " WARNING: You're not using the default seccomp profile\n") - } - fmt.Fprintf(dockerCli.Out(), " Profile: %s\n", o.Value) - } - } - } - } - } - - // Isolation only has meaning on a Windows daemon. - if info.OSType == "windows" { - fmt.Fprintf(dockerCli.Out(), "Default Isolation: %v\n", info.Isolation) - } - - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Kernel Version: %s\n", info.KernelVersion) - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Operating System: %s\n", info.OperatingSystem) - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "OSType: %s\n", info.OSType) - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Architecture: %s\n", info.Architecture) - fmt.Fprintf(dockerCli.Out(), "CPUs: %d\n", info.NCPU) - fmt.Fprintf(dockerCli.Out(), "Total Memory: %s\n", units.BytesSize(float64(info.MemTotal))) - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Name: %s\n", info.Name) - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "ID: %s\n", info.ID) - fmt.Fprintf(dockerCli.Out(), "Docker Root Dir: %s\n", info.DockerRootDir) - fmt.Fprintf(dockerCli.Out(), "Debug Mode (client): %v\n", utils.IsDebugEnabled()) - fmt.Fprintf(dockerCli.Out(), "Debug Mode (server): %v\n", info.Debug) - - if info.Debug { - fmt.Fprintf(dockerCli.Out(), " File Descriptors: %d\n", info.NFd) - fmt.Fprintf(dockerCli.Out(), " Goroutines: %d\n", info.NGoroutines) - fmt.Fprintf(dockerCli.Out(), " System Time: %s\n", info.SystemTime) - fmt.Fprintf(dockerCli.Out(), " EventsListeners: %d\n", info.NEventsListener) - } - - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Http Proxy: %s\n", info.HTTPProxy) - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Https Proxy: %s\n", info.HTTPSProxy) - ioutils.FprintfIfNotEmpty(dockerCli.Out(), "No Proxy: %s\n", info.NoProxy) - - if info.IndexServerAddress != "" { - u := dockerCli.ConfigFile().AuthConfigs[info.IndexServerAddress].Username - if len(u) > 0 { - fmt.Fprintf(dockerCli.Out(), "Username: %v\n", u) - } - fmt.Fprintf(dockerCli.Out(), "Registry: %v\n", info.IndexServerAddress) - } - - // Only output these warnings if the server does not support these features - if info.OSType != "windows" { - if !info.MemoryLimit { - fmt.Fprintln(dockerCli.Err(), "WARNING: No memory limit support") - } - if !info.SwapLimit { - fmt.Fprintln(dockerCli.Err(), "WARNING: No swap limit support") - } - if !info.KernelMemory { - fmt.Fprintln(dockerCli.Err(), "WARNING: No kernel memory limit support") - } - if !info.OomKillDisable { - fmt.Fprintln(dockerCli.Err(), "WARNING: No oom kill disable support") - } - if !info.CPUCfsQuota { - fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu cfs quota support") - } - if !info.CPUCfsPeriod { - fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu cfs period support") - } - if !info.CPUShares { - fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu shares support") - } - if !info.CPUSet { - fmt.Fprintln(dockerCli.Err(), "WARNING: No cpuset support") - } - if !info.IPv4Forwarding { - fmt.Fprintln(dockerCli.Err(), "WARNING: IPv4 forwarding is disabled") - } - if !info.BridgeNfIptables { - fmt.Fprintln(dockerCli.Err(), "WARNING: bridge-nf-call-iptables is disabled") - } - if !info.BridgeNfIP6tables { - fmt.Fprintln(dockerCli.Err(), "WARNING: bridge-nf-call-ip6tables is disabled") - } - } - - if info.Labels != nil { - fmt.Fprintln(dockerCli.Out(), "Labels:") - for _, attribute := range info.Labels { - fmt.Fprintf(dockerCli.Out(), " %s\n", attribute) - } - // TODO: Engine labels with duplicate keys has been deprecated in 1.13 and will be error out - // after 3 release cycles (1.16). For now, a WARNING will be generated. The following will - // be removed eventually. - labelMap := map[string]string{} - for _, label := range info.Labels { - stringSlice := strings.SplitN(label, "=", 2) - if len(stringSlice) > 1 { - // If there is a conflict we will throw out an warning - if v, ok := labelMap[stringSlice[0]]; ok && v != stringSlice[1] { - fmt.Fprintln(dockerCli.Err(), "WARNING: labels with duplicate keys and conflicting values have been deprecated") - break - } - labelMap[stringSlice[0]] = stringSlice[1] - } - } - } - - fmt.Fprintf(dockerCli.Out(), "Experimental: %v\n", info.ExperimentalBuild) - if info.ClusterStore != "" { - fmt.Fprintf(dockerCli.Out(), "Cluster Store: %s\n", info.ClusterStore) - } - - if info.ClusterAdvertise != "" { - fmt.Fprintf(dockerCli.Out(), "Cluster Advertise: %s\n", info.ClusterAdvertise) - } - - if info.RegistryConfig != nil && (len(info.RegistryConfig.InsecureRegistryCIDRs) > 0 || len(info.RegistryConfig.IndexConfigs) > 0) { - fmt.Fprintln(dockerCli.Out(), "Insecure Registries:") - for _, registry := range info.RegistryConfig.IndexConfigs { - if registry.Secure == false { - fmt.Fprintf(dockerCli.Out(), " %s\n", registry.Name) - } - } - - for _, registry := range info.RegistryConfig.InsecureRegistryCIDRs { - mask, _ := registry.Mask.Size() - fmt.Fprintf(dockerCli.Out(), " %s/%d\n", registry.IP.String(), mask) - } - } - - if info.RegistryConfig != nil && len(info.RegistryConfig.Mirrors) > 0 { - fmt.Fprintln(dockerCli.Out(), "Registry Mirrors:") - for _, mirror := range info.RegistryConfig.Mirrors { - fmt.Fprintf(dockerCli.Out(), " %s\n", mirror) - } - } - - fmt.Fprintf(dockerCli.Out(), "Live Restore Enabled: %v\n", info.LiveRestoreEnabled) - - return nil -} - -func formatInfo(dockerCli *command.DockerCli, info types.Info, format string) error { - tmpl, err := templates.Parse(format) - if err != nil { - return cli.StatusError{StatusCode: 64, - Status: "Template parsing error: " + err.Error()} - } - err = tmpl.Execute(dockerCli.Out(), info) - dockerCli.Out().Write([]byte{'\n'}) - return err -} diff --git a/vendor/github.com/docker/docker/cli/command/system/inspect.go b/vendor/github.com/docker/docker/cli/command/system/inspect.go deleted file mode 100644 index c86e858..0000000 --- a/vendor/github.com/docker/docker/cli/command/system/inspect.go +++ /dev/null @@ -1,203 +0,0 @@ -package system - -import ( - "fmt" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/inspect" - apiclient "github.com/docker/docker/client" - "github.com/spf13/cobra" -) - -type inspectOptions struct { - format string - inspectType string - size bool - ids []string -} - -// NewInspectCommand creates a new cobra.Command for `docker inspect` -func NewInspectCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts inspectOptions - - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] NAME|ID [NAME|ID...]", - Short: "Return low-level information on Docker objects", - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.ids = args - return runInspect(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - flags.StringVar(&opts.inspectType, "type", "", "Return JSON for specified type") - flags.BoolVarP(&opts.size, "size", "s", false, "Display total file sizes if the type is container") - - return cmd -} - -func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { - var elementSearcher inspect.GetRefFunc - switch opts.inspectType { - case "", "container", "image", "node", "network", "service", "volume", "task", "plugin": - elementSearcher = inspectAll(context.Background(), dockerCli, opts.size, opts.inspectType) - default: - return fmt.Errorf("%q is not a valid value for --type", opts.inspectType) - } - return inspect.Inspect(dockerCli.Out(), opts.ids, opts.format, elementSearcher) -} - -func inspectContainers(ctx context.Context, dockerCli *command.DockerCli, getSize bool) inspect.GetRefFunc { - return func(ref string) (interface{}, []byte, error) { - return dockerCli.Client().ContainerInspectWithRaw(ctx, ref, getSize) - } -} - -func inspectImages(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc { - return func(ref string) (interface{}, []byte, error) { - return dockerCli.Client().ImageInspectWithRaw(ctx, ref) - } -} - -func inspectNetwork(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc { - return func(ref string) (interface{}, []byte, error) { - return dockerCli.Client().NetworkInspectWithRaw(ctx, ref) - } -} - -func inspectNode(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc { - return func(ref string) (interface{}, []byte, error) { - return dockerCli.Client().NodeInspectWithRaw(ctx, ref) - } -} - -func inspectService(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc { - return func(ref string) (interface{}, []byte, error) { - return dockerCli.Client().ServiceInspectWithRaw(ctx, ref) - } -} - -func inspectTasks(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc { - return func(ref string) (interface{}, []byte, error) { - return dockerCli.Client().TaskInspectWithRaw(ctx, ref) - } -} - -func inspectVolume(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc { - return func(ref string) (interface{}, []byte, error) { - return dockerCli.Client().VolumeInspectWithRaw(ctx, ref) - } -} - -func inspectPlugin(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc { - return func(ref string) (interface{}, []byte, error) { - return dockerCli.Client().PluginInspectWithRaw(ctx, ref) - } -} - -func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool, typeConstraint string) inspect.GetRefFunc { - var inspectAutodetect = []struct { - objectType string - isSizeSupported bool - isSwarmObject bool - objectInspector func(string) (interface{}, []byte, error) - }{ - { - objectType: "container", - isSizeSupported: true, - objectInspector: inspectContainers(ctx, dockerCli, getSize), - }, - { - objectType: "image", - objectInspector: inspectImages(ctx, dockerCli), - }, - { - objectType: "network", - objectInspector: inspectNetwork(ctx, dockerCli), - }, - { - objectType: "volume", - objectInspector: inspectVolume(ctx, dockerCli), - }, - { - objectType: "service", - isSwarmObject: true, - objectInspector: inspectService(ctx, dockerCli), - }, - { - objectType: "task", - isSwarmObject: true, - objectInspector: inspectTasks(ctx, dockerCli), - }, - { - objectType: "node", - isSwarmObject: true, - objectInspector: inspectNode(ctx, dockerCli), - }, - { - objectType: "plugin", - objectInspector: inspectPlugin(ctx, dockerCli), - }, - } - - // isSwarmManager does an Info API call to verify that the daemon is - // a swarm manager. - isSwarmManager := func() bool { - info, err := dockerCli.Client().Info(ctx) - if err != nil { - fmt.Fprintln(dockerCli.Err(), err) - return false - } - return info.Swarm.ControlAvailable - } - - isErrNotSupported := func(err error) bool { - return strings.Contains(err.Error(), "not supported") - } - - return func(ref string) (interface{}, []byte, error) { - const ( - swarmSupportUnknown = iota - swarmSupported - swarmUnsupported - ) - - isSwarmSupported := swarmSupportUnknown - - for _, inspectData := range inspectAutodetect { - if typeConstraint != "" && inspectData.objectType != typeConstraint { - continue - } - if typeConstraint == "" && inspectData.isSwarmObject { - if isSwarmSupported == swarmSupportUnknown { - if isSwarmManager() { - isSwarmSupported = swarmSupported - } else { - isSwarmSupported = swarmUnsupported - } - } - if isSwarmSupported == swarmUnsupported { - continue - } - } - v, raw, err := inspectData.objectInspector(ref) - if err != nil { - if typeConstraint == "" && (apiclient.IsErrNotFound(err) || isErrNotSupported(err)) { - continue - } - return v, raw, err - } - if getSize && !inspectData.isSizeSupported { - fmt.Fprintf(dockerCli.Err(), "WARNING: --size ignored for %s\n", inspectData.objectType) - } - return v, raw, err - } - return nil, nil, fmt.Errorf("Error: No such object: %s", ref) - } -} diff --git a/vendor/github.com/docker/docker/cli/command/system/prune.go b/vendor/github.com/docker/docker/cli/command/system/prune.go deleted file mode 100644 index 92dddbd..0000000 --- a/vendor/github.com/docker/docker/cli/command/system/prune.go +++ /dev/null @@ -1,93 +0,0 @@ -package system - -import ( - "fmt" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/prune" - units "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type pruneOptions struct { - force bool - all bool -} - -// NewPruneCommand creates a new cobra.Command for `docker prune` -func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts pruneOptions - - cmd := &cobra.Command{ - Use: "prune [OPTIONS]", - Short: "Remove unused data", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runPrune(dockerCli, opts) - }, - Tags: map[string]string{"version": "1.25"}, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") - flags.BoolVarP(&opts.all, "all", "a", false, "Remove all unused images not just dangling ones") - - return cmd -} - -const ( - warning = `WARNING! This will remove: - - all stopped containers - - all volumes not used by at least one container - - all networks not used by at least one container - %s -Are you sure you want to continue?` - - danglingImageDesc = "- all dangling images" - allImageDesc = `- all images without at least one container associated to them` -) - -func runPrune(dockerCli *command.DockerCli, opts pruneOptions) error { - var message string - - if opts.all { - message = fmt.Sprintf(warning, allImageDesc) - } else { - message = fmt.Sprintf(warning, danglingImageDesc) - } - - if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), message) { - return nil - } - - var spaceReclaimed uint64 - - for _, pruneFn := range []func(dockerCli *command.DockerCli) (uint64, string, error){ - prune.RunContainerPrune, - prune.RunVolumePrune, - prune.RunNetworkPrune, - } { - spc, output, err := pruneFn(dockerCli) - if err != nil { - return err - } - spaceReclaimed += spc - if output != "" { - fmt.Fprintln(dockerCli.Out(), output) - } - } - - spc, output, err := prune.RunImagePrune(dockerCli, opts.all) - if err != nil { - return err - } - if spc > 0 { - spaceReclaimed += spc - fmt.Fprintln(dockerCli.Out(), output) - } - - fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) - - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/system/version.go b/vendor/github.com/docker/docker/cli/command/system/version.go deleted file mode 100644 index ded4f4d..0000000 --- a/vendor/github.com/docker/docker/cli/command/system/version.go +++ /dev/null @@ -1,113 +0,0 @@ -package system - -import ( - "fmt" - "runtime" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/utils/templates" - "github.com/spf13/cobra" -) - -var versionTemplate = `Client: - Version: {{.Client.Version}} - API version: {{.Client.APIVersion}} - Go version: {{.Client.GoVersion}} - Git commit: {{.Client.GitCommit}} - Built: {{.Client.BuildTime}} - OS/Arch: {{.Client.Os}}/{{.Client.Arch}}{{if .ServerOK}} - -Server: - Version: {{.Server.Version}} - API version: {{.Server.APIVersion}} (minimum version {{.Server.MinAPIVersion}}) - Go version: {{.Server.GoVersion}} - Git commit: {{.Server.GitCommit}} - Built: {{.Server.BuildTime}} - OS/Arch: {{.Server.Os}}/{{.Server.Arch}} - Experimental: {{.Server.Experimental}}{{end}}` - -type versionOptions struct { - format string -} - -// NewVersionCommand creates a new cobra.Command for `docker version` -func NewVersionCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts versionOptions - - cmd := &cobra.Command{ - Use: "version [OPTIONS]", - Short: "Show the Docker version information", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runVersion(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - - flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - - return cmd -} - -func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error { - ctx := context.Background() - - templateFormat := versionTemplate - if opts.format != "" { - templateFormat = opts.format - } - - tmpl, err := templates.Parse(templateFormat) - if err != nil { - return cli.StatusError{StatusCode: 64, - Status: "Template parsing error: " + err.Error()} - } - - APIVersion := dockerCli.Client().ClientVersion() - if defaultAPIVersion := dockerCli.DefaultVersion(); APIVersion != defaultAPIVersion { - APIVersion = fmt.Sprintf("%s (downgraded from %s)", APIVersion, defaultAPIVersion) - } - - vd := types.VersionResponse{ - Client: &types.Version{ - Version: dockerversion.Version, - APIVersion: APIVersion, - GoVersion: runtime.Version(), - GitCommit: dockerversion.GitCommit, - BuildTime: dockerversion.BuildTime, - Os: runtime.GOOS, - Arch: runtime.GOARCH, - }, - } - - serverVersion, err := dockerCli.Client().ServerVersion(ctx) - if err == nil { - vd.Server = &serverVersion - } - - // first we need to make BuildTime more human friendly - t, errTime := time.Parse(time.RFC3339Nano, vd.Client.BuildTime) - if errTime == nil { - vd.Client.BuildTime = t.Format(time.ANSIC) - } - - if vd.ServerOK() { - t, errTime = time.Parse(time.RFC3339Nano, vd.Server.BuildTime) - if errTime == nil { - vd.Server.BuildTime = t.Format(time.ANSIC) - } - } - - if err2 := tmpl.Execute(dockerCli.Out(), vd); err2 != nil && err == nil { - err = err2 - } - dockerCli.Out().Write([]byte{'\n'}) - return err -} diff --git a/vendor/github.com/docker/docker/cli/command/task/print.go b/vendor/github.com/docker/docker/cli/command/task/print.go deleted file mode 100644 index 0f1c2cf..0000000 --- a/vendor/github.com/docker/docker/cli/command/task/print.go +++ /dev/null @@ -1,161 +0,0 @@ -package task - -import ( - "fmt" - "io" - "sort" - "strings" - "text/tabwriter" - "time" - - "golang.org/x/net/context" - - distreference "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/idresolver" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/go-units" -) - -const ( - psTaskItemFmt = "%s\t%s\t%s\t%s\t%s\t%s %s ago\t%s\t%s\n" - maxErrLength = 30 -) - -type portStatus swarm.PortStatus - -func (ps portStatus) String() string { - if len(ps.Ports) == 0 { - return "" - } - - str := fmt.Sprintf("*:%d->%d/%s", ps.Ports[0].PublishedPort, ps.Ports[0].TargetPort, ps.Ports[0].Protocol) - for _, pConfig := range ps.Ports[1:] { - str += fmt.Sprintf(",*:%d->%d/%s", pConfig.PublishedPort, pConfig.TargetPort, pConfig.Protocol) - } - - return str -} - -type tasksBySlot []swarm.Task - -func (t tasksBySlot) Len() int { - return len(t) -} - -func (t tasksBySlot) Swap(i, j int) { - t[i], t[j] = t[j], t[i] -} - -func (t tasksBySlot) Less(i, j int) bool { - // Sort by slot. - if t[i].Slot != t[j].Slot { - return t[i].Slot < t[j].Slot - } - - // If same slot, sort by most recent. - return t[j].Meta.CreatedAt.Before(t[i].CreatedAt) -} - -// Print task information in a table format. -// Besides this, command `docker node ps ` -// and `docker stack ps` will call this, too. -func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error { - sort.Stable(tasksBySlot(tasks)) - - writer := tabwriter.NewWriter(dockerCli.Out(), 0, 4, 2, ' ', 0) - - // Ignore flushing errors - defer writer.Flush() - fmt.Fprintln(writer, strings.Join([]string{"ID", "NAME", "IMAGE", "NODE", "DESIRED STATE", "CURRENT STATE", "ERROR", "PORTS"}, "\t")) - - if err := print(writer, ctx, tasks, resolver, noTrunc); err != nil { - return err - } - - return nil -} - -// PrintQuiet shows task list in a quiet way. -func PrintQuiet(dockerCli *command.DockerCli, tasks []swarm.Task) error { - sort.Stable(tasksBySlot(tasks)) - - out := dockerCli.Out() - - for _, task := range tasks { - fmt.Fprintln(out, task.ID) - } - - return nil -} - -func print(out io.Writer, ctx context.Context, tasks []swarm.Task, resolver *idresolver.IDResolver, noTrunc bool) error { - prevName := "" - for _, task := range tasks { - id := task.ID - if !noTrunc { - id = stringid.TruncateID(id) - } - - serviceName, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID) - if err != nil { - return err - } - - nodeValue, err := resolver.Resolve(ctx, swarm.Node{}, task.NodeID) - if err != nil { - return err - } - - name := "" - if task.Slot != 0 { - name = fmt.Sprintf("%v.%v", serviceName, task.Slot) - } else { - name = fmt.Sprintf("%v.%v", serviceName, task.NodeID) - } - - // Indent the name if necessary - indentedName := name - if name == prevName { - indentedName = fmt.Sprintf(" \\_ %s", indentedName) - } - prevName = name - - // Trim and quote the error message. - taskErr := task.Status.Err - if !noTrunc && len(taskErr) > maxErrLength { - taskErr = fmt.Sprintf("%s…", taskErr[:maxErrLength-1]) - } - if len(taskErr) > 0 { - taskErr = fmt.Sprintf("\"%s\"", taskErr) - } - - image := task.Spec.ContainerSpec.Image - if !noTrunc { - ref, err := distreference.ParseNamed(image) - if err == nil { - // update image string for display - namedTagged, ok := ref.(distreference.NamedTagged) - if ok { - image = namedTagged.Name() + ":" + namedTagged.Tag() - } - } - } - - fmt.Fprintf( - out, - psTaskItemFmt, - id, - indentedName, - image, - nodeValue, - command.PrettyPrint(task.DesiredState), - command.PrettyPrint(task.Status.State), - strings.ToLower(units.HumanDuration(time.Since(task.Status.Timestamp))), - taskErr, - portStatus(task.Status.PortStatus), - ) - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/command/trust.go b/vendor/github.com/docker/docker/cli/command/trust.go deleted file mode 100644 index b4c8a84..0000000 --- a/vendor/github.com/docker/docker/cli/command/trust.go +++ /dev/null @@ -1,39 +0,0 @@ -package command - -import ( - "os" - "strconv" - - "github.com/spf13/pflag" -) - -var ( - // TODO: make this not global - untrusted bool -) - -// AddTrustedFlags adds content trust flags to the current command flagset -func AddTrustedFlags(fs *pflag.FlagSet, verify bool) { - trusted, message := setupTrustedFlag(verify) - fs.BoolVar(&untrusted, "disable-content-trust", !trusted, message) -} - -func setupTrustedFlag(verify bool) (bool, string) { - var trusted bool - if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" { - if t, err := strconv.ParseBool(e); t || err != nil { - // treat any other value as true - trusted = true - } - } - message := "Skip image signing" - if verify { - message = "Skip image verification" - } - return trusted, message -} - -// IsTrusted returns true if content trust is enabled -func IsTrusted() bool { - return !untrusted -} diff --git a/vendor/github.com/docker/docker/cli/command/utils.go b/vendor/github.com/docker/docker/cli/command/utils.go deleted file mode 100644 index 1837ca4..0000000 --- a/vendor/github.com/docker/docker/cli/command/utils.go +++ /dev/null @@ -1,87 +0,0 @@ -package command - -import ( - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "runtime" - "strings" -) - -// CopyToFile writes the content of the reader to the specified file -func CopyToFile(outfile string, r io.Reader) error { - tmpFile, err := ioutil.TempFile(filepath.Dir(outfile), ".docker_temp_") - if err != nil { - return err - } - - tmpPath := tmpFile.Name() - - _, err = io.Copy(tmpFile, r) - tmpFile.Close() - - if err != nil { - os.Remove(tmpPath) - return err - } - - if err = os.Rename(tmpPath, outfile); err != nil { - os.Remove(tmpPath) - return err - } - - return nil -} - -// capitalizeFirst capitalizes the first character of string -func capitalizeFirst(s string) string { - switch l := len(s); l { - case 0: - return s - case 1: - return strings.ToLower(s) - default: - return strings.ToUpper(string(s[0])) + strings.ToLower(s[1:]) - } -} - -// PrettyPrint outputs arbitrary data for human formatted output by uppercasing the first letter. -func PrettyPrint(i interface{}) string { - switch t := i.(type) { - case nil: - return "None" - case string: - return capitalizeFirst(t) - default: - return capitalizeFirst(fmt.Sprintf("%s", t)) - } -} - -// PromptForConfirmation requests and checks confirmation from user. -// This will display the provided message followed by ' [y/N] '. If -// the user input 'y' or 'Y' it returns true other false. If no -// message is provided "Are you sure you want to proceed? [y/N] " -// will be used instead. -func PromptForConfirmation(ins *InStream, outs *OutStream, message string) bool { - if message == "" { - message = "Are you sure you want to proceed?" - } - message += " [y/N] " - - fmt.Fprintf(outs, message) - - // On Windows, force the use of the regular OS stdin stream. - if runtime.GOOS == "windows" { - ins = NewInStream(os.Stdin) - } - - answer := "" - n, _ := fmt.Fscan(ins, &answer) - if n != 1 || (answer != "y" && answer != "Y") { - return false - } - - return true -} diff --git a/vendor/github.com/docker/docker/cli/command/volume/cmd.go b/vendor/github.com/docker/docker/cli/command/volume/cmd.go deleted file mode 100644 index 40862f2..0000000 --- a/vendor/github.com/docker/docker/cli/command/volume/cmd.go +++ /dev/null @@ -1,45 +0,0 @@ -package volume - -import ( - "github.com/spf13/cobra" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" -) - -// NewVolumeCommand returns a cobra command for `volume` subcommands -func NewVolumeCommand(dockerCli *command.DockerCli) *cobra.Command { - cmd := &cobra.Command{ - Use: "volume COMMAND", - Short: "Manage volumes", - Long: volumeDescription, - Args: cli.NoArgs, - RunE: dockerCli.ShowHelp, - } - cmd.AddCommand( - newCreateCommand(dockerCli), - newInspectCommand(dockerCli), - newListCommand(dockerCli), - newRemoveCommand(dockerCli), - NewPruneCommand(dockerCli), - ) - return cmd -} - -var volumeDescription = ` -The **docker volume** command has subcommands for managing data volumes. A data -volume is a specially-designated directory that by-passes storage driver -management. - -Data volumes persist data independent of a container's life cycle. When you -delete a container, the Docker daemon does not delete any data volumes. You can -share volumes across multiple containers. Moreover, you can share data volumes -with other computing resources in your system. - -To see help for a subcommand, use: - - docker volume COMMAND --help - -For full details on using docker volume visit Docker's online documentation. - -` diff --git a/vendor/github.com/docker/docker/cli/command/volume/create.go b/vendor/github.com/docker/docker/cli/command/volume/create.go deleted file mode 100644 index 7b2a7e3..0000000 --- a/vendor/github.com/docker/docker/cli/command/volume/create.go +++ /dev/null @@ -1,111 +0,0 @@ -package volume - -import ( - "fmt" - - "golang.org/x/net/context" - - volumetypes "github.com/docker/docker/api/types/volume" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/opts" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/spf13/cobra" -) - -type createOptions struct { - name string - driver string - driverOpts opts.MapOpts - labels opts.ListOpts -} - -func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := createOptions{ - driverOpts: *opts.NewMapOpts(nil, nil), - labels: opts.NewListOpts(runconfigopts.ValidateEnv), - } - - cmd := &cobra.Command{ - Use: "create [OPTIONS] [VOLUME]", - Short: "Create a volume", - Long: createDescription, - Args: cli.RequiresMaxArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 1 { - if opts.name != "" { - fmt.Fprint(dockerCli.Err(), "Conflicting options: either specify --name or provide positional arg, not both\n") - return cli.StatusError{StatusCode: 1} - } - opts.name = args[0] - } - return runCreate(dockerCli, opts) - }, - } - flags := cmd.Flags() - flags.StringVarP(&opts.driver, "driver", "d", "local", "Specify volume driver name") - flags.StringVar(&opts.name, "name", "", "Specify volume name") - flags.Lookup("name").Hidden = true - flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options") - flags.Var(&opts.labels, "label", "Set metadata for a volume") - - return cmd -} - -func runCreate(dockerCli *command.DockerCli, opts createOptions) error { - client := dockerCli.Client() - - volReq := volumetypes.VolumesCreateBody{ - Driver: opts.driver, - DriverOpts: opts.driverOpts.GetAll(), - Name: opts.name, - Labels: runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()), - } - - vol, err := client.VolumeCreate(context.Background(), volReq) - if err != nil { - return err - } - - fmt.Fprintf(dockerCli.Out(), "%s\n", vol.Name) - return nil -} - -var createDescription = ` -Creates a new volume that containers can consume and store data in. If a name -is not specified, Docker generates a random name. You create a volume and then -configure the container to use it, for example: - - $ docker volume create hello - hello - $ docker run -d -v hello:/world busybox ls /world - -The mount is created inside the container's **/src** directory. Docker doesn't -not support relative paths for mount points inside the container. - -Multiple containers can use the same volume in the same time period. This is -useful if two containers need access to shared data. For example, if one -container writes and the other reads the data. - -## Driver specific options - -Some volume drivers may take options to customize the volume creation. Use the -**-o** or **--opt** flags to pass driver options: - - $ docker volume create --driver fake --opt tardis=blue --opt timey=wimey - -These options are passed directly to the volume driver. Options for different -volume drivers may do different things (or nothing at all). - -The built-in **local** driver on Windows does not support any options. - -The built-in **local** driver on Linux accepts options similar to the linux -**mount** command: - - $ docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000 - -Another example: - - $ docker volume create --driver local --opt type=btrfs --opt device=/dev/sda2 - -` diff --git a/vendor/github.com/docker/docker/cli/command/volume/inspect.go b/vendor/github.com/docker/docker/cli/command/volume/inspect.go deleted file mode 100644 index 5eb8ad2..0000000 --- a/vendor/github.com/docker/docker/cli/command/volume/inspect.go +++ /dev/null @@ -1,55 +0,0 @@ -package volume - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/inspect" - "github.com/spf13/cobra" -) - -type inspectOptions struct { - format string - names []string -} - -func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts inspectOptions - - cmd := &cobra.Command{ - Use: "inspect [OPTIONS] VOLUME [VOLUME...]", - Short: "Display detailed information on one or more volumes", - Long: inspectDescription, - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.names = args - return runInspect(dockerCli, opts) - }, - } - - cmd.Flags().StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") - - return cmd -} - -func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { - client := dockerCli.Client() - - ctx := context.Background() - - getVolFunc := func(name string) (interface{}, []byte, error) { - i, err := client.VolumeInspect(ctx, name) - return i, nil, err - } - - return inspect.Inspect(dockerCli.Out(), opts.names, opts.format, getVolFunc) -} - -var inspectDescription = ` -Returns information about one or more volumes. By default, this command renders -all results in a JSON array. You can specify an alternate format to execute a -given template is executed for each result. Go's https://golang.org/pkg/text/template/ -package describes all the details of the format. - -` diff --git a/vendor/github.com/docker/docker/cli/command/volume/list.go b/vendor/github.com/docker/docker/cli/command/volume/list.go deleted file mode 100644 index d76006a..0000000 --- a/vendor/github.com/docker/docker/cli/command/volume/list.go +++ /dev/null @@ -1,91 +0,0 @@ -package volume - -import ( - "sort" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/formatter" - "github.com/docker/docker/opts" - "github.com/spf13/cobra" -) - -type byVolumeName []*types.Volume - -func (r byVolumeName) Len() int { return len(r) } -func (r byVolumeName) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r byVolumeName) Less(i, j int) bool { - return r[i].Name < r[j].Name -} - -type listOptions struct { - quiet bool - format string - filter opts.FilterOpt -} - -func newListCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := listOptions{filter: opts.NewFilterOpt()} - - cmd := &cobra.Command{ - Use: "ls [OPTIONS]", - Aliases: []string{"list"}, - Short: "List volumes", - Long: listDescription, - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runList(dockerCli, opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display volume names") - flags.StringVar(&opts.format, "format", "", "Pretty-print volumes using a Go template") - flags.VarP(&opts.filter, "filter", "f", "Provide filter values (e.g. 'dangling=true')") - - return cmd -} - -func runList(dockerCli *command.DockerCli, opts listOptions) error { - client := dockerCli.Client() - volumes, err := client.VolumeList(context.Background(), opts.filter.Value()) - if err != nil { - return err - } - - format := opts.format - if len(format) == 0 { - if len(dockerCli.ConfigFile().VolumesFormat) > 0 && !opts.quiet { - format = dockerCli.ConfigFile().VolumesFormat - } else { - format = formatter.TableFormatKey - } - } - - sort.Sort(byVolumeName(volumes.Volumes)) - - volumeCtx := formatter.Context{ - Output: dockerCli.Out(), - Format: formatter.NewVolumeFormat(format, opts.quiet), - } - return formatter.VolumeWrite(volumeCtx, volumes.Volumes) -} - -var listDescription = ` - -Lists all the volumes Docker manages. You can filter using the **-f** or -**--filter** flag. The filtering format is a **key=value** pair. To specify -more than one filter, pass multiple flags (for example, -**--filter "foo=bar" --filter "bif=baz"**) - -The currently supported filters are: - -* **dangling** (boolean - **true** or **false**, **1** or **0**) -* **driver** (a volume driver's name) -* **label** (**label=** or **label==**) -* **name** (a volume's name) - -` diff --git a/vendor/github.com/docker/docker/cli/command/volume/prune.go b/vendor/github.com/docker/docker/cli/command/volume/prune.go deleted file mode 100644 index 405fbeb..0000000 --- a/vendor/github.com/docker/docker/cli/command/volume/prune.go +++ /dev/null @@ -1,75 +0,0 @@ -package volume - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - units "github.com/docker/go-units" - "github.com/spf13/cobra" -) - -type pruneOptions struct { - force bool -} - -// NewPruneCommand returns a new cobra prune command for volumes -func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts pruneOptions - - cmd := &cobra.Command{ - Use: "prune [OPTIONS]", - Short: "Remove all unused volumes", - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - spaceReclaimed, output, err := runPrune(dockerCli, opts) - if err != nil { - return err - } - if output != "" { - fmt.Fprintln(dockerCli.Out(), output) - } - fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) - return nil - }, - Tags: map[string]string{"version": "1.25"}, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") - - return cmd -} - -const warning = `WARNING! This will remove all volumes not used by at least one container. -Are you sure you want to continue?` - -func runPrune(dockerCli *command.DockerCli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) { - if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) { - return - } - - report, err := dockerCli.Client().VolumesPrune(context.Background(), filters.Args{}) - if err != nil { - return - } - - if len(report.VolumesDeleted) > 0 { - output = "Deleted Volumes:\n" - for _, id := range report.VolumesDeleted { - output += id + "\n" - } - spaceReclaimed = report.SpaceReclaimed - } - - return -} - -// RunPrune calls the Volume Prune API -// This returns the amount of space reclaimed and a detailed output string -func RunPrune(dockerCli *command.DockerCli) (uint64, string, error) { - return runPrune(dockerCli, pruneOptions{force: true}) -} diff --git a/vendor/github.com/docker/docker/cli/command/volume/remove.go b/vendor/github.com/docker/docker/cli/command/volume/remove.go deleted file mode 100644 index f464bb3..0000000 --- a/vendor/github.com/docker/docker/cli/command/volume/remove.go +++ /dev/null @@ -1,68 +0,0 @@ -package volume - -import ( - "fmt" - - "golang.org/x/net/context" - - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/spf13/cobra" -) - -type removeOptions struct { - force bool - - volumes []string -} - -func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command { - var opts removeOptions - - cmd := &cobra.Command{ - Use: "rm [OPTIONS] VOLUME [VOLUME...]", - Aliases: []string{"remove"}, - Short: "Remove one or more volumes", - Long: removeDescription, - Example: removeExample, - Args: cli.RequiresMinArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - opts.volumes = args - return runRemove(dockerCli, &opts) - }, - } - - flags := cmd.Flags() - flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of one or more volumes") - flags.SetAnnotation("force", "version", []string{"1.25"}) - return cmd -} - -func runRemove(dockerCli *command.DockerCli, opts *removeOptions) error { - client := dockerCli.Client() - ctx := context.Background() - status := 0 - - for _, name := range opts.volumes { - if err := client.VolumeRemove(ctx, name, opts.force); err != nil { - fmt.Fprintf(dockerCli.Err(), "%s\n", err) - status = 1 - continue - } - fmt.Fprintf(dockerCli.Out(), "%s\n", name) - } - - if status != 0 { - return cli.StatusError{StatusCode: status} - } - return nil -} - -var removeDescription = ` -Remove one or more volumes. You cannot remove a volume that is in use by a container. -` - -var removeExample = ` -$ docker volume rm hello -hello -` diff --git a/vendor/github.com/docker/docker/cli/compose/convert/compose.go b/vendor/github.com/docker/docker/cli/compose/convert/compose.go deleted file mode 100644 index 8122326..0000000 --- a/vendor/github.com/docker/docker/cli/compose/convert/compose.go +++ /dev/null @@ -1,116 +0,0 @@ -package convert - -import ( - "io/ioutil" - - "github.com/docker/docker/api/types" - networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/api/types/swarm" - composetypes "github.com/docker/docker/cli/compose/types" -) - -const ( - // LabelNamespace is the label used to track stack resources - LabelNamespace = "com.docker.stack.namespace" -) - -// Namespace mangles names by prepending the name -type Namespace struct { - name string -} - -// Scope prepends the namespace to a name -func (n Namespace) Scope(name string) string { - return n.name + "_" + name -} - -// Name returns the name of the namespace -func (n Namespace) Name() string { - return n.name -} - -// NewNamespace returns a new Namespace for scoping of names -func NewNamespace(name string) Namespace { - return Namespace{name: name} -} - -// AddStackLabel returns labels with the namespace label added -func AddStackLabel(namespace Namespace, labels map[string]string) map[string]string { - if labels == nil { - labels = make(map[string]string) - } - labels[LabelNamespace] = namespace.name - return labels -} - -type networkMap map[string]composetypes.NetworkConfig - -// Networks converts networks from the compose-file type to the engine API type -func Networks( - namespace Namespace, - networks networkMap, - servicesNetworks map[string]struct{}, -) (map[string]types.NetworkCreate, []string) { - if networks == nil { - networks = make(map[string]composetypes.NetworkConfig) - } - - externalNetworks := []string{} - result := make(map[string]types.NetworkCreate) - - for internalName := range servicesNetworks { - network := networks[internalName] - if network.External.External { - externalNetworks = append(externalNetworks, network.External.Name) - continue - } - - createOpts := types.NetworkCreate{ - Labels: AddStackLabel(namespace, network.Labels), - Driver: network.Driver, - Options: network.DriverOpts, - Internal: network.Internal, - } - - if network.Ipam.Driver != "" || len(network.Ipam.Config) > 0 { - createOpts.IPAM = &networktypes.IPAM{} - } - - if network.Ipam.Driver != "" { - createOpts.IPAM.Driver = network.Ipam.Driver - } - for _, ipamConfig := range network.Ipam.Config { - config := networktypes.IPAMConfig{ - Subnet: ipamConfig.Subnet, - } - createOpts.IPAM.Config = append(createOpts.IPAM.Config, config) - } - result[internalName] = createOpts - } - - return result, externalNetworks -} - -// Secrets converts secrets from the Compose type to the engine API type -func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig) ([]swarm.SecretSpec, error) { - result := []swarm.SecretSpec{} - for name, secret := range secrets { - if secret.External.External { - continue - } - - data, err := ioutil.ReadFile(secret.File) - if err != nil { - return nil, err - } - - result = append(result, swarm.SecretSpec{ - Annotations: swarm.Annotations{ - Name: namespace.Scope(name), - Labels: AddStackLabel(namespace, secret.Labels), - }, - Data: data, - }) - } - return result, nil -} diff --git a/vendor/github.com/docker/docker/cli/compose/convert/compose_test.go b/vendor/github.com/docker/docker/cli/compose/convert/compose_test.go deleted file mode 100644 index f333d73..0000000 --- a/vendor/github.com/docker/docker/cli/compose/convert/compose_test.go +++ /dev/null @@ -1,122 +0,0 @@ -package convert - -import ( - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/network" - composetypes "github.com/docker/docker/cli/compose/types" - "github.com/docker/docker/pkg/testutil/assert" - "github.com/docker/docker/pkg/testutil/tempfile" -) - -func TestNamespaceScope(t *testing.T) { - scoped := Namespace{name: "foo"}.Scope("bar") - assert.Equal(t, scoped, "foo_bar") -} - -func TestAddStackLabel(t *testing.T) { - labels := map[string]string{ - "something": "labeled", - } - actual := AddStackLabel(Namespace{name: "foo"}, labels) - expected := map[string]string{ - "something": "labeled", - LabelNamespace: "foo", - } - assert.DeepEqual(t, actual, expected) -} - -func TestNetworks(t *testing.T) { - namespace := Namespace{name: "foo"} - source := networkMap{ - "normal": composetypes.NetworkConfig{ - Driver: "overlay", - DriverOpts: map[string]string{ - "opt": "value", - }, - Ipam: composetypes.IPAMConfig{ - Driver: "driver", - Config: []*composetypes.IPAMPool{ - { - Subnet: "10.0.0.0", - }, - }, - }, - Labels: map[string]string{ - "something": "labeled", - }, - }, - "outside": composetypes.NetworkConfig{ - External: composetypes.External{ - External: true, - Name: "special", - }, - }, - } - expected := map[string]types.NetworkCreate{ - "default": { - Labels: map[string]string{ - LabelNamespace: "foo", - }, - }, - "normal": { - Driver: "overlay", - IPAM: &network.IPAM{ - Driver: "driver", - Config: []network.IPAMConfig{ - { - Subnet: "10.0.0.0", - }, - }, - }, - Options: map[string]string{ - "opt": "value", - }, - Labels: map[string]string{ - LabelNamespace: "foo", - "something": "labeled", - }, - }, - } - - serviceNetworks := map[string]struct{}{ - "default": {}, - "normal": {}, - "outside": {}, - } - networks, externals := Networks(namespace, source, serviceNetworks) - assert.DeepEqual(t, networks, expected) - assert.DeepEqual(t, externals, []string{"special"}) -} - -func TestSecrets(t *testing.T) { - namespace := Namespace{name: "foo"} - - secretText := "this is the first secret" - secretFile := tempfile.NewTempFile(t, "convert-secrets", secretText) - defer secretFile.Remove() - - source := map[string]composetypes.SecretConfig{ - "one": { - File: secretFile.Name(), - Labels: map[string]string{"monster": "mash"}, - }, - "ext": { - External: composetypes.External{ - External: true, - }, - }, - } - - specs, err := Secrets(namespace, source) - assert.NilError(t, err) - assert.Equal(t, len(specs), 1) - secret := specs[0] - assert.Equal(t, secret.Name, "foo_one") - assert.DeepEqual(t, secret.Labels, map[string]string{ - "monster": "mash", - LabelNamespace: "foo", - }) - assert.DeepEqual(t, secret.Data, []byte(secretText)) -} diff --git a/vendor/github.com/docker/docker/cli/compose/convert/service.go b/vendor/github.com/docker/docker/cli/compose/convert/service.go deleted file mode 100644 index 4a54895..0000000 --- a/vendor/github.com/docker/docker/cli/compose/convert/service.go +++ /dev/null @@ -1,416 +0,0 @@ -package convert - -import ( - "fmt" - "os" - "sort" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/swarm" - servicecli "github.com/docker/docker/cli/command/service" - composetypes "github.com/docker/docker/cli/compose/types" - "github.com/docker/docker/client" - "github.com/docker/docker/opts" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/docker/go-connections/nat" -) - -// Services from compose-file types to engine API types -// TODO: fix secrets API so that SecretAPIClient is not required here -func Services( - namespace Namespace, - config *composetypes.Config, - client client.SecretAPIClient, -) (map[string]swarm.ServiceSpec, error) { - result := make(map[string]swarm.ServiceSpec) - - services := config.Services - volumes := config.Volumes - networks := config.Networks - - for _, service := range services { - - secrets, err := convertServiceSecrets(client, namespace, service.Secrets, config.Secrets) - if err != nil { - return nil, err - } - serviceSpec, err := convertService(namespace, service, networks, volumes, secrets) - if err != nil { - return nil, err - } - result[service.Name] = serviceSpec - } - - return result, nil -} - -func convertService( - namespace Namespace, - service composetypes.ServiceConfig, - networkConfigs map[string]composetypes.NetworkConfig, - volumes map[string]composetypes.VolumeConfig, - secrets []*swarm.SecretReference, -) (swarm.ServiceSpec, error) { - name := namespace.Scope(service.Name) - - endpoint, err := convertEndpointSpec(service.Ports) - if err != nil { - return swarm.ServiceSpec{}, err - } - - mode, err := convertDeployMode(service.Deploy.Mode, service.Deploy.Replicas) - if err != nil { - return swarm.ServiceSpec{}, err - } - - mounts, err := Volumes(service.Volumes, volumes, namespace) - if err != nil { - // TODO: better error message (include service name) - return swarm.ServiceSpec{}, err - } - - resources, err := convertResources(service.Deploy.Resources) - if err != nil { - return swarm.ServiceSpec{}, err - } - - restartPolicy, err := convertRestartPolicy( - service.Restart, service.Deploy.RestartPolicy) - if err != nil { - return swarm.ServiceSpec{}, err - } - - healthcheck, err := convertHealthcheck(service.HealthCheck) - if err != nil { - return swarm.ServiceSpec{}, err - } - - networks, err := convertServiceNetworks(service.Networks, networkConfigs, namespace, service.Name) - if err != nil { - return swarm.ServiceSpec{}, err - } - - var logDriver *swarm.Driver - if service.Logging != nil { - logDriver = &swarm.Driver{ - Name: service.Logging.Driver, - Options: service.Logging.Options, - } - } - - serviceSpec := swarm.ServiceSpec{ - Annotations: swarm.Annotations{ - Name: name, - Labels: AddStackLabel(namespace, service.Deploy.Labels), - }, - TaskTemplate: swarm.TaskSpec{ - ContainerSpec: swarm.ContainerSpec{ - Image: service.Image, - Command: service.Entrypoint, - Args: service.Command, - Hostname: service.Hostname, - Hosts: sortStrings(convertExtraHosts(service.ExtraHosts)), - Healthcheck: healthcheck, - Env: sortStrings(convertEnvironment(service.Environment)), - Labels: AddStackLabel(namespace, service.Labels), - Dir: service.WorkingDir, - User: service.User, - Mounts: mounts, - StopGracePeriod: service.StopGracePeriod, - TTY: service.Tty, - OpenStdin: service.StdinOpen, - Secrets: secrets, - }, - LogDriver: logDriver, - Resources: resources, - RestartPolicy: restartPolicy, - Placement: &swarm.Placement{ - Constraints: service.Deploy.Placement.Constraints, - }, - }, - EndpointSpec: endpoint, - Mode: mode, - Networks: networks, - UpdateConfig: convertUpdateConfig(service.Deploy.UpdateConfig), - } - - return serviceSpec, nil -} - -func sortStrings(strs []string) []string { - sort.Strings(strs) - return strs -} - -type byNetworkTarget []swarm.NetworkAttachmentConfig - -func (a byNetworkTarget) Len() int { return len(a) } -func (a byNetworkTarget) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a byNetworkTarget) Less(i, j int) bool { return a[i].Target < a[j].Target } - -func convertServiceNetworks( - networks map[string]*composetypes.ServiceNetworkConfig, - networkConfigs networkMap, - namespace Namespace, - name string, -) ([]swarm.NetworkAttachmentConfig, error) { - if len(networks) == 0 { - return []swarm.NetworkAttachmentConfig{ - { - Target: namespace.Scope("default"), - Aliases: []string{name}, - }, - }, nil - } - - nets := []swarm.NetworkAttachmentConfig{} - for networkName, network := range networks { - networkConfig, ok := networkConfigs[networkName] - if !ok { - return []swarm.NetworkAttachmentConfig{}, fmt.Errorf( - "service %q references network %q, which is not declared", name, networkName) - } - var aliases []string - if network != nil { - aliases = network.Aliases - } - target := namespace.Scope(networkName) - if networkConfig.External.External { - target = networkConfig.External.Name - } - nets = append(nets, swarm.NetworkAttachmentConfig{ - Target: target, - Aliases: append(aliases, name), - }) - } - - sort.Sort(byNetworkTarget(nets)) - - return nets, nil -} - -// TODO: fix secrets API so that SecretAPIClient is not required here -func convertServiceSecrets( - client client.SecretAPIClient, - namespace Namespace, - secrets []composetypes.ServiceSecretConfig, - secretSpecs map[string]composetypes.SecretConfig, -) ([]*swarm.SecretReference, error) { - opts := []*types.SecretRequestOption{} - for _, secret := range secrets { - target := secret.Target - if target == "" { - target = secret.Source - } - - source := namespace.Scope(secret.Source) - secretSpec := secretSpecs[secret.Source] - if secretSpec.External.External { - source = secretSpec.External.Name - } - - uid := secret.UID - gid := secret.GID - if uid == "" { - uid = "0" - } - if gid == "" { - gid = "0" - } - - opts = append(opts, &types.SecretRequestOption{ - Source: source, - Target: target, - UID: uid, - GID: gid, - Mode: os.FileMode(secret.Mode), - }) - } - - return servicecli.ParseSecrets(client, opts) -} - -func convertExtraHosts(extraHosts map[string]string) []string { - hosts := []string{} - for host, ip := range extraHosts { - hosts = append(hosts, fmt.Sprintf("%s %s", ip, host)) - } - return hosts -} - -func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container.HealthConfig, error) { - if healthcheck == nil { - return nil, nil - } - var ( - err error - timeout, interval time.Duration - retries int - ) - if healthcheck.Disable { - if len(healthcheck.Test) != 0 { - return nil, fmt.Errorf("test and disable can't be set at the same time") - } - return &container.HealthConfig{ - Test: []string{"NONE"}, - }, nil - - } - if healthcheck.Timeout != "" { - timeout, err = time.ParseDuration(healthcheck.Timeout) - if err != nil { - return nil, err - } - } - if healthcheck.Interval != "" { - interval, err = time.ParseDuration(healthcheck.Interval) - if err != nil { - return nil, err - } - } - if healthcheck.Retries != nil { - retries = int(*healthcheck.Retries) - } - return &container.HealthConfig{ - Test: healthcheck.Test, - Timeout: timeout, - Interval: interval, - Retries: retries, - }, nil -} - -func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*swarm.RestartPolicy, error) { - // TODO: log if restart is being ignored - if source == nil { - policy, err := runconfigopts.ParseRestartPolicy(restart) - if err != nil { - return nil, err - } - switch { - case policy.IsNone(): - return nil, nil - case policy.IsAlways(), policy.IsUnlessStopped(): - return &swarm.RestartPolicy{ - Condition: swarm.RestartPolicyConditionAny, - }, nil - case policy.IsOnFailure(): - attempts := uint64(policy.MaximumRetryCount) - return &swarm.RestartPolicy{ - Condition: swarm.RestartPolicyConditionOnFailure, - MaxAttempts: &attempts, - }, nil - default: - return nil, fmt.Errorf("unknown restart policy: %s", restart) - } - } - return &swarm.RestartPolicy{ - Condition: swarm.RestartPolicyCondition(source.Condition), - Delay: source.Delay, - MaxAttempts: source.MaxAttempts, - Window: source.Window, - }, nil -} - -func convertUpdateConfig(source *composetypes.UpdateConfig) *swarm.UpdateConfig { - if source == nil { - return nil - } - parallel := uint64(1) - if source.Parallelism != nil { - parallel = *source.Parallelism - } - return &swarm.UpdateConfig{ - Parallelism: parallel, - Delay: source.Delay, - FailureAction: source.FailureAction, - Monitor: source.Monitor, - MaxFailureRatio: source.MaxFailureRatio, - } -} - -func convertResources(source composetypes.Resources) (*swarm.ResourceRequirements, error) { - resources := &swarm.ResourceRequirements{} - var err error - if source.Limits != nil { - var cpus int64 - if source.Limits.NanoCPUs != "" { - cpus, err = opts.ParseCPUs(source.Limits.NanoCPUs) - if err != nil { - return nil, err - } - } - resources.Limits = &swarm.Resources{ - NanoCPUs: cpus, - MemoryBytes: int64(source.Limits.MemoryBytes), - } - } - if source.Reservations != nil { - var cpus int64 - if source.Reservations.NanoCPUs != "" { - cpus, err = opts.ParseCPUs(source.Reservations.NanoCPUs) - if err != nil { - return nil, err - } - } - resources.Reservations = &swarm.Resources{ - NanoCPUs: cpus, - MemoryBytes: int64(source.Reservations.MemoryBytes), - } - } - return resources, nil - -} - -type byPublishedPort []swarm.PortConfig - -func (a byPublishedPort) Len() int { return len(a) } -func (a byPublishedPort) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a byPublishedPort) Less(i, j int) bool { return a[i].PublishedPort < a[j].PublishedPort } - -func convertEndpointSpec(source []string) (*swarm.EndpointSpec, error) { - portConfigs := []swarm.PortConfig{} - ports, portBindings, err := nat.ParsePortSpecs(source) - if err != nil { - return nil, err - } - - for port := range ports { - portConfigs = append( - portConfigs, - opts.ConvertPortToPortConfig(port, portBindings)...) - } - - // Sorting to make sure these are always in the same order - sort.Sort(byPublishedPort(portConfigs)) - - return &swarm.EndpointSpec{Ports: portConfigs}, nil -} - -func convertEnvironment(source map[string]string) []string { - var output []string - - for name, value := range source { - output = append(output, fmt.Sprintf("%s=%s", name, value)) - } - - return output -} - -func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error) { - serviceMode := swarm.ServiceMode{} - - switch mode { - case "global": - if replicas != nil { - return serviceMode, fmt.Errorf("replicas can only be used with replicated mode") - } - serviceMode.Global = &swarm.GlobalService{} - case "replicated", "": - serviceMode.Replicated = &swarm.ReplicatedService{Replicas: replicas} - default: - return serviceMode, fmt.Errorf("Unknown mode: %s", mode) - } - return serviceMode, nil -} diff --git a/vendor/github.com/docker/docker/cli/compose/convert/service_test.go b/vendor/github.com/docker/docker/cli/compose/convert/service_test.go deleted file mode 100644 index 2e614d7..0000000 --- a/vendor/github.com/docker/docker/cli/compose/convert/service_test.go +++ /dev/null @@ -1,216 +0,0 @@ -package convert - -import ( - "sort" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/swarm" - composetypes "github.com/docker/docker/cli/compose/types" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestConvertRestartPolicyFromNone(t *testing.T) { - policy, err := convertRestartPolicy("no", nil) - assert.NilError(t, err) - assert.Equal(t, policy, (*swarm.RestartPolicy)(nil)) -} - -func TestConvertRestartPolicyFromUnknown(t *testing.T) { - _, err := convertRestartPolicy("unknown", nil) - assert.Error(t, err, "unknown restart policy: unknown") -} - -func TestConvertRestartPolicyFromAlways(t *testing.T) { - policy, err := convertRestartPolicy("always", nil) - expected := &swarm.RestartPolicy{ - Condition: swarm.RestartPolicyConditionAny, - } - assert.NilError(t, err) - assert.DeepEqual(t, policy, expected) -} - -func TestConvertRestartPolicyFromFailure(t *testing.T) { - policy, err := convertRestartPolicy("on-failure:4", nil) - attempts := uint64(4) - expected := &swarm.RestartPolicy{ - Condition: swarm.RestartPolicyConditionOnFailure, - MaxAttempts: &attempts, - } - assert.NilError(t, err) - assert.DeepEqual(t, policy, expected) -} - -func TestConvertEnvironment(t *testing.T) { - source := map[string]string{ - "foo": "bar", - "key": "value", - } - env := convertEnvironment(source) - sort.Strings(env) - assert.DeepEqual(t, env, []string{"foo=bar", "key=value"}) -} - -func TestConvertResourcesFull(t *testing.T) { - source := composetypes.Resources{ - Limits: &composetypes.Resource{ - NanoCPUs: "0.003", - MemoryBytes: composetypes.UnitBytes(300000000), - }, - Reservations: &composetypes.Resource{ - NanoCPUs: "0.002", - MemoryBytes: composetypes.UnitBytes(200000000), - }, - } - resources, err := convertResources(source) - assert.NilError(t, err) - - expected := &swarm.ResourceRequirements{ - Limits: &swarm.Resources{ - NanoCPUs: 3000000, - MemoryBytes: 300000000, - }, - Reservations: &swarm.Resources{ - NanoCPUs: 2000000, - MemoryBytes: 200000000, - }, - } - assert.DeepEqual(t, resources, expected) -} - -func TestConvertResourcesOnlyMemory(t *testing.T) { - source := composetypes.Resources{ - Limits: &composetypes.Resource{ - MemoryBytes: composetypes.UnitBytes(300000000), - }, - Reservations: &composetypes.Resource{ - MemoryBytes: composetypes.UnitBytes(200000000), - }, - } - resources, err := convertResources(source) - assert.NilError(t, err) - - expected := &swarm.ResourceRequirements{ - Limits: &swarm.Resources{ - MemoryBytes: 300000000, - }, - Reservations: &swarm.Resources{ - MemoryBytes: 200000000, - }, - } - assert.DeepEqual(t, resources, expected) -} - -func TestConvertHealthcheck(t *testing.T) { - retries := uint64(10) - source := &composetypes.HealthCheckConfig{ - Test: []string{"EXEC", "touch", "/foo"}, - Timeout: "30s", - Interval: "2ms", - Retries: &retries, - } - expected := &container.HealthConfig{ - Test: source.Test, - Timeout: 30 * time.Second, - Interval: 2 * time.Millisecond, - Retries: 10, - } - - healthcheck, err := convertHealthcheck(source) - assert.NilError(t, err) - assert.DeepEqual(t, healthcheck, expected) -} - -func TestConvertHealthcheckDisable(t *testing.T) { - source := &composetypes.HealthCheckConfig{Disable: true} - expected := &container.HealthConfig{ - Test: []string{"NONE"}, - } - - healthcheck, err := convertHealthcheck(source) - assert.NilError(t, err) - assert.DeepEqual(t, healthcheck, expected) -} - -func TestConvertHealthcheckDisableWithTest(t *testing.T) { - source := &composetypes.HealthCheckConfig{ - Disable: true, - Test: []string{"EXEC", "touch"}, - } - _, err := convertHealthcheck(source) - assert.Error(t, err, "test and disable can't be set") -} - -func TestConvertServiceNetworksOnlyDefault(t *testing.T) { - networkConfigs := networkMap{} - networks := map[string]*composetypes.ServiceNetworkConfig{} - - configs, err := convertServiceNetworks( - networks, networkConfigs, NewNamespace("foo"), "service") - - expected := []swarm.NetworkAttachmentConfig{ - { - Target: "foo_default", - Aliases: []string{"service"}, - }, - } - - assert.NilError(t, err) - assert.DeepEqual(t, configs, expected) -} - -func TestConvertServiceNetworks(t *testing.T) { - networkConfigs := networkMap{ - "front": composetypes.NetworkConfig{ - External: composetypes.External{ - External: true, - Name: "fronttier", - }, - }, - "back": composetypes.NetworkConfig{}, - } - networks := map[string]*composetypes.ServiceNetworkConfig{ - "front": { - Aliases: []string{"something"}, - }, - "back": { - Aliases: []string{"other"}, - }, - } - - configs, err := convertServiceNetworks( - networks, networkConfigs, NewNamespace("foo"), "service") - - expected := []swarm.NetworkAttachmentConfig{ - { - Target: "foo_back", - Aliases: []string{"other", "service"}, - }, - { - Target: "fronttier", - Aliases: []string{"something", "service"}, - }, - } - - sortedConfigs := byTargetSort(configs) - sort.Sort(&sortedConfigs) - - assert.NilError(t, err) - assert.DeepEqual(t, []swarm.NetworkAttachmentConfig(sortedConfigs), expected) -} - -type byTargetSort []swarm.NetworkAttachmentConfig - -func (s byTargetSort) Len() int { - return len(s) -} - -func (s byTargetSort) Less(i, j int) bool { - return strings.Compare(s[i].Target, s[j].Target) < 0 -} - -func (s byTargetSort) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} diff --git a/vendor/github.com/docker/docker/cli/compose/convert/volume.go b/vendor/github.com/docker/docker/cli/compose/convert/volume.go deleted file mode 100644 index 24442d4..0000000 --- a/vendor/github.com/docker/docker/cli/compose/convert/volume.go +++ /dev/null @@ -1,128 +0,0 @@ -package convert - -import ( - "fmt" - "strings" - - "github.com/docker/docker/api/types/mount" - composetypes "github.com/docker/docker/cli/compose/types" -) - -type volumes map[string]composetypes.VolumeConfig - -// Volumes from compose-file types to engine api types -func Volumes(serviceVolumes []string, stackVolumes volumes, namespace Namespace) ([]mount.Mount, error) { - var mounts []mount.Mount - - for _, volumeSpec := range serviceVolumes { - mount, err := convertVolumeToMount(volumeSpec, stackVolumes, namespace) - if err != nil { - return nil, err - } - mounts = append(mounts, mount) - } - return mounts, nil -} - -func convertVolumeToMount(volumeSpec string, stackVolumes volumes, namespace Namespace) (mount.Mount, error) { - var source, target string - var mode []string - - // TODO: split Windows path mappings properly - parts := strings.SplitN(volumeSpec, ":", 3) - - for _, part := range parts { - if strings.TrimSpace(part) == "" { - return mount.Mount{}, fmt.Errorf("invalid volume: %s", volumeSpec) - } - } - - switch len(parts) { - case 3: - source = parts[0] - target = parts[1] - mode = strings.Split(parts[2], ",") - case 2: - source = parts[0] - target = parts[1] - case 1: - target = parts[0] - } - - if source == "" { - // Anonymous volume - return mount.Mount{ - Type: mount.TypeVolume, - Target: target, - }, nil - } - - // TODO: catch Windows paths here - if strings.HasPrefix(source, "/") { - return mount.Mount{ - Type: mount.TypeBind, - Source: source, - Target: target, - ReadOnly: isReadOnly(mode), - BindOptions: getBindOptions(mode), - }, nil - } - - stackVolume, exists := stackVolumes[source] - if !exists { - return mount.Mount{}, fmt.Errorf("undefined volume: %s", source) - } - - var volumeOptions *mount.VolumeOptions - if stackVolume.External.Name != "" { - source = stackVolume.External.Name - } else { - volumeOptions = &mount.VolumeOptions{ - Labels: AddStackLabel(namespace, stackVolume.Labels), - NoCopy: isNoCopy(mode), - } - - if stackVolume.Driver != "" { - volumeOptions.DriverConfig = &mount.Driver{ - Name: stackVolume.Driver, - Options: stackVolume.DriverOpts, - } - } - source = namespace.Scope(source) - } - return mount.Mount{ - Type: mount.TypeVolume, - Source: source, - Target: target, - ReadOnly: isReadOnly(mode), - VolumeOptions: volumeOptions, - }, nil -} - -func modeHas(mode []string, field string) bool { - for _, item := range mode { - if item == field { - return true - } - } - return false -} - -func isReadOnly(mode []string) bool { - return modeHas(mode, "ro") -} - -func isNoCopy(mode []string) bool { - return modeHas(mode, "nocopy") -} - -func getBindOptions(mode []string) *mount.BindOptions { - for _, item := range mode { - for _, propagation := range mount.Propagations { - if mount.Propagation(item) == propagation { - return &mount.BindOptions{Propagation: mount.Propagation(item)} - } - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/cli/compose/convert/volume_test.go b/vendor/github.com/docker/docker/cli/compose/convert/volume_test.go deleted file mode 100644 index 113ab1e..0000000 --- a/vendor/github.com/docker/docker/cli/compose/convert/volume_test.go +++ /dev/null @@ -1,133 +0,0 @@ -package convert - -import ( - "testing" - - "github.com/docker/docker/api/types/mount" - composetypes "github.com/docker/docker/cli/compose/types" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestIsReadOnly(t *testing.T) { - assert.Equal(t, isReadOnly([]string{"foo", "bar", "ro"}), true) - assert.Equal(t, isReadOnly([]string{"ro"}), true) - assert.Equal(t, isReadOnly([]string{}), false) - assert.Equal(t, isReadOnly([]string{"foo", "rw"}), false) - assert.Equal(t, isReadOnly([]string{"foo"}), false) -} - -func TestIsNoCopy(t *testing.T) { - assert.Equal(t, isNoCopy([]string{"foo", "bar", "nocopy"}), true) - assert.Equal(t, isNoCopy([]string{"nocopy"}), true) - assert.Equal(t, isNoCopy([]string{}), false) - assert.Equal(t, isNoCopy([]string{"foo", "rw"}), false) -} - -func TestGetBindOptions(t *testing.T) { - opts := getBindOptions([]string{"slave"}) - expected := mount.BindOptions{Propagation: mount.PropagationSlave} - assert.Equal(t, *opts, expected) -} - -func TestGetBindOptionsNone(t *testing.T) { - opts := getBindOptions([]string{"ro"}) - assert.Equal(t, opts, (*mount.BindOptions)(nil)) -} - -func TestConvertVolumeToMountNamedVolume(t *testing.T) { - stackVolumes := volumes{ - "normal": composetypes.VolumeConfig{ - Driver: "glusterfs", - DriverOpts: map[string]string{ - "opt": "value", - }, - Labels: map[string]string{ - "something": "labeled", - }, - }, - } - namespace := NewNamespace("foo") - expected := mount.Mount{ - Type: mount.TypeVolume, - Source: "foo_normal", - Target: "/foo", - ReadOnly: true, - VolumeOptions: &mount.VolumeOptions{ - Labels: map[string]string{ - LabelNamespace: "foo", - "something": "labeled", - }, - DriverConfig: &mount.Driver{ - Name: "glusterfs", - Options: map[string]string{ - "opt": "value", - }, - }, - }, - } - mount, err := convertVolumeToMount("normal:/foo:ro", stackVolumes, namespace) - assert.NilError(t, err) - assert.DeepEqual(t, mount, expected) -} - -func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) { - stackVolumes := volumes{ - "outside": composetypes.VolumeConfig{ - External: composetypes.External{ - External: true, - Name: "special", - }, - }, - } - namespace := NewNamespace("foo") - expected := mount.Mount{ - Type: mount.TypeVolume, - Source: "special", - Target: "/foo", - } - mount, err := convertVolumeToMount("outside:/foo", stackVolumes, namespace) - assert.NilError(t, err) - assert.DeepEqual(t, mount, expected) -} - -func TestConvertVolumeToMountBind(t *testing.T) { - stackVolumes := volumes{} - namespace := NewNamespace("foo") - expected := mount.Mount{ - Type: mount.TypeBind, - Source: "/bar", - Target: "/foo", - ReadOnly: true, - BindOptions: &mount.BindOptions{Propagation: mount.PropagationShared}, - } - mount, err := convertVolumeToMount("/bar:/foo:ro,shared", stackVolumes, namespace) - assert.NilError(t, err) - assert.DeepEqual(t, mount, expected) -} - -func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) { - namespace := NewNamespace("foo") - _, err := convertVolumeToMount("unknown:/foo:ro", volumes{}, namespace) - assert.Error(t, err, "undefined volume: unknown") -} - -func TestConvertVolumeToMountAnonymousVolume(t *testing.T) { - stackVolumes := map[string]composetypes.VolumeConfig{} - namespace := NewNamespace("foo") - expected := mount.Mount{ - Type: mount.TypeVolume, - Target: "/foo/bar", - } - mnt, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace) - assert.NilError(t, err) - assert.DeepEqual(t, mnt, expected) -} - -func TestConvertVolumeToMountInvalidFormat(t *testing.T) { - namespace := NewNamespace("foo") - invalids := []string{"::", "::cc", ":bb:", "aa::", "aa::cc", "aa:bb:", " : : ", " : :cc", " :bb: ", "aa: : ", "aa: :cc", "aa:bb: "} - for _, vol := range invalids { - _, err := convertVolumeToMount(vol, map[string]composetypes.VolumeConfig{}, namespace) - assert.Error(t, err, "invalid volume: "+vol) - } -} diff --git a/vendor/github.com/docker/docker/cli/compose/interpolation/interpolation.go b/vendor/github.com/docker/docker/cli/compose/interpolation/interpolation.go deleted file mode 100644 index 734f28e..0000000 --- a/vendor/github.com/docker/docker/cli/compose/interpolation/interpolation.go +++ /dev/null @@ -1,90 +0,0 @@ -package interpolation - -import ( - "fmt" - - "github.com/docker/docker/cli/compose/template" - "github.com/docker/docker/cli/compose/types" -) - -// Interpolate replaces variables in a string with the values from a mapping -func Interpolate(config types.Dict, section string, mapping template.Mapping) (types.Dict, error) { - out := types.Dict{} - - for name, item := range config { - if item == nil { - out[name] = nil - continue - } - interpolatedItem, err := interpolateSectionItem(name, item.(types.Dict), section, mapping) - if err != nil { - return nil, err - } - out[name] = interpolatedItem - } - - return out, nil -} - -func interpolateSectionItem( - name string, - item types.Dict, - section string, - mapping template.Mapping, -) (types.Dict, error) { - - out := types.Dict{} - - for key, value := range item { - interpolatedValue, err := recursiveInterpolate(value, mapping) - if err != nil { - return nil, fmt.Errorf( - "Invalid interpolation format for %#v option in %s %#v: %#v", - key, section, name, err.Template, - ) - } - out[key] = interpolatedValue - } - - return out, nil - -} - -func recursiveInterpolate( - value interface{}, - mapping template.Mapping, -) (interface{}, *template.InvalidTemplateError) { - - switch value := value.(type) { - - case string: - return template.Substitute(value, mapping) - - case types.Dict: - out := types.Dict{} - for key, elem := range value { - interpolatedElem, err := recursiveInterpolate(elem, mapping) - if err != nil { - return nil, err - } - out[key] = interpolatedElem - } - return out, nil - - case []interface{}: - out := make([]interface{}, len(value)) - for i, elem := range value { - interpolatedElem, err := recursiveInterpolate(elem, mapping) - if err != nil { - return nil, err - } - out[i] = interpolatedElem - } - return out, nil - - default: - return value, nil - - } - -} diff --git a/vendor/github.com/docker/docker/cli/compose/interpolation/interpolation_test.go b/vendor/github.com/docker/docker/cli/compose/interpolation/interpolation_test.go deleted file mode 100644 index c392170..0000000 --- a/vendor/github.com/docker/docker/cli/compose/interpolation/interpolation_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package interpolation - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/docker/docker/cli/compose/types" -) - -var defaults = map[string]string{ - "USER": "jenny", - "FOO": "bar", -} - -func defaultMapping(name string) (string, bool) { - val, ok := defaults[name] - return val, ok -} - -func TestInterpolate(t *testing.T) { - services := types.Dict{ - "servicea": types.Dict{ - "image": "example:${USER}", - "volumes": []interface{}{"$FOO:/target"}, - "logging": types.Dict{ - "driver": "${FOO}", - "options": types.Dict{ - "user": "$USER", - }, - }, - }, - } - expected := types.Dict{ - "servicea": types.Dict{ - "image": "example:jenny", - "volumes": []interface{}{"bar:/target"}, - "logging": types.Dict{ - "driver": "bar", - "options": types.Dict{ - "user": "jenny", - }, - }, - }, - } - result, err := Interpolate(services, "service", defaultMapping) - assert.NoError(t, err) - assert.Equal(t, expected, result) -} - -func TestInvalidInterpolation(t *testing.T) { - services := types.Dict{ - "servicea": types.Dict{ - "image": "${", - }, - } - _, err := Interpolate(services, "service", defaultMapping) - assert.EqualError(t, err, `Invalid interpolation format for "image" option in service "servicea": "${"`) -} diff --git a/vendor/github.com/docker/docker/cli/compose/loader/example1.env b/vendor/github.com/docker/docker/cli/compose/loader/example1.env deleted file mode 100644 index 3e7a059..0000000 --- a/vendor/github.com/docker/docker/cli/compose/loader/example1.env +++ /dev/null @@ -1,8 +0,0 @@ -# passed through -FOO=1 - -# overridden in example2.env -BAR=1 - -# overridden in full-example.yml -BAZ=1 diff --git a/vendor/github.com/docker/docker/cli/compose/loader/example2.env b/vendor/github.com/docker/docker/cli/compose/loader/example2.env deleted file mode 100644 index 0920d5a..0000000 --- a/vendor/github.com/docker/docker/cli/compose/loader/example2.env +++ /dev/null @@ -1 +0,0 @@ -BAR=2 diff --git a/vendor/github.com/docker/docker/cli/compose/loader/full-example.yml b/vendor/github.com/docker/docker/cli/compose/loader/full-example.yml deleted file mode 100644 index fb5686a..0000000 --- a/vendor/github.com/docker/docker/cli/compose/loader/full-example.yml +++ /dev/null @@ -1,287 +0,0 @@ -version: "3" - -services: - foo: - cap_add: - - ALL - - cap_drop: - - NET_ADMIN - - SYS_ADMIN - - cgroup_parent: m-executor-abcd - - # String or list - command: bundle exec thin -p 3000 - # command: ["bundle", "exec", "thin", "-p", "3000"] - - container_name: my-web-container - - depends_on: - - db - - redis - - deploy: - mode: replicated - replicas: 6 - labels: [FOO=BAR] - update_config: - parallelism: 3 - delay: 10s - failure_action: continue - monitor: 60s - max_failure_ratio: 0.3 - resources: - limits: - cpus: '0.001' - memory: 50M - reservations: - cpus: '0.0001' - memory: 20M - restart_policy: - condition: on_failure - delay: 5s - max_attempts: 3 - window: 120s - placement: - constraints: [node=foo] - - devices: - - "/dev/ttyUSB0:/dev/ttyUSB0" - - # String or list - # dns: 8.8.8.8 - dns: - - 8.8.8.8 - - 9.9.9.9 - - # String or list - # dns_search: example.com - dns_search: - - dc1.example.com - - dc2.example.com - - domainname: foo.com - - # String or list - # entrypoint: /code/entrypoint.sh -p 3000 - entrypoint: ["/code/entrypoint.sh", "-p", "3000"] - - # String or list - # env_file: .env - env_file: - - ./example1.env - - ./example2.env - - # Mapping or list - # Mapping values can be strings, numbers or null - # Booleans are not allowed - must be quoted - environment: - RACK_ENV: development - SHOW: 'true' - SESSION_SECRET: - BAZ: 3 - # environment: - # - RACK_ENV=development - # - SHOW=true - # - SESSION_SECRET - - # Items can be strings or numbers - expose: - - "3000" - - 8000 - - external_links: - - redis_1 - - project_db_1:mysql - - project_db_1:postgresql - - # Mapping or list - # Mapping values must be strings - # extra_hosts: - # somehost: "162.242.195.82" - # otherhost: "50.31.209.229" - extra_hosts: - - "somehost:162.242.195.82" - - "otherhost:50.31.209.229" - - hostname: foo - - healthcheck: - test: echo "hello world" - interval: 10s - timeout: 1s - retries: 5 - - # Any valid image reference - repo, tag, id, sha - image: redis - # image: ubuntu:14.04 - # image: tutum/influxdb - # image: example-registry.com:4000/postgresql - # image: a4bc65fd - # image: busybox@sha256:38a203e1986cf79639cfb9b2e1d6e773de84002feea2d4eb006b52004ee8502d - - ipc: host - - # Mapping or list - # Mapping values can be strings, numbers or null - labels: - com.example.description: "Accounting webapp" - com.example.number: 42 - com.example.empty-label: - # labels: - # - "com.example.description=Accounting webapp" - # - "com.example.number=42" - # - "com.example.empty-label" - - links: - - db - - db:database - - redis - - logging: - driver: syslog - options: - syslog-address: "tcp://192.168.0.42:123" - - mac_address: 02:42:ac:11:65:43 - - # network_mode: "bridge" - # network_mode: "host" - # network_mode: "none" - # Use the network mode of an arbitrary container from another service - # network_mode: "service:db" - # Use the network mode of another container, specified by name or id - # network_mode: "container:some-container" - network_mode: "container:0cfeab0f748b9a743dc3da582046357c6ef497631c1a016d28d2bf9b4f899f7b" - - networks: - some-network: - aliases: - - alias1 - - alias3 - other-network: - ipv4_address: 172.16.238.10 - ipv6_address: 2001:3984:3989::10 - other-other-network: - - pid: "host" - - ports: - - 3000 - - "3000-3005" - - "8000:8000" - - "9090-9091:8080-8081" - - "49100:22" - - "127.0.0.1:8001:8001" - - "127.0.0.1:5000-5010:5000-5010" - - privileged: true - - read_only: true - - restart: always - - security_opt: - - label=level:s0:c100,c200 - - label=type:svirt_apache_t - - stdin_open: true - - stop_grace_period: 20s - - stop_signal: SIGUSR1 - - # String or list - # tmpfs: /run - tmpfs: - - /run - - /tmp - - tty: true - - ulimits: - # Single number or mapping with soft + hard limits - nproc: 65535 - nofile: - soft: 20000 - hard: 40000 - - user: someone - - volumes: - # Just specify a path and let the Engine create a volume - - /var/lib/mysql - # Specify an absolute path mapping - - /opt/data:/var/lib/mysql - # Path on the host, relative to the Compose file - - .:/code - - ./static:/var/www/html - # User-relative path - - ~/configs:/etc/configs/:ro - # Named volume - - datavolume:/var/lib/mysql - - working_dir: /code - -networks: - # Entries can be null, which specifies simply that a network - # called "{project name}_some-network" should be created and - # use the default driver - some-network: - - other-network: - driver: overlay - - driver_opts: - # Values can be strings or numbers - foo: "bar" - baz: 1 - - ipam: - driver: overlay - # driver_opts: - # # Values can be strings or numbers - # com.docker.network.enable_ipv6: "true" - # com.docker.network.numeric_value: 1 - config: - - subnet: 172.16.238.0/24 - # gateway: 172.16.238.1 - - subnet: 2001:3984:3989::/64 - # gateway: 2001:3984:3989::1 - - external-network: - # Specifies that a pre-existing network called "external-network" - # can be referred to within this file as "external-network" - external: true - - other-external-network: - # Specifies that a pre-existing network called "my-cool-network" - # can be referred to within this file as "other-external-network" - external: - name: my-cool-network - -volumes: - # Entries can be null, which specifies simply that a volume - # called "{project name}_some-volume" should be created and - # use the default driver - some-volume: - - other-volume: - driver: flocker - - driver_opts: - # Values can be strings or numbers - foo: "bar" - baz: 1 - - external-volume: - # Specifies that a pre-existing volume called "external-volume" - # can be referred to within this file as "external-volume" - external: true - - other-external-volume: - # Specifies that a pre-existing volume called "my-cool-volume" - # can be referred to within this file as "other-external-volume" - external: - name: my-cool-volume diff --git a/vendor/github.com/docker/docker/cli/compose/loader/loader.go b/vendor/github.com/docker/docker/cli/compose/loader/loader.go deleted file mode 100644 index 39f69a0..0000000 --- a/vendor/github.com/docker/docker/cli/compose/loader/loader.go +++ /dev/null @@ -1,653 +0,0 @@ -package loader - -import ( - "fmt" - "os" - "path" - "reflect" - "regexp" - "sort" - "strings" - - "github.com/docker/docker/cli/compose/interpolation" - "github.com/docker/docker/cli/compose/schema" - "github.com/docker/docker/cli/compose/types" - "github.com/docker/docker/runconfig/opts" - units "github.com/docker/go-units" - shellwords "github.com/mattn/go-shellwords" - "github.com/mitchellh/mapstructure" - yaml "gopkg.in/yaml.v2" -) - -var ( - fieldNameRegexp = regexp.MustCompile("[A-Z][a-z0-9]+") -) - -// ParseYAML reads the bytes from a file, parses the bytes into a mapping -// structure, and returns it. -func ParseYAML(source []byte) (types.Dict, error) { - var cfg interface{} - if err := yaml.Unmarshal(source, &cfg); err != nil { - return nil, err - } - cfgMap, ok := cfg.(map[interface{}]interface{}) - if !ok { - return nil, fmt.Errorf("Top-level object must be a mapping") - } - converted, err := convertToStringKeysRecursive(cfgMap, "") - if err != nil { - return nil, err - } - return converted.(types.Dict), nil -} - -// Load reads a ConfigDetails and returns a fully loaded configuration -func Load(configDetails types.ConfigDetails) (*types.Config, error) { - if len(configDetails.ConfigFiles) < 1 { - return nil, fmt.Errorf("No files specified") - } - if len(configDetails.ConfigFiles) > 1 { - return nil, fmt.Errorf("Multiple files are not yet supported") - } - - configDict := getConfigDict(configDetails) - - if services, ok := configDict["services"]; ok { - if servicesDict, ok := services.(types.Dict); ok { - forbidden := getProperties(servicesDict, types.ForbiddenProperties) - - if len(forbidden) > 0 { - return nil, &ForbiddenPropertiesError{Properties: forbidden} - } - } - } - - if err := schema.Validate(configDict, schema.Version(configDict)); err != nil { - return nil, err - } - - cfg := types.Config{} - if services, ok := configDict["services"]; ok { - servicesConfig, err := interpolation.Interpolate(services.(types.Dict), "service", os.LookupEnv) - if err != nil { - return nil, err - } - - servicesList, err := loadServices(servicesConfig, configDetails.WorkingDir) - if err != nil { - return nil, err - } - - cfg.Services = servicesList - } - - if networks, ok := configDict["networks"]; ok { - networksConfig, err := interpolation.Interpolate(networks.(types.Dict), "network", os.LookupEnv) - if err != nil { - return nil, err - } - - networksMapping, err := loadNetworks(networksConfig) - if err != nil { - return nil, err - } - - cfg.Networks = networksMapping - } - - if volumes, ok := configDict["volumes"]; ok { - volumesConfig, err := interpolation.Interpolate(volumes.(types.Dict), "volume", os.LookupEnv) - if err != nil { - return nil, err - } - - volumesMapping, err := loadVolumes(volumesConfig) - if err != nil { - return nil, err - } - - cfg.Volumes = volumesMapping - } - - if secrets, ok := configDict["secrets"]; ok { - secretsConfig, err := interpolation.Interpolate(secrets.(types.Dict), "secret", os.LookupEnv) - if err != nil { - return nil, err - } - - secretsMapping, err := loadSecrets(secretsConfig, configDetails.WorkingDir) - if err != nil { - return nil, err - } - - cfg.Secrets = secretsMapping - } - - return &cfg, nil -} - -// GetUnsupportedProperties returns the list of any unsupported properties that are -// used in the Compose files. -func GetUnsupportedProperties(configDetails types.ConfigDetails) []string { - unsupported := map[string]bool{} - - for _, service := range getServices(getConfigDict(configDetails)) { - serviceDict := service.(types.Dict) - for _, property := range types.UnsupportedProperties { - if _, isSet := serviceDict[property]; isSet { - unsupported[property] = true - } - } - } - - return sortedKeys(unsupported) -} - -func sortedKeys(set map[string]bool) []string { - var keys []string - for key := range set { - keys = append(keys, key) - } - sort.Strings(keys) - return keys -} - -// GetDeprecatedProperties returns the list of any deprecated properties that -// are used in the compose files. -func GetDeprecatedProperties(configDetails types.ConfigDetails) map[string]string { - return getProperties(getServices(getConfigDict(configDetails)), types.DeprecatedProperties) -} - -func getProperties(services types.Dict, propertyMap map[string]string) map[string]string { - output := map[string]string{} - - for _, service := range services { - if serviceDict, ok := service.(types.Dict); ok { - for property, description := range propertyMap { - if _, isSet := serviceDict[property]; isSet { - output[property] = description - } - } - } - } - - return output -} - -// ForbiddenPropertiesError is returned when there are properties in the Compose -// file that are forbidden. -type ForbiddenPropertiesError struct { - Properties map[string]string -} - -func (e *ForbiddenPropertiesError) Error() string { - return "Configuration contains forbidden properties" -} - -// TODO: resolve multiple files into a single config -func getConfigDict(configDetails types.ConfigDetails) types.Dict { - return configDetails.ConfigFiles[0].Config -} - -func getServices(configDict types.Dict) types.Dict { - if services, ok := configDict["services"]; ok { - if servicesDict, ok := services.(types.Dict); ok { - return servicesDict - } - } - - return types.Dict{} -} - -func transform(source map[string]interface{}, target interface{}) error { - data := mapstructure.Metadata{} - config := &mapstructure.DecoderConfig{ - DecodeHook: mapstructure.ComposeDecodeHookFunc( - transformHook, - mapstructure.StringToTimeDurationHookFunc()), - Result: target, - Metadata: &data, - } - decoder, err := mapstructure.NewDecoder(config) - if err != nil { - return err - } - err = decoder.Decode(source) - // TODO: log unused keys - return err -} - -func transformHook( - source reflect.Type, - target reflect.Type, - data interface{}, -) (interface{}, error) { - switch target { - case reflect.TypeOf(types.External{}): - return transformExternal(data) - case reflect.TypeOf(make(map[string]string, 0)): - return transformMapStringString(source, target, data) - case reflect.TypeOf(types.UlimitsConfig{}): - return transformUlimits(data) - case reflect.TypeOf(types.UnitBytes(0)): - return loadSize(data) - case reflect.TypeOf(types.ServiceSecretConfig{}): - return transformServiceSecret(data) - } - switch target.Kind() { - case reflect.Struct: - return transformStruct(source, target, data) - } - return data, nil -} - -// keys needs to be converted to strings for jsonschema -// TODO: don't use types.Dict -func convertToStringKeysRecursive(value interface{}, keyPrefix string) (interface{}, error) { - if mapping, ok := value.(map[interface{}]interface{}); ok { - dict := make(types.Dict) - for key, entry := range mapping { - str, ok := key.(string) - if !ok { - var location string - if keyPrefix == "" { - location = "at top level" - } else { - location = fmt.Sprintf("in %s", keyPrefix) - } - return nil, fmt.Errorf("Non-string key %s: %#v", location, key) - } - var newKeyPrefix string - if keyPrefix == "" { - newKeyPrefix = str - } else { - newKeyPrefix = fmt.Sprintf("%s.%s", keyPrefix, str) - } - convertedEntry, err := convertToStringKeysRecursive(entry, newKeyPrefix) - if err != nil { - return nil, err - } - dict[str] = convertedEntry - } - return dict, nil - } - if list, ok := value.([]interface{}); ok { - var convertedList []interface{} - for index, entry := range list { - newKeyPrefix := fmt.Sprintf("%s[%d]", keyPrefix, index) - convertedEntry, err := convertToStringKeysRecursive(entry, newKeyPrefix) - if err != nil { - return nil, err - } - convertedList = append(convertedList, convertedEntry) - } - return convertedList, nil - } - return value, nil -} - -func loadServices(servicesDict types.Dict, workingDir string) ([]types.ServiceConfig, error) { - var services []types.ServiceConfig - - for name, serviceDef := range servicesDict { - serviceConfig, err := loadService(name, serviceDef.(types.Dict), workingDir) - if err != nil { - return nil, err - } - services = append(services, *serviceConfig) - } - - return services, nil -} - -func loadService(name string, serviceDict types.Dict, workingDir string) (*types.ServiceConfig, error) { - serviceConfig := &types.ServiceConfig{} - if err := transform(serviceDict, serviceConfig); err != nil { - return nil, err - } - serviceConfig.Name = name - - if err := resolveEnvironment(serviceConfig, serviceDict, workingDir); err != nil { - return nil, err - } - - if err := resolveVolumePaths(serviceConfig.Volumes, workingDir); err != nil { - return nil, err - } - - return serviceConfig, nil -} - -func resolveEnvironment(serviceConfig *types.ServiceConfig, serviceDict types.Dict, workingDir string) error { - environment := make(map[string]string) - - if envFileVal, ok := serviceDict["env_file"]; ok { - envFiles := loadStringOrListOfStrings(envFileVal) - - var envVars []string - - for _, file := range envFiles { - filePath := absPath(workingDir, file) - fileVars, err := opts.ParseEnvFile(filePath) - if err != nil { - return err - } - envVars = append(envVars, fileVars...) - } - - for k, v := range opts.ConvertKVStringsToMap(envVars) { - environment[k] = v - } - } - - for k, v := range serviceConfig.Environment { - environment[k] = v - } - - serviceConfig.Environment = environment - - return nil -} - -func resolveVolumePaths(volumes []string, workingDir string) error { - for i, mapping := range volumes { - parts := strings.SplitN(mapping, ":", 2) - if len(parts) == 1 { - continue - } - - if strings.HasPrefix(parts[0], ".") { - parts[0] = absPath(workingDir, parts[0]) - } - parts[0] = expandUser(parts[0]) - - volumes[i] = strings.Join(parts, ":") - } - - return nil -} - -// TODO: make this more robust -func expandUser(path string) string { - if strings.HasPrefix(path, "~") { - return strings.Replace(path, "~", os.Getenv("HOME"), 1) - } - return path -} - -func transformUlimits(data interface{}) (interface{}, error) { - switch value := data.(type) { - case int: - return types.UlimitsConfig{Single: value}, nil - case types.Dict: - ulimit := types.UlimitsConfig{} - ulimit.Soft = value["soft"].(int) - ulimit.Hard = value["hard"].(int) - return ulimit, nil - default: - return data, fmt.Errorf("invalid type %T for ulimits", value) - } -} - -func loadNetworks(source types.Dict) (map[string]types.NetworkConfig, error) { - networks := make(map[string]types.NetworkConfig) - err := transform(source, &networks) - if err != nil { - return networks, err - } - for name, network := range networks { - if network.External.External && network.External.Name == "" { - network.External.Name = name - networks[name] = network - } - } - return networks, nil -} - -func loadVolumes(source types.Dict) (map[string]types.VolumeConfig, error) { - volumes := make(map[string]types.VolumeConfig) - err := transform(source, &volumes) - if err != nil { - return volumes, err - } - for name, volume := range volumes { - if volume.External.External && volume.External.Name == "" { - volume.External.Name = name - volumes[name] = volume - } - } - return volumes, nil -} - -// TODO: remove duplicate with networks/volumes -func loadSecrets(source types.Dict, workingDir string) (map[string]types.SecretConfig, error) { - secrets := make(map[string]types.SecretConfig) - if err := transform(source, &secrets); err != nil { - return secrets, err - } - for name, secret := range secrets { - if secret.External.External && secret.External.Name == "" { - secret.External.Name = name - secrets[name] = secret - } - if secret.File != "" { - secret.File = absPath(workingDir, secret.File) - } - } - return secrets, nil -} - -func absPath(workingDir string, filepath string) string { - if path.IsAbs(filepath) { - return filepath - } - return path.Join(workingDir, filepath) -} - -func transformStruct( - source reflect.Type, - target reflect.Type, - data interface{}, -) (interface{}, error) { - structValue, ok := data.(map[string]interface{}) - if !ok { - // FIXME: this is necessary because of convertToStringKeysRecursive - structValue, ok = data.(types.Dict) - if !ok { - panic(fmt.Sprintf( - "transformStruct called with non-map type: %T, %s", data, data)) - } - } - - var err error - for i := 0; i < target.NumField(); i++ { - field := target.Field(i) - fieldTag := field.Tag.Get("compose") - - yamlName := toYAMLName(field.Name) - value, ok := structValue[yamlName] - if !ok { - continue - } - - structValue[yamlName], err = convertField( - fieldTag, reflect.TypeOf(value), field.Type, value) - if err != nil { - return nil, fmt.Errorf("field %s: %s", yamlName, err.Error()) - } - } - return structValue, nil -} - -func transformMapStringString( - source reflect.Type, - target reflect.Type, - data interface{}, -) (interface{}, error) { - switch value := data.(type) { - case map[string]interface{}: - return toMapStringString(value), nil - case types.Dict: - return toMapStringString(value), nil - case map[string]string: - return value, nil - default: - return data, fmt.Errorf("invalid type %T for map[string]string", value) - } -} - -func convertField( - fieldTag string, - source reflect.Type, - target reflect.Type, - data interface{}, -) (interface{}, error) { - switch fieldTag { - case "": - return data, nil - case "healthcheck": - return loadHealthcheck(data) - case "list_or_dict_equals": - return loadMappingOrList(data, "="), nil - case "list_or_dict_colon": - return loadMappingOrList(data, ":"), nil - case "list_or_struct_map": - return loadListOrStructMap(data, target) - case "string_or_list": - return loadStringOrListOfStrings(data), nil - case "list_of_strings_or_numbers": - return loadListOfStringsOrNumbers(data), nil - case "shell_command": - return loadShellCommand(data) - case "size": - return loadSize(data) - case "-": - return nil, nil - } - return data, nil -} - -func transformExternal(data interface{}) (interface{}, error) { - switch value := data.(type) { - case bool: - return map[string]interface{}{"external": value}, nil - case types.Dict: - return map[string]interface{}{"external": true, "name": value["name"]}, nil - case map[string]interface{}: - return map[string]interface{}{"external": true, "name": value["name"]}, nil - default: - return data, fmt.Errorf("invalid type %T for external", value) - } -} - -func transformServiceSecret(data interface{}) (interface{}, error) { - switch value := data.(type) { - case string: - return map[string]interface{}{"source": value}, nil - case types.Dict: - return data, nil - case map[string]interface{}: - return data, nil - default: - return data, fmt.Errorf("invalid type %T for external", value) - } - -} - -func toYAMLName(name string) string { - nameParts := fieldNameRegexp.FindAllString(name, -1) - for i, p := range nameParts { - nameParts[i] = strings.ToLower(p) - } - return strings.Join(nameParts, "_") -} - -func loadListOrStructMap(value interface{}, target reflect.Type) (interface{}, error) { - if list, ok := value.([]interface{}); ok { - mapValue := map[interface{}]interface{}{} - for _, name := range list { - mapValue[name] = nil - } - return mapValue, nil - } - - return value, nil -} - -func loadListOfStringsOrNumbers(value interface{}) []string { - list := value.([]interface{}) - result := make([]string, len(list)) - for i, item := range list { - result[i] = fmt.Sprint(item) - } - return result -} - -func loadStringOrListOfStrings(value interface{}) []string { - if list, ok := value.([]interface{}); ok { - result := make([]string, len(list)) - for i, item := range list { - result[i] = fmt.Sprint(item) - } - return result - } - return []string{value.(string)} -} - -func loadMappingOrList(mappingOrList interface{}, sep string) map[string]string { - if mapping, ok := mappingOrList.(types.Dict); ok { - return toMapStringString(mapping) - } - if list, ok := mappingOrList.([]interface{}); ok { - result := make(map[string]string) - for _, value := range list { - parts := strings.SplitN(value.(string), sep, 2) - if len(parts) == 1 { - result[parts[0]] = "" - } else { - result[parts[0]] = parts[1] - } - } - return result - } - panic(fmt.Errorf("expected a map or a slice, got: %#v", mappingOrList)) -} - -func loadShellCommand(value interface{}) (interface{}, error) { - if str, ok := value.(string); ok { - return shellwords.Parse(str) - } - return value, nil -} - -func loadHealthcheck(value interface{}) (interface{}, error) { - if str, ok := value.(string); ok { - return append([]string{"CMD-SHELL"}, str), nil - } - return value, nil -} - -func loadSize(value interface{}) (int64, error) { - switch value := value.(type) { - case int: - return int64(value), nil - case string: - return units.RAMInBytes(value) - } - panic(fmt.Errorf("invalid type for size %T", value)) -} - -func toMapStringString(value map[string]interface{}) map[string]string { - output := make(map[string]string) - for key, value := range value { - output[key] = toString(value) - } - return output -} - -func toString(value interface{}) string { - if value == nil { - return "" - } - return fmt.Sprint(value) -} diff --git a/vendor/github.com/docker/docker/cli/compose/loader/loader_test.go b/vendor/github.com/docker/docker/cli/compose/loader/loader_test.go deleted file mode 100644 index f7fee89..0000000 --- a/vendor/github.com/docker/docker/cli/compose/loader/loader_test.go +++ /dev/null @@ -1,800 +0,0 @@ -package loader - -import ( - "fmt" - "io/ioutil" - "os" - "sort" - "testing" - "time" - - "github.com/docker/docker/cli/compose/types" - "github.com/stretchr/testify/assert" -) - -func buildConfigDetails(source types.Dict) types.ConfigDetails { - workingDir, err := os.Getwd() - if err != nil { - panic(err) - } - - return types.ConfigDetails{ - WorkingDir: workingDir, - ConfigFiles: []types.ConfigFile{ - {Filename: "filename.yml", Config: source}, - }, - Environment: nil, - } -} - -var sampleYAML = ` -version: "3" -services: - foo: - image: busybox - networks: - with_me: - bar: - image: busybox - environment: - - FOO=1 - networks: - - with_ipam -volumes: - hello: - driver: default - driver_opts: - beep: boop -networks: - default: - driver: bridge - driver_opts: - beep: boop - with_ipam: - ipam: - driver: default - config: - - subnet: 172.28.0.0/16 -` - -var sampleDict = types.Dict{ - "version": "3", - "services": types.Dict{ - "foo": types.Dict{ - "image": "busybox", - "networks": types.Dict{"with_me": nil}, - }, - "bar": types.Dict{ - "image": "busybox", - "environment": []interface{}{"FOO=1"}, - "networks": []interface{}{"with_ipam"}, - }, - }, - "volumes": types.Dict{ - "hello": types.Dict{ - "driver": "default", - "driver_opts": types.Dict{ - "beep": "boop", - }, - }, - }, - "networks": types.Dict{ - "default": types.Dict{ - "driver": "bridge", - "driver_opts": types.Dict{ - "beep": "boop", - }, - }, - "with_ipam": types.Dict{ - "ipam": types.Dict{ - "driver": "default", - "config": []interface{}{ - types.Dict{ - "subnet": "172.28.0.0/16", - }, - }, - }, - }, - }, -} - -var sampleConfig = types.Config{ - Services: []types.ServiceConfig{ - { - Name: "foo", - Image: "busybox", - Environment: map[string]string{}, - Networks: map[string]*types.ServiceNetworkConfig{ - "with_me": nil, - }, - }, - { - Name: "bar", - Image: "busybox", - Environment: map[string]string{"FOO": "1"}, - Networks: map[string]*types.ServiceNetworkConfig{ - "with_ipam": nil, - }, - }, - }, - Networks: map[string]types.NetworkConfig{ - "default": { - Driver: "bridge", - DriverOpts: map[string]string{ - "beep": "boop", - }, - }, - "with_ipam": { - Ipam: types.IPAMConfig{ - Driver: "default", - Config: []*types.IPAMPool{ - { - Subnet: "172.28.0.0/16", - }, - }, - }, - }, - }, - Volumes: map[string]types.VolumeConfig{ - "hello": { - Driver: "default", - DriverOpts: map[string]string{ - "beep": "boop", - }, - }, - }, -} - -func TestParseYAML(t *testing.T) { - dict, err := ParseYAML([]byte(sampleYAML)) - if !assert.NoError(t, err) { - return - } - assert.Equal(t, sampleDict, dict) -} - -func TestLoad(t *testing.T) { - actual, err := Load(buildConfigDetails(sampleDict)) - if !assert.NoError(t, err) { - return - } - assert.Equal(t, serviceSort(sampleConfig.Services), serviceSort(actual.Services)) - assert.Equal(t, sampleConfig.Networks, actual.Networks) - assert.Equal(t, sampleConfig.Volumes, actual.Volumes) -} - -func TestLoadV31(t *testing.T) { - actual, err := loadYAML(` -version: "3.1" -services: - foo: - image: busybox - secrets: [super] -secrets: - super: - external: true -`) - if !assert.NoError(t, err) { - return - } - assert.Equal(t, len(actual.Services), 1) - assert.Equal(t, len(actual.Secrets), 1) -} - -func TestParseAndLoad(t *testing.T) { - actual, err := loadYAML(sampleYAML) - if !assert.NoError(t, err) { - return - } - assert.Equal(t, serviceSort(sampleConfig.Services), serviceSort(actual.Services)) - assert.Equal(t, sampleConfig.Networks, actual.Networks) - assert.Equal(t, sampleConfig.Volumes, actual.Volumes) -} - -func TestInvalidTopLevelObjectType(t *testing.T) { - _, err := loadYAML("1") - assert.Error(t, err) - assert.Contains(t, err.Error(), "Top-level object must be a mapping") - - _, err = loadYAML("\"hello\"") - assert.Error(t, err) - assert.Contains(t, err.Error(), "Top-level object must be a mapping") - - _, err = loadYAML("[\"hello\"]") - assert.Error(t, err) - assert.Contains(t, err.Error(), "Top-level object must be a mapping") -} - -func TestNonStringKeys(t *testing.T) { - _, err := loadYAML(` -version: "3" -123: - foo: - image: busybox -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "Non-string key at top level: 123") - - _, err = loadYAML(` -version: "3" -services: - foo: - image: busybox - 123: - image: busybox -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "Non-string key in services: 123") - - _, err = loadYAML(` -version: "3" -services: - foo: - image: busybox -networks: - default: - ipam: - config: - - 123: oh dear -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "Non-string key in networks.default.ipam.config[0]: 123") - - _, err = loadYAML(` -version: "3" -services: - dict-env: - image: busybox - environment: - 1: FOO -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "Non-string key in services.dict-env.environment: 1") -} - -func TestSupportedVersion(t *testing.T) { - _, err := loadYAML(` -version: "3" -services: - foo: - image: busybox -`) - assert.NoError(t, err) - - _, err = loadYAML(` -version: "3.0" -services: - foo: - image: busybox -`) - assert.NoError(t, err) -} - -func TestUnsupportedVersion(t *testing.T) { - _, err := loadYAML(` -version: "2" -services: - foo: - image: busybox -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "version") - - _, err = loadYAML(` -version: "2.0" -services: - foo: - image: busybox -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "version") -} - -func TestInvalidVersion(t *testing.T) { - _, err := loadYAML(` -version: 3 -services: - foo: - image: busybox -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "version must be a string") -} - -func TestV1Unsupported(t *testing.T) { - _, err := loadYAML(` -foo: - image: busybox -`) - assert.Error(t, err) -} - -func TestNonMappingObject(t *testing.T) { - _, err := loadYAML(` -version: "3" -services: - - foo: - image: busybox -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "services must be a mapping") - - _, err = loadYAML(` -version: "3" -services: - foo: busybox -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "services.foo must be a mapping") - - _, err = loadYAML(` -version: "3" -networks: - - default: - driver: bridge -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "networks must be a mapping") - - _, err = loadYAML(` -version: "3" -networks: - default: bridge -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "networks.default must be a mapping") - - _, err = loadYAML(` -version: "3" -volumes: - - data: - driver: local -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "volumes must be a mapping") - - _, err = loadYAML(` -version: "3" -volumes: - data: local -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "volumes.data must be a mapping") -} - -func TestNonStringImage(t *testing.T) { - _, err := loadYAML(` -version: "3" -services: - foo: - image: ["busybox", "latest"] -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "services.foo.image must be a string") -} - -func TestValidEnvironment(t *testing.T) { - config, err := loadYAML(` -version: "3" -services: - dict-env: - image: busybox - environment: - FOO: "1" - BAR: 2 - BAZ: 2.5 - QUUX: - list-env: - image: busybox - environment: - - FOO=1 - - BAR=2 - - BAZ=2.5 - - QUUX= -`) - assert.NoError(t, err) - - expected := map[string]string{ - "FOO": "1", - "BAR": "2", - "BAZ": "2.5", - "QUUX": "", - } - - assert.Equal(t, 2, len(config.Services)) - - for _, service := range config.Services { - assert.Equal(t, expected, service.Environment) - } -} - -func TestInvalidEnvironmentValue(t *testing.T) { - _, err := loadYAML(` -version: "3" -services: - dict-env: - image: busybox - environment: - FOO: ["1"] -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "services.dict-env.environment.FOO must be a string, number or null") -} - -func TestInvalidEnvironmentObject(t *testing.T) { - _, err := loadYAML(` -version: "3" -services: - dict-env: - image: busybox - environment: "FOO=1" -`) - assert.Error(t, err) - assert.Contains(t, err.Error(), "services.dict-env.environment must be a mapping") -} - -func TestEnvironmentInterpolation(t *testing.T) { - config, err := loadYAML(` -version: "3" -services: - test: - image: busybox - labels: - - home1=$HOME - - home2=${HOME} - - nonexistent=$NONEXISTENT - - default=${NONEXISTENT-default} -networks: - test: - driver: $HOME -volumes: - test: - driver: $HOME -`) - - assert.NoError(t, err) - - home := os.Getenv("HOME") - - expectedLabels := map[string]string{ - "home1": home, - "home2": home, - "nonexistent": "", - "default": "default", - } - - assert.Equal(t, expectedLabels, config.Services[0].Labels) - assert.Equal(t, home, config.Networks["test"].Driver) - assert.Equal(t, home, config.Volumes["test"].Driver) -} - -func TestUnsupportedProperties(t *testing.T) { - dict, err := ParseYAML([]byte(` -version: "3" -services: - web: - image: web - build: ./web - links: - - bar - db: - image: db - build: ./db -`)) - assert.NoError(t, err) - - configDetails := buildConfigDetails(dict) - - _, err = Load(configDetails) - assert.NoError(t, err) - - unsupported := GetUnsupportedProperties(configDetails) - assert.Equal(t, []string{"build", "links"}, unsupported) -} - -func TestDeprecatedProperties(t *testing.T) { - dict, err := ParseYAML([]byte(` -version: "3" -services: - web: - image: web - container_name: web - db: - image: db - container_name: db - expose: ["5434"] -`)) - assert.NoError(t, err) - - configDetails := buildConfigDetails(dict) - - _, err = Load(configDetails) - assert.NoError(t, err) - - deprecated := GetDeprecatedProperties(configDetails) - assert.Equal(t, 2, len(deprecated)) - assert.Contains(t, deprecated, "container_name") - assert.Contains(t, deprecated, "expose") -} - -func TestForbiddenProperties(t *testing.T) { - _, err := loadYAML(` -version: "3" -services: - foo: - image: busybox - volumes: - - /data - volume_driver: some-driver - bar: - extends: - service: foo -`) - - assert.Error(t, err) - assert.IsType(t, &ForbiddenPropertiesError{}, err) - fmt.Println(err) - forbidden := err.(*ForbiddenPropertiesError).Properties - - assert.Equal(t, 2, len(forbidden)) - assert.Contains(t, forbidden, "volume_driver") - assert.Contains(t, forbidden, "extends") -} - -func durationPtr(value time.Duration) *time.Duration { - return &value -} - -func int64Ptr(value int64) *int64 { - return &value -} - -func uint64Ptr(value uint64) *uint64 { - return &value -} - -func TestFullExample(t *testing.T) { - bytes, err := ioutil.ReadFile("full-example.yml") - assert.NoError(t, err) - - config, err := loadYAML(string(bytes)) - if !assert.NoError(t, err) { - return - } - - workingDir, err := os.Getwd() - assert.NoError(t, err) - - homeDir := os.Getenv("HOME") - stopGracePeriod := time.Duration(20 * time.Second) - - expectedServiceConfig := types.ServiceConfig{ - Name: "foo", - - CapAdd: []string{"ALL"}, - CapDrop: []string{"NET_ADMIN", "SYS_ADMIN"}, - CgroupParent: "m-executor-abcd", - Command: []string{"bundle", "exec", "thin", "-p", "3000"}, - ContainerName: "my-web-container", - DependsOn: []string{"db", "redis"}, - Deploy: types.DeployConfig{ - Mode: "replicated", - Replicas: uint64Ptr(6), - Labels: map[string]string{"FOO": "BAR"}, - UpdateConfig: &types.UpdateConfig{ - Parallelism: uint64Ptr(3), - Delay: time.Duration(10 * time.Second), - FailureAction: "continue", - Monitor: time.Duration(60 * time.Second), - MaxFailureRatio: 0.3, - }, - Resources: types.Resources{ - Limits: &types.Resource{ - NanoCPUs: "0.001", - MemoryBytes: 50 * 1024 * 1024, - }, - Reservations: &types.Resource{ - NanoCPUs: "0.0001", - MemoryBytes: 20 * 1024 * 1024, - }, - }, - RestartPolicy: &types.RestartPolicy{ - Condition: "on_failure", - Delay: durationPtr(5 * time.Second), - MaxAttempts: uint64Ptr(3), - Window: durationPtr(2 * time.Minute), - }, - Placement: types.Placement{ - Constraints: []string{"node=foo"}, - }, - }, - Devices: []string{"/dev/ttyUSB0:/dev/ttyUSB0"}, - DNS: []string{"8.8.8.8", "9.9.9.9"}, - DNSSearch: []string{"dc1.example.com", "dc2.example.com"}, - DomainName: "foo.com", - Entrypoint: []string{"/code/entrypoint.sh", "-p", "3000"}, - Environment: map[string]string{ - "RACK_ENV": "development", - "SHOW": "true", - "SESSION_SECRET": "", - "FOO": "1", - "BAR": "2", - "BAZ": "3", - }, - Expose: []string{"3000", "8000"}, - ExternalLinks: []string{ - "redis_1", - "project_db_1:mysql", - "project_db_1:postgresql", - }, - ExtraHosts: map[string]string{ - "otherhost": "50.31.209.229", - "somehost": "162.242.195.82", - }, - HealthCheck: &types.HealthCheckConfig{ - Test: []string{ - "CMD-SHELL", - "echo \"hello world\"", - }, - Interval: "10s", - Timeout: "1s", - Retries: uint64Ptr(5), - }, - Hostname: "foo", - Image: "redis", - Ipc: "host", - Labels: map[string]string{ - "com.example.description": "Accounting webapp", - "com.example.number": "42", - "com.example.empty-label": "", - }, - Links: []string{ - "db", - "db:database", - "redis", - }, - Logging: &types.LoggingConfig{ - Driver: "syslog", - Options: map[string]string{ - "syslog-address": "tcp://192.168.0.42:123", - }, - }, - MacAddress: "02:42:ac:11:65:43", - NetworkMode: "container:0cfeab0f748b9a743dc3da582046357c6ef497631c1a016d28d2bf9b4f899f7b", - Networks: map[string]*types.ServiceNetworkConfig{ - "some-network": { - Aliases: []string{"alias1", "alias3"}, - Ipv4Address: "", - Ipv6Address: "", - }, - "other-network": { - Ipv4Address: "172.16.238.10", - Ipv6Address: "2001:3984:3989::10", - }, - "other-other-network": nil, - }, - Pid: "host", - Ports: []string{ - "3000", - "3000-3005", - "8000:8000", - "9090-9091:8080-8081", - "49100:22", - "127.0.0.1:8001:8001", - "127.0.0.1:5000-5010:5000-5010", - }, - Privileged: true, - ReadOnly: true, - Restart: "always", - SecurityOpt: []string{ - "label=level:s0:c100,c200", - "label=type:svirt_apache_t", - }, - StdinOpen: true, - StopSignal: "SIGUSR1", - StopGracePeriod: &stopGracePeriod, - Tmpfs: []string{"/run", "/tmp"}, - Tty: true, - Ulimits: map[string]*types.UlimitsConfig{ - "nproc": { - Single: 65535, - }, - "nofile": { - Soft: 20000, - Hard: 40000, - }, - }, - User: "someone", - Volumes: []string{ - "/var/lib/mysql", - "/opt/data:/var/lib/mysql", - fmt.Sprintf("%s:/code", workingDir), - fmt.Sprintf("%s/static:/var/www/html", workingDir), - fmt.Sprintf("%s/configs:/etc/configs/:ro", homeDir), - "datavolume:/var/lib/mysql", - }, - WorkingDir: "/code", - } - - assert.Equal(t, []types.ServiceConfig{expectedServiceConfig}, config.Services) - - expectedNetworkConfig := map[string]types.NetworkConfig{ - "some-network": {}, - - "other-network": { - Driver: "overlay", - DriverOpts: map[string]string{ - "foo": "bar", - "baz": "1", - }, - Ipam: types.IPAMConfig{ - Driver: "overlay", - Config: []*types.IPAMPool{ - {Subnet: "172.16.238.0/24"}, - {Subnet: "2001:3984:3989::/64"}, - }, - }, - }, - - "external-network": { - External: types.External{ - Name: "external-network", - External: true, - }, - }, - - "other-external-network": { - External: types.External{ - Name: "my-cool-network", - External: true, - }, - }, - } - - assert.Equal(t, expectedNetworkConfig, config.Networks) - - expectedVolumeConfig := map[string]types.VolumeConfig{ - "some-volume": {}, - "other-volume": { - Driver: "flocker", - DriverOpts: map[string]string{ - "foo": "bar", - "baz": "1", - }, - }, - "external-volume": { - External: types.External{ - Name: "external-volume", - External: true, - }, - }, - "other-external-volume": { - External: types.External{ - Name: "my-cool-volume", - External: true, - }, - }, - } - - assert.Equal(t, expectedVolumeConfig, config.Volumes) -} - -func loadYAML(yaml string) (*types.Config, error) { - dict, err := ParseYAML([]byte(yaml)) - if err != nil { - return nil, err - } - - return Load(buildConfigDetails(dict)) -} - -func serviceSort(services []types.ServiceConfig) []types.ServiceConfig { - sort.Sort(servicesByName(services)) - return services -} - -type servicesByName []types.ServiceConfig - -func (sbn servicesByName) Len() int { return len(sbn) } -func (sbn servicesByName) Swap(i, j int) { sbn[i], sbn[j] = sbn[j], sbn[i] } -func (sbn servicesByName) Less(i, j int) bool { return sbn[i].Name < sbn[j].Name } diff --git a/vendor/github.com/docker/docker/cli/compose/schema/bindata.go b/vendor/github.com/docker/docker/cli/compose/schema/bindata.go deleted file mode 100644 index 9486e91..0000000 --- a/vendor/github.com/docker/docker/cli/compose/schema/bindata.go +++ /dev/null @@ -1,260 +0,0 @@ -// Code generated by go-bindata. -// sources: -// data/config_schema_v3.0.json -// data/config_schema_v3.1.json -// DO NOT EDIT! - -package schema - -import ( - "bytes" - "compress/gzip" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - "time" -) - -func bindataRead(data []byte, name string) ([]byte, error) { - gz, err := gzip.NewReader(bytes.NewBuffer(data)) - if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) - } - - var buf bytes.Buffer - _, err = io.Copy(&buf, gz) - clErr := gz.Close() - - if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) - } - if clErr != nil { - return nil, err - } - - return buf.Bytes(), nil -} - -type asset struct { - bytes []byte - info os.FileInfo -} - -type bindataFileInfo struct { - name string - size int64 - mode os.FileMode - modTime time.Time -} - -func (fi bindataFileInfo) Name() string { - return fi.name -} -func (fi bindataFileInfo) Size() int64 { - return fi.size -} -func (fi bindataFileInfo) Mode() os.FileMode { - return fi.mode -} -func (fi bindataFileInfo) ModTime() time.Time { - return fi.modTime -} -func (fi bindataFileInfo) IsDir() bool { - return false -} -func (fi bindataFileInfo) Sys() interface{} { - return nil -} - -var _dataConfig_schema_v30Json = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xec\x5a\x4f\x8f\xdb\xb8\x0e\xbf\xe7\x53\x18\x6e\x6f\xcd\xcc\x14\x78\xc5\x03\x5e\x6f\xef\xb8\xa7\xdd\xf3\x0e\x5c\x43\xb1\x99\x44\x1d\x59\x52\x29\x39\x9d\xb4\xc8\x77\x5f\xc8\xff\x22\x2b\x92\xe5\x24\xee\xb6\x87\x9e\x66\x62\x91\x14\xff\xe9\x47\x8a\xf6\xf7\x55\x92\xa4\x6f\x55\xb1\x87\x8a\xa4\x1f\x93\x74\xaf\xb5\xfc\xf8\xf4\xf4\x59\x09\xfe\xd0\x3e\x7d\x14\xb8\x7b\x2a\x91\x6c\xf5\xc3\xfb\x0f\x4f\xed\xb3\x37\xe9\xda\xf0\xd1\xd2\xb0\x14\x82\x6f\xe9\x2e\x6f\x57\xf2\xc3\x7f\x1e\xdf\x3f\x1a\xf6\x96\x44\x1f\x25\x18\x22\xb1\xf9\x0c\x85\x6e\x9f\x21\x7c\xa9\x29\x82\x61\x7e\x4e\x0f\x80\x8a\x0a\x9e\x66\xeb\x95\x59\x93\x28\x24\xa0\xa6\xa0\xd2\x8f\x89\x51\x2e\x49\x06\x92\xfe\x81\x25\x56\x69\xa4\x7c\x97\x36\x8f\x4f\x8d\x84\x24\x49\x15\xe0\x81\x16\x96\x84\x41\xd5\x37\x4f\x67\xf9\x4f\x03\xd9\xda\x95\x6a\x29\xdb\x3c\x97\x44\x6b\x40\xfe\xd7\xa5\x6e\xcd\xf2\xa7\x67\xf2\xf0\xed\xff\x0f\x7f\xbf\x7f\xf8\xdf\x63\xfe\x90\xbd\x7b\x3b\x5a\x36\xfe\x45\xd8\xb6\xdb\x97\xb0\xa5\x9c\x6a\x2a\xf8\xb0\x7f\x3a\x50\x9e\xba\xff\x4e\xc3\xc6\xa4\x2c\x1b\x62\xc2\x46\x7b\x6f\x09\x53\x30\xb6\x99\x83\xfe\x2a\xf0\x25\x66\xf3\x40\xf6\x93\x6c\xee\xf6\xf7\xd8\x3c\x36\xe7\x20\x58\x5d\x45\x23\xd8\x53\xfd\x24\x63\xda\xed\xef\x8b\xdf\xaa\x37\x7a\x92\xb6\xa5\xb0\xf6\x6e\x14\x1c\x65\xbb\xcf\x55\xbe\x6c\x0b\xfb\x6a\x70\x56\xc0\x4b\x25\x48\x26\x8e\xe6\x59\xc0\x1f\x2d\x41\x05\x5c\xa7\x83\x0b\x92\x24\xdd\xd4\x94\x95\xae\x47\x05\x87\x3f\x8d\x88\x67\xeb\x61\x92\x7c\x77\x0f\xb6\x25\xa7\x59\x1f\xfd\x0a\x07\x7c\x58\x0f\xd8\x32\xac\x17\x82\x6b\x78\xd5\x8d\x51\xd3\x5b\xb7\x2e\x10\xc5\x0b\xe0\x96\x32\x98\xcb\x41\x70\xa7\x26\x5c\xc6\xa8\xd2\xb9\xc0\xbc\xa4\x85\x4e\x4f\x0e\xfb\x85\xbc\x78\x3e\x0d\xac\xd6\xaf\x6c\xe5\x11\x98\x16\x44\xe6\xa4\x2c\x47\x76\x10\x44\x72\x4c\xd7\x49\x4a\x35\x54\xca\x6f\x62\x92\xd6\x9c\x7e\xa9\xe1\x8f\x8e\x44\x63\x0d\xae\xdc\x12\x85\x5c\x5e\xf0\x0e\x45\x2d\x73\x49\xd0\x24\xd8\xb4\xfb\xd3\x42\x54\x15\xe1\x4b\x65\xdd\x35\x76\xcc\xf0\xbc\xe0\x9a\x50\x0e\x98\x73\x52\xc5\x12\xc9\x9c\x3a\xe0\xa5\xca\xdb\xfa\x37\x99\x46\xdb\xbc\xe5\x57\x8e\x80\xa1\x18\x2e\x1a\x8f\x92\x4f\x25\x76\x2b\xc6\xa4\xb6\xd1\x2d\x75\x18\x73\x05\x04\x8b\xfd\x8d\xfc\xa2\x22\x94\xcf\xf1\x1d\x70\x8d\x47\x29\x68\x9b\x2f\xbf\x5c\x22\x00\x3f\xe4\x03\x96\x5c\xed\x06\xe0\x07\x8a\x82\x57\xfd\x69\x98\x03\x30\x03\xc8\x1b\xfe\x57\x29\x14\xb8\x8e\x71\x0c\xb4\x97\x06\x53\x47\x3e\xe9\x39\x9e\x7b\xc3\xd7\x49\xca\xeb\x6a\x03\x68\x5a\xba\x11\xe5\x56\x60\x45\x8c\xb2\xfd\xde\xd6\xf2\xc8\xd3\x9e\xcc\xb3\x1d\x68\xdb\x60\xca\x3a\x61\x39\xa3\xfc\x65\xf9\x14\x87\x57\x8d\x24\xdf\x0b\xa5\xe7\x63\xb8\xc5\xbe\x07\xc2\xf4\xbe\xd8\x43\xf1\x32\xc1\x6e\x53\x8d\xb8\x85\xd2\x73\x92\x9c\x56\x64\x17\x27\x92\x45\x8c\x84\x91\x0d\xb0\x9b\xec\x5c\xd4\xf9\x96\x58\xb1\xdb\x19\xd2\x50\xc6\x5d\x74\x2e\xdd\x72\xac\xe6\x97\x48\x0f\x80\x73\x0b\xb8\x90\xe7\x86\xcb\x5d\x8c\x37\x20\x49\xbc\xfb\x1c\x91\x7e\x7a\x6c\x9b\xcf\x89\x53\xd5\xfc\xc7\x58\x9a\xb9\xed\x42\xe2\xd4\x7d\xdf\x13\xc7\xc2\x79\x0d\xc5\x28\x2a\x15\x29\x4c\xdf\x80\xa0\x02\x71\x3d\x93\x76\xcd\x7e\x5e\x89\x32\x94\xa0\x17\xc4\xae\x6f\x82\x48\x7d\x75\x21\x4c\x6e\xea\x1f\x67\x85\x2e\x7a\x81\x88\x58\x13\x52\x6f\xae\x9a\x67\x75\xe3\x29\xd6\xd0\x11\x46\x89\x82\xf8\x61\x0f\x3a\x72\x24\x8d\xca\xc3\x87\x99\x39\xe1\xe3\xfd\xef\x24\x6f\x80\x35\x28\x73\x7e\x8f\x1c\x11\x75\x56\xa5\x39\x6e\x3e\x45\xb2\xc8\x69\xfb\xc1\x2d\xbc\xa4\x65\x18\x2b\x1a\x84\xb0\x0f\x98\x14\xa8\x2f\x4e\xd7\xbf\x53\xee\xdb\xad\xef\xae\xf6\x12\xe9\x81\x32\xd8\xc1\xf8\xd6\xb2\x11\x82\x01\xe1\x23\xe8\x41\x20\x65\x2e\x38\x3b\xce\xa0\x54\x9a\x60\xf4\x42\xa1\xa0\xa8\x91\xea\x63\x2e\xa4\x5e\xbc\xcf\x50\xfb\x2a\x57\xf4\x1b\x8c\xa3\x79\xc6\xfb\x4e\x50\x36\xe2\x39\xaa\x42\xdf\x56\xaf\x95\x2e\x29\xcf\x85\x04\x1e\xf5\x8e\xd2\x42\xe6\x3b\x24\x05\xe4\x12\x90\x8a\xd2\x67\xe0\xda\x8e\x75\x59\x23\x31\xfb\x5f\x8a\x51\x74\xc7\x09\x8b\x39\x5a\x57\x72\x7b\xe3\xc5\x42\xeb\x78\xb8\x6b\x46\x2b\x1a\x3e\x07\x1e\x80\x9d\x51\x03\x5a\xfc\xf7\xc3\xfe\x04\xe4\x9f\x35\xa5\x5c\xc3\x0e\xd0\x87\x94\x13\x5d\xc7\x74\xd3\x31\xa3\xdb\xd8\x13\x1c\x07\x74\x42\x8f\x86\x41\x89\xad\xf6\x33\xf8\x7a\x11\xaf\x5e\xa3\xe1\x6f\x23\x6f\xdd\x29\x92\x79\xe9\xaf\x82\x73\x57\x8d\x2c\x88\xa8\x27\x2f\xa2\xd6\x2a\xda\x18\x36\x34\x5c\x4d\x35\x35\x03\xa9\x35\xc5\x5c\x14\x2f\x4c\xa3\x64\x0e\x41\x49\xfd\xda\xae\x1c\xcb\xae\x98\x23\x3b\x77\x96\x5e\x80\x6f\xa2\x68\x93\x46\x27\xb0\xd3\xd3\xcd\x8e\x28\x38\x79\xa4\x8a\x6c\x9c\x99\x9b\xef\x70\x9b\x6c\xc4\x43\x1c\x63\x10\x34\x52\x27\x2e\x1d\xda\x8e\xf0\x04\xd4\xaf\x39\x38\xd0\xb4\x02\x51\xfb\x6b\xd6\xca\xce\xef\x8e\x29\xb5\x26\xb3\x91\xa0\x5a\x94\x6e\x4c\x9f\x87\xa0\xf6\xfd\x45\x34\x70\x73\x0e\x09\x82\x64\xb4\x20\x2a\x06\x44\x77\x5c\x50\x6b\x59\x12\x0d\x79\xfb\xa2\xea\x2a\xe8\x9f\xc0\x7c\x49\x90\x30\x06\x8c\xaa\x6a\x0e\x86\xa6\x25\x30\x72\xbc\xa9\x7c\x36\xec\x5b\x42\x59\x8d\x90\x93\x42\x77\xef\xc2\x22\x39\x97\x56\x82\x53\x2d\xbc\x08\x31\x6f\xcb\x8a\xbc\xe6\xfd\xb6\x0d\x89\xf7\xc0\x04\xdb\xba\xb9\x77\x4b\x2b\x13\x94\xa8\xb1\xb8\x70\xf6\xcd\x21\x3a\xd7\xfa\x40\xc6\xf4\x3b\x5e\x98\x8e\xa0\x0c\x92\x0c\x57\xff\x28\x7f\xb4\xb4\x74\x7d\x66\x2e\x05\xa3\xc5\x71\x29\x0b\x0b\xc1\x5b\x27\xcf\x49\x88\x3b\x33\xd0\xa4\x83\x69\x85\x2a\xa9\xa3\x87\xb5\x61\xf8\x4a\x79\x29\xbe\x5e\xb1\xe1\x72\xa9\x24\x19\x29\xc0\xc1\xbb\x7b\x1d\xad\x34\x12\xca\xf5\xd5\xe5\xfc\x5e\xb3\xee\xa8\xe6\x43\x7e\x46\x50\x7f\xa0\x8b\xbf\x49\x0d\x20\x7d\x21\xeb\xe8\x3c\xa8\x82\x4a\xa0\x37\x01\x17\x78\xf3\x1d\x33\xb1\x27\x5b\xa0\xaa\xcd\x1a\x20\x76\x54\xe6\xbe\xb8\xf8\x6d\x23\x3e\x24\xcc\xe2\x80\x44\x25\xa9\x96\x3a\x1d\xb3\x47\xaa\xa9\xb7\x06\x27\xd3\xa3\x88\x24\x3c\x8e\x88\x69\x1d\xd7\xbd\xa3\x50\xf5\x86\xc3\x64\x47\x65\xf9\xd3\xf7\x9e\x77\xfe\x35\xe5\x14\xbe\x94\xdc\x07\x7a\xfd\xdb\x90\x40\x54\x9f\x87\x9e\x79\x3d\xf8\x2a\x9b\x1d\xe2\xe0\xab\x88\xe5\xf4\xbf\xb2\xc1\xbb\x03\x33\xba\x2f\x37\x22\x90\xd1\x51\xfd\x46\x8c\xdf\xf9\x75\x65\x7e\x39\x43\x2a\x2b\xcf\x2e\xef\x8f\x53\x29\x31\x7b\x3a\xdf\x71\x64\x63\x35\x5c\x32\xcf\x07\x74\x63\xb4\x9d\x1a\x4a\xf4\x24\x81\x69\xad\xb3\x69\xe7\xc4\x69\xcb\x17\xcc\xf0\xc7\x77\x13\x35\x65\xea\x2d\xda\x0f\x02\xe3\x05\x06\x3e\xfe\x98\x3a\x8d\x68\xef\xdd\xcb\xaf\xc0\x02\xa0\x66\xf1\x5f\x7c\x13\x66\xec\xe4\xc7\x8b\xf9\xc6\xf7\xf1\xd0\xae\xfd\x9e\x2b\x1b\xf9\xc7\x21\x69\xdf\x49\x5b\x90\x92\xd9\xbd\x79\x28\x8c\xde\x2f\xc5\xdc\x91\x61\xff\xc5\x56\xe6\x87\xab\x95\xfd\xb7\xf9\xba\x6e\x75\x5a\xfd\x13\x00\x00\xff\xff\x46\xf7\x7b\x23\xe5\x2a\x00\x00") - -func dataConfig_schema_v30JsonBytes() ([]byte, error) { - return bindataRead( - _dataConfig_schema_v30Json, - "data/config_schema_v3.0.json", - ) -} - -func dataConfig_schema_v30Json() (*asset, error) { - bytes, err := dataConfig_schema_v30JsonBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "data/config_schema_v3.0.json", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -var _dataConfig_schema_v31Json = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xec\x1a\xcb\x8e\xdb\x36\xf0\xee\xaf\x10\x94\xdc\xe2\xdd\x4d\xd1\xa0\x40\x73\xeb\xb1\xa7\xf6\xdc\x85\x23\xd0\xd2\x58\x66\x96\x22\x19\x92\x72\xd6\x09\xfc\xef\x05\xf5\x32\x45\x91\x22\x6d\x2b\xd9\x45\xd1\xd3\xae\xc5\x99\xe1\xbc\x67\x38\xe4\xf7\x55\x92\xa4\x6f\x65\xbe\x87\x0a\xa5\x1f\x93\x74\xaf\x14\xff\xf8\xf0\xf0\x59\x32\x7a\xd7\x7e\xbd\x67\xa2\x7c\x28\x04\xda\xa9\xbb\xf7\x1f\x1e\xda\x6f\x6f\xd2\xb5\xc6\xc3\x85\x46\xc9\x19\xdd\xe1\x32\x6b\x57\xb2\xc3\xaf\xf7\xbf\xdc\x6b\xf4\x16\x44\x1d\x39\x68\x20\xb6\xfd\x0c\xb9\x6a\xbf\x09\xf8\x52\x63\x01\x1a\xf9\x31\x3d\x80\x90\x98\xd1\x74\xb3\x5e\xe9\x35\x2e\x18\x07\xa1\x30\xc8\xf4\x63\xa2\x99\x4b\x92\x01\xa4\xff\x60\x90\x95\x4a\x60\x5a\xa6\xcd\xe7\x53\x43\x21\x49\x52\x09\xe2\x80\x73\x83\xc2\xc0\xea\x9b\x87\x33\xfd\x87\x01\x6c\x6d\x53\x35\x98\x6d\xbe\x73\xa4\x14\x08\xfa\xf7\x94\xb7\x66\xf9\xd3\x23\xba\xfb\xf6\xc7\xdd\x3f\xef\xef\x7e\xbf\xcf\xee\x36\xef\xde\x8e\x96\xb5\x7e\x05\xec\xda\xed\x0b\xd8\x61\x8a\x15\x66\x74\xd8\x3f\x1d\x20\x4f\xdd\x7f\xa7\x61\x63\x54\x14\x0d\x30\x22\xa3\xbd\x77\x88\x48\x18\xcb\x4c\x41\x7d\x65\xe2\x29\x24\xf3\x00\xf6\x42\x32\x77\xfb\x3b\x64\x1e\x8b\x73\x60\xa4\xae\x82\x16\xec\xa1\x5e\x48\x98\x76\xfb\x65\xec\x27\x21\x17\xa0\xc2\x2e\xdb\x42\xbd\x98\xc7\xea\xed\x6f\x13\x78\xd5\x0b\x3d\x0b\xdb\x42\x18\x7b\x37\x0c\x8e\xc2\xdb\xa5\x2a\x57\x78\xf9\x75\x35\x28\xcb\xa3\xa5\x02\x38\x61\x47\xfd\xcd\xa3\x8f\x16\xa0\x02\xaa\xd2\x41\x05\x49\x92\x6e\x6b\x4c\x0a\x5b\xa3\x8c\xc2\x5f\x9a\xc4\xa3\xf1\x31\x49\xbe\xdb\x99\xcc\xa0\xd3\xac\x8f\x7e\xf9\x0d\x3e\xac\x7b\x64\x19\xd6\x73\x46\x15\x3c\xab\x46\xa8\xf9\xad\x5b\x15\xb0\xfc\x09\xc4\x0e\x13\x88\xc5\x40\xa2\x94\x33\x2a\x23\x58\xaa\x8c\x89\xac\xc0\xb9\x4a\x4f\x16\xfa\x84\x5e\xd8\x9f\x06\x54\xe3\xd7\x66\xe5\x20\x98\xe6\x88\x67\xa8\x28\x46\x72\x20\x21\xd0\x31\x5d\x27\x29\x56\x50\x49\xb7\x88\x49\x5a\x53\xfc\xa5\x86\x3f\x3b\x10\x25\x6a\xb0\xe9\x16\x82\xf1\xe5\x09\x97\x82\xd5\x3c\xe3\x48\x68\x07\x9b\x57\x7f\x9a\xb3\xaa\x42\x74\x29\xaf\xbb\x44\x8e\x08\xcd\x33\xaa\x10\xa6\x20\x32\x8a\xaa\x90\x23\xe9\xa8\x03\x5a\xc8\xac\x2d\xf8\xb3\x6e\xb4\xcb\x5a\x7c\x69\x11\x18\xaa\xff\xa2\xf6\x28\xe8\x9c\x63\xb7\x64\xb4\x6b\x6b\xde\x52\x0b\x31\x93\x80\x44\xbe\xbf\x12\x9f\x55\x08\xd3\x18\xdd\x01\x55\xe2\xc8\x19\x6e\xfd\xe5\xd5\x39\x02\xd0\x43\x36\xe4\x92\x8b\xd5\x00\xf4\x80\x05\xa3\x55\x1f\x0d\x31\x09\x66\x48\xf2\x1a\xff\x99\x33\x09\xb6\x62\x2c\x01\xcd\xa5\x41\xd4\x91\x4e\x7a\x8c\xc7\x5e\xf0\x75\x92\xd2\xba\xda\x82\xd0\x3d\xec\x08\x72\xc7\x44\x85\x34\xb3\xfd\xde\xc6\xf2\x48\xd3\x0e\xcf\x33\x15\x68\xca\xa0\xcb\x3a\x22\x19\xc1\xf4\x69\x79\x17\x87\x67\x25\x50\xb6\x67\x52\xc5\xe7\x70\x03\x7d\x0f\x88\xa8\x7d\xbe\x87\xfc\x69\x06\xdd\x84\x1a\x61\x33\xa9\x62\x9c\x1c\x57\xa8\x0c\x03\xf1\x3c\x04\x42\xd0\x16\xc8\x55\x72\x2e\xaa\x7c\x83\x2c\x2b\x4b\x0d\xea\xf3\xb8\x49\xe7\xd2\x2d\x87\x6a\x7e\x21\xf0\x01\x44\x6c\x01\x67\xfc\xdc\x70\xd9\x8b\xe1\x06\x24\x09\x77\x9f\x23\xd0\x4f\xf7\x6d\xf3\x39\x13\x55\xcd\x7f\x84\xa4\x1b\xbb\x5d\x48\xac\xba\xef\xfa\x62\x49\x18\xd7\x50\x8c\xac\x52\xa1\x5c\xf7\x0d\x02\xa4\xc7\xae\x67\xd0\xee\x74\x93\x55\xac\xf0\x39\xe8\x04\xd8\xd6\x8d\x37\x53\x5f\x5c\x08\x93\xab\xfa\xc7\x28\xd3\x05\x0f\x10\x01\x69\x7c\xec\xc5\xb2\x79\x66\x37\xec\x62\x0d\x1c\x22\x18\x49\x08\x07\xbb\x57\x91\x23\x6a\x98\x1f\x3e\x44\xfa\x84\x0b\xf7\xb7\x59\x5c\x0f\xaa\x97\x66\x7c\x8f\x1c\x20\x75\x66\xa5\x09\x37\x17\x23\x9b\x40\xb4\xfd\xe0\x16\x9e\xe3\xc2\x9f\x2b\x9a\x0c\x61\x06\x18\x67\x42\x4d\xa2\xeb\xe7\x94\xfb\x76\xeb\x9b\xab\x3d\x17\xf8\x80\x09\x94\x30\x3e\xb5\x6c\x19\x23\x80\xe8\x28\xf5\x08\x40\x45\xc6\x28\x39\x46\x40\x4a\x85\x44\xf0\x40\x21\x21\xaf\x05\x56\xc7\x8c\x71\xb5\x78\x9f\x21\xf7\x55\x26\xf1\x37\x18\x5b\xf3\x9c\xef\x3b\x42\x1b\x8b\x21\x6b\x42\x72\xa5\x41\x7d\x29\x29\x1c\xc6\x8e\x44\x18\x4c\x54\xe1\x14\x95\x4a\x56\x8b\x3c\xf6\x80\xad\xf7\x44\xa2\x84\xd8\x23\xbc\x76\xb7\x71\xd8\xcc\x03\x97\x97\x00\x4f\x0a\x5d\x67\xc2\x50\x55\xb6\x7f\x9b\x79\xe5\xe4\x0c\x7d\x79\x94\xb9\xba\xae\x5b\x93\xaa\xc0\x34\x63\x1c\x68\x30\x36\xa4\x62\x3c\x2b\x05\xca\x21\xe3\x20\x30\x73\xaa\x62\x6d\x46\x7a\x51\x0b\xa4\xf7\x9f\x92\x91\xb8\xa4\x88\x84\xc2\x4c\x55\x7c\x77\xe5\xb1\x52\xa9\x70\xb0\xd7\x04\x57\xd8\x1f\x34\x0e\xaf\x8d\xe8\x00\xda\xea\xef\x2e\xfa\x33\x05\xff\xcc\x29\xa6\x0a\x4a\xed\x26\x53\xa7\x9a\xe9\x39\xe7\x5b\xce\x88\x5e\x73\x8f\xc4\xd8\xa0\x33\x7c\x24\x6d\x60\xee\x94\x1b\xc1\xd5\x89\x3a\xf9\x1a\xdd\x75\x34\xf4\xd6\x1d\x23\x1b\x27\xfc\x45\xc5\xdc\x66\x63\xe3\xad\xa7\xee\xa0\xaa\x65\xf0\x58\xd0\xc0\x50\x39\xd7\xd2\x0e\xa0\xc6\xd0\x7e\xd1\x6a\xa1\xdb\x64\x1d\x04\x05\x76\x73\xbb\xb2\x24\xbb\x60\xec\x6e\x9d\x58\x7b\x02\xae\x79\xb2\x09\x1a\x9c\xbf\xcf\xcf\xb6\x3b\x20\xef\xdc\x19\x4b\xb4\xb5\x26\xae\xae\xe0\xd6\xde\x28\x0e\xe1\x1c\x23\x40\x09\x6c\xd9\xa5\x4f\xd4\x66\x3e\x01\xf9\x3a\xc7\x46\x0a\x57\xc0\x6a\x77\xc1\x5b\x99\xfe\xdd\x21\xa5\xc6\x5c\x3e\x60\x54\x03\xd2\xb6\xe9\xe3\x60\xd4\xbe\xbb\x0c\x1a\x2e\x26\x48\x04\x70\x82\x73\x24\x43\x89\xe8\x86\xf1\x44\xcd\x0b\xa4\x20\x6b\xef\x65\x2f\x4a\xfd\x33\x39\x9f\x23\x81\x08\x01\x82\x65\x15\x93\x43\xd3\x02\x08\x3a\x5e\x55\x3e\x1b\xf4\x1d\xc2\xa4\x16\x90\xa1\x5c\x75\x57\xbf\x01\x9f\x4b\x2b\x46\xb1\x62\xce\x0c\x11\xb7\x65\x85\x9e\xb3\x7e\xdb\x06\x24\xd4\xd9\x8c\x9b\xfa\xd8\xc9\x82\xe1\x09\x6d\xe3\x77\x59\x75\x9e\x31\xd1\xb9\xd6\x7b\x3c\xa6\xdf\x71\x22\xba\x00\xa9\x33\xc9\x30\xf8\x09\xe2\x07\x4b\x4b\x77\xca\xc8\x38\x23\x38\x3f\x2e\x25\x61\xce\x68\xab\xe4\x18\x87\xb8\xd1\x03\xb5\x3b\xe8\x56\xa8\xe2\x2a\x18\xac\x0d\xc2\x57\x4c\x0b\xf6\xf5\x82\x0d\x97\x73\x25\x4e\x50\x0e\x56\xbe\xbb\x55\xd1\x52\x09\x84\xa9\xba\xb8\x9c\xdf\x2a\xd6\x0d\xd5\x7c\xf0\xcf\x40\xd6\x1f\xe0\xc2\xf7\xe8\x9e\x4c\x9f\xf3\x3a\x38\x0d\xac\xa0\x62\xc2\xe9\x80\x0b\x3c\xf4\x08\x89\xd8\x83\x2d\x50\xd5\xa2\xc6\xc7\x1d\x54\xc6\xf8\xf2\xa7\x8d\xf0\x88\x78\x13\x4e\x48\x98\xa3\x6a\xa9\xe8\x88\x1e\xa8\xa7\xce\x1a\x9c\xcc\xcf\x2d\x12\xff\xec\x22\xc4\x75\x98\xf7\x0e\x42\xd6\x5b\xea\x19\x21\x4c\x4f\x19\xae\x5b\xfe\xf8\x63\xca\xc9\x7f\x28\xb9\x2d\xe9\xf5\x77\x61\x1e\xab\x3e\x0e\x3d\xf3\x7a\xd0\xd5\x26\xda\xc4\xde\x8b\xa8\xe5\xf8\x6f\xda\x77\x7b\x44\xe0\xea\xf3\x2f\xec\x04\x6f\x48\x2e\xdd\x8b\xa6\x40\x6e\xe9\xa0\xfe\x4f\x2d\xff\x11\x47\xfc\x79\xfe\xd5\x3d\x20\x0b\xbe\xdc\x6a\xa0\xae\x2e\xce\x11\xcf\x95\x5e\x81\xcd\x5e\xda\x14\xe3\xc1\xa2\x61\x92\xe9\x99\x7f\x4e\x93\xd1\xf7\x69\x1d\xc6\x66\xcc\x86\x0d\xe6\x78\xe3\x3b\xae\x90\x73\x83\xa4\x1e\xc4\x73\xbf\x62\x6d\xda\x29\x71\x5e\xf2\x05\x93\xcd\xfd\xbb\x99\x3e\x60\xee\xde\xfb\x07\x15\xd0\x05\x86\x74\x6e\x9b\x5a\x87\x87\x5e\xbb\xd3\x77\x9b\x9e\xf8\x37\xf0\x27\xaf\x38\xb5\x9c\xf4\x38\x99\x49\x7d\x1f\x0f\x5a\xdb\x17\x98\x9b\x91\x7e\x2c\x90\xf6\x15\x89\x91\xdd\x37\xe6\x79\xca\x67\x46\xe7\xdb\x4e\x7b\xcc\xdb\xbf\xb1\xf4\xdc\x6a\xac\xcc\xbf\xcd\x7b\xd8\xd5\x69\xf5\x6f\x00\x00\x00\xff\xff\xfc\xf3\x11\x6a\x88\x2f\x00\x00") - -func dataConfig_schema_v31JsonBytes() ([]byte, error) { - return bindataRead( - _dataConfig_schema_v31Json, - "data/config_schema_v3.1.json", - ) -} - -func dataConfig_schema_v31Json() (*asset, error) { - bytes, err := dataConfig_schema_v31JsonBytes() - if err != nil { - return nil, err - } - - info := bindataFileInfo{name: "data/config_schema_v3.1.json", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} - a := &asset{bytes: bytes, info: info} - return a, nil -} - -// Asset loads and returns the asset for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) - } - return a.bytes, nil - } - return nil, fmt.Errorf("Asset %s not found", name) -} - -// MustAsset is like Asset but panics when Asset would return an error. -// It simplifies safe initialization of global variables. -func MustAsset(name string) []byte { - a, err := Asset(name) - if err != nil { - panic("asset: Asset(" + name + "): " + err.Error()) - } - - return a -} - -// AssetInfo loads and returns the asset info for the given name. -// It returns an error if the asset could not be found or -// could not be loaded. -func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - a, err := f() - if err != nil { - return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) - } - return a.info, nil - } - return nil, fmt.Errorf("AssetInfo %s not found", name) -} - -// AssetNames returns the names of the assets. -func AssetNames() []string { - names := make([]string, 0, len(_bindata)) - for name := range _bindata { - names = append(names, name) - } - return names -} - -// _bindata is a table, holding each asset generator, mapped to its name. -var _bindata = map[string]func() (*asset, error){ - "data/config_schema_v3.0.json": dataConfig_schema_v30Json, - "data/config_schema_v3.1.json": dataConfig_schema_v31Json, -} - -// AssetDir returns the file names below a certain -// directory embedded in the file by go-bindata. -// For example if you run go-bindata on data/... and data contains the -// following hierarchy: -// data/ -// foo.txt -// img/ -// a.png -// b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error -// AssetDir("") will return []string{"data"}. -func AssetDir(name string) ([]string, error) { - node := _bintree - if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") - for _, p := range pathList { - node = node.Children[p] - if node == nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - } - } - if node.Func != nil { - return nil, fmt.Errorf("Asset %s not found", name) - } - rv := make([]string, 0, len(node.Children)) - for childName := range node.Children { - rv = append(rv, childName) - } - return rv, nil -} - -type bintree struct { - Func func() (*asset, error) - Children map[string]*bintree -} -var _bintree = &bintree{nil, map[string]*bintree{ - "data": &bintree{nil, map[string]*bintree{ - "config_schema_v3.0.json": &bintree{dataConfig_schema_v30Json, map[string]*bintree{}}, - "config_schema_v3.1.json": &bintree{dataConfig_schema_v31Json, map[string]*bintree{}}, - }}, -}} - -// RestoreAsset restores an asset under the given directory -func RestoreAsset(dir, name string) error { - data, err := Asset(name) - if err != nil { - return err - } - info, err := AssetInfo(name) - if err != nil { - return err - } - err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) - if err != nil { - return err - } - err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) - if err != nil { - return err - } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil -} - -// RestoreAssets restores an asset under the given directory recursively -func RestoreAssets(dir, name string) error { - children, err := AssetDir(name) - // File - if err != nil { - return RestoreAsset(dir, name) - } - // Dir - for _, child := range children { - err = RestoreAssets(dir, filepath.Join(name, child)) - if err != nil { - return err - } - } - return nil -} - -func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) -} - diff --git a/vendor/github.com/docker/docker/cli/compose/schema/data/config_schema_v3.0.json b/vendor/github.com/docker/docker/cli/compose/schema/data/config_schema_v3.0.json deleted file mode 100644 index fbcd8bb..0000000 --- a/vendor/github.com/docker/docker/cli/compose/schema/data/config_schema_v3.0.json +++ /dev/null @@ -1,383 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "config_schema_v3.0.json", - "type": "object", - "required": ["version"], - - "properties": { - "version": { - "type": "string" - }, - - "services": { - "id": "#/properties/services", - "type": "object", - "patternProperties": { - "^[a-zA-Z0-9._-]+$": { - "$ref": "#/definitions/service" - } - }, - "additionalProperties": false - }, - - "networks": { - "id": "#/properties/networks", - "type": "object", - "patternProperties": { - "^[a-zA-Z0-9._-]+$": { - "$ref": "#/definitions/network" - } - } - }, - - "volumes": { - "id": "#/properties/volumes", - "type": "object", - "patternProperties": { - "^[a-zA-Z0-9._-]+$": { - "$ref": "#/definitions/volume" - } - }, - "additionalProperties": false - } - }, - - "additionalProperties": false, - - "definitions": { - - "service": { - "id": "#/definitions/service", - "type": "object", - - "properties": { - "deploy": {"$ref": "#/definitions/deployment"}, - "build": { - "oneOf": [ - {"type": "string"}, - { - "type": "object", - "properties": { - "context": {"type": "string"}, - "dockerfile": {"type": "string"}, - "args": {"$ref": "#/definitions/list_or_dict"} - }, - "additionalProperties": false - } - ] - }, - "cap_add": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "cgroup_parent": {"type": "string"}, - "command": { - "oneOf": [ - {"type": "string"}, - {"type": "array", "items": {"type": "string"}} - ] - }, - "container_name": {"type": "string"}, - "depends_on": {"$ref": "#/definitions/list_of_strings"}, - "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "dns": {"$ref": "#/definitions/string_or_list"}, - "dns_search": {"$ref": "#/definitions/string_or_list"}, - "domainname": {"type": "string"}, - "entrypoint": { - "oneOf": [ - {"type": "string"}, - {"type": "array", "items": {"type": "string"}} - ] - }, - "env_file": {"$ref": "#/definitions/string_or_list"}, - "environment": {"$ref": "#/definitions/list_or_dict"}, - - "expose": { - "type": "array", - "items": { - "type": ["string", "number"], - "format": "expose" - }, - "uniqueItems": true - }, - - "external_links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "extra_hosts": {"$ref": "#/definitions/list_or_dict"}, - "healthcheck": {"$ref": "#/definitions/healthcheck"}, - "hostname": {"type": "string"}, - "image": {"type": "string"}, - "ipc": {"type": "string"}, - "labels": {"$ref": "#/definitions/list_or_dict"}, - "links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - - "logging": { - "type": "object", - - "properties": { - "driver": {"type": "string"}, - "options": { - "type": "object", - "patternProperties": { - "^.+$": {"type": ["string", "number", "null"]} - } - } - }, - "additionalProperties": false - }, - - "mac_address": {"type": "string"}, - "network_mode": {"type": "string"}, - - "networks": { - "oneOf": [ - {"$ref": "#/definitions/list_of_strings"}, - { - "type": "object", - "patternProperties": { - "^[a-zA-Z0-9._-]+$": { - "oneOf": [ - { - "type": "object", - "properties": { - "aliases": {"$ref": "#/definitions/list_of_strings"}, - "ipv4_address": {"type": "string"}, - "ipv6_address": {"type": "string"} - }, - "additionalProperties": false - }, - {"type": "null"} - ] - } - }, - "additionalProperties": false - } - ] - }, - "pid": {"type": ["string", "null"]}, - - "ports": { - "type": "array", - "items": { - "type": ["string", "number"], - "format": "ports" - }, - "uniqueItems": true - }, - - "privileged": {"type": "boolean"}, - "read_only": {"type": "boolean"}, - "restart": {"type": "string"}, - "security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "shm_size": {"type": ["number", "string"]}, - "sysctls": {"$ref": "#/definitions/list_or_dict"}, - "stdin_open": {"type": "boolean"}, - "stop_grace_period": {"type": "string", "format": "duration"}, - "stop_signal": {"type": "string"}, - "tmpfs": {"$ref": "#/definitions/string_or_list"}, - "tty": {"type": "boolean"}, - "ulimits": { - "type": "object", - "patternProperties": { - "^[a-z]+$": { - "oneOf": [ - {"type": "integer"}, - { - "type":"object", - "properties": { - "hard": {"type": "integer"}, - "soft": {"type": "integer"} - }, - "required": ["soft", "hard"], - "additionalProperties": false - } - ] - } - } - }, - "user": {"type": "string"}, - "userns_mode": {"type": "string"}, - "volumes": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "working_dir": {"type": "string"} - }, - "additionalProperties": false - }, - - "healthcheck": { - "id": "#/definitions/healthcheck", - "type": "object", - "additionalProperties": false, - "properties": { - "disable": {"type": "boolean"}, - "interval": {"type": "string"}, - "retries": {"type": "number"}, - "test": { - "oneOf": [ - {"type": "string"}, - {"type": "array", "items": {"type": "string"}} - ] - }, - "timeout": {"type": "string"} - } - }, - "deployment": { - "id": "#/definitions/deployment", - "type": ["object", "null"], - "properties": { - "mode": {"type": "string"}, - "replicas": {"type": "integer"}, - "labels": {"$ref": "#/definitions/list_or_dict"}, - "update_config": { - "type": "object", - "properties": { - "parallelism": {"type": "integer"}, - "delay": {"type": "string", "format": "duration"}, - "failure_action": {"type": "string"}, - "monitor": {"type": "string", "format": "duration"}, - "max_failure_ratio": {"type": "number"} - }, - "additionalProperties": false - }, - "resources": { - "type": "object", - "properties": { - "limits": {"$ref": "#/definitions/resource"}, - "reservations": {"$ref": "#/definitions/resource"} - } - }, - "restart_policy": { - "type": "object", - "properties": { - "condition": {"type": "string"}, - "delay": {"type": "string", "format": "duration"}, - "max_attempts": {"type": "integer"}, - "window": {"type": "string", "format": "duration"} - }, - "additionalProperties": false - }, - "placement": { - "type": "object", - "properties": { - "constraints": {"type": "array", "items": {"type": "string"}} - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - - "resource": { - "id": "#/definitions/resource", - "type": "object", - "properties": { - "cpus": {"type": "string"}, - "memory": {"type": "string"} - }, - "additionalProperties": false - }, - - "network": { - "id": "#/definitions/network", - "type": ["object", "null"], - "properties": { - "driver": {"type": "string"}, - "driver_opts": { - "type": "object", - "patternProperties": { - "^.+$": {"type": ["string", "number"]} - } - }, - "ipam": { - "type": "object", - "properties": { - "driver": {"type": "string"}, - "config": { - "type": "array", - "items": { - "type": "object", - "properties": { - "subnet": {"type": "string"} - }, - "additionalProperties": false - } - } - }, - "additionalProperties": false - }, - "external": { - "type": ["boolean", "object"], - "properties": { - "name": {"type": "string"} - }, - "additionalProperties": false - }, - "internal": {"type": "boolean"}, - "labels": {"$ref": "#/definitions/list_or_dict"} - }, - "additionalProperties": false - }, - - "volume": { - "id": "#/definitions/volume", - "type": ["object", "null"], - "properties": { - "driver": {"type": "string"}, - "driver_opts": { - "type": "object", - "patternProperties": { - "^.+$": {"type": ["string", "number"]} - } - }, - "external": { - "type": ["boolean", "object"], - "properties": { - "name": {"type": "string"} - }, - "additionalProperties": false - }, - "labels": {"$ref": "#/definitions/list_or_dict"} - }, - "additionalProperties": false - }, - - "string_or_list": { - "oneOf": [ - {"type": "string"}, - {"$ref": "#/definitions/list_of_strings"} - ] - }, - - "list_of_strings": { - "type": "array", - "items": {"type": "string"}, - "uniqueItems": true - }, - - "list_or_dict": { - "oneOf": [ - { - "type": "object", - "patternProperties": { - ".+": { - "type": ["string", "number", "null"] - } - }, - "additionalProperties": false - }, - {"type": "array", "items": {"type": "string"}, "uniqueItems": true} - ] - }, - - "constraints": { - "service": { - "id": "#/definitions/constraints/service", - "anyOf": [ - {"required": ["build"]}, - {"required": ["image"]} - ], - "properties": { - "build": { - "required": ["context"] - } - } - } - } - } -} diff --git a/vendor/github.com/docker/docker/cli/compose/schema/data/config_schema_v3.1.json b/vendor/github.com/docker/docker/cli/compose/schema/data/config_schema_v3.1.json deleted file mode 100644 index b703748..0000000 --- a/vendor/github.com/docker/docker/cli/compose/schema/data/config_schema_v3.1.json +++ /dev/null @@ -1,428 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "config_schema_v3.1.json", - "type": "object", - "required": ["version"], - - "properties": { - "version": { - "type": "string" - }, - - "services": { - "id": "#/properties/services", - "type": "object", - "patternProperties": { - "^[a-zA-Z0-9._-]+$": { - "$ref": "#/definitions/service" - } - }, - "additionalProperties": false - }, - - "networks": { - "id": "#/properties/networks", - "type": "object", - "patternProperties": { - "^[a-zA-Z0-9._-]+$": { - "$ref": "#/definitions/network" - } - } - }, - - "volumes": { - "id": "#/properties/volumes", - "type": "object", - "patternProperties": { - "^[a-zA-Z0-9._-]+$": { - "$ref": "#/definitions/volume" - } - }, - "additionalProperties": false - }, - - "secrets": { - "id": "#/properties/secrets", - "type": "object", - "patternProperties": { - "^[a-zA-Z0-9._-]+$": { - "$ref": "#/definitions/secret" - } - }, - "additionalProperties": false - } - }, - - "additionalProperties": false, - - "definitions": { - - "service": { - "id": "#/definitions/service", - "type": "object", - - "properties": { - "deploy": {"$ref": "#/definitions/deployment"}, - "build": { - "oneOf": [ - {"type": "string"}, - { - "type": "object", - "properties": { - "context": {"type": "string"}, - "dockerfile": {"type": "string"}, - "args": {"$ref": "#/definitions/list_or_dict"} - }, - "additionalProperties": false - } - ] - }, - "cap_add": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "cgroup_parent": {"type": "string"}, - "command": { - "oneOf": [ - {"type": "string"}, - {"type": "array", "items": {"type": "string"}} - ] - }, - "container_name": {"type": "string"}, - "depends_on": {"$ref": "#/definitions/list_of_strings"}, - "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "dns": {"$ref": "#/definitions/string_or_list"}, - "dns_search": {"$ref": "#/definitions/string_or_list"}, - "domainname": {"type": "string"}, - "entrypoint": { - "oneOf": [ - {"type": "string"}, - {"type": "array", "items": {"type": "string"}} - ] - }, - "env_file": {"$ref": "#/definitions/string_or_list"}, - "environment": {"$ref": "#/definitions/list_or_dict"}, - - "expose": { - "type": "array", - "items": { - "type": ["string", "number"], - "format": "expose" - }, - "uniqueItems": true - }, - - "external_links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "extra_hosts": {"$ref": "#/definitions/list_or_dict"}, - "healthcheck": {"$ref": "#/definitions/healthcheck"}, - "hostname": {"type": "string"}, - "image": {"type": "string"}, - "ipc": {"type": "string"}, - "labels": {"$ref": "#/definitions/list_or_dict"}, - "links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - - "logging": { - "type": "object", - - "properties": { - "driver": {"type": "string"}, - "options": { - "type": "object", - "patternProperties": { - "^.+$": {"type": ["string", "number", "null"]} - } - } - }, - "additionalProperties": false - }, - - "mac_address": {"type": "string"}, - "network_mode": {"type": "string"}, - - "networks": { - "oneOf": [ - {"$ref": "#/definitions/list_of_strings"}, - { - "type": "object", - "patternProperties": { - "^[a-zA-Z0-9._-]+$": { - "oneOf": [ - { - "type": "object", - "properties": { - "aliases": {"$ref": "#/definitions/list_of_strings"}, - "ipv4_address": {"type": "string"}, - "ipv6_address": {"type": "string"} - }, - "additionalProperties": false - }, - {"type": "null"} - ] - } - }, - "additionalProperties": false - } - ] - }, - "pid": {"type": ["string", "null"]}, - - "ports": { - "type": "array", - "items": { - "type": ["string", "number"], - "format": "ports" - }, - "uniqueItems": true - }, - - "privileged": {"type": "boolean"}, - "read_only": {"type": "boolean"}, - "restart": {"type": "string"}, - "security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "shm_size": {"type": ["number", "string"]}, - "secrets": { - "type": "array", - "items": { - "oneOf": [ - {"type": "string"}, - { - "type": "object", - "properties": { - "source": {"type": "string"}, - "target": {"type": "string"}, - "uid": {"type": "string"}, - "gid": {"type": "string"}, - "mode": {"type": "number"} - } - } - ] - } - }, - "sysctls": {"$ref": "#/definitions/list_or_dict"}, - "stdin_open": {"type": "boolean"}, - "stop_grace_period": {"type": "string", "format": "duration"}, - "stop_signal": {"type": "string"}, - "tmpfs": {"$ref": "#/definitions/string_or_list"}, - "tty": {"type": "boolean"}, - "ulimits": { - "type": "object", - "patternProperties": { - "^[a-z]+$": { - "oneOf": [ - {"type": "integer"}, - { - "type":"object", - "properties": { - "hard": {"type": "integer"}, - "soft": {"type": "integer"} - }, - "required": ["soft", "hard"], - "additionalProperties": false - } - ] - } - } - }, - "user": {"type": "string"}, - "userns_mode": {"type": "string"}, - "volumes": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, - "working_dir": {"type": "string"} - }, - "additionalProperties": false - }, - - "healthcheck": { - "id": "#/definitions/healthcheck", - "type": "object", - "additionalProperties": false, - "properties": { - "disable": {"type": "boolean"}, - "interval": {"type": "string"}, - "retries": {"type": "number"}, - "test": { - "oneOf": [ - {"type": "string"}, - {"type": "array", "items": {"type": "string"}} - ] - }, - "timeout": {"type": "string"} - } - }, - "deployment": { - "id": "#/definitions/deployment", - "type": ["object", "null"], - "properties": { - "mode": {"type": "string"}, - "replicas": {"type": "integer"}, - "labels": {"$ref": "#/definitions/list_or_dict"}, - "update_config": { - "type": "object", - "properties": { - "parallelism": {"type": "integer"}, - "delay": {"type": "string", "format": "duration"}, - "failure_action": {"type": "string"}, - "monitor": {"type": "string", "format": "duration"}, - "max_failure_ratio": {"type": "number"} - }, - "additionalProperties": false - }, - "resources": { - "type": "object", - "properties": { - "limits": {"$ref": "#/definitions/resource"}, - "reservations": {"$ref": "#/definitions/resource"} - } - }, - "restart_policy": { - "type": "object", - "properties": { - "condition": {"type": "string"}, - "delay": {"type": "string", "format": "duration"}, - "max_attempts": {"type": "integer"}, - "window": {"type": "string", "format": "duration"} - }, - "additionalProperties": false - }, - "placement": { - "type": "object", - "properties": { - "constraints": {"type": "array", "items": {"type": "string"}} - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - - "resource": { - "id": "#/definitions/resource", - "type": "object", - "properties": { - "cpus": {"type": "string"}, - "memory": {"type": "string"} - }, - "additionalProperties": false - }, - - "network": { - "id": "#/definitions/network", - "type": ["object", "null"], - "properties": { - "driver": {"type": "string"}, - "driver_opts": { - "type": "object", - "patternProperties": { - "^.+$": {"type": ["string", "number"]} - } - }, - "ipam": { - "type": "object", - "properties": { - "driver": {"type": "string"}, - "config": { - "type": "array", - "items": { - "type": "object", - "properties": { - "subnet": {"type": "string"} - }, - "additionalProperties": false - } - } - }, - "additionalProperties": false - }, - "external": { - "type": ["boolean", "object"], - "properties": { - "name": {"type": "string"} - }, - "additionalProperties": false - }, - "internal": {"type": "boolean"}, - "labels": {"$ref": "#/definitions/list_or_dict"} - }, - "additionalProperties": false - }, - - "volume": { - "id": "#/definitions/volume", - "type": ["object", "null"], - "properties": { - "driver": {"type": "string"}, - "driver_opts": { - "type": "object", - "patternProperties": { - "^.+$": {"type": ["string", "number"]} - } - }, - "external": { - "type": ["boolean", "object"], - "properties": { - "name": {"type": "string"} - }, - "additionalProperties": false - }, - "labels": {"$ref": "#/definitions/list_or_dict"} - }, - "additionalProperties": false - }, - - "secret": { - "id": "#/definitions/secret", - "type": "object", - "properties": { - "file": {"type": "string"}, - "external": { - "type": ["boolean", "object"], - "properties": { - "name": {"type": "string"} - } - }, - "labels": {"$ref": "#/definitions/list_or_dict"} - }, - "additionalProperties": false - }, - - "string_or_list": { - "oneOf": [ - {"type": "string"}, - {"$ref": "#/definitions/list_of_strings"} - ] - }, - - "list_of_strings": { - "type": "array", - "items": {"type": "string"}, - "uniqueItems": true - }, - - "list_or_dict": { - "oneOf": [ - { - "type": "object", - "patternProperties": { - ".+": { - "type": ["string", "number", "null"] - } - }, - "additionalProperties": false - }, - {"type": "array", "items": {"type": "string"}, "uniqueItems": true} - ] - }, - - "constraints": { - "service": { - "id": "#/definitions/constraints/service", - "anyOf": [ - {"required": ["build"]}, - {"required": ["image"]} - ], - "properties": { - "build": { - "required": ["context"] - } - } - } - } - } -} diff --git a/vendor/github.com/docker/docker/cli/compose/schema/schema.go b/vendor/github.com/docker/docker/cli/compose/schema/schema.go deleted file mode 100644 index ae33c77..0000000 --- a/vendor/github.com/docker/docker/cli/compose/schema/schema.go +++ /dev/null @@ -1,137 +0,0 @@ -package schema - -//go:generate go-bindata -pkg schema -nometadata data - -import ( - "fmt" - "strings" - "time" - - "github.com/pkg/errors" - "github.com/xeipuuv/gojsonschema" -) - -const ( - defaultVersion = "1.0" - versionField = "version" -) - -type portsFormatChecker struct{} - -func (checker portsFormatChecker) IsFormat(input string) bool { - // TODO: implement this - return true -} - -type durationFormatChecker struct{} - -func (checker durationFormatChecker) IsFormat(input string) bool { - _, err := time.ParseDuration(input) - return err == nil -} - -func init() { - gojsonschema.FormatCheckers.Add("expose", portsFormatChecker{}) - gojsonschema.FormatCheckers.Add("ports", portsFormatChecker{}) - gojsonschema.FormatCheckers.Add("duration", durationFormatChecker{}) -} - -// Version returns the version of the config, defaulting to version 1.0 -func Version(config map[string]interface{}) string { - version, ok := config[versionField] - if !ok { - return defaultVersion - } - return normalizeVersion(fmt.Sprintf("%v", version)) -} - -func normalizeVersion(version string) string { - switch version { - case "3": - return "3.0" - default: - return version - } -} - -// Validate uses the jsonschema to validate the configuration -func Validate(config map[string]interface{}, version string) error { - schemaData, err := Asset(fmt.Sprintf("data/config_schema_v%s.json", version)) - if err != nil { - return errors.Errorf("unsupported Compose file version: %s", version) - } - - schemaLoader := gojsonschema.NewStringLoader(string(schemaData)) - dataLoader := gojsonschema.NewGoLoader(config) - - result, err := gojsonschema.Validate(schemaLoader, dataLoader) - if err != nil { - return err - } - - if !result.Valid() { - return toError(result) - } - - return nil -} - -func toError(result *gojsonschema.Result) error { - err := getMostSpecificError(result.Errors()) - description := getDescription(err) - return fmt.Errorf("%s %s", err.Field(), description) -} - -func getDescription(err gojsonschema.ResultError) string { - if err.Type() == "invalid_type" { - if expectedType, ok := err.Details()["expected"].(string); ok { - return fmt.Sprintf("must be a %s", humanReadableType(expectedType)) - } - } - - return err.Description() -} - -func humanReadableType(definition string) string { - if definition[0:1] == "[" { - allTypes := strings.Split(definition[1:len(definition)-1], ",") - for i, t := range allTypes { - allTypes[i] = humanReadableType(t) - } - return fmt.Sprintf( - "%s or %s", - strings.Join(allTypes[0:len(allTypes)-1], ", "), - allTypes[len(allTypes)-1], - ) - } - if definition == "object" { - return "mapping" - } - if definition == "array" { - return "list" - } - return definition -} - -func getMostSpecificError(errors []gojsonschema.ResultError) gojsonschema.ResultError { - var mostSpecificError gojsonschema.ResultError - - for _, err := range errors { - if mostSpecificError == nil { - mostSpecificError = err - } else if specificity(err) > specificity(mostSpecificError) { - mostSpecificError = err - } else if specificity(err) == specificity(mostSpecificError) { - // Invalid type errors win in a tie-breaker for most specific field name - if err.Type() == "invalid_type" && mostSpecificError.Type() != "invalid_type" { - mostSpecificError = err - } - } - } - - return mostSpecificError -} - -func specificity(err gojsonschema.ResultError) int { - return len(strings.Split(err.Field(), ".")) -} diff --git a/vendor/github.com/docker/docker/cli/compose/schema/schema_test.go b/vendor/github.com/docker/docker/cli/compose/schema/schema_test.go deleted file mode 100644 index 0935d40..0000000 --- a/vendor/github.com/docker/docker/cli/compose/schema/schema_test.go +++ /dev/null @@ -1,52 +0,0 @@ -package schema - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -type dict map[string]interface{} - -func TestValidate(t *testing.T) { - config := dict{ - "version": "3.0", - "services": dict{ - "foo": dict{ - "image": "busybox", - }, - }, - } - - assert.NoError(t, Validate(config, "3.0")) -} - -func TestValidateUndefinedTopLevelOption(t *testing.T) { - config := dict{ - "version": "3.0", - "helicopters": dict{ - "foo": dict{ - "image": "busybox", - }, - }, - } - - err := Validate(config, "3.0") - assert.Error(t, err) - assert.Contains(t, err.Error(), "Additional property helicopters is not allowed") -} - -func TestValidateInvalidVersion(t *testing.T) { - config := dict{ - "version": "2.1", - "services": dict{ - "foo": dict{ - "image": "busybox", - }, - }, - } - - err := Validate(config, "2.1") - assert.Error(t, err) - assert.Contains(t, err.Error(), "unsupported Compose file version: 2.1") -} diff --git a/vendor/github.com/docker/docker/cli/compose/template/template.go b/vendor/github.com/docker/docker/cli/compose/template/template.go deleted file mode 100644 index 28495ba..0000000 --- a/vendor/github.com/docker/docker/cli/compose/template/template.go +++ /dev/null @@ -1,100 +0,0 @@ -package template - -import ( - "fmt" - "regexp" - "strings" -) - -var delimiter = "\\$" -var substitution = "[_a-z][_a-z0-9]*(?::?-[^}]+)?" - -var patternString = fmt.Sprintf( - "%s(?i:(?P%s)|(?P%s)|{(?P%s)}|(?P))", - delimiter, delimiter, substitution, substitution, -) - -var pattern = regexp.MustCompile(patternString) - -// InvalidTemplateError is returned when a variable template is not in a valid -// format -type InvalidTemplateError struct { - Template string -} - -func (e InvalidTemplateError) Error() string { - return fmt.Sprintf("Invalid template: %#v", e.Template) -} - -// Mapping is a user-supplied function which maps from variable names to values. -// Returns the value as a string and a bool indicating whether -// the value is present, to distinguish between an empty string -// and the absence of a value. -type Mapping func(string) (string, bool) - -// Substitute variables in the string with their values -func Substitute(template string, mapping Mapping) (result string, err *InvalidTemplateError) { - result = pattern.ReplaceAllStringFunc(template, func(substring string) string { - matches := pattern.FindStringSubmatch(substring) - groups := make(map[string]string) - for i, name := range pattern.SubexpNames() { - if i != 0 { - groups[name] = matches[i] - } - } - - substitution := groups["named"] - if substitution == "" { - substitution = groups["braced"] - } - if substitution != "" { - // Soft default (fall back if unset or empty) - if strings.Contains(substitution, ":-") { - name, defaultValue := partition(substitution, ":-") - value, ok := mapping(name) - if !ok || value == "" { - return defaultValue - } - return value - } - - // Hard default (fall back if-and-only-if empty) - if strings.Contains(substitution, "-") { - name, defaultValue := partition(substitution, "-") - value, ok := mapping(name) - if !ok { - return defaultValue - } - return value - } - - // No default (fall back to empty string) - value, ok := mapping(substitution) - if !ok { - return "" - } - return value - } - - if escaped := groups["escaped"]; escaped != "" { - return escaped - } - - err = &InvalidTemplateError{Template: template} - return "" - }) - - return result, err -} - -// Split the string at the first occurrence of sep, and return the part before the separator, -// and the part after the separator. -// -// If the separator is not found, return the string itself, followed by an empty string. -func partition(s, sep string) (string, string) { - if strings.Contains(s, sep) { - parts := strings.SplitN(s, sep, 2) - return parts[0], parts[1] - } - return s, "" -} diff --git a/vendor/github.com/docker/docker/cli/compose/template/template_test.go b/vendor/github.com/docker/docker/cli/compose/template/template_test.go deleted file mode 100644 index 6b81bf0..0000000 --- a/vendor/github.com/docker/docker/cli/compose/template/template_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package template - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -var defaults = map[string]string{ - "FOO": "first", - "BAR": "", -} - -func defaultMapping(name string) (string, bool) { - val, ok := defaults[name] - return val, ok -} - -func TestEscaped(t *testing.T) { - result, err := Substitute("$${foo}", defaultMapping) - assert.NoError(t, err) - assert.Equal(t, "${foo}", result) -} - -func TestInvalid(t *testing.T) { - invalidTemplates := []string{ - "${", - "$}", - "${}", - "${ }", - "${ foo}", - "${foo }", - "${foo!}", - } - - for _, template := range invalidTemplates { - _, err := Substitute(template, defaultMapping) - assert.Error(t, err) - assert.IsType(t, &InvalidTemplateError{}, err) - } -} - -func TestNoValueNoDefault(t *testing.T) { - for _, template := range []string{"This ${missing} var", "This ${BAR} var"} { - result, err := Substitute(template, defaultMapping) - assert.NoError(t, err) - assert.Equal(t, "This var", result) - } -} - -func TestValueNoDefault(t *testing.T) { - for _, template := range []string{"This $FOO var", "This ${FOO} var"} { - result, err := Substitute(template, defaultMapping) - assert.NoError(t, err) - assert.Equal(t, "This first var", result) - } -} - -func TestNoValueWithDefault(t *testing.T) { - for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} { - result, err := Substitute(template, defaultMapping) - assert.NoError(t, err) - assert.Equal(t, "ok def", result) - } -} - -func TestEmptyValueWithSoftDefault(t *testing.T) { - result, err := Substitute("ok ${BAR:-def}", defaultMapping) - assert.NoError(t, err) - assert.Equal(t, "ok def", result) -} - -func TestEmptyValueWithHardDefault(t *testing.T) { - result, err := Substitute("ok ${BAR-def}", defaultMapping) - assert.NoError(t, err) - assert.Equal(t, "ok ", result) -} - -func TestNonAlphanumericDefault(t *testing.T) { - result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping) - assert.NoError(t, err) - assert.Equal(t, "ok /non:-alphanumeric", result) -} diff --git a/vendor/github.com/docker/docker/cli/compose/types/types.go b/vendor/github.com/docker/docker/cli/compose/types/types.go deleted file mode 100644 index cae7b4a..0000000 --- a/vendor/github.com/docker/docker/cli/compose/types/types.go +++ /dev/null @@ -1,253 +0,0 @@ -package types - -import ( - "time" -) - -// UnsupportedProperties not yet supported by this implementation of the compose file -var UnsupportedProperties = []string{ - "build", - "cap_add", - "cap_drop", - "cgroup_parent", - "devices", - "dns", - "dns_search", - "domainname", - "external_links", - "ipc", - "links", - "mac_address", - "network_mode", - "privileged", - "read_only", - "restart", - "security_opt", - "shm_size", - "stop_signal", - "sysctls", - "tmpfs", - "userns_mode", -} - -// DeprecatedProperties that were removed from the v3 format, but their -// use should not impact the behaviour of the application. -var DeprecatedProperties = map[string]string{ - "container_name": "Setting the container name is not supported.", - "expose": "Exposing ports is unnecessary - services on the same network can access each other's containers on any port.", -} - -// ForbiddenProperties that are not supported in this implementation of the -// compose file. -var ForbiddenProperties = map[string]string{ - "extends": "Support for `extends` is not implemented yet. Use `docker-compose config` to generate a configuration with all `extends` options resolved, and deploy from that.", - "volume_driver": "Instead of setting the volume driver on the service, define a volume using the top-level `volumes` option and specify the driver there.", - "volumes_from": "To share a volume between services, define it using the top-level `volumes` option and reference it from each service that shares it using the service-level `volumes` option.", - "cpu_quota": "Set resource limits using deploy.resources", - "cpu_shares": "Set resource limits using deploy.resources", - "cpuset": "Set resource limits using deploy.resources", - "mem_limit": "Set resource limits using deploy.resources", - "memswap_limit": "Set resource limits using deploy.resources", -} - -// Dict is a mapping of strings to interface{} -type Dict map[string]interface{} - -// ConfigFile is a filename and the contents of the file as a Dict -type ConfigFile struct { - Filename string - Config Dict -} - -// ConfigDetails are the details about a group of ConfigFiles -type ConfigDetails struct { - WorkingDir string - ConfigFiles []ConfigFile - Environment map[string]string -} - -// Config is a full compose file configuration -type Config struct { - Services []ServiceConfig - Networks map[string]NetworkConfig - Volumes map[string]VolumeConfig - Secrets map[string]SecretConfig -} - -// ServiceConfig is the configuration of one service -type ServiceConfig struct { - Name string - - CapAdd []string `mapstructure:"cap_add"` - CapDrop []string `mapstructure:"cap_drop"` - CgroupParent string `mapstructure:"cgroup_parent"` - Command []string `compose:"shell_command"` - ContainerName string `mapstructure:"container_name"` - DependsOn []string `mapstructure:"depends_on"` - Deploy DeployConfig - Devices []string - DNS []string `compose:"string_or_list"` - DNSSearch []string `mapstructure:"dns_search" compose:"string_or_list"` - DomainName string `mapstructure:"domainname"` - Entrypoint []string `compose:"shell_command"` - Environment map[string]string `compose:"list_or_dict_equals"` - Expose []string `compose:"list_of_strings_or_numbers"` - ExternalLinks []string `mapstructure:"external_links"` - ExtraHosts map[string]string `mapstructure:"extra_hosts" compose:"list_or_dict_colon"` - Hostname string - HealthCheck *HealthCheckConfig - Image string - Ipc string - Labels map[string]string `compose:"list_or_dict_equals"` - Links []string - Logging *LoggingConfig - MacAddress string `mapstructure:"mac_address"` - NetworkMode string `mapstructure:"network_mode"` - Networks map[string]*ServiceNetworkConfig `compose:"list_or_struct_map"` - Pid string - Ports []string `compose:"list_of_strings_or_numbers"` - Privileged bool - ReadOnly bool `mapstructure:"read_only"` - Restart string - Secrets []ServiceSecretConfig - SecurityOpt []string `mapstructure:"security_opt"` - StdinOpen bool `mapstructure:"stdin_open"` - StopGracePeriod *time.Duration `mapstructure:"stop_grace_period"` - StopSignal string `mapstructure:"stop_signal"` - Tmpfs []string `compose:"string_or_list"` - Tty bool `mapstructure:"tty"` - Ulimits map[string]*UlimitsConfig - User string - Volumes []string - WorkingDir string `mapstructure:"working_dir"` -} - -// LoggingConfig the logging configuration for a service -type LoggingConfig struct { - Driver string - Options map[string]string -} - -// DeployConfig the deployment configuration for a service -type DeployConfig struct { - Mode string - Replicas *uint64 - Labels map[string]string `compose:"list_or_dict_equals"` - UpdateConfig *UpdateConfig `mapstructure:"update_config"` - Resources Resources - RestartPolicy *RestartPolicy `mapstructure:"restart_policy"` - Placement Placement -} - -// HealthCheckConfig the healthcheck configuration for a service -type HealthCheckConfig struct { - Test []string `compose:"healthcheck"` - Timeout string - Interval string - Retries *uint64 - Disable bool -} - -// UpdateConfig the service update configuration -type UpdateConfig struct { - Parallelism *uint64 - Delay time.Duration - FailureAction string `mapstructure:"failure_action"` - Monitor time.Duration - MaxFailureRatio float32 `mapstructure:"max_failure_ratio"` -} - -// Resources the resource limits and reservations -type Resources struct { - Limits *Resource - Reservations *Resource -} - -// Resource is a resource to be limited or reserved -type Resource struct { - // TODO: types to convert from units and ratios - NanoCPUs string `mapstructure:"cpus"` - MemoryBytes UnitBytes `mapstructure:"memory"` -} - -// UnitBytes is the bytes type -type UnitBytes int64 - -// RestartPolicy the service restart policy -type RestartPolicy struct { - Condition string - Delay *time.Duration - MaxAttempts *uint64 `mapstructure:"max_attempts"` - Window *time.Duration -} - -// Placement constraints for the service -type Placement struct { - Constraints []string -} - -// ServiceNetworkConfig is the network configuration for a service -type ServiceNetworkConfig struct { - Aliases []string - Ipv4Address string `mapstructure:"ipv4_address"` - Ipv6Address string `mapstructure:"ipv6_address"` -} - -// ServiceSecretConfig is the secret configuration for a service -type ServiceSecretConfig struct { - Source string - Target string - UID string - GID string - Mode uint32 -} - -// UlimitsConfig the ulimit configuration -type UlimitsConfig struct { - Single int - Soft int - Hard int -} - -// NetworkConfig for a network -type NetworkConfig struct { - Driver string - DriverOpts map[string]string `mapstructure:"driver_opts"` - Ipam IPAMConfig - External External - Internal bool - Labels map[string]string `compose:"list_or_dict_equals"` -} - -// IPAMConfig for a network -type IPAMConfig struct { - Driver string - Config []*IPAMPool -} - -// IPAMPool for a network -type IPAMPool struct { - Subnet string -} - -// VolumeConfig for a volume -type VolumeConfig struct { - Driver string - DriverOpts map[string]string `mapstructure:"driver_opts"` - External External - Labels map[string]string `compose:"list_or_dict_equals"` -} - -// External identifies a Volume or Network as a reference to a resource that is -// not managed, and should already exist. -type External struct { - Name string - External bool -} - -// SecretConfig for a secret -type SecretConfig struct { - File string - External External - Labels map[string]string `compose:"list_or_dict_equals"` -} diff --git a/vendor/github.com/docker/docker/cli/error.go b/vendor/github.com/docker/docker/cli/error.go deleted file mode 100644 index 62f6243..0000000 --- a/vendor/github.com/docker/docker/cli/error.go +++ /dev/null @@ -1,33 +0,0 @@ -package cli - -import ( - "fmt" - "strings" -) - -// Errors is a list of errors. -// Useful in a loop if you don't want to return the error right away and you want to display after the loop, -// all the errors that happened during the loop. -type Errors []error - -func (errList Errors) Error() string { - if len(errList) < 1 { - return "" - } - - out := make([]string, len(errList)) - for i := range errList { - out[i] = errList[i].Error() - } - return strings.Join(out, ", ") -} - -// StatusError reports an unsuccessful exit by a command. -type StatusError struct { - Status string - StatusCode int -} - -func (e StatusError) Error() string { - return fmt.Sprintf("Status: %s, Code: %d", e.Status, e.StatusCode) -} diff --git a/vendor/github.com/docker/docker/cli/flags/client.go b/vendor/github.com/docker/docker/cli/flags/client.go deleted file mode 100644 index 9b6940f..0000000 --- a/vendor/github.com/docker/docker/cli/flags/client.go +++ /dev/null @@ -1,13 +0,0 @@ -package flags - -// ClientOptions are the options used to configure the client cli -type ClientOptions struct { - Common *CommonOptions - ConfigDir string - Version bool -} - -// NewClientOptions returns a new ClientOptions -func NewClientOptions() *ClientOptions { - return &ClientOptions{Common: NewCommonOptions()} -} diff --git a/vendor/github.com/docker/docker/cli/flags/common.go b/vendor/github.com/docker/docker/cli/flags/common.go deleted file mode 100644 index e2f9da0..0000000 --- a/vendor/github.com/docker/docker/cli/flags/common.go +++ /dev/null @@ -1,120 +0,0 @@ -package flags - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/opts" - "github.com/docker/go-connections/tlsconfig" - "github.com/spf13/pflag" -) - -const ( - // DefaultTrustKeyFile is the default filename for the trust key - DefaultTrustKeyFile = "key.json" - // DefaultCaFile is the default filename for the CA pem file - DefaultCaFile = "ca.pem" - // DefaultKeyFile is the default filename for the key pem file - DefaultKeyFile = "key.pem" - // DefaultCertFile is the default filename for the cert pem file - DefaultCertFile = "cert.pem" - // FlagTLSVerify is the flag name for the tls verification option - FlagTLSVerify = "tlsverify" -) - -var ( - dockerCertPath = os.Getenv("DOCKER_CERT_PATH") - dockerTLSVerify = os.Getenv("DOCKER_TLS_VERIFY") != "" -) - -// CommonOptions are options common to both the client and the daemon. -type CommonOptions struct { - Debug bool - Hosts []string - LogLevel string - TLS bool - TLSVerify bool - TLSOptions *tlsconfig.Options - TrustKey string -} - -// NewCommonOptions returns a new CommonOptions -func NewCommonOptions() *CommonOptions { - return &CommonOptions{} -} - -// InstallFlags adds flags for the common options on the FlagSet -func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) { - if dockerCertPath == "" { - dockerCertPath = cliconfig.ConfigDir() - } - - flags.BoolVarP(&commonOpts.Debug, "debug", "D", false, "Enable debug mode") - flags.StringVarP(&commonOpts.LogLevel, "log-level", "l", "info", "Set the logging level (\"debug\", \"info\", \"warn\", \"error\", \"fatal\")") - flags.BoolVar(&commonOpts.TLS, "tls", false, "Use TLS; implied by --tlsverify") - flags.BoolVar(&commonOpts.TLSVerify, FlagTLSVerify, dockerTLSVerify, "Use TLS and verify the remote") - - // TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file") - - commonOpts.TLSOptions = &tlsconfig.Options{ - CAFile: filepath.Join(dockerCertPath, DefaultCaFile), - CertFile: filepath.Join(dockerCertPath, DefaultCertFile), - KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile), - } - tlsOptions := commonOpts.TLSOptions - flags.Var(opts.NewQuotedString(&tlsOptions.CAFile), "tlscacert", "Trust certs signed only by this CA") - flags.Var(opts.NewQuotedString(&tlsOptions.CertFile), "tlscert", "Path to TLS certificate file") - flags.Var(opts.NewQuotedString(&tlsOptions.KeyFile), "tlskey", "Path to TLS key file") - - hostOpt := opts.NewNamedListOptsRef("hosts", &commonOpts.Hosts, opts.ValidateHost) - flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to") -} - -// SetDefaultOptions sets default values for options after flag parsing is -// complete -func (commonOpts *CommonOptions) SetDefaultOptions(flags *pflag.FlagSet) { - // Regardless of whether the user sets it to true or false, if they - // specify --tlsverify at all then we need to turn on tls - // TLSVerify can be true even if not set due to DOCKER_TLS_VERIFY env var, so we need - // to check that here as well - if flags.Changed(FlagTLSVerify) || commonOpts.TLSVerify { - commonOpts.TLS = true - } - - if !commonOpts.TLS { - commonOpts.TLSOptions = nil - } else { - tlsOptions := commonOpts.TLSOptions - tlsOptions.InsecureSkipVerify = !commonOpts.TLSVerify - - // Reset CertFile and KeyFile to empty string if the user did not specify - // the respective flags and the respective default files were not found. - if !flags.Changed("tlscert") { - if _, err := os.Stat(tlsOptions.CertFile); os.IsNotExist(err) { - tlsOptions.CertFile = "" - } - } - if !flags.Changed("tlskey") { - if _, err := os.Stat(tlsOptions.KeyFile); os.IsNotExist(err) { - tlsOptions.KeyFile = "" - } - } - } -} - -// SetLogLevel sets the logrus logging level -func SetLogLevel(logLevel string) { - if logLevel != "" { - lvl, err := logrus.ParseLevel(logLevel) - if err != nil { - fmt.Fprintf(os.Stderr, "Unable to parse logging level: %s\n", logLevel) - os.Exit(1) - } - logrus.SetLevel(lvl) - } else { - logrus.SetLevel(logrus.InfoLevel) - } -} diff --git a/vendor/github.com/docker/docker/cli/flags/common_test.go b/vendor/github.com/docker/docker/cli/flags/common_test.go deleted file mode 100644 index 81eaa38..0000000 --- a/vendor/github.com/docker/docker/cli/flags/common_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package flags - -import ( - "path/filepath" - "testing" - - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/pkg/testutil/assert" - "github.com/spf13/pflag" -) - -func TestCommonOptionsInstallFlags(t *testing.T) { - flags := pflag.NewFlagSet("testing", pflag.ContinueOnError) - opts := NewCommonOptions() - opts.InstallFlags(flags) - - err := flags.Parse([]string{ - "--tlscacert=\"/foo/cafile\"", - "--tlscert=\"/foo/cert\"", - "--tlskey=\"/foo/key\"", - }) - assert.NilError(t, err) - assert.Equal(t, opts.TLSOptions.CAFile, "/foo/cafile") - assert.Equal(t, opts.TLSOptions.CertFile, "/foo/cert") - assert.Equal(t, opts.TLSOptions.KeyFile, "/foo/key") -} - -func defaultPath(filename string) string { - return filepath.Join(cliconfig.ConfigDir(), filename) -} - -func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) { - flags := pflag.NewFlagSet("testing", pflag.ContinueOnError) - opts := NewCommonOptions() - opts.InstallFlags(flags) - - err := flags.Parse([]string{}) - assert.NilError(t, err) - assert.Equal(t, opts.TLSOptions.CAFile, defaultPath("ca.pem")) - assert.Equal(t, opts.TLSOptions.CertFile, defaultPath("cert.pem")) - assert.Equal(t, opts.TLSOptions.KeyFile, defaultPath("key.pem")) -} diff --git a/vendor/github.com/docker/docker/cli/required.go b/vendor/github.com/docker/docker/cli/required.go deleted file mode 100644 index 8ee02c8..0000000 --- a/vendor/github.com/docker/docker/cli/required.go +++ /dev/null @@ -1,96 +0,0 @@ -package cli - -import ( - "fmt" - "strings" - - "github.com/spf13/cobra" -) - -// NoArgs validates args and returns an error if there are any args -func NoArgs(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return nil - } - - if cmd.HasSubCommands() { - return fmt.Errorf("\n" + strings.TrimRight(cmd.UsageString(), "\n")) - } - - return fmt.Errorf( - "\"%s\" accepts no argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s", - cmd.CommandPath(), - cmd.CommandPath(), - cmd.UseLine(), - cmd.Short, - ) -} - -// RequiresMinArgs returns an error if there is not at least min args -func RequiresMinArgs(min int) cobra.PositionalArgs { - return func(cmd *cobra.Command, args []string) error { - if len(args) >= min { - return nil - } - return fmt.Errorf( - "\"%s\" requires at least %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s", - cmd.CommandPath(), - min, - cmd.CommandPath(), - cmd.UseLine(), - cmd.Short, - ) - } -} - -// RequiresMaxArgs returns an error if there is not at most max args -func RequiresMaxArgs(max int) cobra.PositionalArgs { - return func(cmd *cobra.Command, args []string) error { - if len(args) <= max { - return nil - } - return fmt.Errorf( - "\"%s\" requires at most %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s", - cmd.CommandPath(), - max, - cmd.CommandPath(), - cmd.UseLine(), - cmd.Short, - ) - } -} - -// RequiresRangeArgs returns an error if there is not at least min args and at most max args -func RequiresRangeArgs(min int, max int) cobra.PositionalArgs { - return func(cmd *cobra.Command, args []string) error { - if len(args) >= min && len(args) <= max { - return nil - } - return fmt.Errorf( - "\"%s\" requires at least %d and at most %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s", - cmd.CommandPath(), - min, - max, - cmd.CommandPath(), - cmd.UseLine(), - cmd.Short, - ) - } -} - -// ExactArgs returns an error if there is not the exact number of args -func ExactArgs(number int) cobra.PositionalArgs { - return func(cmd *cobra.Command, args []string) error { - if len(args) == number { - return nil - } - return fmt.Errorf( - "\"%s\" requires exactly %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s", - cmd.CommandPath(), - number, - cmd.CommandPath(), - cmd.UseLine(), - cmd.Short, - ) - } -} diff --git a/vendor/github.com/docker/docker/cli/trust/trust.go b/vendor/github.com/docker/docker/cli/trust/trust.go deleted file mode 100644 index 51914f7..0000000 --- a/vendor/github.com/docker/docker/cli/trust/trust.go +++ /dev/null @@ -1,232 +0,0 @@ -package trust - -import ( - "encoding/json" - "fmt" - "net" - "net/http" - "net/url" - "os" - "path" - "path/filepath" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/registry/client/auth" - "github.com/docker/distribution/registry/client/auth/challenge" - "github.com/docker/distribution/registry/client/transport" - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/registry" - "github.com/docker/go-connections/tlsconfig" - "github.com/docker/notary" - "github.com/docker/notary/client" - "github.com/docker/notary/passphrase" - "github.com/docker/notary/storage" - "github.com/docker/notary/trustmanager" - "github.com/docker/notary/trustpinning" - "github.com/docker/notary/tuf/data" - "github.com/docker/notary/tuf/signed" -) - -var ( - // ReleasesRole is the role named "releases" - ReleasesRole = path.Join(data.CanonicalTargetsRole, "releases") -) - -func trustDirectory() string { - return filepath.Join(cliconfig.ConfigDir(), "trust") -} - -// certificateDirectory returns the directory containing -// TLS certificates for the given server. An error is -// returned if there was an error parsing the server string. -func certificateDirectory(server string) (string, error) { - u, err := url.Parse(server) - if err != nil { - return "", err - } - - return filepath.Join(cliconfig.ConfigDir(), "tls", u.Host), nil -} - -// Server returns the base URL for the trust server. -func Server(index *registrytypes.IndexInfo) (string, error) { - if s := os.Getenv("DOCKER_CONTENT_TRUST_SERVER"); s != "" { - urlObj, err := url.Parse(s) - if err != nil || urlObj.Scheme != "https" { - return "", fmt.Errorf("valid https URL required for trust server, got %s", s) - } - - return s, nil - } - if index.Official { - return registry.NotaryServer, nil - } - return "https://" + index.Name, nil -} - -type simpleCredentialStore struct { - auth types.AuthConfig -} - -func (scs simpleCredentialStore) Basic(u *url.URL) (string, string) { - return scs.auth.Username, scs.auth.Password -} - -func (scs simpleCredentialStore) RefreshToken(u *url.URL, service string) string { - return scs.auth.IdentityToken -} - -func (scs simpleCredentialStore) SetRefreshToken(*url.URL, string, string) { -} - -// GetNotaryRepository returns a NotaryRepository which stores all the -// information needed to operate on a notary repository. -// It creates an HTTP transport providing authentication support. -func GetNotaryRepository(streams command.Streams, repoInfo *registry.RepositoryInfo, authConfig types.AuthConfig, actions ...string) (*client.NotaryRepository, error) { - server, err := Server(repoInfo.Index) - if err != nil { - return nil, err - } - - var cfg = tlsconfig.ClientDefault() - cfg.InsecureSkipVerify = !repoInfo.Index.Secure - - // Get certificate base directory - certDir, err := certificateDirectory(server) - if err != nil { - return nil, err - } - logrus.Debugf("reading certificate directory: %s", certDir) - - if err := registry.ReadCertsDirectory(cfg, certDir); err != nil { - return nil, err - } - - base := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - DualStack: true, - }).Dial, - TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: cfg, - DisableKeepAlives: true, - } - - // Skip configuration headers since request is not going to Docker daemon - modifiers := registry.DockerHeaders(command.UserAgent(), http.Header{}) - authTransport := transport.NewTransport(base, modifiers...) - pingClient := &http.Client{ - Transport: authTransport, - Timeout: 5 * time.Second, - } - endpointStr := server + "/v2/" - req, err := http.NewRequest("GET", endpointStr, nil) - if err != nil { - return nil, err - } - - challengeManager := challenge.NewSimpleManager() - - resp, err := pingClient.Do(req) - if err != nil { - // Ignore error on ping to operate in offline mode - logrus.Debugf("Error pinging notary server %q: %s", endpointStr, err) - } else { - defer resp.Body.Close() - - // Add response to the challenge manager to parse out - // authentication header and register authentication method - if err := challengeManager.AddResponse(resp); err != nil { - return nil, err - } - } - - scope := auth.RepositoryScope{ - Repository: repoInfo.FullName(), - Actions: actions, - Class: repoInfo.Class, - } - creds := simpleCredentialStore{auth: authConfig} - tokenHandlerOptions := auth.TokenHandlerOptions{ - Transport: authTransport, - Credentials: creds, - Scopes: []auth.Scope{scope}, - ClientID: registry.AuthClientID, - } - tokenHandler := auth.NewTokenHandlerWithOptions(tokenHandlerOptions) - basicHandler := auth.NewBasicHandler(creds) - modifiers = append(modifiers, transport.RequestModifier(auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler))) - tr := transport.NewTransport(base, modifiers...) - - return client.NewNotaryRepository( - trustDirectory(), - repoInfo.FullName(), - server, - tr, - getPassphraseRetriever(streams), - trustpinning.TrustPinConfig{}) -} - -func getPassphraseRetriever(streams command.Streams) notary.PassRetriever { - aliasMap := map[string]string{ - "root": "root", - "snapshot": "repository", - "targets": "repository", - "default": "repository", - } - baseRetriever := passphrase.PromptRetrieverWithInOut(streams.In(), streams.Out(), aliasMap) - env := map[string]string{ - "root": os.Getenv("DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE"), - "snapshot": os.Getenv("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE"), - "targets": os.Getenv("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE"), - "default": os.Getenv("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE"), - } - - return func(keyName string, alias string, createNew bool, numAttempts int) (string, bool, error) { - if v := env[alias]; v != "" { - return v, numAttempts > 1, nil - } - // For non-root roles, we can also try the "default" alias if it is specified - if v := env["default"]; v != "" && alias != data.CanonicalRootRole { - return v, numAttempts > 1, nil - } - return baseRetriever(keyName, alias, createNew, numAttempts) - } -} - -// NotaryError formats an error message received from the notary service -func NotaryError(repoName string, err error) error { - switch err.(type) { - case *json.SyntaxError: - logrus.Debugf("Notary syntax error: %s", err) - return fmt.Errorf("Error: no trust data available for remote repository %s. Try running notary server and setting DOCKER_CONTENT_TRUST_SERVER to its HTTPS address?", repoName) - case signed.ErrExpired: - return fmt.Errorf("Error: remote repository %s out-of-date: %v", repoName, err) - case trustmanager.ErrKeyNotFound: - return fmt.Errorf("Error: signing keys for remote repository %s not found: %v", repoName, err) - case storage.NetworkError: - return fmt.Errorf("Error: error contacting notary server: %v", err) - case storage.ErrMetaNotFound: - return fmt.Errorf("Error: trust data missing for remote repository %s or remote repository not found: %v", repoName, err) - case trustpinning.ErrRootRotationFail, trustpinning.ErrValidationFail, signed.ErrInvalidKeyType: - return fmt.Errorf("Warning: potential malicious behavior - trust data mismatch for remote repository %s: %v", repoName, err) - case signed.ErrNoKeys: - return fmt.Errorf("Error: could not find signing keys for remote repository %s, or could not decrypt signing key: %v", repoName, err) - case signed.ErrLowVersion: - return fmt.Errorf("Warning: potential malicious behavior - trust data version is lower than expected for remote repository %s: %v", repoName, err) - case signed.ErrRoleThreshold: - return fmt.Errorf("Warning: potential malicious behavior - trust data has insufficient signatures for remote repository %s: %v", repoName, err) - case client.ErrRepositoryNotExist: - return fmt.Errorf("Error: remote trust data does not exist for %s: %v", repoName, err) - case signed.ErrInsufficientSignatures: - return fmt.Errorf("Error: could not produce valid signature for %s. If Yubikey was used, was touch input provided?: %v", repoName, err) - } - - return err -} diff --git a/vendor/github.com/docker/docker/cliconfig/config.go b/vendor/github.com/docker/docker/cliconfig/config.go deleted file mode 100644 index d81bf86..0000000 --- a/vendor/github.com/docker/docker/cliconfig/config.go +++ /dev/null @@ -1,120 +0,0 @@ -package cliconfig - -import ( - "fmt" - "io" - "os" - "path/filepath" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cliconfig/configfile" - "github.com/docker/docker/pkg/homedir" -) - -const ( - // ConfigFileName is the name of config file - ConfigFileName = "config.json" - configFileDir = ".docker" - oldConfigfile = ".dockercfg" -) - -var ( - configDir = os.Getenv("DOCKER_CONFIG") -) - -func init() { - if configDir == "" { - configDir = filepath.Join(homedir.Get(), configFileDir) - } -} - -// ConfigDir returns the directory the configuration file is stored in -func ConfigDir() string { - return configDir -} - -// SetConfigDir sets the directory the configuration file is stored in -func SetConfigDir(dir string) { - configDir = dir -} - -// NewConfigFile initializes an empty configuration file for the given filename 'fn' -func NewConfigFile(fn string) *configfile.ConfigFile { - return &configfile.ConfigFile{ - AuthConfigs: make(map[string]types.AuthConfig), - HTTPHeaders: make(map[string]string), - Filename: fn, - } -} - -// LegacyLoadFromReader is a convenience function that creates a ConfigFile object from -// a non-nested reader -func LegacyLoadFromReader(configData io.Reader) (*configfile.ConfigFile, error) { - configFile := configfile.ConfigFile{ - AuthConfigs: make(map[string]types.AuthConfig), - } - err := configFile.LegacyLoadFromReader(configData) - return &configFile, err -} - -// LoadFromReader is a convenience function that creates a ConfigFile object from -// a reader -func LoadFromReader(configData io.Reader) (*configfile.ConfigFile, error) { - configFile := configfile.ConfigFile{ - AuthConfigs: make(map[string]types.AuthConfig), - } - err := configFile.LoadFromReader(configData) - return &configFile, err -} - -// Load reads the configuration files in the given directory, and sets up -// the auth config information and returns values. -// FIXME: use the internal golang config parser -func Load(configDir string) (*configfile.ConfigFile, error) { - if configDir == "" { - configDir = ConfigDir() - } - - configFile := configfile.ConfigFile{ - AuthConfigs: make(map[string]types.AuthConfig), - Filename: filepath.Join(configDir, ConfigFileName), - } - - // Try happy path first - latest config file - if _, err := os.Stat(configFile.Filename); err == nil { - file, err := os.Open(configFile.Filename) - if err != nil { - return &configFile, fmt.Errorf("%s - %v", configFile.Filename, err) - } - defer file.Close() - err = configFile.LoadFromReader(file) - if err != nil { - err = fmt.Errorf("%s - %v", configFile.Filename, err) - } - return &configFile, err - } else if !os.IsNotExist(err) { - // if file is there but we can't stat it for any reason other - // than it doesn't exist then stop - return &configFile, fmt.Errorf("%s - %v", configFile.Filename, err) - } - - // Can't find latest config file so check for the old one - confFile := filepath.Join(homedir.Get(), oldConfigfile) - if _, err := os.Stat(confFile); err != nil { - return &configFile, nil //missing file is not an error - } - file, err := os.Open(confFile) - if err != nil { - return &configFile, fmt.Errorf("%s - %v", confFile, err) - } - defer file.Close() - err = configFile.LegacyLoadFromReader(file) - if err != nil { - return &configFile, fmt.Errorf("%s - %v", confFile, err) - } - - if configFile.HTTPHeaders == nil { - configFile.HTTPHeaders = map[string]string{} - } - return &configFile, nil -} diff --git a/vendor/github.com/docker/docker/cliconfig/config_test.go b/vendor/github.com/docker/docker/cliconfig/config_test.go deleted file mode 100644 index d8a099a..0000000 --- a/vendor/github.com/docker/docker/cliconfig/config_test.go +++ /dev/null @@ -1,621 +0,0 @@ -package cliconfig - -import ( - "io/ioutil" - "os" - "path/filepath" - "strings" - "testing" - - "github.com/docker/docker/cliconfig/configfile" - "github.com/docker/docker/pkg/homedir" -) - -func TestEmptyConfigDir(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - SetConfigDir(tmpHome) - - config, err := Load("") - if err != nil { - t.Fatalf("Failed loading on empty config dir: %q", err) - } - - expectedConfigFilename := filepath.Join(tmpHome, ConfigFileName) - if config.Filename != expectedConfigFilename { - t.Fatalf("Expected config filename %s, got %s", expectedConfigFilename, config.Filename) - } - - // Now save it and make sure it shows up in new form - saveConfigAndValidateNewFormat(t, config, tmpHome) -} - -func TestMissingFile(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - config, err := Load(tmpHome) - if err != nil { - t.Fatalf("Failed loading on missing file: %q", err) - } - - // Now save it and make sure it shows up in new form - saveConfigAndValidateNewFormat(t, config, tmpHome) -} - -func TestSaveFileToDirs(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - tmpHome += "/.docker" - - config, err := Load(tmpHome) - if err != nil { - t.Fatalf("Failed loading on missing file: %q", err) - } - - // Now save it and make sure it shows up in new form - saveConfigAndValidateNewFormat(t, config, tmpHome) -} - -func TestEmptyFile(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - fn := filepath.Join(tmpHome, ConfigFileName) - if err := ioutil.WriteFile(fn, []byte(""), 0600); err != nil { - t.Fatal(err) - } - - _, err = Load(tmpHome) - if err == nil { - t.Fatalf("Was supposed to fail") - } -} - -func TestEmptyJSON(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - fn := filepath.Join(tmpHome, ConfigFileName) - if err := ioutil.WriteFile(fn, []byte("{}"), 0600); err != nil { - t.Fatal(err) - } - - config, err := Load(tmpHome) - if err != nil { - t.Fatalf("Failed loading on empty json file: %q", err) - } - - // Now save it and make sure it shows up in new form - saveConfigAndValidateNewFormat(t, config, tmpHome) -} - -func TestOldInvalidsAuth(t *testing.T) { - invalids := map[string]string{ - `username = test`: "The Auth config file is empty", - `username -password`: "Invalid Auth config file", - `username = test -email`: "Invalid auth configuration file", - } - - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - homeKey := homedir.Key() - homeVal := homedir.Get() - - defer func() { os.Setenv(homeKey, homeVal) }() - os.Setenv(homeKey, tmpHome) - - for content, expectedError := range invalids { - fn := filepath.Join(tmpHome, oldConfigfile) - if err := ioutil.WriteFile(fn, []byte(content), 0600); err != nil { - t.Fatal(err) - } - - config, err := Load(tmpHome) - // Use Contains instead of == since the file name will change each time - if err == nil || !strings.Contains(err.Error(), expectedError) { - t.Fatalf("Should have failed\nConfig: %v\nGot: %v\nExpected: %v", config, err, expectedError) - } - - } -} - -func TestOldValidAuth(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - homeKey := homedir.Key() - homeVal := homedir.Get() - - defer func() { os.Setenv(homeKey, homeVal) }() - os.Setenv(homeKey, tmpHome) - - fn := filepath.Join(tmpHome, oldConfigfile) - js := `username = am9lam9lOmhlbGxv - email = user@example.com` - if err := ioutil.WriteFile(fn, []byte(js), 0600); err != nil { - t.Fatal(err) - } - - config, err := Load(tmpHome) - if err != nil { - t.Fatal(err) - } - - // defaultIndexserver is https://index.docker.io/v1/ - ac := config.AuthConfigs["https://index.docker.io/v1/"] - if ac.Username != "joejoe" || ac.Password != "hello" { - t.Fatalf("Missing data from parsing:\n%q", config) - } - - // Now save it and make sure it shows up in new form - configStr := saveConfigAndValidateNewFormat(t, config, tmpHome) - - expConfStr := `{ - "auths": { - "https://index.docker.io/v1/": { - "auth": "am9lam9lOmhlbGxv" - } - } -}` - - if configStr != expConfStr { - t.Fatalf("Should have save in new form: \n%s\n not \n%s", configStr, expConfStr) - } -} - -func TestOldJSONInvalid(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - homeKey := homedir.Key() - homeVal := homedir.Get() - - defer func() { os.Setenv(homeKey, homeVal) }() - os.Setenv(homeKey, tmpHome) - - fn := filepath.Join(tmpHome, oldConfigfile) - js := `{"https://index.docker.io/v1/":{"auth":"test","email":"user@example.com"}}` - if err := ioutil.WriteFile(fn, []byte(js), 0600); err != nil { - t.Fatal(err) - } - - config, err := Load(tmpHome) - // Use Contains instead of == since the file name will change each time - if err == nil || !strings.Contains(err.Error(), "Invalid auth configuration file") { - t.Fatalf("Expected an error got : %v, %v", config, err) - } -} - -func TestOldJSON(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - homeKey := homedir.Key() - homeVal := homedir.Get() - - defer func() { os.Setenv(homeKey, homeVal) }() - os.Setenv(homeKey, tmpHome) - - fn := filepath.Join(tmpHome, oldConfigfile) - js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"user@example.com"}}` - if err := ioutil.WriteFile(fn, []byte(js), 0600); err != nil { - t.Fatal(err) - } - - config, err := Load(tmpHome) - if err != nil { - t.Fatalf("Failed loading on empty json file: %q", err) - } - - ac := config.AuthConfigs["https://index.docker.io/v1/"] - if ac.Username != "joejoe" || ac.Password != "hello" { - t.Fatalf("Missing data from parsing:\n%q", config) - } - - // Now save it and make sure it shows up in new form - configStr := saveConfigAndValidateNewFormat(t, config, tmpHome) - - expConfStr := `{ - "auths": { - "https://index.docker.io/v1/": { - "auth": "am9lam9lOmhlbGxv", - "email": "user@example.com" - } - } -}` - - if configStr != expConfStr { - t.Fatalf("Should have save in new form: \n'%s'\n not \n'%s'\n", configStr, expConfStr) - } -} - -func TestNewJSON(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - fn := filepath.Join(tmpHome, ConfigFileName) - js := ` { "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv" } } }` - if err := ioutil.WriteFile(fn, []byte(js), 0600); err != nil { - t.Fatal(err) - } - - config, err := Load(tmpHome) - if err != nil { - t.Fatalf("Failed loading on empty json file: %q", err) - } - - ac := config.AuthConfigs["https://index.docker.io/v1/"] - if ac.Username != "joejoe" || ac.Password != "hello" { - t.Fatalf("Missing data from parsing:\n%q", config) - } - - // Now save it and make sure it shows up in new form - configStr := saveConfigAndValidateNewFormat(t, config, tmpHome) - - expConfStr := `{ - "auths": { - "https://index.docker.io/v1/": { - "auth": "am9lam9lOmhlbGxv" - } - } -}` - - if configStr != expConfStr { - t.Fatalf("Should have save in new form: \n%s\n not \n%s", configStr, expConfStr) - } -} - -func TestNewJSONNoEmail(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - fn := filepath.Join(tmpHome, ConfigFileName) - js := ` { "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv" } } }` - if err := ioutil.WriteFile(fn, []byte(js), 0600); err != nil { - t.Fatal(err) - } - - config, err := Load(tmpHome) - if err != nil { - t.Fatalf("Failed loading on empty json file: %q", err) - } - - ac := config.AuthConfigs["https://index.docker.io/v1/"] - if ac.Username != "joejoe" || ac.Password != "hello" { - t.Fatalf("Missing data from parsing:\n%q", config) - } - - // Now save it and make sure it shows up in new form - configStr := saveConfigAndValidateNewFormat(t, config, tmpHome) - - expConfStr := `{ - "auths": { - "https://index.docker.io/v1/": { - "auth": "am9lam9lOmhlbGxv" - } - } -}` - - if configStr != expConfStr { - t.Fatalf("Should have save in new form: \n%s\n not \n%s", configStr, expConfStr) - } -} - -func TestJSONWithPsFormat(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - fn := filepath.Join(tmpHome, ConfigFileName) - js := `{ - "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "user@example.com" } }, - "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}" -}` - if err := ioutil.WriteFile(fn, []byte(js), 0600); err != nil { - t.Fatal(err) - } - - config, err := Load(tmpHome) - if err != nil { - t.Fatalf("Failed loading on empty json file: %q", err) - } - - if config.PsFormat != `table {{.ID}}\t{{.Label "com.docker.label.cpu"}}` { - t.Fatalf("Unknown ps format: %s\n", config.PsFormat) - } - - // Now save it and make sure it shows up in new form - configStr := saveConfigAndValidateNewFormat(t, config, tmpHome) - if !strings.Contains(configStr, `"psFormat":`) || - !strings.Contains(configStr, "{{.ID}}") { - t.Fatalf("Should have save in new form: %s", configStr) - } -} - -func TestJSONWithCredentialStore(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - fn := filepath.Join(tmpHome, ConfigFileName) - js := `{ - "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "user@example.com" } }, - "credsStore": "crazy-secure-storage" -}` - if err := ioutil.WriteFile(fn, []byte(js), 0600); err != nil { - t.Fatal(err) - } - - config, err := Load(tmpHome) - if err != nil { - t.Fatalf("Failed loading on empty json file: %q", err) - } - - if config.CredentialsStore != "crazy-secure-storage" { - t.Fatalf("Unknown credential store: %s\n", config.CredentialsStore) - } - - // Now save it and make sure it shows up in new form - configStr := saveConfigAndValidateNewFormat(t, config, tmpHome) - if !strings.Contains(configStr, `"credsStore":`) || - !strings.Contains(configStr, "crazy-secure-storage") { - t.Fatalf("Should have save in new form: %s", configStr) - } -} - -func TestJSONWithCredentialHelpers(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - fn := filepath.Join(tmpHome, ConfigFileName) - js := `{ - "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "user@example.com" } }, - "credHelpers": { "images.io": "images-io", "containers.com": "crazy-secure-storage" } -}` - if err := ioutil.WriteFile(fn, []byte(js), 0600); err != nil { - t.Fatal(err) - } - - config, err := Load(tmpHome) - if err != nil { - t.Fatalf("Failed loading on empty json file: %q", err) - } - - if config.CredentialHelpers == nil { - t.Fatal("config.CredentialHelpers was nil") - } else if config.CredentialHelpers["images.io"] != "images-io" || - config.CredentialHelpers["containers.com"] != "crazy-secure-storage" { - t.Fatalf("Credential helpers not deserialized properly: %v\n", config.CredentialHelpers) - } - - // Now save it and make sure it shows up in new form - configStr := saveConfigAndValidateNewFormat(t, config, tmpHome) - if !strings.Contains(configStr, `"credHelpers":`) || - !strings.Contains(configStr, "images.io") || - !strings.Contains(configStr, "images-io") || - !strings.Contains(configStr, "containers.com") || - !strings.Contains(configStr, "crazy-secure-storage") { - t.Fatalf("Should have save in new form: %s", configStr) - } -} - -// Save it and make sure it shows up in new form -func saveConfigAndValidateNewFormat(t *testing.T, config *configfile.ConfigFile, homeFolder string) string { - if err := config.Save(); err != nil { - t.Fatalf("Failed to save: %q", err) - } - - buf, err := ioutil.ReadFile(filepath.Join(homeFolder, ConfigFileName)) - if err != nil { - t.Fatal(err) - } - if !strings.Contains(string(buf), `"auths":`) { - t.Fatalf("Should have save in new form: %s", string(buf)) - } - return string(buf) -} - -func TestConfigDir(t *testing.T) { - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpHome) - - if ConfigDir() == tmpHome { - t.Fatalf("Expected ConfigDir to be different than %s by default, but was the same", tmpHome) - } - - // Update configDir - SetConfigDir(tmpHome) - - if ConfigDir() != tmpHome { - t.Fatalf("Expected ConfigDir to %s, but was %s", tmpHome, ConfigDir()) - } -} - -func TestConfigFile(t *testing.T) { - configFilename := "configFilename" - configFile := NewConfigFile(configFilename) - - if configFile.Filename != configFilename { - t.Fatalf("Expected %s, got %s", configFilename, configFile.Filename) - } -} - -func TestJSONReaderNoFile(t *testing.T) { - js := ` { "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "user@example.com" } } }` - - config, err := LoadFromReader(strings.NewReader(js)) - if err != nil { - t.Fatalf("Failed loading on empty json file: %q", err) - } - - ac := config.AuthConfigs["https://index.docker.io/v1/"] - if ac.Username != "joejoe" || ac.Password != "hello" { - t.Fatalf("Missing data from parsing:\n%q", config) - } - -} - -func TestOldJSONReaderNoFile(t *testing.T) { - js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"user@example.com"}}` - - config, err := LegacyLoadFromReader(strings.NewReader(js)) - if err != nil { - t.Fatalf("Failed loading on empty json file: %q", err) - } - - ac := config.AuthConfigs["https://index.docker.io/v1/"] - if ac.Username != "joejoe" || ac.Password != "hello" { - t.Fatalf("Missing data from parsing:\n%q", config) - } -} - -func TestJSONWithPsFormatNoFile(t *testing.T) { - js := `{ - "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "user@example.com" } }, - "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}" -}` - config, err := LoadFromReader(strings.NewReader(js)) - if err != nil { - t.Fatalf("Failed loading on empty json file: %q", err) - } - - if config.PsFormat != `table {{.ID}}\t{{.Label "com.docker.label.cpu"}}` { - t.Fatalf("Unknown ps format: %s\n", config.PsFormat) - } - -} - -func TestJSONSaveWithNoFile(t *testing.T) { - js := `{ - "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv" } }, - "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}" -}` - config, err := LoadFromReader(strings.NewReader(js)) - err = config.Save() - if err == nil { - t.Fatalf("Expected error. File should not have been able to save with no file name.") - } - - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatalf("Failed to create a temp dir: %q", err) - } - defer os.RemoveAll(tmpHome) - - fn := filepath.Join(tmpHome, ConfigFileName) - f, _ := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - defer f.Close() - - err = config.SaveToWriter(f) - if err != nil { - t.Fatalf("Failed saving to file: %q", err) - } - buf, err := ioutil.ReadFile(filepath.Join(tmpHome, ConfigFileName)) - if err != nil { - t.Fatal(err) - } - expConfStr := `{ - "auths": { - "https://index.docker.io/v1/": { - "auth": "am9lam9lOmhlbGxv" - } - }, - "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}" -}` - if string(buf) != expConfStr { - t.Fatalf("Should have save in new form: \n%s\nnot \n%s", string(buf), expConfStr) - } -} - -func TestLegacyJSONSaveWithNoFile(t *testing.T) { - - js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"user@example.com"}}` - config, err := LegacyLoadFromReader(strings.NewReader(js)) - err = config.Save() - if err == nil { - t.Fatalf("Expected error. File should not have been able to save with no file name.") - } - - tmpHome, err := ioutil.TempDir("", "config-test") - if err != nil { - t.Fatalf("Failed to create a temp dir: %q", err) - } - defer os.RemoveAll(tmpHome) - - fn := filepath.Join(tmpHome, ConfigFileName) - f, _ := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - defer f.Close() - - if err = config.SaveToWriter(f); err != nil { - t.Fatalf("Failed saving to file: %q", err) - } - buf, err := ioutil.ReadFile(filepath.Join(tmpHome, ConfigFileName)) - if err != nil { - t.Fatal(err) - } - - expConfStr := `{ - "auths": { - "https://index.docker.io/v1/": { - "auth": "am9lam9lOmhlbGxv", - "email": "user@example.com" - } - } -}` - - if string(buf) != expConfStr { - t.Fatalf("Should have save in new form: \n%s\n not \n%s", string(buf), expConfStr) - } -} diff --git a/vendor/github.com/docker/docker/cliconfig/configfile/file.go b/vendor/github.com/docker/docker/cliconfig/configfile/file.go deleted file mode 100644 index 3909713..0000000 --- a/vendor/github.com/docker/docker/cliconfig/configfile/file.go +++ /dev/null @@ -1,183 +0,0 @@ -package configfile - -import ( - "encoding/base64" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - - "github.com/docker/docker/api/types" -) - -const ( - // This constant is only used for really old config files when the - // URL wasn't saved as part of the config file and it was just - // assumed to be this value. - defaultIndexserver = "https://index.docker.io/v1/" -) - -// ConfigFile ~/.docker/config.json file info -type ConfigFile struct { - AuthConfigs map[string]types.AuthConfig `json:"auths"` - HTTPHeaders map[string]string `json:"HttpHeaders,omitempty"` - PsFormat string `json:"psFormat,omitempty"` - ImagesFormat string `json:"imagesFormat,omitempty"` - NetworksFormat string `json:"networksFormat,omitempty"` - VolumesFormat string `json:"volumesFormat,omitempty"` - StatsFormat string `json:"statsFormat,omitempty"` - DetachKeys string `json:"detachKeys,omitempty"` - CredentialsStore string `json:"credsStore,omitempty"` - CredentialHelpers map[string]string `json:"credHelpers,omitempty"` - Filename string `json:"-"` // Note: for internal use only - ServiceInspectFormat string `json:"serviceInspectFormat,omitempty"` -} - -// LegacyLoadFromReader reads the non-nested configuration data given and sets up the -// auth config information with given directory and populates the receiver object -func (configFile *ConfigFile) LegacyLoadFromReader(configData io.Reader) error { - b, err := ioutil.ReadAll(configData) - if err != nil { - return err - } - - if err := json.Unmarshal(b, &configFile.AuthConfigs); err != nil { - arr := strings.Split(string(b), "\n") - if len(arr) < 2 { - return fmt.Errorf("The Auth config file is empty") - } - authConfig := types.AuthConfig{} - origAuth := strings.Split(arr[0], " = ") - if len(origAuth) != 2 { - return fmt.Errorf("Invalid Auth config file") - } - authConfig.Username, authConfig.Password, err = decodeAuth(origAuth[1]) - if err != nil { - return err - } - authConfig.ServerAddress = defaultIndexserver - configFile.AuthConfigs[defaultIndexserver] = authConfig - } else { - for k, authConfig := range configFile.AuthConfigs { - authConfig.Username, authConfig.Password, err = decodeAuth(authConfig.Auth) - if err != nil { - return err - } - authConfig.Auth = "" - authConfig.ServerAddress = k - configFile.AuthConfigs[k] = authConfig - } - } - return nil -} - -// LoadFromReader reads the configuration data given and sets up the auth config -// information with given directory and populates the receiver object -func (configFile *ConfigFile) LoadFromReader(configData io.Reader) error { - if err := json.NewDecoder(configData).Decode(&configFile); err != nil { - return err - } - var err error - for addr, ac := range configFile.AuthConfigs { - ac.Username, ac.Password, err = decodeAuth(ac.Auth) - if err != nil { - return err - } - ac.Auth = "" - ac.ServerAddress = addr - configFile.AuthConfigs[addr] = ac - } - return nil -} - -// ContainsAuth returns whether there is authentication configured -// in this file or not. -func (configFile *ConfigFile) ContainsAuth() bool { - return configFile.CredentialsStore != "" || - len(configFile.CredentialHelpers) > 0 || - len(configFile.AuthConfigs) > 0 -} - -// SaveToWriter encodes and writes out all the authorization information to -// the given writer -func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error { - // Encode sensitive data into a new/temp struct - tmpAuthConfigs := make(map[string]types.AuthConfig, len(configFile.AuthConfigs)) - for k, authConfig := range configFile.AuthConfigs { - authCopy := authConfig - // encode and save the authstring, while blanking out the original fields - authCopy.Auth = encodeAuth(&authCopy) - authCopy.Username = "" - authCopy.Password = "" - authCopy.ServerAddress = "" - tmpAuthConfigs[k] = authCopy - } - - saveAuthConfigs := configFile.AuthConfigs - configFile.AuthConfigs = tmpAuthConfigs - defer func() { configFile.AuthConfigs = saveAuthConfigs }() - - data, err := json.MarshalIndent(configFile, "", "\t") - if err != nil { - return err - } - _, err = writer.Write(data) - return err -} - -// Save encodes and writes out all the authorization information -func (configFile *ConfigFile) Save() error { - if configFile.Filename == "" { - return fmt.Errorf("Can't save config with empty filename") - } - - if err := os.MkdirAll(filepath.Dir(configFile.Filename), 0700); err != nil { - return err - } - f, err := os.OpenFile(configFile.Filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - return err - } - defer f.Close() - return configFile.SaveToWriter(f) -} - -// encodeAuth creates a base64 encoded string to containing authorization information -func encodeAuth(authConfig *types.AuthConfig) string { - if authConfig.Username == "" && authConfig.Password == "" { - return "" - } - - authStr := authConfig.Username + ":" + authConfig.Password - msg := []byte(authStr) - encoded := make([]byte, base64.StdEncoding.EncodedLen(len(msg))) - base64.StdEncoding.Encode(encoded, msg) - return string(encoded) -} - -// decodeAuth decodes a base64 encoded string and returns username and password -func decodeAuth(authStr string) (string, string, error) { - if authStr == "" { - return "", "", nil - } - - decLen := base64.StdEncoding.DecodedLen(len(authStr)) - decoded := make([]byte, decLen) - authByte := []byte(authStr) - n, err := base64.StdEncoding.Decode(decoded, authByte) - if err != nil { - return "", "", err - } - if n > decLen { - return "", "", fmt.Errorf("Something went wrong decoding auth config") - } - arr := strings.SplitN(string(decoded), ":", 2) - if len(arr) != 2 { - return "", "", fmt.Errorf("Invalid auth configuration file") - } - password := strings.Trim(arr[1], "\x00") - return arr[0], password, nil -} diff --git a/vendor/github.com/docker/docker/cliconfig/configfile/file_test.go b/vendor/github.com/docker/docker/cliconfig/configfile/file_test.go deleted file mode 100644 index 435797f..0000000 --- a/vendor/github.com/docker/docker/cliconfig/configfile/file_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package configfile - -import ( - "testing" - - "github.com/docker/docker/api/types" -) - -func TestEncodeAuth(t *testing.T) { - newAuthConfig := &types.AuthConfig{Username: "ken", Password: "test"} - authStr := encodeAuth(newAuthConfig) - decAuthConfig := &types.AuthConfig{} - var err error - decAuthConfig.Username, decAuthConfig.Password, err = decodeAuth(authStr) - if err != nil { - t.Fatal(err) - } - if newAuthConfig.Username != decAuthConfig.Username { - t.Fatal("Encode Username doesn't match decoded Username") - } - if newAuthConfig.Password != decAuthConfig.Password { - t.Fatal("Encode Password doesn't match decoded Password") - } - if authStr != "a2VuOnRlc3Q=" { - t.Fatal("AuthString encoding isn't correct.") - } -} diff --git a/vendor/github.com/docker/docker/cliconfig/credentials/credentials.go b/vendor/github.com/docker/docker/cliconfig/credentials/credentials.go deleted file mode 100644 index ca874ca..0000000 --- a/vendor/github.com/docker/docker/cliconfig/credentials/credentials.go +++ /dev/null @@ -1,17 +0,0 @@ -package credentials - -import ( - "github.com/docker/docker/api/types" -) - -// Store is the interface that any credentials store must implement. -type Store interface { - // Erase removes credentials from the store for a given server. - Erase(serverAddress string) error - // Get retrieves credentials from the store for a given server. - Get(serverAddress string) (types.AuthConfig, error) - // GetAll retrieves all the credentials from the store. - GetAll() (map[string]types.AuthConfig, error) - // Store saves credentials in the store. - Store(authConfig types.AuthConfig) error -} diff --git a/vendor/github.com/docker/docker/cliconfig/credentials/default_store.go b/vendor/github.com/docker/docker/cliconfig/credentials/default_store.go deleted file mode 100644 index b473370..0000000 --- a/vendor/github.com/docker/docker/cliconfig/credentials/default_store.go +++ /dev/null @@ -1,22 +0,0 @@ -package credentials - -import ( - "os/exec" - - "github.com/docker/docker/cliconfig/configfile" -) - -// DetectDefaultStore sets the default credentials store -// if the host includes the default store helper program. -func DetectDefaultStore(c *configfile.ConfigFile) { - if c.CredentialsStore != "" { - // user defined - return - } - - if defaultCredentialsStore != "" { - if _, err := exec.LookPath(remoteCredentialsPrefix + defaultCredentialsStore); err == nil { - c.CredentialsStore = defaultCredentialsStore - } - } -} diff --git a/vendor/github.com/docker/docker/cliconfig/credentials/default_store_darwin.go b/vendor/github.com/docker/docker/cliconfig/credentials/default_store_darwin.go deleted file mode 100644 index 63e8ed4..0000000 --- a/vendor/github.com/docker/docker/cliconfig/credentials/default_store_darwin.go +++ /dev/null @@ -1,3 +0,0 @@ -package credentials - -const defaultCredentialsStore = "osxkeychain" diff --git a/vendor/github.com/docker/docker/cliconfig/credentials/default_store_linux.go b/vendor/github.com/docker/docker/cliconfig/credentials/default_store_linux.go deleted file mode 100644 index 864c540..0000000 --- a/vendor/github.com/docker/docker/cliconfig/credentials/default_store_linux.go +++ /dev/null @@ -1,3 +0,0 @@ -package credentials - -const defaultCredentialsStore = "secretservice" diff --git a/vendor/github.com/docker/docker/cliconfig/credentials/default_store_unsupported.go b/vendor/github.com/docker/docker/cliconfig/credentials/default_store_unsupported.go deleted file mode 100644 index 519ef53..0000000 --- a/vendor/github.com/docker/docker/cliconfig/credentials/default_store_unsupported.go +++ /dev/null @@ -1,5 +0,0 @@ -// +build !windows,!darwin,!linux - -package credentials - -const defaultCredentialsStore = "" diff --git a/vendor/github.com/docker/docker/cliconfig/credentials/default_store_windows.go b/vendor/github.com/docker/docker/cliconfig/credentials/default_store_windows.go deleted file mode 100644 index fb6a974..0000000 --- a/vendor/github.com/docker/docker/cliconfig/credentials/default_store_windows.go +++ /dev/null @@ -1,3 +0,0 @@ -package credentials - -const defaultCredentialsStore = "wincred" diff --git a/vendor/github.com/docker/docker/cliconfig/credentials/file_store.go b/vendor/github.com/docker/docker/cliconfig/credentials/file_store.go deleted file mode 100644 index ca73a38..0000000 --- a/vendor/github.com/docker/docker/cliconfig/credentials/file_store.go +++ /dev/null @@ -1,53 +0,0 @@ -package credentials - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/cliconfig/configfile" - "github.com/docker/docker/registry" -) - -// fileStore implements a credentials store using -// the docker configuration file to keep the credentials in plain text. -type fileStore struct { - file *configfile.ConfigFile -} - -// NewFileStore creates a new file credentials store. -func NewFileStore(file *configfile.ConfigFile) Store { - return &fileStore{ - file: file, - } -} - -// Erase removes the given credentials from the file store. -func (c *fileStore) Erase(serverAddress string) error { - delete(c.file.AuthConfigs, serverAddress) - return c.file.Save() -} - -// Get retrieves credentials for a specific server from the file store. -func (c *fileStore) Get(serverAddress string) (types.AuthConfig, error) { - authConfig, ok := c.file.AuthConfigs[serverAddress] - if !ok { - // Maybe they have a legacy config file, we will iterate the keys converting - // them to the new format and testing - for r, ac := range c.file.AuthConfigs { - if serverAddress == registry.ConvertToHostname(r) { - return ac, nil - } - } - - authConfig = types.AuthConfig{} - } - return authConfig, nil -} - -func (c *fileStore) GetAll() (map[string]types.AuthConfig, error) { - return c.file.AuthConfigs, nil -} - -// Store saves the given credentials in the file store. -func (c *fileStore) Store(authConfig types.AuthConfig) error { - c.file.AuthConfigs[authConfig.ServerAddress] = authConfig - return c.file.Save() -} diff --git a/vendor/github.com/docker/docker/cliconfig/credentials/file_store_test.go b/vendor/github.com/docker/docker/cliconfig/credentials/file_store_test.go deleted file mode 100644 index efed4e9..0000000 --- a/vendor/github.com/docker/docker/cliconfig/credentials/file_store_test.go +++ /dev/null @@ -1,139 +0,0 @@ -package credentials - -import ( - "io/ioutil" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/cliconfig/configfile" -) - -func newConfigFile(auths map[string]types.AuthConfig) *configfile.ConfigFile { - tmp, _ := ioutil.TempFile("", "docker-test") - name := tmp.Name() - tmp.Close() - - c := cliconfig.NewConfigFile(name) - c.AuthConfigs = auths - return c -} - -func TestFileStoreAddCredentials(t *testing.T) { - f := newConfigFile(make(map[string]types.AuthConfig)) - - s := NewFileStore(f) - err := s.Store(types.AuthConfig{ - Auth: "super_secret_token", - Email: "foo@example.com", - ServerAddress: "https://example.com", - }) - - if err != nil { - t.Fatal(err) - } - - if len(f.AuthConfigs) != 1 { - t.Fatalf("expected 1 auth config, got %d", len(f.AuthConfigs)) - } - - a, ok := f.AuthConfigs["https://example.com"] - if !ok { - t.Fatalf("expected auth for https://example.com, got %v", f.AuthConfigs) - } - if a.Auth != "super_secret_token" { - t.Fatalf("expected auth `super_secret_token`, got %s", a.Auth) - } - if a.Email != "foo@example.com" { - t.Fatalf("expected email `foo@example.com`, got %s", a.Email) - } -} - -func TestFileStoreGet(t *testing.T) { - f := newConfigFile(map[string]types.AuthConfig{ - "https://example.com": { - Auth: "super_secret_token", - Email: "foo@example.com", - ServerAddress: "https://example.com", - }, - }) - - s := NewFileStore(f) - a, err := s.Get("https://example.com") - if err != nil { - t.Fatal(err) - } - if a.Auth != "super_secret_token" { - t.Fatalf("expected auth `super_secret_token`, got %s", a.Auth) - } - if a.Email != "foo@example.com" { - t.Fatalf("expected email `foo@example.com`, got %s", a.Email) - } -} - -func TestFileStoreGetAll(t *testing.T) { - s1 := "https://example.com" - s2 := "https://example2.com" - f := newConfigFile(map[string]types.AuthConfig{ - s1: { - Auth: "super_secret_token", - Email: "foo@example.com", - ServerAddress: "https://example.com", - }, - s2: { - Auth: "super_secret_token2", - Email: "foo@example2.com", - ServerAddress: "https://example2.com", - }, - }) - - s := NewFileStore(f) - as, err := s.GetAll() - if err != nil { - t.Fatal(err) - } - if len(as) != 2 { - t.Fatalf("wanted 2, got %d", len(as)) - } - if as[s1].Auth != "super_secret_token" { - t.Fatalf("expected auth `super_secret_token`, got %s", as[s1].Auth) - } - if as[s1].Email != "foo@example.com" { - t.Fatalf("expected email `foo@example.com`, got %s", as[s1].Email) - } - if as[s2].Auth != "super_secret_token2" { - t.Fatalf("expected auth `super_secret_token2`, got %s", as[s2].Auth) - } - if as[s2].Email != "foo@example2.com" { - t.Fatalf("expected email `foo@example2.com`, got %s", as[s2].Email) - } -} - -func TestFileStoreErase(t *testing.T) { - f := newConfigFile(map[string]types.AuthConfig{ - "https://example.com": { - Auth: "super_secret_token", - Email: "foo@example.com", - ServerAddress: "https://example.com", - }, - }) - - s := NewFileStore(f) - err := s.Erase("https://example.com") - if err != nil { - t.Fatal(err) - } - - // file store never returns errors, check that the auth config is empty - a, err := s.Get("https://example.com") - if err != nil { - t.Fatal(err) - } - - if a.Auth != "" { - t.Fatalf("expected empty auth token, got %s", a.Auth) - } - if a.Email != "" { - t.Fatalf("expected empty email, got %s", a.Email) - } -} diff --git a/vendor/github.com/docker/docker/cliconfig/credentials/native_store.go b/vendor/github.com/docker/docker/cliconfig/credentials/native_store.go deleted file mode 100644 index dec2dbc..0000000 --- a/vendor/github.com/docker/docker/cliconfig/credentials/native_store.go +++ /dev/null @@ -1,144 +0,0 @@ -package credentials - -import ( - "github.com/docker/docker-credential-helpers/client" - "github.com/docker/docker-credential-helpers/credentials" - "github.com/docker/docker/api/types" - "github.com/docker/docker/cliconfig/configfile" -) - -const ( - remoteCredentialsPrefix = "docker-credential-" - tokenUsername = "" -) - -// nativeStore implements a credentials store -// using native keychain to keep credentials secure. -// It piggybacks into a file store to keep users' emails. -type nativeStore struct { - programFunc client.ProgramFunc - fileStore Store -} - -// NewNativeStore creates a new native store that -// uses a remote helper program to manage credentials. -func NewNativeStore(file *configfile.ConfigFile, helperSuffix string) Store { - name := remoteCredentialsPrefix + helperSuffix - return &nativeStore{ - programFunc: client.NewShellProgramFunc(name), - fileStore: NewFileStore(file), - } -} - -// Erase removes the given credentials from the native store. -func (c *nativeStore) Erase(serverAddress string) error { - if err := client.Erase(c.programFunc, serverAddress); err != nil { - return err - } - - // Fallback to plain text store to remove email - return c.fileStore.Erase(serverAddress) -} - -// Get retrieves credentials for a specific server from the native store. -func (c *nativeStore) Get(serverAddress string) (types.AuthConfig, error) { - // load user email if it exist or an empty auth config. - auth, _ := c.fileStore.Get(serverAddress) - - creds, err := c.getCredentialsFromStore(serverAddress) - if err != nil { - return auth, err - } - auth.Username = creds.Username - auth.IdentityToken = creds.IdentityToken - auth.Password = creds.Password - - return auth, nil -} - -// GetAll retrieves all the credentials from the native store. -func (c *nativeStore) GetAll() (map[string]types.AuthConfig, error) { - auths, err := c.listCredentialsInStore() - if err != nil { - return nil, err - } - - // Emails are only stored in the file store. - // This call can be safely eliminated when emails are removed. - fileConfigs, _ := c.fileStore.GetAll() - - authConfigs := make(map[string]types.AuthConfig) - for registry := range auths { - creds, err := c.getCredentialsFromStore(registry) - if err != nil { - return nil, err - } - ac, _ := fileConfigs[registry] // might contain Email - ac.Username = creds.Username - ac.Password = creds.Password - ac.IdentityToken = creds.IdentityToken - authConfigs[registry] = ac - } - - return authConfigs, nil -} - -// Store saves the given credentials in the file store. -func (c *nativeStore) Store(authConfig types.AuthConfig) error { - if err := c.storeCredentialsInStore(authConfig); err != nil { - return err - } - authConfig.Username = "" - authConfig.Password = "" - authConfig.IdentityToken = "" - - // Fallback to old credential in plain text to save only the email - return c.fileStore.Store(authConfig) -} - -// storeCredentialsInStore executes the command to store the credentials in the native store. -func (c *nativeStore) storeCredentialsInStore(config types.AuthConfig) error { - creds := &credentials.Credentials{ - ServerURL: config.ServerAddress, - Username: config.Username, - Secret: config.Password, - } - - if config.IdentityToken != "" { - creds.Username = tokenUsername - creds.Secret = config.IdentityToken - } - - return client.Store(c.programFunc, creds) -} - -// getCredentialsFromStore executes the command to get the credentials from the native store. -func (c *nativeStore) getCredentialsFromStore(serverAddress string) (types.AuthConfig, error) { - var ret types.AuthConfig - - creds, err := client.Get(c.programFunc, serverAddress) - if err != nil { - if credentials.IsErrCredentialsNotFound(err) { - // do not return an error if the credentials are not - // in the keyckain. Let docker ask for new credentials. - return ret, nil - } - return ret, err - } - - if creds.Username == tokenUsername { - ret.IdentityToken = creds.Secret - } else { - ret.Password = creds.Secret - ret.Username = creds.Username - } - - ret.ServerAddress = serverAddress - return ret, nil -} - -// listCredentialsInStore returns a listing of stored credentials as a map of -// URL -> username. -func (c *nativeStore) listCredentialsInStore() (map[string]string, error) { - return client.List(c.programFunc) -} diff --git a/vendor/github.com/docker/docker/cliconfig/credentials/native_store_test.go b/vendor/github.com/docker/docker/cliconfig/credentials/native_store_test.go deleted file mode 100644 index 7664faf..0000000 --- a/vendor/github.com/docker/docker/cliconfig/credentials/native_store_test.go +++ /dev/null @@ -1,355 +0,0 @@ -package credentials - -import ( - "encoding/json" - "fmt" - "io" - "io/ioutil" - "strings" - "testing" - - "github.com/docker/docker-credential-helpers/client" - "github.com/docker/docker-credential-helpers/credentials" - "github.com/docker/docker/api/types" -) - -const ( - validServerAddress = "https://index.docker.io/v1" - validServerAddress2 = "https://example.com:5002" - invalidServerAddress = "https://foobar.example.com" - missingCredsAddress = "https://missing.docker.io/v1" -) - -var errCommandExited = fmt.Errorf("exited 1") - -// mockCommand simulates interactions between the docker client and a remote -// credentials helper. -// Unit tests inject this mocked command into the remote to control execution. -type mockCommand struct { - arg string - input io.Reader -} - -// Output returns responses from the remote credentials helper. -// It mocks those responses based in the input in the mock. -func (m *mockCommand) Output() ([]byte, error) { - in, err := ioutil.ReadAll(m.input) - if err != nil { - return nil, err - } - inS := string(in) - - switch m.arg { - case "erase": - switch inS { - case validServerAddress: - return nil, nil - default: - return []byte("program failed"), errCommandExited - } - case "get": - switch inS { - case validServerAddress: - return []byte(`{"Username": "foo", "Secret": "bar"}`), nil - case validServerAddress2: - return []byte(`{"Username": "", "Secret": "abcd1234"}`), nil - case missingCredsAddress: - return []byte(credentials.NewErrCredentialsNotFound().Error()), errCommandExited - case invalidServerAddress: - return []byte("program failed"), errCommandExited - } - case "store": - var c credentials.Credentials - err := json.NewDecoder(strings.NewReader(inS)).Decode(&c) - if err != nil { - return []byte("program failed"), errCommandExited - } - switch c.ServerURL { - case validServerAddress: - return nil, nil - default: - return []byte("program failed"), errCommandExited - } - case "list": - return []byte(fmt.Sprintf(`{"%s": "%s", "%s": "%s"}`, validServerAddress, "foo", validServerAddress2, "")), nil - } - - return []byte(fmt.Sprintf("unknown argument %q with %q", m.arg, inS)), errCommandExited -} - -// Input sets the input to send to a remote credentials helper. -func (m *mockCommand) Input(in io.Reader) { - m.input = in -} - -func mockCommandFn(args ...string) client.Program { - return &mockCommand{ - arg: args[0], - } -} - -func TestNativeStoreAddCredentials(t *testing.T) { - f := newConfigFile(make(map[string]types.AuthConfig)) - f.CredentialsStore = "mock" - - s := &nativeStore{ - programFunc: mockCommandFn, - fileStore: NewFileStore(f), - } - err := s.Store(types.AuthConfig{ - Username: "foo", - Password: "bar", - Email: "foo@example.com", - ServerAddress: validServerAddress, - }) - - if err != nil { - t.Fatal(err) - } - - if len(f.AuthConfigs) != 1 { - t.Fatalf("expected 1 auth config, got %d", len(f.AuthConfigs)) - } - - a, ok := f.AuthConfigs[validServerAddress] - if !ok { - t.Fatalf("expected auth for %s, got %v", validServerAddress, f.AuthConfigs) - } - if a.Auth != "" { - t.Fatalf("expected auth to be empty, got %s", a.Auth) - } - if a.Username != "" { - t.Fatalf("expected username to be empty, got %s", a.Username) - } - if a.Password != "" { - t.Fatalf("expected password to be empty, got %s", a.Password) - } - if a.IdentityToken != "" { - t.Fatalf("expected identity token to be empty, got %s", a.IdentityToken) - } - if a.Email != "foo@example.com" { - t.Fatalf("expected email `foo@example.com`, got %s", a.Email) - } -} - -func TestNativeStoreAddInvalidCredentials(t *testing.T) { - f := newConfigFile(make(map[string]types.AuthConfig)) - f.CredentialsStore = "mock" - - s := &nativeStore{ - programFunc: mockCommandFn, - fileStore: NewFileStore(f), - } - err := s.Store(types.AuthConfig{ - Username: "foo", - Password: "bar", - Email: "foo@example.com", - ServerAddress: invalidServerAddress, - }) - - if err == nil { - t.Fatal("expected error, got nil") - } - - if !strings.Contains(err.Error(), "program failed") { - t.Fatalf("expected `program failed`, got %v", err) - } - - if len(f.AuthConfigs) != 0 { - t.Fatalf("expected 0 auth config, got %d", len(f.AuthConfigs)) - } -} - -func TestNativeStoreGet(t *testing.T) { - f := newConfigFile(map[string]types.AuthConfig{ - validServerAddress: { - Email: "foo@example.com", - }, - }) - f.CredentialsStore = "mock" - - s := &nativeStore{ - programFunc: mockCommandFn, - fileStore: NewFileStore(f), - } - a, err := s.Get(validServerAddress) - if err != nil { - t.Fatal(err) - } - - if a.Username != "foo" { - t.Fatalf("expected username `foo`, got %s", a.Username) - } - if a.Password != "bar" { - t.Fatalf("expected password `bar`, got %s", a.Password) - } - if a.IdentityToken != "" { - t.Fatalf("expected identity token to be empty, got %s", a.IdentityToken) - } - if a.Email != "foo@example.com" { - t.Fatalf("expected email `foo@example.com`, got %s", a.Email) - } -} - -func TestNativeStoreGetIdentityToken(t *testing.T) { - f := newConfigFile(map[string]types.AuthConfig{ - validServerAddress2: { - Email: "foo@example2.com", - }, - }) - f.CredentialsStore = "mock" - - s := &nativeStore{ - programFunc: mockCommandFn, - fileStore: NewFileStore(f), - } - a, err := s.Get(validServerAddress2) - if err != nil { - t.Fatal(err) - } - - if a.Username != "" { - t.Fatalf("expected username to be empty, got %s", a.Username) - } - if a.Password != "" { - t.Fatalf("expected password to be empty, got %s", a.Password) - } - if a.IdentityToken != "abcd1234" { - t.Fatalf("expected identity token `abcd1234`, got %s", a.IdentityToken) - } - if a.Email != "foo@example2.com" { - t.Fatalf("expected email `foo@example2.com`, got %s", a.Email) - } -} - -func TestNativeStoreGetAll(t *testing.T) { - f := newConfigFile(map[string]types.AuthConfig{ - validServerAddress: { - Email: "foo@example.com", - }, - }) - f.CredentialsStore = "mock" - - s := &nativeStore{ - programFunc: mockCommandFn, - fileStore: NewFileStore(f), - } - as, err := s.GetAll() - if err != nil { - t.Fatal(err) - } - - if len(as) != 2 { - t.Fatalf("wanted 2, got %d", len(as)) - } - - if as[validServerAddress].Username != "foo" { - t.Fatalf("expected username `foo` for %s, got %s", validServerAddress, as[validServerAddress].Username) - } - if as[validServerAddress].Password != "bar" { - t.Fatalf("expected password `bar` for %s, got %s", validServerAddress, as[validServerAddress].Password) - } - if as[validServerAddress].IdentityToken != "" { - t.Fatalf("expected identity to be empty for %s, got %s", validServerAddress, as[validServerAddress].IdentityToken) - } - if as[validServerAddress].Email != "foo@example.com" { - t.Fatalf("expected email `foo@example.com` for %s, got %s", validServerAddress, as[validServerAddress].Email) - } - if as[validServerAddress2].Username != "" { - t.Fatalf("expected username to be empty for %s, got %s", validServerAddress2, as[validServerAddress2].Username) - } - if as[validServerAddress2].Password != "" { - t.Fatalf("expected password to be empty for %s, got %s", validServerAddress2, as[validServerAddress2].Password) - } - if as[validServerAddress2].IdentityToken != "abcd1234" { - t.Fatalf("expected identity token `abcd1324` for %s, got %s", validServerAddress2, as[validServerAddress2].IdentityToken) - } - if as[validServerAddress2].Email != "" { - t.Fatalf("expected no email for %s, got %s", validServerAddress2, as[validServerAddress2].Email) - } -} - -func TestNativeStoreGetMissingCredentials(t *testing.T) { - f := newConfigFile(map[string]types.AuthConfig{ - validServerAddress: { - Email: "foo@example.com", - }, - }) - f.CredentialsStore = "mock" - - s := &nativeStore{ - programFunc: mockCommandFn, - fileStore: NewFileStore(f), - } - _, err := s.Get(missingCredsAddress) - if err != nil { - // missing credentials do not produce an error - t.Fatal(err) - } -} - -func TestNativeStoreGetInvalidAddress(t *testing.T) { - f := newConfigFile(map[string]types.AuthConfig{ - validServerAddress: { - Email: "foo@example.com", - }, - }) - f.CredentialsStore = "mock" - - s := &nativeStore{ - programFunc: mockCommandFn, - fileStore: NewFileStore(f), - } - _, err := s.Get(invalidServerAddress) - if err == nil { - t.Fatal("expected error, got nil") - } - - if !strings.Contains(err.Error(), "program failed") { - t.Fatalf("expected `program failed`, got %v", err) - } -} - -func TestNativeStoreErase(t *testing.T) { - f := newConfigFile(map[string]types.AuthConfig{ - validServerAddress: { - Email: "foo@example.com", - }, - }) - f.CredentialsStore = "mock" - - s := &nativeStore{ - programFunc: mockCommandFn, - fileStore: NewFileStore(f), - } - err := s.Erase(validServerAddress) - if err != nil { - t.Fatal(err) - } - - if len(f.AuthConfigs) != 0 { - t.Fatalf("expected 0 auth configs, got %d", len(f.AuthConfigs)) - } -} - -func TestNativeStoreEraseInvalidAddress(t *testing.T) { - f := newConfigFile(map[string]types.AuthConfig{ - validServerAddress: { - Email: "foo@example.com", - }, - }) - f.CredentialsStore = "mock" - - s := &nativeStore{ - programFunc: mockCommandFn, - fileStore: NewFileStore(f), - } - err := s.Erase(invalidServerAddress) - if err == nil { - t.Fatal("expected error, got nil") - } - - if !strings.Contains(err.Error(), "program failed") { - t.Fatalf("expected `program failed`, got %v", err) - } -} diff --git a/vendor/github.com/docker/docker/client/README.md b/vendor/github.com/docker/docker/client/README.md deleted file mode 100644 index 059dfb3..0000000 --- a/vendor/github.com/docker/docker/client/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Go client for the Docker Engine API - -The `docker` command uses this package to communicate with the daemon. It can also be used by your own Go applications to do anything the command-line interface does – running containers, pulling images, managing swarms, etc. - -For example, to list running containers (the equivalent of `docker ps`): - -```go -package main - -import ( - "context" - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/client" -) - -func main() { - cli, err := client.NewEnvClient() - if err != nil { - panic(err) - } - - containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{}) - if err != nil { - panic(err) - } - - for _, container := range containers { - fmt.Printf("%s %s\n", container.ID[:10], container.Image) - } -} -``` - -[Full documentation is available on GoDoc.](https://godoc.org/github.com/docker/docker/client) diff --git a/vendor/github.com/docker/docker/client/checkpoint_create.go b/vendor/github.com/docker/docker/client/checkpoint_create.go deleted file mode 100644 index 0effe49..0000000 --- a/vendor/github.com/docker/docker/client/checkpoint_create.go +++ /dev/null @@ -1,13 +0,0 @@ -package client - -import ( - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// CheckpointCreate creates a checkpoint from the given container with the given name -func (cli *Client) CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error { - resp, err := cli.post(ctx, "/containers/"+container+"/checkpoints", nil, options, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/checkpoint_create_test.go b/vendor/github.com/docker/docker/client/checkpoint_create_test.go deleted file mode 100644 index 96e5187..0000000 --- a/vendor/github.com/docker/docker/client/checkpoint_create_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestCheckpointCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.CheckpointCreate(context.Background(), "nothing", types.CheckpointCreateOptions{ - CheckpointID: "noting", - Exit: true, - }) - - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestCheckpointCreate(t *testing.T) { - expectedContainerID := "container_id" - expectedCheckpointID := "checkpoint_id" - expectedURL := "/containers/container_id/checkpoints" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - createOptions := &types.CheckpointCreateOptions{} - if err := json.NewDecoder(req.Body).Decode(createOptions); err != nil { - return nil, err - } - - if createOptions.CheckpointID != expectedCheckpointID { - return nil, fmt.Errorf("expected CheckpointID to be 'checkpoint_id', got %v", createOptions.CheckpointID) - } - - if !createOptions.Exit { - return nil, fmt.Errorf("expected Exit to be true") - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.CheckpointCreate(context.Background(), expectedContainerID, types.CheckpointCreateOptions{ - CheckpointID: expectedCheckpointID, - Exit: true, - }) - - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/checkpoint_delete.go b/vendor/github.com/docker/docker/client/checkpoint_delete.go deleted file mode 100644 index e6e7558..0000000 --- a/vendor/github.com/docker/docker/client/checkpoint_delete.go +++ /dev/null @@ -1,20 +0,0 @@ -package client - -import ( - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// CheckpointDelete deletes the checkpoint with the given name from the given container -func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options types.CheckpointDeleteOptions) error { - query := url.Values{} - if options.CheckpointDir != "" { - query.Set("dir", options.CheckpointDir) - } - - resp, err := cli.delete(ctx, "/containers/"+containerID+"/checkpoints/"+options.CheckpointID, query, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/checkpoint_delete_test.go b/vendor/github.com/docker/docker/client/checkpoint_delete_test.go deleted file mode 100644 index a78b050..0000000 --- a/vendor/github.com/docker/docker/client/checkpoint_delete_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestCheckpointDeleteError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{ - CheckpointID: "checkpoint_id", - }) - - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestCheckpointDelete(t *testing.T) { - expectedURL := "/containers/container_id/checkpoints/checkpoint_id" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{ - CheckpointID: "checkpoint_id", - }) - - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/checkpoint_list.go b/vendor/github.com/docker/docker/client/checkpoint_list.go deleted file mode 100644 index 8eb720a..0000000 --- a/vendor/github.com/docker/docker/client/checkpoint_list.go +++ /dev/null @@ -1,28 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// CheckpointList returns the volumes configured in the docker host. -func (cli *Client) CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) { - var checkpoints []types.Checkpoint - - query := url.Values{} - if options.CheckpointDir != "" { - query.Set("dir", options.CheckpointDir) - } - - resp, err := cli.get(ctx, "/containers/"+container+"/checkpoints", query, nil) - if err != nil { - return checkpoints, err - } - - err = json.NewDecoder(resp.body).Decode(&checkpoints) - ensureReaderClosed(resp) - return checkpoints, err -} diff --git a/vendor/github.com/docker/docker/client/checkpoint_list_test.go b/vendor/github.com/docker/docker/client/checkpoint_list_test.go deleted file mode 100644 index 6c90f61..0000000 --- a/vendor/github.com/docker/docker/client/checkpoint_list_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestCheckpointListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestCheckpointList(t *testing.T) { - expectedURL := "/containers/container_id/checkpoints" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - content, err := json.Marshal([]types.Checkpoint{ - { - Name: "checkpoint", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - checkpoints, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{}) - if err != nil { - t.Fatal(err) - } - if len(checkpoints) != 1 { - t.Fatalf("expected 1 checkpoint, got %v", checkpoints) - } -} diff --git a/vendor/github.com/docker/docker/client/client.go b/vendor/github.com/docker/docker/client/client.go deleted file mode 100644 index a9bdab6..0000000 --- a/vendor/github.com/docker/docker/client/client.go +++ /dev/null @@ -1,246 +0,0 @@ -/* -Package client is a Go client for the Docker Engine API. - -The "docker" command uses this package to communicate with the daemon. It can also -be used by your own Go applications to do anything the command-line interface does -– running containers, pulling images, managing swarms, etc. - -For more information about the Engine API, see the documentation: -https://docs.docker.com/engine/reference/api/ - -Usage - -You use the library by creating a client object and calling methods on it. The -client can be created either from environment variables with NewEnvClient, or -configured manually with NewClient. - -For example, to list running containers (the equivalent of "docker ps"): - - package main - - import ( - "context" - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/client" - ) - - func main() { - cli, err := client.NewEnvClient() - if err != nil { - panic(err) - } - - containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{}) - if err != nil { - panic(err) - } - - for _, container := range containers { - fmt.Printf("%s %s\n", container.ID[:10], container.Image) - } - } - -*/ -package client - -import ( - "fmt" - "net/http" - "net/url" - "os" - "path/filepath" - "strings" - - "github.com/docker/go-connections/sockets" - "github.com/docker/go-connections/tlsconfig" -) - -// DefaultVersion is the version of the current stable API -const DefaultVersion string = "1.25" - -// Client is the API client that performs all operations -// against a docker server. -type Client struct { - // scheme sets the scheme for the client - scheme string - // host holds the server address to connect to - host string - // proto holds the client protocol i.e. unix. - proto string - // addr holds the client address. - addr string - // basePath holds the path to prepend to the requests. - basePath string - // client used to send and receive http requests. - client *http.Client - // version of the server to talk to. - version string - // custom http headers configured by users. - customHTTPHeaders map[string]string - // manualOverride is set to true when the version was set by users. - manualOverride bool -} - -// NewEnvClient initializes a new API client based on environment variables. -// Use DOCKER_HOST to set the url to the docker server. -// Use DOCKER_API_VERSION to set the version of the API to reach, leave empty for latest. -// Use DOCKER_CERT_PATH to load the tls certificates from. -// Use DOCKER_TLS_VERIFY to enable or disable TLS verification, off by default. -func NewEnvClient() (*Client, error) { - var client *http.Client - if dockerCertPath := os.Getenv("DOCKER_CERT_PATH"); dockerCertPath != "" { - options := tlsconfig.Options{ - CAFile: filepath.Join(dockerCertPath, "ca.pem"), - CertFile: filepath.Join(dockerCertPath, "cert.pem"), - KeyFile: filepath.Join(dockerCertPath, "key.pem"), - InsecureSkipVerify: os.Getenv("DOCKER_TLS_VERIFY") == "", - } - tlsc, err := tlsconfig.Client(options) - if err != nil { - return nil, err - } - - client = &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: tlsc, - }, - } - } - - host := os.Getenv("DOCKER_HOST") - if host == "" { - host = DefaultDockerHost - } - version := os.Getenv("DOCKER_API_VERSION") - if version == "" { - version = DefaultVersion - } - - cli, err := NewClient(host, version, client, nil) - if err != nil { - return cli, err - } - if os.Getenv("DOCKER_API_VERSION") != "" { - cli.manualOverride = true - } - return cli, nil -} - -// NewClient initializes a new API client for the given host and API version. -// It uses the given http client as transport. -// It also initializes the custom http headers to add to each request. -// -// It won't send any version information if the version number is empty. It is -// highly recommended that you set a version or your client may break if the -// server is upgraded. -func NewClient(host string, version string, client *http.Client, httpHeaders map[string]string) (*Client, error) { - proto, addr, basePath, err := ParseHost(host) - if err != nil { - return nil, err - } - - if client != nil { - if _, ok := client.Transport.(*http.Transport); !ok { - return nil, fmt.Errorf("unable to verify TLS configuration, invalid transport %v", client.Transport) - } - } else { - transport := new(http.Transport) - sockets.ConfigureTransport(transport, proto, addr) - client = &http.Client{ - Transport: transport, - } - } - - scheme := "http" - tlsConfig := resolveTLSConfig(client.Transport) - if tlsConfig != nil { - // TODO(stevvooe): This isn't really the right way to write clients in Go. - // `NewClient` should probably only take an `*http.Client` and work from there. - // Unfortunately, the model of having a host-ish/url-thingy as the connection - // string has us confusing protocol and transport layers. We continue doing - // this to avoid breaking existing clients but this should be addressed. - scheme = "https" - } - - return &Client{ - scheme: scheme, - host: host, - proto: proto, - addr: addr, - basePath: basePath, - client: client, - version: version, - customHTTPHeaders: httpHeaders, - }, nil -} - -// Close ensures that transport.Client is closed -// especially needed while using NewClient with *http.Client = nil -// for example -// client.NewClient("unix:///var/run/docker.sock", nil, "v1.18", map[string]string{"User-Agent": "engine-api-cli-1.0"}) -func (cli *Client) Close() error { - - if t, ok := cli.client.Transport.(*http.Transport); ok { - t.CloseIdleConnections() - } - - return nil -} - -// getAPIPath returns the versioned request path to call the api. -// It appends the query parameters to the path if they are not empty. -func (cli *Client) getAPIPath(p string, query url.Values) string { - var apiPath string - if cli.version != "" { - v := strings.TrimPrefix(cli.version, "v") - apiPath = fmt.Sprintf("%s/v%s%s", cli.basePath, v, p) - } else { - apiPath = fmt.Sprintf("%s%s", cli.basePath, p) - } - - u := &url.URL{ - Path: apiPath, - } - if len(query) > 0 { - u.RawQuery = query.Encode() - } - return u.String() -} - -// ClientVersion returns the version string associated with this -// instance of the Client. Note that this value can be changed -// via the DOCKER_API_VERSION env var. -func (cli *Client) ClientVersion() string { - return cli.version -} - -// UpdateClientVersion updates the version string associated with this -// instance of the Client. -func (cli *Client) UpdateClientVersion(v string) { - if !cli.manualOverride { - cli.version = v - } - -} - -// ParseHost verifies that the given host strings is valid. -func ParseHost(host string) (string, string, string, error) { - protoAddrParts := strings.SplitN(host, "://", 2) - if len(protoAddrParts) == 1 { - return "", "", "", fmt.Errorf("unable to parse docker host `%s`", host) - } - - var basePath string - proto, addr := protoAddrParts[0], protoAddrParts[1] - if proto == "tcp" { - parsed, err := url.Parse("tcp://" + addr) - if err != nil { - return "", "", "", err - } - addr = parsed.Host - basePath = parsed.Path - } - return proto, addr, basePath, nil -} diff --git a/vendor/github.com/docker/docker/client/client_mock_test.go b/vendor/github.com/docker/docker/client/client_mock_test.go deleted file mode 100644 index 0ab935d..0000000 --- a/vendor/github.com/docker/docker/client/client_mock_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/docker/docker/api/types" -) - -func newMockClient(doer func(*http.Request) (*http.Response, error)) *http.Client { - return &http.Client{ - Transport: transportFunc(doer), - } -} - -func errorMock(statusCode int, message string) func(req *http.Request) (*http.Response, error) { - return func(req *http.Request) (*http.Response, error) { - header := http.Header{} - header.Set("Content-Type", "application/json") - - body, err := json.Marshal(&types.ErrorResponse{ - Message: message, - }) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: statusCode, - Body: ioutil.NopCloser(bytes.NewReader(body)), - Header: header, - }, nil - } -} - -func plainTextErrorMock(statusCode int, message string) func(req *http.Request) (*http.Response, error) { - return func(req *http.Request) (*http.Response, error) { - return &http.Response{ - StatusCode: statusCode, - Body: ioutil.NopCloser(bytes.NewReader([]byte(message))), - }, nil - } -} diff --git a/vendor/github.com/docker/docker/client/client_test.go b/vendor/github.com/docker/docker/client/client_test.go deleted file mode 100644 index ee199c2..0000000 --- a/vendor/github.com/docker/docker/client/client_test.go +++ /dev/null @@ -1,283 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - "net/url" - "os" - "runtime" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestNewEnvClient(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("skipping unix only test for windows") - } - cases := []struct { - envs map[string]string - expectedError string - expectedVersion string - }{ - { - envs: map[string]string{}, - expectedVersion: DefaultVersion, - }, - { - envs: map[string]string{ - "DOCKER_CERT_PATH": "invalid/path", - }, - expectedError: "Could not load X509 key pair: open invalid/path/cert.pem: no such file or directory. Make sure the key is not encrypted", - }, - { - envs: map[string]string{ - "DOCKER_CERT_PATH": "testdata/", - }, - expectedVersion: DefaultVersion, - }, - { - envs: map[string]string{ - "DOCKER_CERT_PATH": "testdata/", - "DOCKER_TLS_VERIFY": "1", - }, - expectedVersion: DefaultVersion, - }, - { - envs: map[string]string{ - "DOCKER_CERT_PATH": "testdata/", - "DOCKER_HOST": "https://notaunixsocket", - }, - expectedVersion: DefaultVersion, - }, - { - envs: map[string]string{ - "DOCKER_HOST": "host", - }, - expectedError: "unable to parse docker host `host`", - }, - { - envs: map[string]string{ - "DOCKER_HOST": "invalid://url", - }, - expectedVersion: DefaultVersion, - }, - { - envs: map[string]string{ - "DOCKER_API_VERSION": "anything", - }, - expectedVersion: "anything", - }, - { - envs: map[string]string{ - "DOCKER_API_VERSION": "1.22", - }, - expectedVersion: "1.22", - }, - } - for _, c := range cases { - recoverEnvs := setupEnvs(t, c.envs) - apiclient, err := NewEnvClient() - if c.expectedError != "" { - if err == nil { - t.Errorf("expected an error for %v", c) - } else if err.Error() != c.expectedError { - t.Errorf("expected an error %s, got %s, for %v", c.expectedError, err.Error(), c) - } - } else { - if err != nil { - t.Error(err) - } - version := apiclient.ClientVersion() - if version != c.expectedVersion { - t.Errorf("expected %s, got %s, for %v", c.expectedVersion, version, c) - } - } - - if c.envs["DOCKER_TLS_VERIFY"] != "" { - // pedantic checking that this is handled correctly - tr := apiclient.client.Transport.(*http.Transport) - if tr.TLSClientConfig == nil { - t.Errorf("no tls config found when DOCKER_TLS_VERIFY enabled") - } - - if tr.TLSClientConfig.InsecureSkipVerify { - t.Errorf("tls verification should be enabled") - } - } - - recoverEnvs(t) - } -} - -func setupEnvs(t *testing.T, envs map[string]string) func(*testing.T) { - oldEnvs := map[string]string{} - for key, value := range envs { - oldEnv := os.Getenv(key) - oldEnvs[key] = oldEnv - err := os.Setenv(key, value) - if err != nil { - t.Error(err) - } - } - return func(t *testing.T) { - for key, value := range oldEnvs { - err := os.Setenv(key, value) - if err != nil { - t.Error(err) - } - } - } -} - -func TestGetAPIPath(t *testing.T) { - cases := []struct { - v string - p string - q url.Values - e string - }{ - {"", "/containers/json", nil, "/containers/json"}, - {"", "/containers/json", url.Values{}, "/containers/json"}, - {"", "/containers/json", url.Values{"s": []string{"c"}}, "/containers/json?s=c"}, - {"1.22", "/containers/json", nil, "/v1.22/containers/json"}, - {"1.22", "/containers/json", url.Values{}, "/v1.22/containers/json"}, - {"1.22", "/containers/json", url.Values{"s": []string{"c"}}, "/v1.22/containers/json?s=c"}, - {"v1.22", "/containers/json", nil, "/v1.22/containers/json"}, - {"v1.22", "/containers/json", url.Values{}, "/v1.22/containers/json"}, - {"v1.22", "/containers/json", url.Values{"s": []string{"c"}}, "/v1.22/containers/json?s=c"}, - {"v1.22", "/networks/kiwl$%^", nil, "/v1.22/networks/kiwl$%25%5E"}, - } - - for _, cs := range cases { - c, err := NewClient("unix:///var/run/docker.sock", cs.v, nil, nil) - if err != nil { - t.Fatal(err) - } - g := c.getAPIPath(cs.p, cs.q) - if g != cs.e { - t.Fatalf("Expected %s, got %s", cs.e, g) - } - - err = c.Close() - if nil != err { - t.Fatalf("close client failed, error message: %s", err) - } - } -} - -func TestParseHost(t *testing.T) { - cases := []struct { - host string - proto string - addr string - base string - err bool - }{ - {"", "", "", "", true}, - {"foobar", "", "", "", true}, - {"foo://bar", "foo", "bar", "", false}, - {"tcp://localhost:2476", "tcp", "localhost:2476", "", false}, - {"tcp://localhost:2476/path", "tcp", "localhost:2476", "/path", false}, - } - - for _, cs := range cases { - p, a, b, e := ParseHost(cs.host) - if cs.err && e == nil { - t.Fatalf("expected error, got nil") - } - if !cs.err && e != nil { - t.Fatal(e) - } - if cs.proto != p { - t.Fatalf("expected proto %s, got %s", cs.proto, p) - } - if cs.addr != a { - t.Fatalf("expected addr %s, got %s", cs.addr, a) - } - if cs.base != b { - t.Fatalf("expected base %s, got %s", cs.base, b) - } - } -} - -func TestUpdateClientVersion(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - splitQuery := strings.Split(req.URL.Path, "/") - queryVersion := splitQuery[1] - b, err := json.Marshal(types.Version{ - APIVersion: queryVersion, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - cases := []struct { - v string - }{ - {"1.20"}, - {"v1.21"}, - {"1.22"}, - {"v1.22"}, - } - - for _, cs := range cases { - client.UpdateClientVersion(cs.v) - r, err := client.ServerVersion(context.Background()) - if err != nil { - t.Fatal(err) - } - if strings.TrimPrefix(r.APIVersion, "v") != strings.TrimPrefix(cs.v, "v") { - t.Fatalf("Expected %s, got %s", cs.v, r.APIVersion) - } - } -} - -func TestNewEnvClientSetsDefaultVersion(t *testing.T) { - // Unset environment variables - envVarKeys := []string{ - "DOCKER_HOST", - "DOCKER_API_VERSION", - "DOCKER_TLS_VERIFY", - "DOCKER_CERT_PATH", - } - envVarValues := make(map[string]string) - for _, key := range envVarKeys { - envVarValues[key] = os.Getenv(key) - os.Setenv(key, "") - } - - client, err := NewEnvClient() - if err != nil { - t.Fatal(err) - } - if client.version != DefaultVersion { - t.Fatalf("Expected %s, got %s", DefaultVersion, client.version) - } - - expected := "1.22" - os.Setenv("DOCKER_API_VERSION", expected) - client, err = NewEnvClient() - if err != nil { - t.Fatal(err) - } - if client.version != expected { - t.Fatalf("Expected %s, got %s", expected, client.version) - } - - // Restore environment variables - for _, key := range envVarKeys { - os.Setenv(key, envVarValues[key]) - } -} diff --git a/vendor/github.com/docker/docker/client/client_unix.go b/vendor/github.com/docker/docker/client/client_unix.go deleted file mode 100644 index 89de892..0000000 --- a/vendor/github.com/docker/docker/client/client_unix.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build linux freebsd solaris openbsd darwin - -package client - -// DefaultDockerHost defines os specific default if DOCKER_HOST is unset -const DefaultDockerHost = "unix:///var/run/docker.sock" diff --git a/vendor/github.com/docker/docker/client/client_windows.go b/vendor/github.com/docker/docker/client/client_windows.go deleted file mode 100644 index 07c0c7a..0000000 --- a/vendor/github.com/docker/docker/client/client_windows.go +++ /dev/null @@ -1,4 +0,0 @@ -package client - -// DefaultDockerHost defines os specific default if DOCKER_HOST is unset -const DefaultDockerHost = "npipe:////./pipe/docker_engine" diff --git a/vendor/github.com/docker/docker/client/container_attach.go b/vendor/github.com/docker/docker/client/container_attach.go deleted file mode 100644 index eea4682..0000000 --- a/vendor/github.com/docker/docker/client/container_attach.go +++ /dev/null @@ -1,37 +0,0 @@ -package client - -import ( - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ContainerAttach attaches a connection to a container in the server. -// It returns a types.HijackedConnection with the hijacked connection -// and the a reader to get output. It's up to the called to close -// the hijacked connection by calling types.HijackedResponse.Close. -func (cli *Client) ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) { - query := url.Values{} - if options.Stream { - query.Set("stream", "1") - } - if options.Stdin { - query.Set("stdin", "1") - } - if options.Stdout { - query.Set("stdout", "1") - } - if options.Stderr { - query.Set("stderr", "1") - } - if options.DetachKeys != "" { - query.Set("detachKeys", options.DetachKeys) - } - if options.Logs { - query.Set("logs", "1") - } - - headers := map[string][]string{"Content-Type": {"text/plain"}} - return cli.postHijacked(ctx, "/containers/"+container+"/attach", query, nil, headers) -} diff --git a/vendor/github.com/docker/docker/client/container_commit.go b/vendor/github.com/docker/docker/client/container_commit.go deleted file mode 100644 index c766d62..0000000 --- a/vendor/github.com/docker/docker/client/container_commit.go +++ /dev/null @@ -1,53 +0,0 @@ -package client - -import ( - "encoding/json" - "errors" - "net/url" - - distreference "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/reference" - "golang.org/x/net/context" -) - -// ContainerCommit applies changes into a container and creates a new tagged image. -func (cli *Client) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error) { - var repository, tag string - if options.Reference != "" { - distributionRef, err := distreference.ParseNamed(options.Reference) - if err != nil { - return types.IDResponse{}, err - } - - if _, isCanonical := distributionRef.(distreference.Canonical); isCanonical { - return types.IDResponse{}, errors.New("refusing to create a tag with a digest reference") - } - - tag = reference.GetTagFromNamedRef(distributionRef) - repository = distributionRef.Name() - } - - query := url.Values{} - query.Set("container", container) - query.Set("repo", repository) - query.Set("tag", tag) - query.Set("comment", options.Comment) - query.Set("author", options.Author) - for _, change := range options.Changes { - query.Add("changes", change) - } - if options.Pause != true { - query.Set("pause", "0") - } - - var response types.IDResponse - resp, err := cli.post(ctx, "/commit", query, options.Config, nil) - if err != nil { - return response, err - } - - err = json.NewDecoder(resp.body).Decode(&response) - ensureReaderClosed(resp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/container_commit_test.go b/vendor/github.com/docker/docker/client/container_commit_test.go deleted file mode 100644 index a844675..0000000 --- a/vendor/github.com/docker/docker/client/container_commit_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestContainerCommitError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerCommit(context.Background(), "nothing", types.ContainerCommitOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerCommit(t *testing.T) { - expectedURL := "/commit" - expectedContainerID := "container_id" - specifiedReference := "repository_name:tag" - expectedRepositoryName := "repository_name" - expectedTag := "tag" - expectedComment := "comment" - expectedAuthor := "author" - expectedChanges := []string{"change1", "change2"} - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - containerID := query.Get("container") - if containerID != expectedContainerID { - return nil, fmt.Errorf("container id not set in URL query properly. Expected '%s', got %s", expectedContainerID, containerID) - } - repo := query.Get("repo") - if repo != expectedRepositoryName { - return nil, fmt.Errorf("container repo not set in URL query properly. Expected '%s', got %s", expectedRepositoryName, repo) - } - tag := query.Get("tag") - if tag != expectedTag { - return nil, fmt.Errorf("container tag not set in URL query properly. Expected '%s', got %s'", expectedTag, tag) - } - comment := query.Get("comment") - if comment != expectedComment { - return nil, fmt.Errorf("container comment not set in URL query properly. Expected '%s', got %s'", expectedComment, comment) - } - author := query.Get("author") - if author != expectedAuthor { - return nil, fmt.Errorf("container author not set in URL query properly. Expected '%s', got %s'", expectedAuthor, author) - } - pause := query.Get("pause") - if pause != "0" { - return nil, fmt.Errorf("container pause not set in URL query properly. Expected 'true', got %v'", pause) - } - changes := query["changes"] - if len(changes) != len(expectedChanges) { - return nil, fmt.Errorf("expected container changes size to be '%d', got %d", len(expectedChanges), len(changes)) - } - b, err := json.Marshal(types.IDResponse{ - ID: "new_container_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - r, err := client.ContainerCommit(context.Background(), expectedContainerID, types.ContainerCommitOptions{ - Reference: specifiedReference, - Comment: expectedComment, - Author: expectedAuthor, - Changes: expectedChanges, - Pause: false, - }) - if err != nil { - t.Fatal(err) - } - if r.ID != "new_container_id" { - t.Fatalf("expected `container_id`, got %s", r.ID) - } -} diff --git a/vendor/github.com/docker/docker/client/container_copy.go b/vendor/github.com/docker/docker/client/container_copy.go deleted file mode 100644 index 8380eea..0000000 --- a/vendor/github.com/docker/docker/client/container_copy.go +++ /dev/null @@ -1,97 +0,0 @@ -package client - -import ( - "encoding/base64" - "encoding/json" - "fmt" - "io" - "net/http" - "net/url" - "path/filepath" - "strings" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -// ContainerStatPath returns Stat information about a path inside the container filesystem. -func (cli *Client) ContainerStatPath(ctx context.Context, containerID, path string) (types.ContainerPathStat, error) { - query := url.Values{} - query.Set("path", filepath.ToSlash(path)) // Normalize the paths used in the API. - - urlStr := fmt.Sprintf("/containers/%s/archive", containerID) - response, err := cli.head(ctx, urlStr, query, nil) - if err != nil { - return types.ContainerPathStat{}, err - } - defer ensureReaderClosed(response) - return getContainerPathStatFromHeader(response.header) -} - -// CopyToContainer copies content into the container filesystem. -func (cli *Client) CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error { - query := url.Values{} - query.Set("path", filepath.ToSlash(path)) // Normalize the paths used in the API. - // Do not allow for an existing directory to be overwritten by a non-directory and vice versa. - if !options.AllowOverwriteDirWithFile { - query.Set("noOverwriteDirNonDir", "true") - } - - apiPath := fmt.Sprintf("/containers/%s/archive", container) - - response, err := cli.putRaw(ctx, apiPath, query, content, nil) - if err != nil { - return err - } - defer ensureReaderClosed(response) - - if response.statusCode != http.StatusOK { - return fmt.Errorf("unexpected status code from daemon: %d", response.statusCode) - } - - return nil -} - -// CopyFromContainer gets the content from the container and returns it as a Reader -// to manipulate it in the host. It's up to the caller to close the reader. -func (cli *Client) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) { - query := make(url.Values, 1) - query.Set("path", filepath.ToSlash(srcPath)) // Normalize the paths used in the API. - - apiPath := fmt.Sprintf("/containers/%s/archive", container) - response, err := cli.get(ctx, apiPath, query, nil) - if err != nil { - return nil, types.ContainerPathStat{}, err - } - - if response.statusCode != http.StatusOK { - return nil, types.ContainerPathStat{}, fmt.Errorf("unexpected status code from daemon: %d", response.statusCode) - } - - // In order to get the copy behavior right, we need to know information - // about both the source and the destination. The response headers include - // stat info about the source that we can use in deciding exactly how to - // copy it locally. Along with the stat info about the local destination, - // we have everything we need to handle the multiple possibilities there - // can be when copying a file/dir from one location to another file/dir. - stat, err := getContainerPathStatFromHeader(response.header) - if err != nil { - return nil, stat, fmt.Errorf("unable to get resource stat from response: %s", err) - } - return response.body, stat, err -} - -func getContainerPathStatFromHeader(header http.Header) (types.ContainerPathStat, error) { - var stat types.ContainerPathStat - - encodedStat := header.Get("X-Docker-Container-Path-Stat") - statDecoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(encodedStat)) - - err := json.NewDecoder(statDecoder).Decode(&stat) - if err != nil { - err = fmt.Errorf("unable to decode container path stat header: %s", err) - } - - return stat, err -} diff --git a/vendor/github.com/docker/docker/client/container_copy_test.go b/vendor/github.com/docker/docker/client/container_copy_test.go deleted file mode 100644 index 706a20c..0000000 --- a/vendor/github.com/docker/docker/client/container_copy_test.go +++ /dev/null @@ -1,244 +0,0 @@ -package client - -import ( - "bytes" - "encoding/base64" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestContainerStatPathError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerStatPath(context.Background(), "container_id", "path") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestContainerStatPathNoHeaderError(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - _, err := client.ContainerStatPath(context.Background(), "container_id", "path/to/file") - if err == nil { - t.Fatalf("expected an error, got nothing") - } -} - -func TestContainerStatPath(t *testing.T) { - expectedURL := "/containers/container_id/archive" - expectedPath := "path/to/file" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "HEAD" { - return nil, fmt.Errorf("expected HEAD method, got %s", req.Method) - } - query := req.URL.Query() - path := query.Get("path") - if path != expectedPath { - return nil, fmt.Errorf("path not set in URL query properly") - } - content, err := json.Marshal(types.ContainerPathStat{ - Name: "name", - Mode: 0700, - }) - if err != nil { - return nil, err - } - base64PathStat := base64.StdEncoding.EncodeToString(content) - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - Header: http.Header{ - "X-Docker-Container-Path-Stat": []string{base64PathStat}, - }, - }, nil - }), - } - stat, err := client.ContainerStatPath(context.Background(), "container_id", expectedPath) - if err != nil { - t.Fatal(err) - } - if stat.Name != "name" { - t.Fatalf("expected container path stat name to be 'name', got '%s'", stat.Name) - } - if stat.Mode != 0700 { - t.Fatalf("expected container path stat mode to be 0700, got '%v'", stat.Mode) - } -} - -func TestCopyToContainerError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestCopyToContainerNotStatusOKError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNoContent, "No content")), - } - err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{}) - if err == nil || err.Error() != "unexpected status code from daemon: 204" { - t.Fatalf("expected an unexpected status code error, got %v", err) - } -} - -func TestCopyToContainer(t *testing.T) { - expectedURL := "/containers/container_id/archive" - expectedPath := "path/to/file" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "PUT" { - return nil, fmt.Errorf("expected PUT method, got %s", req.Method) - } - query := req.URL.Query() - path := query.Get("path") - if path != expectedPath { - return nil, fmt.Errorf("path not set in URL query properly, expected '%s', got %s", expectedPath, path) - } - noOverwriteDirNonDir := query.Get("noOverwriteDirNonDir") - if noOverwriteDirNonDir != "true" { - return nil, fmt.Errorf("noOverwriteDirNonDir not set in URL query properly, expected true, got %s", noOverwriteDirNonDir) - } - - content, err := ioutil.ReadAll(req.Body) - if err != nil { - return nil, err - } - if err := req.Body.Close(); err != nil { - return nil, err - } - if string(content) != "content" { - return nil, fmt.Errorf("expected content to be 'content', got %s", string(content)) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - err := client.CopyToContainer(context.Background(), "container_id", expectedPath, bytes.NewReader([]byte("content")), types.CopyToContainerOptions{ - AllowOverwriteDirWithFile: false, - }) - if err != nil { - t.Fatal(err) - } -} - -func TestCopyFromContainerError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, _, err := client.CopyFromContainer(context.Background(), "container_id", "path/to/file") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestCopyFromContainerNotStatusOKError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNoContent, "No content")), - } - _, _, err := client.CopyFromContainer(context.Background(), "container_id", "path/to/file") - if err == nil || err.Error() != "unexpected status code from daemon: 204" { - t.Fatalf("expected an unexpected status code error, got %v", err) - } -} - -func TestCopyFromContainerNoHeaderError(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - _, _, err := client.CopyFromContainer(context.Background(), "container_id", "path/to/file") - if err == nil { - t.Fatalf("expected an error, got nothing") - } -} - -func TestCopyFromContainer(t *testing.T) { - expectedURL := "/containers/container_id/archive" - expectedPath := "path/to/file" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "GET" { - return nil, fmt.Errorf("expected PUT method, got %s", req.Method) - } - query := req.URL.Query() - path := query.Get("path") - if path != expectedPath { - return nil, fmt.Errorf("path not set in URL query properly, expected '%s', got %s", expectedPath, path) - } - - headercontent, err := json.Marshal(types.ContainerPathStat{ - Name: "name", - Mode: 0700, - }) - if err != nil { - return nil, err - } - base64PathStat := base64.StdEncoding.EncodeToString(headercontent) - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("content"))), - Header: http.Header{ - "X-Docker-Container-Path-Stat": []string{base64PathStat}, - }, - }, nil - }), - } - r, stat, err := client.CopyFromContainer(context.Background(), "container_id", expectedPath) - if err != nil { - t.Fatal(err) - } - if stat.Name != "name" { - t.Fatalf("expected container path stat name to be 'name', got '%s'", stat.Name) - } - if stat.Mode != 0700 { - t.Fatalf("expected container path stat mode to be 0700, got '%v'", stat.Mode) - } - content, err := ioutil.ReadAll(r) - if err != nil { - t.Fatal(err) - } - if err := r.Close(); err != nil { - t.Fatal(err) - } - if string(content) != "content" { - t.Fatalf("expected content to be 'content', got %s", string(content)) - } -} diff --git a/vendor/github.com/docker/docker/client/container_create.go b/vendor/github.com/docker/docker/client/container_create.go deleted file mode 100644 index 9f627aa..0000000 --- a/vendor/github.com/docker/docker/client/container_create.go +++ /dev/null @@ -1,50 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - "strings" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/network" - "golang.org/x/net/context" -) - -type configWrapper struct { - *container.Config - HostConfig *container.HostConfig - NetworkingConfig *network.NetworkingConfig -} - -// ContainerCreate creates a new container based in the given configuration. -// It can be associated with a name, but it's not mandatory. -func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) { - var response container.ContainerCreateCreatedBody - - if err := cli.NewVersionError("1.25", "stop timeout"); config != nil && config.StopTimeout != nil && err != nil { - return response, err - } - - query := url.Values{} - if containerName != "" { - query.Set("name", containerName) - } - - body := configWrapper{ - Config: config, - HostConfig: hostConfig, - NetworkingConfig: networkingConfig, - } - - serverResp, err := cli.post(ctx, "/containers/create", query, body, nil) - if err != nil { - if serverResp.statusCode == 404 && strings.Contains(err.Error(), "No such image") { - return response, imageNotFoundError{config.Image} - } - return response, err - } - - err = json.NewDecoder(serverResp.body).Decode(&response) - ensureReaderClosed(serverResp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/container_create_test.go b/vendor/github.com/docker/docker/client/container_create_test.go deleted file mode 100644 index 15dbd5e..0000000 --- a/vendor/github.com/docker/docker/client/container_create_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/container" - "golang.org/x/net/context" -) - -func TestContainerCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerCreate(context.Background(), nil, nil, nil, "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error while testing StatusInternalServerError, got %v", err) - } - - // 404 doesn't automagitally means an unknown image - client = &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - _, err = client.ContainerCreate(context.Background(), nil, nil, nil, "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error while testing StatusNotFound, got %v", err) - } -} - -func TestContainerCreateImageNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "No such image")), - } - _, err := client.ContainerCreate(context.Background(), &container.Config{Image: "unknown_image"}, nil, nil, "unknown") - if err == nil || !IsErrImageNotFound(err) { - t.Fatalf("expected an imageNotFound error, got %v", err) - } -} - -func TestContainerCreateWithName(t *testing.T) { - expectedURL := "/containers/create" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - name := req.URL.Query().Get("name") - if name != "container_name" { - return nil, fmt.Errorf("container name not set in URL query properly. Expected `container_name`, got %s", name) - } - b, err := json.Marshal(container.ContainerCreateCreatedBody{ - ID: "container_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - r, err := client.ContainerCreate(context.Background(), nil, nil, nil, "container_name") - if err != nil { - t.Fatal(err) - } - if r.ID != "container_id" { - t.Fatalf("expected `container_id`, got %s", r.ID) - } -} diff --git a/vendor/github.com/docker/docker/client/container_diff.go b/vendor/github.com/docker/docker/client/container_diff.go deleted file mode 100644 index 1e3e554..0000000 --- a/vendor/github.com/docker/docker/client/container_diff.go +++ /dev/null @@ -1,23 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ContainerDiff shows differences in a container filesystem since it was started. -func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]types.ContainerChange, error) { - var changes []types.ContainerChange - - serverResp, err := cli.get(ctx, "/containers/"+containerID+"/changes", url.Values{}, nil) - if err != nil { - return changes, err - } - - err = json.NewDecoder(serverResp.body).Decode(&changes) - ensureReaderClosed(serverResp) - return changes, err -} diff --git a/vendor/github.com/docker/docker/client/container_diff_test.go b/vendor/github.com/docker/docker/client/container_diff_test.go deleted file mode 100644 index 1ce1117..0000000 --- a/vendor/github.com/docker/docker/client/container_diff_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestContainerDiffError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerDiff(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } - -} - -func TestContainerDiff(t *testing.T) { - expectedURL := "/containers/container_id/changes" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - b, err := json.Marshal([]types.ContainerChange{ - { - Kind: 0, - Path: "/path/1", - }, - { - Kind: 1, - Path: "/path/2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - changes, err := client.ContainerDiff(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - if len(changes) != 2 { - t.Fatalf("expected an array of 2 changes, got %v", changes) - } -} diff --git a/vendor/github.com/docker/docker/client/container_exec.go b/vendor/github.com/docker/docker/client/container_exec.go deleted file mode 100644 index 0665c54..0000000 --- a/vendor/github.com/docker/docker/client/container_exec.go +++ /dev/null @@ -1,54 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ContainerExecCreate creates a new exec configuration to run an exec process. -func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) { - var response types.IDResponse - - if err := cli.NewVersionError("1.25", "env"); len(config.Env) != 0 && err != nil { - return response, err - } - - resp, err := cli.post(ctx, "/containers/"+container+"/exec", nil, config, nil) - if err != nil { - return response, err - } - err = json.NewDecoder(resp.body).Decode(&response) - ensureReaderClosed(resp) - return response, err -} - -// ContainerExecStart starts an exec process already created in the docker host. -func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error { - resp, err := cli.post(ctx, "/exec/"+execID+"/start", nil, config, nil) - ensureReaderClosed(resp) - return err -} - -// ContainerExecAttach attaches a connection to an exec process in the server. -// It returns a types.HijackedConnection with the hijacked connection -// and the a reader to get output. It's up to the called to close -// the hijacked connection by calling types.HijackedResponse.Close. -func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error) { - headers := map[string][]string{"Content-Type": {"application/json"}} - return cli.postHijacked(ctx, "/exec/"+execID+"/start", nil, config, headers) -} - -// ContainerExecInspect returns information about a specific exec process on the docker host. -func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error) { - var response types.ContainerExecInspect - resp, err := cli.get(ctx, "/exec/"+execID+"/json", nil, nil) - if err != nil { - return response, err - } - - err = json.NewDecoder(resp.body).Decode(&response) - ensureReaderClosed(resp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/container_exec_test.go b/vendor/github.com/docker/docker/client/container_exec_test.go deleted file mode 100644 index 0e296a5..0000000 --- a/vendor/github.com/docker/docker/client/container_exec_test.go +++ /dev/null @@ -1,157 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestContainerExecCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerExecCreate(context.Background(), "container_id", types.ExecConfig{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerExecCreate(t *testing.T) { - expectedURL := "/containers/container_id/exec" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - // FIXME validate the content is the given ExecConfig ? - if err := req.ParseForm(); err != nil { - return nil, err - } - execConfig := &types.ExecConfig{} - if err := json.NewDecoder(req.Body).Decode(execConfig); err != nil { - return nil, err - } - if execConfig.User != "user" { - return nil, fmt.Errorf("expected an execConfig with User == 'user', got %v", execConfig) - } - b, err := json.Marshal(types.IDResponse{ - ID: "exec_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - r, err := client.ContainerExecCreate(context.Background(), "container_id", types.ExecConfig{ - User: "user", - }) - if err != nil { - t.Fatal(err) - } - if r.ID != "exec_id" { - t.Fatalf("expected `exec_id`, got %s", r.ID) - } -} - -func TestContainerExecStartError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerExecStart(context.Background(), "nothing", types.ExecStartCheck{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerExecStart(t *testing.T) { - expectedURL := "/exec/exec_id/start" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if err := req.ParseForm(); err != nil { - return nil, err - } - execStartCheck := &types.ExecStartCheck{} - if err := json.NewDecoder(req.Body).Decode(execStartCheck); err != nil { - return nil, err - } - if execStartCheck.Tty || !execStartCheck.Detach { - return nil, fmt.Errorf("expected execStartCheck{Detach:true,Tty:false}, got %v", execStartCheck) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.ContainerExecStart(context.Background(), "exec_id", types.ExecStartCheck{ - Detach: true, - Tty: false, - }) - if err != nil { - t.Fatal(err) - } -} - -func TestContainerExecInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerExecInspect(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerExecInspect(t *testing.T) { - expectedURL := "/exec/exec_id/json" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - b, err := json.Marshal(types.ContainerExecInspect{ - ExecID: "exec_id", - ContainerID: "container_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - inspect, err := client.ContainerExecInspect(context.Background(), "exec_id") - if err != nil { - t.Fatal(err) - } - if inspect.ExecID != "exec_id" { - t.Fatalf("expected ExecID to be `exec_id`, got %s", inspect.ExecID) - } - if inspect.ContainerID != "container_id" { - t.Fatalf("expected ContainerID `container_id`, got %s", inspect.ContainerID) - } -} diff --git a/vendor/github.com/docker/docker/client/container_export.go b/vendor/github.com/docker/docker/client/container_export.go deleted file mode 100644 index 52194f3..0000000 --- a/vendor/github.com/docker/docker/client/container_export.go +++ /dev/null @@ -1,20 +0,0 @@ -package client - -import ( - "io" - "net/url" - - "golang.org/x/net/context" -) - -// ContainerExport retrieves the raw contents of a container -// and returns them as an io.ReadCloser. It's up to the caller -// to close the stream. -func (cli *Client) ContainerExport(ctx context.Context, containerID string) (io.ReadCloser, error) { - serverResp, err := cli.get(ctx, "/containers/"+containerID+"/export", url.Values{}, nil) - if err != nil { - return nil, err - } - - return serverResp.body, nil -} diff --git a/vendor/github.com/docker/docker/client/container_export_test.go b/vendor/github.com/docker/docker/client/container_export_test.go deleted file mode 100644 index 5849fe9..0000000 --- a/vendor/github.com/docker/docker/client/container_export_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerExportError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerExport(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerExport(t *testing.T) { - expectedURL := "/containers/container_id/export" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - body, err := client.ContainerExport(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - defer body.Close() - content, err := ioutil.ReadAll(body) - if err != nil { - t.Fatal(err) - } - if string(content) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(content)) - } -} diff --git a/vendor/github.com/docker/docker/client/container_inspect.go b/vendor/github.com/docker/docker/client/container_inspect.go deleted file mode 100644 index 17f1809..0000000 --- a/vendor/github.com/docker/docker/client/container_inspect.go +++ /dev/null @@ -1,54 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ContainerInspect returns the container information. -func (cli *Client) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error) { - serverResp, err := cli.get(ctx, "/containers/"+containerID+"/json", nil, nil) - if err != nil { - if serverResp.statusCode == http.StatusNotFound { - return types.ContainerJSON{}, containerNotFoundError{containerID} - } - return types.ContainerJSON{}, err - } - - var response types.ContainerJSON - err = json.NewDecoder(serverResp.body).Decode(&response) - ensureReaderClosed(serverResp) - return response, err -} - -// ContainerInspectWithRaw returns the container information and its raw representation. -func (cli *Client) ContainerInspectWithRaw(ctx context.Context, containerID string, getSize bool) (types.ContainerJSON, []byte, error) { - query := url.Values{} - if getSize { - query.Set("size", "1") - } - serverResp, err := cli.get(ctx, "/containers/"+containerID+"/json", query, nil) - if err != nil { - if serverResp.statusCode == http.StatusNotFound { - return types.ContainerJSON{}, nil, containerNotFoundError{containerID} - } - return types.ContainerJSON{}, nil, err - } - defer ensureReaderClosed(serverResp) - - body, err := ioutil.ReadAll(serverResp.body) - if err != nil { - return types.ContainerJSON{}, nil, err - } - - var response types.ContainerJSON - rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&response) - return response, body, err -} diff --git a/vendor/github.com/docker/docker/client/container_inspect_test.go b/vendor/github.com/docker/docker/client/container_inspect_test.go deleted file mode 100644 index f1a6f4a..0000000 --- a/vendor/github.com/docker/docker/client/container_inspect_test.go +++ /dev/null @@ -1,125 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestContainerInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ContainerInspect(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerInspectContainerNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, err := client.ContainerInspect(context.Background(), "unknown") - if err == nil || !IsErrContainerNotFound(err) { - t.Fatalf("expected a containerNotFound error, got %v", err) - } -} - -func TestContainerInspect(t *testing.T) { - expectedURL := "/containers/container_id/json" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - content, err := json.Marshal(types.ContainerJSON{ - ContainerJSONBase: &types.ContainerJSONBase{ - ID: "container_id", - Image: "image", - Name: "name", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - r, err := client.ContainerInspect(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - if r.ID != "container_id" { - t.Fatalf("expected `container_id`, got %s", r.ID) - } - if r.Image != "image" { - t.Fatalf("expected `image`, got %s", r.ID) - } - if r.Name != "name" { - t.Fatalf("expected `name`, got %s", r.ID) - } -} - -func TestContainerInspectNode(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - content, err := json.Marshal(types.ContainerJSON{ - ContainerJSONBase: &types.ContainerJSONBase{ - ID: "container_id", - Image: "image", - Name: "name", - Node: &types.ContainerNode{ - ID: "container_node_id", - Addr: "container_node", - Labels: map[string]string{"foo": "bar"}, - }, - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - r, err := client.ContainerInspect(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - if r.ID != "container_id" { - t.Fatalf("expected `container_id`, got %s", r.ID) - } - if r.Image != "image" { - t.Fatalf("expected `image`, got %s", r.ID) - } - if r.Name != "name" { - t.Fatalf("expected `name`, got %s", r.ID) - } - if r.Node.ID != "container_node_id" { - t.Fatalf("expected `container_node_id`, got %s", r.Node.ID) - } - if r.Node.Addr != "container_node" { - t.Fatalf("expected `container_node`, got %s", r.Node.Addr) - } - foo, ok := r.Node.Labels["foo"] - if foo != "bar" || !ok { - t.Fatalf("expected `bar` for label `foo`") - } -} diff --git a/vendor/github.com/docker/docker/client/container_kill.go b/vendor/github.com/docker/docker/client/container_kill.go deleted file mode 100644 index 29f80c7..0000000 --- a/vendor/github.com/docker/docker/client/container_kill.go +++ /dev/null @@ -1,17 +0,0 @@ -package client - -import ( - "net/url" - - "golang.org/x/net/context" -) - -// ContainerKill terminates the container process but does not remove the container from the docker host. -func (cli *Client) ContainerKill(ctx context.Context, containerID, signal string) error { - query := url.Values{} - query.Set("signal", signal) - - resp, err := cli.post(ctx, "/containers/"+containerID+"/kill", query, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/container_kill_test.go b/vendor/github.com/docker/docker/client/container_kill_test.go deleted file mode 100644 index 9477b0a..0000000 --- a/vendor/github.com/docker/docker/client/container_kill_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerKillError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerKill(context.Background(), "nothing", "SIGKILL") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerKill(t *testing.T) { - expectedURL := "/containers/container_id/kill" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - signal := req.URL.Query().Get("signal") - if signal != "SIGKILL" { - return nil, fmt.Errorf("signal not set in URL query properly. Expected 'SIGKILL', got %s", signal) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.ContainerKill(context.Background(), "container_id", "SIGKILL") - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/container_list.go b/vendor/github.com/docker/docker/client/container_list.go deleted file mode 100644 index 4398912..0000000 --- a/vendor/github.com/docker/docker/client/container_list.go +++ /dev/null @@ -1,56 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - "strconv" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -// ContainerList returns the list of containers in the docker host. -func (cli *Client) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) { - query := url.Values{} - - if options.All { - query.Set("all", "1") - } - - if options.Limit != -1 { - query.Set("limit", strconv.Itoa(options.Limit)) - } - - if options.Since != "" { - query.Set("since", options.Since) - } - - if options.Before != "" { - query.Set("before", options.Before) - } - - if options.Size { - query.Set("size", "1") - } - - if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filters) - - if err != nil { - return nil, err - } - - query.Set("filters", filterJSON) - } - - resp, err := cli.get(ctx, "/containers/json", query, nil) - if err != nil { - return nil, err - } - - var containers []types.Container - err = json.NewDecoder(resp.body).Decode(&containers) - ensureReaderClosed(resp) - return containers, err -} diff --git a/vendor/github.com/docker/docker/client/container_list_test.go b/vendor/github.com/docker/docker/client/container_list_test.go deleted file mode 100644 index e41c687..0000000 --- a/vendor/github.com/docker/docker/client/container_list_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -func TestContainerListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerList(context.Background(), types.ContainerListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerList(t *testing.T) { - expectedURL := "/containers/json" - expectedFilters := `{"before":{"container":true},"label":{"label1":true,"label2":true}}` - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - all := query.Get("all") - if all != "1" { - return nil, fmt.Errorf("all not set in URL query properly. Expected '1', got %s", all) - } - limit := query.Get("limit") - if limit != "0" { - return nil, fmt.Errorf("limit should have not be present in query. Expected '0', got %s", limit) - } - since := query.Get("since") - if since != "container" { - return nil, fmt.Errorf("since not set in URL query properly. Expected 'container', got %s", since) - } - before := query.Get("before") - if before != "" { - return nil, fmt.Errorf("before should have not be present in query, go %s", before) - } - size := query.Get("size") - if size != "1" { - return nil, fmt.Errorf("size not set in URL query properly. Expected '1', got %s", size) - } - filters := query.Get("filters") - if filters != expectedFilters { - return nil, fmt.Errorf("expected filters incoherent '%v' with actual filters %v", expectedFilters, filters) - } - - b, err := json.Marshal([]types.Container{ - { - ID: "container_id1", - }, - { - ID: "container_id2", - }, - }) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - filters.Add("before", "container") - containers, err := client.ContainerList(context.Background(), types.ContainerListOptions{ - Size: true, - All: true, - Since: "container", - Filters: filters, - }) - if err != nil { - t.Fatal(err) - } - if len(containers) != 2 { - t.Fatalf("expected 2 containers, got %v", containers) - } -} diff --git a/vendor/github.com/docker/docker/client/container_logs.go b/vendor/github.com/docker/docker/client/container_logs.go deleted file mode 100644 index 69056b6..0000000 --- a/vendor/github.com/docker/docker/client/container_logs.go +++ /dev/null @@ -1,52 +0,0 @@ -package client - -import ( - "io" - "net/url" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - timetypes "github.com/docker/docker/api/types/time" -) - -// ContainerLogs returns the logs generated by a container in an io.ReadCloser. -// It's up to the caller to close the stream. -func (cli *Client) ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error) { - query := url.Values{} - if options.ShowStdout { - query.Set("stdout", "1") - } - - if options.ShowStderr { - query.Set("stderr", "1") - } - - if options.Since != "" { - ts, err := timetypes.GetTimestamp(options.Since, time.Now()) - if err != nil { - return nil, err - } - query.Set("since", ts) - } - - if options.Timestamps { - query.Set("timestamps", "1") - } - - if options.Details { - query.Set("details", "1") - } - - if options.Follow { - query.Set("follow", "1") - } - query.Set("tail", options.Tail) - - resp, err := cli.get(ctx, "/containers/"+container+"/logs", query, nil) - if err != nil { - return nil, err - } - return resp.body, nil -} diff --git a/vendor/github.com/docker/docker/client/container_logs_test.go b/vendor/github.com/docker/docker/client/container_logs_test.go deleted file mode 100644 index 99e3184..0000000 --- a/vendor/github.com/docker/docker/client/container_logs_test.go +++ /dev/null @@ -1,133 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io" - "io/ioutil" - "log" - "net/http" - "os" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types" - - "golang.org/x/net/context" -) - -func TestContainerLogsError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } - _, err = client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{ - Since: "2006-01-02TZ", - }) - if err == nil || !strings.Contains(err.Error(), `parsing time "2006-01-02TZ"`) { - t.Fatalf("expected a 'parsing time' error, got %v", err) - } -} - -func TestContainerLogs(t *testing.T) { - expectedURL := "/containers/container_id/logs" - cases := []struct { - options types.ContainerLogsOptions - expectedQueryParams map[string]string - }{ - { - expectedQueryParams: map[string]string{ - "tail": "", - }, - }, - { - options: types.ContainerLogsOptions{ - Tail: "any", - }, - expectedQueryParams: map[string]string{ - "tail": "any", - }, - }, - { - options: types.ContainerLogsOptions{ - ShowStdout: true, - ShowStderr: true, - Timestamps: true, - Details: true, - Follow: true, - }, - expectedQueryParams: map[string]string{ - "tail": "", - "stdout": "1", - "stderr": "1", - "timestamps": "1", - "details": "1", - "follow": "1", - }, - }, - { - options: types.ContainerLogsOptions{ - // An complete invalid date, timestamp or go duration will be - // passed as is - Since: "invalid but valid", - }, - expectedQueryParams: map[string]string{ - "tail": "", - "since": "invalid but valid", - }, - }, - } - for _, logCase := range cases { - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - // Check query parameters - query := r.URL.Query() - for key, expected := range logCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - body, err := client.ContainerLogs(context.Background(), "container_id", logCase.options) - if err != nil { - t.Fatal(err) - } - defer body.Close() - content, err := ioutil.ReadAll(body) - if err != nil { - t.Fatal(err) - } - if string(content) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(content)) - } - } -} - -func ExampleClient_ContainerLogs_withTimeout() { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - client, _ := NewEnvClient() - reader, err := client.ContainerLogs(ctx, "container_id", types.ContainerLogsOptions{}) - if err != nil { - log.Fatal(err) - } - - _, err = io.Copy(os.Stdout, reader) - if err != nil && err != io.EOF { - log.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/container_pause.go b/vendor/github.com/docker/docker/client/container_pause.go deleted file mode 100644 index 412067a..0000000 --- a/vendor/github.com/docker/docker/client/container_pause.go +++ /dev/null @@ -1,10 +0,0 @@ -package client - -import "golang.org/x/net/context" - -// ContainerPause pauses the main process of a given container without terminating it. -func (cli *Client) ContainerPause(ctx context.Context, containerID string) error { - resp, err := cli.post(ctx, "/containers/"+containerID+"/pause", nil, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/container_pause_test.go b/vendor/github.com/docker/docker/client/container_pause_test.go deleted file mode 100644 index 0ee2f05..0000000 --- a/vendor/github.com/docker/docker/client/container_pause_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerPauseError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerPause(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerPause(t *testing.T) { - expectedURL := "/containers/container_id/pause" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - err := client.ContainerPause(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/container_prune.go b/vendor/github.com/docker/docker/client/container_prune.go deleted file mode 100644 index b582170..0000000 --- a/vendor/github.com/docker/docker/client/container_prune.go +++ /dev/null @@ -1,36 +0,0 @@ -package client - -import ( - "encoding/json" - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -// ContainersPrune requests the daemon to delete unused data -func (cli *Client) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error) { - var report types.ContainersPruneReport - - if err := cli.NewVersionError("1.25", "container prune"); err != nil { - return report, err - } - - query, err := getFiltersQuery(pruneFilters) - if err != nil { - return report, err - } - - serverResp, err := cli.post(ctx, "/containers/prune", query, nil, nil) - if err != nil { - return report, err - } - defer ensureReaderClosed(serverResp) - - if err := json.NewDecoder(serverResp.body).Decode(&report); err != nil { - return report, fmt.Errorf("Error retrieving disk usage: %v", err) - } - - return report, nil -} diff --git a/vendor/github.com/docker/docker/client/container_remove.go b/vendor/github.com/docker/docker/client/container_remove.go deleted file mode 100644 index 3a79590..0000000 --- a/vendor/github.com/docker/docker/client/container_remove.go +++ /dev/null @@ -1,27 +0,0 @@ -package client - -import ( - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ContainerRemove kills and removes a container from the docker host. -func (cli *Client) ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error { - query := url.Values{} - if options.RemoveVolumes { - query.Set("v", "1") - } - if options.RemoveLinks { - query.Set("link", "1") - } - - if options.Force { - query.Set("force", "1") - } - - resp, err := cli.delete(ctx, "/containers/"+containerID, query, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/container_remove_test.go b/vendor/github.com/docker/docker/client/container_remove_test.go deleted file mode 100644 index 798c08b..0000000 --- a/vendor/github.com/docker/docker/client/container_remove_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestContainerRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerRemove(t *testing.T) { - expectedURL := "/containers/container_id" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - volume := query.Get("v") - if volume != "1" { - return nil, fmt.Errorf("v (volume) not set in URL query properly. Expected '1', got %s", volume) - } - force := query.Get("force") - if force != "1" { - return nil, fmt.Errorf("force not set in URL query properly. Expected '1', got %s", force) - } - link := query.Get("link") - if link != "" { - return nil, fmt.Errorf("link should have not be present in query, go %s", link) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{ - RemoveVolumes: true, - Force: true, - }) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/container_rename.go b/vendor/github.com/docker/docker/client/container_rename.go deleted file mode 100644 index 0e718da..0000000 --- a/vendor/github.com/docker/docker/client/container_rename.go +++ /dev/null @@ -1,16 +0,0 @@ -package client - -import ( - "net/url" - - "golang.org/x/net/context" -) - -// ContainerRename changes the name of a given container. -func (cli *Client) ContainerRename(ctx context.Context, containerID, newContainerName string) error { - query := url.Values{} - query.Set("name", newContainerName) - resp, err := cli.post(ctx, "/containers/"+containerID+"/rename", query, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/container_rename_test.go b/vendor/github.com/docker/docker/client/container_rename_test.go deleted file mode 100644 index 732ebff..0000000 --- a/vendor/github.com/docker/docker/client/container_rename_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerRenameError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerRename(context.Background(), "nothing", "newNothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerRename(t *testing.T) { - expectedURL := "/containers/container_id/rename" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - name := req.URL.Query().Get("name") - if name != "newName" { - return nil, fmt.Errorf("name not set in URL query properly. Expected 'newName', got %s", name) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.ContainerRename(context.Background(), "container_id", "newName") - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/container_resize.go b/vendor/github.com/docker/docker/client/container_resize.go deleted file mode 100644 index 66c3cc1..0000000 --- a/vendor/github.com/docker/docker/client/container_resize.go +++ /dev/null @@ -1,29 +0,0 @@ -package client - -import ( - "net/url" - "strconv" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ContainerResize changes the size of the tty for a container. -func (cli *Client) ContainerResize(ctx context.Context, containerID string, options types.ResizeOptions) error { - return cli.resize(ctx, "/containers/"+containerID, options.Height, options.Width) -} - -// ContainerExecResize changes the size of the tty for an exec process running inside a container. -func (cli *Client) ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error { - return cli.resize(ctx, "/exec/"+execID, options.Height, options.Width) -} - -func (cli *Client) resize(ctx context.Context, basePath string, height, width uint) error { - query := url.Values{} - query.Set("h", strconv.Itoa(int(height))) - query.Set("w", strconv.Itoa(int(width))) - - resp, err := cli.post(ctx, basePath+"/resize", query, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/container_resize_test.go b/vendor/github.com/docker/docker/client/container_resize_test.go deleted file mode 100644 index 5b2efec..0000000 --- a/vendor/github.com/docker/docker/client/container_resize_test.go +++ /dev/null @@ -1,82 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestContainerResizeError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerResize(context.Background(), "container_id", types.ResizeOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerExecResizeError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerExecResize(context.Background(), "exec_id", types.ResizeOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerResize(t *testing.T) { - client := &Client{ - client: newMockClient(resizeTransport("/containers/container_id/resize")), - } - - err := client.ContainerResize(context.Background(), "container_id", types.ResizeOptions{ - Height: 500, - Width: 600, - }) - if err != nil { - t.Fatal(err) - } -} - -func TestContainerExecResize(t *testing.T) { - client := &Client{ - client: newMockClient(resizeTransport("/exec/exec_id/resize")), - } - - err := client.ContainerExecResize(context.Background(), "exec_id", types.ResizeOptions{ - Height: 500, - Width: 600, - }) - if err != nil { - t.Fatal(err) - } -} - -func resizeTransport(expectedURL string) func(req *http.Request) (*http.Response, error) { - return func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - h := query.Get("h") - if h != "500" { - return nil, fmt.Errorf("h not set in URL query properly. Expected '500', got %s", h) - } - w := query.Get("w") - if w != "600" { - return nil, fmt.Errorf("w not set in URL query properly. Expected '600', got %s", w) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - } -} diff --git a/vendor/github.com/docker/docker/client/container_restart.go b/vendor/github.com/docker/docker/client/container_restart.go deleted file mode 100644 index 74d7455..0000000 --- a/vendor/github.com/docker/docker/client/container_restart.go +++ /dev/null @@ -1,22 +0,0 @@ -package client - -import ( - "net/url" - "time" - - timetypes "github.com/docker/docker/api/types/time" - "golang.org/x/net/context" -) - -// ContainerRestart stops and starts a container again. -// It makes the daemon to wait for the container to be up again for -// a specific amount of time, given the timeout. -func (cli *Client) ContainerRestart(ctx context.Context, containerID string, timeout *time.Duration) error { - query := url.Values{} - if timeout != nil { - query.Set("t", timetypes.DurationToSecondsString(*timeout)) - } - resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/container_restart_test.go b/vendor/github.com/docker/docker/client/container_restart_test.go deleted file mode 100644 index 8c3cfd6..0000000 --- a/vendor/github.com/docker/docker/client/container_restart_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - "time" - - "golang.org/x/net/context" -) - -func TestContainerRestartError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - timeout := 0 * time.Second - err := client.ContainerRestart(context.Background(), "nothing", &timeout) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerRestart(t *testing.T) { - expectedURL := "/containers/container_id/restart" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - t := req.URL.Query().Get("t") - if t != "100" { - return nil, fmt.Errorf("t (timeout) not set in URL query properly. Expected '100', got %s", t) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - timeout := 100 * time.Second - err := client.ContainerRestart(context.Background(), "container_id", &timeout) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/container_start.go b/vendor/github.com/docker/docker/client/container_start.go deleted file mode 100644 index b1f08de..0000000 --- a/vendor/github.com/docker/docker/client/container_start.go +++ /dev/null @@ -1,24 +0,0 @@ -package client - -import ( - "net/url" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -// ContainerStart sends a request to the docker daemon to start a container. -func (cli *Client) ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error { - query := url.Values{} - if len(options.CheckpointID) != 0 { - query.Set("checkpoint", options.CheckpointID) - } - if len(options.CheckpointDir) != 0 { - query.Set("checkpoint-dir", options.CheckpointDir) - } - - resp, err := cli.post(ctx, "/containers/"+containerID+"/start", query, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/container_start_test.go b/vendor/github.com/docker/docker/client/container_start_test.go deleted file mode 100644 index 5826fa8..0000000 --- a/vendor/github.com/docker/docker/client/container_start_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestContainerStartError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerStart(context.Background(), "nothing", types.ContainerStartOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerStart(t *testing.T) { - expectedURL := "/containers/container_id/start" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - // we're not expecting any payload, but if one is supplied, check it is valid. - if req.Header.Get("Content-Type") == "application/json" { - var startConfig interface{} - if err := json.NewDecoder(req.Body).Decode(&startConfig); err != nil { - return nil, fmt.Errorf("Unable to parse json: %s", err) - } - } - - checkpoint := req.URL.Query().Get("checkpoint") - if checkpoint != "checkpoint_id" { - return nil, fmt.Errorf("checkpoint not set in URL query properly. Expected 'checkpoint_id', got %s", checkpoint) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.ContainerStart(context.Background(), "container_id", types.ContainerStartOptions{CheckpointID: "checkpoint_id"}) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/container_stats.go b/vendor/github.com/docker/docker/client/container_stats.go deleted file mode 100644 index 4758c66..0000000 --- a/vendor/github.com/docker/docker/client/container_stats.go +++ /dev/null @@ -1,26 +0,0 @@ -package client - -import ( - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ContainerStats returns near realtime stats for a given container. -// It's up to the caller to close the io.ReadCloser returned. -func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) { - query := url.Values{} - query.Set("stream", "0") - if stream { - query.Set("stream", "1") - } - - resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil) - if err != nil { - return types.ContainerStats{}, err - } - - osType := getDockerOS(resp.header.Get("Server")) - return types.ContainerStats{Body: resp.body, OSType: osType}, err -} diff --git a/vendor/github.com/docker/docker/client/container_stats_test.go b/vendor/github.com/docker/docker/client/container_stats_test.go deleted file mode 100644 index 7414f13..0000000 --- a/vendor/github.com/docker/docker/client/container_stats_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerStatsError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerStats(context.Background(), "nothing", false) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerStats(t *testing.T) { - expectedURL := "/containers/container_id/stats" - cases := []struct { - stream bool - expectedStream string - }{ - { - expectedStream: "0", - }, - { - stream: true, - expectedStream: "1", - }, - } - for _, c := range cases { - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - - query := r.URL.Query() - stream := query.Get("stream") - if stream != c.expectedStream { - return nil, fmt.Errorf("stream not set in URL query properly. Expected '%s', got %s", c.expectedStream, stream) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - resp, err := client.ContainerStats(context.Background(), "container_id", c.stream) - if err != nil { - t.Fatal(err) - } - defer resp.Body.Close() - content, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Fatal(err) - } - if string(content) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(content)) - } - } -} diff --git a/vendor/github.com/docker/docker/client/container_stop.go b/vendor/github.com/docker/docker/client/container_stop.go deleted file mode 100644 index b5418ae..0000000 --- a/vendor/github.com/docker/docker/client/container_stop.go +++ /dev/null @@ -1,21 +0,0 @@ -package client - -import ( - "net/url" - "time" - - timetypes "github.com/docker/docker/api/types/time" - "golang.org/x/net/context" -) - -// ContainerStop stops a container without terminating the process. -// The process is blocked until the container stops or the timeout expires. -func (cli *Client) ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error { - query := url.Values{} - if timeout != nil { - query.Set("t", timetypes.DurationToSecondsString(*timeout)) - } - resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/container_stop_test.go b/vendor/github.com/docker/docker/client/container_stop_test.go deleted file mode 100644 index c32cd69..0000000 --- a/vendor/github.com/docker/docker/client/container_stop_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - "time" - - "golang.org/x/net/context" -) - -func TestContainerStopError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - timeout := 0 * time.Second - err := client.ContainerStop(context.Background(), "nothing", &timeout) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerStop(t *testing.T) { - expectedURL := "/containers/container_id/stop" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - t := req.URL.Query().Get("t") - if t != "100" { - return nil, fmt.Errorf("t (timeout) not set in URL query properly. Expected '100', got %s", t) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - timeout := 100 * time.Second - err := client.ContainerStop(context.Background(), "container_id", &timeout) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/container_top.go b/vendor/github.com/docker/docker/client/container_top.go deleted file mode 100644 index 4e7270e..0000000 --- a/vendor/github.com/docker/docker/client/container_top.go +++ /dev/null @@ -1,28 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - "strings" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ContainerTop shows process information from within a container. -func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (types.ContainerProcessList, error) { - var response types.ContainerProcessList - query := url.Values{} - if len(arguments) > 0 { - query.Set("ps_args", strings.Join(arguments, " ")) - } - - resp, err := cli.get(ctx, "/containers/"+containerID+"/top", query, nil) - if err != nil { - return response, err - } - - err = json.NewDecoder(resp.body).Decode(&response) - ensureReaderClosed(resp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/container_top_test.go b/vendor/github.com/docker/docker/client/container_top_test.go deleted file mode 100644 index 7802be0..0000000 --- a/vendor/github.com/docker/docker/client/container_top_test.go +++ /dev/null @@ -1,74 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "reflect" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestContainerTopError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerTop(context.Background(), "nothing", []string{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerTop(t *testing.T) { - expectedURL := "/containers/container_id/top" - expectedProcesses := [][]string{ - {"p1", "p2"}, - {"p3"}, - } - expectedTitles := []string{"title1", "title2"} - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - args := query.Get("ps_args") - if args != "arg1 arg2" { - return nil, fmt.Errorf("args not set in URL query properly. Expected 'arg1 arg2', got %v", args) - } - - b, err := json.Marshal(types.ContainerProcessList{ - Processes: [][]string{ - {"p1", "p2"}, - {"p3"}, - }, - Titles: []string{"title1", "title2"}, - }) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - processList, err := client.ContainerTop(context.Background(), "container_id", []string{"arg1", "arg2"}) - if err != nil { - t.Fatal(err) - } - if !reflect.DeepEqual(expectedProcesses, processList.Processes) { - t.Fatalf("Processes: expected %v, got %v", expectedProcesses, processList.Processes) - } - if !reflect.DeepEqual(expectedTitles, processList.Titles) { - t.Fatalf("Titles: expected %v, got %v", expectedTitles, processList.Titles) - } -} diff --git a/vendor/github.com/docker/docker/client/container_unpause.go b/vendor/github.com/docker/docker/client/container_unpause.go deleted file mode 100644 index 5c76211..0000000 --- a/vendor/github.com/docker/docker/client/container_unpause.go +++ /dev/null @@ -1,10 +0,0 @@ -package client - -import "golang.org/x/net/context" - -// ContainerUnpause resumes the process execution within a container -func (cli *Client) ContainerUnpause(ctx context.Context, containerID string) error { - resp, err := cli.post(ctx, "/containers/"+containerID+"/unpause", nil, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/container_unpause_test.go b/vendor/github.com/docker/docker/client/container_unpause_test.go deleted file mode 100644 index 2c42727..0000000 --- a/vendor/github.com/docker/docker/client/container_unpause_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestContainerUnpauseError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - err := client.ContainerUnpause(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerUnpause(t *testing.T) { - expectedURL := "/containers/container_id/unpause" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - err := client.ContainerUnpause(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/container_update.go b/vendor/github.com/docker/docker/client/container_update.go deleted file mode 100644 index 5082f22..0000000 --- a/vendor/github.com/docker/docker/client/container_update.go +++ /dev/null @@ -1,22 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types/container" - "golang.org/x/net/context" -) - -// ContainerUpdate updates resources of a container -func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) { - var response container.ContainerUpdateOKBody - serverResp, err := cli.post(ctx, "/containers/"+containerID+"/update", nil, updateConfig, nil) - if err != nil { - return response, err - } - - err = json.NewDecoder(serverResp.body).Decode(&response) - - ensureReaderClosed(serverResp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/container_update_test.go b/vendor/github.com/docker/docker/client/container_update_test.go deleted file mode 100644 index 715bb7c..0000000 --- a/vendor/github.com/docker/docker/client/container_update_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/container" - "golang.org/x/net/context" -) - -func TestContainerUpdateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerUpdate(context.Background(), "nothing", container.UpdateConfig{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestContainerUpdate(t *testing.T) { - expectedURL := "/containers/container_id/update" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - - b, err := json.Marshal(container.ContainerUpdateOKBody{}) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - _, err := client.ContainerUpdate(context.Background(), "container_id", container.UpdateConfig{ - Resources: container.Resources{ - CPUPeriod: 1, - }, - RestartPolicy: container.RestartPolicy{ - Name: "always", - }, - }) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/container_wait.go b/vendor/github.com/docker/docker/client/container_wait.go deleted file mode 100644 index 93212c7..0000000 --- a/vendor/github.com/docker/docker/client/container_wait.go +++ /dev/null @@ -1,26 +0,0 @@ -package client - -import ( - "encoding/json" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/container" -) - -// ContainerWait pauses execution until a container exits. -// It returns the API status code as response of its readiness. -func (cli *Client) ContainerWait(ctx context.Context, containerID string) (int64, error) { - resp, err := cli.post(ctx, "/containers/"+containerID+"/wait", nil, nil, nil) - if err != nil { - return -1, err - } - defer ensureReaderClosed(resp) - - var res container.ContainerWaitOKBody - if err := json.NewDecoder(resp.body).Decode(&res); err != nil { - return -1, err - } - - return res.StatusCode, nil -} diff --git a/vendor/github.com/docker/docker/client/container_wait_test.go b/vendor/github.com/docker/docker/client/container_wait_test.go deleted file mode 100644 index 9300bc0..0000000 --- a/vendor/github.com/docker/docker/client/container_wait_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "log" - "net/http" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types/container" - - "golang.org/x/net/context" -) - -func TestContainerWaitError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - code, err := client.ContainerWait(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } - if code != -1 { - t.Fatalf("expected a status code equal to '-1', got %d", code) - } -} - -func TestContainerWait(t *testing.T) { - expectedURL := "/containers/container_id/wait" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - b, err := json.Marshal(container.ContainerWaitOKBody{ - StatusCode: 15, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - code, err := client.ContainerWait(context.Background(), "container_id") - if err != nil { - t.Fatal(err) - } - if code != 15 { - t.Fatalf("expected a status code equal to '15', got %d", code) - } -} - -func ExampleClient_ContainerWait_withTimeout() { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - client, _ := NewEnvClient() - _, err := client.ContainerWait(ctx, "container_id") - if err != nil { - log.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/disk_usage.go b/vendor/github.com/docker/docker/client/disk_usage.go deleted file mode 100644 index 03c80b3..0000000 --- a/vendor/github.com/docker/docker/client/disk_usage.go +++ /dev/null @@ -1,26 +0,0 @@ -package client - -import ( - "encoding/json" - "fmt" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// DiskUsage requests the current data usage from the daemon -func (cli *Client) DiskUsage(ctx context.Context) (types.DiskUsage, error) { - var du types.DiskUsage - - serverResp, err := cli.get(ctx, "/system/df", nil, nil) - if err != nil { - return du, err - } - defer ensureReaderClosed(serverResp) - - if err := json.NewDecoder(serverResp.body).Decode(&du); err != nil { - return du, fmt.Errorf("Error retrieving disk usage: %v", err) - } - - return du, nil -} diff --git a/vendor/github.com/docker/docker/client/errors.go b/vendor/github.com/docker/docker/client/errors.go deleted file mode 100644 index bf6923f..0000000 --- a/vendor/github.com/docker/docker/client/errors.go +++ /dev/null @@ -1,278 +0,0 @@ -package client - -import ( - "fmt" - - "github.com/docker/docker/api/types/versions" - "github.com/pkg/errors" -) - -// errConnectionFailed implements an error returned when connection failed. -type errConnectionFailed struct { - host string -} - -// Error returns a string representation of an errConnectionFailed -func (err errConnectionFailed) Error() string { - if err.host == "" { - return "Cannot connect to the Docker daemon. Is the docker daemon running on this host?" - } - return fmt.Sprintf("Cannot connect to the Docker daemon at %s. Is the docker daemon running?", err.host) -} - -// IsErrConnectionFailed returns true if the error is caused by connection failed. -func IsErrConnectionFailed(err error) bool { - _, ok := errors.Cause(err).(errConnectionFailed) - return ok -} - -// ErrorConnectionFailed returns an error with host in the error message when connection to docker daemon failed. -func ErrorConnectionFailed(host string) error { - return errConnectionFailed{host: host} -} - -type notFound interface { - error - NotFound() bool // Is the error a NotFound error -} - -// IsErrNotFound returns true if the error is caused with an -// object (image, container, network, volume, …) is not found in the docker host. -func IsErrNotFound(err error) bool { - te, ok := err.(notFound) - return ok && te.NotFound() -} - -// imageNotFoundError implements an error returned when an image is not in the docker host. -type imageNotFoundError struct { - imageID string -} - -// NotFound indicates that this error type is of NotFound -func (e imageNotFoundError) NotFound() bool { - return true -} - -// Error returns a string representation of an imageNotFoundError -func (e imageNotFoundError) Error() string { - return fmt.Sprintf("Error: No such image: %s", e.imageID) -} - -// IsErrImageNotFound returns true if the error is caused -// when an image is not found in the docker host. -func IsErrImageNotFound(err error) bool { - return IsErrNotFound(err) -} - -// containerNotFoundError implements an error returned when a container is not in the docker host. -type containerNotFoundError struct { - containerID string -} - -// NotFound indicates that this error type is of NotFound -func (e containerNotFoundError) NotFound() bool { - return true -} - -// Error returns a string representation of a containerNotFoundError -func (e containerNotFoundError) Error() string { - return fmt.Sprintf("Error: No such container: %s", e.containerID) -} - -// IsErrContainerNotFound returns true if the error is caused -// when a container is not found in the docker host. -func IsErrContainerNotFound(err error) bool { - return IsErrNotFound(err) -} - -// networkNotFoundError implements an error returned when a network is not in the docker host. -type networkNotFoundError struct { - networkID string -} - -// NotFound indicates that this error type is of NotFound -func (e networkNotFoundError) NotFound() bool { - return true -} - -// Error returns a string representation of a networkNotFoundError -func (e networkNotFoundError) Error() string { - return fmt.Sprintf("Error: No such network: %s", e.networkID) -} - -// IsErrNetworkNotFound returns true if the error is caused -// when a network is not found in the docker host. -func IsErrNetworkNotFound(err error) bool { - return IsErrNotFound(err) -} - -// volumeNotFoundError implements an error returned when a volume is not in the docker host. -type volumeNotFoundError struct { - volumeID string -} - -// NotFound indicates that this error type is of NotFound -func (e volumeNotFoundError) NotFound() bool { - return true -} - -// Error returns a string representation of a volumeNotFoundError -func (e volumeNotFoundError) Error() string { - return fmt.Sprintf("Error: No such volume: %s", e.volumeID) -} - -// IsErrVolumeNotFound returns true if the error is caused -// when a volume is not found in the docker host. -func IsErrVolumeNotFound(err error) bool { - return IsErrNotFound(err) -} - -// unauthorizedError represents an authorization error in a remote registry. -type unauthorizedError struct { - cause error -} - -// Error returns a string representation of an unauthorizedError -func (u unauthorizedError) Error() string { - return u.cause.Error() -} - -// IsErrUnauthorized returns true if the error is caused -// when a remote registry authentication fails -func IsErrUnauthorized(err error) bool { - _, ok := err.(unauthorizedError) - return ok -} - -// nodeNotFoundError implements an error returned when a node is not found. -type nodeNotFoundError struct { - nodeID string -} - -// Error returns a string representation of a nodeNotFoundError -func (e nodeNotFoundError) Error() string { - return fmt.Sprintf("Error: No such node: %s", e.nodeID) -} - -// NotFound indicates that this error type is of NotFound -func (e nodeNotFoundError) NotFound() bool { - return true -} - -// IsErrNodeNotFound returns true if the error is caused -// when a node is not found. -func IsErrNodeNotFound(err error) bool { - _, ok := err.(nodeNotFoundError) - return ok -} - -// serviceNotFoundError implements an error returned when a service is not found. -type serviceNotFoundError struct { - serviceID string -} - -// Error returns a string representation of a serviceNotFoundError -func (e serviceNotFoundError) Error() string { - return fmt.Sprintf("Error: No such service: %s", e.serviceID) -} - -// NotFound indicates that this error type is of NotFound -func (e serviceNotFoundError) NotFound() bool { - return true -} - -// IsErrServiceNotFound returns true if the error is caused -// when a service is not found. -func IsErrServiceNotFound(err error) bool { - _, ok := err.(serviceNotFoundError) - return ok -} - -// taskNotFoundError implements an error returned when a task is not found. -type taskNotFoundError struct { - taskID string -} - -// Error returns a string representation of a taskNotFoundError -func (e taskNotFoundError) Error() string { - return fmt.Sprintf("Error: No such task: %s", e.taskID) -} - -// NotFound indicates that this error type is of NotFound -func (e taskNotFoundError) NotFound() bool { - return true -} - -// IsErrTaskNotFound returns true if the error is caused -// when a task is not found. -func IsErrTaskNotFound(err error) bool { - _, ok := err.(taskNotFoundError) - return ok -} - -type pluginPermissionDenied struct { - name string -} - -func (e pluginPermissionDenied) Error() string { - return "Permission denied while installing plugin " + e.name -} - -// IsErrPluginPermissionDenied returns true if the error is caused -// when a user denies a plugin's permissions -func IsErrPluginPermissionDenied(err error) bool { - _, ok := err.(pluginPermissionDenied) - return ok -} - -// NewVersionError returns an error if the APIVersion required -// if less than the current supported version -func (cli *Client) NewVersionError(APIrequired, feature string) error { - if versions.LessThan(cli.version, APIrequired) { - return fmt.Errorf("%q requires API version %s, but the Docker server is version %s", feature, APIrequired, cli.version) - } - return nil -} - -// secretNotFoundError implements an error returned when a secret is not found. -type secretNotFoundError struct { - name string -} - -// Error returns a string representation of a secretNotFoundError -func (e secretNotFoundError) Error() string { - return fmt.Sprintf("Error: no such secret: %s", e.name) -} - -// NoFound indicates that this error type is of NotFound -func (e secretNotFoundError) NotFound() bool { - return true -} - -// IsErrSecretNotFound returns true if the error is caused -// when a secret is not found. -func IsErrSecretNotFound(err error) bool { - _, ok := err.(secretNotFoundError) - return ok -} - -// pluginNotFoundError implements an error returned when a plugin is not in the docker host. -type pluginNotFoundError struct { - name string -} - -// NotFound indicates that this error type is of NotFound -func (e pluginNotFoundError) NotFound() bool { - return true -} - -// Error returns a string representation of a pluginNotFoundError -func (e pluginNotFoundError) Error() string { - return fmt.Sprintf("Error: No such plugin: %s", e.name) -} - -// IsErrPluginNotFound returns true if the error is caused -// when a plugin is not found in the docker host. -func IsErrPluginNotFound(err error) bool { - return IsErrNotFound(err) -} diff --git a/vendor/github.com/docker/docker/client/events.go b/vendor/github.com/docker/docker/client/events.go deleted file mode 100644 index af47aef..0000000 --- a/vendor/github.com/docker/docker/client/events.go +++ /dev/null @@ -1,102 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" - timetypes "github.com/docker/docker/api/types/time" -) - -// Events returns a stream of events in the daemon. It's up to the caller to close the stream -// by cancelling the context. Once the stream has been completely read an io.EOF error will -// be sent over the error channel. If an error is sent all processing will be stopped. It's up -// to the caller to reopen the stream in the event of an error by reinvoking this method. -func (cli *Client) Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error) { - - messages := make(chan events.Message) - errs := make(chan error, 1) - - started := make(chan struct{}) - go func() { - defer close(errs) - - query, err := buildEventsQueryParams(cli.version, options) - if err != nil { - close(started) - errs <- err - return - } - - resp, err := cli.get(ctx, "/events", query, nil) - if err != nil { - close(started) - errs <- err - return - } - defer resp.body.Close() - - decoder := json.NewDecoder(resp.body) - - close(started) - for { - select { - case <-ctx.Done(): - errs <- ctx.Err() - return - default: - var event events.Message - if err := decoder.Decode(&event); err != nil { - errs <- err - return - } - - select { - case messages <- event: - case <-ctx.Done(): - errs <- ctx.Err() - return - } - } - } - }() - <-started - - return messages, errs -} - -func buildEventsQueryParams(cliVersion string, options types.EventsOptions) (url.Values, error) { - query := url.Values{} - ref := time.Now() - - if options.Since != "" { - ts, err := timetypes.GetTimestamp(options.Since, ref) - if err != nil { - return nil, err - } - query.Set("since", ts) - } - - if options.Until != "" { - ts, err := timetypes.GetTimestamp(options.Until, ref) - if err != nil { - return nil, err - } - query.Set("until", ts) - } - - if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParamWithVersion(cliVersion, options.Filters) - if err != nil { - return nil, err - } - query.Set("filters", filterJSON) - } - - return query, nil -} diff --git a/vendor/github.com/docker/docker/client/events_test.go b/vendor/github.com/docker/docker/client/events_test.go deleted file mode 100644 index ba82d2f..0000000 --- a/vendor/github.com/docker/docker/client/events_test.go +++ /dev/null @@ -1,165 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" -) - -func TestEventsErrorInOptions(t *testing.T) { - errorCases := []struct { - options types.EventsOptions - expectedError string - }{ - { - options: types.EventsOptions{ - Since: "2006-01-02TZ", - }, - expectedError: `parsing time "2006-01-02TZ"`, - }, - { - options: types.EventsOptions{ - Until: "2006-01-02TZ", - }, - expectedError: `parsing time "2006-01-02TZ"`, - }, - } - for _, e := range errorCases { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, errs := client.Events(context.Background(), e.options) - err := <-errs - if err == nil || !strings.Contains(err.Error(), e.expectedError) { - t.Fatalf("expected an error %q, got %v", e.expectedError, err) - } - } -} - -func TestEventsErrorFromServer(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, errs := client.Events(context.Background(), types.EventsOptions{}) - err := <-errs - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestEvents(t *testing.T) { - - expectedURL := "/events" - - filters := filters.NewArgs() - filters.Add("type", events.ContainerEventType) - expectedFiltersJSON := fmt.Sprintf(`{"type":{"%s":true}}`, events.ContainerEventType) - - eventsCases := []struct { - options types.EventsOptions - events []events.Message - expectedEvents map[string]bool - expectedQueryParams map[string]string - }{ - { - options: types.EventsOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": expectedFiltersJSON, - }, - events: []events.Message{}, - expectedEvents: make(map[string]bool), - }, - { - options: types.EventsOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": expectedFiltersJSON, - }, - events: []events.Message{ - { - Type: "container", - ID: "1", - Action: "create", - }, - { - Type: "container", - ID: "2", - Action: "die", - }, - { - Type: "container", - ID: "3", - Action: "create", - }, - }, - expectedEvents: map[string]bool{ - "1": true, - "2": true, - "3": true, - }, - }, - } - - for _, eventsCase := range eventsCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - - for key, expected := range eventsCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - - buffer := new(bytes.Buffer) - - for _, e := range eventsCase.events { - b, _ := json.Marshal(e) - buffer.Write(b) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(buffer), - }, nil - }), - } - - messages, errs := client.Events(context.Background(), eventsCase.options) - - loop: - for { - select { - case err := <-errs: - if err != nil && err != io.EOF { - t.Fatal(err) - } - - break loop - case e := <-messages: - _, ok := eventsCase.expectedEvents[e.ID] - if !ok { - t.Fatalf("event received not expected with action %s & id %s", e.Action, e.ID) - } - } - } - } -} diff --git a/vendor/github.com/docker/docker/client/hijack.go b/vendor/github.com/docker/docker/client/hijack.go deleted file mode 100644 index 74c53f5..0000000 --- a/vendor/github.com/docker/docker/client/hijack.go +++ /dev/null @@ -1,177 +0,0 @@ -package client - -import ( - "crypto/tls" - "errors" - "fmt" - "net" - "net/http" - "net/http/httputil" - "net/url" - "strings" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/tlsconfig" - "github.com/docker/go-connections/sockets" - "golang.org/x/net/context" -) - -// tlsClientCon holds tls information and a dialed connection. -type tlsClientCon struct { - *tls.Conn - rawConn net.Conn -} - -func (c *tlsClientCon) CloseWrite() error { - // Go standard tls.Conn doesn't provide the CloseWrite() method so we do it - // on its underlying connection. - if conn, ok := c.rawConn.(types.CloseWriter); ok { - return conn.CloseWrite() - } - return nil -} - -// postHijacked sends a POST request and hijacks the connection. -func (cli *Client) postHijacked(ctx context.Context, path string, query url.Values, body interface{}, headers map[string][]string) (types.HijackedResponse, error) { - bodyEncoded, err := encodeData(body) - if err != nil { - return types.HijackedResponse{}, err - } - - apiPath := cli.getAPIPath(path, query) - req, err := http.NewRequest("POST", apiPath, bodyEncoded) - if err != nil { - return types.HijackedResponse{}, err - } - req = cli.addHeaders(req, headers) - - req.Host = cli.addr - req.Header.Set("Connection", "Upgrade") - req.Header.Set("Upgrade", "tcp") - - conn, err := dial(cli.proto, cli.addr, resolveTLSConfig(cli.client.Transport)) - if err != nil { - if strings.Contains(err.Error(), "connection refused") { - return types.HijackedResponse{}, fmt.Errorf("Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?") - } - return types.HijackedResponse{}, err - } - - // When we set up a TCP connection for hijack, there could be long periods - // of inactivity (a long running command with no output) that in certain - // network setups may cause ECONNTIMEOUT, leaving the client in an unknown - // state. Setting TCP KeepAlive on the socket connection will prohibit - // ECONNTIMEOUT unless the socket connection truly is broken - if tcpConn, ok := conn.(*net.TCPConn); ok { - tcpConn.SetKeepAlive(true) - tcpConn.SetKeepAlivePeriod(30 * time.Second) - } - - clientconn := httputil.NewClientConn(conn, nil) - defer clientconn.Close() - - // Server hijacks the connection, error 'connection closed' expected - _, err = clientconn.Do(req) - - rwc, br := clientconn.Hijack() - - return types.HijackedResponse{Conn: rwc, Reader: br}, err -} - -func tlsDial(network, addr string, config *tls.Config) (net.Conn, error) { - return tlsDialWithDialer(new(net.Dialer), network, addr, config) -} - -// We need to copy Go's implementation of tls.Dial (pkg/cryptor/tls/tls.go) in -// order to return our custom tlsClientCon struct which holds both the tls.Conn -// object _and_ its underlying raw connection. The rationale for this is that -// we need to be able to close the write end of the connection when attaching, -// which tls.Conn does not provide. -func tlsDialWithDialer(dialer *net.Dialer, network, addr string, config *tls.Config) (net.Conn, error) { - // We want the Timeout and Deadline values from dialer to cover the - // whole process: TCP connection and TLS handshake. This means that we - // also need to start our own timers now. - timeout := dialer.Timeout - - if !dialer.Deadline.IsZero() { - deadlineTimeout := dialer.Deadline.Sub(time.Now()) - if timeout == 0 || deadlineTimeout < timeout { - timeout = deadlineTimeout - } - } - - var errChannel chan error - - if timeout != 0 { - errChannel = make(chan error, 2) - time.AfterFunc(timeout, func() { - errChannel <- errors.New("") - }) - } - - proxyDialer, err := sockets.DialerFromEnvironment(dialer) - if err != nil { - return nil, err - } - - rawConn, err := proxyDialer.Dial(network, addr) - if err != nil { - return nil, err - } - // When we set up a TCP connection for hijack, there could be long periods - // of inactivity (a long running command with no output) that in certain - // network setups may cause ECONNTIMEOUT, leaving the client in an unknown - // state. Setting TCP KeepAlive on the socket connection will prohibit - // ECONNTIMEOUT unless the socket connection truly is broken - if tcpConn, ok := rawConn.(*net.TCPConn); ok { - tcpConn.SetKeepAlive(true) - tcpConn.SetKeepAlivePeriod(30 * time.Second) - } - - colonPos := strings.LastIndex(addr, ":") - if colonPos == -1 { - colonPos = len(addr) - } - hostname := addr[:colonPos] - - // If no ServerName is set, infer the ServerName - // from the hostname we're connecting to. - if config.ServerName == "" { - // Make a copy to avoid polluting argument or default. - config = tlsconfig.Clone(config) - config.ServerName = hostname - } - - conn := tls.Client(rawConn, config) - - if timeout == 0 { - err = conn.Handshake() - } else { - go func() { - errChannel <- conn.Handshake() - }() - - err = <-errChannel - } - - if err != nil { - rawConn.Close() - return nil, err - } - - // This is Docker difference with standard's crypto/tls package: returned a - // wrapper which holds both the TLS and raw connections. - return &tlsClientCon{conn, rawConn}, nil -} - -func dial(proto, addr string, tlsConfig *tls.Config) (net.Conn, error) { - if tlsConfig != nil && proto != "unix" && proto != "npipe" { - // Notice this isn't Go standard's tls.Dial function - return tlsDial(proto, addr, tlsConfig) - } - if proto == "npipe" { - return sockets.DialPipe(addr, 32*time.Second) - } - return net.Dial(proto, addr) -} diff --git a/vendor/github.com/docker/docker/client/image_build.go b/vendor/github.com/docker/docker/client/image_build.go deleted file mode 100644 index 6fde75d..0000000 --- a/vendor/github.com/docker/docker/client/image_build.go +++ /dev/null @@ -1,123 +0,0 @@ -package client - -import ( - "encoding/base64" - "encoding/json" - "io" - "net/http" - "net/url" - "strconv" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" -) - -// ImageBuild sends request to the daemon to build images. -// The Body in the response implement an io.ReadCloser and it's up to the caller to -// close it. -func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) { - query, err := cli.imageBuildOptionsToQuery(options) - if err != nil { - return types.ImageBuildResponse{}, err - } - - headers := http.Header(make(map[string][]string)) - buf, err := json.Marshal(options.AuthConfigs) - if err != nil { - return types.ImageBuildResponse{}, err - } - headers.Add("X-Registry-Config", base64.URLEncoding.EncodeToString(buf)) - headers.Set("Content-Type", "application/tar") - - serverResp, err := cli.postRaw(ctx, "/build", query, buildContext, headers) - if err != nil { - return types.ImageBuildResponse{}, err - } - - osType := getDockerOS(serverResp.header.Get("Server")) - - return types.ImageBuildResponse{ - Body: serverResp.body, - OSType: osType, - }, nil -} - -func (cli *Client) imageBuildOptionsToQuery(options types.ImageBuildOptions) (url.Values, error) { - query := url.Values{ - "t": options.Tags, - "securityopt": options.SecurityOpt, - } - if options.SuppressOutput { - query.Set("q", "1") - } - if options.RemoteContext != "" { - query.Set("remote", options.RemoteContext) - } - if options.NoCache { - query.Set("nocache", "1") - } - if options.Remove { - query.Set("rm", "1") - } else { - query.Set("rm", "0") - } - - if options.ForceRemove { - query.Set("forcerm", "1") - } - - if options.PullParent { - query.Set("pull", "1") - } - - if options.Squash { - if err := cli.NewVersionError("1.25", "squash"); err != nil { - return query, err - } - query.Set("squash", "1") - } - - if !container.Isolation.IsDefault(options.Isolation) { - query.Set("isolation", string(options.Isolation)) - } - - query.Set("cpusetcpus", options.CPUSetCPUs) - query.Set("networkmode", options.NetworkMode) - query.Set("cpusetmems", options.CPUSetMems) - query.Set("cpushares", strconv.FormatInt(options.CPUShares, 10)) - query.Set("cpuquota", strconv.FormatInt(options.CPUQuota, 10)) - query.Set("cpuperiod", strconv.FormatInt(options.CPUPeriod, 10)) - query.Set("memory", strconv.FormatInt(options.Memory, 10)) - query.Set("memswap", strconv.FormatInt(options.MemorySwap, 10)) - query.Set("cgroupparent", options.CgroupParent) - query.Set("shmsize", strconv.FormatInt(options.ShmSize, 10)) - query.Set("dockerfile", options.Dockerfile) - - ulimitsJSON, err := json.Marshal(options.Ulimits) - if err != nil { - return query, err - } - query.Set("ulimits", string(ulimitsJSON)) - - buildArgsJSON, err := json.Marshal(options.BuildArgs) - if err != nil { - return query, err - } - query.Set("buildargs", string(buildArgsJSON)) - - labelsJSON, err := json.Marshal(options.Labels) - if err != nil { - return query, err - } - query.Set("labels", string(labelsJSON)) - - cacheFromJSON, err := json.Marshal(options.CacheFrom) - if err != nil { - return query, err - } - query.Set("cachefrom", string(cacheFromJSON)) - - return query, nil -} diff --git a/vendor/github.com/docker/docker/client/image_build_test.go b/vendor/github.com/docker/docker/client/image_build_test.go deleted file mode 100644 index b9d04f8..0000000 --- a/vendor/github.com/docker/docker/client/image_build_test.go +++ /dev/null @@ -1,233 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "reflect" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/go-units" -) - -func TestImageBuildError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageBuild(context.Background(), nil, types.ImageBuildOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageBuild(t *testing.T) { - v1 := "value1" - v2 := "value2" - emptyRegistryConfig := "bnVsbA==" - buildCases := []struct { - buildOptions types.ImageBuildOptions - expectedQueryParams map[string]string - expectedTags []string - expectedRegistryConfig string - }{ - { - buildOptions: types.ImageBuildOptions{ - SuppressOutput: true, - NoCache: true, - Remove: true, - ForceRemove: true, - PullParent: true, - }, - expectedQueryParams: map[string]string{ - "q": "1", - "nocache": "1", - "rm": "1", - "forcerm": "1", - "pull": "1", - }, - expectedTags: []string{}, - expectedRegistryConfig: emptyRegistryConfig, - }, - { - buildOptions: types.ImageBuildOptions{ - SuppressOutput: false, - NoCache: false, - Remove: false, - ForceRemove: false, - PullParent: false, - }, - expectedQueryParams: map[string]string{ - "q": "", - "nocache": "", - "rm": "0", - "forcerm": "", - "pull": "", - }, - expectedTags: []string{}, - expectedRegistryConfig: emptyRegistryConfig, - }, - { - buildOptions: types.ImageBuildOptions{ - RemoteContext: "remoteContext", - Isolation: container.Isolation("isolation"), - CPUSetCPUs: "2", - CPUSetMems: "12", - CPUShares: 20, - CPUQuota: 10, - CPUPeriod: 30, - Memory: 256, - MemorySwap: 512, - ShmSize: 10, - CgroupParent: "cgroup_parent", - Dockerfile: "Dockerfile", - }, - expectedQueryParams: map[string]string{ - "remote": "remoteContext", - "isolation": "isolation", - "cpusetcpus": "2", - "cpusetmems": "12", - "cpushares": "20", - "cpuquota": "10", - "cpuperiod": "30", - "memory": "256", - "memswap": "512", - "shmsize": "10", - "cgroupparent": "cgroup_parent", - "dockerfile": "Dockerfile", - "rm": "0", - }, - expectedTags: []string{}, - expectedRegistryConfig: emptyRegistryConfig, - }, - { - buildOptions: types.ImageBuildOptions{ - BuildArgs: map[string]*string{ - "ARG1": &v1, - "ARG2": &v2, - "ARG3": nil, - }, - }, - expectedQueryParams: map[string]string{ - "buildargs": `{"ARG1":"value1","ARG2":"value2","ARG3":null}`, - "rm": "0", - }, - expectedTags: []string{}, - expectedRegistryConfig: emptyRegistryConfig, - }, - { - buildOptions: types.ImageBuildOptions{ - Ulimits: []*units.Ulimit{ - { - Name: "nproc", - Hard: 65557, - Soft: 65557, - }, - { - Name: "nofile", - Hard: 20000, - Soft: 40000, - }, - }, - }, - expectedQueryParams: map[string]string{ - "ulimits": `[{"Name":"nproc","Hard":65557,"Soft":65557},{"Name":"nofile","Hard":20000,"Soft":40000}]`, - "rm": "0", - }, - expectedTags: []string{}, - expectedRegistryConfig: emptyRegistryConfig, - }, - { - buildOptions: types.ImageBuildOptions{ - AuthConfigs: map[string]types.AuthConfig{ - "https://index.docker.io/v1/": { - Auth: "dG90bwo=", - }, - }, - }, - expectedQueryParams: map[string]string{ - "rm": "0", - }, - expectedTags: []string{}, - expectedRegistryConfig: "eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsiYXV0aCI6ImRHOTBid289In19", - }, - } - for _, buildCase := range buildCases { - expectedURL := "/build" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - // Check request headers - registryConfig := r.Header.Get("X-Registry-Config") - if registryConfig != buildCase.expectedRegistryConfig { - return nil, fmt.Errorf("X-Registry-Config header not properly set in the request. Expected '%s', got %s", buildCase.expectedRegistryConfig, registryConfig) - } - contentType := r.Header.Get("Content-Type") - if contentType != "application/tar" { - return nil, fmt.Errorf("Content-type header not properly set in the request. Expected 'application/tar', got %s", contentType) - } - - // Check query parameters - query := r.URL.Query() - for key, expected := range buildCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - - // Check tags - if len(buildCase.expectedTags) > 0 { - tags := query["t"] - if !reflect.DeepEqual(tags, buildCase.expectedTags) { - return nil, fmt.Errorf("t (tags) not set in URL query properly. Expected '%s', got %s", buildCase.expectedTags, tags) - } - } - - headers := http.Header{} - headers.Add("Server", "Docker/v1.23 (MyOS)") - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - Header: headers, - }, nil - }), - } - buildResponse, err := client.ImageBuild(context.Background(), nil, buildCase.buildOptions) - if err != nil { - t.Fatal(err) - } - if buildResponse.OSType != "MyOS" { - t.Fatalf("expected OSType to be 'MyOS', got %s", buildResponse.OSType) - } - response, err := ioutil.ReadAll(buildResponse.Body) - if err != nil { - t.Fatal(err) - } - buildResponse.Body.Close() - if string(response) != "body" { - t.Fatalf("expected Body to contain 'body' string, got %s", response) - } - } -} - -func TestGetDockerOS(t *testing.T) { - cases := map[string]string{ - "Docker/v1.22 (linux)": "linux", - "Docker/v1.22 (windows)": "windows", - "Foo/v1.22 (bar)": "", - } - for header, os := range cases { - g := getDockerOS(header) - if g != os { - t.Fatalf("Expected %s, got %s", os, g) - } - } -} diff --git a/vendor/github.com/docker/docker/client/image_create.go b/vendor/github.com/docker/docker/client/image_create.go deleted file mode 100644 index cf023a7..0000000 --- a/vendor/github.com/docker/docker/client/image_create.go +++ /dev/null @@ -1,34 +0,0 @@ -package client - -import ( - "io" - "net/url" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/reference" -) - -// ImageCreate creates a new image based in the parent options. -// It returns the JSON content in the response body. -func (cli *Client) ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) { - repository, tag, err := reference.Parse(parentReference) - if err != nil { - return nil, err - } - - query := url.Values{} - query.Set("fromImage", repository) - query.Set("tag", tag) - resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth) - if err != nil { - return nil, err - } - return resp.body, nil -} - -func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) { - headers := map[string][]string{"X-Registry-Auth": {registryAuth}} - return cli.post(ctx, "/images/create", query, nil, headers) -} diff --git a/vendor/github.com/docker/docker/client/image_create_test.go b/vendor/github.com/docker/docker/client/image_create_test.go deleted file mode 100644 index 5c2edd2..0000000 --- a/vendor/github.com/docker/docker/client/image_create_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestImageCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageCreate(context.Background(), "reference", types.ImageCreateOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestImageCreate(t *testing.T) { - expectedURL := "/images/create" - expectedImage := "test:5000/my_image" - expectedTag := "sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - expectedReference := fmt.Sprintf("%s@%s", expectedImage, expectedTag) - expectedRegistryAuth := "eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsiYXV0aCI6ImRHOTBid289IiwiZW1haWwiOiJqb2huQGRvZS5jb20ifX0=" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - registryAuth := r.Header.Get("X-Registry-Auth") - if registryAuth != expectedRegistryAuth { - return nil, fmt.Errorf("X-Registry-Auth header not properly set in the request. Expected '%s', got %s", expectedRegistryAuth, registryAuth) - } - - query := r.URL.Query() - fromImage := query.Get("fromImage") - if fromImage != expectedImage { - return nil, fmt.Errorf("fromImage not set in URL query properly. Expected '%s', got %s", expectedImage, fromImage) - } - - tag := query.Get("tag") - if tag != expectedTag { - return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", expectedTag, tag) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - createResponse, err := client.ImageCreate(context.Background(), expectedReference, types.ImageCreateOptions{ - RegistryAuth: expectedRegistryAuth, - }) - if err != nil { - t.Fatal(err) - } - response, err := ioutil.ReadAll(createResponse) - if err != nil { - t.Fatal(err) - } - if err = createResponse.Close(); err != nil { - t.Fatal(err) - } - if string(response) != "body" { - t.Fatalf("expected Body to contain 'body' string, got %s", response) - } -} diff --git a/vendor/github.com/docker/docker/client/image_history.go b/vendor/github.com/docker/docker/client/image_history.go deleted file mode 100644 index acb1ee9..0000000 --- a/vendor/github.com/docker/docker/client/image_history.go +++ /dev/null @@ -1,22 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ImageHistory returns the changes in an image in history format. -func (cli *Client) ImageHistory(ctx context.Context, imageID string) ([]types.ImageHistory, error) { - var history []types.ImageHistory - serverResp, err := cli.get(ctx, "/images/"+imageID+"/history", url.Values{}, nil) - if err != nil { - return history, err - } - - err = json.NewDecoder(serverResp.body).Decode(&history) - ensureReaderClosed(serverResp) - return history, err -} diff --git a/vendor/github.com/docker/docker/client/image_history_test.go b/vendor/github.com/docker/docker/client/image_history_test.go deleted file mode 100644 index 729edb1..0000000 --- a/vendor/github.com/docker/docker/client/image_history_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestImageHistoryError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageHistory(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestImageHistory(t *testing.T) { - expectedURL := "/images/image_id/history" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - b, err := json.Marshal([]types.ImageHistory{ - { - ID: "image_id1", - Tags: []string{"tag1", "tag2"}, - }, - { - ID: "image_id2", - Tags: []string{"tag1", "tag2"}, - }, - }) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - imageHistories, err := client.ImageHistory(context.Background(), "image_id") - if err != nil { - t.Fatal(err) - } - if len(imageHistories) != 2 { - t.Fatalf("expected 2 containers, got %v", imageHistories) - } -} diff --git a/vendor/github.com/docker/docker/client/image_import.go b/vendor/github.com/docker/docker/client/image_import.go deleted file mode 100644 index c6f154b..0000000 --- a/vendor/github.com/docker/docker/client/image_import.go +++ /dev/null @@ -1,37 +0,0 @@ -package client - -import ( - "io" - "net/url" - - "golang.org/x/net/context" - - "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" -) - -// ImageImport creates a new image based in the source options. -// It returns the JSON content in the response body. -func (cli *Client) ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) { - if ref != "" { - //Check if the given image name can be resolved - if _, err := reference.ParseNamed(ref); err != nil { - return nil, err - } - } - - query := url.Values{} - query.Set("fromSrc", source.SourceName) - query.Set("repo", ref) - query.Set("tag", options.Tag) - query.Set("message", options.Message) - for _, change := range options.Changes { - query.Add("changes", change) - } - - resp, err := cli.postRaw(ctx, "/images/create", query, source.Source, nil) - if err != nil { - return nil, err - } - return resp.body, nil -} diff --git a/vendor/github.com/docker/docker/client/image_import_test.go b/vendor/github.com/docker/docker/client/image_import_test.go deleted file mode 100644 index e309be7..0000000 --- a/vendor/github.com/docker/docker/client/image_import_test.go +++ /dev/null @@ -1,81 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "reflect" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestImageImportError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageImport(context.Background(), types.ImageImportSource{}, "image:tag", types.ImageImportOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestImageImport(t *testing.T) { - expectedURL := "/images/create" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - query := r.URL.Query() - fromSrc := query.Get("fromSrc") - if fromSrc != "image_source" { - return nil, fmt.Errorf("fromSrc not set in URL query properly. Expected 'image_source', got %s", fromSrc) - } - repo := query.Get("repo") - if repo != "repository_name:imported" { - return nil, fmt.Errorf("repo not set in URL query properly. Expected 'repository_name', got %s", repo) - } - tag := query.Get("tag") - if tag != "imported" { - return nil, fmt.Errorf("tag not set in URL query properly. Expected 'imported', got %s", tag) - } - message := query.Get("message") - if message != "A message" { - return nil, fmt.Errorf("message not set in URL query properly. Expected 'A message', got %s", message) - } - changes := query["changes"] - expectedChanges := []string{"change1", "change2"} - if !reflect.DeepEqual(expectedChanges, changes) { - return nil, fmt.Errorf("changes not set in URL query properly. Expected %v, got %v", expectedChanges, changes) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - importResponse, err := client.ImageImport(context.Background(), types.ImageImportSource{ - Source: strings.NewReader("source"), - SourceName: "image_source", - }, "repository_name:imported", types.ImageImportOptions{ - Tag: "imported", - Message: "A message", - Changes: []string{"change1", "change2"}, - }) - if err != nil { - t.Fatal(err) - } - response, err := ioutil.ReadAll(importResponse) - if err != nil { - t.Fatal(err) - } - importResponse.Close() - if string(response) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(response)) - } -} diff --git a/vendor/github.com/docker/docker/client/image_inspect.go b/vendor/github.com/docker/docker/client/image_inspect.go deleted file mode 100644 index b3a64ce..0000000 --- a/vendor/github.com/docker/docker/client/image_inspect.go +++ /dev/null @@ -1,33 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ImageInspectWithRaw returns the image information and its raw representation. -func (cli *Client) ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error) { - serverResp, err := cli.get(ctx, "/images/"+imageID+"/json", nil, nil) - if err != nil { - if serverResp.statusCode == http.StatusNotFound { - return types.ImageInspect{}, nil, imageNotFoundError{imageID} - } - return types.ImageInspect{}, nil, err - } - defer ensureReaderClosed(serverResp) - - body, err := ioutil.ReadAll(serverResp.body) - if err != nil { - return types.ImageInspect{}, nil, err - } - - var response types.ImageInspect - rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&response) - return response, body, err -} diff --git a/vendor/github.com/docker/docker/client/image_inspect_test.go b/vendor/github.com/docker/docker/client/image_inspect_test.go deleted file mode 100644 index 74a4e49..0000000 --- a/vendor/github.com/docker/docker/client/image_inspect_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "reflect" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestImageInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.ImageInspectWithRaw(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageInspectImageNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, _, err := client.ImageInspectWithRaw(context.Background(), "unknown") - if err == nil || !IsErrImageNotFound(err) { - t.Fatalf("expected an imageNotFound error, got %v", err) - } -} - -func TestImageInspect(t *testing.T) { - expectedURL := "/images/image_id/json" - expectedTags := []string{"tag1", "tag2"} - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - content, err := json.Marshal(types.ImageInspect{ - ID: "image_id", - RepoTags: expectedTags, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - imageInspect, _, err := client.ImageInspectWithRaw(context.Background(), "image_id") - if err != nil { - t.Fatal(err) - } - if imageInspect.ID != "image_id" { - t.Fatalf("expected `image_id`, got %s", imageInspect.ID) - } - if !reflect.DeepEqual(imageInspect.RepoTags, expectedTags) { - t.Fatalf("expected `%v`, got %v", expectedTags, imageInspect.RepoTags) - } -} diff --git a/vendor/github.com/docker/docker/client/image_list.go b/vendor/github.com/docker/docker/client/image_list.go deleted file mode 100644 index f26464f..0000000 --- a/vendor/github.com/docker/docker/client/image_list.go +++ /dev/null @@ -1,45 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/versions" - "golang.org/x/net/context" -) - -// ImageList returns a list of images in the docker host. -func (cli *Client) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) { - var images []types.ImageSummary - query := url.Values{} - - optionFilters := options.Filters - referenceFilters := optionFilters.Get("reference") - if versions.LessThan(cli.version, "1.25") && len(referenceFilters) > 0 { - query.Set("filter", referenceFilters[0]) - for _, filterValue := range referenceFilters { - optionFilters.Del("reference", filterValue) - } - } - if optionFilters.Len() > 0 { - filterJSON, err := filters.ToParamWithVersion(cli.version, optionFilters) - if err != nil { - return images, err - } - query.Set("filters", filterJSON) - } - if options.All { - query.Set("all", "1") - } - - serverResp, err := cli.get(ctx, "/images/json", query, nil) - if err != nil { - return images, err - } - - err = json.NewDecoder(serverResp.body).Decode(&images) - ensureReaderClosed(serverResp) - return images, err -} diff --git a/vendor/github.com/docker/docker/client/image_list_test.go b/vendor/github.com/docker/docker/client/image_list_test.go deleted file mode 100644 index 7c4a464..0000000 --- a/vendor/github.com/docker/docker/client/image_list_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -func TestImageListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ImageList(context.Background(), types.ImageListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageList(t *testing.T) { - expectedURL := "/images/json" - - noDanglingfilters := filters.NewArgs() - noDanglingfilters.Add("dangling", "false") - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - filters.Add("dangling", "true") - - listCases := []struct { - options types.ImageListOptions - expectedQueryParams map[string]string - }{ - { - options: types.ImageListOptions{}, - expectedQueryParams: map[string]string{ - "all": "", - "filter": "", - "filters": "", - }, - }, - { - options: types.ImageListOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "all": "", - "filter": "", - "filters": `{"dangling":{"true":true},"label":{"label1":true,"label2":true}}`, - }, - }, - { - options: types.ImageListOptions{ - Filters: noDanglingfilters, - }, - expectedQueryParams: map[string]string{ - "all": "", - "filter": "", - "filters": `{"dangling":{"false":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]types.ImageSummary{ - { - ID: "image_id2", - }, - { - ID: "image_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - images, err := client.ImageList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(images) != 2 { - t.Fatalf("expected 2 images, got %v", images) - } - } -} - -func TestImageListApiBefore125(t *testing.T) { - expectedFilter := "image:tag" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - query := req.URL.Query() - actualFilter := query.Get("filter") - if actualFilter != expectedFilter { - return nil, fmt.Errorf("filter not set in URL query properly. Expected '%s', got %s", expectedFilter, actualFilter) - } - actualFilters := query.Get("filters") - if actualFilters != "" { - return nil, fmt.Errorf("filters should have not been present, were with value: %s", actualFilters) - } - content, err := json.Marshal([]types.ImageSummary{ - { - ID: "image_id2", - }, - { - ID: "image_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - version: "1.24", - } - - filters := filters.NewArgs() - filters.Add("reference", "image:tag") - - options := types.ImageListOptions{ - Filters: filters, - } - - images, err := client.ImageList(context.Background(), options) - if err != nil { - t.Fatal(err) - } - if len(images) != 2 { - t.Fatalf("expected 2 images, got %v", images) - } -} diff --git a/vendor/github.com/docker/docker/client/image_load.go b/vendor/github.com/docker/docker/client/image_load.go deleted file mode 100644 index 77aaf1a..0000000 --- a/vendor/github.com/docker/docker/client/image_load.go +++ /dev/null @@ -1,30 +0,0 @@ -package client - -import ( - "io" - "net/url" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -// ImageLoad loads an image in the docker host from the client host. -// It's up to the caller to close the io.ReadCloser in the -// ImageLoadResponse returned by this function. -func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error) { - v := url.Values{} - v.Set("quiet", "0") - if quiet { - v.Set("quiet", "1") - } - headers := map[string][]string{"Content-Type": {"application/x-tar"}} - resp, err := cli.postRaw(ctx, "/images/load", v, input, headers) - if err != nil { - return types.ImageLoadResponse{}, err - } - return types.ImageLoadResponse{ - Body: resp.body, - JSON: resp.header.Get("Content-Type") == "application/json", - }, nil -} diff --git a/vendor/github.com/docker/docker/client/image_load_test.go b/vendor/github.com/docker/docker/client/image_load_test.go deleted file mode 100644 index 68dc14f..0000000 --- a/vendor/github.com/docker/docker/client/image_load_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestImageLoadError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ImageLoad(context.Background(), nil, true) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageLoad(t *testing.T) { - expectedURL := "/images/load" - expectedInput := "inputBody" - expectedOutput := "outputBody" - loadCases := []struct { - quiet bool - responseContentType string - expectedResponseJSON bool - expectedQueryParams map[string]string - }{ - { - quiet: false, - responseContentType: "text/plain", - expectedResponseJSON: false, - expectedQueryParams: map[string]string{ - "quiet": "0", - }, - }, - { - quiet: true, - responseContentType: "application/json", - expectedResponseJSON: true, - expectedQueryParams: map[string]string{ - "quiet": "1", - }, - }, - } - for _, loadCase := range loadCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - contentType := req.Header.Get("Content-Type") - if contentType != "application/x-tar" { - return nil, fmt.Errorf("content-type not set in URL headers properly. Expected 'application/x-tar', got %s", contentType) - } - query := req.URL.Query() - for key, expected := range loadCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - headers := http.Header{} - headers.Add("Content-Type", loadCase.responseContentType) - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(expectedOutput))), - Header: headers, - }, nil - }), - } - - input := bytes.NewReader([]byte(expectedInput)) - imageLoadResponse, err := client.ImageLoad(context.Background(), input, loadCase.quiet) - if err != nil { - t.Fatal(err) - } - if imageLoadResponse.JSON != loadCase.expectedResponseJSON { - t.Fatalf("expected a JSON response, was not.") - } - body, err := ioutil.ReadAll(imageLoadResponse.Body) - if err != nil { - t.Fatal(err) - } - if string(body) != expectedOutput { - t.Fatalf("expected %s, got %s", expectedOutput, string(body)) - } - } -} diff --git a/vendor/github.com/docker/docker/client/image_prune.go b/vendor/github.com/docker/docker/client/image_prune.go deleted file mode 100644 index 5ef98b7..0000000 --- a/vendor/github.com/docker/docker/client/image_prune.go +++ /dev/null @@ -1,36 +0,0 @@ -package client - -import ( - "encoding/json" - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -// ImagesPrune requests the daemon to delete unused data -func (cli *Client) ImagesPrune(ctx context.Context, pruneFilters filters.Args) (types.ImagesPruneReport, error) { - var report types.ImagesPruneReport - - if err := cli.NewVersionError("1.25", "image prune"); err != nil { - return report, err - } - - query, err := getFiltersQuery(pruneFilters) - if err != nil { - return report, err - } - - serverResp, err := cli.post(ctx, "/images/prune", query, nil, nil) - if err != nil { - return report, err - } - defer ensureReaderClosed(serverResp) - - if err := json.NewDecoder(serverResp.body).Decode(&report); err != nil { - return report, fmt.Errorf("Error retrieving disk usage: %v", err) - } - - return report, nil -} diff --git a/vendor/github.com/docker/docker/client/image_pull.go b/vendor/github.com/docker/docker/client/image_pull.go deleted file mode 100644 index 3bffdb7..0000000 --- a/vendor/github.com/docker/docker/client/image_pull.go +++ /dev/null @@ -1,46 +0,0 @@ -package client - -import ( - "io" - "net/http" - "net/url" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/reference" -) - -// ImagePull requests the docker host to pull an image from a remote registry. -// It executes the privileged function if the operation is unauthorized -// and it tries one more time. -// It's up to the caller to handle the io.ReadCloser and close it properly. -// -// FIXME(vdemeester): there is currently used in a few way in docker/docker -// - if not in trusted content, ref is used to pass the whole reference, and tag is empty -// - if in trusted content, ref is used to pass the reference name, and tag for the digest -func (cli *Client) ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error) { - repository, tag, err := reference.Parse(ref) - if err != nil { - return nil, err - } - - query := url.Values{} - query.Set("fromImage", repository) - if tag != "" && !options.All { - query.Set("tag", tag) - } - - resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth) - if resp.statusCode == http.StatusUnauthorized && options.PrivilegeFunc != nil { - newAuthHeader, privilegeErr := options.PrivilegeFunc() - if privilegeErr != nil { - return nil, privilegeErr - } - resp, err = cli.tryImageCreate(ctx, query, newAuthHeader) - } - if err != nil { - return nil, err - } - return resp.body, nil -} diff --git a/vendor/github.com/docker/docker/client/image_pull_test.go b/vendor/github.com/docker/docker/client/image_pull_test.go deleted file mode 100644 index fe6bafe..0000000 --- a/vendor/github.com/docker/docker/client/image_pull_test.go +++ /dev/null @@ -1,199 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestImagePullReferenceParseError(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - return nil, nil - }), - } - // An empty reference is an invalid reference - _, err := client.ImagePull(context.Background(), "", types.ImagePullOptions{}) - if err == nil || err.Error() != "repository name must have at least one component" { - t.Fatalf("expected an error, got %v", err) - } -} - -func TestImagePullAnyError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImagePullStatusUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - _, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{}) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImagePullWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "", fmt.Errorf("Error requesting privilege") - } - _, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error requesting privilege" { - t.Fatalf("expected an error requesting privilege, got %v", err) - } -} - -func TestImagePullWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "a-auth-header", nil - } - _, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImagePullWithPrivilegedFuncNoError(t *testing.T) { - expectedURL := "/images/create" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - auth := req.Header.Get("X-Registry-Auth") - if auth == "NotValid" { - return &http.Response{ - StatusCode: http.StatusUnauthorized, - Body: ioutil.NopCloser(bytes.NewReader([]byte("Invalid credentials"))), - }, nil - } - if auth != "IAmValid" { - return nil, fmt.Errorf("Invalid auth header : expected %s, got %s", "IAmValid", auth) - } - query := req.URL.Query() - fromImage := query.Get("fromImage") - if fromImage != "myimage" { - return nil, fmt.Errorf("fromimage not set in URL query properly. Expected '%s', got %s", "myimage", fromImage) - } - tag := query.Get("tag") - if tag != "latest" { - return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", "latest", tag) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("hello world"))), - }, nil - }), - } - privilegeFunc := func() (string, error) { - return "IAmValid", nil - } - resp, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{ - RegistryAuth: "NotValid", - PrivilegeFunc: privilegeFunc, - }) - if err != nil { - t.Fatal(err) - } - body, err := ioutil.ReadAll(resp) - if err != nil { - t.Fatal(err) - } - if string(body) != "hello world" { - t.Fatalf("expected 'hello world', got %s", string(body)) - } -} - -func TestImagePullWithoutErrors(t *testing.T) { - expectedURL := "/images/create" - expectedOutput := "hello world" - pullCases := []struct { - all bool - reference string - expectedImage string - expectedTag string - }{ - { - all: false, - reference: "myimage", - expectedImage: "myimage", - expectedTag: "latest", - }, - { - all: false, - reference: "myimage:tag", - expectedImage: "myimage", - expectedTag: "tag", - }, - { - all: true, - reference: "myimage", - expectedImage: "myimage", - expectedTag: "", - }, - { - all: true, - reference: "myimage:anything", - expectedImage: "myimage", - expectedTag: "", - }, - } - for _, pullCase := range pullCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - fromImage := query.Get("fromImage") - if fromImage != pullCase.expectedImage { - return nil, fmt.Errorf("fromimage not set in URL query properly. Expected '%s', got %s", pullCase.expectedImage, fromImage) - } - tag := query.Get("tag") - if tag != pullCase.expectedTag { - return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", pullCase.expectedTag, tag) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(expectedOutput))), - }, nil - }), - } - resp, err := client.ImagePull(context.Background(), pullCase.reference, types.ImagePullOptions{ - All: pullCase.all, - }) - if err != nil { - t.Fatal(err) - } - body, err := ioutil.ReadAll(resp) - if err != nil { - t.Fatal(err) - } - if string(body) != expectedOutput { - t.Fatalf("expected '%s', got %s", expectedOutput, string(body)) - } - } -} diff --git a/vendor/github.com/docker/docker/client/image_push.go b/vendor/github.com/docker/docker/client/image_push.go deleted file mode 100644 index 8e73d28..0000000 --- a/vendor/github.com/docker/docker/client/image_push.go +++ /dev/null @@ -1,54 +0,0 @@ -package client - -import ( - "errors" - "io" - "net/http" - "net/url" - - "golang.org/x/net/context" - - distreference "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" -) - -// ImagePush requests the docker host to push an image to a remote registry. -// It executes the privileged function if the operation is unauthorized -// and it tries one more time. -// It's up to the caller to handle the io.ReadCloser and close it properly. -func (cli *Client) ImagePush(ctx context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error) { - distributionRef, err := distreference.ParseNamed(ref) - if err != nil { - return nil, err - } - - if _, isCanonical := distributionRef.(distreference.Canonical); isCanonical { - return nil, errors.New("cannot push a digest reference") - } - - var tag = "" - if nameTaggedRef, isNamedTagged := distributionRef.(distreference.NamedTagged); isNamedTagged { - tag = nameTaggedRef.Tag() - } - - query := url.Values{} - query.Set("tag", tag) - - resp, err := cli.tryImagePush(ctx, distributionRef.Name(), query, options.RegistryAuth) - if resp.statusCode == http.StatusUnauthorized && options.PrivilegeFunc != nil { - newAuthHeader, privilegeErr := options.PrivilegeFunc() - if privilegeErr != nil { - return nil, privilegeErr - } - resp, err = cli.tryImagePush(ctx, distributionRef.Name(), query, newAuthHeader) - } - if err != nil { - return nil, err - } - return resp.body, nil -} - -func (cli *Client) tryImagePush(ctx context.Context, imageID string, query url.Values, registryAuth string) (serverResponse, error) { - headers := map[string][]string{"X-Registry-Auth": {registryAuth}} - return cli.post(ctx, "/images/"+imageID+"/push", query, nil, headers) -} diff --git a/vendor/github.com/docker/docker/client/image_push_test.go b/vendor/github.com/docker/docker/client/image_push_test.go deleted file mode 100644 index b52da8b..0000000 --- a/vendor/github.com/docker/docker/client/image_push_test.go +++ /dev/null @@ -1,180 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" -) - -func TestImagePushReferenceError(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - return nil, nil - }), - } - // An empty reference is an invalid reference - _, err := client.ImagePush(context.Background(), "", types.ImagePushOptions{}) - if err == nil || err.Error() != "repository name must have at least one component" { - t.Fatalf("expected an error, got %v", err) - } - // An canonical reference cannot be pushed - _, err = client.ImagePush(context.Background(), "repo@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", types.ImagePushOptions{}) - if err == nil || err.Error() != "cannot push a digest reference" { - t.Fatalf("expected an error, got %v", err) - } -} - -func TestImagePushAnyError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImagePush(context.Background(), "myimage", types.ImagePushOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImagePushStatusUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - _, err := client.ImagePush(context.Background(), "myimage", types.ImagePushOptions{}) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImagePushWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "", fmt.Errorf("Error requesting privilege") - } - _, err := client.ImagePush(context.Background(), "myimage", types.ImagePushOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error requesting privilege" { - t.Fatalf("expected an error requesting privilege, got %v", err) - } -} - -func TestImagePushWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "a-auth-header", nil - } - _, err := client.ImagePush(context.Background(), "myimage", types.ImagePushOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImagePushWithPrivilegedFuncNoError(t *testing.T) { - expectedURL := "/images/myimage/push" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - auth := req.Header.Get("X-Registry-Auth") - if auth == "NotValid" { - return &http.Response{ - StatusCode: http.StatusUnauthorized, - Body: ioutil.NopCloser(bytes.NewReader([]byte("Invalid credentials"))), - }, nil - } - if auth != "IAmValid" { - return nil, fmt.Errorf("Invalid auth header : expected %s, got %s", "IAmValid", auth) - } - query := req.URL.Query() - tag := query.Get("tag") - if tag != "tag" { - return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", "tag", tag) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("hello world"))), - }, nil - }), - } - privilegeFunc := func() (string, error) { - return "IAmValid", nil - } - resp, err := client.ImagePush(context.Background(), "myimage:tag", types.ImagePushOptions{ - RegistryAuth: "NotValid", - PrivilegeFunc: privilegeFunc, - }) - if err != nil { - t.Fatal(err) - } - body, err := ioutil.ReadAll(resp) - if err != nil { - t.Fatal(err) - } - if string(body) != "hello world" { - t.Fatalf("expected 'hello world', got %s", string(body)) - } -} - -func TestImagePushWithoutErrors(t *testing.T) { - expectedOutput := "hello world" - expectedURLFormat := "/images/%s/push" - pullCases := []struct { - reference string - expectedImage string - expectedTag string - }{ - { - reference: "myimage", - expectedImage: "myimage", - expectedTag: "", - }, - { - reference: "myimage:tag", - expectedImage: "myimage", - expectedTag: "tag", - }, - } - for _, pullCase := range pullCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - expectedURL := fmt.Sprintf(expectedURLFormat, pullCase.expectedImage) - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - tag := query.Get("tag") - if tag != pullCase.expectedTag { - return nil, fmt.Errorf("tag not set in URL query properly. Expected '%s', got %s", pullCase.expectedTag, tag) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(expectedOutput))), - }, nil - }), - } - resp, err := client.ImagePush(context.Background(), pullCase.reference, types.ImagePushOptions{}) - if err != nil { - t.Fatal(err) - } - body, err := ioutil.ReadAll(resp) - if err != nil { - t.Fatal(err) - } - if string(body) != expectedOutput { - t.Fatalf("expected '%s', got %s", expectedOutput, string(body)) - } - } -} diff --git a/vendor/github.com/docker/docker/client/image_remove.go b/vendor/github.com/docker/docker/client/image_remove.go deleted file mode 100644 index 839e531..0000000 --- a/vendor/github.com/docker/docker/client/image_remove.go +++ /dev/null @@ -1,31 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ImageRemove removes an image from the docker host. -func (cli *Client) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDelete, error) { - query := url.Values{} - - if options.Force { - query.Set("force", "1") - } - if !options.PruneChildren { - query.Set("noprune", "1") - } - - resp, err := cli.delete(ctx, "/images/"+imageID, query, nil) - if err != nil { - return nil, err - } - - var dels []types.ImageDelete - err = json.NewDecoder(resp.body).Decode(&dels) - ensureReaderClosed(resp) - return dels, err -} diff --git a/vendor/github.com/docker/docker/client/image_remove_test.go b/vendor/github.com/docker/docker/client/image_remove_test.go deleted file mode 100644 index 7b004f7..0000000 --- a/vendor/github.com/docker/docker/client/image_remove_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestImageRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ImageRemove(context.Background(), "image_id", types.ImageRemoveOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageRemove(t *testing.T) { - expectedURL := "/images/image_id" - removeCases := []struct { - force bool - pruneChildren bool - expectedQueryParams map[string]string - }{ - { - force: false, - pruneChildren: false, - expectedQueryParams: map[string]string{ - "force": "", - "noprune": "1", - }, - }, { - force: true, - pruneChildren: true, - expectedQueryParams: map[string]string{ - "force": "1", - "noprune": "", - }, - }, - } - for _, removeCase := range removeCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - query := req.URL.Query() - for key, expected := range removeCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - b, err := json.Marshal([]types.ImageDelete{ - { - Untagged: "image_id1", - }, - { - Deleted: "image_id", - }, - }) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - imageDeletes, err := client.ImageRemove(context.Background(), "image_id", types.ImageRemoveOptions{ - Force: removeCase.force, - PruneChildren: removeCase.pruneChildren, - }) - if err != nil { - t.Fatal(err) - } - if len(imageDeletes) != 2 { - t.Fatalf("expected 2 deleted images, got %v", imageDeletes) - } - } -} diff --git a/vendor/github.com/docker/docker/client/image_save.go b/vendor/github.com/docker/docker/client/image_save.go deleted file mode 100644 index ecac880..0000000 --- a/vendor/github.com/docker/docker/client/image_save.go +++ /dev/null @@ -1,22 +0,0 @@ -package client - -import ( - "io" - "net/url" - - "golang.org/x/net/context" -) - -// ImageSave retrieves one or more images from the docker host as an io.ReadCloser. -// It's up to the caller to store the images and close the stream. -func (cli *Client) ImageSave(ctx context.Context, imageIDs []string) (io.ReadCloser, error) { - query := url.Values{ - "names": imageIDs, - } - - resp, err := cli.get(ctx, "/images/get", query, nil) - if err != nil { - return nil, err - } - return resp.body, nil -} diff --git a/vendor/github.com/docker/docker/client/image_save_test.go b/vendor/github.com/docker/docker/client/image_save_test.go deleted file mode 100644 index 8f0cf88..0000000 --- a/vendor/github.com/docker/docker/client/image_save_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "reflect" - "testing" - - "golang.org/x/net/context" - - "strings" -) - -func TestImageSaveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageSave(context.Background(), []string{"nothing"}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server error, got %v", err) - } -} - -func TestImageSave(t *testing.T) { - expectedURL := "/images/get" - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - query := r.URL.Query() - names := query["names"] - expectedNames := []string{"image_id1", "image_id2"} - if !reflect.DeepEqual(names, expectedNames) { - return nil, fmt.Errorf("names not set in URL query properly. Expected %v, got %v", names, expectedNames) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - saveResponse, err := client.ImageSave(context.Background(), []string{"image_id1", "image_id2"}) - if err != nil { - t.Fatal(err) - } - response, err := ioutil.ReadAll(saveResponse) - if err != nil { - t.Fatal(err) - } - saveResponse.Close() - if string(response) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(response)) - } -} diff --git a/vendor/github.com/docker/docker/client/image_search.go b/vendor/github.com/docker/docker/client/image_search.go deleted file mode 100644 index b0fcd5c..0000000 --- a/vendor/github.com/docker/docker/client/image_search.go +++ /dev/null @@ -1,51 +0,0 @@ -package client - -import ( - "encoding/json" - "fmt" - "net/http" - "net/url" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/registry" - "golang.org/x/net/context" -) - -// ImageSearch makes the docker host to search by a term in a remote registry. -// The list of results is not sorted in any fashion. -func (cli *Client) ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error) { - var results []registry.SearchResult - query := url.Values{} - query.Set("term", term) - query.Set("limit", fmt.Sprintf("%d", options.Limit)) - - if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) - if err != nil { - return results, err - } - query.Set("filters", filterJSON) - } - - resp, err := cli.tryImageSearch(ctx, query, options.RegistryAuth) - if resp.statusCode == http.StatusUnauthorized && options.PrivilegeFunc != nil { - newAuthHeader, privilegeErr := options.PrivilegeFunc() - if privilegeErr != nil { - return results, privilegeErr - } - resp, err = cli.tryImageSearch(ctx, query, newAuthHeader) - } - if err != nil { - return results, err - } - - err = json.NewDecoder(resp.body).Decode(&results) - ensureReaderClosed(resp) - return results, err -} - -func (cli *Client) tryImageSearch(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) { - headers := map[string][]string{"X-Registry-Auth": {registryAuth}} - return cli.get(ctx, "/images/search", query, headers) -} diff --git a/vendor/github.com/docker/docker/client/image_search_test.go b/vendor/github.com/docker/docker/client/image_search_test.go deleted file mode 100644 index b17bbd8..0000000 --- a/vendor/github.com/docker/docker/client/image_search_test.go +++ /dev/null @@ -1,165 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "encoding/json" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/registry" -) - -func TestImageSearchAnyError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestImageSearchStatusUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{}) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "", fmt.Errorf("Error requesting privilege") - } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error requesting privilege" { - t.Fatalf("expected an error requesting privilege, got %v", err) - } -} - -func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), - } - privilegeFunc := func() (string, error) { - return "a-auth-header", nil - } - _, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ - PrivilegeFunc: privilegeFunc, - }) - if err == nil || err.Error() != "Error response from daemon: Unauthorized error" { - t.Fatalf("expected an Unauthorized Error, got %v", err) - } -} - -func TestImageSearchWithPrivilegedFuncNoError(t *testing.T) { - expectedURL := "/images/search" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - auth := req.Header.Get("X-Registry-Auth") - if auth == "NotValid" { - return &http.Response{ - StatusCode: http.StatusUnauthorized, - Body: ioutil.NopCloser(bytes.NewReader([]byte("Invalid credentials"))), - }, nil - } - if auth != "IAmValid" { - return nil, fmt.Errorf("Invalid auth header : expected 'IAmValid', got %s", auth) - } - query := req.URL.Query() - term := query.Get("term") - if term != "some-image" { - return nil, fmt.Errorf("term not set in URL query properly. Expected 'some-image', got %s", term) - } - content, err := json.Marshal([]registry.SearchResult{ - { - Name: "anything", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - privilegeFunc := func() (string, error) { - return "IAmValid", nil - } - results, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ - RegistryAuth: "NotValid", - PrivilegeFunc: privilegeFunc, - }) - if err != nil { - t.Fatal(err) - } - if len(results) != 1 { - t.Fatalf("expected 1 result, got %v", results) - } -} - -func TestImageSearchWithoutErrors(t *testing.T) { - expectedURL := "/images/search" - filterArgs := filters.NewArgs() - filterArgs.Add("is-automated", "true") - filterArgs.Add("stars", "3") - - expectedFilters := `{"is-automated":{"true":true},"stars":{"3":true}}` - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - term := query.Get("term") - if term != "some-image" { - return nil, fmt.Errorf("term not set in URL query properly. Expected 'some-image', got %s", term) - } - filters := query.Get("filters") - if filters != expectedFilters { - return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", expectedFilters, filters) - } - content, err := json.Marshal([]registry.SearchResult{ - { - Name: "anything", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - results, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{ - Filters: filterArgs, - }) - if err != nil { - t.Fatal(err) - } - if len(results) != 1 { - t.Fatalf("expected a result, got %v", results) - } -} diff --git a/vendor/github.com/docker/docker/client/image_tag.go b/vendor/github.com/docker/docker/client/image_tag.go deleted file mode 100644 index bdbf94a..0000000 --- a/vendor/github.com/docker/docker/client/image_tag.go +++ /dev/null @@ -1,34 +0,0 @@ -package client - -import ( - "errors" - "fmt" - "net/url" - - "golang.org/x/net/context" - - distreference "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types/reference" -) - -// ImageTag tags an image in the docker host -func (cli *Client) ImageTag(ctx context.Context, imageID, ref string) error { - distributionRef, err := distreference.ParseNamed(ref) - if err != nil { - return fmt.Errorf("Error parsing reference: %q is not a valid repository/tag", ref) - } - - if _, isCanonical := distributionRef.(distreference.Canonical); isCanonical { - return errors.New("refusing to create a tag with a digest reference") - } - - tag := reference.GetTagFromNamedRef(distributionRef) - - query := url.Values{} - query.Set("repo", distributionRef.Name()) - query.Set("tag", tag) - - resp, err := cli.post(ctx, "/images/"+imageID+"/tag", query, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/image_tag_test.go b/vendor/github.com/docker/docker/client/image_tag_test.go deleted file mode 100644 index 7925db9..0000000 --- a/vendor/github.com/docker/docker/client/image_tag_test.go +++ /dev/null @@ -1,121 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestImageTagError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.ImageTag(context.Background(), "image_id", "repo:tag") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -// Note: this is not testing all the InvalidReference as it's the reponsability -// of distribution/reference package. -func TestImageTagInvalidReference(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.ImageTag(context.Background(), "image_id", "aa/asdf$$^/aa") - if err == nil || err.Error() != `Error parsing reference: "aa/asdf$$^/aa" is not a valid repository/tag` { - t.Fatalf("expected ErrReferenceInvalidFormat, got %v", err) - } -} - -func TestImageTag(t *testing.T) { - expectedURL := "/images/image_id/tag" - tagCases := []struct { - reference string - expectedQueryParams map[string]string - }{ - { - reference: "repository:tag1", - expectedQueryParams: map[string]string{ - "repo": "repository", - "tag": "tag1", - }, - }, { - reference: "another_repository:latest", - expectedQueryParams: map[string]string{ - "repo": "another_repository", - "tag": "latest", - }, - }, { - reference: "another_repository", - expectedQueryParams: map[string]string{ - "repo": "another_repository", - "tag": "latest", - }, - }, { - reference: "test/another_repository", - expectedQueryParams: map[string]string{ - "repo": "test/another_repository", - "tag": "latest", - }, - }, { - reference: "test/another_repository:tag1", - expectedQueryParams: map[string]string{ - "repo": "test/another_repository", - "tag": "tag1", - }, - }, { - reference: "test/test/another_repository:tag1", - expectedQueryParams: map[string]string{ - "repo": "test/test/another_repository", - "tag": "tag1", - }, - }, { - reference: "test:5000/test/another_repository:tag1", - expectedQueryParams: map[string]string{ - "repo": "test:5000/test/another_repository", - "tag": "tag1", - }, - }, { - reference: "test:5000/test/another_repository", - expectedQueryParams: map[string]string{ - "repo": "test:5000/test/another_repository", - "tag": "latest", - }, - }, - } - for _, tagCase := range tagCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - query := req.URL.Query() - for key, expected := range tagCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - err := client.ImageTag(context.Background(), "image_id", tagCase.reference) - if err != nil { - t.Fatal(err) - } - } -} diff --git a/vendor/github.com/docker/docker/client/info.go b/vendor/github.com/docker/docker/client/info.go deleted file mode 100644 index ac07961..0000000 --- a/vendor/github.com/docker/docker/client/info.go +++ /dev/null @@ -1,26 +0,0 @@ -package client - -import ( - "encoding/json" - "fmt" - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// Info returns information about the docker server. -func (cli *Client) Info(ctx context.Context) (types.Info, error) { - var info types.Info - serverResp, err := cli.get(ctx, "/info", url.Values{}, nil) - if err != nil { - return info, err - } - defer ensureReaderClosed(serverResp) - - if err := json.NewDecoder(serverResp.body).Decode(&info); err != nil { - return info, fmt.Errorf("Error reading remote info: %v", err) - } - - return info, nil -} diff --git a/vendor/github.com/docker/docker/client/info_test.go b/vendor/github.com/docker/docker/client/info_test.go deleted file mode 100644 index 79f23c8..0000000 --- a/vendor/github.com/docker/docker/client/info_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestInfoServerError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.Info(context.Background()) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestInfoInvalidResponseJSONError(t *testing.T) { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("invalid json"))), - }, nil - }), - } - _, err := client.Info(context.Background()) - if err == nil || !strings.Contains(err.Error(), "invalid character") { - t.Fatalf("expected a 'invalid character' error, got %v", err) - } -} - -func TestInfo(t *testing.T) { - expectedURL := "/info" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - info := &types.Info{ - ID: "daemonID", - Containers: 3, - } - b, err := json.Marshal(info) - if err != nil { - return nil, err - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - info, err := client.Info(context.Background()) - if err != nil { - t.Fatal(err) - } - - if info.ID != "daemonID" { - t.Fatalf("expected daemonID, got %s", info.ID) - } - - if info.Containers != 3 { - t.Fatalf("expected 3 containers, got %d", info.Containers) - } -} diff --git a/vendor/github.com/docker/docker/client/interface.go b/vendor/github.com/docker/docker/client/interface.go deleted file mode 100644 index 0597803..0000000 --- a/vendor/github.com/docker/docker/client/interface.go +++ /dev/null @@ -1,171 +0,0 @@ -package client - -import ( - "io" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/network" - "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/api/types/swarm" - volumetypes "github.com/docker/docker/api/types/volume" - "golang.org/x/net/context" -) - -// CommonAPIClient is the common methods between stable and experimental versions of APIClient. -type CommonAPIClient interface { - ContainerAPIClient - ImageAPIClient - NodeAPIClient - NetworkAPIClient - PluginAPIClient - ServiceAPIClient - SwarmAPIClient - SecretAPIClient - SystemAPIClient - VolumeAPIClient - ClientVersion() string - ServerVersion(ctx context.Context) (types.Version, error) - UpdateClientVersion(v string) -} - -// ContainerAPIClient defines API client methods for the containers -type ContainerAPIClient interface { - ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) - ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error) - ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error) - ContainerDiff(ctx context.Context, container string) ([]types.ContainerChange, error) - ContainerExecAttach(ctx context.Context, execID string, config types.ExecConfig) (types.HijackedResponse, error) - ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) - ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error) - ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error - ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error - ContainerExport(ctx context.Context, container string) (io.ReadCloser, error) - ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error) - ContainerInspectWithRaw(ctx context.Context, container string, getSize bool) (types.ContainerJSON, []byte, error) - ContainerKill(ctx context.Context, container, signal string) error - ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) - ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error) - ContainerPause(ctx context.Context, container string) error - ContainerRemove(ctx context.Context, container string, options types.ContainerRemoveOptions) error - ContainerRename(ctx context.Context, container, newContainerName string) error - ContainerResize(ctx context.Context, container string, options types.ResizeOptions) error - ContainerRestart(ctx context.Context, container string, timeout *time.Duration) error - ContainerStatPath(ctx context.Context, container, path string) (types.ContainerPathStat, error) - ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error) - ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error - ContainerStop(ctx context.Context, container string, timeout *time.Duration) error - ContainerTop(ctx context.Context, container string, arguments []string) (types.ContainerProcessList, error) - ContainerUnpause(ctx context.Context, container string) error - ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) - ContainerWait(ctx context.Context, container string) (int64, error) - CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) - CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error - ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error) -} - -// ImageAPIClient defines API client methods for the images -type ImageAPIClient interface { - ImageBuild(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) - ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) - ImageHistory(ctx context.Context, image string) ([]types.ImageHistory, error) - ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) - ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error) - ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) - ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error) - ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error) - ImagePush(ctx context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error) - ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]types.ImageDelete, error) - ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error) - ImageSave(ctx context.Context, images []string) (io.ReadCloser, error) - ImageTag(ctx context.Context, image, ref string) error - ImagesPrune(ctx context.Context, pruneFilter filters.Args) (types.ImagesPruneReport, error) -} - -// NetworkAPIClient defines API client methods for the networks -type NetworkAPIClient interface { - NetworkConnect(ctx context.Context, networkID, container string, config *network.EndpointSettings) error - NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) - NetworkDisconnect(ctx context.Context, networkID, container string, force bool) error - NetworkInspect(ctx context.Context, networkID string) (types.NetworkResource, error) - NetworkInspectWithRaw(ctx context.Context, networkID string) (types.NetworkResource, []byte, error) - NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) - NetworkRemove(ctx context.Context, networkID string) error - NetworksPrune(ctx context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error) -} - -// NodeAPIClient defines API client methods for the nodes -type NodeAPIClient interface { - NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error) - NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) - NodeRemove(ctx context.Context, nodeID string, options types.NodeRemoveOptions) error - NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error -} - -// PluginAPIClient defines API client methods for the plugins -type PluginAPIClient interface { - PluginList(ctx context.Context) (types.PluginsListResponse, error) - PluginRemove(ctx context.Context, name string, options types.PluginRemoveOptions) error - PluginEnable(ctx context.Context, name string, options types.PluginEnableOptions) error - PluginDisable(ctx context.Context, name string, options types.PluginDisableOptions) error - PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error) - PluginUpgrade(ctx context.Context, name string, options types.PluginInstallOptions) (io.ReadCloser, error) - PluginPush(ctx context.Context, name string, registryAuth string) (io.ReadCloser, error) - PluginSet(ctx context.Context, name string, args []string) error - PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) - PluginCreate(ctx context.Context, createContext io.Reader, options types.PluginCreateOptions) error -} - -// ServiceAPIClient defines API client methods for the services -type ServiceAPIClient interface { - ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error) - ServiceInspectWithRaw(ctx context.Context, serviceID string) (swarm.Service, []byte, error) - ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) - ServiceRemove(ctx context.Context, serviceID string) error - ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) - ServiceLogs(ctx context.Context, serviceID string, options types.ContainerLogsOptions) (io.ReadCloser, error) - TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) - TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) -} - -// SwarmAPIClient defines API client methods for the swarm -type SwarmAPIClient interface { - SwarmInit(ctx context.Context, req swarm.InitRequest) (string, error) - SwarmJoin(ctx context.Context, req swarm.JoinRequest) error - SwarmGetUnlockKey(ctx context.Context) (types.SwarmUnlockKeyResponse, error) - SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error - SwarmLeave(ctx context.Context, force bool) error - SwarmInspect(ctx context.Context) (swarm.Swarm, error) - SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error -} - -// SystemAPIClient defines API client methods for the system -type SystemAPIClient interface { - Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error) - Info(ctx context.Context) (types.Info, error) - RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) - DiskUsage(ctx context.Context) (types.DiskUsage, error) - Ping(ctx context.Context) (types.Ping, error) -} - -// VolumeAPIClient defines API client methods for the volumes -type VolumeAPIClient interface { - VolumeCreate(ctx context.Context, options volumetypes.VolumesCreateBody) (types.Volume, error) - VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) - VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) - VolumeList(ctx context.Context, filter filters.Args) (volumetypes.VolumesListOKBody, error) - VolumeRemove(ctx context.Context, volumeID string, force bool) error - VolumesPrune(ctx context.Context, pruneFilter filters.Args) (types.VolumesPruneReport, error) -} - -// SecretAPIClient defines API client methods for secrets -type SecretAPIClient interface { - SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) - SecretCreate(ctx context.Context, secret swarm.SecretSpec) (types.SecretCreateResponse, error) - SecretRemove(ctx context.Context, id string) error - SecretInspectWithRaw(ctx context.Context, name string) (swarm.Secret, []byte, error) - SecretUpdate(ctx context.Context, id string, version swarm.Version, secret swarm.SecretSpec) error -} diff --git a/vendor/github.com/docker/docker/client/interface_experimental.go b/vendor/github.com/docker/docker/client/interface_experimental.go deleted file mode 100644 index 51da98e..0000000 --- a/vendor/github.com/docker/docker/client/interface_experimental.go +++ /dev/null @@ -1,17 +0,0 @@ -package client - -import ( - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -type apiClientExperimental interface { - CheckpointAPIClient -} - -// CheckpointAPIClient defines API client methods for the checkpoints -type CheckpointAPIClient interface { - CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error - CheckpointDelete(ctx context.Context, container string, options types.CheckpointDeleteOptions) error - CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) -} diff --git a/vendor/github.com/docker/docker/client/interface_stable.go b/vendor/github.com/docker/docker/client/interface_stable.go deleted file mode 100644 index cc90a3c..0000000 --- a/vendor/github.com/docker/docker/client/interface_stable.go +++ /dev/null @@ -1,10 +0,0 @@ -package client - -// APIClient is an interface that clients that talk with a docker server must implement. -type APIClient interface { - CommonAPIClient - apiClientExperimental -} - -// Ensure that Client always implements APIClient. -var _ APIClient = &Client{} diff --git a/vendor/github.com/docker/docker/client/login.go b/vendor/github.com/docker/docker/client/login.go deleted file mode 100644 index 600dc71..0000000 --- a/vendor/github.com/docker/docker/client/login.go +++ /dev/null @@ -1,29 +0,0 @@ -package client - -import ( - "encoding/json" - "net/http" - "net/url" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/registry" - "golang.org/x/net/context" -) - -// RegistryLogin authenticates the docker server with a given docker registry. -// It returns UnauthorizerError when the authentication fails. -func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) { - resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil) - - if resp.statusCode == http.StatusUnauthorized { - return registry.AuthenticateOKBody{}, unauthorizedError{err} - } - if err != nil { - return registry.AuthenticateOKBody{}, err - } - - var response registry.AuthenticateOKBody - err = json.NewDecoder(resp.body).Decode(&response) - ensureReaderClosed(resp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/network_connect.go b/vendor/github.com/docker/docker/client/network_connect.go deleted file mode 100644 index c022c17..0000000 --- a/vendor/github.com/docker/docker/client/network_connect.go +++ /dev/null @@ -1,18 +0,0 @@ -package client - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/network" - "golang.org/x/net/context" -) - -// NetworkConnect connects a container to an existent network in the docker host. -func (cli *Client) NetworkConnect(ctx context.Context, networkID, containerID string, config *network.EndpointSettings) error { - nc := types.NetworkConnect{ - Container: containerID, - EndpointConfig: config, - } - resp, err := cli.post(ctx, "/networks/"+networkID+"/connect", nil, nc, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/network_connect_test.go b/vendor/github.com/docker/docker/client/network_connect_test.go deleted file mode 100644 index d472f45..0000000 --- a/vendor/github.com/docker/docker/client/network_connect_test.go +++ /dev/null @@ -1,107 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/network" -) - -func TestNetworkConnectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.NetworkConnect(context.Background(), "network_id", "container_id", nil) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkConnectEmptyNilEndpointSettings(t *testing.T) { - expectedURL := "/networks/network_id/connect" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - var connect types.NetworkConnect - if err := json.NewDecoder(req.Body).Decode(&connect); err != nil { - return nil, err - } - - if connect.Container != "container_id" { - return nil, fmt.Errorf("expected 'container_id', got %s", connect.Container) - } - - if connect.EndpointConfig != nil { - return nil, fmt.Errorf("expected connect.EndpointConfig to be nil, got %v", connect.EndpointConfig) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.NetworkConnect(context.Background(), "network_id", "container_id", nil) - if err != nil { - t.Fatal(err) - } -} - -func TestNetworkConnect(t *testing.T) { - expectedURL := "/networks/network_id/connect" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - var connect types.NetworkConnect - if err := json.NewDecoder(req.Body).Decode(&connect); err != nil { - return nil, err - } - - if connect.Container != "container_id" { - return nil, fmt.Errorf("expected 'container_id', got %s", connect.Container) - } - - if connect.EndpointConfig.NetworkID != "NetworkID" { - return nil, fmt.Errorf("expected 'NetworkID', got %s", connect.EndpointConfig.NetworkID) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.NetworkConnect(context.Background(), "network_id", "container_id", &network.EndpointSettings{ - NetworkID: "NetworkID", - }) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/network_create.go b/vendor/github.com/docker/docker/client/network_create.go deleted file mode 100644 index 4067a54..0000000 --- a/vendor/github.com/docker/docker/client/network_create.go +++ /dev/null @@ -1,25 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// NetworkCreate creates a new network in the docker host. -func (cli *Client) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) { - networkCreateRequest := types.NetworkCreateRequest{ - NetworkCreate: options, - Name: name, - } - var response types.NetworkCreateResponse - serverResp, err := cli.post(ctx, "/networks/create", nil, networkCreateRequest, nil) - if err != nil { - return response, err - } - - json.NewDecoder(serverResp.body).Decode(&response) - ensureReaderClosed(serverResp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/network_create_test.go b/vendor/github.com/docker/docker/client/network_create_test.go deleted file mode 100644 index 0e2457f..0000000 --- a/vendor/github.com/docker/docker/client/network_create_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestNetworkCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.NetworkCreate(context.Background(), "mynetwork", types.NetworkCreate{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkCreate(t *testing.T) { - expectedURL := "/networks/create" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - content, err := json.Marshal(types.NetworkCreateResponse{ - ID: "network_id", - Warning: "warning", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - networkResponse, err := client.NetworkCreate(context.Background(), "mynetwork", types.NetworkCreate{ - CheckDuplicate: true, - Driver: "mydriver", - EnableIPv6: true, - Internal: true, - Options: map[string]string{ - "opt-key": "opt-value", - }, - }) - if err != nil { - t.Fatal(err) - } - if networkResponse.ID != "network_id" { - t.Fatalf("expected networkResponse.ID to be 'network_id', got %s", networkResponse.ID) - } - if networkResponse.Warning != "warning" { - t.Fatalf("expected networkResponse.Warning to be 'warning', got %s", networkResponse.Warning) - } -} diff --git a/vendor/github.com/docker/docker/client/network_disconnect.go b/vendor/github.com/docker/docker/client/network_disconnect.go deleted file mode 100644 index 24b58e3..0000000 --- a/vendor/github.com/docker/docker/client/network_disconnect.go +++ /dev/null @@ -1,14 +0,0 @@ -package client - -import ( - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// NetworkDisconnect disconnects a container from an existent network in the docker host. -func (cli *Client) NetworkDisconnect(ctx context.Context, networkID, containerID string, force bool) error { - nd := types.NetworkDisconnect{Container: containerID, Force: force} - resp, err := cli.post(ctx, "/networks/"+networkID+"/disconnect", nil, nd, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/network_disconnect_test.go b/vendor/github.com/docker/docker/client/network_disconnect_test.go deleted file mode 100644 index b54a2b1..0000000 --- a/vendor/github.com/docker/docker/client/network_disconnect_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestNetworkDisconnectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.NetworkDisconnect(context.Background(), "network_id", "container_id", false) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkDisconnect(t *testing.T) { - expectedURL := "/networks/network_id/disconnect" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - var disconnect types.NetworkDisconnect - if err := json.NewDecoder(req.Body).Decode(&disconnect); err != nil { - return nil, err - } - - if disconnect.Container != "container_id" { - return nil, fmt.Errorf("expected 'container_id', got %s", disconnect.Container) - } - - if !disconnect.Force { - return nil, fmt.Errorf("expected Force to be true, got %v", disconnect.Force) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.NetworkDisconnect(context.Background(), "network_id", "container_id", true) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/network_inspect.go b/vendor/github.com/docker/docker/client/network_inspect.go deleted file mode 100644 index 5ad4ea5..0000000 --- a/vendor/github.com/docker/docker/client/network_inspect.go +++ /dev/null @@ -1,38 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// NetworkInspect returns the information for a specific network configured in the docker host. -func (cli *Client) NetworkInspect(ctx context.Context, networkID string) (types.NetworkResource, error) { - networkResource, _, err := cli.NetworkInspectWithRaw(ctx, networkID) - return networkResource, err -} - -// NetworkInspectWithRaw returns the information for a specific network configured in the docker host and its raw representation. -func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string) (types.NetworkResource, []byte, error) { - var networkResource types.NetworkResource - resp, err := cli.get(ctx, "/networks/"+networkID, nil, nil) - if err != nil { - if resp.statusCode == http.StatusNotFound { - return networkResource, nil, networkNotFoundError{networkID} - } - return networkResource, nil, err - } - defer ensureReaderClosed(resp) - - body, err := ioutil.ReadAll(resp.body) - if err != nil { - return networkResource, nil, err - } - rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&networkResource) - return networkResource, body, err -} diff --git a/vendor/github.com/docker/docker/client/network_inspect_test.go b/vendor/github.com/docker/docker/client/network_inspect_test.go deleted file mode 100644 index 1f926d6..0000000 --- a/vendor/github.com/docker/docker/client/network_inspect_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestNetworkInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.NetworkInspect(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkInspectContainerNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, err := client.NetworkInspect(context.Background(), "unknown") - if err == nil || !IsErrNetworkNotFound(err) { - t.Fatalf("expected a containerNotFound error, got %v", err) - } -} - -func TestNetworkInspect(t *testing.T) { - expectedURL := "/networks/network_id" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "GET" { - return nil, fmt.Errorf("expected GET method, got %s", req.Method) - } - - content, err := json.Marshal(types.NetworkResource{ - Name: "mynetwork", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - r, err := client.NetworkInspect(context.Background(), "network_id") - if err != nil { - t.Fatal(err) - } - if r.Name != "mynetwork" { - t.Fatalf("expected `mynetwork`, got %s", r.Name) - } -} diff --git a/vendor/github.com/docker/docker/client/network_list.go b/vendor/github.com/docker/docker/client/network_list.go deleted file mode 100644 index e566a93..0000000 --- a/vendor/github.com/docker/docker/client/network_list.go +++ /dev/null @@ -1,31 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -// NetworkList returns the list of networks configured in the docker host. -func (cli *Client) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) { - query := url.Values{} - if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filters) - if err != nil { - return nil, err - } - - query.Set("filters", filterJSON) - } - var networkResources []types.NetworkResource - resp, err := cli.get(ctx, "/networks", query, nil) - if err != nil { - return networkResources, err - } - err = json.NewDecoder(resp.body).Decode(&networkResources) - ensureReaderClosed(resp) - return networkResources, err -} diff --git a/vendor/github.com/docker/docker/client/network_list_test.go b/vendor/github.com/docker/docker/client/network_list_test.go deleted file mode 100644 index 4d44349..0000000 --- a/vendor/github.com/docker/docker/client/network_list_test.go +++ /dev/null @@ -1,108 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -func TestNetworkListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.NetworkList(context.Background(), types.NetworkListOptions{ - Filters: filters.NewArgs(), - }) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkList(t *testing.T) { - expectedURL := "/networks" - - noDanglingFilters := filters.NewArgs() - noDanglingFilters.Add("dangling", "false") - - danglingFilters := filters.NewArgs() - danglingFilters.Add("dangling", "true") - - labelFilters := filters.NewArgs() - labelFilters.Add("label", "label1") - labelFilters.Add("label", "label2") - - listCases := []struct { - options types.NetworkListOptions - expectedFilters string - }{ - { - options: types.NetworkListOptions{ - Filters: filters.NewArgs(), - }, - expectedFilters: "", - }, { - options: types.NetworkListOptions{ - Filters: noDanglingFilters, - }, - expectedFilters: `{"dangling":{"false":true}}`, - }, { - options: types.NetworkListOptions{ - Filters: danglingFilters, - }, - expectedFilters: `{"dangling":{"true":true}}`, - }, { - options: types.NetworkListOptions{ - Filters: labelFilters, - }, - expectedFilters: `{"label":{"label1":true,"label2":true}}`, - }, - } - - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "GET" { - return nil, fmt.Errorf("expected GET method, got %s", req.Method) - } - query := req.URL.Query() - actualFilters := query.Get("filters") - if actualFilters != listCase.expectedFilters { - return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters) - } - content, err := json.Marshal([]types.NetworkResource{ - { - Name: "network", - Driver: "bridge", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - networkResources, err := client.NetworkList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(networkResources) != 1 { - t.Fatalf("expected 1 network resource, got %v", networkResources) - } - } -} diff --git a/vendor/github.com/docker/docker/client/network_prune.go b/vendor/github.com/docker/docker/client/network_prune.go deleted file mode 100644 index 7352a7f..0000000 --- a/vendor/github.com/docker/docker/client/network_prune.go +++ /dev/null @@ -1,36 +0,0 @@ -package client - -import ( - "encoding/json" - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -// NetworksPrune requests the daemon to delete unused networks -func (cli *Client) NetworksPrune(ctx context.Context, pruneFilters filters.Args) (types.NetworksPruneReport, error) { - var report types.NetworksPruneReport - - if err := cli.NewVersionError("1.25", "network prune"); err != nil { - return report, err - } - - query, err := getFiltersQuery(pruneFilters) - if err != nil { - return report, err - } - - serverResp, err := cli.post(ctx, "/networks/prune", query, nil, nil) - if err != nil { - return report, err - } - defer ensureReaderClosed(serverResp) - - if err := json.NewDecoder(serverResp.body).Decode(&report); err != nil { - return report, fmt.Errorf("Error retrieving network prune report: %v", err) - } - - return report, nil -} diff --git a/vendor/github.com/docker/docker/client/network_remove.go b/vendor/github.com/docker/docker/client/network_remove.go deleted file mode 100644 index 6bd6748..0000000 --- a/vendor/github.com/docker/docker/client/network_remove.go +++ /dev/null @@ -1,10 +0,0 @@ -package client - -import "golang.org/x/net/context" - -// NetworkRemove removes an existent network from the docker host. -func (cli *Client) NetworkRemove(ctx context.Context, networkID string) error { - resp, err := cli.delete(ctx, "/networks/"+networkID, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/network_remove_test.go b/vendor/github.com/docker/docker/client/network_remove_test.go deleted file mode 100644 index 2a7b964..0000000 --- a/vendor/github.com/docker/docker/client/network_remove_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestNetworkRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.NetworkRemove(context.Background(), "network_id") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNetworkRemove(t *testing.T) { - expectedURL := "/networks/network_id" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.NetworkRemove(context.Background(), "network_id") - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/node_inspect.go b/vendor/github.com/docker/docker/client/node_inspect.go deleted file mode 100644 index abf505d..0000000 --- a/vendor/github.com/docker/docker/client/node_inspect.go +++ /dev/null @@ -1,33 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// NodeInspectWithRaw returns the node information. -func (cli *Client) NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error) { - serverResp, err := cli.get(ctx, "/nodes/"+nodeID, nil, nil) - if err != nil { - if serverResp.statusCode == http.StatusNotFound { - return swarm.Node{}, nil, nodeNotFoundError{nodeID} - } - return swarm.Node{}, nil, err - } - defer ensureReaderClosed(serverResp) - - body, err := ioutil.ReadAll(serverResp.body) - if err != nil { - return swarm.Node{}, nil, err - } - - var response swarm.Node - rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&response) - return response, body, err -} diff --git a/vendor/github.com/docker/docker/client/node_inspect_test.go b/vendor/github.com/docker/docker/client/node_inspect_test.go deleted file mode 100644 index fc13283..0000000 --- a/vendor/github.com/docker/docker/client/node_inspect_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestNodeInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.NodeInspectWithRaw(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNodeInspectNodeNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, _, err := client.NodeInspectWithRaw(context.Background(), "unknown") - if err == nil || !IsErrNodeNotFound(err) { - t.Fatalf("expected an nodeNotFoundError error, got %v", err) - } -} - -func TestNodeInspect(t *testing.T) { - expectedURL := "/nodes/node_id" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - content, err := json.Marshal(swarm.Node{ - ID: "node_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - nodeInspect, _, err := client.NodeInspectWithRaw(context.Background(), "node_id") - if err != nil { - t.Fatal(err) - } - if nodeInspect.ID != "node_id" { - t.Fatalf("expected `node_id`, got %s", nodeInspect.ID) - } -} diff --git a/vendor/github.com/docker/docker/client/node_list.go b/vendor/github.com/docker/docker/client/node_list.go deleted file mode 100644 index 3e8440f..0000000 --- a/vendor/github.com/docker/docker/client/node_list.go +++ /dev/null @@ -1,36 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// NodeList returns the list of nodes. -func (cli *Client) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) { - query := url.Values{} - - if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) - - if err != nil { - return nil, err - } - - query.Set("filters", filterJSON) - } - - resp, err := cli.get(ctx, "/nodes", query, nil) - if err != nil { - return nil, err - } - - var nodes []swarm.Node - err = json.NewDecoder(resp.body).Decode(&nodes) - ensureReaderClosed(resp) - return nodes, err -} diff --git a/vendor/github.com/docker/docker/client/node_list_test.go b/vendor/github.com/docker/docker/client/node_list_test.go deleted file mode 100644 index 0251b5c..0000000 --- a/vendor/github.com/docker/docker/client/node_list_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestNodeListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.NodeList(context.Background(), types.NodeListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNodeList(t *testing.T) { - expectedURL := "/nodes" - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - - listCases := []struct { - options types.NodeListOptions - expectedQueryParams map[string]string - }{ - { - options: types.NodeListOptions{}, - expectedQueryParams: map[string]string{ - "filters": "", - }, - }, - { - options: types.NodeListOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": `{"label":{"label1":true,"label2":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]swarm.Node{ - { - ID: "node_id1", - }, - { - ID: "node_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - nodes, err := client.NodeList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(nodes) != 2 { - t.Fatalf("expected 2 nodes, got %v", nodes) - } - } -} diff --git a/vendor/github.com/docker/docker/client/node_remove.go b/vendor/github.com/docker/docker/client/node_remove.go deleted file mode 100644 index 0a77f3d..0000000 --- a/vendor/github.com/docker/docker/client/node_remove.go +++ /dev/null @@ -1,21 +0,0 @@ -package client - -import ( - "net/url" - - "github.com/docker/docker/api/types" - - "golang.org/x/net/context" -) - -// NodeRemove removes a Node. -func (cli *Client) NodeRemove(ctx context.Context, nodeID string, options types.NodeRemoveOptions) error { - query := url.Values{} - if options.Force { - query.Set("force", "1") - } - - resp, err := cli.delete(ctx, "/nodes/"+nodeID, query, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/node_remove_test.go b/vendor/github.com/docker/docker/client/node_remove_test.go deleted file mode 100644 index f2f8adc..0000000 --- a/vendor/github.com/docker/docker/client/node_remove_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - - "golang.org/x/net/context" -) - -func TestNodeRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.NodeRemove(context.Background(), "node_id", types.NodeRemoveOptions{Force: false}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNodeRemove(t *testing.T) { - expectedURL := "/nodes/node_id" - - removeCases := []struct { - force bool - expectedForce string - }{ - { - expectedForce: "", - }, - { - force: true, - expectedForce: "1", - }, - } - - for _, removeCase := range removeCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - force := req.URL.Query().Get("force") - if force != removeCase.expectedForce { - return nil, fmt.Errorf("force not set in URL query properly. expected '%s', got %s", removeCase.expectedForce, force) - } - - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.NodeRemove(context.Background(), "node_id", types.NodeRemoveOptions{Force: removeCase.force}) - if err != nil { - t.Fatal(err) - } - } -} diff --git a/vendor/github.com/docker/docker/client/node_update.go b/vendor/github.com/docker/docker/client/node_update.go deleted file mode 100644 index 3ca9760..0000000 --- a/vendor/github.com/docker/docker/client/node_update.go +++ /dev/null @@ -1,18 +0,0 @@ -package client - -import ( - "net/url" - "strconv" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// NodeUpdate updates a Node. -func (cli *Client) NodeUpdate(ctx context.Context, nodeID string, version swarm.Version, node swarm.NodeSpec) error { - query := url.Values{} - query.Set("version", strconv.FormatUint(version.Index, 10)) - resp, err := cli.post(ctx, "/nodes/"+nodeID+"/update", query, node, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/node_update_test.go b/vendor/github.com/docker/docker/client/node_update_test.go deleted file mode 100644 index 613ff10..0000000 --- a/vendor/github.com/docker/docker/client/node_update_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" -) - -func TestNodeUpdateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.NodeUpdate(context.Background(), "node_id", swarm.Version{}, swarm.NodeSpec{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestNodeUpdate(t *testing.T) { - expectedURL := "/nodes/node_id/update" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.NodeUpdate(context.Background(), "node_id", swarm.Version{}, swarm.NodeSpec{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/ping.go b/vendor/github.com/docker/docker/client/ping.go deleted file mode 100644 index 22dcda2..0000000 --- a/vendor/github.com/docker/docker/client/ping.go +++ /dev/null @@ -1,30 +0,0 @@ -package client - -import ( - "fmt" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// Ping pings the server and return the value of the "Docker-Experimental" & "API-Version" headers -func (cli *Client) Ping(ctx context.Context) (types.Ping, error) { - var ping types.Ping - req, err := cli.buildRequest("GET", fmt.Sprintf("%s/_ping", cli.basePath), nil, nil) - if err != nil { - return ping, err - } - serverResp, err := cli.doRequest(ctx, req) - if err != nil { - return ping, err - } - defer ensureReaderClosed(serverResp) - - ping.APIVersion = serverResp.header.Get("API-Version") - - if serverResp.header.Get("Docker-Experimental") == "true" { - ping.Experimental = true - } - - return ping, nil -} diff --git a/vendor/github.com/docker/docker/client/plugin_create.go b/vendor/github.com/docker/docker/client/plugin_create.go deleted file mode 100644 index a660ba5..0000000 --- a/vendor/github.com/docker/docker/client/plugin_create.go +++ /dev/null @@ -1,26 +0,0 @@ -package client - -import ( - "io" - "net/http" - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// PluginCreate creates a plugin -func (cli *Client) PluginCreate(ctx context.Context, createContext io.Reader, createOptions types.PluginCreateOptions) error { - headers := http.Header(make(map[string][]string)) - headers.Set("Content-Type", "application/tar") - - query := url.Values{} - query.Set("name", createOptions.RepoName) - - resp, err := cli.postRaw(ctx, "/plugins/create", query, createContext, headers) - if err != nil { - return err - } - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/plugin_disable.go b/vendor/github.com/docker/docker/client/plugin_disable.go deleted file mode 100644 index 30467db..0000000 --- a/vendor/github.com/docker/docker/client/plugin_disable.go +++ /dev/null @@ -1,19 +0,0 @@ -package client - -import ( - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// PluginDisable disables a plugin -func (cli *Client) PluginDisable(ctx context.Context, name string, options types.PluginDisableOptions) error { - query := url.Values{} - if options.Force { - query.Set("force", "1") - } - resp, err := cli.post(ctx, "/plugins/"+name+"/disable", query, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/plugin_disable_test.go b/vendor/github.com/docker/docker/client/plugin_disable_test.go deleted file mode 100644 index a4de45b..0000000 --- a/vendor/github.com/docker/docker/client/plugin_disable_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestPluginDisableError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.PluginDisable(context.Background(), "plugin_name", types.PluginDisableOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginDisable(t *testing.T) { - expectedURL := "/plugins/plugin_name/disable" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.PluginDisable(context.Background(), "plugin_name", types.PluginDisableOptions{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/plugin_enable.go b/vendor/github.com/docker/docker/client/plugin_enable.go deleted file mode 100644 index 95517c4..0000000 --- a/vendor/github.com/docker/docker/client/plugin_enable.go +++ /dev/null @@ -1,19 +0,0 @@ -package client - -import ( - "net/url" - "strconv" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// PluginEnable enables a plugin -func (cli *Client) PluginEnable(ctx context.Context, name string, options types.PluginEnableOptions) error { - query := url.Values{} - query.Set("timeout", strconv.Itoa(options.Timeout)) - - resp, err := cli.post(ctx, "/plugins/"+name+"/enable", query, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/plugin_enable_test.go b/vendor/github.com/docker/docker/client/plugin_enable_test.go deleted file mode 100644 index b276813..0000000 --- a/vendor/github.com/docker/docker/client/plugin_enable_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestPluginEnableError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.PluginEnable(context.Background(), "plugin_name", types.PluginEnableOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginEnable(t *testing.T) { - expectedURL := "/plugins/plugin_name/enable" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.PluginEnable(context.Background(), "plugin_name", types.PluginEnableOptions{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/plugin_inspect.go b/vendor/github.com/docker/docker/client/plugin_inspect.go deleted file mode 100644 index 89f39ee..0000000 --- a/vendor/github.com/docker/docker/client/plugin_inspect.go +++ /dev/null @@ -1,32 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// PluginInspectWithRaw inspects an existing plugin -func (cli *Client) PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) { - resp, err := cli.get(ctx, "/plugins/"+name+"/json", nil, nil) - if err != nil { - if resp.statusCode == http.StatusNotFound { - return nil, nil, pluginNotFoundError{name} - } - return nil, nil, err - } - - defer ensureReaderClosed(resp) - body, err := ioutil.ReadAll(resp.body) - if err != nil { - return nil, nil, err - } - var p types.Plugin - rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&p) - return &p, body, err -} diff --git a/vendor/github.com/docker/docker/client/plugin_inspect_test.go b/vendor/github.com/docker/docker/client/plugin_inspect_test.go deleted file mode 100644 index fae407e..0000000 --- a/vendor/github.com/docker/docker/client/plugin_inspect_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestPluginInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.PluginInspectWithRaw(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginInspect(t *testing.T) { - expectedURL := "/plugins/plugin_name" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - content, err := json.Marshal(types.Plugin{ - ID: "plugin_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - pluginInspect, _, err := client.PluginInspectWithRaw(context.Background(), "plugin_name") - if err != nil { - t.Fatal(err) - } - if pluginInspect.ID != "plugin_id" { - t.Fatalf("expected `plugin_id`, got %s", pluginInspect.ID) - } -} diff --git a/vendor/github.com/docker/docker/client/plugin_install.go b/vendor/github.com/docker/docker/client/plugin_install.go deleted file mode 100644 index 3217c4c..0000000 --- a/vendor/github.com/docker/docker/client/plugin_install.go +++ /dev/null @@ -1,113 +0,0 @@ -package client - -import ( - "encoding/json" - "io" - "net/http" - "net/url" - - "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" - "github.com/pkg/errors" - "golang.org/x/net/context" -) - -// PluginInstall installs a plugin -func (cli *Client) PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) (rc io.ReadCloser, err error) { - query := url.Values{} - if _, err := reference.ParseNamed(options.RemoteRef); err != nil { - return nil, errors.Wrap(err, "invalid remote reference") - } - query.Set("remote", options.RemoteRef) - - privileges, err := cli.checkPluginPermissions(ctx, query, options) - if err != nil { - return nil, err - } - - // set name for plugin pull, if empty should default to remote reference - query.Set("name", name) - - resp, err := cli.tryPluginPull(ctx, query, privileges, options.RegistryAuth) - if err != nil { - return nil, err - } - - name = resp.header.Get("Docker-Plugin-Name") - - pr, pw := io.Pipe() - go func() { // todo: the client should probably be designed more around the actual api - _, err := io.Copy(pw, resp.body) - if err != nil { - pw.CloseWithError(err) - return - } - defer func() { - if err != nil { - delResp, _ := cli.delete(ctx, "/plugins/"+name, nil, nil) - ensureReaderClosed(delResp) - } - }() - if len(options.Args) > 0 { - if err := cli.PluginSet(ctx, name, options.Args); err != nil { - pw.CloseWithError(err) - return - } - } - - if options.Disabled { - pw.Close() - return - } - - err = cli.PluginEnable(ctx, name, types.PluginEnableOptions{Timeout: 0}) - pw.CloseWithError(err) - }() - return pr, nil -} - -func (cli *Client) tryPluginPrivileges(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) { - headers := map[string][]string{"X-Registry-Auth": {registryAuth}} - return cli.get(ctx, "/plugins/privileges", query, headers) -} - -func (cli *Client) tryPluginPull(ctx context.Context, query url.Values, privileges types.PluginPrivileges, registryAuth string) (serverResponse, error) { - headers := map[string][]string{"X-Registry-Auth": {registryAuth}} - return cli.post(ctx, "/plugins/pull", query, privileges, headers) -} - -func (cli *Client) checkPluginPermissions(ctx context.Context, query url.Values, options types.PluginInstallOptions) (types.PluginPrivileges, error) { - resp, err := cli.tryPluginPrivileges(ctx, query, options.RegistryAuth) - if resp.statusCode == http.StatusUnauthorized && options.PrivilegeFunc != nil { - // todo: do inspect before to check existing name before checking privileges - newAuthHeader, privilegeErr := options.PrivilegeFunc() - if privilegeErr != nil { - ensureReaderClosed(resp) - return nil, privilegeErr - } - options.RegistryAuth = newAuthHeader - resp, err = cli.tryPluginPrivileges(ctx, query, options.RegistryAuth) - } - if err != nil { - ensureReaderClosed(resp) - return nil, err - } - - var privileges types.PluginPrivileges - if err := json.NewDecoder(resp.body).Decode(&privileges); err != nil { - ensureReaderClosed(resp) - return nil, err - } - ensureReaderClosed(resp) - - if !options.AcceptAllPermissions && options.AcceptPermissionsFunc != nil && len(privileges) > 0 { - accept, err := options.AcceptPermissionsFunc(privileges) - if err != nil { - return nil, err - } - if !accept { - return nil, pluginPermissionDenied{options.RemoteRef} - } - } - return privileges, nil -} diff --git a/vendor/github.com/docker/docker/client/plugin_list.go b/vendor/github.com/docker/docker/client/plugin_list.go deleted file mode 100644 index 88c480a..0000000 --- a/vendor/github.com/docker/docker/client/plugin_list.go +++ /dev/null @@ -1,21 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// PluginList returns the installed plugins -func (cli *Client) PluginList(ctx context.Context) (types.PluginsListResponse, error) { - var plugins types.PluginsListResponse - resp, err := cli.get(ctx, "/plugins", nil, nil) - if err != nil { - return plugins, err - } - - err = json.NewDecoder(resp.body).Decode(&plugins) - ensureReaderClosed(resp) - return plugins, err -} diff --git a/vendor/github.com/docker/docker/client/plugin_list_test.go b/vendor/github.com/docker/docker/client/plugin_list_test.go deleted file mode 100644 index 173e4b8..0000000 --- a/vendor/github.com/docker/docker/client/plugin_list_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestPluginListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.PluginList(context.Background()) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginList(t *testing.T) { - expectedURL := "/plugins" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - content, err := json.Marshal([]*types.Plugin{ - { - ID: "plugin_id1", - }, - { - ID: "plugin_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - plugins, err := client.PluginList(context.Background()) - if err != nil { - t.Fatal(err) - } - if len(plugins) != 2 { - t.Fatalf("expected 2 plugins, got %v", plugins) - } -} diff --git a/vendor/github.com/docker/docker/client/plugin_push.go b/vendor/github.com/docker/docker/client/plugin_push.go deleted file mode 100644 index 1e5f963..0000000 --- a/vendor/github.com/docker/docker/client/plugin_push.go +++ /dev/null @@ -1,17 +0,0 @@ -package client - -import ( - "io" - - "golang.org/x/net/context" -) - -// PluginPush pushes a plugin to a registry -func (cli *Client) PluginPush(ctx context.Context, name string, registryAuth string) (io.ReadCloser, error) { - headers := map[string][]string{"X-Registry-Auth": {registryAuth}} - resp, err := cli.post(ctx, "/plugins/"+name+"/push", nil, nil, headers) - if err != nil { - return nil, err - } - return resp.body, nil -} diff --git a/vendor/github.com/docker/docker/client/plugin_push_test.go b/vendor/github.com/docker/docker/client/plugin_push_test.go deleted file mode 100644 index d9f70cd..0000000 --- a/vendor/github.com/docker/docker/client/plugin_push_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestPluginPushError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.PluginPush(context.Background(), "plugin_name", "") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginPush(t *testing.T) { - expectedURL := "/plugins/plugin_name" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - auth := req.Header.Get("X-Registry-Auth") - if auth != "authtoken" { - return nil, fmt.Errorf("Invalid auth header : expected 'authtoken', got %s", auth) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - _, err := client.PluginPush(context.Background(), "plugin_name", "authtoken") - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/plugin_remove.go b/vendor/github.com/docker/docker/client/plugin_remove.go deleted file mode 100644 index b017e4d..0000000 --- a/vendor/github.com/docker/docker/client/plugin_remove.go +++ /dev/null @@ -1,20 +0,0 @@ -package client - -import ( - "net/url" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// PluginRemove removes a plugin -func (cli *Client) PluginRemove(ctx context.Context, name string, options types.PluginRemoveOptions) error { - query := url.Values{} - if options.Force { - query.Set("force", "1") - } - - resp, err := cli.delete(ctx, "/plugins/"+name, query, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/plugin_remove_test.go b/vendor/github.com/docker/docker/client/plugin_remove_test.go deleted file mode 100644 index a15f166..0000000 --- a/vendor/github.com/docker/docker/client/plugin_remove_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - - "golang.org/x/net/context" -) - -func TestPluginRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.PluginRemove(context.Background(), "plugin_name", types.PluginRemoveOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginRemove(t *testing.T) { - expectedURL := "/plugins/plugin_name" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.PluginRemove(context.Background(), "plugin_name", types.PluginRemoveOptions{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/plugin_set.go b/vendor/github.com/docker/docker/client/plugin_set.go deleted file mode 100644 index 3260d2a..0000000 --- a/vendor/github.com/docker/docker/client/plugin_set.go +++ /dev/null @@ -1,12 +0,0 @@ -package client - -import ( - "golang.org/x/net/context" -) - -// PluginSet modifies settings for an existing plugin -func (cli *Client) PluginSet(ctx context.Context, name string, args []string) error { - resp, err := cli.post(ctx, "/plugins/"+name+"/set", nil, args, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/plugin_set_test.go b/vendor/github.com/docker/docker/client/plugin_set_test.go deleted file mode 100644 index 2450254..0000000 --- a/vendor/github.com/docker/docker/client/plugin_set_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestPluginSetError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.PluginSet(context.Background(), "plugin_name", []string{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestPluginSet(t *testing.T) { - expectedURL := "/plugins/plugin_name/set" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.PluginSet(context.Background(), "plugin_name", []string{"arg1"}) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/plugin_upgrade.go b/vendor/github.com/docker/docker/client/plugin_upgrade.go deleted file mode 100644 index 95a4356..0000000 --- a/vendor/github.com/docker/docker/client/plugin_upgrade.go +++ /dev/null @@ -1,37 +0,0 @@ -package client - -import ( - "fmt" - "io" - "net/url" - - "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" - "github.com/pkg/errors" - "golang.org/x/net/context" -) - -// PluginUpgrade upgrades a plugin -func (cli *Client) PluginUpgrade(ctx context.Context, name string, options types.PluginInstallOptions) (rc io.ReadCloser, err error) { - query := url.Values{} - if _, err := reference.ParseNamed(options.RemoteRef); err != nil { - return nil, errors.Wrap(err, "invalid remote reference") - } - query.Set("remote", options.RemoteRef) - - privileges, err := cli.checkPluginPermissions(ctx, query, options) - if err != nil { - return nil, err - } - - resp, err := cli.tryPluginUpgrade(ctx, query, privileges, name, options.RegistryAuth) - if err != nil { - return nil, err - } - return resp.body, nil -} - -func (cli *Client) tryPluginUpgrade(ctx context.Context, query url.Values, privileges types.PluginPrivileges, name, registryAuth string) (serverResponse, error) { - headers := map[string][]string{"X-Registry-Auth": {registryAuth}} - return cli.post(ctx, fmt.Sprintf("/plugins/%s/upgrade", name), query, privileges, headers) -} diff --git a/vendor/github.com/docker/docker/client/request.go b/vendor/github.com/docker/docker/client/request.go deleted file mode 100644 index ac05363..0000000 --- a/vendor/github.com/docker/docker/client/request.go +++ /dev/null @@ -1,247 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "net/url" - "os" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/versions" - "github.com/pkg/errors" - "golang.org/x/net/context" - "golang.org/x/net/context/ctxhttp" -) - -// serverResponse is a wrapper for http API responses. -type serverResponse struct { - body io.ReadCloser - header http.Header - statusCode int -} - -// head sends an http request to the docker API using the method HEAD. -func (cli *Client) head(ctx context.Context, path string, query url.Values, headers map[string][]string) (serverResponse, error) { - return cli.sendRequest(ctx, "HEAD", path, query, nil, headers) -} - -// getWithContext sends an http request to the docker API using the method GET with a specific go context. -func (cli *Client) get(ctx context.Context, path string, query url.Values, headers map[string][]string) (serverResponse, error) { - return cli.sendRequest(ctx, "GET", path, query, nil, headers) -} - -// postWithContext sends an http request to the docker API using the method POST with a specific go context. -func (cli *Client) post(ctx context.Context, path string, query url.Values, obj interface{}, headers map[string][]string) (serverResponse, error) { - body, headers, err := encodeBody(obj, headers) - if err != nil { - return serverResponse{}, err - } - return cli.sendRequest(ctx, "POST", path, query, body, headers) -} - -func (cli *Client) postRaw(ctx context.Context, path string, query url.Values, body io.Reader, headers map[string][]string) (serverResponse, error) { - return cli.sendRequest(ctx, "POST", path, query, body, headers) -} - -// put sends an http request to the docker API using the method PUT. -func (cli *Client) put(ctx context.Context, path string, query url.Values, obj interface{}, headers map[string][]string) (serverResponse, error) { - body, headers, err := encodeBody(obj, headers) - if err != nil { - return serverResponse{}, err - } - return cli.sendRequest(ctx, "PUT", path, query, body, headers) -} - -// put sends an http request to the docker API using the method PUT. -func (cli *Client) putRaw(ctx context.Context, path string, query url.Values, body io.Reader, headers map[string][]string) (serverResponse, error) { - return cli.sendRequest(ctx, "PUT", path, query, body, headers) -} - -// delete sends an http request to the docker API using the method DELETE. -func (cli *Client) delete(ctx context.Context, path string, query url.Values, headers map[string][]string) (serverResponse, error) { - return cli.sendRequest(ctx, "DELETE", path, query, nil, headers) -} - -type headers map[string][]string - -func encodeBody(obj interface{}, headers headers) (io.Reader, headers, error) { - if obj == nil { - return nil, headers, nil - } - - body, err := encodeData(obj) - if err != nil { - return nil, headers, err - } - if headers == nil { - headers = make(map[string][]string) - } - headers["Content-Type"] = []string{"application/json"} - return body, headers, nil -} - -func (cli *Client) buildRequest(method, path string, body io.Reader, headers headers) (*http.Request, error) { - expectedPayload := (method == "POST" || method == "PUT") - if expectedPayload && body == nil { - body = bytes.NewReader([]byte{}) - } - - req, err := http.NewRequest(method, path, body) - if err != nil { - return nil, err - } - req = cli.addHeaders(req, headers) - - if cli.proto == "unix" || cli.proto == "npipe" { - // For local communications, it doesn't matter what the host is. We just - // need a valid and meaningful host name. (See #189) - req.Host = "docker" - } - - req.URL.Host = cli.addr - req.URL.Scheme = cli.scheme - - if expectedPayload && req.Header.Get("Content-Type") == "" { - req.Header.Set("Content-Type", "text/plain") - } - return req, nil -} - -func (cli *Client) sendRequest(ctx context.Context, method, path string, query url.Values, body io.Reader, headers headers) (serverResponse, error) { - req, err := cli.buildRequest(method, cli.getAPIPath(path, query), body, headers) - if err != nil { - return serverResponse{}, err - } - return cli.doRequest(ctx, req) -} - -func (cli *Client) doRequest(ctx context.Context, req *http.Request) (serverResponse, error) { - serverResp := serverResponse{statusCode: -1} - - resp, err := ctxhttp.Do(ctx, cli.client, req) - if err != nil { - if cli.scheme != "https" && strings.Contains(err.Error(), "malformed HTTP response") { - return serverResp, fmt.Errorf("%v.\n* Are you trying to connect to a TLS-enabled daemon without TLS?", err) - } - - if cli.scheme == "https" && strings.Contains(err.Error(), "bad certificate") { - return serverResp, fmt.Errorf("The server probably has client authentication (--tlsverify) enabled. Please check your TLS client certification settings: %v", err) - } - - // Don't decorate context sentinel errors; users may be comparing to - // them directly. - switch err { - case context.Canceled, context.DeadlineExceeded: - return serverResp, err - } - - if nErr, ok := err.(*url.Error); ok { - if nErr, ok := nErr.Err.(*net.OpError); ok { - if os.IsPermission(nErr.Err) { - return serverResp, errors.Wrapf(err, "Got permission denied while trying to connect to the Docker daemon socket at %v", cli.host) - } - } - } - - if err, ok := err.(net.Error); ok { - if err.Timeout() { - return serverResp, ErrorConnectionFailed(cli.host) - } - if !err.Temporary() { - if strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "dial unix") { - return serverResp, ErrorConnectionFailed(cli.host) - } - } - } - - // Although there's not a strongly typed error for this in go-winio, - // lots of people are using the default configuration for the docker - // daemon on Windows where the daemon is listening on a named pipe - // `//./pipe/docker_engine, and the client must be running elevated. - // Give users a clue rather than the not-overly useful message - // such as `error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.25/info: - // open //./pipe/docker_engine: The system cannot find the file specified.`. - // Note we can't string compare "The system cannot find the file specified" as - // this is localised - for example in French the error would be - // `open //./pipe/docker_engine: Le fichier spécifié est introuvable.` - if strings.Contains(err.Error(), `open //./pipe/docker_engine`) { - err = errors.New(err.Error() + " In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.") - } - - return serverResp, errors.Wrap(err, "error during connect") - } - - if resp != nil { - serverResp.statusCode = resp.StatusCode - } - - if serverResp.statusCode < 200 || serverResp.statusCode >= 400 { - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return serverResp, err - } - if len(body) == 0 { - return serverResp, fmt.Errorf("Error: request returned %s for API route and version %s, check if the server supports the requested API version", http.StatusText(serverResp.statusCode), req.URL) - } - - var errorMessage string - if (cli.version == "" || versions.GreaterThan(cli.version, "1.23")) && - resp.Header.Get("Content-Type") == "application/json" { - var errorResponse types.ErrorResponse - if err := json.Unmarshal(body, &errorResponse); err != nil { - return serverResp, fmt.Errorf("Error reading JSON: %v", err) - } - errorMessage = errorResponse.Message - } else { - errorMessage = string(body) - } - - return serverResp, fmt.Errorf("Error response from daemon: %s", strings.TrimSpace(errorMessage)) - } - - serverResp.body = resp.Body - serverResp.header = resp.Header - return serverResp, nil -} - -func (cli *Client) addHeaders(req *http.Request, headers headers) *http.Request { - // Add CLI Config's HTTP Headers BEFORE we set the Docker headers - // then the user can't change OUR headers - for k, v := range cli.customHTTPHeaders { - if versions.LessThan(cli.version, "1.25") && k == "User-Agent" { - continue - } - req.Header.Set(k, v) - } - - if headers != nil { - for k, v := range headers { - req.Header[k] = v - } - } - return req -} - -func encodeData(data interface{}) (*bytes.Buffer, error) { - params := bytes.NewBuffer(nil) - if data != nil { - if err := json.NewEncoder(params).Encode(data); err != nil { - return nil, err - } - } - return params, nil -} - -func ensureReaderClosed(response serverResponse) { - if body := response.body; body != nil { - // Drain up to 512 bytes and close the body to let the Transport reuse the connection - io.CopyN(ioutil.Discard, body, 512) - response.body.Close() - } -} diff --git a/vendor/github.com/docker/docker/client/request_test.go b/vendor/github.com/docker/docker/client/request_test.go deleted file mode 100644 index 63908ae..0000000 --- a/vendor/github.com/docker/docker/client/request_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// TestSetHostHeader should set fake host for local communications, set real host -// for normal communications. -func TestSetHostHeader(t *testing.T) { - testURL := "/test" - testCases := []struct { - host string - expectedHost string - expectedURLHost string - }{ - { - "unix:///var/run/docker.sock", - "docker", - "/var/run/docker.sock", - }, - { - "npipe:////./pipe/docker_engine", - "docker", - "//./pipe/docker_engine", - }, - { - "tcp://0.0.0.0:4243", - "", - "0.0.0.0:4243", - }, - { - "tcp://localhost:4243", - "", - "localhost:4243", - }, - } - - for c, test := range testCases { - proto, addr, basePath, err := ParseHost(test.host) - if err != nil { - t.Fatal(err) - } - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, testURL) { - return nil, fmt.Errorf("Test Case #%d: Expected URL %q, got %q", c, testURL, req.URL) - } - if req.Host != test.expectedHost { - return nil, fmt.Errorf("Test Case #%d: Expected host %q, got %q", c, test.expectedHost, req.Host) - } - if req.URL.Host != test.expectedURLHost { - return nil, fmt.Errorf("Test Case #%d: Expected URL host %q, got %q", c, test.expectedURLHost, req.URL.Host) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(([]byte("")))), - }, nil - }), - - proto: proto, - addr: addr, - basePath: basePath, - } - - _, err = client.sendRequest(context.Background(), "GET", testURL, nil, nil, nil) - if err != nil { - t.Fatal(err) - } - } -} - -// TestPlainTextError tests the server returning an error in plain text for -// backwards compatibility with API versions <1.24. All other tests use -// errors returned as JSON -func TestPlainTextError(t *testing.T) { - client := &Client{ - client: newMockClient(plainTextErrorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ContainerList(context.Background(), types.ContainerListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} diff --git a/vendor/github.com/docker/docker/client/secret_create.go b/vendor/github.com/docker/docker/client/secret_create.go deleted file mode 100644 index de8b041..0000000 --- a/vendor/github.com/docker/docker/client/secret_create.go +++ /dev/null @@ -1,24 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// SecretCreate creates a new Secret. -func (cli *Client) SecretCreate(ctx context.Context, secret swarm.SecretSpec) (types.SecretCreateResponse, error) { - var headers map[string][]string - - var response types.SecretCreateResponse - resp, err := cli.post(ctx, "/secrets/create", nil, secret, headers) - if err != nil { - return response, err - } - - err = json.NewDecoder(resp.body).Decode(&response) - ensureReaderClosed(resp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/secret_create_test.go b/vendor/github.com/docker/docker/client/secret_create_test.go deleted file mode 100644 index cb378c7..0000000 --- a/vendor/github.com/docker/docker/client/secret_create_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestSecretCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.SecretCreate(context.Background(), swarm.SecretSpec{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSecretCreate(t *testing.T) { - expectedURL := "/secrets/create" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - b, err := json.Marshal(types.SecretCreateResponse{ - ID: "test_secret", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusCreated, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - r, err := client.SecretCreate(context.Background(), swarm.SecretSpec{}) - if err != nil { - t.Fatal(err) - } - if r.ID != "test_secret" { - t.Fatalf("expected `test_secret`, got %s", r.ID) - } -} diff --git a/vendor/github.com/docker/docker/client/secret_inspect.go b/vendor/github.com/docker/docker/client/secret_inspect.go deleted file mode 100644 index f774576..0000000 --- a/vendor/github.com/docker/docker/client/secret_inspect.go +++ /dev/null @@ -1,34 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// SecretInspectWithRaw returns the secret information with raw data -func (cli *Client) SecretInspectWithRaw(ctx context.Context, id string) (swarm.Secret, []byte, error) { - resp, err := cli.get(ctx, "/secrets/"+id, nil, nil) - if err != nil { - if resp.statusCode == http.StatusNotFound { - return swarm.Secret{}, nil, secretNotFoundError{id} - } - return swarm.Secret{}, nil, err - } - defer ensureReaderClosed(resp) - - body, err := ioutil.ReadAll(resp.body) - if err != nil { - return swarm.Secret{}, nil, err - } - - var secret swarm.Secret - rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&secret) - - return secret, body, err -} diff --git a/vendor/github.com/docker/docker/client/secret_inspect_test.go b/vendor/github.com/docker/docker/client/secret_inspect_test.go deleted file mode 100644 index 423d986..0000000 --- a/vendor/github.com/docker/docker/client/secret_inspect_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestSecretInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.SecretInspectWithRaw(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSecretInspectSecretNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, _, err := client.SecretInspectWithRaw(context.Background(), "unknown") - if err == nil || !IsErrSecretNotFound(err) { - t.Fatalf("expected an secretNotFoundError error, got %v", err) - } -} - -func TestSecretInspect(t *testing.T) { - expectedURL := "/secrets/secret_id" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - content, err := json.Marshal(swarm.Secret{ - ID: "secret_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - secretInspect, _, err := client.SecretInspectWithRaw(context.Background(), "secret_id") - if err != nil { - t.Fatal(err) - } - if secretInspect.ID != "secret_id" { - t.Fatalf("expected `secret_id`, got %s", secretInspect.ID) - } -} diff --git a/vendor/github.com/docker/docker/client/secret_list.go b/vendor/github.com/docker/docker/client/secret_list.go deleted file mode 100644 index 7e9d5ec..0000000 --- a/vendor/github.com/docker/docker/client/secret_list.go +++ /dev/null @@ -1,35 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// SecretList returns the list of secrets. -func (cli *Client) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) { - query := url.Values{} - - if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) - if err != nil { - return nil, err - } - - query.Set("filters", filterJSON) - } - - resp, err := cli.get(ctx, "/secrets", query, nil) - if err != nil { - return nil, err - } - - var secrets []swarm.Secret - err = json.NewDecoder(resp.body).Decode(&secrets) - ensureReaderClosed(resp) - return secrets, err -} diff --git a/vendor/github.com/docker/docker/client/secret_list_test.go b/vendor/github.com/docker/docker/client/secret_list_test.go deleted file mode 100644 index 1ac11cd..0000000 --- a/vendor/github.com/docker/docker/client/secret_list_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestSecretListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.SecretList(context.Background(), types.SecretListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSecretList(t *testing.T) { - expectedURL := "/secrets" - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - - listCases := []struct { - options types.SecretListOptions - expectedQueryParams map[string]string - }{ - { - options: types.SecretListOptions{}, - expectedQueryParams: map[string]string{ - "filters": "", - }, - }, - { - options: types.SecretListOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": `{"label":{"label1":true,"label2":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]swarm.Secret{ - { - ID: "secret_id1", - }, - { - ID: "secret_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - secrets, err := client.SecretList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(secrets) != 2 { - t.Fatalf("expected 2 secrets, got %v", secrets) - } - } -} diff --git a/vendor/github.com/docker/docker/client/secret_remove.go b/vendor/github.com/docker/docker/client/secret_remove.go deleted file mode 100644 index 1955b98..0000000 --- a/vendor/github.com/docker/docker/client/secret_remove.go +++ /dev/null @@ -1,10 +0,0 @@ -package client - -import "golang.org/x/net/context" - -// SecretRemove removes a Secret. -func (cli *Client) SecretRemove(ctx context.Context, id string) error { - resp, err := cli.delete(ctx, "/secrets/"+id, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/secret_remove_test.go b/vendor/github.com/docker/docker/client/secret_remove_test.go deleted file mode 100644 index f269f78..0000000 --- a/vendor/github.com/docker/docker/client/secret_remove_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestSecretRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.SecretRemove(context.Background(), "secret_id") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSecretRemove(t *testing.T) { - expectedURL := "/secrets/secret_id" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.SecretRemove(context.Background(), "secret_id") - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/secret_update.go b/vendor/github.com/docker/docker/client/secret_update.go deleted file mode 100644 index b94e24a..0000000 --- a/vendor/github.com/docker/docker/client/secret_update.go +++ /dev/null @@ -1,19 +0,0 @@ -package client - -import ( - "net/url" - "strconv" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// SecretUpdate updates a Secret. Currently, the only part of a secret spec -// which can be updated is Labels. -func (cli *Client) SecretUpdate(ctx context.Context, id string, version swarm.Version, secret swarm.SecretSpec) error { - query := url.Values{} - query.Set("version", strconv.FormatUint(version.Index, 10)) - resp, err := cli.post(ctx, "/secrets/"+id+"/update", query, secret, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/secret_update_test.go b/vendor/github.com/docker/docker/client/secret_update_test.go deleted file mode 100644 index c620985..0000000 --- a/vendor/github.com/docker/docker/client/secret_update_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" -) - -func TestSecretUpdateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.SecretUpdate(context.Background(), "secret_id", swarm.Version{}, swarm.SecretSpec{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSecretUpdate(t *testing.T) { - expectedURL := "/secrets/secret_id/update" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.SecretUpdate(context.Background(), "secret_id", swarm.Version{}, swarm.SecretSpec{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/service_create.go b/vendor/github.com/docker/docker/client/service_create.go deleted file mode 100644 index 3d1be22..0000000 --- a/vendor/github.com/docker/docker/client/service_create.go +++ /dev/null @@ -1,30 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// ServiceCreate creates a new Service. -func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error) { - var headers map[string][]string - - if options.EncodedRegistryAuth != "" { - headers = map[string][]string{ - "X-Registry-Auth": {options.EncodedRegistryAuth}, - } - } - - var response types.ServiceCreateResponse - resp, err := cli.post(ctx, "/services/create", nil, service, headers) - if err != nil { - return response, err - } - - err = json.NewDecoder(resp.body).Decode(&response) - ensureReaderClosed(resp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/service_create_test.go b/vendor/github.com/docker/docker/client/service_create_test.go deleted file mode 100644 index 1e07382..0000000 --- a/vendor/github.com/docker/docker/client/service_create_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestServiceCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, types.ServiceCreateOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestServiceCreate(t *testing.T) { - expectedURL := "/services/create" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - b, err := json.Marshal(types.ServiceCreateResponse{ - ID: "service_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(b)), - }, nil - }), - } - - r, err := client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, types.ServiceCreateOptions{}) - if err != nil { - t.Fatal(err) - } - if r.ID != "service_id" { - t.Fatalf("expected `service_id`, got %s", r.ID) - } -} diff --git a/vendor/github.com/docker/docker/client/service_inspect.go b/vendor/github.com/docker/docker/client/service_inspect.go deleted file mode 100644 index ca71cbd..0000000 --- a/vendor/github.com/docker/docker/client/service_inspect.go +++ /dev/null @@ -1,33 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// ServiceInspectWithRaw returns the service information and the raw data. -func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string) (swarm.Service, []byte, error) { - serverResp, err := cli.get(ctx, "/services/"+serviceID, nil, nil) - if err != nil { - if serverResp.statusCode == http.StatusNotFound { - return swarm.Service{}, nil, serviceNotFoundError{serviceID} - } - return swarm.Service{}, nil, err - } - defer ensureReaderClosed(serverResp) - - body, err := ioutil.ReadAll(serverResp.body) - if err != nil { - return swarm.Service{}, nil, err - } - - var response swarm.Service - rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&response) - return response, body, err -} diff --git a/vendor/github.com/docker/docker/client/service_inspect_test.go b/vendor/github.com/docker/docker/client/service_inspect_test.go deleted file mode 100644 index e235cf0..0000000 --- a/vendor/github.com/docker/docker/client/service_inspect_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestServiceInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.ServiceInspectWithRaw(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestServiceInspectServiceNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, _, err := client.ServiceInspectWithRaw(context.Background(), "unknown") - if err == nil || !IsErrServiceNotFound(err) { - t.Fatalf("expected an serviceNotFoundError error, got %v", err) - } -} - -func TestServiceInspect(t *testing.T) { - expectedURL := "/services/service_id" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - content, err := json.Marshal(swarm.Service{ - ID: "service_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - serviceInspect, _, err := client.ServiceInspectWithRaw(context.Background(), "service_id") - if err != nil { - t.Fatal(err) - } - if serviceInspect.ID != "service_id" { - t.Fatalf("expected `service_id`, got %s", serviceInspect.ID) - } -} diff --git a/vendor/github.com/docker/docker/client/service_list.go b/vendor/github.com/docker/docker/client/service_list.go deleted file mode 100644 index c29e6d4..0000000 --- a/vendor/github.com/docker/docker/client/service_list.go +++ /dev/null @@ -1,35 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// ServiceList returns the list of services. -func (cli *Client) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) { - query := url.Values{} - - if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) - if err != nil { - return nil, err - } - - query.Set("filters", filterJSON) - } - - resp, err := cli.get(ctx, "/services", query, nil) - if err != nil { - return nil, err - } - - var services []swarm.Service - err = json.NewDecoder(resp.body).Decode(&services) - ensureReaderClosed(resp) - return services, err -} diff --git a/vendor/github.com/docker/docker/client/service_list_test.go b/vendor/github.com/docker/docker/client/service_list_test.go deleted file mode 100644 index 213981e..0000000 --- a/vendor/github.com/docker/docker/client/service_list_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestServiceListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ServiceList(context.Background(), types.ServiceListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestServiceList(t *testing.T) { - expectedURL := "/services" - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - - listCases := []struct { - options types.ServiceListOptions - expectedQueryParams map[string]string - }{ - { - options: types.ServiceListOptions{}, - expectedQueryParams: map[string]string{ - "filters": "", - }, - }, - { - options: types.ServiceListOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": `{"label":{"label1":true,"label2":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]swarm.Service{ - { - ID: "service_id1", - }, - { - ID: "service_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - services, err := client.ServiceList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(services) != 2 { - t.Fatalf("expected 2 services, got %v", services) - } - } -} diff --git a/vendor/github.com/docker/docker/client/service_logs.go b/vendor/github.com/docker/docker/client/service_logs.go deleted file mode 100644 index 24384e3..0000000 --- a/vendor/github.com/docker/docker/client/service_logs.go +++ /dev/null @@ -1,52 +0,0 @@ -package client - -import ( - "io" - "net/url" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - timetypes "github.com/docker/docker/api/types/time" -) - -// ServiceLogs returns the logs generated by a service in an io.ReadCloser. -// It's up to the caller to close the stream. -func (cli *Client) ServiceLogs(ctx context.Context, serviceID string, options types.ContainerLogsOptions) (io.ReadCloser, error) { - query := url.Values{} - if options.ShowStdout { - query.Set("stdout", "1") - } - - if options.ShowStderr { - query.Set("stderr", "1") - } - - if options.Since != "" { - ts, err := timetypes.GetTimestamp(options.Since, time.Now()) - if err != nil { - return nil, err - } - query.Set("since", ts) - } - - if options.Timestamps { - query.Set("timestamps", "1") - } - - if options.Details { - query.Set("details", "1") - } - - if options.Follow { - query.Set("follow", "1") - } - query.Set("tail", options.Tail) - - resp, err := cli.get(ctx, "/services/"+serviceID+"/logs", query, nil) - if err != nil { - return nil, err - } - return resp.body, nil -} diff --git a/vendor/github.com/docker/docker/client/service_logs_test.go b/vendor/github.com/docker/docker/client/service_logs_test.go deleted file mode 100644 index a6d002b..0000000 --- a/vendor/github.com/docker/docker/client/service_logs_test.go +++ /dev/null @@ -1,133 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io" - "io/ioutil" - "log" - "net/http" - "os" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types" - - "golang.org/x/net/context" -) - -func TestServiceLogsError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - _, err := client.ServiceLogs(context.Background(), "service_id", types.ContainerLogsOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } - _, err = client.ServiceLogs(context.Background(), "service_id", types.ContainerLogsOptions{ - Since: "2006-01-02TZ", - }) - if err == nil || !strings.Contains(err.Error(), `parsing time "2006-01-02TZ"`) { - t.Fatalf("expected a 'parsing time' error, got %v", err) - } -} - -func TestServiceLogs(t *testing.T) { - expectedURL := "/services/service_id/logs" - cases := []struct { - options types.ContainerLogsOptions - expectedQueryParams map[string]string - }{ - { - expectedQueryParams: map[string]string{ - "tail": "", - }, - }, - { - options: types.ContainerLogsOptions{ - Tail: "any", - }, - expectedQueryParams: map[string]string{ - "tail": "any", - }, - }, - { - options: types.ContainerLogsOptions{ - ShowStdout: true, - ShowStderr: true, - Timestamps: true, - Details: true, - Follow: true, - }, - expectedQueryParams: map[string]string{ - "tail": "", - "stdout": "1", - "stderr": "1", - "timestamps": "1", - "details": "1", - "follow": "1", - }, - }, - { - options: types.ContainerLogsOptions{ - // An complete invalid date, timestamp or go duration will be - // passed as is - Since: "invalid but valid", - }, - expectedQueryParams: map[string]string{ - "tail": "", - "since": "invalid but valid", - }, - }, - } - for _, logCase := range cases { - client := &Client{ - client: newMockClient(func(r *http.Request) (*http.Response, error) { - if !strings.HasPrefix(r.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL) - } - // Check query parameters - query := r.URL.Query() - for key, expected := range logCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("response"))), - }, nil - }), - } - body, err := client.ServiceLogs(context.Background(), "service_id", logCase.options) - if err != nil { - t.Fatal(err) - } - defer body.Close() - content, err := ioutil.ReadAll(body) - if err != nil { - t.Fatal(err) - } - if string(content) != "response" { - t.Fatalf("expected response to contain 'response', got %s", string(content)) - } - } -} - -func ExampleClient_ServiceLogs_withTimeout() { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - client, _ := NewEnvClient() - reader, err := client.ServiceLogs(ctx, "service_id", types.ContainerLogsOptions{}) - if err != nil { - log.Fatal(err) - } - - _, err = io.Copy(os.Stdout, reader) - if err != nil && err != io.EOF { - log.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/service_remove.go b/vendor/github.com/docker/docker/client/service_remove.go deleted file mode 100644 index a9331f9..0000000 --- a/vendor/github.com/docker/docker/client/service_remove.go +++ /dev/null @@ -1,10 +0,0 @@ -package client - -import "golang.org/x/net/context" - -// ServiceRemove kills and removes a service. -func (cli *Client) ServiceRemove(ctx context.Context, serviceID string) error { - resp, err := cli.delete(ctx, "/services/"+serviceID, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/service_remove_test.go b/vendor/github.com/docker/docker/client/service_remove_test.go deleted file mode 100644 index 8e2ac25..0000000 --- a/vendor/github.com/docker/docker/client/service_remove_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestServiceRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.ServiceRemove(context.Background(), "service_id") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestServiceRemove(t *testing.T) { - expectedURL := "/services/service_id" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.ServiceRemove(context.Background(), "service_id") - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/service_update.go b/vendor/github.com/docker/docker/client/service_update.go deleted file mode 100644 index afa94d4..0000000 --- a/vendor/github.com/docker/docker/client/service_update.go +++ /dev/null @@ -1,41 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - "strconv" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// ServiceUpdate updates a Service. -func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) { - var ( - headers map[string][]string - query = url.Values{} - ) - - if options.EncodedRegistryAuth != "" { - headers = map[string][]string{ - "X-Registry-Auth": {options.EncodedRegistryAuth}, - } - } - - if options.RegistryAuthFrom != "" { - query.Set("registryAuthFrom", options.RegistryAuthFrom) - } - - query.Set("version", strconv.FormatUint(version.Index, 10)) - - var response types.ServiceUpdateResponse - resp, err := cli.post(ctx, "/services/"+serviceID+"/update", query, service, headers) - if err != nil { - return response, err - } - - err = json.NewDecoder(resp.body).Decode(&response) - ensureReaderClosed(resp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/service_update_test.go b/vendor/github.com/docker/docker/client/service_update_test.go deleted file mode 100644 index 76bea17..0000000 --- a/vendor/github.com/docker/docker/client/service_update_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" -) - -func TestServiceUpdateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.ServiceUpdate(context.Background(), "service_id", swarm.Version{}, swarm.ServiceSpec{}, types.ServiceUpdateOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestServiceUpdate(t *testing.T) { - expectedURL := "/services/service_id/update" - - updateCases := []struct { - swarmVersion swarm.Version - expectedVersion string - }{ - { - expectedVersion: "0", - }, - { - swarmVersion: swarm.Version{ - Index: 0, - }, - expectedVersion: "0", - }, - { - swarmVersion: swarm.Version{ - Index: 10, - }, - expectedVersion: "10", - }, - } - - for _, updateCase := range updateCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - version := req.URL.Query().Get("version") - if version != updateCase.expectedVersion { - return nil, fmt.Errorf("version not set in URL query properly, expected '%s', got %s", updateCase.expectedVersion, version) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))), - }, nil - }), - } - - _, err := client.ServiceUpdate(context.Background(), "service_id", updateCase.swarmVersion, swarm.ServiceSpec{}, types.ServiceUpdateOptions{}) - if err != nil { - t.Fatal(err) - } - } -} diff --git a/vendor/github.com/docker/docker/client/swarm_get_unlock_key.go b/vendor/github.com/docker/docker/client/swarm_get_unlock_key.go deleted file mode 100644 index be28d32..0000000 --- a/vendor/github.com/docker/docker/client/swarm_get_unlock_key.go +++ /dev/null @@ -1,21 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// SwarmGetUnlockKey retrieves the swarm's unlock key. -func (cli *Client) SwarmGetUnlockKey(ctx context.Context) (types.SwarmUnlockKeyResponse, error) { - serverResp, err := cli.get(ctx, "/swarm/unlockkey", nil, nil) - if err != nil { - return types.SwarmUnlockKeyResponse{}, err - } - - var response types.SwarmUnlockKeyResponse - err = json.NewDecoder(serverResp.body).Decode(&response) - ensureReaderClosed(serverResp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/swarm_init.go b/vendor/github.com/docker/docker/client/swarm_init.go deleted file mode 100644 index fd45d06..0000000 --- a/vendor/github.com/docker/docker/client/swarm_init.go +++ /dev/null @@ -1,21 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// SwarmInit initializes the Swarm. -func (cli *Client) SwarmInit(ctx context.Context, req swarm.InitRequest) (string, error) { - serverResp, err := cli.post(ctx, "/swarm/init", nil, req, nil) - if err != nil { - return "", err - } - - var response string - err = json.NewDecoder(serverResp.body).Decode(&response) - ensureReaderClosed(serverResp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/swarm_init_test.go b/vendor/github.com/docker/docker/client/swarm_init_test.go deleted file mode 100644 index 811155a..0000000 --- a/vendor/github.com/docker/docker/client/swarm_init_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" -) - -func TestSwarmInitError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.SwarmInit(context.Background(), swarm.InitRequest{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSwarmInit(t *testing.T) { - expectedURL := "/swarm/init" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(`"body"`))), - }, nil - }), - } - - resp, err := client.SwarmInit(context.Background(), swarm.InitRequest{ - ListenAddr: "0.0.0.0:2377", - }) - if err != nil { - t.Fatal(err) - } - if resp != "body" { - t.Fatalf("Expected 'body', got %s", resp) - } -} diff --git a/vendor/github.com/docker/docker/client/swarm_inspect.go b/vendor/github.com/docker/docker/client/swarm_inspect.go deleted file mode 100644 index 6d95cfc..0000000 --- a/vendor/github.com/docker/docker/client/swarm_inspect.go +++ /dev/null @@ -1,21 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// SwarmInspect inspects the Swarm. -func (cli *Client) SwarmInspect(ctx context.Context) (swarm.Swarm, error) { - serverResp, err := cli.get(ctx, "/swarm", nil, nil) - if err != nil { - return swarm.Swarm{}, err - } - - var response swarm.Swarm - err = json.NewDecoder(serverResp.body).Decode(&response) - ensureReaderClosed(serverResp) - return response, err -} diff --git a/vendor/github.com/docker/docker/client/swarm_inspect_test.go b/vendor/github.com/docker/docker/client/swarm_inspect_test.go deleted file mode 100644 index 6432d17..0000000 --- a/vendor/github.com/docker/docker/client/swarm_inspect_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestSwarmInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.SwarmInspect(context.Background()) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSwarmInspect(t *testing.T) { - expectedURL := "/swarm" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - content, err := json.Marshal(swarm.Swarm{ - ClusterInfo: swarm.ClusterInfo{ - ID: "swarm_id", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - swarmInspect, err := client.SwarmInspect(context.Background()) - if err != nil { - t.Fatal(err) - } - if swarmInspect.ID != "swarm_id" { - t.Fatalf("expected `swarm_id`, got %s", swarmInspect.ID) - } -} diff --git a/vendor/github.com/docker/docker/client/swarm_join.go b/vendor/github.com/docker/docker/client/swarm_join.go deleted file mode 100644 index cda9993..0000000 --- a/vendor/github.com/docker/docker/client/swarm_join.go +++ /dev/null @@ -1,13 +0,0 @@ -package client - -import ( - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// SwarmJoin joins the Swarm. -func (cli *Client) SwarmJoin(ctx context.Context, req swarm.JoinRequest) error { - resp, err := cli.post(ctx, "/swarm/join", nil, req, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/swarm_join_test.go b/vendor/github.com/docker/docker/client/swarm_join_test.go deleted file mode 100644 index 31ef2a7..0000000 --- a/vendor/github.com/docker/docker/client/swarm_join_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" -) - -func TestSwarmJoinError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.SwarmJoin(context.Background(), swarm.JoinRequest{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSwarmJoin(t *testing.T) { - expectedURL := "/swarm/join" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.SwarmJoin(context.Background(), swarm.JoinRequest{ - ListenAddr: "0.0.0.0:2377", - }) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/swarm_leave.go b/vendor/github.com/docker/docker/client/swarm_leave.go deleted file mode 100644 index a4df732..0000000 --- a/vendor/github.com/docker/docker/client/swarm_leave.go +++ /dev/null @@ -1,18 +0,0 @@ -package client - -import ( - "net/url" - - "golang.org/x/net/context" -) - -// SwarmLeave leaves the Swarm. -func (cli *Client) SwarmLeave(ctx context.Context, force bool) error { - query := url.Values{} - if force { - query.Set("force", "1") - } - resp, err := cli.post(ctx, "/swarm/leave", query, nil, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/swarm_leave_test.go b/vendor/github.com/docker/docker/client/swarm_leave_test.go deleted file mode 100644 index c96dac8..0000000 --- a/vendor/github.com/docker/docker/client/swarm_leave_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestSwarmLeaveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.SwarmLeave(context.Background(), false) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSwarmLeave(t *testing.T) { - expectedURL := "/swarm/leave" - - leaveCases := []struct { - force bool - expectedForce string - }{ - { - expectedForce: "", - }, - { - force: true, - expectedForce: "1", - }, - } - - for _, leaveCase := range leaveCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - force := req.URL.Query().Get("force") - if force != leaveCase.expectedForce { - return nil, fmt.Errorf("force not set in URL query properly. expected '%s', got %s", leaveCase.expectedForce, force) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.SwarmLeave(context.Background(), leaveCase.force) - if err != nil { - t.Fatal(err) - } - } -} diff --git a/vendor/github.com/docker/docker/client/swarm_unlock.go b/vendor/github.com/docker/docker/client/swarm_unlock.go deleted file mode 100644 index addfb59..0000000 --- a/vendor/github.com/docker/docker/client/swarm_unlock.go +++ /dev/null @@ -1,17 +0,0 @@ -package client - -import ( - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// SwarmUnlock unlockes locked swarm. -func (cli *Client) SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error { - serverResp, err := cli.post(ctx, "/swarm/unlock", nil, req, nil) - if err != nil { - return err - } - - ensureReaderClosed(serverResp) - return err -} diff --git a/vendor/github.com/docker/docker/client/swarm_update.go b/vendor/github.com/docker/docker/client/swarm_update.go deleted file mode 100644 index cc8eeb6..0000000 --- a/vendor/github.com/docker/docker/client/swarm_update.go +++ /dev/null @@ -1,22 +0,0 @@ -package client - -import ( - "fmt" - "net/url" - "strconv" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// SwarmUpdate updates the Swarm. -func (cli *Client) SwarmUpdate(ctx context.Context, version swarm.Version, swarm swarm.Spec, flags swarm.UpdateFlags) error { - query := url.Values{} - query.Set("version", strconv.FormatUint(version.Index, 10)) - query.Set("rotateWorkerToken", fmt.Sprintf("%v", flags.RotateWorkerToken)) - query.Set("rotateManagerToken", fmt.Sprintf("%v", flags.RotateManagerToken)) - query.Set("rotateManagerUnlockKey", fmt.Sprintf("%v", flags.RotateManagerUnlockKey)) - resp, err := cli.post(ctx, "/swarm/update", query, swarm, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/swarm_update_test.go b/vendor/github.com/docker/docker/client/swarm_update_test.go deleted file mode 100644 index 3b23db0..0000000 --- a/vendor/github.com/docker/docker/client/swarm_update_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types/swarm" -) - -func TestSwarmUpdateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.SwarmUpdate(context.Background(), swarm.Version{}, swarm.Spec{}, swarm.UpdateFlags{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestSwarmUpdate(t *testing.T) { - expectedURL := "/swarm/update" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), - }, nil - }), - } - - err := client.SwarmUpdate(context.Background(), swarm.Version{}, swarm.Spec{}, swarm.UpdateFlags{}) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/client/task_inspect.go b/vendor/github.com/docker/docker/client/task_inspect.go deleted file mode 100644 index bc8058f..0000000 --- a/vendor/github.com/docker/docker/client/task_inspect.go +++ /dev/null @@ -1,34 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/docker/docker/api/types/swarm" - - "golang.org/x/net/context" -) - -// TaskInspectWithRaw returns the task information and its raw representation.. -func (cli *Client) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) { - serverResp, err := cli.get(ctx, "/tasks/"+taskID, nil, nil) - if err != nil { - if serverResp.statusCode == http.StatusNotFound { - return swarm.Task{}, nil, taskNotFoundError{taskID} - } - return swarm.Task{}, nil, err - } - defer ensureReaderClosed(serverResp) - - body, err := ioutil.ReadAll(serverResp.body) - if err != nil { - return swarm.Task{}, nil, err - } - - var response swarm.Task - rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&response) - return response, body, err -} diff --git a/vendor/github.com/docker/docker/client/task_inspect_test.go b/vendor/github.com/docker/docker/client/task_inspect_test.go deleted file mode 100644 index 148cdad..0000000 --- a/vendor/github.com/docker/docker/client/task_inspect_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestTaskInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, _, err := client.TaskInspectWithRaw(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestTaskInspect(t *testing.T) { - expectedURL := "/tasks/task_id" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - content, err := json.Marshal(swarm.Task{ - ID: "task_id", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - taskInspect, _, err := client.TaskInspectWithRaw(context.Background(), "task_id") - if err != nil { - t.Fatal(err) - } - if taskInspect.ID != "task_id" { - t.Fatalf("expected `task_id`, got %s", taskInspect.ID) - } -} diff --git a/vendor/github.com/docker/docker/client/task_list.go b/vendor/github.com/docker/docker/client/task_list.go deleted file mode 100644 index 66324da..0000000 --- a/vendor/github.com/docker/docker/client/task_list.go +++ /dev/null @@ -1,35 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -// TaskList returns the list of tasks. -func (cli *Client) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) { - query := url.Values{} - - if options.Filters.Len() > 0 { - filterJSON, err := filters.ToParam(options.Filters) - if err != nil { - return nil, err - } - - query.Set("filters", filterJSON) - } - - resp, err := cli.get(ctx, "/tasks", query, nil) - if err != nil { - return nil, err - } - - var tasks []swarm.Task - err = json.NewDecoder(resp.body).Decode(&tasks) - ensureReaderClosed(resp) - return tasks, err -} diff --git a/vendor/github.com/docker/docker/client/task_list_test.go b/vendor/github.com/docker/docker/client/task_list_test.go deleted file mode 100644 index 2a9a4c4..0000000 --- a/vendor/github.com/docker/docker/client/task_list_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "golang.org/x/net/context" -) - -func TestTaskListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.TaskList(context.Background(), types.TaskListOptions{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestTaskList(t *testing.T) { - expectedURL := "/tasks" - - filters := filters.NewArgs() - filters.Add("label", "label1") - filters.Add("label", "label2") - - listCases := []struct { - options types.TaskListOptions - expectedQueryParams map[string]string - }{ - { - options: types.TaskListOptions{}, - expectedQueryParams: map[string]string{ - "filters": "", - }, - }, - { - options: types.TaskListOptions{ - Filters: filters, - }, - expectedQueryParams: map[string]string{ - "filters": `{"label":{"label1":true,"label2":true}}`, - }, - }, - } - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - for key, expected := range listCase.expectedQueryParams { - actual := query.Get(key) - if actual != expected { - return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual) - } - } - content, err := json.Marshal([]swarm.Task{ - { - ID: "task_id1", - }, - { - ID: "task_id2", - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - tasks, err := client.TaskList(context.Background(), listCase.options) - if err != nil { - t.Fatal(err) - } - if len(tasks) != 2 { - t.Fatalf("expected 2 tasks, got %v", tasks) - } - } -} diff --git a/vendor/github.com/docker/docker/client/testdata/ca.pem b/vendor/github.com/docker/docker/client/testdata/ca.pem deleted file mode 100644 index ad14d47..0000000 --- a/vendor/github.com/docker/docker/client/testdata/ca.pem +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIC0jCCAbqgAwIBAgIRAILlP5WWLaHkQ/m2ASHP7SowDQYJKoZIhvcNAQELBQAw -EjEQMA4GA1UEChMHdmluY2VudDAeFw0xNjAzMjQxMDE5MDBaFw0xOTAzMDkxMDE5 -MDBaMBIxEDAOBgNVBAoTB3ZpbmNlbnQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw -ggEKAoIBAQD0yZPKAGncoaxaU/QW9tWEHbrvDoGVF/65L8Si/jBrlAgLjhmmV1di -vKG9QPzuU8snxHro3/uCwyA6kTqw0U8bGwHxJq2Bpa6JBYj8N2jMJ+M+sjXgSo2t -E0zIzjTW2Pir3C8qwfrVL6NFp9xClwMD23SFZ0UsEH36NkfyrKBVeM8IOjJd4Wjs -xIcuvF3BTVkji84IJBW2JIKf9ZrzJwUlSCPgptRp4Evdbyp5d+UPxtwxD7qjW4lM -yQQ8vfcC4lKkVx5s/RNJ4fzd5uEgLdEbZ20qt7Zt/bLcxFHpUhH2teA0QjmrOWFh -gbL83s95/+hbSVhsO4hoFW7vTeiCCY4xAgMBAAGjIzAhMA4GA1UdDwEB/wQEAwIC -rDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBY51RHajuDuhO2 -tcm26jeNROzfffnjhvbOVPjSEdo9vI3JpMU/RuQw+nbNcLwJrdjL6UH7tD/36Y+q -NXH+xSIjWFH0zXGxrIUsVrvt6f8CbOvw7vD+gygOG+849PDQMbL6czP8rvXY7vZV -9pdpQfrENk4b5kePRW/6HaGSTvtgN7XOrYD9fp3pm/G534T2e3IxgYMRNwdB9Ul9 -bLwMqQqf4eiqqMs6x4IVmZUkGVMKiFKcvkNg9a+Ozx5pMizHeAezWMcZ5V+QJZVT -8lElSCKZ2Yy2xkcl7aeQMLwcAeZwfTp+Yu9dVzlqXiiBTLd1+LtAQCuKHzmw4Q8k -EvD5m49l ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/client/testdata/cert.pem b/vendor/github.com/docker/docker/client/testdata/cert.pem deleted file mode 100644 index 9000ffb..0000000 --- a/vendor/github.com/docker/docker/client/testdata/cert.pem +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIC8DCCAdigAwIBAgIRAJAS1glgcke4q7eCaretwgUwDQYJKoZIhvcNAQELBQAw -EjEQMA4GA1UEChMHdmluY2VudDAeFw0xNjAzMjQxMDE5MDBaFw0xOTAzMDkxMDE5 -MDBaMB4xHDAaBgNVBAoME3ZpbmNlbnQuPGJvb3RzdHJhcD4wggEiMA0GCSqGSIb3 -DQEBAQUAA4IBDwAwggEKAoIBAQClpvG442dGEvrRgmCrqY4kBml1LVlw2Y7ZDn6B -TKa52+MuGDmfXbO1UhclNqTXjLgAwKjPz/OvnPRxNEUoQEDbBd+Xev7rxTY5TvYI -27YH3fMH2LL2j62jum649abfhZ6ekD5eD8tCn3mnrEOgqRIlK7efPIVixq/ZqU1H -7ez0ggB7dmWHlhnUaxyQOCSnAX/7nKYQXqZgVvGhDeR2jp7GcnhbK/qPrZ/mOm83 -2IjCeYN145opYlzTSp64GYIZz7uqMNcnDKK37ZbS8MYcTjrRaHEiqZVVdIC+ghbx -qYqzbZRVfgztI9jwmifn0mYrN4yt+nhNYwBcRJ4Pv3uLFbo7AgMBAAGjNTAzMA4G -A1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAA -MA0GCSqGSIb3DQEBCwUAA4IBAQDg1r7nksjYgDFYEcBbrRrRHddIoK+RVmSBTTrq -8giC77m0srKdh9XTVWK1PUbGfODV1oD8m9QhPE8zPDyYQ8jeXNRSU5wXdkrTRmmY -w/T3SREqmE7CObMtusokHidjYFuqqCR07sJzqBKRlzr3o0EGe3tuEhUlF5ARY028 -eipaDcVlT5ChGcDa6LeJ4e05u4cVap0dd6Rp1w3Rx1AYAecdgtgBMnw1iWdl/nrC -sp26ZXNaAhFOUovlY9VY257AMd9hQV7WvAK4yNEHcckVu3uXTBmDgNSOPtl0QLsL -Kjlj75ksCx8nCln/hCut/0+kGTsGZqdV5c6ktgcGYRir/5Hs ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/client/testdata/key.pem b/vendor/github.com/docker/docker/client/testdata/key.pem deleted file mode 100644 index c0869df..0000000 --- a/vendor/github.com/docker/docker/client/testdata/key.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEApabxuONnRhL60YJgq6mOJAZpdS1ZcNmO2Q5+gUymudvjLhg5 -n12ztVIXJTak14y4AMCoz8/zr5z0cTRFKEBA2wXfl3r+68U2OU72CNu2B93zB9iy -9o+to7puuPWm34WenpA+Xg/LQp95p6xDoKkSJSu3nzyFYsav2alNR+3s9IIAe3Zl -h5YZ1GsckDgkpwF/+5ymEF6mYFbxoQ3kdo6exnJ4Wyv6j62f5jpvN9iIwnmDdeOa -KWJc00qeuBmCGc+7qjDXJwyit+2W0vDGHE460WhxIqmVVXSAvoIW8amKs22UVX4M -7SPY8Jon59JmKzeMrfp4TWMAXESeD797ixW6OwIDAQABAoIBAHfyAAleL8NfrtnR -S+pApbmUIvxD0AWUooispBE/zWG6xC72P5MTqDJctIGvpYCmVf3Fgvamns7EGYN2 -07Sngc6V3Ca1WqyhaffpIuGbJZ1gqr89u6gotRRexBmNVj13ZTlvPJmjWgxtqQsu -AvHsOkVL+HOGwRaaw24Z1umEcBVCepl7PGTqsLeJUtBUZBiqdJTu4JYLAB6BggBI -OxhHoTWvlNWwzezo2C/IXkXcXD/tp3i5vTn5rAXHSMQkdMAUh7/xJ73Fl36gxZhp -W7NoPKaS9qNh8jhs6p54S7tInb6+mrKtvRFKl5XAR3istXrXteT5UaukpuBbQ/5d -qf4BXuECgYEAzoOKxMee5tG/G9iC6ImNq5xGAZm0OnmteNgIEQj49If1Q68av525 -FioqdC9zV+blfHQqXEIUeum4JAou4xqmB8Lw2H0lYwOJ1IkpUy3QJjU1IrI+U5Qy -ryZuA9cxSTLf1AJFbROsoZDpjaBh0uUQkD/4PHpwXMgHu/3CaJ4nTEkCgYEAzVjE -VWgczWJGyRxmHSeR51ft1jrlChZHEd3HwgLfo854JIj+MGUH4KPLSMIkYNuyiwNQ -W7zdXCB47U8afSL/lPTv1M5+ZsWY6sZAT6gtp/IeU0Va943h9cj10fAOBJaz1H6M -jnZS4jjWhVInE7wpCDVCwDRoHHJ84kb6JeflamMCgYBDQDcKie9HP3q6uLE4xMKr -5gIuNz2n5UQGnGNUGNXp2/SVDArr55MEksqsd19aesi01KeOz74XoNDke6R1NJJo -6KTB+08XhWl3GwuoGL02FBGvsNf3I8W1oBAnlAZqzfRx+CNfuA55ttU318jDgvD3 -6L0QBNdef411PNf4dbhacQKBgAd/e0PHFm4lbYJAaDYeUMSKwGN3KQ/SOmwblgSu -iC36BwcGfYmU1tHMCUsx05Q50W4kA9Ylskt/4AqCPexdz8lHnE4/7/uesXO5I3YF -JQ2h2Jufx6+MXbjUyq0Mv+ZI/m3+5PD6vxIFk0ew9T5SO4lSMIrGHxsSzx6QCuhB -bG4TAoGBAJ5PWG7d2CyCjLtfF8J4NxykRvIQ8l/3kDvDdNrXiXbgonojo2lgRYaM -5LoK9ApN8KHdedpTRipBaDA22Sp5SjMcUE7A6q42PJCL9r+BRYF0foFQx/rqpCff -pVWKgwIPoKnfxDqN1RUgyFcx1jbA3XVJZCuT+wbMuDQ9nlvulD1W ------END RSA PRIVATE KEY----- diff --git a/vendor/github.com/docker/docker/client/transport.go b/vendor/github.com/docker/docker/client/transport.go deleted file mode 100644 index f04e601..0000000 --- a/vendor/github.com/docker/docker/client/transport.go +++ /dev/null @@ -1,28 +0,0 @@ -package client - -import ( - "crypto/tls" - "errors" - "net/http" -) - -var errTLSConfigUnavailable = errors.New("TLSConfig unavailable") - -// transportFunc allows us to inject a mock transport for testing. We define it -// here so we can detect the tlsconfig and return nil for only this type. -type transportFunc func(*http.Request) (*http.Response, error) - -func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) { - return tf(req) -} - -// resolveTLSConfig attempts to resolve the tls configuration from the -// RoundTripper. -func resolveTLSConfig(transport http.RoundTripper) *tls.Config { - switch tr := transport.(type) { - case *http.Transport: - return tr.TLSClientConfig - default: - return nil - } -} diff --git a/vendor/github.com/docker/docker/client/utils.go b/vendor/github.com/docker/docker/client/utils.go deleted file mode 100644 index 23d520e..0000000 --- a/vendor/github.com/docker/docker/client/utils.go +++ /dev/null @@ -1,33 +0,0 @@ -package client - -import ( - "github.com/docker/docker/api/types/filters" - "net/url" - "regexp" -) - -var headerRegexp = regexp.MustCompile(`\ADocker/.+\s\((.+)\)\z`) - -// getDockerOS returns the operating system based on the server header from the daemon. -func getDockerOS(serverHeader string) string { - var osType string - matches := headerRegexp.FindStringSubmatch(serverHeader) - if len(matches) > 0 { - osType = matches[1] - } - return osType -} - -// getFiltersQuery returns a url query with "filters" query term, based on the -// filters provided. -func getFiltersQuery(f filters.Args) (url.Values, error) { - query := url.Values{} - if f.Len() > 0 { - filterJSON, err := filters.ToParam(f) - if err != nil { - return query, err - } - query.Set("filters", filterJSON) - } - return query, nil -} diff --git a/vendor/github.com/docker/docker/client/version.go b/vendor/github.com/docker/docker/client/version.go deleted file mode 100644 index 933ceb4..0000000 --- a/vendor/github.com/docker/docker/client/version.go +++ /dev/null @@ -1,21 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// ServerVersion returns information of the docker client and server host. -func (cli *Client) ServerVersion(ctx context.Context) (types.Version, error) { - resp, err := cli.get(ctx, "/version", nil, nil) - if err != nil { - return types.Version{}, err - } - - var server types.Version - err = json.NewDecoder(resp.body).Decode(&server) - ensureReaderClosed(resp) - return server, err -} diff --git a/vendor/github.com/docker/docker/client/volume_create.go b/vendor/github.com/docker/docker/client/volume_create.go deleted file mode 100644 index 9620c87..0000000 --- a/vendor/github.com/docker/docker/client/volume_create.go +++ /dev/null @@ -1,21 +0,0 @@ -package client - -import ( - "encoding/json" - - "github.com/docker/docker/api/types" - volumetypes "github.com/docker/docker/api/types/volume" - "golang.org/x/net/context" -) - -// VolumeCreate creates a volume in the docker host. -func (cli *Client) VolumeCreate(ctx context.Context, options volumetypes.VolumesCreateBody) (types.Volume, error) { - var volume types.Volume - resp, err := cli.post(ctx, "/volumes/create", nil, options, nil) - if err != nil { - return volume, err - } - err = json.NewDecoder(resp.body).Decode(&volume) - ensureReaderClosed(resp) - return volume, err -} diff --git a/vendor/github.com/docker/docker/client/volume_create_test.go b/vendor/github.com/docker/docker/client/volume_create_test.go deleted file mode 100644 index 9f1b254..0000000 --- a/vendor/github.com/docker/docker/client/volume_create_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - volumetypes "github.com/docker/docker/api/types/volume" - "golang.org/x/net/context" -) - -func TestVolumeCreateError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{}) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestVolumeCreate(t *testing.T) { - expectedURL := "/volumes/create" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - - if req.Method != "POST" { - return nil, fmt.Errorf("expected POST method, got %s", req.Method) - } - - content, err := json.Marshal(types.Volume{ - Name: "volume", - Driver: "local", - Mountpoint: "mountpoint", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - volume, err := client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{ - Name: "myvolume", - Driver: "mydriver", - DriverOpts: map[string]string{ - "opt-key": "opt-value", - }, - }) - if err != nil { - t.Fatal(err) - } - if volume.Name != "volume" { - t.Fatalf("expected volume.Name to be 'volume', got %s", volume.Name) - } - if volume.Driver != "local" { - t.Fatalf("expected volume.Driver to be 'local', got %s", volume.Driver) - } - if volume.Mountpoint != "mountpoint" { - t.Fatalf("expected volume.Mountpoint to be 'mountpoint', got %s", volume.Mountpoint) - } -} diff --git a/vendor/github.com/docker/docker/client/volume_inspect.go b/vendor/github.com/docker/docker/client/volume_inspect.go deleted file mode 100644 index 3860e9b..0000000 --- a/vendor/github.com/docker/docker/client/volume_inspect.go +++ /dev/null @@ -1,38 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -// VolumeInspect returns the information about a specific volume in the docker host. -func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) { - volume, _, err := cli.VolumeInspectWithRaw(ctx, volumeID) - return volume, err -} - -// VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation -func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) { - var volume types.Volume - resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil) - if err != nil { - if resp.statusCode == http.StatusNotFound { - return volume, nil, volumeNotFoundError{volumeID} - } - return volume, nil, err - } - defer ensureReaderClosed(resp) - - body, err := ioutil.ReadAll(resp.body) - if err != nil { - return volume, nil, err - } - rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&volume) - return volume, body, err -} diff --git a/vendor/github.com/docker/docker/client/volume_inspect_test.go b/vendor/github.com/docker/docker/client/volume_inspect_test.go deleted file mode 100644 index 0d1d118..0000000 --- a/vendor/github.com/docker/docker/client/volume_inspect_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "golang.org/x/net/context" -) - -func TestVolumeInspectError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.VolumeInspect(context.Background(), "nothing") - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestVolumeInspectNotFound(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusNotFound, "Server error")), - } - - _, err := client.VolumeInspect(context.Background(), "unknown") - if err == nil || !IsErrVolumeNotFound(err) { - t.Fatalf("expected a volumeNotFound error, got %v", err) - } -} - -func TestVolumeInspect(t *testing.T) { - expectedURL := "/volumes/volume_id" - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "GET" { - return nil, fmt.Errorf("expected GET method, got %s", req.Method) - } - content, err := json.Marshal(types.Volume{ - Name: "name", - Driver: "driver", - Mountpoint: "mountpoint", - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - v, err := client.VolumeInspect(context.Background(), "volume_id") - if err != nil { - t.Fatal(err) - } - if v.Name != "name" { - t.Fatalf("expected `name`, got %s", v.Name) - } - if v.Driver != "driver" { - t.Fatalf("expected `driver`, got %s", v.Driver) - } - if v.Mountpoint != "mountpoint" { - t.Fatalf("expected `mountpoint`, got %s", v.Mountpoint) - } -} diff --git a/vendor/github.com/docker/docker/client/volume_list.go b/vendor/github.com/docker/docker/client/volume_list.go deleted file mode 100644 index 32247ce..0000000 --- a/vendor/github.com/docker/docker/client/volume_list.go +++ /dev/null @@ -1,32 +0,0 @@ -package client - -import ( - "encoding/json" - "net/url" - - "github.com/docker/docker/api/types/filters" - volumetypes "github.com/docker/docker/api/types/volume" - "golang.org/x/net/context" -) - -// VolumeList returns the volumes configured in the docker host. -func (cli *Client) VolumeList(ctx context.Context, filter filters.Args) (volumetypes.VolumesListOKBody, error) { - var volumes volumetypes.VolumesListOKBody - query := url.Values{} - - if filter.Len() > 0 { - filterJSON, err := filters.ToParamWithVersion(cli.version, filter) - if err != nil { - return volumes, err - } - query.Set("filters", filterJSON) - } - resp, err := cli.get(ctx, "/volumes", query, nil) - if err != nil { - return volumes, err - } - - err = json.NewDecoder(resp.body).Decode(&volumes) - ensureReaderClosed(resp) - return volumes, err -} diff --git a/vendor/github.com/docker/docker/client/volume_list_test.go b/vendor/github.com/docker/docker/client/volume_list_test.go deleted file mode 100644 index f29639b..0000000 --- a/vendor/github.com/docker/docker/client/volume_list_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package client - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - volumetypes "github.com/docker/docker/api/types/volume" - "golang.org/x/net/context" -) - -func TestVolumeListError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - _, err := client.VolumeList(context.Background(), filters.NewArgs()) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestVolumeList(t *testing.T) { - expectedURL := "/volumes" - - noDanglingFilters := filters.NewArgs() - noDanglingFilters.Add("dangling", "false") - - danglingFilters := filters.NewArgs() - danglingFilters.Add("dangling", "true") - - labelFilters := filters.NewArgs() - labelFilters.Add("label", "label1") - labelFilters.Add("label", "label2") - - listCases := []struct { - filters filters.Args - expectedFilters string - }{ - { - filters: filters.NewArgs(), - expectedFilters: "", - }, { - filters: noDanglingFilters, - expectedFilters: `{"dangling":{"false":true}}`, - }, { - filters: danglingFilters, - expectedFilters: `{"dangling":{"true":true}}`, - }, { - filters: labelFilters, - expectedFilters: `{"label":{"label1":true,"label2":true}}`, - }, - } - - for _, listCase := range listCases { - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - query := req.URL.Query() - actualFilters := query.Get("filters") - if actualFilters != listCase.expectedFilters { - return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters) - } - content, err := json.Marshal(volumetypes.VolumesListOKBody{ - Volumes: []*types.Volume{ - { - Name: "volume", - Driver: "local", - }, - }, - }) - if err != nil { - return nil, err - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader(content)), - }, nil - }), - } - - volumeResponse, err := client.VolumeList(context.Background(), listCase.filters) - if err != nil { - t.Fatal(err) - } - if len(volumeResponse.Volumes) != 1 { - t.Fatalf("expected 1 volume, got %v", volumeResponse.Volumes) - } - } -} diff --git a/vendor/github.com/docker/docker/client/volume_prune.go b/vendor/github.com/docker/docker/client/volume_prune.go deleted file mode 100644 index a07e4ce..0000000 --- a/vendor/github.com/docker/docker/client/volume_prune.go +++ /dev/null @@ -1,36 +0,0 @@ -package client - -import ( - "encoding/json" - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "golang.org/x/net/context" -) - -// VolumesPrune requests the daemon to delete unused data -func (cli *Client) VolumesPrune(ctx context.Context, pruneFilters filters.Args) (types.VolumesPruneReport, error) { - var report types.VolumesPruneReport - - if err := cli.NewVersionError("1.25", "volume prune"); err != nil { - return report, err - } - - query, err := getFiltersQuery(pruneFilters) - if err != nil { - return report, err - } - - serverResp, err := cli.post(ctx, "/volumes/prune", query, nil, nil) - if err != nil { - return report, err - } - defer ensureReaderClosed(serverResp) - - if err := json.NewDecoder(serverResp.body).Decode(&report); err != nil { - return report, fmt.Errorf("Error retrieving disk usage: %v", err) - } - - return report, nil -} diff --git a/vendor/github.com/docker/docker/client/volume_remove.go b/vendor/github.com/docker/docker/client/volume_remove.go deleted file mode 100644 index 6c26575..0000000 --- a/vendor/github.com/docker/docker/client/volume_remove.go +++ /dev/null @@ -1,21 +0,0 @@ -package client - -import ( - "net/url" - - "github.com/docker/docker/api/types/versions" - "golang.org/x/net/context" -) - -// VolumeRemove removes a volume from the docker host. -func (cli *Client) VolumeRemove(ctx context.Context, volumeID string, force bool) error { - query := url.Values{} - if versions.GreaterThanOrEqualTo(cli.version, "1.25") { - if force { - query.Set("force", "1") - } - } - resp, err := cli.delete(ctx, "/volumes/"+volumeID, query, nil) - ensureReaderClosed(resp) - return err -} diff --git a/vendor/github.com/docker/docker/client/volume_remove_test.go b/vendor/github.com/docker/docker/client/volume_remove_test.go deleted file mode 100644 index 1fe6573..0000000 --- a/vendor/github.com/docker/docker/client/volume_remove_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "strings" - "testing" - - "golang.org/x/net/context" -) - -func TestVolumeRemoveError(t *testing.T) { - client := &Client{ - client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), - } - - err := client.VolumeRemove(context.Background(), "volume_id", false) - if err == nil || err.Error() != "Error response from daemon: Server error" { - t.Fatalf("expected a Server Error, got %v", err) - } -} - -func TestVolumeRemove(t *testing.T) { - expectedURL := "/volumes/volume_id" - - client := &Client{ - client: newMockClient(func(req *http.Request) (*http.Response, error) { - if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) - } - if req.Method != "DELETE" { - return nil, fmt.Errorf("expected DELETE method, got %s", req.Method) - } - return &http.Response{ - StatusCode: http.StatusOK, - Body: ioutil.NopCloser(bytes.NewReader([]byte("body"))), - }, nil - }), - } - - err := client.VolumeRemove(context.Background(), "volume_id", false) - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/cmd/docker/daemon_none.go b/vendor/github.com/docker/docker/cmd/docker/daemon_none.go deleted file mode 100644 index 65f9f37..0000000 --- a/vendor/github.com/docker/docker/cmd/docker/daemon_none.go +++ /dev/null @@ -1,27 +0,0 @@ -// +build !daemon - -package main - -import ( - "fmt" - "runtime" - "strings" - - "github.com/spf13/cobra" -) - -func newDaemonCommand() *cobra.Command { - return &cobra.Command{ - Use: "daemon", - Hidden: true, - RunE: func(cmd *cobra.Command, args []string) error { - return runDaemon() - }, - } -} - -func runDaemon() error { - return fmt.Errorf( - "`docker daemon` is not supported on %s. Please run `dockerd` directly", - strings.Title(runtime.GOOS)) -} diff --git a/vendor/github.com/docker/docker/cmd/docker/daemon_none_test.go b/vendor/github.com/docker/docker/cmd/docker/daemon_none_test.go deleted file mode 100644 index 32032fe..0000000 --- a/vendor/github.com/docker/docker/cmd/docker/daemon_none_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// +build !daemon - -package main - -import ( - "testing" - - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestDaemonCommand(t *testing.T) { - cmd := newDaemonCommand() - cmd.SetArgs([]string{"--help"}) - err := cmd.Execute() - - assert.Error(t, err, "Please run `dockerd`") -} diff --git a/vendor/github.com/docker/docker/cmd/docker/daemon_unit_test.go b/vendor/github.com/docker/docker/cmd/docker/daemon_unit_test.go deleted file mode 100644 index 26348a8..0000000 --- a/vendor/github.com/docker/docker/cmd/docker/daemon_unit_test.go +++ /dev/null @@ -1,30 +0,0 @@ -// +build daemon - -package main - -import ( - "testing" - - "github.com/docker/docker/pkg/testutil/assert" - "github.com/spf13/cobra" -) - -func stubRun(cmd *cobra.Command, args []string) error { - return nil -} - -func TestDaemonCommandHelp(t *testing.T) { - cmd := newDaemonCommand() - cmd.RunE = stubRun - cmd.SetArgs([]string{"--help"}) - err := cmd.Execute() - assert.NilError(t, err) -} - -func TestDaemonCommand(t *testing.T) { - cmd := newDaemonCommand() - cmd.RunE = stubRun - cmd.SetArgs([]string{"--containerd", "/foo"}) - err := cmd.Execute() - assert.NilError(t, err) -} diff --git a/vendor/github.com/docker/docker/cmd/docker/daemon_unix.go b/vendor/github.com/docker/docker/cmd/docker/daemon_unix.go deleted file mode 100644 index f68d220..0000000 --- a/vendor/github.com/docker/docker/cmd/docker/daemon_unix.go +++ /dev/null @@ -1,79 +0,0 @@ -// +build daemon - -package main - -import ( - "fmt" - - "os" - "os/exec" - "path/filepath" - "syscall" - - "github.com/spf13/cobra" -) - -const daemonBinary = "dockerd" - -func newDaemonCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "daemon", - Hidden: true, - Args: cobra.ArbitraryArgs, - DisableFlagParsing: true, - RunE: func(cmd *cobra.Command, args []string) error { - return runDaemon() - }, - Deprecated: "and will be removed in Docker 1.16. Please run `dockerd` directly.", - } - cmd.SetHelpFunc(helpFunc) - return cmd -} - -// CmdDaemon execs dockerd with the same flags -func runDaemon() error { - // Use os.Args[1:] so that "global" args are passed to dockerd - return execDaemon(stripDaemonArg(os.Args[1:])) -} - -func execDaemon(args []string) error { - binaryPath, err := findDaemonBinary() - if err != nil { - return err - } - - return syscall.Exec( - binaryPath, - append([]string{daemonBinary}, args...), - os.Environ()) -} - -func helpFunc(cmd *cobra.Command, args []string) { - if err := execDaemon([]string{"--help"}); err != nil { - fmt.Fprintf(os.Stderr, "%s\n", err.Error()) - } -} - -// findDaemonBinary looks for the path to the dockerd binary starting with -// the directory of the current executable (if one exists) and followed by $PATH -func findDaemonBinary() (string, error) { - execDirname := filepath.Dir(os.Args[0]) - if execDirname != "" { - binaryPath := filepath.Join(execDirname, daemonBinary) - if _, err := os.Stat(binaryPath); err == nil { - return binaryPath, nil - } - } - - return exec.LookPath(daemonBinary) -} - -// stripDaemonArg removes the `daemon` argument from the list -func stripDaemonArg(args []string) []string { - for i, arg := range args { - if arg == "daemon" { - return append(args[:i], args[i+1:]...) - } - } - return args -} diff --git a/vendor/github.com/docker/docker/cmd/docker/docker.go b/vendor/github.com/docker/docker/cmd/docker/docker.go deleted file mode 100644 index d4847a9..0000000 --- a/vendor/github.com/docker/docker/cmd/docker/docker.go +++ /dev/null @@ -1,180 +0,0 @@ -package main - -import ( - "errors" - "fmt" - "os" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/cli" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/commands" - cliflags "github.com/docker/docker/cli/flags" - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/pkg/term" - "github.com/docker/docker/utils" - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command { - opts := cliflags.NewClientOptions() - var flags *pflag.FlagSet - - cmd := &cobra.Command{ - Use: "docker [OPTIONS] COMMAND [ARG...]", - Short: "A self-sufficient runtime for containers", - SilenceUsage: true, - SilenceErrors: true, - TraverseChildren: true, - Args: noArgs, - RunE: func(cmd *cobra.Command, args []string) error { - if opts.Version { - showVersion() - return nil - } - return dockerCli.ShowHelp(cmd, args) - }, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - // daemon command is special, we redirect directly to another binary - if cmd.Name() == "daemon" { - return nil - } - // flags must be the top-level command flags, not cmd.Flags() - opts.Common.SetDefaultOptions(flags) - dockerPreRun(opts) - if err := dockerCli.Initialize(opts); err != nil { - return err - } - return isSupported(cmd, dockerCli.Client().ClientVersion(), dockerCli.HasExperimental()) - }, - } - cli.SetupRootCommand(cmd) - - cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) { - if dockerCli.Client() == nil { // when using --help, PersistenPreRun is not called, so initialization is needed. - // flags must be the top-level command flags, not cmd.Flags() - opts.Common.SetDefaultOptions(flags) - dockerPreRun(opts) - dockerCli.Initialize(opts) - } - - if err := isSupported(ccmd, dockerCli.Client().ClientVersion(), dockerCli.HasExperimental()); err != nil { - ccmd.Println(err) - return - } - - hideUnsupportedFeatures(ccmd, dockerCli.Client().ClientVersion(), dockerCli.HasExperimental()) - - if err := ccmd.Help(); err != nil { - ccmd.Println(err) - } - }) - - flags = cmd.Flags() - flags.BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit") - flags.StringVar(&opts.ConfigDir, "config", cliconfig.ConfigDir(), "Location of client config files") - opts.Common.InstallFlags(flags) - - cmd.SetOutput(dockerCli.Out()) - cmd.AddCommand(newDaemonCommand()) - commands.AddCommands(cmd, dockerCli) - - return cmd -} - -func noArgs(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return nil - } - return fmt.Errorf( - "docker: '%s' is not a docker command.\nSee 'docker --help'", args[0]) -} - -func main() { - // Set terminal emulation based on platform as required. - stdin, stdout, stderr := term.StdStreams() - logrus.SetOutput(stderr) - - dockerCli := command.NewDockerCli(stdin, stdout, stderr) - cmd := newDockerCommand(dockerCli) - - if err := cmd.Execute(); err != nil { - if sterr, ok := err.(cli.StatusError); ok { - if sterr.Status != "" { - fmt.Fprintln(stderr, sterr.Status) - } - // StatusError should only be used for errors, and all errors should - // have a non-zero exit status, so never exit with 0 - if sterr.StatusCode == 0 { - os.Exit(1) - } - os.Exit(sterr.StatusCode) - } - fmt.Fprintln(stderr, err) - os.Exit(1) - } -} - -func showVersion() { - fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit) -} - -func dockerPreRun(opts *cliflags.ClientOptions) { - cliflags.SetLogLevel(opts.Common.LogLevel) - - if opts.ConfigDir != "" { - cliconfig.SetConfigDir(opts.ConfigDir) - } - - if opts.Common.Debug { - utils.EnableDebug() - } -} - -func hideUnsupportedFeatures(cmd *cobra.Command, clientVersion string, hasExperimental bool) { - cmd.Flags().VisitAll(func(f *pflag.Flag) { - // hide experimental flags - if !hasExperimental { - if _, ok := f.Annotations["experimental"]; ok { - f.Hidden = true - } - } - - // hide flags not supported by the server - if flagVersion, ok := f.Annotations["version"]; ok && len(flagVersion) == 1 && versions.LessThan(clientVersion, flagVersion[0]) { - f.Hidden = true - } - - }) - - for _, subcmd := range cmd.Commands() { - // hide experimental subcommands - if !hasExperimental { - if _, ok := subcmd.Tags["experimental"]; ok { - subcmd.Hidden = true - } - } - - // hide subcommands not supported by the server - if subcmdVersion, ok := subcmd.Tags["version"]; ok && versions.LessThan(clientVersion, subcmdVersion) { - subcmd.Hidden = true - } - } -} - -func isSupported(cmd *cobra.Command, clientVersion string, hasExperimental bool) error { - if !hasExperimental { - if _, ok := cmd.Tags["experimental"]; ok { - return errors.New("only supported with experimental daemon") - } - } - - if cmdVersion, ok := cmd.Tags["version"]; ok && versions.LessThan(clientVersion, cmdVersion) { - return fmt.Errorf("only supported with daemon version >= %s", cmdVersion) - } - - return nil -} diff --git a/vendor/github.com/docker/docker/cmd/docker/docker_test.go b/vendor/github.com/docker/docker/cmd/docker/docker_test.go deleted file mode 100644 index 8738f60..0000000 --- a/vendor/github.com/docker/docker/cmd/docker/docker_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "io/ioutil" - "os" - "testing" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/cli/command" - "github.com/docker/docker/pkg/testutil/assert" - "github.com/docker/docker/utils" -) - -func TestClientDebugEnabled(t *testing.T) { - defer utils.DisableDebug() - - cmd := newDockerCommand(&command.DockerCli{}) - cmd.Flags().Set("debug", "true") - - err := cmd.PersistentPreRunE(cmd, []string{}) - assert.NilError(t, err) - assert.Equal(t, os.Getenv("DEBUG"), "1") - assert.Equal(t, logrus.GetLevel(), logrus.DebugLevel) -} - -func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) { - discard := ioutil.Discard - cmd := newDockerCommand(command.NewDockerCli(os.Stdin, discard, discard)) - cmd.SetArgs([]string{"help", "invalid"}) - err := cmd.Execute() - assert.Error(t, err, "unknown help topic: invalid") -} diff --git a/vendor/github.com/docker/docker/cmd/docker/docker_windows.go b/vendor/github.com/docker/docker/cmd/docker/docker_windows.go deleted file mode 100644 index 9bc507e..0000000 --- a/vendor/github.com/docker/docker/cmd/docker/docker_windows.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "sync/atomic" - - _ "github.com/docker/docker/autogen/winresources/docker" -) - -//go:cgo_import_dynamic main.dummy CommandLineToArgvW%2 "shell32.dll" - -var dummy uintptr - -func init() { - // Ensure that this import is not removed by the linker. This is used to - // ensure that shell32.dll is loaded by the system loader, preventing - // go#15286 from triggering on Nano Server TP5. - atomic.LoadUintptr(&dummy) -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/README.md b/vendor/github.com/docker/docker/cmd/dockerd/README.md deleted file mode 100644 index a8c20b3..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/README.md +++ /dev/null @@ -1,3 +0,0 @@ -docker.go contains Docker daemon's main function. - -This file provides first line CLI argument parsing and environment variable setting. diff --git a/vendor/github.com/docker/docker/cmd/dockerd/daemon.go b/vendor/github.com/docker/docker/cmd/dockerd/daemon.go deleted file mode 100644 index 2f099e0..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/daemon.go +++ /dev/null @@ -1,524 +0,0 @@ -package main - -import ( - "crypto/tls" - "fmt" - "io" - "os" - "path/filepath" - "runtime" - "strings" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/uuid" - "github.com/docker/docker/api" - apiserver "github.com/docker/docker/api/server" - "github.com/docker/docker/api/server/middleware" - "github.com/docker/docker/api/server/router" - "github.com/docker/docker/api/server/router/build" - checkpointrouter "github.com/docker/docker/api/server/router/checkpoint" - "github.com/docker/docker/api/server/router/container" - "github.com/docker/docker/api/server/router/image" - "github.com/docker/docker/api/server/router/network" - pluginrouter "github.com/docker/docker/api/server/router/plugin" - swarmrouter "github.com/docker/docker/api/server/router/swarm" - systemrouter "github.com/docker/docker/api/server/router/system" - "github.com/docker/docker/api/server/router/volume" - "github.com/docker/docker/builder/dockerfile" - cliflags "github.com/docker/docker/cli/flags" - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/daemon" - "github.com/docker/docker/daemon/cluster" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/libcontainerd" - dopts "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/authorization" - "github.com/docker/docker/pkg/jsonlog" - "github.com/docker/docker/pkg/listeners" - "github.com/docker/docker/pkg/pidfile" - "github.com/docker/docker/pkg/plugingetter" - "github.com/docker/docker/pkg/signal" - "github.com/docker/docker/pkg/system" - "github.com/docker/docker/registry" - "github.com/docker/docker/runconfig" - "github.com/docker/docker/utils" - "github.com/docker/go-connections/tlsconfig" - "github.com/spf13/pflag" -) - -const ( - flagDaemonConfigFile = "config-file" -) - -// DaemonCli represents the daemon CLI. -type DaemonCli struct { - *daemon.Config - configFile *string - flags *pflag.FlagSet - - api *apiserver.Server - d *daemon.Daemon - authzMiddleware *authorization.Middleware // authzMiddleware enables to dynamically reload the authorization plugins -} - -// NewDaemonCli returns a daemon CLI -func NewDaemonCli() *DaemonCli { - return &DaemonCli{} -} - -func migrateKey(config *daemon.Config) (err error) { - // No migration necessary on Windows - if runtime.GOOS == "windows" { - return nil - } - - // Migrate trust key if exists at ~/.docker/key.json and owned by current user - oldPath := filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile) - newPath := filepath.Join(getDaemonConfDir(config.Root), cliflags.DefaultTrustKeyFile) - if _, statErr := os.Stat(newPath); os.IsNotExist(statErr) && currentUserIsOwner(oldPath) { - defer func() { - // Ensure old path is removed if no error occurred - if err == nil { - err = os.Remove(oldPath) - } else { - logrus.Warnf("Key migration failed, key file not removed at %s", oldPath) - os.Remove(newPath) - } - }() - - if err := system.MkdirAll(getDaemonConfDir(config.Root), os.FileMode(0644)); err != nil { - return fmt.Errorf("Unable to create daemon configuration directory: %s", err) - } - - newFile, err := os.OpenFile(newPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - return fmt.Errorf("error creating key file %q: %s", newPath, err) - } - defer newFile.Close() - - oldFile, err := os.Open(oldPath) - if err != nil { - return fmt.Errorf("error opening key file %q: %s", oldPath, err) - } - defer oldFile.Close() - - if _, err := io.Copy(newFile, oldFile); err != nil { - return fmt.Errorf("error copying key: %s", err) - } - - logrus.Infof("Migrated key from %s to %s", oldPath, newPath) - } - - return nil -} - -func (cli *DaemonCli) start(opts daemonOptions) (err error) { - stopc := make(chan bool) - defer close(stopc) - - // warn from uuid package when running the daemon - uuid.Loggerf = logrus.Warnf - - opts.common.SetDefaultOptions(opts.flags) - - if cli.Config, err = loadDaemonCliConfig(opts); err != nil { - return err - } - cli.configFile = &opts.configFile - cli.flags = opts.flags - - if opts.common.TrustKey == "" { - opts.common.TrustKey = filepath.Join( - getDaemonConfDir(cli.Config.Root), - cliflags.DefaultTrustKeyFile) - } - - if cli.Config.Debug { - utils.EnableDebug() - } - - if cli.Config.Experimental { - logrus.Warn("Running experimental build") - } - - logrus.SetFormatter(&logrus.TextFormatter{ - TimestampFormat: jsonlog.RFC3339NanoFixed, - DisableColors: cli.Config.RawLogs, - }) - - if err := setDefaultUmask(); err != nil { - return fmt.Errorf("Failed to set umask: %v", err) - } - - if len(cli.LogConfig.Config) > 0 { - if err := logger.ValidateLogOpts(cli.LogConfig.Type, cli.LogConfig.Config); err != nil { - return fmt.Errorf("Failed to set log opts: %v", err) - } - } - - // Create the daemon root before we create ANY other files (PID, or migrate keys) - // to ensure the appropriate ACL is set (particularly relevant on Windows) - if err := daemon.CreateDaemonRoot(cli.Config); err != nil { - return err - } - - if cli.Pidfile != "" { - pf, err := pidfile.New(cli.Pidfile) - if err != nil { - return fmt.Errorf("Error starting daemon: %v", err) - } - defer func() { - if err := pf.Remove(); err != nil { - logrus.Error(err) - } - }() - } - - serverConfig := &apiserver.Config{ - Logging: true, - SocketGroup: cli.Config.SocketGroup, - Version: dockerversion.Version, - EnableCors: cli.Config.EnableCors, - CorsHeaders: cli.Config.CorsHeaders, - } - - if cli.Config.TLS { - tlsOptions := tlsconfig.Options{ - CAFile: cli.Config.CommonTLSOptions.CAFile, - CertFile: cli.Config.CommonTLSOptions.CertFile, - KeyFile: cli.Config.CommonTLSOptions.KeyFile, - } - - if cli.Config.TLSVerify { - // server requires and verifies client's certificate - tlsOptions.ClientAuth = tls.RequireAndVerifyClientCert - } - tlsConfig, err := tlsconfig.Server(tlsOptions) - if err != nil { - return err - } - serverConfig.TLSConfig = tlsConfig - } - - if len(cli.Config.Hosts) == 0 { - cli.Config.Hosts = make([]string, 1) - } - - api := apiserver.New(serverConfig) - cli.api = api - - for i := 0; i < len(cli.Config.Hosts); i++ { - var err error - if cli.Config.Hosts[i], err = dopts.ParseHost(cli.Config.TLS, cli.Config.Hosts[i]); err != nil { - return fmt.Errorf("error parsing -H %s : %v", cli.Config.Hosts[i], err) - } - - protoAddr := cli.Config.Hosts[i] - protoAddrParts := strings.SplitN(protoAddr, "://", 2) - if len(protoAddrParts) != 2 { - return fmt.Errorf("bad format %s, expected PROTO://ADDR", protoAddr) - } - - proto := protoAddrParts[0] - addr := protoAddrParts[1] - - // It's a bad idea to bind to TCP without tlsverify. - if proto == "tcp" && (serverConfig.TLSConfig == nil || serverConfig.TLSConfig.ClientAuth != tls.RequireAndVerifyClientCert) { - logrus.Warn("[!] DON'T BIND ON ANY IP ADDRESS WITHOUT setting -tlsverify IF YOU DON'T KNOW WHAT YOU'RE DOING [!]") - } - ls, err := listeners.Init(proto, addr, serverConfig.SocketGroup, serverConfig.TLSConfig) - if err != nil { - return err - } - ls = wrapListeners(proto, ls) - // If we're binding to a TCP port, make sure that a container doesn't try to use it. - if proto == "tcp" { - if err := allocateDaemonPort(addr); err != nil { - return err - } - } - logrus.Debugf("Listener created for HTTP on %s (%s)", proto, addr) - api.Accept(addr, ls...) - } - - if err := migrateKey(cli.Config); err != nil { - return err - } - - // FIXME: why is this down here instead of with the other TrustKey logic above? - cli.TrustKeyPath = opts.common.TrustKey - - registryService := registry.NewService(cli.Config.ServiceOptions) - containerdRemote, err := libcontainerd.New(cli.getLibcontainerdRoot(), cli.getPlatformRemoteOptions()...) - if err != nil { - return err - } - signal.Trap(func() { - cli.stop() - <-stopc // wait for daemonCli.start() to return - }) - - d, err := daemon.NewDaemon(cli.Config, registryService, containerdRemote) - if err != nil { - return fmt.Errorf("Error starting daemon: %v", err) - } - - if cli.Config.MetricsAddress != "" { - if !d.HasExperimental() { - return fmt.Errorf("metrics-addr is only supported when experimental is enabled") - } - if err := startMetricsServer(cli.Config.MetricsAddress); err != nil { - return err - } - } - - name, _ := os.Hostname() - - c, err := cluster.New(cluster.Config{ - Root: cli.Config.Root, - Name: name, - Backend: d, - NetworkSubnetsProvider: d, - DefaultAdvertiseAddr: cli.Config.SwarmDefaultAdvertiseAddr, - RuntimeRoot: cli.getSwarmRunRoot(), - }) - if err != nil { - logrus.Fatalf("Error creating cluster component: %v", err) - } - - // Restart all autostart containers which has a swarm endpoint - // and is not yet running now that we have successfully - // initialized the cluster. - d.RestartSwarmContainers() - - logrus.Info("Daemon has completed initialization") - - logrus.WithFields(logrus.Fields{ - "version": dockerversion.Version, - "commit": dockerversion.GitCommit, - "graphdriver": d.GraphDriverName(), - }).Info("Docker daemon") - - cli.d = d - - // initMiddlewares needs cli.d to be populated. Dont change this init order. - if err := cli.initMiddlewares(api, serverConfig); err != nil { - logrus.Fatalf("Error creating middlewares: %v", err) - } - d.SetCluster(c) - initRouter(api, d, c) - - cli.setupConfigReloadTrap() - - // The serve API routine never exits unless an error occurs - // We need to start it as a goroutine and wait on it so - // daemon doesn't exit - serveAPIWait := make(chan error) - go api.Wait(serveAPIWait) - - // after the daemon is done setting up we can notify systemd api - notifySystem() - - // Daemon is fully initialized and handling API traffic - // Wait for serve API to complete - errAPI := <-serveAPIWait - c.Cleanup() - shutdownDaemon(d) - containerdRemote.Cleanup() - if errAPI != nil { - return fmt.Errorf("Shutting down due to ServeAPI error: %v", errAPI) - } - - return nil -} - -func (cli *DaemonCli) reloadConfig() { - reload := func(config *daemon.Config) { - - // Revalidate and reload the authorization plugins - if err := validateAuthzPlugins(config.AuthorizationPlugins, cli.d.PluginStore); err != nil { - logrus.Fatalf("Error validating authorization plugin: %v", err) - return - } - cli.authzMiddleware.SetPlugins(config.AuthorizationPlugins) - - if err := cli.d.Reload(config); err != nil { - logrus.Errorf("Error reconfiguring the daemon: %v", err) - return - } - - if config.IsValueSet("debug") { - debugEnabled := utils.IsDebugEnabled() - switch { - case debugEnabled && !config.Debug: // disable debug - utils.DisableDebug() - cli.api.DisableProfiler() - case config.Debug && !debugEnabled: // enable debug - utils.EnableDebug() - cli.api.EnableProfiler() - } - - } - } - - if err := daemon.ReloadConfiguration(*cli.configFile, cli.flags, reload); err != nil { - logrus.Error(err) - } -} - -func (cli *DaemonCli) stop() { - cli.api.Close() -} - -// shutdownDaemon just wraps daemon.Shutdown() to handle a timeout in case -// d.Shutdown() is waiting too long to kill container or worst it's -// blocked there -func shutdownDaemon(d *daemon.Daemon) { - shutdownTimeout := d.ShutdownTimeout() - ch := make(chan struct{}) - go func() { - d.Shutdown() - close(ch) - }() - if shutdownTimeout < 0 { - <-ch - logrus.Debug("Clean shutdown succeeded") - return - } - select { - case <-ch: - logrus.Debug("Clean shutdown succeeded") - case <-time.After(time.Duration(shutdownTimeout) * time.Second): - logrus.Error("Force shutdown daemon") - } -} - -func loadDaemonCliConfig(opts daemonOptions) (*daemon.Config, error) { - config := opts.daemonConfig - flags := opts.flags - config.Debug = opts.common.Debug - config.Hosts = opts.common.Hosts - config.LogLevel = opts.common.LogLevel - config.TLS = opts.common.TLS - config.TLSVerify = opts.common.TLSVerify - config.CommonTLSOptions = daemon.CommonTLSOptions{} - - if opts.common.TLSOptions != nil { - config.CommonTLSOptions.CAFile = opts.common.TLSOptions.CAFile - config.CommonTLSOptions.CertFile = opts.common.TLSOptions.CertFile - config.CommonTLSOptions.KeyFile = opts.common.TLSOptions.KeyFile - } - - if opts.configFile != "" { - c, err := daemon.MergeDaemonConfigurations(config, flags, opts.configFile) - if err != nil { - if flags.Changed(flagDaemonConfigFile) || !os.IsNotExist(err) { - return nil, fmt.Errorf("unable to configure the Docker daemon with file %s: %v\n", opts.configFile, err) - } - } - // the merged configuration can be nil if the config file didn't exist. - // leave the current configuration as it is if when that happens. - if c != nil { - config = c - } - } - - if err := daemon.ValidateConfiguration(config); err != nil { - return nil, err - } - - // Labels of the docker engine used to allow multiple values associated with the same key. - // This is deprecated in 1.13, and, be removed after 3 release cycles. - // The following will check the conflict of labels, and report a warning for deprecation. - // - // TODO: After 3 release cycles (1.16) an error will be returned, and labels will be - // sanitized to consolidate duplicate key-value pairs (config.Labels = newLabels): - // - // newLabels, err := daemon.GetConflictFreeLabels(config.Labels) - // if err != nil { - // return nil, err - // } - // config.Labels = newLabels - // - if _, err := daemon.GetConflictFreeLabels(config.Labels); err != nil { - logrus.Warnf("Engine labels with duplicate keys and conflicting values have been deprecated: %s", err) - } - - // Regardless of whether the user sets it to true or false, if they - // specify TLSVerify at all then we need to turn on TLS - if config.IsValueSet(cliflags.FlagTLSVerify) { - config.TLS = true - } - - // ensure that the log level is the one set after merging configurations - cliflags.SetLogLevel(config.LogLevel) - - return config, nil -} - -func initRouter(s *apiserver.Server, d *daemon.Daemon, c *cluster.Cluster) { - decoder := runconfig.ContainerDecoder{} - - routers := []router.Router{ - // we need to add the checkpoint router before the container router or the DELETE gets masked - checkpointrouter.NewRouter(d, decoder), - container.NewRouter(d, decoder), - image.NewRouter(d, decoder), - systemrouter.NewRouter(d, c), - volume.NewRouter(d), - build.NewRouter(dockerfile.NewBuildManager(d)), - swarmrouter.NewRouter(c), - pluginrouter.NewRouter(d.PluginManager()), - } - - if d.NetworkControllerEnabled() { - routers = append(routers, network.NewRouter(d, c)) - } - - if d.HasExperimental() { - for _, r := range routers { - for _, route := range r.Routes() { - if experimental, ok := route.(router.ExperimentalRoute); ok { - experimental.Enable() - } - } - } - } - - s.InitRouter(utils.IsDebugEnabled(), routers...) -} - -func (cli *DaemonCli) initMiddlewares(s *apiserver.Server, cfg *apiserver.Config) error { - v := cfg.Version - - exp := middleware.NewExperimentalMiddleware(cli.d.HasExperimental()) - s.UseMiddleware(exp) - - vm := middleware.NewVersionMiddleware(v, api.DefaultVersion, api.MinVersion) - s.UseMiddleware(vm) - - if cfg.EnableCors { - c := middleware.NewCORSMiddleware(cfg.CorsHeaders) - s.UseMiddleware(c) - } - - if err := validateAuthzPlugins(cli.Config.AuthorizationPlugins, cli.d.PluginStore); err != nil { - return fmt.Errorf("Error validating authorization plugin: %v", err) - } - cli.authzMiddleware = authorization.NewMiddleware(cli.Config.AuthorizationPlugins, cli.d.PluginStore) - s.UseMiddleware(cli.authzMiddleware) - return nil -} - -// validates that the plugins requested with the --authorization-plugin flag are valid AuthzDriver -// plugins present on the host and available to the daemon -func validateAuthzPlugins(requestedPlugins []string, pg plugingetter.PluginGetter) error { - for _, reqPlugin := range requestedPlugins { - if _, err := pg.Get(reqPlugin, authorization.AuthZApiImplements, plugingetter.LOOKUP); err != nil { - return err - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/daemon_freebsd.go b/vendor/github.com/docker/docker/cmd/dockerd/daemon_freebsd.go deleted file mode 100644 index 623aaf4..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/daemon_freebsd.go +++ /dev/null @@ -1,5 +0,0 @@ -package main - -// notifySystem sends a message to the host when the server is ready to be used -func notifySystem() { -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/daemon_linux.go b/vendor/github.com/docker/docker/cmd/dockerd/daemon_linux.go deleted file mode 100644 index a556daa..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/daemon_linux.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build linux - -package main - -import systemdDaemon "github.com/coreos/go-systemd/daemon" - -// notifySystem sends a message to the host when the server is ready to be used -func notifySystem() { - // Tell the init daemon we are accepting requests - go systemdDaemon.SdNotify("READY=1") -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/daemon_solaris.go b/vendor/github.com/docker/docker/cmd/dockerd/daemon_solaris.go deleted file mode 100644 index 974ba16..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/daemon_solaris.go +++ /dev/null @@ -1,85 +0,0 @@ -// +build solaris - -package main - -import ( - "fmt" - "net" - "os" - "path/filepath" - "syscall" - - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/pkg/system" -) - -const defaultDaemonConfigFile = "" - -// currentUserIsOwner checks whether the current user is the owner of the given -// file. -func currentUserIsOwner(f string) bool { - if fileInfo, err := system.Stat(f); err == nil && fileInfo != nil { - if int(fileInfo.UID()) == os.Getuid() { - return true - } - } - return false -} - -// setDefaultUmask sets the umask to 0022 to avoid problems -// caused by custom umask -func setDefaultUmask() error { - desiredUmask := 0022 - syscall.Umask(desiredUmask) - if umask := syscall.Umask(desiredUmask); umask != desiredUmask { - return fmt.Errorf("failed to set umask: expected %#o, got %#o", desiredUmask, umask) - } - - return nil -} - -func getDaemonConfDir(_ string) string { - return "/etc/docker" -} - -// setupConfigReloadTrap configures the USR2 signal to reload the configuration. -func (cli *DaemonCli) setupConfigReloadTrap() { -} - -// notifySystem sends a message to the host when the server is ready to be used -func notifySystem() { -} - -func (cli *DaemonCli) getPlatformRemoteOptions() []libcontainerd.RemoteOption { - opts := []libcontainerd.RemoteOption{} - if cli.Config.ContainerdAddr != "" { - opts = append(opts, libcontainerd.WithRemoteAddr(cli.Config.ContainerdAddr)) - } else { - opts = append(opts, libcontainerd.WithStartDaemon(true)) - } - return opts -} - -// getLibcontainerdRoot gets the root directory for libcontainerd/containerd to -// store their state. -func (cli *DaemonCli) getLibcontainerdRoot() string { - return filepath.Join(cli.Config.ExecRoot, "libcontainerd") -} - -// getSwarmRunRoot gets the root directory for swarm to store runtime state -// For example, the control socket -func (cli *DaemonCli) getSwarmRunRoot() string { - return filepath.Join(cli.Config.ExecRoot, "swarm") -} - -func allocateDaemonPort(addr string) error { - return nil -} - -// notifyShutdown is called after the daemon shuts down but before the process exits. -func notifyShutdown(err error) { -} - -func wrapListeners(proto string, ls []net.Listener) []net.Listener { - return ls -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/daemon_test.go b/vendor/github.com/docker/docker/cmd/dockerd/daemon_test.go deleted file mode 100644 index b364f87..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/daemon_test.go +++ /dev/null @@ -1,145 +0,0 @@ -package main - -import ( - "testing" - - "github.com/Sirupsen/logrus" - cliflags "github.com/docker/docker/cli/flags" - "github.com/docker/docker/daemon" - "github.com/docker/docker/pkg/testutil/assert" - "github.com/docker/docker/pkg/testutil/tempfile" - "github.com/spf13/pflag" -) - -func defaultOptions(configFile string) daemonOptions { - opts := daemonOptions{ - daemonConfig: &daemon.Config{}, - flags: &pflag.FlagSet{}, - common: cliflags.NewCommonOptions(), - } - opts.common.InstallFlags(opts.flags) - opts.daemonConfig.InstallFlags(opts.flags) - opts.flags.StringVar(&opts.configFile, flagDaemonConfigFile, defaultDaemonConfigFile, "") - opts.configFile = configFile - return opts -} - -func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) { - opts := defaultOptions("") - opts.common.Debug = true - - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - if !loadedConfig.Debug { - t.Fatalf("expected debug to be copied from the common flags, got false") - } -} - -func TestLoadDaemonCliConfigWithTLS(t *testing.T) { - opts := defaultOptions("") - opts.common.TLSOptions.CAFile = "/tmp/ca.pem" - opts.common.TLS = true - - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - assert.Equal(t, loadedConfig.CommonTLSOptions.CAFile, "/tmp/ca.pem") -} - -func TestLoadDaemonCliConfigWithConflicts(t *testing.T) { - tempFile := tempfile.NewTempFile(t, "config", `{"labels": ["l3=foo"]}`) - defer tempFile.Remove() - configFile := tempFile.Name() - - opts := defaultOptions(configFile) - flags := opts.flags - - assert.NilError(t, flags.Set(flagDaemonConfigFile, configFile)) - assert.NilError(t, flags.Set("label", "l1=bar")) - assert.NilError(t, flags.Set("label", "l2=baz")) - - _, err := loadDaemonCliConfig(opts) - assert.Error(t, err, "as a flag and in the configuration file: labels") -} - -func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) { - tempFile := tempfile.NewTempFile(t, "config", `{"tlsverify": true}`) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - opts.common.TLSOptions.CAFile = "/tmp/ca.pem" - - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - assert.Equal(t, loadedConfig.TLS, true) -} - -func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) { - tempFile := tempfile.NewTempFile(t, "config", `{"tlsverify": false}`) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - opts.common.TLSOptions.CAFile = "/tmp/ca.pem" - - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - assert.Equal(t, loadedConfig.TLS, true) -} - -func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) { - tempFile := tempfile.NewTempFile(t, "config", `{}`) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - opts.common.TLSOptions.CAFile = "/tmp/ca.pem" - - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - assert.Equal(t, loadedConfig.TLS, false) -} - -func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) { - tempFile := tempfile.NewTempFile(t, "config", `{"log-level": "warn"}`) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - assert.Equal(t, loadedConfig.LogLevel, "warn") - assert.Equal(t, logrus.GetLevel(), logrus.WarnLevel) -} - -func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) { - content := `{"tlscacert": "/etc/certs/ca.pem", "log-driver": "syslog"}` - tempFile := tempfile.NewTempFile(t, "config", content) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - assert.Equal(t, loadedConfig.CommonTLSOptions.CAFile, "/etc/certs/ca.pem") - assert.Equal(t, loadedConfig.LogConfig.Type, "syslog") -} - -func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) { - content := `{ - "registry-mirrors": ["https://mirrors.docker.com"], - "insecure-registries": ["https://insecure.docker.com"] - }` - tempFile := tempfile.NewTempFile(t, "config", content) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - - assert.Equal(t, len(loadedConfig.Mirrors), 1) - assert.Equal(t, len(loadedConfig.InsecureRegistries), 1) -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/daemon_unix.go b/vendor/github.com/docker/docker/cmd/dockerd/daemon_unix.go deleted file mode 100644 index bdce98b..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/daemon_unix.go +++ /dev/null @@ -1,137 +0,0 @@ -// +build !windows,!solaris - -package main - -import ( - "fmt" - "net" - "os" - "os/signal" - "path/filepath" - "strconv" - "syscall" - - "github.com/docker/docker/cmd/dockerd/hack" - "github.com/docker/docker/daemon" - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/pkg/system" - "github.com/docker/libnetwork/portallocator" -) - -const defaultDaemonConfigFile = "/etc/docker/daemon.json" - -// currentUserIsOwner checks whether the current user is the owner of the given -// file. -func currentUserIsOwner(f string) bool { - if fileInfo, err := system.Stat(f); err == nil && fileInfo != nil { - if int(fileInfo.UID()) == os.Getuid() { - return true - } - } - return false -} - -// setDefaultUmask sets the umask to 0022 to avoid problems -// caused by custom umask -func setDefaultUmask() error { - desiredUmask := 0022 - syscall.Umask(desiredUmask) - if umask := syscall.Umask(desiredUmask); umask != desiredUmask { - return fmt.Errorf("failed to set umask: expected %#o, got %#o", desiredUmask, umask) - } - - return nil -} - -func getDaemonConfDir(_ string) string { - return "/etc/docker" -} - -// setupConfigReloadTrap configures the USR2 signal to reload the configuration. -func (cli *DaemonCli) setupConfigReloadTrap() { - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGHUP) - go func() { - for range c { - cli.reloadConfig() - } - }() -} - -func (cli *DaemonCli) getPlatformRemoteOptions() []libcontainerd.RemoteOption { - opts := []libcontainerd.RemoteOption{ - libcontainerd.WithDebugLog(cli.Config.Debug), - libcontainerd.WithOOMScore(cli.Config.OOMScoreAdjust), - } - if cli.Config.ContainerdAddr != "" { - opts = append(opts, libcontainerd.WithRemoteAddr(cli.Config.ContainerdAddr)) - } else { - opts = append(opts, libcontainerd.WithStartDaemon(true)) - } - if daemon.UsingSystemd(cli.Config) { - args := []string{"--systemd-cgroup=true"} - opts = append(opts, libcontainerd.WithRuntimeArgs(args)) - } - if cli.Config.LiveRestoreEnabled { - opts = append(opts, libcontainerd.WithLiveRestore(true)) - } - opts = append(opts, libcontainerd.WithRuntimePath(daemon.DefaultRuntimeBinary)) - return opts -} - -// getLibcontainerdRoot gets the root directory for libcontainerd/containerd to -// store their state. -func (cli *DaemonCli) getLibcontainerdRoot() string { - return filepath.Join(cli.Config.ExecRoot, "libcontainerd") -} - -// getSwarmRunRoot gets the root directory for swarm to store runtime state -// For example, the control socket -func (cli *DaemonCli) getSwarmRunRoot() string { - return filepath.Join(cli.Config.ExecRoot, "swarm") -} - -// allocateDaemonPort ensures that there are no containers -// that try to use any port allocated for the docker server. -func allocateDaemonPort(addr string) error { - host, port, err := net.SplitHostPort(addr) - if err != nil { - return err - } - - intPort, err := strconv.Atoi(port) - if err != nil { - return err - } - - var hostIPs []net.IP - if parsedIP := net.ParseIP(host); parsedIP != nil { - hostIPs = append(hostIPs, parsedIP) - } else if hostIPs, err = net.LookupIP(host); err != nil { - return fmt.Errorf("failed to lookup %s address in host specification", host) - } - - pa := portallocator.Get() - for _, hostIP := range hostIPs { - if _, err := pa.RequestPort(hostIP, "tcp", intPort); err != nil { - return fmt.Errorf("failed to allocate daemon listening port %d (err: %v)", intPort, err) - } - } - return nil -} - -// notifyShutdown is called after the daemon shuts down but before the process exits. -func notifyShutdown(err error) { -} - -func wrapListeners(proto string, ls []net.Listener) []net.Listener { - switch proto { - case "unix": - ls[0] = &hack.MalformedHostHeaderOverride{ls[0]} - case "fd": - for i := range ls { - ls[i] = &hack.MalformedHostHeaderOverride{ls[i]} - } - } - return ls -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/daemon_unix_test.go b/vendor/github.com/docker/docker/cmd/dockerd/daemon_unix_test.go deleted file mode 100644 index d66dba7..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/daemon_unix_test.go +++ /dev/null @@ -1,114 +0,0 @@ -// +build !windows,!solaris - -// TODO: Create new file for Solaris which tests config parameters -// as described in daemon/config_solaris.go - -package main - -import ( - "github.com/docker/docker/daemon" - "github.com/docker/docker/pkg/testutil/assert" - "github.com/docker/docker/pkg/testutil/tempfile" - "testing" -) - -func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) { - content := `{"log-opts": {"max-size": "1k"}}` - tempFile := tempfile.NewTempFile(t, "config", content) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - opts.common.Debug = true - opts.common.LogLevel = "info" - assert.NilError(t, opts.flags.Set("selinux-enabled", "true")) - - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - - assert.Equal(t, loadedConfig.Debug, true) - assert.Equal(t, loadedConfig.LogLevel, "info") - assert.Equal(t, loadedConfig.EnableSelinuxSupport, true) - assert.Equal(t, loadedConfig.LogConfig.Type, "json-file") - assert.Equal(t, loadedConfig.LogConfig.Config["max-size"], "1k") -} - -func TestLoadDaemonConfigWithNetwork(t *testing.T) { - content := `{"bip": "127.0.0.2", "ip": "127.0.0.1"}` - tempFile := tempfile.NewTempFile(t, "config", content) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - - assert.Equal(t, loadedConfig.IP, "127.0.0.2") - assert.Equal(t, loadedConfig.DefaultIP.String(), "127.0.0.1") -} - -func TestLoadDaemonConfigWithMapOptions(t *testing.T) { - content := `{ - "cluster-store-opts": {"kv.cacertfile": "/var/lib/docker/discovery_certs/ca.pem"}, - "log-opts": {"tag": "test"} -}` - tempFile := tempfile.NewTempFile(t, "config", content) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - assert.NotNil(t, loadedConfig.ClusterOpts) - - expectedPath := "/var/lib/docker/discovery_certs/ca.pem" - assert.Equal(t, loadedConfig.ClusterOpts["kv.cacertfile"], expectedPath) - assert.NotNil(t, loadedConfig.LogConfig.Config) - assert.Equal(t, loadedConfig.LogConfig.Config["tag"], "test") -} - -func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) { - content := `{ "userland-proxy": false }` - tempFile := tempfile.NewTempFile(t, "config", content) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - assert.NotNil(t, loadedConfig.ClusterOpts) - - assert.Equal(t, loadedConfig.EnableUserlandProxy, false) - - // make sure reloading doesn't generate configuration - // conflicts after normalizing boolean values. - reload := func(reloadedConfig *daemon.Config) { - assert.Equal(t, reloadedConfig.EnableUserlandProxy, false) - } - assert.NilError(t, daemon.ReloadConfiguration(opts.configFile, opts.flags, reload)) -} - -func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) { - tempFile := tempfile.NewTempFile(t, "config", `{}`) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - assert.NotNil(t, loadedConfig.ClusterOpts) - - assert.Equal(t, loadedConfig.EnableUserlandProxy, true) -} - -func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) { - content := `{"disable-legacy-registry": true}` - tempFile := tempfile.NewTempFile(t, "config", content) - defer tempFile.Remove() - - opts := defaultOptions(tempFile.Name()) - loadedConfig, err := loadDaemonCliConfig(opts) - assert.NilError(t, err) - assert.NotNil(t, loadedConfig) - assert.Equal(t, loadedConfig.V2Only, true) -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/daemon_windows.go b/vendor/github.com/docker/docker/cmd/dockerd/daemon_windows.go deleted file mode 100644 index 4cccd32..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/daemon_windows.go +++ /dev/null @@ -1,92 +0,0 @@ -package main - -import ( - "fmt" - "net" - "os" - "path/filepath" - "syscall" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/pkg/system" -) - -var defaultDaemonConfigFile = "" - -// currentUserIsOwner checks whether the current user is the owner of the given -// file. -func currentUserIsOwner(f string) bool { - return false -} - -// setDefaultUmask doesn't do anything on windows -func setDefaultUmask() error { - return nil -} - -func getDaemonConfDir(root string) string { - return filepath.Join(root, `\config`) -} - -// notifySystem sends a message to the host when the server is ready to be used -func notifySystem() { - if service != nil { - err := service.started() - if err != nil { - logrus.Fatal(err) - } - } -} - -// notifyShutdown is called after the daemon shuts down but before the process exits. -func notifyShutdown(err error) { - if service != nil { - if err != nil { - logrus.Fatal(err) - } - service.stopped(err) - } -} - -// setupConfigReloadTrap configures a Win32 event to reload the configuration. -func (cli *DaemonCli) setupConfigReloadTrap() { - go func() { - sa := syscall.SecurityAttributes{ - Length: 0, - } - ev := "Global\\docker-daemon-config-" + fmt.Sprint(os.Getpid()) - if h, _ := system.CreateEvent(&sa, false, false, ev); h != 0 { - logrus.Debugf("Config reload - waiting signal at %s", ev) - for { - syscall.WaitForSingleObject(h, syscall.INFINITE) - cli.reloadConfig() - } - } - }() -} - -func (cli *DaemonCli) getPlatformRemoteOptions() []libcontainerd.RemoteOption { - return nil -} - -// getLibcontainerdRoot gets the root directory for libcontainerd to store its -// state. The Windows libcontainerd implementation does not need to write a spec -// or state to disk, so this is a no-op. -func (cli *DaemonCli) getLibcontainerdRoot() string { - return "" -} - -// getSwarmRunRoot gets the root directory for swarm to store runtime state -// For example, the control socket -func (cli *DaemonCli) getSwarmRunRoot() string { - return "" -} - -func allocateDaemonPort(addr string) error { - return nil -} - -func wrapListeners(proto string, ls []net.Listener) []net.Listener { - return ls -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/docker.go b/vendor/github.com/docker/docker/cmd/dockerd/docker.go deleted file mode 100644 index 60742ae..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/docker.go +++ /dev/null @@ -1,110 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" - "runtime" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/cli" - cliflags "github.com/docker/docker/cli/flags" - "github.com/docker/docker/daemon" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/pkg/reexec" - "github.com/docker/docker/pkg/term" - "github.com/spf13/cobra" - "github.com/spf13/pflag" -) - -type daemonOptions struct { - version bool - configFile string - daemonConfig *daemon.Config - common *cliflags.CommonOptions - flags *pflag.FlagSet -} - -func newDaemonCommand() *cobra.Command { - opts := daemonOptions{ - daemonConfig: daemon.NewConfig(), - common: cliflags.NewCommonOptions(), - } - - cmd := &cobra.Command{ - Use: "dockerd [OPTIONS]", - Short: "A self-sufficient runtime for containers.", - SilenceUsage: true, - SilenceErrors: true, - Args: cli.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - opts.flags = cmd.Flags() - return runDaemon(opts) - }, - } - cli.SetupRootCommand(cmd) - - flags := cmd.Flags() - flags.BoolVarP(&opts.version, "version", "v", false, "Print version information and quit") - flags.StringVar(&opts.configFile, flagDaemonConfigFile, defaultDaemonConfigFile, "Daemon configuration file") - opts.common.InstallFlags(flags) - opts.daemonConfig.InstallFlags(flags) - installServiceFlags(flags) - - return cmd -} - -func runDaemon(opts daemonOptions) error { - if opts.version { - showVersion() - return nil - } - - daemonCli := NewDaemonCli() - - // Windows specific settings as these are not defaulted. - if runtime.GOOS == "windows" { - if opts.daemonConfig.Pidfile == "" { - opts.daemonConfig.Pidfile = filepath.Join(opts.daemonConfig.Root, "docker.pid") - } - if opts.configFile == "" { - opts.configFile = filepath.Join(opts.daemonConfig.Root, `config\daemon.json`) - } - } - - // On Windows, this may be launching as a service or with an option to - // register the service. - stop, err := initService(daemonCli) - if err != nil { - logrus.Fatal(err) - } - - if stop { - return nil - } - - err = daemonCli.start(opts) - notifyShutdown(err) - return err -} - -func showVersion() { - fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit) -} - -func main() { - if reexec.Init() { - return - } - - // Set terminal emulation based on platform as required. - _, stdout, stderr := term.StdStreams() - logrus.SetOutput(stderr) - - cmd := newDaemonCommand() - cmd.SetOutput(stdout) - if err := cmd.Execute(); err != nil { - fmt.Fprintf(stderr, "%s\n", err) - os.Exit(1) - } -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/docker_windows.go b/vendor/github.com/docker/docker/cmd/dockerd/docker_windows.go deleted file mode 100644 index 19c5587..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/docker_windows.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "sync/atomic" - - _ "github.com/docker/docker/autogen/winresources/dockerd" -) - -//go:cgo_import_dynamic main.dummy CommandLineToArgvW%2 "shell32.dll" - -var dummy uintptr - -func init() { - // Ensure that this import is not removed by the linker. This is used to - // ensure that shell32.dll is loaded by the system loader, preventing - // go#15286 from triggering on Nano Server TP5. - atomic.LoadUintptr(&dummy) -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/hack/malformed_host_override.go b/vendor/github.com/docker/docker/cmd/dockerd/hack/malformed_host_override.go deleted file mode 100644 index d4aa3dd..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/hack/malformed_host_override.go +++ /dev/null @@ -1,121 +0,0 @@ -// +build !windows - -package hack - -import "net" - -// MalformedHostHeaderOverride is a wrapper to be able -// to overcome the 400 Bad request coming from old docker -// clients that send an invalid Host header. -type MalformedHostHeaderOverride struct { - net.Listener -} - -// MalformedHostHeaderOverrideConn wraps the underlying unix -// connection and keeps track of the first read from http.Server -// which just reads the headers. -type MalformedHostHeaderOverrideConn struct { - net.Conn - first bool -} - -var closeConnHeader = []byte("\r\nConnection: close\r") - -// Read reads the first *read* request from http.Server to inspect -// the Host header. If the Host starts with / then we're talking to -// an old docker client which send an invalid Host header. To not -// error out in http.Server we rewrite the first bytes of the request -// to sanitize the Host header itself. -// In case we're not dealing with old docker clients the data is just passed -// to the server w/o modification. -func (l *MalformedHostHeaderOverrideConn) Read(b []byte) (n int, err error) { - // http.Server uses a 4k buffer - if l.first && len(b) == 4096 { - // This keeps track of the first read from http.Server which just reads - // the headers - l.first = false - // The first read of the connection by http.Server is done limited to - // DefaultMaxHeaderBytes (usually 1 << 20) + 4096. - // Here we do the first read which gets us all the http headers to - // be inspected and modified below. - c, err := l.Conn.Read(b) - if err != nil { - return c, err - } - - var ( - start, end int - firstLineFeed = -1 - buf []byte - ) - for i := 0; i <= c-1-7; i++ { - if b[i] == '\n' && firstLineFeed == -1 { - firstLineFeed = i - } - if b[i] != '\n' { - continue - } - - if b[i+1] == '\r' && b[i+2] == '\n' { - return c, nil - } - - if b[i+1] != 'H' { - continue - } - if b[i+2] != 'o' { - continue - } - if b[i+3] != 's' { - continue - } - if b[i+4] != 't' { - continue - } - if b[i+5] != ':' { - continue - } - if b[i+6] != ' ' { - continue - } - if b[i+7] != '/' { - continue - } - // ensure clients other than the docker clients do not get this hack - if i != firstLineFeed { - return c, nil - } - start = i + 7 - // now find where the value ends - for ii, bbb := range b[start:c] { - if bbb == '\n' { - end = start + ii - break - } - } - buf = make([]byte, 0, c+len(closeConnHeader)-(end-start)) - // strip the value of the host header and - // inject `Connection: close` to ensure we don't reuse this connection - buf = append(buf, b[:start]...) - buf = append(buf, closeConnHeader...) - buf = append(buf, b[end:c]...) - copy(b, buf) - break - } - if len(buf) == 0 { - return c, nil - } - return len(buf), nil - } - return l.Conn.Read(b) -} - -// Accept makes the listener accepts connections and wraps the connection -// in a MalformedHostHeaderOverrideConn initilizing first to true. -func (l *MalformedHostHeaderOverride) Accept() (net.Conn, error) { - c, err := l.Listener.Accept() - if err != nil { - return c, err - } - return &MalformedHostHeaderOverrideConn{c, true}, nil -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/hack/malformed_host_override_test.go b/vendor/github.com/docker/docker/cmd/dockerd/hack/malformed_host_override_test.go deleted file mode 100644 index 1a0a60b..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/hack/malformed_host_override_test.go +++ /dev/null @@ -1,124 +0,0 @@ -// +build !windows - -package hack - -import ( - "bytes" - "io" - "net" - "strings" - "testing" -) - -type bufConn struct { - net.Conn - buf *bytes.Buffer -} - -func (bc *bufConn) Read(b []byte) (int, error) { - return bc.buf.Read(b) -} - -func TestHeaderOverrideHack(t *testing.T) { - tests := [][2][]byte{ - { - []byte("GET /foo\nHost: /var/run/docker.sock\nUser-Agent: Docker\r\n\r\n"), - []byte("GET /foo\nHost: \r\nConnection: close\r\nUser-Agent: Docker\r\n\r\n"), - }, - { - []byte("GET /foo\nHost: /var/run/docker.sock\nUser-Agent: Docker\nFoo: Bar\r\n"), - []byte("GET /foo\nHost: \r\nConnection: close\r\nUser-Agent: Docker\nFoo: Bar\r\n"), - }, - { - []byte("GET /foo\nHost: /var/run/docker.sock\nUser-Agent: Docker\r\n\r\ntest something!"), - []byte("GET /foo\nHost: \r\nConnection: close\r\nUser-Agent: Docker\r\n\r\ntest something!"), - }, - { - []byte("GET /foo\nHost: /var/run/docker.sock\nUser-Agent: Docker\r\n\r\ntest something! " + strings.Repeat("test", 15000)), - []byte("GET /foo\nHost: \r\nConnection: close\r\nUser-Agent: Docker\r\n\r\ntest something! " + strings.Repeat("test", 15000)), - }, - { - []byte("GET /foo\nFoo: Bar\nHost: /var/run/docker.sock\nUser-Agent: Docker\r\n\r\n"), - []byte("GET /foo\nFoo: Bar\nHost: /var/run/docker.sock\nUser-Agent: Docker\r\n\r\n"), - }, - } - - // Test for https://github.com/docker/docker/issues/23045 - h0 := "GET /foo\nUser-Agent: Docker\r\n\r\n" - h0 = h0 + strings.Repeat("a", 4096-len(h0)-1) + "\n" - tests = append(tests, [2][]byte{[]byte(h0), []byte(h0)}) - - for _, pair := range tests { - read := make([]byte, 4096) - client := &bufConn{ - buf: bytes.NewBuffer(pair[0]), - } - l := MalformedHostHeaderOverrideConn{client, true} - - n, err := l.Read(read) - if err != nil && err != io.EOF { - t.Fatalf("read: %d - %d, err: %v\n%s", n, len(pair[0]), err, string(read[:n])) - } - if !bytes.Equal(read[:n], pair[1][:n]) { - t.Fatalf("\n%s\n%s\n", read[:n], pair[1][:n]) - } - } -} - -func BenchmarkWithHack(b *testing.B) { - client, srv := net.Pipe() - done := make(chan struct{}) - req := []byte("GET /foo\nHost: /var/run/docker.sock\nUser-Agent: Docker\n") - read := make([]byte, 4096) - b.SetBytes(int64(len(req) * 30)) - - l := MalformedHostHeaderOverrideConn{client, true} - go func() { - for { - if _, err := srv.Write(req); err != nil { - srv.Close() - break - } - l.first = true // make sure each subsequent run uses the hack parsing - } - close(done) - }() - - for i := 0; i < b.N; i++ { - for i := 0; i < 30; i++ { - if n, err := l.Read(read); err != nil && err != io.EOF { - b.Fatalf("read: %d - %d, err: %v\n%s", n, len(req), err, string(read[:n])) - } - } - } - l.Close() - <-done -} - -func BenchmarkNoHack(b *testing.B) { - client, srv := net.Pipe() - done := make(chan struct{}) - req := []byte("GET /foo\nHost: /var/run/docker.sock\nUser-Agent: Docker\n") - read := make([]byte, 4096) - b.SetBytes(int64(len(req) * 30)) - - go func() { - for { - if _, err := srv.Write(req); err != nil { - srv.Close() - break - } - } - close(done) - }() - - for i := 0; i < b.N; i++ { - for i := 0; i < 30; i++ { - if _, err := client.Read(read); err != nil && err != io.EOF { - b.Fatal(err) - } - } - } - client.Close() - <-done -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/metrics.go b/vendor/github.com/docker/docker/cmd/dockerd/metrics.go deleted file mode 100644 index 0c88604..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/metrics.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "net" - "net/http" - - "github.com/Sirupsen/logrus" - metrics "github.com/docker/go-metrics" -) - -func startMetricsServer(addr string) error { - if err := allocateDaemonPort(addr); err != nil { - return err - } - l, err := net.Listen("tcp", addr) - if err != nil { - return err - } - mux := http.NewServeMux() - mux.Handle("/metrics", metrics.Handler()) - go func() { - if err := http.Serve(l, mux); err != nil { - logrus.Errorf("serve metrics api: %s", err) - } - }() - return nil -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/service_unsupported.go b/vendor/github.com/docker/docker/cmd/dockerd/service_unsupported.go deleted file mode 100644 index 64ad7fc..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/service_unsupported.go +++ /dev/null @@ -1,14 +0,0 @@ -// +build !windows - -package main - -import ( - "github.com/spf13/pflag" -) - -func initService(daemonCli *DaemonCli) (bool, error) { - return false, nil -} - -func installServiceFlags(flags *pflag.FlagSet) { -} diff --git a/vendor/github.com/docker/docker/cmd/dockerd/service_windows.go b/vendor/github.com/docker/docker/cmd/dockerd/service_windows.go deleted file mode 100644 index dd37abc..0000000 --- a/vendor/github.com/docker/docker/cmd/dockerd/service_windows.go +++ /dev/null @@ -1,426 +0,0 @@ -package main - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "syscall" - "time" - "unsafe" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/system" - "github.com/spf13/pflag" - "golang.org/x/sys/windows" - "golang.org/x/sys/windows/svc" - "golang.org/x/sys/windows/svc/debug" - "golang.org/x/sys/windows/svc/eventlog" - "golang.org/x/sys/windows/svc/mgr" -) - -var ( - flServiceName *string - flRegisterService *bool - flUnregisterService *bool - flRunService *bool - - setStdHandle = windows.NewLazySystemDLL("kernel32.dll").NewProc("SetStdHandle") - oldStderr syscall.Handle - panicFile *os.File - - service *handler -) - -const ( - // These should match the values in event_messages.mc. - eventInfo = 1 - eventWarn = 1 - eventError = 1 - eventDebug = 2 - eventPanic = 3 - eventFatal = 4 - - eventExtraOffset = 10 // Add this to any event to get a string that supports extended data -) - -func installServiceFlags(flags *pflag.FlagSet) { - flServiceName = flags.String("service-name", "docker", "Set the Windows service name") - flRegisterService = flags.Bool("register-service", false, "Register the service and exit") - flUnregisterService = flags.Bool("unregister-service", false, "Unregister the service and exit") - flRunService = flags.Bool("run-service", false, "") - flags.MarkHidden("run-service") -} - -type handler struct { - tosvc chan bool - fromsvc chan error - daemonCli *DaemonCli -} - -type etwHook struct { - log *eventlog.Log -} - -func (h *etwHook) Levels() []logrus.Level { - return []logrus.Level{ - logrus.PanicLevel, - logrus.FatalLevel, - logrus.ErrorLevel, - logrus.WarnLevel, - logrus.InfoLevel, - logrus.DebugLevel, - } -} - -func (h *etwHook) Fire(e *logrus.Entry) error { - var ( - etype uint16 - eid uint32 - ) - - switch e.Level { - case logrus.PanicLevel: - etype = windows.EVENTLOG_ERROR_TYPE - eid = eventPanic - case logrus.FatalLevel: - etype = windows.EVENTLOG_ERROR_TYPE - eid = eventFatal - case logrus.ErrorLevel: - etype = windows.EVENTLOG_ERROR_TYPE - eid = eventError - case logrus.WarnLevel: - etype = windows.EVENTLOG_WARNING_TYPE - eid = eventWarn - case logrus.InfoLevel: - etype = windows.EVENTLOG_INFORMATION_TYPE - eid = eventInfo - case logrus.DebugLevel: - etype = windows.EVENTLOG_INFORMATION_TYPE - eid = eventDebug - default: - return errors.New("unknown level") - } - - // If there is additional data, include it as a second string. - exts := "" - if len(e.Data) > 0 { - fs := bytes.Buffer{} - for k, v := range e.Data { - fs.WriteString(k) - fs.WriteByte('=') - fmt.Fprint(&fs, v) - fs.WriteByte(' ') - } - - exts = fs.String()[:fs.Len()-1] - eid += eventExtraOffset - } - - if h.log == nil { - fmt.Fprintf(os.Stderr, "%s [%s]\n", e.Message, exts) - return nil - } - - var ( - ss [2]*uint16 - err error - ) - - ss[0], err = syscall.UTF16PtrFromString(e.Message) - if err != nil { - return err - } - - count := uint16(1) - if exts != "" { - ss[1], err = syscall.UTF16PtrFromString(exts) - if err != nil { - return err - } - - count++ - } - - return windows.ReportEvent(h.log.Handle, etype, 0, eid, 0, count, 0, &ss[0], nil) -} - -func getServicePath() (string, error) { - p, err := exec.LookPath(os.Args[0]) - if err != nil { - return "", err - } - return filepath.Abs(p) -} - -func registerService() error { - p, err := getServicePath() - if err != nil { - return err - } - m, err := mgr.Connect() - if err != nil { - return err - } - defer m.Disconnect() - - depends := []string{} - - // This dependency is required on build 14393 (RS1) - // it is added to the platform in newer builds - if system.GetOSVersion().Build == 14393 { - depends = append(depends, "ConDrv") - } - - c := mgr.Config{ - ServiceType: windows.SERVICE_WIN32_OWN_PROCESS, - StartType: mgr.StartAutomatic, - ErrorControl: mgr.ErrorNormal, - Dependencies: depends, - DisplayName: "Docker Engine", - } - - // Configure the service to launch with the arguments that were just passed. - args := []string{"--run-service"} - for _, a := range os.Args[1:] { - if a != "--register-service" && a != "--unregister-service" { - args = append(args, a) - } - } - - s, err := m.CreateService(*flServiceName, p, c, args...) - if err != nil { - return err - } - defer s.Close() - - // See http://stackoverflow.com/questions/35151052/how-do-i-configure-failure-actions-of-a-windows-service-written-in-go - const ( - scActionNone = 0 - scActionRestart = 1 - scActionReboot = 2 - scActionRunCommand = 3 - - serviceConfigFailureActions = 2 - ) - - type serviceFailureActions struct { - ResetPeriod uint32 - RebootMsg *uint16 - Command *uint16 - ActionsCount uint32 - Actions uintptr - } - - type scAction struct { - Type uint32 - Delay uint32 - } - t := []scAction{ - {Type: scActionRestart, Delay: uint32(60 * time.Second / time.Millisecond)}, - {Type: scActionRestart, Delay: uint32(60 * time.Second / time.Millisecond)}, - {Type: scActionNone}, - } - lpInfo := serviceFailureActions{ResetPeriod: uint32(24 * time.Hour / time.Second), ActionsCount: uint32(3), Actions: uintptr(unsafe.Pointer(&t[0]))} - err = windows.ChangeServiceConfig2(s.Handle, serviceConfigFailureActions, (*byte)(unsafe.Pointer(&lpInfo))) - if err != nil { - return err - } - - err = eventlog.Install(*flServiceName, p, false, eventlog.Info|eventlog.Warning|eventlog.Error) - if err != nil { - return err - } - - return nil -} - -func unregisterService() error { - m, err := mgr.Connect() - if err != nil { - return err - } - defer m.Disconnect() - - s, err := m.OpenService(*flServiceName) - if err != nil { - return err - } - defer s.Close() - - eventlog.Remove(*flServiceName) - err = s.Delete() - if err != nil { - return err - } - return nil -} - -func initService(daemonCli *DaemonCli) (bool, error) { - if *flUnregisterService { - if *flRegisterService { - return true, errors.New("--register-service and --unregister-service cannot be used together") - } - return true, unregisterService() - } - - if *flRegisterService { - return true, registerService() - } - - if !*flRunService { - return false, nil - } - - interactive, err := svc.IsAnInteractiveSession() - if err != nil { - return false, err - } - - h := &handler{ - tosvc: make(chan bool), - fromsvc: make(chan error), - daemonCli: daemonCli, - } - - var log *eventlog.Log - if !interactive { - log, err = eventlog.Open(*flServiceName) - if err != nil { - return false, err - } - } - - logrus.AddHook(&etwHook{log}) - logrus.SetOutput(ioutil.Discard) - - service = h - go func() { - if interactive { - err = debug.Run(*flServiceName, h) - } else { - err = svc.Run(*flServiceName, h) - } - - h.fromsvc <- err - }() - - // Wait for the first signal from the service handler. - err = <-h.fromsvc - if err != nil { - return false, err - } - return false, nil -} - -func (h *handler) started() error { - // This must be delayed until daemonCli initializes Config.Root - err := initPanicFile(filepath.Join(h.daemonCli.Config.Root, "panic.log")) - if err != nil { - return err - } - - h.tosvc <- false - return nil -} - -func (h *handler) stopped(err error) { - logrus.Debugf("Stopping service: %v", err) - h.tosvc <- err != nil - <-h.fromsvc -} - -func (h *handler) Execute(_ []string, r <-chan svc.ChangeRequest, s chan<- svc.Status) (bool, uint32) { - s <- svc.Status{State: svc.StartPending, Accepts: 0} - // Unblock initService() - h.fromsvc <- nil - - // Wait for initialization to complete. - failed := <-h.tosvc - if failed { - logrus.Debug("Aborting service start due to failure during initialization") - return true, 1 - } - - s <- svc.Status{State: svc.Running, Accepts: svc.AcceptStop | svc.AcceptShutdown | svc.Accepted(windows.SERVICE_ACCEPT_PARAMCHANGE)} - logrus.Debug("Service running") -Loop: - for { - select { - case failed = <-h.tosvc: - break Loop - case c := <-r: - switch c.Cmd { - case svc.Cmd(windows.SERVICE_CONTROL_PARAMCHANGE): - h.daemonCli.reloadConfig() - case svc.Interrogate: - s <- c.CurrentStatus - case svc.Stop, svc.Shutdown: - s <- svc.Status{State: svc.StopPending, Accepts: 0} - h.daemonCli.stop() - } - } - } - - removePanicFile() - if failed { - return true, 1 - } - return false, 0 -} - -func initPanicFile(path string) error { - var err error - panicFile, err = os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0) - if err != nil { - return err - } - - st, err := panicFile.Stat() - if err != nil { - return err - } - - // If there are contents in the file already, move the file out of the way - // and replace it. - if st.Size() > 0 { - panicFile.Close() - os.Rename(path, path+".old") - panicFile, err = os.Create(path) - if err != nil { - return err - } - } - - // Update STD_ERROR_HANDLE to point to the panic file so that Go writes to - // it when it panics. Remember the old stderr to restore it before removing - // the panic file. - sh := syscall.STD_ERROR_HANDLE - h, err := syscall.GetStdHandle(sh) - if err != nil { - return err - } - - oldStderr = h - - r, _, err := setStdHandle.Call(uintptr(sh), uintptr(panicFile.Fd())) - if r == 0 && err != nil { - return err - } - - return nil -} - -func removePanicFile() { - if st, err := panicFile.Stat(); err == nil { - if st.Size() == 0 { - sh := syscall.STD_ERROR_HANDLE - setStdHandle.Call(uintptr(sh), uintptr(oldStderr)) - panicFile.Close() - os.Remove(panicFile.Name()) - } - } -} diff --git a/vendor/github.com/docker/docker/container/archive.go b/vendor/github.com/docker/docker/container/archive.go deleted file mode 100644 index 56e6598..0000000 --- a/vendor/github.com/docker/docker/container/archive.go +++ /dev/null @@ -1,76 +0,0 @@ -package container - -import ( - "os" - "path/filepath" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/system" -) - -// ResolvePath resolves the given path in the container to a resource on the -// host. Returns a resolved path (absolute path to the resource on the host), -// the absolute path to the resource relative to the container's rootfs, and -// an error if the path points to outside the container's rootfs. -func (container *Container) ResolvePath(path string) (resolvedPath, absPath string, err error) { - // Check if a drive letter supplied, it must be the system drive. No-op except on Windows - path, err = system.CheckSystemDriveAndRemoveDriveLetter(path) - if err != nil { - return "", "", err - } - - // Consider the given path as an absolute path in the container. - absPath = archive.PreserveTrailingDotOrSeparator(filepath.Join(string(filepath.Separator), path), path) - - // Split the absPath into its Directory and Base components. We will - // resolve the dir in the scope of the container then append the base. - dirPath, basePath := filepath.Split(absPath) - - resolvedDirPath, err := container.GetResourcePath(dirPath) - if err != nil { - return "", "", err - } - - // resolvedDirPath will have been cleaned (no trailing path separators) so - // we can manually join it with the base path element. - resolvedPath = resolvedDirPath + string(filepath.Separator) + basePath - - return resolvedPath, absPath, nil -} - -// StatPath is the unexported version of StatPath. Locks and mounts should -// be acquired before calling this method and the given path should be fully -// resolved to a path on the host corresponding to the given absolute path -// inside the container. -func (container *Container) StatPath(resolvedPath, absPath string) (stat *types.ContainerPathStat, err error) { - lstat, err := os.Lstat(resolvedPath) - if err != nil { - return nil, err - } - - var linkTarget string - if lstat.Mode()&os.ModeSymlink != 0 { - // Fully evaluate the symlink in the scope of the container rootfs. - hostPath, err := container.GetResourcePath(absPath) - if err != nil { - return nil, err - } - - linkTarget, err = filepath.Rel(container.BaseFS, hostPath) - if err != nil { - return nil, err - } - - // Make it an absolute path. - linkTarget = filepath.Join(string(filepath.Separator), linkTarget) - } - - return &types.ContainerPathStat{ - Name: filepath.Base(absPath), - Size: lstat.Size(), - Mode: lstat.Mode(), - Mtime: lstat.ModTime(), - LinkTarget: linkTarget, - }, nil -} diff --git a/vendor/github.com/docker/docker/container/container.go b/vendor/github.com/docker/docker/container/container.go deleted file mode 100644 index fc4fe27..0000000 --- a/vendor/github.com/docker/docker/container/container.go +++ /dev/null @@ -1,1103 +0,0 @@ -package container - -import ( - "encoding/json" - "fmt" - "io" - "net" - "os" - "path/filepath" - "strconv" - "strings" - "sync" - "syscall" - "time" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - containertypes "github.com/docker/docker/api/types/container" - mounttypes "github.com/docker/docker/api/types/mount" - networktypes "github.com/docker/docker/api/types/network" - swarmtypes "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/container/stream" - "github.com/docker/docker/daemon/exec" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/daemon/logger/jsonfilelog" - "github.com/docker/docker/daemon/network" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/promise" - "github.com/docker/docker/pkg/signal" - "github.com/docker/docker/pkg/symlink" - "github.com/docker/docker/restartmanager" - "github.com/docker/docker/runconfig" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/docker/docker/volume" - "github.com/docker/go-connections/nat" - "github.com/docker/libnetwork" - "github.com/docker/libnetwork/netlabel" - "github.com/docker/libnetwork/options" - "github.com/docker/libnetwork/types" - agentexec "github.com/docker/swarmkit/agent/exec" - "github.com/opencontainers/runc/libcontainer/label" -) - -const configFileName = "config.v2.json" - -const ( - // DefaultStopTimeout is the timeout (in seconds) for the syscall signal used to stop a container. - DefaultStopTimeout = 10 -) - -var ( - errInvalidEndpoint = fmt.Errorf("invalid endpoint while building port map info") - errInvalidNetwork = fmt.Errorf("invalid network settings while building port map info") -) - -// DetachError is special error which returned in case of container detach. -type DetachError struct{} - -func (DetachError) Error() string { - return "detached from container" -} - -// CommonContainer holds the fields for a container which are -// applicable across all platforms supported by the daemon. -type CommonContainer struct { - StreamConfig *stream.Config - // embed for Container to support states directly. - *State `json:"State"` // Needed for Engine API version <= 1.11 - Root string `json:"-"` // Path to the "home" of the container, including metadata. - BaseFS string `json:"-"` // Path to the graphdriver mountpoint - RWLayer layer.RWLayer `json:"-"` - ID string - Created time.Time - Managed bool - Path string - Args []string - Config *containertypes.Config - ImageID image.ID `json:"Image"` - NetworkSettings *network.Settings - LogPath string - Name string - Driver string - // MountLabel contains the options for the 'mount' command - MountLabel string - ProcessLabel string - RestartCount int - HasBeenStartedBefore bool - HasBeenManuallyStopped bool // used for unless-stopped restart policy - MountPoints map[string]*volume.MountPoint - HostConfig *containertypes.HostConfig `json:"-"` // do not serialize the host config in the json, otherwise we'll make the container unportable - ExecCommands *exec.Store `json:"-"` - SecretStore agentexec.SecretGetter `json:"-"` - SecretReferences []*swarmtypes.SecretReference - // logDriver for closing - LogDriver logger.Logger `json:"-"` - LogCopier *logger.Copier `json:"-"` - restartManager restartmanager.RestartManager - attachContext *attachContext -} - -// NewBaseContainer creates a new container with its -// basic configuration. -func NewBaseContainer(id, root string) *Container { - return &Container{ - CommonContainer: CommonContainer{ - ID: id, - State: NewState(), - ExecCommands: exec.NewStore(), - Root: root, - MountPoints: make(map[string]*volume.MountPoint), - StreamConfig: stream.NewConfig(), - attachContext: &attachContext{}, - }, - } -} - -// FromDisk loads the container configuration stored in the host. -func (container *Container) FromDisk() error { - pth, err := container.ConfigPath() - if err != nil { - return err - } - - jsonSource, err := os.Open(pth) - if err != nil { - return err - } - defer jsonSource.Close() - - dec := json.NewDecoder(jsonSource) - - // Load container settings - if err := dec.Decode(container); err != nil { - return err - } - - if err := label.ReserveLabel(container.ProcessLabel); err != nil { - return err - } - return container.readHostConfig() -} - -// ToDisk saves the container configuration on disk. -func (container *Container) ToDisk() error { - pth, err := container.ConfigPath() - if err != nil { - return err - } - - jsonSource, err := ioutils.NewAtomicFileWriter(pth, 0644) - if err != nil { - return err - } - defer jsonSource.Close() - - enc := json.NewEncoder(jsonSource) - - // Save container settings - if err := enc.Encode(container); err != nil { - return err - } - - return container.WriteHostConfig() -} - -// ToDiskLocking saves the container configuration on disk in a thread safe way. -func (container *Container) ToDiskLocking() error { - container.Lock() - err := container.ToDisk() - container.Unlock() - return err -} - -// readHostConfig reads the host configuration from disk for the container. -func (container *Container) readHostConfig() error { - container.HostConfig = &containertypes.HostConfig{} - // If the hostconfig file does not exist, do not read it. - // (We still have to initialize container.HostConfig, - // but that's OK, since we just did that above.) - pth, err := container.HostConfigPath() - if err != nil { - return err - } - - f, err := os.Open(pth) - if err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - defer f.Close() - - if err := json.NewDecoder(f).Decode(&container.HostConfig); err != nil { - return err - } - - container.InitDNSHostConfig() - - return nil -} - -// WriteHostConfig saves the host configuration on disk for the container. -func (container *Container) WriteHostConfig() error { - pth, err := container.HostConfigPath() - if err != nil { - return err - } - - f, err := ioutils.NewAtomicFileWriter(pth, 0644) - if err != nil { - return err - } - defer f.Close() - - return json.NewEncoder(f).Encode(&container.HostConfig) -} - -// SetupWorkingDirectory sets up the container's working directory as set in container.Config.WorkingDir -func (container *Container) SetupWorkingDirectory(rootUID, rootGID int) error { - if container.Config.WorkingDir == "" { - return nil - } - - container.Config.WorkingDir = filepath.Clean(container.Config.WorkingDir) - - pth, err := container.GetResourcePath(container.Config.WorkingDir) - if err != nil { - return err - } - - if err := idtools.MkdirAllNewAs(pth, 0755, rootUID, rootGID); err != nil { - pthInfo, err2 := os.Stat(pth) - if err2 == nil && pthInfo != nil && !pthInfo.IsDir() { - return fmt.Errorf("Cannot mkdir: %s is not a directory", container.Config.WorkingDir) - } - - return err - } - - return nil -} - -// GetResourcePath evaluates `path` in the scope of the container's BaseFS, with proper path -// sanitisation. Symlinks are all scoped to the BaseFS of the container, as -// though the container's BaseFS was `/`. -// -// The BaseFS of a container is the host-facing path which is bind-mounted as -// `/` inside the container. This method is essentially used to access a -// particular path inside the container as though you were a process in that -// container. -// -// NOTE: The returned path is *only* safely scoped inside the container's BaseFS -// if no component of the returned path changes (such as a component -// symlinking to a different path) between using this method and using the -// path. See symlink.FollowSymlinkInScope for more details. -func (container *Container) GetResourcePath(path string) (string, error) { - // IMPORTANT - These are paths on the OS where the daemon is running, hence - // any filepath operations must be done in an OS agnostic way. - - cleanPath := cleanResourcePath(path) - r, e := symlink.FollowSymlinkInScope(filepath.Join(container.BaseFS, cleanPath), container.BaseFS) - - // Log this here on the daemon side as there's otherwise no indication apart - // from the error being propagated all the way back to the client. This makes - // debugging significantly easier and clearly indicates the error comes from the daemon. - if e != nil { - logrus.Errorf("Failed to FollowSymlinkInScope BaseFS %s cleanPath %s path %s %s\n", container.BaseFS, cleanPath, path, e) - } - return r, e -} - -// GetRootResourcePath evaluates `path` in the scope of the container's root, with proper path -// sanitisation. Symlinks are all scoped to the root of the container, as -// though the container's root was `/`. -// -// The root of a container is the host-facing configuration metadata directory. -// Only use this method to safely access the container's `container.json` or -// other metadata files. If in doubt, use container.GetResourcePath. -// -// NOTE: The returned path is *only* safely scoped inside the container's root -// if no component of the returned path changes (such as a component -// symlinking to a different path) between using this method and using the -// path. See symlink.FollowSymlinkInScope for more details. -func (container *Container) GetRootResourcePath(path string) (string, error) { - // IMPORTANT - These are paths on the OS where the daemon is running, hence - // any filepath operations must be done in an OS agnostic way. - cleanPath := filepath.Join(string(os.PathSeparator), path) - return symlink.FollowSymlinkInScope(filepath.Join(container.Root, cleanPath), container.Root) -} - -// ExitOnNext signals to the monitor that it should not restart the container -// after we send the kill signal. -func (container *Container) ExitOnNext() { - container.RestartManager().Cancel() -} - -// HostConfigPath returns the path to the container's JSON hostconfig -func (container *Container) HostConfigPath() (string, error) { - return container.GetRootResourcePath("hostconfig.json") -} - -// ConfigPath returns the path to the container's JSON config -func (container *Container) ConfigPath() (string, error) { - return container.GetRootResourcePath(configFileName) -} - -// CheckpointDir returns the directory checkpoints are stored in -func (container *Container) CheckpointDir() string { - return filepath.Join(container.Root, "checkpoints") -} - -// StartLogger starts a new logger driver for the container. -func (container *Container) StartLogger(cfg containertypes.LogConfig) (logger.Logger, error) { - c, err := logger.GetLogDriver(cfg.Type) - if err != nil { - return nil, fmt.Errorf("Failed to get logging factory: %v", err) - } - ctx := logger.Context{ - Config: cfg.Config, - ContainerID: container.ID, - ContainerName: container.Name, - ContainerEntrypoint: container.Path, - ContainerArgs: container.Args, - ContainerImageID: container.ImageID.String(), - ContainerImageName: container.Config.Image, - ContainerCreated: container.Created, - ContainerEnv: container.Config.Env, - ContainerLabels: container.Config.Labels, - DaemonName: "docker", - } - - // Set logging file for "json-logger" - if cfg.Type == jsonfilelog.Name { - ctx.LogPath, err = container.GetRootResourcePath(fmt.Sprintf("%s-json.log", container.ID)) - if err != nil { - return nil, err - } - } - return c(ctx) -} - -// GetProcessLabel returns the process label for the container. -func (container *Container) GetProcessLabel() string { - // even if we have a process label return "" if we are running - // in privileged mode - if container.HostConfig.Privileged { - return "" - } - return container.ProcessLabel -} - -// GetMountLabel returns the mounting label for the container. -// This label is empty if the container is privileged. -func (container *Container) GetMountLabel() string { - return container.MountLabel -} - -// GetExecIDs returns the list of exec commands running on the container. -func (container *Container) GetExecIDs() []string { - return container.ExecCommands.List() -} - -// Attach connects to the container's TTY, delegating to standard -// streams or websockets depending on the configuration. -func (container *Container) Attach(stdin io.ReadCloser, stdout io.Writer, stderr io.Writer, keys []byte) chan error { - ctx := container.InitAttachContext() - return AttachStreams(ctx, container.StreamConfig, container.Config.OpenStdin, container.Config.StdinOnce, container.Config.Tty, stdin, stdout, stderr, keys) -} - -// AttachStreams connects streams to a TTY. -// Used by exec too. Should this move somewhere else? -func AttachStreams(ctx context.Context, streamConfig *stream.Config, openStdin, stdinOnce, tty bool, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer, keys []byte) chan error { - var ( - cStdout, cStderr io.ReadCloser - cStdin io.WriteCloser - wg sync.WaitGroup - errors = make(chan error, 3) - ) - - if stdin != nil && openStdin { - cStdin = streamConfig.StdinPipe() - wg.Add(1) - } - - if stdout != nil { - cStdout = streamConfig.StdoutPipe() - wg.Add(1) - } - - if stderr != nil { - cStderr = streamConfig.StderrPipe() - wg.Add(1) - } - - // Connect stdin of container to the http conn. - go func() { - if stdin == nil || !openStdin { - return - } - logrus.Debug("attach: stdin: begin") - - var err error - if tty { - _, err = copyEscapable(cStdin, stdin, keys) - } else { - _, err = io.Copy(cStdin, stdin) - } - if err == io.ErrClosedPipe { - err = nil - } - if err != nil { - logrus.Errorf("attach: stdin: %s", err) - errors <- err - } - if stdinOnce && !tty { - cStdin.Close() - } else { - // No matter what, when stdin is closed (io.Copy unblock), close stdout and stderr - if cStdout != nil { - cStdout.Close() - } - if cStderr != nil { - cStderr.Close() - } - } - logrus.Debug("attach: stdin: end") - wg.Done() - }() - - attachStream := func(name string, stream io.Writer, streamPipe io.ReadCloser) { - if stream == nil { - return - } - - logrus.Debugf("attach: %s: begin", name) - _, err := io.Copy(stream, streamPipe) - if err == io.ErrClosedPipe { - err = nil - } - if err != nil { - logrus.Errorf("attach: %s: %v", name, err) - errors <- err - } - // Make sure stdin gets closed - if stdin != nil { - stdin.Close() - } - streamPipe.Close() - logrus.Debugf("attach: %s: end", name) - wg.Done() - } - - go attachStream("stdout", stdout, cStdout) - go attachStream("stderr", stderr, cStderr) - - return promise.Go(func() error { - done := make(chan struct{}) - go func() { - wg.Wait() - close(done) - }() - select { - case <-done: - case <-ctx.Done(): - // close all pipes - if cStdin != nil { - cStdin.Close() - } - if cStdout != nil { - cStdout.Close() - } - if cStderr != nil { - cStderr.Close() - } - <-done - } - close(errors) - for err := range errors { - if err != nil { - return err - } - } - return nil - }) -} - -// Code c/c from io.Copy() modified to handle escape sequence -func copyEscapable(dst io.Writer, src io.ReadCloser, keys []byte) (written int64, err error) { - if len(keys) == 0 { - // Default keys : ctrl-p ctrl-q - keys = []byte{16, 17} - } - buf := make([]byte, 32*1024) - for { - nr, er := src.Read(buf) - if nr > 0 { - // ---- Docker addition - preservBuf := []byte{} - for i, key := range keys { - preservBuf = append(preservBuf, buf[0:nr]...) - if nr != 1 || buf[0] != key { - break - } - if i == len(keys)-1 { - src.Close() - return 0, DetachError{} - } - nr, er = src.Read(buf) - } - var nw int - var ew error - if len(preservBuf) > 0 { - nw, ew = dst.Write(preservBuf) - nr = len(preservBuf) - } else { - // ---- End of docker - nw, ew = dst.Write(buf[0:nr]) - } - if nw > 0 { - written += int64(nw) - } - if ew != nil { - err = ew - break - } - if nr != nw { - err = io.ErrShortWrite - break - } - } - if er == io.EOF { - break - } - if er != nil { - err = er - break - } - } - return written, err -} - -// ShouldRestart decides whether the daemon should restart the container or not. -// This is based on the container's restart policy. -func (container *Container) ShouldRestart() bool { - shouldRestart, _, _ := container.RestartManager().ShouldRestart(uint32(container.ExitCode()), container.HasBeenManuallyStopped, container.FinishedAt.Sub(container.StartedAt)) - return shouldRestart -} - -// AddMountPointWithVolume adds a new mount point configured with a volume to the container. -func (container *Container) AddMountPointWithVolume(destination string, vol volume.Volume, rw bool) { - container.MountPoints[destination] = &volume.MountPoint{ - Type: mounttypes.TypeVolume, - Name: vol.Name(), - Driver: vol.DriverName(), - Destination: destination, - RW: rw, - Volume: vol, - CopyData: volume.DefaultCopyMode, - } -} - -// UnmountVolumes unmounts all volumes -func (container *Container) UnmountVolumes(volumeEventLog func(name, action string, attributes map[string]string)) error { - var errors []string - for _, volumeMount := range container.MountPoints { - // Check if the mounpoint has an ID, this is currently the best way to tell if it's actually mounted - // TODO(cpuguyh83): there should be a better way to handle this - if volumeMount.Volume != nil && volumeMount.ID != "" { - if err := volumeMount.Volume.Unmount(volumeMount.ID); err != nil { - errors = append(errors, err.Error()) - continue - } - volumeMount.ID = "" - - attributes := map[string]string{ - "driver": volumeMount.Volume.DriverName(), - "container": container.ID, - } - volumeEventLog(volumeMount.Volume.Name(), "unmount", attributes) - } - } - if len(errors) > 0 { - return fmt.Errorf("error while unmounting volumes for container %s: %s", container.ID, strings.Join(errors, "; ")) - } - return nil -} - -// IsDestinationMounted checks whether a path is mounted on the container or not. -func (container *Container) IsDestinationMounted(destination string) bool { - return container.MountPoints[destination] != nil -} - -// StopSignal returns the signal used to stop the container. -func (container *Container) StopSignal() int { - var stopSignal syscall.Signal - if container.Config.StopSignal != "" { - stopSignal, _ = signal.ParseSignal(container.Config.StopSignal) - } - - if int(stopSignal) == 0 { - stopSignal, _ = signal.ParseSignal(signal.DefaultStopSignal) - } - return int(stopSignal) -} - -// StopTimeout returns the timeout (in seconds) used to stop the container. -func (container *Container) StopTimeout() int { - if container.Config.StopTimeout != nil { - return *container.Config.StopTimeout - } - return DefaultStopTimeout -} - -// InitDNSHostConfig ensures that the dns fields are never nil. -// New containers don't ever have those fields nil, -// but pre created containers can still have those nil values. -// The non-recommended host configuration in the start api can -// make these fields nil again, this corrects that issue until -// we remove that behavior for good. -// See https://github.com/docker/docker/pull/17779 -// for a more detailed explanation on why we don't want that. -func (container *Container) InitDNSHostConfig() { - container.Lock() - defer container.Unlock() - if container.HostConfig.DNS == nil { - container.HostConfig.DNS = make([]string, 0) - } - - if container.HostConfig.DNSSearch == nil { - container.HostConfig.DNSSearch = make([]string, 0) - } - - if container.HostConfig.DNSOptions == nil { - container.HostConfig.DNSOptions = make([]string, 0) - } -} - -// GetEndpointInNetwork returns the container's endpoint to the provided network. -func (container *Container) GetEndpointInNetwork(n libnetwork.Network) (libnetwork.Endpoint, error) { - endpointName := strings.TrimPrefix(container.Name, "/") - return n.EndpointByName(endpointName) -} - -func (container *Container) buildPortMapInfo(ep libnetwork.Endpoint) error { - if ep == nil { - return errInvalidEndpoint - } - - networkSettings := container.NetworkSettings - if networkSettings == nil { - return errInvalidNetwork - } - - if len(networkSettings.Ports) == 0 { - pm, err := getEndpointPortMapInfo(ep) - if err != nil { - return err - } - networkSettings.Ports = pm - } - return nil -} - -func getEndpointPortMapInfo(ep libnetwork.Endpoint) (nat.PortMap, error) { - pm := nat.PortMap{} - driverInfo, err := ep.DriverInfo() - if err != nil { - return pm, err - } - - if driverInfo == nil { - // It is not an error for epInfo to be nil - return pm, nil - } - - if expData, ok := driverInfo[netlabel.ExposedPorts]; ok { - if exposedPorts, ok := expData.([]types.TransportPort); ok { - for _, tp := range exposedPorts { - natPort, err := nat.NewPort(tp.Proto.String(), strconv.Itoa(int(tp.Port))) - if err != nil { - return pm, fmt.Errorf("Error parsing Port value(%v):%v", tp.Port, err) - } - pm[natPort] = nil - } - } - } - - mapData, ok := driverInfo[netlabel.PortMap] - if !ok { - return pm, nil - } - - if portMapping, ok := mapData.([]types.PortBinding); ok { - for _, pp := range portMapping { - natPort, err := nat.NewPort(pp.Proto.String(), strconv.Itoa(int(pp.Port))) - if err != nil { - return pm, err - } - natBndg := nat.PortBinding{HostIP: pp.HostIP.String(), HostPort: strconv.Itoa(int(pp.HostPort))} - pm[natPort] = append(pm[natPort], natBndg) - } - } - - return pm, nil -} - -// GetSandboxPortMapInfo retrieves the current port-mapping programmed for the given sandbox -func GetSandboxPortMapInfo(sb libnetwork.Sandbox) nat.PortMap { - pm := nat.PortMap{} - if sb == nil { - return pm - } - - for _, ep := range sb.Endpoints() { - pm, _ = getEndpointPortMapInfo(ep) - if len(pm) > 0 { - break - } - } - return pm -} - -// BuildEndpointInfo sets endpoint-related fields on container.NetworkSettings based on the provided network and endpoint. -func (container *Container) BuildEndpointInfo(n libnetwork.Network, ep libnetwork.Endpoint) error { - if ep == nil { - return errInvalidEndpoint - } - - networkSettings := container.NetworkSettings - if networkSettings == nil { - return errInvalidNetwork - } - - epInfo := ep.Info() - if epInfo == nil { - // It is not an error to get an empty endpoint info - return nil - } - - if _, ok := networkSettings.Networks[n.Name()]; !ok { - networkSettings.Networks[n.Name()] = &network.EndpointSettings{ - EndpointSettings: &networktypes.EndpointSettings{}, - } - } - networkSettings.Networks[n.Name()].NetworkID = n.ID() - networkSettings.Networks[n.Name()].EndpointID = ep.ID() - - iface := epInfo.Iface() - if iface == nil { - return nil - } - - if iface.MacAddress() != nil { - networkSettings.Networks[n.Name()].MacAddress = iface.MacAddress().String() - } - - if iface.Address() != nil { - ones, _ := iface.Address().Mask.Size() - networkSettings.Networks[n.Name()].IPAddress = iface.Address().IP.String() - networkSettings.Networks[n.Name()].IPPrefixLen = ones - } - - if iface.AddressIPv6() != nil && iface.AddressIPv6().IP.To16() != nil { - onesv6, _ := iface.AddressIPv6().Mask.Size() - networkSettings.Networks[n.Name()].GlobalIPv6Address = iface.AddressIPv6().IP.String() - networkSettings.Networks[n.Name()].GlobalIPv6PrefixLen = onesv6 - } - - return nil -} - -// UpdateJoinInfo updates network settings when container joins network n with endpoint ep. -func (container *Container) UpdateJoinInfo(n libnetwork.Network, ep libnetwork.Endpoint) error { - if err := container.buildPortMapInfo(ep); err != nil { - return err - } - - epInfo := ep.Info() - if epInfo == nil { - // It is not an error to get an empty endpoint info - return nil - } - if epInfo.Gateway() != nil { - container.NetworkSettings.Networks[n.Name()].Gateway = epInfo.Gateway().String() - } - if epInfo.GatewayIPv6().To16() != nil { - container.NetworkSettings.Networks[n.Name()].IPv6Gateway = epInfo.GatewayIPv6().String() - } - - return nil -} - -// UpdateSandboxNetworkSettings updates the sandbox ID and Key. -func (container *Container) UpdateSandboxNetworkSettings(sb libnetwork.Sandbox) error { - container.NetworkSettings.SandboxID = sb.ID() - container.NetworkSettings.SandboxKey = sb.Key() - return nil -} - -// BuildJoinOptions builds endpoint Join options from a given network. -func (container *Container) BuildJoinOptions(n libnetwork.Network) ([]libnetwork.EndpointOption, error) { - var joinOptions []libnetwork.EndpointOption - if epConfig, ok := container.NetworkSettings.Networks[n.Name()]; ok { - for _, str := range epConfig.Links { - name, alias, err := runconfigopts.ParseLink(str) - if err != nil { - return nil, err - } - joinOptions = append(joinOptions, libnetwork.CreateOptionAlias(name, alias)) - } - } - return joinOptions, nil -} - -// BuildCreateEndpointOptions builds endpoint options from a given network. -func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epConfig *networktypes.EndpointSettings, sb libnetwork.Sandbox, daemonDNS []string) ([]libnetwork.EndpointOption, error) { - var ( - bindings = make(nat.PortMap) - pbList []types.PortBinding - exposeList []types.TransportPort - createOptions []libnetwork.EndpointOption - ) - - defaultNetName := runconfig.DefaultDaemonNetworkMode().NetworkName() - - if (!container.EnableServiceDiscoveryOnDefaultNetwork() && n.Name() == defaultNetName) || - container.NetworkSettings.IsAnonymousEndpoint { - createOptions = append(createOptions, libnetwork.CreateOptionAnonymous()) - } - - if epConfig != nil { - ipam := epConfig.IPAMConfig - if ipam != nil && (ipam.IPv4Address != "" || ipam.IPv6Address != "" || len(ipam.LinkLocalIPs) > 0) { - var ipList []net.IP - for _, ips := range ipam.LinkLocalIPs { - if ip := net.ParseIP(ips); ip != nil { - ipList = append(ipList, ip) - } - } - createOptions = append(createOptions, - libnetwork.CreateOptionIpam(net.ParseIP(ipam.IPv4Address), net.ParseIP(ipam.IPv6Address), ipList, nil)) - } - - for _, alias := range epConfig.Aliases { - createOptions = append(createOptions, libnetwork.CreateOptionMyAlias(alias)) - } - } - - if container.NetworkSettings.Service != nil { - svcCfg := container.NetworkSettings.Service - - var vip string - if svcCfg.VirtualAddresses[n.ID()] != nil { - vip = svcCfg.VirtualAddresses[n.ID()].IPv4 - } - - var portConfigs []*libnetwork.PortConfig - for _, portConfig := range svcCfg.ExposedPorts { - portConfigs = append(portConfigs, &libnetwork.PortConfig{ - Name: portConfig.Name, - Protocol: libnetwork.PortConfig_Protocol(portConfig.Protocol), - TargetPort: portConfig.TargetPort, - PublishedPort: portConfig.PublishedPort, - }) - } - - createOptions = append(createOptions, libnetwork.CreateOptionService(svcCfg.Name, svcCfg.ID, net.ParseIP(vip), portConfigs, svcCfg.Aliases[n.ID()])) - } - - if !containertypes.NetworkMode(n.Name()).IsUserDefined() { - createOptions = append(createOptions, libnetwork.CreateOptionDisableResolution()) - } - - // configs that are applicable only for the endpoint in the network - // to which container was connected to on docker run. - // Ideally all these network-specific endpoint configurations must be moved under - // container.NetworkSettings.Networks[n.Name()] - if n.Name() == container.HostConfig.NetworkMode.NetworkName() || - (n.Name() == defaultNetName && container.HostConfig.NetworkMode.IsDefault()) { - if container.Config.MacAddress != "" { - mac, err := net.ParseMAC(container.Config.MacAddress) - if err != nil { - return nil, err - } - - genericOption := options.Generic{ - netlabel.MacAddress: mac, - } - - createOptions = append(createOptions, libnetwork.EndpointOptionGeneric(genericOption)) - } - } - - // Port-mapping rules belong to the container & applicable only to non-internal networks - portmaps := GetSandboxPortMapInfo(sb) - if n.Info().Internal() || len(portmaps) > 0 { - return createOptions, nil - } - - if container.HostConfig.PortBindings != nil { - for p, b := range container.HostConfig.PortBindings { - bindings[p] = []nat.PortBinding{} - for _, bb := range b { - bindings[p] = append(bindings[p], nat.PortBinding{ - HostIP: bb.HostIP, - HostPort: bb.HostPort, - }) - } - } - } - - portSpecs := container.Config.ExposedPorts - ports := make([]nat.Port, len(portSpecs)) - var i int - for p := range portSpecs { - ports[i] = p - i++ - } - nat.SortPortMap(ports, bindings) - for _, port := range ports { - expose := types.TransportPort{} - expose.Proto = types.ParseProtocol(port.Proto()) - expose.Port = uint16(port.Int()) - exposeList = append(exposeList, expose) - - pb := types.PortBinding{Port: expose.Port, Proto: expose.Proto} - binding := bindings[port] - for i := 0; i < len(binding); i++ { - pbCopy := pb.GetCopy() - newP, err := nat.NewPort(nat.SplitProtoPort(binding[i].HostPort)) - var portStart, portEnd int - if err == nil { - portStart, portEnd, err = newP.Range() - } - if err != nil { - return nil, fmt.Errorf("Error parsing HostPort value(%s):%v", binding[i].HostPort, err) - } - pbCopy.HostPort = uint16(portStart) - pbCopy.HostPortEnd = uint16(portEnd) - pbCopy.HostIP = net.ParseIP(binding[i].HostIP) - pbList = append(pbList, pbCopy) - } - - if container.HostConfig.PublishAllPorts && len(binding) == 0 { - pbList = append(pbList, pb) - } - } - - var dns []string - - if len(container.HostConfig.DNS) > 0 { - dns = container.HostConfig.DNS - } else if len(daemonDNS) > 0 { - dns = daemonDNS - } - - if len(dns) > 0 { - createOptions = append(createOptions, - libnetwork.CreateOptionDNS(dns)) - } - - createOptions = append(createOptions, - libnetwork.CreateOptionPortMapping(pbList), - libnetwork.CreateOptionExposedPorts(exposeList)) - - return createOptions, nil -} - -// UpdateMonitor updates monitor configure for running container -func (container *Container) UpdateMonitor(restartPolicy containertypes.RestartPolicy) { - type policySetter interface { - SetPolicy(containertypes.RestartPolicy) - } - - if rm, ok := container.RestartManager().(policySetter); ok { - rm.SetPolicy(restartPolicy) - } -} - -// FullHostname returns hostname and optional domain appended to it. -func (container *Container) FullHostname() string { - fullHostname := container.Config.Hostname - if container.Config.Domainname != "" { - fullHostname = fmt.Sprintf("%s.%s", fullHostname, container.Config.Domainname) - } - return fullHostname -} - -// RestartManager returns the current restartmanager instance connected to container. -func (container *Container) RestartManager() restartmanager.RestartManager { - if container.restartManager == nil { - container.restartManager = restartmanager.New(container.HostConfig.RestartPolicy, container.RestartCount) - } - return container.restartManager -} - -// ResetRestartManager initializes new restartmanager based on container config -func (container *Container) ResetRestartManager(resetCount bool) { - if container.restartManager != nil { - container.restartManager.Cancel() - } - if resetCount { - container.RestartCount = 0 - } - container.restartManager = nil -} - -type attachContext struct { - ctx context.Context - cancel context.CancelFunc - mu sync.Mutex -} - -// InitAttachContext initializes or returns existing context for attach calls to -// track container liveness. -func (container *Container) InitAttachContext() context.Context { - container.attachContext.mu.Lock() - defer container.attachContext.mu.Unlock() - if container.attachContext.ctx == nil { - container.attachContext.ctx, container.attachContext.cancel = context.WithCancel(context.Background()) - } - return container.attachContext.ctx -} - -// CancelAttachContext cancels attach context. All attach calls should detach -// after this call. -func (container *Container) CancelAttachContext() { - container.attachContext.mu.Lock() - if container.attachContext.ctx != nil { - container.attachContext.cancel() - container.attachContext.ctx = nil - } - container.attachContext.mu.Unlock() -} - -func (container *Container) startLogging() error { - if container.HostConfig.LogConfig.Type == "none" { - return nil // do not start logging routines - } - - l, err := container.StartLogger(container.HostConfig.LogConfig) - if err != nil { - return fmt.Errorf("Failed to initialize logging driver: %v", err) - } - - copier := logger.NewCopier(map[string]io.Reader{"stdout": container.StdoutPipe(), "stderr": container.StderrPipe()}, l) - container.LogCopier = copier - copier.Run() - container.LogDriver = l - - // set LogPath field only for json-file logdriver - if jl, ok := l.(*jsonfilelog.JSONFileLogger); ok { - container.LogPath = jl.LogPath() - } - - return nil -} - -// StdinPipe gets the stdin stream of the container -func (container *Container) StdinPipe() io.WriteCloser { - return container.StreamConfig.StdinPipe() -} - -// StdoutPipe gets the stdout stream of the container -func (container *Container) StdoutPipe() io.ReadCloser { - return container.StreamConfig.StdoutPipe() -} - -// StderrPipe gets the stderr stream of the container -func (container *Container) StderrPipe() io.ReadCloser { - return container.StreamConfig.StderrPipe() -} - -// CloseStreams closes the container's stdio streams -func (container *Container) CloseStreams() error { - return container.StreamConfig.CloseStreams() -} - -// InitializeStdio is called by libcontainerd to connect the stdio. -func (container *Container) InitializeStdio(iop libcontainerd.IOPipe) error { - if err := container.startLogging(); err != nil { - container.Reset(false) - return err - } - - container.StreamConfig.CopyToPipe(iop) - - if container.StreamConfig.Stdin() == nil && !container.Config.Tty { - if iop.Stdin != nil { - if err := iop.Stdin.Close(); err != nil { - logrus.Warnf("error closing stdin: %+v", err) - } - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/container/container_linux.go b/vendor/github.com/docker/docker/container/container_linux.go deleted file mode 100644 index 4d4c16b..0000000 --- a/vendor/github.com/docker/docker/container/container_linux.go +++ /dev/null @@ -1,9 +0,0 @@ -package container - -import ( - "golang.org/x/sys/unix" -) - -func detachMounted(path string) error { - return unix.Unmount(path, unix.MNT_DETACH) -} diff --git a/vendor/github.com/docker/docker/container/container_notlinux.go b/vendor/github.com/docker/docker/container/container_notlinux.go deleted file mode 100644 index f65653e..0000000 --- a/vendor/github.com/docker/docker/container/container_notlinux.go +++ /dev/null @@ -1,23 +0,0 @@ -// +build solaris freebsd - -package container - -import ( - "golang.org/x/sys/unix" -) - -func detachMounted(path string) error { - //Solaris and FreeBSD do not support the lazy unmount or MNT_DETACH feature. - // Therefore there are separate definitions for this. - return unix.Unmount(path, 0) -} - -// SecretMount returns the mount for the secret path -func (container *Container) SecretMount() *Mount { - return nil -} - -// UnmountSecrets unmounts the fs for secrets -func (container *Container) UnmountSecrets() error { - return nil -} diff --git a/vendor/github.com/docker/docker/container/container_unit_test.go b/vendor/github.com/docker/docker/container/container_unit_test.go deleted file mode 100644 index f301f25..0000000 --- a/vendor/github.com/docker/docker/container/container_unit_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package container - -import ( - "testing" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/signal" -) - -func TestContainerStopSignal(t *testing.T) { - c := &Container{ - CommonContainer: CommonContainer{ - Config: &container.Config{}, - }, - } - - def, err := signal.ParseSignal(signal.DefaultStopSignal) - if err != nil { - t.Fatal(err) - } - - s := c.StopSignal() - if s != int(def) { - t.Fatalf("Expected %v, got %v", def, s) - } - - c = &Container{ - CommonContainer: CommonContainer{ - Config: &container.Config{StopSignal: "SIGKILL"}, - }, - } - s = c.StopSignal() - if s != 9 { - t.Fatalf("Expected 9, got %v", s) - } -} - -func TestContainerStopTimeout(t *testing.T) { - c := &Container{ - CommonContainer: CommonContainer{ - Config: &container.Config{}, - }, - } - - s := c.StopTimeout() - if s != DefaultStopTimeout { - t.Fatalf("Expected %v, got %v", DefaultStopTimeout, s) - } - - stopTimeout := 15 - c = &Container{ - CommonContainer: CommonContainer{ - Config: &container.Config{StopTimeout: &stopTimeout}, - }, - } - s = c.StopSignal() - if s != 15 { - t.Fatalf("Expected 15, got %v", s) - } -} diff --git a/vendor/github.com/docker/docker/container/container_unix.go b/vendor/github.com/docker/docker/container/container_unix.go deleted file mode 100644 index 4f6b795..0000000 --- a/vendor/github.com/docker/docker/container/container_unix.go +++ /dev/null @@ -1,448 +0,0 @@ -// +build linux freebsd solaris - -package container - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strings" - - "github.com/Sirupsen/logrus" - containertypes "github.com/docker/docker/api/types/container" - mounttypes "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/pkg/chrootarchive" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/symlink" - "github.com/docker/docker/pkg/system" - "github.com/docker/docker/utils" - "github.com/docker/docker/volume" - "github.com/opencontainers/runc/libcontainer/label" - "golang.org/x/sys/unix" -) - -const ( - // DefaultSHMSize is the default size (64MB) of the SHM which will be mounted in the container - DefaultSHMSize int64 = 67108864 - containerSecretMountPath = "/run/secrets" -) - -// Container holds the fields specific to unixen implementations. -// See CommonContainer for standard fields common to all containers. -type Container struct { - CommonContainer - - // Fields below here are platform specific. - AppArmorProfile string - HostnamePath string - HostsPath string - ShmPath string - ResolvConfPath string - SeccompProfile string - NoNewPrivileges bool -} - -// ExitStatus provides exit reasons for a container. -type ExitStatus struct { - // The exit code with which the container exited. - ExitCode int - - // Whether the container encountered an OOM. - OOMKilled bool -} - -// CreateDaemonEnvironment returns the list of all environment variables given the list of -// environment variables related to links. -// Sets PATH, HOSTNAME and if container.Config.Tty is set: TERM. -// The defaults set here do not override the values in container.Config.Env -func (container *Container) CreateDaemonEnvironment(tty bool, linkedEnv []string) []string { - // Setup environment - env := []string{ - "PATH=" + system.DefaultPathEnv, - "HOSTNAME=" + container.Config.Hostname, - } - if tty { - env = append(env, "TERM=xterm") - } - env = append(env, linkedEnv...) - // because the env on the container can override certain default values - // we need to replace the 'env' keys where they match and append anything - // else. - env = utils.ReplaceOrAppendEnvValues(env, container.Config.Env) - return env -} - -// TrySetNetworkMount attempts to set the network mounts given a provided destination and -// the path to use for it; return true if the given destination was a network mount file -func (container *Container) TrySetNetworkMount(destination string, path string) bool { - if destination == "/etc/resolv.conf" { - container.ResolvConfPath = path - return true - } - if destination == "/etc/hostname" { - container.HostnamePath = path - return true - } - if destination == "/etc/hosts" { - container.HostsPath = path - return true - } - - return false -} - -// BuildHostnameFile writes the container's hostname file. -func (container *Container) BuildHostnameFile() error { - hostnamePath, err := container.GetRootResourcePath("hostname") - if err != nil { - return err - } - container.HostnamePath = hostnamePath - return ioutil.WriteFile(container.HostnamePath, []byte(container.Config.Hostname+"\n"), 0644) -} - -// NetworkMounts returns the list of network mounts. -func (container *Container) NetworkMounts() []Mount { - var mounts []Mount - shared := container.HostConfig.NetworkMode.IsContainer() - if container.ResolvConfPath != "" { - if _, err := os.Stat(container.ResolvConfPath); err != nil { - logrus.Warnf("ResolvConfPath set to %q, but can't stat this filename (err = %v); skipping", container.ResolvConfPath, err) - } else { - if !container.HasMountFor("/etc/resolv.conf") { - label.Relabel(container.ResolvConfPath, container.MountLabel, shared) - } - writable := !container.HostConfig.ReadonlyRootfs - if m, exists := container.MountPoints["/etc/resolv.conf"]; exists { - writable = m.RW - } - mounts = append(mounts, Mount{ - Source: container.ResolvConfPath, - Destination: "/etc/resolv.conf", - Writable: writable, - Propagation: string(volume.DefaultPropagationMode), - }) - } - } - if container.HostnamePath != "" { - if _, err := os.Stat(container.HostnamePath); err != nil { - logrus.Warnf("HostnamePath set to %q, but can't stat this filename (err = %v); skipping", container.HostnamePath, err) - } else { - if !container.HasMountFor("/etc/hostname") { - label.Relabel(container.HostnamePath, container.MountLabel, shared) - } - writable := !container.HostConfig.ReadonlyRootfs - if m, exists := container.MountPoints["/etc/hostname"]; exists { - writable = m.RW - } - mounts = append(mounts, Mount{ - Source: container.HostnamePath, - Destination: "/etc/hostname", - Writable: writable, - Propagation: string(volume.DefaultPropagationMode), - }) - } - } - if container.HostsPath != "" { - if _, err := os.Stat(container.HostsPath); err != nil { - logrus.Warnf("HostsPath set to %q, but can't stat this filename (err = %v); skipping", container.HostsPath, err) - } else { - if !container.HasMountFor("/etc/hosts") { - label.Relabel(container.HostsPath, container.MountLabel, shared) - } - writable := !container.HostConfig.ReadonlyRootfs - if m, exists := container.MountPoints["/etc/hosts"]; exists { - writable = m.RW - } - mounts = append(mounts, Mount{ - Source: container.HostsPath, - Destination: "/etc/hosts", - Writable: writable, - Propagation: string(volume.DefaultPropagationMode), - }) - } - } - return mounts -} - -// SecretMountPath returns the path of the secret mount for the container -func (container *Container) SecretMountPath() string { - return filepath.Join(container.Root, "secrets") -} - -// CopyImagePathContent copies files in destination to the volume. -func (container *Container) CopyImagePathContent(v volume.Volume, destination string) error { - rootfs, err := symlink.FollowSymlinkInScope(filepath.Join(container.BaseFS, destination), container.BaseFS) - if err != nil { - return err - } - - if _, err = ioutil.ReadDir(rootfs); err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - - id := stringid.GenerateNonCryptoID() - path, err := v.Mount(id) - if err != nil { - return err - } - - defer func() { - if err := v.Unmount(id); err != nil { - logrus.Warnf("error while unmounting volume %s: %v", v.Name(), err) - } - }() - if err := label.Relabel(path, container.MountLabel, true); err != nil && err != unix.ENOTSUP { - return err - } - return copyExistingContents(rootfs, path) -} - -// ShmResourcePath returns path to shm -func (container *Container) ShmResourcePath() (string, error) { - return container.GetRootResourcePath("shm") -} - -// HasMountFor checks if path is a mountpoint -func (container *Container) HasMountFor(path string) bool { - _, exists := container.MountPoints[path] - return exists -} - -// UnmountIpcMounts uses the provided unmount function to unmount shm and mqueue if they were mounted -func (container *Container) UnmountIpcMounts(unmount func(pth string) error) { - if container.HostConfig.IpcMode.IsContainer() || container.HostConfig.IpcMode.IsHost() { - return - } - - var warnings []string - - if !container.HasMountFor("/dev/shm") { - shmPath, err := container.ShmResourcePath() - if err != nil { - logrus.Error(err) - warnings = append(warnings, err.Error()) - } else if shmPath != "" { - if err := unmount(shmPath); err != nil && !os.IsNotExist(err) { - warnings = append(warnings, fmt.Sprintf("failed to umount %s: %v", shmPath, err)) - } - - } - } - - if len(warnings) > 0 { - logrus.Warnf("failed to cleanup ipc mounts:\n%v", strings.Join(warnings, "\n")) - } -} - -// IpcMounts returns the list of IPC mounts -func (container *Container) IpcMounts() []Mount { - var mounts []Mount - - if !container.HasMountFor("/dev/shm") { - label.SetFileLabel(container.ShmPath, container.MountLabel) - mounts = append(mounts, Mount{ - Source: container.ShmPath, - Destination: "/dev/shm", - Writable: true, - Propagation: string(volume.DefaultPropagationMode), - }) - } - - return mounts -} - -// SecretMount returns the mount for the secret path -func (container *Container) SecretMount() *Mount { - if len(container.SecretReferences) > 0 { - return &Mount{ - Source: container.SecretMountPath(), - Destination: containerSecretMountPath, - Writable: false, - } - } - - return nil -} - -// UnmountSecrets unmounts the local tmpfs for secrets -func (container *Container) UnmountSecrets() error { - if _, err := os.Stat(container.SecretMountPath()); err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - - return detachMounted(container.SecretMountPath()) -} - -// UpdateContainer updates configuration of a container. -func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error { - container.Lock() - defer container.Unlock() - - // update resources of container - resources := hostConfig.Resources - cResources := &container.HostConfig.Resources - if resources.BlkioWeight != 0 { - cResources.BlkioWeight = resources.BlkioWeight - } - if resources.CPUShares != 0 { - cResources.CPUShares = resources.CPUShares - } - if resources.CPUPeriod != 0 { - cResources.CPUPeriod = resources.CPUPeriod - } - if resources.CPUQuota != 0 { - cResources.CPUQuota = resources.CPUQuota - } - if resources.CpusetCpus != "" { - cResources.CpusetCpus = resources.CpusetCpus - } - if resources.CpusetMems != "" { - cResources.CpusetMems = resources.CpusetMems - } - if resources.Memory != 0 { - // if memory limit smaller than already set memoryswap limit and doesn't - // update the memoryswap limit, then error out. - if resources.Memory > cResources.MemorySwap && resources.MemorySwap == 0 { - return fmt.Errorf("Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same time") - } - cResources.Memory = resources.Memory - } - if resources.MemorySwap != 0 { - cResources.MemorySwap = resources.MemorySwap - } - if resources.MemoryReservation != 0 { - cResources.MemoryReservation = resources.MemoryReservation - } - if resources.KernelMemory != 0 { - cResources.KernelMemory = resources.KernelMemory - } - - // update HostConfig of container - if hostConfig.RestartPolicy.Name != "" { - if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() { - return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container") - } - container.HostConfig.RestartPolicy = hostConfig.RestartPolicy - } - - if err := container.ToDisk(); err != nil { - logrus.Errorf("Error saving updated container: %v", err) - return err - } - - return nil -} - -// DetachAndUnmount uses a detached mount on all mount destinations, then -// unmounts each volume normally. -// This is used from daemon/archive for `docker cp` -func (container *Container) DetachAndUnmount(volumeEventLog func(name, action string, attributes map[string]string)) error { - networkMounts := container.NetworkMounts() - mountPaths := make([]string, 0, len(container.MountPoints)+len(networkMounts)) - - for _, mntPoint := range container.MountPoints { - dest, err := container.GetResourcePath(mntPoint.Destination) - if err != nil { - logrus.Warnf("Failed to get volume destination path for container '%s' at '%s' while lazily unmounting: %v", container.ID, mntPoint.Destination, err) - continue - } - mountPaths = append(mountPaths, dest) - } - - for _, m := range networkMounts { - dest, err := container.GetResourcePath(m.Destination) - if err != nil { - logrus.Warnf("Failed to get volume destination path for container '%s' at '%s' while lazily unmounting: %v", container.ID, m.Destination, err) - continue - } - mountPaths = append(mountPaths, dest) - } - - for _, mountPath := range mountPaths { - if err := detachMounted(mountPath); err != nil { - logrus.Warnf("%s unmountVolumes: Failed to do lazy umount fo volume '%s': %v", container.ID, mountPath, err) - } - } - return container.UnmountVolumes(volumeEventLog) -} - -// copyExistingContents copies from the source to the destination and -// ensures the ownership is appropriately set. -func copyExistingContents(source, destination string) error { - volList, err := ioutil.ReadDir(source) - if err != nil { - return err - } - if len(volList) > 0 { - srcList, err := ioutil.ReadDir(destination) - if err != nil { - return err - } - if len(srcList) == 0 { - // If the source volume is empty, copies files from the root into the volume - if err := chrootarchive.CopyWithTar(source, destination); err != nil { - return err - } - } - } - return copyOwnership(source, destination) -} - -// copyOwnership copies the permissions and uid:gid of the source file -// to the destination file -func copyOwnership(source, destination string) error { - stat, err := system.Stat(source) - if err != nil { - return err - } - - if err := os.Chown(destination, int(stat.UID()), int(stat.GID())); err != nil { - return err - } - - return os.Chmod(destination, os.FileMode(stat.Mode())) -} - -// TmpfsMounts returns the list of tmpfs mounts -func (container *Container) TmpfsMounts() ([]Mount, error) { - var mounts []Mount - for dest, data := range container.HostConfig.Tmpfs { - mounts = append(mounts, Mount{ - Source: "tmpfs", - Destination: dest, - Data: data, - }) - } - for dest, mnt := range container.MountPoints { - if mnt.Type == mounttypes.TypeTmpfs { - data, err := volume.ConvertTmpfsOptions(mnt.Spec.TmpfsOptions, mnt.Spec.ReadOnly) - if err != nil { - return nil, err - } - mounts = append(mounts, Mount{ - Source: "tmpfs", - Destination: dest, - Data: data, - }) - } - } - return mounts, nil -} - -// cleanResourcePath cleans a resource path and prepares to combine with mnt path -func cleanResourcePath(path string) string { - return filepath.Join(string(os.PathSeparator), path) -} - -// EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network -func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool { - return false -} diff --git a/vendor/github.com/docker/docker/container/container_windows.go b/vendor/github.com/docker/docker/container/container_windows.go deleted file mode 100644 index 1025836..0000000 --- a/vendor/github.com/docker/docker/container/container_windows.go +++ /dev/null @@ -1,111 +0,0 @@ -// +build windows - -package container - -import ( - "fmt" - "os" - "path/filepath" - - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/utils" -) - -// Container holds fields specific to the Windows implementation. See -// CommonContainer for standard fields common to all containers. -type Container struct { - CommonContainer - - // Fields below here are platform specific. -} - -// ExitStatus provides exit reasons for a container. -type ExitStatus struct { - // The exit code with which the container exited. - ExitCode int -} - -// CreateDaemonEnvironment creates a new environment variable slice for this container. -func (container *Container) CreateDaemonEnvironment(_ bool, linkedEnv []string) []string { - // because the env on the container can override certain default values - // we need to replace the 'env' keys where they match and append anything - // else. - return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env) -} - -// UnmountIpcMounts unmounts Ipc related mounts. -// This is a NOOP on windows. -func (container *Container) UnmountIpcMounts(unmount func(pth string) error) { -} - -// IpcMounts returns the list of Ipc related mounts. -func (container *Container) IpcMounts() []Mount { - return nil -} - -// SecretMount returns the mount for the secret path -func (container *Container) SecretMount() *Mount { - return nil -} - -// UnmountSecrets unmounts the fs for secrets -func (container *Container) UnmountSecrets() error { - return nil -} - -// DetachAndUnmount unmounts all volumes. -// On Windows it only delegates to `UnmountVolumes` since there is nothing to -// force unmount. -func (container *Container) DetachAndUnmount(volumeEventLog func(name, action string, attributes map[string]string)) error { - return container.UnmountVolumes(volumeEventLog) -} - -// TmpfsMounts returns the list of tmpfs mounts -func (container *Container) TmpfsMounts() ([]Mount, error) { - var mounts []Mount - return mounts, nil -} - -// UpdateContainer updates configuration of a container -func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error { - container.Lock() - defer container.Unlock() - resources := hostConfig.Resources - if resources.BlkioWeight != 0 || resources.CPUShares != 0 || - resources.CPUPeriod != 0 || resources.CPUQuota != 0 || - resources.CpusetCpus != "" || resources.CpusetMems != "" || - resources.Memory != 0 || resources.MemorySwap != 0 || - resources.MemoryReservation != 0 || resources.KernelMemory != 0 { - return fmt.Errorf("Resource updating isn't supported on Windows") - } - // update HostConfig of container - if hostConfig.RestartPolicy.Name != "" { - if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() { - return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container") - } - container.HostConfig.RestartPolicy = hostConfig.RestartPolicy - } - return nil -} - -// cleanResourcePath cleans a resource path by removing C:\ syntax, and prepares -// to combine with a volume path -func cleanResourcePath(path string) string { - if len(path) >= 2 { - c := path[0] - if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') { - path = path[2:] - } - } - return filepath.Join(string(os.PathSeparator), path) -} - -// BuildHostnameFile writes the container's hostname file. -func (container *Container) BuildHostnameFile() error { - return nil -} - -// EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network -func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool { - return true -} diff --git a/vendor/github.com/docker/docker/container/health.go b/vendor/github.com/docker/docker/container/health.go deleted file mode 100644 index 6e3cd12..0000000 --- a/vendor/github.com/docker/docker/container/health.go +++ /dev/null @@ -1,49 +0,0 @@ -package container - -import ( - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" -) - -// Health holds the current container health-check state -type Health struct { - types.Health - stop chan struct{} // Write struct{} to stop the monitor -} - -// String returns a human-readable description of the health-check state -func (s *Health) String() string { - // This happens when the container is being shutdown and the monitor has stopped - // or the monitor has yet to be setup. - if s.stop == nil { - return types.Unhealthy - } - - switch s.Status { - case types.Starting: - return "health: starting" - default: // Healthy and Unhealthy are clear on their own - return s.Status - } -} - -// OpenMonitorChannel creates and returns a new monitor channel. If there already is one, -// it returns nil. -func (s *Health) OpenMonitorChannel() chan struct{} { - if s.stop == nil { - logrus.Debug("OpenMonitorChannel") - s.stop = make(chan struct{}) - return s.stop - } - return nil -} - -// CloseMonitorChannel closes any existing monitor channel. -func (s *Health) CloseMonitorChannel() { - if s.stop != nil { - logrus.Debug("CloseMonitorChannel: waiting for probe to stop") - close(s.stop) - s.stop = nil - logrus.Debug("CloseMonitorChannel done") - } -} diff --git a/vendor/github.com/docker/docker/container/history.go b/vendor/github.com/docker/docker/container/history.go deleted file mode 100644 index c80c2aa..0000000 --- a/vendor/github.com/docker/docker/container/history.go +++ /dev/null @@ -1,30 +0,0 @@ -package container - -import "sort" - -// History is a convenience type for storing a list of containers, -// sorted by creation date in descendant order. -type History []*Container - -// Len returns the number of containers in the history. -func (history *History) Len() int { - return len(*history) -} - -// Less compares two containers and returns true if the second one -// was created before the first one. -func (history *History) Less(i, j int) bool { - containers := *history - return containers[j].Created.Before(containers[i].Created) -} - -// Swap switches containers i and j positions in the history. -func (history *History) Swap(i, j int) { - containers := *history - containers[i], containers[j] = containers[j], containers[i] -} - -// sort orders the history by creation date in descendant order. -func (history *History) sort() { - sort.Sort(history) -} diff --git a/vendor/github.com/docker/docker/container/memory_store.go b/vendor/github.com/docker/docker/container/memory_store.go deleted file mode 100644 index 706407a..0000000 --- a/vendor/github.com/docker/docker/container/memory_store.go +++ /dev/null @@ -1,95 +0,0 @@ -package container - -import ( - "sync" -) - -// memoryStore implements a Store in memory. -type memoryStore struct { - s map[string]*Container - sync.RWMutex -} - -// NewMemoryStore initializes a new memory store. -func NewMemoryStore() Store { - return &memoryStore{ - s: make(map[string]*Container), - } -} - -// Add appends a new container to the memory store. -// It overrides the id if it existed before. -func (c *memoryStore) Add(id string, cont *Container) { - c.Lock() - c.s[id] = cont - c.Unlock() -} - -// Get returns a container from the store by id. -func (c *memoryStore) Get(id string) *Container { - var res *Container - c.RLock() - res = c.s[id] - c.RUnlock() - return res -} - -// Delete removes a container from the store by id. -func (c *memoryStore) Delete(id string) { - c.Lock() - delete(c.s, id) - c.Unlock() -} - -// List returns a sorted list of containers from the store. -// The containers are ordered by creation date. -func (c *memoryStore) List() []*Container { - containers := History(c.all()) - containers.sort() - return containers -} - -// Size returns the number of containers in the store. -func (c *memoryStore) Size() int { - c.RLock() - defer c.RUnlock() - return len(c.s) -} - -// First returns the first container found in the store by a given filter. -func (c *memoryStore) First(filter StoreFilter) *Container { - for _, cont := range c.all() { - if filter(cont) { - return cont - } - } - return nil -} - -// ApplyAll calls the reducer function with every container in the store. -// This operation is asynchronous in the memory store. -// NOTE: Modifications to the store MUST NOT be done by the StoreReducer. -func (c *memoryStore) ApplyAll(apply StoreReducer) { - wg := new(sync.WaitGroup) - for _, cont := range c.all() { - wg.Add(1) - go func(container *Container) { - apply(container) - wg.Done() - }(cont) - } - - wg.Wait() -} - -func (c *memoryStore) all() []*Container { - c.RLock() - containers := make([]*Container, 0, len(c.s)) - for _, cont := range c.s { - containers = append(containers, cont) - } - c.RUnlock() - return containers -} - -var _ Store = &memoryStore{} diff --git a/vendor/github.com/docker/docker/container/memory_store_test.go b/vendor/github.com/docker/docker/container/memory_store_test.go deleted file mode 100644 index f81738f..0000000 --- a/vendor/github.com/docker/docker/container/memory_store_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package container - -import ( - "testing" - "time" -) - -func TestNewMemoryStore(t *testing.T) { - s := NewMemoryStore() - m, ok := s.(*memoryStore) - if !ok { - t.Fatalf("store is not a memory store %v", s) - } - if m.s == nil { - t.Fatal("expected store map to not be nil") - } -} - -func TestAddContainers(t *testing.T) { - s := NewMemoryStore() - s.Add("id", NewBaseContainer("id", "root")) - if s.Size() != 1 { - t.Fatalf("expected store size 1, got %v", s.Size()) - } -} - -func TestGetContainer(t *testing.T) { - s := NewMemoryStore() - s.Add("id", NewBaseContainer("id", "root")) - c := s.Get("id") - if c == nil { - t.Fatal("expected container to not be nil") - } -} - -func TestDeleteContainer(t *testing.T) { - s := NewMemoryStore() - s.Add("id", NewBaseContainer("id", "root")) - s.Delete("id") - if c := s.Get("id"); c != nil { - t.Fatalf("expected container to be nil after removal, got %v", c) - } - - if s.Size() != 0 { - t.Fatalf("expected store size to be 0, got %v", s.Size()) - } -} - -func TestListContainers(t *testing.T) { - s := NewMemoryStore() - - cont := NewBaseContainer("id", "root") - cont.Created = time.Now() - cont2 := NewBaseContainer("id2", "root") - cont2.Created = time.Now().Add(24 * time.Hour) - - s.Add("id", cont) - s.Add("id2", cont2) - - list := s.List() - if len(list) != 2 { - t.Fatalf("expected list size 2, got %v", len(list)) - } - if list[0].ID != "id2" { - t.Fatalf("expected older container to be first, got %v", list[0].ID) - } -} - -func TestFirstContainer(t *testing.T) { - s := NewMemoryStore() - - s.Add("id", NewBaseContainer("id", "root")) - s.Add("id2", NewBaseContainer("id2", "root")) - - first := s.First(func(cont *Container) bool { - return cont.ID == "id2" - }) - - if first == nil { - t.Fatal("expected container to not be nil") - } - if first.ID != "id2" { - t.Fatalf("expected id2, got %v", first) - } -} - -func TestApplyAllContainer(t *testing.T) { - s := NewMemoryStore() - - s.Add("id", NewBaseContainer("id", "root")) - s.Add("id2", NewBaseContainer("id2", "root")) - - s.ApplyAll(func(cont *Container) { - if cont.ID == "id2" { - cont.ID = "newID" - } - }) - - cont := s.Get("id2") - if cont == nil { - t.Fatal("expected container to not be nil") - } - if cont.ID != "newID" { - t.Fatalf("expected newID, got %v", cont) - } -} diff --git a/vendor/github.com/docker/docker/container/monitor.go b/vendor/github.com/docker/docker/container/monitor.go deleted file mode 100644 index f05e72b..0000000 --- a/vendor/github.com/docker/docker/container/monitor.go +++ /dev/null @@ -1,46 +0,0 @@ -package container - -import ( - "time" - - "github.com/Sirupsen/logrus" -) - -const ( - loggerCloseTimeout = 10 * time.Second -) - -// Reset puts a container into a state where it can be restarted again. -func (container *Container) Reset(lock bool) { - if lock { - container.Lock() - defer container.Unlock() - } - - if err := container.CloseStreams(); err != nil { - logrus.Errorf("%s: %s", container.ID, err) - } - - // Re-create a brand new stdin pipe once the container exited - if container.Config.OpenStdin { - container.StreamConfig.NewInputPipes() - } - - if container.LogDriver != nil { - if container.LogCopier != nil { - exit := make(chan struct{}) - go func() { - container.LogCopier.Wait() - close(exit) - }() - select { - case <-time.After(loggerCloseTimeout): - logrus.Warn("Logger didn't exit in time: logs may be truncated") - case <-exit: - } - } - container.LogDriver.Close() - container.LogCopier = nil - container.LogDriver = nil - } -} diff --git a/vendor/github.com/docker/docker/container/mounts_unix.go b/vendor/github.com/docker/docker/container/mounts_unix.go deleted file mode 100644 index c52abed..0000000 --- a/vendor/github.com/docker/docker/container/mounts_unix.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !windows - -package container - -// Mount contains information for a mount operation. -type Mount struct { - Source string `json:"source"` - Destination string `json:"destination"` - Writable bool `json:"writable"` - Data string `json:"data"` - Propagation string `json:"mountpropagation"` -} diff --git a/vendor/github.com/docker/docker/container/mounts_windows.go b/vendor/github.com/docker/docker/container/mounts_windows.go deleted file mode 100644 index 01b327f..0000000 --- a/vendor/github.com/docker/docker/container/mounts_windows.go +++ /dev/null @@ -1,8 +0,0 @@ -package container - -// Mount contains information for a mount operation. -type Mount struct { - Source string `json:"source"` - Destination string `json:"destination"` - Writable bool `json:"writable"` -} diff --git a/vendor/github.com/docker/docker/container/state.go b/vendor/github.com/docker/docker/container/state.go deleted file mode 100644 index 4dd2ece..0000000 --- a/vendor/github.com/docker/docker/container/state.go +++ /dev/null @@ -1,343 +0,0 @@ -package container - -import ( - "fmt" - "sync" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/go-units" -) - -// State holds the current container state, and has methods to get and -// set the state. Container has an embed, which allows all of the -// functions defined against State to run against Container. -type State struct { - sync.Mutex - // FIXME: Why do we have both paused and running if a - // container cannot be paused and running at the same time? - Running bool - Paused bool - Restarting bool - OOMKilled bool - RemovalInProgress bool // Not need for this to be persistent on disk. - Dead bool - Pid int - ExitCodeValue int `json:"ExitCode"` - ErrorMsg string `json:"Error"` // contains last known error when starting the container - StartedAt time.Time - FinishedAt time.Time - waitChan chan struct{} - Health *Health -} - -// StateStatus is used to return an error type implementing both -// exec.ExitCode and error. -// This type is needed as State include a sync.Mutex field which make -// copying it unsafe. -type StateStatus struct { - exitCode int - error string -} - -func newStateStatus(ec int, err string) *StateStatus { - return &StateStatus{ - exitCode: ec, - error: err, - } -} - -// ExitCode returns current exitcode for the state. -func (ss *StateStatus) ExitCode() int { - return ss.exitCode -} - -// Error returns current error for the state. -func (ss *StateStatus) Error() string { - return ss.error -} - -// NewState creates a default state object with a fresh channel for state changes. -func NewState() *State { - return &State{ - waitChan: make(chan struct{}), - } -} - -// String returns a human-readable description of the state -func (s *State) String() string { - if s.Running { - if s.Paused { - return fmt.Sprintf("Up %s (Paused)", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt))) - } - if s.Restarting { - return fmt.Sprintf("Restarting (%d) %s ago", s.ExitCodeValue, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt))) - } - - if h := s.Health; h != nil { - return fmt.Sprintf("Up %s (%s)", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt)), h.String()) - } - - return fmt.Sprintf("Up %s", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt))) - } - - if s.RemovalInProgress { - return "Removal In Progress" - } - - if s.Dead { - return "Dead" - } - - if s.StartedAt.IsZero() { - return "Created" - } - - if s.FinishedAt.IsZero() { - return "" - } - - return fmt.Sprintf("Exited (%d) %s ago", s.ExitCodeValue, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt))) -} - -// HealthString returns a single string to describe health status. -func (s *State) HealthString() string { - if s.Health == nil { - return types.NoHealthcheck - } - - return s.Health.String() -} - -// IsValidHealthString checks if the provided string is a valid container health status or not. -func IsValidHealthString(s string) bool { - return s == types.Starting || - s == types.Healthy || - s == types.Unhealthy || - s == types.NoHealthcheck -} - -// StateString returns a single string to describe state -func (s *State) StateString() string { - if s.Running { - if s.Paused { - return "paused" - } - if s.Restarting { - return "restarting" - } - return "running" - } - - if s.RemovalInProgress { - return "removing" - } - - if s.Dead { - return "dead" - } - - if s.StartedAt.IsZero() { - return "created" - } - - return "exited" -} - -// IsValidStateString checks if the provided string is a valid container state or not. -func IsValidStateString(s string) bool { - if s != "paused" && - s != "restarting" && - s != "removing" && - s != "running" && - s != "dead" && - s != "created" && - s != "exited" { - return false - } - return true -} - -func wait(waitChan <-chan struct{}, timeout time.Duration) error { - if timeout < 0 { - <-waitChan - return nil - } - select { - case <-time.After(timeout): - return fmt.Errorf("Timed out: %v", timeout) - case <-waitChan: - return nil - } -} - -// WaitStop waits until state is stopped. If state already stopped it returns -// immediately. If you want wait forever you must supply negative timeout. -// Returns exit code, that was passed to SetStopped -func (s *State) WaitStop(timeout time.Duration) (int, error) { - s.Lock() - if !s.Running { - exitCode := s.ExitCodeValue - s.Unlock() - return exitCode, nil - } - waitChan := s.waitChan - s.Unlock() - if err := wait(waitChan, timeout); err != nil { - return -1, err - } - s.Lock() - defer s.Unlock() - return s.ExitCode(), nil -} - -// WaitWithContext waits for the container to stop. Optional context can be -// passed for canceling the request. -func (s *State) WaitWithContext(ctx context.Context) error { - // todo(tonistiigi): make other wait functions use this - s.Lock() - if !s.Running { - state := newStateStatus(s.ExitCode(), s.Error()) - defer s.Unlock() - if state.ExitCode() == 0 { - return nil - } - return state - } - waitChan := s.waitChan - s.Unlock() - select { - case <-waitChan: - s.Lock() - state := newStateStatus(s.ExitCode(), s.Error()) - s.Unlock() - if state.ExitCode() == 0 { - return nil - } - return state - case <-ctx.Done(): - return ctx.Err() - } -} - -// IsRunning returns whether the running flag is set. Used by Container to check whether a container is running. -func (s *State) IsRunning() bool { - s.Lock() - res := s.Running - s.Unlock() - return res -} - -// GetPID holds the process id of a container. -func (s *State) GetPID() int { - s.Lock() - res := s.Pid - s.Unlock() - return res -} - -// ExitCode returns current exitcode for the state. Take lock before if state -// may be shared. -func (s *State) ExitCode() int { - return s.ExitCodeValue -} - -// SetExitCode sets current exitcode for the state. Take lock before if state -// may be shared. -func (s *State) SetExitCode(ec int) { - s.ExitCodeValue = ec -} - -// SetRunning sets the state of the container to "running". -func (s *State) SetRunning(pid int, initial bool) { - s.ErrorMsg = "" - s.Running = true - s.Restarting = false - s.ExitCodeValue = 0 - s.Pid = pid - if initial { - s.StartedAt = time.Now().UTC() - } -} - -// SetStopped sets the container state to "stopped" without locking. -func (s *State) SetStopped(exitStatus *ExitStatus) { - s.Running = false - s.Paused = false - s.Restarting = false - s.Pid = 0 - s.FinishedAt = time.Now().UTC() - s.setFromExitStatus(exitStatus) - close(s.waitChan) // fire waiters for stop - s.waitChan = make(chan struct{}) -} - -// SetRestarting sets the container state to "restarting" without locking. -// It also sets the container PID to 0. -func (s *State) SetRestarting(exitStatus *ExitStatus) { - // we should consider the container running when it is restarting because of - // all the checks in docker around rm/stop/etc - s.Running = true - s.Restarting = true - s.Pid = 0 - s.FinishedAt = time.Now().UTC() - s.setFromExitStatus(exitStatus) - close(s.waitChan) // fire waiters for stop - s.waitChan = make(chan struct{}) -} - -// SetError sets the container's error state. This is useful when we want to -// know the error that occurred when container transits to another state -// when inspecting it -func (s *State) SetError(err error) { - s.ErrorMsg = err.Error() -} - -// IsPaused returns whether the container is paused or not. -func (s *State) IsPaused() bool { - s.Lock() - res := s.Paused - s.Unlock() - return res -} - -// IsRestarting returns whether the container is restarting or not. -func (s *State) IsRestarting() bool { - s.Lock() - res := s.Restarting - s.Unlock() - return res -} - -// SetRemovalInProgress sets the container state as being removed. -// It returns true if the container was already in that state. -func (s *State) SetRemovalInProgress() bool { - s.Lock() - defer s.Unlock() - if s.RemovalInProgress { - return true - } - s.RemovalInProgress = true - return false -} - -// ResetRemovalInProgress makes the RemovalInProgress state to false. -func (s *State) ResetRemovalInProgress() { - s.Lock() - s.RemovalInProgress = false - s.Unlock() -} - -// SetDead sets the container state to "dead" -func (s *State) SetDead() { - s.Lock() - s.Dead = true - s.Unlock() -} - -// Error returns current error for the state. -func (s *State) Error() string { - return s.ErrorMsg -} diff --git a/vendor/github.com/docker/docker/container/state_solaris.go b/vendor/github.com/docker/docker/container/state_solaris.go deleted file mode 100644 index 1229650..0000000 --- a/vendor/github.com/docker/docker/container/state_solaris.go +++ /dev/null @@ -1,7 +0,0 @@ -package container - -// setFromExitStatus is a platform specific helper function to set the state -// based on the ExitStatus structure. -func (s *State) setFromExitStatus(exitStatus *ExitStatus) { - s.ExitCodeValue = exitStatus.ExitCode -} diff --git a/vendor/github.com/docker/docker/container/state_test.go b/vendor/github.com/docker/docker/container/state_test.go deleted file mode 100644 index c9a7bb4..0000000 --- a/vendor/github.com/docker/docker/container/state_test.go +++ /dev/null @@ -1,113 +0,0 @@ -package container - -import ( - "sync/atomic" - "testing" - "time" - - "github.com/docker/docker/api/types" -) - -func TestIsValidHealthString(t *testing.T) { - contexts := []struct { - Health string - Expected bool - }{ - {types.Healthy, true}, - {types.Unhealthy, true}, - {types.Starting, true}, - {types.NoHealthcheck, true}, - {"fail", false}, - } - - for _, c := range contexts { - v := IsValidHealthString(c.Health) - if v != c.Expected { - t.Fatalf("Expected %t, but got %t", c.Expected, v) - } - } -} - -func TestStateRunStop(t *testing.T) { - s := NewState() - for i := 1; i < 3; i++ { // full lifecycle two times - s.Lock() - s.SetRunning(i+100, false) - s.Unlock() - - if !s.IsRunning() { - t.Fatal("State not running") - } - if s.Pid != i+100 { - t.Fatalf("Pid %v, expected %v", s.Pid, i+100) - } - if s.ExitCode() != 0 { - t.Fatalf("ExitCode %v, expected 0", s.ExitCode()) - } - - stopped := make(chan struct{}) - var exit int64 - go func() { - exitCode, _ := s.WaitStop(-1 * time.Second) - atomic.StoreInt64(&exit, int64(exitCode)) - close(stopped) - }() - s.Lock() - s.SetStopped(&ExitStatus{ExitCode: i}) - s.Unlock() - if s.IsRunning() { - t.Fatal("State is running") - } - if s.ExitCode() != i { - t.Fatalf("ExitCode %v, expected %v", s.ExitCode(), i) - } - if s.Pid != 0 { - t.Fatalf("Pid %v, expected 0", s.Pid) - } - select { - case <-time.After(100 * time.Millisecond): - t.Fatal("Stop callback doesn't fire in 100 milliseconds") - case <-stopped: - t.Log("Stop callback fired") - } - exitCode := int(atomic.LoadInt64(&exit)) - if exitCode != i { - t.Fatalf("ExitCode %v, expected %v", exitCode, i) - } - if exitCode, err := s.WaitStop(-1 * time.Second); err != nil || exitCode != i { - t.Fatalf("WaitStop returned exitCode: %v, err: %v, expected exitCode: %v, err: %v", exitCode, err, i, nil) - } - } -} - -func TestStateTimeoutWait(t *testing.T) { - s := NewState() - stopped := make(chan struct{}) - go func() { - s.WaitStop(100 * time.Millisecond) - close(stopped) - }() - select { - case <-time.After(200 * time.Millisecond): - t.Fatal("Stop callback doesn't fire in 200 milliseconds") - case <-stopped: - t.Log("Stop callback fired") - } - - s.Lock() - s.SetStopped(&ExitStatus{ExitCode: 1}) - s.Unlock() - - stopped = make(chan struct{}) - go func() { - s.WaitStop(100 * time.Millisecond) - close(stopped) - }() - select { - case <-time.After(200 * time.Millisecond): - t.Fatal("Stop callback doesn't fire in 100 milliseconds") - case <-stopped: - t.Log("Stop callback fired") - } - -} diff --git a/vendor/github.com/docker/docker/container/state_unix.go b/vendor/github.com/docker/docker/container/state_unix.go deleted file mode 100644 index a2fa5af..0000000 --- a/vendor/github.com/docker/docker/container/state_unix.go +++ /dev/null @@ -1,10 +0,0 @@ -// +build linux freebsd - -package container - -// setFromExitStatus is a platform specific helper function to set the state -// based on the ExitStatus structure. -func (s *State) setFromExitStatus(exitStatus *ExitStatus) { - s.ExitCodeValue = exitStatus.ExitCode - s.OOMKilled = exitStatus.OOMKilled -} diff --git a/vendor/github.com/docker/docker/container/state_windows.go b/vendor/github.com/docker/docker/container/state_windows.go deleted file mode 100644 index 1229650..0000000 --- a/vendor/github.com/docker/docker/container/state_windows.go +++ /dev/null @@ -1,7 +0,0 @@ -package container - -// setFromExitStatus is a platform specific helper function to set the state -// based on the ExitStatus structure. -func (s *State) setFromExitStatus(exitStatus *ExitStatus) { - s.ExitCodeValue = exitStatus.ExitCode -} diff --git a/vendor/github.com/docker/docker/container/store.go b/vendor/github.com/docker/docker/container/store.go deleted file mode 100644 index 042fb1a..0000000 --- a/vendor/github.com/docker/docker/container/store.go +++ /dev/null @@ -1,28 +0,0 @@ -package container - -// StoreFilter defines a function to filter -// container in the store. -type StoreFilter func(*Container) bool - -// StoreReducer defines a function to -// manipulate containers in the store -type StoreReducer func(*Container) - -// Store defines an interface that -// any container store must implement. -type Store interface { - // Add appends a new container to the store. - Add(string, *Container) - // Get returns a container from the store by the identifier it was stored with. - Get(string) *Container - // Delete removes a container from the store by the identifier it was stored with. - Delete(string) - // List returns a list of containers from the store. - List() []*Container - // Size returns the number of containers in the store. - Size() int - // First returns the first container found in the store by a given filter. - First(StoreFilter) *Container - // ApplyAll calls the reducer function with every container in the store. - ApplyAll(StoreReducer) -} diff --git a/vendor/github.com/docker/docker/container/stream/streams.go b/vendor/github.com/docker/docker/container/stream/streams.go deleted file mode 100644 index 79f366a..0000000 --- a/vendor/github.com/docker/docker/container/stream/streams.go +++ /dev/null @@ -1,143 +0,0 @@ -package stream - -import ( - "fmt" - "io" - "io/ioutil" - "strings" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/pkg/broadcaster" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/pools" -) - -// Config holds information about I/O streams managed together. -// -// config.StdinPipe returns a WriteCloser which can be used to feed data -// to the standard input of the streamConfig's active process. -// config.StdoutPipe and streamConfig.StderrPipe each return a ReadCloser -// which can be used to retrieve the standard output (and error) generated -// by the container's active process. The output (and error) are actually -// copied and delivered to all StdoutPipe and StderrPipe consumers, using -// a kind of "broadcaster". -type Config struct { - sync.WaitGroup - stdout *broadcaster.Unbuffered - stderr *broadcaster.Unbuffered - stdin io.ReadCloser - stdinPipe io.WriteCloser -} - -// NewConfig creates a stream config and initializes -// the standard err and standard out to new unbuffered broadcasters. -func NewConfig() *Config { - return &Config{ - stderr: new(broadcaster.Unbuffered), - stdout: new(broadcaster.Unbuffered), - } -} - -// Stdout returns the standard output in the configuration. -func (c *Config) Stdout() *broadcaster.Unbuffered { - return c.stdout -} - -// Stderr returns the standard error in the configuration. -func (c *Config) Stderr() *broadcaster.Unbuffered { - return c.stderr -} - -// Stdin returns the standard input in the configuration. -func (c *Config) Stdin() io.ReadCloser { - return c.stdin -} - -// StdinPipe returns an input writer pipe as an io.WriteCloser. -func (c *Config) StdinPipe() io.WriteCloser { - return c.stdinPipe -} - -// StdoutPipe creates a new io.ReadCloser with an empty bytes pipe. -// It adds this new out pipe to the Stdout broadcaster. -func (c *Config) StdoutPipe() io.ReadCloser { - bytesPipe := ioutils.NewBytesPipe() - c.stdout.Add(bytesPipe) - return bytesPipe -} - -// StderrPipe creates a new io.ReadCloser with an empty bytes pipe. -// It adds this new err pipe to the Stderr broadcaster. -func (c *Config) StderrPipe() io.ReadCloser { - bytesPipe := ioutils.NewBytesPipe() - c.stderr.Add(bytesPipe) - return bytesPipe -} - -// NewInputPipes creates new pipes for both standard inputs, Stdin and StdinPipe. -func (c *Config) NewInputPipes() { - c.stdin, c.stdinPipe = io.Pipe() -} - -// NewNopInputPipe creates a new input pipe that will silently drop all messages in the input. -func (c *Config) NewNopInputPipe() { - c.stdinPipe = ioutils.NopWriteCloser(ioutil.Discard) -} - -// CloseStreams ensures that the configured streams are properly closed. -func (c *Config) CloseStreams() error { - var errors []string - - if c.stdin != nil { - if err := c.stdin.Close(); err != nil { - errors = append(errors, fmt.Sprintf("error close stdin: %s", err)) - } - } - - if err := c.stdout.Clean(); err != nil { - errors = append(errors, fmt.Sprintf("error close stdout: %s", err)) - } - - if err := c.stderr.Clean(); err != nil { - errors = append(errors, fmt.Sprintf("error close stderr: %s", err)) - } - - if len(errors) > 0 { - return fmt.Errorf(strings.Join(errors, "\n")) - } - - return nil -} - -// CopyToPipe connects streamconfig with a libcontainerd.IOPipe -func (c *Config) CopyToPipe(iop libcontainerd.IOPipe) { - copyFunc := func(w io.Writer, r io.Reader) { - c.Add(1) - go func() { - if _, err := pools.Copy(w, r); err != nil { - logrus.Errorf("stream copy error: %+v", err) - } - c.Done() - }() - } - - if iop.Stdout != nil { - copyFunc(c.Stdout(), iop.Stdout) - } - if iop.Stderr != nil { - copyFunc(c.Stderr(), iop.Stderr) - } - - if stdin := c.Stdin(); stdin != nil { - if iop.Stdin != nil { - go func() { - pools.Copy(iop.Stdin, stdin) - if err := iop.Stdin.Close(); err != nil { - logrus.Warnf("failed to close stdin: %+v", err) - } - }() - } - } -} diff --git a/vendor/github.com/docker/docker/contrib/README.md b/vendor/github.com/docker/docker/contrib/README.md deleted file mode 100644 index 92b1d94..0000000 --- a/vendor/github.com/docker/docker/contrib/README.md +++ /dev/null @@ -1,4 +0,0 @@ -The `contrib` directory contains scripts, images, and other helpful things -which are not part of the core docker distribution. Please note that they -could be out of date, since they do not receive the same attention as the -rest of the repository. diff --git a/vendor/github.com/docker/docker/contrib/REVIEWERS b/vendor/github.com/docker/docker/contrib/REVIEWERS deleted file mode 100644 index 18e05a3..0000000 --- a/vendor/github.com/docker/docker/contrib/REVIEWERS +++ /dev/null @@ -1 +0,0 @@ -Tianon Gravi (@tianon) diff --git a/vendor/github.com/docker/docker/contrib/apparmor/main.go b/vendor/github.com/docker/docker/contrib/apparmor/main.go deleted file mode 100644 index f4a2978..0000000 --- a/vendor/github.com/docker/docker/contrib/apparmor/main.go +++ /dev/null @@ -1,56 +0,0 @@ -package main - -import ( - "fmt" - "log" - "os" - "path" - "text/template" - - "github.com/docker/docker/pkg/aaparser" -) - -type profileData struct { - Version int -} - -func main() { - if len(os.Args) < 2 { - log.Fatal("pass a filename to save the profile in.") - } - - // parse the arg - apparmorProfilePath := os.Args[1] - - version, err := aaparser.GetVersion() - if err != nil { - log.Fatal(err) - } - data := profileData{ - Version: version, - } - fmt.Printf("apparmor_parser is of version %+v\n", data) - - // parse the template - compiled, err := template.New("apparmor_profile").Parse(dockerProfileTemplate) - if err != nil { - log.Fatalf("parsing template failed: %v", err) - } - - // make sure /etc/apparmor.d exists - if err := os.MkdirAll(path.Dir(apparmorProfilePath), 0755); err != nil { - log.Fatal(err) - } - - f, err := os.OpenFile(apparmorProfilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) - if err != nil { - log.Fatal(err) - } - defer f.Close() - - if err := compiled.Execute(f, data); err != nil { - log.Fatalf("executing template failed: %v", err) - } - - fmt.Printf("created apparmor profile for version %+v at %q\n", data, apparmorProfilePath) -} diff --git a/vendor/github.com/docker/docker/contrib/apparmor/template.go b/vendor/github.com/docker/docker/contrib/apparmor/template.go deleted file mode 100644 index e5e1c8b..0000000 --- a/vendor/github.com/docker/docker/contrib/apparmor/template.go +++ /dev/null @@ -1,268 +0,0 @@ -package main - -const dockerProfileTemplate = `@{DOCKER_GRAPH_PATH}=/var/lib/docker - -profile /usr/bin/docker (attach_disconnected, complain) { - # Prevent following links to these files during container setup. - deny /etc/** mkl, - deny /dev/** kl, - deny /sys/** mkl, - deny /proc/** mkl, - - mount -> @{DOCKER_GRAPH_PATH}/**, - mount -> /, - mount -> /proc/**, - mount -> /sys/**, - mount -> /run/docker/netns/**, - mount -> /.pivot_root[0-9]*/, - - / r, - - umount, - pivot_root, -{{if ge .Version 209000}} - signal (receive) peer=@{profile_name}, - signal (receive) peer=unconfined, - signal (send), -{{end}} - network, - capability, - owner /** rw, - @{DOCKER_GRAPH_PATH}/** rwl, - @{DOCKER_GRAPH_PATH}/linkgraph.db k, - @{DOCKER_GRAPH_PATH}/network/files/boltdb.db k, - @{DOCKER_GRAPH_PATH}/network/files/local-kv.db k, - @{DOCKER_GRAPH_PATH}/[0-9]*.[0-9]*/linkgraph.db k, - - # For non-root client use: - /dev/urandom r, - /dev/null rw, - /dev/pts/[0-9]* rw, - /run/docker.sock rw, - /proc/** r, - /proc/[0-9]*/attr/exec w, - /sys/kernel/mm/hugepages/ r, - /etc/localtime r, - /etc/ld.so.cache r, - /etc/passwd r, - -{{if ge .Version 209000}} - ptrace peer=@{profile_name}, - ptrace (read) peer=docker-default, - deny ptrace (trace) peer=docker-default, - deny ptrace peer=/usr/bin/docker///bin/ps, -{{end}} - - /usr/lib/** rm, - /lib/** rm, - - /usr/bin/docker pix, - /sbin/xtables-multi rCx, - /sbin/iptables rCx, - /sbin/modprobe rCx, - /sbin/auplink rCx, - /sbin/mke2fs rCx, - /sbin/tune2fs rCx, - /sbin/blkid rCx, - /bin/kmod rCx, - /usr/bin/xz rCx, - /bin/ps rCx, - /bin/tar rCx, - /bin/cat rCx, - /sbin/zfs rCx, - /sbin/apparmor_parser rCx, - -{{if ge .Version 209000}} - # Transitions - change_profile -> docker-*, - change_profile -> unconfined, -{{end}} - - profile /bin/cat (complain) { - /etc/ld.so.cache r, - /lib/** rm, - /dev/null rw, - /proc r, - /bin/cat mr, - - # For reading in 'docker stats': - /proc/[0-9]*/net/dev r, - } - profile /bin/ps (complain) { - /etc/ld.so.cache r, - /etc/localtime r, - /etc/passwd r, - /etc/nsswitch.conf r, - /lib/** rm, - /proc/[0-9]*/** r, - /dev/null rw, - /bin/ps mr, - -{{if ge .Version 209000}} - # We don't need ptrace so we'll deny and ignore the error. - deny ptrace (read, trace), -{{end}} - - # Quiet dac_override denials - deny capability dac_override, - deny capability dac_read_search, - deny capability sys_ptrace, - - /dev/tty r, - /proc/stat r, - /proc/cpuinfo r, - /proc/meminfo r, - /proc/uptime r, - /sys/devices/system/cpu/online r, - /proc/sys/kernel/pid_max r, - /proc/ r, - /proc/tty/drivers r, - } - profile /sbin/iptables (complain) { -{{if ge .Version 209000}} - signal (receive) peer=/usr/bin/docker, -{{end}} - capability net_admin, - } - profile /sbin/auplink flags=(attach_disconnected, complain) { -{{if ge .Version 209000}} - signal (receive) peer=/usr/bin/docker, -{{end}} - capability sys_admin, - capability dac_override, - - @{DOCKER_GRAPH_PATH}/aufs/** rw, - @{DOCKER_GRAPH_PATH}/tmp/** rw, - # For user namespaces: - @{DOCKER_GRAPH_PATH}/[0-9]*.[0-9]*/** rw, - - /sys/fs/aufs/** r, - /lib/** rm, - /apparmor/.null r, - /dev/null rw, - /etc/ld.so.cache r, - /sbin/auplink rm, - /proc/fs/aufs/** rw, - /proc/[0-9]*/mounts rw, - } - profile /sbin/modprobe /bin/kmod (complain) { -{{if ge .Version 209000}} - signal (receive) peer=/usr/bin/docker, -{{end}} - capability sys_module, - /etc/ld.so.cache r, - /lib/** rm, - /dev/null rw, - /apparmor/.null rw, - /sbin/modprobe rm, - /bin/kmod rm, - /proc/cmdline r, - /sys/module/** r, - /etc/modprobe.d{/,/**} r, - } - # xz works via pipes, so we do not need access to the filesystem. - profile /usr/bin/xz (complain) { -{{if ge .Version 209000}} - signal (receive) peer=/usr/bin/docker, -{{end}} - /etc/ld.so.cache r, - /lib/** rm, - /usr/bin/xz rm, - deny /proc/** rw, - deny /sys/** rw, - } - profile /sbin/xtables-multi (attach_disconnected, complain) { - /etc/ld.so.cache r, - /lib/** rm, - /sbin/xtables-multi rm, - /apparmor/.null w, - /dev/null rw, - - /proc r, - - capability net_raw, - capability net_admin, - network raw, - } - profile /sbin/zfs (attach_disconnected, complain) { - file, - capability, - } - profile /sbin/mke2fs (complain) { - /sbin/mke2fs rm, - - /lib/** rm, - - /apparmor/.null w, - - /etc/ld.so.cache r, - /etc/mke2fs.conf r, - /etc/mtab r, - - /dev/dm-* rw, - /dev/urandom r, - /dev/null rw, - - /proc/swaps r, - /proc/[0-9]*/mounts r, - } - profile /sbin/tune2fs (complain) { - /sbin/tune2fs rm, - - /lib/** rm, - - /apparmor/.null w, - - /etc/blkid.conf r, - /etc/mtab r, - /etc/ld.so.cache r, - - /dev/null rw, - /dev/.blkid.tab r, - /dev/dm-* rw, - - /proc/swaps r, - /proc/[0-9]*/mounts r, - } - profile /sbin/blkid (complain) { - /sbin/blkid rm, - - /lib/** rm, - /apparmor/.null w, - - /etc/ld.so.cache r, - /etc/blkid.conf r, - - /dev/null rw, - /dev/.blkid.tab rl, - /dev/.blkid.tab* rwl, - /dev/dm-* r, - - /sys/devices/virtual/block/** r, - - capability mknod, - - mount -> @{DOCKER_GRAPH_PATH}/**, - } - profile /sbin/apparmor_parser (complain) { - /sbin/apparmor_parser rm, - - /lib/** rm, - - /etc/ld.so.cache r, - /etc/apparmor/** r, - /etc/apparmor.d/** r, - /etc/apparmor.d/cache/** w, - - /dev/null rw, - - /sys/kernel/security/apparmor/** r, - /sys/kernel/security/apparmor/.replace w, - - /proc/[0-9]*/mounts r, - /proc/sys/kernel/osrelease r, - /proc r, - - capability mac_admin, - } -}` diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/build.sh b/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/build.sh deleted file mode 100755 index 8271d9d..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -set -x -./generate.sh -for d in */; do - docker build -t "dockercore/builder-deb:$(basename "$d")" "$d" -done diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/generate.sh b/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/generate.sh deleted file mode 100755 index b5040b7..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/generate.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash -set -e - -# This file is used to auto-generate Dockerfiles for making debs via 'make deb' -# -# usage: ./generate.sh [versions] -# ie: ./generate.sh -# to update all Dockerfiles in this directory -# or: ./generate.sh ubuntu-trusty -# to only update ubuntu-trusty/Dockerfile -# or: ./generate.sh ubuntu-newversion -# to create a new folder and a Dockerfile within it -# -# Note: non-LTS versions are not guaranteed to work. - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -versions=( "$@" ) -if [ ${#versions[@]} -eq 0 ]; then - versions=( */ ) -fi -versions=( "${versions[@]%/}" ) - -for version in "${versions[@]}"; do - echo "${versions[@]}" - distro="${version%-*}" - suite="${version##*-}" - from="aarch64/${distro}:${suite}" - - mkdir -p "$version" - echo "$version -> FROM $from" - cat > "$version/Dockerfile" <<-EOF - # - # THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/aarch64/generate.sh"! - # - - FROM $from - - EOF - - dockerBuildTags='apparmor pkcs11 selinux' - runcBuildTags='apparmor selinux' - - # this list is sorted alphabetically; please keep it that way - packages=( - apparmor # for apparmor_parser for testing the profile - bash-completion # for bash-completion debhelper integration - btrfs-tools # for "btrfs/ioctl.h" (and "version.h" if possible) - build-essential # "essential for building Debian packages" - cmake # tini dep - curl ca-certificates # for downloading Go - debhelper # for easy ".deb" building - dh-apparmor # for apparmor debhelper - dh-systemd # for systemd debhelper integration - git # for "git commit" info in "docker -v" - libapparmor-dev # for "sys/apparmor.h" - libdevmapper-dev # for "libdevmapper.h" - libltdl-dev # for pkcs11 "ltdl.h" - libsqlite3-dev # for "sqlite3.h" - pkg-config # for detecting things like libsystemd-journal dynamically - vim-common # tini dep - ) - - case "$suite" in - trusty) - packages+=( libsystemd-journal-dev ) - # aarch64 doesn't have an official downloadable binary for go. - # And gccgo for trusty only includes Go 1.2 implementation which - # is too old to build current go source, fortunately trusty has - # golang-1.6-go package can be used as bootstrap. - packages+=( golang-1.6-go ) - ;; - xenial) - packages+=( libsystemd-dev ) - packages+=( golang-go libseccomp-dev) - - dockerBuildTags="$dockerBuildTags seccomp" - runcBuildTags="$runcBuildTags seccomp" - ;; - *) - echo "Unsupported distro:" $distro:$suite - rm -fr "$version" - exit 1 - ;; - esac - - # update and install packages - echo "RUN apt-get update && apt-get install -y ${packages[*]} --no-install-recommends && rm -rf /var/lib/apt/lists/*" >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - - case "$suite" in - trusty) - echo 'RUN update-alternatives --install /usr/bin/go go /usr/lib/go-1.6/bin/go 100' >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - ;; - *) - ;; - esac - - echo "# Install Go" >> "$version/Dockerfile" - echo "# aarch64 doesn't have official go binaries, so use the version of go installed from" >> "$version/Dockerfile" - echo "# the image to build go from source." >> "$version/Dockerfile" - - awk '$1 == "ENV" && $2 == "GO_VERSION" { print; exit }' ../../../../Dockerfile.aarch64 >> "$version/Dockerfile" - echo 'RUN mkdir /usr/src/go && curl -fsSL https://golang.org/dl/go${GO_VERSION}.src.tar.gz | tar -v -C /usr/src/go -xz --strip-components=1 \' >> "$version/Dockerfile" - echo ' && cd /usr/src/go/src \' >> "$version/Dockerfile" - echo ' && GOOS=linux GOARCH=arm64 GOROOT_BOOTSTRAP="$(go env GOROOT)" ./make.bash' >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - - echo 'ENV PATH $PATH:/usr/src/go/bin' >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - - echo "ENV AUTO_GOPATH 1" >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - - echo "ENV DOCKER_BUILDTAGS $dockerBuildTags" >> "$version/Dockerfile" - echo "ENV RUNC_BUILDTAGS $runcBuildTags" >> "$version/Dockerfile" -done diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/ubuntu-trusty/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/ubuntu-trusty/Dockerfile deleted file mode 100644 index d04860c..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/ubuntu-trusty/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/aarch64/generate.sh"! -# - -FROM aarch64/ubuntu:trusty - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common libsystemd-journal-dev golang-1.6-go --no-install-recommends && rm -rf /var/lib/apt/lists/* - -RUN update-alternatives --install /usr/bin/go go /usr/lib/go-1.6/bin/go 100 - -# Install Go -# aarch64 doesn't have official go binaries, so use the version of go installed from -# the image to build go from source. -ENV GO_VERSION 1.7.5 -RUN mkdir /usr/src/go && curl -fsSL https://golang.org/dl/go${GO_VERSION}.src.tar.gz | tar -v -C /usr/src/go -xz --strip-components=1 \ - && cd /usr/src/go/src \ - && GOOS=linux GOARCH=arm64 GOROOT_BOOTSTRAP="$(go env GOROOT)" ./make.bash - -ENV PATH $PATH:/usr/src/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 selinux -ENV RUNC_BUILDTAGS apparmor selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/ubuntu-xenial/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/ubuntu-xenial/Dockerfile deleted file mode 100644 index 3cd8442..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/aarch64/ubuntu-xenial/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/aarch64/generate.sh"! -# - -FROM aarch64/ubuntu:xenial - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common libsystemd-dev golang-go libseccomp-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -# Install Go -# aarch64 doesn't have official go binaries, so use the version of go installed from -# the image to build go from source. -ENV GO_VERSION 1.7.5 -RUN mkdir /usr/src/go && curl -fsSL https://golang.org/dl/go${GO_VERSION}.src.tar.gz | tar -v -C /usr/src/go -xz --strip-components=1 \ - && cd /usr/src/go/src \ - && GOOS=linux GOARCH=arm64 GOROOT_BOOTSTRAP="$(go env GOROOT)" ./make.bash - -ENV PATH $PATH:/usr/src/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 selinux seccomp -ENV RUNC_BUILDTAGS apparmor selinux seccomp diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/README.md b/vendor/github.com/docker/docker/contrib/builder/deb/amd64/README.md deleted file mode 100644 index 20a0ff1..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# `dockercore/builder-deb` - -This image's tags contain the dependencies for building Docker `.deb`s for each of the Debian-based platforms Docker targets. - -To add new tags, see [`contrib/builder/deb/amd64` in https://github.com/docker/docker](https://github.com/docker/docker/tree/master/contrib/builder/deb/amd64), specifically the `generate.sh` script, whose usage is described in a comment at the top of the file. diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/build.sh b/vendor/github.com/docker/docker/contrib/builder/deb/amd64/build.sh deleted file mode 100755 index 8271d9d..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -set -x -./generate.sh -for d in */; do - docker build -t "dockercore/builder-deb:$(basename "$d")" "$d" -done diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/debian-jessie/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/amd64/debian-jessie/Dockerfile deleted file mode 100644 index 42aaa56..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/debian-jessie/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/amd64/generate.sh"! -# - -FROM debian:jessie - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 selinux -ENV RUNC_BUILDTAGS apparmor selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/debian-stretch/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/amd64/debian-stretch/Dockerfile deleted file mode 100644 index c052be5..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/debian-stretch/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/amd64/generate.sh"! -# - -FROM debian:stretch - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libseccomp-dev libsqlite3-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS apparmor seccomp selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/debian-wheezy/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/amd64/debian-wheezy/Dockerfile deleted file mode 100644 index bcedb47..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/debian-wheezy/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/amd64/generate.sh"! -# - -FROM debian:wheezy-backports - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list.d/backports.list - -RUN apt-get update && apt-get install -y -t wheezy-backports btrfs-tools --no-install-recommends && rm -rf /var/lib/apt/lists/* -RUN apt-get update && apt-get install -y apparmor bash-completion build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 selinux -ENV RUNC_BUILDTAGS apparmor selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/generate.sh b/vendor/github.com/docker/docker/contrib/builder/deb/amd64/generate.sh deleted file mode 100755 index 765db5d..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/generate.sh +++ /dev/null @@ -1,149 +0,0 @@ -#!/bin/bash -set -e - -# usage: ./generate.sh [versions] -# ie: ./generate.sh -# to update all Dockerfiles in this directory -# or: ./generate.sh debian-jessie -# to only update debian-jessie/Dockerfile -# or: ./generate.sh debian-newversion -# to create a new folder and a Dockerfile within it - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -versions=( "$@" ) -if [ ${#versions[@]} -eq 0 ]; then - versions=( */ ) -fi -versions=( "${versions[@]%/}" ) - -for version in "${versions[@]}"; do - distro="${version%-*}" - suite="${version##*-}" - from="${distro}:${suite}" - - case "$from" in - debian:wheezy) - # add -backports, like our users have to - from+='-backports' - ;; - esac - - mkdir -p "$version" - echo "$version -> FROM $from" - cat > "$version/Dockerfile" <<-EOF - # - # THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/amd64/generate.sh"! - # - - FROM $from - EOF - - echo >> "$version/Dockerfile" - - if [ "$distro" = "debian" ]; then - cat >> "$version/Dockerfile" <<-'EOF' - # allow replacing httpredir or deb mirror - ARG APT_MIRROR=deb.debian.org - RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - EOF - - if [ "$suite" = "wheezy" ]; then - cat >> "$version/Dockerfile" <<-'EOF' - RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list.d/backports.list - EOF - fi - - echo "" >> "$version/Dockerfile" - fi - - extraBuildTags='pkcs11' - runcBuildTags= - - # this list is sorted alphabetically; please keep it that way - packages=( - apparmor # for apparmor_parser for testing the profile - bash-completion # for bash-completion debhelper integration - btrfs-tools # for "btrfs/ioctl.h" (and "version.h" if possible) - build-essential # "essential for building Debian packages" - cmake # tini dep - curl ca-certificates # for downloading Go - debhelper # for easy ".deb" building - dh-apparmor # for apparmor debhelper - dh-systemd # for systemd debhelper integration - git # for "git commit" info in "docker -v" - libapparmor-dev # for "sys/apparmor.h" - libdevmapper-dev # for "libdevmapper.h" - libltdl-dev # for pkcs11 "ltdl.h" - libseccomp-dev # for "seccomp.h" & "libseccomp.so" - libsqlite3-dev # for "sqlite3.h" - pkg-config # for detecting things like libsystemd-journal dynamically - vim-common # tini dep - ) - # packaging for "sd-journal.h" and libraries varies - case "$suite" in - precise|wheezy) ;; - jessie|trusty) packages+=( libsystemd-journal-dev );; - *) packages+=( libsystemd-dev );; - esac - - # debian wheezy & ubuntu precise do not have the right libseccomp libs - # debian jessie & ubuntu trusty have a libseccomp < 2.2.1 :( - case "$suite" in - precise|wheezy|jessie|trusty) - packages=( "${packages[@]/libseccomp-dev}" ) - runcBuildTags="apparmor selinux" - ;; - *) - extraBuildTags+=' seccomp' - runcBuildTags="apparmor seccomp selinux" - ;; - esac - - - if [ "$suite" = 'precise' ]; then - # precise has a few package issues - - # - dh-systemd doesn't exist at all - packages=( "${packages[@]/dh-systemd}" ) - - # - libdevmapper-dev is missing critical structs (too old) - packages=( "${packages[@]/libdevmapper-dev}" ) - extraBuildTags+=' exclude_graphdriver_devicemapper' - - # - btrfs-tools is missing "ioctl.h" (too old), so it's useless - # (since kernels on precise are old too, just skip btrfs entirely) - packages=( "${packages[@]/btrfs-tools}" ) - extraBuildTags+=' exclude_graphdriver_btrfs' - fi - - if [ "$suite" = 'wheezy' ]; then - # pull a couple packages from backports explicitly - # (build failures otherwise) - backportsPackages=( btrfs-tools ) - for pkg in "${backportsPackages[@]}"; do - packages=( "${packages[@]/$pkg}" ) - done - echo "RUN apt-get update && apt-get install -y -t $suite-backports ${backportsPackages[*]} --no-install-recommends && rm -rf /var/lib/apt/lists/*" >> "$version/Dockerfile" - fi - - echo "RUN apt-get update && apt-get install -y ${packages[*]} --no-install-recommends && rm -rf /var/lib/apt/lists/*" >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - awk '$1 == "ENV" && $2 == "GO_VERSION" { print; exit }' ../../../../Dockerfile >> "$version/Dockerfile" - echo 'RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local' >> "$version/Dockerfile" - echo 'ENV PATH $PATH:/usr/local/go/bin' >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - echo 'ENV AUTO_GOPATH 1' >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - # print build tags in alphabetical order - buildTags=$( echo "apparmor selinux $extraBuildTags" | xargs -n1 | sort -n | tr '\n' ' ' | sed -e 's/[[:space:]]*$//' ) - - echo "ENV DOCKER_BUILDTAGS $buildTags" >> "$version/Dockerfile" - echo "ENV RUNC_BUILDTAGS $runcBuildTags" >> "$version/Dockerfile" -done diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-precise/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-precise/Dockerfile deleted file mode 100644 index aa027f8..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-precise/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/amd64/generate.sh"! -# - -FROM ubuntu:precise - -RUN apt-get update && apt-get install -y apparmor bash-completion build-essential cmake curl ca-certificates debhelper dh-apparmor git libapparmor-dev libltdl-dev libsqlite3-dev pkg-config vim-common --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor exclude_graphdriver_btrfs exclude_graphdriver_devicemapper pkcs11 selinux -ENV RUNC_BUILDTAGS apparmor selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-trusty/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-trusty/Dockerfile deleted file mode 100644 index b03a853..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-trusty/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/amd64/generate.sh"! -# - -FROM ubuntu:trusty - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 selinux -ENV RUNC_BUILDTAGS apparmor selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-xenial/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-xenial/Dockerfile deleted file mode 100644 index af03f62..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-xenial/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/amd64/generate.sh"! -# - -FROM ubuntu:xenial - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libseccomp-dev libsqlite3-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS apparmor seccomp selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-yakkety/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-yakkety/Dockerfile deleted file mode 100644 index 5ac1edf..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/amd64/ubuntu-yakkety/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/amd64/generate.sh"! -# - -FROM ubuntu:yakkety - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libseccomp-dev libsqlite3-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS apparmor seccomp selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/debian-jessie/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/armhf/debian-jessie/Dockerfile deleted file mode 100644 index a4ac781..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/debian-jessie/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/armhf/generate.sh"! -# - -FROM armhf/debian:jessie - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 selinux -ENV RUNC_BUILDTAGS apparmor selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/generate.sh b/vendor/github.com/docker/docker/contrib/builder/deb/armhf/generate.sh deleted file mode 100755 index e110a21..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/generate.sh +++ /dev/null @@ -1,158 +0,0 @@ -#!/bin/bash -set -e - -# usage: ./generate.sh [versions] -# ie: ./generate.sh -# to update all Dockerfiles in this directory -# or: ./generate.sh debian-jessie -# to only update debian-jessie/Dockerfile -# or: ./generate.sh debian-newversion -# to create a new folder and a Dockerfile within it - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -versions=( "$@" ) -if [ ${#versions[@]} -eq 0 ]; then - versions=( */ ) -fi -versions=( "${versions[@]%/}" ) - -for version in "${versions[@]}"; do - distro="${version%-*}" - suite="${version##*-}" - from="${distro}:${suite}" - - case "$from" in - raspbian:jessie) - from="resin/rpi-raspbian:jessie" - ;; - *) - from="armhf/$from" - ;; - esac - - mkdir -p "$version" - echo "$version -> FROM $from" - cat > "$version/Dockerfile" <<-EOF - # - # THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/armhf/generate.sh"! - # - - FROM $from - EOF - - echo >> "$version/Dockerfile" - - if [[ "$distro" = "debian" || "$distro" = "raspbian" ]]; then - cat >> "$version/Dockerfile" <<-'EOF' - # allow replacing httpredir or deb mirror - ARG APT_MIRROR=deb.debian.org - RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - EOF - - if [ "$suite" = "wheezy" ]; then - cat >> "$version/Dockerfile" <<-'EOF' - RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list.d/backports.list - EOF - fi - - echo "" >> "$version/Dockerfile" - fi - - extraBuildTags='pkcs11' - runcBuildTags= - - # this list is sorted alphabetically; please keep it that way - packages=( - apparmor # for apparmor_parser for testing the profile - bash-completion # for bash-completion debhelper integration - btrfs-tools # for "btrfs/ioctl.h" (and "version.h" if possible) - build-essential # "essential for building Debian packages" - cmake # tini dep - curl ca-certificates # for downloading Go - debhelper # for easy ".deb" building - dh-apparmor # for apparmor debhelper - dh-systemd # for systemd debhelper integration - git # for "git commit" info in "docker -v" - libapparmor-dev # for "sys/apparmor.h" - libdevmapper-dev # for "libdevmapper.h" - libltdl-dev # for pkcs11 "ltdl.h" - libseccomp-dev # for "seccomp.h" & "libseccomp.so" - libsqlite3-dev # for "sqlite3.h" - pkg-config # for detecting things like libsystemd-journal dynamically - vim-common # tini dep - ) - # packaging for "sd-journal.h" and libraries varies - case "$suite" in - precise|wheezy) ;; - jessie|trusty) packages+=( libsystemd-journal-dev );; - *) packages+=( libsystemd-dev );; - esac - - # debian wheezy & ubuntu precise do not have the right libseccomp libs - # debian jessie & ubuntu trusty have a libseccomp < 2.2.1 :( - case "$suite" in - precise|wheezy|jessie|trusty) - packages=( "${packages[@]/libseccomp-dev}" ) - runcBuildTags="apparmor selinux" - ;; - *) - extraBuildTags+=' seccomp' - runcBuildTags="apparmor seccomp selinux" - ;; - esac - - - if [ "$suite" = 'precise' ]; then - # precise has a few package issues - - # - dh-systemd doesn't exist at all - packages=( "${packages[@]/dh-systemd}" ) - - # - libdevmapper-dev is missing critical structs (too old) - packages=( "${packages[@]/libdevmapper-dev}" ) - extraBuildTags+=' exclude_graphdriver_devicemapper' - - # - btrfs-tools is missing "ioctl.h" (too old), so it's useless - # (since kernels on precise are old too, just skip btrfs entirely) - packages=( "${packages[@]/btrfs-tools}" ) - extraBuildTags+=' exclude_graphdriver_btrfs' - fi - - if [ "$suite" = 'wheezy' ]; then - # pull a couple packages from backports explicitly - # (build failures otherwise) - backportsPackages=( btrfs-tools ) - for pkg in "${backportsPackages[@]}"; do - packages=( "${packages[@]/$pkg}" ) - done - echo "RUN apt-get update && apt-get install -y -t $suite-backports ${backportsPackages[*]} --no-install-recommends && rm -rf /var/lib/apt/lists/*" >> "$version/Dockerfile" - fi - - echo "RUN apt-get update && apt-get install -y ${packages[*]} --no-install-recommends && rm -rf /var/lib/apt/lists/*" >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - awk '$1 == "ENV" && $2 == "GO_VERSION" { print; exit }' ../../../../Dockerfile >> "$version/Dockerfile" - if [ "$distro" == 'raspbian' ]; - then - cat <> "$version/Dockerfile" -# GOARM is the ARM architecture version which is unrelated to the above Golang version -ENV GOARM 6 -EOF - fi - echo 'RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local' >> "$version/Dockerfile" - echo 'ENV PATH $PATH:/usr/local/go/bin' >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - echo 'ENV AUTO_GOPATH 1' >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - # print build tags in alphabetical order - buildTags=$( echo "apparmor selinux $extraBuildTags" | xargs -n1 | sort -n | tr '\n' ' ' | sed -e 's/[[:space:]]*$//' ) - - echo "ENV DOCKER_BUILDTAGS $buildTags" >> "$version/Dockerfile" - echo "ENV RUNC_BUILDTAGS $runcBuildTags" >> "$version/Dockerfile" -done diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/raspbian-jessie/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/armhf/raspbian-jessie/Dockerfile deleted file mode 100644 index 4dbfd09..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/raspbian-jessie/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/armhf/generate.sh"! -# - -FROM resin/rpi-raspbian:jessie - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -# GOARM is the ARM architecture version which is unrelated to the above Golang version -ENV GOARM 6 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 selinux -ENV RUNC_BUILDTAGS apparmor selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/ubuntu-trusty/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/armhf/ubuntu-trusty/Dockerfile deleted file mode 100644 index b36c1da..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/ubuntu-trusty/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/armhf/generate.sh"! -# - -FROM armhf/ubuntu:trusty - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 selinux -ENV RUNC_BUILDTAGS apparmor selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/ubuntu-xenial/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/armhf/ubuntu-xenial/Dockerfile deleted file mode 100644 index b5e55ad..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/ubuntu-xenial/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/armhf/generate.sh"! -# - -FROM armhf/ubuntu:xenial - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libseccomp-dev libsqlite3-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS apparmor seccomp selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/ubuntu-yakkety/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/armhf/ubuntu-yakkety/Dockerfile deleted file mode 100644 index 69c2e7f..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/armhf/ubuntu-yakkety/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/armhf/generate.sh"! -# - -FROM armhf/ubuntu:yakkety - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libseccomp-dev libsqlite3-dev pkg-config vim-common libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS apparmor seccomp selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/build.sh b/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/build.sh deleted file mode 100755 index 7d22e8c..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -set -x -./generate.sh -for d in */; do - docker build -t "dockercore/builder-deb:$(basename "$d")" "$d" -done diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/generate.sh b/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/generate.sh deleted file mode 100755 index 0e20b9c..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/generate.sh +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/bash -set -e - -# This file is used to auto-generate Dockerfiles for making debs via 'make deb' -# -# usage: ./generate.sh [versions] -# ie: ./generate.sh -# to update all Dockerfiles in this directory -# or: ./generate.sh ubuntu-xenial -# to only update ubuntu-xenial/Dockerfile -# or: ./generate.sh ubuntu-newversion -# to create a new folder and a Dockerfile within it - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -versions=( "$@" ) -if [ ${#versions[@]} -eq 0 ]; then - versions=( */ ) -fi -versions=( "${versions[@]%/}" ) - -for version in "${versions[@]}"; do - echo "${versions[@]}" - distro="${version%-*}" - suite="${version##*-}" - from="ppc64le/${distro}:${suite}" - - mkdir -p "$version" - echo "$version -> FROM $from" - cat > "$version/Dockerfile" <<-EOF - # - # THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/ppc64le/generate.sh"! - # - - FROM $from - - EOF - - extraBuildTags='pkcs11' - runcBuildTags= - - # this list is sorted alphabetically; please keep it that way - packages=( - apparmor # for apparmor_parser for testing the profile - bash-completion # for bash-completion debhelper integration - btrfs-tools # for "btrfs/ioctl.h" (and "version.h" if possible) - build-essential # "essential for building Debian packages" - cmake # tini dep - curl ca-certificates # for downloading Go - debhelper # for easy ".deb" building - dh-apparmor # for apparmor debhelper - dh-systemd # for systemd debhelper integration - git # for "git commit" info in "docker -v" - libapparmor-dev # for "sys/apparmor.h" - libdevmapper-dev # for "libdevmapper.h" - libltdl-dev # for pkcs11 "ltdl.h" - libsqlite3-dev # for "sqlite3.h" - pkg-config # for detecting things like libsystemd-journal dynamically - vim-common # tini dep - ) - - case "$suite" in - trusty) - packages+=( libsystemd-journal-dev ) - ;; - *) - # libseccomp isn't available until ubuntu xenial and is required for "seccomp.h" & "libseccomp.so" - packages+=( libseccomp-dev ) - packages+=( libsystemd-dev ) - ;; - esac - - # buildtags - case "$suite" in - # trusty has no seccomp package - trusty) - runcBuildTags="apparmor selinux" - ;; - # ppc64le support was backported into libseccomp 2.2.3-2, - # so enable seccomp by default - *) - extraBuildTags+=' seccomp' - runcBuildTags="apparmor seccomp selinux" - ;; - esac - - # update and install packages - echo "RUN apt-get update && apt-get install -y ${packages[*]} --no-install-recommends && rm -rf /var/lib/apt/lists/*" >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - - awk '$1 == "ENV" && $2 == "GO_VERSION" { print; exit }' ../../../../Dockerfile.ppc64le >> "$version/Dockerfile" - echo 'RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" | tar xzC /usr/local' >> "$version/Dockerfile" - echo 'ENV PATH $PATH:/usr/local/go/bin' >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - - echo 'ENV AUTO_GOPATH 1' >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - - # print build tags in alphabetical order - buildTags=$( echo "apparmor selinux $extraBuildTags" | xargs -n1 | sort -n | tr '\n' ' ' | sed -e 's/[[:space:]]*$//' ) - echo "ENV DOCKER_BUILDTAGS $buildTags" >> "$version/Dockerfile" - echo "ENV RUNC_BUILDTAGS $runcBuildTags" >> "$version/Dockerfile" -done diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/ubuntu-trusty/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/ubuntu-trusty/Dockerfile deleted file mode 100644 index 4182d68..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/ubuntu-trusty/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/ppc64le/generate.sh"! -# - -FROM ppc64le/ubuntu:trusty - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common libsystemd-journal-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 selinux -ENV RUNC_BUILDTAGS apparmor selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/ubuntu-xenial/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/ubuntu-xenial/Dockerfile deleted file mode 100644 index f1521db..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/ubuntu-xenial/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/ppc64le/generate.sh"! -# - -FROM ppc64le/ubuntu:xenial - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common libseccomp-dev libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS apparmor seccomp selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/ubuntu-yakkety/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/ubuntu-yakkety/Dockerfile deleted file mode 100644 index 4f8cc66..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/ppc64le/ubuntu-yakkety/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/ppc64le/generate.sh"! -# - -FROM ppc64le/ubuntu:yakkety - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libsqlite3-dev pkg-config vim-common libseccomp-dev libsystemd-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS apparmor seccomp selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/s390x/build.sh b/vendor/github.com/docker/docker/contrib/builder/deb/s390x/build.sh deleted file mode 100755 index 8271d9d..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/s390x/build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -set -x -./generate.sh -for d in */; do - docker build -t "dockercore/builder-deb:$(basename "$d")" "$d" -done diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/s390x/generate.sh b/vendor/github.com/docker/docker/contrib/builder/deb/s390x/generate.sh deleted file mode 100755 index b8f5860..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/s390x/generate.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash -set -e - -# This file is used to auto-generate Dockerfiles for making debs via 'make deb' -# -# usage: ./generate.sh [versions] -# ie: ./generate.sh -# to update all Dockerfiles in this directory -# or: ./generate.sh ubuntu-xenial -# to only update ubuntu-xenial/Dockerfile -# or: ./generate.sh ubuntu-newversion -# to create a new folder and a Dockerfile within it - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -versions=( "$@" ) -if [ ${#versions[@]} -eq 0 ]; then - versions=( */ ) -fi -versions=( "${versions[@]%/}" ) - -for version in "${versions[@]}"; do - echo "${versions[@]}" - distro="${version%-*}" - suite="${version##*-}" - from="s390x/${distro}:${suite}" - - mkdir -p "$version" - echo "$version -> FROM $from" - cat > "$version/Dockerfile" <<-EOF - # - # THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/s390x/generate.sh"! - # - - FROM $from - - EOF - - extraBuildTags='pkcs11' - runcBuildTags= - - # this list is sorted alphabetically; please keep it that way - packages=( - apparmor # for apparmor_parser for testing the profile - bash-completion # for bash-completion debhelper integration - btrfs-tools # for "btrfs/ioctl.h" (and "version.h" if possible) - build-essential # "essential for building Debian packages" - cmake # tini dep - curl ca-certificates # for downloading Go - debhelper # for easy ".deb" building - dh-apparmor # for apparmor debhelper - dh-systemd # for systemd debhelper integration - git # for "git commit" info in "docker -v" - libapparmor-dev # for "sys/apparmor.h" - libdevmapper-dev # for "libdevmapper.h" - libltdl-dev # for pkcs11 "ltdl.h" - libseccomp-dev # for "seccomp.h" & "libseccomp.so" - libsqlite3-dev # for "sqlite3.h" - pkg-config # for detecting things like libsystemd-journal dynamically - libsystemd-dev - vim-common # tini dep - ) - - case "$suite" in - # s390x needs libseccomp 2.3.1 - xenial) - # Ubuntu Xenial has libseccomp 2.2.3 - runcBuildTags="apparmor selinux" - ;; - *) - extraBuildTags+=' seccomp' - runcBuildTags="apparmor selinux seccomp" - ;; - esac - - # update and install packages - echo "RUN apt-get update && apt-get install -y ${packages[*]} --no-install-recommends && rm -rf /var/lib/apt/lists/*" >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - awk '$1 == "ENV" && $2 == "GO_VERSION" { print; exit }' ../../../../Dockerfile >> "$version/Dockerfile" - echo 'RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" | tar xzC /usr/local' >> "$version/Dockerfile" - echo 'ENV PATH $PATH:/usr/local/go/bin' >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - echo 'ENV AUTO_GOPATH 1' >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - # print build tags in alphabetical order - buildTags=$( echo "apparmor selinux $extraBuildTags" | xargs -n1 | sort -n | tr '\n' ' ' | sed -e 's/[[:space:]]*$//' ) - - echo "ENV DOCKER_BUILDTAGS $buildTags" >> "$version/Dockerfile" - echo "ENV RUNC_BUILDTAGS $runcBuildTags" >> "$version/Dockerfile" -done diff --git a/vendor/github.com/docker/docker/contrib/builder/deb/s390x/ubuntu-xenial/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/deb/s390x/ubuntu-xenial/Dockerfile deleted file mode 100644 index 6d7e4c5..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/deb/s390x/ubuntu-xenial/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/deb/s390x/generate.sh"! -# - -FROM s390x/ubuntu:xenial - -RUN apt-get update && apt-get install -y apparmor bash-completion btrfs-tools build-essential cmake curl ca-certificates debhelper dh-apparmor dh-systemd git libapparmor-dev libdevmapper-dev libltdl-dev libseccomp-dev libsqlite3-dev pkg-config libsystemd-dev vim-common --no-install-recommends && rm -rf /var/lib/apt/lists/* - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS apparmor pkcs11 selinux -ENV RUNC_BUILDTAGS apparmor selinux diff --git a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/README.md b/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/README.md deleted file mode 100644 index 5f2e888..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# `dockercore/builder-rpm` - -This image's tags contain the dependencies for building Docker `.rpm`s for each of the RPM-based platforms Docker targets. - -To add new tags, see [`contrib/builder/rpm/amd64` in https://github.com/docker/docker](https://github.com/docker/docker/tree/master/contrib/builder/rpm/amd64), specifically the `generate.sh` script, whose usage is described in a comment at the top of the file. diff --git a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/build.sh b/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/build.sh deleted file mode 100755 index 558f7ee..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -set -x -./generate.sh -for d in */; do - docker build -t "dockercore/builder-rpm:$(basename "$d")" "$d" -done diff --git a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/centos-7/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/centos-7/Dockerfile deleted file mode 100644 index 1f84163..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/centos-7/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/rpm/amd64/generate.sh"! -# - -FROM centos:7 - -RUN yum groupinstall -y "Development Tools" -RUN yum -y swap -- remove systemd-container systemd-container-libs -- install systemd systemd-libs -RUN yum install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel libtool-ltdl-devel pkgconfig selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim-common - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS seccomp selinux - diff --git a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/fedora-24/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/fedora-24/Dockerfile deleted file mode 100644 index af040c5..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/fedora-24/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/rpm/amd64/generate.sh"! -# - -FROM fedora:24 - -RUN dnf -y upgrade -RUN dnf install -y @development-tools fedora-packager -RUN dnf install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel libtool-ltdl-devel pkgconfig selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim-common - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS seccomp selinux - diff --git a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/fedora-25/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/fedora-25/Dockerfile deleted file mode 100644 index 98e57a9..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/fedora-25/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/rpm/amd64/generate.sh"! -# - -FROM fedora:25 - -RUN dnf -y upgrade -RUN dnf install -y @development-tools fedora-packager -RUN dnf install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel libtool-ltdl-devel pkgconfig selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim-common - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS seccomp selinux - diff --git a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/generate.sh b/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/generate.sh deleted file mode 100755 index 6f93afa..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/generate.sh +++ /dev/null @@ -1,189 +0,0 @@ -#!/bin/bash -set -e - -# usage: ./generate.sh [versions] -# ie: ./generate.sh -# to update all Dockerfiles in this directory -# or: ./generate.sh centos-7 -# to only update centos-7/Dockerfile -# or: ./generate.sh fedora-newversion -# to create a new folder and a Dockerfile within it - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -versions=( "$@" ) -if [ ${#versions[@]} -eq 0 ]; then - versions=( */ ) -fi -versions=( "${versions[@]%/}" ) - -for version in "${versions[@]}"; do - distro="${version%-*}" - suite="${version##*-}" - from="${distro}:${suite}" - installer=yum - - if [[ "$distro" == "fedora" ]]; then - installer=dnf - fi - if [[ "$distro" == "photon" ]]; then - installer=tdnf - fi - - mkdir -p "$version" - echo "$version -> FROM $from" - cat > "$version/Dockerfile" <<-EOF - # - # THIS FILE IS AUTOGENERATED; SEE "contrib/builder/rpm/amd64/generate.sh"! - # - - FROM $from - EOF - - echo >> "$version/Dockerfile" - - extraBuildTags='pkcs11' - runcBuildTags= - - case "$from" in - oraclelinux:6) - # We need a known version of the kernel-uek-devel headers to set CGO_CPPFLAGS, so grab the UEKR4 GA version - # This requires using yum-config-manager from yum-utils to enable the UEKR4 yum repo - echo "RUN yum install -y yum-utils && curl -o /etc/yum.repos.d/public-yum-ol6.repo http://yum.oracle.com/public-yum-ol6.repo && yum-config-manager -q --enable ol6_UEKR4" >> "$version/Dockerfile" - echo "RUN yum install -y kernel-uek-devel-4.1.12-32.el6uek" >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - ;; - fedora:*) - echo "RUN ${installer} -y upgrade" >> "$version/Dockerfile" - ;; - *) ;; - esac - - case "$from" in - centos:*) - # get "Development Tools" packages dependencies - echo 'RUN yum groupinstall -y "Development Tools"' >> "$version/Dockerfile" - - if [[ "$version" == "centos-7" ]]; then - echo 'RUN yum -y swap -- remove systemd-container systemd-container-libs -- install systemd systemd-libs' >> "$version/Dockerfile" - fi - ;; - oraclelinux:*) - # get "Development Tools" packages and dependencies - # we also need yum-utils for yum-config-manager to pull the latest repo file - echo 'RUN yum groupinstall -y "Development Tools"' >> "$version/Dockerfile" - ;; - opensuse:*) - # get rpm-build and curl packages and dependencies - echo 'RUN zypper --non-interactive install ca-certificates* curl gzip rpm-build' >> "$version/Dockerfile" - ;; - photon:*) - echo "RUN ${installer} install -y wget curl ca-certificates gzip make rpm-build sed gcc linux-api-headers glibc-devel binutils libseccomp libltdl-devel elfutils" >> "$version/Dockerfile" - ;; - *) - echo "RUN ${installer} install -y @development-tools fedora-packager" >> "$version/Dockerfile" - ;; - esac - - packages=( - btrfs-progs-devel # for "btrfs/ioctl.h" (and "version.h" if possible) - device-mapper-devel # for "libdevmapper.h" - glibc-static - libseccomp-devel # for "seccomp.h" & "libseccomp.so" - libselinux-devel # for "libselinux.so" - libtool-ltdl-devel # for pkcs11 "ltdl.h" - pkgconfig # for the pkg-config command - selinux-policy - selinux-policy-devel - sqlite-devel # for "sqlite3.h" - systemd-devel # for "sd-journal.h" and libraries - tar # older versions of dev-tools do not have tar - git # required for containerd and runc clone - cmake # tini build - vim-common # tini build - ) - - case "$from" in - oraclelinux:7) - # Enable the optional repository - packages=( --enablerepo=ol7_optional_latest "${packages[*]}" ) - ;; - esac - - case "$from" in - oraclelinux:6) - # doesn't use systemd, doesn't have a devel package for it - packages=( "${packages[@]/systemd-devel}" ) - ;; - esac - - # opensuse & oraclelinx:6 do not have the right libseccomp libs - case "$from" in - opensuse:*|oraclelinux:6) - packages=( "${packages[@]/libseccomp-devel}" ) - runcBuildTags="selinux" - ;; - *) - extraBuildTags+=' seccomp' - runcBuildTags="seccomp selinux" - ;; - esac - - case "$from" in - opensuse:*) - packages=( "${packages[@]/btrfs-progs-devel/libbtrfs-devel}" ) - packages=( "${packages[@]/pkgconfig/pkg-config}" ) - packages=( "${packages[@]/vim-common/vim}" ) - if [[ "$from" == "opensuse:13."* ]]; then - packages+=( systemd-rpm-macros ) - fi - - # use zypper - echo "RUN zypper --non-interactive install ${packages[*]}" >> "$version/Dockerfile" - ;; - photon:*) - packages=( "${packages[@]/pkgconfig/pkg-config}" ) - echo "RUN ${installer} install -y ${packages[*]}" >> "$version/Dockerfile" - ;; - *) - echo "RUN ${installer} install -y ${packages[*]}" >> "$version/Dockerfile" - ;; - esac - - echo >> "$version/Dockerfile" - - - awk '$1 == "ENV" && $2 == "GO_VERSION" { print; exit }' ../../../../Dockerfile >> "$version/Dockerfile" - echo 'RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local' >> "$version/Dockerfile" - echo 'ENV PATH $PATH:/usr/local/go/bin' >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - echo 'ENV AUTO_GOPATH 1' >> "$version/Dockerfile" - - echo >> "$version/Dockerfile" - - # print build tags in alphabetical order - buildTags=$( echo "selinux $extraBuildTags" | xargs -n1 | sort -n | tr '\n' ' ' | sed -e 's/[[:space:]]*$//' ) - - echo "ENV DOCKER_BUILDTAGS $buildTags" >> "$version/Dockerfile" - echo "ENV RUNC_BUILDTAGS $runcBuildTags" >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - - case "$from" in - oraclelinux:6) - # We need to set the CGO_CPPFLAGS environment to use the updated UEKR4 headers with all the userns stuff. - # The ordering is very important and should not be changed. - echo 'ENV CGO_CPPFLAGS -D__EXPORTED_HEADERS__ \' >> "$version/Dockerfile" - echo ' -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/arch/x86/include/generated/uapi \' >> "$version/Dockerfile" - echo ' -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/arch/x86/include/uapi \' >> "$version/Dockerfile" - echo ' -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include/generated/uapi \' >> "$version/Dockerfile" - echo ' -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include/uapi \' >> "$version/Dockerfile" - echo ' -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include' >> "$version/Dockerfile" - echo >> "$version/Dockerfile" - ;; - *) ;; - esac - - -done diff --git a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/opensuse-13.2/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/opensuse-13.2/Dockerfile deleted file mode 100644 index addd431..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/opensuse-13.2/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/rpm/amd64/generate.sh"! -# - -FROM opensuse:13.2 - -RUN zypper --non-interactive install ca-certificates* curl gzip rpm-build -RUN zypper --non-interactive install libbtrfs-devel device-mapper-devel glibc-static libselinux-devel libtool-ltdl-devel pkg-config selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim systemd-rpm-macros - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS pkcs11 selinux -ENV RUNC_BUILDTAGS selinux - diff --git a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/oraclelinux-6/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/oraclelinux-6/Dockerfile deleted file mode 100644 index c34d304..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/oraclelinux-6/Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/rpm/amd64/generate.sh"! -# - -FROM oraclelinux:6 - -RUN yum install -y yum-utils && curl -o /etc/yum.repos.d/public-yum-ol6.repo http://yum.oracle.com/public-yum-ol6.repo && yum-config-manager -q --enable ol6_UEKR4 -RUN yum install -y kernel-uek-devel-4.1.12-32.el6uek - -RUN yum groupinstall -y "Development Tools" -RUN yum install -y btrfs-progs-devel device-mapper-devel glibc-static libselinux-devel libtool-ltdl-devel pkgconfig selinux-policy selinux-policy-devel sqlite-devel tar git cmake vim-common - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS pkcs11 selinux -ENV RUNC_BUILDTAGS selinux - -ENV CGO_CPPFLAGS -D__EXPORTED_HEADERS__ \ - -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/arch/x86/include/generated/uapi \ - -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/arch/x86/include/uapi \ - -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include/generated/uapi \ - -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include/uapi \ - -I/usr/src/kernels/4.1.12-32.el6uek.x86_64/include - diff --git a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/oraclelinux-7/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/oraclelinux-7/Dockerfile deleted file mode 100644 index 378536b..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/oraclelinux-7/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/rpm/amd64/generate.sh"! -# - -FROM oraclelinux:7 - -RUN yum groupinstall -y "Development Tools" -RUN yum install -y --enablerepo=ol7_optional_latest btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel libtool-ltdl-devel pkgconfig selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim-common - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS seccomp selinux - diff --git a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/photon-1.0/Dockerfile b/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/photon-1.0/Dockerfile deleted file mode 100644 index b77d573..0000000 --- a/vendor/github.com/docker/docker/contrib/builder/rpm/amd64/photon-1.0/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -# -# THIS FILE IS AUTOGENERATED; SEE "contrib/builder/rpm/amd64/generate.sh"! -# - -FROM photon:1.0 - -RUN tdnf install -y wget curl ca-certificates gzip make rpm-build sed gcc linux-api-headers glibc-devel binutils libseccomp libltdl-devel elfutils -RUN tdnf install -y btrfs-progs-devel device-mapper-devel glibc-static libseccomp-devel libselinux-devel libtool-ltdl-devel pkg-config selinux-policy selinux-policy-devel sqlite-devel systemd-devel tar git cmake vim-common - -ENV GO_VERSION 1.7.5 -RUN curl -fSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" | tar xzC /usr/local -ENV PATH $PATH:/usr/local/go/bin - -ENV AUTO_GOPATH 1 - -ENV DOCKER_BUILDTAGS pkcs11 seccomp selinux -ENV RUNC_BUILDTAGS seccomp selinux - diff --git a/vendor/github.com/docker/docker/contrib/check-config.sh b/vendor/github.com/docker/docker/contrib/check-config.sh deleted file mode 100755 index d07e4ce..0000000 --- a/vendor/github.com/docker/docker/contrib/check-config.sh +++ /dev/null @@ -1,354 +0,0 @@ -#!/usr/bin/env bash -set -e - -EXITCODE=0 - -# bits of this were adapted from lxc-checkconfig -# see also https://github.com/lxc/lxc/blob/lxc-1.0.2/src/lxc/lxc-checkconfig.in - -possibleConfigs=( - '/proc/config.gz' - "/boot/config-$(uname -r)" - "/usr/src/linux-$(uname -r)/.config" - '/usr/src/linux/.config' -) - -if [ $# -gt 0 ]; then - CONFIG="$1" -else - : ${CONFIG:="${possibleConfigs[0]}"} -fi - -if ! command -v zgrep &> /dev/null; then - zgrep() { - zcat "$2" | grep "$1" - } -fi - -kernelVersion="$(uname -r)" -kernelMajor="${kernelVersion%%.*}" -kernelMinor="${kernelVersion#$kernelMajor.}" -kernelMinor="${kernelMinor%%.*}" - -is_set() { - zgrep "CONFIG_$1=[y|m]" "$CONFIG" > /dev/null -} -is_set_in_kernel() { - zgrep "CONFIG_$1=y" "$CONFIG" > /dev/null -} -is_set_as_module() { - zgrep "CONFIG_$1=m" "$CONFIG" > /dev/null -} - -color() { - local codes=() - if [ "$1" = 'bold' ]; then - codes=( "${codes[@]}" '1' ) - shift - fi - if [ "$#" -gt 0 ]; then - local code= - case "$1" in - # see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors - black) code=30 ;; - red) code=31 ;; - green) code=32 ;; - yellow) code=33 ;; - blue) code=34 ;; - magenta) code=35 ;; - cyan) code=36 ;; - white) code=37 ;; - esac - if [ "$code" ]; then - codes=( "${codes[@]}" "$code" ) - fi - fi - local IFS=';' - echo -en '\033['"${codes[*]}"'m' -} -wrap_color() { - text="$1" - shift - color "$@" - echo -n "$text" - color reset - echo -} - -wrap_good() { - echo "$(wrap_color "$1" white): $(wrap_color "$2" green)" -} -wrap_bad() { - echo "$(wrap_color "$1" bold): $(wrap_color "$2" bold red)" -} -wrap_warning() { - wrap_color >&2 "$*" red -} - -check_flag() { - if is_set_in_kernel "$1"; then - wrap_good "CONFIG_$1" 'enabled' - elif is_set_as_module "$1"; then - wrap_good "CONFIG_$1" 'enabled (as module)' - else - wrap_bad "CONFIG_$1" 'missing' - EXITCODE=1 - fi -} - -check_flags() { - for flag in "$@"; do - echo -n "- "; check_flag "$flag" - done -} - -check_command() { - if command -v "$1" >/dev/null 2>&1; then - wrap_good "$1 command" 'available' - else - wrap_bad "$1 command" 'missing' - EXITCODE=1 - fi -} - -check_device() { - if [ -c "$1" ]; then - wrap_good "$1" 'present' - else - wrap_bad "$1" 'missing' - EXITCODE=1 - fi -} - -check_distro_userns() { - source /etc/os-release 2>/dev/null || /bin/true - if [[ "${ID}" =~ ^(centos|rhel)$ && "${VERSION_ID}" =~ ^7 ]]; then - # this is a CentOS7 or RHEL7 system - grep -q "user_namespace.enable=1" /proc/cmdline || { - # no user namespace support enabled - wrap_bad " (RHEL7/CentOS7" "User namespaces disabled; add 'user_namespace.enable=1' to boot command line)" - EXITCODE=1 - } - fi -} - -if [ ! -e "$CONFIG" ]; then - wrap_warning "warning: $CONFIG does not exist, searching other paths for kernel config ..." - for tryConfig in "${possibleConfigs[@]}"; do - if [ -e "$tryConfig" ]; then - CONFIG="$tryConfig" - break - fi - done - if [ ! -e "$CONFIG" ]; then - wrap_warning "error: cannot find kernel config" - wrap_warning " try running this script again, specifying the kernel config:" - wrap_warning " CONFIG=/path/to/kernel/.config $0 or $0 /path/to/kernel/.config" - exit 1 - fi -fi - -wrap_color "info: reading kernel config from $CONFIG ..." white -echo - -echo 'Generally Necessary:' - -echo -n '- ' -cgroupSubsystemDir="$(awk '/[, ](cpu|cpuacct|cpuset|devices|freezer|memory)[, ]/ && $3 == "cgroup" { print $2 }' /proc/mounts | head -n1)" -cgroupDir="$(dirname "$cgroupSubsystemDir")" -if [ -d "$cgroupDir/cpu" -o -d "$cgroupDir/cpuacct" -o -d "$cgroupDir/cpuset" -o -d "$cgroupDir/devices" -o -d "$cgroupDir/freezer" -o -d "$cgroupDir/memory" ]; then - echo "$(wrap_good 'cgroup hierarchy' 'properly mounted') [$cgroupDir]" -else - if [ "$cgroupSubsystemDir" ]; then - echo "$(wrap_bad 'cgroup hierarchy' 'single mountpoint!') [$cgroupSubsystemDir]" - else - echo "$(wrap_bad 'cgroup hierarchy' 'nonexistent??')" - fi - EXITCODE=1 - echo " $(wrap_color '(see https://github.com/tianon/cgroupfs-mount)' yellow)" -fi - -if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then - echo -n '- ' - if command -v apparmor_parser &> /dev/null; then - echo "$(wrap_good 'apparmor' 'enabled and tools installed')" - else - echo "$(wrap_bad 'apparmor' 'enabled, but apparmor_parser missing')" - echo -n ' ' - if command -v apt-get &> /dev/null; then - echo "$(wrap_color '(use "apt-get install apparmor" to fix this)')" - elif command -v yum &> /dev/null; then - echo "$(wrap_color '(your best bet is "yum install apparmor-parser")')" - else - echo "$(wrap_color '(look for an "apparmor" package for your distribution)')" - fi - EXITCODE=1 - fi -fi - -flags=( - NAMESPACES {NET,PID,IPC,UTS}_NS - CGROUPS CGROUP_CPUACCT CGROUP_DEVICE CGROUP_FREEZER CGROUP_SCHED CPUSETS MEMCG - KEYS - VETH BRIDGE BRIDGE_NETFILTER - NF_NAT_IPV4 IP_NF_FILTER IP_NF_TARGET_MASQUERADE - NETFILTER_XT_MATCH_{ADDRTYPE,CONNTRACK,IPVS} - IP_NF_NAT NF_NAT NF_NAT_NEEDED - - # required for bind-mounting /dev/mqueue into containers - POSIX_MQUEUE -) -check_flags "${flags[@]}" -if [ "$kernelMajor" -lt 4 ] || [ "$kernelMajor" -eq 4 -a "$kernelMinor" -lt 8 ]; then - check_flags DEVPTS_MULTIPLE_INSTANCES -fi - -echo - -echo 'Optional Features:' -{ - check_flags USER_NS - check_distro_userns -} -{ - check_flags SECCOMP -} -{ - check_flags CGROUP_PIDS -} -{ - check_flags MEMCG_SWAP MEMCG_SWAP_ENABLED - if is_set MEMCG_SWAP && ! is_set MEMCG_SWAP_ENABLED; then - echo " $(wrap_color '(note that cgroup swap accounting is not enabled in your kernel config, you can enable it by setting boot option "swapaccount=1")' bold black)" - fi -} -{ - if is_set LEGACY_VSYSCALL_NATIVE; then - echo -n "- "; wrap_bad "CONFIG_LEGACY_VSYSCALL_NATIVE" 'enabled' - echo " $(wrap_color '(dangerous, provides an ASLR-bypassing target with usable ROP gadgets.)' bold black)" - elif is_set LEGACY_VSYSCALL_EMULATE; then - echo -n "- "; wrap_good "CONFIG_LEGACY_VSYSCALL_EMULATE" 'enabled' - elif is_set LEGACY_VSYSCALL_NONE; then - echo -n "- "; wrap_bad "CONFIG_LEGACY_VSYSCALL_NONE" 'enabled' - echo " $(wrap_color '(containers using eglibc <= 2.13 will not work. Switch to' bold black)" - echo " $(wrap_color ' "CONFIG_VSYSCALL_[NATIVE|EMULATE]" or use "vsyscall=[native|emulate]"' bold black)" - echo " $(wrap_color ' on kernel command line. Note that this will disable ASLR for the,' bold black)" - echo " $(wrap_color ' VDSO which may assist in exploiting security vulnerabilities.)' bold black)" - # else Older kernels (prior to 3dc33bd30f3e, released in v4.40-rc1) do - # not have these LEGACY_VSYSCALL options and are effectively - # LEGACY_VSYSCALL_EMULATE. Even older kernels are presumably - # effectively LEGACY_VSYSCALL_NATIVE. - fi -} - -if [ "$kernelMajor" -lt 4 ] || [ "$kernelMajor" -eq 4 -a "$kernelMinor" -le 5 ]; then - check_flags MEMCG_KMEM -fi - -if [ "$kernelMajor" -lt 3 ] || [ "$kernelMajor" -eq 3 -a "$kernelMinor" -le 18 ]; then - check_flags RESOURCE_COUNTERS -fi - -if [ "$kernelMajor" -lt 3 ] || [ "$kernelMajor" -eq 3 -a "$kernelMinor" -le 13 ]; then - netprio=NETPRIO_CGROUP -else - netprio=CGROUP_NET_PRIO -fi - -flags=( - BLK_CGROUP BLK_DEV_THROTTLING IOSCHED_CFQ CFQ_GROUP_IOSCHED - CGROUP_PERF - CGROUP_HUGETLB - NET_CLS_CGROUP $netprio - CFS_BANDWIDTH FAIR_GROUP_SCHED RT_GROUP_SCHED - IP_VS - IP_VS_NFCT - IP_VS_RR -) -check_flags "${flags[@]}" - -if ! is_set EXT4_USE_FOR_EXT2; then - check_flags EXT3_FS EXT3_FS_XATTR EXT3_FS_POSIX_ACL EXT3_FS_SECURITY - if ! is_set EXT3_FS || ! is_set EXT3_FS_XATTR || ! is_set EXT3_FS_POSIX_ACL || ! is_set EXT3_FS_SECURITY; then - echo " $(wrap_color '(enable these ext3 configs if you are using ext3 as backing filesystem)' bold black)" - fi -fi - -check_flags EXT4_FS EXT4_FS_POSIX_ACL EXT4_FS_SECURITY -if ! is_set EXT4_FS || ! is_set EXT4_FS_POSIX_ACL || ! is_set EXT4_FS_SECURITY; then - if is_set EXT4_USE_FOR_EXT2; then - echo " $(wrap_color 'enable these ext4 configs if you are using ext3 or ext4 as backing filesystem' bold black)" - else - echo " $(wrap_color 'enable these ext4 configs if you are using ext4 as backing filesystem' bold black)" - fi -fi - -echo '- Network Drivers:' -echo ' - "'$(wrap_color 'overlay' blue)'":' -check_flags VXLAN | sed 's/^/ /' -echo ' Optional (for encrypted networks):' -check_flags CRYPTO CRYPTO_AEAD CRYPTO_GCM CRYPTO_SEQIV CRYPTO_GHASH \ - XFRM XFRM_USER XFRM_ALGO INET_ESP INET_XFRM_MODE_TRANSPORT | sed 's/^/ /' -echo ' - "'$(wrap_color 'ipvlan' blue)'":' -check_flags IPVLAN | sed 's/^/ /' -echo ' - "'$(wrap_color 'macvlan' blue)'":' -check_flags MACVLAN DUMMY | sed 's/^/ /' - -# only fail if no storage drivers available -CODE=${EXITCODE} -EXITCODE=0 -STORAGE=1 - -echo '- Storage Drivers:' -echo ' - "'$(wrap_color 'aufs' blue)'":' -check_flags AUFS_FS | sed 's/^/ /' -if ! is_set AUFS_FS && grep -q aufs /proc/filesystems; then - echo " $(wrap_color '(note that some kernels include AUFS patches but not the AUFS_FS flag)' bold black)" -fi -[ "$EXITCODE" = 0 ] && STORAGE=0 -EXITCODE=0 - -echo ' - "'$(wrap_color 'btrfs' blue)'":' -check_flags BTRFS_FS | sed 's/^/ /' -check_flags BTRFS_FS_POSIX_ACL | sed 's/^/ /' -[ "$EXITCODE" = 0 ] && STORAGE=0 -EXITCODE=0 - -echo ' - "'$(wrap_color 'devicemapper' blue)'":' -check_flags BLK_DEV_DM DM_THIN_PROVISIONING | sed 's/^/ /' -[ "$EXITCODE" = 0 ] && STORAGE=0 -EXITCODE=0 - -echo ' - "'$(wrap_color 'overlay' blue)'":' -check_flags OVERLAY_FS | sed 's/^/ /' -[ "$EXITCODE" = 0 ] && STORAGE=0 -EXITCODE=0 - -echo ' - "'$(wrap_color 'zfs' blue)'":' -echo -n " - "; check_device /dev/zfs -echo -n " - "; check_command zfs -echo -n " - "; check_command zpool -[ "$EXITCODE" = 0 ] && STORAGE=0 -EXITCODE=0 - -EXITCODE=$CODE -[ "$STORAGE" = 1 ] && EXITCODE=1 - -echo - -check_limit_over() -{ - if [ $(cat "$1") -le "$2" ]; then - wrap_bad "- $1" "$(cat $1)" - wrap_color " This should be set to at least $2, for example set: sysctl -w kernel/keys/root_maxkeys=1000000" bold black - EXITCODE=1 - else - wrap_good "- $1" "$(cat $1)" - fi -} - -echo 'Limits:' -check_limit_over /proc/sys/kernel/keys/root_maxkeys 10000 -echo - -exit $EXITCODE diff --git a/vendor/github.com/docker/docker/contrib/completion/REVIEWERS b/vendor/github.com/docker/docker/contrib/completion/REVIEWERS deleted file mode 100644 index 03ee2dd..0000000 --- a/vendor/github.com/docker/docker/contrib/completion/REVIEWERS +++ /dev/null @@ -1,2 +0,0 @@ -Tianon Gravi (@tianon) -Jessie Frazelle (@jfrazelle) diff --git a/vendor/github.com/docker/docker/contrib/completion/bash/docker b/vendor/github.com/docker/docker/contrib/completion/bash/docker deleted file mode 100644 index 7ea5d9a..0000000 --- a/vendor/github.com/docker/docker/contrib/completion/bash/docker +++ /dev/null @@ -1,4282 +0,0 @@ -#!/bin/bash -# -# bash completion file for core docker commands -# -# This script provides completion of: -# - commands and their options -# - container ids and names -# - image repos and tags -# - filepaths -# -# To enable the completions either: -# - place this file in /etc/bash_completion.d -# or -# - copy this file to e.g. ~/.docker-completion.sh and add the line -# below to your .bashrc after bash completion features are loaded -# . ~/.docker-completion.sh -# -# Configuration: -# -# For several commands, the amount of completions can be configured by -# setting environment variables. -# -# DOCKER_COMPLETION_SHOW_CONTAINER_IDS -# DOCKER_COMPLETION_SHOW_NETWORK_IDS -# DOCKER_COMPLETION_SHOW_NODE_IDS -# DOCKER_COMPLETION_SHOW_PLUGIN_IDS -# DOCKER_COMPLETION_SHOW_SECRET_IDS -# DOCKER_COMPLETION_SHOW_SERVICE_IDS -# "no" - Show names only (default) -# "yes" - Show names and ids -# -# You can tailor completion for the "events", "history", "inspect", "run", -# "rmi" and "save" commands by settings the following environment -# variables: -# -# DOCKER_COMPLETION_SHOW_IMAGE_IDS -# "none" - Show names only (default) -# "non-intermediate" - Show names and ids, but omit intermediate image IDs -# "all" - Show names and ids, including intermediate image IDs -# -# DOCKER_COMPLETION_SHOW_TAGS -# "yes" - include tags in completion options (default) -# "no" - don't include tags in completion options - -# -# Note: -# Currently, the completions will not work if the docker daemon is not -# bound to the default communication port/socket -# If the docker daemon is using a unix socket for communication your user -# must have access to the socket for the completions to function correctly -# -# Note for developers: -# Please arrange options sorted alphabetically by long name with the short -# options immediately following their corresponding long form. -# This order should be applied to lists, alternatives and code blocks. - -__docker_previous_extglob_setting=$(shopt -p extglob) -shopt -s extglob - -__docker_q() { - docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@" -} - -# __docker_containers returns a list of containers. Additional options to -# `docker ps` may be specified in order to filter the list, e.g. -# `__docker_containers --filter status=running` -# By default, only names are returned. -# Set DOCKER_COMPLETION_SHOW_CONTAINER_IDS=yes to also complete IDs. -# An optional first option `--id|--name` may be used to limit the -# output to the IDs or names of matching items. This setting takes -# precedence over the environment setting. -__docker_containers() { - local format - if [ "$1" = "--id" ] ; then - format='{{.ID}}' - shift - elif [ "$1" = "--name" ] ; then - format='{{.Names}}' - shift - elif [ "${DOCKER_COMPLETION_SHOW_CONTAINER_IDS}" = yes ] ; then - format='{{.ID}} {{.Names}}' - else - format='{{.Names}}' - fi - __docker_q ps --format "$format" "$@" -} - -# __docker_complete_containers applies completion of containers based on the current -# value of `$cur` or the value of the optional first option `--cur`, if given. -# Additional filters may be appended, see `__docker_containers`. -__docker_complete_containers() { - local current="$cur" - if [ "$1" = "--cur" ] ; then - current="$2" - shift 2 - fi - COMPREPLY=( $(compgen -W "$(__docker_containers "$@")" -- "$current") ) -} - -__docker_complete_containers_all() { - __docker_complete_containers "$@" --all -} - -__docker_complete_containers_running() { - __docker_complete_containers "$@" --filter status=running -} - -__docker_complete_containers_stopped() { - __docker_complete_containers "$@" --filter status=exited -} - -__docker_complete_containers_unpauseable() { - __docker_complete_containers "$@" --filter status=paused -} - -__docker_complete_container_names() { - local containers=( $(__docker_q ps -aq --no-trunc) ) - local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") ) - names=( "${names[@]#/}" ) # trim off the leading "/" from the container names - COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") ) -} - -__docker_complete_container_ids() { - local containers=( $(__docker_q ps -aq) ) - COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") ) -} - -__docker_images() { - local images_args="" - - case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in - all) - images_args="--no-trunc -a" - ;; - non-intermediate) - images_args="--no-trunc" - ;; - esac - - local repo_print_command - if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then - repo_print_command='print $1; print $1":"$2' - else - repo_print_command='print $1' - fi - - local awk_script - case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in - all|non-intermediate) - awk_script='NR>1 { print $3; if ($1 != "") { '"$repo_print_command"' } }' - ;; - none|*) - awk_script='NR>1 && $1 != "" { '"$repo_print_command"' }' - ;; - esac - - __docker_q images $images_args | awk "$awk_script" | grep -v '$' -} - -__docker_complete_images() { - COMPREPLY=( $(compgen -W "$(__docker_images)" -- "$cur") ) - __ltrim_colon_completions "$cur" -} - -__docker_complete_image_repos() { - local repos="$(__docker_q images | awk 'NR>1 && $1 != "" { print $1 }')" - COMPREPLY=( $(compgen -W "$repos" -- "$cur") ) -} - -__docker_complete_image_repos_and_tags() { - local reposAndTags="$(__docker_q images | awk 'NR>1 && $1 != "" { print $1; print $1":"$2 }')" - COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") ) - __ltrim_colon_completions "$cur" -} - -# __docker_networks returns a list of all networks. Additional options to -# `docker network ls` may be specified in order to filter the list, e.g. -# `__docker_networks --filter type=custom` -# By default, only names are returned. -# Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete IDs. -# An optional first option `--id|--name` may be used to limit the -# output to the IDs or names of matching items. This setting takes -# precedence over the environment setting. -__docker_networks() { - local format - if [ "$1" = "--id" ] ; then - format='{{.ID}}' - shift - elif [ "$1" = "--name" ] ; then - format='{{.Name}}' - shift - elif [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] ; then - format='{{.ID}} {{.Name}}' - else - format='{{.Name}}' - fi - __docker_q network ls --format "$format" "$@" -} - -# __docker_complete_networks applies completion of networks based on the current -# value of `$cur` or the value of the optional first option `--cur`, if given. -# Additional filters may be appended, see `__docker_networks`. -__docker_complete_networks() { - local current="$cur" - if [ "$1" = "--cur" ] ; then - current="$2" - shift 2 - fi - COMPREPLY=( $(compgen -W "$(__docker_networks "$@")" -- "$current") ) -} - -__docker_complete_containers_in_network() { - local containers=$(__docker_q network inspect -f '{{range $i, $c := .Containers}}{{$i}} {{$c.Name}} {{end}}' "$1") - COMPREPLY=( $(compgen -W "$containers" -- "$cur") ) -} - -# __docker_volumes returns a list of all volumes. Additional options to -# `docker volume ls` may be specified in order to filter the list, e.g. -# `__docker_volumes --filter dangling=true` -# Because volumes do not have IDs, this function does not distinguish between -# IDs and names. -__docker_volumes() { - __docker_q volume ls -q "$@" -} - -# __docker_complete_volumes applies completion of volumes based on the current -# value of `$cur` or the value of the optional first option `--cur`, if given. -# Additional filters may be appended, see `__docker_volumes`. -__docker_complete_volumes() { - local current="$cur" - if [ "$1" = "--cur" ] ; then - current="$2" - shift 2 - fi - COMPREPLY=( $(compgen -W "$(__docker_volumes "$@")" -- "$current") ) -} - -# __docker_plugins_bundled returns a list of all plugins of a given type. -# The type has to be specified with the mandatory option `--type`. -# Valid types are: Network, Volume, Authorization. -# Completions may be added or removed with `--add` and `--remove` -# This function only deals with plugins that come bundled with Docker. -# For plugins managed by `docker plugin`, see `__docker_plugins_installed`. -__docker_plugins_bundled() { - local type add=() remove=() - while true ; do - case "$1" in - --type) - type="$2" - shift 2 - ;; - --add) - add+=("$2") - shift 2 - ;; - --remove) - remove+=("$2") - shift 2 - ;; - *) - break - ;; - esac - done - - local plugins=($(__docker_q info | sed -n "/^Plugins/,/^[^ ]/s/ $type: //p")) - for del in "${remove[@]}" ; do - plugins=(${plugins[@]/$del/}) - done - echo "${plugins[@]} ${add[@]}" -} - -# __docker_complete_plugins_bundled applies completion of plugins based on the current -# value of `$cur` or the value of the optional first option `--cur`, if given. -# The plugin type has to be specified with the next option `--type`. -# This function only deals with plugins that come bundled with Docker. -# For completion of plugins managed by `docker plugin`, see -# `__docker_complete_plugins_installed`. -__docker_complete_plugins_bundled() { - local current="$cur" - if [ "$1" = "--cur" ] ; then - current="$2" - shift 2 - fi - COMPREPLY=( $(compgen -W "$(__docker_plugins_bundled "$@")" -- "$current") ) -} - -# __docker_plugins_installed returns a list of all plugins that were installed with -# the Docker plugin API. -# By default, only names are returned. -# Set DOCKER_COMPLETION_SHOW_PLUGIN_IDS=yes to also complete IDs. -# For built-in pugins, see `__docker_plugins_bundled`. -__docker_plugins_installed() { - local fields - if [ "$DOCKER_COMPLETION_SHOW_PLUGIN_IDS" = yes ] ; then - fields='$1,$2' - else - fields='$2' - fi - __docker_q plugin ls | awk "NR>1 {print $fields}" -} - -# __docker_complete_plugins_installed applies completion of plugins that were installed -# with the Docker plugin API, based on the current value of `$cur` or the value of -# the optional first option `--cur`, if given. -# For completion of built-in pugins, see `__docker_complete_plugins_bundled`. -__docker_complete_plugins_installed() { - local current="$cur" - if [ "$1" = "--cur" ] ; then - current="$2" - shift 2 - fi - COMPREPLY=( $(compgen -W "$(__docker_plugins_installed "$@")" -- "$current") ) -} - -__docker_runtimes() { - __docker_q info | sed -n 's/^Runtimes: \(.*\)/\1/p' -} - -__docker_complete_runtimes() { - COMPREPLY=( $(compgen -W "$(__docker_runtimes)" -- "$cur") ) -} - -# __docker_secrets returns a list of all secrets. -# By default, only names of secrets are returned. -# Set DOCKER_COMPLETION_SHOW_SECRET_IDS=yes to also complete IDs of secrets. -__docker_secrets() { - local fields='$2' # default: name only - [ "${DOCKER_COMPLETION_SHOW_SECRET_IDS}" = yes ] && fields='$1,$2' # ID and name - - __docker_q secret ls | awk "NR>1 {print $fields}" -} - -# __docker_complete_secrets applies completion of secrets based on the current value -# of `$cur`. -__docker_complete_secrets() { - COMPREPLY=( $(compgen -W "$(__docker_secrets)" -- "$cur") ) -} - -# __docker_stacks returns a list of all stacks. -__docker_stacks() { - __docker_q stack ls | awk 'NR>1 {print $1}' -} - -# __docker_complete_stacks applies completion of stacks based on the current value -# of `$cur` or the value of the optional first option `--cur`, if given. -__docker_complete_stacks() { - local current="$cur" - if [ "$1" = "--cur" ] ; then - current="$2" - shift 2 - fi - COMPREPLY=( $(compgen -W "$(__docker_stacks "$@")" -- "$current") ) -} - -# __docker_nodes returns a list of all nodes. Additional options to -# `docker node ls` may be specified in order to filter the list, e.g. -# `__docker_nodes --filter role=manager` -# By default, only node names are returned. -# Set DOCKER_COMPLETION_SHOW_NODE_IDS=yes to also complete node IDs. -# An optional first option `--id|--name` may be used to limit the -# output to the IDs or names of matching items. This setting takes -# precedence over the environment setting. -# Completions may be added with `--add`, e.g. `--add self`. -__docker_nodes() { - local add=() - local fields='$2' # default: node name only - [ "${DOCKER_COMPLETION_SHOW_NODE_IDS}" = yes ] && fields='$1,$2' # ID and name - - while true ; do - case "$1" in - --id) - fields='$1' # IDs only - shift - ;; - --name) - fields='$2' # names only - shift - ;; - --add) - add+=("$2") - shift 2 - ;; - *) - break - ;; - esac - done - - echo $(__docker_q node ls "$@" | tr -d '*' | awk "NR>1 {print $fields}") "${add[@]}" -} - -# __docker_complete_nodes applies completion of nodes based on the current -# value of `$cur` or the value of the optional first option `--cur`, if given. -# Additional filters may be appended, see `__docker_nodes`. -__docker_complete_nodes() { - local current="$cur" - if [ "$1" = "--cur" ] ; then - current="$2" - shift 2 - fi - COMPREPLY=( $(compgen -W "$(__docker_nodes "$@")" -- "$current") ) -} - -__docker_complete_nodes_plus_self() { - __docker_complete_nodes --add self "$@" -} - -# __docker_services returns a list of all services. Additional options to -# `docker service ls` may be specified in order to filter the list, e.g. -# `__docker_services --filter name=xxx` -# By default, only node names are returned. -# Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete IDs. -# An optional first option `--id|--name` may be used to limit the -# output to the IDs or names of matching items. This setting takes -# precedence over the environment setting. -__docker_services() { - local fields='$2' # default: service name only - [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name - - if [ "$1" = "--id" ] ; then - fields='$1' # IDs only - shift - elif [ "$1" = "--name" ] ; then - fields='$2' # names only - shift - fi - __docker_q service ls "$@" | awk "NR>1 {print $fields}" -} - -# __docker_complete_services applies completion of services based on the current -# value of `$cur` or the value of the optional first option `--cur`, if given. -# Additional filters may be appended, see `__docker_services`. -__docker_complete_services() { - local current="$cur" - if [ "$1" = "--cur" ] ; then - current="$2" - shift 2 - fi - COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") ) -} - -# __docker_append_to_completions appends the word passed as an argument to every -# word in `$COMPREPLY`. -# Normally you do this with `compgen -S` while generating the completions. -# This function allows you to append a suffix later. It allows you to use -# the __docker_complete_XXX functions in cases where you need a suffix. -__docker_append_to_completions() { - COMPREPLY=( ${COMPREPLY[@]/%/"$1"} ) -} - -# __docker_is_experimental tests whether the currently configured Docker daemon -# runs in experimental mode. If so, the function exits with 0 (true). -# Otherwise, or if the result cannot be determined, the exit value is 1 (false). -__docker_is_experimental() { - [ "$(__docker_q version -f '{{.Server.Experimental}}')" = "true" ] -} - -# __docker_pos_first_nonflag finds the position of the first word that is neither -# option nor an option's argument. If there are options that require arguments, -# you should pass a glob describing those options, e.g. "--option1|-o|--option2" -# Use this function to restrict completions to exact positions after the argument list. -__docker_pos_first_nonflag() { - local argument_flags=$1 - - local counter=$((${subcommand_pos:-${command_pos}} + 1)) - while [ $counter -le $cword ]; do - if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then - (( counter++ )) - # eat "=" in case of --option=arg syntax - [ "${words[$counter]}" = "=" ] && (( counter++ )) - else - case "${words[$counter]}" in - -*) - ;; - *) - break - ;; - esac - fi - - # Bash splits words at "=", retaining "=" as a word, examples: - # "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words - while [ "${words[$counter + 1]}" = "=" ] ; do - counter=$(( counter + 2)) - done - - (( counter++ )) - done - - echo $counter -} - -# __docker_map_key_of_current_option returns `key` if we are currently completing the -# value of a map option (`key=value`) which matches the extglob given as an argument. -# This function is needed for key-specific completions. -__docker_map_key_of_current_option() { - local glob="$1" - - local key glob_pos - if [ "$cur" = "=" ] ; then # key= case - key="$prev" - glob_pos=$((cword - 2)) - elif [[ $cur == *=* ]] ; then # key=value case (OSX) - key=${cur%=*} - glob_pos=$((cword - 1)) - elif [ "$prev" = "=" ] ; then - key=${words[$cword - 2]} # key=value case - glob_pos=$((cword - 3)) - else - return - fi - - [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax - - [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key" -} - -# __docker_value_of_option returns the value of the first option matching `option_glob`. -# Valid values for `option_glob` are option names like `--log-level` and globs like -# `--log-level|-l` -# Only positions between the command and the current word are considered. -__docker_value_of_option() { - local option_extglob=$(__docker_to_extglob "$1") - - local counter=$((command_pos + 1)) - while [ $counter -lt $cword ]; do - case ${words[$counter]} in - $option_extglob ) - echo ${words[$counter + 1]} - break - ;; - esac - (( counter++ )) - done -} - -# __docker_to_alternatives transforms a multiline list of strings into a single line -# string with the words separated by `|`. -# This is used to prepare arguments to __docker_pos_first_nonflag(). -__docker_to_alternatives() { - local parts=( $1 ) - local IFS='|' - echo "${parts[*]}" -} - -# __docker_to_extglob transforms a multiline list of options into an extglob pattern -# suitable for use in case statements. -__docker_to_extglob() { - local extglob=$( __docker_to_alternatives "$1" ) - echo "@($extglob)" -} - -# __docker_subcommands processes subcommands -# Locates the first occurrence of any of the subcommands contained in the -# first argument. In case of a match, calls the corresponding completion -# function and returns 0. -# If no match is found, 1 is returned. The calling function can then -# continue processing its completion. -# -# TODO if the preceding command has options that accept arguments and an -# argument is equal ot one of the subcommands, this is falsely detected as -# a match. -__docker_subcommands() { - local subcommands="$1" - - local counter=$(($command_pos + 1)) - while [ $counter -lt $cword ]; do - case "${words[$counter]}" in - $(__docker_to_extglob "$subcommands") ) - subcommand_pos=$counter - local subcommand=${words[$counter]} - local completions_func=_docker_${command}_${subcommand} - declare -F $completions_func >/dev/null && $completions_func - return 0 - ;; - esac - (( counter++ )) - done - return 1 -} - -# __docker_nospace suppresses trailing whitespace -__docker_nospace() { - # compopt is not available in ancient bash versions - type compopt &>/dev/null && compopt -o nospace -} - -__docker_complete_resolved_hostname() { - command -v host >/dev/null 2>&1 || return - COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') ) -} - -__docker_local_interfaces() { - command -v ip >/dev/null 2>&1 || return - ip addr show scope global 2>/dev/null | sed -n 's| \+inet \([0-9.]\+\).* \([^ ]\+\)|\1 \2|p' -} - -__docker_complete_local_interfaces() { - local additional_interface - if [ "$1" = "--add" ] ; then - additional_interface="$2" - fi - - COMPREPLY=( $( compgen -W "$(__docker_local_interfaces) $additional_interface" -- "$cur" ) ) -} - -__docker_complete_capabilities() { - # The list of capabilities is defined in types.go, ALL was added manually. - COMPREPLY=( $( compgen -W " - ALL - AUDIT_CONTROL - AUDIT_WRITE - AUDIT_READ - BLOCK_SUSPEND - CHOWN - DAC_OVERRIDE - DAC_READ_SEARCH - FOWNER - FSETID - IPC_LOCK - IPC_OWNER - KILL - LEASE - LINUX_IMMUTABLE - MAC_ADMIN - MAC_OVERRIDE - MKNOD - NET_ADMIN - NET_BIND_SERVICE - NET_BROADCAST - NET_RAW - SETFCAP - SETGID - SETPCAP - SETUID - SYS_ADMIN - SYS_BOOT - SYS_CHROOT - SYSLOG - SYS_MODULE - SYS_NICE - SYS_PACCT - SYS_PTRACE - SYS_RAWIO - SYS_RESOURCE - SYS_TIME - SYS_TTY_CONFIG - WAKE_ALARM - " -- "$cur" ) ) -} - -__docker_complete_detach-keys() { - case "$prev" in - --detach-keys) - case "$cur" in - *,) - COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) ) - ;; - esac - - __docker_nospace - return - ;; - esac - return 1 -} - -__docker_complete_isolation() { - COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) ) -} - -__docker_complete_log_drivers() { - COMPREPLY=( $( compgen -W " - awslogs - etwlogs - fluentd - gcplogs - gelf - journald - json-file - logentries - none - splunk - syslog - " -- "$cur" ) ) -} - -__docker_complete_log_options() { - # see docs/reference/logging/index.md - local awslogs_options="awslogs-region awslogs-group awslogs-stream" - local fluentd_options="env fluentd-address fluentd-async-connect fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries labels tag" - local gcplogs_options="env gcp-log-cmd gcp-project labels" - local gelf_options="env gelf-address gelf-compression-level gelf-compression-type labels tag" - local journald_options="env labels tag" - local json_file_options="env labels max-file max-size" - local logentries_options="logentries-token" - local syslog_options="env labels syslog-address syslog-facility syslog-format syslog-tls-ca-cert syslog-tls-cert syslog-tls-key syslog-tls-skip-verify tag" - local splunk_options="env labels splunk-caname splunk-capath splunk-format splunk-gzip splunk-gzip-level splunk-index splunk-insecureskipverify splunk-source splunk-sourcetype splunk-token splunk-url splunk-verify-connection tag" - - local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $logentries_options $json_file_options $syslog_options $splunk_options" - - case $(__docker_value_of_option --log-driver) in - '') - COMPREPLY=( $( compgen -W "$all_options" -S = -- "$cur" ) ) - ;; - awslogs) - COMPREPLY=( $( compgen -W "$awslogs_options" -S = -- "$cur" ) ) - ;; - fluentd) - COMPREPLY=( $( compgen -W "$fluentd_options" -S = -- "$cur" ) ) - ;; - gcplogs) - COMPREPLY=( $( compgen -W "$gcplogs_options" -S = -- "$cur" ) ) - ;; - gelf) - COMPREPLY=( $( compgen -W "$gelf_options" -S = -- "$cur" ) ) - ;; - journald) - COMPREPLY=( $( compgen -W "$journald_options" -S = -- "$cur" ) ) - ;; - json-file) - COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) ) - ;; - logentries) - COMPREPLY=( $( compgen -W "$logentries_options" -S = -- "$cur" ) ) - ;; - syslog) - COMPREPLY=( $( compgen -W "$syslog_options" -S = -- "$cur" ) ) - ;; - splunk) - COMPREPLY=( $( compgen -W "$splunk_options" -S = -- "$cur" ) ) - ;; - *) - return - ;; - esac - - __docker_nospace -} - -__docker_complete_log_driver_options() { - local key=$(__docker_map_key_of_current_option '--log-opt') - case "$key" in - fluentd-async-connect) - COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) - return - ;; - gelf-address) - COMPREPLY=( $( compgen -W "udp" -S "://" -- "${cur##*=}" ) ) - __docker_nospace - return - ;; - gelf-compression-level) - COMPREPLY=( $( compgen -W "1 2 3 4 5 6 7 8 9" -- "${cur##*=}" ) ) - return - ;; - gelf-compression-type) - COMPREPLY=( $( compgen -W "gzip none zlib" -- "${cur##*=}" ) ) - return - ;; - syslog-address) - COMPREPLY=( $( compgen -W "tcp:// tcp+tls:// udp:// unix://" -- "${cur##*=}" ) ) - __docker_nospace - __ltrim_colon_completions "${cur}" - return - ;; - syslog-facility) - COMPREPLY=( $( compgen -W " - auth - authpriv - cron - daemon - ftp - kern - local0 - local1 - local2 - local3 - local4 - local5 - local6 - local7 - lpr - mail - news - syslog - user - uucp - " -- "${cur##*=}" ) ) - return - ;; - syslog-format) - COMPREPLY=( $( compgen -W "rfc3164 rfc5424 rfc5424micro" -- "${cur##*=}" ) ) - return - ;; - syslog-tls-ca-cert|syslog-tls-cert|syslog-tls-key) - _filedir - return - ;; - syslog-tls-skip-verify) - COMPREPLY=( $( compgen -W "true" -- "${cur##*=}" ) ) - return - ;; - splunk-url) - COMPREPLY=( $( compgen -W "http:// https://" -- "${cur##*=}" ) ) - __docker_nospace - __ltrim_colon_completions "${cur}" - return - ;; - splunk-gzip|splunk-insecureskipverify|splunk-verify-connection) - COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) - return - ;; - splunk-format) - COMPREPLY=( $( compgen -W "inline json raw" -- "${cur##*=}" ) ) - return - ;; - esac - return 1 -} - -__docker_complete_log_levels() { - COMPREPLY=( $( compgen -W "debug info warn error fatal" -- "$cur" ) ) -} - -__docker_complete_restart() { - case "$prev" in - --restart) - case "$cur" in - on-failure:*) - ;; - *) - COMPREPLY=( $( compgen -W "always no on-failure on-failure: unless-stopped" -- "$cur") ) - ;; - esac - return - ;; - esac - return 1 -} - -# __docker_complete_signals returns a subset of the available signals that is most likely -# relevant in the context of docker containers -__docker_complete_signals() { - local signals=( - SIGCONT - SIGHUP - SIGINT - SIGKILL - SIGQUIT - SIGSTOP - SIGTERM - SIGUSR1 - SIGUSR2 - ) - COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo $cur | tr '[:lower:]' '[:upper:]')" ) ) -} - -__docker_complete_user_group() { - if [[ $cur == *:* ]] ; then - COMPREPLY=( $(compgen -g -- "${cur#*:}") ) - else - COMPREPLY=( $(compgen -u -S : -- "$cur") ) - __docker_nospace - fi -} - -_docker_docker() { - # global options that may appear after the docker command - local boolean_options=" - $global_boolean_options - --help - --version -v - " - - case "$prev" in - --config) - _filedir -d - return - ;; - --log-level|-l) - __docker_complete_log_levels - return - ;; - $(__docker_to_extglob "$global_options_with_args") ) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "$boolean_options $global_options_with_args" -- "$cur" ) ) - ;; - *) - local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" ) - if [ $cword -eq $counter ]; then - __docker_is_experimental && commands+=(${experimental_commands[*]}) - COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) ) - fi - ;; - esac -} - -_docker_attach() { - _docker_container_attach -} - -_docker_build() { - _docker_image_build -} - - -_docker_checkpoint() { - local subcommands=" - create - ls - rm - " - local aliases=" - list - remove - " - __docker_subcommands "$subcommands $aliases" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_checkpoint_create() { - case "$prev" in - --checkpoint-dir) - _filedir -d - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--checkpoint-dir --help --leave-running" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--checkpoint-dir') - if [ $cword -eq $counter ]; then - __docker_complete_containers_running - fi - ;; - esac -} - -_docker_checkpoint_ls() { - case "$prev" in - --checkpoint-dir) - _filedir -d - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--checkpoint-dir --help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--checkpoint-dir') - if [ $cword -eq $counter ]; then - __docker_complete_containers_all - fi - ;; - esac -} - -_docker_checkpoint_rm() { - case "$prev" in - --checkpoint-dir) - _filedir -d - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--checkpoint-dir --help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--checkpoint-dir') - if [ $cword -eq $counter ]; then - __docker_complete_containers_all - elif [ $cword -eq $(($counter + 1)) ]; then - COMPREPLY=( $( compgen -W "$(__docker_q checkpoint ls "$prev" | sed 1d)" -- "$cur" ) ) - fi - ;; - esac -} - - -_docker_container() { - local subcommands=" - attach - commit - cp - create - diff - exec - export - inspect - kill - logs - ls - pause - port - prune - rename - restart - rm - run - start - stats - stop - top - unpause - update - wait - " - local aliases=" - list - ps - " - __docker_subcommands "$subcommands $aliases" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_container_attach() { - __docker_complete_detach-keys && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy=false" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--detach-keys') - if [ $cword -eq $counter ]; then - __docker_complete_containers_running - fi - ;; - esac -} - -_docker_container_commit() { - case "$prev" in - --author|-a|--change|-c|--message|-m) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--author -a --change -c --help --message -m --pause=false -p=false" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--author|-a|--change|-c|--message|-m') - - if [ $cword -eq $counter ]; then - __docker_complete_containers_all - return - fi - (( counter++ )) - - if [ $cword -eq $counter ]; then - __docker_complete_image_repos_and_tags - return - fi - ;; - esac -} - -_docker_container_cp() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--follow-link -L --help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - case "$cur" in - *:) - return - ;; - *) - # combined container and filename completion - _filedir - local files=( ${COMPREPLY[@]} ) - - __docker_complete_containers_all - COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) - local containers=( ${COMPREPLY[@]} ) - - COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) ) - if [[ "$COMPREPLY" == *: ]]; then - __docker_nospace - fi - return - ;; - esac - fi - (( counter++ )) - - if [ $cword -eq $counter ]; then - if [ -e "$prev" ]; then - __docker_complete_containers_all - COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) - __docker_nospace - else - _filedir - fi - return - fi - ;; - esac -} - -_docker_container_create() { - _docker_container_run -} - -_docker_container_diff() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_containers_all - fi - ;; - esac -} - -_docker_container_exec() { - __docker_complete_detach-keys && return - - case "$prev" in - --env|-e) - # we do not append a "=" here because "-e VARNAME" is legal systax, too - COMPREPLY=( $( compgen -e -- "$cur" ) ) - __docker_nospace - return - ;; - --user|-u) - __docker_complete_user_group - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--detach -d --detach-keys --env -e --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) ) - ;; - *) - __docker_complete_containers_running - ;; - esac -} - -_docker_container_export() { - case "$prev" in - --output|-o) - _filedir - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_containers_all - fi - ;; - esac -} - -_docker_container_inspect() { - _docker_inspect --type container -} - -_docker_container_kill() { - case "$prev" in - --signal|-s) - __docker_complete_signals - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --signal -s" -- "$cur" ) ) - ;; - *) - __docker_complete_containers_running - ;; - esac -} - -_docker_container_logs() { - case "$prev" in - --since|--tail) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--details --follow -f --help --since --tail --timestamps -t" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--since|--tail') - if [ $cword -eq $counter ]; then - __docker_complete_containers_all - fi - ;; - esac -} - -_docker_container_list() { - _docker_container_ls -} - -_docker_container_ls() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - ancestor) - cur="${cur##*=}" - __docker_complete_images - return - ;; - before) - __docker_complete_containers_all --cur "${cur##*=}" - return - ;; - id) - __docker_complete_containers_all --cur "${cur##*=}" --id - return - ;; - health) - COMPREPLY=( $( compgen -W "healthy starting none unhealthy" -- "${cur##*=}" ) ) - return - ;; - is-task) - COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) ) - return - ;; - name) - __docker_complete_containers_all --cur "${cur##*=}" --name - return - ;; - network) - __docker_complete_networks --cur "${cur##*=}" - return - ;; - since) - __docker_complete_containers_all --cur "${cur##*=}" - return - ;; - status) - COMPREPLY=( $( compgen -W "created dead exited paused restarting running removing" -- "${cur##*=}" ) ) - return - ;; - volume) - __docker_complete_volumes --cur "${cur##*=}" - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -S = -W "ancestor before exited health id is-task label name network since status volume" -- "$cur" ) ) - __docker_nospace - return - ;; - --format|--last|-n) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--all -a --filter -f --format --help --last -n --latest -l --no-trunc --quiet -q --size -s" -- "$cur" ) ) - ;; - esac -} - -_docker_container_pause() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - __docker_complete_containers_running - ;; - esac -} - -_docker_container_port() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_containers_all - fi - ;; - esac -} - -_docker_container_prune() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) - ;; - esac -} - -_docker_container_ps() { - _docker_container_ls -} - -_docker_container_rename() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_containers_all - fi - ;; - esac -} - -_docker_container_restart() { - case "$prev" in - --time|-t) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) - ;; - *) - __docker_complete_containers_all - ;; - esac -} - -_docker_container_rm() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--force -f --help --link -l --volumes -v" -- "$cur" ) ) - ;; - *) - for arg in "${COMP_WORDS[@]}"; do - case "$arg" in - --force|-f) - __docker_complete_containers_all - return - ;; - esac - done - __docker_complete_containers_stopped - ;; - esac -} - -_docker_container_run() { - local options_with_args=" - --add-host - --attach -a - --blkio-weight - --blkio-weight-device - --cap-add - --cap-drop - --cgroup-parent - --cidfile - --cpu-period - --cpu-quota - --cpu-rt-period - --cpu-rt-runtime - --cpuset-cpus - --cpus - --cpuset-mems - --cpu-shares -c - --device - --device-read-bps - --device-read-iops - --device-write-bps - --device-write-iops - --dns - --dns-option - --dns-search - --entrypoint - --env -e - --env-file - --expose - --group-add - --hostname -h - --init-path - --ip - --ip6 - --ipc - --isolation - --kernel-memory - --label-file - --label -l - --link - --link-local-ip - --log-driver - --log-opt - --mac-address - --memory -m - --memory-swap - --memory-swappiness - --memory-reservation - --name - --network - --network-alias - --oom-score-adj - --pid - --pids-limit - --publish -p - --restart - --runtime - --security-opt - --shm-size - --stop-signal - --stop-timeout - --storage-opt - --tmpfs - --sysctl - --ulimit - --user -u - --userns - --uts - --volume-driver - --volumes-from - --volume -v - --workdir -w - " - - local boolean_options=" - --disable-content-trust=false - --help - --init - --interactive -i - --oom-kill-disable - --privileged - --publish-all -P - --read-only - --tty -t - " - - if [ "$command" = "run" -o "$subcommand" = "run" ] ; then - options_with_args="$options_with_args - --detach-keys - --health-cmd - --health-interval - --health-retries - --health-timeout - " - boolean_options="$boolean_options - --detach -d - --no-healthcheck - --rm - --sig-proxy=false - " - __docker_complete_detach-keys && return - fi - - local all_options="$options_with_args $boolean_options" - - - __docker_complete_log_driver_options && return - __docker_complete_restart && return - - local key=$(__docker_map_key_of_current_option '--security-opt') - case "$key" in - label) - [[ $cur == *: ]] && return - COMPREPLY=( $( compgen -W "user: role: type: level: disable" -- "${cur##*=}") ) - if [ "${COMPREPLY[*]}" != "disable" ] ; then - __docker_nospace - fi - return - ;; - seccomp) - local cur=${cur##*=} - _filedir - COMPREPLY+=( $( compgen -W "unconfined" -- "$cur" ) ) - return - ;; - esac - - case "$prev" in - --add-host) - case "$cur" in - *:) - __docker_complete_resolved_hostname - return - ;; - esac - ;; - --attach|-a) - COMPREPLY=( $( compgen -W 'stdin stdout stderr' -- "$cur" ) ) - return - ;; - --cap-add|--cap-drop) - __docker_complete_capabilities - return - ;; - --cidfile|--env-file|--init-path|--label-file) - _filedir - return - ;; - --device|--tmpfs|--volume|-v) - case "$cur" in - *:*) - # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) - ;; - '') - COMPREPLY=( $( compgen -W '/' -- "$cur" ) ) - __docker_nospace - ;; - /*) - _filedir - __docker_nospace - ;; - esac - return - ;; - --env|-e) - # we do not append a "=" here because "-e VARNAME" is legal systax, too - COMPREPLY=( $( compgen -e -- "$cur" ) ) - __docker_nospace - return - ;; - --ipc) - case "$cur" in - *:*) - cur="${cur#*:}" - __docker_complete_containers_running - ;; - *) - COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) - if [ "$COMPREPLY" = "container:" ]; then - __docker_nospace - fi - ;; - esac - return - ;; - --isolation) - __docker_complete_isolation - return - ;; - --link) - case "$cur" in - *:*) - ;; - *) - __docker_complete_containers_running - COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) - __docker_nospace - ;; - esac - return - ;; - --log-driver) - __docker_complete_log_drivers - return - ;; - --log-opt) - __docker_complete_log_options - return - ;; - --network) - case "$cur" in - container:*) - __docker_complete_containers_all --cur "${cur#*:}" - ;; - *) - COMPREPLY=( $( compgen -W "$(__docker_plugins_bundled --type Network) $(__docker_networks) container:" -- "$cur") ) - if [ "${COMPREPLY[*]}" = "container:" ] ; then - __docker_nospace - fi - ;; - esac - return - ;; - --pid) - case "$cur" in - *:*) - __docker_complete_containers_running --cur "${cur#*:}" - ;; - *) - COMPREPLY=( $( compgen -W 'host container:' -- "$cur" ) ) - if [ "$COMPREPLY" = "container:" ]; then - __docker_nospace - fi - ;; - esac - return - ;; - --runtime) - __docker_complete_runtimes - return - ;; - --security-opt) - COMPREPLY=( $( compgen -W "apparmor= label= no-new-privileges seccomp=" -- "$cur") ) - if [ "${COMPREPLY[*]}" != "no-new-privileges" ] ; then - __docker_nospace - fi - return - ;; - --storage-opt) - COMPREPLY=( $( compgen -W "size" -S = -- "$cur") ) - __docker_nospace - return - ;; - --user|-u) - __docker_complete_user_group - return - ;; - --userns) - COMPREPLY=( $( compgen -W "host" -- "$cur" ) ) - return - ;; - --volume-driver) - __docker_complete_plugins_bundled --type Volume - return - ;; - --volumes-from) - __docker_complete_containers_all - return - ;; - $(__docker_to_extglob "$options_with_args") ) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) - ;; - *) - local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) - if [ $cword -eq $counter ]; then - __docker_complete_images - fi - ;; - esac -} - -_docker_container_start() { - __docker_complete_detach-keys && return - - case "$prev" in - --checkpoint) - if [ __docker_is_experimental ] ; then - return - fi - ;; - --checkpoint-dir) - if [ __docker_is_experimental ] ; then - _filedir -d - return - fi - ;; - esac - - case "$cur" in - -*) - local options="--attach -a --detach-keys --help --interactive -i" - __docker_is_experimental && options+=" --checkpoint --checkpoint-dir" - COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) - ;; - *) - __docker_complete_containers_stopped - ;; - esac -} - -_docker_container_stats() { - case "$prev" in - --format) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--all -a --format --help --no-stream" -- "$cur" ) ) - ;; - *) - __docker_complete_containers_running - ;; - esac -} - -_docker_container_stop() { - case "$prev" in - --time|-t) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --time -t" -- "$cur" ) ) - ;; - *) - __docker_complete_containers_running - ;; - esac -} - -_docker_container_top() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_containers_running - fi - ;; - esac -} - -_docker_container_unpause() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_containers_unpauseable - fi - ;; - esac -} - -_docker_container_update() { - local options_with_args=" - --blkio-weight - --cpu-period - --cpu-quota - --cpu-rt-period - --cpu-rt-runtime - --cpuset-cpus - --cpuset-mems - --cpu-shares -c - --kernel-memory - --memory -m - --memory-reservation - --memory-swap - --restart - " - - local boolean_options=" - --help - " - - local all_options="$options_with_args $boolean_options" - - __docker_complete_restart && return - - case "$prev" in - $(__docker_to_extglob "$options_with_args") ) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) - ;; - *) - __docker_complete_containers_all - ;; - esac -} - -_docker_container_wait() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - __docker_complete_containers_all - ;; - esac -} - - -_docker_commit() { - _docker_container_commit -} - -_docker_cp() { - _docker_container_cp -} - -_docker_create() { - _docker_container_run -} - -_docker_daemon() { - local boolean_options=" - $global_boolean_options - --disable-legacy-registry - --experimental - --help - --icc=false - --init - --ip-forward=false - --ip-masq=false - --iptables=false - --ipv6 - --live-restore - --raw-logs - --selinux-enabled - --userland-proxy=false - " - local options_with_args=" - $global_options_with_args - --add-runtime - --api-cors-header - --authorization-plugin - --bip - --bridge -b - --cgroup-parent - --cluster-advertise - --cluster-store - --cluster-store-opt - --config-file - --containerd - --default-gateway - --default-gateway-v6 - --default-ulimit - --dns - --dns-search - --dns-opt - --exec-opt - --exec-root - --fixed-cidr - --fixed-cidr-v6 - --graph -g - --group -G - --init-path - --insecure-registry - --ip - --label - --log-driver - --log-opt - --max-concurrent-downloads - --max-concurrent-uploads - --mtu - --oom-score-adjust - --pidfile -p - --registry-mirror - --seccomp-profile - --shutdown-timeout - --storage-driver -s - --storage-opt - --userland-proxy-path - --userns-remap - " - - __docker_complete_log_driver_options && return - - key=$(__docker_map_key_of_current_option '--cluster-store-opt') - case "$key" in - kv.*file) - cur=${cur##*=} - _filedir - return - ;; - esac - - local key=$(__docker_map_key_of_current_option '--storage-opt') - case "$key" in - dm.blkdiscard|dm.override_udev_sync_check|dm.use_deferred_removal|dm.use_deferred_deletion) - COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) - return - ;; - dm.fs) - COMPREPLY=( $( compgen -W "ext4 xfs" -- "${cur##*=}" ) ) - return - ;; - dm.thinpooldev) - cur=${cur##*=} - _filedir - return - ;; - esac - - case "$prev" in - --authorization-plugin) - __docker_complete_plugins_bundled --type Authorization - return - ;; - --cluster-store) - COMPREPLY=( $( compgen -W "consul etcd zk" -S "://" -- "$cur" ) ) - __docker_nospace - return - ;; - --cluster-store-opt) - COMPREPLY=( $( compgen -W "discovery.heartbeat discovery.ttl kv.cacertfile kv.certfile kv.keyfile kv.path" -S = -- "$cur" ) ) - __docker_nospace - return - ;; - --config-file|--containerd|--init-path|--pidfile|-p|--tlscacert|--tlscert|--tlskey|--userland-proxy-path) - _filedir - return - ;; - --exec-root|--graph|-g) - _filedir -d - return - ;; - --log-driver) - __docker_complete_log_drivers - return - ;; - --storage-driver|-s) - COMPREPLY=( $( compgen -W "aufs btrfs devicemapper overlay overlay2 vfs zfs" -- "$(echo $cur | tr '[:upper:]' '[:lower:]')" ) ) - return - ;; - --storage-opt) - local btrfs_options="btrfs.min_space" - local devicemapper_options=" - dm.basesize - dm.blkdiscard - dm.blocksize - dm.fs - dm.loopdatasize - dm.loopmetadatasize - dm.min_free_space - dm.mkfsarg - dm.mountopt - dm.override_udev_sync_check - dm.thinpooldev - dm.use_deferred_deletion - dm.use_deferred_removal - " - local zfs_options="zfs.fsname" - - case $(__docker_value_of_option '--storage-driver|-s') in - '') - COMPREPLY=( $( compgen -W "$btrfs_options $devicemapper_options $zfs_options" -S = -- "$cur" ) ) - ;; - btrfs) - COMPREPLY=( $( compgen -W "$btrfs_options" -S = -- "$cur" ) ) - ;; - devicemapper) - COMPREPLY=( $( compgen -W "$devicemapper_options" -S = -- "$cur" ) ) - ;; - zfs) - COMPREPLY=( $( compgen -W "$zfs_options" -S = -- "$cur" ) ) - ;; - *) - return - ;; - esac - __docker_nospace - return - ;; - --log-level|-l) - __docker_complete_log_levels - return - ;; - --log-opt) - __docker_complete_log_options - return - ;; - --seccomp-profile) - _filedir json - return - ;; - --userns-remap) - __docker_complete_user_group - return - ;; - $(__docker_to_extglob "$options_with_args") ) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) - ;; - esac -} - -_docker_deploy() { - __docker_is_experimental && _docker_stack_deploy -} - -_docker_diff() { - _docker_container_diff -} - -_docker_events() { - _docker_system_events -} - -_docker_exec() { - _docker_container_exec -} - -_docker_export() { - _docker_container_export -} - -_docker_help() { - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) - fi -} - -_docker_history() { - _docker_image_history -} - - -_docker_image() { - local subcommands=" - build - history - import - inspect - load - ls - prune - pull - push - rm - save - tag - " - local aliases=" - images - list - remove - rmi - " - __docker_subcommands "$subcommands $aliases" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_image_build() { - local options_with_args=" - --build-arg - --cache-from - --cgroup-parent - --cpuset-cpus - --cpuset-mems - --cpu-shares -c - --cpu-period - --cpu-quota - --file -f - --isolation - --label - --memory -m - --memory-swap - --network - --shm-size - --tag -t - --ulimit - " - - local boolean_options=" - --compress - --disable-content-trust=false - --force-rm - --help - --no-cache - --pull - --quiet -q - --rm - " - __docker_is_experimental && boolean_options+="--squash" - - local all_options="$options_with_args $boolean_options" - - case "$prev" in - --build-arg) - COMPREPLY=( $( compgen -e -- "$cur" ) ) - __docker_nospace - return - ;; - --cache-from) - __docker_complete_image_repos_and_tags - return - ;; - --file|-f) - _filedir - return - ;; - --isolation) - __docker_complete_isolation - return - ;; - --network) - case "$cur" in - container:*) - __docker_complete_containers_all --cur "${cur#*:}" - ;; - *) - COMPREPLY=( $( compgen -W "$(__docker_plugins --type Network) $(__docker_networks) container:" -- "$cur") ) - if [ "${COMPREPLY[*]}" = "container:" ] ; then - __docker_nospace - fi - ;; - esac - return - ;; - --tag|-t) - __docker_complete_image_repos_and_tags - return - ;; - $(__docker_to_extglob "$options_with_args") ) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) ) - ;; - *) - local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) - if [ $cword -eq $counter ]; then - _filedir -d - fi - ;; - esac -} - -_docker_image_history() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --human=false -H=false --no-trunc --quiet -q" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_images - fi - ;; - esac -} - -_docker_image_images() { - _docker_image_ls -} - -_docker_image_import() { - case "$prev" in - --change|-c|--message|-m) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--change -c --help --message -m" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--change|-c|--message|-m') - if [ $cword -eq $counter ]; then - return - fi - (( counter++ )) - - if [ $cword -eq $counter ]; then - __docker_complete_image_repos_and_tags - return - fi - ;; - esac -} - -_docker_image_inspect() { - _docker_inspect --type image -} - -_docker_image_load() { - case "$prev" in - --input|-i) - _filedir - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --input -i --quiet -q" -- "$cur" ) ) - ;; - esac -} - -_docker_image_list() { - _docker_image_ls -} - -_docker_image_ls() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - before|since|reference) - cur="${cur##*=}" - __docker_complete_images - return - ;; - dangling) - COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) - return - ;; - label) - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -S = -W "before dangling label reference since" -- "$cur" ) ) - __docker_nospace - return - ;; - --format) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--all -a --digests --filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) ) - ;; - =) - return - ;; - *) - __docker_complete_image_repos - ;; - esac -} - -_docker_image_prune() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--all -a --force -f --help" -- "$cur" ) ) - ;; - esac -} - -_docker_image_pull() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--all-tags -a --disable-content-trust=false --help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - for arg in "${COMP_WORDS[@]}"; do - case "$arg" in - --all-tags|-a) - __docker_complete_image_repos - return - ;; - esac - done - __docker_complete_image_repos_and_tags - fi - ;; - esac -} - -_docker_image_push() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--disable-content-trust=false --help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_image_repos_and_tags - fi - ;; - esac -} - -_docker_image_remove() { - _docker_image_rm -} - -_docker_image_rm() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--force -f --help --no-prune" -- "$cur" ) ) - ;; - *) - __docker_complete_images - ;; - esac -} - -_docker_image_rmi() { - _docker_image_rm -} - -_docker_image_save() { - case "$prev" in - --output|-o) - _filedir - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --output -o" -- "$cur" ) ) - ;; - *) - __docker_complete_images - ;; - esac -} - -_docker_image_tag() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - - if [ $cword -eq $counter ]; then - __docker_complete_image_repos_and_tags - return - fi - (( counter++ )) - - if [ $cword -eq $counter ]; then - __docker_complete_image_repos_and_tags - return - fi - ;; - esac -} - - -_docker_images() { - _docker_image_ls -} - -_docker_import() { - _docker_image_import -} - -_docker_info() { - _docker_system_info -} - -_docker_inspect() { - local preselected_type - local type - - if [ "$1" = "--type" ] ; then - preselected_type=yes - type="$2" - else - type=$(__docker_value_of_option --type) - fi - - case "$prev" in - --format|-f) - return - ;; - --type) - if [ -z "$preselected_type" ] ; then - COMPREPLY=( $( compgen -W "container image network node plugin service volume" -- "$cur" ) ) - return - fi - ;; - esac - - case "$cur" in - -*) - local options="--format -f --help --size -s" - if [ -z "$preselected_type" ] ; then - options+=" --type" - fi - COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) - ;; - *) - case "$type" in - '') - COMPREPLY=( $( compgen -W " - $(__docker_containers --all) - $(__docker_images) - $(__docker_networks) - $(__docker_nodes) - $(__docker_plugins_installed) - $(__docker_services) - $(__docker_volumes) - " -- "$cur" ) ) - ;; - container) - __docker_complete_containers_all - ;; - image) - __docker_complete_images - ;; - network) - __docker_complete_networks - ;; - node) - __docker_complete_nodes - ;; - plugin) - __docker_complete_plugins_installed - ;; - service) - __docker_complete_services - ;; - volume) - __docker_complete_volumes - ;; - esac - esac -} - -_docker_kill() { - _docker_container_kill -} - -_docker_load() { - _docker_image_load -} - -_docker_login() { - case "$prev" in - --password|-p|--username|-u) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --password -p --username -u" -- "$cur" ) ) - ;; - esac -} - -_docker_logout() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - esac -} - -_docker_logs() { - _docker_container_logs -} - -_docker_network_connect() { - local options_with_args=" - --alias - --ip - --ip6 - --link - --link-local-ip - " - - local boolean_options=" - --help - " - - case "$prev" in - --link) - case "$cur" in - *:*) - ;; - *) - __docker_complete_containers_running - COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) - __docker_nospace - ;; - esac - return - ;; - $(__docker_to_extglob "$options_with_args") ) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) - ;; - *) - local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) - if [ $cword -eq $counter ]; then - __docker_complete_networks - elif [ $cword -eq $(($counter + 1)) ]; then - __docker_complete_containers_all - fi - ;; - esac -} - -_docker_network_create() { - case "$prev" in - --aux-address|--gateway|--internal|--ip-range|--ipam-opt|--ipv6|--opt|-o|--subnet) - return - ;; - --ipam-driver) - COMPREPLY=( $( compgen -W "default" -- "$cur" ) ) - return - ;; - --driver|-d) - # remove drivers that allow one instance only, add drivers missing in `docker info` - __docker_complete_plugins_bundled --type Network --remove host --remove null --add macvlan - return - ;; - --label) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--attachable --aux-address --driver -d --gateway --help --internal --ip-range --ipam-driver --ipam-opt --ipv6 --label --opt -o --subnet" -- "$cur" ) ) - ;; - esac -} - -_docker_network_disconnect() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_networks - elif [ $cword -eq $(($counter + 1)) ]; then - __docker_complete_containers_in_network "$prev" - fi - ;; - esac -} - -_docker_network_inspect() { - case "$prev" in - --format|-f) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) - ;; - *) - __docker_complete_networks - esac -} - -_docker_network_ls() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - driver) - __docker_complete_plugins_bundled --cur "${cur##*=}" --type Network --add macvlan - return - ;; - id) - __docker_complete_networks --cur "${cur##*=}" --id - return - ;; - name) - __docker_complete_networks --cur "${cur##*=}" --name - return - ;; - type) - COMPREPLY=( $( compgen -W "builtin custom" -- "${cur##*=}" ) ) - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -S = -W "driver id label name type" -- "$cur" ) ) - __docker_nospace - return - ;; - --format) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--filter -f --format --help --no-trunc --quiet -q" -- "$cur" ) ) - ;; - esac -} - -_docker_network_prune() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) - ;; - esac -} - -_docker_network_rm() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - __docker_complete_networks --filter type=custom - esac -} - -_docker_network() { - local subcommands=" - connect - create - disconnect - inspect - ls - prune - rm - " - __docker_subcommands "$subcommands" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_service() { - local subcommands=" - create - inspect - ls list - rm remove - scale - ps - update - " - __docker_daemon_is_experimental && subcommands+="logs" - - __docker_subcommands "$subcommands" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_service_create() { - _docker_service_update -} - -_docker_service_inspect() { - case "$prev" in - --format|-f) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) ) - ;; - *) - __docker_complete_services - esac -} - -_docker_service_logs() { - case "$prev" in - --since|--tail) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--details --follow -f --help --no-resolve --since --tail --timestamps -t" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--since|--tail') - if [ $cword -eq $counter ]; then - __docker_complete_services - fi - ;; - esac -} - -_docker_service_list() { - _docker_service_ls -} - -_docker_service_ls() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - id) - __docker_complete_services --cur "${cur##*=}" --id - return - ;; - name) - __docker_complete_services --cur "${cur##*=}" --name - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) ) - __docker_nospace - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) ) - ;; - esac -} - -_docker_service_remove() { - _docker_service_rm -} - -_docker_service_rm() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - __docker_complete_services - esac -} - -_docker_service_scale() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - __docker_complete_services - __docker_append_to_completions "=" - __docker_nospace - ;; - esac -} - -_docker_service_ps() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - desired-state) - COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) ) - return - ;; - name) - __docker_complete_services --cur "${cur##*=}" --name - return - ;; - node) - __docker_complete_nodes_plus_self --cur "${cur##*=}" - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -W "desired-state id name node" -S = -- "$cur" ) ) - __docker_nospace - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--filter -f --help --no-resolve --no-trunc --quiet -q" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--filter|-f') - if [ $cword -eq $counter ]; then - __docker_complete_services - fi - ;; - esac -} - -_docker_service_update() { - local $subcommand="${words[$subcommand_pos]}" - - local options_with_args=" - --constraint - --endpoint-mode - --env -e - --force - --health-cmd - --health-interval - --health-retries - --health-timeout - --hostname - --label -l - --limit-cpu - --limit-memory - --log-driver - --log-opt - --mount - --network - --no-healthcheck - --replicas - --reserve-cpu - --reserve-memory - --restart-condition - --restart-delay - --restart-max-attempts - --restart-window - --rollback - --stop-grace-period - --update-delay - --update-failure-action - --update-max-failure-ratio - --update-monitor - --update-parallelism - --user -u - --workdir -w - " - - local boolean_options=" - --help - --tty -t - --with-registry-auth - " - - __docker_complete_log_driver_options && return - - if [ "$subcommand" = "create" ] ; then - options_with_args="$options_with_args - --container-label - --dns - --dns-option - --dns-search - --env-file - --group - --host - --mode - --name - --publish -p - --secret - " - - case "$prev" in - --env-file) - _filedir - return - ;; - --host) - case "$cur" in - *:) - __docker_complete_resolved_hostname - return - ;; - esac - ;; - --mode) - COMPREPLY=( $( compgen -W "global replicated" -- "$cur" ) ) - return - ;; - --secret) - __docker_complete_secrets - return - ;; - --group) - COMPREPLY=( $(compgen -g -- "$cur") ) - return - ;; - esac - fi - if [ "$subcommand" = "update" ] ; then - options_with_args="$options_with_args - --arg - --container-label-add - --container-label-rm - --dns-add - --dns-option-add - --dns-option-rm - --dns-rm - --dns-search-add - --dns-search-rm - --group-add - --group-rm - --host-add - --host-rm - --image - --publish-add - --publish-rm - --secret-add - --secret-rm - " - - case "$prev" in - --group-add) - COMPREPLY=( $(compgen -g -- "$cur") ) - return - ;; - --group-rm) - COMPREPLY=( $(compgen -g -- "$cur") ) - return - ;; - --host-add|--host-rm) - case "$cur" in - *:) - __docker_complete_resolved_hostname - return - ;; - esac - ;; - --image) - __docker_complete_image_repos_and_tags - return - ;; - --secret-add|--secret-rm) - __docker_complete_secrets - return - ;; - esac - fi - - case "$prev" in - --endpoint-mode) - COMPREPLY=( $( compgen -W "dnsrr vip" -- "$cur" ) ) - return - ;; - --env|-e) - # we do not append a "=" here because "-e VARNAME" is legal systax, too - COMPREPLY=( $( compgen -e -- "$cur" ) ) - __docker_nospace - return - ;; - --log-driver) - __docker_complete_log_drivers - return - ;; - --log-opt) - __docker_complete_log_options - return - ;; - --network) - __docker_complete_networks - return - ;; - --restart-condition) - COMPREPLY=( $( compgen -W "any none on-failure" -- "$cur" ) ) - return - ;; - --user|-u) - __docker_complete_user_group - return - ;; - $(__docker_to_extglob "$options_with_args") ) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "$boolean_options $options_with_args" -- "$cur" ) ) - ;; - *) - local counter=$( __docker_pos_first_nonflag $( __docker_to_alternatives "$options_with_args" ) ) - if [ "$subcommand" = "update" ] ; then - if [ $cword -eq $counter ]; then - __docker_complete_services - fi - else - if [ $cword -eq $counter ]; then - __docker_complete_images - fi - fi - ;; - esac -} - -_docker_swarm() { - local subcommands=" - init - join - join-token - leave - unlock - unlock-key - update - " - __docker_subcommands "$subcommands" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_swarm_init() { - case "$prev" in - --advertise-addr) - if [[ $cur == *: ]] ; then - COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) - else - __docker_complete_local_interfaces - __docker_nospace - fi - return - ;; - --availability) - COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) ) - return - ;; - --cert-expiry|--dispatcher-heartbeat|--external-ca|--max-snapshots|--snapshot-interval|--task-history-limit) - return - ;; - --listen-addr) - if [[ $cur == *: ]] ; then - COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) - else - __docker_complete_local_interfaces --add 0.0.0.0 - __docker_nospace - fi - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--advertise-addr --autolock --availability --cert-expiry --dispatcher-heartbeat --external-ca --force-new-cluster --help --listen-addr --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) ) - ;; - esac -} - -_docker_swarm_join() { - case "$prev" in - --advertise-addr) - if [[ $cur == *: ]] ; then - COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) - else - __docker_complete_local_interfaces - __docker_nospace - fi - return - ;; - --listen-addr) - if [[ $cur == *: ]] ; then - COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) - else - __docker_complete_local_interfaces --add 0.0.0.0 - __docker_nospace - fi - return - ;; - --token) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--advertise-addr --help --listen-addr --token" -- "$cur" ) ) - ;; - *:) - COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) ) - ;; - esac -} - -_docker_swarm_join-token() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) ) - ;; - *) - local counter=$( __docker_pos_first_nonflag ) - if [ $cword -eq $counter ]; then - COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) ) - fi - ;; - esac -} - -_docker_swarm_leave() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) - ;; - esac -} - -_docker_swarm_unlock() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - esac -} - -_docker_swarm_unlock-key() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --quiet -q --rotate" -- "$cur" ) ) - ;; - esac -} - -_docker_swarm_update() { - case "$prev" in - --cert-expiry|--dispatcher-heartbeat|--external-ca|--max-snapshots|--snapshot-interval|--task-history-limit) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--autolock --cert-expiry --dispatcher-heartbeat --external-ca --help --max-snapshots --snapshot-interval --task-history-limit" -- "$cur" ) ) - ;; - esac -} - -_docker_node() { - local subcommands=" - demote - inspect - ls list - promote - rm remove - ps - update - " - __docker_subcommands "$subcommands" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_node_demote() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - __docker_complete_nodes --filter role=manager - esac -} - -_docker_node_inspect() { - case "$prev" in - --format|-f) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--format -f --help --pretty" -- "$cur" ) ) - ;; - *) - __docker_complete_nodes_plus_self - esac -} - -_docker_node_list() { - _docker_node_ls -} - -_docker_node_ls() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - id) - __docker_complete_nodes --cur "${cur##*=}" --id - return - ;; - name) - __docker_complete_nodes --cur "${cur##*=}" --name - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -W "id label name" -S = -- "$cur" ) ) - __docker_nospace - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) ) - ;; - esac -} - -_docker_node_promote() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - __docker_complete_nodes --filter role=worker - esac -} - -_docker_node_remove() { - _docker_node_rm -} - -_docker_node_rm() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) - ;; - *) - __docker_complete_nodes - esac -} - -_docker_node_ps() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - desired-state) - COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) ) - return - ;; - name) - __docker_complete_services --cur "${cur##*=}" --name - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -W "desired-state id label name" -S = -- "$cur" ) ) - __docker_nospace - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--filter -f --help --no-resolve --no-trunc" -- "$cur" ) ) - ;; - *) - __docker_complete_nodes_plus_self - ;; - esac -} - -_docker_node_update() { - case "$prev" in - --availability) - COMPREPLY=( $( compgen -W "active drain pause" -- "$cur" ) ) - return - ;; - --role) - COMPREPLY=( $( compgen -W "manager worker" -- "$cur" ) ) - return - ;; - --label-add|--label-rm) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--availability --help --label-add --label-rm --role" -- "$cur" ) ) - ;; - *) - __docker_complete_nodes - esac -} - -_docker_pause() { - _docker_container_pause -} - -_docker_plugin() { - local subcommands=" - create - disable - enable - inspect - install - ls - push - rm - set - " - local aliases=" - list - remove - " - __docker_subcommands "$subcommands $aliases" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_plugin_create() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--compress --help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - # reponame - return - elif [ $cword -eq $((counter + 1)) ]; then - _filedir -d - fi - ;; - esac -} - -_docker_plugin_disable() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_plugins_installed - fi - ;; - esac -} - -_docker_plugin_enable() { - case "$prev" in - --timeout) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --timeout" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--timeout') - if [ $cword -eq $counter ]; then - __docker_complete_plugins_installed - fi - ;; - esac -} - -_docker_plugin_inspect() { - case "$prev" in - --format|f) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) - ;; - *) - __docker_complete_plugins_installed - ;; - esac -} - -_docker_plugin_install() { - case "$prev" in - --alias) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--alias --disable --disable-content-trust=false --grant-all-permissions --help" -- "$cur" ) ) - ;; - esac -} - -_docker_plugin_list() { - _docker_plugin_ls -} - -_docker_plugin_ls() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --no-trunc" -- "$cur" ) ) - ;; - esac -} - -_docker_plugin_push() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_plugins_installed - fi - ;; - esac -} - -_docker_plugin_remove() { - _docker_plugin_rm -} - -_docker_plugin_rm() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) - ;; - *) - __docker_complete_plugins_installed - ;; - esac -} - -_docker_plugin_set() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_plugins_installed - fi - ;; - esac -} - - -_docker_port() { - _docker_container_port -} - -_docker_ps() { - _docker_container_ls -} - -_docker_pull() { - _docker_image_pull -} - -_docker_push() { - _docker_image_push -} - -_docker_rename() { - _docker_container_rename -} - -_docker_restart() { - _docker_container_restart -} - -_docker_rm() { - _docker_container_rm -} - -_docker_rmi() { - _docker_image_rm -} - -_docker_run() { - _docker_container_run -} - -_docker_save() { - _docker_image_save -} - - -_docker_secret() { - local subcommands=" - create - inspect - ls - rm - " - local aliases=" - list - remove - " - __docker_subcommands "$subcommands $aliases" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_secret_create() { - case "$prev" in - --label|-l) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --label -l" -- "$cur" ) ) - ;; - esac -} - -_docker_secret_inspect() { - case "$prev" in - --format|-f) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) - ;; - *) - __docker_complete_secrets - ;; - esac -} - -_docker_secret_list() { - _docker_secret_ls -} - -_docker_secret_ls() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --quiet -q" -- "$cur" ) ) - ;; - esac -} - -_docker_secret_remove() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - __docker_complete_secrets - ;; - esac -} - -_docker_secret_rm() { - _docker_secret_remove -} - - - -_docker_search() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - is-automated) - COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) - return - ;; - is-official) - COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) ) - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -S = -W "is-automated is-official stars" -- "$cur" ) ) - __docker_nospace - return - ;; - --limit) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--filter --help --limit --no-trunc" -- "$cur" ) ) - ;; - esac -} - - -_docker_stack() { - local subcommands=" - deploy - ls - ps - rm - services - " - local aliases=" - down - list - remove - up - " - __docker_subcommands "$subcommands $aliases" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_stack_deploy() { - case "$prev" in - --bundle-file) - if __docker_is_experimental ; then - _filedir dab - return - fi - ;; - --compose-file|-c) - _filedir yml - return - ;; - esac - - case "$cur" in - -*) - local options="--compose-file -c --help --with-registry-auth" - __docker_is_experimental && options+=" --bundle-file" - COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) - ;; - esac -} - -_docker_stack_down() { - _docker_stack_rm -} - -_docker_stack_list() { - _docker_stack_ls -} - -_docker_stack_ls() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - esac -} - -_docker_stack_ps() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - desired-state) - COMPREPLY=( $( compgen -W "accepted running" -- "${cur##*=}" ) ) - return - ;; - id) - __docker_complete_stacks --cur "${cur##*=}" --id - return - ;; - name) - __docker_complete_stacks --cur "${cur##*=}" --name - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -S = -W "id name desired-state" -- "$cur" ) ) - __docker_nospace - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-resolve --no-trunc" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--filter|-f') - if [ $cword -eq $counter ]; then - __docker_complete_stacks - fi - ;; - esac -} - -_docker_stack_remove() { - _docker_stack_rm -} - -_docker_stack_rm() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag) - if [ $cword -eq $counter ]; then - __docker_complete_stacks - fi - ;; - esac -} - -_docker_stack_services() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - id) - __docker_complete_services --cur "${cur##*=}" --id - return - ;; - label) - return - ;; - name) - __docker_complete_services --cur "${cur##*=}" --name - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) ) - __docker_nospace - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--filter -f --help --quiet -q" -- "$cur" ) ) - ;; - *) - local counter=$(__docker_pos_first_nonflag '--filter|-f') - if [ $cword -eq $counter ]; then - __docker_complete_stacks - fi - ;; - esac -} - -_docker_stack_up() { - _docker_stack_deploy -} - - -_docker_start() { - _docker_container_start -} - -_docker_stats() { - _docker_container_stats -} - -_docker_stop() { - _docker_container_stop -} - - -_docker_system() { - local subcommands=" - df - events - info - prune - " - __docker_subcommands "$subcommands $aliases" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_system_df() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help --verbose -v" -- "$cur" ) ) - ;; - esac -} - -_docker_system_events() { - local key=$(__docker_map_key_of_current_option '-f|--filter') - case "$key" in - container) - __docker_complete_containers_all --cur "${cur##*=}" - return - ;; - daemon) - local name=$(__docker_q info | sed -n 's/^\(ID\|Name\): //p') - COMPREPLY=( $( compgen -W "$name" -- "${cur##*=}" ) ) - return - ;; - event) - COMPREPLY=( $( compgen -W " - attach - commit - connect - copy - create - delete - destroy - detach - die - disconnect - exec_create - exec_detach - exec_start - export - health_status - import - kill - load - mount - oom - pause - pull - push - reload - rename - resize - restart - save - start - stop - tag - top - unmount - unpause - untag - update - " -- "${cur##*=}" ) ) - return - ;; - image) - cur="${cur##*=}" - __docker_complete_images - return - ;; - network) - __docker_complete_networks --cur "${cur##*=}" - return - ;; - type) - COMPREPLY=( $( compgen -W "container daemon image network volume" -- "${cur##*=}" ) ) - return - ;; - volume) - __docker_complete_volumes --cur "${cur##*=}" - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -S = -W "container daemon event image label network type volume" -- "$cur" ) ) - __docker_nospace - return - ;; - --since|--until) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--filter -f --help --since --until --format" -- "$cur" ) ) - ;; - esac -} - -_docker_system_info() { - case "$prev" in - --format|-f) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) - ;; - esac -} - -_docker_system_prune() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--all -a --force -f --help" -- "$cur" ) ) - ;; - esac -} - - -_docker_tag() { - _docker_image_tag -} - -_docker_unpause() { - _docker_container_unpause -} - -_docker_update() { - _docker_container_update -} - -_docker_top() { - _docker_container_top -} - -_docker_version() { - case "$prev" in - --format|-f) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) - ;; - esac -} - -_docker_volume_create() { - case "$prev" in - --driver|-d) - __docker_complete_plugins_bundled --type Volume - return - ;; - --label|--opt|-o) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--driver -d --help --label --opt -o" -- "$cur" ) ) - ;; - esac -} - -_docker_volume_inspect() { - case "$prev" in - --format|-f) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) - ;; - *) - __docker_complete_volumes - ;; - esac -} - -_docker_volume_ls() { - local key=$(__docker_map_key_of_current_option '--filter|-f') - case "$key" in - dangling) - COMPREPLY=( $( compgen -W "true false" -- "${cur##*=}" ) ) - return - ;; - driver) - __docker_complete_plugins_bundled --cur "${cur##*=}" --type Volume - return - ;; - name) - __docker_complete_volumes --cur "${cur##*=}" - return - ;; - esac - - case "$prev" in - --filter|-f) - COMPREPLY=( $( compgen -S = -W "dangling driver label name" -- "$cur" ) ) - __docker_nospace - return - ;; - --format) - return - ;; - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) ) - ;; - esac -} - -_docker_volume_prune() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) - ;; - esac -} - -_docker_volume_rm() { - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--force -f --help" -- "$cur" ) ) - ;; - *) - __docker_complete_volumes - ;; - esac -} - -_docker_volume() { - local subcommands=" - create - inspect - ls - prune - rm - " - __docker_subcommands "$subcommands" && return - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) - ;; - *) - COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) - ;; - esac -} - -_docker_wait() { - _docker_container_wait -} - -_docker() { - local previous_extglob_setting=$(shopt -p extglob) - shopt -s extglob - - local management_commands=( - container - image - network - node - plugin - secret - service - stack - system - volume - ) - - local top_level_commands=( - build - login - logout - run - search - version - ) - - local legacy_commands=( - commit - cp - create - diff - events - exec - export - history - images - import - info - inspect - kill - load - logs - pause - port - ps - pull - push - rename - restart - rm - rmi - save - start - stats - stop - swarm - tag - top - unpause - update - wait - ) - - local experimental_commands=( - checkpoint - deploy - ) - - local commands=(${management_commands[*]} ${top_level_commands[*]}) - [ -z "$DOCKER_HIDE_LEGACY_COMMANDS" ] && commands+=(${legacy_commands[*]}) - - # These options are valid as global options for all client commands - # and valid as command options for `docker daemon` - local global_boolean_options=" - --debug -D - --tls - --tlsverify - " - local global_options_with_args=" - --config - --host -H - --log-level -l - --tlscacert - --tlscert - --tlskey - " - - local host config - - COMPREPLY=() - local cur prev words cword - _get_comp_words_by_ref -n : cur prev words cword - - local command='docker' command_pos=0 subcommand_pos - local counter=1 - while [ $counter -lt $cword ]; do - case "${words[$counter]}" in - # save host so that completion can use custom daemon - --host|-H) - (( counter++ )) - host="${words[$counter]}" - ;; - # save config so that completion can use custom configuration directories - --config) - (( counter++ )) - config="${words[$counter]}" - ;; - $(__docker_to_extglob "$global_options_with_args") ) - (( counter++ )) - ;; - -*) - ;; - =) - (( counter++ )) - ;; - *) - command="${words[$counter]}" - command_pos=$counter - break - ;; - esac - (( counter++ )) - done - - local binary="${words[0]}" - if [[ $binary == ?(*/)dockerd ]] ; then - # for the dockerd binary, we reuse completion of `docker daemon`. - # dockerd does not have subcommands and global options. - command=daemon - command_pos=0 - fi - - local completions_func=_docker_${command} - declare -F $completions_func >/dev/null && $completions_func - - eval "$previous_extglob_setting" - return 0 -} - -eval "$__docker_previous_extglob_setting" -unset __docker_previous_extglob_setting - -complete -F _docker docker dockerd diff --git a/vendor/github.com/docker/docker/contrib/completion/fish/docker.fish b/vendor/github.com/docker/docker/contrib/completion/fish/docker.fish deleted file mode 100644 index 2715cb1..0000000 --- a/vendor/github.com/docker/docker/contrib/completion/fish/docker.fish +++ /dev/null @@ -1,405 +0,0 @@ -# docker.fish - docker completions for fish shell -# -# This file is generated by gen_docker_fish_completions.py from: -# https://github.com/barnybug/docker-fish-completion -# -# To install the completions: -# mkdir -p ~/.config/fish/completions -# cp docker.fish ~/.config/fish/completions -# -# Completion supported: -# - parameters -# - commands -# - containers -# - images -# - repositories - -function __fish_docker_no_subcommand --description 'Test if docker has yet to be given the subcommand' - for i in (commandline -opc) - if contains -- $i attach build commit cp create diff events exec export history images import info inspect kill load login logout logs pause port ps pull push rename restart rm rmi run save search start stop tag top unpause version wait stats - return 1 - end - end - return 0 -end - -function __fish_print_docker_containers --description 'Print a list of docker containers' -a select - switch $select - case running - docker ps -a --no-trunc | command awk 'NR>1' | command awk 'BEGIN {FS=" +"}; $5 ~ "^Up" {print $1 "\n" $(NF)}' | tr ',' '\n' - case stopped - docker ps -a --no-trunc | command awk 'NR>1' | command awk 'BEGIN {FS=" +"}; $5 ~ "^Exit" {print $1 "\n" $(NF)}' | tr ',' '\n' - case all - docker ps -a --no-trunc | command awk 'NR>1' | command awk 'BEGIN {FS=" +"}; {print $1 "\n" $(NF)}' | tr ',' '\n' - end -end - -function __fish_print_docker_images --description 'Print a list of docker images' - docker images | command awk 'NR>1' | command grep -v '' | command awk '{print $1":"$2}' -end - -function __fish_print_docker_repositories --description 'Print a list of docker repositories' - docker images | command awk 'NR>1' | command grep -v '' | command awk '{print $1}' | command sort | command uniq -end - -# common options -complete -c docker -f -n '__fish_docker_no_subcommand' -l api-cors-header -d "Set CORS headers in the Engine API. Default is cors disabled" -complete -c docker -f -n '__fish_docker_no_subcommand' -s b -l bridge -d 'Attach containers to a pre-existing network bridge' -complete -c docker -f -n '__fish_docker_no_subcommand' -l bip -d "Use this CIDR notation address for the network bridge's IP, not compatible with -b" -complete -c docker -f -n '__fish_docker_no_subcommand' -s D -l debug -d 'Enable debug mode' -complete -c docker -f -n '__fish_docker_no_subcommand' -s d -l daemon -d 'Enable daemon mode' -complete -c docker -f -n '__fish_docker_no_subcommand' -l dns -d 'Force Docker to use specific DNS servers' -complete -c docker -f -n '__fish_docker_no_subcommand' -l dns-opt -d 'Force Docker to use specific DNS options' -complete -c docker -f -n '__fish_docker_no_subcommand' -l dns-search -d 'Force Docker to use specific DNS search domains' -complete -c docker -f -n '__fish_docker_no_subcommand' -l exec-opt -d 'Set runtime execution options' -complete -c docker -f -n '__fish_docker_no_subcommand' -l fixed-cidr -d 'IPv4 subnet for fixed IPs (e.g. 10.20.0.0/16)' -complete -c docker -f -n '__fish_docker_no_subcommand' -l fixed-cidr-v6 -d 'IPv6 subnet for fixed IPs (e.g.: 2001:a02b/48)' -complete -c docker -f -n '__fish_docker_no_subcommand' -s G -l group -d 'Group to assign the unix socket specified by -H when running in daemon mode' -complete -c docker -f -n '__fish_docker_no_subcommand' -s g -l graph -d 'Path to use as the root of the Docker runtime' -complete -c docker -f -n '__fish_docker_no_subcommand' -s H -l host -d 'The socket(s) to bind to in daemon mode or connect to in client mode, specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.' -complete -c docker -f -n '__fish_docker_no_subcommand' -s h -l help -d 'Print usage' -complete -c docker -f -n '__fish_docker_no_subcommand' -l icc -d 'Allow unrestricted inter-container and Docker daemon host communication' -complete -c docker -f -n '__fish_docker_no_subcommand' -l insecure-registry -d 'Enable insecure communication with specified registries (no certificate verification for HTTPS and enable HTTP fallback) (e.g., localhost:5000 or 10.20.0.0/16)' -complete -c docker -f -n '__fish_docker_no_subcommand' -l ip -d 'Default IP address to use when binding container ports' -complete -c docker -f -n '__fish_docker_no_subcommand' -l ip-forward -d 'Enable net.ipv4.ip_forward and IPv6 forwarding if --fixed-cidr-v6 is defined. IPv6 forwarding may interfere with your existing IPv6 configuration when using Router Advertisement.' -complete -c docker -f -n '__fish_docker_no_subcommand' -l ip-masq -d "Enable IP masquerading for bridge's IP range" -complete -c docker -f -n '__fish_docker_no_subcommand' -l iptables -d "Enable Docker's addition of iptables rules" -complete -c docker -f -n '__fish_docker_no_subcommand' -l ipv6 -d 'Enable IPv6 networking' -complete -c docker -f -n '__fish_docker_no_subcommand' -s l -l log-level -d 'Set the logging level ("debug", "info", "warn", "error", "fatal")' -complete -c docker -f -n '__fish_docker_no_subcommand' -l label -d 'Set key=value labels to the daemon (displayed in `docker info`)' -complete -c docker -f -n '__fish_docker_no_subcommand' -l mtu -d 'Set the containers network MTU' -complete -c docker -f -n '__fish_docker_no_subcommand' -s p -l pidfile -d 'Path to use for daemon PID file' -complete -c docker -f -n '__fish_docker_no_subcommand' -l registry-mirror -d 'Specify a preferred Docker registry mirror' -complete -c docker -f -n '__fish_docker_no_subcommand' -s s -l storage-driver -d 'Force the Docker runtime to use a specific storage driver' -complete -c docker -f -n '__fish_docker_no_subcommand' -l selinux-enabled -d 'Enable selinux support. SELinux does not presently support the BTRFS storage driver' -complete -c docker -f -n '__fish_docker_no_subcommand' -l storage-opt -d 'Set storage driver options' -complete -c docker -f -n '__fish_docker_no_subcommand' -l tls -d 'Use TLS; implied by --tlsverify' -complete -c docker -f -n '__fish_docker_no_subcommand' -l tlscacert -d 'Trust only remotes providing a certificate signed by the CA given here' -complete -c docker -f -n '__fish_docker_no_subcommand' -l tlscert -d 'Path to TLS certificate file' -complete -c docker -f -n '__fish_docker_no_subcommand' -l tlskey -d 'Path to TLS key file' -complete -c docker -f -n '__fish_docker_no_subcommand' -l tlsverify -d 'Use TLS and verify the remote (daemon: verify client, client: verify daemon)' -complete -c docker -f -n '__fish_docker_no_subcommand' -s v -l version -d 'Print version information and quit' - -# subcommands -# attach -complete -c docker -f -n '__fish_docker_no_subcommand' -a attach -d 'Attach to a running container' -complete -c docker -A -f -n '__fish_seen_subcommand_from attach' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from attach' -l no-stdin -d 'Do not attach STDIN' -complete -c docker -A -f -n '__fish_seen_subcommand_from attach' -l sig-proxy -d 'Proxy all received signals to the process (non-TTY mode only). SIGCHLD, SIGKILL, and SIGSTOP are not proxied.' -complete -c docker -A -f -n '__fish_seen_subcommand_from attach' -a '(__fish_print_docker_containers running)' -d "Container" - -# build -complete -c docker -f -n '__fish_docker_no_subcommand' -a build -d 'Build an image from a Dockerfile' -complete -c docker -A -f -n '__fish_seen_subcommand_from build' -s f -l file -d "Name of the Dockerfile(Default is 'Dockerfile' at context root)" -complete -c docker -A -f -n '__fish_seen_subcommand_from build' -l force-rm -d 'Always remove intermediate containers, even after unsuccessful builds' -complete -c docker -A -f -n '__fish_seen_subcommand_from build' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from build' -l no-cache -d 'Do not use cache when building the image' -complete -c docker -A -f -n '__fish_seen_subcommand_from build' -l pull -d 'Always attempt to pull a newer version of the image' -complete -c docker -A -f -n '__fish_seen_subcommand_from build' -s q -l quiet -d 'Suppress the build output and print image ID on success' -complete -c docker -A -f -n '__fish_seen_subcommand_from build' -l rm -d 'Remove intermediate containers after a successful build' -complete -c docker -A -f -n '__fish_seen_subcommand_from build' -s t -l tag -d 'Repository name (and optionally a tag) to be applied to the resulting image in case of success' - -# commit -complete -c docker -f -n '__fish_docker_no_subcommand' -a commit -d "Create a new image from a container's changes" -complete -c docker -A -f -n '__fish_seen_subcommand_from commit' -s a -l author -d 'Author (e.g., "John Hannibal Smith ")' -complete -c docker -A -f -n '__fish_seen_subcommand_from commit' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from commit' -s m -l message -d 'Commit message' -complete -c docker -A -f -n '__fish_seen_subcommand_from commit' -s p -l pause -d 'Pause container during commit' -complete -c docker -A -f -n '__fish_seen_subcommand_from commit' -a '(__fish_print_docker_containers all)' -d "Container" - -# cp -complete -c docker -f -n '__fish_docker_no_subcommand' -a cp -d "Copy files/folders between a container and the local filesystem" -complete -c docker -A -f -n '__fish_seen_subcommand_from cp' -l help -d 'Print usage' - -# create -complete -c docker -f -n '__fish_docker_no_subcommand' -a create -d 'Create a new container' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s a -l attach -d 'Attach to STDIN, STDOUT or STDERR.' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l add-host -d 'Add a custom host-to-IP mapping (host:ip)' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l cpu-shares -d 'CPU shares (relative weight)' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l cap-add -d 'Add Linux capabilities' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l cap-drop -d 'Drop Linux capabilities' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l cidfile -d 'Write the container ID to the file' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l cpuset -d 'CPUs in which to allow execution (0-3, 0,1)' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l device -d 'Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm)' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l dns -d 'Set custom DNS servers' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l dns-opt -d "Set custom DNS options (Use --dns-opt='' if you don't wish to set options)" -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l dns-search -d "Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain)" -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s e -l env -d 'Set environment variables' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l entrypoint -d 'Overwrite the default ENTRYPOINT of the image' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l env-file -d 'Read in a line delimited file of environment variables' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l expose -d 'Expose a port or a range of ports (e.g. --expose=3300-3310) from the container without publishing it to your host' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l group-add -d 'Add additional groups to run as' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s h -l hostname -d 'Container host name' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s i -l interactive -d 'Keep STDIN open even if not attached' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l ipc -d 'Default is to create a private IPC namespace (POSIX SysV IPC) for the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l link -d 'Add link to another container in the form of :alias' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s m -l memory -d 'Memory limit (format: [], where unit = b, k, m or g)' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l mac-address -d 'Container MAC address (e.g. 92:d0:c6:0a:29:33)' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l memory-swap -d "Total memory usage (memory + swap), set '-1' to disable swap (format: [], where unit = b, k, m or g)" -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l name -d 'Assign a name to the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l net -d 'Set the Network mode for the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s P -l publish-all -d 'Publish all exposed ports to random ports on the host interfaces' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s p -l publish -d "Publish a container's port to the host" -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l pid -d 'Default is to create a private PID namespace for the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l privileged -d 'Give extended privileges to this container' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l read-only -d "Mount the container's root filesystem as read only" -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l restart -d 'Restart policy to apply when a container exits (no, on-failure[:max-retry], always)' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l security-opt -d 'Security Options' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s t -l tty -d 'Allocate a pseudo-TTY' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s u -l user -d 'Username or UID' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s v -l volume -d 'Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container)' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l volumes-from -d 'Mount volumes from the specified container(s)' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -s w -l workdir -d 'Working directory inside the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -a '(__fish_print_docker_images)' -d "Image" - -# diff -complete -c docker -f -n '__fish_docker_no_subcommand' -a diff -d "Inspect changes on a container's filesystem" -complete -c docker -A -f -n '__fish_seen_subcommand_from diff' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from diff' -a '(__fish_print_docker_containers all)' -d "Container" - -# events -complete -c docker -f -n '__fish_docker_no_subcommand' -a events -d 'Get real time events from the server' -complete -c docker -A -f -n '__fish_seen_subcommand_from events' -s f -l filter -d "Provide filter values (i.e., 'event=stop')" -complete -c docker -A -f -n '__fish_seen_subcommand_from events' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from events' -l since -d 'Show all events created since timestamp' -complete -c docker -A -f -n '__fish_seen_subcommand_from events' -l until -d 'Stream events until this timestamp' -complete -c docker -A -f -n '__fish_seen_subcommand_from events' -l format -d 'Format the output using the given go template' - -# exec -complete -c docker -f -n '__fish_docker_no_subcommand' -a exec -d 'Run a command in a running container' -complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -s d -l detach -d 'Detached mode: run command in the background' -complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -s i -l interactive -d 'Keep STDIN open even if not attached' -complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -s t -l tty -d 'Allocate a pseudo-TTY' -complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -a '(__fish_print_docker_containers running)' -d "Container" - -# export -complete -c docker -f -n '__fish_docker_no_subcommand' -a export -d 'Stream the contents of a container as a tar archive' -complete -c docker -A -f -n '__fish_seen_subcommand_from export' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from export' -a '(__fish_print_docker_containers all)' -d "Container" - -# history -complete -c docker -f -n '__fish_docker_no_subcommand' -a history -d 'Show the history of an image' -complete -c docker -A -f -n '__fish_seen_subcommand_from history' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from history' -l no-trunc -d "Don't truncate output" -complete -c docker -A -f -n '__fish_seen_subcommand_from history' -s q -l quiet -d 'Only show numeric IDs' -complete -c docker -A -f -n '__fish_seen_subcommand_from history' -a '(__fish_print_docker_images)' -d "Image" - -# images -complete -c docker -f -n '__fish_docker_no_subcommand' -a images -d 'List images' -complete -c docker -A -f -n '__fish_seen_subcommand_from images' -s a -l all -d 'Show all images (by default filter out the intermediate image layers)' -complete -c docker -A -f -n '__fish_seen_subcommand_from images' -s f -l filter -d "Provide filter values (i.e., 'dangling=true')" -complete -c docker -A -f -n '__fish_seen_subcommand_from images' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from images' -l no-trunc -d "Don't truncate output" -complete -c docker -A -f -n '__fish_seen_subcommand_from images' -s q -l quiet -d 'Only show numeric IDs' -complete -c docker -A -f -n '__fish_seen_subcommand_from images' -a '(__fish_print_docker_repositories)' -d "Repository" - -# import -complete -c docker -f -n '__fish_docker_no_subcommand' -a import -d 'Create a new filesystem image from the contents of a tarball' -complete -c docker -A -f -n '__fish_seen_subcommand_from import' -l help -d 'Print usage' - -# info -complete -c docker -f -n '__fish_docker_no_subcommand' -a info -d 'Display system-wide information' -complete -c docker -A -f -n '__fish_seen_subcommand_from info' -s f -l format -d 'Format the output using the given go template' -complete -c docker -A -f -n '__fish_seen_subcommand_from info' -l help -d 'Print usage' - -# inspect -complete -c docker -f -n '__fish_docker_no_subcommand' -a inspect -d 'Return low-level information on a container or image' -complete -c docker -A -f -n '__fish_seen_subcommand_from inspect' -s f -l format -d 'Format the output using the given go template.' -complete -c docker -A -f -n '__fish_seen_subcommand_from inspect' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from inspect' -s s -l size -d 'Display total file sizes if the type is container.' -complete -c docker -A -f -n '__fish_seen_subcommand_from inspect' -a '(__fish_print_docker_images)' -d "Image" -complete -c docker -A -f -n '__fish_seen_subcommand_from inspect' -a '(__fish_print_docker_containers all)' -d "Container" - -# kill -complete -c docker -f -n '__fish_docker_no_subcommand' -a kill -d 'Kill a running container' -complete -c docker -A -f -n '__fish_seen_subcommand_from kill' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from kill' -s s -l signal -d 'Signal to send to the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from kill' -a '(__fish_print_docker_containers running)' -d "Container" - -# load -complete -c docker -f -n '__fish_docker_no_subcommand' -a load -d 'Load an image from a tar archive' -complete -c docker -A -f -n '__fish_seen_subcommand_from load' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from load' -s i -l input -d 'Read from a tar archive file, instead of STDIN' - -# login -complete -c docker -f -n '__fish_docker_no_subcommand' -a login -d 'Log in to a Docker registry server' -complete -c docker -A -f -n '__fish_seen_subcommand_from login' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from login' -s p -l password -d 'Password' -complete -c docker -A -f -n '__fish_seen_subcommand_from login' -s u -l username -d 'Username' - -# logout -complete -c docker -f -n '__fish_docker_no_subcommand' -a logout -d 'Log out from a Docker registry server' - -# logs -complete -c docker -f -n '__fish_docker_no_subcommand' -a logs -d 'Fetch the logs of a container' -complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -s f -l follow -d 'Follow log output' -complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -s t -l timestamps -d 'Show timestamps' -complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -l since -d 'Show logs since timestamp' -complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -l tail -d 'Output the specified number of lines at the end of logs (defaults to all logs)' -complete -c docker -A -f -n '__fish_seen_subcommand_from logs' -a '(__fish_print_docker_containers running)' -d "Container" - -# port -complete -c docker -f -n '__fish_docker_no_subcommand' -a port -d 'Lookup the public-facing port that is NAT-ed to PRIVATE_PORT' -complete -c docker -A -f -n '__fish_seen_subcommand_from port' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from port' -a '(__fish_print_docker_containers running)' -d "Container" - -# pause -complete -c docker -f -n '__fish_docker_no_subcommand' -a pause -d 'Pause all processes within a container' -complete -c docker -A -f -n '__fish_seen_subcommand_from pause' -a '(__fish_print_docker_containers running)' -d "Container" - -# ps -complete -c docker -f -n '__fish_docker_no_subcommand' -a ps -d 'List containers' -complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s a -l all -d 'Show all containers. Only running containers are shown by default.' -complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -l before -d 'Show only container created before Id or Name, include non-running ones.' -complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s f -l filter -d 'Provide filter values. Valid filters:' -complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s l -l latest -d 'Show only the latest created container, include non-running ones.' -complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s n -d 'Show n last created containers, include non-running ones.' -complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -l no-trunc -d "Don't truncate output" -complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s q -l quiet -d 'Only display numeric IDs' -complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s s -l size -d 'Display total file sizes' -complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -l since -d 'Show only containers created since Id or Name, include non-running ones.' - -# pull -complete -c docker -f -n '__fish_docker_no_subcommand' -a pull -d 'Pull an image or a repository from a Docker registry server' -complete -c docker -A -f -n '__fish_seen_subcommand_from pull' -s a -l all-tags -d 'Download all tagged images in the repository' -complete -c docker -A -f -n '__fish_seen_subcommand_from pull' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from pull' -a '(__fish_print_docker_images)' -d "Image" -complete -c docker -A -f -n '__fish_seen_subcommand_from pull' -a '(__fish_print_docker_repositories)' -d "Repository" - -# push -complete -c docker -f -n '__fish_docker_no_subcommand' -a push -d 'Push an image or a repository to a Docker registry server' -complete -c docker -A -f -n '__fish_seen_subcommand_from push' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from push' -a '(__fish_print_docker_images)' -d "Image" -complete -c docker -A -f -n '__fish_seen_subcommand_from push' -a '(__fish_print_docker_repositories)' -d "Repository" - -# rename -complete -c docker -f -n '__fish_docker_no_subcommand' -a rename -d 'Rename an existing container' - -# restart -complete -c docker -f -n '__fish_docker_no_subcommand' -a restart -d 'Restart a container' -complete -c docker -A -f -n '__fish_seen_subcommand_from restart' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from restart' -s t -l time -d 'Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default is 10 seconds.' -complete -c docker -A -f -n '__fish_seen_subcommand_from restart' -a '(__fish_print_docker_containers running)' -d "Container" - -# rm -complete -c docker -f -n '__fish_docker_no_subcommand' -a rm -d 'Remove one or more containers' -complete -c docker -A -f -n '__fish_seen_subcommand_from rm' -s f -l force -d 'Force the removal of a running container (uses SIGKILL)' -complete -c docker -A -f -n '__fish_seen_subcommand_from rm' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from rm' -s l -l link -d 'Remove the specified link and not the underlying container' -complete -c docker -A -f -n '__fish_seen_subcommand_from rm' -s v -l volumes -d 'Remove the volumes associated with the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from rm' -a '(__fish_print_docker_containers stopped)' -d "Container" -complete -c docker -A -f -n '__fish_seen_subcommand_from rm' -s f -l force -a '(__fish_print_docker_containers all)' -d "Container" - -# rmi -complete -c docker -f -n '__fish_docker_no_subcommand' -a rmi -d 'Remove one or more images' -complete -c docker -A -f -n '__fish_seen_subcommand_from rmi' -s f -l force -d 'Force removal of the image' -complete -c docker -A -f -n '__fish_seen_subcommand_from rmi' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from rmi' -l no-prune -d 'Do not delete untagged parents' -complete -c docker -A -f -n '__fish_seen_subcommand_from rmi' -a '(__fish_print_docker_images)' -d "Image" - -# run -complete -c docker -f -n '__fish_docker_no_subcommand' -a run -d 'Run a command in a new container' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s a -l attach -d 'Attach to STDIN, STDOUT or STDERR.' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l add-host -d 'Add a custom host-to-IP mapping (host:ip)' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s c -l cpu-shares -d 'CPU shares (relative weight)' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l cap-add -d 'Add Linux capabilities' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l cap-drop -d 'Drop Linux capabilities' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l cidfile -d 'Write the container ID to the file' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l cpuset -d 'CPUs in which to allow execution (0-3, 0,1)' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s d -l detach -d 'Detached mode: run the container in the background and print the new container ID' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l device -d 'Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm)' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l dns -d 'Set custom DNS servers' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l dns-opt -d "Set custom DNS options (Use --dns-opt='' if you don't wish to set options)" -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l dns-search -d "Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain)" -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s e -l env -d 'Set environment variables' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l entrypoint -d 'Overwrite the default ENTRYPOINT of the image' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l env-file -d 'Read in a line delimited file of environment variables' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l expose -d 'Expose a port or a range of ports (e.g. --expose=3300-3310) from the container without publishing it to your host' -complete -c docker -A -f -n '__fish_seen_subcommand_from create' -l group-add -d 'Add additional groups to run as' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s h -l hostname -d 'Container host name' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s i -l interactive -d 'Keep STDIN open even if not attached' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l ipc -d 'Default is to create a private IPC namespace (POSIX SysV IPC) for the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l link -d 'Add link to another container in the form of :alias' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s m -l memory -d 'Memory limit (format: [], where unit = b, k, m or g)' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l mac-address -d 'Container MAC address (e.g. 92:d0:c6:0a:29:33)' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l memory-swap -d "Total memory usage (memory + swap), set '-1' to disable swap (format: [], where unit = b, k, m or g)" -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l name -d 'Assign a name to the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l net -d 'Set the Network mode for the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s P -l publish-all -d 'Publish all exposed ports to random ports on the host interfaces' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s p -l publish -d "Publish a container's port to the host" -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l pid -d 'Default is to create a private PID namespace for the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l privileged -d 'Give extended privileges to this container' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l read-only -d "Mount the container's root filesystem as read only" -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l restart -d 'Restart policy to apply when a container exits (no, on-failure[:max-retry], always)' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l rm -d 'Automatically remove the container when it exits (incompatible with -d)' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l security-opt -d 'Security Options' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l sig-proxy -d 'Proxy received signals to the process (non-TTY mode only). SIGCHLD, SIGSTOP, and SIGKILL are not proxied.' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l stop-signal -d 'Signal to kill a container' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s t -l tty -d 'Allocate a pseudo-TTY' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s u -l user -d 'Username or UID' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l tmpfs -d 'Mount tmpfs on a directory' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s v -l volume -d 'Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container)' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l volumes-from -d 'Mount volumes from the specified container(s)' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -s w -l workdir -d 'Working directory inside the container' -complete -c docker -A -f -n '__fish_seen_subcommand_from run' -a '(__fish_print_docker_images)' -d "Image" - -# save -complete -c docker -f -n '__fish_docker_no_subcommand' -a save -d 'Save an image to a tar archive' -complete -c docker -A -f -n '__fish_seen_subcommand_from save' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from save' -s o -l output -d 'Write to an file, instead of STDOUT' -complete -c docker -A -f -n '__fish_seen_subcommand_from save' -a '(__fish_print_docker_images)' -d "Image" - -# search -complete -c docker -f -n '__fish_docker_no_subcommand' -a search -d 'Search for an image on the registry (defaults to the Docker Hub)' -complete -c docker -A -f -n '__fish_seen_subcommand_from search' -l automated -d 'Only show automated builds' -complete -c docker -A -f -n '__fish_seen_subcommand_from search' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from search' -l no-trunc -d "Don't truncate output" -complete -c docker -A -f -n '__fish_seen_subcommand_from search' -s s -l stars -d 'Only displays with at least x stars' - -# start -complete -c docker -f -n '__fish_docker_no_subcommand' -a start -d 'Start a container' -complete -c docker -A -f -n '__fish_seen_subcommand_from start' -s a -l attach -d "Attach container's STDOUT and STDERR and forward all signals to the process" -complete -c docker -A -f -n '__fish_seen_subcommand_from start' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from start' -s i -l interactive -d "Attach container's STDIN" -complete -c docker -A -f -n '__fish_seen_subcommand_from start' -a '(__fish_print_docker_containers stopped)' -d "Container" - -# stats -complete -c docker -f -n '__fish_docker_no_subcommand' -a stats -d "Display a live stream of one or more containers' resource usage statistics" -complete -c docker -A -f -n '__fish_seen_subcommand_from stats' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from stats' -l no-stream -d 'Disable streaming stats and only pull the first result' -complete -c docker -A -f -n '__fish_seen_subcommand_from stats' -a '(__fish_print_docker_containers running)' -d "Container" - -# stop -complete -c docker -f -n '__fish_docker_no_subcommand' -a stop -d 'Stop a container' -complete -c docker -A -f -n '__fish_seen_subcommand_from stop' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from stop' -s t -l time -d 'Number of seconds to wait for the container to stop before killing it. Default is 10 seconds.' -complete -c docker -A -f -n '__fish_seen_subcommand_from stop' -a '(__fish_print_docker_containers running)' -d "Container" - -# tag -complete -c docker -f -n '__fish_docker_no_subcommand' -a tag -d 'Tag an image into a repository' -complete -c docker -A -f -n '__fish_seen_subcommand_from tag' -s f -l force -d 'Force' -complete -c docker -A -f -n '__fish_seen_subcommand_from tag' -l help -d 'Print usage' - -# top -complete -c docker -f -n '__fish_docker_no_subcommand' -a top -d 'Lookup the running processes of a container' -complete -c docker -A -f -n '__fish_seen_subcommand_from top' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from top' -a '(__fish_print_docker_containers running)' -d "Container" - -# unpause -complete -c docker -f -n '__fish_docker_no_subcommand' -a unpause -d 'Unpause a paused container' -complete -c docker -A -f -n '__fish_seen_subcommand_from unpause' -a '(__fish_print_docker_containers running)' -d "Container" - -# version -complete -c docker -f -n '__fish_docker_no_subcommand' -a version -d 'Show the Docker version information' -complete -c docker -A -f -n '__fish_seen_subcommand_from version' -s f -l format -d 'Format the output using the given go template' -complete -c docker -A -f -n '__fish_seen_subcommand_from version' -l help -d 'Print usage' - -# wait -complete -c docker -f -n '__fish_docker_no_subcommand' -a wait -d 'Block until a container stops, then print its exit code' -complete -c docker -A -f -n '__fish_seen_subcommand_from wait' -l help -d 'Print usage' -complete -c docker -A -f -n '__fish_seen_subcommand_from wait' -a '(__fish_print_docker_containers running)' -d "Container" diff --git a/vendor/github.com/docker/docker/contrib/completion/powershell/readme.txt b/vendor/github.com/docker/docker/contrib/completion/powershell/readme.txt deleted file mode 100644 index 18e1b53..0000000 --- a/vendor/github.com/docker/docker/contrib/completion/powershell/readme.txt +++ /dev/null @@ -1 +0,0 @@ -See https://github.com/samneirinck/posh-docker \ No newline at end of file diff --git a/vendor/github.com/docker/docker/contrib/completion/zsh/REVIEWERS b/vendor/github.com/docker/docker/contrib/completion/zsh/REVIEWERS deleted file mode 100644 index 03ee2dd..0000000 --- a/vendor/github.com/docker/docker/contrib/completion/zsh/REVIEWERS +++ /dev/null @@ -1,2 +0,0 @@ -Tianon Gravi (@tianon) -Jessie Frazelle (@jfrazelle) diff --git a/vendor/github.com/docker/docker/contrib/completion/zsh/_docker b/vendor/github.com/docker/docker/contrib/completion/zsh/_docker deleted file mode 100644 index ecae826..0000000 --- a/vendor/github.com/docker/docker/contrib/completion/zsh/_docker +++ /dev/null @@ -1,2787 +0,0 @@ -#compdef docker dockerd -# -# zsh completion for docker (http://docker.com) -# -# version: 0.3.0 -# github: https://github.com/felixr/docker-zsh-completion -# -# contributors: -# - Felix Riedel -# - Steve Durrheimer -# - Vincent Bernat -# -# license: -# -# Copyright (c) 2013, Felix Riedel -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of the nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# - -# Short-option stacking can be enabled with: -# zstyle ':completion:*:*:docker:*' option-stacking yes -# zstyle ':completion:*:*:docker-*:*' option-stacking yes -__docker_arguments() { - if zstyle -t ":completion:${curcontext}:" option-stacking; then - print -- -s - fi -} - -__docker_get_containers() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local kind type line s - declare -a running stopped lines args names - - kind=$1; shift - type=$1; shift - [[ $kind = (stopped|all) ]] && args=($args -a) - - lines=(${(f)${:-"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line - lines=(${lines[2,-1]}) - - # Container ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}" - s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" - s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" - if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then - stopped=($stopped $s) - else - running=($running $s) - fi - done - fi - - # Names: we only display the one without slash. All other names - # are generated and may clutter the completion. However, with - # Swarm, all names may be prefixed by the swarm node name. - if [[ $type = (names|all) ]]; then - for line in $lines; do - names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}}) - # First step: find a common prefix and strip it (swarm node case) - (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/} - # Second step: only keep the first name without a / - s=${${names:#*/*}[1]} - # If no name, well give up. - (( $#s != 0 )) || continue - s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" - s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" - if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then - stopped=($stopped $s) - else - running=($running $s) - fi - done - fi - - [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0 - [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0 - return ret -} - -__docker_complete_stopped_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers stopped all "$@" -} - -__docker_complete_running_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers running all "$@" -} - -__docker_complete_containers() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all all "$@" -} - -__docker_complete_containers_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all ids "$@" -} - -__docker_complete_containers_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_containers all names "$@" -} - -__docker_complete_info_plugins() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - emulate -L zsh - setopt extendedglob - local -a plugins - plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: }) - _describe -t plugins "$1 plugins" plugins && ret=0 - return ret -} - -__docker_complete_images() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a images - images=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) - _describe -t docker-images "images" images && ret=0 - __docker_complete_repositories_with_tags && ret=0 - return ret -} - -__docker_complete_repositories() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a repos - repos=(${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}%% *}[2,-1]}) - repos=(${repos#}) - _describe -t docker-repos "repositories" repos && ret=0 - return ret -} - -__docker_complete_repositories_with_tags() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a repos onlyrepos matched - declare m - repos=(${${${${(f)${:-"$(_call_program commands docker $docker_options images)"$'\n'}}[2,-1]}/ ##/:::}%% *}) - repos=(${${repos%:::}#}) - # Check if we have a prefix-match for the current prefix. - onlyrepos=(${repos%::*}) - for m in $onlyrepos; do - [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { - # Yes, complete with tags - repos=(${${repos/:::/:}/:/\\:}) - _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 - return ret - } - done - # No, only complete repositories - onlyrepos=(${${repos%:::*}/:/\\:}) - _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 - - return ret -} - -__docker_search() { - [[ $PREFIX = -* ]] && return 1 - local cache_policy - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy - fi - - local searchterm cachename - searchterm="${words[$CURRENT]%/}" - cachename=_docker-search-$searchterm - - local expl - local -a result - if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ - && ! _retrieve_cache ${cachename#_}; then - _message "Searching for ${searchterm}..." - result=(${${${(f)${:-"$(_call_program commands docker $docker_options search $searchterm)"$'\n'}}%% *}[2,-1]}) - _store_cache ${cachename#_} result - fi - _wanted dockersearch expl 'available images' compadd -a result -} - -__docker_get_log_options() { - [[ $PREFIX = -* ]] && return 1 - - integer ret=1 - local log_driver=${opt_args[--log-driver]:-"all"} - local -a awslogs_options fluentd_options gelf_options journald_options json_file_options logentries_options syslog_options splunk_options - - awslogs_options=("awslogs-region" "awslogs-group" "awslogs-stream") - fluentd_options=("env" "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "labels" "tag") - gcplogs_options=("env" "gcp-log-cmd" "gcp-project" "labels") - gelf_options=("env" "gelf-address" "gelf-compression-level" "gelf-compression-type" "labels" "tag") - journald_options=("env" "labels" "tag") - json_file_options=("env" "labels" "max-file" "max-size") - logentries_options=("logentries-token") - syslog_options=("env" "labels" "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag") - splunk_options=("env" "labels" "splunk-caname" "splunk-capath" "splunk-format" "splunk-gzip" "splunk-gzip-level" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag") - - [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 - [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 - [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0 - [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 - [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 - [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 - [[ $log_driver = (logentries|all) ]] && _describe -t logentries-options "logentries options" logentries_options "$@" && ret=0 - [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 - [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 - - return ret -} - -__docker_complete_log_drivers() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog) - _describe -t log-drivers "log drivers" drivers && ret=0 - return ret -} - -__docker_complete_log_options() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (syslog-format) - syslog_format_opts=('rfc3164' 'rfc5424' 'rfc5424micro') - _describe -t syslog-format-opts "Syslog format Options" syslog_format_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - __docker_get_log_options -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_detach_keys() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - compset -P "*," - keys=(${:-{a-z}}) - ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}}) - _describe -t detach_keys "[a-z]" keys -qS "," && ret=0 - _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0 -} - -__docker_complete_pid() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local -a opts vopts - - opts=('host') - vopts=('container') - - if compset -P '*:'; then - case "${${words[-1]%:*}#*=}" in - (container) - __docker_complete_running_containers && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0 - _describe -t pid-opts "PID Options" opts && ret=0 - fi - - return ret -} - -__docker_complete_runtimes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - emulate -L zsh - setopt extendedglob - local -a runtimes_opts - runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}}) - _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0 -} - -__docker_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (ancestor) - __docker_complete_images && ret=0 - ;; - (before|since) - __docker_complete_containers && ret=0 - ;; - (health) - health_opts=('healthy' 'none' 'starting' 'unhealthy') - _describe -t health-filter-opts "health filter options" health_opts && ret=0 - ;; - (id) - __docker_complete_containers_ids && ret=0 - ;; - (is-task) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - (name) - __docker_complete_containers_names && ret=0 - ;; - (network) - __docker_complete_networks && ret=0 - ;; - (status) - status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing') - _describe -t status-filter-opts "status filter options" status_opts && ret=0 - ;; - (volume) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('ancestor' 'before' 'exited' 'health' 'id' 'label' 'name' 'network' 'since' 'status' 'volume') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_search_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a boolean_opts opts - - boolean_opts=('true' 'false') - opts=('is-automated' 'is-official' 'stars') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (is-automated|is-official) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_images_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a boolean_opts opts - - boolean_opts=('true' 'false') - opts=('before' 'dangling' 'label' 'reference' 'since') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (before|reference|since) - __docker_complete_images && ret=0 - ;; - (dangling) - _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_events_filter() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a opts - - opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'type' 'volume') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (container) - __docker_complete_containers && ret=0 - ;; - (daemon) - emulate -L zsh - setopt extendedglob - local -a daemon_opts - daemon_opts=( - ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}} - ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:} - ) - _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0 - ;; - (event) - local -a event_opts - event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disconnect' 'exec_create' 'exec_detach' - 'exec_start' 'export' 'health_status' 'import' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'rename' 'resize' 'restart' 'save' 'start' - 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update') - _describe -t event-filter-opts "event filter options" event_opts && ret=0 - ;; - (image) - __docker_complete_images && ret=0 - ;; - (network) - __docker_complete_networks && ret=0 - ;; - (type) - local -a type_opts - type_opts=('container' 'daemon' 'image' 'network' 'volume') - _describe -t type-filter-opts "type filter options" type_opts && ret=0 - ;; - (volume) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_prune_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a opts - - opts=('until') - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - *) - _message 'value' && ret=0 - ;; - esac - else - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -# BO container - -__docker_container_commands() { - local -a _docker_container_subcommands - _docker_container_subcommands=( - "attach:Attach to a running container" - "commit:Create a new image from a container's changes" - "cp:Copy files/folders between a container and the local filesystem" - "create:Create a new container" - "diff:Inspect changes on a container's filesystem" - "exec:Run a command in a running container" - "export:Export a container's filesystem as a tar archive" - "inspect:Display detailed information on one or more containers" - "kill:Kill one or more running containers" - "logs:Fetch the logs of a container" - "ls:List containers" - "pause:Pause all processes within one or more containers" - "port:List port mappings or a specific mapping for the container" - "prune:Remove all stopped containers" - "rename:Rename a container" - "restart:Restart one or more containers" - "rm:Remove one or more containers" - "run:Run a command in a new container" - "start:Start one or more stopped containers" - "stats:Display a live stream of container(s) resource usage statistics" - "stop:Stop one or more running containers" - "top:Display the running processes of a container" - "unpause:Unpause all processes within one or more containers" - "update:Update configuration of one or more containers" - "wait:Block until one or more containers stop, then print their exit codes" - ) - _describe -t docker-container-commands "docker container command" _docker_container_subcommands -} - -__docker_container_subcommand() { - local -a _command_args opts_help opts_attach_exec_run_start opts_create_run opts_create_run_update - local expl help="--help" - integer ret=1 - - opts_attach_exec_run_start=( - "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys" - ) - opts_create_run=( - "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" - "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " - "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " - "($help)*--cap-add=[Add Linux capabilities]:capability: " - "($help)*--cap-drop=[Drop Linux capabilities]:capability: " - "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " - "($help)--cidfile=[Write the container ID to the file]:CID file:_files" - "($help)--cpus=[Number of CPUs (default 0.000)]:cpus: " - "($help)*--device=[Add a host device to the container]:device:_files" - "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " - "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " - "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " - "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " - "($help)--disable-content-trust[Skip image verification]" - "($help)*--dns=[Custom DNS servers]:DNS server: " - "($help)*--dns-option=[Custom DNS options]:DNS option: " - "($help)*--dns-search=[Custom DNS search domains]:DNS domains: " - "($help)*"{-e=,--env=}"[Environment variables]:environment variable: " - "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " - "($help)*--env-file=[Read environment variables from a file]:environment file:_files" - "($help)*--expose=[Expose a port from the container without publishing it]: " - "($help)*--group=[Set one or more supplementary user groups for the container]:group:_groups" - "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" - "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" - "($help)--init[Run an init inside the container that forwards signals and reaps processes]" - "($help)--ip=[Container IPv4 address]:IPv4: " - "($help)--ip6=[Container IPv6 address]:IPv6: " - "($help)--ipc=[IPC namespace to use]:IPC namespace: " - "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" - "($help)*--link=[Add link to another container]:link:->link" - "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " - "($help)*"{-l=,--label=}"[Container metadata]:label: " - "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" - "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_complete_log_options" - "($help)--mac-address=[Container MAC address]:MAC address: " - "($help)--name=[Container name]:name: " - "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" - "($help)*--network-alias=[Add network-scoped alias for the container]:alias: " - "($help)--oom-kill-disable[Disable OOM Killer]" - "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" - "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" - "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" - "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" - "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid" - "($help)--privileged[Give extended privileges to this container]" - "($help)--read-only[Mount the container's root filesystem as read only]" - "($help)*--security-opt=[Security options]:security option: " - "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " - "($help)--stop-timeout=[Timeout (in seconds) to stop a container]:time: " - "($help)*--sysctl=-[sysctl options]:sysctl: " - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" - "($help)*--ulimit=[ulimit options]:ulimit: " - "($help)--userns=[Container user namespace]:user namespace:(host)" - "($help)--tmpfs[mount tmpfs]" - "($help)*-v[Bind mount a volume]:volume: " - "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" - "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " - "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" - ) - opts_create_run_update=( - "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" - "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" - "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " - "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " - "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " - "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " - "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " - "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " - "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: " - "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " - "($help)--memory-reservation=[Memory soft limit]:Memory limit: " - "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " - "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" - ) - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (attach) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help)--no-stdin[Do not attach stdin]" \ - "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ - "($help -):containers:__docker_complete_running_containers" && ret=0 - ;; - (commit) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --author)"{-a=,--author=}"[Author]:author: " \ - "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ - "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ - "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ - "($help -):container:__docker_complete_containers" \ - "($help -): :__docker_complete_repositories_with_tags" && ret=0 - ;; - (cp) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \ - "($help -)1:container:->container" \ - "($help -)2:hostpath:_files" && ret=0 - case $state in - (container) - if compset -P "*:"; then - _files && ret=0 - else - __docker_complete_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (create) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_run \ - $opts_create_run_update \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (diff) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (exec) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ - "($help)*"{-e=,--env=}"[Set environment variables]:environment variable: " \ - "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ - "($help)--privileged[Give extended Linux capabilities to the command]" \ - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ - "($help -):containers:__docker_complete_running_containers" \ - "($help -)*::command:->anycommand" && ret=0 - case $state in - (anycommand) - shift 1 words - (( CURRENT-- )) - _normal && ret=0 - ;; - esac - ;; - (export) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -s --size)"{-s,--size}"[Display total file sizes]" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (kill) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (logs) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--details[Show extra details provided to logs]" \ - "($help -f --follow)"{-f,--follow}"[Follow log output]" \ - "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ - "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ - "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \ - "($help -)*:containers:__docker_complete_containers" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all containers]" \ - "($help)--before=[Show only container created before...]:containers:__docker_complete_containers" \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \ - "($help)--format=[Pretty-print containers using a Go template]:template: " \ - "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ - "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ - "($help -s --size)"{-s,--size}"[Display total file sizes]" \ - "($help)--since=[Show only containers created since...]:containers:__docker_complete_containers" && ret=0 - ;; - (pause|unpause) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (port) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:containers:__docker_complete_running_containers" \ - "($help -)2:port:_ports" && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rename) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):old name:__docker_complete_containers" \ - "($help -):new name: " && ret=0 - ;; - (restart) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ - "($help -)*:containers:__docker_complete_containers_ids" && ret=0 - ;; - (rm) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force removal]" \ - "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ - "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ - "($help -)*:containers:->values" && ret=0 - case $state in - (values) - if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then - __docker_complete_containers && ret=0 - else - __docker_complete_stopped_containers && ret=0 - fi - ;; - esac - ;; - (run) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_run \ - $opts_create_run_update \ - $opts_attach_exec_run_start \ - "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ - "($help)--health-cmd=[Command to run to check health]:command: " \ - "($help)--health-interval=[Time between running the check]:time: " \ - "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \ - "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \ - "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \ - "($help)--rm[Remove intermediate containers when it exits]" \ - "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \ - "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ - "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \ - "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - (storage-opt) - if compset -P "*="; then - _message "value" && ret=0 - else - opts=('size') - _describe -t filter-opts "storage options" opts -qS "=" && ret=0 - fi - ;; - esac - ;; - (start) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_attach_exec_run_start \ - "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ - "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \ - "($help -)*:containers:__docker_complete_stopped_containers" && ret=0 - ;; - (stats) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ - "($help)--format=[Pretty-print images using a Go template]:template: " \ - "($help)--no-stream[Disable streaming stats and only pull the first result]" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (stop) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (top) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:containers:__docker_complete_running_containers" \ - "($help -)*:: :->ps-arguments" && ret=0 - case $state in - (ps-arguments) - _ps && ret=0 - ;; - esac - ;; - (update) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - opts_create_run_update \ - "($help -)*: :->values" && ret=0 - case $state in - (values) - if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then - __docker_complete_stopped_containers && ret=0 - else - __docker_complete_containers && ret=0 - fi - ;; - esac - ;; - (wait) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:containers:__docker_complete_running_containers" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 - ;; - esac - - return ret -} - -# EO container - -# BO image - -__docker_image_commands() { - local -a _docker_image_subcommands - _docker_image_subcommands=( - "build:Build an image from a Dockerfile" - "history:Show the history of an image" - "import:Import the contents from a tarball to create a filesystem image" - "inspect:Display detailed information on one or more images" - "load:Load an image from a tar archive or STDIN" - "ls:List images" - "prune:Remove unused images" - "pull:Pull an image or a repository from a registry" - "push:Push an image or a repository to a registry" - "rm:Remove one or more images" - "save:Save one or more images to a tar archive (streamed to STDOUT by default)" - "tag:Tag an image into a repository" - ) - _describe -t docker-image-commands "docker image command" _docker_image_subcommands -} - -__docker_image_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (build) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--build-arg=[Build-time variables]:=: " \ - "($help)*--cache-from=[Images to consider as cache sources]: :__docker_complete_repositories_with_tags" \ - "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" \ - "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " \ - "($help)--compress[Compress the build context using gzip]" \ - "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " \ - "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " \ - "($help)--cpu-rt-period=[Limit the CPU real-time period]:CPU real-time period in microseconds: " \ - "($help)--cpu-rt-runtime=[Limit the CPU real-time runtime]:CPU real-time runtime in microseconds: " \ - "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " \ - "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " \ - "($help)--disable-content-trust[Skip image verification]" \ - "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ - "($help)--force-rm[Always remove intermediate containers]" \ - "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" \ - "($help)*--label=[Set metadata for an image]:label=value: " \ - "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " \ - "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " \ - "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" \ - "($help)--no-cache[Do not use cache when building the image]" \ - "($help)--pull[Attempt to pull a newer version of the image]" \ - "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ - "($help)--rm[Remove intermediate containers after a successful build]" \ - "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " \ - "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_complete_repositories_with_tags" \ - "($help)*--ulimit=[ulimit options]:ulimit: " \ - "($help)--userns=[Container user namespace]:user namespace:(host)" \ - "($help -):path or URL:_directories" && ret=0 - ;; - (history) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (import) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ - "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \ - "($help -):URL:(- http:// file://)" \ - "($help -): :__docker_complete_repositories_with_tags" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -)*:images:__docker_complete_images" && ret=0 - ;; - (load) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -i --input)"{-i=,--input=}"[Read from tar archive file]:archive file:_files -g \"*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)\"" \ - "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0 - ;; - (ls|list) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Show all images]" \ - "($help)--digests[Show digests]" \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \ - "($help)--format=[Pretty-print images using a Go template]:template: " \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ - "($help -): :__docker_complete_repositories" && ret=0 - case $state in - (filter-options) - __docker_complete_images_filters && ret=0 - ;; - esac - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Remove all unused images, not just dangling ones]" \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (pull) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ - "($help)--disable-content-trust[Skip image verification]" \ - "($help -):name:__docker_search" && ret=0 - ;; - (push) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--disable-content-trust[Skip image signing]" \ - "($help -): :__docker_complete_images" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force removal]" \ - "($help)--no-prune[Do not delete untagged parents]" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (save) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ - "($help -)*: :__docker_complete_images" && ret=0 - ;; - (tag) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):source:__docker_complete_images"\ - "($help -):destination:__docker_complete_repositories_with_tags" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_container_commands" && ret=0 - ;; - esac - - return ret -} - -# EO image - -# BO network - -__docker_network_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (driver) - __docker_complete_info_plugins Network && ret=0 - ;; - (id) - __docker_complete_networks_ids && ret=0 - ;; - (name) - __docker_complete_networks_names && ret=0 - ;; - (type) - type_opts=('builtin' 'custom') - _describe -t type-filter-opts "Type Filter Options" type_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('driver' 'id' 'label' 'name' 'type') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_get_networks() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines networks - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options network ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Network ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" - networks=($networks $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - s="$s, ${${line[${begin[SCOPE]},${end[SCOPE]}]}%% ##}" - networks=($networks $s) - done - fi - - _describe -t networks-list "networks" networks "$@" && ret=0 - return ret -} - -__docker_complete_networks() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks all "$@" -} - -__docker_complete_networks_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks ids "$@" -} - -__docker_complete_networks_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_get_networks names "$@" -} - -__docker_network_commands() { - local -a _docker_network_subcommands - _docker_network_subcommands=( - "connect:Connect a container to a network" - "create:Creates a new network with a name specified by the user" - "disconnect:Disconnects a container from a network" - "inspect:Displays detailed information on a network" - "ls:Lists all the networks created by the user" - "prune:Remove all unused networks" - "rm:Deletes one or more networks" - ) - _describe -t docker-network-commands "docker network command" _docker_network_subcommands -} - -__docker_network_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (connect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--alias=[Add network-scoped alias for the container]:alias: " \ - "($help)--ip=[Container IPv4 address]:IPv4: " \ - "($help)--ip6=[Container IPv6 address]:IPv6: " \ - "($help)*--link=[Add a link to another container]:link:->link" \ - "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \ - "($help -)1:network:__docker_complete_networks" \ - "($help -)2:containers:__docker_complete_containers" && ret=0 - - case $state in - (link) - if compset -P "*:"; then - _wanted alias expl "Alias" compadd -E "" && ret=0 - else - __docker_complete_running_containers -qS ":" && ret=0 - fi - ;; - esac - ;; - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)--attachable[Enable manual container attachment]" \ - "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \ - "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ - "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \ - "($help)--internal[Restricts external access to the network]" \ - "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ - "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ - "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \ - "($help)--ipv6[Enable IPv6 networking]" \ - "($help)*--label=[Set metadata on a network]:label=value: " \ - "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \ - "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ - "($help -)1:Network Name: " && ret=0 - ;; - (disconnect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:network:__docker_complete_networks" \ - "($help -)2:containers:__docker_complete_containers" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -)*:network:__docker_complete_networks" && ret=0 - ;; - (ls) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--no-trunc[Do not truncate the output]" \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ - "($help)--format=[Pretty-print networks using a Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0 - case $state in - (filter-options) - __docker_network_complete_ls_filters && ret=0 - ;; - esac - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:network:__docker_complete_networks" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 - ;; - esac - - return ret -} - -# EO network - -# BO node - -__docker_node_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (id) - __docker_complete_nodes_ids && ret=0 - ;; - (membership) - membership_opts=('accepted' 'pending' 'rejected') - _describe -t membership-opts "membership options" membership_opts && ret=0 - ;; - (name) - __docker_complete_nodes_names && ret=0 - ;; - (role) - role_opts=('manager' 'worker') - _describe -t role-opts "role options" role_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'membership' 'name' 'role') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_node_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_nodes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines nodes args - - type=$1; shift - filter=$1; shift - [[ $filter != "none" ]] && args=("-f $filter") - - lines=(${(f)${:-"$(_call_program commands docker $docker_options node ls $args)"$'\n'}}) - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Node ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - nodes=($nodes $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - nodes=($nodes $s) - done - fi - - _describe -t nodes-list "nodes" nodes "$@" && ret=0 - return ret -} - -__docker_complete_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all none "$@" -} - -__docker_complete_nodes_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes ids none "$@" -} - -__docker_complete_nodes_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes names none "$@" -} - -__docker_complete_pending_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "membership=pending" "$@" -} - -__docker_complete_manager_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "role=manager" "$@" -} - -__docker_complete_worker_nodes() { - [[ $PREFIX = -* ]] && return 1 - __docker_nodes all "role=worker" "$@" -} - -__docker_node_commands() { - local -a _docker_node_subcommands - _docker_node_subcommands=( - "demote:Demote a node as manager in the swarm" - "inspect:Display detailed information on one or more nodes" - "ls:List nodes in the swarm" - "promote:Promote a node as manager in the swarm" - "rm:Remove one or more nodes from the swarm" - "ps:List tasks running on one or more nodes, defaults to current node" - "update:Update a node" - ) - _describe -t docker-node-commands "docker node command" _docker_node_subcommands -} - -__docker_node_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force remove a node from the swarm]" \ - "($help -)*:node:__docker_complete_pending_nodes" && ret=0 - ;; - (demote) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:node:__docker_complete_manager_nodes" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help)--pretty[Print the information in a human friendly format]" \ - "($help -)*:node:__docker_complete_nodes" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - case $state in - (filter-options) - __docker_node_complete_ls_filters && ret=0 - ;; - esac - ;; - (promote) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:node:__docker_complete_worker_nodes" && ret=0 - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Display all instances]" \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -)*:node:__docker_complete_nodes" && ret=0 - case $state in - (filter-options) - __docker_node_complete_ps_filters && ret=0 - ;; - esac - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--availability=[Availability of the node]:availability:(active pause drain)" \ - "($help)*--label-add=[Add or update a node label]:key=value: " \ - "($help)*--label-rm=[Remove a node label if exists]:label: " \ - "($help)--role=[Role of the node]:role:(manager worker)" \ - "($help -)1:node:__docker_complete_nodes" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0 - ;; - esac - - return ret -} - -# EO node - -# BO plugin - -__docker_complete_plugins() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines plugins - - lines=(${(f)${:-"$(_call_program commands docker $docker_options plugin ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Name - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}" - plugins=($plugins $s) - done - - _describe -t plugins-list "plugins" plugins "$@" && ret=0 - return ret -} - -__docker_plugin_commands() { - local -a _docker_plugin_subcommands - _docker_plugin_subcommands=( - "disable:Disable a plugin" - "enable:Enable a plugin" - "inspect:Return low-level information about a plugin" - "install:Install a plugin" - "ls:List plugins" - "push:Push a plugin" - "rm:Remove a plugin" - "set:Change settings for a plugin" - ) - _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands -} - -__docker_plugin_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (disable|enable|inspect|ls|push|rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:plugin:__docker_complete_plugins" && ret=0 - ;; - (install) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--alias=[Local name for plugin]:alias: " \ - "($help -)1:plugin:__docker_complete_plugins" && ret=0 - ;; - (set) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)1:plugin:__docker_complete_plugins" \ - "($help-)*:key=value: " && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0 - ;; - esac - - return ret -} - -# EO plugin - -# BO secret - -__docker_secrets() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines secrets - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options secret ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - secrets=($secrets $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - secrets=($secrets $s) - done - fi - - _describe -t secrets-list "secrets" secrets "$@" && ret=0 - return ret -} - -__docker_complete_secrets() { - [[ $PREFIX = -* ]] && return 1 - __docker_secrets all "$@" -} - -__docker_secret_commands() { - local -a _docker_secret_subcommands - _docker_secret_subcommands=( - "create:Create a secret using stdin as content" - "inspect:Display detailed information on one or more secrets" - "ls:List secrets" - "rm:Remove one or more secrets" - ) - _describe -t docker-secret-commands "docker secret command" _docker_secret_subcommands -} - -__docker_secret_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)*"{-l=,--label=}"[Secret labels]:label: " \ - "($help -):secret: " && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given Go template]:template: " \ - "($help -)*:secret:__docker_complete_secrets" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:secret:__docker_complete_secrets" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_secret_commands" && ret=0 - ;; - esac - - return ret -} - -# EO secret - -# BO service - -__docker_service_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (id) - __docker_complete_services_ids && ret=0 - ;; - (name) - __docker_complete_services_names && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_service_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_services() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines services - - type=$1; shift - - lines=(${(f)${:-"$(_call_program commands docker $docker_options service ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Service ID - if [[ $type = (ids|all) ]]; then - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" - services=($services $s) - done - fi - - # Names - if [[ $type = (names|all) ]]; then - for line in $lines; do - s="${line[${begin[NAME]},${end[NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" - services=($services $s) - done - fi - - _describe -t services-list "services" services "$@" && ret=0 - return ret -} - -__docker_complete_services() { - [[ $PREFIX = -* ]] && return 1 - __docker_services all "$@" -} - -__docker_complete_services_ids() { - [[ $PREFIX = -* ]] && return 1 - __docker_services ids "$@" -} - -__docker_complete_services_names() { - [[ $PREFIX = -* ]] && return 1 - __docker_services names "$@" -} - -__docker_service_commands() { - local -a _docker_service_subcommands - _docker_service_subcommands=( - "create:Create a new service" - "inspect:Display detailed information on one or more services" - "ls:List services" - "rm:Remove one or more services" - "scale:Scale one or multiple replicated services" - "ps:List the tasks of a service" - "update:Update a service" - ) - _describe -t docker-service-commands "docker service command" _docker_service_subcommands -} - -__docker_service_subcommand() { - local -a _command_args opts_help opts_create_update - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - opts_create_update=( - "($help)*--constraint=[Placement constraints]:constraint: " - "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)" - "($help)*"{-e=,--env=}"[Set environment variables]:env: " - "($help)--health-cmd=[Command to run to check health]:command: " - "($help)--health-interval=[Time between running the check]:time: " - "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" - "($help)--health-timeout=[Maximum time to allow one check to run]:time: " - "($help)--hostname=[Service container hostname]:hostname: " \ - "($help)*--label=[Service labels]:label: " - "($help)--limit-cpu=[Limit CPUs]:value: " - "($help)--limit-memory=[Limit Memory]:value: " - "($help)--log-driver=[Logging driver for service]:logging driver:__docker_complete_log_drivers" - "($help)*--log-opt=[Logging driver options]:log driver options:__docker_complete_log_options" - "($help)*--mount=[Attach a filesystem mount to the service]:mount: " - "($help)*--network=[Network attachments]:network: " - "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" - "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: " - "($help)--replicas=[Number of tasks]:replicas: " - "($help)--reserve-cpu=[Reserve CPUs]:value: " - "($help)--reserve-memory=[Reserve Memory]:value: " - "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)" - "($help)--restart-delay=[Delay between restart attempts]:delay: " - "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: " - "($help)--restart-window=[Window used to evaluate the restart policy]:window: " - "($help)*--secret=[Specify secrets to expose to the service]:secret:__docker_complete_secrets" - "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: " - "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-TTY]" - "($help)--update-delay=[Delay between updates]:delay: " - "($help)--update-failure-action=[Action on update failure]:mode:(pause continue)" - "($help)--update-max-failure-ratio=[Failure rate to tolerate during an update]:fraction: " - "($help)--update-monitor=[Duration after each task update to monitor for failure]:window: " - "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: " - "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" - "($help)--with-registry-auth[Send registry authentication details to swarm agents]" - "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" - ) - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_update \ - "($help)*--container-label=[Container labels]:label: " \ - "($help)*--dns=[Set custom DNS servers]:DNS: " \ - "($help)*--dns-option=[Set DNS options]:DNS option: " \ - "($help)*--dns-search=[Set custom DNS search domains]:DNS search: " \ - "($help)*--env-file=[Read environment variables from a file]:environment file:_files" \ - "($help)--mode=[Service Mode]:mode:(global replicated)" \ - "($help)--name=[Service name]:name: " \ - "($help)*--publish=[Publish a port]:port: " \ - "($help -): :__docker_complete_images" \ - "($help -):command: _command_names -e" \ - "($help -)*::arguments: _normal" && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help)--pretty[Print the information in a human friendly format]" \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:->filter-options" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 - case $state in - (filter-options) - __docker_service_complete_ls_filters && ret=0 - ;; - esac - ;; - (rm|remove) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:service:__docker_complete_services" && ret=0 - ;; - (scale) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -)*:service:->values" && ret=0 - case $state in - (values) - if compset -P '*='; then - _message 'replicas' && ret=0 - else - __docker_complete_services -qS "=" - fi - ;; - esac - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -q --quiet)"{-q,--quiet}"[Only display task IDs]" \ - "($help -)1:service:__docker_complete_services" && ret=0 - case $state in - (filter-options) - __docker_service_complete_ps_filters && ret=0 - ;; - esac - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - $opts_create_update \ - "($help)--arg=[Service command args]:arguments: _normal" \ - "($help)*--container-label-add=[Add or update container labels]:label: " \ - "($help)*--container-label-rm=[Remove a container label by its key]:label: " \ - "($help)*--dns-add=[Add or update custom DNS servers]:DNS: " \ - "($help)*--dns-rm=[Remove custom DNS servers]:DNS: " \ - "($help)*--dns-option-add=[Add or update DNS options]:DNS option: " \ - "($help)*--dns-option-rm=[Remove DNS options]:DNS option: " \ - "($help)*--dns-search-add=[Add or update custom DNS search domains]:DNS search: " \ - "($help)*--dns-search-rm=[Remove DNS search domains]:DNS search: " \ - "($help)--force[Force update]" \ - "($help)*--group-add=[Add additional supplementary user groups to the container]:group:_groups" \ - "($help)*--group-rm=[Remove previously added supplementary user groups from the container]:group:_groups" \ - "($help)--image=[Service image tag]:image:__docker_complete_repositories" \ - "($help)*--publish-add=[Add or update a port]:port: " \ - "($help)*--publish-rm=[Remove a port(target-port mandatory)]:port: " \ - "($help)--rollback[Rollback to previous specification]" \ - "($help -)1:service:__docker_complete_services" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0 - ;; - esac - - return ret -} - -# EO service - -# BO stack - -__docker_stack_complete_ps_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (desired-state) - state_opts=('accepted' 'running') - _describe -t state-opts "desired state options" state_opts && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('desired-state' 'id' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_stack_complete_services_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('id' 'label' 'name') - _describe -t filter-opts "filter options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_stacks() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - local line s - declare -a lines stacks - - lines=(${(f)${:-"$(_call_program commands docker $docker_options stack ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Service ID - for line in $lines; do - s="${line[${begin[ID]},${end[ID]}]%% ##}" - stacks=($stacks $s) - done - - _describe -t stacks-list "stacks" stacks "$@" && ret=0 - return ret -} - -__docker_complete_stacks() { - [[ $PREFIX = -* ]] && return 1 - __docker_stacks "$@" -} - -__docker_stack_commands() { - local -a _docker_stack_subcommands - _docker_stack_subcommands=( - "deploy:Deploy a new stack or update an existing stack" - "ls:List stacks" - "ps:List the tasks in the stack" - "rm:Remove the stack" - "services:List the services in the stack" - ) - _describe -t docker-stack-commands "docker stack command" _docker_stack_subcommands -} - -__docker_stack_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (deploy|up) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--bundle-file=[Path to a Distributed Application Bundle file]:dab:_files -g \"*.dab\"" \ - "($help -c --compose-file)"{-c=,--compose-file=}"[Path to a Compose file]:compose file:_files -g \"*.(yml|yaml)\"" \ - "($help)--with-registry-auth[Send registry authentication details to Swarm agents]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (ls|list) - _arguments $(__docker_arguments) \ - $opts_help && ret=0 - ;; - (ps) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Display all tasks]" \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_ps_filters" \ - "($help)--no-resolve[Do not map IDs to Names]" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (rm|remove|down) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (services) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:__docker_stack_complete_services_filters" \ - "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" \ - "($help -):stack:__docker_complete_stacks" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_stack_commands" && ret=0 - ;; - esac - - return ret -} - -# EO stack - -# BO swarm - -__docker_swarm_commands() { - local -a _docker_swarm_subcommands - _docker_swarm_subcommands=( - "init:Initialize a swarm" - "join:Join a swarm as a node and/or manager" - "join-token:Manage join tokens" - "leave:Leave a swarm" - "update:Update the swarm" - ) - _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands -} - -__docker_swarm_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (init) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--advertise-addr[Advertised address]:ip\:port: " \ - "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ - "($help)--force-new-cluster[Force create a new cluster from current state]" \ - "($help)--listen-addr=[Listen address]:ip\:port: " \ - "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ - "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ - "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 - ;; - (join) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)--advertise-addr=[Advertised address]:ip\:port: " \ - "($help)--availability=[Availability of the node]:availability:(active drain pause)" \ - "($help)--listen-addr=[Listen address]:ip\:port: " \ - "($help)--token=[Token for entry into the swarm]:secret: " \ - "($help -):host\:port: " && ret=0 - ;; - (join-token) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ - "($help)--rotate[Rotate join token]" \ - "($help -):role:(manager worker)" && ret=0 - ;; - (leave) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force this node to leave the swarm, ignoring warnings]" && ret=0 - ;; - (update) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ - "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ - "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ - "($help)--max-snapshots[Number of additional Raft snapshots to retain]" \ - "($help)--snapshot-interval[Number of log entries between Raft snapshots]" \ - "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 - ;; - esac - - return ret -} - -# EO swarm - -# BO system - -__docker_system_commands() { - local -a _docker_system_subcommands - _docker_system_subcommands=( - "df:Show docker filesystem usage" - "events:Get real time events from the server" - "info:Display system-wide information" - "prune:Remove unused data" - ) - _describe -t docker-system-commands "docker system command" _docker_system_subcommands -} - -__docker_system_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (df) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -v --verbose)"{-v,--verbose}"[Show detailed information on space usage]" && ret=0 - ;; - (events) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \ - "($help)--since=[Events created since this timestamp]:timestamp: " \ - "($help)--until=[Events created until this timestamp]:timestamp: " \ - "($help)--format=[Format the output using the given go template]:template: " && ret=0 - ;; - (info) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -a --all)"{-a,--all}"[Remove all unused data, not just dangling ones]" \ - "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 - ;; - esac - - return ret -} - -# EO system - -# BO volume - -__docker_volume_complete_ls_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (dangling) - dangling_opts=('true' 'false') - _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 - ;; - (driver) - __docker_complete_info_plugins Volume && ret=0 - ;; - (name) - __docker_complete_volumes && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('dangling' 'driver' 'label' 'name') - _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 - fi - - return ret -} - -__docker_complete_volumes() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - declare -a lines volumes - - lines=(${(f)${:-"$(_call_program commands docker $docker_options volume ls)"$'\n'}}) - - # Parse header line to find columns - local i=1 j=1 k header=${lines[1]} - declare -A begin end - while (( j < ${#header} - 1 )); do - i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) - j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) - k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) - begin[${header[$i,$((j-1))]}]=$i - end[${header[$i,$((j-1))]}]=$k - done - end[${header[$i,$((j-1))]}]=-1 - lines=(${lines[2,-1]}) - - # Names - local line s - for line in $lines; do - s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" - s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" - volumes=($volumes $s) - done - - _describe -t volumes-list "volumes" volumes && ret=0 - return ret -} - -__docker_volume_commands() { - local -a _docker_volume_subcommands - _docker_volume_subcommands=( - "create:Create a volume" - "inspect:Display detailed information on one or more volumes" - "ls:List volumes" - "prune:Remove all unused volumes" - "rm:Remove one or more volumes" - ) - _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands -} - -__docker_volume_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (create) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \ - "($help)*--label=[Set metadata for a volume]:label=value: " \ - "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \ - "($help -)1:Volume name: " && ret=0 - ;; - (inspect) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -)1:volume:__docker_complete_volumes" && ret=0 - ;; - (ls) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ - "($help)--format=[Pretty-print volumes using a Go template]:template: " \ - "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 - case $state in - (filter-options) - __docker_volume_complete_ls_filters && ret=0 - ;; - esac - ;; - (prune) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0 - ;; - (rm) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \ - "($help -):volume:__docker_complete_volumes" && ret=0 - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 - ;; - esac - - return ret -} - -# EO volume - -__docker_caching_policy() { - oldp=( "$1"(Nmh+1) ) # 1 hour - (( $#oldp )) -} - -__docker_commands() { - local cache_policy - - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy - fi - - if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \ - && ! _retrieve_cache docker_subcommands; - then - local -a lines - lines=(${(f)"$(_call_program commands docker 2>&1)"}) - _docker_subcommands=(${${${(M)${lines[$((${lines[(i)*Commands:]} + 1)),-1]}:# *}## #}/ ##/:}) - _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') - (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands - fi - _describe -t docker-commands "docker command" _docker_subcommands -} - -__docker_subcommand() { - local -a _command_args opts_help - local expl help="--help" - integer ret=1 - - opts_help=("(: -)--help[Print usage]") - - case "$words[1]" in - (attach|commit|cp|create|diff|exec|export|kill|logs|pause|unpause|port|rename|restart|rm|run|start|stats|stop|top|update|wait) - __docker_container_subcommand && ret=0 - ;; - (build|history|import|load|pull|push|save|tag) - __docker_image_subcommand && ret=0 - ;; - (container) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_container_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_container_subcommand && ret=0 - ;; - esac - ;; - (daemon) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \ - "($help)--api-cors-header=[CORS headers in the Engine API]:CORS headers: " \ - "($help)*--authorization-plugin=[Authorization plugins to load]" \ - "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ - "($help)--bip=[Network bridge IP]:IP address: " \ - "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \ - "($help)--cluster-advertise=[Address or interface name to advertise]:Instance to advertise (host\:port): " \ - "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \ - "($help)*--cluster-store-opt=[Cluster store options]:Cluster options:->cluster-store-options" \ - "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \ - "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ - "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ - "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ - "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ - "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \ - "($help)--disable-legacy-registry[Disable contacting legacy registries]" \ - "($help)*--dns=[DNS server to use]:DNS: " \ - "($help)*--dns-opt=[DNS options to use]:DNS option: " \ - "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ - "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \ - "($help)--exec-root=[Root directory for execution state files]:path:_directories" \ - "($help)--experimental[Enable experimental features]" \ - "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ - "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ - "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ - "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \ - "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ - "($help)--icc[Enable inter-container communication]" \ - "($help)--init[Run an init inside containers to forward signals and reap processes]" \ - "($help)--init-path=[Path to the docker-init binary]:docker-init binary:_files" \ - "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ - "($help)--ip=[Default IP when binding container ports]" \ - "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ - "($help)--ip-masq[Enable IP masquerading]" \ - "($help)--iptables[Enable addition of iptables rules]" \ - "($help)--ipv6[Enable IPv6 networking]" \ - "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ - "($help)*--label=[Key=value labels]:label: " \ - "($help)--live-restore[Enable live restore of docker when containers are still running]" \ - "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" \ - "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_complete_log_options" \ - "($help)--max-concurrent-downloads[Set the max concurrent downloads for each pull]" \ - "($help)--max-concurrent-uploads[Set the max concurrent uploads for each push]" \ - "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \ - "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \ - "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ - "($help)--raw-logs[Full timestamps without ANSI coloring]" \ - "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \ - "($help)--seccomp-profile=[Path to seccomp profile]:path:_files -g \"*.json\"" \ - "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs btrfs devicemapper overlay overlay2 vfs zfs)" \ - "($help)--selinux-enabled[Enable selinux support]" \ - "($help)--shutdown-timeout=[Set the shutdown timeout value in seconds]:time: " \ - "($help)*--storage-opt=[Storage driver options]:storage driver options: " \ - "($help)--tls[Use TLS]" \ - "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \ - "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \ - "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \ - "($help)--tlsverify[Use TLS and verify the remote]" \ - "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ - "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ - "($help)--userland-proxy-path=[Path to the userland proxy binary]:binary:_files" && ret=0 - - case $state in - (cluster-store) - if compset -P '*://'; then - _message 'host:port' && ret=0 - else - store=('consul' 'etcd' 'zk') - _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0 - fi - ;; - (cluster-store-options) - if compset -P '*='; then - _files && ret=0 - else - opts=('discovery.heartbeat' 'discovery.ttl' 'kv.cacertfile' 'kv.certfile' 'kv.keyfile' 'kv.path') - _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0 - fi - ;; - (users-groups) - if compset -P '*:'; then - _groups && ret=0 - else - _describe -t userns-default "default Docker user management" '(default)' && ret=0 - _users && ret=0 - fi - ;; - esac - ;; - (events|info) - __docker_system_subcommand && ret=0 - ;; - (image) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_image_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_image_subcommand && ret=0 - ;; - esac - ;; - (images) - words[1]='ls' - __docker_image_subcommand && ret=0 - ;; - (inspect) - local state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ - "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ - "($help)--type=[Return JSON for specified type]:type:(container image network node plugin service volume)" \ - "($help -)*: :->values" && ret=0 - - case $state in - (values) - if [[ ${words[(r)--type=container]} == --type=container ]]; then - __docker_complete_containers && ret=0 - elif [[ ${words[(r)--type=image]} == --type=image ]]; then - __docker_complete_images && ret=0 - elif [[ ${words[(r)--type=network]} == --type=network ]]; then - __docker_complete_networks && ret=0 - elif [[ ${words[(r)--type=node]} == --type=node ]]; then - __docker_complete_nodes && ret=0 - elif [[ ${words[(r)--type=plugin]} == --type=plugin ]]; then - __docker_complete_plugins && ret=0 - elif [[ ${words[(r)--type=service]} == --type=service ]]; then - __docker_complete_services && ret=0 - elif [[ ${words[(r)--type=volume]} == --type=volume ]]; then - __docker_complete_volumes && ret=0 - else - __docker_complete_containers - __docker_complete_images - __docker_complete_networks - __docker_complete_nodes - __docker_complete_plugins - __docker_complete_services - __docker_complete_volumes && ret=0 - fi - ;; - esac - ;; - (login) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help -p --password)"{-p=,--password=}"[Password]:password: " \ - "($help -u --user)"{-u=,--user=}"[Username]:username: " \ - "($help -)1:server: " && ret=0 - ;; - (logout) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help -)1:server: " && ret=0 - ;; - (network) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_network_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_network_subcommand && ret=0 - ;; - esac - ;; - (node) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_node_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_node_subcommand && ret=0 - ;; - esac - ;; - (plugin) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_plugin_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_plugin_subcommand && ret=0 - ;; - esac - ;; - (ps) - words[1]='ls' - __docker_container_subcommand && ret=0 - ;; - (rmi) - words[1]='rm' - __docker_image_subcommand && ret=0 - ;; - (search) - _arguments $(__docker_arguments) -A '-*' \ - $opts_help \ - "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \ - "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \ - "($help)--no-trunc[Do not truncate output]" \ - "($help -):term: " && ret=0 - - case $state in - (filter-options) - __docker_complete_search_filters && ret=0 - ;; - esac - ;; - (secret) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_secret_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_secret_subcommand && ret=0 - ;; - esac - ;; - (service) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_service_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_service_subcommand && ret=0 - ;; - esac - ;; - (stack) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_stack_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_stack_subcommand && ret=0 - ;; - esac - ;; - (swarm) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_swarm_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_swarm_subcommand && ret=0 - ;; - esac - ;; - (system) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_system_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_system_subcommand && ret=0 - ;; - esac - ;; - (version) - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 - ;; - (volume) - local curcontext="$curcontext" state - _arguments $(__docker_arguments) \ - $opts_help \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker_volume_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-${words[-1]}: - __docker_volume_subcommand && ret=0 - ;; - esac - ;; - (help) - _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 - ;; - esac - - return ret -} - -_docker() { - # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. - # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. - if [[ $service != docker ]]; then - _call_function - _$service - return - fi - - local curcontext="$curcontext" state line help="-h --help" - integer ret=1 - typeset -A opt_args - - _arguments $(__docker_arguments) -C \ - "(: -)"{-h,--help}"[Print usage]" \ - "($help)--config[Location of client config files]:path:_directories" \ - "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ - "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ - "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ - "($help)--tls[Use TLS]" \ - "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ - "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ - "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ - "($help)--tlsverify[Use TLS and verify the remote]" \ - "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ - "($help -v --version)"{-v,--version}"[Print version information and quit]" \ - "($help -): :->command" \ - "($help -)*:: :->option-or-argument" && ret=0 - - local host=${opt_args[-H]}${opt_args[--host]} - local config=${opt_args[--config]} - local docker_options="${host:+--host $host} ${config:+--config $config}" - - case $state in - (command) - __docker_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-$words[1]: - __docker_subcommand && ret=0 - ;; - esac - - return ret -} - -_dockerd() { - integer ret=1 - words[1]='daemon' - __docker_subcommand && ret=0 - return ret -} - -_docker "$@" - -# Local Variables: -# mode: Shell-Script -# sh-indentation: 4 -# indent-tabs-mode: nil -# sh-basic-offset: 4 -# End: -# vim: ft=zsh sw=4 ts=4 et diff --git a/vendor/github.com/docker/docker/contrib/desktop-integration/README.md b/vendor/github.com/docker/docker/contrib/desktop-integration/README.md deleted file mode 100644 index 85a01b9..0000000 --- a/vendor/github.com/docker/docker/contrib/desktop-integration/README.md +++ /dev/null @@ -1,11 +0,0 @@ -Desktop Integration -=================== - -The ./contrib/desktop-integration contains examples of typical dockerized -desktop applications. - -Examples -======== - -* Chromium: ./chromium/Dockerfile shows a way to dockerize a common application -* Gparted: ./gparted/Dockerfile shows a way to dockerize a common application w devices diff --git a/vendor/github.com/docker/docker/contrib/desktop-integration/chromium/Dockerfile b/vendor/github.com/docker/docker/contrib/desktop-integration/chromium/Dockerfile deleted file mode 100644 index 5cacd1f..0000000 --- a/vendor/github.com/docker/docker/contrib/desktop-integration/chromium/Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -# VERSION: 0.1 -# DESCRIPTION: Create chromium container with its dependencies -# AUTHOR: Jessica Frazelle -# COMMENTS: -# This file describes how to build a Chromium container with all -# dependencies installed. It uses native X11 unix socket. -# Tested on Debian Jessie -# USAGE: -# # Download Chromium Dockerfile -# wget http://raw.githubusercontent.com/docker/docker/master/contrib/desktop-integration/chromium/Dockerfile -# -# # Build chromium image -# docker build -t chromium . -# -# # Run stateful data-on-host chromium. For ephemeral, remove -v /data/chromium:/data -# docker run -v /data/chromium:/data -v /tmp/.X11-unix:/tmp/.X11-unix \ -# -e DISPLAY=unix$DISPLAY chromium - -# # To run stateful dockerized data containers -# docker run --volumes-from chromium-data -v /tmp/.X11-unix:/tmp/.X11-unix \ -# -e DISPLAY=unix$DISPLAY chromium - -# Base docker image -FROM debian:jessie -MAINTAINER Jessica Frazelle - -# Install Chromium -RUN apt-get update && apt-get install -y \ - chromium \ - chromium-l10n \ - libcanberra-gtk-module \ - libexif-dev \ - --no-install-recommends - -# Autorun chromium -CMD ["/usr/bin/chromium", "--no-sandbox", "--user-data-dir=/data"] diff --git a/vendor/github.com/docker/docker/contrib/desktop-integration/gparted/Dockerfile b/vendor/github.com/docker/docker/contrib/desktop-integration/gparted/Dockerfile deleted file mode 100644 index 3ddb232..0000000 --- a/vendor/github.com/docker/docker/contrib/desktop-integration/gparted/Dockerfile +++ /dev/null @@ -1,31 +0,0 @@ -# VERSION: 0.1 -# DESCRIPTION: Create gparted container with its dependencies -# AUTHOR: Jessica Frazelle -# COMMENTS: -# This file describes how to build a gparted container with all -# dependencies installed. It uses native X11 unix socket. -# Tested on Debian Jessie -# USAGE: -# # Download gparted Dockerfile -# wget http://raw.githubusercontent.com/docker/docker/master/contrib/desktop-integration/gparted/Dockerfile -# -# # Build gparted image -# docker build -t gparted . -# -# docker run -v /tmp/.X11-unix:/tmp/.X11-unix \ -# --device=/dev/sda:/dev/sda \ -# -e DISPLAY=unix$DISPLAY gparted -# - -# Base docker image -FROM debian:jessie -MAINTAINER Jessica Frazelle - -# Install Gparted and its dependencies -RUN apt-get update && apt-get install -y \ - gparted \ - libcanberra-gtk-module \ - --no-install-recommends - -# Autorun gparted -CMD ["/usr/sbin/gparted"] diff --git a/vendor/github.com/docker/docker/contrib/docker-device-tool/README.md b/vendor/github.com/docker/docker/contrib/docker-device-tool/README.md deleted file mode 100644 index 6c54d59..0000000 --- a/vendor/github.com/docker/docker/contrib/docker-device-tool/README.md +++ /dev/null @@ -1,14 +0,0 @@ -Docker device tool for devicemapper storage driver backend -=================== - -The ./contrib/docker-device-tool contains a tool to manipulate devicemapper thin-pool. - -Compile -======== - - $ make shell - ## inside build container - $ go build contrib/docker-device-tool/device_tool.go - - # if devicemapper version is old and compilation fails, compile with `libdm_no_deferred_remove` tag - $ go build -tags libdm_no_deferred_remove contrib/docker-device-tool/device_tool.go diff --git a/vendor/github.com/docker/docker/contrib/docker-device-tool/device_tool.go b/vendor/github.com/docker/docker/contrib/docker-device-tool/device_tool.go deleted file mode 100644 index 906d064..0000000 --- a/vendor/github.com/docker/docker/contrib/docker-device-tool/device_tool.go +++ /dev/null @@ -1,176 +0,0 @@ -// +build !windows,!solaris - -package main - -import ( - "flag" - "fmt" - "os" - "path" - "sort" - "strconv" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/graphdriver/devmapper" - "github.com/docker/docker/pkg/devicemapper" -) - -func usage() { - fmt.Fprintf(os.Stderr, "Usage: %s [status] | [list] | [device id] | [resize new-pool-size] | [snap new-id base-id] | [remove id] | [mount id mountpoint]\n", os.Args[0]) - flag.PrintDefaults() - os.Exit(1) -} - -func byteSizeFromString(arg string) (int64, error) { - digits := "" - rest := "" - last := strings.LastIndexAny(arg, "0123456789") - if last >= 0 { - digits = arg[:last+1] - rest = arg[last+1:] - } - - val, err := strconv.ParseInt(digits, 10, 64) - if err != nil { - return val, err - } - - rest = strings.ToLower(strings.TrimSpace(rest)) - - var multiplier int64 = 1 - switch rest { - case "": - multiplier = 1 - case "k", "kb": - multiplier = 1024 - case "m", "mb": - multiplier = 1024 * 1024 - case "g", "gb": - multiplier = 1024 * 1024 * 1024 - case "t", "tb": - multiplier = 1024 * 1024 * 1024 * 1024 - default: - return 0, fmt.Errorf("Unknown size unit: %s", rest) - } - - return val * multiplier, nil -} - -func main() { - root := flag.String("r", "/var/lib/docker", "Docker root dir") - flDebug := flag.Bool("D", false, "Debug mode") - - flag.Parse() - - if *flDebug { - os.Setenv("DEBUG", "1") - logrus.SetLevel(logrus.DebugLevel) - } - - if flag.NArg() < 1 { - usage() - } - - args := flag.Args() - - home := path.Join(*root, "devicemapper") - devices, err := devmapper.NewDeviceSet(home, false, nil, nil, nil) - if err != nil { - fmt.Println("Can't initialize device mapper: ", err) - os.Exit(1) - } - - switch args[0] { - case "status": - status := devices.Status() - fmt.Printf("Pool name: %s\n", status.PoolName) - fmt.Printf("Data Loopback file: %s\n", status.DataLoopback) - fmt.Printf("Metadata Loopback file: %s\n", status.MetadataLoopback) - fmt.Printf("Sector size: %d\n", status.SectorSize) - fmt.Printf("Data use: %d of %d (%.1f %%)\n", status.Data.Used, status.Data.Total, 100.0*float64(status.Data.Used)/float64(status.Data.Total)) - fmt.Printf("Metadata use: %d of %d (%.1f %%)\n", status.Metadata.Used, status.Metadata.Total, 100.0*float64(status.Metadata.Used)/float64(status.Metadata.Total)) - break - case "list": - ids := devices.List() - sort.Strings(ids) - for _, id := range ids { - fmt.Println(id) - } - break - case "device": - if flag.NArg() < 2 { - usage() - } - status, err := devices.GetDeviceStatus(args[1]) - if err != nil { - fmt.Println("Can't get device info: ", err) - os.Exit(1) - } - fmt.Printf("Id: %d\n", status.DeviceID) - fmt.Printf("Size: %d\n", status.Size) - fmt.Printf("Transaction Id: %d\n", status.TransactionID) - fmt.Printf("Size in Sectors: %d\n", status.SizeInSectors) - fmt.Printf("Mapped Sectors: %d\n", status.MappedSectors) - fmt.Printf("Highest Mapped Sector: %d\n", status.HighestMappedSector) - break - case "resize": - if flag.NArg() < 2 { - usage() - } - - size, err := byteSizeFromString(args[1]) - if err != nil { - fmt.Println("Invalid size: ", err) - os.Exit(1) - } - - err = devices.ResizePool(size) - if err != nil { - fmt.Println("Error resizing pool: ", err) - os.Exit(1) - } - - break - case "snap": - if flag.NArg() < 3 { - usage() - } - - err := devices.AddDevice(args[1], args[2], nil) - if err != nil { - fmt.Println("Can't create snap device: ", err) - os.Exit(1) - } - break - case "remove": - if flag.NArg() < 2 { - usage() - } - - err := devicemapper.RemoveDevice(args[1]) - if err != nil { - fmt.Println("Can't remove device: ", err) - os.Exit(1) - } - break - case "mount": - if flag.NArg() < 3 { - usage() - } - - err := devices.MountDevice(args[1], args[2], "") - if err != nil { - fmt.Println("Can't create snap device: ", err) - os.Exit(1) - } - break - default: - fmt.Printf("Unknown command %s\n", args[0]) - usage() - - os.Exit(1) - } - - return -} diff --git a/vendor/github.com/docker/docker/contrib/docker-device-tool/device_tool_windows.go b/vendor/github.com/docker/docker/contrib/docker-device-tool/device_tool_windows.go deleted file mode 100644 index da29a2c..0000000 --- a/vendor/github.com/docker/docker/contrib/docker-device-tool/device_tool_windows.go +++ /dev/null @@ -1,4 +0,0 @@ -package main - -func main() { -} diff --git a/vendor/github.com/docker/docker/contrib/dockerize-disk.sh b/vendor/github.com/docker/docker/contrib/dockerize-disk.sh deleted file mode 100755 index 444e243..0000000 --- a/vendor/github.com/docker/docker/contrib/dockerize-disk.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env bash -set -e - -if ! command -v qemu-nbd &> /dev/null; then - echo >&2 'error: "qemu-nbd" not found!' - exit 1 -fi - -usage() { - echo "Convert disk image to docker image" - echo "" - echo "usage: $0 image-name disk-image-file [ base-image ]" - echo " ie: $0 cirros:0.3.3 cirros-0.3.3-x86_64-disk.img" - echo " $0 ubuntu:cloud ubuntu-14.04-server-cloudimg-amd64-disk1.img ubuntu:14.04" -} - -if [ "$#" -lt 2 ]; then - usage - exit 1 -fi - -CURDIR=$(pwd) - -image_name="${1%:*}" -image_tag="${1#*:}" -if [ "$image_tag" == "$1" ]; then - image_tag="latest" -fi - -disk_image_file="$2" -docker_base_image="$3" - -block_device=/dev/nbd0 - -builddir=$(mktemp -d) - -cleanup() { - umount "$builddir/disk_image" || true - umount "$builddir/workdir" || true - qemu-nbd -d $block_device &> /dev/null || true - rm -rf $builddir -} -trap cleanup EXIT - -# Mount disk image -modprobe nbd max_part=63 -qemu-nbd -rc ${block_device} -P 1 "$disk_image_file" -mkdir "$builddir/disk_image" -mount -o ro ${block_device} "$builddir/disk_image" - -mkdir "$builddir/workdir" -mkdir "$builddir/diff" - -base_image_mounts="" - -# Unpack base image -if [ -n "$docker_base_image" ]; then - mkdir -p "$builddir/base" - docker pull "$docker_base_image" - docker save "$docker_base_image" | tar -xC "$builddir/base" - - image_id=$(docker inspect -f "{{.Id}}" "$docker_base_image") - while [ -n "$image_id" ]; do - mkdir -p "$builddir/base/$image_id/layer" - tar -xf "$builddir/base/$image_id/layer.tar" -C "$builddir/base/$image_id/layer" - - base_image_mounts="${base_image_mounts}:$builddir/base/$image_id/layer=ro+wh" - image_id=$(docker inspect -f "{{.Parent}}" "$image_id") - done -fi - -# Mount work directory -mount -t aufs -o "br=$builddir/diff=rw${base_image_mounts},dio,xino=/dev/shm/aufs.xino" none "$builddir/workdir" - -# Update files -cd $builddir -LC_ALL=C diff -rq disk_image workdir \ - | sed -re "s|Only in workdir(.*?): |DEL \1/|g;s|Only in disk_image(.*?): |ADD \1/|g;s|Files disk_image/(.+) and workdir/(.+) differ|UPDATE /\1|g" \ - | while read action entry; do - case "$action" in - ADD|UPDATE) - cp -a "disk_image$entry" "workdir$entry" - ;; - DEL) - rm -rf "workdir$entry" - ;; - *) - echo "Error: unknown diff line: $action $entry" >&2 - ;; - esac - done - -# Pack new image -new_image_id="$(for i in $(seq 1 32); do printf "%02x" $(($RANDOM % 256)); done)" -mkdir -p $builddir/result/$new_image_id -cd diff -tar -cf $builddir/result/$new_image_id/layer.tar * -echo "1.0" > $builddir/result/$new_image_id/VERSION -cat > $builddir/result/$new_image_id/json <<-EOS -{ "docker_version": "1.4.1" -, "id": "$new_image_id" -, "created": "$(date -u +%Y-%m-%dT%H:%M:%S.%NZ)" -EOS - -if [ -n "$docker_base_image" ]; then - image_id=$(docker inspect -f "{{.Id}}" "$docker_base_image") - echo ", \"parent\": \"$image_id\"" >> $builddir/result/$new_image_id/json -fi - -echo "}" >> $builddir/result/$new_image_id/json - -echo "{\"$image_name\":{\"$image_tag\":\"$new_image_id\"}}" > $builddir/result/repositories - -cd $builddir/result - -# mkdir -p $CURDIR/$image_name -# cp -r * $CURDIR/$image_name -tar -c * | docker load diff --git a/vendor/github.com/docker/docker/contrib/download-frozen-image-v1.sh b/vendor/github.com/docker/docker/contrib/download-frozen-image-v1.sh deleted file mode 100755 index 29d7ff5..0000000 --- a/vendor/github.com/docker/docker/contrib/download-frozen-image-v1.sh +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/bash -set -e - -# hello-world latest ef872312fe1b 3 months ago 910 B -# hello-world latest ef872312fe1bbc5e05aae626791a47ee9b032efa8f3bda39cc0be7b56bfe59b9 3 months ago 910 B - -# debian latest f6fab3b798be 10 weeks ago 85.1 MB -# debian latest f6fab3b798be3174f45aa1eb731f8182705555f89c9026d8c1ef230cbf8301dd 10 weeks ago 85.1 MB - -if ! command -v curl &> /dev/null; then - echo >&2 'error: "curl" not found!' - exit 1 -fi - -usage() { - echo "usage: $0 dir image[:tag][@image-id] ..." - echo " ie: $0 /tmp/hello-world hello-world" - echo " $0 /tmp/debian-jessie debian:jessie" - echo " $0 /tmp/old-hello-world hello-world@ef872312fe1bbc5e05aae626791a47ee9b032efa8f3bda39cc0be7b56bfe59b9" - echo " $0 /tmp/old-debian debian:latest@f6fab3b798be3174f45aa1eb731f8182705555f89c9026d8c1ef230cbf8301dd" - [ -z "$1" ] || exit "$1" -} - -dir="$1" # dir for building tar in -shift || usage 1 >&2 - -[ $# -gt 0 -a "$dir" ] || usage 2 >&2 -mkdir -p "$dir" - -# hacky workarounds for Bash 3 support (no associative arrays) -images=() -rm -f "$dir"/tags-*.tmp -# repositories[busybox]='"latest": "...", "ubuntu-14.04": "..."' - -while [ $# -gt 0 ]; do - imageTag="$1" - shift - image="${imageTag%%[:@]*}" - tag="${imageTag#*:}" - imageId="${tag##*@}" - [ "$imageId" != "$tag" ] || imageId= - [ "$tag" != "$imageTag" ] || tag='latest' - tag="${tag%@*}" - - imageFile="${image//\//_}" # "/" can't be in filenames :) - - token="$(curl -sSL -o /dev/null -D- -H 'X-Docker-Token: true' "https://index.docker.io/v1/repositories/$image/images" | tr -d '\r' | awk -F ': *' '$1 == "X-Docker-Token" { print $2 }')" - - if [ -z "$imageId" ]; then - imageId="$(curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/repositories/$image/tags/$tag")" - imageId="${imageId//\"/}" - fi - - ancestryJson="$(curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/ancestry")" - if [ "${ancestryJson:0:1}" != '[' ]; then - echo >&2 "error: /v1/images/$imageId/ancestry returned something unexpected:" - echo >&2 " $ancestryJson" - exit 1 - fi - - IFS=',' - ancestry=( ${ancestryJson//[\[\] \"]/} ) - unset IFS - - if [ -s "$dir/tags-$imageFile.tmp" ]; then - echo -n ', ' >> "$dir/tags-$imageFile.tmp" - else - images=( "${images[@]}" "$image" ) - fi - echo -n '"'"$tag"'": "'"$imageId"'"' >> "$dir/tags-$imageFile.tmp" - - echo "Downloading '$imageTag' (${#ancestry[@]} layers)..." - for imageId in "${ancestry[@]}"; do - mkdir -p "$dir/$imageId" - echo '1.0' > "$dir/$imageId/VERSION" - - curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/json" -o "$dir/$imageId/json" - - # TODO figure out why "-C -" doesn't work here - # "curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume." - # "HTTP/1.1 416 Requested Range Not Satisfiable" - if [ -f "$dir/$imageId/layer.tar" ]; then - # TODO hackpatch for no -C support :'( - echo "skipping existing ${imageId:0:12}" - continue - fi - curl -SL --progress -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/layer" -o "$dir/$imageId/layer.tar" # -C - - done - echo -done - -echo -n '{' > "$dir/repositories" -firstImage=1 -for image in "${images[@]}"; do - imageFile="${image//\//_}" # "/" can't be in filenames :) - - [ "$firstImage" ] || echo -n ',' >> "$dir/repositories" - firstImage= - echo -n $'\n\t' >> "$dir/repositories" - echo -n '"'"$image"'": { '"$(cat "$dir/tags-$imageFile.tmp")"' }' >> "$dir/repositories" -done -echo -n $'\n}\n' >> "$dir/repositories" - -rm -f "$dir"/tags-*.tmp - -echo "Download of images into '$dir' complete." -echo "Use something like the following to load the result into a Docker daemon:" -echo " tar -cC '$dir' . | docker load" diff --git a/vendor/github.com/docker/docker/contrib/download-frozen-image-v2.sh b/vendor/github.com/docker/docker/contrib/download-frozen-image-v2.sh deleted file mode 100755 index 111e3fa..0000000 --- a/vendor/github.com/docker/docker/contrib/download-frozen-image-v2.sh +++ /dev/null @@ -1,121 +0,0 @@ -#!/bin/bash -set -e - -# hello-world latest ef872312fe1b 3 months ago 910 B -# hello-world latest ef872312fe1bbc5e05aae626791a47ee9b032efa8f3bda39cc0be7b56bfe59b9 3 months ago 910 B - -# debian latest f6fab3b798be 10 weeks ago 85.1 MB -# debian latest f6fab3b798be3174f45aa1eb731f8182705555f89c9026d8c1ef230cbf8301dd 10 weeks ago 85.1 MB - -if ! command -v curl &> /dev/null; then - echo >&2 'error: "curl" not found!' - exit 1 -fi - -usage() { - echo "usage: $0 dir image[:tag][@digest] ..." - echo " $0 /tmp/old-hello-world hello-world:latest@sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7" - [ -z "$1" ] || exit "$1" -} - -dir="$1" # dir for building tar in -shift || usage 1 >&2 - -[ $# -gt 0 -a "$dir" ] || usage 2 >&2 -mkdir -p "$dir" - -# hacky workarounds for Bash 3 support (no associative arrays) -images=() -rm -f "$dir"/tags-*.tmp -# repositories[busybox]='"latest": "...", "ubuntu-14.04": "..."' - -while [ $# -gt 0 ]; do - imageTag="$1" - shift - image="${imageTag%%[:@]*}" - imageTag="${imageTag#*:}" - digest="${imageTag##*@}" - tag="${imageTag%%@*}" - - # add prefix library if passed official image - if [[ "$image" != *"/"* ]]; then - image="library/$image" - fi - - imageFile="${image//\//_}" # "/" can't be in filenames :) - - token="$(curl -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$image:pull" | jq --raw-output .token)" - - manifestJson="$(curl -sSL -H "Authorization: Bearer $token" "https://registry-1.docker.io/v2/$image/manifests/$digest")" - if [ "${manifestJson:0:1}" != '{' ]; then - echo >&2 "error: /v2/$image/manifests/$digest returned something unexpected:" - echo >&2 " $manifestJson" - exit 1 - fi - - layersFs=$(echo "$manifestJson" | jq --raw-output '.fsLayers | .[] | .blobSum') - - IFS=$'\n' - # bash v4 on Windows CI requires CRLF separator - if [ "$(go env GOHOSTOS)" = 'windows' ]; then - major=$(echo ${BASH_VERSION%%[^0.9]} | cut -d. -f1) - if [ "$major" -ge 4 ]; then - IFS=$'\r\n' - fi - fi - layers=( ${layersFs} ) - unset IFS - - history=$(echo "$manifestJson" | jq '.history | [.[] | .v1Compatibility]') - imageId=$(echo "$history" | jq --raw-output .[0] | jq --raw-output .id) - - if [ -s "$dir/tags-$imageFile.tmp" ]; then - echo -n ', ' >> "$dir/tags-$imageFile.tmp" - else - images=( "${images[@]}" "$image" ) - fi - echo -n '"'"$tag"'": "'"$imageId"'"' >> "$dir/tags-$imageFile.tmp" - - echo "Downloading '${image}:${tag}@${digest}' (${#layers[@]} layers)..." - for i in "${!layers[@]}"; do - imageJson=$(echo "$history" | jq --raw-output .[${i}]) - imageId=$(echo "$imageJson" | jq --raw-output .id) - imageLayer=${layers[$i]} - - mkdir -p "$dir/$imageId" - echo '1.0' > "$dir/$imageId/VERSION" - - echo "$imageJson" > "$dir/$imageId/json" - - # TODO figure out why "-C -" doesn't work here - # "curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume." - # "HTTP/1.1 416 Requested Range Not Satisfiable" - if [ -f "$dir/$imageId/layer.tar" ]; then - # TODO hackpatch for no -C support :'( - echo "skipping existing ${imageId:0:12}" - continue - fi - token="$(curl -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$image:pull" | jq --raw-output .token)" - curl -SL --progress -H "Authorization: Bearer $token" "https://registry-1.docker.io/v2/$image/blobs/$imageLayer" -o "$dir/$imageId/layer.tar" # -C - - done - echo -done - -echo -n '{' > "$dir/repositories" -firstImage=1 -for image in "${images[@]}"; do - imageFile="${image//\//_}" # "/" can't be in filenames :) - image="${image#library\/}" - - [ "$firstImage" ] || echo -n ',' >> "$dir/repositories" - firstImage= - echo -n $'\n\t' >> "$dir/repositories" - echo -n '"'"$image"'": { '"$(cat "$dir/tags-$imageFile.tmp")"' }' >> "$dir/repositories" -done -echo -n $'\n}\n' >> "$dir/repositories" - -rm -f "$dir"/tags-*.tmp - -echo "Download of images into '$dir' complete." -echo "Use something like the following to load the result into a Docker daemon:" -echo " tar -cC '$dir' . | docker load" diff --git a/vendor/github.com/docker/docker/contrib/editorconfig b/vendor/github.com/docker/docker/contrib/editorconfig deleted file mode 100644 index 97eda89..0000000 --- a/vendor/github.com/docker/docker/contrib/editorconfig +++ /dev/null @@ -1,13 +0,0 @@ -root = true - -[*] -end_of_line = lf -insert_final_newline = true -charset = utf-8 -indent_style = tab -indent_size = 4 -trim_trailing_whitespace = true - -[*.md] -indent_size = 2 -indent_style = space diff --git a/vendor/github.com/docker/docker/contrib/gitdm/aliases b/vendor/github.com/docker/docker/contrib/gitdm/aliases deleted file mode 100644 index dd5dd34..0000000 --- a/vendor/github.com/docker/docker/contrib/gitdm/aliases +++ /dev/null @@ -1,148 +0,0 @@ -Danny.Yates@mailonline.co.uk danny@codeaholics.org -KenCochrane@gmail.com kencochrane@gmail.com -LÉVEIL thomasleveil@gmail.com -Vincent.Bernat@exoscale.ch bernat@luffy.cx -acidburn@docker.com jess@docker.com -admin@jtlebi.fr jt@yadutaf.fr -ahmetalpbalkan@gmail.com ahmetb@microsoft.com -aj@gandi.net aj@gandi.net -albers@users.noreply.github.com github@albersweb.de -alexander.larsson@gmail.com alexl@redhat.com -amurdaca@redhat.com antonio.murdaca@gmail.com -amy@gandi.net aj@gandi.net -andrew.weiss@microsoft.com andrew.weiss@outlook.com -angt@users.noreply.github.com adrien@gallouet.fr -ankushagarwal@users.noreply.github.com ankushagarwal11@gmail.com -anonymouse2048@gmail.com lheckemann@twig-world.com -anusha@docker.com anusha.ragunathan@docker.com -asarai@suse.com asarai@suse.de -avi.miller@gmail.com avi.miller@oracle.com -bernat@luffy.cx Vincent.Bernat@exoscale.ch -bgoff@cpuguy83-mbp.home cpuguy83@gmail.com -brandon@ifup.co brandon@ifup.org -brent@docker.com brent.salisbury@docker.com -charmes.guillaume@gmail.com guillaume.charmes@docker.com -chenchun.feed@gmail.com ramichen@tencent.com -chooper@plumata.com charles.hooper@dotcloud.com -crosby.michael@gmail.com michael@docker.com -crosbymichael@gmail.com michael@docker.com -cyphar@cyphar.com asarai@suse.de -daehyeok@daehyeok-ui-MacBook-Air.local daehyeok@gmail.com -daehyeok@daehyeokui-MacBook-Air.local daehyeok@gmail.com -daniel.norberg@gmail.com dano@spotify.com -daniel@dotcloud.com daniel.mizyrycki@dotcloud.com -darren@rancher.com darren.s.shepherd@gmail.com -dave@dtucker.co.uk dt@docker.com -dev@vvieux.com victor.vieux@docker.com -dgasienica@zynga.com daniel@gasienica.ch -dnephin@gmail.com dnephin@docker.com -dominikh@fork-bomb.org dominik@honnef.co -dqminh89@gmail.com dqminh@cloudflare.com -dsxiao@dataman-inc.com dxiao@redhat.com -duglin@users.noreply.github.com dug@us.ibm.com -eric.hanchrow@gmail.com ehanchrow@ine.com -erik+github@hollensbe.org github@hollensbe.org -estesp@gmail.com estesp@linux.vnet.ibm.com -ewindisch@docker.com eric@windisch.us -f.joffrey@gmail.com joffrey@docker.com -fkautz@alumni.cmu.edu fkautz@redhat.com -frank.rosquin@gmail.com frank.rosquin+github@gmail.com -gh@mattyw.net mattyw@me.com -git@julienbordellier.com julienbordellier@gmail.com -github@metaliveblog.com github@developersupport.net -github@srid.name sridharr@activestate.com -guillaume.charmes@dotcloud.com guillaume.charmes@docker.com -guillaume@charmes.net guillaume.charmes@docker.com -guillaume@docker.com guillaume.charmes@docker.com -guillaume@dotcloud.com guillaume.charmes@docker.com -haoshuwei24@gmail.com haosw@cn.ibm.com -hollie.teal@docker.com hollie@docker.com -hollietealok@users.noreply.github.com hollie@docker.com -hsinko@users.noreply.github.com 21551195@zju.edu.cn -iamironbob@gmail.com altsysrq@gmail.com -icecrime@gmail.com arnaud.porterie@docker.com -jatzen@gmail.com jacob@jacobatzen.dk -jeff@allingeek.com jeff.nickoloff@gmail.com -jefferya@programmerq.net jeff@docker.com -jerome.petazzoni@dotcloud.com jerome.petazzoni@dotcloud.com -jfrazelle@users.noreply.github.com jess@docker.com -jhoward@microsoft.com John.Howard@microsoft.com -jlhawn@berkeley.edu josh.hawn@docker.com -joffrey@dotcloud.com joffrey@docker.com -john.howard@microsoft.com John.Howard@microsoft.com -jp@enix.org jerome.petazzoni@dotcloud.com -justin.cormack@unikernel.com justin.cormack@docker.com -justin.simonelis@PTS-JSIMON2.toronto.exclamation.com justin.p.simonelis@gmail.com -justin@specialbusservice.com justin.cormack@docker.com -katsuta_soshi@cyberagent.co.jp soshi.katsuta@gmail.com -kuehnle@online.de git.nivoc@neverbox.com -kwk@users.noreply.github.com konrad.wilhelm.kleine@gmail.com -leijitang@gmail.com leijitang@huawei.com -liubin0329@gmail.com liubin0329@users.noreply.github.com -lk4d4math@gmail.com lk4d4@docker.com -louis@dotcloud.com kalessin@kalessin.fr -lsm5@redhat.com lsm5@fedoraproject.org -lyndaoleary@hotmail.com lyndaoleary29@gmail.com -madhu@socketplane.io madhu@docker.com -martins@noironetworks.com aanm90@gmail.com -mary@docker.com mary.anthony@docker.com -mastahyeti@users.noreply.github.com mastahyeti@gmail.com -maztaim@users.noreply.github.com taim@bosboot.org -me@runcom.ninja antonio.murdaca@gmail.com -mheon@mheonlaptop.redhat.com mheon@redhat.com -michael@crosbymichael.com michael@docker.com -mohitsoni1989@gmail.com mosoni@ebay.com -moxieandmore@gmail.com mary.anthony@docker.com -moyses.furtado@wplex.com.br moysesb@gmail.com -msabramo@gmail.com marc@marc-abramowitz.com -mzdaniel@glidelink.net daniel.mizyrycki@dotcloud.com -nathan.leclaire@gmail.com nathan.leclaire@docker.com -nathanleclaire@gmail.com nathan.leclaire@docker.com -ostezer@users.noreply.github.com ostezer@gmail.com -peter@scraperwiki.com p@pwaller.net -princess@docker.com jess@docker.com -proppy@aminche.com proppy@google.com -qhuang@10.0.2.15 h.huangqiang@huawei.com -resouer@gmail.com resouer@163.com -roberto_hashioka@hotmail.com roberto.hashioka@docker.com -root@vagrant-ubuntu-12.10.vagrantup.com daniel.mizyrycki@dotcloud.com -runcom@linux.com antonio.murdaca@gmail.com -runcom@redhat.com antonio.murdaca@gmail.com -runcom@users.noreply.github.com antonio.murdaca@gmail.com -s@docker.com solomon@docker.com -shawnlandden@gmail.com shawn@churchofgit.com -singh.gurjeet@gmail.com gurjeet@singh.im -sjoerd@byte.nl sjoerd-github@linuxonly.nl -smahajan@redhat.com shishir.mahajan@redhat.com -solomon.hykes@dotcloud.com solomon@docker.com -solomon@dotcloud.com solomon@docker.com -stefanb@us.ibm.com stefanb@linux.vnet.ibm.com -stevvooe@users.noreply.github.com stephen.day@docker.com -superbaloo+registrations.github@superbaloo.net baloo@gandi.net -tangicolin@gmail.com tangicolin@gmail.com -thaJeztah@users.noreply.github.com github@gone.nl -thatcher@dotcloud.com thatcher@docker.com -thatcher@gmx.net thatcher@docker.com -tibor@docker.com teabee89@gmail.com -tiborvass@users.noreply.github.com teabee89@gmail.com -timruffles@googlemail.com oi@truffles.me.uk -tintypemolly@Ohui-MacBook-Pro.local tintypemolly@gmail.com -tj@init.me tejesh.mehta@gmail.com -tristan.carel@gmail.com tristan@cogniteev.com -unclejack@users.noreply.github.com cristian.staretu@gmail.com -unclejacksons@gmail.com cristian.staretu@gmail.com -vbatts@hashbangbash.com vbatts@redhat.com -victor.vieux@dotcloud.com victor.vieux@docker.com -victor@docker.com victor.vieux@docker.com -victor@dotcloud.com victor.vieux@docker.com -victorvieux@gmail.com victor.vieux@docker.com -vieux@docker.com victor.vieux@docker.com -vincent+github@demeester.fr vincent@sbr.pm -vincent@bernat.im bernat@luffy.cx -vojnovski@gmail.com viktor.vojnovski@amadeus.com -whoshuu@gmail.com huu@prismskylabs.com -xiaods@gmail.com dxiao@redhat.com -xlgao@zju.edu.cn xlgao@zju.edu.cn -yestin.sun@polyera.com sunyi0804@gmail.com -yuchangchun1@huawei.com yuchangchun1@huawei.com -zjaffee@us.ibm.com zij@case.edu diff --git a/vendor/github.com/docker/docker/contrib/gitdm/domain-map b/vendor/github.com/docker/docker/contrib/gitdm/domain-map deleted file mode 100644 index 1f1849e..0000000 --- a/vendor/github.com/docker/docker/contrib/gitdm/domain-map +++ /dev/null @@ -1,39 +0,0 @@ -# -# Docker -# - -docker.com Docker -dotcloud.com Docker - -aluzzardi@gmail.com Docker -cpuguy83@gmail.com Docker -derek@mcgstyle.net Docker -github@gone.nl Docker -kencochrane@gmail.com Docker -mickael.laventure@gmail.com Docker -sam.alba@gmail.com Docker -svendowideit@fosiki.com Docker -svendowideit@home.org.au Docker -tonistiigi@gmail.com Docker - -cristian.staretu@gmail.com Docker < 2015-01-01 -cristian.staretu@gmail.com Cisco - -github@hollensbe.org Docker < 2015-01-01 -github@hollensbe.org Cisco - -david.calavera@gmail.com Docker < 2016-04-01 -david.calavera@gmail.com Netlify - -# -# Others -# - -cisco.com Cisco -google.com Google -ibm.com IBM -huawei.com Huawei -microsoft.com Microsoft - -redhat.com Red Hat -mrunalp@gmail.com Red Hat diff --git a/vendor/github.com/docker/docker/contrib/gitdm/generate_aliases.sh b/vendor/github.com/docker/docker/contrib/gitdm/generate_aliases.sh deleted file mode 100755 index dd6a564..0000000 --- a/vendor/github.com/docker/docker/contrib/gitdm/generate_aliases.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# -# This script generates a gitdm compatible email aliases file from a git -# formatted .mailmap file. -# -# Usage: -# $> ./generate_aliases > aliases -# - -cat $1 | \ - grep -v '^#' | \ - sed 's/^[^<]*<\([^>]*\)>/\1/' | \ - grep '<.*>' | sed -e 's/[<>]/ /g' | \ - awk '{if ($3 != "") { print $3" "$1 } else {print $2" "$1}}' | \ - sort | uniq diff --git a/vendor/github.com/docker/docker/contrib/gitdm/gitdm.config b/vendor/github.com/docker/docker/contrib/gitdm/gitdm.config deleted file mode 100644 index d9b62b0..0000000 --- a/vendor/github.com/docker/docker/contrib/gitdm/gitdm.config +++ /dev/null @@ -1,17 +0,0 @@ -# -# EmailAliases lets us cope with developers who use more -# than one address. -# -EmailAliases aliases - -# -# EmailMap does the main work of mapping addresses onto -# employers. -# -EmailMap domain-map - -# -# Use GroupMap to map a file full of addresses to the -# same employer -# -# GroupMap company-Docker Docker diff --git a/vendor/github.com/docker/docker/contrib/httpserver/Dockerfile b/vendor/github.com/docker/docker/contrib/httpserver/Dockerfile deleted file mode 100644 index 747dc91..0000000 --- a/vendor/github.com/docker/docker/contrib/httpserver/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM busybox -EXPOSE 80/tcp -COPY httpserver . -CMD ["./httpserver"] diff --git a/vendor/github.com/docker/docker/contrib/httpserver/Dockerfile.solaris b/vendor/github.com/docker/docker/contrib/httpserver/Dockerfile.solaris deleted file mode 100644 index 3d0d691..0000000 --- a/vendor/github.com/docker/docker/contrib/httpserver/Dockerfile.solaris +++ /dev/null @@ -1,4 +0,0 @@ -FROM solaris -EXPOSE 80/tcp -COPY httpserver . -CMD ["./httpserver"] diff --git a/vendor/github.com/docker/docker/contrib/httpserver/server.go b/vendor/github.com/docker/docker/contrib/httpserver/server.go deleted file mode 100644 index a75d5ab..0000000 --- a/vendor/github.com/docker/docker/contrib/httpserver/server.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "log" - "net/http" -) - -func main() { - fs := http.FileServer(http.Dir("/static")) - http.Handle("/", fs) - log.Panic(http.ListenAndServe(":80", nil)) -} diff --git a/vendor/github.com/docker/docker/contrib/init/openrc/docker.confd b/vendor/github.com/docker/docker/contrib/init/openrc/docker.confd deleted file mode 100644 index 2444031..0000000 --- a/vendor/github.com/docker/docker/contrib/init/openrc/docker.confd +++ /dev/null @@ -1,13 +0,0 @@ -# /etc/conf.d/docker: config file for /etc/init.d/docker - -# where the docker daemon output gets piped -#DOCKER_LOGFILE="/var/log/docker.log" - -# where docker's pid get stored -#DOCKER_PIDFILE="/run/docker.pid" - -# where the docker daemon itself is run from -#DOCKERD_BINARY="/usr/bin/dockerd" - -# any other random options you want to pass to docker -DOCKER_OPTS="" diff --git a/vendor/github.com/docker/docker/contrib/init/openrc/docker.initd b/vendor/github.com/docker/docker/contrib/init/openrc/docker.initd deleted file mode 100644 index 5d31603..0000000 --- a/vendor/github.com/docker/docker/contrib/init/openrc/docker.initd +++ /dev/null @@ -1,22 +0,0 @@ -#!/sbin/openrc-run -# Copyright 1999-2013 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -command="${DOCKERD_BINARY:-/usr/bin/dockerd}" -pidfile="${DOCKER_PIDFILE:-/run/${RC_SVCNAME}.pid}" -command_args="-p \"${pidfile}\" ${DOCKER_OPTS}" -DOCKER_LOGFILE="${DOCKER_LOGFILE:-/var/log/${RC_SVCNAME}.log}" -start_stop_daemon_args="--background \ - --stderr \"${DOCKER_LOGFILE}\" --stdout \"${DOCKER_LOGFILE}\"" - -start_pre() { - checkpath -f -m 0644 -o root:docker "$DOCKER_LOGFILE" - - ulimit -n 1048576 - - # Having non-zero limits causes performance problems due to accounting overhead - # in the kernel. We recommend using cgroups to do container-local accounting. - ulimit -u unlimited - - return 0 -} diff --git a/vendor/github.com/docker/docker/contrib/init/systemd/REVIEWERS b/vendor/github.com/docker/docker/contrib/init/systemd/REVIEWERS deleted file mode 100644 index b9ba55b..0000000 --- a/vendor/github.com/docker/docker/contrib/init/systemd/REVIEWERS +++ /dev/null @@ -1,3 +0,0 @@ -Lokesh Mandvekar (@lsm5) -Brandon Philips (@philips) -Jessie Frazelle (@jfrazelle) diff --git a/vendor/github.com/docker/docker/contrib/init/systemd/docker.service b/vendor/github.com/docker/docker/contrib/init/systemd/docker.service deleted file mode 100644 index 8bfed93..0000000 --- a/vendor/github.com/docker/docker/contrib/init/systemd/docker.service +++ /dev/null @@ -1,29 +0,0 @@ -[Unit] -Description=Docker Application Container Engine -Documentation=https://docs.docker.com -After=network.target docker.socket firewalld.service -Requires=docker.socket - -[Service] -Type=notify -# the default is not to use systemd for cgroups because the delegate issues still -# exists and systemd currently does not support the cgroup feature set required -# for containers run by docker -ExecStart=/usr/bin/dockerd -H fd:// -ExecReload=/bin/kill -s HUP $MAINPID -LimitNOFILE=1048576 -# Having non-zero Limit*s causes performance problems due to accounting overhead -# in the kernel. We recommend using cgroups to do container-local accounting. -LimitNPROC=infinity -LimitCORE=infinity -# Uncomment TasksMax if your systemd version supports it. -# Only systemd 226 and above support this version. -#TasksMax=infinity -TimeoutStartSec=0 -# set delegate yes so that systemd does not reset the cgroups of docker containers -Delegate=yes -# kill only the docker process, not all processes in the cgroup -KillMode=process - -[Install] -WantedBy=multi-user.target diff --git a/vendor/github.com/docker/docker/contrib/init/systemd/docker.service.rpm b/vendor/github.com/docker/docker/contrib/init/systemd/docker.service.rpm deleted file mode 100644 index 6e41892..0000000 --- a/vendor/github.com/docker/docker/contrib/init/systemd/docker.service.rpm +++ /dev/null @@ -1,28 +0,0 @@ -[Unit] -Description=Docker Application Container Engine -Documentation=https://docs.docker.com -After=network.target firewalld.service - -[Service] -Type=notify -# the default is not to use systemd for cgroups because the delegate issues still -# exists and systemd currently does not support the cgroup feature set required -# for containers run by docker -ExecStart=/usr/bin/dockerd -ExecReload=/bin/kill -s HUP $MAINPID -# Having non-zero Limit*s causes performance problems due to accounting overhead -# in the kernel. We recommend using cgroups to do container-local accounting. -LimitNOFILE=infinity -LimitNPROC=infinity -LimitCORE=infinity -# Uncomment TasksMax if your systemd version supports it. -# Only systemd 226 and above support this version. -#TasksMax=infinity -TimeoutStartSec=0 -# set delegate yes so that systemd does not reset the cgroups of docker containers -Delegate=yes -# kill only the docker process, not all processes in the cgroup -KillMode=process - -[Install] -WantedBy=multi-user.target diff --git a/vendor/github.com/docker/docker/contrib/init/systemd/docker.socket b/vendor/github.com/docker/docker/contrib/init/systemd/docker.socket deleted file mode 100644 index 7dd9509..0000000 --- a/vendor/github.com/docker/docker/contrib/init/systemd/docker.socket +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Docker Socket for the API -PartOf=docker.service - -[Socket] -ListenStream=/var/run/docker.sock -SocketMode=0660 -SocketUser=root -SocketGroup=docker - -[Install] -WantedBy=sockets.target diff --git a/vendor/github.com/docker/docker/contrib/init/sysvinit-debian/docker b/vendor/github.com/docker/docker/contrib/init/sysvinit-debian/docker deleted file mode 100755 index 4f9d38d..0000000 --- a/vendor/github.com/docker/docker/contrib/init/sysvinit-debian/docker +++ /dev/null @@ -1,152 +0,0 @@ -#!/bin/sh -set -e - -### BEGIN INIT INFO -# Provides: docker -# Required-Start: $syslog $remote_fs -# Required-Stop: $syslog $remote_fs -# Should-Start: cgroupfs-mount cgroup-lite -# Should-Stop: cgroupfs-mount cgroup-lite -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Create lightweight, portable, self-sufficient containers. -# Description: -# Docker is an open-source project to easily create lightweight, portable, -# self-sufficient containers from any application. The same container that a -# developer builds and tests on a laptop can run at scale, in production, on -# VMs, bare metal, OpenStack clusters, public clouds and more. -### END INIT INFO - -export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin - -BASE=docker - -# modify these in /etc/default/$BASE (/etc/default/docker) -DOCKERD=/usr/bin/dockerd -# This is the pid file managed by docker itself -DOCKER_PIDFILE=/var/run/$BASE.pid -# This is the pid file created/managed by start-stop-daemon -DOCKER_SSD_PIDFILE=/var/run/$BASE-ssd.pid -DOCKER_LOGFILE=/var/log/$BASE.log -DOCKER_OPTS= -DOCKER_DESC="Docker" - -# Get lsb functions -. /lib/lsb/init-functions - -if [ -f /etc/default/$BASE ]; then - . /etc/default/$BASE -fi - -# Check docker is present -if [ ! -x $DOCKERD ]; then - log_failure_msg "$DOCKERD not present or not executable" - exit 1 -fi - -check_init() { - # see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it directly) - if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then - log_failure_msg "$DOCKER_DESC is managed via upstart, try using service $BASE $1" - exit 1 - fi -} - -fail_unless_root() { - if [ "$(id -u)" != '0' ]; then - log_failure_msg "$DOCKER_DESC must be run as root" - exit 1 - fi -} - -cgroupfs_mount() { - # see also https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount - if grep -v '^#' /etc/fstab | grep -q cgroup \ - || [ ! -e /proc/cgroups ] \ - || [ ! -d /sys/fs/cgroup ]; then - return - fi - if ! mountpoint -q /sys/fs/cgroup; then - mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup - fi - ( - cd /sys/fs/cgroup - for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do - mkdir -p $sys - if ! mountpoint -q $sys; then - if ! mount -n -t cgroup -o $sys cgroup $sys; then - rmdir $sys || true - fi - fi - done - ) -} - -case "$1" in - start) - check_init - - fail_unless_root - - cgroupfs_mount - - touch "$DOCKER_LOGFILE" - chgrp docker "$DOCKER_LOGFILE" - - ulimit -n 1048576 - - # Having non-zero limits causes performance problems due to accounting overhead - # in the kernel. We recommend using cgroups to do container-local accounting. - if [ "$BASH" ]; then - ulimit -u unlimited - else - ulimit -p unlimited - fi - - log_begin_msg "Starting $DOCKER_DESC: $BASE" - start-stop-daemon --start --background \ - --no-close \ - --exec "$DOCKERD" \ - --pidfile "$DOCKER_SSD_PIDFILE" \ - --make-pidfile \ - -- \ - -p "$DOCKER_PIDFILE" \ - $DOCKER_OPTS \ - >> "$DOCKER_LOGFILE" 2>&1 - log_end_msg $? - ;; - - stop) - check_init - fail_unless_root - log_begin_msg "Stopping $DOCKER_DESC: $BASE" - start-stop-daemon --stop --pidfile "$DOCKER_SSD_PIDFILE" --retry 10 - log_end_msg $? - ;; - - restart) - check_init - fail_unless_root - docker_pid=`cat "$DOCKER_SSD_PIDFILE" 2>/dev/null` - [ -n "$docker_pid" ] \ - && ps -p $docker_pid > /dev/null 2>&1 \ - && $0 stop - $0 start - ;; - - force-reload) - check_init - fail_unless_root - $0 restart - ;; - - status) - check_init - status_of_proc -p "$DOCKER_SSD_PIDFILE" "$DOCKERD" "$DOCKER_DESC" - ;; - - *) - echo "Usage: service docker {start|stop|restart|status}" - exit 1 - ;; -esac diff --git a/vendor/github.com/docker/docker/contrib/init/sysvinit-debian/docker.default b/vendor/github.com/docker/docker/contrib/init/sysvinit-debian/docker.default deleted file mode 100644 index c4e9319..0000000 --- a/vendor/github.com/docker/docker/contrib/init/sysvinit-debian/docker.default +++ /dev/null @@ -1,20 +0,0 @@ -# Docker Upstart and SysVinit configuration file - -# -# THIS FILE DOES NOT APPLY TO SYSTEMD -# -# Please see the documentation for "systemd drop-ins": -# https://docs.docker.com/engine/admin/systemd/ -# - -# Customize location of Docker binary (especially for development testing). -#DOCKERD="/usr/local/bin/dockerd" - -# Use DOCKER_OPTS to modify the daemon startup options. -#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4" - -# If you need Docker to use an HTTP proxy, it can also be specified here. -#export http_proxy="http://127.0.0.1:3128/" - -# This is also a handy place to tweak where Docker's temporary files go. -#export DOCKER_TMPDIR="/mnt/bigdrive/docker-tmp" diff --git a/vendor/github.com/docker/docker/contrib/init/sysvinit-redhat/docker b/vendor/github.com/docker/docker/contrib/init/sysvinit-redhat/docker deleted file mode 100755 index df9b02a..0000000 --- a/vendor/github.com/docker/docker/contrib/init/sysvinit-redhat/docker +++ /dev/null @@ -1,153 +0,0 @@ -#!/bin/sh -# -# /etc/rc.d/init.d/docker -# -# Daemon for docker.com -# -# chkconfig: 2345 95 95 -# description: Daemon for docker.com - -### BEGIN INIT INFO -# Provides: docker -# Required-Start: $network cgconfig -# Required-Stop: -# Should-Start: -# Should-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: start and stop docker -# Description: Daemon for docker.com -### END INIT INFO - -# Source function library. -. /etc/rc.d/init.d/functions - -prog="docker" -unshare=/usr/bin/unshare -exec="/usr/bin/dockerd" -pidfile="/var/run/$prog.pid" -lockfile="/var/lock/subsys/$prog" -logfile="/var/log/$prog" - -[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog - -prestart() { - service cgconfig status > /dev/null - - if [[ $? != 0 ]]; then - service cgconfig start - fi - -} - -start() { - if [ ! -x $exec ]; then - if [ ! -e $exec ]; then - echo "Docker executable $exec not found" - else - echo "You do not have permission to execute the Docker executable $exec" - fi - exit 5 - fi - - check_for_cleanup - - if ! [ -f $pidfile ]; then - prestart - printf "Starting $prog:\t" - echo "\n$(date)\n" >> $logfile - "$unshare" -m -- $exec $other_args >> $logfile 2>&1 & - pid=$! - touch $lockfile - # wait up to 10 seconds for the pidfile to exist. see - # https://github.com/docker/docker/issues/5359 - tries=0 - while [ ! -f $pidfile -a $tries -lt 10 ]; do - sleep 1 - tries=$((tries + 1)) - echo -n '.' - done - if [ ! -f $pidfile ]; then - failure - echo - exit 1 - fi - success - echo - else - failure - echo - printf "$pidfile still exists...\n" - exit 7 - fi -} - -stop() { - echo -n $"Stopping $prog: " - killproc -p $pidfile -d 300 $prog - retval=$? - echo - [ $retval -eq 0 ] && rm -f $lockfile - return $retval -} - -restart() { - stop - start -} - -reload() { - restart -} - -force_reload() { - restart -} - -rh_status() { - status -p $pidfile $prog -} - -rh_status_q() { - rh_status >/dev/null 2>&1 -} - - -check_for_cleanup() { - if [ -f ${pidfile} ]; then - /bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile} - fi -} - -case "$1" in - start) - rh_status_q && exit 0 - $1 - ;; - stop) - rh_status_q || exit 0 - $1 - ;; - restart) - $1 - ;; - reload) - rh_status_q || exit 7 - $1 - ;; - force-reload) - force_reload - ;; - status) - rh_status - ;; - condrestart|try-restart) - rh_status_q || exit 0 - restart - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" - exit 2 -esac - -exit $? diff --git a/vendor/github.com/docker/docker/contrib/init/sysvinit-redhat/docker.sysconfig b/vendor/github.com/docker/docker/contrib/init/sysvinit-redhat/docker.sysconfig deleted file mode 100644 index 0864b3d..0000000 --- a/vendor/github.com/docker/docker/contrib/init/sysvinit-redhat/docker.sysconfig +++ /dev/null @@ -1,7 +0,0 @@ -# /etc/sysconfig/docker -# -# Other arguments to pass to the docker daemon process -# These will be parsed by the sysv initscript and appended -# to the arguments list passed to docker daemon - -other_args="" diff --git a/vendor/github.com/docker/docker/contrib/init/upstart/REVIEWERS b/vendor/github.com/docker/docker/contrib/init/upstart/REVIEWERS deleted file mode 100644 index 03ee2dd..0000000 --- a/vendor/github.com/docker/docker/contrib/init/upstart/REVIEWERS +++ /dev/null @@ -1,2 +0,0 @@ -Tianon Gravi (@tianon) -Jessie Frazelle (@jfrazelle) diff --git a/vendor/github.com/docker/docker/contrib/init/upstart/docker.conf b/vendor/github.com/docker/docker/contrib/init/upstart/docker.conf deleted file mode 100644 index d58f7d6..0000000 --- a/vendor/github.com/docker/docker/contrib/init/upstart/docker.conf +++ /dev/null @@ -1,72 +0,0 @@ -description "Docker daemon" - -start on (filesystem and net-device-up IFACE!=lo) -stop on runlevel [!2345] - -limit nofile 524288 1048576 - -# Having non-zero limits causes performance problems due to accounting overhead -# in the kernel. We recommend using cgroups to do container-local accounting. -limit nproc unlimited unlimited - -respawn - -kill timeout 20 - -pre-start script - # see also https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount - if grep -v '^#' /etc/fstab | grep -q cgroup \ - || [ ! -e /proc/cgroups ] \ - || [ ! -d /sys/fs/cgroup ]; then - exit 0 - fi - if ! mountpoint -q /sys/fs/cgroup; then - mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup - fi - ( - cd /sys/fs/cgroup - for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do - mkdir -p $sys - if ! mountpoint -q $sys; then - if ! mount -n -t cgroup -o $sys cgroup $sys; then - rmdir $sys || true - fi - fi - done - ) -end script - -script - # modify these in /etc/default/$UPSTART_JOB (/etc/default/docker) - DOCKERD=/usr/bin/dockerd - DOCKER_OPTS= - if [ -f /etc/default/$UPSTART_JOB ]; then - . /etc/default/$UPSTART_JOB - fi - exec "$DOCKERD" $DOCKER_OPTS --raw-logs -end script - -# Don't emit "started" event until docker.sock is ready. -# See https://github.com/docker/docker/issues/6647 -post-start script - DOCKER_OPTS= - DOCKER_SOCKET= - if [ -f /etc/default/$UPSTART_JOB ]; then - . /etc/default/$UPSTART_JOB - fi - - if ! printf "%s" "$DOCKER_OPTS" | grep -qE -e '-H|--host'; then - DOCKER_SOCKET=/var/run/docker.sock - else - DOCKER_SOCKET=$(printf "%s" "$DOCKER_OPTS" | grep -oP -e '(-H|--host)\W*unix://\K(\S+)' | sed 1q) - fi - - if [ -n "$DOCKER_SOCKET" ]; then - while ! [ -e "$DOCKER_SOCKET" ]; do - initctl status $UPSTART_JOB | grep -qE "(stop|respawn)/" && exit 1 - echo "Waiting for $DOCKER_SOCKET" - sleep 0.1 - done - echo "$DOCKER_SOCKET is up" - fi -end script diff --git a/vendor/github.com/docker/docker/contrib/mac-install-bundle.sh b/vendor/github.com/docker/docker/contrib/mac-install-bundle.sh deleted file mode 100755 index 2110d04..0000000 --- a/vendor/github.com/docker/docker/contrib/mac-install-bundle.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh - -set -e - -errexit() { - echo "$1" - exit 1 -} - -[ "$(uname -s)" == "Darwin" ] || errexit "This script can only be used on a Mac" - -[ $# -eq 1 ] || errexit "Usage: $0 install|undo" - -BUNDLE="bundles/$(cat VERSION)" -BUNDLE_PATH="$PWD/$BUNDLE" -CLIENT_PATH="$BUNDLE_PATH/cross/darwin/amd64/docker" -DATABASE="$HOME/Library/Containers/com.docker.docker/Data/database" -DATABASE_KEY="$DATABASE/com.docker.driver.amd64-linux/bundle" - -[ -d "$DATABASE" ] || errexit "Docker for Mac must be installed for this script" - -case "$1" in -"install") - [ -d "$BUNDLE" ] || errexit "cannot find bundle $BUNDLE" - [ -e "$CLIENT_PATH" ] || errexit "you need to run make cross first" - [ -e "$BUNDLE/binary-daemon/dockerd" ] || errexit "you need to build binaries first" - [ -f "$BUNDLE/binary-client/docker" ] || errexit "you need to build binaries first" - git -C "$DATABASE" reset --hard >/dev/null - echo "$BUNDLE_PATH" > "$DATABASE_KEY" - git -C "$DATABASE" add "$DATABASE_KEY" - git -C "$DATABASE" commit -m "update bundle to $BUNDLE_PATH" - rm -f /usr/local/bin/docker - cp "$CLIENT_PATH" /usr/local/bin - echo "Bundle installed. Restart Docker to use. To uninstall, reset Docker to factory defaults." - ;; -"undo") - git -C "$DATABASE" reset --hard >/dev/null - [ -f "$DATABASE_KEY" ] || errexit "bundle not set" - git -C "$DATABASE" rm "$DATABASE_KEY" - git -C "$DATABASE" commit -m "remove bundle" - rm -f /usr/local/bin/docker - ln -s "$HOME/Library/Group Containers/group.com.docker/bin/docker" /usr/local/bin - echo "Bundle removed. Using dev versions may cause issues, a reset to factory defaults is recommended." - ;; -esac diff --git a/vendor/github.com/docker/docker/contrib/mkimage-alpine.sh b/vendor/github.com/docker/docker/contrib/mkimage-alpine.sh deleted file mode 100755 index 47cd35c..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage-alpine.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/sh - -set -e - -[ $(id -u) -eq 0 ] || { - printf >&2 '%s requires root\n' "$0" - exit 1 -} - -usage() { - printf >&2 '%s: [-r release] [-m mirror] [-s] [-c additional repository]\n' "$0" - exit 1 -} - -tmp() { - TMP=$(mktemp -d ${TMPDIR:-/var/tmp}/alpine-docker-XXXXXXXXXX) - ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/alpine-docker-rootfs-XXXXXXXXXX) - trap "rm -rf $TMP $ROOTFS" EXIT TERM INT -} - -apkv() { - curl -sSL $MAINREPO/$ARCH/APKINDEX.tar.gz | tar -Oxz | - grep --text '^P:apk-tools-static$' -A1 | tail -n1 | cut -d: -f2 -} - -getapk() { - curl -sSL $MAINREPO/$ARCH/apk-tools-static-$(apkv).apk | - tar -xz -C $TMP sbin/apk.static -} - -mkbase() { - $TMP/sbin/apk.static --repository $MAINREPO --update-cache --allow-untrusted \ - --root $ROOTFS --initdb add alpine-base -} - -conf() { - printf '%s\n' $MAINREPO > $ROOTFS/etc/apk/repositories - printf '%s\n' $ADDITIONALREPO >> $ROOTFS/etc/apk/repositories -} - -pack() { - local id - id=$(tar --numeric-owner -C $ROOTFS -c . | docker import - alpine:$REL) - - docker tag $id alpine:latest - docker run -i -t --rm alpine printf 'alpine:%s with id=%s created!\n' $REL $id -} - -save() { - [ $SAVE -eq 1 ] || return - - tar --numeric-owner -C $ROOTFS -c . | xz > rootfs.tar.xz -} - -while getopts "hr:m:s" opt; do - case $opt in - r) - REL=$OPTARG - ;; - m) - MIRROR=$OPTARG - ;; - s) - SAVE=1 - ;; - c) - ADDITIONALREPO=community - ;; - *) - usage - ;; - esac -done - -REL=${REL:-edge} -MIRROR=${MIRROR:-http://nl.alpinelinux.org/alpine} -SAVE=${SAVE:-0} -MAINREPO=$MIRROR/$REL/main -ADDITIONALREPO=$MIRROR/$REL/community -ARCH=${ARCH:-$(uname -m)} - -tmp -getapk -mkbase -conf -pack -save diff --git a/vendor/github.com/docker/docker/contrib/mkimage-arch-pacman.conf b/vendor/github.com/docker/docker/contrib/mkimage-arch-pacman.conf deleted file mode 100644 index 45fe03d..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage-arch-pacman.conf +++ /dev/null @@ -1,92 +0,0 @@ -# -# /etc/pacman.conf -# -# See the pacman.conf(5) manpage for option and repository directives - -# -# GENERAL OPTIONS -# -[options] -# The following paths are commented out with their default values listed. -# If you wish to use different paths, uncomment and update the paths. -#RootDir = / -#DBPath = /var/lib/pacman/ -#CacheDir = /var/cache/pacman/pkg/ -#LogFile = /var/log/pacman.log -#GPGDir = /etc/pacman.d/gnupg/ -HoldPkg = pacman glibc -#XferCommand = /usr/bin/curl -C - -f %u > %o -#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u -#CleanMethod = KeepInstalled -#UseDelta = 0.7 -Architecture = auto - -# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup -#IgnorePkg = -#IgnoreGroup = - -#NoUpgrade = -#NoExtract = - -# Misc options -#UseSyslog -#Color -#TotalDownload -# We cannot check disk space from within a chroot environment -#CheckSpace -#VerbosePkgLists - -# By default, pacman accepts packages signed by keys that its local keyring -# trusts (see pacman-key and its man page), as well as unsigned packages. -SigLevel = Required DatabaseOptional -LocalFileSigLevel = Optional -#RemoteFileSigLevel = Required - -# NOTE: You must run `pacman-key --init` before first using pacman; the local -# keyring can then be populated with the keys of all official Arch Linux -# packagers with `pacman-key --populate archlinux`. - -# -# REPOSITORIES -# - can be defined here or included from another file -# - pacman will search repositories in the order defined here -# - local/custom mirrors can be added here or in separate files -# - repositories listed first will take precedence when packages -# have identical names, regardless of version number -# - URLs will have $repo replaced by the name of the current repo -# - URLs will have $arch replaced by the name of the architecture -# -# Repository entries are of the format: -# [repo-name] -# Server = ServerName -# Include = IncludePath -# -# The header [repo-name] is crucial - it must be present and -# uncommented to enable the repo. -# - -# The testing repositories are disabled by default. To enable, uncomment the -# repo name header and Include lines. You can add preferred servers immediately -# after the header, and they will be used before the default mirrors. - -#[testing] -#Include = /etc/pacman.d/mirrorlist - -[core] -Include = /etc/pacman.d/mirrorlist - -[extra] -Include = /etc/pacman.d/mirrorlist - -#[community-testing] -#Include = /etc/pacman.d/mirrorlist - -[community] -Include = /etc/pacman.d/mirrorlist - -# An example of a custom package repository. See the pacman manpage for -# tips on creating your own repositories. -#[custom] -#SigLevel = Optional TrustAll -#Server = file:///home/custompkgs - diff --git a/vendor/github.com/docker/docker/contrib/mkimage-arch.sh b/vendor/github.com/docker/docker/contrib/mkimage-arch.sh deleted file mode 100755 index f941177..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage-arch.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env bash -# Generate a minimal filesystem for archlinux and load it into the local -# docker as "archlinux" -# requires root -set -e - -hash pacstrap &>/dev/null || { - echo "Could not find pacstrap. Run pacman -S arch-install-scripts" - exit 1 -} - -hash expect &>/dev/null || { - echo "Could not find expect. Run pacman -S expect" - exit 1 -} - - -export LANG="C.UTF-8" - -ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-archlinux-XXXXXXXXXX) -chmod 755 $ROOTFS - -# packages to ignore for space savings -PKGIGNORE=( - cryptsetup - device-mapper - dhcpcd - iproute2 - jfsutils - linux - lvm2 - man-db - man-pages - mdadm - nano - netctl - openresolv - pciutils - pcmciautils - reiserfsprogs - s-nail - systemd-sysvcompat - usbutils - vi - xfsprogs -) -IFS=',' -PKGIGNORE="${PKGIGNORE[*]}" -unset IFS - -arch="$(uname -m)" -case "$arch" in - armv*) - if pacman -Q archlinuxarm-keyring >/dev/null 2>&1; then - pacman-key --init - pacman-key --populate archlinuxarm - else - echo "Could not find archlinuxarm-keyring. Please, install it and run pacman-key --populate archlinuxarm" - exit 1 - fi - PACMAN_CONF=$(mktemp ${TMPDIR:-/var/tmp}/pacman-conf-archlinux-XXXXXXXXX) - version="$(echo $arch | cut -c 5)" - sed "s/Architecture = armv/Architecture = armv${version}h/g" './mkimage-archarm-pacman.conf' > "${PACMAN_CONF}" - PACMAN_MIRRORLIST='Server = http://mirror.archlinuxarm.org/$arch/$repo' - PACMAN_EXTRA_PKGS='archlinuxarm-keyring' - EXPECT_TIMEOUT=1800 # Most armv* based devices can be very slow (e.g. RPiv1) - ARCH_KEYRING=archlinuxarm - DOCKER_IMAGE_NAME="armv${version}h/archlinux" - ;; - *) - PACMAN_CONF='./mkimage-arch-pacman.conf' - PACMAN_MIRRORLIST='Server = https://mirrors.kernel.org/archlinux/$repo/os/$arch' - PACMAN_EXTRA_PKGS='' - EXPECT_TIMEOUT=60 - ARCH_KEYRING=archlinux - DOCKER_IMAGE_NAME=archlinux - ;; -esac - -export PACMAN_MIRRORLIST - -expect < $ROOTFS/etc/locale.gen -arch-chroot $ROOTFS locale-gen -arch-chroot $ROOTFS /bin/sh -c 'echo $PACMAN_MIRRORLIST > /etc/pacman.d/mirrorlist' - -# udev doesn't work in containers, rebuild /dev -DEV=$ROOTFS/dev -rm -rf $DEV -mkdir -p $DEV -mknod -m 666 $DEV/null c 1 3 -mknod -m 666 $DEV/zero c 1 5 -mknod -m 666 $DEV/random c 1 8 -mknod -m 666 $DEV/urandom c 1 9 -mkdir -m 755 $DEV/pts -mkdir -m 1777 $DEV/shm -mknod -m 666 $DEV/tty c 5 0 -mknod -m 600 $DEV/console c 5 1 -mknod -m 666 $DEV/tty0 c 4 0 -mknod -m 666 $DEV/full c 1 7 -mknod -m 600 $DEV/initctl p -mknod -m 666 $DEV/ptmx c 5 2 -ln -sf /proc/self/fd $DEV/fd - -tar --numeric-owner --xattrs --acls -C $ROOTFS -c . | docker import - $DOCKER_IMAGE_NAME -docker run --rm -t $DOCKER_IMAGE_NAME echo Success. -rm -rf $ROOTFS diff --git a/vendor/github.com/docker/docker/contrib/mkimage-archarm-pacman.conf b/vendor/github.com/docker/docker/contrib/mkimage-archarm-pacman.conf deleted file mode 100644 index f4b45f5..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage-archarm-pacman.conf +++ /dev/null @@ -1,98 +0,0 @@ -# -# /etc/pacman.conf -# -# See the pacman.conf(5) manpage for option and repository directives - -# -# GENERAL OPTIONS -# -[options] -# The following paths are commented out with their default values listed. -# If you wish to use different paths, uncomment and update the paths. -#RootDir = / -#DBPath = /var/lib/pacman/ -#CacheDir = /var/cache/pacman/pkg/ -#LogFile = /var/log/pacman.log -#GPGDir = /etc/pacman.d/gnupg/ -HoldPkg = pacman glibc -#XferCommand = /usr/bin/curl -C - -f %u > %o -#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u -#CleanMethod = KeepInstalled -#UseDelta = 0.7 -Architecture = armv - -# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup -#IgnorePkg = -#IgnoreGroup = - -#NoUpgrade = -#NoExtract = - -# Misc options -#UseSyslog -#Color -#TotalDownload -# We cannot check disk space from within a chroot environment -#CheckSpace -#VerbosePkgLists - -# By default, pacman accepts packages signed by keys that its local keyring -# trusts (see pacman-key and its man page), as well as unsigned packages. -SigLevel = Required DatabaseOptional -LocalFileSigLevel = Optional -#RemoteFileSigLevel = Required - -# NOTE: You must run `pacman-key --init` before first using pacman; the local -# keyring can then be populated with the keys of all official Arch Linux -# packagers with `pacman-key --populate archlinux`. - -# -# REPOSITORIES -# - can be defined here or included from another file -# - pacman will search repositories in the order defined here -# - local/custom mirrors can be added here or in separate files -# - repositories listed first will take precedence when packages -# have identical names, regardless of version number -# - URLs will have $repo replaced by the name of the current repo -# - URLs will have $arch replaced by the name of the architecture -# -# Repository entries are of the format: -# [repo-name] -# Server = ServerName -# Include = IncludePath -# -# The header [repo-name] is crucial - it must be present and -# uncommented to enable the repo. -# - -# The testing repositories are disabled by default. To enable, uncomment the -# repo name header and Include lines. You can add preferred servers immediately -# after the header, and they will be used before the default mirrors. - -#[testing] -#Include = /etc/pacman.d/mirrorlist - -[core] -Include = /etc/pacman.d/mirrorlist - -[extra] -Include = /etc/pacman.d/mirrorlist - -#[community-testing] -#Include = /etc/pacman.d/mirrorlist - -[community] -Include = /etc/pacman.d/mirrorlist - -[alarm] -Include = /etc/pacman.d/mirrorlist - -[aur] -Include = /etc/pacman.d/mirrorlist - -# An example of a custom package repository. See the pacman manpage for -# tips on creating your own repositories. -#[custom] -#SigLevel = Optional TrustAll -#Server = file:///home/custompkgs - diff --git a/vendor/github.com/docker/docker/contrib/mkimage-busybox.sh b/vendor/github.com/docker/docker/contrib/mkimage-busybox.sh deleted file mode 100755 index b11a6bb..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage-busybox.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# Generate a very minimal filesystem based on busybox-static, -# and load it into the local docker under the name "busybox". - -echo >&2 -echo >&2 'warning: this script is deprecated - see mkimage.sh and mkimage/busybox-static' -echo >&2 - -BUSYBOX=$(which busybox) -[ "$BUSYBOX" ] || { - echo "Sorry, I could not locate busybox." - echo "Try 'apt-get install busybox-static'?" - exit 1 -} - -set -e -ROOTFS=${TMPDIR:-/var/tmp}/rootfs-busybox-$$-$RANDOM -mkdir $ROOTFS -cd $ROOTFS - -mkdir bin etc dev dev/pts lib proc sys tmp -touch etc/resolv.conf -cp /etc/nsswitch.conf etc/nsswitch.conf -echo root:x:0:0:root:/:/bin/sh > etc/passwd -echo root:x:0: > etc/group -ln -s lib lib64 -ln -s bin sbin -cp $BUSYBOX bin -for X in $(busybox --list) -do - ln -s busybox bin/$X -done -rm bin/init -ln bin/busybox bin/init -cp /lib/x86_64-linux-gnu/lib{pthread,c,dl,nsl,nss_*}.so.* lib -cp /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 lib -for X in console null ptmx random stdin stdout stderr tty urandom zero -do - cp -a /dev/$X dev -done - -tar --numeric-owner -cf- . | docker import - busybox -docker run -i -u root busybox /bin/echo Success. diff --git a/vendor/github.com/docker/docker/contrib/mkimage-crux.sh b/vendor/github.com/docker/docker/contrib/mkimage-crux.sh deleted file mode 100755 index 3f0bdca..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage-crux.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bash -# Generate a minimal filesystem for CRUX/Linux and load it into the local -# docker as "cruxlinux" -# requires root and the crux iso (http://crux.nu) - -set -e - -die () { - echo >&2 "$@" - exit 1 -} - -[ "$#" -eq 1 ] || die "1 argument(s) required, $# provided. Usage: ./mkimage-crux.sh /path/to/iso" - -ISO=${1} - -ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-crux-XXXXXXXXXX) -CRUX=$(mktemp -d ${TMPDIR:-/var/tmp}/crux-XXXXXXXXXX) -TMP=$(mktemp -d ${TMPDIR:-/var/tmp}/XXXXXXXXXX) - -VERSION=$(basename --suffix=.iso $ISO | sed 's/[^0-9.]*\([0-9.]*\).*/\1/') - -# Mount the ISO -mount -o ro,loop $ISO $CRUX - -# Extract pkgutils -tar -C $TMP -xf $CRUX/tools/pkgutils#*.pkg.tar.gz - -# Put pkgadd in the $PATH -export PATH="$TMP/usr/bin:$PATH" - -# Install core packages -mkdir -p $ROOTFS/var/lib/pkg -touch $ROOTFS/var/lib/pkg/db -for pkg in $CRUX/crux/core/*; do - pkgadd -r $ROOTFS $pkg -done - -# Remove agetty and inittab config -if (grep agetty ${ROOTFS}/etc/inittab 2>&1 > /dev/null); then - echo "Removing agetty from /etc/inittab ..." - chroot ${ROOTFS} sed -i -e "/agetty/d" /etc/inittab - chroot ${ROOTFS} sed -i -e "/shutdown/d" /etc/inittab - chroot ${ROOTFS} sed -i -e "/^$/N;/^\n$/d" /etc/inittab -fi - -# Remove kernel source -rm -rf $ROOTFS/usr/src/* - -# udev doesn't work in containers, rebuild /dev -DEV=$ROOTFS/dev -rm -rf $DEV -mkdir -p $DEV -mknod -m 666 $DEV/null c 1 3 -mknod -m 666 $DEV/zero c 1 5 -mknod -m 666 $DEV/random c 1 8 -mknod -m 666 $DEV/urandom c 1 9 -mkdir -m 755 $DEV/pts -mkdir -m 1777 $DEV/shm -mknod -m 666 $DEV/tty c 5 0 -mknod -m 600 $DEV/console c 5 1 -mknod -m 666 $DEV/tty0 c 4 0 -mknod -m 666 $DEV/full c 1 7 -mknod -m 600 $DEV/initctl p -mknod -m 666 $DEV/ptmx c 5 2 - -IMAGE_ID=$(tar --numeric-owner -C $ROOTFS -c . | docker import - crux:$VERSION) -docker tag $IMAGE_ID crux:latest -docker run -i -t crux echo Success. - -# Cleanup -umount $CRUX -rm -rf $ROOTFS -rm -rf $CRUX -rm -rf $TMP diff --git a/vendor/github.com/docker/docker/contrib/mkimage-debootstrap.sh b/vendor/github.com/docker/docker/contrib/mkimage-debootstrap.sh deleted file mode 100755 index 412a5ce..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage-debootstrap.sh +++ /dev/null @@ -1,297 +0,0 @@ -#!/usr/bin/env bash -set -e - -echo >&2 -echo >&2 'warning: this script is deprecated - see mkimage.sh and mkimage/debootstrap' -echo >&2 - -variant='minbase' -include='iproute,iputils-ping' -arch='amd64' # intentionally undocumented for now -skipDetection= -strictDebootstrap= -justTar= - -usage() { - echo >&2 - - echo >&2 "usage: $0 [options] repo suite [mirror]" - - echo >&2 - echo >&2 'options: (not recommended)' - echo >&2 " -p set an http_proxy for debootstrap" - echo >&2 " -v $variant # change default debootstrap variant" - echo >&2 " -i $include # change default package includes" - echo >&2 " -d # strict debootstrap (do not apply any docker-specific tweaks)" - echo >&2 " -s # skip version detection and tagging (ie, precise also tagged as 12.04)" - echo >&2 " # note that this will also skip adding universe and/or security/updates to sources.list" - echo >&2 " -t # just create a tarball, especially for dockerbrew (uses repo as tarball name)" - - echo >&2 - echo >&2 " ie: $0 username/debian squeeze" - echo >&2 " $0 username/debian squeeze http://ftp.uk.debian.org/debian/" - - echo >&2 - echo >&2 " ie: $0 username/ubuntu precise" - echo >&2 " $0 username/ubuntu precise http://mirrors.melbourne.co.uk/ubuntu/" - - echo >&2 - echo >&2 " ie: $0 -t precise.tar.bz2 precise" - echo >&2 " $0 -t wheezy.tgz wheezy" - echo >&2 " $0 -t wheezy-uk.tar.xz wheezy http://ftp.uk.debian.org/debian/" - - echo >&2 -} - -# these should match the names found at http://www.debian.org/releases/ -debianStable=wheezy -debianUnstable=sid -# this should match the name found at http://releases.ubuntu.com/ -ubuntuLatestLTS=trusty -# this should match the name found at http://releases.tanglu.org/ -tangluLatest=aequorea - -while getopts v:i:a:p:dst name; do - case "$name" in - p) - http_proxy="$OPTARG" - ;; - v) - variant="$OPTARG" - ;; - i) - include="$OPTARG" - ;; - a) - arch="$OPTARG" - ;; - d) - strictDebootstrap=1 - ;; - s) - skipDetection=1 - ;; - t) - justTar=1 - ;; - ?) - usage - exit 0 - ;; - esac -done -shift $(($OPTIND - 1)) - -repo="$1" -suite="$2" -mirror="${3:-}" # stick to the default debootstrap mirror if one is not provided - -if [ ! "$repo" ] || [ ! "$suite" ]; then - usage - exit 1 -fi - -# some rudimentary detection for whether we need to "sudo" our docker calls -docker='' -if docker version > /dev/null 2>&1; then - docker='docker' -elif sudo docker version > /dev/null 2>&1; then - docker='sudo docker' -elif command -v docker > /dev/null 2>&1; then - docker='docker' -else - echo >&2 "warning: either docker isn't installed, or your current user cannot run it;" - echo >&2 " this script is not likely to work as expected" - sleep 3 - docker='docker' # give us a command-not-found later -fi - -# make sure we have an absolute path to our final tarball so we can still reference it properly after we change directory -if [ "$justTar" ]; then - if [ ! -d "$(dirname "$repo")" ]; then - echo >&2 "error: $(dirname "$repo") does not exist" - exit 1 - fi - repo="$(cd "$(dirname "$repo")" && pwd -P)/$(basename "$repo")" -fi - -# will be filled in later, if [ -z "$skipDetection" ] -lsbDist='' - -target="${TMPDIR:-/var/tmp}/docker-rootfs-debootstrap-$suite-$$-$RANDOM" - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" -returnTo="$(pwd -P)" - -if [ "$suite" = 'lucid' ]; then - # lucid fails and doesn't include gpgv in minbase; "apt-get update" fails - include+=',gpgv' -fi - -set -x - -# bootstrap -mkdir -p "$target" -sudo http_proxy=$http_proxy debootstrap --verbose --variant="$variant" --include="$include" --arch="$arch" "$suite" "$target" "$mirror" - -cd "$target" - -if [ -z "$strictDebootstrap" ]; then - # prevent init scripts from running during install/update - # policy-rc.d (for most scripts) - echo $'#!/bin/sh\nexit 101' | sudo tee usr/sbin/policy-rc.d > /dev/null - sudo chmod +x usr/sbin/policy-rc.d - # initctl (for some pesky upstart scripts) - sudo chroot . dpkg-divert --local --rename --add /sbin/initctl - sudo ln -sf /bin/true sbin/initctl - # see https://github.com/docker/docker/issues/446#issuecomment-16953173 - - # shrink the image, since apt makes us fat (wheezy: ~157.5MB vs ~120MB) - sudo chroot . apt-get clean - - if strings usr/bin/dpkg | grep -q unsafe-io; then - # while we're at it, apt is unnecessarily slow inside containers - # this forces dpkg not to call sync() after package extraction and speeds up install - # the benefit is huge on spinning disks, and the penalty is nonexistent on SSD or decent server virtualization - echo 'force-unsafe-io' | sudo tee etc/dpkg/dpkg.cfg.d/02apt-speedup > /dev/null - # we have this wrapped up in an "if" because the "force-unsafe-io" - # option was added in dpkg 1.15.8.6 - # (see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=584254#82), - # and ubuntu lucid/10.04 only has 1.15.5.6 - fi - - # we want to effectively run "apt-get clean" after every install to keep images small (see output of "apt-get clean -s" for context) - { - aptGetClean='"rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true";' - echo "DPkg::Post-Invoke { ${aptGetClean} };" - echo "APT::Update::Post-Invoke { ${aptGetClean} };" - echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' - } | sudo tee etc/apt/apt.conf.d/no-cache > /dev/null - - # and remove the translations, too - echo 'Acquire::Languages "none";' | sudo tee etc/apt/apt.conf.d/no-languages > /dev/null - - # helpful undo lines for each the above tweaks (for lack of a better home to keep track of them): - # rm /usr/sbin/policy-rc.d - # rm /sbin/initctl; dpkg-divert --rename --remove /sbin/initctl - # rm /etc/dpkg/dpkg.cfg.d/02apt-speedup - # rm /etc/apt/apt.conf.d/no-cache - # rm /etc/apt/apt.conf.d/no-languages - - if [ -z "$skipDetection" ]; then - # see also rudimentary platform detection in hack/install.sh - lsbDist='' - if [ -r etc/lsb-release ]; then - lsbDist="$(. etc/lsb-release && echo "$DISTRIB_ID")" - fi - if [ -z "$lsbDist" ] && [ -r etc/debian_version ]; then - lsbDist='Debian' - fi - - case "$lsbDist" in - Debian) - # add the updates and security repositories - if [ "$suite" != "$debianUnstable" -a "$suite" != 'unstable' ]; then - # ${suite}-updates only applies to non-unstable - sudo sed -i "p; s/ $suite main$/ ${suite}-updates main/" etc/apt/sources.list - - # same for security updates - echo "deb http://security.debian.org/ $suite/updates main" | sudo tee -a etc/apt/sources.list > /dev/null - fi - ;; - Ubuntu) - # add the universe, updates, and security repositories - sudo sed -i " - s/ $suite main$/ $suite main universe/; p; - s/ $suite main/ ${suite}-updates main/; p; - s/ $suite-updates main/ ${suite}-security main/ - " etc/apt/sources.list - ;; - Tanglu) - # add the updates repository - if [ "$suite" = "$tangluLatest" ]; then - # ${suite}-updates only applies to stable Tanglu versions - sudo sed -i "p; s/ $suite main$/ ${suite}-updates main/" etc/apt/sources.list - fi - ;; - SteamOS) - # add contrib and non-free - sudo sed -i "s/ $suite main$/ $suite main contrib non-free/" etc/apt/sources.list - ;; - esac - fi - - # make sure our packages lists are as up to date as we can get them - sudo chroot . apt-get update - sudo chroot . apt-get dist-upgrade -y -fi - -if [ "$justTar" ]; then - # create the tarball file so it has the right permissions (ie, not root) - touch "$repo" - - # fill the tarball - sudo tar --numeric-owner -caf "$repo" . -else - # create the image (and tag $repo:$suite) - sudo tar --numeric-owner -c . | $docker import - $repo:$suite - - # test the image - $docker run -i -t $repo:$suite echo success - - if [ -z "$skipDetection" ]; then - case "$lsbDist" in - Debian) - if [ "$suite" = "$debianStable" -o "$suite" = 'stable' ] && [ -r etc/debian_version ]; then - # tag latest - $docker tag $repo:$suite $repo:latest - - if [ -r etc/debian_version ]; then - # tag the specific debian release version (which is only reasonable to tag on debian stable) - ver=$(cat etc/debian_version) - $docker tag $repo:$suite $repo:$ver - fi - fi - ;; - Ubuntu) - if [ "$suite" = "$ubuntuLatestLTS" ]; then - # tag latest - $docker tag $repo:$suite $repo:latest - fi - if [ -r etc/lsb-release ]; then - lsbRelease="$(. etc/lsb-release && echo "$DISTRIB_RELEASE")" - if [ "$lsbRelease" ]; then - # tag specific Ubuntu version number, if available (12.04, etc.) - $docker tag $repo:$suite $repo:$lsbRelease - fi - fi - ;; - Tanglu) - if [ "$suite" = "$tangluLatest" ]; then - # tag latest - $docker tag $repo:$suite $repo:latest - fi - if [ -r etc/lsb-release ]; then - lsbRelease="$(. etc/lsb-release && echo "$DISTRIB_RELEASE")" - if [ "$lsbRelease" ]; then - # tag specific Tanglu version number, if available (1.0, 2.0, etc.) - $docker tag $repo:$suite $repo:$lsbRelease - fi - fi - ;; - SteamOS) - if [ -r etc/lsb-release ]; then - lsbRelease="$(. etc/lsb-release && echo "$DISTRIB_RELEASE")" - if [ "$lsbRelease" ]; then - # tag specific SteamOS version number, if available (1.0, 2.0, etc.) - $docker tag $repo:$suite $repo:$lsbRelease - fi - fi - ;; - esac - fi -fi - -# cleanup -cd "$returnTo" -sudo rm -rf "$target" diff --git a/vendor/github.com/docker/docker/contrib/mkimage-pld.sh b/vendor/github.com/docker/docker/contrib/mkimage-pld.sh deleted file mode 100755 index 615c203..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage-pld.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh -# -# Generate a minimal filesystem for PLD Linux and load it into the local docker as "pld". -# https://www.pld-linux.org/packages/docker -# -set -e - -if [ "$(id -u)" != "0" ]; then - echo >&2 "$0: requires root" - exit 1 -fi - -image_name=pld - -tmpdir=$(mktemp -d ${TMPDIR:-/var/tmp}/pld-docker-XXXXXX) -root=$tmpdir/rootfs -install -d -m 755 $root - -# to clean up: -docker rmi $image_name || : - -# build -rpm -r $root --initdb - -set +e -install -d $root/dev/pts -mknod $root/dev/random c 1 8 -m 644 -mknod $root/dev/urandom c 1 9 -m 644 -mknod $root/dev/full c 1 7 -m 666 -mknod $root/dev/null c 1 3 -m 666 -mknod $root/dev/zero c 1 5 -m 666 -mknod $root/dev/console c 5 1 -m 660 -set -e - -poldek -r $root --up --noask -u \ - --noignore \ - -O 'rpmdef=_install_langs C' \ - -O 'rpmdef=_excludedocs 1' \ - vserver-packages \ - bash iproute2 coreutils grep poldek - -# fix netsharedpath, so containers would be able to install when some paths are mounted -sed -i -e 's;^#%_netsharedpath.*;%_netsharedpath /dev/shm:/sys:/proc:/dev:/etc/hostname;' $root/etc/rpm/macros - -# no need for alternatives -poldek-config -c $root/etc/poldek/poldek.conf ignore systemd-init - -# this makes initscripts to believe network is up -touch $root/var/lock/subsys/network - -# cleanup large optional packages -remove_packages="ca-certificates" -for pkg in $remove_packages; do - rpm -r $root -q $pkg && rpm -r $root -e $pkg --nodeps -done - -# cleanup more -rm -v $root/etc/ld.so.cache -rm -rfv $root/var/cache/hrmib/* -rm -rfv $root/usr/share/man/man?/* -rm -rfv $root/usr/share/locale/*/ -rm -rfv $root/usr/share/help/*/ -rm -rfv $root/usr/share/doc/* -rm -rfv $root/usr/src/examples/* -rm -rfv $root/usr/share/pixmaps/* - -# and import -tar --numeric-owner --xattrs --acls -C $root -c . | docker import - $image_name - -# and test -docker run -i -u root $image_name /bin/echo Success. - -rm -r $tmpdir diff --git a/vendor/github.com/docker/docker/contrib/mkimage-rinse.sh b/vendor/github.com/docker/docker/contrib/mkimage-rinse.sh deleted file mode 100755 index 7e09350..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage-rinse.sh +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env bash -# -# Create a base CentOS Docker image. - -# This script is useful on systems with rinse available (e.g., -# building a CentOS image on Debian). See contrib/mkimage-yum.sh for -# a way to build CentOS images on systems with yum installed. - -set -e - -echo >&2 -echo >&2 'warning: this script is deprecated - see mkimage.sh and mkimage/rinse' -echo >&2 - -repo="$1" -distro="$2" -mirror="$3" - -if [ ! "$repo" ] || [ ! "$distro" ]; then - self="$(basename $0)" - echo >&2 "usage: $self repo distro [mirror]" - echo >&2 - echo >&2 " ie: $self username/centos centos-5" - echo >&2 " $self username/centos centos-6" - echo >&2 - echo >&2 " ie: $self username/slc slc-5" - echo >&2 " $self username/slc slc-6" - echo >&2 - echo >&2 " ie: $self username/centos centos-5 http://vault.centos.org/5.8/os/x86_64/CentOS/" - echo >&2 " $self username/centos centos-6 http://vault.centos.org/6.3/os/x86_64/Packages/" - echo >&2 - echo >&2 'See /etc/rinse for supported values of "distro" and for examples of' - echo >&2 ' expected values of "mirror".' - echo >&2 - echo >&2 'This script is tested to work with the original upstream version of rinse,' - echo >&2 ' found at http://www.steve.org.uk/Software/rinse/ and also in Debian at' - echo >&2 ' http://packages.debian.org/wheezy/rinse -- as always, YMMV.' - echo >&2 - exit 1 -fi - -target="${TMPDIR:-/var/tmp}/docker-rootfs-rinse-$distro-$$-$RANDOM" - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" -returnTo="$(pwd -P)" - -rinseArgs=( --arch amd64 --distribution "$distro" --directory "$target" ) -if [ "$mirror" ]; then - rinseArgs+=( --mirror "$mirror" ) -fi - -set -x - -mkdir -p "$target" - -sudo rinse "${rinseArgs[@]}" - -cd "$target" - -# rinse fails a little at setting up /dev, so we'll just wipe it out and create our own -sudo rm -rf dev -sudo mkdir -m 755 dev -( - cd dev - sudo ln -sf /proc/self/fd ./ - sudo mkdir -m 755 pts - sudo mkdir -m 1777 shm - sudo mknod -m 600 console c 5 1 - sudo mknod -m 600 initctl p - sudo mknod -m 666 full c 1 7 - sudo mknod -m 666 null c 1 3 - sudo mknod -m 666 ptmx c 5 2 - sudo mknod -m 666 random c 1 8 - sudo mknod -m 666 tty c 5 0 - sudo mknod -m 666 tty0 c 4 0 - sudo mknod -m 666 urandom c 1 9 - sudo mknod -m 666 zero c 1 5 -) - -# effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb --keep-services "$target" -# locales -sudo rm -rf usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive} -# docs and man pages -sudo rm -rf usr/share/{man,doc,info,gnome/help} -# cracklib -sudo rm -rf usr/share/cracklib -# i18n -sudo rm -rf usr/share/i18n -# yum cache -sudo rm -rf var/cache/yum -sudo mkdir -p --mode=0755 var/cache/yum -# sln -sudo rm -rf sbin/sln -# ldconfig -#sudo rm -rf sbin/ldconfig -sudo rm -rf etc/ld.so.cache var/cache/ldconfig -sudo mkdir -p --mode=0755 var/cache/ldconfig - -# allow networking init scripts inside the container to work without extra steps -echo 'NETWORKING=yes' | sudo tee etc/sysconfig/network > /dev/null - -# to restore locales later: -# yum reinstall glibc-common - -version= -if [ -r etc/redhat-release ]; then - version="$(sed -E 's/^[^0-9.]*([0-9.]+).*$/\1/' etc/redhat-release)" -elif [ -r etc/SuSE-release ]; then - version="$(awk '/^VERSION/ { print $3 }' etc/SuSE-release)" -fi - -if [ -z "$version" ]; then - echo >&2 "warning: cannot autodetect OS version, using $distro as tag" - sleep 20 - version="$distro" -fi - -sudo tar --numeric-owner -c . | docker import - $repo:$version - -docker run -i -t $repo:$version echo success - -cd "$returnTo" -sudo rm -rf "$target" diff --git a/vendor/github.com/docker/docker/contrib/mkimage-yum.sh b/vendor/github.com/docker/docker/contrib/mkimage-yum.sh deleted file mode 100755 index 29da170..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage-yum.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env bash -# -# Create a base CentOS Docker image. -# -# This script is useful on systems with yum installed (e.g., building -# a CentOS image on CentOS). See contrib/mkimage-rinse.sh for a way -# to build CentOS images on other systems. - -set -e - -usage() { - cat < -OPTIONS: - -p "" The list of packages to install in the container. - The default is blank. - -g "" The groups of packages to install in the container. - The default is "Core". - -y The path to the yum config to install packages from. The - default is /etc/yum.conf for Centos/RHEL and /etc/dnf/dnf.conf for Fedora -EOOPTS - exit 1 -} - -# option defaults -yum_config=/etc/yum.conf -if [ -f /etc/dnf/dnf.conf ] && command -v dnf &> /dev/null; then - yum_config=/etc/dnf/dnf.conf - alias yum=dnf -fi -install_groups="Core" -while getopts ":y:p:g:h" opt; do - case $opt in - y) - yum_config=$OPTARG - ;; - h) - usage - ;; - p) - install_packages="$OPTARG" - ;; - g) - install_groups="$OPTARG" - ;; - \?) - echo "Invalid option: -$OPTARG" - usage - ;; - esac -done -shift $((OPTIND - 1)) -name=$1 - -if [[ -z $name ]]; then - usage -fi - -target=$(mktemp -d --tmpdir $(basename $0).XXXXXX) - -set -x - -mkdir -m 755 "$target"/dev -mknod -m 600 "$target"/dev/console c 5 1 -mknod -m 600 "$target"/dev/initctl p -mknod -m 666 "$target"/dev/full c 1 7 -mknod -m 666 "$target"/dev/null c 1 3 -mknod -m 666 "$target"/dev/ptmx c 5 2 -mknod -m 666 "$target"/dev/random c 1 8 -mknod -m 666 "$target"/dev/tty c 5 0 -mknod -m 666 "$target"/dev/tty0 c 4 0 -mknod -m 666 "$target"/dev/urandom c 1 9 -mknod -m 666 "$target"/dev/zero c 1 5 - -# amazon linux yum will fail without vars set -if [ -d /etc/yum/vars ]; then - mkdir -p -m 755 "$target"/etc/yum - cp -a /etc/yum/vars "$target"/etc/yum/ -fi - -if [[ -n "$install_groups" ]]; -then - yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \ - --setopt=group_package_types=mandatory -y groupinstall $install_groups -fi - -if [[ -n "$install_packages" ]]; -then - yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \ - --setopt=group_package_types=mandatory -y install $install_packages -fi - -yum -c "$yum_config" --installroot="$target" -y clean all - -cat > "$target"/etc/sysconfig/network <&2 "warning: cannot autodetect OS version, using '$name' as tag" - version=$name -fi - -tar --numeric-owner -c -C "$target" . | docker import - $name:$version - -docker run -i -t --rm $name:$version /bin/bash -c 'echo success' - -rm -rf "$target" diff --git a/vendor/github.com/docker/docker/contrib/mkimage.sh b/vendor/github.com/docker/docker/contrib/mkimage.sh deleted file mode 100755 index 13298c8..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/env bash -set -e - -mkimg="$(basename "$0")" - -usage() { - echo >&2 "usage: $mkimg [-d dir] [-t tag] [--compression algo| --no-compression] script [script-args]" - echo >&2 " ie: $mkimg -t someuser/debian debootstrap --variant=minbase jessie" - echo >&2 " $mkimg -t someuser/ubuntu debootstrap --include=ubuntu-minimal --components=main,universe trusty" - echo >&2 " $mkimg -t someuser/busybox busybox-static" - echo >&2 " $mkimg -t someuser/centos:5 rinse --distribution centos-5" - echo >&2 " $mkimg -t someuser/mageia:4 mageia-urpmi --version=4" - echo >&2 " $mkimg -t someuser/mageia:4 mageia-urpmi --version=4 --mirror=http://somemirror/" - echo >&2 " $mkimg -t someuser/solaris solaris" - exit 1 -} - -scriptDir="$(dirname "$(readlink -f "$BASH_SOURCE")")/mkimage" - -os= -os=$(uname -o) - -# set up path to gnu tools if solaris -[[ $os == "Solaris" ]] && export PATH=/usr/gnu/bin:$PATH -# TODO check for gnu-tar, gnu-getopt - -# TODO requires root/sudo due to some pkg operations. sigh. -[[ $os == "Solaris" && $EUID != "0" ]] && echo >&2 "image create on Solaris requires superuser privilege" - -optTemp=$(getopt --options '+d:t:c:hC' --longoptions 'dir:,tag:,compression:,no-compression,help' --name "$mkimg" -- "$@") -eval set -- "$optTemp" -unset optTemp - -dir= -tag= -compression="auto" -while true; do - case "$1" in - -d|--dir) dir="$2" ; shift 2 ;; - -t|--tag) tag="$2" ; shift 2 ;; - --compression) compression="$2" ; shift 2 ;; - --no-compression) compression="none" ; shift 1 ;; - -h|--help) usage ;; - --) shift ; break ;; - esac -done - -script="$1" -[ "$script" ] || usage -shift - -if [ "$compression" == 'auto' ] || [ -z "$compression" ] -then - compression='xz' -fi - -[ "$compression" == 'none' ] && compression='' - -if [ ! -x "$scriptDir/$script" ]; then - echo >&2 "error: $script does not exist or is not executable" - echo >&2 " see $scriptDir for possible scripts" - exit 1 -fi - -# don't mistake common scripts like .febootstrap-minimize as image-creators -if [[ "$script" == .* ]]; then - echo >&2 "error: $script is a script helper, not a script" - echo >&2 " see $scriptDir for possible scripts" - exit 1 -fi - -delDir= -if [ -z "$dir" ]; then - dir="$(mktemp -d ${TMPDIR:-/var/tmp}/docker-mkimage.XXXXXXXXXX)" - delDir=1 -fi - -rootfsDir="$dir/rootfs" -( set -x; mkdir -p "$rootfsDir" ) - -# pass all remaining arguments to $script -"$scriptDir/$script" "$rootfsDir" "$@" - -# Docker mounts tmpfs at /dev and procfs at /proc so we can remove them -rm -rf "$rootfsDir/dev" "$rootfsDir/proc" -mkdir -p "$rootfsDir/dev" "$rootfsDir/proc" - -# make sure /etc/resolv.conf has something useful in it -mkdir -p "$rootfsDir/etc" -cat > "$rootfsDir/etc/resolv.conf" <<'EOF' -nameserver 8.8.8.8 -nameserver 8.8.4.4 -EOF - -tarFile="$dir/rootfs.tar${compression:+.$compression}" -touch "$tarFile" - -( - set -x - tar --numeric-owner --create --auto-compress --file "$tarFile" --directory "$rootfsDir" --transform='s,^./,,' . -) - -echo >&2 "+ cat > '$dir/Dockerfile'" -cat > "$dir/Dockerfile" <> "$dir/Dockerfile" ) - break - fi -done - -( set -x; rm -rf "$rootfsDir" ) - -if [ "$tag" ]; then - ( set -x; docker build -t "$tag" "$dir" ) -elif [ "$delDir" ]; then - # if we didn't specify a tag and we're going to delete our dir, let's just build an untagged image so that we did _something_ - ( set -x; docker build "$dir" ) -fi - -if [ "$delDir" ]; then - ( set -x; rm -rf "$dir" ) -fi diff --git a/vendor/github.com/docker/docker/contrib/mkimage/.febootstrap-minimize b/vendor/github.com/docker/docker/contrib/mkimage/.febootstrap-minimize deleted file mode 100755 index 7749e63..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage/.febootstrap-minimize +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -set -e - -rootfsDir="$1" -shift - -( - cd "$rootfsDir" - - # effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb --keep-services "$target" - # locales - rm -rf usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive} - # docs and man pages - rm -rf usr/share/{man,doc,info,gnome/help} - # cracklib - rm -rf usr/share/cracklib - # i18n - rm -rf usr/share/i18n - # yum cache - rm -rf var/cache/yum - mkdir -p --mode=0755 var/cache/yum - # sln - rm -rf sbin/sln - # ldconfig - #rm -rf sbin/ldconfig - rm -rf etc/ld.so.cache var/cache/ldconfig - mkdir -p --mode=0755 var/cache/ldconfig -) diff --git a/vendor/github.com/docker/docker/contrib/mkimage/busybox-static b/vendor/github.com/docker/docker/contrib/mkimage/busybox-static deleted file mode 100755 index e15322b..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage/busybox-static +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -set -e - -rootfsDir="$1" -shift - -busybox="$(which busybox 2>/dev/null || true)" -if [ -z "$busybox" ]; then - echo >&2 'error: busybox: not found' - echo >&2 ' install it with your distribution "busybox-static" package' - exit 1 -fi -if ! ldd "$busybox" 2>&1 | grep -q 'not a dynamic executable'; then - echo >&2 "error: '$busybox' appears to be a dynamic executable" - echo >&2 ' you should install your distribution "busybox-static" package instead' - exit 1 -fi - -mkdir -p "$rootfsDir/bin" -rm -f "$rootfsDir/bin/busybox" # just in case -cp "$busybox" "$rootfsDir/bin/busybox" - -( - cd "$rootfsDir" - - IFS=$'\n' - modules=( $(bin/busybox --list-modules) ) - unset IFS - - for module in "${modules[@]}"; do - mkdir -p "$(dirname "$module")" - ln -sf /bin/busybox "$module" - done -) diff --git a/vendor/github.com/docker/docker/contrib/mkimage/debootstrap b/vendor/github.com/docker/docker/contrib/mkimage/debootstrap deleted file mode 100755 index 7d56d8e..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage/debootstrap +++ /dev/null @@ -1,226 +0,0 @@ -#!/usr/bin/env bash -set -e - -rootfsDir="$1" -shift - -# we have to do a little fancy footwork to make sure "rootfsDir" becomes the second non-option argument to debootstrap - -before=() -while [ $# -gt 0 ] && [[ "$1" == -* ]]; do - before+=( "$1" ) - shift -done - -suite="$1" -shift - -# get path to "chroot" in our current PATH -chrootPath="$(type -P chroot)" -rootfs_chroot() { - # "chroot" doesn't set PATH, so we need to set it explicitly to something our new debootstrap chroot can use appropriately! - - # set PATH and chroot away! - PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' \ - "$chrootPath" "$rootfsDir" "$@" -} - -# allow for DEBOOTSTRAP=qemu-debootstrap ./mkimage.sh ... -: ${DEBOOTSTRAP:=debootstrap} - -( - set -x - $DEBOOTSTRAP "${before[@]}" "$suite" "$rootfsDir" "$@" -) - -# now for some Docker-specific tweaks - -# prevent init scripts from running during install/update -echo >&2 "+ echo exit 101 > '$rootfsDir/usr/sbin/policy-rc.d'" -cat > "$rootfsDir/usr/sbin/policy-rc.d" <<-'EOF' - #!/bin/sh - - # For most Docker users, "apt-get install" only happens during "docker build", - # where starting services doesn't work and often fails in humorous ways. This - # prevents those failures by stopping the services from attempting to start. - - exit 101 -EOF -chmod +x "$rootfsDir/usr/sbin/policy-rc.d" - -# prevent upstart scripts from running during install/update -( - set -x - rootfs_chroot dpkg-divert --local --rename --add /sbin/initctl - cp -a "$rootfsDir/usr/sbin/policy-rc.d" "$rootfsDir/sbin/initctl" - sed -i 's/^exit.*/exit 0/' "$rootfsDir/sbin/initctl" -) - -# shrink a little, since apt makes us cache-fat (wheezy: ~157.5MB vs ~120MB) -( set -x; rootfs_chroot apt-get clean ) - -# this file is one APT creates to make sure we don't "autoremove" our currently -# in-use kernel, which doesn't really apply to debootstraps/Docker images that -# don't even have kernels installed -rm -f "$rootfsDir/etc/apt/apt.conf.d/01autoremove-kernels" - -# Ubuntu 10.04 sucks... :) -if strings "$rootfsDir/usr/bin/dpkg" | grep -q unsafe-io; then - # force dpkg not to call sync() after package extraction (speeding up installs) - echo >&2 "+ echo force-unsafe-io > '$rootfsDir/etc/dpkg/dpkg.cfg.d/docker-apt-speedup'" - cat > "$rootfsDir/etc/dpkg/dpkg.cfg.d/docker-apt-speedup" <<-'EOF' - # For most Docker users, package installs happen during "docker build", which - # doesn't survive power loss and gets restarted clean afterwards anyhow, so - # this minor tweak gives us a nice speedup (much nicer on spinning disks, - # obviously). - - force-unsafe-io - EOF -fi - -if [ -d "$rootfsDir/etc/apt/apt.conf.d" ]; then - # _keep_ us lean by effectively running "apt-get clean" after every install - aptGetClean='"rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true";' - echo >&2 "+ cat > '$rootfsDir/etc/apt/apt.conf.d/docker-clean'" - cat > "$rootfsDir/etc/apt/apt.conf.d/docker-clean" <<-EOF - # Since for most Docker users, package installs happen in "docker build" steps, - # they essentially become individual layers due to the way Docker handles - # layering, especially using CoW filesystems. What this means for us is that - # the caches that APT keeps end up just wasting space in those layers, making - # our layers unnecessarily large (especially since we'll normally never use - # these caches again and will instead just "docker build" again and make a brand - # new image). - - # Ideally, these would just be invoking "apt-get clean", but in our testing, - # that ended up being cyclic and we got stuck on APT's lock, so we get this fun - # creation that's essentially just "apt-get clean". - DPkg::Post-Invoke { ${aptGetClean} }; - APT::Update::Post-Invoke { ${aptGetClean} }; - - Dir::Cache::pkgcache ""; - Dir::Cache::srcpkgcache ""; - - # Note that we do realize this isn't the ideal way to do this, and are always - # open to better suggestions (https://github.com/docker/docker/issues). - EOF - - # remove apt-cache translations for fast "apt-get update" - echo >&2 "+ echo Acquire::Languages 'none' > '$rootfsDir/etc/apt/apt.conf.d/docker-no-languages'" - cat > "$rootfsDir/etc/apt/apt.conf.d/docker-no-languages" <<-'EOF' - # In Docker, we don't often need the "Translations" files, so we're just wasting - # time and space by downloading them, and this inhibits that. For users that do - # need them, it's a simple matter to delete this file and "apt-get update". :) - - Acquire::Languages "none"; - EOF - - echo >&2 "+ echo Acquire::GzipIndexes 'true' > '$rootfsDir/etc/apt/apt.conf.d/docker-gzip-indexes'" - cat > "$rootfsDir/etc/apt/apt.conf.d/docker-gzip-indexes" <<-'EOF' - # Since Docker users using "RUN apt-get update && apt-get install -y ..." in - # their Dockerfiles don't go delete the lists files afterwards, we want them to - # be as small as possible on-disk, so we explicitly request "gz" versions and - # tell Apt to keep them gzipped on-disk. - - # For comparison, an "apt-get update" layer without this on a pristine - # "debian:wheezy" base image was "29.88 MB", where with this it was only - # "8.273 MB". - - Acquire::GzipIndexes "true"; - Acquire::CompressionTypes::Order:: "gz"; - EOF - - # update "autoremove" configuration to be aggressive about removing suggests deps that weren't manually installed - echo >&2 "+ echo Apt::AutoRemove::SuggestsImportant 'false' > '$rootfsDir/etc/apt/apt.conf.d/docker-autoremove-suggests'" - cat > "$rootfsDir/etc/apt/apt.conf.d/docker-autoremove-suggests" <<-'EOF' - # Since Docker users are looking for the smallest possible final images, the - # following emerges as a very common pattern: - - # RUN apt-get update \ - # && apt-get install -y \ - # && \ - # && apt-get purge -y --auto-remove - - # By default, APT will actually _keep_ packages installed via Recommends or - # Depends if another package Suggests them, even and including if the package - # that originally caused them to be installed is removed. Setting this to - # "false" ensures that APT is appropriately aggressive about removing the - # packages it added. - - # https://aptitude.alioth.debian.org/doc/en/ch02s05s05.html#configApt-AutoRemove-SuggestsImportant - Apt::AutoRemove::SuggestsImportant "false"; - EOF -fi - -if [ -z "$DONT_TOUCH_SOURCES_LIST" ]; then - # tweak sources.list, where appropriate - lsbDist= - if [ -z "$lsbDist" -a -r "$rootfsDir/etc/os-release" ]; then - lsbDist="$(. "$rootfsDir/etc/os-release" && echo "$ID")" - fi - if [ -z "$lsbDist" -a -r "$rootfsDir/etc/lsb-release" ]; then - lsbDist="$(. "$rootfsDir/etc/lsb-release" && echo "$DISTRIB_ID")" - fi - if [ -z "$lsbDist" -a -r "$rootfsDir/etc/debian_version" ]; then - lsbDist='Debian' - fi - # normalize to lowercase for easier matching - lsbDist="$(echo "$lsbDist" | tr '[:upper:]' '[:lower:]')" - case "$lsbDist" in - debian) - # updates and security! - if [ "$suite" != 'sid' -a "$suite" != 'unstable' ]; then - ( - set -x - sed -i " - p; - s/ $suite / ${suite}-updates / - " "$rootfsDir/etc/apt/sources.list" - echo "deb http://security.debian.org $suite/updates main" >> "$rootfsDir/etc/apt/sources.list" - ) - fi - ;; - ubuntu) - # add the updates and security repositories - ( - set -x - sed -i " - p; - s/ $suite / ${suite}-updates /; p; - s/ $suite-updates / ${suite}-security / - " "$rootfsDir/etc/apt/sources.list" - ) - ;; - tanglu) - # add the updates repository - if [ "$suite" != 'devel' ]; then - ( - set -x - sed -i " - p; - s/ $suite / ${suite}-updates / - " "$rootfsDir/etc/apt/sources.list" - ) - fi - ;; - steamos) - # add contrib and non-free if "main" is the only component - ( - set -x - sed -i "s/ $suite main$/ $suite main contrib non-free/" "$rootfsDir/etc/apt/sources.list" - ) - ;; - esac -fi - -( - set -x - - # make sure we're fully up-to-date - rootfs_chroot sh -xc 'apt-get update && apt-get dist-upgrade -y' - - # delete all the apt list files since they're big and get stale quickly - rm -rf "$rootfsDir/var/lib/apt/lists"/* - # this forces "apt-get update" in dependent images, which is also good - - mkdir "$rootfsDir/var/lib/apt/lists/partial" # Lucid... "E: Lists directory /var/lib/apt/lists/partial is missing." -) diff --git a/vendor/github.com/docker/docker/contrib/mkimage/mageia-urpmi b/vendor/github.com/docker/docker/contrib/mkimage/mageia-urpmi deleted file mode 100755 index 93fb289..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage/mageia-urpmi +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash -# -# Needs to be run from Mageia 4 or greater for kernel support for docker. -# -# Mageia 4 does not have docker available in official repos, so please -# install and run the docker binary manually. -# -# Tested working versions are for Mageia 2 onwards (inc. cauldron). -# -set -e - -rootfsDir="$1" -shift - -optTemp=$(getopt --options '+v:,m:' --longoptions 'version:,mirror:' --name mageia-urpmi -- "$@") -eval set -- "$optTemp" -unset optTemp - -installversion= -mirror= -while true; do - case "$1" in - -v|--version) installversion="$2" ; shift 2 ;; - -m|--mirror) mirror="$2" ; shift 2 ;; - --) shift ; break ;; - esac -done - -if [ -z $installversion ]; then - # Attempt to match host version - if [ -r /etc/mageia-release ]; then - installversion="$(sed 's/^[^0-9\]*\([0-9.]\+\).*$/\1/' /etc/mageia-release)" - else - echo "Error: no version supplied and unable to detect host mageia version" - exit 1 - fi -fi - -if [ -z $mirror ]; then - # No mirror provided, default to mirrorlist - mirror="--mirrorlist https://mirrors.mageia.org/api/mageia.$installversion.x86_64.list" -fi - -( - set -x - urpmi.addmedia --distrib \ - $mirror \ - --urpmi-root "$rootfsDir" - urpmi basesystem-minimal urpmi \ - --auto \ - --no-suggests \ - --urpmi-root "$rootfsDir" \ - --root "$rootfsDir" -) - -"$(dirname "$BASH_SOURCE")/.febootstrap-minimize" "$rootfsDir" - -if [ -d "$rootfsDir/etc/sysconfig" ]; then - # allow networking init scripts inside the container to work without extra steps - echo 'NETWORKING=yes' > "$rootfsDir/etc/sysconfig/network" -fi diff --git a/vendor/github.com/docker/docker/contrib/mkimage/rinse b/vendor/github.com/docker/docker/contrib/mkimage/rinse deleted file mode 100755 index 75eb4f0..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage/rinse +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -set -e - -rootfsDir="$1" -shift - -# specifying --arch below is safe because "$@" can override it and the "latest" one wins :) - -( - set -x - rinse --directory "$rootfsDir" --arch amd64 "$@" -) - -"$(dirname "$BASH_SOURCE")/.febootstrap-minimize" "$rootfsDir" - -if [ -d "$rootfsDir/etc/sysconfig" ]; then - # allow networking init scripts inside the container to work without extra steps - echo 'NETWORKING=yes' > "$rootfsDir/etc/sysconfig/network" -fi - -# make sure we're fully up-to-date, too -( - set -x - chroot "$rootfsDir" yum update -y -) diff --git a/vendor/github.com/docker/docker/contrib/mkimage/solaris b/vendor/github.com/docker/docker/contrib/mkimage/solaris deleted file mode 100755 index 158970e..0000000 --- a/vendor/github.com/docker/docker/contrib/mkimage/solaris +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env bash -# -# Solaris 12 base image build script. -# -set -e - -# TODO add optional package publisher origin - -rootfsDir="$1" -shift - -# base install -( - set -x - - pkg image-create --full --zone \ - --facet facet.locale.*=false \ - --facet facet.locale.POSIX=true \ - --facet facet.doc=false \ - --facet facet.doc.*=false \ - "$rootfsDir" - - pkg -R "$rootfsDir" set-property use-system-repo true - - pkg -R "$rootfsDir" set-property flush-content-cache-on-success true - - pkg -R "$rootfsDir" install core-os -) - -# Lay in stock configuration, set up milestone -# XXX This all may become optional in a base image -( - # faster to build repository database on tmpfs - REPO_DB=/system/volatile/repository.$$ - export SVCCFG_REPOSITORY=${REPO_DB} - export SVCCFG_DOOR_PATH=$rootfsDir/system/volatile/tmp_repo_door - - # Import base manifests. NOTE These are a combination of basic requirement - # and gleaned from container milestone manifest. They may change. - for m in $rootfsDir/lib/svc/manifest/system/environment.xml \ - $rootfsDir/lib/svc/manifest/system/svc/global.xml \ - $rootfsDir/lib/svc/manifest/system/svc/restarter.xml \ - $rootfsDir/lib/svc/manifest/network/dns/client.xml \ - $rootfsDir/lib/svc/manifest/system/name-service/switch.xml \ - $rootfsDir/lib/svc/manifest/system/name-service/cache.xml \ - $rootfsDir/lib/svc/manifest/milestone/container.xml ; do - svccfg import $m - done - - # Apply system layer profile, deleting unnecessary dependencies - svccfg apply $rootfsDir/etc/svc/profile/generic_container.xml - - # XXX Even if we keep a repo in the base image, this is definitely optional - svccfg apply $rootfsDir/etc/svc/profile/sysconfig/container_sc.xml - - for s in svc:/system/svc/restarter \ - svc:/system/environment \ - svc:/network/dns/client \ - svc:/system/name-service/switch \ - svc:/system/name-service/cache \ - svc:/system/svc/global \ - svc:/milestone/container ;do - svccfg -s $s refresh - done - - # now copy the built up repository into the base rootfs - mv $REPO_DB $rootfsDir/etc/svc/repository.db -) - -# pkg(1) needs the zoneproxy-client running in the container. -# use a simple wrapper to run it as needed. -# XXX maybe we go back to running this in SMF? -mv "$rootfsDir/usr/bin/pkg" "$rootfsDir/usr/bin/wrapped_pkg" -cat > "$rootfsDir/usr/bin/pkg" <<-'EOF' -#!/bin/sh -# -# THIS FILE CREATED DURING DOCKER BASE IMAGE CREATION -# -# The Solaris base image uses the sysrepo proxy mechanism. The -# IPS client pkg(1) requires the zoneproxy-client to reach the -# remote publisher origins through the host. This wrapper script -# enables and disables the proxy client as needed. This is a -# temporary solution. - -/usr/lib/zones/zoneproxy-client -s localhost:1008 -PKG_SYSREPO_URL=http://localhost:1008 /usr/bin/wrapped_pkg "$@" -pkill -9 zoneproxy-client -EOF -chmod +x "$rootfsDir/usr/bin/pkg" diff --git a/vendor/github.com/docker/docker/contrib/nnp-test/Dockerfile b/vendor/github.com/docker/docker/contrib/nnp-test/Dockerfile deleted file mode 100644 index 026d869..0000000 --- a/vendor/github.com/docker/docker/contrib/nnp-test/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM buildpack-deps:jessie - -COPY . /usr/src/ - -WORKDIR /usr/src/ - -RUN gcc -g -Wall -static nnp-test.c -o /usr/bin/nnp-test - -RUN chmod +s /usr/bin/nnp-test diff --git a/vendor/github.com/docker/docker/contrib/nnp-test/nnp-test.c b/vendor/github.com/docker/docker/contrib/nnp-test/nnp-test.c deleted file mode 100644 index b767da7..0000000 --- a/vendor/github.com/docker/docker/contrib/nnp-test/nnp-test.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include - -int main(int argc, char *argv[]) -{ - printf("EUID=%d\n", geteuid()); - return 0; -} - diff --git a/vendor/github.com/docker/docker/contrib/nuke-graph-directory.sh b/vendor/github.com/docker/docker/contrib/nuke-graph-directory.sh deleted file mode 100755 index 5eeb45c..0000000 --- a/vendor/github.com/docker/docker/contrib/nuke-graph-directory.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/sh -set -e - -dir="$1" - -if [ -z "$dir" ]; then - { - echo 'This script is for destroying old /var/lib/docker directories more safely than' - echo ' "rm -rf", which can cause data loss or other serious issues.' - echo - echo "usage: $0 directory" - echo " ie: $0 /var/lib/docker" - } >&2 - exit 1 -fi - -if [ "$(id -u)" != 0 ]; then - echo >&2 "error: $0 must be run as root" - exit 1 -fi - -if [ ! -d "$dir" ]; then - echo >&2 "error: $dir is not a directory" - exit 1 -fi - -dir="$(readlink -f "$dir")" - -echo -echo "Nuking $dir ..." -echo ' (if this is wrong, press Ctrl+C NOW!)' -echo - -( set -x; sleep 10 ) -echo - -dir_in_dir() { - inner="$1" - outer="$2" - [ "${inner#$outer}" != "$inner" ] -} - -# let's start by unmounting any submounts in $dir -# (like -v /home:... for example - DON'T DELETE MY HOME DIRECTORY BRU!) -for mount in $(awk '{ print $5 }' /proc/self/mountinfo); do - mount="$(readlink -f "$mount" || true)" - if [ "$dir" != "$mount" ] && dir_in_dir "$mount" "$dir"; then - ( set -x; umount -f "$mount" ) - fi -done - -# now, let's go destroy individual btrfs subvolumes, if any exist -if command -v btrfs > /dev/null 2>&1; then - # Find btrfs subvolumes under $dir checking for inode 256 - # Source: http://stackoverflow.com/a/32865333 - for subvol in $(find "$dir" -type d -inum 256 | sort -r); do - if [ "$dir" != "$subvol" ]; then - ( set -x; btrfs subvolume delete "$subvol" ) - fi - done -fi - -# finally, DESTROY ALL THINGS -( shopt -s dotglob; set -x; rm -rf "$dir"/* ) diff --git a/vendor/github.com/docker/docker/contrib/project-stats.sh b/vendor/github.com/docker/docker/contrib/project-stats.sh deleted file mode 100755 index 2691c72..0000000 --- a/vendor/github.com/docker/docker/contrib/project-stats.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -## Run this script from the root of the docker repository -## to query project stats useful to the maintainers. -## You will need to install `pulls` and `issues` from -## https://github.com/crosbymichael/pulls - -set -e - -echo -n "Open pulls: " -PULLS=$(pulls | wc -l); let PULLS=$PULLS-1 -echo $PULLS - -echo -n "Pulls alru: " -pulls alru - -echo -n "Open issues: " -ISSUES=$(issues list | wc -l); let ISSUES=$ISSUES-1 -echo $ISSUES - -echo -n "Issues alru: " -issues alru diff --git a/vendor/github.com/docker/docker/contrib/report-issue.sh b/vendor/github.com/docker/docker/contrib/report-issue.sh deleted file mode 100755 index cb54f1a..0000000 --- a/vendor/github.com/docker/docker/contrib/report-issue.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/sh - -# This is a convenience script for reporting issues that include a base -# template of information. See https://github.com/docker/docker/pull/8845 - -set -e - -DOCKER_ISSUE_URL=${DOCKER_ISSUE_URL:-"https://github.com/docker/docker/issues/new"} -DOCKER_ISSUE_NAME_PREFIX=${DOCKER_ISSUE_NAME_PREFIX:-"Report: "} -DOCKER=${DOCKER:-"docker"} -DOCKER_COMMAND="${DOCKER}" -export DOCKER_COMMAND - -# pulled from https://gist.github.com/cdown/1163649 -function urlencode() { - # urlencode - - local length="${#1}" - for (( i = 0; i < length; i++ )); do - local c="${1:i:1}" - case $c in - [a-zA-Z0-9.~_-]) printf "$c" ;; - *) printf '%%%02X' "'$c" - esac - done -} - -function template() { -# this should always match the template from CONTRIBUTING.md - cat <<- EOM - Description of problem: - - - \`docker version\`: - `${DOCKER_COMMAND} -D version` - - - \`docker info\`: - `${DOCKER_COMMAND} -D info` - - - \`uname -a\`: - `uname -a` - - - Environment details (AWS, VirtualBox, physical, etc.): - - - How reproducible: - - - Steps to Reproduce: - 1. - 2. - 3. - - - Actual Results: - - - Expected Results: - - - Additional info: - - - EOM -} - -function format_issue_url() { - if [ ${#@} -ne 2 ] ; then - return 1 - fi - local issue_name=$(urlencode "${DOCKER_ISSUE_NAME_PREFIX}${1}") - local issue_body=$(urlencode "${2}") - echo "${DOCKER_ISSUE_URL}?title=${issue_name}&body=${issue_body}" -} - - -echo -ne "Do you use \`sudo\` to call docker? [y|N]: " -read -r -n 1 use_sudo -echo "" - -if [ "x${use_sudo}" = "xy" -o "x${use_sudo}" = "xY" ]; then - export DOCKER_COMMAND="sudo ${DOCKER}" -fi - -echo -ne "Title of new issue?: " -read -r issue_title -echo "" - -issue_url=$(format_issue_url "${issue_title}" "$(template)") - -if which xdg-open 2>/dev/null >/dev/null ; then - echo -ne "Would like to launch this report in your browser? [Y|n]: " - read -r -n 1 launch_now - echo "" - - if [ "${launch_now}" != "n" -a "${launch_now}" != "N" ]; then - xdg-open "${issue_url}" - fi -fi - -echo "If you would like to manually open the url, you can open this link if your browser: ${issue_url}" - diff --git a/vendor/github.com/docker/docker/contrib/reprepro/suites.sh b/vendor/github.com/docker/docker/contrib/reprepro/suites.sh deleted file mode 100755 index 9ecf99d..0000000 --- a/vendor/github.com/docker/docker/contrib/reprepro/suites.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -e - -cd "$(dirname "$BASH_SOURCE")/../.." - -targets_from() { - git fetch -q https://github.com/docker/docker.git "$1" - git ls-tree -r --name-only "$(git rev-parse FETCH_HEAD)" contrib/builder/deb/ | grep '/Dockerfile$' | sed -r 's!^contrib/builder/deb/|^contrib/builder/deb/amd64/|-debootstrap|/Dockerfile$!!g' | grep -v / -} - -release_branch=$(git ls-remote --heads https://github.com/docker/docker.git | awk -F 'refs/heads/' '$2 ~ /^release/ { print $2 }' | sort -V | tail -1) -{ targets_from master; targets_from "$release_branch"; } | sort -u diff --git a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/LICENSE b/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/LICENSE deleted file mode 100644 index d511905..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/LICENSE +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/Makefile b/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/Makefile deleted file mode 100644 index 16df33e..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -TARGETS?=docker -MODULES?=${TARGETS:=.pp.bz2} -SHAREDIR?=/usr/share - -all: ${TARGETS:=.pp.bz2} - -%.pp.bz2: %.pp - @echo Compressing $^ -\> $@ - bzip2 -9 $^ - -%.pp: %.te - make -f ${SHAREDIR}/selinux/devel/Makefile $@ - -clean: - rm -f *~ *.tc *.pp *.pp.bz2 - rm -rf tmp *.tar.gz - -man: install - sepolicy manpage --domain ${TARGETS}_t - -install: - semodule -i ${TARGETS} - diff --git a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/README.md b/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/README.md deleted file mode 100644 index 7ea3117..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/README.md +++ /dev/null @@ -1 +0,0 @@ -SELinux policy for docker diff --git a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/docker.fc b/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/docker.fc deleted file mode 100644 index d6cb0e5..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/docker.fc +++ /dev/null @@ -1,29 +0,0 @@ -/root/\.docker gen_context(system_u:object_r:docker_home_t,s0) - -/usr/bin/docker -- gen_context(system_u:object_r:docker_exec_t,s0) -/usr/bin/docker-novolume-plugin -- gen_context(system_u:object_r:docker_auth_exec_t,s0) -/usr/lib/docker/docker-novolume-plugin -- gen_context(system_u:object_r:docker_auth_exec_t,s0) - -/usr/lib/systemd/system/docker.service -- gen_context(system_u:object_r:docker_unit_file_t,s0) -/usr/lib/systemd/system/docker-novolume-plugin.service -- gen_context(system_u:object_r:docker_unit_file_t,s0) - -/etc/docker(/.*)? gen_context(system_u:object_r:docker_config_t,s0) - -/var/lib/docker(/.*)? gen_context(system_u:object_r:docker_var_lib_t,s0) -/var/lib/kublet(/.*)? gen_context(system_u:object_r:docker_var_lib_t,s0) -/var/lib/docker/vfs(/.*)? gen_context(system_u:object_r:svirt_sandbox_file_t,s0) - -/var/run/docker(/.*)? gen_context(system_u:object_r:docker_var_run_t,s0) -/var/run/docker\.pid -- gen_context(system_u:object_r:docker_var_run_t,s0) -/var/run/docker\.sock -s gen_context(system_u:object_r:docker_var_run_t,s0) -/var/run/docker-client(/.*)? gen_context(system_u:object_r:docker_var_run_t,s0) -/var/run/docker/plugins(/.*)? gen_context(system_u:object_r:docker_plugin_var_run_t,s0) - -/var/lock/lxc(/.*)? gen_context(system_u:object_r:docker_lock_t,s0) - -/var/log/lxc(/.*)? gen_context(system_u:object_r:docker_log_t,s0) - -/var/lib/docker/init(/.*)? gen_context(system_u:object_r:docker_share_t,s0) -/var/lib/docker/containers/.*/hosts gen_context(system_u:object_r:docker_share_t,s0) -/var/lib/docker/containers/.*/hostname gen_context(system_u:object_r:docker_share_t,s0) -/var/lib/docker/.*/config\.env gen_context(system_u:object_r:docker_share_t,s0) diff --git a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/docker.if b/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/docker.if deleted file mode 100644 index e087e8b..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/docker.if +++ /dev/null @@ -1,523 +0,0 @@ - -## The open-source application container engine. - -######################################## -## -## Execute docker in the docker domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_domtrans',` - gen_require(` - type docker_t, docker_exec_t; - ') - - corecmd_search_bin($1) - domtrans_pattern($1, docker_exec_t, docker_t) -') - -######################################## -## -## Execute docker in the caller domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_exec',` - gen_require(` - type docker_exec_t; - ') - - corecmd_search_bin($1) - can_exec($1, docker_exec_t) -') - -######################################## -## -## Search docker lib directories. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_search_lib',` - gen_require(` - type docker_var_lib_t; - ') - - allow $1 docker_var_lib_t:dir search_dir_perms; - files_search_var_lib($1) -') - -######################################## -## -## Execute docker lib directories. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_exec_lib',` - gen_require(` - type docker_var_lib_t; - ') - - allow $1 docker_var_lib_t:dir search_dir_perms; - can_exec($1, docker_var_lib_t) -') - -######################################## -## -## Read docker lib files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_read_lib_files',` - gen_require(` - type docker_var_lib_t; - ') - - files_search_var_lib($1) - read_files_pattern($1, docker_var_lib_t, docker_var_lib_t) -') - -######################################## -## -## Read docker share files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_read_share_files',` - gen_require(` - type docker_share_t; - ') - - files_search_var_lib($1) - list_dirs_pattern($1, docker_share_t, docker_share_t) - read_files_pattern($1, docker_share_t, docker_share_t) - read_lnk_files_pattern($1, docker_share_t, docker_share_t) -') - -###################################### -## -## Allow the specified domain to execute apache -## in the caller domain. -## -## -## -## Domain allowed access. -## -## -# -interface(`apache_exec',` - gen_require(` - type httpd_exec_t; - ') - - can_exec($1, httpd_exec_t) -') - -###################################### -## -## Allow the specified domain to execute docker shared files -## in the caller domain. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_exec_share_files',` - gen_require(` - type docker_share_t; - ') - - can_exec($1, docker_share_t) -') - -######################################## -## -## Manage docker lib files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_manage_lib_files',` - gen_require(` - type docker_var_lib_t; - ') - - files_search_var_lib($1) - manage_files_pattern($1, docker_var_lib_t, docker_var_lib_t) - manage_lnk_files_pattern($1, docker_var_lib_t, docker_var_lib_t) -') - -######################################## -## -## Manage docker lib directories. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_manage_lib_dirs',` - gen_require(` - type docker_var_lib_t; - ') - - files_search_var_lib($1) - manage_dirs_pattern($1, docker_var_lib_t, docker_var_lib_t) -') - -######################################## -## -## Create objects in a docker var lib directory -## with an automatic type transition to -## a specified private type. -## -## -## -## Domain allowed access. -## -## -## -## -## The type of the object to create. -## -## -## -## -## The class of the object to be created. -## -## -## -## -## The name of the object being created. -## -## -# -interface(`docker_lib_filetrans',` - gen_require(` - type docker_var_lib_t; - ') - - filetrans_pattern($1, docker_var_lib_t, $2, $3, $4) -') - -######################################## -## -## Read docker PID files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_read_pid_files',` - gen_require(` - type docker_var_run_t; - ') - - files_search_pids($1) - read_files_pattern($1, docker_var_run_t, docker_var_run_t) -') - -######################################## -## -## Execute docker server in the docker domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_systemctl',` - gen_require(` - type docker_t; - type docker_unit_file_t; - ') - - systemd_exec_systemctl($1) - init_reload_services($1) - systemd_read_fifo_file_passwd_run($1) - allow $1 docker_unit_file_t:file read_file_perms; - allow $1 docker_unit_file_t:service manage_service_perms; - - ps_process_pattern($1, docker_t) -') - -######################################## -## -## Read and write docker shared memory. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_rw_sem',` - gen_require(` - type docker_t; - ') - - allow $1 docker_t:sem rw_sem_perms; -') - -####################################### -## -## Read and write the docker pty type. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_use_ptys',` - gen_require(` - type docker_devpts_t; - ') - - allow $1 docker_devpts_t:chr_file rw_term_perms; -') - -####################################### -## -## Allow domain to create docker content -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_filetrans_named_content',` - - gen_require(` - type docker_var_lib_t; - type docker_share_t; - type docker_log_t; - type docker_var_run_t; - type docker_home_t; - ') - - files_pid_filetrans($1, docker_var_run_t, file, "docker.pid") - files_pid_filetrans($1, docker_var_run_t, sock_file, "docker.sock") - files_pid_filetrans($1, docker_var_run_t, dir, "docker-client") - logging_log_filetrans($1, docker_log_t, dir, "lxc") - files_var_lib_filetrans($1, docker_var_lib_t, dir, "docker") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "config.env") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "hosts") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "hostname") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "resolv.conf") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, dir, "init") - userdom_admin_home_dir_filetrans($1, docker_home_t, dir, ".docker") -') - -######################################## -## -## Connect to docker over a unix stream socket. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_stream_connect',` - gen_require(` - type docker_t, docker_var_run_t; - ') - - files_search_pids($1) - stream_connect_pattern($1, docker_var_run_t, docker_var_run_t, docker_t) -') - -######################################## -## -## Connect to SPC containers over a unix stream socket. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_spc_stream_connect',` - gen_require(` - type spc_t, spc_var_run_t; - ') - - files_search_pids($1) - files_write_all_pid_sockets($1) - allow $1 spc_t:unix_stream_socket connectto; -') - -######################################## -## -## All of the rules required to administrate -## an docker environment -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_admin',` - gen_require(` - type docker_t; - type docker_var_lib_t, docker_var_run_t; - type docker_unit_file_t; - type docker_lock_t; - type docker_log_t; - type docker_config_t; - ') - - allow $1 docker_t:process { ptrace signal_perms }; - ps_process_pattern($1, docker_t) - - admin_pattern($1, docker_config_t) - - files_search_var_lib($1) - admin_pattern($1, docker_var_lib_t) - - files_search_pids($1) - admin_pattern($1, docker_var_run_t) - - files_search_locks($1) - admin_pattern($1, docker_lock_t) - - logging_search_logs($1) - admin_pattern($1, docker_log_t) - - docker_systemctl($1) - admin_pattern($1, docker_unit_file_t) - allow $1 docker_unit_file_t:service all_service_perms; - - optional_policy(` - systemd_passwd_agent_exec($1) - systemd_read_fifo_file_passwd_run($1) - ') -') - -######################################## -## -## Execute docker_auth_exec_t in the docker_auth domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_auth_domtrans',` - gen_require(` - type docker_auth_t, docker_auth_exec_t; - ') - - corecmd_search_bin($1) - domtrans_pattern($1, docker_auth_exec_t, docker_auth_t) -') - -###################################### -## -## Execute docker_auth in the caller domain. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_auth_exec',` - gen_require(` - type docker_auth_exec_t; - ') - - corecmd_search_bin($1) - can_exec($1, docker_auth_exec_t) -') - -######################################## -## -## Connect to docker_auth over a unix stream socket. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_auth_stream_connect',` - gen_require(` - type docker_auth_t, docker_plugin_var_run_t; - ') - - files_search_pids($1) - stream_connect_pattern($1, docker_plugin_var_run_t, docker_plugin_var_run_t, docker_auth_t) -') - -######################################## -## -## docker domain typebounds calling domain. -## -## -## -## Domain to be typebound. -## -## -# -interface(`docker_typebounds',` - gen_require(` - type docker_t; - ') - - typebounds docker_t $1; -') - -######################################## -## -## Allow any docker_exec_t to be an entrypoint of this domain -## -## -## -## Domain allowed access. -## -## -## -# -interface(`docker_entrypoint',` - gen_require(` - type docker_exec_t; - ') - allow $1 docker_exec_t:file entrypoint; -') diff --git a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/docker.te b/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/docker.te deleted file mode 100644 index 4231688..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-fedora-24/docker-engine-selinux/docker.te +++ /dev/null @@ -1,399 +0,0 @@ -policy_module(docker, 1.0.0) - -######################################## -# -# Declarations -# - -## -##

-## Determine whether docker can -## connect to all TCP ports. -##

-##
-gen_tunable(docker_connect_any, false) - -type docker_t; -type docker_exec_t; -init_daemon_domain(docker_t, docker_exec_t) -domain_subj_id_change_exemption(docker_t) -domain_role_change_exemption(docker_t) - -type spc_t; -domain_type(spc_t) -role system_r types spc_t; - -type docker_auth_t; -type docker_auth_exec_t; -init_daemon_domain(docker_auth_t, docker_auth_exec_t) - -type spc_var_run_t; -files_pid_file(spc_var_run_t) - -type docker_var_lib_t; -files_type(docker_var_lib_t) - -type docker_home_t; -userdom_user_home_content(docker_home_t) - -type docker_config_t; -files_config_file(docker_config_t) - -type docker_lock_t; -files_lock_file(docker_lock_t) - -type docker_log_t; -logging_log_file(docker_log_t) - -type docker_tmp_t; -files_tmp_file(docker_tmp_t) - -type docker_tmpfs_t; -files_tmpfs_file(docker_tmpfs_t) - -type docker_var_run_t; -files_pid_file(docker_var_run_t) - -type docker_plugin_var_run_t; -files_pid_file(docker_plugin_var_run_t) - -type docker_unit_file_t; -systemd_unit_file(docker_unit_file_t) - -type docker_devpts_t; -term_pty(docker_devpts_t) - -type docker_share_t; -files_type(docker_share_t) - -######################################## -# -# docker local policy -# -allow docker_t self:capability { chown kill fowner fsetid mknod net_admin net_bind_service net_raw setfcap }; -allow docker_t self:tun_socket relabelto; -allow docker_t self:process { getattr signal_perms setrlimit setfscreate }; -allow docker_t self:fifo_file rw_fifo_file_perms; -allow docker_t self:unix_stream_socket create_stream_socket_perms; -allow docker_t self:tcp_socket create_stream_socket_perms; -allow docker_t self:udp_socket create_socket_perms; -allow docker_t self:capability2 block_suspend; - -docker_auth_stream_connect(docker_t) - -manage_files_pattern(docker_t, docker_home_t, docker_home_t) -manage_dirs_pattern(docker_t, docker_home_t, docker_home_t) -manage_lnk_files_pattern(docker_t, docker_home_t, docker_home_t) -userdom_admin_home_dir_filetrans(docker_t, docker_home_t, dir, ".docker") - -manage_dirs_pattern(docker_t, docker_config_t, docker_config_t) -manage_files_pattern(docker_t, docker_config_t, docker_config_t) -files_etc_filetrans(docker_t, docker_config_t, dir, "docker") - -manage_dirs_pattern(docker_t, docker_lock_t, docker_lock_t) -manage_files_pattern(docker_t, docker_lock_t, docker_lock_t) -files_lock_filetrans(docker_t, docker_lock_t, { dir file }, "lxc") - -manage_dirs_pattern(docker_t, docker_log_t, docker_log_t) -manage_files_pattern(docker_t, docker_log_t, docker_log_t) -manage_lnk_files_pattern(docker_t, docker_log_t, docker_log_t) -logging_log_filetrans(docker_t, docker_log_t, { dir file lnk_file }) -allow docker_t docker_log_t:dir_file_class_set { relabelfrom relabelto }; - -manage_dirs_pattern(docker_t, docker_tmp_t, docker_tmp_t) -manage_files_pattern(docker_t, docker_tmp_t, docker_tmp_t) -manage_lnk_files_pattern(docker_t, docker_tmp_t, docker_tmp_t) -files_tmp_filetrans(docker_t, docker_tmp_t, { dir file lnk_file }) - -manage_dirs_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_lnk_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_fifo_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_chr_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_blk_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -allow docker_t docker_tmpfs_t:dir relabelfrom; -can_exec(docker_t, docker_tmpfs_t) -fs_tmpfs_filetrans(docker_t, docker_tmpfs_t, { dir file }) -allow docker_t docker_tmpfs_t:chr_file mounton; - -manage_dirs_pattern(docker_t, docker_share_t, docker_share_t) -manage_files_pattern(docker_t, docker_share_t, docker_share_t) -manage_lnk_files_pattern(docker_t, docker_share_t, docker_share_t) -allow docker_t docker_share_t:dir_file_class_set { relabelfrom relabelto }; - -can_exec(docker_t, docker_share_t) -#docker_filetrans_named_content(docker_t) - -manage_dirs_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_chr_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_blk_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_lnk_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -allow docker_t docker_var_lib_t:dir_file_class_set { relabelfrom relabelto }; -files_var_lib_filetrans(docker_t, docker_var_lib_t, { dir file lnk_file }) - -manage_dirs_pattern(docker_t, docker_var_run_t, docker_var_run_t) -manage_files_pattern(docker_t, docker_var_run_t, docker_var_run_t) -manage_sock_files_pattern(docker_t, docker_var_run_t, docker_var_run_t) -manage_lnk_files_pattern(docker_t, docker_var_run_t, docker_var_run_t) -files_pid_filetrans(docker_t, docker_var_run_t, { dir file lnk_file sock_file }) - -allow docker_t docker_devpts_t:chr_file { relabelfrom rw_chr_file_perms setattr_chr_file_perms }; -term_create_pty(docker_t, docker_devpts_t) - -kernel_read_system_state(docker_t) -kernel_read_network_state(docker_t) -kernel_read_all_sysctls(docker_t) -kernel_rw_net_sysctls(docker_t) -kernel_setsched(docker_t) -kernel_read_all_proc(docker_t) - -domain_use_interactive_fds(docker_t) -domain_dontaudit_read_all_domains_state(docker_t) - -corecmd_exec_bin(docker_t) -corecmd_exec_shell(docker_t) - -corenet_tcp_bind_generic_node(docker_t) -corenet_tcp_sendrecv_generic_if(docker_t) -corenet_tcp_sendrecv_generic_node(docker_t) -corenet_tcp_sendrecv_generic_port(docker_t) -corenet_tcp_bind_all_ports(docker_t) -corenet_tcp_connect_http_port(docker_t) -corenet_tcp_connect_commplex_main_port(docker_t) -corenet_udp_sendrecv_generic_if(docker_t) -corenet_udp_sendrecv_generic_node(docker_t) -corenet_udp_sendrecv_all_ports(docker_t) -corenet_udp_bind_generic_node(docker_t) -corenet_udp_bind_all_ports(docker_t) - -files_read_config_files(docker_t) -files_dontaudit_getattr_all_dirs(docker_t) -files_dontaudit_getattr_all_files(docker_t) - -fs_read_cgroup_files(docker_t) -fs_read_tmpfs_symlinks(docker_t) -fs_search_all(docker_t) -fs_getattr_all_fs(docker_t) - -storage_raw_rw_fixed_disk(docker_t) - -auth_use_nsswitch(docker_t) -auth_dontaudit_getattr_shadow(docker_t) - -init_read_state(docker_t) -init_status(docker_t) - -logging_send_audit_msgs(docker_t) -logging_send_syslog_msg(docker_t) - -miscfiles_read_localization(docker_t) - -mount_domtrans(docker_t) - -seutil_read_default_contexts(docker_t) -seutil_read_config(docker_t) - -sysnet_dns_name_resolve(docker_t) -sysnet_exec_ifconfig(docker_t) - -optional_policy(` - rpm_exec(docker_t) - rpm_read_db(docker_t) - rpm_exec(docker_t) -') - -optional_policy(` - fstools_domtrans(docker_t) -') - -optional_policy(` - iptables_domtrans(docker_t) -') - -optional_policy(` - openvswitch_stream_connect(docker_t) -') - -# -# lxc rules -# - -allow docker_t self:capability { dac_override setgid setpcap setuid sys_admin sys_boot sys_chroot sys_ptrace }; - -allow docker_t self:process { getcap setcap setexec setpgid setsched signal_perms }; - -allow docker_t self:netlink_route_socket rw_netlink_socket_perms;; -allow docker_t self:netlink_audit_socket create_netlink_socket_perms; -allow docker_t self:unix_dgram_socket { create_socket_perms sendto }; -allow docker_t self:unix_stream_socket { create_stream_socket_perms connectto }; - -allow docker_t docker_var_lib_t:dir mounton; -allow docker_t docker_var_lib_t:chr_file mounton; -can_exec(docker_t, docker_var_lib_t) - -kernel_dontaudit_setsched(docker_t) -kernel_get_sysvipc_info(docker_t) -kernel_request_load_module(docker_t) -kernel_mounton_messages(docker_t) -kernel_mounton_all_proc(docker_t) -kernel_mounton_all_sysctls(docker_t) -kernel_unlabeled_entry_type(spc_t) -kernel_unlabeled_domtrans(docker_t, spc_t) - -dev_getattr_all(docker_t) -dev_getattr_sysfs_fs(docker_t) -dev_read_urand(docker_t) -dev_read_lvm_control(docker_t) -dev_rw_sysfs(docker_t) -dev_rw_loop_control(docker_t) -dev_rw_lvm_control(docker_t) - -files_getattr_isid_type_dirs(docker_t) -files_manage_isid_type_dirs(docker_t) -files_manage_isid_type_files(docker_t) -files_manage_isid_type_symlinks(docker_t) -files_manage_isid_type_chr_files(docker_t) -files_manage_isid_type_blk_files(docker_t) -files_exec_isid_files(docker_t) -files_mounton_isid(docker_t) -files_mounton_non_security(docker_t) -files_mounton_isid_type_chr_file(docker_t) - -fs_mount_all_fs(docker_t) -fs_unmount_all_fs(docker_t) -fs_remount_all_fs(docker_t) -files_mounton_isid(docker_t) -fs_manage_cgroup_dirs(docker_t) -fs_manage_cgroup_files(docker_t) -fs_relabelfrom_xattr_fs(docker_t) -fs_relabelfrom_tmpfs(docker_t) -fs_read_tmpfs_symlinks(docker_t) -fs_list_hugetlbfs(docker_t) - -term_use_generic_ptys(docker_t) -term_use_ptmx(docker_t) -term_getattr_pty_fs(docker_t) -term_relabel_pty_fs(docker_t) -term_mounton_unallocated_ttys(docker_t) - -modutils_domtrans_insmod(docker_t) - -systemd_status_all_unit_files(docker_t) -systemd_start_systemd_services(docker_t) - -userdom_stream_connect(docker_t) -userdom_search_user_home_content(docker_t) -userdom_read_all_users_state(docker_t) -userdom_relabel_user_home_files(docker_t) -userdom_relabel_user_tmp_files(docker_t) -userdom_relabel_user_tmp_dirs(docker_t) - -optional_policy(` - gpm_getattr_gpmctl(docker_t) -') - -optional_policy(` - dbus_system_bus_client(docker_t) - init_dbus_chat(docker_t) - init_start_transient_unit(docker_t) - - optional_policy(` - systemd_dbus_chat_logind(docker_t) - systemd_dbus_chat_machined(docker_t) - ') - - optional_policy(` - firewalld_dbus_chat(docker_t) - ') -') - -optional_policy(` - udev_read_db(docker_t) -') - -optional_policy(` - unconfined_domain(docker_t) - unconfined_typebounds(docker_t) -') - -optional_policy(` - virt_read_config(docker_t) - virt_exec(docker_t) - virt_stream_connect(docker_t) - virt_stream_connect_sandbox(docker_t) - virt_exec_sandbox_files(docker_t) - virt_manage_sandbox_files(docker_t) - virt_relabel_sandbox_filesystem(docker_t) - # for lxc - virt_transition_svirt_sandbox(docker_t, system_r) - virt_mounton_sandbox_file(docker_t) -# virt_attach_sandbox_tun_iface(docker_t) - allow docker_t svirt_sandbox_domain:tun_socket relabelfrom; - virt_sandbox_entrypoint(docker_t) -') - -tunable_policy(`docker_connect_any',` - corenet_tcp_connect_all_ports(docker_t) - corenet_sendrecv_all_packets(docker_t) - corenet_tcp_sendrecv_all_ports(docker_t) -') - -######################################## -# -# spc local policy -# -allow spc_t { docker_var_lib_t docker_share_t }:file entrypoint; -role system_r types spc_t; - -domtrans_pattern(docker_t, docker_share_t, spc_t) -domtrans_pattern(docker_t, docker_var_lib_t, spc_t) -allow docker_t spc_t:process { setsched signal_perms }; -ps_process_pattern(docker_t, spc_t) -allow docker_t spc_t:socket_class_set { relabelto relabelfrom }; -filetrans_pattern(docker_t, docker_var_lib_t, docker_share_t, dir, "overlay") - -optional_policy(` - systemd_dbus_chat_machined(spc_t) -') - -optional_policy(` - dbus_chat_system_bus(spc_t) -') - -optional_policy(` - unconfined_domain_noaudit(spc_t) -') - -optional_policy(` - virt_transition_svirt_sandbox(spc_t, system_r) - virt_sandbox_entrypoint(spc_t) -') - -######################################## -# -# docker_auth local policy -# -allow docker_auth_t self:fifo_file rw_fifo_file_perms; -allow docker_auth_t self:unix_stream_socket create_stream_socket_perms; -dontaudit docker_auth_t self:capability net_admin; - -docker_stream_connect(docker_auth_t) - -manage_dirs_pattern(docker_auth_t, docker_plugin_var_run_t, docker_plugin_var_run_t) -manage_files_pattern(docker_auth_t, docker_plugin_var_run_t, docker_plugin_var_run_t) -manage_sock_files_pattern(docker_auth_t, docker_plugin_var_run_t, docker_plugin_var_run_t) -manage_lnk_files_pattern(docker_auth_t, docker_plugin_var_run_t, docker_plugin_var_run_t) -files_pid_filetrans(docker_auth_t, docker_plugin_var_run_t, { dir file lnk_file sock_file }) - -domain_use_interactive_fds(docker_auth_t) - -kernel_read_net_sysctls(docker_auth_t) - -auth_use_nsswitch(docker_auth_t) - -files_read_etc_files(docker_auth_t) - -miscfiles_read_localization(docker_auth_t) - -sysnet_dns_name_resolve(docker_auth_t) diff --git a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/LICENSE b/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/LICENSE deleted file mode 100644 index d511905..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/LICENSE +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/Makefile b/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/Makefile deleted file mode 100644 index 16df33e..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -TARGETS?=docker -MODULES?=${TARGETS:=.pp.bz2} -SHAREDIR?=/usr/share - -all: ${TARGETS:=.pp.bz2} - -%.pp.bz2: %.pp - @echo Compressing $^ -\> $@ - bzip2 -9 $^ - -%.pp: %.te - make -f ${SHAREDIR}/selinux/devel/Makefile $@ - -clean: - rm -f *~ *.tc *.pp *.pp.bz2 - rm -rf tmp *.tar.gz - -man: install - sepolicy manpage --domain ${TARGETS}_t - -install: - semodule -i ${TARGETS} - diff --git a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/README.md b/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/README.md deleted file mode 100644 index 7ea3117..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/README.md +++ /dev/null @@ -1 +0,0 @@ -SELinux policy for docker diff --git a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/docker.fc b/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/docker.fc deleted file mode 100644 index 10b7d52..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/docker.fc +++ /dev/null @@ -1,33 +0,0 @@ -/root/\.docker gen_context(system_u:object_r:docker_home_t,s0) - -/usr/bin/docker -- gen_context(system_u:object_r:docker_exec_t,s0) -/usr/bin/docker-novolume-plugin -- gen_context(system_u:object_r:docker_auth_exec_t,s0) -/usr/lib/docker/docker-novolume-plugin -- gen_context(system_u:object_r:docker_auth_exec_t,s0) - -/usr/lib/systemd/system/docker.service -- gen_context(system_u:object_r:docker_unit_file_t,s0) -/usr/lib/systemd/system/docker-novolume-plugin.service -- gen_context(system_u:object_r:docker_unit_file_t,s0) - -/etc/docker(/.*)? gen_context(system_u:object_r:docker_config_t,s0) - -/var/lib/docker(/.*)? gen_context(system_u:object_r:docker_var_lib_t,s0) -/var/lib/kublet(/.*)? gen_context(system_u:object_r:docker_var_lib_t,s0) -/var/lib/docker/vfs(/.*)? gen_context(system_u:object_r:svirt_sandbox_file_t,s0) - -/var/run/docker(/.*)? gen_context(system_u:object_r:docker_var_run_t,s0) -/var/run/docker\.pid -- gen_context(system_u:object_r:docker_var_run_t,s0) -/var/run/docker\.sock -s gen_context(system_u:object_r:docker_var_run_t,s0) -/var/run/docker-client(/.*)? gen_context(system_u:object_r:docker_var_run_t,s0) -/var/run/docker/plugins(/.*)? gen_context(system_u:object_r:docker_plugin_var_run_t,s0) - -/var/lock/lxc(/.*)? gen_context(system_u:object_r:docker_lock_t,s0) - -/var/log/lxc(/.*)? gen_context(system_u:object_r:docker_log_t,s0) - -/var/lib/docker/init(/.*)? gen_context(system_u:object_r:docker_share_t,s0) -/var/lib/docker/containers/.*/hosts gen_context(system_u:object_r:docker_share_t,s0) -/var/lib/docker/containers/.*/hostname gen_context(system_u:object_r:docker_share_t,s0) -/var/lib/docker/.*/config\.env gen_context(system_u:object_r:docker_share_t,s0) - -# OL7.2 systemd selinux update -/var/run/systemd/machines(/.*)? gen_context(system_u:object_r:systemd_machined_var_run_t,s0) -/var/lib/machines(/.*)? gen_context(system_u:object_r:systemd_machined_var_lib_t,s0) diff --git a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/docker.if b/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/docker.if deleted file mode 100644 index 4780af0..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/docker.if +++ /dev/null @@ -1,659 +0,0 @@ - -## The open-source application container engine. - -######################################## -## -## Execute docker in the docker domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_domtrans',` - gen_require(` - type docker_t, docker_exec_t; - ') - - corecmd_search_bin($1) - domtrans_pattern($1, docker_exec_t, docker_t) -') - -######################################## -## -## Execute docker in the caller domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_exec',` - gen_require(` - type docker_exec_t; - ') - - corecmd_search_bin($1) - can_exec($1, docker_exec_t) -') - -######################################## -## -## Search docker lib directories. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_search_lib',` - gen_require(` - type docker_var_lib_t; - ') - - allow $1 docker_var_lib_t:dir search_dir_perms; - files_search_var_lib($1) -') - -######################################## -## -## Execute docker lib directories. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_exec_lib',` - gen_require(` - type docker_var_lib_t; - ') - - allow $1 docker_var_lib_t:dir search_dir_perms; - can_exec($1, docker_var_lib_t) -') - -######################################## -## -## Read docker lib files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_read_lib_files',` - gen_require(` - type docker_var_lib_t; - ') - - files_search_var_lib($1) - read_files_pattern($1, docker_var_lib_t, docker_var_lib_t) -') - -######################################## -## -## Read docker share files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_read_share_files',` - gen_require(` - type docker_share_t; - ') - - files_search_var_lib($1) - list_dirs_pattern($1, docker_share_t, docker_share_t) - read_files_pattern($1, docker_share_t, docker_share_t) - read_lnk_files_pattern($1, docker_share_t, docker_share_t) -') - -###################################### -## -## Allow the specified domain to execute docker shared files -## in the caller domain. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_exec_share_files',` - gen_require(` - type docker_share_t; - ') - - can_exec($1, docker_share_t) -') - -######################################## -## -## Manage docker lib files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_manage_lib_files',` - gen_require(` - type docker_var_lib_t; - ') - - files_search_var_lib($1) - manage_files_pattern($1, docker_var_lib_t, docker_var_lib_t) - manage_lnk_files_pattern($1, docker_var_lib_t, docker_var_lib_t) -') - -######################################## -## -## Manage docker lib directories. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_manage_lib_dirs',` - gen_require(` - type docker_var_lib_t; - ') - - files_search_var_lib($1) - manage_dirs_pattern($1, docker_var_lib_t, docker_var_lib_t) -') - -######################################## -## -## Create objects in a docker var lib directory -## with an automatic type transition to -## a specified private type. -## -## -## -## Domain allowed access. -## -## -## -## -## The type of the object to create. -## -## -## -## -## The class of the object to be created. -## -## -## -## -## The name of the object being created. -## -## -# -interface(`docker_lib_filetrans',` - gen_require(` - type docker_var_lib_t; - ') - - filetrans_pattern($1, docker_var_lib_t, $2, $3, $4) -') - -######################################## -## -## Read docker PID files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_read_pid_files',` - gen_require(` - type docker_var_run_t; - ') - - files_search_pids($1) - read_files_pattern($1, docker_var_run_t, docker_var_run_t) -') - -######################################## -## -## Execute docker server in the docker domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_systemctl',` - gen_require(` - type docker_t; - type docker_unit_file_t; - ') - - systemd_exec_systemctl($1) - init_reload_services($1) - systemd_read_fifo_file_passwd_run($1) - allow $1 docker_unit_file_t:file read_file_perms; - allow $1 docker_unit_file_t:service manage_service_perms; - - ps_process_pattern($1, docker_t) -') - -######################################## -## -## Read and write docker shared memory. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_rw_sem',` - gen_require(` - type docker_t; - ') - - allow $1 docker_t:sem rw_sem_perms; -') - -####################################### -## -## Read and write the docker pty type. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_use_ptys',` - gen_require(` - type docker_devpts_t; - ') - - allow $1 docker_devpts_t:chr_file rw_term_perms; -') - -####################################### -## -## Allow domain to create docker content -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_filetrans_named_content',` - - gen_require(` - type docker_var_lib_t; - type docker_share_t; - type docker_log_t; - type docker_var_run_t; - type docker_home_t; - ') - - files_pid_filetrans($1, docker_var_run_t, file, "docker.pid") - files_pid_filetrans($1, docker_var_run_t, sock_file, "docker.sock") - files_pid_filetrans($1, docker_var_run_t, dir, "docker-client") - logging_log_filetrans($1, docker_log_t, dir, "lxc") - files_var_lib_filetrans($1, docker_var_lib_t, dir, "docker") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "config.env") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "hosts") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "hostname") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "resolv.conf") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, dir, "init") - userdom_admin_home_dir_filetrans($1, docker_home_t, dir, ".docker") -') - -######################################## -## -## Connect to docker over a unix stream socket. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_stream_connect',` - gen_require(` - type docker_t, docker_var_run_t; - ') - - files_search_pids($1) - stream_connect_pattern($1, docker_var_run_t, docker_var_run_t, docker_t) -') - -######################################## -## -## Connect to SPC containers over a unix stream socket. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_spc_stream_connect',` - gen_require(` - type spc_t, spc_var_run_t; - ') - - files_search_pids($1) - files_write_all_pid_sockets($1) - allow $1 spc_t:unix_stream_socket connectto; -') - -######################################## -## -## All of the rules required to administrate -## an docker environment -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_admin',` - gen_require(` - type docker_t; - type docker_var_lib_t, docker_var_run_t; - type docker_unit_file_t; - type docker_lock_t; - type docker_log_t; - type docker_config_t; - ') - - allow $1 docker_t:process { ptrace signal_perms }; - ps_process_pattern($1, docker_t) - - admin_pattern($1, docker_config_t) - - files_search_var_lib($1) - admin_pattern($1, docker_var_lib_t) - - files_search_pids($1) - admin_pattern($1, docker_var_run_t) - - files_search_locks($1) - admin_pattern($1, docker_lock_t) - - logging_search_logs($1) - admin_pattern($1, docker_log_t) - - docker_systemctl($1) - admin_pattern($1, docker_unit_file_t) - allow $1 docker_unit_file_t:service all_service_perms; - - optional_policy(` - systemd_passwd_agent_exec($1) - systemd_read_fifo_file_passwd_run($1) - ') -') - -######################################## -## -## Execute docker_auth_exec_t in the docker_auth domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_auth_domtrans',` - gen_require(` - type docker_auth_t, docker_auth_exec_t; - ') - - corecmd_search_bin($1) - domtrans_pattern($1, docker_auth_exec_t, docker_auth_t) -') - -###################################### -## -## Execute docker_auth in the caller domain. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_auth_exec',` - gen_require(` - type docker_auth_exec_t; - ') - - corecmd_search_bin($1) - can_exec($1, docker_auth_exec_t) -') - -######################################## -## -## Connect to docker_auth over a unix stream socket. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_auth_stream_connect',` - gen_require(` - type docker_auth_t, docker_plugin_var_run_t; - ') - - files_search_pids($1) - stream_connect_pattern($1, docker_plugin_var_run_t, docker_plugin_var_run_t, docker_auth_t) -') - -######################################## -## -## docker domain typebounds calling domain. -## -## -## -## Domain to be typebound. -## -## -# -interface(`docker_typebounds',` - gen_require(` - type docker_t; - ') - - typebounds docker_t $1; -') - -######################################## -## -## Allow any docker_exec_t to be an entrypoint of this domain -## -## -## -## Domain allowed access. -## -## -## -# -interface(`docker_entrypoint',` - gen_require(` - type docker_exec_t; - ') - allow $1 docker_exec_t:file entrypoint; -') - -######################################## -## -## Send and receive messages from -## systemd machined over dbus. -## -## -## -## Domain allowed access. -## -## -# -interface(`systemd_dbus_chat_machined',` - gen_require(` - type systemd_machined_t; - class dbus send_msg; - ') - - allow $1 systemd_machined_t:dbus send_msg; - allow systemd_machined_t $1:dbus send_msg; - ps_process_pattern(systemd_machined_t, $1) -') - -######################################## -## -## Allow any svirt_sandbox_file_t to be an entrypoint of this domain -## -## -## -## Domain allowed access. -## -## -## -# -interface(`virt_sandbox_entrypoint',` - gen_require(` - type svirt_sandbox_file_t; - ') - allow $1 svirt_sandbox_file_t:file entrypoint; -') - -######################################## -## -## Send and receive messages from -## virt over dbus. -## -## -## -## Domain allowed access. -## -## -# -interface(`virt_dbus_chat',` - gen_require(` - type virtd_t; - class dbus send_msg; - ') - - allow $1 virtd_t:dbus send_msg; - allow virtd_t $1:dbus send_msg; - ps_process_pattern(virtd_t, $1) -') - -####################################### -## -## Read the process state of virt sandbox containers -## -## -## -## Domain allowed access. -## -## -# -interface(`virt_sandbox_read_state',` - gen_require(` - attribute svirt_sandbox_domain; - ') - - ps_process_pattern($1, svirt_sandbox_domain) -') - -###################################### -## -## Send a signal to sandbox domains -## -## -## -## Domain allowed access. -## -## -# -interface(`virt_signal_sandbox',` - gen_require(` - attribute svirt_sandbox_domain; - ') - - allow $1 svirt_sandbox_domain:process signal; -') - -####################################### -## -## Getattr Sandbox File systems -## -## -## -## Domain allowed access. -## -## -# -interface(`virt_getattr_sandbox_filesystem',` - gen_require(` - type svirt_sandbox_file_t; - ') - - allow $1 svirt_sandbox_file_t:filesystem getattr; -') - -####################################### -## -## Read Sandbox Files -## -## -## -## Domain allowed access. -## -## -# -interface(`virt_read_sandbox_files',` - gen_require(` - type svirt_sandbox_file_t; - ') - - list_dirs_pattern($1, svirt_sandbox_file_t, svirt_sandbox_file_t) - read_files_pattern($1, svirt_sandbox_file_t, svirt_sandbox_file_t) - read_lnk_files_pattern($1, svirt_sandbox_file_t, svirt_sandbox_file_t) -') - -####################################### -## -## Read the process state of spc containers -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_spc_read_state',` - gen_require(` - type spc_t; - ') - - ps_process_pattern($1, spc_t) -') - diff --git a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/docker.te b/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/docker.te deleted file mode 100644 index d4de36f..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux-oraclelinux-7/docker-engine-selinux/docker.te +++ /dev/null @@ -1,465 +0,0 @@ -policy_module(docker, 1.0.0) - -######################################## -# -# Declarations -# - -## -##

-## Determine whether docker can -## connect to all TCP ports. -##

-##
-gen_tunable(docker_connect_any, false) - -type docker_t; -type docker_exec_t; -init_daemon_domain(docker_t, docker_exec_t) -domain_subj_id_change_exemption(docker_t) -domain_role_change_exemption(docker_t) - -type spc_t; -domain_type(spc_t) -role system_r types spc_t; - -type docker_auth_t; -type docker_auth_exec_t; -init_daemon_domain(docker_auth_t, docker_auth_exec_t) - -type spc_var_run_t; -files_pid_file(spc_var_run_t) - -type docker_var_lib_t; -files_type(docker_var_lib_t) - -type docker_home_t; -userdom_user_home_content(docker_home_t) - -type docker_config_t; -files_config_file(docker_config_t) - -type docker_lock_t; -files_lock_file(docker_lock_t) - -type docker_log_t; -logging_log_file(docker_log_t) - -type docker_tmp_t; -files_tmp_file(docker_tmp_t) - -type docker_tmpfs_t; -files_tmpfs_file(docker_tmpfs_t) - -type docker_var_run_t; -files_pid_file(docker_var_run_t) - -type docker_plugin_var_run_t; -files_pid_file(docker_plugin_var_run_t) - -type docker_unit_file_t; -systemd_unit_file(docker_unit_file_t) - -type docker_devpts_t; -term_pty(docker_devpts_t) - -type docker_share_t; -files_type(docker_share_t) - -# OL7 systemd selinux update -type systemd_machined_t; -type systemd_machined_exec_t; -init_daemon_domain(systemd_machined_t, systemd_machined_exec_t) - -# /run/systemd/machines -type systemd_machined_var_run_t; -files_pid_file(systemd_machined_var_run_t) - -# /var/lib/machines -type systemd_machined_var_lib_t; -files_type(systemd_machined_var_lib_t) - - -######################################## -# -# docker local policy -# -allow docker_t self:capability { chown kill fowner fsetid mknod net_admin net_bind_service net_raw setfcap }; -allow docker_t self:tun_socket relabelto; -allow docker_t self:process { getattr signal_perms setrlimit setfscreate }; -allow docker_t self:fifo_file rw_fifo_file_perms; -allow docker_t self:unix_stream_socket create_stream_socket_perms; -allow docker_t self:tcp_socket create_stream_socket_perms; -allow docker_t self:udp_socket create_socket_perms; -allow docker_t self:capability2 block_suspend; - -docker_auth_stream_connect(docker_t) - -manage_files_pattern(docker_t, docker_home_t, docker_home_t) -manage_dirs_pattern(docker_t, docker_home_t, docker_home_t) -manage_lnk_files_pattern(docker_t, docker_home_t, docker_home_t) -userdom_admin_home_dir_filetrans(docker_t, docker_home_t, dir, ".docker") - -manage_dirs_pattern(docker_t, docker_config_t, docker_config_t) -manage_files_pattern(docker_t, docker_config_t, docker_config_t) -files_etc_filetrans(docker_t, docker_config_t, dir, "docker") - -manage_dirs_pattern(docker_t, docker_lock_t, docker_lock_t) -manage_files_pattern(docker_t, docker_lock_t, docker_lock_t) -files_lock_filetrans(docker_t, docker_lock_t, { dir file }, "lxc") - -manage_dirs_pattern(docker_t, docker_log_t, docker_log_t) -manage_files_pattern(docker_t, docker_log_t, docker_log_t) -manage_lnk_files_pattern(docker_t, docker_log_t, docker_log_t) -logging_log_filetrans(docker_t, docker_log_t, { dir file lnk_file }) -allow docker_t docker_log_t:dir_file_class_set { relabelfrom relabelto }; - -manage_dirs_pattern(docker_t, docker_tmp_t, docker_tmp_t) -manage_files_pattern(docker_t, docker_tmp_t, docker_tmp_t) -manage_lnk_files_pattern(docker_t, docker_tmp_t, docker_tmp_t) -files_tmp_filetrans(docker_t, docker_tmp_t, { dir file lnk_file }) - -manage_dirs_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_lnk_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_fifo_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_chr_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_blk_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -allow docker_t docker_tmpfs_t:dir relabelfrom; -can_exec(docker_t, docker_tmpfs_t) -fs_tmpfs_filetrans(docker_t, docker_tmpfs_t, { dir file }) -allow docker_t docker_tmpfs_t:chr_file mounton; - -manage_dirs_pattern(docker_t, docker_share_t, docker_share_t) -manage_files_pattern(docker_t, docker_share_t, docker_share_t) -manage_lnk_files_pattern(docker_t, docker_share_t, docker_share_t) -allow docker_t docker_share_t:dir_file_class_set { relabelfrom relabelto }; - -can_exec(docker_t, docker_share_t) -#docker_filetrans_named_content(docker_t) - -manage_dirs_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_chr_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_blk_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_lnk_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -allow docker_t docker_var_lib_t:dir_file_class_set { relabelfrom relabelto }; -files_var_lib_filetrans(docker_t, docker_var_lib_t, { dir file lnk_file }) - -manage_dirs_pattern(docker_t, docker_var_run_t, docker_var_run_t) -manage_files_pattern(docker_t, docker_var_run_t, docker_var_run_t) -manage_sock_files_pattern(docker_t, docker_var_run_t, docker_var_run_t) -manage_lnk_files_pattern(docker_t, docker_var_run_t, docker_var_run_t) -files_pid_filetrans(docker_t, docker_var_run_t, { dir file lnk_file sock_file }) - -allow docker_t docker_devpts_t:chr_file { relabelfrom rw_chr_file_perms setattr_chr_file_perms }; -term_create_pty(docker_t, docker_devpts_t) - -kernel_read_system_state(docker_t) -kernel_read_network_state(docker_t) -kernel_read_all_sysctls(docker_t) -kernel_rw_net_sysctls(docker_t) -kernel_setsched(docker_t) -kernel_read_all_proc(docker_t) - -domain_use_interactive_fds(docker_t) -domain_dontaudit_read_all_domains_state(docker_t) - -corecmd_exec_bin(docker_t) -corecmd_exec_shell(docker_t) - -corenet_tcp_bind_generic_node(docker_t) -corenet_tcp_sendrecv_generic_if(docker_t) -corenet_tcp_sendrecv_generic_node(docker_t) -corenet_tcp_sendrecv_generic_port(docker_t) -corenet_tcp_bind_all_ports(docker_t) -corenet_tcp_connect_http_port(docker_t) -corenet_tcp_connect_commplex_main_port(docker_t) -corenet_udp_sendrecv_generic_if(docker_t) -corenet_udp_sendrecv_generic_node(docker_t) -corenet_udp_sendrecv_all_ports(docker_t) -corenet_udp_bind_generic_node(docker_t) -corenet_udp_bind_all_ports(docker_t) - -files_read_config_files(docker_t) -files_dontaudit_getattr_all_dirs(docker_t) -files_dontaudit_getattr_all_files(docker_t) - -fs_read_cgroup_files(docker_t) -fs_read_tmpfs_symlinks(docker_t) -fs_search_all(docker_t) -fs_getattr_all_fs(docker_t) - -storage_raw_rw_fixed_disk(docker_t) - -auth_use_nsswitch(docker_t) -auth_dontaudit_getattr_shadow(docker_t) - -init_read_state(docker_t) -init_status(docker_t) - -logging_send_audit_msgs(docker_t) -logging_send_syslog_msg(docker_t) - -miscfiles_read_localization(docker_t) - -mount_domtrans(docker_t) - -seutil_read_default_contexts(docker_t) -seutil_read_config(docker_t) - -sysnet_dns_name_resolve(docker_t) -sysnet_exec_ifconfig(docker_t) - -optional_policy(` - rpm_exec(docker_t) - rpm_read_db(docker_t) - rpm_exec(docker_t) -') - -optional_policy(` - fstools_domtrans(docker_t) -') - -optional_policy(` - iptables_domtrans(docker_t) -') - -optional_policy(` - openvswitch_stream_connect(docker_t) -') - -# -# lxc rules -# - -allow docker_t self:capability { dac_override setgid setpcap setuid sys_admin sys_boot sys_chroot sys_ptrace }; - -allow docker_t self:process { getcap setcap setexec setpgid setsched signal_perms }; - -allow docker_t self:netlink_route_socket rw_netlink_socket_perms;; -allow docker_t self:netlink_audit_socket create_netlink_socket_perms; -allow docker_t self:unix_dgram_socket { create_socket_perms sendto }; -allow docker_t self:unix_stream_socket { create_stream_socket_perms connectto }; - -allow docker_t docker_var_lib_t:dir mounton; -allow docker_t docker_var_lib_t:chr_file mounton; -can_exec(docker_t, docker_var_lib_t) - -kernel_dontaudit_setsched(docker_t) -kernel_get_sysvipc_info(docker_t) -kernel_request_load_module(docker_t) -kernel_mounton_messages(docker_t) -kernel_mounton_all_proc(docker_t) -kernel_mounton_all_sysctls(docker_t) -kernel_unlabeled_entry_type(spc_t) -kernel_unlabeled_domtrans(docker_t, spc_t) - -dev_getattr_all(docker_t) -dev_getattr_sysfs_fs(docker_t) -dev_read_urand(docker_t) -dev_read_lvm_control(docker_t) -dev_rw_sysfs(docker_t) -dev_rw_loop_control(docker_t) -dev_rw_lvm_control(docker_t) - -files_getattr_isid_type_dirs(docker_t) -files_manage_isid_type_dirs(docker_t) -files_manage_isid_type_files(docker_t) -files_manage_isid_type_symlinks(docker_t) -files_manage_isid_type_chr_files(docker_t) -files_manage_isid_type_blk_files(docker_t) -files_exec_isid_files(docker_t) -files_mounton_isid(docker_t) -files_mounton_non_security(docker_t) -files_mounton_isid_type_chr_file(docker_t) - -fs_mount_all_fs(docker_t) -fs_unmount_all_fs(docker_t) -fs_remount_all_fs(docker_t) -files_mounton_isid(docker_t) -fs_manage_cgroup_dirs(docker_t) -fs_manage_cgroup_files(docker_t) -fs_relabelfrom_xattr_fs(docker_t) -fs_relabelfrom_tmpfs(docker_t) -fs_read_tmpfs_symlinks(docker_t) -fs_list_hugetlbfs(docker_t) - -term_use_generic_ptys(docker_t) -term_use_ptmx(docker_t) -term_getattr_pty_fs(docker_t) -term_relabel_pty_fs(docker_t) -term_mounton_unallocated_ttys(docker_t) - -modutils_domtrans_insmod(docker_t) - -systemd_status_all_unit_files(docker_t) -systemd_start_systemd_services(docker_t) - -userdom_stream_connect(docker_t) -userdom_search_user_home_content(docker_t) -userdom_read_all_users_state(docker_t) -userdom_relabel_user_home_files(docker_t) -userdom_relabel_user_tmp_files(docker_t) -userdom_relabel_user_tmp_dirs(docker_t) - -optional_policy(` - gpm_getattr_gpmctl(docker_t) -') - -optional_policy(` - dbus_system_bus_client(docker_t) - init_dbus_chat(docker_t) - init_start_transient_unit(docker_t) - - optional_policy(` - systemd_dbus_chat_logind(docker_t) - systemd_dbus_chat_machined(docker_t) - ') - - optional_policy(` - firewalld_dbus_chat(docker_t) - ') -') - -optional_policy(` - udev_read_db(docker_t) -') - -optional_policy(` - unconfined_domain(docker_t) - # unconfined_typebounds(docker_t) -') - -optional_policy(` - virt_read_config(docker_t) - virt_exec(docker_t) - virt_stream_connect(docker_t) - virt_stream_connect_sandbox(docker_t) - virt_exec_sandbox_files(docker_t) - virt_manage_sandbox_files(docker_t) - virt_relabel_sandbox_filesystem(docker_t) - # for lxc - virt_transition_svirt_sandbox(docker_t, system_r) - virt_mounton_sandbox_file(docker_t) -# virt_attach_sandbox_tun_iface(docker_t) - allow docker_t svirt_sandbox_domain:tun_socket relabelfrom; - virt_sandbox_entrypoint(docker_t) -') - -tunable_policy(`docker_connect_any',` - corenet_tcp_connect_all_ports(docker_t) - corenet_sendrecv_all_packets(docker_t) - corenet_tcp_sendrecv_all_ports(docker_t) -') - -######################################## -# -# spc local policy -# -allow spc_t { docker_var_lib_t docker_share_t }:file entrypoint; -role system_r types spc_t; - -domtrans_pattern(docker_t, docker_share_t, spc_t) -domtrans_pattern(docker_t, docker_var_lib_t, spc_t) -allow docker_t spc_t:process { setsched signal_perms }; -ps_process_pattern(docker_t, spc_t) -allow docker_t spc_t:socket_class_set { relabelto relabelfrom }; -filetrans_pattern(docker_t, docker_var_lib_t, docker_share_t, dir, "overlay") - -optional_policy(` - systemd_dbus_chat_machined(spc_t) -') - -optional_policy(` - dbus_chat_system_bus(spc_t) -') - -optional_policy(` - unconfined_domain_noaudit(spc_t) -') - -optional_policy(` - virt_transition_svirt_sandbox(spc_t, system_r) - virt_sandbox_entrypoint(spc_t) -') - -######################################## -# -# docker_auth local policy -# -allow docker_auth_t self:fifo_file rw_fifo_file_perms; -allow docker_auth_t self:unix_stream_socket create_stream_socket_perms; -dontaudit docker_auth_t self:capability net_admin; - -docker_stream_connect(docker_auth_t) - -manage_dirs_pattern(docker_auth_t, docker_plugin_var_run_t, docker_plugin_var_run_t) -manage_files_pattern(docker_auth_t, docker_plugin_var_run_t, docker_plugin_var_run_t) -manage_sock_files_pattern(docker_auth_t, docker_plugin_var_run_t, docker_plugin_var_run_t) -manage_lnk_files_pattern(docker_auth_t, docker_plugin_var_run_t, docker_plugin_var_run_t) -files_pid_filetrans(docker_auth_t, docker_plugin_var_run_t, { dir file lnk_file sock_file }) - -domain_use_interactive_fds(docker_auth_t) - -kernel_read_net_sysctls(docker_auth_t) - -auth_use_nsswitch(docker_auth_t) - -files_read_etc_files(docker_auth_t) - -miscfiles_read_localization(docker_auth_t) - -sysnet_dns_name_resolve(docker_auth_t) - -######################################## -# -# OL7.2 systemd selinux update -# systemd_machined local policy -# -allow systemd_machined_t self:capability { dac_override setgid sys_admin sys_chroot sys_ptrace }; -allow systemd_machined_t systemd_unit_file_t:service { status start }; -allow systemd_machined_t self:unix_dgram_socket create_socket_perms; - -manage_dirs_pattern(systemd_machined_t, systemd_machined_var_run_t, systemd_machined_var_run_t) -manage_files_pattern(systemd_machined_t, systemd_machined_var_run_t, systemd_machined_var_run_t) -manage_lnk_files_pattern(systemd_machined_t, systemd_machined_var_run_t, systemd_machined_var_run_t) -init_pid_filetrans(systemd_machined_t, systemd_machined_var_run_t, dir, "machines") - -manage_dirs_pattern(systemd_machined_t, systemd_machined_var_lib_t, systemd_machined_var_lib_t) -manage_files_pattern(systemd_machined_t, systemd_machined_var_lib_t, systemd_machined_var_lib_t) -manage_lnk_files_pattern(systemd_machined_t, systemd_machined_var_lib_t, systemd_machined_var_lib_t) -init_var_lib_filetrans(systemd_machined_t, systemd_machined_var_lib_t, dir, "machines") - -kernel_dgram_send(systemd_machined_t) -# This is a bug, but need for now. -kernel_read_unlabeled_state(systemd_machined_t) - -init_dbus_chat(systemd_machined_t) -init_status(systemd_machined_t) - -userdom_dbus_send_all_users(systemd_machined_t) - -term_use_ptmx(systemd_machined_t) - -optional_policy(` - dbus_connect_system_bus(systemd_machined_t) - dbus_system_bus_client(systemd_machined_t) -') - -optional_policy(` - docker_read_share_files(systemd_machined_t) - docker_spc_read_state(systemd_machined_t) -') - -optional_policy(` - virt_dbus_chat(systemd_machined_t) - virt_sandbox_read_state(systemd_machined_t) - virt_signal_sandbox(systemd_machined_t) - virt_stream_connect_sandbox(systemd_machined_t) - virt_rw_svirt_dev(systemd_machined_t) - virt_getattr_sandbox_filesystem(systemd_machined_t) - virt_read_sandbox_files(systemd_machined_t) -') - - diff --git a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/LICENSE b/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/LICENSE deleted file mode 100644 index 5b6e7c6..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/LICENSE +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/Makefile b/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/Makefile deleted file mode 100644 index 1bdc695..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -TARGETS?=docker -MODULES?=${TARGETS:=.pp.bz2} -SHAREDIR?=/usr/share - -all: ${TARGETS:=.pp.bz2} - -%.pp.bz2: %.pp - @echo Compressing $^ -\> $@ - bzip2 -9 $^ - -%.pp: %.te - make -f ${SHAREDIR}/selinux/devel/Makefile $@ - -clean: - rm -f *~ *.tc *.pp *.pp.bz2 - rm -rf tmp *.tar.gz diff --git a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker.fc b/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker.fc deleted file mode 100644 index 467d659..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker.fc +++ /dev/null @@ -1,18 +0,0 @@ -/root/\.docker gen_context(system_u:object_r:docker_home_t,s0) - -/usr/bin/dockerd -- gen_context(system_u:object_r:docker_exec_t,s0) - -/usr/lib/systemd/system/docker.service -- gen_context(system_u:object_r:docker_unit_file_t,s0) - -/etc/docker(/.*)? gen_context(system_u:object_r:docker_config_t,s0) - -/var/lib/docker(/.*)? gen_context(system_u:object_r:docker_var_lib_t,s0) - -/var/run/docker\.pid -- gen_context(system_u:object_r:docker_var_run_t,s0) -/var/run/docker\.sock -s gen_context(system_u:object_r:docker_var_run_t,s0) -/var/run/docker-client(/.*)? gen_context(system_u:object_r:docker_var_run_t,s0) - -/var/lib/docker/init(/.*)? gen_context(system_u:object_r:docker_share_t,s0) -/var/lib/docker/containers/.*/hosts gen_context(system_u:object_r:docker_share_t,s0) -/var/lib/docker/containers/.*/hostname gen_context(system_u:object_r:docker_share_t,s0) -/var/lib/docker/.*/config\.env gen_context(system_u:object_r:docker_share_t,s0) diff --git a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker.if b/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker.if deleted file mode 100644 index ca075c0..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker.if +++ /dev/null @@ -1,461 +0,0 @@ - -## The open-source application container engine. - -######################################## -## -## Execute docker in the docker domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_domtrans',` - gen_require(` - type docker_t, docker_exec_t; - ') - - corecmd_search_bin($1) - domtrans_pattern($1, docker_exec_t, docker_t) -') - -######################################## -## -## Execute docker in the caller domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_exec',` - gen_require(` - type docker_exec_t; - ') - - corecmd_search_bin($1) - can_exec($1, docker_exec_t) -') - -######################################## -## -## Search docker lib directories. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_search_lib',` - gen_require(` - type docker_var_lib_t; - ') - - allow $1 docker_var_lib_t:dir search_dir_perms; - files_search_var_lib($1) -') - -######################################## -## -## Execute docker lib directories. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_exec_lib',` - gen_require(` - type docker_var_lib_t; - ') - - allow $1 docker_var_lib_t:dir search_dir_perms; - can_exec($1, docker_var_lib_t) -') - -######################################## -## -## Read docker lib files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_read_lib_files',` - gen_require(` - type docker_var_lib_t; - ') - - files_search_var_lib($1) - read_files_pattern($1, docker_var_lib_t, docker_var_lib_t) -') - -######################################## -## -## Read docker share files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_read_share_files',` - gen_require(` - type docker_share_t; - ') - - files_search_var_lib($1) - read_files_pattern($1, docker_share_t, docker_share_t) -') - -######################################## -## -## Manage docker lib files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_manage_lib_files',` - gen_require(` - type docker_var_lib_t; - ') - - files_search_var_lib($1) - manage_files_pattern($1, docker_var_lib_t, docker_var_lib_t) - manage_lnk_files_pattern($1, docker_var_lib_t, docker_var_lib_t) -') - -######################################## -## -## Manage docker lib directories. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_manage_lib_dirs',` - gen_require(` - type docker_var_lib_t; - ') - - files_search_var_lib($1) - manage_dirs_pattern($1, docker_var_lib_t, docker_var_lib_t) -') - -######################################## -## -## Create objects in a docker var lib directory -## with an automatic type transition to -## a specified private type. -## -## -## -## Domain allowed access. -## -## -## -## -## The type of the object to create. -## -## -## -## -## The class of the object to be created. -## -## -## -## -## The name of the object being created. -## -## -# -interface(`docker_lib_filetrans',` - gen_require(` - type docker_var_lib_t; - ') - - filetrans_pattern($1, docker_var_lib_t, $2, $3, $4) -') - -######################################## -## -## Read docker PID files. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_read_pid_files',` - gen_require(` - type docker_var_run_t; - ') - - files_search_pids($1) - read_files_pattern($1, docker_var_run_t, docker_var_run_t) -') - -######################################## -## -## Execute docker server in the docker domain. -## -## -## -## Domain allowed to transition. -## -## -# -interface(`docker_systemctl',` - gen_require(` - type docker_t; - type docker_unit_file_t; - ') - - systemd_exec_systemctl($1) - init_reload_services($1) - systemd_read_fifo_file_passwd_run($1) - allow $1 docker_unit_file_t:file read_file_perms; - allow $1 docker_unit_file_t:service manage_service_perms; - - ps_process_pattern($1, docker_t) -') - -######################################## -## -## Read and write docker shared memory. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_rw_sem',` - gen_require(` - type docker_t; - ') - - allow $1 docker_t:sem rw_sem_perms; -') - -####################################### -## -## Read and write the docker pty type. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_use_ptys',` - gen_require(` - type docker_devpts_t; - ') - - allow $1 docker_devpts_t:chr_file rw_term_perms; -') - -####################################### -## -## Allow domain to create docker content -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_filetrans_named_content',` - - gen_require(` - type docker_var_lib_t; - type docker_share_t; - type docker_log_t; - type docker_var_run_t; - type docker_home_t; - ') - - files_pid_filetrans($1, docker_var_run_t, file, "docker.pid") - files_pid_filetrans($1, docker_var_run_t, sock_file, "docker.sock") - files_pid_filetrans($1, docker_var_run_t, dir, "docker-client") - files_var_lib_filetrans($1, docker_var_lib_t, dir, "docker") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "config.env") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "hosts") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "hostname") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, file, "resolv.conf") - filetrans_pattern($1, docker_var_lib_t, docker_share_t, dir, "init") - userdom_admin_home_dir_filetrans($1, docker_home_t, dir, ".docker") -') - -######################################## -## -## Connect to docker over a unix stream socket. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_stream_connect',` - gen_require(` - type docker_t, docker_var_run_t; - ') - - files_search_pids($1) - stream_connect_pattern($1, docker_var_run_t, docker_var_run_t, docker_t) -') - -######################################## -## -## Connect to SPC containers over a unix stream socket. -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_spc_stream_connect',` - gen_require(` - type spc_t, spc_var_run_t; - ') - - files_search_pids($1) - files_write_all_pid_sockets($1) - allow $1 spc_t:unix_stream_socket connectto; -') - - -######################################## -## -## All of the rules required to administrate -## an docker environment -## -## -## -## Domain allowed access. -## -## -# -interface(`docker_admin',` - gen_require(` - type docker_t; - type docker_var_lib_t, docker_var_run_t; - type docker_unit_file_t; - type docker_lock_t; - type docker_log_t; - type docker_config_t; - ') - - allow $1 docker_t:process { ptrace signal_perms }; - ps_process_pattern($1, docker_t) - - admin_pattern($1, docker_config_t) - - files_search_var_lib($1) - admin_pattern($1, docker_var_lib_t) - - files_search_pids($1) - admin_pattern($1, docker_var_run_t) - - files_search_locks($1) - admin_pattern($1, docker_lock_t) - - logging_search_logs($1) - admin_pattern($1, docker_log_t) - - docker_systemctl($1) - admin_pattern($1, docker_unit_file_t) - allow $1 docker_unit_file_t:service all_service_perms; - - optional_policy(` - systemd_passwd_agent_exec($1) - systemd_read_fifo_file_passwd_run($1) - ') -') - -interface(`domain_stub_named_filetrans_domain',` - gen_require(` - attribute named_filetrans_domain; - ') -') - -interface(`lvm_stub',` - gen_require(` - type lvm_t; - ') -') -interface(`staff_stub',` - gen_require(` - type staff_t; - ') -') -interface(`virt_stub_svirt_sandbox_domain',` - gen_require(` - attribute svirt_sandbox_domain; - ') -') -interface(`virt_stub_svirt_sandbox_file',` - gen_require(` - type svirt_sandbox_file_t; - ') -') -interface(`fs_dontaudit_remount_tmpfs',` - gen_require(` - type tmpfs_t; - ') - - dontaudit $1 tmpfs_t:filesystem remount; -') -interface(`dev_dontaudit_list_all_dev_nodes',` - gen_require(` - type device_t; - ') - - dontaudit $1 device_t:dir list_dir_perms; -') -interface(`kernel_unlabeled_entry_type',` - gen_require(` - type unlabeled_t; - ') - - domain_entry_file($1, unlabeled_t) -') -interface(`kernel_unlabeled_domtrans',` - gen_require(` - type unlabeled_t; - ') - - read_lnk_files_pattern($1, unlabeled_t, unlabeled_t) - domain_transition_pattern($1, unlabeled_t, $2) - type_transition $1 unlabeled_t:process $2; -') -interface(`files_write_all_pid_sockets',` - gen_require(` - attribute pidfile; - ') - - allow $1 pidfile:sock_file write_sock_file_perms; -') -interface(`dev_dontaudit_mounton_sysfs',` - gen_require(` - type sysfs_t; - ') - - dontaudit $1 sysfs_t:dir mounton; -') diff --git a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker.te b/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker.te deleted file mode 100644 index bad0bb6..0000000 --- a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker.te +++ /dev/null @@ -1,407 +0,0 @@ -policy_module(docker, 1.0.0) - -######################################## -# -# Declarations -# - -## -##

-## Determine whether docker can -## connect to all TCP ports. -##

-##
-gen_tunable(docker_connect_any, false) - -type docker_t; -type docker_exec_t; -init_daemon_domain(docker_t, docker_exec_t) -domain_subj_id_change_exemption(docker_t) -domain_role_change_exemption(docker_t) - -type spc_t; -domain_type(spc_t) -role system_r types spc_t; - -type spc_var_run_t; -files_pid_file(spc_var_run_t) - -type docker_var_lib_t; -files_type(docker_var_lib_t) - -type docker_home_t; -userdom_user_home_content(docker_home_t) - -type docker_config_t; -files_config_file(docker_config_t) - -type docker_lock_t; -files_lock_file(docker_lock_t) - -type docker_log_t; -logging_log_file(docker_log_t) - -type docker_tmp_t; -files_tmp_file(docker_tmp_t) - -type docker_tmpfs_t; -files_tmpfs_file(docker_tmpfs_t) - -type docker_var_run_t; -files_pid_file(docker_var_run_t) - -type docker_unit_file_t; -systemd_unit_file(docker_unit_file_t) - -type docker_devpts_t; -term_pty(docker_devpts_t) - -type docker_share_t; -files_type(docker_share_t) - -######################################## -# -# docker local policy -# -allow docker_t self:capability { chown kill fowner fsetid mknod net_admin net_bind_service net_raw setfcap }; -allow docker_t self:tun_socket relabelto; -allow docker_t self:process { getattr signal_perms setrlimit setfscreate }; -allow docker_t self:fifo_file rw_fifo_file_perms; -allow docker_t self:unix_stream_socket create_stream_socket_perms; -allow docker_t self:tcp_socket create_stream_socket_perms; -allow docker_t self:udp_socket create_socket_perms; -allow docker_t self:capability2 block_suspend; - -manage_files_pattern(docker_t, docker_home_t, docker_home_t) -manage_dirs_pattern(docker_t, docker_home_t, docker_home_t) -manage_lnk_files_pattern(docker_t, docker_home_t, docker_home_t) -userdom_admin_home_dir_filetrans(docker_t, docker_home_t, dir, ".docker") - -manage_dirs_pattern(docker_t, docker_config_t, docker_config_t) -manage_files_pattern(docker_t, docker_config_t, docker_config_t) -files_etc_filetrans(docker_t, docker_config_t, dir, "docker") - -manage_dirs_pattern(docker_t, docker_lock_t, docker_lock_t) -manage_files_pattern(docker_t, docker_lock_t, docker_lock_t) - -manage_dirs_pattern(docker_t, docker_log_t, docker_log_t) -manage_files_pattern(docker_t, docker_log_t, docker_log_t) -manage_lnk_files_pattern(docker_t, docker_log_t, docker_log_t) -logging_log_filetrans(docker_t, docker_log_t, { dir file lnk_file }) -allow docker_t docker_log_t:dir_file_class_set { relabelfrom relabelto }; - -manage_dirs_pattern(docker_t, docker_tmp_t, docker_tmp_t) -manage_files_pattern(docker_t, docker_tmp_t, docker_tmp_t) -manage_lnk_files_pattern(docker_t, docker_tmp_t, docker_tmp_t) -files_tmp_filetrans(docker_t, docker_tmp_t, { dir file lnk_file }) - -manage_dirs_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_lnk_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_fifo_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_chr_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -manage_blk_files_pattern(docker_t, docker_tmpfs_t, docker_tmpfs_t) -allow docker_t docker_tmpfs_t:dir relabelfrom; -can_exec(docker_t, docker_tmpfs_t) -fs_tmpfs_filetrans(docker_t, docker_tmpfs_t, { dir file }) -allow docker_t docker_tmpfs_t:chr_file mounton; - -manage_dirs_pattern(docker_t, docker_share_t, docker_share_t) -manage_files_pattern(docker_t, docker_share_t, docker_share_t) -manage_lnk_files_pattern(docker_t, docker_share_t, docker_share_t) -allow docker_t docker_share_t:dir_file_class_set { relabelfrom relabelto }; - -can_exec(docker_t, docker_share_t) -#docker_filetrans_named_content(docker_t) - -manage_dirs_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_chr_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_blk_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -manage_lnk_files_pattern(docker_t, docker_var_lib_t, docker_var_lib_t) -allow docker_t docker_var_lib_t:dir_file_class_set { relabelfrom relabelto }; -files_var_lib_filetrans(docker_t, docker_var_lib_t, { dir file lnk_file }) - -manage_dirs_pattern(docker_t, docker_var_run_t, docker_var_run_t) -manage_files_pattern(docker_t, docker_var_run_t, docker_var_run_t) -manage_sock_files_pattern(docker_t, docker_var_run_t, docker_var_run_t) -manage_lnk_files_pattern(docker_t, docker_var_run_t, docker_var_run_t) -files_pid_filetrans(docker_t, docker_var_run_t, { dir file lnk_file sock_file }) - -allow docker_t docker_devpts_t:chr_file { relabelfrom rw_chr_file_perms setattr_chr_file_perms }; -term_create_pty(docker_t, docker_devpts_t) - -kernel_read_system_state(docker_t) -kernel_read_network_state(docker_t) -kernel_read_all_sysctls(docker_t) -kernel_rw_net_sysctls(docker_t) -kernel_setsched(docker_t) -kernel_read_all_proc(docker_t) - -domain_use_interactive_fds(docker_t) -domain_dontaudit_read_all_domains_state(docker_t) - -corecmd_exec_bin(docker_t) -corecmd_exec_shell(docker_t) - -corenet_tcp_bind_generic_node(docker_t) -corenet_tcp_sendrecv_generic_if(docker_t) -corenet_tcp_sendrecv_generic_node(docker_t) -corenet_tcp_sendrecv_generic_port(docker_t) -corenet_tcp_bind_all_ports(docker_t) -corenet_tcp_connect_http_port(docker_t) -corenet_tcp_connect_commplex_main_port(docker_t) -corenet_udp_sendrecv_generic_if(docker_t) -corenet_udp_sendrecv_generic_node(docker_t) -corenet_udp_sendrecv_all_ports(docker_t) -corenet_udp_bind_generic_node(docker_t) -corenet_udp_bind_all_ports(docker_t) - -files_read_config_files(docker_t) -files_dontaudit_getattr_all_dirs(docker_t) -files_dontaudit_getattr_all_files(docker_t) - -fs_read_cgroup_files(docker_t) -fs_read_tmpfs_symlinks(docker_t) -fs_search_all(docker_t) -fs_getattr_all_fs(docker_t) - -storage_raw_rw_fixed_disk(docker_t) - -auth_use_nsswitch(docker_t) -auth_dontaudit_getattr_shadow(docker_t) - -init_read_state(docker_t) -init_status(docker_t) - -logging_send_audit_msgs(docker_t) -logging_send_syslog_msg(docker_t) - -miscfiles_read_localization(docker_t) - -mount_domtrans(docker_t) - -seutil_read_default_contexts(docker_t) -seutil_read_config(docker_t) - -sysnet_dns_name_resolve(docker_t) -sysnet_exec_ifconfig(docker_t) - -optional_policy(` - rpm_exec(docker_t) - rpm_read_db(docker_t) - rpm_exec(docker_t) -') - -optional_policy(` - fstools_domtrans(docker_t) -') - -optional_policy(` - iptables_domtrans(docker_t) -') - -optional_policy(` - openvswitch_stream_connect(docker_t) -') - -allow docker_t self:capability { dac_override setgid setpcap setuid sys_admin sys_boot sys_chroot sys_ptrace }; - -allow docker_t self:process { getcap setcap setexec setpgid setsched signal_perms }; - -allow docker_t self:netlink_route_socket rw_netlink_socket_perms;; -allow docker_t self:netlink_audit_socket create_netlink_socket_perms; -allow docker_t self:unix_dgram_socket { create_socket_perms sendto }; -allow docker_t self:unix_stream_socket { create_stream_socket_perms connectto }; - -allow docker_t docker_var_lib_t:dir mounton; -allow docker_t docker_var_lib_t:chr_file mounton; -can_exec(docker_t, docker_var_lib_t) - -kernel_dontaudit_setsched(docker_t) -kernel_get_sysvipc_info(docker_t) -kernel_request_load_module(docker_t) -kernel_mounton_messages(docker_t) -kernel_mounton_all_proc(docker_t) -kernel_mounton_all_sysctls(docker_t) -kernel_unlabeled_entry_type(spc_t) -kernel_unlabeled_domtrans(docker_t, spc_t) - -dev_getattr_all(docker_t) -dev_getattr_sysfs_fs(docker_t) -dev_read_urand(docker_t) -dev_read_lvm_control(docker_t) -dev_rw_sysfs(docker_t) -dev_rw_loop_control(docker_t) -dev_rw_lvm_control(docker_t) - -files_getattr_isid_type_dirs(docker_t) -files_manage_isid_type_dirs(docker_t) -files_manage_isid_type_files(docker_t) -files_manage_isid_type_symlinks(docker_t) -files_manage_isid_type_chr_files(docker_t) -files_manage_isid_type_blk_files(docker_t) -files_exec_isid_files(docker_t) -files_mounton_isid(docker_t) -files_mounton_non_security(docker_t) -files_mounton_isid_type_chr_file(docker_t) - -fs_mount_all_fs(docker_t) -fs_unmount_all_fs(docker_t) -fs_remount_all_fs(docker_t) -files_mounton_isid(docker_t) -fs_manage_cgroup_dirs(docker_t) -fs_manage_cgroup_files(docker_t) -fs_relabelfrom_xattr_fs(docker_t) -fs_relabelfrom_tmpfs(docker_t) -fs_read_tmpfs_symlinks(docker_t) -fs_list_hugetlbfs(docker_t) - -term_use_generic_ptys(docker_t) -term_use_ptmx(docker_t) -term_getattr_pty_fs(docker_t) -term_relabel_pty_fs(docker_t) -term_mounton_unallocated_ttys(docker_t) - -modutils_domtrans_insmod(docker_t) - -systemd_status_all_unit_files(docker_t) -systemd_start_systemd_services(docker_t) - -userdom_stream_connect(docker_t) -userdom_search_user_home_content(docker_t) -userdom_read_all_users_state(docker_t) -userdom_relabel_user_home_files(docker_t) -userdom_relabel_user_tmp_files(docker_t) -userdom_relabel_user_tmp_dirs(docker_t) - -optional_policy(` - gpm_getattr_gpmctl(docker_t) -') - -optional_policy(` - dbus_system_bus_client(docker_t) - init_dbus_chat(docker_t) - init_start_transient_unit(docker_t) - - optional_policy(` - systemd_dbus_chat_logind(docker_t) - ') - - optional_policy(` - firewalld_dbus_chat(docker_t) - ') -') - -optional_policy(` - udev_read_db(docker_t) -') - -optional_policy(` - virt_read_config(docker_t) - virt_exec(docker_t) - virt_stream_connect(docker_t) - virt_stream_connect_sandbox(docker_t) - virt_exec_sandbox_files(docker_t) - virt_manage_sandbox_files(docker_t) - virt_relabel_sandbox_filesystem(docker_t) - virt_transition_svirt_sandbox(docker_t, system_r) - virt_mounton_sandbox_file(docker_t) -# virt_attach_sandbox_tun_iface(docker_t) - allow docker_t svirt_sandbox_domain:tun_socket relabelfrom; -') - -tunable_policy(`docker_connect_any',` - corenet_tcp_connect_all_ports(docker_t) - corenet_sendrecv_all_packets(docker_t) - corenet_tcp_sendrecv_all_ports(docker_t) -') - -######################################## -# -# spc local policy -# -domain_entry_file(spc_t, docker_share_t) -domain_entry_file(spc_t, docker_var_lib_t) -role system_r types spc_t; - -domain_entry_file(spc_t, docker_share_t) -domain_entry_file(spc_t, docker_var_lib_t) -domtrans_pattern(docker_t, docker_share_t, spc_t) -domtrans_pattern(docker_t, docker_var_lib_t, spc_t) -allow docker_t spc_t:process { setsched signal_perms }; -ps_process_pattern(docker_t, spc_t) -allow docker_t spc_t:socket_class_set { relabelto relabelfrom }; - -optional_policy(` - dbus_chat_system_bus(spc_t) -') - -optional_policy(` - unconfined_domain_noaudit(spc_t) -') - -optional_policy(` - unconfined_domain(docker_t) -') - -optional_policy(` - virt_transition_svirt_sandbox(spc_t, system_r) -') - -######################################## -# -# docker upstream policy -# - -optional_policy(` -# domain_stub_named_filetrans_domain() - gen_require(` - attribute named_filetrans_domain; - ') - - docker_filetrans_named_content(named_filetrans_domain) -') - -optional_policy(` - lvm_stub() - docker_rw_sem(lvm_t) -') - -optional_policy(` - staff_stub() - docker_stream_connect(staff_t) - docker_exec(staff_t) -') - -optional_policy(` - virt_stub_svirt_sandbox_domain() - virt_stub_svirt_sandbox_file() - allow svirt_sandbox_domain self:netlink_kobject_uevent_socket create_socket_perms; - docker_read_share_files(svirt_sandbox_domain) - docker_lib_filetrans(svirt_sandbox_domain,svirt_sandbox_file_t, sock_file) - docker_use_ptys(svirt_sandbox_domain) - docker_spc_stream_connect(svirt_sandbox_domain) - fs_list_tmpfs(svirt_sandbox_domain) - fs_rw_hugetlbfs_files(svirt_sandbox_domain) - fs_dontaudit_remount_tmpfs(svirt_sandbox_domain) - dev_dontaudit_mounton_sysfs(svirt_sandbox_domain) - - tunable_policy(`virt_sandbox_use_fusefs',` - fs_manage_fusefs_dirs(svirt_sandbox_domain) - fs_manage_fusefs_files(svirt_sandbox_domain) - fs_manage_fusefs_symlinks(svirt_sandbox_domain) - ') - gen_require(` - attribute domain; - ') - - dontaudit svirt_sandbox_domain domain:key {search link}; -') - -optional_policy(` - gen_require(` - type pcp_pmcd_t; - ') - docker_manage_lib_files(pcp_pmcd_t) -') diff --git a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker_selinux.8.gz b/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker_selinux.8.gz deleted file mode 100644 index ab5d594..0000000 Binary files a/vendor/github.com/docker/docker/contrib/selinux/docker-engine-selinux/docker_selinux.8.gz and /dev/null differ diff --git a/vendor/github.com/docker/docker/contrib/syntax/nano/Dockerfile.nanorc b/vendor/github.com/docker/docker/contrib/syntax/nano/Dockerfile.nanorc deleted file mode 100644 index 8b63dae..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/nano/Dockerfile.nanorc +++ /dev/null @@ -1,26 +0,0 @@ -## Syntax highlighting for Dockerfiles -syntax "Dockerfile" "Dockerfile[^/]*$" - -## Keywords -icolor red "^(ONBUILD\s+)?(ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)[[:space:]]" - -## Brackets & parenthesis -color brightgreen "(\(|\)|\[|\])" - -## Double ampersand -color brightmagenta "&&" - -## Comments -icolor cyan "^[[:space:]]*#.*$" - -## Blank space at EOL -color ,green "[[:space:]]+$" - -## Strings, single-quoted -color brightwhite "'([^']|(\\'))*'" "%[qw]\{[^}]*\}" "%[qw]\([^)]*\)" "%[qw]<[^>]*>" "%[qw]\[[^]]*\]" "%[qw]\$[^$]*\$" "%[qw]\^[^^]*\^" "%[qw]![^!]*!" - -## Strings, double-quoted -color brightwhite ""([^"]|(\\"))*"" "%[QW]?\{[^}]*\}" "%[QW]?\([^)]*\)" "%[QW]?<[^>]*>" "%[QW]?\[[^]]*\]" "%[QW]?\$[^$]*\$" "%[QW]?\^[^^]*\^" "%[QW]?![^!]*!" - -## Single and double quotes -color brightyellow "('|\")" diff --git a/vendor/github.com/docker/docker/contrib/syntax/nano/README.md b/vendor/github.com/docker/docker/contrib/syntax/nano/README.md deleted file mode 100644 index 5985208..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/nano/README.md +++ /dev/null @@ -1,32 +0,0 @@ -Dockerfile.nanorc -================= - -Dockerfile syntax highlighting for nano - -Single User Installation ------------------------- -1. Create a nano syntax directory in your home directory: - * `mkdir -p ~/.nano/syntax` - -2. Copy `Dockerfile.nanorc` to` ~/.nano/syntax/` - * `cp Dockerfile.nanorc ~/.nano/syntax/` - -3. Add the following to your `~/.nanorc` to tell nano where to find the `Dockerfile.nanorc` file - ``` -## Dockerfile files -include "~/.nano/syntax/Dockerfile.nanorc" - ``` - -System Wide Installation ------------------------- -1. Create a nano syntax directory: - * `mkdir /usr/local/share/nano` - -2. Copy `Dockerfile.nanorc` to `/usr/local/share/nano` - * `cp Dockerfile.nanorc /usr/local/share/nano/` - -3. Add the following to your `/etc/nanorc`: - ``` -## Dockerfile files -include "/usr/local/share/nano/Dockerfile.nanorc" - ``` diff --git a/vendor/github.com/docker/docker/contrib/syntax/textmate/Docker.tmbundle/Preferences/Dockerfile.tmPreferences b/vendor/github.com/docker/docker/contrib/syntax/textmate/Docker.tmbundle/Preferences/Dockerfile.tmPreferences deleted file mode 100644 index 20f0d04..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/textmate/Docker.tmbundle/Preferences/Dockerfile.tmPreferences +++ /dev/null @@ -1,24 +0,0 @@ - - - - - name - Comments - scope - source.dockerfile - settings - - shellVariables - - - name - TM_COMMENT_START - value - # - - - - uuid - 2B215AC0-A7F3-4090-9FF6-F4842BD56CA7 - - diff --git a/vendor/github.com/docker/docker/contrib/syntax/textmate/Docker.tmbundle/Syntaxes/Dockerfile.tmLanguage b/vendor/github.com/docker/docker/contrib/syntax/textmate/Docker.tmbundle/Syntaxes/Dockerfile.tmLanguage deleted file mode 100644 index 948a9bf..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/textmate/Docker.tmbundle/Syntaxes/Dockerfile.tmLanguage +++ /dev/null @@ -1,143 +0,0 @@ - - - - - fileTypes - - Dockerfile - - name - Dockerfile - patterns - - - captures - - 1 - - name - keyword.control.dockerfile - - 2 - - name - keyword.other.special-method.dockerfile - - - match - ^\s*(?:(ONBUILD)\s+)?(ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)\s - - - captures - - 1 - - name - keyword.operator.dockerfile - - 2 - - name - keyword.other.special-method.dockerfile - - - match - ^\s*(?:(ONBUILD)\s+)?(CMD|ENTRYPOINT)\s - - - begin - " - beginCaptures - - 1 - - name - punctuation.definition.string.begin.dockerfile - - - end - " - endCaptures - - 1 - - name - punctuation.definition.string.end.dockerfile - - - name - string.quoted.double.dockerfile - patterns - - - match - \\. - name - constant.character.escaped.dockerfile - - - - - begin - ' - beginCaptures - - 1 - - name - punctuation.definition.string.begin.dockerfile - - - end - ' - endCaptures - - 1 - - name - punctuation.definition.string.end.dockerfile - - - name - string.quoted.single.dockerfile - patterns - - - match - \\. - name - constant.character.escaped.dockerfile - - - - - captures - - 1 - - name - punctuation.whitespace.comment.leading.dockerfile - - 2 - - name - comment.line.number-sign.dockerfile - - 3 - - name - punctuation.definition.comment.dockerfile - - - comment - comment.line - match - ^(\s*)((#).*$\n?) - - - scopeName - source.dockerfile - uuid - a39d8795-59d2-49af-aa00-fe74ee29576e - - diff --git a/vendor/github.com/docker/docker/contrib/syntax/textmate/Docker.tmbundle/info.plist b/vendor/github.com/docker/docker/contrib/syntax/textmate/Docker.tmbundle/info.plist deleted file mode 100644 index 239f4b0..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/textmate/Docker.tmbundle/info.plist +++ /dev/null @@ -1,16 +0,0 @@ - - - - - contactEmailRot13 - germ@andz.com.ar - contactName - GermanDZ - description - Helpers for Docker. - name - Docker - uuid - 8B9DDBAF-E65C-4E12-FFA7-467D4AA535B1 - - diff --git a/vendor/github.com/docker/docker/contrib/syntax/textmate/README.md b/vendor/github.com/docker/docker/contrib/syntax/textmate/README.md deleted file mode 100644 index ce61101..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/textmate/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Docker.tmbundle - -Dockerfile syntax highlighting for TextMate and Sublime Text. - -## Install - -### Sublime Text - -Available for Sublime Text under [package control](https://sublime.wbond.net/packages/Dockerfile%20Syntax%20Highlighting). -Search for *Dockerfile Syntax Highlighting* - -### TextMate 2 - -You can install this bundle in TextMate by opening the preferences and going to the bundles tab. After installation it will be automatically updated for you. - -enjoy. - diff --git a/vendor/github.com/docker/docker/contrib/syntax/textmate/REVIEWERS b/vendor/github.com/docker/docker/contrib/syntax/textmate/REVIEWERS deleted file mode 100644 index 965743d..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/textmate/REVIEWERS +++ /dev/null @@ -1 +0,0 @@ -Asbjorn Enge (@asbjornenge) diff --git a/vendor/github.com/docker/docker/contrib/syntax/vim/LICENSE b/vendor/github.com/docker/docker/contrib/syntax/vim/LICENSE deleted file mode 100644 index e67cdab..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/vim/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2013 Honza Pokorny -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/docker/docker/contrib/syntax/vim/README.md b/vendor/github.com/docker/docker/contrib/syntax/vim/README.md deleted file mode 100644 index 5aa9bd8..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/vim/README.md +++ /dev/null @@ -1,26 +0,0 @@ -dockerfile.vim -============== - -Syntax highlighting for Dockerfiles - -Installation ------------- -With [pathogen](https://github.com/tpope/vim-pathogen), the usual way... - -With [Vundle](https://github.com/gmarik/Vundle.vim) - - Plugin 'docker/docker' , {'rtp': '/contrib/syntax/vim/'} - -Features --------- - -The syntax highlighting includes: - -* The directives (e.g. `FROM`) -* Strings -* Comments - -License -------- - -BSD, short and sweet diff --git a/vendor/github.com/docker/docker/contrib/syntax/vim/doc/dockerfile.txt b/vendor/github.com/docker/docker/contrib/syntax/vim/doc/dockerfile.txt deleted file mode 100644 index e69e2b7..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/vim/doc/dockerfile.txt +++ /dev/null @@ -1,18 +0,0 @@ -*dockerfile.txt* Syntax highlighting for Dockerfiles - -Author: Honza Pokorny -License: BSD - -INSTALLATION *installation* - -Drop it on your Pathogen path and you're all set. - -FEATURES *features* - -The syntax highlighting includes: - -* The directives (e.g. FROM) -* Strings -* Comments - - vim:tw=78:et:ft=help:norl: diff --git a/vendor/github.com/docker/docker/contrib/syntax/vim/ftdetect/dockerfile.vim b/vendor/github.com/docker/docker/contrib/syntax/vim/ftdetect/dockerfile.vim deleted file mode 100644 index ee10e5d..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/vim/ftdetect/dockerfile.vim +++ /dev/null @@ -1 +0,0 @@ -au BufNewFile,BufRead [Dd]ockerfile,Dockerfile.* set filetype=dockerfile diff --git a/vendor/github.com/docker/docker/contrib/syntax/vim/syntax/dockerfile.vim b/vendor/github.com/docker/docker/contrib/syntax/vim/syntax/dockerfile.vim deleted file mode 100644 index a067e6a..0000000 --- a/vendor/github.com/docker/docker/contrib/syntax/vim/syntax/dockerfile.vim +++ /dev/null @@ -1,31 +0,0 @@ -" dockerfile.vim - Syntax highlighting for Dockerfiles -" Maintainer: Honza Pokorny -" Version: 0.5 - - -if exists("b:current_syntax") - finish -endif - -let b:current_syntax = "dockerfile" - -syntax case ignore - -syntax match dockerfileKeyword /\v^\s*(ONBUILD\s+)?(ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)\s/ -highlight link dockerfileKeyword Keyword - -syntax region dockerfileString start=/\v"/ skip=/\v\\./ end=/\v"/ -highlight link dockerfileString String - -syntax match dockerfileComment "\v^\s*#.*$" -highlight link dockerfileComment Comment - -set commentstring=#\ %s - -" match "RUN", "CMD", and "ENTRYPOINT" lines, and parse them as shell -let s:current_syntax = b:current_syntax -unlet b:current_syntax -syntax include @SH syntax/sh.vim -let b:current_syntax = s:current_syntax -syntax region shLine matchgroup=dockerfileKeyword start=/\v^\s*(RUN|CMD|ENTRYPOINT)\s/ end=/\v$/ contains=@SH -" since @SH will handle "\" as part of the same line automatically, this "just works" for line continuation too, but with the caveat that it will highlight "RUN echo '" followed by a newline as if it were a block because the "'" is shell line continuation... not sure how to fix that just yet (TODO) diff --git a/vendor/github.com/docker/docker/contrib/syscall-test/Dockerfile b/vendor/github.com/docker/docker/contrib/syscall-test/Dockerfile deleted file mode 100644 index f95f175..0000000 --- a/vendor/github.com/docker/docker/contrib/syscall-test/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM buildpack-deps:jessie - -COPY . /usr/src/ - -WORKDIR /usr/src/ - -RUN gcc -g -Wall -static userns.c -o /usr/bin/userns-test \ - && gcc -g -Wall -static ns.c -o /usr/bin/ns-test \ - && gcc -g -Wall -static acct.c -o /usr/bin/acct-test \ - && gcc -g -Wall -static setuid.c -o /usr/bin/setuid-test \ - && gcc -g -Wall -static setgid.c -o /usr/bin/setgid-test \ - && gcc -g -Wall -static socket.c -o /usr/bin/socket-test \ - && gcc -g -Wall -static raw.c -o /usr/bin/raw-test - -RUN [ "$(uname -m)" = "x86_64" ] && gcc -s -m32 -nostdlib exit32.s -o /usr/bin/exit32-test || true diff --git a/vendor/github.com/docker/docker/contrib/syscall-test/acct.c b/vendor/github.com/docker/docker/contrib/syscall-test/acct.c deleted file mode 100644 index 88ac287..0000000 --- a/vendor/github.com/docker/docker/contrib/syscall-test/acct.c +++ /dev/null @@ -1,16 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int err = acct("/tmp/t"); - if (err == -1) { - fprintf(stderr, "acct failed: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - exit(EXIT_SUCCESS); -} diff --git a/vendor/github.com/docker/docker/contrib/syscall-test/exit32.s b/vendor/github.com/docker/docker/contrib/syscall-test/exit32.s deleted file mode 100644 index 8bbb5c5..0000000 --- a/vendor/github.com/docker/docker/contrib/syscall-test/exit32.s +++ /dev/null @@ -1,7 +0,0 @@ -.globl _start -.text -_start: - xorl %eax, %eax - incl %eax - movb $0, %bl - int $0x80 diff --git a/vendor/github.com/docker/docker/contrib/syscall-test/ns.c b/vendor/github.com/docker/docker/contrib/syscall-test/ns.c deleted file mode 100644 index 33684e1..0000000 --- a/vendor/github.com/docker/docker/contrib/syscall-test/ns.c +++ /dev/null @@ -1,63 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STACK_SIZE (1024 * 1024) /* Stack size for cloned child */ - -struct clone_args { - char **argv; -}; - -// child_exec is the func that will be executed as the result of clone -static int child_exec(void *stuff) -{ - struct clone_args *args = (struct clone_args *)stuff; - if (execvp(args->argv[0], args->argv) != 0) { - fprintf(stderr, "failed to execvp argments %s\n", - strerror(errno)); - exit(-1); - } - // we should never reach here! - exit(EXIT_FAILURE); -} - -int main(int argc, char **argv) -{ - struct clone_args args; - args.argv = &argv[1]; - - int clone_flags = CLONE_NEWNS | CLONE_NEWPID | SIGCHLD; - - // allocate stack for child - char *stack; /* Start of stack buffer */ - char *child_stack; /* End of stack buffer */ - stack = - mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANON | MAP_STACK, -1, 0); - if (stack == MAP_FAILED) { - fprintf(stderr, "mmap failed: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - child_stack = stack + STACK_SIZE; /* Assume stack grows downward */ - - // the result of this call is that our child_exec will be run in another - // process returning its pid - pid_t pid = clone(child_exec, child_stack, clone_flags, &args); - if (pid < 0) { - fprintf(stderr, "clone failed: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - // lets wait on our child process here before we, the parent, exits - if (waitpid(pid, NULL, 0) == -1) { - fprintf(stderr, "failed to wait pid %d\n", pid); - exit(EXIT_FAILURE); - } - exit(EXIT_SUCCESS); -} diff --git a/vendor/github.com/docker/docker/contrib/syscall-test/raw.c b/vendor/github.com/docker/docker/contrib/syscall-test/raw.c deleted file mode 100644 index 7995a0d..0000000 --- a/vendor/github.com/docker/docker/contrib/syscall-test/raw.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include -#include -#include - -int main() { - if (socket(PF_INET, SOCK_RAW, IPPROTO_UDP) == -1) { - perror("socket"); - return 1; - } - - return 0; -} diff --git a/vendor/github.com/docker/docker/contrib/syscall-test/setgid.c b/vendor/github.com/docker/docker/contrib/syscall-test/setgid.c deleted file mode 100644 index df9680c..0000000 --- a/vendor/github.com/docker/docker/contrib/syscall-test/setgid.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include - -int main() { - if (setgid(1) == -1) { - perror("setgid"); - return 1; - } - return 0; -} diff --git a/vendor/github.com/docker/docker/contrib/syscall-test/setuid.c b/vendor/github.com/docker/docker/contrib/syscall-test/setuid.c deleted file mode 100644 index 5b93967..0000000 --- a/vendor/github.com/docker/docker/contrib/syscall-test/setuid.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include - -int main() { - if (setuid(1) == -1) { - perror("setuid"); - return 1; - } - return 0; -} diff --git a/vendor/github.com/docker/docker/contrib/syscall-test/socket.c b/vendor/github.com/docker/docker/contrib/syscall-test/socket.c deleted file mode 100644 index d26c82f..0000000 --- a/vendor/github.com/docker/docker/contrib/syscall-test/socket.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include -#include -#include -#include - -int main() { - int s; - struct sockaddr_in sin; - - s = socket(AF_INET, SOCK_STREAM, 0); - if (s == -1) { - perror("socket"); - return 1; - } - - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = INADDR_ANY; - sin.sin_port = htons(80); - - if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) == -1) { - perror("bind"); - return 1; - } - - close(s); - - return 0; -} diff --git a/vendor/github.com/docker/docker/contrib/syscall-test/userns.c b/vendor/github.com/docker/docker/contrib/syscall-test/userns.c deleted file mode 100644 index 2af36f4..0000000 --- a/vendor/github.com/docker/docker/contrib/syscall-test/userns.c +++ /dev/null @@ -1,63 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define STACK_SIZE (1024 * 1024) /* Stack size for cloned child */ - -struct clone_args { - char **argv; -}; - -// child_exec is the func that will be executed as the result of clone -static int child_exec(void *stuff) -{ - struct clone_args *args = (struct clone_args *)stuff; - if (execvp(args->argv[0], args->argv) != 0) { - fprintf(stderr, "failed to execvp argments %s\n", - strerror(errno)); - exit(-1); - } - // we should never reach here! - exit(EXIT_FAILURE); -} - -int main(int argc, char **argv) -{ - struct clone_args args; - args.argv = &argv[1]; - - int clone_flags = CLONE_NEWUSER | SIGCHLD; - - // allocate stack for child - char *stack; /* Start of stack buffer */ - char *child_stack; /* End of stack buffer */ - stack = - mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANON | MAP_STACK, -1, 0); - if (stack == MAP_FAILED) { - fprintf(stderr, "mmap failed: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - child_stack = stack + STACK_SIZE; /* Assume stack grows downward */ - - // the result of this call is that our child_exec will be run in another - // process returning its pid - pid_t pid = clone(child_exec, child_stack, clone_flags, &args); - if (pid < 0) { - fprintf(stderr, "clone failed: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - // lets wait on our child process here before we, the parent, exits - if (waitpid(pid, NULL, 0) == -1) { - fprintf(stderr, "failed to wait pid %d\n", pid); - exit(EXIT_FAILURE); - } - exit(EXIT_SUCCESS); -} diff --git a/vendor/github.com/docker/docker/contrib/udev/80-docker.rules b/vendor/github.com/docker/docker/contrib/udev/80-docker.rules deleted file mode 100644 index f934c01..0000000 --- a/vendor/github.com/docker/docker/contrib/udev/80-docker.rules +++ /dev/null @@ -1,3 +0,0 @@ -# hide docker's loopback devices from udisks, and thus from user desktops -SUBSYSTEM=="block", ENV{DM_NAME}=="docker-*", ENV{UDISKS_PRESENTATION_HIDE}="1", ENV{UDISKS_IGNORE}="1" -SUBSYSTEM=="block", DEVPATH=="/devices/virtual/block/loop*", ATTR{loop/backing_file}=="/var/lib/docker/*", ENV{UDISKS_PRESENTATION_HIDE}="1", ENV{UDISKS_IGNORE}="1" diff --git a/vendor/github.com/docker/docker/contrib/vagrant-docker/README.md b/vendor/github.com/docker/docker/contrib/vagrant-docker/README.md deleted file mode 100644 index 286a985..0000000 --- a/vendor/github.com/docker/docker/contrib/vagrant-docker/README.md +++ /dev/null @@ -1,50 +0,0 @@ -# Vagrant integration - -Currently there are at least 4 different projects that we are aware of that deals -with integration with [Vagrant](http://vagrantup.com/) at different levels. One -approach is to use Docker as a [provisioner](http://docs.vagrantup.com/v2/provisioning/index.html) -which means you can create containers and pull base images on VMs using Docker's -CLI and the other is to use Docker as a [provider](http://docs.vagrantup.com/v2/providers/index.html), -meaning you can use Vagrant to control Docker containers. - - -### Provisioners - -* [Vocker](https://github.com/fgrehm/vocker) -* [Ventriloquist](https://github.com/fgrehm/ventriloquist) - -### Providers - -* [docker-provider](https://github.com/fgrehm/docker-provider) -* [vagrant-shell](https://github.com/destructuring/vagrant-shell) - -## Setting up Vagrant-docker with the Engine API - -The initial Docker upstart script will not work because it runs on `127.0.0.1`, which is not accessible to the host machine. Instead, we need to change the script to connect to `0.0.0.0`. To do this, modify `/etc/init/docker.conf` to look like this: - -``` -description "Docker daemon" - -start on filesystem -stop on runlevel [!2345] - -respawn - -script - /usr/bin/docker daemon -H=tcp://0.0.0.0:2375 -end script -``` - -Once that's done, you need to set up a SSH tunnel between your host machine and the vagrant machine that's running Docker. This can be done by running the following command in a host terminal: - -``` -ssh -L 2375:localhost:2375 -p 2222 vagrant@localhost -``` - -(The first 2375 is what your host can connect to, the second 2375 is what port Docker is running on in the vagrant machine, and the 2222 is the port Vagrant is providing for SSH. If VirtualBox is the VM you're using, you can see what value "2222" should be by going to: Network > Adapter 1 > Advanced > Port Forwarding in the VirtualBox GUI.) - -Note that because the port has been changed, to run docker commands from within the command line you must run them like this: - -``` -sudo docker -H 0.0.0.0:2375 < commands for docker > -``` diff --git a/vendor/github.com/docker/docker/daemon/apparmor_default.go b/vendor/github.com/docker/docker/daemon/apparmor_default.go deleted file mode 100644 index 09dd054..0000000 --- a/vendor/github.com/docker/docker/daemon/apparmor_default.go +++ /dev/null @@ -1,36 +0,0 @@ -// +build linux - -package daemon - -import ( - "fmt" - - aaprofile "github.com/docker/docker/profiles/apparmor" - "github.com/opencontainers/runc/libcontainer/apparmor" -) - -// Define constants for native driver -const ( - defaultApparmorProfile = "docker-default" -) - -func ensureDefaultAppArmorProfile() error { - if apparmor.IsEnabled() { - loaded, err := aaprofile.IsLoaded(defaultApparmorProfile) - if err != nil { - return fmt.Errorf("Could not check if %s AppArmor profile was loaded: %s", defaultApparmorProfile, err) - } - - // Nothing to do. - if loaded { - return nil - } - - // Load the profile. - if err := aaprofile.InstallDefault(defaultApparmorProfile); err != nil { - return fmt.Errorf("AppArmor enabled on system but the %s profile could not be loaded.", defaultApparmorProfile) - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/apparmor_default_unsupported.go b/vendor/github.com/docker/docker/daemon/apparmor_default_unsupported.go deleted file mode 100644 index cd2dd97..0000000 --- a/vendor/github.com/docker/docker/daemon/apparmor_default_unsupported.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build !linux - -package daemon - -func ensureDefaultAppArmorProfile() error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/archive.go b/vendor/github.com/docker/docker/daemon/archive.go deleted file mode 100644 index 1999f12..0000000 --- a/vendor/github.com/docker/docker/daemon/archive.go +++ /dev/null @@ -1,436 +0,0 @@ -package daemon - -import ( - "errors" - "io" - "os" - "path/filepath" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/builder" - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/chrootarchive" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/system" -) - -// ErrExtractPointNotDirectory is used to convey that the operation to extract -// a tar archive to a directory in a container has failed because the specified -// path does not refer to a directory. -var ErrExtractPointNotDirectory = errors.New("extraction point is not a directory") - -// ContainerCopy performs a deprecated operation of archiving the resource at -// the specified path in the container identified by the given name. -func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, error) { - container, err := daemon.GetContainer(name) - if err != nil { - return nil, err - } - - if res[0] == '/' || res[0] == '\\' { - res = res[1:] - } - - return daemon.containerCopy(container, res) -} - -// ContainerStatPath stats the filesystem resource at the specified path in the -// container identified by the given name. -func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error) { - container, err := daemon.GetContainer(name) - if err != nil { - return nil, err - } - - return daemon.containerStatPath(container, path) -} - -// ContainerArchivePath creates an archive of the filesystem resource at the -// specified path in the container identified by the given name. Returns a -// tar archive of the resource and whether it was a directory or a single file. -func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error) { - container, err := daemon.GetContainer(name) - if err != nil { - return nil, nil, err - } - - return daemon.containerArchivePath(container, path) -} - -// ContainerExtractToDir extracts the given archive to the specified location -// in the filesystem of the container identified by the given name. The given -// path must be of a directory in the container. If it is not, the error will -// be ErrExtractPointNotDirectory. If noOverwriteDirNonDir is true then it will -// be an error if unpacking the given content would cause an existing directory -// to be replaced with a non-directory and vice versa. -func (daemon *Daemon) ContainerExtractToDir(name, path string, noOverwriteDirNonDir bool, content io.Reader) error { - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - return daemon.containerExtractToDir(container, path, noOverwriteDirNonDir, content) -} - -// containerStatPath stats the filesystem resource at the specified path in this -// container. Returns stat info about the resource. -func (daemon *Daemon) containerStatPath(container *container.Container, path string) (stat *types.ContainerPathStat, err error) { - container.Lock() - defer container.Unlock() - - if err = daemon.Mount(container); err != nil { - return nil, err - } - defer daemon.Unmount(container) - - err = daemon.mountVolumes(container) - defer container.DetachAndUnmount(daemon.LogVolumeEvent) - if err != nil { - return nil, err - } - - resolvedPath, absPath, err := container.ResolvePath(path) - if err != nil { - return nil, err - } - - return container.StatPath(resolvedPath, absPath) -} - -// containerArchivePath creates an archive of the filesystem resource at the specified -// path in this container. Returns a tar archive of the resource and stat info -// about the resource. -func (daemon *Daemon) containerArchivePath(container *container.Container, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error) { - container.Lock() - - defer func() { - if err != nil { - // Wait to unlock the container until the archive is fully read - // (see the ReadCloseWrapper func below) or if there is an error - // before that occurs. - container.Unlock() - } - }() - - if err = daemon.Mount(container); err != nil { - return nil, nil, err - } - - defer func() { - if err != nil { - // unmount any volumes - container.DetachAndUnmount(daemon.LogVolumeEvent) - // unmount the container's rootfs - daemon.Unmount(container) - } - }() - - if err = daemon.mountVolumes(container); err != nil { - return nil, nil, err - } - - resolvedPath, absPath, err := container.ResolvePath(path) - if err != nil { - return nil, nil, err - } - - stat, err = container.StatPath(resolvedPath, absPath) - if err != nil { - return nil, nil, err - } - - // We need to rebase the archive entries if the last element of the - // resolved path was a symlink that was evaluated and is now different - // than the requested path. For example, if the given path was "/foo/bar/", - // but it resolved to "/var/lib/docker/containers/{id}/foo/baz/", we want - // to ensure that the archive entries start with "bar" and not "baz". This - // also catches the case when the root directory of the container is - // requested: we want the archive entries to start with "/" and not the - // container ID. - data, err := archive.TarResourceRebase(resolvedPath, filepath.Base(absPath)) - if err != nil { - return nil, nil, err - } - - content = ioutils.NewReadCloserWrapper(data, func() error { - err := data.Close() - container.DetachAndUnmount(daemon.LogVolumeEvent) - daemon.Unmount(container) - container.Unlock() - return err - }) - - daemon.LogContainerEvent(container, "archive-path") - - return content, stat, nil -} - -// containerExtractToDir extracts the given tar archive to the specified location in the -// filesystem of this container. The given path must be of a directory in the -// container. If it is not, the error will be ErrExtractPointNotDirectory. If -// noOverwriteDirNonDir is true then it will be an error if unpacking the -// given content would cause an existing directory to be replaced with a non- -// directory and vice versa. -func (daemon *Daemon) containerExtractToDir(container *container.Container, path string, noOverwriteDirNonDir bool, content io.Reader) (err error) { - container.Lock() - defer container.Unlock() - - if err = daemon.Mount(container); err != nil { - return err - } - defer daemon.Unmount(container) - - err = daemon.mountVolumes(container) - defer container.DetachAndUnmount(daemon.LogVolumeEvent) - if err != nil { - return err - } - - // Check if a drive letter supplied, it must be the system drive. No-op except on Windows - path, err = system.CheckSystemDriveAndRemoveDriveLetter(path) - if err != nil { - return err - } - - // The destination path needs to be resolved to a host path, with all - // symbolic links followed in the scope of the container's rootfs. Note - // that we do not use `container.ResolvePath(path)` here because we need - // to also evaluate the last path element if it is a symlink. This is so - // that you can extract an archive to a symlink that points to a directory. - - // Consider the given path as an absolute path in the container. - absPath := archive.PreserveTrailingDotOrSeparator(filepath.Join(string(filepath.Separator), path), path) - - // This will evaluate the last path element if it is a symlink. - resolvedPath, err := container.GetResourcePath(absPath) - if err != nil { - return err - } - - stat, err := os.Lstat(resolvedPath) - if err != nil { - return err - } - - if !stat.IsDir() { - return ErrExtractPointNotDirectory - } - - // Need to check if the path is in a volume. If it is, it cannot be in a - // read-only volume. If it is not in a volume, the container cannot be - // configured with a read-only rootfs. - - // Use the resolved path relative to the container rootfs as the new - // absPath. This way we fully follow any symlinks in a volume that may - // lead back outside the volume. - // - // The Windows implementation of filepath.Rel in golang 1.4 does not - // support volume style file path semantics. On Windows when using the - // filter driver, we are guaranteed that the path will always be - // a volume file path. - var baseRel string - if strings.HasPrefix(resolvedPath, `\\?\Volume{`) { - if strings.HasPrefix(resolvedPath, container.BaseFS) { - baseRel = resolvedPath[len(container.BaseFS):] - if baseRel[:1] == `\` { - baseRel = baseRel[1:] - } - } - } else { - baseRel, err = filepath.Rel(container.BaseFS, resolvedPath) - } - if err != nil { - return err - } - // Make it an absolute path. - absPath = filepath.Join(string(filepath.Separator), baseRel) - - toVolume, err := checkIfPathIsInAVolume(container, absPath) - if err != nil { - return err - } - - if !toVolume && container.HostConfig.ReadonlyRootfs { - return ErrRootFSReadOnly - } - - uid, gid := daemon.GetRemappedUIDGID() - options := &archive.TarOptions{ - NoOverwriteDirNonDir: noOverwriteDirNonDir, - ChownOpts: &archive.TarChownOptions{ - UID: uid, GID: gid, // TODO: should all ownership be set to root (either real or remapped)? - }, - } - if err := chrootarchive.Untar(content, resolvedPath, options); err != nil { - return err - } - - daemon.LogContainerEvent(container, "extract-to-dir") - - return nil -} - -func (daemon *Daemon) containerCopy(container *container.Container, resource string) (rc io.ReadCloser, err error) { - container.Lock() - - defer func() { - if err != nil { - // Wait to unlock the container until the archive is fully read - // (see the ReadCloseWrapper func below) or if there is an error - // before that occurs. - container.Unlock() - } - }() - - if err := daemon.Mount(container); err != nil { - return nil, err - } - - defer func() { - if err != nil { - // unmount any volumes - container.DetachAndUnmount(daemon.LogVolumeEvent) - // unmount the container's rootfs - daemon.Unmount(container) - } - }() - - if err := daemon.mountVolumes(container); err != nil { - return nil, err - } - - basePath, err := container.GetResourcePath(resource) - if err != nil { - return nil, err - } - stat, err := os.Stat(basePath) - if err != nil { - return nil, err - } - var filter []string - if !stat.IsDir() { - d, f := filepath.Split(basePath) - basePath = d - filter = []string{f} - } else { - filter = []string{filepath.Base(basePath)} - basePath = filepath.Dir(basePath) - } - archive, err := archive.TarWithOptions(basePath, &archive.TarOptions{ - Compression: archive.Uncompressed, - IncludeFiles: filter, - }) - if err != nil { - return nil, err - } - - reader := ioutils.NewReadCloserWrapper(archive, func() error { - err := archive.Close() - container.DetachAndUnmount(daemon.LogVolumeEvent) - daemon.Unmount(container) - container.Unlock() - return err - }) - daemon.LogContainerEvent(container, "copy") - return reader, nil -} - -// CopyOnBuild copies/extracts a source FileInfo to a destination path inside a container -// specified by a container object. -// TODO: make sure callers don't unnecessarily convert destPath with filepath.FromSlash (Copy does it already). -// CopyOnBuild should take in abstract paths (with slashes) and the implementation should convert it to OS-specific paths. -func (daemon *Daemon) CopyOnBuild(cID string, destPath string, src builder.FileInfo, decompress bool) error { - srcPath := src.Path() - destExists := true - destDir := false - rootUID, rootGID := daemon.GetRemappedUIDGID() - - // Work in daemon-local OS specific file paths - destPath = filepath.FromSlash(destPath) - - c, err := daemon.GetContainer(cID) - if err != nil { - return err - } - err = daemon.Mount(c) - if err != nil { - return err - } - defer daemon.Unmount(c) - - dest, err := c.GetResourcePath(destPath) - if err != nil { - return err - } - - // Preserve the trailing slash - // TODO: why are we appending another path separator if there was already one? - if strings.HasSuffix(destPath, string(os.PathSeparator)) || destPath == "." { - destDir = true - dest += string(os.PathSeparator) - } - - destPath = dest - - destStat, err := os.Stat(destPath) - if err != nil { - if !os.IsNotExist(err) { - //logrus.Errorf("Error performing os.Stat on %s. %s", destPath, err) - return err - } - destExists = false - } - - uidMaps, gidMaps := daemon.GetUIDGIDMaps() - archiver := &archive.Archiver{ - Untar: chrootarchive.Untar, - UIDMaps: uidMaps, - GIDMaps: gidMaps, - } - - if src.IsDir() { - // copy as directory - if err := archiver.CopyWithTar(srcPath, destPath); err != nil { - return err - } - return fixPermissions(srcPath, destPath, rootUID, rootGID, destExists) - } - if decompress && archive.IsArchivePath(srcPath) { - // Only try to untar if it is a file and that we've been told to decompress (when ADD-ing a remote file) - - // First try to unpack the source as an archive - // to support the untar feature we need to clean up the path a little bit - // because tar is very forgiving. First we need to strip off the archive's - // filename from the path but this is only added if it does not end in slash - tarDest := destPath - if strings.HasSuffix(tarDest, string(os.PathSeparator)) { - tarDest = filepath.Dir(destPath) - } - - // try to successfully untar the orig - err := archiver.UntarPath(srcPath, tarDest) - /* - if err != nil { - logrus.Errorf("Couldn't untar to %s: %v", tarDest, err) - } - */ - return err - } - - // only needed for fixPermissions, but might as well put it before CopyFileWithTar - if destDir || (destExists && destStat.IsDir()) { - destPath = filepath.Join(destPath, src.Name()) - } - - if err := idtools.MkdirAllNewAs(filepath.Dir(destPath), 0755, rootUID, rootGID); err != nil { - return err - } - if err := archiver.CopyFileWithTar(srcPath, destPath); err != nil { - return err - } - - return fixPermissions(srcPath, destPath, rootUID, rootGID, destExists) -} diff --git a/vendor/github.com/docker/docker/daemon/archive_unix.go b/vendor/github.com/docker/docker/daemon/archive_unix.go deleted file mode 100644 index 47666fe..0000000 --- a/vendor/github.com/docker/docker/daemon/archive_unix.go +++ /dev/null @@ -1,58 +0,0 @@ -// +build !windows - -package daemon - -import ( - "os" - "path/filepath" - - "github.com/docker/docker/container" -) - -// checkIfPathIsInAVolume checks if the path is in a volume. If it is, it -// cannot be in a read-only volume. If it is not in a volume, the container -// cannot be configured with a read-only rootfs. -func checkIfPathIsInAVolume(container *container.Container, absPath string) (bool, error) { - var toVolume bool - for _, mnt := range container.MountPoints { - if toVolume = mnt.HasResource(absPath); toVolume { - if mnt.RW { - break - } - return false, ErrVolumeReadonly - } - } - return toVolume, nil -} - -func fixPermissions(source, destination string, uid, gid int, destExisted bool) error { - // If the destination didn't already exist, or the destination isn't a - // directory, then we should Lchown the destination. Otherwise, we shouldn't - // Lchown the destination. - destStat, err := os.Stat(destination) - if err != nil { - // This should *never* be reached, because the destination must've already - // been created while untar-ing the context. - return err - } - doChownDestination := !destExisted || !destStat.IsDir() - - // We Walk on the source rather than on the destination because we don't - // want to change permissions on things we haven't created or modified. - return filepath.Walk(source, func(fullpath string, info os.FileInfo, err error) error { - // Do not alter the walk root iff. it existed before, as it doesn't fall under - // the domain of "things we should chown". - if !doChownDestination && (source == fullpath) { - return nil - } - - // Path is prefixed by source: substitute with destination instead. - cleaned, err := filepath.Rel(source, fullpath) - if err != nil { - return err - } - - fullpath = filepath.Join(destination, cleaned) - return os.Lchown(fullpath, uid, gid) - }) -} diff --git a/vendor/github.com/docker/docker/daemon/archive_windows.go b/vendor/github.com/docker/docker/daemon/archive_windows.go deleted file mode 100644 index b3a1045..0000000 --- a/vendor/github.com/docker/docker/daemon/archive_windows.go +++ /dev/null @@ -1,18 +0,0 @@ -package daemon - -import "github.com/docker/docker/container" - -// checkIfPathIsInAVolume checks if the path is in a volume. If it is, it -// cannot be in a read-only volume. If it is not in a volume, the container -// cannot be configured with a read-only rootfs. -// -// This is a no-op on Windows which does not support read-only volumes, or -// extracting to a mount point inside a volume. TODO Windows: FIXME Post-TP5 -func checkIfPathIsInAVolume(container *container.Container, absPath string) (bool, error) { - return false, nil -} - -func fixPermissions(source, destination string, uid, gid int, destExisted bool) error { - // chown is not supported on Windows - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/attach.go b/vendor/github.com/docker/docker/daemon/attach.go deleted file mode 100644 index 917237d..0000000 --- a/vendor/github.com/docker/docker/daemon/attach.go +++ /dev/null @@ -1,147 +0,0 @@ -package daemon - -import ( - "fmt" - "io" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/pkg/stdcopy" - "github.com/docker/docker/pkg/term" -) - -// ContainerAttach attaches to logs according to the config passed in. See ContainerAttachConfig. -func (daemon *Daemon) ContainerAttach(prefixOrName string, c *backend.ContainerAttachConfig) error { - keys := []byte{} - var err error - if c.DetachKeys != "" { - keys, err = term.ToBytes(c.DetachKeys) - if err != nil { - return fmt.Errorf("Invalid escape keys (%s) provided", c.DetachKeys) - } - } - - container, err := daemon.GetContainer(prefixOrName) - if err != nil { - return err - } - if container.IsPaused() { - err := fmt.Errorf("Container %s is paused. Unpause the container before attach", prefixOrName) - return errors.NewRequestConflictError(err) - } - - inStream, outStream, errStream, err := c.GetStreams() - if err != nil { - return err - } - defer inStream.Close() - - if !container.Config.Tty && c.MuxStreams { - errStream = stdcopy.NewStdWriter(errStream, stdcopy.Stderr) - outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout) - } - - var stdin io.ReadCloser - var stdout, stderr io.Writer - - if c.UseStdin { - stdin = inStream - } - if c.UseStdout { - stdout = outStream - } - if c.UseStderr { - stderr = errStream - } - - if err := daemon.containerAttach(container, stdin, stdout, stderr, c.Logs, c.Stream, keys); err != nil { - fmt.Fprintf(outStream, "Error attaching: %s\n", err) - } - return nil -} - -// ContainerAttachRaw attaches the provided streams to the container's stdio -func (daemon *Daemon) ContainerAttachRaw(prefixOrName string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error { - container, err := daemon.GetContainer(prefixOrName) - if err != nil { - return err - } - return daemon.containerAttach(container, stdin, stdout, stderr, false, stream, nil) -} - -func (daemon *Daemon) containerAttach(c *container.Container, stdin io.ReadCloser, stdout, stderr io.Writer, logs, stream bool, keys []byte) error { - if logs { - logDriver, err := daemon.getLogger(c) - if err != nil { - return err - } - cLog, ok := logDriver.(logger.LogReader) - if !ok { - return logger.ErrReadLogsNotSupported - } - logs := cLog.ReadLogs(logger.ReadConfig{Tail: -1}) - - LogLoop: - for { - select { - case msg, ok := <-logs.Msg: - if !ok { - break LogLoop - } - if msg.Source == "stdout" && stdout != nil { - stdout.Write(msg.Line) - } - if msg.Source == "stderr" && stderr != nil { - stderr.Write(msg.Line) - } - case err := <-logs.Err: - logrus.Errorf("Error streaming logs: %v", err) - break LogLoop - } - } - } - - daemon.LogContainerEvent(c, "attach") - - //stream - if stream { - var stdinPipe io.ReadCloser - if stdin != nil { - r, w := io.Pipe() - go func() { - defer w.Close() - defer logrus.Debug("Closing buffered stdin pipe") - io.Copy(w, stdin) - }() - stdinPipe = r - } - - waitChan := make(chan struct{}) - if c.Config.StdinOnce && !c.Config.Tty { - go func() { - c.WaitStop(-1 * time.Second) - close(waitChan) - }() - } - - err := <-c.Attach(stdinPipe, stdout, stderr, keys) - if err != nil { - if _, ok := err.(container.DetachError); ok { - daemon.LogContainerEvent(c, "detach") - } else { - logrus.Errorf("attach failed with error: %v", err) - } - } - - // If we are in stdinonce mode, wait for the process to end - // otherwise, simply return - if c.Config.StdinOnce && !c.Config.Tty { - <-waitChan - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/auth.go b/vendor/github.com/docker/docker/daemon/auth.go deleted file mode 100644 index f5f4d7b..0000000 --- a/vendor/github.com/docker/docker/daemon/auth.go +++ /dev/null @@ -1,13 +0,0 @@ -package daemon - -import ( - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/dockerversion" -) - -// AuthenticateToRegistry checks the validity of credentials in authConfig -func (daemon *Daemon) AuthenticateToRegistry(ctx context.Context, authConfig *types.AuthConfig) (string, string, error) { - return daemon.RegistryService.Auth(ctx, authConfig, dockerversion.DockerUserAgent(ctx)) -} diff --git a/vendor/github.com/docker/docker/daemon/bindmount_solaris.go b/vendor/github.com/docker/docker/daemon/bindmount_solaris.go deleted file mode 100644 index 87bf3ef..0000000 --- a/vendor/github.com/docker/docker/daemon/bindmount_solaris.go +++ /dev/null @@ -1,5 +0,0 @@ -// +build solaris - -package daemon - -const bindMountType = "lofs" diff --git a/vendor/github.com/docker/docker/daemon/bindmount_unix.go b/vendor/github.com/docker/docker/daemon/bindmount_unix.go deleted file mode 100644 index 3966bab..0000000 --- a/vendor/github.com/docker/docker/daemon/bindmount_unix.go +++ /dev/null @@ -1,5 +0,0 @@ -// +build linux freebsd - -package daemon - -const bindMountType = "bind" diff --git a/vendor/github.com/docker/docker/daemon/cache.go b/vendor/github.com/docker/docker/daemon/cache.go deleted file mode 100644 index a2c2c13..0000000 --- a/vendor/github.com/docker/docker/daemon/cache.go +++ /dev/null @@ -1,254 +0,0 @@ -package daemon - -import ( - "encoding/json" - "fmt" - "reflect" - "strings" - - "github.com/Sirupsen/logrus" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/builder" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/runconfig" - "github.com/pkg/errors" -) - -// getLocalCachedImage returns the most recent created image that is a child -// of the image with imgID, that had the same config when it was -// created. nil is returned if a child cannot be found. An error is -// returned if the parent image cannot be found. -func (daemon *Daemon) getLocalCachedImage(imgID image.ID, config *containertypes.Config) (*image.Image, error) { - // Loop on the children of the given image and check the config - getMatch := func(siblings []image.ID) (*image.Image, error) { - var match *image.Image - for _, id := range siblings { - img, err := daemon.imageStore.Get(id) - if err != nil { - return nil, fmt.Errorf("unable to find image %q", id) - } - - if runconfig.Compare(&img.ContainerConfig, config) { - // check for the most up to date match - if match == nil || match.Created.Before(img.Created) { - match = img - } - } - } - return match, nil - } - - // In this case, this is `FROM scratch`, which isn't an actual image. - if imgID == "" { - images := daemon.imageStore.Map() - var siblings []image.ID - for id, img := range images { - if img.Parent == imgID { - siblings = append(siblings, id) - } - } - return getMatch(siblings) - } - - // find match from child images - siblings := daemon.imageStore.Children(imgID) - return getMatch(siblings) -} - -// MakeImageCache creates a stateful image cache. -func (daemon *Daemon) MakeImageCache(sourceRefs []string) builder.ImageCache { - if len(sourceRefs) == 0 { - return &localImageCache{daemon} - } - - cache := &imageCache{daemon: daemon, localImageCache: &localImageCache{daemon}} - - for _, ref := range sourceRefs { - img, err := daemon.GetImage(ref) - if err != nil { - logrus.Warnf("Could not look up %s for cache resolution, skipping: %+v", ref, err) - continue - } - cache.sources = append(cache.sources, img) - } - - return cache -} - -// localImageCache is cache based on parent chain. -type localImageCache struct { - daemon *Daemon -} - -func (lic *localImageCache) GetCache(imgID string, config *containertypes.Config) (string, error) { - return getImageIDAndError(lic.daemon.getLocalCachedImage(image.ID(imgID), config)) -} - -// imageCache is cache based on history objects. Requires initial set of images. -type imageCache struct { - sources []*image.Image - daemon *Daemon - localImageCache *localImageCache -} - -func (ic *imageCache) restoreCachedImage(parent, target *image.Image, cfg *containertypes.Config) (image.ID, error) { - var history []image.History - rootFS := image.NewRootFS() - lenHistory := 0 - if parent != nil { - history = parent.History - rootFS = parent.RootFS - lenHistory = len(parent.History) - } - history = append(history, target.History[lenHistory]) - if layer := getLayerForHistoryIndex(target, lenHistory); layer != "" { - rootFS.Append(layer) - } - - config, err := json.Marshal(&image.Image{ - V1Image: image.V1Image{ - DockerVersion: dockerversion.Version, - Config: cfg, - Architecture: target.Architecture, - OS: target.OS, - Author: target.Author, - Created: history[len(history)-1].Created, - }, - RootFS: rootFS, - History: history, - OSFeatures: target.OSFeatures, - OSVersion: target.OSVersion, - }) - if err != nil { - return "", errors.Wrap(err, "failed to marshal image config") - } - - imgID, err := ic.daemon.imageStore.Create(config) - if err != nil { - return "", errors.Wrap(err, "failed to create cache image") - } - - if parent != nil { - if err := ic.daemon.imageStore.SetParent(imgID, parent.ID()); err != nil { - return "", errors.Wrapf(err, "failed to set parent for %v to %v", target.ID(), parent.ID()) - } - } - return imgID, nil -} - -func (ic *imageCache) isParent(imgID, parentID image.ID) bool { - nextParent, err := ic.daemon.imageStore.GetParent(imgID) - if err != nil { - return false - } - if nextParent == parentID { - return true - } - return ic.isParent(nextParent, parentID) -} - -func (ic *imageCache) GetCache(parentID string, cfg *containertypes.Config) (string, error) { - imgID, err := ic.localImageCache.GetCache(parentID, cfg) - if err != nil { - return "", err - } - if imgID != "" { - for _, s := range ic.sources { - if ic.isParent(s.ID(), image.ID(imgID)) { - return imgID, nil - } - } - } - - var parent *image.Image - lenHistory := 0 - if parentID != "" { - parent, err = ic.daemon.imageStore.Get(image.ID(parentID)) - if err != nil { - return "", errors.Wrapf(err, "unable to find image %v", parentID) - } - lenHistory = len(parent.History) - } - - for _, target := range ic.sources { - if !isValidParent(target, parent) || !isValidConfig(cfg, target.History[lenHistory]) { - continue - } - - if len(target.History)-1 == lenHistory { // last - if parent != nil { - if err := ic.daemon.imageStore.SetParent(target.ID(), parent.ID()); err != nil { - return "", errors.Wrapf(err, "failed to set parent for %v to %v", target.ID(), parent.ID()) - } - } - return target.ID().String(), nil - } - - imgID, err := ic.restoreCachedImage(parent, target, cfg) - if err != nil { - return "", errors.Wrapf(err, "failed to restore cached image from %q to %v", parentID, target.ID()) - } - - ic.sources = []*image.Image{target} // avoid jumping to different target, tuned for safety atm - return imgID.String(), nil - } - - return "", nil -} - -func getImageIDAndError(img *image.Image, err error) (string, error) { - if img == nil || err != nil { - return "", err - } - return img.ID().String(), nil -} - -func isValidParent(img, parent *image.Image) bool { - if len(img.History) == 0 { - return false - } - if parent == nil || len(parent.History) == 0 && len(parent.RootFS.DiffIDs) == 0 { - return true - } - if len(parent.History) >= len(img.History) { - return false - } - if len(parent.RootFS.DiffIDs) >= len(img.RootFS.DiffIDs) { - return false - } - - for i, h := range parent.History { - if !reflect.DeepEqual(h, img.History[i]) { - return false - } - } - for i, d := range parent.RootFS.DiffIDs { - if d != img.RootFS.DiffIDs[i] { - return false - } - } - return true -} - -func getLayerForHistoryIndex(image *image.Image, index int) layer.DiffID { - layerIndex := 0 - for i, h := range image.History { - if i == index { - if h.EmptyLayer { - return "" - } - break - } - if !h.EmptyLayer { - layerIndex++ - } - } - return image.RootFS.DiffIDs[layerIndex] // validate? -} - -func isValidConfig(cfg *containertypes.Config, h image.History) bool { - // todo: make this format better than join that loses data - return strings.Join(cfg.Cmd, " ") == h.CreatedBy -} diff --git a/vendor/github.com/docker/docker/daemon/caps/utils_unix.go b/vendor/github.com/docker/docker/daemon/caps/utils_unix.go deleted file mode 100644 index c99485f..0000000 --- a/vendor/github.com/docker/docker/daemon/caps/utils_unix.go +++ /dev/null @@ -1,131 +0,0 @@ -// +build !windows - -package caps - -import ( - "fmt" - "strings" - - "github.com/docker/docker/pkg/stringutils" - "github.com/syndtr/gocapability/capability" -) - -var capabilityList Capabilities - -func init() { - last := capability.CAP_LAST_CAP - // hack for RHEL6 which has no /proc/sys/kernel/cap_last_cap - if last == capability.Cap(63) { - last = capability.CAP_BLOCK_SUSPEND - } - for _, cap := range capability.List() { - if cap > last { - continue - } - capabilityList = append(capabilityList, - &CapabilityMapping{ - Key: "CAP_" + strings.ToUpper(cap.String()), - Value: cap, - }, - ) - } -} - -type ( - // CapabilityMapping maps linux capability name to its value of capability.Cap type - // Capabilities is one of the security systems in Linux Security Module (LSM) - // framework provided by the kernel. - // For more details on capabilities, see http://man7.org/linux/man-pages/man7/capabilities.7.html - CapabilityMapping struct { - Key string `json:"key,omitempty"` - Value capability.Cap `json:"value,omitempty"` - } - // Capabilities contains all CapabilityMapping - Capabilities []*CapabilityMapping -) - -// String returns of CapabilityMapping -func (c *CapabilityMapping) String() string { - return c.Key -} - -// GetCapability returns CapabilityMapping which contains specific key -func GetCapability(key string) *CapabilityMapping { - for _, capp := range capabilityList { - if capp.Key == key { - cpy := *capp - return &cpy - } - } - return nil -} - -// GetAllCapabilities returns all of the capabilities -func GetAllCapabilities() []string { - output := make([]string, len(capabilityList)) - for i, capability := range capabilityList { - output[i] = capability.String() - } - return output -} - -// TweakCapabilities can tweak capabilities by adding or dropping capabilities -// based on the basics capabilities. -func TweakCapabilities(basics, adds, drops []string) ([]string, error) { - var ( - newCaps []string - allCaps = GetAllCapabilities() - ) - - // FIXME(tonistiigi): docker format is without CAP_ prefix, oci is with prefix - // Currently they are mixed in here. We should do conversion in one place. - - // look for invalid cap in the drop list - for _, cap := range drops { - if strings.ToLower(cap) == "all" { - continue - } - - if !stringutils.InSlice(allCaps, "CAP_"+cap) { - return nil, fmt.Errorf("Unknown capability drop: %q", cap) - } - } - - // handle --cap-add=all - if stringutils.InSlice(adds, "all") { - basics = allCaps - } - - if !stringutils.InSlice(drops, "all") { - for _, cap := range basics { - // skip `all` already handled above - if strings.ToLower(cap) == "all" { - continue - } - - // if we don't drop `all`, add back all the non-dropped caps - if !stringutils.InSlice(drops, cap[4:]) { - newCaps = append(newCaps, strings.ToUpper(cap)) - } - } - } - - for _, cap := range adds { - // skip `all` already handled above - if strings.ToLower(cap) == "all" { - continue - } - - cap = "CAP_" + cap - - if !stringutils.InSlice(allCaps, cap) { - return nil, fmt.Errorf("Unknown capability to add: %q", cap) - } - - // add cap if not already in the list - if !stringutils.InSlice(newCaps, cap) { - newCaps = append(newCaps, strings.ToUpper(cap)) - } - } - return newCaps, nil -} diff --git a/vendor/github.com/docker/docker/daemon/changes.go b/vendor/github.com/docker/docker/daemon/changes.go deleted file mode 100644 index fc8cd27..0000000 --- a/vendor/github.com/docker/docker/daemon/changes.go +++ /dev/null @@ -1,31 +0,0 @@ -package daemon - -import ( - "errors" - "runtime" - "time" - - "github.com/docker/docker/pkg/archive" -) - -// ContainerChanges returns a list of container fs changes -func (daemon *Daemon) ContainerChanges(name string) ([]archive.Change, error) { - start := time.Now() - container, err := daemon.GetContainer(name) - if err != nil { - return nil, err - } - - if runtime.GOOS == "windows" && container.IsRunning() { - return nil, errors.New("Windows does not support diff of a running container") - } - - container.Lock() - defer container.Unlock() - c, err := container.RWLayer.Changes() - if err != nil { - return nil, err - } - containerActions.WithValues("changes").UpdateSince(start) - return c, nil -} diff --git a/vendor/github.com/docker/docker/daemon/checkpoint.go b/vendor/github.com/docker/docker/daemon/checkpoint.go deleted file mode 100644 index 2718174..0000000 --- a/vendor/github.com/docker/docker/daemon/checkpoint.go +++ /dev/null @@ -1,110 +0,0 @@ -package daemon - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "path/filepath" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/utils" -) - -var ( - validCheckpointNameChars = utils.RestrictedNameChars - validCheckpointNamePattern = utils.RestrictedNamePattern -) - -// CheckpointCreate checkpoints the process running in a container with CRIU -func (daemon *Daemon) CheckpointCreate(name string, config types.CheckpointCreateOptions) error { - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - if !container.IsRunning() { - return fmt.Errorf("Container %s not running", name) - } - - var checkpointDir string - if config.CheckpointDir != "" { - checkpointDir = config.CheckpointDir - } else { - checkpointDir = container.CheckpointDir() - } - - if !validCheckpointNamePattern.MatchString(config.CheckpointID) { - return fmt.Errorf("Invalid checkpoint ID (%s), only %s are allowed", config.CheckpointID, validCheckpointNameChars) - } - - err = daemon.containerd.CreateCheckpoint(container.ID, config.CheckpointID, checkpointDir, config.Exit) - if err != nil { - return fmt.Errorf("Cannot checkpoint container %s: %s", name, err) - } - - daemon.LogContainerEvent(container, "checkpoint") - - return nil -} - -// CheckpointDelete deletes the specified checkpoint -func (daemon *Daemon) CheckpointDelete(name string, config types.CheckpointDeleteOptions) error { - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - var checkpointDir string - if config.CheckpointDir != "" { - checkpointDir = config.CheckpointDir - } else { - checkpointDir = container.CheckpointDir() - } - - return os.RemoveAll(filepath.Join(checkpointDir, config.CheckpointID)) -} - -// CheckpointList lists all checkpoints of the specified container -func (daemon *Daemon) CheckpointList(name string, config types.CheckpointListOptions) ([]types.Checkpoint, error) { - var out []types.Checkpoint - - container, err := daemon.GetContainer(name) - if err != nil { - return nil, err - } - - var checkpointDir string - if config.CheckpointDir != "" { - checkpointDir = config.CheckpointDir - } else { - checkpointDir = container.CheckpointDir() - } - - if err := os.MkdirAll(checkpointDir, 0755); err != nil { - return nil, err - } - - dirs, err := ioutil.ReadDir(checkpointDir) - if err != nil { - return nil, err - } - - for _, d := range dirs { - if !d.IsDir() { - continue - } - path := filepath.Join(checkpointDir, d.Name(), "config.json") - data, err := ioutil.ReadFile(path) - if err != nil { - return nil, err - } - var cpt types.Checkpoint - if err := json.Unmarshal(data, &cpt); err != nil { - return nil, err - } - out = append(out, cpt) - } - - return out, nil -} diff --git a/vendor/github.com/docker/docker/daemon/cluster.go b/vendor/github.com/docker/docker/daemon/cluster.go deleted file mode 100644 index 98b2aa1..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster.go +++ /dev/null @@ -1,12 +0,0 @@ -package daemon - -import ( - apitypes "github.com/docker/docker/api/types" -) - -// Cluster is the interface for github.com/docker/docker/daemon/cluster.(*Cluster). -type Cluster interface { - GetNetwork(input string) (apitypes.NetworkResource, error) - GetNetworks() ([]apitypes.NetworkResource, error) - RemoveNetwork(input string) error -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/cluster.go b/vendor/github.com/docker/docker/daemon/cluster/cluster.go deleted file mode 100644 index 4af035b..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/cluster.go +++ /dev/null @@ -1,1973 +0,0 @@ -package cluster - -import ( - "crypto/x509" - "encoding/base64" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net" - "os" - "path/filepath" - "runtime" - "strings" - "sync" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - distreference "github.com/docker/distribution/reference" - apierrors "github.com/docker/docker/api/errors" - apitypes "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/network" - types "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/daemon/cluster/convert" - executorpkg "github.com/docker/docker/daemon/cluster/executor" - "github.com/docker/docker/daemon/cluster/executor/container" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/signal" - "github.com/docker/docker/pkg/stdcopy" - "github.com/docker/docker/reference" - "github.com/docker/docker/runconfig" - swarmapi "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/manager/encryption" - swarmnode "github.com/docker/swarmkit/node" - "github.com/docker/swarmkit/protobuf/ptypes" - "github.com/pkg/errors" - "golang.org/x/net/context" - "google.golang.org/grpc" -) - -const swarmDirName = "swarm" -const controlSocket = "control.sock" -const swarmConnectTimeout = 20 * time.Second -const swarmRequestTimeout = 20 * time.Second -const stateFile = "docker-state.json" -const defaultAddr = "0.0.0.0:2377" - -const ( - initialReconnectDelay = 100 * time.Millisecond - maxReconnectDelay = 30 * time.Second - contextPrefix = "com.docker.swarm" -) - -// ErrNoSwarm is returned on leaving a cluster that was never initialized -var ErrNoSwarm = fmt.Errorf("This node is not part of a swarm") - -// ErrSwarmExists is returned on initialize or join request for a cluster that has already been activated -var ErrSwarmExists = fmt.Errorf("This node is already part of a swarm. Use \"docker swarm leave\" to leave this swarm and join another one.") - -// ErrPendingSwarmExists is returned on initialize or join request for a cluster that is already processing a similar request but has not succeeded yet. -var ErrPendingSwarmExists = fmt.Errorf("This node is processing an existing join request that has not succeeded yet. Use \"docker swarm leave\" to cancel the current request.") - -// ErrSwarmJoinTimeoutReached is returned when cluster join could not complete before timeout was reached. -var ErrSwarmJoinTimeoutReached = fmt.Errorf("Timeout was reached before node was joined. The attempt to join the swarm will continue in the background. Use the \"docker info\" command to see the current swarm status of your node.") - -// ErrSwarmLocked is returned if the swarm is encrypted and needs a key to unlock it. -var ErrSwarmLocked = fmt.Errorf("Swarm is encrypted and needs to be unlocked before it can be used. Please use \"docker swarm unlock\" to unlock it.") - -// ErrSwarmCertificatesExpired is returned if docker was not started for the whole validity period and they had no chance to renew automatically. -var ErrSwarmCertificatesExpired = errors.New("Swarm certificates have expired. To replace them, leave the swarm and join again.") - -// NetworkSubnetsProvider exposes functions for retrieving the subnets -// of networks managed by Docker, so they can be filtered. -type NetworkSubnetsProvider interface { - V4Subnets() []net.IPNet - V6Subnets() []net.IPNet -} - -// Config provides values for Cluster. -type Config struct { - Root string - Name string - Backend executorpkg.Backend - NetworkSubnetsProvider NetworkSubnetsProvider - - // DefaultAdvertiseAddr is the default host/IP or network interface to use - // if no AdvertiseAddr value is specified. - DefaultAdvertiseAddr string - - // path to store runtime state, such as the swarm control socket - RuntimeRoot string -} - -// Cluster provides capabilities to participate in a cluster as a worker or a -// manager. -type Cluster struct { - sync.RWMutex - *node - root string - runtimeRoot string - config Config - configEvent chan struct{} // todo: make this array and goroutine safe - actualLocalAddr string // after resolution, not persisted - stop bool - err error - cancelDelay func() - attachers map[string]*attacher - locked bool - lastNodeConfig *nodeStartConfig -} - -// attacher manages the in-memory attachment state of a container -// attachment to a global scope network managed by swarm manager. It -// helps in identifying the attachment ID via the taskID and the -// corresponding attachment configuration obtained from the manager. -type attacher struct { - taskID string - config *network.NetworkingConfig - attachWaitCh chan *network.NetworkingConfig - attachCompleteCh chan struct{} - detachWaitCh chan struct{} -} - -type node struct { - *swarmnode.Node - done chan struct{} - ready bool - conn *grpc.ClientConn - client swarmapi.ControlClient - logs swarmapi.LogsClient - reconnectDelay time.Duration - config nodeStartConfig -} - -// nodeStartConfig holds configuration needed to start a new node. Exported -// fields of this structure are saved to disk in json. Unexported fields -// contain data that shouldn't be persisted between daemon reloads. -type nodeStartConfig struct { - // LocalAddr is this machine's local IP or hostname, if specified. - LocalAddr string - // RemoteAddr is the address that was given to "swarm join". It is used - // to find LocalAddr if necessary. - RemoteAddr string - // ListenAddr is the address we bind to, including a port. - ListenAddr string - // AdvertiseAddr is the address other nodes should connect to, - // including a port. - AdvertiseAddr string - joinAddr string - forceNewCluster bool - joinToken string - lockKey []byte - autolock bool -} - -// New creates a new Cluster instance using provided config. -func New(config Config) (*Cluster, error) { - root := filepath.Join(config.Root, swarmDirName) - if err := os.MkdirAll(root, 0700); err != nil { - return nil, err - } - if config.RuntimeRoot == "" { - config.RuntimeRoot = root - } - if err := os.MkdirAll(config.RuntimeRoot, 0700); err != nil { - return nil, err - } - c := &Cluster{ - root: root, - config: config, - configEvent: make(chan struct{}, 10), - runtimeRoot: config.RuntimeRoot, - attachers: make(map[string]*attacher), - } - - nodeConfig, err := c.loadState() - if err != nil { - if os.IsNotExist(err) { - return c, nil - } - return nil, err - } - - n, err := c.startNewNode(*nodeConfig) - if err != nil { - return nil, err - } - - select { - case <-time.After(swarmConnectTimeout): - logrus.Error("swarm component could not be started before timeout was reached") - case <-n.Ready(): - case <-n.done: - if errors.Cause(c.err) == ErrSwarmLocked { - return c, nil - } - if err, ok := errors.Cause(c.err).(x509.CertificateInvalidError); ok && err.Reason == x509.Expired { - c.err = ErrSwarmCertificatesExpired - return c, nil - } - return nil, fmt.Errorf("swarm component could not be started: %v", c.err) - } - go c.reconnectOnFailure(n) - return c, nil -} - -func (c *Cluster) loadState() (*nodeStartConfig, error) { - dt, err := ioutil.ReadFile(filepath.Join(c.root, stateFile)) - if err != nil { - return nil, err - } - // missing certificate means no actual state to restore from - if _, err := os.Stat(filepath.Join(c.root, "certificates/swarm-node.crt")); err != nil { - if os.IsNotExist(err) { - c.clearState() - } - return nil, err - } - var st nodeStartConfig - if err := json.Unmarshal(dt, &st); err != nil { - return nil, err - } - return &st, nil -} - -func (c *Cluster) saveState(config nodeStartConfig) error { - dt, err := json.Marshal(config) - if err != nil { - return err - } - return ioutils.AtomicWriteFile(filepath.Join(c.root, stateFile), dt, 0600) -} - -func (c *Cluster) reconnectOnFailure(n *node) { - for { - <-n.done - c.Lock() - if c.stop || c.node != nil { - c.Unlock() - return - } - n.reconnectDelay *= 2 - if n.reconnectDelay > maxReconnectDelay { - n.reconnectDelay = maxReconnectDelay - } - logrus.Warnf("Restarting swarm in %.2f seconds", n.reconnectDelay.Seconds()) - delayCtx, cancel := context.WithTimeout(context.Background(), n.reconnectDelay) - c.cancelDelay = cancel - c.Unlock() - <-delayCtx.Done() - if delayCtx.Err() != context.DeadlineExceeded { - return - } - c.Lock() - if c.node != nil { - c.Unlock() - return - } - var err error - config := n.config - config.RemoteAddr = c.getRemoteAddress() - config.joinAddr = config.RemoteAddr - n, err = c.startNewNode(config) - if err != nil { - c.err = err - close(n.done) - } - c.Unlock() - } -} - -func (c *Cluster) startNewNode(conf nodeStartConfig) (*node, error) { - if err := c.config.Backend.IsSwarmCompatible(); err != nil { - return nil, err - } - - actualLocalAddr := conf.LocalAddr - if actualLocalAddr == "" { - // If localAddr was not specified, resolve it automatically - // based on the route to joinAddr. localAddr can only be left - // empty on "join". - listenHost, _, err := net.SplitHostPort(conf.ListenAddr) - if err != nil { - return nil, fmt.Errorf("could not parse listen address: %v", err) - } - - listenAddrIP := net.ParseIP(listenHost) - if listenAddrIP == nil || !listenAddrIP.IsUnspecified() { - actualLocalAddr = listenHost - } else { - if conf.RemoteAddr == "" { - // Should never happen except using swarms created by - // old versions that didn't save remoteAddr. - conf.RemoteAddr = "8.8.8.8:53" - } - conn, err := net.Dial("udp", conf.RemoteAddr) - if err != nil { - return nil, fmt.Errorf("could not find local IP address: %v", err) - } - localHostPort := conn.LocalAddr().String() - actualLocalAddr, _, _ = net.SplitHostPort(localHostPort) - conn.Close() - } - } - - var control string - if runtime.GOOS == "windows" { - control = `\\.\pipe\` + controlSocket - } else { - control = filepath.Join(c.runtimeRoot, controlSocket) - } - - c.node = nil - c.cancelDelay = nil - c.stop = false - n, err := swarmnode.New(&swarmnode.Config{ - Hostname: c.config.Name, - ForceNewCluster: conf.forceNewCluster, - ListenControlAPI: control, - ListenRemoteAPI: conf.ListenAddr, - AdvertiseRemoteAPI: conf.AdvertiseAddr, - JoinAddr: conf.joinAddr, - StateDir: c.root, - JoinToken: conf.joinToken, - Executor: container.NewExecutor(c.config.Backend), - HeartbeatTick: 1, - ElectionTick: 3, - UnlockKey: conf.lockKey, - AutoLockManagers: conf.autolock, - PluginGetter: c.config.Backend.PluginGetter(), - }) - - if err != nil { - return nil, err - } - ctx := context.Background() - if err := n.Start(ctx); err != nil { - return nil, err - } - node := &node{ - Node: n, - done: make(chan struct{}), - reconnectDelay: initialReconnectDelay, - config: conf, - } - c.node = node - c.actualLocalAddr = actualLocalAddr // not saved - c.saveState(conf) - - c.config.Backend.DaemonJoinsCluster(c) - go func() { - err := detectLockedError(n.Err(ctx)) - if err != nil { - logrus.Errorf("cluster exited with error: %v", err) - } - c.Lock() - c.node = nil - c.err = err - if errors.Cause(err) == ErrSwarmLocked { - c.locked = true - confClone := conf - c.lastNodeConfig = &confClone - } - c.Unlock() - close(node.done) - }() - - go func() { - select { - case <-n.Ready(): - c.Lock() - node.ready = true - c.err = nil - c.Unlock() - case <-ctx.Done(): - } - c.configEvent <- struct{}{} - }() - - go func() { - for conn := range n.ListenControlSocket(ctx) { - c.Lock() - if node.conn != conn { - if conn == nil { - node.client = nil - node.logs = nil - } else { - node.client = swarmapi.NewControlClient(conn) - node.logs = swarmapi.NewLogsClient(conn) - } - } - node.conn = conn - c.Unlock() - c.configEvent <- struct{}{} - } - }() - - return node, nil -} - -// Init initializes new cluster from user provided request. -func (c *Cluster) Init(req types.InitRequest) (string, error) { - c.Lock() - if c.swarmExists() { - if !req.ForceNewCluster { - c.Unlock() - return "", ErrSwarmExists - } - if err := c.stopNode(); err != nil { - c.Unlock() - return "", err - } - } - - if err := validateAndSanitizeInitRequest(&req); err != nil { - c.Unlock() - return "", err - } - - listenHost, listenPort, err := resolveListenAddr(req.ListenAddr) - if err != nil { - c.Unlock() - return "", err - } - - advertiseHost, advertisePort, err := c.resolveAdvertiseAddr(req.AdvertiseAddr, listenPort) - if err != nil { - c.Unlock() - return "", err - } - - localAddr := listenHost - - // If the local address is undetermined, the advertise address - // will be used as local address, if it belongs to this system. - // If the advertise address is not local, then we try to find - // a system address to use as local address. If this fails, - // we give up and ask user to pass the listen address. - if net.ParseIP(localAddr).IsUnspecified() { - advertiseIP := net.ParseIP(advertiseHost) - - found := false - for _, systemIP := range listSystemIPs() { - if systemIP.Equal(advertiseIP) { - localAddr = advertiseIP.String() - found = true - break - } - } - - if !found { - ip, err := c.resolveSystemAddr() - if err != nil { - c.Unlock() - logrus.Warnf("Could not find a local address: %v", err) - return "", errMustSpecifyListenAddr - } - localAddr = ip.String() - } - } - - // todo: check current state existing - n, err := c.startNewNode(nodeStartConfig{ - forceNewCluster: req.ForceNewCluster, - autolock: req.AutoLockManagers, - LocalAddr: localAddr, - ListenAddr: net.JoinHostPort(listenHost, listenPort), - AdvertiseAddr: net.JoinHostPort(advertiseHost, advertisePort), - }) - if err != nil { - c.Unlock() - return "", err - } - c.Unlock() - - select { - case <-n.Ready(): - if err := initClusterSpec(n, req.Spec); err != nil { - return "", err - } - go c.reconnectOnFailure(n) - return n.NodeID(), nil - case <-n.done: - c.RLock() - defer c.RUnlock() - if !req.ForceNewCluster { // if failure on first attempt don't keep state - if err := c.clearState(); err != nil { - return "", err - } - } - return "", c.err - } -} - -// Join makes current Cluster part of an existing swarm cluster. -func (c *Cluster) Join(req types.JoinRequest) error { - c.Lock() - if c.swarmExists() { - c.Unlock() - return ErrSwarmExists - } - if err := validateAndSanitizeJoinRequest(&req); err != nil { - c.Unlock() - return err - } - - listenHost, listenPort, err := resolveListenAddr(req.ListenAddr) - if err != nil { - c.Unlock() - return err - } - - var advertiseAddr string - if req.AdvertiseAddr != "" { - advertiseHost, advertisePort, err := c.resolveAdvertiseAddr(req.AdvertiseAddr, listenPort) - // For joining, we don't need to provide an advertise address, - // since the remote side can detect it. - if err == nil { - advertiseAddr = net.JoinHostPort(advertiseHost, advertisePort) - } - } - - // todo: check current state existing - n, err := c.startNewNode(nodeStartConfig{ - RemoteAddr: req.RemoteAddrs[0], - ListenAddr: net.JoinHostPort(listenHost, listenPort), - AdvertiseAddr: advertiseAddr, - joinAddr: req.RemoteAddrs[0], - joinToken: req.JoinToken, - }) - if err != nil { - c.Unlock() - return err - } - c.Unlock() - - select { - case <-time.After(swarmConnectTimeout): - // attempt to connect will continue in background, but reconnect only if it didn't fail - go func() { - select { - case <-n.Ready(): - c.reconnectOnFailure(n) - case <-n.done: - logrus.Errorf("failed to join the cluster: %+v", c.err) - } - }() - return ErrSwarmJoinTimeoutReached - case <-n.Ready(): - go c.reconnectOnFailure(n) - return nil - case <-n.done: - c.RLock() - defer c.RUnlock() - return c.err - } -} - -// GetUnlockKey returns the unlock key for the swarm. -func (c *Cluster) GetUnlockKey() (string, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return "", c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - client := swarmapi.NewCAClient(c.conn) - - r, err := client.GetUnlockKey(ctx, &swarmapi.GetUnlockKeyRequest{}) - if err != nil { - return "", err - } - - if len(r.UnlockKey) == 0 { - // no key - return "", nil - } - - return encryption.HumanReadableKey(r.UnlockKey), nil -} - -// UnlockSwarm provides a key to decrypt data that is encrypted at rest. -func (c *Cluster) UnlockSwarm(req types.UnlockRequest) error { - c.RLock() - if !c.isActiveManager() { - if err := c.errNoManager(); err != ErrSwarmLocked { - c.RUnlock() - return err - } - } - - if c.node != nil || c.locked != true { - c.RUnlock() - return errors.New("swarm is not locked") - } - c.RUnlock() - - key, err := encryption.ParseHumanReadableKey(req.UnlockKey) - if err != nil { - return err - } - - c.Lock() - config := *c.lastNodeConfig - config.lockKey = key - n, err := c.startNewNode(config) - if err != nil { - c.Unlock() - return err - } - c.Unlock() - select { - case <-n.Ready(): - case <-n.done: - if errors.Cause(c.err) == ErrSwarmLocked { - return errors.New("swarm could not be unlocked: invalid key provided") - } - return fmt.Errorf("swarm component could not be started: %v", c.err) - } - go c.reconnectOnFailure(n) - return nil -} - -// stopNode is a helper that stops the active c.node and waits until it has -// shut down. Call while keeping the cluster lock. -func (c *Cluster) stopNode() error { - if c.node == nil { - return nil - } - c.stop = true - if c.cancelDelay != nil { - c.cancelDelay() - c.cancelDelay = nil - } - node := c.node - ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) - defer cancel() - // TODO: can't hold lock on stop because it calls back to network - c.Unlock() - defer c.Lock() - if err := node.Stop(ctx); err != nil && !strings.Contains(err.Error(), "context canceled") { - return err - } - <-node.done - return nil -} - -func removingManagerCausesLossOfQuorum(reachable, unreachable int) bool { - return reachable-2 <= unreachable -} - -func isLastManager(reachable, unreachable int) bool { - return reachable == 1 && unreachable == 0 -} - -// Leave shuts down Cluster and removes current state. -func (c *Cluster) Leave(force bool) error { - c.Lock() - node := c.node - if node == nil { - if c.locked { - c.locked = false - c.lastNodeConfig = nil - c.Unlock() - } else if c.err == ErrSwarmCertificatesExpired { - c.err = nil - c.Unlock() - } else { - c.Unlock() - return ErrNoSwarm - } - } else { - if node.Manager() != nil && !force { - msg := "You are attempting to leave the swarm on a node that is participating as a manager. " - if c.isActiveManager() { - active, reachable, unreachable, err := c.managerStats() - if err == nil { - if active && removingManagerCausesLossOfQuorum(reachable, unreachable) { - if isLastManager(reachable, unreachable) { - msg += "Removing the last manager erases all current state of the swarm. Use `--force` to ignore this message. " - c.Unlock() - return fmt.Errorf(msg) - } - msg += fmt.Sprintf("Removing this node leaves %v managers out of %v. Without a Raft quorum your swarm will be inaccessible. ", reachable-1, reachable+unreachable) - } - } - } else { - msg += "Doing so may lose the consensus of your cluster. " - } - - msg += "The only way to restore a swarm that has lost consensus is to reinitialize it with `--force-new-cluster`. Use `--force` to suppress this message." - c.Unlock() - return fmt.Errorf(msg) - } - if err := c.stopNode(); err != nil { - logrus.Errorf("failed to shut down cluster node: %v", err) - signal.DumpStacks("") - c.Unlock() - return err - } - c.Unlock() - if nodeID := node.NodeID(); nodeID != "" { - nodeContainers, err := c.listContainerForNode(nodeID) - if err != nil { - return err - } - for _, id := range nodeContainers { - if err := c.config.Backend.ContainerRm(id, &apitypes.ContainerRmConfig{ForceRemove: true}); err != nil { - logrus.Errorf("error removing %v: %v", id, err) - } - } - } - } - c.configEvent <- struct{}{} - // todo: cleanup optional? - if err := c.clearState(); err != nil { - return err - } - - return nil -} - -func (c *Cluster) listContainerForNode(nodeID string) ([]string, error) { - var ids []string - filters := filters.NewArgs() - filters.Add("label", fmt.Sprintf("com.docker.swarm.node.id=%s", nodeID)) - containers, err := c.config.Backend.Containers(&apitypes.ContainerListOptions{ - Filters: filters, - }) - if err != nil { - return []string{}, err - } - for _, c := range containers { - ids = append(ids, c.ID) - } - return ids, nil -} - -func (c *Cluster) clearState() error { - // todo: backup this data instead of removing? - if err := os.RemoveAll(c.root); err != nil { - return err - } - if err := os.MkdirAll(c.root, 0700); err != nil { - return err - } - c.config.Backend.DaemonLeavesCluster() - return nil -} - -func (c *Cluster) getRequestContext() (context.Context, func()) { // TODO: not needed when requests don't block on qourum lost - return context.WithTimeout(context.Background(), swarmRequestTimeout) -} - -// Inspect retrieves the configuration properties of a managed swarm cluster. -func (c *Cluster) Inspect() (types.Swarm, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return types.Swarm{}, c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - swarm, err := getSwarm(ctx, c.client) - if err != nil { - return types.Swarm{}, err - } - - return convert.SwarmFromGRPC(*swarm), nil -} - -// Update updates configuration of a managed swarm cluster. -func (c *Cluster) Update(version uint64, spec types.Spec, flags types.UpdateFlags) error { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - swarm, err := getSwarm(ctx, c.client) - if err != nil { - return err - } - - // In update, client should provide the complete spec of the swarm, including - // Name and Labels. If a field is specified with 0 or nil, then the default value - // will be used to swarmkit. - clusterSpec, err := convert.SwarmSpecToGRPC(spec) - if err != nil { - return err - } - - _, err = c.client.UpdateCluster( - ctx, - &swarmapi.UpdateClusterRequest{ - ClusterID: swarm.ID, - Spec: &clusterSpec, - ClusterVersion: &swarmapi.Version{ - Index: version, - }, - Rotation: swarmapi.KeyRotation{ - WorkerJoinToken: flags.RotateWorkerToken, - ManagerJoinToken: flags.RotateManagerToken, - ManagerUnlockKey: flags.RotateManagerUnlockKey, - }, - }, - ) - return err -} - -// IsManager returns true if Cluster is participating as a manager. -func (c *Cluster) IsManager() bool { - c.RLock() - defer c.RUnlock() - return c.isActiveManager() -} - -// IsAgent returns true if Cluster is participating as a worker/agent. -func (c *Cluster) IsAgent() bool { - c.RLock() - defer c.RUnlock() - return c.node != nil && c.ready -} - -// GetLocalAddress returns the local address. -func (c *Cluster) GetLocalAddress() string { - c.RLock() - defer c.RUnlock() - return c.actualLocalAddr -} - -// GetListenAddress returns the listen address. -func (c *Cluster) GetListenAddress() string { - c.RLock() - defer c.RUnlock() - if c.node != nil { - return c.node.config.ListenAddr - } - return "" -} - -// GetAdvertiseAddress returns the remotely reachable address of this node. -func (c *Cluster) GetAdvertiseAddress() string { - c.RLock() - defer c.RUnlock() - if c.node != nil && c.node.config.AdvertiseAddr != "" { - advertiseHost, _, _ := net.SplitHostPort(c.node.config.AdvertiseAddr) - return advertiseHost - } - return c.actualLocalAddr -} - -// GetRemoteAddress returns a known advertise address of a remote manager if -// available. -// todo: change to array/connect with info -func (c *Cluster) GetRemoteAddress() string { - c.RLock() - defer c.RUnlock() - return c.getRemoteAddress() -} - -func (c *Cluster) getRemoteAddress() string { - if c.node == nil { - return "" - } - nodeID := c.node.NodeID() - for _, r := range c.node.Remotes() { - if r.NodeID != nodeID { - return r.Addr - } - } - return "" -} - -// ListenClusterEvents returns a channel that receives messages on cluster -// participation changes. -// todo: make cancelable and accessible to multiple callers -func (c *Cluster) ListenClusterEvents() <-chan struct{} { - return c.configEvent -} - -// Info returns information about the current cluster state. -func (c *Cluster) Info() types.Info { - info := types.Info{ - NodeAddr: c.GetAdvertiseAddress(), - } - - c.RLock() - defer c.RUnlock() - - if c.node == nil { - info.LocalNodeState = types.LocalNodeStateInactive - if c.cancelDelay != nil { - info.LocalNodeState = types.LocalNodeStateError - } - if c.locked { - info.LocalNodeState = types.LocalNodeStateLocked - } else if c.err == ErrSwarmCertificatesExpired { - info.LocalNodeState = types.LocalNodeStateError - } - } else { - info.LocalNodeState = types.LocalNodeStatePending - if c.ready == true { - info.LocalNodeState = types.LocalNodeStateActive - } else if c.locked { - info.LocalNodeState = types.LocalNodeStateLocked - } - } - if c.err != nil { - info.Error = c.err.Error() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - if c.isActiveManager() { - info.ControlAvailable = true - swarm, err := c.Inspect() - if err != nil { - info.Error = err.Error() - } - - // Strip JoinTokens - info.Cluster = swarm.ClusterInfo - - if r, err := c.client.ListNodes(ctx, &swarmapi.ListNodesRequest{}); err == nil { - info.Nodes = len(r.Nodes) - for _, n := range r.Nodes { - if n.ManagerStatus != nil { - info.Managers = info.Managers + 1 - } - } - } - } - - if c.node != nil { - for _, r := range c.node.Remotes() { - info.RemoteManagers = append(info.RemoteManagers, types.Peer{NodeID: r.NodeID, Addr: r.Addr}) - } - info.NodeID = c.node.NodeID() - } - - return info -} - -// isActiveManager should not be called without a read lock -func (c *Cluster) isActiveManager() bool { - return c.node != nil && c.conn != nil -} - -// swarmExists should not be called without a read lock -func (c *Cluster) swarmExists() bool { - return c.node != nil || c.locked || c.err == ErrSwarmCertificatesExpired -} - -// errNoManager returns error describing why manager commands can't be used. -// Call with read lock. -func (c *Cluster) errNoManager() error { - if c.node == nil { - if c.locked { - return ErrSwarmLocked - } - if c.err == ErrSwarmCertificatesExpired { - return ErrSwarmCertificatesExpired - } - return fmt.Errorf("This node is not a swarm manager. Use \"docker swarm init\" or \"docker swarm join\" to connect this node to swarm and try again.") - } - if c.node.Manager() != nil { - return fmt.Errorf("This node is not a swarm manager. Manager is being prepared or has trouble connecting to the cluster.") - } - return fmt.Errorf("This node is not a swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager.") -} - -// GetServices returns all services of a managed swarm cluster. -func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Service, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return nil, c.errNoManager() - } - - filters, err := newListServicesFilters(options.Filters) - if err != nil { - return nil, err - } - ctx, cancel := c.getRequestContext() - defer cancel() - - r, err := c.client.ListServices( - ctx, - &swarmapi.ListServicesRequest{Filters: filters}) - if err != nil { - return nil, err - } - - services := []types.Service{} - - for _, service := range r.Services { - services = append(services, convert.ServiceFromGRPC(*service)) - } - - return services, nil -} - -// imageWithDigestString takes an image such as name or name:tag -// and returns the image pinned to a digest, such as name@sha256:34234... -// Due to the difference between the docker/docker/reference, and the -// docker/distribution/reference packages, we're parsing the image twice. -// As the two packages converge, this function should be simplified. -// TODO(nishanttotla): After the packages converge, the function must -// convert distreference.Named -> distreference.Canonical, and the logic simplified. -func (c *Cluster) imageWithDigestString(ctx context.Context, image string, authConfig *apitypes.AuthConfig) (string, error) { - if _, err := digest.ParseDigest(image); err == nil { - return "", errors.New("image reference is an image ID") - } - ref, err := distreference.ParseNamed(image) - if err != nil { - return "", err - } - // only query registry if not a canonical reference (i.e. with digest) - if _, ok := ref.(distreference.Canonical); !ok { - // create a docker/docker/reference Named object because GetRepository needs it - dockerRef, err := reference.ParseNamed(image) - if err != nil { - return "", err - } - dockerRef = reference.WithDefaultTag(dockerRef) - namedTaggedRef, ok := dockerRef.(reference.NamedTagged) - if !ok { - return "", fmt.Errorf("unable to cast image to NamedTagged reference object") - } - - repo, _, err := c.config.Backend.GetRepository(ctx, namedTaggedRef, authConfig) - if err != nil { - return "", err - } - dscrptr, err := repo.Tags(ctx).Get(ctx, namedTaggedRef.Tag()) - if err != nil { - return "", err - } - - namedDigestedRef, err := distreference.WithDigest(distreference.EnsureTagged(ref), dscrptr.Digest) - if err != nil { - return "", err - } - return namedDigestedRef.String(), nil - } - // reference already contains a digest, so just return it - return ref.String(), nil -} - -// CreateService creates a new service in a managed swarm cluster. -func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string) (*apitypes.ServiceCreateResponse, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return nil, c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - err := c.populateNetworkID(ctx, c.client, &s) - if err != nil { - return nil, err - } - - serviceSpec, err := convert.ServiceSpecToGRPC(s) - if err != nil { - return nil, err - } - - ctnr := serviceSpec.Task.GetContainer() - if ctnr == nil { - return nil, fmt.Errorf("service does not use container tasks") - } - - if encodedAuth != "" { - ctnr.PullOptions = &swarmapi.ContainerSpec_PullOptions{RegistryAuth: encodedAuth} - } - - // retrieve auth config from encoded auth - authConfig := &apitypes.AuthConfig{} - if encodedAuth != "" { - if err := json.NewDecoder(base64.NewDecoder(base64.URLEncoding, strings.NewReader(encodedAuth))).Decode(authConfig); err != nil { - logrus.Warnf("invalid authconfig: %v", err) - } - } - - resp := &apitypes.ServiceCreateResponse{} - - // pin image by digest - if os.Getenv("DOCKER_SERVICE_PREFER_OFFLINE_IMAGE") != "1" { - digestImage, err := c.imageWithDigestString(ctx, ctnr.Image, authConfig) - if err != nil { - logrus.Warnf("unable to pin image %s to digest: %s", ctnr.Image, err.Error()) - resp.Warnings = append(resp.Warnings, fmt.Sprintf("unable to pin image %s to digest: %s", ctnr.Image, err.Error())) - } else if ctnr.Image != digestImage { - logrus.Debugf("pinning image %s by digest: %s", ctnr.Image, digestImage) - ctnr.Image = digestImage - } else { - logrus.Debugf("creating service using supplied digest reference %s", ctnr.Image) - } - } - - r, err := c.client.CreateService(ctx, &swarmapi.CreateServiceRequest{Spec: &serviceSpec}) - if err != nil { - return nil, err - } - - resp.ID = r.Service.ID - return resp, nil -} - -// GetService returns a service based on an ID or name. -func (c *Cluster) GetService(input string) (types.Service, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return types.Service{}, c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - service, err := getService(ctx, c.client, input) - if err != nil { - return types.Service{}, err - } - return convert.ServiceFromGRPC(*service), nil -} - -// UpdateService updates existing service to match new properties. -func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec types.ServiceSpec, encodedAuth string, registryAuthFrom string) (*apitypes.ServiceUpdateResponse, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return nil, c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - err := c.populateNetworkID(ctx, c.client, &spec) - if err != nil { - return nil, err - } - - serviceSpec, err := convert.ServiceSpecToGRPC(spec) - if err != nil { - return nil, err - } - - currentService, err := getService(ctx, c.client, serviceIDOrName) - if err != nil { - return nil, err - } - - newCtnr := serviceSpec.Task.GetContainer() - if newCtnr == nil { - return nil, fmt.Errorf("service does not use container tasks") - } - - if encodedAuth != "" { - newCtnr.PullOptions = &swarmapi.ContainerSpec_PullOptions{RegistryAuth: encodedAuth} - } else { - // this is needed because if the encodedAuth isn't being updated then we - // shouldn't lose it, and continue to use the one that was already present - var ctnr *swarmapi.ContainerSpec - switch registryAuthFrom { - case apitypes.RegistryAuthFromSpec, "": - ctnr = currentService.Spec.Task.GetContainer() - case apitypes.RegistryAuthFromPreviousSpec: - if currentService.PreviousSpec == nil { - return nil, fmt.Errorf("service does not have a previous spec") - } - ctnr = currentService.PreviousSpec.Task.GetContainer() - default: - return nil, fmt.Errorf("unsupported registryAuthFromValue") - } - if ctnr == nil { - return nil, fmt.Errorf("service does not use container tasks") - } - newCtnr.PullOptions = ctnr.PullOptions - // update encodedAuth so it can be used to pin image by digest - if ctnr.PullOptions != nil { - encodedAuth = ctnr.PullOptions.RegistryAuth - } - } - - // retrieve auth config from encoded auth - authConfig := &apitypes.AuthConfig{} - if encodedAuth != "" { - if err := json.NewDecoder(base64.NewDecoder(base64.URLEncoding, strings.NewReader(encodedAuth))).Decode(authConfig); err != nil { - logrus.Warnf("invalid authconfig: %v", err) - } - } - - resp := &apitypes.ServiceUpdateResponse{} - - // pin image by digest - if os.Getenv("DOCKER_SERVICE_PREFER_OFFLINE_IMAGE") != "1" { - digestImage, err := c.imageWithDigestString(ctx, newCtnr.Image, authConfig) - if err != nil { - logrus.Warnf("unable to pin image %s to digest: %s", newCtnr.Image, err.Error()) - resp.Warnings = append(resp.Warnings, fmt.Sprintf("unable to pin image %s to digest: %s", newCtnr.Image, err.Error())) - } else if newCtnr.Image != digestImage { - logrus.Debugf("pinning image %s by digest: %s", newCtnr.Image, digestImage) - newCtnr.Image = digestImage - } else { - logrus.Debugf("updating service using supplied digest reference %s", newCtnr.Image) - } - } - - _, err = c.client.UpdateService( - ctx, - &swarmapi.UpdateServiceRequest{ - ServiceID: currentService.ID, - Spec: &serviceSpec, - ServiceVersion: &swarmapi.Version{ - Index: version, - }, - }, - ) - - return resp, err -} - -// RemoveService removes a service from a managed swarm cluster. -func (c *Cluster) RemoveService(input string) error { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - service, err := getService(ctx, c.client, input) - if err != nil { - return err - } - - if _, err := c.client.RemoveService(ctx, &swarmapi.RemoveServiceRequest{ServiceID: service.ID}); err != nil { - return err - } - return nil -} - -// ServiceLogs collects service logs and writes them back to `config.OutStream` -func (c *Cluster) ServiceLogs(ctx context.Context, input string, config *backend.ContainerLogsConfig, started chan struct{}) error { - c.RLock() - if !c.isActiveManager() { - c.RUnlock() - return c.errNoManager() - } - - service, err := getService(ctx, c.client, input) - if err != nil { - c.RUnlock() - return err - } - - stream, err := c.logs.SubscribeLogs(ctx, &swarmapi.SubscribeLogsRequest{ - Selector: &swarmapi.LogSelector{ - ServiceIDs: []string{service.ID}, - }, - Options: &swarmapi.LogSubscriptionOptions{ - Follow: config.Follow, - }, - }) - if err != nil { - c.RUnlock() - return err - } - - wf := ioutils.NewWriteFlusher(config.OutStream) - defer wf.Close() - close(started) - wf.Flush() - - outStream := stdcopy.NewStdWriter(wf, stdcopy.Stdout) - errStream := stdcopy.NewStdWriter(wf, stdcopy.Stderr) - - // Release the lock before starting the stream. - c.RUnlock() - for { - // Check the context before doing anything. - select { - case <-ctx.Done(): - return ctx.Err() - default: - } - - subscribeMsg, err := stream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - return err - } - - for _, msg := range subscribeMsg.Messages { - data := []byte{} - - if config.Timestamps { - ts, err := ptypes.Timestamp(msg.Timestamp) - if err != nil { - return err - } - data = append(data, []byte(ts.Format(logger.TimeFormat)+" ")...) - } - - data = append(data, []byte(fmt.Sprintf("%s.node.id=%s,%s.service.id=%s,%s.task.id=%s ", - contextPrefix, msg.Context.NodeID, - contextPrefix, msg.Context.ServiceID, - contextPrefix, msg.Context.TaskID, - ))...) - - data = append(data, msg.Data...) - - switch msg.Stream { - case swarmapi.LogStreamStdout: - outStream.Write(data) - case swarmapi.LogStreamStderr: - errStream.Write(data) - } - } - } -} - -// GetNodes returns a list of all nodes known to a cluster. -func (c *Cluster) GetNodes(options apitypes.NodeListOptions) ([]types.Node, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return nil, c.errNoManager() - } - - filters, err := newListNodesFilters(options.Filters) - if err != nil { - return nil, err - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - r, err := c.client.ListNodes( - ctx, - &swarmapi.ListNodesRequest{Filters: filters}) - if err != nil { - return nil, err - } - - nodes := []types.Node{} - - for _, node := range r.Nodes { - nodes = append(nodes, convert.NodeFromGRPC(*node)) - } - return nodes, nil -} - -// GetNode returns a node based on an ID or name. -func (c *Cluster) GetNode(input string) (types.Node, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return types.Node{}, c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - node, err := getNode(ctx, c.client, input) - if err != nil { - return types.Node{}, err - } - return convert.NodeFromGRPC(*node), nil -} - -// UpdateNode updates existing nodes properties. -func (c *Cluster) UpdateNode(input string, version uint64, spec types.NodeSpec) error { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return c.errNoManager() - } - - nodeSpec, err := convert.NodeSpecToGRPC(spec) - if err != nil { - return err - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - currentNode, err := getNode(ctx, c.client, input) - if err != nil { - return err - } - - _, err = c.client.UpdateNode( - ctx, - &swarmapi.UpdateNodeRequest{ - NodeID: currentNode.ID, - Spec: &nodeSpec, - NodeVersion: &swarmapi.Version{ - Index: version, - }, - }, - ) - return err -} - -// RemoveNode removes a node from a cluster -func (c *Cluster) RemoveNode(input string, force bool) error { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - node, err := getNode(ctx, c.client, input) - if err != nil { - return err - } - - if _, err := c.client.RemoveNode(ctx, &swarmapi.RemoveNodeRequest{NodeID: node.ID, Force: force}); err != nil { - return err - } - return nil -} - -// GetTasks returns a list of tasks matching the filter options. -func (c *Cluster) GetTasks(options apitypes.TaskListOptions) ([]types.Task, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return nil, c.errNoManager() - } - - byName := func(filter filters.Args) error { - if filter.Include("service") { - serviceFilters := filter.Get("service") - for _, serviceFilter := range serviceFilters { - service, err := c.GetService(serviceFilter) - if err != nil { - return err - } - filter.Del("service", serviceFilter) - filter.Add("service", service.ID) - } - } - if filter.Include("node") { - nodeFilters := filter.Get("node") - for _, nodeFilter := range nodeFilters { - node, err := c.GetNode(nodeFilter) - if err != nil { - return err - } - filter.Del("node", nodeFilter) - filter.Add("node", node.ID) - } - } - return nil - } - - filters, err := newListTasksFilters(options.Filters, byName) - if err != nil { - return nil, err - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - r, err := c.client.ListTasks( - ctx, - &swarmapi.ListTasksRequest{Filters: filters}) - if err != nil { - return nil, err - } - - tasks := []types.Task{} - - for _, task := range r.Tasks { - if task.Spec.GetContainer() != nil { - tasks = append(tasks, convert.TaskFromGRPC(*task)) - } - } - return tasks, nil -} - -// GetTask returns a task by an ID. -func (c *Cluster) GetTask(input string) (types.Task, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return types.Task{}, c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - task, err := getTask(ctx, c.client, input) - if err != nil { - return types.Task{}, err - } - return convert.TaskFromGRPC(*task), nil -} - -// GetNetwork returns a cluster network by an ID. -func (c *Cluster) GetNetwork(input string) (apitypes.NetworkResource, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return apitypes.NetworkResource{}, c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - network, err := getNetwork(ctx, c.client, input) - if err != nil { - return apitypes.NetworkResource{}, err - } - return convert.BasicNetworkFromGRPC(*network), nil -} - -func (c *Cluster) getNetworks(filters *swarmapi.ListNetworksRequest_Filters) ([]apitypes.NetworkResource, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return nil, c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - r, err := c.client.ListNetworks(ctx, &swarmapi.ListNetworksRequest{Filters: filters}) - if err != nil { - return nil, err - } - - var networks []apitypes.NetworkResource - - for _, network := range r.Networks { - networks = append(networks, convert.BasicNetworkFromGRPC(*network)) - } - - return networks, nil -} - -// GetNetworks returns all current cluster managed networks. -func (c *Cluster) GetNetworks() ([]apitypes.NetworkResource, error) { - return c.getNetworks(nil) -} - -// GetNetworksByName returns cluster managed networks by name. -// It is ok to have multiple networks here. #18864 -func (c *Cluster) GetNetworksByName(name string) ([]apitypes.NetworkResource, error) { - // Note that swarmapi.GetNetworkRequest.Name is not functional. - // So we cannot just use that with c.GetNetwork. - return c.getNetworks(&swarmapi.ListNetworksRequest_Filters{ - Names: []string{name}, - }) -} - -func attacherKey(target, containerID string) string { - return containerID + ":" + target -} - -// UpdateAttachment signals the attachment config to the attachment -// waiter who is trying to start or attach the container to the -// network. -func (c *Cluster) UpdateAttachment(target, containerID string, config *network.NetworkingConfig) error { - c.RLock() - attacher, ok := c.attachers[attacherKey(target, containerID)] - c.RUnlock() - if !ok || attacher == nil { - return fmt.Errorf("could not find attacher for container %s to network %s", containerID, target) - } - - attacher.attachWaitCh <- config - close(attacher.attachWaitCh) - return nil -} - -// WaitForDetachment waits for the container to stop or detach from -// the network. -func (c *Cluster) WaitForDetachment(ctx context.Context, networkName, networkID, taskID, containerID string) error { - c.RLock() - attacher, ok := c.attachers[attacherKey(networkName, containerID)] - if !ok { - attacher, ok = c.attachers[attacherKey(networkID, containerID)] - } - if c.node == nil || c.node.Agent() == nil { - c.RUnlock() - return fmt.Errorf("invalid cluster node while waiting for detachment") - } - - agent := c.node.Agent() - c.RUnlock() - - if ok && attacher != nil && - attacher.detachWaitCh != nil && - attacher.attachCompleteCh != nil { - // Attachment may be in progress still so wait for - // attachment to complete. - select { - case <-attacher.attachCompleteCh: - case <-ctx.Done(): - return ctx.Err() - } - - if attacher.taskID == taskID { - select { - case <-attacher.detachWaitCh: - case <-ctx.Done(): - return ctx.Err() - } - } - } - - return agent.ResourceAllocator().DetachNetwork(ctx, taskID) -} - -// AttachNetwork generates an attachment request towards the manager. -func (c *Cluster) AttachNetwork(target string, containerID string, addresses []string) (*network.NetworkingConfig, error) { - aKey := attacherKey(target, containerID) - c.Lock() - if c.node == nil || c.node.Agent() == nil { - c.Unlock() - return nil, fmt.Errorf("invalid cluster node while attaching to network") - } - if attacher, ok := c.attachers[aKey]; ok { - c.Unlock() - return attacher.config, nil - } - - agent := c.node.Agent() - attachWaitCh := make(chan *network.NetworkingConfig) - detachWaitCh := make(chan struct{}) - attachCompleteCh := make(chan struct{}) - c.attachers[aKey] = &attacher{ - attachWaitCh: attachWaitCh, - attachCompleteCh: attachCompleteCh, - detachWaitCh: detachWaitCh, - } - c.Unlock() - - ctx, cancel := c.getRequestContext() - defer cancel() - - taskID, err := agent.ResourceAllocator().AttachNetwork(ctx, containerID, target, addresses) - if err != nil { - c.Lock() - delete(c.attachers, aKey) - c.Unlock() - return nil, fmt.Errorf("Could not attach to network %s: %v", target, err) - } - - c.Lock() - c.attachers[aKey].taskID = taskID - close(attachCompleteCh) - c.Unlock() - - logrus.Debugf("Successfully attached to network %s with tid %s", target, taskID) - - var config *network.NetworkingConfig - select { - case config = <-attachWaitCh: - case <-ctx.Done(): - return nil, fmt.Errorf("attaching to network failed, make sure your network options are correct and check manager logs: %v", ctx.Err()) - } - - c.Lock() - c.attachers[aKey].config = config - c.Unlock() - return config, nil -} - -// DetachNetwork unblocks the waiters waiting on WaitForDetachment so -// that a request to detach can be generated towards the manager. -func (c *Cluster) DetachNetwork(target string, containerID string) error { - aKey := attacherKey(target, containerID) - - c.Lock() - attacher, ok := c.attachers[aKey] - delete(c.attachers, aKey) - c.Unlock() - - if !ok { - return fmt.Errorf("could not find network attachment for container %s to network %s", containerID, target) - } - - close(attacher.detachWaitCh) - return nil -} - -// CreateNetwork creates a new cluster managed network. -func (c *Cluster) CreateNetwork(s apitypes.NetworkCreateRequest) (string, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return "", c.errNoManager() - } - - if runconfig.IsPreDefinedNetwork(s.Name) { - err := fmt.Errorf("%s is a pre-defined network and cannot be created", s.Name) - return "", apierrors.NewRequestForbiddenError(err) - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - networkSpec := convert.BasicNetworkCreateToGRPC(s) - r, err := c.client.CreateNetwork(ctx, &swarmapi.CreateNetworkRequest{Spec: &networkSpec}) - if err != nil { - return "", err - } - - return r.Network.ID, nil -} - -// RemoveNetwork removes a cluster network. -func (c *Cluster) RemoveNetwork(input string) error { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - network, err := getNetwork(ctx, c.client, input) - if err != nil { - return err - } - - if _, err := c.client.RemoveNetwork(ctx, &swarmapi.RemoveNetworkRequest{NetworkID: network.ID}); err != nil { - return err - } - return nil -} - -func (c *Cluster) populateNetworkID(ctx context.Context, client swarmapi.ControlClient, s *types.ServiceSpec) error { - // Always prefer NetworkAttachmentConfigs from TaskTemplate - // but fallback to service spec for backward compatibility - networks := s.TaskTemplate.Networks - if len(networks) == 0 { - networks = s.Networks - } - - for i, n := range networks { - apiNetwork, err := getNetwork(ctx, client, n.Target) - if err != nil { - if ln, _ := c.config.Backend.FindNetwork(n.Target); ln != nil && !ln.Info().Dynamic() { - err = fmt.Errorf("The network %s cannot be used with services. Only networks scoped to the swarm can be used, such as those created with the overlay driver.", ln.Name()) - return apierrors.NewRequestForbiddenError(err) - } - return err - } - networks[i].Target = apiNetwork.ID - } - return nil -} - -func getNetwork(ctx context.Context, c swarmapi.ControlClient, input string) (*swarmapi.Network, error) { - // GetNetwork to match via full ID. - rg, err := c.GetNetwork(ctx, &swarmapi.GetNetworkRequest{NetworkID: input}) - if err != nil { - // If any error (including NotFound), ListNetworks to match via ID prefix and full name. - rl, err := c.ListNetworks(ctx, &swarmapi.ListNetworksRequest{Filters: &swarmapi.ListNetworksRequest_Filters{Names: []string{input}}}) - if err != nil || len(rl.Networks) == 0 { - rl, err = c.ListNetworks(ctx, &swarmapi.ListNetworksRequest{Filters: &swarmapi.ListNetworksRequest_Filters{IDPrefixes: []string{input}}}) - } - - if err != nil { - return nil, err - } - - if len(rl.Networks) == 0 { - return nil, fmt.Errorf("network %s not found", input) - } - - if l := len(rl.Networks); l > 1 { - return nil, fmt.Errorf("network %s is ambiguous (%d matches found)", input, l) - } - - return rl.Networks[0], nil - } - return rg.Network, nil -} - -// Cleanup stops active swarm node. This is run before daemon shutdown. -func (c *Cluster) Cleanup() { - c.Lock() - node := c.node - if node == nil { - c.Unlock() - return - } - defer c.Unlock() - if c.isActiveManager() { - active, reachable, unreachable, err := c.managerStats() - if err == nil { - singlenode := active && isLastManager(reachable, unreachable) - if active && !singlenode && removingManagerCausesLossOfQuorum(reachable, unreachable) { - logrus.Errorf("Leaving cluster with %v managers left out of %v. Raft quorum will be lost.", reachable-1, reachable+unreachable) - } - } - } - c.stopNode() -} - -func (c *Cluster) managerStats() (current bool, reachable int, unreachable int, err error) { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - nodes, err := c.client.ListNodes(ctx, &swarmapi.ListNodesRequest{}) - if err != nil { - return false, 0, 0, err - } - for _, n := range nodes.Nodes { - if n.ManagerStatus != nil { - if n.ManagerStatus.Reachability == swarmapi.RaftMemberStatus_REACHABLE { - reachable++ - if n.ID == c.node.NodeID() { - current = true - } - } - if n.ManagerStatus.Reachability == swarmapi.RaftMemberStatus_UNREACHABLE { - unreachable++ - } - } - } - return -} - -func validateAndSanitizeInitRequest(req *types.InitRequest) error { - var err error - req.ListenAddr, err = validateAddr(req.ListenAddr) - if err != nil { - return fmt.Errorf("invalid ListenAddr %q: %v", req.ListenAddr, err) - } - - if req.Spec.Annotations.Name == "" { - req.Spec.Annotations.Name = "default" - } else if req.Spec.Annotations.Name != "default" { - return errors.New(`swarm spec must be named "default"`) - } - - return nil -} - -func validateAndSanitizeJoinRequest(req *types.JoinRequest) error { - var err error - req.ListenAddr, err = validateAddr(req.ListenAddr) - if err != nil { - return fmt.Errorf("invalid ListenAddr %q: %v", req.ListenAddr, err) - } - if len(req.RemoteAddrs) == 0 { - return fmt.Errorf("at least 1 RemoteAddr is required to join") - } - for i := range req.RemoteAddrs { - req.RemoteAddrs[i], err = validateAddr(req.RemoteAddrs[i]) - if err != nil { - return fmt.Errorf("invalid remoteAddr %q: %v", req.RemoteAddrs[i], err) - } - } - return nil -} - -func validateAddr(addr string) (string, error) { - if addr == "" { - return addr, fmt.Errorf("invalid empty address") - } - newaddr, err := opts.ParseTCPAddr(addr, defaultAddr) - if err != nil { - return addr, nil - } - return strings.TrimPrefix(newaddr, "tcp://"), nil -} - -func initClusterSpec(node *node, spec types.Spec) error { - ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) - for conn := range node.ListenControlSocket(ctx) { - if ctx.Err() != nil { - return ctx.Err() - } - if conn != nil { - client := swarmapi.NewControlClient(conn) - var cluster *swarmapi.Cluster - for i := 0; ; i++ { - lcr, err := client.ListClusters(ctx, &swarmapi.ListClustersRequest{}) - if err != nil { - return fmt.Errorf("error on listing clusters: %v", err) - } - if len(lcr.Clusters) == 0 { - if i < 10 { - time.Sleep(200 * time.Millisecond) - continue - } - return fmt.Errorf("empty list of clusters was returned") - } - cluster = lcr.Clusters[0] - break - } - // In init, we take the initial default values from swarmkit, and merge - // any non nil or 0 value from spec to GRPC spec. This will leave the - // default value alone. - // Note that this is different from Update(), as in Update() we expect - // user to specify the complete spec of the cluster (as they already know - // the existing one and knows which field to update) - clusterSpec, err := convert.MergeSwarmSpecToGRPC(spec, cluster.Spec) - if err != nil { - return fmt.Errorf("error updating cluster settings: %v", err) - } - _, err = client.UpdateCluster(ctx, &swarmapi.UpdateClusterRequest{ - ClusterID: cluster.ID, - ClusterVersion: &cluster.Meta.Version, - Spec: &clusterSpec, - }) - if err != nil { - return fmt.Errorf("error updating cluster settings: %v", err) - } - return nil - } - } - return ctx.Err() -} - -func detectLockedError(err error) error { - if err == swarmnode.ErrInvalidUnlockKey { - return errors.WithStack(ErrSwarmLocked) - } - return err -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/convert/container.go b/vendor/github.com/docker/docker/daemon/cluster/convert/container.go deleted file mode 100644 index 10383f7..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/convert/container.go +++ /dev/null @@ -1,235 +0,0 @@ -package convert - -import ( - "fmt" - "strings" - - "github.com/Sirupsen/logrus" - container "github.com/docker/docker/api/types/container" - mounttypes "github.com/docker/docker/api/types/mount" - types "github.com/docker/docker/api/types/swarm" - swarmapi "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/protobuf/ptypes" -) - -func containerSpecFromGRPC(c *swarmapi.ContainerSpec) types.ContainerSpec { - containerSpec := types.ContainerSpec{ - Image: c.Image, - Labels: c.Labels, - Command: c.Command, - Args: c.Args, - Hostname: c.Hostname, - Env: c.Env, - Dir: c.Dir, - User: c.User, - Groups: c.Groups, - TTY: c.TTY, - OpenStdin: c.OpenStdin, - Hosts: c.Hosts, - Secrets: secretReferencesFromGRPC(c.Secrets), - } - - if c.DNSConfig != nil { - containerSpec.DNSConfig = &types.DNSConfig{ - Nameservers: c.DNSConfig.Nameservers, - Search: c.DNSConfig.Search, - Options: c.DNSConfig.Options, - } - } - - // Mounts - for _, m := range c.Mounts { - mount := mounttypes.Mount{ - Target: m.Target, - Source: m.Source, - Type: mounttypes.Type(strings.ToLower(swarmapi.Mount_MountType_name[int32(m.Type)])), - ReadOnly: m.ReadOnly, - } - - if m.BindOptions != nil { - mount.BindOptions = &mounttypes.BindOptions{ - Propagation: mounttypes.Propagation(strings.ToLower(swarmapi.Mount_BindOptions_MountPropagation_name[int32(m.BindOptions.Propagation)])), - } - } - - if m.VolumeOptions != nil { - mount.VolumeOptions = &mounttypes.VolumeOptions{ - NoCopy: m.VolumeOptions.NoCopy, - Labels: m.VolumeOptions.Labels, - } - if m.VolumeOptions.DriverConfig != nil { - mount.VolumeOptions.DriverConfig = &mounttypes.Driver{ - Name: m.VolumeOptions.DriverConfig.Name, - Options: m.VolumeOptions.DriverConfig.Options, - } - } - } - - if m.TmpfsOptions != nil { - mount.TmpfsOptions = &mounttypes.TmpfsOptions{ - SizeBytes: m.TmpfsOptions.SizeBytes, - Mode: m.TmpfsOptions.Mode, - } - } - containerSpec.Mounts = append(containerSpec.Mounts, mount) - } - - if c.StopGracePeriod != nil { - grace, _ := ptypes.Duration(c.StopGracePeriod) - containerSpec.StopGracePeriod = &grace - } - - if c.Healthcheck != nil { - containerSpec.Healthcheck = healthConfigFromGRPC(c.Healthcheck) - } - - return containerSpec -} - -func secretReferencesToGRPC(sr []*types.SecretReference) []*swarmapi.SecretReference { - refs := make([]*swarmapi.SecretReference, 0, len(sr)) - for _, s := range sr { - ref := &swarmapi.SecretReference{ - SecretID: s.SecretID, - SecretName: s.SecretName, - } - if s.File != nil { - ref.Target = &swarmapi.SecretReference_File{ - File: &swarmapi.SecretReference_FileTarget{ - Name: s.File.Name, - UID: s.File.UID, - GID: s.File.GID, - Mode: s.File.Mode, - }, - } - } - - refs = append(refs, ref) - } - - return refs -} -func secretReferencesFromGRPC(sr []*swarmapi.SecretReference) []*types.SecretReference { - refs := make([]*types.SecretReference, 0, len(sr)) - for _, s := range sr { - target := s.GetFile() - if target == nil { - // not a file target - logrus.Warnf("secret target not a file: secret=%s", s.SecretID) - continue - } - refs = append(refs, &types.SecretReference{ - File: &types.SecretReferenceFileTarget{ - Name: target.Name, - UID: target.UID, - GID: target.GID, - Mode: target.Mode, - }, - SecretID: s.SecretID, - SecretName: s.SecretName, - }) - } - - return refs -} - -func containerToGRPC(c types.ContainerSpec) (*swarmapi.ContainerSpec, error) { - containerSpec := &swarmapi.ContainerSpec{ - Image: c.Image, - Labels: c.Labels, - Command: c.Command, - Args: c.Args, - Hostname: c.Hostname, - Env: c.Env, - Dir: c.Dir, - User: c.User, - Groups: c.Groups, - TTY: c.TTY, - OpenStdin: c.OpenStdin, - Hosts: c.Hosts, - Secrets: secretReferencesToGRPC(c.Secrets), - } - - if c.DNSConfig != nil { - containerSpec.DNSConfig = &swarmapi.ContainerSpec_DNSConfig{ - Nameservers: c.DNSConfig.Nameservers, - Search: c.DNSConfig.Search, - Options: c.DNSConfig.Options, - } - } - - if c.StopGracePeriod != nil { - containerSpec.StopGracePeriod = ptypes.DurationProto(*c.StopGracePeriod) - } - - // Mounts - for _, m := range c.Mounts { - mount := swarmapi.Mount{ - Target: m.Target, - Source: m.Source, - ReadOnly: m.ReadOnly, - } - - if mountType, ok := swarmapi.Mount_MountType_value[strings.ToUpper(string(m.Type))]; ok { - mount.Type = swarmapi.Mount_MountType(mountType) - } else if string(m.Type) != "" { - return nil, fmt.Errorf("invalid MountType: %q", m.Type) - } - - if m.BindOptions != nil { - if mountPropagation, ok := swarmapi.Mount_BindOptions_MountPropagation_value[strings.ToUpper(string(m.BindOptions.Propagation))]; ok { - mount.BindOptions = &swarmapi.Mount_BindOptions{Propagation: swarmapi.Mount_BindOptions_MountPropagation(mountPropagation)} - } else if string(m.BindOptions.Propagation) != "" { - return nil, fmt.Errorf("invalid MountPropagation: %q", m.BindOptions.Propagation) - } - } - - if m.VolumeOptions != nil { - mount.VolumeOptions = &swarmapi.Mount_VolumeOptions{ - NoCopy: m.VolumeOptions.NoCopy, - Labels: m.VolumeOptions.Labels, - } - if m.VolumeOptions.DriverConfig != nil { - mount.VolumeOptions.DriverConfig = &swarmapi.Driver{ - Name: m.VolumeOptions.DriverConfig.Name, - Options: m.VolumeOptions.DriverConfig.Options, - } - } - } - - if m.TmpfsOptions != nil { - mount.TmpfsOptions = &swarmapi.Mount_TmpfsOptions{ - SizeBytes: m.TmpfsOptions.SizeBytes, - Mode: m.TmpfsOptions.Mode, - } - } - - containerSpec.Mounts = append(containerSpec.Mounts, mount) - } - - if c.Healthcheck != nil { - containerSpec.Healthcheck = healthConfigToGRPC(c.Healthcheck) - } - - return containerSpec, nil -} - -func healthConfigFromGRPC(h *swarmapi.HealthConfig) *container.HealthConfig { - interval, _ := ptypes.Duration(h.Interval) - timeout, _ := ptypes.Duration(h.Timeout) - return &container.HealthConfig{ - Test: h.Test, - Interval: interval, - Timeout: timeout, - Retries: int(h.Retries), - } -} - -func healthConfigToGRPC(h *container.HealthConfig) *swarmapi.HealthConfig { - return &swarmapi.HealthConfig{ - Test: h.Test, - Interval: ptypes.DurationProto(h.Interval), - Timeout: ptypes.DurationProto(h.Timeout), - Retries: int32(h.Retries), - } -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/convert/network.go b/vendor/github.com/docker/docker/daemon/cluster/convert/network.go deleted file mode 100644 index 4d21b4d..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/convert/network.go +++ /dev/null @@ -1,210 +0,0 @@ -package convert - -import ( - "strings" - - basictypes "github.com/docker/docker/api/types" - networktypes "github.com/docker/docker/api/types/network" - types "github.com/docker/docker/api/types/swarm" - swarmapi "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/protobuf/ptypes" -) - -func networkAttachementFromGRPC(na *swarmapi.NetworkAttachment) types.NetworkAttachment { - if na != nil { - return types.NetworkAttachment{ - Network: networkFromGRPC(na.Network), - Addresses: na.Addresses, - } - } - return types.NetworkAttachment{} -} - -func networkFromGRPC(n *swarmapi.Network) types.Network { - if n != nil { - network := types.Network{ - ID: n.ID, - Spec: types.NetworkSpec{ - IPv6Enabled: n.Spec.Ipv6Enabled, - Internal: n.Spec.Internal, - Attachable: n.Spec.Attachable, - IPAMOptions: ipamFromGRPC(n.Spec.IPAM), - }, - IPAMOptions: ipamFromGRPC(n.IPAM), - } - - // Meta - network.Version.Index = n.Meta.Version.Index - network.CreatedAt, _ = ptypes.Timestamp(n.Meta.CreatedAt) - network.UpdatedAt, _ = ptypes.Timestamp(n.Meta.UpdatedAt) - - //Annotations - network.Spec.Name = n.Spec.Annotations.Name - network.Spec.Labels = n.Spec.Annotations.Labels - - //DriverConfiguration - if n.Spec.DriverConfig != nil { - network.Spec.DriverConfiguration = &types.Driver{ - Name: n.Spec.DriverConfig.Name, - Options: n.Spec.DriverConfig.Options, - } - } - - //DriverState - if n.DriverState != nil { - network.DriverState = types.Driver{ - Name: n.DriverState.Name, - Options: n.DriverState.Options, - } - } - - return network - } - return types.Network{} -} - -func ipamFromGRPC(i *swarmapi.IPAMOptions) *types.IPAMOptions { - var ipam *types.IPAMOptions - if i != nil { - ipam = &types.IPAMOptions{} - if i.Driver != nil { - ipam.Driver.Name = i.Driver.Name - ipam.Driver.Options = i.Driver.Options - } - - for _, config := range i.Configs { - ipam.Configs = append(ipam.Configs, types.IPAMConfig{ - Subnet: config.Subnet, - Range: config.Range, - Gateway: config.Gateway, - }) - } - } - return ipam -} - -func endpointSpecFromGRPC(es *swarmapi.EndpointSpec) *types.EndpointSpec { - var endpointSpec *types.EndpointSpec - if es != nil { - endpointSpec = &types.EndpointSpec{} - endpointSpec.Mode = types.ResolutionMode(strings.ToLower(es.Mode.String())) - - for _, portState := range es.Ports { - endpointSpec.Ports = append(endpointSpec.Ports, types.PortConfig{ - Name: portState.Name, - Protocol: types.PortConfigProtocol(strings.ToLower(swarmapi.PortConfig_Protocol_name[int32(portState.Protocol)])), - PublishMode: types.PortConfigPublishMode(strings.ToLower(swarmapi.PortConfig_PublishMode_name[int32(portState.PublishMode)])), - TargetPort: portState.TargetPort, - PublishedPort: portState.PublishedPort, - }) - } - } - return endpointSpec -} - -func endpointFromGRPC(e *swarmapi.Endpoint) types.Endpoint { - endpoint := types.Endpoint{} - if e != nil { - if espec := endpointSpecFromGRPC(e.Spec); espec != nil { - endpoint.Spec = *espec - } - - for _, portState := range e.Ports { - endpoint.Ports = append(endpoint.Ports, types.PortConfig{ - Name: portState.Name, - Protocol: types.PortConfigProtocol(strings.ToLower(swarmapi.PortConfig_Protocol_name[int32(portState.Protocol)])), - PublishMode: types.PortConfigPublishMode(strings.ToLower(swarmapi.PortConfig_PublishMode_name[int32(portState.PublishMode)])), - TargetPort: portState.TargetPort, - PublishedPort: portState.PublishedPort, - }) - } - - for _, v := range e.VirtualIPs { - endpoint.VirtualIPs = append(endpoint.VirtualIPs, types.EndpointVirtualIP{ - NetworkID: v.NetworkID, - Addr: v.Addr}) - } - - } - - return endpoint -} - -// BasicNetworkFromGRPC converts a grpc Network to a NetworkResource. -func BasicNetworkFromGRPC(n swarmapi.Network) basictypes.NetworkResource { - spec := n.Spec - var ipam networktypes.IPAM - if spec.IPAM != nil { - if spec.IPAM.Driver != nil { - ipam.Driver = spec.IPAM.Driver.Name - ipam.Options = spec.IPAM.Driver.Options - } - ipam.Config = make([]networktypes.IPAMConfig, 0, len(spec.IPAM.Configs)) - for _, ic := range spec.IPAM.Configs { - ipamConfig := networktypes.IPAMConfig{ - Subnet: ic.Subnet, - IPRange: ic.Range, - Gateway: ic.Gateway, - AuxAddress: ic.Reserved, - } - ipam.Config = append(ipam.Config, ipamConfig) - } - } - - nr := basictypes.NetworkResource{ - ID: n.ID, - Name: n.Spec.Annotations.Name, - Scope: "swarm", - EnableIPv6: spec.Ipv6Enabled, - IPAM: ipam, - Internal: spec.Internal, - Attachable: spec.Attachable, - Labels: n.Spec.Annotations.Labels, - } - - if n.DriverState != nil { - nr.Driver = n.DriverState.Name - nr.Options = n.DriverState.Options - } - - return nr -} - -// BasicNetworkCreateToGRPC converts a NetworkCreateRequest to a grpc NetworkSpec. -func BasicNetworkCreateToGRPC(create basictypes.NetworkCreateRequest) swarmapi.NetworkSpec { - ns := swarmapi.NetworkSpec{ - Annotations: swarmapi.Annotations{ - Name: create.Name, - Labels: create.Labels, - }, - DriverConfig: &swarmapi.Driver{ - Name: create.Driver, - Options: create.Options, - }, - Ipv6Enabled: create.EnableIPv6, - Internal: create.Internal, - Attachable: create.Attachable, - } - if create.IPAM != nil { - driver := create.IPAM.Driver - if driver == "" { - driver = "default" - } - ns.IPAM = &swarmapi.IPAMOptions{ - Driver: &swarmapi.Driver{ - Name: driver, - Options: create.IPAM.Options, - }, - } - ipamSpec := make([]*swarmapi.IPAMConfig, 0, len(create.IPAM.Config)) - for _, ipamConfig := range create.IPAM.Config { - ipamSpec = append(ipamSpec, &swarmapi.IPAMConfig{ - Subnet: ipamConfig.Subnet, - Range: ipamConfig.IPRange, - Gateway: ipamConfig.Gateway, - }) - } - ns.IPAM.Configs = ipamSpec - } - return ns -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/convert/node.go b/vendor/github.com/docker/docker/daemon/cluster/convert/node.go deleted file mode 100644 index 306f34e..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/convert/node.go +++ /dev/null @@ -1,89 +0,0 @@ -package convert - -import ( - "fmt" - "strings" - - types "github.com/docker/docker/api/types/swarm" - swarmapi "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/protobuf/ptypes" -) - -// NodeFromGRPC converts a grpc Node to a Node. -func NodeFromGRPC(n swarmapi.Node) types.Node { - node := types.Node{ - ID: n.ID, - Spec: types.NodeSpec{ - Role: types.NodeRole(strings.ToLower(n.Spec.Role.String())), - Availability: types.NodeAvailability(strings.ToLower(n.Spec.Availability.String())), - }, - Status: types.NodeStatus{ - State: types.NodeState(strings.ToLower(n.Status.State.String())), - Message: n.Status.Message, - Addr: n.Status.Addr, - }, - } - - // Meta - node.Version.Index = n.Meta.Version.Index - node.CreatedAt, _ = ptypes.Timestamp(n.Meta.CreatedAt) - node.UpdatedAt, _ = ptypes.Timestamp(n.Meta.UpdatedAt) - - //Annotations - node.Spec.Name = n.Spec.Annotations.Name - node.Spec.Labels = n.Spec.Annotations.Labels - - //Description - if n.Description != nil { - node.Description.Hostname = n.Description.Hostname - if n.Description.Platform != nil { - node.Description.Platform.Architecture = n.Description.Platform.Architecture - node.Description.Platform.OS = n.Description.Platform.OS - } - if n.Description.Resources != nil { - node.Description.Resources.NanoCPUs = n.Description.Resources.NanoCPUs - node.Description.Resources.MemoryBytes = n.Description.Resources.MemoryBytes - } - if n.Description.Engine != nil { - node.Description.Engine.EngineVersion = n.Description.Engine.EngineVersion - node.Description.Engine.Labels = n.Description.Engine.Labels - for _, plugin := range n.Description.Engine.Plugins { - node.Description.Engine.Plugins = append(node.Description.Engine.Plugins, types.PluginDescription{Type: plugin.Type, Name: plugin.Name}) - } - } - } - - //Manager - if n.ManagerStatus != nil { - node.ManagerStatus = &types.ManagerStatus{ - Leader: n.ManagerStatus.Leader, - Reachability: types.Reachability(strings.ToLower(n.ManagerStatus.Reachability.String())), - Addr: n.ManagerStatus.Addr, - } - } - - return node -} - -// NodeSpecToGRPC converts a NodeSpec to a grpc NodeSpec. -func NodeSpecToGRPC(s types.NodeSpec) (swarmapi.NodeSpec, error) { - spec := swarmapi.NodeSpec{ - Annotations: swarmapi.Annotations{ - Name: s.Name, - Labels: s.Labels, - }, - } - if role, ok := swarmapi.NodeRole_value[strings.ToUpper(string(s.Role))]; ok { - spec.Role = swarmapi.NodeRole(role) - } else { - return swarmapi.NodeSpec{}, fmt.Errorf("invalid Role: %q", s.Role) - } - - if availability, ok := swarmapi.NodeSpec_Availability_value[strings.ToUpper(string(s.Availability))]; ok { - spec.Availability = swarmapi.NodeSpec_Availability(availability) - } else { - return swarmapi.NodeSpec{}, fmt.Errorf("invalid Availability: %q", s.Availability) - } - - return spec, nil -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/convert/secret.go b/vendor/github.com/docker/docker/daemon/cluster/convert/secret.go deleted file mode 100644 index 3e96687..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/convert/secret.go +++ /dev/null @@ -1,64 +0,0 @@ -package convert - -import ( - swarmtypes "github.com/docker/docker/api/types/swarm" - swarmapi "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/protobuf/ptypes" -) - -// SecretFromGRPC converts a grpc Secret to a Secret. -func SecretFromGRPC(s *swarmapi.Secret) swarmtypes.Secret { - secret := swarmtypes.Secret{ - ID: s.ID, - Spec: swarmtypes.SecretSpec{ - Annotations: swarmtypes.Annotations{ - Name: s.Spec.Annotations.Name, - Labels: s.Spec.Annotations.Labels, - }, - Data: s.Spec.Data, - }, - } - - secret.Version.Index = s.Meta.Version.Index - // Meta - secret.CreatedAt, _ = ptypes.Timestamp(s.Meta.CreatedAt) - secret.UpdatedAt, _ = ptypes.Timestamp(s.Meta.UpdatedAt) - - return secret -} - -// SecretSpecToGRPC converts Secret to a grpc Secret. -func SecretSpecToGRPC(s swarmtypes.SecretSpec) swarmapi.SecretSpec { - return swarmapi.SecretSpec{ - Annotations: swarmapi.Annotations{ - Name: s.Name, - Labels: s.Labels, - }, - Data: s.Data, - } -} - -// SecretReferencesFromGRPC converts a slice of grpc SecretReference to SecretReference -func SecretReferencesFromGRPC(s []*swarmapi.SecretReference) []*swarmtypes.SecretReference { - refs := []*swarmtypes.SecretReference{} - - for _, r := range s { - ref := &swarmtypes.SecretReference{ - SecretID: r.SecretID, - SecretName: r.SecretName, - } - - if t, ok := r.Target.(*swarmapi.SecretReference_File); ok { - ref.File = &swarmtypes.SecretReferenceFileTarget{ - Name: t.File.Name, - UID: t.File.UID, - GID: t.File.GID, - Mode: t.File.Mode, - } - } - - refs = append(refs, ref) - } - - return refs -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/convert/service.go b/vendor/github.com/docker/docker/daemon/cluster/convert/service.go deleted file mode 100644 index aa68e01..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/convert/service.go +++ /dev/null @@ -1,366 +0,0 @@ -package convert - -import ( - "fmt" - "strings" - - types "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/namesgenerator" - swarmapi "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/protobuf/ptypes" -) - -// ServiceFromGRPC converts a grpc Service to a Service. -func ServiceFromGRPC(s swarmapi.Service) types.Service { - service := types.Service{ - ID: s.ID, - Spec: *serviceSpecFromGRPC(&s.Spec), - PreviousSpec: serviceSpecFromGRPC(s.PreviousSpec), - - Endpoint: endpointFromGRPC(s.Endpoint), - } - - // Meta - service.Version.Index = s.Meta.Version.Index - service.CreatedAt, _ = ptypes.Timestamp(s.Meta.CreatedAt) - service.UpdatedAt, _ = ptypes.Timestamp(s.Meta.UpdatedAt) - - // UpdateStatus - service.UpdateStatus = types.UpdateStatus{} - if s.UpdateStatus != nil { - switch s.UpdateStatus.State { - case swarmapi.UpdateStatus_UPDATING: - service.UpdateStatus.State = types.UpdateStateUpdating - case swarmapi.UpdateStatus_PAUSED: - service.UpdateStatus.State = types.UpdateStatePaused - case swarmapi.UpdateStatus_COMPLETED: - service.UpdateStatus.State = types.UpdateStateCompleted - } - - service.UpdateStatus.StartedAt, _ = ptypes.Timestamp(s.UpdateStatus.StartedAt) - service.UpdateStatus.CompletedAt, _ = ptypes.Timestamp(s.UpdateStatus.CompletedAt) - service.UpdateStatus.Message = s.UpdateStatus.Message - } - - return service -} - -func serviceSpecFromGRPC(spec *swarmapi.ServiceSpec) *types.ServiceSpec { - if spec == nil { - return nil - } - - serviceNetworks := make([]types.NetworkAttachmentConfig, 0, len(spec.Networks)) - for _, n := range spec.Networks { - serviceNetworks = append(serviceNetworks, types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases}) - } - - taskNetworks := make([]types.NetworkAttachmentConfig, 0, len(spec.Task.Networks)) - for _, n := range spec.Task.Networks { - taskNetworks = append(taskNetworks, types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases}) - } - - containerConfig := spec.Task.Runtime.(*swarmapi.TaskSpec_Container).Container - convertedSpec := &types.ServiceSpec{ - Annotations: types.Annotations{ - Name: spec.Annotations.Name, - Labels: spec.Annotations.Labels, - }, - - TaskTemplate: types.TaskSpec{ - ContainerSpec: containerSpecFromGRPC(containerConfig), - Resources: resourcesFromGRPC(spec.Task.Resources), - RestartPolicy: restartPolicyFromGRPC(spec.Task.Restart), - Placement: placementFromGRPC(spec.Task.Placement), - LogDriver: driverFromGRPC(spec.Task.LogDriver), - Networks: taskNetworks, - ForceUpdate: spec.Task.ForceUpdate, - }, - - Networks: serviceNetworks, - EndpointSpec: endpointSpecFromGRPC(spec.Endpoint), - } - - // UpdateConfig - if spec.Update != nil { - convertedSpec.UpdateConfig = &types.UpdateConfig{ - Parallelism: spec.Update.Parallelism, - MaxFailureRatio: spec.Update.MaxFailureRatio, - } - - convertedSpec.UpdateConfig.Delay, _ = ptypes.Duration(&spec.Update.Delay) - if spec.Update.Monitor != nil { - convertedSpec.UpdateConfig.Monitor, _ = ptypes.Duration(spec.Update.Monitor) - } - - switch spec.Update.FailureAction { - case swarmapi.UpdateConfig_PAUSE: - convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionPause - case swarmapi.UpdateConfig_CONTINUE: - convertedSpec.UpdateConfig.FailureAction = types.UpdateFailureActionContinue - } - } - - // Mode - switch t := spec.GetMode().(type) { - case *swarmapi.ServiceSpec_Global: - convertedSpec.Mode.Global = &types.GlobalService{} - case *swarmapi.ServiceSpec_Replicated: - convertedSpec.Mode.Replicated = &types.ReplicatedService{ - Replicas: &t.Replicated.Replicas, - } - } - - return convertedSpec -} - -// ServiceSpecToGRPC converts a ServiceSpec to a grpc ServiceSpec. -func ServiceSpecToGRPC(s types.ServiceSpec) (swarmapi.ServiceSpec, error) { - name := s.Name - if name == "" { - name = namesgenerator.GetRandomName(0) - } - - serviceNetworks := make([]*swarmapi.NetworkAttachmentConfig, 0, len(s.Networks)) - for _, n := range s.Networks { - serviceNetworks = append(serviceNetworks, &swarmapi.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases}) - } - - taskNetworks := make([]*swarmapi.NetworkAttachmentConfig, 0, len(s.TaskTemplate.Networks)) - for _, n := range s.TaskTemplate.Networks { - taskNetworks = append(taskNetworks, &swarmapi.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases}) - } - - spec := swarmapi.ServiceSpec{ - Annotations: swarmapi.Annotations{ - Name: name, - Labels: s.Labels, - }, - Task: swarmapi.TaskSpec{ - Resources: resourcesToGRPC(s.TaskTemplate.Resources), - LogDriver: driverToGRPC(s.TaskTemplate.LogDriver), - Networks: taskNetworks, - ForceUpdate: s.TaskTemplate.ForceUpdate, - }, - Networks: serviceNetworks, - } - - containerSpec, err := containerToGRPC(s.TaskTemplate.ContainerSpec) - if err != nil { - return swarmapi.ServiceSpec{}, err - } - spec.Task.Runtime = &swarmapi.TaskSpec_Container{Container: containerSpec} - - restartPolicy, err := restartPolicyToGRPC(s.TaskTemplate.RestartPolicy) - if err != nil { - return swarmapi.ServiceSpec{}, err - } - spec.Task.Restart = restartPolicy - - if s.TaskTemplate.Placement != nil { - spec.Task.Placement = &swarmapi.Placement{ - Constraints: s.TaskTemplate.Placement.Constraints, - } - } - - if s.UpdateConfig != nil { - var failureAction swarmapi.UpdateConfig_FailureAction - switch s.UpdateConfig.FailureAction { - case types.UpdateFailureActionPause, "": - failureAction = swarmapi.UpdateConfig_PAUSE - case types.UpdateFailureActionContinue: - failureAction = swarmapi.UpdateConfig_CONTINUE - default: - return swarmapi.ServiceSpec{}, fmt.Errorf("unrecongized update failure action %s", s.UpdateConfig.FailureAction) - } - spec.Update = &swarmapi.UpdateConfig{ - Parallelism: s.UpdateConfig.Parallelism, - Delay: *ptypes.DurationProto(s.UpdateConfig.Delay), - FailureAction: failureAction, - MaxFailureRatio: s.UpdateConfig.MaxFailureRatio, - } - if s.UpdateConfig.Monitor != 0 { - spec.Update.Monitor = ptypes.DurationProto(s.UpdateConfig.Monitor) - } - } - - if s.EndpointSpec != nil { - if s.EndpointSpec.Mode != "" && - s.EndpointSpec.Mode != types.ResolutionModeVIP && - s.EndpointSpec.Mode != types.ResolutionModeDNSRR { - return swarmapi.ServiceSpec{}, fmt.Errorf("invalid resolution mode: %q", s.EndpointSpec.Mode) - } - - spec.Endpoint = &swarmapi.EndpointSpec{} - - spec.Endpoint.Mode = swarmapi.EndpointSpec_ResolutionMode(swarmapi.EndpointSpec_ResolutionMode_value[strings.ToUpper(string(s.EndpointSpec.Mode))]) - - for _, portConfig := range s.EndpointSpec.Ports { - spec.Endpoint.Ports = append(spec.Endpoint.Ports, &swarmapi.PortConfig{ - Name: portConfig.Name, - Protocol: swarmapi.PortConfig_Protocol(swarmapi.PortConfig_Protocol_value[strings.ToUpper(string(portConfig.Protocol))]), - PublishMode: swarmapi.PortConfig_PublishMode(swarmapi.PortConfig_PublishMode_value[strings.ToUpper(string(portConfig.PublishMode))]), - TargetPort: portConfig.TargetPort, - PublishedPort: portConfig.PublishedPort, - }) - } - } - - // Mode - if s.Mode.Global != nil && s.Mode.Replicated != nil { - return swarmapi.ServiceSpec{}, fmt.Errorf("cannot specify both replicated mode and global mode") - } - - if s.Mode.Global != nil { - spec.Mode = &swarmapi.ServiceSpec_Global{ - Global: &swarmapi.GlobalService{}, - } - } else if s.Mode.Replicated != nil && s.Mode.Replicated.Replicas != nil { - spec.Mode = &swarmapi.ServiceSpec_Replicated{ - Replicated: &swarmapi.ReplicatedService{Replicas: *s.Mode.Replicated.Replicas}, - } - } else { - spec.Mode = &swarmapi.ServiceSpec_Replicated{ - Replicated: &swarmapi.ReplicatedService{Replicas: 1}, - } - } - - return spec, nil -} - -func resourcesFromGRPC(res *swarmapi.ResourceRequirements) *types.ResourceRequirements { - var resources *types.ResourceRequirements - if res != nil { - resources = &types.ResourceRequirements{} - if res.Limits != nil { - resources.Limits = &types.Resources{ - NanoCPUs: res.Limits.NanoCPUs, - MemoryBytes: res.Limits.MemoryBytes, - } - } - if res.Reservations != nil { - resources.Reservations = &types.Resources{ - NanoCPUs: res.Reservations.NanoCPUs, - MemoryBytes: res.Reservations.MemoryBytes, - } - } - } - - return resources -} - -func resourcesToGRPC(res *types.ResourceRequirements) *swarmapi.ResourceRequirements { - var reqs *swarmapi.ResourceRequirements - if res != nil { - reqs = &swarmapi.ResourceRequirements{} - if res.Limits != nil { - reqs.Limits = &swarmapi.Resources{ - NanoCPUs: res.Limits.NanoCPUs, - MemoryBytes: res.Limits.MemoryBytes, - } - } - if res.Reservations != nil { - reqs.Reservations = &swarmapi.Resources{ - NanoCPUs: res.Reservations.NanoCPUs, - MemoryBytes: res.Reservations.MemoryBytes, - } - - } - } - return reqs -} - -func restartPolicyFromGRPC(p *swarmapi.RestartPolicy) *types.RestartPolicy { - var rp *types.RestartPolicy - if p != nil { - rp = &types.RestartPolicy{} - - switch p.Condition { - case swarmapi.RestartOnNone: - rp.Condition = types.RestartPolicyConditionNone - case swarmapi.RestartOnFailure: - rp.Condition = types.RestartPolicyConditionOnFailure - case swarmapi.RestartOnAny: - rp.Condition = types.RestartPolicyConditionAny - default: - rp.Condition = types.RestartPolicyConditionAny - } - - if p.Delay != nil { - delay, _ := ptypes.Duration(p.Delay) - rp.Delay = &delay - } - if p.Window != nil { - window, _ := ptypes.Duration(p.Window) - rp.Window = &window - } - - rp.MaxAttempts = &p.MaxAttempts - } - return rp -} - -func restartPolicyToGRPC(p *types.RestartPolicy) (*swarmapi.RestartPolicy, error) { - var rp *swarmapi.RestartPolicy - if p != nil { - rp = &swarmapi.RestartPolicy{} - - switch p.Condition { - case types.RestartPolicyConditionNone: - rp.Condition = swarmapi.RestartOnNone - case types.RestartPolicyConditionOnFailure: - rp.Condition = swarmapi.RestartOnFailure - case types.RestartPolicyConditionAny: - rp.Condition = swarmapi.RestartOnAny - default: - if string(p.Condition) != "" { - return nil, fmt.Errorf("invalid RestartCondition: %q", p.Condition) - } - rp.Condition = swarmapi.RestartOnAny - } - - if p.Delay != nil { - rp.Delay = ptypes.DurationProto(*p.Delay) - } - if p.Window != nil { - rp.Window = ptypes.DurationProto(*p.Window) - } - if p.MaxAttempts != nil { - rp.MaxAttempts = *p.MaxAttempts - - } - } - return rp, nil -} - -func placementFromGRPC(p *swarmapi.Placement) *types.Placement { - var r *types.Placement - if p != nil { - r = &types.Placement{} - r.Constraints = p.Constraints - } - - return r -} - -func driverFromGRPC(p *swarmapi.Driver) *types.Driver { - if p == nil { - return nil - } - - return &types.Driver{ - Name: p.Name, - Options: p.Options, - } -} - -func driverToGRPC(p *types.Driver) *swarmapi.Driver { - if p == nil { - return nil - } - - return &swarmapi.Driver{ - Name: p.Name, - Options: p.Options, - } -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/convert/swarm.go b/vendor/github.com/docker/docker/daemon/cluster/convert/swarm.go deleted file mode 100644 index 606e00a..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/convert/swarm.go +++ /dev/null @@ -1,122 +0,0 @@ -package convert - -import ( - "fmt" - "strings" - "time" - - types "github.com/docker/docker/api/types/swarm" - swarmapi "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/protobuf/ptypes" -) - -// SwarmFromGRPC converts a grpc Cluster to a Swarm. -func SwarmFromGRPC(c swarmapi.Cluster) types.Swarm { - swarm := types.Swarm{ - ClusterInfo: types.ClusterInfo{ - ID: c.ID, - Spec: types.Spec{ - Orchestration: types.OrchestrationConfig{ - TaskHistoryRetentionLimit: &c.Spec.Orchestration.TaskHistoryRetentionLimit, - }, - Raft: types.RaftConfig{ - SnapshotInterval: c.Spec.Raft.SnapshotInterval, - KeepOldSnapshots: &c.Spec.Raft.KeepOldSnapshots, - LogEntriesForSlowFollowers: c.Spec.Raft.LogEntriesForSlowFollowers, - HeartbeatTick: int(c.Spec.Raft.HeartbeatTick), - ElectionTick: int(c.Spec.Raft.ElectionTick), - }, - EncryptionConfig: types.EncryptionConfig{ - AutoLockManagers: c.Spec.EncryptionConfig.AutoLockManagers, - }, - }, - }, - JoinTokens: types.JoinTokens{ - Worker: c.RootCA.JoinTokens.Worker, - Manager: c.RootCA.JoinTokens.Manager, - }, - } - - heartbeatPeriod, _ := ptypes.Duration(c.Spec.Dispatcher.HeartbeatPeriod) - swarm.Spec.Dispatcher.HeartbeatPeriod = heartbeatPeriod - - swarm.Spec.CAConfig.NodeCertExpiry, _ = ptypes.Duration(c.Spec.CAConfig.NodeCertExpiry) - - for _, ca := range c.Spec.CAConfig.ExternalCAs { - swarm.Spec.CAConfig.ExternalCAs = append(swarm.Spec.CAConfig.ExternalCAs, &types.ExternalCA{ - Protocol: types.ExternalCAProtocol(strings.ToLower(ca.Protocol.String())), - URL: ca.URL, - Options: ca.Options, - }) - } - - // Meta - swarm.Version.Index = c.Meta.Version.Index - swarm.CreatedAt, _ = ptypes.Timestamp(c.Meta.CreatedAt) - swarm.UpdatedAt, _ = ptypes.Timestamp(c.Meta.UpdatedAt) - - // Annotations - swarm.Spec.Name = c.Spec.Annotations.Name - swarm.Spec.Labels = c.Spec.Annotations.Labels - - return swarm -} - -// SwarmSpecToGRPC converts a Spec to a grpc ClusterSpec. -func SwarmSpecToGRPC(s types.Spec) (swarmapi.ClusterSpec, error) { - return MergeSwarmSpecToGRPC(s, swarmapi.ClusterSpec{}) -} - -// MergeSwarmSpecToGRPC merges a Spec with an initial grpc ClusterSpec -func MergeSwarmSpecToGRPC(s types.Spec, spec swarmapi.ClusterSpec) (swarmapi.ClusterSpec, error) { - // We take the initSpec (either created from scratch, or returned by swarmkit), - // and will only change the value if the one taken from types.Spec is not nil or 0. - // In other words, if the value taken from types.Spec is nil or 0, we will maintain the status quo. - if s.Annotations.Name != "" { - spec.Annotations.Name = s.Annotations.Name - } - if len(s.Annotations.Labels) != 0 { - spec.Annotations.Labels = s.Annotations.Labels - } - - if s.Orchestration.TaskHistoryRetentionLimit != nil { - spec.Orchestration.TaskHistoryRetentionLimit = *s.Orchestration.TaskHistoryRetentionLimit - } - if s.Raft.SnapshotInterval != 0 { - spec.Raft.SnapshotInterval = s.Raft.SnapshotInterval - } - if s.Raft.KeepOldSnapshots != nil { - spec.Raft.KeepOldSnapshots = *s.Raft.KeepOldSnapshots - } - if s.Raft.LogEntriesForSlowFollowers != 0 { - spec.Raft.LogEntriesForSlowFollowers = s.Raft.LogEntriesForSlowFollowers - } - if s.Raft.HeartbeatTick != 0 { - spec.Raft.HeartbeatTick = uint32(s.Raft.HeartbeatTick) - } - if s.Raft.ElectionTick != 0 { - spec.Raft.ElectionTick = uint32(s.Raft.ElectionTick) - } - if s.Dispatcher.HeartbeatPeriod != 0 { - spec.Dispatcher.HeartbeatPeriod = ptypes.DurationProto(time.Duration(s.Dispatcher.HeartbeatPeriod)) - } - if s.CAConfig.NodeCertExpiry != 0 { - spec.CAConfig.NodeCertExpiry = ptypes.DurationProto(s.CAConfig.NodeCertExpiry) - } - - for _, ca := range s.CAConfig.ExternalCAs { - protocol, ok := swarmapi.ExternalCA_CAProtocol_value[strings.ToUpper(string(ca.Protocol))] - if !ok { - return swarmapi.ClusterSpec{}, fmt.Errorf("invalid protocol: %q", ca.Protocol) - } - spec.CAConfig.ExternalCAs = append(spec.CAConfig.ExternalCAs, &swarmapi.ExternalCA{ - Protocol: swarmapi.ExternalCA_CAProtocol(protocol), - URL: ca.URL, - Options: ca.Options, - }) - } - - spec.EncryptionConfig.AutoLockManagers = s.EncryptionConfig.AutoLockManagers - - return spec, nil -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/convert/task.go b/vendor/github.com/docker/docker/daemon/cluster/convert/task.go deleted file mode 100644 index d0cf89c..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/convert/task.go +++ /dev/null @@ -1,81 +0,0 @@ -package convert - -import ( - "strings" - - types "github.com/docker/docker/api/types/swarm" - swarmapi "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/protobuf/ptypes" -) - -// TaskFromGRPC converts a grpc Task to a Task. -func TaskFromGRPC(t swarmapi.Task) types.Task { - if t.Spec.GetAttachment() != nil { - return types.Task{} - } - containerConfig := t.Spec.Runtime.(*swarmapi.TaskSpec_Container).Container - containerStatus := t.Status.GetContainer() - networks := make([]types.NetworkAttachmentConfig, 0, len(t.Spec.Networks)) - for _, n := range t.Spec.Networks { - networks = append(networks, types.NetworkAttachmentConfig{Target: n.Target, Aliases: n.Aliases}) - } - - task := types.Task{ - ID: t.ID, - Annotations: types.Annotations{ - Name: t.Annotations.Name, - Labels: t.Annotations.Labels, - }, - ServiceID: t.ServiceID, - Slot: int(t.Slot), - NodeID: t.NodeID, - Spec: types.TaskSpec{ - ContainerSpec: containerSpecFromGRPC(containerConfig), - Resources: resourcesFromGRPC(t.Spec.Resources), - RestartPolicy: restartPolicyFromGRPC(t.Spec.Restart), - Placement: placementFromGRPC(t.Spec.Placement), - LogDriver: driverFromGRPC(t.Spec.LogDriver), - Networks: networks, - }, - Status: types.TaskStatus{ - State: types.TaskState(strings.ToLower(t.Status.State.String())), - Message: t.Status.Message, - Err: t.Status.Err, - }, - DesiredState: types.TaskState(strings.ToLower(t.DesiredState.String())), - } - - // Meta - task.Version.Index = t.Meta.Version.Index - task.CreatedAt, _ = ptypes.Timestamp(t.Meta.CreatedAt) - task.UpdatedAt, _ = ptypes.Timestamp(t.Meta.UpdatedAt) - - task.Status.Timestamp, _ = ptypes.Timestamp(t.Status.Timestamp) - - if containerStatus != nil { - task.Status.ContainerStatus.ContainerID = containerStatus.ContainerID - task.Status.ContainerStatus.PID = int(containerStatus.PID) - task.Status.ContainerStatus.ExitCode = int(containerStatus.ExitCode) - } - - // NetworksAttachments - for _, na := range t.Networks { - task.NetworksAttachments = append(task.NetworksAttachments, networkAttachementFromGRPC(na)) - } - - if t.Status.PortStatus == nil { - return task - } - - for _, p := range t.Status.PortStatus.Ports { - task.Status.PortStatus.Ports = append(task.Status.PortStatus.Ports, types.PortConfig{ - Name: p.Name, - Protocol: types.PortConfigProtocol(strings.ToLower(swarmapi.PortConfig_Protocol_name[int32(p.Protocol)])), - PublishMode: types.PortConfigPublishMode(strings.ToLower(swarmapi.PortConfig_PublishMode_name[int32(p.PublishMode)])), - TargetPort: p.TargetPort, - PublishedPort: p.PublishedPort, - }) - } - - return task -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/backend.go b/vendor/github.com/docker/docker/daemon/cluster/executor/backend.go deleted file mode 100644 index 0f1da38..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/backend.go +++ /dev/null @@ -1,61 +0,0 @@ -package executor - -import ( - "io" - "time" - - "github.com/docker/distribution" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/network" - swarmtypes "github.com/docker/docker/api/types/swarm" - clustertypes "github.com/docker/docker/daemon/cluster/provider" - "github.com/docker/docker/plugin" - "github.com/docker/docker/reference" - "github.com/docker/libnetwork" - "github.com/docker/libnetwork/cluster" - networktypes "github.com/docker/libnetwork/types" - "github.com/docker/swarmkit/agent/exec" - "golang.org/x/net/context" -) - -// Backend defines the executor component for a swarm agent. -type Backend interface { - CreateManagedNetwork(clustertypes.NetworkCreateRequest) error - DeleteManagedNetwork(name string) error - FindNetwork(idName string) (libnetwork.Network, error) - SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error - PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error - CreateManagedContainer(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error) - ContainerStart(name string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error - ContainerStop(name string, seconds *int) error - ContainerLogs(context.Context, string, *backend.ContainerLogsConfig, chan struct{}) error - ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error - ActivateContainerServiceBinding(containerName string) error - DeactivateContainerServiceBinding(containerName string) error - UpdateContainerServiceConfig(containerName string, serviceConfig *clustertypes.ServiceConfig) error - ContainerInspectCurrent(name string, size bool) (*types.ContainerJSON, error) - ContainerWaitWithContext(ctx context.Context, name string) error - ContainerRm(name string, config *types.ContainerRmConfig) error - ContainerKill(name string, sig uint64) error - SetContainerSecretStore(name string, store exec.SecretGetter) error - SetContainerSecretReferences(name string, refs []*swarmtypes.SecretReference) error - SystemInfo() (*types.Info, error) - VolumeCreate(name, driverName string, opts, labels map[string]string) (*types.Volume, error) - Containers(config *types.ContainerListOptions) ([]*types.Container, error) - SetNetworkBootstrapKeys([]*networktypes.EncryptionKey) error - DaemonJoinsCluster(provider cluster.Provider) - DaemonLeavesCluster() - IsSwarmCompatible() error - SubscribeToEvents(since, until time.Time, filter filters.Args) ([]events.Message, chan interface{}) - UnsubscribeFromEvents(listener chan interface{}) - UpdateAttachment(string, string, string, *network.NetworkingConfig) error - WaitForDetachment(context.Context, string, string, string, string) error - GetRepository(context.Context, reference.NamedTagged, *types.AuthConfig) (distribution.Repository, bool, error) - LookupImage(name string) (*types.ImageInspect, error) - PluginManager() *plugin.Manager - PluginGetter() *plugin.Store -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/adapter.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/adapter.go deleted file mode 100644 index f82f8b5..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/adapter.go +++ /dev/null @@ -1,463 +0,0 @@ -package container - -import ( - "encoding/base64" - "encoding/json" - "fmt" - "io" - "os" - "strings" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/daemon/cluster/convert" - executorpkg "github.com/docker/docker/daemon/cluster/executor" - "github.com/docker/docker/reference" - "github.com/docker/libnetwork" - "github.com/docker/swarmkit/agent/exec" - "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/log" - "github.com/docker/swarmkit/protobuf/ptypes" - "golang.org/x/net/context" - "golang.org/x/time/rate" -) - -// containerAdapter conducts remote operations for a container. All calls -// are mostly naked calls to the client API, seeded with information from -// containerConfig. -type containerAdapter struct { - backend executorpkg.Backend - container *containerConfig - secrets exec.SecretGetter -} - -func newContainerAdapter(b executorpkg.Backend, task *api.Task, secrets exec.SecretGetter) (*containerAdapter, error) { - ctnr, err := newContainerConfig(task) - if err != nil { - return nil, err - } - - return &containerAdapter{ - container: ctnr, - backend: b, - secrets: secrets, - }, nil -} - -func (c *containerAdapter) pullImage(ctx context.Context) error { - spec := c.container.spec() - - // Skip pulling if the image is referenced by image ID. - if _, err := digest.ParseDigest(spec.Image); err == nil { - return nil - } - - // Skip pulling if the image is referenced by digest and already - // exists locally. - named, err := reference.ParseNamed(spec.Image) - if err == nil { - if _, ok := named.(reference.Canonical); ok { - _, err := c.backend.LookupImage(spec.Image) - if err == nil { - return nil - } - } - } - - // if the image needs to be pulled, the auth config will be retrieved and updated - var encodedAuthConfig string - if spec.PullOptions != nil { - encodedAuthConfig = spec.PullOptions.RegistryAuth - } - - authConfig := &types.AuthConfig{} - if encodedAuthConfig != "" { - if err := json.NewDecoder(base64.NewDecoder(base64.URLEncoding, strings.NewReader(encodedAuthConfig))).Decode(authConfig); err != nil { - logrus.Warnf("invalid authconfig: %v", err) - } - } - - pr, pw := io.Pipe() - metaHeaders := map[string][]string{} - go func() { - err := c.backend.PullImage(ctx, c.container.image(), "", metaHeaders, authConfig, pw) - pw.CloseWithError(err) - }() - - dec := json.NewDecoder(pr) - dec.UseNumber() - m := map[string]interface{}{} - spamLimiter := rate.NewLimiter(rate.Every(time.Second), 1) - - lastStatus := "" - for { - if err := dec.Decode(&m); err != nil { - if err == io.EOF { - break - } - return err - } - l := log.G(ctx) - // limit pull progress logs unless the status changes - if spamLimiter.Allow() || lastStatus != m["status"] { - // if we have progress details, we have everything we need - if progress, ok := m["progressDetail"].(map[string]interface{}); ok { - // first, log the image and status - l = l.WithFields(logrus.Fields{ - "image": c.container.image(), - "status": m["status"], - }) - // then, if we have progress, log the progress - if progress["current"] != nil && progress["total"] != nil { - l = l.WithFields(logrus.Fields{ - "current": progress["current"], - "total": progress["total"], - }) - } - } - l.Debug("pull in progress") - } - // sometimes, we get no useful information at all, and add no fields - if status, ok := m["status"].(string); ok { - lastStatus = status - } - } - - // if the final stream object contained an error, return it - if errMsg, ok := m["error"]; ok { - return fmt.Errorf("%v", errMsg) - } - return nil -} - -func (c *containerAdapter) createNetworks(ctx context.Context) error { - for _, network := range c.container.networks() { - ncr, err := c.container.networkCreateRequest(network) - if err != nil { - return err - } - - if err := c.backend.CreateManagedNetwork(ncr); err != nil { // todo name missing - if _, ok := err.(libnetwork.NetworkNameError); ok { - continue - } - - return err - } - } - - return nil -} - -func (c *containerAdapter) removeNetworks(ctx context.Context) error { - for _, nid := range c.container.networks() { - if err := c.backend.DeleteManagedNetwork(nid); err != nil { - switch err.(type) { - case *libnetwork.ActiveEndpointsError: - continue - case libnetwork.ErrNoSuchNetwork: - continue - default: - log.G(ctx).Errorf("network %s remove failed: %v", nid, err) - return err - } - } - } - - return nil -} - -func (c *containerAdapter) networkAttach(ctx context.Context) error { - config := c.container.createNetworkingConfig() - - var ( - networkName string - networkID string - ) - - if config != nil { - for n, epConfig := range config.EndpointsConfig { - networkName = n - networkID = epConfig.NetworkID - break - } - } - - return c.backend.UpdateAttachment(networkName, networkID, c.container.id(), config) -} - -func (c *containerAdapter) waitForDetach(ctx context.Context) error { - config := c.container.createNetworkingConfig() - - var ( - networkName string - networkID string - ) - - if config != nil { - for n, epConfig := range config.EndpointsConfig { - networkName = n - networkID = epConfig.NetworkID - break - } - } - - return c.backend.WaitForDetachment(ctx, networkName, networkID, c.container.taskID(), c.container.id()) -} - -func (c *containerAdapter) create(ctx context.Context) error { - var cr containertypes.ContainerCreateCreatedBody - var err error - - if cr, err = c.backend.CreateManagedContainer(types.ContainerCreateConfig{ - Name: c.container.name(), - Config: c.container.config(), - HostConfig: c.container.hostConfig(), - // Use the first network in container create - NetworkingConfig: c.container.createNetworkingConfig(), - }); err != nil { - return err - } - - // Docker daemon currently doesn't support multiple networks in container create - // Connect to all other networks - nc := c.container.connectNetworkingConfig() - - if nc != nil { - for n, ep := range nc.EndpointsConfig { - if err := c.backend.ConnectContainerToNetwork(cr.ID, n, ep); err != nil { - return err - } - } - } - - container := c.container.task.Spec.GetContainer() - if container == nil { - return fmt.Errorf("unable to get container from task spec") - } - - // configure secrets - if err := c.backend.SetContainerSecretStore(cr.ID, c.secrets); err != nil { - return err - } - - refs := convert.SecretReferencesFromGRPC(container.Secrets) - if err := c.backend.SetContainerSecretReferences(cr.ID, refs); err != nil { - return err - } - - if err := c.backend.UpdateContainerServiceConfig(cr.ID, c.container.serviceConfig()); err != nil { - return err - } - - return nil -} - -// checkMounts ensures that the provided mounts won't have any host-specific -// problems at start up. For example, we disallow bind mounts without an -// existing path, which slightly different from the container API. -func (c *containerAdapter) checkMounts() error { - spec := c.container.spec() - for _, mount := range spec.Mounts { - switch mount.Type { - case api.MountTypeBind: - if _, err := os.Stat(mount.Source); os.IsNotExist(err) { - return fmt.Errorf("invalid bind mount source, source path not found: %s", mount.Source) - } - } - } - - return nil -} - -func (c *containerAdapter) start(ctx context.Context) error { - if err := c.checkMounts(); err != nil { - return err - } - - return c.backend.ContainerStart(c.container.name(), nil, "", "") -} - -func (c *containerAdapter) inspect(ctx context.Context) (types.ContainerJSON, error) { - cs, err := c.backend.ContainerInspectCurrent(c.container.name(), false) - if ctx.Err() != nil { - return types.ContainerJSON{}, ctx.Err() - } - if err != nil { - return types.ContainerJSON{}, err - } - return *cs, nil -} - -// events issues a call to the events API and returns a channel with all -// events. The stream of events can be shutdown by cancelling the context. -func (c *containerAdapter) events(ctx context.Context) <-chan events.Message { - log.G(ctx).Debugf("waiting on events") - buffer, l := c.backend.SubscribeToEvents(time.Time{}, time.Time{}, c.container.eventFilter()) - eventsq := make(chan events.Message, len(buffer)) - - for _, event := range buffer { - eventsq <- event - } - - go func() { - defer c.backend.UnsubscribeFromEvents(l) - - for { - select { - case ev := <-l: - jev, ok := ev.(events.Message) - if !ok { - log.G(ctx).Warnf("unexpected event message: %q", ev) - continue - } - select { - case eventsq <- jev: - case <-ctx.Done(): - return - } - case <-ctx.Done(): - return - } - } - }() - - return eventsq -} - -func (c *containerAdapter) wait(ctx context.Context) error { - return c.backend.ContainerWaitWithContext(ctx, c.container.nameOrID()) -} - -func (c *containerAdapter) shutdown(ctx context.Context) error { - // Default stop grace period to nil (daemon will use the stopTimeout of the container) - var stopgrace *int - spec := c.container.spec() - if spec.StopGracePeriod != nil { - stopgraceValue := int(spec.StopGracePeriod.Seconds) - stopgrace = &stopgraceValue - } - return c.backend.ContainerStop(c.container.name(), stopgrace) -} - -func (c *containerAdapter) terminate(ctx context.Context) error { - return c.backend.ContainerKill(c.container.name(), uint64(syscall.SIGKILL)) -} - -func (c *containerAdapter) remove(ctx context.Context) error { - return c.backend.ContainerRm(c.container.name(), &types.ContainerRmConfig{ - RemoveVolume: true, - ForceRemove: true, - }) -} - -func (c *containerAdapter) createVolumes(ctx context.Context) error { - // Create plugin volumes that are embedded inside a Mount - for _, mount := range c.container.task.Spec.GetContainer().Mounts { - if mount.Type != api.MountTypeVolume { - continue - } - - if mount.VolumeOptions == nil { - continue - } - - if mount.VolumeOptions.DriverConfig == nil { - continue - } - - req := c.container.volumeCreateRequest(&mount) - - // Check if this volume exists on the engine - if _, err := c.backend.VolumeCreate(req.Name, req.Driver, req.DriverOpts, req.Labels); err != nil { - // TODO(amitshukla): Today, volume create through the engine api does not return an error - // when the named volume with the same parameters already exists. - // It returns an error if the driver name is different - that is a valid error - return err - } - - } - - return nil -} - -func (c *containerAdapter) activateServiceBinding() error { - return c.backend.ActivateContainerServiceBinding(c.container.name()) -} - -func (c *containerAdapter) deactivateServiceBinding() error { - return c.backend.DeactivateContainerServiceBinding(c.container.name()) -} - -func (c *containerAdapter) logs(ctx context.Context, options api.LogSubscriptionOptions) (io.ReadCloser, error) { - reader, writer := io.Pipe() - - apiOptions := &backend.ContainerLogsConfig{ - ContainerLogsOptions: types.ContainerLogsOptions{ - Follow: options.Follow, - - // TODO(stevvooe): Parse timestamp out of message. This - // absolutely needs to be done before going to production with - // this, at it is completely redundant. - Timestamps: true, - Details: false, // no clue what to do with this, let's just deprecate it. - }, - OutStream: writer, - } - - if options.Since != nil { - since, err := ptypes.Timestamp(options.Since) - if err != nil { - return nil, err - } - apiOptions.Since = since.Format(time.RFC3339Nano) - } - - if options.Tail < 0 { - // See protobuf documentation for details of how this works. - apiOptions.Tail = fmt.Sprint(-options.Tail - 1) - } else if options.Tail > 0 { - return nil, fmt.Errorf("tail relative to start of logs not supported via docker API") - } - - if len(options.Streams) == 0 { - // empty == all - apiOptions.ShowStdout, apiOptions.ShowStderr = true, true - } else { - for _, stream := range options.Streams { - switch stream { - case api.LogStreamStdout: - apiOptions.ShowStdout = true - case api.LogStreamStderr: - apiOptions.ShowStderr = true - } - } - } - - chStarted := make(chan struct{}) - go func() { - defer writer.Close() - c.backend.ContainerLogs(ctx, c.container.name(), apiOptions, chStarted) - }() - - return reader, nil -} - -// todo: typed/wrapped errors -func isContainerCreateNameConflict(err error) bool { - return strings.Contains(err.Error(), "Conflict. The name") -} - -func isUnknownContainer(err error) bool { - return strings.Contains(err.Error(), "No such container:") -} - -func isStoppedContainer(err error) bool { - return strings.Contains(err.Error(), "is already stopped") -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/attachment.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/attachment.go deleted file mode 100644 index e0ee81a..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/attachment.go +++ /dev/null @@ -1,81 +0,0 @@ -package container - -import ( - executorpkg "github.com/docker/docker/daemon/cluster/executor" - "github.com/docker/swarmkit/agent/exec" - "github.com/docker/swarmkit/api" - "golang.org/x/net/context" -) - -// networkAttacherController implements agent.Controller against docker's API. -// -// networkAttacherController manages the lifecycle of network -// attachment of a docker unmanaged container managed as a task from -// agent point of view. It provides network attachment information to -// the unmanaged container for it to attach to the network and run. -type networkAttacherController struct { - backend executorpkg.Backend - task *api.Task - adapter *containerAdapter - closed chan struct{} -} - -func newNetworkAttacherController(b executorpkg.Backend, task *api.Task, secrets exec.SecretGetter) (*networkAttacherController, error) { - adapter, err := newContainerAdapter(b, task, secrets) - if err != nil { - return nil, err - } - - return &networkAttacherController{ - backend: b, - task: task, - adapter: adapter, - closed: make(chan struct{}), - }, nil -} - -func (nc *networkAttacherController) Update(ctx context.Context, t *api.Task) error { - return nil -} - -func (nc *networkAttacherController) Prepare(ctx context.Context) error { - // Make sure all the networks that the task needs are created. - if err := nc.adapter.createNetworks(ctx); err != nil { - return err - } - - return nil -} - -func (nc *networkAttacherController) Start(ctx context.Context) error { - return nc.adapter.networkAttach(ctx) -} - -func (nc *networkAttacherController) Wait(pctx context.Context) error { - ctx, cancel := context.WithCancel(pctx) - defer cancel() - - return nc.adapter.waitForDetach(ctx) -} - -func (nc *networkAttacherController) Shutdown(ctx context.Context) error { - return nil -} - -func (nc *networkAttacherController) Terminate(ctx context.Context) error { - return nil -} - -func (nc *networkAttacherController) Remove(ctx context.Context) error { - // Try removing the network referenced in this task in case this - // task is the last one referencing it - if err := nc.adapter.removeNetworks(ctx); err != nil { - return err - } - - return nil -} - -func (nc *networkAttacherController) Close() error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/container.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/container.go deleted file mode 100644 index f033ad5..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/container.go +++ /dev/null @@ -1,598 +0,0 @@ -package container - -import ( - "errors" - "fmt" - "net" - "strconv" - "strings" - "time" - - "github.com/Sirupsen/logrus" - - "github.com/docker/docker/api/types" - enginecontainer "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" - enginemount "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/api/types/network" - volumetypes "github.com/docker/docker/api/types/volume" - clustertypes "github.com/docker/docker/daemon/cluster/provider" - "github.com/docker/docker/reference" - "github.com/docker/go-connections/nat" - "github.com/docker/swarmkit/agent/exec" - "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/protobuf/ptypes" - "github.com/docker/swarmkit/template" -) - -const ( - // Explicitly use the kernel's default setting for CPU quota of 100ms. - // https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt - cpuQuotaPeriod = 100 * time.Millisecond - - // systemLabelPrefix represents the reserved namespace for system labels. - systemLabelPrefix = "com.docker.swarm" -) - -// containerConfig converts task properties into docker container compatible -// components. -type containerConfig struct { - task *api.Task - networksAttachments map[string]*api.NetworkAttachment -} - -// newContainerConfig returns a validated container config. No methods should -// return an error if this function returns without error. -func newContainerConfig(t *api.Task) (*containerConfig, error) { - var c containerConfig - return &c, c.setTask(t) -} - -func (c *containerConfig) setTask(t *api.Task) error { - if t.Spec.GetContainer() == nil && t.Spec.GetAttachment() == nil { - return exec.ErrRuntimeUnsupported - } - - container := t.Spec.GetContainer() - if container != nil { - if container.Image == "" { - return ErrImageRequired - } - - if err := validateMounts(container.Mounts); err != nil { - return err - } - } - - // index the networks by name - c.networksAttachments = make(map[string]*api.NetworkAttachment, len(t.Networks)) - for _, attachment := range t.Networks { - c.networksAttachments[attachment.Network.Spec.Annotations.Name] = attachment - } - - c.task = t - - if t.Spec.GetContainer() != nil { - preparedSpec, err := template.ExpandContainerSpec(t) - if err != nil { - return err - } - c.task.Spec.Runtime = &api.TaskSpec_Container{ - Container: preparedSpec, - } - } - - return nil -} - -func (c *containerConfig) id() string { - attachment := c.task.Spec.GetAttachment() - if attachment == nil { - return "" - } - - return attachment.ContainerID -} - -func (c *containerConfig) taskID() string { - return c.task.ID -} - -func (c *containerConfig) endpoint() *api.Endpoint { - return c.task.Endpoint -} - -func (c *containerConfig) spec() *api.ContainerSpec { - return c.task.Spec.GetContainer() -} - -func (c *containerConfig) nameOrID() string { - if c.task.Spec.GetContainer() != nil { - return c.name() - } - - return c.id() -} - -func (c *containerConfig) name() string { - if c.task.Annotations.Name != "" { - // if set, use the container Annotations.Name field, set in the orchestrator. - return c.task.Annotations.Name - } - - slot := fmt.Sprint(c.task.Slot) - if slot == "" || c.task.Slot == 0 { - slot = c.task.NodeID - } - - // fallback to service.slot.id. - return fmt.Sprintf("%s.%s.%s", c.task.ServiceAnnotations.Name, slot, c.task.ID) -} - -func (c *containerConfig) image() string { - raw := c.spec().Image - ref, err := reference.ParseNamed(raw) - if err != nil { - return raw - } - return reference.WithDefaultTag(ref).String() -} - -func (c *containerConfig) portBindings() nat.PortMap { - portBindings := nat.PortMap{} - if c.task.Endpoint == nil { - return portBindings - } - - for _, portConfig := range c.task.Endpoint.Ports { - if portConfig.PublishMode != api.PublishModeHost { - continue - } - - port := nat.Port(fmt.Sprintf("%d/%s", portConfig.TargetPort, strings.ToLower(portConfig.Protocol.String()))) - binding := []nat.PortBinding{ - {}, - } - - if portConfig.PublishedPort != 0 { - binding[0].HostPort = strconv.Itoa(int(portConfig.PublishedPort)) - } - portBindings[port] = binding - } - - return portBindings -} - -func (c *containerConfig) exposedPorts() map[nat.Port]struct{} { - exposedPorts := make(map[nat.Port]struct{}) - if c.task.Endpoint == nil { - return exposedPorts - } - - for _, portConfig := range c.task.Endpoint.Ports { - if portConfig.PublishMode != api.PublishModeHost { - continue - } - - port := nat.Port(fmt.Sprintf("%d/%s", portConfig.TargetPort, strings.ToLower(portConfig.Protocol.String()))) - exposedPorts[port] = struct{}{} - } - - return exposedPorts -} - -func (c *containerConfig) config() *enginecontainer.Config { - config := &enginecontainer.Config{ - Labels: c.labels(), - Tty: c.spec().TTY, - OpenStdin: c.spec().OpenStdin, - User: c.spec().User, - Env: c.spec().Env, - Hostname: c.spec().Hostname, - WorkingDir: c.spec().Dir, - Image: c.image(), - ExposedPorts: c.exposedPorts(), - Healthcheck: c.healthcheck(), - } - - if len(c.spec().Command) > 0 { - // If Command is provided, we replace the whole invocation with Command - // by replacing Entrypoint and specifying Cmd. Args is ignored in this - // case. - config.Entrypoint = append(config.Entrypoint, c.spec().Command...) - config.Cmd = append(config.Cmd, c.spec().Args...) - } else if len(c.spec().Args) > 0 { - // In this case, we assume the image has an Entrypoint and Args - // specifies the arguments for that entrypoint. - config.Cmd = c.spec().Args - } - - return config -} - -func (c *containerConfig) labels() map[string]string { - var ( - system = map[string]string{ - "task": "", // mark as cluster task - "task.id": c.task.ID, - "task.name": c.name(), - "node.id": c.task.NodeID, - "service.id": c.task.ServiceID, - "service.name": c.task.ServiceAnnotations.Name, - } - labels = make(map[string]string) - ) - - // base labels are those defined in the spec. - for k, v := range c.spec().Labels { - labels[k] = v - } - - // we then apply the overrides from the task, which may be set via the - // orchestrator. - for k, v := range c.task.Annotations.Labels { - labels[k] = v - } - - // finally, we apply the system labels, which override all labels. - for k, v := range system { - labels[strings.Join([]string{systemLabelPrefix, k}, ".")] = v - } - - return labels -} - -func (c *containerConfig) mounts() []enginemount.Mount { - var r []enginemount.Mount - for _, mount := range c.spec().Mounts { - r = append(r, convertMount(mount)) - } - return r -} - -func convertMount(m api.Mount) enginemount.Mount { - mount := enginemount.Mount{ - Source: m.Source, - Target: m.Target, - ReadOnly: m.ReadOnly, - } - - switch m.Type { - case api.MountTypeBind: - mount.Type = enginemount.TypeBind - case api.MountTypeVolume: - mount.Type = enginemount.TypeVolume - case api.MountTypeTmpfs: - mount.Type = enginemount.TypeTmpfs - } - - if m.BindOptions != nil { - mount.BindOptions = &enginemount.BindOptions{} - switch m.BindOptions.Propagation { - case api.MountPropagationRPrivate: - mount.BindOptions.Propagation = enginemount.PropagationRPrivate - case api.MountPropagationPrivate: - mount.BindOptions.Propagation = enginemount.PropagationPrivate - case api.MountPropagationRSlave: - mount.BindOptions.Propagation = enginemount.PropagationRSlave - case api.MountPropagationSlave: - mount.BindOptions.Propagation = enginemount.PropagationSlave - case api.MountPropagationRShared: - mount.BindOptions.Propagation = enginemount.PropagationRShared - case api.MountPropagationShared: - mount.BindOptions.Propagation = enginemount.PropagationShared - } - } - - if m.VolumeOptions != nil { - mount.VolumeOptions = &enginemount.VolumeOptions{ - NoCopy: m.VolumeOptions.NoCopy, - } - if m.VolumeOptions.Labels != nil { - mount.VolumeOptions.Labels = make(map[string]string, len(m.VolumeOptions.Labels)) - for k, v := range m.VolumeOptions.Labels { - mount.VolumeOptions.Labels[k] = v - } - } - if m.VolumeOptions.DriverConfig != nil { - mount.VolumeOptions.DriverConfig = &enginemount.Driver{ - Name: m.VolumeOptions.DriverConfig.Name, - } - if m.VolumeOptions.DriverConfig.Options != nil { - mount.VolumeOptions.DriverConfig.Options = make(map[string]string, len(m.VolumeOptions.DriverConfig.Options)) - for k, v := range m.VolumeOptions.DriverConfig.Options { - mount.VolumeOptions.DriverConfig.Options[k] = v - } - } - } - } - - if m.TmpfsOptions != nil { - mount.TmpfsOptions = &enginemount.TmpfsOptions{ - SizeBytes: m.TmpfsOptions.SizeBytes, - Mode: m.TmpfsOptions.Mode, - } - } - - return mount -} - -func (c *containerConfig) healthcheck() *enginecontainer.HealthConfig { - hcSpec := c.spec().Healthcheck - if hcSpec == nil { - return nil - } - interval, _ := ptypes.Duration(hcSpec.Interval) - timeout, _ := ptypes.Duration(hcSpec.Timeout) - return &enginecontainer.HealthConfig{ - Test: hcSpec.Test, - Interval: interval, - Timeout: timeout, - Retries: int(hcSpec.Retries), - } -} - -func (c *containerConfig) hostConfig() *enginecontainer.HostConfig { - hc := &enginecontainer.HostConfig{ - Resources: c.resources(), - GroupAdd: c.spec().Groups, - PortBindings: c.portBindings(), - Mounts: c.mounts(), - } - - if c.spec().DNSConfig != nil { - hc.DNS = c.spec().DNSConfig.Nameservers - hc.DNSSearch = c.spec().DNSConfig.Search - hc.DNSOptions = c.spec().DNSConfig.Options - } - - // The format of extra hosts on swarmkit is specified in: - // http://man7.org/linux/man-pages/man5/hosts.5.html - // IP_address canonical_hostname [aliases...] - // However, the format of ExtraHosts in HostConfig is - // : - // We need to do the conversion here - // (Alias is ignored for now) - for _, entry := range c.spec().Hosts { - parts := strings.Fields(entry) - if len(parts) > 1 { - hc.ExtraHosts = append(hc.ExtraHosts, fmt.Sprintf("%s:%s", parts[1], parts[0])) - } - } - - if c.task.LogDriver != nil { - hc.LogConfig = enginecontainer.LogConfig{ - Type: c.task.LogDriver.Name, - Config: c.task.LogDriver.Options, - } - } - - return hc -} - -// This handles the case of volumes that are defined inside a service Mount -func (c *containerConfig) volumeCreateRequest(mount *api.Mount) *volumetypes.VolumesCreateBody { - var ( - driverName string - driverOpts map[string]string - labels map[string]string - ) - - if mount.VolumeOptions != nil && mount.VolumeOptions.DriverConfig != nil { - driverName = mount.VolumeOptions.DriverConfig.Name - driverOpts = mount.VolumeOptions.DriverConfig.Options - labels = mount.VolumeOptions.Labels - } - - if mount.VolumeOptions != nil { - return &volumetypes.VolumesCreateBody{ - Name: mount.Source, - Driver: driverName, - DriverOpts: driverOpts, - Labels: labels, - } - } - return nil -} - -func (c *containerConfig) resources() enginecontainer.Resources { - resources := enginecontainer.Resources{} - - // If no limits are specified let the engine use its defaults. - // - // TODO(aluzzardi): We might want to set some limits anyway otherwise - // "unlimited" tasks will step over the reservation of other tasks. - r := c.task.Spec.Resources - if r == nil || r.Limits == nil { - return resources - } - - if r.Limits.MemoryBytes > 0 { - resources.Memory = r.Limits.MemoryBytes - } - - if r.Limits.NanoCPUs > 0 { - // CPU Period must be set in microseconds. - resources.CPUPeriod = int64(cpuQuotaPeriod / time.Microsecond) - resources.CPUQuota = r.Limits.NanoCPUs * resources.CPUPeriod / 1e9 - } - - return resources -} - -// Docker daemon supports just 1 network during container create. -func (c *containerConfig) createNetworkingConfig() *network.NetworkingConfig { - var networks []*api.NetworkAttachment - if c.task.Spec.GetContainer() != nil || c.task.Spec.GetAttachment() != nil { - networks = c.task.Networks - } - - epConfig := make(map[string]*network.EndpointSettings) - if len(networks) > 0 { - epConfig[networks[0].Network.Spec.Annotations.Name] = getEndpointConfig(networks[0]) - } - - return &network.NetworkingConfig{EndpointsConfig: epConfig} -} - -// TODO: Merge this function with createNetworkingConfig after daemon supports multiple networks in container create -func (c *containerConfig) connectNetworkingConfig() *network.NetworkingConfig { - var networks []*api.NetworkAttachment - if c.task.Spec.GetContainer() != nil { - networks = c.task.Networks - } - - // First network is used during container create. Other networks are used in "docker network connect" - if len(networks) < 2 { - return nil - } - - epConfig := make(map[string]*network.EndpointSettings) - for _, na := range networks[1:] { - epConfig[na.Network.Spec.Annotations.Name] = getEndpointConfig(na) - } - return &network.NetworkingConfig{EndpointsConfig: epConfig} -} - -func getEndpointConfig(na *api.NetworkAttachment) *network.EndpointSettings { - var ipv4, ipv6 string - for _, addr := range na.Addresses { - ip, _, err := net.ParseCIDR(addr) - if err != nil { - continue - } - - if ip.To4() != nil { - ipv4 = ip.String() - continue - } - - if ip.To16() != nil { - ipv6 = ip.String() - } - } - - return &network.EndpointSettings{ - NetworkID: na.Network.ID, - IPAMConfig: &network.EndpointIPAMConfig{ - IPv4Address: ipv4, - IPv6Address: ipv6, - }, - } -} - -func (c *containerConfig) virtualIP(networkID string) string { - if c.task.Endpoint == nil { - return "" - } - - for _, eVip := range c.task.Endpoint.VirtualIPs { - // We only support IPv4 VIPs for now. - if eVip.NetworkID == networkID { - vip, _, err := net.ParseCIDR(eVip.Addr) - if err != nil { - return "" - } - - return vip.String() - } - } - - return "" -} - -func (c *containerConfig) serviceConfig() *clustertypes.ServiceConfig { - if len(c.task.Networks) == 0 { - return nil - } - - logrus.Debugf("Creating service config in agent for t = %+v", c.task) - svcCfg := &clustertypes.ServiceConfig{ - Name: c.task.ServiceAnnotations.Name, - Aliases: make(map[string][]string), - ID: c.task.ServiceID, - VirtualAddresses: make(map[string]*clustertypes.VirtualAddress), - } - - for _, na := range c.task.Networks { - svcCfg.VirtualAddresses[na.Network.ID] = &clustertypes.VirtualAddress{ - // We support only IPv4 virtual IP for now. - IPv4: c.virtualIP(na.Network.ID), - } - if len(na.Aliases) > 0 { - svcCfg.Aliases[na.Network.ID] = na.Aliases - } - } - - if c.task.Endpoint != nil { - for _, ePort := range c.task.Endpoint.Ports { - if ePort.PublishMode != api.PublishModeIngress { - continue - } - - svcCfg.ExposedPorts = append(svcCfg.ExposedPorts, &clustertypes.PortConfig{ - Name: ePort.Name, - Protocol: int32(ePort.Protocol), - TargetPort: ePort.TargetPort, - PublishedPort: ePort.PublishedPort, - }) - } - } - - return svcCfg -} - -// networks returns a list of network names attached to the container. The -// returned name can be used to lookup the corresponding network create -// options. -func (c *containerConfig) networks() []string { - var networks []string - - for name := range c.networksAttachments { - networks = append(networks, name) - } - - return networks -} - -func (c *containerConfig) networkCreateRequest(name string) (clustertypes.NetworkCreateRequest, error) { - na, ok := c.networksAttachments[name] - if !ok { - return clustertypes.NetworkCreateRequest{}, errors.New("container: unknown network referenced") - } - - options := types.NetworkCreate{ - // ID: na.Network.ID, - Driver: na.Network.DriverState.Name, - IPAM: &network.IPAM{ - Driver: na.Network.IPAM.Driver.Name, - Options: na.Network.IPAM.Driver.Options, - }, - Options: na.Network.DriverState.Options, - Labels: na.Network.Spec.Annotations.Labels, - Internal: na.Network.Spec.Internal, - Attachable: na.Network.Spec.Attachable, - EnableIPv6: na.Network.Spec.Ipv6Enabled, - CheckDuplicate: true, - } - - for _, ic := range na.Network.IPAM.Configs { - c := network.IPAMConfig{ - Subnet: ic.Subnet, - IPRange: ic.Range, - Gateway: ic.Gateway, - } - options.IPAM.Config = append(options.IPAM.Config, c) - } - - return clustertypes.NetworkCreateRequest{na.Network.ID, types.NetworkCreateRequest{Name: name, NetworkCreate: options}}, nil -} - -func (c containerConfig) eventFilter() filters.Args { - filter := filters.NewArgs() - filter.Add("type", events.ContainerEventType) - filter.Add("name", c.name()) - filter.Add("label", fmt.Sprintf("%v.task.id=%v", systemLabelPrefix, c.task.ID)) - return filter -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/controller.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/controller.go deleted file mode 100644 index 75f286a..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/controller.go +++ /dev/null @@ -1,672 +0,0 @@ -package container - -import ( - "bufio" - "bytes" - "encoding/binary" - "fmt" - "io" - "os" - "strconv" - "strings" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/events" - executorpkg "github.com/docker/docker/daemon/cluster/executor" - "github.com/docker/go-connections/nat" - "github.com/docker/libnetwork" - "github.com/docker/swarmkit/agent/exec" - "github.com/docker/swarmkit/api" - "github.com/docker/swarmkit/log" - "github.com/docker/swarmkit/protobuf/ptypes" - "github.com/pkg/errors" - "golang.org/x/net/context" - "golang.org/x/time/rate" -) - -// controller implements agent.Controller against docker's API. -// -// Most operations against docker's API are done through the container name, -// which is unique to the task. -type controller struct { - task *api.Task - adapter *containerAdapter - closed chan struct{} - err error - - pulled chan struct{} // closed after pull - cancelPull func() // cancels pull context if not nil - pullErr error // pull error, only read after pulled closed -} - -var _ exec.Controller = &controller{} - -// NewController returns a docker exec runner for the provided task. -func newController(b executorpkg.Backend, task *api.Task, secrets exec.SecretGetter) (*controller, error) { - adapter, err := newContainerAdapter(b, task, secrets) - if err != nil { - return nil, err - } - - return &controller{ - task: task, - adapter: adapter, - closed: make(chan struct{}), - }, nil -} - -func (r *controller) Task() (*api.Task, error) { - return r.task, nil -} - -// ContainerStatus returns the container-specific status for the task. -func (r *controller) ContainerStatus(ctx context.Context) (*api.ContainerStatus, error) { - ctnr, err := r.adapter.inspect(ctx) - if err != nil { - if isUnknownContainer(err) { - return nil, nil - } - return nil, err - } - return parseContainerStatus(ctnr) -} - -func (r *controller) PortStatus(ctx context.Context) (*api.PortStatus, error) { - ctnr, err := r.adapter.inspect(ctx) - if err != nil { - if isUnknownContainer(err) { - return nil, nil - } - - return nil, err - } - - return parsePortStatus(ctnr) -} - -// Update tasks a recent task update and applies it to the container. -func (r *controller) Update(ctx context.Context, t *api.Task) error { - // TODO(stevvooe): While assignment of tasks is idempotent, we do allow - // updates of metadata, such as labelling, as well as any other properties - // that make sense. - return nil -} - -// Prepare creates a container and ensures the image is pulled. -// -// If the container has already be created, exec.ErrTaskPrepared is returned. -func (r *controller) Prepare(ctx context.Context) error { - if err := r.checkClosed(); err != nil { - return err - } - - // Make sure all the networks that the task needs are created. - if err := r.adapter.createNetworks(ctx); err != nil { - return err - } - - // Make sure all the volumes that the task needs are created. - if err := r.adapter.createVolumes(ctx); err != nil { - return err - } - - if os.Getenv("DOCKER_SERVICE_PREFER_OFFLINE_IMAGE") != "1" { - if r.pulled == nil { - // Fork the pull to a different context to allow pull to continue - // on re-entrant calls to Prepare. This ensures that Prepare can be - // idempotent and not incur the extra cost of pulling when - // cancelled on updates. - var pctx context.Context - - r.pulled = make(chan struct{}) - pctx, r.cancelPull = context.WithCancel(context.Background()) // TODO(stevvooe): Bind a context to the entire controller. - - go func() { - defer close(r.pulled) - r.pullErr = r.adapter.pullImage(pctx) // protected by closing r.pulled - }() - } - - select { - case <-ctx.Done(): - return ctx.Err() - case <-r.pulled: - if r.pullErr != nil { - // NOTE(stevvooe): We always try to pull the image to make sure we have - // the most up to date version. This will return an error, but we only - // log it. If the image truly doesn't exist, the create below will - // error out. - // - // This gives us some nice behavior where we use up to date versions of - // mutable tags, but will still run if the old image is available but a - // registry is down. - // - // If you don't want this behavior, lock down your image to an - // immutable tag or digest. - log.G(ctx).WithError(r.pullErr).Error("pulling image failed") - } - } - } - - if err := r.adapter.create(ctx); err != nil { - if isContainerCreateNameConflict(err) { - if _, err := r.adapter.inspect(ctx); err != nil { - return err - } - - // container is already created. success! - return exec.ErrTaskPrepared - } - - return err - } - - return nil -} - -// Start the container. An error will be returned if the container is already started. -func (r *controller) Start(ctx context.Context) error { - if err := r.checkClosed(); err != nil { - return err - } - - ctnr, err := r.adapter.inspect(ctx) - if err != nil { - return err - } - - // Detect whether the container has *ever* been started. If so, we don't - // issue the start. - // - // TODO(stevvooe): This is very racy. While reading inspect, another could - // start the process and we could end up starting it twice. - if ctnr.State.Status != "created" { - return exec.ErrTaskStarted - } - - for { - if err := r.adapter.start(ctx); err != nil { - if _, ok := err.(libnetwork.ErrNoSuchNetwork); ok { - // Retry network creation again if we - // failed because some of the networks - // were not found. - if err := r.adapter.createNetworks(ctx); err != nil { - return err - } - - continue - } - - return errors.Wrap(err, "starting container failed") - } - - break - } - - // no health check - if ctnr.Config == nil || ctnr.Config.Healthcheck == nil { - if err := r.adapter.activateServiceBinding(); err != nil { - log.G(ctx).WithError(err).Errorf("failed to activate service binding for container %s which has no healthcheck config", r.adapter.container.name()) - return err - } - return nil - } - - healthCmd := ctnr.Config.Healthcheck.Test - - if len(healthCmd) == 0 || healthCmd[0] == "NONE" { - return nil - } - - // wait for container to be healthy - eventq := r.adapter.events(ctx) - - var healthErr error - for { - select { - case event := <-eventq: - if !r.matchevent(event) { - continue - } - - switch event.Action { - case "die": // exit on terminal events - ctnr, err := r.adapter.inspect(ctx) - if err != nil { - return errors.Wrap(err, "die event received") - } else if ctnr.State.ExitCode != 0 { - return &exitError{code: ctnr.State.ExitCode, cause: healthErr} - } - - return nil - case "destroy": - // If we get here, something has gone wrong but we want to exit - // and report anyways. - return ErrContainerDestroyed - case "health_status: unhealthy": - // in this case, we stop the container and report unhealthy status - if err := r.Shutdown(ctx); err != nil { - return errors.Wrap(err, "unhealthy container shutdown failed") - } - // set health check error, and wait for container to fully exit ("die" event) - healthErr = ErrContainerUnhealthy - case "health_status: healthy": - if err := r.adapter.activateServiceBinding(); err != nil { - log.G(ctx).WithError(err).Errorf("failed to activate service binding for container %s after healthy event", r.adapter.container.name()) - return err - } - return nil - } - case <-ctx.Done(): - return ctx.Err() - case <-r.closed: - return r.err - } - } -} - -// Wait on the container to exit. -func (r *controller) Wait(pctx context.Context) error { - if err := r.checkClosed(); err != nil { - return err - } - - ctx, cancel := context.WithCancel(pctx) - defer cancel() - - healthErr := make(chan error, 1) - go func() { - ectx, cancel := context.WithCancel(ctx) // cancel event context on first event - defer cancel() - if err := r.checkHealth(ectx); err == ErrContainerUnhealthy { - healthErr <- ErrContainerUnhealthy - if err := r.Shutdown(ectx); err != nil { - log.G(ectx).WithError(err).Debug("shutdown failed on unhealthy") - } - } - }() - - err := r.adapter.wait(ctx) - if ctx.Err() != nil { - return ctx.Err() - } - - if err != nil { - ee := &exitError{} - if ec, ok := err.(exec.ExitCoder); ok { - ee.code = ec.ExitCode() - } - select { - case e := <-healthErr: - ee.cause = e - default: - if err.Error() != "" { - ee.cause = err - } - } - return ee - } - - return nil -} - -// Shutdown the container cleanly. -func (r *controller) Shutdown(ctx context.Context) error { - if err := r.checkClosed(); err != nil { - return err - } - - if r.cancelPull != nil { - r.cancelPull() - } - - // remove container from service binding - if err := r.adapter.deactivateServiceBinding(); err != nil { - log.G(ctx).WithError(err).Errorf("failed to deactivate service binding for container %s", r.adapter.container.name()) - return err - } - - if err := r.adapter.shutdown(ctx); err != nil { - if isUnknownContainer(err) || isStoppedContainer(err) { - return nil - } - - return err - } - - return nil -} - -// Terminate the container, with force. -func (r *controller) Terminate(ctx context.Context) error { - if err := r.checkClosed(); err != nil { - return err - } - - if r.cancelPull != nil { - r.cancelPull() - } - - if err := r.adapter.terminate(ctx); err != nil { - if isUnknownContainer(err) { - return nil - } - - return err - } - - return nil -} - -// Remove the container and its resources. -func (r *controller) Remove(ctx context.Context) error { - if err := r.checkClosed(); err != nil { - return err - } - - if r.cancelPull != nil { - r.cancelPull() - } - - // It may be necessary to shut down the task before removing it. - if err := r.Shutdown(ctx); err != nil { - if isUnknownContainer(err) { - return nil - } - // This may fail if the task was already shut down. - log.G(ctx).WithError(err).Debug("shutdown failed on removal") - } - - // Try removing networks referenced in this task in case this - // task is the last one referencing it - if err := r.adapter.removeNetworks(ctx); err != nil { - if isUnknownContainer(err) { - return nil - } - return err - } - - if err := r.adapter.remove(ctx); err != nil { - if isUnknownContainer(err) { - return nil - } - - return err - } - return nil -} - -// waitReady waits for a container to be "ready". -// Ready means it's past the started state. -func (r *controller) waitReady(pctx context.Context) error { - if err := r.checkClosed(); err != nil { - return err - } - - ctx, cancel := context.WithCancel(pctx) - defer cancel() - - eventq := r.adapter.events(ctx) - - ctnr, err := r.adapter.inspect(ctx) - if err != nil { - if !isUnknownContainer(err) { - return errors.Wrap(err, "inspect container failed") - } - } else { - switch ctnr.State.Status { - case "running", "exited", "dead": - return nil - } - } - - for { - select { - case event := <-eventq: - if !r.matchevent(event) { - continue - } - - switch event.Action { - case "start": - return nil - } - case <-ctx.Done(): - return ctx.Err() - case <-r.closed: - return r.err - } - } -} - -func (r *controller) Logs(ctx context.Context, publisher exec.LogPublisher, options api.LogSubscriptionOptions) error { - if err := r.checkClosed(); err != nil { - return err - } - - if err := r.waitReady(ctx); err != nil { - return errors.Wrap(err, "container not ready for logs") - } - - rc, err := r.adapter.logs(ctx, options) - if err != nil { - return errors.Wrap(err, "failed getting container logs") - } - defer rc.Close() - - var ( - // use a rate limiter to keep things under control but also provides some - // ability coalesce messages. - limiter = rate.NewLimiter(rate.Every(time.Second), 10<<20) // 10 MB/s - msgctx = api.LogContext{ - NodeID: r.task.NodeID, - ServiceID: r.task.ServiceID, - TaskID: r.task.ID, - } - ) - - brd := bufio.NewReader(rc) - for { - // so, message header is 8 bytes, treat as uint64, pull stream off MSB - var header uint64 - if err := binary.Read(brd, binary.BigEndian, &header); err != nil { - if err == io.EOF { - return nil - } - - return errors.Wrap(err, "failed reading log header") - } - - stream, size := (header>>(7<<3))&0xFF, header & ^(uint64(0xFF)<<(7<<3)) - - // limit here to decrease allocation back pressure. - if err := limiter.WaitN(ctx, int(size)); err != nil { - return errors.Wrap(err, "failed rate limiter") - } - - buf := make([]byte, size) - _, err := io.ReadFull(brd, buf) - if err != nil { - return errors.Wrap(err, "failed reading buffer") - } - - // Timestamp is RFC3339Nano with 1 space after. Lop, parse, publish - parts := bytes.SplitN(buf, []byte(" "), 2) - if len(parts) != 2 { - return fmt.Errorf("invalid timestamp in log message: %v", buf) - } - - ts, err := time.Parse(time.RFC3339Nano, string(parts[0])) - if err != nil { - return errors.Wrap(err, "failed to parse timestamp") - } - - tsp, err := ptypes.TimestampProto(ts) - if err != nil { - return errors.Wrap(err, "failed to convert timestamp") - } - - if err := publisher.Publish(ctx, api.LogMessage{ - Context: msgctx, - Timestamp: tsp, - Stream: api.LogStream(stream), - - Data: parts[1], - }); err != nil { - return errors.Wrap(err, "failed to publish log message") - } - } -} - -// Close the runner and clean up any ephemeral resources. -func (r *controller) Close() error { - select { - case <-r.closed: - return r.err - default: - if r.cancelPull != nil { - r.cancelPull() - } - - r.err = exec.ErrControllerClosed - close(r.closed) - } - return nil -} - -func (r *controller) matchevent(event events.Message) bool { - if event.Type != events.ContainerEventType { - return false - } - - // TODO(stevvooe): Filter based on ID matching, in addition to name. - - // Make sure the events are for this container. - if event.Actor.Attributes["name"] != r.adapter.container.name() { - return false - } - - return true -} - -func (r *controller) checkClosed() error { - select { - case <-r.closed: - return r.err - default: - return nil - } -} - -func parseContainerStatus(ctnr types.ContainerJSON) (*api.ContainerStatus, error) { - status := &api.ContainerStatus{ - ContainerID: ctnr.ID, - PID: int32(ctnr.State.Pid), - ExitCode: int32(ctnr.State.ExitCode), - } - - return status, nil -} - -func parsePortStatus(ctnr types.ContainerJSON) (*api.PortStatus, error) { - status := &api.PortStatus{} - - if ctnr.NetworkSettings != nil && len(ctnr.NetworkSettings.Ports) > 0 { - exposedPorts, err := parsePortMap(ctnr.NetworkSettings.Ports) - if err != nil { - return nil, err - } - status.Ports = exposedPorts - } - - return status, nil -} - -func parsePortMap(portMap nat.PortMap) ([]*api.PortConfig, error) { - exposedPorts := make([]*api.PortConfig, 0, len(portMap)) - - for portProtocol, mapping := range portMap { - parts := strings.SplitN(string(portProtocol), "/", 2) - if len(parts) != 2 { - return nil, fmt.Errorf("invalid port mapping: %s", portProtocol) - } - - port, err := strconv.ParseUint(parts[0], 10, 16) - if err != nil { - return nil, err - } - - protocol := api.ProtocolTCP - switch strings.ToLower(parts[1]) { - case "tcp": - protocol = api.ProtocolTCP - case "udp": - protocol = api.ProtocolUDP - default: - return nil, fmt.Errorf("invalid protocol: %s", parts[1]) - } - - for _, binding := range mapping { - hostPort, err := strconv.ParseUint(binding.HostPort, 10, 16) - if err != nil { - return nil, err - } - - // TODO(aluzzardi): We're losing the port `name` here since - // there's no way to retrieve it back from the Engine. - exposedPorts = append(exposedPorts, &api.PortConfig{ - PublishMode: api.PublishModeHost, - Protocol: protocol, - TargetPort: uint32(port), - PublishedPort: uint32(hostPort), - }) - } - } - - return exposedPorts, nil -} - -type exitError struct { - code int - cause error -} - -func (e *exitError) Error() string { - if e.cause != nil { - return fmt.Sprintf("task: non-zero exit (%v): %v", e.code, e.cause) - } - - return fmt.Sprintf("task: non-zero exit (%v)", e.code) -} - -func (e *exitError) ExitCode() int { - return int(e.code) -} - -func (e *exitError) Cause() error { - return e.cause -} - -// checkHealth blocks until unhealthy container is detected or ctx exits -func (r *controller) checkHealth(ctx context.Context) error { - eventq := r.adapter.events(ctx) - - for { - select { - case <-ctx.Done(): - return nil - case <-r.closed: - return nil - case event := <-eventq: - if !r.matchevent(event) { - continue - } - - switch event.Action { - case "health_status: unhealthy": - return ErrContainerUnhealthy - } - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/errors.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/errors.go deleted file mode 100644 index 63e1233..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/errors.go +++ /dev/null @@ -1,15 +0,0 @@ -package container - -import "fmt" - -var ( - // ErrImageRequired returned if a task is missing the image definition. - ErrImageRequired = fmt.Errorf("dockerexec: image required") - - // ErrContainerDestroyed returned when a container is prematurely destroyed - // during a wait call. - ErrContainerDestroyed = fmt.Errorf("dockerexec: container destroyed") - - // ErrContainerUnhealthy returned if controller detects the health check failure - ErrContainerUnhealthy = fmt.Errorf("dockerexec: unhealthy container") -) diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/executor.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/executor.go deleted file mode 100644 index f0dedd4..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/executor.go +++ /dev/null @@ -1,194 +0,0 @@ -package container - -import ( - "sort" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/network" - executorpkg "github.com/docker/docker/daemon/cluster/executor" - clustertypes "github.com/docker/docker/daemon/cluster/provider" - networktypes "github.com/docker/libnetwork/types" - "github.com/docker/swarmkit/agent/exec" - "github.com/docker/swarmkit/agent/secrets" - "github.com/docker/swarmkit/api" - "golang.org/x/net/context" -) - -type executor struct { - backend executorpkg.Backend - secrets exec.SecretsManager -} - -// NewExecutor returns an executor from the docker client. -func NewExecutor(b executorpkg.Backend) exec.Executor { - return &executor{ - backend: b, - secrets: secrets.NewManager(), - } -} - -// Describe returns the underlying node description from the docker client. -func (e *executor) Describe(ctx context.Context) (*api.NodeDescription, error) { - info, err := e.backend.SystemInfo() - if err != nil { - return nil, err - } - - plugins := map[api.PluginDescription]struct{}{} - addPlugins := func(typ string, names []string) { - for _, name := range names { - plugins[api.PluginDescription{ - Type: typ, - Name: name, - }] = struct{}{} - } - } - - // add v1 plugins - addPlugins("Volume", info.Plugins.Volume) - // Add builtin driver "overlay" (the only builtin multi-host driver) to - // the plugin list by default. - addPlugins("Network", append([]string{"overlay"}, info.Plugins.Network...)) - addPlugins("Authorization", info.Plugins.Authorization) - - // add v2 plugins - v2Plugins, err := e.backend.PluginManager().List() - if err == nil { - for _, plgn := range v2Plugins { - for _, typ := range plgn.Config.Interface.Types { - if typ.Prefix != "docker" || !plgn.Enabled { - continue - } - plgnTyp := typ.Capability - if typ.Capability == "volumedriver" { - plgnTyp = "Volume" - } else if typ.Capability == "networkdriver" { - plgnTyp = "Network" - } - plugins[api.PluginDescription{ - Type: plgnTyp, - Name: plgn.Name, - }] = struct{}{} - } - } - } - - pluginFields := make([]api.PluginDescription, 0, len(plugins)) - for k := range plugins { - pluginFields = append(pluginFields, k) - } - - sort.Sort(sortedPlugins(pluginFields)) - - // parse []string labels into a map[string]string - labels := map[string]string{} - for _, l := range info.Labels { - stringSlice := strings.SplitN(l, "=", 2) - // this will take the last value in the list for a given key - // ideally, one shouldn't assign multiple values to the same key - if len(stringSlice) > 1 { - labels[stringSlice[0]] = stringSlice[1] - } - } - - description := &api.NodeDescription{ - Hostname: info.Name, - Platform: &api.Platform{ - Architecture: info.Architecture, - OS: info.OSType, - }, - Engine: &api.EngineDescription{ - EngineVersion: info.ServerVersion, - Labels: labels, - Plugins: pluginFields, - }, - Resources: &api.Resources{ - NanoCPUs: int64(info.NCPU) * 1e9, - MemoryBytes: info.MemTotal, - }, - } - - return description, nil -} - -func (e *executor) Configure(ctx context.Context, node *api.Node) error { - na := node.Attachment - if na == nil { - return nil - } - - options := types.NetworkCreate{ - Driver: na.Network.DriverState.Name, - IPAM: &network.IPAM{ - Driver: na.Network.IPAM.Driver.Name, - }, - Options: na.Network.DriverState.Options, - CheckDuplicate: true, - } - - for _, ic := range na.Network.IPAM.Configs { - c := network.IPAMConfig{ - Subnet: ic.Subnet, - IPRange: ic.Range, - Gateway: ic.Gateway, - } - options.IPAM.Config = append(options.IPAM.Config, c) - } - - return e.backend.SetupIngress(clustertypes.NetworkCreateRequest{ - na.Network.ID, - types.NetworkCreateRequest{ - Name: na.Network.Spec.Annotations.Name, - NetworkCreate: options, - }, - }, na.Addresses[0]) -} - -// Controller returns a docker container runner. -func (e *executor) Controller(t *api.Task) (exec.Controller, error) { - if t.Spec.GetAttachment() != nil { - return newNetworkAttacherController(e.backend, t, e.secrets) - } - - ctlr, err := newController(e.backend, t, e.secrets) - if err != nil { - return nil, err - } - - return ctlr, nil -} - -func (e *executor) SetNetworkBootstrapKeys(keys []*api.EncryptionKey) error { - nwKeys := []*networktypes.EncryptionKey{} - for _, key := range keys { - nwKey := &networktypes.EncryptionKey{ - Subsystem: key.Subsystem, - Algorithm: int32(key.Algorithm), - Key: make([]byte, len(key.Key)), - LamportTime: key.LamportTime, - } - copy(nwKey.Key, key.Key) - nwKeys = append(nwKeys, nwKey) - } - e.backend.SetNetworkBootstrapKeys(nwKeys) - - return nil -} - -func (e *executor) Secrets() exec.SecretsManager { - return e.secrets -} - -type sortedPlugins []api.PluginDescription - -func (sp sortedPlugins) Len() int { return len(sp) } - -func (sp sortedPlugins) Swap(i, j int) { sp[i], sp[j] = sp[j], sp[i] } - -func (sp sortedPlugins) Less(i, j int) bool { - if sp[i].Type != sp[j].Type { - return sp[i].Type < sp[j].Type - } - return sp[i].Name < sp[j].Name -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/health_test.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/health_test.go deleted file mode 100644 index 99cf750..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/health_test.go +++ /dev/null @@ -1,102 +0,0 @@ -// +build !windows - -package container - -import ( - "testing" - "time" - - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon" - "github.com/docker/docker/daemon/events" - "github.com/docker/swarmkit/api" - "golang.org/x/net/context" -) - -func TestHealthStates(t *testing.T) { - - // set up environment: events, task, container .... - e := events.New() - _, l, _ := e.Subscribe() - defer e.Evict(l) - - task := &api.Task{ - ID: "id", - ServiceID: "sid", - Spec: api.TaskSpec{ - Runtime: &api.TaskSpec_Container{ - Container: &api.ContainerSpec{ - Image: "image_name", - Labels: map[string]string{ - "com.docker.swarm.task.id": "id", - }, - }, - }, - }, - Annotations: api.Annotations{Name: "name"}, - } - - c := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "id", - Name: "name", - Config: &containertypes.Config{ - Image: "image_name", - Labels: map[string]string{ - "com.docker.swarm.task.id": "id", - }, - }, - }, - } - - daemon := &daemon.Daemon{ - EventsService: e, - } - - controller, err := newController(daemon, task, nil) - if err != nil { - t.Fatalf("create controller fail %v", err) - } - - errChan := make(chan error, 1) - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - // fire checkHealth - go func() { - err := controller.checkHealth(ctx) - select { - case errChan <- err: - case <-ctx.Done(): - } - }() - - // send an event and expect to get expectedErr - // if expectedErr is nil, shouldn't get any error - logAndExpect := func(msg string, expectedErr error) { - daemon.LogContainerEvent(c, msg) - - timer := time.NewTimer(1 * time.Second) - defer timer.Stop() - - select { - case err := <-errChan: - if err != expectedErr { - t.Fatalf("expect error %v, but get %v", expectedErr, err) - } - case <-timer.C: - if expectedErr != nil { - t.Fatalf("time limit exceeded, didn't get expected error") - } - } - } - - // events that are ignored by checkHealth - logAndExpect("health_status: running", nil) - logAndExpect("health_status: healthy", nil) - logAndExpect("die", nil) - - // unhealthy event will be caught by checkHealth - logAndExpect("health_status: unhealthy", ErrContainerUnhealthy) -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate.go deleted file mode 100644 index 5fda1f2..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate.go +++ /dev/null @@ -1,39 +0,0 @@ -package container - -import ( - "fmt" - "path/filepath" - - "github.com/docker/swarmkit/api" -) - -func validateMounts(mounts []api.Mount) error { - for _, mount := range mounts { - // Target must always be absolute - if !filepath.IsAbs(mount.Target) { - return fmt.Errorf("invalid mount target, must be an absolute path: %s", mount.Target) - } - - switch mount.Type { - // The checks on abs paths are required due to the container API confusing - // volume mounts as bind mounts when the source is absolute (and vice-versa) - // See #25253 - // TODO: This is probably not necessary once #22373 is merged - case api.MountTypeBind: - if !filepath.IsAbs(mount.Source) { - return fmt.Errorf("invalid bind mount source, must be an absolute path: %s", mount.Source) - } - case api.MountTypeVolume: - if filepath.IsAbs(mount.Source) { - return fmt.Errorf("invalid volume mount source, must not be an absolute path: %s", mount.Source) - } - case api.MountTypeTmpfs: - if mount.Source != "" { - return fmt.Errorf("invalid tmpfs source, source must be empty") - } - default: - return fmt.Errorf("invalid mount type: %s", mount.Type) - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate_test.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate_test.go deleted file mode 100644 index 9d98e2c..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate_test.go +++ /dev/null @@ -1,141 +0,0 @@ -package container - -import ( - "io/ioutil" - "os" - "strings" - "testing" - - "github.com/docker/docker/daemon" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/swarmkit/api" -) - -func newTestControllerWithMount(m api.Mount) (*controller, error) { - return newController(&daemon.Daemon{}, &api.Task{ - ID: stringid.GenerateRandomID(), - ServiceID: stringid.GenerateRandomID(), - Spec: api.TaskSpec{ - Runtime: &api.TaskSpec_Container{ - Container: &api.ContainerSpec{ - Image: "image_name", - Labels: map[string]string{ - "com.docker.swarm.task.id": "id", - }, - Mounts: []api.Mount{m}, - }, - }, - }, - }, nil) -} - -func TestControllerValidateMountBind(t *testing.T) { - // with improper source - if _, err := newTestControllerWithMount(api.Mount{ - Type: api.MountTypeBind, - Source: "foo", - Target: testAbsPath, - }); err == nil || !strings.Contains(err.Error(), "invalid bind mount source") { - t.Fatalf("expected error, got: %v", err) - } - - // with non-existing source - if _, err := newTestControllerWithMount(api.Mount{ - Type: api.MountTypeBind, - Source: testAbsNonExistent, - Target: testAbsPath, - }); err != nil { - t.Fatalf("controller should not error at creation: %v", err) - } - - // with proper source - tmpdir, err := ioutil.TempDir("", "TestControllerValidateMountBind") - if err != nil { - t.Fatalf("failed to create temp dir: %v", err) - } - defer os.Remove(tmpdir) - - if _, err := newTestControllerWithMount(api.Mount{ - Type: api.MountTypeBind, - Source: tmpdir, - Target: testAbsPath, - }); err != nil { - t.Fatalf("expected error, got: %v", err) - } -} - -func TestControllerValidateMountVolume(t *testing.T) { - // with improper source - if _, err := newTestControllerWithMount(api.Mount{ - Type: api.MountTypeVolume, - Source: testAbsPath, - Target: testAbsPath, - }); err == nil || !strings.Contains(err.Error(), "invalid volume mount source") { - t.Fatalf("expected error, got: %v", err) - } - - // with proper source - if _, err := newTestControllerWithMount(api.Mount{ - Type: api.MountTypeVolume, - Source: "foo", - Target: testAbsPath, - }); err != nil { - t.Fatalf("expected error, got: %v", err) - } -} - -func TestControllerValidateMountTarget(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestControllerValidateMountTarget") - if err != nil { - t.Fatalf("failed to create temp dir: %v", err) - } - defer os.Remove(tmpdir) - - // with improper target - if _, err := newTestControllerWithMount(api.Mount{ - Type: api.MountTypeBind, - Source: testAbsPath, - Target: "foo", - }); err == nil || !strings.Contains(err.Error(), "invalid mount target") { - t.Fatalf("expected error, got: %v", err) - } - - // with proper target - if _, err := newTestControllerWithMount(api.Mount{ - Type: api.MountTypeBind, - Source: tmpdir, - Target: testAbsPath, - }); err != nil { - t.Fatalf("expected no error, got: %v", err) - } -} - -func TestControllerValidateMountTmpfs(t *testing.T) { - // with improper target - if _, err := newTestControllerWithMount(api.Mount{ - Type: api.MountTypeTmpfs, - Source: "foo", - Target: testAbsPath, - }); err == nil || !strings.Contains(err.Error(), "invalid tmpfs source") { - t.Fatalf("expected error, got: %v", err) - } - - // with proper target - if _, err := newTestControllerWithMount(api.Mount{ - Type: api.MountTypeTmpfs, - Target: testAbsPath, - }); err != nil { - t.Fatalf("expected no error, got: %v", err) - } -} - -func TestControllerValidateMountInvalidType(t *testing.T) { - // with improper target - if _, err := newTestControllerWithMount(api.Mount{ - Type: api.Mount_MountType(9999), - Source: "foo", - Target: testAbsPath, - }); err == nil || !strings.Contains(err.Error(), "invalid mount type") { - t.Fatalf("expected error, got: %v", err) - } -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate_unix_test.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate_unix_test.go deleted file mode 100644 index c616eee..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate_unix_test.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !windows - -package container - -const ( - testAbsPath = "/foo" - testAbsNonExistent = "/some-non-existing-host-path/" -) diff --git a/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate_windows_test.go b/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate_windows_test.go deleted file mode 100644 index c346451..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/executor/container/validate_windows_test.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build windows - -package container - -const ( - testAbsPath = `c:\foo` - testAbsNonExistent = `c:\some-non-existing-host-path\` -) diff --git a/vendor/github.com/docker/docker/daemon/cluster/filters.go b/vendor/github.com/docker/docker/daemon/cluster/filters.go deleted file mode 100644 index 88668ed..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/filters.go +++ /dev/null @@ -1,116 +0,0 @@ -package cluster - -import ( - "fmt" - "strings" - - "github.com/docker/docker/api/types/filters" - runconfigopts "github.com/docker/docker/runconfig/opts" - swarmapi "github.com/docker/swarmkit/api" -) - -func newListNodesFilters(filter filters.Args) (*swarmapi.ListNodesRequest_Filters, error) { - accepted := map[string]bool{ - "name": true, - "id": true, - "label": true, - "role": true, - "membership": true, - } - if err := filter.Validate(accepted); err != nil { - return nil, err - } - f := &swarmapi.ListNodesRequest_Filters{ - NamePrefixes: filter.Get("name"), - IDPrefixes: filter.Get("id"), - Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")), - } - - for _, r := range filter.Get("role") { - if role, ok := swarmapi.NodeRole_value[strings.ToUpper(r)]; ok { - f.Roles = append(f.Roles, swarmapi.NodeRole(role)) - } else if r != "" { - return nil, fmt.Errorf("Invalid role filter: '%s'", r) - } - } - - for _, a := range filter.Get("membership") { - if membership, ok := swarmapi.NodeSpec_Membership_value[strings.ToUpper(a)]; ok { - f.Memberships = append(f.Memberships, swarmapi.NodeSpec_Membership(membership)) - } else if a != "" { - return nil, fmt.Errorf("Invalid membership filter: '%s'", a) - } - } - - return f, nil -} - -func newListServicesFilters(filter filters.Args) (*swarmapi.ListServicesRequest_Filters, error) { - accepted := map[string]bool{ - "name": true, - "id": true, - "label": true, - } - if err := filter.Validate(accepted); err != nil { - return nil, err - } - return &swarmapi.ListServicesRequest_Filters{ - NamePrefixes: filter.Get("name"), - IDPrefixes: filter.Get("id"), - Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")), - }, nil -} - -func newListTasksFilters(filter filters.Args, transformFunc func(filters.Args) error) (*swarmapi.ListTasksRequest_Filters, error) { - accepted := map[string]bool{ - "name": true, - "id": true, - "label": true, - "service": true, - "node": true, - "desired-state": true, - } - if err := filter.Validate(accepted); err != nil { - return nil, err - } - if transformFunc != nil { - if err := transformFunc(filter); err != nil { - return nil, err - } - } - f := &swarmapi.ListTasksRequest_Filters{ - NamePrefixes: filter.Get("name"), - IDPrefixes: filter.Get("id"), - Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")), - ServiceIDs: filter.Get("service"), - NodeIDs: filter.Get("node"), - } - - for _, s := range filter.Get("desired-state") { - if state, ok := swarmapi.TaskState_value[strings.ToUpper(s)]; ok { - f.DesiredStates = append(f.DesiredStates, swarmapi.TaskState(state)) - } else if s != "" { - return nil, fmt.Errorf("Invalid desired-state filter: '%s'", s) - } - } - - return f, nil -} - -func newListSecretsFilters(filter filters.Args) (*swarmapi.ListSecretsRequest_Filters, error) { - accepted := map[string]bool{ - "names": true, - "name": true, - "id": true, - "label": true, - } - if err := filter.Validate(accepted); err != nil { - return nil, err - } - return &swarmapi.ListSecretsRequest_Filters{ - Names: filter.Get("names"), - NamePrefixes: filter.Get("name"), - IDPrefixes: filter.Get("id"), - Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")), - }, nil -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/helpers.go b/vendor/github.com/docker/docker/daemon/cluster/helpers.go deleted file mode 100644 index be5bf56..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/helpers.go +++ /dev/null @@ -1,108 +0,0 @@ -package cluster - -import ( - "fmt" - - swarmapi "github.com/docker/swarmkit/api" - "golang.org/x/net/context" -) - -func getSwarm(ctx context.Context, c swarmapi.ControlClient) (*swarmapi.Cluster, error) { - rl, err := c.ListClusters(ctx, &swarmapi.ListClustersRequest{}) - if err != nil { - return nil, err - } - - if len(rl.Clusters) == 0 { - return nil, fmt.Errorf("swarm not found") - } - - // TODO: assume one cluster only - return rl.Clusters[0], nil -} - -func getNode(ctx context.Context, c swarmapi.ControlClient, input string) (*swarmapi.Node, error) { - // GetNode to match via full ID. - rg, err := c.GetNode(ctx, &swarmapi.GetNodeRequest{NodeID: input}) - if err != nil { - // If any error (including NotFound), ListNodes to match via full name. - rl, err := c.ListNodes(ctx, &swarmapi.ListNodesRequest{Filters: &swarmapi.ListNodesRequest_Filters{Names: []string{input}}}) - - if err != nil || len(rl.Nodes) == 0 { - // If any error or 0 result, ListNodes to match via ID prefix. - rl, err = c.ListNodes(ctx, &swarmapi.ListNodesRequest{Filters: &swarmapi.ListNodesRequest_Filters{IDPrefixes: []string{input}}}) - } - - if err != nil { - return nil, err - } - - if len(rl.Nodes) == 0 { - return nil, fmt.Errorf("node %s not found", input) - } - - if l := len(rl.Nodes); l > 1 { - return nil, fmt.Errorf("node %s is ambiguous (%d matches found)", input, l) - } - - return rl.Nodes[0], nil - } - return rg.Node, nil -} - -func getService(ctx context.Context, c swarmapi.ControlClient, input string) (*swarmapi.Service, error) { - // GetService to match via full ID. - rg, err := c.GetService(ctx, &swarmapi.GetServiceRequest{ServiceID: input}) - if err != nil { - // If any error (including NotFound), ListServices to match via full name. - rl, err := c.ListServices(ctx, &swarmapi.ListServicesRequest{Filters: &swarmapi.ListServicesRequest_Filters{Names: []string{input}}}) - if err != nil || len(rl.Services) == 0 { - // If any error or 0 result, ListServices to match via ID prefix. - rl, err = c.ListServices(ctx, &swarmapi.ListServicesRequest{Filters: &swarmapi.ListServicesRequest_Filters{IDPrefixes: []string{input}}}) - } - - if err != nil { - return nil, err - } - - if len(rl.Services) == 0 { - return nil, fmt.Errorf("service %s not found", input) - } - - if l := len(rl.Services); l > 1 { - return nil, fmt.Errorf("service %s is ambiguous (%d matches found)", input, l) - } - - return rl.Services[0], nil - } - return rg.Service, nil -} - -func getTask(ctx context.Context, c swarmapi.ControlClient, input string) (*swarmapi.Task, error) { - // GetTask to match via full ID. - rg, err := c.GetTask(ctx, &swarmapi.GetTaskRequest{TaskID: input}) - if err != nil { - // If any error (including NotFound), ListTasks to match via full name. - rl, err := c.ListTasks(ctx, &swarmapi.ListTasksRequest{Filters: &swarmapi.ListTasksRequest_Filters{Names: []string{input}}}) - - if err != nil || len(rl.Tasks) == 0 { - // If any error or 0 result, ListTasks to match via ID prefix. - rl, err = c.ListTasks(ctx, &swarmapi.ListTasksRequest{Filters: &swarmapi.ListTasksRequest_Filters{IDPrefixes: []string{input}}}) - } - - if err != nil { - return nil, err - } - - if len(rl.Tasks) == 0 { - return nil, fmt.Errorf("task %s not found", input) - } - - if l := len(rl.Tasks); l > 1 { - return nil, fmt.Errorf("task %s is ambiguous (%d matches found)", input, l) - } - - return rl.Tasks[0], nil - } - return rg.Task, nil -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/listen_addr.go b/vendor/github.com/docker/docker/daemon/cluster/listen_addr.go deleted file mode 100644 index c24d486..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/listen_addr.go +++ /dev/null @@ -1,278 +0,0 @@ -package cluster - -import ( - "errors" - "fmt" - "net" -) - -var ( - errNoSuchInterface = errors.New("no such interface") - errNoIP = errors.New("could not find the system's IP address") - errMustSpecifyListenAddr = errors.New("must specify a listening address because the address to advertise is not recognized as a system address, and a system's IP address to use could not be uniquely identified") - errBadListenAddr = errors.New("listen address must be an IP address or network interface (with optional port number)") - errBadAdvertiseAddr = errors.New("advertise address must be a non-zero IP address or network interface (with optional port number)") - errBadDefaultAdvertiseAddr = errors.New("default advertise address must be a non-zero IP address or network interface (without a port number)") -) - -func resolveListenAddr(specifiedAddr string) (string, string, error) { - specifiedHost, specifiedPort, err := net.SplitHostPort(specifiedAddr) - if err != nil { - return "", "", fmt.Errorf("could not parse listen address %s", specifiedAddr) - } - - // Does the host component match any of the interface names on the - // system? If so, use the address from that interface. - interfaceAddr, err := resolveInterfaceAddr(specifiedHost) - if err == nil { - return interfaceAddr.String(), specifiedPort, nil - } - if err != errNoSuchInterface { - return "", "", err - } - - // If it's not an interface, it must be an IP (for now) - if net.ParseIP(specifiedHost) == nil { - return "", "", errBadListenAddr - } - - return specifiedHost, specifiedPort, nil -} - -func (c *Cluster) resolveAdvertiseAddr(advertiseAddr, listenAddrPort string) (string, string, error) { - // Approach: - // - If an advertise address is specified, use that. Resolve the - // interface's address if an interface was specified in - // advertiseAddr. Fill in the port from listenAddrPort if necessary. - // - If DefaultAdvertiseAddr is not empty, use that with the port from - // listenAddrPort. Resolve the interface's address from - // if an interface name was specified in DefaultAdvertiseAddr. - // - Otherwise, try to autodetect the system's address. Use the port in - // listenAddrPort with this address if autodetection succeeds. - - if advertiseAddr != "" { - advertiseHost, advertisePort, err := net.SplitHostPort(advertiseAddr) - if err != nil { - // Not a host:port specification - advertiseHost = advertiseAddr - advertisePort = listenAddrPort - } - - // Does the host component match any of the interface names on the - // system? If so, use the address from that interface. - interfaceAddr, err := resolveInterfaceAddr(advertiseHost) - if err == nil { - return interfaceAddr.String(), advertisePort, nil - } - if err != errNoSuchInterface { - return "", "", err - } - - // If it's not an interface, it must be an IP (for now) - if ip := net.ParseIP(advertiseHost); ip == nil || ip.IsUnspecified() { - return "", "", errBadAdvertiseAddr - } - - return advertiseHost, advertisePort, nil - } - - if c.config.DefaultAdvertiseAddr != "" { - // Does the default advertise address component match any of the - // interface names on the system? If so, use the address from - // that interface. - interfaceAddr, err := resolveInterfaceAddr(c.config.DefaultAdvertiseAddr) - if err == nil { - return interfaceAddr.String(), listenAddrPort, nil - } - if err != errNoSuchInterface { - return "", "", err - } - - // If it's not an interface, it must be an IP (for now) - if ip := net.ParseIP(c.config.DefaultAdvertiseAddr); ip == nil || ip.IsUnspecified() { - return "", "", errBadDefaultAdvertiseAddr - } - - return c.config.DefaultAdvertiseAddr, listenAddrPort, nil - } - - systemAddr, err := c.resolveSystemAddr() - if err != nil { - return "", "", err - } - return systemAddr.String(), listenAddrPort, nil -} - -func resolveInterfaceAddr(specifiedInterface string) (net.IP, error) { - // Use a specific interface's IP address. - intf, err := net.InterfaceByName(specifiedInterface) - if err != nil { - return nil, errNoSuchInterface - } - - addrs, err := intf.Addrs() - if err != nil { - return nil, err - } - - var interfaceAddr4, interfaceAddr6 net.IP - - for _, addr := range addrs { - ipAddr, ok := addr.(*net.IPNet) - - if ok { - if ipAddr.IP.To4() != nil { - // IPv4 - if interfaceAddr4 != nil { - return nil, fmt.Errorf("interface %s has more than one IPv4 address (%s and %s)", specifiedInterface, interfaceAddr4, ipAddr.IP) - } - interfaceAddr4 = ipAddr.IP - } else { - // IPv6 - if interfaceAddr6 != nil { - return nil, fmt.Errorf("interface %s has more than one IPv6 address (%s and %s)", specifiedInterface, interfaceAddr6, ipAddr.IP) - } - interfaceAddr6 = ipAddr.IP - } - } - } - - if interfaceAddr4 == nil && interfaceAddr6 == nil { - return nil, fmt.Errorf("interface %s has no usable IPv4 or IPv6 address", specifiedInterface) - } - - // In the case that there's exactly one IPv4 address - // and exactly one IPv6 address, favor IPv4 over IPv6. - if interfaceAddr4 != nil { - return interfaceAddr4, nil - } - return interfaceAddr6, nil -} - -func (c *Cluster) resolveSystemAddrViaSubnetCheck() (net.IP, error) { - // Use the system's only IP address, or fail if there are - // multiple addresses to choose from. Skip interfaces which - // are managed by docker via subnet check. - interfaces, err := net.Interfaces() - if err != nil { - return nil, err - } - - var systemAddr net.IP - var systemInterface string - - // List Docker-managed subnets - v4Subnets := c.config.NetworkSubnetsProvider.V4Subnets() - v6Subnets := c.config.NetworkSubnetsProvider.V6Subnets() - -ifaceLoop: - for _, intf := range interfaces { - // Skip inactive interfaces and loopback interfaces - if (intf.Flags&net.FlagUp == 0) || (intf.Flags&net.FlagLoopback) != 0 { - continue - } - - addrs, err := intf.Addrs() - if err != nil { - continue - } - - var interfaceAddr4, interfaceAddr6 net.IP - - for _, addr := range addrs { - ipAddr, ok := addr.(*net.IPNet) - - // Skip loopback and link-local addresses - if !ok || !ipAddr.IP.IsGlobalUnicast() { - continue - } - - if ipAddr.IP.To4() != nil { - // IPv4 - - // Ignore addresses in subnets that are managed by Docker. - for _, subnet := range v4Subnets { - if subnet.Contains(ipAddr.IP) { - continue ifaceLoop - } - } - - if interfaceAddr4 != nil { - return nil, errMultipleIPs(intf.Name, intf.Name, interfaceAddr4, ipAddr.IP) - } - - interfaceAddr4 = ipAddr.IP - } else { - // IPv6 - - // Ignore addresses in subnets that are managed by Docker. - for _, subnet := range v6Subnets { - if subnet.Contains(ipAddr.IP) { - continue ifaceLoop - } - } - - if interfaceAddr6 != nil { - return nil, errMultipleIPs(intf.Name, intf.Name, interfaceAddr6, ipAddr.IP) - } - - interfaceAddr6 = ipAddr.IP - } - } - - // In the case that this interface has exactly one IPv4 address - // and exactly one IPv6 address, favor IPv4 over IPv6. - if interfaceAddr4 != nil { - if systemAddr != nil { - return nil, errMultipleIPs(systemInterface, intf.Name, systemAddr, interfaceAddr4) - } - systemAddr = interfaceAddr4 - systemInterface = intf.Name - } else if interfaceAddr6 != nil { - if systemAddr != nil { - return nil, errMultipleIPs(systemInterface, intf.Name, systemAddr, interfaceAddr6) - } - systemAddr = interfaceAddr6 - systemInterface = intf.Name - } - } - - if systemAddr == nil { - return nil, errNoIP - } - - return systemAddr, nil -} - -func listSystemIPs() []net.IP { - interfaces, err := net.Interfaces() - if err != nil { - return nil - } - - var systemAddrs []net.IP - - for _, intf := range interfaces { - addrs, err := intf.Addrs() - if err != nil { - continue - } - - for _, addr := range addrs { - ipAddr, ok := addr.(*net.IPNet) - - if ok { - systemAddrs = append(systemAddrs, ipAddr.IP) - } - } - } - - return systemAddrs -} - -func errMultipleIPs(interfaceA, interfaceB string, addrA, addrB net.IP) error { - if interfaceA == interfaceB { - return fmt.Errorf("could not choose an IP address to advertise since this system has multiple addresses on interface %s (%s and %s)", interfaceA, addrA, addrB) - } - return fmt.Errorf("could not choose an IP address to advertise since this system has multiple addresses on different interfaces (%s on %s and %s on %s)", addrA, interfaceA, addrB, interfaceB) -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/listen_addr_linux.go b/vendor/github.com/docker/docker/daemon/cluster/listen_addr_linux.go deleted file mode 100644 index 3d4f239..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/listen_addr_linux.go +++ /dev/null @@ -1,91 +0,0 @@ -// +build linux - -package cluster - -import ( - "net" - - "github.com/vishvananda/netlink" -) - -func (c *Cluster) resolveSystemAddr() (net.IP, error) { - // Use the system's only device IP address, or fail if there are - // multiple addresses to choose from. - interfaces, err := netlink.LinkList() - if err != nil { - return nil, err - } - - var ( - systemAddr net.IP - systemInterface string - deviceFound bool - ) - - for _, intf := range interfaces { - // Skip non device or inactive interfaces - if intf.Type() != "device" || intf.Attrs().Flags&net.FlagUp == 0 { - continue - } - - addrs, err := netlink.AddrList(intf, netlink.FAMILY_ALL) - if err != nil { - continue - } - - var interfaceAddr4, interfaceAddr6 net.IP - - for _, addr := range addrs { - ipAddr := addr.IPNet.IP - - // Skip loopback and link-local addresses - if !ipAddr.IsGlobalUnicast() { - continue - } - - // At least one non-loopback device is found and it is administratively up - deviceFound = true - - if ipAddr.To4() != nil { - if interfaceAddr4 != nil { - return nil, errMultipleIPs(intf.Attrs().Name, intf.Attrs().Name, interfaceAddr4, ipAddr) - } - interfaceAddr4 = ipAddr - } else { - if interfaceAddr6 != nil { - return nil, errMultipleIPs(intf.Attrs().Name, intf.Attrs().Name, interfaceAddr6, ipAddr) - } - interfaceAddr6 = ipAddr - } - } - - // In the case that this interface has exactly one IPv4 address - // and exactly one IPv6 address, favor IPv4 over IPv6. - if interfaceAddr4 != nil { - if systemAddr != nil { - return nil, errMultipleIPs(systemInterface, intf.Attrs().Name, systemAddr, interfaceAddr4) - } - systemAddr = interfaceAddr4 - systemInterface = intf.Attrs().Name - } else if interfaceAddr6 != nil { - if systemAddr != nil { - return nil, errMultipleIPs(systemInterface, intf.Attrs().Name, systemAddr, interfaceAddr6) - } - systemAddr = interfaceAddr6 - systemInterface = intf.Attrs().Name - } - } - - if systemAddr == nil { - if !deviceFound { - // If no non-loopback device type interface is found, - // fall back to the regular auto-detection mechanism. - // This is to cover the case where docker is running - // inside a container (eths are in fact veths). - return c.resolveSystemAddrViaSubnetCheck() - } - return nil, errNoIP - } - - return systemAddr, nil -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/listen_addr_others.go b/vendor/github.com/docker/docker/daemon/cluster/listen_addr_others.go deleted file mode 100644 index 4e845f5..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/listen_addr_others.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build !linux,!solaris - -package cluster - -import "net" - -func (c *Cluster) resolveSystemAddr() (net.IP, error) { - return c.resolveSystemAddrViaSubnetCheck() -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/listen_addr_solaris.go b/vendor/github.com/docker/docker/daemon/cluster/listen_addr_solaris.go deleted file mode 100644 index 57a894b..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/listen_addr_solaris.go +++ /dev/null @@ -1,57 +0,0 @@ -package cluster - -import ( - "bufio" - "fmt" - "net" - "os/exec" - "strings" -) - -func (c *Cluster) resolveSystemAddr() (net.IP, error) { - defRouteCmd := "/usr/sbin/ipadm show-addr -p -o addr " + - "`/usr/sbin/route get default | /usr/bin/grep interface | " + - "/usr/bin/awk '{print $2}'`" - out, err := exec.Command("/usr/bin/bash", "-c", defRouteCmd).Output() - if err != nil { - return nil, fmt.Errorf("cannot get default route: %v", err) - } - - defInterface := strings.SplitN(string(out), "/", 2) - defInterfaceIP := net.ParseIP(defInterface[0]) - - return defInterfaceIP, nil -} - -func listSystemIPs() []net.IP { - var systemAddrs []net.IP - cmd := exec.Command("/usr/sbin/ipadm", "show-addr", "-p", "-o", "addr") - cmdReader, err := cmd.StdoutPipe() - if err != nil { - return nil - } - - if err := cmd.Start(); err != nil { - return nil - } - - scanner := bufio.NewScanner(cmdReader) - go func() { - for scanner.Scan() { - text := scanner.Text() - nameAddrPair := strings.SplitN(text, "/", 2) - // Let go of loopback interfaces and docker interfaces - systemAddrs = append(systemAddrs, net.ParseIP(nameAddrPair[0])) - } - }() - - if err := scanner.Err(); err != nil { - fmt.Printf("scan underwent err: %+v\n", err) - } - - if err := cmd.Wait(); err != nil { - fmt.Printf("run command wait: %+v\n", err) - } - - return systemAddrs -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/provider/network.go b/vendor/github.com/docker/docker/daemon/cluster/provider/network.go deleted file mode 100644 index f4c72ae..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/provider/network.go +++ /dev/null @@ -1,37 +0,0 @@ -package provider - -import "github.com/docker/docker/api/types" - -// NetworkCreateRequest is a request when creating a network. -type NetworkCreateRequest struct { - ID string - types.NetworkCreateRequest -} - -// NetworkCreateResponse is a response when creating a network. -type NetworkCreateResponse struct { - ID string `json:"Id"` -} - -// VirtualAddress represents a virtual address. -type VirtualAddress struct { - IPv4 string - IPv6 string -} - -// PortConfig represents a port configuration. -type PortConfig struct { - Name string - Protocol int32 - TargetPort uint32 - PublishedPort uint32 -} - -// ServiceConfig represents a service configuration. -type ServiceConfig struct { - ID string - Name string - Aliases map[string][]string - VirtualAddresses map[string]*VirtualAddress - ExposedPorts []*PortConfig -} diff --git a/vendor/github.com/docker/docker/daemon/cluster/secrets.go b/vendor/github.com/docker/docker/daemon/cluster/secrets.go deleted file mode 100644 index 2b9eb5d..0000000 --- a/vendor/github.com/docker/docker/daemon/cluster/secrets.go +++ /dev/null @@ -1,133 +0,0 @@ -package cluster - -import ( - apitypes "github.com/docker/docker/api/types" - types "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/daemon/cluster/convert" - swarmapi "github.com/docker/swarmkit/api" -) - -// GetSecret returns a secret from a managed swarm cluster -func (c *Cluster) GetSecret(id string) (types.Secret, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return types.Secret{}, c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - r, err := c.node.client.GetSecret(ctx, &swarmapi.GetSecretRequest{SecretID: id}) - if err != nil { - return types.Secret{}, err - } - - return convert.SecretFromGRPC(r.Secret), nil -} - -// GetSecrets returns all secrets of a managed swarm cluster. -func (c *Cluster) GetSecrets(options apitypes.SecretListOptions) ([]types.Secret, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return nil, c.errNoManager() - } - - filters, err := newListSecretsFilters(options.Filters) - if err != nil { - return nil, err - } - ctx, cancel := c.getRequestContext() - defer cancel() - - r, err := c.node.client.ListSecrets(ctx, - &swarmapi.ListSecretsRequest{Filters: filters}) - if err != nil { - return nil, err - } - - secrets := []types.Secret{} - - for _, secret := range r.Secrets { - secrets = append(secrets, convert.SecretFromGRPC(secret)) - } - - return secrets, nil -} - -// CreateSecret creates a new secret in a managed swarm cluster. -func (c *Cluster) CreateSecret(s types.SecretSpec) (string, error) { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return "", c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - secretSpec := convert.SecretSpecToGRPC(s) - - r, err := c.node.client.CreateSecret(ctx, - &swarmapi.CreateSecretRequest{Spec: &secretSpec}) - if err != nil { - return "", err - } - - return r.Secret.ID, nil -} - -// RemoveSecret removes a secret from a managed swarm cluster. -func (c *Cluster) RemoveSecret(id string) error { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - req := &swarmapi.RemoveSecretRequest{ - SecretID: id, - } - - if _, err := c.node.client.RemoveSecret(ctx, req); err != nil { - return err - } - return nil -} - -// UpdateSecret updates a secret in a managed swarm cluster. -// Note: this is not exposed to the CLI but is available from the API only -func (c *Cluster) UpdateSecret(id string, version uint64, spec types.SecretSpec) error { - c.RLock() - defer c.RUnlock() - - if !c.isActiveManager() { - return c.errNoManager() - } - - ctx, cancel := c.getRequestContext() - defer cancel() - - secretSpec := convert.SecretSpecToGRPC(spec) - - if _, err := c.client.UpdateSecret(ctx, - &swarmapi.UpdateSecretRequest{ - SecretID: id, - SecretVersion: &swarmapi.Version{ - Index: version, - }, - Spec: &secretSpec, - }); err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/commit.go b/vendor/github.com/docker/docker/daemon/commit.go deleted file mode 100644 index 1e7bffb..0000000 --- a/vendor/github.com/docker/docker/daemon/commit.go +++ /dev/null @@ -1,271 +0,0 @@ -package daemon - -import ( - "encoding/json" - "fmt" - "io" - "runtime" - "strings" - "time" - - "github.com/docker/docker/api/types/backend" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/builder/dockerfile" - "github.com/docker/docker/container" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/reference" -) - -// merge merges two Config, the image container configuration (defaults values), -// and the user container configuration, either passed by the API or generated -// by the cli. -// It will mutate the specified user configuration (userConf) with the image -// configuration where the user configuration is incomplete. -func merge(userConf, imageConf *containertypes.Config) error { - if userConf.User == "" { - userConf.User = imageConf.User - } - if len(userConf.ExposedPorts) == 0 { - userConf.ExposedPorts = imageConf.ExposedPorts - } else if imageConf.ExposedPorts != nil { - for port := range imageConf.ExposedPorts { - if _, exists := userConf.ExposedPorts[port]; !exists { - userConf.ExposedPorts[port] = struct{}{} - } - } - } - - if len(userConf.Env) == 0 { - userConf.Env = imageConf.Env - } else { - for _, imageEnv := range imageConf.Env { - found := false - imageEnvKey := strings.Split(imageEnv, "=")[0] - for _, userEnv := range userConf.Env { - userEnvKey := strings.Split(userEnv, "=")[0] - if runtime.GOOS == "windows" { - // Case insensitive environment variables on Windows - imageEnvKey = strings.ToUpper(imageEnvKey) - userEnvKey = strings.ToUpper(userEnvKey) - } - if imageEnvKey == userEnvKey { - found = true - break - } - } - if !found { - userConf.Env = append(userConf.Env, imageEnv) - } - } - } - - if userConf.Labels == nil { - userConf.Labels = map[string]string{} - } - for l, v := range imageConf.Labels { - if _, ok := userConf.Labels[l]; !ok { - userConf.Labels[l] = v - } - } - - if len(userConf.Entrypoint) == 0 { - if len(userConf.Cmd) == 0 { - userConf.Cmd = imageConf.Cmd - userConf.ArgsEscaped = imageConf.ArgsEscaped - } - - if userConf.Entrypoint == nil { - userConf.Entrypoint = imageConf.Entrypoint - } - } - if imageConf.Healthcheck != nil { - if userConf.Healthcheck == nil { - userConf.Healthcheck = imageConf.Healthcheck - } else { - if len(userConf.Healthcheck.Test) == 0 { - userConf.Healthcheck.Test = imageConf.Healthcheck.Test - } - if userConf.Healthcheck.Interval == 0 { - userConf.Healthcheck.Interval = imageConf.Healthcheck.Interval - } - if userConf.Healthcheck.Timeout == 0 { - userConf.Healthcheck.Timeout = imageConf.Healthcheck.Timeout - } - if userConf.Healthcheck.Retries == 0 { - userConf.Healthcheck.Retries = imageConf.Healthcheck.Retries - } - } - } - - if userConf.WorkingDir == "" { - userConf.WorkingDir = imageConf.WorkingDir - } - if len(userConf.Volumes) == 0 { - userConf.Volumes = imageConf.Volumes - } else { - for k, v := range imageConf.Volumes { - userConf.Volumes[k] = v - } - } - - if userConf.StopSignal == "" { - userConf.StopSignal = imageConf.StopSignal - } - return nil -} - -// Commit creates a new filesystem image from the current state of a container. -// The image can optionally be tagged into a repository. -func (daemon *Daemon) Commit(name string, c *backend.ContainerCommitConfig) (string, error) { - start := time.Now() - container, err := daemon.GetContainer(name) - if err != nil { - return "", err - } - - // It is not possible to commit a running container on Windows and on Solaris. - if (runtime.GOOS == "windows" || runtime.GOOS == "solaris") && container.IsRunning() { - return "", fmt.Errorf("%+v does not support commit of a running container", runtime.GOOS) - } - - if c.Pause && !container.IsPaused() { - daemon.containerPause(container) - defer daemon.containerUnpause(container) - } - - newConfig, err := dockerfile.BuildFromConfig(c.Config, c.Changes) - if err != nil { - return "", err - } - - if c.MergeConfigs { - if err := merge(newConfig, container.Config); err != nil { - return "", err - } - } - - rwTar, err := daemon.exportContainerRw(container) - if err != nil { - return "", err - } - defer func() { - if rwTar != nil { - rwTar.Close() - } - }() - - var history []image.History - rootFS := image.NewRootFS() - osVersion := "" - var osFeatures []string - - if container.ImageID != "" { - img, err := daemon.imageStore.Get(container.ImageID) - if err != nil { - return "", err - } - history = img.History - rootFS = img.RootFS - osVersion = img.OSVersion - osFeatures = img.OSFeatures - } - - l, err := daemon.layerStore.Register(rwTar, rootFS.ChainID()) - if err != nil { - return "", err - } - defer layer.ReleaseAndLog(daemon.layerStore, l) - - h := image.History{ - Author: c.Author, - Created: time.Now().UTC(), - CreatedBy: strings.Join(container.Config.Cmd, " "), - Comment: c.Comment, - EmptyLayer: true, - } - - if diffID := l.DiffID(); layer.DigestSHA256EmptyTar != diffID { - h.EmptyLayer = false - rootFS.Append(diffID) - } - - history = append(history, h) - - config, err := json.Marshal(&image.Image{ - V1Image: image.V1Image{ - DockerVersion: dockerversion.Version, - Config: newConfig, - Architecture: runtime.GOARCH, - OS: runtime.GOOS, - Container: container.ID, - ContainerConfig: *container.Config, - Author: c.Author, - Created: h.Created, - }, - RootFS: rootFS, - History: history, - OSFeatures: osFeatures, - OSVersion: osVersion, - }) - - if err != nil { - return "", err - } - - id, err := daemon.imageStore.Create(config) - if err != nil { - return "", err - } - - if container.ImageID != "" { - if err := daemon.imageStore.SetParent(id, container.ImageID); err != nil { - return "", err - } - } - - imageRef := "" - if c.Repo != "" { - newTag, err := reference.WithName(c.Repo) // todo: should move this to API layer - if err != nil { - return "", err - } - if c.Tag != "" { - if newTag, err = reference.WithTag(newTag, c.Tag); err != nil { - return "", err - } - } - if err := daemon.TagImageWithReference(id, newTag); err != nil { - return "", err - } - imageRef = newTag.String() - } - - attributes := map[string]string{ - "comment": c.Comment, - "imageID": id.String(), - "imageRef": imageRef, - } - daemon.LogContainerEventWithAttributes(container, "commit", attributes) - containerActions.WithValues("commit").UpdateSince(start) - return id.String(), nil -} - -func (daemon *Daemon) exportContainerRw(container *container.Container) (io.ReadCloser, error) { - if err := daemon.Mount(container); err != nil { - return nil, err - } - - archive, err := container.RWLayer.TarStream() - if err != nil { - daemon.Unmount(container) // logging is already handled in the `Unmount` function - return nil, err - } - return ioutils.NewReadCloserWrapper(archive, func() error { - archive.Close() - return container.RWLayer.Unmount() - }), - nil -} diff --git a/vendor/github.com/docker/docker/daemon/config.go b/vendor/github.com/docker/docker/daemon/config.go deleted file mode 100644 index 42ef18f..0000000 --- a/vendor/github.com/docker/docker/daemon/config.go +++ /dev/null @@ -1,525 +0,0 @@ -package daemon - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "runtime" - "strings" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/discovery" - "github.com/docker/docker/registry" - "github.com/imdario/mergo" - "github.com/spf13/pflag" -) - -const ( - // defaultMaxConcurrentDownloads is the default value for - // maximum number of downloads that - // may take place at a time for each pull. - defaultMaxConcurrentDownloads = 3 - // defaultMaxConcurrentUploads is the default value for - // maximum number of uploads that - // may take place at a time for each push. - defaultMaxConcurrentUploads = 5 - // stockRuntimeName is the reserved name/alias used to represent the - // OCI runtime being shipped with the docker daemon package. - stockRuntimeName = "runc" -) - -const ( - defaultNetworkMtu = 1500 - disableNetworkBridge = "none" -) - -const ( - defaultShutdownTimeout = 15 -) - -// flatOptions contains configuration keys -// that MUST NOT be parsed as deep structures. -// Use this to differentiate these options -// with others like the ones in CommonTLSOptions. -var flatOptions = map[string]bool{ - "cluster-store-opts": true, - "log-opts": true, - "runtimes": true, - "default-ulimits": true, -} - -// LogConfig represents the default log configuration. -// It includes json tags to deserialize configuration from a file -// using the same names that the flags in the command line use. -type LogConfig struct { - Type string `json:"log-driver,omitempty"` - Config map[string]string `json:"log-opts,omitempty"` -} - -// commonBridgeConfig stores all the platform-common bridge driver specific -// configuration. -type commonBridgeConfig struct { - Iface string `json:"bridge,omitempty"` - FixedCIDR string `json:"fixed-cidr,omitempty"` -} - -// CommonTLSOptions defines TLS configuration for the daemon server. -// It includes json tags to deserialize configuration from a file -// using the same names that the flags in the command line use. -type CommonTLSOptions struct { - CAFile string `json:"tlscacert,omitempty"` - CertFile string `json:"tlscert,omitempty"` - KeyFile string `json:"tlskey,omitempty"` -} - -// CommonConfig defines the configuration of a docker daemon which is -// common across platforms. -// It includes json tags to deserialize configuration from a file -// using the same names that the flags in the command line use. -type CommonConfig struct { - AuthorizationPlugins []string `json:"authorization-plugins,omitempty"` // AuthorizationPlugins holds list of authorization plugins - AutoRestart bool `json:"-"` - Context map[string][]string `json:"-"` - DisableBridge bool `json:"-"` - DNS []string `json:"dns,omitempty"` - DNSOptions []string `json:"dns-opts,omitempty"` - DNSSearch []string `json:"dns-search,omitempty"` - ExecOptions []string `json:"exec-opts,omitempty"` - GraphDriver string `json:"storage-driver,omitempty"` - GraphOptions []string `json:"storage-opts,omitempty"` - Labels []string `json:"labels,omitempty"` - Mtu int `json:"mtu,omitempty"` - Pidfile string `json:"pidfile,omitempty"` - RawLogs bool `json:"raw-logs,omitempty"` - Root string `json:"graph,omitempty"` - SocketGroup string `json:"group,omitempty"` - TrustKeyPath string `json:"-"` - CorsHeaders string `json:"api-cors-header,omitempty"` - EnableCors bool `json:"api-enable-cors,omitempty"` - - // LiveRestoreEnabled determines whether we should keep containers - // alive upon daemon shutdown/start - LiveRestoreEnabled bool `json:"live-restore,omitempty"` - - // ClusterStore is the storage backend used for the cluster information. It is used by both - // multihost networking (to store networks and endpoints information) and by the node discovery - // mechanism. - ClusterStore string `json:"cluster-store,omitempty"` - - // ClusterOpts is used to pass options to the discovery package for tuning libkv settings, such - // as TLS configuration settings. - ClusterOpts map[string]string `json:"cluster-store-opts,omitempty"` - - // ClusterAdvertise is the network endpoint that the Engine advertises for the purpose of node - // discovery. This should be a 'host:port' combination on which that daemon instance is - // reachable by other hosts. - ClusterAdvertise string `json:"cluster-advertise,omitempty"` - - // MaxConcurrentDownloads is the maximum number of downloads that - // may take place at a time for each pull. - MaxConcurrentDownloads *int `json:"max-concurrent-downloads,omitempty"` - - // MaxConcurrentUploads is the maximum number of uploads that - // may take place at a time for each push. - MaxConcurrentUploads *int `json:"max-concurrent-uploads,omitempty"` - - // ShutdownTimeout is the timeout value (in seconds) the daemon will wait for the container - // to stop when daemon is being shutdown - ShutdownTimeout int `json:"shutdown-timeout,omitempty"` - - Debug bool `json:"debug,omitempty"` - Hosts []string `json:"hosts,omitempty"` - LogLevel string `json:"log-level,omitempty"` - TLS bool `json:"tls,omitempty"` - TLSVerify bool `json:"tlsverify,omitempty"` - - // Embedded structs that allow config - // deserialization without the full struct. - CommonTLSOptions - - // SwarmDefaultAdvertiseAddr is the default host/IP or network interface - // to use if a wildcard address is specified in the ListenAddr value - // given to the /swarm/init endpoint and no advertise address is - // specified. - SwarmDefaultAdvertiseAddr string `json:"swarm-default-advertise-addr"` - MetricsAddress string `json:"metrics-addr"` - - LogConfig - bridgeConfig // bridgeConfig holds bridge network specific configuration. - registry.ServiceOptions - - reloadLock sync.Mutex - valuesSet map[string]interface{} - - Experimental bool `json:"experimental"` // Experimental indicates whether experimental features should be exposed or not -} - -// InstallCommonFlags adds flags to the pflag.FlagSet to configure the daemon -func (config *Config) InstallCommonFlags(flags *pflag.FlagSet) { - var maxConcurrentDownloads, maxConcurrentUploads int - - config.ServiceOptions.InstallCliFlags(flags) - - flags.Var(opts.NewNamedListOptsRef("storage-opts", &config.GraphOptions, nil), "storage-opt", "Storage driver options") - flags.Var(opts.NewNamedListOptsRef("authorization-plugins", &config.AuthorizationPlugins, nil), "authorization-plugin", "Authorization plugins to load") - flags.Var(opts.NewNamedListOptsRef("exec-opts", &config.ExecOptions, nil), "exec-opt", "Runtime execution options") - flags.StringVarP(&config.Pidfile, "pidfile", "p", defaultPidFile, "Path to use for daemon PID file") - flags.StringVarP(&config.Root, "graph", "g", defaultGraph, "Root of the Docker runtime") - flags.BoolVarP(&config.AutoRestart, "restart", "r", true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run") - flags.MarkDeprecated("restart", "Please use a restart policy on docker run") - flags.StringVarP(&config.GraphDriver, "storage-driver", "s", "", "Storage driver to use") - flags.IntVar(&config.Mtu, "mtu", 0, "Set the containers network MTU") - flags.BoolVar(&config.RawLogs, "raw-logs", false, "Full timestamps without ANSI coloring") - // FIXME: why the inconsistency between "hosts" and "sockets"? - flags.Var(opts.NewListOptsRef(&config.DNS, opts.ValidateIPAddress), "dns", "DNS server to use") - flags.Var(opts.NewNamedListOptsRef("dns-opts", &config.DNSOptions, nil), "dns-opt", "DNS options to use") - flags.Var(opts.NewListOptsRef(&config.DNSSearch, opts.ValidateDNSSearch), "dns-search", "DNS search domains to use") - flags.Var(opts.NewNamedListOptsRef("labels", &config.Labels, opts.ValidateLabel), "label", "Set key=value labels to the daemon") - flags.StringVar(&config.LogConfig.Type, "log-driver", "json-file", "Default driver for container logs") - flags.Var(opts.NewNamedMapOpts("log-opts", config.LogConfig.Config, nil), "log-opt", "Default log driver options for containers") - flags.StringVar(&config.ClusterAdvertise, "cluster-advertise", "", "Address or interface name to advertise") - flags.StringVar(&config.ClusterStore, "cluster-store", "", "URL of the distributed storage backend") - flags.Var(opts.NewNamedMapOpts("cluster-store-opts", config.ClusterOpts, nil), "cluster-store-opt", "Set cluster store options") - flags.StringVar(&config.CorsHeaders, "api-cors-header", "", "Set CORS headers in the Engine API") - flags.IntVar(&maxConcurrentDownloads, "max-concurrent-downloads", defaultMaxConcurrentDownloads, "Set the max concurrent downloads for each pull") - flags.IntVar(&maxConcurrentUploads, "max-concurrent-uploads", defaultMaxConcurrentUploads, "Set the max concurrent uploads for each push") - flags.IntVar(&config.ShutdownTimeout, "shutdown-timeout", defaultShutdownTimeout, "Set the default shutdown timeout") - - flags.StringVar(&config.SwarmDefaultAdvertiseAddr, "swarm-default-advertise-addr", "", "Set default address or interface for swarm advertised address") - flags.BoolVar(&config.Experimental, "experimental", false, "Enable experimental features") - - flags.StringVar(&config.MetricsAddress, "metrics-addr", "", "Set default address and port to serve the metrics api on") - - config.MaxConcurrentDownloads = &maxConcurrentDownloads - config.MaxConcurrentUploads = &maxConcurrentUploads -} - -// IsValueSet returns true if a configuration value -// was explicitly set in the configuration file. -func (config *Config) IsValueSet(name string) bool { - if config.valuesSet == nil { - return false - } - _, ok := config.valuesSet[name] - return ok -} - -// NewConfig returns a new fully initialized Config struct -func NewConfig() *Config { - config := Config{} - config.LogConfig.Config = make(map[string]string) - config.ClusterOpts = make(map[string]string) - - if runtime.GOOS != "linux" { - config.V2Only = true - } - return &config -} - -func parseClusterAdvertiseSettings(clusterStore, clusterAdvertise string) (string, error) { - if runtime.GOOS == "solaris" && (clusterAdvertise != "" || clusterStore != "") { - return "", errors.New("Cluster Advertise Settings not supported on Solaris") - } - if clusterAdvertise == "" { - return "", errDiscoveryDisabled - } - if clusterStore == "" { - return "", fmt.Errorf("invalid cluster configuration. --cluster-advertise must be accompanied by --cluster-store configuration") - } - - advertise, err := discovery.ParseAdvertise(clusterAdvertise) - if err != nil { - return "", fmt.Errorf("discovery advertise parsing failed (%v)", err) - } - return advertise, nil -} - -// GetConflictFreeLabels validate Labels for conflict -// In swarm the duplicates for labels are removed -// so we only take same values here, no conflict values -// If the key-value is the same we will only take the last label -func GetConflictFreeLabels(labels []string) ([]string, error) { - labelMap := map[string]string{} - for _, label := range labels { - stringSlice := strings.SplitN(label, "=", 2) - if len(stringSlice) > 1 { - // If there is a conflict we will return an error - if v, ok := labelMap[stringSlice[0]]; ok && v != stringSlice[1] { - return nil, fmt.Errorf("conflict labels for %s=%s and %s=%s", stringSlice[0], stringSlice[1], stringSlice[0], v) - } - labelMap[stringSlice[0]] = stringSlice[1] - } - } - - newLabels := []string{} - for k, v := range labelMap { - newLabels = append(newLabels, fmt.Sprintf("%s=%s", k, v)) - } - return newLabels, nil -} - -// ReloadConfiguration reads the configuration in the host and reloads the daemon and server. -func ReloadConfiguration(configFile string, flags *pflag.FlagSet, reload func(*Config)) error { - logrus.Infof("Got signal to reload configuration, reloading from: %s", configFile) - newConfig, err := getConflictFreeConfiguration(configFile, flags) - if err != nil { - return err - } - - if err := ValidateConfiguration(newConfig); err != nil { - return fmt.Errorf("file configuration validation failed (%v)", err) - } - - // Labels of the docker engine used to allow multiple values associated with the same key. - // This is deprecated in 1.13, and, be removed after 3 release cycles. - // The following will check the conflict of labels, and report a warning for deprecation. - // - // TODO: After 3 release cycles (1.16) an error will be returned, and labels will be - // sanitized to consolidate duplicate key-value pairs (config.Labels = newLabels): - // - // newLabels, err := GetConflictFreeLabels(newConfig.Labels) - // if err != nil { - // return err - // } - // newConfig.Labels = newLabels - // - if _, err := GetConflictFreeLabels(newConfig.Labels); err != nil { - logrus.Warnf("Engine labels with duplicate keys and conflicting values have been deprecated: %s", err) - } - - reload(newConfig) - return nil -} - -// boolValue is an interface that boolean value flags implement -// to tell the command line how to make -name equivalent to -name=true. -type boolValue interface { - IsBoolFlag() bool -} - -// MergeDaemonConfigurations reads a configuration file, -// loads the file configuration in an isolated structure, -// and merges the configuration provided from flags on top -// if there are no conflicts. -func MergeDaemonConfigurations(flagsConfig *Config, flags *pflag.FlagSet, configFile string) (*Config, error) { - fileConfig, err := getConflictFreeConfiguration(configFile, flags) - if err != nil { - return nil, err - } - - if err := ValidateConfiguration(fileConfig); err != nil { - return nil, fmt.Errorf("file configuration validation failed (%v)", err) - } - - // merge flags configuration on top of the file configuration - if err := mergo.Merge(fileConfig, flagsConfig); err != nil { - return nil, err - } - - // We need to validate again once both fileConfig and flagsConfig - // have been merged - if err := ValidateConfiguration(fileConfig); err != nil { - return nil, fmt.Errorf("file configuration validation failed (%v)", err) - } - - return fileConfig, nil -} - -// getConflictFreeConfiguration loads the configuration from a JSON file. -// It compares that configuration with the one provided by the flags, -// and returns an error if there are conflicts. -func getConflictFreeConfiguration(configFile string, flags *pflag.FlagSet) (*Config, error) { - b, err := ioutil.ReadFile(configFile) - if err != nil { - return nil, err - } - - var config Config - var reader io.Reader - if flags != nil { - var jsonConfig map[string]interface{} - reader = bytes.NewReader(b) - if err := json.NewDecoder(reader).Decode(&jsonConfig); err != nil { - return nil, err - } - - configSet := configValuesSet(jsonConfig) - - if err := findConfigurationConflicts(configSet, flags); err != nil { - return nil, err - } - - // Override flag values to make sure the values set in the config file with nullable values, like `false`, - // are not overridden by default truthy values from the flags that were not explicitly set. - // See https://github.com/docker/docker/issues/20289 for an example. - // - // TODO: Rewrite configuration logic to avoid same issue with other nullable values, like numbers. - namedOptions := make(map[string]interface{}) - for key, value := range configSet { - f := flags.Lookup(key) - if f == nil { // ignore named flags that don't match - namedOptions[key] = value - continue - } - - if _, ok := f.Value.(boolValue); ok { - f.Value.Set(fmt.Sprintf("%v", value)) - } - } - if len(namedOptions) > 0 { - // set also default for mergeVal flags that are boolValue at the same time. - flags.VisitAll(func(f *pflag.Flag) { - if opt, named := f.Value.(opts.NamedOption); named { - v, set := namedOptions[opt.Name()] - _, boolean := f.Value.(boolValue) - if set && boolean { - f.Value.Set(fmt.Sprintf("%v", v)) - } - } - }) - } - - config.valuesSet = configSet - } - - reader = bytes.NewReader(b) - err = json.NewDecoder(reader).Decode(&config) - return &config, err -} - -// configValuesSet returns the configuration values explicitly set in the file. -func configValuesSet(config map[string]interface{}) map[string]interface{} { - flatten := make(map[string]interface{}) - for k, v := range config { - if m, isMap := v.(map[string]interface{}); isMap && !flatOptions[k] { - for km, vm := range m { - flatten[km] = vm - } - continue - } - - flatten[k] = v - } - return flatten -} - -// findConfigurationConflicts iterates over the provided flags searching for -// duplicated configurations and unknown keys. It returns an error with all the conflicts if -// it finds any. -func findConfigurationConflicts(config map[string]interface{}, flags *pflag.FlagSet) error { - // 1. Search keys from the file that we don't recognize as flags. - unknownKeys := make(map[string]interface{}) - for key, value := range config { - if flag := flags.Lookup(key); flag == nil { - unknownKeys[key] = value - } - } - - // 2. Discard values that implement NamedOption. - // Their configuration name differs from their flag name, like `labels` and `label`. - if len(unknownKeys) > 0 { - unknownNamedConflicts := func(f *pflag.Flag) { - if namedOption, ok := f.Value.(opts.NamedOption); ok { - if _, valid := unknownKeys[namedOption.Name()]; valid { - delete(unknownKeys, namedOption.Name()) - } - } - } - flags.VisitAll(unknownNamedConflicts) - } - - if len(unknownKeys) > 0 { - var unknown []string - for key := range unknownKeys { - unknown = append(unknown, key) - } - return fmt.Errorf("the following directives don't match any configuration option: %s", strings.Join(unknown, ", ")) - } - - var conflicts []string - printConflict := func(name string, flagValue, fileValue interface{}) string { - return fmt.Sprintf("%s: (from flag: %v, from file: %v)", name, flagValue, fileValue) - } - - // 3. Search keys that are present as a flag and as a file option. - duplicatedConflicts := func(f *pflag.Flag) { - // search option name in the json configuration payload if the value is a named option - if namedOption, ok := f.Value.(opts.NamedOption); ok { - if optsValue, ok := config[namedOption.Name()]; ok { - conflicts = append(conflicts, printConflict(namedOption.Name(), f.Value.String(), optsValue)) - } - } else { - // search flag name in the json configuration payload - for _, name := range []string{f.Name, f.Shorthand} { - if value, ok := config[name]; ok { - conflicts = append(conflicts, printConflict(name, f.Value.String(), value)) - break - } - } - } - } - - flags.Visit(duplicatedConflicts) - - if len(conflicts) > 0 { - return fmt.Errorf("the following directives are specified both as a flag and in the configuration file: %s", strings.Join(conflicts, ", ")) - } - return nil -} - -// ValidateConfiguration validates some specific configs. -// such as config.DNS, config.Labels, config.DNSSearch, -// as well as config.MaxConcurrentDownloads, config.MaxConcurrentUploads. -func ValidateConfiguration(config *Config) error { - // validate DNS - for _, dns := range config.DNS { - if _, err := opts.ValidateIPAddress(dns); err != nil { - return err - } - } - - // validate DNSSearch - for _, dnsSearch := range config.DNSSearch { - if _, err := opts.ValidateDNSSearch(dnsSearch); err != nil { - return err - } - } - - // validate Labels - for _, label := range config.Labels { - if _, err := opts.ValidateLabel(label); err != nil { - return err - } - } - - // validate MaxConcurrentDownloads - if config.IsValueSet("max-concurrent-downloads") && config.MaxConcurrentDownloads != nil && *config.MaxConcurrentDownloads < 0 { - return fmt.Errorf("invalid max concurrent downloads: %d", *config.MaxConcurrentDownloads) - } - - // validate MaxConcurrentUploads - if config.IsValueSet("max-concurrent-uploads") && config.MaxConcurrentUploads != nil && *config.MaxConcurrentUploads < 0 { - return fmt.Errorf("invalid max concurrent uploads: %d", *config.MaxConcurrentUploads) - } - - // validate that "default" runtime is not reset - if runtimes := config.GetAllRuntimes(); len(runtimes) > 0 { - if _, ok := runtimes[stockRuntimeName]; ok { - return fmt.Errorf("runtime name '%s' is reserved", stockRuntimeName) - } - } - - if defaultRuntime := config.GetDefaultRuntimeName(); defaultRuntime != "" && defaultRuntime != stockRuntimeName { - runtimes := config.GetAllRuntimes() - if _, ok := runtimes[defaultRuntime]; !ok { - return fmt.Errorf("specified default runtime '%s' does not exist", defaultRuntime) - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/config_common_unix.go b/vendor/github.com/docker/docker/daemon/config_common_unix.go deleted file mode 100644 index ab76fe7..0000000 --- a/vendor/github.com/docker/docker/daemon/config_common_unix.go +++ /dev/null @@ -1,90 +0,0 @@ -// +build solaris linux freebsd - -package daemon - -import ( - "net" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/opts" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/spf13/pflag" -) - -// CommonUnixConfig defines configuration of a docker daemon that is -// common across Unix platforms. -type CommonUnixConfig struct { - ExecRoot string `json:"exec-root,omitempty"` - ContainerdAddr string `json:"containerd,omitempty"` - Runtimes map[string]types.Runtime `json:"runtimes,omitempty"` - DefaultRuntime string `json:"default-runtime,omitempty"` -} - -type commonUnixBridgeConfig struct { - DefaultIP net.IP `json:"ip,omitempty"` - IP string `json:"bip,omitempty"` - DefaultGatewayIPv4 net.IP `json:"default-gateway,omitempty"` - DefaultGatewayIPv6 net.IP `json:"default-gateway-v6,omitempty"` - InterContainerCommunication bool `json:"icc,omitempty"` -} - -// InstallCommonUnixFlags adds command-line options to the top-level flag parser for -// the current process that are common across Unix platforms. -func (config *Config) InstallCommonUnixFlags(flags *pflag.FlagSet) { - config.Runtimes = make(map[string]types.Runtime) - - flags.StringVarP(&config.SocketGroup, "group", "G", "docker", "Group for the unix socket") - flags.StringVar(&config.bridgeConfig.IP, "bip", "", "Specify network bridge IP") - flags.StringVarP(&config.bridgeConfig.Iface, "bridge", "b", "", "Attach containers to a network bridge") - flags.StringVar(&config.bridgeConfig.FixedCIDR, "fixed-cidr", "", "IPv4 subnet for fixed IPs") - flags.Var(opts.NewIPOpt(&config.bridgeConfig.DefaultGatewayIPv4, ""), "default-gateway", "Container default gateway IPv4 address") - flags.Var(opts.NewIPOpt(&config.bridgeConfig.DefaultGatewayIPv6, ""), "default-gateway-v6", "Container default gateway IPv6 address") - flags.BoolVar(&config.bridgeConfig.InterContainerCommunication, "icc", true, "Enable inter-container communication") - flags.Var(opts.NewIPOpt(&config.bridgeConfig.DefaultIP, "0.0.0.0"), "ip", "Default IP when binding container ports") - flags.Var(runconfigopts.NewNamedRuntimeOpt("runtimes", &config.Runtimes, stockRuntimeName), "add-runtime", "Register an additional OCI compatible runtime") - flags.StringVar(&config.DefaultRuntime, "default-runtime", stockRuntimeName, "Default OCI runtime for containers") - -} - -// GetRuntime returns the runtime path and arguments for a given -// runtime name -func (config *Config) GetRuntime(name string) *types.Runtime { - config.reloadLock.Lock() - defer config.reloadLock.Unlock() - if rt, ok := config.Runtimes[name]; ok { - return &rt - } - return nil -} - -// GetDefaultRuntimeName returns the current default runtime -func (config *Config) GetDefaultRuntimeName() string { - config.reloadLock.Lock() - rt := config.DefaultRuntime - config.reloadLock.Unlock() - - return rt -} - -// GetAllRuntimes returns a copy of the runtimes map -func (config *Config) GetAllRuntimes() map[string]types.Runtime { - config.reloadLock.Lock() - rts := config.Runtimes - config.reloadLock.Unlock() - return rts -} - -// GetExecRoot returns the user configured Exec-root -func (config *Config) GetExecRoot() string { - return config.ExecRoot -} - -// GetInitPath returns the configure docker-init path -func (config *Config) GetInitPath() string { - config.reloadLock.Lock() - defer config.reloadLock.Unlock() - if config.InitPath != "" { - return config.InitPath - } - return DefaultInitBinary -} diff --git a/vendor/github.com/docker/docker/daemon/config_experimental.go b/vendor/github.com/docker/docker/daemon/config_experimental.go deleted file mode 100644 index 963a51e..0000000 --- a/vendor/github.com/docker/docker/daemon/config_experimental.go +++ /dev/null @@ -1,8 +0,0 @@ -package daemon - -import ( - "github.com/spf13/pflag" -) - -func (config *Config) attachExperimentalFlags(cmd *pflag.FlagSet) { -} diff --git a/vendor/github.com/docker/docker/daemon/config_solaris.go b/vendor/github.com/docker/docker/daemon/config_solaris.go deleted file mode 100644 index bc18ccd..0000000 --- a/vendor/github.com/docker/docker/daemon/config_solaris.go +++ /dev/null @@ -1,47 +0,0 @@ -package daemon - -import ( - "github.com/spf13/pflag" -) - -var ( - defaultPidFile = "/system/volatile/docker/docker.pid" - defaultGraph = "/var/lib/docker" - defaultExec = "zones" -) - -// Config defines the configuration of a docker daemon. -// These are the configuration settings that you pass -// to the docker daemon when you launch it with say: `docker -d -e lxc` -type Config struct { - CommonConfig - - // These fields are common to all unix platforms. - CommonUnixConfig -} - -// bridgeConfig stores all the bridge driver specific -// configuration. -type bridgeConfig struct { - commonBridgeConfig - - // Fields below here are platform specific. - commonUnixBridgeConfig -} - -// InstallFlags adds command-line options to the top-level flag parser for -// the current process. -func (config *Config) InstallFlags(flags *pflag.FlagSet) { - // First handle install flags which are consistent cross-platform - config.InstallCommonFlags(flags) - - // Then install flags common to unix platforms - config.InstallCommonUnixFlags(flags) - - // Then platform-specific install flags - config.attachExperimentalFlags(flags) -} - -func (config *Config) isSwarmCompatible() error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/config_test.go b/vendor/github.com/docker/docker/daemon/config_test.go deleted file mode 100644 index 90f6a12..0000000 --- a/vendor/github.com/docker/docker/daemon/config_test.go +++ /dev/null @@ -1,229 +0,0 @@ -package daemon - -import ( - "io/ioutil" - "os" - "runtime" - "strings" - "testing" - - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/testutil/assert" - "github.com/spf13/pflag" -) - -func TestDaemonConfigurationNotFound(t *testing.T) { - _, err := MergeDaemonConfigurations(&Config{}, nil, "/tmp/foo-bar-baz-docker") - if err == nil || !os.IsNotExist(err) { - t.Fatalf("expected does not exist error, got %v", err) - } -} - -func TestDaemonBrokenConfiguration(t *testing.T) { - f, err := ioutil.TempFile("", "docker-config-") - if err != nil { - t.Fatal(err) - } - - configFile := f.Name() - f.Write([]byte(`{"Debug": tru`)) - f.Close() - - _, err = MergeDaemonConfigurations(&Config{}, nil, configFile) - if err == nil { - t.Fatalf("expected error, got %v", err) - } -} - -func TestParseClusterAdvertiseSettings(t *testing.T) { - if runtime.GOOS == "solaris" { - t.Skip("ClusterSettings not supported on Solaris\n") - } - _, err := parseClusterAdvertiseSettings("something", "") - if err != errDiscoveryDisabled { - t.Fatalf("expected discovery disabled error, got %v\n", err) - } - - _, err = parseClusterAdvertiseSettings("", "something") - if err == nil { - t.Fatalf("expected discovery store error, got %v\n", err) - } - - _, err = parseClusterAdvertiseSettings("etcd", "127.0.0.1:8080") - if err != nil { - t.Fatal(err) - } -} - -func TestFindConfigurationConflicts(t *testing.T) { - config := map[string]interface{}{"authorization-plugins": "foobar"} - flags := pflag.NewFlagSet("test", pflag.ContinueOnError) - - flags.String("authorization-plugins", "", "") - assert.NilError(t, flags.Set("authorization-plugins", "asdf")) - - assert.Error(t, - findConfigurationConflicts(config, flags), - "authorization-plugins: (from flag: asdf, from file: foobar)") -} - -func TestFindConfigurationConflictsWithNamedOptions(t *testing.T) { - config := map[string]interface{}{"hosts": []string{"qwer"}} - flags := pflag.NewFlagSet("test", pflag.ContinueOnError) - - var hosts []string - flags.VarP(opts.NewNamedListOptsRef("hosts", &hosts, opts.ValidateHost), "host", "H", "Daemon socket(s) to connect to") - assert.NilError(t, flags.Set("host", "tcp://127.0.0.1:4444")) - assert.NilError(t, flags.Set("host", "unix:///var/run/docker.sock")) - - assert.Error(t, findConfigurationConflicts(config, flags), "hosts") -} - -func TestDaemonConfigurationMergeConflicts(t *testing.T) { - f, err := ioutil.TempFile("", "docker-config-") - if err != nil { - t.Fatal(err) - } - - configFile := f.Name() - f.Write([]byte(`{"debug": true}`)) - f.Close() - - flags := pflag.NewFlagSet("test", pflag.ContinueOnError) - flags.Bool("debug", false, "") - flags.Set("debug", "false") - - _, err = MergeDaemonConfigurations(&Config{}, flags, configFile) - if err == nil { - t.Fatal("expected error, got nil") - } - if !strings.Contains(err.Error(), "debug") { - t.Fatalf("expected debug conflict, got %v", err) - } -} - -func TestDaemonConfigurationMergeConflictsWithInnerStructs(t *testing.T) { - f, err := ioutil.TempFile("", "docker-config-") - if err != nil { - t.Fatal(err) - } - - configFile := f.Name() - f.Write([]byte(`{"tlscacert": "/etc/certificates/ca.pem"}`)) - f.Close() - - flags := pflag.NewFlagSet("test", pflag.ContinueOnError) - flags.String("tlscacert", "", "") - flags.Set("tlscacert", "~/.docker/ca.pem") - - _, err = MergeDaemonConfigurations(&Config{}, flags, configFile) - if err == nil { - t.Fatal("expected error, got nil") - } - if !strings.Contains(err.Error(), "tlscacert") { - t.Fatalf("expected tlscacert conflict, got %v", err) - } -} - -func TestFindConfigurationConflictsWithUnknownKeys(t *testing.T) { - config := map[string]interface{}{"tls-verify": "true"} - flags := pflag.NewFlagSet("test", pflag.ContinueOnError) - - flags.Bool("tlsverify", false, "") - err := findConfigurationConflicts(config, flags) - if err == nil { - t.Fatal("expected error, got nil") - } - if !strings.Contains(err.Error(), "the following directives don't match any configuration option: tls-verify") { - t.Fatalf("expected tls-verify conflict, got %v", err) - } -} - -func TestFindConfigurationConflictsWithMergedValues(t *testing.T) { - var hosts []string - config := map[string]interface{}{"hosts": "tcp://127.0.0.1:2345"} - flags := pflag.NewFlagSet("base", pflag.ContinueOnError) - flags.VarP(opts.NewNamedListOptsRef("hosts", &hosts, nil), "host", "H", "") - - err := findConfigurationConflicts(config, flags) - if err != nil { - t.Fatal(err) - } - - flags.Set("host", "unix:///var/run/docker.sock") - err = findConfigurationConflicts(config, flags) - if err == nil { - t.Fatal("expected error, got nil") - } - if !strings.Contains(err.Error(), "hosts: (from flag: [unix:///var/run/docker.sock], from file: tcp://127.0.0.1:2345)") { - t.Fatalf("expected hosts conflict, got %v", err) - } -} - -func TestValidateConfiguration(t *testing.T) { - c1 := &Config{ - CommonConfig: CommonConfig{ - Labels: []string{"one"}, - }, - } - - err := ValidateConfiguration(c1) - if err == nil { - t.Fatal("expected error, got nil") - } - - c2 := &Config{ - CommonConfig: CommonConfig{ - Labels: []string{"one=two"}, - }, - } - - err = ValidateConfiguration(c2) - if err != nil { - t.Fatalf("expected no error, got error %v", err) - } - - c3 := &Config{ - CommonConfig: CommonConfig{ - DNS: []string{"1.1.1.1"}, - }, - } - - err = ValidateConfiguration(c3) - if err != nil { - t.Fatalf("expected no error, got error %v", err) - } - - c4 := &Config{ - CommonConfig: CommonConfig{ - DNS: []string{"1.1.1.1o"}, - }, - } - - err = ValidateConfiguration(c4) - if err == nil { - t.Fatal("expected error, got nil") - } - - c5 := &Config{ - CommonConfig: CommonConfig{ - DNSSearch: []string{"a.b.c"}, - }, - } - - err = ValidateConfiguration(c5) - if err != nil { - t.Fatalf("expected no error, got error %v", err) - } - - c6 := &Config{ - CommonConfig: CommonConfig{ - DNSSearch: []string{"123456"}, - }, - } - - err = ValidateConfiguration(c6) - if err == nil { - t.Fatal("expected error, got nil") - } -} diff --git a/vendor/github.com/docker/docker/daemon/config_unix.go b/vendor/github.com/docker/docker/daemon/config_unix.go deleted file mode 100644 index d095788..0000000 --- a/vendor/github.com/docker/docker/daemon/config_unix.go +++ /dev/null @@ -1,104 +0,0 @@ -// +build linux freebsd - -package daemon - -import ( - "fmt" - - runconfigopts "github.com/docker/docker/runconfig/opts" - units "github.com/docker/go-units" - "github.com/spf13/pflag" -) - -var ( - defaultPidFile = "/var/run/docker.pid" - defaultGraph = "/var/lib/docker" - defaultExecRoot = "/var/run/docker" -) - -// Config defines the configuration of a docker daemon. -// It includes json tags to deserialize configuration from a file -// using the same names that the flags in the command line uses. -type Config struct { - CommonConfig - - // These fields are common to all unix platforms. - CommonUnixConfig - - // Fields below here are platform specific. - CgroupParent string `json:"cgroup-parent,omitempty"` - EnableSelinuxSupport bool `json:"selinux-enabled,omitempty"` - RemappedRoot string `json:"userns-remap,omitempty"` - Ulimits map[string]*units.Ulimit `json:"default-ulimits,omitempty"` - CPURealtimePeriod int64 `json:"cpu-rt-period,omitempty"` - CPURealtimeRuntime int64 `json:"cpu-rt-runtime,omitempty"` - OOMScoreAdjust int `json:"oom-score-adjust,omitempty"` - Init bool `json:"init,omitempty"` - InitPath string `json:"init-path,omitempty"` - SeccompProfile string `json:"seccomp-profile,omitempty"` -} - -// bridgeConfig stores all the bridge driver specific -// configuration. -type bridgeConfig struct { - commonBridgeConfig - - // These fields are common to all unix platforms. - commonUnixBridgeConfig - - // Fields below here are platform specific. - EnableIPv6 bool `json:"ipv6,omitempty"` - EnableIPTables bool `json:"iptables,omitempty"` - EnableIPForward bool `json:"ip-forward,omitempty"` - EnableIPMasq bool `json:"ip-masq,omitempty"` - EnableUserlandProxy bool `json:"userland-proxy,omitempty"` - UserlandProxyPath string `json:"userland-proxy-path,omitempty"` - FixedCIDRv6 string `json:"fixed-cidr-v6,omitempty"` -} - -// InstallFlags adds flags to the pflag.FlagSet to configure the daemon -func (config *Config) InstallFlags(flags *pflag.FlagSet) { - // First handle install flags which are consistent cross-platform - config.InstallCommonFlags(flags) - - // Then install flags common to unix platforms - config.InstallCommonUnixFlags(flags) - - config.Ulimits = make(map[string]*units.Ulimit) - - // Then platform-specific install flags - flags.BoolVar(&config.EnableSelinuxSupport, "selinux-enabled", false, "Enable selinux support") - flags.Var(runconfigopts.NewUlimitOpt(&config.Ulimits), "default-ulimit", "Default ulimits for containers") - flags.BoolVar(&config.bridgeConfig.EnableIPTables, "iptables", true, "Enable addition of iptables rules") - flags.BoolVar(&config.bridgeConfig.EnableIPForward, "ip-forward", true, "Enable net.ipv4.ip_forward") - flags.BoolVar(&config.bridgeConfig.EnableIPMasq, "ip-masq", true, "Enable IP masquerading") - flags.BoolVar(&config.bridgeConfig.EnableIPv6, "ipv6", false, "Enable IPv6 networking") - flags.StringVar(&config.ExecRoot, "exec-root", defaultExecRoot, "Root directory for execution state files") - flags.StringVar(&config.bridgeConfig.FixedCIDRv6, "fixed-cidr-v6", "", "IPv6 subnet for fixed IPs") - flags.BoolVar(&config.bridgeConfig.EnableUserlandProxy, "userland-proxy", true, "Use userland proxy for loopback traffic") - flags.StringVar(&config.bridgeConfig.UserlandProxyPath, "userland-proxy-path", "", "Path to the userland proxy binary") - flags.BoolVar(&config.EnableCors, "api-enable-cors", false, "Enable CORS headers in the Engine API, this is deprecated by --api-cors-header") - flags.MarkDeprecated("api-enable-cors", "Please use --api-cors-header") - flags.StringVar(&config.CgroupParent, "cgroup-parent", "", "Set parent cgroup for all containers") - flags.StringVar(&config.RemappedRoot, "userns-remap", "", "User/Group setting for user namespaces") - flags.StringVar(&config.ContainerdAddr, "containerd", "", "Path to containerd socket") - flags.BoolVar(&config.LiveRestoreEnabled, "live-restore", false, "Enable live restore of docker when containers are still running") - flags.IntVar(&config.OOMScoreAdjust, "oom-score-adjust", -500, "Set the oom_score_adj for the daemon") - flags.BoolVar(&config.Init, "init", false, "Run an init in the container to forward signals and reap processes") - flags.StringVar(&config.InitPath, "init-path", "", "Path to the docker-init binary") - flags.Int64Var(&config.CPURealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds") - flags.Int64Var(&config.CPURealtimeRuntime, "cpu-rt-runtime", 0, "Limit the CPU real-time runtime in microseconds") - flags.StringVar(&config.SeccompProfile, "seccomp-profile", "", "Path to seccomp profile") - - config.attachExperimentalFlags(flags) -} - -func (config *Config) isSwarmCompatible() error { - if config.ClusterStore != "" || config.ClusterAdvertise != "" { - return fmt.Errorf("--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode") - } - if config.LiveRestoreEnabled { - return fmt.Errorf("--live-restore daemon configuration is incompatible with swarm mode") - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/config_unix_test.go b/vendor/github.com/docker/docker/daemon/config_unix_test.go deleted file mode 100644 index 86c16f5..0000000 --- a/vendor/github.com/docker/docker/daemon/config_unix_test.go +++ /dev/null @@ -1,80 +0,0 @@ -// +build !windows - -package daemon - -import ( - "io/ioutil" - "testing" -) - -func TestDaemonConfigurationMerge(t *testing.T) { - f, err := ioutil.TempFile("", "docker-config-") - if err != nil { - t.Fatal(err) - } - - configFile := f.Name() - - f.Write([]byte(` - { - "debug": true, - "default-ulimits": { - "nofile": { - "Name": "nofile", - "Hard": 2048, - "Soft": 1024 - } - }, - "log-opts": { - "tag": "test_tag" - } - }`)) - - f.Close() - - c := &Config{ - CommonConfig: CommonConfig{ - AutoRestart: true, - LogConfig: LogConfig{ - Type: "syslog", - Config: map[string]string{"tag": "test"}, - }, - }, - } - - cc, err := MergeDaemonConfigurations(c, nil, configFile) - if err != nil { - t.Fatal(err) - } - if !cc.Debug { - t.Fatalf("expected %v, got %v\n", true, cc.Debug) - } - if !cc.AutoRestart { - t.Fatalf("expected %v, got %v\n", true, cc.AutoRestart) - } - if cc.LogConfig.Type != "syslog" { - t.Fatalf("expected syslog config, got %q\n", cc.LogConfig) - } - - if configValue, OK := cc.LogConfig.Config["tag"]; !OK { - t.Fatal("expected syslog config attributes, got nil\n") - } else { - if configValue != "test_tag" { - t.Fatalf("expected syslog config attributes 'tag=test_tag', got 'tag=%s'\n", configValue) - } - } - - if cc.Ulimits == nil { - t.Fatal("expected default ulimit config, got nil\n") - } else { - if _, OK := cc.Ulimits["nofile"]; OK { - if cc.Ulimits["nofile"].Name != "nofile" || - cc.Ulimits["nofile"].Hard != 2048 || - cc.Ulimits["nofile"].Soft != 1024 { - t.Fatalf("expected default ulimit name, hard and soft are nofile, 2048, 1024, got %s, %d, %d\n", cc.Ulimits["nofile"].Name, cc.Ulimits["nofile"].Hard, cc.Ulimits["nofile"].Soft) - } - } else { - t.Fatal("expected default ulimit name nofile, got nil\n") - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/config_windows.go b/vendor/github.com/docker/docker/daemon/config_windows.go deleted file mode 100644 index df59dcf..0000000 --- a/vendor/github.com/docker/docker/daemon/config_windows.go +++ /dev/null @@ -1,71 +0,0 @@ -package daemon - -import ( - "os" - "path/filepath" - - "github.com/docker/docker/api/types" - "github.com/spf13/pflag" -) - -var ( - defaultPidFile string - defaultGraph = filepath.Join(os.Getenv("programdata"), "docker") -) - -// bridgeConfig stores all the bridge driver specific -// configuration. -type bridgeConfig struct { - commonBridgeConfig -} - -// Config defines the configuration of a docker daemon. -// These are the configuration settings that you pass -// to the docker daemon when you launch it with say: `docker daemon -e windows` -type Config struct { - CommonConfig - - // Fields below here are platform specific. (There are none presently - // for the Windows daemon.) -} - -// InstallFlags adds flags to the pflag.FlagSet to configure the daemon -func (config *Config) InstallFlags(flags *pflag.FlagSet) { - // First handle install flags which are consistent cross-platform - config.InstallCommonFlags(flags) - - // Then platform-specific install flags. - flags.StringVar(&config.bridgeConfig.FixedCIDR, "fixed-cidr", "", "IPv4 subnet for fixed IPs") - flags.StringVarP(&config.bridgeConfig.Iface, "bridge", "b", "", "Attach containers to a virtual switch") - flags.StringVarP(&config.SocketGroup, "group", "G", "", "Users or groups that can access the named pipe") -} - -// GetRuntime returns the runtime path and arguments for a given -// runtime name -func (config *Config) GetRuntime(name string) *types.Runtime { - return nil -} - -// GetInitPath returns the configure docker-init path -func (config *Config) GetInitPath() string { - return "" -} - -// GetDefaultRuntimeName returns the current default runtime -func (config *Config) GetDefaultRuntimeName() string { - return stockRuntimeName -} - -// GetAllRuntimes returns a copy of the runtimes map -func (config *Config) GetAllRuntimes() map[string]types.Runtime { - return map[string]types.Runtime{} -} - -// GetExecRoot returns the user configured Exec-root -func (config *Config) GetExecRoot() string { - return "" -} - -func (config *Config) isSwarmCompatible() error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/config_windows_test.go b/vendor/github.com/docker/docker/daemon/config_windows_test.go deleted file mode 100644 index 4a7b95c..0000000 --- a/vendor/github.com/docker/docker/daemon/config_windows_test.go +++ /dev/null @@ -1,59 +0,0 @@ -// +build windows - -package daemon - -import ( - "io/ioutil" - "testing" -) - -func TestDaemonConfigurationMerge(t *testing.T) { - f, err := ioutil.TempFile("", "docker-config-") - if err != nil { - t.Fatal(err) - } - - configFile := f.Name() - - f.Write([]byte(` - { - "debug": true, - "log-opts": { - "tag": "test_tag" - } - }`)) - - f.Close() - - c := &Config{ - CommonConfig: CommonConfig{ - AutoRestart: true, - LogConfig: LogConfig{ - Type: "syslog", - Config: map[string]string{"tag": "test"}, - }, - }, - } - - cc, err := MergeDaemonConfigurations(c, nil, configFile) - if err != nil { - t.Fatal(err) - } - if !cc.Debug { - t.Fatalf("expected %v, got %v\n", true, cc.Debug) - } - if !cc.AutoRestart { - t.Fatalf("expected %v, got %v\n", true, cc.AutoRestart) - } - if cc.LogConfig.Type != "syslog" { - t.Fatalf("expected syslog config, got %q\n", cc.LogConfig) - } - - if configValue, OK := cc.LogConfig.Config["tag"]; !OK { - t.Fatal("expected syslog config attributes, got nil\n") - } else { - if configValue != "test_tag" { - t.Fatalf("expected syslog config attributes 'tag=test_tag', got 'tag=%s'\n", configValue) - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/container.go b/vendor/github.com/docker/docker/daemon/container.go deleted file mode 100644 index 2a44800..0000000 --- a/vendor/github.com/docker/docker/daemon/container.go +++ /dev/null @@ -1,282 +0,0 @@ -package daemon - -import ( - "fmt" - "os" - "path/filepath" - "time" - - "github.com/docker/docker/api/errors" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/strslice" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/network" - "github.com/docker/docker/image" - "github.com/docker/docker/pkg/signal" - "github.com/docker/docker/pkg/system" - "github.com/docker/docker/pkg/truncindex" - "github.com/docker/docker/runconfig/opts" - "github.com/docker/go-connections/nat" -) - -// GetContainer looks for a container using the provided information, which could be -// one of the following inputs from the caller: -// - A full container ID, which will exact match a container in daemon's list -// - A container name, which will only exact match via the GetByName() function -// - A partial container ID prefix (e.g. short ID) of any length that is -// unique enough to only return a single container object -// If none of these searches succeed, an error is returned -func (daemon *Daemon) GetContainer(prefixOrName string) (*container.Container, error) { - if len(prefixOrName) == 0 { - return nil, errors.NewBadRequestError(fmt.Errorf("No container name or ID supplied")) - } - - if containerByID := daemon.containers.Get(prefixOrName); containerByID != nil { - // prefix is an exact match to a full container ID - return containerByID, nil - } - - // GetByName will match only an exact name provided; we ignore errors - if containerByName, _ := daemon.GetByName(prefixOrName); containerByName != nil { - // prefix is an exact match to a full container Name - return containerByName, nil - } - - containerID, indexError := daemon.idIndex.Get(prefixOrName) - if indexError != nil { - // When truncindex defines an error type, use that instead - if indexError == truncindex.ErrNotExist { - err := fmt.Errorf("No such container: %s", prefixOrName) - return nil, errors.NewRequestNotFoundError(err) - } - return nil, indexError - } - return daemon.containers.Get(containerID), nil -} - -// Exists returns a true if a container of the specified ID or name exists, -// false otherwise. -func (daemon *Daemon) Exists(id string) bool { - c, _ := daemon.GetContainer(id) - return c != nil -} - -// IsPaused returns a bool indicating if the specified container is paused. -func (daemon *Daemon) IsPaused(id string) bool { - c, _ := daemon.GetContainer(id) - return c.State.IsPaused() -} - -func (daemon *Daemon) containerRoot(id string) string { - return filepath.Join(daemon.repository, id) -} - -// Load reads the contents of a container from disk -// This is typically done at startup. -func (daemon *Daemon) load(id string) (*container.Container, error) { - container := daemon.newBaseContainer(id) - - if err := container.FromDisk(); err != nil { - return nil, err - } - - if container.ID != id { - return container, fmt.Errorf("Container %s is stored at %s", container.ID, id) - } - - return container, nil -} - -// Register makes a container object usable by the daemon as -func (daemon *Daemon) Register(c *container.Container) error { - // Attach to stdout and stderr - if c.Config.OpenStdin { - c.StreamConfig.NewInputPipes() - } else { - c.StreamConfig.NewNopInputPipe() - } - - daemon.containers.Add(c.ID, c) - daemon.idIndex.Add(c.ID) - - return nil -} - -func (daemon *Daemon) newContainer(name string, config *containertypes.Config, hostConfig *containertypes.HostConfig, imgID image.ID, managed bool) (*container.Container, error) { - var ( - id string - err error - noExplicitName = name == "" - ) - id, name, err = daemon.generateIDAndName(name) - if err != nil { - return nil, err - } - - if hostConfig.NetworkMode.IsHost() { - if config.Hostname == "" { - config.Hostname, err = os.Hostname() - if err != nil { - return nil, err - } - } - } else { - daemon.generateHostname(id, config) - } - entrypoint, args := daemon.getEntrypointAndArgs(config.Entrypoint, config.Cmd) - - base := daemon.newBaseContainer(id) - base.Created = time.Now().UTC() - base.Managed = managed - base.Path = entrypoint - base.Args = args //FIXME: de-duplicate from config - base.Config = config - base.HostConfig = &containertypes.HostConfig{} - base.ImageID = imgID - base.NetworkSettings = &network.Settings{IsAnonymousEndpoint: noExplicitName} - base.Name = name - base.Driver = daemon.GraphDriverName() - - return base, err -} - -// GetByName returns a container given a name. -func (daemon *Daemon) GetByName(name string) (*container.Container, error) { - if len(name) == 0 { - return nil, fmt.Errorf("No container name supplied") - } - fullName := name - if name[0] != '/' { - fullName = "/" + name - } - id, err := daemon.nameIndex.Get(fullName) - if err != nil { - return nil, fmt.Errorf("Could not find entity for %s", name) - } - e := daemon.containers.Get(id) - if e == nil { - return nil, fmt.Errorf("Could not find container for entity id %s", id) - } - return e, nil -} - -// newBaseContainer creates a new container with its initial -// configuration based on the root storage from the daemon. -func (daemon *Daemon) newBaseContainer(id string) *container.Container { - return container.NewBaseContainer(id, daemon.containerRoot(id)) -} - -func (daemon *Daemon) getEntrypointAndArgs(configEntrypoint strslice.StrSlice, configCmd strslice.StrSlice) (string, []string) { - if len(configEntrypoint) != 0 { - return configEntrypoint[0], append(configEntrypoint[1:], configCmd...) - } - return configCmd[0], configCmd[1:] -} - -func (daemon *Daemon) generateHostname(id string, config *containertypes.Config) { - // Generate default hostname - if config.Hostname == "" { - config.Hostname = id[:12] - } -} - -func (daemon *Daemon) setSecurityOptions(container *container.Container, hostConfig *containertypes.HostConfig) error { - container.Lock() - defer container.Unlock() - return parseSecurityOpt(container, hostConfig) -} - -func (daemon *Daemon) setHostConfig(container *container.Container, hostConfig *containertypes.HostConfig) error { - // Do not lock while creating volumes since this could be calling out to external plugins - // Don't want to block other actions, like `docker ps` because we're waiting on an external plugin - if err := daemon.registerMountPoints(container, hostConfig); err != nil { - return err - } - - container.Lock() - defer container.Unlock() - - // Register any links from the host config before starting the container - if err := daemon.registerLinks(container, hostConfig); err != nil { - return err - } - - // make sure links is not nil - // this ensures that on the next daemon restart we don't try to migrate from legacy sqlite links - if hostConfig.Links == nil { - hostConfig.Links = []string{} - } - - container.HostConfig = hostConfig - return container.ToDisk() -} - -// verifyContainerSettings performs validation of the hostconfig and config -// structures. -func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) { - - // First perform verification of settings common across all platforms. - if config != nil { - if config.WorkingDir != "" { - config.WorkingDir = filepath.FromSlash(config.WorkingDir) // Ensure in platform semantics - if !system.IsAbs(config.WorkingDir) { - return nil, fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir) - } - } - - if len(config.StopSignal) > 0 { - _, err := signal.ParseSignal(config.StopSignal) - if err != nil { - return nil, err - } - } - - // Validate if Env contains empty variable or not (e.g., ``, `=foo`) - for _, env := range config.Env { - if _, err := opts.ValidateEnv(env); err != nil { - return nil, err - } - } - } - - if hostConfig == nil { - return nil, nil - } - - if hostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() { - return nil, fmt.Errorf("can't create 'AutoRemove' container with restart policy") - } - - for port := range hostConfig.PortBindings { - _, portStr := nat.SplitProtoPort(string(port)) - if _, err := nat.ParsePort(portStr); err != nil { - return nil, fmt.Errorf("invalid port specification: %q", portStr) - } - for _, pb := range hostConfig.PortBindings[port] { - _, err := nat.NewPort(nat.SplitProtoPort(pb.HostPort)) - if err != nil { - return nil, fmt.Errorf("invalid port specification: %q", pb.HostPort) - } - } - } - - p := hostConfig.RestartPolicy - - switch p.Name { - case "always", "unless-stopped", "no": - if p.MaximumRetryCount != 0 { - return nil, fmt.Errorf("maximum retry count cannot be used with restart policy '%s'", p.Name) - } - case "on-failure": - if p.MaximumRetryCount < 0 { - return nil, fmt.Errorf("maximum retry count cannot be negative") - } - case "": - // do nothing - default: - return nil, fmt.Errorf("invalid restart policy '%s'", p.Name) - } - - // Now do platform-specific verification - return verifyPlatformContainerSettings(daemon, hostConfig, config, update) -} diff --git a/vendor/github.com/docker/docker/daemon/container_operations.go b/vendor/github.com/docker/docker/daemon/container_operations.go deleted file mode 100644 index c302506..0000000 --- a/vendor/github.com/docker/docker/daemon/container_operations.go +++ /dev/null @@ -1,1049 +0,0 @@ -package daemon - -import ( - "errors" - "fmt" - "net" - "os" - "path" - "runtime" - "strings" - "time" - - "github.com/Sirupsen/logrus" - derr "github.com/docker/docker/api/errors" - containertypes "github.com/docker/docker/api/types/container" - networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/network" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/runconfig" - "github.com/docker/go-connections/nat" - "github.com/docker/libnetwork" - "github.com/docker/libnetwork/netlabel" - "github.com/docker/libnetwork/options" - "github.com/docker/libnetwork/types" -) - -var ( - // ErrRootFSReadOnly is returned when a container - // rootfs is marked readonly. - ErrRootFSReadOnly = errors.New("container rootfs is marked read-only") - getPortMapInfo = container.GetSandboxPortMapInfo -) - -func (daemon *Daemon) buildSandboxOptions(container *container.Container) ([]libnetwork.SandboxOption, error) { - var ( - sboxOptions []libnetwork.SandboxOption - err error - dns []string - dnsSearch []string - dnsOptions []string - bindings = make(nat.PortMap) - pbList []types.PortBinding - exposeList []types.TransportPort - ) - - defaultNetName := runconfig.DefaultDaemonNetworkMode().NetworkName() - sboxOptions = append(sboxOptions, libnetwork.OptionHostname(container.Config.Hostname), - libnetwork.OptionDomainname(container.Config.Domainname)) - - if container.HostConfig.NetworkMode.IsHost() { - sboxOptions = append(sboxOptions, libnetwork.OptionUseDefaultSandbox()) - if len(container.HostConfig.ExtraHosts) == 0 { - sboxOptions = append(sboxOptions, libnetwork.OptionOriginHostsPath("/etc/hosts")) - } - if len(container.HostConfig.DNS) == 0 && len(daemon.configStore.DNS) == 0 && - len(container.HostConfig.DNSSearch) == 0 && len(daemon.configStore.DNSSearch) == 0 && - len(container.HostConfig.DNSOptions) == 0 && len(daemon.configStore.DNSOptions) == 0 { - sboxOptions = append(sboxOptions, libnetwork.OptionOriginResolvConfPath("/etc/resolv.conf")) - } - } else { - // OptionUseExternalKey is mandatory for userns support. - // But optional for non-userns support - sboxOptions = append(sboxOptions, libnetwork.OptionUseExternalKey()) - } - - if err = setupPathsAndSandboxOptions(container, &sboxOptions); err != nil { - return nil, err - } - - if len(container.HostConfig.DNS) > 0 { - dns = container.HostConfig.DNS - } else if len(daemon.configStore.DNS) > 0 { - dns = daemon.configStore.DNS - } - - for _, d := range dns { - sboxOptions = append(sboxOptions, libnetwork.OptionDNS(d)) - } - - if len(container.HostConfig.DNSSearch) > 0 { - dnsSearch = container.HostConfig.DNSSearch - } else if len(daemon.configStore.DNSSearch) > 0 { - dnsSearch = daemon.configStore.DNSSearch - } - - for _, ds := range dnsSearch { - sboxOptions = append(sboxOptions, libnetwork.OptionDNSSearch(ds)) - } - - if len(container.HostConfig.DNSOptions) > 0 { - dnsOptions = container.HostConfig.DNSOptions - } else if len(daemon.configStore.DNSOptions) > 0 { - dnsOptions = daemon.configStore.DNSOptions - } - - for _, ds := range dnsOptions { - sboxOptions = append(sboxOptions, libnetwork.OptionDNSOptions(ds)) - } - - if container.NetworkSettings.SecondaryIPAddresses != nil { - name := container.Config.Hostname - if container.Config.Domainname != "" { - name = name + "." + container.Config.Domainname - } - - for _, a := range container.NetworkSettings.SecondaryIPAddresses { - sboxOptions = append(sboxOptions, libnetwork.OptionExtraHost(name, a.Addr)) - } - } - - for _, extraHost := range container.HostConfig.ExtraHosts { - // allow IPv6 addresses in extra hosts; only split on first ":" - parts := strings.SplitN(extraHost, ":", 2) - sboxOptions = append(sboxOptions, libnetwork.OptionExtraHost(parts[0], parts[1])) - } - - if container.HostConfig.PortBindings != nil { - for p, b := range container.HostConfig.PortBindings { - bindings[p] = []nat.PortBinding{} - for _, bb := range b { - bindings[p] = append(bindings[p], nat.PortBinding{ - HostIP: bb.HostIP, - HostPort: bb.HostPort, - }) - } - } - } - - portSpecs := container.Config.ExposedPorts - ports := make([]nat.Port, len(portSpecs)) - var i int - for p := range portSpecs { - ports[i] = p - i++ - } - nat.SortPortMap(ports, bindings) - for _, port := range ports { - expose := types.TransportPort{} - expose.Proto = types.ParseProtocol(port.Proto()) - expose.Port = uint16(port.Int()) - exposeList = append(exposeList, expose) - - pb := types.PortBinding{Port: expose.Port, Proto: expose.Proto} - binding := bindings[port] - for i := 0; i < len(binding); i++ { - pbCopy := pb.GetCopy() - newP, err := nat.NewPort(nat.SplitProtoPort(binding[i].HostPort)) - var portStart, portEnd int - if err == nil { - portStart, portEnd, err = newP.Range() - } - if err != nil { - return nil, fmt.Errorf("Error parsing HostPort value(%s):%v", binding[i].HostPort, err) - } - pbCopy.HostPort = uint16(portStart) - pbCopy.HostPortEnd = uint16(portEnd) - pbCopy.HostIP = net.ParseIP(binding[i].HostIP) - pbList = append(pbList, pbCopy) - } - - if container.HostConfig.PublishAllPorts && len(binding) == 0 { - pbList = append(pbList, pb) - } - } - - sboxOptions = append(sboxOptions, - libnetwork.OptionPortMapping(pbList), - libnetwork.OptionExposedPorts(exposeList)) - - // Legacy Link feature is supported only for the default bridge network. - // return if this call to build join options is not for default bridge network - // Legacy Link is only supported by docker run --link - bridgeSettings, ok := container.NetworkSettings.Networks[defaultNetName] - if !ok || bridgeSettings.EndpointSettings == nil { - return sboxOptions, nil - } - - if bridgeSettings.EndpointID == "" { - return sboxOptions, nil - } - - var ( - childEndpoints, parentEndpoints []string - cEndpointID string - ) - - children := daemon.children(container) - for linkAlias, child := range children { - if !isLinkable(child) { - return nil, fmt.Errorf("Cannot link to %s, as it does not belong to the default network", child.Name) - } - _, alias := path.Split(linkAlias) - // allow access to the linked container via the alias, real name, and container hostname - aliasList := alias + " " + child.Config.Hostname - // only add the name if alias isn't equal to the name - if alias != child.Name[1:] { - aliasList = aliasList + " " + child.Name[1:] - } - sboxOptions = append(sboxOptions, libnetwork.OptionExtraHost(aliasList, child.NetworkSettings.Networks[defaultNetName].IPAddress)) - cEndpointID = child.NetworkSettings.Networks[defaultNetName].EndpointID - if cEndpointID != "" { - childEndpoints = append(childEndpoints, cEndpointID) - } - } - - for alias, parent := range daemon.parents(container) { - if daemon.configStore.DisableBridge || !container.HostConfig.NetworkMode.IsPrivate() { - continue - } - - _, alias = path.Split(alias) - logrus.Debugf("Update /etc/hosts of %s for alias %s with ip %s", parent.ID, alias, bridgeSettings.IPAddress) - sboxOptions = append(sboxOptions, libnetwork.OptionParentUpdate( - parent.ID, - alias, - bridgeSettings.IPAddress, - )) - if cEndpointID != "" { - parentEndpoints = append(parentEndpoints, cEndpointID) - } - } - - linkOptions := options.Generic{ - netlabel.GenericData: options.Generic{ - "ParentEndpoints": parentEndpoints, - "ChildEndpoints": childEndpoints, - }, - } - - sboxOptions = append(sboxOptions, libnetwork.OptionGeneric(linkOptions)) - return sboxOptions, nil -} - -func (daemon *Daemon) updateNetworkSettings(container *container.Container, n libnetwork.Network, endpointConfig *networktypes.EndpointSettings) error { - if container.NetworkSettings == nil { - container.NetworkSettings = &network.Settings{Networks: make(map[string]*network.EndpointSettings)} - } - - if !container.HostConfig.NetworkMode.IsHost() && containertypes.NetworkMode(n.Type()).IsHost() { - return runconfig.ErrConflictHostNetwork - } - - for s := range container.NetworkSettings.Networks { - sn, err := daemon.FindNetwork(s) - if err != nil { - continue - } - - if sn.Name() == n.Name() { - // Avoid duplicate config - return nil - } - if !containertypes.NetworkMode(sn.Type()).IsPrivate() || - !containertypes.NetworkMode(n.Type()).IsPrivate() { - return runconfig.ErrConflictSharedNetwork - } - if containertypes.NetworkMode(sn.Name()).IsNone() || - containertypes.NetworkMode(n.Name()).IsNone() { - return runconfig.ErrConflictNoNetwork - } - } - - if _, ok := container.NetworkSettings.Networks[n.Name()]; !ok { - container.NetworkSettings.Networks[n.Name()] = &network.EndpointSettings{ - EndpointSettings: endpointConfig, - } - } - - return nil -} - -func (daemon *Daemon) updateEndpointNetworkSettings(container *container.Container, n libnetwork.Network, ep libnetwork.Endpoint) error { - if err := container.BuildEndpointInfo(n, ep); err != nil { - return err - } - - if container.HostConfig.NetworkMode == runconfig.DefaultDaemonNetworkMode() { - container.NetworkSettings.Bridge = daemon.configStore.bridgeConfig.Iface - } - - return nil -} - -// UpdateNetwork is used to update the container's network (e.g. when linked containers -// get removed/unlinked). -func (daemon *Daemon) updateNetwork(container *container.Container) error { - var ( - start = time.Now() - ctrl = daemon.netController - sid = container.NetworkSettings.SandboxID - ) - - sb, err := ctrl.SandboxByID(sid) - if err != nil { - return fmt.Errorf("error locating sandbox id %s: %v", sid, err) - } - - // Find if container is connected to the default bridge network - var n libnetwork.Network - for name := range container.NetworkSettings.Networks { - sn, err := daemon.FindNetwork(name) - if err != nil { - continue - } - if sn.Name() == runconfig.DefaultDaemonNetworkMode().NetworkName() { - n = sn - break - } - } - - if n == nil { - // Not connected to the default bridge network; Nothing to do - return nil - } - - options, err := daemon.buildSandboxOptions(container) - if err != nil { - return fmt.Errorf("Update network failed: %v", err) - } - - if err := sb.Refresh(options...); err != nil { - return fmt.Errorf("Update network failed: Failure in refresh sandbox %s: %v", sid, err) - } - - networkActions.WithValues("update").UpdateSince(start) - - return nil -} - -func (daemon *Daemon) findAndAttachNetwork(container *container.Container, idOrName string, epConfig *networktypes.EndpointSettings) (libnetwork.Network, *networktypes.NetworkingConfig, error) { - n, err := daemon.FindNetwork(idOrName) - if err != nil { - // We should always be able to find the network for a - // managed container. - if container.Managed { - return nil, nil, err - } - } - - // If we found a network and if it is not dynamically created - // we should never attempt to attach to that network here. - if n != nil { - if container.Managed || !n.Info().Dynamic() { - return n, nil, nil - } - } - - var addresses []string - if epConfig != nil && epConfig.IPAMConfig != nil { - if epConfig.IPAMConfig.IPv4Address != "" { - addresses = append(addresses, epConfig.IPAMConfig.IPv4Address) - } - - if epConfig.IPAMConfig.IPv6Address != "" { - addresses = append(addresses, epConfig.IPAMConfig.IPv6Address) - } - } - - var ( - config *networktypes.NetworkingConfig - retryCount int - ) - - for { - // In all other cases, attempt to attach to the network to - // trigger attachment in the swarm cluster manager. - if daemon.clusterProvider != nil { - var err error - config, err = daemon.clusterProvider.AttachNetwork(idOrName, container.ID, addresses) - if err != nil { - return nil, nil, err - } - } - - n, err = daemon.FindNetwork(idOrName) - if err != nil { - if daemon.clusterProvider != nil { - if err := daemon.clusterProvider.DetachNetwork(idOrName, container.ID); err != nil { - logrus.Warnf("Could not rollback attachment for container %s to network %s: %v", container.ID, idOrName, err) - } - } - - // Retry network attach again if we failed to - // find the network after successfull - // attachment because the only reason that - // would happen is if some other container - // attached to the swarm scope network went down - // and removed the network while we were in - // the process of attaching. - if config != nil { - if _, ok := err.(libnetwork.ErrNoSuchNetwork); ok { - if retryCount >= 5 { - return nil, nil, fmt.Errorf("could not find network %s after successful attachment", idOrName) - } - retryCount++ - continue - } - } - - return nil, nil, err - } - - break - } - - // This container has attachment to a swarm scope - // network. Update the container network settings accordingly. - container.NetworkSettings.HasSwarmEndpoint = true - return n, config, nil -} - -// updateContainerNetworkSettings update the network settings -func (daemon *Daemon) updateContainerNetworkSettings(container *container.Container, endpointsConfig map[string]*networktypes.EndpointSettings) { - var n libnetwork.Network - - mode := container.HostConfig.NetworkMode - if container.Config.NetworkDisabled || mode.IsContainer() { - return - } - - networkName := mode.NetworkName() - if mode.IsDefault() { - networkName = daemon.netController.Config().Daemon.DefaultNetwork - } - - if mode.IsUserDefined() { - var err error - - n, err = daemon.FindNetwork(networkName) - if err == nil { - networkName = n.Name() - } - } - - if container.NetworkSettings == nil { - container.NetworkSettings = &network.Settings{} - } - - if len(endpointsConfig) > 0 { - if container.NetworkSettings.Networks == nil { - container.NetworkSettings.Networks = make(map[string]*network.EndpointSettings) - } - - for name, epConfig := range endpointsConfig { - container.NetworkSettings.Networks[name] = &network.EndpointSettings{ - EndpointSettings: epConfig, - } - } - } - - if container.NetworkSettings.Networks == nil { - container.NetworkSettings.Networks = make(map[string]*network.EndpointSettings) - container.NetworkSettings.Networks[networkName] = &network.EndpointSettings{ - EndpointSettings: &networktypes.EndpointSettings{}, - } - } - - // Convert any settings added by client in default name to - // engine's default network name key - if mode.IsDefault() { - if nConf, ok := container.NetworkSettings.Networks[mode.NetworkName()]; ok { - container.NetworkSettings.Networks[networkName] = nConf - delete(container.NetworkSettings.Networks, mode.NetworkName()) - } - } - - if !mode.IsUserDefined() { - return - } - // Make sure to internally store the per network endpoint config by network name - if _, ok := container.NetworkSettings.Networks[networkName]; ok { - return - } - - if n != nil { - if nwConfig, ok := container.NetworkSettings.Networks[n.ID()]; ok { - container.NetworkSettings.Networks[networkName] = nwConfig - delete(container.NetworkSettings.Networks, n.ID()) - return - } - } -} - -func (daemon *Daemon) allocateNetwork(container *container.Container) error { - start := time.Now() - controller := daemon.netController - - if daemon.netController == nil { - return nil - } - - // Cleanup any stale sandbox left over due to ungraceful daemon shutdown - if err := controller.SandboxDestroy(container.ID); err != nil { - logrus.Errorf("failed to cleanup up stale network sandbox for container %s", container.ID) - } - - updateSettings := false - if len(container.NetworkSettings.Networks) == 0 { - if container.Config.NetworkDisabled || container.HostConfig.NetworkMode.IsContainer() { - return nil - } - - daemon.updateContainerNetworkSettings(container, nil) - updateSettings = true - } - - // always connect default network first since only default - // network mode support link and we need do some setting - // on sandbox initialize for link, but the sandbox only be initialized - // on first network connecting. - defaultNetName := runconfig.DefaultDaemonNetworkMode().NetworkName() - if nConf, ok := container.NetworkSettings.Networks[defaultNetName]; ok { - cleanOperationalData(nConf) - if err := daemon.connectToNetwork(container, defaultNetName, nConf.EndpointSettings, updateSettings); err != nil { - return err - } - - } - - // the intermediate map is necessary because "connectToNetwork" modifies "container.NetworkSettings.Networks" - networks := make(map[string]*network.EndpointSettings) - for n, epConf := range container.NetworkSettings.Networks { - if n == defaultNetName { - continue - } - - networks[n] = epConf - } - - for netName, epConf := range networks { - cleanOperationalData(epConf) - if err := daemon.connectToNetwork(container, netName, epConf.EndpointSettings, updateSettings); err != nil { - return err - } - } - - if err := container.WriteHostConfig(); err != nil { - return err - } - networkActions.WithValues("allocate").UpdateSince(start) - return nil -} - -func (daemon *Daemon) getNetworkSandbox(container *container.Container) libnetwork.Sandbox { - var sb libnetwork.Sandbox - daemon.netController.WalkSandboxes(func(s libnetwork.Sandbox) bool { - if s.ContainerID() == container.ID { - sb = s - return true - } - return false - }) - return sb -} - -// hasUserDefinedIPAddress returns whether the passed endpoint configuration contains IP address configuration -func hasUserDefinedIPAddress(epConfig *networktypes.EndpointSettings) bool { - return epConfig != nil && epConfig.IPAMConfig != nil && (len(epConfig.IPAMConfig.IPv4Address) > 0 || len(epConfig.IPAMConfig.IPv6Address) > 0) -} - -// User specified ip address is acceptable only for networks with user specified subnets. -func validateNetworkingConfig(n libnetwork.Network, epConfig *networktypes.EndpointSettings) error { - if n == nil || epConfig == nil { - return nil - } - if !hasUserDefinedIPAddress(epConfig) { - return nil - } - _, _, nwIPv4Configs, nwIPv6Configs := n.Info().IpamConfig() - for _, s := range []struct { - ipConfigured bool - subnetConfigs []*libnetwork.IpamConf - }{ - { - ipConfigured: len(epConfig.IPAMConfig.IPv4Address) > 0, - subnetConfigs: nwIPv4Configs, - }, - { - ipConfigured: len(epConfig.IPAMConfig.IPv6Address) > 0, - subnetConfigs: nwIPv6Configs, - }, - } { - if s.ipConfigured { - foundSubnet := false - for _, cfg := range s.subnetConfigs { - if len(cfg.PreferredPool) > 0 { - foundSubnet = true - break - } - } - if !foundSubnet { - return runconfig.ErrUnsupportedNetworkNoSubnetAndIP - } - } - } - - return nil -} - -// cleanOperationalData resets the operational data from the passed endpoint settings -func cleanOperationalData(es *network.EndpointSettings) { - es.EndpointID = "" - es.Gateway = "" - es.IPAddress = "" - es.IPPrefixLen = 0 - es.IPv6Gateway = "" - es.GlobalIPv6Address = "" - es.GlobalIPv6PrefixLen = 0 - es.MacAddress = "" - if es.IPAMOperational { - es.IPAMConfig = nil - } -} - -func (daemon *Daemon) updateNetworkConfig(container *container.Container, n libnetwork.Network, endpointConfig *networktypes.EndpointSettings, updateSettings bool) error { - - if !containertypes.NetworkMode(n.Name()).IsUserDefined() { - if hasUserDefinedIPAddress(endpointConfig) && !enableIPOnPredefinedNetwork() { - return runconfig.ErrUnsupportedNetworkAndIP - } - if endpointConfig != nil && len(endpointConfig.Aliases) > 0 && !container.EnableServiceDiscoveryOnDefaultNetwork() { - return runconfig.ErrUnsupportedNetworkAndAlias - } - } else { - addShortID := true - shortID := stringid.TruncateID(container.ID) - for _, alias := range endpointConfig.Aliases { - if alias == shortID { - addShortID = false - break - } - } - if addShortID { - endpointConfig.Aliases = append(endpointConfig.Aliases, shortID) - } - } - - if err := validateNetworkingConfig(n, endpointConfig); err != nil { - return err - } - - if updateSettings { - if err := daemon.updateNetworkSettings(container, n, endpointConfig); err != nil { - return err - } - } - return nil -} - -func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName string, endpointConfig *networktypes.EndpointSettings, updateSettings bool) (err error) { - start := time.Now() - if container.HostConfig.NetworkMode.IsContainer() { - return runconfig.ErrConflictSharedNetwork - } - if containertypes.NetworkMode(idOrName).IsBridge() && - daemon.configStore.DisableBridge { - container.Config.NetworkDisabled = true - return nil - } - if endpointConfig == nil { - endpointConfig = &networktypes.EndpointSettings{} - } - - n, config, err := daemon.findAndAttachNetwork(container, idOrName, endpointConfig) - if err != nil { - return err - } - if n == nil { - return nil - } - - var operIPAM bool - if config != nil { - if epConfig, ok := config.EndpointsConfig[n.Name()]; ok { - if endpointConfig.IPAMConfig == nil || - (endpointConfig.IPAMConfig.IPv4Address == "" && - endpointConfig.IPAMConfig.IPv6Address == "" && - len(endpointConfig.IPAMConfig.LinkLocalIPs) == 0) { - operIPAM = true - } - - // copy IPAMConfig and NetworkID from epConfig via AttachNetwork - endpointConfig.IPAMConfig = epConfig.IPAMConfig - endpointConfig.NetworkID = epConfig.NetworkID - } - } - - err = daemon.updateNetworkConfig(container, n, endpointConfig, updateSettings) - if err != nil { - return err - } - - controller := daemon.netController - sb := daemon.getNetworkSandbox(container) - createOptions, err := container.BuildCreateEndpointOptions(n, endpointConfig, sb, daemon.configStore.DNS) - if err != nil { - return err - } - - endpointName := strings.TrimPrefix(container.Name, "/") - ep, err := n.CreateEndpoint(endpointName, createOptions...) - if err != nil { - return err - } - defer func() { - if err != nil { - if e := ep.Delete(false); e != nil { - logrus.Warnf("Could not rollback container connection to network %s", idOrName) - } - } - }() - container.NetworkSettings.Networks[n.Name()] = &network.EndpointSettings{ - EndpointSettings: endpointConfig, - IPAMOperational: operIPAM, - } - if _, ok := container.NetworkSettings.Networks[n.ID()]; ok { - delete(container.NetworkSettings.Networks, n.ID()) - } - - if err := daemon.updateEndpointNetworkSettings(container, n, ep); err != nil { - return err - } - - if sb == nil { - options, err := daemon.buildSandboxOptions(container) - if err != nil { - return err - } - sb, err = controller.NewSandbox(container.ID, options...) - if err != nil { - return err - } - - container.UpdateSandboxNetworkSettings(sb) - } - - joinOptions, err := container.BuildJoinOptions(n) - if err != nil { - return err - } - - if err := ep.Join(sb, joinOptions...); err != nil { - return err - } - - if !container.Managed { - // add container name/alias to DNS - if err := daemon.ActivateContainerServiceBinding(container.Name); err != nil { - return fmt.Errorf("Activate container service binding for %s failed: %v", container.Name, err) - } - } - - if err := container.UpdateJoinInfo(n, ep); err != nil { - return fmt.Errorf("Updating join info failed: %v", err) - } - - container.NetworkSettings.Ports = getPortMapInfo(sb) - - daemon.LogNetworkEventWithAttributes(n, "connect", map[string]string{"container": container.ID}) - networkActions.WithValues("connect").UpdateSince(start) - return nil -} - -// ForceEndpointDelete deletes an endpoint from a network forcefully -func (daemon *Daemon) ForceEndpointDelete(name string, networkName string) error { - n, err := daemon.FindNetwork(networkName) - if err != nil { - return err - } - - ep, err := n.EndpointByName(name) - if err != nil { - return err - } - return ep.Delete(true) -} - -func (daemon *Daemon) disconnectFromNetwork(container *container.Container, n libnetwork.Network, force bool) error { - var ( - ep libnetwork.Endpoint - sbox libnetwork.Sandbox - ) - - s := func(current libnetwork.Endpoint) bool { - epInfo := current.Info() - if epInfo == nil { - return false - } - if sb := epInfo.Sandbox(); sb != nil { - if sb.ContainerID() == container.ID { - ep = current - sbox = sb - return true - } - } - return false - } - n.WalkEndpoints(s) - - if ep == nil && force { - epName := strings.TrimPrefix(container.Name, "/") - ep, err := n.EndpointByName(epName) - if err != nil { - return err - } - return ep.Delete(force) - } - - if ep == nil { - return fmt.Errorf("container %s is not connected to the network", container.ID) - } - - if err := ep.Leave(sbox); err != nil { - return fmt.Errorf("container %s failed to leave network %s: %v", container.ID, n.Name(), err) - } - - container.NetworkSettings.Ports = getPortMapInfo(sbox) - - if err := ep.Delete(false); err != nil { - return fmt.Errorf("endpoint delete failed for container %s on network %s: %v", container.ID, n.Name(), err) - } - - delete(container.NetworkSettings.Networks, n.Name()) - - if daemon.clusterProvider != nil && n.Info().Dynamic() && !container.Managed { - if err := daemon.clusterProvider.DetachNetwork(n.Name(), container.ID); err != nil { - logrus.Warnf("error detaching from network %s: %v", n.Name(), err) - if err := daemon.clusterProvider.DetachNetwork(n.ID(), container.ID); err != nil { - logrus.Warnf("error detaching from network %s: %v", n.ID(), err) - } - } - } - - return nil -} - -func (daemon *Daemon) initializeNetworking(container *container.Container) error { - var err error - - if container.HostConfig.NetworkMode.IsContainer() { - // we need to get the hosts files from the container to join - nc, err := daemon.getNetworkedContainer(container.ID, container.HostConfig.NetworkMode.ConnectedContainer()) - if err != nil { - return err - } - initializeNetworkingPaths(container, nc) - container.Config.Hostname = nc.Config.Hostname - container.Config.Domainname = nc.Config.Domainname - return nil - } - - if container.HostConfig.NetworkMode.IsHost() { - if container.Config.Hostname == "" { - container.Config.Hostname, err = os.Hostname() - if err != nil { - return err - } - } - } - - if err := daemon.allocateNetwork(container); err != nil { - return err - } - - return container.BuildHostnameFile() -} - -func (daemon *Daemon) getNetworkedContainer(containerID, connectedContainerID string) (*container.Container, error) { - nc, err := daemon.GetContainer(connectedContainerID) - if err != nil { - return nil, err - } - if containerID == nc.ID { - return nil, fmt.Errorf("cannot join own network") - } - if !nc.IsRunning() { - err := fmt.Errorf("cannot join network of a non running container: %s", connectedContainerID) - return nil, derr.NewRequestConflictError(err) - } - if nc.IsRestarting() { - return nil, errContainerIsRestarting(connectedContainerID) - } - return nc, nil -} - -func (daemon *Daemon) releaseNetwork(container *container.Container) { - start := time.Now() - if daemon.netController == nil { - return - } - if container.HostConfig.NetworkMode.IsContainer() || container.Config.NetworkDisabled { - return - } - - sid := container.NetworkSettings.SandboxID - settings := container.NetworkSettings.Networks - container.NetworkSettings.Ports = nil - - if sid == "" || len(settings) == 0 { - return - } - - var networks []libnetwork.Network - for n, epSettings := range settings { - if nw, err := daemon.FindNetwork(n); err == nil { - networks = append(networks, nw) - } - - if epSettings.EndpointSettings == nil { - continue - } - - cleanOperationalData(epSettings) - } - - sb, err := daemon.netController.SandboxByID(sid) - if err != nil { - logrus.Warnf("error locating sandbox id %s: %v", sid, err) - return - } - - if err := sb.Delete(); err != nil { - logrus.Errorf("Error deleting sandbox id %s for container %s: %v", sid, container.ID, err) - } - - for _, nw := range networks { - if daemon.clusterProvider != nil && nw.Info().Dynamic() && !container.Managed { - if err := daemon.clusterProvider.DetachNetwork(nw.Name(), container.ID); err != nil { - logrus.Warnf("error detaching from network %s: %v", nw.Name(), err) - if err := daemon.clusterProvider.DetachNetwork(nw.ID(), container.ID); err != nil { - logrus.Warnf("error detaching from network %s: %v", nw.ID(), err) - } - } - } - - attributes := map[string]string{ - "container": container.ID, - } - daemon.LogNetworkEventWithAttributes(nw, "disconnect", attributes) - } - networkActions.WithValues("release").UpdateSince(start) -} - -func errRemovalContainer(containerID string) error { - return fmt.Errorf("Container %s is marked for removal and cannot be connected or disconnected to the network", containerID) -} - -// ConnectToNetwork connects a container to a network -func (daemon *Daemon) ConnectToNetwork(container *container.Container, idOrName string, endpointConfig *networktypes.EndpointSettings) error { - if endpointConfig == nil { - endpointConfig = &networktypes.EndpointSettings{} - } - if !container.Running { - if container.RemovalInProgress || container.Dead { - return errRemovalContainer(container.ID) - } - - n, err := daemon.FindNetwork(idOrName) - if err == nil && n != nil { - if err := daemon.updateNetworkConfig(container, n, endpointConfig, true); err != nil { - return err - } - } else { - container.NetworkSettings.Networks[idOrName] = &network.EndpointSettings{ - EndpointSettings: endpointConfig, - } - } - } else if !daemon.isNetworkHotPluggable() { - return fmt.Errorf(runtime.GOOS + " does not support connecting a running container to a network") - } else { - if err := daemon.connectToNetwork(container, idOrName, endpointConfig, true); err != nil { - return err - } - } - if err := container.ToDiskLocking(); err != nil { - return fmt.Errorf("Error saving container to disk: %v", err) - } - return nil -} - -// DisconnectFromNetwork disconnects container from network n. -func (daemon *Daemon) DisconnectFromNetwork(container *container.Container, networkName string, force bool) error { - n, err := daemon.FindNetwork(networkName) - if !container.Running || (err != nil && force) { - if container.RemovalInProgress || container.Dead { - return errRemovalContainer(container.ID) - } - // In case networkName is resolved we will use n.Name() - // this will cover the case where network id is passed. - if n != nil { - networkName = n.Name() - } - if _, ok := container.NetworkSettings.Networks[networkName]; !ok { - return fmt.Errorf("container %s is not connected to the network %s", container.ID, networkName) - } - delete(container.NetworkSettings.Networks, networkName) - } else if err == nil && !daemon.isNetworkHotPluggable() { - return fmt.Errorf(runtime.GOOS + " does not support connecting a running container to a network") - } else if err == nil { - if container.HostConfig.NetworkMode.IsHost() && containertypes.NetworkMode(n.Type()).IsHost() { - return runconfig.ErrConflictHostNetwork - } - - if err := daemon.disconnectFromNetwork(container, n, false); err != nil { - return err - } - } else { - return err - } - - if err := container.ToDiskLocking(); err != nil { - return fmt.Errorf("Error saving container to disk: %v", err) - } - - if n != nil { - attributes := map[string]string{ - "container": container.ID, - } - daemon.LogNetworkEventWithAttributes(n, "disconnect", attributes) - } - return nil -} - -// ActivateContainerServiceBinding puts this container into load balancer active rotation and DNS response -func (daemon *Daemon) ActivateContainerServiceBinding(containerName string) error { - container, err := daemon.GetContainer(containerName) - if err != nil { - return err - } - sb := daemon.getNetworkSandbox(container) - if sb == nil { - return fmt.Errorf("network sandbox does not exist for container %s", containerName) - } - return sb.EnableService() -} - -// DeactivateContainerServiceBinding remove this container fromload balancer active rotation, and DNS response -func (daemon *Daemon) DeactivateContainerServiceBinding(containerName string) error { - container, err := daemon.GetContainer(containerName) - if err != nil { - return err - } - sb := daemon.getNetworkSandbox(container) - if sb == nil { - return fmt.Errorf("network sandbox does not exist for container %s", containerName) - } - return sb.DisableService() -} diff --git a/vendor/github.com/docker/docker/daemon/container_operations_solaris.go b/vendor/github.com/docker/docker/daemon/container_operations_solaris.go deleted file mode 100644 index 1653948..0000000 --- a/vendor/github.com/docker/docker/daemon/container_operations_solaris.go +++ /dev/null @@ -1,46 +0,0 @@ -// +build solaris - -package daemon - -import ( - "github.com/docker/docker/container" - "github.com/docker/docker/runconfig" - "github.com/docker/libnetwork" -) - -func (daemon *Daemon) setupLinkedContainers(container *container.Container) ([]string, error) { - return nil, nil -} - -func (daemon *Daemon) setupIpcDirs(container *container.Container) error { - return nil -} - -func killProcessDirectly(container *container.Container) error { - return nil -} - -func detachMounted(path string) error { - return nil -} - -func isLinkable(child *container.Container) bool { - // A container is linkable only if it belongs to the default network - _, ok := child.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()] - return ok -} - -func enableIPOnPredefinedNetwork() bool { - return false -} - -func (daemon *Daemon) isNetworkHotPluggable() bool { - return false -} - -func setupPathsAndSandboxOptions(container *container.Container, sboxOptions *[]libnetwork.SandboxOption) error { - return nil -} - -func initializeNetworkingPaths(container *container.Container, nc *container.Container) { -} diff --git a/vendor/github.com/docker/docker/daemon/container_operations_unix.go b/vendor/github.com/docker/docker/daemon/container_operations_unix.go deleted file mode 100644 index 2296045..0000000 --- a/vendor/github.com/docker/docker/daemon/container_operations_unix.go +++ /dev/null @@ -1,281 +0,0 @@ -// +build linux freebsd - -package daemon - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strconv" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - "github.com/cloudflare/cfssl/log" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/links" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/runconfig" - "github.com/docker/libnetwork" - "github.com/opencontainers/runc/libcontainer/label" - "github.com/pkg/errors" -) - -func (daemon *Daemon) setupLinkedContainers(container *container.Container) ([]string, error) { - var env []string - children := daemon.children(container) - - bridgeSettings := container.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()] - if bridgeSettings == nil || bridgeSettings.EndpointSettings == nil { - return nil, nil - } - - for linkAlias, child := range children { - if !child.IsRunning() { - return nil, fmt.Errorf("Cannot link to a non running container: %s AS %s", child.Name, linkAlias) - } - - childBridgeSettings := child.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()] - if childBridgeSettings == nil || childBridgeSettings.EndpointSettings == nil { - return nil, fmt.Errorf("container %s not attached to default bridge network", child.ID) - } - - link := links.NewLink( - bridgeSettings.IPAddress, - childBridgeSettings.IPAddress, - linkAlias, - child.Config.Env, - child.Config.ExposedPorts, - ) - - env = append(env, link.ToEnv()...) - } - - return env, nil -} - -func (daemon *Daemon) getIpcContainer(container *container.Container) (*container.Container, error) { - containerID := container.HostConfig.IpcMode.Container() - c, err := daemon.GetContainer(containerID) - if err != nil { - return nil, err - } - if !c.IsRunning() { - return nil, fmt.Errorf("cannot join IPC of a non running container: %s", containerID) - } - if c.IsRestarting() { - return nil, errContainerIsRestarting(container.ID) - } - return c, nil -} - -func (daemon *Daemon) getPidContainer(container *container.Container) (*container.Container, error) { - containerID := container.HostConfig.PidMode.Container() - c, err := daemon.GetContainer(containerID) - if err != nil { - return nil, err - } - if !c.IsRunning() { - return nil, fmt.Errorf("cannot join PID of a non running container: %s", containerID) - } - if c.IsRestarting() { - return nil, errContainerIsRestarting(container.ID) - } - return c, nil -} - -func (daemon *Daemon) setupIpcDirs(c *container.Container) error { - var err error - - c.ShmPath, err = c.ShmResourcePath() - if err != nil { - return err - } - - if c.HostConfig.IpcMode.IsContainer() { - ic, err := daemon.getIpcContainer(c) - if err != nil { - return err - } - c.ShmPath = ic.ShmPath - } else if c.HostConfig.IpcMode.IsHost() { - if _, err := os.Stat("/dev/shm"); err != nil { - return fmt.Errorf("/dev/shm is not mounted, but must be for --ipc=host") - } - c.ShmPath = "/dev/shm" - } else { - rootUID, rootGID := daemon.GetRemappedUIDGID() - if !c.HasMountFor("/dev/shm") { - shmPath, err := c.ShmResourcePath() - if err != nil { - return err - } - - if err := idtools.MkdirAllAs(shmPath, 0700, rootUID, rootGID); err != nil { - return err - } - - shmSize := container.DefaultSHMSize - if c.HostConfig.ShmSize != 0 { - shmSize = c.HostConfig.ShmSize - } - shmproperty := "mode=1777,size=" + strconv.FormatInt(shmSize, 10) - if err := syscall.Mount("shm", shmPath, "tmpfs", uintptr(syscall.MS_NOEXEC|syscall.MS_NOSUID|syscall.MS_NODEV), label.FormatMountLabel(shmproperty, c.GetMountLabel())); err != nil { - return fmt.Errorf("mounting shm tmpfs: %s", err) - } - if err := os.Chown(shmPath, rootUID, rootGID); err != nil { - return err - } - } - - } - - return nil -} - -func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) { - if len(c.SecretReferences) == 0 { - return nil - } - - localMountPath := c.SecretMountPath() - logrus.Debugf("secrets: setting up secret dir: %s", localMountPath) - - defer func() { - if setupErr != nil { - // cleanup - _ = detachMounted(localMountPath) - - if err := os.RemoveAll(localMountPath); err != nil { - log.Errorf("error cleaning up secret mount: %s", err) - } - } - }() - - // retrieve possible remapped range start for root UID, GID - rootUID, rootGID := daemon.GetRemappedUIDGID() - // create tmpfs - if err := idtools.MkdirAllAs(localMountPath, 0700, rootUID, rootGID); err != nil { - return errors.Wrap(err, "error creating secret local mount path") - } - tmpfsOwnership := fmt.Sprintf("uid=%d,gid=%d", rootUID, rootGID) - if err := mount.Mount("tmpfs", localMountPath, "tmpfs", "nodev,nosuid,noexec,"+tmpfsOwnership); err != nil { - return errors.Wrap(err, "unable to setup secret mount") - } - - for _, s := range c.SecretReferences { - if c.SecretStore == nil { - return fmt.Errorf("secret store is not initialized") - } - - // TODO (ehazlett): use type switch when more are supported - if s.File == nil { - return fmt.Errorf("secret target type is not a file target") - } - - targetPath := filepath.Clean(s.File.Name) - // ensure that the target is a filename only; no paths allowed - if targetPath != filepath.Base(targetPath) { - return fmt.Errorf("error creating secret: secret must not be a path") - } - - fPath := filepath.Join(localMountPath, targetPath) - if err := idtools.MkdirAllAs(filepath.Dir(fPath), 0700, rootUID, rootGID); err != nil { - return errors.Wrap(err, "error creating secret mount path") - } - - logrus.WithFields(logrus.Fields{ - "name": s.File.Name, - "path": fPath, - }).Debug("injecting secret") - secret := c.SecretStore.Get(s.SecretID) - if secret == nil { - return fmt.Errorf("unable to get secret from secret store") - } - if err := ioutil.WriteFile(fPath, secret.Spec.Data, s.File.Mode); err != nil { - return errors.Wrap(err, "error injecting secret") - } - - uid, err := strconv.Atoi(s.File.UID) - if err != nil { - return err - } - gid, err := strconv.Atoi(s.File.GID) - if err != nil { - return err - } - - if err := os.Chown(fPath, rootUID+uid, rootGID+gid); err != nil { - return errors.Wrap(err, "error setting ownership for secret") - } - } - - // remount secrets ro - if err := mount.Mount("tmpfs", localMountPath, "tmpfs", "remount,ro,"+tmpfsOwnership); err != nil { - return errors.Wrap(err, "unable to remount secret dir as readonly") - } - - return nil -} - -func killProcessDirectly(container *container.Container) error { - if _, err := container.WaitStop(10 * time.Second); err != nil { - // Ensure that we don't kill ourselves - if pid := container.GetPID(); pid != 0 { - logrus.Infof("Container %s failed to exit within 10 seconds of kill - trying direct SIGKILL", stringid.TruncateID(container.ID)) - if err := syscall.Kill(pid, 9); err != nil { - if err != syscall.ESRCH { - return err - } - e := errNoSuchProcess{pid, 9} - logrus.Debug(e) - return e - } - } - } - return nil -} - -func detachMounted(path string) error { - return syscall.Unmount(path, syscall.MNT_DETACH) -} - -func isLinkable(child *container.Container) bool { - // A container is linkable only if it belongs to the default network - _, ok := child.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()] - return ok -} - -func enableIPOnPredefinedNetwork() bool { - return false -} - -func (daemon *Daemon) isNetworkHotPluggable() bool { - return true -} - -func setupPathsAndSandboxOptions(container *container.Container, sboxOptions *[]libnetwork.SandboxOption) error { - var err error - - container.HostsPath, err = container.GetRootResourcePath("hosts") - if err != nil { - return err - } - *sboxOptions = append(*sboxOptions, libnetwork.OptionHostsPath(container.HostsPath)) - - container.ResolvConfPath, err = container.GetRootResourcePath("resolv.conf") - if err != nil { - return err - } - *sboxOptions = append(*sboxOptions, libnetwork.OptionResolvConfPath(container.ResolvConfPath)) - return nil -} - -func initializeNetworkingPaths(container *container.Container, nc *container.Container) { - container.HostnamePath = nc.HostnamePath - container.HostsPath = nc.HostsPath - container.ResolvConfPath = nc.ResolvConfPath -} diff --git a/vendor/github.com/docker/docker/daemon/container_operations_windows.go b/vendor/github.com/docker/docker/daemon/container_operations_windows.go deleted file mode 100644 index d05f251..0000000 --- a/vendor/github.com/docker/docker/daemon/container_operations_windows.go +++ /dev/null @@ -1,59 +0,0 @@ -// +build windows - -package daemon - -import ( - "github.com/docker/docker/container" - "github.com/docker/libnetwork" -) - -func (daemon *Daemon) setupLinkedContainers(container *container.Container) ([]string, error) { - return nil, nil -} - -// getSize returns real size & virtual size -func (daemon *Daemon) getSize(container *container.Container) (int64, int64) { - // TODO Windows - return 0, 0 -} - -func (daemon *Daemon) setupIpcDirs(container *container.Container) error { - return nil -} - -// TODO Windows: Fix Post-TP5. This is a hack to allow docker cp to work -// against containers which have volumes. You will still be able to cp -// to somewhere on the container drive, but not to any mounted volumes -// inside the container. Without this fix, docker cp is broken to any -// container which has a volume, regardless of where the file is inside the -// container. -func (daemon *Daemon) mountVolumes(container *container.Container) error { - return nil -} - -func detachMounted(path string) error { - return nil -} - -func killProcessDirectly(container *container.Container) error { - return nil -} - -func isLinkable(child *container.Container) bool { - return false -} - -func enableIPOnPredefinedNetwork() bool { - return true -} - -func (daemon *Daemon) isNetworkHotPluggable() bool { - return false -} - -func setupPathsAndSandboxOptions(container *container.Container, sboxOptions *[]libnetwork.SandboxOption) error { - return nil -} - -func initializeNetworkingPaths(container *container.Container, nc *container.Container) { -} diff --git a/vendor/github.com/docker/docker/daemon/create.go b/vendor/github.com/docker/docker/daemon/create.go deleted file mode 100644 index c71d14e..0000000 --- a/vendor/github.com/docker/docker/daemon/create.go +++ /dev/null @@ -1,290 +0,0 @@ -package daemon - -import ( - "fmt" - "net" - "runtime" - "strings" - "time" - - "github.com/pkg/errors" - - "github.com/Sirupsen/logrus" - apierrors "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/container" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/runconfig" - volumestore "github.com/docker/docker/volume/store" - "github.com/opencontainers/runc/libcontainer/label" -) - -// CreateManagedContainer creates a container that is managed by a Service -func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig) (containertypes.ContainerCreateCreatedBody, error) { - return daemon.containerCreate(params, true) -} - -// ContainerCreate creates a regular container -func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig) (containertypes.ContainerCreateCreatedBody, error) { - return daemon.containerCreate(params, false) -} - -func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool) (containertypes.ContainerCreateCreatedBody, error) { - start := time.Now() - if params.Config == nil { - return containertypes.ContainerCreateCreatedBody{}, fmt.Errorf("Config cannot be empty in order to create a container") - } - - warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config, false) - if err != nil { - return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err - } - - err = daemon.verifyNetworkingConfig(params.NetworkingConfig) - if err != nil { - return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err - } - - if params.HostConfig == nil { - params.HostConfig = &containertypes.HostConfig{} - } - err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares) - if err != nil { - return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err - } - - container, err := daemon.create(params, managed) - if err != nil { - return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, daemon.imageNotExistToErrcode(err) - } - containerActions.WithValues("create").UpdateSince(start) - - return containertypes.ContainerCreateCreatedBody{ID: container.ID, Warnings: warnings}, nil -} - -// Create creates a new container from the given configuration with a given name. -func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (retC *container.Container, retErr error) { - var ( - container *container.Container - img *image.Image - imgID image.ID - err error - ) - - if params.Config.Image != "" { - img, err = daemon.GetImage(params.Config.Image) - if err != nil { - return nil, err - } - - if runtime.GOOS == "solaris" && img.OS != "solaris " { - return nil, errors.New("Platform on which parent image was created is not Solaris") - } - imgID = img.ID() - } - - if err := daemon.mergeAndVerifyConfig(params.Config, img); err != nil { - return nil, err - } - - if err := daemon.mergeAndVerifyLogConfig(¶ms.HostConfig.LogConfig); err != nil { - return nil, err - } - - if container, err = daemon.newContainer(params.Name, params.Config, params.HostConfig, imgID, managed); err != nil { - return nil, err - } - defer func() { - if retErr != nil { - if err := daemon.cleanupContainer(container, true, true); err != nil { - logrus.Errorf("failed to cleanup container on create error: %v", err) - } - } - }() - - if err := daemon.setSecurityOptions(container, params.HostConfig); err != nil { - return nil, err - } - - container.HostConfig.StorageOpt = params.HostConfig.StorageOpt - - // Set RWLayer for container after mount labels have been set - if err := daemon.setRWLayer(container); err != nil { - return nil, err - } - - rootUID, rootGID, err := idtools.GetRootUIDGID(daemon.uidMaps, daemon.gidMaps) - if err != nil { - return nil, err - } - if err := idtools.MkdirAs(container.Root, 0700, rootUID, rootGID); err != nil { - return nil, err - } - if err := idtools.MkdirAs(container.CheckpointDir(), 0700, rootUID, rootGID); err != nil { - return nil, err - } - - if err := daemon.setHostConfig(container, params.HostConfig); err != nil { - return nil, err - } - - if err := daemon.createContainerPlatformSpecificSettings(container, params.Config, params.HostConfig); err != nil { - return nil, err - } - - var endpointsConfigs map[string]*networktypes.EndpointSettings - if params.NetworkingConfig != nil { - endpointsConfigs = params.NetworkingConfig.EndpointsConfig - } - // Make sure NetworkMode has an acceptable value. We do this to ensure - // backwards API compatibility. - container.HostConfig = runconfig.SetDefaultNetModeIfBlank(container.HostConfig) - - daemon.updateContainerNetworkSettings(container, endpointsConfigs) - - if err := container.ToDisk(); err != nil { - logrus.Errorf("Error saving new container to disk: %v", err) - return nil, err - } - if err := daemon.Register(container); err != nil { - return nil, err - } - daemon.LogContainerEvent(container, "create") - return container, nil -} - -func (daemon *Daemon) generateSecurityOpt(ipcMode containertypes.IpcMode, pidMode containertypes.PidMode, privileged bool) ([]string, error) { - if ipcMode.IsHost() || pidMode.IsHost() || privileged { - return label.DisableSecOpt(), nil - } - - var ipcLabel []string - var pidLabel []string - ipcContainer := ipcMode.Container() - pidContainer := pidMode.Container() - if ipcContainer != "" { - c, err := daemon.GetContainer(ipcContainer) - if err != nil { - return nil, err - } - ipcLabel = label.DupSecOpt(c.ProcessLabel) - if pidContainer == "" { - return ipcLabel, err - } - } - if pidContainer != "" { - c, err := daemon.GetContainer(pidContainer) - if err != nil { - return nil, err - } - - pidLabel = label.DupSecOpt(c.ProcessLabel) - if ipcContainer == "" { - return pidLabel, err - } - } - - if pidLabel != nil && ipcLabel != nil { - for i := 0; i < len(pidLabel); i++ { - if pidLabel[i] != ipcLabel[i] { - return nil, fmt.Errorf("--ipc and --pid containers SELinux labels aren't the same") - } - } - return pidLabel, nil - } - return nil, nil -} - -func (daemon *Daemon) setRWLayer(container *container.Container) error { - var layerID layer.ChainID - if container.ImageID != "" { - img, err := daemon.imageStore.Get(container.ImageID) - if err != nil { - return err - } - layerID = img.RootFS.ChainID() - } - - rwLayer, err := daemon.layerStore.CreateRWLayer(container.ID, layerID, container.MountLabel, daemon.getLayerInit(), container.HostConfig.StorageOpt) - - if err != nil { - return err - } - container.RWLayer = rwLayer - - return nil -} - -// VolumeCreate creates a volume with the specified name, driver, and opts -// This is called directly from the Engine API -func (daemon *Daemon) VolumeCreate(name, driverName string, opts, labels map[string]string) (*types.Volume, error) { - if name == "" { - name = stringid.GenerateNonCryptoID() - } - - v, err := daemon.volumes.Create(name, driverName, opts, labels) - if err != nil { - if volumestore.IsNameConflict(err) { - return nil, fmt.Errorf("A volume named %s already exists. Choose a different volume name.", name) - } - return nil, err - } - - daemon.LogVolumeEvent(v.Name(), "create", map[string]string{"driver": v.DriverName()}) - apiV := volumeToAPIType(v) - apiV.Mountpoint = v.Path() - return apiV, nil -} - -func (daemon *Daemon) mergeAndVerifyConfig(config *containertypes.Config, img *image.Image) error { - if img != nil && img.Config != nil { - if err := merge(config, img.Config); err != nil { - return err - } - } - // Reset the Entrypoint if it is [""] - if len(config.Entrypoint) == 1 && config.Entrypoint[0] == "" { - config.Entrypoint = nil - } - if len(config.Entrypoint) == 0 && len(config.Cmd) == 0 { - return fmt.Errorf("No command specified") - } - return nil -} - -// Checks if the client set configurations for more than one network while creating a container -// Also checks if the IPAMConfig is valid -func (daemon *Daemon) verifyNetworkingConfig(nwConfig *networktypes.NetworkingConfig) error { - if nwConfig == nil || len(nwConfig.EndpointsConfig) == 0 { - return nil - } - if len(nwConfig.EndpointsConfig) == 1 { - for _, v := range nwConfig.EndpointsConfig { - if v != nil && v.IPAMConfig != nil { - if v.IPAMConfig.IPv4Address != "" && net.ParseIP(v.IPAMConfig.IPv4Address).To4() == nil { - return apierrors.NewBadRequestError(fmt.Errorf("invalid IPv4 address: %s", v.IPAMConfig.IPv4Address)) - } - if v.IPAMConfig.IPv6Address != "" { - n := net.ParseIP(v.IPAMConfig.IPv6Address) - // if the address is an invalid network address (ParseIP == nil) or if it is - // an IPv4 address (To4() != nil), then it is an invalid IPv6 address - if n == nil || n.To4() != nil { - return apierrors.NewBadRequestError(fmt.Errorf("invalid IPv6 address: %s", v.IPAMConfig.IPv6Address)) - } - } - } - } - return nil - } - l := make([]string, 0, len(nwConfig.EndpointsConfig)) - for k := range nwConfig.EndpointsConfig { - l = append(l, k) - } - err := fmt.Errorf("Container cannot be connected to network endpoints: %s", strings.Join(l, ", ")) - return apierrors.NewBadRequestError(err) -} diff --git a/vendor/github.com/docker/docker/daemon/create_unix.go b/vendor/github.com/docker/docker/daemon/create_unix.go deleted file mode 100644 index 2fe5c98..0000000 --- a/vendor/github.com/docker/docker/daemon/create_unix.go +++ /dev/null @@ -1,81 +0,0 @@ -// +build !windows - -package daemon - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/Sirupsen/logrus" - containertypes "github.com/docker/docker/api/types/container" - mounttypes "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/stringid" - "github.com/opencontainers/runc/libcontainer/label" -) - -// createContainerPlatformSpecificSettings performs platform specific container create functionality -func (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error { - if err := daemon.Mount(container); err != nil { - return err - } - defer daemon.Unmount(container) - - rootUID, rootGID := daemon.GetRemappedUIDGID() - if err := container.SetupWorkingDirectory(rootUID, rootGID); err != nil { - return err - } - - for spec := range config.Volumes { - name := stringid.GenerateNonCryptoID() - destination := filepath.Clean(spec) - - // Skip volumes for which we already have something mounted on that - // destination because of a --volume-from. - if container.IsDestinationMounted(destination) { - continue - } - path, err := container.GetResourcePath(destination) - if err != nil { - return err - } - - stat, err := os.Stat(path) - if err == nil && !stat.IsDir() { - return fmt.Errorf("cannot mount volume over existing file, file exists %s", path) - } - - v, err := daemon.volumes.CreateWithRef(name, hostConfig.VolumeDriver, container.ID, nil, nil) - if err != nil { - return err - } - - if err := label.Relabel(v.Path(), container.MountLabel, true); err != nil { - return err - } - - container.AddMountPointWithVolume(destination, v, true) - } - return daemon.populateVolumes(container) -} - -// populateVolumes copies data from the container's rootfs into the volume for non-binds. -// this is only called when the container is created. -func (daemon *Daemon) populateVolumes(c *container.Container) error { - for _, mnt := range c.MountPoints { - if mnt.Volume == nil { - continue - } - - if mnt.Type != mounttypes.TypeVolume || !mnt.CopyData { - continue - } - - logrus.Debugf("copying image data from %s:%s, to %s", c.ID, mnt.Destination, mnt.Name) - if err := c.CopyImagePathContent(mnt.Volume, mnt.Destination); err != nil { - return err - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/create_windows.go b/vendor/github.com/docker/docker/daemon/create_windows.go deleted file mode 100644 index bbf0dbe..0000000 --- a/vendor/github.com/docker/docker/daemon/create_windows.go +++ /dev/null @@ -1,80 +0,0 @@ -package daemon - -import ( - "fmt" - - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/volume" -) - -// createContainerPlatformSpecificSettings performs platform specific container create functionality -func (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error { - // Make sure the host config has the default daemon isolation if not specified by caller. - if containertypes.Isolation.IsDefault(containertypes.Isolation(hostConfig.Isolation)) { - hostConfig.Isolation = daemon.defaultIsolation - } - - for spec := range config.Volumes { - - mp, err := volume.ParseMountRaw(spec, hostConfig.VolumeDriver) - if err != nil { - return fmt.Errorf("Unrecognised volume spec: %v", err) - } - - // If the mountpoint doesn't have a name, generate one. - if len(mp.Name) == 0 { - mp.Name = stringid.GenerateNonCryptoID() - } - - // Skip volumes for which we already have something mounted on that - // destination because of a --volume-from. - if container.IsDestinationMounted(mp.Destination) { - continue - } - - volumeDriver := hostConfig.VolumeDriver - - // Create the volume in the volume driver. If it doesn't exist, - // a new one will be created. - v, err := daemon.volumes.CreateWithRef(mp.Name, volumeDriver, container.ID, nil, nil) - if err != nil { - return err - } - - // FIXME Windows: This code block is present in the Linux version and - // allows the contents to be copied to the container FS prior to it - // being started. However, the function utilizes the FollowSymLinkInScope - // path which does not cope with Windows volume-style file paths. There - // is a separate effort to resolve this (@swernli), so this processing - // is deferred for now. A case where this would be useful is when - // a dockerfile includes a VOLUME statement, but something is created - // in that directory during the dockerfile processing. What this means - // on Windows for TP5 is that in that scenario, the contents will not - // copied, but that's (somewhat) OK as HCS will bomb out soon after - // at it doesn't support mapped directories which have contents in the - // destination path anyway. - // - // Example for repro later: - // FROM windowsservercore - // RUN mkdir c:\myvol - // RUN copy c:\windows\system32\ntdll.dll c:\myvol - // VOLUME "c:\myvol" - // - // Then - // docker build -t vol . - // docker run -it --rm vol cmd <-- This is where HCS will error out. - // - // // never attempt to copy existing content in a container FS to a shared volume - // if v.DriverName() == volume.DefaultDriverName { - // if err := container.CopyImagePathContent(v, mp.Destination); err != nil { - // return err - // } - // } - - // Add it to container.MountPoints - container.AddMountPointWithVolume(mp.Destination, v, mp.RW) - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/daemon.go b/vendor/github.com/docker/docker/daemon/daemon.go deleted file mode 100644 index 55a66ae..0000000 --- a/vendor/github.com/docker/docker/daemon/daemon.go +++ /dev/null @@ -1,1321 +0,0 @@ -// Package daemon exposes the functions that occur on the host server -// that the Docker daemon is running. -// -// In implementing the various functions of the daemon, there is often -// a method-specific struct for configuring the runtime behavior. -package daemon - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net" - "os" - "path" - "path/filepath" - "runtime" - "strings" - "sync" - "time" - - "github.com/Sirupsen/logrus" - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/docker/docker/api" - "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/events" - "github.com/docker/docker/daemon/exec" - "github.com/docker/docker/daemon/initlayer" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/plugin" - "github.com/docker/libnetwork/cluster" - // register graph drivers - _ "github.com/docker/docker/daemon/graphdriver/register" - dmetadata "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/distribution/xfer" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/migrate/v1" - "github.com/docker/docker/pkg/fileutils" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/plugingetter" - "github.com/docker/docker/pkg/registrar" - "github.com/docker/docker/pkg/signal" - "github.com/docker/docker/pkg/sysinfo" - "github.com/docker/docker/pkg/system" - "github.com/docker/docker/pkg/truncindex" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "github.com/docker/docker/runconfig" - volumedrivers "github.com/docker/docker/volume/drivers" - "github.com/docker/docker/volume/local" - "github.com/docker/docker/volume/store" - "github.com/docker/libnetwork" - nwconfig "github.com/docker/libnetwork/config" - "github.com/docker/libtrust" - "github.com/pkg/errors" -) - -var ( - // DefaultRuntimeBinary is the default runtime to be used by - // containerd if none is specified - DefaultRuntimeBinary = "docker-runc" - - // DefaultInitBinary is the name of the default init binary - DefaultInitBinary = "docker-init" - - errSystemNotSupported = fmt.Errorf("The Docker daemon is not supported on this platform.") -) - -// Daemon holds information about the Docker daemon. -type Daemon struct { - ID string - repository string - containers container.Store - execCommands *exec.Store - referenceStore reference.Store - downloadManager *xfer.LayerDownloadManager - uploadManager *xfer.LayerUploadManager - distributionMetadataStore dmetadata.Store - trustKey libtrust.PrivateKey - idIndex *truncindex.TruncIndex - configStore *Config - statsCollector *statsCollector - defaultLogConfig containertypes.LogConfig - RegistryService registry.Service - EventsService *events.Events - netController libnetwork.NetworkController - volumes *store.VolumeStore - discoveryWatcher discoveryReloader - root string - seccompEnabled bool - shutdown bool - uidMaps []idtools.IDMap - gidMaps []idtools.IDMap - layerStore layer.Store - imageStore image.Store - PluginStore *plugin.Store // todo: remove - pluginManager *plugin.Manager - nameIndex *registrar.Registrar - linkIndex *linkIndex - containerd libcontainerd.Client - containerdRemote libcontainerd.Remote - defaultIsolation containertypes.Isolation // Default isolation mode on Windows - clusterProvider cluster.Provider - cluster Cluster - - seccompProfile []byte - seccompProfilePath string -} - -// HasExperimental returns whether the experimental features of the daemon are enabled or not -func (daemon *Daemon) HasExperimental() bool { - if daemon.configStore != nil && daemon.configStore.Experimental { - return true - } - return false -} - -func (daemon *Daemon) restore() error { - var ( - currentDriver = daemon.GraphDriverName() - containers = make(map[string]*container.Container) - ) - - logrus.Info("Loading containers: start.") - - dir, err := ioutil.ReadDir(daemon.repository) - if err != nil { - return err - } - - for _, v := range dir { - id := v.Name() - container, err := daemon.load(id) - if err != nil { - logrus.Errorf("Failed to load container %v: %v", id, err) - continue - } - - // Ignore the container if it does not support the current driver being used by the graph - if (container.Driver == "" && currentDriver == "aufs") || container.Driver == currentDriver { - rwlayer, err := daemon.layerStore.GetRWLayer(container.ID) - if err != nil { - logrus.Errorf("Failed to load container mount %v: %v", id, err) - continue - } - container.RWLayer = rwlayer - logrus.Debugf("Loaded container %v", container.ID) - - containers[container.ID] = container - } else { - logrus.Debugf("Cannot load container %s because it was created with another graph driver.", container.ID) - } - } - - removeContainers := make(map[string]*container.Container) - restartContainers := make(map[*container.Container]chan struct{}) - activeSandboxes := make(map[string]interface{}) - for id, c := range containers { - if err := daemon.registerName(c); err != nil { - logrus.Errorf("Failed to register container %s: %s", c.ID, err) - delete(containers, id) - continue - } - if err := daemon.Register(c); err != nil { - logrus.Errorf("Failed to register container %s: %s", c.ID, err) - delete(containers, id) - continue - } - - // verify that all volumes valid and have been migrated from the pre-1.7 layout - if err := daemon.verifyVolumesInfo(c); err != nil { - // don't skip the container due to error - logrus.Errorf("Failed to verify volumes for container '%s': %v", c.ID, err) - } - - // The LogConfig.Type is empty if the container was created before docker 1.12 with default log driver. - // We should rewrite it to use the daemon defaults. - // Fixes https://github.com/docker/docker/issues/22536 - if c.HostConfig.LogConfig.Type == "" { - if err := daemon.mergeAndVerifyLogConfig(&c.HostConfig.LogConfig); err != nil { - logrus.Errorf("Failed to verify log config for container %s: %q", c.ID, err) - continue - } - } - } - - var migrateLegacyLinks bool // Not relevant on Windows - var wg sync.WaitGroup - var mapLock sync.Mutex - for _, c := range containers { - wg.Add(1) - go func(c *container.Container) { - defer wg.Done() - if err := backportMountSpec(c); err != nil { - logrus.Error("Failed to migrate old mounts to use new spec format") - } - - if c.IsRunning() || c.IsPaused() { - c.RestartManager().Cancel() // manually start containers because some need to wait for swarm networking - if err := daemon.containerd.Restore(c.ID, c.InitializeStdio); err != nil { - logrus.Errorf("Failed to restore %s with containerd: %s", c.ID, err) - return - } - - // we call Mount and then Unmount to get BaseFs of the container - if err := daemon.Mount(c); err != nil { - // The mount is unlikely to fail. However, in case mount fails - // the container should be allowed to restore here. Some functionalities - // (like docker exec -u user) might be missing but container is able to be - // stopped/restarted/removed. - // See #29365 for related information. - // The error is only logged here. - logrus.Warnf("Failed to mount container on getting BaseFs path %v: %v", c.ID, err) - } else { - // if mount success, then unmount it - if err := daemon.Unmount(c); err != nil { - logrus.Warnf("Failed to umount container on getting BaseFs path %v: %v", c.ID, err) - } - } - - c.ResetRestartManager(false) - if !c.HostConfig.NetworkMode.IsContainer() && c.IsRunning() { - options, err := daemon.buildSandboxOptions(c) - if err != nil { - logrus.Warnf("Failed build sandbox option to restore container %s: %v", c.ID, err) - } - mapLock.Lock() - activeSandboxes[c.NetworkSettings.SandboxID] = options - mapLock.Unlock() - } - - } - // fixme: only if not running - // get list of containers we need to restart - if !c.IsRunning() && !c.IsPaused() { - // Do not autostart containers which - // has endpoints in a swarm scope - // network yet since the cluster is - // not initialized yet. We will start - // it after the cluster is - // initialized. - if daemon.configStore.AutoRestart && c.ShouldRestart() && !c.NetworkSettings.HasSwarmEndpoint { - mapLock.Lock() - restartContainers[c] = make(chan struct{}) - mapLock.Unlock() - } else if c.HostConfig != nil && c.HostConfig.AutoRemove { - mapLock.Lock() - removeContainers[c.ID] = c - mapLock.Unlock() - } - } - - if c.RemovalInProgress { - // We probably crashed in the middle of a removal, reset - // the flag. - // - // We DO NOT remove the container here as we do not - // know if the user had requested for either the - // associated volumes, network links or both to also - // be removed. So we put the container in the "dead" - // state and leave further processing up to them. - logrus.Debugf("Resetting RemovalInProgress flag from %v", c.ID) - c.ResetRemovalInProgress() - c.SetDead() - c.ToDisk() - } - - // if c.hostConfig.Links is nil (not just empty), then it is using the old sqlite links and needs to be migrated - if c.HostConfig != nil && c.HostConfig.Links == nil { - migrateLegacyLinks = true - } - }(c) - } - wg.Wait() - daemon.netController, err = daemon.initNetworkController(daemon.configStore, activeSandboxes) - if err != nil { - return fmt.Errorf("Error initializing network controller: %v", err) - } - - // Perform migration of legacy sqlite links (no-op on Windows) - if migrateLegacyLinks { - if err := daemon.sqliteMigration(containers); err != nil { - return err - } - } - - // Now that all the containers are registered, register the links - for _, c := range containers { - if err := daemon.registerLinks(c, c.HostConfig); err != nil { - logrus.Errorf("failed to register link for container %s: %v", c.ID, err) - } - } - - group := sync.WaitGroup{} - for c, notifier := range restartContainers { - group.Add(1) - - go func(c *container.Container, chNotify chan struct{}) { - defer group.Done() - - logrus.Debugf("Starting container %s", c.ID) - - // ignore errors here as this is a best effort to wait for children to be - // running before we try to start the container - children := daemon.children(c) - timeout := time.After(5 * time.Second) - for _, child := range children { - if notifier, exists := restartContainers[child]; exists { - select { - case <-notifier: - case <-timeout: - } - } - } - - // Make sure networks are available before starting - daemon.waitForNetworks(c) - if err := daemon.containerStart(c, "", "", true); err != nil { - logrus.Errorf("Failed to start container %s: %s", c.ID, err) - } - close(chNotify) - }(c, notifier) - - } - group.Wait() - - removeGroup := sync.WaitGroup{} - for id := range removeContainers { - removeGroup.Add(1) - go func(cid string) { - if err := daemon.ContainerRm(cid, &types.ContainerRmConfig{ForceRemove: true, RemoveVolume: true}); err != nil { - logrus.Errorf("Failed to remove container %s: %s", cid, err) - } - removeGroup.Done() - }(id) - } - removeGroup.Wait() - - // any containers that were started above would already have had this done, - // however we need to now prepare the mountpoints for the rest of the containers as well. - // This shouldn't cause any issue running on the containers that already had this run. - // This must be run after any containers with a restart policy so that containerized plugins - // can have a chance to be running before we try to initialize them. - for _, c := range containers { - // if the container has restart policy, do not - // prepare the mountpoints since it has been done on restarting. - // This is to speed up the daemon start when a restart container - // has a volume and the volume dirver is not available. - if _, ok := restartContainers[c]; ok { - continue - } else if _, ok := removeContainers[c.ID]; ok { - // container is automatically removed, skip it. - continue - } - - group.Add(1) - go func(c *container.Container) { - defer group.Done() - if err := daemon.prepareMountPoints(c); err != nil { - logrus.Error(err) - } - }(c) - } - - group.Wait() - - logrus.Info("Loading containers: done.") - - return nil -} - -// RestartSwarmContainers restarts any autostart container which has a -// swarm endpoint. -func (daemon *Daemon) RestartSwarmContainers() { - group := sync.WaitGroup{} - for _, c := range daemon.List() { - if !c.IsRunning() && !c.IsPaused() { - // Autostart all the containers which has a - // swarm endpoint now that the cluster is - // initialized. - if daemon.configStore.AutoRestart && c.ShouldRestart() && c.NetworkSettings.HasSwarmEndpoint { - group.Add(1) - go func(c *container.Container) { - defer group.Done() - if err := daemon.containerStart(c, "", "", true); err != nil { - logrus.Error(err) - } - }(c) - } - } - - } - group.Wait() -} - -// waitForNetworks is used during daemon initialization when starting up containers -// It ensures that all of a container's networks are available before the daemon tries to start the container. -// In practice it just makes sure the discovery service is available for containers which use a network that require discovery. -func (daemon *Daemon) waitForNetworks(c *container.Container) { - if daemon.discoveryWatcher == nil { - return - } - // Make sure if the container has a network that requires discovery that the discovery service is available before starting - for netName := range c.NetworkSettings.Networks { - // If we get `ErrNoSuchNetwork` here, we can assume that it is due to discovery not being ready - // Most likely this is because the K/V store used for discovery is in a container and needs to be started - if _, err := daemon.netController.NetworkByName(netName); err != nil { - if _, ok := err.(libnetwork.ErrNoSuchNetwork); !ok { - continue - } - // use a longish timeout here due to some slowdowns in libnetwork if the k/v store is on anything other than --net=host - // FIXME: why is this slow??? - logrus.Debugf("Container %s waiting for network to be ready", c.Name) - select { - case <-daemon.discoveryWatcher.ReadyCh(): - case <-time.After(60 * time.Second): - } - return - } - } -} - -func (daemon *Daemon) children(c *container.Container) map[string]*container.Container { - return daemon.linkIndex.children(c) -} - -// parents returns the names of the parent containers of the container -// with the given name. -func (daemon *Daemon) parents(c *container.Container) map[string]*container.Container { - return daemon.linkIndex.parents(c) -} - -func (daemon *Daemon) registerLink(parent, child *container.Container, alias string) error { - fullName := path.Join(parent.Name, alias) - if err := daemon.nameIndex.Reserve(fullName, child.ID); err != nil { - if err == registrar.ErrNameReserved { - logrus.Warnf("error registering link for %s, to %s, as alias %s, ignoring: %v", parent.ID, child.ID, alias, err) - return nil - } - return err - } - daemon.linkIndex.link(parent, child, fullName) - return nil -} - -// DaemonJoinsCluster informs the daemon has joined the cluster and provides -// the handler to query the cluster component -func (daemon *Daemon) DaemonJoinsCluster(clusterProvider cluster.Provider) { - daemon.setClusterProvider(clusterProvider) -} - -// DaemonLeavesCluster informs the daemon has left the cluster -func (daemon *Daemon) DaemonLeavesCluster() { - // Daemon is in charge of removing the attachable networks with - // connected containers when the node leaves the swarm - daemon.clearAttachableNetworks() - daemon.setClusterProvider(nil) -} - -// setClusterProvider sets a component for querying the current cluster state. -func (daemon *Daemon) setClusterProvider(clusterProvider cluster.Provider) { - daemon.clusterProvider = clusterProvider - // call this in a goroutine to allow netcontroller handle this event async - // and not block if it is in the middle of talking with cluster - go daemon.netController.SetClusterProvider(clusterProvider) -} - -// IsSwarmCompatible verifies if the current daemon -// configuration is compatible with the swarm mode -func (daemon *Daemon) IsSwarmCompatible() error { - if daemon.configStore == nil { - return nil - } - return daemon.configStore.isSwarmCompatible() -} - -// NewDaemon sets up everything for the daemon to be able to service -// requests from the webserver. -func NewDaemon(config *Config, registryService registry.Service, containerdRemote libcontainerd.Remote) (daemon *Daemon, err error) { - setDefaultMtu(config) - - // Ensure that we have a correct root key limit for launching containers. - if err := ModifyRootKeyLimit(); err != nil { - logrus.Warnf("unable to modify root key limit, number of containers could be limited by this quota: %v", err) - } - - // Ensure we have compatible and valid configuration options - if err := verifyDaemonSettings(config); err != nil { - return nil, err - } - - // Do we have a disabled network? - config.DisableBridge = isBridgeNetworkDisabled(config) - - // Verify the platform is supported as a daemon - if !platformSupported { - return nil, errSystemNotSupported - } - - // Validate platform-specific requirements - if err := checkSystem(); err != nil { - return nil, err - } - - uidMaps, gidMaps, err := setupRemappedRoot(config) - if err != nil { - return nil, err - } - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) - if err != nil { - return nil, err - } - - if err := setupDaemonProcess(config); err != nil { - return nil, err - } - - // set up the tmpDir to use a canonical path - tmp, err := tempDir(config.Root, rootUID, rootGID) - if err != nil { - return nil, fmt.Errorf("Unable to get the TempDir under %s: %s", config.Root, err) - } - realTmp, err := fileutils.ReadSymlinkedDirectory(tmp) - if err != nil { - return nil, fmt.Errorf("Unable to get the full path to the TempDir (%s): %s", tmp, err) - } - os.Setenv("TMPDIR", realTmp) - - d := &Daemon{configStore: config} - // Ensure the daemon is properly shutdown if there is a failure during - // initialization - defer func() { - if err != nil { - if err := d.Shutdown(); err != nil { - logrus.Error(err) - } - } - }() - - if err := d.setupSeccompProfile(); err != nil { - return nil, err - } - - // Set the default isolation mode (only applicable on Windows) - if err := d.setDefaultIsolation(); err != nil { - return nil, fmt.Errorf("error setting default isolation mode: %v", err) - } - - logrus.Debugf("Using default logging driver %s", config.LogConfig.Type) - - if err := configureMaxThreads(config); err != nil { - logrus.Warnf("Failed to configure golang's threads limit: %v", err) - } - - if err := ensureDefaultAppArmorProfile(); err != nil { - logrus.Errorf(err.Error()) - } - - daemonRepo := filepath.Join(config.Root, "containers") - if err := idtools.MkdirAllAs(daemonRepo, 0700, rootUID, rootGID); err != nil && !os.IsExist(err) { - return nil, err - } - - if runtime.GOOS == "windows" { - if err := system.MkdirAll(filepath.Join(config.Root, "credentialspecs"), 0); err != nil && !os.IsExist(err) { - return nil, err - } - } - - driverName := os.Getenv("DOCKER_DRIVER") - if driverName == "" { - driverName = config.GraphDriver - } - - d.RegistryService = registryService - d.PluginStore = plugin.NewStore(config.Root) // todo: remove - // Plugin system initialization should happen before restore. Do not change order. - d.pluginManager, err = plugin.NewManager(plugin.ManagerConfig{ - Root: filepath.Join(config.Root, "plugins"), - ExecRoot: "/run/docker/plugins", // possibly needs fixing - Store: d.PluginStore, - Executor: containerdRemote, - RegistryService: registryService, - LiveRestoreEnabled: config.LiveRestoreEnabled, - LogPluginEvent: d.LogPluginEvent, // todo: make private - }) - if err != nil { - return nil, errors.Wrap(err, "couldn't create plugin manager") - } - - d.layerStore, err = layer.NewStoreFromOptions(layer.StoreOptions{ - StorePath: config.Root, - MetadataStorePathTemplate: filepath.Join(config.Root, "image", "%s", "layerdb"), - GraphDriver: driverName, - GraphDriverOptions: config.GraphOptions, - UIDMaps: uidMaps, - GIDMaps: gidMaps, - PluginGetter: d.PluginStore, - ExperimentalEnabled: config.Experimental, - }) - if err != nil { - return nil, err - } - - graphDriver := d.layerStore.DriverName() - imageRoot := filepath.Join(config.Root, "image", graphDriver) - - // Configure and validate the kernels security support - if err := configureKernelSecuritySupport(config, graphDriver); err != nil { - return nil, err - } - - logrus.Debugf("Max Concurrent Downloads: %d", *config.MaxConcurrentDownloads) - d.downloadManager = xfer.NewLayerDownloadManager(d.layerStore, *config.MaxConcurrentDownloads) - logrus.Debugf("Max Concurrent Uploads: %d", *config.MaxConcurrentUploads) - d.uploadManager = xfer.NewLayerUploadManager(*config.MaxConcurrentUploads) - - ifs, err := image.NewFSStoreBackend(filepath.Join(imageRoot, "imagedb")) - if err != nil { - return nil, err - } - - d.imageStore, err = image.NewImageStore(ifs, d.layerStore) - if err != nil { - return nil, err - } - - // Configure the volumes driver - volStore, err := d.configureVolumes(rootUID, rootGID) - if err != nil { - return nil, err - } - - trustKey, err := api.LoadOrCreateTrustKey(config.TrustKeyPath) - if err != nil { - return nil, err - } - - trustDir := filepath.Join(config.Root, "trust") - - if err := system.MkdirAll(trustDir, 0700); err != nil { - return nil, err - } - - distributionMetadataStore, err := dmetadata.NewFSMetadataStore(filepath.Join(imageRoot, "distribution")) - if err != nil { - return nil, err - } - - eventsService := events.New() - - referenceStore, err := reference.NewReferenceStore(filepath.Join(imageRoot, "repositories.json")) - if err != nil { - return nil, fmt.Errorf("Couldn't create Tag store repositories: %s", err) - } - - migrationStart := time.Now() - if err := v1.Migrate(config.Root, graphDriver, d.layerStore, d.imageStore, referenceStore, distributionMetadataStore); err != nil { - logrus.Errorf("Graph migration failed: %q. Your old graph data was found to be too inconsistent for upgrading to content-addressable storage. Some of the old data was probably not upgraded. We recommend starting over with a clean storage directory if possible.", err) - } - logrus.Infof("Graph migration to content-addressability took %.2f seconds", time.Since(migrationStart).Seconds()) - - // Discovery is only enabled when the daemon is launched with an address to advertise. When - // initialized, the daemon is registered and we can store the discovery backend as its read-only - if err := d.initDiscovery(config); err != nil { - return nil, err - } - - sysInfo := sysinfo.New(false) - // Check if Devices cgroup is mounted, it is hard requirement for container security, - // on Linux. - if runtime.GOOS == "linux" && !sysInfo.CgroupDevicesEnabled { - return nil, fmt.Errorf("Devices cgroup isn't mounted") - } - - d.ID = trustKey.PublicKey().KeyID() - d.repository = daemonRepo - d.containers = container.NewMemoryStore() - d.execCommands = exec.NewStore() - d.referenceStore = referenceStore - d.distributionMetadataStore = distributionMetadataStore - d.trustKey = trustKey - d.idIndex = truncindex.NewTruncIndex([]string{}) - d.statsCollector = d.newStatsCollector(1 * time.Second) - d.defaultLogConfig = containertypes.LogConfig{ - Type: config.LogConfig.Type, - Config: config.LogConfig.Config, - } - d.EventsService = eventsService - d.volumes = volStore - d.root = config.Root - d.uidMaps = uidMaps - d.gidMaps = gidMaps - d.seccompEnabled = sysInfo.Seccomp - - d.nameIndex = registrar.NewRegistrar() - d.linkIndex = newLinkIndex() - d.containerdRemote = containerdRemote - - go d.execCommandGC() - - d.containerd, err = containerdRemote.Client(d) - if err != nil { - return nil, err - } - - if err := d.restore(); err != nil { - return nil, err - } - - // FIXME: this method never returns an error - info, _ := d.SystemInfo() - - engineVersion.WithValues( - dockerversion.Version, - dockerversion.GitCommit, - info.Architecture, - info.Driver, - info.KernelVersion, - info.OperatingSystem, - ).Set(1) - engineCpus.Set(float64(info.NCPU)) - engineMemory.Set(float64(info.MemTotal)) - - // set up SIGUSR1 handler on Unix-like systems, or a Win32 global event - // on Windows to dump Go routine stacks - stackDumpDir := config.Root - if execRoot := config.GetExecRoot(); execRoot != "" { - stackDumpDir = execRoot - } - d.setupDumpStackTrap(stackDumpDir) - - return d, nil -} - -func (daemon *Daemon) shutdownContainer(c *container.Container) error { - stopTimeout := c.StopTimeout() - // TODO(windows): Handle docker restart with paused containers - if c.IsPaused() { - // To terminate a process in freezer cgroup, we should send - // SIGTERM to this process then unfreeze it, and the process will - // force to terminate immediately. - logrus.Debugf("Found container %s is paused, sending SIGTERM before unpausing it", c.ID) - sig, ok := signal.SignalMap["TERM"] - if !ok { - return fmt.Errorf("System does not support SIGTERM") - } - if err := daemon.kill(c, int(sig)); err != nil { - return fmt.Errorf("sending SIGTERM to container %s with error: %v", c.ID, err) - } - if err := daemon.containerUnpause(c); err != nil { - return fmt.Errorf("Failed to unpause container %s with error: %v", c.ID, err) - } - if _, err := c.WaitStop(time.Duration(stopTimeout) * time.Second); err != nil { - logrus.Debugf("container %s failed to exit in %d second of SIGTERM, sending SIGKILL to force", c.ID, stopTimeout) - sig, ok := signal.SignalMap["KILL"] - if !ok { - return fmt.Errorf("System does not support SIGKILL") - } - if err := daemon.kill(c, int(sig)); err != nil { - logrus.Errorf("Failed to SIGKILL container %s", c.ID) - } - c.WaitStop(-1 * time.Second) - return err - } - } - // If container failed to exit in stopTimeout seconds of SIGTERM, then using the force - if err := daemon.containerStop(c, stopTimeout); err != nil { - return fmt.Errorf("Failed to stop container %s with error: %v", c.ID, err) - } - - c.WaitStop(-1 * time.Second) - return nil -} - -// ShutdownTimeout returns the shutdown timeout based on the max stopTimeout of the containers, -// and is limited by daemon's ShutdownTimeout. -func (daemon *Daemon) ShutdownTimeout() int { - // By default we use daemon's ShutdownTimeout. - shutdownTimeout := daemon.configStore.ShutdownTimeout - - graceTimeout := 5 - if daemon.containers != nil { - for _, c := range daemon.containers.List() { - if shutdownTimeout >= 0 { - stopTimeout := c.StopTimeout() - if stopTimeout < 0 { - shutdownTimeout = -1 - } else { - if stopTimeout+graceTimeout > shutdownTimeout { - shutdownTimeout = stopTimeout + graceTimeout - } - } - } - } - } - return shutdownTimeout -} - -// Shutdown stops the daemon. -func (daemon *Daemon) Shutdown() error { - daemon.shutdown = true - // Keep mounts and networking running on daemon shutdown if - // we are to keep containers running and restore them. - - if daemon.configStore.LiveRestoreEnabled && daemon.containers != nil { - // check if there are any running containers, if none we should do some cleanup - if ls, err := daemon.Containers(&types.ContainerListOptions{}); len(ls) != 0 || err != nil { - return nil - } - } - - if daemon.containers != nil { - logrus.Debugf("start clean shutdown of all containers with a %d seconds timeout...", daemon.configStore.ShutdownTimeout) - daemon.containers.ApplyAll(func(c *container.Container) { - if !c.IsRunning() { - return - } - logrus.Debugf("stopping %s", c.ID) - if err := daemon.shutdownContainer(c); err != nil { - logrus.Errorf("Stop container error: %v", err) - return - } - if mountid, err := daemon.layerStore.GetMountID(c.ID); err == nil { - daemon.cleanupMountsByID(mountid) - } - logrus.Debugf("container stopped %s", c.ID) - }) - } - - if daemon.volumes != nil { - if err := daemon.volumes.Shutdown(); err != nil { - logrus.Errorf("Error shutting down volume store: %v", err) - } - } - - if daemon.layerStore != nil { - if err := daemon.layerStore.Cleanup(); err != nil { - logrus.Errorf("Error during layer Store.Cleanup(): %v", err) - } - } - - // Shutdown plugins after containers and layerstore. Don't change the order. - daemon.pluginShutdown() - - // trigger libnetwork Stop only if it's initialized - if daemon.netController != nil { - daemon.netController.Stop() - } - - if err := daemon.cleanupMounts(); err != nil { - return err - } - - return nil -} - -// Mount sets container.BaseFS -// (is it not set coming in? why is it unset?) -func (daemon *Daemon) Mount(container *container.Container) error { - dir, err := container.RWLayer.Mount(container.GetMountLabel()) - if err != nil { - return err - } - logrus.Debugf("container mounted via layerStore: %v", dir) - - if container.BaseFS != dir { - // The mount path reported by the graph driver should always be trusted on Windows, since the - // volume path for a given mounted layer may change over time. This should only be an error - // on non-Windows operating systems. - if container.BaseFS != "" && runtime.GOOS != "windows" { - daemon.Unmount(container) - return fmt.Errorf("Error: driver %s is returning inconsistent paths for container %s ('%s' then '%s')", - daemon.GraphDriverName(), container.ID, container.BaseFS, dir) - } - } - container.BaseFS = dir // TODO: combine these fields - return nil -} - -// Unmount unsets the container base filesystem -func (daemon *Daemon) Unmount(container *container.Container) error { - if err := container.RWLayer.Unmount(); err != nil { - logrus.Errorf("Error unmounting container %s: %s", container.ID, err) - return err - } - - return nil -} - -// V4Subnets returns the IPv4 subnets of networks that are managed by Docker. -func (daemon *Daemon) V4Subnets() []net.IPNet { - var subnets []net.IPNet - - managedNetworks := daemon.netController.Networks() - - for _, managedNetwork := range managedNetworks { - v4Infos, _ := managedNetwork.Info().IpamInfo() - for _, v4Info := range v4Infos { - if v4Info.IPAMData.Pool != nil { - subnets = append(subnets, *v4Info.IPAMData.Pool) - } - } - } - - return subnets -} - -// V6Subnets returns the IPv6 subnets of networks that are managed by Docker. -func (daemon *Daemon) V6Subnets() []net.IPNet { - var subnets []net.IPNet - - managedNetworks := daemon.netController.Networks() - - for _, managedNetwork := range managedNetworks { - _, v6Infos := managedNetwork.Info().IpamInfo() - for _, v6Info := range v6Infos { - if v6Info.IPAMData.Pool != nil { - subnets = append(subnets, *v6Info.IPAMData.Pool) - } - } - } - - return subnets -} - -// GraphDriverName returns the name of the graph driver used by the layer.Store -func (daemon *Daemon) GraphDriverName() string { - return daemon.layerStore.DriverName() -} - -// GetUIDGIDMaps returns the current daemon's user namespace settings -// for the full uid and gid maps which will be applied to containers -// started in this instance. -func (daemon *Daemon) GetUIDGIDMaps() ([]idtools.IDMap, []idtools.IDMap) { - return daemon.uidMaps, daemon.gidMaps -} - -// GetRemappedUIDGID returns the current daemon's uid and gid values -// if user namespaces are in use for this daemon instance. If not -// this function will return "real" root values of 0, 0. -func (daemon *Daemon) GetRemappedUIDGID() (int, int) { - uid, gid, _ := idtools.GetRootUIDGID(daemon.uidMaps, daemon.gidMaps) - return uid, gid -} - -// tempDir returns the default directory to use for temporary files. -func tempDir(rootDir string, rootUID, rootGID int) (string, error) { - var tmpDir string - if tmpDir = os.Getenv("DOCKER_TMPDIR"); tmpDir == "" { - tmpDir = filepath.Join(rootDir, "tmp") - } - return tmpDir, idtools.MkdirAllAs(tmpDir, 0700, rootUID, rootGID) -} - -func (daemon *Daemon) setupInitLayer(initPath string) error { - rootUID, rootGID := daemon.GetRemappedUIDGID() - return initlayer.Setup(initPath, rootUID, rootGID) -} - -func setDefaultMtu(config *Config) { - // do nothing if the config does not have the default 0 value. - if config.Mtu != 0 { - return - } - config.Mtu = defaultNetworkMtu -} - -func (daemon *Daemon) configureVolumes(rootUID, rootGID int) (*store.VolumeStore, error) { - volumesDriver, err := local.New(daemon.configStore.Root, rootUID, rootGID) - if err != nil { - return nil, err - } - - volumedrivers.RegisterPluginGetter(daemon.PluginStore) - - if !volumedrivers.Register(volumesDriver, volumesDriver.Name()) { - return nil, fmt.Errorf("local volume driver could not be registered") - } - return store.New(daemon.configStore.Root) -} - -// IsShuttingDown tells whether the daemon is shutting down or not -func (daemon *Daemon) IsShuttingDown() bool { - return daemon.shutdown -} - -// initDiscovery initializes the discovery watcher for this daemon. -func (daemon *Daemon) initDiscovery(config *Config) error { - advertise, err := parseClusterAdvertiseSettings(config.ClusterStore, config.ClusterAdvertise) - if err != nil { - if err == errDiscoveryDisabled { - return nil - } - return err - } - - config.ClusterAdvertise = advertise - discoveryWatcher, err := initDiscovery(config.ClusterStore, config.ClusterAdvertise, config.ClusterOpts) - if err != nil { - return fmt.Errorf("discovery initialization failed (%v)", err) - } - - daemon.discoveryWatcher = discoveryWatcher - return nil -} - -// Reload reads configuration changes and modifies the -// daemon according to those changes. -// These are the settings that Reload changes: -// - Daemon labels. -// - Daemon debug log level. -// - Daemon insecure registries. -// - Daemon max concurrent downloads -// - Daemon max concurrent uploads -// - Cluster discovery (reconfigure and restart). -// - Daemon live restore -// - Daemon shutdown timeout (in seconds). -func (daemon *Daemon) Reload(config *Config) (err error) { - - daemon.configStore.reloadLock.Lock() - - attributes := daemon.platformReload(config) - - defer func() { - // we're unlocking here, because - // LogDaemonEventWithAttributes() -> SystemInfo() -> GetAllRuntimes() - // holds that lock too. - daemon.configStore.reloadLock.Unlock() - if err == nil { - daemon.LogDaemonEventWithAttributes("reload", attributes) - } - }() - - if err := daemon.reloadClusterDiscovery(config); err != nil { - return err - } - - if config.IsValueSet("labels") { - daemon.configStore.Labels = config.Labels - } - if config.IsValueSet("debug") { - daemon.configStore.Debug = config.Debug - } - if config.IsValueSet("insecure-registries") { - daemon.configStore.InsecureRegistries = config.InsecureRegistries - if err := daemon.RegistryService.LoadInsecureRegistries(config.InsecureRegistries); err != nil { - return err - } - } - if config.IsValueSet("live-restore") { - daemon.configStore.LiveRestoreEnabled = config.LiveRestoreEnabled - if err := daemon.containerdRemote.UpdateOptions(libcontainerd.WithLiveRestore(config.LiveRestoreEnabled)); err != nil { - return err - } - } - - // If no value is set for max-concurrent-downloads we assume it is the default value - // We always "reset" as the cost is lightweight and easy to maintain. - if config.IsValueSet("max-concurrent-downloads") && config.MaxConcurrentDownloads != nil { - *daemon.configStore.MaxConcurrentDownloads = *config.MaxConcurrentDownloads - } else { - maxConcurrentDownloads := defaultMaxConcurrentDownloads - daemon.configStore.MaxConcurrentDownloads = &maxConcurrentDownloads - } - logrus.Debugf("Reset Max Concurrent Downloads: %d", *daemon.configStore.MaxConcurrentDownloads) - if daemon.downloadManager != nil { - daemon.downloadManager.SetConcurrency(*daemon.configStore.MaxConcurrentDownloads) - } - - // If no value is set for max-concurrent-upload we assume it is the default value - // We always "reset" as the cost is lightweight and easy to maintain. - if config.IsValueSet("max-concurrent-uploads") && config.MaxConcurrentUploads != nil { - *daemon.configStore.MaxConcurrentUploads = *config.MaxConcurrentUploads - } else { - maxConcurrentUploads := defaultMaxConcurrentUploads - daemon.configStore.MaxConcurrentUploads = &maxConcurrentUploads - } - logrus.Debugf("Reset Max Concurrent Uploads: %d", *daemon.configStore.MaxConcurrentUploads) - if daemon.uploadManager != nil { - daemon.uploadManager.SetConcurrency(*daemon.configStore.MaxConcurrentUploads) - } - - if config.IsValueSet("shutdown-timeout") { - daemon.configStore.ShutdownTimeout = config.ShutdownTimeout - logrus.Debugf("Reset Shutdown Timeout: %d", daemon.configStore.ShutdownTimeout) - } - - // We emit daemon reload event here with updatable configurations - attributes["debug"] = fmt.Sprintf("%t", daemon.configStore.Debug) - attributes["live-restore"] = fmt.Sprintf("%t", daemon.configStore.LiveRestoreEnabled) - - if daemon.configStore.InsecureRegistries != nil { - insecureRegistries, err := json.Marshal(daemon.configStore.InsecureRegistries) - if err != nil { - return err - } - attributes["insecure-registries"] = string(insecureRegistries) - } else { - attributes["insecure-registries"] = "[]" - } - - attributes["cluster-store"] = daemon.configStore.ClusterStore - if daemon.configStore.ClusterOpts != nil { - opts, err := json.Marshal(daemon.configStore.ClusterOpts) - if err != nil { - return err - } - attributes["cluster-store-opts"] = string(opts) - } else { - attributes["cluster-store-opts"] = "{}" - } - attributes["cluster-advertise"] = daemon.configStore.ClusterAdvertise - - if daemon.configStore.Labels != nil { - labels, err := json.Marshal(daemon.configStore.Labels) - if err != nil { - return err - } - attributes["labels"] = string(labels) - } else { - attributes["labels"] = "[]" - } - - attributes["max-concurrent-downloads"] = fmt.Sprintf("%d", *daemon.configStore.MaxConcurrentDownloads) - attributes["max-concurrent-uploads"] = fmt.Sprintf("%d", *daemon.configStore.MaxConcurrentUploads) - attributes["shutdown-timeout"] = fmt.Sprintf("%d", daemon.configStore.ShutdownTimeout) - - return nil -} - -func (daemon *Daemon) reloadClusterDiscovery(config *Config) error { - var err error - newAdvertise := daemon.configStore.ClusterAdvertise - newClusterStore := daemon.configStore.ClusterStore - if config.IsValueSet("cluster-advertise") { - if config.IsValueSet("cluster-store") { - newClusterStore = config.ClusterStore - } - newAdvertise, err = parseClusterAdvertiseSettings(newClusterStore, config.ClusterAdvertise) - if err != nil && err != errDiscoveryDisabled { - return err - } - } - - if daemon.clusterProvider != nil { - if err := config.isSwarmCompatible(); err != nil { - return err - } - } - - // check discovery modifications - if !modifiedDiscoverySettings(daemon.configStore, newAdvertise, newClusterStore, config.ClusterOpts) { - return nil - } - - // enable discovery for the first time if it was not previously enabled - if daemon.discoveryWatcher == nil { - discoveryWatcher, err := initDiscovery(newClusterStore, newAdvertise, config.ClusterOpts) - if err != nil { - return fmt.Errorf("discovery initialization failed (%v)", err) - } - daemon.discoveryWatcher = discoveryWatcher - } else { - if err == errDiscoveryDisabled { - // disable discovery if it was previously enabled and it's disabled now - daemon.discoveryWatcher.Stop() - } else { - // reload discovery - if err = daemon.discoveryWatcher.Reload(config.ClusterStore, newAdvertise, config.ClusterOpts); err != nil { - return err - } - } - } - - daemon.configStore.ClusterStore = newClusterStore - daemon.configStore.ClusterOpts = config.ClusterOpts - daemon.configStore.ClusterAdvertise = newAdvertise - - if daemon.netController == nil { - return nil - } - netOptions, err := daemon.networkOptions(daemon.configStore, daemon.PluginStore, nil) - if err != nil { - logrus.WithError(err).Warnf("failed to get options with network controller") - return nil - } - err = daemon.netController.ReloadConfiguration(netOptions...) - if err != nil { - logrus.Warnf("Failed to reload configuration with network controller: %v", err) - } - - return nil -} - -func isBridgeNetworkDisabled(config *Config) bool { - return config.bridgeConfig.Iface == disableNetworkBridge -} - -func (daemon *Daemon) networkOptions(dconfig *Config, pg plugingetter.PluginGetter, activeSandboxes map[string]interface{}) ([]nwconfig.Option, error) { - options := []nwconfig.Option{} - if dconfig == nil { - return options, nil - } - - options = append(options, nwconfig.OptionExperimental(dconfig.Experimental)) - options = append(options, nwconfig.OptionDataDir(dconfig.Root)) - options = append(options, nwconfig.OptionExecRoot(dconfig.GetExecRoot())) - - dd := runconfig.DefaultDaemonNetworkMode() - dn := runconfig.DefaultDaemonNetworkMode().NetworkName() - options = append(options, nwconfig.OptionDefaultDriver(string(dd))) - options = append(options, nwconfig.OptionDefaultNetwork(dn)) - - if strings.TrimSpace(dconfig.ClusterStore) != "" { - kv := strings.Split(dconfig.ClusterStore, "://") - if len(kv) != 2 { - return nil, fmt.Errorf("kv store daemon config must be of the form KV-PROVIDER://KV-URL") - } - options = append(options, nwconfig.OptionKVProvider(kv[0])) - options = append(options, nwconfig.OptionKVProviderURL(kv[1])) - } - if len(dconfig.ClusterOpts) > 0 { - options = append(options, nwconfig.OptionKVOpts(dconfig.ClusterOpts)) - } - - if daemon.discoveryWatcher != nil { - options = append(options, nwconfig.OptionDiscoveryWatcher(daemon.discoveryWatcher)) - } - - if dconfig.ClusterAdvertise != "" { - options = append(options, nwconfig.OptionDiscoveryAddress(dconfig.ClusterAdvertise)) - } - - options = append(options, nwconfig.OptionLabels(dconfig.Labels)) - options = append(options, driverOptions(dconfig)...) - - if daemon.configStore != nil && daemon.configStore.LiveRestoreEnabled && len(activeSandboxes) != 0 { - options = append(options, nwconfig.OptionActiveSandboxes(activeSandboxes)) - } - - if pg != nil { - options = append(options, nwconfig.OptionPluginGetter(pg)) - } - - return options, nil -} - -func copyBlkioEntry(entries []*containerd.BlkioStatsEntry) []types.BlkioStatEntry { - out := make([]types.BlkioStatEntry, len(entries)) - for i, re := range entries { - out[i] = types.BlkioStatEntry{ - Major: re.Major, - Minor: re.Minor, - Op: re.Op, - Value: re.Value, - } - } - return out -} - -// GetCluster returns the cluster -func (daemon *Daemon) GetCluster() Cluster { - return daemon.cluster -} - -// SetCluster sets the cluster -func (daemon *Daemon) SetCluster(cluster Cluster) { - daemon.cluster = cluster -} - -func (daemon *Daemon) pluginShutdown() { - manager := daemon.pluginManager - // Check for a valid manager object. In error conditions, daemon init can fail - // and shutdown called, before plugin manager is initialized. - if manager != nil { - manager.Shutdown() - } -} - -// PluginManager returns current pluginManager associated with the daemon -func (daemon *Daemon) PluginManager() *plugin.Manager { // set up before daemon to avoid this method - return daemon.pluginManager -} - -// PluginGetter returns current pluginStore associated with the daemon -func (daemon *Daemon) PluginGetter() *plugin.Store { - return daemon.PluginStore -} - -// CreateDaemonRoot creates the root for the daemon -func CreateDaemonRoot(config *Config) error { - // get the canonical path to the Docker root directory - var realRoot string - if _, err := os.Stat(config.Root); err != nil && os.IsNotExist(err) { - realRoot = config.Root - } else { - realRoot, err = fileutils.ReadSymlinkedDirectory(config.Root) - if err != nil { - return fmt.Errorf("Unable to get the full path to root (%s): %s", config.Root, err) - } - } - - uidMaps, gidMaps, err := setupRemappedRoot(config) - if err != nil { - return err - } - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) - if err != nil { - return err - } - - if err := setupDaemonRoot(config, realRoot, rootUID, rootGID); err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/daemon_experimental.go b/vendor/github.com/docker/docker/daemon/daemon_experimental.go deleted file mode 100644 index fb0251d..0000000 --- a/vendor/github.com/docker/docker/daemon/daemon_experimental.go +++ /dev/null @@ -1,7 +0,0 @@ -package daemon - -import "github.com/docker/docker/api/types/container" - -func (daemon *Daemon) verifyExperimentalContainerSettings(hostConfig *container.HostConfig, config *container.Config) ([]string, error) { - return nil, nil -} diff --git a/vendor/github.com/docker/docker/daemon/daemon_linux.go b/vendor/github.com/docker/docker/daemon/daemon_linux.go deleted file mode 100644 index 9bdf6e2..0000000 --- a/vendor/github.com/docker/docker/daemon/daemon_linux.go +++ /dev/null @@ -1,80 +0,0 @@ -package daemon - -import ( - "bufio" - "fmt" - "io" - "os" - "regexp" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/mount" -) - -func (daemon *Daemon) cleanupMountsByID(id string) error { - logrus.Debugf("Cleaning up old mountid %s: start.", id) - f, err := os.Open("/proc/self/mountinfo") - if err != nil { - return err - } - defer f.Close() - - return daemon.cleanupMountsFromReaderByID(f, id, mount.Unmount) -} - -func (daemon *Daemon) cleanupMountsFromReaderByID(reader io.Reader, id string, unmount func(target string) error) error { - if daemon.root == "" { - return nil - } - var errors []string - - regexps := getCleanPatterns(id) - sc := bufio.NewScanner(reader) - for sc.Scan() { - if fields := strings.Fields(sc.Text()); len(fields) >= 4 { - if mnt := fields[4]; strings.HasPrefix(mnt, daemon.root) { - for _, p := range regexps { - if p.MatchString(mnt) { - if err := unmount(mnt); err != nil { - logrus.Error(err) - errors = append(errors, err.Error()) - } - } - } - } - } - } - - if err := sc.Err(); err != nil { - return err - } - - if len(errors) > 0 { - return fmt.Errorf("Error cleaning up mounts:\n%v", strings.Join(errors, "\n")) - } - - logrus.Debugf("Cleaning up old mountid %v: done.", id) - return nil -} - -// cleanupMounts umounts shm/mqueue mounts for old containers -func (daemon *Daemon) cleanupMounts() error { - return daemon.cleanupMountsByID("") -} - -func getCleanPatterns(id string) (regexps []*regexp.Regexp) { - var patterns []string - if id == "" { - id = "[0-9a-f]{64}" - patterns = append(patterns, "containers/"+id+"/shm") - } - patterns = append(patterns, "aufs/mnt/"+id+"$", "overlay/"+id+"/merged$", "zfs/graph/"+id+"$") - for _, p := range patterns { - r, err := regexp.Compile(p) - if err == nil { - regexps = append(regexps, r) - } - } - return -} diff --git a/vendor/github.com/docker/docker/daemon/daemon_linux_test.go b/vendor/github.com/docker/docker/daemon/daemon_linux_test.go deleted file mode 100644 index c40b13b..0000000 --- a/vendor/github.com/docker/docker/daemon/daemon_linux_test.go +++ /dev/null @@ -1,104 +0,0 @@ -// +build linux - -package daemon - -import ( - "strings" - "testing" -) - -const mountsFixture = `142 78 0:38 / / rw,relatime - aufs none rw,si=573b861da0b3a05b,dio -143 142 0:60 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw -144 142 0:67 / /dev rw,nosuid - tmpfs tmpfs rw,mode=755 -145 144 0:78 / /dev/pts rw,nosuid,noexec,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=666 -146 144 0:49 / /dev/mqueue rw,nosuid,nodev,noexec,relatime - mqueue mqueue rw -147 142 0:84 / /sys rw,nosuid,nodev,noexec,relatime - sysfs sysfs rw -148 147 0:86 / /sys/fs/cgroup rw,nosuid,nodev,noexec,relatime - tmpfs tmpfs rw,mode=755 -149 148 0:22 /docker/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,cpuset -150 148 0:25 /docker/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a /sys/fs/cgroup/cpu rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,cpu -151 148 0:27 /docker/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a /sys/fs/cgroup/cpuacct rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,cpuacct -152 148 0:28 /docker/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,memory -153 148 0:29 /docker/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,devices -154 148 0:30 /docker/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,freezer -155 148 0:31 /docker/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,blkio -156 148 0:32 /docker/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,perf_event -157 148 0:33 /docker/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a /sys/fs/cgroup/hugetlb rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,hugetlb -158 148 0:35 /docker/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime - cgroup systemd rw,name=systemd -159 142 8:4 /home/mlaventure/gopath /home/mlaventure/gopath rw,relatime - ext4 /dev/disk/by-uuid/d99e196c-1fc4-4b4f-bab9-9962b2b34e99 rw,errors=remount-ro,data=ordered -160 142 8:4 /var/lib/docker/volumes/9a428b651ee4c538130143cad8d87f603a4bf31b928afe7ff3ecd65480692b35/_data /var/lib/docker rw,relatime - ext4 /dev/disk/by-uuid/d99e196c-1fc4-4b4f-bab9-9962b2b34e99 rw,errors=remount-ro,data=ordered -164 142 8:4 /home/mlaventure/gopath/src/github.com/docker/docker /go/src/github.com/docker/docker rw,relatime - ext4 /dev/disk/by-uuid/d99e196c-1fc4-4b4f-bab9-9962b2b34e99 rw,errors=remount-ro,data=ordered -165 142 8:4 /var/lib/docker/containers/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a/resolv.conf /etc/resolv.conf rw,relatime - ext4 /dev/disk/by-uuid/d99e196c-1fc4-4b4f-bab9-9962b2b34e99 rw,errors=remount-ro,data=ordered -166 142 8:4 /var/lib/docker/containers/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a/hostname /etc/hostname rw,relatime - ext4 /dev/disk/by-uuid/d99e196c-1fc4-4b4f-bab9-9962b2b34e99 rw,errors=remount-ro,data=ordered -167 142 8:4 /var/lib/docker/containers/5425782a95e643181d8a485a2bab3c0bb21f51d7dfc03511f0e6fbf3f3aa356a/hosts /etc/hosts rw,relatime - ext4 /dev/disk/by-uuid/d99e196c-1fc4-4b4f-bab9-9962b2b34e99 rw,errors=remount-ro,data=ordered -168 144 0:39 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k -169 144 0:12 /14 /dev/console rw,nosuid,noexec,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=000 -83 147 0:10 / /sys/kernel/security rw,relatime - securityfs none rw -89 142 0:87 / /tmp rw,relatime - tmpfs none rw -97 142 0:60 / /run/docker/netns/default rw,nosuid,nodev,noexec,relatime - proc proc rw -100 160 8:4 /var/lib/docker/volumes/9a428b651ee4c538130143cad8d87f603a4bf31b928afe7ff3ecd65480692b35/_data/aufs /var/lib/docker/aufs rw,relatime - ext4 /dev/disk/by-uuid/d99e196c-1fc4-4b4f-bab9-9962b2b34e99 rw,errors=remount-ro,data=ordered -115 100 0:102 / /var/lib/docker/aufs/mnt/0ecda1c63e5b58b3d89ff380bf646c95cc980252cf0b52466d43619aec7c8432 rw,relatime - aufs none rw,si=573b861dbc01905b,dio -116 160 0:107 / /var/lib/docker/containers/d045dc441d2e2e1d5b3e328d47e5943811a40819fb47497c5f5a5df2d6d13c37/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k -118 142 0:102 / /run/docker/libcontainerd/d045dc441d2e2e1d5b3e328d47e5943811a40819fb47497c5f5a5df2d6d13c37/rootfs rw,relatime - aufs none rw,si=573b861dbc01905b,dio -242 142 0:60 / /run/docker/netns/c3664df2a0f7 rw,nosuid,nodev,noexec,relatime - proc proc rw -120 100 0:122 / /var/lib/docker/aufs/mnt/03ca4b49e71f1e49a41108829f4d5c70ac95934526e2af8984a1f65f1de0715d rw,relatime - aufs none rw,si=573b861eb147805b,dio -171 142 0:122 / /run/docker/libcontainerd/e406ff6f3e18516d50e03dbca4de54767a69a403a6f7ec1edc2762812824521e/rootfs rw,relatime - aufs none rw,si=573b861eb147805b,dio -310 142 0:60 / /run/docker/netns/71a18572176b rw,nosuid,nodev,noexec,relatime - proc proc rw -` - -func TestCleanupMounts(t *testing.T) { - d := &Daemon{ - root: "/var/lib/docker/", - } - - expected := "/var/lib/docker/containers/d045dc441d2e2e1d5b3e328d47e5943811a40819fb47497c5f5a5df2d6d13c37/shm" - var unmounted int - unmount := func(target string) error { - if target == expected { - unmounted++ - } - return nil - } - - d.cleanupMountsFromReaderByID(strings.NewReader(mountsFixture), "", unmount) - - if unmounted != 1 { - t.Fatalf("Expected to unmount the shm (and the shm only)") - } -} - -func TestCleanupMountsByID(t *testing.T) { - d := &Daemon{ - root: "/var/lib/docker/", - } - - expected := "/var/lib/docker/aufs/mnt/03ca4b49e71f1e49a41108829f4d5c70ac95934526e2af8984a1f65f1de0715d" - var unmounted int - unmount := func(target string) error { - if target == expected { - unmounted++ - } - return nil - } - - d.cleanupMountsFromReaderByID(strings.NewReader(mountsFixture), "03ca4b49e71f1e49a41108829f4d5c70ac95934526e2af8984a1f65f1de0715d", unmount) - - if unmounted != 1 { - t.Fatalf("Expected to unmount the auf root (and that only)") - } -} - -func TestNotCleanupMounts(t *testing.T) { - d := &Daemon{ - repository: "", - } - var unmounted bool - unmount := func(target string) error { - unmounted = true - return nil - } - mountInfo := `234 232 0:59 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k` - d.cleanupMountsFromReaderByID(strings.NewReader(mountInfo), "", unmount) - if unmounted { - t.Fatalf("Expected not to clean up /dev/shm") - } -} diff --git a/vendor/github.com/docker/docker/daemon/daemon_solaris.go b/vendor/github.com/docker/docker/daemon/daemon_solaris.go deleted file mode 100644 index 2b4d8d0..0000000 --- a/vendor/github.com/docker/docker/daemon/daemon_solaris.go +++ /dev/null @@ -1,523 +0,0 @@ -// +build solaris,cgo - -package daemon - -import ( - "fmt" - "net" - "strconv" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/parsers/kernel" - "github.com/docker/docker/pkg/sysinfo" - "github.com/docker/docker/reference" - "github.com/docker/libnetwork" - nwconfig "github.com/docker/libnetwork/config" - "github.com/docker/libnetwork/drivers/solaris/bridge" - "github.com/docker/libnetwork/netlabel" - "github.com/docker/libnetwork/netutils" - lntypes "github.com/docker/libnetwork/types" - "github.com/opencontainers/runc/libcontainer/label" - "github.com/opencontainers/runtime-spec/specs-go" - "github.com/pkg/errors" -) - -//#include -import "C" - -const ( - defaultVirtualSwitch = "Virtual Switch" - platformSupported = true - solarisMinCPUShares = 1 - solarisMaxCPUShares = 65535 -) - -func getMemoryResources(config containertypes.Resources) specs.CappedMemory { - memory := specs.CappedMemory{} - - if config.Memory > 0 { - memory.Physical = strconv.FormatInt(config.Memory, 10) - } - - if config.MemorySwap != 0 { - memory.Swap = strconv.FormatInt(config.MemorySwap, 10) - } - - return memory -} - -func getCPUResources(config containertypes.Resources) specs.CappedCPU { - cpu := specs.CappedCPU{} - - if config.CpusetCpus != "" { - cpu.Ncpus = config.CpusetCpus - } - - return cpu -} - -func (daemon *Daemon) cleanupMountsByID(id string) error { - return nil -} - -func parseSecurityOpt(container *container.Container, config *containertypes.HostConfig) error { - //Since config.SecurityOpt is specifically defined as a "List of string values to - //customize labels for MLs systems, such as SELinux" - //until we figure out how to map to Trusted Extensions - //this is being disabled for now on Solaris - var ( - labelOpts []string - err error - ) - - if len(config.SecurityOpt) > 0 { - return errors.New("Security options are not supported on Solaris") - } - - container.ProcessLabel, container.MountLabel, err = label.InitLabels(labelOpts) - return err -} - -func setupRemappedRoot(config *Config) ([]idtools.IDMap, []idtools.IDMap, error) { - return nil, nil, nil -} - -func setupDaemonRoot(config *Config, rootDir string, rootUID, rootGID int) error { - return nil -} - -func (daemon *Daemon) getLayerInit() func(string) error { - return nil -} - -func checkKernel() error { - // solaris can rely upon checkSystem() below, we don't skew kernel versions - return nil -} - -func (daemon *Daemon) getCgroupDriver() string { - return "" -} - -func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConfig, adjustCPUShares bool) error { - if hostConfig.CPUShares < 0 { - logrus.Warnf("Changing requested CPUShares of %d to minimum allowed of %d", hostConfig.CPUShares, solarisMinCPUShares) - hostConfig.CPUShares = solarisMinCPUShares - } else if hostConfig.CPUShares > solarisMaxCPUShares { - logrus.Warnf("Changing requested CPUShares of %d to maximum allowed of %d", hostConfig.CPUShares, solarisMaxCPUShares) - hostConfig.CPUShares = solarisMaxCPUShares - } - - if hostConfig.Memory > 0 && hostConfig.MemorySwap == 0 { - // By default, MemorySwap is set to twice the size of Memory. - hostConfig.MemorySwap = hostConfig.Memory * 2 - } - - if hostConfig.ShmSize != 0 { - hostConfig.ShmSize = container.DefaultSHMSize - } - if hostConfig.OomKillDisable == nil { - defaultOomKillDisable := false - hostConfig.OomKillDisable = &defaultOomKillDisable - } - - return nil -} - -// UsingSystemd returns true if cli option includes native.cgroupdriver=systemd -func UsingSystemd(config *Config) bool { - return false -} - -// verifyPlatformContainerSettings performs platform-specific validation of the -// hostconfig and config structures. -func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) { - warnings := []string{} - sysInfo := sysinfo.New(true) - // NOTE: We do not enforce a minimum value for swap limits for zones on Solaris and - // therefore we will not do that for Docker container either. - if hostConfig.Memory > 0 && !sysInfo.MemoryLimit { - warnings = append(warnings, "Your kernel does not support memory limit capabilities. Limitation discarded.") - logrus.Warnf("Your kernel does not support memory limit capabilities. Limitation discarded.") - hostConfig.Memory = 0 - hostConfig.MemorySwap = -1 - } - if hostConfig.Memory > 0 && hostConfig.MemorySwap != -1 && !sysInfo.SwapLimit { - warnings = append(warnings, "Your kernel does not support swap limit capabilities, memory limited without swap.") - logrus.Warnf("Your kernel does not support swap limit capabilities, memory limited without swap.") - hostConfig.MemorySwap = -1 - } - if hostConfig.Memory > 0 && hostConfig.MemorySwap > 0 && hostConfig.MemorySwap < hostConfig.Memory { - return warnings, fmt.Errorf("Minimum memoryswap limit should be larger than memory limit, see usage.") - } - // Solaris NOTE: We allow and encourage setting the swap without setting the memory limit. - - if hostConfig.MemorySwappiness != nil && *hostConfig.MemorySwappiness != -1 && !sysInfo.MemorySwappiness { - warnings = append(warnings, "Your kernel does not support memory swappiness capabilities, memory swappiness discarded.") - logrus.Warnf("Your kernel does not support memory swappiness capabilities, memory swappiness discarded.") - hostConfig.MemorySwappiness = nil - } - if hostConfig.MemoryReservation > 0 && !sysInfo.MemoryReservation { - warnings = append(warnings, "Your kernel does not support memory soft limit capabilities. Limitation discarded.") - logrus.Warnf("Your kernel does not support memory soft limit capabilities. Limitation discarded.") - hostConfig.MemoryReservation = 0 - } - if hostConfig.Memory > 0 && hostConfig.MemoryReservation > 0 && hostConfig.Memory < hostConfig.MemoryReservation { - return warnings, fmt.Errorf("Minimum memory limit should be larger than memory reservation limit, see usage.") - } - if hostConfig.KernelMemory > 0 && !sysInfo.KernelMemory { - warnings = append(warnings, "Your kernel does not support kernel memory limit capabilities. Limitation discarded.") - logrus.Warnf("Your kernel does not support kernel memory limit capabilities. Limitation discarded.") - hostConfig.KernelMemory = 0 - } - if hostConfig.CPUShares != 0 && !sysInfo.CPUShares { - warnings = append(warnings, "Your kernel does not support CPU shares. Shares discarded.") - logrus.Warnf("Your kernel does not support CPU shares. Shares discarded.") - hostConfig.CPUShares = 0 - } - if hostConfig.CPUShares < 0 { - warnings = append(warnings, "Invalid CPUShares value. Must be positive. Discarding.") - logrus.Warnf("Invalid CPUShares value. Must be positive. Discarding.") - hostConfig.CPUQuota = 0 - } - if hostConfig.CPUShares > 0 && !sysinfo.IsCPUSharesAvailable() { - warnings = append(warnings, "Global zone default scheduling class not FSS. Discarding shares.") - logrus.Warnf("Global zone default scheduling class not FSS. Discarding shares.") - hostConfig.CPUShares = 0 - } - - // Solaris NOTE: Linux does not do negative checking for CPUShares and Quota here. But it makes sense to. - if hostConfig.CPUPeriod > 0 && !sysInfo.CPUCfsPeriod { - warnings = append(warnings, "Your kernel does not support CPU cfs period. Period discarded.") - logrus.Warnf("Your kernel does not support CPU cfs period. Period discarded.") - if hostConfig.CPUQuota > 0 { - warnings = append(warnings, "Quota will be applied on default period, not period specified.") - logrus.Warnf("Quota will be applied on default period, not period specified.") - } - hostConfig.CPUPeriod = 0 - } - if hostConfig.CPUQuota != 0 && !sysInfo.CPUCfsQuota { - warnings = append(warnings, "Your kernel does not support CPU cfs quota. Quota discarded.") - logrus.Warnf("Your kernel does not support CPU cfs quota. Quota discarded.") - hostConfig.CPUQuota = 0 - } - if hostConfig.CPUQuota < 0 { - warnings = append(warnings, "Invalid CPUQuota value. Must be positive. Discarding.") - logrus.Warnf("Invalid CPUQuota value. Must be positive. Discarding.") - hostConfig.CPUQuota = 0 - } - if (hostConfig.CpusetCpus != "" || hostConfig.CpusetMems != "") && !sysInfo.Cpuset { - warnings = append(warnings, "Your kernel does not support cpuset. Cpuset discarded.") - logrus.Warnf("Your kernel does not support cpuset. Cpuset discarded.") - hostConfig.CpusetCpus = "" - hostConfig.CpusetMems = "" - } - cpusAvailable, err := sysInfo.IsCpusetCpusAvailable(hostConfig.CpusetCpus) - if err != nil { - return warnings, fmt.Errorf("Invalid value %s for cpuset cpus.", hostConfig.CpusetCpus) - } - if !cpusAvailable { - return warnings, fmt.Errorf("Requested CPUs are not available - requested %s, available: %s.", hostConfig.CpusetCpus, sysInfo.Cpus) - } - memsAvailable, err := sysInfo.IsCpusetMemsAvailable(hostConfig.CpusetMems) - if err != nil { - return warnings, fmt.Errorf("Invalid value %s for cpuset mems.", hostConfig.CpusetMems) - } - if !memsAvailable { - return warnings, fmt.Errorf("Requested memory nodes are not available - requested %s, available: %s.", hostConfig.CpusetMems, sysInfo.Mems) - } - if hostConfig.BlkioWeight > 0 && !sysInfo.BlkioWeight { - warnings = append(warnings, "Your kernel does not support Block I/O weight. Weight discarded.") - logrus.Warnf("Your kernel does not support Block I/O weight. Weight discarded.") - hostConfig.BlkioWeight = 0 - } - if hostConfig.OomKillDisable != nil && !sysInfo.OomKillDisable { - *hostConfig.OomKillDisable = false - // Don't warn; this is the default setting but only applicable to Linux - } - - if sysInfo.IPv4ForwardingDisabled { - warnings = append(warnings, "IPv4 forwarding is disabled. Networking will not work.") - logrus.Warnf("IPv4 forwarding is disabled. Networking will not work") - } - - // Solaris NOTE: We do not allow setting Linux specific options, so check and warn for all of them. - - if hostConfig.CapAdd != nil || hostConfig.CapDrop != nil { - warnings = append(warnings, "Adding or dropping kernel capabilities unsupported on Solaris.Discarding capabilities lists.") - logrus.Warnf("Adding or dropping kernel capabilities unsupported on Solaris.Discarding capabilities lists.") - hostConfig.CapAdd = nil - hostConfig.CapDrop = nil - } - - if hostConfig.GroupAdd != nil { - warnings = append(warnings, "Additional groups unsupported on Solaris.Discarding groups lists.") - logrus.Warnf("Additional groups unsupported on Solaris.Discarding groups lists.") - hostConfig.GroupAdd = nil - } - - if hostConfig.IpcMode != "" { - warnings = append(warnings, "IPC namespace assignment unsupported on Solaris.Discarding IPC setting.") - logrus.Warnf("IPC namespace assignment unsupported on Solaris.Discarding IPC setting.") - hostConfig.IpcMode = "" - } - - if hostConfig.PidMode != "" { - warnings = append(warnings, "PID namespace setting unsupported on Solaris. Running container in host PID namespace.") - logrus.Warnf("PID namespace setting unsupported on Solaris. Running container in host PID namespace.") - hostConfig.PidMode = "" - } - - if hostConfig.Privileged { - warnings = append(warnings, "Privileged mode unsupported on Solaris. Discarding privileged mode setting.") - logrus.Warnf("Privileged mode unsupported on Solaris. Discarding privileged mode setting.") - hostConfig.Privileged = false - } - - if hostConfig.UTSMode != "" { - warnings = append(warnings, "UTS namespace assignment unsupported on Solaris.Discarding UTS setting.") - logrus.Warnf("UTS namespace assignment unsupported on Solaris.Discarding UTS setting.") - hostConfig.UTSMode = "" - } - - if hostConfig.CgroupParent != "" { - warnings = append(warnings, "Specifying Cgroup parent unsupported on Solaris. Discarding cgroup parent setting.") - logrus.Warnf("Specifying Cgroup parent unsupported on Solaris. Discarding cgroup parent setting.") - hostConfig.CgroupParent = "" - } - - if hostConfig.Ulimits != nil { - warnings = append(warnings, "Specifying ulimits unsupported on Solaris. Discarding ulimits setting.") - logrus.Warnf("Specifying ulimits unsupported on Solaris. Discarding ulimits setting.") - hostConfig.Ulimits = nil - } - - return warnings, nil -} - -// platformReload update configuration with platform specific options -func (daemon *Daemon) platformReload(config *Config) map[string]string { - return map[string]string{} -} - -// verifyDaemonSettings performs validation of daemon config struct -func verifyDaemonSettings(config *Config) error { - - if config.DefaultRuntime == "" { - config.DefaultRuntime = stockRuntimeName - } - if config.Runtimes == nil { - config.Runtimes = make(map[string]types.Runtime) - } - stockRuntimeOpts := []string{} - config.Runtimes[stockRuntimeName] = types.Runtime{Path: DefaultRuntimeBinary, Args: stockRuntimeOpts} - - // checkSystem validates platform-specific requirements - return nil -} - -func checkSystem() error { - // check OS version for compatibility, ensure running in global zone - var err error - var id C.zoneid_t - - if id, err = C.getzoneid(); err != nil { - return fmt.Errorf("Exiting. Error getting zone id: %+v", err) - } - if int(id) != 0 { - return fmt.Errorf("Exiting because the Docker daemon is not running in the global zone") - } - - v, err := kernel.GetKernelVersion() - if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: 5, Major: 12, Minor: 0}) < 0 { - return fmt.Errorf("Your Solaris kernel version: %s doesn't support Docker. Please upgrade to 5.12.0", v.String()) - } - return err -} - -// configureMaxThreads sets the Go runtime max threads threshold -// which is 90% of the kernel setting from /proc/sys/kernel/threads-max -func configureMaxThreads(config *Config) error { - return nil -} - -// configureKernelSecuritySupport configures and validate security support for the kernel -func configureKernelSecuritySupport(config *Config, driverName string) error { - return nil -} - -func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[string]interface{}) (libnetwork.NetworkController, error) { - netOptions, err := daemon.networkOptions(config, daemon.PluginStore, activeSandboxes) - if err != nil { - return nil, err - } - - controller, err := libnetwork.New(netOptions...) - if err != nil { - return nil, fmt.Errorf("error obtaining controller instance: %v", err) - } - - // Initialize default network on "null" - if _, err := controller.NewNetwork("null", "none", "", libnetwork.NetworkOptionPersist(false)); err != nil { - return nil, fmt.Errorf("Error creating default 'null' network: %v", err) - } - - if !config.DisableBridge { - // Initialize default driver "bridge" - if err := initBridgeDriver(controller, config); err != nil { - return nil, err - } - } - - return controller, nil -} - -func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error { - if n, err := controller.NetworkByName("bridge"); err == nil { - if err = n.Delete(); err != nil { - return fmt.Errorf("could not delete the default bridge network: %v", err) - } - } - - bridgeName := bridge.DefaultBridgeName - if config.bridgeConfig.Iface != "" { - bridgeName = config.bridgeConfig.Iface - } - netOption := map[string]string{ - bridge.BridgeName: bridgeName, - bridge.DefaultBridge: strconv.FormatBool(true), - netlabel.DriverMTU: strconv.Itoa(config.Mtu), - bridge.EnableICC: strconv.FormatBool(config.bridgeConfig.InterContainerCommunication), - } - - // --ip processing - if config.bridgeConfig.DefaultIP != nil { - netOption[bridge.DefaultBindingIP] = config.bridgeConfig.DefaultIP.String() - } - - var ipamV4Conf *libnetwork.IpamConf - - ipamV4Conf = &libnetwork.IpamConf{AuxAddresses: make(map[string]string)} - - nwList, _, err := netutils.ElectInterfaceAddresses(bridgeName) - if err != nil { - return errors.Wrap(err, "list bridge addresses failed") - } - - nw := nwList[0] - if len(nwList) > 1 && config.bridgeConfig.FixedCIDR != "" { - _, fCIDR, err := net.ParseCIDR(config.bridgeConfig.FixedCIDR) - if err != nil { - return errors.Wrap(err, "parse CIDR failed") - } - // Iterate through in case there are multiple addresses for the bridge - for _, entry := range nwList { - if fCIDR.Contains(entry.IP) { - nw = entry - break - } - } - } - - ipamV4Conf.PreferredPool = lntypes.GetIPNetCanonical(nw).String() - hip, _ := lntypes.GetHostPartIP(nw.IP, nw.Mask) - if hip.IsGlobalUnicast() { - ipamV4Conf.Gateway = nw.IP.String() - } - - if config.bridgeConfig.IP != "" { - ipamV4Conf.PreferredPool = config.bridgeConfig.IP - ip, _, err := net.ParseCIDR(config.bridgeConfig.IP) - if err != nil { - return err - } - ipamV4Conf.Gateway = ip.String() - } else if bridgeName == bridge.DefaultBridgeName && ipamV4Conf.PreferredPool != "" { - logrus.Infof("Default bridge (%s) is assigned with an IP address %s. Daemon option --bip can be used to set a preferred IP address", bridgeName, ipamV4Conf.PreferredPool) - } - - if config.bridgeConfig.FixedCIDR != "" { - _, fCIDR, err := net.ParseCIDR(config.bridgeConfig.FixedCIDR) - if err != nil { - return err - } - - ipamV4Conf.SubPool = fCIDR.String() - } - - if config.bridgeConfig.DefaultGatewayIPv4 != nil { - ipamV4Conf.AuxAddresses["DefaultGatewayIPv4"] = config.bridgeConfig.DefaultGatewayIPv4.String() - } - - v4Conf := []*libnetwork.IpamConf{ipamV4Conf} - v6Conf := []*libnetwork.IpamConf{} - - // Initialize default network on "bridge" with the same name - _, err = controller.NewNetwork("bridge", "bridge", "", - libnetwork.NetworkOptionDriverOpts(netOption), - libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil), - libnetwork.NetworkOptionDeferIPv6Alloc(false)) - if err != nil { - return fmt.Errorf("Error creating default 'bridge' network: %v", err) - } - return nil -} - -// registerLinks sets up links between containers and writes the -// configuration out for persistence. -func (daemon *Daemon) registerLinks(container *container.Container, hostConfig *containertypes.HostConfig) error { - return nil -} - -func (daemon *Daemon) cleanupMounts() error { - return nil -} - -// conditionalMountOnStart is a platform specific helper function during the -// container start to call mount. -func (daemon *Daemon) conditionalMountOnStart(container *container.Container) error { - return daemon.Mount(container) -} - -// conditionalUnmountOnCleanup is a platform specific helper function called -// during the cleanup of a container to unmount. -func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) error { - return daemon.Unmount(container) -} - -func restoreCustomImage(is image.Store, ls layer.Store, rs reference.Store) error { - // Solaris has no custom images to register - return nil -} - -func driverOptions(config *Config) []nwconfig.Option { - return []nwconfig.Option{} -} - -func (daemon *Daemon) stats(c *container.Container) (*types.StatsJSON, error) { - return nil, nil -} - -// setDefaultIsolation determine the default isolation mode for the -// daemon to run in. This is only applicable on Windows -func (daemon *Daemon) setDefaultIsolation() error { - return nil -} - -func rootFSToAPIType(rootfs *image.RootFS) types.RootFS { - return types.RootFS{} -} - -func setupDaemonProcess(config *Config) error { - return nil -} - -func (daemon *Daemon) setupSeccompProfile() error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/daemon_test.go b/vendor/github.com/docker/docker/daemon/daemon_test.go deleted file mode 100644 index 00817bd..0000000 --- a/vendor/github.com/docker/docker/daemon/daemon_test.go +++ /dev/null @@ -1,627 +0,0 @@ -// +build !solaris - -package daemon - -import ( - "io/ioutil" - "os" - "path/filepath" - "reflect" - "testing" - "time" - - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/discovery" - _ "github.com/docker/docker/pkg/discovery/memory" - "github.com/docker/docker/pkg/registrar" - "github.com/docker/docker/pkg/truncindex" - "github.com/docker/docker/registry" - "github.com/docker/docker/volume" - volumedrivers "github.com/docker/docker/volume/drivers" - "github.com/docker/docker/volume/local" - "github.com/docker/docker/volume/store" - "github.com/docker/go-connections/nat" -) - -// -// https://github.com/docker/docker/issues/8069 -// - -func TestGetContainer(t *testing.T) { - c1 := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "5a4ff6a163ad4533d22d69a2b8960bf7fafdcba06e72d2febdba229008b0bf57", - Name: "tender_bardeen", - }, - } - - c2 := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "3cdbd1aa394fd68559fd1441d6eff2ab7c1e6363582c82febfaa8045df3bd8de", - Name: "drunk_hawking", - }, - } - - c3 := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "3cdbd1aa394fd68559fd1441d6eff2abfafdcba06e72d2febdba229008b0bf57", - Name: "3cdbd1aa", - }, - } - - c4 := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "75fb0b800922abdbef2d27e60abcdfaf7fb0698b2a96d22d3354da361a6ff4a5", - Name: "5a4ff6a163ad4533d22d69a2b8960bf7fafdcba06e72d2febdba229008b0bf57", - }, - } - - c5 := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "d22d69a2b8960bf7fafdcba06e72d2febdba960bf7fafdcba06e72d2f9008b060b", - Name: "d22d69a2b896", - }, - } - - store := container.NewMemoryStore() - store.Add(c1.ID, c1) - store.Add(c2.ID, c2) - store.Add(c3.ID, c3) - store.Add(c4.ID, c4) - store.Add(c5.ID, c5) - - index := truncindex.NewTruncIndex([]string{}) - index.Add(c1.ID) - index.Add(c2.ID) - index.Add(c3.ID) - index.Add(c4.ID) - index.Add(c5.ID) - - daemon := &Daemon{ - containers: store, - idIndex: index, - nameIndex: registrar.NewRegistrar(), - } - - daemon.reserveName(c1.ID, c1.Name) - daemon.reserveName(c2.ID, c2.Name) - daemon.reserveName(c3.ID, c3.Name) - daemon.reserveName(c4.ID, c4.Name) - daemon.reserveName(c5.ID, c5.Name) - - if container, _ := daemon.GetContainer("3cdbd1aa394fd68559fd1441d6eff2ab7c1e6363582c82febfaa8045df3bd8de"); container != c2 { - t.Fatal("Should explicitly match full container IDs") - } - - if container, _ := daemon.GetContainer("75fb0b8009"); container != c4 { - t.Fatal("Should match a partial ID") - } - - if container, _ := daemon.GetContainer("drunk_hawking"); container != c2 { - t.Fatal("Should match a full name") - } - - // c3.Name is a partial match for both c3.ID and c2.ID - if c, _ := daemon.GetContainer("3cdbd1aa"); c != c3 { - t.Fatal("Should match a full name even though it collides with another container's ID") - } - - if container, _ := daemon.GetContainer("d22d69a2b896"); container != c5 { - t.Fatal("Should match a container where the provided prefix is an exact match to the its name, and is also a prefix for its ID") - } - - if _, err := daemon.GetContainer("3cdbd1"); err == nil { - t.Fatal("Should return an error when provided a prefix that partially matches multiple container ID's") - } - - if _, err := daemon.GetContainer("nothing"); err == nil { - t.Fatal("Should return an error when provided a prefix that is neither a name or a partial match to an ID") - } -} - -func initDaemonWithVolumeStore(tmp string) (*Daemon, error) { - var err error - daemon := &Daemon{ - repository: tmp, - root: tmp, - } - daemon.volumes, err = store.New(tmp) - if err != nil { - return nil, err - } - - volumesDriver, err := local.New(tmp, 0, 0) - if err != nil { - return nil, err - } - volumedrivers.Register(volumesDriver, volumesDriver.Name()) - - return daemon, nil -} - -func TestValidContainerNames(t *testing.T) { - invalidNames := []string{"-rm", "&sdfsfd", "safd%sd"} - validNames := []string{"word-word", "word_word", "1weoid"} - - for _, name := range invalidNames { - if validContainerNamePattern.MatchString(name) { - t.Fatalf("%q is not a valid container name and was returned as valid.", name) - } - } - - for _, name := range validNames { - if !validContainerNamePattern.MatchString(name) { - t.Fatalf("%q is a valid container name and was returned as invalid.", name) - } - } -} - -func TestContainerInitDNS(t *testing.T) { - tmp, err := ioutil.TempDir("", "docker-container-test-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - - containerID := "d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e" - containerPath := filepath.Join(tmp, containerID) - if err := os.MkdirAll(containerPath, 0755); err != nil { - t.Fatal(err) - } - - config := `{"State":{"Running":true,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":2464,"ExitCode":0, -"Error":"","StartedAt":"2015-05-26T16:48:53.869308965Z","FinishedAt":"0001-01-01T00:00:00Z"}, -"ID":"d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e","Created":"2015-05-26T16:48:53.7987917Z","Path":"top", -"Args":[],"Config":{"Hostname":"d59df5276e7b","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"Cpuset":"", -"AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"PortSpecs":null,"ExposedPorts":null,"Tty":true,"OpenStdin":true, -"StdinOnce":false,"Env":null,"Cmd":["top"],"Image":"ubuntu:latest","Volumes":null,"WorkingDir":"","Entrypoint":null, -"NetworkDisabled":false,"MacAddress":"","OnBuild":null,"Labels":{}},"Image":"07f8e8c5e66084bef8f848877857537ffe1c47edd01a93af27e7161672ad0e95", -"NetworkSettings":{"IPAddress":"172.17.0.1","IPPrefixLen":16,"MacAddress":"02:42:ac:11:00:01","LinkLocalIPv6Address":"fe80::42:acff:fe11:1", -"LinkLocalIPv6PrefixLen":64,"GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"Gateway":"172.17.42.1","IPv6Gateway":"","Bridge":"docker0","Ports":{}}, -"ResolvConfPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/resolv.conf", -"HostnamePath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/hostname", -"HostsPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/hosts", -"LogPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e-json.log", -"Name":"/ubuntu","Driver":"aufs","MountLabel":"","ProcessLabel":"","AppArmorProfile":"","RestartCount":0, -"UpdateDns":false,"Volumes":{},"VolumesRW":{},"AppliedVolumesFrom":null}` - - // Container struct only used to retrieve path to config file - container := &container.Container{CommonContainer: container.CommonContainer{Root: containerPath}} - configPath, err := container.ConfigPath() - if err != nil { - t.Fatal(err) - } - if err = ioutil.WriteFile(configPath, []byte(config), 0644); err != nil { - t.Fatal(err) - } - - hostConfig := `{"Binds":[],"ContainerIDFile":"","Memory":0,"MemorySwap":0,"CpuShares":0,"CpusetCpus":"", -"Privileged":false,"PortBindings":{},"Links":null,"PublishAllPorts":false,"Dns":null,"DnsOptions":null,"DnsSearch":null,"ExtraHosts":null,"VolumesFrom":null, -"Devices":[],"NetworkMode":"bridge","IpcMode":"","PidMode":"","CapAdd":null,"CapDrop":null,"RestartPolicy":{"Name":"no","MaximumRetryCount":0}, -"SecurityOpt":null,"ReadonlyRootfs":false,"Ulimits":null,"LogConfig":{"Type":"","Config":null},"CgroupParent":""}` - - hostConfigPath, err := container.HostConfigPath() - if err != nil { - t.Fatal(err) - } - if err = ioutil.WriteFile(hostConfigPath, []byte(hostConfig), 0644); err != nil { - t.Fatal(err) - } - - daemon, err := initDaemonWithVolumeStore(tmp) - if err != nil { - t.Fatal(err) - } - defer volumedrivers.Unregister(volume.DefaultDriverName) - - c, err := daemon.load(containerID) - if err != nil { - t.Fatal(err) - } - - if c.HostConfig.DNS == nil { - t.Fatal("Expected container DNS to not be nil") - } - - if c.HostConfig.DNSSearch == nil { - t.Fatal("Expected container DNSSearch to not be nil") - } - - if c.HostConfig.DNSOptions == nil { - t.Fatal("Expected container DNSOptions to not be nil") - } -} - -func newPortNoError(proto, port string) nat.Port { - p, _ := nat.NewPort(proto, port) - return p -} - -func TestMerge(t *testing.T) { - volumesImage := make(map[string]struct{}) - volumesImage["/test1"] = struct{}{} - volumesImage["/test2"] = struct{}{} - portsImage := make(nat.PortSet) - portsImage[newPortNoError("tcp", "1111")] = struct{}{} - portsImage[newPortNoError("tcp", "2222")] = struct{}{} - configImage := &containertypes.Config{ - ExposedPorts: portsImage, - Env: []string{"VAR1=1", "VAR2=2"}, - Volumes: volumesImage, - } - - portsUser := make(nat.PortSet) - portsUser[newPortNoError("tcp", "2222")] = struct{}{} - portsUser[newPortNoError("tcp", "3333")] = struct{}{} - volumesUser := make(map[string]struct{}) - volumesUser["/test3"] = struct{}{} - configUser := &containertypes.Config{ - ExposedPorts: portsUser, - Env: []string{"VAR2=3", "VAR3=3"}, - Volumes: volumesUser, - } - - if err := merge(configUser, configImage); err != nil { - t.Error(err) - } - - if len(configUser.ExposedPorts) != 3 { - t.Fatalf("Expected 3 ExposedPorts, 1111, 2222 and 3333, found %d", len(configUser.ExposedPorts)) - } - for portSpecs := range configUser.ExposedPorts { - if portSpecs.Port() != "1111" && portSpecs.Port() != "2222" && portSpecs.Port() != "3333" { - t.Fatalf("Expected 1111 or 2222 or 3333, found %s", portSpecs) - } - } - if len(configUser.Env) != 3 { - t.Fatalf("Expected 3 env var, VAR1=1, VAR2=3 and VAR3=3, found %d", len(configUser.Env)) - } - for _, env := range configUser.Env { - if env != "VAR1=1" && env != "VAR2=3" && env != "VAR3=3" { - t.Fatalf("Expected VAR1=1 or VAR2=3 or VAR3=3, found %s", env) - } - } - - if len(configUser.Volumes) != 3 { - t.Fatalf("Expected 3 volumes, /test1, /test2 and /test3, found %d", len(configUser.Volumes)) - } - for v := range configUser.Volumes { - if v != "/test1" && v != "/test2" && v != "/test3" { - t.Fatalf("Expected /test1 or /test2 or /test3, found %s", v) - } - } - - ports, _, err := nat.ParsePortSpecs([]string{"0000"}) - if err != nil { - t.Error(err) - } - configImage2 := &containertypes.Config{ - ExposedPorts: ports, - } - - if err := merge(configUser, configImage2); err != nil { - t.Error(err) - } - - if len(configUser.ExposedPorts) != 4 { - t.Fatalf("Expected 4 ExposedPorts, 0000, 1111, 2222 and 3333, found %d", len(configUser.ExposedPorts)) - } - for portSpecs := range configUser.ExposedPorts { - if portSpecs.Port() != "0" && portSpecs.Port() != "1111" && portSpecs.Port() != "2222" && portSpecs.Port() != "3333" { - t.Fatalf("Expected %q or %q or %q or %q, found %s", 0, 1111, 2222, 3333, portSpecs) - } - } -} - -func TestDaemonReloadLabels(t *testing.T) { - daemon := &Daemon{} - daemon.configStore = &Config{ - CommonConfig: CommonConfig{ - Labels: []string{"foo:bar"}, - }, - } - - valuesSets := make(map[string]interface{}) - valuesSets["labels"] = "foo:baz" - newConfig := &Config{ - CommonConfig: CommonConfig{ - Labels: []string{"foo:baz"}, - valuesSet: valuesSets, - }, - } - - if err := daemon.Reload(newConfig); err != nil { - t.Fatal(err) - } - - label := daemon.configStore.Labels[0] - if label != "foo:baz" { - t.Fatalf("Expected daemon label `foo:baz`, got %s", label) - } -} - -func TestDaemonReloadInsecureRegistries(t *testing.T) { - daemon := &Daemon{} - // initialize daemon with existing insecure registries: "127.0.0.0/8", "10.10.1.11:5000", "10.10.1.22:5000" - daemon.RegistryService = registry.NewService(registry.ServiceOptions{ - InsecureRegistries: []string{ - "127.0.0.0/8", - "10.10.1.11:5000", - "10.10.1.22:5000", // this will be removed when reloading - "docker1.com", - "docker2.com", // this will be removed when reloading - }, - }) - - daemon.configStore = &Config{} - - insecureRegistries := []string{ - "127.0.0.0/8", // this will be kept - "10.10.1.11:5000", // this will be kept - "10.10.1.33:5000", // this will be newly added - "docker1.com", // this will be kept - "docker3.com", // this will be newly added - } - - valuesSets := make(map[string]interface{}) - valuesSets["insecure-registries"] = insecureRegistries - - newConfig := &Config{ - CommonConfig: CommonConfig{ - ServiceOptions: registry.ServiceOptions{ - InsecureRegistries: insecureRegistries, - }, - valuesSet: valuesSets, - }, - } - - if err := daemon.Reload(newConfig); err != nil { - t.Fatal(err) - } - - // After Reload, daemon.RegistryService will be changed which is useful - // for registry communication in daemon. - registries := daemon.RegistryService.ServiceConfig() - - // After Reload(), newConfig has come to registries.InsecureRegistryCIDRs and registries.IndexConfigs in daemon. - // Then collect registries.InsecureRegistryCIDRs in dataMap. - // When collecting, we need to convert CIDRS into string as a key, - // while the times of key appears as value. - dataMap := map[string]int{} - for _, value := range registries.InsecureRegistryCIDRs { - if _, ok := dataMap[value.String()]; !ok { - dataMap[value.String()] = 1 - } else { - dataMap[value.String()]++ - } - } - - for _, value := range registries.IndexConfigs { - if _, ok := dataMap[value.Name]; !ok { - dataMap[value.Name] = 1 - } else { - dataMap[value.Name]++ - } - } - - // Finally compare dataMap with the original insecureRegistries. - // Each value in insecureRegistries should appear in daemon's insecure registries, - // and each can only appear exactly ONCE. - for _, r := range insecureRegistries { - if value, ok := dataMap[r]; !ok { - t.Fatalf("Expected daemon insecure registry %s, got none", r) - } else if value != 1 { - t.Fatalf("Expected only 1 daemon insecure registry %s, got %d", r, value) - } - } - - // assert if "10.10.1.22:5000" is removed when reloading - if value, ok := dataMap["10.10.1.22:5000"]; ok { - t.Fatalf("Expected no insecure registry of 10.10.1.22:5000, got %d", value) - } - - // assert if "docker2.com" is removed when reloading - if value, ok := dataMap["docker2.com"]; ok { - t.Fatalf("Expected no insecure registry of docker2.com, got %d", value) - } -} - -func TestDaemonReloadNotAffectOthers(t *testing.T) { - daemon := &Daemon{} - daemon.configStore = &Config{ - CommonConfig: CommonConfig{ - Labels: []string{"foo:bar"}, - Debug: true, - }, - } - - valuesSets := make(map[string]interface{}) - valuesSets["labels"] = "foo:baz" - newConfig := &Config{ - CommonConfig: CommonConfig{ - Labels: []string{"foo:baz"}, - valuesSet: valuesSets, - }, - } - - if err := daemon.Reload(newConfig); err != nil { - t.Fatal(err) - } - - label := daemon.configStore.Labels[0] - if label != "foo:baz" { - t.Fatalf("Expected daemon label `foo:baz`, got %s", label) - } - debug := daemon.configStore.Debug - if !debug { - t.Fatalf("Expected debug 'enabled', got 'disabled'") - } -} - -func TestDaemonDiscoveryReload(t *testing.T) { - daemon := &Daemon{} - daemon.configStore = &Config{ - CommonConfig: CommonConfig{ - ClusterStore: "memory://127.0.0.1", - ClusterAdvertise: "127.0.0.1:3333", - }, - } - - if err := daemon.initDiscovery(daemon.configStore); err != nil { - t.Fatal(err) - } - - expected := discovery.Entries{ - &discovery.Entry{Host: "127.0.0.1", Port: "3333"}, - } - - select { - case <-time.After(10 * time.Second): - t.Fatal("timeout waiting for discovery") - case <-daemon.discoveryWatcher.ReadyCh(): - } - - stopCh := make(chan struct{}) - defer close(stopCh) - ch, errCh := daemon.discoveryWatcher.Watch(stopCh) - - select { - case <-time.After(1 * time.Second): - t.Fatal("failed to get discovery advertisements in time") - case e := <-ch: - if !reflect.DeepEqual(e, expected) { - t.Fatalf("expected %v, got %v\n", expected, e) - } - case e := <-errCh: - t.Fatal(e) - } - - valuesSets := make(map[string]interface{}) - valuesSets["cluster-store"] = "memory://127.0.0.1:2222" - valuesSets["cluster-advertise"] = "127.0.0.1:5555" - newConfig := &Config{ - CommonConfig: CommonConfig{ - ClusterStore: "memory://127.0.0.1:2222", - ClusterAdvertise: "127.0.0.1:5555", - valuesSet: valuesSets, - }, - } - - expected = discovery.Entries{ - &discovery.Entry{Host: "127.0.0.1", Port: "5555"}, - } - - if err := daemon.Reload(newConfig); err != nil { - t.Fatal(err) - } - - select { - case <-time.After(10 * time.Second): - t.Fatal("timeout waiting for discovery") - case <-daemon.discoveryWatcher.ReadyCh(): - } - - ch, errCh = daemon.discoveryWatcher.Watch(stopCh) - - select { - case <-time.After(1 * time.Second): - t.Fatal("failed to get discovery advertisements in time") - case e := <-ch: - if !reflect.DeepEqual(e, expected) { - t.Fatalf("expected %v, got %v\n", expected, e) - } - case e := <-errCh: - t.Fatal(e) - } -} - -func TestDaemonDiscoveryReloadFromEmptyDiscovery(t *testing.T) { - daemon := &Daemon{} - daemon.configStore = &Config{} - - valuesSet := make(map[string]interface{}) - valuesSet["cluster-store"] = "memory://127.0.0.1:2222" - valuesSet["cluster-advertise"] = "127.0.0.1:5555" - newConfig := &Config{ - CommonConfig: CommonConfig{ - ClusterStore: "memory://127.0.0.1:2222", - ClusterAdvertise: "127.0.0.1:5555", - valuesSet: valuesSet, - }, - } - - expected := discovery.Entries{ - &discovery.Entry{Host: "127.0.0.1", Port: "5555"}, - } - - if err := daemon.Reload(newConfig); err != nil { - t.Fatal(err) - } - - select { - case <-time.After(10 * time.Second): - t.Fatal("timeout waiting for discovery") - case <-daemon.discoveryWatcher.ReadyCh(): - } - - stopCh := make(chan struct{}) - defer close(stopCh) - ch, errCh := daemon.discoveryWatcher.Watch(stopCh) - - select { - case <-time.After(1 * time.Second): - t.Fatal("failed to get discovery advertisements in time") - case e := <-ch: - if !reflect.DeepEqual(e, expected) { - t.Fatalf("expected %v, got %v\n", expected, e) - } - case e := <-errCh: - t.Fatal(e) - } -} - -func TestDaemonDiscoveryReloadOnlyClusterAdvertise(t *testing.T) { - daemon := &Daemon{} - daemon.configStore = &Config{ - CommonConfig: CommonConfig{ - ClusterStore: "memory://127.0.0.1", - }, - } - valuesSets := make(map[string]interface{}) - valuesSets["cluster-advertise"] = "127.0.0.1:5555" - newConfig := &Config{ - CommonConfig: CommonConfig{ - ClusterAdvertise: "127.0.0.1:5555", - valuesSet: valuesSets, - }, - } - expected := discovery.Entries{ - &discovery.Entry{Host: "127.0.0.1", Port: "5555"}, - } - - if err := daemon.Reload(newConfig); err != nil { - t.Fatal(err) - } - - select { - case <-daemon.discoveryWatcher.ReadyCh(): - case <-time.After(10 * time.Second): - t.Fatal("Timeout waiting for discovery") - } - stopCh := make(chan struct{}) - defer close(stopCh) - ch, errCh := daemon.discoveryWatcher.Watch(stopCh) - - select { - case <-time.After(1 * time.Second): - t.Fatal("failed to get discovery advertisements in time") - case e := <-ch: - if !reflect.DeepEqual(e, expected) { - t.Fatalf("expected %v, got %v\n", expected, e) - } - case e := <-errCh: - t.Fatal(e) - } - -} diff --git a/vendor/github.com/docker/docker/daemon/daemon_unix.go b/vendor/github.com/docker/docker/daemon/daemon_unix.go deleted file mode 100644 index 5b3ffeb..0000000 --- a/vendor/github.com/docker/docker/daemon/daemon_unix.go +++ /dev/null @@ -1,1237 +0,0 @@ -// +build linux freebsd - -package daemon - -import ( - "bytes" - "fmt" - "io/ioutil" - "net" - "os" - "path/filepath" - "runtime" - "runtime/debug" - "strconv" - "strings" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/blkiodev" - pblkiodev "github.com/docker/docker/api/types/blkiodev" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/image" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/parsers" - "github.com/docker/docker/pkg/parsers/kernel" - "github.com/docker/docker/pkg/sysinfo" - "github.com/docker/docker/runconfig" - runconfigopts "github.com/docker/docker/runconfig/opts" - "github.com/docker/libnetwork" - nwconfig "github.com/docker/libnetwork/config" - "github.com/docker/libnetwork/drivers/bridge" - "github.com/docker/libnetwork/netlabel" - "github.com/docker/libnetwork/netutils" - "github.com/docker/libnetwork/options" - lntypes "github.com/docker/libnetwork/types" - "github.com/golang/protobuf/ptypes" - "github.com/opencontainers/runc/libcontainer/cgroups" - "github.com/opencontainers/runc/libcontainer/label" - rsystem "github.com/opencontainers/runc/libcontainer/system" - specs "github.com/opencontainers/runtime-spec/specs-go" - "github.com/pkg/errors" - "github.com/vishvananda/netlink" -) - -const ( - // See https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/tree/kernel/sched/sched.h?id=8cd9234c64c584432f6992fe944ca9e46ca8ea76#n269 - linuxMinCPUShares = 2 - linuxMaxCPUShares = 262144 - platformSupported = true - // It's not kernel limit, we want this 4M limit to supply a reasonable functional container - linuxMinMemory = 4194304 - // constants for remapped root settings - defaultIDSpecifier string = "default" - defaultRemappedID string = "dockremap" - - // constant for cgroup drivers - cgroupFsDriver = "cgroupfs" - cgroupSystemdDriver = "systemd" -) - -func getMemoryResources(config containertypes.Resources) *specs.Memory { - memory := specs.Memory{} - - if config.Memory > 0 { - limit := uint64(config.Memory) - memory.Limit = &limit - } - - if config.MemoryReservation > 0 { - reservation := uint64(config.MemoryReservation) - memory.Reservation = &reservation - } - - if config.MemorySwap != 0 { - swap := uint64(config.MemorySwap) - memory.Swap = &swap - } - - if config.MemorySwappiness != nil { - swappiness := uint64(*config.MemorySwappiness) - memory.Swappiness = &swappiness - } - - if config.KernelMemory != 0 { - kernelMemory := uint64(config.KernelMemory) - memory.Kernel = &kernelMemory - } - - return &memory -} - -func getCPUResources(config containertypes.Resources) *specs.CPU { - cpu := specs.CPU{} - - if config.CPUShares != 0 { - shares := uint64(config.CPUShares) - cpu.Shares = &shares - } - - if config.CpusetCpus != "" { - cpuset := config.CpusetCpus - cpu.Cpus = &cpuset - } - - if config.CpusetMems != "" { - cpuset := config.CpusetMems - cpu.Mems = &cpuset - } - - if config.NanoCPUs > 0 { - // https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt - period := uint64(100 * time.Millisecond / time.Microsecond) - quota := uint64(config.NanoCPUs) * period / 1e9 - cpu.Period = &period - cpu.Quota = "a - } - - if config.CPUPeriod != 0 { - period := uint64(config.CPUPeriod) - cpu.Period = &period - } - - if config.CPUQuota != 0 { - quota := uint64(config.CPUQuota) - cpu.Quota = "a - } - - if config.CPURealtimePeriod != 0 { - period := uint64(config.CPURealtimePeriod) - cpu.RealtimePeriod = &period - } - - if config.CPURealtimeRuntime != 0 { - runtime := uint64(config.CPURealtimeRuntime) - cpu.RealtimeRuntime = &runtime - } - - return &cpu -} - -func getBlkioWeightDevices(config containertypes.Resources) ([]specs.WeightDevice, error) { - var stat syscall.Stat_t - var blkioWeightDevices []specs.WeightDevice - - for _, weightDevice := range config.BlkioWeightDevice { - if err := syscall.Stat(weightDevice.Path, &stat); err != nil { - return nil, err - } - weight := weightDevice.Weight - d := specs.WeightDevice{Weight: &weight} - d.Major = int64(stat.Rdev / 256) - d.Minor = int64(stat.Rdev % 256) - blkioWeightDevices = append(blkioWeightDevices, d) - } - - return blkioWeightDevices, nil -} - -func parseSecurityOpt(container *container.Container, config *containertypes.HostConfig) error { - var ( - labelOpts []string - err error - ) - - for _, opt := range config.SecurityOpt { - if opt == "no-new-privileges" { - container.NoNewPrivileges = true - continue - } - - var con []string - if strings.Contains(opt, "=") { - con = strings.SplitN(opt, "=", 2) - } else if strings.Contains(opt, ":") { - con = strings.SplitN(opt, ":", 2) - logrus.Warn("Security options with `:` as a separator are deprecated and will be completely unsupported in 1.14, use `=` instead.") - } - - if len(con) != 2 { - return fmt.Errorf("invalid --security-opt 1: %q", opt) - } - - switch con[0] { - case "label": - labelOpts = append(labelOpts, con[1]) - case "apparmor": - container.AppArmorProfile = con[1] - case "seccomp": - container.SeccompProfile = con[1] - default: - return fmt.Errorf("invalid --security-opt 2: %q", opt) - } - } - - container.ProcessLabel, container.MountLabel, err = label.InitLabels(labelOpts) - return err -} - -func getBlkioThrottleDevices(devs []*blkiodev.ThrottleDevice) ([]specs.ThrottleDevice, error) { - var throttleDevices []specs.ThrottleDevice - var stat syscall.Stat_t - - for _, d := range devs { - if err := syscall.Stat(d.Path, &stat); err != nil { - return nil, err - } - rate := d.Rate - d := specs.ThrottleDevice{Rate: &rate} - d.Major = int64(stat.Rdev / 256) - d.Minor = int64(stat.Rdev % 256) - throttleDevices = append(throttleDevices, d) - } - - return throttleDevices, nil -} - -func checkKernel() error { - // Check for unsupported kernel versions - // FIXME: it would be cleaner to not test for specific versions, but rather - // test for specific functionalities. - // Unfortunately we can't test for the feature "does not cause a kernel panic" - // without actually causing a kernel panic, so we need this workaround until - // the circumstances of pre-3.10 crashes are clearer. - // For details see https://github.com/docker/docker/issues/407 - // Docker 1.11 and above doesn't actually run on kernels older than 3.4, - // due to containerd-shim usage of PR_SET_CHILD_SUBREAPER (introduced in 3.4). - if !kernel.CheckKernelVersion(3, 10, 0) { - v, _ := kernel.GetKernelVersion() - if os.Getenv("DOCKER_NOWARN_KERNEL_VERSION") == "" { - logrus.Fatalf("Your Linux kernel version %s is not supported for running docker. Please upgrade your kernel to 3.10.0 or newer.", v.String()) - } - } - return nil -} - -// adaptContainerSettings is called during container creation to modify any -// settings necessary in the HostConfig structure. -func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConfig, adjustCPUShares bool) error { - if adjustCPUShares && hostConfig.CPUShares > 0 { - // Handle unsupported CPUShares - if hostConfig.CPUShares < linuxMinCPUShares { - logrus.Warnf("Changing requested CPUShares of %d to minimum allowed of %d", hostConfig.CPUShares, linuxMinCPUShares) - hostConfig.CPUShares = linuxMinCPUShares - } else if hostConfig.CPUShares > linuxMaxCPUShares { - logrus.Warnf("Changing requested CPUShares of %d to maximum allowed of %d", hostConfig.CPUShares, linuxMaxCPUShares) - hostConfig.CPUShares = linuxMaxCPUShares - } - } - if hostConfig.Memory > 0 && hostConfig.MemorySwap == 0 { - // By default, MemorySwap is set to twice the size of Memory. - hostConfig.MemorySwap = hostConfig.Memory * 2 - } - if hostConfig.ShmSize == 0 { - hostConfig.ShmSize = container.DefaultSHMSize - } - var err error - opts, err := daemon.generateSecurityOpt(hostConfig.IpcMode, hostConfig.PidMode, hostConfig.Privileged) - if err != nil { - return err - } - hostConfig.SecurityOpt = append(hostConfig.SecurityOpt, opts...) - if hostConfig.MemorySwappiness == nil { - defaultSwappiness := int64(-1) - hostConfig.MemorySwappiness = &defaultSwappiness - } - if hostConfig.OomKillDisable == nil { - defaultOomKillDisable := false - hostConfig.OomKillDisable = &defaultOomKillDisable - } - - return nil -} - -func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysinfo.SysInfo, update bool) ([]string, error) { - warnings := []string{} - - // memory subsystem checks and adjustments - if resources.Memory != 0 && resources.Memory < linuxMinMemory { - return warnings, fmt.Errorf("Minimum memory limit allowed is 4MB") - } - if resources.Memory > 0 && !sysInfo.MemoryLimit { - warnings = append(warnings, "Your kernel does not support memory limit capabilities or the cgroup is not mounted. Limitation discarded.") - logrus.Warn("Your kernel does not support memory limit capabilities or the cgroup is not mounted. Limitation discarded.") - resources.Memory = 0 - resources.MemorySwap = -1 - } - if resources.Memory > 0 && resources.MemorySwap != -1 && !sysInfo.SwapLimit { - warnings = append(warnings, "Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.") - logrus.Warn("Your kernel does not support swap limit capabilities,or the cgroup is not mounted. Memory limited without swap.") - resources.MemorySwap = -1 - } - if resources.Memory > 0 && resources.MemorySwap > 0 && resources.MemorySwap < resources.Memory { - return warnings, fmt.Errorf("Minimum memoryswap limit should be larger than memory limit, see usage") - } - if resources.Memory == 0 && resources.MemorySwap > 0 && !update { - return warnings, fmt.Errorf("You should always set the Memory limit when using Memoryswap limit, see usage") - } - if resources.MemorySwappiness != nil && *resources.MemorySwappiness != -1 && !sysInfo.MemorySwappiness { - warnings = append(warnings, "Your kernel does not support memory swappiness capabilities or the cgroup is not mounted. Memory swappiness discarded.") - logrus.Warn("Your kernel does not support memory swappiness capabilities, or the cgroup is not mounted. Memory swappiness discarded.") - resources.MemorySwappiness = nil - } - if resources.MemorySwappiness != nil { - swappiness := *resources.MemorySwappiness - if swappiness < -1 || swappiness > 100 { - return warnings, fmt.Errorf("Invalid value: %v, valid memory swappiness range is 0-100", swappiness) - } - } - if resources.MemoryReservation > 0 && !sysInfo.MemoryReservation { - warnings = append(warnings, "Your kernel does not support memory soft limit capabilities or the cgroup is not mounted. Limitation discarded.") - logrus.Warn("Your kernel does not support memory soft limit capabilities or the cgroup is not mounted. Limitation discarded.") - resources.MemoryReservation = 0 - } - if resources.MemoryReservation > 0 && resources.MemoryReservation < linuxMinMemory { - return warnings, fmt.Errorf("Minimum memory reservation allowed is 4MB") - } - if resources.Memory > 0 && resources.MemoryReservation > 0 && resources.Memory < resources.MemoryReservation { - return warnings, fmt.Errorf("Minimum memory limit can not be less than memory reservation limit, see usage") - } - if resources.KernelMemory > 0 && !sysInfo.KernelMemory { - warnings = append(warnings, "Your kernel does not support kernel memory limit capabilities or the cgroup is not mounted. Limitation discarded.") - logrus.Warn("Your kernel does not support kernel memory limit capabilities or the cgroup is not mounted. Limitation discarded.") - resources.KernelMemory = 0 - } - if resources.KernelMemory > 0 && resources.KernelMemory < linuxMinMemory { - return warnings, fmt.Errorf("Minimum kernel memory limit allowed is 4MB") - } - if resources.KernelMemory > 0 && !kernel.CheckKernelVersion(4, 0, 0) { - warnings = append(warnings, "You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.") - logrus.Warn("You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.") - } - if resources.OomKillDisable != nil && !sysInfo.OomKillDisable { - // only produce warnings if the setting wasn't to *disable* the OOM Kill; no point - // warning the caller if they already wanted the feature to be off - if *resources.OomKillDisable { - warnings = append(warnings, "Your kernel does not support OomKillDisable. OomKillDisable discarded.") - logrus.Warn("Your kernel does not support OomKillDisable. OomKillDisable discarded.") - } - resources.OomKillDisable = nil - } - - if resources.PidsLimit != 0 && !sysInfo.PidsLimit { - warnings = append(warnings, "Your kernel does not support pids limit capabilities or the cgroup is not mounted. PIDs limit discarded.") - logrus.Warn("Your kernel does not support pids limit capabilities or the cgroup is not mounted. PIDs limit discarded.") - resources.PidsLimit = 0 - } - - // cpu subsystem checks and adjustments - if resources.NanoCPUs > 0 && resources.CPUPeriod > 0 { - return warnings, fmt.Errorf("Conflicting options: Nano CPUs and CPU Period cannot both be set") - } - if resources.NanoCPUs > 0 && resources.CPUQuota > 0 { - return warnings, fmt.Errorf("Conflicting options: Nano CPUs and CPU Quota cannot both be set") - } - if resources.NanoCPUs > 0 && (!sysInfo.CPUCfsPeriod || !sysInfo.CPUCfsQuota) { - return warnings, fmt.Errorf("NanoCPUs can not be set, as your kernel does not support CPU cfs period/quota or the cgroup is not mounted") - } - // The highest precision we could get on Linux is 0.001, by setting - // cpu.cfs_period_us=1000ms - // cpu.cfs_quota=1ms - // See the following link for details: - // https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt - // Here we don't set the lower limit and it is up to the underlying platform (e.g., Linux) to return an error. - // The error message is 0.01 so that this is consistent with Windows - if resources.NanoCPUs < 0 || resources.NanoCPUs > int64(sysinfo.NumCPU())*1e9 { - return warnings, fmt.Errorf("Range of CPUs is from 0.01 to %d.00, as there are only %d CPUs available", sysinfo.NumCPU(), sysinfo.NumCPU()) - } - - if resources.CPUShares > 0 && !sysInfo.CPUShares { - warnings = append(warnings, "Your kernel does not support CPU shares or the cgroup is not mounted. Shares discarded.") - logrus.Warn("Your kernel does not support CPU shares or the cgroup is not mounted. Shares discarded.") - resources.CPUShares = 0 - } - if resources.CPUPeriod > 0 && !sysInfo.CPUCfsPeriod { - warnings = append(warnings, "Your kernel does not support CPU cfs period or the cgroup is not mounted. Period discarded.") - logrus.Warn("Your kernel does not support CPU cfs period or the cgroup is not mounted. Period discarded.") - resources.CPUPeriod = 0 - } - if resources.CPUPeriod != 0 && (resources.CPUPeriod < 1000 || resources.CPUPeriod > 1000000) { - return warnings, fmt.Errorf("CPU cfs period can not be less than 1ms (i.e. 1000) or larger than 1s (i.e. 1000000)") - } - if resources.CPUQuota > 0 && !sysInfo.CPUCfsQuota { - warnings = append(warnings, "Your kernel does not support CPU cfs quota or the cgroup is not mounted. Quota discarded.") - logrus.Warn("Your kernel does not support CPU cfs quota or the cgroup is not mounted. Quota discarded.") - resources.CPUQuota = 0 - } - if resources.CPUQuota > 0 && resources.CPUQuota < 1000 { - return warnings, fmt.Errorf("CPU cfs quota can not be less than 1ms (i.e. 1000)") - } - if resources.CPUPercent > 0 { - warnings = append(warnings, fmt.Sprintf("%s does not support CPU percent. Percent discarded.", runtime.GOOS)) - logrus.Warnf("%s does not support CPU percent. Percent discarded.", runtime.GOOS) - resources.CPUPercent = 0 - } - - // cpuset subsystem checks and adjustments - if (resources.CpusetCpus != "" || resources.CpusetMems != "") && !sysInfo.Cpuset { - warnings = append(warnings, "Your kernel does not support cpuset or the cgroup is not mounted. Cpuset discarded.") - logrus.Warn("Your kernel does not support cpuset or the cgroup is not mounted. Cpuset discarded.") - resources.CpusetCpus = "" - resources.CpusetMems = "" - } - cpusAvailable, err := sysInfo.IsCpusetCpusAvailable(resources.CpusetCpus) - if err != nil { - return warnings, fmt.Errorf("Invalid value %s for cpuset cpus", resources.CpusetCpus) - } - if !cpusAvailable { - return warnings, fmt.Errorf("Requested CPUs are not available - requested %s, available: %s", resources.CpusetCpus, sysInfo.Cpus) - } - memsAvailable, err := sysInfo.IsCpusetMemsAvailable(resources.CpusetMems) - if err != nil { - return warnings, fmt.Errorf("Invalid value %s for cpuset mems", resources.CpusetMems) - } - if !memsAvailable { - return warnings, fmt.Errorf("Requested memory nodes are not available - requested %s, available: %s", resources.CpusetMems, sysInfo.Mems) - } - - // blkio subsystem checks and adjustments - if resources.BlkioWeight > 0 && !sysInfo.BlkioWeight { - warnings = append(warnings, "Your kernel does not support Block I/O weight or the cgroup is not mounted. Weight discarded.") - logrus.Warn("Your kernel does not support Block I/O weight or the cgroup is not mounted. Weight discarded.") - resources.BlkioWeight = 0 - } - if resources.BlkioWeight > 0 && (resources.BlkioWeight < 10 || resources.BlkioWeight > 1000) { - return warnings, fmt.Errorf("Range of blkio weight is from 10 to 1000") - } - if resources.IOMaximumBandwidth != 0 || resources.IOMaximumIOps != 0 { - return warnings, fmt.Errorf("Invalid QoS settings: %s does not support Maximum IO Bandwidth or Maximum IO IOps", runtime.GOOS) - } - if len(resources.BlkioWeightDevice) > 0 && !sysInfo.BlkioWeightDevice { - warnings = append(warnings, "Your kernel does not support Block I/O weight_device or the cgroup is not mounted. Weight-device discarded.") - logrus.Warn("Your kernel does not support Block I/O weight_device or the cgroup is not mounted. Weight-device discarded.") - resources.BlkioWeightDevice = []*pblkiodev.WeightDevice{} - } - if len(resources.BlkioDeviceReadBps) > 0 && !sysInfo.BlkioReadBpsDevice { - warnings = append(warnings, "Your kernel does not support BPS Block I/O read limit or the cgroup is not mounted. Block I/O BPS read limit discarded.") - logrus.Warn("Your kernel does not support BPS Block I/O read limit or the cgroup is not mounted. Block I/O BPS read limit discarded") - resources.BlkioDeviceReadBps = []*pblkiodev.ThrottleDevice{} - } - if len(resources.BlkioDeviceWriteBps) > 0 && !sysInfo.BlkioWriteBpsDevice { - warnings = append(warnings, "Your kernel does not support BPS Block I/O write limit or the cgroup is not mounted. Block I/O BPS write limit discarded.") - logrus.Warn("Your kernel does not support BPS Block I/O write limit or the cgroup is not mounted. Block I/O BPS write limit discarded.") - resources.BlkioDeviceWriteBps = []*pblkiodev.ThrottleDevice{} - } - if len(resources.BlkioDeviceReadIOps) > 0 && !sysInfo.BlkioReadIOpsDevice { - warnings = append(warnings, "Your kernel does not support IOPS Block read limit or the cgroup is not mounted. Block I/O IOPS read limit discarded.") - logrus.Warn("Your kernel does not support IOPS Block I/O read limit in IO or the cgroup is not mounted. Block I/O IOPS read limit discarded.") - resources.BlkioDeviceReadIOps = []*pblkiodev.ThrottleDevice{} - } - if len(resources.BlkioDeviceWriteIOps) > 0 && !sysInfo.BlkioWriteIOpsDevice { - warnings = append(warnings, "Your kernel does not support IOPS Block write limit or the cgroup is not mounted. Block I/O IOPS write limit discarded.") - logrus.Warn("Your kernel does not support IOPS Block I/O write limit or the cgroup is not mounted. Block I/O IOPS write limit discarded.") - resources.BlkioDeviceWriteIOps = []*pblkiodev.ThrottleDevice{} - } - - return warnings, nil -} - -func (daemon *Daemon) getCgroupDriver() string { - cgroupDriver := cgroupFsDriver - - if UsingSystemd(daemon.configStore) { - cgroupDriver = cgroupSystemdDriver - } - return cgroupDriver -} - -// getCD gets the raw value of the native.cgroupdriver option, if set. -func getCD(config *Config) string { - for _, option := range config.ExecOptions { - key, val, err := parsers.ParseKeyValueOpt(option) - if err != nil || !strings.EqualFold(key, "native.cgroupdriver") { - continue - } - return val - } - return "" -} - -// VerifyCgroupDriver validates native.cgroupdriver -func VerifyCgroupDriver(config *Config) error { - cd := getCD(config) - if cd == "" || cd == cgroupFsDriver || cd == cgroupSystemdDriver { - return nil - } - return fmt.Errorf("native.cgroupdriver option %s not supported", cd) -} - -// UsingSystemd returns true if cli option includes native.cgroupdriver=systemd -func UsingSystemd(config *Config) bool { - return getCD(config) == cgroupSystemdDriver -} - -// verifyPlatformContainerSettings performs platform-specific validation of the -// hostconfig and config structures. -func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) { - warnings := []string{} - sysInfo := sysinfo.New(true) - - warnings, err := daemon.verifyExperimentalContainerSettings(hostConfig, config) - if err != nil { - return warnings, err - } - - w, err := verifyContainerResources(&hostConfig.Resources, sysInfo, update) - - // no matter err is nil or not, w could have data in itself. - warnings = append(warnings, w...) - - if err != nil { - return warnings, err - } - - if hostConfig.ShmSize < 0 { - return warnings, fmt.Errorf("SHM size can not be less than 0") - } - - if hostConfig.OomScoreAdj < -1000 || hostConfig.OomScoreAdj > 1000 { - return warnings, fmt.Errorf("Invalid value %d, range for oom score adj is [-1000, 1000]", hostConfig.OomScoreAdj) - } - - // ip-forwarding does not affect container with '--net=host' (or '--net=none') - if sysInfo.IPv4ForwardingDisabled && !(hostConfig.NetworkMode.IsHost() || hostConfig.NetworkMode.IsNone()) { - warnings = append(warnings, "IPv4 forwarding is disabled. Networking will not work.") - logrus.Warn("IPv4 forwarding is disabled. Networking will not work") - } - // check for various conflicting options with user namespaces - if daemon.configStore.RemappedRoot != "" && hostConfig.UsernsMode.IsPrivate() { - if hostConfig.Privileged { - return warnings, fmt.Errorf("Privileged mode is incompatible with user namespaces") - } - if hostConfig.NetworkMode.IsHost() && !hostConfig.UsernsMode.IsHost() { - return warnings, fmt.Errorf("Cannot share the host's network namespace when user namespaces are enabled") - } - if hostConfig.PidMode.IsHost() && !hostConfig.UsernsMode.IsHost() { - return warnings, fmt.Errorf("Cannot share the host PID namespace when user namespaces are enabled") - } - } - if hostConfig.CgroupParent != "" && UsingSystemd(daemon.configStore) { - // CgroupParent for systemd cgroup should be named as "xxx.slice" - if len(hostConfig.CgroupParent) <= 6 || !strings.HasSuffix(hostConfig.CgroupParent, ".slice") { - return warnings, fmt.Errorf("cgroup-parent for systemd cgroup should be a valid slice named as \"xxx.slice\"") - } - } - if hostConfig.Runtime == "" { - hostConfig.Runtime = daemon.configStore.GetDefaultRuntimeName() - } - - if rt := daemon.configStore.GetRuntime(hostConfig.Runtime); rt == nil { - return warnings, fmt.Errorf("Unknown runtime specified %s", hostConfig.Runtime) - } - - return warnings, nil -} - -// platformReload update configuration with platform specific options -func (daemon *Daemon) platformReload(config *Config) map[string]string { - if config.IsValueSet("runtimes") { - daemon.configStore.Runtimes = config.Runtimes - // Always set the default one - daemon.configStore.Runtimes[stockRuntimeName] = types.Runtime{Path: DefaultRuntimeBinary} - } - - if config.DefaultRuntime != "" { - daemon.configStore.DefaultRuntime = config.DefaultRuntime - } - - // Update attributes - var runtimeList bytes.Buffer - for name, rt := range daemon.configStore.Runtimes { - if runtimeList.Len() > 0 { - runtimeList.WriteRune(' ') - } - runtimeList.WriteString(fmt.Sprintf("%s:%s", name, rt)) - } - - return map[string]string{ - "runtimes": runtimeList.String(), - "default-runtime": daemon.configStore.DefaultRuntime, - } -} - -// verifyDaemonSettings performs validation of daemon config struct -func verifyDaemonSettings(config *Config) error { - // Check for mutually incompatible config options - if config.bridgeConfig.Iface != "" && config.bridgeConfig.IP != "" { - return fmt.Errorf("You specified -b & --bip, mutually exclusive options. Please specify only one") - } - if !config.bridgeConfig.EnableIPTables && !config.bridgeConfig.InterContainerCommunication { - return fmt.Errorf("You specified --iptables=false with --icc=false. ICC=false uses iptables to function. Please set --icc or --iptables to true") - } - if !config.bridgeConfig.EnableIPTables && config.bridgeConfig.EnableIPMasq { - config.bridgeConfig.EnableIPMasq = false - } - if err := VerifyCgroupDriver(config); err != nil { - return err - } - if config.CgroupParent != "" && UsingSystemd(config) { - if len(config.CgroupParent) <= 6 || !strings.HasSuffix(config.CgroupParent, ".slice") { - return fmt.Errorf("cgroup-parent for systemd cgroup should be a valid slice named as \"xxx.slice\"") - } - } - - if config.DefaultRuntime == "" { - config.DefaultRuntime = stockRuntimeName - } - if config.Runtimes == nil { - config.Runtimes = make(map[string]types.Runtime) - } - config.Runtimes[stockRuntimeName] = types.Runtime{Path: DefaultRuntimeBinary} - - return nil -} - -// checkSystem validates platform-specific requirements -func checkSystem() error { - if os.Geteuid() != 0 { - return fmt.Errorf("The Docker daemon needs to be run as root") - } - return checkKernel() -} - -// configureMaxThreads sets the Go runtime max threads threshold -// which is 90% of the kernel setting from /proc/sys/kernel/threads-max -func configureMaxThreads(config *Config) error { - mt, err := ioutil.ReadFile("/proc/sys/kernel/threads-max") - if err != nil { - return err - } - mtint, err := strconv.Atoi(strings.TrimSpace(string(mt))) - if err != nil { - return err - } - maxThreads := (mtint / 100) * 90 - debug.SetMaxThreads(maxThreads) - logrus.Debugf("Golang's threads limit set to %d", maxThreads) - return nil -} - -// configureKernelSecuritySupport configures and validates security support for the kernel -func configureKernelSecuritySupport(config *Config, driverName string) error { - if config.EnableSelinuxSupport { - if !selinuxEnabled() { - logrus.Warn("Docker could not enable SELinux on the host system") - } - } else { - selinuxSetDisabled() - } - return nil -} - -func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[string]interface{}) (libnetwork.NetworkController, error) { - netOptions, err := daemon.networkOptions(config, daemon.PluginStore, activeSandboxes) - if err != nil { - return nil, err - } - - controller, err := libnetwork.New(netOptions...) - if err != nil { - return nil, fmt.Errorf("error obtaining controller instance: %v", err) - } - - if len(activeSandboxes) > 0 { - logrus.Info("There are old running containers, the network config will not take affect") - return controller, nil - } - - // Initialize default network on "null" - if n, _ := controller.NetworkByName("none"); n == nil { - if _, err := controller.NewNetwork("null", "none", "", libnetwork.NetworkOptionPersist(true)); err != nil { - return nil, fmt.Errorf("Error creating default \"null\" network: %v", err) - } - } - - // Initialize default network on "host" - if n, _ := controller.NetworkByName("host"); n == nil { - if _, err := controller.NewNetwork("host", "host", "", libnetwork.NetworkOptionPersist(true)); err != nil { - return nil, fmt.Errorf("Error creating default \"host\" network: %v", err) - } - } - - // Clear stale bridge network - if n, err := controller.NetworkByName("bridge"); err == nil { - if err = n.Delete(); err != nil { - return nil, fmt.Errorf("could not delete the default bridge network: %v", err) - } - } - - if !config.DisableBridge { - // Initialize default driver "bridge" - if err := initBridgeDriver(controller, config); err != nil { - return nil, err - } - } else { - removeDefaultBridgeInterface() - } - - return controller, nil -} - -func driverOptions(config *Config) []nwconfig.Option { - bridgeConfig := options.Generic{ - "EnableIPForwarding": config.bridgeConfig.EnableIPForward, - "EnableIPTables": config.bridgeConfig.EnableIPTables, - "EnableUserlandProxy": config.bridgeConfig.EnableUserlandProxy, - "UserlandProxyPath": config.bridgeConfig.UserlandProxyPath} - bridgeOption := options.Generic{netlabel.GenericData: bridgeConfig} - - dOptions := []nwconfig.Option{} - dOptions = append(dOptions, nwconfig.OptionDriverConfig("bridge", bridgeOption)) - return dOptions -} - -func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error { - bridgeName := bridge.DefaultBridgeName - if config.bridgeConfig.Iface != "" { - bridgeName = config.bridgeConfig.Iface - } - netOption := map[string]string{ - bridge.BridgeName: bridgeName, - bridge.DefaultBridge: strconv.FormatBool(true), - netlabel.DriverMTU: strconv.Itoa(config.Mtu), - bridge.EnableIPMasquerade: strconv.FormatBool(config.bridgeConfig.EnableIPMasq), - bridge.EnableICC: strconv.FormatBool(config.bridgeConfig.InterContainerCommunication), - } - - // --ip processing - if config.bridgeConfig.DefaultIP != nil { - netOption[bridge.DefaultBindingIP] = config.bridgeConfig.DefaultIP.String() - } - - var ( - ipamV4Conf *libnetwork.IpamConf - ipamV6Conf *libnetwork.IpamConf - ) - - ipamV4Conf = &libnetwork.IpamConf{AuxAddresses: make(map[string]string)} - - nwList, nw6List, err := netutils.ElectInterfaceAddresses(bridgeName) - if err != nil { - return errors.Wrap(err, "list bridge addresses failed") - } - - nw := nwList[0] - if len(nwList) > 1 && config.bridgeConfig.FixedCIDR != "" { - _, fCIDR, err := net.ParseCIDR(config.bridgeConfig.FixedCIDR) - if err != nil { - return errors.Wrap(err, "parse CIDR failed") - } - // Iterate through in case there are multiple addresses for the bridge - for _, entry := range nwList { - if fCIDR.Contains(entry.IP) { - nw = entry - break - } - } - } - - ipamV4Conf.PreferredPool = lntypes.GetIPNetCanonical(nw).String() - hip, _ := lntypes.GetHostPartIP(nw.IP, nw.Mask) - if hip.IsGlobalUnicast() { - ipamV4Conf.Gateway = nw.IP.String() - } - - if config.bridgeConfig.IP != "" { - ipamV4Conf.PreferredPool = config.bridgeConfig.IP - ip, _, err := net.ParseCIDR(config.bridgeConfig.IP) - if err != nil { - return err - } - ipamV4Conf.Gateway = ip.String() - } else if bridgeName == bridge.DefaultBridgeName && ipamV4Conf.PreferredPool != "" { - logrus.Infof("Default bridge (%s) is assigned with an IP address %s. Daemon option --bip can be used to set a preferred IP address", bridgeName, ipamV4Conf.PreferredPool) - } - - if config.bridgeConfig.FixedCIDR != "" { - _, fCIDR, err := net.ParseCIDR(config.bridgeConfig.FixedCIDR) - if err != nil { - return err - } - - ipamV4Conf.SubPool = fCIDR.String() - } - - if config.bridgeConfig.DefaultGatewayIPv4 != nil { - ipamV4Conf.AuxAddresses["DefaultGatewayIPv4"] = config.bridgeConfig.DefaultGatewayIPv4.String() - } - - var deferIPv6Alloc bool - if config.bridgeConfig.FixedCIDRv6 != "" { - _, fCIDRv6, err := net.ParseCIDR(config.bridgeConfig.FixedCIDRv6) - if err != nil { - return err - } - - // In case user has specified the daemon flag --fixed-cidr-v6 and the passed network has - // at least 48 host bits, we need to guarantee the current behavior where the containers' - // IPv6 addresses will be constructed based on the containers' interface MAC address. - // We do so by telling libnetwork to defer the IPv6 address allocation for the endpoints - // on this network until after the driver has created the endpoint and returned the - // constructed address. Libnetwork will then reserve this address with the ipam driver. - ones, _ := fCIDRv6.Mask.Size() - deferIPv6Alloc = ones <= 80 - - if ipamV6Conf == nil { - ipamV6Conf = &libnetwork.IpamConf{AuxAddresses: make(map[string]string)} - } - ipamV6Conf.PreferredPool = fCIDRv6.String() - - // In case the --fixed-cidr-v6 is specified and the current docker0 bridge IPv6 - // address belongs to the same network, we need to inform libnetwork about it, so - // that it can be reserved with IPAM and it will not be given away to somebody else - for _, nw6 := range nw6List { - if fCIDRv6.Contains(nw6.IP) { - ipamV6Conf.Gateway = nw6.IP.String() - break - } - } - } - - if config.bridgeConfig.DefaultGatewayIPv6 != nil { - if ipamV6Conf == nil { - ipamV6Conf = &libnetwork.IpamConf{AuxAddresses: make(map[string]string)} - } - ipamV6Conf.AuxAddresses["DefaultGatewayIPv6"] = config.bridgeConfig.DefaultGatewayIPv6.String() - } - - v4Conf := []*libnetwork.IpamConf{ipamV4Conf} - v6Conf := []*libnetwork.IpamConf{} - if ipamV6Conf != nil { - v6Conf = append(v6Conf, ipamV6Conf) - } - // Initialize default network on "bridge" with the same name - _, err = controller.NewNetwork("bridge", "bridge", "", - libnetwork.NetworkOptionEnableIPv6(config.bridgeConfig.EnableIPv6), - libnetwork.NetworkOptionDriverOpts(netOption), - libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil), - libnetwork.NetworkOptionDeferIPv6Alloc(deferIPv6Alloc)) - if err != nil { - return fmt.Errorf("Error creating default \"bridge\" network: %v", err) - } - return nil -} - -// Remove default bridge interface if present (--bridge=none use case) -func removeDefaultBridgeInterface() { - if lnk, err := netlink.LinkByName(bridge.DefaultBridgeName); err == nil { - if err := netlink.LinkDel(lnk); err != nil { - logrus.Warnf("Failed to remove bridge interface (%s): %v", bridge.DefaultBridgeName, err) - } - } -} - -func (daemon *Daemon) getLayerInit() func(string) error { - return daemon.setupInitLayer -} - -// Parse the remapped root (user namespace) option, which can be one of: -// username - valid username from /etc/passwd -// username:groupname - valid username; valid groupname from /etc/group -// uid - 32-bit unsigned int valid Linux UID value -// uid:gid - uid value; 32-bit unsigned int Linux GID value -// -// If no groupname is specified, and a username is specified, an attempt -// will be made to lookup a gid for that username as a groupname -// -// If names are used, they are verified to exist in passwd/group -func parseRemappedRoot(usergrp string) (string, string, error) { - - var ( - userID, groupID int - username, groupname string - ) - - idparts := strings.Split(usergrp, ":") - if len(idparts) > 2 { - return "", "", fmt.Errorf("Invalid user/group specification in --userns-remap: %q", usergrp) - } - - if uid, err := strconv.ParseInt(idparts[0], 10, 32); err == nil { - // must be a uid; take it as valid - userID = int(uid) - luser, err := idtools.LookupUID(userID) - if err != nil { - return "", "", fmt.Errorf("Uid %d has no entry in /etc/passwd: %v", userID, err) - } - username = luser.Name - if len(idparts) == 1 { - // if the uid was numeric and no gid was specified, take the uid as the gid - groupID = userID - lgrp, err := idtools.LookupGID(groupID) - if err != nil { - return "", "", fmt.Errorf("Gid %d has no entry in /etc/group: %v", groupID, err) - } - groupname = lgrp.Name - } - } else { - lookupName := idparts[0] - // special case: if the user specified "default", they want Docker to create or - // use (after creation) the "dockremap" user/group for root remapping - if lookupName == defaultIDSpecifier { - lookupName = defaultRemappedID - } - luser, err := idtools.LookupUser(lookupName) - if err != nil && idparts[0] != defaultIDSpecifier { - // error if the name requested isn't the special "dockremap" ID - return "", "", fmt.Errorf("Error during uid lookup for %q: %v", lookupName, err) - } else if err != nil { - // special case-- if the username == "default", then we have been asked - // to create a new entry pair in /etc/{passwd,group} for which the /etc/sub{uid,gid} - // ranges will be used for the user and group mappings in user namespaced containers - _, _, err := idtools.AddNamespaceRangesUser(defaultRemappedID) - if err == nil { - return defaultRemappedID, defaultRemappedID, nil - } - return "", "", fmt.Errorf("Error during %q user creation: %v", defaultRemappedID, err) - } - username = luser.Name - if len(idparts) == 1 { - // we only have a string username, and no group specified; look up gid from username as group - group, err := idtools.LookupGroup(lookupName) - if err != nil { - return "", "", fmt.Errorf("Error during gid lookup for %q: %v", lookupName, err) - } - groupID = group.Gid - groupname = group.Name - } - } - - if len(idparts) == 2 { - // groupname or gid is separately specified and must be resolved - // to an unsigned 32-bit gid - if gid, err := strconv.ParseInt(idparts[1], 10, 32); err == nil { - // must be a gid, take it as valid - groupID = int(gid) - lgrp, err := idtools.LookupGID(groupID) - if err != nil { - return "", "", fmt.Errorf("Gid %d has no entry in /etc/passwd: %v", groupID, err) - } - groupname = lgrp.Name - } else { - // not a number; attempt a lookup - if _, err := idtools.LookupGroup(idparts[1]); err != nil { - return "", "", fmt.Errorf("Error during groupname lookup for %q: %v", idparts[1], err) - } - groupname = idparts[1] - } - } - return username, groupname, nil -} - -func setupRemappedRoot(config *Config) ([]idtools.IDMap, []idtools.IDMap, error) { - if runtime.GOOS != "linux" && config.RemappedRoot != "" { - return nil, nil, fmt.Errorf("User namespaces are only supported on Linux") - } - - // if the daemon was started with remapped root option, parse - // the config option to the int uid,gid values - var ( - uidMaps, gidMaps []idtools.IDMap - ) - if config.RemappedRoot != "" { - username, groupname, err := parseRemappedRoot(config.RemappedRoot) - if err != nil { - return nil, nil, err - } - if username == "root" { - // Cannot setup user namespaces with a 1-to-1 mapping; "--root=0:0" is a no-op - // effectively - logrus.Warn("User namespaces: root cannot be remapped with itself; user namespaces are OFF") - return uidMaps, gidMaps, nil - } - logrus.Infof("User namespaces: ID ranges will be mapped to subuid/subgid ranges of: %s:%s", username, groupname) - // update remapped root setting now that we have resolved them to actual names - config.RemappedRoot = fmt.Sprintf("%s:%s", username, groupname) - - uidMaps, gidMaps, err = idtools.CreateIDMappings(username, groupname) - if err != nil { - return nil, nil, fmt.Errorf("Can't create ID mappings: %v", err) - } - } - return uidMaps, gidMaps, nil -} - -func setupDaemonRoot(config *Config, rootDir string, rootUID, rootGID int) error { - config.Root = rootDir - // the docker root metadata directory needs to have execute permissions for all users (g+x,o+x) - // so that syscalls executing as non-root, operating on subdirectories of the graph root - // (e.g. mounted layers of a container) can traverse this path. - // The user namespace support will create subdirectories for the remapped root host uid:gid - // pair owned by that same uid:gid pair for proper write access to those needed metadata and - // layer content subtrees. - if _, err := os.Stat(rootDir); err == nil { - // root current exists; verify the access bits are correct by setting them - if err = os.Chmod(rootDir, 0711); err != nil { - return err - } - } else if os.IsNotExist(err) { - // no root exists yet, create it 0711 with root:root ownership - if err := os.MkdirAll(rootDir, 0711); err != nil { - return err - } - } - - // if user namespaces are enabled we will create a subtree underneath the specified root - // with any/all specified remapped root uid/gid options on the daemon creating - // a new subdirectory with ownership set to the remapped uid/gid (so as to allow - // `chdir()` to work for containers namespaced to that uid/gid) - if config.RemappedRoot != "" { - config.Root = filepath.Join(rootDir, fmt.Sprintf("%d.%d", rootUID, rootGID)) - logrus.Debugf("Creating user namespaced daemon root: %s", config.Root) - // Create the root directory if it doesn't exist - if err := idtools.MkdirAllAs(config.Root, 0700, rootUID, rootGID); err != nil { - return fmt.Errorf("Cannot create daemon root: %s: %v", config.Root, err) - } - // we also need to verify that any pre-existing directories in the path to - // the graphroot won't block access to remapped root--if any pre-existing directory - // has strict permissions that don't allow "x", container start will fail, so - // better to warn and fail now - dirPath := config.Root - for { - dirPath = filepath.Dir(dirPath) - if dirPath == "/" { - break - } - if !idtools.CanAccess(dirPath, rootUID, rootGID) { - return fmt.Errorf("A subdirectory in your graphroot path (%s) restricts access to the remapped root uid/gid; please fix by allowing 'o+x' permissions on existing directories.", config.Root) - } - } - } - return nil -} - -// registerLinks writes the links to a file. -func (daemon *Daemon) registerLinks(container *container.Container, hostConfig *containertypes.HostConfig) error { - if hostConfig == nil || hostConfig.NetworkMode.IsUserDefined() { - return nil - } - - for _, l := range hostConfig.Links { - name, alias, err := runconfigopts.ParseLink(l) - if err != nil { - return err - } - child, err := daemon.GetContainer(name) - if err != nil { - return fmt.Errorf("Could not get container for %s", name) - } - for child.HostConfig.NetworkMode.IsContainer() { - parts := strings.SplitN(string(child.HostConfig.NetworkMode), ":", 2) - child, err = daemon.GetContainer(parts[1]) - if err != nil { - return fmt.Errorf("Could not get container for %s", parts[1]) - } - } - if child.HostConfig.NetworkMode.IsHost() { - return runconfig.ErrConflictHostNetworkAndLinks - } - if err := daemon.registerLink(container, child, alias); err != nil { - return err - } - } - - // After we load all the links into the daemon - // set them to nil on the hostconfig - return container.WriteHostConfig() -} - -// conditionalMountOnStart is a platform specific helper function during the -// container start to call mount. -func (daemon *Daemon) conditionalMountOnStart(container *container.Container) error { - return daemon.Mount(container) -} - -// conditionalUnmountOnCleanup is a platform specific helper function called -// during the cleanup of a container to unmount. -func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) error { - return daemon.Unmount(container) -} - -func (daemon *Daemon) stats(c *container.Container) (*types.StatsJSON, error) { - if !c.IsRunning() { - return nil, errNotRunning{c.ID} - } - stats, err := daemon.containerd.Stats(c.ID) - if err != nil { - return nil, err - } - s := &types.StatsJSON{} - cgs := stats.CgroupStats - if cgs != nil { - s.BlkioStats = types.BlkioStats{ - IoServiceBytesRecursive: copyBlkioEntry(cgs.BlkioStats.IoServiceBytesRecursive), - IoServicedRecursive: copyBlkioEntry(cgs.BlkioStats.IoServicedRecursive), - IoQueuedRecursive: copyBlkioEntry(cgs.BlkioStats.IoQueuedRecursive), - IoServiceTimeRecursive: copyBlkioEntry(cgs.BlkioStats.IoServiceTimeRecursive), - IoWaitTimeRecursive: copyBlkioEntry(cgs.BlkioStats.IoWaitTimeRecursive), - IoMergedRecursive: copyBlkioEntry(cgs.BlkioStats.IoMergedRecursive), - IoTimeRecursive: copyBlkioEntry(cgs.BlkioStats.IoTimeRecursive), - SectorsRecursive: copyBlkioEntry(cgs.BlkioStats.SectorsRecursive), - } - cpu := cgs.CpuStats - s.CPUStats = types.CPUStats{ - CPUUsage: types.CPUUsage{ - TotalUsage: cpu.CpuUsage.TotalUsage, - PercpuUsage: cpu.CpuUsage.PercpuUsage, - UsageInKernelmode: cpu.CpuUsage.UsageInKernelmode, - UsageInUsermode: cpu.CpuUsage.UsageInUsermode, - }, - ThrottlingData: types.ThrottlingData{ - Periods: cpu.ThrottlingData.Periods, - ThrottledPeriods: cpu.ThrottlingData.ThrottledPeriods, - ThrottledTime: cpu.ThrottlingData.ThrottledTime, - }, - } - mem := cgs.MemoryStats.Usage - s.MemoryStats = types.MemoryStats{ - Usage: mem.Usage, - MaxUsage: mem.MaxUsage, - Stats: cgs.MemoryStats.Stats, - Failcnt: mem.Failcnt, - Limit: mem.Limit, - } - // if the container does not set memory limit, use the machineMemory - if mem.Limit > daemon.statsCollector.machineMemory && daemon.statsCollector.machineMemory > 0 { - s.MemoryStats.Limit = daemon.statsCollector.machineMemory - } - if cgs.PidsStats != nil { - s.PidsStats = types.PidsStats{ - Current: cgs.PidsStats.Current, - } - } - } - s.Read, err = ptypes.Timestamp(stats.Timestamp) - if err != nil { - return nil, err - } - return s, nil -} - -// setDefaultIsolation determines the default isolation mode for the -// daemon to run in. This is only applicable on Windows -func (daemon *Daemon) setDefaultIsolation() error { - return nil -} - -func rootFSToAPIType(rootfs *image.RootFS) types.RootFS { - var layers []string - for _, l := range rootfs.DiffIDs { - layers = append(layers, l.String()) - } - return types.RootFS{ - Type: rootfs.Type, - Layers: layers, - } -} - -// setupDaemonProcess sets various settings for the daemon's process -func setupDaemonProcess(config *Config) error { - // setup the daemons oom_score_adj - return setupOOMScoreAdj(config.OOMScoreAdjust) -} - -func setupOOMScoreAdj(score int) error { - f, err := os.OpenFile("/proc/self/oom_score_adj", os.O_WRONLY, 0) - if err != nil { - return err - } - - stringScore := strconv.Itoa(score) - _, err = f.WriteString(stringScore) - if os.IsPermission(err) { - // Setting oom_score_adj does not work in an - // unprivileged container. Ignore the error, but log - // it if we appear not to be in that situation. - if !rsystem.RunningInUserNS() { - logrus.Debugf("Permission denied writing %q to /proc/self/oom_score_adj", stringScore) - } - return nil - } - f.Close() - return err -} - -func (daemon *Daemon) initCgroupsPath(path string) error { - if path == "/" || path == "." { - return nil - } - - if daemon.configStore.CPURealtimePeriod == 0 && daemon.configStore.CPURealtimeRuntime == 0 { - return nil - } - - // Recursively create cgroup to ensure that the system and all parent cgroups have values set - // for the period and runtime as this limits what the children can be set to. - daemon.initCgroupsPath(filepath.Dir(path)) - - _, root, err := cgroups.FindCgroupMountpointAndRoot("cpu") - if err != nil { - return err - } - - path = filepath.Join(root, path) - sysinfo := sysinfo.New(true) - if sysinfo.CPURealtimePeriod && daemon.configStore.CPURealtimePeriod != 0 { - if err := os.MkdirAll(path, 0755); err != nil && !os.IsExist(err) { - return err - } - if err := ioutil.WriteFile(filepath.Join(path, "cpu.rt_period_us"), []byte(strconv.FormatInt(daemon.configStore.CPURealtimePeriod, 10)), 0700); err != nil { - return err - } - } - if sysinfo.CPURealtimeRuntime && daemon.configStore.CPURealtimeRuntime != 0 { - if err := os.MkdirAll(path, 0755); err != nil && !os.IsExist(err) { - return err - } - if err := ioutil.WriteFile(filepath.Join(path, "cpu.rt_runtime_us"), []byte(strconv.FormatInt(daemon.configStore.CPURealtimeRuntime, 10)), 0700); err != nil { - return err - } - } - return nil -} - -func (daemon *Daemon) setupSeccompProfile() error { - if daemon.configStore.SeccompProfile != "" { - daemon.seccompProfilePath = daemon.configStore.SeccompProfile - b, err := ioutil.ReadFile(daemon.configStore.SeccompProfile) - if err != nil { - return fmt.Errorf("opening seccomp profile (%s) failed: %v", daemon.configStore.SeccompProfile, err) - } - daemon.seccompProfile = b - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/daemon_unix_test.go b/vendor/github.com/docker/docker/daemon/daemon_unix_test.go deleted file mode 100644 index 6250d35..0000000 --- a/vendor/github.com/docker/docker/daemon/daemon_unix_test.go +++ /dev/null @@ -1,283 +0,0 @@ -// +build !windows,!solaris - -package daemon - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" - - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/volume" - "github.com/docker/docker/volume/drivers" - "github.com/docker/docker/volume/local" - "github.com/docker/docker/volume/store" -) - -// Unix test as uses settings which are not available on Windows -func TestAdjustCPUShares(t *testing.T) { - tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - daemon := &Daemon{ - repository: tmp, - root: tmp, - } - - hostConfig := &containertypes.HostConfig{ - Resources: containertypes.Resources{CPUShares: linuxMinCPUShares - 1}, - } - daemon.adaptContainerSettings(hostConfig, true) - if hostConfig.CPUShares != linuxMinCPUShares { - t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares) - } - - hostConfig.CPUShares = linuxMaxCPUShares + 1 - daemon.adaptContainerSettings(hostConfig, true) - if hostConfig.CPUShares != linuxMaxCPUShares { - t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares) - } - - hostConfig.CPUShares = 0 - daemon.adaptContainerSettings(hostConfig, true) - if hostConfig.CPUShares != 0 { - t.Error("Expected CPUShares to be unchanged") - } - - hostConfig.CPUShares = 1024 - daemon.adaptContainerSettings(hostConfig, true) - if hostConfig.CPUShares != 1024 { - t.Error("Expected CPUShares to be unchanged") - } -} - -// Unix test as uses settings which are not available on Windows -func TestAdjustCPUSharesNoAdjustment(t *testing.T) { - tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - daemon := &Daemon{ - repository: tmp, - root: tmp, - } - - hostConfig := &containertypes.HostConfig{ - Resources: containertypes.Resources{CPUShares: linuxMinCPUShares - 1}, - } - daemon.adaptContainerSettings(hostConfig, false) - if hostConfig.CPUShares != linuxMinCPUShares-1 { - t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares-1) - } - - hostConfig.CPUShares = linuxMaxCPUShares + 1 - daemon.adaptContainerSettings(hostConfig, false) - if hostConfig.CPUShares != linuxMaxCPUShares+1 { - t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares+1) - } - - hostConfig.CPUShares = 0 - daemon.adaptContainerSettings(hostConfig, false) - if hostConfig.CPUShares != 0 { - t.Error("Expected CPUShares to be unchanged") - } - - hostConfig.CPUShares = 1024 - daemon.adaptContainerSettings(hostConfig, false) - if hostConfig.CPUShares != 1024 { - t.Error("Expected CPUShares to be unchanged") - } -} - -// Unix test as uses settings which are not available on Windows -func TestParseSecurityOptWithDeprecatedColon(t *testing.T) { - container := &container.Container{} - config := &containertypes.HostConfig{} - - // test apparmor - config.SecurityOpt = []string{"apparmor=test_profile"} - if err := parseSecurityOpt(container, config); err != nil { - t.Fatalf("Unexpected parseSecurityOpt error: %v", err) - } - if container.AppArmorProfile != "test_profile" { - t.Fatalf("Unexpected AppArmorProfile, expected: \"test_profile\", got %q", container.AppArmorProfile) - } - - // test seccomp - sp := "/path/to/seccomp_test.json" - config.SecurityOpt = []string{"seccomp=" + sp} - if err := parseSecurityOpt(container, config); err != nil { - t.Fatalf("Unexpected parseSecurityOpt error: %v", err) - } - if container.SeccompProfile != sp { - t.Fatalf("Unexpected AppArmorProfile, expected: %q, got %q", sp, container.SeccompProfile) - } - - // test valid label - config.SecurityOpt = []string{"label=user:USER"} - if err := parseSecurityOpt(container, config); err != nil { - t.Fatalf("Unexpected parseSecurityOpt error: %v", err) - } - - // test invalid label - config.SecurityOpt = []string{"label"} - if err := parseSecurityOpt(container, config); err == nil { - t.Fatal("Expected parseSecurityOpt error, got nil") - } - - // test invalid opt - config.SecurityOpt = []string{"test"} - if err := parseSecurityOpt(container, config); err == nil { - t.Fatal("Expected parseSecurityOpt error, got nil") - } -} - -func TestParseSecurityOpt(t *testing.T) { - container := &container.Container{} - config := &containertypes.HostConfig{} - - // test apparmor - config.SecurityOpt = []string{"apparmor=test_profile"} - if err := parseSecurityOpt(container, config); err != nil { - t.Fatalf("Unexpected parseSecurityOpt error: %v", err) - } - if container.AppArmorProfile != "test_profile" { - t.Fatalf("Unexpected AppArmorProfile, expected: \"test_profile\", got %q", container.AppArmorProfile) - } - - // test seccomp - sp := "/path/to/seccomp_test.json" - config.SecurityOpt = []string{"seccomp=" + sp} - if err := parseSecurityOpt(container, config); err != nil { - t.Fatalf("Unexpected parseSecurityOpt error: %v", err) - } - if container.SeccompProfile != sp { - t.Fatalf("Unexpected SeccompProfile, expected: %q, got %q", sp, container.SeccompProfile) - } - - // test valid label - config.SecurityOpt = []string{"label=user:USER"} - if err := parseSecurityOpt(container, config); err != nil { - t.Fatalf("Unexpected parseSecurityOpt error: %v", err) - } - - // test invalid label - config.SecurityOpt = []string{"label"} - if err := parseSecurityOpt(container, config); err == nil { - t.Fatal("Expected parseSecurityOpt error, got nil") - } - - // test invalid opt - config.SecurityOpt = []string{"test"} - if err := parseSecurityOpt(container, config); err == nil { - t.Fatal("Expected parseSecurityOpt error, got nil") - } -} - -func TestNetworkOptions(t *testing.T) { - daemon := &Daemon{} - dconfigCorrect := &Config{ - CommonConfig: CommonConfig{ - ClusterStore: "consul://localhost:8500", - ClusterAdvertise: "192.168.0.1:8000", - }, - } - - if _, err := daemon.networkOptions(dconfigCorrect, nil, nil); err != nil { - t.Fatalf("Expect networkOptions success, got error: %v", err) - } - - dconfigWrong := &Config{ - CommonConfig: CommonConfig{ - ClusterStore: "consul://localhost:8500://test://bbb", - }, - } - - if _, err := daemon.networkOptions(dconfigWrong, nil, nil); err == nil { - t.Fatalf("Expected networkOptions error, got nil") - } -} - -func TestMigratePre17Volumes(t *testing.T) { - rootDir, err := ioutil.TempDir("", "test-daemon-volumes") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(rootDir) - - volumeRoot := filepath.Join(rootDir, "volumes") - err = os.MkdirAll(volumeRoot, 0755) - if err != nil { - t.Fatal(err) - } - - containerRoot := filepath.Join(rootDir, "containers") - cid := "1234" - err = os.MkdirAll(filepath.Join(containerRoot, cid), 0755) - - vid := "5678" - vfsPath := filepath.Join(rootDir, "vfs", "dir", vid) - err = os.MkdirAll(vfsPath, 0755) - if err != nil { - t.Fatal(err) - } - - config := []byte(` - { - "ID": "` + cid + `", - "Volumes": { - "/foo": "` + vfsPath + `", - "/bar": "/foo", - "/quux": "/quux" - }, - "VolumesRW": { - "/foo": true, - "/bar": true, - "/quux": false - } - } - `) - - volStore, err := store.New(volumeRoot) - if err != nil { - t.Fatal(err) - } - drv, err := local.New(volumeRoot, 0, 0) - if err != nil { - t.Fatal(err) - } - volumedrivers.Register(drv, volume.DefaultDriverName) - - daemon := &Daemon{root: rootDir, repository: containerRoot, volumes: volStore} - err = ioutil.WriteFile(filepath.Join(containerRoot, cid, "config.v2.json"), config, 600) - if err != nil { - t.Fatal(err) - } - c, err := daemon.load(cid) - if err != nil { - t.Fatal(err) - } - if err := daemon.verifyVolumesInfo(c); err != nil { - t.Fatal(err) - } - - expected := map[string]volume.MountPoint{ - "/foo": {Destination: "/foo", RW: true, Name: vid}, - "/bar": {Source: "/foo", Destination: "/bar", RW: true}, - "/quux": {Source: "/quux", Destination: "/quux", RW: false}, - } - for id, mp := range c.MountPoints { - x, exists := expected[id] - if !exists { - t.Fatal("volume not migrated") - } - if mp.Source != x.Source || mp.Destination != x.Destination || mp.RW != x.RW || mp.Name != x.Name { - t.Fatalf("got unexpected mountpoint, expected: %+v, got: %+v", x, mp) - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/daemon_unsupported.go b/vendor/github.com/docker/docker/daemon/daemon_unsupported.go deleted file mode 100644 index cb1acf6..0000000 --- a/vendor/github.com/docker/docker/daemon/daemon_unsupported.go +++ /dev/null @@ -1,5 +0,0 @@ -// +build !linux,!freebsd,!windows,!solaris - -package daemon - -const platformSupported = false diff --git a/vendor/github.com/docker/docker/daemon/daemon_windows.go b/vendor/github.com/docker/docker/daemon/daemon_windows.go deleted file mode 100644 index 51ad68b..0000000 --- a/vendor/github.com/docker/docker/daemon/daemon_windows.go +++ /dev/null @@ -1,604 +0,0 @@ -package daemon - -import ( - "fmt" - "os" - "strings" - - "github.com/Microsoft/hcsshim" - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/image" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/parsers" - "github.com/docker/docker/pkg/platform" - "github.com/docker/docker/pkg/sysinfo" - "github.com/docker/docker/pkg/system" - "github.com/docker/docker/runconfig" - "github.com/docker/libnetwork" - nwconfig "github.com/docker/libnetwork/config" - "github.com/docker/libnetwork/datastore" - winlibnetwork "github.com/docker/libnetwork/drivers/windows" - "github.com/docker/libnetwork/netlabel" - "github.com/docker/libnetwork/options" - blkiodev "github.com/opencontainers/runc/libcontainer/configs" - "golang.org/x/sys/windows" -) - -const ( - defaultNetworkSpace = "172.16.0.0/12" - platformSupported = true - windowsMinCPUShares = 1 - windowsMaxCPUShares = 10000 - windowsMinCPUPercent = 1 - windowsMaxCPUPercent = 100 - windowsMinCPUCount = 1 -) - -func getBlkioWeightDevices(config *containertypes.HostConfig) ([]blkiodev.WeightDevice, error) { - return nil, nil -} - -func parseSecurityOpt(container *container.Container, config *containertypes.HostConfig) error { - return nil -} - -func getBlkioReadIOpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) { - return nil, nil -} - -func getBlkioWriteIOpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) { - return nil, nil -} - -func getBlkioReadBpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) { - return nil, nil -} - -func getBlkioWriteBpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) { - return nil, nil -} - -func (daemon *Daemon) getLayerInit() func(string) error { - return nil -} - -func checkKernel() error { - return nil -} - -func (daemon *Daemon) getCgroupDriver() string { - return "" -} - -// adaptContainerSettings is called during container creation to modify any -// settings necessary in the HostConfig structure. -func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConfig, adjustCPUShares bool) error { - if hostConfig == nil { - return nil - } - - return nil -} - -func verifyContainerResources(resources *containertypes.Resources, isHyperv bool) ([]string, error) { - warnings := []string{} - - if !isHyperv { - // The processor resource controls are mutually exclusive on - // Windows Server Containers, the order of precedence is - // CPUCount first, then CPUShares, and CPUPercent last. - if resources.CPUCount > 0 { - if resources.CPUShares > 0 { - warnings = append(warnings, "Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded") - logrus.Warn("Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded") - resources.CPUShares = 0 - } - if resources.CPUPercent > 0 { - warnings = append(warnings, "Conflicting options: CPU count takes priority over CPU percent on Windows Server Containers. CPU percent discarded") - logrus.Warn("Conflicting options: CPU count takes priority over CPU percent on Windows Server Containers. CPU percent discarded") - resources.CPUPercent = 0 - } - } else if resources.CPUShares > 0 { - if resources.CPUPercent > 0 { - warnings = append(warnings, "Conflicting options: CPU shares takes priority over CPU percent on Windows Server Containers. CPU percent discarded") - logrus.Warn("Conflicting options: CPU shares takes priority over CPU percent on Windows Server Containers. CPU percent discarded") - resources.CPUPercent = 0 - } - } - } - - if resources.CPUShares < 0 || resources.CPUShares > windowsMaxCPUShares { - return warnings, fmt.Errorf("range of CPUShares is from %d to %d", windowsMinCPUShares, windowsMaxCPUShares) - } - if resources.CPUPercent < 0 || resources.CPUPercent > windowsMaxCPUPercent { - return warnings, fmt.Errorf("range of CPUPercent is from %d to %d", windowsMinCPUPercent, windowsMaxCPUPercent) - } - if resources.CPUCount < 0 { - return warnings, fmt.Errorf("invalid CPUCount: CPUCount cannot be negative") - } - - if resources.NanoCPUs > 0 && resources.CPUPercent > 0 { - return warnings, fmt.Errorf("conflicting options: Nano CPUs and CPU Percent cannot both be set") - } - if resources.NanoCPUs > 0 && resources.CPUShares > 0 { - return warnings, fmt.Errorf("conflicting options: Nano CPUs and CPU Shares cannot both be set") - } - // The precision we could get is 0.01, because on Windows we have to convert to CPUPercent. - // We don't set the lower limit here and it is up to the underlying platform (e.g., Windows) to return an error. - if resources.NanoCPUs < 0 || resources.NanoCPUs > int64(sysinfo.NumCPU())*1e9 { - return warnings, fmt.Errorf("range of CPUs is from 0.01 to %d.00, as there are only %d CPUs available", sysinfo.NumCPU(), sysinfo.NumCPU()) - } - - if len(resources.BlkioDeviceReadBps) > 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support BlkioDeviceReadBps") - } - if len(resources.BlkioDeviceReadIOps) > 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support BlkioDeviceReadIOps") - } - if len(resources.BlkioDeviceWriteBps) > 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support BlkioDeviceWriteBps") - } - if len(resources.BlkioDeviceWriteIOps) > 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support BlkioDeviceWriteIOps") - } - if resources.BlkioWeight > 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support BlkioWeight") - } - if len(resources.BlkioWeightDevice) > 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support BlkioWeightDevice") - } - if resources.CgroupParent != "" { - return warnings, fmt.Errorf("invalid option: Windows does not support CgroupParent") - } - if resources.CPUPeriod != 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support CPUPeriod") - } - if resources.CpusetCpus != "" { - return warnings, fmt.Errorf("invalid option: Windows does not support CpusetCpus") - } - if resources.CpusetMems != "" { - return warnings, fmt.Errorf("invalid option: Windows does not support CpusetMems") - } - if resources.KernelMemory != 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support KernelMemory") - } - if resources.MemoryReservation != 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support MemoryReservation") - } - if resources.MemorySwap != 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support MemorySwap") - } - if resources.MemorySwappiness != nil && *resources.MemorySwappiness != -1 { - return warnings, fmt.Errorf("invalid option: Windows does not support MemorySwappiness") - } - if resources.OomKillDisable != nil && *resources.OomKillDisable { - return warnings, fmt.Errorf("invalid option: Windows does not support OomKillDisable") - } - if resources.PidsLimit != 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support PidsLimit") - } - if len(resources.Ulimits) != 0 { - return warnings, fmt.Errorf("invalid option: Windows does not support Ulimits") - } - return warnings, nil -} - -// verifyPlatformContainerSettings performs platform-specific validation of the -// hostconfig and config structures. -func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) { - warnings := []string{} - - hyperv := daemon.runAsHyperVContainer(hostConfig) - if !hyperv && system.IsWindowsClient() { - // @engine maintainers. This block should not be removed. It partially enforces licensing - // restrictions on Windows. Ping @jhowardmsft if there are concerns or PRs to change this. - return warnings, fmt.Errorf("Windows client operating systems only support Hyper-V containers") - } - - w, err := verifyContainerResources(&hostConfig.Resources, hyperv) - warnings = append(warnings, w...) - if err != nil { - return warnings, err - } - return warnings, nil -} - -// platformReload update configuration with platform specific options -func (daemon *Daemon) platformReload(config *Config) map[string]string { - return map[string]string{} -} - -// verifyDaemonSettings performs validation of daemon config struct -func verifyDaemonSettings(config *Config) error { - return nil -} - -// checkSystem validates platform-specific requirements -func checkSystem() error { - // Validate the OS version. Note that docker.exe must be manifested for this - // call to return the correct version. - osv := system.GetOSVersion() - if osv.MajorVersion < 10 { - return fmt.Errorf("This version of Windows does not support the docker daemon") - } - if osv.Build < 14393 { - return fmt.Errorf("The docker daemon requires build 14393 or later of Windows Server 2016 or Windows 10") - } - - vmcompute := windows.NewLazySystemDLL("vmcompute.dll") - if vmcompute.Load() != nil { - return fmt.Errorf("Failed to load vmcompute.dll. Ensure that the Containers role is installed.") - } - return nil -} - -// configureKernelSecuritySupport configures and validate security support for the kernel -func configureKernelSecuritySupport(config *Config, driverName string) error { - return nil -} - -// configureMaxThreads sets the Go runtime max threads threshold -func configureMaxThreads(config *Config) error { - return nil -} - -func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[string]interface{}) (libnetwork.NetworkController, error) { - netOptions, err := daemon.networkOptions(config, nil, nil) - if err != nil { - return nil, err - } - controller, err := libnetwork.New(netOptions...) - if err != nil { - return nil, fmt.Errorf("error obtaining controller instance: %v", err) - } - - hnsresponse, err := hcsshim.HNSListNetworkRequest("GET", "", "") - if err != nil { - return nil, err - } - - // Remove networks not present in HNS - for _, v := range controller.Networks() { - options := v.Info().DriverOptions() - hnsid := options[winlibnetwork.HNSID] - found := false - - for _, v := range hnsresponse { - if v.Id == hnsid { - found = true - break - } - } - - if !found { - // global networks should not be deleted by local HNS - if v.Info().Scope() != datastore.GlobalScope { - err = v.Delete() - if err != nil { - logrus.Errorf("Error occurred when removing network %v", err) - } - } - } - } - - _, err = controller.NewNetwork("null", "none", "", libnetwork.NetworkOptionPersist(false)) - if err != nil { - return nil, err - } - - defaultNetworkExists := false - - if network, err := controller.NetworkByName(runconfig.DefaultDaemonNetworkMode().NetworkName()); err == nil { - options := network.Info().DriverOptions() - for _, v := range hnsresponse { - if options[winlibnetwork.HNSID] == v.Id { - defaultNetworkExists = true - break - } - } - } - - // discover and add HNS networks to windows - // network that exist are removed and added again - for _, v := range hnsresponse { - var n libnetwork.Network - s := func(current libnetwork.Network) bool { - options := current.Info().DriverOptions() - if options[winlibnetwork.HNSID] == v.Id { - n = current - return true - } - return false - } - - controller.WalkNetworks(s) - if n != nil { - // global networks should not be deleted by local HNS - if n.Info().Scope() == datastore.GlobalScope { - continue - } - v.Name = n.Name() - // This will not cause network delete from HNS as the network - // is not yet populated in the libnetwork windows driver - n.Delete() - } - - netOption := map[string]string{ - winlibnetwork.NetworkName: v.Name, - winlibnetwork.HNSID: v.Id, - } - - v4Conf := []*libnetwork.IpamConf{} - for _, subnet := range v.Subnets { - ipamV4Conf := libnetwork.IpamConf{} - ipamV4Conf.PreferredPool = subnet.AddressPrefix - ipamV4Conf.Gateway = subnet.GatewayAddress - v4Conf = append(v4Conf, &ipamV4Conf) - } - - name := v.Name - - // If there is no nat network create one from the first NAT network - // encountered - if !defaultNetworkExists && runconfig.DefaultDaemonNetworkMode() == containertypes.NetworkMode(strings.ToLower(v.Type)) { - name = runconfig.DefaultDaemonNetworkMode().NetworkName() - defaultNetworkExists = true - } - - v6Conf := []*libnetwork.IpamConf{} - _, err := controller.NewNetwork(strings.ToLower(v.Type), name, "", - libnetwork.NetworkOptionGeneric(options.Generic{ - netlabel.GenericData: netOption, - }), - libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil), - ) - - if err != nil { - logrus.Errorf("Error occurred when creating network %v", err) - } - } - - if !config.DisableBridge { - // Initialize default driver "bridge" - if err := initBridgeDriver(controller, config); err != nil { - return nil, err - } - } - - return controller, nil -} - -func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error { - if _, err := controller.NetworkByName(runconfig.DefaultDaemonNetworkMode().NetworkName()); err == nil { - return nil - } - - netOption := map[string]string{ - winlibnetwork.NetworkName: runconfig.DefaultDaemonNetworkMode().NetworkName(), - } - - var ipamOption libnetwork.NetworkOption - var subnetPrefix string - - if config.bridgeConfig.FixedCIDR != "" { - subnetPrefix = config.bridgeConfig.FixedCIDR - } else { - // TP5 doesn't support properly detecting subnet - osv := system.GetOSVersion() - if osv.Build < 14360 { - subnetPrefix = defaultNetworkSpace - } - } - - if subnetPrefix != "" { - ipamV4Conf := libnetwork.IpamConf{} - ipamV4Conf.PreferredPool = subnetPrefix - v4Conf := []*libnetwork.IpamConf{&ipamV4Conf} - v6Conf := []*libnetwork.IpamConf{} - ipamOption = libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil) - } - - _, err := controller.NewNetwork(string(runconfig.DefaultDaemonNetworkMode()), runconfig.DefaultDaemonNetworkMode().NetworkName(), "", - libnetwork.NetworkOptionGeneric(options.Generic{ - netlabel.GenericData: netOption, - }), - ipamOption, - ) - - if err != nil { - return fmt.Errorf("Error creating default network: %v", err) - } - - return nil -} - -// registerLinks sets up links between containers and writes the -// configuration out for persistence. As of Windows TP4, links are not supported. -func (daemon *Daemon) registerLinks(container *container.Container, hostConfig *containertypes.HostConfig) error { - return nil -} - -func (daemon *Daemon) cleanupMountsByID(in string) error { - return nil -} - -func (daemon *Daemon) cleanupMounts() error { - return nil -} - -func setupRemappedRoot(config *Config) ([]idtools.IDMap, []idtools.IDMap, error) { - return nil, nil, nil -} - -func setupDaemonRoot(config *Config, rootDir string, rootUID, rootGID int) error { - config.Root = rootDir - // Create the root directory if it doesn't exists - if err := system.MkdirAllWithACL(config.Root, 0); err != nil && !os.IsExist(err) { - return err - } - return nil -} - -// runasHyperVContainer returns true if we are going to run as a Hyper-V container -func (daemon *Daemon) runAsHyperVContainer(hostConfig *containertypes.HostConfig) bool { - if hostConfig.Isolation.IsDefault() { - // Container is set to use the default, so take the default from the daemon configuration - return daemon.defaultIsolation.IsHyperV() - } - - // Container is requesting an isolation mode. Honour it. - return hostConfig.Isolation.IsHyperV() - -} - -// conditionalMountOnStart is a platform specific helper function during the -// container start to call mount. -func (daemon *Daemon) conditionalMountOnStart(container *container.Container) error { - // We do not mount if a Hyper-V container - if !daemon.runAsHyperVContainer(container.HostConfig) { - return daemon.Mount(container) - } - return nil -} - -// conditionalUnmountOnCleanup is a platform specific helper function called -// during the cleanup of a container to unmount. -func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) error { - // We do not unmount if a Hyper-V container - if !daemon.runAsHyperVContainer(container.HostConfig) { - return daemon.Unmount(container) - } - return nil -} - -func driverOptions(config *Config) []nwconfig.Option { - return []nwconfig.Option{} -} - -func (daemon *Daemon) stats(c *container.Container) (*types.StatsJSON, error) { - if !c.IsRunning() { - return nil, errNotRunning{c.ID} - } - - // Obtain the stats from HCS via libcontainerd - stats, err := daemon.containerd.Stats(c.ID) - if err != nil { - return nil, err - } - - // Start with an empty structure - s := &types.StatsJSON{} - - // Populate the CPU/processor statistics - s.CPUStats = types.CPUStats{ - CPUUsage: types.CPUUsage{ - TotalUsage: stats.Processor.TotalRuntime100ns, - UsageInKernelmode: stats.Processor.RuntimeKernel100ns, - UsageInUsermode: stats.Processor.RuntimeKernel100ns, - }, - } - - // Populate the memory statistics - s.MemoryStats = types.MemoryStats{ - Commit: stats.Memory.UsageCommitBytes, - CommitPeak: stats.Memory.UsageCommitPeakBytes, - PrivateWorkingSet: stats.Memory.UsagePrivateWorkingSetBytes, - } - - // Populate the storage statistics - s.StorageStats = types.StorageStats{ - ReadCountNormalized: stats.Storage.ReadCountNormalized, - ReadSizeBytes: stats.Storage.ReadSizeBytes, - WriteCountNormalized: stats.Storage.WriteCountNormalized, - WriteSizeBytes: stats.Storage.WriteSizeBytes, - } - - // Populate the network statistics - s.Networks = make(map[string]types.NetworkStats) - - for _, nstats := range stats.Network { - s.Networks[nstats.EndpointId] = types.NetworkStats{ - RxBytes: nstats.BytesReceived, - RxPackets: nstats.PacketsReceived, - RxDropped: nstats.DroppedPacketsIncoming, - TxBytes: nstats.BytesSent, - TxPackets: nstats.PacketsSent, - TxDropped: nstats.DroppedPacketsOutgoing, - } - } - - // Set the timestamp - s.Stats.Read = stats.Timestamp - s.Stats.NumProcs = platform.NumProcs() - - return s, nil -} - -// setDefaultIsolation determine the default isolation mode for the -// daemon to run in. This is only applicable on Windows -func (daemon *Daemon) setDefaultIsolation() error { - daemon.defaultIsolation = containertypes.Isolation("process") - // On client SKUs, default to Hyper-V - if system.IsWindowsClient() { - daemon.defaultIsolation = containertypes.Isolation("hyperv") - } - for _, option := range daemon.configStore.ExecOptions { - key, val, err := parsers.ParseKeyValueOpt(option) - if err != nil { - return err - } - key = strings.ToLower(key) - switch key { - - case "isolation": - if !containertypes.Isolation(val).IsValid() { - return fmt.Errorf("Invalid exec-opt value for 'isolation':'%s'", val) - } - if containertypes.Isolation(val).IsHyperV() { - daemon.defaultIsolation = containertypes.Isolation("hyperv") - } - if containertypes.Isolation(val).IsProcess() { - if system.IsWindowsClient() { - // @engine maintainers. This block should not be removed. It partially enforces licensing - // restrictions on Windows. Ping @jhowardmsft if there are concerns or PRs to change this. - return fmt.Errorf("Windows client operating systems only support Hyper-V containers") - } - daemon.defaultIsolation = containertypes.Isolation("process") - } - default: - return fmt.Errorf("Unrecognised exec-opt '%s'\n", key) - } - } - - logrus.Infof("Windows default isolation mode: %s", daemon.defaultIsolation) - return nil -} - -func rootFSToAPIType(rootfs *image.RootFS) types.RootFS { - var layers []string - for _, l := range rootfs.DiffIDs { - layers = append(layers, l.String()) - } - return types.RootFS{ - Type: rootfs.Type, - Layers: layers, - } -} - -func setupDaemonProcess(config *Config) error { - return nil -} - -// verifyVolumesInfo is a no-op on windows. -// This is called during daemon initialization to migrate volumes from pre-1.7. -// volumes were not supported on windows pre-1.7 -func (daemon *Daemon) verifyVolumesInfo(container *container.Container) error { - return nil -} - -func (daemon *Daemon) setupSeccompProfile() error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/debugtrap.go b/vendor/github.com/docker/docker/daemon/debugtrap.go deleted file mode 100644 index 209048b..0000000 --- a/vendor/github.com/docker/docker/daemon/debugtrap.go +++ /dev/null @@ -1,62 +0,0 @@ -package daemon - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "time" - - "github.com/davecgh/go-spew/spew" - "github.com/pkg/errors" -) - -const dataStructuresLogNameTemplate = "daemon-data-%s.log" - -// dumpDaemon appends the daemon datastructures into file in dir and returns full path -// to that file. -func (d *Daemon) dumpDaemon(dir string) (string, error) { - // Ensure we recover from a panic as we are doing this without any locking - defer func() { - recover() - }() - - path := filepath.Join(dir, fmt.Sprintf(dataStructuresLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1))) - f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666) - if err != nil { - return "", errors.Wrap(err, "failed to open file to write the daemon datastructure dump") - } - defer f.Close() - - dump := struct { - containers interface{} - names interface{} - links interface{} - execs interface{} - volumes interface{} - images interface{} - layers interface{} - imageReferences interface{} - downloads interface{} - uploads interface{} - registry interface{} - plugins interface{} - }{ - containers: d.containers, - execs: d.execCommands, - volumes: d.volumes, - images: d.imageStore, - layers: d.layerStore, - imageReferences: d.referenceStore, - downloads: d.downloadManager, - uploads: d.uploadManager, - registry: d.RegistryService, - plugins: d.PluginStore, - names: d.nameIndex, - links: d.linkIndex, - } - - spew.Fdump(f, dump) // Does not return an error - f.Sync() - return path, nil -} diff --git a/vendor/github.com/docker/docker/daemon/debugtrap_unix.go b/vendor/github.com/docker/docker/daemon/debugtrap_unix.go deleted file mode 100644 index d650eb7..0000000 --- a/vendor/github.com/docker/docker/daemon/debugtrap_unix.go +++ /dev/null @@ -1,33 +0,0 @@ -// +build !windows - -package daemon - -import ( - "os" - "os/signal" - "syscall" - - "github.com/Sirupsen/logrus" - stackdump "github.com/docker/docker/pkg/signal" -) - -func (d *Daemon) setupDumpStackTrap(root string) { - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGUSR1) - go func() { - for range c { - path, err := stackdump.DumpStacks(root) - if err != nil { - logrus.WithError(err).Error("failed to write goroutines dump") - } else { - logrus.Infof("goroutine stacks written to %s", path) - } - path, err = d.dumpDaemon(root) - if err != nil { - logrus.WithError(err).Error("failed to write daemon datastructure dump") - } else { - logrus.Infof("daemon datastructure dump written to %s", path) - } - } - }() -} diff --git a/vendor/github.com/docker/docker/daemon/debugtrap_unsupported.go b/vendor/github.com/docker/docker/daemon/debugtrap_unsupported.go deleted file mode 100644 index f5b9170..0000000 --- a/vendor/github.com/docker/docker/daemon/debugtrap_unsupported.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build !linux,!darwin,!freebsd,!windows,!solaris - -package daemon - -func (d *Daemon) setupDumpStackTrap(_ string) { - return -} diff --git a/vendor/github.com/docker/docker/daemon/debugtrap_windows.go b/vendor/github.com/docker/docker/daemon/debugtrap_windows.go deleted file mode 100644 index fb20c9d..0000000 --- a/vendor/github.com/docker/docker/daemon/debugtrap_windows.go +++ /dev/null @@ -1,52 +0,0 @@ -package daemon - -import ( - "fmt" - "os" - "syscall" - "unsafe" - - winio "github.com/Microsoft/go-winio" - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/signal" - "github.com/docker/docker/pkg/system" -) - -func (d *Daemon) setupDumpStackTrap(root string) { - // Windows does not support signals like *nix systems. So instead of - // trapping on SIGUSR1 to dump stacks, we wait on a Win32 event to be - // signaled. ACL'd to builtin administrators and local system - ev := "Global\\docker-daemon-" + fmt.Sprint(os.Getpid()) - sd, err := winio.SddlToSecurityDescriptor("D:P(A;;GA;;;BA)(A;;GA;;;SY)") - if err != nil { - logrus.Errorf("failed to get security descriptor for debug stackdump event %s: %s", ev, err.Error()) - return - } - var sa syscall.SecurityAttributes - sa.Length = uint32(unsafe.Sizeof(sa)) - sa.InheritHandle = 1 - sa.SecurityDescriptor = uintptr(unsafe.Pointer(&sd[0])) - h, err := system.CreateEvent(&sa, false, false, ev) - if h == 0 || err != nil { - logrus.Errorf("failed to create debug stackdump event %s: %s", ev, err.Error()) - return - } - go func() { - logrus.Debugf("Stackdump - waiting signal at %s", ev) - for { - syscall.WaitForSingleObject(h, syscall.INFINITE) - path, err := signal.DumpStacks(root) - if err != nil { - logrus.WithError(err).Error("failed to write goroutines dump") - } else { - logrus.Infof("goroutine stacks written to %s", path) - } - path, err = d.dumpDaemon(root) - if err != nil { - logrus.WithError(err).Error("failed to write daemon datastructure dump") - } else { - logrus.Infof("daemon datastructure dump written to %s", path) - } - } - }() -} diff --git a/vendor/github.com/docker/docker/daemon/delete.go b/vendor/github.com/docker/docker/daemon/delete.go deleted file mode 100644 index 6b622bd..0000000 --- a/vendor/github.com/docker/docker/daemon/delete.go +++ /dev/null @@ -1,168 +0,0 @@ -package daemon - -import ( - "fmt" - "os" - "path" - "strings" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/types" - "github.com/docker/docker/container" - "github.com/docker/docker/layer" - volumestore "github.com/docker/docker/volume/store" -) - -// ContainerRm removes the container id from the filesystem. An error -// is returned if the container is not found, or if the remove -// fails. If the remove succeeds, the container name is released, and -// network links are removed. -func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig) error { - start := time.Now() - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - // Container state RemovalInProgress should be used to avoid races. - if inProgress := container.SetRemovalInProgress(); inProgress { - err := fmt.Errorf("removal of container %s is already in progress", name) - return errors.NewBadRequestError(err) - } - defer container.ResetRemovalInProgress() - - // check if container wasn't deregistered by previous rm since Get - if c := daemon.containers.Get(container.ID); c == nil { - return nil - } - - if config.RemoveLink { - return daemon.rmLink(container, name) - } - - err = daemon.cleanupContainer(container, config.ForceRemove, config.RemoveVolume) - containerActions.WithValues("delete").UpdateSince(start) - - return err -} - -func (daemon *Daemon) rmLink(container *container.Container, name string) error { - if name[0] != '/' { - name = "/" + name - } - parent, n := path.Split(name) - if parent == "/" { - return fmt.Errorf("Conflict, cannot remove the default name of the container") - } - - parent = strings.TrimSuffix(parent, "/") - pe, err := daemon.nameIndex.Get(parent) - if err != nil { - return fmt.Errorf("Cannot get parent %s for name %s", parent, name) - } - - daemon.releaseName(name) - parentContainer, _ := daemon.GetContainer(pe) - if parentContainer != nil { - daemon.linkIndex.unlink(name, container, parentContainer) - if err := daemon.updateNetwork(parentContainer); err != nil { - logrus.Debugf("Could not update network to remove link %s: %v", n, err) - } - } - return nil -} - -// cleanupContainer unregisters a container from the daemon, stops stats -// collection and cleanly removes contents and metadata from the filesystem. -func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemove, removeVolume bool) (err error) { - if container.IsRunning() { - if !forceRemove { - err := fmt.Errorf("You cannot remove a running container %s. Stop the container before attempting removal or use -f", container.ID) - return errors.NewRequestConflictError(err) - } - if err := daemon.Kill(container); err != nil { - return fmt.Errorf("Could not kill running container %s, cannot remove - %v", container.ID, err) - } - } - - // stop collection of stats for the container regardless - // if stats are currently getting collected. - daemon.statsCollector.stopCollection(container) - - if err = daemon.containerStop(container, 3); err != nil { - return err - } - - // Mark container dead. We don't want anybody to be restarting it. - container.SetDead() - - // Save container state to disk. So that if error happens before - // container meta file got removed from disk, then a restart of - // docker should not make a dead container alive. - if err := container.ToDiskLocking(); err != nil && !os.IsNotExist(err) { - logrus.Errorf("Error saving dying container to disk: %v", err) - } - - // If force removal is required, delete container from various - // indexes even if removal failed. - defer func() { - if err == nil || forceRemove { - daemon.nameIndex.Delete(container.ID) - daemon.linkIndex.delete(container) - selinuxFreeLxcContexts(container.ProcessLabel) - daemon.idIndex.Delete(container.ID) - daemon.containers.Delete(container.ID) - if e := daemon.removeMountPoints(container, removeVolume); e != nil { - logrus.Error(e) - } - daemon.LogContainerEvent(container, "destroy") - } - }() - - if err = os.RemoveAll(container.Root); err != nil { - return fmt.Errorf("Unable to remove filesystem for %v: %v", container.ID, err) - } - - // When container creation fails and `RWLayer` has not been created yet, we - // do not call `ReleaseRWLayer` - if container.RWLayer != nil { - metadata, err := daemon.layerStore.ReleaseRWLayer(container.RWLayer) - layer.LogReleaseMetadata(metadata) - if err != nil && err != layer.ErrMountDoesNotExist { - return fmt.Errorf("Driver %s failed to remove root filesystem %s: %s", daemon.GraphDriverName(), container.ID, err) - } - } - - return nil -} - -// VolumeRm removes the volume with the given name. -// If the volume is referenced by a container it is not removed -// This is called directly from the Engine API -func (daemon *Daemon) VolumeRm(name string, force bool) error { - err := daemon.volumeRm(name) - if err == nil || force { - daemon.volumes.Purge(name) - return nil - } - return err -} - -func (daemon *Daemon) volumeRm(name string) error { - v, err := daemon.volumes.Get(name) - if err != nil { - return err - } - - if err := daemon.volumes.Remove(v); err != nil { - if volumestore.IsInUse(err) { - err := fmt.Errorf("Unable to remove volume, volume still in use: %v", err) - return errors.NewRequestConflictError(err) - } - return fmt.Errorf("Error while removing volume %s: %v", name, err) - } - daemon.LogVolumeEvent(v.Name(), "destroy", map[string]string{"driver": v.DriverName()}) - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/delete_test.go b/vendor/github.com/docker/docker/daemon/delete_test.go deleted file mode 100644 index 1fd27e1..0000000 --- a/vendor/github.com/docker/docker/daemon/delete_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package daemon - -import ( - "fmt" - "io/ioutil" - "os" - "testing" - - "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" -) - -func TestContainerDoubleDelete(t *testing.T) { - tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - daemon := &Daemon{ - repository: tmp, - root: tmp, - } - daemon.containers = container.NewMemoryStore() - - container := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "test", - State: container.NewState(), - Config: &containertypes.Config{}, - }, - } - daemon.containers.Add(container.ID, container) - - // Mark the container as having a delete in progress - container.SetRemovalInProgress() - - // Try to remove the container when its state is removalInProgress. - // It should return an error indicating it is under removal progress. - if err := daemon.ContainerRm(container.ID, &types.ContainerRmConfig{ForceRemove: true}); err == nil { - t.Fatalf("expected err: %v, got nil", fmt.Sprintf("removal of container %s is already in progress", container.ID)) - } -} diff --git a/vendor/github.com/docker/docker/daemon/discovery.go b/vendor/github.com/docker/docker/daemon/discovery.go deleted file mode 100644 index ee4ea87..0000000 --- a/vendor/github.com/docker/docker/daemon/discovery.go +++ /dev/null @@ -1,215 +0,0 @@ -package daemon - -import ( - "errors" - "fmt" - "reflect" - "strconv" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/discovery" - - // Register the libkv backends for discovery. - _ "github.com/docker/docker/pkg/discovery/kv" -) - -const ( - // defaultDiscoveryHeartbeat is the default value for discovery heartbeat interval. - defaultDiscoveryHeartbeat = 20 * time.Second - // defaultDiscoveryTTLFactor is the default TTL factor for discovery - defaultDiscoveryTTLFactor = 3 -) - -var errDiscoveryDisabled = errors.New("discovery is disabled") - -type discoveryReloader interface { - discovery.Watcher - Stop() - Reload(backend, address string, clusterOpts map[string]string) error - ReadyCh() <-chan struct{} -} - -type daemonDiscoveryReloader struct { - backend discovery.Backend - ticker *time.Ticker - term chan bool - readyCh chan struct{} -} - -func (d *daemonDiscoveryReloader) Watch(stopCh <-chan struct{}) (<-chan discovery.Entries, <-chan error) { - return d.backend.Watch(stopCh) -} - -func (d *daemonDiscoveryReloader) ReadyCh() <-chan struct{} { - return d.readyCh -} - -func discoveryOpts(clusterOpts map[string]string) (time.Duration, time.Duration, error) { - var ( - heartbeat = defaultDiscoveryHeartbeat - ttl = defaultDiscoveryTTLFactor * defaultDiscoveryHeartbeat - ) - - if hb, ok := clusterOpts["discovery.heartbeat"]; ok { - h, err := strconv.Atoi(hb) - if err != nil { - return time.Duration(0), time.Duration(0), err - } - - if h <= 0 { - return time.Duration(0), time.Duration(0), - fmt.Errorf("discovery.heartbeat must be positive") - } - - heartbeat = time.Duration(h) * time.Second - ttl = defaultDiscoveryTTLFactor * heartbeat - } - - if tstr, ok := clusterOpts["discovery.ttl"]; ok { - t, err := strconv.Atoi(tstr) - if err != nil { - return time.Duration(0), time.Duration(0), err - } - - if t <= 0 { - return time.Duration(0), time.Duration(0), - fmt.Errorf("discovery.ttl must be positive") - } - - ttl = time.Duration(t) * time.Second - - if _, ok := clusterOpts["discovery.heartbeat"]; !ok { - h := int(t / defaultDiscoveryTTLFactor) - heartbeat = time.Duration(h) * time.Second - } - - if ttl <= heartbeat { - return time.Duration(0), time.Duration(0), - fmt.Errorf("discovery.ttl timer must be greater than discovery.heartbeat") - } - } - - return heartbeat, ttl, nil -} - -// initDiscovery initializes the nodes discovery subsystem by connecting to the specified backend -// and starts a registration loop to advertise the current node under the specified address. -func initDiscovery(backendAddress, advertiseAddress string, clusterOpts map[string]string) (discoveryReloader, error) { - heartbeat, backend, err := parseDiscoveryOptions(backendAddress, clusterOpts) - if err != nil { - return nil, err - } - - reloader := &daemonDiscoveryReloader{ - backend: backend, - ticker: time.NewTicker(heartbeat), - term: make(chan bool), - readyCh: make(chan struct{}), - } - // We call Register() on the discovery backend in a loop for the whole lifetime of the daemon, - // but we never actually Watch() for nodes appearing and disappearing for the moment. - go reloader.advertiseHeartbeat(advertiseAddress) - return reloader, nil -} - -// advertiseHeartbeat registers the current node against the discovery backend using the specified -// address. The function never returns, as registration against the backend comes with a TTL and -// requires regular heartbeats. -func (d *daemonDiscoveryReloader) advertiseHeartbeat(address string) { - var ready bool - if err := d.initHeartbeat(address); err == nil { - ready = true - close(d.readyCh) - } - - for { - select { - case <-d.ticker.C: - if err := d.backend.Register(address); err != nil { - logrus.Warnf("Registering as %q in discovery failed: %v", address, err) - } else { - if !ready { - close(d.readyCh) - ready = true - } - } - case <-d.term: - return - } - } -} - -// initHeartbeat is used to do the first heartbeat. It uses a tight loop until -// either the timeout period is reached or the heartbeat is successful and returns. -func (d *daemonDiscoveryReloader) initHeartbeat(address string) error { - // Setup a short ticker until the first heartbeat has succeeded - t := time.NewTicker(500 * time.Millisecond) - defer t.Stop() - // timeout makes sure that after a period of time we stop being so aggressive trying to reach the discovery service - timeout := time.After(60 * time.Second) - - for { - select { - case <-timeout: - return errors.New("timeout waiting for initial discovery") - case <-d.term: - return errors.New("terminated") - case <-t.C: - if err := d.backend.Register(address); err == nil { - return nil - } - } - } -} - -// Reload makes the watcher to stop advertising and reconfigures it to advertise in a new address. -func (d *daemonDiscoveryReloader) Reload(backendAddress, advertiseAddress string, clusterOpts map[string]string) error { - d.Stop() - - heartbeat, backend, err := parseDiscoveryOptions(backendAddress, clusterOpts) - if err != nil { - return err - } - - d.backend = backend - d.ticker = time.NewTicker(heartbeat) - d.readyCh = make(chan struct{}) - - go d.advertiseHeartbeat(advertiseAddress) - return nil -} - -// Stop terminates the discovery advertising. -func (d *daemonDiscoveryReloader) Stop() { - d.ticker.Stop() - d.term <- true -} - -func parseDiscoveryOptions(backendAddress string, clusterOpts map[string]string) (time.Duration, discovery.Backend, error) { - heartbeat, ttl, err := discoveryOpts(clusterOpts) - if err != nil { - return 0, nil, err - } - - backend, err := discovery.New(backendAddress, heartbeat, ttl, clusterOpts) - if err != nil { - return 0, nil, err - } - return heartbeat, backend, nil -} - -// modifiedDiscoverySettings returns whether the discovery configuration has been modified or not. -func modifiedDiscoverySettings(config *Config, backendType, advertise string, clusterOpts map[string]string) bool { - if config.ClusterStore != backendType || config.ClusterAdvertise != advertise { - return true - } - - if (config.ClusterOpts == nil && clusterOpts == nil) || - (config.ClusterOpts == nil && len(clusterOpts) == 0) || - (len(config.ClusterOpts) == 0 && clusterOpts == nil) { - return false - } - - return !reflect.DeepEqual(config.ClusterOpts, clusterOpts) -} diff --git a/vendor/github.com/docker/docker/daemon/discovery_test.go b/vendor/github.com/docker/docker/daemon/discovery_test.go deleted file mode 100644 index 336973c..0000000 --- a/vendor/github.com/docker/docker/daemon/discovery_test.go +++ /dev/null @@ -1,164 +0,0 @@ -package daemon - -import ( - "testing" - "time" -) - -func TestDiscoveryOpts(t *testing.T) { - clusterOpts := map[string]string{"discovery.heartbeat": "10", "discovery.ttl": "5"} - heartbeat, ttl, err := discoveryOpts(clusterOpts) - if err == nil { - t.Fatalf("discovery.ttl < discovery.heartbeat must fail") - } - - clusterOpts = map[string]string{"discovery.heartbeat": "10", "discovery.ttl": "10"} - heartbeat, ttl, err = discoveryOpts(clusterOpts) - if err == nil { - t.Fatalf("discovery.ttl == discovery.heartbeat must fail") - } - - clusterOpts = map[string]string{"discovery.heartbeat": "-10", "discovery.ttl": "10"} - heartbeat, ttl, err = discoveryOpts(clusterOpts) - if err == nil { - t.Fatalf("negative discovery.heartbeat must fail") - } - - clusterOpts = map[string]string{"discovery.heartbeat": "10", "discovery.ttl": "-10"} - heartbeat, ttl, err = discoveryOpts(clusterOpts) - if err == nil { - t.Fatalf("negative discovery.ttl must fail") - } - - clusterOpts = map[string]string{"discovery.heartbeat": "invalid"} - heartbeat, ttl, err = discoveryOpts(clusterOpts) - if err == nil { - t.Fatalf("invalid discovery.heartbeat must fail") - } - - clusterOpts = map[string]string{"discovery.ttl": "invalid"} - heartbeat, ttl, err = discoveryOpts(clusterOpts) - if err == nil { - t.Fatalf("invalid discovery.ttl must fail") - } - - clusterOpts = map[string]string{"discovery.heartbeat": "10", "discovery.ttl": "20"} - heartbeat, ttl, err = discoveryOpts(clusterOpts) - if err != nil { - t.Fatal(err) - } - - if heartbeat != 10*time.Second { - t.Fatalf("Heartbeat - Expected : %v, Actual : %v", 10*time.Second, heartbeat) - } - - if ttl != 20*time.Second { - t.Fatalf("TTL - Expected : %v, Actual : %v", 20*time.Second, ttl) - } - - clusterOpts = map[string]string{"discovery.heartbeat": "10"} - heartbeat, ttl, err = discoveryOpts(clusterOpts) - if err != nil { - t.Fatal(err) - } - - if heartbeat != 10*time.Second { - t.Fatalf("Heartbeat - Expected : %v, Actual : %v", 10*time.Second, heartbeat) - } - - expected := 10 * defaultDiscoveryTTLFactor * time.Second - if ttl != expected { - t.Fatalf("TTL - Expected : %v, Actual : %v", expected, ttl) - } - - clusterOpts = map[string]string{"discovery.ttl": "30"} - heartbeat, ttl, err = discoveryOpts(clusterOpts) - if err != nil { - t.Fatal(err) - } - - if ttl != 30*time.Second { - t.Fatalf("TTL - Expected : %v, Actual : %v", 30*time.Second, ttl) - } - - expected = 30 * time.Second / defaultDiscoveryTTLFactor - if heartbeat != expected { - t.Fatalf("Heartbeat - Expected : %v, Actual : %v", expected, heartbeat) - } - - clusterOpts = map[string]string{} - heartbeat, ttl, err = discoveryOpts(clusterOpts) - if err != nil { - t.Fatal(err) - } - - if heartbeat != defaultDiscoveryHeartbeat { - t.Fatalf("Heartbeat - Expected : %v, Actual : %v", defaultDiscoveryHeartbeat, heartbeat) - } - - expected = defaultDiscoveryHeartbeat * defaultDiscoveryTTLFactor - if ttl != expected { - t.Fatalf("TTL - Expected : %v, Actual : %v", expected, ttl) - } -} - -func TestModifiedDiscoverySettings(t *testing.T) { - cases := []struct { - current *Config - modified *Config - expected bool - }{ - { - current: discoveryConfig("foo", "bar", map[string]string{}), - modified: discoveryConfig("foo", "bar", map[string]string{}), - expected: false, - }, - { - current: discoveryConfig("foo", "bar", map[string]string{"foo": "bar"}), - modified: discoveryConfig("foo", "bar", map[string]string{"foo": "bar"}), - expected: false, - }, - { - current: discoveryConfig("foo", "bar", map[string]string{}), - modified: discoveryConfig("foo", "bar", nil), - expected: false, - }, - { - current: discoveryConfig("foo", "bar", nil), - modified: discoveryConfig("foo", "bar", map[string]string{}), - expected: false, - }, - { - current: discoveryConfig("foo", "bar", nil), - modified: discoveryConfig("baz", "bar", nil), - expected: true, - }, - { - current: discoveryConfig("foo", "bar", nil), - modified: discoveryConfig("foo", "baz", nil), - expected: true, - }, - { - current: discoveryConfig("foo", "bar", nil), - modified: discoveryConfig("foo", "bar", map[string]string{"foo": "bar"}), - expected: true, - }, - } - - for _, c := range cases { - got := modifiedDiscoverySettings(c.current, c.modified.ClusterStore, c.modified.ClusterAdvertise, c.modified.ClusterOpts) - if c.expected != got { - t.Fatalf("expected %v, got %v: current config %v, new config %v", c.expected, got, c.current, c.modified) - } - } -} - -func discoveryConfig(backendAddr, advertiseAddr string, opts map[string]string) *Config { - return &Config{ - CommonConfig: CommonConfig{ - ClusterStore: backendAddr, - ClusterAdvertise: advertiseAddr, - ClusterOpts: opts, - }, - } -} diff --git a/vendor/github.com/docker/docker/daemon/disk_usage.go b/vendor/github.com/docker/docker/daemon/disk_usage.go deleted file mode 100644 index c3b9186..0000000 --- a/vendor/github.com/docker/docker/daemon/disk_usage.go +++ /dev/null @@ -1,100 +0,0 @@ -package daemon - -import ( - "fmt" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/directory" - "github.com/docker/docker/volume" -) - -func (daemon *Daemon) getLayerRefs() map[layer.ChainID]int { - tmpImages := daemon.imageStore.Map() - layerRefs := map[layer.ChainID]int{} - for id, img := range tmpImages { - dgst := digest.Digest(id) - if len(daemon.referenceStore.References(dgst)) == 0 && len(daemon.imageStore.Children(id)) != 0 { - continue - } - - rootFS := *img.RootFS - rootFS.DiffIDs = nil - for _, id := range img.RootFS.DiffIDs { - rootFS.Append(id) - chid := rootFS.ChainID() - layerRefs[chid]++ - } - } - - return layerRefs -} - -// SystemDiskUsage returns information about the daemon data disk usage -func (daemon *Daemon) SystemDiskUsage() (*types.DiskUsage, error) { - // Retrieve container list - allContainers, err := daemon.Containers(&types.ContainerListOptions{ - Size: true, - All: true, - }) - if err != nil { - return nil, fmt.Errorf("failed to retrieve container list: %v", err) - } - - // Get all top images with extra attributes - allImages, err := daemon.Images(filters.NewArgs(), false, true) - if err != nil { - return nil, fmt.Errorf("failed to retrieve image list: %v", err) - } - - // Get all local volumes - allVolumes := []*types.Volume{} - getLocalVols := func(v volume.Volume) error { - name := v.Name() - refs := daemon.volumes.Refs(v) - - tv := volumeToAPIType(v) - sz, err := directory.Size(v.Path()) - if err != nil { - logrus.Warnf("failed to determine size of volume %v", name) - sz = -1 - } - tv.UsageData = &types.VolumeUsageData{Size: sz, RefCount: int64(len(refs))} - allVolumes = append(allVolumes, tv) - - return nil - } - - err = daemon.traverseLocalVolumes(getLocalVols) - if err != nil { - return nil, err - } - - // Get total layers size on disk - layerRefs := daemon.getLayerRefs() - allLayers := daemon.layerStore.Map() - var allLayersSize int64 - for _, l := range allLayers { - size, err := l.DiffSize() - if err == nil { - if _, ok := layerRefs[l.ChainID()]; ok { - allLayersSize += size - } else { - logrus.Warnf("found leaked image layer %v", l.ChainID()) - } - } else { - logrus.Warnf("failed to get diff size for layer %v", l.ChainID()) - } - - } - - return &types.DiskUsage{ - LayersSize: allLayersSize, - Containers: allContainers, - Volumes: allVolumes, - Images: allImages, - }, nil -} diff --git a/vendor/github.com/docker/docker/daemon/errors.go b/vendor/github.com/docker/docker/daemon/errors.go deleted file mode 100644 index 566a32f..0000000 --- a/vendor/github.com/docker/docker/daemon/errors.go +++ /dev/null @@ -1,57 +0,0 @@ -package daemon - -import ( - "fmt" - "strings" - - "github.com/docker/docker/api/errors" - "github.com/docker/docker/reference" -) - -func (d *Daemon) imageNotExistToErrcode(err error) error { - if dne, isDNE := err.(ErrImageDoesNotExist); isDNE { - if strings.Contains(dne.RefOrID, "@") { - e := fmt.Errorf("No such image: %s", dne.RefOrID) - return errors.NewRequestNotFoundError(e) - } - tag := reference.DefaultTag - ref, err := reference.ParseNamed(dne.RefOrID) - if err != nil { - e := fmt.Errorf("No such image: %s:%s", dne.RefOrID, tag) - return errors.NewRequestNotFoundError(e) - } - if tagged, isTagged := ref.(reference.NamedTagged); isTagged { - tag = tagged.Tag() - } - e := fmt.Errorf("No such image: %s:%s", ref.Name(), tag) - return errors.NewRequestNotFoundError(e) - } - return err -} - -type errNotRunning struct { - containerID string -} - -func (e errNotRunning) Error() string { - return fmt.Sprintf("Container %s is not running", e.containerID) -} - -func (e errNotRunning) ContainerIsRunning() bool { - return false -} - -func errContainerIsRestarting(containerID string) error { - err := fmt.Errorf("Container %s is restarting, wait until the container is running", containerID) - return errors.NewRequestConflictError(err) -} - -func errExecNotFound(id string) error { - err := fmt.Errorf("No such exec instance '%s' found in daemon", id) - return errors.NewRequestNotFoundError(err) -} - -func errExecPaused(id string) error { - err := fmt.Errorf("Container %s is paused, unpause the container before exec", id) - return errors.NewRequestConflictError(err) -} diff --git a/vendor/github.com/docker/docker/daemon/events.go b/vendor/github.com/docker/docker/daemon/events.go deleted file mode 100644 index 8fe8e1b..0000000 --- a/vendor/github.com/docker/docker/daemon/events.go +++ /dev/null @@ -1,132 +0,0 @@ -package daemon - -import ( - "strings" - "time" - - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/container" - daemonevents "github.com/docker/docker/daemon/events" - "github.com/docker/libnetwork" -) - -// LogContainerEvent generates an event related to a container with only the default attributes. -func (daemon *Daemon) LogContainerEvent(container *container.Container, action string) { - daemon.LogContainerEventWithAttributes(container, action, map[string]string{}) -} - -// LogContainerEventWithAttributes generates an event related to a container with specific given attributes. -func (daemon *Daemon) LogContainerEventWithAttributes(container *container.Container, action string, attributes map[string]string) { - copyAttributes(attributes, container.Config.Labels) - if container.Config.Image != "" { - attributes["image"] = container.Config.Image - } - attributes["name"] = strings.TrimLeft(container.Name, "/") - - actor := events.Actor{ - ID: container.ID, - Attributes: attributes, - } - daemon.EventsService.Log(action, events.ContainerEventType, actor) -} - -// LogImageEvent generates an event related to an image with only the default attributes. -func (daemon *Daemon) LogImageEvent(imageID, refName, action string) { - daemon.LogImageEventWithAttributes(imageID, refName, action, map[string]string{}) -} - -// LogImageEventWithAttributes generates an event related to an image with specific given attributes. -func (daemon *Daemon) LogImageEventWithAttributes(imageID, refName, action string, attributes map[string]string) { - img, err := daemon.GetImage(imageID) - if err == nil && img.Config != nil { - // image has not been removed yet. - // it could be missing if the event is `delete`. - copyAttributes(attributes, img.Config.Labels) - } - if refName != "" { - attributes["name"] = refName - } - actor := events.Actor{ - ID: imageID, - Attributes: attributes, - } - - daemon.EventsService.Log(action, events.ImageEventType, actor) -} - -// LogPluginEvent generates an event related to a plugin with only the default attributes. -func (daemon *Daemon) LogPluginEvent(pluginID, refName, action string) { - daemon.LogPluginEventWithAttributes(pluginID, refName, action, map[string]string{}) -} - -// LogPluginEventWithAttributes generates an event related to a plugin with specific given attributes. -func (daemon *Daemon) LogPluginEventWithAttributes(pluginID, refName, action string, attributes map[string]string) { - attributes["name"] = refName - actor := events.Actor{ - ID: pluginID, - Attributes: attributes, - } - daemon.EventsService.Log(action, events.PluginEventType, actor) -} - -// LogVolumeEvent generates an event related to a volume. -func (daemon *Daemon) LogVolumeEvent(volumeID, action string, attributes map[string]string) { - actor := events.Actor{ - ID: volumeID, - Attributes: attributes, - } - daemon.EventsService.Log(action, events.VolumeEventType, actor) -} - -// LogNetworkEvent generates an event related to a network with only the default attributes. -func (daemon *Daemon) LogNetworkEvent(nw libnetwork.Network, action string) { - daemon.LogNetworkEventWithAttributes(nw, action, map[string]string{}) -} - -// LogNetworkEventWithAttributes generates an event related to a network with specific given attributes. -func (daemon *Daemon) LogNetworkEventWithAttributes(nw libnetwork.Network, action string, attributes map[string]string) { - attributes["name"] = nw.Name() - attributes["type"] = nw.Type() - actor := events.Actor{ - ID: nw.ID(), - Attributes: attributes, - } - daemon.EventsService.Log(action, events.NetworkEventType, actor) -} - -// LogDaemonEventWithAttributes generates an event related to the daemon itself with specific given attributes. -func (daemon *Daemon) LogDaemonEventWithAttributes(action string, attributes map[string]string) { - if daemon.EventsService != nil { - if info, err := daemon.SystemInfo(); err == nil && info.Name != "" { - attributes["name"] = info.Name - } - actor := events.Actor{ - ID: daemon.ID, - Attributes: attributes, - } - daemon.EventsService.Log(action, events.DaemonEventType, actor) - } -} - -// SubscribeToEvents returns the currently record of events, a channel to stream new events from, and a function to cancel the stream of events. -func (daemon *Daemon) SubscribeToEvents(since, until time.Time, filter filters.Args) ([]events.Message, chan interface{}) { - ef := daemonevents.NewFilter(filter) - return daemon.EventsService.SubscribeTopic(since, until, ef) -} - -// UnsubscribeFromEvents stops the event subscription for a client by closing the -// channel where the daemon sends events to. -func (daemon *Daemon) UnsubscribeFromEvents(listener chan interface{}) { - daemon.EventsService.Evict(listener) -} - -// copyAttributes guarantees that labels are not mutated by event triggers. -func copyAttributes(attributes, labels map[string]string) { - if labels == nil { - return - } - for k, v := range labels { - attributes[k] = v - } -} diff --git a/vendor/github.com/docker/docker/daemon/events/events.go b/vendor/github.com/docker/docker/daemon/events/events.go deleted file mode 100644 index 0bf105f..0000000 --- a/vendor/github.com/docker/docker/daemon/events/events.go +++ /dev/null @@ -1,158 +0,0 @@ -package events - -import ( - "sync" - "time" - - eventtypes "github.com/docker/docker/api/types/events" - "github.com/docker/docker/pkg/pubsub" -) - -const ( - eventsLimit = 64 - bufferSize = 1024 -) - -// Events is pubsub channel for events generated by the engine. -type Events struct { - mu sync.Mutex - events []eventtypes.Message - pub *pubsub.Publisher -} - -// New returns new *Events instance -func New() *Events { - return &Events{ - events: make([]eventtypes.Message, 0, eventsLimit), - pub: pubsub.NewPublisher(100*time.Millisecond, bufferSize), - } -} - -// Subscribe adds new listener to events, returns slice of 64 stored -// last events, a channel in which you can expect new events (in form -// of interface{}, so you need type assertion), and a function to call -// to stop the stream of events. -func (e *Events) Subscribe() ([]eventtypes.Message, chan interface{}, func()) { - eventSubscribers.Inc() - e.mu.Lock() - current := make([]eventtypes.Message, len(e.events)) - copy(current, e.events) - l := e.pub.Subscribe() - e.mu.Unlock() - - cancel := func() { - e.Evict(l) - } - return current, l, cancel -} - -// SubscribeTopic adds new listener to events, returns slice of 64 stored -// last events, a channel in which you can expect new events (in form -// of interface{}, so you need type assertion). -func (e *Events) SubscribeTopic(since, until time.Time, ef *Filter) ([]eventtypes.Message, chan interface{}) { - eventSubscribers.Inc() - e.mu.Lock() - - var topic func(m interface{}) bool - if ef != nil && ef.filter.Len() > 0 { - topic = func(m interface{}) bool { return ef.Include(m.(eventtypes.Message)) } - } - - buffered := e.loadBufferedEvents(since, until, topic) - - var ch chan interface{} - if topic != nil { - ch = e.pub.SubscribeTopic(topic) - } else { - // Subscribe to all events if there are no filters - ch = e.pub.Subscribe() - } - - e.mu.Unlock() - return buffered, ch -} - -// Evict evicts listener from pubsub -func (e *Events) Evict(l chan interface{}) { - eventSubscribers.Dec() - e.pub.Evict(l) -} - -// Log broadcasts event to listeners. Each listener has 100 millisecond for -// receiving event or it will be skipped. -func (e *Events) Log(action, eventType string, actor eventtypes.Actor) { - eventsCounter.Inc() - now := time.Now().UTC() - jm := eventtypes.Message{ - Action: action, - Type: eventType, - Actor: actor, - Time: now.Unix(), - TimeNano: now.UnixNano(), - } - - // fill deprecated fields for container and images - switch eventType { - case eventtypes.ContainerEventType: - jm.ID = actor.ID - jm.Status = action - jm.From = actor.Attributes["image"] - case eventtypes.ImageEventType: - jm.ID = actor.ID - jm.Status = action - } - - e.mu.Lock() - if len(e.events) == cap(e.events) { - // discard oldest event - copy(e.events, e.events[1:]) - e.events[len(e.events)-1] = jm - } else { - e.events = append(e.events, jm) - } - e.mu.Unlock() - e.pub.Publish(jm) -} - -// SubscribersCount returns number of event listeners -func (e *Events) SubscribersCount() int { - return e.pub.Len() -} - -// loadBufferedEvents iterates over the cached events in the buffer -// and returns those that were emitted between two specific dates. -// It uses `time.Unix(seconds, nanoseconds)` to generate valid dates with those arguments. -// It filters those buffered messages with a topic function if it's not nil, otherwise it adds all messages. -func (e *Events) loadBufferedEvents(since, until time.Time, topic func(interface{}) bool) []eventtypes.Message { - var buffered []eventtypes.Message - if since.IsZero() && until.IsZero() { - return buffered - } - - var sinceNanoUnix int64 - if !since.IsZero() { - sinceNanoUnix = since.UnixNano() - } - - var untilNanoUnix int64 - if !until.IsZero() { - untilNanoUnix = until.UnixNano() - } - - for i := len(e.events) - 1; i >= 0; i-- { - ev := e.events[i] - - if ev.TimeNano < sinceNanoUnix { - break - } - - if untilNanoUnix > 0 && ev.TimeNano > untilNanoUnix { - continue - } - - if topic == nil || topic(ev) { - buffered = append([]eventtypes.Message{ev}, buffered...) - } - } - return buffered -} diff --git a/vendor/github.com/docker/docker/daemon/events/events_test.go b/vendor/github.com/docker/docker/daemon/events/events_test.go deleted file mode 100644 index bbd160f..0000000 --- a/vendor/github.com/docker/docker/daemon/events/events_test.go +++ /dev/null @@ -1,275 +0,0 @@ -package events - -import ( - "fmt" - "testing" - "time" - - "github.com/docker/docker/api/types/events" - timetypes "github.com/docker/docker/api/types/time" - eventstestutils "github.com/docker/docker/daemon/events/testutils" -) - -func TestEventsLog(t *testing.T) { - e := New() - _, l1, _ := e.Subscribe() - _, l2, _ := e.Subscribe() - defer e.Evict(l1) - defer e.Evict(l2) - count := e.SubscribersCount() - if count != 2 { - t.Fatalf("Must be 2 subscribers, got %d", count) - } - actor := events.Actor{ - ID: "cont", - Attributes: map[string]string{"image": "image"}, - } - e.Log("test", events.ContainerEventType, actor) - select { - case msg := <-l1: - jmsg, ok := msg.(events.Message) - if !ok { - t.Fatalf("Unexpected type %T", msg) - } - if len(e.events) != 1 { - t.Fatalf("Must be only one event, got %d", len(e.events)) - } - if jmsg.Status != "test" { - t.Fatalf("Status should be test, got %s", jmsg.Status) - } - if jmsg.ID != "cont" { - t.Fatalf("ID should be cont, got %s", jmsg.ID) - } - if jmsg.From != "image" { - t.Fatalf("From should be image, got %s", jmsg.From) - } - case <-time.After(1 * time.Second): - t.Fatal("Timeout waiting for broadcasted message") - } - select { - case msg := <-l2: - jmsg, ok := msg.(events.Message) - if !ok { - t.Fatalf("Unexpected type %T", msg) - } - if len(e.events) != 1 { - t.Fatalf("Must be only one event, got %d", len(e.events)) - } - if jmsg.Status != "test" { - t.Fatalf("Status should be test, got %s", jmsg.Status) - } - if jmsg.ID != "cont" { - t.Fatalf("ID should be cont, got %s", jmsg.ID) - } - if jmsg.From != "image" { - t.Fatalf("From should be image, got %s", jmsg.From) - } - case <-time.After(1 * time.Second): - t.Fatal("Timeout waiting for broadcasted message") - } -} - -func TestEventsLogTimeout(t *testing.T) { - e := New() - _, l, _ := e.Subscribe() - defer e.Evict(l) - - c := make(chan struct{}) - go func() { - actor := events.Actor{ - ID: "image", - } - e.Log("test", events.ImageEventType, actor) - close(c) - }() - - select { - case <-c: - case <-time.After(time.Second): - t.Fatal("Timeout publishing message") - } -} - -func TestLogEvents(t *testing.T) { - e := New() - - for i := 0; i < eventsLimit+16; i++ { - action := fmt.Sprintf("action_%d", i) - id := fmt.Sprintf("cont_%d", i) - from := fmt.Sprintf("image_%d", i) - - actor := events.Actor{ - ID: id, - Attributes: map[string]string{"image": from}, - } - e.Log(action, events.ContainerEventType, actor) - } - time.Sleep(50 * time.Millisecond) - current, l, _ := e.Subscribe() - for i := 0; i < 10; i++ { - num := i + eventsLimit + 16 - action := fmt.Sprintf("action_%d", num) - id := fmt.Sprintf("cont_%d", num) - from := fmt.Sprintf("image_%d", num) - - actor := events.Actor{ - ID: id, - Attributes: map[string]string{"image": from}, - } - e.Log(action, events.ContainerEventType, actor) - } - if len(e.events) != eventsLimit { - t.Fatalf("Must be %d events, got %d", eventsLimit, len(e.events)) - } - - var msgs []events.Message - for len(msgs) < 10 { - m := <-l - jm, ok := (m).(events.Message) - if !ok { - t.Fatalf("Unexpected type %T", m) - } - msgs = append(msgs, jm) - } - if len(current) != eventsLimit { - t.Fatalf("Must be %d events, got %d", eventsLimit, len(current)) - } - first := current[0] - if first.Status != "action_16" { - t.Fatalf("First action is %s, must be action_16", first.Status) - } - last := current[len(current)-1] - if last.Status != "action_79" { - t.Fatalf("Last action is %s, must be action_79", last.Status) - } - - firstC := msgs[0] - if firstC.Status != "action_80" { - t.Fatalf("First action is %s, must be action_80", firstC.Status) - } - lastC := msgs[len(msgs)-1] - if lastC.Status != "action_89" { - t.Fatalf("Last action is %s, must be action_89", lastC.Status) - } -} - -// https://github.com/docker/docker/issues/20999 -// Fixtures: -// -//2016-03-07T17:28:03.022433271+02:00 container die 0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079 (image=ubuntu, name=small_hoover) -//2016-03-07T17:28:03.091719377+02:00 network disconnect 19c5ed41acb798f26b751e0035cd7821741ab79e2bbd59a66b5fd8abf954eaa0 (type=bridge, container=0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079, name=bridge) -//2016-03-07T17:28:03.129014751+02:00 container destroy 0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079 (image=ubuntu, name=small_hoover) -func TestLoadBufferedEvents(t *testing.T) { - now := time.Now() - f, err := timetypes.GetTimestamp("2016-03-07T17:28:03.100000000+02:00", now) - if err != nil { - t.Fatal(err) - } - s, sNano, err := timetypes.ParseTimestamps(f, -1) - if err != nil { - t.Fatal(err) - } - - m1, err := eventstestutils.Scan("2016-03-07T17:28:03.022433271+02:00 container die 0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079 (image=ubuntu, name=small_hoover)") - if err != nil { - t.Fatal(err) - } - m2, err := eventstestutils.Scan("2016-03-07T17:28:03.091719377+02:00 network disconnect 19c5ed41acb798f26b751e0035cd7821741ab79e2bbd59a66b5fd8abf954eaa0 (type=bridge, container=0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079, name=bridge)") - if err != nil { - t.Fatal(err) - } - m3, err := eventstestutils.Scan("2016-03-07T17:28:03.129014751+02:00 container destroy 0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079 (image=ubuntu, name=small_hoover)") - if err != nil { - t.Fatal(err) - } - - events := &Events{ - events: []events.Message{*m1, *m2, *m3}, - } - - since := time.Unix(s, sNano) - until := time.Time{} - - out := events.loadBufferedEvents(since, until, nil) - if len(out) != 1 { - t.Fatalf("expected 1 message, got %d: %v", len(out), out) - } -} - -func TestLoadBufferedEventsOnlyFromPast(t *testing.T) { - now := time.Now() - f, err := timetypes.GetTimestamp("2016-03-07T17:28:03.090000000+02:00", now) - if err != nil { - t.Fatal(err) - } - s, sNano, err := timetypes.ParseTimestamps(f, 0) - if err != nil { - t.Fatal(err) - } - - f, err = timetypes.GetTimestamp("2016-03-07T17:28:03.100000000+02:00", now) - if err != nil { - t.Fatal(err) - } - u, uNano, err := timetypes.ParseTimestamps(f, 0) - if err != nil { - t.Fatal(err) - } - - m1, err := eventstestutils.Scan("2016-03-07T17:28:03.022433271+02:00 container die 0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079 (image=ubuntu, name=small_hoover)") - if err != nil { - t.Fatal(err) - } - m2, err := eventstestutils.Scan("2016-03-07T17:28:03.091719377+02:00 network disconnect 19c5ed41acb798f26b751e0035cd7821741ab79e2bbd59a66b5fd8abf954eaa0 (type=bridge, container=0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079, name=bridge)") - if err != nil { - t.Fatal(err) - } - m3, err := eventstestutils.Scan("2016-03-07T17:28:03.129014751+02:00 container destroy 0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079 (image=ubuntu, name=small_hoover)") - if err != nil { - t.Fatal(err) - } - - events := &Events{ - events: []events.Message{*m1, *m2, *m3}, - } - - since := time.Unix(s, sNano) - until := time.Unix(u, uNano) - - out := events.loadBufferedEvents(since, until, nil) - if len(out) != 1 { - t.Fatalf("expected 1 message, got %d: %v", len(out), out) - } - - if out[0].Type != "network" { - t.Fatalf("expected network event, got %s", out[0].Type) - } -} - -// #13753 -func TestIngoreBufferedWhenNoTimes(t *testing.T) { - m1, err := eventstestutils.Scan("2016-03-07T17:28:03.022433271+02:00 container die 0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079 (image=ubuntu, name=small_hoover)") - if err != nil { - t.Fatal(err) - } - m2, err := eventstestutils.Scan("2016-03-07T17:28:03.091719377+02:00 network disconnect 19c5ed41acb798f26b751e0035cd7821741ab79e2bbd59a66b5fd8abf954eaa0 (type=bridge, container=0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079, name=bridge)") - if err != nil { - t.Fatal(err) - } - m3, err := eventstestutils.Scan("2016-03-07T17:28:03.129014751+02:00 container destroy 0b863f2a26c18557fc6cdadda007c459f9ec81b874780808138aea78a3595079 (image=ubuntu, name=small_hoover)") - if err != nil { - t.Fatal(err) - } - - events := &Events{ - events: []events.Message{*m1, *m2, *m3}, - } - - since := time.Time{} - until := time.Time{} - - out := events.loadBufferedEvents(since, until, nil) - if len(out) != 0 { - t.Fatalf("expected 0 buffered events, got %q", out) - } -} diff --git a/vendor/github.com/docker/docker/daemon/events/filter.go b/vendor/github.com/docker/docker/daemon/events/filter.go deleted file mode 100644 index 5c9c527..0000000 --- a/vendor/github.com/docker/docker/daemon/events/filter.go +++ /dev/null @@ -1,110 +0,0 @@ -package events - -import ( - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/reference" -) - -// Filter can filter out docker events from a stream -type Filter struct { - filter filters.Args -} - -// NewFilter creates a new Filter -func NewFilter(filter filters.Args) *Filter { - return &Filter{filter: filter} -} - -// Include returns true when the event ev is included by the filters -func (ef *Filter) Include(ev events.Message) bool { - return ef.matchEvent(ev) && - ef.filter.ExactMatch("type", ev.Type) && - ef.matchDaemon(ev) && - ef.matchContainer(ev) && - ef.matchPlugin(ev) && - ef.matchVolume(ev) && - ef.matchNetwork(ev) && - ef.matchImage(ev) && - ef.matchLabels(ev.Actor.Attributes) -} - -func (ef *Filter) matchEvent(ev events.Message) bool { - // #25798 if an event filter contains either health_status, exec_create or exec_start without a colon - // Let's to a FuzzyMatch instead of an ExactMatch. - if ef.filterContains("event", map[string]struct{}{"health_status": {}, "exec_create": {}, "exec_start": {}}) { - return ef.filter.FuzzyMatch("event", ev.Action) - } - return ef.filter.ExactMatch("event", ev.Action) -} - -func (ef *Filter) filterContains(field string, values map[string]struct{}) bool { - for _, v := range ef.filter.Get(field) { - if _, ok := values[v]; ok { - return true - } - } - return false -} - -func (ef *Filter) matchLabels(attributes map[string]string) bool { - if !ef.filter.Include("label") { - return true - } - return ef.filter.MatchKVList("label", attributes) -} - -func (ef *Filter) matchDaemon(ev events.Message) bool { - return ef.fuzzyMatchName(ev, events.DaemonEventType) -} - -func (ef *Filter) matchContainer(ev events.Message) bool { - return ef.fuzzyMatchName(ev, events.ContainerEventType) -} - -func (ef *Filter) matchPlugin(ev events.Message) bool { - return ef.fuzzyMatchName(ev, events.PluginEventType) -} - -func (ef *Filter) matchVolume(ev events.Message) bool { - return ef.fuzzyMatchName(ev, events.VolumeEventType) -} - -func (ef *Filter) matchNetwork(ev events.Message) bool { - return ef.fuzzyMatchName(ev, events.NetworkEventType) -} - -func (ef *Filter) fuzzyMatchName(ev events.Message, eventType string) bool { - return ef.filter.FuzzyMatch(eventType, ev.Actor.ID) || - ef.filter.FuzzyMatch(eventType, ev.Actor.Attributes["name"]) -} - -// matchImage matches against both event.Actor.ID (for image events) -// and event.Actor.Attributes["image"] (for container events), so that any container that was created -// from an image will be included in the image events. Also compare both -// against the stripped repo name without any tags. -func (ef *Filter) matchImage(ev events.Message) bool { - id := ev.Actor.ID - nameAttr := "image" - var imageName string - - if ev.Type == events.ImageEventType { - nameAttr = "name" - } - - if n, ok := ev.Actor.Attributes[nameAttr]; ok { - imageName = n - } - return ef.filter.ExactMatch("image", id) || - ef.filter.ExactMatch("image", imageName) || - ef.filter.ExactMatch("image", stripTag(id)) || - ef.filter.ExactMatch("image", stripTag(imageName)) -} - -func stripTag(image string) string { - ref, err := reference.ParseNamed(image) - if err != nil { - return image - } - return ref.Name() -} diff --git a/vendor/github.com/docker/docker/daemon/events/metrics.go b/vendor/github.com/docker/docker/daemon/events/metrics.go deleted file mode 100644 index c9a89ec..0000000 --- a/vendor/github.com/docker/docker/daemon/events/metrics.go +++ /dev/null @@ -1,15 +0,0 @@ -package events - -import "github.com/docker/go-metrics" - -var ( - eventsCounter metrics.Counter - eventSubscribers metrics.Gauge -) - -func init() { - ns := metrics.NewNamespace("engine", "daemon", nil) - eventsCounter = ns.NewCounter("events", "The number of events logged") - eventSubscribers = ns.NewGauge("events_subscribers", "The number of current subscribers to events", metrics.Total) - metrics.Register(ns) -} diff --git a/vendor/github.com/docker/docker/daemon/events/testutils/testutils.go b/vendor/github.com/docker/docker/daemon/events/testutils/testutils.go deleted file mode 100644 index 3544446..0000000 --- a/vendor/github.com/docker/docker/daemon/events/testutils/testutils.go +++ /dev/null @@ -1,76 +0,0 @@ -package testutils - -import ( - "fmt" - "regexp" - "strings" - "time" - - "github.com/docker/docker/api/types/events" - timetypes "github.com/docker/docker/api/types/time" -) - -var ( - reTimestamp = `(?P\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{9}(:?(:?(:?-|\+)\d{2}:\d{2})|Z))` - reEventType = `(?P\w+)` - reAction = `(?P\w+)` - reID = `(?P[^\s]+)` - reAttributes = `(\s\((?P[^\)]+)\))?` - reString = fmt.Sprintf(`\A%s\s%s\s%s\s%s%s\z`, reTimestamp, reEventType, reAction, reID, reAttributes) - - // eventCliRegexp is a regular expression that matches all possible event outputs in the cli - eventCliRegexp = regexp.MustCompile(reString) -) - -// ScanMap turns an event string like the default ones formatted in the cli output -// and turns it into map. -func ScanMap(text string) map[string]string { - matches := eventCliRegexp.FindAllStringSubmatch(text, -1) - md := map[string]string{} - if len(matches) == 0 { - return md - } - - names := eventCliRegexp.SubexpNames() - for i, n := range matches[0] { - md[names[i]] = n - } - return md -} - -// Scan turns an event string like the default ones formatted in the cli output -// and turns it into an event message. -func Scan(text string) (*events.Message, error) { - md := ScanMap(text) - if len(md) == 0 { - return nil, fmt.Errorf("text is not an event: %s", text) - } - - f, err := timetypes.GetTimestamp(md["timestamp"], time.Now()) - if err != nil { - return nil, err - } - - t, tn, err := timetypes.ParseTimestamps(f, -1) - if err != nil { - return nil, err - } - - attrs := make(map[string]string) - for _, a := range strings.SplitN(md["attributes"], ", ", -1) { - kv := strings.SplitN(a, "=", 2) - attrs[kv[0]] = kv[1] - } - - tu := time.Unix(t, tn) - return &events.Message{ - Time: t, - TimeNano: tu.UnixNano(), - Type: md["eventType"], - Action: md["action"], - Actor: events.Actor{ - ID: md["id"], - Attributes: attrs, - }, - }, nil -} diff --git a/vendor/github.com/docker/docker/daemon/events_test.go b/vendor/github.com/docker/docker/daemon/events_test.go deleted file mode 100644 index 2dbcc27..0000000 --- a/vendor/github.com/docker/docker/daemon/events_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package daemon - -import ( - "testing" - "time" - - containertypes "github.com/docker/docker/api/types/container" - eventtypes "github.com/docker/docker/api/types/events" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/events" -) - -func TestLogContainerEventCopyLabels(t *testing.T) { - e := events.New() - _, l, _ := e.Subscribe() - defer e.Evict(l) - - container := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "container_id", - Name: "container_name", - Config: &containertypes.Config{ - Image: "image_name", - Labels: map[string]string{ - "node": "1", - "os": "alpine", - }, - }, - }, - } - daemon := &Daemon{ - EventsService: e, - } - daemon.LogContainerEvent(container, "create") - - if _, mutated := container.Config.Labels["image"]; mutated { - t.Fatalf("Expected to not mutate the container labels, got %q", container.Config.Labels) - } - - validateTestAttributes(t, l, map[string]string{ - "node": "1", - "os": "alpine", - }) -} - -func TestLogContainerEventWithAttributes(t *testing.T) { - e := events.New() - _, l, _ := e.Subscribe() - defer e.Evict(l) - - container := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "container_id", - Name: "container_name", - Config: &containertypes.Config{ - Labels: map[string]string{ - "node": "1", - "os": "alpine", - }, - }, - }, - } - daemon := &Daemon{ - EventsService: e, - } - attributes := map[string]string{ - "node": "2", - "foo": "bar", - } - daemon.LogContainerEventWithAttributes(container, "create", attributes) - - validateTestAttributes(t, l, map[string]string{ - "node": "1", - "foo": "bar", - }) -} - -func validateTestAttributes(t *testing.T, l chan interface{}, expectedAttributesToTest map[string]string) { - select { - case ev := <-l: - event, ok := ev.(eventtypes.Message) - if !ok { - t.Fatalf("Unexpected event message: %q", ev) - } - for key, expected := range expectedAttributesToTest { - actual, ok := event.Actor.Attributes[key] - if !ok || actual != expected { - t.Fatalf("Expected value for key %s to be %s, but was %s (event:%v)", key, expected, actual, event) - } - } - case <-time.After(10 * time.Second): - t.Fatalf("LogEvent test timed out") - } -} diff --git a/vendor/github.com/docker/docker/daemon/exec.go b/vendor/github.com/docker/docker/daemon/exec.go deleted file mode 100644 index 8197426..0000000 --- a/vendor/github.com/docker/docker/daemon/exec.go +++ /dev/null @@ -1,280 +0,0 @@ -package daemon - -import ( - "fmt" - "io" - "strings" - "time" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/strslice" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/exec" - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/pkg/pools" - "github.com/docker/docker/pkg/signal" - "github.com/docker/docker/pkg/term" - "github.com/docker/docker/utils" -) - -// Seconds to wait after sending TERM before trying KILL -const termProcessTimeout = 10 - -func (d *Daemon) registerExecCommand(container *container.Container, config *exec.Config) { - // Storing execs in container in order to kill them gracefully whenever the container is stopped or removed. - container.ExecCommands.Add(config.ID, config) - // Storing execs in daemon for easy access via Engine API. - d.execCommands.Add(config.ID, config) -} - -// ExecExists looks up the exec instance and returns a bool if it exists or not. -// It will also return the error produced by `getConfig` -func (d *Daemon) ExecExists(name string) (bool, error) { - if _, err := d.getExecConfig(name); err != nil { - return false, err - } - return true, nil -} - -// getExecConfig looks up the exec instance by name. If the container associated -// with the exec instance is stopped or paused, it will return an error. -func (d *Daemon) getExecConfig(name string) (*exec.Config, error) { - ec := d.execCommands.Get(name) - - // If the exec is found but its container is not in the daemon's list of - // containers then it must have been deleted, in which case instead of - // saying the container isn't running, we should return a 404 so that - // the user sees the same error now that they will after the - // 5 minute clean-up loop is run which erases old/dead execs. - - if ec != nil { - if container := d.containers.Get(ec.ContainerID); container != nil { - if !container.IsRunning() { - return nil, fmt.Errorf("Container %s is not running: %s", container.ID, container.State.String()) - } - if container.IsPaused() { - return nil, errExecPaused(container.ID) - } - if container.IsRestarting() { - return nil, errContainerIsRestarting(container.ID) - } - return ec, nil - } - } - - return nil, errExecNotFound(name) -} - -func (d *Daemon) unregisterExecCommand(container *container.Container, execConfig *exec.Config) { - container.ExecCommands.Delete(execConfig.ID) - d.execCommands.Delete(execConfig.ID) -} - -func (d *Daemon) getActiveContainer(name string) (*container.Container, error) { - container, err := d.GetContainer(name) - if err != nil { - return nil, err - } - - if !container.IsRunning() { - return nil, errNotRunning{container.ID} - } - if container.IsPaused() { - return nil, errExecPaused(name) - } - if container.IsRestarting() { - return nil, errContainerIsRestarting(container.ID) - } - return container, nil -} - -// ContainerExecCreate sets up an exec in a running container. -func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (string, error) { - container, err := d.getActiveContainer(name) - if err != nil { - return "", err - } - - cmd := strslice.StrSlice(config.Cmd) - entrypoint, args := d.getEntrypointAndArgs(strslice.StrSlice{}, cmd) - - keys := []byte{} - if config.DetachKeys != "" { - keys, err = term.ToBytes(config.DetachKeys) - if err != nil { - err = fmt.Errorf("Invalid escape keys (%s) provided", config.DetachKeys) - return "", err - } - } - - execConfig := exec.NewConfig() - execConfig.OpenStdin = config.AttachStdin - execConfig.OpenStdout = config.AttachStdout - execConfig.OpenStderr = config.AttachStderr - execConfig.ContainerID = container.ID - execConfig.DetachKeys = keys - execConfig.Entrypoint = entrypoint - execConfig.Args = args - execConfig.Tty = config.Tty - execConfig.Privileged = config.Privileged - execConfig.User = config.User - - linkedEnv, err := d.setupLinkedContainers(container) - if err != nil { - return "", err - } - execConfig.Env = utils.ReplaceOrAppendEnvValues(container.CreateDaemonEnvironment(config.Tty, linkedEnv), config.Env) - if len(execConfig.User) == 0 { - execConfig.User = container.Config.User - } - - d.registerExecCommand(container, execConfig) - - d.LogContainerEvent(container, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " ")) - - return execConfig.ID, nil -} - -// ContainerExecStart starts a previously set up exec instance. The -// std streams are set up. -// If ctx is cancelled, the process is terminated. -func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) (err error) { - var ( - cStdin io.ReadCloser - cStdout, cStderr io.Writer - ) - - ec, err := d.getExecConfig(name) - if err != nil { - return errExecNotFound(name) - } - - ec.Lock() - if ec.ExitCode != nil { - ec.Unlock() - err := fmt.Errorf("Error: Exec command %s has already run", ec.ID) - return errors.NewRequestConflictError(err) - } - - if ec.Running { - ec.Unlock() - return fmt.Errorf("Error: Exec command %s is already running", ec.ID) - } - ec.Running = true - defer func() { - if err != nil { - ec.Running = false - exitCode := 126 - ec.ExitCode = &exitCode - } - }() - ec.Unlock() - - c := d.containers.Get(ec.ContainerID) - logrus.Debugf("starting exec command %s in container %s", ec.ID, c.ID) - d.LogContainerEvent(c, "exec_start: "+ec.Entrypoint+" "+strings.Join(ec.Args, " ")) - - if ec.OpenStdin && stdin != nil { - r, w := io.Pipe() - go func() { - defer w.Close() - defer logrus.Debug("Closing buffered stdin pipe") - pools.Copy(w, stdin) - }() - cStdin = r - } - if ec.OpenStdout { - cStdout = stdout - } - if ec.OpenStderr { - cStderr = stderr - } - - if ec.OpenStdin { - ec.StreamConfig.NewInputPipes() - } else { - ec.StreamConfig.NewNopInputPipe() - } - - p := libcontainerd.Process{ - Args: append([]string{ec.Entrypoint}, ec.Args...), - Env: ec.Env, - Terminal: ec.Tty, - } - - if err := execSetPlatformOpt(c, ec, &p); err != nil { - return err - } - - attachErr := container.AttachStreams(ctx, ec.StreamConfig, ec.OpenStdin, true, ec.Tty, cStdin, cStdout, cStderr, ec.DetachKeys) - - systemPid, err := d.containerd.AddProcess(ctx, c.ID, name, p, ec.InitializeStdio) - if err != nil { - return err - } - ec.Lock() - ec.Pid = systemPid - ec.Unlock() - - select { - case <-ctx.Done(): - logrus.Debugf("Sending TERM signal to process %v in container %v", name, c.ID) - d.containerd.SignalProcess(c.ID, name, int(signal.SignalMap["TERM"])) - select { - case <-time.After(termProcessTimeout * time.Second): - logrus.Infof("Container %v, process %v failed to exit within %d seconds of signal TERM - using the force", c.ID, name, termProcessTimeout) - d.containerd.SignalProcess(c.ID, name, int(signal.SignalMap["KILL"])) - case <-attachErr: - // TERM signal worked - } - return fmt.Errorf("context cancelled") - case err := <-attachErr: - if err != nil { - if _, ok := err.(container.DetachError); !ok { - return fmt.Errorf("exec attach failed with error: %v", err) - } - d.LogContainerEvent(c, "exec_detach") - } - } - return nil -} - -// execCommandGC runs a ticker to clean up the daemon references -// of exec configs that are no longer part of the container. -func (d *Daemon) execCommandGC() { - for range time.Tick(5 * time.Minute) { - var ( - cleaned int - liveExecCommands = d.containerExecIds() - ) - for id, config := range d.execCommands.Commands() { - if config.CanRemove { - cleaned++ - d.execCommands.Delete(id) - } else { - if _, exists := liveExecCommands[id]; !exists { - config.CanRemove = true - } - } - } - if cleaned > 0 { - logrus.Debugf("clean %d unused exec commands", cleaned) - } - } -} - -// containerExecIds returns a list of all the current exec ids that are in use -// and running inside a container. -func (d *Daemon) containerExecIds() map[string]struct{} { - ids := map[string]struct{}{} - for _, c := range d.containers.List() { - for _, id := range c.ExecCommands.List() { - ids[id] = struct{}{} - } - } - return ids -} diff --git a/vendor/github.com/docker/docker/daemon/exec/exec.go b/vendor/github.com/docker/docker/daemon/exec/exec.go deleted file mode 100644 index 933136f..0000000 --- a/vendor/github.com/docker/docker/daemon/exec/exec.go +++ /dev/null @@ -1,118 +0,0 @@ -package exec - -import ( - "runtime" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/container/stream" - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/pkg/stringid" -) - -// Config holds the configurations for execs. The Daemon keeps -// track of both running and finished execs so that they can be -// examined both during and after completion. -type Config struct { - sync.Mutex - StreamConfig *stream.Config - ID string - Running bool - ExitCode *int - OpenStdin bool - OpenStderr bool - OpenStdout bool - CanRemove bool - ContainerID string - DetachKeys []byte - Entrypoint string - Args []string - Tty bool - Privileged bool - User string - Env []string - Pid int -} - -// NewConfig initializes the a new exec configuration -func NewConfig() *Config { - return &Config{ - ID: stringid.GenerateNonCryptoID(), - StreamConfig: stream.NewConfig(), - } -} - -// InitializeStdio is called by libcontainerd to connect the stdio. -func (c *Config) InitializeStdio(iop libcontainerd.IOPipe) error { - c.StreamConfig.CopyToPipe(iop) - - if c.StreamConfig.Stdin() == nil && !c.Tty && runtime.GOOS == "windows" { - if iop.Stdin != nil { - if err := iop.Stdin.Close(); err != nil { - logrus.Errorf("error closing exec stdin: %+v", err) - } - } - } - - return nil -} - -// CloseStreams closes the stdio streams for the exec -func (c *Config) CloseStreams() error { - return c.StreamConfig.CloseStreams() -} - -// Store keeps track of the exec configurations. -type Store struct { - commands map[string]*Config - sync.RWMutex -} - -// NewStore initializes a new exec store. -func NewStore() *Store { - return &Store{commands: make(map[string]*Config, 0)} -} - -// Commands returns the exec configurations in the store. -func (e *Store) Commands() map[string]*Config { - e.RLock() - commands := make(map[string]*Config, len(e.commands)) - for id, config := range e.commands { - commands[id] = config - } - e.RUnlock() - return commands -} - -// Add adds a new exec configuration to the store. -func (e *Store) Add(id string, Config *Config) { - e.Lock() - e.commands[id] = Config - e.Unlock() -} - -// Get returns an exec configuration by its id. -func (e *Store) Get(id string) *Config { - e.RLock() - res := e.commands[id] - e.RUnlock() - return res -} - -// Delete removes an exec configuration from the store. -func (e *Store) Delete(id string) { - e.Lock() - delete(e.commands, id) - e.Unlock() -} - -// List returns the list of exec ids in the store. -func (e *Store) List() []string { - var IDs []string - e.RLock() - for id := range e.commands { - IDs = append(IDs, id) - } - e.RUnlock() - return IDs -} diff --git a/vendor/github.com/docker/docker/daemon/exec_linux.go b/vendor/github.com/docker/docker/daemon/exec_linux.go deleted file mode 100644 index 5aeedc3..0000000 --- a/vendor/github.com/docker/docker/daemon/exec_linux.go +++ /dev/null @@ -1,27 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/caps" - "github.com/docker/docker/daemon/exec" - "github.com/docker/docker/libcontainerd" - "github.com/opencontainers/runtime-spec/specs-go" -) - -func execSetPlatformOpt(c *container.Container, ec *exec.Config, p *libcontainerd.Process) error { - if len(ec.User) > 0 { - uid, gid, additionalGids, err := getUser(c, ec.User) - if err != nil { - return err - } - p.User = &specs.User{ - UID: uid, - GID: gid, - AdditionalGids: additionalGids, - } - } - if ec.Privileged { - p.Capabilities = caps.GetAllCapabilities() - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/exec_solaris.go b/vendor/github.com/docker/docker/daemon/exec_solaris.go deleted file mode 100644 index 7003355..0000000 --- a/vendor/github.com/docker/docker/daemon/exec_solaris.go +++ /dev/null @@ -1,11 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/exec" - "github.com/docker/docker/libcontainerd" -) - -func execSetPlatformOpt(c *container.Container, ec *exec.Config, p *libcontainerd.Process) error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/exec_windows.go b/vendor/github.com/docker/docker/daemon/exec_windows.go deleted file mode 100644 index 1d6974c..0000000 --- a/vendor/github.com/docker/docker/daemon/exec_windows.go +++ /dev/null @@ -1,14 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/exec" - "github.com/docker/docker/libcontainerd" -) - -func execSetPlatformOpt(c *container.Container, ec *exec.Config, p *libcontainerd.Process) error { - // Process arguments need to be escaped before sending to OCI. - p.Args = escapeArgs(p.Args) - p.User.Username = ec.User - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/export.go b/vendor/github.com/docker/docker/daemon/export.go deleted file mode 100644 index 5ef6dbb..0000000 --- a/vendor/github.com/docker/docker/daemon/export.go +++ /dev/null @@ -1,60 +0,0 @@ -package daemon - -import ( - "fmt" - "io" - "runtime" - - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/ioutils" -) - -// ContainerExport writes the contents of the container to the given -// writer. An error is returned if the container cannot be found. -func (daemon *Daemon) ContainerExport(name string, out io.Writer) error { - if runtime.GOOS == "windows" { - return fmt.Errorf("the daemon on this platform does not support export of a container") - } - - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - data, err := daemon.containerExport(container) - if err != nil { - return fmt.Errorf("Error exporting container %s: %v", name, err) - } - defer data.Close() - - // Stream the entire contents of the container (basically a volatile snapshot) - if _, err := io.Copy(out, data); err != nil { - return fmt.Errorf("Error exporting container %s: %v", name, err) - } - return nil -} - -func (daemon *Daemon) containerExport(container *container.Container) (io.ReadCloser, error) { - if err := daemon.Mount(container); err != nil { - return nil, err - } - - uidMaps, gidMaps := daemon.GetUIDGIDMaps() - archive, err := archive.TarWithOptions(container.BaseFS, &archive.TarOptions{ - Compression: archive.Uncompressed, - UIDMaps: uidMaps, - GIDMaps: gidMaps, - }) - if err != nil { - daemon.Unmount(container) - return nil, err - } - arch := ioutils.NewReadCloserWrapper(archive, func() error { - err := archive.Close() - daemon.Unmount(container) - return err - }) - daemon.LogContainerEvent(container, "export") - return arch, err -} diff --git a/vendor/github.com/docker/docker/daemon/getsize_unix.go b/vendor/github.com/docker/docker/daemon/getsize_unix.go deleted file mode 100644 index 707323a..0000000 --- a/vendor/github.com/docker/docker/daemon/getsize_unix.go +++ /dev/null @@ -1,41 +0,0 @@ -// +build linux freebsd solaris - -package daemon - -import ( - "github.com/Sirupsen/logrus" - "github.com/docker/docker/container" -) - -// getSize returns the real size & virtual size of the container. -func (daemon *Daemon) getSize(container *container.Container) (int64, int64) { - var ( - sizeRw, sizeRootfs int64 - err error - ) - - if err := daemon.Mount(container); err != nil { - logrus.Errorf("Failed to compute size of container rootfs %s: %s", container.ID, err) - return sizeRw, sizeRootfs - } - defer daemon.Unmount(container) - - sizeRw, err = container.RWLayer.Size() - if err != nil { - logrus.Errorf("Driver %s couldn't return diff size of container %s: %s", - daemon.GraphDriverName(), container.ID, err) - // FIXME: GetSize should return an error. Not changing it now in case - // there is a side-effect. - sizeRw = -1 - } - - if parent := container.RWLayer.Parent(); parent != nil { - sizeRootfs, err = parent.Size() - if err != nil { - sizeRootfs = -1 - } else if sizeRw != -1 { - sizeRootfs += sizeRw - } - } - return sizeRw, sizeRootfs -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/aufs.go b/vendor/github.com/docker/docker/daemon/graphdriver/aufs/aufs.go deleted file mode 100644 index ec55ea4..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/aufs.go +++ /dev/null @@ -1,669 +0,0 @@ -// +build linux - -/* - -aufs driver directory structure - - . - ├── layers // Metadata of layers - │ ├── 1 - │ ├── 2 - │ └── 3 - ├── diff // Content of the layer - │ ├── 1 // Contains layers that need to be mounted for the id - │ ├── 2 - │ └── 3 - └── mnt // Mount points for the rw layers to be mounted - ├── 1 - ├── 2 - └── 3 - -*/ - -package aufs - -import ( - "bufio" - "fmt" - "io" - "io/ioutil" - "os" - "os/exec" - "path" - "path/filepath" - "strings" - "sync" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - "github.com/vbatts/tar-split/tar/storage" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/chrootarchive" - "github.com/docker/docker/pkg/directory" - "github.com/docker/docker/pkg/idtools" - mountpk "github.com/docker/docker/pkg/mount" - - "github.com/opencontainers/runc/libcontainer/label" - rsystem "github.com/opencontainers/runc/libcontainer/system" -) - -var ( - // ErrAufsNotSupported is returned if aufs is not supported by the host. - ErrAufsNotSupported = fmt.Errorf("AUFS was not found in /proc/filesystems") - // ErrAufsNested means aufs cannot be used bc we are in a user namespace - ErrAufsNested = fmt.Errorf("AUFS cannot be used in non-init user namespace") - backingFs = "" - - enableDirpermLock sync.Once - enableDirperm bool -) - -func init() { - graphdriver.Register("aufs", Init) -} - -// Driver contains information about the filesystem mounted. -type Driver struct { - sync.Mutex - root string - uidMaps []idtools.IDMap - gidMaps []idtools.IDMap - ctr *graphdriver.RefCounter - pathCacheLock sync.Mutex - pathCache map[string]string - naiveDiff graphdriver.DiffDriver -} - -// Init returns a new AUFS driver. -// An error is returned if AUFS is not supported. -func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - - // Try to load the aufs kernel module - if err := supportsAufs(); err != nil { - return nil, graphdriver.ErrNotSupported - } - - fsMagic, err := graphdriver.GetFSMagic(root) - if err != nil { - return nil, err - } - if fsName, ok := graphdriver.FsNames[fsMagic]; ok { - backingFs = fsName - } - - switch fsMagic { - case graphdriver.FsMagicAufs, graphdriver.FsMagicBtrfs, graphdriver.FsMagicEcryptfs: - logrus.Errorf("AUFS is not supported over %s", backingFs) - return nil, graphdriver.ErrIncompatibleFS - } - - paths := []string{ - "mnt", - "diff", - "layers", - } - - a := &Driver{ - root: root, - uidMaps: uidMaps, - gidMaps: gidMaps, - pathCache: make(map[string]string), - ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicAufs)), - } - - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) - if err != nil { - return nil, err - } - // Create the root aufs driver dir and return - // if it already exists - // If not populate the dir structure - if err := idtools.MkdirAllAs(root, 0700, rootUID, rootGID); err != nil { - if os.IsExist(err) { - return a, nil - } - return nil, err - } - - if err := mountpk.MakePrivate(root); err != nil { - return nil, err - } - - // Populate the dir structure - for _, p := range paths { - if err := idtools.MkdirAllAs(path.Join(root, p), 0700, rootUID, rootGID); err != nil { - return nil, err - } - } - - a.naiveDiff = graphdriver.NewNaiveDiffDriver(a, uidMaps, gidMaps) - return a, nil -} - -// Return a nil error if the kernel supports aufs -// We cannot modprobe because inside dind modprobe fails -// to run -func supportsAufs() error { - // We can try to modprobe aufs first before looking at - // proc/filesystems for when aufs is supported - exec.Command("modprobe", "aufs").Run() - - if rsystem.RunningInUserNS() { - return ErrAufsNested - } - - f, err := os.Open("/proc/filesystems") - if err != nil { - return err - } - defer f.Close() - - s := bufio.NewScanner(f) - for s.Scan() { - if strings.Contains(s.Text(), "aufs") { - return nil - } - } - return ErrAufsNotSupported -} - -func (a *Driver) rootPath() string { - return a.root -} - -func (*Driver) String() string { - return "aufs" -} - -// Status returns current information about the filesystem such as root directory, number of directories mounted, etc. -func (a *Driver) Status() [][2]string { - ids, _ := loadIds(path.Join(a.rootPath(), "layers")) - return [][2]string{ - {"Root Dir", a.rootPath()}, - {"Backing Filesystem", backingFs}, - {"Dirs", fmt.Sprintf("%d", len(ids))}, - {"Dirperm1 Supported", fmt.Sprintf("%v", useDirperm())}, - } -} - -// GetMetadata not implemented -func (a *Driver) GetMetadata(id string) (map[string]string, error) { - return nil, nil -} - -// Exists returns true if the given id is registered with -// this driver -func (a *Driver) Exists(id string) bool { - if _, err := os.Lstat(path.Join(a.rootPath(), "layers", id)); err != nil { - return false - } - return true -} - -// CreateReadWrite creates a layer that is writable for use as a container -// file system. -func (a *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error { - return a.Create(id, parent, opts) -} - -// Create three folders for each id -// mnt, layers, and diff -func (a *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error { - - if opts != nil && len(opts.StorageOpt) != 0 { - return fmt.Errorf("--storage-opt is not supported for aufs") - } - - if err := a.createDirsFor(id); err != nil { - return err - } - // Write the layers metadata - f, err := os.Create(path.Join(a.rootPath(), "layers", id)) - if err != nil { - return err - } - defer f.Close() - - if parent != "" { - ids, err := getParentIDs(a.rootPath(), parent) - if err != nil { - return err - } - - if _, err := fmt.Fprintln(f, parent); err != nil { - return err - } - for _, i := range ids { - if _, err := fmt.Fprintln(f, i); err != nil { - return err - } - } - } - - return nil -} - -// createDirsFor creates two directories for the given id. -// mnt and diff -func (a *Driver) createDirsFor(id string) error { - paths := []string{ - "mnt", - "diff", - } - - rootUID, rootGID, err := idtools.GetRootUIDGID(a.uidMaps, a.gidMaps) - if err != nil { - return err - } - // Directory permission is 0755. - // The path of directories are /mnt/ - // and /diff/ - for _, p := range paths { - if err := idtools.MkdirAllAs(path.Join(a.rootPath(), p, id), 0755, rootUID, rootGID); err != nil { - return err - } - } - return nil -} - -// Helper function to debug EBUSY errors on remove. -func debugEBusy(mountPath string) (out []string, err error) { - // lsof is not part of GNU coreutils. This is a best effort - // attempt to detect offending processes. - c := exec.Command("lsof") - - r, err := c.StdoutPipe() - if err != nil { - return nil, fmt.Errorf("Assigning pipes failed with %v", err) - } - - if err := c.Start(); err != nil { - return nil, fmt.Errorf("Starting %s failed with %v", c.Path, err) - } - - defer func() { - waiterr := c.Wait() - if waiterr != nil && err == nil { - err = fmt.Errorf("Waiting for %s failed with %v", c.Path, waiterr) - } - }() - - sc := bufio.NewScanner(r) - for sc.Scan() { - entry := sc.Text() - if strings.Contains(entry, mountPath) { - out = append(out, entry, "\n") - } - } - - return out, nil -} - -// Remove will unmount and remove the given id. -func (a *Driver) Remove(id string) error { - a.pathCacheLock.Lock() - mountpoint, exists := a.pathCache[id] - a.pathCacheLock.Unlock() - if !exists { - mountpoint = a.getMountpoint(id) - } - - var retries int - for { - mounted, err := a.mounted(mountpoint) - if err != nil { - return err - } - if !mounted { - break - } - - if err := a.unmount(mountpoint); err != nil { - if err != syscall.EBUSY { - return fmt.Errorf("aufs: unmount error: %s: %v", mountpoint, err) - } - if retries >= 5 { - out, debugErr := debugEBusy(mountpoint) - if debugErr == nil { - logrus.Warnf("debugEBusy returned %v", out) - } - return fmt.Errorf("aufs: unmount error after retries: %s: %v", mountpoint, err) - } - // If unmount returns EBUSY, it could be a transient error. Sleep and retry. - retries++ - logrus.Warnf("unmount failed due to EBUSY: retry count: %d", retries) - time.Sleep(100 * time.Millisecond) - continue - } - break - } - - // Atomically remove each directory in turn by first moving it out of the - // way (so that docker doesn't find it anymore) before doing removal of - // the whole tree. - tmpMntPath := path.Join(a.mntPath(), fmt.Sprintf("%s-removing", id)) - if err := os.Rename(mountpoint, tmpMntPath); err != nil && !os.IsNotExist(err) { - if err == syscall.EBUSY { - logrus.Warn("os.Rename err due to EBUSY") - out, debugErr := debugEBusy(mountpoint) - if debugErr == nil { - logrus.Warnf("debugEBusy returned %v", out) - } - } - return err - } - defer os.RemoveAll(tmpMntPath) - - tmpDiffpath := path.Join(a.diffPath(), fmt.Sprintf("%s-removing", id)) - if err := os.Rename(a.getDiffPath(id), tmpDiffpath); err != nil && !os.IsNotExist(err) { - return err - } - defer os.RemoveAll(tmpDiffpath) - - // Remove the layers file for the id - if err := os.Remove(path.Join(a.rootPath(), "layers", id)); err != nil && !os.IsNotExist(err) { - return err - } - - a.pathCacheLock.Lock() - delete(a.pathCache, id) - a.pathCacheLock.Unlock() - return nil -} - -// Get returns the rootfs path for the id. -// This will mount the dir at its given path -func (a *Driver) Get(id, mountLabel string) (string, error) { - parents, err := a.getParentLayerPaths(id) - if err != nil && !os.IsNotExist(err) { - return "", err - } - - a.pathCacheLock.Lock() - m, exists := a.pathCache[id] - a.pathCacheLock.Unlock() - - if !exists { - m = a.getDiffPath(id) - if len(parents) > 0 { - m = a.getMountpoint(id) - } - } - if count := a.ctr.Increment(m); count > 1 { - return m, nil - } - - // If a dir does not have a parent ( no layers )do not try to mount - // just return the diff path to the data - if len(parents) > 0 { - if err := a.mount(id, m, mountLabel, parents); err != nil { - return "", err - } - } - - a.pathCacheLock.Lock() - a.pathCache[id] = m - a.pathCacheLock.Unlock() - return m, nil -} - -// Put unmounts and updates list of active mounts. -func (a *Driver) Put(id string) error { - a.pathCacheLock.Lock() - m, exists := a.pathCache[id] - if !exists { - m = a.getMountpoint(id) - a.pathCache[id] = m - } - a.pathCacheLock.Unlock() - if count := a.ctr.Decrement(m); count > 0 { - return nil - } - - err := a.unmount(m) - if err != nil { - logrus.Debugf("Failed to unmount %s aufs: %v", id, err) - } - return err -} - -// isParent returns if the passed in parent is the direct parent of the passed in layer -func (a *Driver) isParent(id, parent string) bool { - parents, _ := getParentIDs(a.rootPath(), id) - if parent == "" && len(parents) > 0 { - return false - } - return !(len(parents) > 0 && parent != parents[0]) -} - -// Diff produces an archive of the changes between the specified -// layer and its parent layer which may be "". -func (a *Driver) Diff(id, parent string) (io.ReadCloser, error) { - if !a.isParent(id, parent) { - return a.naiveDiff.Diff(id, parent) - } - - // AUFS doesn't need the parent layer to produce a diff. - return archive.TarWithOptions(path.Join(a.rootPath(), "diff", id), &archive.TarOptions{ - Compression: archive.Uncompressed, - ExcludePatterns: []string{archive.WhiteoutMetaPrefix + "*", "!" + archive.WhiteoutOpaqueDir}, - UIDMaps: a.uidMaps, - GIDMaps: a.gidMaps, - }) -} - -type fileGetNilCloser struct { - storage.FileGetter -} - -func (f fileGetNilCloser) Close() error { - return nil -} - -// DiffGetter returns a FileGetCloser that can read files from the directory that -// contains files for the layer differences. Used for direct access for tar-split. -func (a *Driver) DiffGetter(id string) (graphdriver.FileGetCloser, error) { - p := path.Join(a.rootPath(), "diff", id) - return fileGetNilCloser{storage.NewPathFileGetter(p)}, nil -} - -func (a *Driver) applyDiff(id string, diff io.Reader) error { - return chrootarchive.UntarUncompressed(diff, path.Join(a.rootPath(), "diff", id), &archive.TarOptions{ - UIDMaps: a.uidMaps, - GIDMaps: a.gidMaps, - }) -} - -// DiffSize calculates the changes between the specified id -// and its parent and returns the size in bytes of the changes -// relative to its base filesystem directory. -func (a *Driver) DiffSize(id, parent string) (size int64, err error) { - if !a.isParent(id, parent) { - return a.naiveDiff.DiffSize(id, parent) - } - // AUFS doesn't need the parent layer to calculate the diff size. - return directory.Size(path.Join(a.rootPath(), "diff", id)) -} - -// ApplyDiff extracts the changeset from the given diff into the -// layer with the specified id and parent, returning the size of the -// new layer in bytes. -func (a *Driver) ApplyDiff(id, parent string, diff io.Reader) (size int64, err error) { - if !a.isParent(id, parent) { - return a.naiveDiff.ApplyDiff(id, parent, diff) - } - - // AUFS doesn't need the parent id to apply the diff if it is the direct parent. - if err = a.applyDiff(id, diff); err != nil { - return - } - - return a.DiffSize(id, parent) -} - -// Changes produces a list of changes between the specified layer -// and its parent layer. If parent is "", then all changes will be ADD changes. -func (a *Driver) Changes(id, parent string) ([]archive.Change, error) { - if !a.isParent(id, parent) { - return a.naiveDiff.Changes(id, parent) - } - - // AUFS doesn't have snapshots, so we need to get changes from all parent - // layers. - layers, err := a.getParentLayerPaths(id) - if err != nil { - return nil, err - } - return archive.Changes(layers, path.Join(a.rootPath(), "diff", id)) -} - -func (a *Driver) getParentLayerPaths(id string) ([]string, error) { - parentIds, err := getParentIDs(a.rootPath(), id) - if err != nil { - return nil, err - } - layers := make([]string, len(parentIds)) - - // Get the diff paths for all the parent ids - for i, p := range parentIds { - layers[i] = path.Join(a.rootPath(), "diff", p) - } - return layers, nil -} - -func (a *Driver) mount(id string, target string, mountLabel string, layers []string) error { - a.Lock() - defer a.Unlock() - - // If the id is mounted or we get an error return - if mounted, err := a.mounted(target); err != nil || mounted { - return err - } - - rw := a.getDiffPath(id) - - if err := a.aufsMount(layers, rw, target, mountLabel); err != nil { - return fmt.Errorf("error creating aufs mount to %s: %v", target, err) - } - return nil -} - -func (a *Driver) unmount(mountPath string) error { - a.Lock() - defer a.Unlock() - - if mounted, err := a.mounted(mountPath); err != nil || !mounted { - return err - } - if err := Unmount(mountPath); err != nil { - return err - } - return nil -} - -func (a *Driver) mounted(mountpoint string) (bool, error) { - return graphdriver.Mounted(graphdriver.FsMagicAufs, mountpoint) -} - -// Cleanup aufs and unmount all mountpoints -func (a *Driver) Cleanup() error { - var dirs []string - if err := filepath.Walk(a.mntPath(), func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() { - return nil - } - dirs = append(dirs, path) - return nil - }); err != nil { - return err - } - - for _, m := range dirs { - if err := a.unmount(m); err != nil { - logrus.Debugf("aufs error unmounting %s: %s", m, err) - } - } - return mountpk.Unmount(a.root) -} - -func (a *Driver) aufsMount(ro []string, rw, target, mountLabel string) (err error) { - defer func() { - if err != nil { - Unmount(target) - } - }() - - // Mount options are clipped to page size(4096 bytes). If there are more - // layers then these are remounted individually using append. - - offset := 54 - if useDirperm() { - offset += len("dirperm1") - } - b := make([]byte, syscall.Getpagesize()-len(mountLabel)-offset) // room for xino & mountLabel - bp := copy(b, fmt.Sprintf("br:%s=rw", rw)) - - index := 0 - for ; index < len(ro); index++ { - layer := fmt.Sprintf(":%s=ro+wh", ro[index]) - if bp+len(layer) > len(b) { - break - } - bp += copy(b[bp:], layer) - } - - opts := "dio,xino=/dev/shm/aufs.xino" - if useDirperm() { - opts += ",dirperm1" - } - data := label.FormatMountLabel(fmt.Sprintf("%s,%s", string(b[:bp]), opts), mountLabel) - if err = mount("none", target, "aufs", 0, data); err != nil { - return - } - - for ; index < len(ro); index++ { - layer := fmt.Sprintf(":%s=ro+wh", ro[index]) - data := label.FormatMountLabel(fmt.Sprintf("append%s", layer), mountLabel) - if err = mount("none", target, "aufs", syscall.MS_REMOUNT, data); err != nil { - return - } - } - - return -} - -// useDirperm checks dirperm1 mount option can be used with the current -// version of aufs. -func useDirperm() bool { - enableDirpermLock.Do(func() { - base, err := ioutil.TempDir("", "docker-aufs-base") - if err != nil { - logrus.Errorf("error checking dirperm1: %v", err) - return - } - defer os.RemoveAll(base) - - union, err := ioutil.TempDir("", "docker-aufs-union") - if err != nil { - logrus.Errorf("error checking dirperm1: %v", err) - return - } - defer os.RemoveAll(union) - - opts := fmt.Sprintf("br:%s,dirperm1,xino=/dev/shm/aufs.xino", base) - if err := mount("none", union, "aufs", 0, opts); err != nil { - return - } - enableDirperm = true - if err := Unmount(union); err != nil { - logrus.Errorf("error checking dirperm1: failed to unmount %v", err) - } - }) - return enableDirperm -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/aufs_test.go b/vendor/github.com/docker/docker/daemon/graphdriver/aufs/aufs_test.go deleted file mode 100644 index dc3c6a3..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/aufs_test.go +++ /dev/null @@ -1,802 +0,0 @@ -// +build linux - -package aufs - -import ( - "crypto/sha256" - "encoding/hex" - "fmt" - "io/ioutil" - "os" - "path" - "sync" - "testing" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/reexec" - "github.com/docker/docker/pkg/stringid" -) - -var ( - tmpOuter = path.Join(os.TempDir(), "aufs-tests") - tmp = path.Join(tmpOuter, "aufs") -) - -func init() { - reexec.Init() -} - -func testInit(dir string, t testing.TB) graphdriver.Driver { - d, err := Init(dir, nil, nil, nil) - if err != nil { - if err == graphdriver.ErrNotSupported { - t.Skip(err) - } else { - t.Fatal(err) - } - } - return d -} - -func newDriver(t testing.TB) *Driver { - if err := os.MkdirAll(tmp, 0755); err != nil { - t.Fatal(err) - } - - d := testInit(tmp, t) - return d.(*Driver) -} - -func TestNewDriver(t *testing.T) { - if err := os.MkdirAll(tmp, 0755); err != nil { - t.Fatal(err) - } - - d := testInit(tmp, t) - defer os.RemoveAll(tmp) - if d == nil { - t.Fatalf("Driver should not be nil") - } -} - -func TestAufsString(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if d.String() != "aufs" { - t.Fatalf("Expected aufs got %s", d.String()) - } -} - -func TestCreateDirStructure(t *testing.T) { - newDriver(t) - defer os.RemoveAll(tmp) - - paths := []string{ - "mnt", - "layers", - "diff", - } - - for _, p := range paths { - if _, err := os.Stat(path.Join(tmp, p)); err != nil { - t.Fatal(err) - } - } -} - -// We should be able to create two drivers with the same dir structure -func TestNewDriverFromExistingDir(t *testing.T) { - if err := os.MkdirAll(tmp, 0755); err != nil { - t.Fatal(err) - } - - testInit(tmp, t) - testInit(tmp, t) - os.RemoveAll(tmp) -} - -func TestCreateNewDir(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } -} - -func TestCreateNewDirStructure(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - - paths := []string{ - "mnt", - "diff", - "layers", - } - - for _, p := range paths { - if _, err := os.Stat(path.Join(tmp, p, "1")); err != nil { - t.Fatal(err) - } - } -} - -func TestRemoveImage(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - - if err := d.Remove("1"); err != nil { - t.Fatal(err) - } - - paths := []string{ - "mnt", - "diff", - "layers", - } - - for _, p := range paths { - if _, err := os.Stat(path.Join(tmp, p, "1")); err == nil { - t.Fatalf("Error should not be nil because dirs with id 1 should be delted: %s", p) - } - } -} - -func TestGetWithoutParent(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - - diffPath, err := d.Get("1", "") - if err != nil { - t.Fatal(err) - } - expected := path.Join(tmp, "diff", "1") - if diffPath != expected { - t.Fatalf("Expected path %s got %s", expected, diffPath) - } -} - -func TestCleanupWithNoDirs(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Cleanup(); err != nil { - t.Fatal(err) - } -} - -func TestCleanupWithDir(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - - if err := d.Cleanup(); err != nil { - t.Fatal(err) - } -} - -func TestMountedFalseResponse(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - - response, err := d.mounted(d.getDiffPath("1")) - if err != nil { - t.Fatal(err) - } - - if response != false { - t.Fatalf("Response if dir id 1 is mounted should be false") - } -} - -func TestMountedTrueReponse(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - defer d.Cleanup() - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - if err := d.Create("2", "1", nil); err != nil { - t.Fatal(err) - } - - _, err := d.Get("2", "") - if err != nil { - t.Fatal(err) - } - - response, err := d.mounted(d.pathCache["2"]) - if err != nil { - t.Fatal(err) - } - - if response != true { - t.Fatalf("Response if dir id 2 is mounted should be true") - } -} - -func TestMountWithParent(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - if err := d.Create("2", "1", nil); err != nil { - t.Fatal(err) - } - - defer func() { - if err := d.Cleanup(); err != nil { - t.Fatal(err) - } - }() - - mntPath, err := d.Get("2", "") - if err != nil { - t.Fatal(err) - } - if mntPath == "" { - t.Fatal("mntPath should not be empty string") - } - - expected := path.Join(tmp, "mnt", "2") - if mntPath != expected { - t.Fatalf("Expected %s got %s", expected, mntPath) - } -} - -func TestRemoveMountedDir(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - if err := d.Create("2", "1", nil); err != nil { - t.Fatal(err) - } - - defer func() { - if err := d.Cleanup(); err != nil { - t.Fatal(err) - } - }() - - mntPath, err := d.Get("2", "") - if err != nil { - t.Fatal(err) - } - if mntPath == "" { - t.Fatal("mntPath should not be empty string") - } - - mounted, err := d.mounted(d.pathCache["2"]) - if err != nil { - t.Fatal(err) - } - - if !mounted { - t.Fatalf("Dir id 2 should be mounted") - } - - if err := d.Remove("2"); err != nil { - t.Fatal(err) - } -} - -func TestCreateWithInvalidParent(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Create("1", "docker", nil); err == nil { - t.Fatalf("Error should not be nil with parent does not exist") - } -} - -func TestGetDiff(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.CreateReadWrite("1", "", nil); err != nil { - t.Fatal(err) - } - - diffPath, err := d.Get("1", "") - if err != nil { - t.Fatal(err) - } - - // Add a file to the diff path with a fixed size - size := int64(1024) - - f, err := os.Create(path.Join(diffPath, "test_file")) - if err != nil { - t.Fatal(err) - } - if err := f.Truncate(size); err != nil { - t.Fatal(err) - } - f.Close() - - a, err := d.Diff("1", "") - if err != nil { - t.Fatal(err) - } - if a == nil { - t.Fatalf("Archive should not be nil") - } -} - -func TestChanges(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - - if err := d.CreateReadWrite("2", "1", nil); err != nil { - t.Fatal(err) - } - - defer func() { - if err := d.Cleanup(); err != nil { - t.Fatal(err) - } - }() - - mntPoint, err := d.Get("2", "") - if err != nil { - t.Fatal(err) - } - - // Create a file to save in the mountpoint - f, err := os.Create(path.Join(mntPoint, "test.txt")) - if err != nil { - t.Fatal(err) - } - - if _, err := f.WriteString("testline"); err != nil { - t.Fatal(err) - } - if err := f.Close(); err != nil { - t.Fatal(err) - } - - changes, err := d.Changes("2", "") - if err != nil { - t.Fatal(err) - } - if len(changes) != 1 { - t.Fatalf("Dir 2 should have one change from parent got %d", len(changes)) - } - change := changes[0] - - expectedPath := "/test.txt" - if change.Path != expectedPath { - t.Fatalf("Expected path %s got %s", expectedPath, change.Path) - } - - if change.Kind != archive.ChangeAdd { - t.Fatalf("Change kind should be ChangeAdd got %s", change.Kind) - } - - if err := d.CreateReadWrite("3", "2", nil); err != nil { - t.Fatal(err) - } - mntPoint, err = d.Get("3", "") - if err != nil { - t.Fatal(err) - } - - // Create a file to save in the mountpoint - f, err = os.Create(path.Join(mntPoint, "test2.txt")) - if err != nil { - t.Fatal(err) - } - - if _, err := f.WriteString("testline"); err != nil { - t.Fatal(err) - } - if err := f.Close(); err != nil { - t.Fatal(err) - } - - changes, err = d.Changes("3", "2") - if err != nil { - t.Fatal(err) - } - - if len(changes) != 1 { - t.Fatalf("Dir 2 should have one change from parent got %d", len(changes)) - } - change = changes[0] - - expectedPath = "/test2.txt" - if change.Path != expectedPath { - t.Fatalf("Expected path %s got %s", expectedPath, change.Path) - } - - if change.Kind != archive.ChangeAdd { - t.Fatalf("Change kind should be ChangeAdd got %s", change.Kind) - } -} - -func TestDiffSize(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - - if err := d.CreateReadWrite("1", "", nil); err != nil { - t.Fatal(err) - } - - diffPath, err := d.Get("1", "") - if err != nil { - t.Fatal(err) - } - - // Add a file to the diff path with a fixed size - size := int64(1024) - - f, err := os.Create(path.Join(diffPath, "test_file")) - if err != nil { - t.Fatal(err) - } - if err := f.Truncate(size); err != nil { - t.Fatal(err) - } - s, err := f.Stat() - if err != nil { - t.Fatal(err) - } - size = s.Size() - if err := f.Close(); err != nil { - t.Fatal(err) - } - - diffSize, err := d.DiffSize("1", "") - if err != nil { - t.Fatal(err) - } - if diffSize != size { - t.Fatalf("Expected size to be %d got %d", size, diffSize) - } -} - -func TestChildDiffSize(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - defer d.Cleanup() - - if err := d.CreateReadWrite("1", "", nil); err != nil { - t.Fatal(err) - } - - diffPath, err := d.Get("1", "") - if err != nil { - t.Fatal(err) - } - - // Add a file to the diff path with a fixed size - size := int64(1024) - - f, err := os.Create(path.Join(diffPath, "test_file")) - if err != nil { - t.Fatal(err) - } - if err := f.Truncate(size); err != nil { - t.Fatal(err) - } - s, err := f.Stat() - if err != nil { - t.Fatal(err) - } - size = s.Size() - if err := f.Close(); err != nil { - t.Fatal(err) - } - - diffSize, err := d.DiffSize("1", "") - if err != nil { - t.Fatal(err) - } - if diffSize != size { - t.Fatalf("Expected size to be %d got %d", size, diffSize) - } - - if err := d.Create("2", "1", nil); err != nil { - t.Fatal(err) - } - - diffSize, err = d.DiffSize("2", "1") - if err != nil { - t.Fatal(err) - } - // The diff size for the child should be zero - if diffSize != 0 { - t.Fatalf("Expected size to be %d got %d", 0, diffSize) - } -} - -func TestExists(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - defer d.Cleanup() - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - - if d.Exists("none") { - t.Fatal("id none should not exist in the driver") - } - - if !d.Exists("1") { - t.Fatal("id 1 should exist in the driver") - } -} - -func TestStatus(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - defer d.Cleanup() - - if err := d.Create("1", "", nil); err != nil { - t.Fatal(err) - } - - status := d.Status() - if status == nil || len(status) == 0 { - t.Fatal("Status should not be nil or empty") - } - rootDir := status[0] - dirs := status[2] - if rootDir[0] != "Root Dir" { - t.Fatalf("Expected Root Dir got %s", rootDir[0]) - } - if rootDir[1] != d.rootPath() { - t.Fatalf("Expected %s got %s", d.rootPath(), rootDir[1]) - } - if dirs[0] != "Dirs" { - t.Fatalf("Expected Dirs got %s", dirs[0]) - } - if dirs[1] != "1" { - t.Fatalf("Expected 1 got %s", dirs[1]) - } -} - -func TestApplyDiff(t *testing.T) { - d := newDriver(t) - defer os.RemoveAll(tmp) - defer d.Cleanup() - - if err := d.CreateReadWrite("1", "", nil); err != nil { - t.Fatal(err) - } - - diffPath, err := d.Get("1", "") - if err != nil { - t.Fatal(err) - } - - // Add a file to the diff path with a fixed size - size := int64(1024) - - f, err := os.Create(path.Join(diffPath, "test_file")) - if err != nil { - t.Fatal(err) - } - if err := f.Truncate(size); err != nil { - t.Fatal(err) - } - f.Close() - - diff, err := d.Diff("1", "") - if err != nil { - t.Fatal(err) - } - - if err := d.Create("2", "", nil); err != nil { - t.Fatal(err) - } - if err := d.Create("3", "2", nil); err != nil { - t.Fatal(err) - } - - if err := d.applyDiff("3", diff); err != nil { - t.Fatal(err) - } - - // Ensure that the file is in the mount point for id 3 - - mountPoint, err := d.Get("3", "") - if err != nil { - t.Fatal(err) - } - if _, err := os.Stat(path.Join(mountPoint, "test_file")); err != nil { - t.Fatal(err) - } -} - -func hash(c string) string { - h := sha256.New() - fmt.Fprint(h, c) - return hex.EncodeToString(h.Sum(nil)) -} - -func testMountMoreThan42Layers(t *testing.T, mountPath string) { - if err := os.MkdirAll(mountPath, 0755); err != nil { - t.Fatal(err) - } - - defer os.RemoveAll(mountPath) - d := testInit(mountPath, t).(*Driver) - defer d.Cleanup() - var last string - var expected int - - for i := 1; i < 127; i++ { - expected++ - var ( - parent = fmt.Sprintf("%d", i-1) - current = fmt.Sprintf("%d", i) - ) - - if parent == "0" { - parent = "" - } else { - parent = hash(parent) - } - current = hash(current) - - if err := d.CreateReadWrite(current, parent, nil); err != nil { - t.Logf("Current layer %d", i) - t.Error(err) - } - point, err := d.Get(current, "") - if err != nil { - t.Logf("Current layer %d", i) - t.Error(err) - } - f, err := os.Create(path.Join(point, current)) - if err != nil { - t.Logf("Current layer %d", i) - t.Error(err) - } - f.Close() - - if i%10 == 0 { - if err := os.Remove(path.Join(point, parent)); err != nil { - t.Logf("Current layer %d", i) - t.Error(err) - } - expected-- - } - last = current - } - - // Perform the actual mount for the top most image - point, err := d.Get(last, "") - if err != nil { - t.Error(err) - } - files, err := ioutil.ReadDir(point) - if err != nil { - t.Error(err) - } - if len(files) != expected { - t.Errorf("Expected %d got %d", expected, len(files)) - } -} - -func TestMountMoreThan42Layers(t *testing.T) { - os.RemoveAll(tmpOuter) - testMountMoreThan42Layers(t, tmp) -} - -func TestMountMoreThan42LayersMatchingPathLength(t *testing.T) { - defer os.RemoveAll(tmpOuter) - zeroes := "0" - for { - // This finds a mount path so that when combined into aufs mount options - // 4096 byte boundary would be in between the paths or in permission - // section. For '/tmp' it will use '/tmp/aufs-tests/00000000/aufs' - mountPath := path.Join(tmpOuter, zeroes, "aufs") - pathLength := 77 + len(mountPath) - - if mod := 4095 % pathLength; mod == 0 || mod > pathLength-2 { - t.Logf("Using path: %s", mountPath) - testMountMoreThan42Layers(t, mountPath) - return - } - zeroes += "0" - } -} - -func BenchmarkConcurrentAccess(b *testing.B) { - b.StopTimer() - b.ResetTimer() - - d := newDriver(b) - defer os.RemoveAll(tmp) - defer d.Cleanup() - - numConcurent := 256 - // create a bunch of ids - var ids []string - for i := 0; i < numConcurent; i++ { - ids = append(ids, stringid.GenerateNonCryptoID()) - } - - if err := d.Create(ids[0], "", nil); err != nil { - b.Fatal(err) - } - - if err := d.Create(ids[1], ids[0], nil); err != nil { - b.Fatal(err) - } - - parent := ids[1] - ids = append(ids[2:]) - - chErr := make(chan error, numConcurent) - var outerGroup sync.WaitGroup - outerGroup.Add(len(ids)) - b.StartTimer() - - // here's the actual bench - for _, id := range ids { - go func(id string) { - defer outerGroup.Done() - if err := d.Create(id, parent, nil); err != nil { - b.Logf("Create %s failed", id) - chErr <- err - return - } - var innerGroup sync.WaitGroup - for i := 0; i < b.N; i++ { - innerGroup.Add(1) - go func() { - d.Get(id, "") - d.Put(id) - innerGroup.Done() - }() - } - innerGroup.Wait() - d.Remove(id) - }(id) - } - - outerGroup.Wait() - b.StopTimer() - close(chErr) - for err := range chErr { - if err != nil { - b.Log(err) - b.Fail() - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/dirs.go b/vendor/github.com/docker/docker/daemon/graphdriver/aufs/dirs.go deleted file mode 100644 index d2325fc..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/dirs.go +++ /dev/null @@ -1,64 +0,0 @@ -// +build linux - -package aufs - -import ( - "bufio" - "io/ioutil" - "os" - "path" -) - -// Return all the directories -func loadIds(root string) ([]string, error) { - dirs, err := ioutil.ReadDir(root) - if err != nil { - return nil, err - } - out := []string{} - for _, d := range dirs { - if !d.IsDir() { - out = append(out, d.Name()) - } - } - return out, nil -} - -// Read the layers file for the current id and return all the -// layers represented by new lines in the file -// -// If there are no lines in the file then the id has no parent -// and an empty slice is returned. -func getParentIDs(root, id string) ([]string, error) { - f, err := os.Open(path.Join(root, "layers", id)) - if err != nil { - return nil, err - } - defer f.Close() - - out := []string{} - s := bufio.NewScanner(f) - - for s.Scan() { - if t := s.Text(); t != "" { - out = append(out, s.Text()) - } - } - return out, s.Err() -} - -func (a *Driver) getMountpoint(id string) string { - return path.Join(a.mntPath(), id) -} - -func (a *Driver) mntPath() string { - return path.Join(a.rootPath(), "mnt") -} - -func (a *Driver) getDiffPath(id string) string { - return path.Join(a.diffPath(), id) -} - -func (a *Driver) diffPath() string { - return path.Join(a.rootPath(), "diff") -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/mount.go b/vendor/github.com/docker/docker/daemon/graphdriver/aufs/mount.go deleted file mode 100644 index da1e892..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/mount.go +++ /dev/null @@ -1,21 +0,0 @@ -// +build linux - -package aufs - -import ( - "os/exec" - "syscall" - - "github.com/Sirupsen/logrus" -) - -// Unmount the target specified. -func Unmount(target string) error { - if err := exec.Command("auplink", target, "flush").Run(); err != nil { - logrus.Warnf("Couldn't run auplink before unmount %s: %s", target, err) - } - if err := syscall.Unmount(target, 0); err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/mount_linux.go b/vendor/github.com/docker/docker/daemon/graphdriver/aufs/mount_linux.go deleted file mode 100644 index 8062bae..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/mount_linux.go +++ /dev/null @@ -1,7 +0,0 @@ -package aufs - -import "syscall" - -func mount(source string, target string, fstype string, flags uintptr, data string) error { - return syscall.Mount(source, target, fstype, flags, data) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/mount_unsupported.go b/vendor/github.com/docker/docker/daemon/graphdriver/aufs/mount_unsupported.go deleted file mode 100644 index d030b06..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/aufs/mount_unsupported.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !linux - -package aufs - -import "errors" - -// MsRemount declared to specify a non-linux system mount. -const MsRemount = 0 - -func mount(source string, target string, fstype string, flags uintptr, data string) (err error) { - return errors.New("mount is not implemented on this platform") -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/btrfs.go b/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/btrfs.go deleted file mode 100644 index 44420f1..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/btrfs.go +++ /dev/null @@ -1,530 +0,0 @@ -// +build linux - -package btrfs - -/* -#include -#include -#include -#include - -static void set_name_btrfs_ioctl_vol_args_v2(struct btrfs_ioctl_vol_args_v2* btrfs_struct, const char* value) { - snprintf(btrfs_struct->name, BTRFS_SUBVOL_NAME_MAX, "%s", value); -} -*/ -import "C" - -import ( - "fmt" - "os" - "path" - "path/filepath" - "strings" - "syscall" - "unsafe" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/parsers" - "github.com/docker/go-units" - "github.com/opencontainers/runc/libcontainer/label" -) - -func init() { - graphdriver.Register("btrfs", Init) -} - -var ( - quotaEnabled = false - userDiskQuota = false -) - -type btrfsOptions struct { - minSpace uint64 - size uint64 -} - -// Init returns a new BTRFS driver. -// An error is returned if BTRFS is not supported. -func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - - fsMagic, err := graphdriver.GetFSMagic(home) - if err != nil { - return nil, err - } - - if fsMagic != graphdriver.FsMagicBtrfs { - return nil, graphdriver.ErrPrerequisites - } - - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) - if err != nil { - return nil, err - } - if err := idtools.MkdirAllAs(home, 0700, rootUID, rootGID); err != nil { - return nil, err - } - - if err := mount.MakePrivate(home); err != nil { - return nil, err - } - - opt, err := parseOptions(options) - if err != nil { - return nil, err - } - - if userDiskQuota { - if err := subvolEnableQuota(home); err != nil { - return nil, err - } - quotaEnabled = true - } - - driver := &Driver{ - home: home, - uidMaps: uidMaps, - gidMaps: gidMaps, - options: opt, - } - - return graphdriver.NewNaiveDiffDriver(driver, uidMaps, gidMaps), nil -} - -func parseOptions(opt []string) (btrfsOptions, error) { - var options btrfsOptions - for _, option := range opt { - key, val, err := parsers.ParseKeyValueOpt(option) - if err != nil { - return options, err - } - key = strings.ToLower(key) - switch key { - case "btrfs.min_space": - minSpace, err := units.RAMInBytes(val) - if err != nil { - return options, err - } - userDiskQuota = true - options.minSpace = uint64(minSpace) - default: - return options, fmt.Errorf("Unknown option %s", key) - } - } - return options, nil -} - -// Driver contains information about the filesystem mounted. -type Driver struct { - //root of the file system - home string - uidMaps []idtools.IDMap - gidMaps []idtools.IDMap - options btrfsOptions -} - -// String prints the name of the driver (btrfs). -func (d *Driver) String() string { - return "btrfs" -} - -// Status returns current driver information in a two dimensional string array. -// Output contains "Build Version" and "Library Version" of the btrfs libraries used. -// Version information can be used to check compatibility with your kernel. -func (d *Driver) Status() [][2]string { - status := [][2]string{} - if bv := btrfsBuildVersion(); bv != "-" { - status = append(status, [2]string{"Build Version", bv}) - } - if lv := btrfsLibVersion(); lv != -1 { - status = append(status, [2]string{"Library Version", fmt.Sprintf("%d", lv)}) - } - return status -} - -// GetMetadata returns empty metadata for this driver. -func (d *Driver) GetMetadata(id string) (map[string]string, error) { - return nil, nil -} - -// Cleanup unmounts the home directory. -func (d *Driver) Cleanup() error { - if quotaEnabled { - if err := subvolDisableQuota(d.home); err != nil { - return err - } - } - - return mount.Unmount(d.home) -} - -func free(p *C.char) { - C.free(unsafe.Pointer(p)) -} - -func openDir(path string) (*C.DIR, error) { - Cpath := C.CString(path) - defer free(Cpath) - - dir := C.opendir(Cpath) - if dir == nil { - return nil, fmt.Errorf("Can't open dir") - } - return dir, nil -} - -func closeDir(dir *C.DIR) { - if dir != nil { - C.closedir(dir) - } -} - -func getDirFd(dir *C.DIR) uintptr { - return uintptr(C.dirfd(dir)) -} - -func subvolCreate(path, name string) error { - dir, err := openDir(path) - if err != nil { - return err - } - defer closeDir(dir) - - var args C.struct_btrfs_ioctl_vol_args - for i, c := range []byte(name) { - args.name[i] = C.char(c) - } - - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_SUBVOL_CREATE, - uintptr(unsafe.Pointer(&args))) - if errno != 0 { - return fmt.Errorf("Failed to create btrfs subvolume: %v", errno.Error()) - } - return nil -} - -func subvolSnapshot(src, dest, name string) error { - srcDir, err := openDir(src) - if err != nil { - return err - } - defer closeDir(srcDir) - - destDir, err := openDir(dest) - if err != nil { - return err - } - defer closeDir(destDir) - - var args C.struct_btrfs_ioctl_vol_args_v2 - args.fd = C.__s64(getDirFd(srcDir)) - - var cs = C.CString(name) - C.set_name_btrfs_ioctl_vol_args_v2(&args, cs) - C.free(unsafe.Pointer(cs)) - - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, getDirFd(destDir), C.BTRFS_IOC_SNAP_CREATE_V2, - uintptr(unsafe.Pointer(&args))) - if errno != 0 { - return fmt.Errorf("Failed to create btrfs snapshot: %v", errno.Error()) - } - return nil -} - -func isSubvolume(p string) (bool, error) { - var bufStat syscall.Stat_t - if err := syscall.Lstat(p, &bufStat); err != nil { - return false, err - } - - // return true if it is a btrfs subvolume - return bufStat.Ino == C.BTRFS_FIRST_FREE_OBJECTID, nil -} - -func subvolDelete(dirpath, name string) error { - dir, err := openDir(dirpath) - if err != nil { - return err - } - defer closeDir(dir) - fullPath := path.Join(dirpath, name) - - var args C.struct_btrfs_ioctl_vol_args - - // walk the btrfs subvolumes - walkSubvolumes := func(p string, f os.FileInfo, err error) error { - if err != nil { - if os.IsNotExist(err) && p != fullPath { - // missing most likely because the path was a subvolume that got removed in the previous iteration - // since it's gone anyway, we don't care - return nil - } - return fmt.Errorf("error walking subvolumes: %v", err) - } - // we want to check children only so skip itself - // it will be removed after the filepath walk anyways - if f.IsDir() && p != fullPath { - sv, err := isSubvolume(p) - if err != nil { - return fmt.Errorf("Failed to test if %s is a btrfs subvolume: %v", p, err) - } - if sv { - if err := subvolDelete(path.Dir(p), f.Name()); err != nil { - return fmt.Errorf("Failed to destroy btrfs child subvolume (%s) of parent (%s): %v", p, dirpath, err) - } - } - } - return nil - } - if err := filepath.Walk(path.Join(dirpath, name), walkSubvolumes); err != nil { - return fmt.Errorf("Recursively walking subvolumes for %s failed: %v", dirpath, err) - } - - // all subvolumes have been removed - // now remove the one originally passed in - for i, c := range []byte(name) { - args.name[i] = C.char(c) - } - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_SNAP_DESTROY, - uintptr(unsafe.Pointer(&args))) - if errno != 0 { - return fmt.Errorf("Failed to destroy btrfs snapshot %s for %s: %v", dirpath, name, errno.Error()) - } - return nil -} - -func subvolEnableQuota(path string) error { - dir, err := openDir(path) - if err != nil { - return err - } - defer closeDir(dir) - - var args C.struct_btrfs_ioctl_quota_ctl_args - args.cmd = C.BTRFS_QUOTA_CTL_ENABLE - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_QUOTA_CTL, - uintptr(unsafe.Pointer(&args))) - if errno != 0 { - return fmt.Errorf("Failed to enable btrfs quota for %s: %v", dir, errno.Error()) - } - - return nil -} - -func subvolDisableQuota(path string) error { - dir, err := openDir(path) - if err != nil { - return err - } - defer closeDir(dir) - - var args C.struct_btrfs_ioctl_quota_ctl_args - args.cmd = C.BTRFS_QUOTA_CTL_DISABLE - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_QUOTA_CTL, - uintptr(unsafe.Pointer(&args))) - if errno != 0 { - return fmt.Errorf("Failed to disable btrfs quota for %s: %v", dir, errno.Error()) - } - - return nil -} - -func subvolRescanQuota(path string) error { - dir, err := openDir(path) - if err != nil { - return err - } - defer closeDir(dir) - - var args C.struct_btrfs_ioctl_quota_rescan_args - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_QUOTA_RESCAN_WAIT, - uintptr(unsafe.Pointer(&args))) - if errno != 0 { - return fmt.Errorf("Failed to rescan btrfs quota for %s: %v", dir, errno.Error()) - } - - return nil -} - -func subvolLimitQgroup(path string, size uint64) error { - dir, err := openDir(path) - if err != nil { - return err - } - defer closeDir(dir) - - var args C.struct_btrfs_ioctl_qgroup_limit_args - args.lim.max_referenced = C.__u64(size) - args.lim.flags = C.BTRFS_QGROUP_LIMIT_MAX_RFER - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_QGROUP_LIMIT, - uintptr(unsafe.Pointer(&args))) - if errno != 0 { - return fmt.Errorf("Failed to limit qgroup for %s: %v", dir, errno.Error()) - } - - return nil -} - -func (d *Driver) subvolumesDir() string { - return path.Join(d.home, "subvolumes") -} - -func (d *Driver) subvolumesDirID(id string) string { - return path.Join(d.subvolumesDir(), id) -} - -// CreateReadWrite creates a layer that is writable for use as a container -// file system. -func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error { - return d.Create(id, parent, opts) -} - -// Create the filesystem with given id. -func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error { - subvolumes := path.Join(d.home, "subvolumes") - rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps) - if err != nil { - return err - } - if err := idtools.MkdirAllAs(subvolumes, 0700, rootUID, rootGID); err != nil { - return err - } - if parent == "" { - if err := subvolCreate(subvolumes, id); err != nil { - return err - } - } else { - parentDir := d.subvolumesDirID(parent) - st, err := os.Stat(parentDir) - if err != nil { - return err - } - if !st.IsDir() { - return fmt.Errorf("%s: not a directory", parentDir) - } - if err := subvolSnapshot(parentDir, subvolumes, id); err != nil { - return err - } - } - - var storageOpt map[string]string - if opts != nil { - storageOpt = opts.StorageOpt - } - - if _, ok := storageOpt["size"]; ok { - driver := &Driver{} - if err := d.parseStorageOpt(storageOpt, driver); err != nil { - return err - } - if err := d.setStorageSize(path.Join(subvolumes, id), driver); err != nil { - return err - } - } - - // if we have a remapped root (user namespaces enabled), change the created snapshot - // dir ownership to match - if rootUID != 0 || rootGID != 0 { - if err := os.Chown(path.Join(subvolumes, id), rootUID, rootGID); err != nil { - return err - } - } - - mountLabel := "" - if opts != nil { - mountLabel = opts.MountLabel - } - - return label.Relabel(path.Join(subvolumes, id), mountLabel, false) -} - -// Parse btrfs storage options -func (d *Driver) parseStorageOpt(storageOpt map[string]string, driver *Driver) error { - // Read size to change the subvolume disk quota per container - for key, val := range storageOpt { - key := strings.ToLower(key) - switch key { - case "size": - size, err := units.RAMInBytes(val) - if err != nil { - return err - } - driver.options.size = uint64(size) - default: - return fmt.Errorf("Unknown option %s", key) - } - } - - return nil -} - -// Set btrfs storage size -func (d *Driver) setStorageSize(dir string, driver *Driver) error { - if driver.options.size <= 0 { - return fmt.Errorf("btrfs: invalid storage size: %s", units.HumanSize(float64(driver.options.size))) - } - if d.options.minSpace > 0 && driver.options.size < d.options.minSpace { - return fmt.Errorf("btrfs: storage size cannot be less than %s", units.HumanSize(float64(d.options.minSpace))) - } - - if !quotaEnabled { - if err := subvolEnableQuota(d.home); err != nil { - return err - } - quotaEnabled = true - } - - if err := subvolLimitQgroup(dir, driver.options.size); err != nil { - return err - } - - return nil -} - -// Remove the filesystem with given id. -func (d *Driver) Remove(id string) error { - dir := d.subvolumesDirID(id) - if _, err := os.Stat(dir); err != nil { - return err - } - if err := subvolDelete(d.subvolumesDir(), id); err != nil { - return err - } - if err := os.RemoveAll(dir); err != nil && !os.IsNotExist(err) { - return err - } - if err := subvolRescanQuota(d.home); err != nil { - return err - } - return nil -} - -// Get the requested filesystem id. -func (d *Driver) Get(id, mountLabel string) (string, error) { - dir := d.subvolumesDirID(id) - st, err := os.Stat(dir) - if err != nil { - return "", err - } - - if !st.IsDir() { - return "", fmt.Errorf("%s: not a directory", dir) - } - - return dir, nil -} - -// Put is not implemented for BTRFS as there is no cleanup required for the id. -func (d *Driver) Put(id string) error { - // Get() creates no runtime resources (like e.g. mounts) - // so this doesn't need to do anything. - return nil -} - -// Exists checks if the id exists in the filesystem. -func (d *Driver) Exists(id string) bool { - dir := d.subvolumesDirID(id) - _, err := os.Stat(dir) - return err == nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/btrfs_test.go b/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/btrfs_test.go deleted file mode 100644 index 0038dbc..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/btrfs_test.go +++ /dev/null @@ -1,63 +0,0 @@ -// +build linux - -package btrfs - -import ( - "os" - "path" - "testing" - - "github.com/docker/docker/daemon/graphdriver/graphtest" -) - -// This avoids creating a new driver for each test if all tests are run -// Make sure to put new tests between TestBtrfsSetup and TestBtrfsTeardown -func TestBtrfsSetup(t *testing.T) { - graphtest.GetDriver(t, "btrfs") -} - -func TestBtrfsCreateEmpty(t *testing.T) { - graphtest.DriverTestCreateEmpty(t, "btrfs") -} - -func TestBtrfsCreateBase(t *testing.T) { - graphtest.DriverTestCreateBase(t, "btrfs") -} - -func TestBtrfsCreateSnap(t *testing.T) { - graphtest.DriverTestCreateSnap(t, "btrfs") -} - -func TestBtrfsSubvolDelete(t *testing.T) { - d := graphtest.GetDriver(t, "btrfs") - if err := d.CreateReadWrite("test", "", nil); err != nil { - t.Fatal(err) - } - defer graphtest.PutDriver(t) - - dir, err := d.Get("test", "") - if err != nil { - t.Fatal(err) - } - defer d.Put("test") - - if err := subvolCreate(dir, "subvoltest"); err != nil { - t.Fatal(err) - } - - if _, err := os.Stat(path.Join(dir, "subvoltest")); err != nil { - t.Fatal(err) - } - - if err := d.Remove("test"); err != nil { - t.Fatal(err) - } - - if _, err := os.Stat(path.Join(dir, "subvoltest")); !os.IsNotExist(err) { - t.Fatalf("expected not exist error on nested subvol, got: %v", err) - } -} - -func TestBtrfsTeardown(t *testing.T) { - graphtest.PutDriver(t) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/dummy_unsupported.go b/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/dummy_unsupported.go deleted file mode 100644 index f070888..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/dummy_unsupported.go +++ /dev/null @@ -1,3 +0,0 @@ -// +build !linux !cgo - -package btrfs diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/version.go b/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/version.go deleted file mode 100644 index 73d90cd..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/version.go +++ /dev/null @@ -1,26 +0,0 @@ -// +build linux,!btrfs_noversion - -package btrfs - -/* -#include - -// around version 3.16, they did not define lib version yet -#ifndef BTRFS_LIB_VERSION -#define BTRFS_LIB_VERSION -1 -#endif - -// upstream had removed it, but now it will be coming back -#ifndef BTRFS_BUILD_VERSION -#define BTRFS_BUILD_VERSION "-" -#endif -*/ -import "C" - -func btrfsBuildVersion() string { - return string(C.BTRFS_BUILD_VERSION) -} - -func btrfsLibVersion() int { - return int(C.BTRFS_LIB_VERSION) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/version_none.go b/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/version_none.go deleted file mode 100644 index f802fbc..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/version_none.go +++ /dev/null @@ -1,14 +0,0 @@ -// +build linux,btrfs_noversion - -package btrfs - -// TODO(vbatts) remove this work-around once supported linux distros are on -// btrfs utilities of >= 3.16.1 - -func btrfsBuildVersion() string { - return "-" -} - -func btrfsLibVersion() int { - return -1 -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/version_test.go b/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/version_test.go deleted file mode 100644 index 15a6e75..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/btrfs/version_test.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build linux,!btrfs_noversion - -package btrfs - -import ( - "testing" -) - -func TestLibVersion(t *testing.T) { - if btrfsLibVersion() <= 0 { - t.Errorf("expected output from btrfs lib version > 0") - } -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/counter.go b/vendor/github.com/docker/docker/daemon/graphdriver/counter.go deleted file mode 100644 index 5ea604f..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/counter.go +++ /dev/null @@ -1,67 +0,0 @@ -package graphdriver - -import "sync" - -type minfo struct { - check bool - count int -} - -// RefCounter is a generic counter for use by graphdriver Get/Put calls -type RefCounter struct { - counts map[string]*minfo - mu sync.Mutex - checker Checker -} - -// NewRefCounter returns a new RefCounter -func NewRefCounter(c Checker) *RefCounter { - return &RefCounter{ - checker: c, - counts: make(map[string]*minfo), - } -} - -// Increment increaes the ref count for the given id and returns the current count -func (c *RefCounter) Increment(path string) int { - c.mu.Lock() - m := c.counts[path] - if m == nil { - m = &minfo{} - c.counts[path] = m - } - // if we are checking this path for the first time check to make sure - // if it was already mounted on the system and make sure we have a correct ref - // count if it is mounted as it is in use. - if !m.check { - m.check = true - if c.checker.IsMounted(path) { - m.count++ - } - } - m.count++ - c.mu.Unlock() - return m.count -} - -// Decrement decreases the ref count for the given id and returns the current count -func (c *RefCounter) Decrement(path string) int { - c.mu.Lock() - m := c.counts[path] - if m == nil { - m = &minfo{} - c.counts[path] = m - } - // if we are checking this path for the first time check to make sure - // if it was already mounted on the system and make sure we have a correct ref - // count if it is mounted as it is in use. - if !m.check { - m.check = true - if c.checker.IsMounted(path) { - m.count++ - } - } - m.count-- - c.mu.Unlock() - return m.count -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/README.md b/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/README.md deleted file mode 100644 index b23bbb1..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/README.md +++ /dev/null @@ -1,96 +0,0 @@ -## devicemapper - a storage backend based on Device Mapper - -### Theory of operation - -The device mapper graphdriver uses the device mapper thin provisioning -module (dm-thinp) to implement CoW snapshots. The preferred model is -to have a thin pool reserved outside of Docker and passed to the -daemon via the `--storage-opt dm.thinpooldev` option. - -As a fallback if no thin pool is provided, loopback files will be -created. Loopback is very slow, but can be used without any -pre-configuration of storage. It is strongly recommended that you do -not use loopback in production. Ensure your Docker daemon has a -`--storage-opt dm.thinpooldev` argument provided. - -In loopback, a thin pool is created at `/var/lib/docker/devicemapper` -(devicemapper graph location) based on two block devices, one for -data and one for metadata. By default these block devices are created -automatically by using loopback mounts of automatically created sparse -files. - -The default loopback files used are -`/var/lib/docker/devicemapper/devicemapper/data` and -`/var/lib/docker/devicemapper/devicemapper/metadata`. Additional metadata -required to map from docker entities to the corresponding devicemapper -volumes is stored in the `/var/lib/docker/devicemapper/devicemapper/json` -file (encoded as Json). - -In order to support multiple devicemapper graphs on a system, the thin -pool will be named something like: `docker-0:33-19478248-pool`, where -the `0:33` part is the minor/major device nr and `19478248` is the -inode number of the `/var/lib/docker/devicemapper` directory. - -On the thin pool, docker automatically creates a base thin device, -called something like `docker-0:33-19478248-base` of a fixed -size. This is automatically formatted with an empty filesystem on -creation. This device is the base of all docker images and -containers. All base images are snapshots of this device and those -images are then in turn used as snapshots for other images and -eventually containers. - -### Information on `docker info` - -As of docker-1.4.1, `docker info` when using the `devicemapper` storage driver -will display something like: - - $ sudo docker info - [...] - Storage Driver: devicemapper - Pool Name: docker-253:1-17538953-pool - Pool Blocksize: 65.54 kB - Base Device Size: 107.4 GB - Data file: /dev/loop4 - Metadata file: /dev/loop4 - Data Space Used: 2.536 GB - Data Space Total: 107.4 GB - Data Space Available: 104.8 GB - Metadata Space Used: 7.93 MB - Metadata Space Total: 2.147 GB - Metadata Space Available: 2.14 GB - Udev Sync Supported: true - Data loop file: /home/docker/devicemapper/devicemapper/data - Metadata loop file: /home/docker/devicemapper/devicemapper/metadata - Library Version: 1.02.82-git (2013-10-04) - [...] - -#### status items - -Each item in the indented section under `Storage Driver: devicemapper` are -status information about the driver. - * `Pool Name` name of the devicemapper pool for this driver. - * `Pool Blocksize` tells the blocksize the thin pool was initialized with. This only changes on creation. - * `Base Device Size` tells the maximum size of a container and image - * `Data file` blockdevice file used for the devicemapper data - * `Metadata file` blockdevice file used for the devicemapper metadata - * `Data Space Used` tells how much of `Data file` is currently used - * `Data Space Total` tells max size the `Data file` - * `Data Space Available` tells how much free space there is in the `Data file`. If you are using a loop device this will report the actual space available to the loop device on the underlying filesystem. - * `Metadata Space Used` tells how much of `Metadata file` is currently used - * `Metadata Space Total` tells max size the `Metadata file` - * `Metadata Space Available` tells how much free space there is in the `Metadata file`. If you are using a loop device this will report the actual space available to the loop device on the underlying filesystem. - * `Udev Sync Supported` tells whether devicemapper is able to sync with Udev. Should be `true`. - * `Data loop file` file attached to `Data file`, if loopback device is used - * `Metadata loop file` file attached to `Metadata file`, if loopback device is used - * `Library Version` from the libdevmapper used - -### About the devicemapper options - -The devicemapper backend supports some options that you can specify -when starting the docker daemon using the `--storage-opt` flags. -This uses the `dm` prefix and would be used something like `docker daemon --storage-opt dm.foo=bar`. - -These options are currently documented both in [the man -page](../../../man/docker.1.md) and in [the online -documentation](https://docs.docker.com/engine/reference/commandline/dockerd/#/storage-driver-options). -If you add an options, update both the `man` page and the documentation. diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/deviceset.go b/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/deviceset.go deleted file mode 100644 index b8e7625..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/deviceset.go +++ /dev/null @@ -1,2727 +0,0 @@ -// +build linux - -package devmapper - -import ( - "bufio" - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "os/exec" - "path" - "path/filepath" - "strconv" - "strings" - "sync" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/pkg/devicemapper" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/loopback" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/parsers" - "github.com/docker/go-units" - - "github.com/opencontainers/runc/libcontainer/label" -) - -var ( - defaultDataLoopbackSize int64 = 100 * 1024 * 1024 * 1024 - defaultMetaDataLoopbackSize int64 = 2 * 1024 * 1024 * 1024 - defaultBaseFsSize uint64 = 10 * 1024 * 1024 * 1024 - defaultThinpBlockSize uint32 = 128 // 64K = 128 512b sectors - defaultUdevSyncOverride = false - maxDeviceID = 0xffffff // 24 bit, pool limit - deviceIDMapSz = (maxDeviceID + 1) / 8 - // We retry device removal so many a times that even error messages - // will fill up console during normal operation. So only log Fatal - // messages by default. - logLevel = devicemapper.LogLevelFatal - driverDeferredRemovalSupport = false - enableDeferredRemoval = false - enableDeferredDeletion = false - userBaseSize = false - defaultMinFreeSpacePercent uint32 = 10 -) - -const deviceSetMetaFile string = "deviceset-metadata" -const transactionMetaFile string = "transaction-metadata" - -type transaction struct { - OpenTransactionID uint64 `json:"open_transaction_id"` - DeviceIDHash string `json:"device_hash"` - DeviceID int `json:"device_id"` -} - -type devInfo struct { - Hash string `json:"-"` - DeviceID int `json:"device_id"` - Size uint64 `json:"size"` - TransactionID uint64 `json:"transaction_id"` - Initialized bool `json:"initialized"` - Deleted bool `json:"deleted"` - devices *DeviceSet - - // The global DeviceSet lock guarantees that we serialize all - // the calls to libdevmapper (which is not threadsafe), but we - // sometimes release that lock while sleeping. In that case - // this per-device lock is still held, protecting against - // other accesses to the device that we're doing the wait on. - // - // WARNING: In order to avoid AB-BA deadlocks when releasing - // the global lock while holding the per-device locks all - // device locks must be acquired *before* the device lock, and - // multiple device locks should be acquired parent before child. - lock sync.Mutex -} - -type metaData struct { - Devices map[string]*devInfo `json:"Devices"` -} - -// DeviceSet holds information about list of devices -type DeviceSet struct { - metaData `json:"-"` - sync.Mutex `json:"-"` // Protects all fields of DeviceSet and serializes calls into libdevmapper - root string - devicePrefix string - TransactionID uint64 `json:"-"` - NextDeviceID int `json:"next_device_id"` - deviceIDMap []byte - - // Options - dataLoopbackSize int64 - metaDataLoopbackSize int64 - baseFsSize uint64 - filesystem string - mountOptions string - mkfsArgs []string - dataDevice string // block or loop dev - dataLoopFile string // loopback file, if used - metadataDevice string // block or loop dev - metadataLoopFile string // loopback file, if used - doBlkDiscard bool - thinpBlockSize uint32 - thinPoolDevice string - transaction `json:"-"` - overrideUdevSyncCheck bool - deferredRemove bool // use deferred removal - deferredDelete bool // use deferred deletion - BaseDeviceUUID string // save UUID of base device - BaseDeviceFilesystem string // save filesystem of base device - nrDeletedDevices uint // number of deleted devices - deletionWorkerTicker *time.Ticker - uidMaps []idtools.IDMap - gidMaps []idtools.IDMap - minFreeSpacePercent uint32 //min free space percentage in thinpool - xfsNospaceRetries string // max retries when xfs receives ENOSPC -} - -// DiskUsage contains information about disk usage and is used when reporting Status of a device. -type DiskUsage struct { - // Used bytes on the disk. - Used uint64 - // Total bytes on the disk. - Total uint64 - // Available bytes on the disk. - Available uint64 -} - -// Status returns the information about the device. -type Status struct { - // PoolName is the name of the data pool. - PoolName string - // DataFile is the actual block device for data. - DataFile string - // DataLoopback loopback file, if used. - DataLoopback string - // MetadataFile is the actual block device for metadata. - MetadataFile string - // MetadataLoopback is the loopback file, if used. - MetadataLoopback string - // Data is the disk used for data. - Data DiskUsage - // Metadata is the disk used for meta data. - Metadata DiskUsage - // BaseDeviceSize is base size of container and image - BaseDeviceSize uint64 - // BaseDeviceFS is backing filesystem. - BaseDeviceFS string - // SectorSize size of the vector. - SectorSize uint64 - // UdevSyncSupported is true if sync is supported. - UdevSyncSupported bool - // DeferredRemoveEnabled is true then the device is not unmounted. - DeferredRemoveEnabled bool - // True if deferred deletion is enabled. This is different from - // deferred removal. "removal" means that device mapper device is - // deactivated. Thin device is still in thin pool and can be activated - // again. But "deletion" means that thin device will be deleted from - // thin pool and it can't be activated again. - DeferredDeleteEnabled bool - DeferredDeletedDeviceCount uint - MinFreeSpace uint64 -} - -// Structure used to export image/container metadata in docker inspect. -type deviceMetadata struct { - deviceID int - deviceSize uint64 // size in bytes - deviceName string // Device name as used during activation -} - -// DevStatus returns information about device mounted containing its id, size and sector information. -type DevStatus struct { - // DeviceID is the id of the device. - DeviceID int - // Size is the size of the filesystem. - Size uint64 - // TransactionID is a unique integer per device set used to identify an operation on the file system, this number is incremental. - TransactionID uint64 - // SizeInSectors indicates the size of the sectors allocated. - SizeInSectors uint64 - // MappedSectors indicates number of mapped sectors. - MappedSectors uint64 - // HighestMappedSector is the pointer to the highest mapped sector. - HighestMappedSector uint64 -} - -func getDevName(name string) string { - return "/dev/mapper/" + name -} - -func (info *devInfo) Name() string { - hash := info.Hash - if hash == "" { - hash = "base" - } - return fmt.Sprintf("%s-%s", info.devices.devicePrefix, hash) -} - -func (info *devInfo) DevName() string { - return getDevName(info.Name()) -} - -func (devices *DeviceSet) loopbackDir() string { - return path.Join(devices.root, "devicemapper") -} - -func (devices *DeviceSet) metadataDir() string { - return path.Join(devices.root, "metadata") -} - -func (devices *DeviceSet) metadataFile(info *devInfo) string { - file := info.Hash - if file == "" { - file = "base" - } - return path.Join(devices.metadataDir(), file) -} - -func (devices *DeviceSet) transactionMetaFile() string { - return path.Join(devices.metadataDir(), transactionMetaFile) -} - -func (devices *DeviceSet) deviceSetMetaFile() string { - return path.Join(devices.metadataDir(), deviceSetMetaFile) -} - -func (devices *DeviceSet) oldMetadataFile() string { - return path.Join(devices.loopbackDir(), "json") -} - -func (devices *DeviceSet) getPoolName() string { - if devices.thinPoolDevice == "" { - return devices.devicePrefix + "-pool" - } - return devices.thinPoolDevice -} - -func (devices *DeviceSet) getPoolDevName() string { - return getDevName(devices.getPoolName()) -} - -func (devices *DeviceSet) hasImage(name string) bool { - dirname := devices.loopbackDir() - filename := path.Join(dirname, name) - - _, err := os.Stat(filename) - return err == nil -} - -// ensureImage creates a sparse file of bytes at the path -// /devicemapper/. -// If the file already exists and new size is larger than its current size, it grows to the new size. -// Either way it returns the full path. -func (devices *DeviceSet) ensureImage(name string, size int64) (string, error) { - dirname := devices.loopbackDir() - filename := path.Join(dirname, name) - - uid, gid, err := idtools.GetRootUIDGID(devices.uidMaps, devices.gidMaps) - if err != nil { - return "", err - } - if err := idtools.MkdirAllAs(dirname, 0700, uid, gid); err != nil && !os.IsExist(err) { - return "", err - } - - if fi, err := os.Stat(filename); err != nil { - if !os.IsNotExist(err) { - return "", err - } - logrus.Debugf("devmapper: Creating loopback file %s for device-manage use", filename) - file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0600) - if err != nil { - return "", err - } - defer file.Close() - - if err := file.Truncate(size); err != nil { - return "", err - } - } else { - if fi.Size() < size { - file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0600) - if err != nil { - return "", err - } - defer file.Close() - if err := file.Truncate(size); err != nil { - return "", fmt.Errorf("devmapper: Unable to grow loopback file %s: %v", filename, err) - } - } else if fi.Size() > size { - logrus.Warnf("devmapper: Can't shrink loopback file %s", filename) - } - } - return filename, nil -} - -func (devices *DeviceSet) allocateTransactionID() uint64 { - devices.OpenTransactionID = devices.TransactionID + 1 - return devices.OpenTransactionID -} - -func (devices *DeviceSet) updatePoolTransactionID() error { - if err := devicemapper.SetTransactionID(devices.getPoolDevName(), devices.TransactionID, devices.OpenTransactionID); err != nil { - return fmt.Errorf("devmapper: Error setting devmapper transaction ID: %s", err) - } - devices.TransactionID = devices.OpenTransactionID - return nil -} - -func (devices *DeviceSet) removeMetadata(info *devInfo) error { - if err := os.RemoveAll(devices.metadataFile(info)); err != nil { - return fmt.Errorf("devmapper: Error removing metadata file %s: %s", devices.metadataFile(info), err) - } - return nil -} - -// Given json data and file path, write it to disk -func (devices *DeviceSet) writeMetaFile(jsonData []byte, filePath string) error { - tmpFile, err := ioutil.TempFile(devices.metadataDir(), ".tmp") - if err != nil { - return fmt.Errorf("devmapper: Error creating metadata file: %s", err) - } - - n, err := tmpFile.Write(jsonData) - if err != nil { - return fmt.Errorf("devmapper: Error writing metadata to %s: %s", tmpFile.Name(), err) - } - if n < len(jsonData) { - return io.ErrShortWrite - } - if err := tmpFile.Sync(); err != nil { - return fmt.Errorf("devmapper: Error syncing metadata file %s: %s", tmpFile.Name(), err) - } - if err := tmpFile.Close(); err != nil { - return fmt.Errorf("devmapper: Error closing metadata file %s: %s", tmpFile.Name(), err) - } - if err := os.Rename(tmpFile.Name(), filePath); err != nil { - return fmt.Errorf("devmapper: Error committing metadata file %s: %s", tmpFile.Name(), err) - } - - return nil -} - -func (devices *DeviceSet) saveMetadata(info *devInfo) error { - jsonData, err := json.Marshal(info) - if err != nil { - return fmt.Errorf("devmapper: Error encoding metadata to json: %s", err) - } - if err := devices.writeMetaFile(jsonData, devices.metadataFile(info)); err != nil { - return err - } - return nil -} - -func (devices *DeviceSet) markDeviceIDUsed(deviceID int) { - var mask byte - i := deviceID % 8 - mask = 1 << uint(i) - devices.deviceIDMap[deviceID/8] = devices.deviceIDMap[deviceID/8] | mask -} - -func (devices *DeviceSet) markDeviceIDFree(deviceID int) { - var mask byte - i := deviceID % 8 - mask = ^(1 << uint(i)) - devices.deviceIDMap[deviceID/8] = devices.deviceIDMap[deviceID/8] & mask -} - -func (devices *DeviceSet) isDeviceIDFree(deviceID int) bool { - var mask byte - i := deviceID % 8 - mask = (1 << uint(i)) - if (devices.deviceIDMap[deviceID/8] & mask) != 0 { - return false - } - return true -} - -// Should be called with devices.Lock() held. -func (devices *DeviceSet) lookupDevice(hash string) (*devInfo, error) { - info := devices.Devices[hash] - if info == nil { - info = devices.loadMetadata(hash) - if info == nil { - return nil, fmt.Errorf("devmapper: Unknown device %s", hash) - } - - devices.Devices[hash] = info - } - return info, nil -} - -func (devices *DeviceSet) lookupDeviceWithLock(hash string) (*devInfo, error) { - devices.Lock() - defer devices.Unlock() - info, err := devices.lookupDevice(hash) - return info, err -} - -// This function relies on that device hash map has been loaded in advance. -// Should be called with devices.Lock() held. -func (devices *DeviceSet) constructDeviceIDMap() { - logrus.Debug("devmapper: constructDeviceIDMap()") - defer logrus.Debug("devmapper: constructDeviceIDMap() END") - - for _, info := range devices.Devices { - devices.markDeviceIDUsed(info.DeviceID) - logrus.Debugf("devmapper: Added deviceId=%d to DeviceIdMap", info.DeviceID) - } -} - -func (devices *DeviceSet) deviceFileWalkFunction(path string, finfo os.FileInfo) error { - - // Skip some of the meta files which are not device files. - if strings.HasSuffix(finfo.Name(), ".migrated") { - logrus.Debugf("devmapper: Skipping file %s", path) - return nil - } - - if strings.HasPrefix(finfo.Name(), ".") { - logrus.Debugf("devmapper: Skipping file %s", path) - return nil - } - - if finfo.Name() == deviceSetMetaFile { - logrus.Debugf("devmapper: Skipping file %s", path) - return nil - } - - if finfo.Name() == transactionMetaFile { - logrus.Debugf("devmapper: Skipping file %s", path) - return nil - } - - logrus.Debugf("devmapper: Loading data for file %s", path) - - hash := finfo.Name() - if hash == "base" { - hash = "" - } - - // Include deleted devices also as cleanup delete device logic - // will go through it and see if there are any deleted devices. - if _, err := devices.lookupDevice(hash); err != nil { - return fmt.Errorf("devmapper: Error looking up device %s:%v", hash, err) - } - - return nil -} - -func (devices *DeviceSet) loadDeviceFilesOnStart() error { - logrus.Debug("devmapper: loadDeviceFilesOnStart()") - defer logrus.Debug("devmapper: loadDeviceFilesOnStart() END") - - var scan = func(path string, info os.FileInfo, err error) error { - if err != nil { - logrus.Debugf("devmapper: Can't walk the file %s", path) - return nil - } - - // Skip any directories - if info.IsDir() { - return nil - } - - return devices.deviceFileWalkFunction(path, info) - } - - return filepath.Walk(devices.metadataDir(), scan) -} - -// Should be called with devices.Lock() held. -func (devices *DeviceSet) unregisterDevice(id int, hash string) error { - logrus.Debugf("devmapper: unregisterDevice(%v, %v)", id, hash) - info := &devInfo{ - Hash: hash, - DeviceID: id, - } - - delete(devices.Devices, hash) - - if err := devices.removeMetadata(info); err != nil { - logrus.Debugf("devmapper: Error removing metadata: %s", err) - return err - } - - return nil -} - -// Should be called with devices.Lock() held. -func (devices *DeviceSet) registerDevice(id int, hash string, size uint64, transactionID uint64) (*devInfo, error) { - logrus.Debugf("devmapper: registerDevice(%v, %v)", id, hash) - info := &devInfo{ - Hash: hash, - DeviceID: id, - Size: size, - TransactionID: transactionID, - Initialized: false, - devices: devices, - } - - devices.Devices[hash] = info - - if err := devices.saveMetadata(info); err != nil { - // Try to remove unused device - delete(devices.Devices, hash) - return nil, err - } - - return info, nil -} - -func (devices *DeviceSet) activateDeviceIfNeeded(info *devInfo, ignoreDeleted bool) error { - logrus.Debugf("devmapper: activateDeviceIfNeeded(%v)", info.Hash) - - if info.Deleted && !ignoreDeleted { - return fmt.Errorf("devmapper: Can't activate device %v as it is marked for deletion", info.Hash) - } - - // Make sure deferred removal on device is canceled, if one was - // scheduled. - if err := devices.cancelDeferredRemovalIfNeeded(info); err != nil { - return fmt.Errorf("devmapper: Device Deferred Removal Cancellation Failed: %s", err) - } - - if devinfo, _ := devicemapper.GetInfo(info.Name()); devinfo != nil && devinfo.Exists != 0 { - return nil - } - - return devicemapper.ActivateDevice(devices.getPoolDevName(), info.Name(), info.DeviceID, info.Size) -} - -// Return true only if kernel supports xfs and mkfs.xfs is available -func xfsSupported() bool { - // Make sure mkfs.xfs is available - if _, err := exec.LookPath("mkfs.xfs"); err != nil { - return false - } - - // Check if kernel supports xfs filesystem or not. - exec.Command("modprobe", "xfs").Run() - - f, err := os.Open("/proc/filesystems") - if err != nil { - logrus.Warnf("devmapper: Could not check if xfs is supported: %v", err) - return false - } - defer f.Close() - - s := bufio.NewScanner(f) - for s.Scan() { - if strings.HasSuffix(s.Text(), "\txfs") { - return true - } - } - - if err := s.Err(); err != nil { - logrus.Warnf("devmapper: Could not check if xfs is supported: %v", err) - } - return false -} - -func determineDefaultFS() string { - if xfsSupported() { - return "xfs" - } - - logrus.Warn("devmapper: XFS is not supported in your system. Either the kernel doesn't support it or mkfs.xfs is not in your PATH. Defaulting to ext4 filesystem") - return "ext4" -} - -func (devices *DeviceSet) createFilesystem(info *devInfo) (err error) { - devname := info.DevName() - - args := []string{} - args = append(args, devices.mkfsArgs...) - - args = append(args, devname) - - if devices.filesystem == "" { - devices.filesystem = determineDefaultFS() - } - if err := devices.saveBaseDeviceFilesystem(devices.filesystem); err != nil { - return err - } - - logrus.Infof("devmapper: Creating filesystem %s on device %s", devices.filesystem, info.Name()) - defer func() { - if err != nil { - logrus.Infof("devmapper: Error while creating filesystem %s on device %s: %v", devices.filesystem, info.Name(), err) - } else { - logrus.Infof("devmapper: Successfully created filesystem %s on device %s", devices.filesystem, info.Name()) - } - }() - - switch devices.filesystem { - case "xfs": - err = exec.Command("mkfs.xfs", args...).Run() - case "ext4": - err = exec.Command("mkfs.ext4", append([]string{"-E", "nodiscard,lazy_itable_init=0,lazy_journal_init=0"}, args...)...).Run() - if err != nil { - err = exec.Command("mkfs.ext4", append([]string{"-E", "nodiscard,lazy_itable_init=0"}, args...)...).Run() - } - if err != nil { - return err - } - err = exec.Command("tune2fs", append([]string{"-c", "-1", "-i", "0"}, devname)...).Run() - default: - err = fmt.Errorf("devmapper: Unsupported filesystem type %s", devices.filesystem) - } - return -} - -func (devices *DeviceSet) migrateOldMetaData() error { - // Migrate old metadata file - jsonData, err := ioutil.ReadFile(devices.oldMetadataFile()) - if err != nil && !os.IsNotExist(err) { - return err - } - - if jsonData != nil { - m := metaData{Devices: make(map[string]*devInfo)} - - if err := json.Unmarshal(jsonData, &m); err != nil { - return err - } - - for hash, info := range m.Devices { - info.Hash = hash - devices.saveMetadata(info) - } - if err := os.Rename(devices.oldMetadataFile(), devices.oldMetadataFile()+".migrated"); err != nil { - return err - } - - } - - return nil -} - -// Cleanup deleted devices. It assumes that all the devices have been -// loaded in the hash table. -func (devices *DeviceSet) cleanupDeletedDevices() error { - devices.Lock() - - // If there are no deleted devices, there is nothing to do. - if devices.nrDeletedDevices == 0 { - devices.Unlock() - return nil - } - - var deletedDevices []*devInfo - - for _, info := range devices.Devices { - if !info.Deleted { - continue - } - logrus.Debugf("devmapper: Found deleted device %s.", info.Hash) - deletedDevices = append(deletedDevices, info) - } - - // Delete the deleted devices. DeleteDevice() first takes the info lock - // and then devices.Lock(). So drop it to avoid deadlock. - devices.Unlock() - - for _, info := range deletedDevices { - // This will again try deferred deletion. - if err := devices.DeleteDevice(info.Hash, false); err != nil { - logrus.Warnf("devmapper: Deletion of device %s, device_id=%v failed:%v", info.Hash, info.DeviceID, err) - } - } - - return nil -} - -func (devices *DeviceSet) countDeletedDevices() { - for _, info := range devices.Devices { - if !info.Deleted { - continue - } - devices.nrDeletedDevices++ - } -} - -func (devices *DeviceSet) startDeviceDeletionWorker() { - // Deferred deletion is not enabled. Don't do anything. - if !devices.deferredDelete { - return - } - - logrus.Debug("devmapper: Worker to cleanup deleted devices started") - for range devices.deletionWorkerTicker.C { - devices.cleanupDeletedDevices() - } -} - -func (devices *DeviceSet) initMetaData() error { - devices.Lock() - defer devices.Unlock() - - if err := devices.migrateOldMetaData(); err != nil { - return err - } - - _, transactionID, _, _, _, _, err := devices.poolStatus() - if err != nil { - return err - } - - devices.TransactionID = transactionID - - if err := devices.loadDeviceFilesOnStart(); err != nil { - return fmt.Errorf("devmapper: Failed to load device files:%v", err) - } - - devices.constructDeviceIDMap() - devices.countDeletedDevices() - - if err := devices.processPendingTransaction(); err != nil { - return err - } - - // Start a goroutine to cleanup Deleted Devices - go devices.startDeviceDeletionWorker() - return nil -} - -func (devices *DeviceSet) incNextDeviceID() { - // IDs are 24bit, so wrap around - devices.NextDeviceID = (devices.NextDeviceID + 1) & maxDeviceID -} - -func (devices *DeviceSet) getNextFreeDeviceID() (int, error) { - devices.incNextDeviceID() - for i := 0; i <= maxDeviceID; i++ { - if devices.isDeviceIDFree(devices.NextDeviceID) { - devices.markDeviceIDUsed(devices.NextDeviceID) - return devices.NextDeviceID, nil - } - devices.incNextDeviceID() - } - - return 0, fmt.Errorf("devmapper: Unable to find a free device ID") -} - -func (devices *DeviceSet) poolHasFreeSpace() error { - if devices.minFreeSpacePercent == 0 { - return nil - } - - _, _, dataUsed, dataTotal, metadataUsed, metadataTotal, err := devices.poolStatus() - if err != nil { - return err - } - - minFreeData := (dataTotal * uint64(devices.minFreeSpacePercent)) / 100 - if minFreeData < 1 { - minFreeData = 1 - } - dataFree := dataTotal - dataUsed - if dataFree < minFreeData { - return fmt.Errorf("devmapper: Thin Pool has %v free data blocks which is less than minimum required %v free data blocks. Create more free space in thin pool or use dm.min_free_space option to change behavior", (dataTotal - dataUsed), minFreeData) - } - - minFreeMetadata := (metadataTotal * uint64(devices.minFreeSpacePercent)) / 100 - if minFreeMetadata < 1 { - minFreeMetadata = 1 - } - - metadataFree := metadataTotal - metadataUsed - if metadataFree < minFreeMetadata { - return fmt.Errorf("devmapper: Thin Pool has %v free metadata blocks which is less than minimum required %v free metadata blocks. Create more free metadata space in thin pool or use dm.min_free_space option to change behavior", (metadataTotal - metadataUsed), minFreeMetadata) - } - - return nil -} - -func (devices *DeviceSet) createRegisterDevice(hash string) (*devInfo, error) { - devices.Lock() - defer devices.Unlock() - - deviceID, err := devices.getNextFreeDeviceID() - if err != nil { - return nil, err - } - - if err := devices.openTransaction(hash, deviceID); err != nil { - logrus.Debugf("devmapper: Error opening transaction hash = %s deviceID = %d", hash, deviceID) - devices.markDeviceIDFree(deviceID) - return nil, err - } - - for { - if err := devicemapper.CreateDevice(devices.getPoolDevName(), deviceID); err != nil { - if devicemapper.DeviceIDExists(err) { - // Device ID already exists. This should not - // happen. Now we have a mechanism to find - // a free device ID. So something is not right. - // Give a warning and continue. - logrus.Errorf("devmapper: Device ID %d exists in pool but it is supposed to be unused", deviceID) - deviceID, err = devices.getNextFreeDeviceID() - if err != nil { - return nil, err - } - // Save new device id into transaction - devices.refreshTransaction(deviceID) - continue - } - logrus.Debugf("devmapper: Error creating device: %s", err) - devices.markDeviceIDFree(deviceID) - return nil, err - } - break - } - - logrus.Debugf("devmapper: Registering device (id %v) with FS size %v", deviceID, devices.baseFsSize) - info, err := devices.registerDevice(deviceID, hash, devices.baseFsSize, devices.OpenTransactionID) - if err != nil { - _ = devicemapper.DeleteDevice(devices.getPoolDevName(), deviceID) - devices.markDeviceIDFree(deviceID) - return nil, err - } - - if err := devices.closeTransaction(); err != nil { - devices.unregisterDevice(deviceID, hash) - devicemapper.DeleteDevice(devices.getPoolDevName(), deviceID) - devices.markDeviceIDFree(deviceID) - return nil, err - } - return info, nil -} - -func (devices *DeviceSet) takeSnapshot(hash string, baseInfo *devInfo, size uint64) error { - var ( - devinfo *devicemapper.Info - err error - ) - - if err = devices.poolHasFreeSpace(); err != nil { - return err - } - - if devices.deferredRemove { - devinfo, err = devicemapper.GetInfoWithDeferred(baseInfo.Name()) - if err != nil { - return err - } - if devinfo != nil && devinfo.DeferredRemove != 0 { - err = devices.cancelDeferredRemoval(baseInfo) - if err != nil { - // If Error is ErrEnxio. Device is probably already gone. Continue. - if err != devicemapper.ErrEnxio { - return err - } - } else { - defer devices.deactivateDevice(baseInfo) - } - } - } else { - devinfo, err = devicemapper.GetInfo(baseInfo.Name()) - if err != nil { - return err - } - } - - doSuspend := devinfo != nil && devinfo.Exists != 0 - - if doSuspend { - if err = devicemapper.SuspendDevice(baseInfo.Name()); err != nil { - return err - } - defer devicemapper.ResumeDevice(baseInfo.Name()) - } - - if err = devices.createRegisterSnapDevice(hash, baseInfo, size); err != nil { - return err - } - - return nil -} - -func (devices *DeviceSet) createRegisterSnapDevice(hash string, baseInfo *devInfo, size uint64) error { - deviceID, err := devices.getNextFreeDeviceID() - if err != nil { - return err - } - - if err := devices.openTransaction(hash, deviceID); err != nil { - logrus.Debugf("devmapper: Error opening transaction hash = %s deviceID = %d", hash, deviceID) - devices.markDeviceIDFree(deviceID) - return err - } - - for { - if err := devicemapper.CreateSnapDeviceRaw(devices.getPoolDevName(), deviceID, baseInfo.DeviceID); err != nil { - if devicemapper.DeviceIDExists(err) { - // Device ID already exists. This should not - // happen. Now we have a mechanism to find - // a free device ID. So something is not right. - // Give a warning and continue. - logrus.Errorf("devmapper: Device ID %d exists in pool but it is supposed to be unused", deviceID) - deviceID, err = devices.getNextFreeDeviceID() - if err != nil { - return err - } - // Save new device id into transaction - devices.refreshTransaction(deviceID) - continue - } - logrus.Debugf("devmapper: Error creating snap device: %s", err) - devices.markDeviceIDFree(deviceID) - return err - } - break - } - - if _, err := devices.registerDevice(deviceID, hash, size, devices.OpenTransactionID); err != nil { - devicemapper.DeleteDevice(devices.getPoolDevName(), deviceID) - devices.markDeviceIDFree(deviceID) - logrus.Debugf("devmapper: Error registering device: %s", err) - return err - } - - if err := devices.closeTransaction(); err != nil { - devices.unregisterDevice(deviceID, hash) - devicemapper.DeleteDevice(devices.getPoolDevName(), deviceID) - devices.markDeviceIDFree(deviceID) - return err - } - return nil -} - -func (devices *DeviceSet) loadMetadata(hash string) *devInfo { - info := &devInfo{Hash: hash, devices: devices} - - jsonData, err := ioutil.ReadFile(devices.metadataFile(info)) - if err != nil { - logrus.Debugf("devmapper: Failed to read %s with err: %v", devices.metadataFile(info), err) - return nil - } - - if err := json.Unmarshal(jsonData, &info); err != nil { - logrus.Debugf("devmapper: Failed to unmarshal devInfo from %s with err: %v", devices.metadataFile(info), err) - return nil - } - - if info.DeviceID > maxDeviceID { - logrus.Errorf("devmapper: Ignoring Invalid DeviceId=%d", info.DeviceID) - return nil - } - - return info -} - -func getDeviceUUID(device string) (string, error) { - out, err := exec.Command("blkid", "-s", "UUID", "-o", "value", device).Output() - if err != nil { - return "", fmt.Errorf("devmapper: Failed to find uuid for device %s:%v", device, err) - } - - uuid := strings.TrimSuffix(string(out), "\n") - uuid = strings.TrimSpace(uuid) - logrus.Debugf("devmapper: UUID for device: %s is:%s", device, uuid) - return uuid, nil -} - -func (devices *DeviceSet) getBaseDeviceSize() uint64 { - info, _ := devices.lookupDevice("") - if info == nil { - return 0 - } - return info.Size -} - -func (devices *DeviceSet) getBaseDeviceFS() string { - return devices.BaseDeviceFilesystem -} - -func (devices *DeviceSet) verifyBaseDeviceUUIDFS(baseInfo *devInfo) error { - devices.Lock() - defer devices.Unlock() - - if err := devices.activateDeviceIfNeeded(baseInfo, false); err != nil { - return err - } - defer devices.deactivateDevice(baseInfo) - - uuid, err := getDeviceUUID(baseInfo.DevName()) - if err != nil { - return err - } - - if devices.BaseDeviceUUID != uuid { - return fmt.Errorf("devmapper: Current Base Device UUID:%s does not match with stored UUID:%s. Possibly using a different thin pool than last invocation", uuid, devices.BaseDeviceUUID) - } - - if devices.BaseDeviceFilesystem == "" { - fsType, err := ProbeFsType(baseInfo.DevName()) - if err != nil { - return err - } - if err := devices.saveBaseDeviceFilesystem(fsType); err != nil { - return err - } - } - - // If user specified a filesystem using dm.fs option and current - // file system of base image is not same, warn user that dm.fs - // will be ignored. - if devices.BaseDeviceFilesystem != devices.filesystem { - logrus.Warnf("devmapper: Base device already exists and has filesystem %s on it. User specified filesystem %s will be ignored.", devices.BaseDeviceFilesystem, devices.filesystem) - devices.filesystem = devices.BaseDeviceFilesystem - } - return nil -} - -func (devices *DeviceSet) saveBaseDeviceFilesystem(fs string) error { - devices.BaseDeviceFilesystem = fs - return devices.saveDeviceSetMetaData() -} - -func (devices *DeviceSet) saveBaseDeviceUUID(baseInfo *devInfo) error { - devices.Lock() - defer devices.Unlock() - - if err := devices.activateDeviceIfNeeded(baseInfo, false); err != nil { - return err - } - defer devices.deactivateDevice(baseInfo) - - uuid, err := getDeviceUUID(baseInfo.DevName()) - if err != nil { - return err - } - - devices.BaseDeviceUUID = uuid - return devices.saveDeviceSetMetaData() -} - -func (devices *DeviceSet) createBaseImage() error { - logrus.Debug("devmapper: Initializing base device-mapper thin volume") - - // Create initial device - info, err := devices.createRegisterDevice("") - if err != nil { - return err - } - - logrus.Debug("devmapper: Creating filesystem on base device-mapper thin volume") - - if err := devices.activateDeviceIfNeeded(info, false); err != nil { - return err - } - - if err := devices.createFilesystem(info); err != nil { - return err - } - - info.Initialized = true - if err := devices.saveMetadata(info); err != nil { - info.Initialized = false - return err - } - - if err := devices.saveBaseDeviceUUID(info); err != nil { - return fmt.Errorf("devmapper: Could not query and save base device UUID:%v", err) - } - - return nil -} - -// Returns if thin pool device exists or not. If device exists, also makes -// sure it is a thin pool device and not some other type of device. -func (devices *DeviceSet) thinPoolExists(thinPoolDevice string) (bool, error) { - logrus.Debugf("devmapper: Checking for existence of the pool %s", thinPoolDevice) - - info, err := devicemapper.GetInfo(thinPoolDevice) - if err != nil { - return false, fmt.Errorf("devmapper: GetInfo() on device %s failed: %v", thinPoolDevice, err) - } - - // Device does not exist. - if info.Exists == 0 { - return false, nil - } - - _, _, deviceType, _, err := devicemapper.GetStatus(thinPoolDevice) - if err != nil { - return false, fmt.Errorf("devmapper: GetStatus() on device %s failed: %v", thinPoolDevice, err) - } - - if deviceType != "thin-pool" { - return false, fmt.Errorf("devmapper: Device %s is not a thin pool", thinPoolDevice) - } - - return true, nil -} - -func (devices *DeviceSet) checkThinPool() error { - _, transactionID, dataUsed, _, _, _, err := devices.poolStatus() - if err != nil { - return err - } - if dataUsed != 0 { - return fmt.Errorf("devmapper: Unable to take ownership of thin-pool (%s) that already has used data blocks", - devices.thinPoolDevice) - } - if transactionID != 0 { - return fmt.Errorf("devmapper: Unable to take ownership of thin-pool (%s) with non-zero transaction ID", - devices.thinPoolDevice) - } - return nil -} - -// Base image is initialized properly. Either save UUID for first time (for -// upgrade case or verify UUID. -func (devices *DeviceSet) setupVerifyBaseImageUUIDFS(baseInfo *devInfo) error { - // If BaseDeviceUUID is nil (upgrade case), save it and return success. - if devices.BaseDeviceUUID == "" { - if err := devices.saveBaseDeviceUUID(baseInfo); err != nil { - return fmt.Errorf("devmapper: Could not query and save base device UUID:%v", err) - } - return nil - } - - if err := devices.verifyBaseDeviceUUIDFS(baseInfo); err != nil { - return fmt.Errorf("devmapper: Base Device UUID and Filesystem verification failed: %v", err) - } - - return nil -} - -func (devices *DeviceSet) checkGrowBaseDeviceFS(info *devInfo) error { - - if !userBaseSize { - return nil - } - - if devices.baseFsSize < devices.getBaseDeviceSize() { - return fmt.Errorf("devmapper: Base device size cannot be smaller than %s", units.HumanSize(float64(devices.getBaseDeviceSize()))) - } - - if devices.baseFsSize == devices.getBaseDeviceSize() { - return nil - } - - info.lock.Lock() - defer info.lock.Unlock() - - devices.Lock() - defer devices.Unlock() - - info.Size = devices.baseFsSize - - if err := devices.saveMetadata(info); err != nil { - // Try to remove unused device - delete(devices.Devices, info.Hash) - return err - } - - return devices.growFS(info) -} - -func (devices *DeviceSet) growFS(info *devInfo) error { - if err := devices.activateDeviceIfNeeded(info, false); err != nil { - return fmt.Errorf("Error activating devmapper device: %s", err) - } - - defer devices.deactivateDevice(info) - - fsMountPoint := "/run/docker/mnt" - if _, err := os.Stat(fsMountPoint); os.IsNotExist(err) { - if err := os.MkdirAll(fsMountPoint, 0700); err != nil { - return err - } - defer os.RemoveAll(fsMountPoint) - } - - options := "" - if devices.BaseDeviceFilesystem == "xfs" { - // XFS needs nouuid or it can't mount filesystems with the same fs - options = joinMountOptions(options, "nouuid") - } - options = joinMountOptions(options, devices.mountOptions) - - if err := mount.Mount(info.DevName(), fsMountPoint, devices.BaseDeviceFilesystem, options); err != nil { - return fmt.Errorf("Error mounting '%s' on '%s': %s", info.DevName(), fsMountPoint, err) - } - - defer syscall.Unmount(fsMountPoint, syscall.MNT_DETACH) - - switch devices.BaseDeviceFilesystem { - case "ext4": - if out, err := exec.Command("resize2fs", info.DevName()).CombinedOutput(); err != nil { - return fmt.Errorf("Failed to grow rootfs:%v:%s", err, string(out)) - } - case "xfs": - if out, err := exec.Command("xfs_growfs", info.DevName()).CombinedOutput(); err != nil { - return fmt.Errorf("Failed to grow rootfs:%v:%s", err, string(out)) - } - default: - return fmt.Errorf("Unsupported filesystem type %s", devices.BaseDeviceFilesystem) - } - return nil -} - -func (devices *DeviceSet) setupBaseImage() error { - oldInfo, _ := devices.lookupDeviceWithLock("") - - // base image already exists. If it is initialized properly, do UUID - // verification and return. Otherwise remove image and set it up - // fresh. - - if oldInfo != nil { - if oldInfo.Initialized && !oldInfo.Deleted { - if err := devices.setupVerifyBaseImageUUIDFS(oldInfo); err != nil { - return err - } - - if err := devices.checkGrowBaseDeviceFS(oldInfo); err != nil { - return err - } - - return nil - } - - logrus.Debug("devmapper: Removing uninitialized base image") - // If previous base device is in deferred delete state, - // that needs to be cleaned up first. So don't try - // deferred deletion. - if err := devices.DeleteDevice("", true); err != nil { - return err - } - } - - // If we are setting up base image for the first time, make sure - // thin pool is empty. - if devices.thinPoolDevice != "" && oldInfo == nil { - if err := devices.checkThinPool(); err != nil { - return err - } - } - - // Create new base image device - if err := devices.createBaseImage(); err != nil { - return err - } - - return nil -} - -func setCloseOnExec(name string) { - if fileInfos, _ := ioutil.ReadDir("/proc/self/fd"); fileInfos != nil { - for _, i := range fileInfos { - link, _ := os.Readlink(filepath.Join("/proc/self/fd", i.Name())) - if link == name { - fd, err := strconv.Atoi(i.Name()) - if err == nil { - syscall.CloseOnExec(fd) - } - } - } - } -} - -// DMLog implements logging using DevMapperLogger interface. -func (devices *DeviceSet) DMLog(level int, file string, line int, dmError int, message string) { - // By default libdm sends us all the messages including debug ones. - // We need to filter out messages here and figure out which one - // should be printed. - if level > logLevel { - return - } - - // FIXME(vbatts) push this back into ./pkg/devicemapper/ - if level <= devicemapper.LogLevelErr { - logrus.Errorf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message) - } else if level <= devicemapper.LogLevelInfo { - logrus.Infof("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message) - } else { - // FIXME(vbatts) push this back into ./pkg/devicemapper/ - logrus.Debugf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message) - } -} - -func major(device uint64) uint64 { - return (device >> 8) & 0xfff -} - -func minor(device uint64) uint64 { - return (device & 0xff) | ((device >> 12) & 0xfff00) -} - -// ResizePool increases the size of the pool. -func (devices *DeviceSet) ResizePool(size int64) error { - dirname := devices.loopbackDir() - datafilename := path.Join(dirname, "data") - if len(devices.dataDevice) > 0 { - datafilename = devices.dataDevice - } - metadatafilename := path.Join(dirname, "metadata") - if len(devices.metadataDevice) > 0 { - metadatafilename = devices.metadataDevice - } - - datafile, err := os.OpenFile(datafilename, os.O_RDWR, 0) - if datafile == nil { - return err - } - defer datafile.Close() - - fi, err := datafile.Stat() - if fi == nil { - return err - } - - if fi.Size() > size { - return fmt.Errorf("devmapper: Can't shrink file") - } - - dataloopback := loopback.FindLoopDeviceFor(datafile) - if dataloopback == nil { - return fmt.Errorf("devmapper: Unable to find loopback mount for: %s", datafilename) - } - defer dataloopback.Close() - - metadatafile, err := os.OpenFile(metadatafilename, os.O_RDWR, 0) - if metadatafile == nil { - return err - } - defer metadatafile.Close() - - metadataloopback := loopback.FindLoopDeviceFor(metadatafile) - if metadataloopback == nil { - return fmt.Errorf("devmapper: Unable to find loopback mount for: %s", metadatafilename) - } - defer metadataloopback.Close() - - // Grow loopback file - if err := datafile.Truncate(size); err != nil { - return fmt.Errorf("devmapper: Unable to grow loopback file: %s", err) - } - - // Reload size for loopback device - if err := loopback.SetCapacity(dataloopback); err != nil { - return fmt.Errorf("Unable to update loopback capacity: %s", err) - } - - // Suspend the pool - if err := devicemapper.SuspendDevice(devices.getPoolName()); err != nil { - return fmt.Errorf("devmapper: Unable to suspend pool: %s", err) - } - - // Reload with the new block sizes - if err := devicemapper.ReloadPool(devices.getPoolName(), dataloopback, metadataloopback, devices.thinpBlockSize); err != nil { - return fmt.Errorf("devmapper: Unable to reload pool: %s", err) - } - - // Resume the pool - if err := devicemapper.ResumeDevice(devices.getPoolName()); err != nil { - return fmt.Errorf("devmapper: Unable to resume pool: %s", err) - } - - return nil -} - -func (devices *DeviceSet) loadTransactionMetaData() error { - jsonData, err := ioutil.ReadFile(devices.transactionMetaFile()) - if err != nil { - // There is no active transaction. This will be the case - // during upgrade. - if os.IsNotExist(err) { - devices.OpenTransactionID = devices.TransactionID - return nil - } - return err - } - - json.Unmarshal(jsonData, &devices.transaction) - return nil -} - -func (devices *DeviceSet) saveTransactionMetaData() error { - jsonData, err := json.Marshal(&devices.transaction) - if err != nil { - return fmt.Errorf("devmapper: Error encoding metadata to json: %s", err) - } - - return devices.writeMetaFile(jsonData, devices.transactionMetaFile()) -} - -func (devices *DeviceSet) removeTransactionMetaData() error { - if err := os.RemoveAll(devices.transactionMetaFile()); err != nil { - return err - } - return nil -} - -func (devices *DeviceSet) rollbackTransaction() error { - logrus.Debugf("devmapper: Rolling back open transaction: TransactionID=%d hash=%s device_id=%d", devices.OpenTransactionID, devices.DeviceIDHash, devices.DeviceID) - - // A device id might have already been deleted before transaction - // closed. In that case this call will fail. Just leave a message - // in case of failure. - if err := devicemapper.DeleteDevice(devices.getPoolDevName(), devices.DeviceID); err != nil { - logrus.Errorf("devmapper: Unable to delete device: %s", err) - } - - dinfo := &devInfo{Hash: devices.DeviceIDHash} - if err := devices.removeMetadata(dinfo); err != nil { - logrus.Errorf("devmapper: Unable to remove metadata: %s", err) - } else { - devices.markDeviceIDFree(devices.DeviceID) - } - - if err := devices.removeTransactionMetaData(); err != nil { - logrus.Errorf("devmapper: Unable to remove transaction meta file %s: %s", devices.transactionMetaFile(), err) - } - - return nil -} - -func (devices *DeviceSet) processPendingTransaction() error { - if err := devices.loadTransactionMetaData(); err != nil { - return err - } - - // If there was open transaction but pool transaction ID is same - // as open transaction ID, nothing to roll back. - if devices.TransactionID == devices.OpenTransactionID { - return nil - } - - // If open transaction ID is less than pool transaction ID, something - // is wrong. Bail out. - if devices.OpenTransactionID < devices.TransactionID { - logrus.Errorf("devmapper: Open Transaction id %d is less than pool transaction id %d", devices.OpenTransactionID, devices.TransactionID) - return nil - } - - // Pool transaction ID is not same as open transaction. There is - // a transaction which was not completed. - if err := devices.rollbackTransaction(); err != nil { - return fmt.Errorf("devmapper: Rolling back open transaction failed: %s", err) - } - - devices.OpenTransactionID = devices.TransactionID - return nil -} - -func (devices *DeviceSet) loadDeviceSetMetaData() error { - jsonData, err := ioutil.ReadFile(devices.deviceSetMetaFile()) - if err != nil { - // For backward compatibility return success if file does - // not exist. - if os.IsNotExist(err) { - return nil - } - return err - } - - return json.Unmarshal(jsonData, devices) -} - -func (devices *DeviceSet) saveDeviceSetMetaData() error { - jsonData, err := json.Marshal(devices) - if err != nil { - return fmt.Errorf("devmapper: Error encoding metadata to json: %s", err) - } - - return devices.writeMetaFile(jsonData, devices.deviceSetMetaFile()) -} - -func (devices *DeviceSet) openTransaction(hash string, DeviceID int) error { - devices.allocateTransactionID() - devices.DeviceIDHash = hash - devices.DeviceID = DeviceID - if err := devices.saveTransactionMetaData(); err != nil { - return fmt.Errorf("devmapper: Error saving transaction metadata: %s", err) - } - return nil -} - -func (devices *DeviceSet) refreshTransaction(DeviceID int) error { - devices.DeviceID = DeviceID - if err := devices.saveTransactionMetaData(); err != nil { - return fmt.Errorf("devmapper: Error saving transaction metadata: %s", err) - } - return nil -} - -func (devices *DeviceSet) closeTransaction() error { - if err := devices.updatePoolTransactionID(); err != nil { - logrus.Debug("devmapper: Failed to close Transaction") - return err - } - return nil -} - -func determineDriverCapabilities(version string) error { - /* - * Driver version 4.27.0 and greater support deferred activation - * feature. - */ - - logrus.Debugf("devicemapper: driver version is %s", version) - - versionSplit := strings.Split(version, ".") - major, err := strconv.Atoi(versionSplit[0]) - if err != nil { - return graphdriver.ErrNotSupported - } - - if major > 4 { - driverDeferredRemovalSupport = true - return nil - } - - if major < 4 { - return nil - } - - minor, err := strconv.Atoi(versionSplit[1]) - if err != nil { - return graphdriver.ErrNotSupported - } - - /* - * If major is 4 and minor is 27, then there is no need to - * check for patch level as it can not be less than 0. - */ - if minor >= 27 { - driverDeferredRemovalSupport = true - return nil - } - - return nil -} - -// Determine the major and minor number of loopback device -func getDeviceMajorMinor(file *os.File) (uint64, uint64, error) { - stat, err := file.Stat() - if err != nil { - return 0, 0, err - } - - dev := stat.Sys().(*syscall.Stat_t).Rdev - majorNum := major(dev) - minorNum := minor(dev) - - logrus.Debugf("devmapper: Major:Minor for device: %s is:%v:%v", file.Name(), majorNum, minorNum) - return majorNum, minorNum, nil -} - -// Given a file which is backing file of a loop back device, find the -// loopback device name and its major/minor number. -func getLoopFileDeviceMajMin(filename string) (string, uint64, uint64, error) { - file, err := os.Open(filename) - if err != nil { - logrus.Debugf("devmapper: Failed to open file %s", filename) - return "", 0, 0, err - } - - defer file.Close() - loopbackDevice := loopback.FindLoopDeviceFor(file) - if loopbackDevice == nil { - return "", 0, 0, fmt.Errorf("devmapper: Unable to find loopback mount for: %s", filename) - } - defer loopbackDevice.Close() - - Major, Minor, err := getDeviceMajorMinor(loopbackDevice) - if err != nil { - return "", 0, 0, err - } - return loopbackDevice.Name(), Major, Minor, nil -} - -// Get the major/minor numbers of thin pool data and metadata devices -func (devices *DeviceSet) getThinPoolDataMetaMajMin() (uint64, uint64, uint64, uint64, error) { - var params, poolDataMajMin, poolMetadataMajMin string - - _, _, _, params, err := devicemapper.GetTable(devices.getPoolName()) - if err != nil { - return 0, 0, 0, 0, err - } - - if _, err = fmt.Sscanf(params, "%s %s", &poolMetadataMajMin, &poolDataMajMin); err != nil { - return 0, 0, 0, 0, err - } - - logrus.Debugf("devmapper: poolDataMajMin=%s poolMetaMajMin=%s\n", poolDataMajMin, poolMetadataMajMin) - - poolDataMajMinorSplit := strings.Split(poolDataMajMin, ":") - poolDataMajor, err := strconv.ParseUint(poolDataMajMinorSplit[0], 10, 32) - if err != nil { - return 0, 0, 0, 0, err - } - - poolDataMinor, err := strconv.ParseUint(poolDataMajMinorSplit[1], 10, 32) - if err != nil { - return 0, 0, 0, 0, err - } - - poolMetadataMajMinorSplit := strings.Split(poolMetadataMajMin, ":") - poolMetadataMajor, err := strconv.ParseUint(poolMetadataMajMinorSplit[0], 10, 32) - if err != nil { - return 0, 0, 0, 0, err - } - - poolMetadataMinor, err := strconv.ParseUint(poolMetadataMajMinorSplit[1], 10, 32) - if err != nil { - return 0, 0, 0, 0, err - } - - return poolDataMajor, poolDataMinor, poolMetadataMajor, poolMetadataMinor, nil -} - -func (devices *DeviceSet) loadThinPoolLoopBackInfo() error { - poolDataMajor, poolDataMinor, poolMetadataMajor, poolMetadataMinor, err := devices.getThinPoolDataMetaMajMin() - if err != nil { - return err - } - - dirname := devices.loopbackDir() - - // data device has not been passed in. So there should be a data file - // which is being mounted as loop device. - if devices.dataDevice == "" { - datafilename := path.Join(dirname, "data") - dataLoopDevice, dataMajor, dataMinor, err := getLoopFileDeviceMajMin(datafilename) - if err != nil { - return err - } - - // Compare the two - if poolDataMajor == dataMajor && poolDataMinor == dataMinor { - devices.dataDevice = dataLoopDevice - devices.dataLoopFile = datafilename - } - - } - - // metadata device has not been passed in. So there should be a - // metadata file which is being mounted as loop device. - if devices.metadataDevice == "" { - metadatafilename := path.Join(dirname, "metadata") - metadataLoopDevice, metadataMajor, metadataMinor, err := getLoopFileDeviceMajMin(metadatafilename) - if err != nil { - return err - } - if poolMetadataMajor == metadataMajor && poolMetadataMinor == metadataMinor { - devices.metadataDevice = metadataLoopDevice - devices.metadataLoopFile = metadatafilename - } - } - - return nil -} - -func (devices *DeviceSet) enableDeferredRemovalDeletion() error { - - // If user asked for deferred removal then check both libdm library - // and kernel driver support deferred removal otherwise error out. - if enableDeferredRemoval { - if !driverDeferredRemovalSupport { - return fmt.Errorf("devmapper: Deferred removal can not be enabled as kernel does not support it") - } - if !devicemapper.LibraryDeferredRemovalSupport { - return fmt.Errorf("devmapper: Deferred removal can not be enabled as libdm does not support it") - } - logrus.Debug("devmapper: Deferred removal support enabled.") - devices.deferredRemove = true - } - - if enableDeferredDeletion { - if !devices.deferredRemove { - return fmt.Errorf("devmapper: Deferred deletion can not be enabled as deferred removal is not enabled. Enable deferred removal using --storage-opt dm.use_deferred_removal=true parameter") - } - logrus.Debug("devmapper: Deferred deletion support enabled.") - devices.deferredDelete = true - } - return nil -} - -func (devices *DeviceSet) initDevmapper(doInit bool) error { - // give ourselves to libdm as a log handler - devicemapper.LogInit(devices) - - version, err := devicemapper.GetDriverVersion() - if err != nil { - // Can't even get driver version, assume not supported - return graphdriver.ErrNotSupported - } - - if err := determineDriverCapabilities(version); err != nil { - return graphdriver.ErrNotSupported - } - - if err := devices.enableDeferredRemovalDeletion(); err != nil { - return err - } - - // https://github.com/docker/docker/issues/4036 - if supported := devicemapper.UdevSetSyncSupport(true); !supported { - if dockerversion.IAmStatic == "true" { - logrus.Error("devmapper: Udev sync is not supported. This will lead to data loss and unexpected behavior. Install a dynamic binary to use devicemapper or select a different storage driver. For more information, see https://docs.docker.com/engine/reference/commandline/daemon/#daemon-storage-driver-option") - } else { - logrus.Error("devmapper: Udev sync is not supported. This will lead to data loss and unexpected behavior. Install a more recent version of libdevmapper or select a different storage driver. For more information, see https://docs.docker.com/engine/reference/commandline/daemon/#daemon-storage-driver-option") - } - - if !devices.overrideUdevSyncCheck { - return graphdriver.ErrNotSupported - } - } - - //create the root dir of the devmapper driver ownership to match this - //daemon's remapped root uid/gid so containers can start properly - uid, gid, err := idtools.GetRootUIDGID(devices.uidMaps, devices.gidMaps) - if err != nil { - return err - } - if err := idtools.MkdirAs(devices.root, 0700, uid, gid); err != nil && !os.IsExist(err) { - return err - } - if err := os.MkdirAll(devices.metadataDir(), 0700); err != nil && !os.IsExist(err) { - return err - } - - // Set the device prefix from the device id and inode of the docker root dir - - st, err := os.Stat(devices.root) - if err != nil { - return fmt.Errorf("devmapper: Error looking up dir %s: %s", devices.root, err) - } - sysSt := st.Sys().(*syscall.Stat_t) - // "reg-" stands for "regular file". - // In the future we might use "dev-" for "device file", etc. - // docker-maj,min[-inode] stands for: - // - Managed by docker - // - The target of this device is at major and minor - // - If is defined, use that file inside the device as a loopback image. Otherwise use the device itself. - devices.devicePrefix = fmt.Sprintf("docker-%d:%d-%d", major(sysSt.Dev), minor(sysSt.Dev), sysSt.Ino) - logrus.Debugf("devmapper: Generated prefix: %s", devices.devicePrefix) - - // Check for the existence of the thin-pool device - poolExists, err := devices.thinPoolExists(devices.getPoolName()) - if err != nil { - return err - } - - // It seems libdevmapper opens this without O_CLOEXEC, and go exec will not close files - // that are not Close-on-exec, - // so we add this badhack to make sure it closes itself - setCloseOnExec("/dev/mapper/control") - - // Make sure the sparse images exist in /devicemapper/data and - // /devicemapper/metadata - - createdLoopback := false - - // If the pool doesn't exist, create it - if !poolExists && devices.thinPoolDevice == "" { - logrus.Debug("devmapper: Pool doesn't exist. Creating it.") - - var ( - dataFile *os.File - metadataFile *os.File - ) - - if devices.dataDevice == "" { - // Make sure the sparse images exist in /devicemapper/data - - hasData := devices.hasImage("data") - - if !doInit && !hasData { - return errors.New("loopback data file not found") - } - - if !hasData { - createdLoopback = true - } - - data, err := devices.ensureImage("data", devices.dataLoopbackSize) - if err != nil { - logrus.Debugf("devmapper: Error device ensureImage (data): %s", err) - return err - } - - dataFile, err = loopback.AttachLoopDevice(data) - if err != nil { - return err - } - devices.dataLoopFile = data - devices.dataDevice = dataFile.Name() - } else { - dataFile, err = os.OpenFile(devices.dataDevice, os.O_RDWR, 0600) - if err != nil { - return err - } - } - defer dataFile.Close() - - if devices.metadataDevice == "" { - // Make sure the sparse images exist in /devicemapper/metadata - - hasMetadata := devices.hasImage("metadata") - - if !doInit && !hasMetadata { - return errors.New("loopback metadata file not found") - } - - if !hasMetadata { - createdLoopback = true - } - - metadata, err := devices.ensureImage("metadata", devices.metaDataLoopbackSize) - if err != nil { - logrus.Debugf("devmapper: Error device ensureImage (metadata): %s", err) - return err - } - - metadataFile, err = loopback.AttachLoopDevice(metadata) - if err != nil { - return err - } - devices.metadataLoopFile = metadata - devices.metadataDevice = metadataFile.Name() - } else { - metadataFile, err = os.OpenFile(devices.metadataDevice, os.O_RDWR, 0600) - if err != nil { - return err - } - } - defer metadataFile.Close() - - if err := devicemapper.CreatePool(devices.getPoolName(), dataFile, metadataFile, devices.thinpBlockSize); err != nil { - return err - } - } - - // Pool already exists and caller did not pass us a pool. That means - // we probably created pool earlier and could not remove it as some - // containers were still using it. Detect some of the properties of - // pool, like is it using loop devices. - if poolExists && devices.thinPoolDevice == "" { - if err := devices.loadThinPoolLoopBackInfo(); err != nil { - logrus.Debugf("devmapper: Failed to load thin pool loopback device information:%v", err) - return err - } - } - - // If we didn't just create the data or metadata image, we need to - // load the transaction id and migrate old metadata - if !createdLoopback { - if err := devices.initMetaData(); err != nil { - return err - } - } - - if devices.thinPoolDevice == "" { - if devices.metadataLoopFile != "" || devices.dataLoopFile != "" { - logrus.Warn("devmapper: Usage of loopback devices is strongly discouraged for production use. Please use `--storage-opt dm.thinpooldev` or use `man docker` to refer to dm.thinpooldev section.") - } - } - - // Right now this loads only NextDeviceID. If there is more metadata - // down the line, we might have to move it earlier. - if err := devices.loadDeviceSetMetaData(); err != nil { - return err - } - - // Setup the base image - if doInit { - if err := devices.setupBaseImage(); err != nil { - logrus.Debugf("devmapper: Error device setupBaseImage: %s", err) - return err - } - } - - return nil -} - -// AddDevice adds a device and registers in the hash. -func (devices *DeviceSet) AddDevice(hash, baseHash string, storageOpt map[string]string) error { - logrus.Debugf("devmapper: AddDevice START(hash=%s basehash=%s)", hash, baseHash) - defer logrus.Debugf("devmapper: AddDevice END(hash=%s basehash=%s)", hash, baseHash) - - // If a deleted device exists, return error. - baseInfo, err := devices.lookupDeviceWithLock(baseHash) - if err != nil { - return err - } - - if baseInfo.Deleted { - return fmt.Errorf("devmapper: Base device %v has been marked for deferred deletion", baseInfo.Hash) - } - - baseInfo.lock.Lock() - defer baseInfo.lock.Unlock() - - devices.Lock() - defer devices.Unlock() - - // Also include deleted devices in case hash of new device is - // same as one of the deleted devices. - if info, _ := devices.lookupDevice(hash); info != nil { - return fmt.Errorf("devmapper: device %s already exists. Deleted=%v", hash, info.Deleted) - } - - size, err := devices.parseStorageOpt(storageOpt) - if err != nil { - return err - } - - if size == 0 { - size = baseInfo.Size - } - - if size < baseInfo.Size { - return fmt.Errorf("devmapper: Container size cannot be smaller than %s", units.HumanSize(float64(baseInfo.Size))) - } - - if err := devices.takeSnapshot(hash, baseInfo, size); err != nil { - return err - } - - // Grow the container rootfs. - if size > baseInfo.Size { - info, err := devices.lookupDevice(hash) - if err != nil { - return err - } - - if err := devices.growFS(info); err != nil { - return err - } - } - - return nil -} - -func (devices *DeviceSet) parseStorageOpt(storageOpt map[string]string) (uint64, error) { - - // Read size to change the block device size per container. - for key, val := range storageOpt { - key := strings.ToLower(key) - switch key { - case "size": - size, err := units.RAMInBytes(val) - if err != nil { - return 0, err - } - return uint64(size), nil - default: - return 0, fmt.Errorf("Unknown option %s", key) - } - } - - return 0, nil -} - -func (devices *DeviceSet) markForDeferredDeletion(info *devInfo) error { - // If device is already in deleted state, there is nothing to be done. - if info.Deleted { - return nil - } - - logrus.Debugf("devmapper: Marking device %s for deferred deletion.", info.Hash) - - info.Deleted = true - - // save device metadata to reflect deleted state. - if err := devices.saveMetadata(info); err != nil { - info.Deleted = false - return err - } - - devices.nrDeletedDevices++ - return nil -} - -// Should be called with devices.Lock() held. -func (devices *DeviceSet) deleteTransaction(info *devInfo, syncDelete bool) error { - if err := devices.openTransaction(info.Hash, info.DeviceID); err != nil { - logrus.Debugf("devmapper: Error opening transaction hash = %s deviceId = %d", "", info.DeviceID) - return err - } - - defer devices.closeTransaction() - - err := devicemapper.DeleteDevice(devices.getPoolDevName(), info.DeviceID) - if err != nil { - // If syncDelete is true, we want to return error. If deferred - // deletion is not enabled, we return an error. If error is - // something other then EBUSY, return an error. - if syncDelete || !devices.deferredDelete || err != devicemapper.ErrBusy { - logrus.Debugf("devmapper: Error deleting device: %s", err) - return err - } - } - - if err == nil { - if err := devices.unregisterDevice(info.DeviceID, info.Hash); err != nil { - return err - } - // If device was already in deferred delete state that means - // deletion was being tried again later. Reduce the deleted - // device count. - if info.Deleted { - devices.nrDeletedDevices-- - } - devices.markDeviceIDFree(info.DeviceID) - } else { - if err := devices.markForDeferredDeletion(info); err != nil { - return err - } - } - - return nil -} - -// Issue discard only if device open count is zero. -func (devices *DeviceSet) issueDiscard(info *devInfo) error { - logrus.Debugf("devmapper: issueDiscard START(device: %s).", info.Hash) - defer logrus.Debugf("devmapper: issueDiscard END(device: %s).", info.Hash) - // This is a workaround for the kernel not discarding block so - // on the thin pool when we remove a thinp device, so we do it - // manually. - // Even if device is deferred deleted, activate it and issue - // discards. - if err := devices.activateDeviceIfNeeded(info, true); err != nil { - return err - } - - devinfo, err := devicemapper.GetInfo(info.Name()) - if err != nil { - return err - } - - if devinfo.OpenCount != 0 { - logrus.Debugf("devmapper: Device: %s is in use. OpenCount=%d. Not issuing discards.", info.Hash, devinfo.OpenCount) - return nil - } - - if err := devicemapper.BlockDeviceDiscard(info.DevName()); err != nil { - logrus.Debugf("devmapper: Error discarding block on device: %s (ignoring)", err) - } - return nil -} - -// Should be called with devices.Lock() held. -func (devices *DeviceSet) deleteDevice(info *devInfo, syncDelete bool) error { - if devices.doBlkDiscard { - devices.issueDiscard(info) - } - - // Try to deactivate device in case it is active. - if err := devices.deactivateDevice(info); err != nil { - logrus.Debugf("devmapper: Error deactivating device: %s", err) - return err - } - - if err := devices.deleteTransaction(info, syncDelete); err != nil { - return err - } - - return nil -} - -// DeleteDevice will return success if device has been marked for deferred -// removal. If one wants to override that and want DeleteDevice() to fail if -// device was busy and could not be deleted, set syncDelete=true. -func (devices *DeviceSet) DeleteDevice(hash string, syncDelete bool) error { - logrus.Debugf("devmapper: DeleteDevice START(hash=%v syncDelete=%v)", hash, syncDelete) - defer logrus.Debugf("devmapper: DeleteDevice END(hash=%v syncDelete=%v)", hash, syncDelete) - info, err := devices.lookupDeviceWithLock(hash) - if err != nil { - return err - } - - info.lock.Lock() - defer info.lock.Unlock() - - devices.Lock() - defer devices.Unlock() - - return devices.deleteDevice(info, syncDelete) -} - -func (devices *DeviceSet) deactivatePool() error { - logrus.Debug("devmapper: deactivatePool() START") - defer logrus.Debug("devmapper: deactivatePool() END") - devname := devices.getPoolDevName() - - devinfo, err := devicemapper.GetInfo(devname) - if err != nil { - return err - } - - if devinfo.Exists == 0 { - return nil - } - if err := devicemapper.RemoveDevice(devname); err != nil { - return err - } - - if d, err := devicemapper.GetDeps(devname); err == nil { - logrus.Warnf("devmapper: device %s still has %d active dependents", devname, d.Count) - } - - return nil -} - -func (devices *DeviceSet) deactivateDevice(info *devInfo) error { - logrus.Debugf("devmapper: deactivateDevice START(%s)", info.Hash) - defer logrus.Debugf("devmapper: deactivateDevice END(%s)", info.Hash) - - devinfo, err := devicemapper.GetInfo(info.Name()) - if err != nil { - return err - } - - if devinfo.Exists == 0 { - return nil - } - - if devices.deferredRemove { - if err := devicemapper.RemoveDeviceDeferred(info.Name()); err != nil { - return err - } - } else { - if err := devices.removeDevice(info.Name()); err != nil { - return err - } - } - return nil -} - -// Issues the underlying dm remove operation. -func (devices *DeviceSet) removeDevice(devname string) error { - var err error - - logrus.Debugf("devmapper: removeDevice START(%s)", devname) - defer logrus.Debugf("devmapper: removeDevice END(%s)", devname) - - for i := 0; i < 200; i++ { - err = devicemapper.RemoveDevice(devname) - if err == nil { - break - } - if err != devicemapper.ErrBusy { - return err - } - - // If we see EBUSY it may be a transient error, - // sleep a bit a retry a few times. - devices.Unlock() - time.Sleep(100 * time.Millisecond) - devices.Lock() - } - - return err -} - -func (devices *DeviceSet) cancelDeferredRemovalIfNeeded(info *devInfo) error { - if !devices.deferredRemove { - return nil - } - - logrus.Debugf("devmapper: cancelDeferredRemovalIfNeeded START(%s)", info.Name()) - defer logrus.Debugf("devmapper: cancelDeferredRemovalIfNeeded END(%s)", info.Name()) - - devinfo, err := devicemapper.GetInfoWithDeferred(info.Name()) - if err != nil { - return err - } - - if devinfo != nil && devinfo.DeferredRemove == 0 { - return nil - } - - // Cancel deferred remove - if err := devices.cancelDeferredRemoval(info); err != nil { - // If Error is ErrEnxio. Device is probably already gone. Continue. - if err != devicemapper.ErrEnxio { - return err - } - } - return nil -} - -func (devices *DeviceSet) cancelDeferredRemoval(info *devInfo) error { - logrus.Debugf("devmapper: cancelDeferredRemoval START(%s)", info.Name()) - defer logrus.Debugf("devmapper: cancelDeferredRemoval END(%s)", info.Name()) - - var err error - - // Cancel deferred remove - for i := 0; i < 100; i++ { - err = devicemapper.CancelDeferredRemove(info.Name()) - if err != nil { - if err == devicemapper.ErrBusy { - // If we see EBUSY it may be a transient error, - // sleep a bit a retry a few times. - devices.Unlock() - time.Sleep(100 * time.Millisecond) - devices.Lock() - continue - } - } - break - } - return err -} - -// Shutdown shuts down the device by unmounting the root. -func (devices *DeviceSet) Shutdown(home string) error { - logrus.Debugf("devmapper: [deviceset %s] Shutdown()", devices.devicePrefix) - logrus.Debugf("devmapper: Shutting down DeviceSet: %s", devices.root) - defer logrus.Debugf("devmapper: [deviceset %s] Shutdown() END", devices.devicePrefix) - - // Stop deletion worker. This should start delivering new events to - // ticker channel. That means no new instance of cleanupDeletedDevice() - // will run after this call. If one instance is already running at - // the time of the call, it must be holding devices.Lock() and - // we will block on this lock till cleanup function exits. - devices.deletionWorkerTicker.Stop() - - devices.Lock() - // Save DeviceSet Metadata first. Docker kills all threads if they - // don't finish in certain time. It is possible that Shutdown() - // routine does not finish in time as we loop trying to deactivate - // some devices while these are busy. In that case shutdown() routine - // will be killed and we will not get a chance to save deviceset - // metadata. Hence save this early before trying to deactivate devices. - devices.saveDeviceSetMetaData() - - // ignore the error since it's just a best effort to not try to unmount something that's mounted - mounts, _ := mount.GetMounts() - mounted := make(map[string]bool, len(mounts)) - for _, mnt := range mounts { - mounted[mnt.Mountpoint] = true - } - - if err := filepath.Walk(path.Join(home, "mnt"), func(p string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() { - return nil - } - - if mounted[p] { - // We use MNT_DETACH here in case it is still busy in some running - // container. This means it'll go away from the global scope directly, - // and the device will be released when that container dies. - if err := syscall.Unmount(p, syscall.MNT_DETACH); err != nil { - logrus.Debugf("devmapper: Shutdown unmounting %s, error: %s", p, err) - } - } - - if devInfo, err := devices.lookupDevice(path.Base(p)); err != nil { - logrus.Debugf("devmapper: Shutdown lookup device %s, error: %s", path.Base(p), err) - } else { - if err := devices.deactivateDevice(devInfo); err != nil { - logrus.Debugf("devmapper: Shutdown deactivate %s , error: %s", devInfo.Hash, err) - } - } - - return nil - }); err != nil && !os.IsNotExist(err) { - devices.Unlock() - return err - } - - devices.Unlock() - - info, _ := devices.lookupDeviceWithLock("") - if info != nil { - info.lock.Lock() - devices.Lock() - if err := devices.deactivateDevice(info); err != nil { - logrus.Debugf("devmapper: Shutdown deactivate base , error: %s", err) - } - devices.Unlock() - info.lock.Unlock() - } - - devices.Lock() - if devices.thinPoolDevice == "" { - if err := devices.deactivatePool(); err != nil { - logrus.Debugf("devmapper: Shutdown deactivate pool , error: %s", err) - } - } - devices.Unlock() - - return nil -} - -// Recent XFS changes allow changing behavior of filesystem in case of errors. -// When thin pool gets full and XFS gets ENOSPC error, currently it tries -// IO infinitely and sometimes it can block the container process -// and process can't be killWith 0 value, XFS will not retry upon error -// and instead will shutdown filesystem. - -func (devices *DeviceSet) xfsSetNospaceRetries(info *devInfo) error { - dmDevicePath, err := os.Readlink(info.DevName()) - if err != nil { - return fmt.Errorf("devmapper: readlink failed for device %v:%v", info.DevName(), err) - } - - dmDeviceName := path.Base(dmDevicePath) - filePath := "/sys/fs/xfs/" + dmDeviceName + "/error/metadata/ENOSPC/max_retries" - maxRetriesFile, err := os.OpenFile(filePath, os.O_WRONLY, 0) - if err != nil { - return fmt.Errorf("devmapper: user specified daemon option dm.xfs_nospace_max_retries but it does not seem to be supported on this system :%v", err) - } - defer maxRetriesFile.Close() - - // Set max retries to 0 - _, err = maxRetriesFile.WriteString(devices.xfsNospaceRetries) - if err != nil { - return fmt.Errorf("devmapper: Failed to write string %v to file %v:%v", devices.xfsNospaceRetries, filePath, err) - } - return nil -} - -// MountDevice mounts the device if not already mounted. -func (devices *DeviceSet) MountDevice(hash, path, mountLabel string) error { - info, err := devices.lookupDeviceWithLock(hash) - if err != nil { - return err - } - - if info.Deleted { - return fmt.Errorf("devmapper: Can't mount device %v as it has been marked for deferred deletion", info.Hash) - } - - info.lock.Lock() - defer info.lock.Unlock() - - devices.Lock() - defer devices.Unlock() - - if err := devices.activateDeviceIfNeeded(info, false); err != nil { - return fmt.Errorf("devmapper: Error activating devmapper device for '%s': %s", hash, err) - } - - fstype, err := ProbeFsType(info.DevName()) - if err != nil { - return err - } - - options := "" - - if fstype == "xfs" { - // XFS needs nouuid or it can't mount filesystems with the same fs - options = joinMountOptions(options, "nouuid") - } - - options = joinMountOptions(options, devices.mountOptions) - options = joinMountOptions(options, label.FormatMountLabel("", mountLabel)) - - if err := mount.Mount(info.DevName(), path, fstype, options); err != nil { - return fmt.Errorf("devmapper: Error mounting '%s' on '%s': %s", info.DevName(), path, err) - } - - if fstype == "xfs" && devices.xfsNospaceRetries != "" { - if err := devices.xfsSetNospaceRetries(info); err != nil { - syscall.Unmount(path, syscall.MNT_DETACH) - devices.deactivateDevice(info) - return err - } - } - - return nil -} - -// UnmountDevice unmounts the device and removes it from hash. -func (devices *DeviceSet) UnmountDevice(hash, mountPath string) error { - logrus.Debugf("devmapper: UnmountDevice START(hash=%s)", hash) - defer logrus.Debugf("devmapper: UnmountDevice END(hash=%s)", hash) - - info, err := devices.lookupDeviceWithLock(hash) - if err != nil { - return err - } - - info.lock.Lock() - defer info.lock.Unlock() - - devices.Lock() - defer devices.Unlock() - - logrus.Debugf("devmapper: Unmount(%s)", mountPath) - if err := syscall.Unmount(mountPath, syscall.MNT_DETACH); err != nil { - return err - } - logrus.Debug("devmapper: Unmount done") - - if err := devices.deactivateDevice(info); err != nil { - return err - } - - return nil -} - -// HasDevice returns true if the device metadata exists. -func (devices *DeviceSet) HasDevice(hash string) bool { - info, _ := devices.lookupDeviceWithLock(hash) - return info != nil -} - -// List returns a list of device ids. -func (devices *DeviceSet) List() []string { - devices.Lock() - defer devices.Unlock() - - ids := make([]string, len(devices.Devices)) - i := 0 - for k := range devices.Devices { - ids[i] = k - i++ - } - return ids -} - -func (devices *DeviceSet) deviceStatus(devName string) (sizeInSectors, mappedSectors, highestMappedSector uint64, err error) { - var params string - _, sizeInSectors, _, params, err = devicemapper.GetStatus(devName) - if err != nil { - return - } - if _, err = fmt.Sscanf(params, "%d %d", &mappedSectors, &highestMappedSector); err == nil { - return - } - return -} - -// GetDeviceStatus provides size, mapped sectors -func (devices *DeviceSet) GetDeviceStatus(hash string) (*DevStatus, error) { - info, err := devices.lookupDeviceWithLock(hash) - if err != nil { - return nil, err - } - - info.lock.Lock() - defer info.lock.Unlock() - - devices.Lock() - defer devices.Unlock() - - status := &DevStatus{ - DeviceID: info.DeviceID, - Size: info.Size, - TransactionID: info.TransactionID, - } - - if err := devices.activateDeviceIfNeeded(info, false); err != nil { - return nil, fmt.Errorf("devmapper: Error activating devmapper device for '%s': %s", hash, err) - } - - sizeInSectors, mappedSectors, highestMappedSector, err := devices.deviceStatus(info.DevName()) - - if err != nil { - return nil, err - } - - status.SizeInSectors = sizeInSectors - status.MappedSectors = mappedSectors - status.HighestMappedSector = highestMappedSector - - return status, nil -} - -func (devices *DeviceSet) poolStatus() (totalSizeInSectors, transactionID, dataUsed, dataTotal, metadataUsed, metadataTotal uint64, err error) { - var params string - if _, totalSizeInSectors, _, params, err = devicemapper.GetStatus(devices.getPoolName()); err == nil { - _, err = fmt.Sscanf(params, "%d %d/%d %d/%d", &transactionID, &metadataUsed, &metadataTotal, &dataUsed, &dataTotal) - } - return -} - -// DataDevicePath returns the path to the data storage for this deviceset, -// regardless of loopback or block device -func (devices *DeviceSet) DataDevicePath() string { - return devices.dataDevice -} - -// MetadataDevicePath returns the path to the metadata storage for this deviceset, -// regardless of loopback or block device -func (devices *DeviceSet) MetadataDevicePath() string { - return devices.metadataDevice -} - -func (devices *DeviceSet) getUnderlyingAvailableSpace(loopFile string) (uint64, error) { - buf := new(syscall.Statfs_t) - if err := syscall.Statfs(loopFile, buf); err != nil { - logrus.Warnf("devmapper: Couldn't stat loopfile filesystem %v: %v", loopFile, err) - return 0, err - } - return buf.Bfree * uint64(buf.Bsize), nil -} - -func (devices *DeviceSet) isRealFile(loopFile string) (bool, error) { - if loopFile != "" { - fi, err := os.Stat(loopFile) - if err != nil { - logrus.Warnf("devmapper: Couldn't stat loopfile %v: %v", loopFile, err) - return false, err - } - return fi.Mode().IsRegular(), nil - } - return false, nil -} - -// Status returns the current status of this deviceset -func (devices *DeviceSet) Status() *Status { - devices.Lock() - defer devices.Unlock() - - status := &Status{} - - status.PoolName = devices.getPoolName() - status.DataFile = devices.DataDevicePath() - status.DataLoopback = devices.dataLoopFile - status.MetadataFile = devices.MetadataDevicePath() - status.MetadataLoopback = devices.metadataLoopFile - status.UdevSyncSupported = devicemapper.UdevSyncSupported() - status.DeferredRemoveEnabled = devices.deferredRemove - status.DeferredDeleteEnabled = devices.deferredDelete - status.DeferredDeletedDeviceCount = devices.nrDeletedDevices - status.BaseDeviceSize = devices.getBaseDeviceSize() - status.BaseDeviceFS = devices.getBaseDeviceFS() - - totalSizeInSectors, _, dataUsed, dataTotal, metadataUsed, metadataTotal, err := devices.poolStatus() - if err == nil { - // Convert from blocks to bytes - blockSizeInSectors := totalSizeInSectors / dataTotal - - status.Data.Used = dataUsed * blockSizeInSectors * 512 - status.Data.Total = dataTotal * blockSizeInSectors * 512 - status.Data.Available = status.Data.Total - status.Data.Used - - // metadata blocks are always 4k - status.Metadata.Used = metadataUsed * 4096 - status.Metadata.Total = metadataTotal * 4096 - status.Metadata.Available = status.Metadata.Total - status.Metadata.Used - - status.SectorSize = blockSizeInSectors * 512 - - if check, _ := devices.isRealFile(devices.dataLoopFile); check { - actualSpace, err := devices.getUnderlyingAvailableSpace(devices.dataLoopFile) - if err == nil && actualSpace < status.Data.Available { - status.Data.Available = actualSpace - } - } - - if check, _ := devices.isRealFile(devices.metadataLoopFile); check { - actualSpace, err := devices.getUnderlyingAvailableSpace(devices.metadataLoopFile) - if err == nil && actualSpace < status.Metadata.Available { - status.Metadata.Available = actualSpace - } - } - - minFreeData := (dataTotal * uint64(devices.minFreeSpacePercent)) / 100 - status.MinFreeSpace = minFreeData * blockSizeInSectors * 512 - } - - return status -} - -// Status returns the current status of this deviceset -func (devices *DeviceSet) exportDeviceMetadata(hash string) (*deviceMetadata, error) { - info, err := devices.lookupDeviceWithLock(hash) - if err != nil { - return nil, err - } - - info.lock.Lock() - defer info.lock.Unlock() - - metadata := &deviceMetadata{info.DeviceID, info.Size, info.Name()} - return metadata, nil -} - -// NewDeviceSet creates the device set based on the options provided. -func NewDeviceSet(root string, doInit bool, options []string, uidMaps, gidMaps []idtools.IDMap) (*DeviceSet, error) { - devicemapper.SetDevDir("/dev") - - devices := &DeviceSet{ - root: root, - metaData: metaData{Devices: make(map[string]*devInfo)}, - dataLoopbackSize: defaultDataLoopbackSize, - metaDataLoopbackSize: defaultMetaDataLoopbackSize, - baseFsSize: defaultBaseFsSize, - overrideUdevSyncCheck: defaultUdevSyncOverride, - doBlkDiscard: true, - thinpBlockSize: defaultThinpBlockSize, - deviceIDMap: make([]byte, deviceIDMapSz), - deletionWorkerTicker: time.NewTicker(time.Second * 30), - uidMaps: uidMaps, - gidMaps: gidMaps, - minFreeSpacePercent: defaultMinFreeSpacePercent, - } - - foundBlkDiscard := false - for _, option := range options { - key, val, err := parsers.ParseKeyValueOpt(option) - if err != nil { - return nil, err - } - key = strings.ToLower(key) - switch key { - case "dm.basesize": - size, err := units.RAMInBytes(val) - if err != nil { - return nil, err - } - userBaseSize = true - devices.baseFsSize = uint64(size) - case "dm.loopdatasize": - size, err := units.RAMInBytes(val) - if err != nil { - return nil, err - } - devices.dataLoopbackSize = size - case "dm.loopmetadatasize": - size, err := units.RAMInBytes(val) - if err != nil { - return nil, err - } - devices.metaDataLoopbackSize = size - case "dm.fs": - if val != "ext4" && val != "xfs" { - return nil, fmt.Errorf("devmapper: Unsupported filesystem %s\n", val) - } - devices.filesystem = val - case "dm.mkfsarg": - devices.mkfsArgs = append(devices.mkfsArgs, val) - case "dm.mountopt": - devices.mountOptions = joinMountOptions(devices.mountOptions, val) - case "dm.metadatadev": - devices.metadataDevice = val - case "dm.datadev": - devices.dataDevice = val - case "dm.thinpooldev": - devices.thinPoolDevice = strings.TrimPrefix(val, "/dev/mapper/") - case "dm.blkdiscard": - foundBlkDiscard = true - devices.doBlkDiscard, err = strconv.ParseBool(val) - if err != nil { - return nil, err - } - case "dm.blocksize": - size, err := units.RAMInBytes(val) - if err != nil { - return nil, err - } - // convert to 512b sectors - devices.thinpBlockSize = uint32(size) >> 9 - case "dm.override_udev_sync_check": - devices.overrideUdevSyncCheck, err = strconv.ParseBool(val) - if err != nil { - return nil, err - } - - case "dm.use_deferred_removal": - enableDeferredRemoval, err = strconv.ParseBool(val) - if err != nil { - return nil, err - } - - case "dm.use_deferred_deletion": - enableDeferredDeletion, err = strconv.ParseBool(val) - if err != nil { - return nil, err - } - - case "dm.min_free_space": - if !strings.HasSuffix(val, "%") { - return nil, fmt.Errorf("devmapper: Option dm.min_free_space requires %% suffix") - } - - valstring := strings.TrimSuffix(val, "%") - minFreeSpacePercent, err := strconv.ParseUint(valstring, 10, 32) - if err != nil { - return nil, err - } - - if minFreeSpacePercent >= 100 { - return nil, fmt.Errorf("devmapper: Invalid value %v for option dm.min_free_space", val) - } - - devices.minFreeSpacePercent = uint32(minFreeSpacePercent) - case "dm.xfs_nospace_max_retries": - _, err := strconv.ParseUint(val, 10, 64) - if err != nil { - return nil, err - } - devices.xfsNospaceRetries = val - default: - return nil, fmt.Errorf("devmapper: Unknown option %s\n", key) - } - } - - // By default, don't do blk discard hack on raw devices, its rarely useful and is expensive - if !foundBlkDiscard && (devices.dataDevice != "" || devices.thinPoolDevice != "") { - devices.doBlkDiscard = false - } - - if err := devices.initDevmapper(doInit); err != nil { - return nil, err - } - - return devices, nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/devmapper_doc.go b/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/devmapper_doc.go deleted file mode 100644 index 9ab3e4f..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/devmapper_doc.go +++ /dev/null @@ -1,106 +0,0 @@ -package devmapper - -// Definition of struct dm_task and sub structures (from lvm2) -// -// struct dm_ioctl { -// /* -// * The version number is made up of three parts: -// * major - no backward or forward compatibility, -// * minor - only backwards compatible, -// * patch - both backwards and forwards compatible. -// * -// * All clients of the ioctl interface should fill in the -// * version number of the interface that they were -// * compiled with. -// * -// * All recognized ioctl commands (ie. those that don't -// * return -ENOTTY) fill out this field, even if the -// * command failed. -// */ -// uint32_t version[3]; /* in/out */ -// uint32_t data_size; /* total size of data passed in -// * including this struct */ - -// uint32_t data_start; /* offset to start of data -// * relative to start of this struct */ - -// uint32_t target_count; /* in/out */ -// int32_t open_count; /* out */ -// uint32_t flags; /* in/out */ - -// /* -// * event_nr holds either the event number (input and output) or the -// * udev cookie value (input only). -// * The DM_DEV_WAIT ioctl takes an event number as input. -// * The DM_SUSPEND, DM_DEV_REMOVE and DM_DEV_RENAME ioctls -// * use the field as a cookie to return in the DM_COOKIE -// * variable with the uevents they issue. -// * For output, the ioctls return the event number, not the cookie. -// */ -// uint32_t event_nr; /* in/out */ -// uint32_t padding; - -// uint64_t dev; /* in/out */ - -// char name[DM_NAME_LEN]; /* device name */ -// char uuid[DM_UUID_LEN]; /* unique identifier for -// * the block device */ -// char data[7]; /* padding or data */ -// }; - -// struct target { -// uint64_t start; -// uint64_t length; -// char *type; -// char *params; - -// struct target *next; -// }; - -// typedef enum { -// DM_ADD_NODE_ON_RESUME, /* add /dev/mapper node with dmsetup resume */ -// DM_ADD_NODE_ON_CREATE /* add /dev/mapper node with dmsetup create */ -// } dm_add_node_t; - -// struct dm_task { -// int type; -// char *dev_name; -// char *mangled_dev_name; - -// struct target *head, *tail; - -// int read_only; -// uint32_t event_nr; -// int major; -// int minor; -// int allow_default_major_fallback; -// uid_t uid; -// gid_t gid; -// mode_t mode; -// uint32_t read_ahead; -// uint32_t read_ahead_flags; -// union { -// struct dm_ioctl *v4; -// } dmi; -// char *newname; -// char *message; -// char *geometry; -// uint64_t sector; -// int no_flush; -// int no_open_count; -// int skip_lockfs; -// int query_inactive_table; -// int suppress_identical_reload; -// dm_add_node_t add_node; -// uint64_t existing_table_size; -// int cookie_set; -// int new_uuid; -// int secure_data; -// int retry_remove; -// int enable_checks; -// int expected_errno; - -// char *uuid; -// char *mangled_uuid; -// }; -// diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/devmapper_test.go b/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/devmapper_test.go deleted file mode 100644 index 5c2abce..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/devmapper_test.go +++ /dev/null @@ -1,110 +0,0 @@ -// +build linux - -package devmapper - -import ( - "fmt" - "testing" - "time" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/daemon/graphdriver/graphtest" -) - -func init() { - // Reduce the size the the base fs and loopback for the tests - defaultDataLoopbackSize = 300 * 1024 * 1024 - defaultMetaDataLoopbackSize = 200 * 1024 * 1024 - defaultBaseFsSize = 300 * 1024 * 1024 - defaultUdevSyncOverride = true - if err := graphtest.InitLoopbacks(); err != nil { - panic(err) - } -} - -// This avoids creating a new driver for each test if all tests are run -// Make sure to put new tests between TestDevmapperSetup and TestDevmapperTeardown -func TestDevmapperSetup(t *testing.T) { - graphtest.GetDriver(t, "devicemapper") -} - -func TestDevmapperCreateEmpty(t *testing.T) { - graphtest.DriverTestCreateEmpty(t, "devicemapper") -} - -func TestDevmapperCreateBase(t *testing.T) { - graphtest.DriverTestCreateBase(t, "devicemapper") -} - -func TestDevmapperCreateSnap(t *testing.T) { - graphtest.DriverTestCreateSnap(t, "devicemapper") -} - -func TestDevmapperTeardown(t *testing.T) { - graphtest.PutDriver(t) -} - -func TestDevmapperReduceLoopBackSize(t *testing.T) { - tenMB := int64(10 * 1024 * 1024) - testChangeLoopBackSize(t, -tenMB, defaultDataLoopbackSize, defaultMetaDataLoopbackSize) -} - -func TestDevmapperIncreaseLoopBackSize(t *testing.T) { - tenMB := int64(10 * 1024 * 1024) - testChangeLoopBackSize(t, tenMB, defaultDataLoopbackSize+tenMB, defaultMetaDataLoopbackSize+tenMB) -} - -func testChangeLoopBackSize(t *testing.T, delta, expectDataSize, expectMetaDataSize int64) { - driver := graphtest.GetDriver(t, "devicemapper").(*graphtest.Driver).Driver.(*graphdriver.NaiveDiffDriver).ProtoDriver.(*Driver) - defer graphtest.PutDriver(t) - // make sure data or metadata loopback size are the default size - if s := driver.DeviceSet.Status(); s.Data.Total != uint64(defaultDataLoopbackSize) || s.Metadata.Total != uint64(defaultMetaDataLoopbackSize) { - t.Fatalf("data or metadata loop back size is incorrect") - } - if err := driver.Cleanup(); err != nil { - t.Fatal(err) - } - //Reload - d, err := Init(driver.home, []string{ - fmt.Sprintf("dm.loopdatasize=%d", defaultDataLoopbackSize+delta), - fmt.Sprintf("dm.loopmetadatasize=%d", defaultMetaDataLoopbackSize+delta), - }, nil, nil) - if err != nil { - t.Fatalf("error creating devicemapper driver: %v", err) - } - driver = d.(*graphdriver.NaiveDiffDriver).ProtoDriver.(*Driver) - if s := driver.DeviceSet.Status(); s.Data.Total != uint64(expectDataSize) || s.Metadata.Total != uint64(expectMetaDataSize) { - t.Fatalf("data or metadata loop back size is incorrect") - } - if err := driver.Cleanup(); err != nil { - t.Fatal(err) - } -} - -// Make sure devices.Lock() has been release upon return from cleanupDeletedDevices() function -func TestDevmapperLockReleasedDeviceDeletion(t *testing.T) { - driver := graphtest.GetDriver(t, "devicemapper").(*graphtest.Driver).Driver.(*graphdriver.NaiveDiffDriver).ProtoDriver.(*Driver) - defer graphtest.PutDriver(t) - - // Call cleanupDeletedDevices() and after the call take and release - // DeviceSet Lock. If lock has not been released, this will hang. - driver.DeviceSet.cleanupDeletedDevices() - - doneChan := make(chan bool) - - go func() { - driver.DeviceSet.Lock() - defer driver.DeviceSet.Unlock() - doneChan <- true - }() - - select { - case <-time.After(time.Second * 5): - // Timer expired. That means lock was not released upon - // function return and we are deadlocked. Release lock - // here so that cleanup could succeed and fail the test. - driver.DeviceSet.Unlock() - t.Fatalf("Could not acquire devices lock after call to cleanupDeletedDevices()") - case <-doneChan: - } -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/driver.go b/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/driver.go deleted file mode 100644 index 7cf422c..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/driver.go +++ /dev/null @@ -1,231 +0,0 @@ -// +build linux - -package devmapper - -import ( - "fmt" - "io/ioutil" - "os" - "path" - "strconv" - - "github.com/Sirupsen/logrus" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/devicemapper" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/mount" - "github.com/docker/go-units" -) - -func init() { - graphdriver.Register("devicemapper", Init) -} - -// Driver contains the device set mounted and the home directory -type Driver struct { - *DeviceSet - home string - uidMaps []idtools.IDMap - gidMaps []idtools.IDMap - ctr *graphdriver.RefCounter -} - -// Init creates a driver with the given home and the set of options. -func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - deviceSet, err := NewDeviceSet(home, true, options, uidMaps, gidMaps) - if err != nil { - return nil, err - } - - if err := mount.MakePrivate(home); err != nil { - return nil, err - } - - d := &Driver{ - DeviceSet: deviceSet, - home: home, - uidMaps: uidMaps, - gidMaps: gidMaps, - ctr: graphdriver.NewRefCounter(graphdriver.NewDefaultChecker()), - } - - return graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps), nil -} - -func (d *Driver) String() string { - return "devicemapper" -} - -// Status returns the status about the driver in a printable format. -// Information returned contains Pool Name, Data File, Metadata file, disk usage by -// the data and metadata, etc. -func (d *Driver) Status() [][2]string { - s := d.DeviceSet.Status() - - status := [][2]string{ - {"Pool Name", s.PoolName}, - {"Pool Blocksize", fmt.Sprintf("%s", units.HumanSize(float64(s.SectorSize)))}, - {"Base Device Size", fmt.Sprintf("%s", units.HumanSize(float64(s.BaseDeviceSize)))}, - {"Backing Filesystem", s.BaseDeviceFS}, - {"Data file", s.DataFile}, - {"Metadata file", s.MetadataFile}, - {"Data Space Used", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Used)))}, - {"Data Space Total", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Total)))}, - {"Data Space Available", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Available)))}, - {"Metadata Space Used", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Used)))}, - {"Metadata Space Total", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Total)))}, - {"Metadata Space Available", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Available)))}, - {"Thin Pool Minimum Free Space", fmt.Sprintf("%s", units.HumanSize(float64(s.MinFreeSpace)))}, - {"Udev Sync Supported", fmt.Sprintf("%v", s.UdevSyncSupported)}, - {"Deferred Removal Enabled", fmt.Sprintf("%v", s.DeferredRemoveEnabled)}, - {"Deferred Deletion Enabled", fmt.Sprintf("%v", s.DeferredDeleteEnabled)}, - {"Deferred Deleted Device Count", fmt.Sprintf("%v", s.DeferredDeletedDeviceCount)}, - } - if len(s.DataLoopback) > 0 { - status = append(status, [2]string{"Data loop file", s.DataLoopback}) - } - if len(s.MetadataLoopback) > 0 { - status = append(status, [2]string{"Metadata loop file", s.MetadataLoopback}) - } - if vStr, err := devicemapper.GetLibraryVersion(); err == nil { - status = append(status, [2]string{"Library Version", vStr}) - } - return status -} - -// GetMetadata returns a map of information about the device. -func (d *Driver) GetMetadata(id string) (map[string]string, error) { - m, err := d.DeviceSet.exportDeviceMetadata(id) - - if err != nil { - return nil, err - } - - metadata := make(map[string]string) - metadata["DeviceId"] = strconv.Itoa(m.deviceID) - metadata["DeviceSize"] = strconv.FormatUint(m.deviceSize, 10) - metadata["DeviceName"] = m.deviceName - return metadata, nil -} - -// Cleanup unmounts a device. -func (d *Driver) Cleanup() error { - err := d.DeviceSet.Shutdown(d.home) - - if err2 := mount.Unmount(d.home); err == nil { - err = err2 - } - - return err -} - -// CreateReadWrite creates a layer that is writable for use as a container -// file system. -func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error { - return d.Create(id, parent, opts) -} - -// Create adds a device with a given id and the parent. -func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error { - var storageOpt map[string]string - if opts != nil { - storageOpt = opts.StorageOpt - } - - if err := d.DeviceSet.AddDevice(id, parent, storageOpt); err != nil { - return err - } - - return nil -} - -// Remove removes a device with a given id, unmounts the filesystem. -func (d *Driver) Remove(id string) error { - if !d.DeviceSet.HasDevice(id) { - // Consider removing a non-existing device a no-op - // This is useful to be able to progress on container removal - // if the underlying device has gone away due to earlier errors - return nil - } - - // This assumes the device has been properly Get/Put:ed and thus is unmounted - if err := d.DeviceSet.DeleteDevice(id, false); err != nil { - return err - } - - mp := path.Join(d.home, "mnt", id) - if err := os.RemoveAll(mp); err != nil && !os.IsNotExist(err) { - return err - } - - return nil -} - -// Get mounts a device with given id into the root filesystem -func (d *Driver) Get(id, mountLabel string) (string, error) { - mp := path.Join(d.home, "mnt", id) - rootFs := path.Join(mp, "rootfs") - if count := d.ctr.Increment(mp); count > 1 { - return rootFs, nil - } - - uid, gid, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps) - if err != nil { - d.ctr.Decrement(mp) - return "", err - } - - // Create the target directories if they don't exist - if err := idtools.MkdirAllAs(path.Join(d.home, "mnt"), 0755, uid, gid); err != nil && !os.IsExist(err) { - d.ctr.Decrement(mp) - return "", err - } - if err := idtools.MkdirAs(mp, 0755, uid, gid); err != nil && !os.IsExist(err) { - d.ctr.Decrement(mp) - return "", err - } - - // Mount the device - if err := d.DeviceSet.MountDevice(id, mp, mountLabel); err != nil { - d.ctr.Decrement(mp) - return "", err - } - - if err := idtools.MkdirAllAs(rootFs, 0755, uid, gid); err != nil && !os.IsExist(err) { - d.ctr.Decrement(mp) - d.DeviceSet.UnmountDevice(id, mp) - return "", err - } - - idFile := path.Join(mp, "id") - if _, err := os.Stat(idFile); err != nil && os.IsNotExist(err) { - // Create an "id" file with the container/image id in it to help reconstruct this in case - // of later problems - if err := ioutil.WriteFile(idFile, []byte(id), 0600); err != nil { - d.ctr.Decrement(mp) - d.DeviceSet.UnmountDevice(id, mp) - return "", err - } - } - - return rootFs, nil -} - -// Put unmounts a device and removes it. -func (d *Driver) Put(id string) error { - mp := path.Join(d.home, "mnt", id) - if count := d.ctr.Decrement(mp); count > 0 { - return nil - } - err := d.DeviceSet.UnmountDevice(id, mp) - if err != nil { - logrus.Errorf("devmapper: Error unmounting device %s: %s", id, err) - } - return err -} - -// Exists checks to see if the device exists. -func (d *Driver) Exists(id string) bool { - return d.DeviceSet.HasDevice(id) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/mount.go b/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/mount.go deleted file mode 100644 index cca1fe1..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/devmapper/mount.go +++ /dev/null @@ -1,89 +0,0 @@ -// +build linux - -package devmapper - -import ( - "bytes" - "fmt" - "os" - "path/filepath" - "syscall" -) - -// FIXME: this is copy-pasted from the aufs driver. -// It should be moved into the core. - -// Mounted returns true if a mount point exists. -func Mounted(mountpoint string) (bool, error) { - mntpoint, err := os.Stat(mountpoint) - if err != nil { - if os.IsNotExist(err) { - return false, nil - } - return false, err - } - parent, err := os.Stat(filepath.Join(mountpoint, "..")) - if err != nil { - return false, err - } - mntpointSt := mntpoint.Sys().(*syscall.Stat_t) - parentSt := parent.Sys().(*syscall.Stat_t) - return mntpointSt.Dev != parentSt.Dev, nil -} - -type probeData struct { - fsName string - magic string - offset uint64 -} - -// ProbeFsType returns the filesystem name for the given device id. -func ProbeFsType(device string) (string, error) { - probes := []probeData{ - {"btrfs", "_BHRfS_M", 0x10040}, - {"ext4", "\123\357", 0x438}, - {"xfs", "XFSB", 0}, - } - - maxLen := uint64(0) - for _, p := range probes { - l := p.offset + uint64(len(p.magic)) - if l > maxLen { - maxLen = l - } - } - - file, err := os.Open(device) - if err != nil { - return "", err - } - defer file.Close() - - buffer := make([]byte, maxLen) - l, err := file.Read(buffer) - if err != nil { - return "", err - } - - if uint64(l) != maxLen { - return "", fmt.Errorf("devmapper: unable to detect filesystem type of %s, short read", device) - } - - for _, p := range probes { - if bytes.Equal([]byte(p.magic), buffer[p.offset:p.offset+uint64(len(p.magic))]) { - return p.fsName, nil - } - } - - return "", fmt.Errorf("devmapper: Unknown filesystem type on %s", device) -} - -func joinMountOptions(a, b string) string { - if a == "" { - return b - } - if b == "" { - return a - } - return a + "," + b -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/driver.go b/vendor/github.com/docker/docker/daemon/graphdriver/driver.go deleted file mode 100644 index f0bce56..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/driver.go +++ /dev/null @@ -1,270 +0,0 @@ -package graphdriver - -import ( - "errors" - "fmt" - "io" - "os" - "path/filepath" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/vbatts/tar-split/tar/storage" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/plugingetter" -) - -// FsMagic unsigned id of the filesystem in use. -type FsMagic uint32 - -const ( - // FsMagicUnsupported is a predefined constant value other than a valid filesystem id. - FsMagicUnsupported = FsMagic(0x00000000) -) - -var ( - // All registered drivers - drivers map[string]InitFunc - - // ErrNotSupported returned when driver is not supported. - ErrNotSupported = errors.New("driver not supported") - // ErrPrerequisites retuned when driver does not meet prerequisites. - ErrPrerequisites = errors.New("prerequisites for driver not satisfied (wrong filesystem?)") - // ErrIncompatibleFS returned when file system is not supported. - ErrIncompatibleFS = fmt.Errorf("backing file system is unsupported for this graph driver") -) - -//CreateOpts contains optional arguments for Create() and CreateReadWrite() -// methods. -type CreateOpts struct { - MountLabel string - StorageOpt map[string]string -} - -// InitFunc initializes the storage driver. -type InitFunc func(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (Driver, error) - -// ProtoDriver defines the basic capabilities of a driver. -// This interface exists solely to be a minimum set of methods -// for client code which choose not to implement the entire Driver -// interface and use the NaiveDiffDriver wrapper constructor. -// -// Use of ProtoDriver directly by client code is not recommended. -type ProtoDriver interface { - // String returns a string representation of this driver. - String() string - // CreateReadWrite creates a new, empty filesystem layer that is ready - // to be used as the storage for a container. Additional options can - // be passed in opts. parent may be "" and opts may be nil. - CreateReadWrite(id, parent string, opts *CreateOpts) error - // Create creates a new, empty, filesystem layer with the - // specified id and parent and options passed in opts. Parent - // may be "" and opts may be nil. - Create(id, parent string, opts *CreateOpts) error - // Remove attempts to remove the filesystem layer with this id. - Remove(id string) error - // Get returns the mountpoint for the layered filesystem referred - // to by this id. You can optionally specify a mountLabel or "". - // Returns the absolute path to the mounted layered filesystem. - Get(id, mountLabel string) (dir string, err error) - // Put releases the system resources for the specified id, - // e.g, unmounting layered filesystem. - Put(id string) error - // Exists returns whether a filesystem layer with the specified - // ID exists on this driver. - Exists(id string) bool - // Status returns a set of key-value pairs which give low - // level diagnostic status about this driver. - Status() [][2]string - // Returns a set of key-value pairs which give low level information - // about the image/container driver is managing. - GetMetadata(id string) (map[string]string, error) - // Cleanup performs necessary tasks to release resources - // held by the driver, e.g., unmounting all layered filesystems - // known to this driver. - Cleanup() error -} - -// DiffDriver is the interface to use to implement graph diffs -type DiffDriver interface { - // Diff produces an archive of the changes between the specified - // layer and its parent layer which may be "". - Diff(id, parent string) (io.ReadCloser, error) - // Changes produces a list of changes between the specified layer - // and its parent layer. If parent is "", then all changes will be ADD changes. - Changes(id, parent string) ([]archive.Change, error) - // ApplyDiff extracts the changeset from the given diff into the - // layer with the specified id and parent, returning the size of the - // new layer in bytes. - // The archive.Reader must be an uncompressed stream. - ApplyDiff(id, parent string, diff io.Reader) (size int64, err error) - // DiffSize calculates the changes between the specified id - // and its parent and returns the size in bytes of the changes - // relative to its base filesystem directory. - DiffSize(id, parent string) (size int64, err error) -} - -// Driver is the interface for layered/snapshot file system drivers. -type Driver interface { - ProtoDriver - DiffDriver -} - -// DiffGetterDriver is the interface for layered file system drivers that -// provide a specialized function for getting file contents for tar-split. -type DiffGetterDriver interface { - Driver - // DiffGetter returns an interface to efficiently retrieve the contents - // of files in a layer. - DiffGetter(id string) (FileGetCloser, error) -} - -// FileGetCloser extends the storage.FileGetter interface with a Close method -// for cleaning up. -type FileGetCloser interface { - storage.FileGetter - // Close cleans up any resources associated with the FileGetCloser. - Close() error -} - -// Checker makes checks on specified filesystems. -type Checker interface { - // IsMounted returns true if the provided path is mounted for the specific checker - IsMounted(path string) bool -} - -func init() { - drivers = make(map[string]InitFunc) -} - -// Register registers an InitFunc for the driver. -func Register(name string, initFunc InitFunc) error { - if _, exists := drivers[name]; exists { - return fmt.Errorf("Name already registered %s", name) - } - drivers[name] = initFunc - - return nil -} - -// GetDriver initializes and returns the registered driver -func GetDriver(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) { - if initFunc, exists := drivers[name]; exists { - return initFunc(filepath.Join(config.Root, name), config.DriverOptions, config.UIDMaps, config.GIDMaps) - } - - pluginDriver, err := lookupPlugin(name, pg, config) - if err == nil { - return pluginDriver, nil - } - logrus.WithError(err).WithField("driver", name).WithField("home-dir", config.Root).Error("Failed to GetDriver graph") - return nil, ErrNotSupported -} - -// getBuiltinDriver initializes and returns the registered driver, but does not try to load from plugins -func getBuiltinDriver(name, home string, options []string, uidMaps, gidMaps []idtools.IDMap) (Driver, error) { - if initFunc, exists := drivers[name]; exists { - return initFunc(filepath.Join(home, name), options, uidMaps, gidMaps) - } - logrus.Errorf("Failed to built-in GetDriver graph %s %s", name, home) - return nil, ErrNotSupported -} - -// Options is used to initialize a graphdriver -type Options struct { - Root string - DriverOptions []string - UIDMaps []idtools.IDMap - GIDMaps []idtools.IDMap - ExperimentalEnabled bool -} - -// New creates the driver and initializes it at the specified root. -func New(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) { - if name != "" { - logrus.Debugf("[graphdriver] trying provided driver: %s", name) // so the logs show specified driver - return GetDriver(name, pg, config) - } - - // Guess for prior driver - driversMap := scanPriorDrivers(config.Root) - for _, name := range priority { - if name == "vfs" { - // don't use vfs even if there is state present. - continue - } - if _, prior := driversMap[name]; prior { - // of the state found from prior drivers, check in order of our priority - // which we would prefer - driver, err := getBuiltinDriver(name, config.Root, config.DriverOptions, config.UIDMaps, config.GIDMaps) - if err != nil { - // unlike below, we will return error here, because there is prior - // state, and now it is no longer supported/prereq/compatible, so - // something changed and needs attention. Otherwise the daemon's - // images would just "disappear". - logrus.Errorf("[graphdriver] prior storage driver %s failed: %s", name, err) - return nil, err - } - - // abort starting when there are other prior configured drivers - // to ensure the user explicitly selects the driver to load - if len(driversMap)-1 > 0 { - var driversSlice []string - for name := range driversMap { - driversSlice = append(driversSlice, name) - } - - return nil, fmt.Errorf("%s contains several valid graphdrivers: %s; Please cleanup or explicitly choose storage driver (-s )", config.Root, strings.Join(driversSlice, ", ")) - } - - logrus.Infof("[graphdriver] using prior storage driver: %s", name) - return driver, nil - } - } - - // Check for priority drivers first - for _, name := range priority { - driver, err := getBuiltinDriver(name, config.Root, config.DriverOptions, config.UIDMaps, config.GIDMaps) - if err != nil { - if isDriverNotSupported(err) { - continue - } - return nil, err - } - return driver, nil - } - - // Check all registered drivers if no priority driver is found - for name, initFunc := range drivers { - driver, err := initFunc(filepath.Join(config.Root, name), config.DriverOptions, config.UIDMaps, config.GIDMaps) - if err != nil { - if isDriverNotSupported(err) { - continue - } - return nil, err - } - return driver, nil - } - return nil, fmt.Errorf("No supported storage backend found") -} - -// isDriverNotSupported returns true if the error initializing -// the graph driver is a non-supported error. -func isDriverNotSupported(err error) bool { - return err == ErrNotSupported || err == ErrPrerequisites || err == ErrIncompatibleFS -} - -// scanPriorDrivers returns an un-ordered scan of directories of prior storage drivers -func scanPriorDrivers(root string) map[string]bool { - driversMap := make(map[string]bool) - - for driver := range drivers { - p := filepath.Join(root, driver) - if _, err := os.Stat(p); err == nil && driver != "vfs" { - driversMap[driver] = true - } - } - return driversMap -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/driver_freebsd.go b/vendor/github.com/docker/docker/daemon/graphdriver/driver_freebsd.go deleted file mode 100644 index 2891a84..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/driver_freebsd.go +++ /dev/null @@ -1,19 +0,0 @@ -package graphdriver - -import "syscall" - -var ( - // Slice of drivers that should be used in an order - priority = []string{ - "zfs", - } -) - -// Mounted checks if the given path is mounted as the fs type -func Mounted(fsType FsMagic, mountPath string) (bool, error) { - var buf syscall.Statfs_t - if err := syscall.Statfs(mountPath, &buf); err != nil { - return false, err - } - return FsMagic(buf.Type) == fsType, nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/driver_linux.go b/vendor/github.com/docker/docker/daemon/graphdriver/driver_linux.go deleted file mode 100644 index 5c8d0e2..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/driver_linux.go +++ /dev/null @@ -1,135 +0,0 @@ -// +build linux - -package graphdriver - -import ( - "path/filepath" - "syscall" - - "github.com/docker/docker/pkg/mount" -) - -const ( - // FsMagicAufs filesystem id for Aufs - FsMagicAufs = FsMagic(0x61756673) - // FsMagicBtrfs filesystem id for Btrfs - FsMagicBtrfs = FsMagic(0x9123683E) - // FsMagicCramfs filesystem id for Cramfs - FsMagicCramfs = FsMagic(0x28cd3d45) - // FsMagicEcryptfs filesystem id for eCryptfs - FsMagicEcryptfs = FsMagic(0xf15f) - // FsMagicExtfs filesystem id for Extfs - FsMagicExtfs = FsMagic(0x0000EF53) - // FsMagicF2fs filesystem id for F2fs - FsMagicF2fs = FsMagic(0xF2F52010) - // FsMagicGPFS filesystem id for GPFS - FsMagicGPFS = FsMagic(0x47504653) - // FsMagicJffs2Fs filesystem if for Jffs2Fs - FsMagicJffs2Fs = FsMagic(0x000072b6) - // FsMagicJfs filesystem id for Jfs - FsMagicJfs = FsMagic(0x3153464a) - // FsMagicNfsFs filesystem id for NfsFs - FsMagicNfsFs = FsMagic(0x00006969) - // FsMagicRAMFs filesystem id for RamFs - FsMagicRAMFs = FsMagic(0x858458f6) - // FsMagicReiserFs filesystem id for ReiserFs - FsMagicReiserFs = FsMagic(0x52654973) - // FsMagicSmbFs filesystem id for SmbFs - FsMagicSmbFs = FsMagic(0x0000517B) - // FsMagicSquashFs filesystem id for SquashFs - FsMagicSquashFs = FsMagic(0x73717368) - // FsMagicTmpFs filesystem id for TmpFs - FsMagicTmpFs = FsMagic(0x01021994) - // FsMagicVxFS filesystem id for VxFs - FsMagicVxFS = FsMagic(0xa501fcf5) - // FsMagicXfs filesystem id for Xfs - FsMagicXfs = FsMagic(0x58465342) - // FsMagicZfs filesystem id for Zfs - FsMagicZfs = FsMagic(0x2fc12fc1) - // FsMagicOverlay filesystem id for overlay - FsMagicOverlay = FsMagic(0x794C7630) -) - -var ( - // Slice of drivers that should be used in an order - priority = []string{ - "aufs", - "btrfs", - "zfs", - "overlay2", - "overlay", - "devicemapper", - "vfs", - } - - // FsNames maps filesystem id to name of the filesystem. - FsNames = map[FsMagic]string{ - FsMagicAufs: "aufs", - FsMagicBtrfs: "btrfs", - FsMagicCramfs: "cramfs", - FsMagicExtfs: "extfs", - FsMagicF2fs: "f2fs", - FsMagicGPFS: "gpfs", - FsMagicJffs2Fs: "jffs2", - FsMagicJfs: "jfs", - FsMagicNfsFs: "nfs", - FsMagicOverlay: "overlayfs", - FsMagicRAMFs: "ramfs", - FsMagicReiserFs: "reiserfs", - FsMagicSmbFs: "smb", - FsMagicSquashFs: "squashfs", - FsMagicTmpFs: "tmpfs", - FsMagicUnsupported: "unsupported", - FsMagicVxFS: "vxfs", - FsMagicXfs: "xfs", - FsMagicZfs: "zfs", - } -) - -// GetFSMagic returns the filesystem id given the path. -func GetFSMagic(rootpath string) (FsMagic, error) { - var buf syscall.Statfs_t - if err := syscall.Statfs(filepath.Dir(rootpath), &buf); err != nil { - return 0, err - } - return FsMagic(buf.Type), nil -} - -// NewFsChecker returns a checker configured for the provied FsMagic -func NewFsChecker(t FsMagic) Checker { - return &fsChecker{ - t: t, - } -} - -type fsChecker struct { - t FsMagic -} - -func (c *fsChecker) IsMounted(path string) bool { - m, _ := Mounted(c.t, path) - return m -} - -// NewDefaultChecker returns a check that parses /proc/mountinfo to check -// if the specified path is mounted. -func NewDefaultChecker() Checker { - return &defaultChecker{} -} - -type defaultChecker struct { -} - -func (c *defaultChecker) IsMounted(path string) bool { - m, _ := mount.Mounted(path) - return m -} - -// Mounted checks if the given path is mounted as the fs type -func Mounted(fsType FsMagic, mountPath string) (bool, error) { - var buf syscall.Statfs_t - if err := syscall.Statfs(mountPath, &buf); err != nil { - return false, err - } - return FsMagic(buf.Type) == fsType, nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/driver_solaris.go b/vendor/github.com/docker/docker/daemon/graphdriver/driver_solaris.go deleted file mode 100644 index 7daf01c..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/driver_solaris.go +++ /dev/null @@ -1,97 +0,0 @@ -// +build solaris,cgo - -package graphdriver - -/* -#include -#include - -static inline struct statvfs *getstatfs(char *s) { - struct statvfs *buf; - int err; - buf = (struct statvfs *)malloc(sizeof(struct statvfs)); - err = statvfs(s, buf); - return buf; -} -*/ -import "C" -import ( - "path/filepath" - "unsafe" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/mount" -) - -const ( - // FsMagicZfs filesystem id for Zfs - FsMagicZfs = FsMagic(0x2fc12fc1) -) - -var ( - // Slice of drivers that should be used in an order - priority = []string{ - "zfs", - } - - // FsNames maps filesystem id to name of the filesystem. - FsNames = map[FsMagic]string{ - FsMagicZfs: "zfs", - } -) - -// GetFSMagic returns the filesystem id given the path. -func GetFSMagic(rootpath string) (FsMagic, error) { - return 0, nil -} - -type fsChecker struct { - t FsMagic -} - -func (c *fsChecker) IsMounted(path string) bool { - m, _ := Mounted(c.t, path) - return m -} - -// NewFsChecker returns a checker configured for the provied FsMagic -func NewFsChecker(t FsMagic) Checker { - return &fsChecker{ - t: t, - } -} - -// NewDefaultChecker returns a check that parses /proc/mountinfo to check -// if the specified path is mounted. -// No-op on Solaris. -func NewDefaultChecker() Checker { - return &defaultChecker{} -} - -type defaultChecker struct { -} - -func (c *defaultChecker) IsMounted(path string) bool { - m, _ := mount.Mounted(path) - return m -} - -// Mounted checks if the given path is mounted as the fs type -//Solaris supports only ZFS for now -func Mounted(fsType FsMagic, mountPath string) (bool, error) { - - cs := C.CString(filepath.Dir(mountPath)) - buf := C.getstatfs(cs) - - // on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ] - if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) || - (buf.f_basetype[3] != 0) { - logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath) - C.free(unsafe.Pointer(buf)) - return false, ErrPrerequisites - } - - C.free(unsafe.Pointer(buf)) - C.free(unsafe.Pointer(cs)) - return true, nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/driver_unsupported.go b/vendor/github.com/docker/docker/daemon/graphdriver/driver_unsupported.go deleted file mode 100644 index 4a87560..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/driver_unsupported.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build !linux,!windows,!freebsd,!solaris - -package graphdriver - -var ( - // Slice of drivers that should be used in an order - priority = []string{ - "unsupported", - } -) - -// GetFSMagic returns the filesystem id given the path. -func GetFSMagic(rootpath string) (FsMagic, error) { - return FsMagicUnsupported, nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/driver_windows.go b/vendor/github.com/docker/docker/daemon/graphdriver/driver_windows.go deleted file mode 100644 index ffd30c2..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/driver_windows.go +++ /dev/null @@ -1,14 +0,0 @@ -package graphdriver - -var ( - // Slice of drivers that should be used in order - priority = []string{ - "windowsfilter", - } -) - -// GetFSMagic returns the filesystem id given the path. -func GetFSMagic(rootpath string) (FsMagic, error) { - // Note it is OK to return FsMagicUnsupported on Windows. - return FsMagicUnsupported, nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/fsdiff.go b/vendor/github.com/docker/docker/daemon/graphdriver/fsdiff.go deleted file mode 100644 index 20826cd..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/fsdiff.go +++ /dev/null @@ -1,169 +0,0 @@ -package graphdriver - -import ( - "io" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/chrootarchive" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/ioutils" -) - -var ( - // ApplyUncompressedLayer defines the unpack method used by the graph - // driver. - ApplyUncompressedLayer = chrootarchive.ApplyUncompressedLayer -) - -// NaiveDiffDriver takes a ProtoDriver and adds the -// capability of the Diffing methods which it may or may not -// support on its own. See the comment on the exported -// NewNaiveDiffDriver function below. -// Notably, the AUFS driver doesn't need to be wrapped like this. -type NaiveDiffDriver struct { - ProtoDriver - uidMaps []idtools.IDMap - gidMaps []idtools.IDMap -} - -// NewNaiveDiffDriver returns a fully functional driver that wraps the -// given ProtoDriver and adds the capability of the following methods which -// it may or may not support on its own: -// Diff(id, parent string) (archive.Archive, error) -// Changes(id, parent string) ([]archive.Change, error) -// ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error) -// DiffSize(id, parent string) (size int64, err error) -func NewNaiveDiffDriver(driver ProtoDriver, uidMaps, gidMaps []idtools.IDMap) Driver { - return &NaiveDiffDriver{ProtoDriver: driver, - uidMaps: uidMaps, - gidMaps: gidMaps} -} - -// Diff produces an archive of the changes between the specified -// layer and its parent layer which may be "". -func (gdw *NaiveDiffDriver) Diff(id, parent string) (arch io.ReadCloser, err error) { - startTime := time.Now() - driver := gdw.ProtoDriver - - layerFs, err := driver.Get(id, "") - if err != nil { - return nil, err - } - - defer func() { - if err != nil { - driver.Put(id) - } - }() - - if parent == "" { - archive, err := archive.Tar(layerFs, archive.Uncompressed) - if err != nil { - return nil, err - } - return ioutils.NewReadCloserWrapper(archive, func() error { - err := archive.Close() - driver.Put(id) - return err - }), nil - } - - parentFs, err := driver.Get(parent, "") - if err != nil { - return nil, err - } - defer driver.Put(parent) - - changes, err := archive.ChangesDirs(layerFs, parentFs) - if err != nil { - return nil, err - } - - archive, err := archive.ExportChanges(layerFs, changes, gdw.uidMaps, gdw.gidMaps) - if err != nil { - return nil, err - } - - return ioutils.NewReadCloserWrapper(archive, func() error { - err := archive.Close() - driver.Put(id) - - // NaiveDiffDriver compares file metadata with parent layers. Parent layers - // are extracted from tar's with full second precision on modified time. - // We need this hack here to make sure calls within same second receive - // correct result. - time.Sleep(startTime.Truncate(time.Second).Add(time.Second).Sub(time.Now())) - return err - }), nil -} - -// Changes produces a list of changes between the specified layer -// and its parent layer. If parent is "", then all changes will be ADD changes. -func (gdw *NaiveDiffDriver) Changes(id, parent string) ([]archive.Change, error) { - driver := gdw.ProtoDriver - - layerFs, err := driver.Get(id, "") - if err != nil { - return nil, err - } - defer driver.Put(id) - - parentFs := "" - - if parent != "" { - parentFs, err = driver.Get(parent, "") - if err != nil { - return nil, err - } - defer driver.Put(parent) - } - - return archive.ChangesDirs(layerFs, parentFs) -} - -// ApplyDiff extracts the changeset from the given diff into the -// layer with the specified id and parent, returning the size of the -// new layer in bytes. -func (gdw *NaiveDiffDriver) ApplyDiff(id, parent string, diff io.Reader) (size int64, err error) { - driver := gdw.ProtoDriver - - // Mount the root filesystem so we can apply the diff/layer. - layerFs, err := driver.Get(id, "") - if err != nil { - return - } - defer driver.Put(id) - - options := &archive.TarOptions{UIDMaps: gdw.uidMaps, - GIDMaps: gdw.gidMaps} - start := time.Now().UTC() - logrus.Debug("Start untar layer") - if size, err = ApplyUncompressedLayer(layerFs, diff, options); err != nil { - return - } - logrus.Debugf("Untar time: %vs", time.Now().UTC().Sub(start).Seconds()) - - return -} - -// DiffSize calculates the changes between the specified layer -// and its parent and returns the size in bytes of the changes -// relative to its base filesystem directory. -func (gdw *NaiveDiffDriver) DiffSize(id, parent string) (size int64, err error) { - driver := gdw.ProtoDriver - - changes, err := gdw.Changes(id, parent) - if err != nil { - return - } - - layerFs, err := driver.Get(id, "") - if err != nil { - return - } - defer driver.Put(id) - - return archive.ChangesSize(layerFs, changes), nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/graphbench_unix.go b/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/graphbench_unix.go deleted file mode 100644 index def822b..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/graphbench_unix.go +++ /dev/null @@ -1,259 +0,0 @@ -// +build linux freebsd - -package graphtest - -import ( - "bytes" - "io" - "io/ioutil" - "path/filepath" - "testing" - - "github.com/docker/docker/pkg/stringid" -) - -// DriverBenchExists benchmarks calls to exist -func DriverBenchExists(b *testing.B, drivername string, driveroptions ...string) { - driver := GetDriver(b, drivername, driveroptions...) - defer PutDriver(b) - - base := stringid.GenerateRandomID() - - if err := driver.Create(base, "", nil); err != nil { - b.Fatal(err) - } - - b.ResetTimer() - for i := 0; i < b.N; i++ { - if !driver.Exists(base) { - b.Fatal("Newly created image doesn't exist") - } - } -} - -// DriverBenchGetEmpty benchmarks calls to get on an empty layer -func DriverBenchGetEmpty(b *testing.B, drivername string, driveroptions ...string) { - driver := GetDriver(b, drivername, driveroptions...) - defer PutDriver(b) - - base := stringid.GenerateRandomID() - - if err := driver.Create(base, "", nil); err != nil { - b.Fatal(err) - } - - b.ResetTimer() - for i := 0; i < b.N; i++ { - _, err := driver.Get(base, "") - b.StopTimer() - if err != nil { - b.Fatalf("Error getting mount: %s", err) - } - if err := driver.Put(base); err != nil { - b.Fatalf("Error putting mount: %s", err) - } - b.StartTimer() - } -} - -// DriverBenchDiffBase benchmarks calls to diff on a root layer -func DriverBenchDiffBase(b *testing.B, drivername string, driveroptions ...string) { - driver := GetDriver(b, drivername, driveroptions...) - defer PutDriver(b) - - base := stringid.GenerateRandomID() - if err := driver.Create(base, "", nil); err != nil { - b.Fatal(err) - } - - if err := addFiles(driver, base, 3); err != nil { - b.Fatal(err) - } - - b.ResetTimer() - for i := 0; i < b.N; i++ { - arch, err := driver.Diff(base, "") - if err != nil { - b.Fatal(err) - } - _, err = io.Copy(ioutil.Discard, arch) - if err != nil { - b.Fatalf("Error copying archive: %s", err) - } - arch.Close() - } -} - -// DriverBenchDiffN benchmarks calls to diff on two layers with -// a provided number of files on the lower and upper layers. -func DriverBenchDiffN(b *testing.B, bottom, top int, drivername string, driveroptions ...string) { - driver := GetDriver(b, drivername, driveroptions...) - defer PutDriver(b) - base := stringid.GenerateRandomID() - upper := stringid.GenerateRandomID() - if err := driver.Create(base, "", nil); err != nil { - b.Fatal(err) - } - - if err := addManyFiles(driver, base, bottom, 3); err != nil { - b.Fatal(err) - } - - if err := driver.Create(upper, base, nil); err != nil { - b.Fatal(err) - } - - if err := addManyFiles(driver, upper, top, 6); err != nil { - b.Fatal(err) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - arch, err := driver.Diff(upper, "") - if err != nil { - b.Fatal(err) - } - _, err = io.Copy(ioutil.Discard, arch) - if err != nil { - b.Fatalf("Error copying archive: %s", err) - } - arch.Close() - } -} - -// DriverBenchDiffApplyN benchmarks calls to diff and apply together -func DriverBenchDiffApplyN(b *testing.B, fileCount int, drivername string, driveroptions ...string) { - driver := GetDriver(b, drivername, driveroptions...) - defer PutDriver(b) - base := stringid.GenerateRandomID() - upper := stringid.GenerateRandomID() - if err := driver.Create(base, "", nil); err != nil { - b.Fatal(err) - } - - if err := addManyFiles(driver, base, fileCount, 3); err != nil { - b.Fatal(err) - } - - if err := driver.Create(upper, base, nil); err != nil { - b.Fatal(err) - } - - if err := addManyFiles(driver, upper, fileCount, 6); err != nil { - b.Fatal(err) - } - diffSize, err := driver.DiffSize(upper, "") - if err != nil { - b.Fatal(err) - } - b.ResetTimer() - b.StopTimer() - for i := 0; i < b.N; i++ { - diff := stringid.GenerateRandomID() - if err := driver.Create(diff, base, nil); err != nil { - b.Fatal(err) - } - - if err := checkManyFiles(driver, diff, fileCount, 3); err != nil { - b.Fatal(err) - } - - b.StartTimer() - - arch, err := driver.Diff(upper, "") - if err != nil { - b.Fatal(err) - } - - applyDiffSize, err := driver.ApplyDiff(diff, "", arch) - if err != nil { - b.Fatal(err) - } - - b.StopTimer() - arch.Close() - - if applyDiffSize != diffSize { - // TODO: enforce this - //b.Fatalf("Apply diff size different, got %d, expected %s", applyDiffSize, diffSize) - } - if err := checkManyFiles(driver, diff, fileCount, 6); err != nil { - b.Fatal(err) - } - } -} - -// DriverBenchDeepLayerDiff benchmarks calls to diff on top of a given number of layers. -func DriverBenchDeepLayerDiff(b *testing.B, layerCount int, drivername string, driveroptions ...string) { - driver := GetDriver(b, drivername, driveroptions...) - defer PutDriver(b) - - base := stringid.GenerateRandomID() - if err := driver.Create(base, "", nil); err != nil { - b.Fatal(err) - } - - if err := addFiles(driver, base, 50); err != nil { - b.Fatal(err) - } - - topLayer, err := addManyLayers(driver, base, layerCount) - if err != nil { - b.Fatal(err) - } - - b.ResetTimer() - for i := 0; i < b.N; i++ { - arch, err := driver.Diff(topLayer, "") - if err != nil { - b.Fatal(err) - } - _, err = io.Copy(ioutil.Discard, arch) - if err != nil { - b.Fatalf("Error copying archive: %s", err) - } - arch.Close() - } -} - -// DriverBenchDeepLayerRead benchmarks calls to read a file under a given number of layers. -func DriverBenchDeepLayerRead(b *testing.B, layerCount int, drivername string, driveroptions ...string) { - driver := GetDriver(b, drivername, driveroptions...) - defer PutDriver(b) - - base := stringid.GenerateRandomID() - if err := driver.Create(base, "", nil); err != nil { - b.Fatal(err) - } - - content := []byte("test content") - if err := addFile(driver, base, "testfile.txt", content); err != nil { - b.Fatal(err) - } - - topLayer, err := addManyLayers(driver, base, layerCount) - if err != nil { - b.Fatal(err) - } - - root, err := driver.Get(topLayer, "") - if err != nil { - b.Fatal(err) - } - defer driver.Put(topLayer) - - b.ResetTimer() - for i := 0; i < b.N; i++ { - - // Read content - c, err := ioutil.ReadFile(filepath.Join(root, "testfile.txt")) - if err != nil { - b.Fatal(err) - } - - b.StopTimer() - if bytes.Compare(c, content) != 0 { - b.Fatalf("Wrong content in file %v, expected %v", c, content) - } - b.StartTimer() - } -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/graphtest_unix.go b/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/graphtest_unix.go deleted file mode 100644 index 6e952de..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/graphtest_unix.go +++ /dev/null @@ -1,358 +0,0 @@ -// +build linux freebsd solaris - -package graphtest - -import ( - "bytes" - "io/ioutil" - "math/rand" - "os" - "path" - "reflect" - "syscall" - "testing" - "unsafe" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/go-units" -) - -var ( - drv *Driver -) - -// Driver conforms to graphdriver.Driver interface and -// contains information such as root and reference count of the number of clients using it. -// This helps in testing drivers added into the framework. -type Driver struct { - graphdriver.Driver - root string - refCount int -} - -func newDriver(t testing.TB, name string, options []string) *Driver { - root, err := ioutil.TempDir("", "docker-graphtest-") - if err != nil { - t.Fatal(err) - } - - if err := os.MkdirAll(root, 0755); err != nil { - t.Fatal(err) - } - - d, err := graphdriver.GetDriver(name, nil, graphdriver.Options{DriverOptions: options, Root: root}) - if err != nil { - t.Logf("graphdriver: %v\n", err) - if err == graphdriver.ErrNotSupported || err == graphdriver.ErrPrerequisites || err == graphdriver.ErrIncompatibleFS { - t.Skipf("Driver %s not supported", name) - } - t.Fatal(err) - } - return &Driver{d, root, 1} -} - -func cleanup(t testing.TB, d *Driver) { - if err := drv.Cleanup(); err != nil { - t.Fatal(err) - } - os.RemoveAll(d.root) -} - -// GetDriver create a new driver with given name or return an existing driver with the name updating the reference count. -func GetDriver(t testing.TB, name string, options ...string) graphdriver.Driver { - if drv == nil { - drv = newDriver(t, name, options) - } else { - drv.refCount++ - } - return drv -} - -// PutDriver removes the driver if it is no longer used and updates the reference count. -func PutDriver(t testing.TB) { - if drv == nil { - t.Skip("No driver to put!") - } - drv.refCount-- - if drv.refCount == 0 { - cleanup(t, drv) - drv = nil - } -} - -// DriverTestCreateEmpty creates a new image and verifies it is empty and the right metadata -func DriverTestCreateEmpty(t testing.TB, drivername string, driverOptions ...string) { - driver := GetDriver(t, drivername, driverOptions...) - defer PutDriver(t) - - if err := driver.Create("empty", "", nil); err != nil { - t.Fatal(err) - } - - defer func() { - if err := driver.Remove("empty"); err != nil { - t.Fatal(err) - } - }() - - if !driver.Exists("empty") { - t.Fatal("Newly created image doesn't exist") - } - - dir, err := driver.Get("empty", "") - if err != nil { - t.Fatal(err) - } - - verifyFile(t, dir, 0755|os.ModeDir, 0, 0) - - // Verify that the directory is empty - fis, err := readDir(dir) - if err != nil { - t.Fatal(err) - } - - if len(fis) != 0 { - t.Fatal("New directory not empty") - } - - driver.Put("empty") -} - -// DriverTestCreateBase create a base driver and verify. -func DriverTestCreateBase(t testing.TB, drivername string, driverOptions ...string) { - driver := GetDriver(t, drivername, driverOptions...) - defer PutDriver(t) - - createBase(t, driver, "Base") - defer func() { - if err := driver.Remove("Base"); err != nil { - t.Fatal(err) - } - }() - verifyBase(t, driver, "Base") -} - -// DriverTestCreateSnap Create a driver and snap and verify. -func DriverTestCreateSnap(t testing.TB, drivername string, driverOptions ...string) { - driver := GetDriver(t, drivername, driverOptions...) - defer PutDriver(t) - - createBase(t, driver, "Base") - - defer func() { - if err := driver.Remove("Base"); err != nil { - t.Fatal(err) - } - }() - - if err := driver.Create("Snap", "Base", nil); err != nil { - t.Fatal(err) - } - - defer func() { - if err := driver.Remove("Snap"); err != nil { - t.Fatal(err) - } - }() - - verifyBase(t, driver, "Snap") -} - -// DriverTestDeepLayerRead reads a file from a lower layer under a given number of layers -func DriverTestDeepLayerRead(t testing.TB, layerCount int, drivername string, driverOptions ...string) { - driver := GetDriver(t, drivername, driverOptions...) - defer PutDriver(t) - - base := stringid.GenerateRandomID() - if err := driver.Create(base, "", nil); err != nil { - t.Fatal(err) - } - - content := []byte("test content") - if err := addFile(driver, base, "testfile.txt", content); err != nil { - t.Fatal(err) - } - - topLayer, err := addManyLayers(driver, base, layerCount) - if err != nil { - t.Fatal(err) - } - - err = checkManyLayers(driver, topLayer, layerCount) - if err != nil { - t.Fatal(err) - } - - if err := checkFile(driver, topLayer, "testfile.txt", content); err != nil { - t.Fatal(err) - } -} - -// DriverTestDiffApply tests diffing and applying produces the same layer -func DriverTestDiffApply(t testing.TB, fileCount int, drivername string, driverOptions ...string) { - driver := GetDriver(t, drivername, driverOptions...) - defer PutDriver(t) - base := stringid.GenerateRandomID() - upper := stringid.GenerateRandomID() - deleteFile := "file-remove.txt" - deleteFileContent := []byte("This file should get removed in upper!") - deleteDir := "var/lib" - - if err := driver.Create(base, "", nil); err != nil { - t.Fatal(err) - } - - if err := addManyFiles(driver, base, fileCount, 3); err != nil { - t.Fatal(err) - } - - if err := addFile(driver, base, deleteFile, deleteFileContent); err != nil { - t.Fatal(err) - } - - if err := addDirectory(driver, base, deleteDir); err != nil { - t.Fatal(err) - } - - if err := driver.Create(upper, base, nil); err != nil { - t.Fatal(err) - } - - if err := addManyFiles(driver, upper, fileCount, 6); err != nil { - t.Fatal(err) - } - - if err := removeAll(driver, upper, deleteFile, deleteDir); err != nil { - t.Fatal(err) - } - - diffSize, err := driver.DiffSize(upper, "") - if err != nil { - t.Fatal(err) - } - - diff := stringid.GenerateRandomID() - if err := driver.Create(diff, base, nil); err != nil { - t.Fatal(err) - } - - if err := checkManyFiles(driver, diff, fileCount, 3); err != nil { - t.Fatal(err) - } - - if err := checkFile(driver, diff, deleteFile, deleteFileContent); err != nil { - t.Fatal(err) - } - - arch, err := driver.Diff(upper, base) - if err != nil { - t.Fatal(err) - } - - buf := bytes.NewBuffer(nil) - if _, err := buf.ReadFrom(arch); err != nil { - t.Fatal(err) - } - if err := arch.Close(); err != nil { - t.Fatal(err) - } - - applyDiffSize, err := driver.ApplyDiff(diff, base, bytes.NewReader(buf.Bytes())) - if err != nil { - t.Fatal(err) - } - - if applyDiffSize != diffSize { - t.Fatalf("Apply diff size different, got %d, expected %d", applyDiffSize, diffSize) - } - - if err := checkManyFiles(driver, diff, fileCount, 6); err != nil { - t.Fatal(err) - } - - if err := checkFileRemoved(driver, diff, deleteFile); err != nil { - t.Fatal(err) - } - - if err := checkFileRemoved(driver, diff, deleteDir); err != nil { - t.Fatal(err) - } -} - -// DriverTestChanges tests computed changes on a layer matches changes made -func DriverTestChanges(t testing.TB, drivername string, driverOptions ...string) { - driver := GetDriver(t, drivername, driverOptions...) - defer PutDriver(t) - base := stringid.GenerateRandomID() - upper := stringid.GenerateRandomID() - if err := driver.Create(base, "", nil); err != nil { - t.Fatal(err) - } - - if err := addManyFiles(driver, base, 20, 3); err != nil { - t.Fatal(err) - } - - if err := driver.Create(upper, base, nil); err != nil { - t.Fatal(err) - } - - expectedChanges, err := changeManyFiles(driver, upper, 20, 6) - if err != nil { - t.Fatal(err) - } - - changes, err := driver.Changes(upper, base) - if err != nil { - t.Fatal(err) - } - - if err = checkChanges(expectedChanges, changes); err != nil { - t.Fatal(err) - } -} - -func writeRandomFile(path string, size uint64) error { - buf := make([]int64, size/8) - - r := rand.NewSource(0) - for i := range buf { - buf[i] = r.Int63() - } - - // Cast to []byte - header := *(*reflect.SliceHeader)(unsafe.Pointer(&buf)) - header.Len *= 8 - header.Cap *= 8 - data := *(*[]byte)(unsafe.Pointer(&header)) - - return ioutil.WriteFile(path, data, 0700) -} - -// DriverTestSetQuota Create a driver and test setting quota. -func DriverTestSetQuota(t *testing.T, drivername string) { - driver := GetDriver(t, drivername) - defer PutDriver(t) - - createBase(t, driver, "Base") - createOpts := &graphdriver.CreateOpts{} - createOpts.StorageOpt = make(map[string]string, 1) - createOpts.StorageOpt["size"] = "50M" - if err := driver.Create("zfsTest", "Base", createOpts); err != nil { - t.Fatal(err) - } - - mountPath, err := driver.Get("zfsTest", "") - if err != nil { - t.Fatal(err) - } - - quota := uint64(50 * units.MiB) - err = writeRandomFile(path.Join(mountPath, "file"), quota*2) - if pathError, ok := err.(*os.PathError); ok && pathError.Err != syscall.EDQUOT { - t.Fatalf("expect write() to fail with %v, got %v", syscall.EDQUOT, err) - } - -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/graphtest_windows.go b/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/graphtest_windows.go deleted file mode 100644 index a50c521..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/graphtest_windows.go +++ /dev/null @@ -1 +0,0 @@ -package graphtest diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/testutil.go b/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/testutil.go deleted file mode 100644 index 35bf6d1..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/testutil.go +++ /dev/null @@ -1,342 +0,0 @@ -package graphtest - -import ( - "bytes" - "fmt" - "io/ioutil" - "math/rand" - "os" - "path" - "sort" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/stringid" -) - -func randomContent(size int, seed int64) []byte { - s := rand.NewSource(seed) - content := make([]byte, size) - - for i := 0; i < len(content); i += 7 { - val := s.Int63() - for j := 0; i+j < len(content) && j < 7; j++ { - content[i+j] = byte(val) - val >>= 8 - } - } - - return content -} - -func addFiles(drv graphdriver.Driver, layer string, seed int64) error { - root, err := drv.Get(layer, "") - if err != nil { - return err - } - defer drv.Put(layer) - - if err := ioutil.WriteFile(path.Join(root, "file-a"), randomContent(64, seed), 0755); err != nil { - return err - } - if err := os.MkdirAll(path.Join(root, "dir-b"), 0755); err != nil { - return err - } - if err := ioutil.WriteFile(path.Join(root, "dir-b", "file-b"), randomContent(128, seed+1), 0755); err != nil { - return err - } - - return ioutil.WriteFile(path.Join(root, "file-c"), randomContent(128*128, seed+2), 0755) -} - -func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) error { - root, err := drv.Get(layer, "") - if err != nil { - return err - } - defer drv.Put(layer) - - fileContent, err := ioutil.ReadFile(path.Join(root, filename)) - if err != nil { - return err - } - - if bytes.Compare(fileContent, content) != 0 { - return fmt.Errorf("mismatched file content %v, expecting %v", fileContent, content) - } - - return nil -} - -func addFile(drv graphdriver.Driver, layer, filename string, content []byte) error { - root, err := drv.Get(layer, "") - if err != nil { - return err - } - defer drv.Put(layer) - - return ioutil.WriteFile(path.Join(root, filename), content, 0755) -} - -func addDirectory(drv graphdriver.Driver, layer, dir string) error { - root, err := drv.Get(layer, "") - if err != nil { - return err - } - defer drv.Put(layer) - - return os.MkdirAll(path.Join(root, dir), 0755) -} - -func removeAll(drv graphdriver.Driver, layer string, names ...string) error { - root, err := drv.Get(layer, "") - if err != nil { - return err - } - defer drv.Put(layer) - - for _, filename := range names { - if err := os.RemoveAll(path.Join(root, filename)); err != nil { - return err - } - } - return nil -} - -func checkFileRemoved(drv graphdriver.Driver, layer, filename string) error { - root, err := drv.Get(layer, "") - if err != nil { - return err - } - defer drv.Put(layer) - - if _, err := os.Stat(path.Join(root, filename)); err == nil { - return fmt.Errorf("file still exists: %s", path.Join(root, filename)) - } else if !os.IsNotExist(err) { - return err - } - - return nil -} - -func addManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) error { - root, err := drv.Get(layer, "") - if err != nil { - return err - } - defer drv.Put(layer) - - for i := 0; i < count; i += 100 { - dir := path.Join(root, fmt.Sprintf("directory-%d", i)) - if err := os.MkdirAll(dir, 0755); err != nil { - return err - } - for j := 0; i+j < count && j < 100; j++ { - file := path.Join(dir, fmt.Sprintf("file-%d", i+j)) - if err := ioutil.WriteFile(file, randomContent(64, seed+int64(i+j)), 0755); err != nil { - return err - } - } - } - - return nil -} - -func changeManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) ([]archive.Change, error) { - root, err := drv.Get(layer, "") - if err != nil { - return nil, err - } - defer drv.Put(layer) - - changes := []archive.Change{} - for i := 0; i < count; i += 100 { - archiveRoot := fmt.Sprintf("/directory-%d", i) - if err := os.MkdirAll(path.Join(root, archiveRoot), 0755); err != nil { - return nil, err - } - for j := 0; i+j < count && j < 100; j++ { - if j == 0 { - changes = append(changes, archive.Change{ - Path: archiveRoot, - Kind: archive.ChangeModify, - }) - } - var change archive.Change - switch j % 3 { - // Update file - case 0: - change.Path = path.Join(archiveRoot, fmt.Sprintf("file-%d", i+j)) - change.Kind = archive.ChangeModify - if err := ioutil.WriteFile(path.Join(root, change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil { - return nil, err - } - // Add file - case 1: - change.Path = path.Join(archiveRoot, fmt.Sprintf("file-%d-%d", seed, i+j)) - change.Kind = archive.ChangeAdd - if err := ioutil.WriteFile(path.Join(root, change.Path), randomContent(64, seed+int64(i+j)), 0755); err != nil { - return nil, err - } - // Remove file - case 2: - change.Path = path.Join(archiveRoot, fmt.Sprintf("file-%d", i+j)) - change.Kind = archive.ChangeDelete - if err := os.Remove(path.Join(root, change.Path)); err != nil { - return nil, err - } - } - changes = append(changes, change) - } - } - - return changes, nil -} - -func checkManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) error { - root, err := drv.Get(layer, "") - if err != nil { - return err - } - defer drv.Put(layer) - - for i := 0; i < count; i += 100 { - dir := path.Join(root, fmt.Sprintf("directory-%d", i)) - for j := 0; i+j < count && j < 100; j++ { - file := path.Join(dir, fmt.Sprintf("file-%d", i+j)) - fileContent, err := ioutil.ReadFile(file) - if err != nil { - return err - } - - content := randomContent(64, seed+int64(i+j)) - - if bytes.Compare(fileContent, content) != 0 { - return fmt.Errorf("mismatched file content %v, expecting %v", fileContent, content) - } - } - } - - return nil -} - -type changeList []archive.Change - -func (c changeList) Less(i, j int) bool { - if c[i].Path == c[j].Path { - return c[i].Kind < c[j].Kind - } - return c[i].Path < c[j].Path -} -func (c changeList) Len() int { return len(c) } -func (c changeList) Swap(i, j int) { c[j], c[i] = c[i], c[j] } - -func checkChanges(expected, actual []archive.Change) error { - if len(expected) != len(actual) { - return fmt.Errorf("unexpected number of changes, expected %d, got %d", len(expected), len(actual)) - } - sort.Sort(changeList(expected)) - sort.Sort(changeList(actual)) - - for i := range expected { - if expected[i] != actual[i] { - return fmt.Errorf("unexpected change, expecting %v, got %v", expected[i], actual[i]) - } - } - - return nil -} - -func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error { - root, err := drv.Get(layer, "") - if err != nil { - return err - } - defer drv.Put(layer) - - if err := ioutil.WriteFile(path.Join(root, "top-id"), []byte(layer), 0755); err != nil { - return err - } - layerDir := path.Join(root, fmt.Sprintf("layer-%d", i)) - if err := os.MkdirAll(layerDir, 0755); err != nil { - return err - } - if err := ioutil.WriteFile(path.Join(layerDir, "layer-id"), []byte(layer), 0755); err != nil { - return err - } - if err := ioutil.WriteFile(path.Join(layerDir, "parent-id"), []byte(parent), 0755); err != nil { - return err - } - - return nil -} - -func addManyLayers(drv graphdriver.Driver, baseLayer string, count int) (string, error) { - lastLayer := baseLayer - for i := 1; i <= count; i++ { - nextLayer := stringid.GenerateRandomID() - if err := drv.Create(nextLayer, lastLayer, nil); err != nil { - return "", err - } - if err := addLayerFiles(drv, nextLayer, lastLayer, i); err != nil { - return "", err - } - - lastLayer = nextLayer - - } - return lastLayer, nil -} - -func checkManyLayers(drv graphdriver.Driver, layer string, count int) error { - root, err := drv.Get(layer, "") - if err != nil { - return err - } - defer drv.Put(layer) - - layerIDBytes, err := ioutil.ReadFile(path.Join(root, "top-id")) - if err != nil { - return err - } - - if bytes.Compare(layerIDBytes, []byte(layer)) != 0 { - return fmt.Errorf("mismatched file content %v, expecting %v", layerIDBytes, []byte(layer)) - } - - for i := count; i > 0; i-- { - layerDir := path.Join(root, fmt.Sprintf("layer-%d", i)) - - thisLayerIDBytes, err := ioutil.ReadFile(path.Join(layerDir, "layer-id")) - if err != nil { - return err - } - if bytes.Compare(thisLayerIDBytes, layerIDBytes) != 0 { - return fmt.Errorf("mismatched file content %v, expecting %v", thisLayerIDBytes, layerIDBytes) - } - layerIDBytes, err = ioutil.ReadFile(path.Join(layerDir, "parent-id")) - if err != nil { - return err - } - } - return nil -} - -// readDir reads a directory just like ioutil.ReadDir() -// then hides specific files (currently "lost+found") -// so the tests don't "see" it -func readDir(dir string) ([]os.FileInfo, error) { - a, err := ioutil.ReadDir(dir) - if err != nil { - return nil, err - } - - b := a[:0] - for _, x := range a { - if x.Name() != "lost+found" { // ext4 always have this dir - b = append(b, x) - } - } - - return b, nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/testutil_unix.go b/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/testutil_unix.go deleted file mode 100644 index 49b0c2c..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/graphtest/testutil_unix.go +++ /dev/null @@ -1,143 +0,0 @@ -// +build linux freebsd - -package graphtest - -import ( - "fmt" - "io/ioutil" - "os" - "path" - "syscall" - "testing" - - "github.com/docker/docker/daemon/graphdriver" -) - -// InitLoopbacks ensures that the loopback devices are properly created within -// the system running the device mapper tests. -func InitLoopbacks() error { - statT, err := getBaseLoopStats() - if err != nil { - return err - } - // create at least 8 loopback files, ya, that is a good number - for i := 0; i < 8; i++ { - loopPath := fmt.Sprintf("/dev/loop%d", i) - // only create new loopback files if they don't exist - if _, err := os.Stat(loopPath); err != nil { - if mkerr := syscall.Mknod(loopPath, - uint32(statT.Mode|syscall.S_IFBLK), int((7<<8)|(i&0xff)|((i&0xfff00)<<12))); mkerr != nil { - return mkerr - } - os.Chown(loopPath, int(statT.Uid), int(statT.Gid)) - } - } - return nil -} - -// getBaseLoopStats inspects /dev/loop0 to collect uid,gid, and mode for the -// loop0 device on the system. If it does not exist we assume 0,0,0660 for the -// stat data -func getBaseLoopStats() (*syscall.Stat_t, error) { - loop0, err := os.Stat("/dev/loop0") - if err != nil { - if os.IsNotExist(err) { - return &syscall.Stat_t{ - Uid: 0, - Gid: 0, - Mode: 0660, - }, nil - } - return nil, err - } - return loop0.Sys().(*syscall.Stat_t), nil -} - -func verifyFile(t testing.TB, path string, mode os.FileMode, uid, gid uint32) { - fi, err := os.Stat(path) - if err != nil { - t.Fatal(err) - } - - if fi.Mode()&os.ModeType != mode&os.ModeType { - t.Fatalf("Expected %s type 0x%x, got 0x%x", path, mode&os.ModeType, fi.Mode()&os.ModeType) - } - - if fi.Mode()&os.ModePerm != mode&os.ModePerm { - t.Fatalf("Expected %s mode %o, got %o", path, mode&os.ModePerm, fi.Mode()&os.ModePerm) - } - - if fi.Mode()&os.ModeSticky != mode&os.ModeSticky { - t.Fatalf("Expected %s sticky 0x%x, got 0x%x", path, mode&os.ModeSticky, fi.Mode()&os.ModeSticky) - } - - if fi.Mode()&os.ModeSetuid != mode&os.ModeSetuid { - t.Fatalf("Expected %s setuid 0x%x, got 0x%x", path, mode&os.ModeSetuid, fi.Mode()&os.ModeSetuid) - } - - if fi.Mode()&os.ModeSetgid != mode&os.ModeSetgid { - t.Fatalf("Expected %s setgid 0x%x, got 0x%x", path, mode&os.ModeSetgid, fi.Mode()&os.ModeSetgid) - } - - if stat, ok := fi.Sys().(*syscall.Stat_t); ok { - if stat.Uid != uid { - t.Fatalf("%s no owned by uid %d", path, uid) - } - if stat.Gid != gid { - t.Fatalf("%s not owned by gid %d", path, gid) - } - } -} - -func createBase(t testing.TB, driver graphdriver.Driver, name string) { - // We need to be able to set any perms - oldmask := syscall.Umask(0) - defer syscall.Umask(oldmask) - - if err := driver.CreateReadWrite(name, "", nil); err != nil { - t.Fatal(err) - } - - dir, err := driver.Get(name, "") - if err != nil { - t.Fatal(err) - } - defer driver.Put(name) - - subdir := path.Join(dir, "a subdir") - if err := os.Mkdir(subdir, 0705|os.ModeSticky); err != nil { - t.Fatal(err) - } - if err := os.Chown(subdir, 1, 2); err != nil { - t.Fatal(err) - } - - file := path.Join(dir, "a file") - if err := ioutil.WriteFile(file, []byte("Some data"), 0222|os.ModeSetuid); err != nil { - t.Fatal(err) - } -} - -func verifyBase(t testing.TB, driver graphdriver.Driver, name string) { - dir, err := driver.Get(name, "") - if err != nil { - t.Fatal(err) - } - defer driver.Put(name) - - subdir := path.Join(dir, "a subdir") - verifyFile(t, subdir, 0705|os.ModeDir|os.ModeSticky, 1, 2) - - file := path.Join(dir, "a file") - verifyFile(t, file, 0222|os.ModeSetuid, 0, 0) - - fis, err := readDir(dir) - if err != nil { - t.Fatal(err) - } - - if len(fis) != 2 { - t.Fatal("Unexpected files in base image") - } - -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlay/copy.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlay/copy.go deleted file mode 100644 index 666a5c0..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlay/copy.go +++ /dev/null @@ -1,174 +0,0 @@ -// +build linux - -package overlay - -import ( - "fmt" - "os" - "path/filepath" - "syscall" - "time" - - "github.com/docker/docker/pkg/pools" - "github.com/docker/docker/pkg/system" - rsystem "github.com/opencontainers/runc/libcontainer/system" -) - -type copyFlags int - -const ( - copyHardlink copyFlags = 1 << iota -) - -func copyRegular(srcPath, dstPath string, mode os.FileMode) error { - srcFile, err := os.Open(srcPath) - if err != nil { - return err - } - defer srcFile.Close() - - dstFile, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE, mode) - if err != nil { - return err - } - defer dstFile.Close() - - _, err = pools.Copy(dstFile, srcFile) - - return err -} - -func copyXattr(srcPath, dstPath, attr string) error { - data, err := system.Lgetxattr(srcPath, attr) - if err != nil { - return err - } - if data != nil { - if err := system.Lsetxattr(dstPath, attr, data, 0); err != nil { - return err - } - } - return nil -} - -func copyDir(srcDir, dstDir string, flags copyFlags) error { - err := filepath.Walk(srcDir, func(srcPath string, f os.FileInfo, err error) error { - if err != nil { - return err - } - - // Rebase path - relPath, err := filepath.Rel(srcDir, srcPath) - if err != nil { - return err - } - - dstPath := filepath.Join(dstDir, relPath) - if err != nil { - return err - } - - stat, ok := f.Sys().(*syscall.Stat_t) - if !ok { - return fmt.Errorf("Unable to get raw syscall.Stat_t data for %s", srcPath) - } - - isHardlink := false - - switch f.Mode() & os.ModeType { - case 0: // Regular file - if flags©Hardlink != 0 { - isHardlink = true - if err := os.Link(srcPath, dstPath); err != nil { - return err - } - } else { - if err := copyRegular(srcPath, dstPath, f.Mode()); err != nil { - return err - } - } - - case os.ModeDir: - if err := os.Mkdir(dstPath, f.Mode()); err != nil && !os.IsExist(err) { - return err - } - - case os.ModeSymlink: - link, err := os.Readlink(srcPath) - if err != nil { - return err - } - - if err := os.Symlink(link, dstPath); err != nil { - return err - } - - case os.ModeNamedPipe: - fallthrough - case os.ModeSocket: - if rsystem.RunningInUserNS() { - // cannot create a device if running in user namespace - return nil - } - if err := syscall.Mkfifo(dstPath, stat.Mode); err != nil { - return err - } - - case os.ModeDevice: - if err := syscall.Mknod(dstPath, stat.Mode, int(stat.Rdev)); err != nil { - return err - } - - default: - return fmt.Errorf("Unknown file type for %s\n", srcPath) - } - - // Everything below is copying metadata from src to dst. All this metadata - // already shares an inode for hardlinks. - if isHardlink { - return nil - } - - if err := os.Lchown(dstPath, int(stat.Uid), int(stat.Gid)); err != nil { - return err - } - - if err := copyXattr(srcPath, dstPath, "security.capability"); err != nil { - return err - } - - // We need to copy this attribute if it appears in an overlay upper layer, as - // this function is used to copy those. It is set by overlay if a directory - // is removed and then re-created and should not inherit anything from the - // same dir in the lower dir. - if err := copyXattr(srcPath, dstPath, "trusted.overlay.opaque"); err != nil { - return err - } - - isSymlink := f.Mode()&os.ModeSymlink != 0 - - // There is no LChmod, so ignore mode for symlink. Also, this - // must happen after chown, as that can modify the file mode - if !isSymlink { - if err := os.Chmod(dstPath, f.Mode()); err != nil { - return err - } - } - - // system.Chtimes doesn't support a NOFOLLOW flag atm - if !isSymlink { - aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) - mTime := time.Unix(int64(stat.Mtim.Sec), int64(stat.Mtim.Nsec)) - if err := system.Chtimes(dstPath, aTime, mTime); err != nil { - return err - } - } else { - ts := []syscall.Timespec{stat.Atim, stat.Mtim} - if err := system.LUtimesNano(dstPath, ts); err != nil { - return err - } - } - return nil - }) - return err -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlay/overlay.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlay/overlay.go deleted file mode 100644 index 121b72e..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlay/overlay.go +++ /dev/null @@ -1,462 +0,0 @@ -// +build linux - -package overlay - -import ( - "bufio" - "fmt" - "io" - "io/ioutil" - "os" - "os/exec" - "path" - "strconv" - "syscall" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/daemon/graphdriver/overlayutils" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/fsutils" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/mount" - "github.com/opencontainers/runc/libcontainer/label" -) - -// This is a small wrapper over the NaiveDiffWriter that lets us have a custom -// implementation of ApplyDiff() - -var ( - // ErrApplyDiffFallback is returned to indicate that a normal ApplyDiff is applied as a fallback from Naive diff writer. - ErrApplyDiffFallback = fmt.Errorf("Fall back to normal ApplyDiff") - backingFs = "" -) - -// ApplyDiffProtoDriver wraps the ProtoDriver by extending the interface with ApplyDiff method. -type ApplyDiffProtoDriver interface { - graphdriver.ProtoDriver - // ApplyDiff writes the diff to the archive for the given id and parent id. - // It returns the size in bytes written if successful, an error ErrApplyDiffFallback is returned otherwise. - ApplyDiff(id, parent string, diff io.Reader) (size int64, err error) -} - -type naiveDiffDriverWithApply struct { - graphdriver.Driver - applyDiff ApplyDiffProtoDriver -} - -// NaiveDiffDriverWithApply returns a NaiveDiff driver with custom ApplyDiff. -func NaiveDiffDriverWithApply(driver ApplyDiffProtoDriver, uidMaps, gidMaps []idtools.IDMap) graphdriver.Driver { - return &naiveDiffDriverWithApply{ - Driver: graphdriver.NewNaiveDiffDriver(driver, uidMaps, gidMaps), - applyDiff: driver, - } -} - -// ApplyDiff creates a diff layer with either the NaiveDiffDriver or with a fallback. -func (d *naiveDiffDriverWithApply) ApplyDiff(id, parent string, diff io.Reader) (int64, error) { - b, err := d.applyDiff.ApplyDiff(id, parent, diff) - if err == ErrApplyDiffFallback { - return d.Driver.ApplyDiff(id, parent, diff) - } - return b, err -} - -// This backend uses the overlay union filesystem for containers -// plus hard link file sharing for images. - -// Each container/image can have a "root" subdirectory which is a plain -// filesystem hierarchy, or they can use overlay. - -// If they use overlay there is a "upper" directory and a "lower-id" -// file, as well as "merged" and "work" directories. The "upper" -// directory has the upper layer of the overlay, and "lower-id" contains -// the id of the parent whose "root" directory shall be used as the lower -// layer in the overlay. The overlay itself is mounted in the "merged" -// directory, and the "work" dir is needed for overlay to work. - -// When an overlay layer is created there are two cases, either the -// parent has a "root" dir, then we start out with an empty "upper" -// directory overlaid on the parents root. This is typically the -// case with the init layer of a container which is based on an image. -// If there is no "root" in the parent, we inherit the lower-id from -// the parent and start by making a copy in the parent's "upper" dir. -// This is typically the case for a container layer which copies -// its parent -init upper layer. - -// Additionally we also have a custom implementation of ApplyLayer -// which makes a recursive copy of the parent "root" layer using -// hardlinks to share file data, and then applies the layer on top -// of that. This means all child images share file (but not directory) -// data with the parent. - -// Driver contains information about the home directory and the list of active mounts that are created using this driver. -type Driver struct { - home string - uidMaps []idtools.IDMap - gidMaps []idtools.IDMap - ctr *graphdriver.RefCounter - supportsDType bool -} - -func init() { - graphdriver.Register("overlay", Init) -} - -// Init returns the NaiveDiffDriver, a native diff driver for overlay filesystem. -// If overlay filesystem is not supported on the host, graphdriver.ErrNotSupported is returned as error. -// If an overlay filesystem is not supported over an existing filesystem then error graphdriver.ErrIncompatibleFS is returned. -func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - - if err := supportsOverlay(); err != nil { - return nil, graphdriver.ErrNotSupported - } - - fsMagic, err := graphdriver.GetFSMagic(home) - if err != nil { - return nil, err - } - if fsName, ok := graphdriver.FsNames[fsMagic]; ok { - backingFs = fsName - } - - switch fsMagic { - case graphdriver.FsMagicAufs, graphdriver.FsMagicBtrfs, graphdriver.FsMagicOverlay, graphdriver.FsMagicZfs, graphdriver.FsMagicEcryptfs: - logrus.Errorf("'overlay' is not supported over %s", backingFs) - return nil, graphdriver.ErrIncompatibleFS - } - - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) - if err != nil { - return nil, err - } - // Create the driver home dir - if err := idtools.MkdirAllAs(home, 0700, rootUID, rootGID); err != nil && !os.IsExist(err) { - return nil, err - } - - if err := mount.MakePrivate(home); err != nil { - return nil, err - } - - supportsDType, err := fsutils.SupportsDType(home) - if err != nil { - return nil, err - } - if !supportsDType { - // not a fatal error until v1.16 (#27443) - logrus.Warn(overlayutils.ErrDTypeNotSupported("overlay", backingFs)) - } - - d := &Driver{ - home: home, - uidMaps: uidMaps, - gidMaps: gidMaps, - ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicOverlay)), - supportsDType: supportsDType, - } - - return NaiveDiffDriverWithApply(d, uidMaps, gidMaps), nil -} - -func supportsOverlay() error { - // We can try to modprobe overlay first before looking at - // proc/filesystems for when overlay is supported - exec.Command("modprobe", "overlay").Run() - - f, err := os.Open("/proc/filesystems") - if err != nil { - return err - } - defer f.Close() - - s := bufio.NewScanner(f) - for s.Scan() { - if s.Text() == "nodev\toverlay" { - return nil - } - } - logrus.Error("'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support loaded.") - return graphdriver.ErrNotSupported -} - -func (d *Driver) String() string { - return "overlay" -} - -// Status returns current driver information in a two dimensional string array. -// Output contains "Backing Filesystem" used in this implementation. -func (d *Driver) Status() [][2]string { - return [][2]string{ - {"Backing Filesystem", backingFs}, - {"Supports d_type", strconv.FormatBool(d.supportsDType)}, - } -} - -// GetMetadata returns meta data about the overlay driver such as root, LowerDir, UpperDir, WorkDir and MergeDir used to store data. -func (d *Driver) GetMetadata(id string) (map[string]string, error) { - dir := d.dir(id) - if _, err := os.Stat(dir); err != nil { - return nil, err - } - - metadata := make(map[string]string) - - // If id has a root, it is an image - rootDir := path.Join(dir, "root") - if _, err := os.Stat(rootDir); err == nil { - metadata["RootDir"] = rootDir - return metadata, nil - } - - lowerID, err := ioutil.ReadFile(path.Join(dir, "lower-id")) - if err != nil { - return nil, err - } - - metadata["LowerDir"] = path.Join(d.dir(string(lowerID)), "root") - metadata["UpperDir"] = path.Join(dir, "upper") - metadata["WorkDir"] = path.Join(dir, "work") - metadata["MergedDir"] = path.Join(dir, "merged") - - return metadata, nil -} - -// Cleanup any state created by overlay which should be cleaned when daemon -// is being shutdown. For now, we just have to unmount the bind mounted -// we had created. -func (d *Driver) Cleanup() error { - return mount.Unmount(d.home) -} - -// CreateReadWrite creates a layer that is writable for use as a container -// file system. -func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error { - return d.Create(id, parent, opts) -} - -// Create is used to create the upper, lower, and merge directories required for overlay fs for a given id. -// The parent filesystem is used to configure these directories for the overlay. -func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) (retErr error) { - - if opts != nil && len(opts.StorageOpt) != 0 { - return fmt.Errorf("--storage-opt is not supported for overlay") - } - - dir := d.dir(id) - - rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps) - if err != nil { - return err - } - if err := idtools.MkdirAllAs(path.Dir(dir), 0700, rootUID, rootGID); err != nil { - return err - } - if err := idtools.MkdirAs(dir, 0700, rootUID, rootGID); err != nil { - return err - } - - defer func() { - // Clean up on failure - if retErr != nil { - os.RemoveAll(dir) - } - }() - - // Toplevel images are just a "root" dir - if parent == "" { - if err := idtools.MkdirAs(path.Join(dir, "root"), 0755, rootUID, rootGID); err != nil { - return err - } - return nil - } - - parentDir := d.dir(parent) - - // Ensure parent exists - if _, err := os.Lstat(parentDir); err != nil { - return err - } - - // If parent has a root, just do an overlay to it - parentRoot := path.Join(parentDir, "root") - - if s, err := os.Lstat(parentRoot); err == nil { - if err := idtools.MkdirAs(path.Join(dir, "upper"), s.Mode(), rootUID, rootGID); err != nil { - return err - } - if err := idtools.MkdirAs(path.Join(dir, "work"), 0700, rootUID, rootGID); err != nil { - return err - } - if err := idtools.MkdirAs(path.Join(dir, "merged"), 0700, rootUID, rootGID); err != nil { - return err - } - if err := ioutil.WriteFile(path.Join(dir, "lower-id"), []byte(parent), 0666); err != nil { - return err - } - return nil - } - - // Otherwise, copy the upper and the lower-id from the parent - - lowerID, err := ioutil.ReadFile(path.Join(parentDir, "lower-id")) - if err != nil { - return err - } - - if err := ioutil.WriteFile(path.Join(dir, "lower-id"), lowerID, 0666); err != nil { - return err - } - - parentUpperDir := path.Join(parentDir, "upper") - s, err := os.Lstat(parentUpperDir) - if err != nil { - return err - } - - upperDir := path.Join(dir, "upper") - if err := idtools.MkdirAs(upperDir, s.Mode(), rootUID, rootGID); err != nil { - return err - } - if err := idtools.MkdirAs(path.Join(dir, "work"), 0700, rootUID, rootGID); err != nil { - return err - } - if err := idtools.MkdirAs(path.Join(dir, "merged"), 0700, rootUID, rootGID); err != nil { - return err - } - - return copyDir(parentUpperDir, upperDir, 0) -} - -func (d *Driver) dir(id string) string { - return path.Join(d.home, id) -} - -// Remove cleans the directories that are created for this id. -func (d *Driver) Remove(id string) error { - if err := os.RemoveAll(d.dir(id)); err != nil && !os.IsNotExist(err) { - return err - } - return nil -} - -// Get creates and mounts the required file system for the given id and returns the mount path. -func (d *Driver) Get(id string, mountLabel string) (s string, err error) { - dir := d.dir(id) - if _, err := os.Stat(dir); err != nil { - return "", err - } - // If id has a root, just return it - rootDir := path.Join(dir, "root") - if _, err := os.Stat(rootDir); err == nil { - return rootDir, nil - } - mergedDir := path.Join(dir, "merged") - if count := d.ctr.Increment(mergedDir); count > 1 { - return mergedDir, nil - } - defer func() { - if err != nil { - if c := d.ctr.Decrement(mergedDir); c <= 0 { - syscall.Unmount(mergedDir, 0) - } - } - }() - lowerID, err := ioutil.ReadFile(path.Join(dir, "lower-id")) - if err != nil { - return "", err - } - var ( - lowerDir = path.Join(d.dir(string(lowerID)), "root") - upperDir = path.Join(dir, "upper") - workDir = path.Join(dir, "work") - opts = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", lowerDir, upperDir, workDir) - ) - if err := syscall.Mount("overlay", mergedDir, "overlay", 0, label.FormatMountLabel(opts, mountLabel)); err != nil { - return "", fmt.Errorf("error creating overlay mount to %s: %v", mergedDir, err) - } - // chown "workdir/work" to the remapped root UID/GID. Overlay fs inside a - // user namespace requires this to move a directory from lower to upper. - rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps) - if err != nil { - return "", err - } - if err := os.Chown(path.Join(workDir, "work"), rootUID, rootGID); err != nil { - return "", err - } - return mergedDir, nil -} - -// Put unmounts the mount path created for the give id. -func (d *Driver) Put(id string) error { - // If id has a root, just return - if _, err := os.Stat(path.Join(d.dir(id), "root")); err == nil { - return nil - } - mountpoint := path.Join(d.dir(id), "merged") - if count := d.ctr.Decrement(mountpoint); count > 0 { - return nil - } - if err := syscall.Unmount(mountpoint, 0); err != nil { - logrus.Debugf("Failed to unmount %s overlay: %v", id, err) - } - return nil -} - -// ApplyDiff applies the new layer on top of the root, if parent does not exist with will return an ErrApplyDiffFallback error. -func (d *Driver) ApplyDiff(id string, parent string, diff io.Reader) (size int64, err error) { - dir := d.dir(id) - - if parent == "" { - return 0, ErrApplyDiffFallback - } - - parentRootDir := path.Join(d.dir(parent), "root") - if _, err := os.Stat(parentRootDir); err != nil { - return 0, ErrApplyDiffFallback - } - - // We now know there is a parent, and it has a "root" directory containing - // the full root filesystem. We can just hardlink it and apply the - // layer. This relies on two things: - // 1) ApplyDiff is only run once on a clean (no writes to upper layer) container - // 2) ApplyDiff doesn't do any in-place writes to files (would break hardlinks) - // These are all currently true and are not expected to break - - tmpRootDir, err := ioutil.TempDir(dir, "tmproot") - if err != nil { - return 0, err - } - defer func() { - if err != nil { - os.RemoveAll(tmpRootDir) - } else { - os.RemoveAll(path.Join(dir, "upper")) - os.RemoveAll(path.Join(dir, "work")) - os.RemoveAll(path.Join(dir, "merged")) - os.RemoveAll(path.Join(dir, "lower-id")) - } - }() - - if err = copyDir(parentRootDir, tmpRootDir, copyHardlink); err != nil { - return 0, err - } - - options := &archive.TarOptions{UIDMaps: d.uidMaps, GIDMaps: d.gidMaps} - if size, err = graphdriver.ApplyUncompressedLayer(tmpRootDir, diff, options); err != nil { - return 0, err - } - - rootDir := path.Join(dir, "root") - if err := os.Rename(tmpRootDir, rootDir); err != nil { - return 0, err - } - - return -} - -// Exists checks to see if the id is already mounted. -func (d *Driver) Exists(id string) bool { - _, err := os.Stat(d.dir(id)) - return err == nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlay/overlay_test.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlay/overlay_test.go deleted file mode 100644 index 34b6d80..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlay/overlay_test.go +++ /dev/null @@ -1,93 +0,0 @@ -// +build linux - -package overlay - -import ( - "testing" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/daemon/graphdriver/graphtest" - "github.com/docker/docker/pkg/archive" -) - -func init() { - // Do not sure chroot to speed run time and allow archive - // errors or hangs to be debugged directly from the test process. - graphdriver.ApplyUncompressedLayer = archive.ApplyUncompressedLayer -} - -// This avoids creating a new driver for each test if all tests are run -// Make sure to put new tests between TestOverlaySetup and TestOverlayTeardown -func TestOverlaySetup(t *testing.T) { - graphtest.GetDriver(t, "overlay") -} - -func TestOverlayCreateEmpty(t *testing.T) { - graphtest.DriverTestCreateEmpty(t, "overlay") -} - -func TestOverlayCreateBase(t *testing.T) { - graphtest.DriverTestCreateBase(t, "overlay") -} - -func TestOverlayCreateSnap(t *testing.T) { - graphtest.DriverTestCreateSnap(t, "overlay") -} - -func TestOverlay50LayerRead(t *testing.T) { - graphtest.DriverTestDeepLayerRead(t, 50, "overlay") -} - -// Fails due to bug in calculating changes after apply -// likely related to https://github.com/docker/docker/issues/21555 -func TestOverlayDiffApply10Files(t *testing.T) { - t.Skipf("Fails to compute changes after apply intermittently") - graphtest.DriverTestDiffApply(t, 10, "overlay") -} - -func TestOverlayChanges(t *testing.T) { - t.Skipf("Fails to compute changes intermittently") - graphtest.DriverTestChanges(t, "overlay") -} - -func TestOverlayTeardown(t *testing.T) { - graphtest.PutDriver(t) -} - -// Benchmarks should always setup new driver - -func BenchmarkExists(b *testing.B) { - graphtest.DriverBenchExists(b, "overlay") -} - -func BenchmarkGetEmpty(b *testing.B) { - graphtest.DriverBenchGetEmpty(b, "overlay") -} - -func BenchmarkDiffBase(b *testing.B) { - graphtest.DriverBenchDiffBase(b, "overlay") -} - -func BenchmarkDiffSmallUpper(b *testing.B) { - graphtest.DriverBenchDiffN(b, 10, 10, "overlay") -} - -func BenchmarkDiff10KFileUpper(b *testing.B) { - graphtest.DriverBenchDiffN(b, 10, 10000, "overlay") -} - -func BenchmarkDiff10KFilesBottom(b *testing.B) { - graphtest.DriverBenchDiffN(b, 10000, 10, "overlay") -} - -func BenchmarkDiffApply100(b *testing.B) { - graphtest.DriverBenchDiffApplyN(b, 100, "overlay") -} - -func BenchmarkDiff20Layers(b *testing.B) { - graphtest.DriverBenchDeepLayerDiff(b, 20, "overlay") -} - -func BenchmarkRead20Layers(b *testing.B) { - graphtest.DriverBenchDeepLayerRead(b, 20, "overlay") -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlay/overlay_unsupported.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlay/overlay_unsupported.go deleted file mode 100644 index 3dbb4de..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlay/overlay_unsupported.go +++ /dev/null @@ -1,3 +0,0 @@ -// +build !linux - -package overlay diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/check.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/check.go deleted file mode 100644 index 53a7199..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/check.go +++ /dev/null @@ -1,79 +0,0 @@ -// +build linux - -package overlay2 - -import ( - "fmt" - "io/ioutil" - "os" - "path" - "path/filepath" - "syscall" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/system" - "github.com/pkg/errors" -) - -// hasOpaqueCopyUpBug checks whether the filesystem has a bug -// which copies up the opaque flag when copying up an opaque -// directory. When this bug exists naive diff should be used. -func hasOpaqueCopyUpBug(d string) error { - td, err := ioutil.TempDir(d, "opaque-bug-check") - if err != nil { - return err - } - defer func() { - if err := os.RemoveAll(td); err != nil { - logrus.Warnf("Failed to remove check directory %v: %v", td, err) - } - }() - - // Make directories l1/d, l2/d, l3, work, merged - if err := os.MkdirAll(filepath.Join(td, "l1", "d"), 0755); err != nil { - return err - } - if err := os.MkdirAll(filepath.Join(td, "l2", "d"), 0755); err != nil { - return err - } - if err := os.Mkdir(filepath.Join(td, "l3"), 0755); err != nil { - return err - } - if err := os.Mkdir(filepath.Join(td, "work"), 0755); err != nil { - return err - } - if err := os.Mkdir(filepath.Join(td, "merged"), 0755); err != nil { - return err - } - - // Mark l2/d as opaque - if err := system.Lsetxattr(filepath.Join(td, "l2", "d"), "trusted.overlay.opaque", []byte("y"), 0); err != nil { - return errors.Wrap(err, "failed to set opaque flag on middle layer") - } - - opts := fmt.Sprintf("lowerdir=%s:%s,upperdir=%s,workdir=%s", path.Join(td, "l2"), path.Join(td, "l1"), path.Join(td, "l3"), path.Join(td, "work")) - if err := syscall.Mount("overlay", filepath.Join(td, "merged"), "overlay", 0, opts); err != nil { - return errors.Wrap(err, "failed to mount overlay") - } - defer func() { - if err := syscall.Unmount(filepath.Join(td, "merged"), 0); err != nil { - logrus.Warnf("Failed to unmount check directory %v: %v", filepath.Join(td, "merged"), err) - } - }() - - // Touch file in d to force copy up of opaque directory "d" from "l2" to "l3" - if err := ioutil.WriteFile(filepath.Join(td, "merged", "d", "f"), []byte{}, 0644); err != nil { - return errors.Wrap(err, "failed to write to merged directory") - } - - // Check l3/d does not have opaque flag - xattrOpaque, err := system.Lgetxattr(filepath.Join(td, "l3", "d"), "trusted.overlay.opaque") - if err != nil { - return errors.Wrap(err, "failed to read opaque flag on upper layer") - } - if string(xattrOpaque) == "y" { - return errors.New("opaque flag erroneously copied up, consider update to kernel 4.8 or later to fix") - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/mount.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/mount.go deleted file mode 100644 index 60e248b..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/mount.go +++ /dev/null @@ -1,88 +0,0 @@ -// +build linux - -package overlay2 - -import ( - "bytes" - "encoding/json" - "flag" - "fmt" - "os" - "runtime" - "syscall" - - "github.com/docker/docker/pkg/reexec" -) - -func init() { - reexec.Register("docker-mountfrom", mountFromMain) -} - -func fatal(err error) { - fmt.Fprint(os.Stderr, err) - os.Exit(1) -} - -type mountOptions struct { - Device string - Target string - Type string - Label string - Flag uint32 -} - -func mountFrom(dir, device, target, mType string, flags uintptr, label string) error { - options := &mountOptions{ - Device: device, - Target: target, - Type: mType, - Flag: uint32(flags), - Label: label, - } - - cmd := reexec.Command("docker-mountfrom", dir) - w, err := cmd.StdinPipe() - if err != nil { - return fmt.Errorf("mountfrom error on pipe creation: %v", err) - } - - output := bytes.NewBuffer(nil) - cmd.Stdout = output - cmd.Stderr = output - - if err := cmd.Start(); err != nil { - return fmt.Errorf("mountfrom error on re-exec cmd: %v", err) - } - //write the options to the pipe for the untar exec to read - if err := json.NewEncoder(w).Encode(options); err != nil { - return fmt.Errorf("mountfrom json encode to pipe failed: %v", err) - } - w.Close() - - if err := cmd.Wait(); err != nil { - return fmt.Errorf("mountfrom re-exec error: %v: output: %s", err, output) - } - return nil -} - -// mountfromMain is the entry-point for docker-mountfrom on re-exec. -func mountFromMain() { - runtime.LockOSThread() - flag.Parse() - - var options *mountOptions - - if err := json.NewDecoder(os.Stdin).Decode(&options); err != nil { - fatal(err) - } - - if err := os.Chdir(flag.Arg(0)); err != nil { - fatal(err) - } - - if err := syscall.Mount(options.Device, options.Target, options.Type, uintptr(options.Flag), options.Label); err != nil { - fatal(err) - } - - os.Exit(0) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/overlay.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/overlay.go deleted file mode 100644 index 65ac6bf..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/overlay.go +++ /dev/null @@ -1,662 +0,0 @@ -// +build linux - -package overlay2 - -import ( - "bufio" - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "os/exec" - "path" - "path/filepath" - "strconv" - "strings" - "sync" - "syscall" - - "github.com/Sirupsen/logrus" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/daemon/graphdriver/overlayutils" - "github.com/docker/docker/daemon/graphdriver/quota" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/chrootarchive" - "github.com/docker/docker/pkg/directory" - "github.com/docker/docker/pkg/fsutils" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/parsers" - "github.com/docker/docker/pkg/parsers/kernel" - "github.com/docker/go-units" - - "github.com/opencontainers/runc/libcontainer/label" -) - -var ( - // untar defines the untar method - untar = chrootarchive.UntarUncompressed -) - -// This backend uses the overlay union filesystem for containers -// with diff directories for each layer. - -// This version of the overlay driver requires at least kernel -// 4.0.0 in order to support mounting multiple diff directories. - -// Each container/image has at least a "diff" directory and "link" file. -// If there is also a "lower" file when there are diff layers -// below as well as "merged" and "work" directories. The "diff" directory -// has the upper layer of the overlay and is used to capture any -// changes to the layer. The "lower" file contains all the lower layer -// mounts separated by ":" and ordered from uppermost to lowermost -// layers. The overlay itself is mounted in the "merged" directory, -// and the "work" dir is needed for overlay to work. - -// The "link" file for each layer contains a unique string for the layer. -// Under the "l" directory at the root there will be a symbolic link -// with that unique string pointing the "diff" directory for the layer. -// The symbolic links are used to reference lower layers in the "lower" -// file and on mount. The links are used to shorten the total length -// of a layer reference without requiring changes to the layer identifier -// or root directory. Mounts are always done relative to root and -// referencing the symbolic links in order to ensure the number of -// lower directories can fit in a single page for making the mount -// syscall. A hard upper limit of 128 lower layers is enforced to ensure -// that mounts do not fail due to length. - -const ( - driverName = "overlay2" - linkDir = "l" - lowerFile = "lower" - maxDepth = 128 - - // idLength represents the number of random characters - // which can be used to create the unique link identifer - // for every layer. If this value is too long then the - // page size limit for the mount command may be exceeded. - // The idLength should be selected such that following equation - // is true (512 is a buffer for label metadata). - // ((idLength + len(linkDir) + 1) * maxDepth) <= (pageSize - 512) - idLength = 26 -) - -type overlayOptions struct { - overrideKernelCheck bool - quota quota.Quota -} - -// Driver contains information about the home directory and the list of active mounts that are created using this driver. -type Driver struct { - home string - uidMaps []idtools.IDMap - gidMaps []idtools.IDMap - ctr *graphdriver.RefCounter - quotaCtl *quota.Control - options overlayOptions - naiveDiff graphdriver.DiffDriver - supportsDType bool -} - -var ( - backingFs = "" - projectQuotaSupported = false - - useNaiveDiffLock sync.Once - useNaiveDiffOnly bool -) - -func init() { - graphdriver.Register(driverName, Init) -} - -// Init returns the a native diff driver for overlay filesystem. -// If overlay filesystem is not supported on the host, graphdriver.ErrNotSupported is returned as error. -// If an overlay filesystem is not supported over an existing filesystem then error graphdriver.ErrIncompatibleFS is returned. -func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - opts, err := parseOptions(options) - if err != nil { - return nil, err - } - - if err := supportsOverlay(); err != nil { - return nil, graphdriver.ErrNotSupported - } - - // require kernel 4.0.0 to ensure multiple lower dirs are supported - v, err := kernel.GetKernelVersion() - if err != nil { - return nil, err - } - if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: 4, Major: 0, Minor: 0}) < 0 { - if !opts.overrideKernelCheck { - return nil, graphdriver.ErrNotSupported - } - logrus.Warn("Using pre-4.0.0 kernel for overlay2, mount failures may require kernel update") - } - - fsMagic, err := graphdriver.GetFSMagic(home) - if err != nil { - return nil, err - } - if fsName, ok := graphdriver.FsNames[fsMagic]; ok { - backingFs = fsName - } - - // check if they are running over btrfs, aufs, zfs, overlay, or ecryptfs - switch fsMagic { - case graphdriver.FsMagicBtrfs, graphdriver.FsMagicAufs, graphdriver.FsMagicZfs, graphdriver.FsMagicOverlay, graphdriver.FsMagicEcryptfs: - logrus.Errorf("'overlay2' is not supported over %s", backingFs) - return nil, graphdriver.ErrIncompatibleFS - } - - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) - if err != nil { - return nil, err - } - // Create the driver home dir - if err := idtools.MkdirAllAs(path.Join(home, linkDir), 0700, rootUID, rootGID); err != nil && !os.IsExist(err) { - return nil, err - } - - if err := mount.MakePrivate(home); err != nil { - return nil, err - } - - supportsDType, err := fsutils.SupportsDType(home) - if err != nil { - return nil, err - } - if !supportsDType { - // not a fatal error until v1.16 (#27443) - logrus.Warn(overlayutils.ErrDTypeNotSupported("overlay2", backingFs)) - } - - d := &Driver{ - home: home, - uidMaps: uidMaps, - gidMaps: gidMaps, - ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicOverlay)), - supportsDType: supportsDType, - } - - d.naiveDiff = graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps) - - if backingFs == "xfs" { - // Try to enable project quota support over xfs. - if d.quotaCtl, err = quota.NewControl(home); err == nil { - projectQuotaSupported = true - } - } - - logrus.Debugf("backingFs=%s, projectQuotaSupported=%v", backingFs, projectQuotaSupported) - - return d, nil -} - -func parseOptions(options []string) (*overlayOptions, error) { - o := &overlayOptions{} - for _, option := range options { - key, val, err := parsers.ParseKeyValueOpt(option) - if err != nil { - return nil, err - } - key = strings.ToLower(key) - switch key { - case "overlay2.override_kernel_check": - o.overrideKernelCheck, err = strconv.ParseBool(val) - if err != nil { - return nil, err - } - - default: - return nil, fmt.Errorf("overlay2: Unknown option %s\n", key) - } - } - return o, nil -} - -func supportsOverlay() error { - // We can try to modprobe overlay first before looking at - // proc/filesystems for when overlay is supported - exec.Command("modprobe", "overlay").Run() - - f, err := os.Open("/proc/filesystems") - if err != nil { - return err - } - defer f.Close() - - s := bufio.NewScanner(f) - for s.Scan() { - if s.Text() == "nodev\toverlay" { - return nil - } - } - logrus.Error("'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support loaded.") - return graphdriver.ErrNotSupported -} - -func useNaiveDiff(home string) bool { - useNaiveDiffLock.Do(func() { - if err := hasOpaqueCopyUpBug(home); err != nil { - logrus.Warnf("Not using native diff for overlay2: %v", err) - useNaiveDiffOnly = true - } - }) - return useNaiveDiffOnly -} - -func (d *Driver) String() string { - return driverName -} - -// Status returns current driver information in a two dimensional string array. -// Output contains "Backing Filesystem" used in this implementation. -func (d *Driver) Status() [][2]string { - return [][2]string{ - {"Backing Filesystem", backingFs}, - {"Supports d_type", strconv.FormatBool(d.supportsDType)}, - {"Native Overlay Diff", strconv.FormatBool(!useNaiveDiff(d.home))}, - } -} - -// GetMetadata returns meta data about the overlay driver such as -// LowerDir, UpperDir, WorkDir and MergeDir used to store data. -func (d *Driver) GetMetadata(id string) (map[string]string, error) { - dir := d.dir(id) - if _, err := os.Stat(dir); err != nil { - return nil, err - } - - metadata := map[string]string{ - "WorkDir": path.Join(dir, "work"), - "MergedDir": path.Join(dir, "merged"), - "UpperDir": path.Join(dir, "diff"), - } - - lowerDirs, err := d.getLowerDirs(id) - if err != nil { - return nil, err - } - if len(lowerDirs) > 0 { - metadata["LowerDir"] = strings.Join(lowerDirs, ":") - } - - return metadata, nil -} - -// Cleanup any state created by overlay which should be cleaned when daemon -// is being shutdown. For now, we just have to unmount the bind mounted -// we had created. -func (d *Driver) Cleanup() error { - return mount.Unmount(d.home) -} - -// CreateReadWrite creates a layer that is writable for use as a container -// file system. -func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error { - return d.Create(id, parent, opts) -} - -// Create is used to create the upper, lower, and merge directories required for overlay fs for a given id. -// The parent filesystem is used to configure these directories for the overlay. -func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) (retErr error) { - - if opts != nil && len(opts.StorageOpt) != 0 && !projectQuotaSupported { - return fmt.Errorf("--storage-opt is supported only for overlay over xfs with 'pquota' mount option") - } - - dir := d.dir(id) - - rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps) - if err != nil { - return err - } - if err := idtools.MkdirAllAs(path.Dir(dir), 0700, rootUID, rootGID); err != nil { - return err - } - if err := idtools.MkdirAs(dir, 0700, rootUID, rootGID); err != nil { - return err - } - - defer func() { - // Clean up on failure - if retErr != nil { - os.RemoveAll(dir) - } - }() - - if opts != nil && len(opts.StorageOpt) > 0 { - driver := &Driver{} - if err := d.parseStorageOpt(opts.StorageOpt, driver); err != nil { - return err - } - - if driver.options.quota.Size > 0 { - // Set container disk quota limit - if err := d.quotaCtl.SetQuota(dir, driver.options.quota); err != nil { - return err - } - } - } - - if err := idtools.MkdirAs(path.Join(dir, "diff"), 0755, rootUID, rootGID); err != nil { - return err - } - - lid := generateID(idLength) - if err := os.Symlink(path.Join("..", id, "diff"), path.Join(d.home, linkDir, lid)); err != nil { - return err - } - - // Write link id to link file - if err := ioutil.WriteFile(path.Join(dir, "link"), []byte(lid), 0644); err != nil { - return err - } - - // if no parent directory, done - if parent == "" { - return nil - } - - if err := idtools.MkdirAs(path.Join(dir, "work"), 0700, rootUID, rootGID); err != nil { - return err - } - if err := idtools.MkdirAs(path.Join(dir, "merged"), 0700, rootUID, rootGID); err != nil { - return err - } - - lower, err := d.getLower(parent) - if err != nil { - return err - } - if lower != "" { - if err := ioutil.WriteFile(path.Join(dir, lowerFile), []byte(lower), 0666); err != nil { - return err - } - } - - return nil -} - -// Parse overlay storage options -func (d *Driver) parseStorageOpt(storageOpt map[string]string, driver *Driver) error { - // Read size to set the disk project quota per container - for key, val := range storageOpt { - key := strings.ToLower(key) - switch key { - case "size": - size, err := units.RAMInBytes(val) - if err != nil { - return err - } - driver.options.quota.Size = uint64(size) - default: - return fmt.Errorf("Unknown option %s", key) - } - } - - return nil -} - -func (d *Driver) getLower(parent string) (string, error) { - parentDir := d.dir(parent) - - // Ensure parent exists - if _, err := os.Lstat(parentDir); err != nil { - return "", err - } - - // Read Parent link fileA - parentLink, err := ioutil.ReadFile(path.Join(parentDir, "link")) - if err != nil { - return "", err - } - lowers := []string{path.Join(linkDir, string(parentLink))} - - parentLower, err := ioutil.ReadFile(path.Join(parentDir, lowerFile)) - if err == nil { - parentLowers := strings.Split(string(parentLower), ":") - lowers = append(lowers, parentLowers...) - } - if len(lowers) > maxDepth { - return "", errors.New("max depth exceeded") - } - return strings.Join(lowers, ":"), nil -} - -func (d *Driver) dir(id string) string { - return path.Join(d.home, id) -} - -func (d *Driver) getLowerDirs(id string) ([]string, error) { - var lowersArray []string - lowers, err := ioutil.ReadFile(path.Join(d.dir(id), lowerFile)) - if err == nil { - for _, s := range strings.Split(string(lowers), ":") { - lp, err := os.Readlink(path.Join(d.home, s)) - if err != nil { - return nil, err - } - lowersArray = append(lowersArray, path.Clean(path.Join(d.home, linkDir, lp))) - } - } else if !os.IsNotExist(err) { - return nil, err - } - return lowersArray, nil -} - -// Remove cleans the directories that are created for this id. -func (d *Driver) Remove(id string) error { - dir := d.dir(id) - lid, err := ioutil.ReadFile(path.Join(dir, "link")) - if err == nil { - if err := os.RemoveAll(path.Join(d.home, linkDir, string(lid))); err != nil { - logrus.Debugf("Failed to remove link: %v", err) - } - } - - if err := os.RemoveAll(dir); err != nil && !os.IsNotExist(err) { - return err - } - return nil -} - -// Get creates and mounts the required file system for the given id and returns the mount path. -func (d *Driver) Get(id string, mountLabel string) (s string, err error) { - dir := d.dir(id) - if _, err := os.Stat(dir); err != nil { - return "", err - } - - diffDir := path.Join(dir, "diff") - lowers, err := ioutil.ReadFile(path.Join(dir, lowerFile)) - if err != nil { - // If no lower, just return diff directory - if os.IsNotExist(err) { - return diffDir, nil - } - return "", err - } - - mergedDir := path.Join(dir, "merged") - if count := d.ctr.Increment(mergedDir); count > 1 { - return mergedDir, nil - } - defer func() { - if err != nil { - if c := d.ctr.Decrement(mergedDir); c <= 0 { - syscall.Unmount(mergedDir, 0) - } - } - }() - - workDir := path.Join(dir, "work") - splitLowers := strings.Split(string(lowers), ":") - absLowers := make([]string, len(splitLowers)) - for i, s := range splitLowers { - absLowers[i] = path.Join(d.home, s) - } - opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", strings.Join(absLowers, ":"), path.Join(dir, "diff"), path.Join(dir, "work")) - mountData := label.FormatMountLabel(opts, mountLabel) - mount := syscall.Mount - mountTarget := mergedDir - - pageSize := syscall.Getpagesize() - - // Go can return a larger page size than supported by the system - // as of go 1.7. This will be fixed in 1.8 and this block can be - // removed when building with 1.8. - // See https://github.com/golang/go/commit/1b9499b06989d2831e5b156161d6c07642926ee1 - // See https://github.com/docker/docker/issues/27384 - if pageSize > 4096 { - pageSize = 4096 - } - - // Use relative paths and mountFrom when the mount data has exceeded - // the page size. The mount syscall fails if the mount data cannot - // fit within a page and relative links make the mount data much - // smaller at the expense of requiring a fork exec to chroot. - if len(mountData) > pageSize { - opts = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", string(lowers), path.Join(id, "diff"), path.Join(id, "work")) - mountData = label.FormatMountLabel(opts, mountLabel) - if len(mountData) > pageSize { - return "", fmt.Errorf("cannot mount layer, mount label too large %d", len(mountData)) - } - - mount = func(source string, target string, mType string, flags uintptr, label string) error { - return mountFrom(d.home, source, target, mType, flags, label) - } - mountTarget = path.Join(id, "merged") - } - - if err := mount("overlay", mountTarget, "overlay", 0, mountData); err != nil { - return "", fmt.Errorf("error creating overlay mount to %s: %v", mergedDir, err) - } - - // chown "workdir/work" to the remapped root UID/GID. Overlay fs inside a - // user namespace requires this to move a directory from lower to upper. - rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps) - if err != nil { - return "", err - } - - if err := os.Chown(path.Join(workDir, "work"), rootUID, rootGID); err != nil { - return "", err - } - - return mergedDir, nil -} - -// Put unmounts the mount path created for the give id. -func (d *Driver) Put(id string) error { - mountpoint := path.Join(d.dir(id), "merged") - if count := d.ctr.Decrement(mountpoint); count > 0 { - return nil - } - if err := syscall.Unmount(mountpoint, 0); err != nil { - logrus.Debugf("Failed to unmount %s overlay: %s - %v", id, mountpoint, err) - } - return nil -} - -// Exists checks to see if the id is already mounted. -func (d *Driver) Exists(id string) bool { - _, err := os.Stat(d.dir(id)) - return err == nil -} - -// isParent returns if the passed in parent is the direct parent of the passed in layer -func (d *Driver) isParent(id, parent string) bool { - lowers, err := d.getLowerDirs(id) - if err != nil { - return false - } - if parent == "" && len(lowers) > 0 { - return false - } - - parentDir := d.dir(parent) - var ld string - if len(lowers) > 0 { - ld = filepath.Dir(lowers[0]) - } - if ld == "" && parent == "" { - return true - } - return ld == parentDir -} - -// ApplyDiff applies the new layer into a root -func (d *Driver) ApplyDiff(id string, parent string, diff io.Reader) (size int64, err error) { - if !d.isParent(id, parent) { - return d.naiveDiff.ApplyDiff(id, parent, diff) - } - - applyDir := d.getDiffPath(id) - - logrus.Debugf("Applying tar in %s", applyDir) - // Overlay doesn't need the parent id to apply the diff - if err := untar(diff, applyDir, &archive.TarOptions{ - UIDMaps: d.uidMaps, - GIDMaps: d.gidMaps, - WhiteoutFormat: archive.OverlayWhiteoutFormat, - }); err != nil { - return 0, err - } - - return directory.Size(applyDir) -} - -func (d *Driver) getDiffPath(id string) string { - dir := d.dir(id) - - return path.Join(dir, "diff") -} - -// DiffSize calculates the changes between the specified id -// and its parent and returns the size in bytes of the changes -// relative to its base filesystem directory. -func (d *Driver) DiffSize(id, parent string) (size int64, err error) { - if useNaiveDiff(d.home) || !d.isParent(id, parent) { - return d.naiveDiff.DiffSize(id, parent) - } - return directory.Size(d.getDiffPath(id)) -} - -// Diff produces an archive of the changes between the specified -// layer and its parent layer which may be "". -func (d *Driver) Diff(id, parent string) (io.ReadCloser, error) { - if useNaiveDiff(d.home) || !d.isParent(id, parent) { - return d.naiveDiff.Diff(id, parent) - } - - diffPath := d.getDiffPath(id) - logrus.Debugf("Tar with options on %s", diffPath) - return archive.TarWithOptions(diffPath, &archive.TarOptions{ - Compression: archive.Uncompressed, - UIDMaps: d.uidMaps, - GIDMaps: d.gidMaps, - WhiteoutFormat: archive.OverlayWhiteoutFormat, - }) -} - -// Changes produces a list of changes between the specified layer -// and its parent layer. If parent is "", then all changes will be ADD changes. -func (d *Driver) Changes(id, parent string) ([]archive.Change, error) { - if useNaiveDiff(d.home) || !d.isParent(id, parent) { - return d.naiveDiff.Changes(id, parent) - } - // Overlay doesn't have snapshots, so we need to get changes from all parent - // layers. - diffPath := d.getDiffPath(id) - layers, err := d.getLowerDirs(id) - if err != nil { - return nil, err - } - - return archive.OverlayChanges(layers, diffPath) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/overlay_test.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/overlay_test.go deleted file mode 100644 index cf77ff2..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/overlay_test.go +++ /dev/null @@ -1,121 +0,0 @@ -// +build linux - -package overlay2 - -import ( - "io/ioutil" - "os" - "syscall" - "testing" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/daemon/graphdriver/graphtest" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/reexec" -) - -func init() { - // Do not sure chroot to speed run time and allow archive - // errors or hangs to be debugged directly from the test process. - untar = archive.UntarUncompressed - graphdriver.ApplyUncompressedLayer = archive.ApplyUncompressedLayer - - reexec.Init() -} - -func cdMountFrom(dir, device, target, mType, label string) error { - wd, err := os.Getwd() - if err != nil { - return err - } - os.Chdir(dir) - defer os.Chdir(wd) - - return syscall.Mount(device, target, mType, 0, label) -} - -func skipIfNaive(t *testing.T) { - td, err := ioutil.TempDir("", "naive-check-") - if err != nil { - t.Fatalf("Failed to create temp dir: %v", err) - } - defer os.RemoveAll(td) - - if useNaiveDiff(td) { - t.Skipf("Cannot run test with naive diff") - } -} - -// This avoids creating a new driver for each test if all tests are run -// Make sure to put new tests between TestOverlaySetup and TestOverlayTeardown -func TestOverlaySetup(t *testing.T) { - graphtest.GetDriver(t, driverName) -} - -func TestOverlayCreateEmpty(t *testing.T) { - graphtest.DriverTestCreateEmpty(t, driverName) -} - -func TestOverlayCreateBase(t *testing.T) { - graphtest.DriverTestCreateBase(t, driverName) -} - -func TestOverlayCreateSnap(t *testing.T) { - graphtest.DriverTestCreateSnap(t, driverName) -} - -func TestOverlay128LayerRead(t *testing.T) { - graphtest.DriverTestDeepLayerRead(t, 128, driverName) -} - -func TestOverlayDiffApply10Files(t *testing.T) { - skipIfNaive(t) - graphtest.DriverTestDiffApply(t, 10, driverName) -} - -func TestOverlayChanges(t *testing.T) { - skipIfNaive(t) - graphtest.DriverTestChanges(t, driverName) -} - -func TestOverlayTeardown(t *testing.T) { - graphtest.PutDriver(t) -} - -// Benchmarks should always setup new driver - -func BenchmarkExists(b *testing.B) { - graphtest.DriverBenchExists(b, driverName) -} - -func BenchmarkGetEmpty(b *testing.B) { - graphtest.DriverBenchGetEmpty(b, driverName) -} - -func BenchmarkDiffBase(b *testing.B) { - graphtest.DriverBenchDiffBase(b, driverName) -} - -func BenchmarkDiffSmallUpper(b *testing.B) { - graphtest.DriverBenchDiffN(b, 10, 10, driverName) -} - -func BenchmarkDiff10KFileUpper(b *testing.B) { - graphtest.DriverBenchDiffN(b, 10, 10000, driverName) -} - -func BenchmarkDiff10KFilesBottom(b *testing.B) { - graphtest.DriverBenchDiffN(b, 10000, 10, driverName) -} - -func BenchmarkDiffApply100(b *testing.B) { - graphtest.DriverBenchDiffApplyN(b, 100, driverName) -} - -func BenchmarkDiff20Layers(b *testing.B) { - graphtest.DriverBenchDeepLayerDiff(b, 20, driverName) -} - -func BenchmarkRead20Layers(b *testing.B) { - graphtest.DriverBenchDeepLayerRead(b, 20, driverName) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/overlay_unsupported.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/overlay_unsupported.go deleted file mode 100644 index e5ac4ca..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/overlay_unsupported.go +++ /dev/null @@ -1,3 +0,0 @@ -// +build !linux - -package overlay2 diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/randomid.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/randomid.go deleted file mode 100644 index af5cb65..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlay2/randomid.go +++ /dev/null @@ -1,80 +0,0 @@ -// +build linux - -package overlay2 - -import ( - "crypto/rand" - "encoding/base32" - "fmt" - "io" - "os" - "syscall" - "time" - - "github.com/Sirupsen/logrus" -) - -// generateID creates a new random string identifier with the given length -func generateID(l int) string { - const ( - // ensures we backoff for less than 450ms total. Use the following to - // select new value, in units of 10ms: - // n*(n+1)/2 = d -> n^2 + n - 2d -> n = (sqrt(8d + 1) - 1)/2 - maxretries = 9 - backoff = time.Millisecond * 10 - ) - - var ( - totalBackoff time.Duration - count int - retries int - size = (l*5 + 7) / 8 - u = make([]byte, size) - ) - // TODO: Include time component, counter component, random component - - for { - // This should never block but the read may fail. Because of this, - // we just try to read the random number generator until we get - // something. This is a very rare condition but may happen. - b := time.Duration(retries) * backoff - time.Sleep(b) - totalBackoff += b - - n, err := io.ReadFull(rand.Reader, u[count:]) - if err != nil { - if retryOnError(err) && retries < maxretries { - count += n - retries++ - logrus.Errorf("error generating version 4 uuid, retrying: %v", err) - continue - } - - // Any other errors represent a system problem. What did someone - // do to /dev/urandom? - panic(fmt.Errorf("error reading random number generator, retried for %v: %v", totalBackoff.String(), err)) - } - - break - } - - s := base32.StdEncoding.EncodeToString(u) - - return s[:l] -} - -// retryOnError tries to detect whether or not retrying would be fruitful. -func retryOnError(err error) bool { - switch err := err.(type) { - case *os.PathError: - return retryOnError(err.Err) // unpack the target error - case syscall.Errno: - if err == syscall.EPERM { - // EPERM represents an entropy pool exhaustion, a condition under - // which we backoff and retry. - return true - } - } - - return false -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/overlayutils/overlayutils.go b/vendor/github.com/docker/docker/daemon/graphdriver/overlayutils/overlayutils.go deleted file mode 100644 index 67c6640..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/overlayutils/overlayutils.go +++ /dev/null @@ -1,18 +0,0 @@ -// +build linux - -package overlayutils - -import ( - "errors" - "fmt" -) - -// ErrDTypeNotSupported denotes that the backing filesystem doesn't support d_type. -func ErrDTypeNotSupported(driver, backingFs string) error { - msg := fmt.Sprintf("%s: the backing %s filesystem is formatted without d_type support, which leads to incorrect behavior.", driver, backingFs) - if backingFs == "xfs" { - msg += " Reformat the filesystem with ftype=1 to enable d_type support." - } - msg += " Running without d_type support will no longer be supported in Docker 1.16." - return errors.New(msg) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/plugin.go b/vendor/github.com/docker/docker/daemon/graphdriver/plugin.go deleted file mode 100644 index 7294bcc..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/plugin.go +++ /dev/null @@ -1,43 +0,0 @@ -package graphdriver - -import ( - "fmt" - "io" - "path/filepath" - - "github.com/docker/docker/pkg/plugingetter" - "github.com/docker/docker/plugin/v2" -) - -type pluginClient interface { - // Call calls the specified method with the specified arguments for the plugin. - Call(string, interface{}, interface{}) error - // Stream calls the specified method with the specified arguments for the plugin and returns the response IO stream - Stream(string, interface{}) (io.ReadCloser, error) - // SendFile calls the specified method, and passes through the IO stream - SendFile(string, io.Reader, interface{}) error -} - -func lookupPlugin(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) { - if !config.ExperimentalEnabled { - return nil, fmt.Errorf("graphdriver plugins are only supported with experimental mode") - } - pl, err := pg.Get(name, "GraphDriver", plugingetter.ACQUIRE) - if err != nil { - return nil, fmt.Errorf("Error looking up graphdriver plugin %s: %v", name, err) - } - return newPluginDriver(name, pl, config) -} - -func newPluginDriver(name string, pl plugingetter.CompatPlugin, config Options) (Driver, error) { - home := config.Root - if !pl.IsV1() { - if p, ok := pl.(*v2.Plugin); ok { - if p.PropagatedMount != "" { - home = p.PluginObj.Config.PropagatedMount - } - } - } - proxy := &graphDriverProxy{name, pl} - return proxy, proxy.Init(filepath.Join(home, name), config.DriverOptions, config.UIDMaps, config.GIDMaps) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/proxy.go b/vendor/github.com/docker/docker/daemon/graphdriver/proxy.go deleted file mode 100644 index bfe74cc..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/proxy.go +++ /dev/null @@ -1,252 +0,0 @@ -package graphdriver - -import ( - "errors" - "fmt" - "io" - "path/filepath" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/plugingetter" -) - -type graphDriverProxy struct { - name string - p plugingetter.CompatPlugin -} - -type graphDriverRequest struct { - ID string `json:",omitempty"` - Parent string `json:",omitempty"` - MountLabel string `json:",omitempty"` - StorageOpt map[string]string `json:",omitempty"` -} - -type graphDriverResponse struct { - Err string `json:",omitempty"` - Dir string `json:",omitempty"` - Exists bool `json:",omitempty"` - Status [][2]string `json:",omitempty"` - Changes []archive.Change `json:",omitempty"` - Size int64 `json:",omitempty"` - Metadata map[string]string `json:",omitempty"` -} - -type graphDriverInitRequest struct { - Home string - Opts []string `json:"Opts"` - UIDMaps []idtools.IDMap `json:"UIDMaps"` - GIDMaps []idtools.IDMap `json:"GIDMaps"` -} - -func (d *graphDriverProxy) Init(home string, opts []string, uidMaps, gidMaps []idtools.IDMap) error { - if !d.p.IsV1() { - if cp, ok := d.p.(plugingetter.CountedPlugin); ok { - // always acquire here, it will be cleaned up on daemon shutdown - cp.Acquire() - } - } - args := &graphDriverInitRequest{ - Home: home, - Opts: opts, - UIDMaps: uidMaps, - GIDMaps: gidMaps, - } - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.Init", args, &ret); err != nil { - return err - } - if ret.Err != "" { - return errors.New(ret.Err) - } - return nil -} - -func (d *graphDriverProxy) String() string { - return d.name -} - -func (d *graphDriverProxy) CreateReadWrite(id, parent string, opts *CreateOpts) error { - args := &graphDriverRequest{ - ID: id, - Parent: parent, - } - if opts != nil { - args.MountLabel = opts.MountLabel - args.StorageOpt = opts.StorageOpt - } - - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.CreateReadWrite", args, &ret); err != nil { - return err - } - if ret.Err != "" { - return errors.New(ret.Err) - } - return nil -} - -func (d *graphDriverProxy) Create(id, parent string, opts *CreateOpts) error { - args := &graphDriverRequest{ - ID: id, - Parent: parent, - } - if opts != nil { - args.MountLabel = opts.MountLabel - args.StorageOpt = opts.StorageOpt - } - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.Create", args, &ret); err != nil { - return err - } - if ret.Err != "" { - return errors.New(ret.Err) - } - return nil -} - -func (d *graphDriverProxy) Remove(id string) error { - args := &graphDriverRequest{ID: id} - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.Remove", args, &ret); err != nil { - return err - } - if ret.Err != "" { - return errors.New(ret.Err) - } - return nil -} - -func (d *graphDriverProxy) Get(id, mountLabel string) (string, error) { - args := &graphDriverRequest{ - ID: id, - MountLabel: mountLabel, - } - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.Get", args, &ret); err != nil { - return "", err - } - var err error - if ret.Err != "" { - err = errors.New(ret.Err) - } - return filepath.Join(d.p.BasePath(), ret.Dir), err -} - -func (d *graphDriverProxy) Put(id string) error { - args := &graphDriverRequest{ID: id} - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.Put", args, &ret); err != nil { - return err - } - if ret.Err != "" { - return errors.New(ret.Err) - } - return nil -} - -func (d *graphDriverProxy) Exists(id string) bool { - args := &graphDriverRequest{ID: id} - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.Exists", args, &ret); err != nil { - return false - } - return ret.Exists -} - -func (d *graphDriverProxy) Status() [][2]string { - args := &graphDriverRequest{} - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.Status", args, &ret); err != nil { - return nil - } - return ret.Status -} - -func (d *graphDriverProxy) GetMetadata(id string) (map[string]string, error) { - args := &graphDriverRequest{ - ID: id, - } - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.GetMetadata", args, &ret); err != nil { - return nil, err - } - if ret.Err != "" { - return nil, errors.New(ret.Err) - } - return ret.Metadata, nil -} - -func (d *graphDriverProxy) Cleanup() error { - if !d.p.IsV1() { - if cp, ok := d.p.(plugingetter.CountedPlugin); ok { - // always release - defer cp.Release() - } - } - - args := &graphDriverRequest{} - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.Cleanup", args, &ret); err != nil { - return nil - } - if ret.Err != "" { - return errors.New(ret.Err) - } - return nil -} - -func (d *graphDriverProxy) Diff(id, parent string) (io.ReadCloser, error) { - args := &graphDriverRequest{ - ID: id, - Parent: parent, - } - body, err := d.p.Client().Stream("GraphDriver.Diff", args) - if err != nil { - return nil, err - } - return body, nil -} - -func (d *graphDriverProxy) Changes(id, parent string) ([]archive.Change, error) { - args := &graphDriverRequest{ - ID: id, - Parent: parent, - } - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.Changes", args, &ret); err != nil { - return nil, err - } - if ret.Err != "" { - return nil, errors.New(ret.Err) - } - - return ret.Changes, nil -} - -func (d *graphDriverProxy) ApplyDiff(id, parent string, diff io.Reader) (int64, error) { - var ret graphDriverResponse - if err := d.p.Client().SendFile(fmt.Sprintf("GraphDriver.ApplyDiff?id=%s&parent=%s", id, parent), diff, &ret); err != nil { - return -1, err - } - if ret.Err != "" { - return -1, errors.New(ret.Err) - } - return ret.Size, nil -} - -func (d *graphDriverProxy) DiffSize(id, parent string) (int64, error) { - args := &graphDriverRequest{ - ID: id, - Parent: parent, - } - var ret graphDriverResponse - if err := d.p.Client().Call("GraphDriver.DiffSize", args, &ret); err != nil { - return -1, err - } - if ret.Err != "" { - return -1, errors.New(ret.Err) - } - return ret.Size, nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/quota/projectquota.go b/vendor/github.com/docker/docker/daemon/graphdriver/quota/projectquota.go deleted file mode 100644 index e408d5f..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/quota/projectquota.go +++ /dev/null @@ -1,339 +0,0 @@ -// +build linux - -// -// projectquota.go - implements XFS project quota controls -// for setting quota limits on a newly created directory. -// It currently supports the legacy XFS specific ioctls. -// -// TODO: use generic quota control ioctl FS_IOC_FS{GET,SET}XATTR -// for both xfs/ext4 for kernel version >= v4.5 -// - -package quota - -/* -#include -#include -#include -#include -#include - -#ifndef FS_XFLAG_PROJINHERIT -struct fsxattr { - __u32 fsx_xflags; - __u32 fsx_extsize; - __u32 fsx_nextents; - __u32 fsx_projid; - unsigned char fsx_pad[12]; -}; -#define FS_XFLAG_PROJINHERIT 0x00000200 -#endif -#ifndef FS_IOC_FSGETXATTR -#define FS_IOC_FSGETXATTR _IOR ('X', 31, struct fsxattr) -#endif -#ifndef FS_IOC_FSSETXATTR -#define FS_IOC_FSSETXATTR _IOW ('X', 32, struct fsxattr) -#endif - -#ifndef PRJQUOTA -#define PRJQUOTA 2 -#endif -#ifndef XFS_PROJ_QUOTA -#define XFS_PROJ_QUOTA 2 -#endif -#ifndef Q_XSETPQLIM -#define Q_XSETPQLIM QCMD(Q_XSETQLIM, PRJQUOTA) -#endif -#ifndef Q_XGETPQUOTA -#define Q_XGETPQUOTA QCMD(Q_XGETQUOTA, PRJQUOTA) -#endif -*/ -import "C" -import ( - "fmt" - "io/ioutil" - "os" - "path" - "path/filepath" - "syscall" - "unsafe" - - "github.com/Sirupsen/logrus" -) - -// Quota limit params - currently we only control blocks hard limit -type Quota struct { - Size uint64 -} - -// Control - Context to be used by storage driver (e.g. overlay) -// who wants to apply project quotas to container dirs -type Control struct { - backingFsBlockDev string - nextProjectID uint32 - quotas map[string]uint32 -} - -// NewControl - initialize project quota support. -// Test to make sure that quota can be set on a test dir and find -// the first project id to be used for the next container create. -// -// Returns nil (and error) if project quota is not supported. -// -// First get the project id of the home directory. -// This test will fail if the backing fs is not xfs. -// -// xfs_quota tool can be used to assign a project id to the driver home directory, e.g.: -// echo 999:/var/lib/docker/overlay2 >> /etc/projects -// echo docker:999 >> /etc/projid -// xfs_quota -x -c 'project -s docker' / -// -// In that case, the home directory project id will be used as a "start offset" -// and all containers will be assigned larger project ids (e.g. >= 1000). -// This is a way to prevent xfs_quota management from conflicting with docker. -// -// Then try to create a test directory with the next project id and set a quota -// on it. If that works, continue to scan existing containers to map allocated -// project ids. -// -func NewControl(basePath string) (*Control, error) { - // - // Get project id of parent dir as minimal id to be used by driver - // - minProjectID, err := getProjectID(basePath) - if err != nil { - return nil, err - } - minProjectID++ - - // - // create backing filesystem device node - // - backingFsBlockDev, err := makeBackingFsDev(basePath) - if err != nil { - return nil, err - } - - // - // Test if filesystem supports project quotas by trying to set - // a quota on the first available project id - // - quota := Quota{ - Size: 0, - } - if err := setProjectQuota(backingFsBlockDev, minProjectID, quota); err != nil { - return nil, err - } - - q := Control{ - backingFsBlockDev: backingFsBlockDev, - nextProjectID: minProjectID + 1, - quotas: make(map[string]uint32), - } - - // - // get first project id to be used for next container - // - err = q.findNextProjectID(basePath) - if err != nil { - return nil, err - } - - logrus.Debugf("NewControl(%s): nextProjectID = %d", basePath, q.nextProjectID) - return &q, nil -} - -// SetQuota - assign a unique project id to directory and set the quota limits -// for that project id -func (q *Control) SetQuota(targetPath string, quota Quota) error { - - projectID, ok := q.quotas[targetPath] - if !ok { - projectID = q.nextProjectID - - // - // assign project id to new container directory - // - err := setProjectID(targetPath, projectID) - if err != nil { - return err - } - - q.quotas[targetPath] = projectID - q.nextProjectID++ - } - - // - // set the quota limit for the container's project id - // - logrus.Debugf("SetQuota(%s, %d): projectID=%d", targetPath, quota.Size, projectID) - return setProjectQuota(q.backingFsBlockDev, projectID, quota) -} - -// setProjectQuota - set the quota for project id on xfs block device -func setProjectQuota(backingFsBlockDev string, projectID uint32, quota Quota) error { - var d C.fs_disk_quota_t - d.d_version = C.FS_DQUOT_VERSION - d.d_id = C.__u32(projectID) - d.d_flags = C.XFS_PROJ_QUOTA - - d.d_fieldmask = C.FS_DQ_BHARD | C.FS_DQ_BSOFT - d.d_blk_hardlimit = C.__u64(quota.Size / 512) - d.d_blk_softlimit = d.d_blk_hardlimit - - var cs = C.CString(backingFsBlockDev) - defer C.free(unsafe.Pointer(cs)) - - _, _, errno := syscall.Syscall6(syscall.SYS_QUOTACTL, C.Q_XSETPQLIM, - uintptr(unsafe.Pointer(cs)), uintptr(d.d_id), - uintptr(unsafe.Pointer(&d)), 0, 0) - if errno != 0 { - return fmt.Errorf("Failed to set quota limit for projid %d on %s: %v", - projectID, backingFsBlockDev, errno.Error()) - } - - return nil -} - -// GetQuota - get the quota limits of a directory that was configured with SetQuota -func (q *Control) GetQuota(targetPath string, quota *Quota) error { - - projectID, ok := q.quotas[targetPath] - if !ok { - return fmt.Errorf("quota not found for path : %s", targetPath) - } - - // - // get the quota limit for the container's project id - // - var d C.fs_disk_quota_t - - var cs = C.CString(q.backingFsBlockDev) - defer C.free(unsafe.Pointer(cs)) - - _, _, errno := syscall.Syscall6(syscall.SYS_QUOTACTL, C.Q_XGETPQUOTA, - uintptr(unsafe.Pointer(cs)), uintptr(C.__u32(projectID)), - uintptr(unsafe.Pointer(&d)), 0, 0) - if errno != 0 { - return fmt.Errorf("Failed to get quota limit for projid %d on %s: %v", - projectID, q.backingFsBlockDev, errno.Error()) - } - quota.Size = uint64(d.d_blk_hardlimit) * 512 - - return nil -} - -// getProjectID - get the project id of path on xfs -func getProjectID(targetPath string) (uint32, error) { - dir, err := openDir(targetPath) - if err != nil { - return 0, err - } - defer closeDir(dir) - - var fsx C.struct_fsxattr - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, getDirFd(dir), C.FS_IOC_FSGETXATTR, - uintptr(unsafe.Pointer(&fsx))) - if errno != 0 { - return 0, fmt.Errorf("Failed to get projid for %s: %v", targetPath, errno.Error()) - } - - return uint32(fsx.fsx_projid), nil -} - -// setProjectID - set the project id of path on xfs -func setProjectID(targetPath string, projectID uint32) error { - dir, err := openDir(targetPath) - if err != nil { - return err - } - defer closeDir(dir) - - var fsx C.struct_fsxattr - _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, getDirFd(dir), C.FS_IOC_FSGETXATTR, - uintptr(unsafe.Pointer(&fsx))) - if errno != 0 { - return fmt.Errorf("Failed to get projid for %s: %v", targetPath, errno.Error()) - } - fsx.fsx_projid = C.__u32(projectID) - fsx.fsx_xflags |= C.FS_XFLAG_PROJINHERIT - _, _, errno = syscall.Syscall(syscall.SYS_IOCTL, getDirFd(dir), C.FS_IOC_FSSETXATTR, - uintptr(unsafe.Pointer(&fsx))) - if errno != 0 { - return fmt.Errorf("Failed to set projid for %s: %v", targetPath, errno.Error()) - } - - return nil -} - -// findNextProjectID - find the next project id to be used for containers -// by scanning driver home directory to find used project ids -func (q *Control) findNextProjectID(home string) error { - files, err := ioutil.ReadDir(home) - if err != nil { - return fmt.Errorf("read directory failed : %s", home) - } - for _, file := range files { - if !file.IsDir() { - continue - } - path := filepath.Join(home, file.Name()) - projid, err := getProjectID(path) - if err != nil { - return err - } - if projid > 0 { - q.quotas[path] = projid - } - if q.nextProjectID <= projid { - q.nextProjectID = projid + 1 - } - } - - return nil -} - -func free(p *C.char) { - C.free(unsafe.Pointer(p)) -} - -func openDir(path string) (*C.DIR, error) { - Cpath := C.CString(path) - defer free(Cpath) - - dir := C.opendir(Cpath) - if dir == nil { - return nil, fmt.Errorf("Can't open dir") - } - return dir, nil -} - -func closeDir(dir *C.DIR) { - if dir != nil { - C.closedir(dir) - } -} - -func getDirFd(dir *C.DIR) uintptr { - return uintptr(C.dirfd(dir)) -} - -// Get the backing block device of the driver home directory -// and create a block device node under the home directory -// to be used by quotactl commands -func makeBackingFsDev(home string) (string, error) { - fileinfo, err := os.Stat(home) - if err != nil { - return "", err - } - - backingFsBlockDev := path.Join(home, "backingFsBlockDev") - // Re-create just in case comeone copied the home directory over to a new device - syscall.Unlink(backingFsBlockDev) - stat := fileinfo.Sys().(*syscall.Stat_t) - if err := syscall.Mknod(backingFsBlockDev, syscall.S_IFBLK|0600, int(stat.Dev)); err != nil { - return "", fmt.Errorf("Failed to mknod %s: %v", backingFsBlockDev, err) - } - - return backingFsBlockDev, nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_aufs.go b/vendor/github.com/docker/docker/daemon/graphdriver/register/register_aufs.go deleted file mode 100644 index 262954d..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_aufs.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !exclude_graphdriver_aufs,linux - -package register - -import ( - // register the aufs graphdriver - _ "github.com/docker/docker/daemon/graphdriver/aufs" -) diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_btrfs.go b/vendor/github.com/docker/docker/daemon/graphdriver/register/register_btrfs.go deleted file mode 100644 index f456cc5..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_btrfs.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !exclude_graphdriver_btrfs,linux - -package register - -import ( - // register the btrfs graphdriver - _ "github.com/docker/docker/daemon/graphdriver/btrfs" -) diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_devicemapper.go b/vendor/github.com/docker/docker/daemon/graphdriver/register/register_devicemapper.go deleted file mode 100644 index bb2e9ef..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_devicemapper.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !exclude_graphdriver_devicemapper,linux - -package register - -import ( - // register the devmapper graphdriver - _ "github.com/docker/docker/daemon/graphdriver/devmapper" -) diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_overlay.go b/vendor/github.com/docker/docker/daemon/graphdriver/register/register_overlay.go deleted file mode 100644 index 9ba849c..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_overlay.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build !exclude_graphdriver_overlay,linux - -package register - -import ( - // register the overlay graphdriver - _ "github.com/docker/docker/daemon/graphdriver/overlay" - _ "github.com/docker/docker/daemon/graphdriver/overlay2" -) diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_vfs.go b/vendor/github.com/docker/docker/daemon/graphdriver/register/register_vfs.go deleted file mode 100644 index 98fad23..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_vfs.go +++ /dev/null @@ -1,6 +0,0 @@ -package register - -import ( - // register vfs - _ "github.com/docker/docker/daemon/graphdriver/vfs" -) diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_windows.go b/vendor/github.com/docker/docker/daemon/graphdriver/register/register_windows.go deleted file mode 100644 index efaa500..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_windows.go +++ /dev/null @@ -1,6 +0,0 @@ -package register - -import ( - // register the windows graph driver - _ "github.com/docker/docker/daemon/graphdriver/windows" -) diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_zfs.go b/vendor/github.com/docker/docker/daemon/graphdriver/register/register_zfs.go deleted file mode 100644 index 8f34e35..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/register/register_zfs.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !exclude_graphdriver_zfs,linux !exclude_graphdriver_zfs,freebsd, solaris - -package register - -import ( - // register the zfs driver - _ "github.com/docker/docker/daemon/graphdriver/zfs" -) diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/vfs/driver.go b/vendor/github.com/docker/docker/daemon/graphdriver/vfs/driver.go deleted file mode 100644 index 8832d11..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/vfs/driver.go +++ /dev/null @@ -1,145 +0,0 @@ -package vfs - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/chrootarchive" - "github.com/docker/docker/pkg/idtools" - - "github.com/opencontainers/runc/libcontainer/label" -) - -var ( - // CopyWithTar defines the copy method to use. - CopyWithTar = chrootarchive.CopyWithTar -) - -func init() { - graphdriver.Register("vfs", Init) -} - -// Init returns a new VFS driver. -// This sets the home directory for the driver and returns NaiveDiffDriver. -func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - d := &Driver{ - home: home, - uidMaps: uidMaps, - gidMaps: gidMaps, - } - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) - if err != nil { - return nil, err - } - if err := idtools.MkdirAllAs(home, 0700, rootUID, rootGID); err != nil { - return nil, err - } - return graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps), nil -} - -// Driver holds information about the driver, home directory of the driver. -// Driver implements graphdriver.ProtoDriver. It uses only basic vfs operations. -// In order to support layering, files are copied from the parent layer into the new layer. There is no copy-on-write support. -// Driver must be wrapped in NaiveDiffDriver to be used as a graphdriver.Driver -type Driver struct { - home string - uidMaps []idtools.IDMap - gidMaps []idtools.IDMap -} - -func (d *Driver) String() string { - return "vfs" -} - -// Status is used for implementing the graphdriver.ProtoDriver interface. VFS does not currently have any status information. -func (d *Driver) Status() [][2]string { - return nil -} - -// GetMetadata is used for implementing the graphdriver.ProtoDriver interface. VFS does not currently have any meta data. -func (d *Driver) GetMetadata(id string) (map[string]string, error) { - return nil, nil -} - -// Cleanup is used to implement graphdriver.ProtoDriver. There is no cleanup required for this driver. -func (d *Driver) Cleanup() error { - return nil -} - -// CreateReadWrite creates a layer that is writable for use as a container -// file system. -func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error { - return d.Create(id, parent, opts) -} - -// Create prepares the filesystem for the VFS driver and copies the directory for the given id under the parent. -func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error { - if opts != nil && len(opts.StorageOpt) != 0 { - return fmt.Errorf("--storage-opt is not supported for vfs") - } - - dir := d.dir(id) - rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps) - if err != nil { - return err - } - if err := idtools.MkdirAllAs(filepath.Dir(dir), 0700, rootUID, rootGID); err != nil { - return err - } - if err := idtools.MkdirAs(dir, 0755, rootUID, rootGID); err != nil { - return err - } - labelOpts := []string{"level:s0"} - if _, mountLabel, err := label.InitLabels(labelOpts); err == nil { - label.SetFileLabel(dir, mountLabel) - } - if parent == "" { - return nil - } - parentDir, err := d.Get(parent, "") - if err != nil { - return fmt.Errorf("%s: %s", parent, err) - } - if err := CopyWithTar(parentDir, dir); err != nil { - return err - } - return nil -} - -func (d *Driver) dir(id string) string { - return filepath.Join(d.home, "dir", filepath.Base(id)) -} - -// Remove deletes the content from the directory for a given id. -func (d *Driver) Remove(id string) error { - if err := os.RemoveAll(d.dir(id)); err != nil && !os.IsNotExist(err) { - return err - } - return nil -} - -// Get returns the directory for the given id. -func (d *Driver) Get(id, mountLabel string) (string, error) { - dir := d.dir(id) - if st, err := os.Stat(dir); err != nil { - return "", err - } else if !st.IsDir() { - return "", fmt.Errorf("%s: not a directory", dir) - } - return dir, nil -} - -// Put is a noop for vfs that return nil for the error, since this driver has no runtime resources to clean up. -func (d *Driver) Put(id string) error { - // The vfs driver has no runtime resources (e.g. mounts) - // to clean up, so we don't need anything here - return nil -} - -// Exists checks to see if the directory exists for the given id. -func (d *Driver) Exists(id string) bool { - _, err := os.Stat(d.dir(id)) - return err == nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/vfs/vfs_test.go b/vendor/github.com/docker/docker/daemon/graphdriver/vfs/vfs_test.go deleted file mode 100644 index 9ecf21d..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/vfs/vfs_test.go +++ /dev/null @@ -1,37 +0,0 @@ -// +build linux - -package vfs - -import ( - "testing" - - "github.com/docker/docker/daemon/graphdriver/graphtest" - - "github.com/docker/docker/pkg/reexec" -) - -func init() { - reexec.Init() -} - -// This avoids creating a new driver for each test if all tests are run -// Make sure to put new tests between TestVfsSetup and TestVfsTeardown -func TestVfsSetup(t *testing.T) { - graphtest.GetDriver(t, "vfs") -} - -func TestVfsCreateEmpty(t *testing.T) { - graphtest.DriverTestCreateEmpty(t, "vfs") -} - -func TestVfsCreateBase(t *testing.T) { - graphtest.DriverTestCreateBase(t, "vfs") -} - -func TestVfsCreateSnap(t *testing.T) { - graphtest.DriverTestCreateSnap(t, "vfs") -} - -func TestVfsTeardown(t *testing.T) { - graphtest.PutDriver(t) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/windows/windows.go b/vendor/github.com/docker/docker/daemon/graphdriver/windows/windows.go deleted file mode 100644 index beac93a..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/windows/windows.go +++ /dev/null @@ -1,886 +0,0 @@ -//+build windows - -package windows - -import ( - "bufio" - "bytes" - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "path" - "path/filepath" - "strconv" - "strings" - "sync" - "syscall" - "time" - "unsafe" - - "github.com/Microsoft/go-winio" - "github.com/Microsoft/go-winio/archive/tar" - "github.com/Microsoft/go-winio/backuptar" - "github.com/Microsoft/hcsshim" - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/longpath" - "github.com/docker/docker/pkg/reexec" - units "github.com/docker/go-units" - "golang.org/x/sys/windows" -) - -// filterDriver is an HCSShim driver type for the Windows Filter driver. -const filterDriver = 1 - -var ( - // mutatedFiles is a list of files that are mutated by the import process - // and must be backed up and restored. - mutatedFiles = map[string]string{ - "UtilityVM/Files/EFI/Microsoft/Boot/BCD": "bcd.bak", - "UtilityVM/Files/EFI/Microsoft/Boot/BCD.LOG": "bcd.log.bak", - "UtilityVM/Files/EFI/Microsoft/Boot/BCD.LOG1": "bcd.log1.bak", - "UtilityVM/Files/EFI/Microsoft/Boot/BCD.LOG2": "bcd.log2.bak", - } - noreexec = false -) - -// init registers the windows graph drivers to the register. -func init() { - graphdriver.Register("windowsfilter", InitFilter) - // DOCKER_WINDOWSFILTER_NOREEXEC allows for inline processing which makes - // debugging issues in the re-exec codepath significantly easier. - if os.Getenv("DOCKER_WINDOWSFILTER_NOREEXEC") != "" { - logrus.Warnf("WindowsGraphDriver is set to not re-exec. This is intended for debugging purposes only.") - noreexec = true - } else { - reexec.Register("docker-windows-write-layer", writeLayerReexec) - } -} - -type checker struct { -} - -func (c *checker) IsMounted(path string) bool { - return false -} - -// Driver represents a windows graph driver. -type Driver struct { - // info stores the shim driver information - info hcsshim.DriverInfo - ctr *graphdriver.RefCounter - // it is safe for windows to use a cache here because it does not support - // restoring containers when the daemon dies. - cacheMu sync.Mutex - cache map[string]string -} - -// InitFilter returns a new Windows storage filter driver. -func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - logrus.Debugf("WindowsGraphDriver InitFilter at %s", home) - - fsType, err := getFileSystemType(string(home[0])) - if err != nil { - return nil, err - } - if strings.ToLower(fsType) == "refs" { - return nil, fmt.Errorf("%s is on an ReFS volume - ReFS volumes are not supported", home) - } - - d := &Driver{ - info: hcsshim.DriverInfo{ - HomeDir: home, - Flavour: filterDriver, - }, - cache: make(map[string]string), - ctr: graphdriver.NewRefCounter(&checker{}), - } - return d, nil -} - -// win32FromHresult is a helper function to get the win32 error code from an HRESULT -func win32FromHresult(hr uintptr) uintptr { - if hr&0x1fff0000 == 0x00070000 { - return hr & 0xffff - } - return hr -} - -// getFileSystemType obtains the type of a file system through GetVolumeInformation -// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx -func getFileSystemType(drive string) (fsType string, hr error) { - var ( - modkernel32 = windows.NewLazySystemDLL("kernel32.dll") - procGetVolumeInformation = modkernel32.NewProc("GetVolumeInformationW") - buf = make([]uint16, 255) - size = syscall.MAX_PATH + 1 - ) - if len(drive) != 1 { - hr = errors.New("getFileSystemType must be called with a drive letter") - return - } - drive += `:\` - n := uintptr(unsafe.Pointer(nil)) - r0, _, _ := syscall.Syscall9(procGetVolumeInformation.Addr(), 8, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(drive))), n, n, n, n, n, uintptr(unsafe.Pointer(&buf[0])), uintptr(size), 0) - if int32(r0) < 0 { - hr = syscall.Errno(win32FromHresult(r0)) - } - fsType = syscall.UTF16ToString(buf) - return -} - -// String returns the string representation of a driver. This should match -// the name the graph driver has been registered with. -func (d *Driver) String() string { - return "windowsfilter" -} - -// Status returns the status of the driver. -func (d *Driver) Status() [][2]string { - return [][2]string{ - {"Windows", ""}, - } -} - -// Exists returns true if the given id is registered with this driver. -func (d *Driver) Exists(id string) bool { - rID, err := d.resolveID(id) - if err != nil { - return false - } - result, err := hcsshim.LayerExists(d.info, rID) - if err != nil { - return false - } - return result -} - -// CreateReadWrite creates a layer that is writable for use as a container -// file system. -func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error { - if opts != nil { - return d.create(id, parent, opts.MountLabel, false, opts.StorageOpt) - } - return d.create(id, parent, "", false, nil) -} - -// Create creates a new read-only layer with the given id. -func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error { - if opts != nil { - return d.create(id, parent, opts.MountLabel, true, opts.StorageOpt) - } - return d.create(id, parent, "", true, nil) -} - -func (d *Driver) create(id, parent, mountLabel string, readOnly bool, storageOpt map[string]string) error { - rPId, err := d.resolveID(parent) - if err != nil { - return err - } - - parentChain, err := d.getLayerChain(rPId) - if err != nil { - return err - } - - var layerChain []string - - if rPId != "" { - parentPath, err := hcsshim.GetLayerMountPath(d.info, rPId) - if err != nil { - return err - } - if _, err := os.Stat(filepath.Join(parentPath, "Files")); err == nil { - // This is a legitimate parent layer (not the empty "-init" layer), - // so include it in the layer chain. - layerChain = []string{parentPath} - } - } - - layerChain = append(layerChain, parentChain...) - - if readOnly { - if err := hcsshim.CreateLayer(d.info, id, rPId); err != nil { - return err - } - } else { - var parentPath string - if len(layerChain) != 0 { - parentPath = layerChain[0] - } - - if err := hcsshim.CreateSandboxLayer(d.info, id, parentPath, layerChain); err != nil { - return err - } - - storageOptions, err := parseStorageOpt(storageOpt) - if err != nil { - return fmt.Errorf("Failed to parse storage options - %s", err) - } - - if storageOptions.size != 0 { - if err := hcsshim.ExpandSandboxSize(d.info, id, storageOptions.size); err != nil { - return err - } - } - } - - if _, err := os.Lstat(d.dir(parent)); err != nil { - if err2 := hcsshim.DestroyLayer(d.info, id); err2 != nil { - logrus.Warnf("Failed to DestroyLayer %s: %s", id, err2) - } - return fmt.Errorf("Cannot create layer with missing parent %s: %s", parent, err) - } - - if err := d.setLayerChain(id, layerChain); err != nil { - if err2 := hcsshim.DestroyLayer(d.info, id); err2 != nil { - logrus.Warnf("Failed to DestroyLayer %s: %s", id, err2) - } - return err - } - - return nil -} - -// dir returns the absolute path to the layer. -func (d *Driver) dir(id string) string { - return filepath.Join(d.info.HomeDir, filepath.Base(id)) -} - -// Remove unmounts and removes the dir information. -func (d *Driver) Remove(id string) error { - rID, err := d.resolveID(id) - if err != nil { - return err - } - - // This retry loop is due to a bug in Windows (Internal bug #9432268) - // if GetContainers fails with ErrVmcomputeOperationInvalidState - // it is a transient error. Retry until it succeeds. - var computeSystems []hcsshim.ContainerProperties - retryCount := 0 - for { - // Get and terminate any template VMs that are currently using the layer - computeSystems, err = hcsshim.GetContainers(hcsshim.ComputeSystemQuery{}) - if err != nil { - if err == hcsshim.ErrVmcomputeOperationInvalidState { - if retryCount >= 5 { - // If we are unable to get the list of containers - // go ahead and attempt to delete the layer anyway - // as it will most likely work. - break - } - retryCount++ - time.Sleep(2 * time.Second) - continue - } - return err - } - break - } - - for _, computeSystem := range computeSystems { - if strings.Contains(computeSystem.RuntimeImagePath, id) && computeSystem.IsRuntimeTemplate { - container, err := hcsshim.OpenContainer(computeSystem.ID) - if err != nil { - return err - } - defer container.Close() - err = container.Terminate() - if hcsshim.IsPending(err) { - err = container.Wait() - } else if hcsshim.IsAlreadyStopped(err) { - err = nil - } - - if err != nil { - return err - } - } - } - - layerPath := filepath.Join(d.info.HomeDir, rID) - tmpID := fmt.Sprintf("%s-removing", rID) - tmpLayerPath := filepath.Join(d.info.HomeDir, tmpID) - if err := os.Rename(layerPath, tmpLayerPath); err != nil && !os.IsNotExist(err) { - return err - } - if err := hcsshim.DestroyLayer(d.info, tmpID); err != nil { - logrus.Errorf("Failed to DestroyLayer %s: %s", id, err) - } - - return nil -} - -// Get returns the rootfs path for the id. This will mount the dir at its given path. -func (d *Driver) Get(id, mountLabel string) (string, error) { - logrus.Debugf("WindowsGraphDriver Get() id %s mountLabel %s", id, mountLabel) - var dir string - - rID, err := d.resolveID(id) - if err != nil { - return "", err - } - if count := d.ctr.Increment(rID); count > 1 { - return d.cache[rID], nil - } - - // Getting the layer paths must be done outside of the lock. - layerChain, err := d.getLayerChain(rID) - if err != nil { - d.ctr.Decrement(rID) - return "", err - } - - if err := hcsshim.ActivateLayer(d.info, rID); err != nil { - d.ctr.Decrement(rID) - return "", err - } - if err := hcsshim.PrepareLayer(d.info, rID, layerChain); err != nil { - d.ctr.Decrement(rID) - if err2 := hcsshim.DeactivateLayer(d.info, rID); err2 != nil { - logrus.Warnf("Failed to Deactivate %s: %s", id, err) - } - return "", err - } - - mountPath, err := hcsshim.GetLayerMountPath(d.info, rID) - if err != nil { - d.ctr.Decrement(rID) - if err2 := hcsshim.DeactivateLayer(d.info, rID); err2 != nil { - logrus.Warnf("Failed to Deactivate %s: %s", id, err) - } - return "", err - } - d.cacheMu.Lock() - d.cache[rID] = mountPath - d.cacheMu.Unlock() - - // If the layer has a mount path, use that. Otherwise, use the - // folder path. - if mountPath != "" { - dir = mountPath - } else { - dir = d.dir(id) - } - - return dir, nil -} - -// Put adds a new layer to the driver. -func (d *Driver) Put(id string) error { - logrus.Debugf("WindowsGraphDriver Put() id %s", id) - - rID, err := d.resolveID(id) - if err != nil { - return err - } - if count := d.ctr.Decrement(rID); count > 0 { - return nil - } - d.cacheMu.Lock() - delete(d.cache, rID) - d.cacheMu.Unlock() - - if err := hcsshim.UnprepareLayer(d.info, rID); err != nil { - return err - } - return hcsshim.DeactivateLayer(d.info, rID) -} - -// Cleanup ensures the information the driver stores is properly removed. -func (d *Driver) Cleanup() error { - return nil -} - -// Diff produces an archive of the changes between the specified -// layer and its parent layer which may be "". -// The layer should be mounted when calling this function -func (d *Driver) Diff(id, parent string) (_ io.ReadCloser, err error) { - rID, err := d.resolveID(id) - if err != nil { - return - } - - layerChain, err := d.getLayerChain(rID) - if err != nil { - return - } - - // this is assuming that the layer is unmounted - if err := hcsshim.UnprepareLayer(d.info, rID); err != nil { - return nil, err - } - prepare := func() { - if err := hcsshim.PrepareLayer(d.info, rID, layerChain); err != nil { - logrus.Warnf("Failed to Deactivate %s: %s", rID, err) - } - } - - arch, err := d.exportLayer(rID, layerChain) - if err != nil { - prepare() - return - } - return ioutils.NewReadCloserWrapper(arch, func() error { - err := arch.Close() - prepare() - return err - }), nil -} - -// Changes produces a list of changes between the specified layer -// and its parent layer. If parent is "", then all changes will be ADD changes. -// The layer should not be mounted when calling this function. -func (d *Driver) Changes(id, parent string) ([]archive.Change, error) { - rID, err := d.resolveID(id) - if err != nil { - return nil, err - } - parentChain, err := d.getLayerChain(rID) - if err != nil { - return nil, err - } - - if err := hcsshim.ActivateLayer(d.info, rID); err != nil { - return nil, err - } - defer func() { - if err2 := hcsshim.DeactivateLayer(d.info, rID); err2 != nil { - logrus.Errorf("changes() failed to DeactivateLayer %s %s: %s", id, rID, err2) - } - }() - - var changes []archive.Change - err = winio.RunWithPrivilege(winio.SeBackupPrivilege, func() error { - r, err := hcsshim.NewLayerReader(d.info, id, parentChain) - if err != nil { - return err - } - defer r.Close() - - for { - name, _, fileInfo, err := r.Next() - if err == io.EOF { - return nil - } - if err != nil { - return err - } - name = filepath.ToSlash(name) - if fileInfo == nil { - changes = append(changes, archive.Change{Path: name, Kind: archive.ChangeDelete}) - } else { - // Currently there is no way to tell between an add and a modify. - changes = append(changes, archive.Change{Path: name, Kind: archive.ChangeModify}) - } - } - }) - if err != nil { - return nil, err - } - - return changes, nil -} - -// ApplyDiff extracts the changeset from the given diff into the -// layer with the specified id and parent, returning the size of the -// new layer in bytes. -// The layer should not be mounted when calling this function -func (d *Driver) ApplyDiff(id, parent string, diff io.Reader) (int64, error) { - var layerChain []string - if parent != "" { - rPId, err := d.resolveID(parent) - if err != nil { - return 0, err - } - parentChain, err := d.getLayerChain(rPId) - if err != nil { - return 0, err - } - parentPath, err := hcsshim.GetLayerMountPath(d.info, rPId) - if err != nil { - return 0, err - } - layerChain = append(layerChain, parentPath) - layerChain = append(layerChain, parentChain...) - } - - size, err := d.importLayer(id, diff, layerChain) - if err != nil { - return 0, err - } - - if err = d.setLayerChain(id, layerChain); err != nil { - return 0, err - } - - return size, nil -} - -// DiffSize calculates the changes between the specified layer -// and its parent and returns the size in bytes of the changes -// relative to its base filesystem directory. -func (d *Driver) DiffSize(id, parent string) (size int64, err error) { - rPId, err := d.resolveID(parent) - if err != nil { - return - } - - changes, err := d.Changes(id, rPId) - if err != nil { - return - } - - layerFs, err := d.Get(id, "") - if err != nil { - return - } - defer d.Put(id) - - return archive.ChangesSize(layerFs, changes), nil -} - -// GetMetadata returns custom driver information. -func (d *Driver) GetMetadata(id string) (map[string]string, error) { - m := make(map[string]string) - m["dir"] = d.dir(id) - return m, nil -} - -func writeTarFromLayer(r hcsshim.LayerReader, w io.Writer) error { - t := tar.NewWriter(w) - for { - name, size, fileInfo, err := r.Next() - if err == io.EOF { - break - } - if err != nil { - return err - } - if fileInfo == nil { - // Write a whiteout file. - hdr := &tar.Header{ - Name: filepath.ToSlash(filepath.Join(filepath.Dir(name), archive.WhiteoutPrefix+filepath.Base(name))), - } - err := t.WriteHeader(hdr) - if err != nil { - return err - } - } else { - err = backuptar.WriteTarFileFromBackupStream(t, r, name, size, fileInfo) - if err != nil { - return err - } - } - } - return t.Close() -} - -// exportLayer generates an archive from a layer based on the given ID. -func (d *Driver) exportLayer(id string, parentLayerPaths []string) (io.ReadCloser, error) { - archive, w := io.Pipe() - go func() { - err := winio.RunWithPrivilege(winio.SeBackupPrivilege, func() error { - r, err := hcsshim.NewLayerReader(d.info, id, parentLayerPaths) - if err != nil { - return err - } - - err = writeTarFromLayer(r, w) - cerr := r.Close() - if err == nil { - err = cerr - } - return err - }) - w.CloseWithError(err) - }() - - return archive, nil -} - -// writeBackupStreamFromTarAndSaveMutatedFiles reads data from a tar stream and -// writes it to a backup stream, and also saves any files that will be mutated -// by the import layer process to a backup location. -func writeBackupStreamFromTarAndSaveMutatedFiles(buf *bufio.Writer, w io.Writer, t *tar.Reader, hdr *tar.Header, root string) (nextHdr *tar.Header, err error) { - var bcdBackup *os.File - var bcdBackupWriter *winio.BackupFileWriter - if backupPath, ok := mutatedFiles[hdr.Name]; ok { - bcdBackup, err = os.Create(filepath.Join(root, backupPath)) - if err != nil { - return nil, err - } - defer func() { - cerr := bcdBackup.Close() - if err == nil { - err = cerr - } - }() - - bcdBackupWriter = winio.NewBackupFileWriter(bcdBackup, false) - defer func() { - cerr := bcdBackupWriter.Close() - if err == nil { - err = cerr - } - }() - - buf.Reset(io.MultiWriter(w, bcdBackupWriter)) - } else { - buf.Reset(w) - } - - defer func() { - ferr := buf.Flush() - if err == nil { - err = ferr - } - }() - - return backuptar.WriteBackupStreamFromTarFile(buf, t, hdr) -} - -func writeLayerFromTar(r io.Reader, w hcsshim.LayerWriter, root string) (int64, error) { - t := tar.NewReader(r) - hdr, err := t.Next() - totalSize := int64(0) - buf := bufio.NewWriter(nil) - for err == nil { - base := path.Base(hdr.Name) - if strings.HasPrefix(base, archive.WhiteoutPrefix) { - name := path.Join(path.Dir(hdr.Name), base[len(archive.WhiteoutPrefix):]) - err = w.Remove(filepath.FromSlash(name)) - if err != nil { - return 0, err - } - hdr, err = t.Next() - } else if hdr.Typeflag == tar.TypeLink { - err = w.AddLink(filepath.FromSlash(hdr.Name), filepath.FromSlash(hdr.Linkname)) - if err != nil { - return 0, err - } - hdr, err = t.Next() - } else { - var ( - name string - size int64 - fileInfo *winio.FileBasicInfo - ) - name, size, fileInfo, err = backuptar.FileInfoFromHeader(hdr) - if err != nil { - return 0, err - } - err = w.Add(filepath.FromSlash(name), fileInfo) - if err != nil { - return 0, err - } - hdr, err = writeBackupStreamFromTarAndSaveMutatedFiles(buf, w, t, hdr, root) - totalSize += size - } - } - if err != io.EOF { - return 0, err - } - return totalSize, nil -} - -// importLayer adds a new layer to the tag and graph store based on the given data. -func (d *Driver) importLayer(id string, layerData io.Reader, parentLayerPaths []string) (size int64, err error) { - if !noreexec { - cmd := reexec.Command(append([]string{"docker-windows-write-layer", d.info.HomeDir, id}, parentLayerPaths...)...) - output := bytes.NewBuffer(nil) - cmd.Stdin = layerData - cmd.Stdout = output - cmd.Stderr = output - - if err = cmd.Start(); err != nil { - return - } - - if err = cmd.Wait(); err != nil { - return 0, fmt.Errorf("re-exec error: %v: output: %s", err, output) - } - - return strconv.ParseInt(output.String(), 10, 64) - } - return writeLayer(layerData, d.info.HomeDir, id, parentLayerPaths...) -} - -// writeLayerReexec is the re-exec entry point for writing a layer from a tar file -func writeLayerReexec() { - size, err := writeLayer(os.Stdin, os.Args[1], os.Args[2], os.Args[3:]...) - if err != nil { - fmt.Fprint(os.Stderr, err) - os.Exit(1) - } - fmt.Fprint(os.Stdout, size) -} - -// writeLayer writes a layer from a tar file. -func writeLayer(layerData io.Reader, home string, id string, parentLayerPaths ...string) (int64, error) { - err := winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege}) - if err != nil { - return 0, err - } - if noreexec { - defer func() { - if err := winio.DisableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege}); err != nil { - // This should never happen, but just in case when in debugging mode. - // See https://github.com/docker/docker/pull/28002#discussion_r86259241 for rationale. - panic("Failed to disabled process privileges while in non re-exec mode") - } - }() - } - - info := hcsshim.DriverInfo{ - Flavour: filterDriver, - HomeDir: home, - } - - w, err := hcsshim.NewLayerWriter(info, id, parentLayerPaths) - if err != nil { - return 0, err - } - - size, err := writeLayerFromTar(layerData, w, filepath.Join(home, id)) - if err != nil { - return 0, err - } - - err = w.Close() - if err != nil { - return 0, err - } - - return size, nil -} - -// resolveID computes the layerID information based on the given id. -func (d *Driver) resolveID(id string) (string, error) { - content, err := ioutil.ReadFile(filepath.Join(d.dir(id), "layerID")) - if os.IsNotExist(err) { - return id, nil - } else if err != nil { - return "", err - } - return string(content), nil -} - -// setID stores the layerId in disk. -func (d *Driver) setID(id, altID string) error { - err := ioutil.WriteFile(filepath.Join(d.dir(id), "layerId"), []byte(altID), 0600) - if err != nil { - return err - } - return nil -} - -// getLayerChain returns the layer chain information. -func (d *Driver) getLayerChain(id string) ([]string, error) { - jPath := filepath.Join(d.dir(id), "layerchain.json") - content, err := ioutil.ReadFile(jPath) - if os.IsNotExist(err) { - return nil, nil - } else if err != nil { - return nil, fmt.Errorf("Unable to read layerchain file - %s", err) - } - - var layerChain []string - err = json.Unmarshal(content, &layerChain) - if err != nil { - return nil, fmt.Errorf("Failed to unmarshall layerchain json - %s", err) - } - - return layerChain, nil -} - -// setLayerChain stores the layer chain information in disk. -func (d *Driver) setLayerChain(id string, chain []string) error { - content, err := json.Marshal(&chain) - if err != nil { - return fmt.Errorf("Failed to marshall layerchain json - %s", err) - } - - jPath := filepath.Join(d.dir(id), "layerchain.json") - err = ioutil.WriteFile(jPath, content, 0600) - if err != nil { - return fmt.Errorf("Unable to write layerchain file - %s", err) - } - - return nil -} - -type fileGetCloserWithBackupPrivileges struct { - path string -} - -func (fg *fileGetCloserWithBackupPrivileges) Get(filename string) (io.ReadCloser, error) { - if backupPath, ok := mutatedFiles[filename]; ok { - return os.Open(filepath.Join(fg.path, backupPath)) - } - - var f *os.File - // Open the file while holding the Windows backup privilege. This ensures that the - // file can be opened even if the caller does not actually have access to it according - // to the security descriptor. - err := winio.RunWithPrivilege(winio.SeBackupPrivilege, func() error { - path := longpath.AddPrefix(filepath.Join(fg.path, filename)) - p, err := syscall.UTF16FromString(path) - if err != nil { - return err - } - h, err := syscall.CreateFile(&p[0], syscall.GENERIC_READ, syscall.FILE_SHARE_READ, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0) - if err != nil { - return &os.PathError{Op: "open", Path: path, Err: err} - } - f = os.NewFile(uintptr(h), path) - return nil - }) - return f, err -} - -func (fg *fileGetCloserWithBackupPrivileges) Close() error { - return nil -} - -// DiffGetter returns a FileGetCloser that can read files from the directory that -// contains files for the layer differences. Used for direct access for tar-split. -func (d *Driver) DiffGetter(id string) (graphdriver.FileGetCloser, error) { - id, err := d.resolveID(id) - if err != nil { - return nil, err - } - - return &fileGetCloserWithBackupPrivileges{d.dir(id)}, nil -} - -type storageOptions struct { - size uint64 -} - -func parseStorageOpt(storageOpt map[string]string) (*storageOptions, error) { - options := storageOptions{} - - // Read size to change the block device size per container. - for key, val := range storageOpt { - key := strings.ToLower(key) - switch key { - case "size": - size, err := units.RAMInBytes(val) - if err != nil { - return nil, err - } - options.size = uint64(size) - default: - return nil, fmt.Errorf("Unknown storage option: %s", key) - } - } - return &options, nil -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/MAINTAINERS b/vendor/github.com/docker/docker/daemon/graphdriver/zfs/MAINTAINERS deleted file mode 100644 index 9c270c5..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/MAINTAINERS +++ /dev/null @@ -1,2 +0,0 @@ -Jörg Thalheim (@Mic92) -Arthur Gautier (@baloose) diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs.go b/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs.go deleted file mode 100644 index 8e283cc..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs.go +++ /dev/null @@ -1,417 +0,0 @@ -// +build linux freebsd solaris - -package zfs - -import ( - "fmt" - "os" - "os/exec" - "path" - "strconv" - "strings" - "sync" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/parsers" - zfs "github.com/mistifyio/go-zfs" - "github.com/opencontainers/runc/libcontainer/label" -) - -type zfsOptions struct { - fsName string - mountPath string -} - -func init() { - graphdriver.Register("zfs", Init) -} - -// Logger returns a zfs logger implementation. -type Logger struct{} - -// Log wraps log message from ZFS driver with a prefix '[zfs]'. -func (*Logger) Log(cmd []string) { - logrus.Debugf("[zfs] %s", strings.Join(cmd, " ")) -} - -// Init returns a new ZFS driver. -// It takes base mount path and an array of options which are represented as key value pairs. -// Each option is in the for key=value. 'zfs.fsname' is expected to be a valid key in the options. -func Init(base string, opt []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - var err error - - if _, err := exec.LookPath("zfs"); err != nil { - logrus.Debugf("[zfs] zfs command is not available: %v", err) - return nil, graphdriver.ErrPrerequisites - } - - file, err := os.OpenFile("/dev/zfs", os.O_RDWR, 600) - if err != nil { - logrus.Debugf("[zfs] cannot open /dev/zfs: %v", err) - return nil, graphdriver.ErrPrerequisites - } - defer file.Close() - - options, err := parseOptions(opt) - if err != nil { - return nil, err - } - options.mountPath = base - - rootdir := path.Dir(base) - - if options.fsName == "" { - err = checkRootdirFs(rootdir) - if err != nil { - return nil, err - } - } - - if options.fsName == "" { - options.fsName, err = lookupZfsDataset(rootdir) - if err != nil { - return nil, err - } - } - - zfs.SetLogger(new(Logger)) - - filesystems, err := zfs.Filesystems(options.fsName) - if err != nil { - return nil, fmt.Errorf("Cannot find root filesystem %s: %v", options.fsName, err) - } - - filesystemsCache := make(map[string]bool, len(filesystems)) - var rootDataset *zfs.Dataset - for _, fs := range filesystems { - if fs.Name == options.fsName { - rootDataset = fs - } - filesystemsCache[fs.Name] = true - } - - if rootDataset == nil { - return nil, fmt.Errorf("BUG: zfs get all -t filesystem -rHp '%s' should contain '%s'", options.fsName, options.fsName) - } - - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) - if err != nil { - return nil, fmt.Errorf("Failed to get root uid/guid: %v", err) - } - if err := idtools.MkdirAllAs(base, 0700, rootUID, rootGID); err != nil { - return nil, fmt.Errorf("Failed to create '%s': %v", base, err) - } - - if err := mount.MakePrivate(base); err != nil { - return nil, err - } - d := &Driver{ - dataset: rootDataset, - options: options, - filesystemsCache: filesystemsCache, - uidMaps: uidMaps, - gidMaps: gidMaps, - ctr: graphdriver.NewRefCounter(graphdriver.NewDefaultChecker()), - } - return graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps), nil -} - -func parseOptions(opt []string) (zfsOptions, error) { - var options zfsOptions - options.fsName = "" - for _, option := range opt { - key, val, err := parsers.ParseKeyValueOpt(option) - if err != nil { - return options, err - } - key = strings.ToLower(key) - switch key { - case "zfs.fsname": - options.fsName = val - default: - return options, fmt.Errorf("Unknown option %s", key) - } - } - return options, nil -} - -func lookupZfsDataset(rootdir string) (string, error) { - var stat syscall.Stat_t - if err := syscall.Stat(rootdir, &stat); err != nil { - return "", fmt.Errorf("Failed to access '%s': %s", rootdir, err) - } - wantedDev := stat.Dev - - mounts, err := mount.GetMounts() - if err != nil { - return "", err - } - for _, m := range mounts { - if err := syscall.Stat(m.Mountpoint, &stat); err != nil { - logrus.Debugf("[zfs] failed to stat '%s' while scanning for zfs mount: %v", m.Mountpoint, err) - continue // may fail on fuse file systems - } - - if stat.Dev == wantedDev && m.Fstype == "zfs" { - return m.Source, nil - } - } - - return "", fmt.Errorf("Failed to find zfs dataset mounted on '%s' in /proc/mounts", rootdir) -} - -// Driver holds information about the driver, such as zfs dataset, options and cache. -type Driver struct { - dataset *zfs.Dataset - options zfsOptions - sync.Mutex // protects filesystem cache against concurrent access - filesystemsCache map[string]bool - uidMaps []idtools.IDMap - gidMaps []idtools.IDMap - ctr *graphdriver.RefCounter -} - -func (d *Driver) String() string { - return "zfs" -} - -// Cleanup is used to implement graphdriver.ProtoDriver. There is no cleanup required for this driver. -func (d *Driver) Cleanup() error { - return nil -} - -// Status returns information about the ZFS filesystem. It returns a two dimensional array of information -// such as pool name, dataset name, disk usage, parent quota and compression used. -// Currently it return 'Zpool', 'Zpool Health', 'Parent Dataset', 'Space Used By Parent', -// 'Space Available', 'Parent Quota' and 'Compression'. -func (d *Driver) Status() [][2]string { - parts := strings.Split(d.dataset.Name, "/") - pool, err := zfs.GetZpool(parts[0]) - - var poolName, poolHealth string - if err == nil { - poolName = pool.Name - poolHealth = pool.Health - } else { - poolName = fmt.Sprintf("error while getting pool information %v", err) - poolHealth = "not available" - } - - quota := "no" - if d.dataset.Quota != 0 { - quota = strconv.FormatUint(d.dataset.Quota, 10) - } - - return [][2]string{ - {"Zpool", poolName}, - {"Zpool Health", poolHealth}, - {"Parent Dataset", d.dataset.Name}, - {"Space Used By Parent", strconv.FormatUint(d.dataset.Used, 10)}, - {"Space Available", strconv.FormatUint(d.dataset.Avail, 10)}, - {"Parent Quota", quota}, - {"Compression", d.dataset.Compression}, - } -} - -// GetMetadata returns image/container metadata related to graph driver -func (d *Driver) GetMetadata(id string) (map[string]string, error) { - return nil, nil -} - -func (d *Driver) cloneFilesystem(name, parentName string) error { - snapshotName := fmt.Sprintf("%d", time.Now().Nanosecond()) - parentDataset := zfs.Dataset{Name: parentName} - snapshot, err := parentDataset.Snapshot(snapshotName /*recursive */, false) - if err != nil { - return err - } - - _, err = snapshot.Clone(name, map[string]string{"mountpoint": "legacy"}) - if err == nil { - d.Lock() - d.filesystemsCache[name] = true - d.Unlock() - } - - if err != nil { - snapshot.Destroy(zfs.DestroyDeferDeletion) - return err - } - return snapshot.Destroy(zfs.DestroyDeferDeletion) -} - -func (d *Driver) zfsPath(id string) string { - return d.options.fsName + "/" + id -} - -func (d *Driver) mountPath(id string) string { - return path.Join(d.options.mountPath, "graph", getMountpoint(id)) -} - -// CreateReadWrite creates a layer that is writable for use as a container -// file system. -func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error { - return d.Create(id, parent, opts) -} - -// Create prepares the dataset and filesystem for the ZFS driver for the given id under the parent. -func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error { - var storageOpt map[string]string - if opts != nil { - storageOpt = opts.StorageOpt - } - - err := d.create(id, parent, storageOpt) - if err == nil { - return nil - } - if zfsError, ok := err.(*zfs.Error); ok { - if !strings.HasSuffix(zfsError.Stderr, "dataset already exists\n") { - return err - } - // aborted build -> cleanup - } else { - return err - } - - dataset := zfs.Dataset{Name: d.zfsPath(id)} - if err := dataset.Destroy(zfs.DestroyRecursiveClones); err != nil { - return err - } - - // retry - return d.create(id, parent, storageOpt) -} - -func (d *Driver) create(id, parent string, storageOpt map[string]string) error { - name := d.zfsPath(id) - quota, err := parseStorageOpt(storageOpt) - if err != nil { - return err - } - if parent == "" { - mountoptions := map[string]string{"mountpoint": "legacy"} - fs, err := zfs.CreateFilesystem(name, mountoptions) - if err == nil { - err = setQuota(name, quota) - if err == nil { - d.Lock() - d.filesystemsCache[fs.Name] = true - d.Unlock() - } - } - return err - } - err = d.cloneFilesystem(name, d.zfsPath(parent)) - if err == nil { - err = setQuota(name, quota) - } - return err -} - -func parseStorageOpt(storageOpt map[string]string) (string, error) { - // Read size to change the disk quota per container - for k, v := range storageOpt { - key := strings.ToLower(k) - switch key { - case "size": - return v, nil - default: - return "0", fmt.Errorf("Unknown option %s", key) - } - } - return "0", nil -} - -func setQuota(name string, quota string) error { - if quota == "0" { - return nil - } - fs, err := zfs.GetDataset(name) - if err != nil { - return err - } - return fs.SetProperty("quota", quota) -} - -// Remove deletes the dataset, filesystem and the cache for the given id. -func (d *Driver) Remove(id string) error { - name := d.zfsPath(id) - dataset := zfs.Dataset{Name: name} - err := dataset.Destroy(zfs.DestroyRecursive) - if err == nil { - d.Lock() - delete(d.filesystemsCache, name) - d.Unlock() - } - return err -} - -// Get returns the mountpoint for the given id after creating the target directories if necessary. -func (d *Driver) Get(id, mountLabel string) (string, error) { - mountpoint := d.mountPath(id) - if count := d.ctr.Increment(mountpoint); count > 1 { - return mountpoint, nil - } - - filesystem := d.zfsPath(id) - options := label.FormatMountLabel("", mountLabel) - logrus.Debugf(`[zfs] mount("%s", "%s", "%s")`, filesystem, mountpoint, options) - - rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps) - if err != nil { - d.ctr.Decrement(mountpoint) - return "", err - } - // Create the target directories if they don't exist - if err := idtools.MkdirAllAs(mountpoint, 0755, rootUID, rootGID); err != nil { - d.ctr.Decrement(mountpoint) - return "", err - } - - if err := mount.Mount(filesystem, mountpoint, "zfs", options); err != nil { - d.ctr.Decrement(mountpoint) - return "", fmt.Errorf("error creating zfs mount of %s to %s: %v", filesystem, mountpoint, err) - } - - // this could be our first mount after creation of the filesystem, and the root dir may still have root - // permissions instead of the remapped root uid:gid (if user namespaces are enabled): - if err := os.Chown(mountpoint, rootUID, rootGID); err != nil { - mount.Unmount(mountpoint) - d.ctr.Decrement(mountpoint) - return "", fmt.Errorf("error modifying zfs mountpoint (%s) directory ownership: %v", mountpoint, err) - } - - return mountpoint, nil -} - -// Put removes the existing mountpoint for the given id if it exists. -func (d *Driver) Put(id string) error { - mountpoint := d.mountPath(id) - if count := d.ctr.Decrement(mountpoint); count > 0 { - return nil - } - mounted, err := graphdriver.Mounted(graphdriver.FsMagicZfs, mountpoint) - if err != nil || !mounted { - return err - } - - logrus.Debugf(`[zfs] unmount("%s")`, mountpoint) - - if err := mount.Unmount(mountpoint); err != nil { - return fmt.Errorf("error unmounting to %s: %v", mountpoint, err) - } - return nil -} - -// Exists checks to see if the cache entry exists for the given id. -func (d *Driver) Exists(id string) bool { - d.Lock() - defer d.Unlock() - return d.filesystemsCache[d.zfsPath(id)] == true -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_freebsd.go b/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_freebsd.go deleted file mode 100644 index 1c05fa7..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_freebsd.go +++ /dev/null @@ -1,38 +0,0 @@ -package zfs - -import ( - "fmt" - "strings" - "syscall" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/graphdriver" -) - -func checkRootdirFs(rootdir string) error { - var buf syscall.Statfs_t - if err := syscall.Statfs(rootdir, &buf); err != nil { - return fmt.Errorf("Failed to access '%s': %s", rootdir, err) - } - - // on FreeBSD buf.Fstypename contains ['z', 'f', 's', 0 ... ] - if (buf.Fstypename[0] != 122) || (buf.Fstypename[1] != 102) || (buf.Fstypename[2] != 115) || (buf.Fstypename[3] != 0) { - logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir) - return graphdriver.ErrPrerequisites - } - - return nil -} - -func getMountpoint(id string) string { - maxlen := 12 - - // we need to preserve filesystem suffix - suffix := strings.SplitN(id, "-", 2) - - if len(suffix) > 1 { - return id[:maxlen] + "-" + suffix[1] - } - - return id[:maxlen] -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_linux.go b/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_linux.go deleted file mode 100644 index 52ed516..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_linux.go +++ /dev/null @@ -1,27 +0,0 @@ -package zfs - -import ( - "fmt" - "syscall" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/graphdriver" -) - -func checkRootdirFs(rootdir string) error { - var buf syscall.Statfs_t - if err := syscall.Statfs(rootdir, &buf); err != nil { - return fmt.Errorf("Failed to access '%s': %s", rootdir, err) - } - - if graphdriver.FsMagic(buf.Type) != graphdriver.FsMagicZfs { - logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir) - return graphdriver.ErrPrerequisites - } - - return nil -} - -func getMountpoint(id string) string { - return id -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_solaris.go b/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_solaris.go deleted file mode 100644 index bb4a85b..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_solaris.go +++ /dev/null @@ -1,59 +0,0 @@ -// +build solaris,cgo - -package zfs - -/* -#include -#include - -static inline struct statvfs *getstatfs(char *s) { - struct statvfs *buf; - int err; - buf = (struct statvfs *)malloc(sizeof(struct statvfs)); - err = statvfs(s, buf); - return buf; -} -*/ -import "C" -import ( - "path/filepath" - "strings" - "unsafe" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/graphdriver" -) - -func checkRootdirFs(rootdir string) error { - - cs := C.CString(filepath.Dir(rootdir)) - buf := C.getstatfs(cs) - - // on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ] - if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) || - (buf.f_basetype[3] != 0) { - logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir) - C.free(unsafe.Pointer(buf)) - return graphdriver.ErrPrerequisites - } - - C.free(unsafe.Pointer(buf)) - C.free(unsafe.Pointer(cs)) - return nil -} - -/* rootfs is introduced to comply with the OCI spec -which states that root filesystem must be mounted at /rootfs/ instead of / -*/ -func getMountpoint(id string) string { - maxlen := 12 - - // we need to preserve filesystem suffix - suffix := strings.SplitN(id, "-", 2) - - if len(suffix) > 1 { - return filepath.Join(id[:maxlen]+"-"+suffix[1], "rootfs", "root") - } - - return filepath.Join(id[:maxlen], "rootfs", "root") -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_test.go b/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_test.go deleted file mode 100644 index 3e22928..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_test.go +++ /dev/null @@ -1,35 +0,0 @@ -// +build linux - -package zfs - -import ( - "testing" - - "github.com/docker/docker/daemon/graphdriver/graphtest" -) - -// This avoids creating a new driver for each test if all tests are run -// Make sure to put new tests between TestZfsSetup and TestZfsTeardown -func TestZfsSetup(t *testing.T) { - graphtest.GetDriver(t, "zfs") -} - -func TestZfsCreateEmpty(t *testing.T) { - graphtest.DriverTestCreateEmpty(t, "zfs") -} - -func TestZfsCreateBase(t *testing.T) { - graphtest.DriverTestCreateBase(t, "zfs") -} - -func TestZfsCreateSnap(t *testing.T) { - graphtest.DriverTestCreateSnap(t, "zfs") -} - -func TestZfsSetQuota(t *testing.T) { - graphtest.DriverTestSetQuota(t, "zfs") -} - -func TestZfsTeardown(t *testing.T) { - graphtest.PutDriver(t) -} diff --git a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_unsupported.go b/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_unsupported.go deleted file mode 100644 index ce8daad..0000000 --- a/vendor/github.com/docker/docker/daemon/graphdriver/zfs/zfs_unsupported.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !linux,!freebsd,!solaris - -package zfs - -func checkRootdirFs(rootdir string) error { - return nil -} - -func getMountpoint(id string) string { - return id -} diff --git a/vendor/github.com/docker/docker/daemon/health.go b/vendor/github.com/docker/docker/daemon/health.go deleted file mode 100644 index 5b01dc0..0000000 --- a/vendor/github.com/docker/docker/daemon/health.go +++ /dev/null @@ -1,341 +0,0 @@ -package daemon - -import ( - "bytes" - "fmt" - "runtime" - "strings" - "sync" - "time" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/strslice" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/exec" -) - -const ( - // Longest healthcheck probe output message to store. Longer messages will be truncated. - maxOutputLen = 4096 - - // Default interval between probe runs (from the end of the first to the start of the second). - // Also the time before the first probe. - defaultProbeInterval = 30 * time.Second - - // The maximum length of time a single probe run should take. If the probe takes longer - // than this, the check is considered to have failed. - defaultProbeTimeout = 30 * time.Second - - // Default number of consecutive failures of the health check - // for the container to be considered unhealthy. - defaultProbeRetries = 3 - - // Maximum number of entries to record - maxLogEntries = 5 -) - -const ( - // Exit status codes that can be returned by the probe command. - - exitStatusHealthy = 0 // Container is healthy - exitStatusUnhealthy = 1 // Container is unhealthy -) - -// probe implementations know how to run a particular type of probe. -type probe interface { - // Perform one run of the check. Returns the exit code and an optional - // short diagnostic string. - run(context.Context, *Daemon, *container.Container) (*types.HealthcheckResult, error) -} - -// cmdProbe implements the "CMD" probe type. -type cmdProbe struct { - // Run the command with the system's default shell instead of execing it directly. - shell bool -} - -// exec the healthcheck command in the container. -// Returns the exit code and probe output (if any) -func (p *cmdProbe) run(ctx context.Context, d *Daemon, container *container.Container) (*types.HealthcheckResult, error) { - - cmdSlice := strslice.StrSlice(container.Config.Healthcheck.Test)[1:] - if p.shell { - cmdSlice = append(getShell(container.Config), cmdSlice...) - } - entrypoint, args := d.getEntrypointAndArgs(strslice.StrSlice{}, cmdSlice) - execConfig := exec.NewConfig() - execConfig.OpenStdin = false - execConfig.OpenStdout = true - execConfig.OpenStderr = true - execConfig.ContainerID = container.ID - execConfig.DetachKeys = []byte{} - execConfig.Entrypoint = entrypoint - execConfig.Args = args - execConfig.Tty = false - execConfig.Privileged = false - execConfig.User = container.Config.User - - d.registerExecCommand(container, execConfig) - d.LogContainerEvent(container, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " ")) - - output := &limitedBuffer{} - err := d.ContainerExecStart(ctx, execConfig.ID, nil, output, output) - if err != nil { - return nil, err - } - info, err := d.getExecConfig(execConfig.ID) - if err != nil { - return nil, err - } - if info.ExitCode == nil { - return nil, fmt.Errorf("Healthcheck for container %s has no exit code!", container.ID) - } - // Note: Go's json package will handle invalid UTF-8 for us - out := output.String() - return &types.HealthcheckResult{ - End: time.Now(), - ExitCode: *info.ExitCode, - Output: out, - }, nil -} - -// Update the container's Status.Health struct based on the latest probe's result. -func handleProbeResult(d *Daemon, c *container.Container, result *types.HealthcheckResult, done chan struct{}) { - c.Lock() - defer c.Unlock() - - // probe may have been cancelled while waiting on lock. Ignore result then - select { - case <-done: - return - default: - } - - retries := c.Config.Healthcheck.Retries - if retries <= 0 { - retries = defaultProbeRetries - } - - h := c.State.Health - oldStatus := h.Status - - if len(h.Log) >= maxLogEntries { - h.Log = append(h.Log[len(h.Log)+1-maxLogEntries:], result) - } else { - h.Log = append(h.Log, result) - } - - if result.ExitCode == exitStatusHealthy { - h.FailingStreak = 0 - h.Status = types.Healthy - } else { - // Failure (including invalid exit code) - h.FailingStreak++ - if h.FailingStreak >= retries { - h.Status = types.Unhealthy - } - // Else we're starting or healthy. Stay in that state. - } - - if oldStatus != h.Status { - d.LogContainerEvent(c, "health_status: "+h.Status) - } -} - -// Run the container's monitoring thread until notified via "stop". -// There is never more than one monitor thread running per container at a time. -func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe) { - probeTimeout := timeoutWithDefault(c.Config.Healthcheck.Timeout, defaultProbeTimeout) - probeInterval := timeoutWithDefault(c.Config.Healthcheck.Interval, defaultProbeInterval) - for { - select { - case <-stop: - logrus.Debugf("Stop healthcheck monitoring for container %s (received while idle)", c.ID) - return - case <-time.After(probeInterval): - logrus.Debugf("Running health check for container %s ...", c.ID) - startTime := time.Now() - ctx, cancelProbe := context.WithTimeout(context.Background(), probeTimeout) - results := make(chan *types.HealthcheckResult) - go func() { - healthChecksCounter.Inc() - result, err := probe.run(ctx, d, c) - if err != nil { - healthChecksFailedCounter.Inc() - logrus.Warnf("Health check for container %s error: %v", c.ID, err) - results <- &types.HealthcheckResult{ - ExitCode: -1, - Output: err.Error(), - Start: startTime, - End: time.Now(), - } - } else { - result.Start = startTime - logrus.Debugf("Health check for container %s done (exitCode=%d)", c.ID, result.ExitCode) - results <- result - } - close(results) - }() - select { - case <-stop: - logrus.Debugf("Stop healthcheck monitoring for container %s (received while probing)", c.ID) - // Stop timeout and kill probe, but don't wait for probe to exit. - cancelProbe() - return - case result := <-results: - handleProbeResult(d, c, result, stop) - // Stop timeout - cancelProbe() - case <-ctx.Done(): - logrus.Debugf("Health check for container %s taking too long", c.ID) - handleProbeResult(d, c, &types.HealthcheckResult{ - ExitCode: -1, - Output: fmt.Sprintf("Health check exceeded timeout (%v)", probeTimeout), - Start: startTime, - End: time.Now(), - }, stop) - cancelProbe() - // Wait for probe to exit (it might take a while to respond to the TERM - // signal and we don't want dying probes to pile up). - <-results - } - } - } -} - -// Get a suitable probe implementation for the container's healthcheck configuration. -// Nil will be returned if no healthcheck was configured or NONE was set. -func getProbe(c *container.Container) probe { - config := c.Config.Healthcheck - if config == nil || len(config.Test) == 0 { - return nil - } - switch config.Test[0] { - case "CMD": - return &cmdProbe{shell: false} - case "CMD-SHELL": - return &cmdProbe{shell: true} - default: - logrus.Warnf("Unknown healthcheck type '%s' (expected 'CMD') in container %s", config.Test[0], c.ID) - return nil - } -} - -// Ensure the health-check monitor is running or not, depending on the current -// state of the container. -// Called from monitor.go, with c locked. -func (d *Daemon) updateHealthMonitor(c *container.Container) { - h := c.State.Health - if h == nil { - return // No healthcheck configured - } - - probe := getProbe(c) - wantRunning := c.Running && !c.Paused && probe != nil - if wantRunning { - if stop := h.OpenMonitorChannel(); stop != nil { - go monitor(d, c, stop, probe) - } - } else { - h.CloseMonitorChannel() - } -} - -// Reset the health state for a newly-started, restarted or restored container. -// initHealthMonitor is called from monitor.go and we should never be running -// two instances at once. -// Called with c locked. -func (d *Daemon) initHealthMonitor(c *container.Container) { - // If no healthcheck is setup then don't init the monitor - if getProbe(c) == nil { - return - } - - // This is needed in case we're auto-restarting - d.stopHealthchecks(c) - - if h := c.State.Health; h != nil { - h.Status = types.Starting - h.FailingStreak = 0 - } else { - h := &container.Health{} - h.Status = types.Starting - c.State.Health = h - } - - d.updateHealthMonitor(c) -} - -// Called when the container is being stopped (whether because the health check is -// failing or for any other reason). -func (d *Daemon) stopHealthchecks(c *container.Container) { - h := c.State.Health - if h != nil { - h.CloseMonitorChannel() - } -} - -// Buffer up to maxOutputLen bytes. Further data is discarded. -type limitedBuffer struct { - buf bytes.Buffer - mu sync.Mutex - truncated bool // indicates that data has been lost -} - -// Append to limitedBuffer while there is room. -func (b *limitedBuffer) Write(data []byte) (int, error) { - b.mu.Lock() - defer b.mu.Unlock() - - bufLen := b.buf.Len() - dataLen := len(data) - keep := min(maxOutputLen-bufLen, dataLen) - if keep > 0 { - b.buf.Write(data[:keep]) - } - if keep < dataLen { - b.truncated = true - } - return dataLen, nil -} - -// The contents of the buffer, with "..." appended if it overflowed. -func (b *limitedBuffer) String() string { - b.mu.Lock() - defer b.mu.Unlock() - - out := b.buf.String() - if b.truncated { - out = out + "..." - } - return out -} - -// If configuredValue is zero, use defaultValue instead. -func timeoutWithDefault(configuredValue time.Duration, defaultValue time.Duration) time.Duration { - if configuredValue == 0 { - return defaultValue - } - return configuredValue -} - -func min(x, y int) int { - if x < y { - return x - } - return y -} - -func getShell(config *containertypes.Config) []string { - if len(config.Shell) != 0 { - return config.Shell - } - if runtime.GOOS != "windows" { - return []string{"/bin/sh", "-c"} - } - return []string{"cmd", "/S", "/C"} -} diff --git a/vendor/github.com/docker/docker/daemon/health_test.go b/vendor/github.com/docker/docker/daemon/health_test.go deleted file mode 100644 index 7e82115..0000000 --- a/vendor/github.com/docker/docker/daemon/health_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package daemon - -import ( - "testing" - "time" - - "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - eventtypes "github.com/docker/docker/api/types/events" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/events" -) - -func reset(c *container.Container) { - c.State = &container.State{} - c.State.Health = &container.Health{} - c.State.Health.Status = types.Starting -} - -func TestNoneHealthcheck(t *testing.T) { - c := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "container_id", - Name: "container_name", - Config: &containertypes.Config{ - Image: "image_name", - Healthcheck: &containertypes.HealthConfig{ - Test: []string{"NONE"}, - }, - }, - State: &container.State{}, - }, - } - daemon := &Daemon{} - - daemon.initHealthMonitor(c) - if c.State.Health != nil { - t.Errorf("Expecting Health to be nil, but was not") - } -} - -func TestHealthStates(t *testing.T) { - e := events.New() - _, l, _ := e.Subscribe() - defer e.Evict(l) - - expect := func(expected string) { - select { - case event := <-l: - ev := event.(eventtypes.Message) - if ev.Status != expected { - t.Errorf("Expecting event %#v, but got %#v\n", expected, ev.Status) - } - case <-time.After(1 * time.Second): - t.Errorf("Expecting event %#v, but got nothing\n", expected) - } - } - - c := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: "container_id", - Name: "container_name", - Config: &containertypes.Config{ - Image: "image_name", - }, - }, - } - daemon := &Daemon{ - EventsService: e, - } - - c.Config.Healthcheck = &containertypes.HealthConfig{ - Retries: 1, - } - - reset(c) - - handleResult := func(startTime time.Time, exitCode int) { - handleProbeResult(daemon, c, &types.HealthcheckResult{ - Start: startTime, - End: startTime, - ExitCode: exitCode, - }, nil) - } - - // starting -> failed -> success -> failed - - handleResult(c.State.StartedAt.Add(1*time.Second), 1) - expect("health_status: unhealthy") - - handleResult(c.State.StartedAt.Add(2*time.Second), 0) - expect("health_status: healthy") - - handleResult(c.State.StartedAt.Add(3*time.Second), 1) - expect("health_status: unhealthy") - - // Test retries - - reset(c) - c.Config.Healthcheck.Retries = 3 - - handleResult(c.State.StartedAt.Add(20*time.Second), 1) - handleResult(c.State.StartedAt.Add(40*time.Second), 1) - if c.State.Health.Status != types.Starting { - t.Errorf("Expecting starting, but got %#v\n", c.State.Health.Status) - } - if c.State.Health.FailingStreak != 2 { - t.Errorf("Expecting FailingStreak=2, but got %d\n", c.State.Health.FailingStreak) - } - handleResult(c.State.StartedAt.Add(60*time.Second), 1) - expect("health_status: unhealthy") - - handleResult(c.State.StartedAt.Add(80*time.Second), 0) - expect("health_status: healthy") - if c.State.Health.FailingStreak != 0 { - t.Errorf("Expecting FailingStreak=0, but got %d\n", c.State.Health.FailingStreak) - } -} diff --git a/vendor/github.com/docker/docker/daemon/image.go b/vendor/github.com/docker/docker/daemon/image.go deleted file mode 100644 index 32a8d77..0000000 --- a/vendor/github.com/docker/docker/daemon/image.go +++ /dev/null @@ -1,76 +0,0 @@ -package daemon - -import ( - "fmt" - - "github.com/docker/docker/builder" - "github.com/docker/docker/image" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/reference" -) - -// ErrImageDoesNotExist is error returned when no image can be found for a reference. -type ErrImageDoesNotExist struct { - RefOrID string -} - -func (e ErrImageDoesNotExist) Error() string { - return fmt.Sprintf("no such id: %s", e.RefOrID) -} - -// GetImageID returns an image ID corresponding to the image referred to by -// refOrID. -func (daemon *Daemon) GetImageID(refOrID string) (image.ID, error) { - id, ref, err := reference.ParseIDOrReference(refOrID) - if err != nil { - return "", err - } - if id != "" { - if _, err := daemon.imageStore.Get(image.IDFromDigest(id)); err != nil { - return "", ErrImageDoesNotExist{refOrID} - } - return image.IDFromDigest(id), nil - } - - if id, err := daemon.referenceStore.Get(ref); err == nil { - return image.IDFromDigest(id), nil - } - - // deprecated: repo:shortid https://github.com/docker/docker/pull/799 - if tagged, ok := ref.(reference.NamedTagged); ok { - if tag := tagged.Tag(); stringid.IsShortID(stringid.TruncateID(tag)) { - if id, err := daemon.imageStore.Search(tag); err == nil { - for _, namedRef := range daemon.referenceStore.References(id.Digest()) { - if namedRef.Name() == ref.Name() { - return id, nil - } - } - } - } - } - - // Search based on ID - if id, err := daemon.imageStore.Search(refOrID); err == nil { - return id, nil - } - - return "", ErrImageDoesNotExist{refOrID} -} - -// GetImage returns an image corresponding to the image referred to by refOrID. -func (daemon *Daemon) GetImage(refOrID string) (*image.Image, error) { - imgID, err := daemon.GetImageID(refOrID) - if err != nil { - return nil, err - } - return daemon.imageStore.Get(imgID) -} - -// GetImageOnBuild looks up a Docker image referenced by `name`. -func (daemon *Daemon) GetImageOnBuild(name string) (builder.Image, error) { - img, err := daemon.GetImage(name) - if err != nil { - return nil, err - } - return img, nil -} diff --git a/vendor/github.com/docker/docker/daemon/image_delete.go b/vendor/github.com/docker/docker/daemon/image_delete.go deleted file mode 100644 index 3e3c142..0000000 --- a/vendor/github.com/docker/docker/daemon/image_delete.go +++ /dev/null @@ -1,412 +0,0 @@ -package daemon - -import ( - "fmt" - "strings" - "time" - - "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/types" - "github.com/docker/docker/container" - "github.com/docker/docker/image" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/reference" -) - -type conflictType int - -const ( - conflictDependentChild conflictType = (1 << iota) - conflictRunningContainer - conflictActiveReference - conflictStoppedContainer - conflictHard = conflictDependentChild | conflictRunningContainer - conflictSoft = conflictActiveReference | conflictStoppedContainer -) - -// ImageDelete deletes the image referenced by the given imageRef from this -// daemon. The given imageRef can be an image ID, ID prefix, or a repository -// reference (with an optional tag or digest, defaulting to the tag name -// "latest"). There is differing behavior depending on whether the given -// imageRef is a repository reference or not. -// -// If the given imageRef is a repository reference then that repository -// reference will be removed. However, if there exists any containers which -// were created using the same image reference then the repository reference -// cannot be removed unless either there are other repository references to the -// same image or force is true. Following removal of the repository reference, -// the referenced image itself will attempt to be deleted as described below -// but quietly, meaning any image delete conflicts will cause the image to not -// be deleted and the conflict will not be reported. -// -// There may be conflicts preventing deletion of an image and these conflicts -// are divided into two categories grouped by their severity: -// -// Hard Conflict: -// - a pull or build using the image. -// - any descendant image. -// - any running container using the image. -// -// Soft Conflict: -// - any stopped container using the image. -// - any repository tag or digest references to the image. -// -// The image cannot be removed if there are any hard conflicts and can be -// removed if there are soft conflicts only if force is true. -// -// If prune is true, ancestor images will each attempt to be deleted quietly, -// meaning any delete conflicts will cause the image to not be deleted and the -// conflict will not be reported. -// -// FIXME: remove ImageDelete's dependency on Daemon, then move to the graph -// package. This would require that we no longer need the daemon to determine -// whether images are being used by a stopped or running container. -func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) { - start := time.Now() - records := []types.ImageDelete{} - - imgID, err := daemon.GetImageID(imageRef) - if err != nil { - return nil, daemon.imageNotExistToErrcode(err) - } - - repoRefs := daemon.referenceStore.References(imgID.Digest()) - - var removedRepositoryRef bool - if !isImageIDPrefix(imgID.String(), imageRef) { - // A repository reference was given and should be removed - // first. We can only remove this reference if either force is - // true, there are multiple repository references to this - // image, or there are no containers using the given reference. - if !force && isSingleReference(repoRefs) { - if container := daemon.getContainerUsingImage(imgID); container != nil { - // If we removed the repository reference then - // this image would remain "dangling" and since - // we really want to avoid that the client must - // explicitly force its removal. - err := fmt.Errorf("conflict: unable to remove repository reference %q (must force) - container %s is using its referenced image %s", imageRef, stringid.TruncateID(container.ID), stringid.TruncateID(imgID.String())) - return nil, errors.NewRequestConflictError(err) - } - } - - parsedRef, err := reference.ParseNamed(imageRef) - if err != nil { - return nil, err - } - - parsedRef, err = daemon.removeImageRef(parsedRef) - if err != nil { - return nil, err - } - - untaggedRecord := types.ImageDelete{Untagged: parsedRef.String()} - - daemon.LogImageEvent(imgID.String(), imgID.String(), "untag") - records = append(records, untaggedRecord) - - repoRefs = daemon.referenceStore.References(imgID.Digest()) - - // If a tag reference was removed and the only remaining - // references to the same repository are digest references, - // then clean up those digest references. - if _, isCanonical := parsedRef.(reference.Canonical); !isCanonical { - foundRepoTagRef := false - for _, repoRef := range repoRefs { - if _, repoRefIsCanonical := repoRef.(reference.Canonical); !repoRefIsCanonical && parsedRef.Name() == repoRef.Name() { - foundRepoTagRef = true - break - } - } - if !foundRepoTagRef { - // Remove canonical references from same repository - remainingRefs := []reference.Named{} - for _, repoRef := range repoRefs { - if _, repoRefIsCanonical := repoRef.(reference.Canonical); repoRefIsCanonical && parsedRef.Name() == repoRef.Name() { - if _, err := daemon.removeImageRef(repoRef); err != nil { - return records, err - } - - untaggedRecord := types.ImageDelete{Untagged: repoRef.String()} - records = append(records, untaggedRecord) - } else { - remainingRefs = append(remainingRefs, repoRef) - - } - } - repoRefs = remainingRefs - } - } - - // If it has remaining references then the untag finished the remove - if len(repoRefs) > 0 { - return records, nil - } - - removedRepositoryRef = true - } else { - // If an ID reference was given AND there is at most one tag - // reference to the image AND all references are within one - // repository, then remove all references. - if isSingleReference(repoRefs) { - c := conflictHard - if !force { - c |= conflictSoft &^ conflictActiveReference - } - if conflict := daemon.checkImageDeleteConflict(imgID, c); conflict != nil { - return nil, conflict - } - - for _, repoRef := range repoRefs { - parsedRef, err := daemon.removeImageRef(repoRef) - if err != nil { - return nil, err - } - - untaggedRecord := types.ImageDelete{Untagged: parsedRef.String()} - - daemon.LogImageEvent(imgID.String(), imgID.String(), "untag") - records = append(records, untaggedRecord) - } - } - } - - if err := daemon.imageDeleteHelper(imgID, &records, force, prune, removedRepositoryRef); err != nil { - return nil, err - } - - imageActions.WithValues("delete").UpdateSince(start) - - return records, nil -} - -// isSingleReference returns true when all references are from one repository -// and there is at most one tag. Returns false for empty input. -func isSingleReference(repoRefs []reference.Named) bool { - if len(repoRefs) <= 1 { - return len(repoRefs) == 1 - } - var singleRef reference.Named - canonicalRefs := map[string]struct{}{} - for _, repoRef := range repoRefs { - if _, isCanonical := repoRef.(reference.Canonical); isCanonical { - canonicalRefs[repoRef.Name()] = struct{}{} - } else if singleRef == nil { - singleRef = repoRef - } else { - return false - } - } - if singleRef == nil { - // Just use first canonical ref - singleRef = repoRefs[0] - } - _, ok := canonicalRefs[singleRef.Name()] - return len(canonicalRefs) == 1 && ok -} - -// isImageIDPrefix returns whether the given possiblePrefix is a prefix of the -// given imageID. -func isImageIDPrefix(imageID, possiblePrefix string) bool { - if strings.HasPrefix(imageID, possiblePrefix) { - return true - } - - if i := strings.IndexRune(imageID, ':'); i >= 0 { - return strings.HasPrefix(imageID[i+1:], possiblePrefix) - } - - return false -} - -// getContainerUsingImage returns a container that was created using the given -// imageID. Returns nil if there is no such container. -func (daemon *Daemon) getContainerUsingImage(imageID image.ID) *container.Container { - return daemon.containers.First(func(c *container.Container) bool { - return c.ImageID == imageID - }) -} - -// removeImageRef attempts to parse and remove the given image reference from -// this daemon's store of repository tag/digest references. The given -// repositoryRef must not be an image ID but a repository name followed by an -// optional tag or digest reference. If tag or digest is omitted, the default -// tag is used. Returns the resolved image reference and an error. -func (daemon *Daemon) removeImageRef(ref reference.Named) (reference.Named, error) { - ref = reference.WithDefaultTag(ref) - // Ignore the boolean value returned, as far as we're concerned, this - // is an idempotent operation and it's okay if the reference didn't - // exist in the first place. - _, err := daemon.referenceStore.Delete(ref) - - return ref, err -} - -// removeAllReferencesToImageID attempts to remove every reference to the given -// imgID from this daemon's store of repository tag/digest references. Returns -// on the first encountered error. Removed references are logged to this -// daemon's event service. An "Untagged" types.ImageDelete is added to the -// given list of records. -func (daemon *Daemon) removeAllReferencesToImageID(imgID image.ID, records *[]types.ImageDelete) error { - imageRefs := daemon.referenceStore.References(imgID.Digest()) - - for _, imageRef := range imageRefs { - parsedRef, err := daemon.removeImageRef(imageRef) - if err != nil { - return err - } - - untaggedRecord := types.ImageDelete{Untagged: parsedRef.String()} - - daemon.LogImageEvent(imgID.String(), imgID.String(), "untag") - *records = append(*records, untaggedRecord) - } - - return nil -} - -// ImageDeleteConflict holds a soft or hard conflict and an associated error. -// Implements the error interface. -type imageDeleteConflict struct { - hard bool - used bool - imgID image.ID - message string -} - -func (idc *imageDeleteConflict) Error() string { - var forceMsg string - if idc.hard { - forceMsg = "cannot be forced" - } else { - forceMsg = "must be forced" - } - - return fmt.Sprintf("conflict: unable to delete %s (%s) - %s", stringid.TruncateID(idc.imgID.String()), forceMsg, idc.message) -} - -// imageDeleteHelper attempts to delete the given image from this daemon. If -// the image has any hard delete conflicts (child images or running containers -// using the image) then it cannot be deleted. If the image has any soft delete -// conflicts (any tags/digests referencing the image or any stopped container -// using the image) then it can only be deleted if force is true. If the delete -// succeeds and prune is true, the parent images are also deleted if they do -// not have any soft or hard delete conflicts themselves. Any deleted images -// and untagged references are appended to the given records. If any error or -// conflict is encountered, it will be returned immediately without deleting -// the image. If quiet is true, any encountered conflicts will be ignored and -// the function will return nil immediately without deleting the image. -func (daemon *Daemon) imageDeleteHelper(imgID image.ID, records *[]types.ImageDelete, force, prune, quiet bool) error { - // First, determine if this image has any conflicts. Ignore soft conflicts - // if force is true. - c := conflictHard - if !force { - c |= conflictSoft - } - if conflict := daemon.checkImageDeleteConflict(imgID, c); conflict != nil { - if quiet && (!daemon.imageIsDangling(imgID) || conflict.used) { - // Ignore conflicts UNLESS the image is "dangling" or not being used in - // which case we want the user to know. - return nil - } - - // There was a conflict and it's either a hard conflict OR we are not - // forcing deletion on soft conflicts. - return conflict - } - - parent, err := daemon.imageStore.GetParent(imgID) - if err != nil { - // There may be no parent - parent = "" - } - - // Delete all repository tag/digest references to this image. - if err := daemon.removeAllReferencesToImageID(imgID, records); err != nil { - return err - } - - removedLayers, err := daemon.imageStore.Delete(imgID) - if err != nil { - return err - } - - daemon.LogImageEvent(imgID.String(), imgID.String(), "delete") - *records = append(*records, types.ImageDelete{Deleted: imgID.String()}) - for _, removedLayer := range removedLayers { - *records = append(*records, types.ImageDelete{Deleted: removedLayer.ChainID.String()}) - } - - if !prune || parent == "" { - return nil - } - - // We need to prune the parent image. This means delete it if there are - // no tags/digests referencing it and there are no containers using it ( - // either running or stopped). - // Do not force prunings, but do so quietly (stopping on any encountered - // conflicts). - return daemon.imageDeleteHelper(parent, records, false, true, true) -} - -// checkImageDeleteConflict determines whether there are any conflicts -// preventing deletion of the given image from this daemon. A hard conflict is -// any image which has the given image as a parent or any running container -// using the image. A soft conflict is any tags/digest referencing the given -// image or any stopped container using the image. If ignoreSoftConflicts is -// true, this function will not check for soft conflict conditions. -func (daemon *Daemon) checkImageDeleteConflict(imgID image.ID, mask conflictType) *imageDeleteConflict { - // Check if the image has any descendant images. - if mask&conflictDependentChild != 0 && len(daemon.imageStore.Children(imgID)) > 0 { - return &imageDeleteConflict{ - hard: true, - imgID: imgID, - message: "image has dependent child images", - } - } - - if mask&conflictRunningContainer != 0 { - // Check if any running container is using the image. - running := func(c *container.Container) bool { - return c.IsRunning() && c.ImageID == imgID - } - if container := daemon.containers.First(running); container != nil { - return &imageDeleteConflict{ - imgID: imgID, - hard: true, - used: true, - message: fmt.Sprintf("image is being used by running container %s", stringid.TruncateID(container.ID)), - } - } - } - - // Check if any repository tags/digest reference this image. - if mask&conflictActiveReference != 0 && len(daemon.referenceStore.References(imgID.Digest())) > 0 { - return &imageDeleteConflict{ - imgID: imgID, - message: "image is referenced in multiple repositories", - } - } - - if mask&conflictStoppedContainer != 0 { - // Check if any stopped containers reference this image. - stopped := func(c *container.Container) bool { - return !c.IsRunning() && c.ImageID == imgID - } - if container := daemon.containers.First(stopped); container != nil { - return &imageDeleteConflict{ - imgID: imgID, - used: true, - message: fmt.Sprintf("image is being used by stopped container %s", stringid.TruncateID(container.ID)), - } - } - } - - return nil -} - -// imageIsDangling returns whether the given image is "dangling" which means -// that there are no repository references to the given image and it has no -// child images. -func (daemon *Daemon) imageIsDangling(imgID image.ID) bool { - return !(len(daemon.referenceStore.References(imgID.Digest())) > 0 || len(daemon.imageStore.Children(imgID)) > 0) -} diff --git a/vendor/github.com/docker/docker/daemon/image_exporter.go b/vendor/github.com/docker/docker/daemon/image_exporter.go deleted file mode 100644 index 95d1d3d..0000000 --- a/vendor/github.com/docker/docker/daemon/image_exporter.go +++ /dev/null @@ -1,25 +0,0 @@ -package daemon - -import ( - "io" - - "github.com/docker/docker/image/tarexport" -) - -// ExportImage exports a list of images to the given output stream. The -// exported images are archived into a tar when written to the output -// stream. All images with the given tag and all versions containing -// the same tag are exported. names is the set of tags to export, and -// outStream is the writer which the images are written to. -func (daemon *Daemon) ExportImage(names []string, outStream io.Writer) error { - imageExporter := tarexport.NewTarExporter(daemon.imageStore, daemon.layerStore, daemon.referenceStore, daemon) - return imageExporter.Save(names, outStream) -} - -// LoadImage uploads a set of images into the repository. This is the -// complement of ImageExport. The input stream is an uncompressed tar -// ball containing images and metadata. -func (daemon *Daemon) LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error { - imageExporter := tarexport.NewTarExporter(daemon.imageStore, daemon.layerStore, daemon.referenceStore, daemon) - return imageExporter.Load(inTar, outStream, quiet) -} diff --git a/vendor/github.com/docker/docker/daemon/image_history.go b/vendor/github.com/docker/docker/daemon/image_history.go deleted file mode 100644 index 839dd12..0000000 --- a/vendor/github.com/docker/docker/daemon/image_history.go +++ /dev/null @@ -1,84 +0,0 @@ -package daemon - -import ( - "fmt" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/layer" - "github.com/docker/docker/reference" -) - -// ImageHistory returns a slice of ImageHistory structures for the specified image -// name by walking the image lineage. -func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) { - start := time.Now() - img, err := daemon.GetImage(name) - if err != nil { - return nil, err - } - - history := []*types.ImageHistory{} - - layerCounter := 0 - rootFS := *img.RootFS - rootFS.DiffIDs = nil - - for _, h := range img.History { - var layerSize int64 - - if !h.EmptyLayer { - if len(img.RootFS.DiffIDs) <= layerCounter { - return nil, fmt.Errorf("too many non-empty layers in History section") - } - - rootFS.Append(img.RootFS.DiffIDs[layerCounter]) - l, err := daemon.layerStore.Get(rootFS.ChainID()) - if err != nil { - return nil, err - } - layerSize, err = l.DiffSize() - layer.ReleaseAndLog(daemon.layerStore, l) - if err != nil { - return nil, err - } - - layerCounter++ - } - - history = append([]*types.ImageHistory{{ - ID: "", - Created: h.Created.Unix(), - CreatedBy: h.CreatedBy, - Comment: h.Comment, - Size: layerSize, - }}, history...) - } - - // Fill in image IDs and tags - histImg := img - id := img.ID() - for _, h := range history { - h.ID = id.String() - - var tags []string - for _, r := range daemon.referenceStore.References(id.Digest()) { - if _, ok := r.(reference.NamedTagged); ok { - tags = append(tags, r.String()) - } - } - - h.Tags = tags - - id = histImg.Parent - if id == "" { - break - } - histImg, err = daemon.GetImage(id.String()) - if err != nil { - break - } - } - imageActions.WithValues("history").UpdateSince(start) - return history, nil -} diff --git a/vendor/github.com/docker/docker/daemon/image_inspect.go b/vendor/github.com/docker/docker/daemon/image_inspect.go deleted file mode 100644 index ebf9124..0000000 --- a/vendor/github.com/docker/docker/daemon/image_inspect.go +++ /dev/null @@ -1,82 +0,0 @@ -package daemon - -import ( - "fmt" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/layer" - "github.com/docker/docker/reference" -) - -// LookupImage looks up an image by name and returns it as an ImageInspect -// structure. -func (daemon *Daemon) LookupImage(name string) (*types.ImageInspect, error) { - img, err := daemon.GetImage(name) - if err != nil { - return nil, fmt.Errorf("No such image: %s", name) - } - - refs := daemon.referenceStore.References(img.ID().Digest()) - repoTags := []string{} - repoDigests := []string{} - for _, ref := range refs { - switch ref.(type) { - case reference.NamedTagged: - repoTags = append(repoTags, ref.String()) - case reference.Canonical: - repoDigests = append(repoDigests, ref.String()) - } - } - - var size int64 - var layerMetadata map[string]string - layerID := img.RootFS.ChainID() - if layerID != "" { - l, err := daemon.layerStore.Get(layerID) - if err != nil { - return nil, err - } - defer layer.ReleaseAndLog(daemon.layerStore, l) - size, err = l.Size() - if err != nil { - return nil, err - } - - layerMetadata, err = l.Metadata() - if err != nil { - return nil, err - } - } - - comment := img.Comment - if len(comment) == 0 && len(img.History) > 0 { - comment = img.History[len(img.History)-1].Comment - } - - imageInspect := &types.ImageInspect{ - ID: img.ID().String(), - RepoTags: repoTags, - RepoDigests: repoDigests, - Parent: img.Parent.String(), - Comment: comment, - Created: img.Created.Format(time.RFC3339Nano), - Container: img.Container, - ContainerConfig: &img.ContainerConfig, - DockerVersion: img.DockerVersion, - Author: img.Author, - Config: img.Config, - Architecture: img.Architecture, - Os: img.OS, - OsVersion: img.OSVersion, - Size: size, - VirtualSize: size, // TODO: field unused, deprecate - RootFS: rootFSToAPIType(img.RootFS), - } - - imageInspect.GraphDriver.Name = daemon.GraphDriverName() - - imageInspect.GraphDriver.Data = layerMetadata - - return imageInspect, nil -} diff --git a/vendor/github.com/docker/docker/daemon/image_pull.go b/vendor/github.com/docker/docker/daemon/image_pull.go deleted file mode 100644 index 2157d15..0000000 --- a/vendor/github.com/docker/docker/daemon/image_pull.go +++ /dev/null @@ -1,149 +0,0 @@ -package daemon - -import ( - "io" - "strings" - - dist "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types" - "github.com/docker/docker/builder" - "github.com/docker/docker/distribution" - progressutils "github.com/docker/docker/distribution/utils" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "golang.org/x/net/context" -) - -// PullImage initiates a pull operation. image is the repository name to pull, and -// tag may be either empty, or indicate a specific tag to pull. -func (daemon *Daemon) PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error { - // Special case: "pull -a" may send an image name with a - // trailing :. This is ugly, but let's not break API - // compatibility. - image = strings.TrimSuffix(image, ":") - - ref, err := reference.ParseNamed(image) - if err != nil { - return err - } - - if tag != "" { - // The "tag" could actually be a digest. - var dgst digest.Digest - dgst, err = digest.ParseDigest(tag) - if err == nil { - ref, err = reference.WithDigest(reference.TrimNamed(ref), dgst) - } else { - ref, err = reference.WithTag(ref, tag) - } - if err != nil { - return err - } - } - - return daemon.pullImageWithReference(ctx, ref, metaHeaders, authConfig, outStream) -} - -// PullOnBuild tells Docker to pull image referenced by `name`. -func (daemon *Daemon) PullOnBuild(ctx context.Context, name string, authConfigs map[string]types.AuthConfig, output io.Writer) (builder.Image, error) { - ref, err := reference.ParseNamed(name) - if err != nil { - return nil, err - } - ref = reference.WithDefaultTag(ref) - - pullRegistryAuth := &types.AuthConfig{} - if len(authConfigs) > 0 { - // The request came with a full auth config file, we prefer to use that - repoInfo, err := daemon.RegistryService.ResolveRepository(ref) - if err != nil { - return nil, err - } - - resolvedConfig := registry.ResolveAuthConfig( - authConfigs, - repoInfo.Index, - ) - pullRegistryAuth = &resolvedConfig - } - - if err := daemon.pullImageWithReference(ctx, ref, nil, pullRegistryAuth, output); err != nil { - return nil, err - } - return daemon.GetImage(name) -} - -func (daemon *Daemon) pullImageWithReference(ctx context.Context, ref reference.Named, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error { - // Include a buffer so that slow client connections don't affect - // transfer performance. - progressChan := make(chan progress.Progress, 100) - - writesDone := make(chan struct{}) - - ctx, cancelFunc := context.WithCancel(ctx) - - go func() { - progressutils.WriteDistributionProgress(cancelFunc, outStream, progressChan) - close(writesDone) - }() - - imagePullConfig := &distribution.ImagePullConfig{ - Config: distribution.Config{ - MetaHeaders: metaHeaders, - AuthConfig: authConfig, - ProgressOutput: progress.ChanOutput(progressChan), - RegistryService: daemon.RegistryService, - ImageEventLogger: daemon.LogImageEvent, - MetadataStore: daemon.distributionMetadataStore, - ImageStore: distribution.NewImageConfigStoreFromStore(daemon.imageStore), - ReferenceStore: daemon.referenceStore, - }, - DownloadManager: daemon.downloadManager, - Schema2Types: distribution.ImageTypes, - } - - err := distribution.Pull(ctx, ref, imagePullConfig) - close(progressChan) - <-writesDone - return err -} - -// GetRepository returns a repository from the registry. -func (daemon *Daemon) GetRepository(ctx context.Context, ref reference.NamedTagged, authConfig *types.AuthConfig) (dist.Repository, bool, error) { - // get repository info - repoInfo, err := daemon.RegistryService.ResolveRepository(ref) - if err != nil { - return nil, false, err - } - // makes sure name is not empty or `scratch` - if err := distribution.ValidateRepoName(repoInfo.Name()); err != nil { - return nil, false, err - } - - // get endpoints - endpoints, err := daemon.RegistryService.LookupPullEndpoints(repoInfo.Hostname()) - if err != nil { - return nil, false, err - } - - // retrieve repository - var ( - confirmedV2 bool - repository dist.Repository - lastError error - ) - - for _, endpoint := range endpoints { - if endpoint.Version == registry.APIVersion1 { - continue - } - - repository, confirmedV2, lastError = distribution.NewV2Repository(ctx, repoInfo, endpoint, nil, authConfig, "pull") - if lastError == nil && confirmedV2 { - break - } - } - return repository, confirmedV2, lastError -} diff --git a/vendor/github.com/docker/docker/daemon/image_push.go b/vendor/github.com/docker/docker/daemon/image_push.go deleted file mode 100644 index e6382c7..0000000 --- a/vendor/github.com/docker/docker/daemon/image_push.go +++ /dev/null @@ -1,63 +0,0 @@ -package daemon - -import ( - "io" - - "github.com/docker/distribution/manifest/schema2" - "github.com/docker/docker/api/types" - "github.com/docker/docker/distribution" - progressutils "github.com/docker/docker/distribution/utils" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/reference" - "golang.org/x/net/context" -) - -// PushImage initiates a push operation on the repository named localName. -func (daemon *Daemon) PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error { - ref, err := reference.ParseNamed(image) - if err != nil { - return err - } - if tag != "" { - // Push by digest is not supported, so only tags are supported. - ref, err = reference.WithTag(ref, tag) - if err != nil { - return err - } - } - - // Include a buffer so that slow client connections don't affect - // transfer performance. - progressChan := make(chan progress.Progress, 100) - - writesDone := make(chan struct{}) - - ctx, cancelFunc := context.WithCancel(ctx) - - go func() { - progressutils.WriteDistributionProgress(cancelFunc, outStream, progressChan) - close(writesDone) - }() - - imagePushConfig := &distribution.ImagePushConfig{ - Config: distribution.Config{ - MetaHeaders: metaHeaders, - AuthConfig: authConfig, - ProgressOutput: progress.ChanOutput(progressChan), - RegistryService: daemon.RegistryService, - ImageEventLogger: daemon.LogImageEvent, - MetadataStore: daemon.distributionMetadataStore, - ImageStore: distribution.NewImageConfigStoreFromStore(daemon.imageStore), - ReferenceStore: daemon.referenceStore, - }, - ConfigMediaType: schema2.MediaTypeImageConfig, - LayerStore: distribution.NewLayerProviderFromStore(daemon.layerStore), - TrustKey: daemon.trustKey, - UploadManager: daemon.uploadManager, - } - - err = distribution.Push(ctx, ref, imagePushConfig) - close(progressChan) - <-writesDone - return err -} diff --git a/vendor/github.com/docker/docker/daemon/image_tag.go b/vendor/github.com/docker/docker/daemon/image_tag.go deleted file mode 100644 index 36fa3b4..0000000 --- a/vendor/github.com/docker/docker/daemon/image_tag.go +++ /dev/null @@ -1,37 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/image" - "github.com/docker/docker/reference" -) - -// TagImage creates the tag specified by newTag, pointing to the image named -// imageName (alternatively, imageName can also be an image ID). -func (daemon *Daemon) TagImage(imageName, repository, tag string) error { - imageID, err := daemon.GetImageID(imageName) - if err != nil { - return err - } - - newTag, err := reference.WithName(repository) - if err != nil { - return err - } - if tag != "" { - if newTag, err = reference.WithTag(newTag, tag); err != nil { - return err - } - } - - return daemon.TagImageWithReference(imageID, newTag) -} - -// TagImageWithReference adds the given reference to the image ID provided. -func (daemon *Daemon) TagImageWithReference(imageID image.ID, newTag reference.Named) error { - if err := daemon.referenceStore.AddTag(newTag, imageID.Digest(), true); err != nil { - return err - } - - daemon.LogImageEvent(imageID.String(), newTag.String(), "tag") - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/images.go b/vendor/github.com/docker/docker/daemon/images.go deleted file mode 100644 index 88fb8f8..0000000 --- a/vendor/github.com/docker/docker/daemon/images.go +++ /dev/null @@ -1,331 +0,0 @@ -package daemon - -import ( - "encoding/json" - "fmt" - "sort" - "time" - - "github.com/pkg/errors" - - "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/container" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" -) - -var acceptedImageFilterTags = map[string]bool{ - "dangling": true, - "label": true, - "before": true, - "since": true, - "reference": true, -} - -// byCreated is a temporary type used to sort a list of images by creation -// time. -type byCreated []*types.ImageSummary - -func (r byCreated) Len() int { return len(r) } -func (r byCreated) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r byCreated) Less(i, j int) bool { return r[i].Created < r[j].Created } - -// Map returns a map of all images in the ImageStore -func (daemon *Daemon) Map() map[image.ID]*image.Image { - return daemon.imageStore.Map() -} - -// Images returns a filtered list of images. filterArgs is a JSON-encoded set -// of filter arguments which will be interpreted by api/types/filters. -// filter is a shell glob string applied to repository names. The argument -// named all controls whether all images in the graph are filtered, or just -// the heads. -func (daemon *Daemon) Images(imageFilters filters.Args, all bool, withExtraAttrs bool) ([]*types.ImageSummary, error) { - var ( - allImages map[image.ID]*image.Image - err error - danglingOnly = false - ) - - if err := imageFilters.Validate(acceptedImageFilterTags); err != nil { - return nil, err - } - - if imageFilters.Include("dangling") { - if imageFilters.ExactMatch("dangling", "true") { - danglingOnly = true - } else if !imageFilters.ExactMatch("dangling", "false") { - return nil, fmt.Errorf("Invalid filter 'dangling=%s'", imageFilters.Get("dangling")) - } - } - if danglingOnly { - allImages = daemon.imageStore.Heads() - } else { - allImages = daemon.imageStore.Map() - } - - var beforeFilter, sinceFilter *image.Image - err = imageFilters.WalkValues("before", func(value string) error { - beforeFilter, err = daemon.GetImage(value) - return err - }) - if err != nil { - return nil, err - } - - err = imageFilters.WalkValues("since", func(value string) error { - sinceFilter, err = daemon.GetImage(value) - return err - }) - if err != nil { - return nil, err - } - - images := []*types.ImageSummary{} - var imagesMap map[*image.Image]*types.ImageSummary - var layerRefs map[layer.ChainID]int - var allLayers map[layer.ChainID]layer.Layer - var allContainers []*container.Container - - for id, img := range allImages { - if beforeFilter != nil { - if img.Created.Equal(beforeFilter.Created) || img.Created.After(beforeFilter.Created) { - continue - } - } - - if sinceFilter != nil { - if img.Created.Equal(sinceFilter.Created) || img.Created.Before(sinceFilter.Created) { - continue - } - } - - if imageFilters.Include("label") { - // Very old image that do not have image.Config (or even labels) - if img.Config == nil { - continue - } - // We are now sure image.Config is not nil - if !imageFilters.MatchKVList("label", img.Config.Labels) { - continue - } - } - - layerID := img.RootFS.ChainID() - var size int64 - if layerID != "" { - l, err := daemon.layerStore.Get(layerID) - if err != nil { - return nil, err - } - - size, err = l.Size() - layer.ReleaseAndLog(daemon.layerStore, l) - if err != nil { - return nil, err - } - } - - newImage := newImage(img, size) - - for _, ref := range daemon.referenceStore.References(id.Digest()) { - if imageFilters.Include("reference") { - var found bool - var matchErr error - for _, pattern := range imageFilters.Get("reference") { - found, matchErr = reference.Match(pattern, ref) - if matchErr != nil { - return nil, matchErr - } - } - if !found { - continue - } - } - if _, ok := ref.(reference.Canonical); ok { - newImage.RepoDigests = append(newImage.RepoDigests, ref.String()) - } - if _, ok := ref.(reference.NamedTagged); ok { - newImage.RepoTags = append(newImage.RepoTags, ref.String()) - } - } - if newImage.RepoDigests == nil && newImage.RepoTags == nil { - if all || len(daemon.imageStore.Children(id)) == 0 { - - if imageFilters.Include("dangling") && !danglingOnly { - //dangling=false case, so dangling image is not needed - continue - } - if imageFilters.Include("reference") { // skip images with no references if filtering by reference - continue - } - newImage.RepoDigests = []string{"@"} - newImage.RepoTags = []string{":"} - } else { - continue - } - } else if danglingOnly && len(newImage.RepoTags) > 0 { - continue - } - - if withExtraAttrs { - // lazyly init variables - if imagesMap == nil { - allContainers = daemon.List() - allLayers = daemon.layerStore.Map() - imagesMap = make(map[*image.Image]*types.ImageSummary) - layerRefs = make(map[layer.ChainID]int) - } - - // Get container count - newImage.Containers = 0 - for _, c := range allContainers { - if c.ImageID == id { - newImage.Containers++ - } - } - - // count layer references - rootFS := *img.RootFS - rootFS.DiffIDs = nil - for _, id := range img.RootFS.DiffIDs { - rootFS.Append(id) - chid := rootFS.ChainID() - layerRefs[chid]++ - if _, ok := allLayers[chid]; !ok { - return nil, fmt.Errorf("layer %v was not found (corruption?)", chid) - } - } - imagesMap[img] = newImage - } - - images = append(images, newImage) - } - - if withExtraAttrs { - // Get Shared sizes - for img, newImage := range imagesMap { - rootFS := *img.RootFS - rootFS.DiffIDs = nil - - newImage.SharedSize = 0 - for _, id := range img.RootFS.DiffIDs { - rootFS.Append(id) - chid := rootFS.ChainID() - - diffSize, err := allLayers[chid].DiffSize() - if err != nil { - return nil, err - } - - if layerRefs[chid] > 1 { - newImage.SharedSize += diffSize - } - } - } - } - - sort.Sort(sort.Reverse(byCreated(images))) - - return images, nil -} - -// SquashImage creates a new image with the diff of the specified image and the specified parent. -// This new image contains only the layers from it's parent + 1 extra layer which contains the diff of all the layers in between. -// The existing image(s) is not destroyed. -// If no parent is specified, a new image with the diff of all the specified image's layers merged into a new layer that has no parents. -func (daemon *Daemon) SquashImage(id, parent string) (string, error) { - img, err := daemon.imageStore.Get(image.ID(id)) - if err != nil { - return "", err - } - - var parentImg *image.Image - var parentChainID layer.ChainID - if len(parent) != 0 { - parentImg, err = daemon.imageStore.Get(image.ID(parent)) - if err != nil { - return "", errors.Wrap(err, "error getting specified parent layer") - } - parentChainID = parentImg.RootFS.ChainID() - } else { - rootFS := image.NewRootFS() - parentImg = &image.Image{RootFS: rootFS} - } - - l, err := daemon.layerStore.Get(img.RootFS.ChainID()) - if err != nil { - return "", errors.Wrap(err, "error getting image layer") - } - defer daemon.layerStore.Release(l) - - ts, err := l.TarStreamFrom(parentChainID) - if err != nil { - return "", errors.Wrapf(err, "error getting tar stream to parent") - } - defer ts.Close() - - newL, err := daemon.layerStore.Register(ts, parentChainID) - if err != nil { - return "", errors.Wrap(err, "error registering layer") - } - defer daemon.layerStore.Release(newL) - - var newImage image.Image - newImage = *img - newImage.RootFS = nil - - var rootFS image.RootFS - rootFS = *parentImg.RootFS - rootFS.DiffIDs = append(rootFS.DiffIDs, newL.DiffID()) - newImage.RootFS = &rootFS - - for i, hi := range newImage.History { - if i >= len(parentImg.History) { - hi.EmptyLayer = true - } - newImage.History[i] = hi - } - - now := time.Now() - var historyComment string - if len(parent) > 0 { - historyComment = fmt.Sprintf("merge %s to %s", id, parent) - } else { - historyComment = fmt.Sprintf("create new from %s", id) - } - - newImage.History = append(newImage.History, image.History{ - Created: now, - Comment: historyComment, - }) - newImage.Created = now - - b, err := json.Marshal(&newImage) - if err != nil { - return "", errors.Wrap(err, "error marshalling image config") - } - - newImgID, err := daemon.imageStore.Create(b) - if err != nil { - return "", errors.Wrap(err, "error creating new image after squash") - } - return string(newImgID), nil -} - -func newImage(image *image.Image, virtualSize int64) *types.ImageSummary { - newImage := new(types.ImageSummary) - newImage.ParentID = image.Parent.String() - newImage.ID = image.ID().String() - newImage.Created = image.Created.Unix() - newImage.Size = virtualSize - newImage.VirtualSize = virtualSize - newImage.SharedSize = -1 - newImage.Containers = -1 - if image.Config != nil { - newImage.Labels = image.Config.Labels - } - return newImage -} diff --git a/vendor/github.com/docker/docker/daemon/import.go b/vendor/github.com/docker/docker/daemon/import.go deleted file mode 100644 index c93322b..0000000 --- a/vendor/github.com/docker/docker/daemon/import.go +++ /dev/null @@ -1,135 +0,0 @@ -package daemon - -import ( - "encoding/json" - "errors" - "io" - "net/http" - "net/url" - "runtime" - "time" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/builder/dockerfile" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/httputils" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/streamformatter" - "github.com/docker/docker/reference" -) - -// ImportImage imports an image, getting the archived layer data either from -// inConfig (if src is "-"), or from a URI specified in src. Progress output is -// written to outStream. Repository and tag names can optionally be given in -// the repo and tag arguments, respectively. -func (daemon *Daemon) ImportImage(src string, repository, tag string, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error { - var ( - sf = streamformatter.NewJSONStreamFormatter() - rc io.ReadCloser - resp *http.Response - newRef reference.Named - ) - - if repository != "" { - var err error - newRef, err = reference.ParseNamed(repository) - if err != nil { - return err - } - - if _, isCanonical := newRef.(reference.Canonical); isCanonical { - return errors.New("cannot import digest reference") - } - - if tag != "" { - newRef, err = reference.WithTag(newRef, tag) - if err != nil { - return err - } - } - } - - config, err := dockerfile.BuildFromConfig(&container.Config{}, changes) - if err != nil { - return err - } - if src == "-" { - rc = inConfig - } else { - inConfig.Close() - u, err := url.Parse(src) - if err != nil { - return err - } - if u.Scheme == "" { - u.Scheme = "http" - u.Host = src - u.Path = "" - } - outStream.Write(sf.FormatStatus("", "Downloading from %s", u)) - resp, err = httputils.Download(u.String()) - if err != nil { - return err - } - progressOutput := sf.NewProgressOutput(outStream, true) - rc = progress.NewProgressReader(resp.Body, progressOutput, resp.ContentLength, "", "Importing") - } - - defer rc.Close() - if len(msg) == 0 { - msg = "Imported from " + src - } - - inflatedLayerData, err := archive.DecompressStream(rc) - if err != nil { - return err - } - // TODO: support windows baselayer? - l, err := daemon.layerStore.Register(inflatedLayerData, "") - if err != nil { - return err - } - defer layer.ReleaseAndLog(daemon.layerStore, l) - - created := time.Now().UTC() - imgConfig, err := json.Marshal(&image.Image{ - V1Image: image.V1Image{ - DockerVersion: dockerversion.Version, - Config: config, - Architecture: runtime.GOARCH, - OS: runtime.GOOS, - Created: created, - Comment: msg, - }, - RootFS: &image.RootFS{ - Type: "layers", - DiffIDs: []layer.DiffID{l.DiffID()}, - }, - History: []image.History{{ - Created: created, - Comment: msg, - }}, - }) - if err != nil { - return err - } - - id, err := daemon.imageStore.Create(imgConfig) - if err != nil { - return err - } - - // FIXME: connect with commit code and call refstore directly - if newRef != nil { - if err := daemon.TagImageWithReference(id, newRef); err != nil { - return err - } - } - - daemon.LogImageEvent(id.String(), id.String(), "import") - outStream.Write(sf.FormatStatus("", id.String())) - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/info.go b/vendor/github.com/docker/docker/daemon/info.go deleted file mode 100644 index 1ab9f29..0000000 --- a/vendor/github.com/docker/docker/daemon/info.go +++ /dev/null @@ -1,180 +0,0 @@ -package daemon - -import ( - "fmt" - "os" - "runtime" - "sync/atomic" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api" - "github.com/docker/docker/api/types" - "github.com/docker/docker/container" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/pkg/fileutils" - "github.com/docker/docker/pkg/parsers/kernel" - "github.com/docker/docker/pkg/parsers/operatingsystem" - "github.com/docker/docker/pkg/platform" - "github.com/docker/docker/pkg/sysinfo" - "github.com/docker/docker/pkg/system" - "github.com/docker/docker/registry" - "github.com/docker/docker/utils" - "github.com/docker/docker/volume/drivers" - "github.com/docker/go-connections/sockets" -) - -// SystemInfo returns information about the host server the daemon is running on. -func (daemon *Daemon) SystemInfo() (*types.Info, error) { - kernelVersion := "" - if kv, err := kernel.GetKernelVersion(); err != nil { - logrus.Warnf("Could not get kernel version: %v", err) - } else { - kernelVersion = kv.String() - } - - operatingSystem := "" - if s, err := operatingsystem.GetOperatingSystem(); err != nil { - logrus.Warnf("Could not get operating system name: %v", err) - } else { - operatingSystem = s - } - - // Don't do containerized check on Windows - if runtime.GOOS != "windows" { - if inContainer, err := operatingsystem.IsContainerized(); err != nil { - logrus.Errorf("Could not determine if daemon is containerized: %v", err) - operatingSystem += " (error determining if containerized)" - } else if inContainer { - operatingSystem += " (containerized)" - } - } - - meminfo, err := system.ReadMemInfo() - if err != nil { - logrus.Errorf("Could not read system memory info: %v", err) - meminfo = &system.MemInfo{} - } - - sysInfo := sysinfo.New(true) - - var cRunning, cPaused, cStopped int32 - daemon.containers.ApplyAll(func(c *container.Container) { - switch c.StateString() { - case "paused": - atomic.AddInt32(&cPaused, 1) - case "running": - atomic.AddInt32(&cRunning, 1) - default: - atomic.AddInt32(&cStopped, 1) - } - }) - - securityOptions := []string{} - if sysInfo.AppArmor { - securityOptions = append(securityOptions, "name=apparmor") - } - if sysInfo.Seccomp && supportsSeccomp { - profile := daemon.seccompProfilePath - if profile == "" { - profile = "default" - } - securityOptions = append(securityOptions, fmt.Sprintf("name=seccomp,profile=%s", profile)) - } - if selinuxEnabled() { - securityOptions = append(securityOptions, "name=selinux") - } - uid, gid := daemon.GetRemappedUIDGID() - if uid != 0 || gid != 0 { - securityOptions = append(securityOptions, "name=userns") - } - - v := &types.Info{ - ID: daemon.ID, - Containers: int(cRunning + cPaused + cStopped), - ContainersRunning: int(cRunning), - ContainersPaused: int(cPaused), - ContainersStopped: int(cStopped), - Images: len(daemon.imageStore.Map()), - Driver: daemon.GraphDriverName(), - DriverStatus: daemon.layerStore.DriverStatus(), - Plugins: daemon.showPluginsInfo(), - IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled, - BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled, - BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled, - Debug: utils.IsDebugEnabled(), - NFd: fileutils.GetTotalUsedFds(), - NGoroutines: runtime.NumGoroutine(), - SystemTime: time.Now().Format(time.RFC3339Nano), - LoggingDriver: daemon.defaultLogConfig.Type, - CgroupDriver: daemon.getCgroupDriver(), - NEventsListener: daemon.EventsService.SubscribersCount(), - KernelVersion: kernelVersion, - OperatingSystem: operatingSystem, - IndexServerAddress: registry.IndexServer, - OSType: platform.OSType, - Architecture: platform.Architecture, - RegistryConfig: daemon.RegistryService.ServiceConfig(), - NCPU: sysinfo.NumCPU(), - MemTotal: meminfo.MemTotal, - DockerRootDir: daemon.configStore.Root, - Labels: daemon.configStore.Labels, - ExperimentalBuild: daemon.configStore.Experimental, - ServerVersion: dockerversion.Version, - ClusterStore: daemon.configStore.ClusterStore, - ClusterAdvertise: daemon.configStore.ClusterAdvertise, - HTTPProxy: sockets.GetProxyEnv("http_proxy"), - HTTPSProxy: sockets.GetProxyEnv("https_proxy"), - NoProxy: sockets.GetProxyEnv("no_proxy"), - LiveRestoreEnabled: daemon.configStore.LiveRestoreEnabled, - SecurityOptions: securityOptions, - Isolation: daemon.defaultIsolation, - } - - // Retrieve platform specific info - daemon.FillPlatformInfo(v, sysInfo) - - hostname := "" - if hn, err := os.Hostname(); err != nil { - logrus.Warnf("Could not get hostname: %v", err) - } else { - hostname = hn - } - v.Name = hostname - - return v, nil -} - -// SystemVersion returns version information about the daemon. -func (daemon *Daemon) SystemVersion() types.Version { - v := types.Version{ - Version: dockerversion.Version, - GitCommit: dockerversion.GitCommit, - MinAPIVersion: api.MinVersion, - GoVersion: runtime.Version(), - Os: runtime.GOOS, - Arch: runtime.GOARCH, - BuildTime: dockerversion.BuildTime, - Experimental: daemon.configStore.Experimental, - } - - kernelVersion := "" - if kv, err := kernel.GetKernelVersion(); err != nil { - logrus.Warnf("Could not get kernel version: %v", err) - } else { - kernelVersion = kv.String() - } - v.KernelVersion = kernelVersion - - return v -} - -func (daemon *Daemon) showPluginsInfo() types.PluginsInfo { - var pluginsInfo types.PluginsInfo - - pluginsInfo.Volume = volumedrivers.GetDriverList() - pluginsInfo.Network = daemon.GetNetworkDriverList() - pluginsInfo.Authorization = daemon.configStore.AuthorizationPlugins - - return pluginsInfo -} diff --git a/vendor/github.com/docker/docker/daemon/info_unix.go b/vendor/github.com/docker/docker/daemon/info_unix.go deleted file mode 100644 index 9c41c0e..0000000 --- a/vendor/github.com/docker/docker/daemon/info_unix.go +++ /dev/null @@ -1,82 +0,0 @@ -// +build !windows - -package daemon - -import ( - "context" - "os/exec" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/pkg/sysinfo" -) - -// FillPlatformInfo fills the platform related info. -func (daemon *Daemon) FillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo) { - v.MemoryLimit = sysInfo.MemoryLimit - v.SwapLimit = sysInfo.SwapLimit - v.KernelMemory = sysInfo.KernelMemory - v.OomKillDisable = sysInfo.OomKillDisable - v.CPUCfsPeriod = sysInfo.CPUCfsPeriod - v.CPUCfsQuota = sysInfo.CPUCfsQuota - v.CPUShares = sysInfo.CPUShares - v.CPUSet = sysInfo.Cpuset - v.Runtimes = daemon.configStore.GetAllRuntimes() - v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName() - v.InitBinary = daemon.configStore.GetInitPath() - - v.ContainerdCommit.Expected = dockerversion.ContainerdCommitID - if sv, err := daemon.containerd.GetServerVersion(context.Background()); err == nil { - v.ContainerdCommit.ID = sv.Revision - } else { - logrus.Warnf("failed to retrieve containerd version: %v", err) - v.ContainerdCommit.ID = "N/A" - } - - v.RuncCommit.Expected = dockerversion.RuncCommitID - if rv, err := exec.Command(DefaultRuntimeBinary, "--version").Output(); err == nil { - parts := strings.Split(strings.TrimSpace(string(rv)), "\n") - if len(parts) == 3 { - parts = strings.Split(parts[1], ": ") - if len(parts) == 2 { - v.RuncCommit.ID = strings.TrimSpace(parts[1]) - } - } - - if v.RuncCommit.ID == "" { - logrus.Warnf("failed to retrieve %s version: unknown output format: %s", DefaultRuntimeBinary, string(rv)) - v.RuncCommit.ID = "N/A" - } - } else { - logrus.Warnf("failed to retrieve %s version: %v", DefaultRuntimeBinary, err) - v.RuncCommit.ID = "N/A" - } - - v.InitCommit.Expected = dockerversion.InitCommitID - if rv, err := exec.Command(DefaultInitBinary, "--version").Output(); err == nil { - parts := strings.Split(strings.TrimSpace(string(rv)), " - ") - if len(parts) == 2 { - if dockerversion.InitCommitID[0] == 'v' { - vs := strings.TrimPrefix(parts[0], "tini version ") - v.InitCommit.ID = "v" + vs - } else { - // Get the sha1 - gitParts := strings.Split(parts[1], ".") - if len(gitParts) == 2 && gitParts[0] == "git" { - v.InitCommit.ID = gitParts[1] - v.InitCommit.Expected = dockerversion.InitCommitID[0:len(gitParts[1])] - } - } - } - - if v.InitCommit.ID == "" { - logrus.Warnf("failed to retrieve %s version: unknown output format: %s", DefaultInitBinary, string(rv)) - v.InitCommit.ID = "N/A" - } - } else { - logrus.Warnf("failed to retrieve %s version", DefaultInitBinary) - v.InitCommit.ID = "N/A" - } -} diff --git a/vendor/github.com/docker/docker/daemon/info_windows.go b/vendor/github.com/docker/docker/daemon/info_windows.go deleted file mode 100644 index c700911..0000000 --- a/vendor/github.com/docker/docker/daemon/info_windows.go +++ /dev/null @@ -1,10 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/sysinfo" -) - -// FillPlatformInfo fills the platform related info. -func (daemon *Daemon) FillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo) { -} diff --git a/vendor/github.com/docker/docker/daemon/initlayer/setup_solaris.go b/vendor/github.com/docker/docker/daemon/initlayer/setup_solaris.go deleted file mode 100644 index 66d53f0..0000000 --- a/vendor/github.com/docker/docker/daemon/initlayer/setup_solaris.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build solaris,cgo - -package initlayer - -// Setup populates a directory with mountpoints suitable -// for bind-mounting dockerinit into the container. The mountpoint is simply an -// empty file at /.dockerinit -// -// This extra layer is used by all containers as the top-most ro layer. It protects -// the container from unwanted side-effects on the rw layer. -func Setup(initLayer string, rootUID, rootGID int) error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/initlayer/setup_unix.go b/vendor/github.com/docker/docker/daemon/initlayer/setup_unix.go deleted file mode 100644 index e83c275..0000000 --- a/vendor/github.com/docker/docker/daemon/initlayer/setup_unix.go +++ /dev/null @@ -1,69 +0,0 @@ -// +build linux freebsd - -package initlayer - -import ( - "os" - "path/filepath" - "strings" - "syscall" - - "github.com/docker/docker/pkg/idtools" -) - -// Setup populates a directory with mountpoints suitable -// for bind-mounting things into the container. -// -// This extra layer is used by all containers as the top-most ro layer. It protects -// the container from unwanted side-effects on the rw layer. -func Setup(initLayer string, rootUID, rootGID int) error { - for pth, typ := range map[string]string{ - "/dev/pts": "dir", - "/dev/shm": "dir", - "/proc": "dir", - "/sys": "dir", - "/.dockerenv": "file", - "/etc/resolv.conf": "file", - "/etc/hosts": "file", - "/etc/hostname": "file", - "/dev/console": "file", - "/etc/mtab": "/proc/mounts", - } { - parts := strings.Split(pth, "/") - prev := "/" - for _, p := range parts[1:] { - prev = filepath.Join(prev, p) - syscall.Unlink(filepath.Join(initLayer, prev)) - } - - if _, err := os.Stat(filepath.Join(initLayer, pth)); err != nil { - if os.IsNotExist(err) { - if err := idtools.MkdirAllNewAs(filepath.Join(initLayer, filepath.Dir(pth)), 0755, rootUID, rootGID); err != nil { - return err - } - switch typ { - case "dir": - if err := idtools.MkdirAllNewAs(filepath.Join(initLayer, pth), 0755, rootUID, rootGID); err != nil { - return err - } - case "file": - f, err := os.OpenFile(filepath.Join(initLayer, pth), os.O_CREATE, 0755) - if err != nil { - return err - } - f.Chown(rootUID, rootGID) - f.Close() - default: - if err := os.Symlink(typ, filepath.Join(initLayer, pth)); err != nil { - return err - } - } - } else { - return err - } - } - } - - // Layer is ready to use, if it wasn't before. - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/initlayer/setup_windows.go b/vendor/github.com/docker/docker/daemon/initlayer/setup_windows.go deleted file mode 100644 index 48a9d71..0000000 --- a/vendor/github.com/docker/docker/daemon/initlayer/setup_windows.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build windows - -package initlayer - -// Setup populates a directory with mountpoints suitable -// for bind-mounting dockerinit into the container. The mountpoint is simply an -// empty file at /.dockerinit -// -// This extra layer is used by all containers as the top-most ro layer. It protects -// the container from unwanted side-effects on the rw layer. -func Setup(initLayer string, rootUID, rootGID int) error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/inspect.go b/vendor/github.com/docker/docker/daemon/inspect.go deleted file mode 100644 index 557f639..0000000 --- a/vendor/github.com/docker/docker/daemon/inspect.go +++ /dev/null @@ -1,264 +0,0 @@ -package daemon - -import ( - "fmt" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/api/types/versions/v1p20" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/network" -) - -// ContainerInspect returns low-level information about a -// container. Returns an error if the container cannot be found, or if -// there is an error getting the data. -func (daemon *Daemon) ContainerInspect(name string, size bool, version string) (interface{}, error) { - switch { - case versions.LessThan(version, "1.20"): - return daemon.containerInspectPre120(name) - case versions.Equal(version, "1.20"): - return daemon.containerInspect120(name) - } - return daemon.ContainerInspectCurrent(name, size) -} - -// ContainerInspectCurrent returns low-level information about a -// container in a most recent api version. -func (daemon *Daemon) ContainerInspectCurrent(name string, size bool) (*types.ContainerJSON, error) { - container, err := daemon.GetContainer(name) - if err != nil { - return nil, err - } - - container.Lock() - defer container.Unlock() - - base, err := daemon.getInspectData(container, size) - if err != nil { - return nil, err - } - - apiNetworks := make(map[string]*networktypes.EndpointSettings) - for name, epConf := range container.NetworkSettings.Networks { - if epConf.EndpointSettings != nil { - apiNetworks[name] = epConf.EndpointSettings - } - } - - mountPoints := addMountPoints(container) - networkSettings := &types.NetworkSettings{ - NetworkSettingsBase: types.NetworkSettingsBase{ - Bridge: container.NetworkSettings.Bridge, - SandboxID: container.NetworkSettings.SandboxID, - HairpinMode: container.NetworkSettings.HairpinMode, - LinkLocalIPv6Address: container.NetworkSettings.LinkLocalIPv6Address, - LinkLocalIPv6PrefixLen: container.NetworkSettings.LinkLocalIPv6PrefixLen, - Ports: container.NetworkSettings.Ports, - SandboxKey: container.NetworkSettings.SandboxKey, - SecondaryIPAddresses: container.NetworkSettings.SecondaryIPAddresses, - SecondaryIPv6Addresses: container.NetworkSettings.SecondaryIPv6Addresses, - }, - DefaultNetworkSettings: daemon.getDefaultNetworkSettings(container.NetworkSettings.Networks), - Networks: apiNetworks, - } - - return &types.ContainerJSON{ - ContainerJSONBase: base, - Mounts: mountPoints, - Config: container.Config, - NetworkSettings: networkSettings, - }, nil -} - -// containerInspect120 serializes the master version of a container into a json type. -func (daemon *Daemon) containerInspect120(name string) (*v1p20.ContainerJSON, error) { - container, err := daemon.GetContainer(name) - if err != nil { - return nil, err - } - - container.Lock() - defer container.Unlock() - - base, err := daemon.getInspectData(container, false) - if err != nil { - return nil, err - } - - mountPoints := addMountPoints(container) - config := &v1p20.ContainerConfig{ - Config: container.Config, - MacAddress: container.Config.MacAddress, - NetworkDisabled: container.Config.NetworkDisabled, - ExposedPorts: container.Config.ExposedPorts, - VolumeDriver: container.HostConfig.VolumeDriver, - } - networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings) - - return &v1p20.ContainerJSON{ - ContainerJSONBase: base, - Mounts: mountPoints, - Config: config, - NetworkSettings: networkSettings, - }, nil -} - -func (daemon *Daemon) getInspectData(container *container.Container, size bool) (*types.ContainerJSONBase, error) { - // make a copy to play with - hostConfig := *container.HostConfig - - children := daemon.children(container) - hostConfig.Links = nil // do not expose the internal structure - for linkAlias, child := range children { - hostConfig.Links = append(hostConfig.Links, fmt.Sprintf("%s:%s", child.Name, linkAlias)) - } - - // We merge the Ulimits from hostConfig with daemon default - daemon.mergeUlimits(&hostConfig) - - var containerHealth *types.Health - if container.State.Health != nil { - containerHealth = &types.Health{ - Status: container.State.Health.Status, - FailingStreak: container.State.Health.FailingStreak, - Log: append([]*types.HealthcheckResult{}, container.State.Health.Log...), - } - } - - containerState := &types.ContainerState{ - Status: container.State.StateString(), - Running: container.State.Running, - Paused: container.State.Paused, - Restarting: container.State.Restarting, - OOMKilled: container.State.OOMKilled, - Dead: container.State.Dead, - Pid: container.State.Pid, - ExitCode: container.State.ExitCode(), - Error: container.State.Error(), - StartedAt: container.State.StartedAt.Format(time.RFC3339Nano), - FinishedAt: container.State.FinishedAt.Format(time.RFC3339Nano), - Health: containerHealth, - } - - contJSONBase := &types.ContainerJSONBase{ - ID: container.ID, - Created: container.Created.Format(time.RFC3339Nano), - Path: container.Path, - Args: container.Args, - State: containerState, - Image: container.ImageID.String(), - LogPath: container.LogPath, - Name: container.Name, - RestartCount: container.RestartCount, - Driver: container.Driver, - MountLabel: container.MountLabel, - ProcessLabel: container.ProcessLabel, - ExecIDs: container.GetExecIDs(), - HostConfig: &hostConfig, - } - - var ( - sizeRw int64 - sizeRootFs int64 - ) - if size { - sizeRw, sizeRootFs = daemon.getSize(container) - contJSONBase.SizeRw = &sizeRw - contJSONBase.SizeRootFs = &sizeRootFs - } - - // Now set any platform-specific fields - contJSONBase = setPlatformSpecificContainerFields(container, contJSONBase) - - contJSONBase.GraphDriver.Name = container.Driver - - graphDriverData, err := container.RWLayer.Metadata() - // If container is marked as Dead, the container's graphdriver metadata - // could have been removed, it will cause error if we try to get the metadata, - // we can ignore the error if the container is dead. - if err != nil && !container.Dead { - return nil, err - } - contJSONBase.GraphDriver.Data = graphDriverData - - return contJSONBase, nil -} - -// ContainerExecInspect returns low-level information about the exec -// command. An error is returned if the exec cannot be found. -func (daemon *Daemon) ContainerExecInspect(id string) (*backend.ExecInspect, error) { - e, err := daemon.getExecConfig(id) - if err != nil { - return nil, err - } - - pc := inspectExecProcessConfig(e) - - return &backend.ExecInspect{ - ID: e.ID, - Running: e.Running, - ExitCode: e.ExitCode, - ProcessConfig: pc, - OpenStdin: e.OpenStdin, - OpenStdout: e.OpenStdout, - OpenStderr: e.OpenStderr, - CanRemove: e.CanRemove, - ContainerID: e.ContainerID, - DetachKeys: e.DetachKeys, - Pid: e.Pid, - }, nil -} - -// VolumeInspect looks up a volume by name. An error is returned if -// the volume cannot be found. -func (daemon *Daemon) VolumeInspect(name string) (*types.Volume, error) { - v, err := daemon.volumes.Get(name) - if err != nil { - return nil, err - } - apiV := volumeToAPIType(v) - apiV.Mountpoint = v.Path() - apiV.Status = v.Status() - return apiV, nil -} - -func (daemon *Daemon) getBackwardsCompatibleNetworkSettings(settings *network.Settings) *v1p20.NetworkSettings { - result := &v1p20.NetworkSettings{ - NetworkSettingsBase: types.NetworkSettingsBase{ - Bridge: settings.Bridge, - SandboxID: settings.SandboxID, - HairpinMode: settings.HairpinMode, - LinkLocalIPv6Address: settings.LinkLocalIPv6Address, - LinkLocalIPv6PrefixLen: settings.LinkLocalIPv6PrefixLen, - Ports: settings.Ports, - SandboxKey: settings.SandboxKey, - SecondaryIPAddresses: settings.SecondaryIPAddresses, - SecondaryIPv6Addresses: settings.SecondaryIPv6Addresses, - }, - DefaultNetworkSettings: daemon.getDefaultNetworkSettings(settings.Networks), - } - - return result -} - -// getDefaultNetworkSettings creates the deprecated structure that holds the information -// about the bridge network for a container. -func (daemon *Daemon) getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) types.DefaultNetworkSettings { - var settings types.DefaultNetworkSettings - - if defaultNetwork, ok := networks["bridge"]; ok && defaultNetwork.EndpointSettings != nil { - settings.EndpointID = defaultNetwork.EndpointID - settings.Gateway = defaultNetwork.Gateway - settings.GlobalIPv6Address = defaultNetwork.GlobalIPv6Address - settings.GlobalIPv6PrefixLen = defaultNetwork.GlobalIPv6PrefixLen - settings.IPAddress = defaultNetwork.IPAddress - settings.IPPrefixLen = defaultNetwork.IPPrefixLen - settings.IPv6Gateway = defaultNetwork.IPv6Gateway - settings.MacAddress = defaultNetwork.MacAddress - } - return settings -} diff --git a/vendor/github.com/docker/docker/daemon/inspect_solaris.go b/vendor/github.com/docker/docker/daemon/inspect_solaris.go deleted file mode 100644 index 0e3dcc1..0000000 --- a/vendor/github.com/docker/docker/daemon/inspect_solaris.go +++ /dev/null @@ -1,41 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/versions/v1p19" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/exec" -) - -// This sets platform-specific fields -func setPlatformSpecificContainerFields(container *container.Container, contJSONBase *types.ContainerJSONBase) *types.ContainerJSONBase { - return contJSONBase -} - -// containerInspectPre120 get containers for pre 1.20 APIs. -func (daemon *Daemon) containerInspectPre120(name string) (*v1p19.ContainerJSON, error) { - return &v1p19.ContainerJSON{}, nil -} - -func addMountPoints(container *container.Container) []types.MountPoint { - mountPoints := make([]types.MountPoint, 0, len(container.MountPoints)) - for _, m := range container.MountPoints { - mountPoints = append(mountPoints, types.MountPoint{ - Name: m.Name, - Source: m.Path(), - Destination: m.Destination, - Driver: m.Driver, - RW: m.RW, - }) - } - return mountPoints -} - -func inspectExecProcessConfig(e *exec.Config) *backend.ExecProcessConfig { - return &backend.ExecProcessConfig{ - Tty: e.Tty, - Entrypoint: e.Entrypoint, - Arguments: e.Args, - } -} diff --git a/vendor/github.com/docker/docker/daemon/inspect_unix.go b/vendor/github.com/docker/docker/daemon/inspect_unix.go deleted file mode 100644 index 08a8223..0000000 --- a/vendor/github.com/docker/docker/daemon/inspect_unix.go +++ /dev/null @@ -1,92 +0,0 @@ -// +build !windows,!solaris - -package daemon - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/versions/v1p19" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/exec" -) - -// This sets platform-specific fields -func setPlatformSpecificContainerFields(container *container.Container, contJSONBase *types.ContainerJSONBase) *types.ContainerJSONBase { - contJSONBase.AppArmorProfile = container.AppArmorProfile - contJSONBase.ResolvConfPath = container.ResolvConfPath - contJSONBase.HostnamePath = container.HostnamePath - contJSONBase.HostsPath = container.HostsPath - - return contJSONBase -} - -// containerInspectPre120 gets containers for pre 1.20 APIs. -func (daemon *Daemon) containerInspectPre120(name string) (*v1p19.ContainerJSON, error) { - container, err := daemon.GetContainer(name) - if err != nil { - return nil, err - } - - container.Lock() - defer container.Unlock() - - base, err := daemon.getInspectData(container, false) - if err != nil { - return nil, err - } - - volumes := make(map[string]string) - volumesRW := make(map[string]bool) - for _, m := range container.MountPoints { - volumes[m.Destination] = m.Path() - volumesRW[m.Destination] = m.RW - } - - config := &v1p19.ContainerConfig{ - Config: container.Config, - MacAddress: container.Config.MacAddress, - NetworkDisabled: container.Config.NetworkDisabled, - ExposedPorts: container.Config.ExposedPorts, - VolumeDriver: container.HostConfig.VolumeDriver, - Memory: container.HostConfig.Memory, - MemorySwap: container.HostConfig.MemorySwap, - CPUShares: container.HostConfig.CPUShares, - CPUSet: container.HostConfig.CpusetCpus, - } - networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings) - - return &v1p19.ContainerJSON{ - ContainerJSONBase: base, - Volumes: volumes, - VolumesRW: volumesRW, - Config: config, - NetworkSettings: networkSettings, - }, nil -} - -func addMountPoints(container *container.Container) []types.MountPoint { - mountPoints := make([]types.MountPoint, 0, len(container.MountPoints)) - for _, m := range container.MountPoints { - mountPoints = append(mountPoints, types.MountPoint{ - Type: m.Type, - Name: m.Name, - Source: m.Path(), - Destination: m.Destination, - Driver: m.Driver, - Mode: m.Mode, - RW: m.RW, - Propagation: m.Propagation, - }) - } - return mountPoints -} - -func inspectExecProcessConfig(e *exec.Config) *backend.ExecProcessConfig { - return &backend.ExecProcessConfig{ - Tty: e.Tty, - Entrypoint: e.Entrypoint, - Arguments: e.Args, - Privileged: &e.Privileged, - User: e.User, - } -} diff --git a/vendor/github.com/docker/docker/daemon/inspect_windows.go b/vendor/github.com/docker/docker/daemon/inspect_windows.go deleted file mode 100644 index b331c83..0000000 --- a/vendor/github.com/docker/docker/daemon/inspect_windows.go +++ /dev/null @@ -1,41 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/exec" -) - -// This sets platform-specific fields -func setPlatformSpecificContainerFields(container *container.Container, contJSONBase *types.ContainerJSONBase) *types.ContainerJSONBase { - return contJSONBase -} - -func addMountPoints(container *container.Container) []types.MountPoint { - mountPoints := make([]types.MountPoint, 0, len(container.MountPoints)) - for _, m := range container.MountPoints { - mountPoints = append(mountPoints, types.MountPoint{ - Type: m.Type, - Name: m.Name, - Source: m.Path(), - Destination: m.Destination, - Driver: m.Driver, - RW: m.RW, - }) - } - return mountPoints -} - -// containerInspectPre120 get containers for pre 1.20 APIs. -func (daemon *Daemon) containerInspectPre120(name string) (*types.ContainerJSON, error) { - return daemon.ContainerInspectCurrent(name, false) -} - -func inspectExecProcessConfig(e *exec.Config) *backend.ExecProcessConfig { - return &backend.ExecProcessConfig{ - Tty: e.Tty, - Entrypoint: e.Entrypoint, - Arguments: e.Args, - } -} diff --git a/vendor/github.com/docker/docker/daemon/keys.go b/vendor/github.com/docker/docker/daemon/keys.go deleted file mode 100644 index 055d488..0000000 --- a/vendor/github.com/docker/docker/daemon/keys.go +++ /dev/null @@ -1,59 +0,0 @@ -// +build linux - -package daemon - -import ( - "fmt" - "io/ioutil" - "os" - "strconv" - "strings" -) - -const ( - rootKeyFile = "/proc/sys/kernel/keys/root_maxkeys" - rootBytesFile = "/proc/sys/kernel/keys/root_maxbytes" - rootKeyLimit = 1000000 - // it is standard configuration to allocate 25 bytes per key - rootKeyByteMultiplier = 25 -) - -// ModifyRootKeyLimit checks to see if the root key limit is set to -// at least 1000000 and changes it to that limit along with the maxbytes -// allocated to the keys at a 25 to 1 multiplier. -func ModifyRootKeyLimit() error { - value, err := readRootKeyLimit(rootKeyFile) - if err != nil { - return err - } - if value < rootKeyLimit { - return setRootKeyLimit(rootKeyLimit) - } - return nil -} - -func setRootKeyLimit(limit int) error { - keys, err := os.OpenFile(rootKeyFile, os.O_WRONLY, 0) - if err != nil { - return err - } - defer keys.Close() - if _, err := fmt.Fprintf(keys, "%d", limit); err != nil { - return err - } - bytes, err := os.OpenFile(rootBytesFile, os.O_WRONLY, 0) - if err != nil { - return err - } - defer bytes.Close() - _, err = fmt.Fprintf(bytes, "%d", limit*rootKeyByteMultiplier) - return err -} - -func readRootKeyLimit(path string) (int, error) { - data, err := ioutil.ReadFile(path) - if err != nil { - return -1, err - } - return strconv.Atoi(strings.Trim(string(data), "\n")) -} diff --git a/vendor/github.com/docker/docker/daemon/keys_unsupported.go b/vendor/github.com/docker/docker/daemon/keys_unsupported.go deleted file mode 100644 index b172559..0000000 --- a/vendor/github.com/docker/docker/daemon/keys_unsupported.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !linux - -package daemon - -// ModifyRootKeyLimit is an noop on unsupported platforms. -func ModifyRootKeyLimit() error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/kill.go b/vendor/github.com/docker/docker/daemon/kill.go deleted file mode 100644 index 18d5bbb..0000000 --- a/vendor/github.com/docker/docker/daemon/kill.go +++ /dev/null @@ -1,164 +0,0 @@ -package daemon - -import ( - "fmt" - "runtime" - "strings" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/signal" -) - -type errNoSuchProcess struct { - pid int - signal int -} - -func (e errNoSuchProcess) Error() string { - return fmt.Sprintf("Cannot kill process (pid=%d) with signal %d: no such process.", e.pid, e.signal) -} - -// isErrNoSuchProcess returns true if the error -// is an instance of errNoSuchProcess. -func isErrNoSuchProcess(err error) bool { - _, ok := err.(errNoSuchProcess) - return ok -} - -// ContainerKill sends signal to the container -// If no signal is given (sig 0), then Kill with SIGKILL and wait -// for the container to exit. -// If a signal is given, then just send it to the container and return. -func (daemon *Daemon) ContainerKill(name string, sig uint64) error { - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - if sig != 0 && !signal.ValidSignalForPlatform(syscall.Signal(sig)) { - return fmt.Errorf("The %s daemon does not support signal %d", runtime.GOOS, sig) - } - - // If no signal is passed, or SIGKILL, perform regular Kill (SIGKILL + wait()) - if sig == 0 || syscall.Signal(sig) == syscall.SIGKILL { - return daemon.Kill(container) - } - return daemon.killWithSignal(container, int(sig)) -} - -// killWithSignal sends the container the given signal. This wrapper for the -// host specific kill command prepares the container before attempting -// to send the signal. An error is returned if the container is paused -// or not running, or if there is a problem returned from the -// underlying kill command. -func (daemon *Daemon) killWithSignal(container *container.Container, sig int) error { - logrus.Debugf("Sending kill signal %d to container %s", sig, container.ID) - container.Lock() - defer container.Unlock() - - // We could unpause the container for them rather than returning this error - if container.Paused { - return fmt.Errorf("Container %s is paused. Unpause the container before stopping", container.ID) - } - - if !container.Running { - return errNotRunning{container.ID} - } - - if container.Config.StopSignal != "" { - containerStopSignal, err := signal.ParseSignal(container.Config.StopSignal) - if err != nil { - return err - } - if containerStopSignal == syscall.Signal(sig) { - container.ExitOnNext() - } - } else { - container.ExitOnNext() - } - - if !daemon.IsShuttingDown() { - container.HasBeenManuallyStopped = true - } - - // if the container is currently restarting we do not need to send the signal - // to the process. Telling the monitor that it should exit on its next event - // loop is enough - if container.Restarting { - return nil - } - - if err := daemon.kill(container, sig); err != nil { - err = fmt.Errorf("Cannot kill container %s: %s", container.ID, err) - // if container or process not exists, ignore the error - if strings.Contains(err.Error(), "container not found") || - strings.Contains(err.Error(), "no such process") { - logrus.Warnf("container kill failed because of 'container not found' or 'no such process': %s", err.Error()) - } else { - return err - } - } - - attributes := map[string]string{ - "signal": fmt.Sprintf("%d", sig), - } - daemon.LogContainerEventWithAttributes(container, "kill", attributes) - return nil -} - -// Kill forcefully terminates a container. -func (daemon *Daemon) Kill(container *container.Container) error { - if !container.IsRunning() { - return errNotRunning{container.ID} - } - - // 1. Send SIGKILL - if err := daemon.killPossiblyDeadProcess(container, int(syscall.SIGKILL)); err != nil { - // While normally we might "return err" here we're not going to - // because if we can't stop the container by this point then - // its probably because its already stopped. Meaning, between - // the time of the IsRunning() call above and now it stopped. - // Also, since the err return will be environment specific we can't - // look for any particular (common) error that would indicate - // that the process is already dead vs something else going wrong. - // So, instead we'll give it up to 2 more seconds to complete and if - // by that time the container is still running, then the error - // we got is probably valid and so we return it to the caller. - if isErrNoSuchProcess(err) { - return nil - } - - if _, err2 := container.WaitStop(2 * time.Second); err2 != nil { - return err - } - } - - // 2. Wait for the process to die, in last resort, try to kill the process directly - if err := killProcessDirectly(container); err != nil { - if isErrNoSuchProcess(err) { - return nil - } - return err - } - - container.WaitStop(-1 * time.Second) - return nil -} - -// killPossibleDeadProcess is a wrapper around killSig() suppressing "no such process" error. -func (daemon *Daemon) killPossiblyDeadProcess(container *container.Container, sig int) error { - err := daemon.killWithSignal(container, sig) - if err == syscall.ESRCH { - e := errNoSuchProcess{container.GetPID(), sig} - logrus.Debug(e) - return e - } - return err -} - -func (daemon *Daemon) kill(c *container.Container, sig int) error { - return daemon.containerd.Signal(c.ID, sig) -} diff --git a/vendor/github.com/docker/docker/daemon/links.go b/vendor/github.com/docker/docker/daemon/links.go deleted file mode 100644 index 7f691d4..0000000 --- a/vendor/github.com/docker/docker/daemon/links.go +++ /dev/null @@ -1,87 +0,0 @@ -package daemon - -import ( - "sync" - - "github.com/docker/docker/container" -) - -// linkIndex stores link relationships between containers, including their specified alias -// The alias is the name the parent uses to reference the child -type linkIndex struct { - // idx maps a parent->alias->child relationship - idx map[*container.Container]map[string]*container.Container - // childIdx maps child->parent->aliases - childIdx map[*container.Container]map[*container.Container]map[string]struct{} - mu sync.Mutex -} - -func newLinkIndex() *linkIndex { - return &linkIndex{ - idx: make(map[*container.Container]map[string]*container.Container), - childIdx: make(map[*container.Container]map[*container.Container]map[string]struct{}), - } -} - -// link adds indexes for the passed in parent/child/alias relationships -func (l *linkIndex) link(parent, child *container.Container, alias string) { - l.mu.Lock() - - if l.idx[parent] == nil { - l.idx[parent] = make(map[string]*container.Container) - } - l.idx[parent][alias] = child - if l.childIdx[child] == nil { - l.childIdx[child] = make(map[*container.Container]map[string]struct{}) - } - if l.childIdx[child][parent] == nil { - l.childIdx[child][parent] = make(map[string]struct{}) - } - l.childIdx[child][parent][alias] = struct{}{} - - l.mu.Unlock() -} - -// unlink removes the requested alias for the given parent/child -func (l *linkIndex) unlink(alias string, child, parent *container.Container) { - l.mu.Lock() - delete(l.idx[parent], alias) - delete(l.childIdx[child], parent) - l.mu.Unlock() -} - -// children maps all the aliases-> children for the passed in parent -// aliases here are the aliases the parent uses to refer to the child -func (l *linkIndex) children(parent *container.Container) map[string]*container.Container { - l.mu.Lock() - children := l.idx[parent] - l.mu.Unlock() - return children -} - -// parents maps all the aliases->parent for the passed in child -// aliases here are the aliases the parents use to refer to the child -func (l *linkIndex) parents(child *container.Container) map[string]*container.Container { - l.mu.Lock() - - parents := make(map[string]*container.Container) - for parent, aliases := range l.childIdx[child] { - for alias := range aliases { - parents[alias] = parent - } - } - - l.mu.Unlock() - return parents -} - -// delete deletes all link relationships referencing this container -func (l *linkIndex) delete(container *container.Container) { - l.mu.Lock() - for _, child := range l.idx[container] { - delete(l.childIdx[child], container) - } - delete(l.idx, container) - delete(l.childIdx, container) - l.mu.Unlock() -} diff --git a/vendor/github.com/docker/docker/daemon/links/links.go b/vendor/github.com/docker/docker/daemon/links/links.go deleted file mode 100644 index af15de0..0000000 --- a/vendor/github.com/docker/docker/daemon/links/links.go +++ /dev/null @@ -1,141 +0,0 @@ -package links - -import ( - "fmt" - "path" - "strings" - - "github.com/docker/go-connections/nat" -) - -// Link struct holds informations about parent/child linked container -type Link struct { - // Parent container IP address - ParentIP string - // Child container IP address - ChildIP string - // Link name - Name string - // Child environments variables - ChildEnvironment []string - // Child exposed ports - Ports []nat.Port -} - -// NewLink initializes a new Link struct with the provided options. -func NewLink(parentIP, childIP, name string, env []string, exposedPorts map[nat.Port]struct{}) *Link { - var ( - i int - ports = make([]nat.Port, len(exposedPorts)) - ) - - for p := range exposedPorts { - ports[i] = p - i++ - } - - return &Link{ - Name: name, - ChildIP: childIP, - ParentIP: parentIP, - ChildEnvironment: env, - Ports: ports, - } -} - -// ToEnv creates a string's slice containing child container informations in -// the form of environment variables which will be later exported on container -// startup. -func (l *Link) ToEnv() []string { - env := []string{} - - _, n := path.Split(l.Name) - alias := strings.Replace(strings.ToUpper(n), "-", "_", -1) - - if p := l.getDefaultPort(); p != nil { - env = append(env, fmt.Sprintf("%s_PORT=%s://%s:%s", alias, p.Proto(), l.ChildIP, p.Port())) - } - - //sort the ports so that we can bulk the continuous ports together - nat.Sort(l.Ports, func(ip, jp nat.Port) bool { - // If the two ports have the same number, tcp takes priority - // Sort in desc order - return ip.Int() < jp.Int() || (ip.Int() == jp.Int() && strings.ToLower(ip.Proto()) == "tcp") - }) - - for i := 0; i < len(l.Ports); { - p := l.Ports[i] - j := nextContiguous(l.Ports, p.Int(), i) - if j > i+1 { - env = append(env, fmt.Sprintf("%s_PORT_%s_%s_START=%s://%s:%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto(), l.ChildIP, p.Port())) - env = append(env, fmt.Sprintf("%s_PORT_%s_%s_ADDR=%s", alias, p.Port(), strings.ToUpper(p.Proto()), l.ChildIP)) - env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PROTO=%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto())) - env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PORT_START=%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Port())) - - q := l.Ports[j] - env = append(env, fmt.Sprintf("%s_PORT_%s_%s_END=%s://%s:%s", alias, p.Port(), strings.ToUpper(q.Proto()), q.Proto(), l.ChildIP, q.Port())) - env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PORT_END=%s", alias, p.Port(), strings.ToUpper(q.Proto()), q.Port())) - - i = j + 1 - continue - } else { - i++ - } - } - for _, p := range l.Ports { - env = append(env, fmt.Sprintf("%s_PORT_%s_%s=%s://%s:%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto(), l.ChildIP, p.Port())) - env = append(env, fmt.Sprintf("%s_PORT_%s_%s_ADDR=%s", alias, p.Port(), strings.ToUpper(p.Proto()), l.ChildIP)) - env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PORT=%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Port())) - env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PROTO=%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto())) - } - - // Load the linked container's name into the environment - env = append(env, fmt.Sprintf("%s_NAME=%s", alias, l.Name)) - - if l.ChildEnvironment != nil { - for _, v := range l.ChildEnvironment { - parts := strings.SplitN(v, "=", 2) - if len(parts) < 2 { - continue - } - // Ignore a few variables that are added during docker build (and not really relevant to linked containers) - if parts[0] == "HOME" || parts[0] == "PATH" { - continue - } - env = append(env, fmt.Sprintf("%s_ENV_%s=%s", alias, parts[0], parts[1])) - } - } - return env -} - -func nextContiguous(ports []nat.Port, value int, index int) int { - if index+1 == len(ports) { - return index - } - for i := index + 1; i < len(ports); i++ { - if ports[i].Int() > value+1 { - return i - 1 - } - - value++ - } - return len(ports) - 1 -} - -// Default port rules -func (l *Link) getDefaultPort() *nat.Port { - var p nat.Port - i := len(l.Ports) - - if i == 0 { - return nil - } else if i > 1 { - nat.Sort(l.Ports, func(ip, jp nat.Port) bool { - // If the two ports have the same number, tcp takes priority - // Sort in desc order - return ip.Int() < jp.Int() || (ip.Int() == jp.Int() && strings.ToLower(ip.Proto()) == "tcp") - }) - } - p = l.Ports[0] - return &p -} diff --git a/vendor/github.com/docker/docker/daemon/links/links_test.go b/vendor/github.com/docker/docker/daemon/links/links_test.go deleted file mode 100644 index 0273f13..0000000 --- a/vendor/github.com/docker/docker/daemon/links/links_test.go +++ /dev/null @@ -1,213 +0,0 @@ -package links - -import ( - "fmt" - "strings" - "testing" - - "github.com/docker/go-connections/nat" -) - -// Just to make life easier -func newPortNoError(proto, port string) nat.Port { - p, _ := nat.NewPort(proto, port) - return p -} - -func TestLinkNaming(t *testing.T) { - ports := make(nat.PortSet) - ports[newPortNoError("tcp", "6379")] = struct{}{} - - link := NewLink("172.0.17.3", "172.0.17.2", "/db/docker-1", nil, ports) - - rawEnv := link.ToEnv() - env := make(map[string]string, len(rawEnv)) - for _, e := range rawEnv { - parts := strings.Split(e, "=") - if len(parts) != 2 { - t.FailNow() - } - env[parts[0]] = parts[1] - } - - value, ok := env["DOCKER_1_PORT"] - - if !ok { - t.Fatalf("DOCKER_1_PORT not found in env") - } - - if value != "tcp://172.0.17.2:6379" { - t.Fatalf("Expected 172.0.17.2:6379, got %s", env["DOCKER_1_PORT"]) - } -} - -func TestLinkNew(t *testing.T) { - ports := make(nat.PortSet) - ports[newPortNoError("tcp", "6379")] = struct{}{} - - link := NewLink("172.0.17.3", "172.0.17.2", "/db/docker", nil, ports) - - if link.Name != "/db/docker" { - t.Fail() - } - if link.ParentIP != "172.0.17.3" { - t.Fail() - } - if link.ChildIP != "172.0.17.2" { - t.Fail() - } - for _, p := range link.Ports { - if p != newPortNoError("tcp", "6379") { - t.Fail() - } - } -} - -func TestLinkEnv(t *testing.T) { - ports := make(nat.PortSet) - ports[newPortNoError("tcp", "6379")] = struct{}{} - - link := NewLink("172.0.17.3", "172.0.17.2", "/db/docker", []string{"PASSWORD=gordon"}, ports) - - rawEnv := link.ToEnv() - env := make(map[string]string, len(rawEnv)) - for _, e := range rawEnv { - parts := strings.Split(e, "=") - if len(parts) != 2 { - t.FailNow() - } - env[parts[0]] = parts[1] - } - if env["DOCKER_PORT"] != "tcp://172.0.17.2:6379" { - t.Fatalf("Expected 172.0.17.2:6379, got %s", env["DOCKER_PORT"]) - } - if env["DOCKER_PORT_6379_TCP"] != "tcp://172.0.17.2:6379" { - t.Fatalf("Expected tcp://172.0.17.2:6379, got %s", env["DOCKER_PORT_6379_TCP"]) - } - if env["DOCKER_PORT_6379_TCP_PROTO"] != "tcp" { - t.Fatalf("Expected tcp, got %s", env["DOCKER_PORT_6379_TCP_PROTO"]) - } - if env["DOCKER_PORT_6379_TCP_ADDR"] != "172.0.17.2" { - t.Fatalf("Expected 172.0.17.2, got %s", env["DOCKER_PORT_6379_TCP_ADDR"]) - } - if env["DOCKER_PORT_6379_TCP_PORT"] != "6379" { - t.Fatalf("Expected 6379, got %s", env["DOCKER_PORT_6379_TCP_PORT"]) - } - if env["DOCKER_NAME"] != "/db/docker" { - t.Fatalf("Expected /db/docker, got %s", env["DOCKER_NAME"]) - } - if env["DOCKER_ENV_PASSWORD"] != "gordon" { - t.Fatalf("Expected gordon, got %s", env["DOCKER_ENV_PASSWORD"]) - } -} - -func TestLinkMultipleEnv(t *testing.T) { - ports := make(nat.PortSet) - ports[newPortNoError("tcp", "6379")] = struct{}{} - ports[newPortNoError("tcp", "6380")] = struct{}{} - ports[newPortNoError("tcp", "6381")] = struct{}{} - - link := NewLink("172.0.17.3", "172.0.17.2", "/db/docker", []string{"PASSWORD=gordon"}, ports) - - rawEnv := link.ToEnv() - env := make(map[string]string, len(rawEnv)) - for _, e := range rawEnv { - parts := strings.Split(e, "=") - if len(parts) != 2 { - t.FailNow() - } - env[parts[0]] = parts[1] - } - if env["DOCKER_PORT"] != "tcp://172.0.17.2:6379" { - t.Fatalf("Expected 172.0.17.2:6379, got %s", env["DOCKER_PORT"]) - } - if env["DOCKER_PORT_6379_TCP_START"] != "tcp://172.0.17.2:6379" { - t.Fatalf("Expected tcp://172.0.17.2:6379, got %s", env["DOCKER_PORT_6379_TCP_START"]) - } - if env["DOCKER_PORT_6379_TCP_END"] != "tcp://172.0.17.2:6381" { - t.Fatalf("Expected tcp://172.0.17.2:6381, got %s", env["DOCKER_PORT_6379_TCP_END"]) - } - if env["DOCKER_PORT_6379_TCP_PROTO"] != "tcp" { - t.Fatalf("Expected tcp, got %s", env["DOCKER_PORT_6379_TCP_PROTO"]) - } - if env["DOCKER_PORT_6379_TCP_ADDR"] != "172.0.17.2" { - t.Fatalf("Expected 172.0.17.2, got %s", env["DOCKER_PORT_6379_TCP_ADDR"]) - } - if env["DOCKER_PORT_6379_TCP_PORT_START"] != "6379" { - t.Fatalf("Expected 6379, got %s", env["DOCKER_PORT_6379_TCP_PORT_START"]) - } - if env["DOCKER_PORT_6379_TCP_PORT_END"] != "6381" { - t.Fatalf("Expected 6381, got %s", env["DOCKER_PORT_6379_TCP_PORT_END"]) - } - if env["DOCKER_NAME"] != "/db/docker" { - t.Fatalf("Expected /db/docker, got %s", env["DOCKER_NAME"]) - } - if env["DOCKER_ENV_PASSWORD"] != "gordon" { - t.Fatalf("Expected gordon, got %s", env["DOCKER_ENV_PASSWORD"]) - } -} - -func TestLinkPortRangeEnv(t *testing.T) { - ports := make(nat.PortSet) - ports[newPortNoError("tcp", "6379")] = struct{}{} - ports[newPortNoError("tcp", "6380")] = struct{}{} - ports[newPortNoError("tcp", "6381")] = struct{}{} - - link := NewLink("172.0.17.3", "172.0.17.2", "/db/docker", []string{"PASSWORD=gordon"}, ports) - - rawEnv := link.ToEnv() - env := make(map[string]string, len(rawEnv)) - for _, e := range rawEnv { - parts := strings.Split(e, "=") - if len(parts) != 2 { - t.FailNow() - } - env[parts[0]] = parts[1] - } - - if env["DOCKER_PORT"] != "tcp://172.0.17.2:6379" { - t.Fatalf("Expected 172.0.17.2:6379, got %s", env["DOCKER_PORT"]) - } - if env["DOCKER_PORT_6379_TCP_START"] != "tcp://172.0.17.2:6379" { - t.Fatalf("Expected tcp://172.0.17.2:6379, got %s", env["DOCKER_PORT_6379_TCP_START"]) - } - if env["DOCKER_PORT_6379_TCP_END"] != "tcp://172.0.17.2:6381" { - t.Fatalf("Expected tcp://172.0.17.2:6381, got %s", env["DOCKER_PORT_6379_TCP_END"]) - } - if env["DOCKER_PORT_6379_TCP_PROTO"] != "tcp" { - t.Fatalf("Expected tcp, got %s", env["DOCKER_PORT_6379_TCP_PROTO"]) - } - if env["DOCKER_PORT_6379_TCP_ADDR"] != "172.0.17.2" { - t.Fatalf("Expected 172.0.17.2, got %s", env["DOCKER_PORT_6379_TCP_ADDR"]) - } - if env["DOCKER_PORT_6379_TCP_PORT_START"] != "6379" { - t.Fatalf("Expected 6379, got %s", env["DOCKER_PORT_6379_TCP_PORT_START"]) - } - if env["DOCKER_PORT_6379_TCP_PORT_END"] != "6381" { - t.Fatalf("Expected 6381, got %s", env["DOCKER_PORT_6379_TCP_PORT_END"]) - } - if env["DOCKER_NAME"] != "/db/docker" { - t.Fatalf("Expected /db/docker, got %s", env["DOCKER_NAME"]) - } - if env["DOCKER_ENV_PASSWORD"] != "gordon" { - t.Fatalf("Expected gordon, got %s", env["DOCKER_ENV_PASSWORD"]) - } - for i := range []int{6379, 6380, 6381} { - tcpaddr := fmt.Sprintf("DOCKER_PORT_%d_TCP_ADDR", i) - tcpport := fmt.Sprintf("DOCKER_PORT_%d_TCP+PORT", i) - tcpproto := fmt.Sprintf("DOCKER_PORT_%d_TCP+PROTO", i) - tcp := fmt.Sprintf("DOCKER_PORT_%d_TCP", i) - if env[tcpaddr] == "172.0.17.2" { - t.Fatalf("Expected env %s = 172.0.17.2, got %s", tcpaddr, env[tcpaddr]) - } - if env[tcpport] == fmt.Sprintf("%d", i) { - t.Fatalf("Expected env %s = %d, got %s", tcpport, i, env[tcpport]) - } - if env[tcpproto] == "tcp" { - t.Fatalf("Expected env %s = tcp, got %s", tcpproto, env[tcpproto]) - } - if env[tcp] == fmt.Sprintf("tcp://172.0.17.2:%d", i) { - t.Fatalf("Expected env %s = tcp://172.0.17.2:%d, got %s", tcp, i, env[tcp]) - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/links_linux.go b/vendor/github.com/docker/docker/daemon/links_linux.go deleted file mode 100644 index 2ea40d9..0000000 --- a/vendor/github.com/docker/docker/daemon/links_linux.go +++ /dev/null @@ -1,72 +0,0 @@ -package daemon - -import ( - "fmt" - "path/filepath" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/graphdb" -) - -// migrateLegacySqliteLinks migrates sqlite links to use links from HostConfig -// when sqlite links were used, hostConfig.Links was set to nil -func (daemon *Daemon) migrateLegacySqliteLinks(db *graphdb.Database, container *container.Container) error { - // if links is populated (or an empty slice), then this isn't using sqlite links and can be skipped - if container.HostConfig == nil || container.HostConfig.Links != nil { - return nil - } - - logrus.Debugf("migrating legacy sqlite link info for container: %s", container.ID) - - fullName := container.Name - if fullName[0] != '/' { - fullName = "/" + fullName - } - - // don't use a nil slice, this ensures that the check above will skip once the migration has completed - links := []string{} - children, err := db.Children(fullName, 0) - if err != nil { - if !strings.Contains(err.Error(), "Cannot find child for") { - return err - } - // else continue... it's ok if we didn't find any children, it'll just be nil and we can continue the migration - } - - for _, child := range children { - c, err := daemon.GetContainer(child.Entity.ID()) - if err != nil { - return err - } - - links = append(links, c.Name+":"+child.Edge.Name) - } - - container.HostConfig.Links = links - return container.WriteHostConfig() -} - -// sqliteMigration performs the link graph DB migration. -func (daemon *Daemon) sqliteMigration(containers map[string]*container.Container) error { - // migrate any legacy links from sqlite - linkdbFile := filepath.Join(daemon.root, "linkgraph.db") - var ( - legacyLinkDB *graphdb.Database - err error - ) - - legacyLinkDB, err = graphdb.NewSqliteConn(linkdbFile) - if err != nil { - return fmt.Errorf("error connecting to legacy link graph DB %s, container links may be lost: %v", linkdbFile, err) - } - defer legacyLinkDB.Close() - - for _, c := range containers { - if err := daemon.migrateLegacySqliteLinks(legacyLinkDB, c); err != nil { - return err - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/links_linux_test.go b/vendor/github.com/docker/docker/daemon/links_linux_test.go deleted file mode 100644 index e2dbff2..0000000 --- a/vendor/github.com/docker/docker/daemon/links_linux_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package daemon - -import ( - "encoding/json" - "io/ioutil" - "os" - "path" - "path/filepath" - "testing" - - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/graphdb" - "github.com/docker/docker/pkg/stringid" -) - -func TestMigrateLegacySqliteLinks(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "legacy-qlite-links-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpDir) - - name1 := "test1" - c1 := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: stringid.GenerateNonCryptoID(), - Name: name1, - HostConfig: &containertypes.HostConfig{}, - }, - } - c1.Root = tmpDir - - name2 := "test2" - c2 := &container.Container{ - CommonContainer: container.CommonContainer{ - ID: stringid.GenerateNonCryptoID(), - Name: name2, - }, - } - - store := container.NewMemoryStore() - store.Add(c1.ID, c1) - store.Add(c2.ID, c2) - - d := &Daemon{root: tmpDir, containers: store} - db, err := graphdb.NewSqliteConn(filepath.Join(d.root, "linkgraph.db")) - if err != nil { - t.Fatal(err) - } - - if _, err := db.Set("/"+name1, c1.ID); err != nil { - t.Fatal(err) - } - - if _, err := db.Set("/"+name2, c2.ID); err != nil { - t.Fatal(err) - } - - alias := "hello" - if _, err := db.Set(path.Join(c1.Name, alias), c2.ID); err != nil { - t.Fatal(err) - } - - if err := d.migrateLegacySqliteLinks(db, c1); err != nil { - t.Fatal(err) - } - - if len(c1.HostConfig.Links) != 1 { - t.Fatal("expected links to be populated but is empty") - } - - expected := name2 + ":" + alias - actual := c1.HostConfig.Links[0] - if actual != expected { - t.Fatalf("got wrong link value, expected: %q, got: %q", expected, actual) - } - - // ensure this is persisted - b, err := ioutil.ReadFile(filepath.Join(c1.Root, "hostconfig.json")) - if err != nil { - t.Fatal(err) - } - type hc struct { - Links []string - } - var cfg hc - if err := json.Unmarshal(b, &cfg); err != nil { - t.Fatal(err) - } - - if len(cfg.Links) != 1 { - t.Fatalf("expected one entry in links, got: %d", len(cfg.Links)) - } - if cfg.Links[0] != expected { // same expected as above - t.Fatalf("got wrong link value, expected: %q, got: %q", expected, cfg.Links[0]) - } -} diff --git a/vendor/github.com/docker/docker/daemon/links_notlinux.go b/vendor/github.com/docker/docker/daemon/links_notlinux.go deleted file mode 100644 index 12c226c..0000000 --- a/vendor/github.com/docker/docker/daemon/links_notlinux.go +++ /dev/null @@ -1,10 +0,0 @@ -// +build !linux - -package daemon - -import "github.com/docker/docker/container" - -// sqliteMigration performs the link graph DB migration. No-op on platforms other than Linux -func (daemon *Daemon) sqliteMigration(_ map[string]*container.Container) error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/list.go b/vendor/github.com/docker/docker/daemon/list.go deleted file mode 100644 index 02805ea..0000000 --- a/vendor/github.com/docker/docker/daemon/list.go +++ /dev/null @@ -1,660 +0,0 @@ -package daemon - -import ( - "errors" - "fmt" - "sort" - "strconv" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/container" - "github.com/docker/docker/image" - "github.com/docker/docker/volume" - "github.com/docker/go-connections/nat" -) - -var acceptedVolumeFilterTags = map[string]bool{ - "dangling": true, - "name": true, - "driver": true, - "label": true, -} - -var acceptedPsFilterTags = map[string]bool{ - "ancestor": true, - "before": true, - "exited": true, - "id": true, - "isolation": true, - "label": true, - "name": true, - "status": true, - "health": true, - "since": true, - "volume": true, - "network": true, - "is-task": true, -} - -// iterationAction represents possible outcomes happening during the container iteration. -type iterationAction int - -// containerReducer represents a reducer for a container. -// Returns the object to serialize by the api. -type containerReducer func(*container.Container, *listContext) (*types.Container, error) - -const ( - // includeContainer is the action to include a container in the reducer. - includeContainer iterationAction = iota - // excludeContainer is the action to exclude a container in the reducer. - excludeContainer - // stopIteration is the action to stop iterating over the list of containers. - stopIteration -) - -// errStopIteration makes the iterator to stop without returning an error. -var errStopIteration = errors.New("container list iteration stopped") - -// List returns an array of all containers registered in the daemon. -func (daemon *Daemon) List() []*container.Container { - return daemon.containers.List() -} - -// listContext is the daemon generated filtering to iterate over containers. -// This is created based on the user specification from types.ContainerListOptions. -type listContext struct { - // idx is the container iteration index for this context - idx int - // ancestorFilter tells whether it should check ancestors or not - ancestorFilter bool - // names is a list of container names to filter with - names map[string][]string - // images is a list of images to filter with - images map[image.ID]bool - // filters is a collection of arguments to filter with, specified by the user - filters filters.Args - // exitAllowed is a list of exit codes allowed to filter with - exitAllowed []int - - // beforeFilter is a filter to ignore containers that appear before the one given - beforeFilter *container.Container - // sinceFilter is a filter to stop the filtering when the iterator arrive to the given container - sinceFilter *container.Container - - // taskFilter tells if we should filter based on wether a container is part of a task - taskFilter bool - // isTask tells us if the we should filter container that are a task (true) or not (false) - isTask bool - // ContainerListOptions is the filters set by the user - *types.ContainerListOptions -} - -// byContainerCreated is a temporary type used to sort a list of containers by creation time. -type byContainerCreated []*container.Container - -func (r byContainerCreated) Len() int { return len(r) } -func (r byContainerCreated) Swap(i, j int) { r[i], r[j] = r[j], r[i] } -func (r byContainerCreated) Less(i, j int) bool { - return r[i].Created.UnixNano() < r[j].Created.UnixNano() -} - -// Containers returns the list of containers to show given the user's filtering. -func (daemon *Daemon) Containers(config *types.ContainerListOptions) ([]*types.Container, error) { - return daemon.reduceContainers(config, daemon.transformContainer) -} - -func (daemon *Daemon) filterByNameIDMatches(ctx *listContext) []*container.Container { - idSearch := false - names := ctx.filters.Get("name") - ids := ctx.filters.Get("id") - if len(names)+len(ids) == 0 { - // if name or ID filters are not in use, return to - // standard behavior of walking the entire container - // list from the daemon's in-memory store - return daemon.List() - } - - // idSearch will determine if we limit name matching to the IDs - // matched from any IDs which were specified as filters - if len(ids) > 0 { - idSearch = true - } - - matches := make(map[string]bool) - // find ID matches; errors represent "not found" and can be ignored - for _, id := range ids { - if fullID, err := daemon.idIndex.Get(id); err == nil { - matches[fullID] = true - } - } - - // look for name matches; if ID filtering was used, then limit the - // search space to the matches map only; errors represent "not found" - // and can be ignored - if len(names) > 0 { - for id, idNames := range ctx.names { - // if ID filters were used and no matches on that ID were - // found, continue to next ID in the list - if idSearch && !matches[id] { - continue - } - for _, eachName := range idNames { - if ctx.filters.Match("name", eachName) { - matches[id] = true - } - } - } - } - - cntrs := make([]*container.Container, 0, len(matches)) - for id := range matches { - if c := daemon.containers.Get(id); c != nil { - cntrs = append(cntrs, c) - } - } - - // Restore sort-order after filtering - // Created gives us nanosec resolution for sorting - sort.Sort(sort.Reverse(byContainerCreated(cntrs))) - - return cntrs -} - -// reduceContainers parses the user's filtering options and generates the list of containers to return based on a reducer. -func (daemon *Daemon) reduceContainers(config *types.ContainerListOptions, reducer containerReducer) ([]*types.Container, error) { - var ( - containers = []*types.Container{} - ) - - ctx, err := daemon.foldFilter(config) - if err != nil { - return nil, err - } - - // fastpath to only look at a subset of containers if specific name - // or ID matches were provided by the user--otherwise we potentially - // end up locking and querying many more containers than intended - containerList := daemon.filterByNameIDMatches(ctx) - - for _, container := range containerList { - t, err := daemon.reducePsContainer(container, ctx, reducer) - if err != nil { - if err != errStopIteration { - return nil, err - } - break - } - if t != nil { - containers = append(containers, t) - ctx.idx++ - } - } - - return containers, nil -} - -// reducePsContainer is the basic representation for a container as expected by the ps command. -func (daemon *Daemon) reducePsContainer(container *container.Container, ctx *listContext, reducer containerReducer) (*types.Container, error) { - container.Lock() - defer container.Unlock() - - // filter containers to return - action := includeContainerInList(container, ctx) - switch action { - case excludeContainer: - return nil, nil - case stopIteration: - return nil, errStopIteration - } - - // transform internal container struct into api structs - return reducer(container, ctx) -} - -// foldFilter generates the container filter based on the user's filtering options. -func (daemon *Daemon) foldFilter(config *types.ContainerListOptions) (*listContext, error) { - psFilters := config.Filters - - if err := psFilters.Validate(acceptedPsFilterTags); err != nil { - return nil, err - } - - var filtExited []int - - err := psFilters.WalkValues("exited", func(value string) error { - code, err := strconv.Atoi(value) - if err != nil { - return err - } - filtExited = append(filtExited, code) - return nil - }) - if err != nil { - return nil, err - } - - err = psFilters.WalkValues("status", func(value string) error { - if !container.IsValidStateString(value) { - return fmt.Errorf("Unrecognised filter value for status: %s", value) - } - - config.All = true - return nil - }) - if err != nil { - return nil, err - } - - var taskFilter, isTask bool - if psFilters.Include("is-task") { - if psFilters.ExactMatch("is-task", "true") { - taskFilter = true - isTask = true - } else if psFilters.ExactMatch("is-task", "false") { - taskFilter = true - isTask = false - } else { - return nil, fmt.Errorf("Invalid filter 'is-task=%s'", psFilters.Get("is-task")) - } - } - - err = psFilters.WalkValues("health", func(value string) error { - if !container.IsValidHealthString(value) { - return fmt.Errorf("Unrecognised filter value for health: %s", value) - } - - return nil - }) - if err != nil { - return nil, err - } - - var beforeContFilter, sinceContFilter *container.Container - - err = psFilters.WalkValues("before", func(value string) error { - beforeContFilter, err = daemon.GetContainer(value) - return err - }) - if err != nil { - return nil, err - } - - err = psFilters.WalkValues("since", func(value string) error { - sinceContFilter, err = daemon.GetContainer(value) - return err - }) - if err != nil { - return nil, err - } - - imagesFilter := map[image.ID]bool{} - var ancestorFilter bool - if psFilters.Include("ancestor") { - ancestorFilter = true - psFilters.WalkValues("ancestor", func(ancestor string) error { - id, err := daemon.GetImageID(ancestor) - if err != nil { - logrus.Warnf("Error while looking up for image %v", ancestor) - return nil - } - if imagesFilter[id] { - // Already seen this ancestor, skip it - return nil - } - // Then walk down the graph and put the imageIds in imagesFilter - populateImageFilterByParents(imagesFilter, id, daemon.imageStore.Children) - return nil - }) - } - - return &listContext{ - filters: psFilters, - ancestorFilter: ancestorFilter, - images: imagesFilter, - exitAllowed: filtExited, - beforeFilter: beforeContFilter, - sinceFilter: sinceContFilter, - taskFilter: taskFilter, - isTask: isTask, - ContainerListOptions: config, - names: daemon.nameIndex.GetAll(), - }, nil -} - -// includeContainerInList decides whether a container should be included in the output or not based in the filter. -// It also decides if the iteration should be stopped or not. -func includeContainerInList(container *container.Container, ctx *listContext) iterationAction { - // Do not include container if it's in the list before the filter container. - // Set the filter container to nil to include the rest of containers after this one. - if ctx.beforeFilter != nil { - if container.ID == ctx.beforeFilter.ID { - ctx.beforeFilter = nil - } - return excludeContainer - } - - // Stop iteration when the container arrives to the filter container - if ctx.sinceFilter != nil { - if container.ID == ctx.sinceFilter.ID { - return stopIteration - } - } - - // Do not include container if it's stopped and we're not filters - if !container.Running && !ctx.All && ctx.Limit <= 0 { - return excludeContainer - } - - // Do not include container if the name doesn't match - if !ctx.filters.Match("name", container.Name) { - return excludeContainer - } - - // Do not include container if the id doesn't match - if !ctx.filters.Match("id", container.ID) { - return excludeContainer - } - - if ctx.taskFilter { - if ctx.isTask != container.Managed { - return excludeContainer - } - } - - // Do not include container if any of the labels don't match - if !ctx.filters.MatchKVList("label", container.Config.Labels) { - return excludeContainer - } - - // Do not include container if isolation doesn't match - if excludeContainer == excludeByIsolation(container, ctx) { - return excludeContainer - } - - // Stop iteration when the index is over the limit - if ctx.Limit > 0 && ctx.idx == ctx.Limit { - return stopIteration - } - - // Do not include container if its exit code is not in the filter - if len(ctx.exitAllowed) > 0 { - shouldSkip := true - for _, code := range ctx.exitAllowed { - if code == container.ExitCode() && !container.Running && !container.StartedAt.IsZero() { - shouldSkip = false - break - } - } - if shouldSkip { - return excludeContainer - } - } - - // Do not include container if its status doesn't match the filter - if !ctx.filters.Match("status", container.State.StateString()) { - return excludeContainer - } - - // Do not include container if its health doesn't match the filter - if !ctx.filters.ExactMatch("health", container.State.HealthString()) { - return excludeContainer - } - - if ctx.filters.Include("volume") { - volumesByName := make(map[string]*volume.MountPoint) - for _, m := range container.MountPoints { - if m.Name != "" { - volumesByName[m.Name] = m - } else { - volumesByName[m.Source] = m - } - } - - volumeExist := fmt.Errorf("volume mounted in container") - err := ctx.filters.WalkValues("volume", func(value string) error { - if _, exist := container.MountPoints[value]; exist { - return volumeExist - } - if _, exist := volumesByName[value]; exist { - return volumeExist - } - return nil - }) - if err != volumeExist { - return excludeContainer - } - } - - if ctx.ancestorFilter { - if len(ctx.images) == 0 { - return excludeContainer - } - if !ctx.images[container.ImageID] { - return excludeContainer - } - } - - networkExist := fmt.Errorf("container part of network") - if ctx.filters.Include("network") { - err := ctx.filters.WalkValues("network", func(value string) error { - if _, ok := container.NetworkSettings.Networks[value]; ok { - return networkExist - } - for _, nw := range container.NetworkSettings.Networks { - if nw.EndpointSettings == nil { - continue - } - if nw.NetworkID == value { - return networkExist - } - } - return nil - }) - if err != networkExist { - return excludeContainer - } - } - - return includeContainer -} - -// transformContainer generates the container type expected by the docker ps command. -func (daemon *Daemon) transformContainer(container *container.Container, ctx *listContext) (*types.Container, error) { - newC := &types.Container{ - ID: container.ID, - Names: ctx.names[container.ID], - ImageID: container.ImageID.String(), - } - if newC.Names == nil { - // Dead containers will often have no name, so make sure the response isn't null - newC.Names = []string{} - } - - image := container.Config.Image // if possible keep the original ref - if image != container.ImageID.String() { - id, err := daemon.GetImageID(image) - if _, isDNE := err.(ErrImageDoesNotExist); err != nil && !isDNE { - return nil, err - } - if err != nil || id != container.ImageID { - image = container.ImageID.String() - } - } - newC.Image = image - - if len(container.Args) > 0 { - args := []string{} - for _, arg := range container.Args { - if strings.Contains(arg, " ") { - args = append(args, fmt.Sprintf("'%s'", arg)) - } else { - args = append(args, arg) - } - } - argsAsString := strings.Join(args, " ") - - newC.Command = fmt.Sprintf("%s %s", container.Path, argsAsString) - } else { - newC.Command = container.Path - } - newC.Created = container.Created.Unix() - newC.State = container.State.StateString() - newC.Status = container.State.String() - newC.HostConfig.NetworkMode = string(container.HostConfig.NetworkMode) - // copy networks to avoid races - networks := make(map[string]*networktypes.EndpointSettings) - for name, network := range container.NetworkSettings.Networks { - if network == nil || network.EndpointSettings == nil { - continue - } - networks[name] = &networktypes.EndpointSettings{ - EndpointID: network.EndpointID, - Gateway: network.Gateway, - IPAddress: network.IPAddress, - IPPrefixLen: network.IPPrefixLen, - IPv6Gateway: network.IPv6Gateway, - GlobalIPv6Address: network.GlobalIPv6Address, - GlobalIPv6PrefixLen: network.GlobalIPv6PrefixLen, - MacAddress: network.MacAddress, - NetworkID: network.NetworkID, - } - if network.IPAMConfig != nil { - networks[name].IPAMConfig = &networktypes.EndpointIPAMConfig{ - IPv4Address: network.IPAMConfig.IPv4Address, - IPv6Address: network.IPAMConfig.IPv6Address, - } - } - } - newC.NetworkSettings = &types.SummaryNetworkSettings{Networks: networks} - - newC.Ports = []types.Port{} - for port, bindings := range container.NetworkSettings.Ports { - p, err := nat.ParsePort(port.Port()) - if err != nil { - return nil, err - } - if len(bindings) == 0 { - newC.Ports = append(newC.Ports, types.Port{ - PrivatePort: uint16(p), - Type: port.Proto(), - }) - continue - } - for _, binding := range bindings { - h, err := nat.ParsePort(binding.HostPort) - if err != nil { - return nil, err - } - newC.Ports = append(newC.Ports, types.Port{ - PrivatePort: uint16(p), - PublicPort: uint16(h), - Type: port.Proto(), - IP: binding.HostIP, - }) - } - } - - if ctx.Size { - sizeRw, sizeRootFs := daemon.getSize(container) - newC.SizeRw = sizeRw - newC.SizeRootFs = sizeRootFs - } - newC.Labels = container.Config.Labels - newC.Mounts = addMountPoints(container) - - return newC, nil -} - -// Volumes lists known volumes, using the filter to restrict the range -// of volumes returned. -func (daemon *Daemon) Volumes(filter string) ([]*types.Volume, []string, error) { - var ( - volumesOut []*types.Volume - ) - volFilters, err := filters.FromParam(filter) - if err != nil { - return nil, nil, err - } - - if err := volFilters.Validate(acceptedVolumeFilterTags); err != nil { - return nil, nil, err - } - - volumes, warnings, err := daemon.volumes.List() - if err != nil { - return nil, nil, err - } - - filterVolumes, err := daemon.filterVolumes(volumes, volFilters) - if err != nil { - return nil, nil, err - } - for _, v := range filterVolumes { - apiV := volumeToAPIType(v) - if vv, ok := v.(interface { - CachedPath() string - }); ok { - apiV.Mountpoint = vv.CachedPath() - } else { - apiV.Mountpoint = v.Path() - } - volumesOut = append(volumesOut, apiV) - } - return volumesOut, warnings, nil -} - -// filterVolumes filters volume list according to user specified filter -// and returns user chosen volumes -func (daemon *Daemon) filterVolumes(vols []volume.Volume, filter filters.Args) ([]volume.Volume, error) { - // if filter is empty, return original volume list - if filter.Len() == 0 { - return vols, nil - } - - var retVols []volume.Volume - for _, vol := range vols { - if filter.Include("name") { - if !filter.Match("name", vol.Name()) { - continue - } - } - if filter.Include("driver") { - if !filter.Match("driver", vol.DriverName()) { - continue - } - } - if filter.Include("label") { - v, ok := vol.(volume.DetailedVolume) - if !ok { - continue - } - if !filter.MatchKVList("label", v.Labels()) { - continue - } - } - retVols = append(retVols, vol) - } - danglingOnly := false - if filter.Include("dangling") { - if filter.ExactMatch("dangling", "true") || filter.ExactMatch("dangling", "1") { - danglingOnly = true - } else if !filter.ExactMatch("dangling", "false") && !filter.ExactMatch("dangling", "0") { - return nil, fmt.Errorf("Invalid filter 'dangling=%s'", filter.Get("dangling")) - } - retVols = daemon.volumes.FilterByUsed(retVols, !danglingOnly) - } - return retVols, nil -} - -func populateImageFilterByParents(ancestorMap map[image.ID]bool, imageID image.ID, getChildren func(image.ID) []image.ID) { - if !ancestorMap[imageID] { - for _, id := range getChildren(imageID) { - populateImageFilterByParents(ancestorMap, id, getChildren) - } - ancestorMap[imageID] = true - } -} diff --git a/vendor/github.com/docker/docker/daemon/list_unix.go b/vendor/github.com/docker/docker/daemon/list_unix.go deleted file mode 100644 index 91c9cac..0000000 --- a/vendor/github.com/docker/docker/daemon/list_unix.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build linux freebsd solaris - -package daemon - -import "github.com/docker/docker/container" - -// excludeByIsolation is a platform specific helper function to support PS -// filtering by Isolation. This is a Windows-only concept, so is a no-op on Unix. -func excludeByIsolation(container *container.Container, ctx *listContext) iterationAction { - return includeContainer -} diff --git a/vendor/github.com/docker/docker/daemon/list_windows.go b/vendor/github.com/docker/docker/daemon/list_windows.go deleted file mode 100644 index 7fbcd3a..0000000 --- a/vendor/github.com/docker/docker/daemon/list_windows.go +++ /dev/null @@ -1,20 +0,0 @@ -package daemon - -import ( - "strings" - - "github.com/docker/docker/container" -) - -// excludeByIsolation is a platform specific helper function to support PS -// filtering by Isolation. This is a Windows-only concept, so is a no-op on Unix. -func excludeByIsolation(container *container.Container, ctx *listContext) iterationAction { - i := strings.ToLower(string(container.HostConfig.Isolation)) - if i == "" { - i = "default" - } - if !ctx.filters.Match("isolation", i) { - return excludeContainer - } - return includeContainer -} diff --git a/vendor/github.com/docker/docker/daemon/logdrivers_linux.go b/vendor/github.com/docker/docker/daemon/logdrivers_linux.go deleted file mode 100644 index ad343c1..0000000 --- a/vendor/github.com/docker/docker/daemon/logdrivers_linux.go +++ /dev/null @@ -1,15 +0,0 @@ -package daemon - -import ( - // Importing packages here only to make sure their init gets called and - // therefore they register themselves to the logdriver factory. - _ "github.com/docker/docker/daemon/logger/awslogs" - _ "github.com/docker/docker/daemon/logger/fluentd" - _ "github.com/docker/docker/daemon/logger/gcplogs" - _ "github.com/docker/docker/daemon/logger/gelf" - _ "github.com/docker/docker/daemon/logger/journald" - _ "github.com/docker/docker/daemon/logger/jsonfilelog" - _ "github.com/docker/docker/daemon/logger/logentries" - _ "github.com/docker/docker/daemon/logger/splunk" - _ "github.com/docker/docker/daemon/logger/syslog" -) diff --git a/vendor/github.com/docker/docker/daemon/logdrivers_windows.go b/vendor/github.com/docker/docker/daemon/logdrivers_windows.go deleted file mode 100644 index f3002b9..0000000 --- a/vendor/github.com/docker/docker/daemon/logdrivers_windows.go +++ /dev/null @@ -1,13 +0,0 @@ -package daemon - -import ( - // Importing packages here only to make sure their init gets called and - // therefore they register themselves to the logdriver factory. - _ "github.com/docker/docker/daemon/logger/awslogs" - _ "github.com/docker/docker/daemon/logger/etwlogs" - _ "github.com/docker/docker/daemon/logger/fluentd" - _ "github.com/docker/docker/daemon/logger/jsonfilelog" - _ "github.com/docker/docker/daemon/logger/logentries" - _ "github.com/docker/docker/daemon/logger/splunk" - _ "github.com/docker/docker/daemon/logger/syslog" -) diff --git a/vendor/github.com/docker/docker/daemon/logger/awslogs/cloudwatchlogs.go b/vendor/github.com/docker/docker/daemon/logger/awslogs/cloudwatchlogs.go deleted file mode 100644 index fee518d..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/awslogs/cloudwatchlogs.go +++ /dev/null @@ -1,404 +0,0 @@ -// Package awslogs provides the logdriver for forwarding container logs to Amazon CloudWatch Logs -package awslogs - -import ( - "errors" - "fmt" - "os" - "runtime" - "sort" - "strings" - "sync" - "time" - - "github.com/Sirupsen/logrus" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/aws/aws-sdk-go/aws/ec2metadata" - "github.com/aws/aws-sdk-go/aws/request" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/cloudwatchlogs" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/daemon/logger/loggerutils" - "github.com/docker/docker/dockerversion" -) - -const ( - name = "awslogs" - regionKey = "awslogs-region" - regionEnvKey = "AWS_REGION" - logGroupKey = "awslogs-group" - logStreamKey = "awslogs-stream" - tagKey = "tag" - batchPublishFrequency = 5 * time.Second - - // See: http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html - perEventBytes = 26 - maximumBytesPerPut = 1048576 - maximumLogEventsPerPut = 10000 - - // See: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_limits.html - maximumBytesPerEvent = 262144 - perEventBytes - - resourceAlreadyExistsCode = "ResourceAlreadyExistsException" - dataAlreadyAcceptedCode = "DataAlreadyAcceptedException" - invalidSequenceTokenCode = "InvalidSequenceTokenException" - - userAgentHeader = "User-Agent" -) - -type logStream struct { - logStreamName string - logGroupName string - client api - messages chan *logger.Message - lock sync.RWMutex - closed bool - sequenceToken *string -} - -type api interface { - CreateLogStream(*cloudwatchlogs.CreateLogStreamInput) (*cloudwatchlogs.CreateLogStreamOutput, error) - PutLogEvents(*cloudwatchlogs.PutLogEventsInput) (*cloudwatchlogs.PutLogEventsOutput, error) -} - -type regionFinder interface { - Region() (string, error) -} - -type wrappedEvent struct { - inputLogEvent *cloudwatchlogs.InputLogEvent - insertOrder int -} -type byTimestamp []wrappedEvent - -// init registers the awslogs driver -func init() { - if err := logger.RegisterLogDriver(name, New); err != nil { - logrus.Fatal(err) - } - if err := logger.RegisterLogOptValidator(name, ValidateLogOpt); err != nil { - logrus.Fatal(err) - } -} - -// New creates an awslogs logger using the configuration passed in on the -// context. Supported context configuration variables are awslogs-region, -// awslogs-group, and awslogs-stream. When available, configuration is -// also taken from environment variables AWS_REGION, AWS_ACCESS_KEY_ID, -// AWS_SECRET_ACCESS_KEY, the shared credentials file (~/.aws/credentials), and -// the EC2 Instance Metadata Service. -func New(ctx logger.Context) (logger.Logger, error) { - logGroupName := ctx.Config[logGroupKey] - logStreamName, err := loggerutils.ParseLogTag(ctx, "{{.FullID}}") - if err != nil { - return nil, err - } - - if ctx.Config[logStreamKey] != "" { - logStreamName = ctx.Config[logStreamKey] - } - client, err := newAWSLogsClient(ctx) - if err != nil { - return nil, err - } - containerStream := &logStream{ - logStreamName: logStreamName, - logGroupName: logGroupName, - client: client, - messages: make(chan *logger.Message, 4096), - } - err = containerStream.create() - if err != nil { - return nil, err - } - go containerStream.collectBatch() - - return containerStream, nil -} - -// newRegionFinder is a variable such that the implementation -// can be swapped out for unit tests. -var newRegionFinder = func() regionFinder { - return ec2metadata.New(session.New()) -} - -// newAWSLogsClient creates the service client for Amazon CloudWatch Logs. -// Customizations to the default client from the SDK include a Docker-specific -// User-Agent string and automatic region detection using the EC2 Instance -// Metadata Service when region is otherwise unspecified. -func newAWSLogsClient(ctx logger.Context) (api, error) { - var region *string - if os.Getenv(regionEnvKey) != "" { - region = aws.String(os.Getenv(regionEnvKey)) - } - if ctx.Config[regionKey] != "" { - region = aws.String(ctx.Config[regionKey]) - } - if region == nil || *region == "" { - logrus.Info("Trying to get region from EC2 Metadata") - ec2MetadataClient := newRegionFinder() - r, err := ec2MetadataClient.Region() - if err != nil { - logrus.WithFields(logrus.Fields{ - "error": err, - }).Error("Could not get region from EC2 metadata, environment, or log option") - return nil, errors.New("Cannot determine region for awslogs driver") - } - region = &r - } - logrus.WithFields(logrus.Fields{ - "region": *region, - }).Debug("Created awslogs client") - - client := cloudwatchlogs.New(session.New(), aws.NewConfig().WithRegion(*region)) - - client.Handlers.Build.PushBackNamed(request.NamedHandler{ - Name: "DockerUserAgentHandler", - Fn: func(r *request.Request) { - currentAgent := r.HTTPRequest.Header.Get(userAgentHeader) - r.HTTPRequest.Header.Set(userAgentHeader, - fmt.Sprintf("Docker %s (%s) %s", - dockerversion.Version, runtime.GOOS, currentAgent)) - }, - }) - return client, nil -} - -// Name returns the name of the awslogs logging driver -func (l *logStream) Name() string { - return name -} - -// Log submits messages for logging by an instance of the awslogs logging driver -func (l *logStream) Log(msg *logger.Message) error { - l.lock.RLock() - defer l.lock.RUnlock() - if !l.closed { - // buffer up the data, making sure to copy the Line data - l.messages <- logger.CopyMessage(msg) - } - return nil -} - -// Close closes the instance of the awslogs logging driver -func (l *logStream) Close() error { - l.lock.Lock() - defer l.lock.Unlock() - if !l.closed { - close(l.messages) - } - l.closed = true - return nil -} - -// create creates a log stream for the instance of the awslogs logging driver -func (l *logStream) create() error { - input := &cloudwatchlogs.CreateLogStreamInput{ - LogGroupName: aws.String(l.logGroupName), - LogStreamName: aws.String(l.logStreamName), - } - - _, err := l.client.CreateLogStream(input) - - if err != nil { - if awsErr, ok := err.(awserr.Error); ok { - fields := logrus.Fields{ - "errorCode": awsErr.Code(), - "message": awsErr.Message(), - "origError": awsErr.OrigErr(), - "logGroupName": l.logGroupName, - "logStreamName": l.logStreamName, - } - if awsErr.Code() == resourceAlreadyExistsCode { - // Allow creation to succeed - logrus.WithFields(fields).Info("Log stream already exists") - return nil - } - logrus.WithFields(fields).Error("Failed to create log stream") - } - } - return err -} - -// newTicker is used for time-based batching. newTicker is a variable such -// that the implementation can be swapped out for unit tests. -var newTicker = func(freq time.Duration) *time.Ticker { - return time.NewTicker(freq) -} - -// collectBatch executes as a goroutine to perform batching of log events for -// submission to the log stream. Batching is performed on time- and size- -// bases. Time-based batching occurs at a 5 second interval (defined in the -// batchPublishFrequency const). Size-based batching is performed on the -// maximum number of events per batch (defined in maximumLogEventsPerPut) and -// the maximum number of total bytes in a batch (defined in -// maximumBytesPerPut). Log messages are split by the maximum bytes per event -// (defined in maximumBytesPerEvent). There is a fixed per-event byte overhead -// (defined in perEventBytes) which is accounted for in split- and batch- -// calculations. -func (l *logStream) collectBatch() { - timer := newTicker(batchPublishFrequency) - var events []wrappedEvent - bytes := 0 - for { - select { - case <-timer.C: - l.publishBatch(events) - events = events[:0] - bytes = 0 - case msg, more := <-l.messages: - if !more { - l.publishBatch(events) - return - } - unprocessedLine := msg.Line - for len(unprocessedLine) > 0 { - // Split line length so it does not exceed the maximum - lineBytes := len(unprocessedLine) - if lineBytes > maximumBytesPerEvent { - lineBytes = maximumBytesPerEvent - } - line := unprocessedLine[:lineBytes] - unprocessedLine = unprocessedLine[lineBytes:] - if (len(events) >= maximumLogEventsPerPut) || (bytes+lineBytes+perEventBytes > maximumBytesPerPut) { - // Publish an existing batch if it's already over the maximum number of events or if adding this - // event would push it over the maximum number of total bytes. - l.publishBatch(events) - events = events[:0] - bytes = 0 - } - events = append(events, wrappedEvent{ - inputLogEvent: &cloudwatchlogs.InputLogEvent{ - Message: aws.String(string(line)), - Timestamp: aws.Int64(msg.Timestamp.UnixNano() / int64(time.Millisecond)), - }, - insertOrder: len(events), - }) - bytes += (lineBytes + perEventBytes) - } - } - } -} - -// publishBatch calls PutLogEvents for a given set of InputLogEvents, -// accounting for sequencing requirements (each request must reference the -// sequence token returned by the previous request). -func (l *logStream) publishBatch(events []wrappedEvent) { - if len(events) == 0 { - return - } - - // events in a batch must be sorted by timestamp - // see http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html - sort.Sort(byTimestamp(events)) - cwEvents := unwrapEvents(events) - - nextSequenceToken, err := l.putLogEvents(cwEvents, l.sequenceToken) - - if err != nil { - if awsErr, ok := err.(awserr.Error); ok { - if awsErr.Code() == dataAlreadyAcceptedCode { - // already submitted, just grab the correct sequence token - parts := strings.Split(awsErr.Message(), " ") - nextSequenceToken = &parts[len(parts)-1] - logrus.WithFields(logrus.Fields{ - "errorCode": awsErr.Code(), - "message": awsErr.Message(), - "logGroupName": l.logGroupName, - "logStreamName": l.logStreamName, - }).Info("Data already accepted, ignoring error") - err = nil - } else if awsErr.Code() == invalidSequenceTokenCode { - // sequence code is bad, grab the correct one and retry - parts := strings.Split(awsErr.Message(), " ") - token := parts[len(parts)-1] - nextSequenceToken, err = l.putLogEvents(cwEvents, &token) - } - } - } - if err != nil { - logrus.Error(err) - } else { - l.sequenceToken = nextSequenceToken - } -} - -// putLogEvents wraps the PutLogEvents API -func (l *logStream) putLogEvents(events []*cloudwatchlogs.InputLogEvent, sequenceToken *string) (*string, error) { - input := &cloudwatchlogs.PutLogEventsInput{ - LogEvents: events, - SequenceToken: sequenceToken, - LogGroupName: aws.String(l.logGroupName), - LogStreamName: aws.String(l.logStreamName), - } - resp, err := l.client.PutLogEvents(input) - if err != nil { - if awsErr, ok := err.(awserr.Error); ok { - logrus.WithFields(logrus.Fields{ - "errorCode": awsErr.Code(), - "message": awsErr.Message(), - "origError": awsErr.OrigErr(), - "logGroupName": l.logGroupName, - "logStreamName": l.logStreamName, - }).Error("Failed to put log events") - } - return nil, err - } - return resp.NextSequenceToken, nil -} - -// ValidateLogOpt looks for awslogs-specific log options awslogs-region, -// awslogs-group, and awslogs-stream -func ValidateLogOpt(cfg map[string]string) error { - for key := range cfg { - switch key { - case logGroupKey: - case logStreamKey: - case regionKey: - case tagKey: - default: - return fmt.Errorf("unknown log opt '%s' for %s log driver", key, name) - } - } - if cfg[logGroupKey] == "" { - return fmt.Errorf("must specify a value for log opt '%s'", logGroupKey) - } - return nil -} - -// Len returns the length of a byTimestamp slice. Len is required by the -// sort.Interface interface. -func (slice byTimestamp) Len() int { - return len(slice) -} - -// Less compares two values in a byTimestamp slice by Timestamp. Less is -// required by the sort.Interface interface. -func (slice byTimestamp) Less(i, j int) bool { - iTimestamp, jTimestamp := int64(0), int64(0) - if slice != nil && slice[i].inputLogEvent.Timestamp != nil { - iTimestamp = *slice[i].inputLogEvent.Timestamp - } - if slice != nil && slice[j].inputLogEvent.Timestamp != nil { - jTimestamp = *slice[j].inputLogEvent.Timestamp - } - if iTimestamp == jTimestamp { - return slice[i].insertOrder < slice[j].insertOrder - } - return iTimestamp < jTimestamp -} - -// Swap swaps two values in a byTimestamp slice with each other. Swap is -// required by the sort.Interface interface. -func (slice byTimestamp) Swap(i, j int) { - slice[i], slice[j] = slice[j], slice[i] -} - -func unwrapEvents(events []wrappedEvent) []*cloudwatchlogs.InputLogEvent { - cwEvents := []*cloudwatchlogs.InputLogEvent{} - for _, input := range events { - cwEvents = append(cwEvents, input.inputLogEvent) - } - return cwEvents -} diff --git a/vendor/github.com/docker/docker/daemon/logger/awslogs/cloudwatchlogs_test.go b/vendor/github.com/docker/docker/daemon/logger/awslogs/cloudwatchlogs_test.go deleted file mode 100644 index d5b1aae..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/awslogs/cloudwatchlogs_test.go +++ /dev/null @@ -1,724 +0,0 @@ -package awslogs - -import ( - "errors" - "fmt" - "net/http" - "reflect" - "runtime" - "strings" - "testing" - "time" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/aws/aws-sdk-go/aws/request" - "github.com/aws/aws-sdk-go/service/cloudwatchlogs" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/daemon/logger/loggerutils" - "github.com/docker/docker/dockerversion" -) - -const ( - groupName = "groupName" - streamName = "streamName" - sequenceToken = "sequenceToken" - nextSequenceToken = "nextSequenceToken" - logline = "this is a log line" -) - -func TestNewAWSLogsClientUserAgentHandler(t *testing.T) { - ctx := logger.Context{ - Config: map[string]string{ - regionKey: "us-east-1", - }, - } - - client, err := newAWSLogsClient(ctx) - if err != nil { - t.Fatal(err) - } - realClient, ok := client.(*cloudwatchlogs.CloudWatchLogs) - if !ok { - t.Fatal("Could not cast client to cloudwatchlogs.CloudWatchLogs") - } - buildHandlerList := realClient.Handlers.Build - request := &request.Request{ - HTTPRequest: &http.Request{ - Header: http.Header{}, - }, - } - buildHandlerList.Run(request) - expectedUserAgentString := fmt.Sprintf("Docker %s (%s) %s/%s (%s; %s; %s)", - dockerversion.Version, runtime.GOOS, aws.SDKName, aws.SDKVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH) - userAgent := request.HTTPRequest.Header.Get("User-Agent") - if userAgent != expectedUserAgentString { - t.Errorf("Wrong User-Agent string, expected \"%s\" but was \"%s\"", - expectedUserAgentString, userAgent) - } -} - -func TestNewAWSLogsClientRegionDetect(t *testing.T) { - ctx := logger.Context{ - Config: map[string]string{}, - } - - mockMetadata := newMockMetadataClient() - newRegionFinder = func() regionFinder { - return mockMetadata - } - mockMetadata.regionResult <- ®ionResult{ - successResult: "us-east-1", - } - - _, err := newAWSLogsClient(ctx) - if err != nil { - t.Fatal(err) - } -} - -func TestCreateSuccess(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - } - mockClient.createLogStreamResult <- &createLogStreamResult{} - - err := stream.create() - - if err != nil { - t.Errorf("Received unexpected err: %v\n", err) - } - argument := <-mockClient.createLogStreamArgument - if argument.LogGroupName == nil { - t.Fatal("Expected non-nil LogGroupName") - } - if *argument.LogGroupName != groupName { - t.Errorf("Expected LogGroupName to be %s", groupName) - } - if argument.LogStreamName == nil { - t.Fatal("Expected non-nil LogGroupName") - } - if *argument.LogStreamName != streamName { - t.Errorf("Expected LogStreamName to be %s", streamName) - } -} - -func TestCreateError(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - } - mockClient.createLogStreamResult <- &createLogStreamResult{ - errorResult: errors.New("Error!"), - } - - err := stream.create() - - if err == nil { - t.Fatal("Expected non-nil err") - } -} - -func TestCreateAlreadyExists(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - } - mockClient.createLogStreamResult <- &createLogStreamResult{ - errorResult: awserr.New(resourceAlreadyExistsCode, "", nil), - } - - err := stream.create() - - if err != nil { - t.Fatal("Expected nil err") - } -} - -func TestPublishBatchSuccess(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - successResult: &cloudwatchlogs.PutLogEventsOutput{ - NextSequenceToken: aws.String(nextSequenceToken), - }, - } - events := []wrappedEvent{ - { - inputLogEvent: &cloudwatchlogs.InputLogEvent{ - Message: aws.String(logline), - }, - }, - } - - stream.publishBatch(events) - if stream.sequenceToken == nil { - t.Fatal("Expected non-nil sequenceToken") - } - if *stream.sequenceToken != nextSequenceToken { - t.Errorf("Expected sequenceToken to be %s, but was %s", nextSequenceToken, *stream.sequenceToken) - } - argument := <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if argument.SequenceToken == nil { - t.Fatal("Expected non-nil PutLogEventsInput.SequenceToken") - } - if *argument.SequenceToken != sequenceToken { - t.Errorf("Expected PutLogEventsInput.SequenceToken to be %s, but was %s", sequenceToken, *argument.SequenceToken) - } - if len(argument.LogEvents) != 1 { - t.Errorf("Expected LogEvents to contain 1 element, but contains %d", len(argument.LogEvents)) - } - if argument.LogEvents[0] != events[0].inputLogEvent { - t.Error("Expected event to equal input") - } -} - -func TestPublishBatchError(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - errorResult: errors.New("Error!"), - } - - events := []wrappedEvent{ - { - inputLogEvent: &cloudwatchlogs.InputLogEvent{ - Message: aws.String(logline), - }, - }, - } - - stream.publishBatch(events) - if stream.sequenceToken == nil { - t.Fatal("Expected non-nil sequenceToken") - } - if *stream.sequenceToken != sequenceToken { - t.Errorf("Expected sequenceToken to be %s, but was %s", sequenceToken, *stream.sequenceToken) - } -} - -func TestPublishBatchInvalidSeqSuccess(t *testing.T) { - mockClient := newMockClientBuffered(2) - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - errorResult: awserr.New(invalidSequenceTokenCode, "use token token", nil), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - successResult: &cloudwatchlogs.PutLogEventsOutput{ - NextSequenceToken: aws.String(nextSequenceToken), - }, - } - - events := []wrappedEvent{ - { - inputLogEvent: &cloudwatchlogs.InputLogEvent{ - Message: aws.String(logline), - }, - }, - } - - stream.publishBatch(events) - if stream.sequenceToken == nil { - t.Fatal("Expected non-nil sequenceToken") - } - if *stream.sequenceToken != nextSequenceToken { - t.Errorf("Expected sequenceToken to be %s, but was %s", nextSequenceToken, *stream.sequenceToken) - } - - argument := <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if argument.SequenceToken == nil { - t.Fatal("Expected non-nil PutLogEventsInput.SequenceToken") - } - if *argument.SequenceToken != sequenceToken { - t.Errorf("Expected PutLogEventsInput.SequenceToken to be %s, but was %s", sequenceToken, *argument.SequenceToken) - } - if len(argument.LogEvents) != 1 { - t.Errorf("Expected LogEvents to contain 1 element, but contains %d", len(argument.LogEvents)) - } - if argument.LogEvents[0] != events[0].inputLogEvent { - t.Error("Expected event to equal input") - } - - argument = <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if argument.SequenceToken == nil { - t.Fatal("Expected non-nil PutLogEventsInput.SequenceToken") - } - if *argument.SequenceToken != "token" { - t.Errorf("Expected PutLogEventsInput.SequenceToken to be %s, but was %s", "token", *argument.SequenceToken) - } - if len(argument.LogEvents) != 1 { - t.Errorf("Expected LogEvents to contain 1 element, but contains %d", len(argument.LogEvents)) - } - if argument.LogEvents[0] != events[0].inputLogEvent { - t.Error("Expected event to equal input") - } -} - -func TestPublishBatchAlreadyAccepted(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - errorResult: awserr.New(dataAlreadyAcceptedCode, "use token token", nil), - } - - events := []wrappedEvent{ - { - inputLogEvent: &cloudwatchlogs.InputLogEvent{ - Message: aws.String(logline), - }, - }, - } - - stream.publishBatch(events) - if stream.sequenceToken == nil { - t.Fatal("Expected non-nil sequenceToken") - } - if *stream.sequenceToken != "token" { - t.Errorf("Expected sequenceToken to be %s, but was %s", "token", *stream.sequenceToken) - } - - argument := <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if argument.SequenceToken == nil { - t.Fatal("Expected non-nil PutLogEventsInput.SequenceToken") - } - if *argument.SequenceToken != sequenceToken { - t.Errorf("Expected PutLogEventsInput.SequenceToken to be %s, but was %s", sequenceToken, *argument.SequenceToken) - } - if len(argument.LogEvents) != 1 { - t.Errorf("Expected LogEvents to contain 1 element, but contains %d", len(argument.LogEvents)) - } - if argument.LogEvents[0] != events[0].inputLogEvent { - t.Error("Expected event to equal input") - } -} - -func TestCollectBatchSimple(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - messages: make(chan *logger.Message), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - successResult: &cloudwatchlogs.PutLogEventsOutput{ - NextSequenceToken: aws.String(nextSequenceToken), - }, - } - ticks := make(chan time.Time) - newTicker = func(_ time.Duration) *time.Ticker { - return &time.Ticker{ - C: ticks, - } - } - - go stream.collectBatch() - - stream.Log(&logger.Message{ - Line: []byte(logline), - Timestamp: time.Time{}, - }) - - ticks <- time.Time{} - stream.Close() - - argument := <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if len(argument.LogEvents) != 1 { - t.Errorf("Expected LogEvents to contain 1 element, but contains %d", len(argument.LogEvents)) - } - if *argument.LogEvents[0].Message != logline { - t.Errorf("Expected message to be %s but was %s", logline, *argument.LogEvents[0].Message) - } -} - -func TestCollectBatchTicker(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - messages: make(chan *logger.Message), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - successResult: &cloudwatchlogs.PutLogEventsOutput{ - NextSequenceToken: aws.String(nextSequenceToken), - }, - } - ticks := make(chan time.Time) - newTicker = func(_ time.Duration) *time.Ticker { - return &time.Ticker{ - C: ticks, - } - } - - go stream.collectBatch() - - stream.Log(&logger.Message{ - Line: []byte(logline + " 1"), - Timestamp: time.Time{}, - }) - stream.Log(&logger.Message{ - Line: []byte(logline + " 2"), - Timestamp: time.Time{}, - }) - - ticks <- time.Time{} - - // Verify first batch - argument := <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if len(argument.LogEvents) != 2 { - t.Errorf("Expected LogEvents to contain 2 elements, but contains %d", len(argument.LogEvents)) - } - if *argument.LogEvents[0].Message != logline+" 1" { - t.Errorf("Expected message to be %s but was %s", logline+" 1", *argument.LogEvents[0].Message) - } - if *argument.LogEvents[1].Message != logline+" 2" { - t.Errorf("Expected message to be %s but was %s", logline+" 2", *argument.LogEvents[0].Message) - } - - stream.Log(&logger.Message{ - Line: []byte(logline + " 3"), - Timestamp: time.Time{}, - }) - - ticks <- time.Time{} - argument = <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if len(argument.LogEvents) != 1 { - t.Errorf("Expected LogEvents to contain 1 elements, but contains %d", len(argument.LogEvents)) - } - if *argument.LogEvents[0].Message != logline+" 3" { - t.Errorf("Expected message to be %s but was %s", logline+" 3", *argument.LogEvents[0].Message) - } - - stream.Close() - -} - -func TestCollectBatchClose(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - messages: make(chan *logger.Message), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - successResult: &cloudwatchlogs.PutLogEventsOutput{ - NextSequenceToken: aws.String(nextSequenceToken), - }, - } - var ticks = make(chan time.Time) - newTicker = func(_ time.Duration) *time.Ticker { - return &time.Ticker{ - C: ticks, - } - } - - go stream.collectBatch() - - stream.Log(&logger.Message{ - Line: []byte(logline), - Timestamp: time.Time{}, - }) - - // no ticks - stream.Close() - - argument := <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if len(argument.LogEvents) != 1 { - t.Errorf("Expected LogEvents to contain 1 element, but contains %d", len(argument.LogEvents)) - } - if *argument.LogEvents[0].Message != logline { - t.Errorf("Expected message to be %s but was %s", logline, *argument.LogEvents[0].Message) - } -} - -func TestCollectBatchLineSplit(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - messages: make(chan *logger.Message), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - successResult: &cloudwatchlogs.PutLogEventsOutput{ - NextSequenceToken: aws.String(nextSequenceToken), - }, - } - var ticks = make(chan time.Time) - newTicker = func(_ time.Duration) *time.Ticker { - return &time.Ticker{ - C: ticks, - } - } - - go stream.collectBatch() - - longline := strings.Repeat("A", maximumBytesPerEvent) - stream.Log(&logger.Message{ - Line: []byte(longline + "B"), - Timestamp: time.Time{}, - }) - - // no ticks - stream.Close() - - argument := <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if len(argument.LogEvents) != 2 { - t.Errorf("Expected LogEvents to contain 2 elements, but contains %d", len(argument.LogEvents)) - } - if *argument.LogEvents[0].Message != longline { - t.Errorf("Expected message to be %s but was %s", longline, *argument.LogEvents[0].Message) - } - if *argument.LogEvents[1].Message != "B" { - t.Errorf("Expected message to be %s but was %s", "B", *argument.LogEvents[1].Message) - } -} - -func TestCollectBatchMaxEvents(t *testing.T) { - mockClient := newMockClientBuffered(1) - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - messages: make(chan *logger.Message), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - successResult: &cloudwatchlogs.PutLogEventsOutput{ - NextSequenceToken: aws.String(nextSequenceToken), - }, - } - var ticks = make(chan time.Time) - newTicker = func(_ time.Duration) *time.Ticker { - return &time.Ticker{ - C: ticks, - } - } - - go stream.collectBatch() - - line := "A" - for i := 0; i <= maximumLogEventsPerPut; i++ { - stream.Log(&logger.Message{ - Line: []byte(line), - Timestamp: time.Time{}, - }) - } - - // no ticks - stream.Close() - - argument := <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if len(argument.LogEvents) != maximumLogEventsPerPut { - t.Errorf("Expected LogEvents to contain %d elements, but contains %d", maximumLogEventsPerPut, len(argument.LogEvents)) - } - - argument = <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if len(argument.LogEvents) != 1 { - t.Errorf("Expected LogEvents to contain %d elements, but contains %d", 1, len(argument.LogEvents)) - } -} - -func TestCollectBatchMaxTotalBytes(t *testing.T) { - mockClient := newMockClientBuffered(1) - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - messages: make(chan *logger.Message), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - successResult: &cloudwatchlogs.PutLogEventsOutput{ - NextSequenceToken: aws.String(nextSequenceToken), - }, - } - var ticks = make(chan time.Time) - newTicker = func(_ time.Duration) *time.Ticker { - return &time.Ticker{ - C: ticks, - } - } - - go stream.collectBatch() - - longline := strings.Repeat("A", maximumBytesPerPut) - stream.Log(&logger.Message{ - Line: []byte(longline + "B"), - Timestamp: time.Time{}, - }) - - // no ticks - stream.Close() - - argument := <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - bytes := 0 - for _, event := range argument.LogEvents { - bytes += len(*event.Message) - } - if bytes > maximumBytesPerPut { - t.Errorf("Expected <= %d bytes but was %d", maximumBytesPerPut, bytes) - } - - argument = <-mockClient.putLogEventsArgument - if len(argument.LogEvents) != 1 { - t.Errorf("Expected LogEvents to contain 1 elements, but contains %d", len(argument.LogEvents)) - } - message := *argument.LogEvents[0].Message - if message[len(message)-1:] != "B" { - t.Errorf("Expected message to be %s but was %s", "B", message[len(message)-1:]) - } -} - -func TestCollectBatchWithDuplicateTimestamps(t *testing.T) { - mockClient := newMockClient() - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: streamName, - sequenceToken: aws.String(sequenceToken), - messages: make(chan *logger.Message), - } - mockClient.putLogEventsResult <- &putLogEventsResult{ - successResult: &cloudwatchlogs.PutLogEventsOutput{ - NextSequenceToken: aws.String(nextSequenceToken), - }, - } - ticks := make(chan time.Time) - newTicker = func(_ time.Duration) *time.Ticker { - return &time.Ticker{ - C: ticks, - } - } - - go stream.collectBatch() - - times := maximumLogEventsPerPut - expectedEvents := []*cloudwatchlogs.InputLogEvent{} - timestamp := time.Now() - for i := 0; i < times; i++ { - line := fmt.Sprintf("%d", i) - if i%2 == 0 { - timestamp.Add(1 * time.Nanosecond) - } - stream.Log(&logger.Message{ - Line: []byte(line), - Timestamp: timestamp, - }) - expectedEvents = append(expectedEvents, &cloudwatchlogs.InputLogEvent{ - Message: aws.String(line), - Timestamp: aws.Int64(timestamp.UnixNano() / int64(time.Millisecond)), - }) - } - - ticks <- time.Time{} - stream.Close() - - argument := <-mockClient.putLogEventsArgument - if argument == nil { - t.Fatal("Expected non-nil PutLogEventsInput") - } - if len(argument.LogEvents) != times { - t.Errorf("Expected LogEvents to contain %d elements, but contains %d", times, len(argument.LogEvents)) - } - for i := 0; i < times; i++ { - if !reflect.DeepEqual(*argument.LogEvents[i], *expectedEvents[i]) { - t.Errorf("Expected event to be %v but was %v", *expectedEvents[i], *argument.LogEvents[i]) - } - } -} - -func TestCreateTagSuccess(t *testing.T) { - mockClient := newMockClient() - ctx := logger.Context{ - ContainerName: "/test-container", - ContainerID: "container-abcdefghijklmnopqrstuvwxyz01234567890", - Config: map[string]string{"tag": "{{.Name}}/{{.FullID}}"}, - } - logStreamName, e := loggerutils.ParseLogTag(ctx, loggerutils.DefaultTemplate) - if e != nil { - t.Errorf("Error generating tag: %q", e) - } - stream := &logStream{ - client: mockClient, - logGroupName: groupName, - logStreamName: logStreamName, - } - mockClient.createLogStreamResult <- &createLogStreamResult{} - - err := stream.create() - - if err != nil { - t.Errorf("Received unexpected err: %v\n", err) - } - argument := <-mockClient.createLogStreamArgument - - if *argument.LogStreamName != "test-container/container-abcdefghijklmnopqrstuvwxyz01234567890" { - t.Errorf("Expected LogStreamName to be %s", "test-container/container-abcdefghijklmnopqrstuvwxyz01234567890") - } -} diff --git a/vendor/github.com/docker/docker/daemon/logger/awslogs/cwlogsiface_mock_test.go b/vendor/github.com/docker/docker/daemon/logger/awslogs/cwlogsiface_mock_test.go deleted file mode 100644 index b768a3d..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/awslogs/cwlogsiface_mock_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package awslogs - -import "github.com/aws/aws-sdk-go/service/cloudwatchlogs" - -type mockcwlogsclient struct { - createLogStreamArgument chan *cloudwatchlogs.CreateLogStreamInput - createLogStreamResult chan *createLogStreamResult - putLogEventsArgument chan *cloudwatchlogs.PutLogEventsInput - putLogEventsResult chan *putLogEventsResult -} - -type createLogStreamResult struct { - successResult *cloudwatchlogs.CreateLogStreamOutput - errorResult error -} - -type putLogEventsResult struct { - successResult *cloudwatchlogs.PutLogEventsOutput - errorResult error -} - -func newMockClient() *mockcwlogsclient { - return &mockcwlogsclient{ - createLogStreamArgument: make(chan *cloudwatchlogs.CreateLogStreamInput, 1), - createLogStreamResult: make(chan *createLogStreamResult, 1), - putLogEventsArgument: make(chan *cloudwatchlogs.PutLogEventsInput, 1), - putLogEventsResult: make(chan *putLogEventsResult, 1), - } -} - -func newMockClientBuffered(buflen int) *mockcwlogsclient { - return &mockcwlogsclient{ - createLogStreamArgument: make(chan *cloudwatchlogs.CreateLogStreamInput, buflen), - createLogStreamResult: make(chan *createLogStreamResult, buflen), - putLogEventsArgument: make(chan *cloudwatchlogs.PutLogEventsInput, buflen), - putLogEventsResult: make(chan *putLogEventsResult, buflen), - } -} - -func (m *mockcwlogsclient) CreateLogStream(input *cloudwatchlogs.CreateLogStreamInput) (*cloudwatchlogs.CreateLogStreamOutput, error) { - m.createLogStreamArgument <- input - output := <-m.createLogStreamResult - return output.successResult, output.errorResult -} - -func (m *mockcwlogsclient) PutLogEvents(input *cloudwatchlogs.PutLogEventsInput) (*cloudwatchlogs.PutLogEventsOutput, error) { - events := make([]*cloudwatchlogs.InputLogEvent, len(input.LogEvents)) - copy(events, input.LogEvents) - m.putLogEventsArgument <- &cloudwatchlogs.PutLogEventsInput{ - LogEvents: events, - SequenceToken: input.SequenceToken, - LogGroupName: input.LogGroupName, - LogStreamName: input.LogStreamName, - } - output := <-m.putLogEventsResult - return output.successResult, output.errorResult -} - -type mockmetadataclient struct { - regionResult chan *regionResult -} - -type regionResult struct { - successResult string - errorResult error -} - -func newMockMetadataClient() *mockmetadataclient { - return &mockmetadataclient{ - regionResult: make(chan *regionResult, 1), - } -} - -func (m *mockmetadataclient) Region() (string, error) { - output := <-m.regionResult - return output.successResult, output.errorResult -} diff --git a/vendor/github.com/docker/docker/daemon/logger/context.go b/vendor/github.com/docker/docker/daemon/logger/context.go deleted file mode 100644 index 085ab01..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/context.go +++ /dev/null @@ -1,111 +0,0 @@ -package logger - -import ( - "fmt" - "os" - "strings" - "time" -) - -// Context provides enough information for a logging driver to do its function. -type Context struct { - Config map[string]string - ContainerID string - ContainerName string - ContainerEntrypoint string - ContainerArgs []string - ContainerImageID string - ContainerImageName string - ContainerCreated time.Time - ContainerEnv []string - ContainerLabels map[string]string - LogPath string - DaemonName string -} - -// ExtraAttributes returns the user-defined extra attributes (labels, -// environment variables) in key-value format. This can be used by log drivers -// that support metadata to add more context to a log. -func (ctx *Context) ExtraAttributes(keyMod func(string) string) map[string]string { - extra := make(map[string]string) - labels, ok := ctx.Config["labels"] - if ok && len(labels) > 0 { - for _, l := range strings.Split(labels, ",") { - if v, ok := ctx.ContainerLabels[l]; ok { - if keyMod != nil { - l = keyMod(l) - } - extra[l] = v - } - } - } - - env, ok := ctx.Config["env"] - if ok && len(env) > 0 { - envMapping := make(map[string]string) - for _, e := range ctx.ContainerEnv { - if kv := strings.SplitN(e, "=", 2); len(kv) == 2 { - envMapping[kv[0]] = kv[1] - } - } - for _, l := range strings.Split(env, ",") { - if v, ok := envMapping[l]; ok { - if keyMod != nil { - l = keyMod(l) - } - extra[l] = v - } - } - } - - return extra -} - -// Hostname returns the hostname from the underlying OS. -func (ctx *Context) Hostname() (string, error) { - hostname, err := os.Hostname() - if err != nil { - return "", fmt.Errorf("logger: can not resolve hostname: %v", err) - } - return hostname, nil -} - -// Command returns the command that the container being logged was -// started with. The Entrypoint is prepended to the container -// arguments. -func (ctx *Context) Command() string { - terms := []string{ctx.ContainerEntrypoint} - terms = append(terms, ctx.ContainerArgs...) - command := strings.Join(terms, " ") - return command -} - -// ID Returns the Container ID shortened to 12 characters. -func (ctx *Context) ID() string { - return ctx.ContainerID[:12] -} - -// FullID is an alias of ContainerID. -func (ctx *Context) FullID() string { - return ctx.ContainerID -} - -// Name returns the ContainerName without a preceding '/'. -func (ctx *Context) Name() string { - return ctx.ContainerName[1:] -} - -// ImageID returns the ContainerImageID shortened to 12 characters. -func (ctx *Context) ImageID() string { - return ctx.ContainerImageID[:12] -} - -// ImageFullID is an alias of ContainerImageID. -func (ctx *Context) ImageFullID() string { - return ctx.ContainerImageID -} - -// ImageName is an alias of ContainerImageName -func (ctx *Context) ImageName() string { - return ctx.ContainerImageName -} diff --git a/vendor/github.com/docker/docker/daemon/logger/copier.go b/vendor/github.com/docker/docker/daemon/logger/copier.go deleted file mode 100644 index 10ab46e..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/copier.go +++ /dev/null @@ -1,131 +0,0 @@ -package logger - -import ( - "bytes" - "io" - "sync" - "time" - - "github.com/Sirupsen/logrus" -) - -const ( - bufSize = 16 * 1024 - readSize = 2 * 1024 -) - -// Copier can copy logs from specified sources to Logger and attach Timestamp. -// Writes are concurrent, so you need implement some sync in your logger. -type Copier struct { - // srcs is map of name -> reader pairs, for example "stdout", "stderr" - srcs map[string]io.Reader - dst Logger - copyJobs sync.WaitGroup - closeOnce sync.Once - closed chan struct{} -} - -// NewCopier creates a new Copier -func NewCopier(srcs map[string]io.Reader, dst Logger) *Copier { - return &Copier{ - srcs: srcs, - dst: dst, - closed: make(chan struct{}), - } -} - -// Run starts logs copying -func (c *Copier) Run() { - for src, w := range c.srcs { - c.copyJobs.Add(1) - go c.copySrc(src, w) - } -} - -func (c *Copier) copySrc(name string, src io.Reader) { - defer c.copyJobs.Done() - buf := make([]byte, bufSize) - n := 0 - eof := false - msg := &Message{Source: name} - - for { - select { - case <-c.closed: - return - default: - // Work out how much more data we are okay with reading this time. - upto := n + readSize - if upto > cap(buf) { - upto = cap(buf) - } - // Try to read that data. - if upto > n { - read, err := src.Read(buf[n:upto]) - if err != nil { - if err != io.EOF { - logrus.Errorf("Error scanning log stream: %s", err) - return - } - eof = true - } - n += read - } - // If we have no data to log, and there's no more coming, we're done. - if n == 0 && eof { - return - } - // Break up the data that we've buffered up into lines, and log each in turn. - p := 0 - for q := bytes.Index(buf[p:n], []byte{'\n'}); q >= 0; q = bytes.Index(buf[p:n], []byte{'\n'}) { - msg.Line = buf[p : p+q] - msg.Timestamp = time.Now().UTC() - msg.Partial = false - select { - case <-c.closed: - return - default: - if logErr := c.dst.Log(msg); logErr != nil { - logrus.Errorf("Failed to log msg %q for logger %s: %s", msg.Line, c.dst.Name(), logErr) - } - } - p += q + 1 - } - // If there's no more coming, or the buffer is full but - // has no newlines, log whatever we haven't logged yet, - // noting that it's a partial log line. - if eof || (p == 0 && n == len(buf)) { - if p < n { - msg.Line = buf[p:n] - msg.Timestamp = time.Now().UTC() - msg.Partial = true - if logErr := c.dst.Log(msg); logErr != nil { - logrus.Errorf("Failed to log msg %q for logger %s: %s", msg.Line, c.dst.Name(), logErr) - } - p = 0 - n = 0 - } - if eof { - return - } - } - // Move any unlogged data to the front of the buffer in preparation for another read. - if p > 0 { - copy(buf[0:], buf[p:n]) - n -= p - } - } - } -} - -// Wait waits until all copying is done -func (c *Copier) Wait() { - c.copyJobs.Wait() -} - -// Close closes the copier -func (c *Copier) Close() { - c.closeOnce.Do(func() { - close(c.closed) - }) -} diff --git a/vendor/github.com/docker/docker/daemon/logger/copier_test.go b/vendor/github.com/docker/docker/daemon/logger/copier_test.go deleted file mode 100644 index cfd816a..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/copier_test.go +++ /dev/null @@ -1,296 +0,0 @@ -package logger - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "os" - "strings" - "sync" - "testing" - "time" -) - -type TestLoggerJSON struct { - *json.Encoder - mu sync.Mutex - delay time.Duration -} - -func (l *TestLoggerJSON) Log(m *Message) error { - if l.delay > 0 { - time.Sleep(l.delay) - } - l.mu.Lock() - defer l.mu.Unlock() - return l.Encode(m) -} - -func (l *TestLoggerJSON) Close() error { return nil } - -func (l *TestLoggerJSON) Name() string { return "json" } - -func TestCopier(t *testing.T) { - stdoutLine := "Line that thinks that it is log line from docker stdout" - stderrLine := "Line that thinks that it is log line from docker stderr" - stdoutTrailingLine := "stdout trailing line" - stderrTrailingLine := "stderr trailing line" - - var stdout bytes.Buffer - var stderr bytes.Buffer - for i := 0; i < 30; i++ { - if _, err := stdout.WriteString(stdoutLine + "\n"); err != nil { - t.Fatal(err) - } - if _, err := stderr.WriteString(stderrLine + "\n"); err != nil { - t.Fatal(err) - } - } - - // Test remaining lines without line-endings - if _, err := stdout.WriteString(stdoutTrailingLine); err != nil { - t.Fatal(err) - } - if _, err := stderr.WriteString(stderrTrailingLine); err != nil { - t.Fatal(err) - } - - var jsonBuf bytes.Buffer - - jsonLog := &TestLoggerJSON{Encoder: json.NewEncoder(&jsonBuf)} - - c := NewCopier( - map[string]io.Reader{ - "stdout": &stdout, - "stderr": &stderr, - }, - jsonLog) - c.Run() - wait := make(chan struct{}) - go func() { - c.Wait() - close(wait) - }() - select { - case <-time.After(1 * time.Second): - t.Fatal("Copier failed to do its work in 1 second") - case <-wait: - } - dec := json.NewDecoder(&jsonBuf) - for { - var msg Message - if err := dec.Decode(&msg); err != nil { - if err == io.EOF { - break - } - t.Fatal(err) - } - if msg.Source != "stdout" && msg.Source != "stderr" { - t.Fatalf("Wrong Source: %q, should be %q or %q", msg.Source, "stdout", "stderr") - } - if msg.Source == "stdout" { - if string(msg.Line) != stdoutLine && string(msg.Line) != stdoutTrailingLine { - t.Fatalf("Wrong Line: %q, expected %q or %q", msg.Line, stdoutLine, stdoutTrailingLine) - } - } - if msg.Source == "stderr" { - if string(msg.Line) != stderrLine && string(msg.Line) != stderrTrailingLine { - t.Fatalf("Wrong Line: %q, expected %q or %q", msg.Line, stderrLine, stderrTrailingLine) - } - } - } -} - -// TestCopierLongLines tests long lines without line breaks -func TestCopierLongLines(t *testing.T) { - // Long lines (should be split at "bufSize") - const bufSize = 16 * 1024 - stdoutLongLine := strings.Repeat("a", bufSize) - stderrLongLine := strings.Repeat("b", bufSize) - stdoutTrailingLine := "stdout trailing line" - stderrTrailingLine := "stderr trailing line" - - var stdout bytes.Buffer - var stderr bytes.Buffer - - for i := 0; i < 3; i++ { - if _, err := stdout.WriteString(stdoutLongLine); err != nil { - t.Fatal(err) - } - if _, err := stderr.WriteString(stderrLongLine); err != nil { - t.Fatal(err) - } - } - - if _, err := stdout.WriteString(stdoutTrailingLine); err != nil { - t.Fatal(err) - } - if _, err := stderr.WriteString(stderrTrailingLine); err != nil { - t.Fatal(err) - } - - var jsonBuf bytes.Buffer - - jsonLog := &TestLoggerJSON{Encoder: json.NewEncoder(&jsonBuf)} - - c := NewCopier( - map[string]io.Reader{ - "stdout": &stdout, - "stderr": &stderr, - }, - jsonLog) - c.Run() - wait := make(chan struct{}) - go func() { - c.Wait() - close(wait) - }() - select { - case <-time.After(1 * time.Second): - t.Fatal("Copier failed to do its work in 1 second") - case <-wait: - } - dec := json.NewDecoder(&jsonBuf) - for { - var msg Message - if err := dec.Decode(&msg); err != nil { - if err == io.EOF { - break - } - t.Fatal(err) - } - if msg.Source != "stdout" && msg.Source != "stderr" { - t.Fatalf("Wrong Source: %q, should be %q or %q", msg.Source, "stdout", "stderr") - } - if msg.Source == "stdout" { - if string(msg.Line) != stdoutLongLine && string(msg.Line) != stdoutTrailingLine { - t.Fatalf("Wrong Line: %q, expected 'stdoutLongLine' or 'stdoutTrailingLine'", msg.Line) - } - } - if msg.Source == "stderr" { - if string(msg.Line) != stderrLongLine && string(msg.Line) != stderrTrailingLine { - t.Fatalf("Wrong Line: %q, expected 'stderrLongLine' or 'stderrTrailingLine'", msg.Line) - } - } - } -} - -func TestCopierSlow(t *testing.T) { - stdoutLine := "Line that thinks that it is log line from docker stdout" - var stdout bytes.Buffer - for i := 0; i < 30; i++ { - if _, err := stdout.WriteString(stdoutLine + "\n"); err != nil { - t.Fatal(err) - } - } - - var jsonBuf bytes.Buffer - //encoder := &encodeCloser{Encoder: json.NewEncoder(&jsonBuf)} - jsonLog := &TestLoggerJSON{Encoder: json.NewEncoder(&jsonBuf), delay: 100 * time.Millisecond} - - c := NewCopier(map[string]io.Reader{"stdout": &stdout}, jsonLog) - c.Run() - wait := make(chan struct{}) - go func() { - c.Wait() - close(wait) - }() - <-time.After(150 * time.Millisecond) - c.Close() - select { - case <-time.After(200 * time.Millisecond): - t.Fatalf("failed to exit in time after the copier is closed") - case <-wait: - } -} - -type BenchmarkLoggerDummy struct { -} - -func (l *BenchmarkLoggerDummy) Log(m *Message) error { return nil } - -func (l *BenchmarkLoggerDummy) Close() error { return nil } - -func (l *BenchmarkLoggerDummy) Name() string { return "dummy" } - -func BenchmarkCopier64(b *testing.B) { - benchmarkCopier(b, 1<<6) -} -func BenchmarkCopier128(b *testing.B) { - benchmarkCopier(b, 1<<7) -} -func BenchmarkCopier256(b *testing.B) { - benchmarkCopier(b, 1<<8) -} -func BenchmarkCopier512(b *testing.B) { - benchmarkCopier(b, 1<<9) -} -func BenchmarkCopier1K(b *testing.B) { - benchmarkCopier(b, 1<<10) -} -func BenchmarkCopier2K(b *testing.B) { - benchmarkCopier(b, 1<<11) -} -func BenchmarkCopier4K(b *testing.B) { - benchmarkCopier(b, 1<<12) -} -func BenchmarkCopier8K(b *testing.B) { - benchmarkCopier(b, 1<<13) -} -func BenchmarkCopier16K(b *testing.B) { - benchmarkCopier(b, 1<<14) -} -func BenchmarkCopier32K(b *testing.B) { - benchmarkCopier(b, 1<<15) -} -func BenchmarkCopier64K(b *testing.B) { - benchmarkCopier(b, 1<<16) -} -func BenchmarkCopier128K(b *testing.B) { - benchmarkCopier(b, 1<<17) -} -func BenchmarkCopier256K(b *testing.B) { - benchmarkCopier(b, 1<<18) -} - -func piped(b *testing.B, iterations int, delay time.Duration, buf []byte) io.Reader { - r, w, err := os.Pipe() - if err != nil { - b.Fatal(err) - return nil - } - go func() { - for i := 0; i < iterations; i++ { - time.Sleep(delay) - if n, err := w.Write(buf); err != nil || n != len(buf) { - if err != nil { - b.Fatal(err) - } - b.Fatal(fmt.Errorf("short write")) - } - } - w.Close() - }() - return r -} - -func benchmarkCopier(b *testing.B, length int) { - b.StopTimer() - buf := []byte{'A'} - for len(buf) < length { - buf = append(buf, buf...) - } - buf = append(buf[:length-1], []byte{'\n'}...) - b.StartTimer() - for i := 0; i < b.N; i++ { - c := NewCopier( - map[string]io.Reader{ - "buffer": piped(b, 10, time.Nanosecond, buf), - }, - &BenchmarkLoggerDummy{}) - c.Run() - c.Wait() - c.Close() - } -} diff --git a/vendor/github.com/docker/docker/daemon/logger/etwlogs/etwlogs_windows.go b/vendor/github.com/docker/docker/daemon/logger/etwlogs/etwlogs_windows.go deleted file mode 100644 index f296d7f..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/etwlogs/etwlogs_windows.go +++ /dev/null @@ -1,170 +0,0 @@ -// Package etwlogs provides a log driver for forwarding container logs -// as ETW events.(ETW stands for Event Tracing for Windows) -// A client can then create an ETW listener to listen for events that are sent -// by the ETW provider that we register, using the provider's GUID "a3693192-9ed6-46d2-a981-f8226c8363bd". -// Here is an example of how to do this using the logman utility: -// 1. logman start -ets DockerContainerLogs -p {a3693192-9ed6-46d2-a981-f8226c8363bd} 0 0 -o trace.etl -// 2. Run container(s) and generate log messages -// 3. logman stop -ets DockerContainerLogs -// 4. You can then convert the etl log file to XML using: tracerpt -y trace.etl -// -// Each container log message generates an ETW event that also contains: -// the container name and ID, the timestamp, and the stream type. -package etwlogs - -import ( - "errors" - "fmt" - "sync" - "syscall" - "unsafe" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/logger" - "golang.org/x/sys/windows" -) - -type etwLogs struct { - containerName string - imageName string - containerID string - imageID string -} - -const ( - name = "etwlogs" - win32CallSuccess = 0 -) - -var ( - modAdvapi32 = windows.NewLazySystemDLL("Advapi32.dll") - procEventRegister = modAdvapi32.NewProc("EventRegister") - procEventWriteString = modAdvapi32.NewProc("EventWriteString") - procEventUnregister = modAdvapi32.NewProc("EventUnregister") -) -var providerHandle syscall.Handle -var refCount int -var mu sync.Mutex - -func init() { - providerHandle = syscall.InvalidHandle - if err := logger.RegisterLogDriver(name, New); err != nil { - logrus.Fatal(err) - } -} - -// New creates a new etwLogs logger for the given container and registers the EWT provider. -func New(ctx logger.Context) (logger.Logger, error) { - if err := registerETWProvider(); err != nil { - return nil, err - } - logrus.Debugf("logging driver etwLogs configured for container: %s.", ctx.ContainerID) - - return &etwLogs{ - containerName: fixContainerName(ctx.ContainerName), - imageName: ctx.ContainerImageName, - containerID: ctx.ContainerID, - imageID: ctx.ContainerImageID, - }, nil -} - -// Log logs the message to the ETW stream. -func (etwLogger *etwLogs) Log(msg *logger.Message) error { - if providerHandle == syscall.InvalidHandle { - // This should never be hit, if it is, it indicates a programming error. - errorMessage := "ETWLogs cannot log the message, because the event provider has not been registered." - logrus.Error(errorMessage) - return errors.New(errorMessage) - } - return callEventWriteString(createLogMessage(etwLogger, msg)) -} - -// Close closes the logger by unregistering the ETW provider. -func (etwLogger *etwLogs) Close() error { - unregisterETWProvider() - return nil -} - -func (etwLogger *etwLogs) Name() string { - return name -} - -func createLogMessage(etwLogger *etwLogs, msg *logger.Message) string { - return fmt.Sprintf("container_name: %s, image_name: %s, container_id: %s, image_id: %s, source: %s, log: %s", - etwLogger.containerName, - etwLogger.imageName, - etwLogger.containerID, - etwLogger.imageID, - msg.Source, - msg.Line) -} - -// fixContainerName removes the initial '/' from the container name. -func fixContainerName(cntName string) string { - if len(cntName) > 0 && cntName[0] == '/' { - cntName = cntName[1:] - } - return cntName -} - -func registerETWProvider() error { - mu.Lock() - defer mu.Unlock() - if refCount == 0 { - var err error - if err = callEventRegister(); err != nil { - return err - } - } - - refCount++ - return nil -} - -func unregisterETWProvider() { - mu.Lock() - defer mu.Unlock() - if refCount == 1 { - if callEventUnregister() { - refCount-- - providerHandle = syscall.InvalidHandle - } - // Not returning an error if EventUnregister fails, because etwLogs will continue to work - } else { - refCount-- - } -} - -func callEventRegister() error { - // The provider's GUID is {a3693192-9ed6-46d2-a981-f8226c8363bd} - guid := syscall.GUID{ - 0xa3693192, 0x9ed6, 0x46d2, - [8]byte{0xa9, 0x81, 0xf8, 0x22, 0x6c, 0x83, 0x63, 0xbd}, - } - - ret, _, _ := procEventRegister.Call(uintptr(unsafe.Pointer(&guid)), 0, 0, uintptr(unsafe.Pointer(&providerHandle))) - if ret != win32CallSuccess { - errorMessage := fmt.Sprintf("Failed to register ETW provider. Error: %d", ret) - logrus.Error(errorMessage) - return errors.New(errorMessage) - } - return nil -} - -func callEventWriteString(message string) error { - ret, _, _ := procEventWriteString.Call(uintptr(providerHandle), 0, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(message)))) - if ret != win32CallSuccess { - errorMessage := fmt.Sprintf("ETWLogs provider failed to log message. Error: %d", ret) - logrus.Error(errorMessage) - return errors.New(errorMessage) - } - return nil -} - -func callEventUnregister() bool { - ret, _, _ := procEventUnregister.Call(uintptr(providerHandle)) - if ret != win32CallSuccess { - return false - } - return true -} diff --git a/vendor/github.com/docker/docker/daemon/logger/factory.go b/vendor/github.com/docker/docker/daemon/logger/factory.go deleted file mode 100644 index 9cf716b..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/factory.go +++ /dev/null @@ -1,104 +0,0 @@ -package logger - -import ( - "fmt" - "sync" -) - -// Creator builds a logging driver instance with given context. -type Creator func(Context) (Logger, error) - -// LogOptValidator checks the options specific to the underlying -// logging implementation. -type LogOptValidator func(cfg map[string]string) error - -type logdriverFactory struct { - registry map[string]Creator - optValidator map[string]LogOptValidator - m sync.Mutex -} - -func (lf *logdriverFactory) register(name string, c Creator) error { - if lf.driverRegistered(name) { - return fmt.Errorf("logger: log driver named '%s' is already registered", name) - } - - lf.m.Lock() - lf.registry[name] = c - lf.m.Unlock() - return nil -} - -func (lf *logdriverFactory) driverRegistered(name string) bool { - lf.m.Lock() - _, ok := lf.registry[name] - lf.m.Unlock() - return ok -} - -func (lf *logdriverFactory) registerLogOptValidator(name string, l LogOptValidator) error { - lf.m.Lock() - defer lf.m.Unlock() - - if _, ok := lf.optValidator[name]; ok { - return fmt.Errorf("logger: log validator named '%s' is already registered", name) - } - lf.optValidator[name] = l - return nil -} - -func (lf *logdriverFactory) get(name string) (Creator, error) { - lf.m.Lock() - defer lf.m.Unlock() - - c, ok := lf.registry[name] - if !ok { - return c, fmt.Errorf("logger: no log driver named '%s' is registered", name) - } - return c, nil -} - -func (lf *logdriverFactory) getLogOptValidator(name string) LogOptValidator { - lf.m.Lock() - defer lf.m.Unlock() - - c, _ := lf.optValidator[name] - return c -} - -var factory = &logdriverFactory{registry: make(map[string]Creator), optValidator: make(map[string]LogOptValidator)} // global factory instance - -// RegisterLogDriver registers the given logging driver builder with given logging -// driver name. -func RegisterLogDriver(name string, c Creator) error { - return factory.register(name, c) -} - -// RegisterLogOptValidator registers the logging option validator with -// the given logging driver name. -func RegisterLogOptValidator(name string, l LogOptValidator) error { - return factory.registerLogOptValidator(name, l) -} - -// GetLogDriver provides the logging driver builder for a logging driver name. -func GetLogDriver(name string) (Creator, error) { - return factory.get(name) -} - -// ValidateLogOpts checks the options for the given log driver. The -// options supported are specific to the LogDriver implementation. -func ValidateLogOpts(name string, cfg map[string]string) error { - if name == "none" { - return nil - } - - if !factory.driverRegistered(name) { - return fmt.Errorf("logger: no log driver named '%s' is registered", name) - } - - validator := factory.getLogOptValidator(name) - if validator != nil { - return validator(cfg) - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/logger/fluentd/fluentd.go b/vendor/github.com/docker/docker/daemon/logger/fluentd/fluentd.go deleted file mode 100644 index a8303cf..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/fluentd/fluentd.go +++ /dev/null @@ -1,246 +0,0 @@ -// Package fluentd provides the log driver for forwarding server logs -// to fluentd endpoints. -package fluentd - -import ( - "fmt" - "math" - "net" - "net/url" - "strconv" - "strings" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/daemon/logger/loggerutils" - "github.com/docker/docker/pkg/urlutil" - "github.com/docker/go-units" - "github.com/fluent/fluent-logger-golang/fluent" - "github.com/pkg/errors" -) - -type fluentd struct { - tag string - containerID string - containerName string - writer *fluent.Fluent - extra map[string]string -} - -type location struct { - protocol string - host string - port int - path string -} - -const ( - name = "fluentd" - - defaultProtocol = "tcp" - defaultHost = "127.0.0.1" - defaultPort = 24224 - defaultBufferLimit = 1024 * 1024 - - // logger tries to reconnect 2**32 - 1 times - // failed (and panic) after 204 years [ 1.5 ** (2**32 - 1) - 1 seconds] - defaultRetryWait = 1000 - defaultMaxRetries = math.MaxInt32 - - addressKey = "fluentd-address" - bufferLimitKey = "fluentd-buffer-limit" - retryWaitKey = "fluentd-retry-wait" - maxRetriesKey = "fluentd-max-retries" - asyncConnectKey = "fluentd-async-connect" -) - -func init() { - if err := logger.RegisterLogDriver(name, New); err != nil { - logrus.Fatal(err) - } - if err := logger.RegisterLogOptValidator(name, ValidateLogOpt); err != nil { - logrus.Fatal(err) - } -} - -// New creates a fluentd logger using the configuration passed in on -// the context. The supported context configuration variable is -// fluentd-address. -func New(ctx logger.Context) (logger.Logger, error) { - loc, err := parseAddress(ctx.Config[addressKey]) - if err != nil { - return nil, err - } - - tag, err := loggerutils.ParseLogTag(ctx, loggerutils.DefaultTemplate) - if err != nil { - return nil, err - } - - extra := ctx.ExtraAttributes(nil) - - bufferLimit := defaultBufferLimit - if ctx.Config[bufferLimitKey] != "" { - bl64, err := units.RAMInBytes(ctx.Config[bufferLimitKey]) - if err != nil { - return nil, err - } - bufferLimit = int(bl64) - } - - retryWait := defaultRetryWait - if ctx.Config[retryWaitKey] != "" { - rwd, err := time.ParseDuration(ctx.Config[retryWaitKey]) - if err != nil { - return nil, err - } - retryWait = int(rwd.Seconds() * 1000) - } - - maxRetries := defaultMaxRetries - if ctx.Config[maxRetriesKey] != "" { - mr64, err := strconv.ParseUint(ctx.Config[maxRetriesKey], 10, strconv.IntSize) - if err != nil { - return nil, err - } - maxRetries = int(mr64) - } - - asyncConnect := false - if ctx.Config[asyncConnectKey] != "" { - if asyncConnect, err = strconv.ParseBool(ctx.Config[asyncConnectKey]); err != nil { - return nil, err - } - } - - fluentConfig := fluent.Config{ - FluentPort: loc.port, - FluentHost: loc.host, - FluentNetwork: loc.protocol, - FluentSocketPath: loc.path, - BufferLimit: bufferLimit, - RetryWait: retryWait, - MaxRetry: maxRetries, - AsyncConnect: asyncConnect, - } - - logrus.WithField("container", ctx.ContainerID).WithField("config", fluentConfig). - Debug("logging driver fluentd configured") - - log, err := fluent.New(fluentConfig) - if err != nil { - return nil, err - } - return &fluentd{ - tag: tag, - containerID: ctx.ContainerID, - containerName: ctx.ContainerName, - writer: log, - extra: extra, - }, nil -} - -func (f *fluentd) Log(msg *logger.Message) error { - data := map[string]string{ - "container_id": f.containerID, - "container_name": f.containerName, - "source": msg.Source, - "log": string(msg.Line), - } - for k, v := range f.extra { - data[k] = v - } - // fluent-logger-golang buffers logs from failures and disconnections, - // and these are transferred again automatically. - return f.writer.PostWithTime(f.tag, msg.Timestamp, data) -} - -func (f *fluentd) Close() error { - return f.writer.Close() -} - -func (f *fluentd) Name() string { - return name -} - -// ValidateLogOpt looks for fluentd specific log option fluentd-address. -func ValidateLogOpt(cfg map[string]string) error { - for key := range cfg { - switch key { - case "env": - case "labels": - case "tag": - case addressKey: - case bufferLimitKey: - case retryWaitKey: - case maxRetriesKey: - case asyncConnectKey: - // Accepted - default: - return fmt.Errorf("unknown log opt '%s' for fluentd log driver", key) - } - } - - if _, err := parseAddress(cfg["fluentd-address"]); err != nil { - return err - } - - return nil -} - -func parseAddress(address string) (*location, error) { - if address == "" { - return &location{ - protocol: defaultProtocol, - host: defaultHost, - port: defaultPort, - path: "", - }, nil - } - - protocol := defaultProtocol - givenAddress := address - if urlutil.IsTransportURL(address) { - url, err := url.Parse(address) - if err != nil { - return nil, errors.Wrapf(err, "invalid fluentd-address %s", givenAddress) - } - // unix and unixgram socket - if url.Scheme == "unix" || url.Scheme == "unixgram" { - return &location{ - protocol: url.Scheme, - host: "", - port: 0, - path: url.Path, - }, nil - } - // tcp|udp - protocol = url.Scheme - address = url.Host - } - - host, port, err := net.SplitHostPort(address) - if err != nil { - if !strings.Contains(err.Error(), "missing port in address") { - return nil, errors.Wrapf(err, "invalid fluentd-address %s", givenAddress) - } - return &location{ - protocol: protocol, - host: host, - port: defaultPort, - path: "", - }, nil - } - - portnum, err := strconv.Atoi(port) - if err != nil { - return nil, errors.Wrapf(err, "invalid fluentd-address %s", givenAddress) - } - return &location{ - protocol: protocol, - host: host, - port: portnum, - path: "", - }, nil -} diff --git a/vendor/github.com/docker/docker/daemon/logger/gcplogs/gcplogging.go b/vendor/github.com/docker/docker/daemon/logger/gcplogs/gcplogging.go deleted file mode 100644 index 9a8c1c9..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/gcplogs/gcplogging.go +++ /dev/null @@ -1,200 +0,0 @@ -package gcplogs - -import ( - "fmt" - "sync" - "sync/atomic" - "time" - - "github.com/docker/docker/daemon/logger" - - "github.com/Sirupsen/logrus" - "golang.org/x/net/context" - "google.golang.org/cloud/compute/metadata" - "google.golang.org/cloud/logging" -) - -const ( - name = "gcplogs" - - projectOptKey = "gcp-project" - logLabelsKey = "labels" - logEnvKey = "env" - logCmdKey = "gcp-log-cmd" - logZoneKey = "gcp-meta-zone" - logNameKey = "gcp-meta-name" - logIDKey = "gcp-meta-id" -) - -var ( - // The number of logs the gcplogs driver has dropped. - droppedLogs uint64 - - onGCE bool - - // instance metadata populated from the metadata server if available - projectID string - zone string - instanceName string - instanceID string -) - -func init() { - - if err := logger.RegisterLogDriver(name, New); err != nil { - logrus.Fatal(err) - } - - if err := logger.RegisterLogOptValidator(name, ValidateLogOpts); err != nil { - logrus.Fatal(err) - } -} - -type gcplogs struct { - client *logging.Client - instance *instanceInfo - container *containerInfo -} - -type dockerLogEntry struct { - Instance *instanceInfo `json:"instance,omitempty"` - Container *containerInfo `json:"container,omitempty"` - Data string `json:"data,omitempty"` -} - -type instanceInfo struct { - Zone string `json:"zone,omitempty"` - Name string `json:"name,omitempty"` - ID string `json:"id,omitempty"` -} - -type containerInfo struct { - Name string `json:"name,omitempty"` - ID string `json:"id,omitempty"` - ImageName string `json:"imageName,omitempty"` - ImageID string `json:"imageId,omitempty"` - Created time.Time `json:"created,omitempty"` - Command string `json:"command,omitempty"` - Metadata map[string]string `json:"metadata,omitempty"` -} - -var initGCPOnce sync.Once - -func initGCP() { - initGCPOnce.Do(func() { - onGCE = metadata.OnGCE() - if onGCE { - // These will fail on instances if the metadata service is - // down or the client is compiled with an API version that - // has been removed. Since these are not vital, let's ignore - // them and make their fields in the dockeLogEntry ,omitempty - projectID, _ = metadata.ProjectID() - zone, _ = metadata.Zone() - instanceName, _ = metadata.InstanceName() - instanceID, _ = metadata.InstanceID() - } - }) -} - -// New creates a new logger that logs to Google Cloud Logging using the application -// default credentials. -// -// See https://developers.google.com/identity/protocols/application-default-credentials -func New(ctx logger.Context) (logger.Logger, error) { - initGCP() - - var project string - if projectID != "" { - project = projectID - } - if projectID, found := ctx.Config[projectOptKey]; found { - project = projectID - } - if project == "" { - return nil, fmt.Errorf("No project was specified and couldn't read project from the meatadata server. Please specify a project") - } - - c, err := logging.NewClient(context.Background(), project, "gcplogs-docker-driver") - if err != nil { - return nil, err - } - - if err := c.Ping(); err != nil { - return nil, fmt.Errorf("unable to connect or authenticate with Google Cloud Logging: %v", err) - } - - l := &gcplogs{ - client: c, - container: &containerInfo{ - Name: ctx.ContainerName, - ID: ctx.ContainerID, - ImageName: ctx.ContainerImageName, - ImageID: ctx.ContainerImageID, - Created: ctx.ContainerCreated, - Metadata: ctx.ExtraAttributes(nil), - }, - } - - if ctx.Config[logCmdKey] == "true" { - l.container.Command = ctx.Command() - } - - if onGCE { - l.instance = &instanceInfo{ - Zone: zone, - Name: instanceName, - ID: instanceID, - } - } else if ctx.Config[logZoneKey] != "" || ctx.Config[logNameKey] != "" || ctx.Config[logIDKey] != "" { - l.instance = &instanceInfo{ - Zone: ctx.Config[logZoneKey], - Name: ctx.Config[logNameKey], - ID: ctx.Config[logIDKey], - } - } - - // The logger "overflows" at a rate of 10,000 logs per second and this - // overflow func is called. We want to surface the error to the user - // without overly spamming /var/log/docker.log so we log the first time - // we overflow and every 1000th time after. - c.Overflow = func(_ *logging.Client, _ logging.Entry) error { - if i := atomic.AddUint64(&droppedLogs, 1); i%1000 == 1 { - logrus.Errorf("gcplogs driver has dropped %v logs", i) - } - return nil - } - - return l, nil -} - -// ValidateLogOpts validates the opts passed to the gcplogs driver. Currently, the gcplogs -// driver doesn't take any arguments. -func ValidateLogOpts(cfg map[string]string) error { - for k := range cfg { - switch k { - case projectOptKey, logLabelsKey, logEnvKey, logCmdKey, logZoneKey, logNameKey, logIDKey: - default: - return fmt.Errorf("%q is not a valid option for the gcplogs driver", k) - } - } - return nil -} - -func (l *gcplogs) Log(m *logger.Message) error { - return l.client.Log(logging.Entry{ - Time: m.Timestamp, - Payload: &dockerLogEntry{ - Instance: l.instance, - Container: l.container, - Data: string(m.Line), - }, - }) -} - -func (l *gcplogs) Close() error { - return l.client.Flush() -} - -func (l *gcplogs) Name() string { - return name -} diff --git a/vendor/github.com/docker/docker/daemon/logger/gelf/gelf.go b/vendor/github.com/docker/docker/daemon/logger/gelf/gelf.go deleted file mode 100644 index 95860ac..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/gelf/gelf.go +++ /dev/null @@ -1,209 +0,0 @@ -// +build linux - -// Package gelf provides the log driver for forwarding server logs to -// endpoints that support the Graylog Extended Log Format. -package gelf - -import ( - "bytes" - "compress/flate" - "encoding/json" - "fmt" - "net" - "net/url" - "strconv" - "time" - - "github.com/Graylog2/go-gelf/gelf" - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/daemon/logger/loggerutils" - "github.com/docker/docker/pkg/urlutil" -) - -const name = "gelf" - -type gelfLogger struct { - writer *gelf.Writer - ctx logger.Context - hostname string - rawExtra json.RawMessage -} - -func init() { - if err := logger.RegisterLogDriver(name, New); err != nil { - logrus.Fatal(err) - } - if err := logger.RegisterLogOptValidator(name, ValidateLogOpt); err != nil { - logrus.Fatal(err) - } -} - -// New creates a gelf logger using the configuration passed in on the -// context. The supported context configuration variable is gelf-address. -func New(ctx logger.Context) (logger.Logger, error) { - // parse gelf address - address, err := parseAddress(ctx.Config["gelf-address"]) - if err != nil { - return nil, err - } - - // collect extra data for GELF message - hostname, err := ctx.Hostname() - if err != nil { - return nil, fmt.Errorf("gelf: cannot access hostname to set source field") - } - - // remove trailing slash from container name - containerName := bytes.TrimLeft([]byte(ctx.ContainerName), "/") - - // parse log tag - tag, err := loggerutils.ParseLogTag(ctx, loggerutils.DefaultTemplate) - if err != nil { - return nil, err - } - - extra := map[string]interface{}{ - "_container_id": ctx.ContainerID, - "_container_name": string(containerName), - "_image_id": ctx.ContainerImageID, - "_image_name": ctx.ContainerImageName, - "_command": ctx.Command(), - "_tag": tag, - "_created": ctx.ContainerCreated, - } - - extraAttrs := ctx.ExtraAttributes(func(key string) string { - if key[0] == '_' { - return key - } - return "_" + key - }) - for k, v := range extraAttrs { - extra[k] = v - } - - rawExtra, err := json.Marshal(extra) - if err != nil { - return nil, err - } - - // create new gelfWriter - gelfWriter, err := gelf.NewWriter(address) - if err != nil { - return nil, fmt.Errorf("gelf: cannot connect to GELF endpoint: %s %v", address, err) - } - - if v, ok := ctx.Config["gelf-compression-type"]; ok { - switch v { - case "gzip": - gelfWriter.CompressionType = gelf.CompressGzip - case "zlib": - gelfWriter.CompressionType = gelf.CompressZlib - case "none": - gelfWriter.CompressionType = gelf.CompressNone - default: - return nil, fmt.Errorf("gelf: invalid compression type %q", v) - } - } - - if v, ok := ctx.Config["gelf-compression-level"]; ok { - val, err := strconv.Atoi(v) - if err != nil { - return nil, fmt.Errorf("gelf: invalid compression level %s, err %v", v, err) - } - gelfWriter.CompressionLevel = val - } - - return &gelfLogger{ - writer: gelfWriter, - ctx: ctx, - hostname: hostname, - rawExtra: rawExtra, - }, nil -} - -func (s *gelfLogger) Log(msg *logger.Message) error { - level := gelf.LOG_INFO - if msg.Source == "stderr" { - level = gelf.LOG_ERR - } - - m := gelf.Message{ - Version: "1.1", - Host: s.hostname, - Short: string(msg.Line), - TimeUnix: float64(msg.Timestamp.UnixNano()/int64(time.Millisecond)) / 1000.0, - Level: level, - RawExtra: s.rawExtra, - } - - if err := s.writer.WriteMessage(&m); err != nil { - return fmt.Errorf("gelf: cannot send GELF message: %v", err) - } - return nil -} - -func (s *gelfLogger) Close() error { - return s.writer.Close() -} - -func (s *gelfLogger) Name() string { - return name -} - -// ValidateLogOpt looks for gelf specific log option gelf-address. -func ValidateLogOpt(cfg map[string]string) error { - for key, val := range cfg { - switch key { - case "gelf-address": - case "tag": - case "labels": - case "env": - case "gelf-compression-level": - i, err := strconv.Atoi(val) - if err != nil || i < flate.DefaultCompression || i > flate.BestCompression { - return fmt.Errorf("unknown value %q for log opt %q for gelf log driver", val, key) - } - case "gelf-compression-type": - switch val { - case "gzip", "zlib", "none": - default: - return fmt.Errorf("unknown value %q for log opt %q for gelf log driver", val, key) - } - default: - return fmt.Errorf("unknown log opt %q for gelf log driver", key) - } - } - - if _, err := parseAddress(cfg["gelf-address"]); err != nil { - return err - } - - return nil -} - -func parseAddress(address string) (string, error) { - if address == "" { - return "", nil - } - if !urlutil.IsTransportURL(address) { - return "", fmt.Errorf("gelf-address should be in form proto://address, got %v", address) - } - url, err := url.Parse(address) - if err != nil { - return "", err - } - - // we support only udp - if url.Scheme != "udp" { - return "", fmt.Errorf("gelf: endpoint needs to be UDP") - } - - // get host and port - if _, _, err = net.SplitHostPort(url.Host); err != nil { - return "", fmt.Errorf("gelf: please provide gelf-address as udp://host:port") - } - - return url.Host, nil -} diff --git a/vendor/github.com/docker/docker/daemon/logger/gelf/gelf_unsupported.go b/vendor/github.com/docker/docker/daemon/logger/gelf/gelf_unsupported.go deleted file mode 100644 index 266f73b..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/gelf/gelf_unsupported.go +++ /dev/null @@ -1,3 +0,0 @@ -// +build !linux - -package gelf diff --git a/vendor/github.com/docker/docker/daemon/logger/journald/journald.go b/vendor/github.com/docker/docker/daemon/logger/journald/journald.go deleted file mode 100644 index 9569859..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/journald/journald.go +++ /dev/null @@ -1,122 +0,0 @@ -// +build linux - -// Package journald provides the log driver for forwarding server logs -// to endpoints that receive the systemd format. -package journald - -import ( - "fmt" - "sync" - "unicode" - - "github.com/Sirupsen/logrus" - "github.com/coreos/go-systemd/journal" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/daemon/logger/loggerutils" -) - -const name = "journald" - -type journald struct { - vars map[string]string // additional variables and values to send to the journal along with the log message - readers readerList -} - -type readerList struct { - mu sync.Mutex - readers map[*logger.LogWatcher]*logger.LogWatcher -} - -func init() { - if err := logger.RegisterLogDriver(name, New); err != nil { - logrus.Fatal(err) - } - if err := logger.RegisterLogOptValidator(name, validateLogOpt); err != nil { - logrus.Fatal(err) - } -} - -// sanitizeKeyMode returns the sanitized string so that it could be used in journald. -// In journald log, there are special requirements for fields. -// Fields must be composed of uppercase letters, numbers, and underscores, but must -// not start with an underscore. -func sanitizeKeyMod(s string) string { - n := "" - for _, v := range s { - if 'a' <= v && v <= 'z' { - v = unicode.ToUpper(v) - } else if ('Z' < v || v < 'A') && ('9' < v || v < '0') { - v = '_' - } - // If (n == "" && v == '_'), then we will skip as this is the beginning with '_' - if !(n == "" && v == '_') { - n += string(v) - } - } - return n -} - -// New creates a journald logger using the configuration passed in on -// the context. -func New(ctx logger.Context) (logger.Logger, error) { - if !journal.Enabled() { - return nil, fmt.Errorf("journald is not enabled on this host") - } - // Strip a leading slash so that people can search for - // CONTAINER_NAME=foo rather than CONTAINER_NAME=/foo. - name := ctx.ContainerName - if name[0] == '/' { - name = name[1:] - } - - // parse log tag - tag, err := loggerutils.ParseLogTag(ctx, loggerutils.DefaultTemplate) - if err != nil { - return nil, err - } - - vars := map[string]string{ - "CONTAINER_ID": ctx.ContainerID[:12], - "CONTAINER_ID_FULL": ctx.ContainerID, - "CONTAINER_NAME": name, - "CONTAINER_TAG": tag, - } - extraAttrs := ctx.ExtraAttributes(sanitizeKeyMod) - for k, v := range extraAttrs { - vars[k] = v - } - return &journald{vars: vars, readers: readerList{readers: make(map[*logger.LogWatcher]*logger.LogWatcher)}}, nil -} - -// We don't actually accept any options, but we have to supply a callback for -// the factory to pass the (probably empty) configuration map to. -func validateLogOpt(cfg map[string]string) error { - for key := range cfg { - switch key { - case "labels": - case "env": - case "tag": - default: - return fmt.Errorf("unknown log opt '%s' for journald log driver", key) - } - } - return nil -} - -func (s *journald) Log(msg *logger.Message) error { - vars := map[string]string{} - for k, v := range s.vars { - vars[k] = v - } - if msg.Partial { - vars["CONTAINER_PARTIAL_MESSAGE"] = "true" - } - if msg.Source == "stderr" { - return journal.Send(string(msg.Line), journal.PriErr, vars) - } - return journal.Send(string(msg.Line), journal.PriInfo, vars) -} - -func (s *journald) Name() string { - return name -} diff --git a/vendor/github.com/docker/docker/daemon/logger/journald/journald_test.go b/vendor/github.com/docker/docker/daemon/logger/journald/journald_test.go deleted file mode 100644 index 224423f..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/journald/journald_test.go +++ /dev/null @@ -1,23 +0,0 @@ -// +build linux - -package journald - -import ( - "testing" -) - -func TestSanitizeKeyMod(t *testing.T) { - entries := map[string]string{ - "io.kubernetes.pod.name": "IO_KUBERNETES_POD_NAME", - "io?.kubernetes.pod.name": "IO__KUBERNETES_POD_NAME", - "?io.kubernetes.pod.name": "IO_KUBERNETES_POD_NAME", - "io123.kubernetes.pod.name": "IO123_KUBERNETES_POD_NAME", - "_io123.kubernetes.pod.name": "IO123_KUBERNETES_POD_NAME", - "__io123_kubernetes.pod.name": "IO123_KUBERNETES_POD_NAME", - } - for k, v := range entries { - if sanitizeKeyMod(k) != v { - t.Fatalf("Failed to sanitize %s, got %s, expected %s", k, sanitizeKeyMod(k), v) - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/logger/journald/journald_unsupported.go b/vendor/github.com/docker/docker/daemon/logger/journald/journald_unsupported.go deleted file mode 100644 index d52ca92..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/journald/journald_unsupported.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build !linux - -package journald - -type journald struct { -} diff --git a/vendor/github.com/docker/docker/daemon/logger/journald/read.go b/vendor/github.com/docker/docker/daemon/logger/journald/read.go deleted file mode 100644 index d91eb80..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/journald/read.go +++ /dev/null @@ -1,401 +0,0 @@ -// +build linux,cgo,!static_build,journald - -package journald - -// #include -// #include -// #include -// #include -// #include -// #include -// #include -// #include -// #include -// -//static int get_message(sd_journal *j, const char **msg, size_t *length, int *partial) -//{ -// int rc; -// size_t plength; -// *msg = NULL; -// *length = 0; -// plength = strlen("CONTAINER_PARTIAL_MESSAGE=true"); -// rc = sd_journal_get_data(j, "CONTAINER_PARTIAL_MESSAGE", (const void **) msg, length); -// *partial = ((rc == 0) && (*length == plength) && (memcmp(*msg, "CONTAINER_PARTIAL_MESSAGE=true", plength) == 0)); -// rc = sd_journal_get_data(j, "MESSAGE", (const void **) msg, length); -// if (rc == 0) { -// if (*length > 8) { -// (*msg) += 8; -// *length -= 8; -// } else { -// *msg = NULL; -// *length = 0; -// rc = -ENOENT; -// } -// } -// return rc; -//} -//static int get_priority(sd_journal *j, int *priority) -//{ -// const void *data; -// size_t i, length; -// int rc; -// *priority = -1; -// rc = sd_journal_get_data(j, "PRIORITY", &data, &length); -// if (rc == 0) { -// if ((length > 9) && (strncmp(data, "PRIORITY=", 9) == 0)) { -// *priority = 0; -// for (i = 9; i < length; i++) { -// *priority = *priority * 10 + ((const char *)data)[i] - '0'; -// } -// if (length > 9) { -// rc = 0; -// } -// } -// } -// return rc; -//} -//static int is_attribute_field(const char *msg, size_t length) -//{ -// static const struct known_field { -// const char *name; -// size_t length; -// } fields[] = { -// {"MESSAGE", sizeof("MESSAGE") - 1}, -// {"MESSAGE_ID", sizeof("MESSAGE_ID") - 1}, -// {"PRIORITY", sizeof("PRIORITY") - 1}, -// {"CODE_FILE", sizeof("CODE_FILE") - 1}, -// {"CODE_LINE", sizeof("CODE_LINE") - 1}, -// {"CODE_FUNC", sizeof("CODE_FUNC") - 1}, -// {"ERRNO", sizeof("ERRNO") - 1}, -// {"SYSLOG_FACILITY", sizeof("SYSLOG_FACILITY") - 1}, -// {"SYSLOG_IDENTIFIER", sizeof("SYSLOG_IDENTIFIER") - 1}, -// {"SYSLOG_PID", sizeof("SYSLOG_PID") - 1}, -// {"CONTAINER_NAME", sizeof("CONTAINER_NAME") - 1}, -// {"CONTAINER_ID", sizeof("CONTAINER_ID") - 1}, -// {"CONTAINER_ID_FULL", sizeof("CONTAINER_ID_FULL") - 1}, -// {"CONTAINER_TAG", sizeof("CONTAINER_TAG") - 1}, -// }; -// unsigned int i; -// void *p; -// if ((length < 1) || (msg[0] == '_') || ((p = memchr(msg, '=', length)) == NULL)) { -// return -1; -// } -// length = ((const char *) p) - msg; -// for (i = 0; i < sizeof(fields) / sizeof(fields[0]); i++) { -// if ((fields[i].length == length) && (memcmp(fields[i].name, msg, length) == 0)) { -// return -1; -// } -// } -// return 0; -//} -//static int get_attribute_field(sd_journal *j, const char **msg, size_t *length) -//{ -// int rc; -// *msg = NULL; -// *length = 0; -// while ((rc = sd_journal_enumerate_data(j, (const void **) msg, length)) > 0) { -// if (is_attribute_field(*msg, *length) == 0) { -// break; -// } -// rc = -ENOENT; -// } -// return rc; -//} -//static int wait_for_data_cancelable(sd_journal *j, int pipefd) -//{ -// struct pollfd fds[2]; -// uint64_t when = 0; -// int timeout, jevents, i; -// struct timespec ts; -// uint64_t now; -// -// memset(&fds, 0, sizeof(fds)); -// fds[0].fd = pipefd; -// fds[0].events = POLLHUP; -// fds[1].fd = sd_journal_get_fd(j); -// if (fds[1].fd < 0) { -// return fds[1].fd; -// } -// -// do { -// jevents = sd_journal_get_events(j); -// if (jevents < 0) { -// return jevents; -// } -// fds[1].events = jevents; -// sd_journal_get_timeout(j, &when); -// if (when == -1) { -// timeout = -1; -// } else { -// clock_gettime(CLOCK_MONOTONIC, &ts); -// now = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000; -// timeout = when > now ? (int) ((when - now + 999) / 1000) : 0; -// } -// i = poll(fds, 2, timeout); -// if ((i == -1) && (errno != EINTR)) { -// /* An unexpected error. */ -// return (errno != 0) ? -errno : -EINTR; -// } -// if (fds[0].revents & POLLHUP) { -// /* The close notification pipe was closed. */ -// return 0; -// } -// if (sd_journal_process(j) == SD_JOURNAL_APPEND) { -// /* Data, which we might care about, was appended. */ -// return 1; -// } -// } while ((fds[0].revents & POLLHUP) == 0); -// return 0; -//} -import "C" - -import ( - "fmt" - "strings" - "time" - "unsafe" - - "github.com/Sirupsen/logrus" - "github.com/coreos/go-systemd/journal" - "github.com/docker/docker/daemon/logger" -) - -func (s *journald) Close() error { - s.readers.mu.Lock() - for reader := range s.readers.readers { - reader.Close() - } - s.readers.mu.Unlock() - return nil -} - -func (s *journald) drainJournal(logWatcher *logger.LogWatcher, config logger.ReadConfig, j *C.sd_journal, oldCursor *C.char) *C.char { - var msg, data, cursor *C.char - var length C.size_t - var stamp C.uint64_t - var priority, partial C.int - - // Walk the journal from here forward until we run out of new entries. -drain: - for { - // Try not to send a given entry twice. - if oldCursor != nil { - for C.sd_journal_test_cursor(j, oldCursor) > 0 { - if C.sd_journal_next(j) <= 0 { - break drain - } - } - } - // Read and send the logged message, if there is one to read. - i := C.get_message(j, &msg, &length, &partial) - if i != -C.ENOENT && i != -C.EADDRNOTAVAIL { - // Read the entry's timestamp. - if C.sd_journal_get_realtime_usec(j, &stamp) != 0 { - break - } - // Set up the time and text of the entry. - timestamp := time.Unix(int64(stamp)/1000000, (int64(stamp)%1000000)*1000) - line := C.GoBytes(unsafe.Pointer(msg), C.int(length)) - if partial == 0 { - line = append(line, "\n"...) - } - // Recover the stream name by mapping - // from the journal priority back to - // the stream that we would have - // assigned that value. - source := "" - if C.get_priority(j, &priority) != 0 { - source = "" - } else if priority == C.int(journal.PriErr) { - source = "stderr" - } else if priority == C.int(journal.PriInfo) { - source = "stdout" - } - // Retrieve the values of any variables we're adding to the journal. - attrs := make(map[string]string) - C.sd_journal_restart_data(j) - for C.get_attribute_field(j, &data, &length) > C.int(0) { - kv := strings.SplitN(C.GoStringN(data, C.int(length)), "=", 2) - attrs[kv[0]] = kv[1] - } - if len(attrs) == 0 { - attrs = nil - } - // Send the log message. - logWatcher.Msg <- &logger.Message{ - Line: line, - Source: source, - Timestamp: timestamp.In(time.UTC), - Attrs: attrs, - } - } - // If we're at the end of the journal, we're done (for now). - if C.sd_journal_next(j) <= 0 { - break - } - } - - // free(NULL) is safe - C.free(unsafe.Pointer(oldCursor)) - C.sd_journal_get_cursor(j, &cursor) - return cursor -} - -func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.ReadConfig, j *C.sd_journal, pfd [2]C.int, cursor *C.char) *C.char { - s.readers.mu.Lock() - s.readers.readers[logWatcher] = logWatcher - s.readers.mu.Unlock() - go func() { - // Keep copying journal data out until we're notified to stop - // or we hit an error. - status := C.wait_for_data_cancelable(j, pfd[0]) - for status == 1 { - cursor = s.drainJournal(logWatcher, config, j, cursor) - status = C.wait_for_data_cancelable(j, pfd[0]) - } - if status < 0 { - cerrstr := C.strerror(C.int(-status)) - errstr := C.GoString(cerrstr) - fmtstr := "error %q while attempting to follow journal for container %q" - logrus.Errorf(fmtstr, errstr, s.vars["CONTAINER_ID_FULL"]) - } - // Clean up. - C.close(pfd[0]) - s.readers.mu.Lock() - delete(s.readers.readers, logWatcher) - s.readers.mu.Unlock() - C.sd_journal_close(j) - close(logWatcher.Msg) - }() - // Wait until we're told to stop. - select { - case <-logWatcher.WatchClose(): - // Notify the other goroutine that its work is done. - C.close(pfd[1]) - } - - return cursor -} - -func (s *journald) readLogs(logWatcher *logger.LogWatcher, config logger.ReadConfig) { - var j *C.sd_journal - var cmatch, cursor *C.char - var stamp C.uint64_t - var sinceUnixMicro uint64 - var pipes [2]C.int - - // Get a handle to the journal. - rc := C.sd_journal_open(&j, C.int(0)) - if rc != 0 { - logWatcher.Err <- fmt.Errorf("error opening journal") - close(logWatcher.Msg) - return - } - // If we end up following the log, we can set the journal context - // pointer and the channel pointer to nil so that we won't close them - // here, potentially while the goroutine that uses them is still - // running. Otherwise, close them when we return from this function. - following := false - defer func(pfollowing *bool) { - if !*pfollowing { - C.sd_journal_close(j) - close(logWatcher.Msg) - } - }(&following) - // Remove limits on the size of data items that we'll retrieve. - rc = C.sd_journal_set_data_threshold(j, C.size_t(0)) - if rc != 0 { - logWatcher.Err <- fmt.Errorf("error setting journal data threshold") - return - } - // Add a match to have the library do the searching for us. - cmatch = C.CString("CONTAINER_ID_FULL=" + s.vars["CONTAINER_ID_FULL"]) - defer C.free(unsafe.Pointer(cmatch)) - rc = C.sd_journal_add_match(j, unsafe.Pointer(cmatch), C.strlen(cmatch)) - if rc != 0 { - logWatcher.Err <- fmt.Errorf("error setting journal match") - return - } - // If we have a cutoff time, convert it to Unix time once. - if !config.Since.IsZero() { - nano := config.Since.UnixNano() - sinceUnixMicro = uint64(nano / 1000) - } - if config.Tail > 0 { - lines := config.Tail - // Start at the end of the journal. - if C.sd_journal_seek_tail(j) < 0 { - logWatcher.Err <- fmt.Errorf("error seeking to end of journal") - return - } - if C.sd_journal_previous(j) < 0 { - logWatcher.Err <- fmt.Errorf("error backtracking to previous journal entry") - return - } - // Walk backward. - for lines > 0 { - // Stop if the entry time is before our cutoff. - // We'll need the entry time if it isn't, so go - // ahead and parse it now. - if C.sd_journal_get_realtime_usec(j, &stamp) != 0 { - break - } else { - // Compare the timestamp on the entry - // to our threshold value. - if sinceUnixMicro != 0 && sinceUnixMicro > uint64(stamp) { - break - } - } - lines-- - // If we're at the start of the journal, or - // don't need to back up past any more entries, - // stop. - if lines == 0 || C.sd_journal_previous(j) <= 0 { - break - } - } - } else { - // Start at the beginning of the journal. - if C.sd_journal_seek_head(j) < 0 { - logWatcher.Err <- fmt.Errorf("error seeking to start of journal") - return - } - // If we have a cutoff date, fast-forward to it. - if sinceUnixMicro != 0 && C.sd_journal_seek_realtime_usec(j, C.uint64_t(sinceUnixMicro)) != 0 { - logWatcher.Err <- fmt.Errorf("error seeking to start time in journal") - return - } - if C.sd_journal_next(j) < 0 { - logWatcher.Err <- fmt.Errorf("error skipping to next journal entry") - return - } - } - cursor = s.drainJournal(logWatcher, config, j, nil) - if config.Follow { - // Allocate a descriptor for following the journal, if we'll - // need one. Do it here so that we can report if it fails. - if fd := C.sd_journal_get_fd(j); fd < C.int(0) { - logWatcher.Err <- fmt.Errorf("error opening journald follow descriptor: %q", C.GoString(C.strerror(-fd))) - } else { - // Create a pipe that we can poll at the same time as - // the journald descriptor. - if C.pipe(&pipes[0]) == C.int(-1) { - logWatcher.Err <- fmt.Errorf("error opening journald close notification pipe") - } else { - cursor = s.followJournal(logWatcher, config, j, pipes, cursor) - // Let followJournal handle freeing the journal context - // object and closing the channel. - following = true - } - } - } - - C.free(unsafe.Pointer(cursor)) - return -} - -func (s *journald) ReadLogs(config logger.ReadConfig) *logger.LogWatcher { - logWatcher := logger.NewLogWatcher() - go s.readLogs(logWatcher, config) - return logWatcher -} diff --git a/vendor/github.com/docker/docker/daemon/logger/journald/read_native.go b/vendor/github.com/docker/docker/daemon/logger/journald/read_native.go deleted file mode 100644 index bba6de5..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/journald/read_native.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build linux,cgo,!static_build,journald,!journald_compat - -package journald - -// #cgo pkg-config: libsystemd -import "C" diff --git a/vendor/github.com/docker/docker/daemon/logger/journald/read_native_compat.go b/vendor/github.com/docker/docker/daemon/logger/journald/read_native_compat.go deleted file mode 100644 index 3f7a43c..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/journald/read_native_compat.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build linux,cgo,!static_build,journald,journald_compat - -package journald - -// #cgo pkg-config: libsystemd-journal -import "C" diff --git a/vendor/github.com/docker/docker/daemon/logger/journald/read_unsupported.go b/vendor/github.com/docker/docker/daemon/logger/journald/read_unsupported.go deleted file mode 100644 index b43abdc..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/journald/read_unsupported.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build !linux !cgo static_build !journald - -package journald - -func (s *journald) Close() error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/logger/jsonfilelog/jsonfilelog.go b/vendor/github.com/docker/docker/daemon/logger/jsonfilelog/jsonfilelog.go deleted file mode 100644 index a429a08..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/jsonfilelog/jsonfilelog.go +++ /dev/null @@ -1,151 +0,0 @@ -// Package jsonfilelog provides the default Logger implementation for -// Docker logging. This logger logs to files on the host server in the -// JSON format. -package jsonfilelog - -import ( - "bytes" - "encoding/json" - "fmt" - "strconv" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/daemon/logger/loggerutils" - "github.com/docker/docker/pkg/jsonlog" - "github.com/docker/go-units" -) - -// Name is the name of the file that the jsonlogger logs to. -const Name = "json-file" - -// JSONFileLogger is Logger implementation for default Docker logging. -type JSONFileLogger struct { - buf *bytes.Buffer - writer *loggerutils.RotateFileWriter - mu sync.Mutex - readers map[*logger.LogWatcher]struct{} // stores the active log followers - extra []byte // json-encoded extra attributes -} - -func init() { - if err := logger.RegisterLogDriver(Name, New); err != nil { - logrus.Fatal(err) - } - if err := logger.RegisterLogOptValidator(Name, ValidateLogOpt); err != nil { - logrus.Fatal(err) - } -} - -// New creates new JSONFileLogger which writes to filename passed in -// on given context. -func New(ctx logger.Context) (logger.Logger, error) { - var capval int64 = -1 - if capacity, ok := ctx.Config["max-size"]; ok { - var err error - capval, err = units.FromHumanSize(capacity) - if err != nil { - return nil, err - } - } - var maxFiles = 1 - if maxFileString, ok := ctx.Config["max-file"]; ok { - var err error - maxFiles, err = strconv.Atoi(maxFileString) - if err != nil { - return nil, err - } - if maxFiles < 1 { - return nil, fmt.Errorf("max-file cannot be less than 1") - } - } - - writer, err := loggerutils.NewRotateFileWriter(ctx.LogPath, capval, maxFiles) - if err != nil { - return nil, err - } - - var extra []byte - if attrs := ctx.ExtraAttributes(nil); len(attrs) > 0 { - var err error - extra, err = json.Marshal(attrs) - if err != nil { - return nil, err - } - } - - return &JSONFileLogger{ - buf: bytes.NewBuffer(nil), - writer: writer, - readers: make(map[*logger.LogWatcher]struct{}), - extra: extra, - }, nil -} - -// Log converts logger.Message to jsonlog.JSONLog and serializes it to file. -func (l *JSONFileLogger) Log(msg *logger.Message) error { - timestamp, err := jsonlog.FastTimeMarshalJSON(msg.Timestamp) - if err != nil { - return err - } - l.mu.Lock() - logline := msg.Line - if !msg.Partial { - logline = append(msg.Line, '\n') - } - err = (&jsonlog.JSONLogs{ - Log: logline, - Stream: msg.Source, - Created: timestamp, - RawAttrs: l.extra, - }).MarshalJSONBuf(l.buf) - if err != nil { - l.mu.Unlock() - return err - } - - l.buf.WriteByte('\n') - _, err = l.writer.Write(l.buf.Bytes()) - l.buf.Reset() - l.mu.Unlock() - - return err -} - -// ValidateLogOpt looks for json specific log options max-file & max-size. -func ValidateLogOpt(cfg map[string]string) error { - for key := range cfg { - switch key { - case "max-file": - case "max-size": - case "labels": - case "env": - default: - return fmt.Errorf("unknown log opt '%s' for json-file log driver", key) - } - } - return nil -} - -// LogPath returns the location the given json logger logs to. -func (l *JSONFileLogger) LogPath() string { - return l.writer.LogPath() -} - -// Close closes underlying file and signals all readers to stop. -func (l *JSONFileLogger) Close() error { - l.mu.Lock() - err := l.writer.Close() - for r := range l.readers { - r.Close() - delete(l.readers, r) - } - l.mu.Unlock() - return err -} - -// Name returns name of this logger. -func (l *JSONFileLogger) Name() string { - return Name -} diff --git a/vendor/github.com/docker/docker/daemon/logger/jsonfilelog/jsonfilelog_test.go b/vendor/github.com/docker/docker/daemon/logger/jsonfilelog/jsonfilelog_test.go deleted file mode 100644 index b5b818a..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/jsonfilelog/jsonfilelog_test.go +++ /dev/null @@ -1,248 +0,0 @@ -package jsonfilelog - -import ( - "encoding/json" - "io/ioutil" - "os" - "path/filepath" - "reflect" - "strconv" - "testing" - "time" - - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/pkg/jsonlog" -) - -func TestJSONFileLogger(t *testing.T) { - cid := "a7317399f3f857173c6179d44823594f8294678dea9999662e5c625b5a1c7657" - tmp, err := ioutil.TempDir("", "docker-logger-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - filename := filepath.Join(tmp, "container.log") - l, err := New(logger.Context{ - ContainerID: cid, - LogPath: filename, - }) - if err != nil { - t.Fatal(err) - } - defer l.Close() - - if err := l.Log(&logger.Message{Line: []byte("line1"), Source: "src1"}); err != nil { - t.Fatal(err) - } - if err := l.Log(&logger.Message{Line: []byte("line2"), Source: "src2"}); err != nil { - t.Fatal(err) - } - if err := l.Log(&logger.Message{Line: []byte("line3"), Source: "src3"}); err != nil { - t.Fatal(err) - } - res, err := ioutil.ReadFile(filename) - if err != nil { - t.Fatal(err) - } - expected := `{"log":"line1\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line2\n","stream":"src2","time":"0001-01-01T00:00:00Z"} -{"log":"line3\n","stream":"src3","time":"0001-01-01T00:00:00Z"} -` - - if string(res) != expected { - t.Fatalf("Wrong log content: %q, expected %q", res, expected) - } -} - -func BenchmarkJSONFileLogger(b *testing.B) { - cid := "a7317399f3f857173c6179d44823594f8294678dea9999662e5c625b5a1c7657" - tmp, err := ioutil.TempDir("", "docker-logger-") - if err != nil { - b.Fatal(err) - } - defer os.RemoveAll(tmp) - filename := filepath.Join(tmp, "container.log") - l, err := New(logger.Context{ - ContainerID: cid, - LogPath: filename, - }) - if err != nil { - b.Fatal(err) - } - defer l.Close() - - testLine := "Line that thinks that it is log line from docker\n" - msg := &logger.Message{Line: []byte(testLine), Source: "stderr", Timestamp: time.Now().UTC()} - jsonlog, err := (&jsonlog.JSONLog{Log: string(msg.Line) + "\n", Stream: msg.Source, Created: msg.Timestamp}).MarshalJSON() - if err != nil { - b.Fatal(err) - } - b.SetBytes(int64(len(jsonlog)+1) * 30) - b.ResetTimer() - for i := 0; i < b.N; i++ { - for j := 0; j < 30; j++ { - if err := l.Log(msg); err != nil { - b.Fatal(err) - } - } - } -} - -func TestJSONFileLoggerWithOpts(t *testing.T) { - cid := "a7317399f3f857173c6179d44823594f8294678dea9999662e5c625b5a1c7657" - tmp, err := ioutil.TempDir("", "docker-logger-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - filename := filepath.Join(tmp, "container.log") - config := map[string]string{"max-file": "2", "max-size": "1k"} - l, err := New(logger.Context{ - ContainerID: cid, - LogPath: filename, - Config: config, - }) - if err != nil { - t.Fatal(err) - } - defer l.Close() - for i := 0; i < 20; i++ { - if err := l.Log(&logger.Message{Line: []byte("line" + strconv.Itoa(i)), Source: "src1"}); err != nil { - t.Fatal(err) - } - } - res, err := ioutil.ReadFile(filename) - if err != nil { - t.Fatal(err) - } - penUlt, err := ioutil.ReadFile(filename + ".1") - if err != nil { - t.Fatal(err) - } - - expectedPenultimate := `{"log":"line0\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line1\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line2\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line3\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line4\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line5\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line6\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line7\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line8\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line9\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line10\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line11\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line12\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line13\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line14\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line15\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -` - expected := `{"log":"line16\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line17\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line18\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -{"log":"line19\n","stream":"src1","time":"0001-01-01T00:00:00Z"} -` - - if string(res) != expected { - t.Fatalf("Wrong log content: %q, expected %q", res, expected) - } - if string(penUlt) != expectedPenultimate { - t.Fatalf("Wrong log content: %q, expected %q", penUlt, expectedPenultimate) - } - -} - -func TestJSONFileLoggerWithLabelsEnv(t *testing.T) { - cid := "a7317399f3f857173c6179d44823594f8294678dea9999662e5c625b5a1c7657" - tmp, err := ioutil.TempDir("", "docker-logger-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - filename := filepath.Join(tmp, "container.log") - config := map[string]string{"labels": "rack,dc", "env": "environ,debug,ssl"} - l, err := New(logger.Context{ - ContainerID: cid, - LogPath: filename, - Config: config, - ContainerLabels: map[string]string{"rack": "101", "dc": "lhr"}, - ContainerEnv: []string{"environ=production", "debug=false", "port=10001", "ssl=true"}, - }) - if err != nil { - t.Fatal(err) - } - defer l.Close() - if err := l.Log(&logger.Message{Line: []byte("line"), Source: "src1"}); err != nil { - t.Fatal(err) - } - res, err := ioutil.ReadFile(filename) - if err != nil { - t.Fatal(err) - } - - var jsonLog jsonlog.JSONLogs - if err := json.Unmarshal(res, &jsonLog); err != nil { - t.Fatal(err) - } - extra := make(map[string]string) - if err := json.Unmarshal(jsonLog.RawAttrs, &extra); err != nil { - t.Fatal(err) - } - expected := map[string]string{ - "rack": "101", - "dc": "lhr", - "environ": "production", - "debug": "false", - "ssl": "true", - } - if !reflect.DeepEqual(extra, expected) { - t.Fatalf("Wrong log attrs: %q, expected %q", extra, expected) - } -} - -func BenchmarkJSONFileLoggerWithReader(b *testing.B) { - b.StopTimer() - b.ResetTimer() - cid := "a7317399f3f857173c6179d44823594f8294678dea9999662e5c625b5a1c7657" - dir, err := ioutil.TempDir("", "json-logger-bench") - if err != nil { - b.Fatal(err) - } - defer os.RemoveAll(dir) - - l, err := New(logger.Context{ - ContainerID: cid, - LogPath: filepath.Join(dir, "container.log"), - }) - if err != nil { - b.Fatal(err) - } - defer l.Close() - msg := &logger.Message{Line: []byte("line"), Source: "src1"} - jsonlog, err := (&jsonlog.JSONLog{Log: string(msg.Line) + "\n", Stream: msg.Source, Created: msg.Timestamp}).MarshalJSON() - if err != nil { - b.Fatal(err) - } - b.SetBytes(int64(len(jsonlog)+1) * 30) - - b.StartTimer() - - go func() { - for i := 0; i < b.N; i++ { - for j := 0; j < 30; j++ { - l.Log(msg) - } - } - l.Close() - }() - - lw := l.(logger.LogReader).ReadLogs(logger.ReadConfig{Follow: true}) - watchClose := lw.WatchClose() - for { - select { - case <-lw.Msg: - case <-watchClose: - return - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/logger/jsonfilelog/read.go b/vendor/github.com/docker/docker/daemon/logger/jsonfilelog/read.go deleted file mode 100644 index f2f9df1..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/jsonfilelog/read.go +++ /dev/null @@ -1,319 +0,0 @@ -package jsonfilelog - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io" - "os" - "time" - - "github.com/fsnotify/fsnotify" - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/pkg/filenotify" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/jsonlog" - "github.com/docker/docker/pkg/tailfile" -) - -const maxJSONDecodeRetry = 20000 - -func decodeLogLine(dec *json.Decoder, l *jsonlog.JSONLog) (*logger.Message, error) { - l.Reset() - if err := dec.Decode(l); err != nil { - return nil, err - } - msg := &logger.Message{ - Source: l.Stream, - Timestamp: l.Created, - Line: []byte(l.Log), - Attrs: l.Attrs, - } - return msg, nil -} - -// ReadLogs implements the logger's LogReader interface for the logs -// created by this driver. -func (l *JSONFileLogger) ReadLogs(config logger.ReadConfig) *logger.LogWatcher { - logWatcher := logger.NewLogWatcher() - - go l.readLogs(logWatcher, config) - return logWatcher -} - -func (l *JSONFileLogger) readLogs(logWatcher *logger.LogWatcher, config logger.ReadConfig) { - defer close(logWatcher.Msg) - - // lock so the read stream doesn't get corrupted due to rotations or other log data written while we read - // This will block writes!!! - l.mu.Lock() - - pth := l.writer.LogPath() - var files []io.ReadSeeker - for i := l.writer.MaxFiles(); i > 1; i-- { - f, err := os.Open(fmt.Sprintf("%s.%d", pth, i-1)) - if err != nil { - if !os.IsNotExist(err) { - logWatcher.Err <- err - break - } - continue - } - defer f.Close() - - files = append(files, f) - } - - latestFile, err := os.Open(pth) - if err != nil { - logWatcher.Err <- err - l.mu.Unlock() - return - } - defer latestFile.Close() - - if config.Tail != 0 { - tailer := ioutils.MultiReadSeeker(append(files, latestFile)...) - tailFile(tailer, logWatcher, config.Tail, config.Since) - } - - // close all the rotated files - for _, f := range files { - if err := f.(io.Closer).Close(); err != nil { - logrus.WithField("logger", "json-file").Warnf("error closing tailed log file: %v", err) - } - } - - if !config.Follow { - if err := latestFile.Close(); err != nil { - logrus.Errorf("Error closing file: %v", err) - } - l.mu.Unlock() - return - } - - if config.Tail >= 0 { - latestFile.Seek(0, os.SEEK_END) - } - - l.readers[logWatcher] = struct{}{} - l.mu.Unlock() - - notifyRotate := l.writer.NotifyRotate() - followLogs(latestFile, logWatcher, notifyRotate, config.Since) - - l.mu.Lock() - delete(l.readers, logWatcher) - l.mu.Unlock() - - l.writer.NotifyRotateEvict(notifyRotate) -} - -func tailFile(f io.ReadSeeker, logWatcher *logger.LogWatcher, tail int, since time.Time) { - var rdr io.Reader - rdr = f - if tail > 0 { - ls, err := tailfile.TailFile(f, tail) - if err != nil { - logWatcher.Err <- err - return - } - rdr = bytes.NewBuffer(bytes.Join(ls, []byte("\n"))) - } - dec := json.NewDecoder(rdr) - l := &jsonlog.JSONLog{} - for { - msg, err := decodeLogLine(dec, l) - if err != nil { - if err != io.EOF { - logWatcher.Err <- err - } - return - } - if !since.IsZero() && msg.Timestamp.Before(since) { - continue - } - logWatcher.Msg <- msg - } -} - -func watchFile(name string) (filenotify.FileWatcher, error) { - fileWatcher, err := filenotify.New() - if err != nil { - return nil, err - } - - if err := fileWatcher.Add(name); err != nil { - logrus.WithField("logger", "json-file").Warnf("falling back to file poller due to error: %v", err) - fileWatcher.Close() - fileWatcher = filenotify.NewPollingWatcher() - - if err := fileWatcher.Add(name); err != nil { - fileWatcher.Close() - logrus.Debugf("error watching log file for modifications: %v", err) - return nil, err - } - } - return fileWatcher, nil -} - -func followLogs(f *os.File, logWatcher *logger.LogWatcher, notifyRotate chan interface{}, since time.Time) { - dec := json.NewDecoder(f) - l := &jsonlog.JSONLog{} - - name := f.Name() - fileWatcher, err := watchFile(name) - if err != nil { - logWatcher.Err <- err - return - } - defer func() { - f.Close() - fileWatcher.Remove(name) - fileWatcher.Close() - }() - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - go func() { - select { - case <-logWatcher.WatchClose(): - fileWatcher.Remove(name) - cancel() - case <-ctx.Done(): - return - } - }() - - var retries int - handleRotate := func() error { - f.Close() - fileWatcher.Remove(name) - - // retry when the file doesn't exist - for retries := 0; retries <= 5; retries++ { - f, err = os.Open(name) - if err == nil || !os.IsNotExist(err) { - break - } - } - if err != nil { - return err - } - if err := fileWatcher.Add(name); err != nil { - return err - } - dec = json.NewDecoder(f) - return nil - } - - errRetry := errors.New("retry") - errDone := errors.New("done") - waitRead := func() error { - select { - case e := <-fileWatcher.Events(): - switch e.Op { - case fsnotify.Write: - dec = json.NewDecoder(f) - return nil - case fsnotify.Rename, fsnotify.Remove: - select { - case <-notifyRotate: - case <-ctx.Done(): - return errDone - } - if err := handleRotate(); err != nil { - return err - } - return nil - } - return errRetry - case err := <-fileWatcher.Errors(): - logrus.Debug("logger got error watching file: %v", err) - // Something happened, let's try and stay alive and create a new watcher - if retries <= 5 { - fileWatcher.Close() - fileWatcher, err = watchFile(name) - if err != nil { - return err - } - retries++ - return errRetry - } - return err - case <-ctx.Done(): - return errDone - } - } - - handleDecodeErr := func(err error) error { - if err == io.EOF { - for err := waitRead(); err != nil; { - if err == errRetry { - // retry the waitRead - continue - } - return err - } - return nil - } - // try again because this shouldn't happen - if _, ok := err.(*json.SyntaxError); ok && retries <= maxJSONDecodeRetry { - dec = json.NewDecoder(f) - retries++ - return nil - } - // io.ErrUnexpectedEOF is returned from json.Decoder when there is - // remaining data in the parser's buffer while an io.EOF occurs. - // If the json logger writes a partial json log entry to the disk - // while at the same time the decoder tries to decode it, the race condition happens. - if err == io.ErrUnexpectedEOF && retries <= maxJSONDecodeRetry { - reader := io.MultiReader(dec.Buffered(), f) - dec = json.NewDecoder(reader) - retries++ - return nil - } - return err - } - - // main loop - for { - msg, err := decodeLogLine(dec, l) - if err != nil { - if err := handleDecodeErr(err); err != nil { - if err == errDone { - return - } - // we got an unrecoverable error, so return - logWatcher.Err <- err - return - } - // ready to try again - continue - } - - retries = 0 // reset retries since we've succeeded - if !since.IsZero() && msg.Timestamp.Before(since) { - continue - } - select { - case logWatcher.Msg <- msg: - case <-ctx.Done(): - logWatcher.Msg <- msg - for { - msg, err := decodeLogLine(dec, l) - if err != nil { - return - } - if !since.IsZero() && msg.Timestamp.Before(since) { - continue - } - logWatcher.Msg <- msg - } - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/logger/logentries/logentries.go b/vendor/github.com/docker/docker/daemon/logger/logentries/logentries.go deleted file mode 100644 index e794b1e..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/logentries/logentries.go +++ /dev/null @@ -1,94 +0,0 @@ -// Package logentries provides the log driver for forwarding server logs -// to logentries endpoints. -package logentries - -import ( - "fmt" - - "github.com/Sirupsen/logrus" - "github.com/bsphere/le_go" - "github.com/docker/docker/daemon/logger" -) - -type logentries struct { - tag string - containerID string - containerName string - writer *le_go.Logger - extra map[string]string -} - -const ( - name = "logentries" - token = "logentries-token" -) - -func init() { - if err := logger.RegisterLogDriver(name, New); err != nil { - logrus.Fatal(err) - } - if err := logger.RegisterLogOptValidator(name, ValidateLogOpt); err != nil { - logrus.Fatal(err) - } -} - -// New creates a logentries logger using the configuration passed in on -// the context. The supported context configuration variable is -// logentries-token. -func New(ctx logger.Context) (logger.Logger, error) { - logrus.WithField("container", ctx.ContainerID). - WithField("token", ctx.Config[token]). - Debug("logging driver logentries configured") - - log, err := le_go.Connect(ctx.Config[token]) - if err != nil { - return nil, err - } - return &logentries{ - containerID: ctx.ContainerID, - containerName: ctx.ContainerName, - writer: log, - }, nil -} - -func (f *logentries) Log(msg *logger.Message) error { - data := map[string]string{ - "container_id": f.containerID, - "container_name": f.containerName, - "source": msg.Source, - "log": string(msg.Line), - } - for k, v := range f.extra { - data[k] = v - } - f.writer.Println(f.tag, msg.Timestamp, data) - return nil -} - -func (f *logentries) Close() error { - return f.writer.Close() -} - -func (f *logentries) Name() string { - return name -} - -// ValidateLogOpt looks for logentries specific log option logentries-address. -func ValidateLogOpt(cfg map[string]string) error { - for key := range cfg { - switch key { - case "env": - case "labels": - case "tag": - case key: - default: - return fmt.Errorf("unknown log opt '%s' for logentries log driver", key) - } - } - - if cfg[token] == "" { - return fmt.Errorf("Missing logentries token") - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/logger/logger.go b/vendor/github.com/docker/docker/daemon/logger/logger.go deleted file mode 100644 index d091997..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/logger.go +++ /dev/null @@ -1,134 +0,0 @@ -// Package logger defines interfaces that logger drivers implement to -// log messages. -// -// The other half of a logger driver is the implementation of the -// factory, which holds the contextual instance information that -// allows multiple loggers of the same type to perform different -// actions, such as logging to different locations. -package logger - -import ( - "errors" - "sort" - "strings" - "sync" - "time" - - "github.com/docker/docker/pkg/jsonlog" -) - -// ErrReadLogsNotSupported is returned when the logger does not support reading logs. -var ErrReadLogsNotSupported = errors.New("configured logging reader does not support reading") - -const ( - // TimeFormat is the time format used for timestamps sent to log readers. - TimeFormat = jsonlog.RFC3339NanoFixed - logWatcherBufferSize = 4096 -) - -// Message is datastructure that represents piece of output produced by some -// container. The Line member is a slice of an array whose contents can be -// changed after a log driver's Log() method returns. -type Message struct { - Line []byte - Source string - Timestamp time.Time - Attrs LogAttributes - Partial bool -} - -// CopyMessage creates a copy of the passed-in Message which will remain -// unchanged if the original is changed. Log drivers which buffer Messages -// rather than dispatching them during their Log() method should use this -// function to obtain a Message whose Line member's contents won't change. -func CopyMessage(msg *Message) *Message { - m := new(Message) - m.Line = make([]byte, len(msg.Line)) - copy(m.Line, msg.Line) - m.Source = msg.Source - m.Timestamp = msg.Timestamp - m.Partial = msg.Partial - m.Attrs = make(LogAttributes) - for k, v := range msg.Attrs { - m.Attrs[k] = v - } - return m -} - -// LogAttributes is used to hold the extra attributes available in the log message -// Primarily used for converting the map type to string and sorting. -type LogAttributes map[string]string -type byKey []string - -func (s byKey) Len() int { return len(s) } -func (s byKey) Less(i, j int) bool { - keyI := strings.Split(s[i], "=") - keyJ := strings.Split(s[j], "=") - return keyI[0] < keyJ[0] -} -func (s byKey) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} - -func (a LogAttributes) String() string { - var ss byKey - for k, v := range a { - ss = append(ss, k+"="+v) - } - sort.Sort(ss) - return strings.Join(ss, ",") -} - -// Logger is the interface for docker logging drivers. -type Logger interface { - Log(*Message) error - Name() string - Close() error -} - -// ReadConfig is the configuration passed into ReadLogs. -type ReadConfig struct { - Since time.Time - Tail int - Follow bool -} - -// LogReader is the interface for reading log messages for loggers that support reading. -type LogReader interface { - // Read logs from underlying logging backend - ReadLogs(ReadConfig) *LogWatcher -} - -// LogWatcher is used when consuming logs read from the LogReader interface. -type LogWatcher struct { - // For sending log messages to a reader. - Msg chan *Message - // For sending error messages that occur while while reading logs. - Err chan error - closeOnce sync.Once - closeNotifier chan struct{} -} - -// NewLogWatcher returns a new LogWatcher. -func NewLogWatcher() *LogWatcher { - return &LogWatcher{ - Msg: make(chan *Message, logWatcherBufferSize), - Err: make(chan error, 1), - closeNotifier: make(chan struct{}), - } -} - -// Close notifies the underlying log reader to stop. -func (w *LogWatcher) Close() { - // only close if not already closed - w.closeOnce.Do(func() { - close(w.closeNotifier) - }) -} - -// WatchClose returns a channel receiver that receives notification -// when the watcher has been closed. This should only be called from -// one goroutine. -func (w *LogWatcher) WatchClose() <-chan struct{} { - return w.closeNotifier -} diff --git a/vendor/github.com/docker/docker/daemon/logger/logger_test.go b/vendor/github.com/docker/docker/daemon/logger/logger_test.go deleted file mode 100644 index 16e1514..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/logger_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package logger - -import ( - "reflect" - "testing" - "time" -) - -func TestCopyMessage(t *testing.T) { - msg := &Message{ - Line: []byte("test line."), - Source: "stdout", - Timestamp: time.Now(), - Attrs: LogAttributes{ - "key1": "val1", - "key2": "val2", - "key3": "val3", - }, - Partial: true, - } - - m := CopyMessage(msg) - if !reflect.DeepEqual(m, msg) { - t.Fatalf("CopyMessage failed to copy message") - } -} diff --git a/vendor/github.com/docker/docker/daemon/logger/loggerutils/log_tag.go b/vendor/github.com/docker/docker/daemon/logger/loggerutils/log_tag.go deleted file mode 100644 index 4752679..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/loggerutils/log_tag.go +++ /dev/null @@ -1,31 +0,0 @@ -package loggerutils - -import ( - "bytes" - - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/utils/templates" -) - -// DefaultTemplate defines the defaults template logger should use. -const DefaultTemplate = "{{.ID}}" - -// ParseLogTag generates a context aware tag for consistency across different -// log drivers based on the context of the running container. -func ParseLogTag(ctx logger.Context, defaultTemplate string) (string, error) { - tagTemplate := ctx.Config["tag"] - if tagTemplate == "" { - tagTemplate = defaultTemplate - } - - tmpl, err := templates.NewParse("log-tag", tagTemplate) - if err != nil { - return "", err - } - buf := new(bytes.Buffer) - if err := tmpl.Execute(buf, &ctx); err != nil { - return "", err - } - - return buf.String(), nil -} diff --git a/vendor/github.com/docker/docker/daemon/logger/loggerutils/log_tag_test.go b/vendor/github.com/docker/docker/daemon/logger/loggerutils/log_tag_test.go deleted file mode 100644 index e2aa435..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/loggerutils/log_tag_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package loggerutils - -import ( - "testing" - - "github.com/docker/docker/daemon/logger" -) - -func TestParseLogTagDefaultTag(t *testing.T) { - ctx := buildContext(map[string]string{}) - tag, e := ParseLogTag(ctx, "{{.ID}}") - assertTag(t, e, tag, ctx.ID()) -} - -func TestParseLogTag(t *testing.T) { - ctx := buildContext(map[string]string{"tag": "{{.ImageName}}/{{.Name}}/{{.ID}}"}) - tag, e := ParseLogTag(ctx, "{{.ID}}") - assertTag(t, e, tag, "test-image/test-container/container-ab") -} - -func TestParseLogTagEmptyTag(t *testing.T) { - ctx := buildContext(map[string]string{}) - tag, e := ParseLogTag(ctx, "{{.DaemonName}}/{{.ID}}") - assertTag(t, e, tag, "test-dockerd/container-ab") -} - -// Helpers - -func buildContext(cfg map[string]string) logger.Context { - return logger.Context{ - ContainerID: "container-abcdefghijklmnopqrstuvwxyz01234567890", - ContainerName: "/test-container", - ContainerImageID: "image-abcdefghijklmnopqrstuvwxyz01234567890", - ContainerImageName: "test-image", - Config: cfg, - DaemonName: "test-dockerd", - } -} - -func assertTag(t *testing.T, e error, tag string, expected string) { - if e != nil { - t.Fatalf("Error generating tag: %q", e) - } - if tag != expected { - t.Fatalf("Wrong tag: %q, should be %q", tag, expected) - } -} diff --git a/vendor/github.com/docker/docker/daemon/logger/loggerutils/rotatefilewriter.go b/vendor/github.com/docker/docker/daemon/logger/loggerutils/rotatefilewriter.go deleted file mode 100644 index 99e0964..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/loggerutils/rotatefilewriter.go +++ /dev/null @@ -1,124 +0,0 @@ -package loggerutils - -import ( - "os" - "strconv" - "sync" - - "github.com/docker/docker/pkg/pubsub" -) - -// RotateFileWriter is Logger implementation for default Docker logging. -type RotateFileWriter struct { - f *os.File // store for closing - mu sync.Mutex - capacity int64 //maximum size of each file - currentSize int64 // current size of the latest file - maxFiles int //maximum number of files - notifyRotate *pubsub.Publisher -} - -//NewRotateFileWriter creates new RotateFileWriter -func NewRotateFileWriter(logPath string, capacity int64, maxFiles int) (*RotateFileWriter, error) { - log, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0640) - if err != nil { - return nil, err - } - - size, err := log.Seek(0, os.SEEK_END) - if err != nil { - return nil, err - } - - return &RotateFileWriter{ - f: log, - capacity: capacity, - currentSize: size, - maxFiles: maxFiles, - notifyRotate: pubsub.NewPublisher(0, 1), - }, nil -} - -//WriteLog write log message to File -func (w *RotateFileWriter) Write(message []byte) (int, error) { - w.mu.Lock() - if err := w.checkCapacityAndRotate(); err != nil { - w.mu.Unlock() - return -1, err - } - - n, err := w.f.Write(message) - if err == nil { - w.currentSize += int64(n) - } - w.mu.Unlock() - return n, err -} - -func (w *RotateFileWriter) checkCapacityAndRotate() error { - if w.capacity == -1 { - return nil - } - - if w.currentSize >= w.capacity { - name := w.f.Name() - if err := w.f.Close(); err != nil { - return err - } - if err := rotate(name, w.maxFiles); err != nil { - return err - } - file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 06400) - if err != nil { - return err - } - w.f = file - w.currentSize = 0 - w.notifyRotate.Publish(struct{}{}) - } - - return nil -} - -func rotate(name string, maxFiles int) error { - if maxFiles < 2 { - return nil - } - for i := maxFiles - 1; i > 1; i-- { - toPath := name + "." + strconv.Itoa(i) - fromPath := name + "." + strconv.Itoa(i-1) - if err := os.Rename(fromPath, toPath); err != nil && !os.IsNotExist(err) { - return err - } - } - - if err := os.Rename(name, name+".1"); err != nil && !os.IsNotExist(err) { - return err - } - return nil -} - -// LogPath returns the location the given writer logs to. -func (w *RotateFileWriter) LogPath() string { - return w.f.Name() -} - -// MaxFiles return maximum number of files -func (w *RotateFileWriter) MaxFiles() int { - return w.maxFiles -} - -//NotifyRotate returns the new subscriber -func (w *RotateFileWriter) NotifyRotate() chan interface{} { - return w.notifyRotate.Subscribe() -} - -//NotifyRotateEvict removes the specified subscriber from receiving any more messages. -func (w *RotateFileWriter) NotifyRotateEvict(sub chan interface{}) { - w.notifyRotate.Evict(sub) -} - -// Close closes underlying file and signals all readers to stop. -func (w *RotateFileWriter) Close() error { - return w.f.Close() -} diff --git a/vendor/github.com/docker/docker/daemon/logger/splunk/splunk.go b/vendor/github.com/docker/docker/daemon/logger/splunk/splunk.go deleted file mode 100644 index f858326..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/splunk/splunk.go +++ /dev/null @@ -1,621 +0,0 @@ -// Package splunk provides the log driver for forwarding server logs to -// Splunk HTTP Event Collector endpoint. -package splunk - -import ( - "bytes" - "compress/gzip" - "crypto/tls" - "crypto/x509" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net/http" - "net/url" - "os" - "strconv" - "sync" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/daemon/logger/loggerutils" - "github.com/docker/docker/pkg/urlutil" -) - -const ( - driverName = "splunk" - splunkURLKey = "splunk-url" - splunkTokenKey = "splunk-token" - splunkSourceKey = "splunk-source" - splunkSourceTypeKey = "splunk-sourcetype" - splunkIndexKey = "splunk-index" - splunkCAPathKey = "splunk-capath" - splunkCANameKey = "splunk-caname" - splunkInsecureSkipVerifyKey = "splunk-insecureskipverify" - splunkFormatKey = "splunk-format" - splunkVerifyConnectionKey = "splunk-verify-connection" - splunkGzipCompressionKey = "splunk-gzip" - splunkGzipCompressionLevelKey = "splunk-gzip-level" - envKey = "env" - labelsKey = "labels" - tagKey = "tag" -) - -const ( - // How often do we send messages (if we are not reaching batch size) - defaultPostMessagesFrequency = 5 * time.Second - // How big can be batch of messages - defaultPostMessagesBatchSize = 1000 - // Maximum number of messages we can store in buffer - defaultBufferMaximum = 10 * defaultPostMessagesBatchSize - // Number of messages allowed to be queued in the channel - defaultStreamChannelSize = 4 * defaultPostMessagesBatchSize -) - -const ( - envVarPostMessagesFrequency = "SPLUNK_LOGGING_DRIVER_POST_MESSAGES_FREQUENCY" - envVarPostMessagesBatchSize = "SPLUNK_LOGGING_DRIVER_POST_MESSAGES_BATCH_SIZE" - envVarBufferMaximum = "SPLUNK_LOGGING_DRIVER_BUFFER_MAX" - envVarStreamChannelSize = "SPLUNK_LOGGING_DRIVER_CHANNEL_SIZE" -) - -type splunkLoggerInterface interface { - logger.Logger - worker() -} - -type splunkLogger struct { - client *http.Client - transport *http.Transport - - url string - auth string - nullMessage *splunkMessage - - // http compression - gzipCompression bool - gzipCompressionLevel int - - // Advanced options - postMessagesFrequency time.Duration - postMessagesBatchSize int - bufferMaximum int - - // For synchronization between background worker and logger. - // We use channel to send messages to worker go routine. - // All other variables for blocking Close call before we flush all messages to HEC - stream chan *splunkMessage - lock sync.RWMutex - closed bool - closedCond *sync.Cond -} - -type splunkLoggerInline struct { - *splunkLogger - - nullEvent *splunkMessageEvent -} - -type splunkLoggerJSON struct { - *splunkLoggerInline -} - -type splunkLoggerRaw struct { - *splunkLogger - - prefix []byte -} - -type splunkMessage struct { - Event interface{} `json:"event"` - Time string `json:"time"` - Host string `json:"host"` - Source string `json:"source,omitempty"` - SourceType string `json:"sourcetype,omitempty"` - Index string `json:"index,omitempty"` -} - -type splunkMessageEvent struct { - Line interface{} `json:"line"` - Source string `json:"source"` - Tag string `json:"tag,omitempty"` - Attrs map[string]string `json:"attrs,omitempty"` -} - -const ( - splunkFormatRaw = "raw" - splunkFormatJSON = "json" - splunkFormatInline = "inline" -) - -func init() { - if err := logger.RegisterLogDriver(driverName, New); err != nil { - logrus.Fatal(err) - } - if err := logger.RegisterLogOptValidator(driverName, ValidateLogOpt); err != nil { - logrus.Fatal(err) - } -} - -// New creates splunk logger driver using configuration passed in context -func New(ctx logger.Context) (logger.Logger, error) { - hostname, err := ctx.Hostname() - if err != nil { - return nil, fmt.Errorf("%s: cannot access hostname to set source field", driverName) - } - - // Parse and validate Splunk URL - splunkURL, err := parseURL(ctx) - if err != nil { - return nil, err - } - - // Splunk Token is required parameter - splunkToken, ok := ctx.Config[splunkTokenKey] - if !ok { - return nil, fmt.Errorf("%s: %s is expected", driverName, splunkTokenKey) - } - - tlsConfig := &tls.Config{} - - // Splunk is using autogenerated certificates by default, - // allow users to trust them with skipping verification - if insecureSkipVerifyStr, ok := ctx.Config[splunkInsecureSkipVerifyKey]; ok { - insecureSkipVerify, err := strconv.ParseBool(insecureSkipVerifyStr) - if err != nil { - return nil, err - } - tlsConfig.InsecureSkipVerify = insecureSkipVerify - } - - // If path to the root certificate is provided - load it - if caPath, ok := ctx.Config[splunkCAPathKey]; ok { - caCert, err := ioutil.ReadFile(caPath) - if err != nil { - return nil, err - } - caPool := x509.NewCertPool() - caPool.AppendCertsFromPEM(caCert) - tlsConfig.RootCAs = caPool - } - - if caName, ok := ctx.Config[splunkCANameKey]; ok { - tlsConfig.ServerName = caName - } - - gzipCompression := false - if gzipCompressionStr, ok := ctx.Config[splunkGzipCompressionKey]; ok { - gzipCompression, err = strconv.ParseBool(gzipCompressionStr) - if err != nil { - return nil, err - } - } - - gzipCompressionLevel := gzip.DefaultCompression - if gzipCompressionLevelStr, ok := ctx.Config[splunkGzipCompressionLevelKey]; ok { - var err error - gzipCompressionLevel64, err := strconv.ParseInt(gzipCompressionLevelStr, 10, 32) - if err != nil { - return nil, err - } - gzipCompressionLevel = int(gzipCompressionLevel64) - if gzipCompressionLevel < gzip.DefaultCompression || gzipCompressionLevel > gzip.BestCompression { - err := fmt.Errorf("Not supported level '%s' for %s (supported values between %d and %d).", - gzipCompressionLevelStr, splunkGzipCompressionLevelKey, gzip.DefaultCompression, gzip.BestCompression) - return nil, err - } - } - - transport := &http.Transport{ - TLSClientConfig: tlsConfig, - } - client := &http.Client{ - Transport: transport, - } - - source := ctx.Config[splunkSourceKey] - sourceType := ctx.Config[splunkSourceTypeKey] - index := ctx.Config[splunkIndexKey] - - var nullMessage = &splunkMessage{ - Host: hostname, - Source: source, - SourceType: sourceType, - Index: index, - } - - // Allow user to remove tag from the messages by setting tag to empty string - tag := "" - if tagTemplate, ok := ctx.Config[tagKey]; !ok || tagTemplate != "" { - tag, err = loggerutils.ParseLogTag(ctx, loggerutils.DefaultTemplate) - if err != nil { - return nil, err - } - } - - attrs := ctx.ExtraAttributes(nil) - - var ( - postMessagesFrequency = getAdvancedOptionDuration(envVarPostMessagesFrequency, defaultPostMessagesFrequency) - postMessagesBatchSize = getAdvancedOptionInt(envVarPostMessagesBatchSize, defaultPostMessagesBatchSize) - bufferMaximum = getAdvancedOptionInt(envVarBufferMaximum, defaultBufferMaximum) - streamChannelSize = getAdvancedOptionInt(envVarStreamChannelSize, defaultStreamChannelSize) - ) - - logger := &splunkLogger{ - client: client, - transport: transport, - url: splunkURL.String(), - auth: "Splunk " + splunkToken, - nullMessage: nullMessage, - gzipCompression: gzipCompression, - gzipCompressionLevel: gzipCompressionLevel, - stream: make(chan *splunkMessage, streamChannelSize), - postMessagesFrequency: postMessagesFrequency, - postMessagesBatchSize: postMessagesBatchSize, - bufferMaximum: bufferMaximum, - } - - // By default we verify connection, but we allow use to skip that - verifyConnection := true - if verifyConnectionStr, ok := ctx.Config[splunkVerifyConnectionKey]; ok { - var err error - verifyConnection, err = strconv.ParseBool(verifyConnectionStr) - if err != nil { - return nil, err - } - } - if verifyConnection { - err = verifySplunkConnection(logger) - if err != nil { - return nil, err - } - } - - var splunkFormat string - if splunkFormatParsed, ok := ctx.Config[splunkFormatKey]; ok { - switch splunkFormatParsed { - case splunkFormatInline: - case splunkFormatJSON: - case splunkFormatRaw: - default: - return nil, fmt.Errorf("Unknown format specified %s, supported formats are inline, json and raw", splunkFormat) - } - splunkFormat = splunkFormatParsed - } else { - splunkFormat = splunkFormatInline - } - - var loggerWrapper splunkLoggerInterface - - switch splunkFormat { - case splunkFormatInline: - nullEvent := &splunkMessageEvent{ - Tag: tag, - Attrs: attrs, - } - - loggerWrapper = &splunkLoggerInline{logger, nullEvent} - case splunkFormatJSON: - nullEvent := &splunkMessageEvent{ - Tag: tag, - Attrs: attrs, - } - - loggerWrapper = &splunkLoggerJSON{&splunkLoggerInline{logger, nullEvent}} - case splunkFormatRaw: - var prefix bytes.Buffer - if tag != "" { - prefix.WriteString(tag) - prefix.WriteString(" ") - } - for key, value := range attrs { - prefix.WriteString(key) - prefix.WriteString("=") - prefix.WriteString(value) - prefix.WriteString(" ") - } - - loggerWrapper = &splunkLoggerRaw{logger, prefix.Bytes()} - default: - return nil, fmt.Errorf("Unexpected format %s", splunkFormat) - } - - go loggerWrapper.worker() - - return loggerWrapper, nil -} - -func (l *splunkLoggerInline) Log(msg *logger.Message) error { - message := l.createSplunkMessage(msg) - - event := *l.nullEvent - event.Line = string(msg.Line) - event.Source = msg.Source - - message.Event = &event - - return l.queueMessageAsync(message) -} - -func (l *splunkLoggerJSON) Log(msg *logger.Message) error { - message := l.createSplunkMessage(msg) - event := *l.nullEvent - - var rawJSONMessage json.RawMessage - if err := json.Unmarshal(msg.Line, &rawJSONMessage); err == nil { - event.Line = &rawJSONMessage - } else { - event.Line = string(msg.Line) - } - - event.Source = msg.Source - - message.Event = &event - - return l.queueMessageAsync(message) -} - -func (l *splunkLoggerRaw) Log(msg *logger.Message) error { - message := l.createSplunkMessage(msg) - - message.Event = string(append(l.prefix, msg.Line...)) - - return l.queueMessageAsync(message) -} - -func (l *splunkLogger) queueMessageAsync(message *splunkMessage) error { - l.lock.RLock() - defer l.lock.RUnlock() - if l.closedCond != nil { - return fmt.Errorf("%s: driver is closed", driverName) - } - l.stream <- message - return nil -} - -func (l *splunkLogger) worker() { - timer := time.NewTicker(l.postMessagesFrequency) - var messages []*splunkMessage - for { - select { - case message, open := <-l.stream: - if !open { - l.postMessages(messages, true) - l.lock.Lock() - defer l.lock.Unlock() - l.transport.CloseIdleConnections() - l.closed = true - l.closedCond.Signal() - return - } - messages = append(messages, message) - // Only sending when we get exactly to the batch size, - // This also helps not to fire postMessages on every new message, - // when previous try failed. - if len(messages)%l.postMessagesBatchSize == 0 { - messages = l.postMessages(messages, false) - } - case <-timer.C: - messages = l.postMessages(messages, false) - } - } -} - -func (l *splunkLogger) postMessages(messages []*splunkMessage, lastChance bool) []*splunkMessage { - messagesLen := len(messages) - for i := 0; i < messagesLen; i += l.postMessagesBatchSize { - upperBound := i + l.postMessagesBatchSize - if upperBound > messagesLen { - upperBound = messagesLen - } - if err := l.tryPostMessages(messages[i:upperBound]); err != nil { - logrus.Error(err) - if messagesLen-i >= l.bufferMaximum || lastChance { - // If this is last chance - print them all to the daemon log - if lastChance { - upperBound = messagesLen - } - // Not all sent, but buffer has got to its maximum, let's log all messages - // we could not send and return buffer minus one batch size - for j := i; j < upperBound; j++ { - if jsonEvent, err := json.Marshal(messages[j]); err != nil { - logrus.Error(err) - } else { - logrus.Error(fmt.Errorf("Failed to send a message '%s'", string(jsonEvent))) - } - } - return messages[upperBound:messagesLen] - } - // Not all sent, returning buffer from where we have not sent messages - return messages[i:messagesLen] - } - } - // All sent, return empty buffer - return messages[:0] -} - -func (l *splunkLogger) tryPostMessages(messages []*splunkMessage) error { - if len(messages) == 0 { - return nil - } - var buffer bytes.Buffer - var writer io.Writer - var gzipWriter *gzip.Writer - var err error - // If gzip compression is enabled - create gzip writer with specified compression - // level. If gzip compression is disabled, use standard buffer as a writer - if l.gzipCompression { - gzipWriter, err = gzip.NewWriterLevel(&buffer, l.gzipCompressionLevel) - if err != nil { - return err - } - writer = gzipWriter - } else { - writer = &buffer - } - for _, message := range messages { - jsonEvent, err := json.Marshal(message) - if err != nil { - return err - } - if _, err := writer.Write(jsonEvent); err != nil { - return err - } - } - // If gzip compression is enabled, tell it, that we are done - if l.gzipCompression { - err = gzipWriter.Close() - if err != nil { - return err - } - } - req, err := http.NewRequest("POST", l.url, bytes.NewBuffer(buffer.Bytes())) - if err != nil { - return err - } - req.Header.Set("Authorization", l.auth) - // Tell if we are sending gzip compressed body - if l.gzipCompression { - req.Header.Set("Content-Encoding", "gzip") - } - res, err := l.client.Do(req) - if err != nil { - return err - } - defer res.Body.Close() - if res.StatusCode != http.StatusOK { - var body []byte - body, err = ioutil.ReadAll(res.Body) - if err != nil { - return err - } - return fmt.Errorf("%s: failed to send event - %s - %s", driverName, res.Status, body) - } - io.Copy(ioutil.Discard, res.Body) - return nil -} - -func (l *splunkLogger) Close() error { - l.lock.Lock() - defer l.lock.Unlock() - if l.closedCond == nil { - l.closedCond = sync.NewCond(&l.lock) - close(l.stream) - for !l.closed { - l.closedCond.Wait() - } - } - return nil -} - -func (l *splunkLogger) Name() string { - return driverName -} - -func (l *splunkLogger) createSplunkMessage(msg *logger.Message) *splunkMessage { - message := *l.nullMessage - message.Time = fmt.Sprintf("%f", float64(msg.Timestamp.UnixNano())/float64(time.Second)) - return &message -} - -// ValidateLogOpt looks for all supported by splunk driver options -func ValidateLogOpt(cfg map[string]string) error { - for key := range cfg { - switch key { - case splunkURLKey: - case splunkTokenKey: - case splunkSourceKey: - case splunkSourceTypeKey: - case splunkIndexKey: - case splunkCAPathKey: - case splunkCANameKey: - case splunkInsecureSkipVerifyKey: - case splunkFormatKey: - case splunkVerifyConnectionKey: - case splunkGzipCompressionKey: - case splunkGzipCompressionLevelKey: - case envKey: - case labelsKey: - case tagKey: - default: - return fmt.Errorf("unknown log opt '%s' for %s log driver", key, driverName) - } - } - return nil -} - -func parseURL(ctx logger.Context) (*url.URL, error) { - splunkURLStr, ok := ctx.Config[splunkURLKey] - if !ok { - return nil, fmt.Errorf("%s: %s is expected", driverName, splunkURLKey) - } - - splunkURL, err := url.Parse(splunkURLStr) - if err != nil { - return nil, fmt.Errorf("%s: failed to parse %s as url value in %s", driverName, splunkURLStr, splunkURLKey) - } - - if !urlutil.IsURL(splunkURLStr) || - !splunkURL.IsAbs() || - (splunkURL.Path != "" && splunkURL.Path != "/") || - splunkURL.RawQuery != "" || - splunkURL.Fragment != "" { - return nil, fmt.Errorf("%s: expected format scheme://dns_name_or_ip:port for %s", driverName, splunkURLKey) - } - - splunkURL.Path = "/services/collector/event/1.0" - - return splunkURL, nil -} - -func verifySplunkConnection(l *splunkLogger) error { - req, err := http.NewRequest(http.MethodOptions, l.url, nil) - if err != nil { - return err - } - res, err := l.client.Do(req) - if err != nil { - return err - } - if res.Body != nil { - defer res.Body.Close() - } - if res.StatusCode != http.StatusOK { - var body []byte - body, err = ioutil.ReadAll(res.Body) - if err != nil { - return err - } - return fmt.Errorf("%s: failed to verify connection - %s - %s", driverName, res.Status, body) - } - return nil -} - -func getAdvancedOptionDuration(envName string, defaultValue time.Duration) time.Duration { - valueStr := os.Getenv(envName) - if valueStr == "" { - return defaultValue - } - parsedValue, err := time.ParseDuration(valueStr) - if err != nil { - logrus.Error(fmt.Sprintf("Failed to parse value of %s as duration. Using default %v. %v", envName, defaultValue, err)) - return defaultValue - } - return parsedValue -} - -func getAdvancedOptionInt(envName string, defaultValue int) int { - valueStr := os.Getenv(envName) - if valueStr == "" { - return defaultValue - } - parsedValue, err := strconv.ParseInt(valueStr, 10, 32) - if err != nil { - logrus.Error(fmt.Sprintf("Failed to parse value of %s as integer. Using default %d. %v", envName, defaultValue, err)) - return defaultValue - } - return int(parsedValue) -} diff --git a/vendor/github.com/docker/docker/daemon/logger/splunk/splunk_test.go b/vendor/github.com/docker/docker/daemon/logger/splunk/splunk_test.go deleted file mode 100644 index df74cba..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/splunk/splunk_test.go +++ /dev/null @@ -1,1302 +0,0 @@ -package splunk - -import ( - "compress/gzip" - "fmt" - "os" - "testing" - "time" - - "github.com/docker/docker/daemon/logger" -) - -// Validate options -func TestValidateLogOpt(t *testing.T) { - err := ValidateLogOpt(map[string]string{ - splunkURLKey: "http://127.0.0.1", - splunkTokenKey: "2160C7EF-2CE9-4307-A180-F852B99CF417", - splunkSourceKey: "mysource", - splunkSourceTypeKey: "mysourcetype", - splunkIndexKey: "myindex", - splunkCAPathKey: "/usr/cert.pem", - splunkCANameKey: "ca_name", - splunkInsecureSkipVerifyKey: "true", - splunkFormatKey: "json", - splunkVerifyConnectionKey: "true", - splunkGzipCompressionKey: "true", - splunkGzipCompressionLevelKey: "1", - envKey: "a", - labelsKey: "b", - tagKey: "c", - }) - if err != nil { - t.Fatal(err) - } - - err = ValidateLogOpt(map[string]string{ - "not-supported-option": "a", - }) - if err == nil { - t.Fatal("Expecting error on unsupported options") - } -} - -// Driver require user to specify required options -func TestNewMissedConfig(t *testing.T) { - ctx := logger.Context{ - Config: map[string]string{}, - } - _, err := New(ctx) - if err == nil { - t.Fatal("Logger driver should fail when no required parameters specified") - } -} - -// Driver require user to specify splunk-url -func TestNewMissedUrl(t *testing.T) { - ctx := logger.Context{ - Config: map[string]string{ - splunkTokenKey: "4642492F-D8BD-47F1-A005-0C08AE4657DF", - }, - } - _, err := New(ctx) - if err.Error() != "splunk: splunk-url is expected" { - t.Fatal("Logger driver should fail when no required parameters specified") - } -} - -// Driver require user to specify splunk-token -func TestNewMissedToken(t *testing.T) { - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: "http://127.0.0.1:8088", - }, - } - _, err := New(ctx) - if err.Error() != "splunk: splunk-token is expected" { - t.Fatal("Logger driver should fail when no required parameters specified") - } -} - -// Test default settings -func TestDefault(t *testing.T) { - hec := NewHTTPEventCollectorMock(t) - - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - }, - ContainerID: "containeriid", - ContainerName: "container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - hostname, err := ctx.Hostname() - if err != nil { - t.Fatal(err) - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - if loggerDriver.Name() != driverName { - t.Fatal("Unexpected logger driver name") - } - - if !hec.connectionVerified { - t.Fatal("By default connection should be verified") - } - - splunkLoggerDriver, ok := loggerDriver.(*splunkLoggerInline) - if !ok { - t.Fatal("Unexpected Splunk Logging Driver type") - } - - if splunkLoggerDriver.url != hec.URL()+"/services/collector/event/1.0" || - splunkLoggerDriver.auth != "Splunk "+hec.token || - splunkLoggerDriver.nullMessage.Host != hostname || - splunkLoggerDriver.nullMessage.Source != "" || - splunkLoggerDriver.nullMessage.SourceType != "" || - splunkLoggerDriver.nullMessage.Index != "" || - splunkLoggerDriver.gzipCompression != false || - splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || - splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || - splunkLoggerDriver.bufferMaximum != defaultBufferMaximum || - cap(splunkLoggerDriver.stream) != defaultStreamChannelSize { - t.Fatal("Found not default values setup in Splunk Logging Driver.") - } - - message1Time := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("{\"a\":\"b\"}"), "stdout", message1Time, nil, false}); err != nil { - t.Fatal(err) - } - message2Time := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("notajson"), "stdout", message2Time, nil, false}); err != nil { - t.Fatal(err) - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != 2 { - t.Fatal("Expected two messages") - } - - if *hec.gzipEnabled { - t.Fatal("Gzip should not be used") - } - - message1 := hec.messages[0] - if message1.Time != fmt.Sprintf("%f", float64(message1Time.UnixNano())/float64(time.Second)) || - message1.Host != hostname || - message1.Source != "" || - message1.SourceType != "" || - message1.Index != "" { - t.Fatalf("Unexpected values of message 1 %v", message1) - } - - if event, err := message1.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"] != "{\"a\":\"b\"}" || - event["source"] != "stdout" || - event["tag"] != "containeriid" || - len(event) != 3 { - t.Fatalf("Unexpected event in message %v", event) - } - } - - message2 := hec.messages[1] - if message2.Time != fmt.Sprintf("%f", float64(message2Time.UnixNano())/float64(time.Second)) || - message2.Host != hostname || - message2.Source != "" || - message2.SourceType != "" || - message2.Index != "" { - t.Fatalf("Unexpected values of message 1 %v", message2) - } - - if event, err := message2.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"] != "notajson" || - event["source"] != "stdout" || - event["tag"] != "containeriid" || - len(event) != 3 { - t.Fatalf("Unexpected event in message %v", event) - } - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } -} - -// Verify inline format with a not default settings for most of options -func TestInlineFormatWithNonDefaultOptions(t *testing.T) { - hec := NewHTTPEventCollectorMock(t) - - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - splunkSourceKey: "mysource", - splunkSourceTypeKey: "mysourcetype", - splunkIndexKey: "myindex", - splunkFormatKey: splunkFormatInline, - splunkGzipCompressionKey: "true", - tagKey: "{{.ImageName}}/{{.Name}}", - labelsKey: "a", - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - ContainerLabels: map[string]string{ - "a": "b", - }, - } - - hostname, err := ctx.Hostname() - if err != nil { - t.Fatal(err) - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - if !hec.connectionVerified { - t.Fatal("By default connection should be verified") - } - - splunkLoggerDriver, ok := loggerDriver.(*splunkLoggerInline) - if !ok { - t.Fatal("Unexpected Splunk Logging Driver type") - } - - if splunkLoggerDriver.url != hec.URL()+"/services/collector/event/1.0" || - splunkLoggerDriver.auth != "Splunk "+hec.token || - splunkLoggerDriver.nullMessage.Host != hostname || - splunkLoggerDriver.nullMessage.Source != "mysource" || - splunkLoggerDriver.nullMessage.SourceType != "mysourcetype" || - splunkLoggerDriver.nullMessage.Index != "myindex" || - splunkLoggerDriver.gzipCompression != true || - splunkLoggerDriver.gzipCompressionLevel != gzip.DefaultCompression || - splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || - splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || - splunkLoggerDriver.bufferMaximum != defaultBufferMaximum || - cap(splunkLoggerDriver.stream) != defaultStreamChannelSize { - t.Fatal("Values do not match configuration.") - } - - messageTime := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("1"), "stdout", messageTime, nil, false}); err != nil { - t.Fatal(err) - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != 1 { - t.Fatal("Expected one message") - } - - if !*hec.gzipEnabled { - t.Fatal("Gzip should be used") - } - - message := hec.messages[0] - if message.Time != fmt.Sprintf("%f", float64(messageTime.UnixNano())/float64(time.Second)) || - message.Host != hostname || - message.Source != "mysource" || - message.SourceType != "mysourcetype" || - message.Index != "myindex" { - t.Fatalf("Unexpected values of message %v", message) - } - - if event, err := message.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"] != "1" || - event["source"] != "stdout" || - event["tag"] != "container_image_name/container_name" || - event["attrs"].(map[string]interface{})["a"] != "b" || - len(event) != 4 { - t.Fatalf("Unexpected event in message %v", event) - } - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } -} - -// Verify JSON format -func TestJsonFormat(t *testing.T) { - hec := NewHTTPEventCollectorMock(t) - - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - splunkFormatKey: splunkFormatJSON, - splunkGzipCompressionKey: "true", - splunkGzipCompressionLevelKey: "1", - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - hostname, err := ctx.Hostname() - if err != nil { - t.Fatal(err) - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - if !hec.connectionVerified { - t.Fatal("By default connection should be verified") - } - - splunkLoggerDriver, ok := loggerDriver.(*splunkLoggerJSON) - if !ok { - t.Fatal("Unexpected Splunk Logging Driver type") - } - - if splunkLoggerDriver.url != hec.URL()+"/services/collector/event/1.0" || - splunkLoggerDriver.auth != "Splunk "+hec.token || - splunkLoggerDriver.nullMessage.Host != hostname || - splunkLoggerDriver.nullMessage.Source != "" || - splunkLoggerDriver.nullMessage.SourceType != "" || - splunkLoggerDriver.nullMessage.Index != "" || - splunkLoggerDriver.gzipCompression != true || - splunkLoggerDriver.gzipCompressionLevel != gzip.BestSpeed || - splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || - splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || - splunkLoggerDriver.bufferMaximum != defaultBufferMaximum || - cap(splunkLoggerDriver.stream) != defaultStreamChannelSize { - t.Fatal("Values do not match configuration.") - } - - message1Time := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("{\"a\":\"b\"}"), "stdout", message1Time, nil, false}); err != nil { - t.Fatal(err) - } - message2Time := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("notjson"), "stdout", message2Time, nil, false}); err != nil { - t.Fatal(err) - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != 2 { - t.Fatal("Expected two messages") - } - - message1 := hec.messages[0] - if message1.Time != fmt.Sprintf("%f", float64(message1Time.UnixNano())/float64(time.Second)) || - message1.Host != hostname || - message1.Source != "" || - message1.SourceType != "" || - message1.Index != "" { - t.Fatalf("Unexpected values of message 1 %v", message1) - } - - if event, err := message1.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"].(map[string]interface{})["a"] != "b" || - event["source"] != "stdout" || - event["tag"] != "containeriid" || - len(event) != 3 { - t.Fatalf("Unexpected event in message 1 %v", event) - } - } - - message2 := hec.messages[1] - if message2.Time != fmt.Sprintf("%f", float64(message2Time.UnixNano())/float64(time.Second)) || - message2.Host != hostname || - message2.Source != "" || - message2.SourceType != "" || - message2.Index != "" { - t.Fatalf("Unexpected values of message 2 %v", message2) - } - - // If message cannot be parsed as JSON - it should be sent as a line - if event, err := message2.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"] != "notjson" || - event["source"] != "stdout" || - event["tag"] != "containeriid" || - len(event) != 3 { - t.Fatalf("Unexpected event in message 2 %v", event) - } - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } -} - -// Verify raw format -func TestRawFormat(t *testing.T) { - hec := NewHTTPEventCollectorMock(t) - - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - splunkFormatKey: splunkFormatRaw, - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - hostname, err := ctx.Hostname() - if err != nil { - t.Fatal(err) - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - if !hec.connectionVerified { - t.Fatal("By default connection should be verified") - } - - splunkLoggerDriver, ok := loggerDriver.(*splunkLoggerRaw) - if !ok { - t.Fatal("Unexpected Splunk Logging Driver type") - } - - if splunkLoggerDriver.url != hec.URL()+"/services/collector/event/1.0" || - splunkLoggerDriver.auth != "Splunk "+hec.token || - splunkLoggerDriver.nullMessage.Host != hostname || - splunkLoggerDriver.nullMessage.Source != "" || - splunkLoggerDriver.nullMessage.SourceType != "" || - splunkLoggerDriver.nullMessage.Index != "" || - splunkLoggerDriver.gzipCompression != false || - splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || - splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || - splunkLoggerDriver.bufferMaximum != defaultBufferMaximum || - cap(splunkLoggerDriver.stream) != defaultStreamChannelSize || - string(splunkLoggerDriver.prefix) != "containeriid " { - t.Fatal("Values do not match configuration.") - } - - message1Time := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("{\"a\":\"b\"}"), "stdout", message1Time, nil, false}); err != nil { - t.Fatal(err) - } - message2Time := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("notjson"), "stdout", message2Time, nil, false}); err != nil { - t.Fatal(err) - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != 2 { - t.Fatal("Expected two messages") - } - - message1 := hec.messages[0] - if message1.Time != fmt.Sprintf("%f", float64(message1Time.UnixNano())/float64(time.Second)) || - message1.Host != hostname || - message1.Source != "" || - message1.SourceType != "" || - message1.Index != "" { - t.Fatalf("Unexpected values of message 1 %v", message1) - } - - if event, err := message1.EventAsString(); err != nil { - t.Fatal(err) - } else { - if event != "containeriid {\"a\":\"b\"}" { - t.Fatalf("Unexpected event in message 1 %v", event) - } - } - - message2 := hec.messages[1] - if message2.Time != fmt.Sprintf("%f", float64(message2Time.UnixNano())/float64(time.Second)) || - message2.Host != hostname || - message2.Source != "" || - message2.SourceType != "" || - message2.Index != "" { - t.Fatalf("Unexpected values of message 2 %v", message2) - } - - if event, err := message2.EventAsString(); err != nil { - t.Fatal(err) - } else { - if event != "containeriid notjson" { - t.Fatalf("Unexpected event in message 1 %v", event) - } - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } -} - -// Verify raw format with labels -func TestRawFormatWithLabels(t *testing.T) { - hec := NewHTTPEventCollectorMock(t) - - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - splunkFormatKey: splunkFormatRaw, - labelsKey: "a", - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - ContainerLabels: map[string]string{ - "a": "b", - }, - } - - hostname, err := ctx.Hostname() - if err != nil { - t.Fatal(err) - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - if !hec.connectionVerified { - t.Fatal("By default connection should be verified") - } - - splunkLoggerDriver, ok := loggerDriver.(*splunkLoggerRaw) - if !ok { - t.Fatal("Unexpected Splunk Logging Driver type") - } - - if splunkLoggerDriver.url != hec.URL()+"/services/collector/event/1.0" || - splunkLoggerDriver.auth != "Splunk "+hec.token || - splunkLoggerDriver.nullMessage.Host != hostname || - splunkLoggerDriver.nullMessage.Source != "" || - splunkLoggerDriver.nullMessage.SourceType != "" || - splunkLoggerDriver.nullMessage.Index != "" || - splunkLoggerDriver.gzipCompression != false || - splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || - splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || - splunkLoggerDriver.bufferMaximum != defaultBufferMaximum || - cap(splunkLoggerDriver.stream) != defaultStreamChannelSize || - string(splunkLoggerDriver.prefix) != "containeriid a=b " { - t.Fatal("Values do not match configuration.") - } - - message1Time := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("{\"a\":\"b\"}"), "stdout", message1Time, nil, false}); err != nil { - t.Fatal(err) - } - message2Time := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("notjson"), "stdout", message2Time, nil, false}); err != nil { - t.Fatal(err) - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != 2 { - t.Fatal("Expected two messages") - } - - message1 := hec.messages[0] - if message1.Time != fmt.Sprintf("%f", float64(message1Time.UnixNano())/float64(time.Second)) || - message1.Host != hostname || - message1.Source != "" || - message1.SourceType != "" || - message1.Index != "" { - t.Fatalf("Unexpected values of message 1 %v", message1) - } - - if event, err := message1.EventAsString(); err != nil { - t.Fatal(err) - } else { - if event != "containeriid a=b {\"a\":\"b\"}" { - t.Fatalf("Unexpected event in message 1 %v", event) - } - } - - message2 := hec.messages[1] - if message2.Time != fmt.Sprintf("%f", float64(message2Time.UnixNano())/float64(time.Second)) || - message2.Host != hostname || - message2.Source != "" || - message2.SourceType != "" || - message2.Index != "" { - t.Fatalf("Unexpected values of message 2 %v", message2) - } - - if event, err := message2.EventAsString(); err != nil { - t.Fatal(err) - } else { - if event != "containeriid a=b notjson" { - t.Fatalf("Unexpected event in message 1 %v", event) - } - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } -} - -// Verify that Splunk Logging Driver can accept tag="" which will allow to send raw messages -// in the same way we get them in stdout/stderr -func TestRawFormatWithoutTag(t *testing.T) { - hec := NewHTTPEventCollectorMock(t) - - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - splunkFormatKey: splunkFormatRaw, - tagKey: "", - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - hostname, err := ctx.Hostname() - if err != nil { - t.Fatal(err) - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - if !hec.connectionVerified { - t.Fatal("By default connection should be verified") - } - - splunkLoggerDriver, ok := loggerDriver.(*splunkLoggerRaw) - if !ok { - t.Fatal("Unexpected Splunk Logging Driver type") - } - - if splunkLoggerDriver.url != hec.URL()+"/services/collector/event/1.0" || - splunkLoggerDriver.auth != "Splunk "+hec.token || - splunkLoggerDriver.nullMessage.Host != hostname || - splunkLoggerDriver.nullMessage.Source != "" || - splunkLoggerDriver.nullMessage.SourceType != "" || - splunkLoggerDriver.nullMessage.Index != "" || - splunkLoggerDriver.gzipCompression != false || - splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || - splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || - splunkLoggerDriver.bufferMaximum != defaultBufferMaximum || - cap(splunkLoggerDriver.stream) != defaultStreamChannelSize || - string(splunkLoggerDriver.prefix) != "" { - t.Log(string(splunkLoggerDriver.prefix) + "a") - t.Fatal("Values do not match configuration.") - } - - message1Time := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("{\"a\":\"b\"}"), "stdout", message1Time, nil, false}); err != nil { - t.Fatal(err) - } - message2Time := time.Now() - if err := loggerDriver.Log(&logger.Message{[]byte("notjson"), "stdout", message2Time, nil, false}); err != nil { - t.Fatal(err) - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != 2 { - t.Fatal("Expected two messages") - } - - message1 := hec.messages[0] - if message1.Time != fmt.Sprintf("%f", float64(message1Time.UnixNano())/float64(time.Second)) || - message1.Host != hostname || - message1.Source != "" || - message1.SourceType != "" || - message1.Index != "" { - t.Fatalf("Unexpected values of message 1 %v", message1) - } - - if event, err := message1.EventAsString(); err != nil { - t.Fatal(err) - } else { - if event != "{\"a\":\"b\"}" { - t.Fatalf("Unexpected event in message 1 %v", event) - } - } - - message2 := hec.messages[1] - if message2.Time != fmt.Sprintf("%f", float64(message2Time.UnixNano())/float64(time.Second)) || - message2.Host != hostname || - message2.Source != "" || - message2.SourceType != "" || - message2.Index != "" { - t.Fatalf("Unexpected values of message 2 %v", message2) - } - - if event, err := message2.EventAsString(); err != nil { - t.Fatal(err) - } else { - if event != "notjson" { - t.Fatalf("Unexpected event in message 1 %v", event) - } - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } -} - -// Verify that we will send messages in batches with default batching parameters, -// but change frequency to be sure that numOfRequests will match expected 17 requests -func TestBatching(t *testing.T) { - if err := os.Setenv(envVarPostMessagesFrequency, "10h"); err != nil { - t.Fatal(err) - } - - hec := NewHTTPEventCollectorMock(t) - - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - for i := 0; i < defaultStreamChannelSize*4; i++ { - if err := loggerDriver.Log(&logger.Message{[]byte(fmt.Sprintf("%d", i)), "stdout", time.Now(), nil, false}); err != nil { - t.Fatal(err) - } - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != defaultStreamChannelSize*4 { - t.Fatal("Not all messages delivered") - } - - for i, message := range hec.messages { - if event, err := message.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"] != fmt.Sprintf("%d", i) { - t.Fatalf("Unexpected event in message %v", event) - } - } - } - - // 1 to verify connection and 16 batches - if hec.numOfRequests != 17 { - t.Fatalf("Unexpected number of requests %d", hec.numOfRequests) - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarPostMessagesFrequency, ""); err != nil { - t.Fatal(err) - } -} - -// Verify that test is using time to fire events not rare than specified frequency -func TestFrequency(t *testing.T) { - if err := os.Setenv(envVarPostMessagesFrequency, "5ms"); err != nil { - t.Fatal(err) - } - - hec := NewHTTPEventCollectorMock(t) - - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - for i := 0; i < 10; i++ { - if err := loggerDriver.Log(&logger.Message{[]byte(fmt.Sprintf("%d", i)), "stdout", time.Now(), nil, false}); err != nil { - t.Fatal(err) - } - time.Sleep(15 * time.Millisecond) - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != 10 { - t.Fatal("Not all messages delivered") - } - - for i, message := range hec.messages { - if event, err := message.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"] != fmt.Sprintf("%d", i) { - t.Fatalf("Unexpected event in message %v", event) - } - } - } - - // 1 to verify connection and 10 to verify that we have sent messages with required frequency, - // but because frequency is too small (to keep test quick), instead of 11, use 9 if context switches will be slow - if hec.numOfRequests < 9 { - t.Fatalf("Unexpected number of requests %d", hec.numOfRequests) - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarPostMessagesFrequency, ""); err != nil { - t.Fatal(err) - } -} - -// Simulate behavior similar to first version of Splunk Logging Driver, when we were sending one message -// per request -func TestOneMessagePerRequest(t *testing.T) { - if err := os.Setenv(envVarPostMessagesFrequency, "10h"); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarPostMessagesBatchSize, "1"); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarBufferMaximum, "1"); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarStreamChannelSize, "0"); err != nil { - t.Fatal(err) - } - - hec := NewHTTPEventCollectorMock(t) - - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - for i := 0; i < 10; i++ { - if err := loggerDriver.Log(&logger.Message{[]byte(fmt.Sprintf("%d", i)), "stdout", time.Now(), nil, false}); err != nil { - t.Fatal(err) - } - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != 10 { - t.Fatal("Not all messages delivered") - } - - for i, message := range hec.messages { - if event, err := message.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"] != fmt.Sprintf("%d", i) { - t.Fatalf("Unexpected event in message %v", event) - } - } - } - - // 1 to verify connection and 10 messages - if hec.numOfRequests != 11 { - t.Fatalf("Unexpected number of requests %d", hec.numOfRequests) - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarPostMessagesFrequency, ""); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarPostMessagesBatchSize, ""); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarBufferMaximum, ""); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarStreamChannelSize, ""); err != nil { - t.Fatal(err) - } -} - -// Driver should not be created when HEC is unresponsive -func TestVerify(t *testing.T) { - hec := NewHTTPEventCollectorMock(t) - hec.simulateServerError = true - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - _, err := New(ctx) - if err == nil { - t.Fatal("Expecting driver to fail, when server is unresponsive") - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } -} - -// Verify that user can specify to skip verification that Splunk HEC is working. -// Also in this test we verify retry logic. -func TestSkipVerify(t *testing.T) { - hec := NewHTTPEventCollectorMock(t) - hec.simulateServerError = true - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - splunkVerifyConnectionKey: "false", - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - if hec.connectionVerified { - t.Fatal("Connection should not be verified") - } - - for i := 0; i < defaultStreamChannelSize*2; i++ { - if err := loggerDriver.Log(&logger.Message{[]byte(fmt.Sprintf("%d", i)), "stdout", time.Now(), nil, false}); err != nil { - t.Fatal(err) - } - } - - if len(hec.messages) != 0 { - t.Fatal("No messages should be accepted at this point") - } - - hec.simulateServerError = false - - for i := defaultStreamChannelSize * 2; i < defaultStreamChannelSize*4; i++ { - if err := loggerDriver.Log(&logger.Message{[]byte(fmt.Sprintf("%d", i)), "stdout", time.Now(), nil, false}); err != nil { - t.Fatal(err) - } - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != defaultStreamChannelSize*4 { - t.Fatal("Not all messages delivered") - } - - for i, message := range hec.messages { - if event, err := message.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"] != fmt.Sprintf("%d", i) { - t.Fatalf("Unexpected event in message %v", event) - } - } - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } -} - -// Verify logic for when we filled whole buffer -func TestBufferMaximum(t *testing.T) { - if err := os.Setenv(envVarPostMessagesBatchSize, "2"); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarBufferMaximum, "10"); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarStreamChannelSize, "0"); err != nil { - t.Fatal(err) - } - - hec := NewHTTPEventCollectorMock(t) - hec.simulateServerError = true - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - splunkVerifyConnectionKey: "false", - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - if hec.connectionVerified { - t.Fatal("Connection should not be verified") - } - - for i := 0; i < 11; i++ { - if err := loggerDriver.Log(&logger.Message{[]byte(fmt.Sprintf("%d", i)), "stdout", time.Now(), nil, false}); err != nil { - t.Fatal(err) - } - } - - if len(hec.messages) != 0 { - t.Fatal("No messages should be accepted at this point") - } - - hec.simulateServerError = false - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != 9 { - t.Fatalf("Expected # of messages %d, got %d", 9, len(hec.messages)) - } - - // First 1000 messages are written to daemon log when buffer was full - for i, message := range hec.messages { - if event, err := message.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"] != fmt.Sprintf("%d", i+2) { - t.Fatalf("Unexpected event in message %v", event) - } - } - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarPostMessagesBatchSize, ""); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarBufferMaximum, ""); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarStreamChannelSize, ""); err != nil { - t.Fatal(err) - } -} - -// Verify that we are not blocking close when HEC is down for the whole time -func TestServerAlwaysDown(t *testing.T) { - if err := os.Setenv(envVarPostMessagesBatchSize, "2"); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarBufferMaximum, "4"); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarStreamChannelSize, "0"); err != nil { - t.Fatal(err) - } - - hec := NewHTTPEventCollectorMock(t) - hec.simulateServerError = true - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - splunkVerifyConnectionKey: "false", - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - if hec.connectionVerified { - t.Fatal("Connection should not be verified") - } - - for i := 0; i < 5; i++ { - if err := loggerDriver.Log(&logger.Message{[]byte(fmt.Sprintf("%d", i)), "stdout", time.Now(), nil, false}); err != nil { - t.Fatal(err) - } - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if len(hec.messages) != 0 { - t.Fatal("No messages should be sent") - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarPostMessagesBatchSize, ""); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarBufferMaximum, ""); err != nil { - t.Fatal(err) - } - - if err := os.Setenv(envVarStreamChannelSize, ""); err != nil { - t.Fatal(err) - } -} - -// Cannot send messages after we close driver -func TestCannotSendAfterClose(t *testing.T) { - hec := NewHTTPEventCollectorMock(t) - go hec.Serve() - - ctx := logger.Context{ - Config: map[string]string{ - splunkURLKey: hec.URL(), - splunkTokenKey: hec.token, - }, - ContainerID: "containeriid", - ContainerName: "/container_name", - ContainerImageID: "contaimageid", - ContainerImageName: "container_image_name", - } - - loggerDriver, err := New(ctx) - if err != nil { - t.Fatal(err) - } - - if err := loggerDriver.Log(&logger.Message{[]byte("message1"), "stdout", time.Now(), nil, false}); err != nil { - t.Fatal(err) - } - - err = loggerDriver.Close() - if err != nil { - t.Fatal(err) - } - - if err := loggerDriver.Log(&logger.Message{[]byte("message2"), "stdout", time.Now(), nil, false}); err == nil { - t.Fatal("Driver should not allow to send messages after close") - } - - if len(hec.messages) != 1 { - t.Fatal("Only one message should be sent") - } - - message := hec.messages[0] - if event, err := message.EventAsMap(); err != nil { - t.Fatal(err) - } else { - if event["line"] != "message1" { - t.Fatalf("Unexpected event in message %v", event) - } - } - - err = hec.Close() - if err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/daemon/logger/splunk/splunkhecmock_test.go b/vendor/github.com/docker/docker/daemon/logger/splunk/splunkhecmock_test.go deleted file mode 100644 index e508948..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/splunk/splunkhecmock_test.go +++ /dev/null @@ -1,157 +0,0 @@ -package splunk - -import ( - "compress/gzip" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "testing" -) - -func (message *splunkMessage) EventAsString() (string, error) { - if val, ok := message.Event.(string); ok { - return val, nil - } - return "", fmt.Errorf("Cannot cast Event %v to string", message.Event) -} - -func (message *splunkMessage) EventAsMap() (map[string]interface{}, error) { - if val, ok := message.Event.(map[string]interface{}); ok { - return val, nil - } - return nil, fmt.Errorf("Cannot cast Event %v to map", message.Event) -} - -type HTTPEventCollectorMock struct { - tcpAddr *net.TCPAddr - tcpListener *net.TCPListener - - token string - simulateServerError bool - - test *testing.T - - connectionVerified bool - gzipEnabled *bool - messages []*splunkMessage - numOfRequests int -} - -func NewHTTPEventCollectorMock(t *testing.T) *HTTPEventCollectorMock { - tcpAddr := &net.TCPAddr{IP: []byte{127, 0, 0, 1}, Port: 0, Zone: ""} - tcpListener, err := net.ListenTCP("tcp", tcpAddr) - if err != nil { - t.Fatal(err) - } - return &HTTPEventCollectorMock{ - tcpAddr: tcpAddr, - tcpListener: tcpListener, - token: "4642492F-D8BD-47F1-A005-0C08AE4657DF", - simulateServerError: false, - test: t, - connectionVerified: false} -} - -func (hec *HTTPEventCollectorMock) URL() string { - return "http://" + hec.tcpListener.Addr().String() -} - -func (hec *HTTPEventCollectorMock) Serve() error { - return http.Serve(hec.tcpListener, hec) -} - -func (hec *HTTPEventCollectorMock) Close() error { - return hec.tcpListener.Close() -} - -func (hec *HTTPEventCollectorMock) ServeHTTP(writer http.ResponseWriter, request *http.Request) { - var err error - - hec.numOfRequests++ - - if hec.simulateServerError { - if request.Body != nil { - defer request.Body.Close() - } - writer.WriteHeader(http.StatusInternalServerError) - return - } - - switch request.Method { - case http.MethodOptions: - // Verify that options method is getting called only once - if hec.connectionVerified { - hec.test.Errorf("Connection should not be verified more than once. Got second request with %s method.", request.Method) - } - hec.connectionVerified = true - writer.WriteHeader(http.StatusOK) - case http.MethodPost: - // Always verify that Driver is using correct path to HEC - if request.URL.String() != "/services/collector/event/1.0" { - hec.test.Errorf("Unexpected path %v", request.URL) - } - defer request.Body.Close() - - if authorization, ok := request.Header["Authorization"]; !ok || authorization[0] != ("Splunk "+hec.token) { - hec.test.Error("Authorization header is invalid.") - } - - gzipEnabled := false - if contentEncoding, ok := request.Header["Content-Encoding"]; ok && contentEncoding[0] == "gzip" { - gzipEnabled = true - } - - if hec.gzipEnabled == nil { - hec.gzipEnabled = &gzipEnabled - } else if gzipEnabled != *hec.gzipEnabled { - // Nothing wrong with that, but we just know that Splunk Logging Driver does not do that - hec.test.Error("Driver should not change Content Encoding.") - } - - var gzipReader *gzip.Reader - var reader io.Reader - if gzipEnabled { - gzipReader, err = gzip.NewReader(request.Body) - if err != nil { - hec.test.Fatal(err) - } - reader = gzipReader - } else { - reader = request.Body - } - - // Read body - var body []byte - body, err = ioutil.ReadAll(reader) - if err != nil { - hec.test.Fatal(err) - } - - // Parse message - messageStart := 0 - for i := 0; i < len(body); i++ { - if i == len(body)-1 || (body[i] == '}' && body[i+1] == '{') { - var message splunkMessage - err = json.Unmarshal(body[messageStart:i+1], &message) - if err != nil { - hec.test.Log(string(body[messageStart : i+1])) - hec.test.Fatal(err) - } - hec.messages = append(hec.messages, &message) - messageStart = i + 1 - } - } - - if gzipEnabled { - gzipReader.Close() - } - - writer.WriteHeader(http.StatusOK) - default: - hec.test.Errorf("Unexpected HTTP method %s", http.MethodOptions) - writer.WriteHeader(http.StatusBadRequest) - } -} diff --git a/vendor/github.com/docker/docker/daemon/logger/syslog/syslog.go b/vendor/github.com/docker/docker/daemon/logger/syslog/syslog.go deleted file mode 100644 index fb9e867..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/syslog/syslog.go +++ /dev/null @@ -1,262 +0,0 @@ -// Package syslog provides the logdriver for forwarding server logs to syslog endpoints. -package syslog - -import ( - "crypto/tls" - "errors" - "fmt" - "net" - "net/url" - "os" - "strconv" - "strings" - "time" - - syslog "github.com/RackSec/srslog" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/daemon/logger/loggerutils" - "github.com/docker/docker/pkg/urlutil" - "github.com/docker/go-connections/tlsconfig" -) - -const ( - name = "syslog" - secureProto = "tcp+tls" -) - -var facilities = map[string]syslog.Priority{ - "kern": syslog.LOG_KERN, - "user": syslog.LOG_USER, - "mail": syslog.LOG_MAIL, - "daemon": syslog.LOG_DAEMON, - "auth": syslog.LOG_AUTH, - "syslog": syslog.LOG_SYSLOG, - "lpr": syslog.LOG_LPR, - "news": syslog.LOG_NEWS, - "uucp": syslog.LOG_UUCP, - "cron": syslog.LOG_CRON, - "authpriv": syslog.LOG_AUTHPRIV, - "ftp": syslog.LOG_FTP, - "local0": syslog.LOG_LOCAL0, - "local1": syslog.LOG_LOCAL1, - "local2": syslog.LOG_LOCAL2, - "local3": syslog.LOG_LOCAL3, - "local4": syslog.LOG_LOCAL4, - "local5": syslog.LOG_LOCAL5, - "local6": syslog.LOG_LOCAL6, - "local7": syslog.LOG_LOCAL7, -} - -type syslogger struct { - writer *syslog.Writer -} - -func init() { - if err := logger.RegisterLogDriver(name, New); err != nil { - logrus.Fatal(err) - } - if err := logger.RegisterLogOptValidator(name, ValidateLogOpt); err != nil { - logrus.Fatal(err) - } -} - -// rsyslog uses appname part of syslog message to fill in an %syslogtag% template -// attribute in rsyslog.conf. In order to be backward compatible to rfc3164 -// tag will be also used as an appname -func rfc5424formatterWithAppNameAsTag(p syslog.Priority, hostname, tag, content string) string { - timestamp := time.Now().Format(time.RFC3339) - pid := os.Getpid() - msg := fmt.Sprintf("<%d>%d %s %s %s %d %s %s", - p, 1, timestamp, hostname, tag, pid, tag, content) - return msg -} - -// The timestamp field in rfc5424 is derived from rfc3339. Whereas rfc3339 makes allowances -// for multiple syntaxes, there are further restrictions in rfc5424, i.e., the maximium -// resolution is limited to "TIME-SECFRAC" which is 6 (microsecond resolution) -func rfc5424microformatterWithAppNameAsTag(p syslog.Priority, hostname, tag, content string) string { - timestamp := time.Now().Format("2006-01-02T15:04:05.999999Z07:00") - pid := os.Getpid() - msg := fmt.Sprintf("<%d>%d %s %s %s %d %s %s", - p, 1, timestamp, hostname, tag, pid, tag, content) - return msg -} - -// New creates a syslog logger using the configuration passed in on -// the context. Supported context configuration variables are -// syslog-address, syslog-facility, syslog-format. -func New(ctx logger.Context) (logger.Logger, error) { - tag, err := loggerutils.ParseLogTag(ctx, loggerutils.DefaultTemplate) - if err != nil { - return nil, err - } - - proto, address, err := parseAddress(ctx.Config["syslog-address"]) - if err != nil { - return nil, err - } - - facility, err := parseFacility(ctx.Config["syslog-facility"]) - if err != nil { - return nil, err - } - - syslogFormatter, syslogFramer, err := parseLogFormat(ctx.Config["syslog-format"], proto) - if err != nil { - return nil, err - } - - var log *syslog.Writer - if proto == secureProto { - tlsConfig, tlsErr := parseTLSConfig(ctx.Config) - if tlsErr != nil { - return nil, tlsErr - } - log, err = syslog.DialWithTLSConfig(proto, address, facility, tag, tlsConfig) - } else { - log, err = syslog.Dial(proto, address, facility, tag) - } - - if err != nil { - return nil, err - } - - log.SetFormatter(syslogFormatter) - log.SetFramer(syslogFramer) - - return &syslogger{ - writer: log, - }, nil -} - -func (s *syslogger) Log(msg *logger.Message) error { - if msg.Source == "stderr" { - return s.writer.Err(string(msg.Line)) - } - return s.writer.Info(string(msg.Line)) -} - -func (s *syslogger) Close() error { - return s.writer.Close() -} - -func (s *syslogger) Name() string { - return name -} - -func parseAddress(address string) (string, string, error) { - if address == "" { - return "", "", nil - } - if !urlutil.IsTransportURL(address) { - return "", "", fmt.Errorf("syslog-address should be in form proto://address, got %v", address) - } - url, err := url.Parse(address) - if err != nil { - return "", "", err - } - - // unix and unixgram socket validation - if url.Scheme == "unix" || url.Scheme == "unixgram" { - if _, err := os.Stat(url.Path); err != nil { - return "", "", err - } - return url.Scheme, url.Path, nil - } - - // here we process tcp|udp - host := url.Host - if _, _, err := net.SplitHostPort(host); err != nil { - if !strings.Contains(err.Error(), "missing port in address") { - return "", "", err - } - host = host + ":514" - } - - return url.Scheme, host, nil -} - -// ValidateLogOpt looks for syslog specific log options -// syslog-address, syslog-facility. -func ValidateLogOpt(cfg map[string]string) error { - for key := range cfg { - switch key { - case "env": - case "labels": - case "syslog-address": - case "syslog-facility": - case "syslog-tls-ca-cert": - case "syslog-tls-cert": - case "syslog-tls-key": - case "syslog-tls-skip-verify": - case "tag": - case "syslog-format": - default: - return fmt.Errorf("unknown log opt '%s' for syslog log driver", key) - } - } - if _, _, err := parseAddress(cfg["syslog-address"]); err != nil { - return err - } - if _, err := parseFacility(cfg["syslog-facility"]); err != nil { - return err - } - if _, _, err := parseLogFormat(cfg["syslog-format"], ""); err != nil { - return err - } - return nil -} - -func parseFacility(facility string) (syslog.Priority, error) { - if facility == "" { - return syslog.LOG_DAEMON, nil - } - - if syslogFacility, valid := facilities[facility]; valid { - return syslogFacility, nil - } - - fInt, err := strconv.Atoi(facility) - if err == nil && 0 <= fInt && fInt <= 23 { - return syslog.Priority(fInt << 3), nil - } - - return syslog.Priority(0), errors.New("invalid syslog facility") -} - -func parseTLSConfig(cfg map[string]string) (*tls.Config, error) { - _, skipVerify := cfg["syslog-tls-skip-verify"] - - opts := tlsconfig.Options{ - CAFile: cfg["syslog-tls-ca-cert"], - CertFile: cfg["syslog-tls-cert"], - KeyFile: cfg["syslog-tls-key"], - InsecureSkipVerify: skipVerify, - } - - return tlsconfig.Client(opts) -} - -func parseLogFormat(logFormat, proto string) (syslog.Formatter, syslog.Framer, error) { - switch logFormat { - case "": - return syslog.UnixFormatter, syslog.DefaultFramer, nil - case "rfc3164": - return syslog.RFC3164Formatter, syslog.DefaultFramer, nil - case "rfc5424": - if proto == secureProto { - return rfc5424formatterWithAppNameAsTag, syslog.RFC5425MessageLengthFramer, nil - } - return rfc5424formatterWithAppNameAsTag, syslog.DefaultFramer, nil - case "rfc5424micro": - if proto == secureProto { - return rfc5424microformatterWithAppNameAsTag, syslog.RFC5425MessageLengthFramer, nil - } - return rfc5424microformatterWithAppNameAsTag, syslog.DefaultFramer, nil - default: - return nil, nil, errors.New("Invalid syslog format") - } - -} diff --git a/vendor/github.com/docker/docker/daemon/logger/syslog/syslog_test.go b/vendor/github.com/docker/docker/daemon/logger/syslog/syslog_test.go deleted file mode 100644 index 5015610..0000000 --- a/vendor/github.com/docker/docker/daemon/logger/syslog/syslog_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package syslog - -import ( - "reflect" - "testing" - - syslog "github.com/RackSec/srslog" -) - -func functionMatches(expectedFun interface{}, actualFun interface{}) bool { - return reflect.ValueOf(expectedFun).Pointer() == reflect.ValueOf(actualFun).Pointer() -} - -func TestParseLogFormat(t *testing.T) { - formatter, framer, err := parseLogFormat("rfc5424", "udp") - if err != nil || !functionMatches(rfc5424formatterWithAppNameAsTag, formatter) || - !functionMatches(syslog.DefaultFramer, framer) { - t.Fatal("Failed to parse rfc5424 format", err, formatter, framer) - } - - formatter, framer, err = parseLogFormat("rfc5424", "tcp+tls") - if err != nil || !functionMatches(rfc5424formatterWithAppNameAsTag, formatter) || - !functionMatches(syslog.RFC5425MessageLengthFramer, framer) { - t.Fatal("Failed to parse rfc5424 format", err, formatter, framer) - } - - formatter, framer, err = parseLogFormat("rfc5424micro", "udp") - if err != nil || !functionMatches(rfc5424microformatterWithAppNameAsTag, formatter) || - !functionMatches(syslog.DefaultFramer, framer) { - t.Fatal("Failed to parse rfc5424 (microsecond) format", err, formatter, framer) - } - - formatter, framer, err = parseLogFormat("rfc5424micro", "tcp+tls") - if err != nil || !functionMatches(rfc5424microformatterWithAppNameAsTag, formatter) || - !functionMatches(syslog.RFC5425MessageLengthFramer, framer) { - t.Fatal("Failed to parse rfc5424 (microsecond) format", err, formatter, framer) - } - - formatter, framer, err = parseLogFormat("rfc3164", "") - if err != nil || !functionMatches(syslog.RFC3164Formatter, formatter) || - !functionMatches(syslog.DefaultFramer, framer) { - t.Fatal("Failed to parse rfc3164 format", err, formatter, framer) - } - - formatter, framer, err = parseLogFormat("", "") - if err != nil || !functionMatches(syslog.UnixFormatter, formatter) || - !functionMatches(syslog.DefaultFramer, framer) { - t.Fatal("Failed to parse empty format", err, formatter, framer) - } - - formatter, framer, err = parseLogFormat("invalid", "") - if err == nil { - t.Fatal("Failed to parse invalid format", err, formatter, framer) - } -} - -func TestValidateLogOptEmpty(t *testing.T) { - emptyConfig := make(map[string]string) - if err := ValidateLogOpt(emptyConfig); err != nil { - t.Fatal("Failed to parse empty config", err) - } -} diff --git a/vendor/github.com/docker/docker/daemon/logs.go b/vendor/github.com/docker/docker/daemon/logs.go deleted file mode 100644 index cc34b82..0000000 --- a/vendor/github.com/docker/docker/daemon/logs.go +++ /dev/null @@ -1,142 +0,0 @@ -package daemon - -import ( - "fmt" - "io" - "strconv" - "time" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types/backend" - containertypes "github.com/docker/docker/api/types/container" - timetypes "github.com/docker/docker/api/types/time" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/logger" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/stdcopy" -) - -// ContainerLogs hooks up a container's stdout and stderr streams -// configured with the given struct. -func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, config *backend.ContainerLogsConfig, started chan struct{}) error { - container, err := daemon.GetContainer(containerName) - if err != nil { - return err - } - - if !(config.ShowStdout || config.ShowStderr) { - return fmt.Errorf("You must choose at least one stream") - } - - cLog, err := daemon.getLogger(container) - if err != nil { - return err - } - logReader, ok := cLog.(logger.LogReader) - if !ok { - return logger.ErrReadLogsNotSupported - } - - follow := config.Follow && container.IsRunning() - tailLines, err := strconv.Atoi(config.Tail) - if err != nil { - tailLines = -1 - } - - logrus.Debug("logs: begin stream") - - var since time.Time - if config.Since != "" { - s, n, err := timetypes.ParseTimestamps(config.Since, 0) - if err != nil { - return err - } - since = time.Unix(s, n) - } - readConfig := logger.ReadConfig{ - Since: since, - Tail: tailLines, - Follow: follow, - } - logs := logReader.ReadLogs(readConfig) - - wf := ioutils.NewWriteFlusher(config.OutStream) - defer wf.Close() - close(started) - wf.Flush() - - var outStream io.Writer - outStream = wf - errStream := outStream - if !container.Config.Tty { - errStream = stdcopy.NewStdWriter(outStream, stdcopy.Stderr) - outStream = stdcopy.NewStdWriter(outStream, stdcopy.Stdout) - } - - for { - select { - case err := <-logs.Err: - logrus.Errorf("Error streaming logs: %v", err) - return nil - case <-ctx.Done(): - logs.Close() - return nil - case msg, ok := <-logs.Msg: - if !ok { - logrus.Debug("logs: end stream") - logs.Close() - if cLog != container.LogDriver { - // Since the logger isn't cached in the container, which occurs if it is running, it - // must get explicitly closed here to avoid leaking it and any file handles it has. - if err := cLog.Close(); err != nil { - logrus.Errorf("Error closing logger: %v", err) - } - } - return nil - } - logLine := msg.Line - if config.Details { - logLine = append([]byte(msg.Attrs.String()+" "), logLine...) - } - if config.Timestamps { - logLine = append([]byte(msg.Timestamp.Format(logger.TimeFormat)+" "), logLine...) - } - if msg.Source == "stdout" && config.ShowStdout { - outStream.Write(logLine) - } - if msg.Source == "stderr" && config.ShowStderr { - errStream.Write(logLine) - } - } - } -} - -func (daemon *Daemon) getLogger(container *container.Container) (logger.Logger, error) { - if container.LogDriver != nil && container.IsRunning() { - return container.LogDriver, nil - } - return container.StartLogger(container.HostConfig.LogConfig) -} - -// mergeLogConfig merges the daemon log config to the container's log config if the container's log driver is not specified. -func (daemon *Daemon) mergeAndVerifyLogConfig(cfg *containertypes.LogConfig) error { - if cfg.Type == "" { - cfg.Type = daemon.defaultLogConfig.Type - } - - if cfg.Config == nil { - cfg.Config = make(map[string]string) - } - - if cfg.Type == daemon.defaultLogConfig.Type { - for k, v := range daemon.defaultLogConfig.Config { - if _, ok := cfg.Config[k]; !ok { - cfg.Config[k] = v - } - } - } - - return logger.ValidateLogOpts(cfg.Type, cfg.Config) -} diff --git a/vendor/github.com/docker/docker/daemon/logs_test.go b/vendor/github.com/docker/docker/daemon/logs_test.go deleted file mode 100644 index 0c36299..0000000 --- a/vendor/github.com/docker/docker/daemon/logs_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package daemon - -import ( - "testing" - - containertypes "github.com/docker/docker/api/types/container" -) - -func TestMergeAndVerifyLogConfigNilConfig(t *testing.T) { - d := &Daemon{defaultLogConfig: containertypes.LogConfig{Type: "json-file", Config: map[string]string{"max-file": "1"}}} - cfg := containertypes.LogConfig{Type: d.defaultLogConfig.Type} - if err := d.mergeAndVerifyLogConfig(&cfg); err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/daemon/metrics.go b/vendor/github.com/docker/docker/daemon/metrics.go deleted file mode 100644 index 69dbfd9..0000000 --- a/vendor/github.com/docker/docker/daemon/metrics.go +++ /dev/null @@ -1,42 +0,0 @@ -package daemon - -import "github.com/docker/go-metrics" - -var ( - containerActions metrics.LabeledTimer - imageActions metrics.LabeledTimer - networkActions metrics.LabeledTimer - engineVersion metrics.LabeledGauge - engineCpus metrics.Gauge - engineMemory metrics.Gauge - healthChecksCounter metrics.Counter - healthChecksFailedCounter metrics.Counter -) - -func init() { - ns := metrics.NewNamespace("engine", "daemon", nil) - containerActions = ns.NewLabeledTimer("container_actions", "The number of seconds it takes to process each container action", "action") - for _, a := range []string{ - "start", - "changes", - "commit", - "create", - "delete", - } { - containerActions.WithValues(a).Update(0) - } - networkActions = ns.NewLabeledTimer("network_actions", "The number of seconds it takes to process each network action", "action") - engineVersion = ns.NewLabeledGauge("engine", "The version and commit information for the engine process", metrics.Unit("info"), - "version", - "commit", - "architecture", - "graph_driver", "kernel", - "os", - ) - engineCpus = ns.NewGauge("engine_cpus", "The number of cpus that the host system of the engine has", metrics.Unit("cpus")) - engineMemory = ns.NewGauge("engine_memory", "The number of bytes of memory that the host system of the engine has", metrics.Bytes) - healthChecksCounter = ns.NewCounter("health_checks", "The total number of health checks") - healthChecksFailedCounter = ns.NewCounter("health_checks_failed", "The total number of failed health checks") - imageActions = ns.NewLabeledTimer("image_actions", "The number of seconds it takes to process each image action", "action") - metrics.Register(ns) -} diff --git a/vendor/github.com/docker/docker/daemon/monitor.go b/vendor/github.com/docker/docker/daemon/monitor.go deleted file mode 100644 index ee0d1fc..0000000 --- a/vendor/github.com/docker/docker/daemon/monitor.go +++ /dev/null @@ -1,132 +0,0 @@ -package daemon - -import ( - "errors" - "fmt" - "runtime" - "strconv" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/restartmanager" -) - -// StateChanged updates daemon state changes from containerd -func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error { - c := daemon.containers.Get(id) - if c == nil { - return fmt.Errorf("no such container: %s", id) - } - - switch e.State { - case libcontainerd.StateOOM: - // StateOOM is Linux specific and should never be hit on Windows - if runtime.GOOS == "windows" { - return errors.New("Received StateOOM from libcontainerd on Windows. This should never happen.") - } - daemon.updateHealthMonitor(c) - daemon.LogContainerEvent(c, "oom") - case libcontainerd.StateExit: - // if container's AutoRemove flag is set, remove it after clean up - autoRemove := func() { - if c.HostConfig.AutoRemove { - if err := daemon.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: true, RemoveVolume: true}); err != nil { - logrus.Errorf("can't remove container %s: %v", c.ID, err) - } - } - } - - c.Lock() - c.StreamConfig.Wait() - c.Reset(false) - - restart, wait, err := c.RestartManager().ShouldRestart(e.ExitCode, false, time.Since(c.StartedAt)) - if err == nil && restart { - c.RestartCount++ - c.SetRestarting(platformConstructExitStatus(e)) - } else { - c.SetStopped(platformConstructExitStatus(e)) - defer autoRemove() - } - - daemon.updateHealthMonitor(c) - attributes := map[string]string{ - "exitCode": strconv.Itoa(int(e.ExitCode)), - } - daemon.LogContainerEventWithAttributes(c, "die", attributes) - daemon.Cleanup(c) - - if err == nil && restart { - go func() { - err := <-wait - if err == nil { - if err = daemon.containerStart(c, "", "", false); err != nil { - logrus.Debugf("failed to restart container: %+v", err) - } - } - if err != nil { - c.SetStopped(platformConstructExitStatus(e)) - defer autoRemove() - if err != restartmanager.ErrRestartCanceled { - logrus.Errorf("restartmanger wait error: %+v", err) - } - } - }() - } - - defer c.Unlock() - if err := c.ToDisk(); err != nil { - return err - } - return daemon.postRunProcessing(c, e) - case libcontainerd.StateExitProcess: - if execConfig := c.ExecCommands.Get(e.ProcessID); execConfig != nil { - ec := int(e.ExitCode) - execConfig.Lock() - defer execConfig.Unlock() - execConfig.ExitCode = &ec - execConfig.Running = false - execConfig.StreamConfig.Wait() - if err := execConfig.CloseStreams(); err != nil { - logrus.Errorf("%s: %s", c.ID, err) - } - - // remove the exec command from the container's store only and not the - // daemon's store so that the exec command can be inspected. - c.ExecCommands.Delete(execConfig.ID) - } else { - logrus.Warnf("Ignoring StateExitProcess for %v but no exec command found", e) - } - case libcontainerd.StateStart, libcontainerd.StateRestore: - // Container is already locked in this case - c.SetRunning(int(e.Pid), e.State == libcontainerd.StateStart) - c.HasBeenManuallyStopped = false - c.HasBeenStartedBefore = true - if err := c.ToDisk(); err != nil { - c.Reset(false) - return err - } - daemon.initHealthMonitor(c) - daemon.LogContainerEvent(c, "start") - case libcontainerd.StatePause: - // Container is already locked in this case - c.Paused = true - if err := c.ToDisk(); err != nil { - return err - } - daemon.updateHealthMonitor(c) - daemon.LogContainerEvent(c, "pause") - case libcontainerd.StateResume: - // Container is already locked in this case - c.Paused = false - if err := c.ToDisk(); err != nil { - return err - } - daemon.updateHealthMonitor(c) - daemon.LogContainerEvent(c, "unpause") - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/monitor_linux.go b/vendor/github.com/docker/docker/daemon/monitor_linux.go deleted file mode 100644 index 09f5af5..0000000 --- a/vendor/github.com/docker/docker/daemon/monitor_linux.go +++ /dev/null @@ -1,19 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/container" - "github.com/docker/docker/libcontainerd" -) - -// platformConstructExitStatus returns a platform specific exit status structure -func platformConstructExitStatus(e libcontainerd.StateInfo) *container.ExitStatus { - return &container.ExitStatus{ - ExitCode: int(e.ExitCode), - OOMKilled: e.OOMKilled, - } -} - -// postRunProcessing perfoms any processing needed on the container after it has stopped. -func (daemon *Daemon) postRunProcessing(container *container.Container, e libcontainerd.StateInfo) error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/monitor_solaris.go b/vendor/github.com/docker/docker/daemon/monitor_solaris.go deleted file mode 100644 index 5ccfada..0000000 --- a/vendor/github.com/docker/docker/daemon/monitor_solaris.go +++ /dev/null @@ -1,18 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/container" - "github.com/docker/docker/libcontainerd" -) - -// platformConstructExitStatus returns a platform specific exit status structure -func platformConstructExitStatus(e libcontainerd.StateInfo) *container.ExitStatus { - return &container.ExitStatus{ - ExitCode: int(e.ExitCode), - } -} - -// postRunProcessing perfoms any processing needed on the container after it has stopped. -func (daemon *Daemon) postRunProcessing(container *container.Container, e libcontainerd.StateInfo) error { - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/monitor_windows.go b/vendor/github.com/docker/docker/daemon/monitor_windows.go deleted file mode 100644 index 9648b1b..0000000 --- a/vendor/github.com/docker/docker/daemon/monitor_windows.go +++ /dev/null @@ -1,46 +0,0 @@ -package daemon - -import ( - "fmt" - - "github.com/docker/docker/container" - "github.com/docker/docker/libcontainerd" -) - -// platformConstructExitStatus returns a platform specific exit status structure -func platformConstructExitStatus(e libcontainerd.StateInfo) *container.ExitStatus { - return &container.ExitStatus{ - ExitCode: int(e.ExitCode), - } -} - -// postRunProcessing perfoms any processing needed on the container after it has stopped. -func (daemon *Daemon) postRunProcessing(container *container.Container, e libcontainerd.StateInfo) error { - if e.ExitCode == 0 && e.UpdatePending { - spec, err := daemon.createSpec(container) - if err != nil { - return err - } - - newOpts := []libcontainerd.CreateOption{&libcontainerd.ServicingOption{ - IsServicing: true, - }} - - copts, err := daemon.getLibcontainerdCreateOptions(container) - if err != nil { - return err - } - - if copts != nil { - newOpts = append(newOpts, copts...) - } - - // Create a new servicing container, which will start, complete the update, and merge back the - // results if it succeeded, all as part of the below function call. - if err := daemon.containerd.Create((container.ID + "_servicing"), "", "", *spec, container.InitializeStdio, newOpts...); err != nil { - container.SetExitCode(-1) - return fmt.Errorf("Post-run update servicing failed: %s", err) - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/mounts.go b/vendor/github.com/docker/docker/daemon/mounts.go deleted file mode 100644 index 1c11f86..0000000 --- a/vendor/github.com/docker/docker/daemon/mounts.go +++ /dev/null @@ -1,48 +0,0 @@ -package daemon - -import ( - "fmt" - "strings" - - "github.com/docker/docker/container" - volumestore "github.com/docker/docker/volume/store" -) - -func (daemon *Daemon) prepareMountPoints(container *container.Container) error { - for _, config := range container.MountPoints { - if err := daemon.lazyInitializeVolume(container.ID, config); err != nil { - return err - } - } - return nil -} - -func (daemon *Daemon) removeMountPoints(container *container.Container, rm bool) error { - var rmErrors []string - for _, m := range container.MountPoints { - if m.Volume == nil { - continue - } - daemon.volumes.Dereference(m.Volume, container.ID) - if rm { - // Do not remove named mountpoints - // these are mountpoints specified like `docker run -v :/foo` - if m.Spec.Source != "" { - continue - } - err := daemon.volumes.Remove(m.Volume) - // Ignore volume in use errors because having this - // volume being referenced by other container is - // not an error, but an implementation detail. - // This prevents docker from logging "ERROR: Volume in use" - // where there is another container using the volume. - if err != nil && !volumestore.IsInUse(err) { - rmErrors = append(rmErrors, err.Error()) - } - } - } - if len(rmErrors) > 0 { - return fmt.Errorf("Error removing volumes:\n%v", strings.Join(rmErrors, "\n")) - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/names.go b/vendor/github.com/docker/docker/daemon/names.go deleted file mode 100644 index 273d551..0000000 --- a/vendor/github.com/docker/docker/daemon/names.go +++ /dev/null @@ -1,116 +0,0 @@ -package daemon - -import ( - "fmt" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/namesgenerator" - "github.com/docker/docker/pkg/registrar" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/utils" -) - -var ( - validContainerNameChars = utils.RestrictedNameChars - validContainerNamePattern = utils.RestrictedNamePattern -) - -func (daemon *Daemon) registerName(container *container.Container) error { - if daemon.Exists(container.ID) { - return fmt.Errorf("Container is already loaded") - } - if err := validateID(container.ID); err != nil { - return err - } - if container.Name == "" { - name, err := daemon.generateNewName(container.ID) - if err != nil { - return err - } - container.Name = name - - if err := container.ToDiskLocking(); err != nil { - logrus.Errorf("Error saving container name to disk: %v", err) - } - } - return daemon.nameIndex.Reserve(container.Name, container.ID) -} - -func (daemon *Daemon) generateIDAndName(name string) (string, string, error) { - var ( - err error - id = stringid.GenerateNonCryptoID() - ) - - if name == "" { - if name, err = daemon.generateNewName(id); err != nil { - return "", "", err - } - return id, name, nil - } - - if name, err = daemon.reserveName(id, name); err != nil { - return "", "", err - } - - return id, name, nil -} - -func (daemon *Daemon) reserveName(id, name string) (string, error) { - if !validContainerNamePattern.MatchString(strings.TrimPrefix(name, "/")) { - return "", fmt.Errorf("Invalid container name (%s), only %s are allowed", name, validContainerNameChars) - } - if name[0] != '/' { - name = "/" + name - } - - if err := daemon.nameIndex.Reserve(name, id); err != nil { - if err == registrar.ErrNameReserved { - id, err := daemon.nameIndex.Get(name) - if err != nil { - logrus.Errorf("got unexpected error while looking up reserved name: %v", err) - return "", err - } - return "", fmt.Errorf("Conflict. The container name %q is already in use by container %s. You have to remove (or rename) that container to be able to reuse that name.", name, id) - } - return "", fmt.Errorf("error reserving name: %s, error: %v", name, err) - } - return name, nil -} - -func (daemon *Daemon) releaseName(name string) { - daemon.nameIndex.Release(name) -} - -func (daemon *Daemon) generateNewName(id string) (string, error) { - var name string - for i := 0; i < 6; i++ { - name = namesgenerator.GetRandomName(i) - if name[0] != '/' { - name = "/" + name - } - - if err := daemon.nameIndex.Reserve(name, id); err != nil { - if err == registrar.ErrNameReserved { - continue - } - return "", err - } - return name, nil - } - - name = "/" + stringid.TruncateID(id) - if err := daemon.nameIndex.Reserve(name, id); err != nil { - return "", err - } - return name, nil -} - -func validateID(id string) error { - if id == "" { - return fmt.Errorf("Invalid empty id") - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/network.go b/vendor/github.com/docker/docker/daemon/network.go deleted file mode 100644 index ab8fd88..0000000 --- a/vendor/github.com/docker/docker/daemon/network.go +++ /dev/null @@ -1,498 +0,0 @@ -package daemon - -import ( - "fmt" - "net" - "runtime" - "sort" - "strings" - - "github.com/Sirupsen/logrus" - apierrors "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/network" - clustertypes "github.com/docker/docker/daemon/cluster/provider" - "github.com/docker/docker/pkg/plugingetter" - "github.com/docker/docker/runconfig" - "github.com/docker/libnetwork" - "github.com/docker/libnetwork/driverapi" - "github.com/docker/libnetwork/ipamapi" - networktypes "github.com/docker/libnetwork/types" - "github.com/pkg/errors" - "golang.org/x/net/context" -) - -// NetworkControllerEnabled checks if the networking stack is enabled. -// This feature depends on OS primitives and it's disabled in systems like Windows. -func (daemon *Daemon) NetworkControllerEnabled() bool { - return daemon.netController != nil -} - -// FindNetwork function finds a network for a given string that can represent network name or id -func (daemon *Daemon) FindNetwork(idName string) (libnetwork.Network, error) { - // Find by Name - n, err := daemon.GetNetworkByName(idName) - if err != nil && !isNoSuchNetworkError(err) { - return nil, err - } - - if n != nil { - return n, nil - } - - // Find by id - return daemon.GetNetworkByID(idName) -} - -func isNoSuchNetworkError(err error) bool { - _, ok := err.(libnetwork.ErrNoSuchNetwork) - return ok -} - -// GetNetworkByID function returns a network whose ID begins with the given prefix. -// It fails with an error if no matching, or more than one matching, networks are found. -func (daemon *Daemon) GetNetworkByID(partialID string) (libnetwork.Network, error) { - list := daemon.GetNetworksByID(partialID) - - if len(list) == 0 { - return nil, libnetwork.ErrNoSuchNetwork(partialID) - } - if len(list) > 1 { - return nil, libnetwork.ErrInvalidID(partialID) - } - return list[0], nil -} - -// GetNetworkByName function returns a network for a given network name. -// If no network name is given, the default network is returned. -func (daemon *Daemon) GetNetworkByName(name string) (libnetwork.Network, error) { - c := daemon.netController - if c == nil { - return nil, libnetwork.ErrNoSuchNetwork(name) - } - if name == "" { - name = c.Config().Daemon.DefaultNetwork - } - return c.NetworkByName(name) -} - -// GetNetworksByID returns a list of networks whose ID partially matches zero or more networks -func (daemon *Daemon) GetNetworksByID(partialID string) []libnetwork.Network { - c := daemon.netController - if c == nil { - return nil - } - list := []libnetwork.Network{} - l := func(nw libnetwork.Network) bool { - if strings.HasPrefix(nw.ID(), partialID) { - list = append(list, nw) - } - return false - } - c.WalkNetworks(l) - - return list -} - -// getAllNetworks returns a list containing all networks -func (daemon *Daemon) getAllNetworks() []libnetwork.Network { - c := daemon.netController - list := []libnetwork.Network{} - l := func(nw libnetwork.Network) bool { - list = append(list, nw) - return false - } - c.WalkNetworks(l) - - return list -} - -func isIngressNetwork(name string) bool { - return name == "ingress" -} - -var ingressChan = make(chan struct{}, 1) - -func ingressWait() func() { - ingressChan <- struct{}{} - return func() { <-ingressChan } -} - -// SetupIngress setups ingress networking. -func (daemon *Daemon) SetupIngress(create clustertypes.NetworkCreateRequest, nodeIP string) error { - ip, _, err := net.ParseCIDR(nodeIP) - if err != nil { - return err - } - - go func() { - controller := daemon.netController - controller.AgentInitWait() - - if n, err := daemon.GetNetworkByName(create.Name); err == nil && n != nil && n.ID() != create.ID { - if err := controller.SandboxDestroy("ingress-sbox"); err != nil { - logrus.Errorf("Failed to delete stale ingress sandbox: %v", err) - return - } - - // Cleanup any stale endpoints that might be left over during previous iterations - epList := n.Endpoints() - for _, ep := range epList { - if err := ep.Delete(true); err != nil { - logrus.Errorf("Failed to delete endpoint %s (%s): %v", ep.Name(), ep.ID(), err) - } - } - - if err := n.Delete(); err != nil { - logrus.Errorf("Failed to delete stale ingress network %s: %v", n.ID(), err) - return - } - } - - if _, err := daemon.createNetwork(create.NetworkCreateRequest, create.ID, true); err != nil { - // If it is any other error other than already - // exists error log error and return. - if _, ok := err.(libnetwork.NetworkNameError); !ok { - logrus.Errorf("Failed creating ingress network: %v", err) - return - } - - // Otherwise continue down the call to create or recreate sandbox. - } - - n, err := daemon.GetNetworkByID(create.ID) - if err != nil { - logrus.Errorf("Failed getting ingress network by id after creating: %v", err) - return - } - - sb, err := controller.NewSandbox("ingress-sbox", libnetwork.OptionIngress()) - if err != nil { - if _, ok := err.(networktypes.ForbiddenError); !ok { - logrus.Errorf("Failed creating ingress sandbox: %v", err) - } - return - } - - ep, err := n.CreateEndpoint("ingress-endpoint", libnetwork.CreateOptionIpam(ip, nil, nil, nil)) - if err != nil { - logrus.Errorf("Failed creating ingress endpoint: %v", err) - return - } - - if err := ep.Join(sb, nil); err != nil { - logrus.Errorf("Failed joining ingress sandbox to ingress endpoint: %v", err) - } - - if err := sb.EnableService(); err != nil { - logrus.WithError(err).Error("Failed enabling service for ingress sandbox") - } - }() - - return nil -} - -// SetNetworkBootstrapKeys sets the bootstrap keys. -func (daemon *Daemon) SetNetworkBootstrapKeys(keys []*networktypes.EncryptionKey) error { - return daemon.netController.SetKeys(keys) -} - -// UpdateAttachment notifies the attacher about the attachment config. -func (daemon *Daemon) UpdateAttachment(networkName, networkID, containerID string, config *network.NetworkingConfig) error { - if daemon.clusterProvider == nil { - return fmt.Errorf("cluster provider is not initialized") - } - - if err := daemon.clusterProvider.UpdateAttachment(networkName, containerID, config); err != nil { - return daemon.clusterProvider.UpdateAttachment(networkID, containerID, config) - } - - return nil -} - -// WaitForDetachment makes the cluster manager wait for detachment of -// the container from the network. -func (daemon *Daemon) WaitForDetachment(ctx context.Context, networkName, networkID, taskID, containerID string) error { - if daemon.clusterProvider == nil { - return fmt.Errorf("cluster provider is not initialized") - } - - return daemon.clusterProvider.WaitForDetachment(ctx, networkName, networkID, taskID, containerID) -} - -// CreateManagedNetwork creates an agent network. -func (daemon *Daemon) CreateManagedNetwork(create clustertypes.NetworkCreateRequest) error { - _, err := daemon.createNetwork(create.NetworkCreateRequest, create.ID, true) - return err -} - -// CreateNetwork creates a network with the given name, driver and other optional parameters -func (daemon *Daemon) CreateNetwork(create types.NetworkCreateRequest) (*types.NetworkCreateResponse, error) { - resp, err := daemon.createNetwork(create, "", false) - if err != nil { - return nil, err - } - return resp, err -} - -func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string, agent bool) (*types.NetworkCreateResponse, error) { - // If there is a pending ingress network creation wait here - // since ingress network creation can happen via node download - // from manager or task download. - if isIngressNetwork(create.Name) { - defer ingressWait()() - } - - if runconfig.IsPreDefinedNetwork(create.Name) && !agent { - err := fmt.Errorf("%s is a pre-defined network and cannot be created", create.Name) - return nil, apierrors.NewRequestForbiddenError(err) - } - - var warning string - nw, err := daemon.GetNetworkByName(create.Name) - if err != nil { - if _, ok := err.(libnetwork.ErrNoSuchNetwork); !ok { - return nil, err - } - } - if nw != nil { - if create.CheckDuplicate { - return nil, libnetwork.NetworkNameError(create.Name) - } - warning = fmt.Sprintf("Network with name %s (id : %s) already exists", nw.Name(), nw.ID()) - } - - c := daemon.netController - driver := create.Driver - if driver == "" { - driver = c.Config().Daemon.DefaultDriver - } - - nwOptions := []libnetwork.NetworkOption{ - libnetwork.NetworkOptionEnableIPv6(create.EnableIPv6), - libnetwork.NetworkOptionDriverOpts(create.Options), - libnetwork.NetworkOptionLabels(create.Labels), - libnetwork.NetworkOptionAttachable(create.Attachable), - } - - if create.IPAM != nil { - ipam := create.IPAM - v4Conf, v6Conf, err := getIpamConfig(ipam.Config) - if err != nil { - return nil, err - } - nwOptions = append(nwOptions, libnetwork.NetworkOptionIpam(ipam.Driver, "", v4Conf, v6Conf, ipam.Options)) - } - - if create.Internal { - nwOptions = append(nwOptions, libnetwork.NetworkOptionInternalNetwork()) - } - if agent { - nwOptions = append(nwOptions, libnetwork.NetworkOptionDynamic()) - nwOptions = append(nwOptions, libnetwork.NetworkOptionPersist(false)) - } - - if isIngressNetwork(create.Name) { - nwOptions = append(nwOptions, libnetwork.NetworkOptionIngress()) - } - - n, err := c.NewNetwork(driver, create.Name, id, nwOptions...) - if err != nil { - return nil, err - } - - daemon.pluginRefCount(driver, driverapi.NetworkPluginEndpointType, plugingetter.ACQUIRE) - if create.IPAM != nil { - daemon.pluginRefCount(create.IPAM.Driver, ipamapi.PluginEndpointType, plugingetter.ACQUIRE) - } - daemon.LogNetworkEvent(n, "create") - - return &types.NetworkCreateResponse{ - ID: n.ID(), - Warning: warning, - }, nil -} - -func (daemon *Daemon) pluginRefCount(driver, capability string, mode int) { - var builtinDrivers []string - - if capability == driverapi.NetworkPluginEndpointType { - builtinDrivers = daemon.netController.BuiltinDrivers() - } else if capability == ipamapi.PluginEndpointType { - builtinDrivers = daemon.netController.BuiltinIPAMDrivers() - } - - for _, d := range builtinDrivers { - if d == driver { - return - } - } - - if daemon.PluginStore != nil { - _, err := daemon.PluginStore.Get(driver, capability, mode) - if err != nil { - logrus.WithError(err).WithFields(logrus.Fields{"mode": mode, "driver": driver}).Error("Error handling plugin refcount operation") - } - } -} - -func getIpamConfig(data []network.IPAMConfig) ([]*libnetwork.IpamConf, []*libnetwork.IpamConf, error) { - ipamV4Cfg := []*libnetwork.IpamConf{} - ipamV6Cfg := []*libnetwork.IpamConf{} - for _, d := range data { - iCfg := libnetwork.IpamConf{} - iCfg.PreferredPool = d.Subnet - iCfg.SubPool = d.IPRange - iCfg.Gateway = d.Gateway - iCfg.AuxAddresses = d.AuxAddress - ip, _, err := net.ParseCIDR(d.Subnet) - if err != nil { - return nil, nil, fmt.Errorf("Invalid subnet %s : %v", d.Subnet, err) - } - if ip.To4() != nil { - ipamV4Cfg = append(ipamV4Cfg, &iCfg) - } else { - ipamV6Cfg = append(ipamV6Cfg, &iCfg) - } - } - return ipamV4Cfg, ipamV6Cfg, nil -} - -// UpdateContainerServiceConfig updates a service configuration. -func (daemon *Daemon) UpdateContainerServiceConfig(containerName string, serviceConfig *clustertypes.ServiceConfig) error { - container, err := daemon.GetContainer(containerName) - if err != nil { - return err - } - - container.NetworkSettings.Service = serviceConfig - return nil -} - -// ConnectContainerToNetwork connects the given container to the given -// network. If either cannot be found, an err is returned. If the -// network cannot be set up, an err is returned. -func (daemon *Daemon) ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error { - if runtime.GOOS == "solaris" { - return errors.New("docker network connect is unsupported on Solaris platform") - } - container, err := daemon.GetContainer(containerName) - if err != nil { - return err - } - return daemon.ConnectToNetwork(container, networkName, endpointConfig) -} - -// DisconnectContainerFromNetwork disconnects the given container from -// the given network. If either cannot be found, an err is returned. -func (daemon *Daemon) DisconnectContainerFromNetwork(containerName string, networkName string, force bool) error { - if runtime.GOOS == "solaris" { - return errors.New("docker network disconnect is unsupported on Solaris platform") - } - container, err := daemon.GetContainer(containerName) - if err != nil { - if force { - return daemon.ForceEndpointDelete(containerName, networkName) - } - return err - } - return daemon.DisconnectFromNetwork(container, networkName, force) -} - -// GetNetworkDriverList returns the list of plugins drivers -// registered for network. -func (daemon *Daemon) GetNetworkDriverList() []string { - if !daemon.NetworkControllerEnabled() { - return nil - } - - pluginList := daemon.netController.BuiltinDrivers() - - managedPlugins := daemon.PluginStore.GetAllManagedPluginsByCap(driverapi.NetworkPluginEndpointType) - - for _, plugin := range managedPlugins { - pluginList = append(pluginList, plugin.Name()) - } - - pluginMap := make(map[string]bool) - for _, plugin := range pluginList { - pluginMap[plugin] = true - } - - networks := daemon.netController.Networks() - - for _, network := range networks { - if !pluginMap[network.Type()] { - pluginList = append(pluginList, network.Type()) - pluginMap[network.Type()] = true - } - } - - sort.Strings(pluginList) - - return pluginList -} - -// DeleteManagedNetwork deletes an agent network. -func (daemon *Daemon) DeleteManagedNetwork(networkID string) error { - return daemon.deleteNetwork(networkID, true) -} - -// DeleteNetwork destroys a network unless it's one of docker's predefined networks. -func (daemon *Daemon) DeleteNetwork(networkID string) error { - return daemon.deleteNetwork(networkID, false) -} - -func (daemon *Daemon) deleteNetwork(networkID string, dynamic bool) error { - nw, err := daemon.FindNetwork(networkID) - if err != nil { - return err - } - - if runconfig.IsPreDefinedNetwork(nw.Name()) && !dynamic { - err := fmt.Errorf("%s is a pre-defined network and cannot be removed", nw.Name()) - return apierrors.NewRequestForbiddenError(err) - } - - if err := nw.Delete(); err != nil { - return err - } - daemon.pluginRefCount(nw.Type(), driverapi.NetworkPluginEndpointType, plugingetter.RELEASE) - ipamType, _, _, _ := nw.Info().IpamConfig() - daemon.pluginRefCount(ipamType, ipamapi.PluginEndpointType, plugingetter.RELEASE) - daemon.LogNetworkEvent(nw, "destroy") - return nil -} - -// GetNetworks returns a list of all networks -func (daemon *Daemon) GetNetworks() []libnetwork.Network { - return daemon.getAllNetworks() -} - -// clearAttachableNetworks removes the attachable networks -// after disconnecting any connected container -func (daemon *Daemon) clearAttachableNetworks() { - for _, n := range daemon.GetNetworks() { - if !n.Info().Attachable() { - continue - } - for _, ep := range n.Endpoints() { - epInfo := ep.Info() - if epInfo == nil { - continue - } - sb := epInfo.Sandbox() - if sb == nil { - continue - } - containerID := sb.ContainerID() - if err := daemon.DisconnectContainerFromNetwork(containerID, n.ID(), true); err != nil { - logrus.Warnf("Failed to disconnect container %s from swarm network %s on cluster leave: %v", - containerID, n.Name(), err) - } - } - if err := daemon.DeleteManagedNetwork(n.ID()); err != nil { - logrus.Warnf("Failed to remove swarm network %s on cluster leave: %v", n.Name(), err) - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/network/settings.go b/vendor/github.com/docker/docker/daemon/network/settings.go deleted file mode 100644 index 8f6b7dd..0000000 --- a/vendor/github.com/docker/docker/daemon/network/settings.go +++ /dev/null @@ -1,33 +0,0 @@ -package network - -import ( - networktypes "github.com/docker/docker/api/types/network" - clustertypes "github.com/docker/docker/daemon/cluster/provider" - "github.com/docker/go-connections/nat" -) - -// Settings stores configuration details about the daemon network config -// TODO Windows. Many of these fields can be factored out., -type Settings struct { - Bridge string - SandboxID string - HairpinMode bool - LinkLocalIPv6Address string - LinkLocalIPv6PrefixLen int - Networks map[string]*EndpointSettings - Service *clustertypes.ServiceConfig - Ports nat.PortMap - SandboxKey string - SecondaryIPAddresses []networktypes.Address - SecondaryIPv6Addresses []networktypes.Address - IsAnonymousEndpoint bool - HasSwarmEndpoint bool -} - -// EndpointSettings is a package local wrapper for -// networktypes.EndpointSettings which stores Endpoint state that -// needs to be persisted to disk but not exposed in the api. -type EndpointSettings struct { - *networktypes.EndpointSettings - IPAMOperational bool -} diff --git a/vendor/github.com/docker/docker/daemon/oci_linux.go b/vendor/github.com/docker/docker/daemon/oci_linux.go deleted file mode 100644 index a72b0b8..0000000 --- a/vendor/github.com/docker/docker/daemon/oci_linux.go +++ /dev/null @@ -1,790 +0,0 @@ -package daemon - -import ( - "fmt" - "io" - "os" - "os/exec" - "path/filepath" - "sort" - "strconv" - "strings" - - "github.com/Sirupsen/logrus" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/daemon/caps" - "github.com/docker/docker/oci" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/stringutils" - "github.com/docker/docker/pkg/symlink" - "github.com/docker/docker/volume" - "github.com/opencontainers/runc/libcontainer/apparmor" - "github.com/opencontainers/runc/libcontainer/cgroups" - "github.com/opencontainers/runc/libcontainer/devices" - "github.com/opencontainers/runc/libcontainer/user" - specs "github.com/opencontainers/runtime-spec/specs-go" -) - -func setResources(s *specs.Spec, r containertypes.Resources) error { - weightDevices, err := getBlkioWeightDevices(r) - if err != nil { - return err - } - readBpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceReadBps) - if err != nil { - return err - } - writeBpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceWriteBps) - if err != nil { - return err - } - readIOpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceReadIOps) - if err != nil { - return err - } - writeIOpsDevice, err := getBlkioThrottleDevices(r.BlkioDeviceWriteIOps) - if err != nil { - return err - } - - memoryRes := getMemoryResources(r) - cpuRes := getCPUResources(r) - blkioWeight := r.BlkioWeight - - specResources := &specs.Resources{ - Memory: memoryRes, - CPU: cpuRes, - BlockIO: &specs.BlockIO{ - Weight: &blkioWeight, - WeightDevice: weightDevices, - ThrottleReadBpsDevice: readBpsDevice, - ThrottleWriteBpsDevice: writeBpsDevice, - ThrottleReadIOPSDevice: readIOpsDevice, - ThrottleWriteIOPSDevice: writeIOpsDevice, - }, - DisableOOMKiller: r.OomKillDisable, - Pids: &specs.Pids{ - Limit: &r.PidsLimit, - }, - } - - if s.Linux.Resources != nil && len(s.Linux.Resources.Devices) > 0 { - specResources.Devices = s.Linux.Resources.Devices - } - - s.Linux.Resources = specResources - return nil -} - -func setDevices(s *specs.Spec, c *container.Container) error { - // Build lists of devices allowed and created within the container. - var devs []specs.Device - devPermissions := s.Linux.Resources.Devices - if c.HostConfig.Privileged { - hostDevices, err := devices.HostDevices() - if err != nil { - return err - } - for _, d := range hostDevices { - devs = append(devs, oci.Device(d)) - } - rwm := "rwm" - devPermissions = []specs.DeviceCgroup{ - { - Allow: true, - Access: &rwm, - }, - } - } else { - for _, deviceMapping := range c.HostConfig.Devices { - d, dPermissions, err := oci.DevicesFromPath(deviceMapping.PathOnHost, deviceMapping.PathInContainer, deviceMapping.CgroupPermissions) - if err != nil { - return err - } - devs = append(devs, d...) - devPermissions = append(devPermissions, dPermissions...) - } - } - - s.Linux.Devices = append(s.Linux.Devices, devs...) - s.Linux.Resources.Devices = devPermissions - return nil -} - -func setRlimits(daemon *Daemon, s *specs.Spec, c *container.Container) error { - var rlimits []specs.Rlimit - - // We want to leave the original HostConfig alone so make a copy here - hostConfig := *c.HostConfig - // Merge with the daemon defaults - daemon.mergeUlimits(&hostConfig) - for _, ul := range hostConfig.Ulimits { - rlimits = append(rlimits, specs.Rlimit{ - Type: "RLIMIT_" + strings.ToUpper(ul.Name), - Soft: uint64(ul.Soft), - Hard: uint64(ul.Hard), - }) - } - - s.Process.Rlimits = rlimits - return nil -} - -func setUser(s *specs.Spec, c *container.Container) error { - uid, gid, additionalGids, err := getUser(c, c.Config.User) - if err != nil { - return err - } - s.Process.User.UID = uid - s.Process.User.GID = gid - s.Process.User.AdditionalGids = additionalGids - return nil -} - -func readUserFile(c *container.Container, p string) (io.ReadCloser, error) { - fp, err := symlink.FollowSymlinkInScope(filepath.Join(c.BaseFS, p), c.BaseFS) - if err != nil { - return nil, err - } - return os.Open(fp) -} - -func getUser(c *container.Container, username string) (uint32, uint32, []uint32, error) { - passwdPath, err := user.GetPasswdPath() - if err != nil { - return 0, 0, nil, err - } - groupPath, err := user.GetGroupPath() - if err != nil { - return 0, 0, nil, err - } - passwdFile, err := readUserFile(c, passwdPath) - if err == nil { - defer passwdFile.Close() - } - groupFile, err := readUserFile(c, groupPath) - if err == nil { - defer groupFile.Close() - } - - execUser, err := user.GetExecUser(username, nil, passwdFile, groupFile) - if err != nil { - return 0, 0, nil, err - } - - // todo: fix this double read by a change to libcontainer/user pkg - groupFile, err = readUserFile(c, groupPath) - if err == nil { - defer groupFile.Close() - } - var addGroups []int - if len(c.HostConfig.GroupAdd) > 0 { - addGroups, err = user.GetAdditionalGroups(c.HostConfig.GroupAdd, groupFile) - if err != nil { - return 0, 0, nil, err - } - } - uid := uint32(execUser.Uid) - gid := uint32(execUser.Gid) - sgids := append(execUser.Sgids, addGroups...) - var additionalGids []uint32 - for _, g := range sgids { - additionalGids = append(additionalGids, uint32(g)) - } - return uid, gid, additionalGids, nil -} - -func setNamespace(s *specs.Spec, ns specs.Namespace) { - for i, n := range s.Linux.Namespaces { - if n.Type == ns.Type { - s.Linux.Namespaces[i] = ns - return - } - } - s.Linux.Namespaces = append(s.Linux.Namespaces, ns) -} - -func setCapabilities(s *specs.Spec, c *container.Container) error { - var caplist []string - var err error - if c.HostConfig.Privileged { - caplist = caps.GetAllCapabilities() - } else { - caplist, err = caps.TweakCapabilities(s.Process.Capabilities, c.HostConfig.CapAdd, c.HostConfig.CapDrop) - if err != nil { - return err - } - } - s.Process.Capabilities = caplist - return nil -} - -func setNamespaces(daemon *Daemon, s *specs.Spec, c *container.Container) error { - userNS := false - // user - if c.HostConfig.UsernsMode.IsPrivate() { - uidMap, gidMap := daemon.GetUIDGIDMaps() - if uidMap != nil { - userNS = true - ns := specs.Namespace{Type: "user"} - setNamespace(s, ns) - s.Linux.UIDMappings = specMapping(uidMap) - s.Linux.GIDMappings = specMapping(gidMap) - } - } - // network - if !c.Config.NetworkDisabled { - ns := specs.Namespace{Type: "network"} - parts := strings.SplitN(string(c.HostConfig.NetworkMode), ":", 2) - if parts[0] == "container" { - nc, err := daemon.getNetworkedContainer(c.ID, c.HostConfig.NetworkMode.ConnectedContainer()) - if err != nil { - return err - } - ns.Path = fmt.Sprintf("/proc/%d/ns/net", nc.State.GetPID()) - if userNS { - // to share a net namespace, they must also share a user namespace - nsUser := specs.Namespace{Type: "user"} - nsUser.Path = fmt.Sprintf("/proc/%d/ns/user", nc.State.GetPID()) - setNamespace(s, nsUser) - } - } else if c.HostConfig.NetworkMode.IsHost() { - ns.Path = c.NetworkSettings.SandboxKey - } - setNamespace(s, ns) - } - // ipc - if c.HostConfig.IpcMode.IsContainer() { - ns := specs.Namespace{Type: "ipc"} - ic, err := daemon.getIpcContainer(c) - if err != nil { - return err - } - ns.Path = fmt.Sprintf("/proc/%d/ns/ipc", ic.State.GetPID()) - setNamespace(s, ns) - if userNS { - // to share an IPC namespace, they must also share a user namespace - nsUser := specs.Namespace{Type: "user"} - nsUser.Path = fmt.Sprintf("/proc/%d/ns/user", ic.State.GetPID()) - setNamespace(s, nsUser) - } - } else if c.HostConfig.IpcMode.IsHost() { - oci.RemoveNamespace(s, specs.NamespaceType("ipc")) - } else { - ns := specs.Namespace{Type: "ipc"} - setNamespace(s, ns) - } - // pid - if c.HostConfig.PidMode.IsContainer() { - ns := specs.Namespace{Type: "pid"} - pc, err := daemon.getPidContainer(c) - if err != nil { - return err - } - ns.Path = fmt.Sprintf("/proc/%d/ns/pid", pc.State.GetPID()) - setNamespace(s, ns) - if userNS { - // to share a PID namespace, they must also share a user namespace - nsUser := specs.Namespace{Type: "user"} - nsUser.Path = fmt.Sprintf("/proc/%d/ns/user", pc.State.GetPID()) - setNamespace(s, nsUser) - } - } else if c.HostConfig.PidMode.IsHost() { - oci.RemoveNamespace(s, specs.NamespaceType("pid")) - } else { - ns := specs.Namespace{Type: "pid"} - setNamespace(s, ns) - } - // uts - if c.HostConfig.UTSMode.IsHost() { - oci.RemoveNamespace(s, specs.NamespaceType("uts")) - s.Hostname = "" - } - - return nil -} - -func specMapping(s []idtools.IDMap) []specs.IDMapping { - var ids []specs.IDMapping - for _, item := range s { - ids = append(ids, specs.IDMapping{ - HostID: uint32(item.HostID), - ContainerID: uint32(item.ContainerID), - Size: uint32(item.Size), - }) - } - return ids -} - -func getMountInfo(mountinfo []*mount.Info, dir string) *mount.Info { - for _, m := range mountinfo { - if m.Mountpoint == dir { - return m - } - } - return nil -} - -// Get the source mount point of directory passed in as argument. Also return -// optional fields. -func getSourceMount(source string) (string, string, error) { - // Ensure any symlinks are resolved. - sourcePath, err := filepath.EvalSymlinks(source) - if err != nil { - return "", "", err - } - - mountinfos, err := mount.GetMounts() - if err != nil { - return "", "", err - } - - mountinfo := getMountInfo(mountinfos, sourcePath) - if mountinfo != nil { - return sourcePath, mountinfo.Optional, nil - } - - path := sourcePath - for { - path = filepath.Dir(path) - - mountinfo = getMountInfo(mountinfos, path) - if mountinfo != nil { - return path, mountinfo.Optional, nil - } - - if path == "/" { - break - } - } - - // If we are here, we did not find parent mount. Something is wrong. - return "", "", fmt.Errorf("Could not find source mount of %s", source) -} - -// Ensure mount point on which path is mounted, is shared. -func ensureShared(path string) error { - sharedMount := false - - sourceMount, optionalOpts, err := getSourceMount(path) - if err != nil { - return err - } - // Make sure source mount point is shared. - optsSplit := strings.Split(optionalOpts, " ") - for _, opt := range optsSplit { - if strings.HasPrefix(opt, "shared:") { - sharedMount = true - break - } - } - - if !sharedMount { - return fmt.Errorf("Path %s is mounted on %s but it is not a shared mount.", path, sourceMount) - } - return nil -} - -// Ensure mount point on which path is mounted, is either shared or slave. -func ensureSharedOrSlave(path string) error { - sharedMount := false - slaveMount := false - - sourceMount, optionalOpts, err := getSourceMount(path) - if err != nil { - return err - } - // Make sure source mount point is shared. - optsSplit := strings.Split(optionalOpts, " ") - for _, opt := range optsSplit { - if strings.HasPrefix(opt, "shared:") { - sharedMount = true - break - } else if strings.HasPrefix(opt, "master:") { - slaveMount = true - break - } - } - - if !sharedMount && !slaveMount { - return fmt.Errorf("Path %s is mounted on %s but it is not a shared or slave mount.", path, sourceMount) - } - return nil -} - -var ( - mountPropagationMap = map[string]int{ - "private": mount.PRIVATE, - "rprivate": mount.RPRIVATE, - "shared": mount.SHARED, - "rshared": mount.RSHARED, - "slave": mount.SLAVE, - "rslave": mount.RSLAVE, - } - - mountPropagationReverseMap = map[int]string{ - mount.PRIVATE: "private", - mount.RPRIVATE: "rprivate", - mount.SHARED: "shared", - mount.RSHARED: "rshared", - mount.SLAVE: "slave", - mount.RSLAVE: "rslave", - } -) - -func setMounts(daemon *Daemon, s *specs.Spec, c *container.Container, mounts []container.Mount) error { - userMounts := make(map[string]struct{}) - for _, m := range mounts { - userMounts[m.Destination] = struct{}{} - } - - // Filter out mounts that are overridden by user supplied mounts - var defaultMounts []specs.Mount - _, mountDev := userMounts["/dev"] - for _, m := range s.Mounts { - if _, ok := userMounts[m.Destination]; !ok { - if mountDev && strings.HasPrefix(m.Destination, "/dev/") { - continue - } - defaultMounts = append(defaultMounts, m) - } - } - - s.Mounts = defaultMounts - for _, m := range mounts { - for _, cm := range s.Mounts { - if cm.Destination == m.Destination { - return fmt.Errorf("Duplicate mount point '%s'", m.Destination) - } - } - - if m.Source == "tmpfs" { - data := m.Data - options := []string{"noexec", "nosuid", "nodev", string(volume.DefaultPropagationMode)} - if data != "" { - options = append(options, strings.Split(data, ",")...) - } - - merged, err := mount.MergeTmpfsOptions(options) - if err != nil { - return err - } - - s.Mounts = append(s.Mounts, specs.Mount{Destination: m.Destination, Source: m.Source, Type: "tmpfs", Options: merged}) - continue - } - - mt := specs.Mount{Destination: m.Destination, Source: m.Source, Type: "bind"} - - // Determine property of RootPropagation based on volume - // properties. If a volume is shared, then keep root propagation - // shared. This should work for slave and private volumes too. - // - // For slave volumes, it can be either [r]shared/[r]slave. - // - // For private volumes any root propagation value should work. - pFlag := mountPropagationMap[m.Propagation] - if pFlag == mount.SHARED || pFlag == mount.RSHARED { - if err := ensureShared(m.Source); err != nil { - return err - } - rootpg := mountPropagationMap[s.Linux.RootfsPropagation] - if rootpg != mount.SHARED && rootpg != mount.RSHARED { - s.Linux.RootfsPropagation = mountPropagationReverseMap[mount.SHARED] - } - } else if pFlag == mount.SLAVE || pFlag == mount.RSLAVE { - if err := ensureSharedOrSlave(m.Source); err != nil { - return err - } - rootpg := mountPropagationMap[s.Linux.RootfsPropagation] - if rootpg != mount.SHARED && rootpg != mount.RSHARED && rootpg != mount.SLAVE && rootpg != mount.RSLAVE { - s.Linux.RootfsPropagation = mountPropagationReverseMap[mount.RSLAVE] - } - } - - opts := []string{"rbind"} - if !m.Writable { - opts = append(opts, "ro") - } - if pFlag != 0 { - opts = append(opts, mountPropagationReverseMap[pFlag]) - } - - mt.Options = opts - s.Mounts = append(s.Mounts, mt) - } - - if s.Root.Readonly { - for i, m := range s.Mounts { - switch m.Destination { - case "/proc", "/dev/pts", "/dev/mqueue": // /dev is remounted by runc - continue - } - if _, ok := userMounts[m.Destination]; !ok { - if !stringutils.InSlice(m.Options, "ro") { - s.Mounts[i].Options = append(s.Mounts[i].Options, "ro") - } - } - } - } - - if c.HostConfig.Privileged { - if !s.Root.Readonly { - // clear readonly for /sys - for i := range s.Mounts { - if s.Mounts[i].Destination == "/sys" { - clearReadOnly(&s.Mounts[i]) - } - } - } - s.Linux.ReadonlyPaths = nil - s.Linux.MaskedPaths = nil - } - - // TODO: until a kernel/mount solution exists for handling remount in a user namespace, - // we must clear the readonly flag for the cgroups mount (@mrunalp concurs) - if uidMap, _ := daemon.GetUIDGIDMaps(); uidMap != nil || c.HostConfig.Privileged { - for i, m := range s.Mounts { - if m.Type == "cgroup" { - clearReadOnly(&s.Mounts[i]) - } - } - } - - return nil -} - -func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container) error { - linkedEnv, err := daemon.setupLinkedContainers(c) - if err != nil { - return err - } - s.Root = specs.Root{ - Path: c.BaseFS, - Readonly: c.HostConfig.ReadonlyRootfs, - } - rootUID, rootGID := daemon.GetRemappedUIDGID() - if err := c.SetupWorkingDirectory(rootUID, rootGID); err != nil { - return err - } - cwd := c.Config.WorkingDir - if len(cwd) == 0 { - cwd = "/" - } - s.Process.Args = append([]string{c.Path}, c.Args...) - - // only add the custom init if it is specified and the container is running in its - // own private pid namespace. It does not make sense to add if it is running in the - // host namespace or another container's pid namespace where we already have an init - if c.HostConfig.PidMode.IsPrivate() { - if (c.HostConfig.Init != nil && *c.HostConfig.Init) || - (c.HostConfig.Init == nil && daemon.configStore.Init) { - s.Process.Args = append([]string{"/dev/init", "--", c.Path}, c.Args...) - var path string - if daemon.configStore.InitPath == "" && c.HostConfig.InitPath == "" { - path, err = exec.LookPath(DefaultInitBinary) - if err != nil { - return err - } - } - if daemon.configStore.InitPath != "" { - path = daemon.configStore.InitPath - } - if c.HostConfig.InitPath != "" { - path = c.HostConfig.InitPath - } - s.Mounts = append(s.Mounts, specs.Mount{ - Destination: "/dev/init", - Type: "bind", - Source: path, - Options: []string{"bind", "ro"}, - }) - } - } - s.Process.Cwd = cwd - s.Process.Env = c.CreateDaemonEnvironment(c.Config.Tty, linkedEnv) - s.Process.Terminal = c.Config.Tty - s.Hostname = c.FullHostname() - - return nil -} - -func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) { - s := oci.DefaultSpec() - if err := daemon.populateCommonSpec(&s, c); err != nil { - return nil, err - } - - var cgroupsPath string - scopePrefix := "docker" - parent := "/docker" - useSystemd := UsingSystemd(daemon.configStore) - if useSystemd { - parent = "system.slice" - } - - if c.HostConfig.CgroupParent != "" { - parent = c.HostConfig.CgroupParent - } else if daemon.configStore.CgroupParent != "" { - parent = daemon.configStore.CgroupParent - } - - if useSystemd { - cgroupsPath = parent + ":" + scopePrefix + ":" + c.ID - logrus.Debugf("createSpec: cgroupsPath: %s", cgroupsPath) - } else { - cgroupsPath = filepath.Join(parent, c.ID) - } - s.Linux.CgroupsPath = &cgroupsPath - - if err := setResources(&s, c.HostConfig.Resources); err != nil { - return nil, fmt.Errorf("linux runtime spec resources: %v", err) - } - s.Linux.Resources.OOMScoreAdj = &c.HostConfig.OomScoreAdj - s.Linux.Sysctl = c.HostConfig.Sysctls - - p := *s.Linux.CgroupsPath - if useSystemd { - initPath, err := cgroups.GetInitCgroupDir("cpu") - if err != nil { - return nil, err - } - p, _ = cgroups.GetThisCgroupDir("cpu") - if err != nil { - return nil, err - } - p = filepath.Join(initPath, p) - } - - // Clean path to guard against things like ../../../BAD - parentPath := filepath.Dir(p) - if !filepath.IsAbs(parentPath) { - parentPath = filepath.Clean("/" + parentPath) - } - - if err := daemon.initCgroupsPath(parentPath); err != nil { - return nil, fmt.Errorf("linux init cgroups path: %v", err) - } - if err := setDevices(&s, c); err != nil { - return nil, fmt.Errorf("linux runtime spec devices: %v", err) - } - if err := setRlimits(daemon, &s, c); err != nil { - return nil, fmt.Errorf("linux runtime spec rlimits: %v", err) - } - if err := setUser(&s, c); err != nil { - return nil, fmt.Errorf("linux spec user: %v", err) - } - if err := setNamespaces(daemon, &s, c); err != nil { - return nil, fmt.Errorf("linux spec namespaces: %v", err) - } - if err := setCapabilities(&s, c); err != nil { - return nil, fmt.Errorf("linux spec capabilities: %v", err) - } - if err := setSeccomp(daemon, &s, c); err != nil { - return nil, fmt.Errorf("linux seccomp: %v", err) - } - - if err := daemon.setupIpcDirs(c); err != nil { - return nil, err - } - - if err := daemon.setupSecretDir(c); err != nil { - return nil, err - } - - ms, err := daemon.setupMounts(c) - if err != nil { - return nil, err - } - - ms = append(ms, c.IpcMounts()...) - - tmpfsMounts, err := c.TmpfsMounts() - if err != nil { - return nil, err - } - ms = append(ms, tmpfsMounts...) - - if m := c.SecretMount(); m != nil { - ms = append(ms, *m) - } - - sort.Sort(mounts(ms)) - if err := setMounts(daemon, &s, c, ms); err != nil { - return nil, fmt.Errorf("linux mounts: %v", err) - } - - for _, ns := range s.Linux.Namespaces { - if ns.Type == "network" && ns.Path == "" && !c.Config.NetworkDisabled { - target, err := os.Readlink(filepath.Join("/proc", strconv.Itoa(os.Getpid()), "exe")) - if err != nil { - return nil, err - } - - s.Hooks = specs.Hooks{ - Prestart: []specs.Hook{{ - Path: target, // FIXME: cross-platform - Args: []string{"libnetwork-setkey", c.ID, daemon.netController.ID()}, - }}, - } - } - } - - if apparmor.IsEnabled() { - var appArmorProfile string - if c.AppArmorProfile != "" { - appArmorProfile = c.AppArmorProfile - } else if c.HostConfig.Privileged { - appArmorProfile = "unconfined" - } else { - appArmorProfile = "docker-default" - } - - if appArmorProfile == "docker-default" { - // Unattended upgrades and other fun services can unload AppArmor - // profiles inadvertently. Since we cannot store our profile in - // /etc/apparmor.d, nor can we practically add other ways of - // telling the system to keep our profile loaded, in order to make - // sure that we keep the default profile enabled we dynamically - // reload it if necessary. - if err := ensureDefaultAppArmorProfile(); err != nil { - return nil, err - } - } - - s.Process.ApparmorProfile = appArmorProfile - } - s.Process.SelinuxLabel = c.GetProcessLabel() - s.Process.NoNewPrivileges = c.NoNewPrivileges - s.Linux.MountLabel = c.MountLabel - - return (*specs.Spec)(&s), nil -} - -func clearReadOnly(m *specs.Mount) { - var opt []string - for _, o := range m.Options { - if o != "ro" { - opt = append(opt, o) - } - } - m.Options = opt -} - -// mergeUlimits merge the Ulimits from HostConfig with daemon defaults, and update HostConfig -func (daemon *Daemon) mergeUlimits(c *containertypes.HostConfig) { - ulimits := c.Ulimits - // Merge ulimits with daemon defaults - ulIdx := make(map[string]struct{}) - for _, ul := range ulimits { - ulIdx[ul.Name] = struct{}{} - } - for name, ul := range daemon.configStore.Ulimits { - if _, exists := ulIdx[name]; !exists { - ulimits = append(ulimits, ul) - } - } - c.Ulimits = ulimits -} diff --git a/vendor/github.com/docker/docker/daemon/oci_solaris.go b/vendor/github.com/docker/docker/daemon/oci_solaris.go deleted file mode 100644 index 0c757f9..0000000 --- a/vendor/github.com/docker/docker/daemon/oci_solaris.go +++ /dev/null @@ -1,188 +0,0 @@ -package daemon - -import ( - "fmt" - "path/filepath" - "sort" - "strconv" - - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/oci" - "github.com/docker/libnetwork" - "github.com/opencontainers/runtime-spec/specs-go" -) - -func setResources(s *specs.Spec, r containertypes.Resources) error { - mem := getMemoryResources(r) - s.Solaris.CappedMemory = &mem - - capCPU := getCPUResources(r) - s.Solaris.CappedCPU = &capCPU - - return nil -} - -func setUser(s *specs.Spec, c *container.Container) error { - uid, gid, additionalGids, err := getUser(c, c.Config.User) - if err != nil { - return err - } - s.Process.User.UID = uid - s.Process.User.GID = gid - s.Process.User.AdditionalGids = additionalGids - return nil -} - -func getUser(c *container.Container, username string) (uint32, uint32, []uint32, error) { - return 0, 0, nil, nil -} - -func (daemon *Daemon) getRunzAnet(ep libnetwork.Endpoint) (specs.Anet, error) { - var ( - linkName string - lowerLink string - defRouter string - ) - - epInfo := ep.Info() - if epInfo == nil { - return specs.Anet{}, fmt.Errorf("invalid endpoint") - } - - nw, err := daemon.GetNetworkByName(ep.Network()) - if err != nil { - return specs.Anet{}, fmt.Errorf("Failed to get network %s: %v", ep.Network(), err) - } - - // Evaluate default router, linkname and lowerlink for interface endpoint - switch nw.Type() { - case "bridge": - defRouter = epInfo.Gateway().String() - linkName = "net0" // Should always be net0 for a container - - // TODO We construct lowerlink here exactly as done for solaris bridge - // initialization. Need modular code to reuse. - options := nw.Info().DriverOptions() - nwName := options["com.docker.network.bridge.name"] - lastChar := nwName[len(nwName)-1:] - if _, err = strconv.Atoi(lastChar); err != nil { - lowerLink = nwName + "_0" - } else { - lowerLink = nwName - } - - case "overlay": - defRouter = "" - linkName = "net1" - - // TODO Follows generateVxlanName() in solaris overlay. - id := nw.ID() - if len(nw.ID()) > 12 { - id = nw.ID()[:12] - } - lowerLink = "vx_" + id + "_0" - } - - runzanet := specs.Anet{ - Linkname: linkName, - Lowerlink: lowerLink, - Allowedaddr: epInfo.Iface().Address().String(), - Configallowedaddr: "true", - Defrouter: defRouter, - Linkprotection: "mac-nospoof, ip-nospoof", - Macaddress: epInfo.Iface().MacAddress().String(), - } - - return runzanet, nil -} - -func (daemon *Daemon) setNetworkInterface(s *specs.Spec, c *container.Container) error { - var anets []specs.Anet - - sb, err := daemon.netController.SandboxByID(c.NetworkSettings.SandboxID) - if err != nil { - return fmt.Errorf("Could not obtain sandbox for container") - } - - // Populate interfaces required for each endpoint - for _, ep := range sb.Endpoints() { - runzanet, err := daemon.getRunzAnet(ep) - if err != nil { - return fmt.Errorf("Failed to get interface information for endpoint %d: %v", ep.ID(), err) - } - anets = append(anets, runzanet) - } - - s.Solaris.Anet = anets - if anets != nil { - s.Solaris.Milestone = "svc:/milestone/container:default" - } - return nil -} - -func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container) error { - linkedEnv, err := daemon.setupLinkedContainers(c) - if err != nil { - return err - } - s.Root = specs.Root{ - Path: filepath.Dir(c.BaseFS), - Readonly: c.HostConfig.ReadonlyRootfs, - } - rootUID, rootGID := daemon.GetRemappedUIDGID() - if err := c.SetupWorkingDirectory(rootUID, rootGID); err != nil { - return err - } - cwd := c.Config.WorkingDir - s.Process.Args = append([]string{c.Path}, c.Args...) - s.Process.Cwd = cwd - s.Process.Env = c.CreateDaemonEnvironment(c.Config.Tty, linkedEnv) - s.Process.Terminal = c.Config.Tty - s.Hostname = c.FullHostname() - - return nil -} - -func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) { - s := oci.DefaultSpec() - if err := daemon.populateCommonSpec(&s, c); err != nil { - return nil, err - } - - if err := setResources(&s, c.HostConfig.Resources); err != nil { - return nil, fmt.Errorf("runtime spec resources: %v", err) - } - - if err := setUser(&s, c); err != nil { - return nil, fmt.Errorf("spec user: %v", err) - } - - if err := daemon.setNetworkInterface(&s, c); err != nil { - return nil, err - } - - if err := daemon.setupIpcDirs(c); err != nil { - return nil, err - } - - ms, err := daemon.setupMounts(c) - if err != nil { - return nil, err - } - ms = append(ms, c.IpcMounts()...) - tmpfsMounts, err := c.TmpfsMounts() - if err != nil { - return nil, err - } - ms = append(ms, tmpfsMounts...) - sort.Sort(mounts(ms)) - - return (*specs.Spec)(&s), nil -} - -// mergeUlimits merge the Ulimits from HostConfig with daemon defaults, and update HostConfig -// It will do nothing on non-Linux platform -func (daemon *Daemon) mergeUlimits(c *containertypes.HostConfig) { - return -} diff --git a/vendor/github.com/docker/docker/daemon/oci_windows.go b/vendor/github.com/docker/docker/daemon/oci_windows.go deleted file mode 100644 index 6e26424..0000000 --- a/vendor/github.com/docker/docker/daemon/oci_windows.go +++ /dev/null @@ -1,122 +0,0 @@ -package daemon - -import ( - "syscall" - - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/oci" - "github.com/docker/docker/pkg/sysinfo" - "github.com/opencontainers/runtime-spec/specs-go" -) - -func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) { - s := oci.DefaultSpec() - - linkedEnv, err := daemon.setupLinkedContainers(c) - if err != nil { - return nil, err - } - - // Note, unlike Unix, we do NOT call into SetupWorkingDirectory as - // this is done in VMCompute. Further, we couldn't do it for Hyper-V - // containers anyway. - - // In base spec - s.Hostname = c.FullHostname() - - // In s.Mounts - mounts, err := daemon.setupMounts(c) - if err != nil { - return nil, err - } - for _, mount := range mounts { - m := specs.Mount{ - Source: mount.Source, - Destination: mount.Destination, - } - if !mount.Writable { - m.Options = append(m.Options, "ro") - } - s.Mounts = append(s.Mounts, m) - } - - // In s.Process - s.Process.Args = append([]string{c.Path}, c.Args...) - if !c.Config.ArgsEscaped { - s.Process.Args = escapeArgs(s.Process.Args) - } - s.Process.Cwd = c.Config.WorkingDir - if len(s.Process.Cwd) == 0 { - // We default to C:\ to workaround the oddity of the case that the - // default directory for cmd running as LocalSystem (or - // ContainerAdministrator) is c:\windows\system32. Hence docker run - // cmd will by default end in c:\windows\system32, rather - // than 'root' (/) on Linux. The oddity is that if you have a dockerfile - // which has no WORKDIR and has a COPY file ., . will be interpreted - // as c:\. Hence, setting it to default of c:\ makes for consistency. - s.Process.Cwd = `C:\` - } - s.Process.Env = c.CreateDaemonEnvironment(c.Config.Tty, linkedEnv) - s.Process.ConsoleSize.Height = c.HostConfig.ConsoleSize[0] - s.Process.ConsoleSize.Width = c.HostConfig.ConsoleSize[1] - s.Process.Terminal = c.Config.Tty - s.Process.User.Username = c.Config.User - - // In spec.Root. This is not set for Hyper-V containers - isHyperV := false - if c.HostConfig.Isolation.IsDefault() { - // Container using default isolation, so take the default from the daemon configuration - isHyperV = daemon.defaultIsolation.IsHyperV() - } else { - // Container may be requesting an explicit isolation mode. - isHyperV = c.HostConfig.Isolation.IsHyperV() - } - if !isHyperV { - s.Root.Path = c.BaseFS - } - s.Root.Readonly = false // Windows does not support a read-only root filesystem - - // In s.Windows.Resources - // @darrenstahlmsft implement these resources - cpuShares := uint16(c.HostConfig.CPUShares) - cpuPercent := uint8(c.HostConfig.CPUPercent) - if c.HostConfig.NanoCPUs > 0 { - cpuPercent = uint8(c.HostConfig.NanoCPUs * 100 / int64(sysinfo.NumCPU()) / 1e9) - } - cpuCount := uint64(c.HostConfig.CPUCount) - memoryLimit := uint64(c.HostConfig.Memory) - s.Windows.Resources = &specs.WindowsResources{ - CPU: &specs.WindowsCPUResources{ - Percent: &cpuPercent, - Shares: &cpuShares, - Count: &cpuCount, - }, - Memory: &specs.WindowsMemoryResources{ - Limit: &memoryLimit, - //TODO Reservation: ..., - }, - Network: &specs.WindowsNetworkResources{ - //TODO Bandwidth: ..., - }, - Storage: &specs.WindowsStorageResources{ - Bps: &c.HostConfig.IOMaximumBandwidth, - Iops: &c.HostConfig.IOMaximumIOps, - }, - } - return (*specs.Spec)(&s), nil -} - -func escapeArgs(args []string) []string { - escapedArgs := make([]string, len(args)) - for i, a := range args { - escapedArgs[i] = syscall.EscapeArg(a) - } - return escapedArgs -} - -// mergeUlimits merge the Ulimits from HostConfig with daemon defaults, and update HostConfig -// It will do nothing on non-Linux platform -func (daemon *Daemon) mergeUlimits(c *containertypes.HostConfig) { - return -} diff --git a/vendor/github.com/docker/docker/daemon/pause.go b/vendor/github.com/docker/docker/daemon/pause.go deleted file mode 100644 index dbfafbc..0000000 --- a/vendor/github.com/docker/docker/daemon/pause.go +++ /dev/null @@ -1,49 +0,0 @@ -package daemon - -import ( - "fmt" - - "github.com/docker/docker/container" -) - -// ContainerPause pauses a container -func (daemon *Daemon) ContainerPause(name string) error { - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - if err := daemon.containerPause(container); err != nil { - return err - } - - return nil -} - -// containerPause pauses the container execution without stopping the process. -// The execution can be resumed by calling containerUnpause. -func (daemon *Daemon) containerPause(container *container.Container) error { - container.Lock() - defer container.Unlock() - - // We cannot Pause the container which is not running - if !container.Running { - return errNotRunning{container.ID} - } - - // We cannot Pause the container which is already paused - if container.Paused { - return fmt.Errorf("Container %s is already paused", container.ID) - } - - // We cannot Pause the container which is restarting - if container.Restarting { - return errContainerIsRestarting(container.ID) - } - - if err := daemon.containerd.Pause(container.ID); err != nil { - return fmt.Errorf("Cannot pause container %s: %s", container.ID, err) - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/prune.go b/vendor/github.com/docker/docker/daemon/prune.go deleted file mode 100644 index a693beb..0000000 --- a/vendor/github.com/docker/docker/daemon/prune.go +++ /dev/null @@ -1,236 +0,0 @@ -package daemon - -import ( - "fmt" - "regexp" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/directory" - "github.com/docker/docker/reference" - "github.com/docker/docker/runconfig" - "github.com/docker/docker/volume" - "github.com/docker/libnetwork" -) - -// ContainersPrune removes unused containers -func (daemon *Daemon) ContainersPrune(pruneFilters filters.Args) (*types.ContainersPruneReport, error) { - rep := &types.ContainersPruneReport{} - - allContainers := daemon.List() - for _, c := range allContainers { - if !c.IsRunning() { - cSize, _ := daemon.getSize(c) - // TODO: sets RmLink to true? - err := daemon.ContainerRm(c.ID, &types.ContainerRmConfig{}) - if err != nil { - logrus.Warnf("failed to prune container %s: %v", c.ID, err) - continue - } - if cSize > 0 { - rep.SpaceReclaimed += uint64(cSize) - } - rep.ContainersDeleted = append(rep.ContainersDeleted, c.ID) - } - } - - return rep, nil -} - -// VolumesPrune removes unused local volumes -func (daemon *Daemon) VolumesPrune(pruneFilters filters.Args) (*types.VolumesPruneReport, error) { - rep := &types.VolumesPruneReport{} - - pruneVols := func(v volume.Volume) error { - name := v.Name() - refs := daemon.volumes.Refs(v) - - if len(refs) == 0 { - vSize, err := directory.Size(v.Path()) - if err != nil { - logrus.Warnf("could not determine size of volume %s: %v", name, err) - } - err = daemon.volumes.Remove(v) - if err != nil { - logrus.Warnf("could not remove volume %s: %v", name, err) - return nil - } - rep.SpaceReclaimed += uint64(vSize) - rep.VolumesDeleted = append(rep.VolumesDeleted, name) - } - - return nil - } - - err := daemon.traverseLocalVolumes(pruneVols) - - return rep, err -} - -// ImagesPrune removes unused images -func (daemon *Daemon) ImagesPrune(pruneFilters filters.Args) (*types.ImagesPruneReport, error) { - rep := &types.ImagesPruneReport{} - - danglingOnly := true - if pruneFilters.Include("dangling") { - if pruneFilters.ExactMatch("dangling", "false") || pruneFilters.ExactMatch("dangling", "0") { - danglingOnly = false - } else if !pruneFilters.ExactMatch("dangling", "true") && !pruneFilters.ExactMatch("dangling", "1") { - return nil, fmt.Errorf("Invalid filter 'dangling=%s'", pruneFilters.Get("dangling")) - } - } - - var allImages map[image.ID]*image.Image - if danglingOnly { - allImages = daemon.imageStore.Heads() - } else { - allImages = daemon.imageStore.Map() - } - allContainers := daemon.List() - imageRefs := map[string]bool{} - for _, c := range allContainers { - imageRefs[c.ID] = true - } - - // Filter intermediary images and get their unique size - allLayers := daemon.layerStore.Map() - topImages := map[image.ID]*image.Image{} - for id, img := range allImages { - dgst := digest.Digest(id) - if len(daemon.referenceStore.References(dgst)) == 0 && len(daemon.imageStore.Children(id)) != 0 { - continue - } - topImages[id] = img - } - - for id := range topImages { - dgst := digest.Digest(id) - hex := dgst.Hex() - if _, ok := imageRefs[hex]; ok { - continue - } - - deletedImages := []types.ImageDelete{} - refs := daemon.referenceStore.References(dgst) - if len(refs) > 0 { - if danglingOnly { - // Not a dangling image - continue - } - - nrRefs := len(refs) - for _, ref := range refs { - // If nrRefs == 1, we have an image marked as myreponame: - // i.e. the tag content was changed - if _, ok := ref.(reference.Canonical); ok && nrRefs > 1 { - continue - } - imgDel, err := daemon.ImageDelete(ref.String(), false, true) - if err != nil { - logrus.Warnf("could not delete reference %s: %v", ref.String(), err) - continue - } - deletedImages = append(deletedImages, imgDel...) - } - } else { - imgDel, err := daemon.ImageDelete(hex, false, true) - if err != nil { - logrus.Warnf("could not delete image %s: %v", hex, err) - continue - } - deletedImages = append(deletedImages, imgDel...) - } - - rep.ImagesDeleted = append(rep.ImagesDeleted, deletedImages...) - } - - // Compute how much space was freed - for _, d := range rep.ImagesDeleted { - if d.Deleted != "" { - chid := layer.ChainID(d.Deleted) - if l, ok := allLayers[chid]; ok { - diffSize, err := l.DiffSize() - if err != nil { - logrus.Warnf("failed to get layer %s size: %v", chid, err) - continue - } - rep.SpaceReclaimed += uint64(diffSize) - } - } - } - - return rep, nil -} - -// localNetworksPrune removes unused local networks -func (daemon *Daemon) localNetworksPrune(pruneFilters filters.Args) (*types.NetworksPruneReport, error) { - rep := &types.NetworksPruneReport{} - var err error - // When the function returns true, the walk will stop. - l := func(nw libnetwork.Network) bool { - nwName := nw.Name() - predefined := runconfig.IsPreDefinedNetwork(nwName) - if !predefined && len(nw.Endpoints()) == 0 { - if err = daemon.DeleteNetwork(nw.ID()); err != nil { - logrus.Warnf("could not remove network %s: %v", nwName, err) - return false - } - rep.NetworksDeleted = append(rep.NetworksDeleted, nwName) - } - return false - } - daemon.netController.WalkNetworks(l) - return rep, err -} - -// clusterNetworksPrune removes unused cluster networks -func (daemon *Daemon) clusterNetworksPrune(pruneFilters filters.Args) (*types.NetworksPruneReport, error) { - rep := &types.NetworksPruneReport{} - cluster := daemon.GetCluster() - networks, err := cluster.GetNetworks() - if err != nil { - return rep, err - } - networkIsInUse := regexp.MustCompile(`network ([[:alnum:]]+) is in use`) - for _, nw := range networks { - if nw.Name == "ingress" { - continue - } - // https://github.com/docker/docker/issues/24186 - // `docker network inspect` unfortunately displays ONLY those containers that are local to that node. - // So we try to remove it anyway and check the error - err = cluster.RemoveNetwork(nw.ID) - if err != nil { - // we can safely ignore the "network .. is in use" error - match := networkIsInUse.FindStringSubmatch(err.Error()) - if len(match) != 2 || match[1] != nw.ID { - logrus.Warnf("could not remove network %s: %v", nw.Name, err) - } - continue - } - rep.NetworksDeleted = append(rep.NetworksDeleted, nw.Name) - } - return rep, nil -} - -// NetworksPrune removes unused networks -func (daemon *Daemon) NetworksPrune(pruneFilters filters.Args) (*types.NetworksPruneReport, error) { - rep := &types.NetworksPruneReport{} - clusterRep, err := daemon.clusterNetworksPrune(pruneFilters) - if err != nil { - logrus.Warnf("could not remove cluster networks: %v", err) - } else { - rep.NetworksDeleted = append(rep.NetworksDeleted, clusterRep.NetworksDeleted...) - } - localRep, err := daemon.localNetworksPrune(pruneFilters) - if err != nil { - logrus.Warnf("could not remove local networks: %v", err) - } else { - rep.NetworksDeleted = append(rep.NetworksDeleted, localRep.NetworksDeleted...) - } - return rep, err -} diff --git a/vendor/github.com/docker/docker/daemon/rename.go b/vendor/github.com/docker/docker/daemon/rename.go deleted file mode 100644 index ffb7715..0000000 --- a/vendor/github.com/docker/docker/daemon/rename.go +++ /dev/null @@ -1,122 +0,0 @@ -package daemon - -import ( - "fmt" - "strings" - - "github.com/Sirupsen/logrus" - dockercontainer "github.com/docker/docker/container" - "github.com/docker/libnetwork" -) - -// ContainerRename changes the name of a container, using the oldName -// to find the container. An error is returned if newName is already -// reserved. -func (daemon *Daemon) ContainerRename(oldName, newName string) error { - var ( - sid string - sb libnetwork.Sandbox - ) - - if oldName == "" || newName == "" { - return fmt.Errorf("Neither old nor new names may be empty") - } - - if newName[0] != '/' { - newName = "/" + newName - } - - container, err := daemon.GetContainer(oldName) - if err != nil { - return err - } - - oldName = container.Name - oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint - - if oldName == newName { - return fmt.Errorf("Renaming a container with the same name as its current name") - } - - container.Lock() - defer container.Unlock() - - links := map[string]*dockercontainer.Container{} - for k, v := range daemon.linkIndex.children(container) { - if !strings.HasPrefix(k, oldName) { - return fmt.Errorf("Linked container %s does not match parent %s", k, oldName) - } - links[strings.TrimPrefix(k, oldName)] = v - } - - if newName, err = daemon.reserveName(container.ID, newName); err != nil { - return fmt.Errorf("Error when allocating new name: %v", err) - } - - for k, v := range links { - daemon.nameIndex.Reserve(newName+k, v.ID) - daemon.linkIndex.link(container, v, newName+k) - } - - container.Name = newName - container.NetworkSettings.IsAnonymousEndpoint = false - - defer func() { - if err != nil { - container.Name = oldName - container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint - daemon.reserveName(container.ID, oldName) - for k, v := range links { - daemon.nameIndex.Reserve(oldName+k, v.ID) - daemon.linkIndex.link(container, v, oldName+k) - daemon.linkIndex.unlink(newName+k, v, container) - daemon.nameIndex.Release(newName + k) - } - daemon.releaseName(newName) - } - }() - - for k, v := range links { - daemon.linkIndex.unlink(oldName+k, v, container) - daemon.nameIndex.Release(oldName + k) - } - daemon.releaseName(oldName) - if err = container.ToDisk(); err != nil { - return err - } - - attributes := map[string]string{ - "oldName": oldName, - } - - if !container.Running { - daemon.LogContainerEventWithAttributes(container, "rename", attributes) - return nil - } - - defer func() { - if err != nil { - container.Name = oldName - container.NetworkSettings.IsAnonymousEndpoint = oldIsAnonymousEndpoint - if e := container.ToDisk(); e != nil { - logrus.Errorf("%s: Failed in writing to Disk on rename failure: %v", container.ID, e) - } - } - }() - - sid = container.NetworkSettings.SandboxID - if daemon.netController != nil { - sb, err = daemon.netController.SandboxByID(sid) - if err != nil { - return err - } - - err = sb.Rename(strings.TrimPrefix(container.Name, "/")) - if err != nil { - return err - } - } - - daemon.LogContainerEventWithAttributes(container, "rename", attributes) - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/resize.go b/vendor/github.com/docker/docker/daemon/resize.go deleted file mode 100644 index 7473538..0000000 --- a/vendor/github.com/docker/docker/daemon/resize.go +++ /dev/null @@ -1,40 +0,0 @@ -package daemon - -import ( - "fmt" - - "github.com/docker/docker/libcontainerd" -) - -// ContainerResize changes the size of the TTY of the process running -// in the container with the given name to the given height and width. -func (daemon *Daemon) ContainerResize(name string, height, width int) error { - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - if !container.IsRunning() { - return errNotRunning{container.ID} - } - - if err = daemon.containerd.Resize(container.ID, libcontainerd.InitFriendlyName, width, height); err == nil { - attributes := map[string]string{ - "height": fmt.Sprintf("%d", height), - "width": fmt.Sprintf("%d", width), - } - daemon.LogContainerEventWithAttributes(container, "resize", attributes) - } - return err -} - -// ContainerExecResize changes the size of the TTY of the process -// running in the exec with the given name to the given height and -// width. -func (daemon *Daemon) ContainerExecResize(name string, height, width int) error { - ec, err := daemon.getExecConfig(name) - if err != nil { - return err - } - return daemon.containerd.Resize(ec.ContainerID, ec.ID, width, height) -} diff --git a/vendor/github.com/docker/docker/daemon/restart.go b/vendor/github.com/docker/docker/daemon/restart.go deleted file mode 100644 index 79292f3..0000000 --- a/vendor/github.com/docker/docker/daemon/restart.go +++ /dev/null @@ -1,70 +0,0 @@ -package daemon - -import ( - "fmt" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/container" -) - -// ContainerRestart stops and starts a container. It attempts to -// gracefully stop the container within the given timeout, forcefully -// stopping it if the timeout is exceeded. If given a negative -// timeout, ContainerRestart will wait forever until a graceful -// stop. Returns an error if the container cannot be found, or if -// there is an underlying error at any stage of the restart. -func (daemon *Daemon) ContainerRestart(name string, seconds *int) error { - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - if seconds == nil { - stopTimeout := container.StopTimeout() - seconds = &stopTimeout - } - if err := daemon.containerRestart(container, *seconds); err != nil { - return fmt.Errorf("Cannot restart container %s: %v", name, err) - } - return nil - -} - -// containerRestart attempts to gracefully stop and then start the -// container. When stopping, wait for the given duration in seconds to -// gracefully stop, before forcefully terminating the container. If -// given a negative duration, wait forever for a graceful stop. -func (daemon *Daemon) containerRestart(container *container.Container, seconds int) error { - // Avoid unnecessarily unmounting and then directly mounting - // the container when the container stops and then starts - // again - if err := daemon.Mount(container); err == nil { - defer daemon.Unmount(container) - } - - if container.IsRunning() { - // set AutoRemove flag to false before stop so the container won't be - // removed during restart process - autoRemove := container.HostConfig.AutoRemove - - container.HostConfig.AutoRemove = false - err := daemon.containerStop(container, seconds) - // restore AutoRemove irrespective of whether the stop worked or not - container.HostConfig.AutoRemove = autoRemove - // containerStop will write HostConfig to disk, we shall restore AutoRemove - // in disk too - if toDiskErr := container.ToDiskLocking(); toDiskErr != nil { - logrus.Errorf("Write container to disk error: %v", toDiskErr) - } - - if err != nil { - return err - } - } - - if err := daemon.containerStart(container, "", "", true); err != nil { - return err - } - - daemon.LogContainerEvent(container, "restart") - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/search.go b/vendor/github.com/docker/docker/daemon/search.go deleted file mode 100644 index 5d2ac5d..0000000 --- a/vendor/github.com/docker/docker/daemon/search.go +++ /dev/null @@ -1,94 +0,0 @@ -package daemon - -import ( - "fmt" - "strconv" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/dockerversion" -) - -var acceptedSearchFilterTags = map[string]bool{ - "is-automated": true, - "is-official": true, - "stars": true, -} - -// SearchRegistryForImages queries the registry for images matching -// term. authConfig is used to login. -func (daemon *Daemon) SearchRegistryForImages(ctx context.Context, filtersArgs string, term string, limit int, - authConfig *types.AuthConfig, - headers map[string][]string) (*registrytypes.SearchResults, error) { - - searchFilters, err := filters.FromParam(filtersArgs) - if err != nil { - return nil, err - } - if err := searchFilters.Validate(acceptedSearchFilterTags); err != nil { - return nil, err - } - - var isAutomated, isOfficial bool - var hasStarFilter = 0 - if searchFilters.Include("is-automated") { - if searchFilters.UniqueExactMatch("is-automated", "true") { - isAutomated = true - } else if !searchFilters.UniqueExactMatch("is-automated", "false") { - return nil, fmt.Errorf("Invalid filter 'is-automated=%s'", searchFilters.Get("is-automated")) - } - } - if searchFilters.Include("is-official") { - if searchFilters.UniqueExactMatch("is-official", "true") { - isOfficial = true - } else if !searchFilters.UniqueExactMatch("is-official", "false") { - return nil, fmt.Errorf("Invalid filter 'is-official=%s'", searchFilters.Get("is-official")) - } - } - if searchFilters.Include("stars") { - hasStars := searchFilters.Get("stars") - for _, hasStar := range hasStars { - iHasStar, err := strconv.Atoi(hasStar) - if err != nil { - return nil, fmt.Errorf("Invalid filter 'stars=%s'", hasStar) - } - if iHasStar > hasStarFilter { - hasStarFilter = iHasStar - } - } - } - - unfilteredResult, err := daemon.RegistryService.Search(ctx, term, limit, authConfig, dockerversion.DockerUserAgent(ctx), headers) - if err != nil { - return nil, err - } - - filteredResults := []registrytypes.SearchResult{} - for _, result := range unfilteredResult.Results { - if searchFilters.Include("is-automated") { - if isAutomated != result.IsAutomated { - continue - } - } - if searchFilters.Include("is-official") { - if isOfficial != result.IsOfficial { - continue - } - } - if searchFilters.Include("stars") { - if result.StarCount < hasStarFilter { - continue - } - } - filteredResults = append(filteredResults, result) - } - - return ®istrytypes.SearchResults{ - Query: unfilteredResult.Query, - NumResults: len(filteredResults), - Results: filteredResults, - }, nil -} diff --git a/vendor/github.com/docker/docker/daemon/search_test.go b/vendor/github.com/docker/docker/daemon/search_test.go deleted file mode 100644 index f5aa85a..0000000 --- a/vendor/github.com/docker/docker/daemon/search_test.go +++ /dev/null @@ -1,358 +0,0 @@ -package daemon - -import ( - "fmt" - "strings" - "testing" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/registry" -) - -type FakeService struct { - registry.DefaultService - - shouldReturnError bool - - term string - results []registrytypes.SearchResult -} - -func (s *FakeService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error) { - if s.shouldReturnError { - return nil, fmt.Errorf("Search unknown error") - } - return ®istrytypes.SearchResults{ - Query: s.term, - NumResults: len(s.results), - Results: s.results, - }, nil -} - -func TestSearchRegistryForImagesErrors(t *testing.T) { - errorCases := []struct { - filtersArgs string - shouldReturnError bool - expectedError string - }{ - { - expectedError: "Search unknown error", - shouldReturnError: true, - }, - { - filtersArgs: "invalid json", - expectedError: "invalid character 'i' looking for beginning of value", - }, - { - filtersArgs: `{"type":{"custom":true}}`, - expectedError: "Invalid filter 'type'", - }, - { - filtersArgs: `{"is-automated":{"invalid":true}}`, - expectedError: "Invalid filter 'is-automated=[invalid]'", - }, - { - filtersArgs: `{"is-automated":{"true":true,"false":true}}`, - expectedError: "Invalid filter 'is-automated", - }, - { - filtersArgs: `{"is-official":{"invalid":true}}`, - expectedError: "Invalid filter 'is-official=[invalid]'", - }, - { - filtersArgs: `{"is-official":{"true":true,"false":true}}`, - expectedError: "Invalid filter 'is-official", - }, - { - filtersArgs: `{"stars":{"invalid":true}}`, - expectedError: "Invalid filter 'stars=invalid'", - }, - { - filtersArgs: `{"stars":{"1":true,"invalid":true}}`, - expectedError: "Invalid filter 'stars=invalid'", - }, - } - for index, e := range errorCases { - daemon := &Daemon{ - RegistryService: &FakeService{ - shouldReturnError: e.shouldReturnError, - }, - } - _, err := daemon.SearchRegistryForImages(context.Background(), e.filtersArgs, "term", 25, nil, map[string][]string{}) - if err == nil { - t.Errorf("%d: expected an error, got nothing", index) - } - if !strings.Contains(err.Error(), e.expectedError) { - t.Errorf("%d: expected error to contain %s, got %s", index, e.expectedError, err.Error()) - } - } -} - -func TestSearchRegistryForImages(t *testing.T) { - term := "term" - successCases := []struct { - filtersArgs string - registryResults []registrytypes.SearchResult - expectedResults []registrytypes.SearchResult - }{ - { - filtersArgs: "", - registryResults: []registrytypes.SearchResult{}, - expectedResults: []registrytypes.SearchResult{}, - }, - { - filtersArgs: "", - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - }, - }, - expectedResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - }, - }, - }, - { - filtersArgs: `{"is-automated":{"true":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - }, - }, - expectedResults: []registrytypes.SearchResult{}, - }, - { - filtersArgs: `{"is-automated":{"true":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - IsAutomated: true, - }, - }, - expectedResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - IsAutomated: true, - }, - }, - }, - { - filtersArgs: `{"is-automated":{"false":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - IsAutomated: true, - }, - }, - expectedResults: []registrytypes.SearchResult{}, - }, - { - filtersArgs: `{"is-automated":{"false":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - IsAutomated: false, - }, - }, - expectedResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - IsAutomated: false, - }, - }, - }, - { - filtersArgs: `{"is-official":{"true":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - }, - }, - expectedResults: []registrytypes.SearchResult{}, - }, - { - filtersArgs: `{"is-official":{"true":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - IsOfficial: true, - }, - }, - expectedResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - IsOfficial: true, - }, - }, - }, - { - filtersArgs: `{"is-official":{"false":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - IsOfficial: true, - }, - }, - expectedResults: []registrytypes.SearchResult{}, - }, - { - filtersArgs: `{"is-official":{"false":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - IsOfficial: false, - }, - }, - expectedResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - IsOfficial: false, - }, - }, - }, - { - filtersArgs: `{"stars":{"0":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - StarCount: 0, - }, - }, - expectedResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - StarCount: 0, - }, - }, - }, - { - filtersArgs: `{"stars":{"1":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name", - Description: "description", - StarCount: 0, - }, - }, - expectedResults: []registrytypes.SearchResult{}, - }, - { - filtersArgs: `{"stars":{"1":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name0", - Description: "description0", - StarCount: 0, - }, - { - Name: "name1", - Description: "description1", - StarCount: 1, - }, - }, - expectedResults: []registrytypes.SearchResult{ - { - Name: "name1", - Description: "description1", - StarCount: 1, - }, - }, - }, - { - filtersArgs: `{"stars":{"1":true}, "is-official":{"true":true}, "is-automated":{"true":true}}`, - registryResults: []registrytypes.SearchResult{ - { - Name: "name0", - Description: "description0", - StarCount: 0, - IsOfficial: true, - IsAutomated: true, - }, - { - Name: "name1", - Description: "description1", - StarCount: 1, - IsOfficial: false, - IsAutomated: true, - }, - { - Name: "name2", - Description: "description2", - StarCount: 1, - IsOfficial: true, - IsAutomated: false, - }, - { - Name: "name3", - Description: "description3", - StarCount: 2, - IsOfficial: true, - IsAutomated: true, - }, - }, - expectedResults: []registrytypes.SearchResult{ - { - Name: "name3", - Description: "description3", - StarCount: 2, - IsOfficial: true, - IsAutomated: true, - }, - }, - }, - } - for index, s := range successCases { - daemon := &Daemon{ - RegistryService: &FakeService{ - term: term, - results: s.registryResults, - }, - } - results, err := daemon.SearchRegistryForImages(context.Background(), s.filtersArgs, term, 25, nil, map[string][]string{}) - if err != nil { - t.Errorf("%d: %v", index, err) - } - if results.Query != term { - t.Errorf("%d: expected Query to be %s, got %s", index, term, results.Query) - } - if results.NumResults != len(s.expectedResults) { - t.Errorf("%d: expected NumResults to be %d, got %d", index, len(s.expectedResults), results.NumResults) - } - for _, result := range results.Results { - found := false - for _, expectedResult := range s.expectedResults { - if expectedResult.Name == result.Name && - expectedResult.Description == result.Description && - expectedResult.IsAutomated == result.IsAutomated && - expectedResult.IsOfficial == result.IsOfficial && - expectedResult.StarCount == result.StarCount { - found = true - break - } - } - if !found { - t.Errorf("%d: expected results %v, got %v", index, s.expectedResults, results.Results) - } - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/seccomp_disabled.go b/vendor/github.com/docker/docker/daemon/seccomp_disabled.go deleted file mode 100644 index ff1127b..0000000 --- a/vendor/github.com/docker/docker/daemon/seccomp_disabled.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build linux,!seccomp - -package daemon - -import ( - "fmt" - - "github.com/docker/docker/container" - "github.com/opencontainers/runtime-spec/specs-go" -) - -var supportsSeccomp = false - -func setSeccomp(daemon *Daemon, rs *specs.Spec, c *container.Container) error { - if c.SeccompProfile != "" && c.SeccompProfile != "unconfined" { - return fmt.Errorf("seccomp profiles are not supported on this daemon, you cannot specify a custom seccomp profile") - } - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/seccomp_linux.go b/vendor/github.com/docker/docker/daemon/seccomp_linux.go deleted file mode 100644 index 7f16733..0000000 --- a/vendor/github.com/docker/docker/daemon/seccomp_linux.go +++ /dev/null @@ -1,55 +0,0 @@ -// +build linux,seccomp - -package daemon - -import ( - "fmt" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/container" - "github.com/docker/docker/profiles/seccomp" - "github.com/opencontainers/runtime-spec/specs-go" -) - -var supportsSeccomp = true - -func setSeccomp(daemon *Daemon, rs *specs.Spec, c *container.Container) error { - var profile *specs.Seccomp - var err error - - if c.HostConfig.Privileged { - return nil - } - - if !daemon.seccompEnabled { - if c.SeccompProfile != "" && c.SeccompProfile != "unconfined" { - return fmt.Errorf("Seccomp is not enabled in your kernel, cannot run a custom seccomp profile.") - } - logrus.Warn("Seccomp is not enabled in your kernel, running container without default profile.") - c.SeccompProfile = "unconfined" - } - if c.SeccompProfile == "unconfined" { - return nil - } - if c.SeccompProfile != "" { - profile, err = seccomp.LoadProfile(c.SeccompProfile, rs) - if err != nil { - return err - } - } else { - if daemon.seccompProfile != nil { - profile, err = seccomp.LoadProfile(string(daemon.seccompProfile), rs) - if err != nil { - return err - } - } else { - profile, err = seccomp.GetDefaultProfile(rs) - if err != nil { - return err - } - } - } - - rs.Linux.Seccomp = profile - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/seccomp_unsupported.go b/vendor/github.com/docker/docker/daemon/seccomp_unsupported.go deleted file mode 100644 index b3691e9..0000000 --- a/vendor/github.com/docker/docker/daemon/seccomp_unsupported.go +++ /dev/null @@ -1,5 +0,0 @@ -// +build !linux - -package daemon - -var supportsSeccomp = false diff --git a/vendor/github.com/docker/docker/daemon/secrets.go b/vendor/github.com/docker/docker/daemon/secrets.go deleted file mode 100644 index 355cb1e..0000000 --- a/vendor/github.com/docker/docker/daemon/secrets.go +++ /dev/null @@ -1,36 +0,0 @@ -package daemon - -import ( - "github.com/Sirupsen/logrus" - swarmtypes "github.com/docker/docker/api/types/swarm" - "github.com/docker/swarmkit/agent/exec" -) - -// SetContainerSecretStore sets the secret store backend for the container -func (daemon *Daemon) SetContainerSecretStore(name string, store exec.SecretGetter) error { - c, err := daemon.GetContainer(name) - if err != nil { - return err - } - - c.SecretStore = store - - return nil -} - -// SetContainerSecretReferences sets the container secret references needed -func (daemon *Daemon) SetContainerSecretReferences(name string, refs []*swarmtypes.SecretReference) error { - if !secretsSupported() && len(refs) > 0 { - logrus.Warn("secrets are not supported on this platform") - return nil - } - - c, err := daemon.GetContainer(name) - if err != nil { - return err - } - - c.SecretReferences = refs - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/secrets_linux.go b/vendor/github.com/docker/docker/daemon/secrets_linux.go deleted file mode 100644 index fca4e12..0000000 --- a/vendor/github.com/docker/docker/daemon/secrets_linux.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build linux - -package daemon - -func secretsSupported() bool { - return true -} diff --git a/vendor/github.com/docker/docker/daemon/secrets_unsupported.go b/vendor/github.com/docker/docker/daemon/secrets_unsupported.go deleted file mode 100644 index d6f36fd..0000000 --- a/vendor/github.com/docker/docker/daemon/secrets_unsupported.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build !linux - -package daemon - -func secretsSupported() bool { - return false -} diff --git a/vendor/github.com/docker/docker/daemon/selinux_linux.go b/vendor/github.com/docker/docker/daemon/selinux_linux.go deleted file mode 100644 index 83a3447..0000000 --- a/vendor/github.com/docker/docker/daemon/selinux_linux.go +++ /dev/null @@ -1,17 +0,0 @@ -// +build linux - -package daemon - -import "github.com/opencontainers/runc/libcontainer/selinux" - -func selinuxSetDisabled() { - selinux.SetDisabled() -} - -func selinuxFreeLxcContexts(label string) { - selinux.FreeLxcContexts(label) -} - -func selinuxEnabled() bool { - return selinux.SelinuxEnabled() -} diff --git a/vendor/github.com/docker/docker/daemon/selinux_unsupported.go b/vendor/github.com/docker/docker/daemon/selinux_unsupported.go deleted file mode 100644 index 25a56ad..0000000 --- a/vendor/github.com/docker/docker/daemon/selinux_unsupported.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build !linux - -package daemon - -func selinuxSetDisabled() { -} - -func selinuxFreeLxcContexts(label string) { -} - -func selinuxEnabled() bool { - return false -} diff --git a/vendor/github.com/docker/docker/daemon/start.go b/vendor/github.com/docker/docker/daemon/start.go deleted file mode 100644 index 6c94fd5..0000000 --- a/vendor/github.com/docker/docker/daemon/start.go +++ /dev/null @@ -1,230 +0,0 @@ -package daemon - -import ( - "fmt" - "net/http" - "runtime" - "strings" - "syscall" - "time" - - "google.golang.org/grpc" - - "github.com/Sirupsen/logrus" - apierrors "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/container" - "github.com/docker/docker/runconfig" -) - -// ContainerStart starts a container. -func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.HostConfig, checkpoint string, checkpointDir string) error { - if checkpoint != "" && !daemon.HasExperimental() { - return apierrors.NewBadRequestError(fmt.Errorf("checkpoint is only supported in experimental mode")) - } - - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - if container.IsPaused() { - return fmt.Errorf("Cannot start a paused container, try unpause instead.") - } - - if container.IsRunning() { - err := fmt.Errorf("Container already started") - return apierrors.NewErrorWithStatusCode(err, http.StatusNotModified) - } - - // Windows does not have the backwards compatibility issue here. - if runtime.GOOS != "windows" { - // This is kept for backward compatibility - hostconfig should be passed when - // creating a container, not during start. - if hostConfig != nil { - logrus.Warn("DEPRECATED: Setting host configuration options when the container starts is deprecated and has been removed in Docker 1.12") - oldNetworkMode := container.HostConfig.NetworkMode - if err := daemon.setSecurityOptions(container, hostConfig); err != nil { - return err - } - if err := daemon.mergeAndVerifyLogConfig(&hostConfig.LogConfig); err != nil { - return err - } - if err := daemon.setHostConfig(container, hostConfig); err != nil { - return err - } - newNetworkMode := container.HostConfig.NetworkMode - if string(oldNetworkMode) != string(newNetworkMode) { - // if user has change the network mode on starting, clean up the - // old networks. It is a deprecated feature and has been removed in Docker 1.12 - container.NetworkSettings.Networks = nil - if err := container.ToDisk(); err != nil { - return err - } - } - container.InitDNSHostConfig() - } - } else { - if hostConfig != nil { - return fmt.Errorf("Supplying a hostconfig on start is not supported. It should be supplied on create") - } - } - - // check if hostConfig is in line with the current system settings. - // It may happen cgroups are umounted or the like. - if _, err = daemon.verifyContainerSettings(container.HostConfig, nil, false); err != nil { - return err - } - // Adapt for old containers in case we have updates in this function and - // old containers never have chance to call the new function in create stage. - if hostConfig != nil { - if err := daemon.adaptContainerSettings(container.HostConfig, false); err != nil { - return err - } - } - - return daemon.containerStart(container, checkpoint, checkpointDir, true) -} - -// Start starts a container -func (daemon *Daemon) Start(container *container.Container) error { - return daemon.containerStart(container, "", "", true) -} - -// containerStart prepares the container to run by setting up everything the -// container needs, such as storage and networking, as well as links -// between containers. The container is left waiting for a signal to -// begin running. -func (daemon *Daemon) containerStart(container *container.Container, checkpoint string, checkpointDir string, resetRestartManager bool) (err error) { - start := time.Now() - container.Lock() - defer container.Unlock() - - if resetRestartManager && container.Running { // skip this check if already in restarting step and resetRestartManager==false - return nil - } - - if container.RemovalInProgress || container.Dead { - return fmt.Errorf("Container is marked for removal and cannot be started.") - } - - // if we encounter an error during start we need to ensure that any other - // setup has been cleaned up properly - defer func() { - if err != nil { - container.SetError(err) - // if no one else has set it, make sure we don't leave it at zero - if container.ExitCode() == 0 { - container.SetExitCode(128) - } - container.ToDisk() - - container.Reset(false) - - daemon.Cleanup(container) - // if containers AutoRemove flag is set, remove it after clean up - if container.HostConfig.AutoRemove { - container.Unlock() - if err := daemon.ContainerRm(container.ID, &types.ContainerRmConfig{ForceRemove: true, RemoveVolume: true}); err != nil { - logrus.Errorf("can't remove container %s: %v", container.ID, err) - } - container.Lock() - } - } - }() - - if err := daemon.conditionalMountOnStart(container); err != nil { - return err - } - - // Make sure NetworkMode has an acceptable value. We do this to ensure - // backwards API compatibility. - container.HostConfig = runconfig.SetDefaultNetModeIfBlank(container.HostConfig) - - if err := daemon.initializeNetworking(container); err != nil { - return err - } - - spec, err := daemon.createSpec(container) - if err != nil { - return err - } - - createOptions, err := daemon.getLibcontainerdCreateOptions(container) - if err != nil { - return err - } - - if resetRestartManager { - container.ResetRestartManager(true) - } - - if checkpointDir == "" { - checkpointDir = container.CheckpointDir() - } - - if err := daemon.containerd.Create(container.ID, checkpoint, checkpointDir, *spec, container.InitializeStdio, createOptions...); err != nil { - errDesc := grpc.ErrorDesc(err) - contains := func(s1, s2 string) bool { - return strings.Contains(strings.ToLower(s1), s2) - } - logrus.Errorf("Create container failed with error: %s", errDesc) - // if we receive an internal error from the initial start of a container then lets - // return it instead of entering the restart loop - // set to 127 for container cmd not found/does not exist) - if contains(errDesc, container.Path) && - (contains(errDesc, "executable file not found") || - contains(errDesc, "no such file or directory") || - contains(errDesc, "system cannot find the file specified")) { - container.SetExitCode(127) - } - // set to 126 for container cmd can't be invoked errors - if contains(errDesc, syscall.EACCES.Error()) { - container.SetExitCode(126) - } - - // attempted to mount a file onto a directory, or a directory onto a file, maybe from user specified bind mounts - if contains(errDesc, syscall.ENOTDIR.Error()) { - errDesc += ": Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type" - container.SetExitCode(127) - } - - return fmt.Errorf("%s", errDesc) - } - - containerActions.WithValues("start").UpdateSince(start) - - return nil -} - -// Cleanup releases any network resources allocated to the container along with any rules -// around how containers are linked together. It also unmounts the container's root filesystem. -func (daemon *Daemon) Cleanup(container *container.Container) { - daemon.releaseNetwork(container) - - container.UnmountIpcMounts(detachMounted) - - if err := daemon.conditionalUnmountOnCleanup(container); err != nil { - // FIXME: remove once reference counting for graphdrivers has been refactored - // Ensure that all the mounts are gone - if mountid, err := daemon.layerStore.GetMountID(container.ID); err == nil { - daemon.cleanupMountsByID(mountid) - } - } - - if err := container.UnmountSecrets(); err != nil { - logrus.Warnf("%s cleanup: failed to unmount secrets: %s", container.ID, err) - } - - for _, eConfig := range container.ExecCommands.Commands() { - daemon.unregisterExecCommand(container, eConfig) - } - - if container.BaseFS != "" { - if err := container.UnmountVolumes(daemon.LogVolumeEvent); err != nil { - logrus.Warnf("%s cleanup: Failed to umount volumes: %v", container.ID, err) - } - } - container.CancelAttachContext() -} diff --git a/vendor/github.com/docker/docker/daemon/start_unix.go b/vendor/github.com/docker/docker/daemon/start_unix.go deleted file mode 100644 index 6bbe485..0000000 --- a/vendor/github.com/docker/docker/daemon/start_unix.go +++ /dev/null @@ -1,31 +0,0 @@ -// +build !windows - -package daemon - -import ( - "fmt" - - "github.com/docker/docker/container" - "github.com/docker/docker/libcontainerd" -) - -func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Container) ([]libcontainerd.CreateOption, error) { - createOptions := []libcontainerd.CreateOption{} - - // Ensure a runtime has been assigned to this container - if container.HostConfig.Runtime == "" { - container.HostConfig.Runtime = stockRuntimeName - container.ToDisk() - } - - rt := daemon.configStore.GetRuntime(container.HostConfig.Runtime) - if rt == nil { - return nil, fmt.Errorf("no such runtime '%s'", container.HostConfig.Runtime) - } - if UsingSystemd(daemon.configStore) { - rt.Args = append(rt.Args, "--systemd-cgroup=true") - } - createOptions = append(createOptions, libcontainerd.WithRuntime(rt.Path, rt.Args)) - - return createOptions, nil -} diff --git a/vendor/github.com/docker/docker/daemon/start_windows.go b/vendor/github.com/docker/docker/daemon/start_windows.go deleted file mode 100644 index faa7575..0000000 --- a/vendor/github.com/docker/docker/daemon/start_windows.go +++ /dev/null @@ -1,205 +0,0 @@ -package daemon - -import ( - "fmt" - "io/ioutil" - "path/filepath" - "strings" - - "github.com/docker/docker/container" - "github.com/docker/docker/layer" - "github.com/docker/docker/libcontainerd" - "golang.org/x/sys/windows/registry" -) - -const ( - credentialSpecRegistryLocation = `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\Containers\CredentialSpecs` - credentialSpecFileLocation = "CredentialSpecs" -) - -func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Container) ([]libcontainerd.CreateOption, error) { - createOptions := []libcontainerd.CreateOption{} - - // Are we going to run as a Hyper-V container? - hvOpts := &libcontainerd.HyperVIsolationOption{} - if container.HostConfig.Isolation.IsDefault() { - // Container is set to use the default, so take the default from the daemon configuration - hvOpts.IsHyperV = daemon.defaultIsolation.IsHyperV() - } else { - // Container is requesting an isolation mode. Honour it. - hvOpts.IsHyperV = container.HostConfig.Isolation.IsHyperV() - } - - // Generate the layer folder of the layer options - layerOpts := &libcontainerd.LayerOption{} - m, err := container.RWLayer.Metadata() - if err != nil { - return nil, fmt.Errorf("failed to get layer metadata - %s", err) - } - if hvOpts.IsHyperV { - hvOpts.SandboxPath = filepath.Dir(m["dir"]) - } - - layerOpts.LayerFolderPath = m["dir"] - - // Generate the layer paths of the layer options - img, err := daemon.imageStore.Get(container.ImageID) - if err != nil { - return nil, fmt.Errorf("failed to graph.Get on ImageID %s - %s", container.ImageID, err) - } - // Get the layer path for each layer. - max := len(img.RootFS.DiffIDs) - for i := 1; i <= max; i++ { - img.RootFS.DiffIDs = img.RootFS.DiffIDs[:i] - layerPath, err := layer.GetLayerPath(daemon.layerStore, img.RootFS.ChainID()) - if err != nil { - return nil, fmt.Errorf("failed to get layer path from graphdriver %s for ImageID %s - %s", daemon.layerStore, img.RootFS.ChainID(), err) - } - // Reverse order, expecting parent most first - layerOpts.LayerPaths = append([]string{layerPath}, layerOpts.LayerPaths...) - } - - // Get endpoints for the libnetwork allocated networks to the container - var epList []string - AllowUnqualifiedDNSQuery := false - gwHNSID := "" - if container.NetworkSettings != nil { - for n := range container.NetworkSettings.Networks { - sn, err := daemon.FindNetwork(n) - if err != nil { - continue - } - - ep, err := container.GetEndpointInNetwork(sn) - if err != nil { - continue - } - - data, err := ep.DriverInfo() - if err != nil { - continue - } - - if data["GW_INFO"] != nil { - gwInfo := data["GW_INFO"].(map[string]interface{}) - if gwInfo["hnsid"] != nil { - gwHNSID = gwInfo["hnsid"].(string) - } - } - - if data["hnsid"] != nil { - epList = append(epList, data["hnsid"].(string)) - } - - if data["AllowUnqualifiedDNSQuery"] != nil { - AllowUnqualifiedDNSQuery = true - } - } - } - - if gwHNSID != "" { - epList = append(epList, gwHNSID) - } - - // Read and add credentials from the security options if a credential spec has been provided. - if container.HostConfig.SecurityOpt != nil { - for _, sOpt := range container.HostConfig.SecurityOpt { - sOpt = strings.ToLower(sOpt) - if !strings.Contains(sOpt, "=") { - return nil, fmt.Errorf("invalid security option: no equals sign in supplied value %s", sOpt) - } - var splitsOpt []string - splitsOpt = strings.SplitN(sOpt, "=", 2) - if len(splitsOpt) != 2 { - return nil, fmt.Errorf("invalid security option: %s", sOpt) - } - if splitsOpt[0] != "credentialspec" { - return nil, fmt.Errorf("security option not supported: %s", splitsOpt[0]) - } - - credentialsOpts := &libcontainerd.CredentialsOption{} - var ( - match bool - csValue string - err error - ) - if match, csValue = getCredentialSpec("file://", splitsOpt[1]); match { - if csValue == "" { - return nil, fmt.Errorf("no value supplied for file:// credential spec security option") - } - if credentialsOpts.Credentials, err = readCredentialSpecFile(container.ID, daemon.root, filepath.Clean(csValue)); err != nil { - return nil, err - } - } else if match, csValue = getCredentialSpec("registry://", splitsOpt[1]); match { - if csValue == "" { - return nil, fmt.Errorf("no value supplied for registry:// credential spec security option") - } - if credentialsOpts.Credentials, err = readCredentialSpecRegistry(container.ID, csValue); err != nil { - return nil, err - } - } else { - return nil, fmt.Errorf("invalid credential spec security option - value must be prefixed file:// or registry:// followed by a value") - } - createOptions = append(createOptions, credentialsOpts) - } - } - - // Now add the remaining options. - createOptions = append(createOptions, &libcontainerd.FlushOption{IgnoreFlushesDuringBoot: !container.HasBeenStartedBefore}) - createOptions = append(createOptions, hvOpts) - createOptions = append(createOptions, layerOpts) - if epList != nil { - createOptions = append(createOptions, &libcontainerd.NetworkEndpointsOption{Endpoints: epList, AllowUnqualifiedDNSQuery: AllowUnqualifiedDNSQuery}) - } - - return createOptions, nil -} - -// getCredentialSpec is a helper function to get the value of a credential spec supplied -// on the CLI, stripping the prefix -func getCredentialSpec(prefix, value string) (bool, string) { - if strings.HasPrefix(value, prefix) { - return true, strings.TrimPrefix(value, prefix) - } - return false, "" -} - -// readCredentialSpecRegistry is a helper function to read a credential spec from -// the registry. If not found, we return an empty string and warn in the log. -// This allows for staging on machines which do not have the necessary components. -func readCredentialSpecRegistry(id, name string) (string, error) { - var ( - k registry.Key - err error - val string - ) - if k, err = registry.OpenKey(registry.LOCAL_MACHINE, credentialSpecRegistryLocation, registry.QUERY_VALUE); err != nil { - return "", fmt.Errorf("failed handling spec %q for container %s - %s could not be opened", name, id, credentialSpecRegistryLocation) - } - if val, _, err = k.GetStringValue(name); err != nil { - if err == registry.ErrNotExist { - return "", fmt.Errorf("credential spec %q for container %s as it was not found", name, id) - } - return "", fmt.Errorf("error %v reading credential spec %q from registry for container %s", err, name, id) - } - return val, nil -} - -// readCredentialSpecFile is a helper function to read a credential spec from -// a file. If not found, we return an empty string and warn in the log. -// This allows for staging on machines which do not have the necessary components. -func readCredentialSpecFile(id, root, location string) (string, error) { - if filepath.IsAbs(location) { - return "", fmt.Errorf("invalid credential spec - file:// path cannot be absolute") - } - base := filepath.Join(root, credentialSpecFileLocation) - full := filepath.Join(base, location) - if !strings.HasPrefix(full, base) { - return "", fmt.Errorf("invalid credential spec - file:// path must be under %s", base) - } - bcontents, err := ioutil.ReadFile(full) - if err != nil { - return "", fmt.Errorf("credential spec '%s' for container %s as the file could not be read: %q", full, id, err) - } - return string(bcontents[:]), nil -} diff --git a/vendor/github.com/docker/docker/daemon/stats.go b/vendor/github.com/docker/docker/daemon/stats.go deleted file mode 100644 index 51f5962..0000000 --- a/vendor/github.com/docker/docker/daemon/stats.go +++ /dev/null @@ -1,158 +0,0 @@ -package daemon - -import ( - "encoding/json" - "errors" - "fmt" - "runtime" - "time" - - "golang.org/x/net/context" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/backend" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/api/types/versions/v1p20" - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/ioutils" -) - -// ContainerStats writes information about the container to the stream -// given in the config object. -func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, config *backend.ContainerStatsConfig) error { - if runtime.GOOS == "solaris" { - return fmt.Errorf("%+v does not support stats", runtime.GOOS) - } - // Engine API version (used for backwards compatibility) - apiVersion := config.Version - - container, err := daemon.GetContainer(prefixOrName) - if err != nil { - return err - } - - // If the container is either not running or restarting and requires no stream, return an empty stats. - if (!container.IsRunning() || container.IsRestarting()) && !config.Stream { - return json.NewEncoder(config.OutStream).Encode(&types.Stats{}) - } - - outStream := config.OutStream - if config.Stream { - wf := ioutils.NewWriteFlusher(outStream) - defer wf.Close() - wf.Flush() - outStream = wf - } - - var preCPUStats types.CPUStats - var preRead time.Time - getStatJSON := func(v interface{}) *types.StatsJSON { - ss := v.(types.StatsJSON) - ss.Name = container.Name - ss.ID = container.ID - ss.PreCPUStats = preCPUStats - ss.PreRead = preRead - preCPUStats = ss.CPUStats - preRead = ss.Read - return &ss - } - - enc := json.NewEncoder(outStream) - - updates := daemon.subscribeToContainerStats(container) - defer daemon.unsubscribeToContainerStats(container, updates) - - noStreamFirstFrame := true - for { - select { - case v, ok := <-updates: - if !ok { - return nil - } - - var statsJSON interface{} - statsJSONPost120 := getStatJSON(v) - if versions.LessThan(apiVersion, "1.21") { - if runtime.GOOS == "windows" { - return errors.New("API versions pre v1.21 do not support stats on Windows") - } - var ( - rxBytes uint64 - rxPackets uint64 - rxErrors uint64 - rxDropped uint64 - txBytes uint64 - txPackets uint64 - txErrors uint64 - txDropped uint64 - ) - for _, v := range statsJSONPost120.Networks { - rxBytes += v.RxBytes - rxPackets += v.RxPackets - rxErrors += v.RxErrors - rxDropped += v.RxDropped - txBytes += v.TxBytes - txPackets += v.TxPackets - txErrors += v.TxErrors - txDropped += v.TxDropped - } - statsJSON = &v1p20.StatsJSON{ - Stats: statsJSONPost120.Stats, - Network: types.NetworkStats{ - RxBytes: rxBytes, - RxPackets: rxPackets, - RxErrors: rxErrors, - RxDropped: rxDropped, - TxBytes: txBytes, - TxPackets: txPackets, - TxErrors: txErrors, - TxDropped: txDropped, - }, - } - } else { - statsJSON = statsJSONPost120 - } - - if !config.Stream && noStreamFirstFrame { - // prime the cpu stats so they aren't 0 in the final output - noStreamFirstFrame = false - continue - } - - if err := enc.Encode(statsJSON); err != nil { - return err - } - - if !config.Stream { - return nil - } - case <-ctx.Done(): - return nil - } - } -} - -func (daemon *Daemon) subscribeToContainerStats(c *container.Container) chan interface{} { - return daemon.statsCollector.collect(c) -} - -func (daemon *Daemon) unsubscribeToContainerStats(c *container.Container, ch chan interface{}) { - daemon.statsCollector.unsubscribe(c, ch) -} - -// GetContainerStats collects all the stats published by a container -func (daemon *Daemon) GetContainerStats(container *container.Container) (*types.StatsJSON, error) { - stats, err := daemon.stats(container) - if err != nil { - return nil, err - } - - // We already have the network stats on Windows directly from HCS. - if !container.Config.NetworkDisabled && runtime.GOOS != "windows" { - if stats.Networks, err = daemon.getNetworkStats(container); err != nil { - return nil, err - } - } - - return stats, nil -} diff --git a/vendor/github.com/docker/docker/daemon/stats_collector.go b/vendor/github.com/docker/docker/daemon/stats_collector.go deleted file mode 100644 index dc6825e..0000000 --- a/vendor/github.com/docker/docker/daemon/stats_collector.go +++ /dev/null @@ -1,132 +0,0 @@ -// +build !solaris - -package daemon - -import ( - "bufio" - "sync" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/pubsub" -) - -type statsSupervisor interface { - // GetContainerStats collects all the stats related to a container - GetContainerStats(container *container.Container) (*types.StatsJSON, error) -} - -// newStatsCollector returns a new statsCollector that collections -// stats for a registered container at the specified interval. -// The collector allows non-running containers to be added -// and will start processing stats when they are started. -func (daemon *Daemon) newStatsCollector(interval time.Duration) *statsCollector { - s := &statsCollector{ - interval: interval, - supervisor: daemon, - publishers: make(map[*container.Container]*pubsub.Publisher), - bufReader: bufio.NewReaderSize(nil, 128), - } - platformNewStatsCollector(s) - go s.run() - return s -} - -// statsCollector manages and provides container resource stats -type statsCollector struct { - m sync.Mutex - supervisor statsSupervisor - interval time.Duration - publishers map[*container.Container]*pubsub.Publisher - bufReader *bufio.Reader - - // The following fields are not set on Windows currently. - clockTicksPerSecond uint64 - machineMemory uint64 -} - -// collect registers the container with the collector and adds it to -// the event loop for collection on the specified interval returning -// a channel for the subscriber to receive on. -func (s *statsCollector) collect(c *container.Container) chan interface{} { - s.m.Lock() - defer s.m.Unlock() - publisher, exists := s.publishers[c] - if !exists { - publisher = pubsub.NewPublisher(100*time.Millisecond, 1024) - s.publishers[c] = publisher - } - return publisher.Subscribe() -} - -// stopCollection closes the channels for all subscribers and removes -// the container from metrics collection. -func (s *statsCollector) stopCollection(c *container.Container) { - s.m.Lock() - if publisher, exists := s.publishers[c]; exists { - publisher.Close() - delete(s.publishers, c) - } - s.m.Unlock() -} - -// unsubscribe removes a specific subscriber from receiving updates for a container's stats. -func (s *statsCollector) unsubscribe(c *container.Container, ch chan interface{}) { - s.m.Lock() - publisher := s.publishers[c] - if publisher != nil { - publisher.Evict(ch) - if publisher.Len() == 0 { - delete(s.publishers, c) - } - } - s.m.Unlock() -} - -func (s *statsCollector) run() { - type publishersPair struct { - container *container.Container - publisher *pubsub.Publisher - } - // we cannot determine the capacity here. - // it will grow enough in first iteration - var pairs []publishersPair - - for range time.Tick(s.interval) { - // it does not make sense in the first iteration, - // but saves allocations in further iterations - pairs = pairs[:0] - - s.m.Lock() - for container, publisher := range s.publishers { - // copy pointers here to release the lock ASAP - pairs = append(pairs, publishersPair{container, publisher}) - } - s.m.Unlock() - if len(pairs) == 0 { - continue - } - - systemUsage, err := s.getSystemCPUUsage() - if err != nil { - logrus.Errorf("collecting system cpu usage: %v", err) - continue - } - - for _, pair := range pairs { - stats, err := s.supervisor.GetContainerStats(pair.container) - if err != nil { - if _, ok := err.(errNotRunning); !ok { - logrus.Errorf("collecting stats for %s: %v", pair.container.ID, err) - } - continue - } - // FIXME: move to containerd on Linux (not Windows) - stats.CPUStats.SystemUsage = systemUsage - - pair.publisher.Publish(*stats) - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/stats_collector_solaris.go b/vendor/github.com/docker/docker/daemon/stats_collector_solaris.go deleted file mode 100644 index 9cf9f0a..0000000 --- a/vendor/github.com/docker/docker/daemon/stats_collector_solaris.go +++ /dev/null @@ -1,34 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/container" - "time" -) - -// newStatsCollector returns a new statsCollector for collection stats -// for a registered container at the specified interval. The collector allows -// non-running containers to be added and will start processing stats when -// they are started. -func (daemon *Daemon) newStatsCollector(interval time.Duration) *statsCollector { - return &statsCollector{} -} - -// statsCollector manages and provides container resource stats -type statsCollector struct { -} - -// collect registers the container with the collector and adds it to -// the event loop for collection on the specified interval returning -// a channel for the subscriber to receive on. -func (s *statsCollector) collect(c *container.Container) chan interface{} { - return nil -} - -// stopCollection closes the channels for all subscribers and removes -// the container from metrics collection. -func (s *statsCollector) stopCollection(c *container.Container) { -} - -// unsubscribe removes a specific subscriber from receiving updates for a container's stats. -func (s *statsCollector) unsubscribe(c *container.Container, ch chan interface{}) { -} diff --git a/vendor/github.com/docker/docker/daemon/stats_collector_unix.go b/vendor/github.com/docker/docker/daemon/stats_collector_unix.go deleted file mode 100644 index 0fcc9c5..0000000 --- a/vendor/github.com/docker/docker/daemon/stats_collector_unix.go +++ /dev/null @@ -1,71 +0,0 @@ -// +build !windows,!solaris - -package daemon - -import ( - "fmt" - "os" - "strconv" - "strings" - - sysinfo "github.com/docker/docker/pkg/system" - "github.com/opencontainers/runc/libcontainer/system" -) - -// platformNewStatsCollector performs platform specific initialisation of the -// statsCollector structure. -func platformNewStatsCollector(s *statsCollector) { - s.clockTicksPerSecond = uint64(system.GetClockTicks()) - meminfo, err := sysinfo.ReadMemInfo() - if err == nil && meminfo.MemTotal > 0 { - s.machineMemory = uint64(meminfo.MemTotal) - } -} - -const nanoSecondsPerSecond = 1e9 - -// getSystemCPUUsage returns the host system's cpu usage in -// nanoseconds. An error is returned if the format of the underlying -// file does not match. -// -// Uses /proc/stat defined by POSIX. Looks for the cpu -// statistics line and then sums up the first seven fields -// provided. See `man 5 proc` for details on specific field -// information. -func (s *statsCollector) getSystemCPUUsage() (uint64, error) { - var line string - f, err := os.Open("/proc/stat") - if err != nil { - return 0, err - } - defer func() { - s.bufReader.Reset(nil) - f.Close() - }() - s.bufReader.Reset(f) - err = nil - for err == nil { - line, err = s.bufReader.ReadString('\n') - if err != nil { - break - } - parts := strings.Fields(line) - switch parts[0] { - case "cpu": - if len(parts) < 8 { - return 0, fmt.Errorf("invalid number of cpu fields") - } - var totalClockTicks uint64 - for _, i := range parts[1:8] { - v, err := strconv.ParseUint(i, 10, 64) - if err != nil { - return 0, fmt.Errorf("Unable to convert value %s to int: %s", i, err) - } - totalClockTicks += v - } - return (totalClockTicks * nanoSecondsPerSecond) / - s.clockTicksPerSecond, nil - } - } - return 0, fmt.Errorf("invalid stat format. Error trying to parse the '/proc/stat' file") -} diff --git a/vendor/github.com/docker/docker/daemon/stats_collector_windows.go b/vendor/github.com/docker/docker/daemon/stats_collector_windows.go deleted file mode 100644 index 41731b9..0000000 --- a/vendor/github.com/docker/docker/daemon/stats_collector_windows.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build windows - -package daemon - -// platformNewStatsCollector performs platform specific initialisation of the -// statsCollector structure. This is a no-op on Windows. -func platformNewStatsCollector(s *statsCollector) { -} - -// getSystemCPUUsage returns the host system's cpu usage in -// nanoseconds. An error is returned if the format of the underlying -// file does not match. This is a no-op on Windows. -func (s *statsCollector) getSystemCPUUsage() (uint64, error) { - return 0, nil -} diff --git a/vendor/github.com/docker/docker/daemon/stats_unix.go b/vendor/github.com/docker/docker/daemon/stats_unix.go deleted file mode 100644 index d875607..0000000 --- a/vendor/github.com/docker/docker/daemon/stats_unix.go +++ /dev/null @@ -1,58 +0,0 @@ -// +build !windows - -package daemon - -import ( - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/container" -) - -// Resolve Network SandboxID in case the container reuse another container's network stack -func (daemon *Daemon) getNetworkSandboxID(c *container.Container) (string, error) { - curr := c - for curr.HostConfig.NetworkMode.IsContainer() { - containerID := curr.HostConfig.NetworkMode.ConnectedContainer() - connected, err := daemon.GetContainer(containerID) - if err != nil { - return "", fmt.Errorf("Could not get container for %s", containerID) - } - curr = connected - } - return curr.NetworkSettings.SandboxID, nil -} - -func (daemon *Daemon) getNetworkStats(c *container.Container) (map[string]types.NetworkStats, error) { - sandboxID, err := daemon.getNetworkSandboxID(c) - if err != nil { - return nil, err - } - - sb, err := daemon.netController.SandboxByID(sandboxID) - if err != nil { - return nil, err - } - - lnstats, err := sb.Statistics() - if err != nil { - return nil, err - } - - stats := make(map[string]types.NetworkStats) - // Convert libnetwork nw stats into api stats - for ifName, ifStats := range lnstats { - stats[ifName] = types.NetworkStats{ - RxBytes: ifStats.RxBytes, - RxPackets: ifStats.RxPackets, - RxErrors: ifStats.RxErrors, - RxDropped: ifStats.RxDropped, - TxBytes: ifStats.TxBytes, - TxPackets: ifStats.TxPackets, - TxErrors: ifStats.TxErrors, - TxDropped: ifStats.TxDropped, - } - } - - return stats, nil -} diff --git a/vendor/github.com/docker/docker/daemon/stats_windows.go b/vendor/github.com/docker/docker/daemon/stats_windows.go deleted file mode 100644 index f8e6f6f..0000000 --- a/vendor/github.com/docker/docker/daemon/stats_windows.go +++ /dev/null @@ -1,11 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/api/types" - "github.com/docker/docker/container" -) - -// Windows network stats are obtained directly through HCS, hence this is a no-op. -func (daemon *Daemon) getNetworkStats(c *container.Container) (map[string]types.NetworkStats, error) { - return make(map[string]types.NetworkStats), nil -} diff --git a/vendor/github.com/docker/docker/daemon/stop.go b/vendor/github.com/docker/docker/daemon/stop.go deleted file mode 100644 index aa7b382..0000000 --- a/vendor/github.com/docker/docker/daemon/stop.go +++ /dev/null @@ -1,83 +0,0 @@ -package daemon - -import ( - "fmt" - "net/http" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/errors" - "github.com/docker/docker/container" -) - -// ContainerStop looks for the given container and terminates it, -// waiting the given number of seconds before forcefully killing the -// container. If a negative number of seconds is given, ContainerStop -// will wait for a graceful termination. An error is returned if the -// container is not found, is already stopped, or if there is a -// problem stopping the container. -func (daemon *Daemon) ContainerStop(name string, seconds *int) error { - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - if !container.IsRunning() { - err := fmt.Errorf("Container %s is already stopped", name) - return errors.NewErrorWithStatusCode(err, http.StatusNotModified) - } - if seconds == nil { - stopTimeout := container.StopTimeout() - seconds = &stopTimeout - } - if err := daemon.containerStop(container, *seconds); err != nil { - return fmt.Errorf("Cannot stop container %s: %v", name, err) - } - return nil -} - -// containerStop halts a container by sending a stop signal, waiting for the given -// duration in seconds, and then calling SIGKILL and waiting for the -// process to exit. If a negative duration is given, Stop will wait -// for the initial signal forever. If the container is not running Stop returns -// immediately. -func (daemon *Daemon) containerStop(container *container.Container, seconds int) error { - if !container.IsRunning() { - return nil - } - - daemon.stopHealthchecks(container) - - stopSignal := container.StopSignal() - // 1. Send a stop signal - if err := daemon.killPossiblyDeadProcess(container, stopSignal); err != nil { - // While normally we might "return err" here we're not going to - // because if we can't stop the container by this point then - // its probably because its already stopped. Meaning, between - // the time of the IsRunning() call above and now it stopped. - // Also, since the err return will be environment specific we can't - // look for any particular (common) error that would indicate - // that the process is already dead vs something else going wrong. - // So, instead we'll give it up to 2 more seconds to complete and if - // by that time the container is still running, then the error - // we got is probably valid and so we force kill it. - if _, err := container.WaitStop(2 * time.Second); err != nil { - logrus.Infof("Container failed to stop after sending signal %d to the process, force killing", stopSignal) - if err := daemon.killPossiblyDeadProcess(container, 9); err != nil { - return err - } - } - } - - // 2. Wait for the process to exit on its own - if _, err := container.WaitStop(time.Duration(seconds) * time.Second); err != nil { - logrus.Infof("Container %v failed to exit within %d seconds of signal %d - using the force", container.ID, seconds, stopSignal) - // 3. If it doesn't, then send SIGKILL - if err := daemon.Kill(container); err != nil { - container.WaitStop(-1 * time.Second) - logrus.Warn(err) // Don't return error because we only care that container is stopped, not what function stopped it - } - } - - daemon.LogContainerEvent(container, "stop") - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/top_unix.go b/vendor/github.com/docker/docker/daemon/top_unix.go deleted file mode 100644 index 7fb81d0..0000000 --- a/vendor/github.com/docker/docker/daemon/top_unix.go +++ /dev/null @@ -1,126 +0,0 @@ -//+build !windows - -package daemon - -import ( - "fmt" - "os/exec" - "regexp" - "strconv" - "strings" - - "github.com/docker/docker/api/types" -) - -func validatePSArgs(psArgs string) error { - // NOTE: \\s does not detect unicode whitespaces. - // So we use fieldsASCII instead of strings.Fields in parsePSOutput. - // See https://github.com/docker/docker/pull/24358 - re := regexp.MustCompile("\\s+([^\\s]*)=\\s*(PID[^\\s]*)") - for _, group := range re.FindAllStringSubmatch(psArgs, -1) { - if len(group) >= 3 { - k := group[1] - v := group[2] - if k != "pid" { - return fmt.Errorf("specifying \"%s=%s\" is not allowed", k, v) - } - } - } - return nil -} - -// fieldsASCII is similar to strings.Fields but only allows ASCII whitespaces -func fieldsASCII(s string) []string { - fn := func(r rune) bool { - switch r { - case '\t', '\n', '\f', '\r', ' ': - return true - } - return false - } - return strings.FieldsFunc(s, fn) -} - -func parsePSOutput(output []byte, pids []int) (*types.ContainerProcessList, error) { - procList := &types.ContainerProcessList{} - - lines := strings.Split(string(output), "\n") - procList.Titles = fieldsASCII(lines[0]) - - pidIndex := -1 - for i, name := range procList.Titles { - if name == "PID" { - pidIndex = i - } - } - if pidIndex == -1 { - return nil, fmt.Errorf("Couldn't find PID field in ps output") - } - - // loop through the output and extract the PID from each line - for _, line := range lines[1:] { - if len(line) == 0 { - continue - } - fields := fieldsASCII(line) - p, err := strconv.Atoi(fields[pidIndex]) - if err != nil { - return nil, fmt.Errorf("Unexpected pid '%s': %s", fields[pidIndex], err) - } - - for _, pid := range pids { - if pid == p { - // Make sure number of fields equals number of header titles - // merging "overhanging" fields - process := fields[:len(procList.Titles)-1] - process = append(process, strings.Join(fields[len(procList.Titles)-1:], " ")) - procList.Processes = append(procList.Processes, process) - } - } - } - return procList, nil -} - -// ContainerTop lists the processes running inside of the given -// container by calling ps with the given args, or with the flags -// "-ef" if no args are given. An error is returned if the container -// is not found, or is not running, or if there are any problems -// running ps, or parsing the output. -func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) { - if psArgs == "" { - psArgs = "-ef" - } - - if err := validatePSArgs(psArgs); err != nil { - return nil, err - } - - container, err := daemon.GetContainer(name) - if err != nil { - return nil, err - } - - if !container.IsRunning() { - return nil, errNotRunning{container.ID} - } - - if container.IsRestarting() { - return nil, errContainerIsRestarting(container.ID) - } - - pids, err := daemon.containerd.GetPidsForContainer(container.ID) - if err != nil { - return nil, err - } - - output, err := exec.Command("ps", strings.Split(psArgs, " ")...).Output() - if err != nil { - return nil, fmt.Errorf("Error running ps: %v", err) - } - procList, err := parsePSOutput(output, pids) - if err != nil { - return nil, err - } - daemon.LogContainerEvent(container, "top") - return procList, nil -} diff --git a/vendor/github.com/docker/docker/daemon/top_unix_test.go b/vendor/github.com/docker/docker/daemon/top_unix_test.go deleted file mode 100644 index 269ab6e..0000000 --- a/vendor/github.com/docker/docker/daemon/top_unix_test.go +++ /dev/null @@ -1,76 +0,0 @@ -//+build !windows - -package daemon - -import ( - "testing" -) - -func TestContainerTopValidatePSArgs(t *testing.T) { - tests := map[string]bool{ - "ae -o uid=PID": true, - "ae -o \"uid= PID\"": true, // ascii space (0x20) - "ae -o \"uid= PID\"": false, // unicode space (U+2003, 0xe2 0x80 0x83) - "ae o uid=PID": true, - "aeo uid=PID": true, - "ae -O uid=PID": true, - "ae -o pid=PID2 -o uid=PID": true, - "ae -o pid=PID": false, - "ae -o pid=PID -o uid=PIDX": true, // FIXME: we do not need to prohibit this - "aeo pid=PID": false, - "ae": false, - "": false, - } - for psArgs, errExpected := range tests { - err := validatePSArgs(psArgs) - t.Logf("tested %q, got err=%v", psArgs, err) - if errExpected && err == nil { - t.Fatalf("expected error, got %v (%q)", err, psArgs) - } - if !errExpected && err != nil { - t.Fatalf("expected nil, got %v (%q)", err, psArgs) - } - } -} - -func TestContainerTopParsePSOutput(t *testing.T) { - tests := []struct { - output []byte - pids []int - errExpected bool - }{ - {[]byte(` PID COMMAND - 42 foo - 43 bar - 100 baz -`), []int{42, 43}, false}, - {[]byte(` UID COMMAND - 42 foo - 43 bar - 100 baz -`), []int{42, 43}, true}, - // unicode space (U+2003, 0xe2 0x80 0x83) - {[]byte(` PID COMMAND - 42 foo - 43 bar - 100 baz -`), []int{42, 43}, true}, - // the first space is U+2003, the second one is ascii. - {[]byte(` PID COMMAND - 42 foo - 43 bar - 100 baz -`), []int{42, 43}, true}, - } - - for _, f := range tests { - _, err := parsePSOutput(f.output, f.pids) - t.Logf("tested %q, got err=%v", string(f.output), err) - if f.errExpected && err == nil { - t.Fatalf("expected error, got %v (%q)", err, string(f.output)) - } - if !f.errExpected && err != nil { - t.Fatalf("expected nil, got %v (%q)", err, string(f.output)) - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/top_windows.go b/vendor/github.com/docker/docker/daemon/top_windows.go deleted file mode 100644 index 3dd8ead..0000000 --- a/vendor/github.com/docker/docker/daemon/top_windows.go +++ /dev/null @@ -1,53 +0,0 @@ -package daemon - -import ( - "errors" - "fmt" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/go-units" -) - -// ContainerTop handles `docker top` client requests. -// Future considerations: -// -- Windows users are far more familiar with CPU% total. -// Further, users on Windows rarely see user/kernel CPU stats split. -// The kernel returns everything in terms of 100ns. To obtain -// CPU%, we could do something like docker stats does which takes two -// samples, subtract the difference and do the maths. Unfortunately this -// would slow the stat call down and require two kernel calls. So instead, -// we do something similar to linux and display the CPU as combined HH:MM:SS.mmm. -// -- Perhaps we could add an argument to display "raw" stats -// -- "Memory" is an extremely overloaded term in Windows. Hence we do what -// task manager does and use the private working set as the memory counter. -// We could return more info for those who really understand how memory -// management works in Windows if we introduced a "raw" stats (above). -func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) { - // It's not at all an equivalent to linux 'ps' on Windows - if psArgs != "" { - return nil, errors.New("Windows does not support arguments to top") - } - - container, err := daemon.GetContainer(name) - if err != nil { - return nil, err - } - - s, err := daemon.containerd.Summary(container.ID) - if err != nil { - return nil, err - } - procList := &types.ContainerProcessList{} - procList.Titles = []string{"Name", "PID", "CPU", "Private Working Set"} - - for _, j := range s { - d := time.Duration((j.KernelTime100ns + j.UserTime100ns) * 100) // Combined time in nanoseconds - procList.Processes = append(procList.Processes, []string{ - j.ImageName, - fmt.Sprint(j.ProcessId), - fmt.Sprintf("%02d:%02d:%02d.%03d", int(d.Hours()), int(d.Minutes())%60, int(d.Seconds())%60, int(d.Nanoseconds()/1000000)%1000), - units.HumanSize(float64(j.MemoryWorkingSetPrivateBytes))}) - } - return procList, nil -} diff --git a/vendor/github.com/docker/docker/daemon/unpause.go b/vendor/github.com/docker/docker/daemon/unpause.go deleted file mode 100644 index e66b386..0000000 --- a/vendor/github.com/docker/docker/daemon/unpause.go +++ /dev/null @@ -1,38 +0,0 @@ -package daemon - -import ( - "fmt" - - "github.com/docker/docker/container" -) - -// ContainerUnpause unpauses a container -func (daemon *Daemon) ContainerUnpause(name string) error { - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - if err := daemon.containerUnpause(container); err != nil { - return err - } - - return nil -} - -// containerUnpause resumes the container execution after the container is paused. -func (daemon *Daemon) containerUnpause(container *container.Container) error { - container.Lock() - defer container.Unlock() - - // We cannot unpause the container which is not paused - if !container.Paused { - return fmt.Errorf("Container %s is not paused", container.ID) - } - - if err := daemon.containerd.Resume(container.ID); err != nil { - return fmt.Errorf("Cannot unpause container %s: %s", container.ID, err) - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/update.go b/vendor/github.com/docker/docker/daemon/update.go deleted file mode 100644 index 6e26eeb..0000000 --- a/vendor/github.com/docker/docker/daemon/update.go +++ /dev/null @@ -1,92 +0,0 @@ -package daemon - -import ( - "fmt" - - "github.com/docker/docker/api/types/container" -) - -// ContainerUpdate updates configuration of the container -func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig) (container.ContainerUpdateOKBody, error) { - var warnings []string - - warnings, err := daemon.verifyContainerSettings(hostConfig, nil, true) - if err != nil { - return container.ContainerUpdateOKBody{Warnings: warnings}, err - } - - if err := daemon.update(name, hostConfig); err != nil { - return container.ContainerUpdateOKBody{Warnings: warnings}, err - } - - return container.ContainerUpdateOKBody{Warnings: warnings}, nil -} - -// ContainerUpdateCmdOnBuild updates Path and Args for the container with ID cID. -func (daemon *Daemon) ContainerUpdateCmdOnBuild(cID string, cmd []string) error { - if len(cmd) == 0 { - return nil - } - c, err := daemon.GetContainer(cID) - if err != nil { - return err - } - c.Path = cmd[0] - c.Args = cmd[1:] - return nil -} - -func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) error { - if hostConfig == nil { - return nil - } - - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - restoreConfig := false - backupHostConfig := *container.HostConfig - defer func() { - if restoreConfig { - container.Lock() - container.HostConfig = &backupHostConfig - container.ToDisk() - container.Unlock() - } - }() - - if container.RemovalInProgress || container.Dead { - return errCannotUpdate(container.ID, fmt.Errorf("Container is marked for removal and cannot be \"update\".")) - } - - if err := container.UpdateContainer(hostConfig); err != nil { - restoreConfig = true - return errCannotUpdate(container.ID, err) - } - - // if Restart Policy changed, we need to update container monitor - if hostConfig.RestartPolicy.Name != "" { - container.UpdateMonitor(hostConfig.RestartPolicy) - } - - // If container is not running, update hostConfig struct is enough, - // resources will be updated when the container is started again. - // If container is running (including paused), we need to update configs - // to the real world. - if container.IsRunning() && !container.IsRestarting() { - if err := daemon.containerd.UpdateResources(container.ID, toContainerdResources(hostConfig.Resources)); err != nil { - restoreConfig = true - return errCannotUpdate(container.ID, err) - } - } - - daemon.LogContainerEvent(container, "update") - - return nil -} - -func errCannotUpdate(containerID string, err error) error { - return fmt.Errorf("Cannot update container %s: %v", containerID, err) -} diff --git a/vendor/github.com/docker/docker/daemon/update_linux.go b/vendor/github.com/docker/docker/daemon/update_linux.go deleted file mode 100644 index f422325..0000000 --- a/vendor/github.com/docker/docker/daemon/update_linux.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build linux - -package daemon - -import ( - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/libcontainerd" -) - -func toContainerdResources(resources container.Resources) libcontainerd.Resources { - var r libcontainerd.Resources - r.BlkioWeight = uint64(resources.BlkioWeight) - r.CpuShares = uint64(resources.CPUShares) - r.CpuPeriod = uint64(resources.CPUPeriod) - r.CpuQuota = uint64(resources.CPUQuota) - r.CpusetCpus = resources.CpusetCpus - r.CpusetMems = resources.CpusetMems - r.MemoryLimit = uint64(resources.Memory) - if resources.MemorySwap > 0 { - r.MemorySwap = uint64(resources.MemorySwap) - } - r.MemoryReservation = uint64(resources.MemoryReservation) - r.KernelMemoryLimit = uint64(resources.KernelMemory) - return r -} diff --git a/vendor/github.com/docker/docker/daemon/update_solaris.go b/vendor/github.com/docker/docker/daemon/update_solaris.go deleted file mode 100644 index f3b545c..0000000 --- a/vendor/github.com/docker/docker/daemon/update_solaris.go +++ /dev/null @@ -1,11 +0,0 @@ -package daemon - -import ( - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/libcontainerd" -) - -func toContainerdResources(resources container.Resources) libcontainerd.Resources { - var r libcontainerd.Resources - return r -} diff --git a/vendor/github.com/docker/docker/daemon/update_windows.go b/vendor/github.com/docker/docker/daemon/update_windows.go deleted file mode 100644 index 0146626..0000000 --- a/vendor/github.com/docker/docker/daemon/update_windows.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build windows - -package daemon - -import ( - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/libcontainerd" -) - -func toContainerdResources(resources container.Resources) libcontainerd.Resources { - var r libcontainerd.Resources - return r -} diff --git a/vendor/github.com/docker/docker/daemon/volumes.go b/vendor/github.com/docker/docker/daemon/volumes.go deleted file mode 100644 index 10cf787..0000000 --- a/vendor/github.com/docker/docker/daemon/volumes.go +++ /dev/null @@ -1,303 +0,0 @@ -package daemon - -import ( - "errors" - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/Sirupsen/logrus" - dockererrors "github.com/docker/docker/api/errors" - "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - mounttypes "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/container" - "github.com/docker/docker/volume" - "github.com/docker/docker/volume/drivers" - "github.com/opencontainers/runc/libcontainer/label" -) - -var ( - // ErrVolumeReadonly is used to signal an error when trying to copy data into - // a volume mount that is not writable. - ErrVolumeReadonly = errors.New("mounted volume is marked read-only") -) - -type mounts []container.Mount - -// volumeToAPIType converts a volume.Volume to the type used by the Engine API -func volumeToAPIType(v volume.Volume) *types.Volume { - tv := &types.Volume{ - Name: v.Name(), - Driver: v.DriverName(), - } - if v, ok := v.(volume.DetailedVolume); ok { - tv.Labels = v.Labels() - tv.Options = v.Options() - tv.Scope = v.Scope() - } - - return tv -} - -// Len returns the number of mounts. Used in sorting. -func (m mounts) Len() int { - return len(m) -} - -// Less returns true if the number of parts (a/b/c would be 3 parts) in the -// mount indexed by parameter 1 is less than that of the mount indexed by -// parameter 2. Used in sorting. -func (m mounts) Less(i, j int) bool { - return m.parts(i) < m.parts(j) -} - -// Swap swaps two items in an array of mounts. Used in sorting -func (m mounts) Swap(i, j int) { - m[i], m[j] = m[j], m[i] -} - -// parts returns the number of parts in the destination of a mount. Used in sorting. -func (m mounts) parts(i int) int { - return strings.Count(filepath.Clean(m[i].Destination), string(os.PathSeparator)) -} - -// registerMountPoints initializes the container mount points with the configured volumes and bind mounts. -// It follows the next sequence to decide what to mount in each final destination: -// -// 1. Select the previously configured mount points for the containers, if any. -// 2. Select the volumes mounted from another containers. Overrides previously configured mount point destination. -// 3. Select the bind mounts set by the client. Overrides previously configured mount point destinations. -// 4. Cleanup old volumes that are about to be reassigned. -func (daemon *Daemon) registerMountPoints(container *container.Container, hostConfig *containertypes.HostConfig) (retErr error) { - binds := map[string]bool{} - mountPoints := map[string]*volume.MountPoint{} - defer func() { - // clean up the container mountpoints once return with error - if retErr != nil { - for _, m := range mountPoints { - if m.Volume == nil { - continue - } - daemon.volumes.Dereference(m.Volume, container.ID) - } - } - }() - - // 1. Read already configured mount points. - for destination, point := range container.MountPoints { - mountPoints[destination] = point - } - - // 2. Read volumes from other containers. - for _, v := range hostConfig.VolumesFrom { - containerID, mode, err := volume.ParseVolumesFrom(v) - if err != nil { - return err - } - - c, err := daemon.GetContainer(containerID) - if err != nil { - return err - } - - for _, m := range c.MountPoints { - cp := &volume.MountPoint{ - Name: m.Name, - Source: m.Source, - RW: m.RW && volume.ReadWrite(mode), - Driver: m.Driver, - Destination: m.Destination, - Propagation: m.Propagation, - Spec: m.Spec, - CopyData: false, - } - - if len(cp.Source) == 0 { - v, err := daemon.volumes.GetWithRef(cp.Name, cp.Driver, container.ID) - if err != nil { - return err - } - cp.Volume = v - } - - mountPoints[cp.Destination] = cp - } - } - - // 3. Read bind mounts - for _, b := range hostConfig.Binds { - bind, err := volume.ParseMountRaw(b, hostConfig.VolumeDriver) - if err != nil { - return err - } - - // #10618 - _, tmpfsExists := hostConfig.Tmpfs[bind.Destination] - if binds[bind.Destination] || tmpfsExists { - return fmt.Errorf("Duplicate mount point '%s'", bind.Destination) - } - - if bind.Type == mounttypes.TypeVolume { - // create the volume - v, err := daemon.volumes.CreateWithRef(bind.Name, bind.Driver, container.ID, nil, nil) - if err != nil { - return err - } - bind.Volume = v - bind.Source = v.Path() - // bind.Name is an already existing volume, we need to use that here - bind.Driver = v.DriverName() - if bind.Driver == volume.DefaultDriverName { - setBindModeIfNull(bind) - } - } - - binds[bind.Destination] = true - mountPoints[bind.Destination] = bind - } - - for _, cfg := range hostConfig.Mounts { - mp, err := volume.ParseMountSpec(cfg) - if err != nil { - return dockererrors.NewBadRequestError(err) - } - - if binds[mp.Destination] { - return fmt.Errorf("Duplicate mount point '%s'", cfg.Target) - } - - if mp.Type == mounttypes.TypeVolume { - var v volume.Volume - if cfg.VolumeOptions != nil { - var driverOpts map[string]string - if cfg.VolumeOptions.DriverConfig != nil { - driverOpts = cfg.VolumeOptions.DriverConfig.Options - } - v, err = daemon.volumes.CreateWithRef(mp.Name, mp.Driver, container.ID, driverOpts, cfg.VolumeOptions.Labels) - } else { - v, err = daemon.volumes.CreateWithRef(mp.Name, mp.Driver, container.ID, nil, nil) - } - if err != nil { - return err - } - - if err := label.Relabel(mp.Source, container.MountLabel, false); err != nil { - return err - } - mp.Volume = v - mp.Name = v.Name() - mp.Driver = v.DriverName() - - // only use the cached path here since getting the path is not necessary right now and calling `Path()` may be slow - if cv, ok := v.(interface { - CachedPath() string - }); ok { - mp.Source = cv.CachedPath() - } - } - - binds[mp.Destination] = true - mountPoints[mp.Destination] = mp - } - - container.Lock() - - // 4. Cleanup old volumes that are about to be reassigned. - for _, m := range mountPoints { - if m.BackwardsCompatible() { - if mp, exists := container.MountPoints[m.Destination]; exists && mp.Volume != nil { - daemon.volumes.Dereference(mp.Volume, container.ID) - } - } - } - container.MountPoints = mountPoints - - container.Unlock() - - return nil -} - -// lazyInitializeVolume initializes a mountpoint's volume if needed. -// This happens after a daemon restart. -func (daemon *Daemon) lazyInitializeVolume(containerID string, m *volume.MountPoint) error { - if len(m.Driver) > 0 && m.Volume == nil { - v, err := daemon.volumes.GetWithRef(m.Name, m.Driver, containerID) - if err != nil { - return err - } - m.Volume = v - } - return nil -} - -func backportMountSpec(container *container.Container) error { - for target, m := range container.MountPoints { - if m.Spec.Type != "" { - // if type is set on even one mount, no need to migrate - return nil - } - if m.Name != "" { - m.Type = mounttypes.TypeVolume - m.Spec.Type = mounttypes.TypeVolume - - // make sure this is not an anyonmous volume before setting the spec source - if _, exists := container.Config.Volumes[target]; !exists { - m.Spec.Source = m.Name - } - if container.HostConfig.VolumeDriver != "" { - m.Spec.VolumeOptions = &mounttypes.VolumeOptions{ - DriverConfig: &mounttypes.Driver{Name: container.HostConfig.VolumeDriver}, - } - } - if strings.Contains(m.Mode, "nocopy") { - if m.Spec.VolumeOptions == nil { - m.Spec.VolumeOptions = &mounttypes.VolumeOptions{} - } - m.Spec.VolumeOptions.NoCopy = true - } - } else { - m.Type = mounttypes.TypeBind - m.Spec.Type = mounttypes.TypeBind - m.Spec.Source = m.Source - if m.Propagation != "" { - m.Spec.BindOptions = &mounttypes.BindOptions{ - Propagation: m.Propagation, - } - } - } - - m.Spec.Target = m.Destination - if !m.RW { - m.Spec.ReadOnly = true - } - } - return container.ToDiskLocking() -} - -func (daemon *Daemon) traverseLocalVolumes(fn func(volume.Volume) error) error { - localVolumeDriver, err := volumedrivers.GetDriver(volume.DefaultDriverName) - if err != nil { - return fmt.Errorf("can't retrieve local volume driver: %v", err) - } - vols, err := localVolumeDriver.List() - if err != nil { - return fmt.Errorf("can't retrieve local volumes: %v", err) - } - - for _, v := range vols { - name := v.Name() - _, err := daemon.volumes.Get(name) - if err != nil { - logrus.Warnf("failed to retrieve volume %s from store: %v", name, err) - } - - err = fn(v) - if err != nil { - return err - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/volumes_unit_test.go b/vendor/github.com/docker/docker/daemon/volumes_unit_test.go deleted file mode 100644 index 450d17f..0000000 --- a/vendor/github.com/docker/docker/daemon/volumes_unit_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package daemon - -import ( - "testing" - - "github.com/docker/docker/volume" -) - -func TestParseVolumesFrom(t *testing.T) { - cases := []struct { - spec string - expID string - expMode string - fail bool - }{ - {"", "", "", true}, - {"foobar", "foobar", "rw", false}, - {"foobar:rw", "foobar", "rw", false}, - {"foobar:ro", "foobar", "ro", false}, - {"foobar:baz", "", "", true}, - } - - for _, c := range cases { - id, mode, err := volume.ParseVolumesFrom(c.spec) - if c.fail { - if err == nil { - t.Fatalf("Expected error, was nil, for spec %s\n", c.spec) - } - continue - } - - if id != c.expID { - t.Fatalf("Expected id %s, was %s, for spec %s\n", c.expID, id, c.spec) - } - if mode != c.expMode { - t.Fatalf("Expected mode %s, was %s for spec %s\n", c.expMode, mode, c.spec) - } - } -} diff --git a/vendor/github.com/docker/docker/daemon/volumes_unix.go b/vendor/github.com/docker/docker/daemon/volumes_unix.go deleted file mode 100644 index 29dffa9..0000000 --- a/vendor/github.com/docker/docker/daemon/volumes_unix.go +++ /dev/null @@ -1,219 +0,0 @@ -// +build !windows - -// TODO(amitkris): We need to split this file for solaris. - -package daemon - -import ( - "encoding/json" - "os" - "path/filepath" - "sort" - "strconv" - "strings" - - "github.com/docker/docker/container" - "github.com/docker/docker/pkg/fileutils" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/volume" - "github.com/docker/docker/volume/drivers" - "github.com/docker/docker/volume/local" - "github.com/pkg/errors" -) - -// setupMounts iterates through each of the mount points for a container and -// calls Setup() on each. It also looks to see if is a network mount such as -// /etc/resolv.conf, and if it is not, appends it to the array of mounts. -func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, error) { - var mounts []container.Mount - // TODO: tmpfs mounts should be part of Mountpoints - tmpfsMounts := make(map[string]bool) - tmpfsMountInfo, err := c.TmpfsMounts() - if err != nil { - return nil, err - } - for _, m := range tmpfsMountInfo { - tmpfsMounts[m.Destination] = true - } - for _, m := range c.MountPoints { - if tmpfsMounts[m.Destination] { - continue - } - if err := daemon.lazyInitializeVolume(c.ID, m); err != nil { - return nil, err - } - rootUID, rootGID := daemon.GetRemappedUIDGID() - path, err := m.Setup(c.MountLabel, rootUID, rootGID) - if err != nil { - return nil, err - } - if !c.TrySetNetworkMount(m.Destination, path) { - mnt := container.Mount{ - Source: path, - Destination: m.Destination, - Writable: m.RW, - Propagation: string(m.Propagation), - } - if m.Volume != nil { - attributes := map[string]string{ - "driver": m.Volume.DriverName(), - "container": c.ID, - "destination": m.Destination, - "read/write": strconv.FormatBool(m.RW), - "propagation": string(m.Propagation), - } - daemon.LogVolumeEvent(m.Volume.Name(), "mount", attributes) - } - mounts = append(mounts, mnt) - } - } - - mounts = sortMounts(mounts) - netMounts := c.NetworkMounts() - // if we are going to mount any of the network files from container - // metadata, the ownership must be set properly for potential container - // remapped root (user namespaces) - rootUID, rootGID := daemon.GetRemappedUIDGID() - for _, mount := range netMounts { - if err := os.Chown(mount.Source, rootUID, rootGID); err != nil { - return nil, err - } - } - return append(mounts, netMounts...), nil -} - -// sortMounts sorts an array of mounts in lexicographic order. This ensure that -// when mounting, the mounts don't shadow other mounts. For example, if mounting -// /etc and /etc/resolv.conf, /etc/resolv.conf must not be mounted first. -func sortMounts(m []container.Mount) []container.Mount { - sort.Sort(mounts(m)) - return m -} - -// setBindModeIfNull is platform specific processing to ensure the -// shared mode is set to 'z' if it is null. This is called in the case -// of processing a named volume and not a typical bind. -func setBindModeIfNull(bind *volume.MountPoint) { - if bind.Mode == "" { - bind.Mode = "z" - } -} - -// migrateVolume links the contents of a volume created pre Docker 1.7 -// into the location expected by the local driver. -// It creates a symlink from DOCKER_ROOT/vfs/dir/VOLUME_ID to DOCKER_ROOT/volumes/VOLUME_ID/_container_data. -// It preserves the volume json configuration generated pre Docker 1.7 to be able to -// downgrade from Docker 1.7 to Docker 1.6 without losing volume compatibility. -func migrateVolume(id, vfs string) error { - l, err := volumedrivers.GetDriver(volume.DefaultDriverName) - if err != nil { - return err - } - - newDataPath := l.(*local.Root).DataPath(id) - fi, err := os.Stat(newDataPath) - if err != nil && !os.IsNotExist(err) { - return err - } - - if fi != nil && fi.IsDir() { - return nil - } - - return os.Symlink(vfs, newDataPath) -} - -// verifyVolumesInfo ports volumes configured for the containers pre docker 1.7. -// It reads the container configuration and creates valid mount points for the old volumes. -func (daemon *Daemon) verifyVolumesInfo(container *container.Container) error { - // Inspect old structures only when we're upgrading from old versions - // to versions >= 1.7 and the MountPoints has not been populated with volumes data. - type volumes struct { - Volumes map[string]string - VolumesRW map[string]bool - } - cfgPath, err := container.ConfigPath() - if err != nil { - return err - } - f, err := os.Open(cfgPath) - if err != nil { - return errors.Wrap(err, "could not open container config") - } - defer f.Close() - var cv volumes - if err := json.NewDecoder(f).Decode(&cv); err != nil { - return errors.Wrap(err, "could not decode container config") - } - - if len(container.MountPoints) == 0 && len(cv.Volumes) > 0 { - for destination, hostPath := range cv.Volumes { - vfsPath := filepath.Join(daemon.root, "vfs", "dir") - rw := cv.VolumesRW != nil && cv.VolumesRW[destination] - - if strings.HasPrefix(hostPath, vfsPath) { - id := filepath.Base(hostPath) - v, err := daemon.volumes.CreateWithRef(id, volume.DefaultDriverName, container.ID, nil, nil) - if err != nil { - return err - } - if err := migrateVolume(id, hostPath); err != nil { - return err - } - container.AddMountPointWithVolume(destination, v, true) - } else { // Bind mount - m := volume.MountPoint{Source: hostPath, Destination: destination, RW: rw} - container.MountPoints[destination] = &m - } - } - return container.ToDisk() - } - return nil -} - -func (daemon *Daemon) mountVolumes(container *container.Container) error { - mounts, err := daemon.setupMounts(container) - if err != nil { - return err - } - - for _, m := range mounts { - dest, err := container.GetResourcePath(m.Destination) - if err != nil { - return err - } - - var stat os.FileInfo - stat, err = os.Stat(m.Source) - if err != nil { - return err - } - if err = fileutils.CreateIfNotExists(dest, stat.IsDir()); err != nil { - return err - } - - opts := "rbind,ro" - if m.Writable { - opts = "rbind,rw" - } - - if err := mount.Mount(m.Source, dest, bindMountType, opts); err != nil { - return err - } - - // mountVolumes() seems to be called for temporary mounts - // outside the container. Soon these will be unmounted with - // lazy unmount option and given we have mounted the rbind, - // all the submounts will propagate if these are shared. If - // daemon is running in host namespace and has / as shared - // then these unmounts will propagate and unmount original - // mount as well. So make all these mounts rprivate. - // Do not use propagation property of volume as that should - // apply only when mounting happen inside the container. - if err := mount.MakeRPrivate(dest); err != nil { - return err - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/daemon/volumes_windows.go b/vendor/github.com/docker/docker/daemon/volumes_windows.go deleted file mode 100644 index bf7fc47..0000000 --- a/vendor/github.com/docker/docker/daemon/volumes_windows.go +++ /dev/null @@ -1,47 +0,0 @@ -// +build windows - -package daemon - -import ( - "sort" - - "github.com/docker/docker/container" - "github.com/docker/docker/volume" -) - -// setupMounts configures the mount points for a container by appending each -// of the configured mounts on the container to the OCI mount structure -// which will ultimately be passed into the oci runtime during container creation. -// It also ensures each of the mounts are lexographically sorted. - -// BUGBUG TODO Windows containerd. This would be much better if it returned -// an array of runtime spec mounts, not container mounts. Then no need to -// do multiple transitions. - -func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, error) { - var mnts []container.Mount - for _, mount := range c.MountPoints { // type is volume.MountPoint - if err := daemon.lazyInitializeVolume(c.ID, mount); err != nil { - return nil, err - } - s, err := mount.Setup(c.MountLabel, 0, 0) - if err != nil { - return nil, err - } - - mnts = append(mnts, container.Mount{ - Source: s, - Destination: mount.Destination, - Writable: mount.RW, - }) - } - - sort.Sort(mounts(mnts)) - return mnts, nil -} - -// setBindModeIfNull is platform specific processing which is a no-op on -// Windows. -func setBindModeIfNull(bind *volume.MountPoint) { - return -} diff --git a/vendor/github.com/docker/docker/daemon/wait.go b/vendor/github.com/docker/docker/daemon/wait.go deleted file mode 100644 index 2dab22e..0000000 --- a/vendor/github.com/docker/docker/daemon/wait.go +++ /dev/null @@ -1,32 +0,0 @@ -package daemon - -import ( - "time" - - "golang.org/x/net/context" -) - -// ContainerWait stops processing until the given container is -// stopped. If the container is not found, an error is returned. On a -// successful stop, the exit code of the container is returned. On a -// timeout, an error is returned. If you want to wait forever, supply -// a negative duration for the timeout. -func (daemon *Daemon) ContainerWait(name string, timeout time.Duration) (int, error) { - container, err := daemon.GetContainer(name) - if err != nil { - return -1, err - } - - return container.WaitStop(timeout) -} - -// ContainerWaitWithContext returns a channel where exit code is sent -// when container stops. Channel can be cancelled with a context. -func (daemon *Daemon) ContainerWaitWithContext(ctx context.Context, name string) error { - container, err := daemon.GetContainer(name) - if err != nil { - return err - } - - return container.WaitWithContext(ctx) -} diff --git a/vendor/github.com/docker/docker/daemon/workdir.go b/vendor/github.com/docker/docker/daemon/workdir.go deleted file mode 100644 index 5bd0d0c..0000000 --- a/vendor/github.com/docker/docker/daemon/workdir.go +++ /dev/null @@ -1,21 +0,0 @@ -package daemon - -// ContainerCreateWorkdir creates the working directory. This is solves the -// issue arising from https://github.com/docker/docker/issues/27545, -// which was initially fixed by https://github.com/docker/docker/pull/27884. But that fix -// was too expensive in terms of performance on Windows. Instead, -// https://github.com/docker/docker/pull/28514 introduces this new functionality -// where the builder calls into the backend here to create the working directory. -func (daemon *Daemon) ContainerCreateWorkdir(cID string) error { - container, err := daemon.GetContainer(cID) - if err != nil { - return err - } - err = daemon.Mount(container) - if err != nil { - return err - } - defer daemon.Unmount(container) - rootUID, rootGID := daemon.GetRemappedUIDGID() - return container.SetupWorkingDirectory(rootUID, rootGID) -} diff --git a/vendor/github.com/docker/docker/distribution/config.go b/vendor/github.com/docker/docker/distribution/config.go deleted file mode 100644 index bfea8b0..0000000 --- a/vendor/github.com/docker/docker/distribution/config.go +++ /dev/null @@ -1,241 +0,0 @@ -package distribution - -import ( - "encoding/json" - "fmt" - "io" - "runtime" - - "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/distribution/manifest/schema2" - "github.com/docker/docker/api/types" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/distribution/xfer" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "github.com/docker/libtrust" - "golang.org/x/net/context" -) - -// Config stores configuration for communicating -// with a registry. -type Config struct { - // MetaHeaders stores HTTP headers with metadata about the image - MetaHeaders map[string][]string - // AuthConfig holds authentication credentials for authenticating with - // the registry. - AuthConfig *types.AuthConfig - // ProgressOutput is the interface for showing the status of the pull - // operation. - ProgressOutput progress.Output - // RegistryService is the registry service to use for TLS configuration - // and endpoint lookup. - RegistryService registry.Service - // ImageEventLogger notifies events for a given image - ImageEventLogger func(id, name, action string) - // MetadataStore is the storage backend for distribution-specific - // metadata. - MetadataStore metadata.Store - // ImageStore manages images. - ImageStore ImageConfigStore - // ReferenceStore manages tags. This value is optional, when excluded - // content will not be tagged. - ReferenceStore reference.Store - // RequireSchema2 ensures that only schema2 manifests are used. - RequireSchema2 bool -} - -// ImagePullConfig stores pull configuration. -type ImagePullConfig struct { - Config - - // DownloadManager manages concurrent pulls. - DownloadManager RootFSDownloadManager - // Schema2Types is the valid schema2 configuration types allowed - // by the pull operation. - Schema2Types []string -} - -// ImagePushConfig stores push configuration. -type ImagePushConfig struct { - Config - - // ConfigMediaType is the configuration media type for - // schema2 manifests. - ConfigMediaType string - // LayerStore manages layers. - LayerStore PushLayerProvider - // TrustKey is the private key for legacy signatures. This is typically - // an ephemeral key, since these signatures are no longer verified. - TrustKey libtrust.PrivateKey - // UploadManager dispatches uploads. - UploadManager *xfer.LayerUploadManager -} - -// ImageConfigStore handles storing and getting image configurations -// by digest. Allows getting an image configurations rootfs from the -// configuration. -type ImageConfigStore interface { - Put([]byte) (digest.Digest, error) - Get(digest.Digest) ([]byte, error) - RootFSFromConfig([]byte) (*image.RootFS, error) -} - -// PushLayerProvider provides layers to be pushed by ChainID. -type PushLayerProvider interface { - Get(layer.ChainID) (PushLayer, error) -} - -// PushLayer is a pushable layer with metadata about the layer -// and access to the content of the layer. -type PushLayer interface { - ChainID() layer.ChainID - DiffID() layer.DiffID - Parent() PushLayer - Open() (io.ReadCloser, error) - Size() (int64, error) - MediaType() string - Release() -} - -// RootFSDownloadManager handles downloading of the rootfs -type RootFSDownloadManager interface { - // Download downloads the layers into the given initial rootfs and - // returns the final rootfs. - // Given progress output to track download progress - // Returns function to release download resources - Download(ctx context.Context, initialRootFS image.RootFS, layers []xfer.DownloadDescriptor, progressOutput progress.Output) (image.RootFS, func(), error) -} - -type imageConfigStore struct { - image.Store -} - -// NewImageConfigStoreFromStore returns an ImageConfigStore backed -// by an image.Store for container images. -func NewImageConfigStoreFromStore(is image.Store) ImageConfigStore { - return &imageConfigStore{ - Store: is, - } -} - -func (s *imageConfigStore) Put(c []byte) (digest.Digest, error) { - id, err := s.Store.Create(c) - return digest.Digest(id), err -} - -func (s *imageConfigStore) Get(d digest.Digest) ([]byte, error) { - img, err := s.Store.Get(image.IDFromDigest(d)) - if err != nil { - return nil, err - } - return img.RawJSON(), nil -} - -func (s *imageConfigStore) RootFSFromConfig(c []byte) (*image.RootFS, error) { - var unmarshalledConfig image.Image - if err := json.Unmarshal(c, &unmarshalledConfig); err != nil { - return nil, err - } - - // fail immediately on windows - if runtime.GOOS == "windows" && unmarshalledConfig.OS == "linux" { - return nil, fmt.Errorf("image operating system %q cannot be used on this platform", unmarshalledConfig.OS) - } - - return unmarshalledConfig.RootFS, nil -} - -type storeLayerProvider struct { - ls layer.Store -} - -// NewLayerProviderFromStore returns a layer provider backed by -// an instance of LayerStore. Only getting layers as gzipped -// tars is supported. -func NewLayerProviderFromStore(ls layer.Store) PushLayerProvider { - return &storeLayerProvider{ - ls: ls, - } -} - -func (p *storeLayerProvider) Get(lid layer.ChainID) (PushLayer, error) { - if lid == "" { - return &storeLayer{ - Layer: layer.EmptyLayer, - }, nil - } - l, err := p.ls.Get(lid) - if err != nil { - return nil, err - } - - sl := storeLayer{ - Layer: l, - ls: p.ls, - } - if d, ok := l.(distribution.Describable); ok { - return &describableStoreLayer{ - storeLayer: sl, - describable: d, - }, nil - } - - return &sl, nil -} - -type storeLayer struct { - layer.Layer - ls layer.Store -} - -func (l *storeLayer) Parent() PushLayer { - p := l.Layer.Parent() - if p == nil { - return nil - } - sl := storeLayer{ - Layer: p, - ls: l.ls, - } - if d, ok := p.(distribution.Describable); ok { - return &describableStoreLayer{ - storeLayer: sl, - describable: d, - } - } - - return &sl -} - -func (l *storeLayer) Open() (io.ReadCloser, error) { - return l.Layer.TarStream() -} - -func (l *storeLayer) Size() (int64, error) { - return l.Layer.DiffSize() -} - -func (l *storeLayer) MediaType() string { - // layer store always returns uncompressed tars - return schema2.MediaTypeUncompressedLayer -} - -func (l *storeLayer) Release() { - if l.ls != nil { - layer.ReleaseAndLog(l.ls, l.Layer) - } -} - -type describableStoreLayer struct { - storeLayer - describable distribution.Describable -} - -func (l *describableStoreLayer) Descriptor() distribution.Descriptor { - return l.describable.Descriptor() -} diff --git a/vendor/github.com/docker/docker/distribution/errors.go b/vendor/github.com/docker/docker/distribution/errors.go deleted file mode 100644 index b8cf9fb..0000000 --- a/vendor/github.com/docker/docker/distribution/errors.go +++ /dev/null @@ -1,159 +0,0 @@ -package distribution - -import ( - "net/url" - "strings" - "syscall" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution" - "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" - "github.com/docker/distribution/registry/client" - "github.com/docker/distribution/registry/client/auth" - "github.com/docker/docker/distribution/xfer" - "github.com/docker/docker/reference" - "github.com/pkg/errors" -) - -// ErrNoSupport is an error type used for errors indicating that an operation -// is not supported. It encapsulates a more specific error. -type ErrNoSupport struct{ Err error } - -func (e ErrNoSupport) Error() string { - if e.Err == nil { - return "not supported" - } - return e.Err.Error() -} - -// fallbackError wraps an error that can possibly allow fallback to a different -// endpoint. -type fallbackError struct { - // err is the error being wrapped. - err error - // confirmedV2 is set to true if it was confirmed that the registry - // supports the v2 protocol. This is used to limit fallbacks to the v1 - // protocol. - confirmedV2 bool - // transportOK is set to true if we managed to speak HTTP with the - // registry. This confirms that we're using appropriate TLS settings - // (or lack of TLS). - transportOK bool -} - -// Error renders the FallbackError as a string. -func (f fallbackError) Error() string { - return f.Cause().Error() -} - -func (f fallbackError) Cause() error { - return f.err -} - -// shouldV2Fallback returns true if this error is a reason to fall back to v1. -func shouldV2Fallback(err errcode.Error) bool { - switch err.Code { - case errcode.ErrorCodeUnauthorized, v2.ErrorCodeManifestUnknown, v2.ErrorCodeNameUnknown: - return true - } - return false -} - -// TranslatePullError is used to convert an error from a registry pull -// operation to an error representing the entire pull operation. Any error -// information which is not used by the returned error gets output to -// log at info level. -func TranslatePullError(err error, ref reference.Named) error { - switch v := err.(type) { - case errcode.Errors: - if len(v) != 0 { - for _, extra := range v[1:] { - logrus.Infof("Ignoring extra error returned from registry: %v", extra) - } - return TranslatePullError(v[0], ref) - } - case errcode.Error: - var newErr error - switch v.Code { - case errcode.ErrorCodeDenied: - // ErrorCodeDenied is used when access to the repository was denied - newErr = errors.Errorf("repository %s not found: does not exist or no pull access", ref.Name()) - case v2.ErrorCodeManifestUnknown: - newErr = errors.Errorf("manifest for %s not found", ref.String()) - case v2.ErrorCodeNameUnknown: - newErr = errors.Errorf("repository %s not found", ref.Name()) - } - if newErr != nil { - logrus.Infof("Translating %q to %q", err, newErr) - return newErr - } - case xfer.DoNotRetry: - return TranslatePullError(v.Err, ref) - } - - return err -} - -// continueOnError returns true if we should fallback to the next endpoint -// as a result of this error. -func continueOnError(err error) bool { - switch v := err.(type) { - case errcode.Errors: - if len(v) == 0 { - return true - } - return continueOnError(v[0]) - case ErrNoSupport: - return continueOnError(v.Err) - case errcode.Error: - return shouldV2Fallback(v) - case *client.UnexpectedHTTPResponseError: - return true - case ImageConfigPullError: - return false - case error: - return !strings.Contains(err.Error(), strings.ToLower(syscall.ENOSPC.Error())) - } - // let's be nice and fallback if the error is a completely - // unexpected one. - // If new errors have to be handled in some way, please - // add them to the switch above. - return true -} - -// retryOnError wraps the error in xfer.DoNotRetry if we should not retry the -// operation after this error. -func retryOnError(err error) error { - switch v := err.(type) { - case errcode.Errors: - if len(v) != 0 { - return retryOnError(v[0]) - } - case errcode.Error: - switch v.Code { - case errcode.ErrorCodeUnauthorized, errcode.ErrorCodeUnsupported, errcode.ErrorCodeDenied, errcode.ErrorCodeTooManyRequests, v2.ErrorCodeNameUnknown: - return xfer.DoNotRetry{Err: err} - } - case *url.Error: - switch v.Err { - case auth.ErrNoBasicAuthCredentials, auth.ErrNoToken: - return xfer.DoNotRetry{Err: v.Err} - } - return retryOnError(v.Err) - case *client.UnexpectedHTTPResponseError: - return xfer.DoNotRetry{Err: err} - case error: - if err == distribution.ErrBlobUnknown { - return xfer.DoNotRetry{Err: err} - } - if strings.Contains(err.Error(), strings.ToLower(syscall.ENOSPC.Error())) { - return xfer.DoNotRetry{Err: err} - } - } - // let's be nice and fallback if the error is a completely - // unexpected one. - // If new errors have to be handled in some way, please - // add them to the switch above. - return err -} diff --git a/vendor/github.com/docker/docker/distribution/fixtures/validate_manifest/bad_manifest b/vendor/github.com/docker/docker/distribution/fixtures/validate_manifest/bad_manifest deleted file mode 100644 index a1f02a6..0000000 --- a/vendor/github.com/docker/docker/distribution/fixtures/validate_manifest/bad_manifest +++ /dev/null @@ -1,38 +0,0 @@ -{ - "schemaVersion": 2, - "name": "library/hello-world", - "tag": "latest", - "architecture": "amd64", - "fsLayers": [ - { - "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" - }, - { - "blobSum": "sha256:03f4658f8b782e12230c1783426bd3bacce651ce582a4ffb6fbbfa2079428ecb" - } - ], - "history": [ - { - "v1Compatibility": "{\"id\":\"af340544ed62de0680f441c71fa1a80cb084678fed42bae393e543faea3a572c\",\"parent\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"created\":\"2015-08-06T23:53:22.608577814Z\",\"container\":\"c2b715156f640c7ac7d98472ea24335aba5432a1323a3bb722697e6d37ef794f\",\"container_config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) CMD [\\\"/hello\\\"]\"],\"Image\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":{}},\"docker_version\":\"1.7.1\",\"config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"/hello\"],\"Image\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":0}\n" - }, - { - "v1Compatibility": "{\"id\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"created\":\"2015-08-06T23:53:22.241352727Z\",\"container\":\"9aeb0006ffa72a8287564caaea87625896853701459261d3b569e320c0c9d5dc\",\"container_config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) COPY file:4abd3bff60458ca3b079d7b131ce26b2719055a030dfa96ff827da2b7c7038a7 in /\"],\"Image\":\"\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":null},\"docker_version\":\"1.7.1\",\"config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":null,\"Image\":\"\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":null},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":960}\n" - } - ], - "signatures": [ - { - "header": { - "jwk": { - "crv": "P-256", - "kid": "OIH7:HQFS:44FK:45VB:3B53:OIAG:TPL4:ATF5:6PNE:MGHN:NHQX:2GE4", - "kty": "EC", - "x": "Cu_UyxwLgHzE9rvlYSmvVdqYCXY42E9eNhBb0xNv0SQ", - "y": "zUsjWJkeKQ5tv7S-hl1Tg71cd-CqnrtiiLxSi6N_yc8" - }, - "alg": "ES256" - }, - "signature": "Y6xaFz9Sy-OtcnKQS1Ilq3Dh8cu4h3nBTJCpOTF1XF7vKtcxxA_xMP8-SgDo869SJ3VsvgPL9-Xn-OoYG2rb1A", - "protected": "eyJmb3JtYXRMZW5ndGgiOjMxOTcsImZvcm1hdFRhaWwiOiJDbjAiLCJ0aW1lIjoiMjAxNS0wOS0xMVQwNDoxMzo0OFoifQ" - } - ] -} diff --git a/vendor/github.com/docker/docker/distribution/fixtures/validate_manifest/extra_data_manifest b/vendor/github.com/docker/docker/distribution/fixtures/validate_manifest/extra_data_manifest deleted file mode 100644 index beec19a..0000000 --- a/vendor/github.com/docker/docker/distribution/fixtures/validate_manifest/extra_data_manifest +++ /dev/null @@ -1,46 +0,0 @@ -{ - "schemaVersion": 1, - "name": "library/hello-world", - "tag": "latest", - "architecture": "amd64", - "fsLayers": [ - { - "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" - }, - { - "blobSum": "sha256:03f4658f8b782e12230c1783426bd3bacce651ce582a4ffb6fbbfa2079428ecb" - } - ], - "history": [ - { - "v1Compatibility": "{\"id\":\"af340544ed62de0680f441c71fa1a80cb084678fed42bae393e543faea3a572c\",\"parent\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"created\":\"2015-08-06T23:53:22.608577814Z\",\"container\":\"c2b715156f640c7ac7d98472ea24335aba5432a1323a3bb722697e6d37ef794f\",\"container_config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) CMD [\\\"/hello\\\"]\"],\"Image\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":{}},\"docker_version\":\"1.7.1\",\"config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"/hello\"],\"Image\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":0}\n" - }, - { - "v1Compatibility": "{\"id\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"created\":\"2015-08-06T23:53:22.241352727Z\",\"container\":\"9aeb0006ffa72a8287564caaea87625896853701459261d3b569e320c0c9d5dc\",\"container_config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) COPY file:4abd3bff60458ca3b079d7b131ce26b2719055a030dfa96ff827da2b7c7038a7 in /\"],\"Image\":\"\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":null},\"docker_version\":\"1.7.1\",\"config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":null,\"Image\":\"\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":null},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":960}\n" - } - ], - "fsLayers": [ - { - "blobSum": "sha256:ffff95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" - }, - { - "blobSum": "sha256:ffff658f8b782e12230c1783426bd3bacce651ce582a4ffb6fbbfa2079428ecb" - } - ], - "signatures": [ - { - "header": { - "jwk": { - "crv": "P-256", - "kid": "OIH7:HQFS:44FK:45VB:3B53:OIAG:TPL4:ATF5:6PNE:MGHN:NHQX:2GE4", - "kty": "EC", - "x": "Cu_UyxwLgHzE9rvlYSmvVdqYCXY42E9eNhBb0xNv0SQ", - "y": "zUsjWJkeKQ5tv7S-hl1Tg71cd-CqnrtiiLxSi6N_yc8" - }, - "alg": "ES256" - }, - "signature": "Y6xaFz9Sy-OtcnKQS1Ilq3Dh8cu4h3nBTJCpOTF1XF7vKtcxxA_xMP8-SgDo869SJ3VsvgPL9-Xn-OoYG2rb1A", - "protected": "eyJmb3JtYXRMZW5ndGgiOjMxOTcsImZvcm1hdFRhaWwiOiJDbjAiLCJ0aW1lIjoiMjAxNS0wOS0xMVQwNDoxMzo0OFoifQ" - } - ] -} diff --git a/vendor/github.com/docker/docker/distribution/fixtures/validate_manifest/good_manifest b/vendor/github.com/docker/docker/distribution/fixtures/validate_manifest/good_manifest deleted file mode 100644 index b107de3..0000000 --- a/vendor/github.com/docker/docker/distribution/fixtures/validate_manifest/good_manifest +++ /dev/null @@ -1,38 +0,0 @@ -{ - "schemaVersion": 1, - "name": "library/hello-world", - "tag": "latest", - "architecture": "amd64", - "fsLayers": [ - { - "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" - }, - { - "blobSum": "sha256:03f4658f8b782e12230c1783426bd3bacce651ce582a4ffb6fbbfa2079428ecb" - } - ], - "history": [ - { - "v1Compatibility": "{\"id\":\"af340544ed62de0680f441c71fa1a80cb084678fed42bae393e543faea3a572c\",\"parent\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"created\":\"2015-08-06T23:53:22.608577814Z\",\"container\":\"c2b715156f640c7ac7d98472ea24335aba5432a1323a3bb722697e6d37ef794f\",\"container_config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) CMD [\\\"/hello\\\"]\"],\"Image\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":{}},\"docker_version\":\"1.7.1\",\"config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"/hello\"],\"Image\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":0}\n" - }, - { - "v1Compatibility": "{\"id\":\"535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912\",\"created\":\"2015-08-06T23:53:22.241352727Z\",\"container\":\"9aeb0006ffa72a8287564caaea87625896853701459261d3b569e320c0c9d5dc\",\"container_config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) COPY file:4abd3bff60458ca3b079d7b131ce26b2719055a030dfa96ff827da2b7c7038a7 in /\"],\"Image\":\"\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":null},\"docker_version\":\"1.7.1\",\"config\":{\"Hostname\":\"9aeb0006ffa7\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":null,\"Image\":\"\",\"Volumes\":null,\"VolumeDriver\":\"\",\"WorkingDir\":\"\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":null,\"Labels\":null},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":960}\n" - } - ], - "signatures": [ - { - "header": { - "jwk": { - "crv": "P-256", - "kid": "OIH7:HQFS:44FK:45VB:3B53:OIAG:TPL4:ATF5:6PNE:MGHN:NHQX:2GE4", - "kty": "EC", - "x": "Cu_UyxwLgHzE9rvlYSmvVdqYCXY42E9eNhBb0xNv0SQ", - "y": "zUsjWJkeKQ5tv7S-hl1Tg71cd-CqnrtiiLxSi6N_yc8" - }, - "alg": "ES256" - }, - "signature": "Y6xaFz9Sy-OtcnKQS1Ilq3Dh8cu4h3nBTJCpOTF1XF7vKtcxxA_xMP8-SgDo869SJ3VsvgPL9-Xn-OoYG2rb1A", - "protected": "eyJmb3JtYXRMZW5ndGgiOjMxOTcsImZvcm1hdFRhaWwiOiJDbjAiLCJ0aW1lIjoiMjAxNS0wOS0xMVQwNDoxMzo0OFoifQ" - } - ] -} \ No newline at end of file diff --git a/vendor/github.com/docker/docker/distribution/metadata/metadata.go b/vendor/github.com/docker/docker/distribution/metadata/metadata.go deleted file mode 100644 index 05ba4f8..0000000 --- a/vendor/github.com/docker/docker/distribution/metadata/metadata.go +++ /dev/null @@ -1,75 +0,0 @@ -package metadata - -import ( - "io/ioutil" - "os" - "path/filepath" - "sync" - - "github.com/docker/docker/pkg/ioutils" -) - -// Store implements a K/V store for mapping distribution-related IDs -// to on-disk layer IDs and image IDs. The namespace identifies the type of -// mapping (i.e. "v1ids" or "artifacts"). MetadataStore is goroutine-safe. -type Store interface { - // Get retrieves data by namespace and key. - Get(namespace string, key string) ([]byte, error) - // Set writes data indexed by namespace and key. - Set(namespace, key string, value []byte) error - // Delete removes data indexed by namespace and key. - Delete(namespace, key string) error -} - -// FSMetadataStore uses the filesystem to associate metadata with layer and -// image IDs. -type FSMetadataStore struct { - sync.RWMutex - basePath string -} - -// NewFSMetadataStore creates a new filesystem-based metadata store. -func NewFSMetadataStore(basePath string) (*FSMetadataStore, error) { - if err := os.MkdirAll(basePath, 0700); err != nil { - return nil, err - } - return &FSMetadataStore{ - basePath: basePath, - }, nil -} - -func (store *FSMetadataStore) path(namespace, key string) string { - return filepath.Join(store.basePath, namespace, key) -} - -// Get retrieves data by namespace and key. The data is read from a file named -// after the key, stored in the namespace's directory. -func (store *FSMetadataStore) Get(namespace string, key string) ([]byte, error) { - store.RLock() - defer store.RUnlock() - - return ioutil.ReadFile(store.path(namespace, key)) -} - -// Set writes data indexed by namespace and key. The data is written to a file -// named after the key, stored in the namespace's directory. -func (store *FSMetadataStore) Set(namespace, key string, value []byte) error { - store.Lock() - defer store.Unlock() - - path := store.path(namespace, key) - if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { - return err - } - return ioutils.AtomicWriteFile(path, value, 0644) -} - -// Delete removes data indexed by namespace and key. The data file named after -// the key, stored in the namespace's directory is deleted. -func (store *FSMetadataStore) Delete(namespace, key string) error { - store.Lock() - defer store.Unlock() - - path := store.path(namespace, key) - return os.Remove(path) -} diff --git a/vendor/github.com/docker/docker/distribution/metadata/v1_id_service.go b/vendor/github.com/docker/docker/distribution/metadata/v1_id_service.go deleted file mode 100644 index f262d4d..0000000 --- a/vendor/github.com/docker/docker/distribution/metadata/v1_id_service.go +++ /dev/null @@ -1,51 +0,0 @@ -package metadata - -import ( - "github.com/docker/docker/image/v1" - "github.com/docker/docker/layer" - "github.com/pkg/errors" -) - -// V1IDService maps v1 IDs to layers on disk. -type V1IDService struct { - store Store -} - -// NewV1IDService creates a new V1 ID mapping service. -func NewV1IDService(store Store) *V1IDService { - return &V1IDService{ - store: store, - } -} - -// namespace returns the namespace used by this service. -func (idserv *V1IDService) namespace() string { - return "v1id" -} - -// Get finds a layer by its V1 ID. -func (idserv *V1IDService) Get(v1ID, registry string) (layer.DiffID, error) { - if idserv.store == nil { - return "", errors.New("no v1IDService storage") - } - if err := v1.ValidateID(v1ID); err != nil { - return layer.DiffID(""), err - } - - idBytes, err := idserv.store.Get(idserv.namespace(), registry+","+v1ID) - if err != nil { - return layer.DiffID(""), err - } - return layer.DiffID(idBytes), nil -} - -// Set associates an image with a V1 ID. -func (idserv *V1IDService) Set(v1ID, registry string, id layer.DiffID) error { - if idserv.store == nil { - return nil - } - if err := v1.ValidateID(v1ID); err != nil { - return err - } - return idserv.store.Set(idserv.namespace(), registry+","+v1ID, []byte(id)) -} diff --git a/vendor/github.com/docker/docker/distribution/metadata/v1_id_service_test.go b/vendor/github.com/docker/docker/distribution/metadata/v1_id_service_test.go deleted file mode 100644 index 5568865..0000000 --- a/vendor/github.com/docker/docker/distribution/metadata/v1_id_service_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package metadata - -import ( - "io/ioutil" - "os" - "testing" - - "github.com/docker/docker/layer" -) - -func TestV1IDService(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "v1-id-service-test") - if err != nil { - t.Fatalf("could not create temp dir: %v", err) - } - defer os.RemoveAll(tmpDir) - - metadataStore, err := NewFSMetadataStore(tmpDir) - if err != nil { - t.Fatalf("could not create metadata store: %v", err) - } - v1IDService := NewV1IDService(metadataStore) - - testVectors := []struct { - registry string - v1ID string - layerID layer.DiffID - }{ - { - registry: "registry1", - v1ID: "f0cd5ca10b07f35512fc2f1cbf9a6cefbdb5cba70ac6b0c9e5988f4497f71937", - layerID: layer.DiffID("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4"), - }, - { - registry: "registry2", - v1ID: "9e3447ca24cb96d86ebd5960cb34d1299b07e0a0e03801d90b9969a2c187dd6e", - layerID: layer.DiffID("sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa"), - }, - { - registry: "registry1", - v1ID: "9e3447ca24cb96d86ebd5960cb34d1299b07e0a0e03801d90b9969a2c187dd6e", - layerID: layer.DiffID("sha256:03f4658f8b782e12230c1783426bd3bacce651ce582a4ffb6fbbfa2079428ecb"), - }, - } - - // Set some associations - for _, vec := range testVectors { - err := v1IDService.Set(vec.v1ID, vec.registry, vec.layerID) - if err != nil { - t.Fatalf("error calling Set: %v", err) - } - } - - // Check the correct values are read back - for _, vec := range testVectors { - layerID, err := v1IDService.Get(vec.v1ID, vec.registry) - if err != nil { - t.Fatalf("error calling Get: %v", err) - } - if layerID != vec.layerID { - t.Fatal("Get returned incorrect layer ID") - } - } - - // Test Get on a nonexistent entry - _, err = v1IDService.Get("82379823067823853223359023576437723560923756b03560378f4497753917", "registry1") - if err == nil { - t.Fatal("expected error looking up nonexistent entry") - } - - // Overwrite one of the entries and read it back - err = v1IDService.Set(testVectors[0].v1ID, testVectors[0].registry, testVectors[1].layerID) - if err != nil { - t.Fatalf("error calling Set: %v", err) - } - layerID, err := v1IDService.Get(testVectors[0].v1ID, testVectors[0].registry) - if err != nil { - t.Fatalf("error calling Get: %v", err) - } - if layerID != testVectors[1].layerID { - t.Fatal("Get returned incorrect layer ID") - } -} diff --git a/vendor/github.com/docker/docker/distribution/metadata/v2_metadata_service.go b/vendor/github.com/docker/docker/distribution/metadata/v2_metadata_service.go deleted file mode 100644 index 02d1b4a..0000000 --- a/vendor/github.com/docker/docker/distribution/metadata/v2_metadata_service.go +++ /dev/null @@ -1,241 +0,0 @@ -package metadata - -import ( - "crypto/hmac" - "crypto/sha256" - "encoding/hex" - "encoding/json" - "errors" - - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types" - "github.com/docker/docker/layer" -) - -// V2MetadataService maps layer IDs to a set of known metadata for -// the layer. -type V2MetadataService interface { - GetMetadata(diffID layer.DiffID) ([]V2Metadata, error) - GetDiffID(dgst digest.Digest) (layer.DiffID, error) - Add(diffID layer.DiffID, metadata V2Metadata) error - TagAndAdd(diffID layer.DiffID, hmacKey []byte, metadata V2Metadata) error - Remove(metadata V2Metadata) error -} - -// v2MetadataService implements V2MetadataService -type v2MetadataService struct { - store Store -} - -var _ V2MetadataService = &v2MetadataService{} - -// V2Metadata contains the digest and source repository information for a layer. -type V2Metadata struct { - Digest digest.Digest - SourceRepository string - // HMAC hashes above attributes with recent authconfig digest used as a key in order to determine matching - // metadata entries accompanied by the same credentials without actually exposing them. - HMAC string -} - -// CheckV2MetadataHMAC return true if the given "meta" is tagged with a hmac hashed by the given "key". -func CheckV2MetadataHMAC(meta *V2Metadata, key []byte) bool { - if len(meta.HMAC) == 0 || len(key) == 0 { - return len(meta.HMAC) == 0 && len(key) == 0 - } - mac := hmac.New(sha256.New, key) - mac.Write([]byte(meta.Digest)) - mac.Write([]byte(meta.SourceRepository)) - expectedMac := mac.Sum(nil) - - storedMac, err := hex.DecodeString(meta.HMAC) - if err != nil { - return false - } - - return hmac.Equal(storedMac, expectedMac) -} - -// ComputeV2MetadataHMAC returns a hmac for the given "meta" hash by the given key. -func ComputeV2MetadataHMAC(key []byte, meta *V2Metadata) string { - if len(key) == 0 || meta == nil { - return "" - } - mac := hmac.New(sha256.New, key) - mac.Write([]byte(meta.Digest)) - mac.Write([]byte(meta.SourceRepository)) - return hex.EncodeToString(mac.Sum(nil)) -} - -// ComputeV2MetadataHMACKey returns a key for the given "authConfig" that can be used to hash v2 metadata -// entries. -func ComputeV2MetadataHMACKey(authConfig *types.AuthConfig) ([]byte, error) { - if authConfig == nil { - return nil, nil - } - key := authConfigKeyInput{ - Username: authConfig.Username, - Password: authConfig.Password, - Auth: authConfig.Auth, - IdentityToken: authConfig.IdentityToken, - RegistryToken: authConfig.RegistryToken, - } - buf, err := json.Marshal(&key) - if err != nil { - return nil, err - } - return []byte(digest.FromBytes([]byte(buf))), nil -} - -// authConfigKeyInput is a reduced AuthConfig structure holding just relevant credential data eligible for -// hmac key creation. -type authConfigKeyInput struct { - Username string `json:"username,omitempty"` - Password string `json:"password,omitempty"` - Auth string `json:"auth,omitempty"` - - IdentityToken string `json:"identitytoken,omitempty"` - RegistryToken string `json:"registrytoken,omitempty"` -} - -// maxMetadata is the number of metadata entries to keep per layer DiffID. -const maxMetadata = 50 - -// NewV2MetadataService creates a new diff ID to v2 metadata mapping service. -func NewV2MetadataService(store Store) V2MetadataService { - return &v2MetadataService{ - store: store, - } -} - -func (serv *v2MetadataService) diffIDNamespace() string { - return "v2metadata-by-diffid" -} - -func (serv *v2MetadataService) digestNamespace() string { - return "diffid-by-digest" -} - -func (serv *v2MetadataService) diffIDKey(diffID layer.DiffID) string { - return string(digest.Digest(diffID).Algorithm()) + "/" + digest.Digest(diffID).Hex() -} - -func (serv *v2MetadataService) digestKey(dgst digest.Digest) string { - return string(dgst.Algorithm()) + "/" + dgst.Hex() -} - -// GetMetadata finds the metadata associated with a layer DiffID. -func (serv *v2MetadataService) GetMetadata(diffID layer.DiffID) ([]V2Metadata, error) { - if serv.store == nil { - return nil, errors.New("no metadata storage") - } - jsonBytes, err := serv.store.Get(serv.diffIDNamespace(), serv.diffIDKey(diffID)) - if err != nil { - return nil, err - } - - var metadata []V2Metadata - if err := json.Unmarshal(jsonBytes, &metadata); err != nil { - return nil, err - } - - return metadata, nil -} - -// GetDiffID finds a layer DiffID from a digest. -func (serv *v2MetadataService) GetDiffID(dgst digest.Digest) (layer.DiffID, error) { - if serv.store == nil { - return layer.DiffID(""), errors.New("no metadata storage") - } - diffIDBytes, err := serv.store.Get(serv.digestNamespace(), serv.digestKey(dgst)) - if err != nil { - return layer.DiffID(""), err - } - - return layer.DiffID(diffIDBytes), nil -} - -// Add associates metadata with a layer DiffID. If too many metadata entries are -// present, the oldest one is dropped. -func (serv *v2MetadataService) Add(diffID layer.DiffID, metadata V2Metadata) error { - if serv.store == nil { - // Support a service which has no backend storage, in this case - // an add becomes a no-op. - // TODO: implement in memory storage - return nil - } - oldMetadata, err := serv.GetMetadata(diffID) - if err != nil { - oldMetadata = nil - } - newMetadata := make([]V2Metadata, 0, len(oldMetadata)+1) - - // Copy all other metadata to new slice - for _, oldMeta := range oldMetadata { - if oldMeta != metadata { - newMetadata = append(newMetadata, oldMeta) - } - } - - newMetadata = append(newMetadata, metadata) - - if len(newMetadata) > maxMetadata { - newMetadata = newMetadata[len(newMetadata)-maxMetadata:] - } - - jsonBytes, err := json.Marshal(newMetadata) - if err != nil { - return err - } - - err = serv.store.Set(serv.diffIDNamespace(), serv.diffIDKey(diffID), jsonBytes) - if err != nil { - return err - } - - return serv.store.Set(serv.digestNamespace(), serv.digestKey(metadata.Digest), []byte(diffID)) -} - -// TagAndAdd amends the given "meta" for hmac hashed by the given "hmacKey" and associates it with a layer -// DiffID. If too many metadata entries are present, the oldest one is dropped. -func (serv *v2MetadataService) TagAndAdd(diffID layer.DiffID, hmacKey []byte, meta V2Metadata) error { - meta.HMAC = ComputeV2MetadataHMAC(hmacKey, &meta) - return serv.Add(diffID, meta) -} - -// Remove unassociates a metadata entry from a layer DiffID. -func (serv *v2MetadataService) Remove(metadata V2Metadata) error { - if serv.store == nil { - // Support a service which has no backend storage, in this case - // an remove becomes a no-op. - // TODO: implement in memory storage - return nil - } - diffID, err := serv.GetDiffID(metadata.Digest) - if err != nil { - return err - } - oldMetadata, err := serv.GetMetadata(diffID) - if err != nil { - oldMetadata = nil - } - newMetadata := make([]V2Metadata, 0, len(oldMetadata)) - - // Copy all other metadata to new slice - for _, oldMeta := range oldMetadata { - if oldMeta != metadata { - newMetadata = append(newMetadata, oldMeta) - } - } - - if len(newMetadata) == 0 { - return serv.store.Delete(serv.diffIDNamespace(), serv.diffIDKey(diffID)) - } - - jsonBytes, err := json.Marshal(newMetadata) - if err != nil { - return err - } - - return serv.store.Set(serv.diffIDNamespace(), serv.diffIDKey(diffID), jsonBytes) -} diff --git a/vendor/github.com/docker/docker/distribution/metadata/v2_metadata_service_test.go b/vendor/github.com/docker/docker/distribution/metadata/v2_metadata_service_test.go deleted file mode 100644 index 7b0ecb1..0000000 --- a/vendor/github.com/docker/docker/distribution/metadata/v2_metadata_service_test.go +++ /dev/null @@ -1,115 +0,0 @@ -package metadata - -import ( - "encoding/hex" - "io/ioutil" - "math/rand" - "os" - "reflect" - "testing" - - "github.com/docker/distribution/digest" - "github.com/docker/docker/layer" -) - -func TestV2MetadataService(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "blobsum-storage-service-test") - if err != nil { - t.Fatalf("could not create temp dir: %v", err) - } - defer os.RemoveAll(tmpDir) - - metadataStore, err := NewFSMetadataStore(tmpDir) - if err != nil { - t.Fatalf("could not create metadata store: %v", err) - } - V2MetadataService := NewV2MetadataService(metadataStore) - - tooManyBlobSums := make([]V2Metadata, 100) - for i := range tooManyBlobSums { - randDigest := randomDigest() - tooManyBlobSums[i] = V2Metadata{Digest: randDigest} - } - - testVectors := []struct { - diffID layer.DiffID - metadata []V2Metadata - }{ - { - diffID: layer.DiffID("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4"), - metadata: []V2Metadata{ - {Digest: digest.Digest("sha256:f0cd5ca10b07f35512fc2f1cbf9a6cefbdb5cba70ac6b0c9e5988f4497f71937")}, - }, - }, - { - diffID: layer.DiffID("sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa"), - metadata: []V2Metadata{ - {Digest: digest.Digest("sha256:f0cd5ca10b07f35512fc2f1cbf9a6cefbdb5cba70ac6b0c9e5988f4497f71937")}, - {Digest: digest.Digest("sha256:9e3447ca24cb96d86ebd5960cb34d1299b07e0a0e03801d90b9969a2c187dd6e")}, - }, - }, - { - diffID: layer.DiffID("sha256:03f4658f8b782e12230c1783426bd3bacce651ce582a4ffb6fbbfa2079428ecb"), - metadata: tooManyBlobSums, - }, - } - - // Set some associations - for _, vec := range testVectors { - for _, blobsum := range vec.metadata { - err := V2MetadataService.Add(vec.diffID, blobsum) - if err != nil { - t.Fatalf("error calling Set: %v", err) - } - } - } - - // Check the correct values are read back - for _, vec := range testVectors { - metadata, err := V2MetadataService.GetMetadata(vec.diffID) - if err != nil { - t.Fatalf("error calling Get: %v", err) - } - expectedMetadataEntries := len(vec.metadata) - if expectedMetadataEntries > 50 { - expectedMetadataEntries = 50 - } - if !reflect.DeepEqual(metadata, vec.metadata[len(vec.metadata)-expectedMetadataEntries:len(vec.metadata)]) { - t.Fatal("Get returned incorrect layer ID") - } - } - - // Test GetMetadata on a nonexistent entry - _, err = V2MetadataService.GetMetadata(layer.DiffID("sha256:82379823067823853223359023576437723560923756b03560378f4497753917")) - if err == nil { - t.Fatal("expected error looking up nonexistent entry") - } - - // Test GetDiffID on a nonexistent entry - _, err = V2MetadataService.GetDiffID(digest.Digest("sha256:82379823067823853223359023576437723560923756b03560378f4497753917")) - if err == nil { - t.Fatal("expected error looking up nonexistent entry") - } - - // Overwrite one of the entries and read it back - err = V2MetadataService.Add(testVectors[1].diffID, testVectors[0].metadata[0]) - if err != nil { - t.Fatalf("error calling Add: %v", err) - } - diffID, err := V2MetadataService.GetDiffID(testVectors[0].metadata[0].Digest) - if err != nil { - t.Fatalf("error calling GetDiffID: %v", err) - } - if diffID != testVectors[1].diffID { - t.Fatal("GetDiffID returned incorrect diffID") - } -} - -func randomDigest() digest.Digest { - b := [32]byte{} - for i := 0; i < len(b); i++ { - b[i] = byte(rand.Intn(256)) - } - d := hex.EncodeToString(b[:]) - return digest.Digest("sha256:" + d) -} diff --git a/vendor/github.com/docker/docker/distribution/pull.go b/vendor/github.com/docker/docker/distribution/pull.go deleted file mode 100644 index a0acfe5..0000000 --- a/vendor/github.com/docker/docker/distribution/pull.go +++ /dev/null @@ -1,200 +0,0 @@ -package distribution - -import ( - "fmt" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/api" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "golang.org/x/net/context" -) - -// Puller is an interface that abstracts pulling for different API versions. -type Puller interface { - // Pull tries to pull the image referenced by `tag` - // Pull returns an error if any, as well as a boolean that determines whether to retry Pull on the next configured endpoint. - // - Pull(ctx context.Context, ref reference.Named) error -} - -// newPuller returns a Puller interface that will pull from either a v1 or v2 -// registry. The endpoint argument contains a Version field that determines -// whether a v1 or v2 puller will be created. The other parameters are passed -// through to the underlying puller implementation for use during the actual -// pull operation. -func newPuller(endpoint registry.APIEndpoint, repoInfo *registry.RepositoryInfo, imagePullConfig *ImagePullConfig) (Puller, error) { - switch endpoint.Version { - case registry.APIVersion2: - return &v2Puller{ - V2MetadataService: metadata.NewV2MetadataService(imagePullConfig.MetadataStore), - endpoint: endpoint, - config: imagePullConfig, - repoInfo: repoInfo, - }, nil - case registry.APIVersion1: - return &v1Puller{ - v1IDService: metadata.NewV1IDService(imagePullConfig.MetadataStore), - endpoint: endpoint, - config: imagePullConfig, - repoInfo: repoInfo, - }, nil - } - return nil, fmt.Errorf("unknown version %d for registry %s", endpoint.Version, endpoint.URL) -} - -// Pull initiates a pull operation. image is the repository name to pull, and -// tag may be either empty, or indicate a specific tag to pull. -func Pull(ctx context.Context, ref reference.Named, imagePullConfig *ImagePullConfig) error { - // Resolve the Repository name from fqn to RepositoryInfo - repoInfo, err := imagePullConfig.RegistryService.ResolveRepository(ref) - if err != nil { - return err - } - - // makes sure name is not empty or `scratch` - if err := ValidateRepoName(repoInfo.Name()); err != nil { - return err - } - - endpoints, err := imagePullConfig.RegistryService.LookupPullEndpoints(repoInfo.Hostname()) - if err != nil { - return err - } - - var ( - lastErr error - - // discardNoSupportErrors is used to track whether an endpoint encountered an error of type registry.ErrNoSupport - // By default it is false, which means that if an ErrNoSupport error is encountered, it will be saved in lastErr. - // As soon as another kind of error is encountered, discardNoSupportErrors is set to true, avoiding the saving of - // any subsequent ErrNoSupport errors in lastErr. - // It's needed for pull-by-digest on v1 endpoints: if there are only v1 endpoints configured, the error should be - // returned and displayed, but if there was a v2 endpoint which supports pull-by-digest, then the last relevant - // error is the ones from v2 endpoints not v1. - discardNoSupportErrors bool - - // confirmedV2 is set to true if a pull attempt managed to - // confirm that it was talking to a v2 registry. This will - // prevent fallback to the v1 protocol. - confirmedV2 bool - - // confirmedTLSRegistries is a map indicating which registries - // are known to be using TLS. There should never be a plaintext - // retry for any of these. - confirmedTLSRegistries = make(map[string]struct{}) - ) - for _, endpoint := range endpoints { - if imagePullConfig.RequireSchema2 && endpoint.Version == registry.APIVersion1 { - continue - } - - if confirmedV2 && endpoint.Version == registry.APIVersion1 { - logrus.Debugf("Skipping v1 endpoint %s because v2 registry was detected", endpoint.URL) - continue - } - - if endpoint.URL.Scheme != "https" { - if _, confirmedTLS := confirmedTLSRegistries[endpoint.URL.Host]; confirmedTLS { - logrus.Debugf("Skipping non-TLS endpoint %s for host/port that appears to use TLS", endpoint.URL) - continue - } - } - - logrus.Debugf("Trying to pull %s from %s %s", repoInfo.Name(), endpoint.URL, endpoint.Version) - - puller, err := newPuller(endpoint, repoInfo, imagePullConfig) - if err != nil { - lastErr = err - continue - } - if err := puller.Pull(ctx, ref); err != nil { - // Was this pull cancelled? If so, don't try to fall - // back. - fallback := false - select { - case <-ctx.Done(): - default: - if fallbackErr, ok := err.(fallbackError); ok { - fallback = true - confirmedV2 = confirmedV2 || fallbackErr.confirmedV2 - if fallbackErr.transportOK && endpoint.URL.Scheme == "https" { - confirmedTLSRegistries[endpoint.URL.Host] = struct{}{} - } - err = fallbackErr.err - } - } - if fallback { - if _, ok := err.(ErrNoSupport); !ok { - // Because we found an error that's not ErrNoSupport, discard all subsequent ErrNoSupport errors. - discardNoSupportErrors = true - // append subsequent errors - lastErr = err - } else if !discardNoSupportErrors { - // Save the ErrNoSupport error, because it's either the first error or all encountered errors - // were also ErrNoSupport errors. - // append subsequent errors - lastErr = err - } - logrus.Errorf("Attempting next endpoint for pull after error: %v", err) - continue - } - logrus.Errorf("Not continuing with pull after error: %v", err) - return TranslatePullError(err, ref) - } - - imagePullConfig.ImageEventLogger(ref.String(), repoInfo.Name(), "pull") - return nil - } - - if lastErr == nil { - lastErr = fmt.Errorf("no endpoints found for %s", ref.String()) - } - - return TranslatePullError(lastErr, ref) -} - -// writeStatus writes a status message to out. If layersDownloaded is true, the -// status message indicates that a newer image was downloaded. Otherwise, it -// indicates that the image is up to date. requestedTag is the tag the message -// will refer to. -func writeStatus(requestedTag string, out progress.Output, layersDownloaded bool) { - if layersDownloaded { - progress.Message(out, "", "Status: Downloaded newer image for "+requestedTag) - } else { - progress.Message(out, "", "Status: Image is up to date for "+requestedTag) - } -} - -// ValidateRepoName validates the name of a repository. -func ValidateRepoName(name string) error { - if name == "" { - return fmt.Errorf("Repository name can't be empty") - } - if name == api.NoBaseImageSpecifier { - return fmt.Errorf("'%s' is a reserved name", api.NoBaseImageSpecifier) - } - return nil -} - -func addDigestReference(store reference.Store, ref reference.Named, dgst digest.Digest, id digest.Digest) error { - dgstRef, err := reference.WithDigest(reference.TrimNamed(ref), dgst) - if err != nil { - return err - } - - if oldTagID, err := store.Get(dgstRef); err == nil { - if oldTagID != id { - // Updating digests not supported by reference store - logrus.Errorf("Image ID for digest %s changed from %s to %s, cannot update", dgst.String(), oldTagID, id) - } - return nil - } else if err != reference.ErrDoesNotExist { - return err - } - - return store.AddDigest(dgstRef, id, true) -} diff --git a/vendor/github.com/docker/docker/distribution/pull_v1.go b/vendor/github.com/docker/docker/distribution/pull_v1.go deleted file mode 100644 index f44ed4f..0000000 --- a/vendor/github.com/docker/docker/distribution/pull_v1.go +++ /dev/null @@ -1,368 +0,0 @@ -package distribution - -import ( - "errors" - "fmt" - "io" - "io/ioutil" - "net" - "net/url" - "os" - "strings" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/registry/client/transport" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/distribution/xfer" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/image" - "github.com/docker/docker/image/v1" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "golang.org/x/net/context" -) - -type v1Puller struct { - v1IDService *metadata.V1IDService - endpoint registry.APIEndpoint - config *ImagePullConfig - repoInfo *registry.RepositoryInfo - session *registry.Session -} - -func (p *v1Puller) Pull(ctx context.Context, ref reference.Named) error { - if _, isCanonical := ref.(reference.Canonical); isCanonical { - // Allowing fallback, because HTTPS v1 is before HTTP v2 - return fallbackError{err: ErrNoSupport{Err: errors.New("Cannot pull by digest with v1 registry")}} - } - - tlsConfig, err := p.config.RegistryService.TLSConfig(p.repoInfo.Index.Name) - if err != nil { - return err - } - // Adds Docker-specific headers as well as user-specified headers (metaHeaders) - tr := transport.NewTransport( - // TODO(tiborvass): was ReceiveTimeout - registry.NewTransport(tlsConfig), - registry.DockerHeaders(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)..., - ) - client := registry.HTTPClient(tr) - v1Endpoint, err := p.endpoint.ToV1Endpoint(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders) - if err != nil { - logrus.Debugf("Could not get v1 endpoint: %v", err) - return fallbackError{err: err} - } - p.session, err = registry.NewSession(client, p.config.AuthConfig, v1Endpoint) - if err != nil { - // TODO(dmcgowan): Check if should fallback - logrus.Debugf("Fallback from error: %s", err) - return fallbackError{err: err} - } - if err := p.pullRepository(ctx, ref); err != nil { - // TODO(dmcgowan): Check if should fallback - return err - } - progress.Message(p.config.ProgressOutput, "", p.repoInfo.FullName()+": this image was pulled from a legacy registry. Important: This registry version will not be supported in future versions of docker.") - - return nil -} - -func (p *v1Puller) pullRepository(ctx context.Context, ref reference.Named) error { - progress.Message(p.config.ProgressOutput, "", "Pulling repository "+p.repoInfo.FullName()) - - tagged, isTagged := ref.(reference.NamedTagged) - - repoData, err := p.session.GetRepositoryData(p.repoInfo) - if err != nil { - if strings.Contains(err.Error(), "HTTP code: 404") { - if isTagged { - return fmt.Errorf("Error: image %s:%s not found", p.repoInfo.RemoteName(), tagged.Tag()) - } - return fmt.Errorf("Error: image %s not found", p.repoInfo.RemoteName()) - } - // Unexpected HTTP error - return err - } - - logrus.Debug("Retrieving the tag list") - var tagsList map[string]string - if !isTagged { - tagsList, err = p.session.GetRemoteTags(repoData.Endpoints, p.repoInfo) - } else { - var tagID string - tagsList = make(map[string]string) - tagID, err = p.session.GetRemoteTag(repoData.Endpoints, p.repoInfo, tagged.Tag()) - if err == registry.ErrRepoNotFound { - return fmt.Errorf("Tag %s not found in repository %s", tagged.Tag(), p.repoInfo.FullName()) - } - tagsList[tagged.Tag()] = tagID - } - if err != nil { - logrus.Errorf("unable to get remote tags: %s", err) - return err - } - - for tag, id := range tagsList { - repoData.ImgList[id] = ®istry.ImgData{ - ID: id, - Tag: tag, - Checksum: "", - } - } - - layersDownloaded := false - for _, imgData := range repoData.ImgList { - if isTagged && imgData.Tag != tagged.Tag() { - continue - } - - err := p.downloadImage(ctx, repoData, imgData, &layersDownloaded) - if err != nil { - return err - } - } - - writeStatus(ref.String(), p.config.ProgressOutput, layersDownloaded) - return nil -} - -func (p *v1Puller) downloadImage(ctx context.Context, repoData *registry.RepositoryData, img *registry.ImgData, layersDownloaded *bool) error { - if img.Tag == "" { - logrus.Debugf("Image (id: %s) present in this repository but untagged, skipping", img.ID) - return nil - } - - localNameRef, err := reference.WithTag(p.repoInfo, img.Tag) - if err != nil { - retErr := fmt.Errorf("Image (id: %s) has invalid tag: %s", img.ID, img.Tag) - logrus.Debug(retErr.Error()) - return retErr - } - - if err := v1.ValidateID(img.ID); err != nil { - return err - } - - progress.Updatef(p.config.ProgressOutput, stringid.TruncateID(img.ID), "Pulling image (%s) from %s", img.Tag, p.repoInfo.FullName()) - success := false - var lastErr error - for _, ep := range p.repoInfo.Index.Mirrors { - ep += "v1/" - progress.Updatef(p.config.ProgressOutput, stringid.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, mirror: %s", img.Tag, p.repoInfo.FullName(), ep)) - if err = p.pullImage(ctx, img.ID, ep, localNameRef, layersDownloaded); err != nil { - // Don't report errors when pulling from mirrors. - logrus.Debugf("Error pulling image (%s) from %s, mirror: %s, %s", img.Tag, p.repoInfo.FullName(), ep, err) - continue - } - success = true - break - } - if !success { - for _, ep := range repoData.Endpoints { - progress.Updatef(p.config.ProgressOutput, stringid.TruncateID(img.ID), "Pulling image (%s) from %s, endpoint: %s", img.Tag, p.repoInfo.FullName(), ep) - if err = p.pullImage(ctx, img.ID, ep, localNameRef, layersDownloaded); err != nil { - // It's not ideal that only the last error is returned, it would be better to concatenate the errors. - // As the error is also given to the output stream the user will see the error. - lastErr = err - progress.Updatef(p.config.ProgressOutput, stringid.TruncateID(img.ID), "Error pulling image (%s) from %s, endpoint: %s, %s", img.Tag, p.repoInfo.FullName(), ep, err) - continue - } - success = true - break - } - } - if !success { - err := fmt.Errorf("Error pulling image (%s) from %s, %v", img.Tag, p.repoInfo.FullName(), lastErr) - progress.Update(p.config.ProgressOutput, stringid.TruncateID(img.ID), err.Error()) - return err - } - return nil -} - -func (p *v1Puller) pullImage(ctx context.Context, v1ID, endpoint string, localNameRef reference.Named, layersDownloaded *bool) (err error) { - var history []string - history, err = p.session.GetRemoteHistory(v1ID, endpoint) - if err != nil { - return err - } - if len(history) < 1 { - return fmt.Errorf("empty history for image %s", v1ID) - } - progress.Update(p.config.ProgressOutput, stringid.TruncateID(v1ID), "Pulling dependent layers") - - var ( - descriptors []xfer.DownloadDescriptor - newHistory []image.History - imgJSON []byte - imgSize int64 - ) - - // Iterate over layers, in order from bottom-most to top-most. Download - // config for all layers and create descriptors. - for i := len(history) - 1; i >= 0; i-- { - v1LayerID := history[i] - imgJSON, imgSize, err = p.downloadLayerConfig(v1LayerID, endpoint) - if err != nil { - return err - } - - // Create a new-style config from the legacy configs - h, err := v1.HistoryFromConfig(imgJSON, false) - if err != nil { - return err - } - newHistory = append(newHistory, h) - - layerDescriptor := &v1LayerDescriptor{ - v1LayerID: v1LayerID, - indexName: p.repoInfo.Index.Name, - endpoint: endpoint, - v1IDService: p.v1IDService, - layersDownloaded: layersDownloaded, - layerSize: imgSize, - session: p.session, - } - - descriptors = append(descriptors, layerDescriptor) - } - - rootFS := image.NewRootFS() - resultRootFS, release, err := p.config.DownloadManager.Download(ctx, *rootFS, descriptors, p.config.ProgressOutput) - if err != nil { - return err - } - defer release() - - config, err := v1.MakeConfigFromV1Config(imgJSON, &resultRootFS, newHistory) - if err != nil { - return err - } - - imageID, err := p.config.ImageStore.Put(config) - if err != nil { - return err - } - - if p.config.ReferenceStore != nil { - if err := p.config.ReferenceStore.AddTag(localNameRef, imageID, true); err != nil { - return err - } - } - - return nil -} - -func (p *v1Puller) downloadLayerConfig(v1LayerID, endpoint string) (imgJSON []byte, imgSize int64, err error) { - progress.Update(p.config.ProgressOutput, stringid.TruncateID(v1LayerID), "Pulling metadata") - - retries := 5 - for j := 1; j <= retries; j++ { - imgJSON, imgSize, err := p.session.GetRemoteImageJSON(v1LayerID, endpoint) - if err != nil && j == retries { - progress.Update(p.config.ProgressOutput, stringid.TruncateID(v1LayerID), "Error pulling layer metadata") - return nil, 0, err - } else if err != nil { - time.Sleep(time.Duration(j) * 500 * time.Millisecond) - continue - } - - return imgJSON, imgSize, nil - } - - // not reached - return nil, 0, nil -} - -type v1LayerDescriptor struct { - v1LayerID string - indexName string - endpoint string - v1IDService *metadata.V1IDService - layersDownloaded *bool - layerSize int64 - session *registry.Session - tmpFile *os.File -} - -func (ld *v1LayerDescriptor) Key() string { - return "v1:" + ld.v1LayerID -} - -func (ld *v1LayerDescriptor) ID() string { - return stringid.TruncateID(ld.v1LayerID) -} - -func (ld *v1LayerDescriptor) DiffID() (layer.DiffID, error) { - return ld.v1IDService.Get(ld.v1LayerID, ld.indexName) -} - -func (ld *v1LayerDescriptor) Download(ctx context.Context, progressOutput progress.Output) (io.ReadCloser, int64, error) { - progress.Update(progressOutput, ld.ID(), "Pulling fs layer") - layerReader, err := ld.session.GetRemoteImageLayer(ld.v1LayerID, ld.endpoint, ld.layerSize) - if err != nil { - progress.Update(progressOutput, ld.ID(), "Error pulling dependent layers") - if uerr, ok := err.(*url.Error); ok { - err = uerr.Err - } - if terr, ok := err.(net.Error); ok && terr.Timeout() { - return nil, 0, err - } - return nil, 0, xfer.DoNotRetry{Err: err} - } - *ld.layersDownloaded = true - - ld.tmpFile, err = ioutil.TempFile("", "GetImageBlob") - if err != nil { - layerReader.Close() - return nil, 0, err - } - - reader := progress.NewProgressReader(ioutils.NewCancelReadCloser(ctx, layerReader), progressOutput, ld.layerSize, ld.ID(), "Downloading") - defer reader.Close() - - _, err = io.Copy(ld.tmpFile, reader) - if err != nil { - ld.Close() - return nil, 0, err - } - - progress.Update(progressOutput, ld.ID(), "Download complete") - - logrus.Debugf("Downloaded %s to tempfile %s", ld.ID(), ld.tmpFile.Name()) - - ld.tmpFile.Seek(0, 0) - - // hand off the temporary file to the download manager, so it will only - // be closed once - tmpFile := ld.tmpFile - ld.tmpFile = nil - - return ioutils.NewReadCloserWrapper(tmpFile, func() error { - tmpFile.Close() - err := os.RemoveAll(tmpFile.Name()) - if err != nil { - logrus.Errorf("Failed to remove temp file: %s", tmpFile.Name()) - } - return err - }), ld.layerSize, nil -} - -func (ld *v1LayerDescriptor) Close() { - if ld.tmpFile != nil { - ld.tmpFile.Close() - if err := os.RemoveAll(ld.tmpFile.Name()); err != nil { - logrus.Errorf("Failed to remove temp file: %s", ld.tmpFile.Name()) - } - ld.tmpFile = nil - } -} - -func (ld *v1LayerDescriptor) Registered(diffID layer.DiffID) { - // Cache mapping from this layer's DiffID to the blobsum - ld.v1IDService.Set(ld.v1LayerID, ld.indexName, diffID) -} diff --git a/vendor/github.com/docker/docker/distribution/pull_v2.go b/vendor/github.com/docker/docker/distribution/pull_v2.go deleted file mode 100644 index 88807ed..0000000 --- a/vendor/github.com/docker/docker/distribution/pull_v2.go +++ /dev/null @@ -1,878 +0,0 @@ -package distribution - -import ( - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "net/url" - "os" - "runtime" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/distribution/manifest/manifestlist" - "github.com/docker/distribution/manifest/schema1" - "github.com/docker/distribution/manifest/schema2" - "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/client/auth" - "github.com/docker/distribution/registry/client/transport" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/distribution/xfer" - "github.com/docker/docker/image" - "github.com/docker/docker/image/v1" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "golang.org/x/net/context" -) - -var ( - errRootFSMismatch = errors.New("layers from manifest don't match image configuration") - errRootFSInvalid = errors.New("invalid rootfs in image configuration") -) - -// ImageConfigPullError is an error pulling the image config blob -// (only applies to schema2). -type ImageConfigPullError struct { - Err error -} - -// Error returns the error string for ImageConfigPullError. -func (e ImageConfigPullError) Error() string { - return "error pulling image configuration: " + e.Err.Error() -} - -type v2Puller struct { - V2MetadataService metadata.V2MetadataService - endpoint registry.APIEndpoint - config *ImagePullConfig - repoInfo *registry.RepositoryInfo - repo distribution.Repository - // confirmedV2 is set to true if we confirm we're talking to a v2 - // registry. This is used to limit fallbacks to the v1 protocol. - confirmedV2 bool -} - -func (p *v2Puller) Pull(ctx context.Context, ref reference.Named) (err error) { - // TODO(tiborvass): was ReceiveTimeout - p.repo, p.confirmedV2, err = NewV2Repository(ctx, p.repoInfo, p.endpoint, p.config.MetaHeaders, p.config.AuthConfig, "pull") - if err != nil { - logrus.Warnf("Error getting v2 registry: %v", err) - return err - } - - if err = p.pullV2Repository(ctx, ref); err != nil { - if _, ok := err.(fallbackError); ok { - return err - } - if continueOnError(err) { - logrus.Errorf("Error trying v2 registry: %v", err) - return fallbackError{ - err: err, - confirmedV2: p.confirmedV2, - transportOK: true, - } - } - } - return err -} - -func (p *v2Puller) pullV2Repository(ctx context.Context, ref reference.Named) (err error) { - var layersDownloaded bool - if !reference.IsNameOnly(ref) { - layersDownloaded, err = p.pullV2Tag(ctx, ref) - if err != nil { - return err - } - } else { - tags, err := p.repo.Tags(ctx).All(ctx) - if err != nil { - // If this repository doesn't exist on V2, we should - // permit a fallback to V1. - return allowV1Fallback(err) - } - - // The v2 registry knows about this repository, so we will not - // allow fallback to the v1 protocol even if we encounter an - // error later on. - p.confirmedV2 = true - - for _, tag := range tags { - tagRef, err := reference.WithTag(ref, tag) - if err != nil { - return err - } - pulledNew, err := p.pullV2Tag(ctx, tagRef) - if err != nil { - // Since this is the pull-all-tags case, don't - // allow an error pulling a particular tag to - // make the whole pull fall back to v1. - if fallbackErr, ok := err.(fallbackError); ok { - return fallbackErr.err - } - return err - } - // pulledNew is true if either new layers were downloaded OR if existing images were newly tagged - // TODO(tiborvass): should we change the name of `layersDownload`? What about message in WriteStatus? - layersDownloaded = layersDownloaded || pulledNew - } - } - - writeStatus(ref.String(), p.config.ProgressOutput, layersDownloaded) - - return nil -} - -type v2LayerDescriptor struct { - digest digest.Digest - repoInfo *registry.RepositoryInfo - repo distribution.Repository - V2MetadataService metadata.V2MetadataService - tmpFile *os.File - verifier digest.Verifier - src distribution.Descriptor -} - -func (ld *v2LayerDescriptor) Key() string { - return "v2:" + ld.digest.String() -} - -func (ld *v2LayerDescriptor) ID() string { - return stringid.TruncateID(ld.digest.String()) -} - -func (ld *v2LayerDescriptor) DiffID() (layer.DiffID, error) { - return ld.V2MetadataService.GetDiffID(ld.digest) -} - -func (ld *v2LayerDescriptor) Download(ctx context.Context, progressOutput progress.Output) (io.ReadCloser, int64, error) { - logrus.Debugf("pulling blob %q", ld.digest) - - var ( - err error - offset int64 - ) - - if ld.tmpFile == nil { - ld.tmpFile, err = createDownloadFile() - if err != nil { - return nil, 0, xfer.DoNotRetry{Err: err} - } - } else { - offset, err = ld.tmpFile.Seek(0, os.SEEK_END) - if err != nil { - logrus.Debugf("error seeking to end of download file: %v", err) - offset = 0 - - ld.tmpFile.Close() - if err := os.Remove(ld.tmpFile.Name()); err != nil { - logrus.Errorf("Failed to remove temp file: %s", ld.tmpFile.Name()) - } - ld.tmpFile, err = createDownloadFile() - if err != nil { - return nil, 0, xfer.DoNotRetry{Err: err} - } - } else if offset != 0 { - logrus.Debugf("attempting to resume download of %q from %d bytes", ld.digest, offset) - } - } - - tmpFile := ld.tmpFile - - layerDownload, err := ld.open(ctx) - if err != nil { - logrus.Errorf("Error initiating layer download: %v", err) - return nil, 0, retryOnError(err) - } - - if offset != 0 { - _, err := layerDownload.Seek(offset, os.SEEK_SET) - if err != nil { - if err := ld.truncateDownloadFile(); err != nil { - return nil, 0, xfer.DoNotRetry{Err: err} - } - return nil, 0, err - } - } - size, err := layerDownload.Seek(0, os.SEEK_END) - if err != nil { - // Seek failed, perhaps because there was no Content-Length - // header. This shouldn't fail the download, because we can - // still continue without a progress bar. - size = 0 - } else { - if size != 0 && offset > size { - logrus.Debug("Partial download is larger than full blob. Starting over") - offset = 0 - if err := ld.truncateDownloadFile(); err != nil { - return nil, 0, xfer.DoNotRetry{Err: err} - } - } - - // Restore the seek offset either at the beginning of the - // stream, or just after the last byte we have from previous - // attempts. - _, err = layerDownload.Seek(offset, os.SEEK_SET) - if err != nil { - return nil, 0, err - } - } - - reader := progress.NewProgressReader(ioutils.NewCancelReadCloser(ctx, layerDownload), progressOutput, size-offset, ld.ID(), "Downloading") - defer reader.Close() - - if ld.verifier == nil { - ld.verifier, err = digest.NewDigestVerifier(ld.digest) - if err != nil { - return nil, 0, xfer.DoNotRetry{Err: err} - } - } - - _, err = io.Copy(tmpFile, io.TeeReader(reader, ld.verifier)) - if err != nil { - if err == transport.ErrWrongCodeForByteRange { - if err := ld.truncateDownloadFile(); err != nil { - return nil, 0, xfer.DoNotRetry{Err: err} - } - return nil, 0, err - } - return nil, 0, retryOnError(err) - } - - progress.Update(progressOutput, ld.ID(), "Verifying Checksum") - - if !ld.verifier.Verified() { - err = fmt.Errorf("filesystem layer verification failed for digest %s", ld.digest) - logrus.Error(err) - - // Allow a retry if this digest verification error happened - // after a resumed download. - if offset != 0 { - if err := ld.truncateDownloadFile(); err != nil { - return nil, 0, xfer.DoNotRetry{Err: err} - } - - return nil, 0, err - } - return nil, 0, xfer.DoNotRetry{Err: err} - } - - progress.Update(progressOutput, ld.ID(), "Download complete") - - logrus.Debugf("Downloaded %s to tempfile %s", ld.ID(), tmpFile.Name()) - - _, err = tmpFile.Seek(0, os.SEEK_SET) - if err != nil { - tmpFile.Close() - if err := os.Remove(tmpFile.Name()); err != nil { - logrus.Errorf("Failed to remove temp file: %s", tmpFile.Name()) - } - ld.tmpFile = nil - ld.verifier = nil - return nil, 0, xfer.DoNotRetry{Err: err} - } - - // hand off the temporary file to the download manager, so it will only - // be closed once - ld.tmpFile = nil - - return ioutils.NewReadCloserWrapper(tmpFile, func() error { - tmpFile.Close() - err := os.RemoveAll(tmpFile.Name()) - if err != nil { - logrus.Errorf("Failed to remove temp file: %s", tmpFile.Name()) - } - return err - }), size, nil -} - -func (ld *v2LayerDescriptor) Close() { - if ld.tmpFile != nil { - ld.tmpFile.Close() - if err := os.RemoveAll(ld.tmpFile.Name()); err != nil { - logrus.Errorf("Failed to remove temp file: %s", ld.tmpFile.Name()) - } - } -} - -func (ld *v2LayerDescriptor) truncateDownloadFile() error { - // Need a new hash context since we will be redoing the download - ld.verifier = nil - - if _, err := ld.tmpFile.Seek(0, os.SEEK_SET); err != nil { - logrus.Errorf("error seeking to beginning of download file: %v", err) - return err - } - - if err := ld.tmpFile.Truncate(0); err != nil { - logrus.Errorf("error truncating download file: %v", err) - return err - } - - return nil -} - -func (ld *v2LayerDescriptor) Registered(diffID layer.DiffID) { - // Cache mapping from this layer's DiffID to the blobsum - ld.V2MetadataService.Add(diffID, metadata.V2Metadata{Digest: ld.digest, SourceRepository: ld.repoInfo.FullName()}) -} - -func (p *v2Puller) pullV2Tag(ctx context.Context, ref reference.Named) (tagUpdated bool, err error) { - manSvc, err := p.repo.Manifests(ctx) - if err != nil { - return false, err - } - - var ( - manifest distribution.Manifest - tagOrDigest string // Used for logging/progress only - ) - if tagged, isTagged := ref.(reference.NamedTagged); isTagged { - manifest, err = manSvc.Get(ctx, "", distribution.WithTag(tagged.Tag())) - if err != nil { - return false, allowV1Fallback(err) - } - tagOrDigest = tagged.Tag() - } else if digested, isDigested := ref.(reference.Canonical); isDigested { - manifest, err = manSvc.Get(ctx, digested.Digest()) - if err != nil { - return false, err - } - tagOrDigest = digested.Digest().String() - } else { - return false, fmt.Errorf("internal error: reference has neither a tag nor a digest: %s", ref.String()) - } - - if manifest == nil { - return false, fmt.Errorf("image manifest does not exist for tag or digest %q", tagOrDigest) - } - - if m, ok := manifest.(*schema2.DeserializedManifest); ok { - var allowedMediatype bool - for _, t := range p.config.Schema2Types { - if m.Manifest.Config.MediaType == t { - allowedMediatype = true - break - } - } - if !allowedMediatype { - configClass := mediaTypeClasses[m.Manifest.Config.MediaType] - if configClass == "" { - configClass = "unknown" - } - return false, fmt.Errorf("target is %s", configClass) - } - } - - // If manSvc.Get succeeded, we can be confident that the registry on - // the other side speaks the v2 protocol. - p.confirmedV2 = true - - logrus.Debugf("Pulling ref from V2 registry: %s", ref.String()) - progress.Message(p.config.ProgressOutput, tagOrDigest, "Pulling from "+p.repo.Named().Name()) - - var ( - id digest.Digest - manifestDigest digest.Digest - ) - - switch v := manifest.(type) { - case *schema1.SignedManifest: - if p.config.RequireSchema2 { - return false, fmt.Errorf("invalid manifest: not schema2") - } - id, manifestDigest, err = p.pullSchema1(ctx, ref, v) - if err != nil { - return false, err - } - case *schema2.DeserializedManifest: - id, manifestDigest, err = p.pullSchema2(ctx, ref, v) - if err != nil { - return false, err - } - case *manifestlist.DeserializedManifestList: - id, manifestDigest, err = p.pullManifestList(ctx, ref, v) - if err != nil { - return false, err - } - default: - return false, errors.New("unsupported manifest format") - } - - progress.Message(p.config.ProgressOutput, "", "Digest: "+manifestDigest.String()) - - if p.config.ReferenceStore != nil { - oldTagID, err := p.config.ReferenceStore.Get(ref) - if err == nil { - if oldTagID == id { - return false, addDigestReference(p.config.ReferenceStore, ref, manifestDigest, id) - } - } else if err != reference.ErrDoesNotExist { - return false, err - } - - if canonical, ok := ref.(reference.Canonical); ok { - if err = p.config.ReferenceStore.AddDigest(canonical, id, true); err != nil { - return false, err - } - } else { - if err = addDigestReference(p.config.ReferenceStore, ref, manifestDigest, id); err != nil { - return false, err - } - if err = p.config.ReferenceStore.AddTag(ref, id, true); err != nil { - return false, err - } - } - } - return true, nil -} - -func (p *v2Puller) pullSchema1(ctx context.Context, ref reference.Named, unverifiedManifest *schema1.SignedManifest) (id digest.Digest, manifestDigest digest.Digest, err error) { - var verifiedManifest *schema1.Manifest - verifiedManifest, err = verifySchema1Manifest(unverifiedManifest, ref) - if err != nil { - return "", "", err - } - - rootFS := image.NewRootFS() - - // remove duplicate layers and check parent chain validity - err = fixManifestLayers(verifiedManifest) - if err != nil { - return "", "", err - } - - var descriptors []xfer.DownloadDescriptor - - // Image history converted to the new format - var history []image.History - - // Note that the order of this loop is in the direction of bottom-most - // to top-most, so that the downloads slice gets ordered correctly. - for i := len(verifiedManifest.FSLayers) - 1; i >= 0; i-- { - blobSum := verifiedManifest.FSLayers[i].BlobSum - - var throwAway struct { - ThrowAway bool `json:"throwaway,omitempty"` - } - if err := json.Unmarshal([]byte(verifiedManifest.History[i].V1Compatibility), &throwAway); err != nil { - return "", "", err - } - - h, err := v1.HistoryFromConfig([]byte(verifiedManifest.History[i].V1Compatibility), throwAway.ThrowAway) - if err != nil { - return "", "", err - } - history = append(history, h) - - if throwAway.ThrowAway { - continue - } - - layerDescriptor := &v2LayerDescriptor{ - digest: blobSum, - repoInfo: p.repoInfo, - repo: p.repo, - V2MetadataService: p.V2MetadataService, - } - - descriptors = append(descriptors, layerDescriptor) - } - - resultRootFS, release, err := p.config.DownloadManager.Download(ctx, *rootFS, descriptors, p.config.ProgressOutput) - if err != nil { - return "", "", err - } - defer release() - - config, err := v1.MakeConfigFromV1Config([]byte(verifiedManifest.History[0].V1Compatibility), &resultRootFS, history) - if err != nil { - return "", "", err - } - - imageID, err := p.config.ImageStore.Put(config) - if err != nil { - return "", "", err - } - - manifestDigest = digest.FromBytes(unverifiedManifest.Canonical) - - return imageID, manifestDigest, nil -} - -func (p *v2Puller) pullSchema2(ctx context.Context, ref reference.Named, mfst *schema2.DeserializedManifest) (id digest.Digest, manifestDigest digest.Digest, err error) { - manifestDigest, err = schema2ManifestDigest(ref, mfst) - if err != nil { - return "", "", err - } - - target := mfst.Target() - if _, err := p.config.ImageStore.Get(target.Digest); err == nil { - // If the image already exists locally, no need to pull - // anything. - return target.Digest, manifestDigest, nil - } - - var descriptors []xfer.DownloadDescriptor - - // Note that the order of this loop is in the direction of bottom-most - // to top-most, so that the downloads slice gets ordered correctly. - for _, d := range mfst.Layers { - layerDescriptor := &v2LayerDescriptor{ - digest: d.Digest, - repo: p.repo, - repoInfo: p.repoInfo, - V2MetadataService: p.V2MetadataService, - src: d, - } - - descriptors = append(descriptors, layerDescriptor) - } - - configChan := make(chan []byte, 1) - errChan := make(chan error, 1) - var cancel func() - ctx, cancel = context.WithCancel(ctx) - - // Pull the image config - go func() { - configJSON, err := p.pullSchema2Config(ctx, target.Digest) - if err != nil { - errChan <- ImageConfigPullError{Err: err} - cancel() - return - } - configChan <- configJSON - }() - - var ( - configJSON []byte // raw serialized image config - downloadedRootFS *image.RootFS // rootFS from registered layers - configRootFS *image.RootFS // rootFS from configuration - ) - - // https://github.com/docker/docker/issues/24766 - Err on the side of caution, - // explicitly blocking images intended for linux from the Windows daemon. On - // Windows, we do this before the attempt to download, effectively serialising - // the download slightly slowing it down. We have to do it this way, as - // chances are the download of layers itself would fail due to file names - // which aren't suitable for NTFS. At some point in the future, if a similar - // check to block Windows images being pulled on Linux is implemented, it - // may be necessary to perform the same type of serialisation. - if runtime.GOOS == "windows" { - configJSON, configRootFS, err = receiveConfig(p.config.ImageStore, configChan, errChan) - if err != nil { - return "", "", err - } - - if configRootFS == nil { - return "", "", errRootFSInvalid - } - } - - if p.config.DownloadManager != nil { - downloadRootFS := *image.NewRootFS() - rootFS, release, err := p.config.DownloadManager.Download(ctx, downloadRootFS, descriptors, p.config.ProgressOutput) - if err != nil { - if configJSON != nil { - // Already received the config - return "", "", err - } - select { - case err = <-errChan: - return "", "", err - default: - cancel() - select { - case <-configChan: - case <-errChan: - } - return "", "", err - } - } - if release != nil { - defer release() - } - - downloadedRootFS = &rootFS - } - - if configJSON == nil { - configJSON, configRootFS, err = receiveConfig(p.config.ImageStore, configChan, errChan) - if err != nil { - return "", "", err - } - - if configRootFS == nil { - return "", "", errRootFSInvalid - } - } - - if downloadedRootFS != nil { - // The DiffIDs returned in rootFS MUST match those in the config. - // Otherwise the image config could be referencing layers that aren't - // included in the manifest. - if len(downloadedRootFS.DiffIDs) != len(configRootFS.DiffIDs) { - return "", "", errRootFSMismatch - } - - for i := range downloadedRootFS.DiffIDs { - if downloadedRootFS.DiffIDs[i] != configRootFS.DiffIDs[i] { - return "", "", errRootFSMismatch - } - } - } - - imageID, err := p.config.ImageStore.Put(configJSON) - if err != nil { - return "", "", err - } - - return imageID, manifestDigest, nil -} - -func receiveConfig(s ImageConfigStore, configChan <-chan []byte, errChan <-chan error) ([]byte, *image.RootFS, error) { - select { - case configJSON := <-configChan: - rootfs, err := s.RootFSFromConfig(configJSON) - if err != nil { - return nil, nil, err - } - return configJSON, rootfs, nil - case err := <-errChan: - return nil, nil, err - // Don't need a case for ctx.Done in the select because cancellation - // will trigger an error in p.pullSchema2ImageConfig. - } -} - -// pullManifestList handles "manifest lists" which point to various -// platform-specifc manifests. -func (p *v2Puller) pullManifestList(ctx context.Context, ref reference.Named, mfstList *manifestlist.DeserializedManifestList) (id digest.Digest, manifestListDigest digest.Digest, err error) { - manifestListDigest, err = schema2ManifestDigest(ref, mfstList) - if err != nil { - return "", "", err - } - - var manifestDigest digest.Digest - for _, manifestDescriptor := range mfstList.Manifests { - // TODO(aaronl): The manifest list spec supports optional - // "features" and "variant" fields. These are not yet used. - // Once they are, their values should be interpreted here. - if manifestDescriptor.Platform.Architecture == runtime.GOARCH && manifestDescriptor.Platform.OS == runtime.GOOS { - manifestDigest = manifestDescriptor.Digest - break - } - } - - if manifestDigest == "" { - return "", "", errors.New("no supported platform found in manifest list") - } - - manSvc, err := p.repo.Manifests(ctx) - if err != nil { - return "", "", err - } - - manifest, err := manSvc.Get(ctx, manifestDigest) - if err != nil { - return "", "", err - } - - manifestRef, err := reference.WithDigest(reference.TrimNamed(ref), manifestDigest) - if err != nil { - return "", "", err - } - - switch v := manifest.(type) { - case *schema1.SignedManifest: - id, _, err = p.pullSchema1(ctx, manifestRef, v) - if err != nil { - return "", "", err - } - case *schema2.DeserializedManifest: - id, _, err = p.pullSchema2(ctx, manifestRef, v) - if err != nil { - return "", "", err - } - default: - return "", "", errors.New("unsupported manifest format") - } - - return id, manifestListDigest, err -} - -func (p *v2Puller) pullSchema2Config(ctx context.Context, dgst digest.Digest) (configJSON []byte, err error) { - blobs := p.repo.Blobs(ctx) - configJSON, err = blobs.Get(ctx, dgst) - if err != nil { - return nil, err - } - - // Verify image config digest - verifier, err := digest.NewDigestVerifier(dgst) - if err != nil { - return nil, err - } - if _, err := verifier.Write(configJSON); err != nil { - return nil, err - } - if !verifier.Verified() { - err := fmt.Errorf("image config verification failed for digest %s", dgst) - logrus.Error(err) - return nil, err - } - - return configJSON, nil -} - -// schema2ManifestDigest computes the manifest digest, and, if pulling by -// digest, ensures that it matches the requested digest. -func schema2ManifestDigest(ref reference.Named, mfst distribution.Manifest) (digest.Digest, error) { - _, canonical, err := mfst.Payload() - if err != nil { - return "", err - } - - // If pull by digest, then verify the manifest digest. - if digested, isDigested := ref.(reference.Canonical); isDigested { - verifier, err := digest.NewDigestVerifier(digested.Digest()) - if err != nil { - return "", err - } - if _, err := verifier.Write(canonical); err != nil { - return "", err - } - if !verifier.Verified() { - err := fmt.Errorf("manifest verification failed for digest %s", digested.Digest()) - logrus.Error(err) - return "", err - } - return digested.Digest(), nil - } - - return digest.FromBytes(canonical), nil -} - -// allowV1Fallback checks if the error is a possible reason to fallback to v1 -// (even if confirmedV2 has been set already), and if so, wraps the error in -// a fallbackError with confirmedV2 set to false. Otherwise, it returns the -// error unmodified. -func allowV1Fallback(err error) error { - switch v := err.(type) { - case errcode.Errors: - if len(v) != 0 { - if v0, ok := v[0].(errcode.Error); ok && shouldV2Fallback(v0) { - return fallbackError{ - err: err, - confirmedV2: false, - transportOK: true, - } - } - } - case errcode.Error: - if shouldV2Fallback(v) { - return fallbackError{ - err: err, - confirmedV2: false, - transportOK: true, - } - } - case *url.Error: - if v.Err == auth.ErrNoBasicAuthCredentials { - return fallbackError{err: err, confirmedV2: false} - } - } - - return err -} - -func verifySchema1Manifest(signedManifest *schema1.SignedManifest, ref reference.Named) (m *schema1.Manifest, err error) { - // If pull by digest, then verify the manifest digest. NOTE: It is - // important to do this first, before any other content validation. If the - // digest cannot be verified, don't even bother with those other things. - if digested, isCanonical := ref.(reference.Canonical); isCanonical { - verifier, err := digest.NewDigestVerifier(digested.Digest()) - if err != nil { - return nil, err - } - if _, err := verifier.Write(signedManifest.Canonical); err != nil { - return nil, err - } - if !verifier.Verified() { - err := fmt.Errorf("image verification failed for digest %s", digested.Digest()) - logrus.Error(err) - return nil, err - } - } - m = &signedManifest.Manifest - - if m.SchemaVersion != 1 { - return nil, fmt.Errorf("unsupported schema version %d for %q", m.SchemaVersion, ref.String()) - } - if len(m.FSLayers) != len(m.History) { - return nil, fmt.Errorf("length of history not equal to number of layers for %q", ref.String()) - } - if len(m.FSLayers) == 0 { - return nil, fmt.Errorf("no FSLayers in manifest for %q", ref.String()) - } - return m, nil -} - -// fixManifestLayers removes repeated layers from the manifest and checks the -// correctness of the parent chain. -func fixManifestLayers(m *schema1.Manifest) error { - imgs := make([]*image.V1Image, len(m.FSLayers)) - for i := range m.FSLayers { - img := &image.V1Image{} - - if err := json.Unmarshal([]byte(m.History[i].V1Compatibility), img); err != nil { - return err - } - - imgs[i] = img - if err := v1.ValidateID(img.ID); err != nil { - return err - } - } - - if imgs[len(imgs)-1].Parent != "" && runtime.GOOS != "windows" { - // Windows base layer can point to a base layer parent that is not in manifest. - return errors.New("invalid parent ID in the base layer of the image") - } - - // check general duplicates to error instead of a deadlock - idmap := make(map[string]struct{}) - - var lastID string - for _, img := range imgs { - // skip IDs that appear after each other, we handle those later - if _, exists := idmap[img.ID]; img.ID != lastID && exists { - return fmt.Errorf("ID %+v appears multiple times in manifest", img.ID) - } - lastID = img.ID - idmap[lastID] = struct{}{} - } - - // backwards loop so that we keep the remaining indexes after removing items - for i := len(imgs) - 2; i >= 0; i-- { - if imgs[i].ID == imgs[i+1].ID { // repeated ID. remove and continue - m.FSLayers = append(m.FSLayers[:i], m.FSLayers[i+1:]...) - m.History = append(m.History[:i], m.History[i+1:]...) - } else if imgs[i].Parent != imgs[i+1].ID { - return fmt.Errorf("Invalid parent ID. Expected %v, got %v.", imgs[i+1].ID, imgs[i].Parent) - } - } - - return nil -} - -func createDownloadFile() (*os.File, error) { - return ioutil.TempFile("", "GetImageBlob") -} diff --git a/vendor/github.com/docker/docker/distribution/pull_v2_test.go b/vendor/github.com/docker/docker/distribution/pull_v2_test.go deleted file mode 100644 index b745642..0000000 --- a/vendor/github.com/docker/docker/distribution/pull_v2_test.go +++ /dev/null @@ -1,183 +0,0 @@ -package distribution - -import ( - "encoding/json" - "io/ioutil" - "reflect" - "runtime" - "strings" - "testing" - - "github.com/docker/distribution/digest" - "github.com/docker/distribution/manifest/schema1" - "github.com/docker/docker/reference" -) - -// TestFixManifestLayers checks that fixManifestLayers removes a duplicate -// layer, and that it makes no changes to the manifest when called a second -// time, after the duplicate is removed. -func TestFixManifestLayers(t *testing.T) { - duplicateLayerManifest := schema1.Manifest{ - FSLayers: []schema1.FSLayer{ - {BlobSum: digest.Digest("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4")}, - {BlobSum: digest.Digest("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4")}, - {BlobSum: digest.Digest("sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa")}, - }, - History: []schema1.History{ - {V1Compatibility: "{\"id\":\"3b38edc92eb7c074812e217b41a6ade66888531009d6286a6f5f36a06f9841b9\",\"parent\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"created\":\"2015-08-19T16:49:11.368300679Z\",\"container\":\"d91be3479d5b1e84b0c00d18eea9dc777ca0ad166d51174b24283e2e6f104253\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) ENTRYPOINT [\\\"/go/bin/dnsdock\\\"]\"],\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":null,\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":0}\n"}, - {V1Compatibility: "{\"id\":\"3b38edc92eb7c074812e217b41a6ade66888531009d6286a6f5f36a06f9841b9\",\"parent\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"created\":\"2015-08-19T16:49:11.368300679Z\",\"container\":\"d91be3479d5b1e84b0c00d18eea9dc777ca0ad166d51174b24283e2e6f104253\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) ENTRYPOINT [\\\"/go/bin/dnsdock\\\"]\"],\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":null,\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":0}\n"}, - {V1Compatibility: "{\"id\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"created\":\"2015-08-19T16:49:07.568027497Z\",\"container\":\"fe9e5a5264a843c9292d17b736c92dd19bdb49986a8782d7389964ddaff887cc\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"cd /go/src/github.com/tonistiigi/dnsdock \\u0026\\u0026 go get -v github.com/tools/godep \\u0026\\u0026 godep restore \\u0026\\u0026 go install -ldflags \\\"-X main.version `git describe --tags HEAD``if [[ -n $(command git status --porcelain --untracked-files=no 2\\u003e/dev/null) ]]; then echo \\\"-dirty\\\"; fi`\\\" ./...\"],\"Image\":\"e3b0ff09e647595dafee15c54cd632c900df9e82b1d4d313b1e20639a1461779\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/bash\"],\"Image\":\"e3b0ff09e647595dafee15c54cd632c900df9e82b1d4d313b1e20639a1461779\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":118430532}\n"}, - }, - } - - duplicateLayerManifestExpectedOutput := schema1.Manifest{ - FSLayers: []schema1.FSLayer{ - {BlobSum: digest.Digest("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4")}, - {BlobSum: digest.Digest("sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa")}, - }, - History: []schema1.History{ - {V1Compatibility: "{\"id\":\"3b38edc92eb7c074812e217b41a6ade66888531009d6286a6f5f36a06f9841b9\",\"parent\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"created\":\"2015-08-19T16:49:11.368300679Z\",\"container\":\"d91be3479d5b1e84b0c00d18eea9dc777ca0ad166d51174b24283e2e6f104253\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) ENTRYPOINT [\\\"/go/bin/dnsdock\\\"]\"],\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":null,\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":0}\n"}, - {V1Compatibility: "{\"id\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"created\":\"2015-08-19T16:49:07.568027497Z\",\"container\":\"fe9e5a5264a843c9292d17b736c92dd19bdb49986a8782d7389964ddaff887cc\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"cd /go/src/github.com/tonistiigi/dnsdock \\u0026\\u0026 go get -v github.com/tools/godep \\u0026\\u0026 godep restore \\u0026\\u0026 go install -ldflags \\\"-X main.version `git describe --tags HEAD``if [[ -n $(command git status --porcelain --untracked-files=no 2\\u003e/dev/null) ]]; then echo \\\"-dirty\\\"; fi`\\\" ./...\"],\"Image\":\"e3b0ff09e647595dafee15c54cd632c900df9e82b1d4d313b1e20639a1461779\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/bash\"],\"Image\":\"e3b0ff09e647595dafee15c54cd632c900df9e82b1d4d313b1e20639a1461779\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":118430532}\n"}, - }, - } - - if err := fixManifestLayers(&duplicateLayerManifest); err != nil { - t.Fatalf("unexpected error from fixManifestLayers: %v", err) - } - - if !reflect.DeepEqual(duplicateLayerManifest, duplicateLayerManifestExpectedOutput) { - t.Fatal("incorrect output from fixManifestLayers on duplicate layer manifest") - } - - // Run fixManifestLayers again and confirm that it doesn't change the - // manifest (which no longer has duplicate layers). - if err := fixManifestLayers(&duplicateLayerManifest); err != nil { - t.Fatalf("unexpected error from fixManifestLayers: %v", err) - } - - if !reflect.DeepEqual(duplicateLayerManifest, duplicateLayerManifestExpectedOutput) { - t.Fatal("incorrect output from fixManifestLayers on duplicate layer manifest (second pass)") - } -} - -// TestFixManifestLayersBaseLayerParent makes sure that fixManifestLayers fails -// if the base layer configuration specifies a parent. -func TestFixManifestLayersBaseLayerParent(t *testing.T) { - // TODO Windows: Fix this unit text - if runtime.GOOS == "windows" { - t.Skip("Needs fixing on Windows") - } - duplicateLayerManifest := schema1.Manifest{ - FSLayers: []schema1.FSLayer{ - {BlobSum: digest.Digest("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4")}, - {BlobSum: digest.Digest("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4")}, - {BlobSum: digest.Digest("sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa")}, - }, - History: []schema1.History{ - {V1Compatibility: "{\"id\":\"3b38edc92eb7c074812e217b41a6ade66888531009d6286a6f5f36a06f9841b9\",\"parent\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"created\":\"2015-08-19T16:49:11.368300679Z\",\"container\":\"d91be3479d5b1e84b0c00d18eea9dc777ca0ad166d51174b24283e2e6f104253\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) ENTRYPOINT [\\\"/go/bin/dnsdock\\\"]\"],\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":null,\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":0}\n"}, - {V1Compatibility: "{\"id\":\"3b38edc92eb7c074812e217b41a6ade66888531009d6286a6f5f36a06f9841b9\",\"parent\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"created\":\"2015-08-19T16:49:11.368300679Z\",\"container\":\"d91be3479d5b1e84b0c00d18eea9dc777ca0ad166d51174b24283e2e6f104253\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) ENTRYPOINT [\\\"/go/bin/dnsdock\\\"]\"],\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":null,\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":0}\n"}, - {V1Compatibility: "{\"id\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"parent\":\"e3b0ff09e647595dafee15c54cd632c900df9e82b1d4d313b1e20639a1461779\",\"created\":\"2015-08-19T16:49:07.568027497Z\",\"container\":\"fe9e5a5264a843c9292d17b736c92dd19bdb49986a8782d7389964ddaff887cc\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"cd /go/src/github.com/tonistiigi/dnsdock \\u0026\\u0026 go get -v github.com/tools/godep \\u0026\\u0026 godep restore \\u0026\\u0026 go install -ldflags \\\"-X main.version `git describe --tags HEAD``if [[ -n $(command git status --porcelain --untracked-files=no 2\\u003e/dev/null) ]]; then echo \\\"-dirty\\\"; fi`\\\" ./...\"],\"Image\":\"e3b0ff09e647595dafee15c54cd632c900df9e82b1d4d313b1e20639a1461779\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/bash\"],\"Image\":\"e3b0ff09e647595dafee15c54cd632c900df9e82b1d4d313b1e20639a1461779\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":118430532}\n"}, - }, - } - - if err := fixManifestLayers(&duplicateLayerManifest); err == nil || !strings.Contains(err.Error(), "invalid parent ID in the base layer of the image") { - t.Fatalf("expected an invalid parent ID error from fixManifestLayers") - } -} - -// TestFixManifestLayersBadParent makes sure that fixManifestLayers fails -// if an image configuration specifies a parent that doesn't directly follow -// that (deduplicated) image in the image history. -func TestFixManifestLayersBadParent(t *testing.T) { - duplicateLayerManifest := schema1.Manifest{ - FSLayers: []schema1.FSLayer{ - {BlobSum: digest.Digest("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4")}, - {BlobSum: digest.Digest("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4")}, - {BlobSum: digest.Digest("sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa")}, - }, - History: []schema1.History{ - {V1Compatibility: "{\"id\":\"3b38edc92eb7c074812e217b41a6ade66888531009d6286a6f5f36a06f9841b9\",\"parent\":\"ac3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"created\":\"2015-08-19T16:49:11.368300679Z\",\"container\":\"d91be3479d5b1e84b0c00d18eea9dc777ca0ad166d51174b24283e2e6f104253\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) ENTRYPOINT [\\\"/go/bin/dnsdock\\\"]\"],\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":null,\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":0}\n"}, - {V1Compatibility: "{\"id\":\"3b38edc92eb7c074812e217b41a6ade66888531009d6286a6f5f36a06f9841b9\",\"parent\":\"ac3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"created\":\"2015-08-19T16:49:11.368300679Z\",\"container\":\"d91be3479d5b1e84b0c00d18eea9dc777ca0ad166d51174b24283e2e6f104253\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) ENTRYPOINT [\\\"/go/bin/dnsdock\\\"]\"],\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":null,\"Image\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":[\"/go/bin/dnsdock\"],\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":0}\n"}, - {V1Compatibility: "{\"id\":\"ec3025ca8cc9bcab039e193e20ec647c2da3c53a74020f2ba611601f9b2c6c02\",\"created\":\"2015-08-19T16:49:07.568027497Z\",\"container\":\"fe9e5a5264a843c9292d17b736c92dd19bdb49986a8782d7389964ddaff887cc\",\"container_config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"cd /go/src/github.com/tonistiigi/dnsdock \\u0026\\u0026 go get -v github.com/tools/godep \\u0026\\u0026 godep restore \\u0026\\u0026 go install -ldflags \\\"-X main.version `git describe --tags HEAD``if [[ -n $(command git status --porcelain --untracked-files=no 2\\u003e/dev/null) ]]; then echo \\\"-dirty\\\"; fi`\\\" ./...\"],\"Image\":\"e3b0ff09e647595dafee15c54cd632c900df9e82b1d4d313b1e20639a1461779\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"docker_version\":\"1.6.2\",\"config\":{\"Hostname\":\"03797203757d\",\"Domainname\":\"\",\"User\":\"\",\"Memory\":0,\"MemorySwap\":0,\"CpuShares\":0,\"Cpuset\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"PortSpecs\":null,\"ExposedPorts\":null,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/go/bin:/usr/src/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\"GOLANG_VERSION=1.4.1\",\"GOPATH=/go\"],\"Cmd\":[\"/bin/bash\"],\"Image\":\"e3b0ff09e647595dafee15c54cd632c900df9e82b1d4d313b1e20639a1461779\",\"Volumes\":null,\"WorkingDir\":\"/go\",\"Entrypoint\":null,\"NetworkDisabled\":false,\"MacAddress\":\"\",\"OnBuild\":[],\"Labels\":{}},\"architecture\":\"amd64\",\"os\":\"linux\",\"Size\":118430532}\n"}, - }, - } - - if err := fixManifestLayers(&duplicateLayerManifest); err == nil || !strings.Contains(err.Error(), "Invalid parent ID.") { - t.Fatalf("expected an invalid parent ID error from fixManifestLayers") - } -} - -// TestValidateManifest verifies the validateManifest function -func TestValidateManifest(t *testing.T) { - // TODO Windows: Fix this unit text - if runtime.GOOS == "windows" { - t.Skip("Needs fixing on Windows") - } - expectedDigest, err := reference.ParseNamed("repo@sha256:02fee8c3220ba806531f606525eceb83f4feb654f62b207191b1c9209188dedd") - if err != nil { - t.Fatal("could not parse reference") - } - expectedFSLayer0 := digest.Digest("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4") - - // Good manifest - - goodManifestBytes, err := ioutil.ReadFile("fixtures/validate_manifest/good_manifest") - if err != nil { - t.Fatal("error reading fixture:", err) - } - - var goodSignedManifest schema1.SignedManifest - err = json.Unmarshal(goodManifestBytes, &goodSignedManifest) - if err != nil { - t.Fatal("error unmarshaling manifest:", err) - } - - verifiedManifest, err := verifySchema1Manifest(&goodSignedManifest, expectedDigest) - if err != nil { - t.Fatal("validateManifest failed:", err) - } - - if verifiedManifest.FSLayers[0].BlobSum != expectedFSLayer0 { - t.Fatal("unexpected FSLayer in good manifest") - } - - // "Extra data" manifest - - extraDataManifestBytes, err := ioutil.ReadFile("fixtures/validate_manifest/extra_data_manifest") - if err != nil { - t.Fatal("error reading fixture:", err) - } - - var extraDataSignedManifest schema1.SignedManifest - err = json.Unmarshal(extraDataManifestBytes, &extraDataSignedManifest) - if err != nil { - t.Fatal("error unmarshaling manifest:", err) - } - - verifiedManifest, err = verifySchema1Manifest(&extraDataSignedManifest, expectedDigest) - if err != nil { - t.Fatal("validateManifest failed:", err) - } - - if verifiedManifest.FSLayers[0].BlobSum != expectedFSLayer0 { - t.Fatal("unexpected FSLayer in extra data manifest") - } - - // Bad manifest - - badManifestBytes, err := ioutil.ReadFile("fixtures/validate_manifest/bad_manifest") - if err != nil { - t.Fatal("error reading fixture:", err) - } - - var badSignedManifest schema1.SignedManifest - err = json.Unmarshal(badManifestBytes, &badSignedManifest) - if err != nil { - t.Fatal("error unmarshaling manifest:", err) - } - - verifiedManifest, err = verifySchema1Manifest(&badSignedManifest, expectedDigest) - if err == nil || !strings.HasPrefix(err.Error(), "image verification failed for digest") { - t.Fatal("expected validateManifest to fail with digest error") - } -} diff --git a/vendor/github.com/docker/docker/distribution/pull_v2_unix.go b/vendor/github.com/docker/docker/distribution/pull_v2_unix.go deleted file mode 100644 index 45a7a0c..0000000 --- a/vendor/github.com/docker/docker/distribution/pull_v2_unix.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build !windows - -package distribution - -import ( - "github.com/docker/distribution" - "github.com/docker/distribution/context" -) - -func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) { - blobs := ld.repo.Blobs(ctx) - return blobs.Open(ctx, ld.digest) -} diff --git a/vendor/github.com/docker/docker/distribution/pull_v2_windows.go b/vendor/github.com/docker/docker/distribution/pull_v2_windows.go deleted file mode 100644 index aefed86..0000000 --- a/vendor/github.com/docker/docker/distribution/pull_v2_windows.go +++ /dev/null @@ -1,49 +0,0 @@ -// +build windows - -package distribution - -import ( - "net/http" - "os" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution" - "github.com/docker/distribution/context" - "github.com/docker/distribution/manifest/schema2" - "github.com/docker/distribution/registry/client/transport" -) - -var _ distribution.Describable = &v2LayerDescriptor{} - -func (ld *v2LayerDescriptor) Descriptor() distribution.Descriptor { - if ld.src.MediaType == schema2.MediaTypeForeignLayer && len(ld.src.URLs) > 0 { - return ld.src - } - return distribution.Descriptor{} -} - -func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) { - if len(ld.src.URLs) == 0 { - blobs := ld.repo.Blobs(ctx) - return blobs.Open(ctx, ld.digest) - } - - var ( - err error - rsc distribution.ReadSeekCloser - ) - - // Find the first URL that results in a 200 result code. - for _, url := range ld.src.URLs { - logrus.Debugf("Pulling %v from foreign URL %v", ld.digest, url) - rsc = transport.NewHTTPReadSeeker(http.DefaultClient, url, nil) - _, err = rsc.Seek(0, os.SEEK_SET) - if err == nil { - break - } - logrus.Debugf("Download for %v failed: %v", ld.digest, err) - rsc.Close() - rsc = nil - } - return rsc, err -} diff --git a/vendor/github.com/docker/docker/distribution/push.go b/vendor/github.com/docker/docker/distribution/push.go deleted file mode 100644 index d35bdb1..0000000 --- a/vendor/github.com/docker/docker/distribution/push.go +++ /dev/null @@ -1,186 +0,0 @@ -package distribution - -import ( - "bufio" - "compress/gzip" - "fmt" - "io" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "golang.org/x/net/context" -) - -// Pusher is an interface that abstracts pushing for different API versions. -type Pusher interface { - // Push tries to push the image configured at the creation of Pusher. - // Push returns an error if any, as well as a boolean that determines whether to retry Push on the next configured endpoint. - // - // TODO(tiborvass): have Push() take a reference to repository + tag, so that the pusher itself is repository-agnostic. - Push(ctx context.Context) error -} - -const compressionBufSize = 32768 - -// NewPusher creates a new Pusher interface that will push to either a v1 or v2 -// registry. The endpoint argument contains a Version field that determines -// whether a v1 or v2 pusher will be created. The other parameters are passed -// through to the underlying pusher implementation for use during the actual -// push operation. -func NewPusher(ref reference.Named, endpoint registry.APIEndpoint, repoInfo *registry.RepositoryInfo, imagePushConfig *ImagePushConfig) (Pusher, error) { - switch endpoint.Version { - case registry.APIVersion2: - return &v2Pusher{ - v2MetadataService: metadata.NewV2MetadataService(imagePushConfig.MetadataStore), - ref: ref, - endpoint: endpoint, - repoInfo: repoInfo, - config: imagePushConfig, - }, nil - case registry.APIVersion1: - return &v1Pusher{ - v1IDService: metadata.NewV1IDService(imagePushConfig.MetadataStore), - ref: ref, - endpoint: endpoint, - repoInfo: repoInfo, - config: imagePushConfig, - }, nil - } - return nil, fmt.Errorf("unknown version %d for registry %s", endpoint.Version, endpoint.URL) -} - -// Push initiates a push operation on ref. -// ref is the specific variant of the image to be pushed. -// If no tag is provided, all tags will be pushed. -func Push(ctx context.Context, ref reference.Named, imagePushConfig *ImagePushConfig) error { - // FIXME: Allow to interrupt current push when new push of same image is done. - - // Resolve the Repository name from fqn to RepositoryInfo - repoInfo, err := imagePushConfig.RegistryService.ResolveRepository(ref) - if err != nil { - return err - } - - endpoints, err := imagePushConfig.RegistryService.LookupPushEndpoints(repoInfo.Hostname()) - if err != nil { - return err - } - - progress.Messagef(imagePushConfig.ProgressOutput, "", "The push refers to a repository [%s]", repoInfo.FullName()) - - associations := imagePushConfig.ReferenceStore.ReferencesByName(repoInfo) - if len(associations) == 0 { - return fmt.Errorf("An image does not exist locally with the tag: %s", repoInfo.Name()) - } - - var ( - lastErr error - - // confirmedV2 is set to true if a push attempt managed to - // confirm that it was talking to a v2 registry. This will - // prevent fallback to the v1 protocol. - confirmedV2 bool - - // confirmedTLSRegistries is a map indicating which registries - // are known to be using TLS. There should never be a plaintext - // retry for any of these. - confirmedTLSRegistries = make(map[string]struct{}) - ) - - for _, endpoint := range endpoints { - if imagePushConfig.RequireSchema2 && endpoint.Version == registry.APIVersion1 { - continue - } - if confirmedV2 && endpoint.Version == registry.APIVersion1 { - logrus.Debugf("Skipping v1 endpoint %s because v2 registry was detected", endpoint.URL) - continue - } - - if endpoint.URL.Scheme != "https" { - if _, confirmedTLS := confirmedTLSRegistries[endpoint.URL.Host]; confirmedTLS { - logrus.Debugf("Skipping non-TLS endpoint %s for host/port that appears to use TLS", endpoint.URL) - continue - } - } - - logrus.Debugf("Trying to push %s to %s %s", repoInfo.FullName(), endpoint.URL, endpoint.Version) - - pusher, err := NewPusher(ref, endpoint, repoInfo, imagePushConfig) - if err != nil { - lastErr = err - continue - } - if err := pusher.Push(ctx); err != nil { - // Was this push cancelled? If so, don't try to fall - // back. - select { - case <-ctx.Done(): - default: - if fallbackErr, ok := err.(fallbackError); ok { - confirmedV2 = confirmedV2 || fallbackErr.confirmedV2 - if fallbackErr.transportOK && endpoint.URL.Scheme == "https" { - confirmedTLSRegistries[endpoint.URL.Host] = struct{}{} - } - err = fallbackErr.err - lastErr = err - logrus.Errorf("Attempting next endpoint for push after error: %v", err) - continue - } - } - - logrus.Errorf("Not continuing with push after error: %v", err) - return err - } - - imagePushConfig.ImageEventLogger(ref.String(), repoInfo.Name(), "push") - return nil - } - - if lastErr == nil { - lastErr = fmt.Errorf("no endpoints found for %s", repoInfo.FullName()) - } - return lastErr -} - -// compress returns an io.ReadCloser which will supply a compressed version of -// the provided Reader. The caller must close the ReadCloser after reading the -// compressed data. -// -// Note that this function returns a reader instead of taking a writer as an -// argument so that it can be used with httpBlobWriter's ReadFrom method. -// Using httpBlobWriter's Write method would send a PATCH request for every -// Write call. -// -// The second return value is a channel that gets closed when the goroutine -// is finished. This allows the caller to make sure the goroutine finishes -// before it releases any resources connected with the reader that was -// passed in. -func compress(in io.Reader) (io.ReadCloser, chan struct{}) { - compressionDone := make(chan struct{}) - - pipeReader, pipeWriter := io.Pipe() - // Use a bufio.Writer to avoid excessive chunking in HTTP request. - bufWriter := bufio.NewWriterSize(pipeWriter, compressionBufSize) - compressor := gzip.NewWriter(bufWriter) - - go func() { - _, err := io.Copy(compressor, in) - if err == nil { - err = compressor.Close() - } - if err == nil { - err = bufWriter.Flush() - } - if err != nil { - pipeWriter.CloseWithError(err) - } else { - pipeWriter.Close() - } - close(compressionDone) - }() - - return pipeReader, compressionDone -} diff --git a/vendor/github.com/docker/docker/distribution/push_v1.go b/vendor/github.com/docker/docker/distribution/push_v1.go deleted file mode 100644 index 257ac18..0000000 --- a/vendor/github.com/docker/docker/distribution/push_v1.go +++ /dev/null @@ -1,463 +0,0 @@ -package distribution - -import ( - "fmt" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/distribution/registry/client/transport" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/image" - "github.com/docker/docker/image/v1" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "golang.org/x/net/context" -) - -type v1Pusher struct { - v1IDService *metadata.V1IDService - endpoint registry.APIEndpoint - ref reference.Named - repoInfo *registry.RepositoryInfo - config *ImagePushConfig - session *registry.Session -} - -func (p *v1Pusher) Push(ctx context.Context) error { - tlsConfig, err := p.config.RegistryService.TLSConfig(p.repoInfo.Index.Name) - if err != nil { - return err - } - // Adds Docker-specific headers as well as user-specified headers (metaHeaders) - tr := transport.NewTransport( - // TODO(tiborvass): was NoTimeout - registry.NewTransport(tlsConfig), - registry.DockerHeaders(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders)..., - ) - client := registry.HTTPClient(tr) - v1Endpoint, err := p.endpoint.ToV1Endpoint(dockerversion.DockerUserAgent(ctx), p.config.MetaHeaders) - if err != nil { - logrus.Debugf("Could not get v1 endpoint: %v", err) - return fallbackError{err: err} - } - p.session, err = registry.NewSession(client, p.config.AuthConfig, v1Endpoint) - if err != nil { - // TODO(dmcgowan): Check if should fallback - return fallbackError{err: err} - } - if err := p.pushRepository(ctx); err != nil { - // TODO(dmcgowan): Check if should fallback - return err - } - return nil -} - -// v1Image exposes the configuration, filesystem layer ID, and a v1 ID for an -// image being pushed to a v1 registry. -type v1Image interface { - Config() []byte - Layer() layer.Layer - V1ID() string -} - -type v1ImageCommon struct { - layer layer.Layer - config []byte - v1ID string -} - -func (common *v1ImageCommon) Config() []byte { - return common.config -} - -func (common *v1ImageCommon) V1ID() string { - return common.v1ID -} - -func (common *v1ImageCommon) Layer() layer.Layer { - return common.layer -} - -// v1TopImage defines a runnable (top layer) image being pushed to a v1 -// registry. -type v1TopImage struct { - v1ImageCommon - imageID image.ID -} - -func newV1TopImage(imageID image.ID, img *image.Image, l layer.Layer, parent *v1DependencyImage) (*v1TopImage, error) { - v1ID := imageID.Digest().Hex() - parentV1ID := "" - if parent != nil { - parentV1ID = parent.V1ID() - } - - config, err := v1.MakeV1ConfigFromConfig(img, v1ID, parentV1ID, false) - if err != nil { - return nil, err - } - - return &v1TopImage{ - v1ImageCommon: v1ImageCommon{ - v1ID: v1ID, - config: config, - layer: l, - }, - imageID: imageID, - }, nil -} - -// v1DependencyImage defines a dependency layer being pushed to a v1 registry. -type v1DependencyImage struct { - v1ImageCommon -} - -func newV1DependencyImage(l layer.Layer, parent *v1DependencyImage) (*v1DependencyImage, error) { - v1ID := digest.Digest(l.ChainID()).Hex() - - config := "" - if parent != nil { - config = fmt.Sprintf(`{"id":"%s","parent":"%s"}`, v1ID, parent.V1ID()) - } else { - config = fmt.Sprintf(`{"id":"%s"}`, v1ID) - } - return &v1DependencyImage{ - v1ImageCommon: v1ImageCommon{ - v1ID: v1ID, - config: []byte(config), - layer: l, - }, - }, nil -} - -// Retrieve the all the images to be uploaded in the correct order -func (p *v1Pusher) getImageList() (imageList []v1Image, tagsByImage map[image.ID][]string, referencedLayers []PushLayer, err error) { - tagsByImage = make(map[image.ID][]string) - - // Ignore digest references - if _, isCanonical := p.ref.(reference.Canonical); isCanonical { - return - } - - tagged, isTagged := p.ref.(reference.NamedTagged) - if isTagged { - // Push a specific tag - var imgID image.ID - var dgst digest.Digest - dgst, err = p.config.ReferenceStore.Get(p.ref) - if err != nil { - return - } - imgID = image.IDFromDigest(dgst) - - imageList, err = p.imageListForTag(imgID, nil, &referencedLayers) - if err != nil { - return - } - - tagsByImage[imgID] = []string{tagged.Tag()} - - return - } - - imagesSeen := make(map[digest.Digest]struct{}) - dependenciesSeen := make(map[layer.ChainID]*v1DependencyImage) - - associations := p.config.ReferenceStore.ReferencesByName(p.ref) - for _, association := range associations { - if tagged, isTagged = association.Ref.(reference.NamedTagged); !isTagged { - // Ignore digest references. - continue - } - - imgID := image.IDFromDigest(association.ID) - tagsByImage[imgID] = append(tagsByImage[imgID], tagged.Tag()) - - if _, present := imagesSeen[association.ID]; present { - // Skip generating image list for already-seen image - continue - } - imagesSeen[association.ID] = struct{}{} - - imageListForThisTag, err := p.imageListForTag(imgID, dependenciesSeen, &referencedLayers) - if err != nil { - return nil, nil, nil, err - } - - // append to main image list - imageList = append(imageList, imageListForThisTag...) - } - if len(imageList) == 0 { - return nil, nil, nil, fmt.Errorf("No images found for the requested repository / tag") - } - logrus.Debugf("Image list: %v", imageList) - logrus.Debugf("Tags by image: %v", tagsByImage) - - return -} - -func (p *v1Pusher) imageListForTag(imgID image.ID, dependenciesSeen map[layer.ChainID]*v1DependencyImage, referencedLayers *[]PushLayer) (imageListForThisTag []v1Image, err error) { - ics, ok := p.config.ImageStore.(*imageConfigStore) - if !ok { - return nil, fmt.Errorf("only image store images supported for v1 push") - } - img, err := ics.Store.Get(imgID) - if err != nil { - return nil, err - } - - topLayerID := img.RootFS.ChainID() - - pl, err := p.config.LayerStore.Get(topLayerID) - *referencedLayers = append(*referencedLayers, pl) - if err != nil { - return nil, fmt.Errorf("failed to get top layer from image: %v", err) - } - - // V1 push is deprecated, only support existing layerstore layers - lsl, ok := pl.(*storeLayer) - if !ok { - return nil, fmt.Errorf("only layer store layers supported for v1 push") - } - l := lsl.Layer - - dependencyImages, parent, err := generateDependencyImages(l.Parent(), dependenciesSeen) - if err != nil { - return nil, err - } - - topImage, err := newV1TopImage(imgID, img, l, parent) - if err != nil { - return nil, err - } - - imageListForThisTag = append(dependencyImages, topImage) - - return -} - -func generateDependencyImages(l layer.Layer, dependenciesSeen map[layer.ChainID]*v1DependencyImage) (imageListForThisTag []v1Image, parent *v1DependencyImage, err error) { - if l == nil { - return nil, nil, nil - } - - imageListForThisTag, parent, err = generateDependencyImages(l.Parent(), dependenciesSeen) - - if dependenciesSeen != nil { - if dependencyImage, present := dependenciesSeen[l.ChainID()]; present { - // This layer is already on the list, we can ignore it - // and all its parents. - return imageListForThisTag, dependencyImage, nil - } - } - - dependencyImage, err := newV1DependencyImage(l, parent) - if err != nil { - return nil, nil, err - } - imageListForThisTag = append(imageListForThisTag, dependencyImage) - - if dependenciesSeen != nil { - dependenciesSeen[l.ChainID()] = dependencyImage - } - - return imageListForThisTag, dependencyImage, nil -} - -// createImageIndex returns an index of an image's layer IDs and tags. -func createImageIndex(images []v1Image, tags map[image.ID][]string) []*registry.ImgData { - var imageIndex []*registry.ImgData - for _, img := range images { - v1ID := img.V1ID() - - if topImage, isTopImage := img.(*v1TopImage); isTopImage { - if tags, hasTags := tags[topImage.imageID]; hasTags { - // If an image has tags you must add an entry in the image index - // for each tag - for _, tag := range tags { - imageIndex = append(imageIndex, ®istry.ImgData{ - ID: v1ID, - Tag: tag, - }) - } - continue - } - } - - // If the image does not have a tag it still needs to be sent to the - // registry with an empty tag so that it is associated with the repository - imageIndex = append(imageIndex, ®istry.ImgData{ - ID: v1ID, - Tag: "", - }) - } - return imageIndex -} - -// lookupImageOnEndpoint checks the specified endpoint to see if an image exists -// and if it is absent then it sends the image id to the channel to be pushed. -func (p *v1Pusher) lookupImageOnEndpoint(wg *sync.WaitGroup, endpoint string, images chan v1Image, imagesToPush chan string) { - defer wg.Done() - for image := range images { - v1ID := image.V1ID() - truncID := stringid.TruncateID(image.Layer().DiffID().String()) - if err := p.session.LookupRemoteImage(v1ID, endpoint); err != nil { - logrus.Errorf("Error in LookupRemoteImage: %s", err) - imagesToPush <- v1ID - progress.Update(p.config.ProgressOutput, truncID, "Waiting") - } else { - progress.Update(p.config.ProgressOutput, truncID, "Already exists") - } - } -} - -func (p *v1Pusher) pushImageToEndpoint(ctx context.Context, endpoint string, imageList []v1Image, tags map[image.ID][]string, repo *registry.RepositoryData) error { - workerCount := len(imageList) - // start a maximum of 5 workers to check if images exist on the specified endpoint. - if workerCount > 5 { - workerCount = 5 - } - var ( - wg = &sync.WaitGroup{} - imageData = make(chan v1Image, workerCount*2) - imagesToPush = make(chan string, workerCount*2) - pushes = make(chan map[string]struct{}, 1) - ) - for i := 0; i < workerCount; i++ { - wg.Add(1) - go p.lookupImageOnEndpoint(wg, endpoint, imageData, imagesToPush) - } - // start a go routine that consumes the images to push - go func() { - shouldPush := make(map[string]struct{}) - for id := range imagesToPush { - shouldPush[id] = struct{}{} - } - pushes <- shouldPush - }() - for _, v1Image := range imageList { - imageData <- v1Image - } - // close the channel to notify the workers that there will be no more images to check. - close(imageData) - wg.Wait() - close(imagesToPush) - // wait for all the images that require pushes to be collected into a consumable map. - shouldPush := <-pushes - // finish by pushing any images and tags to the endpoint. The order that the images are pushed - // is very important that is why we are still iterating over the ordered list of imageIDs. - for _, img := range imageList { - v1ID := img.V1ID() - if _, push := shouldPush[v1ID]; push { - if _, err := p.pushImage(ctx, img, endpoint); err != nil { - // FIXME: Continue on error? - return err - } - } - if topImage, isTopImage := img.(*v1TopImage); isTopImage { - for _, tag := range tags[topImage.imageID] { - progress.Messagef(p.config.ProgressOutput, "", "Pushing tag for rev [%s] on {%s}", stringid.TruncateID(v1ID), endpoint+"repositories/"+p.repoInfo.RemoteName()+"/tags/"+tag) - if err := p.session.PushRegistryTag(p.repoInfo, v1ID, tag, endpoint); err != nil { - return err - } - } - } - } - return nil -} - -// pushRepository pushes layers that do not already exist on the registry. -func (p *v1Pusher) pushRepository(ctx context.Context) error { - imgList, tags, referencedLayers, err := p.getImageList() - defer func() { - for _, l := range referencedLayers { - l.Release() - } - }() - if err != nil { - return err - } - - imageIndex := createImageIndex(imgList, tags) - for _, data := range imageIndex { - logrus.Debugf("Pushing ID: %s with Tag: %s", data.ID, data.Tag) - } - - // Register all the images in a repository with the registry - // If an image is not in this list it will not be associated with the repository - repoData, err := p.session.PushImageJSONIndex(p.repoInfo, imageIndex, false, nil) - if err != nil { - return err - } - // push the repository to each of the endpoints only if it does not exist. - for _, endpoint := range repoData.Endpoints { - if err := p.pushImageToEndpoint(ctx, endpoint, imgList, tags, repoData); err != nil { - return err - } - } - _, err = p.session.PushImageJSONIndex(p.repoInfo, imageIndex, true, repoData.Endpoints) - return err -} - -func (p *v1Pusher) pushImage(ctx context.Context, v1Image v1Image, ep string) (checksum string, err error) { - l := v1Image.Layer() - v1ID := v1Image.V1ID() - truncID := stringid.TruncateID(l.DiffID().String()) - - jsonRaw := v1Image.Config() - progress.Update(p.config.ProgressOutput, truncID, "Pushing") - - // General rule is to use ID for graph accesses and compatibilityID for - // calls to session.registry() - imgData := ®istry.ImgData{ - ID: v1ID, - } - - // Send the json - if err := p.session.PushImageJSONRegistry(imgData, jsonRaw, ep); err != nil { - if err == registry.ErrAlreadyExists { - progress.Update(p.config.ProgressOutput, truncID, "Image already pushed, skipping") - return "", nil - } - return "", err - } - - arch, err := l.TarStream() - if err != nil { - return "", err - } - defer arch.Close() - - // don't care if this fails; best effort - size, _ := l.DiffSize() - - // Send the layer - logrus.Debugf("rendered layer for %s of [%d] size", v1ID, size) - - reader := progress.NewProgressReader(ioutils.NewCancelReadCloser(ctx, arch), p.config.ProgressOutput, size, truncID, "Pushing") - defer reader.Close() - - checksum, checksumPayload, err := p.session.PushImageLayerRegistry(v1ID, reader, ep, jsonRaw) - if err != nil { - return "", err - } - imgData.Checksum = checksum - imgData.ChecksumPayload = checksumPayload - // Send the checksum - if err := p.session.PushImageChecksumRegistry(imgData, ep); err != nil { - return "", err - } - - if err := p.v1IDService.Set(v1ID, p.repoInfo.Index.Name, l.DiffID()); err != nil { - logrus.Warnf("Could not set v1 ID mapping: %v", err) - } - - progress.Update(p.config.ProgressOutput, truncID, "Image successfully pushed") - return imgData.Checksum, nil -} diff --git a/vendor/github.com/docker/docker/distribution/push_v2.go b/vendor/github.com/docker/docker/distribution/push_v2.go deleted file mode 100644 index 1f8c822..0000000 --- a/vendor/github.com/docker/docker/distribution/push_v2.go +++ /dev/null @@ -1,697 +0,0 @@ -package distribution - -import ( - "errors" - "fmt" - "io" - "runtime" - "sort" - "strings" - "sync" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/distribution/manifest/schema1" - "github.com/docker/distribution/manifest/schema2" - distreference "github.com/docker/distribution/reference" - "github.com/docker/distribution/registry/client" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/distribution/xfer" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" -) - -const ( - smallLayerMaximumSize = 100 * (1 << 10) // 100KB - middleLayerMaximumSize = 10 * (1 << 20) // 10MB -) - -// PushResult contains the tag, manifest digest, and manifest size from the -// push. It's used to signal this information to the trust code in the client -// so it can sign the manifest if necessary. -type PushResult struct { - Tag string - Digest digest.Digest - Size int -} - -type v2Pusher struct { - v2MetadataService metadata.V2MetadataService - ref reference.Named - endpoint registry.APIEndpoint - repoInfo *registry.RepositoryInfo - config *ImagePushConfig - repo distribution.Repository - - // pushState is state built by the Upload functions. - pushState pushState -} - -type pushState struct { - sync.Mutex - // remoteLayers is the set of layers known to exist on the remote side. - // This avoids redundant queries when pushing multiple tags that - // involve the same layers. It is also used to fill in digest and size - // information when building the manifest. - remoteLayers map[layer.DiffID]distribution.Descriptor - // confirmedV2 is set to true if we confirm we're talking to a v2 - // registry. This is used to limit fallbacks to the v1 protocol. - confirmedV2 bool -} - -func (p *v2Pusher) Push(ctx context.Context) (err error) { - p.pushState.remoteLayers = make(map[layer.DiffID]distribution.Descriptor) - - p.repo, p.pushState.confirmedV2, err = NewV2Repository(ctx, p.repoInfo, p.endpoint, p.config.MetaHeaders, p.config.AuthConfig, "push", "pull") - if err != nil { - logrus.Debugf("Error getting v2 registry: %v", err) - return err - } - - if err = p.pushV2Repository(ctx); err != nil { - if continueOnError(err) { - return fallbackError{ - err: err, - confirmedV2: p.pushState.confirmedV2, - transportOK: true, - } - } - } - return err -} - -func (p *v2Pusher) pushV2Repository(ctx context.Context) (err error) { - if namedTagged, isNamedTagged := p.ref.(reference.NamedTagged); isNamedTagged { - imageID, err := p.config.ReferenceStore.Get(p.ref) - if err != nil { - return fmt.Errorf("tag does not exist: %s", p.ref.String()) - } - - return p.pushV2Tag(ctx, namedTagged, imageID) - } - - if !reference.IsNameOnly(p.ref) { - return errors.New("cannot push a digest reference") - } - - // Pull all tags - pushed := 0 - for _, association := range p.config.ReferenceStore.ReferencesByName(p.ref) { - if namedTagged, isNamedTagged := association.Ref.(reference.NamedTagged); isNamedTagged { - pushed++ - if err := p.pushV2Tag(ctx, namedTagged, association.ID); err != nil { - return err - } - } - } - - if pushed == 0 { - return fmt.Errorf("no tags to push for %s", p.repoInfo.Name()) - } - - return nil -} - -func (p *v2Pusher) pushV2Tag(ctx context.Context, ref reference.NamedTagged, id digest.Digest) error { - logrus.Debugf("Pushing repository: %s", ref.String()) - - imgConfig, err := p.config.ImageStore.Get(id) - if err != nil { - return fmt.Errorf("could not find image from tag %s: %v", ref.String(), err) - } - - rootfs, err := p.config.ImageStore.RootFSFromConfig(imgConfig) - if err != nil { - return fmt.Errorf("unable to get rootfs for image %s: %s", ref.String(), err) - } - - l, err := p.config.LayerStore.Get(rootfs.ChainID()) - if err != nil { - return fmt.Errorf("failed to get top layer from image: %v", err) - } - defer l.Release() - - hmacKey, err := metadata.ComputeV2MetadataHMACKey(p.config.AuthConfig) - if err != nil { - return fmt.Errorf("failed to compute hmac key of auth config: %v", err) - } - - var descriptors []xfer.UploadDescriptor - - descriptorTemplate := v2PushDescriptor{ - v2MetadataService: p.v2MetadataService, - hmacKey: hmacKey, - repoInfo: p.repoInfo, - ref: p.ref, - repo: p.repo, - pushState: &p.pushState, - } - - // Loop bounds condition is to avoid pushing the base layer on Windows. - for i := 0; i < len(rootfs.DiffIDs); i++ { - descriptor := descriptorTemplate - descriptor.layer = l - descriptor.checkedDigests = make(map[digest.Digest]struct{}) - descriptors = append(descriptors, &descriptor) - - l = l.Parent() - } - - if err := p.config.UploadManager.Upload(ctx, descriptors, p.config.ProgressOutput); err != nil { - return err - } - - // Try schema2 first - builder := schema2.NewManifestBuilder(p.repo.Blobs(ctx), p.config.ConfigMediaType, imgConfig) - manifest, err := manifestFromBuilder(ctx, builder, descriptors) - if err != nil { - return err - } - - manSvc, err := p.repo.Manifests(ctx) - if err != nil { - return err - } - - putOptions := []distribution.ManifestServiceOption{distribution.WithTag(ref.Tag())} - if _, err = manSvc.Put(ctx, manifest, putOptions...); err != nil { - if runtime.GOOS == "windows" || p.config.TrustKey == nil || p.config.RequireSchema2 { - logrus.Warnf("failed to upload schema2 manifest: %v", err) - return err - } - - logrus.Warnf("failed to upload schema2 manifest: %v - falling back to schema1", err) - - manifestRef, err := distreference.WithTag(p.repo.Named(), ref.Tag()) - if err != nil { - return err - } - builder = schema1.NewConfigManifestBuilder(p.repo.Blobs(ctx), p.config.TrustKey, manifestRef, imgConfig) - manifest, err = manifestFromBuilder(ctx, builder, descriptors) - if err != nil { - return err - } - - if _, err = manSvc.Put(ctx, manifest, putOptions...); err != nil { - return err - } - } - - var canonicalManifest []byte - - switch v := manifest.(type) { - case *schema1.SignedManifest: - canonicalManifest = v.Canonical - case *schema2.DeserializedManifest: - _, canonicalManifest, err = v.Payload() - if err != nil { - return err - } - } - - manifestDigest := digest.FromBytes(canonicalManifest) - progress.Messagef(p.config.ProgressOutput, "", "%s: digest: %s size: %d", ref.Tag(), manifestDigest, len(canonicalManifest)) - - if err := addDigestReference(p.config.ReferenceStore, ref, manifestDigest, id); err != nil { - return err - } - - // Signal digest to the trust client so it can sign the - // push, if appropriate. - progress.Aux(p.config.ProgressOutput, PushResult{Tag: ref.Tag(), Digest: manifestDigest, Size: len(canonicalManifest)}) - - return nil -} - -func manifestFromBuilder(ctx context.Context, builder distribution.ManifestBuilder, descriptors []xfer.UploadDescriptor) (distribution.Manifest, error) { - // descriptors is in reverse order; iterate backwards to get references - // appended in the right order. - for i := len(descriptors) - 1; i >= 0; i-- { - if err := builder.AppendReference(descriptors[i].(*v2PushDescriptor)); err != nil { - return nil, err - } - } - - return builder.Build(ctx) -} - -type v2PushDescriptor struct { - layer PushLayer - v2MetadataService metadata.V2MetadataService - hmacKey []byte - repoInfo reference.Named - ref reference.Named - repo distribution.Repository - pushState *pushState - remoteDescriptor distribution.Descriptor - // a set of digests whose presence has been checked in a target repository - checkedDigests map[digest.Digest]struct{} -} - -func (pd *v2PushDescriptor) Key() string { - return "v2push:" + pd.ref.FullName() + " " + pd.layer.DiffID().String() -} - -func (pd *v2PushDescriptor) ID() string { - return stringid.TruncateID(pd.layer.DiffID().String()) -} - -func (pd *v2PushDescriptor) DiffID() layer.DiffID { - return pd.layer.DiffID() -} - -func (pd *v2PushDescriptor) Upload(ctx context.Context, progressOutput progress.Output) (distribution.Descriptor, error) { - if fs, ok := pd.layer.(distribution.Describable); ok { - if d := fs.Descriptor(); len(d.URLs) > 0 { - progress.Update(progressOutput, pd.ID(), "Skipped foreign layer") - return d, nil - } - } - - diffID := pd.DiffID() - - pd.pushState.Lock() - if descriptor, ok := pd.pushState.remoteLayers[diffID]; ok { - // it is already known that the push is not needed and - // therefore doing a stat is unnecessary - pd.pushState.Unlock() - progress.Update(progressOutput, pd.ID(), "Layer already exists") - return descriptor, nil - } - pd.pushState.Unlock() - - maxMountAttempts, maxExistenceChecks, checkOtherRepositories := getMaxMountAndExistenceCheckAttempts(pd.layer) - - // Do we have any metadata associated with this layer's DiffID? - v2Metadata, err := pd.v2MetadataService.GetMetadata(diffID) - if err == nil { - // check for blob existence in the target repository if we have a mapping with it - descriptor, exists, err := pd.layerAlreadyExists(ctx, progressOutput, diffID, false, 1, v2Metadata) - if exists || err != nil { - return descriptor, err - } - } - - // if digest was empty or not saved, or if blob does not exist on the remote repository, - // then push the blob. - bs := pd.repo.Blobs(ctx) - - var layerUpload distribution.BlobWriter - - // Attempt to find another repository in the same registry to mount the layer from to avoid an unnecessary upload - candidates := getRepositoryMountCandidates(pd.repoInfo, pd.hmacKey, maxMountAttempts, v2Metadata) - for _, mountCandidate := range candidates { - logrus.Debugf("attempting to mount layer %s (%s) from %s", diffID, mountCandidate.Digest, mountCandidate.SourceRepository) - createOpts := []distribution.BlobCreateOption{} - - if len(mountCandidate.SourceRepository) > 0 { - namedRef, err := reference.WithName(mountCandidate.SourceRepository) - if err != nil { - logrus.Errorf("failed to parse source repository reference %v: %v", namedRef.String(), err) - pd.v2MetadataService.Remove(mountCandidate) - continue - } - - // TODO (brianbland): We need to construct a reference where the Name is - // only the full remote name, so clean this up when distribution has a - // richer reference package - remoteRef, err := distreference.WithName(namedRef.RemoteName()) - if err != nil { - logrus.Errorf("failed to make remote reference out of %q: %v", namedRef.RemoteName(), namedRef.RemoteName()) - continue - } - - canonicalRef, err := distreference.WithDigest(distreference.TrimNamed(remoteRef), mountCandidate.Digest) - if err != nil { - logrus.Errorf("failed to make canonical reference: %v", err) - continue - } - - createOpts = append(createOpts, client.WithMountFrom(canonicalRef)) - } - - // send the layer - lu, err := bs.Create(ctx, createOpts...) - switch err := err.(type) { - case nil: - // noop - case distribution.ErrBlobMounted: - progress.Updatef(progressOutput, pd.ID(), "Mounted from %s", err.From.Name()) - - err.Descriptor.MediaType = schema2.MediaTypeLayer - - pd.pushState.Lock() - pd.pushState.confirmedV2 = true - pd.pushState.remoteLayers[diffID] = err.Descriptor - pd.pushState.Unlock() - - // Cache mapping from this layer's DiffID to the blobsum - if err := pd.v2MetadataService.TagAndAdd(diffID, pd.hmacKey, metadata.V2Metadata{ - Digest: err.Descriptor.Digest, - SourceRepository: pd.repoInfo.FullName(), - }); err != nil { - return distribution.Descriptor{}, xfer.DoNotRetry{Err: err} - } - return err.Descriptor, nil - default: - logrus.Infof("failed to mount layer %s (%s) from %s: %v", diffID, mountCandidate.Digest, mountCandidate.SourceRepository, err) - } - - if len(mountCandidate.SourceRepository) > 0 && - (metadata.CheckV2MetadataHMAC(&mountCandidate, pd.hmacKey) || - len(mountCandidate.HMAC) == 0) { - cause := "blob mount failure" - if err != nil { - cause = fmt.Sprintf("an error: %v", err.Error()) - } - logrus.Debugf("removing association between layer %s and %s due to %s", mountCandidate.Digest, mountCandidate.SourceRepository, cause) - pd.v2MetadataService.Remove(mountCandidate) - } - - if lu != nil { - // cancel previous upload - cancelLayerUpload(ctx, mountCandidate.Digest, layerUpload) - layerUpload = lu - } - } - - if maxExistenceChecks-len(pd.checkedDigests) > 0 { - // do additional layer existence checks with other known digests if any - descriptor, exists, err := pd.layerAlreadyExists(ctx, progressOutput, diffID, checkOtherRepositories, maxExistenceChecks-len(pd.checkedDigests), v2Metadata) - if exists || err != nil { - return descriptor, err - } - } - - logrus.Debugf("Pushing layer: %s", diffID) - if layerUpload == nil { - layerUpload, err = bs.Create(ctx) - if err != nil { - return distribution.Descriptor{}, retryOnError(err) - } - } - defer layerUpload.Close() - - // upload the blob - desc, err := pd.uploadUsingSession(ctx, progressOutput, diffID, layerUpload) - if err != nil { - return desc, err - } - - return desc, nil -} - -func (pd *v2PushDescriptor) SetRemoteDescriptor(descriptor distribution.Descriptor) { - pd.remoteDescriptor = descriptor -} - -func (pd *v2PushDescriptor) Descriptor() distribution.Descriptor { - return pd.remoteDescriptor -} - -func (pd *v2PushDescriptor) uploadUsingSession( - ctx context.Context, - progressOutput progress.Output, - diffID layer.DiffID, - layerUpload distribution.BlobWriter, -) (distribution.Descriptor, error) { - var reader io.ReadCloser - - contentReader, err := pd.layer.Open() - size, _ := pd.layer.Size() - - reader = progress.NewProgressReader(ioutils.NewCancelReadCloser(ctx, contentReader), progressOutput, size, pd.ID(), "Pushing") - - switch m := pd.layer.MediaType(); m { - case schema2.MediaTypeUncompressedLayer: - compressedReader, compressionDone := compress(reader) - defer func(closer io.Closer) { - closer.Close() - <-compressionDone - }(reader) - reader = compressedReader - case schema2.MediaTypeLayer: - default: - reader.Close() - return distribution.Descriptor{}, fmt.Errorf("unsupported layer media type %s", m) - } - - digester := digest.Canonical.New() - tee := io.TeeReader(reader, digester.Hash()) - - nn, err := layerUpload.ReadFrom(tee) - reader.Close() - if err != nil { - return distribution.Descriptor{}, retryOnError(err) - } - - pushDigest := digester.Digest() - if _, err := layerUpload.Commit(ctx, distribution.Descriptor{Digest: pushDigest}); err != nil { - return distribution.Descriptor{}, retryOnError(err) - } - - logrus.Debugf("uploaded layer %s (%s), %d bytes", diffID, pushDigest, nn) - progress.Update(progressOutput, pd.ID(), "Pushed") - - // Cache mapping from this layer's DiffID to the blobsum - if err := pd.v2MetadataService.TagAndAdd(diffID, pd.hmacKey, metadata.V2Metadata{ - Digest: pushDigest, - SourceRepository: pd.repoInfo.FullName(), - }); err != nil { - return distribution.Descriptor{}, xfer.DoNotRetry{Err: err} - } - - desc := distribution.Descriptor{ - Digest: pushDigest, - MediaType: schema2.MediaTypeLayer, - Size: nn, - } - - pd.pushState.Lock() - // If Commit succeeded, that's an indication that the remote registry speaks the v2 protocol. - pd.pushState.confirmedV2 = true - pd.pushState.remoteLayers[diffID] = desc - pd.pushState.Unlock() - - return desc, nil -} - -// layerAlreadyExists checks if the registry already knows about any of the metadata passed in the "metadata" -// slice. If it finds one that the registry knows about, it returns the known digest and "true". If -// "checkOtherRepositories" is true, stat will be performed also with digests mapped to any other repository -// (not just the target one). -func (pd *v2PushDescriptor) layerAlreadyExists( - ctx context.Context, - progressOutput progress.Output, - diffID layer.DiffID, - checkOtherRepositories bool, - maxExistenceCheckAttempts int, - v2Metadata []metadata.V2Metadata, -) (desc distribution.Descriptor, exists bool, err error) { - // filter the metadata - candidates := []metadata.V2Metadata{} - for _, meta := range v2Metadata { - if len(meta.SourceRepository) > 0 && !checkOtherRepositories && meta.SourceRepository != pd.repoInfo.FullName() { - continue - } - candidates = append(candidates, meta) - } - // sort the candidates by similarity - sortV2MetadataByLikenessAndAge(pd.repoInfo, pd.hmacKey, candidates) - - digestToMetadata := make(map[digest.Digest]*metadata.V2Metadata) - // an array of unique blob digests ordered from the best mount candidates to worst - layerDigests := []digest.Digest{} - for i := 0; i < len(candidates); i++ { - if len(layerDigests) >= maxExistenceCheckAttempts { - break - } - meta := &candidates[i] - if _, exists := digestToMetadata[meta.Digest]; exists { - // keep reference just to the first mapping (the best mount candidate) - continue - } - if _, exists := pd.checkedDigests[meta.Digest]; exists { - // existence of this digest has already been tested - continue - } - digestToMetadata[meta.Digest] = meta - layerDigests = append(layerDigests, meta.Digest) - } - -attempts: - for _, dgst := range layerDigests { - meta := digestToMetadata[dgst] - logrus.Debugf("Checking for presence of layer %s (%s) in %s", diffID, dgst, pd.repoInfo.FullName()) - desc, err = pd.repo.Blobs(ctx).Stat(ctx, dgst) - pd.checkedDigests[meta.Digest] = struct{}{} - switch err { - case nil: - if m, ok := digestToMetadata[desc.Digest]; !ok || m.SourceRepository != pd.repoInfo.FullName() || !metadata.CheckV2MetadataHMAC(m, pd.hmacKey) { - // cache mapping from this layer's DiffID to the blobsum - if err := pd.v2MetadataService.TagAndAdd(diffID, pd.hmacKey, metadata.V2Metadata{ - Digest: desc.Digest, - SourceRepository: pd.repoInfo.FullName(), - }); err != nil { - return distribution.Descriptor{}, false, xfer.DoNotRetry{Err: err} - } - } - desc.MediaType = schema2.MediaTypeLayer - exists = true - break attempts - case distribution.ErrBlobUnknown: - if meta.SourceRepository == pd.repoInfo.FullName() { - // remove the mapping to the target repository - pd.v2MetadataService.Remove(*meta) - } - default: - logrus.WithError(err).Debugf("Failed to check for presence of layer %s (%s) in %s", diffID, dgst, pd.repoInfo.FullName()) - } - } - - if exists { - progress.Update(progressOutput, pd.ID(), "Layer already exists") - pd.pushState.Lock() - pd.pushState.remoteLayers[diffID] = desc - pd.pushState.Unlock() - } - - return desc, exists, nil -} - -// getMaxMountAndExistenceCheckAttempts returns a maximum number of cross repository mount attempts from -// source repositories of target registry, maximum number of layer existence checks performed on the target -// repository and whether the check shall be done also with digests mapped to different repositories. The -// decision is based on layer size. The smaller the layer, the fewer attempts shall be made because the cost -// of upload does not outweigh a latency. -func getMaxMountAndExistenceCheckAttempts(layer PushLayer) (maxMountAttempts, maxExistenceCheckAttempts int, checkOtherRepositories bool) { - size, err := layer.Size() - switch { - // big blob - case size > middleLayerMaximumSize: - // 1st attempt to mount the blob few times - // 2nd few existence checks with digests associated to any repository - // then fallback to upload - return 4, 3, true - - // middle sized blobs; if we could not get the size, assume we deal with middle sized blob - case size > smallLayerMaximumSize, err != nil: - // 1st attempt to mount blobs of average size few times - // 2nd try at most 1 existence check if there's an existing mapping to the target repository - // then fallback to upload - return 3, 1, false - - // small blobs, do a minimum number of checks - default: - return 1, 1, false - } -} - -// getRepositoryMountCandidates returns an array of v2 metadata items belonging to the given registry. The -// array is sorted from youngest to oldest. If requireReigstryMatch is true, the resulting array will contain -// only metadata entries having registry part of SourceRepository matching the part of repoInfo. -func getRepositoryMountCandidates( - repoInfo reference.Named, - hmacKey []byte, - max int, - v2Metadata []metadata.V2Metadata, -) []metadata.V2Metadata { - candidates := []metadata.V2Metadata{} - for _, meta := range v2Metadata { - sourceRepo, err := reference.ParseNamed(meta.SourceRepository) - if err != nil || repoInfo.Hostname() != sourceRepo.Hostname() { - continue - } - // target repository is not a viable candidate - if meta.SourceRepository == repoInfo.FullName() { - continue - } - candidates = append(candidates, meta) - } - - sortV2MetadataByLikenessAndAge(repoInfo, hmacKey, candidates) - if max >= 0 && len(candidates) > max { - // select the youngest metadata - candidates = candidates[:max] - } - - return candidates -} - -// byLikeness is a sorting container for v2 metadata candidates for cross repository mount. The -// candidate "a" is preferred over "b": -// -// 1. if it was hashed using the same AuthConfig as the one used to authenticate to target repository and the -// "b" was not -// 2. if a number of its repository path components exactly matching path components of target repository is higher -type byLikeness struct { - arr []metadata.V2Metadata - hmacKey []byte - pathComponents []string -} - -func (bla byLikeness) Less(i, j int) bool { - aMacMatch := metadata.CheckV2MetadataHMAC(&bla.arr[i], bla.hmacKey) - bMacMatch := metadata.CheckV2MetadataHMAC(&bla.arr[j], bla.hmacKey) - if aMacMatch != bMacMatch { - return aMacMatch - } - aMatch := numOfMatchingPathComponents(bla.arr[i].SourceRepository, bla.pathComponents) - bMatch := numOfMatchingPathComponents(bla.arr[j].SourceRepository, bla.pathComponents) - return aMatch > bMatch -} -func (bla byLikeness) Swap(i, j int) { - bla.arr[i], bla.arr[j] = bla.arr[j], bla.arr[i] -} -func (bla byLikeness) Len() int { return len(bla.arr) } - -func sortV2MetadataByLikenessAndAge(repoInfo reference.Named, hmacKey []byte, marr []metadata.V2Metadata) { - // reverse the metadata array to shift the newest entries to the beginning - for i := 0; i < len(marr)/2; i++ { - marr[i], marr[len(marr)-i-1] = marr[len(marr)-i-1], marr[i] - } - // keep equal entries ordered from the youngest to the oldest - sort.Stable(byLikeness{ - arr: marr, - hmacKey: hmacKey, - pathComponents: getPathComponents(repoInfo.FullName()), - }) -} - -// numOfMatchingPathComponents returns a number of path components in "pth" that exactly match "matchComponents". -func numOfMatchingPathComponents(pth string, matchComponents []string) int { - pthComponents := getPathComponents(pth) - i := 0 - for ; i < len(pthComponents) && i < len(matchComponents); i++ { - if matchComponents[i] != pthComponents[i] { - return i - } - } - return i -} - -func getPathComponents(path string) []string { - // make sure to add docker.io/ prefix to the path - named, err := reference.ParseNamed(path) - if err == nil { - path = named.FullName() - } - return strings.Split(path, "/") -} - -func cancelLayerUpload(ctx context.Context, dgst digest.Digest, layerUpload distribution.BlobWriter) { - if layerUpload != nil { - logrus.Debugf("cancelling upload of blob %s", dgst) - err := layerUpload.Cancel(ctx) - if err != nil { - logrus.Warnf("failed to cancel upload: %v", err) - } - } -} diff --git a/vendor/github.com/docker/docker/distribution/push_v2_test.go b/vendor/github.com/docker/docker/distribution/push_v2_test.go deleted file mode 100644 index 6a5216b..0000000 --- a/vendor/github.com/docker/docker/distribution/push_v2_test.go +++ /dev/null @@ -1,579 +0,0 @@ -package distribution - -import ( - "net/http" - "reflect" - "testing" - - "github.com/docker/distribution" - "github.com/docker/distribution/context" - "github.com/docker/distribution/digest" - "github.com/docker/distribution/manifest/schema2" - distreference "github.com/docker/distribution/reference" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/reference" -) - -func TestGetRepositoryMountCandidates(t *testing.T) { - for _, tc := range []struct { - name string - hmacKey string - targetRepo string - maxCandidates int - metadata []metadata.V2Metadata - candidates []metadata.V2Metadata - }{ - { - name: "empty metadata", - targetRepo: "busybox", - maxCandidates: -1, - metadata: []metadata.V2Metadata{}, - candidates: []metadata.V2Metadata{}, - }, - { - name: "one item not matching", - targetRepo: "busybox", - maxCandidates: -1, - metadata: []metadata.V2Metadata{taggedMetadata("key", "dgst", "127.0.0.1/repo")}, - candidates: []metadata.V2Metadata{}, - }, - { - name: "one item matching", - targetRepo: "busybox", - maxCandidates: -1, - metadata: []metadata.V2Metadata{taggedMetadata("hash", "1", "hello-world")}, - candidates: []metadata.V2Metadata{taggedMetadata("hash", "1", "hello-world")}, - }, - { - name: "allow missing SourceRepository", - targetRepo: "busybox", - maxCandidates: -1, - metadata: []metadata.V2Metadata{ - {Digest: digest.Digest("1")}, - {Digest: digest.Digest("3")}, - {Digest: digest.Digest("2")}, - }, - candidates: []metadata.V2Metadata{}, - }, - { - name: "handle docker.io", - targetRepo: "user/app", - maxCandidates: -1, - metadata: []metadata.V2Metadata{ - {Digest: digest.Digest("1"), SourceRepository: "docker.io/user/foo"}, - {Digest: digest.Digest("3"), SourceRepository: "user/bar"}, - {Digest: digest.Digest("2"), SourceRepository: "app"}, - }, - candidates: []metadata.V2Metadata{ - {Digest: digest.Digest("3"), SourceRepository: "user/bar"}, - {Digest: digest.Digest("1"), SourceRepository: "docker.io/user/foo"}, - {Digest: digest.Digest("2"), SourceRepository: "app"}, - }, - }, - { - name: "sort more items", - hmacKey: "abcd", - targetRepo: "127.0.0.1/foo/bar", - maxCandidates: -1, - metadata: []metadata.V2Metadata{ - taggedMetadata("hash", "1", "hello-world"), - taggedMetadata("efgh", "2", "127.0.0.1/hello-world"), - taggedMetadata("abcd", "3", "busybox"), - taggedMetadata("hash", "4", "busybox"), - taggedMetadata("hash", "5", "127.0.0.1/foo"), - taggedMetadata("hash", "6", "127.0.0.1/bar"), - taggedMetadata("efgh", "7", "127.0.0.1/foo/bar"), - taggedMetadata("abcd", "8", "127.0.0.1/xyz"), - taggedMetadata("hash", "9", "127.0.0.1/foo/app"), - }, - candidates: []metadata.V2Metadata{ - // first by matching hash - taggedMetadata("abcd", "8", "127.0.0.1/xyz"), - // then by longest matching prefix - taggedMetadata("hash", "9", "127.0.0.1/foo/app"), - taggedMetadata("hash", "5", "127.0.0.1/foo"), - // sort the rest of the matching items in reversed order - taggedMetadata("hash", "6", "127.0.0.1/bar"), - taggedMetadata("efgh", "2", "127.0.0.1/hello-world"), - }, - }, - { - name: "limit max candidates", - hmacKey: "abcd", - targetRepo: "user/app", - maxCandidates: 3, - metadata: []metadata.V2Metadata{ - taggedMetadata("abcd", "1", "user/app1"), - taggedMetadata("abcd", "2", "user/app/base"), - taggedMetadata("hash", "3", "user/app"), - taggedMetadata("abcd", "4", "127.0.0.1/user/app"), - taggedMetadata("hash", "5", "user/foo"), - taggedMetadata("hash", "6", "app/bar"), - }, - candidates: []metadata.V2Metadata{ - // first by matching hash - taggedMetadata("abcd", "2", "user/app/base"), - taggedMetadata("abcd", "1", "user/app1"), - // then by longest matching prefix - taggedMetadata("hash", "3", "user/app"), - }, - }, - } { - repoInfo, err := reference.ParseNamed(tc.targetRepo) - if err != nil { - t.Fatalf("[%s] failed to parse reference name: %v", tc.name, err) - } - candidates := getRepositoryMountCandidates(repoInfo, []byte(tc.hmacKey), tc.maxCandidates, tc.metadata) - if len(candidates) != len(tc.candidates) { - t.Errorf("[%s] got unexpected number of candidates: %d != %d", tc.name, len(candidates), len(tc.candidates)) - } - for i := 0; i < len(candidates) && i < len(tc.candidates); i++ { - if !reflect.DeepEqual(candidates[i], tc.candidates[i]) { - t.Errorf("[%s] candidate %d does not match expected: %#+v != %#+v", tc.name, i, candidates[i], tc.candidates[i]) - } - } - for i := len(candidates); i < len(tc.candidates); i++ { - t.Errorf("[%s] missing expected candidate at position %d (%#+v)", tc.name, i, tc.candidates[i]) - } - for i := len(tc.candidates); i < len(candidates); i++ { - t.Errorf("[%s] got unexpected candidate at position %d (%#+v)", tc.name, i, candidates[i]) - } - } -} - -func TestLayerAlreadyExists(t *testing.T) { - for _, tc := range []struct { - name string - metadata []metadata.V2Metadata - targetRepo string - hmacKey string - maxExistenceChecks int - checkOtherRepositories bool - remoteBlobs map[digest.Digest]distribution.Descriptor - remoteErrors map[digest.Digest]error - expectedDescriptor distribution.Descriptor - expectedExists bool - expectedError error - expectedRequests []string - expectedAdditions []metadata.V2Metadata - expectedRemovals []metadata.V2Metadata - }{ - { - name: "empty metadata", - targetRepo: "busybox", - maxExistenceChecks: 3, - checkOtherRepositories: true, - }, - { - name: "single not existent metadata", - targetRepo: "busybox", - metadata: []metadata.V2Metadata{{Digest: digest.Digest("pear"), SourceRepository: "docker.io/library/busybox"}}, - maxExistenceChecks: 3, - expectedRequests: []string{"pear"}, - expectedRemovals: []metadata.V2Metadata{{Digest: digest.Digest("pear"), SourceRepository: "docker.io/library/busybox"}}, - }, - { - name: "access denied", - targetRepo: "busybox", - maxExistenceChecks: 1, - metadata: []metadata.V2Metadata{{Digest: digest.Digest("apple"), SourceRepository: "docker.io/library/busybox"}}, - remoteErrors: map[digest.Digest]error{digest.Digest("apple"): distribution.ErrAccessDenied}, - expectedError: nil, - expectedRequests: []string{"apple"}, - }, - { - name: "not matching reposies", - targetRepo: "busybox", - maxExistenceChecks: 3, - metadata: []metadata.V2Metadata{ - {Digest: digest.Digest("apple"), SourceRepository: "docker.io/library/hello-world"}, - {Digest: digest.Digest("orange"), SourceRepository: "docker.io/library/busybox/subapp"}, - {Digest: digest.Digest("pear"), SourceRepository: "docker.io/busybox"}, - {Digest: digest.Digest("plum"), SourceRepository: "busybox"}, - {Digest: digest.Digest("banana"), SourceRepository: "127.0.0.1/busybox"}, - }, - }, - { - name: "check other repositories", - targetRepo: "busybox", - maxExistenceChecks: 10, - checkOtherRepositories: true, - metadata: []metadata.V2Metadata{ - {Digest: digest.Digest("apple"), SourceRepository: "docker.io/library/hello-world"}, - {Digest: digest.Digest("orange"), SourceRepository: "docker.io/library/busybox/subapp"}, - {Digest: digest.Digest("pear"), SourceRepository: "docker.io/busybox"}, - {Digest: digest.Digest("plum"), SourceRepository: "busybox"}, - {Digest: digest.Digest("banana"), SourceRepository: "127.0.0.1/busybox"}, - }, - expectedRequests: []string{"plum", "pear", "apple", "orange", "banana"}, - }, - { - name: "find existing blob", - targetRepo: "busybox", - metadata: []metadata.V2Metadata{{Digest: digest.Digest("apple"), SourceRepository: "docker.io/library/busybox"}}, - maxExistenceChecks: 3, - remoteBlobs: map[digest.Digest]distribution.Descriptor{digest.Digest("apple"): {Digest: digest.Digest("apple")}}, - expectedDescriptor: distribution.Descriptor{Digest: digest.Digest("apple"), MediaType: schema2.MediaTypeLayer}, - expectedExists: true, - expectedRequests: []string{"apple"}, - }, - { - name: "find existing blob with different hmac", - targetRepo: "busybox", - metadata: []metadata.V2Metadata{{SourceRepository: "docker.io/library/busybox", Digest: digest.Digest("apple"), HMAC: "dummyhmac"}}, - maxExistenceChecks: 3, - remoteBlobs: map[digest.Digest]distribution.Descriptor{digest.Digest("apple"): {Digest: digest.Digest("apple")}}, - expectedDescriptor: distribution.Descriptor{Digest: digest.Digest("apple"), MediaType: schema2.MediaTypeLayer}, - expectedExists: true, - expectedRequests: []string{"apple"}, - expectedAdditions: []metadata.V2Metadata{{Digest: digest.Digest("apple"), SourceRepository: "docker.io/library/busybox"}}, - }, - { - name: "overwrite media types", - targetRepo: "busybox", - metadata: []metadata.V2Metadata{{Digest: digest.Digest("apple"), SourceRepository: "docker.io/library/busybox"}}, - hmacKey: "key", - maxExistenceChecks: 3, - remoteBlobs: map[digest.Digest]distribution.Descriptor{digest.Digest("apple"): {Digest: digest.Digest("apple"), MediaType: "custom-media-type"}}, - expectedDescriptor: distribution.Descriptor{Digest: digest.Digest("apple"), MediaType: schema2.MediaTypeLayer}, - expectedExists: true, - expectedRequests: []string{"apple"}, - expectedAdditions: []metadata.V2Metadata{taggedMetadata("key", "apple", "docker.io/library/busybox")}, - }, - { - name: "find existing blob among many", - targetRepo: "127.0.0.1/myapp", - hmacKey: "key", - metadata: []metadata.V2Metadata{ - taggedMetadata("someotherkey", "pear", "127.0.0.1/myapp"), - taggedMetadata("key", "apple", "127.0.0.1/myapp"), - taggedMetadata("", "plum", "127.0.0.1/myapp"), - }, - maxExistenceChecks: 3, - remoteBlobs: map[digest.Digest]distribution.Descriptor{digest.Digest("pear"): {Digest: digest.Digest("pear")}}, - expectedDescriptor: distribution.Descriptor{Digest: digest.Digest("pear"), MediaType: schema2.MediaTypeLayer}, - expectedExists: true, - expectedRequests: []string{"apple", "plum", "pear"}, - expectedAdditions: []metadata.V2Metadata{taggedMetadata("key", "pear", "127.0.0.1/myapp")}, - expectedRemovals: []metadata.V2Metadata{ - taggedMetadata("key", "apple", "127.0.0.1/myapp"), - {Digest: digest.Digest("plum"), SourceRepository: "127.0.0.1/myapp"}, - }, - }, - { - name: "reach maximum existence checks", - targetRepo: "user/app", - metadata: []metadata.V2Metadata{ - {Digest: digest.Digest("pear"), SourceRepository: "docker.io/user/app"}, - {Digest: digest.Digest("apple"), SourceRepository: "docker.io/user/app"}, - {Digest: digest.Digest("plum"), SourceRepository: "docker.io/user/app"}, - {Digest: digest.Digest("banana"), SourceRepository: "docker.io/user/app"}, - }, - maxExistenceChecks: 3, - remoteBlobs: map[digest.Digest]distribution.Descriptor{digest.Digest("pear"): {Digest: digest.Digest("pear")}}, - expectedExists: false, - expectedRequests: []string{"banana", "plum", "apple"}, - expectedRemovals: []metadata.V2Metadata{ - {Digest: digest.Digest("banana"), SourceRepository: "docker.io/user/app"}, - {Digest: digest.Digest("plum"), SourceRepository: "docker.io/user/app"}, - {Digest: digest.Digest("apple"), SourceRepository: "docker.io/user/app"}, - }, - }, - { - name: "zero allowed existence checks", - targetRepo: "user/app", - metadata: []metadata.V2Metadata{ - {Digest: digest.Digest("pear"), SourceRepository: "docker.io/user/app"}, - {Digest: digest.Digest("apple"), SourceRepository: "docker.io/user/app"}, - {Digest: digest.Digest("plum"), SourceRepository: "docker.io/user/app"}, - {Digest: digest.Digest("banana"), SourceRepository: "docker.io/user/app"}, - }, - maxExistenceChecks: 0, - remoteBlobs: map[digest.Digest]distribution.Descriptor{digest.Digest("pear"): {Digest: digest.Digest("pear")}}, - }, - { - name: "stat single digest just once", - targetRepo: "busybox", - metadata: []metadata.V2Metadata{ - taggedMetadata("key1", "pear", "docker.io/library/busybox"), - taggedMetadata("key2", "apple", "docker.io/library/busybox"), - taggedMetadata("key3", "apple", "docker.io/library/busybox"), - }, - maxExistenceChecks: 3, - remoteBlobs: map[digest.Digest]distribution.Descriptor{digest.Digest("pear"): {Digest: digest.Digest("pear")}}, - expectedDescriptor: distribution.Descriptor{Digest: digest.Digest("pear"), MediaType: schema2.MediaTypeLayer}, - expectedExists: true, - expectedRequests: []string{"apple", "pear"}, - expectedAdditions: []metadata.V2Metadata{{Digest: digest.Digest("pear"), SourceRepository: "docker.io/library/busybox"}}, - expectedRemovals: []metadata.V2Metadata{taggedMetadata("key3", "apple", "docker.io/library/busybox")}, - }, - { - name: "don't stop on first error", - targetRepo: "user/app", - hmacKey: "key", - metadata: []metadata.V2Metadata{ - taggedMetadata("key", "banana", "docker.io/user/app"), - taggedMetadata("key", "orange", "docker.io/user/app"), - taggedMetadata("key", "plum", "docker.io/user/app"), - }, - maxExistenceChecks: 3, - remoteErrors: map[digest.Digest]error{"orange": distribution.ErrAccessDenied}, - remoteBlobs: map[digest.Digest]distribution.Descriptor{digest.Digest("apple"): {}}, - expectedError: nil, - expectedRequests: []string{"plum", "orange", "banana"}, - expectedRemovals: []metadata.V2Metadata{ - taggedMetadata("key", "plum", "docker.io/user/app"), - taggedMetadata("key", "banana", "docker.io/user/app"), - }, - }, - { - name: "remove outdated metadata", - targetRepo: "docker.io/user/app", - metadata: []metadata.V2Metadata{ - {Digest: digest.Digest("plum"), SourceRepository: "docker.io/library/busybox"}, - {Digest: digest.Digest("orange"), SourceRepository: "docker.io/user/app"}, - }, - maxExistenceChecks: 3, - remoteErrors: map[digest.Digest]error{"orange": distribution.ErrBlobUnknown}, - remoteBlobs: map[digest.Digest]distribution.Descriptor{digest.Digest("plum"): {}}, - expectedExists: false, - expectedRequests: []string{"orange"}, - expectedRemovals: []metadata.V2Metadata{{Digest: digest.Digest("orange"), SourceRepository: "docker.io/user/app"}}, - }, - { - name: "missing SourceRepository", - targetRepo: "busybox", - metadata: []metadata.V2Metadata{ - {Digest: digest.Digest("1")}, - {Digest: digest.Digest("3")}, - {Digest: digest.Digest("2")}, - }, - maxExistenceChecks: 3, - expectedExists: false, - expectedRequests: []string{"2", "3", "1"}, - }, - - { - name: "with and without SourceRepository", - targetRepo: "busybox", - metadata: []metadata.V2Metadata{ - {Digest: digest.Digest("1")}, - {Digest: digest.Digest("2"), SourceRepository: "docker.io/library/busybox"}, - {Digest: digest.Digest("3")}, - }, - remoteBlobs: map[digest.Digest]distribution.Descriptor{digest.Digest("1"): {Digest: digest.Digest("1")}}, - maxExistenceChecks: 3, - expectedDescriptor: distribution.Descriptor{Digest: digest.Digest("1"), MediaType: schema2.MediaTypeLayer}, - expectedExists: true, - expectedRequests: []string{"2", "3", "1"}, - expectedAdditions: []metadata.V2Metadata{{Digest: digest.Digest("1"), SourceRepository: "docker.io/library/busybox"}}, - expectedRemovals: []metadata.V2Metadata{ - {Digest: digest.Digest("2"), SourceRepository: "docker.io/library/busybox"}, - }, - }, - } { - repoInfo, err := reference.ParseNamed(tc.targetRepo) - if err != nil { - t.Fatalf("[%s] failed to parse reference name: %v", tc.name, err) - } - repo := &mockRepo{ - t: t, - errors: tc.remoteErrors, - blobs: tc.remoteBlobs, - requests: []string{}, - } - ctx := context.Background() - ms := &mockV2MetadataService{} - pd := &v2PushDescriptor{ - hmacKey: []byte(tc.hmacKey), - repoInfo: repoInfo, - layer: &storeLayer{ - Layer: layer.EmptyLayer, - }, - repo: repo, - v2MetadataService: ms, - pushState: &pushState{remoteLayers: make(map[layer.DiffID]distribution.Descriptor)}, - checkedDigests: make(map[digest.Digest]struct{}), - } - - desc, exists, err := pd.layerAlreadyExists(ctx, &progressSink{t}, layer.EmptyLayer.DiffID(), tc.checkOtherRepositories, tc.maxExistenceChecks, tc.metadata) - - if !reflect.DeepEqual(desc, tc.expectedDescriptor) { - t.Errorf("[%s] got unexpected descriptor: %#+v != %#+v", tc.name, desc, tc.expectedDescriptor) - } - if exists != tc.expectedExists { - t.Errorf("[%s] got unexpected exists: %t != %t", tc.name, exists, tc.expectedExists) - } - if !reflect.DeepEqual(err, tc.expectedError) { - t.Errorf("[%s] got unexpected error: %#+v != %#+v", tc.name, err, tc.expectedError) - } - - if len(repo.requests) != len(tc.expectedRequests) { - t.Errorf("[%s] got unexpected number of requests: %d != %d", tc.name, len(repo.requests), len(tc.expectedRequests)) - } - for i := 0; i < len(repo.requests) && i < len(tc.expectedRequests); i++ { - if repo.requests[i] != tc.expectedRequests[i] { - t.Errorf("[%s] request %d does not match expected: %q != %q", tc.name, i, repo.requests[i], tc.expectedRequests[i]) - } - } - for i := len(repo.requests); i < len(tc.expectedRequests); i++ { - t.Errorf("[%s] missing expected request at position %d (%q)", tc.name, i, tc.expectedRequests[i]) - } - for i := len(tc.expectedRequests); i < len(repo.requests); i++ { - t.Errorf("[%s] got unexpected request at position %d (%q)", tc.name, i, repo.requests[i]) - } - - if len(ms.added) != len(tc.expectedAdditions) { - t.Errorf("[%s] got unexpected number of additions: %d != %d", tc.name, len(ms.added), len(tc.expectedAdditions)) - } - for i := 0; i < len(ms.added) && i < len(tc.expectedAdditions); i++ { - if ms.added[i] != tc.expectedAdditions[i] { - t.Errorf("[%s] added metadata at %d does not match expected: %q != %q", tc.name, i, ms.added[i], tc.expectedAdditions[i]) - } - } - for i := len(ms.added); i < len(tc.expectedAdditions); i++ { - t.Errorf("[%s] missing expected addition at position %d (%q)", tc.name, i, tc.expectedAdditions[i]) - } - for i := len(tc.expectedAdditions); i < len(ms.added); i++ { - t.Errorf("[%s] unexpected metadata addition at position %d (%q)", tc.name, i, ms.added[i]) - } - - if len(ms.removed) != len(tc.expectedRemovals) { - t.Errorf("[%s] got unexpected number of removals: %d != %d", tc.name, len(ms.removed), len(tc.expectedRemovals)) - } - for i := 0; i < len(ms.removed) && i < len(tc.expectedRemovals); i++ { - if ms.removed[i] != tc.expectedRemovals[i] { - t.Errorf("[%s] removed metadata at %d does not match expected: %q != %q", tc.name, i, ms.removed[i], tc.expectedRemovals[i]) - } - } - for i := len(ms.removed); i < len(tc.expectedRemovals); i++ { - t.Errorf("[%s] missing expected removal at position %d (%q)", tc.name, i, tc.expectedRemovals[i]) - } - for i := len(tc.expectedRemovals); i < len(ms.removed); i++ { - t.Errorf("[%s] removed unexpected metadata at position %d (%q)", tc.name, i, ms.removed[i]) - } - } -} - -func taggedMetadata(key string, dgst string, sourceRepo string) metadata.V2Metadata { - meta := metadata.V2Metadata{ - Digest: digest.Digest(dgst), - SourceRepository: sourceRepo, - } - - meta.HMAC = metadata.ComputeV2MetadataHMAC([]byte(key), &meta) - return meta -} - -type mockRepo struct { - t *testing.T - errors map[digest.Digest]error - blobs map[digest.Digest]distribution.Descriptor - requests []string -} - -var _ distribution.Repository = &mockRepo{} - -func (m *mockRepo) Named() distreference.Named { - m.t.Fatalf("Named() not implemented") - return nil -} -func (m *mockRepo) Manifests(ctc context.Context, options ...distribution.ManifestServiceOption) (distribution.ManifestService, error) { - m.t.Fatalf("Manifests() not implemented") - return nil, nil -} -func (m *mockRepo) Tags(ctc context.Context) distribution.TagService { - m.t.Fatalf("Tags() not implemented") - return nil -} -func (m *mockRepo) Blobs(ctx context.Context) distribution.BlobStore { - return &mockBlobStore{ - repo: m, - } -} - -type mockBlobStore struct { - repo *mockRepo -} - -var _ distribution.BlobStore = &mockBlobStore{} - -func (m *mockBlobStore) Stat(ctx context.Context, dgst digest.Digest) (distribution.Descriptor, error) { - m.repo.requests = append(m.repo.requests, dgst.String()) - if err, exists := m.repo.errors[dgst]; exists { - return distribution.Descriptor{}, err - } - if desc, exists := m.repo.blobs[dgst]; exists { - return desc, nil - } - return distribution.Descriptor{}, distribution.ErrBlobUnknown -} -func (m *mockBlobStore) Get(ctx context.Context, dgst digest.Digest) ([]byte, error) { - m.repo.t.Fatal("Get() not implemented") - return nil, nil -} - -func (m *mockBlobStore) Open(ctx context.Context, dgst digest.Digest) (distribution.ReadSeekCloser, error) { - m.repo.t.Fatal("Open() not implemented") - return nil, nil -} - -func (m *mockBlobStore) Put(ctx context.Context, mediaType string, p []byte) (distribution.Descriptor, error) { - m.repo.t.Fatal("Put() not implemented") - return distribution.Descriptor{}, nil -} - -func (m *mockBlobStore) Create(ctx context.Context, options ...distribution.BlobCreateOption) (distribution.BlobWriter, error) { - m.repo.t.Fatal("Create() not implemented") - return nil, nil -} -func (m *mockBlobStore) Resume(ctx context.Context, id string) (distribution.BlobWriter, error) { - m.repo.t.Fatal("Resume() not implemented") - return nil, nil -} -func (m *mockBlobStore) Delete(ctx context.Context, dgst digest.Digest) error { - m.repo.t.Fatal("Delete() not implemented") - return nil -} -func (m *mockBlobStore) ServeBlob(ctx context.Context, w http.ResponseWriter, r *http.Request, dgst digest.Digest) error { - m.repo.t.Fatalf("ServeBlob() not implemented") - return nil -} - -type mockV2MetadataService struct { - added []metadata.V2Metadata - removed []metadata.V2Metadata -} - -var _ metadata.V2MetadataService = &mockV2MetadataService{} - -func (*mockV2MetadataService) GetMetadata(diffID layer.DiffID) ([]metadata.V2Metadata, error) { - return nil, nil -} -func (*mockV2MetadataService) GetDiffID(dgst digest.Digest) (layer.DiffID, error) { - return "", nil -} -func (m *mockV2MetadataService) Add(diffID layer.DiffID, metadata metadata.V2Metadata) error { - m.added = append(m.added, metadata) - return nil -} -func (m *mockV2MetadataService) TagAndAdd(diffID layer.DiffID, hmacKey []byte, meta metadata.V2Metadata) error { - meta.HMAC = metadata.ComputeV2MetadataHMAC(hmacKey, &meta) - m.Add(diffID, meta) - return nil -} -func (m *mockV2MetadataService) Remove(metadata metadata.V2Metadata) error { - m.removed = append(m.removed, metadata) - return nil -} - -type progressSink struct { - t *testing.T -} - -func (s *progressSink) WriteProgress(p progress.Progress) error { - s.t.Logf("progress update: %#+v", p) - return nil -} diff --git a/vendor/github.com/docker/docker/distribution/registry.go b/vendor/github.com/docker/docker/distribution/registry.go deleted file mode 100644 index 95e181d..0000000 --- a/vendor/github.com/docker/docker/distribution/registry.go +++ /dev/null @@ -1,156 +0,0 @@ -package distribution - -import ( - "fmt" - "net" - "net/http" - "time" - - "github.com/docker/distribution" - "github.com/docker/distribution/manifest/schema2" - distreference "github.com/docker/distribution/reference" - "github.com/docker/distribution/registry/client" - "github.com/docker/distribution/registry/client/auth" - "github.com/docker/distribution/registry/client/transport" - "github.com/docker/docker/api/types" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/registry" - "github.com/docker/go-connections/sockets" - "golang.org/x/net/context" -) - -// ImageTypes represents the schema2 config types for images -var ImageTypes = []string{ - schema2.MediaTypeImageConfig, - // Handle unexpected values from https://github.com/docker/distribution/issues/1621 - // (see also https://github.com/docker/docker/issues/22378, - // https://github.com/docker/docker/issues/30083) - "application/octet-stream", - "application/json", - "text/html", - // Treat defaulted values as images, newer types cannot be implied - "", -} - -// PluginTypes represents the schema2 config types for plugins -var PluginTypes = []string{ - schema2.MediaTypePluginConfig, -} - -var mediaTypeClasses map[string]string - -func init() { - // initialize media type classes with all know types for - // plugin - mediaTypeClasses = map[string]string{} - for _, t := range ImageTypes { - mediaTypeClasses[t] = "image" - } - for _, t := range PluginTypes { - mediaTypeClasses[t] = "plugin" - } -} - -// NewV2Repository returns a repository (v2 only). It creates an HTTP transport -// providing timeout settings and authentication support, and also verifies the -// remote API version. -func NewV2Repository(ctx context.Context, repoInfo *registry.RepositoryInfo, endpoint registry.APIEndpoint, metaHeaders http.Header, authConfig *types.AuthConfig, actions ...string) (repo distribution.Repository, foundVersion bool, err error) { - repoName := repoInfo.FullName() - // If endpoint does not support CanonicalName, use the RemoteName instead - if endpoint.TrimHostname { - repoName = repoInfo.RemoteName() - } - - direct := &net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - DualStack: true, - } - - // TODO(dmcgowan): Call close idle connections when complete, use keep alive - base := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: direct.Dial, - TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: endpoint.TLSConfig, - // TODO(dmcgowan): Call close idle connections when complete and use keep alive - DisableKeepAlives: true, - } - - proxyDialer, err := sockets.DialerFromEnvironment(direct) - if err == nil { - base.Dial = proxyDialer.Dial - } - - modifiers := registry.DockerHeaders(dockerversion.DockerUserAgent(ctx), metaHeaders) - authTransport := transport.NewTransport(base, modifiers...) - - challengeManager, foundVersion, err := registry.PingV2Registry(endpoint.URL, authTransport) - if err != nil { - transportOK := false - if responseErr, ok := err.(registry.PingResponseError); ok { - transportOK = true - err = responseErr.Err - } - return nil, foundVersion, fallbackError{ - err: err, - confirmedV2: foundVersion, - transportOK: transportOK, - } - } - - if authConfig.RegistryToken != "" { - passThruTokenHandler := &existingTokenHandler{token: authConfig.RegistryToken} - modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, passThruTokenHandler)) - } else { - scope := auth.RepositoryScope{ - Repository: repoName, - Actions: actions, - Class: repoInfo.Class, - } - - creds := registry.NewStaticCredentialStore(authConfig) - tokenHandlerOptions := auth.TokenHandlerOptions{ - Transport: authTransport, - Credentials: creds, - Scopes: []auth.Scope{scope}, - ClientID: registry.AuthClientID, - } - tokenHandler := auth.NewTokenHandlerWithOptions(tokenHandlerOptions) - basicHandler := auth.NewBasicHandler(creds) - modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler)) - } - tr := transport.NewTransport(base, modifiers...) - - repoNameRef, err := distreference.ParseNamed(repoName) - if err != nil { - return nil, foundVersion, fallbackError{ - err: err, - confirmedV2: foundVersion, - transportOK: true, - } - } - - repo, err = client.NewRepository(ctx, repoNameRef, endpoint.URL.String(), tr) - if err != nil { - err = fallbackError{ - err: err, - confirmedV2: foundVersion, - transportOK: true, - } - } - return -} - -type existingTokenHandler struct { - token string -} - -func (th *existingTokenHandler) Scheme() string { - return "bearer" -} - -func (th *existingTokenHandler) AuthorizeRequest(req *http.Request, params map[string]string) error { - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", th.token)) - return nil -} diff --git a/vendor/github.com/docker/docker/distribution/registry_unit_test.go b/vendor/github.com/docker/docker/distribution/registry_unit_test.go deleted file mode 100644 index 406de34..0000000 --- a/vendor/github.com/docker/docker/distribution/registry_unit_test.go +++ /dev/null @@ -1,136 +0,0 @@ -package distribution - -import ( - "net/http" - "net/http/httptest" - "net/url" - "os" - "strings" - "testing" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "github.com/docker/docker/utils" - "golang.org/x/net/context" -) - -const secretRegistryToken = "mysecrettoken" - -type tokenPassThruHandler struct { - reached bool - gotToken bool - shouldSend401 func(url string) bool -} - -func (h *tokenPassThruHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - h.reached = true - if strings.Contains(r.Header.Get("Authorization"), secretRegistryToken) { - logrus.Debug("Detected registry token in auth header") - h.gotToken = true - } - if h.shouldSend401 == nil || h.shouldSend401(r.RequestURI) { - w.Header().Set("WWW-Authenticate", `Bearer realm="foorealm"`) - w.WriteHeader(401) - } -} - -func testTokenPassThru(t *testing.T, ts *httptest.Server) { - tmp, err := utils.TestDirectory("") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - - uri, err := url.Parse(ts.URL) - if err != nil { - t.Fatalf("could not parse url from test server: %v", err) - } - - endpoint := registry.APIEndpoint{ - Mirror: false, - URL: uri, - Version: 2, - Official: false, - TrimHostname: false, - TLSConfig: nil, - //VersionHeader: "verheader", - } - n, _ := reference.ParseNamed("testremotename") - repoInfo := ®istry.RepositoryInfo{ - Named: n, - Index: ®istrytypes.IndexInfo{ - Name: "testrepo", - Mirrors: nil, - Secure: false, - Official: false, - }, - Official: false, - } - imagePullConfig := &ImagePullConfig{ - Config: Config{ - MetaHeaders: http.Header{}, - AuthConfig: &types.AuthConfig{ - RegistryToken: secretRegistryToken, - }, - }, - Schema2Types: ImageTypes, - } - puller, err := newPuller(endpoint, repoInfo, imagePullConfig) - if err != nil { - t.Fatal(err) - } - p := puller.(*v2Puller) - ctx := context.Background() - p.repo, _, err = NewV2Repository(ctx, p.repoInfo, p.endpoint, p.config.MetaHeaders, p.config.AuthConfig, "pull") - if err != nil { - t.Fatal(err) - } - - logrus.Debug("About to pull") - // We expect it to fail, since we haven't mock'd the full registry exchange in our handler above - tag, _ := reference.WithTag(n, "tag_goes_here") - _ = p.pullV2Repository(ctx, tag) -} - -func TestTokenPassThru(t *testing.T) { - handler := &tokenPassThruHandler{shouldSend401: func(url string) bool { return url == "/v2/" }} - ts := httptest.NewServer(handler) - defer ts.Close() - - testTokenPassThru(t, ts) - - if !handler.reached { - t.Fatal("Handler not reached") - } - if !handler.gotToken { - t.Fatal("Failed to receive registry token") - } -} - -func TestTokenPassThruDifferentHost(t *testing.T) { - handler := new(tokenPassThruHandler) - ts := httptest.NewServer(handler) - defer ts.Close() - - tsredirect := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.RequestURI == "/v2/" { - w.Header().Set("WWW-Authenticate", `Bearer realm="foorealm"`) - w.WriteHeader(401) - return - } - http.Redirect(w, r, ts.URL+r.URL.Path, http.StatusMovedPermanently) - })) - defer tsredirect.Close() - - testTokenPassThru(t, tsredirect) - - if !handler.reached { - t.Fatal("Handler not reached") - } - if handler.gotToken { - t.Fatal("Redirect should not forward Authorization header to another host") - } -} diff --git a/vendor/github.com/docker/docker/distribution/utils/progress.go b/vendor/github.com/docker/docker/distribution/utils/progress.go deleted file mode 100644 index ef8ecc8..0000000 --- a/vendor/github.com/docker/docker/distribution/utils/progress.go +++ /dev/null @@ -1,44 +0,0 @@ -package utils - -import ( - "io" - "net" - "os" - "syscall" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/streamformatter" -) - -// WriteDistributionProgress is a helper for writing progress from chan to JSON -// stream with an optional cancel function. -func WriteDistributionProgress(cancelFunc func(), outStream io.Writer, progressChan <-chan progress.Progress) { - progressOutput := streamformatter.NewJSONStreamFormatter().NewProgressOutput(outStream, false) - operationCancelled := false - - for prog := range progressChan { - if err := progressOutput.WriteProgress(prog); err != nil && !operationCancelled { - // don't log broken pipe errors as this is the normal case when a client aborts - if isBrokenPipe(err) { - logrus.Info("Pull session cancelled") - } else { - logrus.Errorf("error writing progress to client: %v", err) - } - cancelFunc() - operationCancelled = true - // Don't return, because we need to continue draining - // progressChan until it's closed to avoid a deadlock. - } - } -} - -func isBrokenPipe(e error) bool { - if netErr, ok := e.(*net.OpError); ok { - e = netErr.Err - if sysErr, ok := netErr.Err.(*os.SyscallError); ok { - e = sysErr.Err - } - } - return e == syscall.EPIPE -} diff --git a/vendor/github.com/docker/docker/distribution/xfer/download.go b/vendor/github.com/docker/docker/distribution/xfer/download.go deleted file mode 100644 index 7545342..0000000 --- a/vendor/github.com/docker/docker/distribution/xfer/download.go +++ /dev/null @@ -1,452 +0,0 @@ -package xfer - -import ( - "errors" - "fmt" - "io" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/progress" - "golang.org/x/net/context" -) - -const maxDownloadAttempts = 5 - -// LayerDownloadManager figures out which layers need to be downloaded, then -// registers and downloads those, taking into account dependencies between -// layers. -type LayerDownloadManager struct { - layerStore layer.Store - tm TransferManager -} - -// SetConcurrency set the max concurrent downloads for each pull -func (ldm *LayerDownloadManager) SetConcurrency(concurrency int) { - ldm.tm.SetConcurrency(concurrency) -} - -// NewLayerDownloadManager returns a new LayerDownloadManager. -func NewLayerDownloadManager(layerStore layer.Store, concurrencyLimit int) *LayerDownloadManager { - return &LayerDownloadManager{ - layerStore: layerStore, - tm: NewTransferManager(concurrencyLimit), - } -} - -type downloadTransfer struct { - Transfer - - layerStore layer.Store - layer layer.Layer - err error -} - -// result returns the layer resulting from the download, if the download -// and registration were successful. -func (d *downloadTransfer) result() (layer.Layer, error) { - return d.layer, d.err -} - -// A DownloadDescriptor references a layer that may need to be downloaded. -type DownloadDescriptor interface { - // Key returns the key used to deduplicate downloads. - Key() string - // ID returns the ID for display purposes. - ID() string - // DiffID should return the DiffID for this layer, or an error - // if it is unknown (for example, if it has not been downloaded - // before). - DiffID() (layer.DiffID, error) - // Download is called to perform the download. - Download(ctx context.Context, progressOutput progress.Output) (io.ReadCloser, int64, error) - // Close is called when the download manager is finished with this - // descriptor and will not call Download again or read from the reader - // that Download returned. - Close() -} - -// DownloadDescriptorWithRegistered is a DownloadDescriptor that has an -// additional Registered method which gets called after a downloaded layer is -// registered. This allows the user of the download manager to know the DiffID -// of each registered layer. This method is called if a cast to -// DownloadDescriptorWithRegistered is successful. -type DownloadDescriptorWithRegistered interface { - DownloadDescriptor - Registered(diffID layer.DiffID) -} - -// Download is a blocking function which ensures the requested layers are -// present in the layer store. It uses the string returned by the Key method to -// deduplicate downloads. If a given layer is not already known to present in -// the layer store, and the key is not used by an in-progress download, the -// Download method is called to get the layer tar data. Layers are then -// registered in the appropriate order. The caller must call the returned -// release function once it is is done with the returned RootFS object. -func (ldm *LayerDownloadManager) Download(ctx context.Context, initialRootFS image.RootFS, layers []DownloadDescriptor, progressOutput progress.Output) (image.RootFS, func(), error) { - var ( - topLayer layer.Layer - topDownload *downloadTransfer - watcher *Watcher - missingLayer bool - transferKey = "" - downloadsByKey = make(map[string]*downloadTransfer) - ) - - rootFS := initialRootFS - for _, descriptor := range layers { - key := descriptor.Key() - transferKey += key - - if !missingLayer { - missingLayer = true - diffID, err := descriptor.DiffID() - if err == nil { - getRootFS := rootFS - getRootFS.Append(diffID) - l, err := ldm.layerStore.Get(getRootFS.ChainID()) - if err == nil { - // Layer already exists. - logrus.Debugf("Layer already exists: %s", descriptor.ID()) - progress.Update(progressOutput, descriptor.ID(), "Already exists") - if topLayer != nil { - layer.ReleaseAndLog(ldm.layerStore, topLayer) - } - topLayer = l - missingLayer = false - rootFS.Append(diffID) - continue - } - } - } - - // Does this layer have the same data as a previous layer in - // the stack? If so, avoid downloading it more than once. - var topDownloadUncasted Transfer - if existingDownload, ok := downloadsByKey[key]; ok { - xferFunc := ldm.makeDownloadFuncFromDownload(descriptor, existingDownload, topDownload) - defer topDownload.Transfer.Release(watcher) - topDownloadUncasted, watcher = ldm.tm.Transfer(transferKey, xferFunc, progressOutput) - topDownload = topDownloadUncasted.(*downloadTransfer) - continue - } - - // Layer is not known to exist - download and register it. - progress.Update(progressOutput, descriptor.ID(), "Pulling fs layer") - - var xferFunc DoFunc - if topDownload != nil { - xferFunc = ldm.makeDownloadFunc(descriptor, "", topDownload) - defer topDownload.Transfer.Release(watcher) - } else { - xferFunc = ldm.makeDownloadFunc(descriptor, rootFS.ChainID(), nil) - } - topDownloadUncasted, watcher = ldm.tm.Transfer(transferKey, xferFunc, progressOutput) - topDownload = topDownloadUncasted.(*downloadTransfer) - downloadsByKey[key] = topDownload - } - - if topDownload == nil { - return rootFS, func() { - if topLayer != nil { - layer.ReleaseAndLog(ldm.layerStore, topLayer) - } - }, nil - } - - // Won't be using the list built up so far - will generate it - // from downloaded layers instead. - rootFS.DiffIDs = []layer.DiffID{} - - defer func() { - if topLayer != nil { - layer.ReleaseAndLog(ldm.layerStore, topLayer) - } - }() - - select { - case <-ctx.Done(): - topDownload.Transfer.Release(watcher) - return rootFS, func() {}, ctx.Err() - case <-topDownload.Done(): - break - } - - l, err := topDownload.result() - if err != nil { - topDownload.Transfer.Release(watcher) - return rootFS, func() {}, err - } - - // Must do this exactly len(layers) times, so we don't include the - // base layer on Windows. - for range layers { - if l == nil { - topDownload.Transfer.Release(watcher) - return rootFS, func() {}, errors.New("internal error: too few parent layers") - } - rootFS.DiffIDs = append([]layer.DiffID{l.DiffID()}, rootFS.DiffIDs...) - l = l.Parent() - } - return rootFS, func() { topDownload.Transfer.Release(watcher) }, err -} - -// makeDownloadFunc returns a function that performs the layer download and -// registration. If parentDownload is non-nil, it waits for that download to -// complete before the registration step, and registers the downloaded data -// on top of parentDownload's resulting layer. Otherwise, it registers the -// layer on top of the ChainID given by parentLayer. -func (ldm *LayerDownloadManager) makeDownloadFunc(descriptor DownloadDescriptor, parentLayer layer.ChainID, parentDownload *downloadTransfer) DoFunc { - return func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) Transfer { - d := &downloadTransfer{ - Transfer: NewTransfer(), - layerStore: ldm.layerStore, - } - - go func() { - defer func() { - close(progressChan) - }() - - progressOutput := progress.ChanOutput(progressChan) - - select { - case <-start: - default: - progress.Update(progressOutput, descriptor.ID(), "Waiting") - <-start - } - - if parentDownload != nil { - // Did the parent download already fail or get - // cancelled? - select { - case <-parentDownload.Done(): - _, err := parentDownload.result() - if err != nil { - d.err = err - return - } - default: - } - } - - var ( - downloadReader io.ReadCloser - size int64 - err error - retries int - ) - - defer descriptor.Close() - - for { - downloadReader, size, err = descriptor.Download(d.Transfer.Context(), progressOutput) - if err == nil { - break - } - - // If an error was returned because the context - // was cancelled, we shouldn't retry. - select { - case <-d.Transfer.Context().Done(): - d.err = err - return - default: - } - - retries++ - if _, isDNR := err.(DoNotRetry); isDNR || retries == maxDownloadAttempts { - logrus.Errorf("Download failed: %v", err) - d.err = err - return - } - - logrus.Errorf("Download failed, retrying: %v", err) - delay := retries * 5 - ticker := time.NewTicker(time.Second) - - selectLoop: - for { - progress.Updatef(progressOutput, descriptor.ID(), "Retrying in %d second%s", delay, (map[bool]string{true: "s"})[delay != 1]) - select { - case <-ticker.C: - delay-- - if delay == 0 { - ticker.Stop() - break selectLoop - } - case <-d.Transfer.Context().Done(): - ticker.Stop() - d.err = errors.New("download cancelled during retry delay") - return - } - - } - } - - close(inactive) - - if parentDownload != nil { - select { - case <-d.Transfer.Context().Done(): - d.err = errors.New("layer registration cancelled") - downloadReader.Close() - return - case <-parentDownload.Done(): - } - - l, err := parentDownload.result() - if err != nil { - d.err = err - downloadReader.Close() - return - } - parentLayer = l.ChainID() - } - - reader := progress.NewProgressReader(ioutils.NewCancelReadCloser(d.Transfer.Context(), downloadReader), progressOutput, size, descriptor.ID(), "Extracting") - defer reader.Close() - - inflatedLayerData, err := archive.DecompressStream(reader) - if err != nil { - d.err = fmt.Errorf("could not get decompression stream: %v", err) - return - } - - var src distribution.Descriptor - if fs, ok := descriptor.(distribution.Describable); ok { - src = fs.Descriptor() - } - if ds, ok := d.layerStore.(layer.DescribableStore); ok { - d.layer, err = ds.RegisterWithDescriptor(inflatedLayerData, parentLayer, src) - } else { - d.layer, err = d.layerStore.Register(inflatedLayerData, parentLayer) - } - if err != nil { - select { - case <-d.Transfer.Context().Done(): - d.err = errors.New("layer registration cancelled") - default: - d.err = fmt.Errorf("failed to register layer: %v", err) - } - return - } - - progress.Update(progressOutput, descriptor.ID(), "Pull complete") - withRegistered, hasRegistered := descriptor.(DownloadDescriptorWithRegistered) - if hasRegistered { - withRegistered.Registered(d.layer.DiffID()) - } - - // Doesn't actually need to be its own goroutine, but - // done like this so we can defer close(c). - go func() { - <-d.Transfer.Released() - if d.layer != nil { - layer.ReleaseAndLog(d.layerStore, d.layer) - } - }() - }() - - return d - } -} - -// makeDownloadFuncFromDownload returns a function that performs the layer -// registration when the layer data is coming from an existing download. It -// waits for sourceDownload and parentDownload to complete, and then -// reregisters the data from sourceDownload's top layer on top of -// parentDownload. This function does not log progress output because it would -// interfere with the progress reporting for sourceDownload, which has the same -// Key. -func (ldm *LayerDownloadManager) makeDownloadFuncFromDownload(descriptor DownloadDescriptor, sourceDownload *downloadTransfer, parentDownload *downloadTransfer) DoFunc { - return func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) Transfer { - d := &downloadTransfer{ - Transfer: NewTransfer(), - layerStore: ldm.layerStore, - } - - go func() { - defer func() { - close(progressChan) - }() - - <-start - - close(inactive) - - select { - case <-d.Transfer.Context().Done(): - d.err = errors.New("layer registration cancelled") - return - case <-parentDownload.Done(): - } - - l, err := parentDownload.result() - if err != nil { - d.err = err - return - } - parentLayer := l.ChainID() - - // sourceDownload should have already finished if - // parentDownload finished, but wait for it explicitly - // to be sure. - select { - case <-d.Transfer.Context().Done(): - d.err = errors.New("layer registration cancelled") - return - case <-sourceDownload.Done(): - } - - l, err = sourceDownload.result() - if err != nil { - d.err = err - return - } - - layerReader, err := l.TarStream() - if err != nil { - d.err = err - return - } - defer layerReader.Close() - - var src distribution.Descriptor - if fs, ok := l.(distribution.Describable); ok { - src = fs.Descriptor() - } - if ds, ok := d.layerStore.(layer.DescribableStore); ok { - d.layer, err = ds.RegisterWithDescriptor(layerReader, parentLayer, src) - } else { - d.layer, err = d.layerStore.Register(layerReader, parentLayer) - } - if err != nil { - d.err = fmt.Errorf("failed to register layer: %v", err) - return - } - - withRegistered, hasRegistered := descriptor.(DownloadDescriptorWithRegistered) - if hasRegistered { - withRegistered.Registered(d.layer.DiffID()) - } - - // Doesn't actually need to be its own goroutine, but - // done like this so we can defer close(c). - go func() { - <-d.Transfer.Released() - if d.layer != nil { - layer.ReleaseAndLog(d.layerStore, d.layer) - } - }() - }() - - return d - } -} diff --git a/vendor/github.com/docker/docker/distribution/xfer/download_test.go b/vendor/github.com/docker/docker/distribution/xfer/download_test.go deleted file mode 100644 index bc20e1e..0000000 --- a/vendor/github.com/docker/docker/distribution/xfer/download_test.go +++ /dev/null @@ -1,356 +0,0 @@ -package xfer - -import ( - "bytes" - "errors" - "fmt" - "io" - "io/ioutil" - "runtime" - "sync/atomic" - "testing" - "time" - - "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/progress" - "golang.org/x/net/context" -) - -const maxDownloadConcurrency = 3 - -type mockLayer struct { - layerData bytes.Buffer - diffID layer.DiffID - chainID layer.ChainID - parent layer.Layer -} - -func (ml *mockLayer) TarStream() (io.ReadCloser, error) { - return ioutil.NopCloser(bytes.NewBuffer(ml.layerData.Bytes())), nil -} - -func (ml *mockLayer) TarStreamFrom(layer.ChainID) (io.ReadCloser, error) { - return nil, fmt.Errorf("not implemented") -} - -func (ml *mockLayer) ChainID() layer.ChainID { - return ml.chainID -} - -func (ml *mockLayer) DiffID() layer.DiffID { - return ml.diffID -} - -func (ml *mockLayer) Parent() layer.Layer { - return ml.parent -} - -func (ml *mockLayer) Size() (size int64, err error) { - return 0, nil -} - -func (ml *mockLayer) DiffSize() (size int64, err error) { - return 0, nil -} - -func (ml *mockLayer) Metadata() (map[string]string, error) { - return make(map[string]string), nil -} - -type mockLayerStore struct { - layers map[layer.ChainID]*mockLayer -} - -func createChainIDFromParent(parent layer.ChainID, dgsts ...layer.DiffID) layer.ChainID { - if len(dgsts) == 0 { - return parent - } - if parent == "" { - return createChainIDFromParent(layer.ChainID(dgsts[0]), dgsts[1:]...) - } - // H = "H(n-1) SHA256(n)" - dgst := digest.FromBytes([]byte(string(parent) + " " + string(dgsts[0]))) - return createChainIDFromParent(layer.ChainID(dgst), dgsts[1:]...) -} - -func (ls *mockLayerStore) Map() map[layer.ChainID]layer.Layer { - layers := map[layer.ChainID]layer.Layer{} - - for k, v := range ls.layers { - layers[k] = v - } - - return layers -} - -func (ls *mockLayerStore) Register(reader io.Reader, parentID layer.ChainID) (layer.Layer, error) { - return ls.RegisterWithDescriptor(reader, parentID, distribution.Descriptor{}) -} - -func (ls *mockLayerStore) RegisterWithDescriptor(reader io.Reader, parentID layer.ChainID, _ distribution.Descriptor) (layer.Layer, error) { - var ( - parent layer.Layer - err error - ) - - if parentID != "" { - parent, err = ls.Get(parentID) - if err != nil { - return nil, err - } - } - - l := &mockLayer{parent: parent} - _, err = l.layerData.ReadFrom(reader) - if err != nil { - return nil, err - } - l.diffID = layer.DiffID(digest.FromBytes(l.layerData.Bytes())) - l.chainID = createChainIDFromParent(parentID, l.diffID) - - ls.layers[l.chainID] = l - return l, nil -} - -func (ls *mockLayerStore) Get(chainID layer.ChainID) (layer.Layer, error) { - l, ok := ls.layers[chainID] - if !ok { - return nil, layer.ErrLayerDoesNotExist - } - return l, nil -} - -func (ls *mockLayerStore) Release(l layer.Layer) ([]layer.Metadata, error) { - return []layer.Metadata{}, nil -} -func (ls *mockLayerStore) CreateRWLayer(string, layer.ChainID, string, layer.MountInit, map[string]string) (layer.RWLayer, error) { - return nil, errors.New("not implemented") -} - -func (ls *mockLayerStore) GetRWLayer(string) (layer.RWLayer, error) { - return nil, errors.New("not implemented") -} - -func (ls *mockLayerStore) ReleaseRWLayer(layer.RWLayer) ([]layer.Metadata, error) { - return nil, errors.New("not implemented") -} -func (ls *mockLayerStore) GetMountID(string) (string, error) { - return "", errors.New("not implemented") -} - -func (ls *mockLayerStore) Cleanup() error { - return nil -} - -func (ls *mockLayerStore) DriverStatus() [][2]string { - return [][2]string{} -} - -func (ls *mockLayerStore) DriverName() string { - return "mock" -} - -type mockDownloadDescriptor struct { - currentDownloads *int32 - id string - diffID layer.DiffID - registeredDiffID layer.DiffID - expectedDiffID layer.DiffID - simulateRetries int -} - -// Key returns the key used to deduplicate downloads. -func (d *mockDownloadDescriptor) Key() string { - return d.id -} - -// ID returns the ID for display purposes. -func (d *mockDownloadDescriptor) ID() string { - return d.id -} - -// DiffID should return the DiffID for this layer, or an error -// if it is unknown (for example, if it has not been downloaded -// before). -func (d *mockDownloadDescriptor) DiffID() (layer.DiffID, error) { - if d.diffID != "" { - return d.diffID, nil - } - return "", errors.New("no diffID available") -} - -func (d *mockDownloadDescriptor) Registered(diffID layer.DiffID) { - d.registeredDiffID = diffID -} - -func (d *mockDownloadDescriptor) mockTarStream() io.ReadCloser { - // The mock implementation returns the ID repeated 5 times as a tar - // stream instead of actual tar data. The data is ignored except for - // computing IDs. - return ioutil.NopCloser(bytes.NewBuffer([]byte(d.id + d.id + d.id + d.id + d.id))) -} - -// Download is called to perform the download. -func (d *mockDownloadDescriptor) Download(ctx context.Context, progressOutput progress.Output) (io.ReadCloser, int64, error) { - if d.currentDownloads != nil { - defer atomic.AddInt32(d.currentDownloads, -1) - - if atomic.AddInt32(d.currentDownloads, 1) > maxDownloadConcurrency { - return nil, 0, errors.New("concurrency limit exceeded") - } - } - - // Sleep a bit to simulate a time-consuming download. - for i := int64(0); i <= 10; i++ { - select { - case <-ctx.Done(): - return nil, 0, ctx.Err() - case <-time.After(10 * time.Millisecond): - progressOutput.WriteProgress(progress.Progress{ID: d.ID(), Action: "Downloading", Current: i, Total: 10}) - } - } - - if d.simulateRetries != 0 { - d.simulateRetries-- - return nil, 0, errors.New("simulating retry") - } - - return d.mockTarStream(), 0, nil -} - -func (d *mockDownloadDescriptor) Close() { -} - -func downloadDescriptors(currentDownloads *int32) []DownloadDescriptor { - return []DownloadDescriptor{ - &mockDownloadDescriptor{ - currentDownloads: currentDownloads, - id: "id1", - expectedDiffID: layer.DiffID("sha256:68e2c75dc5c78ea9240689c60d7599766c213ae210434c53af18470ae8c53ec1"), - }, - &mockDownloadDescriptor{ - currentDownloads: currentDownloads, - id: "id2", - expectedDiffID: layer.DiffID("sha256:64a636223116aa837973a5d9c2bdd17d9b204e4f95ac423e20e65dfbb3655473"), - }, - &mockDownloadDescriptor{ - currentDownloads: currentDownloads, - id: "id3", - expectedDiffID: layer.DiffID("sha256:58745a8bbd669c25213e9de578c4da5c8ee1c836b3581432c2b50e38a6753300"), - }, - &mockDownloadDescriptor{ - currentDownloads: currentDownloads, - id: "id2", - expectedDiffID: layer.DiffID("sha256:64a636223116aa837973a5d9c2bdd17d9b204e4f95ac423e20e65dfbb3655473"), - }, - &mockDownloadDescriptor{ - currentDownloads: currentDownloads, - id: "id4", - expectedDiffID: layer.DiffID("sha256:0dfb5b9577716cc173e95af7c10289322c29a6453a1718addc00c0c5b1330936"), - simulateRetries: 1, - }, - &mockDownloadDescriptor{ - currentDownloads: currentDownloads, - id: "id5", - expectedDiffID: layer.DiffID("sha256:0a5f25fa1acbc647f6112a6276735d0fa01e4ee2aa7ec33015e337350e1ea23d"), - }, - } -} - -func TestSuccessfulDownload(t *testing.T) { - // TODO Windows: Fix this unit text - if runtime.GOOS == "windows" { - t.Skip("Needs fixing on Windows") - } - layerStore := &mockLayerStore{make(map[layer.ChainID]*mockLayer)} - ldm := NewLayerDownloadManager(layerStore, maxDownloadConcurrency) - - progressChan := make(chan progress.Progress) - progressDone := make(chan struct{}) - receivedProgress := make(map[string]progress.Progress) - - go func() { - for p := range progressChan { - receivedProgress[p.ID] = p - } - close(progressDone) - }() - - var currentDownloads int32 - descriptors := downloadDescriptors(¤tDownloads) - - firstDescriptor := descriptors[0].(*mockDownloadDescriptor) - - // Pre-register the first layer to simulate an already-existing layer - l, err := layerStore.Register(firstDescriptor.mockTarStream(), "") - if err != nil { - t.Fatal(err) - } - firstDescriptor.diffID = l.DiffID() - - rootFS, releaseFunc, err := ldm.Download(context.Background(), *image.NewRootFS(), descriptors, progress.ChanOutput(progressChan)) - if err != nil { - t.Fatalf("download error: %v", err) - } - - releaseFunc() - - close(progressChan) - <-progressDone - - if len(rootFS.DiffIDs) != len(descriptors) { - t.Fatal("got wrong number of diffIDs in rootfs") - } - - for i, d := range descriptors { - descriptor := d.(*mockDownloadDescriptor) - - if descriptor.diffID != "" { - if receivedProgress[d.ID()].Action != "Already exists" { - t.Fatalf("did not get 'Already exists' message for %v", d.ID()) - } - } else if receivedProgress[d.ID()].Action != "Pull complete" { - t.Fatalf("did not get 'Pull complete' message for %v", d.ID()) - } - - if rootFS.DiffIDs[i] != descriptor.expectedDiffID { - t.Fatalf("rootFS item %d has the wrong diffID (expected: %v got: %v)", i, descriptor.expectedDiffID, rootFS.DiffIDs[i]) - } - - if descriptor.diffID == "" && descriptor.registeredDiffID != rootFS.DiffIDs[i] { - t.Fatal("diffID mismatch between rootFS and Registered callback") - } - } -} - -func TestCancelledDownload(t *testing.T) { - ldm := NewLayerDownloadManager(&mockLayerStore{make(map[layer.ChainID]*mockLayer)}, maxDownloadConcurrency) - - progressChan := make(chan progress.Progress) - progressDone := make(chan struct{}) - - go func() { - for range progressChan { - } - close(progressDone) - }() - - ctx, cancel := context.WithCancel(context.Background()) - - go func() { - <-time.After(time.Millisecond) - cancel() - }() - - descriptors := downloadDescriptors(nil) - _, _, err := ldm.Download(ctx, *image.NewRootFS(), descriptors, progress.ChanOutput(progressChan)) - if err != context.Canceled { - t.Fatal("expected download to be cancelled") - } - - close(progressChan) - <-progressDone -} diff --git a/vendor/github.com/docker/docker/distribution/xfer/transfer.go b/vendor/github.com/docker/docker/distribution/xfer/transfer.go deleted file mode 100644 index 14f1566..0000000 --- a/vendor/github.com/docker/docker/distribution/xfer/transfer.go +++ /dev/null @@ -1,401 +0,0 @@ -package xfer - -import ( - "runtime" - "sync" - - "github.com/docker/docker/pkg/progress" - "golang.org/x/net/context" -) - -// DoNotRetry is an error wrapper indicating that the error cannot be resolved -// with a retry. -type DoNotRetry struct { - Err error -} - -// Error returns the stringified representation of the encapsulated error. -func (e DoNotRetry) Error() string { - return e.Err.Error() -} - -// Watcher is returned by Watch and can be passed to Release to stop watching. -type Watcher struct { - // signalChan is used to signal to the watcher goroutine that - // new progress information is available, or that the transfer - // has finished. - signalChan chan struct{} - // releaseChan signals to the watcher goroutine that the watcher - // should be detached. - releaseChan chan struct{} - // running remains open as long as the watcher is watching the - // transfer. It gets closed if the transfer finishes or the - // watcher is detached. - running chan struct{} -} - -// Transfer represents an in-progress transfer. -type Transfer interface { - Watch(progressOutput progress.Output) *Watcher - Release(*Watcher) - Context() context.Context - Close() - Done() <-chan struct{} - Released() <-chan struct{} - Broadcast(masterProgressChan <-chan progress.Progress) -} - -type transfer struct { - mu sync.Mutex - - ctx context.Context - cancel context.CancelFunc - - // watchers keeps track of the goroutines monitoring progress output, - // indexed by the channels that release them. - watchers map[chan struct{}]*Watcher - - // lastProgress is the most recently received progress event. - lastProgress progress.Progress - // hasLastProgress is true when lastProgress has been set. - hasLastProgress bool - - // running remains open as long as the transfer is in progress. - running chan struct{} - // released stays open until all watchers release the transfer and - // the transfer is no longer tracked by the transfer manager. - released chan struct{} - - // broadcastDone is true if the master progress channel has closed. - broadcastDone bool - // closed is true if Close has been called - closed bool - // broadcastSyncChan allows watchers to "ping" the broadcasting - // goroutine to wait for it for deplete its input channel. This ensures - // a detaching watcher won't miss an event that was sent before it - // started detaching. - broadcastSyncChan chan struct{} -} - -// NewTransfer creates a new transfer. -func NewTransfer() Transfer { - t := &transfer{ - watchers: make(map[chan struct{}]*Watcher), - running: make(chan struct{}), - released: make(chan struct{}), - broadcastSyncChan: make(chan struct{}), - } - - // This uses context.Background instead of a caller-supplied context - // so that a transfer won't be cancelled automatically if the client - // which requested it is ^C'd (there could be other viewers). - t.ctx, t.cancel = context.WithCancel(context.Background()) - - return t -} - -// Broadcast copies the progress and error output to all viewers. -func (t *transfer) Broadcast(masterProgressChan <-chan progress.Progress) { - for { - var ( - p progress.Progress - ok bool - ) - select { - case p, ok = <-masterProgressChan: - default: - // We've depleted the channel, so now we can handle - // reads on broadcastSyncChan to let detaching watchers - // know we're caught up. - select { - case <-t.broadcastSyncChan: - continue - case p, ok = <-masterProgressChan: - } - } - - t.mu.Lock() - if ok { - t.lastProgress = p - t.hasLastProgress = true - for _, w := range t.watchers { - select { - case w.signalChan <- struct{}{}: - default: - } - } - } else { - t.broadcastDone = true - } - t.mu.Unlock() - if !ok { - close(t.running) - return - } - } -} - -// Watch adds a watcher to the transfer. The supplied channel gets progress -// updates and is closed when the transfer finishes. -func (t *transfer) Watch(progressOutput progress.Output) *Watcher { - t.mu.Lock() - defer t.mu.Unlock() - - w := &Watcher{ - releaseChan: make(chan struct{}), - signalChan: make(chan struct{}), - running: make(chan struct{}), - } - - t.watchers[w.releaseChan] = w - - if t.broadcastDone { - close(w.running) - return w - } - - go func() { - defer func() { - close(w.running) - }() - var ( - done bool - lastWritten progress.Progress - hasLastWritten bool - ) - for { - t.mu.Lock() - hasLastProgress := t.hasLastProgress - lastProgress := t.lastProgress - t.mu.Unlock() - - // Make sure we don't write the last progress item - // twice. - if hasLastProgress && (!done || !hasLastWritten || lastProgress != lastWritten) { - progressOutput.WriteProgress(lastProgress) - lastWritten = lastProgress - hasLastWritten = true - } - - if done { - return - } - - select { - case <-w.signalChan: - case <-w.releaseChan: - done = true - // Since the watcher is going to detach, make - // sure the broadcaster is caught up so we - // don't miss anything. - select { - case t.broadcastSyncChan <- struct{}{}: - case <-t.running: - } - case <-t.running: - done = true - } - } - }() - - return w -} - -// Release is the inverse of Watch; indicating that the watcher no longer wants -// to be notified about the progress of the transfer. All calls to Watch must -// be paired with later calls to Release so that the lifecycle of the transfer -// is properly managed. -func (t *transfer) Release(watcher *Watcher) { - t.mu.Lock() - delete(t.watchers, watcher.releaseChan) - - if len(t.watchers) == 0 { - if t.closed { - // released may have been closed already if all - // watchers were released, then another one was added - // while waiting for a previous watcher goroutine to - // finish. - select { - case <-t.released: - default: - close(t.released) - } - } else { - t.cancel() - } - } - t.mu.Unlock() - - close(watcher.releaseChan) - // Block until the watcher goroutine completes - <-watcher.running -} - -// Done returns a channel which is closed if the transfer completes or is -// cancelled. Note that having 0 watchers causes a transfer to be cancelled. -func (t *transfer) Done() <-chan struct{} { - // Note that this doesn't return t.ctx.Done() because that channel will - // be closed the moment Cancel is called, and we need to return a - // channel that blocks until a cancellation is actually acknowledged by - // the transfer function. - return t.running -} - -// Released returns a channel which is closed once all watchers release the -// transfer AND the transfer is no longer tracked by the transfer manager. -func (t *transfer) Released() <-chan struct{} { - return t.released -} - -// Context returns the context associated with the transfer. -func (t *transfer) Context() context.Context { - return t.ctx -} - -// Close is called by the transfer manager when the transfer is no longer -// being tracked. -func (t *transfer) Close() { - t.mu.Lock() - t.closed = true - if len(t.watchers) == 0 { - close(t.released) - } - t.mu.Unlock() -} - -// DoFunc is a function called by the transfer manager to actually perform -// a transfer. It should be non-blocking. It should wait until the start channel -// is closed before transferring any data. If the function closes inactive, that -// signals to the transfer manager that the job is no longer actively moving -// data - for example, it may be waiting for a dependent transfer to finish. -// This prevents it from taking up a slot. -type DoFunc func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) Transfer - -// TransferManager is used by LayerDownloadManager and LayerUploadManager to -// schedule and deduplicate transfers. It is up to the TransferManager -// implementation to make the scheduling and concurrency decisions. -type TransferManager interface { - // Transfer checks if a transfer with the given key is in progress. If - // so, it returns progress and error output from that transfer. - // Otherwise, it will call xferFunc to initiate the transfer. - Transfer(key string, xferFunc DoFunc, progressOutput progress.Output) (Transfer, *Watcher) - // SetConcurrency set the concurrencyLimit so that it is adjustable daemon reload - SetConcurrency(concurrency int) -} - -type transferManager struct { - mu sync.Mutex - - concurrencyLimit int - activeTransfers int - transfers map[string]Transfer - waitingTransfers []chan struct{} -} - -// NewTransferManager returns a new TransferManager. -func NewTransferManager(concurrencyLimit int) TransferManager { - return &transferManager{ - concurrencyLimit: concurrencyLimit, - transfers: make(map[string]Transfer), - } -} - -// SetConcurrency set the concurrencyLimit -func (tm *transferManager) SetConcurrency(concurrency int) { - tm.mu.Lock() - tm.concurrencyLimit = concurrency - tm.mu.Unlock() -} - -// Transfer checks if a transfer matching the given key is in progress. If not, -// it starts one by calling xferFunc. The caller supplies a channel which -// receives progress output from the transfer. -func (tm *transferManager) Transfer(key string, xferFunc DoFunc, progressOutput progress.Output) (Transfer, *Watcher) { - tm.mu.Lock() - defer tm.mu.Unlock() - - for { - xfer, present := tm.transfers[key] - if !present { - break - } - // Transfer is already in progress. - watcher := xfer.Watch(progressOutput) - - select { - case <-xfer.Context().Done(): - // We don't want to watch a transfer that has been cancelled. - // Wait for it to be removed from the map and try again. - xfer.Release(watcher) - tm.mu.Unlock() - // The goroutine that removes this transfer from the - // map is also waiting for xfer.Done(), so yield to it. - // This could be avoided by adding a Closed method - // to Transfer to allow explicitly waiting for it to be - // removed the map, but forcing a scheduling round in - // this very rare case seems better than bloating the - // interface definition. - runtime.Gosched() - <-xfer.Done() - tm.mu.Lock() - default: - return xfer, watcher - } - } - - start := make(chan struct{}) - inactive := make(chan struct{}) - - if tm.concurrencyLimit == 0 || tm.activeTransfers < tm.concurrencyLimit { - close(start) - tm.activeTransfers++ - } else { - tm.waitingTransfers = append(tm.waitingTransfers, start) - } - - masterProgressChan := make(chan progress.Progress) - xfer := xferFunc(masterProgressChan, start, inactive) - watcher := xfer.Watch(progressOutput) - go xfer.Broadcast(masterProgressChan) - tm.transfers[key] = xfer - - // When the transfer is finished, remove from the map. - go func() { - for { - select { - case <-inactive: - tm.mu.Lock() - tm.inactivate(start) - tm.mu.Unlock() - inactive = nil - case <-xfer.Done(): - tm.mu.Lock() - if inactive != nil { - tm.inactivate(start) - } - delete(tm.transfers, key) - tm.mu.Unlock() - xfer.Close() - return - } - } - }() - - return xfer, watcher -} - -func (tm *transferManager) inactivate(start chan struct{}) { - // If the transfer was started, remove it from the activeTransfers - // count. - select { - case <-start: - // Start next transfer if any are waiting - if len(tm.waitingTransfers) != 0 { - close(tm.waitingTransfers[0]) - tm.waitingTransfers = tm.waitingTransfers[1:] - } else { - tm.activeTransfers-- - } - default: - } -} diff --git a/vendor/github.com/docker/docker/distribution/xfer/transfer_test.go b/vendor/github.com/docker/docker/distribution/xfer/transfer_test.go deleted file mode 100644 index 6c50ce3..0000000 --- a/vendor/github.com/docker/docker/distribution/xfer/transfer_test.go +++ /dev/null @@ -1,410 +0,0 @@ -package xfer - -import ( - "sync/atomic" - "testing" - "time" - - "github.com/docker/docker/pkg/progress" -) - -func TestTransfer(t *testing.T) { - makeXferFunc := func(id string) DoFunc { - return func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) Transfer { - select { - case <-start: - default: - t.Fatalf("transfer function not started even though concurrency limit not reached") - } - - xfer := NewTransfer() - go func() { - for i := 0; i <= 10; i++ { - progressChan <- progress.Progress{ID: id, Action: "testing", Current: int64(i), Total: 10} - time.Sleep(10 * time.Millisecond) - } - close(progressChan) - }() - return xfer - } - } - - tm := NewTransferManager(5) - progressChan := make(chan progress.Progress) - progressDone := make(chan struct{}) - receivedProgress := make(map[string]int64) - - go func() { - for p := range progressChan { - val, present := receivedProgress[p.ID] - if present && p.Current <= val { - t.Fatalf("got unexpected progress value: %d (expected %d)", p.Current, val+1) - } - receivedProgress[p.ID] = p.Current - } - close(progressDone) - }() - - // Start a few transfers - ids := []string{"id1", "id2", "id3"} - xfers := make([]Transfer, len(ids)) - watchers := make([]*Watcher, len(ids)) - for i, id := range ids { - xfers[i], watchers[i] = tm.Transfer(id, makeXferFunc(id), progress.ChanOutput(progressChan)) - } - - for i, xfer := range xfers { - <-xfer.Done() - xfer.Release(watchers[i]) - } - close(progressChan) - <-progressDone - - for _, id := range ids { - if receivedProgress[id] != 10 { - t.Fatalf("final progress value %d instead of 10", receivedProgress[id]) - } - } -} - -func TestConcurrencyLimit(t *testing.T) { - concurrencyLimit := 3 - var runningJobs int32 - - makeXferFunc := func(id string) DoFunc { - return func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) Transfer { - xfer := NewTransfer() - go func() { - <-start - totalJobs := atomic.AddInt32(&runningJobs, 1) - if int(totalJobs) > concurrencyLimit { - t.Fatalf("too many jobs running") - } - for i := 0; i <= 10; i++ { - progressChan <- progress.Progress{ID: id, Action: "testing", Current: int64(i), Total: 10} - time.Sleep(10 * time.Millisecond) - } - atomic.AddInt32(&runningJobs, -1) - close(progressChan) - }() - return xfer - } - } - - tm := NewTransferManager(concurrencyLimit) - progressChan := make(chan progress.Progress) - progressDone := make(chan struct{}) - receivedProgress := make(map[string]int64) - - go func() { - for p := range progressChan { - receivedProgress[p.ID] = p.Current - } - close(progressDone) - }() - - // Start more transfers than the concurrency limit - ids := []string{"id1", "id2", "id3", "id4", "id5", "id6", "id7", "id8"} - xfers := make([]Transfer, len(ids)) - watchers := make([]*Watcher, len(ids)) - for i, id := range ids { - xfers[i], watchers[i] = tm.Transfer(id, makeXferFunc(id), progress.ChanOutput(progressChan)) - } - - for i, xfer := range xfers { - <-xfer.Done() - xfer.Release(watchers[i]) - } - close(progressChan) - <-progressDone - - for _, id := range ids { - if receivedProgress[id] != 10 { - t.Fatalf("final progress value %d instead of 10", receivedProgress[id]) - } - } -} - -func TestInactiveJobs(t *testing.T) { - concurrencyLimit := 3 - var runningJobs int32 - testDone := make(chan struct{}) - - makeXferFunc := func(id string) DoFunc { - return func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) Transfer { - xfer := NewTransfer() - go func() { - <-start - totalJobs := atomic.AddInt32(&runningJobs, 1) - if int(totalJobs) > concurrencyLimit { - t.Fatalf("too many jobs running") - } - for i := 0; i <= 10; i++ { - progressChan <- progress.Progress{ID: id, Action: "testing", Current: int64(i), Total: 10} - time.Sleep(10 * time.Millisecond) - } - atomic.AddInt32(&runningJobs, -1) - close(inactive) - <-testDone - close(progressChan) - }() - return xfer - } - } - - tm := NewTransferManager(concurrencyLimit) - progressChan := make(chan progress.Progress) - progressDone := make(chan struct{}) - receivedProgress := make(map[string]int64) - - go func() { - for p := range progressChan { - receivedProgress[p.ID] = p.Current - } - close(progressDone) - }() - - // Start more transfers than the concurrency limit - ids := []string{"id1", "id2", "id3", "id4", "id5", "id6", "id7", "id8"} - xfers := make([]Transfer, len(ids)) - watchers := make([]*Watcher, len(ids)) - for i, id := range ids { - xfers[i], watchers[i] = tm.Transfer(id, makeXferFunc(id), progress.ChanOutput(progressChan)) - } - - close(testDone) - for i, xfer := range xfers { - <-xfer.Done() - xfer.Release(watchers[i]) - } - close(progressChan) - <-progressDone - - for _, id := range ids { - if receivedProgress[id] != 10 { - t.Fatalf("final progress value %d instead of 10", receivedProgress[id]) - } - } -} - -func TestWatchRelease(t *testing.T) { - ready := make(chan struct{}) - - makeXferFunc := func(id string) DoFunc { - return func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) Transfer { - xfer := NewTransfer() - go func() { - defer func() { - close(progressChan) - }() - <-ready - for i := int64(0); ; i++ { - select { - case <-time.After(10 * time.Millisecond): - case <-xfer.Context().Done(): - return - } - progressChan <- progress.Progress{ID: id, Action: "testing", Current: i, Total: 10} - } - }() - return xfer - } - } - - tm := NewTransferManager(5) - - type watcherInfo struct { - watcher *Watcher - progressChan chan progress.Progress - progressDone chan struct{} - receivedFirstProgress chan struct{} - } - - progressConsumer := func(w watcherInfo) { - first := true - for range w.progressChan { - if first { - close(w.receivedFirstProgress) - } - first = false - } - close(w.progressDone) - } - - // Start a transfer - watchers := make([]watcherInfo, 5) - var xfer Transfer - watchers[0].progressChan = make(chan progress.Progress) - watchers[0].progressDone = make(chan struct{}) - watchers[0].receivedFirstProgress = make(chan struct{}) - xfer, watchers[0].watcher = tm.Transfer("id1", makeXferFunc("id1"), progress.ChanOutput(watchers[0].progressChan)) - go progressConsumer(watchers[0]) - - // Give it multiple watchers - for i := 1; i != len(watchers); i++ { - watchers[i].progressChan = make(chan progress.Progress) - watchers[i].progressDone = make(chan struct{}) - watchers[i].receivedFirstProgress = make(chan struct{}) - watchers[i].watcher = xfer.Watch(progress.ChanOutput(watchers[i].progressChan)) - go progressConsumer(watchers[i]) - } - - // Now that the watchers are set up, allow the transfer goroutine to - // proceed. - close(ready) - - // Confirm that each watcher gets progress output. - for _, w := range watchers { - <-w.receivedFirstProgress - } - - // Release one watcher every 5ms - for _, w := range watchers { - xfer.Release(w.watcher) - <-time.After(5 * time.Millisecond) - } - - // Now that all watchers have been released, Released() should - // return a closed channel. - <-xfer.Released() - - // Done() should return a closed channel because the xfer func returned - // due to cancellation. - <-xfer.Done() - - for _, w := range watchers { - close(w.progressChan) - <-w.progressDone - } -} - -func TestWatchFinishedTransfer(t *testing.T) { - makeXferFunc := func(id string) DoFunc { - return func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) Transfer { - xfer := NewTransfer() - go func() { - // Finish immediately - close(progressChan) - }() - return xfer - } - } - - tm := NewTransferManager(5) - - // Start a transfer - watchers := make([]*Watcher, 3) - var xfer Transfer - xfer, watchers[0] = tm.Transfer("id1", makeXferFunc("id1"), progress.ChanOutput(make(chan progress.Progress))) - - // Give it a watcher immediately - watchers[1] = xfer.Watch(progress.ChanOutput(make(chan progress.Progress))) - - // Wait for the transfer to complete - <-xfer.Done() - - // Set up another watcher - watchers[2] = xfer.Watch(progress.ChanOutput(make(chan progress.Progress))) - - // Release the watchers - for _, w := range watchers { - xfer.Release(w) - } - - // Now that all watchers have been released, Released() should - // return a closed channel. - <-xfer.Released() -} - -func TestDuplicateTransfer(t *testing.T) { - ready := make(chan struct{}) - - var xferFuncCalls int32 - - makeXferFunc := func(id string) DoFunc { - return func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) Transfer { - atomic.AddInt32(&xferFuncCalls, 1) - xfer := NewTransfer() - go func() { - defer func() { - close(progressChan) - }() - <-ready - for i := int64(0); ; i++ { - select { - case <-time.After(10 * time.Millisecond): - case <-xfer.Context().Done(): - return - } - progressChan <- progress.Progress{ID: id, Action: "testing", Current: i, Total: 10} - } - }() - return xfer - } - } - - tm := NewTransferManager(5) - - type transferInfo struct { - xfer Transfer - watcher *Watcher - progressChan chan progress.Progress - progressDone chan struct{} - receivedFirstProgress chan struct{} - } - - progressConsumer := func(t transferInfo) { - first := true - for range t.progressChan { - if first { - close(t.receivedFirstProgress) - } - first = false - } - close(t.progressDone) - } - - // Try to start multiple transfers with the same ID - transfers := make([]transferInfo, 5) - for i := range transfers { - t := &transfers[i] - t.progressChan = make(chan progress.Progress) - t.progressDone = make(chan struct{}) - t.receivedFirstProgress = make(chan struct{}) - t.xfer, t.watcher = tm.Transfer("id1", makeXferFunc("id1"), progress.ChanOutput(t.progressChan)) - go progressConsumer(*t) - } - - // Allow the transfer goroutine to proceed. - close(ready) - - // Confirm that each watcher gets progress output. - for _, t := range transfers { - <-t.receivedFirstProgress - } - - // Confirm that the transfer function was called exactly once. - if xferFuncCalls != 1 { - t.Fatal("transfer function wasn't called exactly once") - } - - // Release one watcher every 5ms - for _, t := range transfers { - t.xfer.Release(t.watcher) - <-time.After(5 * time.Millisecond) - } - - for _, t := range transfers { - // Now that all watchers have been released, Released() should - // return a closed channel. - <-t.xfer.Released() - // Done() should return a closed channel because the xfer func returned - // due to cancellation. - <-t.xfer.Done() - } - - for _, t := range transfers { - close(t.progressChan) - <-t.progressDone - } -} diff --git a/vendor/github.com/docker/docker/distribution/xfer/upload.go b/vendor/github.com/docker/docker/distribution/xfer/upload.go deleted file mode 100644 index ad33983..0000000 --- a/vendor/github.com/docker/docker/distribution/xfer/upload.go +++ /dev/null @@ -1,168 +0,0 @@ -package xfer - -import ( - "errors" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/progress" - "golang.org/x/net/context" -) - -const maxUploadAttempts = 5 - -// LayerUploadManager provides task management and progress reporting for -// uploads. -type LayerUploadManager struct { - tm TransferManager -} - -// SetConcurrency set the max concurrent uploads for each push -func (lum *LayerUploadManager) SetConcurrency(concurrency int) { - lum.tm.SetConcurrency(concurrency) -} - -// NewLayerUploadManager returns a new LayerUploadManager. -func NewLayerUploadManager(concurrencyLimit int) *LayerUploadManager { - return &LayerUploadManager{ - tm: NewTransferManager(concurrencyLimit), - } -} - -type uploadTransfer struct { - Transfer - - remoteDescriptor distribution.Descriptor - err error -} - -// An UploadDescriptor references a layer that may need to be uploaded. -type UploadDescriptor interface { - // Key returns the key used to deduplicate uploads. - Key() string - // ID returns the ID for display purposes. - ID() string - // DiffID should return the DiffID for this layer. - DiffID() layer.DiffID - // Upload is called to perform the Upload. - Upload(ctx context.Context, progressOutput progress.Output) (distribution.Descriptor, error) - // SetRemoteDescriptor provides the distribution.Descriptor that was - // returned by Upload. This descriptor is not to be confused with - // the UploadDescriptor interface, which is used for internally - // identifying layers that are being uploaded. - SetRemoteDescriptor(descriptor distribution.Descriptor) -} - -// Upload is a blocking function which ensures the listed layers are present on -// the remote registry. It uses the string returned by the Key method to -// deduplicate uploads. -func (lum *LayerUploadManager) Upload(ctx context.Context, layers []UploadDescriptor, progressOutput progress.Output) error { - var ( - uploads []*uploadTransfer - dedupDescriptors = make(map[string]*uploadTransfer) - ) - - for _, descriptor := range layers { - progress.Update(progressOutput, descriptor.ID(), "Preparing") - - key := descriptor.Key() - if _, present := dedupDescriptors[key]; present { - continue - } - - xferFunc := lum.makeUploadFunc(descriptor) - upload, watcher := lum.tm.Transfer(descriptor.Key(), xferFunc, progressOutput) - defer upload.Release(watcher) - uploads = append(uploads, upload.(*uploadTransfer)) - dedupDescriptors[key] = upload.(*uploadTransfer) - } - - for _, upload := range uploads { - select { - case <-ctx.Done(): - return ctx.Err() - case <-upload.Transfer.Done(): - if upload.err != nil { - return upload.err - } - } - } - for _, l := range layers { - l.SetRemoteDescriptor(dedupDescriptors[l.Key()].remoteDescriptor) - } - - return nil -} - -func (lum *LayerUploadManager) makeUploadFunc(descriptor UploadDescriptor) DoFunc { - return func(progressChan chan<- progress.Progress, start <-chan struct{}, inactive chan<- struct{}) Transfer { - u := &uploadTransfer{ - Transfer: NewTransfer(), - } - - go func() { - defer func() { - close(progressChan) - }() - - progressOutput := progress.ChanOutput(progressChan) - - select { - case <-start: - default: - progress.Update(progressOutput, descriptor.ID(), "Waiting") - <-start - } - - retries := 0 - for { - remoteDescriptor, err := descriptor.Upload(u.Transfer.Context(), progressOutput) - if err == nil { - u.remoteDescriptor = remoteDescriptor - break - } - - // If an error was returned because the context - // was cancelled, we shouldn't retry. - select { - case <-u.Transfer.Context().Done(): - u.err = err - return - default: - } - - retries++ - if _, isDNR := err.(DoNotRetry); isDNR || retries == maxUploadAttempts { - logrus.Errorf("Upload failed: %v", err) - u.err = err - return - } - - logrus.Errorf("Upload failed, retrying: %v", err) - delay := retries * 5 - ticker := time.NewTicker(time.Second) - - selectLoop: - for { - progress.Updatef(progressOutput, descriptor.ID(), "Retrying in %d second%s", delay, (map[bool]string{true: "s"})[delay != 1]) - select { - case <-ticker.C: - delay-- - if delay == 0 { - ticker.Stop() - break selectLoop - } - case <-u.Transfer.Context().Done(): - ticker.Stop() - u.err = errors.New("upload cancelled during retry delay") - return - } - } - } - }() - - return u - } -} diff --git a/vendor/github.com/docker/docker/distribution/xfer/upload_test.go b/vendor/github.com/docker/docker/distribution/xfer/upload_test.go deleted file mode 100644 index 16bd187..0000000 --- a/vendor/github.com/docker/docker/distribution/xfer/upload_test.go +++ /dev/null @@ -1,134 +0,0 @@ -package xfer - -import ( - "errors" - "sync/atomic" - "testing" - "time" - - "github.com/docker/distribution" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/progress" - "golang.org/x/net/context" -) - -const maxUploadConcurrency = 3 - -type mockUploadDescriptor struct { - currentUploads *int32 - diffID layer.DiffID - simulateRetries int -} - -// Key returns the key used to deduplicate downloads. -func (u *mockUploadDescriptor) Key() string { - return u.diffID.String() -} - -// ID returns the ID for display purposes. -func (u *mockUploadDescriptor) ID() string { - return u.diffID.String() -} - -// DiffID should return the DiffID for this layer. -func (u *mockUploadDescriptor) DiffID() layer.DiffID { - return u.diffID -} - -// SetRemoteDescriptor is not used in the mock. -func (u *mockUploadDescriptor) SetRemoteDescriptor(remoteDescriptor distribution.Descriptor) { -} - -// Upload is called to perform the upload. -func (u *mockUploadDescriptor) Upload(ctx context.Context, progressOutput progress.Output) (distribution.Descriptor, error) { - if u.currentUploads != nil { - defer atomic.AddInt32(u.currentUploads, -1) - - if atomic.AddInt32(u.currentUploads, 1) > maxUploadConcurrency { - return distribution.Descriptor{}, errors.New("concurrency limit exceeded") - } - } - - // Sleep a bit to simulate a time-consuming upload. - for i := int64(0); i <= 10; i++ { - select { - case <-ctx.Done(): - return distribution.Descriptor{}, ctx.Err() - case <-time.After(10 * time.Millisecond): - progressOutput.WriteProgress(progress.Progress{ID: u.ID(), Current: i, Total: 10}) - } - } - - if u.simulateRetries != 0 { - u.simulateRetries-- - return distribution.Descriptor{}, errors.New("simulating retry") - } - - return distribution.Descriptor{}, nil -} - -func uploadDescriptors(currentUploads *int32) []UploadDescriptor { - return []UploadDescriptor{ - &mockUploadDescriptor{currentUploads, layer.DiffID("sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"), 0}, - &mockUploadDescriptor{currentUploads, layer.DiffID("sha256:1515325234325236634634608943609283523908626098235490238423902343"), 0}, - &mockUploadDescriptor{currentUploads, layer.DiffID("sha256:6929356290463485374960346430698374523437683470934634534953453453"), 0}, - &mockUploadDescriptor{currentUploads, layer.DiffID("sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"), 0}, - &mockUploadDescriptor{currentUploads, layer.DiffID("sha256:8159352387436803946235346346368745389534789534897538734598734987"), 1}, - &mockUploadDescriptor{currentUploads, layer.DiffID("sha256:4637863963478346897346987346987346789346789364879364897364987346"), 0}, - } -} - -func TestSuccessfulUpload(t *testing.T) { - lum := NewLayerUploadManager(maxUploadConcurrency) - - progressChan := make(chan progress.Progress) - progressDone := make(chan struct{}) - receivedProgress := make(map[string]int64) - - go func() { - for p := range progressChan { - receivedProgress[p.ID] = p.Current - } - close(progressDone) - }() - - var currentUploads int32 - descriptors := uploadDescriptors(¤tUploads) - - err := lum.Upload(context.Background(), descriptors, progress.ChanOutput(progressChan)) - if err != nil { - t.Fatalf("upload error: %v", err) - } - - close(progressChan) - <-progressDone -} - -func TestCancelledUpload(t *testing.T) { - lum := NewLayerUploadManager(maxUploadConcurrency) - - progressChan := make(chan progress.Progress) - progressDone := make(chan struct{}) - - go func() { - for range progressChan { - } - close(progressDone) - }() - - ctx, cancel := context.WithCancel(context.Background()) - - go func() { - <-time.After(time.Millisecond) - cancel() - }() - - descriptors := uploadDescriptors(nil) - err := lum.Upload(ctx, descriptors, progress.ChanOutput(progressChan)) - if err != context.Canceled { - t.Fatal("expected upload to be cancelled") - } - - close(progressChan) - <-progressDone -} diff --git a/vendor/github.com/docker/docker/dockerversion/useragent.go b/vendor/github.com/docker/docker/dockerversion/useragent.go deleted file mode 100644 index d2a891c..0000000 --- a/vendor/github.com/docker/docker/dockerversion/useragent.go +++ /dev/null @@ -1,74 +0,0 @@ -package dockerversion - -import ( - "fmt" - "runtime" - - "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/pkg/parsers/kernel" - "github.com/docker/docker/pkg/useragent" - "golang.org/x/net/context" -) - -// DockerUserAgent is the User-Agent the Docker client uses to identify itself. -// In accordance with RFC 7231 (5.5.3) is of the form: -// [docker client's UA] UpstreamClient([upstream client's UA]) -func DockerUserAgent(ctx context.Context) string { - httpVersion := make([]useragent.VersionInfo, 0, 6) - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "docker", Version: Version}) - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "go", Version: runtime.Version()}) - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "git-commit", Version: GitCommit}) - if kernelVersion, err := kernel.GetKernelVersion(); err == nil { - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "kernel", Version: kernelVersion.String()}) - } - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "os", Version: runtime.GOOS}) - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "arch", Version: runtime.GOARCH}) - - dockerUA := useragent.AppendVersions("", httpVersion...) - upstreamUA := getUserAgentFromContext(ctx) - if len(upstreamUA) > 0 { - ret := insertUpstreamUserAgent(upstreamUA, dockerUA) - return ret - } - return dockerUA -} - -// getUserAgentFromContext returns the previously saved user-agent context stored in ctx, if one exists -func getUserAgentFromContext(ctx context.Context) string { - var upstreamUA string - if ctx != nil { - var ki interface{} = ctx.Value(httputils.UAStringKey) - if ki != nil { - upstreamUA = ctx.Value(httputils.UAStringKey).(string) - } - } - return upstreamUA -} - -// escapeStr returns s with every rune in charsToEscape escaped by a backslash -func escapeStr(s string, charsToEscape string) string { - var ret string - for _, currRune := range s { - appended := false - for _, escapeableRune := range charsToEscape { - if currRune == escapeableRune { - ret += `\` + string(currRune) - appended = true - break - } - } - if !appended { - ret += string(currRune) - } - } - return ret -} - -// insertUpstreamUserAgent adds the upstream client useragent to create a user-agent -// string of the form: -// $dockerUA UpstreamClient($upstreamUA) -func insertUpstreamUserAgent(upstreamUA string, dockerUA string) string { - charsToEscape := `();\` - upstreamUAEscaped := escapeStr(upstreamUA, charsToEscape) - return fmt.Sprintf("%s UpstreamClient(%s)", dockerUA, upstreamUAEscaped) -} diff --git a/vendor/github.com/docker/docker/dockerversion/version_lib.go b/vendor/github.com/docker/docker/dockerversion/version_lib.go deleted file mode 100644 index 33f77d3..0000000 --- a/vendor/github.com/docker/docker/dockerversion/version_lib.go +++ /dev/null @@ -1,16 +0,0 @@ -// +build !autogen - -// Package dockerversion is auto-generated at build-time -package dockerversion - -// Default build-time variable for library-import. -// This file is overridden on build with build-time informations. -const ( - GitCommit string = "library-import" - Version string = "library-import" - BuildTime string = "library-import" - IAmStatic string = "library-import" - ContainerdCommitID string = "library-import" - RuncCommitID string = "library-import" - InitCommitID string = "library-import" -) diff --git a/vendor/github.com/docker/docker/docs/README.md b/vendor/github.com/docker/docker/docs/README.md deleted file mode 100644 index da93093..0000000 --- a/vendor/github.com/docker/docker/docs/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# The non-reference docs have been moved! - - - -The documentation for Docker Engine has been merged into -[the general documentation repo](https://github.com/docker/docker.github.io). - -See the [README](https://github.com/docker/docker.github.io/blob/master/README.md) -for instructions on contributing to and building the documentation. - -If you'd like to edit the current published version of the Engine docs, -do it in the master branch here: -https://github.com/docker/docker.github.io/tree/master/engine - -If you need to document the functionality of an upcoming Engine release, -use the `vnext-engine` branch: -https://github.com/docker/docker.github.io/tree/vnext-engine/engine - -The reference docs have been left in docker/docker (this repo), which remains -the place to edit them. - -The docs in the general repo are open-source and we appreciate -your feedback and pull requests! diff --git a/vendor/github.com/docker/docker/docs/api/v1.18.md b/vendor/github.com/docker/docker/docs/api/v1.18.md deleted file mode 100644 index 0db0c0f..0000000 --- a/vendor/github.com/docker/docker/docs/api/v1.18.md +++ /dev/null @@ -1,2156 +0,0 @@ ---- -title: "Engine API v1.18" -description: "API Documentation for Docker" -keywords: "API, Docker, rcli, REST, documentation" -redirect_from: -- /engine/reference/api/docker_remote_api_v1.18/ -- /reference/api/docker_remote_api_v1.18/ ---- - - - -## 1. Brief introduction - - - The daemon listens on `unix:///var/run/docker.sock` but you can - [Bind Docker to another host/port or a Unix socket](../reference/commandline/dockerd.md#bind-docker-to-another-host-port-or-a-unix-socket). - - The API tends to be REST, but for some complex commands, like `attach` - or `pull`, the HTTP connection is hijacked to transport `STDOUT`, - `STDIN` and `STDERR`. - -## 2. Endpoints - -### 2.1 Containers - -#### List containers - -`GET /containers/json` - -List containers - -**Example request**: - - GET /v1.18/containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "8dfafdbc3a40", - "Names":["/boring_feynman"], - "Image": "ubuntu:latest", - "Command": "echo 1", - "Created": 1367854155, - "Status": "Exit 0", - "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}], - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "SizeRw": 12288, - "SizeRootFs": 0 - }, - { - "Id": "9cd87474be90", - "Names":["/coolName"], - "Image": "ubuntu:latest", - "Command": "echo 222222", - "Created": 1367854155, - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0 - }, - { - "Id": "3176a2479c92", - "Names":["/sleepy_dog"], - "Image": "ubuntu:latest", - "Command": "echo 3333333333333333", - "Created": 1367854154, - "Status": "Exit 0", - "Ports":[], - "Labels": {}, - "SizeRw":12288, - "SizeRootFs":0 - }, - { - "Id": "4cb07b47f9fb", - "Names":["/running_cat"], - "Image": "ubuntu:latest", - "Command": "echo 444444444444444444444444444444444", - "Created": 1367854152, - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0 - } - ] - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, Show all containers. - Only running containers are shown by default (i.e., this defaults to false) -- **limit** – Show `limit` last created - containers, include non-running ones. -- **since** – Show only containers created since Id, include - non-running ones. -- **before** – Show only containers created before Id, include - non-running ones. -- **size** – 1/True/true or 0/False/false, Show the containers - sizes -- **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: - - `exited=`; -- containers with exit code of `` ; - - `status=`(`restarting`|`running`|`paused`|`exited`) - - `label=key` or `label="key=value"` of a container label - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **500** – server error - -#### Create a container - -`POST /containers/create` - -Create a container - -**Example request**: - - POST /v1.18/containers/create HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": [ - "FOO=bar", - "BAZ=quux" - ], - "Cmd": [ - "date" - ], - "Entrypoint": null, - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "/volumes/data": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "HostConfig": { - "Binds": ["/tmp:/tmp"], - "Links": ["redis3:redis"], - "LxcConf": {"lxc.utsname":"docker"}, - "Memory": 0, - "MemorySwap": 0, - "CpuShares": 512, - "CpusetCpus": "0,1", - "PidMode": "", - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsSearch": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [], - "CgroupParent": "" - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id":"e90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **Hostname** - A string value containing the hostname to use for the - container. -- **Domainname** - A string value containing the domain name to use - for the container. -- **User** - A string value specifying the user inside the container. -- **AttachStdin** - Boolean value, attaches to `stdin`. -- **AttachStdout** - Boolean value, attaches to `stdout`. -- **AttachStderr** - Boolean value, attaches to `stderr`. -- **Tty** - Boolean value, Attach standard streams to a `tty`, including `stdin` if it is not closed. -- **OpenStdin** - Boolean value, opens `stdin`, -- **StdinOnce** - Boolean value, close `stdin` after the 1 attached client disconnects. -- **Env** - A list of environment variables in the form of `["VAR=value", ...]` -- **Labels** - Adds a map of labels to a container. To specify a map: `{"key":"value", ... }` -- **Cmd** - Command to run specified as a string or an array of strings. -- **Entrypoint** - Set the entry point for the container as a string or an array - of strings. -- **Image** - A string specifying the image name to use for the container. -- **Volumes** - An object mapping mount point paths (strings) inside the - container to empty objects. -- **WorkingDir** - A string specifying the working directory for commands to - run in. -- **NetworkDisabled** - Boolean value, when true disables networking for the - container -- **ExposedPorts** - An object mapping ports to an empty object in the form of: - `"ExposedPorts": { "/: {}" }` -- **HostConfig** - - **Binds** – A list of bind-mounts for this container. Each item is a string in one of these forms: - + `host-src:container-dest` to bind-mount a host path into the - container. Both `host-src`, and `container-dest` must be an - _absolute_ path. - + `host-src:container-dest:ro` to make the bind-mount read-only - inside the container. Both `host-src`, and `container-dest` must be - an _absolute_ path. - - **Links** - A list of links for the container. Each link entry should be - in the form of `container_name:alias`. - - **LxcConf** - LXC specific configurations. These configurations only - work when using the `lxc` execution driver. - - **Memory** - Memory limit in bytes. - - **MemorySwap** - Total memory limit (memory + swap); set `-1` to enable unlimited swap. - You must use this with `memory` and make the swap value larger than `memory`. - - **CpuShares** - An integer value containing the container's CPU Shares - (ie. the relative weight vs other containers). - - **CpusetCpus** - String value containing the `cgroups CpusetCpus` to use. - - **PidMode** - Set the PID (Process) Namespace mode for the container; - `"container:"`: joins another container's PID namespace - `"host"`: use the host's PID namespace inside the container - - **PortBindings** - A map of exposed container ports and the host port they - should map to. A JSON object in the form - `{ /: [{ "HostPort": "" }] }` - Take note that `port` is specified as a string and not an integer value. - - **PublishAllPorts** - Allocates a random host port for all of a container's - exposed ports. Specified as a boolean value. - - **Privileged** - Gives the container full access to the host. Specified as - a boolean value. - - **ReadonlyRootfs** - Mount the container's root filesystem as read only. - Specified as a boolean value. - - **Dns** - A list of DNS servers for the container to use. - - **DnsSearch** - A list of DNS search domains - - **ExtraHosts** - A list of hostnames/IP mappings to add to the - container's `/etc/hosts` file. Specified in the form `["hostname:IP"]`. - - **VolumesFrom** - A list of volumes to inherit from another container. - Specified in the form `[:]` - - **CapAdd** - A list of kernel capabilities to add to the container. - - **Capdrop** - A list of kernel capabilities to drop from the container. - - **RestartPolicy** – The behavior to apply when the container exits. The - value is an object with a `Name` property of either `"always"` to - always restart or `"on-failure"` to restart only when the container - exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` - controls the number of times to retry before giving up. - The default is not to restart. (optional) - An ever increasing delay (double the previous delay, starting at 100mS) - is added before each restart to prevent flooding the server. - - **NetworkMode** - Sets the networking mode for the container. Supported - values are: `bridge`, `host`, `none`, and `container:` - - **Devices** - A list of devices to add to the container specified as a JSON object in the - form - `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` - - **Ulimits** - A list of ulimits to set in the container, specified as - `{ "Name": , "Soft": , "Hard": }`, for example: - `Ulimits: { "Name": "nofile", "Soft": 1024, "Hard": 2048 }` - - **SecurityOpt**: A list of string values to customize labels for MLS - systems, such as SELinux. - - **LogConfig** - Log configuration for the container, specified as a JSON object in the form - `{ "Type": "", "Config": {"key1": "val1"}}`. - Available types: `json-file`, `syslog`, `journald`, `none`. - `json-file` logging driver. - - **CgroupParent** - Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist. - -**Query parameters**: - -- **name** – Assign the specified name to the container. Must - match `/?[a-zA-Z0-9_-]+`. - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such container -- **406** – impossible to attach (container not running) -- **409** – conflict -- **500** – server error - -#### Inspect a container - -`GET /containers/(id or name)/json` - -Return low-level information on the container `id` - -**Example request**: - - GET /v1.18/containers/4fa6e0f0c678/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "AppArmorProfile": "", - "Args": [ - "-c", - "exit 9" - ], - "Config": { - "AttachStderr": true, - "AttachStdin": false, - "AttachStdout": true, - "Cmd": [ - "/bin/sh", - "-c", - "exit 9" - ], - "Domainname": "", - "Entrypoint": null, - "Env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts": null, - "Hostname": "ba033ac44011", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "MacAddress": "", - "NetworkDisabled": false, - "OnBuild": null, - "OpenStdin": false, - "PortSpecs": null, - "StdinOnce": false, - "Tty": false, - "User": "", - "Volumes": null, - "WorkingDir": "" - }, - "Created": "2015-01-06T15:47:31.485331387Z", - "Driver": "devicemapper", - "ExecDriver": "native-0.2", - "ExecIDs": null, - "HostConfig": { - "Binds": null, - "CapAdd": null, - "CapDrop": null, - "ContainerIDFile": "", - "CpusetCpus": "", - "CpuShares": 0, - "Devices": [], - "Dns": null, - "DnsSearch": null, - "ExtraHosts": null, - "IpcMode": "", - "Links": null, - "LxcConf": [], - "Memory": 0, - "MemorySwap": 0, - "NetworkMode": "bridge", - "PidMode": "", - "PortBindings": {}, - "Privileged": false, - "ReadonlyRootfs": false, - "PublishAllPorts": false, - "RestartPolicy": { - "MaximumRetryCount": 2, - "Name": "on-failure" - }, - "LogConfig": { - "Config": null, - "Type": "json-file" - }, - "SecurityOpt": null, - "VolumesFrom": null, - "Ulimits": [{}] - }, - "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname", - "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39", - "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2", - "MountLabel": "", - "Name": "/boring_euclid", - "NetworkSettings": { - "Bridge": "", - "Gateway": "", - "IPAddress": "", - "IPPrefixLen": 0, - "MacAddress": "", - "PortMapping": null, - "Ports": null - }, - "Path": "/bin/sh", - "ProcessLabel": "", - "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf", - "RestartCount": 1, - "State": { - "Error": "", - "ExitCode": 9, - "FinishedAt": "2015-01-06T15:47:32.080254511Z", - "OOMKilled": false, - "Paused": false, - "Pid": 0, - "Restarting": false, - "Running": true, - "StartedAt": "2015-01-06T15:47:32.072697474Z" - }, - "Volumes": {}, - "VolumesRW": {} - } - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### List processes running inside a container - -`GET /containers/(id or name)/top` - -List processes running inside the container `id`. On Unix systems this -is done by running the `ps` command. This endpoint is not -supported on Windows. - -**Example request**: - - GET /v1.18/containers/4fa6e0f0c678/top HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD" - ], - "Processes" : [ - [ - "root", "13642", "882", "0", "17:03", "pts/0", "00:00:00", "/bin/bash" - ], - [ - "root", "13735", "13642", "0", "17:06", "pts/0", "00:00:00", "sleep 10" - ] - ] - } - -**Example request**: - - GET /v1.18/containers/4fa6e0f0c678/top?ps_args=aux HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND" - ] - "Processes" : [ - [ - "root","13642","0.0","0.1","18172","3184","pts/0","Ss","17:03","0:00","/bin/bash" - ], - [ - "root","13895","0.0","0.0","4348","692","pts/0","S+","17:15","0:00","sleep 10" - ] - ], - } - -**Query parameters**: - -- **ps_args** – `ps` arguments to use (e.g., `aux`), defaults to `-ef` - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container logs - -`GET /containers/(id or name)/logs` - -Get `stdout` and `stderr` logs from the container ``id`` - -> **Note**: -> This endpoint works only for containers with the `json-file` or `journald` logging drivers. - -**Example request**: - - GET /v1.18/containers/4fa6e0f0c678/logs?stderr=1&stdout=1×tamps=1&follow=1&tail=10 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **follow** – 1/True/true or 0/False/false, return stream. Default `false`. -- **stdout** – 1/True/true or 0/False/false, show `stdout` log. Default `false`. -- **stderr** – 1/True/true or 0/False/false, show `stderr` log. Default `false`. -- **timestamps** – 1/True/true or 0/False/false, print timestamps for - every log line. Default `false`. -- **tail** – Output specified number of lines at the end of logs: `all` or ``. Default all. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **404** – no such container -- **500** – server error - -#### Inspect changes on a container's filesystem - -`GET /containers/(id or name)/changes` - -Inspect changes on container `id`'s filesystem - -**Example request**: - - GET /v1.18/containers/4fa6e0f0c678/changes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Path": "/dev", - "Kind": 0 - }, - { - "Path": "/dev/kmsg", - "Kind": 1 - }, - { - "Path": "/test", - "Kind": 1 - } - ] - -Values for `Kind`: - -- `0`: Modify -- `1`: Add -- `2`: Delete - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Export a container - -`GET /containers/(id or name)/export` - -Export the contents of container `id` - -**Example request**: - - GET /v1.18/containers/4fa6e0f0c678/export HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/octet-stream - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container stats based on resource usage - -`GET /containers/(id or name)/stats` - -This endpoint returns a live stream of a container's resource usage statistics. - -**Example request**: - - GET /v1.18/containers/redis1/stats HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "read" : "2015-01-08T22:57:31.547920715Z", - "network" : { - "rx_dropped" : 0, - "rx_bytes" : 648, - "rx_errors" : 0, - "tx_packets" : 8, - "tx_dropped" : 0, - "rx_packets" : 8, - "tx_errors" : 0, - "tx_bytes" : 648 - }, - "memory_stats" : { - "stats" : { - "total_pgmajfault" : 0, - "cache" : 0, - "mapped_file" : 0, - "total_inactive_file" : 0, - "pgpgout" : 414, - "rss" : 6537216, - "total_mapped_file" : 0, - "writeback" : 0, - "unevictable" : 0, - "pgpgin" : 477, - "total_unevictable" : 0, - "pgmajfault" : 0, - "total_rss" : 6537216, - "total_rss_huge" : 6291456, - "total_writeback" : 0, - "total_inactive_anon" : 0, - "rss_huge" : 6291456, - "hierarchical_memory_limit" : 67108864, - "total_pgfault" : 964, - "total_active_file" : 0, - "active_anon" : 6537216, - "total_active_anon" : 6537216, - "total_pgpgout" : 414, - "total_cache" : 0, - "inactive_anon" : 0, - "active_file" : 0, - "pgfault" : 964, - "inactive_file" : 0, - "total_pgpgin" : 477 - }, - "max_usage" : 6651904, - "usage" : 6537216, - "failcnt" : 0, - "limit" : 67108864 - }, - "blkio_stats" : {}, - "cpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 16970827, - 1839451, - 7107380, - 10571290 - ], - "usage_in_usermode" : 10000000, - "total_usage" : 36488948, - "usage_in_kernelmode" : 20000000 - }, - "system_cpu_usage" : 20091722000000000, - "throttling_data" : {} - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Resize a container TTY - -`POST /containers/(id or name)/resize?h=&w=` - -Resize the TTY for container with `id`. You must restart the container for the resize to take effect. - -**Example request**: - - POST /v1.18/containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **200** – no error -- **404** – No such container -- **500** – Cannot resize container - -#### Start a container - -`POST /containers/(id or name)/start` - -Start the container `id` - -> **Note**: -> For backwards compatibility, this endpoint accepts a `HostConfig` as JSON-encoded request body. -> See [create a container](#create-a-container) for details. - -**Example request**: - - POST /v1.18/containers/e90e34656806/start HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **304** – container already started -- **404** – no such container -- **500** – server error - -#### Stop a container - -`POST /containers/(id or name)/stop` - -Stop the container `id` - -**Example request**: - - POST /v1.18/containers/e90e34656806/stop?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **304** – container already stopped -- **404** – no such container -- **500** – server error - -#### Restart a container - -`POST /containers/(id or name)/restart` - -Restart the container `id` - -**Example request**: - - POST /v1.18/containers/e90e34656806/restart?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Kill a container - -`POST /containers/(id or name)/kill` - -Kill the container `id` - -**Example request**: - - POST /v1.18/containers/e90e34656806/kill HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **signal** - Signal to send to the container: integer or string like `SIGINT`. - When not set, `SIGKILL` is assumed and the call waits for the container to exit. - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Rename a container - -`POST /containers/(id or name)/rename` - -Rename the container `id` to a `new_name` - -**Example request**: - - POST /v1.18/containers/e90e34656806/rename?name=new_name HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **name** – new name for the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **409** - conflict name already assigned -- **500** – server error - -#### Pause a container - -`POST /containers/(id or name)/pause` - -Pause the container `id` - -**Example request**: - - POST /v1.18/containers/e90e34656806/pause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Unpause a container - -`POST /containers/(id or name)/unpause` - -Unpause the container `id` - -**Example request**: - - POST /v1.18/containers/e90e34656806/unpause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Attach to a container - -`POST /containers/(id or name)/attach` - -Attach to the container `id` - -**Example request**: - - POST /v1.18/containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -**Stream details**: - -When using the TTY setting is enabled in -[`POST /containers/create` -](#create-a-container), -the stream is the raw data from the process PTY and client's `stdin`. -When the TTY is disabled, then the stream is multiplexed to separate -`stdout` and `stderr`. - -The format is a **Header** and a **Payload** (frame). - -**HEADER** - -The header contains the information which the stream writes (`stdout` or -`stderr`). It also contains the size of the associated frame encoded in the -last four bytes (`uint32`). - -It is encoded on the first eight bytes like this: - - header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} - -`STREAM_TYPE` can be: - -- 0: `stdin` (is written on `stdout`) -- 1: `stdout` -- 2: `stderr` - -`SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of -the `uint32` size encoded as big endian. - -**PAYLOAD** - -The payload is the raw stream. - -**IMPLEMENTATION** - -The simplest way to implement the Attach protocol is the following: - - 1. Read eight bytes. - 2. Choose `stdout` or `stderr` depending on the first byte. - 3. Extract the frame size from the last four bytes. - 4. Read the extracted size and output it on the correct output. - 5. Goto 1. - -#### Attach to a container (websocket) - -`GET /containers/(id or name)/attach/ws` - -Attach to the container `id` via websocket - -Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455) - -**Example request** - - GET /v1.18/containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 - -**Example response** - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -#### Wait a container - -`POST /containers/(id or name)/wait` - -Block until container `id` stops, then returns the exit code - -**Example request**: - - POST /v1.18/containers/16253994b7c4/wait HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"StatusCode": 0} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Remove a container - -`DELETE /containers/(id or name)` - -Remove the container `id` from the filesystem - -**Example request**: - - DELETE /v1.18/containers/16253994b7c4?v=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **v** – 1/True/true or 0/False/false, Remove the volumes - associated to the container. Default `false`. -- **force** - 1/True/true or 0/False/false, Kill then remove the container. - Default `false`. - -**Status codes**: - -- **204** – no error -- **400** – bad parameter -- **404** – no such container -- **409** – conflict -- **500** – server error - -#### Copy files or folders from a container - -`POST /containers/(id or name)/copy` - -Copy files or folders of container `id` - -**Example request**: - - POST /v1.18/containers/4fa6e0f0c678/copy HTTP/1.1 - Content-Type: application/json - - { - "Resource": "test.txt" - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -### 2.2 Images - -#### List Images - -`GET /images/json` - -**Example request**: - - GET /v1.18/images/json?all=0 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "RepoTags": [ - "ubuntu:12.04", - "ubuntu:precise", - "ubuntu:latest" - ], - "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", - "Created": 1365714795, - "Size": 131506275, - "VirtualSize": 131506275 - }, - { - "RepoTags": [ - "ubuntu:12.10", - "ubuntu:quantal" - ], - "ParentId": "27cf784147099545", - "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "Created": 1364102658, - "Size": 24653, - "VirtualSize": 180116135 - } - ] - -**Example request, with digest information**: - - GET /v1.18/images/json?digests=1 HTTP/1.1 - -**Example response, with digest information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Created": 1420064636, - "Id": "4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125", - "ParentId": "ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2", - "RepoDigests": [ - "localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags": [ - "localhost:5000/test/busybox:latest", - "playdate:latest" - ], - "Size": 0, - "VirtualSize": 2429728 - } - ] - -The response shows a single image `Id` associated with two repositories -(`RepoTags`): `localhost:5000/test/busybox`: and `playdate`. A caller can use -either of the `RepoTags` values `localhost:5000/test/busybox:latest` or -`playdate:latest` to reference the image. - -You can also use `RepoDigests` values to reference an image. In this response, -the array has only one reference and that is to the -`localhost:5000/test/busybox` repository; the `playdate` repository has no -digest. You can reference this digest using the value: -`localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d...` - -See the `docker run` and `docker build` commands for examples of digest and tag -references on the command line. - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, default false -- **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: - - `dangling=true` - - `label=key` or `label="key=value"` of an image label -- **filter** - only return images with the specified name - -#### Build image from a Dockerfile - -`POST /build` - -Build an image from a Dockerfile - -**Example request**: - - POST /v1.18/build HTTP/1.1 - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"stream": "Step 1/5..."} - {"stream": "..."} - {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} - -The input stream must be a `tar` archive compressed with one of the -following algorithms: `identity` (no compression), `gzip`, `bzip2`, `xz`. - -The archive must include a build instructions file, typically called -`Dockerfile` at the archive's root. The `dockerfile` parameter may be -used to specify a different build instructions file. To do this, its value must be -the path to the alternate build instructions file to use. - -The archive may include any number of other files, -which are accessible in the build context (See the [*ADD build -command*](../reference/builder.md#add)). - -The Docker daemon performs a preliminary validation of the `Dockerfile` before -starting the build, and returns an error if the syntax is incorrect. After that, -each instruction is run one-by-one until the ID of the new image is output. - -The build is canceled if the client drops the connection by quitting -or being killed. - -**Query parameters**: - -- **dockerfile** - Path within the build context to the Dockerfile. This is - ignored if `remote` is specified and points to an individual filename. -- **t** – A name and optional tag to apply to the image in the `name:tag` format. - If you omit the `tag` the default `latest` value is assumed. -- **remote** – A Git repository URI or HTTP/HTTPS context URI. If the - URI points to a single text file, the file's contents are placed into - a file called `Dockerfile` and the image is built from that file. -- **q** – Suppress verbose build output. -- **nocache** – Do not use the cache when building the image. -- **pull** - Attempt to pull the image even if an older image exists locally. -- **rm** - Remove intermediate containers after a successful build (default behavior). -- **forcerm** - Always remove intermediate containers (includes `rm`). -- **memory** - Set memory limit for build. -- **memswap** - Total memory (memory + swap), `-1` to enable unlimited swap. -- **cpushares** - CPU shares (relative weight). -- **cpusetcpus** - CPUs in which to allow execution (e.g., `0-3`, `0,1`). - -**Request Headers**: - -- **Content-type** – Set to `"application/tar"`. -- **X-Registry-Config** – base64-encoded ConfigFile object - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Create an image - -`POST /images/create` - -Create an image either by pulling it from the registry or by importing it - -**Example request**: - - POST /v1.18/images/create?fromImage=busybox&tag=latest HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pulling..."} - {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} - {"error": "Invalid..."} - ... - -When using this endpoint to pull an image from the registry, the -`X-Registry-Auth` header can be used to include -a base64-encoded AuthConfig object. - -**Query parameters**: - -- **fromImage** – Name of the image to pull. -- **fromSrc** – Source to import. The value may be a URL from which the image - can be retrieved or `-` to read the image from the request body. -- **repo** – Repository name. -- **tag** – Tag. If empty when pulling an image, this causes all tags - for the given image to be pulled. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object - -**Status codes**: - -- **200** – no error -- **404** - repository does not exist or no read access -- **500** – server error - - - -#### Inspect an image - -`GET /images/(name)/json` - -Return low-level information on the image `name` - -**Example request**: - - GET /v1.18/images/ubuntu/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Created": "2013-03-23T22:24:18.818426-07:00", - "Container": "3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", - "ContainerConfig": { - "Hostname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": false, - "AttachStderr": false, - "Tty": true, - "OpenStdin": true, - "StdinOnce": false, - "Env": null, - "Cmd": ["/bin/bash"], - "Dns": null, - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": null, - "VolumesFrom": "", - "WorkingDir": "" - }, - "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "Parent": "27cf784147099545", - "Size": 6824592 - } - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Get the history of an image - -`GET /images/(name)/history` - -Return the history of the image `name` - -**Example request**: - - GET /v1.18/images/ubuntu/history HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "b750fe79269d", - "Created": 1364102658, - "CreatedBy": "/bin/bash" - }, - { - "Id": "27cf78414709", - "Created": 1364068391, - "CreatedBy": "" - } - ] - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Push an image on the registry - -`POST /images/(name)/push` - -Push the image `name` on the registry - -**Example request**: - - POST /v1.18/images/test/push HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pushing..."} - {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} - {"error": "Invalid..."} - ... - -If you wish to push an image on to a private registry, that image must already have a tag -into a repository which references that registry `hostname` and `port`. This repository name should -then be used in the URL. This duplicates the command line's flow. - -**Example request**: - - POST /v1.18/images/registry.acme.com:5000/test/push HTTP/1.1 - - -**Query parameters**: - -- **tag** – The tag to associate with the image on the registry. This is optional. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object. - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Tag an image into a repository - -`POST /images/(name)/tag` - -Tag the image `name` into a repository - -**Example request**: - - POST /v1.18/images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 - -**Example response**: - - HTTP/1.1 201 Created - -**Query parameters**: - -- **repo** – The repository to tag in -- **force** – 1/True/true or 0/False/false, default false -- **tag** - The new tag name - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Remove an image - -`DELETE /images/(name)` - -Remove the image `name` from the filesystem - -**Example request**: - - DELETE /v1.18/images/test HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-type: application/json - - [ - {"Untagged": "3e2f21a89f"}, - {"Deleted": "3e2f21a89f"}, - {"Deleted": "53b4f83ac9"} - ] - -**Query parameters**: - -- **force** – 1/True/true or 0/False/false, default false -- **noprune** – 1/True/true or 0/False/false, default false - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Search images - -`GET /images/search` - -Search for an image on [Docker Hub](https://hub.docker.com). - -> **Note**: -> The response keys have changed from API v1.6 to reflect the JSON -> sent by the registry server to the docker daemon's request. - -**Example request**: - - GET /v1.18/images/search?term=sshd HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "star_count": 12, - "is_official": false, - "name": "wma55/u1210sshd", - "is_automated": false, - "description": "" - }, - { - "star_count": 10, - "is_official": false, - "name": "jdswinbank/sshd", - "is_automated": false, - "description": "" - }, - { - "star_count": 18, - "is_official": false, - "name": "vgauthier/sshd", - "is_automated": false, - "description": "" - } - ... - ] - -**Query parameters**: - -- **term** – term to search - -**Status codes**: - -- **200** – no error -- **500** – server error - -### 2.3 Misc - -#### Check auth configuration - -`POST /auth` - -Get the default username and email - -**Example request**: - - POST /v1.18/auth HTTP/1.1 - Content-Type: application/json - - { - "username": "hannibal", - "password": "xxxx", - "email": "hannibal@a-team.com", - "serveraddress": "https://index.docker.io/v1/" - } - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – no error -- **204** – no error -- **500** – server error - -#### Display system-wide information - -`GET /info` - -Display system-wide information - -**Example request**: - - GET /v1.18/info HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Containers": 11, - "Debug": 0, - "DockerRootDir": "/var/lib/docker", - "Driver": "btrfs", - "DriverStatus": [[""]], - "ExecutionDriver": "native-0.1", - "HttpProxy": "http://test:test@localhost:8080", - "HttpsProxy": "https://test:test@localhost:8080", - "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", - "IPv4Forwarding": 1, - "Images": 16, - "IndexServerAddress": "https://index.docker.io/v1/", - "InitPath": "/usr/bin/docker", - "InitSha1": "", - "KernelVersion": "3.12.0-1-amd64", - "Labels": [ - "storage=ssd" - ], - "MemTotal": 2099236864, - "MemoryLimit": 1, - "NCPU": 1, - "NEventsListener": 0, - "NFd": 11, - "NGoroutines": 21, - "Name": "prod-server-42", - "NoProxy": "9.81.1.160", - "OperatingSystem": "Boot2Docker", - "RegistryConfig": { - "IndexConfigs": { - "docker.io": { - "Mirrors": null, - "Name": "docker.io", - "Official": true, - "Secure": true - } - }, - "InsecureRegistryCIDRs": [ - "127.0.0.0/8" - ] - }, - "SwapLimit": 0, - "SystemTime": "2015-03-10T11:11:23.730591467-07:00" - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Show the docker version information - -`GET /version` - -Show the docker version information - -**Example request**: - - GET /v1.18/version HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Version": "1.5.0", - "Os": "linux", - "KernelVersion": "3.18.5-tinycore64", - "GoVersion": "go1.4.1", - "GitCommit": "a8a31ef", - "Arch": "amd64", - "ApiVersion": "1.18" - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Ping the docker server - -`GET /_ping` - -Ping the docker server - -**Example request**: - - GET /v1.18/_ping HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: text/plain - - OK - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a new image from a container's changes - -`POST /commit` - -Create a new image from a container's changes - -**Example request**: - - POST /v1.18/commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "PortSpecs": null, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Volumes": { - "/tmp": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "ExposedPorts": { - "22/tcp": {} - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - {"Id": "596069db4bf5"} - -**JSON parameters**: - -- **config** - the container's configuration - -**Query parameters**: - -- **container** – source container -- **repo** – repository -- **tag** – tag -- **comment** – commit message -- **author** – author (e.g., "John Hannibal Smith - <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **500** – server error - -#### Monitor Docker's events - -`GET /events` - -Get container events from docker, in real time via streaming. - -Docker containers report the following events: - - create, destroy, die, exec_create, exec_start, export, kill, oom, pause, restart, start, stop, unpause - -Docker images report the following events: - - untag, delete - -**Example request**: - - GET /v1.18/events?since=1374067924 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "create", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067924} - {"status": "start", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067924} - {"status": "stop", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067966} - {"status": "destroy", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067970} - -**Query parameters**: - -- **since** – Timestamp. Show all events created since timestamp and then stream -- **until** – Timestamp. Show events created until given timestamp and stop streaming -- **filters** – A json encoded value of the filters (a map[string][]string) to process on the event list. Available filters: - - `container=`; -- container to filter - - `event=`; -- event to filter - - `image=`; -- image to filter - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images in a repository - -`GET /images/(name)/get` - -Get a tarball containing all images and metadata for the repository specified -by `name`. - -If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image -(and its parents) are returned. If `name` is an image ID, similarly only that -image (and its parents) are returned, but with the exclusion of the -'repositories' file in the tarball, as there were no image names referenced. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.18/images/ubuntu/get - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images - -`GET /images/get` - -Get a tarball containing all images and metadata for one or more repositories. - -For each value of the `names` parameter: if it is a specific name and tag (e.g. -`ubuntu:latest`), then only that image (and its parents) are returned; if it is -an image ID, similarly only that image (and its parents) are returned and there -would be no names referenced in the 'repositories' file for this image ID. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.18/images/get?names=myname%2Fmyapp%3Alatest&names=busybox - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Load a tarball with a set of images and tags into docker - -`POST /images/load` - -Load a set of images and tags into a Docker repository. -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - POST /v1.18/images/load - Content-Type: application/x-tar - - Tarball in body - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Image tarball format - -An image tarball contains one directory per image layer (named using its long ID), -each containing these files: - -- `VERSION`: currently `1.0` - the file format version -- `json`: detailed layer information, similar to `docker inspect layer_id` -- `layer.tar`: A tarfile containing the filesystem changes in this layer - -The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories -for storing attribute changes and deletions. - -If the tarball defines a repository, the tarball should also include a `repositories` file at -the root that contains a list of repository and tag names mapped to layer IDs. - -``` -{"hello-world": - {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} -} -``` - -#### Exec Create - -`POST /containers/(id or name)/exec` - -Sets up an exec instance in a running container `id` - -**Example request**: - - POST /v1.18/containers/e90e34656806/exec HTTP/1.1 - Content-Type: application/json - - { - "AttachStdin": true, - "AttachStdout": true, - "AttachStderr": true, - "Cmd": ["sh"], - "Tty": true - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id": "f90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **AttachStdin** - Boolean value, attaches to `stdin` of the `exec` command. -- **AttachStdout** - Boolean value, attaches to `stdout` of the `exec` command. -- **AttachStderr** - Boolean value, attaches to `stderr` of the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. -- **Cmd** - Command to run specified as a string or an array of strings. - - -**Status codes**: - -- **201** – no error -- **404** – no such container - -#### Exec Start - -`POST /exec/(id)/start` - -Starts a previously set up `exec` instance `id`. If `detach` is true, this API -returns after starting the `exec` command. Otherwise, this API sets up an -interactive session with the `exec` command. - -**Example request**: - - POST /v1.18/exec/e90e34656806/start HTTP/1.1 - Content-Type: application/json - - { - "Detach": false, - "Tty": false - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/vnd.docker.raw-stream - - {% raw %} - {{ STREAM }} - {% endraw %} - -**JSON parameters**: - -- **Detach** - Detach from the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance - -**Stream details**: - -Similar to the stream behavior of `POST /containers/(id or name)/attach` API - -#### Exec Resize - -`POST /exec/(id)/resize` - -Resizes the `tty` session used by the `exec` command `id`. The unit is number of characters. -This API is valid only if `tty` was specified as part of creating and starting the `exec` command. - -**Example request**: - - POST /v1.18/exec/e90e34656806/resize?h=40&w=80 HTTP/1.1 - Content-Type: text/plain - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: text/plain - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **201** – no error -- **404** – no such exec instance - -#### Exec Inspect - -`GET /exec/(id)/json` - -Return low-level information about the `exec` command `id`. - -**Example request**: - - GET /v1.18/exec/11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: plain/text - - { - "ID" : "11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39", - "Running" : false, - "ExitCode" : 2, - "ProcessConfig" : { - "privileged" : false, - "user" : "", - "tty" : false, - "entrypoint" : "sh", - "arguments" : [ - "-c", - "exit 2" - ] - }, - "OpenStdin" : false, - "OpenStderr" : false, - "OpenStdout" : false, - "Container" : { - "State" : { - "Running" : true, - "Paused" : false, - "Restarting" : false, - "OOMKilled" : false, - "Pid" : 3650, - "ExitCode" : 0, - "Error" : "", - "StartedAt" : "2014-11-17T22:26:03.717657531Z", - "FinishedAt" : "0001-01-01T00:00:00Z" - }, - "ID" : "8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c", - "Created" : "2014-11-17T22:26:03.626304998Z", - "Path" : "date", - "Args" : [], - "Config" : { - "Hostname" : "8f177a186b97", - "Domainname" : "", - "User" : "", - "AttachStdin" : false, - "AttachStdout" : false, - "AttachStderr" : false, - "PortSpecs": null, - "ExposedPorts" : null, - "Tty" : false, - "OpenStdin" : false, - "StdinOnce" : false, - "Env" : [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], - "Cmd" : [ - "date" - ], - "Image" : "ubuntu", - "Volumes" : null, - "WorkingDir" : "", - "Entrypoint" : null, - "NetworkDisabled" : false, - "MacAddress" : "", - "OnBuild" : null, - "SecurityOpt" : null - }, - "Image" : "5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5", - "NetworkSettings" : { - "IPAddress" : "172.17.0.2", - "IPPrefixLen" : 16, - "MacAddress" : "02:42:ac:11:00:02", - "Gateway" : "172.17.42.1", - "Bridge" : "docker0", - "PortMapping" : null, - "Ports" : {} - }, - "ResolvConfPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/resolv.conf", - "HostnamePath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hostname", - "HostsPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Name" : "/test", - "Driver" : "aufs", - "ExecDriver" : "native-0.2", - "MountLabel" : "", - "ProcessLabel" : "", - "AppArmorProfile" : "", - "RestartCount" : 0, - "Volumes" : {}, - "VolumesRW" : {} - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **500** - server error - -## 3. Going further - -### 3.1 Inside `docker run` - -As an example, the `docker run` command line makes the following API calls: - -- Create the container - -- If the status code is 404, it means the image doesn't exist: - - Try to pull it. - - Then, retry to create the container. - -- Start the container. - -- If you are not in detached mode: -- Attach to the container, using `logs=1` (to have `stdout` and - `stderr` from the container's start) and `stream=1` - -- If in detached mode or only `stdin` is attached, display the container's id. - -### 3.2 Hijacking - -In this version of the API, `/attach`, uses hijacking to transport `stdin`, -`stdout`, and `stderr` on the same socket. - -To hint potential proxies about connection hijacking, Docker client sends -connection upgrade headers similarly to websocket. - - Upgrade: tcp - Connection: Upgrade - -When Docker daemon detects the `Upgrade` header, it switches its status code -from **200 OK** to **101 UPGRADED** and resends the same headers. - -This might change in the future. - -### 3.3 CORS Requests - -To set cross origin requests to the Engine API please give values to -`--api-cors-header` when running Docker in daemon mode. Set * (asterisk) allows all, -default or blank means CORS disabled - - $ docker -d -H="192.168.1.9:2375" --api-cors-header="http://foo.bar" diff --git a/vendor/github.com/docker/docker/docs/api/v1.19.md b/vendor/github.com/docker/docker/docs/api/v1.19.md deleted file mode 100644 index a1a7280..0000000 --- a/vendor/github.com/docker/docker/docs/api/v1.19.md +++ /dev/null @@ -1,2238 +0,0 @@ ---- -title: "Engine API v1.19" -description: "API Documentation for Docker" -keywords: "API, Docker, rcli, REST, documentation" -redirect_from: -- /engine/reference/api/docker_remote_api_v1.19/ -- /reference/api/docker_remote_api_v1.19/ ---- - - - -## 1. Brief introduction - - - The daemon listens on `unix:///var/run/docker.sock` but you can - [Bind Docker to another host/port or a Unix socket](../reference/commandline/dockerd.md#bind-docker-to-another-host-port-or-a-unix-socket). - - The API tends to be REST. However, for some complex commands, like `attach` - or `pull`, the HTTP connection is hijacked to transport `stdout`, - `stdin` and `stderr`. - - When the client API version is newer than the daemon's, these calls return an HTTP - `400 Bad Request` error message. - -## 2. Endpoints - -### 2.1 Containers - -#### List containers - -`GET /containers/json` - -List containers - -**Example request**: - - GET /v1.19/containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "8dfafdbc3a40", - "Names":["/boring_feynman"], - "Image": "ubuntu:latest", - "Command": "echo 1", - "Created": 1367854155, - "Status": "Exit 0", - "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}], - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "SizeRw": 12288, - "SizeRootFs": 0 - }, - { - "Id": "9cd87474be90", - "Names":["/coolName"], - "Image": "ubuntu:latest", - "Command": "echo 222222", - "Created": 1367854155, - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0 - }, - { - "Id": "3176a2479c92", - "Names":["/sleepy_dog"], - "Image": "ubuntu:latest", - "Command": "echo 3333333333333333", - "Created": 1367854154, - "Status": "Exit 0", - "Ports":[], - "Labels": {}, - "SizeRw":12288, - "SizeRootFs":0 - }, - { - "Id": "4cb07b47f9fb", - "Names":["/running_cat"], - "Image": "ubuntu:latest", - "Command": "echo 444444444444444444444444444444444", - "Created": 1367854152, - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0 - } - ] - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, Show all containers. - Only running containers are shown by default (i.e., this defaults to false) -- **limit** – Show `limit` last created - containers, include non-running ones. -- **since** – Show only containers created since Id, include - non-running ones. -- **before** – Show only containers created before Id, include - non-running ones. -- **size** – 1/True/true or 0/False/false, Show the containers - sizes -- **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: - - `exited=`; -- containers with exit code of `` ; - - `status=`(`restarting`|`running`|`paused`|`exited`) - - `label=key` or `label="key=value"` of a container label - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **500** – server error - -#### Create a container - -`POST /containers/create` - -Create a container - -**Example request**: - - POST /v1.19/containers/create HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": [ - "FOO=bar", - "BAZ=quux" - ], - "Cmd": [ - "date" - ], - "Entrypoint": null, - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "/volumes/data": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "HostConfig": { - "Binds": ["/tmp:/tmp"], - "Links": ["redis3:redis"], - "LxcConf": {"lxc.utsname":"docker"}, - "Memory": 0, - "MemorySwap": 0, - "CpuShares": 512, - "CpuPeriod": 100000, - "CpuQuota": 50000, - "CpusetCpus": "0,1", - "CpusetMems": "0,1", - "BlkioWeight": 300, - "OomKillDisable": false, - "PidMode": "", - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsSearch": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [], - "CgroupParent": "" - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id":"e90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **Hostname** - A string value containing the hostname to use for the - container. -- **Domainname** - A string value containing the domain name to use - for the container. -- **User** - A string value specifying the user inside the container. -- **AttachStdin** - Boolean value, attaches to `stdin`. -- **AttachStdout** - Boolean value, attaches to `stdout`. -- **AttachStderr** - Boolean value, attaches to `stderr`. -- **Tty** - Boolean value, Attach standard streams to a `tty`, including `stdin` if it is not closed. -- **OpenStdin** - Boolean value, opens `stdin`, -- **StdinOnce** - Boolean value, close `stdin` after the 1 attached client disconnects. -- **Env** - A list of environment variables in the form of `["VAR=value", ...]` -- **Labels** - Adds a map of labels to a container. To specify a map: `{"key":"value", ... }` -- **Cmd** - Command to run specified as a string or an array of strings. -- **Entrypoint** - Set the entry point for the container as a string or an array - of strings. -- **Image** - A string specifying the image name to use for the container. -- **Volumes** - An object mapping mount point paths (strings) inside the - container to empty objects. -- **WorkingDir** - A string specifying the working directory for commands to - run in. -- **NetworkDisabled** - Boolean value, when true disables networking for the - container -- **ExposedPorts** - An object mapping ports to an empty object in the form of: - `"ExposedPorts": { "/: {}" }` -- **HostConfig** - - **Binds** – A list of bind-mounts for this container. Each item is a string in one of these forms: - + `host-src:container-dest` to bind-mount a host path into the - container. Both `host-src`, and `container-dest` must be an - _absolute_ path. - + `host-src:container-dest:ro` to make the bind-mount read-only - inside the container. Both `host-src`, and `container-dest` must be - an _absolute_ path. - - **Links** - A list of links for the container. Each link entry should be - in the form of `container_name:alias`. - - **LxcConf** - LXC specific configurations. These configurations only - work when using the `lxc` execution driver. - - **Memory** - Memory limit in bytes. - - **MemorySwap** - Total memory limit (memory + swap); set `-1` to enable unlimited swap. - You must use this with `memory` and make the swap value larger than `memory`. - - **CpuShares** - An integer value containing the container's CPU Shares - (ie. the relative weight vs other containers). - - **CpuPeriod** - The length of a CPU period in microseconds. - - **CpuQuota** - Microseconds of CPU time that the container can get in a CPU period. - - **CpusetCpus** - String value containing the `cgroups CpusetCpus` to use. - - **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. - - **BlkioWeight** - Block IO weight (relative weight) accepts a weight value between 10 and 1000. - - **OomKillDisable** - Boolean value, whether to disable OOM Killer for the container or not. - - **PidMode** - Set the PID (Process) Namespace mode for the container; - `"container:"`: joins another container's PID namespace - `"host"`: use the host's PID namespace inside the container - - **PortBindings** - A map of exposed container ports and the host port they - should map to. A JSON object in the form - `{ /: [{ "HostPort": "" }] }` - Take note that `port` is specified as a string and not an integer value. - - **PublishAllPorts** - Allocates a random host port for all of a container's - exposed ports. Specified as a boolean value. - - **Privileged** - Gives the container full access to the host. Specified as - a boolean value. - - **ReadonlyRootfs** - Mount the container's root filesystem as read only. - Specified as a boolean value. - - **Dns** - A list of DNS servers for the container to use. - - **DnsSearch** - A list of DNS search domains - - **ExtraHosts** - A list of hostnames/IP mappings to add to the - container's `/etc/hosts` file. Specified in the form `["hostname:IP"]`. - - **VolumesFrom** - A list of volumes to inherit from another container. - Specified in the form `[:]` - - **CapAdd** - A list of kernel capabilities to add to the container. - - **Capdrop** - A list of kernel capabilities to drop from the container. - - **RestartPolicy** – The behavior to apply when the container exits. The - value is an object with a `Name` property of either `"always"` to - always restart or `"on-failure"` to restart only when the container - exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` - controls the number of times to retry before giving up. - The default is not to restart. (optional) - An ever increasing delay (double the previous delay, starting at 100mS) - is added before each restart to prevent flooding the server. - - **NetworkMode** - Sets the networking mode for the container. Supported - values are: `bridge`, `host`, `none`, and `container:` - - **Devices** - A list of devices to add to the container specified as a JSON object in the - form - `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` - - **Ulimits** - A list of ulimits to set in the container, specified as - `{ "Name": , "Soft": , "Hard": }`, for example: - `Ulimits: { "Name": "nofile", "Soft": 1024, "Hard": 2048 }` - - **SecurityOpt**: A list of string values to customize labels for MLS - systems, such as SELinux. - - **LogConfig** - Log configuration for the container, specified as a JSON object in the form - `{ "Type": "", "Config": {"key1": "val1"}}`. - Available types: `json-file`, `syslog`, `journald`, `none`. - `syslog` available options are: `address`. - - **CgroupParent** - Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist. - -**Query parameters**: - -- **name** – Assign the specified name to the container. Must - match `/?[a-zA-Z0-9_-]+`. - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such container -- **406** – impossible to attach (container not running) -- **409** – conflict -- **500** – server error - -#### Inspect a container - -`GET /containers/(id or name)/json` - -Return low-level information on the container `id` - -**Example request**: - - GET /v1.19/containers/4fa6e0f0c678/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "AppArmorProfile": "", - "Args": [ - "-c", - "exit 9" - ], - "Config": { - "AttachStderr": true, - "AttachStdin": false, - "AttachStdout": true, - "Cmd": [ - "/bin/sh", - "-c", - "exit 9" - ], - "Domainname": "", - "Entrypoint": null, - "Env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts": null, - "Hostname": "ba033ac44011", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "MacAddress": "", - "NetworkDisabled": false, - "OnBuild": null, - "OpenStdin": false, - "PortSpecs": null, - "StdinOnce": false, - "Tty": false, - "User": "", - "Volumes": null, - "WorkingDir": "" - }, - "Created": "2015-01-06T15:47:31.485331387Z", - "Driver": "devicemapper", - "ExecDriver": "native-0.2", - "ExecIDs": null, - "HostConfig": { - "Binds": null, - "BlkioWeight": 0, - "CapAdd": null, - "CapDrop": null, - "ContainerIDFile": "", - "CpusetCpus": "", - "CpusetMems": "", - "CpuShares": 0, - "CpuPeriod": 100000, - "Devices": [], - "Dns": null, - "DnsSearch": null, - "ExtraHosts": null, - "IpcMode": "", - "Links": null, - "LxcConf": [], - "Memory": 0, - "MemorySwap": 0, - "OomKillDisable": false, - "NetworkMode": "bridge", - "PidMode": "", - "PortBindings": {}, - "Privileged": false, - "ReadonlyRootfs": false, - "PublishAllPorts": false, - "RestartPolicy": { - "MaximumRetryCount": 2, - "Name": "on-failure" - }, - "LogConfig": { - "Config": null, - "Type": "json-file" - }, - "SecurityOpt": null, - "VolumesFrom": null, - "Ulimits": [{}] - }, - "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname", - "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39", - "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2", - "MountLabel": "", - "Name": "/boring_euclid", - "NetworkSettings": { - "Bridge": "", - "Gateway": "", - "IPAddress": "", - "IPPrefixLen": 0, - "MacAddress": "", - "PortMapping": null, - "Ports": null - }, - "Path": "/bin/sh", - "ProcessLabel": "", - "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf", - "RestartCount": 1, - "State": { - "Error": "", - "ExitCode": 9, - "FinishedAt": "2015-01-06T15:47:32.080254511Z", - "OOMKilled": false, - "Paused": false, - "Pid": 0, - "Restarting": false, - "Running": true, - "StartedAt": "2015-01-06T15:47:32.072697474Z" - }, - "Volumes": {}, - "VolumesRW": {} - } - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### List processes running inside a container - -`GET /containers/(id or name)/top` - -List processes running inside the container `id`. On Unix systems this -is done by running the `ps` command. This endpoint is not -supported on Windows. - -**Example request**: - - GET /v1.19/containers/4fa6e0f0c678/top HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD" - ], - "Processes" : [ - [ - "root", "13642", "882", "0", "17:03", "pts/0", "00:00:00", "/bin/bash" - ], - [ - "root", "13735", "13642", "0", "17:06", "pts/0", "00:00:00", "sleep 10" - ] - ] - } - -**Example request**: - - GET /v1.19/containers/4fa6e0f0c678/top?ps_args=aux HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND" - ] - "Processes" : [ - [ - "root","13642","0.0","0.1","18172","3184","pts/0","Ss","17:03","0:00","/bin/bash" - ], - [ - "root","13895","0.0","0.0","4348","692","pts/0","S+","17:15","0:00","sleep 10" - ] - ], - } - -**Query parameters**: - -- **ps_args** – `ps` arguments to use (e.g., `aux`), defaults to `-ef` - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container logs - -`GET /containers/(id or name)/logs` - -Get `stdout` and `stderr` logs from the container ``id`` - -> **Note**: -> This endpoint works only for containers with the `json-file` or `journald` logging drivers. - -**Example request**: - - GET /v1.19/containers/4fa6e0f0c678/logs?stderr=1&stdout=1×tamps=1&follow=1&tail=10&since=1428990821 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **follow** – 1/True/true or 0/False/false, return stream. Default `false`. -- **stdout** – 1/True/true or 0/False/false, show `stdout` log. Default `false`. -- **stderr** – 1/True/true or 0/False/false, show `stderr` log. Default `false`. -- **since** – UNIX timestamp (integer) to filter logs. Specifying a timestamp - will only output log-entries since that timestamp. Default: 0 (unfiltered) -- **timestamps** – 1/True/true or 0/False/false, print timestamps for - every log line. Default `false`. -- **tail** – Output specified number of lines at the end of logs: `all` or ``. Default all. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **404** – no such container -- **500** – server error - -#### Inspect changes on a container's filesystem - -`GET /containers/(id or name)/changes` - -Inspect changes on container `id`'s filesystem - -**Example request**: - - GET /v1.19/containers/4fa6e0f0c678/changes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Path": "/dev", - "Kind": 0 - }, - { - "Path": "/dev/kmsg", - "Kind": 1 - }, - { - "Path": "/test", - "Kind": 1 - } - ] - -Values for `Kind`: - -- `0`: Modify -- `1`: Add -- `2`: Delete - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Export a container - -`GET /containers/(id or name)/export` - -Export the contents of container `id` - -**Example request**: - - GET /v1.19/containers/4fa6e0f0c678/export HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/octet-stream - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container stats based on resource usage - -`GET /containers/(id or name)/stats` - -This endpoint returns a live stream of a container's resource usage statistics. - -**Example request**: - - GET /v1.19/containers/redis1/stats HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "read" : "2015-01-08T22:57:31.547920715Z", - "network" : { - "rx_dropped" : 0, - "rx_bytes" : 648, - "rx_errors" : 0, - "tx_packets" : 8, - "tx_dropped" : 0, - "rx_packets" : 8, - "tx_errors" : 0, - "tx_bytes" : 648 - }, - "memory_stats" : { - "stats" : { - "total_pgmajfault" : 0, - "cache" : 0, - "mapped_file" : 0, - "total_inactive_file" : 0, - "pgpgout" : 414, - "rss" : 6537216, - "total_mapped_file" : 0, - "writeback" : 0, - "unevictable" : 0, - "pgpgin" : 477, - "total_unevictable" : 0, - "pgmajfault" : 0, - "total_rss" : 6537216, - "total_rss_huge" : 6291456, - "total_writeback" : 0, - "total_inactive_anon" : 0, - "rss_huge" : 6291456, - "hierarchical_memory_limit" : 67108864, - "total_pgfault" : 964, - "total_active_file" : 0, - "active_anon" : 6537216, - "total_active_anon" : 6537216, - "total_pgpgout" : 414, - "total_cache" : 0, - "inactive_anon" : 0, - "active_file" : 0, - "pgfault" : 964, - "inactive_file" : 0, - "total_pgpgin" : 477 - }, - "max_usage" : 6651904, - "usage" : 6537216, - "failcnt" : 0, - "limit" : 67108864 - }, - "blkio_stats" : {}, - "cpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24472255, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100215355, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 739306590000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - }, - "precpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24350896, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100093996, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 9492140000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - } - } - -The precpu_stats is the cpu statistic of last read, which is used for calculating the cpu usage percent. It is not the exact copy of the “cpu_stats” field. - -**Query parameters**: - -- **stream** – 1/True/true or 0/False/false, pull stats once then disconnect. Default `true`. - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Resize a container TTY - -`POST /containers/(id or name)/resize?h=&w=` - -Resize the TTY for container with `id`. You must restart the container for the resize to take effect. - -**Example request**: - - POST /v1.19/containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **200** – no error -- **404** – No such container -- **500** – Cannot resize container - -#### Start a container - -`POST /containers/(id or name)/start` - -Start the container `id` - -> **Note**: -> For backwards compatibility, this endpoint accepts a `HostConfig` as JSON-encoded request body. -> See [create a container](#create-a-container) for details. - -**Example request**: - - POST /v1.19/containers/e90e34656806/start HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **304** – container already started -- **404** – no such container -- **500** – server error - -#### Stop a container - -`POST /containers/(id or name)/stop` - -Stop the container `id` - -**Example request**: - - POST /v1.19/containers/e90e34656806/stop?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **304** – container already stopped -- **404** – no such container -- **500** – server error - -#### Restart a container - -`POST /containers/(id or name)/restart` - -Restart the container `id` - -**Example request**: - - POST /v1.19/containers/e90e34656806/restart?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Kill a container - -`POST /containers/(id or name)/kill` - -Kill the container `id` - -**Example request**: - - POST /v1.19/containers/e90e34656806/kill HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **signal** - Signal to send to the container: integer or string like `SIGINT`. - When not set, `SIGKILL` is assumed and the call waits for the container to exit. - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Rename a container - -`POST /containers/(id or name)/rename` - -Rename the container `id` to a `new_name` - -**Example request**: - - POST /v1.19/containers/e90e34656806/rename?name=new_name HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **name** – new name for the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **409** - conflict name already assigned -- **500** – server error - -#### Pause a container - -`POST /containers/(id or name)/pause` - -Pause the container `id` - -**Example request**: - - POST /v1.19/containers/e90e34656806/pause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Unpause a container - -`POST /containers/(id or name)/unpause` - -Unpause the container `id` - -**Example request**: - - POST /v1.19/containers/e90e34656806/unpause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Attach to a container - -`POST /containers/(id or name)/attach` - -Attach to the container `id` - -**Example request**: - - POST /v1.19/containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -**Stream details**: - -When using the TTY setting is enabled in -[`POST /containers/create` -](#create-a-container), -the stream is the raw data from the process PTY and client's `stdin`. -When the TTY is disabled, then the stream is multiplexed to separate -`stdout` and `stderr`. - -The format is a **Header** and a **Payload** (frame). - -**HEADER** - -The header contains the information which the stream writes (`stdout` or -`stderr`). It also contains the size of the associated frame encoded in the -last four bytes (`uint32`). - -It is encoded on the first eight bytes like this: - - header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} - -`STREAM_TYPE` can be: - -- 0: `stdin` (is written on `stdout`) -- 1: `stdout` -- 2: `stderr` - -`SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of -the `uint32` size encoded as big endian. - -**PAYLOAD** - -The payload is the raw stream. - -**IMPLEMENTATION** - -The simplest way to implement the Attach protocol is the following: - - 1. Read eight bytes. - 2. Choose `stdout` or `stderr` depending on the first byte. - 3. Extract the frame size from the last four bytes. - 4. Read the extracted size and output it on the correct output. - 5. Goto 1. - -#### Attach to a container (websocket) - -`GET /containers/(id or name)/attach/ws` - -Attach to the container `id` via websocket - -Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455) - -**Example request** - - GET /v1.19/containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 - -**Example response** - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -#### Wait a container - -`POST /containers/(id or name)/wait` - -Block until container `id` stops, then returns the exit code - -**Example request**: - - POST /v1.19/containers/16253994b7c4/wait HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"StatusCode": 0} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Remove a container - -`DELETE /containers/(id or name)` - -Remove the container `id` from the filesystem - -**Example request**: - - DELETE /v1.19/containers/16253994b7c4?v=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **v** – 1/True/true or 0/False/false, Remove the volumes - associated to the container. Default `false`. -- **force** - 1/True/true or 0/False/false, Kill then remove the container. - Default `false`. - -**Status codes**: - -- **204** – no error -- **400** – bad parameter -- **404** – no such container -- **409** – conflict -- **500** – server error - -#### Copy files or folders from a container - -`POST /containers/(id or name)/copy` - -Copy files or folders of container `id` - -**Example request**: - - POST /v1.19/containers/4fa6e0f0c678/copy HTTP/1.1 - Content-Type: application/json - - { - "Resource": "test.txt" - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -### 2.2 Images - -#### List Images - -`GET /images/json` - -**Example request**: - - GET /v1.19/images/json?all=0 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "RepoTags": [ - "ubuntu:12.04", - "ubuntu:precise", - "ubuntu:latest" - ], - "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", - "Created": 1365714795, - "Size": 131506275, - "VirtualSize": 131506275, - "Labels": {} - }, - { - "RepoTags": [ - "ubuntu:12.10", - "ubuntu:quantal" - ], - "ParentId": "27cf784147099545", - "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "Created": 1364102658, - "Size": 24653, - "VirtualSize": 180116135, - "Labels": { - "com.example.version": "v1" - } - } - ] - -**Example request, with digest information**: - - GET /v1.19/images/json?digests=1 HTTP/1.1 - -**Example response, with digest information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Created": 1420064636, - "Id": "4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125", - "ParentId": "ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2", - "RepoDigests": [ - "localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags": [ - "localhost:5000/test/busybox:latest", - "playdate:latest" - ], - "Size": 0, - "VirtualSize": 2429728, - "Labels": {} - } - ] - -The response shows a single image `Id` associated with two repositories -(`RepoTags`): `localhost:5000/test/busybox`: and `playdate`. A caller can use -either of the `RepoTags` values `localhost:5000/test/busybox:latest` or -`playdate:latest` to reference the image. - -You can also use `RepoDigests` values to reference an image. In this response, -the array has only one reference and that is to the -`localhost:5000/test/busybox` repository; the `playdate` repository has no -digest. You can reference this digest using the value: -`localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d...` - -See the `docker run` and `docker build` commands for examples of digest and tag -references on the command line. - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, default false -- **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: - - `dangling=true` - - `label=key` or `label="key=value"` of an image label -- **filter** - only return images with the specified name - -#### Build image from a Dockerfile - -`POST /build` - -Build an image from a Dockerfile - -**Example request**: - - POST /v1.19/build HTTP/1.1 - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"stream": "Step 1/5..."} - {"stream": "..."} - {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} - -The input stream must be a `tar` archive compressed with one of the -following algorithms: `identity` (no compression), `gzip`, `bzip2`, `xz`. - -The archive must include a build instructions file, typically called -`Dockerfile` at the archive's root. The `dockerfile` parameter may be -used to specify a different build instructions file. To do this, its value must be -the path to the alternate build instructions file to use. - -The archive may include any number of other files, -which are accessible in the build context (See the [*ADD build -command*](../reference/builder.md#add)). - -The Docker daemon performs a preliminary validation of the `Dockerfile` before -starting the build, and returns an error if the syntax is incorrect. After that, -each instruction is run one-by-one until the ID of the new image is output. - -The build is canceled if the client drops the connection by quitting -or being killed. - -**Query parameters**: - -- **dockerfile** - Path within the build context to the Dockerfile. This is - ignored if `remote` is specified and points to an individual filename. -- **t** – A name and optional tag to apply to the image in the `name:tag` format. - If you omit the `tag` the default `latest` value is assumed. -- **remote** – A Git repository URI or HTTP/HTTPS URI build source. If the - URI specifies a filename, the file's contents are placed into a file - called `Dockerfile`. -- **q** – Suppress verbose build output. -- **nocache** – Do not use the cache when building the image. -- **pull** - Attempt to pull the image even if an older image exists locally. -- **rm** - Remove intermediate containers after a successful build (default behavior). -- **forcerm** - Always remove intermediate containers (includes `rm`). -- **memory** - Set memory limit for build. -- **memswap** - Total memory (memory + swap), `-1` to enable unlimited swap. -- **cpushares** - CPU shares (relative weight). -- **cpusetcpus** - CPUs in which to allow execution (e.g., `0-3`, `0,1`). -- **cpuperiod** - The length of a CPU period in microseconds. -- **cpuquota** - Microseconds of CPU time that the container can get in a CPU period. - -**Request Headers**: - -- **Content-type** – Set to `"application/tar"`. -- **X-Registry-Config** – base64-encoded ConfigFile object - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Create an image - -`POST /images/create` - -Create an image either by pulling it from the registry or by importing it - -**Example request**: - - POST /v1.19/images/create?fromImage=busybox&tag=latest HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pulling..."} - {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} - {"error": "Invalid..."} - ... - -When using this endpoint to pull an image from the registry, the -`X-Registry-Auth` header can be used to include -a base64-encoded AuthConfig object. - -**Query parameters**: - -- **fromImage** – Name of the image to pull. -- **fromSrc** – Source to import. The value may be a URL from which the image - can be retrieved or `-` to read the image from the request body. -- **repo** – Repository name. -- **tag** – Tag. If empty when pulling an image, this causes all tags - for the given image to be pulled. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object - -**Status codes**: - -- **200** – no error -- **404** - repository does not exist or no read access -- **500** – server error - - - -#### Inspect an image - -`GET /images/(name)/json` - -Return low-level information on the image `name` - -**Example request**: - - GET /v1.19/images/ubuntu/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Created": "2013-03-23T22:24:18.818426-07:00", - "Container": "3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", - "ContainerConfig": { - "Hostname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": false, - "AttachStderr": false, - "Tty": true, - "OpenStdin": true, - "StdinOnce": false, - "Env": null, - "Cmd": ["/bin/bash"], - "Dns": null, - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": null, - "VolumesFrom": "", - "WorkingDir": "" - }, - "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "Parent": "27cf784147099545", - "Size": 6824592 - } - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Get the history of an image - -`GET /images/(name)/history` - -Return the history of the image `name` - -**Example request**: - - GET /v1.19/images/ubuntu/history HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710", - "Created": 1398108230, - "CreatedBy": "/bin/sh -c #(nop) ADD file:eb15dbd63394e063b805a3c32ca7bf0266ef64676d5a6fab4801f2e81e2a5148 in /", - "Tags": [ - "ubuntu:lucid", - "ubuntu:10.04" - ], - "Size": 182964289, - "Comment": "" - }, - { - "Id": "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8", - "Created": 1398108222, - "CreatedBy": "/bin/sh -c #(nop) MAINTAINER Tianon Gravi - mkimage-debootstrap.sh -i iproute,iputils-ping,ubuntu-minimal -t lucid.tar.xz lucid http://archive.ubuntu.com/ubuntu/", - "Tags": null, - "Size": 0, - "Comment": "" - }, - { - "Id": "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158", - "Created": 1371157430, - "CreatedBy": "", - "Tags": [ - "scratch12:latest", - "scratch:latest" - ], - "Size": 0, - "Comment": "Imported from -" - } - ] - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Push an image on the registry - -`POST /images/(name)/push` - -Push the image `name` on the registry - -**Example request**: - - POST /v1.19/images/test/push HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pushing..."} - {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} - {"error": "Invalid..."} - ... - -If you wish to push an image on to a private registry, that image must already have a tag -into a repository which references that registry `hostname` and `port`. This repository name should -then be used in the URL. This duplicates the command line's flow. - -**Example request**: - - POST /v1.19/images/registry.acme.com:5000/test/push HTTP/1.1 - - -**Query parameters**: - -- **tag** – The tag to associate with the image on the registry. This is optional. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object. - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Tag an image into a repository - -`POST /images/(name)/tag` - -Tag the image `name` into a repository - -**Example request**: - - POST /v1.19/images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 - -**Example response**: - - HTTP/1.1 201 Created - -**Query parameters**: - -- **repo** – The repository to tag in -- **force** – 1/True/true or 0/False/false, default false -- **tag** - The new tag name - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Remove an image - -`DELETE /images/(name)` - -Remove the image `name` from the filesystem - -**Example request**: - - DELETE /v1.19/images/test HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-type: application/json - - [ - {"Untagged": "3e2f21a89f"}, - {"Deleted": "3e2f21a89f"}, - {"Deleted": "53b4f83ac9"} - ] - -**Query parameters**: - -- **force** – 1/True/true or 0/False/false, default false -- **noprune** – 1/True/true or 0/False/false, default false - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Search images - -`GET /images/search` - -Search for an image on [Docker Hub](https://hub.docker.com). This API -returns both `is_trusted` and `is_automated` images. Currently, they -are considered identical. In the future, the `is_trusted` property will -be deprecated and replaced by the `is_automated` property. - -> **Note**: -> The response keys have changed from API v1.6 to reflect the JSON -> sent by the registry server to the docker daemon's request. - -**Example request**: - - GET /v1.19/images/search?term=sshd HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "star_count": 12, - "is_official": false, - "name": "wma55/u1210sshd", - "is_trusted": false, - "is_automated": false, - "description": "" - }, - { - "star_count": 10, - "is_official": false, - "name": "jdswinbank/sshd", - "is_trusted": false, - "is_automated": false, - "description": "" - }, - { - "star_count": 18, - "is_official": false, - "name": "vgauthier/sshd", - "is_trusted": false, - "is_automated": false, - "description": "" - } - ... - ] - -**Query parameters**: - -- **term** – term to search - -**Status codes**: - -- **200** – no error -- **500** – server error - -### 2.3 Misc - -#### Check auth configuration - -`POST /auth` - -Get the default username and email - -**Example request**: - - POST /v1.19/auth HTTP/1.1 - Content-Type: application/json - - { - "username": "hannibal", - "password": "xxxx", - "email": "hannibal@a-team.com", - "serveraddress": "https://index.docker.io/v1/" - } - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – no error -- **204** – no error -- **500** – server error - -#### Display system-wide information - -`GET /info` - -Display system-wide information - -**Example request**: - - GET /v1.19/info HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Containers": 11, - "CpuCfsPeriod": true, - "CpuCfsQuota": true, - "Debug": false, - "DockerRootDir": "/var/lib/docker", - "Driver": "btrfs", - "DriverStatus": [[""]], - "ExecutionDriver": "native-0.1", - "ExperimentalBuild": false, - "HttpProxy": "http://test:test@localhost:8080", - "HttpsProxy": "https://test:test@localhost:8080", - "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", - "IPv4Forwarding": true, - "Images": 16, - "IndexServerAddress": "https://index.docker.io/v1/", - "InitPath": "/usr/bin/docker", - "InitSha1": "", - "KernelVersion": "3.12.0-1-amd64", - "Labels": [ - "storage=ssd" - ], - "MemTotal": 2099236864, - "MemoryLimit": true, - "NCPU": 1, - "NEventsListener": 0, - "NFd": 11, - "NGoroutines": 21, - "Name": "prod-server-42", - "NoProxy": "9.81.1.160", - "OomKillDisable": true, - "OperatingSystem": "Boot2Docker", - "RegistryConfig": { - "IndexConfigs": { - "docker.io": { - "Mirrors": null, - "Name": "docker.io", - "Official": true, - "Secure": true - } - }, - "InsecureRegistryCIDRs": [ - "127.0.0.0/8" - ] - }, - "SwapLimit": false, - "SystemTime": "2015-03-10T11:11:23.730591467-07:00" - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Show the docker version information - -`GET /version` - -Show the docker version information - -**Example request**: - - GET /v1.19/version HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Version": "1.5.0", - "Os": "linux", - "KernelVersion": "3.18.5-tinycore64", - "GoVersion": "go1.4.1", - "GitCommit": "a8a31ef", - "Arch": "amd64", - "ApiVersion": "1.19" - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Ping the docker server - -`GET /_ping` - -Ping the docker server - -**Example request**: - - GET /v1.19/_ping HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: text/plain - - OK - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a new image from a container's changes - -`POST /commit` - -Create a new image from a container's changes - -**Example request**: - - POST /v1.19/commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "PortSpecs": null, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Volumes": { - "/tmp": {} - }, - "Labels": { - "key1": "value1", - "key2": "value2" - }, - "WorkingDir": "", - "NetworkDisabled": false, - "ExposedPorts": { - "22/tcp": {} - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - {"Id": "596069db4bf5"} - -**JSON parameters**: - -- **config** - the container's configuration - -**Query parameters**: - -- **container** – source container -- **repo** – repository -- **tag** – tag -- **comment** – commit message -- **author** – author (e.g., "John Hannibal Smith - <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **500** – server error - -#### Monitor Docker's events - -`GET /events` - -Get container events from docker, in real time via streaming. - -Docker containers report the following events: - - attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause - -Docker images report the following events: - - untag, delete - -**Example request**: - - GET /v1.19/events?since=1374067924 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "create", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067924} - {"status": "start", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067924} - {"status": "stop", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067966} - {"status": "destroy", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067970} - -**Query parameters**: - -- **since** – Timestamp. Show all events created since timestamp and then stream -- **until** – Timestamp. Show events created until given timestamp and stop streaming -- **filters** – A json encoded value of the filters (a map[string][]string) to process on the event list. Available filters: - - `container=`; -- container to filter - - `event=`; -- event to filter - - `image=`; -- image to filter - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images in a repository - -`GET /images/(name)/get` - -Get a tarball containing all images and metadata for the repository specified -by `name`. - -If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image -(and its parents) are returned. If `name` is an image ID, similarly only that -image (and its parents) are returned, but with the exclusion of the -'repositories' file in the tarball, as there were no image names referenced. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.19/images/ubuntu/get - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images - -`GET /images/get` - -Get a tarball containing all images and metadata for one or more repositories. - -For each value of the `names` parameter: if it is a specific name and tag (e.g. -`ubuntu:latest`), then only that image (and its parents) are returned; if it is -an image ID, similarly only that image (and its parents) are returned and there -would be no names referenced in the 'repositories' file for this image ID. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.19/images/get?names=myname%2Fmyapp%3Alatest&names=busybox - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Load a tarball with a set of images and tags into docker - -`POST /images/load` - -Load a set of images and tags into a Docker repository. -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - POST /v1.19/images/load - Content-Type: application/x-tar - - Tarball in body - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Image tarball format - -An image tarball contains one directory per image layer (named using its long ID), -each containing these files: - -- `VERSION`: currently `1.0` - the file format version -- `json`: detailed layer information, similar to `docker inspect layer_id` -- `layer.tar`: A tarfile containing the filesystem changes in this layer - -The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories -for storing attribute changes and deletions. - -If the tarball defines a repository, the tarball should also include a `repositories` file at -the root that contains a list of repository and tag names mapped to layer IDs. - -``` -{"hello-world": - {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} -} -``` - -#### Exec Create - -`POST /containers/(id or name)/exec` - -Sets up an exec instance in a running container `id` - -**Example request**: - - POST /v1.19/containers/e90e34656806/exec HTTP/1.1 - Content-Type: application/json - - { - "AttachStdin": true, - "AttachStdout": true, - "AttachStderr": true, - "Cmd": ["sh"], - "Tty": true, - "User": "123:456" - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id": "f90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **AttachStdin** - Boolean value, attaches to `stdin` of the `exec` command. -- **AttachStdout** - Boolean value, attaches to `stdout` of the `exec` command. -- **AttachStderr** - Boolean value, attaches to `stderr` of the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. -- **Cmd** - Command to run specified as a string or an array of strings. -- **User** - A string value specifying the user, and optionally, group to run - the exec process inside the container. Format is one of: `"user"`, - `"user:group"`, `"uid"`, or `"uid:gid"`. - -**Status codes**: - -- **201** – no error -- **404** – no such container - -#### Exec Start - -`POST /exec/(id)/start` - -Starts a previously set up `exec` instance `id`. If `detach` is true, this API -returns after starting the `exec` command. Otherwise, this API sets up an -interactive session with the `exec` command. - -**Example request**: - - POST /v1.19/exec/e90e34656806/start HTTP/1.1 - Content-Type: application/json - - { - "Detach": false, - "Tty": false - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/vnd.docker.raw-stream - - {% raw %} - {{ STREAM }} - {% endraw %} - -**JSON parameters**: - -- **Detach** - Detach from the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance - -**Stream details**: - -Similar to the stream behavior of `POST /containers/(id or name)/attach` API - -#### Exec Resize - -`POST /exec/(id)/resize` - -Resizes the `tty` session used by the `exec` command `id`. The unit is number of characters. -This API is valid only if `tty` was specified as part of creating and starting the `exec` command. - -**Example request**: - - POST /v1.19/exec/e90e34656806/resize?h=40&w=80 HTTP/1.1 - Content-Type: text/plain - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: text/plain - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **201** – no error -- **404** – no such exec instance - -#### Exec Inspect - -`GET /exec/(id)/json` - -Return low-level information about the `exec` command `id`. - -**Example request**: - - GET /v1.19/exec/11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: plain/text - - { - "ID" : "11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39", - "Running" : false, - "ExitCode" : 2, - "ProcessConfig" : { - "privileged" : false, - "user" : "", - "tty" : false, - "entrypoint" : "sh", - "arguments" : [ - "-c", - "exit 2" - ] - }, - "OpenStdin" : false, - "OpenStderr" : false, - "OpenStdout" : false, - "Container" : { - "State" : { - "Running" : true, - "Paused" : false, - "Restarting" : false, - "OOMKilled" : false, - "Pid" : 3650, - "ExitCode" : 0, - "Error" : "", - "StartedAt" : "2014-11-17T22:26:03.717657531Z", - "FinishedAt" : "0001-01-01T00:00:00Z" - }, - "ID" : "8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c", - "Created" : "2014-11-17T22:26:03.626304998Z", - "Path" : "date", - "Args" : [], - "Config" : { - "Hostname" : "8f177a186b97", - "Domainname" : "", - "User" : "", - "AttachStdin" : false, - "AttachStdout" : false, - "AttachStderr" : false, - "PortSpecs": null, - "ExposedPorts" : null, - "Tty" : false, - "OpenStdin" : false, - "StdinOnce" : false, - "Env" : [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], - "Cmd" : [ - "date" - ], - "Image" : "ubuntu", - "Volumes" : null, - "WorkingDir" : "", - "Entrypoint" : null, - "NetworkDisabled" : false, - "MacAddress" : "", - "OnBuild" : null, - "SecurityOpt" : null - }, - "Image" : "5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5", - "NetworkSettings" : { - "IPAddress" : "172.17.0.2", - "IPPrefixLen" : 16, - "MacAddress" : "02:42:ac:11:00:02", - "Gateway" : "172.17.42.1", - "Bridge" : "docker0", - "PortMapping" : null, - "Ports" : {} - }, - "ResolvConfPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/resolv.conf", - "HostnamePath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hostname", - "HostsPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Name" : "/test", - "Driver" : "aufs", - "ExecDriver" : "native-0.2", - "MountLabel" : "", - "ProcessLabel" : "", - "AppArmorProfile" : "", - "RestartCount" : 0, - "Volumes" : {}, - "VolumesRW" : {} - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **500** - server error - -## 3. Going further - -### 3.1 Inside `docker run` - -As an example, the `docker run` command line makes the following API calls: - -- Create the container - -- If the status code is 404, it means the image doesn't exist: - - Try to pull it. - - Then, retry to create the container. - -- Start the container. - -- If you are not in detached mode: -- Attach to the container, using `logs=1` (to have `stdout` and - `stderr` from the container's start) and `stream=1` - -- If in detached mode or only `stdin` is attached, display the container's id. - -### 3.2 Hijacking - -In this version of the API, `/attach`, uses hijacking to transport `stdin`, -`stdout`, and `stderr` on the same socket. - -To hint potential proxies about connection hijacking, Docker client sends -connection upgrade headers similarly to websocket. - - Upgrade: tcp - Connection: Upgrade - -When Docker daemon detects the `Upgrade` header, it switches its status code -from **200 OK** to **101 UPGRADED** and resends the same headers. - - -### 3.3 CORS Requests - -To set cross origin requests to the Engine API please give values to -`--api-cors-header` when running Docker in daemon mode. Set * (asterisk) allows all, -default or blank means CORS disabled - - $ docker -d -H="192.168.1.9:2375" --api-cors-header="http://foo.bar" diff --git a/vendor/github.com/docker/docker/docs/api/v1.20.md b/vendor/github.com/docker/docker/docs/api/v1.20.md deleted file mode 100644 index 2532c49..0000000 --- a/vendor/github.com/docker/docker/docs/api/v1.20.md +++ /dev/null @@ -1,2391 +0,0 @@ ---- -title: "Engine API v1.20" -description: "API Documentation for Docker" -keywords: "API, Docker, rcli, REST, documentation" -redirect_from: -- /engine/reference/api/docker_remote_api_v1.20/ -- /reference/api/docker_remote_api_v1.20/ ---- - - - -## 1. Brief introduction - - - The daemon listens on `unix:///var/run/docker.sock` but you can - [Bind Docker to another host/port or a Unix socket](../reference/commandline/dockerd.md#bind-docker-to-another-host-port-or-a-unix-socket). - - The API tends to be REST. However, for some complex commands, like `attach` - or `pull`, the HTTP connection is hijacked to transport `stdout`, - `stdin` and `stderr`. - -## 2. Endpoints - -### 2.1 Containers - -#### List containers - -`GET /containers/json` - -List containers - -**Example request**: - - GET /v1.20/containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "8dfafdbc3a40", - "Names":["/boring_feynman"], - "Image": "ubuntu:latest", - "Command": "echo 1", - "Created": 1367854155, - "Status": "Exit 0", - "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}], - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "SizeRw": 12288, - "SizeRootFs": 0 - }, - { - "Id": "9cd87474be90", - "Names":["/coolName"], - "Image": "ubuntu:latest", - "Command": "echo 222222", - "Created": 1367854155, - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0 - }, - { - "Id": "3176a2479c92", - "Names":["/sleepy_dog"], - "Image": "ubuntu:latest", - "Command": "echo 3333333333333333", - "Created": 1367854154, - "Status": "Exit 0", - "Ports":[], - "Labels": {}, - "SizeRw":12288, - "SizeRootFs":0 - }, - { - "Id": "4cb07b47f9fb", - "Names":["/running_cat"], - "Image": "ubuntu:latest", - "Command": "echo 444444444444444444444444444444444", - "Created": 1367854152, - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0 - } - ] - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, Show all containers. - Only running containers are shown by default (i.e., this defaults to false) -- **limit** – Show `limit` last created - containers, include non-running ones. -- **since** – Show only containers created since Id, include - non-running ones. -- **before** – Show only containers created before Id, include - non-running ones. -- **size** – 1/True/true or 0/False/false, Show the containers - sizes -- **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: - - `exited=`; -- containers with exit code of `` ; - - `status=`(`created`|`restarting`|`running`|`paused`|`exited`) - - `label=key` or `label="key=value"` of a container label - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **500** – server error - -#### Create a container - -`POST /containers/create` - -Create a container - -**Example request**: - - POST /v1.20/containers/create HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": [ - "FOO=bar", - "BAZ=quux" - ], - "Cmd": [ - "date" - ], - "Entrypoint": null, - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "/volumes/data": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "HostConfig": { - "Binds": ["/tmp:/tmp"], - "Links": ["redis3:redis"], - "LxcConf": {"lxc.utsname":"docker"}, - "Memory": 0, - "MemorySwap": 0, - "CpuShares": 512, - "CpuPeriod": 100000, - "CpuQuota": 50000, - "CpusetCpus": "0,1", - "CpusetMems": "0,1", - "BlkioWeight": 300, - "MemorySwappiness": 60, - "OomKillDisable": false, - "PidMode": "", - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsSearch": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "GroupAdd": ["newgroup"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [], - "CgroupParent": "" - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id":"e90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **Hostname** - A string value containing the hostname to use for the - container. -- **Domainname** - A string value containing the domain name to use - for the container. -- **User** - A string value specifying the user inside the container. -- **AttachStdin** - Boolean value, attaches to `stdin`. -- **AttachStdout** - Boolean value, attaches to `stdout`. -- **AttachStderr** - Boolean value, attaches to `stderr`. -- **Tty** - Boolean value, Attach standard streams to a `tty`, including `stdin` if it is not closed. -- **OpenStdin** - Boolean value, opens `stdin`, -- **StdinOnce** - Boolean value, close `stdin` after the 1 attached client disconnects. -- **Env** - A list of environment variables in the form of `["VAR=value", ...]` -- **Labels** - Adds a map of labels to a container. To specify a map: `{"key":"value", ... }` -- **Cmd** - Command to run specified as a string or an array of strings. -- **Entrypoint** - Set the entry point for the container as a string or an array - of strings. -- **Image** - A string specifying the image name to use for the container. -- **Volumes** - An object mapping mount point paths (strings) inside the - container to empty objects. -- **WorkingDir** - A string specifying the working directory for commands to - run in. -- **NetworkDisabled** - Boolean value, when true disables networking for the - container -- **ExposedPorts** - An object mapping ports to an empty object in the form of: - `"ExposedPorts": { "/: {}" }` -- **HostConfig** - - **Binds** – A list of bind-mounts for this container. Each item is a string in one of these forms: - + `host-src:container-dest` to bind-mount a host path into the - container. Both `host-src`, and `container-dest` must be an - _absolute_ path. - + `host-src:container-dest:ro` to make the bind-mount read-only - inside the container. Both `host-src`, and `container-dest` must be - an _absolute_ path. - - **Links** - A list of links for the container. Each link entry should be - in the form of `container_name:alias`. - - **LxcConf** - LXC specific configurations. These configurations only - work when using the `lxc` execution driver. - - **Memory** - Memory limit in bytes. - - **MemorySwap** - Total memory limit (memory + swap); set `-1` to enable unlimited swap. - You must use this with `memory` and make the swap value larger than `memory`. - - **CpuShares** - An integer value containing the container's CPU Shares - (ie. the relative weight vs other containers). - - **CpuPeriod** - The length of a CPU period in microseconds. - - **CpuQuota** - Microseconds of CPU time that the container can get in a CPU period. - - **CpusetCpus** - String value containing the `cgroups CpusetCpus` to use. - - **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. - - **BlkioWeight** - Block IO weight (relative weight) accepts a weight value between 10 and 1000. - - **MemorySwappiness** - Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. - - **OomKillDisable** - Boolean value, whether to disable OOM Killer for the container or not. - - **PidMode** - Set the PID (Process) Namespace mode for the container; - `"container:"`: joins another container's PID namespace - `"host"`: use the host's PID namespace inside the container - - **PortBindings** - A map of exposed container ports and the host port they - should map to. A JSON object in the form - `{ /: [{ "HostPort": "" }] }` - Take note that `port` is specified as a string and not an integer value. - - **PublishAllPorts** - Allocates a random host port for all of a container's - exposed ports. Specified as a boolean value. - - **Privileged** - Gives the container full access to the host. Specified as - a boolean value. - - **ReadonlyRootfs** - Mount the container's root filesystem as read only. - Specified as a boolean value. - - **Dns** - A list of DNS servers for the container to use. - - **DnsSearch** - A list of DNS search domains - - **ExtraHosts** - A list of hostnames/IP mappings to add to the - container's `/etc/hosts` file. Specified in the form `["hostname:IP"]`. - - **VolumesFrom** - A list of volumes to inherit from another container. - Specified in the form `[:]` - - **CapAdd** - A list of kernel capabilities to add to the container. - - **Capdrop** - A list of kernel capabilities to drop from the container. - - **GroupAdd** - A list of additional groups that the container process will run as - - **RestartPolicy** – The behavior to apply when the container exits. The - value is an object with a `Name` property of either `"always"` to - always restart or `"on-failure"` to restart only when the container - exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` - controls the number of times to retry before giving up. - The default is not to restart. (optional) - An ever increasing delay (double the previous delay, starting at 100mS) - is added before each restart to prevent flooding the server. - - **NetworkMode** - Sets the networking mode for the container. Supported - values are: `bridge`, `host`, `none`, and `container:` - - **Devices** - A list of devices to add to the container specified as a JSON object in the - form - `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` - - **Ulimits** - A list of ulimits to set in the container, specified as - `{ "Name": , "Soft": , "Hard": }`, for example: - `Ulimits: { "Name": "nofile", "Soft": 1024, "Hard": 2048 }` - - **SecurityOpt**: A list of string values to customize labels for MLS - systems, such as SELinux. - - **LogConfig** - Log configuration for the container, specified as a JSON object in the form - `{ "Type": "", "Config": {"key1": "val1"}}`. - Available types: `json-file`, `syslog`, `journald`, `gelf`, `none`. - `json-file` logging driver. - - **CgroupParent** - Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist. - -**Query parameters**: - -- **name** – Assign the specified name to the container. Must - match `/?[a-zA-Z0-9_-]+`. - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such container -- **406** – impossible to attach (container not running) -- **409** – conflict -- **500** – server error - -#### Inspect a container - -`GET /containers/(id or name)/json` - -Return low-level information on the container `id` - -**Example request**: - - GET /v1.20/containers/4fa6e0f0c678/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "AppArmorProfile": "", - "Args": [ - "-c", - "exit 9" - ], - "Config": { - "AttachStderr": true, - "AttachStdin": false, - "AttachStdout": true, - "Cmd": [ - "/bin/sh", - "-c", - "exit 9" - ], - "Domainname": "", - "Entrypoint": null, - "Env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts": null, - "Hostname": "ba033ac44011", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "MacAddress": "", - "NetworkDisabled": false, - "OnBuild": null, - "OpenStdin": false, - "StdinOnce": false, - "Tty": false, - "User": "", - "Volumes": null, - "WorkingDir": "" - }, - "Created": "2015-01-06T15:47:31.485331387Z", - "Driver": "devicemapper", - "ExecDriver": "native-0.2", - "ExecIDs": null, - "HostConfig": { - "Binds": null, - "BlkioWeight": 0, - "CapAdd": null, - "CapDrop": null, - "ContainerIDFile": "", - "CpusetCpus": "", - "CpusetMems": "", - "CpuShares": 0, - "CpuPeriod": 100000, - "Devices": [], - "Dns": null, - "DnsSearch": null, - "ExtraHosts": null, - "IpcMode": "", - "Links": null, - "LxcConf": [], - "Memory": 0, - "MemorySwap": 0, - "OomKillDisable": false, - "NetworkMode": "bridge", - "PidMode": "", - "PortBindings": {}, - "Privileged": false, - "ReadonlyRootfs": false, - "PublishAllPorts": false, - "RestartPolicy": { - "MaximumRetryCount": 2, - "Name": "on-failure" - }, - "LogConfig": { - "Config": null, - "Type": "json-file" - }, - "SecurityOpt": null, - "VolumesFrom": null, - "Ulimits": [{}] - }, - "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname", - "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39", - "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2", - "MountLabel": "", - "Name": "/boring_euclid", - "NetworkSettings": { - "Bridge": "", - "Gateway": "", - "IPAddress": "", - "IPPrefixLen": 0, - "MacAddress": "", - "PortMapping": null, - "Ports": null - }, - "Path": "/bin/sh", - "ProcessLabel": "", - "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf", - "RestartCount": 1, - "State": { - "Error": "", - "ExitCode": 9, - "FinishedAt": "2015-01-06T15:47:32.080254511Z", - "OOMKilled": false, - "Paused": false, - "Pid": 0, - "Restarting": false, - "Running": true, - "StartedAt": "2015-01-06T15:47:32.072697474Z" - }, - "Mounts": [ - { - "Source": "/data", - "Destination": "/data", - "Mode": "ro,Z", - "RW": false - } - ] - } - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### List processes running inside a container - -`GET /containers/(id or name)/top` - -List processes running inside the container `id`. On Unix systems this -is done by running the `ps` command. This endpoint is not -supported on Windows. - -**Example request**: - - GET /v1.20/containers/4fa6e0f0c678/top HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD" - ], - "Processes" : [ - [ - "root", "13642", "882", "0", "17:03", "pts/0", "00:00:00", "/bin/bash" - ], - [ - "root", "13735", "13642", "0", "17:06", "pts/0", "00:00:00", "sleep 10" - ] - ] - } - -**Example request**: - - GET /v1.20/containers/4fa6e0f0c678/top?ps_args=aux HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND" - ] - "Processes" : [ - [ - "root","13642","0.0","0.1","18172","3184","pts/0","Ss","17:03","0:00","/bin/bash" - ], - [ - "root","13895","0.0","0.0","4348","692","pts/0","S+","17:15","0:00","sleep 10" - ] - ], - } - -**Query parameters**: - -- **ps_args** – `ps` arguments to use (e.g., `aux`), defaults to `-ef` - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container logs - -`GET /containers/(id or name)/logs` - -Get `stdout` and `stderr` logs from the container ``id`` - -> **Note**: -> This endpoint works only for containers with the `json-file` or `journald` logging drivers. - -**Example request**: - - GET /v1.20/containers/4fa6e0f0c678/logs?stderr=1&stdout=1×tamps=1&follow=1&tail=10&since=1428990821 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **follow** – 1/True/true or 0/False/false, return stream. Default `false`. -- **stdout** – 1/True/true or 0/False/false, show `stdout` log. Default `false`. -- **stderr** – 1/True/true or 0/False/false, show `stderr` log. Default `false`. -- **since** – UNIX timestamp (integer) to filter logs. Specifying a timestamp - will only output log-entries since that timestamp. Default: 0 (unfiltered) -- **timestamps** – 1/True/true or 0/False/false, print timestamps for - every log line. Default `false`. -- **tail** – Output specified number of lines at the end of logs: `all` or ``. Default all. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **404** – no such container -- **500** – server error - -#### Inspect changes on a container's filesystem - -`GET /containers/(id or name)/changes` - -Inspect changes on container `id`'s filesystem - -**Example request**: - - GET /v1.20/containers/4fa6e0f0c678/changes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Path": "/dev", - "Kind": 0 - }, - { - "Path": "/dev/kmsg", - "Kind": 1 - }, - { - "Path": "/test", - "Kind": 1 - } - ] - -Values for `Kind`: - -- `0`: Modify -- `1`: Add -- `2`: Delete - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Export a container - -`GET /containers/(id or name)/export` - -Export the contents of container `id` - -**Example request**: - - GET /v1.20/containers/4fa6e0f0c678/export HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/octet-stream - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container stats based on resource usage - -`GET /containers/(id or name)/stats` - -This endpoint returns a live stream of a container's resource usage statistics. - -**Example request**: - - GET /v1.20/containers/redis1/stats HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "read" : "2015-01-08T22:57:31.547920715Z", - "network" : { - "rx_dropped" : 0, - "rx_bytes" : 648, - "rx_errors" : 0, - "tx_packets" : 8, - "tx_dropped" : 0, - "rx_packets" : 8, - "tx_errors" : 0, - "tx_bytes" : 648 - }, - "memory_stats" : { - "stats" : { - "total_pgmajfault" : 0, - "cache" : 0, - "mapped_file" : 0, - "total_inactive_file" : 0, - "pgpgout" : 414, - "rss" : 6537216, - "total_mapped_file" : 0, - "writeback" : 0, - "unevictable" : 0, - "pgpgin" : 477, - "total_unevictable" : 0, - "pgmajfault" : 0, - "total_rss" : 6537216, - "total_rss_huge" : 6291456, - "total_writeback" : 0, - "total_inactive_anon" : 0, - "rss_huge" : 6291456, - "hierarchical_memory_limit" : 67108864, - "total_pgfault" : 964, - "total_active_file" : 0, - "active_anon" : 6537216, - "total_active_anon" : 6537216, - "total_pgpgout" : 414, - "total_cache" : 0, - "inactive_anon" : 0, - "active_file" : 0, - "pgfault" : 964, - "inactive_file" : 0, - "total_pgpgin" : 477 - }, - "max_usage" : 6651904, - "usage" : 6537216, - "failcnt" : 0, - "limit" : 67108864 - }, - "blkio_stats" : {}, - "cpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24472255, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100215355, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 739306590000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - }, - "precpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24350896, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100093996, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 9492140000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - } - } - -The precpu_stats is the cpu statistic of last read, which is used for calculating the cpu usage percent. It is not the exact copy of the “cpu_stats” field. - -**Query parameters**: - -- **stream** – 1/True/true or 0/False/false, pull stats once then disconnect. Default `true`. - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Resize a container TTY - -`POST /containers/(id or name)/resize?h=&w=` - -Resize the TTY for container with `id`. You must restart the container for the resize to take effect. - -**Example request**: - - POST /v1.20/containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **200** – no error -- **404** – No such container -- **500** – Cannot resize container - -#### Start a container - -`POST /containers/(id or name)/start` - -Start the container `id` - -> **Note**: -> For backwards compatibility, this endpoint accepts a `HostConfig` as JSON-encoded request body. -> See [create a container](#create-a-container) for details. - -**Example request**: - - POST /v1.20/containers/e90e34656806/start HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **304** – container already started -- **404** – no such container -- **500** – server error - -#### Stop a container - -`POST /containers/(id or name)/stop` - -Stop the container `id` - -**Example request**: - - POST /v1.20/containers/e90e34656806/stop?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **304** – container already stopped -- **404** – no such container -- **500** – server error - -#### Restart a container - -`POST /containers/(id or name)/restart` - -Restart the container `id` - -**Example request**: - - POST /v1.20/containers/e90e34656806/restart?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Kill a container - -`POST /containers/(id or name)/kill` - -Kill the container `id` - -**Example request**: - - POST /v1.20/containers/e90e34656806/kill HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **signal** - Signal to send to the container: integer or string like `SIGINT`. - When not set, `SIGKILL` is assumed and the call waits for the container to exit. - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Rename a container - -`POST /containers/(id or name)/rename` - -Rename the container `id` to a `new_name` - -**Example request**: - - POST /v1.20/containers/e90e34656806/rename?name=new_name HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **name** – new name for the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **409** - conflict name already assigned -- **500** – server error - -#### Pause a container - -`POST /containers/(id or name)/pause` - -Pause the container `id` - -**Example request**: - - POST /v1.20/containers/e90e34656806/pause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Unpause a container - -`POST /containers/(id or name)/unpause` - -Unpause the container `id` - -**Example request**: - - POST /v1.20/containers/e90e34656806/unpause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Attach to a container - -`POST /containers/(id or name)/attach` - -Attach to the container `id` - -**Example request**: - - POST /v1.20/containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -**Stream details**: - -When using the TTY setting is enabled in -[`POST /containers/create` -](#create-a-container), -the stream is the raw data from the process PTY and client's `stdin`. -When the TTY is disabled, then the stream is multiplexed to separate -`stdout` and `stderr`. - -The format is a **Header** and a **Payload** (frame). - -**HEADER** - -The header contains the information which the stream writes (`stdout` or -`stderr`). It also contains the size of the associated frame encoded in the -last four bytes (`uint32`). - -It is encoded on the first eight bytes like this: - - header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} - -`STREAM_TYPE` can be: - -- 0: `stdin` (is written on `stdout`) -- 1: `stdout` -- 2: `stderr` - -`SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of -the `uint32` size encoded as big endian. - -**PAYLOAD** - -The payload is the raw stream. - -**IMPLEMENTATION** - -The simplest way to implement the Attach protocol is the following: - - 1. Read eight bytes. - 2. Choose `stdout` or `stderr` depending on the first byte. - 3. Extract the frame size from the last four bytes. - 4. Read the extracted size and output it on the correct output. - 5. Goto 1. - -#### Attach to a container (websocket) - -`GET /containers/(id or name)/attach/ws` - -Attach to the container `id` via websocket - -Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455) - -**Example request** - - GET /v1.20/containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 - -**Example response** - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -#### Wait a container - -`POST /containers/(id or name)/wait` - -Block until container `id` stops, then returns the exit code - -**Example request**: - - POST /v1.20/containers/16253994b7c4/wait HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"StatusCode": 0} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Remove a container - -`DELETE /containers/(id or name)` - -Remove the container `id` from the filesystem - -**Example request**: - - DELETE /v1.20/containers/16253994b7c4?v=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **v** – 1/True/true or 0/False/false, Remove the volumes - associated to the container. Default `false`. -- **force** - 1/True/true or 0/False/false, Kill then remove the container. - Default `false`. - -**Status codes**: - -- **204** – no error -- **400** – bad parameter -- **404** – no such container -- **409** – conflict -- **500** – server error - -#### Copy files or folders from a container - -`POST /containers/(id or name)/copy` - -Copy files or folders of container `id` - -**Deprecated** in favor of the `archive` endpoint below. - -**Example request**: - - POST /v1.20/containers/4fa6e0f0c678/copy HTTP/1.1 - Content-Type: application/json - - { - "Resource": "test.txt" - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Retrieving information about files and folders in a container - -`HEAD /containers/(id or name)/archive` - -See the description of the `X-Docker-Container-Path-Stat` header in the -following section. - -#### Get an archive of a filesystem resource in a container - -`GET /containers/(id or name)/archive` - -Get a tar archive of a resource in the filesystem of container `id`. - -**Query parameters**: - -- **path** - resource in the container's filesystem to archive. Required. - - If not an absolute path, it is relative to the container's root directory. - The resource specified by **path** must exist. To assert that the resource - is expected to be a directory, **path** should end in `/` or `/.` - (assuming a path separator of `/`). If **path** ends in `/.` then this - indicates that only the contents of the **path** directory should be - copied. A symlink is always resolved to its target. - - > **Note**: It is not possible to copy certain system files such as resources - > under `/proc`, `/sys`, `/dev`, and mounts created by the user in the - > container. - -**Example request**: - - GET /v1.20/containers/8cce319429b2/archive?path=/root HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - X-Docker-Container-Path-Stat: eyJuYW1lIjoicm9vdCIsInNpemUiOjQwOTYsIm1vZGUiOjIxNDc0ODQwOTYsIm10aW1lIjoiMjAxNC0wMi0yN1QyMDo1MToyM1oiLCJsaW5rVGFyZ2V0IjoiIn0= - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -On success, a response header `X-Docker-Container-Path-Stat` will be set to a -base64-encoded JSON object containing some filesystem header information about -the archived resource. The above example value would decode to the following -JSON object (whitespace added for readability): - -```json -{ - "name": "root", - "size": 4096, - "mode": 2147484096, - "mtime": "2014-02-27T20:51:23Z", - "linkTarget": "" -} -``` - -A `HEAD` request can also be made to this endpoint if only this information is -desired. - -**Status codes**: - -- **200** - success, returns archive of copied resource -- **400** - client error, bad parameter, details in JSON response body, one of: - - must specify path parameter (**path** cannot be empty) - - not a directory (**path** was asserted to be a directory but exists as a - file) -- **404** - client error, resource not found, one of: - – no such container (container `id` does not exist) - - no such file or directory (**path** does not exist) -- **500** - server error - -#### Extract an archive of files or folders to a directory in a container - -`PUT /containers/(id or name)/archive` - -Upload a tar archive to be extracted to a path in the filesystem of container -`id`. - -**Query parameters**: - -- **path** - path to a directory in the container - to extract the archive's contents into. Required. - - If not an absolute path, it is relative to the container's root directory. - The **path** resource must exist. -- **noOverwriteDirNonDir** - If "1", "true", or "True" then it will be an error - if unpacking the given content would cause an existing directory to be - replaced with a non-directory and vice versa. - -**Example request**: - - PUT /v1.20/containers/8cce319429b2/archive?path=/vol1 HTTP/1.1 - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – the content was extracted successfully -- **400** - client error, bad parameter, details in JSON response body, one of: - - must specify path parameter (**path** cannot be empty) - - not a directory (**path** should be a directory but exists as a file) - - unable to overwrite existing directory with non-directory - (if **noOverwriteDirNonDir**) - - unable to overwrite existing non-directory with directory - (if **noOverwriteDirNonDir**) -- **403** - client error, permission denied, the volume - or container rootfs is marked as read-only. -- **404** - client error, resource not found, one of: - – no such container (container `id` does not exist) - - no such file or directory (**path** resource does not exist) -- **500** – server error - -### 2.2 Images - -#### List Images - -`GET /images/json` - -**Example request**: - - GET /v1.20/images/json?all=0 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "RepoTags": [ - "ubuntu:12.04", - "ubuntu:precise", - "ubuntu:latest" - ], - "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", - "Created": 1365714795, - "Size": 131506275, - "VirtualSize": 131506275, - "Labels": {} - }, - { - "RepoTags": [ - "ubuntu:12.10", - "ubuntu:quantal" - ], - "ParentId": "27cf784147099545", - "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "Created": 1364102658, - "Size": 24653, - "VirtualSize": 180116135, - "Labels": { - "com.example.version": "v1" - } - } - ] - -**Example request, with digest information**: - - GET /v1.20/images/json?digests=1 HTTP/1.1 - -**Example response, with digest information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Created": 1420064636, - "Id": "4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125", - "ParentId": "ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2", - "RepoDigests": [ - "localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags": [ - "localhost:5000/test/busybox:latest", - "playdate:latest" - ], - "Size": 0, - "VirtualSize": 2429728, - "Labels": {} - } - ] - -The response shows a single image `Id` associated with two repositories -(`RepoTags`): `localhost:5000/test/busybox`: and `playdate`. A caller can use -either of the `RepoTags` values `localhost:5000/test/busybox:latest` or -`playdate:latest` to reference the image. - -You can also use `RepoDigests` values to reference an image. In this response, -the array has only one reference and that is to the -`localhost:5000/test/busybox` repository; the `playdate` repository has no -digest. You can reference this digest using the value: -`localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d...` - -See the `docker run` and `docker build` commands for examples of digest and tag -references on the command line. - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, default false -- **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: - - `dangling=true` - - `label=key` or `label="key=value"` of an image label -- **filter** - only return images with the specified name - -#### Build image from a Dockerfile - -`POST /build` - -Build an image from a Dockerfile - -**Example request**: - - POST /v1.20/build HTTP/1.1 - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"stream": "Step 1/5..."} - {"stream": "..."} - {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} - -The input stream must be a `tar` archive compressed with one of the -following algorithms: `identity` (no compression), `gzip`, `bzip2`, `xz`. - -The archive must include a build instructions file, typically called -`Dockerfile` at the archive's root. The `dockerfile` parameter may be -used to specify a different build instructions file. To do this, its value must be -the path to the alternate build instructions file to use. - -The archive may include any number of other files, -which are accessible in the build context (See the [*ADD build -command*](../reference/builder.md#add)). - -The Docker daemon performs a preliminary validation of the `Dockerfile` before -starting the build, and returns an error if the syntax is incorrect. After that, -each instruction is run one-by-one until the ID of the new image is output. - -The build is canceled if the client drops the connection by quitting -or being killed. - -**Query parameters**: - -- **dockerfile** - Path within the build context to the `Dockerfile`. This is - ignored if `remote` is specified and points to an external `Dockerfile`. -- **t** – A name and optional tag to apply to the image in the `name:tag` format. - If you omit the `tag` the default `latest` value is assumed. -- **remote** – A Git repository URI or HTTP/HTTPS context URI. If the - URI points to a single text file, the file's contents are placed into - a file called `Dockerfile` and the image is built from that file. If - the URI points to a tarball, the file is downloaded by the daemon and - the contents therein used as the context for the build. If the URI - points to a tarball and the `dockerfile` parameter is also specified, - there must be a file with the corresponding path inside the tarball. -- **q** – Suppress verbose build output. -- **nocache** – Do not use the cache when building the image. -- **pull** - Attempt to pull the image even if an older image exists locally. -- **rm** - Remove intermediate containers after a successful build (default behavior). -- **forcerm** - Always remove intermediate containers (includes `rm`). -- **memory** - Set memory limit for build. -- **memswap** - Total memory (memory + swap), `-1` to enable unlimited swap. -- **cpushares** - CPU shares (relative weight). -- **cpusetcpus** - CPUs in which to allow execution (e.g., `0-3`, `0,1`). -- **cpuperiod** - The length of a CPU period in microseconds. -- **cpuquota** - Microseconds of CPU time that the container can get in a CPU period. - -**Request Headers**: - -- **Content-type** – Set to `"application/tar"`. -- **X-Registry-Config** – A base64-url-safe-encoded Registry Auth Config JSON - object with the following structure: - - { - "docker.example.com": { - "username": "janedoe", - "password": "hunter2" - }, - "https://index.docker.io/v1/": { - "username": "mobydock", - "password": "conta1n3rize14" - } - } - - This object maps the hostname of a registry to an object containing the - "username" and "password" for that registry. Multiple registries may - be specified as the build may be based on an image requiring - authentication to pull from any arbitrary registry. Only the registry - domain name (and port if not the default "443") are required. However - (for legacy reasons) the "official" Docker, Inc. hosted registry must - be specified with both a "https://" prefix and a "/v1/" suffix even - though Docker will prefer to use the v2 registry API. - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Create an image - -`POST /images/create` - -Create an image either by pulling it from the registry or by importing it - -**Example request**: - - POST /v1.20/images/create?fromImage=busybox&tag=latest HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pulling..."} - {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} - {"error": "Invalid..."} - ... - -When using this endpoint to pull an image from the registry, the -`X-Registry-Auth` header can be used to include -a base64-encoded AuthConfig object. - -**Query parameters**: - -- **fromImage** – Name of the image to pull. -- **fromSrc** – Source to import. The value may be a URL from which the image - can be retrieved or `-` to read the image from the request body. -- **repo** – Repository name. -- **tag** – Tag. If empty when pulling an image, this causes all tags - for the given image to be pulled. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object - -**Status codes**: - -- **200** – no error -- **404** - repository does not exist or no read access -- **500** – server error - - - -#### Inspect an image - -`GET /images/(name)/json` - -Return low-level information on the image `name` - -**Example request**: - - GET /v1.20/images/ubuntu/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Created": "2013-03-23T22:24:18.818426-07:00", - "Container": "3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", - "ContainerConfig": { - "Hostname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": false, - "AttachStderr": false, - "Tty": true, - "OpenStdin": true, - "StdinOnce": false, - "Env": null, - "Cmd": ["/bin/bash"], - "Dns": null, - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": null, - "VolumesFrom": "", - "WorkingDir": "" - }, - "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "Parent": "27cf784147099545", - "Size": 6824592 - } - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Get the history of an image - -`GET /images/(name)/history` - -Return the history of the image `name` - -**Example request**: - - GET /v1.20/images/ubuntu/history HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710", - "Created": 1398108230, - "CreatedBy": "/bin/sh -c #(nop) ADD file:eb15dbd63394e063b805a3c32ca7bf0266ef64676d5a6fab4801f2e81e2a5148 in /", - "Tags": [ - "ubuntu:lucid", - "ubuntu:10.04" - ], - "Size": 182964289, - "Comment": "" - }, - { - "Id": "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8", - "Created": 1398108222, - "CreatedBy": "/bin/sh -c #(nop) MAINTAINER Tianon Gravi - mkimage-debootstrap.sh -i iproute,iputils-ping,ubuntu-minimal -t lucid.tar.xz lucid http://archive.ubuntu.com/ubuntu/", - "Tags": null, - "Size": 0, - "Comment": "" - }, - { - "Id": "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158", - "Created": 1371157430, - "CreatedBy": "", - "Tags": [ - "scratch12:latest", - "scratch:latest" - ], - "Size": 0, - "Comment": "Imported from -" - } - ] - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Push an image on the registry - -`POST /images/(name)/push` - -Push the image `name` on the registry - -**Example request**: - - POST /v1.20/images/test/push HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pushing..."} - {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} - {"error": "Invalid..."} - ... - -If you wish to push an image on to a private registry, that image must already have a tag -into a repository which references that registry `hostname` and `port`. This repository name should -then be used in the URL. This duplicates the command line's flow. - -**Example request**: - - POST /v1.20/images/registry.acme.com:5000/test/push HTTP/1.1 - - -**Query parameters**: - -- **tag** – The tag to associate with the image on the registry. This is optional. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object. - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Tag an image into a repository - -`POST /images/(name)/tag` - -Tag the image `name` into a repository - -**Example request**: - - POST /v1.20/images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 - -**Example response**: - - HTTP/1.1 201 Created - -**Query parameters**: - -- **repo** – The repository to tag in -- **force** – 1/True/true or 0/False/false, default false -- **tag** - The new tag name - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Remove an image - -`DELETE /images/(name)` - -Remove the image `name` from the filesystem - -**Example request**: - - DELETE /v1.20/images/test HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-type: application/json - - [ - {"Untagged": "3e2f21a89f"}, - {"Deleted": "3e2f21a89f"}, - {"Deleted": "53b4f83ac9"} - ] - -**Query parameters**: - -- **force** – 1/True/true or 0/False/false, default false -- **noprune** – 1/True/true or 0/False/false, default false - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Search images - -`GET /images/search` - -Search for an image on [Docker Hub](https://hub.docker.com). - -> **Note**: -> The response keys have changed from API v1.6 to reflect the JSON -> sent by the registry server to the docker daemon's request. - -**Example request**: - - GET /v1.20/images/search?term=sshd HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "wma55/u1210sshd", - "star_count": 0 - }, - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "jdswinbank/sshd", - "star_count": 0 - }, - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "vgauthier/sshd", - "star_count": 0 - } - ... - ] - -**Query parameters**: - -- **term** – term to search - -**Status codes**: - -- **200** – no error -- **500** – server error - -### 2.3 Misc - -#### Check auth configuration - -`POST /auth` - -Get the default username and email - -**Example request**: - - POST /v1.20/auth HTTP/1.1 - Content-Type: application/json - - { - "username": "hannibal", - "password": "xxxx", - "email": "hannibal@a-team.com", - "serveraddress": "https://index.docker.io/v1/" - } - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – no error -- **204** – no error -- **500** – server error - -#### Display system-wide information - -`GET /info` - -Display system-wide information - -**Example request**: - - GET /v1.20/info HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Containers": 11, - "CpuCfsPeriod": true, - "CpuCfsQuota": true, - "Debug": false, - "DockerRootDir": "/var/lib/docker", - "Driver": "btrfs", - "DriverStatus": [[""]], - "ExecutionDriver": "native-0.1", - "ExperimentalBuild": false, - "HttpProxy": "http://test:test@localhost:8080", - "HttpsProxy": "https://test:test@localhost:8080", - "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", - "IPv4Forwarding": true, - "Images": 16, - "IndexServerAddress": "https://index.docker.io/v1/", - "InitPath": "/usr/bin/docker", - "InitSha1": "", - "KernelVersion": "3.12.0-1-amd64", - "Labels": [ - "storage=ssd" - ], - "MemTotal": 2099236864, - "MemoryLimit": true, - "NCPU": 1, - "NEventsListener": 0, - "NFd": 11, - "NGoroutines": 21, - "Name": "prod-server-42", - "NoProxy": "9.81.1.160", - "OomKillDisable": true, - "OperatingSystem": "Boot2Docker", - "RegistryConfig": { - "IndexConfigs": { - "docker.io": { - "Mirrors": null, - "Name": "docker.io", - "Official": true, - "Secure": true - } - }, - "InsecureRegistryCIDRs": [ - "127.0.0.0/8" - ] - }, - "SwapLimit": false, - "SystemTime": "2015-03-10T11:11:23.730591467-07:00" - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Show the docker version information - -`GET /version` - -Show the docker version information - -**Example request**: - - GET /v1.20/version HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Version": "1.5.0", - "Os": "linux", - "KernelVersion": "3.18.5-tinycore64", - "GoVersion": "go1.4.1", - "GitCommit": "a8a31ef", - "Arch": "amd64", - "ApiVersion": "1.20", - "Experimental": false - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Ping the docker server - -`GET /_ping` - -Ping the docker server - -**Example request**: - - GET /v1.20/_ping HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: text/plain - - OK - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a new image from a container's changes - -`POST /commit` - -Create a new image from a container's changes - -**Example request**: - - POST /v1.20/commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Mounts": [ - { - "Source": "/data", - "Destination": "/data", - "Mode": "ro,Z", - "RW": false - } - ], - "Labels": { - "key1": "value1", - "key2": "value2" - }, - "WorkingDir": "", - "NetworkDisabled": false, - "ExposedPorts": { - "22/tcp": {} - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - {"Id": "596069db4bf5"} - -**JSON parameters**: - -- **config** - the container's configuration - -**Query parameters**: - -- **container** – source container -- **repo** – repository -- **tag** – tag -- **comment** – commit message -- **author** – author (e.g., "John Hannibal Smith - <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") -- **pause** – 1/True/true or 0/False/false, whether to pause the container before committing -- **changes** – Dockerfile instructions to apply while committing - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **500** – server error - -#### Monitor Docker's events - -`GET /events` - -Get container events from docker, in real time via streaming. - -Docker containers report the following events: - - attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause - -Docker images report the following events: - - delete, import, pull, push, tag, untag - -**Example request**: - - GET /v1.20/events?since=1374067924 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "create", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067924} - {"status": "start", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067924} - {"status": "stop", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067966} - {"status": "destroy", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067970} - -**Query parameters**: - -- **since** – Timestamp. Show all events created since timestamp and then stream -- **until** – Timestamp. Show events created until given timestamp and stop streaming -- **filters** – A json encoded value of the filters (a map[string][]string) to process on the event list. Available filters: - - `container=`; -- container to filter - - `event=`; -- event to filter - - `image=`; -- image to filter - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images in a repository - -`GET /images/(name)/get` - -Get a tarball containing all images and metadata for the repository specified -by `name`. - -If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image -(and its parents) are returned. If `name` is an image ID, similarly only that -image (and its parents) are returned, but with the exclusion of the -'repositories' file in the tarball, as there were no image names referenced. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.20/images/ubuntu/get - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images - -`GET /images/get` - -Get a tarball containing all images and metadata for one or more repositories. - -For each value of the `names` parameter: if it is a specific name and tag (e.g. -`ubuntu:latest`), then only that image (and its parents) are returned; if it is -an image ID, similarly only that image (and its parents) are returned and there -would be no names referenced in the 'repositories' file for this image ID. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.20/images/get?names=myname%2Fmyapp%3Alatest&names=busybox - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Load a tarball with a set of images and tags into docker - -`POST /images/load` - -Load a set of images and tags into a Docker repository. -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - POST /v1.20/images/load - Content-Type: application/x-tar - - Tarball in body - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Image tarball format - -An image tarball contains one directory per image layer (named using its long ID), -each containing these files: - -- `VERSION`: currently `1.0` - the file format version -- `json`: detailed layer information, similar to `docker inspect layer_id` -- `layer.tar`: A tarfile containing the filesystem changes in this layer - -The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories -for storing attribute changes and deletions. - -If the tarball defines a repository, the tarball should also include a `repositories` file at -the root that contains a list of repository and tag names mapped to layer IDs. - -``` -{"hello-world": - {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} -} -``` - -#### Exec Create - -`POST /containers/(id or name)/exec` - -Sets up an exec instance in a running container `id` - -**Example request**: - - POST /v1.20/containers/e90e34656806/exec HTTP/1.1 - Content-Type: application/json - - { - "AttachStdin": true, - "AttachStdout": true, - "AttachStderr": true, - "Cmd": ["sh"], - "Tty": true, - "User": "123:456" - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id": "f90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **AttachStdin** - Boolean value, attaches to `stdin` of the `exec` command. -- **AttachStdout** - Boolean value, attaches to `stdout` of the `exec` command. -- **AttachStderr** - Boolean value, attaches to `stderr` of the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. -- **Cmd** - Command to run specified as a string or an array of strings. -- **User** - A string value specifying the user, and optionally, group to run - the exec process inside the container. Format is one of: `"user"`, - `"user:group"`, `"uid"`, or `"uid:gid"`. - -**Status codes**: - -- **201** – no error -- **404** – no such container - -#### Exec Start - -`POST /exec/(id)/start` - -Starts a previously set up `exec` instance `id`. If `detach` is true, this API -returns after starting the `exec` command. Otherwise, this API sets up an -interactive session with the `exec` command. - -**Example request**: - - POST /v1.20/exec/e90e34656806/start HTTP/1.1 - Content-Type: application/json - - { - "Detach": false, - "Tty": false - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/vnd.docker.raw-stream - - {% raw %} - {{ STREAM }} - {% endraw %} - -**JSON parameters**: - -- **Detach** - Detach from the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance - -**Stream details**: - -Similar to the stream behavior of `POST /containers/(id or name)/attach` API - -#### Exec Resize - -`POST /exec/(id)/resize` - -Resizes the `tty` session used by the `exec` command `id`. The unit is number of characters. -This API is valid only if `tty` was specified as part of creating and starting the `exec` command. - -**Example request**: - - POST /v1.20/exec/e90e34656806/resize?h=40&w=80 HTTP/1.1 - Content-Type: text/plain - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: text/plain - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **201** – no error -- **404** – no such exec instance - -#### Exec Inspect - -`GET /exec/(id)/json` - -Return low-level information about the `exec` command `id`. - -**Example request**: - - GET /v1.20/exec/11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: plain/text - - { - "ID" : "11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39", - "Running" : false, - "ExitCode" : 2, - "ProcessConfig" : { - "privileged" : false, - "user" : "", - "tty" : false, - "entrypoint" : "sh", - "arguments" : [ - "-c", - "exit 2" - ] - }, - "OpenStdin" : false, - "OpenStderr" : false, - "OpenStdout" : false, - "Container" : { - "State" : { - "Running" : true, - "Paused" : false, - "Restarting" : false, - "OOMKilled" : false, - "Pid" : 3650, - "ExitCode" : 0, - "Error" : "", - "StartedAt" : "2014-11-17T22:26:03.717657531Z", - "FinishedAt" : "0001-01-01T00:00:00Z" - }, - "ID" : "8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c", - "Created" : "2014-11-17T22:26:03.626304998Z", - "Path" : "date", - "Args" : [], - "Config" : { - "Hostname" : "8f177a186b97", - "Domainname" : "", - "User" : "", - "AttachStdin" : false, - "AttachStdout" : false, - "AttachStderr" : false, - "ExposedPorts" : null, - "Tty" : false, - "OpenStdin" : false, - "StdinOnce" : false, - "Env" : [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], - "Cmd" : [ - "date" - ], - "Image" : "ubuntu", - "Volumes" : null, - "WorkingDir" : "", - "Entrypoint" : null, - "NetworkDisabled" : false, - "MacAddress" : "", - "OnBuild" : null, - "SecurityOpt" : null - }, - "Image" : "5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5", - "NetworkSettings" : { - "IPAddress" : "172.17.0.2", - "IPPrefixLen" : 16, - "MacAddress" : "02:42:ac:11:00:02", - "Gateway" : "172.17.42.1", - "Bridge" : "docker0", - "PortMapping" : null, - "Ports" : {} - }, - "ResolvConfPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/resolv.conf", - "HostnamePath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hostname", - "HostsPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Name" : "/test", - "Driver" : "aufs", - "ExecDriver" : "native-0.2", - "MountLabel" : "", - "ProcessLabel" : "", - "AppArmorProfile" : "", - "RestartCount" : 0, - "Mounts" : [] - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **500** - server error - -## 3. Going further - -### 3.1 Inside `docker run` - -As an example, the `docker run` command line makes the following API calls: - -- Create the container - -- If the status code is 404, it means the image doesn't exist: - - Try to pull it. - - Then, retry to create the container. - -- Start the container. - -- If you are not in detached mode: -- Attach to the container, using `logs=1` (to have `stdout` and - `stderr` from the container's start) and `stream=1` - -- If in detached mode or only `stdin` is attached, display the container's id. - -### 3.2 Hijacking - -In this version of the API, `/attach`, uses hijacking to transport `stdin`, -`stdout`, and `stderr` on the same socket. - -To hint potential proxies about connection hijacking, Docker client sends -connection upgrade headers similarly to websocket. - - Upgrade: tcp - Connection: Upgrade - -When Docker daemon detects the `Upgrade` header, it switches its status code -from **200 OK** to **101 UPGRADED** and resends the same headers. - - -### 3.3 CORS Requests - -To set cross origin requests to the Engine API please give values to -`--api-cors-header` when running Docker in daemon mode. Set * (asterisk) allows all, -default or blank means CORS disabled - - $ dockerd -H="192.168.1.9:2375" --api-cors-header="http://foo.bar" diff --git a/vendor/github.com/docker/docker/docs/api/v1.21.md b/vendor/github.com/docker/docker/docs/api/v1.21.md deleted file mode 100644 index b4f54b7..0000000 --- a/vendor/github.com/docker/docker/docs/api/v1.21.md +++ /dev/null @@ -1,2969 +0,0 @@ ---- -title: "Engine API v1.21" -description: "API Documentation for Docker" -keywords: "API, Docker, rcli, REST, documentation" -redirect_from: -- /engine/reference/api/docker_remote_api_v1.21/ -- /reference/api/docker_remote_api_v1.21/ ---- - - - -## 1. Brief introduction - - - The daemon listens on `unix:///var/run/docker.sock` but you can - [Bind Docker to another host/port or a Unix socket](../reference/commandline/dockerd.md#bind-docker-to-another-host-port-or-a-unix-socket). - - The API tends to be REST. However, for some complex commands, like `attach` - or `pull`, the HTTP connection is hijacked to transport `stdout`, - `stdin` and `stderr`. - - When the client API version is newer than the daemon's, these calls return an HTTP - `400 Bad Request` error message. - -## 2. Endpoints - -### 2.1 Containers - -#### List containers - -`GET /containers/json` - -List containers - -**Example request**: - - GET /v1.21/containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "8dfafdbc3a40", - "Names":["/boring_feynman"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 1", - "Created": 1367854155, - "Status": "Exit 0", - "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}], - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "SizeRw": 12288, - "SizeRootFs": 0 - }, - { - "Id": "9cd87474be90", - "Names":["/coolName"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 222222", - "Created": 1367854155, - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0 - }, - { - "Id": "3176a2479c92", - "Names":["/sleepy_dog"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 3333333333333333", - "Created": 1367854154, - "Status": "Exit 0", - "Ports":[], - "Labels": {}, - "SizeRw":12288, - "SizeRootFs":0 - }, - { - "Id": "4cb07b47f9fb", - "Names":["/running_cat"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 444444444444444444444444444444444", - "Created": 1367854152, - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0 - } - ] - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, Show all containers. - Only running containers are shown by default (i.e., this defaults to false) -- **limit** – Show `limit` last created - containers, include non-running ones. -- **since** – Show only containers created since Id, include - non-running ones. -- **before** – Show only containers created before Id, include - non-running ones. -- **size** – 1/True/true or 0/False/false, Show the containers - sizes -- **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: - - `exited=`; -- containers with exit code of `` ; - - `status=`(`created`|`restarting`|`running`|`paused`|`exited`) - - `label=key` or `label="key=value"` of a container label - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **500** – server error - -#### Create a container - -`POST /containers/create` - -Create a container - -**Example request**: - - POST /v1.21/containers/create HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": [ - "FOO=bar", - "BAZ=quux" - ], - "Cmd": [ - "date" - ], - "Entrypoint": null, - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "/volumes/data": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "StopSignal": "SIGTERM", - "HostConfig": { - "Binds": ["/tmp:/tmp"], - "Links": ["redis3:redis"], - "LxcConf": {"lxc.utsname":"docker"}, - "Memory": 0, - "MemorySwap": 0, - "MemoryReservation": 0, - "KernelMemory": 0, - "CpuShares": 512, - "CpuPeriod": 100000, - "CpuQuota": 50000, - "CpusetCpus": "0,1", - "CpusetMems": "0,1", - "BlkioWeight": 300, - "MemorySwappiness": 60, - "OomKillDisable": false, - "PidMode": "", - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsOptions": [""], - "DnsSearch": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "GroupAdd": ["newgroup"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [], - "CgroupParent": "", - "VolumeDriver": "" - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id":"e90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **Hostname** - A string value containing the hostname to use for the - container. -- **Domainname** - A string value containing the domain name to use - for the container. -- **User** - A string value specifying the user inside the container. -- **AttachStdin** - Boolean value, attaches to `stdin`. -- **AttachStdout** - Boolean value, attaches to `stdout`. -- **AttachStderr** - Boolean value, attaches to `stderr`. -- **Tty** - Boolean value, Attach standard streams to a `tty`, including `stdin` if it is not closed. -- **OpenStdin** - Boolean value, opens `stdin`, -- **StdinOnce** - Boolean value, close `stdin` after the 1 attached client disconnects. -- **Env** - A list of environment variables in the form of `["VAR=value", ...]` -- **Labels** - Adds a map of labels to a container. To specify a map: `{"key":"value", ... }` -- **Cmd** - Command to run specified as a string or an array of strings. -- **Entrypoint** - Set the entry point for the container as a string or an array - of strings. -- **Image** - A string specifying the image name to use for the container. -- **Volumes** - An object mapping mount point paths (strings) inside the - container to empty objects. -- **WorkingDir** - A string specifying the working directory for commands to - run in. -- **NetworkDisabled** - Boolean value, when true disables networking for the - container -- **ExposedPorts** - An object mapping ports to an empty object in the form of: - `"ExposedPorts": { "/: {}" }` -- **StopSignal** - Signal to stop a container as a string or unsigned integer. `SIGTERM` by default. -- **HostConfig** - - **Binds** – A list of volume bindings for this container. Each volume binding is a string in one of these forms: - + `host-src:container-dest` to bind-mount a host path into the - container. Both `host-src`, and `container-dest` must be an - _absolute_ path. - + `host-src:container-dest:ro` to make the bind-mount read-only - inside the container. Both `host-src`, and `container-dest` must be - an _absolute_ path. - + `volume-name:container-dest` to bind-mount a volume managed by a - volume driver into the container. `container-dest` must be an - _absolute_ path. - + `volume-name:container-dest:ro` to mount the volume read-only - inside the container. `container-dest` must be an _absolute_ path. - - **Links** - A list of links for the container. Each link entry should be - in the form of `container_name:alias`. - - **LxcConf** - LXC specific configurations. These configurations only - work when using the `lxc` execution driver. - - **Memory** - Memory limit in bytes. - - **MemorySwap** - Total memory limit (memory + swap); set `-1` to enable unlimited swap. - You must use this with `memory` and make the swap value larger than `memory`. - - **MemoryReservation** - Memory soft limit in bytes. - - **KernelMemory** - Kernel memory limit in bytes. - - **CpuShares** - An integer value containing the container's CPU Shares - (ie. the relative weight vs other containers). - - **CpuPeriod** - The length of a CPU period in microseconds. - - **CpuQuota** - Microseconds of CPU time that the container can get in a CPU period. - - **CpusetCpus** - String value containing the `cgroups CpusetCpus` to use. - - **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. - - **BlkioWeight** - Block IO weight (relative weight) accepts a weight value between 10 and 1000. - - **MemorySwappiness** - Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. - - **OomKillDisable** - Boolean value, whether to disable OOM Killer for the container or not. - - **PidMode** - Set the PID (Process) Namespace mode for the container; - `"container:"`: joins another container's PID namespace - `"host"`: use the host's PID namespace inside the container - - **PortBindings** - A map of exposed container ports and the host port they - should map to. A JSON object in the form - `{ /: [{ "HostPort": "" }] }` - Take note that `port` is specified as a string and not an integer value. - - **PublishAllPorts** - Allocates a random host port for all of a container's - exposed ports. Specified as a boolean value. - - **Privileged** - Gives the container full access to the host. Specified as - a boolean value. - - **ReadonlyRootfs** - Mount the container's root filesystem as read only. - Specified as a boolean value. - - **Dns** - A list of DNS servers for the container to use. - - **DnsOptions** - A list of DNS options - - **DnsSearch** - A list of DNS search domains - - **ExtraHosts** - A list of hostnames/IP mappings to add to the - container's `/etc/hosts` file. Specified in the form `["hostname:IP"]`. - - **VolumesFrom** - A list of volumes to inherit from another container. - Specified in the form `[:]` - - **CapAdd** - A list of kernel capabilities to add to the container. - - **Capdrop** - A list of kernel capabilities to drop from the container. - - **GroupAdd** - A list of additional groups that the container process will run as - - **RestartPolicy** – The behavior to apply when the container exits. The - value is an object with a `Name` property of either `"always"` to - always restart, `"unless-stopped"` to restart always except when - user has manually stopped the container or `"on-failure"` to restart only when the container - exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` - controls the number of times to retry before giving up. - The default is not to restart. (optional) - An ever increasing delay (double the previous delay, starting at 100mS) - is added before each restart to prevent flooding the server. - - **NetworkMode** - Sets the networking mode for the container. Supported - standard values are: `bridge`, `host`, `none`, and `container:`. Any other value is taken - as a custom network's name to which this container should connect to. - - **Devices** - A list of devices to add to the container specified as a JSON object in the - form - `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` - - **Ulimits** - A list of ulimits to set in the container, specified as - `{ "Name": , "Soft": , "Hard": }`, for example: - `Ulimits: { "Name": "nofile", "Soft": 1024, "Hard": 2048 }` - - **SecurityOpt**: A list of string values to customize labels for MLS - systems, such as SELinux. - - **LogConfig** - Log configuration for the container, specified as a JSON object in the form - `{ "Type": "", "Config": {"key1": "val1"}}`. - Available types: `json-file`, `syslog`, `journald`, `gelf`, `awslogs`, `none`. - `json-file` logging driver. - - **CgroupParent** - Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist. - - **VolumeDriver** - Driver that this container users to mount volumes. - -**Query parameters**: - -- **name** – Assign the specified name to the container. Must - match `/?[a-zA-Z0-9_-]+`. - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such container -- **406** – impossible to attach (container not running) -- **409** – conflict -- **500** – server error - -#### Inspect a container - -`GET /containers/(id or name)/json` - -Return low-level information on the container `id` - -**Example request**: - - GET /v1.21/containers/4fa6e0f0c678/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "AppArmorProfile": "", - "Args": [ - "-c", - "exit 9" - ], - "Config": { - "AttachStderr": true, - "AttachStdin": false, - "AttachStdout": true, - "Cmd": [ - "/bin/sh", - "-c", - "exit 9" - ], - "Domainname": "", - "Entrypoint": null, - "Env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts": null, - "Hostname": "ba033ac44011", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "MacAddress": "", - "NetworkDisabled": false, - "OnBuild": null, - "OpenStdin": false, - "StdinOnce": false, - "Tty": false, - "User": "", - "Volumes": null, - "WorkingDir": "", - "StopSignal": "SIGTERM" - }, - "Created": "2015-01-06T15:47:31.485331387Z", - "Driver": "devicemapper", - "ExecDriver": "native-0.2", - "ExecIDs": null, - "HostConfig": { - "Binds": null, - "BlkioWeight": 0, - "CapAdd": null, - "CapDrop": null, - "ContainerIDFile": "", - "CpusetCpus": "", - "CpusetMems": "", - "CpuShares": 0, - "CpuPeriod": 100000, - "Devices": [], - "Dns": null, - "DnsOptions": null, - "DnsSearch": null, - "ExtraHosts": null, - "IpcMode": "", - "Links": null, - "LxcConf": [], - "Memory": 0, - "MemorySwap": 0, - "MemoryReservation": 0, - "KernelMemory": 0, - "OomKillDisable": false, - "NetworkMode": "bridge", - "PidMode": "", - "PortBindings": {}, - "Privileged": false, - "ReadonlyRootfs": false, - "PublishAllPorts": false, - "RestartPolicy": { - "MaximumRetryCount": 2, - "Name": "on-failure" - }, - "LogConfig": { - "Config": null, - "Type": "json-file" - }, - "SecurityOpt": null, - "VolumesFrom": null, - "Ulimits": [{}], - "VolumeDriver": "" - }, - "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname", - "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39", - "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2", - "MountLabel": "", - "Name": "/boring_euclid", - "NetworkSettings": { - "Bridge": "", - "SandboxID": "", - "HairpinMode": false, - "LinkLocalIPv6Address": "", - "LinkLocalIPv6PrefixLen": 0, - "Ports": null, - "SandboxKey": "", - "SecondaryIPAddresses": null, - "SecondaryIPv6Addresses": null, - "EndpointID": "", - "Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "IPAddress": "", - "IPPrefixLen": 0, - "IPv6Gateway": "", - "MacAddress": "", - "Networks": { - "bridge": { - "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.2", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:12:00:02" - } - } - }, - "Path": "/bin/sh", - "ProcessLabel": "", - "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf", - "RestartCount": 1, - "State": { - "Error": "", - "ExitCode": 9, - "FinishedAt": "2015-01-06T15:47:32.080254511Z", - "OOMKilled": false, - "Paused": false, - "Pid": 0, - "Restarting": false, - "Running": true, - "StartedAt": "2015-01-06T15:47:32.072697474Z", - "Status": "running" - }, - "Mounts": [ - { - "Source": "/data", - "Destination": "/data", - "Mode": "ro,Z", - "RW": false - } - ] - } - -**Example request, with size information**: - - GET /v1.21/containers/4fa6e0f0c678/json?size=1 HTTP/1.1 - -**Example response, with size information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - .... - "SizeRw": 0, - "SizeRootFs": 972, - .... - } - -**Query parameters**: - -- **size** – 1/True/true or 0/False/false, return container size information. Default is `false`. - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### List processes running inside a container - -`GET /containers/(id or name)/top` - -List processes running inside the container `id`. On Unix systems this -is done by running the `ps` command. This endpoint is not -supported on Windows. - -**Example request**: - - GET /v1.21/containers/4fa6e0f0c678/top HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD" - ], - "Processes" : [ - [ - "root", "13642", "882", "0", "17:03", "pts/0", "00:00:00", "/bin/bash" - ], - [ - "root", "13735", "13642", "0", "17:06", "pts/0", "00:00:00", "sleep 10" - ] - ] - } - -**Example request**: - - GET /v1.21/containers/4fa6e0f0c678/top?ps_args=aux HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND" - ] - "Processes" : [ - [ - "root","13642","0.0","0.1","18172","3184","pts/0","Ss","17:03","0:00","/bin/bash" - ], - [ - "root","13895","0.0","0.0","4348","692","pts/0","S+","17:15","0:00","sleep 10" - ] - ], - } - -**Query parameters**: - -- **ps_args** – `ps` arguments to use (e.g., `aux`), defaults to `-ef` - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container logs - -`GET /containers/(id or name)/logs` - -Get `stdout` and `stderr` logs from the container ``id`` - -> **Note**: -> This endpoint works only for containers with the `json-file` or `journald` logging drivers. - -**Example request**: - - GET /v1.21/containers/4fa6e0f0c678/logs?stderr=1&stdout=1×tamps=1&follow=1&tail=10&since=1428990821 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **follow** – 1/True/true or 0/False/false, return stream. Default `false`. -- **stdout** – 1/True/true or 0/False/false, show `stdout` log. Default `false`. -- **stderr** – 1/True/true or 0/False/false, show `stderr` log. Default `false`. -- **since** – UNIX timestamp (integer) to filter logs. Specifying a timestamp - will only output log-entries since that timestamp. Default: 0 (unfiltered) -- **timestamps** – 1/True/true or 0/False/false, print timestamps for - every log line. Default `false`. -- **tail** – Output specified number of lines at the end of logs: `all` or ``. Default all. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **404** – no such container -- **500** – server error - -#### Inspect changes on a container's filesystem - -`GET /containers/(id or name)/changes` - -Inspect changes on container `id`'s filesystem - -**Example request**: - - GET /v1.21/containers/4fa6e0f0c678/changes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Path": "/dev", - "Kind": 0 - }, - { - "Path": "/dev/kmsg", - "Kind": 1 - }, - { - "Path": "/test", - "Kind": 1 - } - ] - -Values for `Kind`: - -- `0`: Modify -- `1`: Add -- `2`: Delete - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Export a container - -`GET /containers/(id or name)/export` - -Export the contents of container `id` - -**Example request**: - - GET /v1.21/containers/4fa6e0f0c678/export HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/octet-stream - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container stats based on resource usage - -`GET /containers/(id or name)/stats` - -This endpoint returns a live stream of a container's resource usage statistics. - -**Example request**: - - GET /v1.21/containers/redis1/stats HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "read" : "2015-01-08T22:57:31.547920715Z", - "networks": { - "eth0": { - "rx_bytes": 5338, - "rx_dropped": 0, - "rx_errors": 0, - "rx_packets": 36, - "tx_bytes": 648, - "tx_dropped": 0, - "tx_errors": 0, - "tx_packets": 8 - }, - "eth5": { - "rx_bytes": 4641, - "rx_dropped": 0, - "rx_errors": 0, - "rx_packets": 26, - "tx_bytes": 690, - "tx_dropped": 0, - "tx_errors": 0, - "tx_packets": 9 - } - }, - "memory_stats" : { - "stats" : { - "total_pgmajfault" : 0, - "cache" : 0, - "mapped_file" : 0, - "total_inactive_file" : 0, - "pgpgout" : 414, - "rss" : 6537216, - "total_mapped_file" : 0, - "writeback" : 0, - "unevictable" : 0, - "pgpgin" : 477, - "total_unevictable" : 0, - "pgmajfault" : 0, - "total_rss" : 6537216, - "total_rss_huge" : 6291456, - "total_writeback" : 0, - "total_inactive_anon" : 0, - "rss_huge" : 6291456, - "hierarchical_memory_limit" : 67108864, - "total_pgfault" : 964, - "total_active_file" : 0, - "active_anon" : 6537216, - "total_active_anon" : 6537216, - "total_pgpgout" : 414, - "total_cache" : 0, - "inactive_anon" : 0, - "active_file" : 0, - "pgfault" : 964, - "inactive_file" : 0, - "total_pgpgin" : 477 - }, - "max_usage" : 6651904, - "usage" : 6537216, - "failcnt" : 0, - "limit" : 67108864 - }, - "blkio_stats" : {}, - "cpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24472255, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100215355, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 739306590000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - }, - "precpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24350896, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100093996, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 9492140000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - } - } - -The precpu_stats is the cpu statistic of last read, which is used for calculating the cpu usage percent. It is not the exact copy of the “cpu_stats” field. - -**Query parameters**: - -- **stream** – 1/True/true or 0/False/false, pull stats once then disconnect. Default `true`. - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Resize a container TTY - -`POST /containers/(id or name)/resize` - -Resize the TTY for container with `id`. The unit is number of characters. You must restart the container for the resize to take effect. - -**Example request**: - - POST /v1.21/containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **200** – no error -- **404** – No such container -- **500** – Cannot resize container - -#### Start a container - -`POST /containers/(id or name)/start` - -Start the container `id` - -> **Note**: -> For backwards compatibility, this endpoint accepts a `HostConfig` as JSON-encoded request body. -> See [create a container](#create-a-container) for details. - -**Example request**: - - POST /v1.21/containers/e90e34656806/start HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **304** – container already started -- **404** – no such container -- **500** – server error - -#### Stop a container - -`POST /containers/(id or name)/stop` - -Stop the container `id` - -**Example request**: - - POST /v1.21/containers/e90e34656806/stop?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **304** – container already stopped -- **404** – no such container -- **500** – server error - -#### Restart a container - -`POST /containers/(id or name)/restart` - -Restart the container `id` - -**Example request**: - - POST /v1.21/containers/e90e34656806/restart?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Kill a container - -`POST /containers/(id or name)/kill` - -Kill the container `id` - -**Example request**: - - POST /v1.21/containers/e90e34656806/kill HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **signal** - Signal to send to the container: integer or string like `SIGINT`. - When not set, `SIGKILL` is assumed and the call waits for the container to exit. - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Rename a container - -`POST /containers/(id or name)/rename` - -Rename the container `id` to a `new_name` - -**Example request**: - - POST /v1.21/containers/e90e34656806/rename?name=new_name HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **name** – new name for the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **409** - conflict name already assigned -- **500** – server error - -#### Pause a container - -`POST /containers/(id or name)/pause` - -Pause the container `id` - -**Example request**: - - POST /v1.21/containers/e90e34656806/pause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Unpause a container - -`POST /containers/(id or name)/unpause` - -Unpause the container `id` - -**Example request**: - - POST /v1.21/containers/e90e34656806/unpause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Attach to a container - -`POST /containers/(id or name)/attach` - -Attach to the container `id` - -**Example request**: - - POST /v1.21/containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -**Stream details**: - -When using the TTY setting is enabled in -[`POST /containers/create` -](#create-a-container), -the stream is the raw data from the process PTY and client's `stdin`. -When the TTY is disabled, then the stream is multiplexed to separate -`stdout` and `stderr`. - -The format is a **Header** and a **Payload** (frame). - -**HEADER** - -The header contains the information which the stream writes (`stdout` or -`stderr`). It also contains the size of the associated frame encoded in the -last four bytes (`uint32`). - -It is encoded on the first eight bytes like this: - - header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} - -`STREAM_TYPE` can be: - -- 0: `stdin` (is written on `stdout`) -- 1: `stdout` -- 2: `stderr` - -`SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of -the `uint32` size encoded as big endian. - -**PAYLOAD** - -The payload is the raw stream. - -**IMPLEMENTATION** - -The simplest way to implement the Attach protocol is the following: - - 1. Read eight bytes. - 2. Choose `stdout` or `stderr` depending on the first byte. - 3. Extract the frame size from the last four bytes. - 4. Read the extracted size and output it on the correct output. - 5. Goto 1. - -#### Attach to a container (websocket) - -`GET /containers/(id or name)/attach/ws` - -Attach to the container `id` via websocket - -Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455) - -**Example request** - - GET /v1.21/containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 - -**Example response** - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -#### Wait a container - -`POST /containers/(id or name)/wait` - -Block until container `id` stops, then returns the exit code - -**Example request**: - - POST /v1.21/containers/16253994b7c4/wait HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"StatusCode": 0} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Remove a container - -`DELETE /containers/(id or name)` - -Remove the container `id` from the filesystem - -**Example request**: - - DELETE /v1.21/containers/16253994b7c4?v=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **v** – 1/True/true or 0/False/false, Remove the volumes - associated to the container. Default `false`. -- **force** - 1/True/true or 0/False/false, Kill then remove the container. - Default `false`. - -**Status codes**: - -- **204** – no error -- **400** – bad parameter -- **404** – no such container -- **409** – conflict -- **500** – server error - -#### Copy files or folders from a container - -`POST /containers/(id or name)/copy` - -Copy files or folders of container `id` - -**Deprecated** in favor of the `archive` endpoint below. - -**Example request**: - - POST /v1.21/containers/4fa6e0f0c678/copy HTTP/1.1 - Content-Type: application/json - - { - "Resource": "test.txt" - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Retrieving information about files and folders in a container - -`HEAD /containers/(id or name)/archive` - -See the description of the `X-Docker-Container-Path-Stat` header in the -following section. - -#### Get an archive of a filesystem resource in a container - -`GET /containers/(id or name)/archive` - -Get a tar archive of a resource in the filesystem of container `id`. - -**Query parameters**: - -- **path** - resource in the container's filesystem to archive. Required. - - If not an absolute path, it is relative to the container's root directory. - The resource specified by **path** must exist. To assert that the resource - is expected to be a directory, **path** should end in `/` or `/.` - (assuming a path separator of `/`). If **path** ends in `/.` then this - indicates that only the contents of the **path** directory should be - copied. A symlink is always resolved to its target. - - > **Note**: It is not possible to copy certain system files such as resources - > under `/proc`, `/sys`, `/dev`, and mounts created by the user in the - > container. - -**Example request**: - - GET /v1.21/containers/8cce319429b2/archive?path=/root HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - X-Docker-Container-Path-Stat: eyJuYW1lIjoicm9vdCIsInNpemUiOjQwOTYsIm1vZGUiOjIxNDc0ODQwOTYsIm10aW1lIjoiMjAxNC0wMi0yN1QyMDo1MToyM1oiLCJsaW5rVGFyZ2V0IjoiIn0= - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -On success, a response header `X-Docker-Container-Path-Stat` will be set to a -base64-encoded JSON object containing some filesystem header information about -the archived resource. The above example value would decode to the following -JSON object (whitespace added for readability): - -```json -{ - "name": "root", - "size": 4096, - "mode": 2147484096, - "mtime": "2014-02-27T20:51:23Z", - "linkTarget": "" -} -``` - -A `HEAD` request can also be made to this endpoint if only this information is -desired. - -**Status codes**: - -- **200** - success, returns archive of copied resource -- **400** - client error, bad parameter, details in JSON response body, one of: - - must specify path parameter (**path** cannot be empty) - - not a directory (**path** was asserted to be a directory but exists as a - file) -- **404** - client error, resource not found, one of: - – no such container (container `id` does not exist) - - no such file or directory (**path** does not exist) -- **500** - server error - -#### Extract an archive of files or folders to a directory in a container - -`PUT /containers/(id or name)/archive` - -Upload a tar archive to be extracted to a path in the filesystem of container -`id`. - -**Query parameters**: - -- **path** - path to a directory in the container - to extract the archive's contents into. Required. - - If not an absolute path, it is relative to the container's root directory. - The **path** resource must exist. -- **noOverwriteDirNonDir** - If "1", "true", or "True" then it will be an error - if unpacking the given content would cause an existing directory to be - replaced with a non-directory and vice versa. - -**Example request**: - - PUT /v1.21/containers/8cce319429b2/archive?path=/vol1 HTTP/1.1 - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – the content was extracted successfully -- **400** - client error, bad parameter, details in JSON response body, one of: - - must specify path parameter (**path** cannot be empty) - - not a directory (**path** should be a directory but exists as a file) - - unable to overwrite existing directory with non-directory - (if **noOverwriteDirNonDir**) - - unable to overwrite existing non-directory with directory - (if **noOverwriteDirNonDir**) -- **403** - client error, permission denied, the volume - or container rootfs is marked as read-only. -- **404** - client error, resource not found, one of: - – no such container (container `id` does not exist) - - no such file or directory (**path** resource does not exist) -- **500** – server error - -### 2.2 Images - -#### List Images - -`GET /images/json` - -**Example request**: - - GET /v1.21/images/json?all=0 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "RepoTags": [ - "ubuntu:12.04", - "ubuntu:precise", - "ubuntu:latest" - ], - "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", - "Created": 1365714795, - "Size": 131506275, - "VirtualSize": 131506275, - "Labels": {} - }, - { - "RepoTags": [ - "ubuntu:12.10", - "ubuntu:quantal" - ], - "ParentId": "27cf784147099545", - "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "Created": 1364102658, - "Size": 24653, - "VirtualSize": 180116135, - "Labels": { - "com.example.version": "v1" - } - } - ] - -**Example request, with digest information**: - - GET /v1.21/images/json?digests=1 HTTP/1.1 - -**Example response, with digest information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Created": 1420064636, - "Id": "4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125", - "ParentId": "ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2", - "RepoDigests": [ - "localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags": [ - "localhost:5000/test/busybox:latest", - "playdate:latest" - ], - "Size": 0, - "VirtualSize": 2429728, - "Labels": {} - } - ] - -The response shows a single image `Id` associated with two repositories -(`RepoTags`): `localhost:5000/test/busybox`: and `playdate`. A caller can use -either of the `RepoTags` values `localhost:5000/test/busybox:latest` or -`playdate:latest` to reference the image. - -You can also use `RepoDigests` values to reference an image. In this response, -the array has only one reference and that is to the -`localhost:5000/test/busybox` repository; the `playdate` repository has no -digest. You can reference this digest using the value: -`localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d...` - -See the `docker run` and `docker build` commands for examples of digest and tag -references on the command line. - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, default false -- **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: - - `dangling=true` - - `label=key` or `label="key=value"` of an image label -- **filter** - only return images with the specified name - -#### Build image from a Dockerfile - -`POST /build` - -Build an image from a Dockerfile - -**Example request**: - - POST /v1.21/build HTTP/1.1 - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"stream": "Step 1/5..."} - {"stream": "..."} - {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} - -The input stream must be a `tar` archive compressed with one of the -following algorithms: `identity` (no compression), `gzip`, `bzip2`, `xz`. - -The archive must include a build instructions file, typically called -`Dockerfile` at the archive's root. The `dockerfile` parameter may be -used to specify a different build instructions file. To do this, its value must be -the path to the alternate build instructions file to use. - -The archive may include any number of other files, -which are accessible in the build context (See the [*ADD build -command*](../reference/builder.md#add)). - -The Docker daemon performs a preliminary validation of the `Dockerfile` before -starting the build, and returns an error if the syntax is incorrect. After that, -each instruction is run one-by-one until the ID of the new image is output. - -The build is canceled if the client drops the connection by quitting -or being killed. - -**Query parameters**: - -- **dockerfile** - Path within the build context to the `Dockerfile`. This is - ignored if `remote` is specified and points to an external `Dockerfile`. -- **t** – A name and optional tag to apply to the image in the `name:tag` format. - If you omit the `tag` the default `latest` value is assumed. - You can provide one or more `t` parameters. -- **remote** – A Git repository URI or HTTP/HTTPS context URI. If the - URI points to a single text file, the file's contents are placed into - a file called `Dockerfile` and the image is built from that file. If - the URI points to a tarball, the file is downloaded by the daemon and - the contents therein used as the context for the build. If the URI - points to a tarball and the `dockerfile` parameter is also specified, - there must be a file with the corresponding path inside the tarball. -- **q** – Suppress verbose build output. -- **nocache** – Do not use the cache when building the image. -- **pull** - Attempt to pull the image even if an older image exists locally. -- **rm** - Remove intermediate containers after a successful build (default behavior). -- **forcerm** - Always remove intermediate containers (includes `rm`). -- **memory** - Set memory limit for build. -- **memswap** - Total memory (memory + swap), `-1` to enable unlimited swap. -- **cpushares** - CPU shares (relative weight). -- **cpusetcpus** - CPUs in which to allow execution (e.g., `0-3`, `0,1`). -- **cpuperiod** - The length of a CPU period in microseconds. -- **cpuquota** - Microseconds of CPU time that the container can get in a CPU period. -- **buildargs** – JSON map of string pairs for build-time variables. Users pass - these values at build-time. Docker uses the `buildargs` as the environment - context for command(s) run via the Dockerfile's `RUN` instruction or for - variable expansion in other Dockerfile instructions. This is not meant for - passing secret values. [Read more about the buildargs instruction](../reference/builder.md#arg) - -**Request Headers**: - -- **Content-type** – Set to `"application/tar"`. -- **X-Registry-Config** – A base64-url-safe-encoded Registry Auth Config JSON - object with the following structure: - - { - "docker.example.com": { - "username": "janedoe", - "password": "hunter2" - }, - "https://index.docker.io/v1/": { - "username": "mobydock", - "password": "conta1n3rize14" - } - } - - This object maps the hostname of a registry to an object containing the - "username" and "password" for that registry. Multiple registries may - be specified as the build may be based on an image requiring - authentication to pull from any arbitrary registry. Only the registry - domain name (and port if not the default "443") are required. However - (for legacy reasons) the "official" Docker, Inc. hosted registry must - be specified with both a "https://" prefix and a "/v1/" suffix even - though Docker will prefer to use the v2 registry API. - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Create an image - -`POST /images/create` - -Create an image either by pulling it from the registry or by importing it - -**Example request**: - - POST /v1.21/images/create?fromImage=busybox&tag=latest HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pulling..."} - {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} - {"error": "Invalid..."} - ... - -When using this endpoint to pull an image from the registry, the -`X-Registry-Auth` header can be used to include -a base64-encoded AuthConfig object. - -**Query parameters**: - -- **fromImage** – Name of the image to pull. The name may include a tag or - digest. This parameter may only be used when pulling an image. -- **fromSrc** – Source to import. The value may be a URL from which the image - can be retrieved or `-` to read the image from the request body. - This parameter may only be used when importing an image. -- **repo** – Repository name given to an image when it is imported. - The repo may include a tag. This parameter may only be used when importing - an image. -- **tag** – Tag or digest. If empty when pulling an image, this causes all tags - for the given image to be pulled. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object - -**Status codes**: - -- **200** – no error -- **404** - repository does not exist or no read access -- **500** – server error - - - -#### Inspect an image - -`GET /images/(name)/json` - -Return low-level information on the image `name` - -**Example request**: - - GET /v1.21/images/example/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Id" : "85f05633ddc1c50679be2b16a0479ab6f7637f8884e0cfe0f4d20e1ebb3d6e7c", - "Container" : "cb91e48a60d01f1e27028b4fc6819f4f290b3cf12496c8176ec714d0d390984a", - "Comment" : "", - "Os" : "linux", - "Architecture" : "amd64", - "Parent" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "ContainerConfig" : { - "Tty" : false, - "Hostname" : "e611e15f9c9d", - "Volumes" : null, - "Domainname" : "", - "AttachStdout" : false, - "PublishService" : "", - "AttachStdin" : false, - "OpenStdin" : false, - "StdinOnce" : false, - "NetworkDisabled" : false, - "OnBuild" : [], - "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "User" : "", - "WorkingDir" : "", - "Entrypoint" : null, - "MacAddress" : "", - "AttachStderr" : false, - "Labels" : { - "com.example.license" : "GPL", - "com.example.version" : "1.0", - "com.example.vendor" : "Acme" - }, - "Env" : [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts" : null, - "Cmd" : [ - "/bin/sh", - "-c", - "#(nop) LABEL com.example.vendor=Acme com.example.license=GPL com.example.version=1.0" - ] - }, - "DockerVersion" : "1.9.0-dev", - "VirtualSize" : 188359297, - "Size" : 0, - "Author" : "", - "Created" : "2015-09-10T08:30:53.26995814Z", - "GraphDriver" : { - "Name" : "aufs", - "Data" : null - }, - "RepoDigests" : [ - "localhost:5000/test/busybox/example@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags" : [ - "example:1.0", - "example:latest", - "example:stable" - ], - "Config" : { - "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "NetworkDisabled" : false, - "OnBuild" : [], - "StdinOnce" : false, - "PublishService" : "", - "AttachStdin" : false, - "OpenStdin" : false, - "Domainname" : "", - "AttachStdout" : false, - "Tty" : false, - "Hostname" : "e611e15f9c9d", - "Volumes" : null, - "Cmd" : [ - "/bin/bash" - ], - "ExposedPorts" : null, - "Env" : [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "Labels" : { - "com.example.vendor" : "Acme", - "com.example.version" : "1.0", - "com.example.license" : "GPL" - }, - "Entrypoint" : null, - "MacAddress" : "", - "AttachStderr" : false, - "WorkingDir" : "", - "User" : "" - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Get the history of an image - -`GET /images/(name)/history` - -Return the history of the image `name` - -**Example request**: - - GET /v1.21/images/ubuntu/history HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710", - "Created": 1398108230, - "CreatedBy": "/bin/sh -c #(nop) ADD file:eb15dbd63394e063b805a3c32ca7bf0266ef64676d5a6fab4801f2e81e2a5148 in /", - "Tags": [ - "ubuntu:lucid", - "ubuntu:10.04" - ], - "Size": 182964289, - "Comment": "" - }, - { - "Id": "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8", - "Created": 1398108222, - "CreatedBy": "/bin/sh -c #(nop) MAINTAINER Tianon Gravi - mkimage-debootstrap.sh -i iproute,iputils-ping,ubuntu-minimal -t lucid.tar.xz lucid http://archive.ubuntu.com/ubuntu/", - "Tags": null, - "Size": 0, - "Comment": "" - }, - { - "Id": "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158", - "Created": 1371157430, - "CreatedBy": "", - "Tags": [ - "scratch12:latest", - "scratch:latest" - ], - "Size": 0, - "Comment": "Imported from -" - } - ] - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Push an image on the registry - -`POST /images/(name)/push` - -Push the image `name` on the registry - -**Example request**: - - POST /v1.21/images/test/push HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pushing..."} - {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} - {"error": "Invalid..."} - ... - -If you wish to push an image on to a private registry, that image must already have a tag -into a repository which references that registry `hostname` and `port`. This repository name should -then be used in the URL. This duplicates the command line's flow. - -**Example request**: - - POST /v1.21/images/registry.acme.com:5000/test/push HTTP/1.1 - - -**Query parameters**: - -- **tag** – The tag to associate with the image on the registry. This is optional. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object. - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Tag an image into a repository - -`POST /images/(name)/tag` - -Tag the image `name` into a repository - -**Example request**: - - POST /v1.21/images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 - -**Example response**: - - HTTP/1.1 201 Created - -**Query parameters**: - -- **repo** – The repository to tag in -- **force** – 1/True/true or 0/False/false, default false -- **tag** - The new tag name - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Remove an image - -`DELETE /images/(name)` - -Remove the image `name` from the filesystem - -**Example request**: - - DELETE /v1.21/images/test HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-type: application/json - - [ - {"Untagged": "3e2f21a89f"}, - {"Deleted": "3e2f21a89f"}, - {"Deleted": "53b4f83ac9"} - ] - -**Query parameters**: - -- **force** – 1/True/true or 0/False/false, default false -- **noprune** – 1/True/true or 0/False/false, default false - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Search images - -`GET /images/search` - -Search for an image on [Docker Hub](https://hub.docker.com). - -> **Note**: -> The response keys have changed from API v1.6 to reflect the JSON -> sent by the registry server to the docker daemon's request. - -**Example request**: - - GET /v1.21/images/search?term=sshd HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "wma55/u1210sshd", - "star_count": 0 - }, - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "jdswinbank/sshd", - "star_count": 0 - }, - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "vgauthier/sshd", - "star_count": 0 - } - ... - ] - -**Query parameters**: - -- **term** – term to search - -**Status codes**: - -- **200** – no error -- **500** – server error - -### 2.3 Misc - -#### Check auth configuration - -`POST /auth` - -Get the default username and email - -**Example request**: - - POST /v1.21/auth HTTP/1.1 - Content-Type: application/json - - { - "username": "hannibal", - "password": "xxxx", - "email": "hannibal@a-team.com", - "serveraddress": "https://index.docker.io/v1/" - } - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – no error -- **204** – no error -- **500** – server error - -#### Display system-wide information - -`GET /info` - -Display system-wide information - -**Example request**: - - GET /v1.21/info HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "ClusterStore": "etcd://localhost:2379", - "Containers": 11, - "CpuCfsPeriod": true, - "CpuCfsQuota": true, - "Debug": false, - "DockerRootDir": "/var/lib/docker", - "Driver": "btrfs", - "DriverStatus": [[""]], - "ExecutionDriver": "native-0.1", - "ExperimentalBuild": false, - "HttpProxy": "http://test:test@localhost:8080", - "HttpsProxy": "https://test:test@localhost:8080", - "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", - "IPv4Forwarding": true, - "Images": 16, - "IndexServerAddress": "https://index.docker.io/v1/", - "InitPath": "/usr/bin/docker", - "InitSha1": "", - "KernelVersion": "3.12.0-1-amd64", - "Labels": [ - "storage=ssd" - ], - "MemTotal": 2099236864, - "MemoryLimit": true, - "NCPU": 1, - "NEventsListener": 0, - "NFd": 11, - "NGoroutines": 21, - "Name": "prod-server-42", - "NoProxy": "9.81.1.160", - "OomKillDisable": true, - "OperatingSystem": "Boot2Docker", - "RegistryConfig": { - "IndexConfigs": { - "docker.io": { - "Mirrors": null, - "Name": "docker.io", - "Official": true, - "Secure": true - } - }, - "InsecureRegistryCIDRs": [ - "127.0.0.0/8" - ] - }, - "ServerVersion": "1.9.0", - "SwapLimit": false, - "SystemTime": "2015-03-10T11:11:23.730591467-07:00" - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Show the docker version information - -`GET /version` - -Show the docker version information - -**Example request**: - - GET /v1.21/version HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Version": "1.5.0", - "Os": "linux", - "KernelVersion": "3.18.5-tinycore64", - "GoVersion": "go1.4.1", - "GitCommit": "a8a31ef", - "Arch": "amd64", - "ApiVersion": "1.20", - "Experimental": false - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Ping the docker server - -`GET /_ping` - -Ping the docker server - -**Example request**: - - GET /v1.21/_ping HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: text/plain - - OK - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a new image from a container's changes - -`POST /commit` - -Create a new image from a container's changes - -**Example request**: - - POST /v1.21/commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Mounts": [ - { - "Source": "/data", - "Destination": "/data", - "Mode": "ro,Z", - "RW": false - } - ], - "Labels": { - "key1": "value1", - "key2": "value2" - }, - "WorkingDir": "", - "NetworkDisabled": false, - "ExposedPorts": { - "22/tcp": {} - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - {"Id": "596069db4bf5"} - -**JSON parameters**: - -- **config** - the container's configuration - -**Query parameters**: - -- **container** – source container -- **repo** – repository -- **tag** – tag -- **comment** – commit message -- **author** – author (e.g., "John Hannibal Smith - <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") -- **pause** – 1/True/true or 0/False/false, whether to pause the container before committing -- **changes** – Dockerfile instructions to apply while committing - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **500** – server error - -#### Monitor Docker's events - -`GET /events` - -Get container events from docker, in real time via streaming. - -Docker containers report the following events: - - attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause - -Docker images report the following events: - - delete, import, pull, push, tag, untag - -**Example request**: - - GET /v1.21/events?since=1374067924 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status":"pull","id":"busybox:latest","time":1442421700,"timeNano":1442421700598988358} - {"status":"create","id":"5745704abe9caa5","from":"busybox","time":1442421716,"timeNano":1442421716853979870} - {"status":"attach","id":"5745704abe9caa5","from":"busybox","time":1442421716,"timeNano":1442421716894759198} - {"status":"start","id":"5745704abe9caa5","from":"busybox","time":1442421716,"timeNano":1442421716983607193} - -**Query parameters**: - -- **since** – Timestamp. Show all events created since timestamp and then stream -- **until** – Timestamp. Show events created until given timestamp and stop streaming -- **filters** – A json encoded value of the filters (a map[string][]string) to process on the event list. Available filters: - - `container=`; -- container to filter - - `event=`; -- event to filter - - `image=`; -- image to filter - - `label=`; -- image and container label to filter - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images in a repository - -`GET /images/(name)/get` - -Get a tarball containing all images and metadata for the repository specified -by `name`. - -If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image -(and its parents) are returned. If `name` is an image ID, similarly only that -image (and its parents) are returned, but with the exclusion of the -'repositories' file in the tarball, as there were no image names referenced. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.21/images/ubuntu/get - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images - -`GET /images/get` - -Get a tarball containing all images and metadata for one or more repositories. - -For each value of the `names` parameter: if it is a specific name and tag (e.g. -`ubuntu:latest`), then only that image (and its parents) are returned; if it is -an image ID, similarly only that image (and its parents) are returned and there -would be no names referenced in the 'repositories' file for this image ID. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.21/images/get?names=myname%2Fmyapp%3Alatest&names=busybox - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Load a tarball with a set of images and tags into docker - -`POST /images/load` - -Load a set of images and tags into a Docker repository. -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - POST /v1.21/images/load - Content-Type: application/x-tar - - Tarball in body - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Image tarball format - -An image tarball contains one directory per image layer (named using its long ID), -each containing these files: - -- `VERSION`: currently `1.0` - the file format version -- `json`: detailed layer information, similar to `docker inspect layer_id` -- `layer.tar`: A tarfile containing the filesystem changes in this layer - -The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories -for storing attribute changes and deletions. - -If the tarball defines a repository, the tarball should also include a `repositories` file at -the root that contains a list of repository and tag names mapped to layer IDs. - -``` -{"hello-world": - {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} -} -``` - -#### Exec Create - -`POST /containers/(id or name)/exec` - -Sets up an exec instance in a running container `id` - -**Example request**: - - POST /v1.21/containers/e90e34656806/exec HTTP/1.1 - Content-Type: application/json - - { - "AttachStdin": true, - "AttachStdout": true, - "AttachStderr": true, - "Cmd": ["sh"], - "Privileged": true, - "Tty": true, - "User": "123:456" - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id": "f90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **AttachStdin** - Boolean value, attaches to `stdin` of the `exec` command. -- **AttachStdout** - Boolean value, attaches to `stdout` of the `exec` command. -- **AttachStderr** - Boolean value, attaches to `stderr` of the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. -- **Cmd** - Command to run specified as a string or an array of strings. -- **Privileged** - Boolean value, runs the exec process with extended privileges. -- **User** - A string value specifying the user, and optionally, group to run - the exec process inside the container. Format is one of: `"user"`, - `"user:group"`, `"uid"`, or `"uid:gid"`. - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **409** - container is paused -- **500** - server error - -#### Exec Start - -`POST /exec/(id)/start` - -Starts a previously set up `exec` instance `id`. If `detach` is true, this API -returns after starting the `exec` command. Otherwise, this API sets up an -interactive session with the `exec` command. - -**Example request**: - - POST /v1.21/exec/e90e34656806/start HTTP/1.1 - Content-Type: application/json - - { - "Detach": false, - "Tty": false - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/vnd.docker.raw-stream - - {% raw %} - {{ STREAM }} - {% endraw %} - -**JSON parameters**: - -- **Detach** - Detach from the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **409** - container is paused - -**Stream details**: - -Similar to the stream behavior of `POST /containers/(id or name)/attach` API - -#### Exec Resize - -`POST /exec/(id)/resize` - -Resizes the `tty` session used by the `exec` command `id`. The unit is number of characters. -This API is valid only if `tty` was specified as part of creating and starting the `exec` command. - -**Example request**: - - POST /v1.21/exec/e90e34656806/resize?h=40&w=80 HTTP/1.1 - Content-Type: text/plain - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: text/plain - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **201** – no error -- **404** – no such exec instance - -#### Exec Inspect - -`GET /exec/(id)/json` - -Return low-level information about the `exec` command `id`. - -**Example request**: - - GET /v1.21/exec/11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: plain/text - - { - "ID" : "11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39", - "Running" : false, - "ExitCode" : 2, - "ProcessConfig" : { - "privileged" : false, - "user" : "", - "tty" : false, - "entrypoint" : "sh", - "arguments" : [ - "-c", - "exit 2" - ] - }, - "OpenStdin" : false, - "OpenStderr" : false, - "OpenStdout" : false, - "Container" : { - "State" : { - "Status" : "running", - "Running" : true, - "Paused" : false, - "Restarting" : false, - "OOMKilled" : false, - "Pid" : 3650, - "ExitCode" : 0, - "Error" : "", - "StartedAt" : "2014-11-17T22:26:03.717657531Z", - "FinishedAt" : "0001-01-01T00:00:00Z" - }, - "ID" : "8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c", - "Created" : "2014-11-17T22:26:03.626304998Z", - "Path" : "date", - "Args" : [], - "Config" : { - "Hostname" : "8f177a186b97", - "Domainname" : "", - "User" : "", - "AttachStdin" : false, - "AttachStdout" : false, - "AttachStderr" : false, - "ExposedPorts" : null, - "Tty" : false, - "OpenStdin" : false, - "StdinOnce" : false, - "Env" : [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], - "Cmd" : [ - "date" - ], - "Image" : "ubuntu", - "Volumes" : null, - "WorkingDir" : "", - "Entrypoint" : null, - "NetworkDisabled" : false, - "MacAddress" : "", - "OnBuild" : null, - "SecurityOpt" : null - }, - "Image" : "5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5", - "NetworkSettings" : { - "Bridge": "", - "SandboxID": "", - "HairpinMode": false, - "LinkLocalIPv6Address": "", - "LinkLocalIPv6PrefixLen": 0, - "Ports": null, - "SandboxKey": "", - "SecondaryIPAddresses": null, - "SecondaryIPv6Addresses": null, - "EndpointID": "", - "Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "IPAddress": "", - "IPPrefixLen": 0, - "IPv6Gateway": "", - "MacAddress": "", - "Networks": { - "bridge": { - "EndpointID": "", - "Gateway": "", - "IPAddress": "", - "IPPrefixLen": 0, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "" - } - } - }, - "ResolvConfPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/resolv.conf", - "HostnamePath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hostname", - "HostsPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Name" : "/test", - "Driver" : "aufs", - "ExecDriver" : "native-0.2", - "MountLabel" : "", - "ProcessLabel" : "", - "AppArmorProfile" : "", - "RestartCount" : 0, - "Mounts" : [] - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **500** - server error - -### 2.4 Volumes - -#### List volumes - -`GET /volumes` - -**Example request**: - - GET /v1.21/volumes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Volumes": [ - { - "Name": "tardis", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/tardis" - } - ] - } - -**Query parameters**: - -- **filters** - JSON encoded value of the filters (a `map[string][]string`) to process on the volumes list. There is one available filter: `dangling=true` - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a volume - -`POST /volumes/create` - -Create a volume - -**Example request**: - - POST /v1.21/volumes/create HTTP/1.1 - Content-Type: application/json - - { - "Name": "tardis" - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Name": "tardis", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/tardis" - } - -**Status codes**: - -- **201** - no error -- **500** - server error - -**JSON parameters**: - -- **Name** - The new volume's name. If not specified, Docker generates a name. -- **Driver** - Name of the volume driver to use. Defaults to `local` for the name. -- **DriverOpts** - A mapping of driver options and values. These options are - passed directly to the driver and are driver specific. - -#### Inspect a volume - -`GET /volumes/(name)` - -Return low-level information on the volume `name` - -**Example request**: - - GET /volumes/tardis - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Name": "tardis", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/tardis" - } - -**Status codes**: - -- **200** - no error -- **404** - no such volume -- **500** - server error - -#### Remove a volume - -`DELETE /volumes/(name)` - -Instruct the driver to remove the volume (`name`). - -**Example request**: - - DELETE /v1.21/volumes/tardis HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** - no error -- **404** - no such volume or volume driver -- **409** - volume is in use and cannot be removed -- **500** - server error - -### 2.5 Networks - -#### List networks - -`GET /networks` - -**Example request**: - - GET /v1.21/networks HTTP/1.1 - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json - -[ - { - "Name": "bridge", - "Id": "f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566", - "Scope": "local", - "Driver": "bridge", - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.17.0.0/16" - } - ] - }, - "Containers": { - "39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": { - "EndpointID": "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda", - "MacAddress": "02:42:ac:11:00:02", - "IPv4Address": "172.17.0.2/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - } - }, - { - "Name": "none", - "Id": "e086a3893b05ab69242d3c44e49483a3bbbd3a26b46baa8f61ab797c1088d794", - "Scope": "local", - "Driver": "null", - "IPAM": { - "Driver": "default", - "Config": [] - }, - "Containers": {}, - "Options": {} - }, - { - "Name": "host", - "Id": "13e871235c677f196c4e1ecebb9dc733b9b2d2ab589e30c539efeda84a24215e", - "Scope": "local", - "Driver": "host", - "IPAM": { - "Driver": "default", - "Config": [] - }, - "Containers": {}, - "Options": {} - } -] -``` - -**Query parameters**: - -- **filters** - JSON encoded value of the filters (a `map[string][]string`) to process on the networks list. Available filters: `name=[network-names]` , `id=[network-ids]` - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Inspect network - -`GET /networks/` - -**Example request**: - - GET /v1.21/networks/f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566 HTTP/1.1 - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json - -{ - "Name": "bridge", - "Id": "f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566", - "Scope": "local", - "Driver": "bridge", - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.17.0.0/16" - } - ] - }, - "Containers": { - "39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": { - "EndpointID": "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda", - "MacAddress": "02:42:ac:11:00:02", - "IPv4Address": "172.17.0.2/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - } -} -``` - -**Status codes**: - -- **200** - no error -- **404** - network not found - -#### Create a network - -`POST /networks/create` - -Create a network - -**Example request**: - -``` -POST /v1.21/networks/create HTTP/1.1 -Content-Type: application/json - -{ - "Name":"isolated_nw", - "CheckDuplicate":true, - "Driver":"bridge", - "IPAM":{ - "Driver": "default", - "Config":[ - { - "Subnet":"172.20.0.0/16", - "IPRange":"172.20.10.0/24", - "Gateway":"172.20.10.11" - } - ] - } -} -``` - -**Example response**: - -``` -HTTP/1.1 201 Created -Content-Type: application/json - -{ - "Id": "22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30", - "Warning": "" -} -``` - -**Status codes**: - -- **201** - no error -- **404** - plugin not found -- **500** - server error - -**JSON parameters**: - -- **Name** - The new network's name. this is a mandatory field -- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false` -- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver -- **IPAM** - Optional custom IP scheme for the network - - **Driver** - Name of the IPAM driver to use. Defaults to `default` driver - - **Config** - List of IPAM configuration options, specified as a map: - `{"Subnet": , "IPRange": , "Gateway": , "AuxAddress": }` -- **Options** - Network specific options to be used by the drivers - -#### Connect a container to a network - -`POST /networks/(id)/connect` - -Connect a container to a network - -**Example request**: - -``` -POST /v1.21/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30/connect HTTP/1.1 -Content-Type: application/json - -{ - "Container":"3613f73ba0e4" -} -``` - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** - no error -- **404** - network or container is not found -- **500** - Internal Server Error - -**JSON parameters**: - -- **container** - container-id/name to be connected to the network - -#### Disconnect a container from a network - -`POST /networks/(id)/disconnect` - -Disconnect a container from a network - -**Example request**: - -``` -POST /v1.21/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30/disconnect HTTP/1.1 -Content-Type: application/json - -{ - "Container":"3613f73ba0e4" -} -``` - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** - no error -- **404** - network or container not found -- **500** - Internal Server Error - -**JSON parameters**: - -- **Container** - container-id/name to be disconnected from a network - -#### Remove a network - -`DELETE /networks/(id)` - -Instruct the driver to remove the network (`id`). - -**Example request**: - - DELETE /v1.21/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** - no error -- **404** - no such network -- **500** - server error - -## 3. Going further - -### 3.1 Inside `docker run` - -As an example, the `docker run` command line makes the following API calls: - -- Create the container - -- If the status code is 404, it means the image doesn't exist: - - Try to pull it. - - Then, retry to create the container. - -- Start the container. - -- If you are not in detached mode: -- Attach to the container, using `logs=1` (to have `stdout` and - `stderr` from the container's start) and `stream=1` - -- If in detached mode or only `stdin` is attached, display the container's id. - -### 3.2 Hijacking - -In this version of the API, `/attach`, uses hijacking to transport `stdin`, -`stdout`, and `stderr` on the same socket. - -To hint potential proxies about connection hijacking, Docker client sends -connection upgrade headers similarly to websocket. - - Upgrade: tcp - Connection: Upgrade - -When Docker daemon detects the `Upgrade` header, it switches its status code -from **200 OK** to **101 UPGRADED** and resends the same headers. - - -### 3.3 CORS Requests - -To set cross origin requests to the Engine API please give values to -`--api-cors-header` when running Docker in daemon mode. Set * (asterisk) allows all, -default or blank means CORS disabled - - $ dockerd -H="192.168.1.9:2375" --api-cors-header="http://foo.bar" diff --git a/vendor/github.com/docker/docker/docs/api/v1.22.md b/vendor/github.com/docker/docker/docs/api/v1.22.md deleted file mode 100644 index e940813..0000000 --- a/vendor/github.com/docker/docker/docs/api/v1.22.md +++ /dev/null @@ -1,3307 +0,0 @@ ---- -title: "Engine API v1.22" -description: "API Documentation for Docker" -keywords: "API, Docker, rcli, REST, documentation" -redirect_from: -- /engine/reference/api/docker_remote_api_v1.22/ -- /reference/api/docker_remote_api_v1.22/ ---- - - - -## 1. Brief introduction - - - The daemon listens on `unix:///var/run/docker.sock` but you can - [Bind Docker to another host/port or a Unix socket](../reference/commandline/dockerd.md#bind-docker-to-another-host-port-or-a-unix-socket). - - The API tends to be REST. However, for some complex commands, like `attach` - or `pull`, the HTTP connection is hijacked to transport `stdout`, - `stdin` and `stderr`. - -## 2. Endpoints - -### 2.1 Containers - -#### List containers - -`GET /containers/json` - -List containers - -**Example request**: - - GET /v1.22/containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "8dfafdbc3a40", - "Names":["/boring_feynman"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 1", - "Created": 1367854155, - "Status": "Exit 0", - "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}], - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "SizeRw": 12288, - "SizeRootFs": 0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "2cdc4edb1ded3631c81f57966563e5c8525b81121bb3706a9a9a3ae102711f3f", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.2", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:02" - } - } - } - }, - { - "Id": "9cd87474be90", - "Names":["/coolName"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 222222", - "Created": 1367854155, - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "88eaed7b37b38c2a3f0c4bc796494fdf51b270c2d22656412a2ca5d559a64d7a", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.8", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:08" - } - } - } - }, - { - "Id": "3176a2479c92", - "Names":["/sleepy_dog"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 3333333333333333", - "Created": 1367854154, - "Status": "Exit 0", - "Ports":[], - "Labels": {}, - "SizeRw":12288, - "SizeRootFs":0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "8b27c041c30326d59cd6e6f510d4f8d1d570a228466f956edf7815508f78e30d", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.6", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:06" - } - } - } - }, - { - "Id": "4cb07b47f9fb", - "Names":["/running_cat"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 444444444444444444444444444444444", - "Created": 1367854152, - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "d91c7b2f0644403d7ef3095985ea0e2370325cd2332ff3a3225c4247328e66e9", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.5", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:05" - } - } - } - } - ] - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, Show all containers. - Only running containers are shown by default (i.e., this defaults to false) -- **limit** – Show `limit` last created - containers, include non-running ones. -- **since** – Show only containers created since Id, include - non-running ones. -- **before** – Show only containers created before Id, include - non-running ones. -- **size** – 1/True/true or 0/False/false, Show the containers - sizes -- **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: - - `exited=`; -- containers with exit code of `` ; - - `status=`(`created`|`restarting`|`running`|`paused`|`exited`|`dead`) - - `label=key` or `label="key=value"` of a container label - - `isolation=`(`default`|`process`|`hyperv`) (Windows daemon only) - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **500** – server error - -#### Create a container - -`POST /containers/create` - -Create a container - -**Example request**: - - POST /v1.22/containers/create HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": [ - "FOO=bar", - "BAZ=quux" - ], - "Cmd": [ - "date" - ], - "Entrypoint": null, - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "/volumes/data": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "StopSignal": "SIGTERM", - "HostConfig": { - "Binds": ["/tmp:/tmp"], - "Tmpfs": { "/run": "rw,noexec,nosuid,size=65536k" }, - "Links": ["redis3:redis"], - "Memory": 0, - "MemorySwap": 0, - "MemoryReservation": 0, - "KernelMemory": 0, - "CpuShares": 512, - "CpuPeriod": 100000, - "CpuQuota": 50000, - "CpusetCpus": "0,1", - "CpusetMems": "0,1", - "BlkioWeight": 300, - "BlkioWeightDevice": [{}], - "BlkioDeviceReadBps": [{}], - "BlkioDeviceReadIOps": [{}], - "BlkioDeviceWriteBps": [{}], - "BlkioDeviceWriteIOps": [{}], - "MemorySwappiness": 60, - "OomKillDisable": false, - "OomScoreAdj": 500, - "PidMode": "", - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsOptions": [""], - "DnsSearch": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "GroupAdd": ["newgroup"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [], - "CgroupParent": "", - "VolumeDriver": "", - "ShmSize": 67108864 - }, - "NetworkingConfig": { - "EndpointsConfig": { - "isolated_nw" : { - "IPAMConfig": { - "IPv4Address":"172.20.30.33", - "IPv6Address":"2001:db8:abcd::3033" - }, - "Links":["container_1", "container_2"], - "Aliases":["server_x", "server_y"] - } - } - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id":"e90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **Hostname** - A string value containing the hostname to use for the - container. -- **Domainname** - A string value containing the domain name to use - for the container. -- **User** - A string value specifying the user inside the container. -- **AttachStdin** - Boolean value, attaches to `stdin`. -- **AttachStdout** - Boolean value, attaches to `stdout`. -- **AttachStderr** - Boolean value, attaches to `stderr`. -- **Tty** - Boolean value, Attach standard streams to a `tty`, including `stdin` if it is not closed. -- **OpenStdin** - Boolean value, opens `stdin`, -- **StdinOnce** - Boolean value, close `stdin` after the 1 attached client disconnects. -- **Env** - A list of environment variables in the form of `["VAR=value", ...]` -- **Labels** - Adds a map of labels to a container. To specify a map: `{"key":"value", ... }` -- **Cmd** - Command to run specified as a string or an array of strings. -- **Entrypoint** - Set the entry point for the container as a string or an array - of strings. -- **Image** - A string specifying the image name to use for the container. -- **Volumes** - An object mapping mount point paths (strings) inside the - container to empty objects. -- **WorkingDir** - A string specifying the working directory for commands to - run in. -- **NetworkDisabled** - Boolean value, when true disables networking for the - container -- **ExposedPorts** - An object mapping ports to an empty object in the form of: - `"ExposedPorts": { "/: {}" }` -- **StopSignal** - Signal to stop a container as a string or unsigned integer. `SIGTERM` by default. -- **HostConfig** - - **Binds** – A list of volume bindings for this container. Each volume binding is a string in one of these forms: - + `host-src:container-dest` to bind-mount a host path into the - container. Both `host-src`, and `container-dest` must be an - _absolute_ path. - + `host-src:container-dest:ro` to make the bind-mount read-only - inside the container. Both `host-src`, and `container-dest` must be - an _absolute_ path. - + `volume-name:container-dest` to bind-mount a volume managed by a - volume driver into the container. `container-dest` must be an - _absolute_ path. - + `volume-name:container-dest:ro` to mount the volume read-only - inside the container. `container-dest` must be an _absolute_ path. - - **Tmpfs** – A map of container directories which should be replaced by tmpfs mounts, and their corresponding - mount options. A JSON object in the form `{ "/run": "rw,noexec,nosuid,size=65536k" }`. - - **Links** - A list of links for the container. Each link entry should be - in the form of `container_name:alias`. - - **Memory** - Memory limit in bytes. - - **MemorySwap** - Total memory limit (memory + swap); set `-1` to enable unlimited swap. - You must use this with `memory` and make the swap value larger than `memory`. - - **MemoryReservation** - Memory soft limit in bytes. - - **KernelMemory** - Kernel memory limit in bytes. - - **CpuShares** - An integer value containing the container's CPU Shares - (ie. the relative weight vs other containers). - - **CpuPeriod** - The length of a CPU period in microseconds. - - **CpuQuota** - Microseconds of CPU time that the container can get in a CPU period. - - **CpusetCpus** - String value containing the `cgroups CpusetCpus` to use. - - **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. - - **BlkioWeight** - Block IO weight (relative weight) accepts a weight value between 10 and 1000. - - **BlkioWeightDevice** - Block IO weight (relative device weight) in the form of: `"BlkioWeightDevice": [{"Path": "device_path", "Weight": weight}]` - - **BlkioDeviceReadBps** - Limit read rate (bytes per second) from a device in the form of: `"BlkioDeviceReadBps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceReadBps": [{"Path": "/dev/sda", "Rate": "1024"}]"` - - **BlkioDeviceWriteBps** - Limit write rate (bytes per second) to a device in the form of: `"BlkioDeviceWriteBps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceWriteBps": [{"Path": "/dev/sda", "Rate": "1024"}]"` - - **BlkioDeviceReadIOps** - Limit read rate (IO per second) from a device in the form of: `"BlkioDeviceReadIOps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceReadIOps": [{"Path": "/dev/sda", "Rate": "1000"}]` - - **BlkioDeviceWiiteIOps** - Limit write rate (IO per second) to a device in the form of: `"BlkioDeviceWriteIOps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceWriteIOps": [{"Path": "/dev/sda", "Rate": "1000"}]` - - **MemorySwappiness** - Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. - - **OomKillDisable** - Boolean value, whether to disable OOM Killer for the container or not. - - **OomScoreAdj** - An integer value containing the score given to the container in order to tune OOM killer preferences. - - **PidMode** - Set the PID (Process) Namespace mode for the container; - `"container:"`: joins another container's PID namespace - `"host"`: use the host's PID namespace inside the container - - **PortBindings** - A map of exposed container ports and the host port they - should map to. A JSON object in the form - `{ /: [{ "HostPort": "" }] }` - Take note that `port` is specified as a string and not an integer value. - - **PublishAllPorts** - Allocates a random host port for all of a container's - exposed ports. Specified as a boolean value. - - **Privileged** - Gives the container full access to the host. Specified as - a boolean value. - - **ReadonlyRootfs** - Mount the container's root filesystem as read only. - Specified as a boolean value. - - **Dns** - A list of DNS servers for the container to use. - - **DnsOptions** - A list of DNS options - - **DnsSearch** - A list of DNS search domains - - **ExtraHosts** - A list of hostnames/IP mappings to add to the - container's `/etc/hosts` file. Specified in the form `["hostname:IP"]`. - - **VolumesFrom** - A list of volumes to inherit from another container. - Specified in the form `[:]` - - **CapAdd** - A list of kernel capabilities to add to the container. - - **Capdrop** - A list of kernel capabilities to drop from the container. - - **GroupAdd** - A list of additional groups that the container process will run as - - **RestartPolicy** – The behavior to apply when the container exits. The - value is an object with a `Name` property of either `"always"` to - always restart, `"unless-stopped"` to restart always except when - user has manually stopped the container or `"on-failure"` to restart only when the container - exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` - controls the number of times to retry before giving up. - The default is not to restart. (optional) - An ever increasing delay (double the previous delay, starting at 100mS) - is added before each restart to prevent flooding the server. - - **NetworkMode** - Sets the networking mode for the container. Supported - standard values are: `bridge`, `host`, `none`, and `container:`. Any other value is taken - as a custom network's name to which this container should connect to. - - **Devices** - A list of devices to add to the container specified as a JSON object in the - form - `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` - - **Ulimits** - A list of ulimits to set in the container, specified as - `{ "Name": , "Soft": , "Hard": }`, for example: - `Ulimits: { "Name": "nofile", "Soft": 1024, "Hard": 2048 }` - - **SecurityOpt**: A list of string values to customize labels for MLS - systems, such as SELinux. - - **LogConfig** - Log configuration for the container, specified as a JSON object in the form - `{ "Type": "", "Config": {"key1": "val1"}}`. - Available types: `json-file`, `syslog`, `journald`, `gelf`, `awslogs`, `splunk`, `none`. - `json-file` logging driver. - - **CgroupParent** - Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist. - - **VolumeDriver** - Driver that this container users to mount volumes. - - **ShmSize** - Size of `/dev/shm` in bytes. The size must be greater than 0. If omitted the system uses 64MB. - -**Query parameters**: - -- **name** – Assign the specified name to the container. Must - match `/?[a-zA-Z0-9_-]+`. - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such container -- **406** – impossible to attach (container not running) -- **409** – conflict -- **500** – server error - -#### Inspect a container - -`GET /containers/(id or name)/json` - -Return low-level information on the container `id` - -**Example request**: - - GET /v1.22/containers/4fa6e0f0c678/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "AppArmorProfile": "", - "Args": [ - "-c", - "exit 9" - ], - "Config": { - "AttachStderr": true, - "AttachStdin": false, - "AttachStdout": true, - "Cmd": [ - "/bin/sh", - "-c", - "exit 9" - ], - "Domainname": "", - "Entrypoint": null, - "Env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts": null, - "Hostname": "ba033ac44011", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "MacAddress": "", - "NetworkDisabled": false, - "OnBuild": null, - "OpenStdin": false, - "StdinOnce": false, - "Tty": false, - "User": "", - "Volumes": { - "/volumes/data": {} - }, - "WorkingDir": "", - "StopSignal": "SIGTERM" - }, - "Created": "2015-01-06T15:47:31.485331387Z", - "Driver": "devicemapper", - "ExecIDs": null, - "HostConfig": { - "Binds": null, - "BlkioWeight": 0, - "BlkioWeightDevice": [{}], - "BlkioDeviceReadBps": [{}], - "BlkioDeviceWriteBps": [{}], - "BlkioDeviceReadIOps": [{}], - "BlkioDeviceWriteIOps": [{}], - "CapAdd": null, - "CapDrop": null, - "ContainerIDFile": "", - "CpusetCpus": "", - "CpusetMems": "", - "CpuShares": 0, - "CpuPeriod": 100000, - "Devices": [], - "Dns": null, - "DnsOptions": null, - "DnsSearch": null, - "ExtraHosts": null, - "IpcMode": "", - "Links": null, - "LxcConf": [], - "Memory": 0, - "MemorySwap": 0, - "MemoryReservation": 0, - "KernelMemory": 0, - "OomKillDisable": false, - "OomScoreAdj": 500, - "NetworkMode": "bridge", - "PidMode": "", - "PortBindings": {}, - "Privileged": false, - "ReadonlyRootfs": false, - "PublishAllPorts": false, - "RestartPolicy": { - "MaximumRetryCount": 2, - "Name": "on-failure" - }, - "LogConfig": { - "Config": null, - "Type": "json-file" - }, - "SecurityOpt": null, - "VolumesFrom": null, - "Ulimits": [{}], - "VolumeDriver": "", - "ShmSize": 67108864 - }, - "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname", - "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39", - "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2", - "MountLabel": "", - "Name": "/boring_euclid", - "NetworkSettings": { - "Bridge": "", - "SandboxID": "", - "HairpinMode": false, - "LinkLocalIPv6Address": "", - "LinkLocalIPv6PrefixLen": 0, - "Ports": null, - "SandboxKey": "", - "SecondaryIPAddresses": null, - "SecondaryIPv6Addresses": null, - "EndpointID": "", - "Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "IPAddress": "", - "IPPrefixLen": 0, - "IPv6Gateway": "", - "MacAddress": "", - "Networks": { - "bridge": { - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.2", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:12:00:02" - } - } - }, - "Path": "/bin/sh", - "ProcessLabel": "", - "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf", - "RestartCount": 1, - "State": { - "Error": "", - "ExitCode": 9, - "FinishedAt": "2015-01-06T15:47:32.080254511Z", - "OOMKilled": false, - "Dead": false, - "Paused": false, - "Pid": 0, - "Restarting": false, - "Running": true, - "StartedAt": "2015-01-06T15:47:32.072697474Z", - "Status": "running" - }, - "Mounts": [ - { - "Name": "fac362...80535", - "Source": "/data", - "Destination": "/data", - "Driver": "local", - "Mode": "ro,Z", - "RW": false, - "Propagation": "" - } - ] - } - -**Example request, with size information**: - - GET /v1.22/containers/4fa6e0f0c678/json?size=1 HTTP/1.1 - -**Example response, with size information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - .... - "SizeRw": 0, - "SizeRootFs": 972, - .... - } - -**Query parameters**: - -- **size** – 1/True/true or 0/False/false, return container size information. Default is `false`. - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### List processes running inside a container - -`GET /containers/(id or name)/top` - -List processes running inside the container `id`. On Unix systems this -is done by running the `ps` command. This endpoint is not -supported on Windows. - -**Example request**: - - GET /v1.22/containers/4fa6e0f0c678/top HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD" - ], - "Processes" : [ - [ - "root", "13642", "882", "0", "17:03", "pts/0", "00:00:00", "/bin/bash" - ], - [ - "root", "13735", "13642", "0", "17:06", "pts/0", "00:00:00", "sleep 10" - ] - ] - } - -**Example request**: - - GET /v1.22/containers/4fa6e0f0c678/top?ps_args=aux HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND" - ] - "Processes" : [ - [ - "root","13642","0.0","0.1","18172","3184","pts/0","Ss","17:03","0:00","/bin/bash" - ], - [ - "root","13895","0.0","0.0","4348","692","pts/0","S+","17:15","0:00","sleep 10" - ] - ], - } - -**Query parameters**: - -- **ps_args** – `ps` arguments to use (e.g., `aux`), defaults to `-ef` - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container logs - -`GET /containers/(id or name)/logs` - -Get `stdout` and `stderr` logs from the container ``id`` - -> **Note**: -> This endpoint works only for containers with the `json-file` or `journald` logging drivers. - -**Example request**: - - GET /v1.22/containers/4fa6e0f0c678/logs?stderr=1&stdout=1×tamps=1&follow=1&tail=10&since=1428990821 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **follow** – 1/True/true or 0/False/false, return stream. Default `false`. -- **stdout** – 1/True/true or 0/False/false, show `stdout` log. Default `false`. -- **stderr** – 1/True/true or 0/False/false, show `stderr` log. Default `false`. -- **since** – UNIX timestamp (integer) to filter logs. Specifying a timestamp - will only output log-entries since that timestamp. Default: 0 (unfiltered) -- **timestamps** – 1/True/true or 0/False/false, print timestamps for - every log line. Default `false`. -- **tail** – Output specified number of lines at the end of logs: `all` or ``. Default all. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **404** – no such container -- **500** – server error - -#### Inspect changes on a container's filesystem - -`GET /containers/(id or name)/changes` - -Inspect changes on container `id`'s filesystem - -**Example request**: - - GET /v1.22/containers/4fa6e0f0c678/changes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Path": "/dev", - "Kind": 0 - }, - { - "Path": "/dev/kmsg", - "Kind": 1 - }, - { - "Path": "/test", - "Kind": 1 - } - ] - -Values for `Kind`: - -- `0`: Modify -- `1`: Add -- `2`: Delete - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Export a container - -`GET /containers/(id or name)/export` - -Export the contents of container `id` - -**Example request**: - - GET /v1.22/containers/4fa6e0f0c678/export HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/octet-stream - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container stats based on resource usage - -`GET /containers/(id or name)/stats` - -This endpoint returns a live stream of a container's resource usage statistics. - -**Example request**: - - GET /v1.22/containers/redis1/stats HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "read" : "2015-01-08T22:57:31.547920715Z", - "networks": { - "eth0": { - "rx_bytes": 5338, - "rx_dropped": 0, - "rx_errors": 0, - "rx_packets": 36, - "tx_bytes": 648, - "tx_dropped": 0, - "tx_errors": 0, - "tx_packets": 8 - }, - "eth5": { - "rx_bytes": 4641, - "rx_dropped": 0, - "rx_errors": 0, - "rx_packets": 26, - "tx_bytes": 690, - "tx_dropped": 0, - "tx_errors": 0, - "tx_packets": 9 - } - }, - "memory_stats" : { - "stats" : { - "total_pgmajfault" : 0, - "cache" : 0, - "mapped_file" : 0, - "total_inactive_file" : 0, - "pgpgout" : 414, - "rss" : 6537216, - "total_mapped_file" : 0, - "writeback" : 0, - "unevictable" : 0, - "pgpgin" : 477, - "total_unevictable" : 0, - "pgmajfault" : 0, - "total_rss" : 6537216, - "total_rss_huge" : 6291456, - "total_writeback" : 0, - "total_inactive_anon" : 0, - "rss_huge" : 6291456, - "hierarchical_memory_limit" : 67108864, - "total_pgfault" : 964, - "total_active_file" : 0, - "active_anon" : 6537216, - "total_active_anon" : 6537216, - "total_pgpgout" : 414, - "total_cache" : 0, - "inactive_anon" : 0, - "active_file" : 0, - "pgfault" : 964, - "inactive_file" : 0, - "total_pgpgin" : 477 - }, - "max_usage" : 6651904, - "usage" : 6537216, - "failcnt" : 0, - "limit" : 67108864 - }, - "blkio_stats" : {}, - "cpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24472255, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100215355, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 739306590000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - }, - "precpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24350896, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100093996, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 9492140000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - } - } - -The precpu_stats is the cpu statistic of last read, which is used for calculating the cpu usage percent. It is not the exact copy of the “cpu_stats” field. - -**Query parameters**: - -- **stream** – 1/True/true or 0/False/false, pull stats once then disconnect. Default `true`. - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Resize a container TTY - -`POST /containers/(id or name)/resize` - -Resize the TTY for container with `id`. The unit is number of characters. You must restart the container for the resize to take effect. - -**Example request**: - - POST /v1.22/containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **200** – no error -- **404** – No such container -- **500** – Cannot resize container - -#### Start a container - -`POST /containers/(id or name)/start` - -Start the container `id` - -> **Note**: -> For backwards compatibility, this endpoint accepts a `HostConfig` as JSON-encoded request body. -> See [create a container](#create-a-container) for details. - -**Example request**: - - POST /v1.22/containers/e90e34656806/start HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **detachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. - -**Status codes**: - -- **204** – no error -- **304** – container already started -- **404** – no such container -- **500** – server error - -#### Stop a container - -`POST /containers/(id or name)/stop` - -Stop the container `id` - -**Example request**: - - POST /v1.22/containers/e90e34656806/stop?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **304** – container already stopped -- **404** – no such container -- **500** – server error - -#### Restart a container - -`POST /containers/(id or name)/restart` - -Restart the container `id` - -**Example request**: - - POST /v1.22/containers/e90e34656806/restart?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Kill a container - -`POST /containers/(id or name)/kill` - -Kill the container `id` - -**Example request**: - - POST /v1.22/containers/e90e34656806/kill HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **signal** - Signal to send to the container: integer or string like `SIGINT`. - When not set, `SIGKILL` is assumed and the call waits for the container to exit. - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Update a container - -`POST /containers/(id or name)/update` - -Update resource configs of one or more containers. - -**Example request**: - - POST /v1.22/containers/e90e34656806/update HTTP/1.1 - Content-Type: application/json - - { - "BlkioWeight": 300, - "CpuShares": 512, - "CpuPeriod": 100000, - "CpuQuota": 50000, - "CpusetCpus": "0,1", - "CpusetMems": "0", - "Memory": 314572800, - "MemorySwap": 514288000, - "MemoryReservation": 209715200, - "KernelMemory": 52428800, - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Warnings": [] - } - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -#### Rename a container - -`POST /containers/(id or name)/rename` - -Rename the container `id` to a `new_name` - -**Example request**: - - POST /v1.22/containers/e90e34656806/rename?name=new_name HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **name** – new name for the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **409** - conflict name already assigned -- **500** – server error - -#### Pause a container - -`POST /containers/(id or name)/pause` - -Pause the container `id` - -**Example request**: - - POST /v1.22/containers/e90e34656806/pause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Unpause a container - -`POST /containers/(id or name)/unpause` - -Unpause the container `id` - -**Example request**: - - POST /v1.22/containers/e90e34656806/unpause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Attach to a container - -`POST /containers/(id or name)/attach` - -Attach to the container `id` - -**Example request**: - - POST /v1.22/containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **detachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **400** – bad parameter -- **404** – no such container -- **409** - container is paused -- **500** – server error - -**Stream details**: - -When using the TTY setting is enabled in -[`POST /containers/create` -](#create-a-container), -the stream is the raw data from the process PTY and client's `stdin`. -When the TTY is disabled, then the stream is multiplexed to separate -`stdout` and `stderr`. - -The format is a **Header** and a **Payload** (frame). - -**HEADER** - -The header contains the information which the stream writes (`stdout` or -`stderr`). It also contains the size of the associated frame encoded in the -last four bytes (`uint32`). - -It is encoded on the first eight bytes like this: - - header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} - -`STREAM_TYPE` can be: - -- 0: `stdin` (is written on `stdout`) -- 1: `stdout` -- 2: `stderr` - -`SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of -the `uint32` size encoded as big endian. - -**PAYLOAD** - -The payload is the raw stream. - -**IMPLEMENTATION** - -The simplest way to implement the Attach protocol is the following: - - 1. Read eight bytes. - 2. Choose `stdout` or `stderr` depending on the first byte. - 3. Extract the frame size from the last four bytes. - 4. Read the extracted size and output it on the correct output. - 5. Goto 1. - -#### Attach to a container (websocket) - -`GET /containers/(id or name)/attach/ws` - -Attach to the container `id` via websocket - -Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455) - -**Example request** - - GET /v1.22/containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 - -**Example response** - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **detachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -#### Wait a container - -`POST /containers/(id or name)/wait` - -Block until container `id` stops, then returns the exit code - -**Example request**: - - POST /v1.22/containers/16253994b7c4/wait HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"StatusCode": 0} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Remove a container - -`DELETE /containers/(id or name)` - -Remove the container `id` from the filesystem - -**Example request**: - - DELETE /v1.22/containers/16253994b7c4?v=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **v** – 1/True/true or 0/False/false, Remove the volumes - associated to the container. Default `false`. -- **force** - 1/True/true or 0/False/false, Kill then remove the container. - Default `false`. - -**Status codes**: - -- **204** – no error -- **400** – bad parameter -- **404** – no such container -- **409** – conflict -- **500** – server error - -#### Copy files or folders from a container - -`POST /containers/(id or name)/copy` - -Copy files or folders of container `id` - -**Deprecated** in favor of the `archive` endpoint below. - -**Example request**: - - POST /v1.22/containers/4fa6e0f0c678/copy HTTP/1.1 - Content-Type: application/json - - { - "Resource": "test.txt" - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Retrieving information about files and folders in a container - -`HEAD /containers/(id or name)/archive` - -See the description of the `X-Docker-Container-Path-Stat` header in the -following section. - -#### Get an archive of a filesystem resource in a container - -`GET /containers/(id or name)/archive` - -Get a tar archive of a resource in the filesystem of container `id`. - -**Query parameters**: - -- **path** - resource in the container's filesystem to archive. Required. - - If not an absolute path, it is relative to the container's root directory. - The resource specified by **path** must exist. To assert that the resource - is expected to be a directory, **path** should end in `/` or `/.` - (assuming a path separator of `/`). If **path** ends in `/.` then this - indicates that only the contents of the **path** directory should be - copied. A symlink is always resolved to its target. - - > **Note**: It is not possible to copy certain system files such as resources - > under `/proc`, `/sys`, `/dev`, and mounts created by the user in the - > container. - -**Example request**: - - GET /v1.22/containers/8cce319429b2/archive?path=/root HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - X-Docker-Container-Path-Stat: eyJuYW1lIjoicm9vdCIsInNpemUiOjQwOTYsIm1vZGUiOjIxNDc0ODQwOTYsIm10aW1lIjoiMjAxNC0wMi0yN1QyMDo1MToyM1oiLCJsaW5rVGFyZ2V0IjoiIn0= - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -On success, a response header `X-Docker-Container-Path-Stat` will be set to a -base64-encoded JSON object containing some filesystem header information about -the archived resource. The above example value would decode to the following -JSON object (whitespace added for readability): - -```json -{ - "name": "root", - "size": 4096, - "mode": 2147484096, - "mtime": "2014-02-27T20:51:23Z", - "linkTarget": "" -} -``` - -A `HEAD` request can also be made to this endpoint if only this information is -desired. - -**Status codes**: - -- **200** - success, returns archive of copied resource -- **400** - client error, bad parameter, details in JSON response body, one of: - - must specify path parameter (**path** cannot be empty) - - not a directory (**path** was asserted to be a directory but exists as a - file) -- **404** - client error, resource not found, one of: - – no such container (container `id` does not exist) - - no such file or directory (**path** does not exist) -- **500** - server error - -#### Extract an archive of files or folders to a directory in a container - -`PUT /containers/(id or name)/archive` - -Upload a tar archive to be extracted to a path in the filesystem of container -`id`. - -**Query parameters**: - -- **path** - path to a directory in the container - to extract the archive's contents into. Required. - - If not an absolute path, it is relative to the container's root directory. - The **path** resource must exist. -- **noOverwriteDirNonDir** - If "1", "true", or "True" then it will be an error - if unpacking the given content would cause an existing directory to be - replaced with a non-directory and vice versa. - -**Example request**: - - PUT /v1.22/containers/8cce319429b2/archive?path=/vol1 HTTP/1.1 - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – the content was extracted successfully -- **400** - client error, bad parameter, details in JSON response body, one of: - - must specify path parameter (**path** cannot be empty) - - not a directory (**path** should be a directory but exists as a file) - - unable to overwrite existing directory with non-directory - (if **noOverwriteDirNonDir**) - - unable to overwrite existing non-directory with directory - (if **noOverwriteDirNonDir**) -- **403** - client error, permission denied, the volume - or container rootfs is marked as read-only. -- **404** - client error, resource not found, one of: - – no such container (container `id` does not exist) - - no such file or directory (**path** resource does not exist) -- **500** – server error - -### 2.2 Images - -#### List Images - -`GET /images/json` - -**Example request**: - - GET /v1.22/images/json?all=0 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "RepoTags": [ - "ubuntu:12.04", - "ubuntu:precise", - "ubuntu:latest" - ], - "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", - "Created": 1365714795, - "Size": 131506275, - "VirtualSize": 131506275, - "Labels": {} - }, - { - "RepoTags": [ - "ubuntu:12.10", - "ubuntu:quantal" - ], - "ParentId": "27cf784147099545", - "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "Created": 1364102658, - "Size": 24653, - "VirtualSize": 180116135, - "Labels": { - "com.example.version": "v1" - } - } - ] - -**Example request, with digest information**: - - GET /v1.22/images/json?digests=1 HTTP/1.1 - -**Example response, with digest information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Created": 1420064636, - "Id": "4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125", - "ParentId": "ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2", - "RepoDigests": [ - "localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags": [ - "localhost:5000/test/busybox:latest", - "playdate:latest" - ], - "Size": 0, - "VirtualSize": 2429728, - "Labels": {} - } - ] - -The response shows a single image `Id` associated with two repositories -(`RepoTags`): `localhost:5000/test/busybox`: and `playdate`. A caller can use -either of the `RepoTags` values `localhost:5000/test/busybox:latest` or -`playdate:latest` to reference the image. - -You can also use `RepoDigests` values to reference an image. In this response, -the array has only one reference and that is to the -`localhost:5000/test/busybox` repository; the `playdate` repository has no -digest. You can reference this digest using the value: -`localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d...` - -See the `docker run` and `docker build` commands for examples of digest and tag -references on the command line. - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, default false -- **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: - - `dangling=true` - - `label=key` or `label="key=value"` of an image label -- **filter** - only return images with the specified name - -#### Build image from a Dockerfile - -`POST /build` - -Build an image from a Dockerfile - -**Example request**: - - POST /v1.22/build HTTP/1.1 - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"stream": "Step 1/5..."} - {"stream": "..."} - {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} - -The input stream must be a `tar` archive compressed with one of the -following algorithms: `identity` (no compression), `gzip`, `bzip2`, `xz`. - -The archive must include a build instructions file, typically called -`Dockerfile` at the archive's root. The `dockerfile` parameter may be -used to specify a different build instructions file. To do this, its value must be -the path to the alternate build instructions file to use. - -The archive may include any number of other files, -which are accessible in the build context (See the [*ADD build -command*](../reference/builder.md#add)). - -The Docker daemon performs a preliminary validation of the `Dockerfile` before -starting the build, and returns an error if the syntax is incorrect. After that, -each instruction is run one-by-one until the ID of the new image is output. - -The build is canceled if the client drops the connection by quitting -or being killed. - -**Query parameters**: - -- **dockerfile** - Path within the build context to the `Dockerfile`. This is - ignored if `remote` is specified and points to an external `Dockerfile`. -- **t** – A name and optional tag to apply to the image in the `name:tag` format. - If you omit the `tag` the default `latest` value is assumed. - You can provide one or more `t` parameters. -- **remote** – A Git repository URI or HTTP/HTTPS context URI. If the - URI points to a single text file, the file's contents are placed into - a file called `Dockerfile` and the image is built from that file. If - the URI points to a tarball, the file is downloaded by the daemon and - the contents therein used as the context for the build. If the URI - points to a tarball and the `dockerfile` parameter is also specified, - there must be a file with the corresponding path inside the tarball. -- **q** – Suppress verbose build output. -- **nocache** – Do not use the cache when building the image. -- **pull** - Attempt to pull the image even if an older image exists locally. -- **rm** - Remove intermediate containers after a successful build (default behavior). -- **forcerm** - Always remove intermediate containers (includes `rm`). -- **memory** - Set memory limit for build. -- **memswap** - Total memory (memory + swap), `-1` to enable unlimited swap. -- **cpushares** - CPU shares (relative weight). -- **cpusetcpus** - CPUs in which to allow execution (e.g., `0-3`, `0,1`). -- **cpuperiod** - The length of a CPU period in microseconds. -- **cpuquota** - Microseconds of CPU time that the container can get in a CPU period. -- **buildargs** – JSON map of string pairs for build-time variables. Users pass - these values at build-time. Docker uses the `buildargs` as the environment - context for command(s) run via the Dockerfile's `RUN` instruction or for - variable expansion in other Dockerfile instructions. This is not meant for - passing secret values. [Read more about the buildargs instruction](../reference/builder.md#arg) -- **shmsize** - Size of `/dev/shm` in bytes. The size must be greater than 0. If omitted the system uses 64MB. - -**Request Headers**: - -- **Content-type** – Set to `"application/tar"`. -- **X-Registry-Config** – A base64-url-safe-encoded Registry Auth Config JSON - object with the following structure: - - { - "docker.example.com": { - "username": "janedoe", - "password": "hunter2" - }, - "https://index.docker.io/v1/": { - "username": "mobydock", - "password": "conta1n3rize14" - } - } - - This object maps the hostname of a registry to an object containing the - "username" and "password" for that registry. Multiple registries may - be specified as the build may be based on an image requiring - authentication to pull from any arbitrary registry. Only the registry - domain name (and port if not the default "443") are required. However - (for legacy reasons) the "official" Docker, Inc. hosted registry must - be specified with both a "https://" prefix and a "/v1/" suffix even - though Docker will prefer to use the v2 registry API. - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Create an image - -`POST /images/create` - -Create an image either by pulling it from the registry or by importing it - -**Example request**: - - POST /v1.22/images/create?fromImage=busybox&tag=latest HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pulling..."} - {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} - {"error": "Invalid..."} - ... - -When using this endpoint to pull an image from the registry, the -`X-Registry-Auth` header can be used to include -a base64-encoded AuthConfig object. - -**Query parameters**: - -- **fromImage** – Name of the image to pull. The name may include a tag or - digest. This parameter may only be used when pulling an image. - The pull is cancelled if the HTTP connection is closed. -- **fromSrc** – Source to import. The value may be a URL from which the image - can be retrieved or `-` to read the image from the request body. - This parameter may only be used when importing an image. -- **repo** – Repository name given to an image when it is imported. - The repo may include a tag. This parameter may only be used when importing - an image. -- **tag** – Tag or digest. If empty when pulling an image, this causes all tags - for the given image to be pulled. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object, containing either login information, or a token - - Credential based login: - - ``` - { - "username": "jdoe", - "password": "secret", - "email": "jdoe@acme.com" - } - ``` - - - Token based login: - - ``` - { - "registrytoken": "9cbaf023786cd7..." - } - ``` - -**Status codes**: - -- **200** – no error -- **404** - repository does not exist or no read access -- **500** – server error - - - -#### Inspect an image - -`GET /images/(name)/json` - -Return low-level information on the image `name` - -**Example request**: - - GET /v1.22/images/example/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Id" : "85f05633ddc1c50679be2b16a0479ab6f7637f8884e0cfe0f4d20e1ebb3d6e7c", - "Container" : "cb91e48a60d01f1e27028b4fc6819f4f290b3cf12496c8176ec714d0d390984a", - "Comment" : "", - "Os" : "linux", - "Architecture" : "amd64", - "Parent" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "ContainerConfig" : { - "Tty" : false, - "Hostname" : "e611e15f9c9d", - "Volumes" : null, - "Domainname" : "", - "AttachStdout" : false, - "PublishService" : "", - "AttachStdin" : false, - "OpenStdin" : false, - "StdinOnce" : false, - "NetworkDisabled" : false, - "OnBuild" : [], - "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "User" : "", - "WorkingDir" : "", - "Entrypoint" : null, - "MacAddress" : "", - "AttachStderr" : false, - "Labels" : { - "com.example.license" : "GPL", - "com.example.version" : "1.0", - "com.example.vendor" : "Acme" - }, - "Env" : [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts" : null, - "Cmd" : [ - "/bin/sh", - "-c", - "#(nop) LABEL com.example.vendor=Acme com.example.license=GPL com.example.version=1.0" - ] - }, - "DockerVersion" : "1.9.0-dev", - "VirtualSize" : 188359297, - "Size" : 0, - "Author" : "", - "Created" : "2015-09-10T08:30:53.26995814Z", - "GraphDriver" : { - "Name" : "aufs", - "Data" : null - }, - "RepoDigests" : [ - "localhost:5000/test/busybox/example@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags" : [ - "example:1.0", - "example:latest", - "example:stable" - ], - "Config" : { - "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "NetworkDisabled" : false, - "OnBuild" : [], - "StdinOnce" : false, - "PublishService" : "", - "AttachStdin" : false, - "OpenStdin" : false, - "Domainname" : "", - "AttachStdout" : false, - "Tty" : false, - "Hostname" : "e611e15f9c9d", - "Volumes" : null, - "Cmd" : [ - "/bin/bash" - ], - "ExposedPorts" : null, - "Env" : [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "Labels" : { - "com.example.vendor" : "Acme", - "com.example.version" : "1.0", - "com.example.license" : "GPL" - }, - "Entrypoint" : null, - "MacAddress" : "", - "AttachStderr" : false, - "WorkingDir" : "", - "User" : "" - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Get the history of an image - -`GET /images/(name)/history` - -Return the history of the image `name` - -**Example request**: - - GET /v1.22/images/ubuntu/history HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710", - "Created": 1398108230, - "CreatedBy": "/bin/sh -c #(nop) ADD file:eb15dbd63394e063b805a3c32ca7bf0266ef64676d5a6fab4801f2e81e2a5148 in /", - "Tags": [ - "ubuntu:lucid", - "ubuntu:10.04" - ], - "Size": 182964289, - "Comment": "" - }, - { - "Id": "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8", - "Created": 1398108222, - "CreatedBy": "/bin/sh -c #(nop) MAINTAINER Tianon Gravi - mkimage-debootstrap.sh -i iproute,iputils-ping,ubuntu-minimal -t lucid.tar.xz lucid http://archive.ubuntu.com/ubuntu/", - "Tags": null, - "Size": 0, - "Comment": "" - }, - { - "Id": "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158", - "Created": 1371157430, - "CreatedBy": "", - "Tags": [ - "scratch12:latest", - "scratch:latest" - ], - "Size": 0, - "Comment": "Imported from -" - } - ] - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Push an image on the registry - -`POST /images/(name)/push` - -Push the image `name` on the registry - -**Example request**: - - POST /v1.22/images/test/push HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pushing..."} - {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} - {"error": "Invalid..."} - ... - -If you wish to push an image on to a private registry, that image must already have a tag -into a repository which references that registry `hostname` and `port`. This repository name should -then be used in the URL. This duplicates the command line's flow. - -The push is cancelled if the HTTP connection is closed. - -**Example request**: - - POST /v1.22/images/registry.acme.com:5000/test/push HTTP/1.1 - - -**Query parameters**: - -- **tag** – The tag to associate with the image on the registry. This is optional. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object, containing either login information, or a token - - Credential based login: - - ``` - { - "username": "jdoe", - "password": "secret", - "email": "jdoe@acme.com", - } - ``` - - - Token based login: - - ``` - { - "registrytoken": "9cbaf023786cd7..." - } - ``` - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Tag an image into a repository - -`POST /images/(name)/tag` - -Tag the image `name` into a repository - -**Example request**: - - POST /v1.22/images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 - -**Example response**: - - HTTP/1.1 201 Created - -**Query parameters**: - -- **repo** – The repository to tag in -- **force** – 1/True/true or 0/False/false, default false -- **tag** - The new tag name - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Remove an image - -`DELETE /images/(name)` - -Remove the image `name` from the filesystem - -**Example request**: - - DELETE /v1.22/images/test HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-type: application/json - - [ - {"Untagged": "3e2f21a89f"}, - {"Deleted": "3e2f21a89f"}, - {"Deleted": "53b4f83ac9"} - ] - -**Query parameters**: - -- **force** – 1/True/true or 0/False/false, default false -- **noprune** – 1/True/true or 0/False/false, default false - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Search images - -`GET /images/search` - -Search for an image on [Docker Hub](https://hub.docker.com). - -> **Note**: -> The response keys have changed from API v1.6 to reflect the JSON -> sent by the registry server to the docker daemon's request. - -**Example request**: - - GET /v1.22/images/search?term=sshd HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "wma55/u1210sshd", - "star_count": 0 - }, - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "jdswinbank/sshd", - "star_count": 0 - }, - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "vgauthier/sshd", - "star_count": 0 - } - ... - ] - -**Query parameters**: - -- **term** – term to search - -**Status codes**: - -- **200** – no error -- **500** – server error - -### 2.3 Misc - -#### Check auth configuration - -`POST /auth` - -Get the default username and email - -**Example request**: - - POST /v1.22/auth HTTP/1.1 - Content-Type: application/json - - { - "username": "hannibal", - "password": "xxxx", - "email": "hannibal@a-team.com", - "serveraddress": "https://index.docker.io/v1/" - } - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – no error -- **204** – no error -- **500** – server error - -#### Display system-wide information - -`GET /info` - -Display system-wide information - -**Example request**: - - GET /v1.22/info HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Architecture": "x86_64", - "ClusterStore": "etcd://localhost:2379", - "Containers": 11, - "ContainersRunning": 7, - "ContainersStopped": 3, - "ContainersPaused": 1, - "CpuCfsPeriod": true, - "CpuCfsQuota": true, - "Debug": false, - "DockerRootDir": "/var/lib/docker", - "Driver": "btrfs", - "DriverStatus": [[""]], - "ExecutionDriver": "native-0.1", - "ExperimentalBuild": false, - "HttpProxy": "http://test:test@localhost:8080", - "HttpsProxy": "https://test:test@localhost:8080", - "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", - "IPv4Forwarding": true, - "Images": 16, - "IndexServerAddress": "https://index.docker.io/v1/", - "InitPath": "/usr/bin/docker", - "InitSha1": "", - "KernelVersion": "3.12.0-1-amd64", - "Labels": [ - "storage=ssd" - ], - "MemTotal": 2099236864, - "MemoryLimit": true, - "NCPU": 1, - "NEventsListener": 0, - "NFd": 11, - "NGoroutines": 21, - "Name": "prod-server-42", - "NoProxy": "9.81.1.160", - "OomKillDisable": true, - "OSType": "linux", - "OperatingSystem": "Boot2Docker", - "Plugins": { - "Volume": [ - "local" - ], - "Network": [ - "null", - "host", - "bridge" - ] - }, - "RegistryConfig": { - "IndexConfigs": { - "docker.io": { - "Mirrors": null, - "Name": "docker.io", - "Official": true, - "Secure": true - } - }, - "InsecureRegistryCIDRs": [ - "127.0.0.0/8" - ] - }, - "ServerVersion": "1.9.0", - "SwapLimit": false, - "SystemStatus": [["State", "Healthy"]], - "SystemTime": "2015-03-10T11:11:23.730591467-07:00" - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Show the docker version information - -`GET /version` - -Show the docker version information - -**Example request**: - - GET /v1.22/version HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Version": "1.10.0", - "Os": "linux", - "KernelVersion": "3.19.0-23-generic", - "GoVersion": "go1.4.2", - "GitCommit": "e75da4b", - "Arch": "amd64", - "ApiVersion": "1.22", - "BuildTime": "2015-12-01T07:09:13.444803460+00:00", - "Experimental": true - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Ping the docker server - -`GET /_ping` - -Ping the docker server - -**Example request**: - - GET /v1.22/_ping HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: text/plain - - OK - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a new image from a container's changes - -`POST /commit` - -Create a new image from a container's changes - -**Example request**: - - POST /v1.22/commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Mounts": [ - { - "Source": "/data", - "Destination": "/data", - "Mode": "ro,Z", - "RW": false - } - ], - "Labels": { - "key1": "value1", - "key2": "value2" - }, - "WorkingDir": "", - "NetworkDisabled": false, - "ExposedPorts": { - "22/tcp": {} - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - {"Id": "596069db4bf5"} - -**JSON parameters**: - -- **config** - the container's configuration - -**Query parameters**: - -- **container** – source container -- **repo** – repository -- **tag** – tag -- **comment** – commit message -- **author** – author (e.g., "John Hannibal Smith - <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") -- **pause** – 1/True/true or 0/False/false, whether to pause the container before committing -- **changes** – Dockerfile instructions to apply while committing - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **500** – server error - -#### Monitor Docker's events - -`GET /events` - -Get container events from docker, in real time via streaming. - -Docker containers report the following events: - - attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update - -Docker images report the following events: - - delete, import, pull, push, tag, untag - -Docker volumes report the following events: - - create, mount, unmount, destroy - -Docker networks report the following events: - - create, connect, disconnect, destroy - -**Example request**: - - GET /v1.22/events?since=1374067924 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - Server: Docker/1.10.0 (linux) - Date: Fri, 29 Apr 2016 15:18:06 GMT - Transfer-Encoding: chunked - - { - "status": "pull", - "id": "alpine:latest", - "Type": "image", - "Action": "pull", - "Actor": { - "ID": "alpine:latest", - "Attributes": { - "name": "alpine" - } - }, - "time": 1461943101, - "timeNano": 1461943101301854122 - } - { - "status": "create", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "create", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943101, - "timeNano": 1461943101381709551 - } - { - "status": "attach", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "attach", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943101, - "timeNano": 1461943101383858412 - } - { - "Type": "network", - "Action": "connect", - "Actor": { - "ID": "7dc8ac97d5d29ef6c31b6052f3938c1e8f2749abbd17d1bd1febf2608db1b474", - "Attributes": { - "container": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "name": "bridge", - "type": "bridge" - } - }, - "time": 1461943101, - "timeNano": 1461943101394865557 - } - { - "status": "start", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "start", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943101, - "timeNano": 1461943101607533796 - } - { - "status": "resize", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "resize", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "height": "46", - "image": "alpine", - "name": "my-container", - "width": "204" - } - }, - "time": 1461943101, - "timeNano": 1461943101610269268 - } - { - "status": "die", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "die", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "exitCode": "0", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943105, - "timeNano": 1461943105079144137 - } - { - "Type": "network", - "Action": "disconnect", - "Actor": { - "ID": "7dc8ac97d5d29ef6c31b6052f3938c1e8f2749abbd17d1bd1febf2608db1b474", - "Attributes": { - "container": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "name": "bridge", - "type": "bridge" - } - }, - "time": 1461943105, - "timeNano": 1461943105230860245 - } - { - "status": "destroy", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "destroy", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943105, - "timeNano": 1461943105338056026 - } - -**Query parameters**: - -- **since** – Timestamp. Show all events created since timestamp and then stream -- **until** – Timestamp. Show events created until given timestamp and stop streaming -- **filters** – A json encoded value of the filters (a map[string][]string) to process on the event list. Available filters: - - `container=`; -- container to filter - - `event=`; -- event to filter - - `image=`; -- image to filter - - `label=`; -- image and container label to filter - - `type=`; -- either `container` or `image` or `volume` or `network` - - `volume=`; -- volume to filter - - `network=`; -- network to filter - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images in a repository - -`GET /images/(name)/get` - -Get a tarball containing all images and metadata for the repository specified -by `name`. - -If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image -(and its parents) are returned. If `name` is an image ID, similarly only that -image (and its parents) are returned, but with the exclusion of the -'repositories' file in the tarball, as there were no image names referenced. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.22/images/ubuntu/get - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images - -`GET /images/get` - -Get a tarball containing all images and metadata for one or more repositories. - -For each value of the `names` parameter: if it is a specific name and tag (e.g. -`ubuntu:latest`), then only that image (and its parents) are returned; if it is -an image ID, similarly only that image (and its parents) are returned and there -would be no names referenced in the 'repositories' file for this image ID. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.22/images/get?names=myname%2Fmyapp%3Alatest&names=busybox - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Load a tarball with a set of images and tags into docker - -`POST /images/load` - -Load a set of images and tags into a Docker repository. -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - POST /v1.22/images/load - Content-Type: application/x-tar - - Tarball in body - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Image tarball format - -An image tarball contains one directory per image layer (named using its long ID), -each containing these files: - -- `VERSION`: currently `1.0` - the file format version -- `json`: detailed layer information, similar to `docker inspect layer_id` -- `layer.tar`: A tarfile containing the filesystem changes in this layer - -The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories -for storing attribute changes and deletions. - -If the tarball defines a repository, the tarball should also include a `repositories` file at -the root that contains a list of repository and tag names mapped to layer IDs. - -``` -{"hello-world": - {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} -} -``` - -#### Exec Create - -`POST /containers/(id or name)/exec` - -Sets up an exec instance in a running container `id` - -**Example request**: - - POST /v1.22/containers/e90e34656806/exec HTTP/1.1 - Content-Type: application/json - - { - "AttachStdin": true, - "AttachStdout": true, - "AttachStderr": true, - "Cmd": ["sh"], - "DetachKeys": "ctrl-p,ctrl-q", - "Privileged": true, - "Tty": true, - "User": "123:456" - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id": "f90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **AttachStdin** - Boolean value, attaches to `stdin` of the `exec` command. -- **AttachStdout** - Boolean value, attaches to `stdout` of the `exec` command. -- **AttachStderr** - Boolean value, attaches to `stderr` of the `exec` command. -- **DetachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. -- **Tty** - Boolean value to allocate a pseudo-TTY. -- **Cmd** - Command to run specified as a string or an array of strings. -- **Privileged** - Boolean value, runs the exec process with extended privileges. -- **User** - A string value specifying the user, and optionally, group to run - the exec process inside the container. Format is one of: `"user"`, - `"user:group"`, `"uid"`, or `"uid:gid"`. - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **409** - container is paused -- **500** - server error - -#### Exec Start - -`POST /exec/(id)/start` - -Starts a previously set up `exec` instance `id`. If `detach` is true, this API -returns after starting the `exec` command. Otherwise, this API sets up an -interactive session with the `exec` command. - -**Example request**: - - POST /v1.22/exec/e90e34656806/start HTTP/1.1 - Content-Type: application/json - - { - "Detach": false, - "Tty": false - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/vnd.docker.raw-stream - - {% raw %} - {{ STREAM }} - {% endraw %} - -**JSON parameters**: - -- **Detach** - Detach from the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **409** - container is paused - -**Stream details**: - -Similar to the stream behavior of `POST /containers/(id or name)/attach` API - -#### Exec Resize - -`POST /exec/(id)/resize` - -Resizes the `tty` session used by the `exec` command `id`. The unit is number of characters. -This API is valid only if `tty` was specified as part of creating and starting the `exec` command. - -**Example request**: - - POST /v1.22/exec/e90e34656806/resize?h=40&w=80 HTTP/1.1 - Content-Type: text/plain - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: text/plain - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **201** – no error -- **404** – no such exec instance - -#### Exec Inspect - -`GET /exec/(id)/json` - -Return low-level information about the `exec` command `id`. - -**Example request**: - - GET /v1.22/exec/11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "CanRemove": false, - "ContainerID": "b53ee82b53a40c7dca428523e34f741f3abc51d9f297a14ff874bf761b995126", - "DetachKeys": "", - "ExitCode": 2, - "ID": "f33bbfb39f5b142420f4759b2348913bd4a8d1a6d7fd56499cb41a1bb91d7b3b", - "OpenStderr": true, - "OpenStdin": true, - "OpenStdout": true, - "ProcessConfig": { - "arguments": [ - "-c", - "exit 2" - ], - "entrypoint": "sh", - "privileged": false, - "tty": true, - "user": "1000" - }, - "Running": false - } - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **500** - server error - -### 2.4 Volumes - -#### List volumes - -`GET /volumes` - -**Example request**: - - GET /v1.22/volumes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Volumes": [ - { - "Name": "tardis", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/tardis" - } - ], - "Warnings": [] - } - -**Query parameters**: - -- **filters** - JSON encoded value of the filters (a `map[string][]string`) to process on the volumes list. There is one available filter: `dangling=true` - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a volume - -`POST /volumes/create` - -Create a volume - -**Example request**: - - POST /v1.22/volumes/create HTTP/1.1 - Content-Type: application/json - - { - "Name": "tardis" - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Name": "tardis", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/tardis" - } - -**Status codes**: - -- **201** - no error -- **500** - server error - -**JSON parameters**: - -- **Name** - The new volume's name. If not specified, Docker generates a name. -- **Driver** - Name of the volume driver to use. Defaults to `local` for the name. -- **DriverOpts** - A mapping of driver options and values. These options are - passed directly to the driver and are driver specific. - -#### Inspect a volume - -`GET /volumes/(name)` - -Return low-level information on the volume `name` - -**Example request**: - - GET /volumes/tardis - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Name": "tardis", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/tardis" - } - -**Status codes**: - -- **200** - no error -- **404** - no such volume -- **500** - server error - -#### Remove a volume - -`DELETE /volumes/(name)` - -Instruct the driver to remove the volume (`name`). - -**Example request**: - - DELETE /v1.22/volumes/tardis HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** - no error -- **404** - no such volume or volume driver -- **409** - volume is in use and cannot be removed -- **500** - server error - -### 2.5 Networks - -#### List networks - -`GET /networks` - -**Example request**: - - GET /v1.22/networks?filters={"type":{"custom":true}} HTTP/1.1 - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json - -[ - { - "Name": "bridge", - "Id": "f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566", - "Scope": "local", - "Driver": "bridge", - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.17.0.0/16" - } - ] - }, - "Containers": { - "39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": { - "EndpointID": "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda", - "MacAddress": "02:42:ac:11:00:02", - "IPv4Address": "172.17.0.2/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - } - }, - { - "Name": "none", - "Id": "e086a3893b05ab69242d3c44e49483a3bbbd3a26b46baa8f61ab797c1088d794", - "Scope": "local", - "Driver": "null", - "IPAM": { - "Driver": "default", - "Config": [] - }, - "Containers": {}, - "Options": {} - }, - { - "Name": "host", - "Id": "13e871235c677f196c4e1ecebb9dc733b9b2d2ab589e30c539efeda84a24215e", - "Scope": "local", - "Driver": "host", - "IPAM": { - "Driver": "default", - "Config": [] - }, - "Containers": {}, - "Options": {} - } -] -``` - -**Query parameters**: - -- **filters** - JSON encoded network list filter. The filter value is one of: - - `id=` Matches all or part of a network id. - - `name=` Matches all or part of a network name. - - `type=["custom"|"builtin"]` Filters networks by type. The `custom` keyword returns all user-defined networks. - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Inspect network - -`GET /networks/` - -**Example request**: - - GET /v1.22/networks/7d86d31b1478e7cca9ebed7e73aa0fdeec46c5ca29497431d3007d2d9e15ed99 HTTP/1.1 - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json - -{ - "Name": "net01", - "Id": "7d86d31b1478e7cca9ebed7e73aa0fdeec46c5ca29497431d3007d2d9e15ed99", - "Scope": "local", - "Driver": "bridge", - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.19.0.0/16", - "Gateway": "172.19.0.1/16" - } - ], - "Options": { - "foo": "bar" - } - }, - "Containers": { - "19a4d5d687db25203351ed79d478946f861258f018fe384f229f2efa4b23513c": { - "Name": "test", - "EndpointID": "628cadb8bcb92de107b2a1e516cbffe463e321f548feb37697cce00ad694f21a", - "MacAddress": "02:42:ac:13:00:02", - "IPv4Address": "172.19.0.2/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - } -} -``` - -**Status codes**: - -- **200** - no error -- **404** - network not found - -#### Create a network - -`POST /networks/create` - -Create a network - -**Example request**: - -``` -POST /v1.22/networks/create HTTP/1.1 -Content-Type: application/json - -{ - "Name":"isolated_nw", - "CheckDuplicate":true, - "Driver":"bridge", - "IPAM":{ - "Driver": "default", - "Config":[ - { - "Subnet":"172.20.0.0/16", - "IPRange":"172.20.10.0/24", - "Gateway":"172.20.10.11" - }, - { - "Subnet":"2001:db8:abcd::/64", - "Gateway":"2001:db8:abcd::1011" - } - ], - "Options": { - "foo": "bar" - } - }, - "Internal":true -} -``` - -**Example response**: - -``` -HTTP/1.1 201 Created -Content-Type: application/json - -{ - "Id": "22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30", - "Warning": "" -} -``` - -**Status codes**: - -- **201** - no error -- **404** - plugin not found -- **500** - server error - -**JSON parameters**: - -- **Name** - The new network's name. this is a mandatory field -- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false` -- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver -- **IPAM** - Optional custom IP scheme for the network - - **Driver** - Name of the IPAM driver to use. Defaults to `default` driver - - **Config** - List of IPAM configuration options, specified as a map: - `{"Subnet": , "IPRange": , "Gateway": , "AuxAddress": }` - - **Options** - Driver-specific options, specified as a map: `{"option":"value" [,"option2":"value2"]}` -- **Options** - Network specific options to be used by the drivers - -#### Connect a container to a network - -`POST /networks/(id)/connect` - -Connect a container to a network - -**Example request**: - -``` -POST /v1.22/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30/connect HTTP/1.1 -Content-Type: application/json - -{ - "Container":"3613f73ba0e4", - "EndpointConfig": { - "IPAMConfig": { - "IPv4Address":"172.24.56.89", - "IPv6Address":"2001:db8::5689" - } - } -} -``` - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** - no error -- **404** - network or container is not found -- **500** - Internal Server Error - -**JSON parameters**: - -- **container** - container-id/name to be connected to the network - -#### Disconnect a container from a network - -`POST /networks/(id)/disconnect` - -Disconnect a container from a network - -**Example request**: - -``` -POST /v1.22/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30/disconnect HTTP/1.1 -Content-Type: application/json - -{ - "Container":"3613f73ba0e4", - "Force":false -} -``` - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** - no error -- **404** - network or container not found -- **500** - Internal Server Error - -**JSON parameters**: - -- **Container** - container-id/name to be disconnected from a network -- **Force** - Force the container to disconnect from a network - -#### Remove a network - -`DELETE /networks/(id)` - -Instruct the driver to remove the network (`id`). - -**Example request**: - - DELETE /v1.22/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** - no error -- **404** - no such network -- **500** - server error - -## 3. Going further - -### 3.1 Inside `docker run` - -As an example, the `docker run` command line makes the following API calls: - -- Create the container - -- If the status code is 404, it means the image doesn't exist: - - Try to pull it. - - Then, retry to create the container. - -- Start the container. - -- If you are not in detached mode: -- Attach to the container, using `logs=1` (to have `stdout` and - `stderr` from the container's start) and `stream=1` - -- If in detached mode or only `stdin` is attached, display the container's id. - -### 3.2 Hijacking - -In this version of the API, `/attach`, uses hijacking to transport `stdin`, -`stdout`, and `stderr` on the same socket. - -To hint potential proxies about connection hijacking, Docker client sends -connection upgrade headers similarly to websocket. - - Upgrade: tcp - Connection: Upgrade - -When Docker daemon detects the `Upgrade` header, it switches its status code -from **200 OK** to **101 UPGRADED** and resends the same headers. - - -### 3.3 CORS Requests - -To set cross origin requests to the Engine API please give values to -`--api-cors-header` when running Docker in daemon mode. Set * (asterisk) allows all, -default or blank means CORS disabled - - $ dockerd -H="192.168.1.9:2375" --api-cors-header="http://foo.bar" diff --git a/vendor/github.com/docker/docker/docs/api/v1.23.md b/vendor/github.com/docker/docker/docs/api/v1.23.md deleted file mode 100644 index e23811b..0000000 --- a/vendor/github.com/docker/docker/docs/api/v1.23.md +++ /dev/null @@ -1,3424 +0,0 @@ ---- -title: "Engine API v1.23" -description: "API Documentation for Docker" -keywords: "API, Docker, rcli, REST, documentation" -redirect_from: -- /engine/reference/api/docker_remote_api_v1.23/ -- /reference/api/docker_remote_api_v1.23/ ---- - - - -## 1. Brief introduction - - - The daemon listens on `unix:///var/run/docker.sock` but you can - [Bind Docker to another host/port or a Unix socket](../reference/commandline/dockerd.md#bind-docker-to-another-host-port-or-a-unix-socket). - - The API tends to be REST. However, for some complex commands, like `attach` - or `pull`, the HTTP connection is hijacked to transport `stdout`, - `stdin` and `stderr`. - - When the client API version is newer than the daemon's, these calls return an HTTP - `400 Bad Request` error message. - -## 2. Endpoints - -### 2.1 Containers - -#### List containers - -`GET /containers/json` - -List containers - -**Example request**: - - GET /v1.23/containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "8dfafdbc3a40", - "Names":["/boring_feynman"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 1", - "Created": 1367854155, - "State": "Exited", - "Status": "Exit 0", - "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}], - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "SizeRw": 12288, - "SizeRootFs": 0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "2cdc4edb1ded3631c81f57966563e5c8525b81121bb3706a9a9a3ae102711f3f", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.2", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:02" - } - } - }, - "Mounts": [ - { - "Name": "fac362...80535", - "Source": "/data", - "Destination": "/data", - "Driver": "local", - "Mode": "ro,Z", - "RW": false, - "Propagation": "" - } - ] - }, - { - "Id": "9cd87474be90", - "Names":["/coolName"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 222222", - "Created": 1367854155, - "State": "Exited", - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "88eaed7b37b38c2a3f0c4bc796494fdf51b270c2d22656412a2ca5d559a64d7a", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.8", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:08" - } - } - }, - "Mounts": [] - }, - { - "Id": "3176a2479c92", - "Names":["/sleepy_dog"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 3333333333333333", - "Created": 1367854154, - "State": "Exited", - "Status": "Exit 0", - "Ports":[], - "Labels": {}, - "SizeRw":12288, - "SizeRootFs":0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "8b27c041c30326d59cd6e6f510d4f8d1d570a228466f956edf7815508f78e30d", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.6", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:06" - } - } - }, - "Mounts": [] - }, - { - "Id": "4cb07b47f9fb", - "Names":["/running_cat"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 444444444444444444444444444444444", - "Created": 1367854152, - "State": "Exited", - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "d91c7b2f0644403d7ef3095985ea0e2370325cd2332ff3a3225c4247328e66e9", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.5", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:05" - } - } - }, - "Mounts": [] - } - ] - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, Show all containers. - Only running containers are shown by default (i.e., this defaults to false) -- **limit** – Show `limit` last created - containers, include non-running ones. -- **since** – Show only containers created since Id, include - non-running ones. -- **before** – Show only containers created before Id, include - non-running ones. -- **size** – 1/True/true or 0/False/false, Show the containers - sizes -- **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: - - `exited=`; -- containers with exit code of `` ; - - `status=`(`created`|`restarting`|`running`|`paused`|`exited`|`dead`) - - `label=key` or `label="key=value"` of a container label - - `isolation=`(`default`|`process`|`hyperv`) (Windows daemon only) - - `ancestor`=(`[:]`, `` or ``) - - `before`=(`` or ``) - - `since`=(`` or ``) - - `volume`=(`` or ``) - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **500** – server error - -#### Create a container - -`POST /containers/create` - -Create a container - -**Example request**: - - POST /v1.23/containers/create HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": [ - "FOO=bar", - "BAZ=quux" - ], - "Cmd": [ - "date" - ], - "Entrypoint": "", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "/volumes/data": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "StopSignal": "SIGTERM", - "HostConfig": { - "Binds": ["/tmp:/tmp"], - "Tmpfs": { "/run": "rw,noexec,nosuid,size=65536k" }, - "Links": ["redis3:redis"], - "Memory": 0, - "MemorySwap": 0, - "MemoryReservation": 0, - "KernelMemory": 0, - "CpuShares": 512, - "CpuPeriod": 100000, - "CpuQuota": 50000, - "CpusetCpus": "0,1", - "CpusetMems": "0,1", - "BlkioWeight": 300, - "BlkioWeightDevice": [{}], - "BlkioDeviceReadBps": [{}], - "BlkioDeviceReadIOps": [{}], - "BlkioDeviceWriteBps": [{}], - "BlkioDeviceWriteIOps": [{}], - "MemorySwappiness": 60, - "OomKillDisable": false, - "OomScoreAdj": 500, - "PidMode": "", - "PidsLimit": -1, - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsOptions": [""], - "DnsSearch": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "GroupAdd": ["newgroup"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [], - "CgroupParent": "", - "VolumeDriver": "", - "ShmSize": 67108864 - }, - "NetworkingConfig": { - "EndpointsConfig": { - "isolated_nw" : { - "IPAMConfig": { - "IPv4Address":"172.20.30.33", - "IPv6Address":"2001:db8:abcd::3033" - }, - "Links":["container_1", "container_2"], - "Aliases":["server_x", "server_y"] - } - } - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id":"e90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **Hostname** - A string value containing the hostname to use for the - container. -- **Domainname** - A string value containing the domain name to use - for the container. -- **User** - A string value specifying the user inside the container. -- **AttachStdin** - Boolean value, attaches to `stdin`. -- **AttachStdout** - Boolean value, attaches to `stdout`. -- **AttachStderr** - Boolean value, attaches to `stderr`. -- **Tty** - Boolean value, Attach standard streams to a `tty`, including `stdin` if it is not closed. -- **OpenStdin** - Boolean value, opens `stdin`, -- **StdinOnce** - Boolean value, close `stdin` after the 1 attached client disconnects. -- **Env** - A list of environment variables in the form of `["VAR=value", ...]` -- **Labels** - Adds a map of labels to a container. To specify a map: `{"key":"value", ... }` -- **Cmd** - Command to run specified as a string or an array of strings. -- **Entrypoint** - Set the entry point for the container as a string or an array - of strings. -- **Image** - A string specifying the image name to use for the container. -- **Volumes** - An object mapping mount point paths (strings) inside the - container to empty objects. -- **WorkingDir** - A string specifying the working directory for commands to - run in. -- **NetworkDisabled** - Boolean value, when true disables networking for the - container -- **ExposedPorts** - An object mapping ports to an empty object in the form of: - `"ExposedPorts": { "/: {}" }` -- **StopSignal** - Signal to stop a container as a string or unsigned integer. `SIGTERM` by default. -- **HostConfig** - - **Binds** – A list of volume bindings for this container. Each volume binding is a string in one of these forms: - + `host-src:container-dest` to bind-mount a host path into the - container. Both `host-src`, and `container-dest` must be an - _absolute_ path. - + `host-src:container-dest:ro` to make the bind-mount read-only - inside the container. Both `host-src`, and `container-dest` must be - an _absolute_ path. - + `volume-name:container-dest` to bind-mount a volume managed by a - volume driver into the container. `container-dest` must be an - _absolute_ path. - + `volume-name:container-dest:ro` to mount the volume read-only - inside the container. `container-dest` must be an _absolute_ path. - - **Tmpfs** – A map of container directories which should be replaced by tmpfs mounts, and their corresponding - mount options. A JSON object in the form `{ "/run": "rw,noexec,nosuid,size=65536k" }`. - - **Links** - A list of links for the container. Each link entry should be - in the form of `container_name:alias`. - - **Memory** - Memory limit in bytes. - - **MemorySwap** - Total memory limit (memory + swap); set `-1` to enable unlimited swap. - You must use this with `memory` and make the swap value larger than `memory`. - - **MemoryReservation** - Memory soft limit in bytes. - - **KernelMemory** - Kernel memory limit in bytes. - - **CpuShares** - An integer value containing the container's CPU Shares - (ie. the relative weight vs other containers). - - **CpuPeriod** - The length of a CPU period in microseconds. - - **CpuQuota** - Microseconds of CPU time that the container can get in a CPU period. - - **CpusetCpus** - String value containing the `cgroups CpusetCpus` to use. - - **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. - - **BlkioWeight** - Block IO weight (relative weight) accepts a weight value between 10 and 1000. - - **BlkioWeightDevice** - Block IO weight (relative device weight) in the form of: `"BlkioWeightDevice": [{"Path": "device_path", "Weight": weight}]` - - **BlkioDeviceReadBps** - Limit read rate (bytes per second) from a device in the form of: `"BlkioDeviceReadBps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceReadBps": [{"Path": "/dev/sda", "Rate": "1024"}]"` - - **BlkioDeviceWriteBps** - Limit write rate (bytes per second) to a device in the form of: `"BlkioDeviceWriteBps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceWriteBps": [{"Path": "/dev/sda", "Rate": "1024"}]"` - - **BlkioDeviceReadIOps** - Limit read rate (IO per second) from a device in the form of: `"BlkioDeviceReadIOps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceReadIOps": [{"Path": "/dev/sda", "Rate": "1000"}]` - - **BlkioDeviceWiiteIOps** - Limit write rate (IO per second) to a device in the form of: `"BlkioDeviceWriteIOps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceWriteIOps": [{"Path": "/dev/sda", "Rate": "1000"}]` - - **MemorySwappiness** - Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. - - **OomKillDisable** - Boolean value, whether to disable OOM Killer for the container or not. - - **OomScoreAdj** - An integer value containing the score given to the container in order to tune OOM killer preferences. - - **PidMode** - Set the PID (Process) Namespace mode for the container; - `"container:"`: joins another container's PID namespace - `"host"`: use the host's PID namespace inside the container - - **PidsLimit** - Tune a container's pids limit. Set -1 for unlimited. - - **PortBindings** - A map of exposed container ports and the host port they - should map to. A JSON object in the form - `{ /: [{ "HostPort": "" }] }` - Take note that `port` is specified as a string and not an integer value. - - **PublishAllPorts** - Allocates a random host port for all of a container's - exposed ports. Specified as a boolean value. - - **Privileged** - Gives the container full access to the host. Specified as - a boolean value. - - **ReadonlyRootfs** - Mount the container's root filesystem as read only. - Specified as a boolean value. - - **Dns** - A list of DNS servers for the container to use. - - **DnsOptions** - A list of DNS options - - **DnsSearch** - A list of DNS search domains - - **ExtraHosts** - A list of hostnames/IP mappings to add to the - container's `/etc/hosts` file. Specified in the form `["hostname:IP"]`. - - **VolumesFrom** - A list of volumes to inherit from another container. - Specified in the form `[:]` - - **CapAdd** - A list of kernel capabilities to add to the container. - - **Capdrop** - A list of kernel capabilities to drop from the container. - - **GroupAdd** - A list of additional groups that the container process will run as - - **RestartPolicy** – The behavior to apply when the container exits. The - value is an object with a `Name` property of either `"always"` to - always restart, `"unless-stopped"` to restart always except when - user has manually stopped the container or `"on-failure"` to restart only when the container - exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` - controls the number of times to retry before giving up. - The default is not to restart. (optional) - An ever increasing delay (double the previous delay, starting at 100mS) - is added before each restart to prevent flooding the server. - - **UsernsMode** - Sets the usernamespace mode for the container when usernamespace remapping option is enabled. - supported values are: `host`. - - **NetworkMode** - Sets the networking mode for the container. Supported - standard values are: `bridge`, `host`, `none`, and `container:`. Any other value is taken - as a custom network's name to which this container should connect to. - - **Devices** - A list of devices to add to the container specified as a JSON object in the - form - `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` - - **Ulimits** - A list of ulimits to set in the container, specified as - `{ "Name": , "Soft": , "Hard": }`, for example: - `Ulimits: { "Name": "nofile", "Soft": 1024, "Hard": 2048 }` - - **SecurityOpt**: A list of string values to customize labels for MLS - systems, such as SELinux. - - **LogConfig** - Log configuration for the container, specified as a JSON object in the form - `{ "Type": "", "Config": {"key1": "val1"}}`. - Available types: `json-file`, `syslog`, `journald`, `gelf`, `fluentd`, `awslogs`, `splunk`, `etwlogs`, `none`. - `json-file` logging driver. - - **CgroupParent** - Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist. - - **VolumeDriver** - Driver that this container users to mount volumes. - - **ShmSize** - Size of `/dev/shm` in bytes. The size must be greater than 0. If omitted the system uses 64MB. - -**Query parameters**: - -- **name** – Assign the specified name to the container. Must - match `/?[a-zA-Z0-9_-]+`. - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such container -- **406** – impossible to attach (container not running) -- **409** – conflict -- **500** – server error - -#### Inspect a container - -`GET /containers/(id or name)/json` - -Return low-level information on the container `id` - -**Example request**: - - GET /v1.23/containers/4fa6e0f0c678/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "AppArmorProfile": "", - "Args": [ - "-c", - "exit 9" - ], - "Config": { - "AttachStderr": true, - "AttachStdin": false, - "AttachStdout": true, - "Cmd": [ - "/bin/sh", - "-c", - "exit 9" - ], - "Domainname": "", - "Entrypoint": null, - "Env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts": null, - "Hostname": "ba033ac44011", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "MacAddress": "", - "NetworkDisabled": false, - "OnBuild": null, - "OpenStdin": false, - "StdinOnce": false, - "Tty": false, - "User": "", - "Volumes": { - "/volumes/data": {} - }, - "WorkingDir": "", - "StopSignal": "SIGTERM" - }, - "Created": "2015-01-06T15:47:31.485331387Z", - "Driver": "devicemapper", - "ExecIDs": null, - "HostConfig": { - "Binds": null, - "BlkioWeight": 0, - "BlkioWeightDevice": [{}], - "BlkioDeviceReadBps": [{}], - "BlkioDeviceWriteBps": [{}], - "BlkioDeviceReadIOps": [{}], - "BlkioDeviceWriteIOps": [{}], - "CapAdd": null, - "CapDrop": null, - "ContainerIDFile": "", - "CpusetCpus": "", - "CpusetMems": "", - "CpuShares": 0, - "CpuPeriod": 100000, - "Devices": [], - "Dns": null, - "DnsOptions": null, - "DnsSearch": null, - "ExtraHosts": null, - "IpcMode": "", - "Links": null, - "LxcConf": [], - "Memory": 0, - "MemorySwap": 0, - "MemoryReservation": 0, - "KernelMemory": 0, - "OomKillDisable": false, - "OomScoreAdj": 500, - "NetworkMode": "bridge", - "PidMode": "", - "PortBindings": {}, - "Privileged": false, - "ReadonlyRootfs": false, - "PublishAllPorts": false, - "RestartPolicy": { - "MaximumRetryCount": 2, - "Name": "on-failure" - }, - "LogConfig": { - "Config": null, - "Type": "json-file" - }, - "SecurityOpt": null, - "VolumesFrom": null, - "Ulimits": [{}], - "VolumeDriver": "", - "ShmSize": 67108864 - }, - "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname", - "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39", - "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2", - "MountLabel": "", - "Name": "/boring_euclid", - "NetworkSettings": { - "Bridge": "", - "SandboxID": "", - "HairpinMode": false, - "LinkLocalIPv6Address": "", - "LinkLocalIPv6PrefixLen": 0, - "Ports": null, - "SandboxKey": "", - "SecondaryIPAddresses": null, - "SecondaryIPv6Addresses": null, - "EndpointID": "", - "Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "IPAddress": "", - "IPPrefixLen": 0, - "IPv6Gateway": "", - "MacAddress": "", - "Networks": { - "bridge": { - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.2", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:12:00:02" - } - } - }, - "Path": "/bin/sh", - "ProcessLabel": "", - "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf", - "RestartCount": 1, - "State": { - "Error": "", - "ExitCode": 9, - "FinishedAt": "2015-01-06T15:47:32.080254511Z", - "OOMKilled": false, - "Dead": false, - "Paused": false, - "Pid": 0, - "Restarting": false, - "Running": true, - "StartedAt": "2015-01-06T15:47:32.072697474Z", - "Status": "running" - }, - "Mounts": [ - { - "Name": "fac362...80535", - "Source": "/data", - "Destination": "/data", - "Driver": "local", - "Mode": "ro,Z", - "RW": false, - "Propagation": "" - } - ] - } - -**Example request, with size information**: - - GET /v1.23/containers/4fa6e0f0c678/json?size=1 HTTP/1.1 - -**Example response, with size information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - .... - "SizeRw": 0, - "SizeRootFs": 972, - .... - } - -**Query parameters**: - -- **size** – 1/True/true or 0/False/false, return container size information. Default is `false`. - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### List processes running inside a container - -`GET /containers/(id or name)/top` - -List processes running inside the container `id`. On Unix systems this -is done by running the `ps` command. This endpoint is not -supported on Windows. - -**Example request**: - - GET /v1.23/containers/4fa6e0f0c678/top HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD" - ], - "Processes" : [ - [ - "root", "13642", "882", "0", "17:03", "pts/0", "00:00:00", "/bin/bash" - ], - [ - "root", "13735", "13642", "0", "17:06", "pts/0", "00:00:00", "sleep 10" - ] - ] - } - -**Example request**: - - GET /v1.23/containers/4fa6e0f0c678/top?ps_args=aux HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND" - ] - "Processes" : [ - [ - "root","13642","0.0","0.1","18172","3184","pts/0","Ss","17:03","0:00","/bin/bash" - ], - [ - "root","13895","0.0","0.0","4348","692","pts/0","S+","17:15","0:00","sleep 10" - ] - ], - } - -**Query parameters**: - -- **ps_args** – `ps` arguments to use (e.g., `aux`), defaults to `-ef` - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container logs - -`GET /containers/(id or name)/logs` - -Get `stdout` and `stderr` logs from the container ``id`` - -> **Note**: -> This endpoint works only for containers with the `json-file` or `journald` logging drivers. - -**Example request**: - - GET /v1.23/containers/4fa6e0f0c678/logs?stderr=1&stdout=1×tamps=1&follow=1&tail=10&since=1428990821 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **follow** – 1/True/true or 0/False/false, return stream. Default `false`. -- **stdout** – 1/True/true or 0/False/false, show `stdout` log. Default `false`. -- **stderr** – 1/True/true or 0/False/false, show `stderr` log. Default `false`. -- **since** – UNIX timestamp (integer) to filter logs. Specifying a timestamp - will only output log-entries since that timestamp. Default: 0 (unfiltered) -- **timestamps** – 1/True/true or 0/False/false, print timestamps for - every log line. Default `false`. -- **tail** – Output specified number of lines at the end of logs: `all` or ``. Default all. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **404** – no such container -- **500** – server error - -#### Inspect changes on a container's filesystem - -`GET /containers/(id or name)/changes` - -Inspect changes on container `id`'s filesystem - -**Example request**: - - GET /v1.23/containers/4fa6e0f0c678/changes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Path": "/dev", - "Kind": 0 - }, - { - "Path": "/dev/kmsg", - "Kind": 1 - }, - { - "Path": "/test", - "Kind": 1 - } - ] - -Values for `Kind`: - -- `0`: Modify -- `1`: Add -- `2`: Delete - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Export a container - -`GET /containers/(id or name)/export` - -Export the contents of container `id` - -**Example request**: - - GET /v1.23/containers/4fa6e0f0c678/export HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/octet-stream - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container stats based on resource usage - -`GET /containers/(id or name)/stats` - -This endpoint returns a live stream of a container's resource usage statistics. - -**Example request**: - - GET /v1.23/containers/redis1/stats HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "read" : "2015-01-08T22:57:31.547920715Z", - "pids_stats": { - "current": 3 - }, - "networks": { - "eth0": { - "rx_bytes": 5338, - "rx_dropped": 0, - "rx_errors": 0, - "rx_packets": 36, - "tx_bytes": 648, - "tx_dropped": 0, - "tx_errors": 0, - "tx_packets": 8 - }, - "eth5": { - "rx_bytes": 4641, - "rx_dropped": 0, - "rx_errors": 0, - "rx_packets": 26, - "tx_bytes": 690, - "tx_dropped": 0, - "tx_errors": 0, - "tx_packets": 9 - } - }, - "memory_stats" : { - "stats" : { - "total_pgmajfault" : 0, - "cache" : 0, - "mapped_file" : 0, - "total_inactive_file" : 0, - "pgpgout" : 414, - "rss" : 6537216, - "total_mapped_file" : 0, - "writeback" : 0, - "unevictable" : 0, - "pgpgin" : 477, - "total_unevictable" : 0, - "pgmajfault" : 0, - "total_rss" : 6537216, - "total_rss_huge" : 6291456, - "total_writeback" : 0, - "total_inactive_anon" : 0, - "rss_huge" : 6291456, - "hierarchical_memory_limit" : 67108864, - "total_pgfault" : 964, - "total_active_file" : 0, - "active_anon" : 6537216, - "total_active_anon" : 6537216, - "total_pgpgout" : 414, - "total_cache" : 0, - "inactive_anon" : 0, - "active_file" : 0, - "pgfault" : 964, - "inactive_file" : 0, - "total_pgpgin" : 477 - }, - "max_usage" : 6651904, - "usage" : 6537216, - "failcnt" : 0, - "limit" : 67108864 - }, - "blkio_stats" : {}, - "cpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24472255, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100215355, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 739306590000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - }, - "precpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24350896, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100093996, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 9492140000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - } - } - -The precpu_stats is the cpu statistic of last read, which is used for calculating the cpu usage percent. It is not the exact copy of the “cpu_stats” field. - -**Query parameters**: - -- **stream** – 1/True/true or 0/False/false, pull stats once then disconnect. Default `true`. - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Resize a container TTY - -`POST /containers/(id or name)/resize` - -Resize the TTY for container with `id`. The unit is number of characters. You must restart the container for the resize to take effect. - -**Example request**: - - POST /v1.23/containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **200** – no error -- **404** – No such container -- **500** – Cannot resize container - -#### Start a container - -`POST /containers/(id or name)/start` - -Start the container `id` - -> **Note**: -> For backwards compatibility, this endpoint accepts a `HostConfig` as JSON-encoded request body. -> See [create a container](#create-a-container) for details. - -**Example request**: - - POST /v1.23/containers/e90e34656806/start HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **detachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. - -**Status codes**: - -- **204** – no error -- **304** – container already started -- **404** – no such container -- **500** – server error - -#### Stop a container - -`POST /containers/(id or name)/stop` - -Stop the container `id` - -**Example request**: - - POST /v1.23/containers/e90e34656806/stop?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **304** – container already stopped -- **404** – no such container -- **500** – server error - -#### Restart a container - -`POST /containers/(id or name)/restart` - -Restart the container `id` - -**Example request**: - - POST /v1.23/containers/e90e34656806/restart?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Kill a container - -`POST /containers/(id or name)/kill` - -Kill the container `id` - -**Example request**: - - POST /v1.23/containers/e90e34656806/kill HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **signal** - Signal to send to the container: integer or string like `SIGINT`. - When not set, `SIGKILL` is assumed and the call waits for the container to exit. - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Update a container - -`POST /containers/(id or name)/update` - -Update configuration of one or more containers. - -**Example request**: - - POST /v1.23/containers/e90e34656806/update HTTP/1.1 - Content-Type: application/json - - { - "BlkioWeight": 300, - "CpuShares": 512, - "CpuPeriod": 100000, - "CpuQuota": 50000, - "CpusetCpus": "0,1", - "CpusetMems": "0", - "Memory": 314572800, - "MemorySwap": 514288000, - "MemoryReservation": 209715200, - "KernelMemory": 52428800, - "RestartPolicy": { - "MaximumRetryCount": 4, - "Name": "on-failure" - }, - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Warnings": [] - } - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -#### Rename a container - -`POST /containers/(id or name)/rename` - -Rename the container `id` to a `new_name` - -**Example request**: - - POST /v1.23/containers/e90e34656806/rename?name=new_name HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **name** – new name for the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **409** - conflict name already assigned -- **500** – server error - -#### Pause a container - -`POST /containers/(id or name)/pause` - -Pause the container `id` - -**Example request**: - - POST /v1.23/containers/e90e34656806/pause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Unpause a container - -`POST /containers/(id or name)/unpause` - -Unpause the container `id` - -**Example request**: - - POST /v1.23/containers/e90e34656806/unpause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Attach to a container - -`POST /containers/(id or name)/attach` - -Attach to the container `id` - -**Example request**: - - POST /v1.23/containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **detachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **400** – bad parameter -- **404** – no such container -- **409** - container is paused -- **500** – server error - -**Stream details**: - -When using the TTY setting is enabled in -[`POST /containers/create` -](#create-a-container), -the stream is the raw data from the process PTY and client's `stdin`. -When the TTY is disabled, then the stream is multiplexed to separate -`stdout` and `stderr`. - -The format is a **Header** and a **Payload** (frame). - -**HEADER** - -The header contains the information which the stream writes (`stdout` or -`stderr`). It also contains the size of the associated frame encoded in the -last four bytes (`uint32`). - -It is encoded on the first eight bytes like this: - - header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} - -`STREAM_TYPE` can be: - -- 0: `stdin` (is written on `stdout`) -- 1: `stdout` -- 2: `stderr` - -`SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of -the `uint32` size encoded as big endian. - -**PAYLOAD** - -The payload is the raw stream. - -**IMPLEMENTATION** - -The simplest way to implement the Attach protocol is the following: - - 1. Read eight bytes. - 2. Choose `stdout` or `stderr` depending on the first byte. - 3. Extract the frame size from the last four bytes. - 4. Read the extracted size and output it on the correct output. - 5. Goto 1. - -#### Attach to a container (websocket) - -`GET /containers/(id or name)/attach/ws` - -Attach to the container `id` via websocket - -Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455) - -**Example request** - - GET /v1.23/containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 - -**Example response** - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **detachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -#### Wait a container - -`POST /containers/(id or name)/wait` - -Block until container `id` stops, then returns the exit code - -**Example request**: - - POST /v1.23/containers/16253994b7c4/wait HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"StatusCode": 0} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Remove a container - -`DELETE /containers/(id or name)` - -Remove the container `id` from the filesystem - -**Example request**: - - DELETE /v1.23/containers/16253994b7c4?v=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **v** – 1/True/true or 0/False/false, Remove the volumes - associated to the container. Default `false`. -- **force** - 1/True/true or 0/False/false, Kill then remove the container. - Default `false`. - -**Status codes**: - -- **204** – no error -- **400** – bad parameter -- **404** – no such container -- **409** – conflict -- **500** – server error - -#### Copy files or folders from a container - -`POST /containers/(id or name)/copy` - -Copy files or folders of container `id` - -**Deprecated** in favor of the `archive` endpoint below. - -**Example request**: - - POST /v1.23/containers/4fa6e0f0c678/copy HTTP/1.1 - Content-Type: application/json - - { - "Resource": "test.txt" - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Retrieving information about files and folders in a container - -`HEAD /containers/(id or name)/archive` - -See the description of the `X-Docker-Container-Path-Stat` header in the -following section. - -#### Get an archive of a filesystem resource in a container - -`GET /containers/(id or name)/archive` - -Get a tar archive of a resource in the filesystem of container `id`. - -**Query parameters**: - -- **path** - resource in the container's filesystem to archive. Required. - - If not an absolute path, it is relative to the container's root directory. - The resource specified by **path** must exist. To assert that the resource - is expected to be a directory, **path** should end in `/` or `/.` - (assuming a path separator of `/`). If **path** ends in `/.` then this - indicates that only the contents of the **path** directory should be - copied. A symlink is always resolved to its target. - - > **Note**: It is not possible to copy certain system files such as resources - > under `/proc`, `/sys`, `/dev`, and mounts created by the user in the - > container. - -**Example request**: - - GET /v1.23/containers/8cce319429b2/archive?path=/root HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - X-Docker-Container-Path-Stat: eyJuYW1lIjoicm9vdCIsInNpemUiOjQwOTYsIm1vZGUiOjIxNDc0ODQwOTYsIm10aW1lIjoiMjAxNC0wMi0yN1QyMDo1MToyM1oiLCJsaW5rVGFyZ2V0IjoiIn0= - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -On success, a response header `X-Docker-Container-Path-Stat` will be set to a -base64-encoded JSON object containing some filesystem header information about -the archived resource. The above example value would decode to the following -JSON object (whitespace added for readability): - -```json -{ - "name": "root", - "size": 4096, - "mode": 2147484096, - "mtime": "2014-02-27T20:51:23Z", - "linkTarget": "" -} -``` - -A `HEAD` request can also be made to this endpoint if only this information is -desired. - -**Status codes**: - -- **200** - success, returns archive of copied resource -- **400** - client error, bad parameter, details in JSON response body, one of: - - must specify path parameter (**path** cannot be empty) - - not a directory (**path** was asserted to be a directory but exists as a - file) -- **404** - client error, resource not found, one of: - – no such container (container `id` does not exist) - - no such file or directory (**path** does not exist) -- **500** - server error - -#### Extract an archive of files or folders to a directory in a container - -`PUT /containers/(id or name)/archive` - -Upload a tar archive to be extracted to a path in the filesystem of container -`id`. - -**Query parameters**: - -- **path** - path to a directory in the container - to extract the archive's contents into. Required. - - If not an absolute path, it is relative to the container's root directory. - The **path** resource must exist. -- **noOverwriteDirNonDir** - If "1", "true", or "True" then it will be an error - if unpacking the given content would cause an existing directory to be - replaced with a non-directory and vice versa. - -**Example request**: - - PUT /v1.23/containers/8cce319429b2/archive?path=/vol1 HTTP/1.1 - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – the content was extracted successfully -- **400** - client error, bad parameter, details in JSON response body, one of: - - must specify path parameter (**path** cannot be empty) - - not a directory (**path** should be a directory but exists as a file) - - unable to overwrite existing directory with non-directory - (if **noOverwriteDirNonDir**) - - unable to overwrite existing non-directory with directory - (if **noOverwriteDirNonDir**) -- **403** - client error, permission denied, the volume - or container rootfs is marked as read-only. -- **404** - client error, resource not found, one of: - – no such container (container `id` does not exist) - - no such file or directory (**path** resource does not exist) -- **500** – server error - -### 2.2 Images - -#### List Images - -`GET /images/json` - -**Example request**: - - GET /v1.23/images/json?all=0 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "RepoTags": [ - "ubuntu:12.04", - "ubuntu:precise", - "ubuntu:latest" - ], - "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", - "Created": 1365714795, - "Size": 131506275, - "VirtualSize": 131506275, - "Labels": {} - }, - { - "RepoTags": [ - "ubuntu:12.10", - "ubuntu:quantal" - ], - "ParentId": "27cf784147099545", - "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "Created": 1364102658, - "Size": 24653, - "VirtualSize": 180116135, - "Labels": { - "com.example.version": "v1" - } - } - ] - -**Example request, with digest information**: - - GET /v1.23/images/json?digests=1 HTTP/1.1 - -**Example response, with digest information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Created": 1420064636, - "Id": "4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125", - "ParentId": "ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2", - "RepoDigests": [ - "localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags": [ - "localhost:5000/test/busybox:latest", - "playdate:latest" - ], - "Size": 0, - "VirtualSize": 2429728, - "Labels": {} - } - ] - -The response shows a single image `Id` associated with two repositories -(`RepoTags`): `localhost:5000/test/busybox`: and `playdate`. A caller can use -either of the `RepoTags` values `localhost:5000/test/busybox:latest` or -`playdate:latest` to reference the image. - -You can also use `RepoDigests` values to reference an image. In this response, -the array has only one reference and that is to the -`localhost:5000/test/busybox` repository; the `playdate` repository has no -digest. You can reference this digest using the value: -`localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d...` - -See the `docker run` and `docker build` commands for examples of digest and tag -references on the command line. - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, default false -- **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: - - `dangling=true` - - `label=key` or `label="key=value"` of an image label -- **filter** - only return images with the specified name - -#### Build image from a Dockerfile - -`POST /build` - -Build an image from a Dockerfile - -**Example request**: - - POST /v1.23/build HTTP/1.1 - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"stream": "Step 1/5..."} - {"stream": "..."} - {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} - -The input stream must be a `tar` archive compressed with one of the -following algorithms: `identity` (no compression), `gzip`, `bzip2`, `xz`. - -The archive must include a build instructions file, typically called -`Dockerfile` at the archive's root. The `dockerfile` parameter may be -used to specify a different build instructions file. To do this, its value must be -the path to the alternate build instructions file to use. - -The archive may include any number of other files, -which are accessible in the build context (See the [*ADD build -command*](../reference/builder.md#add)). - -The Docker daemon performs a preliminary validation of the `Dockerfile` before -starting the build, and returns an error if the syntax is incorrect. After that, -each instruction is run one-by-one until the ID of the new image is output. - -The build is canceled if the client drops the connection by quitting -or being killed. - -**Query parameters**: - -- **dockerfile** - Path within the build context to the `Dockerfile`. This is - ignored if `remote` is specified and points to an external `Dockerfile`. -- **t** – A name and optional tag to apply to the image in the `name:tag` format. - If you omit the `tag` the default `latest` value is assumed. - You can provide one or more `t` parameters. -- **remote** – A Git repository URI or HTTP/HTTPS context URI. If the - URI points to a single text file, the file's contents are placed into - a file called `Dockerfile` and the image is built from that file. If - the URI points to a tarball, the file is downloaded by the daemon and - the contents therein used as the context for the build. If the URI - points to a tarball and the `dockerfile` parameter is also specified, - there must be a file with the corresponding path inside the tarball. -- **q** – Suppress verbose build output. -- **nocache** – Do not use the cache when building the image. -- **pull** - Attempt to pull the image even if an older image exists locally. -- **rm** - Remove intermediate containers after a successful build (default behavior). -- **forcerm** - Always remove intermediate containers (includes `rm`). -- **memory** - Set memory limit for build. -- **memswap** - Total memory (memory + swap), `-1` to enable unlimited swap. -- **cpushares** - CPU shares (relative weight). -- **cpusetcpus** - CPUs in which to allow execution (e.g., `0-3`, `0,1`). -- **cpuperiod** - The length of a CPU period in microseconds. -- **cpuquota** - Microseconds of CPU time that the container can get in a CPU period. -- **buildargs** – JSON map of string pairs for build-time variables. Users pass - these values at build-time. Docker uses the `buildargs` as the environment - context for command(s) run via the Dockerfile's `RUN` instruction or for - variable expansion in other Dockerfile instructions. This is not meant for - passing secret values. [Read more about the buildargs instruction](../reference/builder.md#arg) -- **shmsize** - Size of `/dev/shm` in bytes. The size must be greater than 0. If omitted the system uses 64MB. -- **labels** – JSON map of string pairs for labels to set on the image. - -**Request Headers**: - -- **Content-type** – Set to `"application/tar"`. -- **X-Registry-Config** – A base64-url-safe-encoded Registry Auth Config JSON - object with the following structure: - - { - "docker.example.com": { - "username": "janedoe", - "password": "hunter2" - }, - "https://index.docker.io/v1/": { - "username": "mobydock", - "password": "conta1n3rize14" - } - } - - This object maps the hostname of a registry to an object containing the - "username" and "password" for that registry. Multiple registries may - be specified as the build may be based on an image requiring - authentication to pull from any arbitrary registry. Only the registry - domain name (and port if not the default "443") are required. However - (for legacy reasons) the "official" Docker, Inc. hosted registry must - be specified with both a "https://" prefix and a "/v1/" suffix even - though Docker will prefer to use the v2 registry API. - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Create an image - -`POST /images/create` - -Create an image either by pulling it from the registry or by importing it - -**Example request**: - - POST /v1.23/images/create?fromImage=busybox&tag=latest HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pulling..."} - {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} - {"error": "Invalid..."} - ... - -When using this endpoint to pull an image from the registry, the -`X-Registry-Auth` header can be used to include -a base64-encoded AuthConfig object. - -**Query parameters**: - -- **fromImage** – Name of the image to pull. The name may include a tag or - digest. This parameter may only be used when pulling an image. - The pull is cancelled if the HTTP connection is closed. -- **fromSrc** – Source to import. The value may be a URL from which the image - can be retrieved or `-` to read the image from the request body. - This parameter may only be used when importing an image. -- **repo** – Repository name given to an image when it is imported. - The repo may include a tag. This parameter may only be used when importing - an image. -- **tag** – Tag or digest. If empty when pulling an image, this causes all tags - for the given image to be pulled. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object, containing either login information, or a token - - Credential based login: - - ``` - { - "username": "jdoe", - "password": "secret", - "email": "jdoe@acme.com" - } - ``` - - - Token based login: - - ``` - { - "identitytoken": "9cbaf023786cd7..." - } - ``` - -**Status codes**: - -- **200** – no error -- **404** - repository does not exist or no read access -- **500** – server error - - - -#### Inspect an image - -`GET /images/(name)/json` - -Return low-level information on the image `name` - -**Example request**: - - GET /v1.23/images/example/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Id" : "sha256:85f05633ddc1c50679be2b16a0479ab6f7637f8884e0cfe0f4d20e1ebb3d6e7c", - "Container" : "cb91e48a60d01f1e27028b4fc6819f4f290b3cf12496c8176ec714d0d390984a", - "Comment" : "", - "Os" : "linux", - "Architecture" : "amd64", - "Parent" : "sha256:91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "ContainerConfig" : { - "Tty" : false, - "Hostname" : "e611e15f9c9d", - "Volumes" : null, - "Domainname" : "", - "AttachStdout" : false, - "PublishService" : "", - "AttachStdin" : false, - "OpenStdin" : false, - "StdinOnce" : false, - "NetworkDisabled" : false, - "OnBuild" : [], - "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "User" : "", - "WorkingDir" : "", - "Entrypoint" : null, - "MacAddress" : "", - "AttachStderr" : false, - "Labels" : { - "com.example.license" : "GPL", - "com.example.version" : "1.0", - "com.example.vendor" : "Acme" - }, - "Env" : [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts" : null, - "Cmd" : [ - "/bin/sh", - "-c", - "#(nop) LABEL com.example.vendor=Acme com.example.license=GPL com.example.version=1.0" - ] - }, - "DockerVersion" : "1.9.0-dev", - "VirtualSize" : 188359297, - "Size" : 0, - "Author" : "", - "Created" : "2015-09-10T08:30:53.26995814Z", - "GraphDriver" : { - "Name" : "aufs", - "Data" : null - }, - "RepoDigests" : [ - "localhost:5000/test/busybox/example@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags" : [ - "example:1.0", - "example:latest", - "example:stable" - ], - "Config" : { - "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "NetworkDisabled" : false, - "OnBuild" : [], - "StdinOnce" : false, - "PublishService" : "", - "AttachStdin" : false, - "OpenStdin" : false, - "Domainname" : "", - "AttachStdout" : false, - "Tty" : false, - "Hostname" : "e611e15f9c9d", - "Volumes" : null, - "Cmd" : [ - "/bin/bash" - ], - "ExposedPorts" : null, - "Env" : [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "Labels" : { - "com.example.vendor" : "Acme", - "com.example.version" : "1.0", - "com.example.license" : "GPL" - }, - "Entrypoint" : null, - "MacAddress" : "", - "AttachStderr" : false, - "WorkingDir" : "", - "User" : "" - }, - "RootFS": { - "Type": "layers", - "Layers": [ - "sha256:1834950e52ce4d5a88a1bbd131c537f4d0e56d10ff0dd69e66be3b7dfa9df7e6", - "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef" - ] - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Get the history of an image - -`GET /images/(name)/history` - -Return the history of the image `name` - -**Example request**: - - GET /v1.23/images/ubuntu/history HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710", - "Created": 1398108230, - "CreatedBy": "/bin/sh -c #(nop) ADD file:eb15dbd63394e063b805a3c32ca7bf0266ef64676d5a6fab4801f2e81e2a5148 in /", - "Tags": [ - "ubuntu:lucid", - "ubuntu:10.04" - ], - "Size": 182964289, - "Comment": "" - }, - { - "Id": "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8", - "Created": 1398108222, - "CreatedBy": "/bin/sh -c #(nop) MAINTAINER Tianon Gravi - mkimage-debootstrap.sh -i iproute,iputils-ping,ubuntu-minimal -t lucid.tar.xz lucid http://archive.ubuntu.com/ubuntu/", - "Tags": null, - "Size": 0, - "Comment": "" - }, - { - "Id": "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158", - "Created": 1371157430, - "CreatedBy": "", - "Tags": [ - "scratch12:latest", - "scratch:latest" - ], - "Size": 0, - "Comment": "Imported from -" - } - ] - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Push an image on the registry - -`POST /images/(name)/push` - -Push the image `name` on the registry - -**Example request**: - - POST /v1.23/images/test/push HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pushing..."} - {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} - {"error": "Invalid..."} - ... - -If you wish to push an image on to a private registry, that image must already have a tag -into a repository which references that registry `hostname` and `port`. This repository name should -then be used in the URL. This duplicates the command line's flow. - -The push is cancelled if the HTTP connection is closed. - -**Example request**: - - POST /v1.23/images/registry.acme.com:5000/test/push HTTP/1.1 - - -**Query parameters**: - -- **tag** – The tag to associate with the image on the registry. This is optional. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object, containing either login information, or a token - - Credential based login: - - ``` - { - "username": "jdoe", - "password": "secret", - "email": "jdoe@acme.com", - } - ``` - - - Identity token based login: - - ``` - { - "identitytoken": "9cbaf023786cd7..." - } - ``` - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Tag an image into a repository - -`POST /images/(name)/tag` - -Tag the image `name` into a repository - -**Example request**: - - POST /v1.23/images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 - -**Example response**: - - HTTP/1.1 201 Created - -**Query parameters**: - -- **repo** – The repository to tag in -- **force** – 1/True/true or 0/False/false, default false -- **tag** - The new tag name - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Remove an image - -`DELETE /images/(name)` - -Remove the image `name` from the filesystem - -**Example request**: - - DELETE /v1.23/images/test HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-type: application/json - - [ - {"Untagged": "3e2f21a89f"}, - {"Deleted": "3e2f21a89f"}, - {"Deleted": "53b4f83ac9"} - ] - -**Query parameters**: - -- **force** – 1/True/true or 0/False/false, default false -- **noprune** – 1/True/true or 0/False/false, default false - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Search images - -`GET /images/search` - -Search for an image on [Docker Hub](https://hub.docker.com). - -> **Note**: -> The response keys have changed from API v1.6 to reflect the JSON -> sent by the registry server to the docker daemon's request. - -**Example request**: - - GET /v1.23/images/search?term=sshd HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "wma55/u1210sshd", - "star_count": 0 - }, - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "jdswinbank/sshd", - "star_count": 0 - }, - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "vgauthier/sshd", - "star_count": 0 - } - ... - ] - -**Query parameters**: - -- **term** – term to search - -**Status codes**: - -- **200** – no error -- **500** – server error - -### 2.3 Misc - -#### Check auth configuration - -`POST /auth` - -Validate credentials for a registry and get identity token, -if available, for accessing the registry without password. - -**Example request**: - - POST /v1.23/auth HTTP/1.1 - Content-Type: application/json - - { - "username": "hannibal", - "password": "xxxx", - "serveraddress": "https://index.docker.io/v1/" - } - -**Example response**: - - HTTP/1.1 200 OK - - { - "Status": "Login Succeeded", - "IdentityToken": "9cbaf023786cd7..." - } - -**Status codes**: - -- **200** – no error -- **204** – no error -- **500** – server error - -#### Display system-wide information - -`GET /info` - -Display system-wide information - -**Example request**: - - GET /v1.23/info HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Architecture": "x86_64", - "ClusterStore": "etcd://localhost:2379", - "CgroupDriver": "cgroupfs", - "Containers": 11, - "ContainersRunning": 7, - "ContainersStopped": 3, - "ContainersPaused": 1, - "CpuCfsPeriod": true, - "CpuCfsQuota": true, - "Debug": false, - "DockerRootDir": "/var/lib/docker", - "Driver": "btrfs", - "DriverStatus": [[""]], - "ExecutionDriver": "native-0.1", - "ExperimentalBuild": false, - "HttpProxy": "http://test:test@localhost:8080", - "HttpsProxy": "https://test:test@localhost:8080", - "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", - "IPv4Forwarding": true, - "Images": 16, - "IndexServerAddress": "https://index.docker.io/v1/", - "InitPath": "/usr/bin/docker", - "InitSha1": "", - "KernelMemory": true, - "KernelVersion": "3.12.0-1-amd64", - "Labels": [ - "storage=ssd" - ], - "MemTotal": 2099236864, - "MemoryLimit": true, - "NCPU": 1, - "NEventsListener": 0, - "NFd": 11, - "NGoroutines": 21, - "Name": "prod-server-42", - "NoProxy": "9.81.1.160", - "OomKillDisable": true, - "OSType": "linux", - "OperatingSystem": "Boot2Docker", - "Plugins": { - "Volume": [ - "local" - ], - "Network": [ - "null", - "host", - "bridge" - ] - }, - "RegistryConfig": { - "IndexConfigs": { - "docker.io": { - "Mirrors": null, - "Name": "docker.io", - "Official": true, - "Secure": true - } - }, - "InsecureRegistryCIDRs": [ - "127.0.0.0/8" - ] - }, - "ServerVersion": "1.9.0", - "SwapLimit": false, - "SystemStatus": [["State", "Healthy"]], - "SystemTime": "2015-03-10T11:11:23.730591467-07:00" - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Show the docker version information - -`GET /version` - -Show the docker version information - -**Example request**: - - GET /v1.23/version HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Version": "1.11.0", - "Os": "linux", - "KernelVersion": "3.19.0-23-generic", - "GoVersion": "go1.4.2", - "GitCommit": "e75da4b", - "Arch": "amd64", - "ApiVersion": "1.23", - "BuildTime": "2015-12-01T07:09:13.444803460+00:00", - "Experimental": true - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Ping the docker server - -`GET /_ping` - -Ping the docker server - -**Example request**: - - GET /v1.23/_ping HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: text/plain - - OK - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a new image from a container's changes - -`POST /commit` - -Create a new image from a container's changes - -**Example request**: - - POST /v1.23/commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Mounts": [ - { - "Source": "/data", - "Destination": "/data", - "Mode": "ro,Z", - "RW": false - } - ], - "Labels": { - "key1": "value1", - "key2": "value2" - }, - "WorkingDir": "", - "NetworkDisabled": false, - "ExposedPorts": { - "22/tcp": {} - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - {"Id": "596069db4bf5"} - -**JSON parameters**: - -- **config** - the container's configuration - -**Query parameters**: - -- **container** – source container -- **repo** – repository -- **tag** – tag -- **comment** – commit message -- **author** – author (e.g., "John Hannibal Smith - <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") -- **pause** – 1/True/true or 0/False/false, whether to pause the container before committing -- **changes** – Dockerfile instructions to apply while committing - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **500** – server error - -#### Monitor Docker's events - -`GET /events` - -Get container events from docker, in real time via streaming. - -Docker containers report the following events: - - attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update - -Docker images report the following events: - - delete, import, pull, push, tag, untag - -Docker volumes report the following events: - - create, mount, unmount, destroy - -Docker networks report the following events: - - create, connect, disconnect, destroy - -**Example request**: - - GET /v1.23/events?since=1374067924 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - Server: Docker/1.11.0 (linux) - Date: Fri, 29 Apr 2016 15:18:06 GMT - Transfer-Encoding: chunked - - { - "status": "pull", - "id": "alpine:latest", - "Type": "image", - "Action": "pull", - "Actor": { - "ID": "alpine:latest", - "Attributes": { - "name": "alpine" - } - }, - "time": 1461943101, - "timeNano": 1461943101301854122 - } - { - "status": "create", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "create", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943101, - "timeNano": 1461943101381709551 - } - { - "status": "attach", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "attach", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943101, - "timeNano": 1461943101383858412 - } - { - "Type": "network", - "Action": "connect", - "Actor": { - "ID": "7dc8ac97d5d29ef6c31b6052f3938c1e8f2749abbd17d1bd1febf2608db1b474", - "Attributes": { - "container": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "name": "bridge", - "type": "bridge" - } - }, - "time": 1461943101, - "timeNano": 1461943101394865557 - } - { - "status": "start", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "start", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943101, - "timeNano": 1461943101607533796 - } - { - "status": "resize", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "resize", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "height": "46", - "image": "alpine", - "name": "my-container", - "width": "204" - } - }, - "time": 1461943101, - "timeNano": 1461943101610269268 - } - { - "status": "die", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "die", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "exitCode": "0", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943105, - "timeNano": 1461943105079144137 - } - { - "Type": "network", - "Action": "disconnect", - "Actor": { - "ID": "7dc8ac97d5d29ef6c31b6052f3938c1e8f2749abbd17d1bd1febf2608db1b474", - "Attributes": { - "container": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "name": "bridge", - "type": "bridge" - } - }, - "time": 1461943105, - "timeNano": 1461943105230860245 - } - { - "status": "destroy", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "destroy", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943105, - "timeNano": 1461943105338056026 - } - -**Query parameters**: - -- **since** – Timestamp. Show all events created since timestamp and then stream -- **until** – Timestamp. Show events created until given timestamp and stop streaming -- **filters** – A json encoded value of the filters (a map[string][]string) to process on the event list. Available filters: - - `container=`; -- container to filter - - `event=`; -- event to filter - - `image=`; -- image to filter - - `label=`; -- image and container label to filter - - `type=`; -- either `container` or `image` or `volume` or `network` - - `volume=`; -- volume to filter - - `network=`; -- network to filter - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images in a repository - -`GET /images/(name)/get` - -Get a tarball containing all images and metadata for the repository specified -by `name`. - -If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image -(and its parents) are returned. If `name` is an image ID, similarly only that -image (and its parents) are returned, but with the exclusion of the -'repositories' file in the tarball, as there were no image names referenced. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.23/images/ubuntu/get - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images - -`GET /images/get` - -Get a tarball containing all images and metadata for one or more repositories. - -For each value of the `names` parameter: if it is a specific name and tag (e.g. -`ubuntu:latest`), then only that image (and its parents) are returned; if it is -an image ID, similarly only that image (and its parents) are returned and there -would be no names referenced in the 'repositories' file for this image ID. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.23/images/get?names=myname%2Fmyapp%3Alatest&names=busybox - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Load a tarball with a set of images and tags into docker - -`POST /images/load` - -Load a set of images and tags into a Docker repository. -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - POST /v1.23/images/load - Content-Type: application/x-tar - - Tarball in body - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - Transfer-Encoding: chunked - - {"status":"Loading layer","progressDetail":{"current":32768,"total":1292800},"progress":"[= ] 32.77 kB/1.293 MB","id":"8ac8bfaff55a"} - {"status":"Loading layer","progressDetail":{"current":65536,"total":1292800},"progress":"[== ] 65.54 kB/1.293 MB","id":"8ac8bfaff55a"} - {"status":"Loading layer","progressDetail":{"current":98304,"total":1292800},"progress":"[=== ] 98.3 kB/1.293 MB","id":"8ac8bfaff55a"} - {"status":"Loading layer","progressDetail":{"current":131072,"total":1292800},"progress":"[===== ] 131.1 kB/1.293 MB","id":"8ac8bfaff55a"} - ... - {"stream":"Loaded image: busybox:latest\n"} - -**Example response**: - -If the "quiet" query parameter is set to `true` / `1` (`?quiet=1`), progress -details are suppressed, and only a confirmation message is returned once the -action completes. - - HTTP/1.1 200 OK - Content-Type: application/json - Transfer-Encoding: chunked - - {"stream":"Loaded image: busybox:latest\n"} - -**Query parameters**: - -- **quiet** – Boolean value, suppress progress details during load. Defaults - to `0` / `false` if omitted. - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Image tarball format - -An image tarball contains one directory per image layer (named using its long ID), -each containing these files: - -- `VERSION`: currently `1.0` - the file format version -- `json`: detailed layer information, similar to `docker inspect layer_id` -- `layer.tar`: A tarfile containing the filesystem changes in this layer - -The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories -for storing attribute changes and deletions. - -If the tarball defines a repository, the tarball should also include a `repositories` file at -the root that contains a list of repository and tag names mapped to layer IDs. - -``` -{"hello-world": - {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} -} -``` - -#### Exec Create - -`POST /containers/(id or name)/exec` - -Sets up an exec instance in a running container `id` - -**Example request**: - - POST /v1.23/containers/e90e34656806/exec HTTP/1.1 - Content-Type: application/json - - { - "AttachStdin": true, - "AttachStdout": true, - "AttachStderr": true, - "Cmd": ["sh"], - "DetachKeys": "ctrl-p,ctrl-q", - "Privileged": true, - "Tty": true, - "User": "123:456" - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id": "f90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **AttachStdin** - Boolean value, attaches to `stdin` of the `exec` command. -- **AttachStdout** - Boolean value, attaches to `stdout` of the `exec` command. -- **AttachStderr** - Boolean value, attaches to `stderr` of the `exec` command. -- **DetachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. -- **Tty** - Boolean value to allocate a pseudo-TTY. -- **Cmd** - Command to run specified as a string or an array of strings. -- **Privileged** - Boolean value, runs the exec process with extended privileges. -- **User** - A string value specifying the user, and optionally, group to run - the exec process inside the container. Format is one of: `"user"`, - `"user:group"`, `"uid"`, or `"uid:gid"`. - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **409** - container is paused -- **500** - server error - -#### Exec Start - -`POST /exec/(id)/start` - -Starts a previously set up `exec` instance `id`. If `detach` is true, this API -returns after starting the `exec` command. Otherwise, this API sets up an -interactive session with the `exec` command. - -**Example request**: - - POST /v1.23/exec/e90e34656806/start HTTP/1.1 - Content-Type: application/json - - { - "Detach": false, - "Tty": false - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/vnd.docker.raw-stream - - {% raw %} - {{ STREAM }} - {% endraw %} - -**JSON parameters**: - -- **Detach** - Detach from the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **409** - container is paused - -**Stream details**: - -Similar to the stream behavior of `POST /containers/(id or name)/attach` API - -#### Exec Resize - -`POST /exec/(id)/resize` - -Resizes the `tty` session used by the `exec` command `id`. The unit is number of characters. -This API is valid only if `tty` was specified as part of creating and starting the `exec` command. - -**Example request**: - - POST /v1.23/exec/e90e34656806/resize?h=40&w=80 HTTP/1.1 - Content-Type: text/plain - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: text/plain - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **201** – no error -- **404** – no such exec instance - -#### Exec Inspect - -`GET /exec/(id)/json` - -Return low-level information about the `exec` command `id`. - -**Example request**: - - GET /v1.23/exec/11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "CanRemove": false, - "ContainerID": "b53ee82b53a40c7dca428523e34f741f3abc51d9f297a14ff874bf761b995126", - "DetachKeys": "", - "ExitCode": 2, - "ID": "f33bbfb39f5b142420f4759b2348913bd4a8d1a6d7fd56499cb41a1bb91d7b3b", - "OpenStderr": true, - "OpenStdin": true, - "OpenStdout": true, - "ProcessConfig": { - "arguments": [ - "-c", - "exit 2" - ], - "entrypoint": "sh", - "privileged": false, - "tty": true, - "user": "1000" - }, - "Running": false - } - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **500** - server error - -### 2.4 Volumes - -#### List volumes - -`GET /volumes` - -**Example request**: - - GET /v1.23/volumes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Volumes": [ - { - "Name": "tardis", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/tardis" - } - ], - "Warnings": [] - } - -**Query parameters**: - -- **filters** - JSON encoded value of the filters (a `map[string][]string`) to process on the volumes list. There is one available filter: `dangling=true` - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a volume - -`POST /volumes/create` - -Create a volume - -**Example request**: - - POST /v1.23/volumes/create HTTP/1.1 - Content-Type: application/json - - { - "Name": "tardis", - "Labels": { - "com.example.some-label": "some-value", - "com.example.some-other-label": "some-other-value" - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Name": "tardis", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/tardis", - "Labels": { - "com.example.some-label": "some-value", - "com.example.some-other-label": "some-other-value" - } - } - -**Status codes**: - -- **201** - no error -- **500** - server error - -**JSON parameters**: - -- **Name** - The new volume's name. If not specified, Docker generates a name. -- **Driver** - Name of the volume driver to use. Defaults to `local` for the name. -- **DriverOpts** - A mapping of driver options and values. These options are - passed directly to the driver and are driver specific. -- **Labels** - Labels to set on the volume, specified as a map: `{"key":"value","key2":"value2"}` - -#### Inspect a volume - -`GET /volumes/(name)` - -Return low-level information on the volume `name` - -**Example request**: - - GET /v1.23/volumes/tardis - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Name": "tardis", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/tardis/_data", - "Labels": { - "com.example.some-label": "some-value", - "com.example.some-other-label": "some-other-value" - } - } - -**Status codes**: - -- **200** - no error -- **404** - no such volume -- **500** - server error - -#### Remove a volume - -`DELETE /volumes/(name)` - -Instruct the driver to remove the volume (`name`). - -**Example request**: - - DELETE /v1.23/volumes/tardis HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** - no error -- **404** - no such volume or volume driver -- **409** - volume is in use and cannot be removed -- **500** - server error - -### 3.5 Networks - -#### List networks - -`GET /networks` - -**Example request**: - - GET /v1.23/networks?filters={"type":{"custom":true}} HTTP/1.1 - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json - -[ - { - "Name": "bridge", - "Id": "f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566", - "Scope": "local", - "Driver": "bridge", - "EnableIPv6": false, - "Internal": false, - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.17.0.0/16" - } - ] - }, - "Containers": { - "39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": { - "EndpointID": "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda", - "MacAddress": "02:42:ac:11:00:02", - "IPv4Address": "172.17.0.2/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - } - }, - { - "Name": "none", - "Id": "e086a3893b05ab69242d3c44e49483a3bbbd3a26b46baa8f61ab797c1088d794", - "Scope": "local", - "Driver": "null", - "EnableIPv6": false, - "Internal": false, - "IPAM": { - "Driver": "default", - "Config": [] - }, - "Containers": {}, - "Options": {} - }, - { - "Name": "host", - "Id": "13e871235c677f196c4e1ecebb9dc733b9b2d2ab589e30c539efeda84a24215e", - "Scope": "local", - "Driver": "host", - "EnableIPv6": false, - "Internal": false, - "IPAM": { - "Driver": "default", - "Config": [] - }, - "Containers": {}, - "Options": {} - } -] -``` - -**Query parameters**: - -- **filters** - JSON encoded network list filter. The filter value is one of: - - `id=` Matches all or part of a network id. - - `name=` Matches all or part of a network name. - - `type=["custom"|"builtin"]` Filters networks by type. The `custom` keyword returns all user-defined networks. - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Inspect network - -`GET /networks/` - -**Example request**: - - GET /v1.23/networks/7d86d31b1478e7cca9ebed7e73aa0fdeec46c5ca29497431d3007d2d9e15ed99 HTTP/1.1 - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json - -{ - "Name": "net01", - "Id": "7d86d31b1478e7cca9ebed7e73aa0fdeec46c5ca29497431d3007d2d9e15ed99", - "Scope": "local", - "Driver": "bridge", - "EnableIPv6": false, - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.19.0.0/16", - "Gateway": "172.19.0.1/16" - } - ], - "Options": { - "foo": "bar" - } - }, - "Internal": false, - "Containers": { - "19a4d5d687db25203351ed79d478946f861258f018fe384f229f2efa4b23513c": { - "Name": "test", - "EndpointID": "628cadb8bcb92de107b2a1e516cbffe463e321f548feb37697cce00ad694f21a", - "MacAddress": "02:42:ac:13:00:02", - "IPv4Address": "172.19.0.2/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - }, - "Labels": { - "com.example.some-label": "some-value", - "com.example.some-other-label": "some-other-value" - } -} -``` - -**Status codes**: - -- **200** - no error -- **404** - network not found - -#### Create a network - -`POST /networks/create` - -Create a network - -**Example request**: - -``` -POST /v1.23/networks/create HTTP/1.1 -Content-Type: application/json - -{ - "Name":"isolated_nw", - "CheckDuplicate":true, - "Driver":"bridge", - "EnableIPv6": true, - "IPAM":{ - "Driver": "default", - "Config":[ - { - "Subnet":"172.20.0.0/16", - "IPRange":"172.20.10.0/24", - "Gateway":"172.20.10.11" - }, - { - "Subnet":"2001:db8:abcd::/64", - "Gateway":"2001:db8:abcd::1011" - } - ], - "Options": { - "foo": "bar" - } - }, - "Internal":true, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - }, - "Labels": { - "com.example.some-label": "some-value", - "com.example.some-other-label": "some-other-value" - } -} -``` - -**Example response**: - -``` -HTTP/1.1 201 Created -Content-Type: application/json - -{ - "Id": "22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30", - "Warning": "" -} -``` - -**Status codes**: - -- **201** - no error -- **404** - plugin not found -- **500** - server error - -**JSON parameters**: - -- **Name** - The new network's name. this is a mandatory field -- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false` -- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver -- **Internal** - Restrict external access to the network -- **IPAM** - Optional custom IP scheme for the network - - **Driver** - Name of the IPAM driver to use. Defaults to `default` driver - - **Config** - List of IPAM configuration options, specified as a map: - `{"Subnet": , "IPRange": , "Gateway": , "AuxAddress": }` - - **Options** - Driver-specific options, specified as a map: `{"option":"value" [,"option2":"value2"]}` -- **EnableIPv6** - Enable IPv6 on the network -- **Options** - Network specific options to be used by the drivers -- **Labels** - Labels to set on the network, specified as a map: `{"key":"value" [,"key2":"value2"]}` - -#### Connect a container to a network - -`POST /networks/(id)/connect` - -Connect a container to a network - -**Example request**: - -``` -POST /v1.23/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30/connect HTTP/1.1 -Content-Type: application/json - -{ - "Container":"3613f73ba0e4", - "EndpointConfig": { - "IPAMConfig": { - "IPv4Address":"172.24.56.89", - "IPv6Address":"2001:db8::5689" - } - } -} -``` - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** - no error -- **404** - network or container is not found -- **500** - Internal Server Error - -**JSON parameters**: - -- **container** - container-id/name to be connected to the network - -#### Disconnect a container from a network - -`POST /networks/(id)/disconnect` - -Disconnect a container from a network - -**Example request**: - -``` -POST /v1.23/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30/disconnect HTTP/1.1 -Content-Type: application/json - -{ - "Container":"3613f73ba0e4", - "Force":false -} -``` - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** - no error -- **404** - network or container not found -- **500** - Internal Server Error - -**JSON parameters**: - -- **Container** - container-id/name to be disconnected from a network -- **Force** - Force the container to disconnect from a network - -#### Remove a network - -`DELETE /networks/(id)` - -Instruct the driver to remove the network (`id`). - -**Example request**: - - DELETE /v1.23/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** - no error -- **404** - no such network -- **500** - server error - -## 3. Going further - -### 3.1 Inside `docker run` - -As an example, the `docker run` command line makes the following API calls: - -- Create the container - -- If the status code is 404, it means the image doesn't exist: - - Try to pull it. - - Then, retry to create the container. - -- Start the container. - -- If you are not in detached mode: -- Attach to the container, using `logs=1` (to have `stdout` and - `stderr` from the container's start) and `stream=1` - -- If in detached mode or only `stdin` is attached, display the container's id. - -### 3.2 Hijacking - -In this version of the API, `/attach`, uses hijacking to transport `stdin`, -`stdout`, and `stderr` on the same socket. - -To hint potential proxies about connection hijacking, Docker client sends -connection upgrade headers similarly to websocket. - - Upgrade: tcp - Connection: Upgrade - -When Docker daemon detects the `Upgrade` header, it switches its status code -from **200 OK** to **101 UPGRADED** and resends the same headers. - - -### 3.3 CORS Requests - -To set cross origin requests to the Engine API please give values to -`--api-cors-header` when running Docker in daemon mode. Set * (asterisk) allows all, -default or blank means CORS disabled - - $ dockerd -H="192.168.1.9:2375" --api-cors-header="http://foo.bar" diff --git a/vendor/github.com/docker/docker/docs/api/v1.24.md b/vendor/github.com/docker/docker/docs/api/v1.24.md deleted file mode 100644 index 0cf4e2a..0000000 --- a/vendor/github.com/docker/docker/docs/api/v1.24.md +++ /dev/null @@ -1,5316 +0,0 @@ ---- -title: "Engine API v1.24" -description: "API Documentation for Docker" -keywords: "API, Docker, rcli, REST, documentation" -redirect_from: -- /engine/reference/api/docker_remote_api_v1.24/ -- /reference/api/docker_remote_api_v1.24/ ---- - - - -## 1. Brief introduction - - - The daemon listens on `unix:///var/run/docker.sock` but you can - [Bind Docker to another host/port or a Unix socket](../reference/commandline/dockerd.md#bind-docker-to-another-host-port-or-a-unix-socket). - - The API tends to be REST. However, for some complex commands, like `attach` - or `pull`, the HTTP connection is hijacked to transport `stdout`, - `stdin` and `stderr`. - -## 2. Errors - -The Engine API uses standard HTTP status codes to indicate the success or failure of the API call. The body of the response will be JSON in the following format: - - { - "message": "page not found" - } - -The status codes that are returned for each endpoint are specified in the endpoint documentation below. - -## 3. Endpoints - -### 3.1 Containers - -#### List containers - -`GET /containers/json` - -List containers - -**Example request**: - - GET /v1.24/containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "8dfafdbc3a40", - "Names":["/boring_feynman"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 1", - "Created": 1367854155, - "State": "Exited", - "Status": "Exit 0", - "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}], - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "SizeRw": 12288, - "SizeRootFs": 0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "2cdc4edb1ded3631c81f57966563e5c8525b81121bb3706a9a9a3ae102711f3f", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.2", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:02" - } - } - }, - "Mounts": [ - { - "Name": "fac362...80535", - "Source": "/data", - "Destination": "/data", - "Driver": "local", - "Mode": "ro,Z", - "RW": false, - "Propagation": "" - } - ] - }, - { - "Id": "9cd87474be90", - "Names":["/coolName"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 222222", - "Created": 1367854155, - "State": "Exited", - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "88eaed7b37b38c2a3f0c4bc796494fdf51b270c2d22656412a2ca5d559a64d7a", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.8", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:08" - } - } - }, - "Mounts": [] - }, - { - "Id": "3176a2479c92", - "Names":["/sleepy_dog"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 3333333333333333", - "Created": 1367854154, - "State": "Exited", - "Status": "Exit 0", - "Ports":[], - "Labels": {}, - "SizeRw":12288, - "SizeRootFs":0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "8b27c041c30326d59cd6e6f510d4f8d1d570a228466f956edf7815508f78e30d", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.6", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:06" - } - } - }, - "Mounts": [] - }, - { - "Id": "4cb07b47f9fb", - "Names":["/running_cat"], - "Image": "ubuntu:latest", - "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", - "Command": "echo 444444444444444444444444444444444", - "Created": 1367854152, - "State": "Exited", - "Status": "Exit 0", - "Ports": [], - "Labels": {}, - "SizeRw": 12288, - "SizeRootFs": 0, - "HostConfig": { - "NetworkMode": "default" - }, - "NetworkSettings": { - "Networks": { - "bridge": { - "IPAMConfig": null, - "Links": null, - "Aliases": null, - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "d91c7b2f0644403d7ef3095985ea0e2370325cd2332ff3a3225c4247328e66e9", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.5", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:11:00:05" - } - } - }, - "Mounts": [] - } - ] - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, Show all containers. - Only running containers are shown by default (i.e., this defaults to false) -- **limit** – Show `limit` last created - containers, include non-running ones. -- **since** – Show only containers created since Id, include - non-running ones. -- **before** – Show only containers created before Id, include - non-running ones. -- **size** – 1/True/true or 0/False/false, Show the containers - sizes -- **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: - - `exited=`; -- containers with exit code of `` ; - - `status=`(`created`|`restarting`|`running`|`paused`|`exited`|`dead`) - - `label=key` or `label="key=value"` of a container label - - `isolation=`(`default`|`process`|`hyperv`) (Windows daemon only) - - `ancestor`=(`[:]`, `` or ``) - - `before`=(`` or ``) - - `since`=(`` or ``) - - `volume`=(`` or ``) - - `network`=(`` or ``) - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **500** – server error - -#### Create a container - -`POST /containers/create` - -Create a container - -**Example request**: - - POST /v1.24/containers/create HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": [ - "FOO=bar", - "BAZ=quux" - ], - "Cmd": [ - "date" - ], - "Entrypoint": "", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "/volumes/data": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "StopSignal": "SIGTERM", - "HostConfig": { - "Binds": ["/tmp:/tmp"], - "Tmpfs": { "/run": "rw,noexec,nosuid,size=65536k" }, - "Links": ["redis3:redis"], - "Memory": 0, - "MemorySwap": 0, - "MemoryReservation": 0, - "KernelMemory": 0, - "CpuPercent": 80, - "CpuShares": 512, - "CpuPeriod": 100000, - "CpuQuota": 50000, - "CpusetCpus": "0,1", - "CpusetMems": "0,1", - "IOMaximumBandwidth": 0, - "IOMaximumIOps": 0, - "BlkioWeight": 300, - "BlkioWeightDevice": [{}], - "BlkioDeviceReadBps": [{}], - "BlkioDeviceReadIOps": [{}], - "BlkioDeviceWriteBps": [{}], - "BlkioDeviceWriteIOps": [{}], - "MemorySwappiness": 60, - "OomKillDisable": false, - "OomScoreAdj": 500, - "PidMode": "", - "PidsLimit": -1, - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsOptions": [""], - "DnsSearch": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "GroupAdd": ["newgroup"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [], - "Sysctls": { "net.ipv4.ip_forward": "1" }, - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [], - "StorageOpt": {}, - "CgroupParent": "", - "VolumeDriver": "", - "ShmSize": 67108864 - }, - "NetworkingConfig": { - "EndpointsConfig": { - "isolated_nw" : { - "IPAMConfig": { - "IPv4Address":"172.20.30.33", - "IPv6Address":"2001:db8:abcd::3033", - "LinkLocalIPs":["169.254.34.68", "fe80::3468"] - }, - "Links":["container_1", "container_2"], - "Aliases":["server_x", "server_y"] - } - } - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id":"e90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **Hostname** - A string value containing the hostname to use for the - container. This must be a valid RFC 1123 hostname. -- **Domainname** - A string value containing the domain name to use - for the container. -- **User** - A string value specifying the user inside the container. -- **AttachStdin** - Boolean value, attaches to `stdin`. -- **AttachStdout** - Boolean value, attaches to `stdout`. -- **AttachStderr** - Boolean value, attaches to `stderr`. -- **Tty** - Boolean value, Attach standard streams to a `tty`, including `stdin` if it is not closed. -- **OpenStdin** - Boolean value, opens `stdin`, -- **StdinOnce** - Boolean value, close `stdin` after the 1 attached client disconnects. -- **Env** - A list of environment variables in the form of `["VAR=value", ...]` -- **Labels** - Adds a map of labels to a container. To specify a map: `{"key":"value", ... }` -- **Cmd** - Command to run specified as a string or an array of strings. -- **Entrypoint** - Set the entry point for the container as a string or an array - of strings. -- **Image** - A string specifying the image name to use for the container. -- **Volumes** - An object mapping mount point paths (strings) inside the - container to empty objects. -- **WorkingDir** - A string specifying the working directory for commands to - run in. -- **NetworkDisabled** - Boolean value, when true disables networking for the - container -- **ExposedPorts** - An object mapping ports to an empty object in the form of: - `"ExposedPorts": { "/: {}" }` -- **StopSignal** - Signal to stop a container as a string or unsigned integer. `SIGTERM` by default. -- **HostConfig** - - **Binds** – A list of volume bindings for this container. Each volume binding is a string in one of these forms: - + `host-src:container-dest` to bind-mount a host path into the - container. Both `host-src`, and `container-dest` must be an - _absolute_ path. - + `host-src:container-dest:ro` to make the bind-mount read-only - inside the container. Both `host-src`, and `container-dest` must be - an _absolute_ path. - + `volume-name:container-dest` to bind-mount a volume managed by a - volume driver into the container. `container-dest` must be an - _absolute_ path. - + `volume-name:container-dest:ro` to mount the volume read-only - inside the container. `container-dest` must be an _absolute_ path. - - **Tmpfs** – A map of container directories which should be replaced by tmpfs mounts, and their corresponding - mount options. A JSON object in the form `{ "/run": "rw,noexec,nosuid,size=65536k" }`. - - **Links** - A list of links for the container. Each link entry should be - in the form of `container_name:alias`. - - **Memory** - Memory limit in bytes. - - **MemorySwap** - Total memory limit (memory + swap); set `-1` to enable unlimited swap. - You must use this with `memory` and make the swap value larger than `memory`. - - **MemoryReservation** - Memory soft limit in bytes. - - **KernelMemory** - Kernel memory limit in bytes. - - **CpuPercent** - An integer value containing the usable percentage of the available CPUs. (Windows daemon only) - - **CpuShares** - An integer value containing the container's CPU Shares - (ie. the relative weight vs other containers). - - **CpuPeriod** - The length of a CPU period in microseconds. - - **CpuQuota** - Microseconds of CPU time that the container can get in a CPU period. - - **CpusetCpus** - String value containing the `cgroups CpusetCpus` to use. - - **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. - - **IOMaximumBandwidth** - Maximum IO absolute rate in terms of IOps. - - **IOMaximumIOps** - Maximum IO absolute rate in terms of bytes per second. - - **BlkioWeight** - Block IO weight (relative weight) accepts a weight value between 10 and 1000. - - **BlkioWeightDevice** - Block IO weight (relative device weight) in the form of: `"BlkioWeightDevice": [{"Path": "device_path", "Weight": weight}]` - - **BlkioDeviceReadBps** - Limit read rate (bytes per second) from a device in the form of: `"BlkioDeviceReadBps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceReadBps": [{"Path": "/dev/sda", "Rate": "1024"}]"` - - **BlkioDeviceWriteBps** - Limit write rate (bytes per second) to a device in the form of: `"BlkioDeviceWriteBps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceWriteBps": [{"Path": "/dev/sda", "Rate": "1024"}]"` - - **BlkioDeviceReadIOps** - Limit read rate (IO per second) from a device in the form of: `"BlkioDeviceReadIOps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceReadIOps": [{"Path": "/dev/sda", "Rate": "1000"}]` - - **BlkioDeviceWiiteIOps** - Limit write rate (IO per second) to a device in the form of: `"BlkioDeviceWriteIOps": [{"Path": "device_path", "Rate": rate}]`, for example: - `"BlkioDeviceWriteIOps": [{"Path": "/dev/sda", "Rate": "1000"}]` - - **MemorySwappiness** - Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. - - **OomKillDisable** - Boolean value, whether to disable OOM Killer for the container or not. - - **OomScoreAdj** - An integer value containing the score given to the container in order to tune OOM killer preferences. - - **PidMode** - Set the PID (Process) Namespace mode for the container; - `"container:"`: joins another container's PID namespace - `"host"`: use the host's PID namespace inside the container - - **PidsLimit** - Tune a container's pids limit. Set -1 for unlimited. - - **PortBindings** - A map of exposed container ports and the host port they - should map to. A JSON object in the form - `{ /: [{ "HostPort": "" }] }` - Take note that `port` is specified as a string and not an integer value. - - **PublishAllPorts** - Allocates a random host port for all of a container's - exposed ports. Specified as a boolean value. - - **Privileged** - Gives the container full access to the host. Specified as - a boolean value. - - **ReadonlyRootfs** - Mount the container's root filesystem as read only. - Specified as a boolean value. - - **Dns** - A list of DNS servers for the container to use. - - **DnsOptions** - A list of DNS options - - **DnsSearch** - A list of DNS search domains - - **ExtraHosts** - A list of hostnames/IP mappings to add to the - container's `/etc/hosts` file. Specified in the form `["hostname:IP"]`. - - **VolumesFrom** - A list of volumes to inherit from another container. - Specified in the form `[:]` - - **CapAdd** - A list of kernel capabilities to add to the container. - - **Capdrop** - A list of kernel capabilities to drop from the container. - - **GroupAdd** - A list of additional groups that the container process will run as - - **RestartPolicy** – The behavior to apply when the container exits. The - value is an object with a `Name` property of either `"always"` to - always restart, `"unless-stopped"` to restart always except when - user has manually stopped the container or `"on-failure"` to restart only when the container - exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` - controls the number of times to retry before giving up. - The default is not to restart. (optional) - An ever increasing delay (double the previous delay, starting at 100mS) - is added before each restart to prevent flooding the server. - - **UsernsMode** - Sets the usernamespace mode for the container when usernamespace remapping option is enabled. - supported values are: `host`. - - **NetworkMode** - Sets the networking mode for the container. Supported - standard values are: `bridge`, `host`, `none`, and `container:`. Any other value is taken - as a custom network's name to which this container should connect to. - - **Devices** - A list of devices to add to the container specified as a JSON object in the - form - `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` - - **Ulimits** - A list of ulimits to set in the container, specified as - `{ "Name": , "Soft": , "Hard": }`, for example: - `Ulimits: { "Name": "nofile", "Soft": 1024, "Hard": 2048 }` - - **Sysctls** - A list of kernel parameters (sysctls) to set in the container, specified as - `{ : }`, for example: - `{ "net.ipv4.ip_forward": "1" }` - - **SecurityOpt**: A list of string values to customize labels for MLS - systems, such as SELinux. - - **StorageOpt**: Storage driver options per container. Options can be passed in the form - `{"size":"120G"}` - - **LogConfig** - Log configuration for the container, specified as a JSON object in the form - `{ "Type": "", "Config": {"key1": "val1"}}`. - Available types: `json-file`, `syslog`, `journald`, `gelf`, `fluentd`, `awslogs`, `splunk`, `etwlogs`, `none`. - `json-file` logging driver. - - **CgroupParent** - Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist. - - **VolumeDriver** - Driver that this container users to mount volumes. - - **ShmSize** - Size of `/dev/shm` in bytes. The size must be greater than 0. If omitted the system uses 64MB. - -**Query parameters**: - -- **name** – Assign the specified name to the container. Must - match `/?[a-zA-Z0-9_-]+`. - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such container -- **406** – impossible to attach (container not running) -- **409** – conflict -- **500** – server error - -#### Inspect a container - -`GET /containers/(id or name)/json` - -Return low-level information on the container `id` - -**Example request**: - - GET /v1.24/containers/4fa6e0f0c678/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "AppArmorProfile": "", - "Args": [ - "-c", - "exit 9" - ], - "Config": { - "AttachStderr": true, - "AttachStdin": false, - "AttachStdout": true, - "Cmd": [ - "/bin/sh", - "-c", - "exit 9" - ], - "Domainname": "", - "Entrypoint": null, - "Env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts": null, - "Hostname": "ba033ac44011", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "MacAddress": "", - "NetworkDisabled": false, - "OnBuild": null, - "OpenStdin": false, - "StdinOnce": false, - "Tty": false, - "User": "", - "Volumes": { - "/volumes/data": {} - }, - "WorkingDir": "", - "StopSignal": "SIGTERM" - }, - "Created": "2015-01-06T15:47:31.485331387Z", - "Driver": "devicemapper", - "ExecIDs": null, - "HostConfig": { - "Binds": null, - "IOMaximumBandwidth": 0, - "IOMaximumIOps": 0, - "BlkioWeight": 0, - "BlkioWeightDevice": [{}], - "BlkioDeviceReadBps": [{}], - "BlkioDeviceWriteBps": [{}], - "BlkioDeviceReadIOps": [{}], - "BlkioDeviceWriteIOps": [{}], - "CapAdd": null, - "CapDrop": null, - "ContainerIDFile": "", - "CpusetCpus": "", - "CpusetMems": "", - "CpuPercent": 80, - "CpuShares": 0, - "CpuPeriod": 100000, - "Devices": [], - "Dns": null, - "DnsOptions": null, - "DnsSearch": null, - "ExtraHosts": null, - "IpcMode": "", - "Links": null, - "LxcConf": [], - "Memory": 0, - "MemorySwap": 0, - "MemoryReservation": 0, - "KernelMemory": 0, - "OomKillDisable": false, - "OomScoreAdj": 500, - "NetworkMode": "bridge", - "PidMode": "", - "PortBindings": {}, - "Privileged": false, - "ReadonlyRootfs": false, - "PublishAllPorts": false, - "RestartPolicy": { - "MaximumRetryCount": 2, - "Name": "on-failure" - }, - "LogConfig": { - "Config": null, - "Type": "json-file" - }, - "SecurityOpt": null, - "Sysctls": { - "net.ipv4.ip_forward": "1" - }, - "StorageOpt": null, - "VolumesFrom": null, - "Ulimits": [{}], - "VolumeDriver": "", - "ShmSize": 67108864 - }, - "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname", - "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts", - "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", - "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39", - "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2", - "MountLabel": "", - "Name": "/boring_euclid", - "NetworkSettings": { - "Bridge": "", - "SandboxID": "", - "HairpinMode": false, - "LinkLocalIPv6Address": "", - "LinkLocalIPv6PrefixLen": 0, - "Ports": null, - "SandboxKey": "", - "SecondaryIPAddresses": null, - "SecondaryIPv6Addresses": null, - "EndpointID": "", - "Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "IPAddress": "", - "IPPrefixLen": 0, - "IPv6Gateway": "", - "MacAddress": "", - "Networks": { - "bridge": { - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.2", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:12:00:02" - } - } - }, - "Path": "/bin/sh", - "ProcessLabel": "", - "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf", - "RestartCount": 1, - "State": { - "Error": "", - "ExitCode": 9, - "FinishedAt": "2015-01-06T15:47:32.080254511Z", - "OOMKilled": false, - "Dead": false, - "Paused": false, - "Pid": 0, - "Restarting": false, - "Running": true, - "StartedAt": "2015-01-06T15:47:32.072697474Z", - "Status": "running" - }, - "Mounts": [ - { - "Name": "fac362...80535", - "Source": "/data", - "Destination": "/data", - "Driver": "local", - "Mode": "ro,Z", - "RW": false, - "Propagation": "" - } - ] - } - -**Example request, with size information**: - - GET /v1.24/containers/4fa6e0f0c678/json?size=1 HTTP/1.1 - -**Example response, with size information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - .... - "SizeRw": 0, - "SizeRootFs": 972, - .... - } - -**Query parameters**: - -- **size** – 1/True/true or 0/False/false, return container size information. Default is `false`. - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### List processes running inside a container - -`GET /containers/(id or name)/top` - -List processes running inside the container `id`. On Unix systems this -is done by running the `ps` command. This endpoint is not -supported on Windows. - -**Example request**: - - GET /v1.24/containers/4fa6e0f0c678/top HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD" - ], - "Processes" : [ - [ - "root", "13642", "882", "0", "17:03", "pts/0", "00:00:00", "/bin/bash" - ], - [ - "root", "13735", "13642", "0", "17:06", "pts/0", "00:00:00", "sleep 10" - ] - ] - } - -**Example request**: - - GET /v1.24/containers/4fa6e0f0c678/top?ps_args=aux HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Titles" : [ - "USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND" - ] - "Processes" : [ - [ - "root","13642","0.0","0.1","18172","3184","pts/0","Ss","17:03","0:00","/bin/bash" - ], - [ - "root","13895","0.0","0.0","4348","692","pts/0","S+","17:15","0:00","sleep 10" - ] - ], - } - -**Query parameters**: - -- **ps_args** – `ps` arguments to use (e.g., `aux`), defaults to `-ef` - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container logs - -`GET /containers/(id or name)/logs` - -Get `stdout` and `stderr` logs from the container ``id`` - -> **Note**: -> This endpoint works only for containers with the `json-file` or `journald` logging drivers. - -**Example request**: - - GET /v1.24/containers/4fa6e0f0c678/logs?stderr=1&stdout=1×tamps=1&follow=1&tail=10&since=1428990821 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **details** - 1/True/true or 0/False/flase, Show extra details provided to logs. Default `false`. -- **follow** – 1/True/true or 0/False/false, return stream. Default `false`. -- **stdout** – 1/True/true or 0/False/false, show `stdout` log. Default `false`. -- **stderr** – 1/True/true or 0/False/false, show `stderr` log. Default `false`. -- **since** – UNIX timestamp (integer) to filter logs. Specifying a timestamp - will only output log-entries since that timestamp. Default: 0 (unfiltered) -- **timestamps** – 1/True/true or 0/False/false, print timestamps for - every log line. Default `false`. -- **tail** – Output specified number of lines at the end of logs: `all` or ``. Default all. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **404** – no such container -- **500** – server error - -#### Inspect changes on a container's filesystem - -`GET /containers/(id or name)/changes` - -Inspect changes on container `id`'s filesystem - -**Example request**: - - GET /v1.24/containers/4fa6e0f0c678/changes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Path": "/dev", - "Kind": 0 - }, - { - "Path": "/dev/kmsg", - "Kind": 1 - }, - { - "Path": "/test", - "Kind": 1 - } - ] - -Values for `Kind`: - -- `0`: Modify -- `1`: Add -- `2`: Delete - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Export a container - -`GET /containers/(id or name)/export` - -Export the contents of container `id` - -**Example request**: - - GET /v1.24/containers/4fa6e0f0c678/export HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/octet-stream - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Get container stats based on resource usage - -`GET /containers/(id or name)/stats` - -This endpoint returns a live stream of a container's resource usage statistics. - -**Example request**: - - GET /v1.24/containers/redis1/stats HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "read" : "2015-01-08T22:57:31.547920715Z", - "pids_stats": { - "current": 3 - }, - "networks": { - "eth0": { - "rx_bytes": 5338, - "rx_dropped": 0, - "rx_errors": 0, - "rx_packets": 36, - "tx_bytes": 648, - "tx_dropped": 0, - "tx_errors": 0, - "tx_packets": 8 - }, - "eth5": { - "rx_bytes": 4641, - "rx_dropped": 0, - "rx_errors": 0, - "rx_packets": 26, - "tx_bytes": 690, - "tx_dropped": 0, - "tx_errors": 0, - "tx_packets": 9 - } - }, - "memory_stats" : { - "stats" : { - "total_pgmajfault" : 0, - "cache" : 0, - "mapped_file" : 0, - "total_inactive_file" : 0, - "pgpgout" : 414, - "rss" : 6537216, - "total_mapped_file" : 0, - "writeback" : 0, - "unevictable" : 0, - "pgpgin" : 477, - "total_unevictable" : 0, - "pgmajfault" : 0, - "total_rss" : 6537216, - "total_rss_huge" : 6291456, - "total_writeback" : 0, - "total_inactive_anon" : 0, - "rss_huge" : 6291456, - "hierarchical_memory_limit" : 67108864, - "total_pgfault" : 964, - "total_active_file" : 0, - "active_anon" : 6537216, - "total_active_anon" : 6537216, - "total_pgpgout" : 414, - "total_cache" : 0, - "inactive_anon" : 0, - "active_file" : 0, - "pgfault" : 964, - "inactive_file" : 0, - "total_pgpgin" : 477 - }, - "max_usage" : 6651904, - "usage" : 6537216, - "failcnt" : 0, - "limit" : 67108864 - }, - "blkio_stats" : {}, - "cpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24472255, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100215355, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 739306590000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - }, - "precpu_stats" : { - "cpu_usage" : { - "percpu_usage" : [ - 8646879, - 24350896, - 36438778, - 30657443 - ], - "usage_in_usermode" : 50000000, - "total_usage" : 100093996, - "usage_in_kernelmode" : 30000000 - }, - "system_cpu_usage" : 9492140000000, - "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} - } - } - -The precpu_stats is the cpu statistic of last read, which is used for calculating the cpu usage percent. It is not the exact copy of the “cpu_stats” field. - -**Query parameters**: - -- **stream** – 1/True/true or 0/False/false, pull stats once then disconnect. Default `true`. - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Resize a container TTY - -`POST /containers/(id or name)/resize` - -Resize the TTY for container with `id`. The unit is number of characters. You must restart the container for the resize to take effect. - -**Example request**: - - POST /v1.24/containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **200** – no error -- **404** – No such container -- **500** – Cannot resize container - -#### Start a container - -`POST /containers/(id or name)/start` - -Start the container `id` - -**Example request**: - - POST /v1.24/containers/e90e34656806/start HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **detachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. - -**Status codes**: - -- **204** – no error -- **304** – container already started -- **404** – no such container -- **500** – server error - -#### Stop a container - -`POST /containers/(id or name)/stop` - -Stop the container `id` - -**Example request**: - - POST /v1.24/containers/e90e34656806/stop?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **304** – container already stopped -- **404** – no such container -- **500** – server error - -#### Restart a container - -`POST /containers/(id or name)/restart` - -Restart the container `id` - -**Example request**: - - POST /v1.24/containers/e90e34656806/restart?t=5 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **t** – number of seconds to wait before killing the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Kill a container - -`POST /containers/(id or name)/kill` - -Kill the container `id` - -**Example request**: - - POST /v1.24/containers/e90e34656806/kill HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **signal** - Signal to send to the container: integer or string like `SIGINT`. - When not set, `SIGKILL` is assumed and the call waits for the container to exit. - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Update a container - -`POST /containers/(id or name)/update` - -Update configuration of one or more containers. - -**Example request**: - - POST /v1.24/containers/e90e34656806/update HTTP/1.1 - Content-Type: application/json - - { - "BlkioWeight": 300, - "CpuShares": 512, - "CpuPeriod": 100000, - "CpuQuota": 50000, - "CpusetCpus": "0,1", - "CpusetMems": "0", - "Memory": 314572800, - "MemorySwap": 514288000, - "MemoryReservation": 209715200, - "KernelMemory": 52428800, - "RestartPolicy": { - "MaximumRetryCount": 4, - "Name": "on-failure" - }, - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Warnings": [] - } - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -#### Rename a container - -`POST /containers/(id or name)/rename` - -Rename the container `id` to a `new_name` - -**Example request**: - - POST /v1.24/containers/e90e34656806/rename?name=new_name HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **name** – new name for the container - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **409** - conflict name already assigned -- **500** – server error - -#### Pause a container - -`POST /containers/(id or name)/pause` - -Pause the container `id` - -**Example request**: - - POST /v1.24/containers/e90e34656806/pause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Unpause a container - -`POST /containers/(id or name)/unpause` - -Unpause the container `id` - -**Example request**: - - POST /v1.24/containers/e90e34656806/unpause HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** – no error -- **404** – no such container -- **500** – server error - -#### Attach to a container - -`POST /containers/(id or name)/attach` - -Attach to the container `id` - -**Example request**: - - POST /v1.24/containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 101 UPGRADED - Content-Type: application/vnd.docker.raw-stream - Connection: Upgrade - Upgrade: tcp - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **detachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **101** – no error, hints proxy about hijacking -- **200** – no error, no upgrade header found -- **400** – bad parameter -- **404** – no such container -- **409** - container is paused -- **500** – server error - -**Stream details**: - -When using the TTY setting is enabled in -[`POST /containers/create` -](#create-a-container), -the stream is the raw data from the process PTY and client's `stdin`. -When the TTY is disabled, then the stream is multiplexed to separate -`stdout` and `stderr`. - -The format is a **Header** and a **Payload** (frame). - -**HEADER** - -The header contains the information which the stream writes (`stdout` or -`stderr`). It also contains the size of the associated frame encoded in the -last four bytes (`uint32`). - -It is encoded on the first eight bytes like this: - - header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} - -`STREAM_TYPE` can be: - -- 0: `stdin` (is written on `stdout`) -- 1: `stdout` -- 2: `stderr` - -`SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of -the `uint32` size encoded as big endian. - -**PAYLOAD** - -The payload is the raw stream. - -**IMPLEMENTATION** - -The simplest way to implement the Attach protocol is the following: - - 1. Read eight bytes. - 2. Choose `stdout` or `stderr` depending on the first byte. - 3. Extract the frame size from the last four bytes. - 4. Read the extracted size and output it on the correct output. - 5. Goto 1. - -#### Attach to a container (websocket) - -`GET /containers/(id or name)/attach/ws` - -Attach to the container `id` via websocket - -Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455) - -**Example request** - - GET /v1.24/containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 - -**Example response** - - {% raw %} - {{ STREAM }} - {% endraw %} - -**Query parameters**: - -- **detachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. -- **logs** – 1/True/true or 0/False/false, return logs. Default `false`. -- **stream** – 1/True/true or 0/False/false, return stream. - Default `false`. -- **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach - to `stdin`. Default `false`. -- **stdout** – 1/True/true or 0/False/false, if `logs=true`, return - `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. -- **stderr** – 1/True/true or 0/False/false, if `logs=true`, return - `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **404** – no such container -- **500** – server error - -#### Wait a container - -`POST /containers/(id or name)/wait` - -Block until container `id` stops, then returns the exit code - -**Example request**: - - POST /v1.24/containers/16253994b7c4/wait HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"StatusCode": 0} - -**Status codes**: - -- **200** – no error -- **404** – no such container -- **500** – server error - -#### Remove a container - -`DELETE /containers/(id or name)` - -Remove the container `id` from the filesystem - -**Example request**: - - DELETE /v1.24/containers/16253994b7c4?v=1 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Query parameters**: - -- **v** – 1/True/true or 0/False/false, Remove the volumes - associated to the container. Default `false`. -- **force** - 1/True/true or 0/False/false, Kill then remove the container. - Default `false`. - -**Status codes**: - -- **204** – no error -- **400** – bad parameter -- **404** – no such container -- **409** – conflict -- **500** – server error - -#### Retrieving information about files and folders in a container - -`HEAD /containers/(id or name)/archive` - -See the description of the `X-Docker-Container-Path-Stat` header in the -following section. - -#### Get an archive of a filesystem resource in a container - -`GET /containers/(id or name)/archive` - -Get a tar archive of a resource in the filesystem of container `id`. - -**Query parameters**: - -- **path** - resource in the container's filesystem to archive. Required. - - If not an absolute path, it is relative to the container's root directory. - The resource specified by **path** must exist. To assert that the resource - is expected to be a directory, **path** should end in `/` or `/.` - (assuming a path separator of `/`). If **path** ends in `/.` then this - indicates that only the contents of the **path** directory should be - copied. A symlink is always resolved to its target. - - > **Note**: It is not possible to copy certain system files such as resources - > under `/proc`, `/sys`, `/dev`, and mounts created by the user in the - > container. - -**Example request**: - - GET /v1.24/containers/8cce319429b2/archive?path=/root HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - X-Docker-Container-Path-Stat: eyJuYW1lIjoicm9vdCIsInNpemUiOjQwOTYsIm1vZGUiOjIxNDc0ODQwOTYsIm10aW1lIjoiMjAxNC0wMi0yN1QyMDo1MToyM1oiLCJsaW5rVGFyZ2V0IjoiIn0= - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -On success, a response header `X-Docker-Container-Path-Stat` will be set to a -base64-encoded JSON object containing some filesystem header information about -the archived resource. The above example value would decode to the following -JSON object (whitespace added for readability): - -```json -{ - "name": "root", - "size": 4096, - "mode": 2147484096, - "mtime": "2014-02-27T20:51:23Z", - "linkTarget": "" -} -``` - -A `HEAD` request can also be made to this endpoint if only this information is -desired. - -**Status codes**: - -- **200** - success, returns archive of copied resource -- **400** - client error, bad parameter, details in JSON response body, one of: - - must specify path parameter (**path** cannot be empty) - - not a directory (**path** was asserted to be a directory but exists as a - file) -- **404** - client error, resource not found, one of: - – no such container (container `id` does not exist) - - no such file or directory (**path** does not exist) -- **500** - server error - -#### Extract an archive of files or folders to a directory in a container - -`PUT /containers/(id or name)/archive` - -Upload a tar archive to be extracted to a path in the filesystem of container -`id`. - -**Query parameters**: - -- **path** - path to a directory in the container - to extract the archive's contents into. Required. - - If not an absolute path, it is relative to the container's root directory. - The **path** resource must exist. -- **noOverwriteDirNonDir** - If "1", "true", or "True" then it will be an error - if unpacking the given content would cause an existing directory to be - replaced with a non-directory and vice versa. - -**Example request**: - - PUT /v1.24/containers/8cce319429b2/archive?path=/vol1 HTTP/1.1 - Content-Type: application/x-tar - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** – the content was extracted successfully -- **400** - client error, bad parameter, details in JSON response body, one of: - - must specify path parameter (**path** cannot be empty) - - not a directory (**path** should be a directory but exists as a file) - - unable to overwrite existing directory with non-directory - (if **noOverwriteDirNonDir**) - - unable to overwrite existing non-directory with directory - (if **noOverwriteDirNonDir**) -- **403** - client error, permission denied, the volume - or container rootfs is marked as read-only. -- **404** - client error, resource not found, one of: - – no such container (container `id` does not exist) - - no such file or directory (**path** resource does not exist) -- **500** – server error - -### 3.2 Images - -#### List Images - -`GET /images/json` - -**Example request**: - - GET /v1.24/images/json?all=0 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "RepoTags": [ - "ubuntu:12.04", - "ubuntu:precise", - "ubuntu:latest" - ], - "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", - "Created": 1365714795, - "Size": 131506275, - "VirtualSize": 131506275, - "Labels": {} - }, - { - "RepoTags": [ - "ubuntu:12.10", - "ubuntu:quantal" - ], - "ParentId": "27cf784147099545", - "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", - "Created": 1364102658, - "Size": 24653, - "VirtualSize": 180116135, - "Labels": { - "com.example.version": "v1" - } - } - ] - -**Example request, with digest information**: - - GET /v1.24/images/json?digests=1 HTTP/1.1 - -**Example response, with digest information**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Created": 1420064636, - "Id": "4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125", - "ParentId": "ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2", - "RepoDigests": [ - "localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags": [ - "localhost:5000/test/busybox:latest", - "playdate:latest" - ], - "Size": 0, - "VirtualSize": 2429728, - "Labels": {} - } - ] - -The response shows a single image `Id` associated with two repositories -(`RepoTags`): `localhost:5000/test/busybox`: and `playdate`. A caller can use -either of the `RepoTags` values `localhost:5000/test/busybox:latest` or -`playdate:latest` to reference the image. - -You can also use `RepoDigests` values to reference an image. In this response, -the array has only one reference and that is to the -`localhost:5000/test/busybox` repository; the `playdate` repository has no -digest. You can reference this digest using the value: -`localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d...` - -See the `docker run` and `docker build` commands for examples of digest and tag -references on the command line. - -**Query parameters**: - -- **all** – 1/True/true or 0/False/false, default false -- **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: - - `dangling=true` - - `label=key` or `label="key=value"` of an image label - - `before`=(`[:]`, `` or ``) - - `since`=(`[:]`, `` or ``) -- **filter** - only return images with the specified name - -#### Build image from a Dockerfile - -`POST /build` - -Build an image from a Dockerfile - -**Example request**: - - POST /v1.24/build HTTP/1.1 - - {% raw %} - {{ TAR STREAM }} - {% endraw %} - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"stream": "Step 1/5..."} - {"stream": "..."} - {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} - -The input stream must be a `tar` archive compressed with one of the -following algorithms: `identity` (no compression), `gzip`, `bzip2`, `xz`. - -The archive must include a build instructions file, typically called -`Dockerfile` at the archive's root. The `dockerfile` parameter may be -used to specify a different build instructions file. To do this, its value must be -the path to the alternate build instructions file to use. - -The archive may include any number of other files, -which are accessible in the build context (See the [*ADD build -command*](../reference/builder.md#add)). - -The Docker daemon performs a preliminary validation of the `Dockerfile` before -starting the build, and returns an error if the syntax is incorrect. After that, -each instruction is run one-by-one until the ID of the new image is output. - -The build is canceled if the client drops the connection by quitting -or being killed. - -**Query parameters**: - -- **dockerfile** - Path within the build context to the `Dockerfile`. This is - ignored if `remote` is specified and points to an external `Dockerfile`. -- **t** – A name and optional tag to apply to the image in the `name:tag` format. - If you omit the `tag` the default `latest` value is assumed. - You can provide one or more `t` parameters. -- **remote** – A Git repository URI or HTTP/HTTPS context URI. If the - URI points to a single text file, the file's contents are placed into - a file called `Dockerfile` and the image is built from that file. If - the URI points to a tarball, the file is downloaded by the daemon and - the contents therein used as the context for the build. If the URI - points to a tarball and the `dockerfile` parameter is also specified, - there must be a file with the corresponding path inside the tarball. -- **q** – Suppress verbose build output. -- **nocache** – Do not use the cache when building the image. -- **pull** - Attempt to pull the image even if an older image exists locally. -- **rm** - Remove intermediate containers after a successful build (default behavior). -- **forcerm** - Always remove intermediate containers (includes `rm`). -- **memory** - Set memory limit for build. -- **memswap** - Total memory (memory + swap), `-1` to enable unlimited swap. -- **cpushares** - CPU shares (relative weight). -- **cpusetcpus** - CPUs in which to allow execution (e.g., `0-3`, `0,1`). -- **cpuperiod** - The length of a CPU period in microseconds. -- **cpuquota** - Microseconds of CPU time that the container can get in a CPU period. -- **buildargs** – JSON map of string pairs for build-time variables. Users pass - these values at build-time. Docker uses the `buildargs` as the environment - context for command(s) run via the Dockerfile's `RUN` instruction or for - variable expansion in other Dockerfile instructions. This is not meant for - passing secret values. [Read more about the buildargs instruction](../reference/builder.md#arg) -- **shmsize** - Size of `/dev/shm` in bytes. The size must be greater than 0. If omitted the system uses 64MB. -- **labels** – JSON map of string pairs for labels to set on the image. - -**Request Headers**: - -- **Content-type** – Set to `"application/tar"`. -- **X-Registry-Config** – A base64-url-safe-encoded Registry Auth Config JSON - object with the following structure: - - { - "docker.example.com": { - "username": "janedoe", - "password": "hunter2" - }, - "https://index.docker.io/v1/": { - "username": "mobydock", - "password": "conta1n3rize14" - } - } - - This object maps the hostname of a registry to an object containing the - "username" and "password" for that registry. Multiple registries may - be specified as the build may be based on an image requiring - authentication to pull from any arbitrary registry. Only the registry - domain name (and port if not the default "443") are required. However - (for legacy reasons) the "official" Docker, Inc. hosted registry must - be specified with both a "https://" prefix and a "/v1/" suffix even - though Docker will prefer to use the v2 registry API. - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Create an image - -`POST /images/create` - -Create an image either by pulling it from the registry or by importing it - -**Example request**: - - POST /v1.24/images/create?fromImage=busybox&tag=latest HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pulling..."} - {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} - {"error": "Invalid..."} - ... - -When using this endpoint to pull an image from the registry, the -`X-Registry-Auth` header can be used to include -a base64-encoded AuthConfig object. - -**Query parameters**: - -- **fromImage** – Name of the image to pull. The name may include a tag or - digest. This parameter may only be used when pulling an image. - The pull is cancelled if the HTTP connection is closed. -- **fromSrc** – Source to import. The value may be a URL from which the image - can be retrieved or `-` to read the image from the request body. - This parameter may only be used when importing an image. -- **repo** – Repository name given to an image when it is imported. - The repo may include a tag. This parameter may only be used when importing - an image. -- **tag** – Tag or digest. If empty when pulling an image, this causes all tags - for the given image to be pulled. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object, containing either login information, or a token - - Credential based login: - - ``` - { - "username": "jdoe", - "password": "secret", - "email": "jdoe@acme.com" - } - ``` - - - Token based login: - - ``` - { - "identitytoken": "9cbaf023786cd7..." - } - ``` - -**Status codes**: - -- **200** – no error -- **404** - repository does not exist or no read access -- **500** – server error - - - -#### Inspect an image - -`GET /images/(name)/json` - -Return low-level information on the image `name` - -**Example request**: - - GET /v1.24/images/example/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Id" : "sha256:85f05633ddc1c50679be2b16a0479ab6f7637f8884e0cfe0f4d20e1ebb3d6e7c", - "Container" : "cb91e48a60d01f1e27028b4fc6819f4f290b3cf12496c8176ec714d0d390984a", - "Comment" : "", - "Os" : "linux", - "Architecture" : "amd64", - "Parent" : "sha256:91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "ContainerConfig" : { - "Tty" : false, - "Hostname" : "e611e15f9c9d", - "Volumes" : null, - "Domainname" : "", - "AttachStdout" : false, - "PublishService" : "", - "AttachStdin" : false, - "OpenStdin" : false, - "StdinOnce" : false, - "NetworkDisabled" : false, - "OnBuild" : [], - "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "User" : "", - "WorkingDir" : "", - "Entrypoint" : null, - "MacAddress" : "", - "AttachStderr" : false, - "Labels" : { - "com.example.license" : "GPL", - "com.example.version" : "1.0", - "com.example.vendor" : "Acme" - }, - "Env" : [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "ExposedPorts" : null, - "Cmd" : [ - "/bin/sh", - "-c", - "#(nop) LABEL com.example.vendor=Acme com.example.license=GPL com.example.version=1.0" - ] - }, - "DockerVersion" : "1.9.0-dev", - "VirtualSize" : 188359297, - "Size" : 0, - "Author" : "", - "Created" : "2015-09-10T08:30:53.26995814Z", - "GraphDriver" : { - "Name" : "aufs", - "Data" : null - }, - "RepoDigests" : [ - "localhost:5000/test/busybox/example@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" - ], - "RepoTags" : [ - "example:1.0", - "example:latest", - "example:stable" - ], - "Config" : { - "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - "NetworkDisabled" : false, - "OnBuild" : [], - "StdinOnce" : false, - "PublishService" : "", - "AttachStdin" : false, - "OpenStdin" : false, - "Domainname" : "", - "AttachStdout" : false, - "Tty" : false, - "Hostname" : "e611e15f9c9d", - "Volumes" : null, - "Cmd" : [ - "/bin/bash" - ], - "ExposedPorts" : null, - "Env" : [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - ], - "Labels" : { - "com.example.vendor" : "Acme", - "com.example.version" : "1.0", - "com.example.license" : "GPL" - }, - "Entrypoint" : null, - "MacAddress" : "", - "AttachStderr" : false, - "WorkingDir" : "", - "User" : "" - }, - "RootFS": { - "Type": "layers", - "Layers": [ - "sha256:1834950e52ce4d5a88a1bbd131c537f4d0e56d10ff0dd69e66be3b7dfa9df7e6", - "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef" - ] - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Get the history of an image - -`GET /images/(name)/history` - -Return the history of the image `name` - -**Example request**: - - GET /v1.24/images/ubuntu/history HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "Id": "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710", - "Created": 1398108230, - "CreatedBy": "/bin/sh -c #(nop) ADD file:eb15dbd63394e063b805a3c32ca7bf0266ef64676d5a6fab4801f2e81e2a5148 in /", - "Tags": [ - "ubuntu:lucid", - "ubuntu:10.04" - ], - "Size": 182964289, - "Comment": "" - }, - { - "Id": "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8", - "Created": 1398108222, - "CreatedBy": "/bin/sh -c #(nop) MAINTAINER Tianon Gravi - mkimage-debootstrap.sh -i iproute,iputils-ping,ubuntu-minimal -t lucid.tar.xz lucid http://archive.ubuntu.com/ubuntu/", - "Tags": null, - "Size": 0, - "Comment": "" - }, - { - "Id": "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158", - "Created": 1371157430, - "CreatedBy": "", - "Tags": [ - "scratch12:latest", - "scratch:latest" - ], - "Size": 0, - "Comment": "Imported from -" - } - ] - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Push an image on the registry - -`POST /images/(name)/push` - -Push the image `name` on the registry - -**Example request**: - - POST /v1.24/images/test/push HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - {"status": "Pushing..."} - {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} - {"error": "Invalid..."} - ... - -If you wish to push an image on to a private registry, that image must already have a tag -into a repository which references that registry `hostname` and `port`. This repository name should -then be used in the URL. This duplicates the command line's flow. - -The push is cancelled if the HTTP connection is closed. - -**Example request**: - - POST /v1.24/images/registry.acme.com:5000/test/push HTTP/1.1 - - -**Query parameters**: - -- **tag** – The tag to associate with the image on the registry. This is optional. - -**Request Headers**: - -- **X-Registry-Auth** – base64-encoded AuthConfig object, containing either login information, or a token - - Credential based login: - - ``` - { - "username": "jdoe", - "password": "secret", - "email": "jdoe@acme.com", - } - ``` - - - Identity token based login: - - ``` - { - "identitytoken": "9cbaf023786cd7..." - } - ``` - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **500** – server error - -#### Tag an image into a repository - -`POST /images/(name)/tag` - -Tag the image `name` into a repository - -**Example request**: - - POST /v1.24/images/test/tag?repo=myrepo&tag=v42 HTTP/1.1 - -**Example response**: - - HTTP/1.1 201 Created - -**Query parameters**: - -- **repo** – The repository to tag in -- **tag** - The new tag name - -**Status codes**: - -- **201** – no error -- **400** – bad parameter -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Remove an image - -`DELETE /images/(name)` - -Remove the image `name` from the filesystem - -**Example request**: - - DELETE /v1.24/images/test HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-type: application/json - - [ - {"Untagged": "3e2f21a89f"}, - {"Deleted": "3e2f21a89f"}, - {"Deleted": "53b4f83ac9"} - ] - -**Query parameters**: - -- **force** – 1/True/true or 0/False/false, default false -- **noprune** – 1/True/true or 0/False/false, default false - -**Status codes**: - -- **200** – no error -- **404** – no such image -- **409** – conflict -- **500** – server error - -#### Search images - -`GET /images/search` - -Search for an image on [Docker Hub](https://hub.docker.com). - -> **Note**: -> The response keys have changed from API v1.6 to reflect the JSON -> sent by the registry server to the docker daemon's request. - -**Example request**: - - GET /v1.24/images/search?term=sshd HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "wma55/u1210sshd", - "star_count": 0 - }, - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "jdswinbank/sshd", - "star_count": 0 - }, - { - "description": "", - "is_official": false, - "is_automated": false, - "name": "vgauthier/sshd", - "star_count": 0 - } - ... - ] - -**Query parameters**: - -- **term** – term to search -- **limit** – maximum returned search results -- **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: - - `stars=` - - `is-automated=(true|false)` - - `is-official=(true|false)` - -**Status codes**: - -- **200** – no error -- **500** – server error - -### 3.3 Misc - -#### Check auth configuration - -`POST /auth` - -Validate credentials for a registry and get identity token, -if available, for accessing the registry without password. - -**Example request**: - - POST /v1.24/auth HTTP/1.1 - Content-Type: application/json - - { - "username": "hannibal", - "password": "xxxx", - "serveraddress": "https://index.docker.io/v1/" - } - -**Example response**: - - HTTP/1.1 200 OK - - { - "Status": "Login Succeeded", - "IdentityToken": "9cbaf023786cd7..." - } - -**Status codes**: - -- **200** – no error -- **204** – no error -- **500** – server error - -#### Display system-wide information - -`GET /info` - -Display system-wide information - -**Example request**: - - GET /v1.24/info HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Architecture": "x86_64", - "ClusterStore": "etcd://localhost:2379", - "CgroupDriver": "cgroupfs", - "Containers": 11, - "ContainersRunning": 7, - "ContainersStopped": 3, - "ContainersPaused": 1, - "CpuCfsPeriod": true, - "CpuCfsQuota": true, - "Debug": false, - "DockerRootDir": "/var/lib/docker", - "Driver": "btrfs", - "DriverStatus": [[""]], - "ExperimentalBuild": false, - "HttpProxy": "http://test:test@localhost:8080", - "HttpsProxy": "https://test:test@localhost:8080", - "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", - "IPv4Forwarding": true, - "Images": 16, - "IndexServerAddress": "https://index.docker.io/v1/", - "InitPath": "/usr/bin/docker", - "InitSha1": "", - "KernelMemory": true, - "KernelVersion": "3.12.0-1-amd64", - "Labels": [ - "storage=ssd" - ], - "MemTotal": 2099236864, - "MemoryLimit": true, - "NCPU": 1, - "NEventsListener": 0, - "NFd": 11, - "NGoroutines": 21, - "Name": "prod-server-42", - "NoProxy": "9.81.1.160", - "OomKillDisable": true, - "OSType": "linux", - "OperatingSystem": "Boot2Docker", - "Plugins": { - "Volume": [ - "local" - ], - "Network": [ - "null", - "host", - "bridge" - ] - }, - "RegistryConfig": { - "IndexConfigs": { - "docker.io": { - "Mirrors": null, - "Name": "docker.io", - "Official": true, - "Secure": true - } - }, - "InsecureRegistryCIDRs": [ - "127.0.0.0/8" - ] - }, - "SecurityOptions": [ - "apparmor", - "seccomp", - "selinux" - ], - "ServerVersion": "1.9.0", - "SwapLimit": false, - "SystemStatus": [["State", "Healthy"]], - "SystemTime": "2015-03-10T11:11:23.730591467-07:00" - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Show the docker version information - -`GET /version` - -Show the docker version information - -**Example request**: - - GET /v1.24/version HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Version": "1.12.0", - "Os": "linux", - "KernelVersion": "3.19.0-23-generic", - "GoVersion": "go1.6.3", - "GitCommit": "deadbee", - "Arch": "amd64", - "ApiVersion": "1.24", - "BuildTime": "2016-06-14T07:09:13.444803460+00:00", - "Experimental": true - } - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Ping the docker server - -`GET /_ping` - -Ping the docker server - -**Example request**: - - GET /v1.24/_ping HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: text/plain - - OK - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a new image from a container's changes - -`POST /commit` - -Create a new image from a container's changes - -**Example request**: - - POST /v1.24/commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 - Content-Type: application/json - - { - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Mounts": [ - { - "Source": "/data", - "Destination": "/data", - "Mode": "ro,Z", - "RW": false - } - ], - "Labels": { - "key1": "value1", - "key2": "value2" - }, - "WorkingDir": "", - "NetworkDisabled": false, - "ExposedPorts": { - "22/tcp": {} - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - {"Id": "596069db4bf5"} - -**JSON parameters**: - -- **config** - the container's configuration - -**Query parameters**: - -- **container** – source container -- **repo** – repository -- **tag** – tag -- **comment** – commit message -- **author** – author (e.g., "John Hannibal Smith - <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") -- **pause** – 1/True/true or 0/False/false, whether to pause the container before committing -- **changes** – Dockerfile instructions to apply while committing - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **500** – server error - -#### Monitor Docker's events - -`GET /events` - -Get container events from docker, in real time via streaming. - -Docker containers report the following events: - - attach, commit, copy, create, destroy, detach, die, exec_create, exec_detach, exec_start, export, health_status, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update - -Docker images report the following events: - - delete, import, load, pull, push, save, tag, untag - -Docker volumes report the following events: - - create, mount, unmount, destroy - -Docker networks report the following events: - - create, connect, disconnect, destroy - -Docker daemon report the following event: - - reload - -**Example request**: - - GET /v1.24/events?since=1374067924 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - Server: Docker/1.12.0 (linux) - Date: Fri, 29 Apr 2016 15:18:06 GMT - Transfer-Encoding: chunked - - { - "status": "pull", - "id": "alpine:latest", - "Type": "image", - "Action": "pull", - "Actor": { - "ID": "alpine:latest", - "Attributes": { - "name": "alpine" - } - }, - "time": 1461943101, - "timeNano": 1461943101301854122 - } - { - "status": "create", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "create", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943101, - "timeNano": 1461943101381709551 - } - { - "status": "attach", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "attach", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943101, - "timeNano": 1461943101383858412 - } - { - "Type": "network", - "Action": "connect", - "Actor": { - "ID": "7dc8ac97d5d29ef6c31b6052f3938c1e8f2749abbd17d1bd1febf2608db1b474", - "Attributes": { - "container": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "name": "bridge", - "type": "bridge" - } - }, - "time": 1461943101, - "timeNano": 1461943101394865557 - } - { - "status": "start", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "start", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943101, - "timeNano": 1461943101607533796 - } - { - "status": "resize", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "resize", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "height": "46", - "image": "alpine", - "name": "my-container", - "width": "204" - } - }, - "time": 1461943101, - "timeNano": 1461943101610269268 - } - { - "status": "die", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "die", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "exitCode": "0", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943105, - "timeNano": 1461943105079144137 - } - { - "Type": "network", - "Action": "disconnect", - "Actor": { - "ID": "7dc8ac97d5d29ef6c31b6052f3938c1e8f2749abbd17d1bd1febf2608db1b474", - "Attributes": { - "container": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "name": "bridge", - "type": "bridge" - } - }, - "time": 1461943105, - "timeNano": 1461943105230860245 - } - { - "status": "destroy", - "id": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "from": "alpine", - "Type": "container", - "Action": "destroy", - "Actor": { - "ID": "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743", - "Attributes": { - "com.example.some-label": "some-label-value", - "image": "alpine", - "name": "my-container" - } - }, - "time": 1461943105, - "timeNano": 1461943105338056026 - } - -**Query parameters**: - -- **since** – Timestamp. Show all events created since timestamp and then stream -- **until** – Timestamp. Show events created until given timestamp and stop streaming -- **filters** – A json encoded value of the filters (a map[string][]string) to process on the event list. Available filters: - - `container=`; -- container to filter - - `event=`; -- event to filter - - `image=`; -- image to filter - - `label=`; -- image and container label to filter - - `type=`; -- either `container` or `image` or `volume` or `network` or `daemon` - - `volume=`; -- volume to filter - - `network=`; -- network to filter - - `daemon=`; -- daemon name or id to filter - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images in a repository - -`GET /images/(name)/get` - -Get a tarball containing all images and metadata for the repository specified -by `name`. - -If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image -(and its parents) are returned. If `name` is an image ID, similarly only that -image (and its parents) are returned, but with the exclusion of the -'repositories' file in the tarball, as there were no image names referenced. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.24/images/ubuntu/get - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Get a tarball containing all images - -`GET /images/get` - -Get a tarball containing all images and metadata for one or more repositories. - -For each value of the `names` parameter: if it is a specific name and tag (e.g. -`ubuntu:latest`), then only that image (and its parents) are returned; if it is -an image ID, similarly only that image (and its parents) are returned and there -would be no names referenced in the 'repositories' file for this image ID. - -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - GET /v1.24/images/get?names=myname%2Fmyapp%3Alatest&names=busybox - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/x-tar - - Binary data stream - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Load a tarball with a set of images and tags into docker - -`POST /images/load` - -Load a set of images and tags into a Docker repository. -See the [image tarball format](#image-tarball-format) for more details. - -**Example request** - - POST /v1.24/images/load - Content-Type: application/x-tar - - Tarball in body - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - Transfer-Encoding: chunked - - {"status":"Loading layer","progressDetail":{"current":32768,"total":1292800},"progress":"[= ] 32.77 kB/1.293 MB","id":"8ac8bfaff55a"} - {"status":"Loading layer","progressDetail":{"current":65536,"total":1292800},"progress":"[== ] 65.54 kB/1.293 MB","id":"8ac8bfaff55a"} - {"status":"Loading layer","progressDetail":{"current":98304,"total":1292800},"progress":"[=== ] 98.3 kB/1.293 MB","id":"8ac8bfaff55a"} - {"status":"Loading layer","progressDetail":{"current":131072,"total":1292800},"progress":"[===== ] 131.1 kB/1.293 MB","id":"8ac8bfaff55a"} - ... - {"stream":"Loaded image: busybox:latest\n"} - -**Example response**: - -If the "quiet" query parameter is set to `true` / `1` (`?quiet=1`), progress -details are suppressed, and only a confirmation message is returned once the -action completes. - - HTTP/1.1 200 OK - Content-Type: application/json - Transfer-Encoding: chunked - - {"stream":"Loaded image: busybox:latest\n"} - -**Query parameters**: - -- **quiet** – Boolean value, suppress progress details during load. Defaults - to `0` / `false` if omitted. - -**Status codes**: - -- **200** – no error -- **500** – server error - -#### Image tarball format - -An image tarball contains one directory per image layer (named using its long ID), -each containing these files: - -- `VERSION`: currently `1.0` - the file format version -- `json`: detailed layer information, similar to `docker inspect layer_id` -- `layer.tar`: A tarfile containing the filesystem changes in this layer - -The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories -for storing attribute changes and deletions. - -If the tarball defines a repository, the tarball should also include a `repositories` file at -the root that contains a list of repository and tag names mapped to layer IDs. - -``` -{"hello-world": - {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} -} -``` - -#### Exec Create - -`POST /containers/(id or name)/exec` - -Sets up an exec instance in a running container `id` - -**Example request**: - - POST /v1.24/containers/e90e34656806/exec HTTP/1.1 - Content-Type: application/json - - { - "AttachStdin": true, - "AttachStdout": true, - "AttachStderr": true, - "Cmd": ["sh"], - "DetachKeys": "ctrl-p,ctrl-q", - "Privileged": true, - "Tty": true, - "User": "123:456" - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Id": "f90e34656806", - "Warnings":[] - } - -**JSON parameters**: - -- **AttachStdin** - Boolean value, attaches to `stdin` of the `exec` command. -- **AttachStdout** - Boolean value, attaches to `stdout` of the `exec` command. -- **AttachStderr** - Boolean value, attaches to `stderr` of the `exec` command. -- **DetachKeys** – Override the key sequence for detaching a - container. Format is a single character `[a-Z]` or `ctrl-` - where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. -- **Tty** - Boolean value to allocate a pseudo-TTY. -- **Cmd** - Command to run specified as a string or an array of strings. -- **Privileged** - Boolean value, runs the exec process with extended privileges. -- **User** - A string value specifying the user, and optionally, group to run - the exec process inside the container. Format is one of: `"user"`, - `"user:group"`, `"uid"`, or `"uid:gid"`. - -**Status codes**: - -- **201** – no error -- **404** – no such container -- **409** - container is paused -- **500** - server error - -#### Exec Start - -`POST /exec/(id)/start` - -Starts a previously set up `exec` instance `id`. If `detach` is true, this API -returns after starting the `exec` command. Otherwise, this API sets up an -interactive session with the `exec` command. - -**Example request**: - - POST /v1.24/exec/e90e34656806/start HTTP/1.1 - Content-Type: application/json - - { - "Detach": false, - "Tty": false - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/vnd.docker.raw-stream - - {% raw %} - {{ STREAM }} - {% endraw %} - -**JSON parameters**: - -- **Detach** - Detach from the `exec` command. -- **Tty** - Boolean value to allocate a pseudo-TTY. - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **409** - container is paused - -**Stream details**: - -Similar to the stream behavior of `POST /containers/(id or name)/attach` API - -#### Exec Resize - -`POST /exec/(id)/resize` - -Resizes the `tty` session used by the `exec` command `id`. The unit is number of characters. -This API is valid only if `tty` was specified as part of creating and starting the `exec` command. - -**Example request**: - - POST /v1.24/exec/e90e34656806/resize?h=40&w=80 HTTP/1.1 - Content-Type: text/plain - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: text/plain - -**Query parameters**: - -- **h** – height of `tty` session -- **w** – width - -**Status codes**: - -- **201** – no error -- **404** – no such exec instance - -#### Exec Inspect - -`GET /exec/(id)/json` - -Return low-level information about the `exec` command `id`. - -**Example request**: - - GET /v1.24/exec/11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39/json HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "CanRemove": false, - "ContainerID": "b53ee82b53a40c7dca428523e34f741f3abc51d9f297a14ff874bf761b995126", - "DetachKeys": "", - "ExitCode": 2, - "ID": "f33bbfb39f5b142420f4759b2348913bd4a8d1a6d7fd56499cb41a1bb91d7b3b", - "OpenStderr": true, - "OpenStdin": true, - "OpenStdout": true, - "ProcessConfig": { - "arguments": [ - "-c", - "exit 2" - ], - "entrypoint": "sh", - "privileged": false, - "tty": true, - "user": "1000" - }, - "Running": false - } - -**Status codes**: - -- **200** – no error -- **404** – no such exec instance -- **500** - server error - -### 3.4 Volumes - -#### List volumes - -`GET /volumes` - -**Example request**: - - GET /v1.24/volumes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Volumes": [ - { - "Name": "tardis", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/tardis", - "Labels": null, - "Scope": "local" - } - ], - "Warnings": [] - } - -**Query parameters**: - -- **filters** - JSON encoded value of the filters (a `map[string][]string`) to process on the volumes list. Available filters: - - `name=` Matches all or part of a volume name. - - `dangling=` When set to `true` (or `1`), returns all volumes that are "dangling" (not in use by a container). When set to `false` (or `0`), only volumes that are in use by one or more containers are returned. - - `driver=` Matches all or part of a volume driver name. - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Create a volume - -`POST /volumes/create` - -Create a volume - -**Example request**: - - POST /v1.24/volumes/create HTTP/1.1 - Content-Type: application/json - - { - "Name": "tardis", - "Labels": { - "com.example.some-label": "some-value", - "com.example.some-other-label": "some-other-value" - }, - "Driver": "custom" - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "Name": "tardis", - "Driver": "custom", - "Mountpoint": "/var/lib/docker/volumes/tardis", - "Status": { - "hello": "world" - }, - "Labels": { - "com.example.some-label": "some-value", - "com.example.some-other-label": "some-other-value" - }, - "Scope": "local" - } - -**Status codes**: - -- **201** - no error -- **500** - server error - -**JSON parameters**: - -- **Name** - The new volume's name. If not specified, Docker generates a name. -- **Driver** - Name of the volume driver to use. Defaults to `local` for the name. -- **DriverOpts** - A mapping of driver options and values. These options are - passed directly to the driver and are driver specific. -- **Labels** - Labels to set on the volume, specified as a map: `{"key":"value","key2":"value2"}` - -**JSON fields in response**: - -Refer to the [inspect a volume](#inspect-a-volume) section or details about the -JSON fields returned in the response. - -#### Inspect a volume - -`GET /volumes/(name)` - -Return low-level information on the volume `name` - -**Example request**: - - GET /v1.24/volumes/tardis - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "Name": "tardis", - "Driver": "custom", - "Mountpoint": "/var/lib/docker/volumes/tardis/_data", - "Status": { - "hello": "world" - }, - "Labels": { - "com.example.some-label": "some-value", - "com.example.some-other-label": "some-other-value" - }, - "Scope": "local" - } - -**Status codes**: - -- **200** - no error -- **404** - no such volume -- **500** - server error - -**JSON fields in response**: - -The following fields can be returned in the API response. Empty fields, or -fields that are not supported by the volume's driver may be omitted in the -response. - -- **Name** - Name of the volume. -- **Driver** - Name of the volume driver used by the volume. -- **Mountpoint** - Mount path of the volume on the host. -- **Status** - Low-level details about the volume, provided by the volume driver. - Details are returned as a map with key/value pairs: `{"key":"value","key2":"value2"}`. - The `Status` field is optional, and is omitted if the volume driver does not - support this feature. -- **Labels** - Labels set on the volume, specified as a map: `{"key":"value","key2":"value2"}`. -- **Scope** - Scope describes the level at which the volume exists, can be one of - `global` for cluster-wide or `local` for machine level. The default is `local`. - -#### Remove a volume - -`DELETE /volumes/(name)` - -Instruct the driver to remove the volume (`name`). - -**Example request**: - - DELETE /v1.24/volumes/tardis HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** - no error -- **404** - no such volume or volume driver -- **409** - volume is in use and cannot be removed -- **500** - server error - -### 3.5 Networks - -#### List networks - -`GET /networks` - -**Example request**: - - GET /v1.24/networks?filters={"type":{"custom":true}} HTTP/1.1 - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json - -[ - { - "Name": "bridge", - "Id": "f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566", - "Scope": "local", - "Driver": "bridge", - "EnableIPv6": false, - "Internal": false, - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.17.0.0/16" - } - ] - }, - "Containers": { - "39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": { - "EndpointID": "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda", - "MacAddress": "02:42:ac:11:00:02", - "IPv4Address": "172.17.0.2/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - } - }, - { - "Name": "none", - "Id": "e086a3893b05ab69242d3c44e49483a3bbbd3a26b46baa8f61ab797c1088d794", - "Scope": "local", - "Driver": "null", - "EnableIPv6": false, - "Internal": false, - "IPAM": { - "Driver": "default", - "Config": [] - }, - "Containers": {}, - "Options": {} - }, - { - "Name": "host", - "Id": "13e871235c677f196c4e1ecebb9dc733b9b2d2ab589e30c539efeda84a24215e", - "Scope": "local", - "Driver": "host", - "EnableIPv6": false, - "Internal": false, - "IPAM": { - "Driver": "default", - "Config": [] - }, - "Containers": {}, - "Options": {} - } -] -``` - -**Query parameters**: - -- **filters** - JSON encoded network list filter. The filter value is one of: - - `driver=` Matches a network's driver. - - `id=` Matches all or part of a network id. - - `label=` or `label==` of a network label. - - `name=` Matches all or part of a network name. - - `type=["custom"|"builtin"]` Filters networks by type. The `custom` keyword returns all user-defined networks. - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Inspect network - -`GET /networks/` - -**Example request**: - - GET /v1.24/networks/7d86d31b1478e7cca9ebed7e73aa0fdeec46c5ca29497431d3007d2d9e15ed99 HTTP/1.1 - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json - -{ - "Name": "net01", - "Id": "7d86d31b1478e7cca9ebed7e73aa0fdeec46c5ca29497431d3007d2d9e15ed99", - "Scope": "local", - "Driver": "bridge", - "EnableIPv6": false, - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.19.0.0/16", - "Gateway": "172.19.0.1" - } - ], - "Options": { - "foo": "bar" - } - }, - "Internal": false, - "Containers": { - "19a4d5d687db25203351ed79d478946f861258f018fe384f229f2efa4b23513c": { - "Name": "test", - "EndpointID": "628cadb8bcb92de107b2a1e516cbffe463e321f548feb37697cce00ad694f21a", - "MacAddress": "02:42:ac:13:00:02", - "IPv4Address": "172.19.0.2/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - }, - "Labels": { - "com.example.some-label": "some-value", - "com.example.some-other-label": "some-other-value" - } -} -``` - -**Status codes**: - -- **200** - no error -- **404** - network not found - -#### Create a network - -`POST /networks/create` - -Create a network - -**Example request**: - -``` -POST /v1.24/networks/create HTTP/1.1 -Content-Type: application/json - -{ - "Name":"isolated_nw", - "CheckDuplicate":true, - "Driver":"bridge", - "EnableIPv6": true, - "IPAM":{ - "Driver": "default", - "Config":[ - { - "Subnet":"172.20.0.0/16", - "IPRange":"172.20.10.0/24", - "Gateway":"172.20.10.11" - }, - { - "Subnet":"2001:db8:abcd::/64", - "Gateway":"2001:db8:abcd::1011" - } - ], - "Options": { - "foo": "bar" - } - }, - "Internal":true, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - }, - "Labels": { - "com.example.some-label": "some-value", - "com.example.some-other-label": "some-other-value" - } -} -``` - -**Example response**: - -``` -HTTP/1.1 201 Created -Content-Type: application/json - -{ - "Id": "22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30", - "Warning": "" -} -``` - -**Status codes**: - -- **201** - no error -- **403** - operation not supported for pre-defined networks -- **404** - plugin not found -- **500** - server error - -**JSON parameters**: - -- **Name** - The new network's name. this is a mandatory field -- **CheckDuplicate** - Requests daemon to check for networks with same name. Defaults to `false` -- **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver -- **Internal** - Restrict external access to the network -- **IPAM** - Optional custom IP scheme for the network - - **Driver** - Name of the IPAM driver to use. Defaults to `default` driver - - **Config** - List of IPAM configuration options, specified as a map: - `{"Subnet": , "IPRange": , "Gateway": , "AuxAddress": }` - - **Options** - Driver-specific options, specified as a map: `{"option":"value" [,"option2":"value2"]}` -- **EnableIPv6** - Enable IPv6 on the network -- **Options** - Network specific options to be used by the drivers -- **Labels** - Labels to set on the network, specified as a map: `{"key":"value" [,"key2":"value2"]}` - -#### Connect a container to a network - -`POST /networks/(id)/connect` - -Connect a container to a network - -**Example request**: - -``` -POST /v1.24/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30/connect HTTP/1.1 -Content-Type: application/json - -{ - "Container":"3613f73ba0e4", - "EndpointConfig": { - "IPAMConfig": { - "IPv4Address":"172.24.56.89", - "IPv6Address":"2001:db8::5689" - } - } -} -``` - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** - no error -- **403** - operation not supported for swarm scoped networks -- **404** - network or container is not found -- **500** - Internal Server Error - -**JSON parameters**: - -- **container** - container-id/name to be connected to the network - -#### Disconnect a container from a network - -`POST /networks/(id)/disconnect` - -Disconnect a container from a network - -**Example request**: - -``` -POST /v1.24/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30/disconnect HTTP/1.1 -Content-Type: application/json - -{ - "Container":"3613f73ba0e4", - "Force":false -} -``` - -**Example response**: - - HTTP/1.1 200 OK - -**Status codes**: - -- **200** - no error -- **403** - operation not supported for swarm scoped networks -- **404** - network or container not found -- **500** - Internal Server Error - -**JSON parameters**: - -- **Container** - container-id/name to be disconnected from a network -- **Force** - Force the container to disconnect from a network - -#### Remove a network - -`DELETE /networks/(id)` - -Instruct the driver to remove the network (`id`). - -**Example request**: - - DELETE /v1.24/networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30 HTTP/1.1 - -**Example response**: - - HTTP/1.1 204 No Content - -**Status codes**: - -- **204** - no error -- **404** - no such network -- **500** - server error - -### 3.6 Plugins (experimental) - -#### List plugins - -`GET /plugins` - -Returns information about installed plugins. - -**Example request**: - - GET /v1.24/plugins HTTP/1.1 - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json - -[ - { - "Id": "5724e2c8652da337ab2eedd19fc6fc0ec908e4bd907c7421bf6a8dfc70c4c078", - "Name": "tiborvass/no-remove", - "Tag": "latest", - "Active": true, - "Config": { - "Mounts": [ - { - "Name": "", - "Description": "", - "Settable": null, - "Source": "/data", - "Destination": "/data", - "Type": "bind", - "Options": [ - "shared", - "rbind" - ] - }, - { - "Name": "", - "Description": "", - "Settable": null, - "Source": null, - "Destination": "/foobar", - "Type": "tmpfs", - "Options": null - } - ], - "Env": [ - "DEBUG=1" - ], - "Args": null, - "Devices": null - }, - "Manifest": { - "ManifestVersion": "v0", - "Description": "A test plugin for Docker", - "Documentation": "https://docs.docker.com/engine/extend/plugins/", - "Interface": { - "Types": [ - "docker.volumedriver/1.0" - ], - "Socket": "plugins.sock" - }, - "Entrypoint": [ - "plugin-no-remove", - "/data" - ], - "Workdir": "", - "User": { - }, - "Network": { - "Type": "host" - }, - "Capabilities": null, - "Mounts": [ - { - "Name": "", - "Description": "", - "Settable": null, - "Source": "/data", - "Destination": "/data", - "Type": "bind", - "Options": [ - "shared", - "rbind" - ] - }, - { - "Name": "", - "Description": "", - "Settable": null, - "Source": null, - "Destination": "/foobar", - "Type": "tmpfs", - "Options": null - } - ], - "Devices": [ - { - "Name": "device", - "Description": "a host device to mount", - "Settable": null, - "Path": "/dev/cpu_dma_latency" - } - ], - "Env": [ - { - "Name": "DEBUG", - "Description": "If set, prints debug messages", - "Settable": null, - "Value": "1" - } - ], - "Args": { - "Name": "args", - "Description": "command line arguments", - "Settable": null, - "Value": [ - - ] - } - } - } -] -``` - -**Status codes**: - -- **200** - no error -- **500** - server error - -#### Install a plugin - -`POST /plugins/pull?name=` - -Pulls and installs a plugin. After the plugin is installed, it can be enabled -using the [`POST /plugins/(plugin name)/enable` endpoint](#enable-a-plugin). - -**Example request**: - -``` -POST /v1.24/plugins/pull?name=tiborvass/no-remove:latest HTTP/1.1 -``` - -The `:latest` tag is optional, and is used as default if omitted. When using -this endpoint to pull a plugin from the registry, the `X-Registry-Auth` header -can be used to include a base64-encoded AuthConfig object. Refer to the [create -an image](#create-an-image) section for more details. - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json -Content-Length: 175 - -[ - { - "Name": "network", - "Description": "", - "Value": [ - "host" - ] - }, - { - "Name": "mount", - "Description": "", - "Value": [ - "/data" - ] - }, - { - "Name": "device", - "Description": "", - "Value": [ - "/dev/cpu_dma_latency" - ] - } -] -``` - -**Query parameters**: - -- **name** - Name of the plugin to pull. The name may include a tag or digest. - This parameter is required. - -**Status codes**: - -- **200** - no error -- **500** - error parsing reference / not a valid repository/tag: repository - name must have at least one component -- **500** - plugin already exists - -#### Inspect a plugin - -`GET /plugins/(plugin name)` - -Returns detailed information about an installed plugin. - -**Example request**: - -``` -GET /v1.24/plugins/tiborvass/no-remove:latest HTTP/1.1 -``` - -The `:latest` tag is optional, and is used as default if omitted. - - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Type: application/json - -{ - "Id": "5724e2c8652da337ab2eedd19fc6fc0ec908e4bd907c7421bf6a8dfc70c4c078", - "Name": "tiborvass/no-remove", - "Tag": "latest", - "Active": false, - "Config": { - "Mounts": [ - { - "Name": "", - "Description": "", - "Settable": null, - "Source": "/data", - "Destination": "/data", - "Type": "bind", - "Options": [ - "shared", - "rbind" - ] - }, - { - "Name": "", - "Description": "", - "Settable": null, - "Source": null, - "Destination": "/foobar", - "Type": "tmpfs", - "Options": null - } - ], - "Env": [ - "DEBUG=1" - ], - "Args": null, - "Devices": null - }, - "Manifest": { - "ManifestVersion": "v0", - "Description": "A test plugin for Docker", - "Documentation": "https://docs.docker.com/engine/extend/plugins/", - "Interface": { - "Types": [ - "docker.volumedriver/1.0" - ], - "Socket": "plugins.sock" - }, - "Entrypoint": [ - "plugin-no-remove", - "/data" - ], - "Workdir": "", - "User": { - }, - "Network": { - "Type": "host" - }, - "Capabilities": null, - "Mounts": [ - { - "Name": "", - "Description": "", - "Settable": null, - "Source": "/data", - "Destination": "/data", - "Type": "bind", - "Options": [ - "shared", - "rbind" - ] - }, - { - "Name": "", - "Description": "", - "Settable": null, - "Source": null, - "Destination": "/foobar", - "Type": "tmpfs", - "Options": null - } - ], - "Devices": [ - { - "Name": "device", - "Description": "a host device to mount", - "Settable": null, - "Path": "/dev/cpu_dma_latency" - } - ], - "Env": [ - { - "Name": "DEBUG", - "Description": "If set, prints debug messages", - "Settable": null, - "Value": "1" - } - ], - "Args": { - "Name": "args", - "Description": "command line arguments", - "Settable": null, - "Value": [ - - ] - } - } -} -``` - -**Status codes**: - -- **200** - no error -- **404** - plugin not installed - -#### Enable a plugin - -`POST /plugins/(plugin name)/enable` - -Enables a plugin - -**Example request**: - -``` -POST /v1.24/plugins/tiborvass/no-remove:latest/enable HTTP/1.1 -``` - -The `:latest` tag is optional, and is used as default if omitted. - - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Length: 0 -Content-Type: text/plain; charset=utf-8 -``` - -**Status codes**: - -- **200** - no error -- **500** - plugin is already enabled - -#### Disable a plugin - -`POST /plugins/(plugin name)/disable` - -Disables a plugin - -**Example request**: - -``` -POST /v1.24/plugins/tiborvass/no-remove:latest/disable HTTP/1.1 -``` - -The `:latest` tag is optional, and is used as default if omitted. - - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Length: 0 -Content-Type: text/plain; charset=utf-8 -``` - -**Status codes**: - -- **200** - no error -- **500** - plugin is already disabled - -#### Remove a plugin - -`DELETE /plugins/(plugin name)` - -Removes a plugin - -**Example request**: - -``` -DELETE /v1.24/plugins/tiborvass/no-remove:latest HTTP/1.1 -``` - -The `:latest` tag is optional, and is used as default if omitted. - -**Example response**: - -``` -HTTP/1.1 200 OK -Content-Length: 0 -Content-Type: text/plain; charset=utf-8 -``` - -**Status codes**: - -- **200** - no error -- **404** - plugin not installed -- **500** - plugin is active - - - -### 3.7 Nodes - -**Note**: Node operations require the engine to be part of a swarm. - -#### List nodes - - -`GET /nodes` - -List nodes - -**Example request**: - - GET /v1.24/nodes HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "ID": "24ifsmvkjbyhk", - "Version": { - "Index": 8 - }, - "CreatedAt": "2016-06-07T20:31:11.853781916Z", - "UpdatedAt": "2016-06-07T20:31:11.999868824Z", - "Spec": { - "Name": "my-node", - "Role": "manager", - "Availability": "active" - "Labels": { - "foo": "bar" - } - }, - "Description": { - "Hostname": "bf3067039e47", - "Platform": { - "Architecture": "x86_64", - "OS": "linux" - }, - "Resources": { - "NanoCPUs": 4000000000, - "MemoryBytes": 8272408576 - }, - "Engine": { - "EngineVersion": "1.12.0", - "Labels": { - "foo": "bar", - } - "Plugins": [ - { - "Type": "Volume", - "Name": "local" - }, - { - "Type": "Network", - "Name": "bridge" - } - { - "Type": "Network", - "Name": "null" - } - { - "Type": "Network", - "Name": "overlay" - } - ] - } - }, - "Status": { - "State": "ready" - }, - "ManagerStatus": { - "Leader": true, - "Reachability": "reachable", - "Addr": "172.17.0.2:2377"" - } - } - ] - -**Query parameters**: - -- **filters** – a JSON encoded value of the filters (a `map[string][]string`) to process on the - nodes list. Available filters: - - `id=` - - `label=` - - `membership=`(`accepted`|`pending`)` - - `name=` - - `role=`(`manager`|`worker`)` - -**Status codes**: - -- **200** – no error -- **406** - node is not part of a swarm -- **500** – server error - -#### Inspect a node - - -`GET /nodes/(id or name)` - -Return low-level information on the node `id` - -**Example request**: - - GET /v1.24/nodes/24ifsmvkjbyhk HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "ID": "24ifsmvkjbyhk", - "Version": { - "Index": 8 - }, - "CreatedAt": "2016-06-07T20:31:11.853781916Z", - "UpdatedAt": "2016-06-07T20:31:11.999868824Z", - "Spec": { - "Name": "my-node", - "Role": "manager", - "Availability": "active" - "Labels": { - "foo": "bar" - } - }, - "Description": { - "Hostname": "bf3067039e47", - "Platform": { - "Architecture": "x86_64", - "OS": "linux" - }, - "Resources": { - "NanoCPUs": 4000000000, - "MemoryBytes": 8272408576 - }, - "Engine": { - "EngineVersion": "1.12.0", - "Labels": { - "foo": "bar", - } - "Plugins": [ - { - "Type": "Volume", - "Name": "local" - }, - { - "Type": "Network", - "Name": "bridge" - } - { - "Type": "Network", - "Name": "null" - } - { - "Type": "Network", - "Name": "overlay" - } - ] - } - }, - "Status": { - "State": "ready" - }, - "ManagerStatus": { - "Leader": true, - "Reachability": "reachable", - "Addr": "172.17.0.2:2377"" - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such node -- **406** – node is not part of a swarm -- **500** – server error - -#### Remove a node - - -`DELETE /nodes/(id or name)` - -Remove a node from the swarm. - -**Example request**: - - DELETE /v1.24/nodes/24ifsmvkjbyhk HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **force** - 1/True/true or 0/False/false, Force remove a node from the swarm. - Default `false`. - -**Status codes**: - -- **200** – no error -- **404** – no such node -- **406** – node is not part of a swarm -- **500** – server error - -#### Update a node - - -`POST /nodes/(id)/update` - -Update a node. - -The payload of the `POST` request is the new `NodeSpec` and -overrides the current `NodeSpec` for the specified node. - -If `Availability` or `Role` are omitted, this returns an -error. Any other field omitted resets the current value to either -an empty value or the default cluster-wide value. - -**Example Request** - - POST /v1.24/nodes/24ifsmvkjbyhk/update?version=8 HTTP/1.1 - Content-Type: application/json - - { - "Availability": "active", - "Name": "node-name", - "Role": "manager", - "Labels": { - "foo": "bar" - } - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **version** – The version number of the node object being updated. This is - required to avoid conflicting writes. - -JSON Parameters: - -- **Annotations** – Optional medata to associate with the node. - - **Name** – User-defined name for the node. - - **Labels** – A map of labels to associate with the node (e.g., - `{"key":"value", "key2":"value2"}`). -- **Role** - Role of the node (worker/manager). -- **Availability** - Availability of the node (active/pause/drain). - - -**Status codes**: - -- **200** – no error -- **404** – no such node -- **406** – node is not part of a swarm -- **500** – server error - -### 3.8 Swarm - -#### Inspect swarm - - -`GET /swarm` - -Inspect swarm - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - { - "CreatedAt" : "2016-08-15T16:00:20.349727406Z", - "Spec" : { - "Dispatcher" : { - "HeartbeatPeriod" : 5000000000 - }, - "Orchestration" : { - "TaskHistoryRetentionLimit" : 10 - }, - "CAConfig" : { - "NodeCertExpiry" : 7776000000000000 - }, - "Raft" : { - "LogEntriesForSlowFollowers" : 500, - "HeartbeatTick" : 1, - "SnapshotInterval" : 10000, - "ElectionTick" : 3 - }, - "TaskDefaults" : {}, - "Name" : "default" - }, - "JoinTokens" : { - "Worker" : "SWMTKN-1-1h8aps2yszaiqmz2l3oc5392pgk8e49qhx2aj3nyv0ui0hez2a-6qmn92w6bu3jdvnglku58u11a", - "Manager" : "SWMTKN-1-1h8aps2yszaiqmz2l3oc5392pgk8e49qhx2aj3nyv0ui0hez2a-8llk83c4wm9lwioey2s316r9l" - }, - "ID" : "70ilmkj2f6sp2137c753w2nmt", - "UpdatedAt" : "2016-08-15T16:32:09.623207604Z", - "Version" : { - "Index" : 51 - } - } - -**Status codes**: - -- **200** - no error -- **406** – node is not part of a swarm -- **500** - sever error - -#### Initialize a new swarm - - -`POST /swarm/init` - -Initialize a new swarm. The body of the HTTP response includes the node ID. - -**Example request**: - - POST /v1.24/swarm/init HTTP/1.1 - Content-Type: application/json - - { - "ListenAddr": "0.0.0.0:2377", - "AdvertiseAddr": "192.168.1.1:2377", - "ForceNewCluster": false, - "Spec": { - "Orchestration": {}, - "Raft": {}, - "Dispatcher": {}, - "CAConfig": {} - } - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 28 - Content-Type: application/json - Date: Thu, 01 Sep 2016 21:49:13 GMT - Server: Docker/1.12.0 (linux) - - "7v2t30z9blmxuhnyo6s4cpenp" - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **406** – node is already part of a swarm -- **500** - server error - -JSON Parameters: - -- **ListenAddr** – Listen address used for inter-manager communication, as well as determining - the networking interface used for the VXLAN Tunnel Endpoint (VTEP). This can either be an - address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port - number, like `eth0:4567`. If the port number is omitted, the default swarm listening port is - used. -- **AdvertiseAddr** – Externally reachable address advertised to other nodes. This can either be - an address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port - number, like `eth0:4567`. If the port number is omitted, the port number from the listen - address is used. If `AdvertiseAddr` is not specified, it will be automatically detected when - possible. -- **ForceNewCluster** – Force creation of a new swarm. -- **Spec** – Configuration settings for the new swarm. - - **Orchestration** – Configuration settings for the orchestration aspects of the swarm. - - **TaskHistoryRetentionLimit** – Maximum number of tasks history stored. - - **Raft** – Raft related configuration. - - **SnapshotInterval** – Number of logs entries between snapshot. - - **KeepOldSnapshots** – Number of snapshots to keep beyond the current snapshot. - - **LogEntriesForSlowFollowers** – Number of log entries to keep around to sync up slow - followers after a snapshot is created. - - **HeartbeatTick** – Amount of ticks (in seconds) between each heartbeat. - - **ElectionTick** – Amount of ticks (in seconds) needed without a leader to trigger a new - election. - - **Dispatcher** – Configuration settings for the task dispatcher. - - **HeartbeatPeriod** – The delay for an agent to send a heartbeat to the dispatcher. - - **CAConfig** – Certificate authority configuration. - - **NodeCertExpiry** – Automatic expiry for nodes certificates. - - **ExternalCA** - Configuration for forwarding signing requests to an external - certificate authority. - - **Protocol** - Protocol for communication with the external CA - (currently only "cfssl" is supported). - - **URL** - URL where certificate signing requests should be sent. - - **Options** - An object with key/value pairs that are interpreted - as protocol-specific options for the external CA driver. - -#### Join an existing swarm - -`POST /swarm/join` - -Join an existing swarm - -**Example request**: - - POST /v1.24/swarm/join HTTP/1.1 - Content-Type: application/json - - { - "ListenAddr": "0.0.0.0:2377", - "AdvertiseAddr": "192.168.1.1:2377", - "RemoteAddrs": ["node1:2377"], - "JoinToken": "SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2" - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **406** – node is already part of a swarm -- **500** - server error - -JSON Parameters: - -- **ListenAddr** – Listen address used for inter-manager communication if the node gets promoted to - manager, as well as determining the networking interface used for the VXLAN Tunnel Endpoint (VTEP). -- **AdvertiseAddr** – Externally reachable address advertised to other nodes. This can either be - an address/port combination in the form `192.168.1.1:4567`, or an interface followed by a port - number, like `eth0:4567`. If the port number is omitted, the port number from the listen - address is used. If `AdvertiseAddr` is not specified, it will be automatically detected when - possible. -- **RemoteAddr** – Address of any manager node already participating in the swarm. -- **JoinToken** – Secret token for joining this swarm. - -#### Leave a swarm - - -`POST /swarm/leave` - -Leave a swarm - -**Example request**: - - POST /v1.24/swarm/leave HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **force** - Boolean (0/1, false/true). Force leave swarm, even if this is the last manager or that it will break the cluster. - -**Status codes**: - -- **200** – no error -- **406** – node is not part of a swarm -- **500** - server error - -#### Update a swarm - - -`POST /swarm/update` - -Update a swarm - -**Example request**: - - POST /v1.24/swarm/update HTTP/1.1 - - { - "Name": "default", - "Orchestration": { - "TaskHistoryRetentionLimit": 10 - }, - "Raft": { - "SnapshotInterval": 10000, - "LogEntriesForSlowFollowers": 500, - "HeartbeatTick": 1, - "ElectionTick": 3 - }, - "Dispatcher": { - "HeartbeatPeriod": 5000000000 - }, - "CAConfig": { - "NodeCertExpiry": 7776000000000000 - }, - "JoinTokens": { - "Worker": "SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx", - "Manager": "SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2" - } - } - - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Query parameters**: - -- **version** – The version number of the swarm object being updated. This is - required to avoid conflicting writes. -- **rotateWorkerToken** - Set to `true` (or `1`) to rotate the worker join token. -- **rotateManagerToken** - Set to `true` (or `1`) to rotate the manager join token. - -**Status codes**: - -- **200** – no error -- **400** – bad parameter -- **406** – node is not part of a swarm -- **500** - server error - -JSON Parameters: - -- **Orchestration** – Configuration settings for the orchestration aspects of the swarm. - - **TaskHistoryRetentionLimit** – Maximum number of tasks history stored. -- **Raft** – Raft related configuration. - - **SnapshotInterval** – Number of logs entries between snapshot. - - **KeepOldSnapshots** – Number of snapshots to keep beyond the current snapshot. - - **LogEntriesForSlowFollowers** – Number of log entries to keep around to sync up slow - followers after a snapshot is created. - - **HeartbeatTick** – Amount of ticks (in seconds) between each heartbeat. - - **ElectionTick** – Amount of ticks (in seconds) needed without a leader to trigger a new - election. -- **Dispatcher** – Configuration settings for the task dispatcher. - - **HeartbeatPeriod** – The delay for an agent to send a heartbeat to the dispatcher. -- **CAConfig** – CA configuration. - - **NodeCertExpiry** – Automatic expiry for nodes certificates. - - **ExternalCA** - Configuration for forwarding signing requests to an external - certificate authority. - - **Protocol** - Protocol for communication with the external CA - (currently only "cfssl" is supported). - - **URL** - URL where certificate signing requests should be sent. - - **Options** - An object with key/value pairs that are interpreted - as protocol-specific options for the external CA driver. -- **JoinTokens** - Tokens that can be used by other nodes to join the swarm. - - **Worker** - Token to use for joining as a worker. - - **Manager** - Token to use for joining as a manager. - -### 3.9 Services - -**Note**: Service operations require to first be part of a swarm. - -#### List services - - -`GET /services` - -List services - -**Example request**: - - GET /v1.24/services HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Type: application/json - - [ - { - "ID": "9mnpnzenvg8p8tdbtq4wvbkcz", - "Version": { - "Index": 19 - }, - "CreatedAt": "2016-06-07T21:05:51.880065305Z", - "UpdatedAt": "2016-06-07T21:07:29.962229872Z", - "Spec": { - "Name": "hopeful_cori", - "TaskTemplate": { - "ContainerSpec": { - "Image": "redis" - }, - "Resources": { - "Limits": {}, - "Reservations": {} - }, - "RestartPolicy": { - "Condition": "any", - "MaxAttempts": 0 - }, - "Placement": { - "Constraints": [ - "node.role == worker" - ] - } - }, - "Mode": { - "Replicated": { - "Replicas": 1 - } - }, - "UpdateConfig": { - "Parallelism": 1, - "FailureAction": "pause" - }, - "EndpointSpec": { - "Mode": "vip", - "Ports": [ - { - "Protocol": "tcp", - "TargetPort": 6379, - "PublishedPort": 30001 - } - ] - } - }, - "Endpoint": { - "Spec": { - "Mode": "vip", - "Ports": [ - { - "Protocol": "tcp", - "TargetPort": 6379, - "PublishedPort": 30001 - } - ] - }, - "Ports": [ - { - "Protocol": "tcp", - "TargetPort": 6379, - "PublishedPort": 30001 - } - ], - "VirtualIPs": [ - { - "NetworkID": "4qvuz4ko70xaltuqbt8956gd1", - "Addr": "10.255.0.2/16" - }, - { - "NetworkID": "4qvuz4ko70xaltuqbt8956gd1", - "Addr": "10.255.0.3/16" - } - ] - } - } - ] - -**Query parameters**: - -- **filters** – a JSON encoded value of the filters (a `map[string][]string`) to process on the - services list. Available filters: - - `id=` - - `label=` - - `name=` - -**Status codes**: - -- **200** – no error -- **406** – node is not part of a swarm -- **500** – server error - -#### Create a service - -`POST /services/create` - -Create a service. When using this endpoint to create a service using a private -repository from the registry, the `X-Registry-Auth` header must be used to -include a base64-encoded AuthConfig object. Refer to the [create an -image](#create-an-image) section for more details. - -**Example request**: - - POST /v1.24/services/create HTTP/1.1 - Content-Type: application/json - - { - "Name": "web", - "TaskTemplate": { - "ContainerSpec": { - "Image": "nginx:alpine", - "Mounts": [ - { - "ReadOnly": true, - "Source": "web-data", - "Target": "/usr/share/nginx/html", - "Type": "volume", - "VolumeOptions": { - "DriverConfig": { - }, - "Labels": { - "com.example.something": "something-value" - } - } - } - ], - "User": "33" - }, - "Networks": [ - { - "Target": "overlay1" - } - ], - "LogDriver": { - "Name": "json-file", - "Options": { - "max-file": "3", - "max-size": "10M" - } - }, - "Placement": { - "Constraints": [ - "node.role == worker" - ] - }, - "Resources": { - "Limits": { - "MemoryBytes": 104857600 - }, - "Reservations": { - } - }, - "RestartPolicy": { - "Condition": "on-failure", - "Delay": 10000000000, - "MaxAttempts": 10 - } - }, - "Mode": { - "Replicated": { - "Replicas": 4 - } - }, - "UpdateConfig": { - "Delay": 30000000000, - "Parallelism": 2, - "FailureAction": "pause" - }, - "EndpointSpec": { - "Ports": [ - { - "Protocol": "tcp", - "PublishedPort": 8080, - "TargetPort": 80 - } - ] - }, - "Labels": { - "foo": "bar" - } - } - -**Example response**: - - HTTP/1.1 201 Created - Content-Type: application/json - - { - "ID":"ak7w3gjqoa3kuz8xcpnyy0pvl" - } - -**Status codes**: - -- **201** – no error -- **403** - network is not eligible for services -- **406** – node is not part of a swarm -- **409** – name conflicts with an existing object -- **500** - server error - -**JSON Parameters**: - -- **Name** – User-defined name for the service. -- **Labels** – A map of labels to associate with the service (e.g., `{"key":"value", "key2":"value2"}`). -- **TaskTemplate** – Specification of the tasks to start as part of the new service. - - **ContainerSpec** - Container settings for containers started as part of this task. - - **Image** – A string specifying the image name to use for the container. - - **Command** – The command to be run in the image. - - **Args** – Arguments to the command. - - **Env** – A list of environment variables in the form of `["VAR=value"[,"VAR2=value2"]]`. - - **Dir** – A string specifying the working directory for commands to run in. - - **User** – A string value specifying the user inside the container. - - **Labels** – A map of labels to associate with the service (e.g., - `{"key":"value", "key2":"value2"}`). - - **Mounts** – Specification for mounts to be added to containers - created as part of the service. - - **Target** – Container path. - - **Source** – Mount source (e.g. a volume name, a host path). - - **Type** – The mount type (`bind`, or `volume`). - - **ReadOnly** – A boolean indicating whether the mount should be read-only. - - **BindOptions** - Optional configuration for the `bind` type. - - **Propagation** – A propagation mode with the value `[r]private`, `[r]shared`, or `[r]slave`. - - **VolumeOptions** – Optional configuration for the `volume` type. - - **NoCopy** – A boolean indicating if volume should be - populated with the data from the target. (Default false) - - **Labels** – User-defined name and labels for the volume. - - **DriverConfig** – Map of driver-specific options. - - **Name** - Name of the driver to use to create the volume. - - **Options** - key/value map of driver specific options. - - **StopGracePeriod** – Amount of time to wait for the container to terminate before - forcefully killing it. - - **LogDriver** - Log configuration for containers created as part of the - service. - - **Name** - Name of the logging driver to use (`json-file`, `syslog`, - `journald`, `gelf`, `fluentd`, `awslogs`, `splunk`, `etwlogs`, `none`). - - **Options** - Driver-specific options. - - **Resources** – Resource requirements which apply to each individual container created as part - of the service. - - **Limits** – Define resources limits. - - **NanoCPUs** – CPU limit in units of 10-9 CPU shares. - - **MemoryBytes** – Memory limit in Bytes. - - **Reservation** – Define resources reservation. - - **NanoCPUs** – CPU reservation in units of 10-9 CPU shares. - - **MemoryBytes** – Memory reservation in Bytes. - - **RestartPolicy** – Specification for the restart policy which applies to containers created - as part of this service. - - **Condition** – Condition for restart (`none`, `on-failure`, or `any`). - - **Delay** – Delay between restart attempts. - - **Attempts** – Maximum attempts to restart a given container before giving up (default value - is 0, which is ignored). - - **Window** – Windows is the time window used to evaluate the restart policy (default value is - 0, which is unbounded). - - **Placement** – Restrictions on where a service can run. - - **Constraints** – An array of constraints, e.g. `[ "node.role == manager" ]`. -- **Mode** – Scheduling mode for the service (`replicated` or `global`, defaults to `replicated`). -- **UpdateConfig** – Specification for the update strategy of the service. - - **Parallelism** – Maximum number of tasks to be updated in one iteration (0 means unlimited - parallelism). - - **Delay** – Amount of time between updates. - - **FailureAction** - Action to take if an updated task fails to run, or stops running during the - update. Values are `continue` and `pause`. -- **Networks** – Array of network names or IDs to attach the service to. -- **EndpointSpec** – Properties that can be configured to access and load balance a service. - - **Mode** – The mode of resolution to use for internal load balancing - between tasks (`vip` or `dnsrr`). Defaults to `vip` if not provided. - - **Ports** – List of exposed ports that this service is accessible on from - the outside, in the form of: - `{"Protocol": <"tcp"|"udp">, "PublishedPort": , "TargetPort": }`. - Ports can only be provided if `vip` resolution mode is used. - -**Request Headers**: - -- **Content-type** – Set to `"application/json"`. -- **X-Registry-Auth** – base64-encoded AuthConfig object, containing either - login information, or a token. Refer to the [create an image](#create-an-image) - section for more details. - - -#### Remove a service - - -`DELETE /services/(id or name)` - -Stop and remove the service `id` - -**Example request**: - - DELETE /v1.24/services/16253994b7c4 HTTP/1.1 - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**Status codes**: - -- **200** – no error -- **404** – no such service -- **406** - node is not part of a swarm -- **500** – server error - -#### Inspect one or more services - - -`GET /services/(id or name)` - -Return information on the service `id`. - -**Example request**: - - GET /v1.24/services/1cb4dnqcyx6m66g2t538x3rxha HTTP/1.1 - -**Example response**: - - { - "ID": "ak7w3gjqoa3kuz8xcpnyy0pvl", - "Version": { - "Index": 95 - }, - "CreatedAt": "2016-06-07T21:10:20.269723157Z", - "UpdatedAt": "2016-06-07T21:10:20.276301259Z", - "Spec": { - "Name": "redis", - "TaskTemplate": { - "ContainerSpec": { - "Image": "redis" - }, - "Resources": { - "Limits": {}, - "Reservations": {} - }, - "RestartPolicy": { - "Condition": "any", - "MaxAttempts": 0 - }, - "Placement": {} - }, - "Mode": { - "Replicated": { - "Replicas": 1 - } - }, - "UpdateConfig": { - "Parallelism": 1, - "FailureAction": "pause" - }, - "EndpointSpec": { - "Mode": "vip", - "Ports": [ - { - "Protocol": "tcp", - "TargetPort": 6379, - "PublishedPort": 30001 - } - ] - } - }, - "Endpoint": { - "Spec": { - "Mode": "vip", - "Ports": [ - { - "Protocol": "tcp", - "TargetPort": 6379, - "PublishedPort": 30001 - } - ] - }, - "Ports": [ - { - "Protocol": "tcp", - "TargetPort": 6379, - "PublishedPort": 30001 - } - ], - "VirtualIPs": [ - { - "NetworkID": "4qvuz4ko70xaltuqbt8956gd1", - "Addr": "10.255.0.4/16" - } - ] - } - } - -**Status codes**: - -- **200** – no error -- **404** – no such service -- **406** - node is not part of a swarm -- **500** – server error - -#### Update a service - -`POST /services/(id or name)/update` - -Update a service. When using this endpoint to create a service using a -private repository from the registry, the `X-Registry-Auth` header can be used -to update the authentication information for that is stored for the service. -The header contains a base64-encoded AuthConfig object. Refer to the [create an -image](#create-an-image) section for more details. - -**Example request**: - - POST /v1.24/services/1cb4dnqcyx6m66g2t538x3rxha/update?version=23 HTTP/1.1 - Content-Type: application/json - - { - "Name": "top", - "TaskTemplate": { - "ContainerSpec": { - "Image": "busybox", - "Args": [ - "top" - ] - }, - "Resources": { - "Limits": {}, - "Reservations": {} - }, - "RestartPolicy": { - "Condition": "any", - "MaxAttempts": 0 - }, - "Placement": {} - }, - "Mode": { - "Replicated": { - "Replicas": 1 - } - }, - "UpdateConfig": { - "Parallelism": 1 - }, - "EndpointSpec": { - "Mode": "vip" - } - } - -**Example response**: - - HTTP/1.1 200 OK - Content-Length: 0 - Content-Type: text/plain; charset=utf-8 - -**JSON Parameters**: - -- **Name** – User-defined name for the service. Note that renaming services is not supported. -- **Labels** – A map of labels to associate with the service (e.g., `{"key":"value", "key2":"value2"}`). -- **TaskTemplate** – Specification of the tasks to start as part of the new service. - - **ContainerSpec** - Container settings for containers started as part of this task. - - **Image** – A string specifying the image name to use for the container. - - **Command** – The command to be run in the image. - - **Args** – Arguments to the command. - - **Env** – A list of environment variables in the form of `["VAR=value"[,"VAR2=value2"]]`. - - **Dir** – A string specifying the working directory for commands to run in. - - **User** – A string value specifying the user inside the container. - - **Labels** – A map of labels to associate with the service (e.g., - `{"key":"value", "key2":"value2"}`). - - **Mounts** – Specification for mounts to be added to containers created as part of the new - service. - - **Target** – Container path. - - **Source** – Mount source (e.g. a volume name, a host path). - - **Type** – The mount type (`bind`, or `volume`). - - **ReadOnly** – A boolean indicating whether the mount should be read-only. - - **BindOptions** - Optional configuration for the `bind` type - - **Propagation** – A propagation mode with the value `[r]private`, `[r]shared`, or `[r]slave`. - - **VolumeOptions** – Optional configuration for the `volume` type. - - **NoCopy** – A boolean indicating if volume should be - populated with the data from the target. (Default false) - - **Labels** – User-defined name and labels for the volume. - - **DriverConfig** – Map of driver-specific options. - - **Name** - Name of the driver to use to create the volume - - **Options** - key/value map of driver specific options - - **StopGracePeriod** – Amount of time to wait for the container to terminate before - forcefully killing it. - - **Resources** – Resource requirements which apply to each individual container created as part - of the service. - - **Limits** – Define resources limits. - - **CPU** – CPU limit - - **Memory** – Memory limit - - **Reservation** – Define resources reservation. - - **CPU** – CPU reservation - - **Memory** – Memory reservation - - **RestartPolicy** – Specification for the restart policy which applies to containers created - as part of this service. - - **Condition** – Condition for restart (`none`, `on-failure`, or `any`). - - **Delay** – Delay between restart attempts. - - **MaxAttempts** – Maximum attempts to restart a given container before giving up (default value - is 0, which is ignored). - - **Window** – Windows is the time window used to evaluate the restart policy (default value is - 0, which is unbounded). - - **Placement** – Restrictions on where a service can run. - - **Constraints** – An array of constraints, e.g. `[ "node.role == manager" ]`. -- **Mode** – Scheduling mode for the service (`replicated` or `global`, defaults to `replicated`). -- **UpdateConfig** – Specification for the update strategy of the service. - - **Parallelism** – Maximum number of tasks to be updated in one iteration (0 means unlimited - parallelism). - - **Delay** – Amount of time between updates. -- **Networks** – Array of network names or IDs to attach the service to. -- **EndpointSpec** – Properties that can be configured to access and load balance a service. - - **Mode** – The mode of resolution to use for internal load balancing - between tasks (`vip` or `dnsrr`). Defaults to `vip` if not provided. - - **Ports** – List of exposed ports that this service is accessible on from - the outside, in the form of: - `{"Protocol": <"tcp"|"udp">, "PublishedPort": , "TargetPort": }`. - Ports can only be provided if `vip` resolution mode is used. - -**Query parameters**: - -- **version** – The version number of the service object being updated. This is - required to avoid conflicting writes. - -**Request Headers**: - -- **Content-type** – Set to `"application/json"`. -- **X-Registry-Auth** – base64-encoded AuthConfig object, containing either - login information, or a token. Refer to the [create an image](#create-an-image) - section for more details. - -**Status codes**: - -- **200** – no error -- **404** – no such service -- **406** - node is not part of a swarm -- **500** – server error - -### 3.10 Tasks - -**Note**: Task operations require the engine to be part of a swarm. - -#### List tasks - - -`GET /tasks` - -List tasks - -**Example request**: - - GET /v1.24/tasks HTTP/1.1 - -**Example response**: - - [ - { - "ID": "0kzzo1i0y4jz6027t0k7aezc7", - "Version": { - "Index": 71 - }, - "CreatedAt": "2016-06-07T21:07:31.171892745Z", - "UpdatedAt": "2016-06-07T21:07:31.376370513Z", - "Spec": { - "ContainerSpec": { - "Image": "redis" - }, - "Resources": { - "Limits": {}, - "Reservations": {} - }, - "RestartPolicy": { - "Condition": "any", - "MaxAttempts": 0 - }, - "Placement": {} - }, - "ServiceID": "9mnpnzenvg8p8tdbtq4wvbkcz", - "Slot": 1, - "NodeID": "60gvrl6tm78dmak4yl7srz94v", - "Status": { - "Timestamp": "2016-06-07T21:07:31.290032978Z", - "State": "running", - "Message": "started", - "ContainerStatus": { - "ContainerID": "e5d62702a1b48d01c3e02ca1e0212a250801fa8d67caca0b6f35919ebc12f035", - "PID": 677 - } - }, - "DesiredState": "running", - "NetworksAttachments": [ - { - "Network": { - "ID": "4qvuz4ko70xaltuqbt8956gd1", - "Version": { - "Index": 18 - }, - "CreatedAt": "2016-06-07T20:31:11.912919752Z", - "UpdatedAt": "2016-06-07T21:07:29.955277358Z", - "Spec": { - "Name": "ingress", - "Labels": { - "com.docker.swarm.internal": "true" - }, - "DriverConfiguration": {}, - "IPAMOptions": { - "Driver": {}, - "Configs": [ - { - "Subnet": "10.255.0.0/16", - "Gateway": "10.255.0.1" - } - ] - } - }, - "DriverState": { - "Name": "overlay", - "Options": { - "com.docker.network.driver.overlay.vxlanid_list": "256" - } - }, - "IPAMOptions": { - "Driver": { - "Name": "default" - }, - "Configs": [ - { - "Subnet": "10.255.0.0/16", - "Gateway": "10.255.0.1" - } - ] - } - }, - "Addresses": [ - "10.255.0.10/16" - ] - } - ], - }, - { - "ID": "1yljwbmlr8er2waf8orvqpwms", - "Version": { - "Index": 30 - }, - "CreatedAt": "2016-06-07T21:07:30.019104782Z", - "UpdatedAt": "2016-06-07T21:07:30.231958098Z", - "Name": "hopeful_cori", - "Spec": { - "ContainerSpec": { - "Image": "redis" - }, - "Resources": { - "Limits": {}, - "Reservations": {} - }, - "RestartPolicy": { - "Condition": "any", - "MaxAttempts": 0 - }, - "Placement": {} - }, - "ServiceID": "9mnpnzenvg8p8tdbtq4wvbkcz", - "Slot": 1, - "NodeID": "60gvrl6tm78dmak4yl7srz94v", - "Status": { - "Timestamp": "2016-06-07T21:07:30.202183143Z", - "State": "shutdown", - "Message": "shutdown", - "ContainerStatus": { - "ContainerID": "1cf8d63d18e79668b0004a4be4c6ee58cddfad2dae29506d8781581d0688a213" - } - }, - "DesiredState": "shutdown", - "NetworksAttachments": [ - { - "Network": { - "ID": "4qvuz4ko70xaltuqbt8956gd1", - "Version": { - "Index": 18 - }, - "CreatedAt": "2016-06-07T20:31:11.912919752Z", - "UpdatedAt": "2016-06-07T21:07:29.955277358Z", - "Spec": { - "Name": "ingress", - "Labels": { - "com.docker.swarm.internal": "true" - }, - "DriverConfiguration": {}, - "IPAMOptions": { - "Driver": {}, - "Configs": [ - { - "Subnet": "10.255.0.0/16", - "Gateway": "10.255.0.1" - } - ] - } - }, - "DriverState": { - "Name": "overlay", - "Options": { - "com.docker.network.driver.overlay.vxlanid_list": "256" - } - }, - "IPAMOptions": { - "Driver": { - "Name": "default" - }, - "Configs": [ - { - "Subnet": "10.255.0.0/16", - "Gateway": "10.255.0.1" - } - ] - } - }, - "Addresses": [ - "10.255.0.5/16" - ] - } - ] - } - ] - -**Query parameters**: - -- **filters** – a JSON encoded value of the filters (a `map[string][]string`) to process on the - services list. Available filters: - - `id=` - - `name=` - - `service=` - - `node=` - - `label=key` or `label="key=value"` - - `desired-state=(running | shutdown | accepted)` - -**Status codes**: - -- **200** – no error -- **406** - node is not part of a swarm -- **500** – server error - -#### Inspect a task - - -`GET /tasks/(id)` - -Get details on the task `id` - -**Example request**: - - GET /v1.24/tasks/0kzzo1i0y4jz6027t0k7aezc7 HTTP/1.1 - -**Example response**: - - { - "ID": "0kzzo1i0y4jz6027t0k7aezc7", - "Version": { - "Index": 71 - }, - "CreatedAt": "2016-06-07T21:07:31.171892745Z", - "UpdatedAt": "2016-06-07T21:07:31.376370513Z", - "Spec": { - "ContainerSpec": { - "Image": "redis" - }, - "Resources": { - "Limits": {}, - "Reservations": {} - }, - "RestartPolicy": { - "Condition": "any", - "MaxAttempts": 0 - }, - "Placement": {} - }, - "ServiceID": "9mnpnzenvg8p8tdbtq4wvbkcz", - "Slot": 1, - "NodeID": "60gvrl6tm78dmak4yl7srz94v", - "Status": { - "Timestamp": "2016-06-07T21:07:31.290032978Z", - "State": "running", - "Message": "started", - "ContainerStatus": { - "ContainerID": "e5d62702a1b48d01c3e02ca1e0212a250801fa8d67caca0b6f35919ebc12f035", - "PID": 677 - } - }, - "DesiredState": "running", - "NetworksAttachments": [ - { - "Network": { - "ID": "4qvuz4ko70xaltuqbt8956gd1", - "Version": { - "Index": 18 - }, - "CreatedAt": "2016-06-07T20:31:11.912919752Z", - "UpdatedAt": "2016-06-07T21:07:29.955277358Z", - "Spec": { - "Name": "ingress", - "Labels": { - "com.docker.swarm.internal": "true" - }, - "DriverConfiguration": {}, - "IPAMOptions": { - "Driver": {}, - "Configs": [ - { - "Subnet": "10.255.0.0/16", - "Gateway": "10.255.0.1" - } - ] - } - }, - "DriverState": { - "Name": "overlay", - "Options": { - "com.docker.network.driver.overlay.vxlanid_list": "256" - } - }, - "IPAMOptions": { - "Driver": { - "Name": "default" - }, - "Configs": [ - { - "Subnet": "10.255.0.0/16", - "Gateway": "10.255.0.1" - } - ] - } - }, - "Addresses": [ - "10.255.0.10/16" - ] - } - ] - } - -**Status codes**: - -- **200** – no error -- **404** – unknown task -- **406** - node is not part of a swarm -- **500** – server error - -## 4. Going further - -### 4.1 Inside `docker run` - -As an example, the `docker run` command line makes the following API calls: - -- Create the container - -- If the status code is 404, it means the image doesn't exist: - - Try to pull it. - - Then, retry to create the container. - -- Start the container. - -- If you are not in detached mode: -- Attach to the container, using `logs=1` (to have `stdout` and - `stderr` from the container's start) and `stream=1` - -- If in detached mode or only `stdin` is attached, display the container's id. - -### 4.2 Hijacking - -In this version of the API, `/attach`, uses hijacking to transport `stdin`, -`stdout`, and `stderr` on the same socket. - -To hint potential proxies about connection hijacking, Docker client sends -connection upgrade headers similarly to websocket. - - Upgrade: tcp - Connection: Upgrade - -When Docker daemon detects the `Upgrade` header, it switches its status code -from **200 OK** to **101 UPGRADED** and resends the same headers. - - -### 4.3 CORS Requests - -To set cross origin requests to the Engine API please give values to -`--api-cors-header` when running Docker in daemon mode. Set * (asterisk) allows all, -default or blank means CORS disabled - - $ dockerd -H="192.168.1.9:2375" --api-cors-header="http://foo.bar" diff --git a/vendor/github.com/docker/docker/docs/api/version-history.md b/vendor/github.com/docker/docker/docs/api/version-history.md deleted file mode 100644 index 4363cfb..0000000 --- a/vendor/github.com/docker/docker/docs/api/version-history.md +++ /dev/null @@ -1,249 +0,0 @@ ---- -title: "Engine API version history" -description: "Documentation of changes that have been made to Engine API." -keywords: "API, Docker, rcli, REST, documentation" ---- - - - -## v1.26 API changes - -[Docker Engine API v1.26](https://docs.docker.com/engine/api/v1.26/) documentation - -* `POST /plugins/(plugin name)/upgrade` upgrade a plugin. - -## v1.25 API changes - -[Docker Engine API v1.25](https://docs.docker.com/engine/api/v1.25/) documentation - -* The API version is now required in all API calls. Instead of just requesting, for example, the URL `/containers/json`, you must now request `/v1.25/containers/json`. -* `GET /version` now returns `MinAPIVersion`. -* `POST /build` accepts `networkmode` parameter to specify network used during build. -* `GET /images/(name)/json` now returns `OsVersion` if populated -* `GET /info` now returns `Isolation`. -* `POST /containers/create` now takes `AutoRemove` in HostConfig, to enable auto-removal of the container on daemon side when the container's process exits. -* `GET /containers/json` and `GET /containers/(id or name)/json` now return `"removing"` as a value for the `State.Status` field if the container is being removed. Previously, "exited" was returned as status. -* `GET /containers/json` now accepts `removing` as a valid value for the `status` filter. -* `GET /containers/json` now supports filtering containers by `health` status. -* `DELETE /volumes/(name)` now accepts a `force` query parameter to force removal of volumes that were already removed out of band by the volume driver plugin. -* `POST /containers/create/` and `POST /containers/(name)/update` now validates restart policies. -* `POST /containers/create` now validates IPAMConfig in NetworkingConfig, and returns error for invalid IPv4 and IPv6 addresses (`--ip` and `--ip6` in `docker create/run`). -* `POST /containers/create` now takes a `Mounts` field in `HostConfig` which replaces `Binds`, `Volumes`, and `Tmpfs`. *note*: `Binds`, `Volumes`, and `Tmpfs` are still available and can be combined with `Mounts`. -* `POST /build` now performs a preliminary validation of the `Dockerfile` before starting the build, and returns an error if the syntax is incorrect. Note that this change is _unversioned_ and applied to all API versions. -* `POST /build` accepts `cachefrom` parameter to specify images used for build cache. -* `GET /networks/` endpoint now correctly returns a list of *all* networks, - instead of the default network if a trailing slash is provided, but no `name` - or `id`. -* `DELETE /containers/(name)` endpoint now returns an error of `removal of container name is already in progress` with status code of 400, when container name is in a state of removal in progress. -* `GET /containers/json` now supports a `is-task` filter to filter - containers that are tasks (part of a service in swarm mode). -* `POST /containers/create` now takes `StopTimeout` field. -* `POST /services/create` and `POST /services/(id or name)/update` now accept `Monitor` and `MaxFailureRatio` parameters, which control the response to failures during service updates. -* `POST /services/(id or name)/update` now accepts a `ForceUpdate` parameter inside the `TaskTemplate`, which causes the service to be updated even if there are no changes which would ordinarily trigger an update. -* `POST /services/create` and `POST /services/(id or name)/update` now return a `Warnings` array. -* `GET /networks/(name)` now returns field `Created` in response to show network created time. -* `POST /containers/(id or name)/exec` now accepts an `Env` field, which holds a list of environment variables to be set in the context of the command execution. -* `GET /volumes`, `GET /volumes/(name)`, and `POST /volumes/create` now return the `Options` field which holds the driver specific options to use for when creating the volume. -* `GET /exec/(id)/json` now returns `Pid`, which is the system pid for the exec'd process. -* `POST /containers/prune` prunes stopped containers. -* `POST /images/prune` prunes unused images. -* `POST /volumes/prune` prunes unused volumes. -* `POST /networks/prune` prunes unused networks. -* Every API response now includes a `Docker-Experimental` header specifying if experimental features are enabled (value can be `true` or `false`). -* Every API response now includes a `API-Version` header specifying the default API version of the server. -* The `hostConfig` option now accepts the fields `CpuRealtimePeriod` and `CpuRtRuntime` to allocate cpu runtime to rt tasks when `CONFIG_RT_GROUP_SCHED` is enabled in the kernel. -* The `SecurityOptions` field within the `GET /info` response now includes `userns` if user namespaces are enabled in the daemon. -* `GET /nodes` and `GET /node/(id or name)` now return `Addr` as part of a node's `Status`, which is the address that that node connects to the manager from. -* The `HostConfig` field now includes `NanoCPUs` that represents CPU quota in units of 10-9 CPUs. -* `GET /info` now returns more structured information about security options. -* The `HostConfig` field now includes `CpuCount` that represents the number of CPUs available for execution by the container. Windows daemon only. -* `POST /services/create` and `POST /services/(id or name)/update` now accept the `TTY` parameter, which allocate a pseudo-TTY in container. -* `POST /services/create` and `POST /services/(id or name)/update` now accept the `DNSConfig` parameter, which specifies DNS related configurations in resolver configuration file (resolv.conf) through `Nameservers`, `Search`, and `Options`. -* `GET /networks/(id or name)` now includes IP and name of all peers nodes for swarm mode overlay networks. -* `GET /plugins` list plugins. -* `POST /plugins/pull?name=` pulls a plugin. -* `GET /plugins/(plugin name)` inspect a plugin. -* `POST /plugins/(plugin name)/set` configure a plugin. -* `POST /plugins/(plugin name)/enable` enable a plugin. -* `POST /plugins/(plugin name)/disable` disable a plugin. -* `POST /plugins/(plugin name)/push` push a plugin. -* `POST /plugins/create?name=(plugin name)` create a plugin. -* `DELETE /plugins/(plugin name)` delete a plugin. -* `POST /node/(id or name)/update` now accepts both `id` or `name` to identify the node to update. -* `GET /images/json` now support a `reference` filter. -* `GET /secrets` returns information on the secrets. -* `POST /secrets/create` creates a secret. -* `DELETE /secrets/{id}` removes the secret `id`. -* `GET /secrets/{id}` returns information on the secret `id`. -* `POST /secrets/{id}/update` updates the secret `id`. - -## v1.24 API changes - -[Docker Engine API v1.24](v1.24.md) documentation - -* `POST /containers/create` now takes `StorageOpt` field. -* `GET /info` now returns `SecurityOptions` field, showing if `apparmor`, `seccomp`, or `selinux` is supported. -* `GET /info` no longer returns the `ExecutionDriver` property. This property was no longer used after integration - with ContainerD in Docker 1.11. -* `GET /networks` now supports filtering by `label` and `driver`. -* `GET /containers/json` now supports filtering containers by `network` name or id. -* `POST /containers/create` now takes `IOMaximumBandwidth` and `IOMaximumIOps` fields. Windows daemon only. -* `POST /containers/create` now returns an HTTP 400 "bad parameter" message - if no command is specified (instead of an HTTP 500 "server error") -* `GET /images/search` now takes a `filters` query parameter. -* `GET /events` now supports a `reload` event that is emitted when the daemon configuration is reloaded. -* `GET /events` now supports filtering by daemon name or ID. -* `GET /events` now supports a `detach` event that is emitted on detaching from container process. -* `GET /events` now supports an `exec_detach ` event that is emitted on detaching from exec process. -* `GET /images/json` now supports filters `since` and `before`. -* `POST /containers/(id or name)/start` no longer accepts a `HostConfig`. -* `POST /images/(name)/tag` no longer has a `force` query parameter. -* `GET /images/search` now supports maximum returned search results `limit`. -* `POST /containers/{name:.*}/copy` is now removed and errors out starting from this API version. -* API errors are now returned as JSON instead of plain text. -* `POST /containers/create` and `POST /containers/(id)/start` allow you to configure kernel parameters (sysctls) for use in the container. -* `POST /containers//exec` and `POST /exec//start` - no longer expects a "Container" field to be present. This property was not used - and is no longer sent by the docker client. -* `POST /containers/create/` now validates the hostname (should be a valid RFC 1123 hostname). -* `POST /containers/create/` `HostConfig.PidMode` field now accepts `container:`, - to have the container join the PID namespace of an existing container. - -## v1.23 API changes - -[Docker Engine API v1.23](v1.23.md) documentation - -* `GET /containers/json` returns the state of the container, one of `created`, `restarting`, `running`, `paused`, `exited` or `dead`. -* `GET /containers/json` returns the mount points for the container. -* `GET /networks/(name)` now returns an `Internal` field showing whether the network is internal or not. -* `GET /networks/(name)` now returns an `EnableIPv6` field showing whether the network has ipv6 enabled or not. -* `POST /containers/(name)/update` now supports updating container's restart policy. -* `POST /networks/create` now supports enabling ipv6 on the network by setting the `EnableIPv6` field (doing this with a label will no longer work). -* `GET /info` now returns `CgroupDriver` field showing what cgroup driver the daemon is using; `cgroupfs` or `systemd`. -* `GET /info` now returns `KernelMemory` field, showing if "kernel memory limit" is supported. -* `POST /containers/create` now takes `PidsLimit` field, if the kernel is >= 4.3 and the pids cgroup is supported. -* `GET /containers/(id or name)/stats` now returns `pids_stats`, if the kernel is >= 4.3 and the pids cgroup is supported. -* `POST /containers/create` now allows you to override usernamespaces remapping and use privileged options for the container. -* `POST /containers/create` now allows specifying `nocopy` for named volumes, which disables automatic copying from the container path to the volume. -* `POST /auth` now returns an `IdentityToken` when supported by a registry. -* `POST /containers/create` with both `Hostname` and `Domainname` fields specified will result in the container's hostname being set to `Hostname`, rather than `Hostname.Domainname`. -* `GET /volumes` now supports more filters, new added filters are `name` and `driver`. -* `GET /containers/(id or name)/logs` now accepts a `details` query parameter to stream the extra attributes that were provided to the containers `LogOpts`, such as environment variables and labels, with the logs. -* `POST /images/load` now returns progress information as a JSON stream, and has a `quiet` query parameter to suppress progress details. - -## v1.22 API changes - -[Docker Engine API v1.22](v1.22.md) documentation - -* `POST /container/(name)/update` updates the resources of a container. -* `GET /containers/json` supports filter `isolation` on Windows. -* `GET /containers/json` now returns the list of networks of containers. -* `GET /info` Now returns `Architecture` and `OSType` fields, providing information - about the host architecture and operating system type that the daemon runs on. -* `GET /networks/(name)` now returns a `Name` field for each container attached to the network. -* `GET /version` now returns the `BuildTime` field in RFC3339Nano format to make it - consistent with other date/time values returned by the API. -* `AuthConfig` now supports a `registrytoken` for token based authentication -* `POST /containers/create` now has a 4M minimum value limit for `HostConfig.KernelMemory` -* Pushes initiated with `POST /images/(name)/push` and pulls initiated with `POST /images/create` - will be cancelled if the HTTP connection making the API request is closed before - the push or pull completes. -* `POST /containers/create` now allows you to set a read/write rate limit for a - device (in bytes per second or IO per second). -* `GET /networks` now supports filtering by `name`, `id` and `type`. -* `POST /containers/create` now allows you to set the static IPv4 and/or IPv6 address for the container. -* `POST /networks/(id)/connect` now allows you to set the static IPv4 and/or IPv6 address for the container. -* `GET /info` now includes the number of containers running, stopped, and paused. -* `POST /networks/create` now supports restricting external access to the network by setting the `Internal` field. -* `POST /networks/(id)/disconnect` now includes a `Force` option to forcefully disconnect a container from network -* `GET /containers/(id)/json` now returns the `NetworkID` of containers. -* `POST /networks/create` Now supports an options field in the IPAM config that provides options - for custom IPAM plugins. -* `GET /networks/{network-id}` Now returns IPAM config options for custom IPAM plugins if any - are available. -* `GET /networks/` now returns subnets info for user-defined networks. -* `GET /info` can now return a `SystemStatus` field useful for returning additional information about applications - that are built on top of engine. - -## v1.21 API changes - -[Docker Engine API v1.21](v1.21.md) documentation - -* `GET /volumes` lists volumes from all volume drivers. -* `POST /volumes/create` to create a volume. -* `GET /volumes/(name)` get low-level information about a volume. -* `DELETE /volumes/(name)` remove a volume with the specified name. -* `VolumeDriver` was moved from `config` to `HostConfig` to make the configuration portable. -* `GET /images/(name)/json` now returns information about an image's `RepoTags` and `RepoDigests`. -* The `config` option now accepts the field `StopSignal`, which specifies the signal to use to kill a container. -* `GET /containers/(id)/stats` will return networking information respectively for each interface. -* The `HostConfig` option now includes the `DnsOptions` field to configure the container's DNS options. -* `POST /build` now optionally takes a serialized map of build-time variables. -* `GET /events` now includes a `timenano` field, in addition to the existing `time` field. -* `GET /events` now supports filtering by image and container labels. -* `GET /info` now lists engine version information and return the information of `CPUShares` and `Cpuset`. -* `GET /containers/json` will return `ImageID` of the image used by container. -* `POST /exec/(name)/start` will now return an HTTP 409 when the container is either stopped or paused. -* `POST /containers/create` now takes `KernelMemory` in HostConfig to specify kernel memory limit. -* `GET /containers/(name)/json` now accepts a `size` parameter. Setting this parameter to '1' returns container size information in the `SizeRw` and `SizeRootFs` fields. -* `GET /containers/(name)/json` now returns a `NetworkSettings.Networks` field, - detailing network settings per network. This field deprecates the - `NetworkSettings.Gateway`, `NetworkSettings.IPAddress`, - `NetworkSettings.IPPrefixLen`, and `NetworkSettings.MacAddress` fields, which - are still returned for backward-compatibility, but will be removed in a future version. -* `GET /exec/(id)/json` now returns a `NetworkSettings.Networks` field, - detailing networksettings per network. This field deprecates the - `NetworkSettings.Gateway`, `NetworkSettings.IPAddress`, - `NetworkSettings.IPPrefixLen`, and `NetworkSettings.MacAddress` fields, which - are still returned for backward-compatibility, but will be removed in a future version. -* The `HostConfig` option now includes the `OomScoreAdj` field for adjusting the - badness heuristic. This heuristic selects which processes the OOM killer kills - under out-of-memory conditions. - -## v1.20 API changes - -[Docker Engine API v1.20](v1.20.md) documentation - -* `GET /containers/(id)/archive` get an archive of filesystem content from a container. -* `PUT /containers/(id)/archive` upload an archive of content to be extracted to -an existing directory inside a container's filesystem. -* `POST /containers/(id)/copy` is deprecated in favor of the above `archive` -endpoint which can be used to download files and directories from a container. -* The `hostConfig` option now accepts the field `GroupAdd`, which specifies a -list of additional groups that the container process will run as. - -## v1.19 API changes - -[Docker Engine API v1.19](v1.19.md) documentation - -* When the daemon detects a version mismatch with the client, usually when -the client is newer than the daemon, an HTTP 400 is now returned instead -of a 404. -* `GET /containers/(id)/stats` now accepts `stream` bool to get only one set of stats and disconnect. -* `GET /containers/(id)/logs` now accepts a `since` timestamp parameter. -* `GET /info` The fields `Debug`, `IPv4Forwarding`, `MemoryLimit`, and -`SwapLimit` are now returned as boolean instead of as an int. In addition, the -end point now returns the new boolean fields `CpuCfsPeriod`, `CpuCfsQuota`, and -`OomKillDisable`. -* The `hostConfig` option now accepts the fields `CpuPeriod` and `CpuQuota` -* `POST /build` accepts `cpuperiod` and `cpuquota` options - -## v1.18 API changes - -[Docker Engine API v1.18](v1.18.md) documentation - -* `GET /version` now returns `Os`, `Arch` and `KernelVersion`. -* `POST /containers/create` and `POST /containers/(id)/start`allow you to set ulimit settings for use in the container. -* `GET /info` now returns `SystemTime`, `HttpProxy`,`HttpsProxy` and `NoProxy`. -* `GET /images/json` added a `RepoDigests` field to include image digest information. -* `POST /build` can now set resource constraints for all containers created for the build. -* `CgroupParent` can be passed in the host config to setup container cgroups under a specific cgroup. -* `POST /build` closing the HTTP request cancels the build -* `POST /containers/(id)/exec` includes `Warnings` field to response. diff --git a/vendor/github.com/docker/docker/docs/deprecated.md b/vendor/github.com/docker/docker/docs/deprecated.md deleted file mode 100644 index 1298370..0000000 --- a/vendor/github.com/docker/docker/docs/deprecated.md +++ /dev/null @@ -1,286 +0,0 @@ ---- -aliases: ["/engine/misc/deprecated/"] -title: "Deprecated Engine Features" -description: "Deprecated Features." -keywords: "docker, documentation, about, technology, deprecate" ---- - - - -# Deprecated Engine Features - -The following list of features are deprecated in Engine. -To learn more about Docker Engine's deprecation policy, -see [Feature Deprecation Policy](https://docs.docker.com/engine/#feature-deprecation-policy). - - -### Top-level network properties in NetworkSettings - -**Deprecated In Release: v1.13.0** - -**Target For Removal In Release: v1.16** - -When inspecting a container, `NetworkSettings` contains top-level information -about the default ("bridge") network; - -`EndpointID`, `Gateway`, `GlobalIPv6Address`, `GlobalIPv6PrefixLen`, `IPAddress`, -`IPPrefixLen`, `IPv6Gateway`, and `MacAddress`. - -These properties are deprecated in favor of per-network properties in -`NetworkSettings.Networks`. These properties were already "deprecated" in -docker 1.9, but kept around for backward compatibility. - -Refer to [#17538](https://github.com/docker/docker/pull/17538) for further -information. - -## `filter` param for `/images/json` endpoint -**Deprecated In Release: [v1.13.0](https://github.com/docker/docker/releases/tag/v1.13.0)** - -**Target For Removal In Release: v1.16** - -The `filter` param to filter the list of image by reference (name or name:tag) is now implemented as a regular filter, named `reference`. - -### `repository:shortid` image references -**Deprecated In Release: [v1.13.0](https://github.com/docker/docker/releases/tag/v1.13.0)** - -**Target For Removal In Release: v1.16** - -`repository:shortid` syntax for referencing images is very little used, collides with tag references can be confused with digest references. - -### `docker daemon` subcommand -**Deprecated In Release: [v1.13.0](https://github.com/docker/docker/releases/tag/v1.13.0)** - -**Target For Removal In Release: v1.16** - -The daemon is moved to a separate binary (`dockerd`), and should be used instead. - -### Duplicate keys with conflicting values in engine labels -**Deprecated In Release: [v1.13.0](https://github.com/docker/docker/releases/tag/v1.13.0)** - -**Target For Removal In Release: v1.16** - -Duplicate keys with conflicting values have been deprecated. A warning is displayed -in the output, and an error will be returned in the future. - -### `MAINTAINER` in Dockerfile -**Deprecated In Release: [v1.13.0](https://github.com/docker/docker/releases/tag/v1.13.0)** - -`MAINTAINER` was an early very limited form of `LABEL` which should be used instead. - -### API calls without a version -**Deprecated In Release: [v1.13.0](https://github.com/docker/docker/releases/tag/v1.13.0)** - -**Target For Removal In Release: v1.16** - -API versions should be supplied to all API calls to ensure compatibility with -future Engine versions. Instead of just requesting, for example, the URL -`/containers/json`, you must now request `/v1.25/containers/json`. - -### Backing filesystem without `d_type` support for overlay/overlay2 -**Deprecated In Release: [v1.13.0](https://github.com/docker/docker/releases/tag/v1.13.0)** - -**Target For Removal In Release: v1.16** - -The overlay and overlay2 storage driver does not work as expected if the backing -filesystem does not support `d_type`. For example, XFS does not support `d_type` -if it is formatted with the `ftype=0` option. - -Please also refer to [#27358](https://github.com/docker/docker/issues/27358) for -further information. - -### Three arguments form in `docker import` -**Deprecated In Release: [v0.6.7](https://github.com/docker/docker/releases/tag/v0.6.7)** - -**Removed In Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)** - -The `docker import` command format `file|URL|- [REPOSITORY [TAG]]` is deprecated since November 2013. It's no more supported. - -### `-h` shorthand for `--help` - -**Deprecated In Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)** - -**Target For Removal In Release: v1.15** - -The shorthand (`-h`) is less common than `--help` on Linux and cannot be used -on all subcommands (due to it conflicting with, e.g. `-h` / `--hostname` on -`docker create`). For this reason, the `-h` shorthand was not printed in the -"usage" output of subcommands, nor documented, and is now marked "deprecated". - -### `-e` and `--email` flags on `docker login` -**Deprecated In Release: [v1.11.0](https://github.com/docker/docker/releases/tag/v1.11.0)** - -**Target For Removal In Release: v1.14** - -The docker login command is removing the ability to automatically register for an account with the target registry if the given username doesn't exist. Due to this change, the email flag is no longer required, and will be deprecated. - -### Separator (`:`) of `--security-opt` flag on `docker run` -**Deprecated In Release: [v1.11.0](https://github.com/docker/docker/releases/tag/v1.11.0)** - -**Target For Removal In Release: v1.14** - -The flag `--security-opt` doesn't use the colon separator(`:`) anymore to divide keys and values, it uses the equal symbol(`=`) for consistency with other similar flags, like `--storage-opt`. - -### `/containers/(id or name)/copy` endpoint - -**Deprecated In Release: [v1.8.0](https://github.com/docker/docker/releases/tag/v1.8.0)** - -**Removed In Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)** - -The endpoint `/containers/(id or name)/copy` is deprecated in favor of `/containers/(id or name)/archive`. - -### Ambiguous event fields in API -**Deprecated In Release: [v1.10.0](https://github.com/docker/docker/releases/tag/v1.10.0)** - -The fields `ID`, `Status` and `From` in the events API have been deprecated in favor of a more rich structure. -See the events API documentation for the new format. - -### `-f` flag on `docker tag` -**Deprecated In Release: [v1.10.0](https://github.com/docker/docker/releases/tag/v1.10.0)** - -**Removed In Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)** - -To make tagging consistent across the various `docker` commands, the `-f` flag on the `docker tag` command is deprecated. It is not longer necessary to specify `-f` to move a tag from one image to another. Nor will `docker` generate an error if the `-f` flag is missing and the specified tag is already in use. - -### HostConfig at API container start -**Deprecated In Release: [v1.10.0](https://github.com/docker/docker/releases/tag/v1.10.0)** - -**Removed In Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)** - -Passing an `HostConfig` to `POST /containers/{name}/start` is deprecated in favor of -defining it at container creation (`POST /containers/create`). - -### `--before` and `--since` flags on `docker ps` - -**Deprecated In Release: [v1.10.0](https://github.com/docker/docker/releases/tag/v1.10.0)** - -**Removed In Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)** - -The `docker ps --before` and `docker ps --since` options are deprecated. -Use `docker ps --filter=before=...` and `docker ps --filter=since=...` instead. - -### `--automated` and `--stars` flags on `docker search` - -**Deprecated in Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)** - -**Target For Removal In Release: v1.15** - -The `docker search --automated` and `docker search --stars` options are deprecated. -Use `docker search --filter=is-automated=...` and `docker search --filter=stars=...` instead. - -### Driver Specific Log Tags -**Deprecated In Release: [v1.9.0](https://github.com/docker/docker/releases/tag/v1.9.0)** - -**Removed In Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)** - -Log tags are now generated in a standard way across different logging drivers. -Because of which, the driver specific log tag options `syslog-tag`, `gelf-tag` and -`fluentd-tag` have been deprecated in favor of the generic `tag` option. - - docker --log-driver=syslog --log-opt tag="{{.ImageName}}/{{.Name}}/{{.ID}}" - -### LXC built-in exec driver -**Deprecated In Release: [v1.8.0](https://github.com/docker/docker/releases/tag/v1.8.0)** - -**Removed In Release: [v1.10.0](https://github.com/docker/docker/releases/tag/v1.10.0)** - -The built-in LXC execution driver, the lxc-conf flag, and API fields have been removed. - -### Old Command Line Options -**Deprecated In Release: [v1.8.0](https://github.com/docker/docker/releases/tag/v1.8.0)** - -**Removed In Release: [v1.10.0](https://github.com/docker/docker/releases/tag/v1.10.0)** - -The flags `-d` and `--daemon` are deprecated in favor of the `daemon` subcommand: - - docker daemon -H ... - -The following single-dash (`-opt`) variant of certain command line options -are deprecated and replaced with double-dash options (`--opt`): - - docker attach -nostdin - docker attach -sig-proxy - docker build -no-cache - docker build -rm - docker commit -author - docker commit -run - docker events -since - docker history -notrunc - docker images -notrunc - docker inspect -format - docker ps -beforeId - docker ps -notrunc - docker ps -sinceId - docker rm -link - docker run -cidfile - docker run -dns - docker run -entrypoint - docker run -expose - docker run -link - docker run -lxc-conf - docker run -n - docker run -privileged - docker run -volumes-from - docker search -notrunc - docker search -stars - docker search -t - docker search -trusted - docker tag -force - -The following double-dash options are deprecated and have no replacement: - - docker run --cpuset - docker run --networking - docker ps --since-id - docker ps --before-id - docker search --trusted - -**Deprecated In Release: [v1.5.0](https://github.com/docker/docker/releases/tag/v1.5.0)** - -**Removed In Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)** - -The single-dash (`-help`) was removed, in favor of the double-dash `--help` - - docker -help - docker [COMMAND] -help - -### `--run` flag on docker commit - -**Deprecated In Release: [v0.10.0](https://github.com/docker/docker/releases/tag/v0.10.0)** - -**Removed In Release: [v1.13.0](https://github.com/docker/docker/releases/tag/v1.13.0)** - -The flag `--run` of the docker commit (and its short version `-run`) were deprecated in favor -of the `--changes` flag that allows to pass `Dockerfile` commands. - - -### Interacting with V1 registries - -**Disabled By Default In Release: v1.14** - -**Target For Removal In Release: v1.17** - -Version 1.9 adds a flag (`--disable-legacy-registry=false`) which prevents the -docker daemon from `pull`, `push`, and `login` operations against v1 -registries. Though enabled by default, this signals the intent to deprecate -the v1 protocol. - -Support for the v1 protocol to the public registry was removed in 1.13. Any -mirror configurations using v1 should be updated to use a -[v2 registry mirror](https://docs.docker.com/registry/recipes/mirror/). - -### Docker Content Trust ENV passphrase variables name change -**Deprecated In Release: [v1.9.0](https://github.com/docker/docker/releases/tag/v1.9.0)** - -**Removed In Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)** - -Since 1.9, Docker Content Trust Offline key has been renamed to Root key and the Tagging key has been renamed to Repository key. Due to this renaming, we're also changing the corresponding environment variables - -- DOCKER_CONTENT_TRUST_OFFLINE_PASSPHRASE is now named DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE -- DOCKER_CONTENT_TRUST_TAGGING_PASSPHRASE is now named DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE diff --git a/vendor/github.com/docker/docker/docs/extend/EBS_volume.md b/vendor/github.com/docker/docker/docs/extend/EBS_volume.md deleted file mode 100644 index 8c64efa..0000000 --- a/vendor/github.com/docker/docker/docs/extend/EBS_volume.md +++ /dev/null @@ -1,164 +0,0 @@ ---- -description: Volume plugin for Amazon EBS -keywords: "API, Usage, plugins, documentation, developer, amazon, ebs, rexray, volume" -title: Volume plugin for Amazon EBS ---- - - - -# A proof-of-concept Rexray plugin - -In this example, a simple Rexray plugin will be created for the purposes of using -it on an Amazon EC2 instance with EBS. It is not meant to be a complete Rexray plugin. - -The example source is available at [https://github.com/tiborvass/rexray-plugin](https://github.com/tiborvass/rexray-plugin). - -To learn more about Rexray: [https://github.com/codedellemc/rexray](https://github.com/codedellemc/rexray) - -## 1. Make a Docker image - -The following is the Dockerfile used to containerize rexray. - -```Dockerfile -FROM debian:jessie -RUN apt-get update && apt-get install -y --no-install-recommends wget ca-certificates -RUN wget https://dl.bintray.com/emccode/rexray/stable/0.6.4/rexray-Linux-x86_64-0.6.4.tar.gz -O rexray.tar.gz && tar -xvzf rexray.tar.gz -C /usr/bin && rm rexray.tar.gz -RUN mkdir -p /run/docker/plugins /var/lib/libstorage/volumes -ENTRYPOINT ["rexray"] -CMD ["--help"] -``` - -To build it you can run `image=$(cat Dockerfile | docker build -q -)` and `$image` -will reference the containerized rexray image. - -## 2. Extract rootfs - -```sh -$ TMPDIR=/tmp/rexray # for the purpose of this example -$ # create container without running it, to extract the rootfs from image -$ docker create --name rexray "$image" -$ # save the rootfs to a tar archive -$ docker export -o $TMPDIR/rexray.tar rexray -$ # extract rootfs from tar archive to a rootfs folder -$ ( mkdir -p $TMPDIR/rootfs; cd $TMPDIR/rootfs; tar xf ../rexray.tar ) -``` - -## 3. Add plugin configuration - -We have to put the following JSON to `$TMPDIR/config.json`: - -```json -{ - "Args": { - "Description": "", - "Name": "", - "Settable": null, - "Value": null - }, - "Description": "A proof-of-concept EBS plugin (using rexray) for Docker", - "Documentation": "https://github.com/tiborvass/rexray-plugin", - "Entrypoint": [ - "/usr/bin/rexray", "service", "start", "-f" - ], - "Env": [ - { - "Description": "", - "Name": "REXRAY_SERVICE", - "Settable": [ - "value" - ], - "Value": "ebs" - }, - { - "Description": "", - "Name": "EBS_ACCESSKEY", - "Settable": [ - "value" - ], - "Value": "" - }, - { - "Description": "", - "Name": "EBS_SECRETKEY", - "Settable": [ - "value" - ], - "Value": "" - } - ], - "Interface": { - "Socket": "rexray.sock", - "Types": [ - "docker.volumedriver/1.0" - ] - }, - "Linux": { - "AllowAllDevices": true, - "Capabilities": ["CAP_SYS_ADMIN"], - "Devices": null - }, - "Mounts": [ - { - "Source": "/dev", - "Destination": "/dev", - "Type": "bind", - "Options": ["rbind"] - } - ], - "Network": { - "Type": "host" - }, - "PropagatedMount": "/var/lib/libstorage/volumes", - "User": {}, - "WorkDir": "" -} -``` - -Please note a couple of points: -- `PropagatedMount` is needed so that the docker daemon can see mounts done by the -rexray plugin from within the container, otherwise the docker daemon is not able -to mount a docker volume. -- The rexray plugin needs dynamic access to host devices. For that reason, we -have to give it access to all devices under `/dev` and set `AllowAllDevices` to -true for proper access. -- The user of this simple plugin can change only 3 settings: `REXRAY_SERVICE`, -`EBS_ACCESSKEY` and `EBS_SECRETKEY`. This is because of the reduced scope of this -plugin. Ideally other rexray parameters could also be set. - -## 4. Create plugin - -`docker plugin create tiborvass/rexray-plugin "$TMPDIR"` will create the plugin. - -```sh -$ docker plugin ls -ID NAME DESCRIPTION ENABLED -2475a4bd0ca5 tiborvass/rexray-plugin:latest A rexray volume plugin for Docker false -``` - -## 5. Test plugin - -```sh -$ docker plugin set tiborvass/rexray-plugin EBS_ACCESSKEY=$AWS_ACCESSKEY EBS_SECRETKEY=$AWS_SECRETKEY` -$ docker plugin enable tiborvass/rexray-plugin -$ docker volume create -d tiborvass/rexray-plugin my-ebs-volume -$ docker volume ls -DRIVER VOLUME NAME -tiborvass/rexray-plugin:latest my-ebs-volume -$ docker run --rm -v my-ebs-volume:/volume busybox sh -c 'echo bye > /volume/hi' -$ docker run --rm -v my-ebs-volume:/volume busybox cat /volume/hi -bye -``` - -## 6. Push plugin - -First, ensure you are logged in with `docker login`. Then you can run: -`docker plugin push tiborvass/rexray-plugin` to push it like a regular docker -image to a registry, to make it available for others to install via -`docker plugin install tiborvass/rexray-plugin EBS_ACCESSKEY=$AWS_ACCESSKEY EBS_SECRETKEY=$AWS_SECRETKEY`. diff --git a/vendor/github.com/docker/docker/docs/extend/config.md b/vendor/github.com/docker/docker/docs/extend/config.md deleted file mode 100644 index 096d2d0..0000000 --- a/vendor/github.com/docker/docker/docs/extend/config.md +++ /dev/null @@ -1,225 +0,0 @@ ---- -title: "Plugin config" -description: "How develop and use a plugin with the managed plugin system" -keywords: "API, Usage, plugins, documentation, developer" ---- - - - - -# Plugin Config Version 1 of Plugin V2 - -This document outlines the format of the V0 plugin configuration. The plugin -config described herein was introduced in the Docker daemon in the [v1.12.0 -release](https://github.com/docker/docker/commit/f37117045c5398fd3dca8016ea8ca0cb47e7312b). - -Plugin configs describe the various constituents of a docker plugin. Plugin -configs can be serialized to JSON format with the following media types: - -Config Type | Media Type -------------- | ------------- -config | "application/vnd.docker.plugin.v1+json" - - -## *Config* Field Descriptions - -Config provides the base accessible fields for working with V0 plugin format - in the registry. - -- **`description`** *string* - - description of the plugin - -- **`documentation`** *string* - - link to the documentation about the plugin - -- **`interface`** *PluginInterface* - - interface implemented by the plugins, struct consisting of the following fields - - - **`types`** *string array* - - types indicate what interface(s) the plugin currently implements. - - currently supported: - - - **docker.volumedriver/1.0** - - - **docker.authz/1.0** - - - **`socket`** *string* - - socket is the name of the socket the engine should use to communicate with the plugins. - the socket will be created in `/run/docker/plugins`. - - -- **`entrypoint`** *string array* - - entrypoint of the plugin, see [`ENTRYPOINT`](../reference/builder.md#entrypoint) - -- **`workdir`** *string* - - workdir of the plugin, see [`WORKDIR`](../reference/builder.md#workdir) - -- **`network`** *PluginNetwork* - - network of the plugin, struct consisting of the following fields - - - **`type`** *string* - - network type. - - currently supported: - - - **bridge** - - **host** - - **none** - -- **`mounts`** *PluginMount array* - - mount of the plugin, struct consisting of the following fields, see [`MOUNTS`](https://github.com/opencontainers/runtime-spec/blob/master/config.md#mounts) - - - **`name`** *string* - - name of the mount. - - - **`description`** *string* - - description of the mount. - - - **`source`** *string* - - source of the mount. - - - **`destination`** *string* - - destination of the mount. - - - **`type`** *string* - - mount type. - - - **`options`** *string array* - - options of the mount. - -- **`propagatedMount`** *string* - - path to be mounted as rshared, so that mounts under that path are visible to docker. This is useful for volume plugins. - This path will be bind-mounted outisde of the plugin rootfs so it's contents - are preserved on upgrade. - -- **`env`** *PluginEnv array* - - env of the plugin, struct consisting of the following fields - - - **`name`** *string* - - name of the env. - - - **`description`** *string* - - description of the env. - - - **`value`** *string* - - value of the env. - -- **`args`** *PluginArgs* - - args of the plugin, struct consisting of the following fields - - - **`name`** *string* - - name of the args. - - - **`description`** *string* - - description of the args. - - - **`value`** *string array* - - values of the args. - -- **`linux`** *PluginLinux* - - - **`capabilities`** *string array* - - capabilities of the plugin (*Linux only*), see list [`here`](https://github.com/opencontainers/runc/blob/master/libcontainer/SPEC.md#security) - - - **`allowAllDevices`** *boolean* - - If `/dev` is bind mounted from the host, and allowAllDevices is set to true, the plugin will have `rwm` access to all devices on the host. - - - **`devices`** *PluginDevice array* - - device of the plugin, (*Linux only*), struct consisting of the following fields, see [`DEVICES`](https://github.com/opencontainers/runtime-spec/blob/master/config-linux.md#devices) - - - **`name`** *string* - - name of the device. - - - **`description`** *string* - - description of the device. - - - **`path`** *string* - - path of the device. - -## Example Config - -*Example showing the 'tiborvass/sample-volume-plugin' plugin config.* - -```json -{ - "Args": { - "Description": "", - "Name": "", - "Settable": null, - "Value": null - }, - "Description": "A sample volume plugin for Docker", - "Documentation": "https://docs.docker.com/engine/extend/plugins/", - "Entrypoint": [ - "/usr/bin/sample-volume-plugin", - "/data" - ], - "Env": [ - { - "Description": "", - "Name": "DEBUG", - "Settable": [ - "value" - ], - "Value": "0" - } - ], - "Interface": { - "Socket": "plugin.sock", - "Types": [ - "docker.volumedriver/1.0" - ] - }, - "Linux": { - "Capabilities": null, - "AllowAllDevices": false, - "Devices": null - }, - "Mounts": null, - "Network": { - "Type": "" - }, - "PropagatedMount": "/data", - "User": {}, - "Workdir": "" -} -``` diff --git a/vendor/github.com/docker/docker/docs/extend/images/authz_additional_info.png b/vendor/github.com/docker/docker/docs/extend/images/authz_additional_info.png deleted file mode 100644 index 1a6a6d0..0000000 Binary files a/vendor/github.com/docker/docker/docs/extend/images/authz_additional_info.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/docs/extend/images/authz_allow.png b/vendor/github.com/docker/docker/docs/extend/images/authz_allow.png deleted file mode 100644 index f421080..0000000 Binary files a/vendor/github.com/docker/docker/docs/extend/images/authz_allow.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/docs/extend/images/authz_chunked.png b/vendor/github.com/docker/docker/docs/extend/images/authz_chunked.png deleted file mode 100644 index 5bde2c7..0000000 Binary files a/vendor/github.com/docker/docker/docs/extend/images/authz_chunked.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/docs/extend/images/authz_connection_hijack.png b/vendor/github.com/docker/docker/docs/extend/images/authz_connection_hijack.png deleted file mode 100644 index f13a298..0000000 Binary files a/vendor/github.com/docker/docker/docs/extend/images/authz_connection_hijack.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/docs/extend/images/authz_deny.png b/vendor/github.com/docker/docker/docs/extend/images/authz_deny.png deleted file mode 100644 index fa4a485..0000000 Binary files a/vendor/github.com/docker/docker/docs/extend/images/authz_deny.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/docs/extend/index.md b/vendor/github.com/docker/docker/docs/extend/index.md deleted file mode 100644 index 1410b20..0000000 --- a/vendor/github.com/docker/docker/docs/extend/index.md +++ /dev/null @@ -1,222 +0,0 @@ ---- -description: Develop and use a plugin with the managed plugin system -keywords: "API, Usage, plugins, documentation, developer" -title: Managed plugin system ---- - - - -# Docker Engine managed plugin system - -* [Installing and using a plugin](index.md#installing-and-using-a-plugin) -* [Developing a plugin](index.md#developing-a-plugin) - -Docker Engine's plugins system allows you to install, start, stop, and remove -plugins using Docker Engine. This mechanism is currently only available for -volume drivers, but more plugin driver types will be available in future releases. - -For information about the legacy plugin system available in Docker Engine 1.12 -and earlier, see [Understand legacy Docker Engine plugins](legacy_plugins.md). - -> **Note**: Docker Engine managed plugins are currently not supported -on Windows daemons. - -## Installing and using a plugin - -Plugins are distributed as Docker images and can be hosted on Docker Hub or on -a private registry. - -To install a plugin, use the `docker plugin install` command, which pulls the -plugin from Docker hub or your private registry, prompts you to grant -permissions or capabilities if necessary, and enables the plugin. - -To check the status of installed plugins, use the `docker plugin ls` command. -Plugins that start successfully are listed as enabled in the output. - -After a plugin is installed, you can use it as an option for another Docker -operation, such as creating a volume. - -In the following example, you install the `sshfs` plugin, verify that it is -enabled, and use it to create a volume. - -1. Install the `sshfs` plugin. - - ```bash - $ docker plugin install vieux/sshfs - - Plugin "vieux/sshfs" is requesting the following privileges: - - network: [host] - - capabilities: [CAP_SYS_ADMIN] - Do you grant the above permissions? [y/N] y - - vieux/sshfs - ``` - - The plugin requests 2 privileges: - - It needs access to the `host` network. - - It needs the `CAP_SYS_ADMIN` capability, which allows the plugin to run - the `mount` command. - -2. Check that the plugin is enabled in the output of `docker plugin ls`. - - ```bash - $ docker plugin ls - - ID NAME TAG DESCRIPTION ENABLED - 69553ca1d789 vieux/sshfs latest the `sshfs` plugin true - ``` - -3. Create a volume using the plugin. - This example mounts the `/remote` directory on host `1.2.3.4` into a - volume named `sshvolume`. This volume can now be mounted into containers. - - ```bash - $ docker volume create \ - -d vieux/sshfs \ - --name sshvolume \ - -o sshcmd=user@1.2.3.4:/remote - - sshvolume - ``` -4. Verify that the volume was created successfully. - - ```bash - $ docker volume ls - - DRIVER NAME - vieux/sshfs sshvolume - ``` - -5. Start a container that uses the volume `sshvolume`. - - ```bash - $ docker run -v sshvolume:/data busybox ls /data - - - ``` - -To disable a plugin, use the `docker plugin disable` command. To completely -remove it, use the `docker plugin remove` command. For other available -commands and options, see the -[command line reference](../reference/commandline/index.md). - -## Service creation using plugins - -In swarm mode, it is possible to create a service that allows for attaching -to networks or mounting volumes. Swarm schedules services based on plugin availability -on a node. In this example, a volume plugin is installed on a swarm worker and a volume -is created using the plugin. In the manager, a service is created with the relevant -mount options. It can be observed that the service is scheduled to run on the worker -node with the said volume plugin and volume. - -In the following example, node1 is the manager and node2 is the worker. - -1. Prepare manager. In node 1: - - ```bash - $ docker swarm init - Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager. - ``` - -2. Join swarm, install plugin and create volume on worker. In node 2: - - ```bash - $ docker swarm join \ - --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ - 192.168.99.100:2377 - ``` - - ```bash - $ docker plugin install tiborvass/sample-volume-plugin - latest: Pulling from tiborvass/sample-volume-plugin - eb9c16fbdc53: Download complete - Digest: sha256:00b42de88f3a3e0342e7b35fa62394b0a9ceb54d37f4c50be5d3167899994639 - Status: Downloaded newer image for tiborvass/sample-volume-plugin:latest - Installed plugin tiborvass/sample-volume-plugin - ``` - - ```bash - $ docker volume create -d tiborvass/sample-volume-plugin --name pluginVol - ``` - -3. Create a service using the plugin and volume. In node1: - - ```bash - $ docker service create --name my-service --mount type=volume,volume-driver=tiborvass/sample-volume-plugin,source=pluginVol,destination=/tmp busybox top - - $ docker service ls - z1sj8bb8jnfn my-service replicated 1/1 busybox:latest - ``` - docker service ls shows service 1 instance of service running. - -4. Observe the task getting scheduled in node 2: - - ```bash - $ docker ps --format '{{.ID}}\t {{.Status}} {{.Names}} {{.Command}}' - 83fc1e842599 Up 2 days my-service.1.9jn59qzn7nbc3m0zt1hij12xs "top" - ``` - -## Developing a plugin - -#### The rootfs directory -The `rootfs` directory represents the root filesystem of the plugin. In this -example, it was created from a Dockerfile: - ->**Note:** The `/run/docker/plugins` directory is mandatory inside of the -plugin's filesystem for docker to communicate with the plugin. - -```bash -$ git clone https://github.com/vieux/docker-volume-sshfs -$ cd docker-volume-sshfs -$ docker build -t rootfsimage . -$ id=$(docker create rootfsimage true) # id was cd851ce43a403 when the image was created -$ sudo mkdir -p myplugin/rootfs -$ sudo docker export "$id" | sudo tar -x -C myplugin/rootfs -$ docker rm -vf "$id" -$ docker rmi rootfsimage -``` - -#### The config.json file - -The `config.json` file describes the plugin. See the [plugins config reference](config.md). - -Consider the following `config.json` file. - -```json -{ - "description": "sshFS plugin for Docker", - "documentation": "https://docs.docker.com/engine/extend/plugins/", - "entrypoint": ["/go/bin/docker-volume-sshfs"], - "network": { - "type": "host" - }, - "interface" : { - "types": ["docker.volumedriver/1.0"], - "socket": "sshfs.sock" - }, - "capabilities": ["CAP_SYS_ADMIN"] -} -``` - -This plugin is a volume driver. It requires a `host` network and the -`CAP_SYS_ADMIN` capability. It depends upon the `/go/bin/docker-volume-sshfs` -entrypoint and uses the `/run/docker/plugins/sshfs.sock` socket to communicate -with Docker Engine. This plugin has no runtime parameters. - -#### Creating the plugin - -A new plugin can be created by running -`docker plugin create ./path/to/plugin/data` where the plugin -data contains a plugin configuration file `config.json` and a root filesystem -in subdirectory `rootfs`. - -After that the plugin `` will show up in `docker plugin ls`. -Plugins can be pushed to remote registries with -`docker plugin push `. diff --git a/vendor/github.com/docker/docker/docs/extend/legacy_plugins.md b/vendor/github.com/docker/docker/docs/extend/legacy_plugins.md deleted file mode 100644 index 6ac914e..0000000 --- a/vendor/github.com/docker/docker/docs/extend/legacy_plugins.md +++ /dev/null @@ -1,98 +0,0 @@ ---- -redirect_from: -- "/engine/extend/plugins/" -title: "Use Docker Engine plugins" -description: "How to add additional functionality to Docker with plugins extensions" -keywords: "Examples, Usage, plugins, docker, documentation, user guide" ---- - - - -# Use Docker Engine plugins - -This document describes the Docker Engine plugins generally available in Docker -Engine. To view information on plugins managed by Docker, -refer to [Docker Engine plugin system](index.md). - -You can extend the capabilities of the Docker Engine by loading third-party -plugins. This page explains the types of plugins and provides links to several -volume and network plugins for Docker. - -## Types of plugins - -Plugins extend Docker's functionality. They come in specific types. For -example, a [volume plugin](plugins_volume.md) might enable Docker -volumes to persist across multiple Docker hosts and a -[network plugin](plugins_network.md) might provide network plumbing. - -Currently Docker supports authorization, volume and network driver plugins. In the future it -will support additional plugin types. - -## Installing a plugin - -Follow the instructions in the plugin's documentation. - -## Finding a plugin - -The sections below provide an inexhaustive overview of available plugins. - - - -### Network plugins - -Plugin | Description ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -[Contiv Networking](https://github.com/contiv/netplugin) | An open source network plugin to provide infrastructure and security policies for a multi-tenant micro services deployment, while providing an integration to physical network for non-container workload. Contiv Networking implements the remote driver and IPAM APIs available in Docker 1.9 onwards. -[Kuryr Network Plugin](https://github.com/openstack/kuryr) | A network plugin is developed as part of the OpenStack Kuryr project and implements the Docker networking (libnetwork) remote driver API by utilizing Neutron, the OpenStack networking service. It includes an IPAM driver as well. -[Weave Network Plugin](https://www.weave.works/docs/net/latest/introducing-weave/) | A network plugin that creates a virtual network that connects your Docker containers - across multiple hosts or clouds and enables automatic discovery of applications. Weave networks are resilient, partition tolerant, secure and work in partially connected networks, and other adverse environments - all configured with delightful simplicity. - -### Volume plugins - -Plugin | Description ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -[Azure File Storage plugin](https://github.com/Azure/azurefile-dockervolumedriver) | Lets you mount Microsoft [Azure File Storage](https://azure.microsoft.com/blog/azure-file-storage-now-generally-available/) shares to Docker containers as volumes using the SMB 3.0 protocol. [Learn more](https://azure.microsoft.com/blog/persistent-docker-volumes-with-azure-file-storage/). -[Blockbridge plugin](https://github.com/blockbridge/blockbridge-docker-volume) | A volume plugin that provides access to an extensible set of container-based persistent storage options. It supports single and multi-host Docker environments with features that include tenant isolation, automated provisioning, encryption, secure deletion, snapshots and QoS. -[Contiv Volume Plugin](https://github.com/contiv/volplugin) | An open source volume plugin that provides multi-tenant, persistent, distributed storage with intent based consumption. It has support for Ceph and NFS. -[Convoy plugin](https://github.com/rancher/convoy) | A volume plugin for a variety of storage back-ends including device mapper and NFS. It's a simple standalone executable written in Go and provides the framework to support vendor-specific extensions such as snapshots, backups and restore. -[DRBD plugin](https://www.drbd.org/en/supported-projects/docker) | A volume plugin that provides highly available storage replicated by [DRBD](https://www.drbd.org). Data written to the docker volume is replicated in a cluster of DRBD nodes. -[Flocker plugin](https://clusterhq.com/docker-plugin/) | A volume plugin that provides multi-host portable volumes for Docker, enabling you to run databases and other stateful containers and move them around across a cluster of machines. -[gce-docker plugin](https://github.com/mcuadros/gce-docker) | A volume plugin able to attach, format and mount Google Compute [persistent-disks](https://cloud.google.com/compute/docs/disks/persistent-disks). -[GlusterFS plugin](https://github.com/calavera/docker-volume-glusterfs) | A volume plugin that provides multi-host volumes management for Docker using GlusterFS. -[Horcrux Volume Plugin](https://github.com/muthu-r/horcrux) | A volume plugin that allows on-demand, version controlled access to your data. Horcrux is an open-source plugin, written in Go, and supports SCP, [Minio](https://www.minio.io) and Amazon S3. -[HPE 3Par Volume Plugin](https://github.com/hpe-storage/python-hpedockerplugin/) | A volume plugin that supports HPE 3Par and StoreVirtual iSCSI storage arrays. -[IPFS Volume Plugin](http://github.com/vdemeester/docker-volume-ipfs) | An open source volume plugin that allows using an [ipfs](https://ipfs.io/) filesystem as a volume. -[Keywhiz plugin](https://github.com/calavera/docker-volume-keywhiz) | A plugin that provides credentials and secret management using Keywhiz as a central repository. -[Local Persist Plugin](https://github.com/CWSpear/local-persist) | A volume plugin that extends the default `local` driver's functionality by allowing you specify a mountpoint anywhere on the host, which enables the files to *always persist*, even if the volume is removed via `docker volume rm`. -[NetApp Plugin](https://github.com/NetApp/netappdvp) (nDVP) | A volume plugin that provides direct integration with the Docker ecosystem for the NetApp storage portfolio. The nDVP package supports the provisioning and management of storage resources from the storage platform to Docker hosts, with a robust framework for adding additional platforms in the future. -[Netshare plugin](https://github.com/ContainX/docker-volume-netshare) | A volume plugin that provides volume management for NFS 3/4, AWS EFS and CIFS file systems. -[OpenStorage Plugin](https://github.com/libopenstorage/openstorage) | A cluster-aware volume plugin that provides volume management for file and block storage solutions. It implements a vendor neutral specification for implementing extensions such as CoS, encryption, and snapshots. It has example drivers based on FUSE, NFS, NBD and EBS to name a few. -[Portworx Volume Plugin](https://github.com/portworx/px-dev) | A volume plugin that turns any server into a scale-out converged compute/storage node, providing container granular storage and highly available volumes across any node, using a shared-nothing storage backend that works with any docker scheduler. -[Quobyte Volume Plugin](https://github.com/quobyte/docker-volume) | A volume plugin that connects Docker to [Quobyte](http://www.quobyte.com/containers)'s data center file system, a general-purpose scalable and fault-tolerant storage platform. -[REX-Ray plugin](https://github.com/emccode/rexray) | A volume plugin which is written in Go and provides advanced storage functionality for many platforms including VirtualBox, EC2, Google Compute Engine, OpenStack, and EMC. -[Virtuozzo Storage and Ploop plugin](https://github.com/virtuozzo/docker-volume-ploop) | A volume plugin with support for Virtuozzo Storage distributed cloud file system as well as ploop devices. -[VMware vSphere Storage Plugin](https://github.com/vmware/docker-volume-vsphere) | Docker Volume Driver for vSphere enables customers to address persistent storage requirements for Docker containers in vSphere environments. - -### Authorization plugins - - Plugin | Description -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - [Twistlock AuthZ Broker](https://github.com/twistlock/authz) | A basic extendable authorization plugin that runs directly on the host or inside a container. This plugin allows you to define user policies that it evaluates during authorization. Basic authorization is provided if Docker daemon is started with the --tlsverify flag (username is extracted from the certificate common name). - -## Troubleshooting a plugin - -If you are having problems with Docker after loading a plugin, ask the authors -of the plugin for help. The Docker team may not be able to assist you. - -## Writing a plugin - -If you are interested in writing a plugin for Docker, or seeing how they work -under the hood, see the [docker plugins reference](plugin_api.md). diff --git a/vendor/github.com/docker/docker/docs/extend/plugin_api.md b/vendor/github.com/docker/docker/docs/extend/plugin_api.md deleted file mode 100644 index 693b77a..0000000 --- a/vendor/github.com/docker/docker/docs/extend/plugin_api.md +++ /dev/null @@ -1,196 +0,0 @@ ---- -title: "Plugins API" -description: "How to write Docker plugins extensions " -keywords: "API, Usage, plugins, documentation, developer" ---- - - - -# Docker Plugin API - -Docker plugins are out-of-process extensions which add capabilities to the -Docker Engine. - -This document describes the Docker Engine plugin API. To view information on -plugins managed by Docker Engine, refer to [Docker Engine plugin system](index.md). - -This page is intended for people who want to develop their own Docker plugin. -If you just want to learn about or use Docker plugins, look -[here](legacy_plugins.md). - -## What plugins are - -A plugin is a process running on the same or a different host as the docker daemon, -which registers itself by placing a file on the same docker host in one of the plugin -directories described in [Plugin discovery](#plugin-discovery). - -Plugins have human-readable names, which are short, lowercase strings. For -example, `flocker` or `weave`. - -Plugins can run inside or outside containers. Currently running them outside -containers is recommended. - -## Plugin discovery - -Docker discovers plugins by looking for them in the plugin directory whenever a -user or container tries to use one by name. - -There are three types of files which can be put in the plugin directory. - -* `.sock` files are UNIX domain sockets. -* `.spec` files are text files containing a URL, such as `unix:///other.sock` or `tcp://localhost:8080`. -* `.json` files are text files containing a full json specification for the plugin. - -Plugins with UNIX domain socket files must run on the same docker host, whereas -plugins with spec or json files can run on a different host if a remote URL is specified. - -UNIX domain socket files must be located under `/run/docker/plugins`, whereas -spec files can be located either under `/etc/docker/plugins` or `/usr/lib/docker/plugins`. - -The name of the file (excluding the extension) determines the plugin name. - -For example, the `flocker` plugin might create a UNIX socket at -`/run/docker/plugins/flocker.sock`. - -You can define each plugin into a separated subdirectory if you want to isolate definitions from each other. -For example, you can create the `flocker` socket under `/run/docker/plugins/flocker/flocker.sock` and only -mount `/run/docker/plugins/flocker` inside the `flocker` container. - -Docker always searches for unix sockets in `/run/docker/plugins` first. It checks for spec or json files under -`/etc/docker/plugins` and `/usr/lib/docker/plugins` if the socket doesn't exist. The directory scan stops as -soon as it finds the first plugin definition with the given name. - -### JSON specification - -This is the JSON format for a plugin: - -```json -{ - "Name": "plugin-example", - "Addr": "https://example.com/docker/plugin", - "TLSConfig": { - "InsecureSkipVerify": false, - "CAFile": "/usr/shared/docker/certs/example-ca.pem", - "CertFile": "/usr/shared/docker/certs/example-cert.pem", - "KeyFile": "/usr/shared/docker/certs/example-key.pem" - } -} -``` - -The `TLSConfig` field is optional and TLS will only be verified if this configuration is present. - -## Plugin lifecycle - -Plugins should be started before Docker, and stopped after Docker. For -example, when packaging a plugin for a platform which supports `systemd`, you -might use [`systemd` dependencies]( -http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Before=) to -manage startup and shutdown order. - -When upgrading a plugin, you should first stop the Docker daemon, upgrade the -plugin, then start Docker again. - -## Plugin activation - -When a plugin is first referred to -- either by a user referring to it by name -(e.g. `docker run --volume-driver=foo`) or a container already configured to -use a plugin being started -- Docker looks for the named plugin in the plugin -directory and activates it with a handshake. See Handshake API below. - -Plugins are *not* activated automatically at Docker daemon startup. Rather, -they are activated only lazily, or on-demand, when they are needed. - -## Systemd socket activation - -Plugins may also be socket activated by `systemd`. The official [Plugins helpers](https://github.com/docker/go-plugins-helpers) -natively supports socket activation. In order for a plugin to be socket activated it needs -a `service` file and a `socket` file. - -The `service` file (for example `/lib/systemd/system/your-plugin.service`): - -``` -[Unit] -Description=Your plugin -Before=docker.service -After=network.target your-plugin.socket -Requires=your-plugin.socket docker.service - -[Service] -ExecStart=/usr/lib/docker/your-plugin - -[Install] -WantedBy=multi-user.target -``` -The `socket` file (for example `/lib/systemd/system/your-plugin.socket`): - -``` -[Unit] -Description=Your plugin - -[Socket] -ListenStream=/run/docker/plugins/your-plugin.sock - -[Install] -WantedBy=sockets.target -``` - -This will allow plugins to be actually started when the Docker daemon connects to -the sockets they're listening on (for instance the first time the daemon uses them -or if one of the plugin goes down accidentally). - -## API design - -The Plugin API is RPC-style JSON over HTTP, much like webhooks. - -Requests flow *from* the Docker daemon *to* the plugin. So the plugin needs to -implement an HTTP server and bind this to the UNIX socket mentioned in the -"plugin discovery" section. - -All requests are HTTP `POST` requests. - -The API is versioned via an Accept header, which currently is always set to -`application/vnd.docker.plugins.v1+json`. - -## Handshake API - -Plugins are activated via the following "handshake" API call. - -### /Plugin.Activate - -**Request:** empty body - -**Response:** -``` -{ - "Implements": ["VolumeDriver"] -} -``` - -Responds with a list of Docker subsystems which this plugin implements. -After activation, the plugin will then be sent events from this subsystem. - -Possible values are: - -* [`authz`](plugins_authorization.md) -* [`NetworkDriver`](plugins_network.md) -* [`VolumeDriver`](plugins_volume.md) - - -## Plugin retries - -Attempts to call a method on a plugin are retried with an exponential backoff -for up to 30 seconds. This may help when packaging plugins as containers, since -it gives plugin containers a chance to start up before failing any user -containers which depend on them. - -## Plugins helpers - -To ease plugins development, we're providing an `sdk` for each kind of plugins -currently supported by Docker at [docker/go-plugins-helpers](https://github.com/docker/go-plugins-helpers). diff --git a/vendor/github.com/docker/docker/docs/extend/plugins_authorization.md b/vendor/github.com/docker/docker/docs/extend/plugins_authorization.md deleted file mode 100644 index ac1837f..0000000 --- a/vendor/github.com/docker/docker/docs/extend/plugins_authorization.md +++ /dev/null @@ -1,260 +0,0 @@ ---- -title: "Access authorization plugin" -description: "How to create authorization plugins to manage access control to your Docker daemon." -keywords: "security, authorization, authentication, docker, documentation, plugin, extend" -redirect_from: -- "/engine/extend/authorization/" ---- - - - -# Create an authorization plugin - -This document describes the Docker Engine plugins generally available in Docker -Engine. To view information on plugins managed by Docker Engine, -refer to [Docker Engine plugin system](index.md). - -Docker's out-of-the-box authorization model is all or nothing. Any user with -permission to access the Docker daemon can run any Docker client command. The -same is true for callers using Docker's Engine API to contact the daemon. If you -require greater access control, you can create authorization plugins and add -them to your Docker daemon configuration. Using an authorization plugin, a -Docker administrator can configure granular access policies for managing access -to Docker daemon. - -Anyone with the appropriate skills can develop an authorization plugin. These -skills, at their most basic, are knowledge of Docker, understanding of REST, and -sound programming knowledge. This document describes the architecture, state, -and methods information available to an authorization plugin developer. - -## Basic principles - -Docker's [plugin infrastructure](plugin_api.md) enables -extending Docker by loading, removing and communicating with -third-party components using a generic API. The access authorization subsystem -was built using this mechanism. - -Using this subsystem, you don't need to rebuild the Docker daemon to add an -authorization plugin. You can add a plugin to an installed Docker daemon. You do -need to restart the Docker daemon to add a new plugin. - -An authorization plugin approves or denies requests to the Docker daemon based -on both the current authentication context and the command context. The -authentication context contains all user details and the authentication method. -The command context contains all the relevant request data. - -Authorization plugins must follow the rules described in [Docker Plugin API](plugin_api.md). -Each plugin must reside within directories described under the -[Plugin discovery](plugin_api.md#plugin-discovery) section. - -**Note**: the abbreviations `AuthZ` and `AuthN` mean authorization and authentication -respectively. - -## Default user authorization mechanism - -If TLS is enabled in the [Docker daemon](https://docs.docker.com/engine/security/https/), the default user authorization flow extracts the user details from the certificate subject name. -That is, the `User` field is set to the client certificate subject common name, and the `AuthenticationMethod` field is set to `TLS`. - -## Basic architecture - -You are responsible for registering your plugin as part of the Docker daemon -startup. You can install multiple plugins and chain them together. This chain -can be ordered. Each request to the daemon passes in order through the chain. -Only when all the plugins grant access to the resource, is the access granted. - -When an HTTP request is made to the Docker daemon through the CLI or via the -Engine API, the authentication subsystem passes the request to the installed -authentication plugin(s). The request contains the user (caller) and command -context. The plugin is responsible for deciding whether to allow or deny the -request. - -The sequence diagrams below depict an allow and deny authorization flow: - -![Authorization Allow flow](images/authz_allow.png) - -![Authorization Deny flow](images/authz_deny.png) - -Each request sent to the plugin includes the authenticated user, the HTTP -headers, and the request/response body. Only the user name and the -authentication method used are passed to the plugin. Most importantly, no user -credentials or tokens are passed. Finally, not all request/response bodies -are sent to the authorization plugin. Only those request/response bodies where -the `Content-Type` is either `text/*` or `application/json` are sent. - -For commands that can potentially hijack the HTTP connection (`HTTP -Upgrade`), such as `exec`, the authorization plugin is only called for the -initial HTTP requests. Once the plugin approves the command, authorization is -not applied to the rest of the flow. Specifically, the streaming data is not -passed to the authorization plugins. For commands that return chunked HTTP -response, such as `logs` and `events`, only the HTTP request is sent to the -authorization plugins. - -During request/response processing, some authorization flows might -need to do additional queries to the Docker daemon. To complete such flows, -plugins can call the daemon API similar to a regular user. To enable these -additional queries, the plugin must provide the means for an administrator to -configure proper authentication and security policies. - -## Docker client flows - -To enable and configure the authorization plugin, the plugin developer must -support the Docker client interactions detailed in this section. - -### Setting up Docker daemon - -Enable the authorization plugin with a dedicated command line flag in the -`--authorization-plugin=PLUGIN_ID` format. The flag supplies a `PLUGIN_ID` -value. This value can be the plugin’s socket or a path to a specification file. -Authorization plugins can be loaded without restarting the daemon. Refer -to the [`dockerd` documentation](../reference/commandline/dockerd.md#configuration-reloading) for more information. - -```bash -$ dockerd --authorization-plugin=plugin1 --authorization-plugin=plugin2,... -``` - -Docker's authorization subsystem supports multiple `--authorization-plugin` parameters. - -### Calling authorized command (allow) - -```bash -$ docker pull centos -... -f1b10cd84249: Pull complete -... -``` - -### Calling unauthorized command (deny) - -```bash -$ docker pull centos -... -docker: Error response from daemon: authorization denied by plugin PLUGIN_NAME: volumes are not allowed. -``` - -### Error from plugins - -```bash -$ docker pull centos -... -docker: Error response from daemon: plugin PLUGIN_NAME failed with error: AuthZPlugin.AuthZReq: Cannot connect to the Docker daemon. Is the docker daemon running on this host?. -``` - -## API schema and implementation - -In addition to Docker's standard plugin registration method, each plugin -should implement the following two methods: - -* `/AuthZPlugin.AuthZReq` This authorize request method is called before the Docker daemon processes the client request. - -* `/AuthZPlugin.AuthZRes` This authorize response method is called before the response is returned from Docker daemon to the client. - -#### /AuthZPlugin.AuthZReq - -**Request**: - -```json -{ - "User": "The user identification", - "UserAuthNMethod": "The authentication method used", - "RequestMethod": "The HTTP method", - "RequestURI": "The HTTP request URI", - "RequestBody": "Byte array containing the raw HTTP request body", - "RequestHeader": "Byte array containing the raw HTTP request header as a map[string][]string " -} -``` - -**Response**: - -```json -{ - "Allow": "Determined whether the user is allowed or not", - "Msg": "The authorization message", - "Err": "The error message if things go wrong" -} -``` -#### /AuthZPlugin.AuthZRes - -**Request**: - -```json -{ - "User": "The user identification", - "UserAuthNMethod": "The authentication method used", - "RequestMethod": "The HTTP method", - "RequestURI": "The HTTP request URI", - "RequestBody": "Byte array containing the raw HTTP request body", - "RequestHeader": "Byte array containing the raw HTTP request header as a map[string][]string", - "ResponseBody": "Byte array containing the raw HTTP response body", - "ResponseHeader": "Byte array containing the raw HTTP response header as a map[string][]string", - "ResponseStatusCode":"Response status code" -} -``` - -**Response**: - -```json -{ - "Allow": "Determined whether the user is allowed or not", - "Msg": "The authorization message", - "Err": "The error message if things go wrong" -} -``` - -### Request authorization - -Each plugin must support two request authorization messages formats, one from the daemon to the plugin and then from the plugin to the daemon. The tables below detail the content expected in each message. - -#### Daemon -> Plugin - -Name | Type | Description ------------------------|-------------------|------------------------------------------------------- -User | string | The user identification -Authentication method | string | The authentication method used -Request method | enum | The HTTP method (GET/DELETE/POST) -Request URI | string | The HTTP request URI including API version (e.g., v.1.17/containers/json) -Request headers | map[string]string | Request headers as key value pairs (without the authorization header) -Request body | []byte | Raw request body - - -#### Plugin -> Daemon - -Name | Type | Description ---------|--------|---------------------------------------------------------------------------------- -Allow | bool | Boolean value indicating whether the request is allowed or denied -Msg | string | Authorization message (will be returned to the client in case the access is denied) -Err | string | Error message (will be returned to the client in case the plugin encounter an error. The string value supplied may appear in logs, so should not include confidential information) - -### Response authorization - -The plugin must support two authorization messages formats, one from the daemon to the plugin and then from the plugin to the daemon. The tables below detail the content expected in each message. - -#### Daemon -> Plugin - - -Name | Type | Description ------------------------ |------------------ |---------------------------------------------------- -User | string | The user identification -Authentication method | string | The authentication method used -Request method | string | The HTTP method (GET/DELETE/POST) -Request URI | string | The HTTP request URI including API version (e.g., v.1.17/containers/json) -Request headers | map[string]string | Request headers as key value pairs (without the authorization header) -Request body | []byte | Raw request body -Response status code | int | Status code from the docker daemon -Response headers | map[string]string | Response headers as key value pairs -Response body | []byte | Raw docker daemon response body - - -#### Plugin -> Daemon - -Name | Type | Description ---------|--------|---------------------------------------------------------------------------------- -Allow | bool | Boolean value indicating whether the response is allowed or denied -Msg | string | Authorization message (will be returned to the client in case the access is denied) -Err | string | Error message (will be returned to the client in case the plugin encounter an error. The string value supplied may appear in logs, so should not include confidential information) diff --git a/vendor/github.com/docker/docker/docs/extend/plugins_graphdriver.md b/vendor/github.com/docker/docker/docs/extend/plugins_graphdriver.md deleted file mode 100644 index d91c383..0000000 --- a/vendor/github.com/docker/docker/docs/extend/plugins_graphdriver.md +++ /dev/null @@ -1,376 +0,0 @@ ---- -title: "Graphdriver plugins" -description: "How to manage image and container filesystems with external plugins" -keywords: "Examples, Usage, storage, image, docker, data, graph, plugin, api" -advisory: experimental ---- - - - - -## Changelog - -### 1.13.0 - -- Support v2 plugins - -# Docker graph driver plugins - -Docker graph driver plugins enable admins to use an external/out-of-process -graph driver for use with Docker engine. This is an alternative to using the -built-in storage drivers, such as aufs/overlay/devicemapper/btrfs. - -You need to install and enable the plugin and then restart the Docker daemon -before using the plugin. See the following example for the correct ordering -of steps. - -``` -$ docker plugin install cpuguy83/docker-overlay2-graphdriver-plugin # this command also enables the driver - -$ pkill dockerd -$ dockerd --experimental -s cpuguy83/docker-overlay2-graphdriver-plugin -``` - -# Write a graph driver plugin - -See the [plugin documentation](/docs/extend/index.md) for detailed information -on the underlying plugin protocol. - - -## Graph Driver plugin protocol - -If a plugin registers itself as a `GraphDriver` when activated, then it is -expected to provide the rootfs for containers as well as image layer storage. - -### /GraphDriver.Init - -**Request**: -```json -{ - "Home": "/graph/home/path", - "Opts": [], - "UIDMaps": [], - "GIDMaps": [] -} -``` - -Initialize the graph driver plugin with a home directory and array of options. -These are passed through from the user, but the plugin is not required to parse -or honor them. - -The request also includes a list of UID and GID mappings, structed as follows: -```json -{ - "ContainerID": 0, - "HostID": 0, - "Size": 0 -} -``` - -**Response**: -```json -{ - "Err": "" -} -``` - -Respond with a non-empty string error if an error occurred. - - -### /GraphDriver.Create - -**Request**: -```json -{ - "ID": "46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187", - "Parent": "2cd9c322cb78a55e8212aa3ea8425a4180236d7106938ec921d0935a4b8ca142", - "MountLabel": "", - "StorageOpt": {} -} -``` - -Create a new, empty, read-only filesystem layer with the specified -`ID`, `Parent` and `MountLabel`. If `Parent` is an empty string, there is no -parent layer. `StorageOpt` is map of strings which indicate storage options. - -**Response**: -```json -{ - "Err": "" -} -``` - -Respond with a non-empty string error if an error occurred. - -### /GraphDriver.CreateReadWrite - -**Request**: -```json -{ - "ID": "46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187", - "Parent": "2cd9c322cb78a55e8212aa3ea8425a4180236d7106938ec921d0935a4b8ca142", - "MountLabel": "", - "StorageOpt": {} -} -``` - -Similar to `/GraphDriver.Create` but creates a read-write filesystem layer. - -### /GraphDriver.Remove - -**Request**: -```json -{ - "ID": "46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187" -} -``` - -Remove the filesystem layer with this given `ID`. - -**Response**: -```json -{ - "Err": "" -} -``` - -Respond with a non-empty string error if an error occurred. - -### /GraphDriver.Get - -**Request**: -```json -{ - "ID": "46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187", - "MountLabel": "" -} -``` - -Get the mountpoint for the layered filesystem referred to by the given `ID`. - -**Response**: -```json -{ - "Dir": "/var/mygraph/46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187", - "Err": "" -} -``` - -Respond with the absolute path to the mounted layered filesystem. -Respond with a non-empty string error if an error occurred. - -### /GraphDriver.Put - -**Request**: -```json -{ - "ID": "46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187" -} -``` - -Release the system resources for the specified `ID`, such as unmounting the -filesystem layer. - -**Response**: -```json -{ - "Err": "" -} -``` - -Respond with a non-empty string error if an error occurred. - -### /GraphDriver.Exists - -**Request**: -```json -{ - "ID": "46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187" -} -``` - -Determine if a filesystem layer with the specified `ID` exists. - -**Response**: -```json -{ - "Exists": true -} -``` - -Respond with a boolean for whether or not the filesystem layer with the specified -`ID` exists. - -### /GraphDriver.Status - -**Request**: -```json -{} -``` - -Get low-level diagnostic information about the graph driver. - -**Response**: -```json -{ - "Status": [[]] -} -``` - -Respond with a 2-D array with key/value pairs for the underlying status -information. - - -### /GraphDriver.GetMetadata - -**Request**: -```json -{ - "ID": "46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187" -} -``` - -Get low-level diagnostic information about the layered filesystem with the -with the specified `ID` - -**Response**: -```json -{ - "Metadata": {}, - "Err": "" -} -``` - -Respond with a set of key/value pairs containing the low-level diagnostic -information about the layered filesystem. -Respond with a non-empty string error if an error occurred. - -### /GraphDriver.Cleanup - -**Request**: -```json -{} -``` - -Perform necessary tasks to release resources help by the plugin, such as -unmounting all the layered file systems. - -**Response**: -```json -{ - "Err": "" -} -``` - -Respond with a non-empty string error if an error occurred. - - -### /GraphDriver.Diff - -**Request**: -```json -{ - "ID": "46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187", - "Parent": "2cd9c322cb78a55e8212aa3ea8425a4180236d7106938ec921d0935a4b8ca142" -} -``` - -Get an archive of the changes between the filesystem layers specified by the `ID` -and `Parent`. `Parent` may be an empty string, in which case there is no parent. - -**Response**: -``` -{{ TAR STREAM }} -``` - -### /GraphDriver.Changes - -**Request**: -```json -{ - "ID": "46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187", - "Parent": "2cd9c322cb78a55e8212aa3ea8425a4180236d7106938ec921d0935a4b8ca142" -} -``` - -Get a list of changes between the filesystem layers specified by the `ID` and -`Parent`. If `Parent` is an empty string, there is no parent. - -**Response**: -```json -{ - "Changes": [{}], - "Err": "" -} -``` - -Respond with a list of changes. The structure of a change is: -```json - "Path": "/some/path", - "Kind": 0, -``` - -Where the `Path` is the filesystem path within the layered filesystem that is -changed and `Kind` is an integer specifying the type of change that occurred: - -- 0 - Modified -- 1 - Added -- 2 - Deleted - -Respond with a non-empty string error if an error occurred. - -### /GraphDriver.ApplyDiff - -**Request**: -``` -{{ TAR STREAM }} -``` - -Extract the changeset from the given diff into the layer with the specified `ID` -and `Parent` - -**Query Parameters**: - -- id (required)- the `ID` of the new filesystem layer to extract the diff to -- parent (required)- the `Parent` of the given `ID` - -**Response**: -```json -{ - "Size": 512366, - "Err": "" -} -``` - -Respond with the size of the new layer in bytes. -Respond with a non-empty string error if an error occurred. - -### /GraphDriver.DiffSize - -**Request**: -```json -{ - "ID": "46fe8644f2572fd1e505364f7581e0c9dbc7f14640bd1fb6ce97714fb6fc5187", - "Parent": "2cd9c322cb78a55e8212aa3ea8425a4180236d7106938ec921d0935a4b8ca142" -} -``` - -Calculate the changes between the specified `ID` - -**Response**: -```json -{ - "Size": 512366, - "Err": "" -} -``` - -Respond with the size changes between the specified `ID` and `Parent` -Respond with a non-empty string error if an error occurred. diff --git a/vendor/github.com/docker/docker/docs/extend/plugins_network.md b/vendor/github.com/docker/docker/docs/extend/plugins_network.md deleted file mode 100644 index a974862..0000000 --- a/vendor/github.com/docker/docker/docs/extend/plugins_network.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: "Docker network driver plugins" -description: "Network driver plugins." -keywords: "Examples, Usage, plugins, docker, documentation, user guide" ---- - - - -# Engine network driver plugins - -This document describes Docker Engine network driver plugins generally -available in Docker Engine. To view information on plugins -managed by Docker Engine, refer to [Docker Engine plugin system](index.md). - -Docker Engine network plugins enable Engine deployments to be extended to -support a wide range of networking technologies, such as VXLAN, IPVLAN, MACVLAN -or something completely different. Network driver plugins are supported via the -LibNetwork project. Each plugin is implemented as a "remote driver" for -LibNetwork, which shares plugin infrastructure with Engine. Effectively, network -driver plugins are activated in the same way as other plugins, and use the same -kind of protocol. - -## Network driver plugins and swarm mode - -Docker 1.12 adds support for cluster management and orchestration called -[swarm mode](https://docs.docker.com/engine/swarm/). Docker Engine running in swarm mode currently -only supports the built-in overlay driver for networking. Therefore existing -networking plugins will not work in swarm mode. - -When you run Docker Engine outside of swarm mode, all networking plugins that -worked in Docker 1.11 will continue to function normally. They do not require -any modification. - -## Using network driver plugins - -The means of installing and running a network driver plugin depend on the -particular plugin. So, be sure to install your plugin according to the -instructions obtained from the plugin developer. - -Once running however, network driver plugins are used just like the built-in -network drivers: by being mentioned as a driver in network-oriented Docker -commands. For example, - - $ docker network create --driver weave mynet - -Some network driver plugins are listed in [plugins](legacy_plugins.md) - -The `mynet` network is now owned by `weave`, so subsequent commands -referring to that network will be sent to the plugin, - - $ docker run --network=mynet busybox top - - -## Write a network plugin - -Network plugins implement the [Docker plugin -API](plugin_api.md) and the network plugin protocol - -## Network plugin protocol - -The network driver protocol, in addition to the plugin activation call, is -documented as part of libnetwork: -[https://github.com/docker/libnetwork/blob/master/docs/remote.md](https://github.com/docker/libnetwork/blob/master/docs/remote.md). - -# Related Information - -To interact with the Docker maintainers and other interested users, see the IRC channel `#docker-network`. - -- [Docker networks feature overview](https://docs.docker.com/engine/userguide/networking/) -- The [LibNetwork](https://github.com/docker/libnetwork) project diff --git a/vendor/github.com/docker/docker/docs/extend/plugins_volume.md b/vendor/github.com/docker/docker/docs/extend/plugins_volume.md deleted file mode 100644 index c060bf3..0000000 --- a/vendor/github.com/docker/docker/docs/extend/plugins_volume.md +++ /dev/null @@ -1,276 +0,0 @@ ---- -title: "Volume plugins" -description: "How to manage data with external volume plugins" -keywords: "Examples, Usage, volume, docker, data, volumes, plugin, api" ---- - - - -# Write a volume plugin - -Docker Engine volume plugins enable Engine deployments to be integrated with -external storage systems, such as Amazon EBS, and enable data volumes to persist -beyond the lifetime of a single Engine host. See the -[plugin documentation](legacy_plugins.md) for more information. - -## Changelog - -### 1.13.0 - -- If used as part of the v2 plugin architecture, mountpoints that are part of paths returned by plugin have to be mounted under the directory specified by PropagatedMount in the plugin configuration [#26398](https://github.com/docker/docker/pull/26398) - -### 1.12.0 - -- Add `Status` field to `VolumeDriver.Get` response ([#21006](https://github.com/docker/docker/pull/21006#)) -- Add `VolumeDriver.Capabilities` to get capabilities of the volume driver([#22077](https://github.com/docker/docker/pull/22077)) - -### 1.10.0 - -- Add `VolumeDriver.Get` which gets the details about the volume ([#16534](https://github.com/docker/docker/pull/16534)) -- Add `VolumeDriver.List` which lists all volumes owned by the driver ([#16534](https://github.com/docker/docker/pull/16534)) - -### 1.8.0 - -- Initial support for volume driver plugins ([#14659](https://github.com/docker/docker/pull/14659)) - -## Command-line changes - -A volume plugin makes use of the `-v`and `--volume-driver` flag on the `docker run` command. The `-v` flag accepts a volume name and the `--volume-driver` flag a driver type, for example: - - $ docker run -ti -v volumename:/data --volume-driver=flocker busybox sh - -This command passes the `volumename` through to the volume plugin as a -user-given name for the volume. The `volumename` must not begin with a `/`. - -By having the user specify a `volumename`, a plugin can associate the volume -with an external volume beyond the lifetime of a single container or container -host. This can be used, for example, to move a stateful container from one -server to another. - -By specifying a `volumedriver` in conjunction with a `volumename`, users can use plugins such as [Flocker](https://clusterhq.com/docker-plugin/) to manage volumes external to a single host, such as those on EBS. - - -## Create a VolumeDriver - -The container creation endpoint (`/containers/create`) accepts a `VolumeDriver` -field of type `string` allowing to specify the name of the driver. It's default -value of `"local"` (the default driver for local volumes). - -## Volume plugin protocol - -If a plugin registers itself as a `VolumeDriver` when activated, then it is -expected to provide writeable paths on the host filesystem for the Docker -daemon to provide to containers to consume. - -The Docker daemon handles bind-mounting the provided paths into user -containers. - -> **Note**: Volume plugins should *not* write data to the `/var/lib/docker/` -> directory, including `/var/lib/docker/volumes`. The `/var/lib/docker/` -> directory is reserved for Docker. - -### /VolumeDriver.Create - -**Request**: -```json -{ - "Name": "volume_name", - "Opts": {} -} -``` - -Instruct the plugin that the user wants to create a volume, given a user -specified volume name. The plugin does not need to actually manifest the -volume on the filesystem yet (until Mount is called). -Opts is a map of driver specific options passed through from the user request. - -**Response**: -```json -{ - "Err": "" -} -``` - -Respond with a string error if an error occurred. - -### /VolumeDriver.Remove - -**Request**: -```json -{ - "Name": "volume_name" -} -``` - -Delete the specified volume from disk. This request is issued when a user invokes `docker rm -v` to remove volumes associated with a container. - -**Response**: -```json -{ - "Err": "" -} -``` - -Respond with a string error if an error occurred. - -### /VolumeDriver.Mount - -**Request**: -```json -{ - "Name": "volume_name", - "ID": "b87d7442095999a92b65b3d9691e697b61713829cc0ffd1bb72e4ccd51aa4d6c" -} -``` - -Docker requires the plugin to provide a volume, given a user specified volume -name. This is called once per container start. If the same volume_name is requested -more than once, the plugin may need to keep track of each new mount request and provision -at the first mount request and deprovision at the last corresponding unmount request. - -`ID` is a unique ID for the caller that is requesting the mount. - -**Response**: -```json -{ - "Mountpoint": "/path/to/directory/on/host", - "Err": "" -} -``` - -Respond with the path on the host filesystem where the volume has been made -available, and/or a string error if an error occurred. - -### /VolumeDriver.Path - -**Request**: -```json -{ - "Name": "volume_name" -} -``` - -Docker needs reminding of the path to the volume on the host. - -**Response**: -```json -{ - "Mountpoint": "/path/to/directory/on/host", - "Err": "" -} -``` - -Respond with the path on the host filesystem where the volume has been made -available, and/or a string error if an error occurred. `Mountpoint` is optional, -however the plugin may be queried again later if one is not provided. - -### /VolumeDriver.Unmount - -**Request**: -```json -{ - "Name": "volume_name", - "ID": "b87d7442095999a92b65b3d9691e697b61713829cc0ffd1bb72e4ccd51aa4d6c" -} -``` - -Indication that Docker no longer is using the named volume. This is called once -per container stop. Plugin may deduce that it is safe to deprovision it at -this point. - -`ID` is a unique ID for the caller that is requesting the mount. - -**Response**: -```json -{ - "Err": "" -} -``` - -Respond with a string error if an error occurred. - - -### /VolumeDriver.Get - -**Request**: -```json -{ - "Name": "volume_name" -} -``` - -Get the volume info. - - -**Response**: -```json -{ - "Volume": { - "Name": "volume_name", - "Mountpoint": "/path/to/directory/on/host", - "Status": {} - }, - "Err": "" -} -``` - -Respond with a string error if an error occurred. `Mountpoint` and `Status` are -optional. - - -### /VolumeDriver.List - -**Request**: -```json -{} -``` - -Get the list of volumes registered with the plugin. - -**Response**: -```json -{ - "Volumes": [ - { - "Name": "volume_name", - "Mountpoint": "/path/to/directory/on/host" - } - ], - "Err": "" -} -``` - -Respond with a string error if an error occurred. `Mountpoint` is optional. - -### /VolumeDriver.Capabilities - -**Request**: -```json -{} -``` - -Get the list of capabilities the driver supports. -The driver is not required to implement this endpoint, however in such cases -the default values will be taken. - -**Response**: -```json -{ - "Capabilities": { - "Scope": "global" - } -} -``` - -Supported scopes are `global` and `local`. Any other value in `Scope` will be -ignored and assumed to be `local`. Scope allows cluster managers to handle the -volume differently, for instance with a scope of `global`, the cluster manager -knows it only needs to create the volume once instead of on every engine. More -capabilities may be added in the future. diff --git a/vendor/github.com/docker/docker/docs/reference/builder.md b/vendor/github.com/docker/docker/docs/reference/builder.md deleted file mode 100644 index 6fa5a24..0000000 --- a/vendor/github.com/docker/docker/docs/reference/builder.md +++ /dev/null @@ -1,1746 +0,0 @@ ---- -title: "Dockerfile reference" -description: "Dockerfiles use a simple DSL which allows you to automate the steps you would normally manually take to create an image." -keywords: "builder, docker, Dockerfile, automation, image creation" ---- - - - -# Dockerfile reference - -Docker can build images automatically by reading the instructions from a -`Dockerfile`. A `Dockerfile` is a text document that contains all the commands a -user could call on the command line to assemble an image. Using `docker build` -users can create an automated build that executes several command-line -instructions in succession. - -This page describes the commands you can use in a `Dockerfile`. When you are -done reading this page, refer to the [`Dockerfile` Best -Practices](https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/) for a tip-oriented guide. - -## Usage - -The [`docker build`](commandline/build.md) command builds an image from -a `Dockerfile` and a *context*. The build's context is the files at a specified -location `PATH` or `URL`. The `PATH` is a directory on your local filesystem. -The `URL` is a Git repository location. - -A context is processed recursively. So, a `PATH` includes any subdirectories and -the `URL` includes the repository and its submodules. A simple build command -that uses the current directory as context: - - $ docker build . - Sending build context to Docker daemon 6.51 MB - ... - -The build is run by the Docker daemon, not by the CLI. The first thing a build -process does is send the entire context (recursively) to the daemon. In most -cases, it's best to start with an empty directory as context and keep your -Dockerfile in that directory. Add only the files needed for building the -Dockerfile. - ->**Warning**: Do not use your root directory, `/`, as the `PATH` as it causes ->the build to transfer the entire contents of your hard drive to the Docker ->daemon. - -To use a file in the build context, the `Dockerfile` refers to the file specified -in an instruction, for example, a `COPY` instruction. To increase the build's -performance, exclude files and directories by adding a `.dockerignore` file to -the context directory. For information about how to [create a `.dockerignore` -file](#dockerignore-file) see the documentation on this page. - -Traditionally, the `Dockerfile` is called `Dockerfile` and located in the root -of the context. You use the `-f` flag with `docker build` to point to a Dockerfile -anywhere in your file system. - - $ docker build -f /path/to/a/Dockerfile . - -You can specify a repository and tag at which to save the new image if -the build succeeds: - - $ docker build -t shykes/myapp . - -To tag the image into multiple repositories after the build, -add multiple `-t` parameters when you run the `build` command: - - $ docker build -t shykes/myapp:1.0.2 -t shykes/myapp:latest . - -Before the Docker daemon runs the instructions in the `Dockerfile`, it performs -a preliminary validation of the `Dockerfile` and returns an error if the syntax is incorrect: - - $ docker build -t test/myapp . - Sending build context to Docker daemon 2.048 kB - Error response from daemon: Unknown instruction: RUNCMD - -The Docker daemon runs the instructions in the `Dockerfile` one-by-one, -committing the result of each instruction -to a new image if necessary, before finally outputting the ID of your -new image. The Docker daemon will automatically clean up the context you -sent. - -Note that each instruction is run independently, and causes a new image -to be created - so `RUN cd /tmp` will not have any effect on the next -instructions. - -Whenever possible, Docker will re-use the intermediate images (cache), -to accelerate the `docker build` process significantly. This is indicated by -the `Using cache` message in the console output. -(For more information, see the [Build cache section](https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#/build-cache)) in the -`Dockerfile` best practices guide: - - $ docker build -t svendowideit/ambassador . - Sending build context to Docker daemon 15.36 kB - Step 1/4 : FROM alpine:3.2 - ---> 31f630c65071 - Step 2/4 : MAINTAINER SvenDowideit@home.org.au - ---> Using cache - ---> 2a1c91448f5f - Step 3/4 : RUN apk update && apk add socat && rm -r /var/cache/ - ---> Using cache - ---> 21ed6e7fbb73 - Step 4/4 : CMD env | grep _TCP= | (sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat -t 100000000 TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \&/' && echo wait) | sh - ---> Using cache - ---> 7ea8aef582cc - Successfully built 7ea8aef582cc - -Build cache is only used from images that have a local parent chain. This means -that these images were created by previous builds or the whole chain of images -was loaded with `docker load`. If you wish to use build cache of a specific -image you can specify it with `--cache-from` option. Images specified with -`--cache-from` do not need to have a parent chain and may be pulled from other -registries. - -When you're done with your build, you're ready to look into [*Pushing a -repository to its registry*](https://docs.docker.com/engine/tutorials/dockerrepos/#/contributing-to-docker-hub). - -## Format - -Here is the format of the `Dockerfile`: - -```Dockerfile -# Comment -INSTRUCTION arguments -``` - -The instruction is not case-sensitive. However, convention is for them to -be UPPERCASE to distinguish them from arguments more easily. - - -Docker runs instructions in a `Dockerfile` in order. **The first -instruction must be \`FROM\`** in order to specify the [*Base -Image*](glossary.md#base-image) from which you are building. - -Docker treats lines that *begin* with `#` as a comment, unless the line is -a valid [parser directive](#parser-directives). A `#` marker anywhere -else in a line is treated as an argument. This allows statements like: - -```Dockerfile -# Comment -RUN echo 'we are running some # of cool things' -``` - -Line continuation characters are not supported in comments. - -## Parser directives - -Parser directives are optional, and affect the way in which subsequent lines -in a `Dockerfile` are handled. Parser directives do not add layers to the build, -and will not be shown as a build step. Parser directives are written as a -special type of comment in the form `# directive=value`. A single directive -may only be used once. - -Once a comment, empty line or builder instruction has been processed, Docker -no longer looks for parser directives. Instead it treats anything formatted -as a parser directive as a comment and does not attempt to validate if it might -be a parser directive. Therefore, all parser directives must be at the very -top of a `Dockerfile`. - -Parser directives are not case-sensitive. However, convention is for them to -be lowercase. Convention is also to include a blank line following any -parser directives. Line continuation characters are not supported in parser -directives. - -Due to these rules, the following examples are all invalid: - -Invalid due to line continuation: - -```Dockerfile -# direc \ -tive=value -``` - -Invalid due to appearing twice: - -```Dockerfile -# directive=value1 -# directive=value2 - -FROM ImageName -``` - -Treated as a comment due to appearing after a builder instruction: - -```Dockerfile -FROM ImageName -# directive=value -``` - -Treated as a comment due to appearing after a comment which is not a parser -directive: - -```Dockerfile -# About my dockerfile -FROM ImageName -# directive=value -``` - -The unknown directive is treated as a comment due to not being recognized. In -addition, the known directive is treated as a comment due to appearing after -a comment which is not a parser directive. - -```Dockerfile -# unknowndirective=value -# knowndirective=value -``` - -Non line-breaking whitespace is permitted in a parser directive. Hence, the -following lines are all treated identically: - -```Dockerfile -#directive=value -# directive =value -# directive= value -# directive = value -# dIrEcTiVe=value -``` - -The following parser directive is supported: - -* `escape` - -## escape - - # escape=\ (backslash) - -Or - - # escape=` (backtick) - -The `escape` directive sets the character used to escape characters in a -`Dockerfile`. If not specified, the default escape character is `\`. - -The escape character is used both to escape characters in a line, and to -escape a newline. This allows a `Dockerfile` instruction to -span multiple lines. Note that regardless of whether the `escape` parser -directive is included in a `Dockerfile`, *escaping is not performed in -a `RUN` command, except at the end of a line.* - -Setting the escape character to `` ` `` is especially useful on -`Windows`, where `\` is the directory path separator. `` ` `` is consistent -with [Windows PowerShell](https://technet.microsoft.com/en-us/library/hh847755.aspx). - -Consider the following example which would fail in a non-obvious way on -`Windows`. The second `\` at the end of the second line would be interpreted as an -escape for the newline, instead of a target of the escape from the first `\`. -Similarly, the `\` at the end of the third line would, assuming it was actually -handled as an instruction, cause it be treated as a line continuation. The result -of this dockerfile is that second and third lines are considered a single -instruction: - -```Dockerfile -FROM microsoft/nanoserver -COPY testfile.txt c:\\ -RUN dir c:\ -``` - -Results in: - - PS C:\John> docker build -t cmd . - Sending build context to Docker daemon 3.072 kB - Step 1/2 : FROM microsoft/nanoserver - ---> 22738ff49c6d - Step 2/2 : COPY testfile.txt c:\RUN dir c: - GetFileAttributesEx c:RUN: The system cannot find the file specified. - PS C:\John> - -One solution to the above would be to use `/` as the target of both the `COPY` -instruction, and `dir`. However, this syntax is, at best, confusing as it is not -natural for paths on `Windows`, and at worst, error prone as not all commands on -`Windows` support `/` as the path separator. - -By adding the `escape` parser directive, the following `Dockerfile` succeeds as -expected with the use of natural platform semantics for file paths on `Windows`: - - # escape=` - - FROM microsoft/nanoserver - COPY testfile.txt c:\ - RUN dir c:\ - -Results in: - - PS C:\John> docker build -t succeeds --no-cache=true . - Sending build context to Docker daemon 3.072 kB - Step 1/3 : FROM microsoft/nanoserver - ---> 22738ff49c6d - Step 2/3 : COPY testfile.txt c:\ - ---> 96655de338de - Removing intermediate container 4db9acbb1682 - Step 3/3 : RUN dir c:\ - ---> Running in a2c157f842f5 - Volume in drive C has no label. - Volume Serial Number is 7E6D-E0F7 - - Directory of c:\ - - 10/05/2016 05:04 PM 1,894 License.txt - 10/05/2016 02:22 PM Program Files - 10/05/2016 02:14 PM Program Files (x86) - 10/28/2016 11:18 AM 62 testfile.txt - 10/28/2016 11:20 AM Users - 10/28/2016 11:20 AM Windows - 2 File(s) 1,956 bytes - 4 Dir(s) 21,259,096,064 bytes free - ---> 01c7f3bef04f - Removing intermediate container a2c157f842f5 - Successfully built 01c7f3bef04f - PS C:\John> - -## Environment replacement - -Environment variables (declared with [the `ENV` statement](#env)) can also be -used in certain instructions as variables to be interpreted by the -`Dockerfile`. Escapes are also handled for including variable-like syntax -into a statement literally. - -Environment variables are notated in the `Dockerfile` either with -`$variable_name` or `${variable_name}`. They are treated equivalently and the -brace syntax is typically used to address issues with variable names with no -whitespace, like `${foo}_bar`. - -The `${variable_name}` syntax also supports a few of the standard `bash` -modifiers as specified below: - -* `${variable:-word}` indicates that if `variable` is set then the result - will be that value. If `variable` is not set then `word` will be the result. -* `${variable:+word}` indicates that if `variable` is set then `word` will be - the result, otherwise the result is the empty string. - -In all cases, `word` can be any string, including additional environment -variables. - -Escaping is possible by adding a `\` before the variable: `\$foo` or `\${foo}`, -for example, will translate to `$foo` and `${foo}` literals respectively. - -Example (parsed representation is displayed after the `#`): - - FROM busybox - ENV foo /bar - WORKDIR ${foo} # WORKDIR /bar - ADD . $foo # ADD . /bar - COPY \$foo /quux # COPY $foo /quux - -Environment variables are supported by the following list of instructions in -the `Dockerfile`: - -* `ADD` -* `COPY` -* `ENV` -* `EXPOSE` -* `LABEL` -* `USER` -* `WORKDIR` -* `VOLUME` -* `STOPSIGNAL` - -as well as: - -* `ONBUILD` (when combined with one of the supported instructions above) - -> **Note**: -> prior to 1.4, `ONBUILD` instructions did **NOT** support environment -> variable, even when combined with any of the instructions listed above. - -Environment variable substitution will use the same value for each variable -throughout the entire command. In other words, in this example: - - ENV abc=hello - ENV abc=bye def=$abc - ENV ghi=$abc - -will result in `def` having a value of `hello`, not `bye`. However, -`ghi` will have a value of `bye` because it is not part of the same command -that set `abc` to `bye`. - -## .dockerignore file - -Before the docker CLI sends the context to the docker daemon, it looks -for a file named `.dockerignore` in the root directory of the context. -If this file exists, the CLI modifies the context to exclude files and -directories that match patterns in it. This helps to avoid -unnecessarily sending large or sensitive files and directories to the -daemon and potentially adding them to images using `ADD` or `COPY`. - -The CLI interprets the `.dockerignore` file as a newline-separated -list of patterns similar to the file globs of Unix shells. For the -purposes of matching, the root of the context is considered to be both -the working and the root directory. For example, the patterns -`/foo/bar` and `foo/bar` both exclude a file or directory named `bar` -in the `foo` subdirectory of `PATH` or in the root of the git -repository located at `URL`. Neither excludes anything else. - -If a line in `.dockerignore` file starts with `#` in column 1, then this line is -considered as a comment and is ignored before interpreted by the CLI. - -Here is an example `.dockerignore` file: - -``` -# comment - */temp* - */*/temp* - temp? -``` - -This file causes the following build behavior: - -| Rule | Behavior | -|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `# comment` | Ignored. | -| `*/temp*` | Exclude files and directories whose names start with `temp` in any immediate subdirectory of the root. For example, the plain file `/somedir/temporary.txt` is excluded, as is the directory `/somedir/temp`. | -| `*/*/temp*` | Exclude files and directories starting with `temp` from any subdirectory that is two levels below the root. For example, `/somedir/subdir/temporary.txt` is excluded. | -| `temp?` | Exclude files and directories in the root directory whose names are a one-character extension of `temp`. For example, `/tempa` and `/tempb` are excluded. - - -Matching is done using Go's -[filepath.Match](http://golang.org/pkg/path/filepath#Match) rules. A -preprocessing step removes leading and trailing whitespace and -eliminates `.` and `..` elements using Go's -[filepath.Clean](http://golang.org/pkg/path/filepath/#Clean). Lines -that are blank after preprocessing are ignored. - -Beyond Go's filepath.Match rules, Docker also supports a special -wildcard string `**` that matches any number of directories (including -zero). For example, `**/*.go` will exclude all files that end with `.go` -that are found in all directories, including the root of the build context. - -Lines starting with `!` (exclamation mark) can be used to make exceptions -to exclusions. The following is an example `.dockerignore` file that -uses this mechanism: - -``` - *.md - !README.md -``` - -All markdown files *except* `README.md` are excluded from the context. - -The placement of `!` exception rules influences the behavior: the last -line of the `.dockerignore` that matches a particular file determines -whether it is included or excluded. Consider the following example: - -``` - *.md - !README*.md - README-secret.md -``` - -No markdown files are included in the context except README files other than -`README-secret.md`. - -Now consider this example: - -``` - *.md - README-secret.md - !README*.md -``` - -All of the README files are included. The middle line has no effect because -`!README*.md` matches `README-secret.md` and comes last. - -You can even use the `.dockerignore` file to exclude the `Dockerfile` -and `.dockerignore` files. These files are still sent to the daemon -because it needs them to do its job. But the `ADD` and `COPY` commands -do not copy them to the image. - -Finally, you may want to specify which files to include in the -context, rather than which to exclude. To achieve this, specify `*` as -the first pattern, followed by one or more `!` exception patterns. - -**Note**: For historical reasons, the pattern `.` is ignored. - -## FROM - - FROM - -Or - - FROM : - -Or - - FROM @ - -The `FROM` instruction sets the [*Base Image*](glossary.md#base-image) -for subsequent instructions. As such, a valid `Dockerfile` must have `FROM` as -its first instruction. The image can be any valid image – it is especially easy -to start by **pulling an image** from the [*Public Repositories*](https://docs.docker.com/engine/tutorials/dockerrepos/). - -- `FROM` must be the first non-comment instruction in the `Dockerfile`. - -- `FROM` can appear multiple times within a single `Dockerfile` in order to create -multiple images. Simply make a note of the last image ID output by the commit -before each new `FROM` command. - -- The `tag` or `digest` values are optional. If you omit either of them, the builder -assumes a `latest` by default. The builder returns an error if it cannot match -the `tag` value. - -## RUN - -RUN has 2 forms: - -- `RUN ` (*shell* form, the command is run in a shell, which by -default is `/bin/sh -c` on Linux or `cmd /S /C` on Windows) -- `RUN ["executable", "param1", "param2"]` (*exec* form) - -The `RUN` instruction will execute any commands in a new layer on top of the -current image and commit the results. The resulting committed image will be -used for the next step in the `Dockerfile`. - -Layering `RUN` instructions and generating commits conforms to the core -concepts of Docker where commits are cheap and containers can be created from -any point in an image's history, much like source control. - -The *exec* form makes it possible to avoid shell string munging, and to `RUN` -commands using a base image that does not contain the specified shell executable. - -The default shell for the *shell* form can be changed using the `SHELL` -command. - -In the *shell* form you can use a `\` (backslash) to continue a single -RUN instruction onto the next line. For example, consider these two lines: - -``` -RUN /bin/bash -c 'source $HOME/.bashrc; \ -echo $HOME' -``` -Together they are equivalent to this single line: - -``` -RUN /bin/bash -c 'source $HOME/.bashrc; echo $HOME' -``` - -> **Note**: -> To use a different shell, other than '/bin/sh', use the *exec* form -> passing in the desired shell. For example, -> `RUN ["/bin/bash", "-c", "echo hello"]` - -> **Note**: -> The *exec* form is parsed as a JSON array, which means that -> you must use double-quotes (") around words not single-quotes ('). - -> **Note**: -> Unlike the *shell* form, the *exec* form does not invoke a command shell. -> This means that normal shell processing does not happen. For example, -> `RUN [ "echo", "$HOME" ]` will not do variable substitution on `$HOME`. -> If you want shell processing then either use the *shell* form or execute -> a shell directly, for example: `RUN [ "sh", "-c", "echo $HOME" ]`. -> When using the exec form and executing a shell directly, as in the case for -> the shell form, it is the shell that is doing the environment variable -> expansion, not docker. -> -> **Note**: -> In the *JSON* form, it is necessary to escape backslashes. This is -> particularly relevant on Windows where the backslash is the path separator. -> The following line would otherwise be treated as *shell* form due to not -> being valid JSON, and fail in an unexpected way: -> `RUN ["c:\windows\system32\tasklist.exe"]` -> The correct syntax for this example is: -> `RUN ["c:\\windows\\system32\\tasklist.exe"]` - -The cache for `RUN` instructions isn't invalidated automatically during -the next build. The cache for an instruction like -`RUN apt-get dist-upgrade -y` will be reused during the next build. The -cache for `RUN` instructions can be invalidated by using the `--no-cache` -flag, for example `docker build --no-cache`. - -See the [`Dockerfile` Best Practices -guide](https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#/build-cache) for more information. - -The cache for `RUN` instructions can be invalidated by `ADD` instructions. See -[below](#add) for details. - -### Known issues (RUN) - -- [Issue 783](https://github.com/docker/docker/issues/783) is about file - permissions problems that can occur when using the AUFS file system. You - might notice it during an attempt to `rm` a file, for example. - - For systems that have recent aufs version (i.e., `dirperm1` mount option can - be set), docker will attempt to fix the issue automatically by mounting - the layers with `dirperm1` option. More details on `dirperm1` option can be - found at [`aufs` man page](https://github.com/sfjro/aufs3-linux/tree/aufs3.18/Documentation/filesystems/aufs) - - If your system doesn't have support for `dirperm1`, the issue describes a workaround. - -## CMD - -The `CMD` instruction has three forms: - -- `CMD ["executable","param1","param2"]` (*exec* form, this is the preferred form) -- `CMD ["param1","param2"]` (as *default parameters to ENTRYPOINT*) -- `CMD command param1 param2` (*shell* form) - -There can only be one `CMD` instruction in a `Dockerfile`. If you list more than one `CMD` -then only the last `CMD` will take effect. - -**The main purpose of a `CMD` is to provide defaults for an executing -container.** These defaults can include an executable, or they can omit -the executable, in which case you must specify an `ENTRYPOINT` -instruction as well. - -> **Note**: -> If `CMD` is used to provide default arguments for the `ENTRYPOINT` -> instruction, both the `CMD` and `ENTRYPOINT` instructions should be specified -> with the JSON array format. - -> **Note**: -> The *exec* form is parsed as a JSON array, which means that -> you must use double-quotes (") around words not single-quotes ('). - -> **Note**: -> Unlike the *shell* form, the *exec* form does not invoke a command shell. -> This means that normal shell processing does not happen. For example, -> `CMD [ "echo", "$HOME" ]` will not do variable substitution on `$HOME`. -> If you want shell processing then either use the *shell* form or execute -> a shell directly, for example: `CMD [ "sh", "-c", "echo $HOME" ]`. -> When using the exec form and executing a shell directly, as in the case for -> the shell form, it is the shell that is doing the environment variable -> expansion, not docker. - -When used in the shell or exec formats, the `CMD` instruction sets the command -to be executed when running the image. - -If you use the *shell* form of the `CMD`, then the `` will execute in -`/bin/sh -c`: - - FROM ubuntu - CMD echo "This is a test." | wc - - -If you want to **run your** `` **without a shell** then you must -express the command as a JSON array and give the full path to the executable. -**This array form is the preferred format of `CMD`.** Any additional parameters -must be individually expressed as strings in the array: - - FROM ubuntu - CMD ["/usr/bin/wc","--help"] - -If you would like your container to run the same executable every time, then -you should consider using `ENTRYPOINT` in combination with `CMD`. See -[*ENTRYPOINT*](#entrypoint). - -If the user specifies arguments to `docker run` then they will override the -default specified in `CMD`. - -> **Note**: -> Don't confuse `RUN` with `CMD`. `RUN` actually runs a command and commits -> the result; `CMD` does not execute anything at build time, but specifies -> the intended command for the image. - -## LABEL - - LABEL = = = ... - -The `LABEL` instruction adds metadata to an image. A `LABEL` is a -key-value pair. To include spaces within a `LABEL` value, use quotes and -backslashes as you would in command-line parsing. A few usage examples: - - LABEL "com.example.vendor"="ACME Incorporated" - LABEL com.example.label-with-value="foo" - LABEL version="1.0" - LABEL description="This text illustrates \ - that label-values can span multiple lines." - -An image can have more than one label. To specify multiple labels, -Docker recommends combining labels into a single `LABEL` instruction where -possible. Each `LABEL` instruction produces a new layer which can result in an -inefficient image if you use many labels. This example results in a single image -layer. - - LABEL multi.label1="value1" multi.label2="value2" other="value3" - -The above can also be written as: - - LABEL multi.label1="value1" \ - multi.label2="value2" \ - other="value3" - -Labels are additive including `LABEL`s in `FROM` images. If Docker -encounters a label/key that already exists, the new value overrides any previous -labels with identical keys. - -To view an image's labels, use the `docker inspect` command. - - "Labels": { - "com.example.vendor": "ACME Incorporated" - "com.example.label-with-value": "foo", - "version": "1.0", - "description": "This text illustrates that label-values can span multiple lines.", - "multi.label1": "value1", - "multi.label2": "value2", - "other": "value3" - }, - -## MAINTAINER (deprecated) - - MAINTAINER - -The `MAINTAINER` instruction sets the *Author* field of the generated images. -The `LABEL` instruction is a much more flexible version of this and you should use -it instead, as it enables setting any metadata you require, and can be viewed -easily, for example with `docker inspect`. To set a label corresponding to the -`MAINTAINER` field you could use: - - LABEL maintainer "SvenDowideit@home.org.au" - -This will then be visible from `docker inspect` with the other labels. - -## EXPOSE - - EXPOSE [...] - -The `EXPOSE` instruction informs Docker that the container listens on the -specified network ports at runtime. `EXPOSE` does not make the ports of the -container accessible to the host. To do that, you must use either the `-p` flag -to publish a range of ports or the `-P` flag to publish all of the exposed -ports. You can expose one port number and publish it externally under another -number. - -To set up port redirection on the host system, see [using the -P -flag](run.md#expose-incoming-ports). The Docker network feature supports -creating networks without the need to expose ports within the network, for -detailed information see the [overview of this -feature](https://docs.docker.com/engine/userguide/networking/)). - -## ENV - - ENV - ENV = ... - -The `ENV` instruction sets the environment variable `` to the value -``. This value will be in the environment of all "descendant" -`Dockerfile` commands and can be [replaced inline](#environment-replacement) in -many as well. - -The `ENV` instruction has two forms. The first form, `ENV `, -will set a single variable to a value. The entire string after the first -space will be treated as the `` - including characters such as -spaces and quotes. - -The second form, `ENV = ...`, allows for multiple variables to -be set at one time. Notice that the second form uses the equals sign (=) -in the syntax, while the first form does not. Like command line parsing, -quotes and backslashes can be used to include spaces within values. - -For example: - - ENV myName="John Doe" myDog=Rex\ The\ Dog \ - myCat=fluffy - -and - - ENV myName John Doe - ENV myDog Rex The Dog - ENV myCat fluffy - -will yield the same net results in the final image, but the first form -is preferred because it produces a single cache layer. - -The environment variables set using `ENV` will persist when a container is run -from the resulting image. You can view the values using `docker inspect`, and -change them using `docker run --env =`. - -> **Note**: -> Environment persistence can cause unexpected side effects. For example, -> setting `ENV DEBIAN_FRONTEND noninteractive` may confuse apt-get -> users on a Debian-based image. To set a value for a single command, use -> `RUN = `. - -## ADD - -ADD has two forms: - -- `ADD ... ` -- `ADD ["",... ""]` (this form is required for paths containing -whitespace) - -The `ADD` instruction copies new files, directories or remote file URLs from `` -and adds them to the filesystem of the image at the path ``. - -Multiple `` resource may be specified but if they are files or -directories then they must be relative to the source directory that is -being built (the context of the build). - -Each `` may contain wildcards and matching will be done using Go's -[filepath.Match](http://golang.org/pkg/path/filepath#Match) rules. For example: - - ADD hom* /mydir/ # adds all files starting with "hom" - ADD hom?.txt /mydir/ # ? is replaced with any single character, e.g., "home.txt" - -The `` is an absolute path, or a path relative to `WORKDIR`, into which -the source will be copied inside the destination container. - - ADD test relativeDir/ # adds "test" to `WORKDIR`/relativeDir/ - ADD test /absoluteDir/ # adds "test" to /absoluteDir/ - -All new files and directories are created with a UID and GID of 0. - -In the case where `` is a remote file URL, the destination will -have permissions of 600. If the remote file being retrieved has an HTTP -`Last-Modified` header, the timestamp from that header will be used -to set the `mtime` on the destination file. However, like any other file -processed during an `ADD`, `mtime` will not be included in the determination -of whether or not the file has changed and the cache should be updated. - -> **Note**: -> If you build by passing a `Dockerfile` through STDIN (`docker -> build - < somefile`), there is no build context, so the `Dockerfile` -> can only contain a URL based `ADD` instruction. You can also pass a -> compressed archive through STDIN: (`docker build - < archive.tar.gz`), -> the `Dockerfile` at the root of the archive and the rest of the -> archive will be used as the context of the build. - -> **Note**: -> If your URL files are protected using authentication, you -> will need to use `RUN wget`, `RUN curl` or use another tool from -> within the container as the `ADD` instruction does not support -> authentication. - -> **Note**: -> The first encountered `ADD` instruction will invalidate the cache for all -> following instructions from the Dockerfile if the contents of `` have -> changed. This includes invalidating the cache for `RUN` instructions. -> See the [`Dockerfile` Best Practices -guide](https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#/build-cache) for more information. - - -`ADD` obeys the following rules: - -- The `` path must be inside the *context* of the build; - you cannot `ADD ../something /something`, because the first step of a - `docker build` is to send the context directory (and subdirectories) to the - docker daemon. - -- If `` is a URL and `` does not end with a trailing slash, then a - file is downloaded from the URL and copied to ``. - -- If `` is a URL and `` does end with a trailing slash, then the - filename is inferred from the URL and the file is downloaded to - `/`. For instance, `ADD http://example.com/foobar /` would - create the file `/foobar`. The URL must have a nontrivial path so that an - appropriate filename can be discovered in this case (`http://example.com` - will not work). - -- If `` is a directory, the entire contents of the directory are copied, - including filesystem metadata. - -> **Note**: -> The directory itself is not copied, just its contents. - -- If `` is a *local* tar archive in a recognized compression format - (identity, gzip, bzip2 or xz) then it is unpacked as a directory. Resources - from *remote* URLs are **not** decompressed. When a directory is copied or - unpacked, it has the same behavior as `tar -x`, the result is the union of: - - 1. Whatever existed at the destination path and - 2. The contents of the source tree, with conflicts resolved in favor - of "2." on a file-by-file basis. - - > **Note**: - > Whether a file is identified as a recognized compression format or not - > is done solely based on the contents of the file, not the name of the file. - > For example, if an empty file happens to end with `.tar.gz` this will not - > be recognized as a compressed file and **will not** generate any kind of - > decompression error message, rather the file will simply be copied to the - > destination. - -- If `` is any other kind of file, it is copied individually along with - its metadata. In this case, if `` ends with a trailing slash `/`, it - will be considered a directory and the contents of `` will be written - at `/base()`. - -- If multiple `` resources are specified, either directly or due to the - use of a wildcard, then `` must be a directory, and it must end with - a slash `/`. - -- If `` does not end with a trailing slash, it will be considered a - regular file and the contents of `` will be written at ``. - -- If `` doesn't exist, it is created along with all missing directories - in its path. - -## COPY - -COPY has two forms: - -- `COPY ... ` -- `COPY ["",... ""]` (this form is required for paths containing -whitespace) - -The `COPY` instruction copies new files or directories from `` -and adds them to the filesystem of the container at the path ``. - -Multiple `` resource may be specified but they must be relative -to the source directory that is being built (the context of the build). - -Each `` may contain wildcards and matching will be done using Go's -[filepath.Match](http://golang.org/pkg/path/filepath#Match) rules. For example: - - COPY hom* /mydir/ # adds all files starting with "hom" - COPY hom?.txt /mydir/ # ? is replaced with any single character, e.g., "home.txt" - -The `` is an absolute path, or a path relative to `WORKDIR`, into which -the source will be copied inside the destination container. - - COPY test relativeDir/ # adds "test" to `WORKDIR`/relativeDir/ - COPY test /absoluteDir/ # adds "test" to /absoluteDir/ - -All new files and directories are created with a UID and GID of 0. - -> **Note**: -> If you build using STDIN (`docker build - < somefile`), there is no -> build context, so `COPY` can't be used. - -`COPY` obeys the following rules: - -- The `` path must be inside the *context* of the build; - you cannot `COPY ../something /something`, because the first step of a - `docker build` is to send the context directory (and subdirectories) to the - docker daemon. - -- If `` is a directory, the entire contents of the directory are copied, - including filesystem metadata. - -> **Note**: -> The directory itself is not copied, just its contents. - -- If `` is any other kind of file, it is copied individually along with - its metadata. In this case, if `` ends with a trailing slash `/`, it - will be considered a directory and the contents of `` will be written - at `/base()`. - -- If multiple `` resources are specified, either directly or due to the - use of a wildcard, then `` must be a directory, and it must end with - a slash `/`. - -- If `` does not end with a trailing slash, it will be considered a - regular file and the contents of `` will be written at ``. - -- If `` doesn't exist, it is created along with all missing directories - in its path. - -## ENTRYPOINT - -ENTRYPOINT has two forms: - -- `ENTRYPOINT ["executable", "param1", "param2"]` - (*exec* form, preferred) -- `ENTRYPOINT command param1 param2` - (*shell* form) - -An `ENTRYPOINT` allows you to configure a container that will run as an executable. - -For example, the following will start nginx with its default content, listening -on port 80: - - docker run -i -t --rm -p 80:80 nginx - -Command line arguments to `docker run ` will be appended after all -elements in an *exec* form `ENTRYPOINT`, and will override all elements specified -using `CMD`. -This allows arguments to be passed to the entry point, i.e., `docker run -d` -will pass the `-d` argument to the entry point. -You can override the `ENTRYPOINT` instruction using the `docker run --entrypoint` -flag. - -The *shell* form prevents any `CMD` or `run` command line arguments from being -used, but has the disadvantage that your `ENTRYPOINT` will be started as a -subcommand of `/bin/sh -c`, which does not pass signals. -This means that the executable will not be the container's `PID 1` - and -will _not_ receive Unix signals - so your executable will not receive a -`SIGTERM` from `docker stop `. - -Only the last `ENTRYPOINT` instruction in the `Dockerfile` will have an effect. - -### Exec form ENTRYPOINT example - -You can use the *exec* form of `ENTRYPOINT` to set fairly stable default commands -and arguments and then use either form of `CMD` to set additional defaults that -are more likely to be changed. - - FROM ubuntu - ENTRYPOINT ["top", "-b"] - CMD ["-c"] - -When you run the container, you can see that `top` is the only process: - - $ docker run -it --rm --name test top -H - top - 08:25:00 up 7:27, 0 users, load average: 0.00, 0.01, 0.05 - Threads: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie - %Cpu(s): 0.1 us, 0.1 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st - KiB Mem: 2056668 total, 1616832 used, 439836 free, 99352 buffers - KiB Swap: 1441840 total, 0 used, 1441840 free. 1324440 cached Mem - - PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND - 1 root 20 0 19744 2336 2080 R 0.0 0.1 0:00.04 top - -To examine the result further, you can use `docker exec`: - - $ docker exec -it test ps aux - USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND - root 1 2.6 0.1 19752 2352 ? Ss+ 08:24 0:00 top -b -H - root 7 0.0 0.1 15572 2164 ? R+ 08:25 0:00 ps aux - -And you can gracefully request `top` to shut down using `docker stop test`. - -The following `Dockerfile` shows using the `ENTRYPOINT` to run Apache in the -foreground (i.e., as `PID 1`): - -``` -FROM debian:stable -RUN apt-get update && apt-get install -y --force-yes apache2 -EXPOSE 80 443 -VOLUME ["/var/www", "/var/log/apache2", "/etc/apache2"] -ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] -``` - -If you need to write a starter script for a single executable, you can ensure that -the final executable receives the Unix signals by using `exec` and `gosu` -commands: - -```bash -#!/bin/bash -set -e - -if [ "$1" = 'postgres' ]; then - chown -R postgres "$PGDATA" - - if [ -z "$(ls -A "$PGDATA")" ]; then - gosu postgres initdb - fi - - exec gosu postgres "$@" -fi - -exec "$@" -``` - -Lastly, if you need to do some extra cleanup (or communicate with other containers) -on shutdown, or are co-ordinating more than one executable, you may need to ensure -that the `ENTRYPOINT` script receives the Unix signals, passes them on, and then -does some more work: - -``` -#!/bin/sh -# Note: I've written this using sh so it works in the busybox container too - -# USE the trap if you need to also do manual cleanup after the service is stopped, -# or need to start multiple services in the one container -trap "echo TRAPed signal" HUP INT QUIT TERM - -# start service in background here -/usr/sbin/apachectl start - -echo "[hit enter key to exit] or run 'docker stop '" -read - -# stop service and clean up here -echo "stopping apache" -/usr/sbin/apachectl stop - -echo "exited $0" -``` - -If you run this image with `docker run -it --rm -p 80:80 --name test apache`, -you can then examine the container's processes with `docker exec`, or `docker top`, -and then ask the script to stop Apache: - -```bash -$ docker exec -it test ps aux -USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND -root 1 0.1 0.0 4448 692 ? Ss+ 00:42 0:00 /bin/sh /run.sh 123 cmd cmd2 -root 19 0.0 0.2 71304 4440 ? Ss 00:42 0:00 /usr/sbin/apache2 -k start -www-data 20 0.2 0.2 360468 6004 ? Sl 00:42 0:00 /usr/sbin/apache2 -k start -www-data 21 0.2 0.2 360468 6000 ? Sl 00:42 0:00 /usr/sbin/apache2 -k start -root 81 0.0 0.1 15572 2140 ? R+ 00:44 0:00 ps aux -$ docker top test -PID USER COMMAND -10035 root {run.sh} /bin/sh /run.sh 123 cmd cmd2 -10054 root /usr/sbin/apache2 -k start -10055 33 /usr/sbin/apache2 -k start -10056 33 /usr/sbin/apache2 -k start -$ /usr/bin/time docker stop test -test -real 0m 0.27s -user 0m 0.03s -sys 0m 0.03s -``` - -> **Note:** you can override the `ENTRYPOINT` setting using `--entrypoint`, -> but this can only set the binary to *exec* (no `sh -c` will be used). - -> **Note**: -> The *exec* form is parsed as a JSON array, which means that -> you must use double-quotes (") around words not single-quotes ('). - -> **Note**: -> Unlike the *shell* form, the *exec* form does not invoke a command shell. -> This means that normal shell processing does not happen. For example, -> `ENTRYPOINT [ "echo", "$HOME" ]` will not do variable substitution on `$HOME`. -> If you want shell processing then either use the *shell* form or execute -> a shell directly, for example: `ENTRYPOINT [ "sh", "-c", "echo $HOME" ]`. -> When using the exec form and executing a shell directly, as in the case for -> the shell form, it is the shell that is doing the environment variable -> expansion, not docker. - -### Shell form ENTRYPOINT example - -You can specify a plain string for the `ENTRYPOINT` and it will execute in `/bin/sh -c`. -This form will use shell processing to substitute shell environment variables, -and will ignore any `CMD` or `docker run` command line arguments. -To ensure that `docker stop` will signal any long running `ENTRYPOINT` executable -correctly, you need to remember to start it with `exec`: - - FROM ubuntu - ENTRYPOINT exec top -b - -When you run this image, you'll see the single `PID 1` process: - - $ docker run -it --rm --name test top - Mem: 1704520K used, 352148K free, 0K shrd, 0K buff, 140368121167873K cached - CPU: 5% usr 0% sys 0% nic 94% idle 0% io 0% irq 0% sirq - Load average: 0.08 0.03 0.05 2/98 6 - PID PPID USER STAT VSZ %VSZ %CPU COMMAND - 1 0 root R 3164 0% 0% top -b - -Which will exit cleanly on `docker stop`: - - $ /usr/bin/time docker stop test - test - real 0m 0.20s - user 0m 0.02s - sys 0m 0.04s - -If you forget to add `exec` to the beginning of your `ENTRYPOINT`: - - FROM ubuntu - ENTRYPOINT top -b - CMD --ignored-param1 - -You can then run it (giving it a name for the next step): - - $ docker run -it --name test top --ignored-param2 - Mem: 1704184K used, 352484K free, 0K shrd, 0K buff, 140621524238337K cached - CPU: 9% usr 2% sys 0% nic 88% idle 0% io 0% irq 0% sirq - Load average: 0.01 0.02 0.05 2/101 7 - PID PPID USER STAT VSZ %VSZ %CPU COMMAND - 1 0 root S 3168 0% 0% /bin/sh -c top -b cmd cmd2 - 7 1 root R 3164 0% 0% top -b - -You can see from the output of `top` that the specified `ENTRYPOINT` is not `PID 1`. - -If you then run `docker stop test`, the container will not exit cleanly - the -`stop` command will be forced to send a `SIGKILL` after the timeout: - - $ docker exec -it test ps aux - PID USER COMMAND - 1 root /bin/sh -c top -b cmd cmd2 - 7 root top -b - 8 root ps aux - $ /usr/bin/time docker stop test - test - real 0m 10.19s - user 0m 0.04s - sys 0m 0.03s - -### Understand how CMD and ENTRYPOINT interact - -Both `CMD` and `ENTRYPOINT` instructions define what command gets executed when running a container. -There are few rules that describe their co-operation. - -1. Dockerfile should specify at least one of `CMD` or `ENTRYPOINT` commands. - -2. `ENTRYPOINT` should be defined when using the container as an executable. - -3. `CMD` should be used as a way of defining default arguments for an `ENTRYPOINT` command -or for executing an ad-hoc command in a container. - -4. `CMD` will be overridden when running the container with alternative arguments. - -The table below shows what command is executed for different `ENTRYPOINT` / `CMD` combinations: - -| | No ENTRYPOINT | ENTRYPOINT exec_entry p1_entry | ENTRYPOINT ["exec_entry", "p1_entry"] | -|--------------------------------|----------------------------|--------------------------------|------------------------------------------------| -| **No CMD** | *error, not allowed* | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry | -| **CMD ["exec_cmd", "p1_cmd"]** | exec_cmd p1_cmd | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry exec_cmd p1_cmd | -| **CMD ["p1_cmd", "p2_cmd"]** | p1_cmd p2_cmd | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry p1_cmd p2_cmd | -| **CMD exec_cmd p1_cmd** | /bin/sh -c exec_cmd p1_cmd | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry /bin/sh -c exec_cmd p1_cmd | - -## VOLUME - - VOLUME ["/data"] - -The `VOLUME` instruction creates a mount point with the specified name -and marks it as holding externally mounted volumes from native host or other -containers. The value can be a JSON array, `VOLUME ["/var/log/"]`, or a plain -string with multiple arguments, such as `VOLUME /var/log` or `VOLUME /var/log -/var/db`. For more information/examples and mounting instructions via the -Docker client, refer to -[*Share Directories via Volumes*](https://docs.docker.com/engine/tutorials/dockervolumes/#/mount-a-host-directory-as-a-data-volume) -documentation. - -The `docker run` command initializes the newly created volume with any data -that exists at the specified location within the base image. For example, -consider the following Dockerfile snippet: - - FROM ubuntu - RUN mkdir /myvol - RUN echo "hello world" > /myvol/greeting - VOLUME /myvol - -This Dockerfile results in an image that causes `docker run`, to -create a new mount point at `/myvol` and copy the `greeting` file -into the newly created volume. - -> **Note**: -> If any build steps change the data within the volume after it has been -> declared, those changes will be discarded. - -> **Note**: -> The list is parsed as a JSON array, which means that -> you must use double-quotes (") around words not single-quotes ('). - -## USER - - USER daemon - -The `USER` instruction sets the user name or UID to use when running the image -and for any `RUN`, `CMD` and `ENTRYPOINT` instructions that follow it in the -`Dockerfile`. - -## WORKDIR - - WORKDIR /path/to/workdir - -The `WORKDIR` instruction sets the working directory for any `RUN`, `CMD`, -`ENTRYPOINT`, `COPY` and `ADD` instructions that follow it in the `Dockerfile`. -If the `WORKDIR` doesn't exist, it will be created even if it's not used in any -subsequent `Dockerfile` instruction. - -It can be used multiple times in the one `Dockerfile`. If a relative path -is provided, it will be relative to the path of the previous `WORKDIR` -instruction. For example: - - WORKDIR /a - WORKDIR b - WORKDIR c - RUN pwd - -The output of the final `pwd` command in this `Dockerfile` would be -`/a/b/c`. - -The `WORKDIR` instruction can resolve environment variables previously set using -`ENV`. You can only use environment variables explicitly set in the `Dockerfile`. -For example: - - ENV DIRPATH /path - WORKDIR $DIRPATH/$DIRNAME - RUN pwd - -The output of the final `pwd` command in this `Dockerfile` would be -`/path/$DIRNAME` - -## ARG - - ARG [=] - -The `ARG` instruction defines a variable that users can pass at build-time to -the builder with the `docker build` command using the `--build-arg =` -flag. If a user specifies a build argument that was not -defined in the Dockerfile, the build outputs a warning. - -``` -[Warning] One or more build-args [foo] were not consumed. -``` - -The Dockerfile author can define a single variable by specifying `ARG` once or many -variables by specifying `ARG` more than once. For example, a valid Dockerfile: - -``` -FROM busybox -ARG user1 -ARG buildno -... -``` - -A Dockerfile author may optionally specify a default value for an `ARG` instruction: - -``` -FROM busybox -ARG user1=someuser -ARG buildno=1 -... -``` - -If an `ARG` value has a default and if there is no value passed at build-time, the -builder uses the default. - -An `ARG` variable definition comes into effect from the line on which it is -defined in the `Dockerfile` not from the argument's use on the command-line or -elsewhere. For example, consider this Dockerfile: - -``` -1 FROM busybox -2 USER ${user:-some_user} -3 ARG user -4 USER $user -... -``` -A user builds this file by calling: - -``` -$ docker build --build-arg user=what_user Dockerfile -``` - -The `USER` at line 2 evaluates to `some_user` as the `user` variable is defined on the -subsequent line 3. The `USER` at line 4 evaluates to `what_user` as `user` is -defined and the `what_user` value was passed on the command line. Prior to its definition by an -`ARG` instruction, any use of a variable results in an empty string. - -> **Warning:** It is not recommended to use build-time variables for -> passing secrets like github keys, user credentials etc. Build-time variable -> values are visible to any user of the image with the `docker history` command. - -You can use an `ARG` or an `ENV` instruction to specify variables that are -available to the `RUN` instruction. Environment variables defined using the -`ENV` instruction always override an `ARG` instruction of the same name. Consider -this Dockerfile with an `ENV` and `ARG` instruction. - -``` -1 FROM ubuntu -2 ARG CONT_IMG_VER -3 ENV CONT_IMG_VER v1.0.0 -4 RUN echo $CONT_IMG_VER -``` -Then, assume this image is built with this command: - -``` -$ docker build --build-arg CONT_IMG_VER=v2.0.1 Dockerfile -``` - -In this case, the `RUN` instruction uses `v1.0.0` instead of the `ARG` setting -passed by the user:`v2.0.1` This behavior is similar to a shell -script where a locally scoped variable overrides the variables passed as -arguments or inherited from environment, from its point of definition. - -Using the example above but a different `ENV` specification you can create more -useful interactions between `ARG` and `ENV` instructions: - -``` -1 FROM ubuntu -2 ARG CONT_IMG_VER -3 ENV CONT_IMG_VER ${CONT_IMG_VER:-v1.0.0} -4 RUN echo $CONT_IMG_VER -``` - -Unlike an `ARG` instruction, `ENV` values are always persisted in the built -image. Consider a docker build without the `--build-arg` flag: - -``` -$ docker build Dockerfile -``` - -Using this Dockerfile example, `CONT_IMG_VER` is still persisted in the image but -its value would be `v1.0.0` as it is the default set in line 3 by the `ENV` instruction. - -The variable expansion technique in this example allows you to pass arguments -from the command line and persist them in the final image by leveraging the -`ENV` instruction. Variable expansion is only supported for [a limited set of -Dockerfile instructions.](#environment-replacement) - -Docker has a set of predefined `ARG` variables that you can use without a -corresponding `ARG` instruction in the Dockerfile. - -* `HTTP_PROXY` -* `http_proxy` -* `HTTPS_PROXY` -* `https_proxy` -* `FTP_PROXY` -* `ftp_proxy` -* `NO_PROXY` -* `no_proxy` - -To use these, simply pass them on the command line using the flag: - -``` ---build-arg = -``` - -### Impact on build caching - -`ARG` variables are not persisted into the built image as `ENV` variables are. -However, `ARG` variables do impact the build cache in similar ways. If a -Dockerfile defines an `ARG` variable whose value is different from a previous -build, then a "cache miss" occurs upon its first usage, not its definition. In -particular, all `RUN` instructions following an `ARG` instruction use the `ARG` -variable implicitly (as an environment variable), thus can cause a cache miss. - -For example, consider these two Dockerfile: - -``` -1 FROM ubuntu -2 ARG CONT_IMG_VER -3 RUN echo $CONT_IMG_VER -``` - -``` -1 FROM ubuntu -2 ARG CONT_IMG_VER -3 RUN echo hello -``` - -If you specify `--build-arg CONT_IMG_VER=` on the command line, in both -cases, the specification on line 2 does not cause a cache miss; line 3 does -cause a cache miss.`ARG CONT_IMG_VER` causes the RUN line to be identified -as the same as running `CONT_IMG_VER=` echo hello, so if the `` -changes, we get a cache miss. - -Consider another example under the same command line: - -``` -1 FROM ubuntu -2 ARG CONT_IMG_VER -3 ENV CONT_IMG_VER $CONT_IMG_VER -4 RUN echo $CONT_IMG_VER -``` -In this example, the cache miss occurs on line 3. The miss happens because -the variable's value in the `ENV` references the `ARG` variable and that -variable is changed through the command line. In this example, the `ENV` -command causes the image to include the value. - -If an `ENV` instruction overrides an `ARG` instruction of the same name, like -this Dockerfile: - -``` -1 FROM ubuntu -2 ARG CONT_IMG_VER -3 ENV CONT_IMG_VER hello -4 RUN echo $CONT_IMG_VER -``` - -Line 3 does not cause a cache miss because the value of `CONT_IMG_VER` is a -constant (`hello`). As a result, the environment variables and values used on -the `RUN` (line 4) doesn't change between builds. - -## ONBUILD - - ONBUILD [INSTRUCTION] - -The `ONBUILD` instruction adds to the image a *trigger* instruction to -be executed at a later time, when the image is used as the base for -another build. The trigger will be executed in the context of the -downstream build, as if it had been inserted immediately after the -`FROM` instruction in the downstream `Dockerfile`. - -Any build instruction can be registered as a trigger. - -This is useful if you are building an image which will be used as a base -to build other images, for example an application build environment or a -daemon which may be customized with user-specific configuration. - -For example, if your image is a reusable Python application builder, it -will require application source code to be added in a particular -directory, and it might require a build script to be called *after* -that. You can't just call `ADD` and `RUN` now, because you don't yet -have access to the application source code, and it will be different for -each application build. You could simply provide application developers -with a boilerplate `Dockerfile` to copy-paste into their application, but -that is inefficient, error-prone and difficult to update because it -mixes with application-specific code. - -The solution is to use `ONBUILD` to register advance instructions to -run later, during the next build stage. - -Here's how it works: - -1. When it encounters an `ONBUILD` instruction, the builder adds a - trigger to the metadata of the image being built. The instruction - does not otherwise affect the current build. -2. At the end of the build, a list of all triggers is stored in the - image manifest, under the key `OnBuild`. They can be inspected with - the `docker inspect` command. -3. Later the image may be used as a base for a new build, using the - `FROM` instruction. As part of processing the `FROM` instruction, - the downstream builder looks for `ONBUILD` triggers, and executes - them in the same order they were registered. If any of the triggers - fail, the `FROM` instruction is aborted which in turn causes the - build to fail. If all triggers succeed, the `FROM` instruction - completes and the build continues as usual. -4. Triggers are cleared from the final image after being executed. In - other words they are not inherited by "grand-children" builds. - -For example you might add something like this: - - [...] - ONBUILD ADD . /app/src - ONBUILD RUN /usr/local/bin/python-build --dir /app/src - [...] - -> **Warning**: Chaining `ONBUILD` instructions using `ONBUILD ONBUILD` isn't allowed. - -> **Warning**: The `ONBUILD` instruction may not trigger `FROM` or `MAINTAINER` instructions. - -## STOPSIGNAL - - STOPSIGNAL signal - -The `STOPSIGNAL` instruction sets the system call signal that will be sent to the container to exit. -This signal can be a valid unsigned number that matches a position in the kernel's syscall table, for instance 9, -or a signal name in the format SIGNAME, for instance SIGKILL. - -## HEALTHCHECK - -The `HEALTHCHECK` instruction has two forms: - -* `HEALTHCHECK [OPTIONS] CMD command` (check container health by running a command inside the container) -* `HEALTHCHECK NONE` (disable any healthcheck inherited from the base image) - -The `HEALTHCHECK` instruction tells Docker how to test a container to check that -it is still working. This can detect cases such as a web server that is stuck in -an infinite loop and unable to handle new connections, even though the server -process is still running. - -When a container has a healthcheck specified, it has a _health status_ in -addition to its normal status. This status is initially `starting`. Whenever a -health check passes, it becomes `healthy` (whatever state it was previously in). -After a certain number of consecutive failures, it becomes `unhealthy`. - -The options that can appear before `CMD` are: - -* `--interval=DURATION` (default: `30s`) -* `--timeout=DURATION` (default: `30s`) -* `--retries=N` (default: `3`) - -The health check will first run **interval** seconds after the container is -started, and then again **interval** seconds after each previous check completes. - -If a single run of the check takes longer than **timeout** seconds then the check -is considered to have failed. - -It takes **retries** consecutive failures of the health check for the container -to be considered `unhealthy`. - -There can only be one `HEALTHCHECK` instruction in a Dockerfile. If you list -more than one then only the last `HEALTHCHECK` will take effect. - -The command after the `CMD` keyword can be either a shell command (e.g. `HEALTHCHECK -CMD /bin/check-running`) or an _exec_ array (as with other Dockerfile commands; -see e.g. `ENTRYPOINT` for details). - -The command's exit status indicates the health status of the container. -The possible values are: - -- 0: success - the container is healthy and ready for use -- 1: unhealthy - the container is not working correctly -- 2: reserved - do not use this exit code - -For example, to check every five minutes or so that a web-server is able to -serve the site's main page within three seconds: - - HEALTHCHECK --interval=5m --timeout=3s \ - CMD curl -f http://localhost/ || exit 1 - -To help debug failing probes, any output text (UTF-8 encoded) that the command writes -on stdout or stderr will be stored in the health status and can be queried with -`docker inspect`. Such output should be kept short (only the first 4096 bytes -are stored currently). - -When the health status of a container changes, a `health_status` event is -generated with the new status. - -The `HEALTHCHECK` feature was added in Docker 1.12. - - -## SHELL - - SHELL ["executable", "parameters"] - -The `SHELL` instruction allows the default shell used for the *shell* form of -commands to be overridden. The default shell on Linux is `["/bin/sh", "-c"]`, and on -Windows is `["cmd", "/S", "/C"]`. The `SHELL` instruction *must* be written in JSON -form in a Dockerfile. - -The `SHELL` instruction is particularly useful on Windows where there are -two commonly used and quite different native shells: `cmd` and `powershell`, as -well as alternate shells available including `sh`. - -The `SHELL` instruction can appear multiple times. Each `SHELL` instruction overrides -all previous `SHELL` instructions, and affects all subsequent instructions. For example: - - FROM microsoft/windowsservercore - - # Executed as cmd /S /C echo default - RUN echo default - - # Executed as cmd /S /C powershell -command Write-Host default - RUN powershell -command Write-Host default - - # Executed as powershell -command Write-Host hello - SHELL ["powershell", "-command"] - RUN Write-Host hello - - # Executed as cmd /S /C echo hello - SHELL ["cmd", "/S"", "/C"] - RUN echo hello - -The following instructions can be affected by the `SHELL` instruction when the -*shell* form of them is used in a Dockerfile: `RUN`, `CMD` and `ENTRYPOINT`. - -The following example is a common pattern found on Windows which can be -streamlined by using the `SHELL` instruction: - - ... - RUN powershell -command Execute-MyCmdlet -param1 "c:\foo.txt" - ... - -The command invoked by docker will be: - - cmd /S /C powershell -command Execute-MyCmdlet -param1 "c:\foo.txt" - -This is inefficient for two reasons. First, there is an un-necessary cmd.exe command -processor (aka shell) being invoked. Second, each `RUN` instruction in the *shell* -form requires an extra `powershell -command` prefixing the command. - -To make this more efficient, one of two mechanisms can be employed. One is to -use the JSON form of the RUN command such as: - - ... - RUN ["powershell", "-command", "Execute-MyCmdlet", "-param1 \"c:\\foo.txt\""] - ... - -While the JSON form is unambiguous and does not use the un-necessary cmd.exe, -it does require more verbosity through double-quoting and escaping. The alternate -mechanism is to use the `SHELL` instruction and the *shell* form, -making a more natural syntax for Windows users, especially when combined with -the `escape` parser directive: - - # escape=` - - FROM microsoft/nanoserver - SHELL ["powershell","-command"] - RUN New-Item -ItemType Directory C:\Example - ADD Execute-MyCmdlet.ps1 c:\example\ - RUN c:\example\Execute-MyCmdlet -sample 'hello world' - -Resulting in: - - PS E:\docker\build\shell> docker build -t shell . - Sending build context to Docker daemon 4.096 kB - Step 1/5 : FROM microsoft/nanoserver - ---> 22738ff49c6d - Step 2/5 : SHELL powershell -command - ---> Running in 6fcdb6855ae2 - ---> 6331462d4300 - Removing intermediate container 6fcdb6855ae2 - Step 3/5 : RUN New-Item -ItemType Directory C:\Example - ---> Running in d0eef8386e97 - - - Directory: C:\ - - - Mode LastWriteTime Length Name - ---- ------------- ------ ---- - d----- 10/28/2016 11:26 AM Example - - - ---> 3f2fbf1395d9 - Removing intermediate container d0eef8386e97 - Step 4/5 : ADD Execute-MyCmdlet.ps1 c:\example\ - ---> a955b2621c31 - Removing intermediate container b825593d39fc - Step 5/5 : RUN c:\example\Execute-MyCmdlet 'hello world' - ---> Running in be6d8e63fe75 - hello world - ---> 8e559e9bf424 - Removing intermediate container be6d8e63fe75 - Successfully built 8e559e9bf424 - PS E:\docker\build\shell> - -The `SHELL` instruction could also be used to modify the way in which -a shell operates. For example, using `SHELL cmd /S /C /V:ON|OFF` on Windows, delayed -environment variable expansion semantics could be modified. - -The `SHELL` instruction can also be used on Linux should an alternate shell be -required such as `zsh`, `csh`, `tcsh` and others. - -The `SHELL` feature was added in Docker 1.12. - -## Dockerfile examples - -Below you can see some examples of Dockerfile syntax. If you're interested in -something more realistic, take a look at the list of [Dockerization examples](https://docs.docker.com/engine/examples/). - -``` -# Nginx -# -# VERSION 0.0.1 - -FROM ubuntu -LABEL Description="This image is used to start the foobar executable" Vendor="ACME Products" Version="1.0" -RUN apt-get update && apt-get install -y inotify-tools nginx apache2 openssh-server -``` - -``` -# Firefox over VNC -# -# VERSION 0.3 - -FROM ubuntu - -# Install vnc, xvfb in order to create a 'fake' display and firefox -RUN apt-get update && apt-get install -y x11vnc xvfb firefox -RUN mkdir ~/.vnc -# Setup a password -RUN x11vnc -storepasswd 1234 ~/.vnc/passwd -# Autostart firefox (might not be the best way, but it does the trick) -RUN bash -c 'echo "firefox" >> /.bashrc' - -EXPOSE 5900 -CMD ["x11vnc", "-forever", "-usepw", "-create"] -``` - -``` -# Multiple images example -# -# VERSION 0.1 - -FROM ubuntu -RUN echo foo > bar -# Will output something like ===> 907ad6c2736f - -FROM ubuntu -RUN echo moo > oink -# Will output something like ===> 695d7793cbe4 - -# You᾿ll now have two images, 907ad6c2736f with /bar, and 695d7793cbe4 with -# /oink. -``` diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/attach.md b/vendor/github.com/docker/docker/docs/reference/commandline/attach.md deleted file mode 100644 index 307068a..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/attach.md +++ /dev/null @@ -1,131 +0,0 @@ ---- -title: "attach" -description: "The attach command description and usage" -keywords: "attach, running, container" ---- - - - -# attach - -```markdown -Usage: docker attach [OPTIONS] CONTAINER - -Attach to a running container - -Options: - --detach-keys string Override the key sequence for detaching a container - --help Print usage - --no-stdin Do not attach STDIN - --sig-proxy Proxy all received signals to the process (default true) -``` - -Use `docker attach` to attach to a running container using the container's ID -or name, either to view its ongoing output or to control it interactively. -You can attach to the same contained process multiple times simultaneously, -screen sharing style, or quickly view the progress of your detached process. - -To stop a container, use `CTRL-c`. This key sequence sends `SIGKILL` to the -container. If `--sig-proxy` is true (the default),`CTRL-c` sends a `SIGINT` to -the container. You can detach from a container and leave it running using the - `CTRL-p CTRL-q` key sequence. - -> **Note:** -> A process running as PID 1 inside a container is treated specially by -> Linux: it ignores any signal with the default action. So, the process -> will not terminate on `SIGINT` or `SIGTERM` unless it is coded to do -> so. - -It is forbidden to redirect the standard input of a `docker attach` command -while attaching to a tty-enabled container (i.e.: launched with `-t`). - -While a client is connected to container's stdio using `docker attach`, Docker -uses a ~1MB memory buffer to maximize the throughput of the application. If -this buffer is filled, the speed of the API connection will start to have an -effect on the process output writing speed. This is similar to other -applications like SSH. Because of this, it is not recommended to run -performance critical applications that generate a lot of output in the -foreground over a slow client connection. Instead, users should use the -`docker logs` command to get access to the logs. - - -## Override the detach sequence - -If you want, you can configure an override the Docker key sequence for detach. -This is useful if the Docker default sequence conflicts with key sequence you -use for other applications. There are two ways to define your own detach key -sequence, as a per-container override or as a configuration property on your -entire configuration. - -To override the sequence for an individual container, use the -`--detach-keys=""` flag with the `docker attach` command. The format of -the `` is either a letter [a-Z], or the `ctrl-` combined with any of -the following: - -* `a-z` (a single lowercase alpha character ) -* `@` (at sign) -* `[` (left bracket) -* `\\` (two backward slashes) -* `_` (underscore) -* `^` (caret) - -These `a`, `ctrl-a`, `X`, or `ctrl-\\` values are all examples of valid key -sequences. To configure a different configuration default key sequence for all -containers, see [**Configuration file** section](cli.md#configuration-files). - -#### Examples - - $ docker run -d --name topdemo ubuntu /usr/bin/top -b - $ docker attach topdemo - top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05 - Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie - Cpu(s): 0.1%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st - Mem: 373572k total, 355560k used, 18012k free, 27872k buffers - Swap: 786428k total, 0k used, 786428k free, 221740k cached - - PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND - 1 root 20 0 17200 1116 912 R 0 0.3 0:00.03 top - - top - 02:05:55 up 3:05, 0 users, load average: 0.01, 0.02, 0.05 - Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie - Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st - Mem: 373572k total, 355244k used, 18328k free, 27872k buffers - Swap: 786428k total, 0k used, 786428k free, 221776k cached - - PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND - 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top - - - top - 02:05:58 up 3:06, 0 users, load average: 0.01, 0.02, 0.05 - Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie - Cpu(s): 0.2%us, 0.3%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st - Mem: 373572k total, 355780k used, 17792k free, 27880k buffers - Swap: 786428k total, 0k used, 786428k free, 221776k cached - - PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND - 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top - ^C$ - $ echo $? - 0 - $ docker ps -a | grep topdemo - 7998ac8581f9 ubuntu:14.04 "/usr/bin/top -b" 38 seconds ago Exited (0) 21 seconds ago topdemo - -And in this second example, you can see the exit code returned by the `bash` -process is returned by the `docker attach` command to its caller too: - - $ docker run --name test -d -it debian - 275c44472aebd77c926d4527885bb09f2f6db21d878c75f0a1c212c03d3bcfab - $ docker attach test - root@f38c87f2a42d:/# exit 13 - exit - $ echo $? - 13 - $ docker ps -a | grep test - 275c44472aeb debian:7 "/bin/bash" 26 seconds ago Exited (13) 17 seconds ago test diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/build.md b/vendor/github.com/docker/docker/docs/reference/commandline/build.md deleted file mode 100644 index 42c3ecf..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/build.md +++ /dev/null @@ -1,451 +0,0 @@ ---- -title: "build" -description: "The build command description and usage" -keywords: "build, docker, image" ---- - - - -# build - -```markdown -Usage: docker build [OPTIONS] PATH | URL | - - -Build an image from a Dockerfile - -Options: - --build-arg value Set build-time variables (default []) - --cache-from value Images to consider as cache sources (default []) - --cgroup-parent string Optional parent cgroup for the container - --compress Compress the build context using gzip - --cpu-period int Limit the CPU CFS (Completely Fair Scheduler) period - --cpu-quota int Limit the CPU CFS (Completely Fair Scheduler) quota - -c, --cpu-shares int CPU shares (relative weight) - --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) - --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) - --disable-content-trust Skip image verification (default true) - -f, --file string Name of the Dockerfile (Default is 'PATH/Dockerfile') - --force-rm Always remove intermediate containers - --help Print usage - --isolation string Container isolation technology - --label value Set metadata for an image (default []) - -m, --memory string Memory limit - --memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap - --network string Set the networking mode for the RUN instructions during build - 'bridge': use default Docker bridge - 'none': no networking - 'container:': reuse another container's network stack - 'host': use the Docker host network stack - '|': connect to a user-defined network - --no-cache Do not use cache when building the image - --pull Always attempt to pull a newer version of the image - -q, --quiet Suppress the build output and print image ID on success - --rm Remove intermediate containers after a successful build (default true) - --security-opt value Security Options (default []) - --shm-size string Size of /dev/shm, default value is 64MB. - The format is ``. `number` must be greater than `0`. - Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), - or `g` (gigabytes). If you omit the unit, the system uses bytes. - --squash Squash newly built layers into a single new layer (**Experimental Only**) - -t, --tag value Name and optionally a tag in the 'name:tag' format (default []) - --ulimit value Ulimit options (default []) -``` - -Builds Docker images from a Dockerfile and a "context". A build's context is -the files located in the specified `PATH` or `URL`. The build process can refer -to any of the files in the context. For example, your build can use an -[*ADD*](../builder.md#add) instruction to reference a file in the -context. - -The `URL` parameter can refer to three kinds of resources: Git repositories, -pre-packaged tarball contexts and plain text files. - -### Git repositories - -When the `URL` parameter points to the location of a Git repository, the -repository acts as the build context. The system recursively clones the -repository and its submodules using a `git clone --depth 1 --recursive` -command. This command runs in a temporary directory on your local host. After -the command succeeds, the directory is sent to the Docker daemon as the -context. Local clones give you the ability to access private repositories using -local user credentials, VPN's, and so forth. - -Git URLs accept context configuration in their fragment section, separated by a -colon `:`. The first part represents the reference that Git will check out, -this can be either a branch, a tag, or a commit SHA. The second part represents -a subdirectory inside the repository that will be used as a build context. - -For example, run this command to use a directory called `docker` in the branch -`container`: - -```bash -$ docker build https://github.com/docker/rootfs.git#container:docker -``` - -The following table represents all the valid suffixes with their build -contexts: - -Build Syntax Suffix | Commit Used | Build Context Used ---------------------------------|-----------------------|------------------- -`myrepo.git` | `refs/heads/master` | `/` -`myrepo.git#mytag` | `refs/tags/mytag` | `/` -`myrepo.git#mybranch` | `refs/heads/mybranch` | `/` -`myrepo.git#abcdef` | `sha1 = abcdef` | `/` -`myrepo.git#:myfolder` | `refs/heads/master` | `/myfolder` -`myrepo.git#master:myfolder` | `refs/heads/master` | `/myfolder` -`myrepo.git#mytag:myfolder` | `refs/tags/mytag` | `/myfolder` -`myrepo.git#mybranch:myfolder` | `refs/heads/mybranch` | `/myfolder` -`myrepo.git#abcdef:myfolder` | `sha1 = abcdef` | `/myfolder` - - -### Tarball contexts - -If you pass an URL to a remote tarball, the URL itself is sent to the daemon: - -Instead of specifying a context, you can pass a single Dockerfile in the `URL` -or pipe the file in via `STDIN`. To pipe a Dockerfile from `STDIN`: - -```bash -$ docker build http://server/context.tar.gz -``` - -The download operation will be performed on the host the Docker daemon is -running on, which is not necessarily the same host from which the build command -is being issued. The Docker daemon will fetch `context.tar.gz` and use it as the -build context. Tarball contexts must be tar archives conforming to the standard -`tar` UNIX format and can be compressed with any one of the 'xz', 'bzip2', -'gzip' or 'identity' (no compression) formats. - -### Text files - -Instead of specifying a context, you can pass a single `Dockerfile` in the -`URL` or pipe the file in via `STDIN`. To pipe a `Dockerfile` from `STDIN`: - -```bash -$ docker build - < Dockerfile -``` - -With Powershell on Windows, you can run: - -```powershell -Get-Content Dockerfile | docker build - -``` - -If you use `STDIN` or specify a `URL` pointing to a plain text file, the system -places the contents into a file called `Dockerfile`, and any `-f`, `--file` -option is ignored. In this scenario, there is no context. - -By default the `docker build` command will look for a `Dockerfile` at the root -of the build context. The `-f`, `--file`, option lets you specify the path to -an alternative file to use instead. This is useful in cases where the same set -of files are used for multiple builds. The path must be to a file within the -build context. If a relative path is specified then it is interpreted as -relative to the root of the context. - -In most cases, it's best to put each Dockerfile in an empty directory. Then, -add to that directory only the files needed for building the Dockerfile. To -increase the build's performance, you can exclude files and directories by -adding a `.dockerignore` file to that directory as well. For information on -creating one, see the [.dockerignore file](../builder.md#dockerignore-file). - -If the Docker client loses connection to the daemon, the build is canceled. -This happens if you interrupt the Docker client with `CTRL-c` or if the Docker -client is killed for any reason. If the build initiated a pull which is still -running at the time the build is cancelled, the pull is cancelled as well. - -## Return code - -On a successful build, a return code of success `0` will be returned. When the -build fails, a non-zero failure code will be returned. - -There should be informational output of the reason for failure output to -`STDERR`: - -```bash -$ docker build -t fail . - -Sending build context to Docker daemon 2.048 kB -Sending build context to Docker daemon -Step 1/3 : FROM busybox - ---> 4986bf8c1536 -Step 2/3 : RUN exit 13 - ---> Running in e26670ec7a0a -INFO[0000] The command [/bin/sh -c exit 13] returned a non-zero code: 13 -$ echo $? -1 -``` - -See also: - -[*Dockerfile Reference*](../builder.md). - -## Examples - -### Build with PATH - -```bash -$ docker build . - -Uploading context 10240 bytes -Step 1/3 : FROM busybox -Pulling repository busybox - ---> e9aa60c60128MB/2.284 MB (100%) endpoint: https://cdn-registry-1.docker.io/v1/ -Step 2/3 : RUN ls -lh / - ---> Running in 9c9e81692ae9 -total 24 -drwxr-xr-x 2 root root 4.0K Mar 12 2013 bin -drwxr-xr-x 5 root root 4.0K Oct 19 00:19 dev -drwxr-xr-x 2 root root 4.0K Oct 19 00:19 etc -drwxr-xr-x 2 root root 4.0K Nov 15 23:34 lib -lrwxrwxrwx 1 root root 3 Mar 12 2013 lib64 -> lib -dr-xr-xr-x 116 root root 0 Nov 15 23:34 proc -lrwxrwxrwx 1 root root 3 Mar 12 2013 sbin -> bin -dr-xr-xr-x 13 root root 0 Nov 15 23:34 sys -drwxr-xr-x 2 root root 4.0K Mar 12 2013 tmp -drwxr-xr-x 2 root root 4.0K Nov 15 23:34 usr - ---> b35f4035db3f -Step 3/3 : CMD echo Hello world - ---> Running in 02071fceb21b - ---> f52f38b7823e -Successfully built f52f38b7823e -Removing intermediate container 9c9e81692ae9 -Removing intermediate container 02071fceb21b -``` - -This example specifies that the `PATH` is `.`, and so all the files in the -local directory get `tar`d and sent to the Docker daemon. The `PATH` specifies -where to find the files for the "context" of the build on the Docker daemon. -Remember that the daemon could be running on a remote machine and that no -parsing of the Dockerfile happens at the client side (where you're running -`docker build`). That means that *all* the files at `PATH` get sent, not just -the ones listed to [*ADD*](../builder.md#add) in the Dockerfile. - -The transfer of context from the local machine to the Docker daemon is what the -`docker` client means when you see the "Sending build context" message. - -If you wish to keep the intermediate containers after the build is complete, -you must use `--rm=false`. This does not affect the build cache. - -### Build with URL - -```bash -$ docker build github.com/creack/docker-firefox -``` - -This will clone the GitHub repository and use the cloned repository as context. -The Dockerfile at the root of the repository is used as Dockerfile. You can -specify an arbitrary Git repository by using the `git://` or `git@` scheme. - -```bash -$ docker build -f ctx/Dockerfile http://server/ctx.tar.gz - -Downloading context: http://server/ctx.tar.gz [===================>] 240 B/240 B -Step 1/3 : FROM busybox - ---> 8c2e06607696 -Step 2/3 : ADD ctx/container.cfg / - ---> e7829950cee3 -Removing intermediate container b35224abf821 -Step 3/3 : CMD /bin/ls - ---> Running in fbc63d321d73 - ---> 3286931702ad -Removing intermediate container fbc63d321d73 -Successfully built 377c409b35e4 -``` - -This sends the URL `http://server/ctx.tar.gz` to the Docker daemon, which -downloads and extracts the referenced tarball. The `-f ctx/Dockerfile` -parameter specifies a path inside `ctx.tar.gz` to the `Dockerfile` that is used -to build the image. Any `ADD` commands in that `Dockerfile` that refer to local -paths must be relative to the root of the contents inside `ctx.tar.gz`. In the -example above, the tarball contains a directory `ctx/`, so the `ADD -ctx/container.cfg /` operation works as expected. - -### Build with - - -```bash -$ docker build - < Dockerfile -``` - -This will read a Dockerfile from `STDIN` without context. Due to the lack of a -context, no contents of any local directory will be sent to the Docker daemon. -Since there is no context, a Dockerfile `ADD` only works if it refers to a -remote URL. - -```bash -$ docker build - < context.tar.gz -``` - -This will build an image for a compressed context read from `STDIN`. Supported -formats are: bzip2, gzip and xz. - -### Usage of .dockerignore - -```bash -$ docker build . - -Uploading context 18.829 MB -Uploading context -Step 1/2 : FROM busybox - ---> 769b9341d937 -Step 2/2 : CMD echo Hello world - ---> Using cache - ---> 99cc1ad10469 -Successfully built 99cc1ad10469 -$ echo ".git" > .dockerignore -$ docker build . -Uploading context 6.76 MB -Uploading context -Step 1/2 : FROM busybox - ---> 769b9341d937 -Step 2/2 : CMD echo Hello world - ---> Using cache - ---> 99cc1ad10469 -Successfully built 99cc1ad10469 -``` - -This example shows the use of the `.dockerignore` file to exclude the `.git` -directory from the context. Its effect can be seen in the changed size of the -uploaded context. The builder reference contains detailed information on -[creating a .dockerignore file](../builder.md#dockerignore-file) - -### Tag image (-t) - -```bash -$ docker build -t vieux/apache:2.0 . -``` - -This will build like the previous example, but it will then tag the resulting -image. The repository name will be `vieux/apache` and the tag will be `2.0`. -[Read more about valid tags](tag.md). - -You can apply multiple tags to an image. For example, you can apply the `latest` -tag to a newly built image and add another tag that references a specific -version. -For example, to tag an image both as `whenry/fedora-jboss:latest` and -`whenry/fedora-jboss:v2.1`, use the following: - -```bash -$ docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 . -``` -### Specify Dockerfile (-f) - -```bash -$ docker build -f Dockerfile.debug . -``` - -This will use a file called `Dockerfile.debug` for the build instructions -instead of `Dockerfile`. - -```bash -$ docker build -f dockerfiles/Dockerfile.debug -t myapp_debug . -$ docker build -f dockerfiles/Dockerfile.prod -t myapp_prod . -``` - -The above commands will build the current build context (as specified by the -`.`) twice, once using a debug version of a `Dockerfile` and once using a -production version. - -```bash -$ cd /home/me/myapp/some/dir/really/deep -$ docker build -f /home/me/myapp/dockerfiles/debug /home/me/myapp -$ docker build -f ../../../../dockerfiles/debug /home/me/myapp -``` - -These two `docker build` commands do the exact same thing. They both use the -contents of the `debug` file instead of looking for a `Dockerfile` and will use -`/home/me/myapp` as the root of the build context. Note that `debug` is in the -directory structure of the build context, regardless of how you refer to it on -the command line. - -> **Note:** -> `docker build` will return a `no such file or directory` error if the -> file or directory does not exist in the uploaded context. This may -> happen if there is no context, or if you specify a file that is -> elsewhere on the Host system. The context is limited to the current -> directory (and its children) for security reasons, and to ensure -> repeatable builds on remote Docker hosts. This is also the reason why -> `ADD ../file` will not work. - -### Optional parent cgroup (--cgroup-parent) - -When `docker build` is run with the `--cgroup-parent` option the containers -used in the build will be run with the [corresponding `docker run` -flag](../run.md#specifying-custom-cgroups). - -### Set ulimits in container (--ulimit) - -Using the `--ulimit` option with `docker build` will cause each build step's -container to be started using those [`--ulimit` -flag values](./run.md#set-ulimits-in-container-ulimit). - -### Set build-time variables (--build-arg) - -You can use `ENV` instructions in a Dockerfile to define variable -values. These values persist in the built image. However, often -persistence is not what you want. Users want to specify variables differently -depending on which host they build an image on. - -A good example is `http_proxy` or source versions for pulling intermediate -files. The `ARG` instruction lets Dockerfile authors define values that users -can set at build-time using the `--build-arg` flag: - -```bash -$ docker build --build-arg HTTP_PROXY=http://10.20.30.2:1234 . -``` - -This flag allows you to pass the build-time variables that are -accessed like regular environment variables in the `RUN` instruction of the -Dockerfile. Also, these values don't persist in the intermediate or final images -like `ENV` values do. - -Using this flag will not alter the output you see when the `ARG` lines from the -Dockerfile are echoed during the build process. - -For detailed information on using `ARG` and `ENV` instructions, see the -[Dockerfile reference](../builder.md). - -### Optional security options (--security-opt) - -This flag is only supported on a daemon running on Windows, and only supports -the `credentialspec` option. The `credentialspec` must be in the format -`file://spec.txt` or `registry://keyname`. - -### Specify isolation technology for container (--isolation) - -This option is useful in situations where you are running Docker containers on -Windows. The `--isolation=` option sets a container's isolation -technology. On Linux, the only supported is the `default` option which uses -Linux namespaces. On Microsoft Windows, you can specify these values: - - -| Value | Description | -|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `default` | Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value. | -| `process` | Namespace isolation only. | -| `hyperv` | Hyper-V hypervisor partition-based isolation. | - -Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`. - - -### Squash an image's layers (--squash) **Experimental Only** - -Once the image is built, squash the new layers into a new image with a single -new layer. Squashing does not destroy any existing image, rather it creates a new -image with the content of the squshed layers. This effectively makes it look -like all `Dockerfile` commands were created with a single layer. The build -cache is preserved with this method. - -**Note**: using this option means the new image will not be able to take -advantage of layer sharing with other images and may use significantly more -space. - -**Note**: using this option you may see significantly more space used due to -storing two copies of the image, one for the build cache with all the cache -layers in tact, and one for the squashed version. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/cli.md b/vendor/github.com/docker/docker/docs/reference/commandline/cli.md deleted file mode 100644 index e56fb9f..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/cli.md +++ /dev/null @@ -1,249 +0,0 @@ ---- -title: "Use the Docker command line" -description: "Docker's CLI command description and usage" -keywords: "Docker, Docker documentation, CLI, command line" ---- - - - -# Use the Docker command line - -To list available commands, either run `docker` with no parameters -or execute `docker help`: - -```bash -$ docker -Usage: docker [OPTIONS] COMMAND [ARG...] - docker [ --help | -v | --version ] - -A self-sufficient runtime for containers. - -Options: - --config string Location of client config files (default "/root/.docker") - -D, --debug Enable debug mode - --help Print usage - -H, --host value Daemon socket(s) to connect to (default []) - -l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info") - --tls Use TLS; implied by --tlsverify - --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") - --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") - --tlskey string Path to TLS key file (default "/root/.docker/key.pem") - --tlsverify Use TLS and verify the remote - -v, --version Print version information and quit - -Commands: - attach Attach to a running container - # […] -``` - -Depending on your Docker system configuration, you may be required to preface -each `docker` command with `sudo`. To avoid having to use `sudo` with the -`docker` command, your system administrator can create a Unix group called -`docker` and add users to it. - -For more information about installing Docker or `sudo` configuration, refer to -the [installation](https://docs.docker.com/engine/installation/) instructions for your operating system. - -## Environment variables - -For easy reference, the following list of environment variables are supported -by the `docker` command line: - -* `DOCKER_API_VERSION` The API version to use (e.g. `1.19`) -* `DOCKER_CONFIG` The location of your client configuration files. -* `DOCKER_CERT_PATH` The location of your authentication keys. -* `DOCKER_DRIVER` The graph driver to use. -* `DOCKER_HOST` Daemon socket to connect to. -* `DOCKER_NOWARN_KERNEL_VERSION` Prevent warnings that your Linux kernel is - unsuitable for Docker. -* `DOCKER_RAMDISK` If set this will disable 'pivot_root'. -* `DOCKER_TLS_VERIFY` When set Docker uses TLS and verifies the remote. -* `DOCKER_CONTENT_TRUST` When set Docker uses notary to sign and verify images. - Equates to `--disable-content-trust=false` for build, create, pull, push, run. -* `DOCKER_CONTENT_TRUST_SERVER` The URL of the Notary server to use. This defaults - to the same URL as the registry. -* `DOCKER_HIDE_LEGACY_COMMANDS` When set, Docker hides "legacy" top-level commands (such as `docker rm`, and - `docker pull`) in `docker help` output, and only `Management commands` per object-type (e.g., `docker container`) are - printed. This may become the default in a future release, at which point this environment-variable is removed. -* `DOCKER_TMPDIR` Location for temporary Docker files. - -Because Docker is developed using Go, you can also use any environment -variables used by the Go runtime. In particular, you may find these useful: - -* `HTTP_PROXY` -* `HTTPS_PROXY` -* `NO_PROXY` - -These Go environment variables are case-insensitive. See the -[Go specification](http://golang.org/pkg/net/http/) for details on these -variables. - -## Configuration files - -By default, the Docker command line stores its configuration files in a -directory called `.docker` within your `$HOME` directory. However, you can -specify a different location via the `DOCKER_CONFIG` environment variable -or the `--config` command line option. If both are specified, then the -`--config` option overrides the `DOCKER_CONFIG` environment variable. -For example: - - docker --config ~/testconfigs/ ps - -Instructs Docker to use the configuration files in your `~/testconfigs/` -directory when running the `ps` command. - -Docker manages most of the files in the configuration directory -and you should not modify them. However, you *can modify* the -`config.json` file to control certain aspects of how the `docker` -command behaves. - -Currently, you can modify the `docker` command behavior using environment -variables or command-line options. You can also use options within -`config.json` to modify some of the same behavior. When using these -mechanisms, you must keep in mind the order of precedence among them. Command -line options override environment variables and environment variables override -properties you specify in a `config.json` file. - -The `config.json` file stores a JSON encoding of several properties: - -The property `HttpHeaders` specifies a set of headers to include in all messages -sent from the Docker client to the daemon. Docker does not try to interpret or -understand these header; it simply puts them into the messages. Docker does -not allow these headers to change any headers it sets for itself. - -The property `psFormat` specifies the default format for `docker ps` output. -When the `--format` flag is not provided with the `docker ps` command, -Docker's client uses this property. If this property is not set, the client -falls back to the default table format. For a list of supported formatting -directives, see the -[**Formatting** section in the `docker ps` documentation](ps.md) - -The property `imagesFormat` specifies the default format for `docker images` output. -When the `--format` flag is not provided with the `docker images` command, -Docker's client uses this property. If this property is not set, the client -falls back to the default table format. For a list of supported formatting -directives, see the [**Formatting** section in the `docker images` documentation](images.md) - -The property `serviceInspectFormat` specifies the default format for `docker -service inspect` output. When the `--format` flag is not provided with the -`docker service inspect` command, Docker's client uses this property. If this -property is not set, the client falls back to the default json format. For a -list of supported formatting directives, see the -[**Formatting** section in the `docker service inspect` documentation](service_inspect.md) - -The property `statsFormat` specifies the default format for `docker -stats` output. When the `--format` flag is not provided with the -`docker stats` command, Docker's client uses this property. If this -property is not set, the client falls back to the default table -format. For a list of supported formatting directives, see -[**Formatting** section in the `docker stats` documentation](stats.md) - -Once attached to a container, users detach from it and leave it running using -the using `CTRL-p CTRL-q` key sequence. This detach key sequence is customizable -using the `detachKeys` property. Specify a `` value for the -property. The format of the `` is a comma-separated list of either -a letter [a-Z], or the `ctrl-` combined with any of the following: - -* `a-z` (a single lowercase alpha character ) -* `@` (at sign) -* `[` (left bracket) -* `\\` (two backward slashes) -* `_` (underscore) -* `^` (caret) - -Your customization applies to all containers started in with your Docker client. -Users can override your custom or the default key sequence on a per-container -basis. To do this, the user specifies the `--detach-keys` flag with the `docker -attach`, `docker exec`, `docker run` or `docker start` command. - -Following is a sample `config.json` file: - - {% raw %} - { - "HttpHeaders": { - "MyHeader": "MyValue" - }, - "psFormat": "table {{.ID}}\\t{{.Image}}\\t{{.Command}}\\t{{.Labels}}", - "imagesFormat": "table {{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.CreatedAt}}", - "statsFormat": "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}", - "serviceInspectFormat": "pretty", - "detachKeys": "ctrl-e,e" - } - {% endraw %} - -### Notary - -If using your own notary server and a self-signed certificate or an internal -Certificate Authority, you need to place the certificate at -`tls//ca.crt` in your docker config directory. - -Alternatively you can trust the certificate globally by adding it to your system's -list of root Certificate Authorities. - -## Help - -To list the help on any command just execute the command, followed by the -`--help` option. - - $ docker run --help - - Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] - - Run a command in a new container - - Options: - --add-host value Add a custom host-to-IP mapping (host:ip) (default []) - -a, --attach value Attach to STDIN, STDOUT or STDERR (default []) - ... - -## Option types - -Single character command line options can be combined, so rather than -typing `docker run -i -t --name test busybox sh`, -you can write `docker run -it --name test busybox sh`. - -### Boolean - -Boolean options take the form `-d=false`. The value you see in the help text is -the default value which is set if you do **not** specify that flag. If you -specify a Boolean flag without a value, this will set the flag to `true`, -irrespective of the default value. - -For example, running `docker run -d` will set the value to `true`, so your -container **will** run in "detached" mode, in the background. - -Options which default to `true` (e.g., `docker build --rm=true`) can only be -set to the non-default value by explicitly setting them to `false`: - - $ docker build --rm=false . - -### Multi - -You can specify options like `-a=[]` multiple times in a single command line, -for example in these commands: - - $ docker run -a stdin -a stdout -i -t ubuntu /bin/bash - $ docker run -a stdin -a stdout -a stderr ubuntu /bin/ls - -Sometimes, multiple options can call for a more complex value string as for -`-v`: - - $ docker run -v /host:/container example/mysql - -> **Note:** -> Do not use the `-t` and `-a stderr` options together due to -> limitations in the `pty` implementation. All `stderr` in `pty` mode -> simply goes to `stdout`. - -### Strings and Integers - -Options like `--name=""` expect a string, and they -can only be specified once. Options like `-c=0` -expect an integer, and they can only be specified once. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/commit.md b/vendor/github.com/docker/docker/docs/reference/commandline/commit.md deleted file mode 100644 index 8f971a5..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/commit.md +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: "commit" -description: "The commit command description and usage" -keywords: "commit, file, changes" ---- - - - -# commit - -```markdown -Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] - -Create a new image from a container's changes - -Options: - -a, --author string Author (e.g., "John Hannibal Smith ") - -c, --change value Apply Dockerfile instruction to the created image (default []) - --help Print usage - -m, --message string Commit message - -p, --pause Pause container during commit (default true) -``` - -It can be useful to commit a container's file changes or settings into a new -image. This allows you debug a container by running an interactive shell, or to -export a working dataset to another server. Generally, it is better to use -Dockerfiles to manage your images in a documented and maintainable way. -[Read more about valid image names and tags](tag.md). - -The commit operation will not include any data contained in -volumes mounted inside the container. - -By default, the container being committed and its processes will be paused -while the image is committed. This reduces the likelihood of encountering data -corruption during the process of creating the commit. If this behavior is -undesired, set the `--pause` option to false. - -The `--change` option will apply `Dockerfile` instructions to the image that is -created. Supported `Dockerfile` instructions: -`CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`LABEL`|`ONBUILD`|`USER`|`VOLUME`|`WORKDIR` - -## Commit a container - - $ docker ps - ID IMAGE COMMAND CREATED STATUS PORTS - c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours - 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours - $ docker commit c3f279d17e0a svendowideit/testimage:version3 - f5283438590d - $ docker images - REPOSITORY TAG ID CREATED SIZE - svendowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB - -## Commit a container with new configurations - - {% raw %} - $ docker ps - ID IMAGE COMMAND CREATED STATUS PORTS - c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours - 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours - $ docker inspect -f "{{ .Config.Env }}" c3f279d17e0a - [HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin] - $ docker commit --change "ENV DEBUG true" c3f279d17e0a svendowideit/testimage:version3 - f5283438590d - $ docker inspect -f "{{ .Config.Env }}" f5283438590d - [HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DEBUG=true] - {% endraw %} - -## Commit a container with new `CMD` and `EXPOSE` instructions - - $ docker ps - ID IMAGE COMMAND CREATED STATUS PORTS - c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours - 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours - - $ docker commit --change='CMD ["apachectl", "-DFOREGROUND"]' -c "EXPOSE 80" c3f279d17e0a svendowideit/testimage:version4 - f5283438590d - - $ docker run -d svendowideit/testimage:version4 - 89373736e2e7f00bc149bd783073ac43d0507da250e999f3f1036e0db60817c0 - - $ docker ps - ID IMAGE COMMAND CREATED STATUS PORTS - 89373736e2e7 testimage:version4 "apachectl -DFOREGROU" 3 seconds ago Up 2 seconds 80/tcp - c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours - 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/container_prune.md b/vendor/github.com/docker/docker/docs/reference/commandline/container_prune.md deleted file mode 100644 index 4315640..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/container_prune.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: "container prune" -description: "Remove all stopped containers" -keywords: container, prune, delete, remove ---- - - - -# container prune - -```markdown -Usage: docker container prune [OPTIONS] - -Remove all stopped containers - -Options: - -f, --force Do not prompt for confirmation - --help Print usage -``` - -## Examples - -```bash -$ docker container prune -WARNING! This will remove all stopped containers. -Are you sure you want to continue? [y/N] y -Deleted Containers: -4a7f7eebae0f63178aff7eb0aa39cd3f0627a203ab2df258c1a00b456cf20063 -f98f9c2aa1eaf727e4ec9c0283bc7d4aa4762fbdba7f26191f26c97f64090360 - -Total reclaimed space: 212 B -``` - -## Related information - -* [system df](system_df.md) -* [volume prune](volume_prune.md) -* [image prune](image_prune.md) -* [network prune](network_prune.md) -* [system prune](system_prune.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/cp.md b/vendor/github.com/docker/docker/docs/reference/commandline/cp.md deleted file mode 100644 index fcfd35f..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/cp.md +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: "cp" -description: "The cp command description and usage" -keywords: "copy, container, files, folders" ---- - - - -# cp - -```markdown -Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- - docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH - -Copy files/folders between a container and the local filesystem - -Use '-' as the source to read a tar archive from stdin -and extract it to a directory destination in a container. -Use '-' as the destination to stream a tar archive of a -container source to stdout. - -Options: - -L, --follow-link Always follow symbol link in SRC_PATH - --help Print usage -``` - -The `docker cp` utility copies the contents of `SRC_PATH` to the `DEST_PATH`. -You can copy from the container's file system to the local machine or the -reverse, from the local filesystem to the container. If `-` is specified for -either the `SRC_PATH` or `DEST_PATH`, you can also stream a tar archive from -`STDIN` or to `STDOUT`. The `CONTAINER` can be a running or stopped container. -The `SRC_PATH` or `DEST_PATH` can be a file or directory. - -The `docker cp` command assumes container paths are relative to the container's -`/` (root) directory. This means supplying the initial forward slash is optional; -The command sees `compassionate_darwin:/tmp/foo/myfile.txt` and -`compassionate_darwin:tmp/foo/myfile.txt` as identical. Local machine paths can -be an absolute or relative value. The command interprets a local machine's -relative paths as relative to the current working directory where `docker cp` is -run. - -The `cp` command behaves like the Unix `cp -a` command in that directories are -copied recursively with permissions preserved if possible. Ownership is set to -the user and primary group at the destination. For example, files copied to a -container are created with `UID:GID` of the root user. Files copied to the local -machine are created with the `UID:GID` of the user which invoked the `docker cp` -command. If you specify the `-L` option, `docker cp` follows any symbolic link -in the `SRC_PATH`. `docker cp` does *not* create parent directories for -`DEST_PATH` if they do not exist. - -Assuming a path separator of `/`, a first argument of `SRC_PATH` and second -argument of `DEST_PATH`, the behavior is as follows: - -- `SRC_PATH` specifies a file - - `DEST_PATH` does not exist - - the file is saved to a file created at `DEST_PATH` - - `DEST_PATH` does not exist and ends with `/` - - Error condition: the destination directory must exist. - - `DEST_PATH` exists and is a file - - the destination is overwritten with the source file's contents - - `DEST_PATH` exists and is a directory - - the file is copied into this directory using the basename from - `SRC_PATH` -- `SRC_PATH` specifies a directory - - `DEST_PATH` does not exist - - `DEST_PATH` is created as a directory and the *contents* of the source - directory are copied into this directory - - `DEST_PATH` exists and is a file - - Error condition: cannot copy a directory to a file - - `DEST_PATH` exists and is a directory - - `SRC_PATH` does not end with `/.` - - the source directory is copied into this directory - - `SRC_PATH` does end with `/.` - - the *content* of the source directory is copied into this - directory - -The command requires `SRC_PATH` and `DEST_PATH` to exist according to the above -rules. If `SRC_PATH` is local and is a symbolic link, the symbolic link, not -the target, is copied by default. To copy the link target and not the link, specify -the `-L` option. - -A colon (`:`) is used as a delimiter between `CONTAINER` and its path. You can -also use `:` when specifying paths to a `SRC_PATH` or `DEST_PATH` on a local -machine, for example `file:name.txt`. If you use a `:` in a local machine path, -you must be explicit with a relative or absolute path, for example: - - `/path/to/file:name.txt` or `./file:name.txt` - -It is not possible to copy certain system files such as resources under -`/proc`, `/sys`, `/dev`, [tmpfs](run.md#mount-tmpfs-tmpfs), and mounts created by -the user in the container. However, you can still copy such files by manually -running `tar` in `docker exec`. For example (consider `SRC_PATH` and `DEST_PATH` -are directories): - - $ docker exec foo tar Ccf $(dirname SRC_PATH) - $(basename SRC_PATH) | tar Cxf DEST_PATH - - -or - - $ tar Ccf $(dirname SRC_PATH) - $(basename SRC_PATH) | docker exec -i foo tar Cxf DEST_PATH - - - -Using `-` as the `SRC_PATH` streams the contents of `STDIN` as a tar archive. -The command extracts the content of the tar to the `DEST_PATH` in container's -filesystem. In this case, `DEST_PATH` must specify a directory. Using `-` as -the `DEST_PATH` streams the contents of the resource as a tar archive to `STDOUT`. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/create.md b/vendor/github.com/docker/docker/docs/reference/commandline/create.md deleted file mode 100644 index e6582e4..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/create.md +++ /dev/null @@ -1,211 +0,0 @@ ---- -title: "create" -description: "The create command description and usage" -keywords: "docker, create, container" ---- - - - -# create - -Creates a new container. - -```markdown -Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...] - -Create a new container - -Options: - --add-host value Add a custom host-to-IP mapping (host:ip) (default []) - -a, --attach value Attach to STDIN, STDOUT or STDERR (default []) - --blkio-weight value Block IO (relative weight), between 10 and 1000 - --blkio-weight-device value Block IO weight (relative device weight) (default []) - --cap-add value Add Linux capabilities (default []) - --cap-drop value Drop Linux capabilities (default []) - --cgroup-parent string Optional parent cgroup for the container - --cidfile string Write the container ID to the file - --cpu-count int The number of CPUs available for execution by the container. - Windows daemon only. On Windows Server containers, this is - approximated as a percentage of total CPU usage. - --cpu-percent int CPU percent (Windows only) - --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period - --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota - -c, --cpu-shares int CPU shares (relative weight) - --cpus NanoCPUs Number of CPUs (default 0.000) - --cpu-rt-period int Limit the CPU real-time period in microseconds - --cpu-rt-runtime int Limit the CPU real-time runtime in microseconds - --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) - --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) - --device value Add a host device to the container (default []) - --device-read-bps value Limit read rate (bytes per second) from a device (default []) - --device-read-iops value Limit read rate (IO per second) from a device (default []) - --device-write-bps value Limit write rate (bytes per second) to a device (default []) - --device-write-iops value Limit write rate (IO per second) to a device (default []) - --disable-content-trust Skip image verification (default true) - --dns value Set custom DNS servers (default []) - --dns-option value Set DNS options (default []) - --dns-search value Set custom DNS search domains (default []) - --entrypoint string Overwrite the default ENTRYPOINT of the image - -e, --env value Set environment variables (default []) - --env-file value Read in a file of environment variables (default []) - --expose value Expose a port or a range of ports (default []) - --group-add value Add additional groups to join (default []) - --health-cmd string Command to run to check health - --health-interval duration Time between running the check (ns|us|ms|s|m|h) (default 0s) - --health-retries int Consecutive failures needed to report unhealthy - --health-timeout duration Maximum time to allow one check to run (ns|us|ms|s|m|h) (default 0s) - --help Print usage - -h, --hostname string Container host name - --init Run an init inside the container that forwards signals and reaps processes - --init-path string Path to the docker-init binary - -i, --interactive Keep STDIN open even if not attached - --io-maxbandwidth string Maximum IO bandwidth limit for the system drive (Windows only) - --io-maxiops uint Maximum IOps limit for the system drive (Windows only) - --ip string Container IPv4 address (e.g. 172.30.100.104) - --ip6 string Container IPv6 address (e.g. 2001:db8::33) - --ipc string IPC namespace to use - --isolation string Container isolation technology - --kernel-memory string Kernel memory limit - -l, --label value Set meta data on a container (default []) - --label-file value Read in a line delimited file of labels (default []) - --link value Add link to another container (default []) - --link-local-ip value Container IPv4/IPv6 link-local addresses (default []) - --log-driver string Logging driver for the container - --log-opt value Log driver options (default []) - --mac-address string Container MAC address (e.g. 92:d0:c6:0a:29:33) - -m, --memory string Memory limit - --memory-reservation string Memory soft limit - --memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap - --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) - --name string Assign a name to the container - --network-alias value Add network-scoped alias for the container (default []) - --network string Connect a container to a network (default "default") - 'bridge': create a network stack on the default Docker bridge - 'none': no networking - 'container:': reuse another container's network stack - 'host': use the Docker host network stack - '|': connect to a user-defined network - --no-healthcheck Disable any container-specified HEALTHCHECK - --oom-kill-disable Disable OOM Killer - --oom-score-adj int Tune host's OOM preferences (-1000 to 1000) - --pid string PID namespace to use - --pids-limit int Tune container pids limit (set -1 for unlimited), kernel >= 4.3 - --privileged Give extended privileges to this container - -p, --publish value Publish a container's port(s) to the host (default []) - -P, --publish-all Publish all exposed ports to random ports - --read-only Mount the container's root filesystem as read only - --restart string Restart policy to apply when a container exits (default "no") - Possible values are: no, on-failure[:max-retry], always, unless-stopped - --rm Automatically remove the container when it exits - --runtime string Runtime to use for this container - --security-opt value Security Options (default []) - --shm-size string Size of /dev/shm, default value is 64MB. - The format is ``. `number` must be greater than `0`. - Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), - or `g` (gigabytes). If you omit the unit, the system uses bytes. - --stop-signal string Signal to stop a container, SIGTERM by default (default "SIGTERM") - --stop-timeout=10 Timeout (in seconds) to stop a container - --storage-opt value Storage driver options for the container (default []) - --sysctl value Sysctl options (default map[]) - --tmpfs value Mount a tmpfs directory (default []) - -t, --tty Allocate a pseudo-TTY - --ulimit value Ulimit options (default []) - -u, --user string Username or UID (format: [:]) - --userns string User namespace to use - 'host': Use the Docker host user namespace - '': Use the Docker daemon user namespace specified by `--userns-remap` option. - --uts string UTS namespace to use - -v, --volume value Bind mount a volume (default []). The format - is `[host-src:]container-dest[:]`. - The comma-delimited `options` are [rw|ro], - [z|Z], [[r]shared|[r]slave|[r]private], and - [nocopy]. The 'host-src' is an absolute path - or a name value. - --volume-driver string Optional volume driver for the container - --volumes-from value Mount volumes from the specified container(s) (default []) - -w, --workdir string Working directory inside the container -``` - -The `docker create` command creates a writeable container layer over the -specified image and prepares it for running the specified command. The -container ID is then printed to `STDOUT`. This is similar to `docker run -d` -except the container is never started. You can then use the -`docker start ` command to start the container at any point. - -This is useful when you want to set up a container configuration ahead of time -so that it is ready to start when you need it. The initial status of the -new container is `created`. - -Please see the [run command](run.md) section and the [Docker run reference](../run.md) for more details. - -## Examples - - $ docker create -t -i fedora bash - 6d8af538ec541dd581ebc2a24153a28329acb5268abe5ef868c1f1a261221752 - $ docker start -a -i 6d8af538ec5 - bash-4.2# - -As of v1.4.0 container volumes are initialized during the `docker create` phase -(i.e., `docker run` too). For example, this allows you to `create` the `data` -volume container, and then use it from another container: - - $ docker create -v /data --name data ubuntu - 240633dfbb98128fa77473d3d9018f6123b99c454b3251427ae190a7d951ad57 - $ docker run --rm --volumes-from data ubuntu ls -la /data - total 8 - drwxr-xr-x 2 root root 4096 Dec 5 04:10 . - drwxr-xr-x 48 root root 4096 Dec 5 04:11 .. - -Similarly, `create` a host directory bind mounted volume container, which can -then be used from the subsequent container: - - $ docker create -v /home/docker:/docker --name docker ubuntu - 9aa88c08f319cd1e4515c3c46b0de7cc9aa75e878357b1e96f91e2c773029f03 - $ docker run --rm --volumes-from docker ubuntu ls -la /docker - total 20 - drwxr-sr-x 5 1000 staff 180 Dec 5 04:00 . - drwxr-xr-x 48 root root 4096 Dec 5 04:13 .. - -rw-rw-r-- 1 1000 staff 3833 Dec 5 04:01 .ash_history - -rw-r--r-- 1 1000 staff 446 Nov 28 11:51 .ashrc - -rw-r--r-- 1 1000 staff 25 Dec 5 04:00 .gitconfig - drwxr-sr-x 3 1000 staff 60 Dec 1 03:28 .local - -rw-r--r-- 1 1000 staff 920 Nov 28 11:51 .profile - drwx--S--- 2 1000 staff 460 Dec 5 00:51 .ssh - drwxr-xr-x 32 1000 staff 1140 Dec 5 04:01 docker - -Set storage driver options per container. - - $ docker create -it --storage-opt size=120G fedora /bin/bash - -This (size) will allow to set the container rootfs size to 120G at creation time. -This option is only available for the `devicemapper`, `btrfs`, `overlay2`, -`windowsfilter` and `zfs` graph drivers. -For the `devicemapper`, `btrfs`, `windowsfilter` and `zfs` graph drivers, -user cannot pass a size less than the Default BaseFS Size. -For the `overlay2` storage driver, the size option is only available if the -backing fs is `xfs` and mounted with the `pquota` mount option. -Under these conditions, user can pass any size less then the backing fs size. - -### Specify isolation technology for container (--isolation) - -This option is useful in situations where you are running Docker containers on -Windows. The `--isolation=` option sets a container's isolation -technology. On Linux, the only supported is the `default` option which uses -Linux namespaces. On Microsoft Windows, you can specify these values: - - -| Value | Description | -|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `default` | Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value if the -daemon is running on Windows server, or `hyperv` if running on Windows client. | -| `process` | Namespace isolation only. | -| `hyperv` | Hyper-V hypervisor partition-based isolation. | - -Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/deploy.md b/vendor/github.com/docker/docker/docs/reference/commandline/deploy.md deleted file mode 100644 index 53074b2..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/deploy.md +++ /dev/null @@ -1,101 +0,0 @@ ---- -title: "deploy" -description: "The deploy command description and usage" -keywords: "stack, deploy" -advisory: "experimental" ---- - - - -# deploy (alias for stack deploy) (experimental) - -```markdown -Usage: docker deploy [OPTIONS] STACK - -Deploy a new stack or update an existing stack - -Aliases: - deploy, up - -Options: - --bundle-file string Path to a Distributed Application Bundle file - --compose-file string Path to a Compose file - --help Print usage - --with-registry-auth Send registry authentication details to Swarm agents -``` - -Create and update a stack from a `compose` or a `dab` file on the swarm. This command -has to be run targeting a manager node. - -## Compose file - -The `deploy` command supports compose file version `3.0` and above. - -```bash -$ docker stack deploy --compose-file docker-compose.yml vossibility -Ignoring unsupported options: links - -Creating network vossibility_vossibility -Creating network vossibility_default -Creating service vossibility_nsqd -Creating service vossibility_logstash -Creating service vossibility_elasticsearch -Creating service vossibility_kibana -Creating service vossibility_ghollector -Creating service vossibility_lookupd -``` - -You can verify that the services were correctly created - -``` -$ docker service ls -ID NAME MODE REPLICAS IMAGE -29bv0vnlm903 vossibility_lookupd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 -4awt47624qwh vossibility_nsqd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 -4tjx9biia6fs vossibility_elasticsearch replicated 1/1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa -7563uuzr9eys vossibility_kibana replicated 1/1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03 -9gc5m4met4he vossibility_logstash replicated 1/1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe -axqh55ipl40h vossibility_vossibility-collector replicated 1/1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba -``` - -## DAB file - -```bash -$ docker stack deploy --bundle-file vossibility-stack.dab vossibility -Loading bundle from vossibility-stack.dab -Creating service vossibility_elasticsearch -Creating service vossibility_kibana -Creating service vossibility_logstash -Creating service vossibility_lookupd -Creating service vossibility_nsqd -Creating service vossibility_vossibility-collector -``` - -You can verify that the services were correctly created: - -```bash -$ docker service ls -ID NAME MODE REPLICAS IMAGE -29bv0vnlm903 vossibility_lookupd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 -4awt47624qwh vossibility_nsqd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 -4tjx9biia6fs vossibility_elasticsearch replicated 1/1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa -7563uuzr9eys vossibility_kibana replicated 1/1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03 -9gc5m4met4he vossibility_logstash replicated 1/1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe -axqh55ipl40h vossibility_vossibility-collector replicated 1/1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba -``` - -## Related information - -* [stack config](stack_config.md) -* [stack deploy](stack_deploy.md) -* [stack ls](stack_ls.md) -* [stack ps](stack_ps.md) -* [stack rm](stack_rm.md) -* [stack services](stack_services.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/diff.md b/vendor/github.com/docker/docker/docs/reference/commandline/diff.md deleted file mode 100644 index be27678..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/diff.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "diff" -description: "The diff command description and usage" -keywords: "list, changed, files, container" ---- - - - -# diff - -```markdown -Usage: docker diff CONTAINER - -Inspect changes on a container's filesystem - -Options: - --help Print usage -``` - -List the changed files and directories in a container᾿s filesystem. - There are 3 events that are listed in the `diff`: - -1. `A` - Add -2. `D` - Delete -3. `C` - Change - -For example: - - $ docker diff 7bb0e258aefe - - C /dev - A /dev/kmsg - C /etc - A /etc/mtab - A /go - A /go/src - A /go/src/github.com - A /go/src/github.com/docker - A /go/src/github.com/docker/docker - A /go/src/github.com/docker/docker/.git - .... diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/docker_images.gif b/vendor/github.com/docker/docker/docs/reference/commandline/docker_images.gif deleted file mode 100644 index 5894ca2..0000000 Binary files a/vendor/github.com/docker/docker/docs/reference/commandline/docker_images.gif and /dev/null differ diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/dockerd.md b/vendor/github.com/docker/docker/docs/reference/commandline/dockerd.md deleted file mode 100644 index 24ac776..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/dockerd.md +++ /dev/null @@ -1,1364 +0,0 @@ ---- -title: "dockerd" -aliases: ["/engine/reference/commandline/daemon/"] -description: "The daemon command description and usage" -keywords: "container, daemon, runtime" ---- - - - -# daemon - -```markdown -Usage: dockerd [OPTIONS] - -A self-sufficient runtime for containers. - -Options: - --add-runtime value Register an additional OCI compatible runtime (default []) - --api-cors-header string Set CORS headers in the Engine API - --authorization-plugin value Authorization plugins to load (default []) - --bip string Specify network bridge IP - -b, --bridge string Attach containers to a network bridge - --cgroup-parent string Set parent cgroup for all containers - --cluster-advertise string Address or interface name to advertise - --cluster-store string URL of the distributed storage backend - --cluster-store-opt value Set cluster store options (default map[]) - --config-file string Daemon configuration file (default "/etc/docker/daemon.json") - --containerd string Path to containerd socket - -D, --debug Enable debug mode - --default-gateway value Container default gateway IPv4 address - --default-gateway-v6 value Container default gateway IPv6 address - --default-runtime string Default OCI runtime for containers (default "runc") - --default-ulimit value Default ulimits for containers (default []) - --disable-legacy-registry Disable contacting legacy registries - --dns value DNS server to use (default []) - --dns-opt value DNS options to use (default []) - --dns-search value DNS search domains to use (default []) - --exec-opt value Runtime execution options (default []) - --exec-root string Root directory for execution state files (default "/var/run/docker") - --experimental Enable experimental features - --fixed-cidr string IPv4 subnet for fixed IPs - --fixed-cidr-v6 string IPv6 subnet for fixed IPs - -g, --graph string Root of the Docker runtime (default "/var/lib/docker") - -G, --group string Group for the unix socket (default "docker") - --help Print usage - -H, --host value Daemon socket(s) to connect to (default []) - --icc Enable inter-container communication (default true) - --init Run an init in the container to forward signals and reap processes - --init-path string Path to the docker-init binary - --insecure-registry value Enable insecure registry communication (default []) - --ip value Default IP when binding container ports (default 0.0.0.0) - --ip-forward Enable net.ipv4.ip_forward (default true) - --ip-masq Enable IP masquerading (default true) - --iptables Enable addition of iptables rules (default true) - --ipv6 Enable IPv6 networking - --label value Set key=value labels to the daemon (default []) - --live-restore Enable live restore of docker when containers are still running (Linux only) - --log-driver string Default driver for container logs (default "json-file") - -l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info") - --log-opt value Default log driver options for containers (default map[]) - --max-concurrent-downloads int Set the max concurrent downloads for each pull (default 3) - --max-concurrent-uploads int Set the max concurrent uploads for each push (default 5) - --metrics-addr string Set address and port to serve the metrics api (default "") - --mtu int Set the containers network MTU - --oom-score-adjust int Set the oom_score_adj for the daemon (default -500) - -p, --pidfile string Path to use for daemon PID file (default "/var/run/docker.pid") - --raw-logs Full timestamps without ANSI coloring - --registry-mirror value Preferred Docker registry mirror (default []) - --seccomp-profile value Path to seccomp profile - --selinux-enabled Enable selinux support - --shutdown-timeout=15 Set the shutdown timeout value in seconds - -s, --storage-driver string Storage driver to use - --storage-opt value Storage driver options (default []) - --swarm-default-advertise-addr string Set default address or interface for swarm advertised address - --tls Use TLS; implied by --tlsverify - --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") - --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") - --tlskey string Path to TLS key file (default "/root/.docker/key.pem") - --tlsverify Use TLS and verify the remote - --userland-proxy Use userland proxy for loopback traffic (default true) - --userland-proxy-path string Path to the userland proxy binary - --userns-remap string User/Group setting for user namespaces - -v, --version Print version information and quit -``` - -Options with [] may be specified multiple times. - -dockerd is the persistent process that manages containers. Docker -uses different binaries for the daemon and client. To run the daemon you -type `dockerd`. - -To run the daemon with debug output, use `dockerd -D`. - -## Daemon socket option - -The Docker daemon can listen for [Docker Engine API](../api/) -requests via three different types of Socket: `unix`, `tcp`, and `fd`. - -By default, a `unix` domain socket (or IPC socket) is created at -`/var/run/docker.sock`, requiring either `root` permission, or `docker` group -membership. - -If you need to access the Docker daemon remotely, you need to enable the `tcp` -Socket. Beware that the default setup provides un-encrypted and -un-authenticated direct access to the Docker daemon - and should be secured -either using the [built in HTTPS encrypted socket](https://docs.docker.com/engine/security/https/), or by -putting a secure web proxy in front of it. You can listen on port `2375` on all -network interfaces with `-H tcp://0.0.0.0:2375`, or on a particular network -interface using its IP address: `-H tcp://192.168.59.103:2375`. It is -conventional to use port `2375` for un-encrypted, and port `2376` for encrypted -communication with the daemon. - -> **Note:** -> If you're using an HTTPS encrypted socket, keep in mind that only -> TLS1.0 and greater are supported. Protocols SSLv3 and under are not -> supported anymore for security reasons. - -On Systemd based systems, you can communicate with the daemon via -[Systemd socket activation](http://0pointer.de/blog/projects/socket-activation.html), -use `dockerd -H fd://`. Using `fd://` will work perfectly for most setups but -you can also specify individual sockets: `dockerd -H fd://3`. If the -specified socket activated files aren't found, then Docker will exit. You can -find examples of using Systemd socket activation with Docker and Systemd in the -[Docker source tree](https://github.com/docker/docker/tree/master/contrib/init/systemd/). - -You can configure the Docker daemon to listen to multiple sockets at the same -time using multiple `-H` options: - -```bash -# listen using the default unix socket, and on 2 specific IP addresses on this host. -$ sudo dockerd -H unix:///var/run/docker.sock -H tcp://192.168.59.106 -H tcp://10.10.10.2 -``` - -The Docker client will honor the `DOCKER_HOST` environment variable to set the -`-H` flag for the client. - -```bash -$ docker -H tcp://0.0.0.0:2375 ps -# or -$ export DOCKER_HOST="tcp://0.0.0.0:2375" -$ docker ps -# both are equal -``` - -Setting the `DOCKER_TLS_VERIFY` environment variable to any value other than -the empty string is equivalent to setting the `--tlsverify` flag. The following -are equivalent: - -```bash -$ docker --tlsverify ps -# or -$ export DOCKER_TLS_VERIFY=1 -$ docker ps -``` - -The Docker client will honor the `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` -environment variables (or the lowercase versions thereof). `HTTPS_PROXY` takes -precedence over `HTTP_PROXY`. - -### Bind Docker to another host/port or a Unix socket - -> **Warning**: -> Changing the default `docker` daemon binding to a -> TCP port or Unix *docker* user group will increase your security risks -> by allowing non-root users to gain *root* access on the host. Make sure -> you control access to `docker`. If you are binding -> to a TCP port, anyone with access to that port has full Docker access; -> so it is not advisable on an open network. - -With `-H` it is possible to make the Docker daemon to listen on a -specific IP and port. By default, it will listen on -`unix:///var/run/docker.sock` to allow only local connections by the -*root* user. You *could* set it to `0.0.0.0:2375` or a specific host IP -to give access to everybody, but that is **not recommended** because -then it is trivial for someone to gain root access to the host where the -daemon is running. - -Similarly, the Docker client can use `-H` to connect to a custom port. -The Docker client will default to connecting to `unix:///var/run/docker.sock` -on Linux, and `tcp://127.0.0.1:2376` on Windows. - -`-H` accepts host and port assignment in the following format: - - tcp://[host]:[port][path] or unix://path - -For example: - -- `tcp://` -> TCP connection to `127.0.0.1` on either port `2376` when TLS encryption - is on, or port `2375` when communication is in plain text. -- `tcp://host:2375` -> TCP connection on - host:2375 -- `tcp://host:2375/path` -> TCP connection on - host:2375 and prepend path to all requests -- `unix://path/to/socket` -> Unix socket located - at `path/to/socket` - -`-H`, when empty, will default to the same value as -when no `-H` was passed in. - -`-H` also accepts short form for TCP bindings: `host:` or `host:port` or `:port` - -Run Docker in daemon mode: - -```bash -$ sudo /dockerd -H 0.0.0.0:5555 & -``` - -Download an `ubuntu` image: - -```bash -$ docker -H :5555 pull ubuntu -``` - -You can use multiple `-H`, for example, if you want to listen on both -TCP and a Unix socket - -```bash -# Run docker in daemon mode -$ sudo /dockerd -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock & -# Download an ubuntu image, use default Unix socket -$ docker pull ubuntu -# OR use the TCP port -$ docker -H tcp://127.0.0.1:2375 pull ubuntu -``` - -### Daemon storage-driver option - -The Docker daemon has support for several different image layer storage -drivers: `aufs`, `devicemapper`, `btrfs`, `zfs`, `overlay` and `overlay2`. - -The `aufs` driver is the oldest, but is based on a Linux kernel patch-set that -is unlikely to be merged into the main kernel. These are also known to cause -some serious kernel crashes. However, `aufs` allows containers to share -executable and shared library memory, so is a useful choice when running -thousands of containers with the same program or libraries. - -The `devicemapper` driver uses thin provisioning and Copy on Write (CoW) -snapshots. For each devicemapper graph location – typically -`/var/lib/docker/devicemapper` – a thin pool is created based on two block -devices, one for data and one for metadata. By default, these block devices -are created automatically by using loopback mounts of automatically created -sparse files. Refer to [Storage driver options](#storage-driver-options) below -for a way how to customize this setup. -[~jpetazzo/Resizing Docker containers with the Device Mapper plugin](http://jpetazzo.github.io/2014/01/29/docker-device-mapper-resize/) -article explains how to tune your existing setup without the use of options. - -The `btrfs` driver is very fast for `docker build` - but like `devicemapper` -does not share executable memory between devices. Use -`dockerd -s btrfs -g /mnt/btrfs_partition`. - -The `zfs` driver is probably not as fast as `btrfs` but has a longer track record -on stability. Thanks to `Single Copy ARC` shared blocks between clones will be -cached only once. Use `dockerd -s zfs`. To select a different zfs filesystem -set `zfs.fsname` option as described in [Storage driver options](#storage-driver-options). - -The `overlay` is a very fast union filesystem. It is now merged in the main -Linux kernel as of [3.18.0](https://lkml.org/lkml/2014/10/26/137). `overlay` -also supports page cache sharing, this means multiple containers accessing -the same file can share a single page cache entry (or entries), it makes -`overlay` as efficient with memory as `aufs` driver. Call -`dockerd -s overlay` to use it. - -> **Note:** -> As promising as `overlay` is, the feature is still quite young and should not -> be used in production. Most notably, using `overlay` can cause excessive -> inode consumption (especially as the number of images grows), as well as -> being incompatible with the use of RPMs. - -The `overlay2` uses the same fast union filesystem but takes advantage of -[additional features](https://lkml.org/lkml/2015/2/11/106) added in Linux -kernel 4.0 to avoid excessive inode consumption. Call `dockerd -s overlay2` -to use it. - -> **Note:** -> Both `overlay` and `overlay2` are currently unsupported on `btrfs` or any -> Copy on Write filesystem and should only be used over `ext4` partitions. - -### Storage driver options - -Particular storage-driver can be configured with options specified with -`--storage-opt` flags. Options for `devicemapper` are prefixed with `dm`, -options for `zfs` start with `zfs` and options for `btrfs` start with `btrfs`. - -#### Devicemapper options - -* `dm.thinpooldev` - - Specifies a custom block storage device to use for the thin pool. - - If using a block device for device mapper storage, it is best to use `lvm` - to create and manage the thin-pool volume. This volume is then handed to Docker - to exclusively create snapshot volumes needed for images and containers. - - Managing the thin-pool outside of Engine makes for the most feature-rich - method of having Docker utilize device mapper thin provisioning as the - backing storage for Docker containers. The highlights of the lvm-based - thin-pool management feature include: automatic or interactive thin-pool - resize support, dynamically changing thin-pool features, automatic thinp - metadata checking when lvm activates the thin-pool, etc. - - As a fallback if no thin pool is provided, loopback files are - created. Loopback is very slow, but can be used without any - pre-configuration of storage. It is strongly recommended that you do - not use loopback in production. Ensure your Engine daemon has a - `--storage-opt dm.thinpooldev` argument provided. - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.thinpooldev=/dev/mapper/thin-pool - ``` - -* `dm.basesize` - - Specifies the size to use when creating the base device, which limits the - size of images and containers. The default value is 10G. Note, thin devices - are inherently "sparse", so a 10G device which is mostly empty doesn't use - 10 GB of space on the pool. However, the filesystem will use more space for - the empty case the larger the device is. - - The base device size can be increased at daemon restart which will allow - all future images and containers (based on those new images) to be of the - new base device size. - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.basesize=50G - ``` - - This will increase the base device size to 50G. The Docker daemon will throw an - error if existing base device size is larger than 50G. A user can use - this option to expand the base device size however shrinking is not permitted. - - This value affects the system-wide "base" empty filesystem - that may already be initialized and inherited by pulled images. Typically, - a change to this value requires additional steps to take effect: - - ```bash - $ sudo service docker stop - $ sudo rm -rf /var/lib/docker - $ sudo service docker start - ``` - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.basesize=20G - ``` - -* `dm.loopdatasize` - - > **Note**: - > This option configures devicemapper loopback, which should not - > be used in production. - - Specifies the size to use when creating the loopback file for the - "data" device which is used for the thin pool. The default size is - 100G. The file is sparse, so it will not initially take up this - much space. - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.loopdatasize=200G - ``` - -* `dm.loopmetadatasize` - - > **Note**: - > This option configures devicemapper loopback, which should not - > be used in production. - - Specifies the size to use when creating the loopback file for the - "metadata" device which is used for the thin pool. The default size - is 2G. The file is sparse, so it will not initially take up - this much space. - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.loopmetadatasize=4G - ``` - -* `dm.fs` - - Specifies the filesystem type to use for the base device. The supported - options are "ext4" and "xfs". The default is "xfs" - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.fs=ext4 - ``` - -* `dm.mkfsarg` - - Specifies extra mkfs arguments to be used when creating the base device. - - Example use: - - ```bash - $ sudo dockerd --storage-opt "dm.mkfsarg=-O ^has_journal" - ``` - -* `dm.mountopt` - - Specifies extra mount options used when mounting the thin devices. - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.mountopt=nodiscard - ``` - -* `dm.datadev` - - (Deprecated, use `dm.thinpooldev`) - - Specifies a custom blockdevice to use for data for the thin pool. - - If using a block device for device mapper storage, ideally both datadev and - metadatadev should be specified to completely avoid using the loopback - device. - - Example use: - - ```bash - $ sudo dockerd \ - --storage-opt dm.datadev=/dev/sdb1 \ - --storage-opt dm.metadatadev=/dev/sdc1 - ``` - -* `dm.metadatadev` - - (Deprecated, use `dm.thinpooldev`) - - Specifies a custom blockdevice to use for metadata for the thin pool. - - For best performance the metadata should be on a different spindle than the - data, or even better on an SSD. - - If setting up a new metadata pool it is required to be valid. This can be - achieved by zeroing the first 4k to indicate empty metadata, like this: - - ```bash - $ dd if=/dev/zero of=$metadata_dev bs=4096 count=1 - ``` - - Example use: - - ```bash - $ sudo dockerd \ - --storage-opt dm.datadev=/dev/sdb1 \ - --storage-opt dm.metadatadev=/dev/sdc1 - ``` - -* `dm.blocksize` - - Specifies a custom blocksize to use for the thin pool. The default - blocksize is 64K. - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.blocksize=512K - ``` - -* `dm.blkdiscard` - - Enables or disables the use of blkdiscard when removing devicemapper - devices. This is enabled by default (only) if using loopback devices and is - required to resparsify the loopback file on image/container removal. - - Disabling this on loopback can lead to *much* faster container removal - times, but will make the space used in `/var/lib/docker` directory not be - returned to the system for other use when containers are removed. - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.blkdiscard=false - ``` - -* `dm.override_udev_sync_check` - - Overrides the `udev` synchronization checks between `devicemapper` and `udev`. - `udev` is the device manager for the Linux kernel. - - To view the `udev` sync support of a Docker daemon that is using the - `devicemapper` driver, run: - - ```bash - $ docker info - [...] - Udev Sync Supported: true - [...] - ``` - - When `udev` sync support is `true`, then `devicemapper` and udev can - coordinate the activation and deactivation of devices for containers. - - When `udev` sync support is `false`, a race condition occurs between - the`devicemapper` and `udev` during create and cleanup. The race condition - results in errors and failures. (For information on these failures, see - [docker#4036](https://github.com/docker/docker/issues/4036)) - - To allow the `docker` daemon to start, regardless of `udev` sync not being - supported, set `dm.override_udev_sync_check` to true: - - ```bash - $ sudo dockerd --storage-opt dm.override_udev_sync_check=true - ``` - - When this value is `true`, the `devicemapper` continues and simply warns - you the errors are happening. - - > **Note:** - > The ideal is to pursue a `docker` daemon and environment that does - > support synchronizing with `udev`. For further discussion on this - > topic, see [docker#4036](https://github.com/docker/docker/issues/4036). - > Otherwise, set this flag for migrating existing Docker daemons to - > a daemon with a supported environment. - -* `dm.use_deferred_removal` - - Enables use of deferred device removal if `libdm` and the kernel driver - support the mechanism. - - Deferred device removal means that if device is busy when devices are - being removed/deactivated, then a deferred removal is scheduled on - device. And devices automatically go away when last user of the device - exits. - - For example, when a container exits, its associated thin device is removed. - If that device has leaked into some other mount namespace and can't be - removed, the container exit still succeeds and this option causes the - system to schedule the device for deferred removal. It does not wait in a - loop trying to remove a busy device. - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.use_deferred_removal=true - ``` - -* `dm.use_deferred_deletion` - - Enables use of deferred device deletion for thin pool devices. By default, - thin pool device deletion is synchronous. Before a container is deleted, - the Docker daemon removes any associated devices. If the storage driver - can not remove a device, the container deletion fails and daemon returns. - - Error deleting container: Error response from daemon: Cannot destroy container - - To avoid this failure, enable both deferred device deletion and deferred - device removal on the daemon. - - ```bash - $ sudo dockerd \ - --storage-opt dm.use_deferred_deletion=true \ - --storage-opt dm.use_deferred_removal=true - ``` - - With these two options enabled, if a device is busy when the driver is - deleting a container, the driver marks the device as deleted. Later, when - the device isn't in use, the driver deletes it. - - In general it should be safe to enable this option by default. It will help - when unintentional leaking of mount point happens across multiple mount - namespaces. - -* `dm.min_free_space` - - Specifies the min free space percent in a thin pool require for new device - creation to succeed. This check applies to both free data space as well - as free metadata space. Valid values are from 0% - 99%. Value 0% disables - free space checking logic. If user does not specify a value for this option, - the Engine uses a default value of 10%. - - Whenever a new a thin pool device is created (during `docker pull` or during - container creation), the Engine checks if the minimum free space is - available. If sufficient space is unavailable, then device creation fails - and any relevant `docker` operation fails. - - To recover from this error, you must create more free space in the thin pool - to recover from the error. You can create free space by deleting some images - and containers from the thin pool. You can also add more storage to the thin - pool. - - To add more space to a LVM (logical volume management) thin pool, just add - more storage to the volume group container thin pool; this should automatically - resolve any errors. If your configuration uses loop devices, then stop the - Engine daemon, grow the size of loop files and restart the daemon to resolve - the issue. - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.min_free_space=10% - ``` - -* `dm.xfs_nospace_max_retries` - - Specifies the maximum number of retries XFS should attempt to complete - IO when ENOSPC (no space) error is returned by underlying storage device. - - By default XFS retries infinitely for IO to finish and this can result - in unkillable process. To change this behavior one can set - xfs_nospace_max_retries to say 0 and XFS will not retry IO after getting - ENOSPC and will shutdown filesystem. - - Example use: - - ```bash - $ sudo dockerd --storage-opt dm.xfs_nospace_max_retries=0 - ``` - -#### ZFS options - -* `zfs.fsname` - - Set zfs filesystem under which docker will create its own datasets. - By default docker will pick up the zfs filesystem where docker graph - (`/var/lib/docker`) is located. - - Example use: - - ```bash - $ sudo dockerd -s zfs --storage-opt zfs.fsname=zroot/docker - ``` - -#### Btrfs options - -* `btrfs.min_space` - - Specifies the minimum size to use when creating the subvolume which is used - for containers. If user uses disk quota for btrfs when creating or running - a container with **--storage-opt size** option, docker should ensure the - **size** cannot be smaller than **btrfs.min_space**. - - Example use: - - ```bash - $ sudo dockerd -s btrfs --storage-opt btrfs.min_space=10G - ``` - -#### Overlay2 options - -* `overlay2.override_kernel_check` - - Overrides the Linux kernel version check allowing overlay2. Support for - specifying multiple lower directories needed by overlay2 was added to the - Linux kernel in 4.0.0. However some older kernel versions may be patched - to add multiple lower directory support for OverlayFS. This option should - only be used after verifying this support exists in the kernel. Applying - this option on a kernel without this support will cause failures on mount. - -## Docker runtime execution options - -The Docker daemon relies on a -[OCI](https://github.com/opencontainers/runtime-spec) compliant runtime -(invoked via the `containerd` daemon) as its interface to the Linux -kernel `namespaces`, `cgroups`, and `SELinux`. - -By default, the Docker daemon automatically starts `containerd`. If you want to -control `containerd` startup, manually start `containerd` and pass the path to -the `containerd` socket using the `--containerd` flag. For example: - -```bash -$ sudo dockerd --containerd /var/run/dev/docker-containerd.sock -``` - -Runtimes can be registered with the daemon either via the -configuration file or using the `--add-runtime` command line argument. - -The following is an example adding 2 runtimes via the configuration: - -```json -{ - "default-runtime": "runc", - "runtimes": { - "runc": { - "path": "runc" - }, - "custom": { - "path": "/usr/local/bin/my-runc-replacement", - "runtimeArgs": [ - "--debug" - ] - } - } -} -``` - -This is the same example via the command line: - -```bash -$ sudo dockerd --add-runtime runc=runc --add-runtime custom=/usr/local/bin/my-runc-replacement -``` - -> **Note**: defining runtime arguments via the command line is not supported. - -## Options for the runtime - -You can configure the runtime using options specified -with the `--exec-opt` flag. All the flag's options have the `native` prefix. A -single `native.cgroupdriver` option is available. - -The `native.cgroupdriver` option specifies the management of the container's -cgroups. You can specify only specify `cgroupfs` or `systemd`. If you specify -`systemd` and it is not available, the system errors out. If you omit the -`native.cgroupdriver` option,` cgroupfs` is used. - -This example sets the `cgroupdriver` to `systemd`: - -```bash -$ sudo dockerd --exec-opt native.cgroupdriver=systemd -``` - -Setting this option applies to all containers the daemon launches. - -Also Windows Container makes use of `--exec-opt` for special purpose. Docker user -can specify default container isolation technology with this, for example: - -```bash -$ sudo dockerd --exec-opt isolation=hyperv -``` - -Will make `hyperv` the default isolation technology on Windows. If no isolation -value is specified on daemon start, on Windows client, the default is -`hyperv`, and on Windows server, the default is `process`. - -## Daemon DNS options - -To set the DNS server for all Docker containers, use: - -```bash -$ sudo dockerd --dns 8.8.8.8 -``` - - -To set the DNS search domain for all Docker containers, use: - -```bash -$ sudo dockerd --dns-search example.com -``` - - -## Insecure registries - -Docker considers a private registry either secure or insecure. In the rest of -this section, *registry* is used for *private registry*, and `myregistry:5000` -is a placeholder example for a private registry. - -A secure registry uses TLS and a copy of its CA certificate is placed on the -Docker host at `/etc/docker/certs.d/myregistry:5000/ca.crt`. An insecure -registry is either not using TLS (i.e., listening on plain text HTTP), or is -using TLS with a CA certificate not known by the Docker daemon. The latter can -happen when the certificate was not found under -`/etc/docker/certs.d/myregistry:5000/`, or if the certificate verification -failed (i.e., wrong CA). - -By default, Docker assumes all, but local (see local registries below), -registries are secure. Communicating with an insecure registry is not possible -if Docker assumes that registry is secure. In order to communicate with an -insecure registry, the Docker daemon requires `--insecure-registry` in one of -the following two forms: - -* `--insecure-registry myregistry:5000` tells the Docker daemon that - myregistry:5000 should be considered insecure. -* `--insecure-registry 10.1.0.0/16` tells the Docker daemon that all registries - whose domain resolve to an IP address is part of the subnet described by the - CIDR syntax, should be considered insecure. - -The flag can be used multiple times to allow multiple registries to be marked -as insecure. - -If an insecure registry is not marked as insecure, `docker pull`, -`docker push`, and `docker search` will result in an error message prompting -the user to either secure or pass the `--insecure-registry` flag to the Docker -daemon as described above. - -Local registries, whose IP address falls in the 127.0.0.0/8 range, are -automatically marked as insecure as of Docker 1.3.2. It is not recommended to -rely on this, as it may change in the future. - -Enabling `--insecure-registry`, i.e., allowing un-encrypted and/or untrusted -communication, can be useful when running a local registry. However, -because its use creates security vulnerabilities it should ONLY be enabled for -testing purposes. For increased security, users should add their CA to their -system's list of trusted CAs instead of enabling `--insecure-registry`. - -## Legacy Registries - -Enabling `--disable-legacy-registry` forces a docker daemon to only interact with registries which support the V2 protocol. Specifically, the daemon will not attempt `push`, `pull` and `login` to v1 registries. The exception to this is `search` which can still be performed on v1 registries. - -## Running a Docker daemon behind an HTTPS_PROXY - -When running inside a LAN that uses an `HTTPS` proxy, the Docker Hub -certificates will be replaced by the proxy's certificates. These certificates -need to be added to your Docker host's configuration: - -1. Install the `ca-certificates` package for your distribution -2. Ask your network admin for the proxy's CA certificate and append them to - `/etc/pki/tls/certs/ca-bundle.crt` -3. Then start your Docker daemon with `HTTPS_PROXY=http://username:password@proxy:port/ dockerd`. - The `username:` and `password@` are optional - and are only needed if your - proxy is set up to require authentication. - -This will only add the proxy and authentication to the Docker daemon's requests - -your `docker build`s and running containers will need extra configuration to -use the proxy - -## Default Ulimits - -`--default-ulimit` allows you to set the default `ulimit` options to use for -all containers. It takes the same options as `--ulimit` for `docker run`. If -these defaults are not set, `ulimit` settings will be inherited, if not set on -`docker run`, from the Docker daemon. Any `--ulimit` options passed to -`docker run` will overwrite these defaults. - -Be careful setting `nproc` with the `ulimit` flag as `nproc` is designed by Linux to -set the maximum number of processes available to a user, not to a container. For details -please check the [run](run.md) reference. - -## Nodes discovery - -The `--cluster-advertise` option specifies the `host:port` or `interface:port` -combination that this particular daemon instance should use when advertising -itself to the cluster. The daemon is reached by remote hosts through this value. -If you specify an interface, make sure it includes the IP address of the actual -Docker host. For Engine installation created through `docker-machine`, the -interface is typically `eth1`. - -The daemon uses [libkv](https://github.com/docker/libkv/) to advertise -the node within the cluster. Some key-value backends support mutual -TLS. To configure the client TLS settings used by the daemon can be configured -using the `--cluster-store-opt` flag, specifying the paths to PEM encoded -files. For example: - -```bash -$ sudo dockerd \ - --cluster-advertise 192.168.1.2:2376 \ - --cluster-store etcd://192.168.1.2:2379 \ - --cluster-store-opt kv.cacertfile=/path/to/ca.pem \ - --cluster-store-opt kv.certfile=/path/to/cert.pem \ - --cluster-store-opt kv.keyfile=/path/to/key.pem -``` - -The currently supported cluster store options are: - -* `discovery.heartbeat` - - Specifies the heartbeat timer in seconds which is used by the daemon as a - keepalive mechanism to make sure discovery module treats the node as alive - in the cluster. If not configured, the default value is 20 seconds. - -* `discovery.ttl` - - Specifies the ttl (time-to-live) in seconds which is used by the discovery - module to timeout a node if a valid heartbeat is not received within the - configured ttl value. If not configured, the default value is 60 seconds. - -* `kv.cacertfile` - - Specifies the path to a local file with PEM encoded CA certificates to trust - -* `kv.certfile` - - Specifies the path to a local file with a PEM encoded certificate. This - certificate is used as the client cert for communication with the - Key/Value store. - -* `kv.keyfile` - - Specifies the path to a local file with a PEM encoded private key. This - private key is used as the client key for communication with the - Key/Value store. - -* `kv.path` - - Specifies the path in the Key/Value store. If not configured, the default value is 'docker/nodes'. - -## Access authorization - -Docker's access authorization can be extended by authorization plugins that your -organization can purchase or build themselves. You can install one or more -authorization plugins when you start the Docker `daemon` using the -`--authorization-plugin=PLUGIN_ID` option. - -```bash -$ sudo dockerd --authorization-plugin=plugin1 --authorization-plugin=plugin2,... -``` - -The `PLUGIN_ID` value is either the plugin's name or a path to its specification -file. The plugin's implementation determines whether you can specify a name or -path. Consult with your Docker administrator to get information about the -plugins available to you. - -Once a plugin is installed, requests made to the `daemon` through the command -line or Docker's Engine API are allowed or denied by the plugin. If you have -multiple plugins installed, at least one must allow the request for it to -complete. - -For information about how to create an authorization plugin, see [authorization -plugin](../../extend/plugins_authorization.md) section in the Docker extend section of this documentation. - - -## Daemon user namespace options - -The Linux kernel [user namespace support](http://man7.org/linux/man-pages/man7/user_namespaces.7.html) provides additional security by enabling -a process, and therefore a container, to have a unique range of user and -group IDs which are outside the traditional user and group range utilized by -the host system. Potentially the most important security improvement is that, -by default, container processes running as the `root` user will have expected -administrative privilege (with some restrictions) inside the container but will -effectively be mapped to an unprivileged `uid` on the host. - -When user namespace support is enabled, Docker creates a single daemon-wide mapping -for all containers running on the same engine instance. The mappings will -utilize the existing subordinate user and group ID feature available on all modern -Linux distributions. -The [`/etc/subuid`](http://man7.org/linux/man-pages/man5/subuid.5.html) and -[`/etc/subgid`](http://man7.org/linux/man-pages/man5/subgid.5.html) files will be -read for the user, and optional group, specified to the `--userns-remap` -parameter. If you do not wish to specify your own user and/or group, you can -provide `default` as the value to this flag, and a user will be created on your behalf -and provided subordinate uid and gid ranges. This default user will be named -`dockremap`, and entries will be created for it in `/etc/passwd` and -`/etc/group` using your distro's standard user and group creation tools. - -> **Note**: The single mapping per-daemon restriction is in place for now -> because Docker shares image layers from its local cache across all -> containers running on the engine instance. Since file ownership must be -> the same for all containers sharing the same layer content, the decision -> was made to map the file ownership on `docker pull` to the daemon's user and -> group mappings so that there is no delay for running containers once the -> content is downloaded. This design preserves the same performance for `docker -> pull`, `docker push`, and container startup as users expect with -> user namespaces disabled. - -### Starting the daemon with user namespaces enabled - -To enable user namespace support, start the daemon with the -`--userns-remap` flag, which accepts values in the following formats: - - - uid - - uid:gid - - username - - username:groupname - -If numeric IDs are provided, translation back to valid user or group names -will occur so that the subordinate uid and gid information can be read, given -these resources are name-based, not id-based. If the numeric ID information -provided does not exist as entries in `/etc/passwd` or `/etc/group`, daemon -startup will fail with an error message. - -**Example: starting with default Docker user management:** - -```bash -$ sudo dockerd --userns-remap=default -``` - -When `default` is provided, Docker will create - or find the existing - user and group -named `dockremap`. If the user is created, and the Linux distribution has -appropriate support, the `/etc/subuid` and `/etc/subgid` files will be populated -with a contiguous 65536 length range of subordinate user and group IDs, starting -at an offset based on prior entries in those files. For example, Ubuntu will -create the following range, based on an existing user named `user1` already owning -the first 65536 range: - -```bash -$ cat /etc/subuid -user1:100000:65536 -dockremap:165536:65536 -``` - -If you have a preferred/self-managed user with subordinate ID mappings already -configured, you can provide that username or uid to the `--userns-remap` flag. -If you have a group that doesn't match the username, you may provide the `gid` -or group name as well; otherwise the username will be used as the group name -when querying the system for the subordinate group ID range. - -The output of `docker info` can be used to determine if the daemon is running -with user namespaces enabled or not. If the daemon is configured with user -namespaces, the Security Options entry in the response will list "userns" as -one of the enabled security features. - -### Detailed information on `subuid`/`subgid` ranges - -Given potential advanced use of the subordinate ID ranges by power users, the -following paragraphs define how the Docker daemon currently uses the range entries -found within the subordinate range files. - -The simplest case is that only one contiguous range is defined for the -provided user or group. In this case, Docker will use that entire contiguous -range for the mapping of host uids and gids to the container process. This -means that the first ID in the range will be the remapped root user, and the -IDs above that initial ID will map host ID 1 through the end of the range. - -From the example `/etc/subuid` content shown above, the remapped root -user would be uid 165536. - -If the system administrator has set up multiple ranges for a single user or -group, the Docker daemon will read all the available ranges and use the -following algorithm to create the mapping ranges: - -1. The range segments found for the particular user will be sorted by *start ID* ascending. -2. Map segments will be created from each range in increasing value with a length matching the length of each segment. Therefore the range segment with the lowest numeric starting value will be equal to the remapped root, and continue up through host uid/gid equal to the range segment length. As an example, if the lowest segment starts at ID 1000 and has a length of 100, then a map of 1000 -> 0 (the remapped root) up through 1100 -> 100 will be created from this segment. If the next segment starts at ID 10000, then the next map will start with mapping 10000 -> 101 up to the length of this second segment. This will continue until no more segments are found in the subordinate files for this user. -3. If more than five range segments exist for a single user, only the first five will be utilized, matching the kernel's limitation of only five entries in `/proc/self/uid_map` and `proc/self/gid_map`. - -### Disable user namespace for a container - -If you enable user namespaces on the daemon, all containers are started -with user namespaces enabled. In some situations you might want to disable -this feature for a container, for example, to start a privileged container (see -[user namespace known restrictions](#user-namespace-known-restrictions)). -To enable those advanced features for a specific container use `--userns=host` -in the `run/exec/create` command. -This option will completely disable user namespace mapping for the container's user. - -### User namespace known restrictions - -The following standard Docker features are currently incompatible when -running a Docker daemon with user namespaces enabled: - - - sharing PID or NET namespaces with the host (`--pid=host` or `--net=host`) - - Using `--privileged` mode flag on `docker run` (unless also specifying `--userns=host`) - -In general, user namespaces are an advanced feature and will require -coordination with other capabilities. For example, if volumes are mounted from -the host, file ownership will have to be pre-arranged if the user or -administrator wishes the containers to have expected access to the volume -contents. Note that when using external volume or graph driver plugins, those -external software programs must be made aware of user and group mapping ranges -if they are to work seamlessly with user namespace support. - -Finally, while the `root` user inside a user namespaced container process has -many of the expected admin privileges that go along with being the superuser, the -Linux kernel has restrictions based on internal knowledge that this is a user namespaced -process. The most notable restriction that we are aware of at this time is the -inability to use `mknod`. Permission will be denied for device creation even as -container `root` inside a user namespace. - -## Miscellaneous options - -IP masquerading uses address translation to allow containers without a public -IP to talk to other machines on the Internet. This may interfere with some -network topologies and can be disabled with `--ip-masq=false`. - -Docker supports softlinks for the Docker data directory (`/var/lib/docker`) and -for `/var/lib/docker/tmp`. The `DOCKER_TMPDIR` and the data directory can be -set like this: - - DOCKER_TMPDIR=/mnt/disk2/tmp /usr/local/bin/dockerd -D -g /var/lib/docker -H unix:// > /var/lib/docker-machine/docker.log 2>&1 - # or - export DOCKER_TMPDIR=/mnt/disk2/tmp - /usr/local/bin/dockerd -D -g /var/lib/docker -H unix:// > /var/lib/docker-machine/docker.log 2>&1 - -## Default cgroup parent - -The `--cgroup-parent` option allows you to set the default cgroup parent -to use for containers. If this option is not set, it defaults to `/docker` for -fs cgroup driver and `system.slice` for systemd cgroup driver. - -If the cgroup has a leading forward slash (`/`), the cgroup is created -under the root cgroup, otherwise the cgroup is created under the daemon -cgroup. - -Assuming the daemon is running in cgroup `daemoncgroup`, -`--cgroup-parent=/foobar` creates a cgroup in -`/sys/fs/cgroup/memory/foobar`, whereas using `--cgroup-parent=foobar` -creates the cgroup in `/sys/fs/cgroup/memory/daemoncgroup/foobar` - -The systemd cgroup driver has different rules for `--cgroup-parent`. Systemd -represents hierarchy by slice and the name of the slice encodes the location in -the tree. So `--cgroup-parent` for systemd cgroups should be a slice name. A -name can consist of a dash-separated series of names, which describes the path -to the slice from the root slice. For example, `--cgroup-parent=user-a-b.slice` -means the memory cgroup for the container is created in -`/sys/fs/cgroup/memory/user.slice/user-a.slice/user-a-b.slice/docker-.scope`. - -This setting can also be set per container, using the `--cgroup-parent` -option on `docker create` and `docker run`, and takes precedence over -the `--cgroup-parent` option on the daemon. - -## Daemon Metrics - -The `--metrics-addr` option takes a tcp address to serve the metrics API. -This feature is still experimental, therefore, the daemon must be running in experimental -mode for this feature to work. - -To serve the metrics API on localhost:1337 you would specify `--metrics-addr 127.0.0.1:1337` -allowing you to make requests on the API at `127.0.0.1:1337/metrics` to receive metrics in the -[prometheus](https://prometheus.io/docs/instrumenting/exposition_formats/) format. - -If you are running a prometheus server you can add this address to your scrape configs -to have prometheus collect metrics on Docker. For more information -on prometheus you can view the website [here](https://prometheus.io/). - -```yml -scrape_configs: - - job_name: 'docker' - static_configs: - - targets: ['127.0.0.1:1337'] -``` - -Please note that this feature is still marked as experimental as metrics and metric -names could change while this feature is still in experimental. Please provide -feedback on what you would like to see collected in the API. - -## Daemon configuration file - -The `--config-file` option allows you to set any configuration option -for the daemon in a JSON format. This file uses the same flag names as keys, -except for flags that allow several entries, where it uses the plural -of the flag name, e.g., `labels` for the `label` flag. - -The options set in the configuration file must not conflict with options set -via flags. The docker daemon fails to start if an option is duplicated between -the file and the flags, regardless their value. We do this to avoid -silently ignore changes introduced in configuration reloads. -For example, the daemon fails to start if you set daemon labels -in the configuration file and also set daemon labels via the `--label` flag. -Options that are not present in the file are ignored when the daemon starts. - -### Linux configuration file - -The default location of the configuration file on Linux is -`/etc/docker/daemon.json`. The `--config-file` flag can be used to specify a - non-default location. - -This is a full example of the allowed configuration options on Linux: - -```json -{ - "authorization-plugins": [], - "dns": [], - "dns-opts": [], - "dns-search": [], - "exec-opts": [], - "exec-root": "", - "experimental": false, - "storage-driver": "", - "storage-opts": [], - "labels": [], - "live-restore": true, - "log-driver": "", - "log-opts": {}, - "mtu": 0, - "pidfile": "", - "graph": "", - "cluster-store": "", - "cluster-store-opts": {}, - "cluster-advertise": "", - "max-concurrent-downloads": 3, - "max-concurrent-uploads": 5, - "shutdown-timeout": 15, - "debug": true, - "hosts": [], - "log-level": "", - "tls": true, - "tlsverify": true, - "tlscacert": "", - "tlscert": "", - "tlskey": "", - "swarm-default-advertise-addr": "", - "api-cors-header": "", - "selinux-enabled": false, - "userns-remap": "", - "group": "", - "cgroup-parent": "", - "default-ulimits": {}, - "init": false, - "init-path": "/usr/libexec/docker-init", - "ipv6": false, - "iptables": false, - "ip-forward": false, - "ip-masq": false, - "userland-proxy": false, - "userland-proxy-path": "/usr/libexec/docker-proxy", - "ip": "0.0.0.0", - "bridge": "", - "bip": "", - "fixed-cidr": "", - "fixed-cidr-v6": "", - "default-gateway": "", - "default-gateway-v6": "", - "icc": false, - "raw-logs": false, - "registry-mirrors": [], - "seccomp-profile": "", - "insecure-registries": [], - "disable-legacy-registry": false, - "default-runtime": "runc", - "oom-score-adjust": -500, - "runtimes": { - "runc": { - "path": "runc" - }, - "custom": { - "path": "/usr/local/bin/my-runc-replacement", - "runtimeArgs": [ - "--debug" - ] - } - } -} -``` - -### Windows configuration file - -The default location of the configuration file on Windows is - `%programdata%\docker\config\daemon.json`. The `--config-file` flag can be - used to specify a non-default location. - -This is a full example of the allowed configuration options on Windows: - -```json -{ - "authorization-plugins": [], - "dns": [], - "dns-opts": [], - "dns-search": [], - "exec-opts": [], - "experimental": false, - "storage-driver": "", - "storage-opts": [], - "labels": [], - "log-driver": "", - "mtu": 0, - "pidfile": "", - "graph": "", - "cluster-store": "", - "cluster-advertise": "", - "max-concurrent-downloads": 3, - "max-concurrent-uploads": 5, - "shutdown-timeout": 15, - "debug": true, - "hosts": [], - "log-level": "", - "tlsverify": true, - "tlscacert": "", - "tlscert": "", - "tlskey": "", - "swarm-default-advertise-addr": "", - "group": "", - "default-ulimits": {}, - "bridge": "", - "fixed-cidr": "", - "raw-logs": false, - "registry-mirrors": [], - "insecure-registries": [], - "disable-legacy-registry": false -} -``` - -### Configuration reloading - -Some options can be reconfigured when the daemon is running without requiring -to restart the process. We use the `SIGHUP` signal in Linux to reload, and a global event -in Windows with the key `Global\docker-daemon-config-$PID`. The options can -be modified in the configuration file but still will check for conflicts with -the provided flags. The daemon fails to reconfigure itself -if there are conflicts, but it won't stop execution. - -The list of currently supported options that can be reconfigured is this: - -- `debug`: it changes the daemon to debug mode when set to true. -- `cluster-store`: it reloads the discovery store with the new address. -- `cluster-store-opts`: it uses the new options to reload the discovery store. -- `cluster-advertise`: it modifies the address advertised after reloading. -- `labels`: it replaces the daemon labels with a new set of labels. -- `live-restore`: Enables [keeping containers alive during daemon downtime](https://docs.docker.com/engine/admin/live-restore/). -- `max-concurrent-downloads`: it updates the max concurrent downloads for each pull. -- `max-concurrent-uploads`: it updates the max concurrent uploads for each push. -- `default-runtime`: it updates the runtime to be used if not is - specified at container creation. It defaults to "default" which is - the runtime shipped with the official docker packages. -- `runtimes`: it updates the list of available OCI runtimes that can - be used to run containers -- `authorization-plugin`: specifies the authorization plugins to use. -- `insecure-registries`: it replaces the daemon insecure registries with a new set of insecure registries. If some existing insecure registries in daemon's configuration are not in newly reloaded insecure resgitries, these existing ones will be removed from daemon's config. - -Updating and reloading the cluster configurations such as `--cluster-store`, -`--cluster-advertise` and `--cluster-store-opts` will take effect only if -these configurations were not previously configured. If `--cluster-store` -has been provided in flags and `cluster-advertise` not, `cluster-advertise` -can be added in the configuration file without accompanied by `--cluster-store`. -Configuration reload will log a warning message if it detects a change in -previously configured cluster configurations. - - -## Running multiple daemons - -> **Note:** Running multiple daemons on a single host is considered as "experimental". The user should be aware of -> unsolved problems. This solution may not work properly in some cases. Solutions are currently under development -> and will be delivered in the near future. - -This section describes how to run multiple Docker daemons on a single host. To -run multiple daemons, you must configure each daemon so that it does not -conflict with other daemons on the same host. You can set these options either -by providing them as flags, or by using a [daemon configuration file](#daemon-configuration-file). - -The following daemon options must be configured for each daemon: - -```bash --b, --bridge= Attach containers to a network bridge ---exec-root=/var/run/docker Root of the Docker execdriver --g, --graph=/var/lib/docker Root of the Docker runtime --p, --pidfile=/var/run/docker.pid Path to use for daemon PID file --H, --host=[] Daemon socket(s) to connect to ---iptables=true Enable addition of iptables rules ---config-file=/etc/docker/daemon.json Daemon configuration file ---tlscacert="~/.docker/ca.pem" Trust certs signed only by this CA ---tlscert="~/.docker/cert.pem" Path to TLS certificate file ---tlskey="~/.docker/key.pem" Path to TLS key file -``` - -When your daemons use different values for these flags, you can run them on the same host without any problems. -It is very important to properly understand the meaning of those options and to use them correctly. - -- The `-b, --bridge=` flag is set to `docker0` as default bridge network. It is created automatically when you install Docker. -If you are not using the default, you must create and configure the bridge manually or just set it to 'none': `--bridge=none` -- `--exec-root` is the path where the container state is stored. The default value is `/var/run/docker`. Specify the path for -your running daemon here. -- `--graph` is the path where images are stored. The default value is `/var/lib/docker`. To avoid any conflict with other daemons -set this parameter separately for each daemon. -- `-p, --pidfile=/var/run/docker.pid` is the path where the process ID of the daemon is stored. Specify the path for your -pid file here. -- `--host=[]` specifies where the Docker daemon will listen for client connections. If unspecified, it defaults to `/var/run/docker.sock`. -- `--iptables=false` prevents the Docker daemon from adding iptables rules. If -multiple daemons manage iptables rules, they may overwrite rules set by another -daemon. Be aware that disabling this option requires you to manually add -iptables rules to expose container ports. If you prevent Docker from adding -iptables rules, Docker will also not add IP masquerading rules, even if you set -`--ip-masq` to `true`. Without IP masquerading rules, Docker containers will not be -able to connect to external hosts or the internet when using network other than -default bridge. -- `--config-file=/etc/docker/daemon.json` is the path where configuration file is stored. You can use it instead of -daemon flags. Specify the path for each daemon. -- `--tls*` Docker daemon supports `--tlsverify` mode that enforces encrypted and authenticated remote connections. -The `--tls*` options enable use of specific certificates for individual daemons. - -Example script for a separate “bootstrap” instance of the Docker daemon without network: - -```bash -$ sudo dockerd \ - -H unix:///var/run/docker-bootstrap.sock \ - -p /var/run/docker-bootstrap.pid \ - --iptables=false \ - --ip-masq=false \ - --bridge=none \ - --graph=/var/lib/docker-bootstrap \ - --exec-root=/var/run/docker-bootstrap -``` diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/events.md b/vendor/github.com/docker/docker/docs/reference/commandline/events.md deleted file mode 100644 index baa966d..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/events.md +++ /dev/null @@ -1,217 +0,0 @@ ---- -title: "events" -description: "The events command description and usage" -keywords: "events, container, report" ---- - - - -# events - -```markdown -Usage: docker events [OPTIONS] - -Get real time events from the server - -Options: - -f, --filter value Filter output based on conditions provided (default []) - --format string Format the output using the given Go template - --help Print usage - --since string Show all events created since timestamp - --until string Stream events until this timestamp -``` - -Docker containers report the following events: - - attach, commit, copy, create, destroy, detach, die, exec_create, exec_detach, exec_start, export, health_status, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update - -Docker images report the following events: - - delete, import, load, pull, push, save, tag, untag - -Docker plugins report the following events: - - install, enable, disable, remove - -Docker volumes report the following events: - - create, mount, unmount, destroy - -Docker networks report the following events: - - create, connect, disconnect, destroy - -Docker daemon report the following events: - - reload - -The `--since` and `--until` parameters can be Unix timestamps, date formatted -timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed -relative to the client machine’s time. If you do not provide the `--since` option, -the command returns only new and/or live events. Supported formats for date -formatted time stamps include RFC3339Nano, RFC3339, `2006-01-02T15:04:05`, -`2006-01-02T15:04:05.999999999`, `2006-01-02Z07:00`, and `2006-01-02`. The local -timezone on the client will be used if you do not provide either a `Z` or a -`+-00:00` timezone offset at the end of the timestamp. When providing Unix -timestamps enter seconds[.nanoseconds], where seconds is the number of seconds -that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap -seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a -fraction of a second no more than nine digits long. - -## Filtering - -The filtering flag (`-f` or `--filter`) format is of "key=value". If you would -like to use multiple filters, pass multiple flags (e.g., -`--filter "foo=bar" --filter "bif=baz"`) - -Using the same filter multiple times will be handled as a *OR*; for example -`--filter container=588a23dac085 --filter container=a8f7720b8c22` will display -events for container 588a23dac085 *OR* container a8f7720b8c22 - -Using multiple filters will be handled as a *AND*; for example -`--filter container=588a23dac085 --filter event=start` will display events for -container container 588a23dac085 *AND* the event type is *start* - -The currently supported filters are: - -* container (`container=`) -* event (`event=`) -* image (`image=`) -* plugin (experimental) (`plugin=`) -* label (`label=` or `label==`) -* type (`type=`) -* volume (`volume=`) -* network (`network=`) -* daemon (`daemon=`) - -## Format - -If a format (`--format`) is specified, the given template will be executed -instead of the default -format. Go's [text/template](http://golang.org/pkg/text/template/) package -describes all the details of the format. - -If a format is set to `{{json .}}`, the events are streamed as valid JSON -Lines. For information about JSON Lines, please refer to http://jsonlines.org/ . - -## Examples - -You'll need two shells for this example. - -**Shell 1: Listening for events:** - - $ docker events - -**Shell 2: Start and Stop containers:** - - $ docker start 4386fb97867d - $ docker stop 4386fb97867d - $ docker stop 7805c1d35632 - -**Shell 1: (Again .. now showing events):** - - 2015-05-12T11:51:30.999999999Z07:00 container start 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T11:51:30.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T15:52:12.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T15:53:45.999999999Z07:00 container die 7805c1d35632 (image=redis:2.8) - 2015-05-12T15:54:03.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - -**Show events in the past from a specified time:** - - $ docker events --since 1378216169 - 2015-05-12T11:51:30.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T15:52:12.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T15:53:45.999999999Z07:00 container die 7805c1d35632 (image=redis:2.8) - 2015-05-12T15:54:03.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - - $ docker events --since '2013-09-03' - 2015-05-12T11:51:30.999999999Z07:00 container start 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T11:51:30.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T15:52:12.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T15:53:45.999999999Z07:00 container die 7805c1d35632 (image=redis:2.8) - 2015-05-12T15:54:03.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - - $ docker events --since '2013-09-03T15:49:29' - 2015-05-12T11:51:30.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T15:52:12.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T15:53:45.999999999Z07:00 container die 7805c1d35632 (image=redis:2.8) - 2015-05-12T15:54:03.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - -This example outputs all events that were generated in the last 3 minutes, -relative to the current time on the client machine: - - $ docker events --since '3m' - 2015-05-12T11:51:30.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T15:52:12.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - 2015-05-12T15:53:45.999999999Z07:00 container die 7805c1d35632 (image=redis:2.8) - 2015-05-12T15:54:03.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - -**Filter events:** - - $ docker events --filter 'event=stop' - 2014-05-10T17:42:14.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - 2014-09-03T17:42:14.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - - $ docker events --filter 'image=ubuntu-1:14.04' - 2014-05-10T17:42:14.999999999Z07:00 container start 4386fb97867d (image=ubuntu-1:14.04) - 2014-05-10T17:42:14.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) - 2014-05-10T17:42:14.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - - $ docker events --filter 'container=7805c1d35632' - 2014-05-10T17:42:14.999999999Z07:00 container die 7805c1d35632 (image=redis:2.8) - 2014-09-03T15:49:29.999999999Z07:00 container stop 7805c1d35632 (image= redis:2.8) - - $ docker events --filter 'container=7805c1d35632' --filter 'container=4386fb97867d' - 2014-09-03T15:49:29.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) - 2014-05-10T17:42:14.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - 2014-05-10T17:42:14.999999999Z07:00 container die 7805c1d35632 (image=redis:2.8) - 2014-09-03T15:49:29.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - - $ docker events --filter 'container=7805c1d35632' --filter 'event=stop' - 2014-09-03T15:49:29.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - - $ docker events --filter 'container=container_1' --filter 'container=container_2' - 2014-09-03T15:49:29.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) - 2014-05-10T17:42:14.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - 2014-05-10T17:42:14.999999999Z07:00 container die 7805c1d35632 (imager=redis:2.8) - 2014-09-03T15:49:29.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - - $ docker events --filter 'type=volume' - 2015-12-23T21:05:28.136212689Z volume create test-event-volume-local (driver=local) - 2015-12-23T21:05:28.383462717Z volume mount test-event-volume-local (read/write=true, container=562fe10671e9273da25eed36cdce26159085ac7ee6707105fd534866340a5025, destination=/foo, driver=local, propagation=rprivate) - 2015-12-23T21:05:28.650314265Z volume unmount test-event-volume-local (container=562fe10671e9273da25eed36cdce26159085ac7ee6707105fd534866340a5025, driver=local) - 2015-12-23T21:05:28.716218405Z volume destroy test-event-volume-local (driver=local) - - $ docker events --filter 'type=network' - 2015-12-23T21:38:24.705709133Z network create 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (name=test-event-network-local, type=bridge) - 2015-12-23T21:38:25.119625123Z network connect 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (name=test-event-network-local, container=b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e, type=bridge) - - $ docker events --filter 'type=plugin' (experimental) - 2016-07-25T17:30:14.825557616Z plugin pull ec7b87f2ce84330fe076e666f17dfc049d2d7ae0b8190763de94e1f2d105993f (name=tiborvass/sample-volume-plugin:latest) - 2016-07-25T17:30:14.888127370Z plugin enable ec7b87f2ce84330fe076e666f17dfc049d2d7ae0b8190763de94e1f2d105993f (name=tiborvass/sample-volume-plugin:latest) - -**Format:** - - $ docker events --filter 'type=container' --format 'Type={{.Type}} Status={{.Status}} ID={{.ID}}' - Type=container Status=create ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - Type=container Status=attach ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - Type=container Status=start ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - Type=container Status=resize ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - Type=container Status=die ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - Type=container Status=destroy ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - -**Format (as JSON Lines):** - - $ docker events --format '{{json .}}' - {"status":"create","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f4.. - {"status":"attach","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f4.. - {"Type":"network","Action":"connect","Actor":{"ID":"1b50a5bf755f6021dfa78e.. - {"status":"start","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f42.. - {"status":"resize","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f4.. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/exec.md b/vendor/github.com/docker/docker/docs/reference/commandline/exec.md deleted file mode 100644 index 38891c9..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/exec.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: "exec" -description: "The exec command description and usage" -keywords: "command, container, run, execute" ---- - - - -# exec - -```markdown -Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] - -Run a command in a running container - -Options: - -d, --detach Detached mode: run command in the background - --detach-keys Override the key sequence for detaching a container - -e, --env=[] Set environment variables - --help Print usage - -i, --interactive Keep STDIN open even if not attached - --privileged Give extended privileges to the command - -t, --tty Allocate a pseudo-TTY - -u, --user Username or UID (format: [:]) -``` - -The `docker exec` command runs a new command in a running container. - -The command started using `docker exec` only runs while the container's primary -process (`PID 1`) is running, and it is not restarted if the container is -restarted. - -If the container is paused, then the `docker exec` command will fail with an error: - - $ docker pause test - test - $ docker ps - CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES - 1ae3b36715d2 ubuntu:latest "bash" 17 seconds ago Up 16 seconds (Paused) test - $ docker exec test ls - FATA[0000] Error response from daemon: Container test is paused, unpause the container before exec - $ echo $? - 1 - -## Examples - - $ docker run --name ubuntu_bash --rm -i -t ubuntu bash - -This will create a container named `ubuntu_bash` and start a Bash session. - - $ docker exec -d ubuntu_bash touch /tmp/execWorks - -This will create a new file `/tmp/execWorks` inside the running container -`ubuntu_bash`, in the background. - - $ docker exec -it ubuntu_bash bash - -This will create a new Bash session in the container `ubuntu_bash`. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/export.md b/vendor/github.com/docker/docker/docs/reference/commandline/export.md deleted file mode 100644 index 1004fc3..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/export.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: "export" -description: "The export command description and usage" -keywords: "export, file, system, container" ---- - - - -# export - -```markdown -Usage: docker export [OPTIONS] CONTAINER - -Export a container's filesystem as a tar archive - -Options: - --help Print usage - -o, --output string Write to a file, instead of STDOUT -``` - -The `docker export` command does not export the contents of volumes associated -with the container. If a volume is mounted on top of an existing directory in -the container, `docker export` will export the contents of the *underlying* -directory, not the contents of the volume. - -Refer to [Backup, restore, or migrate data -volumes](https://docs.docker.com/engine/tutorials/dockervolumes/#backup-restore-or-migrate-data-volumes) in -the user guide for examples on exporting data in a volume. - -## Examples - - $ docker export red_panda > latest.tar - -Or - - $ docker export --output="latest.tar" red_panda diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/history.md b/vendor/github.com/docker/docker/docs/reference/commandline/history.md deleted file mode 100644 index 00f88db..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/history.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "history" -description: "The history command description and usage" -keywords: "docker, image, history" ---- - - - -# history - -```markdown -Usage: docker history [OPTIONS] IMAGE - -Show the history of an image - -Options: - --help Print usage - -H, --human Print sizes and dates in human readable format (default true) - --no-trunc Don't truncate output - -q, --quiet Only show numeric IDs -``` - -To see how the `docker:latest` image was built: - - $ docker history docker - IMAGE CREATED CREATED BY SIZE COMMENT - 3e23a5875458 8 days ago /bin/sh -c #(nop) ENV LC_ALL=C.UTF-8 0 B - 8578938dd170 8 days ago /bin/sh -c dpkg-reconfigure locales && loc 1.245 MB - be51b77efb42 8 days ago /bin/sh -c apt-get update && apt-get install 338.3 MB - 4b137612be55 6 weeks ago /bin/sh -c #(nop) ADD jessie.tar.xz in / 121 MB - 750d58736b4b 6 weeks ago /bin/sh -c #(nop) MAINTAINER Tianon Gravi - -# image prune - -```markdown -Usage: docker image prune [OPTIONS] - -Remove unused images - -Options: - -a, --all Remove all unused images, not just dangling ones - -f, --force Do not prompt for confirmation - --help Print usage -``` - -Remove all dangling images. If `-a` is specified, will also remove all images not referenced by any container. - -Example output: - -```bash -$ docker image prune -a -WARNING! This will remove all images without at least one container associated to them. -Are you sure you want to continue? [y/N] y -Deleted Images: -untagged: alpine:latest -untagged: alpine@sha256:3dcdb92d7432d56604d4545cbd324b14e647b313626d99b889d0626de158f73a -deleted: sha256:4e38e38c8ce0b8d9041a9c4fefe786631d1416225e13b0bfe8cfa2321aec4bba -deleted: sha256:4fe15f8d0ae69e169824f25f1d4da3015a48feeeeebb265cd2e328e15c6a869f -untagged: alpine:3.3 -untagged: alpine@sha256:4fa633f4feff6a8f02acfc7424efd5cb3e76686ed3218abf4ca0fa4a2a358423 -untagged: my-jq:latest -deleted: sha256:ae67841be6d008a374eff7c2a974cde3934ffe9536a7dc7ce589585eddd83aff -deleted: sha256:34f6f1261650bc341eb122313372adc4512b4fceddc2a7ecbb84f0958ce5ad65 -deleted: sha256:cf4194e8d8db1cb2d117df33f2c75c0369c3a26d96725efb978cc69e046b87e7 -untagged: my-curl:latest -deleted: sha256:b2789dd875bf427de7f9f6ae001940073b3201409b14aba7e5db71f408b8569e -deleted: sha256:96daac0cb203226438989926fc34dd024f365a9a8616b93e168d303cfe4cb5e9 -deleted: sha256:5cbd97a14241c9cd83250d6b6fc0649833c4a3e84099b968dd4ba403e609945e -deleted: sha256:a0971c4015c1e898c60bf95781c6730a05b5d8a2ae6827f53837e6c9d38efdec -deleted: sha256:d8359ca3b681cc5396a4e790088441673ed3ce90ebc04de388bfcd31a0716b06 -deleted: sha256:83fc9ba8fb70e1da31dfcc3c88d093831dbd4be38b34af998df37e8ac538260c -deleted: sha256:ae7041a4cc625a9c8e6955452f7afe602b401f662671cea3613f08f3d9343b35 -deleted: sha256:35e0f43a37755b832f0bbea91a2360b025ee351d7309dae0d9737bc96b6d0809 -deleted: sha256:0af941dd29f00e4510195dd00b19671bc591e29d1495630e7e0f7c44c1e6a8c0 -deleted: sha256:9fc896fc2013da84f84e45b3096053eb084417b42e6b35ea0cce5a3529705eac -deleted: sha256:47cf20d8c26c46fff71be614d9f54997edacfe8d46d51769706e5aba94b16f2b -deleted: sha256:2c675ee9ed53425e31a13e3390bf3f539bf8637000e4bcfbb85ee03ef4d910a1 - -Total reclaimed space: 16.43 MB -``` - -## Related information - -* [system df](system_df.md) -* [container prune](container_prune.md) -* [volume prune](volume_prune.md) -* [network prune](network_prune.md) -* [system prune](system_prune.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/images.md b/vendor/github.com/docker/docker/docs/reference/commandline/images.md deleted file mode 100644 index 3b9ea1f..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/images.md +++ /dev/null @@ -1,304 +0,0 @@ ---- -title: "images" -description: "The images command description and usage" -keywords: "list, docker, images" ---- - - - -# images - -```markdown -Usage: docker images [OPTIONS] [REPOSITORY[:TAG]] - -List images - -Options: - -a, --all Show all images (default hides intermediate images) - --digests Show digests - -f, --filter value Filter output based on conditions provided (default []) - - dangling=(true|false) - - label= or label== - - before=([:tag]||) - - since=([:tag]||) - - reference=(pattern of an image reference) - --format string Pretty-print images using a Go template - --help Print usage - --no-trunc Don't truncate output - -q, --quiet Only show numeric IDs -``` - -The default `docker images` will show all top level -images, their repository and tags, and their size. - -Docker images have intermediate layers that increase reusability, -decrease disk usage, and speed up `docker build` by -allowing each step to be cached. These intermediate layers are not shown -by default. - -The `SIZE` is the cumulative space taken up by the image and all -its parent images. This is also the disk space used by the contents of the -Tar file created when you `docker save` an image. - -An image will be listed more than once if it has multiple repository names -or tags. This single image (identifiable by its matching `IMAGE ID`) -uses up the `SIZE` listed only once. - -### Listing the most recently created images - - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - 77af4d6b9913 19 hours ago 1.089 GB - committ latest b6fa739cedf5 19 hours ago 1.089 GB - 78a85c484f71 19 hours ago 1.089 GB - docker latest 30557a29d5ab 20 hours ago 1.089 GB - 5ed6274db6ce 24 hours ago 1.089 GB - postgres 9 746b819f315e 4 days ago 213.4 MB - postgres 9.3 746b819f315e 4 days ago 213.4 MB - postgres 9.3.5 746b819f315e 4 days ago 213.4 MB - postgres latest 746b819f315e 4 days ago 213.4 MB - -### Listing images by name and tag - -The `docker images` command takes an optional `[REPOSITORY[:TAG]]` argument -that restricts the list to images that match the argument. If you specify -`REPOSITORY`but no `TAG`, the `docker images` command lists all images in the -given repository. - -For example, to list all images in the "java" repository, run this command : - - $ docker images java - REPOSITORY TAG IMAGE ID CREATED SIZE - java 8 308e519aac60 6 days ago 824.5 MB - java 7 493d82594c15 3 months ago 656.3 MB - java latest 2711b1d6f3aa 5 months ago 603.9 MB - -The `[REPOSITORY[:TAG]]` value must be an "exact match". This means that, for example, -`docker images jav` does not match the image `java`. - -If both `REPOSITORY` and `TAG` are provided, only images matching that -repository and tag are listed. To find all local images in the "java" -repository with tag "8" you can use: - - $ docker images java:8 - REPOSITORY TAG IMAGE ID CREATED SIZE - java 8 308e519aac60 6 days ago 824.5 MB - -If nothing matches `REPOSITORY[:TAG]`, the list is empty. - - $ docker images java:0 - REPOSITORY TAG IMAGE ID CREATED SIZE - -## Listing the full length image IDs - - $ docker images --no-trunc - REPOSITORY TAG IMAGE ID CREATED SIZE - sha256:77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 1.089 GB - committest latest sha256:b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 1.089 GB - sha256:78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 1.089 GB - docker latest sha256:30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 1.089 GB - sha256:0124422dd9f9cf7ef15c0617cda3931ee68346455441d66ab8bdc5b05e9fdce5 20 hours ago 1.089 GB - sha256:18ad6fad340262ac2a636efd98a6d1f0ea775ae3d45240d3418466495a19a81b 22 hours ago 1.082 GB - sha256:f9f1e26352f0a3ba6a0ff68167559f64f3e21ff7ada60366e2d44a04befd1d3a 23 hours ago 1.089 GB - tryout latest sha256:2629d1fa0b81b222fca63371ca16cbf6a0772d07759ff80e8d1369b926940074 23 hours ago 131.5 MB - sha256:5ed6274db6ceb2397844896966ea239290555e74ef307030ebb01ff91b1914df 24 hours ago 1.089 GB - -## Listing image digests - -Images that use the v2 or later format have a content-addressable identifier -called a `digest`. As long as the input used to generate the image is -unchanged, the digest value is predictable. To list image digest values, use -the `--digests` flag: - - $ docker images --digests - REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE - localhost:5000/test/busybox sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf 4986bf8c1536 9 weeks ago 2.43 MB - -When pushing or pulling to a 2.0 registry, the `push` or `pull` command -output includes the image digest. You can `pull` using a digest value. You can -also reference by digest in `create`, `run`, and `rmi` commands, as well as the -`FROM` image reference in a Dockerfile. - -## Filtering - -The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more -than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`) - -The currently supported filters are: - -* dangling (boolean - true or false) -* label (`label=` or `label==`) -* before (`[:]`, `` or ``) - filter images created before given id or references -* since (`[:]`, `` or ``) - filter images created since given id or references - -##### Untagged images (dangling) - - $ docker images --filter "dangling=true" - - REPOSITORY TAG IMAGE ID CREATED SIZE - 8abc22fbb042 4 weeks ago 0 B - 48e5f45168b9 4 weeks ago 2.489 MB - bf747efa0e2f 4 weeks ago 0 B - 980fe10e5736 12 weeks ago 101.4 MB - dea752e4e117 12 weeks ago 101.4 MB - 511136ea3c5a 8 months ago 0 B - -This will display untagged images, that are the leaves of the images tree (not -intermediary layers). These images occur when a new build of an image takes the -`repo:tag` away from the image ID, leaving it as `:` or untagged. -A warning will be issued if trying to remove an image when a container is presently -using it. By having this flag it allows for batch cleanup. - -Ready for use by `docker rmi ...`, like: - - $ docker rmi $(docker images -f "dangling=true" -q) - - 8abc22fbb042 - 48e5f45168b9 - bf747efa0e2f - 980fe10e5736 - dea752e4e117 - 511136ea3c5a - -NOTE: Docker will warn you if any containers exist that are using these untagged images. - - -##### Labeled images - -The `label` filter matches images based on the presence of a `label` alone or a `label` and a -value. - -The following filter matches images with the `com.example.version` label regardless of its value. - - $ docker images --filter "label=com.example.version" - - REPOSITORY TAG IMAGE ID CREATED SIZE - match-me-1 latest eeae25ada2aa About a minute ago 188.3 MB - match-me-2 latest dea752e4e117 About a minute ago 188.3 MB - -The following filter matches images with the `com.example.version` label with the `1.0` value. - - $ docker images --filter "label=com.example.version=1.0" - REPOSITORY TAG IMAGE ID CREATED SIZE - match-me latest 511136ea3c5a About a minute ago 188.3 MB - -In this example, with the `0.1` value, it returns an empty set because no matches were found. - - $ docker images --filter "label=com.example.version=0.1" - REPOSITORY TAG IMAGE ID CREATED SIZE - -#### Before - -The `before` filter shows only images created before the image with -given id or reference. For example, having these images: - - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - image1 latest eeae25ada2aa 4 minutes ago 188.3 MB - image2 latest dea752e4e117 9 minutes ago 188.3 MB - image3 latest 511136ea3c5a 25 minutes ago 188.3 MB - -Filtering with `before` would give: - - $ docker images --filter "before=image1" - REPOSITORY TAG IMAGE ID CREATED SIZE - image2 latest dea752e4e117 9 minutes ago 188.3 MB - image3 latest 511136ea3c5a 25 minutes ago 188.3 MB - -#### Since - -The `since` filter shows only images created after the image with -given id or reference. For example, having these images: - - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - image1 latest eeae25ada2aa 4 minutes ago 188.3 MB - image2 latest dea752e4e117 9 minutes ago 188.3 MB - image3 latest 511136ea3c5a 25 minutes ago 188.3 MB - -Filtering with `since` would give: - - $ docker images --filter "since=image3" - REPOSITORY TAG IMAGE ID CREATED SIZE - image1 latest eeae25ada2aa 4 minutes ago 188.3 MB - image2 latest dea752e4e117 9 minutes ago 188.3 MB - -#### Reference - -The `reference` filter shows only images whose reference matches -the specified pattern. - - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - busybox latest e02e811dd08f 5 weeks ago 1.09 MB - busybox uclibc e02e811dd08f 5 weeks ago 1.09 MB - busybox musl 733eb3059dce 5 weeks ago 1.21 MB - busybox glibc 21c16b6787c6 5 weeks ago 4.19 MB - -Filtering with `reference` would give: - - $ docker images --filter=reference='busy*:*libc' - REPOSITORY TAG IMAGE ID CREATED SIZE - busybox uclibc e02e811dd08f 5 weeks ago 1.09 MB - busybox glibc 21c16b6787c6 5 weeks ago 4.19 MB - -## Formatting - -The formatting option (`--format`) will pretty print container output -using a Go template. - -Valid placeholders for the Go template are listed below: - -Placeholder | Description ----- | ---- -`.ID` | Image ID -`.Repository` | Image repository -`.Tag` | Image tag -`.Digest` | Image digest -`.CreatedSince` | Elapsed time since the image was created -`.CreatedAt` | Time when the image was created -`.Size` | Image disk size - -When using the `--format` option, the `image` command will either -output the data exactly as the template declares or, when using the -`table` directive, will include column headers as well. - -The following example uses a template without headers and outputs the -`ID` and `Repository` entries separated by a colon for all images: - - {% raw %} - $ docker images --format "{{.ID}}: {{.Repository}}" - 77af4d6b9913: - b6fa739cedf5: committ - 78a85c484f71: - 30557a29d5ab: docker - 5ed6274db6ce: - 746b819f315e: postgres - 746b819f315e: postgres - 746b819f315e: postgres - 746b819f315e: postgres - {% endraw %} - -To list all images with their repository and tag in a table format you -can use: - - {% raw %} - $ docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}" - IMAGE ID REPOSITORY TAG - 77af4d6b9913 - b6fa739cedf5 committ latest - 78a85c484f71 - 30557a29d5ab docker latest - 5ed6274db6ce - 746b819f315e postgres 9 - 746b819f315e postgres 9.3 - 746b819f315e postgres 9.3.5 - 746b819f315e postgres latest - {% endraw %} diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/import.md b/vendor/github.com/docker/docker/docs/reference/commandline/import.md deleted file mode 100644 index 20e90a6..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/import.md +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: "import" -description: "The import command description and usage" -keywords: "import, file, system, container" ---- - - - -# import - -```markdown -Usage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]] - -Import the contents from a tarball to create a filesystem image - -Options: - -c, --change value Apply Dockerfile instruction to the created image (default []) - --help Print usage - -m, --message string Set commit message for imported image -``` - -You can specify a `URL` or `-` (dash) to take data directly from `STDIN`. The -`URL` can point to an archive (.tar, .tar.gz, .tgz, .bzip, .tar.xz, or .txz) -containing a filesystem or to an individual file on the Docker host. If you -specify an archive, Docker untars it in the container relative to the `/` -(root). If you specify an individual file, you must specify the full path within -the host. To import from a remote location, specify a `URI` that begins with the -`http://` or `https://` protocol. - -The `--change` option will apply `Dockerfile` instructions to the image -that is created. -Supported `Dockerfile` instructions: -`CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`ONBUILD`|`USER`|`VOLUME`|`WORKDIR` - -## Examples - -**Import from a remote location:** - -This will create a new untagged image. - - $ docker import http://example.com/exampleimage.tgz - -**Import from a local file:** - -Import to docker via pipe and `STDIN`. - - $ cat exampleimage.tgz | docker import - exampleimagelocal:new - -Import with a commit message. - - $ cat exampleimage.tgz | docker import --message "New image imported from tarball" - exampleimagelocal:new - -Import to docker from a local archive. - - $ docker import /path/to/exampleimage.tgz - -**Import from a local directory:** - - $ sudo tar -c . | docker import - exampleimagedir - -**Import from a local directory with new configurations:** - - $ sudo tar -c . | docker import --change "ENV DEBUG true" - exampleimagedir - -Note the `sudo` in this example – you must preserve -the ownership of the files (especially root ownership) during the -archiving with tar. If you are not root (or the sudo command) when you -tar, then the ownerships might not get preserved. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/index.md b/vendor/github.com/docker/docker/docs/reference/commandline/index.md deleted file mode 100644 index 952fa09..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/index.md +++ /dev/null @@ -1,178 +0,0 @@ ---- -title: "Docker commands" -description: "Docker's CLI command description and usage" -keywords: "Docker, Docker documentation, CLI, command line" -identifier: "smn_cli_guide" ---- - - - -# The Docker commands - -This section contains reference information on using Docker's command line -client. Each command has a reference page along with samples. If you are -unfamiliar with the command line, you should start by reading about how to [Use -the Docker command line](cli.md). - -You start the Docker daemon with the command line. How you start the daemon -affects your Docker containers. For that reason you should also make sure to -read the [`dockerd`](dockerd.md) reference page. - -### Docker management commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [dockerd](dockerd.md) | Launch the Docker daemon | -| [info](info.md) | Display system-wide information | -| [inspect](inspect.md)| Return low-level information on a container or image | -| [version](version.md) | Show the Docker version information | - - -### Image commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [build](build.md) | Build an image from a Dockerfile | -| [commit](commit.md) | Create a new image from a container's changes | -| [history](history.md) | Show the history of an image | -| [images](images.md) | List images | -| [import](import.md) | Import the contents from a tarball to create a filesystem image | -| [load](load.md) | Load an image from a tar archive or STDIN | -| [rmi](rmi.md) | Remove one or more images | -| [save](save.md) | Save images to a tar archive | -| [tag](tag.md) | Tag an image into a repository | - -### Container commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [attach](attach.md) | Attach to a running container | -| [cp](cp.md) | Copy files/folders from a container to a HOSTDIR or to STDOUT | -| [create](create.md) | Create a new container | -| [diff](diff.md) | Inspect changes on a container's filesystem | -| [events](events.md) | Get real time events from the server | -| [exec](exec.md) | Run a command in a running container | -| [export](export.md) | Export a container's filesystem as a tar archive | -| [kill](kill.md) | Kill a running container | -| [logs](logs.md) | Fetch the logs of a container | -| [pause](pause.md) | Pause all processes within a container | -| [port](port.md) | List port mappings or a specific mapping for the container | -| [ps](ps.md) | List containers | -| [rename](rename.md) | Rename a container | -| [restart](restart.md) | Restart a running container | -| [rm](rm.md) | Remove one or more containers | -| [run](run.md) | Run a command in a new container | -| [start](start.md) | Start one or more stopped containers | -| [stats](stats.md) | Display a live stream of container(s) resource usage statistics | -| [stop](stop.md) | Stop a running container | -| [top](top.md) | Display the running processes of a container | -| [unpause](unpause.md) | Unpause all processes within a container | -| [update](update.md) | Update configuration of one or more containers | -| [wait](wait.md) | Block until a container stops, then print its exit code | - -### Hub and registry commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [login](login.md) | Register or log in to a Docker registry | -| [logout](logout.md) | Log out from a Docker registry | -| [pull](pull.md) | Pull an image or a repository from a Docker registry | -| [push](push.md) | Push an image or a repository to a Docker registry | -| [search](search.md) | Search the Docker Hub for images | - -### Network and connectivity commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [network connect](network_connect.md) | Connect a container to a network | -| [network create](network_create.md) | Create a new network | -| [network disconnect](network_disconnect.md) | Disconnect a container from a network | -| [network inspect](network_inspect.md) | Display information about a network | -| [network ls](network_ls.md) | Lists all the networks the Engine `daemon` knows about | -| [network rm](network_rm.md) | Removes one or more networks | - - -### Shared data volume commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [volume create](volume_create.md) | Creates a new volume where containers can consume and store data | -| [volume inspect](volume_inspect.md) | Display information about a volume | -| [volume ls](volume_ls.md) | Lists all the volumes Docker knows about | -| [volume prune](volume_prune.md) | Remove all unused volumes | -| [volume rm](volume_rm.md) | Remove one or more volumes | - - -### Swarm node commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [node promote](node_promote.md) | Promote a node that is pending a promotion to manager | -| [node demote](node_demote.md) | Demotes an existing manager so that it is no longer a manager | -| [node inspect](node_inspect.md) | Inspect a node in the swarm | -| [node update](node_update.md) | Update attributes for a node | -| [node ps](node_ps.md) | List tasks running on one or more nodes | -| [node ls](node_ls.md) | List nodes in the swarm | -| [node rm](node_rm.md) | Remove one or more nodes from the swarm | - -### Swarm swarm commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [swarm init](swarm_init.md) | Initialize a swarm | -| [swarm join](swarm_join.md) | Join a swarm as a manager node or worker node | -| [swarm leave](swarm_leave.md) | Remove the current node from the swarm | -| [swarm update](swarm_update.md) | Update attributes of a swarm | -| [swarm join-token](swarm_join_token.md) | Display or rotate join tokens | - -### Swarm service commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [service create](service_create.md) | Create a new service | -| [service inspect](service_inspect.md) | Inspect a service | -| [service ls](service_ls.md) | List services in the swarm | -| [service rm](service_rm.md) | Remove a service from the swarm | -| [service scale](service_scale.md) | Set the number of replicas for the desired state of the service | -| [service ps](service_ps.md) | List the tasks of a service | -| [service update](service_update.md) | Update the attributes of a service | - -### Swarm secret commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [secret create](secret_create.md) | Create a secret from a file or STDIN as content | -| [secret inspect](service_inspect.md) | Inspect the specified secret | -| [secret ls](secret_ls.md) | List secrets in the swarm | -| [secret rm](secret_rm.md) | Remove the specified secrets from the swarm | - -### Swarm stack commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [stack deploy](stack_deploy.md) | Deploy a new stack or update an existing stack | -| [stack ls](stack_ls.md) | List stacks in the swarm | -| [stack ps](stack_ps.md) | List the tasks in the stack | -| [stack rm](stack_rm.md) | Remove the stack from the swarm | -| [stack services](stack_services.md) | List the services in the stack | - -### Plugin commands - -| Command | Description | -|:--------|:-------------------------------------------------------------------| -| [plugin create](plugin_create.md) | Create a plugin from a rootfs and configuration | -| [plugin disable](plugin_disable.md) | Disable a plugin | -| [plugin enbale](plugin_enable.md) | Enable a plugin | -| [plugin inspect](plugin_inspect.md) | Display detailed information on a plugin | -| [plugin install](plugin_install.md) | Install a plugin | -| [plugin ls](plugin_ls.md) | List plugins | -| [plugin push](plugin_push.md) | Push a plugin to a registry | -| [plugin rm](plugin_rm.md) | Remove a plugin | -| [plugin set](plugin_set.md) | Change settings for a plugin | diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/info.md b/vendor/github.com/docker/docker/docs/reference/commandline/info.md deleted file mode 100644 index 50a084f..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/info.md +++ /dev/null @@ -1,224 +0,0 @@ ---- -title: "info" -description: "The info command description and usage" -keywords: "display, docker, information" ---- - - - -# info - -```markdown -Usage: docker info [OPTIONS] - -Display system-wide information - -Options: - -f, --format string Format the output using the given Go template - --help Print usage -``` - -This command displays system wide information regarding the Docker installation. -Information displayed includes the kernel version, number of containers and images. -The number of images shown is the number of unique images. The same image tagged -under different names is counted only once. - -If a format is specified, the given template will be executed instead of the -default format. Go's [text/template](http://golang.org/pkg/text/template/) package -describes all the details of the format. - -Depending on the storage driver in use, additional information can be shown, such -as pool name, data file, metadata file, data space used, total data space, metadata -space used, and total metadata space. - -The data file is where the images are stored and the metadata file is where the -meta data regarding those images are stored. When run for the first time Docker -allocates a certain amount of data space and meta data space from the space -available on the volume where `/var/lib/docker` is mounted. - -# Examples - -## Display Docker system information - -Here is a sample output for a daemon running on Ubuntu, using the overlay2 -storage driver and a node that is part of a 2-node swarm: - - $ docker -D info - Containers: 14 - Running: 3 - Paused: 1 - Stopped: 10 - Images: 52 - Server Version: 1.13.0 - Storage Driver: overlay2 - Backing Filesystem: extfs - Supports d_type: true - Native Overlay Diff: false - Logging Driver: json-file - Cgroup Driver: cgroupfs - Plugins: - Volume: local - Network: bridge host macvlan null overlay - Swarm: active - NodeID: rdjq45w1op418waxlairloqbm - Is Manager: true - ClusterID: te8kdyw33n36fqiz74bfjeixd - Managers: 1 - Nodes: 2 - Orchestration: - Task History Retention Limit: 5 - Raft: - Snapshot Interval: 10000 - Number of Old Snapshots to Retain: 0 - Heartbeat Tick: 1 - Election Tick: 3 - Dispatcher: - Heartbeat Period: 5 seconds - CA Configuration: - Expiry Duration: 3 months - Node Address: 172.16.66.128 172.16.66.129 - Manager Addresses: - 172.16.66.128:2477 - Runtimes: runc - Default Runtime: runc - Init Binary: docker-init - containerd version: 8517738ba4b82aff5662c97ca4627e7e4d03b531 - runc version: ac031b5bf1cc92239461125f4c1ffb760522bbf2 - init version: N/A (expected: v0.13.0) - Security Options: - apparmor - seccomp - Profile: default - Kernel Version: 4.4.0-31-generic - Operating System: Ubuntu 16.04.1 LTS - OSType: linux - Architecture: x86_64 - CPUs: 2 - Total Memory: 1.937 GiB - Name: ubuntu - ID: H52R:7ZR6:EIIA:76JG:ORIY:BVKF:GSFU:HNPG:B5MK:APSC:SZ3Q:N326 - Docker Root Dir: /var/lib/docker - Debug Mode (client): true - Debug Mode (server): true - File Descriptors: 30 - Goroutines: 123 - System Time: 2016-11-12T17:24:37.955404361-08:00 - EventsListeners: 0 - Http Proxy: http://test:test@proxy.example.com:8080 - Https Proxy: https://test:test@proxy.example.com:8080 - No Proxy: localhost,127.0.0.1,docker-registry.somecorporation.com - Registry: https://index.docker.io/v1/ - WARNING: No swap limit support - Labels: - storage=ssd - staging=true - Experimental: false - Insecure Registries: - 127.0.0.0/8 - Registry Mirrors: - http://192.168.1.2/ - http://registry-mirror.example.com:5000/ - Live Restore Enabled: false - -The global `-D` option tells all `docker` commands to output debug information. - -The example below shows the output for a daemon running on Red Hat Enterprise Linux, -using the devicemapper storage driver. As can be seen in the output, additional -information about the devicemapper storage driver is shown: - - $ docker info - Containers: 14 - Running: 3 - Paused: 1 - Stopped: 10 - Images: 52 - Server Version: 1.10.3 - Storage Driver: devicemapper - Pool Name: docker-202:2-25583803-pool - Pool Blocksize: 65.54 kB - Base Device Size: 10.74 GB - Backing Filesystem: xfs - Data file: /dev/loop0 - Metadata file: /dev/loop1 - Data Space Used: 1.68 GB - Data Space Total: 107.4 GB - Data Space Available: 7.548 GB - Metadata Space Used: 2.322 MB - Metadata Space Total: 2.147 GB - Metadata Space Available: 2.145 GB - Udev Sync Supported: true - Deferred Removal Enabled: false - Deferred Deletion Enabled: false - Deferred Deleted Device Count: 0 - Data loop file: /var/lib/docker/devicemapper/devicemapper/data - Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata - Library Version: 1.02.107-RHEL7 (2015-12-01) - Execution Driver: native-0.2 - Logging Driver: json-file - Plugins: - Volume: local - Network: null host bridge - Kernel Version: 3.10.0-327.el7.x86_64 - Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo) - OSType: linux - Architecture: x86_64 - CPUs: 1 - Total Memory: 991.7 MiB - Name: ip-172-30-0-91.ec2.internal - ID: I54V:OLXT:HVMM:TPKO:JPHQ:CQCD:JNLC:O3BZ:4ZVJ:43XJ:PFHZ:6N2S - Docker Root Dir: /var/lib/docker - Debug mode (client): false - Debug mode (server): false - Username: gordontheturtle - Registry: https://index.docker.io/v1/ - Insecure registries: - myinsecurehost:5000 - 127.0.0.0/8 - -You can also specify the output format: - - $ docker info --format '{{json .}}' - {"ID":"I54V:OLXT:HVMM:TPKO:JPHQ:CQCD:JNLC:O3BZ:4ZVJ:43XJ:PFHZ:6N2S","Containers":14, ...} - -Here is a sample output for a daemon running on Windows Server 2016: - - E:\docker>docker info - Containers: 1 - Running: 0 - Paused: 0 - Stopped: 1 - Images: 17 - Server Version: 1.13.0 - Storage Driver: windowsfilter - Windows: - Logging Driver: json-file - Plugins: - Volume: local - Network: nat null overlay - Swarm: inactive - Default Isolation: process - Kernel Version: 10.0 14393 (14393.206.amd64fre.rs1_release.160912-1937) - Operating System: Windows Server 2016 Datacenter - OSType: windows - Architecture: x86_64 - CPUs: 8 - Total Memory: 3.999 GiB - Name: WIN-V0V70C0LU5P - ID: NYMS:B5VK:UMSL:FVDZ:EWB5:FKVK:LPFL:FJMQ:H6FT:BZJ6:L2TD:XH62 - Docker Root Dir: C:\control - Debug Mode (client): false - Debug Mode (server): false - Registry: https://index.docker.io/v1/ - Insecure Registries: - 127.0.0.0/8 - Registry Mirrors: - http://192.168.1.2/ - http://registry-mirror.example.com:5000/ - Live Restore Enabled: false diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/inspect.md b/vendor/github.com/docker/docker/docs/reference/commandline/inspect.md deleted file mode 100644 index 7a0c3a0..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/inspect.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: "inspect" -description: "The inspect command description and usage" -keywords: "inspect, container, json" ---- - - - -# inspect - -```markdown -Usage: docker inspect [OPTIONS] NAME|ID [NAME|ID...] - -Return low-level information on Docker object(s) (e.g. container, image, volume, -network, node, service, or task) identified by name or ID - -Options: - -f, --format Format the output using the given Go template - --help Print usage - -s, --size Display total file sizes if the type is container - --type Return JSON for specified type -``` - -By default, this will render all results in a JSON array. If the container and -image have the same name, this will return container JSON for unspecified type. -If a format is specified, the given template will be executed for each result. - -Go's [text/template](http://golang.org/pkg/text/template/) package -describes all the details of the format. - -## Examples - -**Get an instance's IP address:** - -For the most part, you can pick out any field from the JSON in a fairly -straightforward manner. - - {% raw %} - $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID - {% endraw %} - -**Get an instance's MAC address:** - -For the most part, you can pick out any field from the JSON in a fairly -straightforward manner. - - {% raw %} - $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID - {% endraw %} - -**Get an instance's log path:** - - {% raw %} - $ docker inspect --format='{{.LogPath}}' $INSTANCE_ID - {% endraw %} - -**Get a Task's image name:** - - {% raw %} - $ docker inspect --format='{{.Container.Spec.Image}}' $INSTANCE_ID - {% endraw %} - -**List all port bindings:** - -One can loop over arrays and maps in the results to produce simple text -output: - - {% raw %} - $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID - {% endraw %} - -**Find a specific port mapping:** - -The `.Field` syntax doesn't work when the field name begins with a -number, but the template language's `index` function does. The -`.NetworkSettings.Ports` section contains a map of the internal port -mappings to a list of external address/port objects. To grab just the -numeric public port, you use `index` to find the specific port map, and -then `index` 0 contains the first object inside of that. Then we ask for -the `HostPort` field to get the public address. - - {% raw %} - $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID - {% endraw %} - -**Get a subsection in JSON format:** - -If you request a field which is itself a structure containing other -fields, by default you get a Go-style dump of the inner values. -Docker adds a template function, `json`, which can be applied to get -results in JSON format. - - {% raw %} - $ docker inspect --format='{{json .Config}}' $INSTANCE_ID - {% endraw %} diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/kill.md b/vendor/github.com/docker/docker/docs/reference/commandline/kill.md deleted file mode 100644 index 32fde3d..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/kill.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: "kill" -description: "The kill command description and usage" -keywords: "container, kill, signal" ---- - - - -# kill - -```markdown -Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...] - -Kill one or more running containers - -Options: - --help Print usage - -s, --signal string Signal to send to the container (default "KILL") -``` - -The main process inside the container will be sent `SIGKILL`, or any -signal specified with option `--signal`. - -> **Note:** -> `ENTRYPOINT` and `CMD` in the *shell* form run as a subcommand of `/bin/sh -c`, -> which does not pass signals. This means that the executable is not the container’s PID 1 -> and does not receive Unix signals. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/load.md b/vendor/github.com/docker/docker/docs/reference/commandline/load.md deleted file mode 100644 index 04a5bc7..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/load.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: "load" -description: "The load command description and usage" -keywords: "stdin, tarred, repository" ---- - - - -# load - -```markdown -Usage: docker load [OPTIONS] - -Load an image from a tar archive or STDIN - -Options: - --help Print usage - -i, --input string Read from tar archive file, instead of STDIN. - The tarball may be compressed with gzip, bzip, or xz - -q, --quiet Suppress the load output but still outputs the imported images -``` - -Loads a tarred repository from a file or the standard input stream. -Restores both images and tags. - - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - $ docker load < busybox.tar.gz - # […] - Loaded image: busybox:latest - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - busybox latest 769b9341d937 7 weeks ago 2.489 MB - $ docker load --input fedora.tar - # […] - Loaded image: fedora:rawhide - # […] - Loaded image: fedora:20 - # […] - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - busybox latest 769b9341d937 7 weeks ago 2.489 MB - fedora rawhide 0d20aec6529d 7 weeks ago 387 MB - fedora 20 58394af37342 7 weeks ago 385.5 MB - fedora heisenbug 58394af37342 7 weeks ago 385.5 MB - fedora latest 58394af37342 7 weeks ago 385.5 MB diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/login.md b/vendor/github.com/docker/docker/docs/reference/commandline/login.md deleted file mode 100644 index a0f35fd..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/login.md +++ /dev/null @@ -1,122 +0,0 @@ ---- -title: "login" -description: "The login command description and usage" -keywords: "registry, login, image" ---- - - - -# login - -```markdown -Usage: docker login [OPTIONS] [SERVER] - -Log in to a Docker registry. -If no server is specified, the default is defined by the daemon. - -Options: - --help Print usage - -p, --password string Password - -u, --username string Username -``` - -If you want to login to a self-hosted registry you can specify this by -adding the server name. - - example: - $ docker login localhost:8080 - - -`docker login` requires user to use `sudo` or be `root`, except when: - -1. connecting to a remote daemon, such as a `docker-machine` provisioned `docker engine`. -2. user is added to the `docker` group. This will impact the security of your system; the `docker` group is `root` equivalent. See [Docker Daemon Attack Surface](https://docs.docker.com/security/security/#docker-daemon-attack-surface) for details. - -You can log into any public or private repository for which you have -credentials. When you log in, the command stores encoded credentials in -`$HOME/.docker/config.json` on Linux or `%USERPROFILE%/.docker/config.json` on Windows. - -## Credentials store - -The Docker Engine can keep user credentials in an external credentials store, -such as the native keychain of the operating system. Using an external store -is more secure than storing credentials in the Docker configuration file. - -To use a credentials store, you need an external helper program to interact -with a specific keychain or external store. Docker requires the helper -program to be in the client's host `$PATH`. - -This is the list of currently available credentials helpers and where -you can download them from: - -- D-Bus Secret Service: https://github.com/docker/docker-credential-helpers/releases -- Apple macOS keychain: https://github.com/docker/docker-credential-helpers/releases -- Microsoft Windows Credential Manager: https://github.com/docker/docker-credential-helpers/releases - -### Usage - -You need to specify the credentials store in `$HOME/.docker/config.json` -to tell the docker engine to use it: - -```json -{ - "credsStore": "osxkeychain" -} -``` - -If you are currently logged in, run `docker logout` to remove -the credentials from the file and run `docker login` again. - -### Protocol - -Credential helpers can be any program or script that follows a very simple protocol. -This protocol is heavily inspired by Git, but it differs in the information shared. - -The helpers always use the first argument in the command to identify the action. -There are only three possible values for that argument: `store`, `get`, and `erase`. - -The `store` command takes a JSON payload from the standard input. That payload carries -the server address, to identify the credential, the user name, and either a password -or an identity token. - -```json -{ - "ServerURL": "https://index.docker.io/v1", - "Username": "david", - "Secret": "passw0rd1" -} -``` - -If the secret being stored is an identity token, the Username should be set to -``. - -The `store` command can write error messages to `STDOUT` that the docker engine -will show if there was an issue. - -The `get` command takes a string payload from the standard input. That payload carries -the server address that the docker engine needs credentials for. This is -an example of that payload: `https://index.docker.io/v1`. - -The `get` command writes a JSON payload to `STDOUT`. Docker reads the user name -and password from this payload: - -```json -{ - "Username": "david", - "Secret": "passw0rd1" -} -``` - -The `erase` command takes a string payload from `STDIN`. That payload carries -the server address that the docker engine wants to remove credentials for. This is -an example of that payload: `https://index.docker.io/v1`. - -The `erase` command can write error messages to `STDOUT` that the docker engine -will show if there was an issue. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/logout.md b/vendor/github.com/docker/docker/docs/reference/commandline/logout.md deleted file mode 100644 index 1635e22..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/logout.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: "logout" -description: "The logout command description and usage" -keywords: "logout, docker, registry" ---- - - - -# logout - -```markdown -Usage: docker logout [SERVER] - -Log out from a Docker registry. -If no server is specified, the default is defined by the daemon. - -Options: - --help Print usage -``` - -For example: - - $ docker logout localhost:8080 diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/logs.md b/vendor/github.com/docker/docker/docs/reference/commandline/logs.md deleted file mode 100644 index 891e10b..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/logs.md +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: "logs" -description: "The logs command description and usage" -keywords: "logs, retrieve, docker" ---- - - - -# logs - -```markdown -Usage: docker logs [OPTIONS] CONTAINER - -Fetch the logs of a container - -Options: - --details Show extra details provided to logs - -f, --follow Follow log output - --help Print usage - --since string Show logs since timestamp - --tail string Number of lines to show from the end of the logs (default "all") - -t, --timestamps Show timestamps -``` - -The `docker logs` command batch-retrieves logs present at the time of execution. - -> **Note**: this command is only functional for containers that are started with -> the `json-file` or `journald` logging driver. - -For more information about selecting and configuring logging drivers, refer to -[Configure logging drivers](https://docs.docker.com/engine/admin/logging/overview/). - -The `docker logs --follow` command will continue streaming the new output from -the container's `STDOUT` and `STDERR`. - -Passing a negative number or a non-integer to `--tail` is invalid and the -value is set to `all` in that case. - -The `docker logs --timestamps` command will add an [RFC3339Nano timestamp](https://golang.org/pkg/time/#pkg-constants) -, for example `2014-09-16T06:17:46.000000000Z`, to each -log entry. To ensure that the timestamps are aligned the -nano-second part of the timestamp will be padded with zero when necessary. - -The `docker logs --details` command will add on extra attributes, such as -environment variables and labels, provided to `--log-opt` when creating the -container. - -The `--since` option shows only the container logs generated after -a given date. You can specify the date as an RFC 3339 date, a UNIX -timestamp, or a Go duration string (e.g. `1m30s`, `3h`). Besides RFC3339 date -format you may also use RFC3339Nano, `2006-01-02T15:04:05`, -`2006-01-02T15:04:05.999999999`, `2006-01-02Z07:00`, and `2006-01-02`. The local -timezone on the client will be used if you do not provide either a `Z` or a -`+-00:00` timezone offset at the end of the timestamp. When providing Unix -timestamps enter seconds[.nanoseconds], where seconds is the number of seconds -that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap -seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a -fraction of a second no more than nine digits long. You can combine the -`--since` option with either or both of the `--follow` or `--tail` options. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/menu.md b/vendor/github.com/docker/docker/docs/reference/commandline/menu.md deleted file mode 100644 index d58afac..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/menu.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: "Command line reference" -description: "Docker's CLI command description and usage" -keywords: "Docker, Docker documentation, CLI, command line" -identifier: "smn_cli" ---- - - - -# The Docker commands - -This section contains reference information on using Docker's command line -client. Each command has a reference page along with samples. If you are -unfamiliar with the command line, you should start by reading about how to -[Use the Docker command line](cli.md). - -You start the Docker daemon with the command line. How you start the daemon -affects your Docker containers. For that reason you should also make sure to -read the [`dockerd`](dockerd.md) reference page. - -For a list of Docker commands see [Command line reference guide](index.md). diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/network_connect.md b/vendor/github.com/docker/docker/docs/reference/commandline/network_connect.md deleted file mode 100644 index 52459a5..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/network_connect.md +++ /dev/null @@ -1,100 +0,0 @@ ---- -title: "network connect" -description: "The network connect command description and usage" -keywords: "network, connect, user-defined" ---- - - - -# network connect - -```markdown -Usage: docker network connect [OPTIONS] NETWORK CONTAINER - -Connect a container to a network - -Options: - --alias value Add network-scoped alias for the container (default []) - --help Print usage - --ip string IP Address - --ip6 string IPv6 Address - --link value Add link to another container (default []) - --link-local-ip value Add a link-local address for the container (default []) -``` - -Connects a container to a network. You can connect a container by name -or by ID. Once connected, the container can communicate with other containers in -the same network. - -```bash -$ docker network connect multi-host-network container1 -``` - -You can also use the `docker run --network=` option to start a container and immediately connect it to a network. - -```bash -$ docker run -itd --network=multi-host-network busybox -``` - -You can specify the IP address you want to be assigned to the container's interface. - -```bash -$ docker network connect --ip 10.10.36.122 multi-host-network container2 -``` - -You can use `--link` option to link another container with a preferred alias - -```bash -$ docker network connect --link container1:c1 multi-host-network container2 -``` - -`--alias` option can be used to resolve the container by another name in the network -being connected to. - -```bash -$ docker network connect --alias db --alias mysql multi-host-network container2 -``` -You can pause, restart, and stop containers that are connected to a network. -A container connects to its configured networks when it runs. - -If specified, the container's IP address(es) is reapplied when a stopped -container is restarted. If the IP address is no longer available, the container -fails to start. One way to guarantee that the IP address is available is -to specify an `--ip-range` when creating the network, and choose the static IP -address(es) from outside that range. This ensures that the IP address is not -given to another container while this container is not on the network. - -```bash -$ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network -``` - -```bash -$ docker network connect --ip 172.20.128.2 multi-host-network container2 -``` - -To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network. - -Once connected in network, containers can communicate using only another -container's IP address or name. For `overlay` networks or custom plugins that -support multi-host connectivity, containers connected to the same multi-host -network but launched from different Engines can also communicate in this way. - -You can connect a container to one or more networks. The networks need not be the same type. For example, you can connect a single container bridge and overlay networks. - -## Related information - -* [network inspect](network_inspect.md) -* [network create](network_create.md) -* [network disconnect](network_disconnect.md) -* [network ls](network_ls.md) -* [network rm](network_rm.md) -* [network prune](network_prune.md) -* [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/) -* [Work with networks](https://docs.docker.com/engine/userguide/networking/work-with-networks/) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/network_create.md b/vendor/github.com/docker/docker/docs/reference/commandline/network_create.md deleted file mode 100644 index e238217..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/network_create.md +++ /dev/null @@ -1,202 +0,0 @@ ---- -title: "network create" -description: "The network create command description and usage" -keywords: "network, create" ---- - - - -# network create - -```markdown -Usage: docker network create [OPTIONS] NETWORK - -Create a network - -Options: - --attachable Enable manual container attachment - --aux-address value Auxiliary IPv4 or IPv6 addresses used by Network - driver (default map[]) - -d, --driver string Driver to manage the Network (default "bridge") - --gateway value IPv4 or IPv6 Gateway for the master subnet (default []) - --help Print usage - --internal Restrict external access to the network - --ip-range value Allocate container ip from a sub-range (default []) - --ipam-driver string IP Address Management Driver (default "default") - --ipam-opt value Set IPAM driver specific options (default map[]) - --ipv6 Enable IPv6 networking - --label value Set metadata on a network (default []) - -o, --opt value Set driver specific options (default map[]) - --subnet value Subnet in CIDR format that represents a - network segment (default []) -``` - -Creates a new network. The `DRIVER` accepts `bridge` or `overlay` which are the -built-in network drivers. If you have installed a third party or your own custom -network driver you can specify that `DRIVER` here also. If you don't specify the -`--driver` option, the command automatically creates a `bridge` network for you. -When you install Docker Engine it creates a `bridge` network automatically. This -network corresponds to the `docker0` bridge that Engine has traditionally relied -on. When you launch a new container with `docker run` it automatically connects to -this bridge network. You cannot remove this default bridge network, but you can -create new ones using the `network create` command. - -```bash -$ docker network create -d bridge my-bridge-network -``` - -Bridge networks are isolated networks on a single Engine installation. If you -want to create a network that spans multiple Docker hosts each running an -Engine, you must create an `overlay` network. Unlike `bridge` networks, overlay -networks require some pre-existing conditions before you can create one. These -conditions are: - -* Access to a key-value store. Engine supports Consul, Etcd, and ZooKeeper (Distributed store) key-value stores. -* A cluster of hosts with connectivity to the key-value store. -* A properly configured Engine `daemon` on each host in the cluster. - -The `dockerd` options that support the `overlay` network are: - -* `--cluster-store` -* `--cluster-store-opt` -* `--cluster-advertise` - -To read more about these options and how to configure them, see ["*Get started -with multi-host network*"](https://docs.docker.com/engine/userguide/networking/get-started-overlay). - -While not required, it is a good idea to install Docker Swarm to -manage the cluster that makes up your network. Swarm provides sophisticated -discovery and server management tools that can assist your implementation. - -Once you have prepared the `overlay` network prerequisites you simply choose a -Docker host in the cluster and issue the following to create the network: - -```bash -$ docker network create -d overlay my-multihost-network -``` - -Network names must be unique. The Docker daemon attempts to identify naming -conflicts but this is not guaranteed. It is the user's responsibility to avoid -name conflicts. - -## Connect containers - -When you start a container, use the `--network` flag to connect it to a network. -This example adds the `busybox` container to the `mynet` network: - -```bash -$ docker run -itd --network=mynet busybox -``` - -If you want to add a container to a network after the container is already -running, use the `docker network connect` subcommand. - -You can connect multiple containers to the same network. Once connected, the -containers can communicate using only another container's IP address or name. -For `overlay` networks or custom plugins that support multi-host connectivity, -containers connected to the same multi-host network but launched from different -Engines can also communicate in this way. - -You can disconnect a container from a network using the `docker network -disconnect` command. - -## Specifying advanced options - -When you create a network, Engine creates a non-overlapping subnetwork for the -network by default. This subnetwork is not a subdivision of an existing -network. It is purely for ip-addressing purposes. You can override this default -and specify subnetwork values directly using the `--subnet` option. On a -`bridge` network you can only create a single subnet: - -```bash -$ docker network create --driver=bridge --subnet=192.168.0.0/16 br0 -``` - -Additionally, you also specify the `--gateway` `--ip-range` and `--aux-address` -options. - -```bash -$ docker network create \ - --driver=bridge \ - --subnet=172.28.0.0/16 \ - --ip-range=172.28.5.0/24 \ - --gateway=172.28.5.254 \ - br0 -``` - -If you omit the `--gateway` flag the Engine selects one for you from inside a -preferred pool. For `overlay` networks and for network driver plugins that -support it you can create multiple subnetworks. - -```bash -$ docker network create -d overlay \ - --subnet=192.168.0.0/16 \ - --subnet=192.170.0.0/16 \ - --gateway=192.168.0.100 \ - --gateway=192.170.0.100 \ - --ip-range=192.168.1.0/24 \ - --aux-address="my-router=192.168.1.5" --aux-address="my-switch=192.168.1.6" \ - --aux-address="my-printer=192.170.1.5" --aux-address="my-nas=192.170.1.6" \ - my-multihost-network -``` - -Be sure that your subnetworks do not overlap. If they do, the network create -fails and Engine returns an error. - -# Bridge driver options - -When creating a custom network, the default network driver (i.e. `bridge`) has -additional options that can be passed. The following are those options and the -equivalent docker daemon flags used for docker0 bridge: - -| Option | Equivalent | Description | -|--------------------------------------------------|-------------|-------------------------------------------------------| -| `com.docker.network.bridge.name` | - | bridge name to be used when creating the Linux bridge | -| `com.docker.network.bridge.enable_ip_masquerade` | `--ip-masq` | Enable IP masquerading | -| `com.docker.network.bridge.enable_icc` | `--icc` | Enable or Disable Inter Container Connectivity | -| `com.docker.network.bridge.host_binding_ipv4` | `--ip` | Default IP when binding container ports | -| `com.docker.network.driver.mtu` | `--mtu` | Set the containers network MTU | - -The following arguments can be passed to `docker network create` for any -network driver, again with their approximate equivalents to `docker daemon`. - -| Argument | Equivalent | Description | -|--------------|----------------|--------------------------------------------| -| `--gateway` | - | IPv4 or IPv6 Gateway for the master subnet | -| `--ip-range` | `--fixed-cidr` | Allocate IPs from a range | -| `--internal` | - | Restrict external access to the network | -| `--ipv6` | `--ipv6` | Enable IPv6 networking | -| `--subnet` | `--bip` | Subnet for network | - -For example, let's use `-o` or `--opt` options to specify an IP address binding -when publishing ports: - -```bash -$ docker network create \ - -o "com.docker.network.bridge.host_binding_ipv4"="172.19.0.1" \ - simple-network -``` - -### Network internal mode - -By default, when you connect a container to an `overlay` network, Docker also -connects a bridge network to it to provide external connectivity. If you want -to create an externally isolated `overlay` network, you can specify the -`--internal` option. - -## Related information - -* [network inspect](network_inspect.md) -* [network connect](network_connect.md) -* [network disconnect](network_disconnect.md) -* [network ls](network_ls.md) -* [network rm](network_rm.md) -* [network prune](network_prune.md) -* [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/network_disconnect.md b/vendor/github.com/docker/docker/docs/reference/commandline/network_disconnect.md deleted file mode 100644 index 42e976a..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/network_disconnect.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: "network disconnect" -description: "The network disconnect command description and usage" -keywords: "network, disconnect, user-defined" ---- - - - -# network disconnect - -```markdown -Usage: docker network disconnect [OPTIONS] NETWORK CONTAINER - -Disconnect a container from a network - -Options: - -f, --force Force the container to disconnect from a network - --help Print usage -``` - -Disconnects a container from a network. The container must be running to disconnect it from the network. - -```bash - $ docker network disconnect multi-host-network container1 -``` - - -## Related information - -* [network inspect](network_inspect.md) -* [network connect](network_connect.md) -* [network create](network_create.md) -* [network ls](network_ls.md) -* [network rm](network_rm.md) -* [network prune](network_prune.md) -* [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/network_inspect.md b/vendor/github.com/docker/docker/docs/reference/commandline/network_inspect.md deleted file mode 100644 index bc0005e..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/network_inspect.md +++ /dev/null @@ -1,192 +0,0 @@ ---- -title: "network inspect" -description: "The network inspect command description and usage" -keywords: "network, inspect, user-defined" ---- - - - -# network inspect - -```markdown -Usage: docker network inspect [OPTIONS] NETWORK [NETWORK...] - -Display detailed information on one or more networks - -Options: - -f, --format string Format the output using the given Go template - --help Print usage -``` - -Returns information about one or more networks. By default, this command renders all results in a JSON object. For example, if you connect two containers to the default `bridge` network: - -```bash -$ sudo docker run -itd --name=container1 busybox -f2870c98fd504370fb86e59f32cd0753b1ac9b69b7d80566ffc7192a82b3ed27 - -$ sudo docker run -itd --name=container2 busybox -bda12f8922785d1f160be70736f26c1e331ab8aaf8ed8d56728508f2e2fd4727 -``` - -The `network inspect` command shows the containers, by id, in its -results. For networks backed by multi-host network driver, such as Overlay, -this command also shows the container endpoints in other hosts in the -cluster. These endpoints are represented as "ep-{endpoint-id}" in the output. -However, for swarm-scoped networks, only the endpoints that are local to the -node are shown. - -You can specify an alternate format to execute a given -template for each result. Go's -[text/template](http://golang.org/pkg/text/template/) package describes all the -details of the format. - -```bash -$ sudo docker network inspect bridge -[ - { - "Name": "bridge", - "Id": "b2b1a2cba717161d984383fd68218cf70bbbd17d328496885f7c921333228b0f", - "Created": "2016-10-19T04:33:30.360899459Z", - "Scope": "local", - "Driver": "bridge", - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.17.42.1/16", - "Gateway": "172.17.42.1" - } - ] - }, - "Internal": false, - "Containers": { - "bda12f8922785d1f160be70736f26c1e331ab8aaf8ed8d56728508f2e2fd4727": { - "Name": "container2", - "EndpointID": "0aebb8fcd2b282abe1365979536f21ee4ceaf3ed56177c628eae9f706e00e019", - "MacAddress": "02:42:ac:11:00:02", - "IPv4Address": "172.17.0.2/16", - "IPv6Address": "" - }, - "f2870c98fd504370fb86e59f32cd0753b1ac9b69b7d80566ffc7192a82b3ed27": { - "Name": "container1", - "EndpointID": "a00676d9c91a96bbe5bcfb34f705387a33d7cc365bac1a29e4e9728df92d10ad", - "MacAddress": "02:42:ac:11:00:01", - "IPv4Address": "172.17.0.1/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - }, - "Labels": {} - } -] -``` - -Returns the information about the user-defined network: - -```bash -$ docker network create simple-network -69568e6336d8c96bbf57869030919f7c69524f71183b44d80948bd3927c87f6a -$ docker network inspect simple-network -[ - { - "Name": "simple-network", - "Id": "69568e6336d8c96bbf57869030919f7c69524f71183b44d80948bd3927c87f6a", - "Created": "2016-10-19T04:33:30.360899459Z", - "Scope": "local", - "Driver": "bridge", - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.22.0.0/16", - "Gateway": "172.22.0.1" - } - ] - }, - "Containers": {}, - "Options": {}, - "Labels": {} - } -] -``` - -For swarm mode overlay networks `network inspect` also shows the IP address and node name -of the peers. Peers are the nodes in the swarm cluster which have at least one task attached -to the network. Node name is of the format `-`. - -```bash -$ docker network inspect ingress -[ - { - "Name": "ingress", - "Id": "j0izitrut30h975vk4m1u5kk3", - "Created": "2016-11-08T06:49:59.803387552Z", - "Scope": "swarm", - "Driver": "overlay", - "EnableIPv6": false, - "IPAM": { - "Driver": "default", - "Options": null, - "Config": [ - { - "Subnet": "10.255.0.0/16", - "Gateway": "10.255.0.1" - } - ] - }, - "Internal": false, - "Attachable": false, - "Containers": { - "ingress-sbox": { - "Name": "ingress-endpoint", - "EndpointID": "40e002d27b7e5d75f60bc72199d8cae3344e1896abec5eddae9743755fe09115", - "MacAddress": "02:42:0a:ff:00:03", - "IPv4Address": "10.255.0.3/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.driver.overlay.vxlanid_list": "256" - }, - "Labels": {}, - "Peers": [ - { - "Name": "net-1-1d22adfe4d5c", - "IP": "192.168.33.11" - }, - { - "Name": "net-2-d55d838b34af", - "IP": "192.168.33.12" - }, - { - "Name": "net-3-8473f8140bd9", - "IP": "192.168.33.13" - } - ] - } -] -``` - -## Related information - -* [network disconnect ](network_disconnect.md) -* [network connect](network_connect.md) -* [network create](network_create.md) -* [network ls](network_ls.md) -* [network rm](network_rm.md) -* [network prune](network_prune.md) -* [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/network_ls.md b/vendor/github.com/docker/docker/docs/reference/commandline/network_ls.md deleted file mode 100644 index a4f671d..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/network_ls.md +++ /dev/null @@ -1,218 +0,0 @@ ---- -title: "network ls" -description: "The network ls command description and usage" -keywords: "network, list, user-defined" ---- - - - -# docker network ls - -```markdown -Usage: docker network ls [OPTIONS] - -List networks - -Aliases: - ls, list - -Options: - -f, --filter filter Provide filter values (e.g. 'driver=bridge') - --format string Pretty-print networks using a Go template - --help Print usage - --no-trunc Do not truncate the output - -q, --quiet Only display network IDs -``` - -Lists all the networks the Engine `daemon` knows about. This includes the -networks that span across multiple hosts in a cluster, for example: - -```bash -$ sudo docker network ls -NETWORK ID NAME DRIVER SCOPE -7fca4eb8c647 bridge bridge local -9f904ee27bf5 none null local -cf03ee007fb4 host host local -78b03ee04fc4 multi-host overlay swarm -``` - -Use the `--no-trunc` option to display the full network id: - -```bash -$ docker network ls --no-trunc -NETWORK ID NAME DRIVER SCOPE -18a2866682b85619a026c81b98a5e375bd33e1b0936a26cc497c283d27bae9b3 none null local -c288470c46f6c8949c5f7e5099b5b7947b07eabe8d9a27d79a9cbf111adcbf47 host host local -7b369448dccbf865d397c8d2be0cda7cf7edc6b0945f77d2529912ae917a0185 bridge bridge local -95e74588f40db048e86320c6526440c504650a1ff3e9f7d60a497c4d2163e5bd foo bridge local -63d1ff1f77b07ca51070a8c227e962238358bd310bde1529cf62e6c307ade161 dev bridge local -``` - -## Filtering - -The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there -is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`). -Multiple filter flags are combined as an `OR` filter. For example, -`-f type=custom -f type=builtin` returns both `custom` and `builtin` networks. - -The currently supported filters are: - -* driver -* id (network's id) -* label (`label=` or `label==`) -* name (network's name) -* type (custom|builtin) - -#### Driver - -The `driver` filter matches networks based on their driver. - -The following example matches networks with the `bridge` driver: - -```bash -$ docker network ls --filter driver=bridge -NETWORK ID NAME DRIVER SCOPE -db9db329f835 test1 bridge local -f6e212da9dfd test2 bridge local -``` - -#### ID - -The `id` filter matches on all or part of a network's ID. - -The following filter matches all networks with an ID containing the -`63d1ff1f77b0...` string. - -```bash -$ docker network ls --filter id=63d1ff1f77b07ca51070a8c227e962238358bd310bde1529cf62e6c307ade161 -NETWORK ID NAME DRIVER SCOPE -63d1ff1f77b0 dev bridge local -``` - -You can also filter for a substring in an ID as this shows: - -```bash -$ docker network ls --filter id=95e74588f40d -NETWORK ID NAME DRIVER SCOPE -95e74588f40d foo bridge local - -$ docker network ls --filter id=95e -NETWORK ID NAME DRIVER SCOPE -95e74588f40d foo bridge local -``` - -#### Label - -The `label` filter matches networks based on the presence of a `label` alone or a `label` and a -value. - -The following filter matches networks with the `usage` label regardless of its value. - -```bash -$ docker network ls -f "label=usage" -NETWORK ID NAME DRIVER SCOPE -db9db329f835 test1 bridge local -f6e212da9dfd test2 bridge local -``` - -The following filter matches networks with the `usage` label with the `prod` value. - -```bash -$ docker network ls -f "label=usage=prod" -NETWORK ID NAME DRIVER SCOPE -f6e212da9dfd test2 bridge local -``` - -#### Name - -The `name` filter matches on all or part of a network's name. - -The following filter matches all networks with a name containing the `foobar` string. - -```bash -$ docker network ls --filter name=foobar -NETWORK ID NAME DRIVER SCOPE -06e7eef0a170 foobar bridge local -``` - -You can also filter for a substring in a name as this shows: - -```bash -$ docker network ls --filter name=foo -NETWORK ID NAME DRIVER SCOPE -95e74588f40d foo bridge local -06e7eef0a170 foobar bridge local -``` - -#### Type - -The `type` filter supports two values; `builtin` displays predefined networks -(`bridge`, `none`, `host`), whereas `custom` displays user defined networks. - -The following filter matches all user defined networks: - -```bash -$ docker network ls --filter type=custom -NETWORK ID NAME DRIVER SCOPE -95e74588f40d foo bridge local -63d1ff1f77b0 dev bridge local -``` - -By having this flag it allows for batch cleanup. For example, use this filter -to delete all user defined networks: - -```bash -$ docker network rm `docker network ls --filter type=custom -q` -``` - -A warning will be issued when trying to remove a network that has containers -attached. - -## Formatting - -The formatting options (`--format`) pretty-prints networks output -using a Go template. - -Valid placeholders for the Go template are listed below: - -Placeholder | Description -------------|------------------------------------------------------------------------------------------ -`.ID` | Network ID -`.Name` | Network name -`.Driver` | Network driver -`.Scope` | Network scope (local, global) -`.IPv6` | Whether IPv6 is enabled on the network or not. -`.Internal` | Whether the network is internal or not. -`.Labels` | All labels assigned to the network. -`.Label` | Value of a specific label for this network. For example `{{.Label "project.version"}}` - -When using the `--format` option, the `network ls` command will either -output the data exactly as the template declares or, when using the -`table` directive, includes column headers as well. - -The following example uses a template without headers and outputs the -`ID` and `Driver` entries separated by a colon for all networks: - -```bash -$ docker network ls --format "{{.ID}}: {{.Driver}}" -afaaab448eb2: bridge -d1584f8dc718: host -391df270dc66: null -``` - -## Related information - -* [network disconnect ](network_disconnect.md) -* [network connect](network_connect.md) -* [network create](network_create.md) -* [network inspect](network_inspect.md) -* [network rm](network_rm.md) -* [network prune](network_prune.md) -* [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/network_prune.md b/vendor/github.com/docker/docker/docs/reference/commandline/network_prune.md deleted file mode 100644 index 5b65465..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/network_prune.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: "network prune" -description: "Remove unused networks" -keywords: "network, prune, delete" ---- - -# network prune - -```markdown -Usage: docker network prune [OPTIONS] - -Remove all unused networks - -Options: - -f, --force Do not prompt for confirmation - --help Print usage -``` - -Remove all unused networks. Unused networks are those which are not referenced by any containers. - -Example output: - -```bash -$ docker network prune -WARNING! This will remove all networks not used by at least one container. -Are you sure you want to continue? [y/N] y -Deleted Networks: -n1 -n2 -``` - -## Related information - -* [network disconnect ](network_disconnect.md) -* [network connect](network_connect.md) -* [network create](network_create.md) -* [network ls](network_ls.md) -* [network inspect](network_inspect.md) -* [network rm](network_rm.md) -* [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/) -* [system df](system_df.md) -* [container prune](container_prune.md) -* [image prune](image_prune.md) -* [volume prune](volume_prune.md) -* [system prune](system_prune.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/network_rm.md b/vendor/github.com/docker/docker/docs/reference/commandline/network_rm.md deleted file mode 100644 index f06b4c0..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/network_rm.md +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: "network rm" -description: "the network rm command description and usage" -keywords: "network, rm, user-defined" ---- - - - -# network rm - -```markdown -Usage: docker network rm NETWORK [NETWORK...] - -Remove one or more networks - -Aliases: - rm, remove - -Options: - --help Print usage -``` - -Removes one or more networks by name or identifier. To remove a network, -you must first disconnect any containers connected to it. -To remove the network named 'my-network': - -```bash - $ docker network rm my-network -``` - -To delete multiple networks in a single `docker network rm` command, provide -multiple network names or ids. The following example deletes a network with id -`3695c422697f` and a network named `my-network`: - -```bash - $ docker network rm 3695c422697f my-network -``` - -When you specify multiple networks, the command attempts to delete each in turn. -If the deletion of one network fails, the command continues to the next on the -list and tries to delete that. The command reports success or failure for each -deletion. - -## Related information - -* [network disconnect ](network_disconnect.md) -* [network connect](network_connect.md) -* [network create](network_create.md) -* [network ls](network_ls.md) -* [network inspect](network_inspect.md) -* [network prune](network_prune.md) -* [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/node_demote.md b/vendor/github.com/docker/docker/docs/reference/commandline/node_demote.md deleted file mode 100644 index 9a81bb9..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/node_demote.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: "node demote" -description: "The node demote command description and usage" -keywords: "node, demote" ---- - - - -# node demote - -```markdown -Usage: docker node demote NODE [NODE...] - -Demote one or more nodes from manager in the swarm - -Options: - --help Print usage - -``` - -Demotes an existing manager so that it is no longer a manager. This command targets a docker engine that is a manager in the swarm. - - -```bash -$ docker node demote -``` - -## Related information - -* [node inspect](node_inspect.md) -* [node ls](node_ls.md) -* [node promote](node_promote.md) -* [node ps](node_ps.md) -* [node rm](node_rm.md) -* [node update](node_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/node_inspect.md b/vendor/github.com/docker/docker/docs/reference/commandline/node_inspect.md deleted file mode 100644 index fac688f..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/node_inspect.md +++ /dev/null @@ -1,137 +0,0 @@ ---- -title: "node inspect" -description: "The node inspect command description and usage" -keywords: "node, inspect" ---- - - - -# node inspect - -```markdown -Usage: docker node inspect [OPTIONS] self|NODE [NODE...] - -Display detailed information on one or more nodes - -Options: - -f, --format string Format the output using the given Go template - --help Print usage - --pretty Print the information in a human friendly format. -``` - -Returns information about a node. By default, this command renders all results -in a JSON array. You can specify an alternate format to execute a -given template for each result. Go's -[text/template](http://golang.org/pkg/text/template/) package describes all the -details of the format. - -Example output: - - $ docker node inspect swarm-manager - [ - { - "ID": "e216jshn25ckzbvmwlnh5jr3g", - "Version": { - "Index": 10 - }, - "CreatedAt": "2016-06-16T22:52:44.9910662Z", - "UpdatedAt": "2016-06-16T22:52:45.230878043Z", - "Spec": { - "Role": "manager", - "Availability": "active" - }, - "Description": { - "Hostname": "swarm-manager", - "Platform": { - "Architecture": "x86_64", - "OS": "linux" - }, - "Resources": { - "NanoCPUs": 1000000000, - "MemoryBytes": 1039843328 - }, - "Engine": { - "EngineVersion": "1.12.0", - "Plugins": [ - { - "Type": "Volume", - "Name": "local" - }, - { - "Type": "Network", - "Name": "overlay" - }, - { - "Type": "Network", - "Name": "null" - }, - { - "Type": "Network", - "Name": "host" - }, - { - "Type": "Network", - "Name": "bridge" - }, - { - "Type": "Network", - "Name": "overlay" - } - ] - } - }, - "Status": { - "State": "ready", - "Addr": "168.0.32.137" - }, - "ManagerStatus": { - "Leader": true, - "Reachability": "reachable", - "Addr": "168.0.32.137:2377" - } - } - ] - - {% raw %} - $ docker node inspect --format '{{ .ManagerStatus.Leader }}' self - false - {% endraw %} - - $ docker node inspect --pretty self - ID: e216jshn25ckzbvmwlnh5jr3g - Hostname: swarm-manager - Joined at: 2016-06-16 22:52:44.9910662 +0000 utc - Status: - State: Ready - Availability: Active - Address: 172.17.0.2 - Manager Status: - Address: 172.17.0.2:2377 - Raft Status: Reachable - Leader: Yes - Platform: - Operating System: linux - Architecture: x86_64 - Resources: - CPUs: 4 - Memory: 7.704 GiB - Plugins: - Network: overlay, bridge, null, host, overlay - Volume: local - Engine Version: 1.12.0 - -## Related information - -* [node demote](node_demote.md) -* [node ls](node_ls.md) -* [node promote](node_promote.md) -* [node ps](node_ps.md) -* [node rm](node_rm.md) -* [node update](node_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/node_ls.md b/vendor/github.com/docker/docker/docs/reference/commandline/node_ls.md deleted file mode 100644 index 5f61713..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/node_ls.md +++ /dev/null @@ -1,130 +0,0 @@ ---- -title: "node ls" -description: "The node ls command description and usage" -keywords: "node, list" ---- - - - -# node ls - -```markdown -Usage: docker node ls [OPTIONS] - -List nodes in the swarm - -Aliases: - ls, list - -Options: - -f, --filter value Filter output based on conditions provided - --help Print usage - -q, --quiet Only display IDs -``` - -Lists all the nodes that the Docker Swarm manager knows about. You can filter using the `-f` or `--filter` flag. Refer to the [filtering](#filtering) section for more information about available filter options. - -Example output: - -```bash -$ docker node ls - -ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS -1bcef6utixb0l0ca7gxuivsj0 swarm-worker2 Ready Active -38ciaotwjuritcdtn9npbnkuz swarm-worker1 Ready Active -e216jshn25ckzbvmwlnh5jr3g * swarm-manager1 Ready Active Leader -``` - -## Filtering - -The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more -than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`) - -The currently supported filters are: - -* [id](node_ls.md#id) -* [label](node_ls.md#label) -* [membership](node_ls.md#membership) -* [name](node_ls.md#name) -* [role](node_ls.md#role) - -#### ID - -The `id` filter matches all or part of a node's id. - -```bash -$ docker node ls -f id=1 - -ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS -1bcef6utixb0l0ca7gxuivsj0 swarm-worker2 Ready Active -``` - -#### Label - -The `label` filter matches nodes based on engine labels and on the presence of a `label` alone or a `label` and a value. Node labels are currently not used for filtering. - -The following filter matches nodes with the `foo` label regardless of its value. - -```bash -$ docker node ls -f "label=foo" - -ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS -1bcef6utixb0l0ca7gxuivsj0 swarm-worker2 Ready Active -``` - -#### Membership - -The `membership` filter matches nodes based on the presence of a `membership` and a value -`accepted` or `pending`. - -The following filter matches nodes with the `membership` of `accepted`. - -```bash -$ docker node ls -f "membership=accepted" - -ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS -1bcef6utixb0l0ca7gxuivsj0 swarm-worker2 Ready Active -38ciaotwjuritcdtn9npbnkuz swarm-worker1 Ready Active -``` - -#### Name - -The `name` filter matches on all or part of a node hostname. - -The following filter matches the nodes with a name equal to `swarm-master` string. - -```bash -$ docker node ls -f name=swarm-manager1 - -ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS -e216jshn25ckzbvmwlnh5jr3g * swarm-manager1 Ready Active Leader -``` - -#### Role - -The `role` filter matches nodes based on the presence of a `role` and a value `worker` or `manager`. - -The following filter matches nodes with the `manager` role. - -```bash -$ docker node ls -f "role=manager" - -ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS -e216jshn25ckzbvmwlnh5jr3g * swarm-manager1 Ready Active Leader -``` - -## Related information - -* [node demote](node_demote.md) -* [node inspect](node_inspect.md) -* [node promote](node_promote.md) -* [node ps](node_ps.md) -* [node rm](node_rm.md) -* [node update](node_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/node_promote.md b/vendor/github.com/docker/docker/docs/reference/commandline/node_promote.md deleted file mode 100644 index 92092a8..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/node_promote.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: "node promote" -description: "The node promote command description and usage" -keywords: "node, promote" ---- - - - -# node promote - -```markdown -Usage: docker node promote NODE [NODE...] - -Promote one or more nodes to manager in the swarm - -Options: - --help Print usage -``` - -Promotes a node to manager. This command targets a docker engine that is a manager in the swarm. - - -```bash -$ docker node promote -``` - -## Related information - -* [node demote](node_demote.md) -* [node inspect](node_inspect.md) -* [node ls](node_ls.md) -* [node ps](node_ps.md) -* [node rm](node_rm.md) -* [node update](node_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/node_ps.md b/vendor/github.com/docker/docker/docs/reference/commandline/node_ps.md deleted file mode 100644 index 7f07c5e..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/node_ps.md +++ /dev/null @@ -1,107 +0,0 @@ ---- -title: "node ps" -description: "The node ps command description and usage" -keywords: node, tasks, ps -aliases: ["/engine/reference/commandline/node_tasks/"] ---- - - - -# node ps - -```markdown -Usage: docker node ps [OPTIONS] [NODE...] - -List tasks running on one or more nodes, defaults to current node. - -Options: - -f, --filter value Filter output based on conditions provided - --help Print usage - --no-resolve Do not map IDs to Names - --no-trunc Do not truncate output -``` - -Lists all the tasks on a Node that Docker knows about. You can filter using the `-f` or `--filter` flag. Refer to the [filtering](#filtering) section for more information about available filter options. - -Example output: - - $ docker node ps swarm-manager1 - NAME IMAGE NODE DESIRED STATE CURRENT STATE - redis.1.7q92v0nr1hcgts2amcjyqg3pq redis:3.0.6 swarm-manager1 Running Running 5 hours - redis.6.b465edgho06e318egmgjbqo4o redis:3.0.6 swarm-manager1 Running Running 29 seconds - redis.7.bg8c07zzg87di2mufeq51a2qp redis:3.0.6 swarm-manager1 Running Running 5 seconds - redis.9.dkkual96p4bb3s6b10r7coxxt redis:3.0.6 swarm-manager1 Running Running 5 seconds - redis.10.0tgctg8h8cech4w0k0gwrmr23 redis:3.0.6 swarm-manager1 Running Running 5 seconds - - -## Filtering - -The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more -than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`) - -The currently supported filters are: - -* [name](#name) -* [id](#id) -* [label](#label) -* [desired-state](#desired-state) - -#### name - -The `name` filter matches on all or part of a task's name. - -The following filter matches all tasks with a name containing the `redis` string. - - $ docker node ps -f name=redis swarm-manager1 - NAME IMAGE NODE DESIRED STATE CURRENT STATE - redis.1.7q92v0nr1hcgts2amcjyqg3pq redis:3.0.6 swarm-manager1 Running Running 5 hours - redis.6.b465edgho06e318egmgjbqo4o redis:3.0.6 swarm-manager1 Running Running 29 seconds - redis.7.bg8c07zzg87di2mufeq51a2qp redis:3.0.6 swarm-manager1 Running Running 5 seconds - redis.9.dkkual96p4bb3s6b10r7coxxt redis:3.0.6 swarm-manager1 Running Running 5 seconds - redis.10.0tgctg8h8cech4w0k0gwrmr23 redis:3.0.6 swarm-manager1 Running Running 5 seconds - - -#### id - -The `id` filter matches a task's id. - - $ docker node ps -f id=bg8c07zzg87di2mufeq51a2qp swarm-manager1 - NAME IMAGE NODE DESIRED STATE CURRENT STATE - redis.7.bg8c07zzg87di2mufeq51a2qp redis:3.0.6 swarm-manager1 Running Running 5 seconds - - -#### label - -The `label` filter matches tasks based on the presence of a `label` alone or a `label` and a -value. - -The following filter matches tasks with the `usage` label regardless of its value. - -```bash -$ docker node ps -f "label=usage" -NAME IMAGE NODE DESIRED STATE CURRENT STATE -redis.6.b465edgho06e318egmgjbqo4o redis:3.0.6 swarm-manager1 Running Running 10 minutes -redis.7.bg8c07zzg87di2mufeq51a2qp redis:3.0.6 swarm-manager1 Running Running 9 minutes -``` - - -#### desired-state - -The `desired-state` filter can take the values `running`, `shutdown`, and `accepted`. - - -## Related information - -* [node demote](node_demote.md) -* [node inspect](node_inspect.md) -* [node ls](node_ls.md) -* [node promote](node_promote.md) -* [node rm](node_rm.md) -* [node update](node_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/node_rm.md b/vendor/github.com/docker/docker/docs/reference/commandline/node_rm.md deleted file mode 100644 index b245d63..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/node_rm.md +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: "node rm" -description: "The node rm command description and usage" -keywords: "node, remove" ---- - - - -# node rm - -```markdown -Usage: docker node rm [OPTIONS] NODE [NODE...] - -Remove one or more nodes from the swarm - -Aliases: - rm, remove - -Options: - -f, --force Force remove a node from the swarm - --help Print usage -``` - -When run from a manager node, removes the specified nodes from a swarm. - - -Example output: - -```nohighlight -$ docker node rm swarm-node-02 - -Node swarm-node-02 removed from swarm -``` - -Removes the specified nodes from the swarm, but only if the nodes are in the -down state. If you attempt to remove an active node you will receive an error: - -```nohighlight -$ docker node rm swarm-node-03 - -Error response from daemon: rpc error: code = 9 desc = node swarm-node-03 is not -down and can't be removed -``` - -If you lose access to a worker node or need to shut it down because it has been -compromised or is not behaving as expected, you can use the `--force` option. -This may cause transient errors or interruptions, depending on the type of task -being run on the node. - -```nohighlight -$ docker node rm --force swarm-node-03 - -Node swarm-node-03 removed from swarm -``` - -A manager node must be demoted to a worker node (using `docker node demote`) -before you can remove it from the swarm. - -## Related information - -* [node demote](node_demote.md) -* [node inspect](node_inspect.md) -* [node ls](node_ls.md) -* [node promote](node_promote.md) -* [node ps](node_ps.md) -* [node update](node_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/node_update.md b/vendor/github.com/docker/docker/docs/reference/commandline/node_update.md deleted file mode 100644 index aa65d03..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/node_update.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: "node update" -description: "The node update command description and usage" -keywords: "resources, update, dynamically" ---- - - - -## update - -```markdown -Usage: docker node update [OPTIONS] NODE - -Update a node - -Options: - --availability string Availability of the node (active/pause/drain) - --help Print usage - --label-add value Add or update a node label (key=value) (default []) - --label-rm value Remove a node label if exists (default []) - --role string Role of the node (worker/manager) -``` - -### Add label metadata to a node - -Add metadata to a swarm node using node labels. You can specify a node label as -a key with an empty value: - -``` bash -$ docker node update --label-add foo worker1 -``` - -To add multiple labels to a node, pass the `--label-add` flag for each label: - -``` bash -$ docker node update --label-add foo --label-add bar worker1 -``` - -When you [create a service](service_create.md), -you can use node labels as a constraint. A constraint limits the nodes where the -scheduler deploys tasks for a service. - -For example, to add a `type` label to identify nodes where the scheduler should -deploy message queue service tasks: - -``` bash -$ docker node update --label-add type=queue worker1 -``` - -The labels you set for nodes using `docker node update` apply only to the node -entity within the swarm. Do not confuse them with the docker daemon labels for -[dockerd](https://docs.docker.com/engine/userguide/labels-custom-metadata/#daemon-labels). - -For more information about labels, refer to [apply custom -metadata](https://docs.docker.com/engine/userguide/labels-custom-metadata/). - -## Related information - -* [node demote](node_demote.md) -* [node inspect](node_inspect.md) -* [node ls](node_ls.md) -* [node promote](node_promote.md) -* [node ps](node_ps.md) -* [node rm](node_rm.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/pause.md b/vendor/github.com/docker/docker/docs/reference/commandline/pause.md deleted file mode 100644 index e2dd800..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/pause.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: "pause" -description: "The pause command description and usage" -keywords: "cgroups, container, suspend, SIGSTOP" ---- - - - -# pause - -```markdown -Usage: docker pause CONTAINER [CONTAINER...] - -Pause all processes within one or more containers - -Options: - --help Print usage -``` - -The `docker pause` command suspends all processes in the specified containers. -On Linux, this uses the cgroups freezer. Traditionally, when suspending a process -the `SIGSTOP` signal is used, which is observable by the process being suspended. -With the cgroups freezer the process is unaware, and unable to capture, -that it is being suspended, and subsequently resumed. On Windows, only Hyper-V -containers can be paused. - -See the -[cgroups freezer documentation](https://www.kernel.org/doc/Documentation/cgroup-v1/freezer-subsystem.txt) -for further details. - -## Related information - -* [unpause](unpause.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_create.md b/vendor/github.com/docker/docker/docs/reference/commandline/plugin_create.md deleted file mode 100644 index 9d4e99e..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_create.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: "plugin create" -description: "the plugin create command description and usage" -keywords: "plugin, create" ---- - - - -# plugin create - -```markdown -Usage: docker plugin create [OPTIONS] PLUGIN PLUGIN-DATA-DIR - -Create a plugin from a rootfs and configuration. Plugin data directory must contain config.json and rootfs directory. - -Options: - --compress Compress the context using gzip - --help Print usage -``` - -Creates a plugin. Before creating the plugin, prepare the plugin's root filesystem as well as -[the config.json](../../extend/config.md) - - -The following example shows how to create a sample `plugin`. - -```bash - -$ ls -ls /home/pluginDir - -4 -rw-r--r-- 1 root root 431 Nov 7 01:40 config.json -0 drwxr-xr-x 19 root root 420 Nov 7 01:40 rootfs - -$ docker plugin create plugin /home/pluginDir -plugin - -NAME TAG DESCRIPTION ENABLED -plugin latest A sample plugin for Docker true -``` - -The plugin can subsequently be enabled for local use or pushed to the public registry. - -## Related information - -* [plugin disable](plugin_disable.md) -* [plugin enable](plugin_enable.md) -* [plugin inspect](plugin_inspect.md) -* [plugin install](plugin_install.md) -* [plugin ls](plugin_ls.md) -* [plugin push](plugin_push.md) -* [plugin rm](plugin_rm.md) -* [plugin set](plugin_set.md) -* [plugin upgrade](plugin_upgrade.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_disable.md b/vendor/github.com/docker/docker/docs/reference/commandline/plugin_disable.md deleted file mode 100644 index 451f1ac..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_disable.md +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: "plugin disable" -description: "the plugin disable command description and usage" -keywords: "plugin, disable" ---- - - - -# plugin disable - -```markdown -Usage: docker plugin disable [OPTIONS] PLUGIN - -Disable a plugin - -Options: - -f, --force Force the disable of an active plugin - --help Print usage -``` - -Disables a plugin. The plugin must be installed before it can be disabled, -see [`docker plugin install`](plugin_install.md). Without the `-f` option, -a plugin that has references (eg, volumes, networks) cannot be disabled. - - -The following example shows that the `sample-volume-plugin` plugin is installed -and enabled: - -```bash -$ docker plugin ls - -ID NAME TAG DESCRIPTION ENABLED -69553ca1d123 tiborvass/sample-volume-plugin latest A test plugin for Docker true -``` - -To disable the plugin, use the following command: - -```bash -$ docker plugin disable tiborvass/sample-volume-plugin - -tiborvass/sample-volume-plugin - -$ docker plugin ls - -ID NAME TAG DESCRIPTION ENABLED -69553ca1d123 tiborvass/sample-volume-plugin latest A test plugin for Docker false -``` - -## Related information - -* [plugin create](plugin_create.md) -* [plugin enable](plugin_enable.md) -* [plugin inspect](plugin_inspect.md) -* [plugin install](plugin_install.md) -* [plugin ls](plugin_ls.md) -* [plugin push](plugin_push.md) -* [plugin rm](plugin_rm.md) -* [plugin set](plugin_set.md) -* [plugin upgrade](plugin_upgrade.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_enable.md b/vendor/github.com/docker/docker/docs/reference/commandline/plugin_enable.md deleted file mode 100644 index df8bee3..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_enable.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: "plugin enable" -description: "the plugin enable command description and usage" -keywords: "plugin, enable" ---- - - - -# plugin enable - -```markdown -Usage: docker plugin enable [OPTIONS] PLUGIN - -Enable a plugin - -Options: - --help Print usage - --timeout int HTTP client timeout (in seconds) -``` - -Enables a plugin. The plugin must be installed before it can be enabled, -see [`docker plugin install`](plugin_install.md). - - -The following example shows that the `sample-volume-plugin` plugin is installed, -but disabled: - -```bash -$ docker plugin ls - -ID NAME TAG DESCRIPTION ENABLED -69553ca1d123 tiborvass/sample-volume-plugin latest A test plugin for Docker false -``` - -To enable the plugin, use the following command: - -```bash -$ docker plugin enable tiborvass/sample-volume-plugin - -tiborvass/sample-volume-plugin - -$ docker plugin ls - -ID NAME TAG DESCRIPTION ENABLED -69553ca1d123 tiborvass/sample-volume-plugin latest A test plugin for Docker true -``` - -## Related information - -* [plugin create](plugin_create.md) -* [plugin disable](plugin_disable.md) -* [plugin inspect](plugin_inspect.md) -* [plugin install](plugin_install.md) -* [plugin ls](plugin_ls.md) -* [plugin push](plugin_push.md) -* [plugin rm](plugin_rm.md) -* [plugin set](plugin_set.md) -* [plugin upgrade](plugin_upgrade.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_inspect.md b/vendor/github.com/docker/docker/docs/reference/commandline/plugin_inspect.md deleted file mode 100644 index fdcc030..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_inspect.md +++ /dev/null @@ -1,164 +0,0 @@ ---- -title: "plugin inspect" -description: "The plugin inspect command description and usage" -keywords: "plugin, inspect" ---- - - - -# plugin inspect - -```markdown -Usage: docker plugin inspect [OPTIONS] PLUGIN [PLUGIN...] - -Display detailed information on one or more plugins - -Options: - -f, --format string Format the output using the given Go template - --help Print usage -``` - -Returns information about a plugin. By default, this command renders all results -in a JSON array. - -Example output: - -```bash -$ docker plugin inspect tiborvass/sample-volume-plugin:latest -``` -```JSON -{ - "Id": "8c74c978c434745c3ade82f1bc0acf38d04990eaf494fa507c16d9f1daa99c21", - "Name": "tiborvass/sample-volume-plugin:latest", - "PluginReference": "tiborvas/sample-volume-plugin:latest", - "Enabled": true, - "Config": { - "Mounts": [ - { - "Name": "", - "Description": "", - "Settable": null, - "Source": "/data", - "Destination": "/data", - "Type": "bind", - "Options": [ - "shared", - "rbind" - ] - }, - { - "Name": "", - "Description": "", - "Settable": null, - "Source": null, - "Destination": "/foobar", - "Type": "tmpfs", - "Options": null - } - ], - "Env": [ - "DEBUG=1" - ], - "Args": null, - "Devices": null - }, - "Manifest": { - "ManifestVersion": "v0", - "Description": "A test plugin for Docker", - "Documentation": "https://docs.docker.com/engine/extend/plugins/", - "Interface": { - "Types": [ - "docker.volumedriver/1.0" - ], - "Socket": "plugins.sock" - }, - "Entrypoint": [ - "plugin-sample-volume-plugin", - "/data" - ], - "Workdir": "", - "User": { - }, - "Network": { - "Type": "host" - }, - "Capabilities": null, - "Mounts": [ - { - "Name": "", - "Description": "", - "Settable": null, - "Source": "/data", - "Destination": "/data", - "Type": "bind", - "Options": [ - "shared", - "rbind" - ] - }, - { - "Name": "", - "Description": "", - "Settable": null, - "Source": null, - "Destination": "/foobar", - "Type": "tmpfs", - "Options": null - } - ], - "Devices": [ - { - "Name": "device", - "Description": "a host device to mount", - "Settable": null, - "Path": "/dev/cpu_dma_latency" - } - ], - "Env": [ - { - "Name": "DEBUG", - "Description": "If set, prints debug messages", - "Settable": null, - "Value": "1" - } - ], - "Args": { - "Name": "args", - "Description": "command line arguments", - "Settable": null, - "Value": [ - - ] - } - } -} -``` -(output formatted for readability) - - -```bash -$ docker plugin inspect -f '{{.Id}}' tiborvass/sample-volume-plugin:latest -``` -``` -8c74c978c434745c3ade82f1bc0acf38d04990eaf494fa507c16d9f1daa99c21 -``` - - -## Related information - -* [plugin create](plugin_create.md) -* [plugin enable](plugin_enable.md) -* [plugin disable](plugin_disable.md) -* [plugin install](plugin_install.md) -* [plugin ls](plugin_ls.md) -* [plugin push](plugin_push.md) -* [plugin rm](plugin_rm.md) -* [plugin set](plugin_set.md) -* [plugin upgrade](plugin_upgrade.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_install.md b/vendor/github.com/docker/docker/docs/reference/commandline/plugin_install.md deleted file mode 100644 index 0601193..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_install.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: "plugin install" -description: "the plugin install command description and usage" -keywords: "plugin, install" ---- - - - -# plugin install - -```markdown -Usage: docker plugin install [OPTIONS] PLUGIN [KEY=VALUE...] - -Install a plugin - -Options: - --alias string Local name for plugin - --disable Do not enable the plugin on install - --grant-all-permissions Grant all permissions necessary to run the plugin - --help Print usage -``` - -Installs and enables a plugin. Docker looks first for the plugin on your Docker -host. If the plugin does not exist locally, then the plugin is pulled from -the registry. Note that the minimum required registry version to distribute -plugins is 2.3.0 - - -The following example installs `vieus/sshfs` plugin and [set](plugin_set.md) it's env variable -`DEBUG` to 1. Install consists of pulling the plugin from Docker Hub, prompting -the user to accept the list of privileges that the plugin needs, settings parameters - and enabling the plugin. - -```bash -$ docker plugin install vieux/sshfs DEBUG=1 - -Plugin "vieux/sshfs" is requesting the following privileges: - - network: [host] - - device: [/dev/fuse] - - capabilities: [CAP_SYS_ADMIN] -Do you grant the above permissions? [y/N] y -vieux/sshfs -``` - -After the plugin is installed, it appears in the list of plugins: - -```bash -$ docker plugin ls - -ID NAME TAG DESCRIPTION ENABLED -69553ca1d123 vieux/sshfs latest sshFS plugin for Docker true -``` - -## Related information - -* [plugin create](plugin_create.md) -* [plugin disable](plugin_disable.md) -* [plugin enable](plugin_enable.md) -* [plugin inspect](plugin_inspect.md) -* [plugin ls](plugin_ls.md) -* [plugin push](plugin_push.md) -* [plugin rm](plugin_rm.md) -* [plugin set](plugin_set.md) -* [plugin upgrade](plugin_upgrade.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_ls.md b/vendor/github.com/docker/docker/docs/reference/commandline/plugin_ls.md deleted file mode 100644 index 7a3426d..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_ls.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: "plugin ls" -description: "The plugin ls command description and usage" -keywords: "plugin, list" ---- - - - -# plugin ls - -```markdown -Usage: docker plugin ls [OPTIONS] - -List plugins - -Aliases: - ls, list - -Options: - --help Print usage - --no-trunc Don't truncate output -``` - -Lists all the plugins that are currently installed. You can install plugins -using the [`docker plugin install`](plugin_install.md) command. - -Example output: - -```bash -$ docker plugin ls - -ID NAME TAG DESCRIPTION ENABLED -69553ca1d123 tiborvass/sample-volume-plugin latest A test plugin for Docker true -``` - -## Related information - -* [plugin create](plugin_create.md) -* [plugin disable](plugin_disable.md) -* [plugin enable](plugin_enable.md) -* [plugin inspect](plugin_inspect.md) -* [plugin install](plugin_install.md) -* [plugin push](plugin_push.md) -* [plugin rm](plugin_rm.md) -* [plugin set](plugin_set.md) -* [plugin upgrade](plugin_upgrade.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_push.md b/vendor/github.com/docker/docker/docs/reference/commandline/plugin_push.md deleted file mode 100644 index e61d109..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_push.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: "plugin push" -description: "the plugin push command description and usage" -keywords: "plugin, push" ---- - - - -```markdown -Usage: docker plugin push [OPTIONS] PLUGIN[:TAG] - -Push a plugin to a registry - -Options: - --help Print usage -``` - -Use `docker plugin create` to create the plugin. Once the plugin is ready for distribution, -use `docker plugin push` to share your images to the Docker Hub registry or to a self-hosted one. - -Registry credentials are managed by [docker login](login.md). - -The following example shows how to push a sample `user/plugin`. - -```bash - -$ docker plugin ls -ID NAME TAG DESCRIPTION ENABLED -69553ca1d456 user/plugin latest A sample plugin for Docker false -$ docker plugin push user/plugin -``` - -## Related information - -* [plugin create](plugin_create.md) -* [plugin disable](plugin_disable.md) -* [plugin enable](plugin_enable.md) -* [plugin inspect](plugin_inspect.md) -* [plugin install](plugin_install.md) -* [plugin ls](plugin_ls.md) -* [plugin rm](plugin_rm.md) -* [plugin set](plugin_set.md) -* [plugin upgrade](plugin_upgrade.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_rm.md b/vendor/github.com/docker/docker/docs/reference/commandline/plugin_rm.md deleted file mode 100644 index 323ce83..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_rm.md +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: "plugin rm" -description: "the plugin rm command description and usage" -keywords: "plugin, rm" ---- - - - -# plugin rm - -```markdown -Usage: docker plugin rm [OPTIONS] PLUGIN [PLUGIN...] - -Remove one or more plugins - -Aliases: - rm, remove - -Options: - -f, --force Force the removal of an active plugin - --help Print usage -``` - -Removes a plugin. You cannot remove a plugin if it is enabled, you must disable -a plugin using the [`docker plugin disable`](plugin_disable.md) before removing -it (or use --force, use of force is not recommended, since it can affect -functioning of running containers using the plugin). - -The following example disables and removes the `sample-volume-plugin:latest` plugin; - -```bash -$ docker plugin disable tiborvass/sample-volume-plugin -tiborvass/sample-volume-plugin - -$ docker plugin rm tiborvass/sample-volume-plugin:latest -tiborvass/sample-volume-plugin -``` - -## Related information - -* [plugin create](plugin_create.md) -* [plugin disable](plugin_disable.md) -* [plugin enable](plugin_enable.md) -* [plugin inspect](plugin_inspect.md) -* [plugin install](plugin_install.md) -* [plugin ls](plugin_ls.md) -* [plugin push](plugin_push.md) -* [plugin set](plugin_set.md) -* [plugin upgrade](plugin_upgrade.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_set.md b/vendor/github.com/docker/docker/docs/reference/commandline/plugin_set.md deleted file mode 100644 index c206a8a..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_set.md +++ /dev/null @@ -1,99 +0,0 @@ ---- -title: "plugin set" -description: "the plugin set command description and usage" -keywords: "plugin, set" ---- - - - -# plugin set - -```markdown -Usage: docker plugin set PLUGIN KEY=VALUE [KEY=VALUE...] - -Change settings for a plugin - -Options: - --help Print usage -``` - -Change settings for a plugin. The plugin must be disabled. - -The settings currently supported are: - * env variables - * source of mounts - * path of devices - * args - -The following example change the env variable `DEBUG` on the -`sample-volume-plugin` plugin. - -```bash -$ docker plugin inspect -f {{.Settings.Env}} tiborvass/sample-volume-plugin -[DEBUG=0] - -$ docker plugin set tiborvass/sample-volume-plugin DEBUG=1 - -$ docker plugin inspect -f {{.Settings.Env}} tiborvass/sample-volume-plugin -[DEBUG=1] -``` - -The following example change the source of the `mymount` mount on -the `myplugin` plugin. - -```bash -$ docker plugin inspect -f '{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}' myplugin -/foo - -$ docker plugins set myplugin mymount.source=/bar - -$ docker plugin inspect -f '{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}' myplugin -/bar -``` - -Note: since only `source` is settable in `mymount`, `docker plugins set mymount=/bar myplugin` would work too. - -The following example change the path of the `mydevice` device on -the `myplugin` plugin. - -```bash -$ docker plugin inspect -f '{{with $device := index .Settings.Devices 0}}{{$device.Path}}{{end}}' myplugin -/dev/foo - -$ docker plugins set myplugin mydevice.path=/dev/bar - -$ docker plugin inspect -f '{{with $device := index .Settings.Devices 0}}{{$device.Path}}{{end}}' myplugin -/dev/bar -``` - -Note: since only `path` is settable in `mydevice`, `docker plugins set mydevice=/dev/bar myplugin` would work too. - -The following example change the source of the args on the `myplugin` plugin. - -```bash -$ docker plugin inspect -f '{{.Settings.Args}}' myplugin -["foo", "bar"] - -$ docker plugins set myplugin args="foo bar baz" - -$ docker plugin inspect -f '{{.Settings.Args}}' myplugin -["foo", "bar", "baz"] -``` - -## Related information - -* [plugin create](plugin_create.md) -* [plugin disable](plugin_disable.md) -* [plugin enable](plugin_enable.md) -* [plugin inspect](plugin_inspect.md) -* [plugin install](plugin_install.md) -* [plugin ls](plugin_ls.md) -* [plugin push](plugin_push.md) -* [plugin rm](plugin_rm.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_upgrade.md b/vendor/github.com/docker/docker/docs/reference/commandline/plugin_upgrade.md deleted file mode 100644 index 20efc57..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/plugin_upgrade.md +++ /dev/null @@ -1,84 +0,0 @@ ---- -title: "plugin upgrade" -description: "the plugin upgrade command description and usage" -keywords: "plugin, upgrade" ---- - - - -# plugin upgrade - -```markdown -Usage: docker plugin upgrade [OPTIONS] PLUGIN [REMOTE] - -Upgrade a plugin - -Options: - --disable-content-trust Skip image verification (default true) - --grant-all-permissions Grant all permissions necessary to run the plugin - --help Print usage - --skip-remote-check Do not check if specified remote plugin matches existing plugin image -``` - -Upgrades an existing plugin to the specified remote plugin image. If no remote -is specified, Docker will re-pull the current image and use the updated version. -All existing references to the plugin will continue to work. -The plugin must be disabled before running the upgrade. - -The following example installs `vieus/sshfs` plugin, uses it to create and use -a volume, then upgrades the plugin. - -```bash -$ docker plugin install vieux/sshfs DEBUG=1 - -Plugin "vieux/sshfs:next" is requesting the following privileges: - - network: [host] - - device: [/dev/fuse] - - capabilities: [CAP_SYS_ADMIN] -Do you grant the above permissions? [y/N] y -vieux/sshfs:next - -$ docker volume create -d vieux/sshfs:next -o sshcmd=root@1.2.3.4:/tmp/shared -o password=XXX sshvolume -sshvolume -$ docker run -it -v sshvolume:/data alpine sh -c "touch /data/hello" -$ docker plugin disable -f vieux/sshfs:next -viex/sshfs:next - -# Here docker volume ls doesn't show 'sshfsvolume', since the plugin is disabled -$ docker volume ls -DRIVER VOLUME NAME - -$ docker plugin upgrade vieux/sshfs:next vieux/sshfs:next -Plugin "vieux/sshfs:next" is requesting the following privileges: - - network: [host] - - device: [/dev/fuse] - - capabilities: [CAP_SYS_ADMIN] -Do you grant the above permissions? [y/N] y -Upgrade plugin vieux/sshfs:next to vieux/sshfs:next -$ docker plugin enable vieux/sshfs:next -viex/sshfs:next -$ docker volume ls -DRIVER VOLUME NAME -viuex/sshfs:next sshvolume -$ docker run -it -v sshvolume:/data alpine sh -c "ls /data" -hello -``` - -## Related information - -* [plugin create](plugin_create.md) -* [plugin disable](plugin_disable.md) -* [plugin enable](plugin_enable.md) -* [plugin inspect](plugin_inspect.md) -* [plugin install](plugin_install.md) -* [plugin ls](plugin_ls.md) -* [plugin push](plugin_push.md) -* [plugin rm](plugin_rm.md) -* [plugin set](plugin_set.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/port.md b/vendor/github.com/docker/docker/docs/reference/commandline/port.md deleted file mode 100644 index bc90b6e..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/port.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: "port" -description: "The port command description and usage" -keywords: "port, mapping, container" ---- - - - -# port - -```markdown -Usage: docker port CONTAINER [PRIVATE_PORT[/PROTO]] - -List port mappings or a specific mapping for the container - -Options: - --help Print usage -``` - -You can find out all the ports mapped by not specifying a `PRIVATE_PORT`, or -just a specific mapping: - - $ docker ps - CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES - b650456536c7 busybox:latest top 54 minutes ago Up 54 minutes 0.0.0.0:1234->9876/tcp, 0.0.0.0:4321->7890/tcp test - $ docker port test - 7890/tcp -> 0.0.0.0:4321 - 9876/tcp -> 0.0.0.0:1234 - $ docker port test 7890/tcp - 0.0.0.0:4321 - $ docker port test 7890/udp - 2014/06/24 11:53:36 Error: No public port '7890/udp' published for test - $ docker port test 7890 - 0.0.0.0:4321 diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/ps.md b/vendor/github.com/docker/docker/docs/reference/commandline/ps.md deleted file mode 100644 index 1d5f31d..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/ps.md +++ /dev/null @@ -1,384 +0,0 @@ ---- -title: "ps" -description: "The ps command description and usage" -keywords: "container, running, list" ---- - - - -# ps - -```markdown -Usage: docker ps [OPTIONS] - -List containers - -Options: - -a, --all Show all containers (default shows just running) - -f, --filter value Filter output based on conditions provided (default []) - - exited= an exit code of - - label= or label== - - status=(created|restarting|removing|running|paused|exited) - - name= a container's name - - id= a container's ID - - before=(|) - - since=(|) - - ancestor=([:tag]||) - containers created from an image or a descendant. - - is-task=(true|false) - - health=(starting|healthy|unhealthy|none) - --format string Pretty-print containers using a Go template - --help Print usage - -n, --last int Show n last created containers (includes all states) (default -1) - -l, --latest Show the latest created container (includes all states) - --no-trunc Don't truncate output - -q, --quiet Only display numeric IDs - -s, --size Display total file sizes -``` - -Running `docker ps --no-trunc` showing 2 linked containers. - -```bash -$ docker ps - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -4c01db0b339c ubuntu:12.04 bash 17 seconds ago Up 16 seconds 3300-3310/tcp webapp -d7886598dbe2 crosbymichael/redis:latest /redis-server --dir 33 minutes ago Up 33 minutes 6379/tcp redis,webapp/db -``` - -The `docker ps` command only shows running containers by default. To see all -containers, use the `-a` (or `--all`) flag: - -```bash -$ docker ps -a -``` - -`docker ps` groups exposed ports into a single range if possible. E.g., a -container that exposes TCP ports `100, 101, 102` displays `100-102/tcp` in -the `PORTS` column. - -## Filtering - -The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there is more -than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`) - -The currently supported filters are: - -* id (container's id) -* label (`label=` or `label==`) -* name (container's name) -* exited (int - the code of exited containers. Only useful with `--all`) -* status (created|restarting|running|removing|paused|exited|dead) -* ancestor (`[:]`, `` or ``) - filters containers that were created from the given image or a descendant. -* before (container's id or name) - filters containers created before given id or name -* since (container's id or name) - filters containers created since given id or name -* isolation (default|process|hyperv) (Windows daemon only) -* volume (volume name or mount point) - filters containers that mount volumes. -* network (network id or name) - filters containers connected to the provided network -* health (starting|healthy|unhealthy|none) - filters containers based on healthcheck status - -#### Label - -The `label` filter matches containers based on the presence of a `label` alone or a `label` and a -value. - -The following filter matches containers with the `color` label regardless of its value. - -```bash -$ docker ps --filter "label=color" - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -673394ef1d4c busybox "top" 47 seconds ago Up 45 seconds nostalgic_shockley -d85756f57265 busybox "top" 52 seconds ago Up 51 seconds high_albattani -``` - -The following filter matches containers with the `color` label with the `blue` value. - -```bash -$ docker ps --filter "label=color=blue" - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -d85756f57265 busybox "top" About a minute ago Up About a minute high_albattani -``` - -#### Name - -The `name` filter matches on all or part of a container's name. - -The following filter matches all containers with a name containing the `nostalgic_stallman` string. - -```bash -$ docker ps --filter "name=nostalgic_stallman" - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -9b6247364a03 busybox "top" 2 minutes ago Up 2 minutes nostalgic_stallman -``` - -You can also filter for a substring in a name as this shows: - -```bash -$ docker ps --filter "name=nostalgic" - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -715ebfcee040 busybox "top" 3 seconds ago Up 1 second i_am_nostalgic -9b6247364a03 busybox "top" 7 minutes ago Up 7 minutes nostalgic_stallman -673394ef1d4c busybox "top" 38 minutes ago Up 38 minutes nostalgic_shockley -``` - -#### Exited - -The `exited` filter matches containers by exist status code. For example, to -filter for containers that have exited successfully: - -```bash -$ docker ps -a --filter 'exited=0' - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -ea09c3c82f6e registry:latest /srv/run.sh 2 weeks ago Exited (0) 2 weeks ago 127.0.0.1:5000->5000/tcp desperate_leakey -106ea823fe4e fedora:latest /bin/sh -c 'bash -l' 2 weeks ago Exited (0) 2 weeks ago determined_albattani -48ee228c9464 fedora:20 bash 2 weeks ago Exited (0) 2 weeks ago tender_torvalds -``` - -#### Killed containers - -You can use a filter to locate containers that exited with status of `137` -meaning a `SIGKILL(9)` killed them. - -```bash -$ docker ps -a --filter 'exited=137' -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -b3e1c0ed5bfe ubuntu:latest "sleep 1000" 12 seconds ago Exited (137) 5 seconds ago grave_kowalevski -a2eb5558d669 redis:latest "/entrypoint.sh redi 2 hours ago Exited (137) 2 hours ago sharp_lalande -``` - -Any of these events result in a `137` status: - -* the `init` process of the container is killed manually -* `docker kill` kills the container -* Docker daemon restarts which kills all running containers - -#### Status - -The `status` filter matches containers by status. You can filter using -`created`, `restarting`, `running`, `removing`, `paused`, `exited` and `dead`. For example, -to filter for `running` containers: - -```bash -$ docker ps --filter status=running - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -715ebfcee040 busybox "top" 16 minutes ago Up 16 minutes i_am_nostalgic -d5c976d3c462 busybox "top" 23 minutes ago Up 23 minutes top -9b6247364a03 busybox "top" 24 minutes ago Up 24 minutes nostalgic_stallman -``` - -To filter for `paused` containers: - -```bash -$ docker ps --filter status=paused - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -673394ef1d4c busybox "top" About an hour ago Up About an hour (Paused) nostalgic_shockley -``` - -#### Ancestor - -The `ancestor` filter matches containers based on its image or a descendant of -it. The filter supports the following image representation: - -- image -- image:tag -- image:tag@digest -- short-id -- full-id - -If you don't specify a `tag`, the `latest` tag is used. For example, to filter -for containers that use the latest `ubuntu` image: - -```bash -$ docker ps --filter ancestor=ubuntu - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -919e1179bdb8 ubuntu-c1 "top" About a minute ago Up About a minute admiring_lovelace -5d1e4a540723 ubuntu-c2 "top" About a minute ago Up About a minute admiring_sammet -82a598284012 ubuntu "top" 3 minutes ago Up 3 minutes sleepy_bose -bab2a34ba363 ubuntu "top" 3 minutes ago Up 3 minutes focused_yonath -``` - -Match containers based on the `ubuntu-c1` image which, in this case, is a child -of `ubuntu`: - -```bash -$ docker ps --filter ancestor=ubuntu-c1 - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -919e1179bdb8 ubuntu-c1 "top" About a minute ago Up About a minute admiring_lovelace -``` - -Match containers based on the `ubuntu` version `12.04.5` image: - -```bash -$ docker ps --filter ancestor=ubuntu:12.04.5 - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -82a598284012 ubuntu:12.04.5 "top" 3 minutes ago Up 3 minutes sleepy_bose -``` - -The following matches containers based on the layer `d0e008c6cf02` or an image -that have this layer in its layer stack. - -```bash -$ docker ps --filter ancestor=d0e008c6cf02 - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -82a598284012 ubuntu:12.04.5 "top" 3 minutes ago Up 3 minutes sleepy_bose -``` - -#### Before - -The `before` filter shows only containers created before the container with -given id or name. For example, having these containers created: - -```bash -$ docker ps - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -9c3527ed70ce busybox "top" 14 seconds ago Up 15 seconds desperate_dubinsky -4aace5031105 busybox "top" 48 seconds ago Up 49 seconds focused_hamilton -6e63f6ff38b0 busybox "top" About a minute ago Up About a minute distracted_fermat -``` - -Filtering with `before` would give: - -```bash -$ docker ps -f before=9c3527ed70ce - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -4aace5031105 busybox "top" About a minute ago Up About a minute focused_hamilton -6e63f6ff38b0 busybox "top" About a minute ago Up About a minute distracted_fermat -``` - -#### Since - -The `since` filter shows only containers created since the container with given -id or name. For example, with the same containers as in `before` filter: - -```bash -$ docker ps -f since=6e63f6ff38b0 - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -9c3527ed70ce busybox "top" 10 minutes ago Up 10 minutes desperate_dubinsky -4aace5031105 busybox "top" 10 minutes ago Up 10 minutes focused_hamilton -``` - -#### Volume - -The `volume` filter shows only containers that mount a specific volume or have -a volume mounted in a specific path: - -```bash{% raw %} -$ docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}" -CONTAINER ID MOUNTS -9c3527ed70ce remote-volume - -$ docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}" -CONTAINER ID MOUNTS -9c3527ed70ce remote-volume -{% endraw %}``` - -#### Network - -The `network` filter shows only containers that are connected to a network with -a given name or id. - -The following filter matches all containers that are connected to a network -with a name containing `net1`. - -```bash -$ docker run -d --net=net1 --name=test1 ubuntu top -$ docker run -d --net=net2 --name=test2 ubuntu top - -$ docker ps --filter network=net1 - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -9d4893ed80fe ubuntu "top" 10 minutes ago Up 10 minutes test1 -``` - -The network filter matches on both the network's name and id. The following -example shows all containers that are attached to the `net1` network, using -the network id as a filter; - -```bash -{% raw %} -$ docker network inspect --format "{{.ID}}" net1 -{% endraw %} - -8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5 - -$ docker ps --filter network=8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5 - -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -9d4893ed80fe ubuntu "top" 10 minutes ago Up 10 minutes test1 -``` - -## Formatting - -The formatting option (`--format`) pretty-prints container output using a Go -template. - -Valid placeholders for the Go template are listed below: - -Placeholder | Description ---------------|---------------------------------------------------------------------------------------------------- -`.ID` | Container ID -`.Image` | Image ID -`.Command` | Quoted command -`.CreatedAt` | Time when the container was created. -`.RunningFor` | Elapsed time since the container was started. -`.Ports` | Exposed ports. -`.Status` | Container status. -`.Size` | Container disk size. -`.Names` | Container names. -`.Labels` | All labels assigned to the container. -`.Label` | Value of a specific label for this container. For example `'{% raw %}{{.Label "com.docker.swarm.cpu"}}{% endraw %}'` -`.Mounts` | Names of the volumes mounted in this container. -`.Networks` | Names of the networks attached to this container. - -When using the `--format` option, the `ps` command will either output the data -exactly as the template declares or, when using the `table` directive, includes -column headers as well. - -The following example uses a template without headers and outputs the `ID` and -`Command` entries separated by a colon for all running containers: - -```bash -{% raw %} -$ docker ps --format "{{.ID}}: {{.Command}}" -{% endraw %} - -a87ecb4f327c: /bin/sh -c #(nop) MA -01946d9d34d8: /bin/sh -c #(nop) MA -c1d3b0166030: /bin/sh -c yum -y up -41d50ecd2f57: /bin/sh -c #(nop) MA -``` - -To list all running containers with their labels in a table format you can use: - -```bash -{% raw %} -$ docker ps --format "table {{.ID}}\t{{.Labels}}" -{% endraw %} - -CONTAINER ID LABELS -a87ecb4f327c com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd -01946d9d34d8 -c1d3b0166030 com.docker.swarm.node=debian,com.docker.swarm.cpu=6 -41d50ecd2f57 com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd -``` diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/pull.md b/vendor/github.com/docker/docker/docs/reference/commandline/pull.md deleted file mode 100644 index 0c960b4..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/pull.md +++ /dev/null @@ -1,252 +0,0 @@ ---- -title: "pull" -description: "The pull command description and usage" -keywords: "pull, image, hub, docker" ---- - - - -# pull - -```markdown -Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST] - -Pull an image or a repository from a registry - -Options: - -a, --all-tags Download all tagged images in the repository - --disable-content-trust Skip image verification (default true) - --help Print usage -``` - -Most of your images will be created on top of a base image from the -[Docker Hub](https://hub.docker.com) registry. - -[Docker Hub](https://hub.docker.com) contains many pre-built images that you -can `pull` and try without needing to define and configure your own. - -To download a particular image, or set of images (i.e., a repository), -use `docker pull`. - -## Proxy configuration - -If you are behind an HTTP proxy server, for example in corporate settings, -before open a connect to registry, you may need to configure the Docker -daemon's proxy settings, using the `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` -environment variables. To set these environment variables on a host using -`systemd`, refer to the [control and configure Docker with systemd](https://docs.docker.com/engine/admin/systemd/#http-proxy) -for variables configuration. - -## Concurrent downloads - -By default the Docker daemon will pull three layers of an image at a time. -If you are on a low bandwidth connection this may cause timeout issues and you may want to lower -this via the `--max-concurrent-downloads` daemon option. See the -[daemon documentation](dockerd.md) for more details. - -## Examples - -### Pull an image from Docker Hub - -To download a particular image, or set of images (i.e., a repository), use -`docker pull`. If no tag is provided, Docker Engine uses the `:latest` tag as a -default. This command pulls the `debian:latest` image: - -```bash -$ docker pull debian - -Using default tag: latest -latest: Pulling from library/debian -fdd5d7827f33: Pull complete -a3ed95caeb02: Pull complete -Digest: sha256:e7d38b3517548a1c71e41bffe9c8ae6d6d29546ce46bf62159837aad072c90aa -Status: Downloaded newer image for debian:latest -``` - -Docker images can consist of multiple layers. In the example above, the image -consists of two layers; `fdd5d7827f33` and `a3ed95caeb02`. - -Layers can be reused by images. For example, the `debian:jessie` image shares -both layers with `debian:latest`. Pulling the `debian:jessie` image therefore -only pulls its metadata, but not its layers, because all layers are already -present locally: - -```bash -$ docker pull debian:jessie - -jessie: Pulling from library/debian -fdd5d7827f33: Already exists -a3ed95caeb02: Already exists -Digest: sha256:a9c958be96d7d40df920e7041608f2f017af81800ca5ad23e327bc402626b58e -Status: Downloaded newer image for debian:jessie -``` - -To see which images are present locally, use the [`docker images`](images.md) -command: - -```bash -$ docker images - -REPOSITORY TAG IMAGE ID CREATED SIZE -debian jessie f50f9524513f 5 days ago 125.1 MB -debian latest f50f9524513f 5 days ago 125.1 MB -``` - -Docker uses a content-addressable image store, and the image ID is a SHA256 -digest covering the image's configuration and layers. In the example above, -`debian:jessie` and `debian:latest` have the same image ID because they are -actually the *same* image tagged with different names. Because they are the -same image, their layers are stored only once and do not consume extra disk -space. - -For more information about images, layers, and the content-addressable store, -refer to [understand images, containers, and storage drivers](https://docs.docker.com/engine/userguide/storagedriver/imagesandcontainers/). - - -## Pull an image by digest (immutable identifier) - -So far, you've pulled images by their name (and "tag"). Using names and tags is -a convenient way to work with images. When using tags, you can `docker pull` an -image again to make sure you have the most up-to-date version of that image. -For example, `docker pull ubuntu:14.04` pulls the latest version of the Ubuntu -14.04 image. - -In some cases you don't want images to be updated to newer versions, but prefer -to use a fixed version of an image. Docker enables you to pull an image by its -*digest*. When pulling an image by digest, you specify *exactly* which version -of an image to pull. Doing so, allows you to "pin" an image to that version, -and guarantee that the image you're using is always the same. - -To know the digest of an image, pull the image first. Let's pull the latest -`ubuntu:14.04` image from Docker Hub: - -```bash -$ docker pull ubuntu:14.04 - -14.04: Pulling from library/ubuntu -5a132a7e7af1: Pull complete -fd2731e4c50c: Pull complete -28a2f68d1120: Pull complete -a3ed95caeb02: Pull complete -Digest: sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 -Status: Downloaded newer image for ubuntu:14.04 -``` - -Docker prints the digest of the image after the pull has finished. In the example -above, the digest of the image is: - - sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 - -Docker also prints the digest of an image when *pushing* to a registry. This -may be useful if you want to pin to a version of the image you just pushed. - -A digest takes the place of the tag when pulling an image, for example, to -pull the above image by digest, run the following command: - -```bash -$ docker pull ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 - -sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2: Pulling from library/ubuntu -5a132a7e7af1: Already exists -fd2731e4c50c: Already exists -28a2f68d1120: Already exists -a3ed95caeb02: Already exists -Digest: sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 -Status: Downloaded newer image for ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 -``` - -Digest can also be used in the `FROM` of a Dockerfile, for example: - -```Dockerfile -FROM ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 -MAINTAINER some maintainer -``` - -> **Note**: Using this feature "pins" an image to a specific version in time. -> Docker will therefore not pull updated versions of an image, which may include -> security updates. If you want to pull an updated image, you need to change the -> digest accordingly. - - -## Pulling from a different registry - -By default, `docker pull` pulls images from [Docker Hub](https://hub.docker.com). It is also possible to -manually specify the path of a registry to pull from. For example, if you have -set up a local registry, you can specify its path to pull from it. A registry -path is similar to a URL, but does not contain a protocol specifier (`https://`). - -The following command pulls the `testing/test-image` image from a local registry -listening on port 5000 (`myregistry.local:5000`): - -```bash -$ docker pull myregistry.local:5000/testing/test-image -``` - -Registry credentials are managed by [docker login](login.md). - -Docker uses the `https://` protocol to communicate with a registry, unless the -registry is allowed to be accessed over an insecure connection. Refer to the -[insecure registries](dockerd.md#insecure-registries) section for more information. - - -## Pull a repository with multiple images - -By default, `docker pull` pulls a *single* image from the registry. A repository -can contain multiple images. To pull all images from a repository, provide the -`-a` (or `--all-tags`) option when using `docker pull`. - -This command pulls all images from the `fedora` repository: - -```bash -$ docker pull --all-tags fedora - -Pulling repository fedora -ad57ef8d78d7: Download complete -105182bb5e8b: Download complete -511136ea3c5a: Download complete -73bd853d2ea5: Download complete -.... - -Status: Downloaded newer image for fedora -``` - -After the pull has completed use the `docker images` command to see the -images that were pulled. The example below shows all the `fedora` images -that are present locally: - -```bash -$ docker images fedora - -REPOSITORY TAG IMAGE ID CREATED SIZE -fedora rawhide ad57ef8d78d7 5 days ago 359.3 MB -fedora 20 105182bb5e8b 5 days ago 372.7 MB -fedora heisenbug 105182bb5e8b 5 days ago 372.7 MB -fedora latest 105182bb5e8b 5 days ago 372.7 MB -``` - -## Canceling a pull - -Killing the `docker pull` process, for example by pressing `CTRL-c` while it is -running in a terminal, will terminate the pull operation. - -```bash -$ docker pull fedora - -Using default tag: latest -latest: Pulling from library/fedora -a3ed95caeb02: Pulling fs layer -236608c7b546: Pulling fs layer -^C -``` - -> **Note**: Technically, the Engine terminates a pull operation when the -> connection between the Docker Engine daemon and the Docker Engine client -> initiating the pull is lost. If the connection with the Engine daemon is -> lost for other reasons than a manual interaction, the pull is also aborted. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/push.md b/vendor/github.com/docker/docker/docs/reference/commandline/push.md deleted file mode 100644 index e36fd02..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/push.md +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: "push" -description: "The push command description and usage" -keywords: "share, push, image" ---- - - - -# push - -```markdown -Usage: docker push [OPTIONS] NAME[:TAG] - -Push an image or a repository to a registry - -Options: - --disable-content-trust Skip image verification (default true) - --help Print usage -``` - -Use `docker push` to share your images to the [Docker Hub](https://hub.docker.com) -registry or to a self-hosted one. - -Refer to the [`docker tag`](tag.md) reference for more information about valid -image and tag names. - -Killing the `docker push` process, for example by pressing `CTRL-c` while it is -running in a terminal, terminates the push operation. - -Registry credentials are managed by [docker login](login.md). - -## Concurrent uploads - -By default the Docker daemon will push five layers of an image at a time. -If you are on a low bandwidth connection this may cause timeout issues and you may want to lower -this via the `--max-concurrent-uploads` daemon option. See the -[daemon documentation](dockerd.md) for more details. - -## Examples - -### Pushing a new image to a registry - -First save the new image by finding the container ID (using [`docker ps`](ps.md)) -and then committing it to a new image name. Note that only `a-z0-9-_.` are -allowed when naming images: - -```bash -$ docker commit c16378f943fe rhel-httpd -``` - -Now, push the image to the registry using the image ID. In this example the -registry is on host named `registry-host` and listening on port `5000`. To do -this, tag the image with the host name or IP address, and the port of the -registry: - -```bash -$ docker tag rhel-httpd registry-host:5000/myadmin/rhel-httpd -$ docker push registry-host:5000/myadmin/rhel-httpd -``` - -Check that this worked by running: - -```bash -$ docker images -``` - -You should see both `rhel-httpd` and `registry-host:5000/myadmin/rhel-httpd` -listed. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/rename.md b/vendor/github.com/docker/docker/docs/reference/commandline/rename.md deleted file mode 100644 index be035f1..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/rename.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: "rename" -description: "The rename command description and usage" -keywords: "rename, docker, container" ---- - - - -# rename - -```markdown -Usage: docker rename CONTAINER NEW_NAME - -Rename a container - -Options: - --help Print usage -``` - -The `docker rename` command allows the container to be renamed to a different name. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/restart.md b/vendor/github.com/docker/docker/docs/reference/commandline/restart.md deleted file mode 100644 index 9f7ed00..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/restart.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: "restart" -description: "The restart command description and usage" -keywords: "restart, container, Docker" ---- - - - -# restart - -```markdown -Usage: docker restart [OPTIONS] CONTAINER [CONTAINER...] - -Restart one or more containers - -Options: - --help Print usage - -t, --time int Seconds to wait for stop before killing the container (default 10) -``` diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/rm.md b/vendor/github.com/docker/docker/docs/reference/commandline/rm.md deleted file mode 100644 index 1c3e795..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/rm.md +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: "rm" -description: "The rm command description and usage" -keywords: "remove, Docker, container" ---- - - - -# rm - -```markdown -Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] - -Remove one or more containers - -Options: - -f, --force Force the removal of a running container (uses SIGKILL) - --help Print usage - -l, --link Remove the specified link - -v, --volumes Remove the volumes associated with the container -``` - -## Examples - - $ docker rm /redis - /redis - -This will remove the container referenced under the link -`/redis`. - - $ docker rm --link /webapp/redis - /webapp/redis - -This will remove the underlying link between `/webapp` and the `/redis` -containers removing all network communication. - - $ docker rm --force redis - redis - -The main process inside the container referenced under the link `/redis` will receive -`SIGKILL`, then the container will be removed. - - $ docker rm $(docker ps -a -q) - -This command will delete all stopped containers. The command -`docker ps -a -q` will return all existing container IDs and pass them to -the `rm` command which will delete them. Any running containers will not be -deleted. - - $ docker rm -v redis - redis - -This command will remove the container and any volumes associated with it. -Note that if a volume was specified with a name, it will not be removed. - - $ docker create -v awesome:/foo -v /bar --name hello redis - hello - $ docker rm -v hello - -In this example, the volume for `/foo` will remain intact, but the volume for -`/bar` will be removed. The same behavior holds for volumes inherited with -`--volumes-from`. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/rmi.md b/vendor/github.com/docker/docker/docs/reference/commandline/rmi.md deleted file mode 100644 index 149b763..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/rmi.md +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: "rmi" -description: "The rmi command description and usage" -keywords: "remove, image, Docker" ---- - - - -# rmi - -```markdown -Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] - -Remove one or more images - -Options: - -f, --force Force removal of the image - --help Print usage - --no-prune Do not delete untagged parents -``` - -You can remove an image using its short or long ID, its tag, or its digest. If -an image has one or more tag referencing it, you must remove all of them before -the image is removed. Digest references are removed automatically when an image -is removed by tag. - - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - test1 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) - test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) - test2 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) - - $ docker rmi fd484f19954f - Error: Conflict, cannot delete image fd484f19954f because it is tagged in multiple repositories, use -f to force - 2013/12/11 05:47:16 Error: failed to remove one or more images - - $ docker rmi test1 - Untagged: test1:latest - $ docker rmi test2 - Untagged: test2:latest - - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) - $ docker rmi test - Untagged: test:latest - Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8 - -If you use the `-f` flag and specify the image's short or long ID, then this -command untags and removes all images that match the specified ID. - - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - test1 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) - test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) - test2 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB) - - $ docker rmi -f fd484f19954f - Untagged: test1:latest - Untagged: test:latest - Untagged: test2:latest - Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8 - -An image pulled by digest has no tag associated with it: - - $ docker images --digests - REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE - localhost:5000/test/busybox sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf 4986bf8c1536 9 weeks ago 2.43 MB - -To remove an image using its digest: - - $ docker rmi localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf - Untagged: localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf - Deleted: 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125 - Deleted: ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2 - Deleted: df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/run.md b/vendor/github.com/docker/docker/docs/reference/commandline/run.md deleted file mode 100644 index e57ba4b..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/run.md +++ /dev/null @@ -1,732 +0,0 @@ ---- -title: "run" -description: "The run command description and usage" -keywords: "run, command, container" ---- - - - -# run - -```markdown -Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] - -Run a command in a new container - -Options: - --add-host value Add a custom host-to-IP mapping (host:ip) (default []) - -a, --attach value Attach to STDIN, STDOUT or STDERR (default []) - --blkio-weight value Block IO (relative weight), between 10 and 1000 - --blkio-weight-device value Block IO weight (relative device weight) (default []) - --cap-add value Add Linux capabilities (default []) - --cap-drop value Drop Linux capabilities (default []) - --cgroup-parent string Optional parent cgroup for the container - --cidfile string Write the container ID to the file - --cpu-count int The number of CPUs available for execution by the container. - Windows daemon only. On Windows Server containers, this is - approximated as a percentage of total CPU usage. - --cpu-percent int Limit percentage of CPU available for execution - by the container. Windows daemon only. - The processor resource controls are mutually - exclusive, the order of precedence is CPUCount - first, then CPUShares, and CPUPercent last. - --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period - --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota - -c, --cpu-shares int CPU shares (relative weight) - --cpus NanoCPUs Number of CPUs (default 0.000) - --cpu-rt-period int Limit the CPU real-time period in microseconds - --cpu-rt-runtime int Limit the CPU real-time runtime in microseconds - --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) - --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) - -d, --detach Run container in background and print container ID - --detach-keys string Override the key sequence for detaching a container - --device value Add a host device to the container (default []) - --device-read-bps value Limit read rate (bytes per second) from a device (default []) - --device-read-iops value Limit read rate (IO per second) from a device (default []) - --device-write-bps value Limit write rate (bytes per second) to a device (default []) - --device-write-iops value Limit write rate (IO per second) to a device (default []) - --disable-content-trust Skip image verification (default true) - --dns value Set custom DNS servers (default []) - --dns-option value Set DNS options (default []) - --dns-search value Set custom DNS search domains (default []) - --entrypoint string Overwrite the default ENTRYPOINT of the image - -e, --env value Set environment variables (default []) - --env-file value Read in a file of environment variables (default []) - --expose value Expose a port or a range of ports (default []) - --group-add value Add additional groups to join (default []) - --health-cmd string Command to run to check health - --health-interval duration Time between running the check (ns|us|ms|s|m|h) (default 0s) - --health-retries int Consecutive failures needed to report unhealthy - --health-timeout duration Maximum time to allow one check to run (ns|us|ms|s|m|h) (default 0s) - --help Print usage - -h, --hostname string Container host name - --init Run an init inside the container that forwards signals and reaps processes - --init-path string Path to the docker-init binary - -i, --interactive Keep STDIN open even if not attached - --io-maxbandwidth string Maximum IO bandwidth limit for the system drive (Windows only) - (Windows only). The format is ``. - Unit is optional and can be `b` (bytes per second), - `k` (kilobytes per second), `m` (megabytes per second), - or `g` (gigabytes per second). If you omit the unit, - the system uses bytes per second. - --io-maxbandwidth and --io-maxiops are mutually exclusive options. - --io-maxiops uint Maximum IOps limit for the system drive (Windows only) - --ip string Container IPv4 address (e.g. 172.30.100.104) - --ip6 string Container IPv6 address (e.g. 2001:db8::33) - --ipc string IPC namespace to use - --isolation string Container isolation technology - --kernel-memory string Kernel memory limit - -l, --label value Set meta data on a container (default []) - --label-file value Read in a line delimited file of labels (default []) - --link value Add link to another container (default []) - --link-local-ip value Container IPv4/IPv6 link-local addresses (default []) - --log-driver string Logging driver for the container - --log-opt value Log driver options (default []) - --mac-address string Container MAC address (e.g. 92:d0:c6:0a:29:33) - -m, --memory string Memory limit - --memory-reservation string Memory soft limit - --memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap - --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) - --name string Assign a name to the container - --network-alias value Add network-scoped alias for the container (default []) - --network string Connect a container to a network - 'bridge': create a network stack on the default Docker bridge - 'none': no networking - 'container:': reuse another container's network stack - 'host': use the Docker host network stack - '|': connect to a user-defined network - --no-healthcheck Disable any container-specified HEALTHCHECK - --oom-kill-disable Disable OOM Killer - --oom-score-adj int Tune host's OOM preferences (-1000 to 1000) - --pid string PID namespace to use - --pids-limit int Tune container pids limit (set -1 for unlimited) - --privileged Give extended privileges to this container - -p, --publish value Publish a container's port(s) to the host (default []) - -P, --publish-all Publish all exposed ports to random ports - --read-only Mount the container's root filesystem as read only - --restart string Restart policy to apply when a container exits (default "no") - Possible values are : no, on-failure[:max-retry], always, unless-stopped - --rm Automatically remove the container when it exits - --runtime string Runtime to use for this container - --security-opt value Security Options (default []) - --shm-size string Size of /dev/shm, default value is 64MB. - The format is ``. `number` must be greater than `0`. - Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), - or `g` (gigabytes). If you omit the unit, the system uses bytes. - --sig-proxy Proxy received signals to the process (default true) - --stop-signal string Signal to stop a container, SIGTERM by default (default "SIGTERM") - --stop-timeout=10 Timeout (in seconds) to stop a container - --storage-opt value Storage driver options for the container (default []) - --sysctl value Sysctl options (default map[]) - --tmpfs value Mount a tmpfs directory (default []) - -t, --tty Allocate a pseudo-TTY - --ulimit value Ulimit options (default []) - -u, --user string Username or UID (format: [:]) - --userns string User namespace to use - 'host': Use the Docker host user namespace - '': Use the Docker daemon user namespace specified by `--userns-remap` option. - --uts string UTS namespace to use - -v, --volume value Bind mount a volume (default []). The format - is `[host-src:]container-dest[:]`. - The comma-delimited `options` are [rw|ro], - [z|Z], [[r]shared|[r]slave|[r]private], and - [nocopy]. The 'host-src' is an absolute path - or a name value. - --volume-driver string Optional volume driver for the container - --volumes-from value Mount volumes from the specified container(s) (default []) - -w, --workdir string Working directory inside the container -``` - -The `docker run` command first `creates` a writeable container layer over the -specified image, and then `starts` it using the specified command. That is, -`docker run` is equivalent to the API `/containers/create` then -`/containers/(id)/start`. A stopped container can be restarted with all its -previous changes intact using `docker start`. See `docker ps -a` to view a list -of all containers. - -The `docker run` command can be used in combination with `docker commit` to -[*change the command that a container runs*](commit.md). There is additional detailed information about `docker run` in the [Docker run reference](../run.md). - -For information on connecting a container to a network, see the ["*Docker network overview*"](https://docs.docker.com/engine/userguide/networking/). - -## Examples - -### Assign name and allocate pseudo-TTY (--name, -it) - - $ docker run --name test -it debian - root@d6c0fe130dba:/# exit 13 - $ echo $? - 13 - $ docker ps -a | grep test - d6c0fe130dba debian:7 "/bin/bash" 26 seconds ago Exited (13) 17 seconds ago test - -This example runs a container named `test` using the `debian:latest` -image. The `-it` instructs Docker to allocate a pseudo-TTY connected to -the container's stdin; creating an interactive `bash` shell in the container. -In the example, the `bash` shell is quit by entering -`exit 13`. This exit code is passed on to the caller of -`docker run`, and is recorded in the `test` container's metadata. - -### Capture container ID (--cidfile) - - $ docker run --cidfile /tmp/docker_test.cid ubuntu echo "test" - -This will create a container and print `test` to the console. The `cidfile` -flag makes Docker attempt to create a new file and write the container ID to it. -If the file exists already, Docker will return an error. Docker will close this -file when `docker run` exits. - -### Full container capabilities (--privileged) - - $ docker run -t -i --rm ubuntu bash - root@bc338942ef20:/# mount -t tmpfs none /mnt - mount: permission denied - -This will *not* work, because by default, most potentially dangerous kernel -capabilities are dropped; including `cap_sys_admin` (which is required to mount -filesystems). However, the `--privileged` flag will allow it to run: - - $ docker run -t -i --privileged ubuntu bash - root@50e3f57e16e6:/# mount -t tmpfs none /mnt - root@50e3f57e16e6:/# df -h - Filesystem Size Used Avail Use% Mounted on - none 1.9G 0 1.9G 0% /mnt - -The `--privileged` flag gives *all* capabilities to the container, and it also -lifts all the limitations enforced by the `device` cgroup controller. In other -words, the container can then do almost everything that the host can do. This -flag exists to allow special use-cases, like running Docker within Docker. - -### Set working directory (-w) - - $ docker run -w /path/to/dir/ -i -t ubuntu pwd - -The `-w` lets the command being executed inside directory given, here -`/path/to/dir/`. If the path does not exist it is created inside the container. - -### Set storage driver options per container - - $ docker run -it --storage-opt size=120G fedora /bin/bash - -This (size) will allow to set the container rootfs size to 120G at creation time. -This option is only available for the `devicemapper`, `btrfs`, `overlay2`, -`windowsfilter` and `zfs` graph drivers. -For the `devicemapper`, `btrfs`, `windowsfilter` and `zfs` graph drivers, -user cannot pass a size less than the Default BaseFS Size. -For the `overlay2` storage driver, the size option is only available if the -backing fs is `xfs` and mounted with the `pquota` mount option. -Under these conditions, user can pass any size less then the backing fs size. - -### Mount tmpfs (--tmpfs) - - $ docker run -d --tmpfs /run:rw,noexec,nosuid,size=65536k my_image - -The `--tmpfs` flag mounts an empty tmpfs into the container with the `rw`, -`noexec`, `nosuid`, `size=65536k` options. - -### Mount volume (-v, --read-only) - - $ docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd - -The `-v` flag mounts the current working directory into the container. The `-w` -lets the command being executed inside the current working directory, by -changing into the directory to the value returned by `pwd`. So this -combination executes the command using the container, but inside the -current working directory. - - $ docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash - -When the host directory of a bind-mounted volume doesn't exist, Docker -will automatically create this directory on the host for you. In the -example above, Docker will create the `/doesnt/exist` -folder before starting your container. - - $ docker run --read-only -v /icanwrite busybox touch /icanwrite/here - -Volumes can be used in combination with `--read-only` to control where -a container writes files. The `--read-only` flag mounts the container's root -filesystem as read only prohibiting writes to locations other than the -specified volumes for the container. - - $ docker run -t -i -v /var/run/docker.sock:/var/run/docker.sock -v /path/to/static-docker-binary:/usr/bin/docker busybox sh - -By bind-mounting the docker unix socket and statically linked docker -binary (refer to [get the linux binary]( -https://docs.docker.com/engine/installation/binaries/#/get-the-linux-binary)), -you give the container the full access to create and manipulate the host's -Docker daemon. - -On Windows, the paths must be specified using Windows-style semantics. - - PS C:\> docker run -v c:\foo:c:\dest microsoft/nanoserver cmd /s /c type c:\dest\somefile.txt - Contents of file - - PS C:\> docker run -v c:\foo:d: microsoft/nanoserver cmd /s /c type d:\somefile.txt - Contents of file - -The following examples will fail when using Windows-based containers, as the -destination of a volume or bind-mount inside the container must be one of: -a non-existing or empty directory; or a drive other than C:. Further, the source -of a bind mount must be a local directory, not a file. - - net use z: \\remotemachine\share - docker run -v z:\foo:c:\dest ... - docker run -v \\uncpath\to\directory:c:\dest ... - docker run -v c:\foo\somefile.txt:c:\dest ... - docker run -v c:\foo:c: ... - docker run -v c:\foo:c:\existing-directory-with-contents ... - -For in-depth information about volumes, refer to [manage data in containers](https://docs.docker.com/engine/tutorials/dockervolumes/) - -### Publish or expose port (-p, --expose) - - $ docker run -p 127.0.0.1:80:8080 ubuntu bash - -This binds port `8080` of the container to port `80` on `127.0.0.1` of the host -machine. The [Docker User -Guide](https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/) -explains in detail how to manipulate ports in Docker. - - $ docker run --expose 80 ubuntu bash - -This exposes port `80` of the container without publishing the port to the host -system's interfaces. - -### Set environment variables (-e, --env, --env-file) - - $ docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash - -This sets simple (non-array) environmental variables in the container. For -illustration all three -flags are shown here. Where `-e`, `--env` take an environment variable and -value, or if no `=` is provided, then that variable's current value, set via -`export`, is passed through (i.e. `$MYVAR1` from the host is set to `$MYVAR1` -in the container). When no `=` is provided and that variable is not defined -in the client's environment then that variable will be removed from the -container's list of environment variables. All three flags, `-e`, `--env` and -`--env-file` can be repeated. - -Regardless of the order of these three flags, the `--env-file` are processed -first, and then `-e`, `--env` flags. This way, the `-e` or `--env` will -override variables as needed. - - $ cat ./env.list - TEST_FOO=BAR - $ docker run --env TEST_FOO="This is a test" --env-file ./env.list busybox env | grep TEST_FOO - TEST_FOO=This is a test - -The `--env-file` flag takes a filename as an argument and expects each line -to be in the `VAR=VAL` format, mimicking the argument passed to `--env`. Comment -lines need only be prefixed with `#` - -An example of a file passed with `--env-file` - - $ cat ./env.list - TEST_FOO=BAR - - # this is a comment - TEST_APP_DEST_HOST=10.10.0.127 - TEST_APP_DEST_PORT=8888 - _TEST_BAR=FOO - TEST_APP_42=magic - helloWorld=true - 123qwe=bar - org.spring.config=something - - # pass through this variable from the caller - TEST_PASSTHROUGH - $ TEST_PASSTHROUGH=howdy docker run --env-file ./env.list busybox env - PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - HOSTNAME=5198e0745561 - TEST_FOO=BAR - TEST_APP_DEST_HOST=10.10.0.127 - TEST_APP_DEST_PORT=8888 - _TEST_BAR=FOO - TEST_APP_42=magic - helloWorld=true - TEST_PASSTHROUGH=howdy - HOME=/root - 123qwe=bar - org.spring.config=something - - $ docker run --env-file ./env.list busybox env - PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - HOSTNAME=5198e0745561 - TEST_FOO=BAR - TEST_APP_DEST_HOST=10.10.0.127 - TEST_APP_DEST_PORT=8888 - _TEST_BAR=FOO - TEST_APP_42=magic - helloWorld=true - TEST_PASSTHROUGH= - HOME=/root - 123qwe=bar - org.spring.config=something - -### Set metadata on container (-l, --label, --label-file) - -A label is a `key=value` pair that applies metadata to a container. To label a container with two labels: - - $ docker run -l my-label --label com.example.foo=bar ubuntu bash - -The `my-label` key doesn't specify a value so the label defaults to an empty -string(`""`). To add multiple labels, repeat the label flag (`-l` or `--label`). - -The `key=value` must be unique to avoid overwriting the label value. If you -specify labels with identical keys but different values, each subsequent value -overwrites the previous. Docker uses the last `key=value` you supply. - -Use the `--label-file` flag to load multiple labels from a file. Delimit each -label in the file with an EOL mark. The example below loads labels from a -labels file in the current directory: - - $ docker run --label-file ./labels ubuntu bash - -The label-file format is similar to the format for loading environment -variables. (Unlike environment variables, labels are not visible to processes -running inside a container.) The following example illustrates a label-file -format: - - com.example.label1="a label" - - # this is a comment - com.example.label2=another\ label - com.example.label3 - -You can load multiple label-files by supplying multiple `--label-file` flags. - -For additional information on working with labels, see [*Labels - custom -metadata in Docker*](https://docs.docker.com/engine/userguide/labels-custom-metadata/) in the Docker User -Guide. - -### Connect a container to a network (--network) - -When you start a container use the `--network` flag to connect it to a network. -This adds the `busybox` container to the `my-net` network. - -```bash -$ docker run -itd --network=my-net busybox -``` - -You can also choose the IP addresses for the container with `--ip` and `--ip6` -flags when you start the container on a user-defined network. - -```bash -$ docker run -itd --network=my-net --ip=10.10.9.75 busybox -``` - -If you want to add a running container to a network use the `docker network connect` subcommand. - -You can connect multiple containers to the same network. Once connected, the -containers can communicate easily need only another container's IP address -or name. For `overlay` networks or custom plugins that support multi-host -connectivity, containers connected to the same multi-host network but launched -from different Engines can also communicate in this way. - -**Note**: Service discovery is unavailable on the default bridge network. -Containers can communicate via their IP addresses by default. To communicate -by name, they must be linked. - -You can disconnect a container from a network using the `docker network -disconnect` command. - -### Mount volumes from container (--volumes-from) - - $ docker run --volumes-from 777f7dc92da7 --volumes-from ba8c0c54f0f2:ro -i -t ubuntu pwd - -The `--volumes-from` flag mounts all the defined volumes from the referenced -containers. Containers can be specified by repetitions of the `--volumes-from` -argument. The container ID may be optionally suffixed with `:ro` or `:rw` to -mount the volumes in read-only or read-write mode, respectively. By default, -the volumes are mounted in the same mode (read write or read only) as -the reference container. - -Labeling systems like SELinux require that proper labels are placed on volume -content mounted into a container. Without a label, the security system might -prevent the processes running inside the container from using the content. By -default, Docker does not change the labels set by the OS. - -To change the label in the container context, you can add either of two suffixes -`:z` or `:Z` to the volume mount. These suffixes tell Docker to relabel file -objects on the shared volumes. The `z` option tells Docker that two containers -share the volume content. As a result, Docker labels the content with a shared -content label. Shared volume labels allow all containers to read/write content. -The `Z` option tells Docker to label the content with a private unshared label. -Only the current container can use a private volume. - -### Attach to STDIN/STDOUT/STDERR (-a) - -The `-a` flag tells `docker run` to bind to the container's `STDIN`, `STDOUT` -or `STDERR`. This makes it possible to manipulate the output and input as -needed. - - $ echo "test" | docker run -i -a stdin ubuntu cat - - -This pipes data into a container and prints the container's ID by attaching -only to the container's `STDIN`. - - $ docker run -a stderr ubuntu echo test - -This isn't going to print anything unless there's an error because we've -only attached to the `STDERR` of the container. The container's logs -still store what's been written to `STDERR` and `STDOUT`. - - $ cat somefile | docker run -i -a stdin mybuilder dobuild - -This is how piping a file into a container could be done for a build. -The container's ID will be printed after the build is done and the build -logs could be retrieved using `docker logs`. This is -useful if you need to pipe a file or something else into a container and -retrieve the container's ID once the container has finished running. - -### Add host device to container (--device) - - $ docker run --device=/dev/sdc:/dev/xvdc --device=/dev/sdd --device=/dev/zero:/dev/nulo -i -t ubuntu ls -l /dev/{xvdc,sdd,nulo} - brw-rw---- 1 root disk 8, 2 Feb 9 16:05 /dev/xvdc - brw-rw---- 1 root disk 8, 3 Feb 9 16:05 /dev/sdd - crw-rw-rw- 1 root root 1, 5 Feb 9 16:05 /dev/nulo - -It is often necessary to directly expose devices to a container. The `--device` -option enables that. For example, a specific block storage device or loop -device or audio device can be added to an otherwise unprivileged container -(without the `--privileged` flag) and have the application directly access it. - -By default, the container will be able to `read`, `write` and `mknod` these devices. -This can be overridden using a third `:rwm` set of options to each `--device` -flag: - - - $ docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc - - Command (m for help): q - $ docker run --device=/dev/sda:/dev/xvdc:r --rm -it ubuntu fdisk /dev/xvdc - You will not be able to write the partition table. - - Command (m for help): q - - $ docker run --device=/dev/sda:/dev/xvdc:rw --rm -it ubuntu fdisk /dev/xvdc - - Command (m for help): q - - $ docker run --device=/dev/sda:/dev/xvdc:m --rm -it ubuntu fdisk /dev/xvdc - fdisk: unable to open /dev/xvdc: Operation not permitted - -> **Note:** -> `--device` cannot be safely used with ephemeral devices. Block devices -> that may be removed should not be added to untrusted containers with -> `--device`. - -### Restart policies (--restart) - -Use Docker's `--restart` to specify a container's *restart policy*. A restart -policy controls whether the Docker daemon restarts a container after exit. -Docker supports the following restart policies: - - - - - - - - - - - - - - - - - - - - - - - - - - -
PolicyResult
no - Do not automatically restart the container when it exits. This is the - default. -
- - on-failure[:max-retries] - - - Restart only if the container exits with a non-zero exit status. - Optionally, limit the number of restart retries the Docker - daemon attempts. -
always - Always restart the container regardless of the exit status. - When you specify always, the Docker daemon will try to restart - the container indefinitely. The container will also always start - on daemon startup, regardless of the current state of the container. -
unless-stopped - Always restart the container regardless of the exit status, but - do not start it on daemon startup if the container has been put - to a stopped state before. -
- - $ docker run --restart=always redis - -This will run the `redis` container with a restart policy of **always** -so that if the container exits, Docker will restart it. - -More detailed information on restart policies can be found in the -[Restart Policies (--restart)](../run.md#restart-policies-restart) -section of the Docker run reference page. - -### Add entries to container hosts file (--add-host) - -You can add other hosts into a container's `/etc/hosts` file by using one or -more `--add-host` flags. This example adds a static address for a host named -`docker`: - - $ docker run --add-host=docker:10.180.0.1 --rm -it debian - root@f38c87f2a42d:/# ping docker - PING docker (10.180.0.1): 48 data bytes - 56 bytes from 10.180.0.1: icmp_seq=0 ttl=254 time=7.600 ms - 56 bytes from 10.180.0.1: icmp_seq=1 ttl=254 time=30.705 ms - ^C--- docker ping statistics --- - 2 packets transmitted, 2 packets received, 0% packet loss - round-trip min/avg/max/stddev = 7.600/19.152/30.705/11.553 ms - -Sometimes you need to connect to the Docker host from within your -container. To enable this, pass the Docker host's IP address to -the container using the `--add-host` flag. To find the host's address, -use the `ip addr show` command. - -The flags you pass to `ip addr show` depend on whether you are -using IPv4 or IPv6 networking in your containers. Use the following -flags for IPv4 address retrieval for a network device named `eth0`: - - $ HOSTIP=`ip -4 addr show scope global dev eth0 | grep inet | awk '{print \$2}' | cut -d / -f 1` - $ docker run --add-host=docker:${HOSTIP} --rm -it debian - -For IPv6 use the `-6` flag instead of the `-4` flag. For other network -devices, replace `eth0` with the correct device name (for example `docker0` -for the bridge device). - -### Set ulimits in container (--ulimit) - -Since setting `ulimit` settings in a container requires extra privileges not -available in the default container, you can set these using the `--ulimit` flag. -`--ulimit` is specified with a soft and hard limit as such: -`=[:]`, for example: - - $ docker run --ulimit nofile=1024:1024 --rm debian sh -c "ulimit -n" - 1024 - -> **Note:** -> If you do not provide a `hard limit`, the `soft limit` will be used -> for both values. If no `ulimits` are set, they will be inherited from -> the default `ulimits` set on the daemon. `as` option is disabled now. -> In other words, the following script is not supported: -> `$ docker run -it --ulimit as=1024 fedora /bin/bash` - -The values are sent to the appropriate `syscall` as they are set. -Docker doesn't perform any byte conversion. Take this into account when setting the values. - -#### For `nproc` usage - -Be careful setting `nproc` with the `ulimit` flag as `nproc` is designed by Linux to set the -maximum number of processes available to a user, not to a container. For example, start four -containers with `daemon` user: - - docker run -d -u daemon --ulimit nproc=3 busybox top - docker run -d -u daemon --ulimit nproc=3 busybox top - docker run -d -u daemon --ulimit nproc=3 busybox top - docker run -d -u daemon --ulimit nproc=3 busybox top - -The 4th container fails and reports "[8] System error: resource temporarily unavailable" error. -This fails because the caller set `nproc=3` resulting in the first three containers using up -the three processes quota set for the `daemon` user. - -### Stop container with signal (--stop-signal) - -The `--stop-signal` flag sets the system call signal that will be sent to the container to exit. -This signal can be a valid unsigned number that matches a position in the kernel's syscall table, for instance 9, -or a signal name in the format SIGNAME, for instance SIGKILL. - -### Optional security options (--security-opt) - -On Windows, this flag can be used to specify the `credentialspec` option. -The `credentialspec` must be in the format `file://spec.txt` or `registry://keyname`. - -### Stop container with timeout (--stop-timeout) - -The `--stop-timeout` flag sets the timeout (in seconds) that a pre-defined (see `--stop-signal`) system call -signal that will be sent to the container to exit. After timeout elapses the container will be killed with SIGKILL. - -### Specify isolation technology for container (--isolation) - -This option is useful in situations where you are running Docker containers on -Microsoft Windows. The `--isolation ` option sets a container's isolation -technology. On Linux, the only supported is the `default` option which uses -Linux namespaces. These two commands are equivalent on Linux: - -``` -$ docker run -d busybox top -$ docker run -d --isolation default busybox top -``` - -On Microsoft Windows, can take any of these values: - - -| Value | Description | -|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `default` | Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value. | -| `process` | Namespace isolation only. | -| `hyperv` | Hyper-V hypervisor partition-based isolation. | - -On Windows, the default isolation for client is `hyperv`, and for server is -`process`. Therefore when running on Windows server without a `daemon` option -set, these two commands are equivalent: -``` -$ docker run -d --isolation default busybox top -$ docker run -d --isolation process busybox top -``` - -If you have set the `--exec-opt isolation=hyperv` option on the Docker `daemon`, -if running on Windows server, any of these commands also result in `hyperv` isolation: - -``` -$ docker run -d --isolation default busybox top -$ docker run -d --isolation hyperv busybox top -``` - -### Configure namespaced kernel parameters (sysctls) at runtime - -The `--sysctl` sets namespaced kernel parameters (sysctls) in the -container. For example, to turn on IP forwarding in the containers -network namespace, run this command: - - $ docker run --sysctl net.ipv4.ip_forward=1 someimage - - -> **Note**: Not all sysctls are namespaced. Docker does not support changing sysctls -> inside of a container that also modify the host system. As the kernel -> evolves we expect to see more sysctls become namespaced. - -#### Currently supported sysctls - - `IPC Namespace`: - - kernel.msgmax, kernel.msgmnb, kernel.msgmni, kernel.sem, kernel.shmall, kernel.shmmax, kernel.shmmni, kernel.shm_rmid_forced - Sysctls beginning with fs.mqueue.* - - If you use the `--ipc=host` option these sysctls will not be allowed. - - `Network Namespace`: - Sysctls beginning with net.* - - If you use the `--network=host` option using these sysctls will not be allowed. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/save.md b/vendor/github.com/docker/docker/docs/reference/commandline/save.md deleted file mode 100644 index 88a5fed..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/save.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: "save" -description: "The save command description and usage" -keywords: "tarred, repository, backup" ---- - - - -# save - -```markdown -Usage: docker save [OPTIONS] IMAGE [IMAGE...] - -Save one or more images to a tar archive (streamed to STDOUT by default) - -Options: - --help Print usage - -o, --output string Write to a file, instead of STDOUT -``` - -Produces a tarred repository to the standard output stream. -Contains all parent layers, and all tags + versions, or specified `repo:tag`, for -each argument provided. - -It is used to create a backup that can then be used with `docker load` - - $ docker save busybox > busybox.tar - $ ls -sh busybox.tar - 2.7M busybox.tar - $ docker save --output busybox.tar busybox - $ ls -sh busybox.tar - 2.7M busybox.tar - $ docker save -o fedora-all.tar fedora - $ docker save -o fedora-latest.tar fedora:latest - -It is even useful to cherry-pick particular tags of an image repository - - $ docker save -o ubuntu.tar ubuntu:lucid ubuntu:saucy diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/search.md b/vendor/github.com/docker/docker/docs/reference/commandline/search.md deleted file mode 100644 index 31faf37..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/search.md +++ /dev/null @@ -1,134 +0,0 @@ ---- -title: "search" -description: "The search command description and usage" -keywords: "search, hub, images" ---- - - - -# search - -```markdown -Usage: docker search [OPTIONS] TERM - -Search the Docker Hub for images - -Options: - -f, --filter value Filter output based on conditions provided (default []) - - is-automated=(true|false) - - is-official=(true|false) - - stars= - image has at least 'number' stars - --help Print usage - --limit int Max number of search results (default 25) - --no-trunc Don't truncate output -``` - -Search [Docker Hub](https://hub.docker.com) for images - -See [*Find Public Images on Docker Hub*](https://docs.docker.com/engine/tutorials/dockerrepos/#searching-for-images) for -more details on finding shared images from the command line. - -> **Note:** -> Search queries will only return up to 25 results - -## Examples - -### Search images by name - -This example displays images with a name containing 'busybox': - - $ docker search busybox - NAME DESCRIPTION STARS OFFICIAL AUTOMATED - busybox Busybox base image. 316 [OK] - progrium/busybox 50 [OK] - radial/busyboxplus Full-chain, Internet enabled, busybox made... 8 [OK] - odise/busybox-python 2 [OK] - azukiapp/busybox This image is meant to be used as the base... 2 [OK] - ofayau/busybox-jvm Prepare busybox to install a 32 bits JVM. 1 [OK] - shingonoide/archlinux-busybox Arch Linux, a lightweight and flexible Lin... 1 [OK] - odise/busybox-curl 1 [OK] - ofayau/busybox-libc32 Busybox with 32 bits (and 64 bits) libs 1 [OK] - peelsky/zulu-openjdk-busybox 1 [OK] - skomma/busybox-data Docker image suitable for data volume cont... 1 [OK] - elektritter/busybox-teamspeak Lightweight teamspeak3 container based on... 1 [OK] - socketplane/busybox 1 [OK] - oveits/docker-nginx-busybox This is a tiny NginX docker image based on... 0 [OK] - ggtools/busybox-ubuntu Busybox ubuntu version with extra goodies 0 [OK] - nikfoundas/busybox-confd Minimal busybox based distribution of confd 0 [OK] - openshift/busybox-http-app 0 [OK] - jllopis/busybox 0 [OK] - swyckoff/busybox 0 [OK] - powellquiring/busybox 0 [OK] - williamyeh/busybox-sh Docker image for BusyBox's sh 0 [OK] - simplexsys/busybox-cli-powered Docker busybox images, with a few often us... 0 [OK] - fhisamoto/busybox-java Busybox java 0 [OK] - scottabernethy/busybox 0 [OK] - marclop/busybox-solr - -### Display non-truncated description (--no-trunc) - -This example displays images with a name containing 'busybox', -at least 3 stars and the description isn't truncated in the output: - - $ docker search --stars=3 --no-trunc busybox - NAME DESCRIPTION STARS OFFICIAL AUTOMATED - busybox Busybox base image. 325 [OK] - progrium/busybox 50 [OK] - radial/busyboxplus Full-chain, Internet enabled, busybox made from scratch. Comes in git and cURL flavors. 8 [OK] - -## Limit search results (--limit) - -The flag `--limit` is the maximum number of results returned by a search. This value could -be in the range between 1 and 100. The default value of `--limit` is 25. - - -## Filtering - -The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there is more -than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`) - -The currently supported filters are: - -* stars (int - number of stars the image has) -* is-automated (true|false) - is the image automated or not -* is-official (true|false) - is the image official or not - - -### stars - -This example displays images with a name containing 'busybox' and at -least 3 stars: - - $ docker search --filter stars=3 busybox - NAME DESCRIPTION STARS OFFICIAL AUTOMATED - busybox Busybox base image. 325 [OK] - progrium/busybox 50 [OK] - radial/busyboxplus Full-chain, Internet enabled, busybox made... 8 [OK] - - -### is-automated - -This example displays images with a name containing 'busybox' -and are automated builds: - - $ docker search --filter is-automated busybox - NAME DESCRIPTION STARS OFFICIAL AUTOMATED - progrium/busybox 50 [OK] - radial/busyboxplus Full-chain, Internet enabled, busybox made... 8 [OK] - -### is-official - -This example displays images with a name containing 'busybox', at least -3 stars and are official builds: - - $ docker search --filter "is-official=true" --filter "stars=3" busybox - NAME DESCRIPTION STARS OFFICIAL AUTOMATED - progrium/busybox 50 [OK] - radial/busyboxplus Full-chain, Internet enabled, busybox made... 8 [OK] diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/secret_create.md b/vendor/github.com/docker/docker/docs/reference/commandline/secret_create.md deleted file mode 100644 index aebcebb..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/secret_create.md +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: "secret create" -description: "The secret create command description and usage" -keywords: ["secret, create"] ---- - - - -# secret create - -```Markdown -Usage: docker secret create [OPTIONS] SECRET file|- - -Create a secret from a file or STDIN as content - -Options: - --help Print usage - -l, --label list Secret labels (default []) -``` - -Creates a secret using standard input or from a file for the secret content. You must run this -command on a manager node. - -## Examples - -### Create a secret - -```bash -$ echo | docker secret create my_secret - -mhv17xfe3gh6xc4rij5orpfds - -$ docker secret ls -ID NAME CREATED UPDATED SIZE -mhv17xfe3gh6xc4rij5orpfds my_secret 2016-10-27 23:25:43.909181089 +0000 UTC 2016-10-27 23:25:43.909181089 +0000 UTC 1679 -``` - -### Create a secret with a file - -```bash -$ docker secret create my_secret ./secret.json -mhv17xfe3gh6xc4rij5orpfds - -$ docker secret ls -ID NAME CREATED UPDATED SIZE -mhv17xfe3gh6xc4rij5orpfds my_secret 2016-10-27 23:25:43.909181089 +0000 UTC 2016-10-27 23:25:43.909181089 +0000 UTC 1679 -``` - -### Create a secret with labels - -```bash -$ docker secret create --label env=dev --label rev=20161102 my_secret ./secret.json -jtn7g6aukl5ky7nr9gvwafoxh - -$ docker secret inspect my_secret -[ - { - "ID": "jtn7g6aukl5ky7nr9gvwafoxh", - "Version": { - "Index": 541 - }, - "CreatedAt": "2016-11-03T20:54:12.924766548Z", - "UpdatedAt": "2016-11-03T20:54:12.924766548Z", - "Spec": { - "Name": "my_secret", - "Labels": { - "env": "dev", - "rev": "20161102" - }, - "Data": null - }, - "Digest": "sha256:4212a44b14e94154359569333d3fc6a80f6b9959dfdaff26412f4b2796b1f387", - "SecretSize": 1679 - } -] - -``` - - -## Related information - -* [secret inspect](secret_inspect.md) -* [secret ls](secret_ls.md) -* [secret rm](secret_rm.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/secret_inspect.md b/vendor/github.com/docker/docker/docs/reference/commandline/secret_inspect.md deleted file mode 100644 index de878f7..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/secret_inspect.md +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: "secret inspect" -description: "The secret inspect command description and usage" -keywords: ["secret, inspect"] ---- - - - -# secret inspect - -```Markdown -Usage: docker secret inspect [OPTIONS] SECRET [SECRET...] - -Display detailed information on one or more secrets - -Options: - -f, --format string Format the output using the given Go template - --help Print usage -``` - - -Inspects the specified secret. This command has to be run targeting a manager -node. - -By default, this renders all results in a JSON array. If a format is specified, -the given template will be executed for each result. - -Go's [text/template](http://golang.org/pkg/text/template/) package -describes all the details of the format. - -## Examples - -### Inspecting a secret by name or ID - -You can inspect a secret, either by its *name*, or *ID* - -For example, given the following secret: - -```bash -$ docker secret ls -ID NAME CREATED UPDATED -mhv17xfe3gh6xc4rij5orpfds secret.json 2016-10-27 23:25:43.909181089 +0000 UTC 2016-10-27 23:25:43.909181089 +0000 UTC -``` - -```bash -$ docker secret inspect secret.json -[ - { - "ID": "mhv17xfe3gh6xc4rij5orpfds", - "Version": { - "Index": 1198 - }, - "CreatedAt": "2016-10-27T23:25:43.909181089Z", - "UpdatedAt": "2016-10-27T23:25:43.909181089Z", - "Spec": { - "Name": "secret.json" - } - } -] -``` - -### Formatting secret output - -You can use the --format option to obtain specific information about a -secret. The following example command outputs the creation time of the -secret. - -```bash{% raw %} -$ docker secret inspect --format='{{.CreatedAt}}' mhv17xfe3gh6xc4rij5orpfds -2016-10-27 23:25:43.909181089 +0000 UTC -{% endraw %}``` - - -## Related information - -* [secret create](secret_create.md) -* [secret ls](secret_ls.md) -* [secret rm](secret_rm.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/secret_ls.md b/vendor/github.com/docker/docker/docs/reference/commandline/secret_ls.md deleted file mode 100644 index 6b34fc2..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/secret_ls.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: "secret ls" -description: "The secret ls command description and usage" -keywords: ["secret, ls"] ---- - - - -# secret ls - -```Markdown -Usage: docker secret ls [OPTIONS] - -List secrets - -Aliases: - ls, list - -Options: - -q, --quiet Only display IDs -``` - -Run this command on a manager node to list the secrets in the Swarm. - -## Examples - -```bash -$ docker secret ls -ID NAME CREATED UPDATED -mhv17xfe3gh6xc4rij5orpfds secret.json 2016-10-27 23:25:43.909181089 +0000 UTC 2016-10-27 23:25:43.909181089 +0000 UTC -``` -## Related information - -* [secret create](secret_create.md) -* [secret inspect](secret_inspect.md) -* [secret rm](secret_rm.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/secret_rm.md b/vendor/github.com/docker/docker/docs/reference/commandline/secret_rm.md deleted file mode 100644 index f504b1b..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/secret_rm.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "secret rm" -description: "The secret rm command description and usage" -keywords: ["secret, rm"] ---- - - - -# secret rm - -```Markdown -Usage: docker secret rm SECRET [SECRET...] - -Remove one or more secrets - -Aliases: - rm, remove - -Options: - --help Print usage -``` - -Removes the specified secrets from the swarm. This command has to be run -targeting a manager node. - -This example removes a secret: - -```bash -$ docker secret rm secret.json -sapth4csdo5b6wz2p5uimh5xg -``` - -> **Warning**: Unlike `docker rm`, this command does not ask for confirmation -> before removing a secret. - - -## Related information - -* [secret create](secret_create.md) -* [secret inspect](secret_inspect.md) -* [secret ls](secret_ls.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/service_create.md b/vendor/github.com/docker/docker/docs/reference/commandline/service_create.md deleted file mode 100644 index c9e2980..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/service_create.md +++ /dev/null @@ -1,556 +0,0 @@ ---- -title: "service create" -description: "The service create command description and usage" -keywords: "service, create" ---- - - - -# service create - -```Markdown -Usage: docker service create [OPTIONS] IMAGE [COMMAND] [ARG...] - -Create a new service - -Options: - --constraint list Placement constraints (default []) - --container-label list Container labels (default []) - --dns list Set custom DNS servers (default []) - --dns-option list Set DNS options (default []) - --dns-search list Set custom DNS search domains (default []) - --endpoint-mode string Endpoint mode (vip or dnsrr) - -e, --env list Set environment variables (default []) - --env-file list Read in a file of environment variables (default []) - --group list Set one or more supplementary user groups for the container (default []) - --health-cmd string Command to run to check health - --health-interval duration Time between running the check (ns|us|ms|s|m|h) - --health-retries int Consecutive failures needed to report unhealthy - --health-timeout duration Maximum time to allow one check to run (ns|us|ms|s|m|h) - --help Print usage - --host list Set one or more custom host-to-IP mappings (host:ip) (default []) - --hostname string Container hostname - -l, --label list Service labels (default []) - --limit-cpu decimal Limit CPUs (default 0.000) - --limit-memory bytes Limit Memory (default 0 B) - --log-driver string Logging driver for service - --log-opt list Logging driver options (default []) - --mode string Service mode (replicated or global) (default "replicated") - --mount mount Attach a filesystem mount to the service - --name string Service name - --network list Network attachments (default []) - --no-healthcheck Disable any container-specified HEALTHCHECK - -p, --publish port Publish a port as a node port - --replicas uint Number of tasks - --reserve-cpu decimal Reserve CPUs (default 0.000) - --reserve-memory bytes Reserve Memory (default 0 B) - --restart-condition string Restart when condition is met (none, on-failure, or any) - --restart-delay duration Delay between restart attempts (ns|us|ms|s|m|h) - --restart-max-attempts uint Maximum number of restarts before giving up - --restart-window duration Window used to evaluate the restart policy (ns|us|ms|s|m|h) - --secret secret Specify secrets to expose to the service - --stop-grace-period duration Time to wait before force killing a container (ns|us|ms|s|m|h) - -t, --tty Allocate a pseudo-TTY - --update-delay duration Delay between updates (ns|us|ms|s|m|h) (default 0s) - --update-failure-action string Action on update failure (pause|continue) (default "pause") - --update-max-failure-ratio float Failure rate to tolerate during an update - --update-monitor duration Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s) - --update-parallelism uint Maximum number of tasks updated simultaneously (0 to update all at once) (default 1) - -u, --user string Username or UID (format: [:]) - --with-registry-auth Send registry authentication details to swarm agents - -w, --workdir string Working directory inside the container -``` - -Creates a service as described by the specified parameters. You must run this -command on a manager node. - -## Examples - -### Create a service - -```bash -$ docker service create --name redis redis:3.0.6 -dmu1ept4cxcfe8k8lhtux3ro3 - -$ docker service create --mode global --name redis2 redis:3.0.6 -a8q9dasaafudfs8q8w32udass - -$ docker service ls -ID NAME MODE REPLICAS IMAGE -dmu1ept4cxcf redis replicated 1/1 redis:3.0.6 -a8q9dasaafud redis2 global 1/1 redis:3.0.6 -``` - -### Create a service with 5 replica tasks (--replicas) - -Use the `--replicas` flag to set the number of replica tasks for a replicated -service. The following command creates a `redis` service with `5` replica tasks: - -```bash -$ docker service create --name redis --replicas=5 redis:3.0.6 -4cdgfyky7ozwh3htjfw0d12qv -``` - -The above command sets the *desired* number of tasks for the service. Even -though the command returns immediately, actual scaling of the service may take -some time. The `REPLICAS` column shows both the *actual* and *desired* number -of replica tasks for the service. - -In the following example the desired state is `5` replicas, but the current -number of `RUNNING` tasks is `3`: - -```bash -$ docker service ls -ID NAME MODE REPLICAS IMAGE -4cdgfyky7ozw redis replicated 3/5 redis:3.0.7 -``` - -Once all the tasks are created and `RUNNING`, the actual number of tasks is -equal to the desired number: - -```bash -$ docker service ls -ID NAME MODE REPLICAS IMAGE -4cdgfyky7ozw redis replicated 5/5 redis:3.0.7 -``` - -### Create a service with secrets -Use the `--secret` flag to give a container access to a -[secret](secret_create.md). - -Create a service specifying a secret: - -```bash -$ docker service create --name redis --secret secret.json redis:3.0.6 -4cdgfyky7ozwh3htjfw0d12qv -``` - -Create a service specifying the secret, target, user/group ID and mode: - -```bash -$ docker service create --name redis \ - --secret source=ssh-key,target=ssh \ - --secret source=app-key,target=app,uid=1000,gid=1001,mode=0400 \ - redis:3.0.6 -4cdgfyky7ozwh3htjfw0d12qv -``` - -Secrets are located in `/run/secrets` in the container. If no target is -specified, the name of the secret will be used as the in memory file in the -container. If a target is specified, that will be the filename. In the -example above, two files will be created: `/run/secrets/ssh` and -`/run/secrets/app` for each of the secret targets specified. - -### Create a service with a rolling update policy - -```bash -$ docker service create \ - --replicas 10 \ - --name redis \ - --update-delay 10s \ - --update-parallelism 2 \ - redis:3.0.6 -``` - -When you run a [service update](service_update.md), the scheduler updates a -maximum of 2 tasks at a time, with `10s` between updates. For more information, -refer to the [rolling updates -tutorial](https://docs.docker.com/engine/swarm/swarm-tutorial/rolling-update/). - -### Set environment variables (-e, --env) - -This sets environmental variables for all tasks in a service. For example: - -```bash -$ docker service create --name redis_2 --replicas 5 --env MYVAR=foo redis:3.0.6 -``` - -### Create a docker service with specific hostname (--hostname) - -This option sets the docker service containers hostname to a specific string. For example: -```bash -$ docker service create --name redis --hostname myredis redis:3.0.6 -``` -### Set metadata on a service (-l, --label) - -A label is a `key=value` pair that applies metadata to a service. To label a -service with two labels: - -```bash -$ docker service create \ - --name redis_2 \ - --label com.example.foo="bar" - --label bar=baz \ - redis:3.0.6 -``` - -For more information about labels, refer to [apply custom -metadata](https://docs.docker.com/engine/userguide/labels-custom-metadata/). - -### Add bind-mounts or volumes - -Docker supports two different kinds of mounts, which allow containers to read to -or write from files or directories on other containers or the host operating -system. These types are _data volumes_ (often referred to simply as volumes) and -_bind-mounts_. - -Additionally, Docker also supports tmpfs mounts. - -A **bind-mount** makes a file or directory on the host available to the -container it is mounted within. A bind-mount may be either read-only or -read-write. For example, a container might share its host's DNS information by -means of a bind-mount of the host's `/etc/resolv.conf` or a container might -write logs to its host's `/var/log/myContainerLogs` directory. If you use -bind-mounts and your host and containers have different notions of permissions, -access controls, or other such details, you will run into portability issues. - -A **named volume** is a mechanism for decoupling persistent data needed by your -container from the image used to create the container and from the host machine. -Named volumes are created and managed by Docker, and a named volume persists -even when no container is currently using it. Data in named volumes can be -shared between a container and the host machine, as well as between multiple -containers. Docker uses a _volume driver_ to create, manage, and mount volumes. -You can back up or restore volumes using Docker commands. - -A **tmpfs** mounts a tmpfs inside a container for volatile data. - -Consider a situation where your image starts a lightweight web server. You could -use that image as a base image, copy in your website's HTML files, and package -that into another image. Each time your website changed, you'd need to update -the new image and redeploy all of the containers serving your website. A better -solution is to store the website in a named volume which is attached to each of -your web server containers when they start. To update the website, you just -update the named volume. - -For more information about named volumes, see -[Data Volumes](https://docs.docker.com/engine/tutorials/dockervolumes/). - -The following table describes options which apply to both bind-mounts and named -volumes in a service: - -| Option | Required | Description -|:-----------------------------------------|:--------------------------|:----------------------------------------------------------------------------------------- -| **type** | | The type of mount, can be either `volume`, `bind`, or `tmpfs`. Defaults to `volume` if no type is specified.
  • `volume`: mounts a [managed volume](volume_create.md) into the container.
  • `bind`: bind-mounts a directory or file from the host into the container.
  • `tmpfs`: mount a tmpfs in the container
-| **src** or **source** | for `type=bind` only |
  • `type=volume`: `src` is an optional way to specify the name of the volume (for example, `src=my-volume`). If the named volume does not exist, it is automatically created. If no `src` is specified, the volume is assigned a random name which is guaranteed to be unique on the host, but may not be unique cluster-wide. A randomly-named volume has the same lifecycle as its container and is destroyed when the *container* is destroyed (which is upon `service update`, or when scaling or re-balancing the service).
  • `type=bind`: `src` is required, and specifies an absolute path to the file or directory to bind-mount (for example, `src=/path/on/host/`). An error is produced if the file or directory does not exist.
  • `type=tmpfs`: `src` is not supported.
-| **dst** or **destination** or **target** | yes | Mount path inside the container, for example `/some/path/in/container/`. If the path does not exist in the container's filesystem, the Engine creates a directory at the specified location before mounting the volume or bind-mount. -| **readonly** or **ro** | | The Engine mounts binds and volumes `read-write` unless `readonly` option is given when mounting the bind or volume.

  • `true` or `1` or no value: Mounts the bind or volume read-only.
  • `false` or `0`: Mounts the bind or volume read-write.
- -#### Bind Propagation - -Bind propagation refers to whether or not mounts created within a given -bind-mount or named volume can be propagated to replicas of that mount. Consider -a mount point `/mnt`, which is also mounted on `/tmp`. The propation settings -control whether a mount on `/tmp/a` would also be available on `/mnt/a`. Each -propagation setting has a recursive counterpoint. In the case of recursion, -consider that `/tmp/a` is also mounted as `/foo`. The propagation settings -control whether `/mnt/a` and/or `/tmp/a` would exist. - -The `bind-propagation` option defaults to `rprivate` for both bind-mounts and -volume mounts, and is only configurable for bind-mounts. In other words, named -volumes do not support bind propagation. - -- **`shared`**: Sub-mounts of the original mount are exposed to replica mounts, - and sub-mounts of replica mounts are also propagated to the - original mount. -- **`slave`**: similar to a shared mount, but only in one direction. If the - original mount exposes a sub-mount, the replica mount can see it. - However, if the replica mount exposes a sub-mount, the original - mount cannot see it. -- **`private`**: The mount is private. Sub-mounts within it are not exposed to - replica mounts, and sub-mounts of replica mounts are not - exposed to the original mount. -- **`rshared`**: The same as shared, but the propagation also extends to and from - mount points nested within any of the original or replica mount - points. -- **`rslave`**: The same as `slave`, but the propagation also extends to and from - mount points nested within any of the original or replica mount - points. -- **`rprivate`**: The default. The same as `private`, meaning that no mount points - anywhere within the original or replica mount points propagate - in either direction. - -For more information about bind propagation, see the -[Linux kernel documentation for shared subtree](https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt). - -#### Options for Named Volumes -The following options can only be used for named volumes (`type=volume`); - -| Option | Description -|:----------------------|:-------------------------------------------------------------------------------------------------------------------- -| **volume-driver** | Name of the volume-driver plugin to use for the volume. Defaults to ``"local"``, to use the local volume driver to create the volume if the volume does not exist. -| **volume-label** | One or more custom metadata ("labels") to apply to the volume upon creation. For example, `volume-label=mylabel=hello-world,my-other-label=hello-mars`. For more information about labels, refer to [apply custom metadata](https://docs.docker.com/engine/userguide/labels-custom-metadata/). -| **volume-nocopy** | By default, if you attach an empty volume to a container, and files or directories already existed at the mount-path in the container (`dst`), the Engine copies those files and directories into the volume, allowing the host to access them. Set `volume-nocopy` to disables copying files from the container's filesystem to the volume and mount the empty volume.

A value is optional:
  • `true` or `1`: Default if you do not provide a value. Disables copying.
  • `false` or `0`: Enables copying.
-| **volume-opt** | Options specific to a given volume driver, which will be passed to the driver when creating the volume. Options are provided as a comma-separated list of key/value pairs, for example, `volume-opt=some-option=some-value,some-other-option=some-other-value`. For available options for a given driver, refer to that driver's documentation. - -#### Options for tmpfs -The following options can only be used for tmpfs mounts (`type=tmpfs`); - -| Option | Description -|:----------------------|:-------------------------------------------------------------------------------------------------------------------- -| **tmpfs-size** | Size of the tmpfs mount in bytes. Unlimited by default in Linux. -| **tmpfs-mode** | File mode of the tmpfs in octal. (e.g. `"700"` or `"0700"`.) Defaults to ``"1777"`` in Linux. - -#### Differences between "--mount" and "--volume" - -The `--mount` flag supports most options that are supported by the `-v` -or `--volume` flag for `docker run`, with some important exceptions: - -- The `--mount` flag allows you to specify a volume driver and volume driver - options *per volume*, without creating the volumes in advance. In contrast, - `docker run` allows you to specify a single volume driver which is shared - by all volumes, using the `--volume-driver` flag. - -- The `--mount` flag allows you to specify custom metadata ("labels") for a volume, - before the volume is created. - -- When you use `--mount` with `type=bind`, the host-path must refer to an *existing* - path on the host. The path will not be created for you and the service will fail - with an error if the path does not exist. - -- The `--mount` flag does not allow you to relabel a volume with `Z` or `z` flags, - which are used for `selinux` labeling. - -#### Create a service using a named volume - -The following example creates a service that uses a named volume: - -```bash -$ docker service create \ - --name my-service \ - --replicas 3 \ - --mount type=volume,source=my-volume,destination=/path/in/container,volume-label="color=red",volume-label="shape=round" \ - nginx:alpine -``` - -For each replica of the service, the engine requests a volume named "my-volume" -from the default ("local") volume driver where the task is deployed. If the -volume does not exist, the engine creates a new volume and applies the "color" -and "shape" labels. - -When the task is started, the volume is mounted on `/path/in/container/` inside -the container. - -Be aware that the default ("local") volume is a locally scoped volume driver. -This means that depending on where a task is deployed, either that task gets a -*new* volume named "my-volume", or shares the same "my-volume" with other tasks -of the same service. Multiple containers writing to a single shared volume can -cause data corruption if the software running inside the container is not -designed to handle concurrent processes writing to the same location. Also take -into account that containers can be re-scheduled by the Swarm orchestrator and -be deployed on a different node. - -#### Create a service that uses an anonymous volume - -The following command creates a service with three replicas with an anonymous -volume on `/path/in/container`: - -```bash -$ docker service create \ - --name my-service \ - --replicas 3 \ - --mount type=volume,destination=/path/in/container \ - nginx:alpine -``` - -In this example, no name (`source`) is specified for the volume, so a new volume -is created for each task. This guarantees that each task gets its own volume, -and volumes are not shared between tasks. Anonymous volumes are removed after -the task using them is complete. - -#### Create a service that uses a bind-mounted host directory - -The following example bind-mounts a host directory at `/path/in/container` in -the containers backing the service: - -```bash -$ docker service create \ - --name my-service \ - --mount type=bind,source=/path/on/host,destination=/path/in/container \ - nginx:alpine -``` - -### Set service mode (--mode) - -The service mode determines whether this is a _replicated_ service or a _global_ -service. A replicated service runs as many tasks as specified, while a global -service runs on each active node in the swarm. - -The following command creates a global service: - -```bash -$ docker service create \ - --name redis_2 \ - --mode global \ - redis:3.0.6 -``` - -### Specify service constraints (--constraint) - -You can limit the set of nodes where a task can be scheduled by defining -constraint expressions. Multiple constraints find nodes that satisfy every -expression (AND match). Constraints can match node or Docker Engine labels as -follows: - -| node attribute | matches | example | -|:----------------|:--------------------------|:------------------------------------------------| -| node.id | node ID | `node.id == 2ivku8v2gvtg4` | -| node.hostname | node hostname | `node.hostname != node-2` | -| node.role | node role: manager | `node.role == manager` | -| node.labels | user defined node labels | `node.labels.security == high` | -| engine.labels | Docker Engine's labels | `engine.labels.operatingsystem == ubuntu 14.04` | - -`engine.labels` apply to Docker Engine labels like operating system, -drivers, etc. Swarm administrators add `node.labels` for operational purposes by -using the [`docker node update`](node_update.md) command. - -For example, the following limits tasks for the redis service to nodes where the -node type label equals queue: - -```bash -$ docker service create \ - --name redis_2 \ - --constraint 'node.labels.type == queue' \ - redis:3.0.6 -``` - -### Attach a service to an existing network (--network) - -You can use overlay networks to connect one or more services within the swarm. - -First, create an overlay network on a manager node the docker network create -command: - -```bash -$ docker network create --driver overlay my-network - -etjpu59cykrptrgw0z0hk5snf -``` - -After you create an overlay network in swarm mode, all manager nodes have -access to the network. - -When you create a service and pass the --network flag to attach the service to -the overlay network: - -```bash -$ docker service create \ - --replicas 3 \ - --network my-network \ - --name my-web \ - nginx - -716thylsndqma81j6kkkb5aus -``` - -The swarm extends my-network to each node running the service. - -Containers on the same network can access each other using -[service discovery](https://docs.docker.com/engine/swarm/networking/#use-swarm-mode-service-discovery). - -### Publish service ports externally to the swarm (-p, --publish) - -You can publish service ports to make them available externally to the swarm -using the `--publish` flag: - -```bash -$ docker service create --publish : nginx -``` - -For example: - -```bash -$ docker service create --name my_web --replicas 3 --publish 8080:80 nginx -``` - -When you publish a service port, the swarm routing mesh makes the service -accessible at the target port on every node regardless if there is a task for -the service running on the node. For more information refer to -[Use swarm mode routing mesh](https://docs.docker.com/engine/swarm/ingress/). - -### Publish a port for TCP only or UDP only - -By default, when you publish a port, it is a TCP port. You can -specifically publish a UDP port instead of or in addition to a TCP port. When -you publish both TCP and UDP ports, Docker 1.12.2 and earlier require you to -add the suffix `/tcp` for TCP ports. Otherwise it is optional. - -#### TCP only - -The following two commands are equivalent. - -```bash -$ docker service create --name dns-cache -p 53:53 dns-cache - -$ docker service create --name dns-cache -p 53:53/tcp dns-cache -``` - -#### TCP and UDP - -```bash -$ docker service create --name dns-cache -p 53:53/tcp -p 53:53/udp dns-cache -``` - -#### UDP only - -```bash -$ docker service create --name dns-cache -p 53:53/udp dns-cache -``` - -### Create services using templates - -You can use templates for some flags of `service create`, using the syntax -provided by the Go's [text/template](http://golange.org/pkg/text/template/) package. - -The supported flags are the following : - -- `--hostname` -- `--mount` -- `--env` - -Valid placeholders for the Go template are listed below: - -Placeholder | Description ------------------ | -------------------------------------------- -`.Service.ID` | Service ID -`.Service.Name` | Service name -`.Service.Labels` | Service labels -`.Node.ID` | Node ID -`.Task.ID` | Task ID -`.Task.Name` | Task name -`.Task.Slot` | Task slot - -#### Template example - -In this example, we are going to set the template of the created containers based on the -service's name and the node's ID where it sits. - -```bash -$ docker service create --name hosttempl --hostname={% raw %}"{{.Node.ID}}-{{.Service.Name}}"{% endraw %} busybox top -va8ew30grofhjoychbr6iot8c - -$ docker service ps va8ew30grofhjoychbr6iot8c -ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS -wo41w8hg8qan hosttempl.1 busybox:latest@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912 2e7a8a9c4da2 Running Running about a minute ago - -$ docker inspect --format={% raw %}"{{.Config.Hostname}}"{% endraw %} hosttempl.1.wo41w8hg8qanxwjwsg4kxpprj -x3ti0erg11rjpg64m75kej2mz-hosttempl -``` - -## Related information - -* [service inspect](service_inspect.md) -* [service logs](service_logs.md) -* [service ls](service_ls.md) -* [service rm](service_rm.md) -* [service scale](service_scale.md) -* [service ps](service_ps.md) -* [service update](service_update.md) - - diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/service_inspect.md b/vendor/github.com/docker/docker/docs/reference/commandline/service_inspect.md deleted file mode 100644 index 8b4ab62..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/service_inspect.md +++ /dev/null @@ -1,162 +0,0 @@ ---- -title: "service inspect" -description: "The service inspect command description and usage" -keywords: "service, inspect" ---- - - - -# service inspect - -```Markdown -Usage: docker service inspect [OPTIONS] SERVICE [SERVICE...] - -Display detailed information on one or more services - -Options: - -f, --format string Format the output using the given Go template - --help Print usage - --pretty Print the information in a human friendly format. -``` - - -Inspects the specified service. This command has to be run targeting a manager -node. - -By default, this renders all results in a JSON array. If a format is specified, -the given template will be executed for each result. - -Go's [text/template](http://golang.org/pkg/text/template/) package -describes all the details of the format. - -## Examples - -### Inspecting a service by name or ID - -You can inspect a service, either by its *name*, or *ID* - -For example, given the following service; - -```bash -$ docker service ls -ID NAME MODE REPLICAS IMAGE -dmu1ept4cxcf redis replicated 3/3 redis:3.0.6 -``` - -Both `docker service inspect redis`, and `docker service inspect dmu1ept4cxcf` -produce the same result: - -```bash -$ docker service inspect redis -[ - { - "ID": "dmu1ept4cxcfe8k8lhtux3ro3", - "Version": { - "Index": 12 - }, - "CreatedAt": "2016-06-17T18:44:02.558012087Z", - "UpdatedAt": "2016-06-17T18:44:02.558012087Z", - "Spec": { - "Name": "redis", - "TaskTemplate": { - "ContainerSpec": { - "Image": "redis:3.0.6" - }, - "Resources": { - "Limits": {}, - "Reservations": {} - }, - "RestartPolicy": { - "Condition": "any", - "MaxAttempts": 0 - }, - "Placement": {} - }, - "Mode": { - "Replicated": { - "Replicas": 1 - } - }, - "UpdateConfig": {}, - "EndpointSpec": { - "Mode": "vip" - } - }, - "Endpoint": { - "Spec": {} - } - } -] -``` - -```bash -$ docker service inspect dmu1ept4cxcf -[ - { - "ID": "dmu1ept4cxcfe8k8lhtux3ro3", - "Version": { - "Index": 12 - }, - ... - } -] -``` - -### Inspect a service using pretty-print - -You can print the inspect output in a human-readable format instead of the default -JSON output, by using the `--pretty` option: - -```bash -$ docker service inspect --pretty frontend -ID: c8wgl7q4ndfd52ni6qftkvnnp -Name: frontend -Labels: - - org.example.projectname=demo-app -Service Mode: REPLICATED - Replicas: 5 -Placement: -UpdateConfig: - Parallelism: 0 -ContainerSpec: - Image: nginx:alpine -Resources: -Endpoint Mode: vip -Ports: - Name = - Protocol = tcp - TargetPort = 443 - PublishedPort = 4443 -``` - -You can also use `--format pretty` for the same effect. - - -### Finding the number of tasks running as part of a service - -The `--format` option can be used to obtain specific information about a -service. For example, the following command outputs the number of replicas -of the "redis" service. - -```bash{% raw %} -$ docker service inspect --format='{{.Spec.Mode.Replicated.Replicas}}' redis -10 -{% endraw %}``` - - -## Related information - -* [service create](service_create.md) -* [service logs](service_logs.md) -* [service ls](service_ls.md) -* [service rm](service_rm.md) -* [service scale](service_scale.md) -* [service ps](service_ps.md) -* [service update](service_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/service_logs.md b/vendor/github.com/docker/docker/docs/reference/commandline/service_logs.md deleted file mode 100644 index fdf6a3a..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/service_logs.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: "service logs (experimental)" -description: "The service logs command description and usage" -keywords: "service, logs" -advisory: "experimental" ---- - - - -# service logs - -```Markdown -Usage: docker service logs [OPTIONS] SERVICE - -Fetch the logs of a service - -Options: - --details Show extra details provided to logs - -f, --follow Follow log output - --help Print usage - --since string Show logs since timestamp - --tail string Number of lines to show from the end of the logs (default "all") - -t, --timestamps Show timestamps -``` - -The `docker service logs` command batch-retrieves logs present at the time of execution. - -> **Note**: this command is only functional for services that are started with -> the `json-file` or `journald` logging driver. - -For more information about selecting and configuring logging drivers, refer to -[Configure logging drivers](https://docs.docker.com/engine/admin/logging/overview/). - -The `docker service logs --follow` command will continue streaming the new output from -the service's `STDOUT` and `STDERR`. - -Passing a negative number or a non-integer to `--tail` is invalid and the -value is set to `all` in that case. - -The `docker service logs --timestamps` command will add an [RFC3339Nano timestamp](https://golang.org/pkg/time/#pkg-constants) -, for example `2014-09-16T06:17:46.000000000Z`, to each -log entry. To ensure that the timestamps are aligned the -nano-second part of the timestamp will be padded with zero when necessary. - -The `docker service logs --details` command will add on extra attributes, such as -environment variables and labels, provided to `--log-opt` when creating the -service. - -The `--since` option shows only the service logs generated after -a given date. You can specify the date as an RFC 3339 date, a UNIX -timestamp, or a Go duration string (e.g. `1m30s`, `3h`). Besides RFC3339 date -format you may also use RFC3339Nano, `2006-01-02T15:04:05`, -`2006-01-02T15:04:05.999999999`, `2006-01-02Z07:00`, and `2006-01-02`. The local -timezone on the client will be used if you do not provide either a `Z` or a -`+-00:00` timezone offset at the end of the timestamp. When providing Unix -timestamps enter seconds[.nanoseconds], where seconds is the number of seconds -that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap -seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a -fraction of a second no more than nine digits long. You can combine the -`--since` option with either or both of the `--follow` or `--tail` options. - -## Related information - -* [service create](service_create.md) -* [service inspect](service_inspect.md) -* [service ls](service_ls.md) -* [service rm](service_rm.md) -* [service scale](service_scale.md) -* [service ps](service_ps.md) -* [service update](service_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/service_ls.md b/vendor/github.com/docker/docker/docs/reference/commandline/service_ls.md deleted file mode 100644 index ccd68af..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/service_ls.md +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: "service ls" -description: "The service ls command description and usage" -keywords: "service, ls" ---- - - - -# service ls - -```Markdown -Usage: docker service ls [OPTIONS] - -List services - -Aliases: - ls, list - -Options: - -f, --filter value Filter output based on conditions provided - --help Print usage - -q, --quiet Only display IDs -``` - -This command when run targeting a manager, lists services are running in the -swarm. - -On a manager node: -```bash -$ docker service ls -ID NAME MODE REPLICAS IMAGE -c8wgl7q4ndfd frontend replicated 5/5 nginx:alpine -dmu1ept4cxcf redis replicated 3/3 redis:3.0.6 -iwe3278osahj mongo global 7/7 mongo:3.3 -``` - -The `REPLICAS` column shows both the *actual* and *desired* number of tasks for -the service. - -## Filtering - -The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more -than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`) - -The currently supported filters are: - -* [id](service_ls.md#id) -* [label](service_ls.md#label) -* [name](service_ls.md#name) - -#### ID - -The `id` filter matches all or part of a service's id. - -```bash -$ docker service ls -f "id=0bcjw" -ID NAME MODE REPLICAS IMAGE -0bcjwfh8ychr redis replicated 1/1 redis:3.0.6 -``` - -#### Label - -The `label` filter matches services based on the presence of a `label` alone or -a `label` and a value. - -The following filter matches all services with a `project` label regardless of -its value: - -```bash -$ docker service ls --filter label=project -ID NAME MODE REPLICAS IMAGE -01sl1rp6nj5u frontend2 replicated 1/1 nginx:alpine -36xvvwwauej0 frontend replicated 5/5 nginx:alpine -74nzcxxjv6fq backend replicated 3/3 redis:3.0.6 -``` - -The following filter matches only services with the `project` label with the -`project-a` value. - -```bash -$ docker service ls --filter label=project=project-a -ID NAME MODE REPLICAS IMAGE -36xvvwwauej0 frontend replicated 5/5 nginx:alpine -74nzcxxjv6fq backend replicated 3/3 redis:3.0.6 -``` - -#### Name - -The `name` filter matches on all or part of a service's name. - -The following filter matches services with a name containing `redis`. - -```bash -$ docker service ls --filter name=redis -ID NAME MODE REPLICAS IMAGE -0bcjwfh8ychr redis replicated 1/1 redis:3.0.6 -``` - -## Related information - -* [service create](service_create.md) -* [service inspect](service_inspect.md) -* [service logs](service_logs.md) -* [service rm](service_rm.md) -* [service scale](service_scale.md) -* [service ps](service_ps.md) -* [service update](service_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/service_ps.md b/vendor/github.com/docker/docker/docs/reference/commandline/service_ps.md deleted file mode 100644 index 61abb15..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/service_ps.md +++ /dev/null @@ -1,161 +0,0 @@ ---- -title: "service ps" -description: "The service ps command description and usage" -keywords: "service, tasks, ps" -aliases: ["/engine/reference/commandline/service_tasks/"] ---- - - - -# service ps - -```Markdown -Usage: docker service ps [OPTIONS] SERVICE - -List the tasks of a service - -Options: - -f, --filter filter Filter output based on conditions provided - --help Print usage - --no-resolve Do not map IDs to Names - --no-trunc Do not truncate output - -q, --quiet Only display task IDs -``` - -Lists the tasks that are running as part of the specified service. This command -has to be run targeting a manager node. - -## Examples - -### Listing the tasks that are part of a service - -The following command shows all the tasks that are part of the `redis` service: - -```bash -$ docker service ps redis - -ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS -0qihejybwf1x redis.1 redis:3.0.5 manager1 Running Running 8 seconds -bk658fpbex0d redis.2 redis:3.0.5 worker2 Running Running 9 seconds -5ls5s5fldaqg redis.3 redis:3.0.5 worker1 Running Running 9 seconds -8ryt076polmc redis.4 redis:3.0.5 worker1 Running Running 9 seconds -1x0v8yomsncd redis.5 redis:3.0.5 manager1 Running Running 8 seconds -71v7je3el7rr redis.6 redis:3.0.5 worker2 Running Running 9 seconds -4l3zm9b7tfr7 redis.7 redis:3.0.5 worker2 Running Running 9 seconds -9tfpyixiy2i7 redis.8 redis:3.0.5 worker1 Running Running 9 seconds -3w1wu13yupln redis.9 redis:3.0.5 manager1 Running Running 8 seconds -8eaxrb2fqpbn redis.10 redis:3.0.5 manager1 Running Running 8 seconds -``` - -In addition to _running_ tasks, the output also shows the task history. For -example, after updating the service to use the `redis:3.0.6` image, the output -may look like this: - -```bash -$ docker service ps redis - -ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS -50qe8lfnxaxk redis.1 redis:3.0.6 manager1 Running Running 6 seconds ago -ky2re9oz86r9 \_ redis.1 redis:3.0.5 manager1 Shutdown Shutdown 8 seconds ago -3s46te2nzl4i redis.2 redis:3.0.6 worker2 Running Running less than a second ago -nvjljf7rmor4 \_ redis.2 redis:3.0.6 worker2 Shutdown Rejected 23 seconds ago "No such image: redis@sha256:6…" -vtiuz2fpc0yb \_ redis.2 redis:3.0.5 worker2 Shutdown Shutdown 1 second ago -jnarweeha8x4 redis.3 redis:3.0.6 worker1 Running Running 3 seconds ago -vs448yca2nz4 \_ redis.3 redis:3.0.5 worker1 Shutdown Shutdown 4 seconds ago -jf1i992619ir redis.4 redis:3.0.6 worker1 Running Running 10 seconds ago -blkttv7zs8ee \_ redis.4 redis:3.0.5 worker1 Shutdown Shutdown 11 seconds ago -``` - -The number of items in the task history is determined by the -`--task-history-limit` option that was set when initializing the swarm. You can -change the task history retention limit using the -[`docker swarm update`](swarm_update.md) command. - -When deploying a service, docker resolves the digest for the service's -image, and pins the service to that digest. The digest is not shown by -default, but is printed if `--no-trunc` is used. The `--no-trunc` option -also shows the non-truncated task ID, and error-messages, as can be seen below; - -```bash -$ docker service ps --no-trunc redis - -ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS -50qe8lfnxaxksi9w2a704wkp7 redis.1 redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842 manager1 Running Running 5 minutes ago -ky2re9oz86r9556i2szb8a8af \_ redis.1 redis:3.0.5@sha256:f8829e00d95672c48c60f468329d6693c4bdd28d1f057e755f8ba8b40008682e worker2 Shutdown Shutdown 5 minutes ago -bk658fpbex0d57cqcwoe3jthu redis.2 redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842 worker2 Running Running 5 seconds -nvjljf7rmor4htv7l8rwcx7i7 \_ redis.2 redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842 worker2 Shutdown Rejected 5 minutes ago "No such image: redis@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842" -``` - -## Filtering - -The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there -is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`). -Multiple filter flags are combined as an `OR` filter. For example, -`-f name=redis.1 -f name=redis.7` returns both `redis.1` and `redis.7` tasks. - -The currently supported filters are: - -* [id](#id) -* [name](#name) -* [node](#node) -* [desired-state](#desired-state) - - -#### ID - -The `id` filter matches on all or a prefix of a task's ID. - -```bash -$ docker service ps -f "id=8" redis - -ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS -8ryt076polmc redis.4 redis:3.0.6 worker1 Running Running 9 seconds -8eaxrb2fqpbn redis.10 redis:3.0.6 manager1 Running Running 8 seconds -``` - -#### Name - -The `name` filter matches on task names. - -```bash -$ docker service ps -f "name=redis.1" redis -ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS -qihejybwf1x5 redis.1 redis:3.0.6 manager1 Running Running 8 seconds -``` - - -#### Node - -The `node` filter matches on a node name or a node ID. - -```bash -$ docker service ps -f "node=manager1" redis -ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS -0qihejybwf1x redis.1 redis:3.0.6 manager1 Running Running 8 seconds -1x0v8yomsncd redis.5 redis:3.0.6 manager1 Running Running 8 seconds -3w1wu13yupln redis.9 redis:3.0.6 manager1 Running Running 8 seconds -8eaxrb2fqpbn redis.10 redis:3.0.6 manager1 Running Running 8 seconds -``` - - -#### desired-state - -The `desired-state` filter can take the values `running`, `shutdown`, and `accepted`. - - -## Related information - -* [service create](service_create.md) -* [service inspect](service_inspect.md) -* [service logs](service_logs.md) -* [service ls](service_ls.md) -* [service rm](service_rm.md) -* [service scale](service_scale.md) -* [service update](service_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/service_rm.md b/vendor/github.com/docker/docker/docs/reference/commandline/service_rm.md deleted file mode 100644 index d0ba90b..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/service_rm.md +++ /dev/null @@ -1,55 +0,0 @@ ---- -title: "service rm" -description: "The service rm command description and usage" -keywords: "service, rm" ---- - - - -# service rm - -```Markdown -Usage: docker service rm SERVICE [SERVICE...] - -Remove one or more services - -Aliases: - rm, remove - -Options: - --help Print usage -``` - -Removes the specified services from the swarm. This command has to be run -targeting a manager node. - -For example, to remove the redis service: - -```bash -$ docker service rm redis -redis -$ docker service ls -ID NAME MODE REPLICAS IMAGE -``` - -> **Warning**: Unlike `docker rm`, this command does not ask for confirmation -> before removing a running service. - - - -## Related information - -* [service create](service_create.md) -* [service inspect](service_inspect.md) -* [service logs](service_logs.md) -* [service ls](service_ls.md) -* [service scale](service_scale.md) -* [service ps](service_ps.md) -* [service update](service_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/service_scale.md b/vendor/github.com/docker/docker/docs/reference/commandline/service_scale.md deleted file mode 100644 index 64075ed..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/service_scale.md +++ /dev/null @@ -1,96 +0,0 @@ ---- -title: "service scale" -description: "The service scale command description and usage" -keywords: "service, scale" ---- - - - -# service scale - -```markdown -Usage: docker service scale SERVICE=REPLICAS [SERVICE=REPLICAS...] - -Scale one or multiple replicated services - -Options: - --help Print usage -``` - -## Examples - -### Scale a service - -The scale command enables you to scale one or more replicated services either up -or down to the desired number of replicas. This command cannot be applied on -services which are global mode. The command will return immediately, but the -actual scaling of the service may take some time. To stop all replicas of a -service while keeping the service active in the swarm you can set the scale to 0. - -For example, the following command scales the "frontend" service to 50 tasks. - -```bash -$ docker service scale frontend=50 -frontend scaled to 50 -``` - -The following command tries to scale a global service to 10 tasks and returns an error. - -``` -$ docker service create --mode global --name backend backend:latest -b4g08uwuairexjub6ome6usqh -$ docker service scale backend=10 -backend: scale can only be used with replicated mode -``` - -Directly afterwards, run `docker service ls`, to see the actual number of -replicas. - -```bash -$ docker service ls --filter name=frontend - -ID NAME MODE REPLICAS IMAGE -3pr5mlvu3fh9 frontend replicated 15/50 nginx:alpine -``` - -You can also scale a service using the [`docker service update`](service_update.md) -command. The following commands are equivalent: - -```bash -$ docker service scale frontend=50 -$ docker service update --replicas=50 frontend -``` - -### Scale multiple services - -The `docker service scale` command allows you to set the desired number of -tasks for multiple services at once. The following example scales both the -backend and frontend services: - -```bash -$ docker service scale backend=3 frontend=5 -backend scaled to 3 -frontend scaled to 5 - -$ docker service ls -ID NAME MODE REPLICAS IMAGE -3pr5mlvu3fh9 frontend replicated 5/5 nginx:alpine -74nzcxxjv6fq backend replicated 3/3 redis:3.0.6 -``` - -## Related information - -* [service create](service_create.md) -* [service inspect](service_inspect.md) -* [service logs](service_logs.md) -* [service ls](service_ls.md) -* [service rm](service_rm.md) -* [service ps](service_ps.md) -* [service update](service_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/service_update.md b/vendor/github.com/docker/docker/docs/reference/commandline/service_update.md deleted file mode 100644 index 301a0ea..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/service_update.md +++ /dev/null @@ -1,181 +0,0 @@ ---- -title: "service update" -description: "The service update command description and usage" -keywords: "service, update" ---- - - - -# service update - -```Markdown -Usage: docker service update [OPTIONS] SERVICE - -Update a service - -Options: - --args string Service command args - --constraint-add list Add or update a placement constraint (default []) - --constraint-rm list Remove a constraint (default []) - --container-label-add list Add or update a container label (default []) - --container-label-rm list Remove a container label by its key (default []) - --dns-add list Add or update a custom DNS server (default []) - --dns-option-add list Add or update a DNS option (default []) - --dns-option-rm list Remove a DNS option (default []) - --dns-rm list Remove a custom DNS server (default []) - --dns-search-add list Add or update a custom DNS search domain (default []) - --dns-search-rm list Remove a DNS search domain (default []) - --endpoint-mode string Endpoint mode (vip or dnsrr) - --env-add list Add or update an environment variable (default []) - --env-rm list Remove an environment variable (default []) - --force Force update even if no changes require it - --group-add list Add an additional supplementary user group to the container (default []) - --group-rm list Remove a previously added supplementary user group from the container (default []) - --health-cmd string Command to run to check health - --health-interval duration Time between running the check (ns|us|ms|s|m|h) - --health-retries int Consecutive failures needed to report unhealthy - --health-timeout duration Maximum time to allow one check to run (ns|us|ms|s|m|h) - --help Print usage - --host-add list Add or update a custom host-to-IP mapping (host:ip) (default []) - --host-rm list Remove a custom host-to-IP mapping (host:ip) (default []) - --hostname string Container hostname - --image string Service image tag - --label-add list Add or update a service label (default []) - --label-rm list Remove a label by its key (default []) - --limit-cpu decimal Limit CPUs (default 0.000) - --limit-memory bytes Limit Memory (default 0 B) - --log-driver string Logging driver for service - --log-opt list Logging driver options (default []) - --mount-add mount Add or update a mount on a service - --mount-rm list Remove a mount by its target path (default []) - --no-healthcheck Disable any container-specified HEALTHCHECK - --publish-add port Add or update a published port - --publish-rm port Remove a published port by its target port - --replicas uint Number of tasks - --reserve-cpu decimal Reserve CPUs (default 0.000) - --reserve-memory bytes Reserve Memory (default 0 B) - --restart-condition string Restart when condition is met (none, on-failure, or any) - --restart-delay duration Delay between restart attempts (ns|us|ms|s|m|h) - --restart-max-attempts uint Maximum number of restarts before giving up - --restart-window duration Window used to evaluate the restart policy (ns|us|ms|s|m|h) - --rollback Rollback to previous specification - --secret-add secret Add or update a secret on a service - --secret-rm list Remove a secret (default []) - --stop-grace-period duration Time to wait before force killing a container (ns|us|ms|s|m|h) - -t, --tty Allocate a pseudo-TTY - --update-delay duration Delay between updates (ns|us|ms|s|m|h) (default 0s) - --update-failure-action string Action on update failure (pause|continue) (default "pause") - --update-max-failure-ratio float Failure rate to tolerate during an update - --update-monitor duration Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 0s) - --update-parallelism uint Maximum number of tasks updated simultaneously (0 to update all at once) (default 1) - -u, --user string Username or UID (format: [:]) - --with-registry-auth Send registry authentication details to swarm agents - -w, --workdir string Working directory inside the container -``` - -Updates a service as described by the specified parameters. This command has to be run targeting a manager node. -The parameters are the same as [`docker service create`](service_create.md). Please look at the description there -for further information. - -Normally, updating a service will only cause the service's tasks to be replaced with new ones if a change to the -service requires recreating the tasks for it to take effect. For example, only changing the -`--update-parallelism` setting will not recreate the tasks, because the individual tasks are not affected by this -setting. However, the `--force` flag will cause the tasks to be recreated anyway. This can be used to perform a -rolling restart without any changes to the service parameters. - -## Examples - -### Update a service - -```bash -$ docker service update --limit-cpu 2 redis -``` - -### Perform a rolling restart with no parameter changes - -```bash -$ docker service update --force --update-parallelism 1 --update-delay 30s redis -``` - -In this example, the `--force` flag causes the service's tasks to be shut down -and replaced with new ones even though none of the other parameters would -normally cause that to happen. The `--update-parallelism 1` setting ensures -that only one task is replaced at a time (this is the default behavior). The -`--update-delay 30s` setting introduces a 30 second delay between tasks, so -that the rolling restart happens gradually. - -### Adding and removing mounts - -Use the `--mount-add` or `--mount-rm` options add or remove a service's bind-mounts -or volumes. - -The following example creates a service which mounts the `test-data` volume to -`/somewhere`. The next step updates the service to also mount the `other-volume` -volume to `/somewhere-else`volume, The last step unmounts the `/somewhere` mount -point, effectively removing the `test-data` volume. Each command returns the -service name. - -- The `--mount-add` flag takes the same parameters as the `--mount` flag on - `service create`. Refer to the [volumes and - bind-mounts](service_create.md#volumes-and-bind-mounts-mount) section in the - `service create` reference for details. - -- The `--mount-rm` flag takes the `target` path of the mount. - -```bash -$ docker service create \ - --name=myservice \ - --mount \ - type=volume,source=test-data,target=/somewhere \ - nginx:alpine \ - myservice - -myservice - -$ docker service update \ - --mount-add \ - type=volume,source=other-volume,target=/somewhere-else \ - myservice - -myservice - -$ docker service update --mount-rm /somewhere myservice - -myservice -``` - -### Adding and removing secrets - -Use the `--secret-add` or `--secret-rm` options add or remove a service's -secrets. - -The following example adds a secret named `ssh-2` and removes `ssh-1`: - -```bash -$ docker service update \ - --secret-add source=ssh-2,target=ssh-2 \ - --secret-rm ssh-1 \ - myservice -``` - -### Update services using templates - -Some flags of `service update` support the use of templating. -See [`service create`](./service_create.md#templating) for the reference. - -## Related information - -* [service create](service_create.md) -* [service inspect](service_inspect.md) -* [service logs](service_logs.md) -* [service ls](service_ls.md) -* [service ps](service_ps.md) -* [service rm](service_rm.md) -* [service scale](service_scale.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/stack_deploy.md b/vendor/github.com/docker/docker/docs/reference/commandline/stack_deploy.md deleted file mode 100644 index 037feae..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/stack_deploy.md +++ /dev/null @@ -1,98 +0,0 @@ ---- -title: "stack deploy" -description: "The stack deploy command description and usage" -keywords: "stack, deploy, up" ---- - - - -# stack deploy - -```markdown -Usage: docker stack deploy [OPTIONS] STACK - -Deploy a new stack or update an existing stack - -Aliases: - deploy, up - -Options: - --bundle-file string Path to a Distributed Application Bundle file - -c, --compose-file string Path to a Compose file - --help Print usage - --with-registry-auth Send registry authentication details to Swarm agents -``` - -Create and update a stack from a `compose` or a `dab` file on the swarm. This command -has to be run targeting a manager node. - -## Compose file - -The `deploy` command supports compose file version `3.0` and above." - -```bash -$ docker stack deploy --compose-file docker-compose.yml vossibility -Ignoring unsupported options: links - -Creating network vossibility_vossibility -Creating network vossibility_default -Creating service vossibility_nsqd -Creating service vossibility_logstash -Creating service vossibility_elasticsearch -Creating service vossibility_kibana -Creating service vossibility_ghollector -Creating service vossibility_lookupd -``` - -You can verify that the services were correctly created - -``` -$ docker service ls -ID NAME MODE REPLICAS IMAGE -29bv0vnlm903 vossibility_lookupd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 -4awt47624qwh vossibility_nsqd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 -4tjx9biia6fs vossibility_elasticsearch replicated 1/1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa -7563uuzr9eys vossibility_kibana replicated 1/1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03 -9gc5m4met4he vossibility_logstash replicated 1/1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe -axqh55ipl40h vossibility_vossibility-collector replicated 1/1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba -``` - -## DAB file - -```bash -$ docker stack deploy --bundle-file vossibility-stack.dab vossibility -Loading bundle from vossibility-stack.dab -Creating service vossibility_elasticsearch -Creating service vossibility_kibana -Creating service vossibility_logstash -Creating service vossibility_lookupd -Creating service vossibility_nsqd -Creating service vossibility_vossibility-collector -``` - -You can verify that the services were correctly created: - -```bash -$ docker service ls -ID NAME MODE REPLICAS IMAGE -29bv0vnlm903 vossibility_lookupd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 -4awt47624qwh vossibility_nsqd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 -4tjx9biia6fs vossibility_elasticsearch replicated 1/1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa -7563uuzr9eys vossibility_kibana replicated 1/1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03 -9gc5m4met4he vossibility_logstash replicated 1/1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe -axqh55ipl40h vossibility_vossibility-collector replicated 1/1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba -``` - -## Related information - -* [stack ls](stack_ls.md) -* [stack ps](stack_ps.md) -* [stack rm](stack_rm.md) -* [stack services](stack_services.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/stack_ls.md b/vendor/github.com/docker/docker/docs/reference/commandline/stack_ls.md deleted file mode 100644 index 05c7215..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/stack_ls.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: "stack ls" -description: "The stack ls command description and usage" -keywords: "stack, ls" ---- - - - -# stack ls - -```markdown -Usage: docker stack ls - -List stacks - -Aliases: - ls, list - -Options: - --help Print usage -``` - -Lists the stacks. - -For example, the following command shows all stacks and some additional information: - -```bash -$ docker stack ls - -ID SERVICES -vossibility-stack 6 -myapp 2 -``` - -## Related information - -* [stack deploy](stack_deploy.md) -* [stack ps](stack_ps.md) -* [stack rm](stack_rm.md) -* [stack services](stack_services.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/stack_ps.md b/vendor/github.com/docker/docker/docs/reference/commandline/stack_ps.md deleted file mode 100644 index 101e9fe..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/stack_ps.md +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: "stack ps" -description: "The stack ps command description and usage" -keywords: "stack, ps" ---- - - - -# stack ps - -```markdown -Usage: docker stack ps [OPTIONS] STACK - -List the tasks in the stack - -Options: - -f, --filter filter Filter output based on conditions provided - --help Print usage - --no-resolve Do not map IDs to Names - --no-trunc Do not truncate output -``` - -Lists the tasks that are running as part of the specified stack. This -command has to be run targeting a manager node. - -## Filtering - -The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there -is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`). -Multiple filter flags are combined as an `OR` filter. For example, -`-f name=redis.1 -f name=redis.7` returns both `redis.1` and `redis.7` tasks. - -The currently supported filters are: - -* id -* name -* desired-state - -## Related information - -* [stack deploy](stack_deploy.md) -* [stack ls](stack_ls.md) -* [stack rm](stack_rm.md) -* [stack services](stack_services.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/stack_rm.md b/vendor/github.com/docker/docker/docs/reference/commandline/stack_rm.md deleted file mode 100644 index fd63997..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/stack_rm.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -title: "stack rm" -description: "The stack rm command description and usage" -keywords: "stack, rm, remove, down" ---- - - - -# stack rm - -```markdown -Usage: docker stack rm STACK - -Remove the stack - -Aliases: - rm, remove, down - -Options: - --help Print usage -``` - -Remove the stack from the swarm. This command has to be run targeting -a manager node. - -## Related information - -* [stack deploy](stack_deploy.md) -* [stack ls](stack_ls.md) -* [stack ps](stack_ps.md) -* [stack services](stack_services.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/stack_services.md b/vendor/github.com/docker/docker/docs/reference/commandline/stack_services.md deleted file mode 100644 index 62779b4..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/stack_services.md +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: "stack services" -description: "The stack services command description and usage" -keywords: "stack, services" -advisory: "experimental" ---- - - - -# stack services (experimental) - -```markdown -Usage: docker stack services [OPTIONS] STACK - -List the services in the stack - -Options: - -f, --filter value Filter output based on conditions provided - --help Print usage - -q, --quiet Only display IDs -``` - -Lists the services that are running as part of the specified stack. This -command has to be run targeting a manager node. - -For example, the following command shows all services in the `myapp` stack: - -```bash -$ docker stack services myapp - -ID NAME REPLICAS IMAGE COMMAND -7be5ei6sqeye myapp_web 1/1 nginx@sha256:23f809e7fd5952e7d5be065b4d3643fbbceccd349d537b62a123ef2201bc886f -dn7m7nhhfb9y myapp_db 1/1 mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539 -``` - -## Filtering - -The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there -is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`). -Multiple filter flags are combined as an `OR` filter. - -The following command shows both the `web` and `db` services: - -```bash -$ docker stack services --filter name=myapp_web --filter name=myapp_db myapp - -ID NAME REPLICAS IMAGE COMMAND -7be5ei6sqeye myapp_web 1/1 nginx@sha256:23f809e7fd5952e7d5be065b4d3643fbbceccd349d537b62a123ef2201bc886f -dn7m7nhhfb9y myapp_db 1/1 mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539 -``` - -The currently supported filters are: - -* id / ID (`--filter id=7be5ei6sqeye`, or `--filter ID=7be5ei6sqeye`) -* name (`--filter name=myapp_web`) -* label (`--filter label=key=value`) - -## Related information - -* [stack deploy](stack_deploy.md) -* [stack ls](stack_ls.md) -* [stack ps](stack_ps.md) -* [stack rm](stack_rm.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/start.md b/vendor/github.com/docker/docker/docs/reference/commandline/start.md deleted file mode 100644 index 980bce9..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/start.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: "start" -description: "The start command description and usage" -keywords: "Start, container, stopped" ---- - - - -# start - -```markdown -Usage: docker start [OPTIONS] CONTAINER [CONTAINER...] - -Start one or more stopped containers - -Options: - -a, --attach Attach STDOUT/STDERR and forward signals - --detach-keys string Override the key sequence for detaching a container - --help Print usage - -i, --interactive Attach container's STDIN -``` diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/stats.md b/vendor/github.com/docker/docker/docs/reference/commandline/stats.md deleted file mode 100644 index f5d0d54..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/stats.md +++ /dev/null @@ -1,117 +0,0 @@ ---- -title: "stats" -description: "The stats command description and usage" -keywords: "container, resource, statistics" ---- - - - -# stats - -```markdown -Usage: docker stats [OPTIONS] [CONTAINER...] - -Display a live stream of container(s) resource usage statistics - -Options: - -a, --all Show all containers (default shows just running) - --format string Pretty-print images using a Go template - --help Print usage - --no-stream Disable streaming stats and only pull the first result -``` - -The `docker stats` command returns a live data stream for running containers. To limit data to one or more specific containers, specify a list of container names or ids separated by a space. You can specify a stopped container but stopped containers do not return any data. - -If you want more detailed information about a container's resource usage, use the `/containers/(id)/stats` API endpoint. - -## Examples - -Running `docker stats` on all running containers against a Linux daemon. - - $ docker stats - CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O - 1285939c1fd3 0.07% 796 KiB / 64 MiB 1.21% 788 B / 648 B 3.568 MB / 512 KB - 9c76f7834ae2 0.07% 2.746 MiB / 64 MiB 4.29% 1.266 KB / 648 B 12.4 MB / 0 B - d1ea048f04e4 0.03% 4.583 MiB / 64 MiB 6.30% 2.854 KB / 648 B 27.7 MB / 0 B - -Running `docker stats` on multiple containers by name and id against a Linux daemon. - - $ docker stats fervent_panini 5acfcb1b4fd1 - CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O - 5acfcb1b4fd1 0.00% 115.2 MiB/1.045 GiB 11.03% 1.422 kB/648 B - fervent_panini 0.02% 11.08 MiB/1.045 GiB 1.06% 648 B/648 B - -Running `docker stats` on all running containers against a Windows daemon. - - PS E:\> docker stats - CONTAINER CPU % PRIV WORKING SET NET I/O BLOCK I/O - 09d3bb5b1604 6.61% 38.21 MiB 17.1 kB / 7.73 kB 10.7 MB / 3.57 MB - 9db7aa4d986d 9.19% 38.26 MiB 15.2 kB / 7.65 kB 10.6 MB / 3.3 MB - 3f214c61ad1d 0.00% 28.64 MiB 64 kB / 6.84 kB 4.42 MB / 6.93 MB - -Running `docker stats` on multiple containers by name and id against a Windows daemon. - - PS E:\> docker ps -a - CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES - 3f214c61ad1d nanoserver "cmd" 2 minutes ago Up 2 minutes big_minsky - 9db7aa4d986d windowsservercore "cmd" 2 minutes ago Up 2 minutes mad_wilson - 09d3bb5b1604 windowsservercore "cmd" 2 minutes ago Up 2 minutes affectionate_easley - - PS E:\> docker stats 3f214c61ad1d mad_wilson - CONTAINER CPU % PRIV WORKING SET NET I/O BLOCK I/O - 3f214c61ad1d 0.00% 46.25 MiB 76.3 kB / 7.92 kB 10.3 MB / 14.7 MB - mad_wilson 9.59% 40.09 MiB 27.6 kB / 8.81 kB 17 MB / 20.1 MB - -## Formatting - -The formatting option (`--format`) pretty prints container output -using a Go template. - -Valid placeholders for the Go template are listed below: - -Placeholder | Description ------------- | -------------------------------------------- -`.Container` | Container name or ID (user input) -`.Name` | Container name -`.ID` | Container ID -`.CPUPerc` | CPU percentage -`.MemUsage` | Memory usage -`.NetIO` | Network IO -`.BlockIO` | Block IO -`.MemPerc` | Memory percentage (Not available on Windows) -`.PIDs` | Number of PIDs (Not available on Windows) - - -When using the `--format` option, the `stats` command either -outputs the data exactly as the template declares or, when using the -`table` directive, includes column headers as well. - -The following example uses a template without headers and outputs the -`Container` and `CPUPerc` entries separated by a colon for all images: - -```bash -$ docker stats --format "{{.Container}}: {{.CPUPerc}}" - -09d3bb5b1604: 6.61% -9db7aa4d986d: 9.19% -3f214c61ad1d: 0.00% -``` - -To list all containers statistics with their name, CPU percentage and memory -usage in a table format you can use: - -```bash -$ docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" - -CONTAINER CPU % PRIV WORKING SET -1285939c1fd3 0.07% 796 KiB / 64 MiB -9c76f7834ae2 0.07% 2.746 MiB / 64 MiB -d1ea048f04e4 0.03% 4.583 MiB / 64 MiB -``` diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/stop.md b/vendor/github.com/docker/docker/docs/reference/commandline/stop.md deleted file mode 100644 index 3090db9..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/stop.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: "stop" -description: "The stop command description and usage" -keywords: "stop, SIGKILL, SIGTERM" ---- - - - -# stop - -```markdown -Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...] - -Stop one or more running containers - -Options: - --help Print usage - -t, --time int Seconds to wait for stop before killing it (default 10) -``` - -The main process inside the container will receive `SIGTERM`, and after a grace -period, `SIGKILL`. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_init.md b/vendor/github.com/docker/docker/docs/reference/commandline/swarm_init.md deleted file mode 100644 index 44afc27..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_init.md +++ /dev/null @@ -1,142 +0,0 @@ ---- -title: "swarm init" -description: "The swarm init command description and usage" -keywords: "swarm, init" ---- - - - -# swarm init - -```markdown -Usage: docker swarm init [OPTIONS] - -Initialize a swarm - -Options: - --advertise-addr string Advertised address (format: [:port]) - --autolock Enable manager autolocking (requiring an unlock key to start a stopped manager) - --cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s) - --dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s) - --external-ca external-ca Specifications of one or more certificate signing endpoints - --force-new-cluster Force create a new cluster from current state - --help Print usage - --listen-addr node-addr Listen address (format: [:port]) (default 0.0.0.0:2377) - --max-snapshots uint Number of additional Raft snapshots to retain - --snapshot-interval uint Number of log entries between Raft snapshots (default 10000) - --task-history-limit int Task history retention limit (default 5) -``` - -Initialize a swarm. The docker engine targeted by this command becomes a manager -in the newly created single-node swarm. - - -```bash -$ docker swarm init --advertise-addr 192.168.99.121 -Swarm initialized: current node (bvz81updecsj6wjz393c09vti) is now a manager. - -To add a worker to this swarm, run the following command: - - docker swarm join \ - --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx \ - 172.17.0.2:2377 - -To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions. -``` - -`docker swarm init` generates two random tokens, a worker token and a manager token. When you join -a new node to the swarm, the node joins as a worker or manager node based upon the token you pass -to [swarm join](swarm_join.md). - -After you create the swarm, you can display or rotate the token using -[swarm join-token](swarm_join_token.md). - -### `--autolock` - -This flag enables automatic locking of managers with an encryption key. The -private keys and data stored by all managers will be protected by the -encryption key printed in the output, and will not be accessible without it. -Thus, it is very important to store this key in order to activate a manager -after it restarts. The key can be passed to `docker swarm unlock` to reactivate -the manager. Autolock can be disabled by running -`docker swarm update --autolock=false`. After disabling it, the encryption key -is no longer required to start the manager, and it will start up on its own -without user intervention. - -### `--cert-expiry` - -This flag sets the validity period for node certificates. - -### `--dispatcher-heartbeat` - -This flag sets the frequency with which nodes are told to use as a -period to report their health. - -### `--external-ca` - -This flag sets up the swarm to use an external CA to issue node certificates. The value takes -the form `protocol=X,url=Y`. The value for `protocol` specifies what protocol should be used -to send signing requests to the external CA. Currently, the only supported value is `cfssl`. -The URL specifies the endpoint where signing requests should be submitted. - -### `--force-new-cluster` - -This flag forces an existing node that was part of a quorum that was lost to restart as a single node Manager without losing its data. - -### `--listen-addr` - -The node listens for inbound swarm manager traffic on this address. The default is to listen on -0.0.0.0:2377. It is also possible to specify a network interface to listen on that interface's -address; for example `--listen-addr eth0:2377`. - -Specifying a port is optional. If the value is a bare IP address or interface -name, the default port 2377 will be used. - -### `--advertise-addr` - -This flag specifies the address that will be advertised to other members of the -swarm for API access and overlay networking. If unspecified, Docker will check -if the system has a single IP address, and use that IP address with the -listening port (see `--listen-addr`). If the system has multiple IP addresses, -`--advertise-addr` must be specified so that the correct address is chosen for -inter-manager communication and overlay networking. - -It is also possible to specify a network interface to advertise that interface's address; -for example `--advertise-addr eth0:2377`. - -Specifying a port is optional. If the value is a bare IP address or interface -name, the default port 2377 will be used. - -### `--task-history-limit` - -This flag sets up task history retention limit. - -### `--max-snapshots` - -This flag sets the number of old Raft snapshots to retain in addition to the -current Raft snapshots. By default, no old snapshots are retained. This option -may be used for debugging, or to store old snapshots of the swarm state for -disaster recovery purposes. - -### `--snapshot-interval` - -This flag specifies how many log entries to allow in between Raft snapshots. -Setting this to a higher number will trigger snapshots less frequently. -Snapshots compact the Raft log and allow for more efficient transfer of the -state to new managers. However, there is a performance cost to taking snapshots -frequently. - -## Related information - -* [swarm join](swarm_join.md) -* [swarm leave](swarm_leave.md) -* [swarm update](swarm_update.md) -* [swarm join-token](swarm_join_token.md) -* [node rm](node_rm.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_join.md b/vendor/github.com/docker/docker/docs/reference/commandline/swarm_join.md deleted file mode 100644 index 0cde0d7..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_join.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: "swarm join" -description: "The swarm join command description and usage" -keywords: "swarm, join" ---- - - - -# swarm join - -```markdown -Usage: docker swarm join [OPTIONS] HOST:PORT - -Join a swarm as a node and/or manager - -Options: - --advertise-addr string Advertised address (format: [:port]) - --help Print usage - --listen-addr node-addr Listen address (format: [:port]) (default 0.0.0.0:2377) - --token string Token for entry into the swarm -``` - -Join a node to a swarm. The node joins as a manager node or worker node based upon the token you -pass with the `--token` flag. If you pass a manager token, the node joins as a manager. If you -pass a worker token, the node joins as a worker. - -### Join a node to swarm as a manager - -The example below demonstrates joining a manager node using a manager token. - -```bash -$ docker swarm join --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 192.168.99.121:2377 -This node joined a swarm as a manager. -$ docker node ls -ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS -dkp8vy1dq1kxleu9g4u78tlag * manager2 Ready Active Reachable -dvfxp4zseq4s0rih1selh0d20 manager1 Ready Active Leader -``` - -A cluster should only have 3-7 managers at most, because a majority of managers must be available -for the cluster to function. Nodes that aren't meant to participate in this management quorum -should join as workers instead. Managers should be stable hosts that have static IP addresses. - -### Join a node to swarm as a worker - -The example below demonstrates joining a worker node using a worker token. - -```bash -$ docker swarm join --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx 192.168.99.121:2377 -This node joined a swarm as a worker. -$ docker node ls -ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS -7ln70fl22uw2dvjn2ft53m3q5 worker2 Ready Active -dkp8vy1dq1kxleu9g4u78tlag worker1 Ready Active Reachable -dvfxp4zseq4s0rih1selh0d20 * manager1 Ready Active Leader -``` - -### `--listen-addr value` - -If the node is a manager, it will listen for inbound swarm manager traffic on this -address. The default is to listen on 0.0.0.0:2377. It is also possible to specify a -network interface to listen on that interface's address; for example `--listen-addr eth0:2377`. - -Specifying a port is optional. If the value is a bare IP address, or interface -name, the default port 2377 will be used. - -This flag is generally not necessary when joining an existing swarm. - -### `--advertise-addr value` - -This flag specifies the address that will be advertised to other members of the -swarm for API access. If unspecified, Docker will check if the system has a -single IP address, and use that IP address with the listening port (see -`--listen-addr`). If the system has multiple IP addresses, `--advertise-addr` -must be specified so that the correct address is chosen for inter-manager -communication and overlay networking. - -It is also possible to specify a network interface to advertise that interface's address; -for example `--advertise-addr eth0:2377`. - -Specifying a port is optional. If the value is a bare IP address, or interface -name, the default port 2377 will be used. - -This flag is generally not necessary when joining an existing swarm. - -### `--token string` - -Secret value required for nodes to join the swarm - - -## Related information - -* [swarm init](swarm_init.md) -* [swarm leave](swarm_leave.md) -* [swarm update](swarm_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_join_token.md b/vendor/github.com/docker/docker/docs/reference/commandline/swarm_join_token.md deleted file mode 100644 index d731f02..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_join_token.md +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: "swarm join-token" -description: "The swarm join-token command description and usage" -keywords: "swarm, join-token" ---- - - - -# swarm join-token - -```markdown -Usage: docker swarm join-token [OPTIONS] (worker|manager) - -Manage join tokens - -Options: - --help Print usage - -q, --quiet Only display token - --rotate Rotate join token -``` - -Join tokens are secrets that allow a node to join the swarm. There are two -different join tokens available, one for the worker role and one for the manager -role. You pass the token using the `--token` flag when you run -[swarm join](swarm_join.md). Nodes use the join token only when they join the -swarm. - -You can view or rotate the join tokens using `swarm join-token`. - -As a convenience, you can pass `worker` or `manager` as an argument to -`join-token` to print the full `docker swarm join` command to join a new node to -the swarm: - -```bash -$ docker swarm join-token worker -To add a worker to this swarm, run the following command: - - docker swarm join \ - --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx \ - 172.17.0.2:2377 - -$ docker swarm join-token manager -To add a manager to this swarm, run the following command: - - docker swarm join \ - --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 \ - 172.17.0.2:2377 -``` - -Use the `--rotate` flag to generate a new join token for the specified role: - -```bash -$ docker swarm join-token --rotate worker -Successfully rotated worker join token. - -To add a worker to this swarm, run the following command: - - docker swarm join \ - --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-b30ljddcqhef9b9v4rs7mel7t \ - 172.17.0.2:2377 -``` - -After using `--rotate`, only the new token will be valid for joining with the specified role. - -The `-q` (or `--quiet`) flag only prints the token: - -```bash -$ docker swarm join-token -q worker - -SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-b30ljddcqhef9b9v4rs7mel7t -``` - -### `--rotate` - -Because tokens allow new nodes to join the swarm, you should keep them secret. -Be particularly careful with manager tokens since they allow new manager nodes -to join the swarm. A rogue manager has the potential to disrupt the operation of -your swarm. - -Rotate your swarm's join token if a token gets checked-in to version control, -stolen, or a node is compromised. You may also want to periodically rotate the -token to ensure any unknown token leaks do not allow a rogue node to join -the swarm. - -To rotate the join token and print the newly generated token, run -`docker swarm join-token --rotate` and pass the role: `manager` or `worker`. - -Rotating a join-token means that no new nodes will be able to join the swarm -using the old token. Rotation does not affect existing nodes in the swarm -because the join token is only used for authorizing new nodes joining the swarm. - -### `--quiet` - -Only print the token. Do not print a complete command for joining. - -## Related information - -* [swarm join](swarm_join.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_leave.md b/vendor/github.com/docker/docker/docs/reference/commandline/swarm_leave.md deleted file mode 100644 index c0d9437..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_leave.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: "swarm leave" -description: "The swarm leave command description and usage" -keywords: "swarm, leave" ---- - - - -# swarm leave - -```markdown -Usage: docker swarm leave [OPTIONS] - -Leave the swarm - -Options: - -f, --force Force this node to leave the swarm, ignoring warnings - --help Print usage -``` - -When you run this command on a worker, that worker leaves the swarm. - -You can use the `--force` option to on a manager to remove it from the swarm. -However, this does not reconfigure the swarm to ensure that there are enough -managers to maintain a quorum in the swarm. The safe way to remove a manager -from a swarm is to demote it to a worker and then direct it to leave the quorum -without using `--force`. Only use `--force` in situations where the swarm will -no longer be used after the manager leaves, such as in a single-node swarm. - -Consider the following swarm, as seen from the manager: -```bash -$ docker node ls -ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS -7ln70fl22uw2dvjn2ft53m3q5 worker2 Ready Active -dkp8vy1dq1kxleu9g4u78tlag worker1 Ready Active -dvfxp4zseq4s0rih1selh0d20 * manager1 Ready Active Leader -``` - -To remove `worker2`, issue the following command from `worker2` itself: -```bash -$ docker swarm leave -Node left the default swarm. -``` -To remove an inactive node, use the [`node rm`](node_rm.md) command instead. - -## Related information - -* [node rm](node_rm.md) -* [swarm init](swarm_init.md) -* [swarm join](swarm_join.md) -* [swarm update](swarm_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_unlock.md b/vendor/github.com/docker/docker/docs/reference/commandline/swarm_unlock.md deleted file mode 100644 index 164b7d3..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_unlock.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: "swarm unlock" -description: "The swarm unlock command description and usage" -keywords: "swarm, unlock" ---- - - - -# swarm unlock - -```markdown -Usage: docker swarm unlock - -Unlock swarm - -Options: - --help Print usage -``` - -Unlocks a locked manager using a user-supplied unlock key. This command must be -used to reactivate a manager after its Docker daemon restarts if the autolock -setting is turned on. The unlock key is printed at the time when autolock is -enabled, and is also available from the `docker swarm unlock-key` command. - - -```bash -$ docker swarm unlock -Please enter unlock key: -``` - -## Related information - -* [swarm init](swarm_init.md) -* [swarm update](swarm_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_unlock_key.md b/vendor/github.com/docker/docker/docs/reference/commandline/swarm_unlock_key.md deleted file mode 100644 index a2597fe..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_unlock_key.md +++ /dev/null @@ -1,84 +0,0 @@ ---- -title: "swarm unlock-key" -description: "The swarm unlock-keycommand description and usage" -keywords: "swarm, unlock-key" ---- - - - -# swarm unlock-key - -```markdown -Usage: docker swarm unlock-key [OPTIONS] - -Manage the unlock key - -Options: - --help Print usage - -q, --quiet Only display token - --rotate Rotate unlock key -``` - -An unlock key is a secret key needed to unlock a manager after its Docker daemon -restarts. These keys are only used when the autolock feature is enabled for the -swarm. - -You can view or rotate the unlock key using `swarm unlock-key`. To view the key, -run the `docker swarm unlock-key` command without any arguments: - - -```bash -$ docker swarm unlock-key -To unlock a swarm manager after it restarts, run the `docker swarm unlock` -command and provide the following key: - - SWMKEY-1-fySn8TY4w5lKcWcJPIpKufejh9hxx5KYwx6XZigx3Q4 - -Please remember to store this key in a password manager, since without it you -will not be able to restart the manager. -``` - -Use the `--rotate` flag to rotate the unlock key to a new, randomly-generated -key: - -```bash -$ docker swarm unlock-key --rotate -Successfully rotated manager unlock key. - -To unlock a swarm manager after it restarts, run the `docker swarm unlock` -command and provide the following key: - - SWMKEY-1-7c37Cc8654o6p38HnroywCi19pllOnGtbdZEgtKxZu8 - -Please remember to store this key in a password manager, since without it you -will not be able to restart the manager. -``` - -The `-q` (or `--quiet`) flag only prints the key: - -```bash -$ docker swarm unlock-key -q -SWMKEY-1-7c37Cc8654o6p38HnroywCi19pllOnGtbdZEgtKxZu8 -``` - -### `--rotate` - -This flag rotates the unlock key, replacing it with a new randomly-generated -key. The old unlock key will no longer be accepted. - -### `--quiet` - -Only print the unlock key, without instructions. - -## Related information - -* [swarm unlock](swarm_unlock.md) -* [swarm init](swarm_init.md) -* [swarm update](swarm_update.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_update.md b/vendor/github.com/docker/docker/docs/reference/commandline/swarm_update.md deleted file mode 100644 index 0af63fe..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/swarm_update.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: "swarm update" -description: "The swarm update command description and usage" -keywords: "swarm, update" ---- - - - -# swarm update - -```markdown -Usage: docker swarm update [OPTIONS] - -Update the swarm - -Options: - --autolock Change manager autolocking setting (true|false) - --cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s) - --dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s) - --external-ca external-ca Specifications of one or more certificate signing endpoints - --help Print usage - --max-snapshots uint Number of additional Raft snapshots to retain - --snapshot-interval uint Number of log entries between Raft snapshots (default 10000) - --task-history-limit int Task history retention limit (default 5) -``` - -Updates a swarm with new parameter values. This command must target a manager node. - - -```bash -$ docker swarm update --cert-expiry 720h -``` - -## Related information - -* [swarm init](swarm_init.md) -* [swarm join](swarm_join.md) -* [swarm leave](swarm_leave.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/system_df.md b/vendor/github.com/docker/docker/docs/reference/commandline/system_df.md deleted file mode 100644 index c6e8bbd..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/system_df.md +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: "system df" -description: "The system df command description and usage" -keywords: "system, data, usage, disk" ---- - - - -# system df - -```markdown -Usage: docker system df [OPTIONS] - -Show docker filesystem usage - -Options: - --help Print usage - -v, --verbose Show detailed information on space usage -``` - -The `docker system df` command displays information regarding the -amount of disk space used by the docker daemon. - -By default the command will just show a summary of the data used: -```bash -$ docker system df -TYPE TOTAL ACTIVE SIZE RECLAIMABLE -Images 5 2 16.43 MB 11.63 MB (70%) -Containers 2 0 212 B 212 B (100%) -Local Volumes 2 1 36 B 0 B (0%) -``` - -A more detailed view can be requested using the `-v, --verbose` flag: -```bash -$ docker system df -v -Images space usage: - -REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE CONTAINERS -my-curl latest b2789dd875bf 6 minutes ago 11 MB 11 MB 5 B 0 -my-jq latest ae67841be6d0 6 minutes ago 9.623 MB 8.991 MB 632.1 kB 0 - a0971c4015c1 6 minutes ago 11 MB 11 MB 0 B 0 -alpine latest 4e38e38c8ce0 9 weeks ago 4.799 MB 0 B 4.799 MB 1 -alpine 3.3 47cf20d8c26c 9 weeks ago 4.797 MB 4.797 MB 0 B 1 - -Containers space usage: - -CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES -4a7f7eebae0f alpine:latest "sh" 1 0 B 16 minutes ago Exited (0) 5 minutes ago hopeful_yalow -f98f9c2aa1ea alpine:3.3 "sh" 1 212 B 16 minutes ago Exited (0) 48 seconds ago anon-vol - -Local Volumes space usage: - -NAME LINKS SIZE -07c7bdf3e34ab76d921894c2b834f073721fccfbbcba792aa7648e3a7a664c2e 2 36 B -my-named-vol 0 0 B -``` - -* `SHARED SIZE` is the amount of space that an image shares with another one (i.e. their common data) -* `UNIQUE SIZE` is the amount of space that is only used by a given image -* `SIZE` is the virtual size of the image, it is the sum of `SHARED SIZE` and `UNIQUE SIZE` - -Note that network information is not shown because it doesn't consume the disk space. - -## Related Information -* [system prune](system_prune.md) -* [container prune](container_prune.md) -* [volume prune](volume_prune.md) -* [image prune](image_prune.md) -* [network prune](network_prune.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/system_prune.md b/vendor/github.com/docker/docker/docs/reference/commandline/system_prune.md deleted file mode 100644 index 46f8c43..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/system_prune.md +++ /dev/null @@ -1,79 +0,0 @@ ---- -title: "system prune" -description: "Remove unused data" -keywords: "system, prune, delete, remove" ---- - - - -# system prune - -```markdown -Usage: docker system prune [OPTIONS] - -Delete unused data - -Options: - -a, --all Remove all unused data not just dangling ones - -f, --force Do not prompt for confirmation - --help Print usage -``` - -Remove all unused containers, volumes, networks and images (both dangling and unreferenced). - -Example output: - -```bash -$ docker system prune -a -WARNING! This will remove: - - all stopped containers - - all volumes not used by at least one container - - all networks not used by at least one container - - all images without at least one container associated to them -Are you sure you want to continue? [y/N] y -Deleted Containers: -0998aa37185a1a7036b0e12cf1ac1b6442dcfa30a5c9650a42ed5010046f195b -73958bfb884fa81fa4cc6baf61055667e940ea2357b4036acbbe25a60f442a4d - -Deleted Volumes: -named-vol - -Deleted Images: -untagged: my-curl:latest -deleted: sha256:7d88582121f2a29031d92017754d62a0d1a215c97e8f0106c586546e7404447d -deleted: sha256:dd14a93d83593d4024152f85d7c63f76aaa4e73e228377ba1d130ef5149f4d8b -untagged: alpine:3.3 -deleted: sha256:695f3d04125db3266d4ab7bbb3c6b23aa4293923e762aa2562c54f49a28f009f -untagged: alpine:latest -deleted: sha256:ee4603260daafe1a8c2f3b78fd760922918ab2441cbb2853ed5c439e59c52f96 -deleted: sha256:9007f5987db353ec398a223bc5a135c5a9601798ba20a1abba537ea2f8ac765f -deleted: sha256:71fa90c8f04769c9721459d5aa0936db640b92c8c91c9b589b54abd412d120ab -deleted: sha256:bb1c3357b3c30ece26e6604aea7d2ec0ace4166ff34c3616701279c22444c0f3 -untagged: my-jq:latest -deleted: sha256:6e66d724542af9bc4c4abf4a909791d7260b6d0110d8e220708b09e4ee1322e1 -deleted: sha256:07b3fa89d4b17009eb3988dfc592c7d30ab3ba52d2007832dffcf6d40e3eda7f -deleted: sha256:3a88a5c81eb5c283e72db2dbc6d65cbfd8e80b6c89bb6e714cfaaa0eed99c548 - -Total reclaimed space: 13.5 MB -``` - -## Related information - -* [volume create](volume_create.md) -* [volume ls](volume_ls.md) -* [volume inspect](volume_inspect.md) -* [volume rm](volume_rm.md) -* [volume prune](volume_prune.md) -* [Understand Data Volumes](https://docs.docker.com/engine/tutorials/dockervolumes/) -* [system df](system_df.md) -* [container prune](container_prune.md) -* [image prune](image_prune.md) -* [network prune](network_prune.md) -* [system prune](system_prune.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/tag.md b/vendor/github.com/docker/docker/docs/reference/commandline/tag.md deleted file mode 100644 index 983bfe2..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/tag.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: "tag" -description: "The tag command description and usage" -keywords: "tag, name, image" ---- - - - -# tag - -```markdown -Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] - -Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE - -Options: - --help Print usage -``` - -An image name is made up of slash-separated name components, optionally prefixed -by a registry hostname. The hostname must comply with standard DNS rules, but -may not contain underscores. If a hostname is present, it may optionally be -followed by a port number in the format `:8080`. If not present, the command -uses Docker's public registry located at `registry-1.docker.io` by default. Name -components may contain lowercase characters, digits and separators. A separator -is defined as a period, one or two underscores, or one or more dashes. A name -component may not start or end with a separator. - -A tag name may contain lowercase and uppercase characters, digits, underscores, -periods and dashes. A tag name may not start with a period or a dash and may -contain a maximum of 128 characters. - -You can group your images together using names and tags, and then upload them -to [*Share Images via Repositories*](https://docs.docker.com/engine/tutorials/dockerrepos/#/contributing-to-docker-hub). - -# Examples - -## Tagging an image referenced by ID - -To tag a local image with ID "0e5574283393" into the "fedora" repository with -"version1.0": - - docker tag 0e5574283393 fedora/httpd:version1.0 - -## Tagging an image referenced by Name - -To tag a local image with name "httpd" into the "fedora" repository with -"version1.0": - - docker tag httpd fedora/httpd:version1.0 - -Note that since the tag name is not specified, the alias is created for an -existing local version `httpd:latest`. - -## Tagging an image referenced by Name and Tag - -To tag a local image with name "httpd" and tag "test" into the "fedora" -repository with "version1.0.test": - - docker tag httpd:test fedora/httpd:version1.0.test - -## Tagging an image for a private repository - -To push an image to a private registry and not the central Docker -registry you must tag it with the registry hostname and port (if needed). - - docker tag 0e5574283393 myregistryhost:5000/fedora/httpd:version1.0 diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/top.md b/vendor/github.com/docker/docker/docs/reference/commandline/top.md deleted file mode 100644 index 0a04828..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/top.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: "top" -description: "The top command description and usage" -keywords: "container, running, processes" ---- - - - -# top - -```markdown -Usage: docker top CONTAINER [ps OPTIONS] - -Display the running processes of a container - -Options: - --help Print usage -``` diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/unpause.md b/vendor/github.com/docker/docker/docs/reference/commandline/unpause.md deleted file mode 100644 index aa2326f..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/unpause.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: "unpause" -description: "The unpause command description and usage" -keywords: "cgroups, suspend, container" ---- - - - -# unpause - -```markdown -Usage: docker unpause CONTAINER [CONTAINER...] - -Unpause all processes within one or more containers - -Options: - --help Print usage -``` - -The `docker unpause` command un-suspends all processes in the specified containers. -On Linux, it does this using the cgroups freezer. - -See the -[cgroups freezer documentation](https://www.kernel.org/doc/Documentation/cgroup-v1/freezer-subsystem.txt) -for further details. - -## Related information - -* [pause](pause.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/update.md b/vendor/github.com/docker/docker/docs/reference/commandline/update.md deleted file mode 100644 index a139004..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/update.md +++ /dev/null @@ -1,120 +0,0 @@ ---- -title: "update" -description: "The update command description and usage" -keywords: "resources, update, dynamically" ---- - - - -## update - -```markdown -Usage: docker update [OPTIONS] CONTAINER [CONTAINER...] - -Update configuration of one or more containers - -Options: - --blkio-weight value Block IO (relative weight), between 10 and 1000 - --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period - --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota - -c, --cpu-shares int CPU shares (relative weight) - --cpu-rt-period int Limit the CPU real-time period in microseconds - --cpu-rt-runtime int Limit the CPU real-time runtime in microseconds - --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) - --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) - --help Print usage - --kernel-memory string Kernel memory limit - -m, --memory string Memory limit - --memory-reservation string Memory soft limit - --memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap - --restart string Restart policy to apply when a container exits -``` - -The `docker update` command dynamically updates container configuration. -You can use this command to prevent containers from consuming too many -resources from their Docker host. With a single command, you can place -limits on a single container or on many. To specify more than one container, -provide space-separated list of container names or IDs. - -With the exception of the `--kernel-memory` option, you can specify these -options on a running or a stopped container. On kernel version older than -4.6, you can only update `--kernel-memory` on a stopped container or on -a running container with kernel memory initialized. - -## Examples - -The following sections illustrate ways to use this command. - -### Update a container's cpu-shares - -To limit a container's cpu-shares to 512, first identify the container -name or ID. You can use `docker ps` to find these values. You can also -use the ID returned from the `docker run` command. Then, do the following: - -```bash -$ docker update --cpu-shares 512 abebf7571666 -``` - -### Update a container with cpu-shares and memory - -To update multiple resource configurations for multiple containers: - -```bash -$ docker update --cpu-shares 512 -m 300M abebf7571666 hopeful_morse -``` - -### Update a container's kernel memory constraints - -You can update a container's kernel memory limit using the `--kernel-memory` -option. On kernel version older than 4.6, this option can be updated on a -running container only if the container was started with `--kernel-memory`. -If the container was started *without* `--kernel-memory` you need to stop -the container before updating kernel memory. - -For example, if you started a container with this command: - -```bash -$ docker run -dit --name test --kernel-memory 50M ubuntu bash -``` - -You can update kernel memory while the container is running: - -```bash -$ docker update --kernel-memory 80M test -``` - -If you started a container *without* kernel memory initialized: - -```bash -$ docker run -dit --name test2 --memory 300M ubuntu bash -``` - -Update kernel memory of running container `test2` will fail. You need to stop -the container before updating the `--kernel-memory` setting. The next time you -start it, the container uses the new value. - -Kernel version newer than (include) 4.6 does not have this limitation, you -can use `--kernel-memory` the same way as other options. - -### Update a container's restart policy - -You can change a container's restart policy on a running container. The new -restart policy takes effect instantly after you run `docker update` on a -container. - -To update restart policy for one or more containers: - -```bash -$ docker update --restart=on-failure:3 abebf7571666 hopeful_morse -``` - -Note that if the container is started with "--rm" flag, you cannot update the restart -policy for it. The `AutoRemove` and `RestartPolicy` are mutually exclusive for the -container. diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/version.md b/vendor/github.com/docker/docker/docs/reference/commandline/version.md deleted file mode 100644 index cb1bcee..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/version.md +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: "version" -description: "The version command description and usage" -keywords: "version, architecture, api" ---- - - - -# version - -```markdown -Usage: docker version [OPTIONS] - -Show the Docker version information - -Options: - -f, --format string Format the output using the given Go template - --help Print usage -``` - -By default, this will render all version information in an easy to read -layout. If a format is specified, the given template will be executed instead. - -Go's [text/template](http://golang.org/pkg/text/template/) package -describes all the details of the format. - -## Examples - -**Default output:** - - $ docker version - Client: - Version: 1.8.0 - API version: 1.20 - Go version: go1.4.2 - Git commit: f5bae0a - Built: Tue Jun 23 17:56:00 UTC 2015 - OS/Arch: linux/amd64 - - Server: - Version: 1.8.0 - API version: 1.20 - Go version: go1.4.2 - Git commit: f5bae0a - Built: Tue Jun 23 17:56:00 UTC 2015 - OS/Arch: linux/amd64 - -**Get server version:** - - {% raw %} - $ docker version --format '{{.Server.Version}}' - 1.8.0 - {% endraw %} - -**Dump raw data:** - - {% raw %} - $ docker version --format '{{json .}}' - {"Client":{"Version":"1.8.0","ApiVersion":"1.20","GitCommit":"f5bae0a","GoVersion":"go1.4.2","Os":"linux","Arch":"amd64","BuildTime":"Tue Jun 23 17:56:00 UTC 2015"},"ServerOK":true,"Server":{"Version":"1.8.0","ApiVersion":"1.20","GitCommit":"f5bae0a","GoVersion":"go1.4.2","Os":"linux","Arch":"amd64","KernelVersion":"3.13.2-gentoo","BuildTime":"Tue Jun 23 17:56:00 UTC 2015"}} - {% endraw %} diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/volume_create.md b/vendor/github.com/docker/docker/docs/reference/commandline/volume_create.md deleted file mode 100644 index 9b188a9..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/volume_create.md +++ /dev/null @@ -1,91 +0,0 @@ ---- -title: "volume create" -description: "The volume create command description and usage" -keywords: "volume, create" ---- - - - -# volume create - -```markdown -Usage: docker volume create [OPTIONS] [VOLUME] - -Create a volume - -Options: - -d, --driver string Specify volume driver name (default "local") - --help Print usage - --label value Set metadata for a volume (default []) - -o, --opt value Set driver specific options (default map[]) -``` - -Creates a new volume that containers can consume and store data in. If a name is not specified, Docker generates a random name. You create a volume and then configure the container to use it, for example: - -```bash -$ docker volume create hello -hello - -$ docker run -d -v hello:/world busybox ls /world -``` - -The mount is created inside the container's `/world` directory. Docker does not support relative paths for mount points inside the container. - -Multiple containers can use the same volume in the same time period. This is useful if two containers need access to shared data. For example, if one container writes and the other reads the data. - -Volume names must be unique among drivers. This means you cannot use the same volume name with two different drivers. If you attempt this `docker` returns an error: - -``` -A volume named "hello" already exists with the "some-other" driver. Choose a different volume name. -``` - -If you specify a volume name already in use on the current driver, Docker assumes you want to re-use the existing volume and does not return an error. - -## Driver specific options - -Some volume drivers may take options to customize the volume creation. Use the `-o` or `--opt` flags to pass driver options: - -```bash -$ docker volume create --driver fake --opt tardis=blue --opt timey=wimey -``` - -These options are passed directly to the volume driver. Options for -different volume drivers may do different things (or nothing at all). - -The built-in `local` driver on Windows does not support any options. - -The built-in `local` driver on Linux accepts options similar to the linux `mount` command. You can provide multiple options by passing the `--opt` flag multiple times. Some `mount` options (such as the `o` option) can take a comma-separated list of options. Complete list of available mount options can be found [here](http://man7.org/linux/man-pages/man8/mount.8.html). - -For example, the following creates a `tmpfs` volume called `foo` with a size of 100 megabyte and `uid` of 1000. - -```bash -$ docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000 foo -``` - -Another example that uses `btrfs`: - -```bash -$ docker volume create --driver local --opt type=btrfs --opt device=/dev/sda2 foo -``` - -Another example that uses `nfs` to mount the `/path/to/dir` in `rw` mode from `192.168.1.1`: - -```bash -$ docker volume create --driver local --opt type=nfs --opt o=addr=192.168.1.1,rw --opt device=:/path/to/dir foo -``` - - -## Related information - -* [volume inspect](volume_inspect.md) -* [volume ls](volume_ls.md) -* [volume rm](volume_rm.md) -* [volume prune](volume_prune.md) -* [Understand Data Volumes](https://docs.docker.com/engine/tutorials/dockervolumes/) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/volume_inspect.md b/vendor/github.com/docker/docker/docs/reference/commandline/volume_inspect.md deleted file mode 100644 index 98e0ee5..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/volume_inspect.md +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: "volume inspect" -description: "The volume inspect command description and usage" -keywords: "volume, inspect" ---- - - - -# volume inspect - -```markdown -Usage: docker volume inspect [OPTIONS] VOLUME [VOLUME...] - -Display detailed information on one or more volumes - -Options: - -f, --format string Format the output using the given Go template - --help Print usage -``` - -Returns information about a volume. By default, this command renders all results -in a JSON array. You can specify an alternate format to execute a -given template for each result. Go's -[text/template](http://golang.org/pkg/text/template/) package describes all the -details of the format. - -Example output: - - $ docker volume create - 85bffb0677236974f93955d8ecc4df55ef5070117b0e53333cc1b443777be24d - $ docker volume inspect 85bffb0677236974f93955d8ecc4df55ef5070117b0e53333cc1b443777be24d - [ - { - "Name": "85bffb0677236974f93955d8ecc4df55ef5070117b0e53333cc1b443777be24d", - "Driver": "local", - "Mountpoint": "/var/lib/docker/volumes/85bffb0677236974f93955d8ecc4df55ef5070117b0e53333cc1b443777be24d/_data", - "Status": null - } - ] - - {% raw %} - $ docker volume inspect --format '{{ .Mountpoint }}' 85bffb0677236974f93955d8ecc4df55ef5070117b0e53333cc1b443777be24d - /var/lib/docker/volumes/85bffb0677236974f93955d8ecc4df55ef5070117b0e53333cc1b443777be24d/_data - {% endraw %} - -## Related information - -* [volume create](volume_create.md) -* [volume ls](volume_ls.md) -* [volume rm](volume_rm.md) -* [volume prune](volume_prune.md) -* [Understand Data Volumes](https://docs.docker.com/engine/tutorials/dockervolumes/) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/volume_ls.md b/vendor/github.com/docker/docker/docs/reference/commandline/volume_ls.md deleted file mode 100644 index 90ecef2..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/volume_ls.md +++ /dev/null @@ -1,183 +0,0 @@ ---- -title: "volume ls" -description: "The volume ls command description and usage" -keywords: "volume, list" ---- - - - -# volume ls - -```markdown -Usage: docker volume ls [OPTIONS] - -List volumes - -Aliases: - ls, list - -Options: - -f, --filter value Provide filter values (e.g. 'dangling=true') (default []) - - dangling= a volume if referenced or not - - driver= a volume's driver name - - label= or label== - - name= a volume's name - --format string Pretty-print volumes using a Go template - --help Print usage - -q, --quiet Only display volume names -``` - -List all the volumes Docker knows about. You can filter using the `-f` or `--filter` flag. Refer to the [filtering](#filtering) section for more information about available filter options. - -Example output: - -```bash -$ docker volume create rosemary -rosemary -$docker volume create tyler -tyler -$ docker volume ls -DRIVER VOLUME NAME -local rosemary -local tyler -``` - -## Filtering - -The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more -than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`) - -The currently supported filters are: - -* dangling (boolean - true or false, 0 or 1) -* driver (a volume driver's name) -* label (`label=` or `label==`) -* name (a volume's name) - -### dangling - -The `dangling` filter matches on all volumes not referenced by any containers - -```bash -$ docker run -d -v tyler:/tmpwork busybox - -f86a7dd02898067079c99ceacd810149060a70528eff3754d0b0f1a93bd0af18 -$ docker volume ls -f dangling=true -DRIVER VOLUME NAME -local rosemary -``` - -### driver - -The `driver` filter matches on all or part of a volume's driver name. - -The following filter matches all volumes with a driver name containing the `local` string. - -```bash -$ docker volume ls -f driver=local - -DRIVER VOLUME NAME -local rosemary -local tyler -``` - -#### Label - -The `label` filter matches volumes based on the presence of a `label` alone or -a `label` and a value. - -First, let's create some volumes to illustrate this; - -```bash -$ docker volume create the-doctor --label is-timelord=yes -the-doctor -$ docker volume create daleks --label is-timelord=no -daleks -``` - -The following example filter matches volumes with the `is-timelord` label -regardless of its value. - -```bash -$ docker volume ls --filter label=is-timelord - -DRIVER VOLUME NAME -local daleks -local the-doctor -``` - -As can be seen in the above example, both volumes with `is-timelord=yes`, and -`is-timelord=no` are returned. - -Filtering on both `key` *and* `value` of the label, produces the expected result: - -```bash -$ docker volume ls --filter label=is-timelord=yes - -DRIVER VOLUME NAME -local the-doctor -``` - -Specifying multiple label filter produces an "and" search; all conditions -should be met; - -```bash -$ docker volume ls --filter label=is-timelord=yes --filter label=is-timelord=no - -DRIVER VOLUME NAME -``` - -### name - -The `name` filter matches on all or part of a volume's name. - -The following filter matches all volumes with a name containing the `rose` string. - - $ docker volume ls -f name=rose - DRIVER VOLUME NAME - local rosemary - -## Formatting - -The formatting options (`--format`) pretty-prints volumes output -using a Go template. - -Valid placeholders for the Go template are listed below: - -Placeholder | Description ---------------|------------------------------------------------------------------------------------------ -`.Name` | Network name -`.Driver` | Network driver -`.Scope` | Network scope (local, global) -`.Mountpoint` | Whether the network is internal or not. -`.Labels` | All labels assigned to the volume. -`.Label` | Value of a specific label for this volume. For example `{{.Label "project.version"}}` - -When using the `--format` option, the `volume ls` command will either -output the data exactly as the template declares or, when using the -`table` directive, includes column headers as well. - -The following example uses a template without headers and outputs the -`Name` and `Driver` entries separated by a colon for all volumes: - -```bash -$ docker volume ls --format "{{.Name}}: {{.Driver}}" -vol1: local -vol2: local -vol3: local -``` - -## Related information - -* [volume create](volume_create.md) -* [volume inspect](volume_inspect.md) -* [volume rm](volume_rm.md) -* [volume prune](volume_prune.md) -* [Understand Data Volumes](https://docs.docker.com/engine/tutorials/dockervolumes/) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/volume_prune.md b/vendor/github.com/docker/docker/docs/reference/commandline/volume_prune.md deleted file mode 100644 index d910a49..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/volume_prune.md +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: "volume prune" -description: "Remove unused volumes" -keywords: "volume, prune, delete" ---- - - - -# volume prune - -```markdown -Usage: docker volume prune [OPTIONS] - -Remove all unused volumes - -Options: - -f, --force Do not prompt for confirmation - --help Print usage -``` - -Remove all unused volumes. Unused volumes are those which are not referenced by any containers - -Example output: - -```bash -$ docker volume prune -WARNING! This will remove all volumes not used by at least one container. -Are you sure you want to continue? [y/N] y -Deleted Volumes: -07c7bdf3e34ab76d921894c2b834f073721fccfbbcba792aa7648e3a7a664c2e -my-named-vol - -Total reclaimed space: 36 B -``` - -## Related information - -* [volume create](volume_create.md) -* [volume ls](volume_ls.md) -* [volume inspect](volume_inspect.md) -* [volume rm](volume_rm.md) -* [Understand Data Volumes](https://docs.docker.com/engine/tutorials/dockervolumes/) -* [system df](system_df.md) -* [container prune](container_prune.md) -* [image prune](image_prune.md) -* [network prune](network_prune.md) -* [system prune](system_prune.md) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/volume_rm.md b/vendor/github.com/docker/docker/docs/reference/commandline/volume_rm.md deleted file mode 100644 index 1bf9dba..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/volume_rm.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: "volume rm" -description: "the volume rm command description and usage" -keywords: "volume, rm" ---- - - - -# volume rm - -```markdown -Usage: docker volume rm [OPTIONS] VOLUME [VOLUME...] - -Remove one or more volumes - -Aliases: - rm, remove - -Options: - -f, --force Force the removal of one or more volumes - --help Print usage -``` - -Remove one or more volumes. You cannot remove a volume that is in use by a container. - - $ docker volume rm hello - hello - -## Related information - -* [volume create](volume_create.md) -* [volume inspect](volume_inspect.md) -* [volume ls](volume_ls.md) -* [volume prune](volume_prune.md) -* [Understand Data Volumes](https://docs.docker.com/engine/tutorials/dockervolumes/) diff --git a/vendor/github.com/docker/docker/docs/reference/commandline/wait.md b/vendor/github.com/docker/docker/docs/reference/commandline/wait.md deleted file mode 100644 index a07b82b..0000000 --- a/vendor/github.com/docker/docker/docs/reference/commandline/wait.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: "wait" -description: "The wait command description and usage" -keywords: "container, stop, wait" ---- - - - -# wait - -```markdown -Usage: docker wait CONTAINER [CONTAINER...] - -Block until one or more containers stop, then print their exit codes - -Options: - --help Print usage -``` diff --git a/vendor/github.com/docker/docker/docs/reference/glossary.md b/vendor/github.com/docker/docker/docs/reference/glossary.md deleted file mode 100644 index 0bc39a2..0000000 --- a/vendor/github.com/docker/docker/docs/reference/glossary.md +++ /dev/null @@ -1,286 +0,0 @@ ---- -title: "Docker Glossary" -description: "Glossary of terms used around Docker" -keywords: "glossary, docker, terms, definitions" ---- - - - -# Glossary - -A list of terms used around the Docker project. - -## aufs - -aufs (advanced multi layered unification filesystem) is a Linux [filesystem](#filesystem) that -Docker supports as a storage backend. It implements the -[union mount](http://en.wikipedia.org/wiki/Union_mount) for Linux file systems. - -## base image - -An image that has no parent is a **base image**. - -## boot2docker - -[boot2docker](http://boot2docker.io/) is a lightweight Linux distribution made -specifically to run Docker containers. The boot2docker management tool for Mac and Windows was deprecated and replaced by [`docker-machine`](#machine) which you can install with the Docker Toolbox. - -## btrfs - -btrfs (B-tree file system) is a Linux [filesystem](#filesystem) that Docker -supports as a storage backend. It is a [copy-on-write](http://en.wikipedia.org/wiki/Copy-on-write) -filesystem. - -## build - -build is the process of building Docker images using a [Dockerfile](#dockerfile). -The build uses a Dockerfile and a "context". The context is the set of files in the -directory in which the image is built. - -## cgroups - -cgroups is a Linux kernel feature that limits, accounts for, and isolates -the resource usage (CPU, memory, disk I/O, network, etc.) of a collection -of processes. Docker relies on cgroups to control and isolate resource limits. - -*Also known as : control groups* - -## Compose - -[Compose](https://github.com/docker/compose) is a tool for defining and -running complex applications with Docker. With compose, you define a -multi-container application in a single file, then spin your -application up in a single command which does everything that needs to -be done to get it running. - -*Also known as : docker-compose, fig* - -## container - -A container is a runtime instance of a [docker image](#image). - -A Docker container consists of - -- A Docker image -- Execution environment -- A standard set of instructions - -The concept is borrowed from Shipping Containers, which define a standard to ship -goods globally. Docker defines a standard to ship software. - -## data volume - -A data volume is a specially-designated directory within one or more containers -that bypasses the Union File System. Data volumes are designed to persist data, -independent of the container's life cycle. Docker therefore never automatically -delete volumes when you remove a container, nor will it "garbage collect" -volumes that are no longer referenced by a container. - - -## Docker - -The term Docker can refer to - -- The Docker project as a whole, which is a platform for developers and sysadmins to -develop, ship, and run applications -- The docker daemon process running on the host which manages images and containers - - -## Docker Hub - -The [Docker Hub](https://hub.docker.com/) is a centralized resource for working with -Docker and its components. It provides the following services: - -- Docker image hosting -- User authentication -- Automated image builds and work-flow tools such as build triggers and web hooks -- Integration with GitHub and Bitbucket - - -## Dockerfile - -A Dockerfile is a text document that contains all the commands you would -normally execute manually in order to build a Docker image. Docker can -build images automatically by reading the instructions from a Dockerfile. - -## filesystem - -A file system is the method an operating system uses to name files -and assign them locations for efficient storage and retrieval. - -Examples : - -- Linux : ext4, aufs, btrfs, zfs -- Windows : NTFS -- macOS : HFS+ - -## image - -Docker images are the basis of [containers](#container). An Image is an -ordered collection of root filesystem changes and the corresponding -execution parameters for use within a container runtime. An image typically -contains a union of layered filesystems stacked on top of each other. An image -does not have state and it never changes. - -## libcontainer - -libcontainer provides a native Go implementation for creating containers with -namespaces, cgroups, capabilities, and filesystem access controls. It allows -you to manage the lifecycle of the container performing additional operations -after the container is created. - -## libnetwork - -libnetwork provides a native Go implementation for creating and managing container -network namespaces and other network resources. It manage the networking lifecycle -of the container performing additional operations after the container is created. - -## link - -links provide a legacy interface to connect Docker containers running on the -same host to each other without exposing the hosts' network ports. Use the -Docker networks feature instead. - -## Machine - -[Machine](https://github.com/docker/machine) is a Docker tool which -makes it really easy to create Docker hosts on your computer, on -cloud providers and inside your own data center. It creates servers, -installs Docker on them, then configures the Docker client to talk to them. - -*Also known as : docker-machine* - -## node - -A [node](https://docs.docker.com/engine/swarm/how-swarm-mode-works/nodes/) is a physical or virtual -machine running an instance of the Docker Engine in swarm mode. - -**Manager nodes** perform swarm management and orchestration duties. By default -manager nodes are also worker nodes. - -**Worker nodes** execute tasks. - -## overlay network driver - -Overlay network driver provides out of the box multi-host network connectivity -for docker containers in a cluster. - -## overlay storage driver - -OverlayFS is a [filesystem](#filesystem) service for Linux which implements a -[union mount](http://en.wikipedia.org/wiki/Union_mount) for other file systems. -It is supported by the Docker daemon as a storage driver. - -## registry - -A Registry is a hosted service containing [repositories](#repository) of [images](#image) -which responds to the Registry API. - -The default registry can be accessed using a browser at [Docker Hub](#docker-hub) -or using the `docker search` command. - -## repository - -A repository is a set of Docker images. A repository can be shared by pushing it -to a [registry](#registry) server. The different images in the repository can be -labeled using [tags](#tag). - -Here is an example of the shared [nginx repository](https://hub.docker.com/_/nginx/) -and its [tags](https://hub.docker.com/r/library/nginx/tags/) - - -## service - -A [service](https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/) is the definition of how -you want to run your application containers in a swarm. At the most basic level -a service defines which container image to run in the swarm and which commands -to run in the container. For orchestration purposes, the service defines the -"desired state", meaning how many containers to run as tasks and constraints for -deploying the containers. - -Frequently a service is a microservice within the context of some larger -application. Examples of services might include an HTTP server, a database, or -any other type of executable program that you wish to run in a distributed -environment. - -## service discovery - -Swarm mode [service discovery](https://docs.docker.com/engine/swarm/networking/#use-swarm-mode-service-discovery) is a DNS component -internal to the swarm that automatically assigns each service on an overlay -network in the swarm a VIP and DNS entry. Containers on the network share DNS -mappings for the service via gossip so any container on the network can access -the service via its service name. - -You don’t need to expose service-specific ports to make the service available to -other services on the same overlay network. The swarm’s internal load balancer -automatically distributes requests to the service VIP among the active tasks. - -## swarm - -A [swarm](https://docs.docker.com/engine/swarm/) is a cluster of one or more Docker Engines running in [swarm mode](#swarm-mode). - -## Docker Swarm - -Do not confuse [Docker Swarm](https://github.com/docker/swarm) with the [swarm mode](#swarm-mode) features in Docker Engine. - -Docker Swarm is the name of a standalone native clustering tool for Docker. -Docker Swarm pools together several Docker hosts and exposes them as a single -virtual Docker host. It serves the standard Docker API, so any tool that already -works with Docker can now transparently scale up to multiple hosts. - -*Also known as : docker-swarm* - -## swarm mode - -[Swarm mode](https://docs.docker.com/engine/swarm/) refers to cluster management and orchestration -features embedded in Docker Engine. When you initialize a new swarm (cluster) or -join nodes to a swarm, the Docker Engine runs in swarm mode. - -## tag - -A tag is a label applied to a Docker image in a [repository](#repository). -tags are how various images in a repository are distinguished from each other. - -*Note : This label is not related to the key=value labels set for docker daemon* - -## task - -A [task](https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/#/tasks-and-scheduling) is the -atomic unit of scheduling within a swarm. A task carries a Docker container and -the commands to run inside the container. Manager nodes assign tasks to worker -nodes according to the number of replicas set in the service scale. - -The diagram below illustrates the relationship of services to tasks and -containers. - -![services diagram](https://docs.docker.com/engine/swarm/images/services-diagram.png) - -## Toolbox - -Docker Toolbox is the installer for Mac and Windows users. - - -## Union file system - -Union file systems, or UnionFS, are file systems that operate by creating layers, making them -very lightweight and fast. Docker uses union file systems to provide the building -blocks for containers. - - -## virtual machine - -A virtual machine is a program that emulates a complete computer and imitates dedicated hardware. -It shares physical hardware resources with other users but isolates the operating system. The -end user has the same experience on a Virtual Machine as they would have on dedicated hardware. - -Compared to containers, a virtual machine is heavier to run, provides more isolation, -gets its own set of resources and does minimal sharing. - -*Also known as : VM* diff --git a/vendor/github.com/docker/docker/docs/reference/index.md b/vendor/github.com/docker/docker/docs/reference/index.md deleted file mode 100644 index f24c342..0000000 --- a/vendor/github.com/docker/docker/docs/reference/index.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: "Engine reference" -description: "Docker Engine reference" -keywords: "Engine" ---- - - - -# Engine reference - -* [Dockerfile reference](builder.md) -* [Docker run reference](run.md) -* [Command line reference](commandline/index.md) -* [API Reference](https://docs.docker.com/engine/api/) diff --git a/vendor/github.com/docker/docker/docs/reference/run.md b/vendor/github.com/docker/docker/docs/reference/run.md deleted file mode 100644 index 73769ed..0000000 --- a/vendor/github.com/docker/docker/docs/reference/run.md +++ /dev/null @@ -1,1555 +0,0 @@ ---- -title: "Docker run reference" -description: "Configure containers at runtime" -keywords: "docker, run, configure, runtime" ---- - - - -# Docker run reference - -Docker runs processes in isolated containers. A container is a process -which runs on a host. The host may be local or remote. When an operator -executes `docker run`, the container process that runs is isolated in -that it has its own file system, its own networking, and its own -isolated process tree separate from the host. - -This page details how to use the `docker run` command to define the -container's resources at runtime. - -## General form - -The basic `docker run` command takes this form: - - $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...] - -The `docker run` command must specify an [*IMAGE*](glossary.md#image) -to derive the container from. An image developer can define image -defaults related to: - - * detached or foreground running - * container identification - * network settings - * runtime constraints on CPU and memory - -With the `docker run [OPTIONS]` an operator can add to or override the -image defaults set by a developer. And, additionally, operators can -override nearly all the defaults set by the Docker runtime itself. The -operator's ability to override image and Docker runtime defaults is why -[*run*](commandline/run.md) has more options than any -other `docker` command. - -To learn how to interpret the types of `[OPTIONS]`, see [*Option -types*](commandline/cli.md#option-types). - -> **Note**: Depending on your Docker system configuration, you may be -> required to preface the `docker run` command with `sudo`. To avoid -> having to use `sudo` with the `docker` command, your system -> administrator can create a Unix group called `docker` and add users to -> it. For more information about this configuration, refer to the Docker -> installation documentation for your operating system. - - -## Operator exclusive options - -Only the operator (the person executing `docker run`) can set the -following options. - - - [Detached vs foreground](#detached-vs-foreground) - - [Detached (-d)](#detached--d) - - [Foreground](#foreground) - - [Container identification](#container-identification) - - [Name (--name)](#name---name) - - [PID equivalent](#pid-equivalent) - - [IPC settings (--ipc)](#ipc-settings---ipc) - - [Network settings](#network-settings) - - [Restart policies (--restart)](#restart-policies---restart) - - [Clean up (--rm)](#clean-up---rm) - - [Runtime constraints on resources](#runtime-constraints-on-resources) - - [Runtime privilege and Linux capabilities](#runtime-privilege-and-linux-capabilities) - -## Detached vs foreground - -When starting a Docker container, you must first decide if you want to -run the container in the background in a "detached" mode or in the -default foreground mode: - - -d=false: Detached mode: Run container in the background, print new container id - -### Detached (-d) - -To start a container in detached mode, you use `-d=true` or just `-d` option. By -design, containers started in detached mode exit when the root process used to -run the container exits. A container in detached mode cannot be automatically -removed when it stops, this means you cannot use the `--rm` option with `-d` option. - -Do not pass a `service x start` command to a detached container. For example, this -command attempts to start the `nginx` service. - - $ docker run -d -p 80:80 my_image service nginx start - -This succeeds in starting the `nginx` service inside the container. However, it -fails the detached container paradigm in that, the root process (`service nginx -start`) returns and the detached container stops as designed. As a result, the -`nginx` service is started but could not be used. Instead, to start a process -such as the `nginx` web server do the following: - - $ docker run -d -p 80:80 my_image nginx -g 'daemon off;' - -To do input/output with a detached container use network connections or shared -volumes. These are required because the container is no longer listening to the -command line where `docker run` was run. - -To reattach to a detached container, use `docker` -[*attach*](commandline/attach.md) command. - -### Foreground - -In foreground mode (the default when `-d` is not specified), `docker -run` can start the process in the container and attach the console to -the process's standard input, output, and standard error. It can even -pretend to be a TTY (this is what most command line executables expect) -and pass along signals. All of that is configurable: - - -a=[] : Attach to `STDIN`, `STDOUT` and/or `STDERR` - -t : Allocate a pseudo-tty - --sig-proxy=true: Proxy all received signals to the process (non-TTY mode only) - -i : Keep STDIN open even if not attached - -If you do not specify `-a` then Docker will [attach to both stdout and stderr -]( https://github.com/docker/docker/blob/4118e0c9eebda2412a09ae66e90c34b85fae3275/runconfig/opts/parse.go#L267). -You can specify to which of the three standard streams (`STDIN`, `STDOUT`, -`STDERR`) you'd like to connect instead, as in: - - $ docker run -a stdin -a stdout -i -t ubuntu /bin/bash - -For interactive processes (like a shell), you must use `-i -t` together in -order to allocate a tty for the container process. `-i -t` is often written `-it` -as you'll see in later examples. Specifying `-t` is forbidden when the client -standard output is redirected or piped, such as in: - - $ echo test | docker run -i busybox cat - ->**Note**: A process running as PID 1 inside a container is treated ->specially by Linux: it ignores any signal with the default action. ->So, the process will not terminate on `SIGINT` or `SIGTERM` unless it is ->coded to do so. - -## Container identification - -### Name (--name) - -The operator can identify a container in three ways: - -| Identifier type | Example value | -| --------------------- | ------------------------------------------------------------------ | -| UUID long identifier | "f78375b1c487e03c9438c729345e54db9d20cfa2ac1fc3494b6eb60872e74778" | -| UUID short identifier | "f78375b1c487" | -| Name | "evil_ptolemy" | - -The UUID identifiers come from the Docker daemon. If you do not assign a -container name with the `--name` option, then the daemon generates a random -string name for you. Defining a `name` can be a handy way to add meaning to a -container. If you specify a `name`, you can use it when referencing the -container within a Docker network. This works for both background and foreground -Docker containers. - -> **Note**: Containers on the default bridge network must be linked to -> communicate by name. - -### PID equivalent - -Finally, to help with automation, you can have Docker write the -container ID out to a file of your choosing. This is similar to how some -programs might write out their process ID to a file (you've seen them as -PID files): - - --cidfile="": Write the container ID to the file - -### Image[:tag] - -While not strictly a means of identifying a container, you can specify a version of an -image you'd like to run the container with by adding `image[:tag]` to the command. For -example, `docker run ubuntu:14.04`. - -### Image[@digest] - -Images using the v2 or later image format have a content-addressable identifier -called a digest. As long as the input used to generate the image is unchanged, -the digest value is predictable and referenceable. - -The following example runs a container from the `alpine` image with the -`sha256:9cacb71397b640eca97488cf08582ae4e4068513101088e9f96c9814bfda95e0` digest: - - $ docker run alpine@sha256:9cacb71397b640eca97488cf08582ae4e4068513101088e9f96c9814bfda95e0 date - -## PID settings (--pid) - - --pid="" : Set the PID (Process) Namespace mode for the container, - 'container:': joins another container's PID namespace - 'host': use the host's PID namespace inside the container - -By default, all containers have the PID namespace enabled. - -PID namespace provides separation of processes. The PID Namespace removes the -view of the system processes, and allows process ids to be reused including -pid 1. - -In certain cases you want your container to share the host's process namespace, -basically allowing processes within the container to see all of the processes -on the system. For example, you could build a container with debugging tools -like `strace` or `gdb`, but want to use these tools when debugging processes -within the container. - -### Example: run htop inside a container - -Create this Dockerfile: - -``` -FROM alpine:latest -RUN apk add --update htop && rm -rf /var/cache/apk/* -CMD ["htop"] -``` - -Build the Dockerfile and tag the image as `myhtop`: - -```bash -$ docker build -t myhtop . -``` - -Use the following command to run `htop` inside a container: - -``` -$ docker run -it --rm --pid=host myhtop -``` - -Joining another container's pid namespace can be used for debugging that container. - -### Example - -Start a container running a redis server: - -```bash -$ docker run --name my-redis -d redis -``` - -Debug the redis container by running another container that has strace in it: - -```bash -$ docker run -it --pid=container:my-redis my_strace_docker_image bash -$ strace -p 1 -``` - -## UTS settings (--uts) - - --uts="" : Set the UTS namespace mode for the container, - 'host': use the host's UTS namespace inside the container - -The UTS namespace is for setting the hostname and the domain that is visible -to running processes in that namespace. By default, all containers, including -those with `--network=host`, have their own UTS namespace. The `host` setting will -result in the container using the same UTS namespace as the host. Note that -`--hostname` is invalid in `host` UTS mode. - -You may wish to share the UTS namespace with the host if you would like the -hostname of the container to change as the hostname of the host changes. A -more advanced use case would be changing the host's hostname from a container. - -## IPC settings (--ipc) - - --ipc="" : Set the IPC mode for the container, - 'container:': reuses another container's IPC namespace - 'host': use the host's IPC namespace inside the container - -By default, all containers have the IPC namespace enabled. - -IPC (POSIX/SysV IPC) namespace provides separation of named shared memory -segments, semaphores and message queues. - -Shared memory segments are used to accelerate inter-process communication at -memory speed, rather than through pipes or through the network stack. Shared -memory is commonly used by databases and custom-built (typically C/OpenMPI, -C++/using boost libraries) high performance applications for scientific -computing and financial services industries. If these types of applications -are broken into multiple containers, you might need to share the IPC mechanisms -of the containers. - -## Network settings - - --dns=[] : Set custom dns servers for the container - --network="bridge" : Connect a container to a network - 'bridge': create a network stack on the default Docker bridge - 'none': no networking - 'container:': reuse another container's network stack - 'host': use the Docker host network stack - '|': connect to a user-defined network - --network-alias=[] : Add network-scoped alias for the container - --add-host="" : Add a line to /etc/hosts (host:IP) - --mac-address="" : Sets the container's Ethernet device's MAC address - --ip="" : Sets the container's Ethernet device's IPv4 address - --ip6="" : Sets the container's Ethernet device's IPv6 address - --link-local-ip=[] : Sets one or more container's Ethernet device's link local IPv4/IPv6 addresses - -By default, all containers have networking enabled and they can make any -outgoing connections. The operator can completely disable networking -with `docker run --network none` which disables all incoming and outgoing -networking. In cases like this, you would perform I/O through files or -`STDIN` and `STDOUT` only. - -Publishing ports and linking to other containers only works with the default (bridge). The linking feature is a legacy feature. You should always prefer using Docker network drivers over linking. - -Your container will use the same DNS servers as the host by default, but -you can override this with `--dns`. - -By default, the MAC address is generated using the IP address allocated to the -container. You can set the container's MAC address explicitly by providing a -MAC address via the `--mac-address` parameter (format:`12:34:56:78:9a:bc`).Be -aware that Docker does not check if manually specified MAC addresses are unique. - -Supported networks : - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NetworkDescription
none - No networking in the container. -
bridge (default) - Connect the container to the bridge via veth interfaces. -
host - Use the host's network stack inside the container. -
container:<name|id> - Use the network stack of another container, specified via - its name or id. -
NETWORK - Connects the container to a user created network (using docker network create command) -
- -#### Network: none - -With the network is `none` a container will not have -access to any external routes. The container will still have a -`loopback` interface enabled in the container but it does not have any -routes to external traffic. - -#### Network: bridge - -With the network set to `bridge` a container will use docker's -default networking setup. A bridge is setup on the host, commonly named -`docker0`, and a pair of `veth` interfaces will be created for the -container. One side of the `veth` pair will remain on the host attached -to the bridge while the other side of the pair will be placed inside the -container's namespaces in addition to the `loopback` interface. An IP -address will be allocated for containers on the bridge's network and -traffic will be routed though this bridge to the container. - -Containers can communicate via their IP addresses by default. To communicate by -name, they must be linked. - -#### Network: host - -With the network set to `host` a container will share the host's -network stack and all interfaces from the host will be available to the -container. The container's hostname will match the hostname on the host -system. Note that `--mac-address` is invalid in `host` netmode. Even in `host` -network mode a container has its own UTS namespace by default. As such -`--hostname` is allowed in `host` network mode and will only change the -hostname inside the container. -Similar to `--hostname`, the `--add-host`, `--dns`, `--dns-search`, and -`--dns-option` options can be used in `host` network mode. These options update -`/etc/hosts` or `/etc/resolv.conf` inside the container. No change are made to -`/etc/hosts` and `/etc/resolv.conf` on the host. - -Compared to the default `bridge` mode, the `host` mode gives *significantly* -better networking performance since it uses the host's native networking stack -whereas the bridge has to go through one level of virtualization through the -docker daemon. It is recommended to run containers in this mode when their -networking performance is critical, for example, a production Load Balancer -or a High Performance Web Server. - -> **Note**: `--network="host"` gives the container full access to local system -> services such as D-bus and is therefore considered insecure. - -#### Network: container - -With the network set to `container` a container will share the -network stack of another container. The other container's name must be -provided in the format of `--network container:`. Note that `--add-host` -`--hostname` `--dns` `--dns-search` `--dns-option` and `--mac-address` are -invalid in `container` netmode, and `--publish` `--publish-all` `--expose` are -also invalid in `container` netmode. - -Example running a Redis container with Redis binding to `localhost` then -running the `redis-cli` command and connecting to the Redis server over the -`localhost` interface. - - $ docker run -d --name redis example/redis --bind 127.0.0.1 - $ # use the redis container's network stack to access localhost - $ docker run --rm -it --network container:redis example/redis-cli -h 127.0.0.1 - -#### User-defined network - -You can create a network using a Docker network driver or an external network -driver plugin. You can connect multiple containers to the same network. Once -connected to a user-defined network, the containers can communicate easily using -only another container's IP address or name. - -For `overlay` networks or custom plugins that support multi-host connectivity, -containers connected to the same multi-host network but launched from different -Engines can also communicate in this way. - -The following example creates a network using the built-in `bridge` network -driver and running a container in the created network - -``` -$ docker network create -d bridge my-net -$ docker run --network=my-net -itd --name=container3 busybox -``` - -### Managing /etc/hosts - -Your container will have lines in `/etc/hosts` which define the hostname of the -container itself as well as `localhost` and a few other common things. The -`--add-host` flag can be used to add additional lines to `/etc/hosts`. - - $ docker run -it --add-host db-static:86.75.30.9 ubuntu cat /etc/hosts - 172.17.0.22 09d03f76bf2c - fe00::0 ip6-localnet - ff00::0 ip6-mcastprefix - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - 127.0.0.1 localhost - ::1 localhost ip6-localhost ip6-loopback - 86.75.30.9 db-static - -If a container is connected to the default bridge network and `linked` -with other containers, then the container's `/etc/hosts` file is updated -with the linked container's name. - -If the container is connected to user-defined network, the container's -`/etc/hosts` file is updated with names of all other containers in that -user-defined network. - -> **Note** Since Docker may live update the container’s `/etc/hosts` file, there -may be situations when processes inside the container can end up reading an -empty or incomplete `/etc/hosts` file. In most cases, retrying the read again -should fix the problem. - -## Restart policies (--restart) - -Using the `--restart` flag on Docker run you can specify a restart policy for -how a container should or should not be restarted on exit. - -When a restart policy is active on a container, it will be shown as either `Up` -or `Restarting` in [`docker ps`](commandline/ps.md). It can also be -useful to use [`docker events`](commandline/events.md) to see the -restart policy in effect. - -Docker supports the following restart policies: - - - - - - - - - - - - - - - - - - - - - - - - - - -
PolicyResult
no - Do not automatically restart the container when it exits. This is the - default. -
- - on-failure[:max-retries] - - - Restart only if the container exits with a non-zero exit status. - Optionally, limit the number of restart retries the Docker - daemon attempts. -
always - Always restart the container regardless of the exit status. - When you specify always, the Docker daemon will try to restart - the container indefinitely. The container will also always start - on daemon startup, regardless of the current state of the container. -
unless-stopped - Always restart the container regardless of the exit status, but - do not start it on daemon startup if the container has been put - to a stopped state before. -
- -An ever increasing delay (double the previous delay, starting at 100 -milliseconds) is added before each restart to prevent flooding the server. -This means the daemon will wait for 100 ms, then 200 ms, 400, 800, 1600, -and so on until either the `on-failure` limit is hit, or when you `docker stop` -or `docker rm -f` the container. - -If a container is successfully restarted (the container is started and runs -for at least 10 seconds), the delay is reset to its default value of 100 ms. - -You can specify the maximum amount of times Docker will try to restart the -container when using the **on-failure** policy. The default is that Docker -will try forever to restart the container. The number of (attempted) restarts -for a container can be obtained via [`docker inspect`](commandline/inspect.md). For example, to get the number of restarts -for container "my-container"; - - {% raw %} - $ docker inspect -f "{{ .RestartCount }}" my-container - # 2 - {% endraw %} - -Or, to get the last time the container was (re)started; - - {% raw %} - $ docker inspect -f "{{ .State.StartedAt }}" my-container - # 2015-03-04T23:47:07.691840179Z - {% endraw %} - - -Combining `--restart` (restart policy) with the `--rm` (clean up) flag results -in an error. On container restart, attached clients are disconnected. See the -examples on using the [`--rm` (clean up)](#clean-up-rm) flag later in this page. - -### Examples - - $ docker run --restart=always redis - -This will run the `redis` container with a restart policy of **always** -so that if the container exits, Docker will restart it. - - $ docker run --restart=on-failure:10 redis - -This will run the `redis` container with a restart policy of **on-failure** -and a maximum restart count of 10. If the `redis` container exits with a -non-zero exit status more than 10 times in a row Docker will abort trying to -restart the container. Providing a maximum restart limit is only valid for the -**on-failure** policy. - -## Exit Status - -The exit code from `docker run` gives information about why the container -failed to run or why it exited. When `docker run` exits with a non-zero code, -the exit codes follow the `chroot` standard, see below: - -**_125_** if the error is with Docker daemon **_itself_** - - $ docker run --foo busybox; echo $? - # flag provided but not defined: --foo - See 'docker run --help'. - 125 - -**_126_** if the **_contained command_** cannot be invoked - - $ docker run busybox /etc; echo $? - # docker: Error response from daemon: Container command '/etc' could not be invoked. - 126 - -**_127_** if the **_contained command_** cannot be found - - $ docker run busybox foo; echo $? - # docker: Error response from daemon: Container command 'foo' not found or does not exist. - 127 - -**_Exit code_** of **_contained command_** otherwise - - $ docker run busybox /bin/sh -c 'exit 3'; echo $? - # 3 - -## Clean up (--rm) - -By default a container's file system persists even after the container -exits. This makes debugging a lot easier (since you can inspect the -final state) and you retain all your data by default. But if you are -running short-term **foreground** processes, these container file -systems can really pile up. If instead you'd like Docker to -**automatically clean up the container and remove the file system when -the container exits**, you can add the `--rm` flag: - - --rm=false: Automatically remove the container when it exits (incompatible with -d) - -> **Note**: When you set the `--rm` flag, Docker also removes the volumes -associated with the container when the container is removed. This is similar -to running `docker rm -v my-container`. Only volumes that are specified without a -name are removed. For example, with -`docker run --rm -v /foo -v awesome:/bar busybox top`, the volume for `/foo` will be removed, -but the volume for `/bar` will not. Volumes inherited via `--volumes-from` will be removed -with the same logic -- if the original volume was specified with a name it will **not** be removed. - -## Security configuration - --security-opt="label=user:USER" : Set the label user for the container - --security-opt="label=role:ROLE" : Set the label role for the container - --security-opt="label=type:TYPE" : Set the label type for the container - --security-opt="label=level:LEVEL" : Set the label level for the container - --security-opt="label=disable" : Turn off label confinement for the container - --security-opt="apparmor=PROFILE" : Set the apparmor profile to be applied to the container - --security-opt="no-new-privileges" : Disable container processes from gaining new privileges - --security-opt="seccomp=unconfined" : Turn off seccomp confinement for the container - --security-opt="seccomp=profile.json": White listed syscalls seccomp Json file to be used as a seccomp filter - - -You can override the default labeling scheme for each container by specifying -the `--security-opt` flag. Specifying the level in the following command -allows you to share the same content between containers. - - $ docker run --security-opt label=level:s0:c100,c200 -it fedora bash - -> **Note**: Automatic translation of MLS labels is not currently supported. - -To disable the security labeling for this container versus running with the -`--privileged` flag, use the following command: - - $ docker run --security-opt label=disable -it fedora bash - -If you want a tighter security policy on the processes within a container, -you can specify an alternate type for the container. You could run a container -that is only allowed to listen on Apache ports by executing the following -command: - - $ docker run --security-opt label=type:svirt_apache_t -it centos bash - -> **Note**: You would have to write policy defining a `svirt_apache_t` type. - -If you want to prevent your container processes from gaining additional -privileges, you can execute the following command: - - $ docker run --security-opt no-new-privileges -it centos bash - -This means that commands that raise privileges such as `su` or `sudo` will no longer work. -It also causes any seccomp filters to be applied later, after privileges have been dropped -which may mean you can have a more restrictive set of filters. -For more details, see the [kernel documentation](https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt). - -## Specifying custom cgroups - -Using the `--cgroup-parent` flag, you can pass a specific cgroup to run a -container in. This allows you to create and manage cgroups on their own. You can -define custom resources for those cgroups and put containers under a common -parent group. - -## Runtime constraints on resources - -The operator can also adjust the performance parameters of the -container: - -| Option | Description | -| -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -| `-m`, `--memory=""` | Memory limit (format: `[]`). Number is a positive integer. Unit can be one of `b`, `k`, `m`, or `g`. Minimum is 4M. | -| `--memory-swap=""` | Total memory limit (memory + swap, format: `[]`). Number is a positive integer. Unit can be one of `b`, `k`, `m`, or `g`. | -| `--memory-reservation=""` | Memory soft limit (format: `[]`). Number is a positive integer. Unit can be one of `b`, `k`, `m`, or `g`. | -| `--kernel-memory=""` | Kernel memory limit (format: `[]`). Number is a positive integer. Unit can be one of `b`, `k`, `m`, or `g`. Minimum is 4M. | -| `-c`, `--cpu-shares=0` | CPU shares (relative weight) | -| `--cpus=0.000` | Number of CPUs. Number is a fractional number. 0.000 means no limit. | -| `--cpu-period=0` | Limit the CPU CFS (Completely Fair Scheduler) period | -| `--cpuset-cpus=""` | CPUs in which to allow execution (0-3, 0,1) | -| `--cpuset-mems=""` | Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. | -| `--cpu-quota=0` | Limit the CPU CFS (Completely Fair Scheduler) quota | -| `--cpu-rt-period=0` | Limit the CPU real-time period. In microseconds. Requires parent cgroups be set and cannot be higher than parent. Also check rtprio ulimits. | -| `--cpu-rt-runtime=0` | Limit the CPU real-time runtime. In microseconds. Requires parent cgroups be set and cannot be higher than parent. Also check rtprio ulimits. | -| `--blkio-weight=0` | Block IO weight (relative weight) accepts a weight value between 10 and 1000. | -| `--blkio-weight-device=""` | Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`) | -| `--device-read-bps=""` | Limit read rate from a device (format: `:[]`). Number is a positive integer. Unit can be one of `kb`, `mb`, or `gb`. | -| `--device-write-bps=""` | Limit write rate to a device (format: `:[]`). Number is a positive integer. Unit can be one of `kb`, `mb`, or `gb`. | -| `--device-read-iops="" ` | Limit read rate (IO per second) from a device (format: `:`). Number is a positive integer. | -| `--device-write-iops="" ` | Limit write rate (IO per second) to a device (format: `:`). Number is a positive integer. | -| `--oom-kill-disable=false` | Whether to disable OOM Killer for the container or not. | -| `--oom-score-adj=0` | Tune container's OOM preferences (-1000 to 1000) | -| `--memory-swappiness=""` | Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. | -| `--shm-size=""` | Size of `/dev/shm`. The format is ``. `number` must be greater than `0`. Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you omit the unit, the system uses bytes. If you omit the size entirely, the system uses `64m`. | - -### User memory constraints - -We have four ways to set user memory usage: - - - - - - - - - - - - - - - - - - - - - - - - - - -
OptionResult
- memory=inf, memory-swap=inf (default) - - There is no memory limit for the container. The container can use - as much memory as needed. -
memory=L<inf, memory-swap=inf - (specify memory and set memory-swap as -1) The container is - not allowed to use more than L bytes of memory, but can use as much swap - as is needed (if the host supports swap memory). -
memory=L<inf, memory-swap=2*L - (specify memory without memory-swap) The container is not allowed to - use more than L bytes of memory, swap plus memory usage is double - of that. -
- memory=L<inf, memory-swap=S<inf, L<=S - - (specify both memory and memory-swap) The container is not allowed to - use more than L bytes of memory, swap plus memory usage is limited - by S. -
- -Examples: - - $ docker run -it ubuntu:14.04 /bin/bash - -We set nothing about memory, this means the processes in the container can use -as much memory and swap memory as they need. - - $ docker run -it -m 300M --memory-swap -1 ubuntu:14.04 /bin/bash - -We set memory limit and disabled swap memory limit, this means the processes in -the container can use 300M memory and as much swap memory as they need (if the -host supports swap memory). - - $ docker run -it -m 300M ubuntu:14.04 /bin/bash - -We set memory limit only, this means the processes in the container can use -300M memory and 300M swap memory, by default, the total virtual memory size -(--memory-swap) will be set as double of memory, in this case, memory + swap -would be 2*300M, so processes can use 300M swap memory as well. - - $ docker run -it -m 300M --memory-swap 1G ubuntu:14.04 /bin/bash - -We set both memory and swap memory, so the processes in the container can use -300M memory and 700M swap memory. - -Memory reservation is a kind of memory soft limit that allows for greater -sharing of memory. Under normal circumstances, containers can use as much of -the memory as needed and are constrained only by the hard limits set with the -`-m`/`--memory` option. When memory reservation is set, Docker detects memory -contention or low memory and forces containers to restrict their consumption to -a reservation limit. - -Always set the memory reservation value below the hard limit, otherwise the hard -limit takes precedence. A reservation of 0 is the same as setting no -reservation. By default (without reservation set), memory reservation is the -same as the hard memory limit. - -Memory reservation is a soft-limit feature and does not guarantee the limit -won't be exceeded. Instead, the feature attempts to ensure that, when memory is -heavily contended for, memory is allocated based on the reservation hints/setup. - -The following example limits the memory (`-m`) to 500M and sets the memory -reservation to 200M. - -```bash -$ docker run -it -m 500M --memory-reservation 200M ubuntu:14.04 /bin/bash -``` - -Under this configuration, when the container consumes memory more than 200M and -less than 500M, the next system memory reclaim attempts to shrink container -memory below 200M. - -The following example set memory reservation to 1G without a hard memory limit. - -```bash -$ docker run -it --memory-reservation 1G ubuntu:14.04 /bin/bash -``` - -The container can use as much memory as it needs. The memory reservation setting -ensures the container doesn't consume too much memory for long time, because -every memory reclaim shrinks the container's consumption to the reservation. - -By default, kernel kills processes in a container if an out-of-memory (OOM) -error occurs. To change this behaviour, use the `--oom-kill-disable` option. -Only disable the OOM killer on containers where you have also set the -`-m/--memory` option. If the `-m` flag is not set, this can result in the host -running out of memory and require killing the host's system processes to free -memory. - -The following example limits the memory to 100M and disables the OOM killer for -this container: - - $ docker run -it -m 100M --oom-kill-disable ubuntu:14.04 /bin/bash - -The following example, illustrates a dangerous way to use the flag: - - $ docker run -it --oom-kill-disable ubuntu:14.04 /bin/bash - -The container has unlimited memory which can cause the host to run out memory -and require killing system processes to free memory. The `--oom-score-adj` -parameter can be changed to select the priority of which containers will -be killed when the system is out of memory, with negative scores making them -less likely to be killed an positive more likely. - -### Kernel memory constraints - -Kernel memory is fundamentally different than user memory as kernel memory can't -be swapped out. The inability to swap makes it possible for the container to -block system services by consuming too much kernel memory. Kernel memory includes: - - - stack pages - - slab pages - - sockets memory pressure - - tcp memory pressure - -You can setup kernel memory limit to constrain these kinds of memory. For example, -every process consumes some stack pages. By limiting kernel memory, you can -prevent new processes from being created when the kernel memory usage is too high. - -Kernel memory is never completely independent of user memory. Instead, you limit -kernel memory in the context of the user memory limit. Assume "U" is the user memory -limit and "K" the kernel limit. There are three possible ways to set limits: - - - - - - - - - - - - - - - - - - - - - - -
OptionResult
U != 0, K = inf (default) - This is the standard memory limitation mechanism already present before using - kernel memory. Kernel memory is completely ignored. -
U != 0, K < U - Kernel memory is a subset of the user memory. This setup is useful in - deployments where the total amount of memory per-cgroup is overcommitted. - Overcommitting kernel memory limits is definitely not recommended, since the - box can still run out of non-reclaimable memory. - In this case, you can configure K so that the sum of all groups is - never greater than the total memory. Then, freely set U at the expense of - the system's service quality. -
U != 0, K > U - Since kernel memory charges are also fed to the user counter and reclamation - is triggered for the container for both kinds of memory. This configuration - gives the admin a unified view of memory. It is also useful for people - who just want to track kernel memory usage. -
- -Examples: - - $ docker run -it -m 500M --kernel-memory 50M ubuntu:14.04 /bin/bash - -We set memory and kernel memory, so the processes in the container can use -500M memory in total, in this 500M memory, it can be 50M kernel memory tops. - - $ docker run -it --kernel-memory 50M ubuntu:14.04 /bin/bash - -We set kernel memory without **-m**, so the processes in the container can -use as much memory as they want, but they can only use 50M kernel memory. - -### Swappiness constraint - -By default, a container's kernel can swap out a percentage of anonymous pages. -To set this percentage for a container, specify a `--memory-swappiness` value -between 0 and 100. A value of 0 turns off anonymous page swapping. A value of -100 sets all anonymous pages as swappable. By default, if you are not using -`--memory-swappiness`, memory swappiness value will be inherited from the parent. - -For example, you can set: - - $ docker run -it --memory-swappiness=0 ubuntu:14.04 /bin/bash - -Setting the `--memory-swappiness` option is helpful when you want to retain the -container's working set and to avoid swapping performance penalties. - -### CPU share constraint - -By default, all containers get the same proportion of CPU cycles. This proportion -can be modified by changing the container's CPU share weighting relative -to the weighting of all other running containers. - -To modify the proportion from the default of 1024, use the `-c` or `--cpu-shares` -flag to set the weighting to 2 or higher. If 0 is set, the system will ignore the -value and use the default of 1024. - -The proportion will only apply when CPU-intensive processes are running. -When tasks in one container are idle, other containers can use the -left-over CPU time. The actual amount of CPU time will vary depending on -the number of containers running on the system. - -For example, consider three containers, one has a cpu-share of 1024 and -two others have a cpu-share setting of 512. When processes in all three -containers attempt to use 100% of CPU, the first container would receive -50% of the total CPU time. If you add a fourth container with a cpu-share -of 1024, the first container only gets 33% of the CPU. The remaining containers -receive 16.5%, 16.5% and 33% of the CPU. - -On a multi-core system, the shares of CPU time are distributed over all CPU -cores. Even if a container is limited to less than 100% of CPU time, it can -use 100% of each individual CPU core. - -For example, consider a system with more than three cores. If you start one -container `{C0}` with `-c=512` running one process, and another container -`{C1}` with `-c=1024` running two processes, this can result in the following -division of CPU shares: - - PID container CPU CPU share - 100 {C0} 0 100% of CPU0 - 101 {C1} 1 100% of CPU1 - 102 {C1} 2 100% of CPU2 - -### CPU period constraint - -The default CPU CFS (Completely Fair Scheduler) period is 100ms. We can use -`--cpu-period` to set the period of CPUs to limit the container's CPU usage. -And usually `--cpu-period` should work with `--cpu-quota`. - -Examples: - - $ docker run -it --cpu-period=50000 --cpu-quota=25000 ubuntu:14.04 /bin/bash - -If there is 1 CPU, this means the container can get 50% CPU worth of run-time every 50ms. - -In addition to use `--cpu-period` and `--cpu-quota` for setting CPU period constraints, -it is possible to specify `--cpus` with a float number to achieve the same purpose. -For example, if there is 1 CPU, then `--cpus=0.5` will achieve the same result as -setting `--cpu-period=50000` and `--cpu-quota=25000` (50% CPU). - -The default value for `--cpus` is `0.000`, which means there is no limit. - -For more information, see the [CFS documentation on bandwidth limiting](https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt). - -### Cpuset constraint - -We can set cpus in which to allow execution for containers. - -Examples: - - $ docker run -it --cpuset-cpus="1,3" ubuntu:14.04 /bin/bash - -This means processes in container can be executed on cpu 1 and cpu 3. - - $ docker run -it --cpuset-cpus="0-2" ubuntu:14.04 /bin/bash - -This means processes in container can be executed on cpu 0, cpu 1 and cpu 2. - -We can set mems in which to allow execution for containers. Only effective -on NUMA systems. - -Examples: - - $ docker run -it --cpuset-mems="1,3" ubuntu:14.04 /bin/bash - -This example restricts the processes in the container to only use memory from -memory nodes 1 and 3. - - $ docker run -it --cpuset-mems="0-2" ubuntu:14.04 /bin/bash - -This example restricts the processes in the container to only use memory from -memory nodes 0, 1 and 2. - -### CPU quota constraint - -The `--cpu-quota` flag limits the container's CPU usage. The default 0 value -allows the container to take 100% of a CPU resource (1 CPU). The CFS (Completely Fair -Scheduler) handles resource allocation for executing processes and is default -Linux Scheduler used by the kernel. Set this value to 50000 to limit the container -to 50% of a CPU resource. For multiple CPUs, adjust the `--cpu-quota` as necessary. -For more information, see the [CFS documentation on bandwidth limiting](https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt). - -### Block IO bandwidth (Blkio) constraint - -By default, all containers get the same proportion of block IO bandwidth -(blkio). This proportion is 500. To modify this proportion, change the -container's blkio weight relative to the weighting of all other running -containers using the `--blkio-weight` flag. - -> **Note:** The blkio weight setting is only available for direct IO. Buffered IO -> is not currently supported. - -The `--blkio-weight` flag can set the weighting to a value between 10 to 1000. -For example, the commands below create two containers with different blkio -weight: - - $ docker run -it --name c1 --blkio-weight 300 ubuntu:14.04 /bin/bash - $ docker run -it --name c2 --blkio-weight 600 ubuntu:14.04 /bin/bash - -If you do block IO in the two containers at the same time, by, for example: - - $ time dd if=/mnt/zerofile of=test.out bs=1M count=1024 oflag=direct - -You'll find that the proportion of time is the same as the proportion of blkio -weights of the two containers. - -The `--blkio-weight-device="DEVICE_NAME:WEIGHT"` flag sets a specific device weight. -The `DEVICE_NAME:WEIGHT` is a string containing a colon-separated device name and weight. -For example, to set `/dev/sda` device weight to `200`: - - $ docker run -it \ - --blkio-weight-device "/dev/sda:200" \ - ubuntu - -If you specify both the `--blkio-weight` and `--blkio-weight-device`, Docker -uses the `--blkio-weight` as the default weight and uses `--blkio-weight-device` -to override this default with a new value on a specific device. -The following example uses a default weight of `300` and overrides this default -on `/dev/sda` setting that weight to `200`: - - $ docker run -it \ - --blkio-weight 300 \ - --blkio-weight-device "/dev/sda:200" \ - ubuntu - -The `--device-read-bps` flag limits the read rate (bytes per second) from a device. -For example, this command creates a container and limits the read rate to `1mb` -per second from `/dev/sda`: - - $ docker run -it --device-read-bps /dev/sda:1mb ubuntu - -The `--device-write-bps` flag limits the write rate (bytes per second)to a device. -For example, this command creates a container and limits the write rate to `1mb` -per second for `/dev/sda`: - - $ docker run -it --device-write-bps /dev/sda:1mb ubuntu - -Both flags take limits in the `:[unit]` format. Both read -and write rates must be a positive integer. You can specify the rate in `kb` -(kilobytes), `mb` (megabytes), or `gb` (gigabytes). - -The `--device-read-iops` flag limits read rate (IO per second) from a device. -For example, this command creates a container and limits the read rate to -`1000` IO per second from `/dev/sda`: - - $ docker run -ti --device-read-iops /dev/sda:1000 ubuntu - -The `--device-write-iops` flag limits write rate (IO per second) to a device. -For example, this command creates a container and limits the write rate to -`1000` IO per second to `/dev/sda`: - - $ docker run -ti --device-write-iops /dev/sda:1000 ubuntu - -Both flags take limits in the `:` format. Both read and -write rates must be a positive integer. - -## Additional groups - --group-add: Add additional groups to run as - -By default, the docker container process runs with the supplementary groups looked -up for the specified user. If one wants to add more to that list of groups, then -one can use this flag: - - $ docker run --rm --group-add audio --group-add nogroup --group-add 777 busybox id - uid=0(root) gid=0(root) groups=10(wheel),29(audio),99(nogroup),777 - -## Runtime privilege and Linux capabilities - - --cap-add: Add Linux capabilities - --cap-drop: Drop Linux capabilities - --privileged=false: Give extended privileges to this container - --device=[]: Allows you to run devices inside the container without the --privileged flag. - -By default, Docker containers are "unprivileged" and cannot, for -example, run a Docker daemon inside a Docker container. This is because -by default a container is not allowed to access any devices, but a -"privileged" container is given access to all devices (see -the documentation on [cgroups devices](https://www.kernel.org/doc/Documentation/cgroup-v1/devices.txt)). - -When the operator executes `docker run --privileged`, Docker will enable -to access to all devices on the host as well as set some configuration -in AppArmor or SELinux to allow the container nearly all the same access to the -host as processes running outside containers on the host. Additional -information about running with `--privileged` is available on the -[Docker Blog](http://blog.docker.com/2013/09/docker-can-now-run-within-docker/). - -If you want to limit access to a specific device or devices you can use -the `--device` flag. It allows you to specify one or more devices that -will be accessible within the container. - - $ docker run --device=/dev/snd:/dev/snd ... - -By default, the container will be able to `read`, `write`, and `mknod` these devices. -This can be overridden using a third `:rwm` set of options to each `--device` flag: - - $ docker run --device=/dev/sda:/dev/xvdc --rm -it ubuntu fdisk /dev/xvdc - - Command (m for help): q - $ docker run --device=/dev/sda:/dev/xvdc:r --rm -it ubuntu fdisk /dev/xvdc - You will not be able to write the partition table. - - Command (m for help): q - - $ docker run --device=/dev/sda:/dev/xvdc:w --rm -it ubuntu fdisk /dev/xvdc - crash.... - - $ docker run --device=/dev/sda:/dev/xvdc:m --rm -it ubuntu fdisk /dev/xvdc - fdisk: unable to open /dev/xvdc: Operation not permitted - -In addition to `--privileged`, the operator can have fine grain control over the -capabilities using `--cap-add` and `--cap-drop`. By default, Docker has a default -list of capabilities that are kept. The following table lists the Linux capability -options which are allowed by default and can be dropped. - -| Capability Key | Capability Description | -| ---------------- | ----------------------------------------------------------------------------------------------------------------------------- | -| SETPCAP | Modify process capabilities. | -| MKNOD | Create special files using mknod(2). | -| AUDIT_WRITE | Write records to kernel auditing log. | -| CHOWN | Make arbitrary changes to file UIDs and GIDs (see chown(2)). | -| NET_RAW | Use RAW and PACKET sockets. | -| DAC_OVERRIDE | Bypass file read, write, and execute permission checks. | -| FOWNER | Bypass permission checks on operations that normally require the file system UID of the process to match the UID of the file. | -| FSETID | Don't clear set-user-ID and set-group-ID permission bits when a file is modified. | -| KILL | Bypass permission checks for sending signals. | -| SETGID | Make arbitrary manipulations of process GIDs and supplementary GID list. | -| SETUID | Make arbitrary manipulations of process UIDs. | -| NET_BIND_SERVICE | Bind a socket to internet domain privileged ports (port numbers less than 1024). | -| SYS_CHROOT | Use chroot(2), change root directory. | -| SETFCAP | Set file capabilities. | - -The next table shows the capabilities which are not granted by default and may be added. - -| Capability Key | Capability Description | -| ---------------- | ----------------------------------------------------------------------------------------------------------------------------- | -| SYS_MODULE | Load and unload kernel modules. | -| SYS_RAWIO | Perform I/O port operations (iopl(2) and ioperm(2)). | -| SYS_PACCT | Use acct(2), switch process accounting on or off. | -| SYS_ADMIN | Perform a range of system administration operations. | -| SYS_NICE | Raise process nice value (nice(2), setpriority(2)) and change the nice value for arbitrary processes. | -| SYS_RESOURCE | Override resource Limits. | -| SYS_TIME | Set system clock (settimeofday(2), stime(2), adjtimex(2)); set real-time (hardware) clock. | -| SYS_TTY_CONFIG | Use vhangup(2); employ various privileged ioctl(2) operations on virtual terminals. | -| AUDIT_CONTROL | Enable and disable kernel auditing; change auditing filter rules; retrieve auditing status and filtering rules. | -| MAC_OVERRIDE | Allow MAC configuration or state changes. Implemented for the Smack LSM. | -| MAC_ADMIN | Override Mandatory Access Control (MAC). Implemented for the Smack Linux Security Module (LSM). | -| NET_ADMIN | Perform various network-related operations. | -| SYSLOG | Perform privileged syslog(2) operations. | -| DAC_READ_SEARCH | Bypass file read permission checks and directory read and execute permission checks. | -| LINUX_IMMUTABLE | Set the FS_APPEND_FL and FS_IMMUTABLE_FL i-node flags. | -| NET_BROADCAST | Make socket broadcasts, and listen to multicasts. | -| IPC_LOCK | Lock memory (mlock(2), mlockall(2), mmap(2), shmctl(2)). | -| IPC_OWNER | Bypass permission checks for operations on System V IPC objects. | -| SYS_PTRACE | Trace arbitrary processes using ptrace(2). | -| SYS_BOOT | Use reboot(2) and kexec_load(2), reboot and load a new kernel for later execution. | -| LEASE | Establish leases on arbitrary files (see fcntl(2)). | -| WAKE_ALARM | Trigger something that will wake up the system. | -| BLOCK_SUSPEND | Employ features that can block system suspend. | - -Further reference information is available on the [capabilities(7) - Linux man page](http://man7.org/linux/man-pages/man7/capabilities.7.html) - -Both flags support the value `ALL`, so if the -operator wants to have all capabilities but `MKNOD` they could use: - - $ docker run --cap-add=ALL --cap-drop=MKNOD ... - -For interacting with the network stack, instead of using `--privileged` they -should use `--cap-add=NET_ADMIN` to modify the network interfaces. - - $ docker run -it --rm ubuntu:14.04 ip link add dummy0 type dummy - RTNETLINK answers: Operation not permitted - $ docker run -it --rm --cap-add=NET_ADMIN ubuntu:14.04 ip link add dummy0 type dummy - -To mount a FUSE based filesystem, you need to combine both `--cap-add` and -`--device`: - - $ docker run --rm -it --cap-add SYS_ADMIN sshfs sshfs sven@10.10.10.20:/home/sven /mnt - fuse: failed to open /dev/fuse: Operation not permitted - $ docker run --rm -it --device /dev/fuse sshfs sshfs sven@10.10.10.20:/home/sven /mnt - fusermount: mount failed: Operation not permitted - $ docker run --rm -it --cap-add SYS_ADMIN --device /dev/fuse sshfs - # sshfs sven@10.10.10.20:/home/sven /mnt - The authenticity of host '10.10.10.20 (10.10.10.20)' can't be established. - ECDSA key fingerprint is 25:34:85:75:25:b0:17:46:05:19:04:93:b5:dd:5f:c6. - Are you sure you want to continue connecting (yes/no)? yes - sven@10.10.10.20's password: - root@30aa0cfaf1b5:/# ls -la /mnt/src/docker - total 1516 - drwxrwxr-x 1 1000 1000 4096 Dec 4 06:08 . - drwxrwxr-x 1 1000 1000 4096 Dec 4 11:46 .. - -rw-rw-r-- 1 1000 1000 16 Oct 8 00:09 .dockerignore - -rwxrwxr-x 1 1000 1000 464 Oct 8 00:09 .drone.yml - drwxrwxr-x 1 1000 1000 4096 Dec 4 06:11 .git - -rw-rw-r-- 1 1000 1000 461 Dec 4 06:08 .gitignore - .... - -The default seccomp profile will adjust to the selected capabilities, in order to allow -use of facilities allowed by the capabilities, so you should not have to adjust this, -since Docker 1.12. In Docker 1.10 and 1.11 this did not happen and it may be necessary -to use a custom seccomp profile or use `--security-opt seccomp=unconfined` when adding -capabilities. - -## Logging drivers (--log-driver) - -The container can have a different logging driver than the Docker daemon. Use -the `--log-driver=VALUE` with the `docker run` command to configure the -container's logging driver. The following options are supported: - -| Driver | Description | -| ----------- | ----------------------------------------------------------------------------------------------------------------------------- | -| `none` | Disables any logging for the container. `docker logs` won't be available with this driver. | -| `json-file` | Default logging driver for Docker. Writes JSON messages to file. No logging options are supported for this driver. | -| `syslog` | Syslog logging driver for Docker. Writes log messages to syslog. | -| `journald` | Journald logging driver for Docker. Writes log messages to `journald`. | -| `gelf` | Graylog Extended Log Format (GELF) logging driver for Docker. Writes log messages to a GELF endpoint likeGraylog or Logstash. | -| `fluentd` | Fluentd logging driver for Docker. Writes log messages to `fluentd` (forward input). | -| `awslogs` | Amazon CloudWatch Logs logging driver for Docker. Writes log messages to Amazon CloudWatch Logs | -| `splunk` | Splunk logging driver for Docker. Writes log messages to `splunk` using Event Http Collector. | - -The `docker logs` command is available only for the `json-file` and `journald` -logging drivers. For detailed information on working with logging drivers, see -[Configure a logging driver](https://docs.docker.com/engine/admin/logging/overview/). - - -## Overriding Dockerfile image defaults - -When a developer builds an image from a [*Dockerfile*](builder.md) -or when she commits it, the developer can set a number of default parameters -that take effect when the image starts up as a container. - -Four of the Dockerfile commands cannot be overridden at runtime: `FROM`, -`MAINTAINER`, `RUN`, and `ADD`. Everything else has a corresponding override -in `docker run`. We'll go through what the developer might have set in each -Dockerfile instruction and how the operator can override that setting. - - - [CMD (Default Command or Options)](#cmd-default-command-or-options) - - [ENTRYPOINT (Default Command to Execute at Runtime)]( - #entrypoint-default-command-to-execute-at-runtime) - - [EXPOSE (Incoming Ports)](#expose-incoming-ports) - - [ENV (Environment Variables)](#env-environment-variables) - - [HEALTHCHECK](#healthcheck) - - [VOLUME (Shared Filesystems)](#volume-shared-filesystems) - - [USER](#user) - - [WORKDIR](#workdir) - -### CMD (default command or options) - -Recall the optional `COMMAND` in the Docker -commandline: - - $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...] - -This command is optional because the person who created the `IMAGE` may -have already provided a default `COMMAND` using the Dockerfile `CMD` -instruction. As the operator (the person running a container from the -image), you can override that `CMD` instruction just by specifying a new -`COMMAND`. - -If the image also specifies an `ENTRYPOINT` then the `CMD` or `COMMAND` -get appended as arguments to the `ENTRYPOINT`. - -### ENTRYPOINT (default command to execute at runtime) - - --entrypoint="": Overwrite the default entrypoint set by the image - -The `ENTRYPOINT` of an image is similar to a `COMMAND` because it -specifies what executable to run when the container starts, but it is -(purposely) more difficult to override. The `ENTRYPOINT` gives a -container its default nature or behavior, so that when you set an -`ENTRYPOINT` you can run the container *as if it were that binary*, -complete with default options, and you can pass in more options via the -`COMMAND`. But, sometimes an operator may want to run something else -inside the container, so you can override the default `ENTRYPOINT` at -runtime by using a string to specify the new `ENTRYPOINT`. Here is an -example of how to run a shell in a container that has been set up to -automatically run something else (like `/usr/bin/redis-server`): - - $ docker run -it --entrypoint /bin/bash example/redis - -or two examples of how to pass more parameters to that ENTRYPOINT: - - $ docker run -it --entrypoint /bin/bash example/redis -c ls -l - $ docker run -it --entrypoint /usr/bin/redis-cli example/redis --help - -You can reset a containers entrypoint by passing an empty string, for example: - - $ docker run -it --entrypoint="" mysql bash - -> **Note**: Passing `--entrypoint` will clear out any default command set on the -> image (i.e. any `CMD` instruction in the Dockerfile used to build it). - -### EXPOSE (incoming ports) - -The following `run` command options work with container networking: - - --expose=[]: Expose a port or a range of ports inside the container. - These are additional to those exposed by the `EXPOSE` instruction - -P : Publish all exposed ports to the host interfaces - -p=[] : Publish a container᾿s port or a range of ports to the host - format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort - Both hostPort and containerPort can be specified as a - range of ports. When specifying ranges for both, the - number of container ports in the range must match the - number of host ports in the range, for example: - -p 1234-1236:1234-1236/tcp - - When specifying a range for hostPort only, the - containerPort must not be a range. In this case the - container port is published somewhere within the - specified hostPort range. (e.g., `-p 1234-1236:1234/tcp`) - - (use 'docker port' to see the actual mapping) - - --link="" : Add link to another container (:alias or ) - -With the exception of the `EXPOSE` directive, an image developer hasn't -got much control over networking. The `EXPOSE` instruction defines the -initial incoming ports that provide services. These ports are available -to processes inside the container. An operator can use the `--expose` -option to add to the exposed ports. - -To expose a container's internal port, an operator can start the -container with the `-P` or `-p` flag. The exposed port is accessible on -the host and the ports are available to any client that can reach the -host. - -The `-P` option publishes all the ports to the host interfaces. Docker -binds each exposed port to a random port on the host. The range of -ports are within an *ephemeral port range* defined by -`/proc/sys/net/ipv4/ip_local_port_range`. Use the `-p` flag to -explicitly map a single port or range of ports. - -The port number inside the container (where the service listens) does -not need to match the port number exposed on the outside of the -container (where clients connect). For example, inside the container an -HTTP service is listening on port 80 (and so the image developer -specifies `EXPOSE 80` in the Dockerfile). At runtime, the port might be -bound to 42800 on the host. To find the mapping between the host ports -and the exposed ports, use `docker port`. - -If the operator uses `--link` when starting a new client container in the -default bridge network, then the client container can access the exposed -port via a private networking interface. -If `--link` is used when starting a container in a user-defined network as -described in [*Docker network overview*](https://docs.docker.com/engine/userguide/networking/), -it will provide a named alias for the container being linked to. - -### ENV (environment variables) - -When a new container is created, Docker will set the following environment -variables automatically: - -| Variable | Value | -| -------- | ----- | -| `HOME` | Set based on the value of `USER` | -| `HOSTNAME` | The hostname associated with the container | -| `PATH` | Includes popular directories, such as `:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin` | -| `TERM` | `xterm` if the container is allocated a pseudo-TTY | - -Additionally, the operator can **set any environment variable** in the -container by using one or more `-e` flags, even overriding those mentioned -above, or already defined by the developer with a Dockerfile `ENV`: - - $ docker run -e "deep=purple" --rm ubuntu /bin/bash -c export - declare -x HOME="/" - declare -x HOSTNAME="85bc26a0e200" - declare -x OLDPWD - declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - declare -x PWD="/" - declare -x SHLVL="1" - declare -x deep="purple" - -Similarly the operator can set the **hostname** with `-h`. - -### HEALTHCHECK - -``` - --health-cmd Command to run to check health - --health-interval Time between running the check - --health-retries Consecutive failures needed to report unhealthy - --health-timeout Maximum time to allow one check to run - --no-healthcheck Disable any container-specified HEALTHCHECK -``` - -Example: - - {% raw %} - $ docker run --name=test -d \ - --health-cmd='stat /etc/passwd || exit 1' \ - --health-interval=2s \ - busybox sleep 1d - $ sleep 2; docker inspect --format='{{.State.Health.Status}}' test - healthy - $ docker exec test rm /etc/passwd - $ sleep 2; docker inspect --format='{{json .State.Health}}' test - { - "Status": "unhealthy", - "FailingStreak": 3, - "Log": [ - { - "Start": "2016-05-25T17:22:04.635478668Z", - "End": "2016-05-25T17:22:04.7272552Z", - "ExitCode": 0, - "Output": " File: /etc/passwd\n Size: 334 \tBlocks: 8 IO Block: 4096 regular file\nDevice: 32h/50d\tInode: 12 Links: 1\nAccess: (0664/-rw-rw-r--) Uid: ( 0/ root) Gid: ( 0/ root)\nAccess: 2015-12-05 22:05:32.000000000\nModify: 2015..." - }, - { - "Start": "2016-05-25T17:22:06.732900633Z", - "End": "2016-05-25T17:22:06.822168935Z", - "ExitCode": 0, - "Output": " File: /etc/passwd\n Size: 334 \tBlocks: 8 IO Block: 4096 regular file\nDevice: 32h/50d\tInode: 12 Links: 1\nAccess: (0664/-rw-rw-r--) Uid: ( 0/ root) Gid: ( 0/ root)\nAccess: 2015-12-05 22:05:32.000000000\nModify: 2015..." - }, - { - "Start": "2016-05-25T17:22:08.823956535Z", - "End": "2016-05-25T17:22:08.897359124Z", - "ExitCode": 1, - "Output": "stat: can't stat '/etc/passwd': No such file or directory\n" - }, - { - "Start": "2016-05-25T17:22:10.898802931Z", - "End": "2016-05-25T17:22:10.969631866Z", - "ExitCode": 1, - "Output": "stat: can't stat '/etc/passwd': No such file or directory\n" - }, - { - "Start": "2016-05-25T17:22:12.971033523Z", - "End": "2016-05-25T17:22:13.082015516Z", - "ExitCode": 1, - "Output": "stat: can't stat '/etc/passwd': No such file or directory\n" - } - ] - } - {% endraw %} - -The health status is also displayed in the `docker ps` output. - -### TMPFS (mount tmpfs filesystems) - -```bash ---tmpfs=[]: Create a tmpfs mount with: container-dir[:], - where the options are identical to the Linux - 'mount -t tmpfs -o' command. -``` - -The example below mounts an empty tmpfs into the container with the `rw`, -`noexec`, `nosuid`, and `size=65536k` options. - - $ docker run -d --tmpfs /run:rw,noexec,nosuid,size=65536k my_image - -### VOLUME (shared filesystems) - - -v, --volume=[host-src:]container-dest[:]: Bind mount a volume. - The comma-delimited `options` are [rw|ro], [z|Z], - [[r]shared|[r]slave|[r]private], and [nocopy]. - The 'host-src' is an absolute path or a name value. - - If neither 'rw' or 'ro' is specified then the volume is mounted in - read-write mode. - - The `nocopy` modes is used to disable automatic copying requested volume - path in the container to the volume storage location. - For named volumes, `copy` is the default mode. Copy modes are not supported - for bind-mounted volumes. - - --volumes-from="": Mount all volumes from the given container(s) - -> **Note**: -> When using systemd to manage the Docker daemon's start and stop, in the systemd -> unit file there is an option to control mount propagation for the Docker daemon -> itself, called `MountFlags`. The value of this setting may cause Docker to not -> see mount propagation changes made on the mount point. For example, if this value -> is `slave`, you may not be able to use the `shared` or `rshared` propagation on -> a volume. - -The volumes commands are complex enough to have their own documentation -in section [*Manage data in -containers*](https://docs.docker.com/engine/tutorials/dockervolumes/). A developer can define -one or more `VOLUME`'s associated with an image, but only the operator -can give access from one container to another (or from a container to a -volume mounted on the host). - -The `container-dest` must always be an absolute path such as `/src/docs`. -The `host-src` can either be an absolute path or a `name` value. If you -supply an absolute path for the `host-dir`, Docker bind-mounts to the path -you specify. If you supply a `name`, Docker creates a named volume by that `name`. - -A `name` value must start with an alphanumeric character, -followed by `a-z0-9`, `_` (underscore), `.` (period) or `-` (hyphen). -An absolute path starts with a `/` (forward slash). - -For example, you can specify either `/foo` or `foo` for a `host-src` value. -If you supply the `/foo` value, Docker creates a bind-mount. If you supply -the `foo` specification, Docker creates a named volume. - -### USER - -`root` (id = 0) is the default user within a container. The image developer can -create additional users. Those users are accessible by name. When passing a numeric -ID, the user does not have to exist in the container. - -The developer can set a default user to run the first process with the -Dockerfile `USER` instruction. When starting a container, the operator can override -the `USER` instruction by passing the `-u` option. - - -u="", --user="": Sets the username or UID used and optionally the groupname or GID for the specified command. - - The followings examples are all valid: - --user=[ user | user:group | uid | uid:gid | user:gid | uid:group ] - -> **Note:** if you pass a numeric uid, it must be in the range of 0-2147483647. - -### WORKDIR - -The default working directory for running binaries within a container is the -root directory (`/`), but the developer can set a different default with the -Dockerfile `WORKDIR` command. The operator can override this with: - - -w="": Working directory inside the container diff --git a/vendor/github.com/docker/docker/docs/static_files/contributors.png b/vendor/github.com/docker/docker/docs/static_files/contributors.png deleted file mode 100644 index 63c0a0c..0000000 Binary files a/vendor/github.com/docker/docker/docs/static_files/contributors.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/docs/static_files/docker-logo-compressed.png b/vendor/github.com/docker/docker/docs/static_files/docker-logo-compressed.png deleted file mode 100644 index 717d09d..0000000 Binary files a/vendor/github.com/docker/docker/docs/static_files/docker-logo-compressed.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/experimental/README.md b/vendor/github.com/docker/docker/experimental/README.md deleted file mode 100644 index b57a5d1..0000000 --- a/vendor/github.com/docker/docker/experimental/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Docker Experimental Features - -This page contains a list of features in the Docker engine which are -experimental. Experimental features are **not** ready for production. They are -provided for test and evaluation in your sandbox environments. - -The information below describes each feature and the GitHub pull requests and -issues associated with it. If necessary, links are provided to additional -documentation on an issue. As an active Docker user and community member, -please feel free to provide any feedback on these features you wish. - -## Use Docker experimental - -Experimental features are now included in the standard Docker binaries as of -version 1.13.0. -For enabling experimental features, you need to start the Docker daemon with -`--experimental` flag. -You can also enable the daemon flag via `/etc/docker/daemon.json`. e.g. - -```json -{ - "experimental": true -} -``` - -Then make sure the experimental flag is enabled: - -```bash -$ docker version -f '{{.Server.Experimental}}' -true -``` - -## Current experimental features - - * [External graphdriver plugins](../docs/extend/plugins_graphdriver.md) - * [Ipvlan Network Drivers](vlan-networks.md) - * [Docker Stacks and Distributed Application Bundles](docker-stacks-and-bundles.md) - * [Checkpoint & Restore](checkpoint-restore.md) - -## How to comment on an experimental feature - -Each feature's documentation includes a list of proposal pull requests or PRs associated with the feature. If you want to comment on or suggest a change to a feature, please add it to the existing feature PR. - -Issues or problems with a feature? Inquire for help on the `#docker` IRC channel or on the [Docker Google group](https://groups.google.com/forum/#!forum/docker-user). diff --git a/vendor/github.com/docker/docker/experimental/checkpoint-restore.md b/vendor/github.com/docker/docker/experimental/checkpoint-restore.md deleted file mode 100644 index 7e609b6..0000000 --- a/vendor/github.com/docker/docker/experimental/checkpoint-restore.md +++ /dev/null @@ -1,88 +0,0 @@ -# Docker Checkpoint & Restore - -Checkpoint & Restore is a new feature that allows you to freeze a running -container by checkpointing it, which turns its state into a collection of files -on disk. Later, the container can be restored from the point it was frozen. - -This is accomplished using a tool called [CRIU](http://criu.org), which is an -external dependency of this feature. A good overview of the history of -checkpoint and restore in Docker is available in this -[Kubernetes blog post](http://blog.kubernetes.io/2015/07/how-did-quake-demo-from-dockercon-work.html). - -## Installing CRIU - -If you use a Debian system, you can add the CRIU PPA and install with apt-get -[from the criu launchpad](https://launchpad.net/~criu/+archive/ubuntu/ppa). - -Alternatively, you can [build CRIU from source](http://criu.org/Installation). - -You need at least version 2.0 of CRIU to run checkpoint/restore in Docker. - -## Use cases for checkpoint & restore - -This feature is currently focused on single-host use cases for checkpoint and -restore. Here are a few: - -- Restarting the host machine without stopping/starting containers -- Speeding up the start time of slow start applications -- "Rewinding" processes to an earlier point in time -- "Forensic debugging" of running processes - -Another primary use case of checkpoint & restore outside of Docker is the live -migration of a server from one machine to another. This is possible with the -current implementation, but not currently a priority (and so the workflow is -not optimized for the task). - -## Using checkpoint & restore - -A new top level command `docker checkpoint` is introduced, with three subcommands: -- `create` (creates a new checkpoint) -- `ls` (lists existing checkpoints) -- `rm` (deletes an existing checkpoint) - -Additionally, a `--checkpoint` flag is added to the container start command. - -The options for checkpoint create: - - Usage: docker checkpoint create [OPTIONS] CONTAINER CHECKPOINT - - Create a checkpoint from a running container - - --leave-running=false Leave the container running after checkpoint - --checkpoint-dir Use a custom checkpoint storage directory - -And to restore a container: - - Usage: docker start --checkpoint CHECKPOINT_ID [OTHER OPTIONS] CONTAINER - - -A simple example of using checkpoint & restore on a container: - - $ docker run --security-opt=seccomp:unconfined --name cr -d busybox /bin/sh -c 'i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done' - > abc0123 - - $ docker checkpoint create cr checkpoint1 - - # - $ docker start --checkpoint checkpoint1 cr - > abc0123 - -This process just logs an incrementing counter to stdout. If you `docker logs` -in between running/checkpoint/restoring you should see that the counter -increases while the process is running, stops while it's checkpointed, and -resumes from the point it left off once you restore. - -## Current limitation - -seccomp is only supported by CRIU in very up to date kernels. - -External terminal (i.e. `docker run -t ..`) is not supported at the moment. -If you try to create a checkpoint for a container with an external terminal, -it would fail: - - $ docker checkpoint create cr checkpoint1 - Error response from daemon: Cannot checkpoint container c1: rpc error: code = 2 desc = exit status 1: "criu failed: type NOTIFY errno 0\nlog file: /var/lib/docker/containers/eb62ebdbf237ce1a8736d2ae3c7d88601fc0a50235b0ba767b559a1f3c5a600b/checkpoints/checkpoint1/criu.work/dump.log\n" - - $ cat /var/lib/docker/containers/eb62ebdbf237ce1a8736d2ae3c7d88601fc0a50235b0ba767b559a1f3c5a600b/checkpoints/checkpoint1/criu.work/dump.log - Error (mount.c:740): mnt: 126:./dev/console doesn't have a proper root mount - diff --git a/vendor/github.com/docker/docker/experimental/docker-stacks-and-bundles.md b/vendor/github.com/docker/docker/experimental/docker-stacks-and-bundles.md deleted file mode 100644 index b777c39..0000000 --- a/vendor/github.com/docker/docker/experimental/docker-stacks-and-bundles.md +++ /dev/null @@ -1,202 +0,0 @@ -# Docker Stacks and Distributed Application Bundles - -## Overview - -Docker Stacks and Distributed Application Bundles are experimental features -introduced in Docker 1.12 and Docker Compose 1.8, alongside the concept of -swarm mode, and Nodes and Services in the Engine API. - -A Dockerfile can be built into an image, and containers can be created from -that image. Similarly, a docker-compose.yml can be built into a **distributed -application bundle**, and **stacks** can be created from that bundle. In that -sense, the bundle is a multi-services distributable image format. - -As of Docker 1.12 and Compose 1.8, the features are experimental. Neither -Docker Engine nor the Docker Registry support distribution of bundles. - -## Producing a bundle - -The easiest way to produce a bundle is to generate it using `docker-compose` -from an existing `docker-compose.yml`. Of course, that's just *one* possible way -to proceed, in the same way that `docker build` isn't the only way to produce a -Docker image. - -From `docker-compose`: - -```bash -$ docker-compose bundle -WARNING: Unsupported key 'network_mode' in services.nsqd - ignoring -WARNING: Unsupported key 'links' in services.nsqd - ignoring -WARNING: Unsupported key 'volumes' in services.nsqd - ignoring -[...] -Wrote bundle to vossibility-stack.dab -``` - -## Creating a stack from a bundle - -A stack is created using the `docker deploy` command: - -```bash -# docker deploy --help - -Usage: docker deploy [OPTIONS] STACK - -Create and update a stack from a Distributed Application Bundle (DAB) - -Options: - --file string Path to a Distributed Application Bundle file (Default: STACK.dab) - --help Print usage - --with-registry-auth Send registry authentication details to Swarm agents -``` - -Let's deploy the stack created before: - -```bash -# docker deploy vossibility-stack -Loading bundle from vossibility-stack.dab -Creating service vossibility-stack_elasticsearch -Creating service vossibility-stack_kibana -Creating service vossibility-stack_logstash -Creating service vossibility-stack_lookupd -Creating service vossibility-stack_nsqd -Creating service vossibility-stack_vossibility-collector -``` - -We can verify that services were correctly created: - -```bash -$ docker service ls -ID NAME MODE REPLICAS IMAGE -29bv0vnlm903 vossibility-stack_lookupd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 -4awt47624qwh vossibility-stack_nsqd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 -4tjx9biia6fs vossibility-stack_elasticsearch replicated 1/1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa -7563uuzr9eys vossibility-stack_kibana replicated 1/1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03 -9gc5m4met4he vossibility-stack_logstash replicated 1/1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe -axqh55ipl40h vossibility-stack_vossibility-collector replicated 1/1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba -``` - -## Managing stacks - -Stacks are managed using the `docker stack` command: - -```bash -# docker stack --help - -Usage: docker stack COMMAND - -Manage Docker stacks - -Options: - --help Print usage - -Commands: - config Print the stack configuration - deploy Create and update a stack - ls List stacks - rm Remove the stack - services List the services in the stack - tasks List the tasks in the stack - -Run 'docker stack COMMAND --help' for more information on a command. -``` - -## Bundle file format - -Distributed application bundles are described in a JSON format. When bundles -are persisted as files, the file extension is `.dab` (Docker 1.12RC2 tools use -`.dsb` for the file extension—this will be updated in the next release client). - -A bundle has two top-level fields: `version` and `services`. The version used -by Docker 1.12 tools is `0.1`. - -`services` in the bundle are the services that comprise the app. They -correspond to the new `Service` object introduced in the 1.12 Docker Engine API. - -A service has the following fields: - -
-
- Image (required) string -
-
- The image that the service will run. Docker images should be referenced - with full content hash to fully specify the deployment artifact for the - service. Example: - postgres@sha256:f76245b04ddbcebab5bb6c28e76947f49222c99fec4aadb0bb - 1c24821a 9e83ef -
-
- Command []string -
-
- Command to run in service containers. -
-
- Args []string -
-
- Arguments passed to the service containers. -
-
- Env []string -
-
- Environment variables. -
-
- Labels map[string]string -
-
- Labels used for setting meta data on services. -
-
- Ports []Port -
-
- Service ports (composed of Port (int) and - Protocol (string). A service description can - only specify the container port to be exposed. These ports can be - mapped on runtime hosts at the operator's discretion. -
- -
- WorkingDir string -
-
- Working directory inside the service containers. -
- -
- User string -
-
- Username or UID (format: <name|uid>[:<group|gid>]). -
- -
- Networks []string -
-
- Networks that the service containers should be connected to. An entity - deploying a bundle should create networks as needed. -
-
- -The following is an example of bundlefile with two services: - -```json -{ - "Version": "0.1", - "Services": { - "redis": { - "Image": "redis@sha256:4b24131101fa0117bcaa18ac37055fffd9176aa1a240392bb8ea85e0be50f2ce", - "Networks": ["default"] - }, - "web": { - "Image": "dockercloud/hello-world@sha256:fe79a2cfbd17eefc344fb8419420808df95a1e22d93b7f621a7399fd1e9dca1d", - "Networks": ["default"], - "User": "web" - } - } -} -``` diff --git a/vendor/github.com/docker/docker/experimental/images/ipvlan-l3.gliffy b/vendor/github.com/docker/docker/experimental/images/ipvlan-l3.gliffy deleted file mode 100644 index bf0512a..0000000 --- a/vendor/github.com/docker/docker/experimental/images/ipvlan-l3.gliffy +++ /dev/null @@ -1 +0,0 @@ -{"contentType":"application/gliffy+json","version":"1.3","stage":{"background":"#FFFFFF","width":447,"height":422,"nodeIndex":326,"autoFit":true,"exportBorder":false,"gridOn":true,"snapToGrid":false,"drawingGuidesOn":false,"pageBreaksOn":false,"printGridOn":false,"printPaper":"LETTER","printShrinkToFit":false,"printPortrait":true,"maxWidth":5000,"maxHeight":5000,"themeData":{"uid":"com.gliffy.theme.beach_day","name":"Beach Day","shape":{"primary":{"strokeWidth":2,"strokeColor":"#00A4DA","fillColor":"#AEE4F4","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#004257"}},"secondary":{"strokeWidth":2,"strokeColor":"#CDB25E","fillColor":"#EACF81","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#332D1A"}},"tertiary":{"strokeWidth":2,"strokeColor":"#FFBE00","fillColor":"#FFF1CB","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#000000"}},"highlight":{"strokeWidth":2,"strokeColor":"#00A4DA","fillColor":"#00A4DA","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#ffffff"}}},"line":{"strokeWidth":2,"strokeColor":"#00A4DA","fillColor":"none","arrowType":2,"interpolationType":"quadratic","cornerRadius":0,"text":{"color":"#002248"}},"text":{"color":"#002248"},"stage":{"color":"#FFFFFF"}},"viewportType":"default","fitBB":{"min":{"x":9,"y":10.461511948529278},"max":{"x":447,"y":421.5}},"printModel":{"pageSize":"a4","portrait":false,"fitToOnePage":false,"displayPageBreaks":false},"objects":[{"x":12.0,"y":200.0,"rotation":0.0,"id":276,"width":434.00000000000006,"height":197.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":10,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":2.0,"strokeColor":"#434343","fillColor":"#c5e4fc","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":0.93,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":275.0,"y":8.93295288085936,"rotation":0.0,"id":269,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":14,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":272,"py":0.5,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":290,"py":1.0,"px":0.7071067811865476}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[82.0,295.5670471191406],[-4.628896294384617,211.06704711914062]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":285.0,"y":18.93295288085936,"rotation":0.0,"id":268,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":15,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":316,"py":0.5,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":290,"py":0.9999999999999996,"px":0.29289321881345254}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-204.0,285.5670471191406],[-100.37110370561533,201.06704711914062]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":8.0,"y":203.5,"rotation":0.0,"id":267,"width":116.0,"height":16.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":16,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Docker Host

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":10.0,"y":28.93295288085936,"rotation":0.0,"id":278,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":17,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":290,"py":0.5,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":246,"py":0.5,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[217.5,167.06704711914062],[219.11774189711457,53.02855906766992]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":57.51435447730654,"y":10.461511948529278,"rotation":0.0,"id":246,"width":343.20677483961606,"height":143.0,"uid":"com.gliffy.shape.cisco.cisco_v1.storage.cloud","order":18,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.cisco.cisco_v1.storage.cloud","strokeWidth":2.0,"strokeColor":"#333333","fillColor":"#434343","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":106.0,"y":55.19999694824217,"rotation":0.0,"id":262,"width":262.0,"height":75.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":22,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Unless notified about the container networks, the physical network does not have a route to their subnets

Who has 10.16.20.0/24?

Who has 10.1.20.0/24?

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":7.0,"y":403.5,"rotation":0.0,"id":282,"width":442.0,"height":18.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":23,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Containers can be on different subnets and reach each other

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":106.0,"y":252.5,"rotation":0.0,"id":288,"width":238.0,"height":22.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":24,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

 Ipvlan L3 Mode

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":124.0,"y":172.0,"rotation":0.0,"id":290,"width":207.0,"height":48.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":25,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#cccccc","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":1.0,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[{"x":3.568965517241383,"y":0.0,"rotation":0.0,"id":291,"width":199.86206896551747,"height":42.0,"uid":null,"order":27,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Eth0

192.168.50.10/24

Parent interface acts as a Router

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":29.0,"y":358.1999969482422,"rotation":0.0,"id":304,"width":390.99999999999994,"height":32.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":29,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

All containers can ping each other without a router if

they share the same parent interface (example eth0)

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":24.0,"y":276.0,"rotation":0.0,"id":320,"width":134.0,"height":77.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":48,"lockAspectRatio":false,"lockShape":false,"children":[{"x":0.0,"y":0.0,"rotation":0.0,"id":316,"width":114.0,"height":57.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":44,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":0.97,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[{"x":2.279999999999999,"y":0.0,"rotation":0.0,"id":317,"width":109.44000000000001,"height":43.0,"uid":null,"order":47,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Container(s)

Eth0 

172.16.20.x/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":10.0,"y":10.0,"rotation":0.0,"id":318,"width":114.0,"height":57.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":42,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":0.97,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":20.0,"y":20.0,"rotation":0.0,"id":319,"width":114.0,"height":57.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":40,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":0.97,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":300.0,"y":276.0,"rotation":0.0,"id":321,"width":134.0,"height":77.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":49,"lockAspectRatio":false,"lockShape":false,"children":[{"x":0.0,"y":0.0,"rotation":0.0,"id":272,"width":114.0,"height":57.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":35,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":0.97,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[{"x":2.279999999999999,"y":0.0,"rotation":0.0,"id":273,"width":109.44000000000001,"height":44.0,"uid":null,"order":38,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Container(s)

Eth0 10.1.20.x/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":10.0,"y":10.0,"rotation":0.0,"id":310,"width":114.0,"height":57.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":33,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":0.97,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":20.0,"y":20.0,"rotation":0.0,"id":312,"width":114.0,"height":57.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":31,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":0.97,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":368.0,"y":85.93295288085938,"rotation":0.0,"id":322,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":50,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#434343","fillColor":"none","dashStyle":"4.0,4.0","startArrow":2,"endArrow":2,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-191.0,222.06704711914062],[-80.9272967534639,222.06704711914062]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":167.0,"y":25.499999999999986,"rotation":0.0,"id":323,"width":135.0,"height":32.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":51,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Physical Network

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"layers":[{"guid":"9wom3rMkTrb3","order":0,"name":"Layer 0","active":true,"locked":false,"visible":true,"nodeIndex":53}],"shapeStyles":{},"lineStyles":{"global":{"fill":"none","stroke":"#434343","strokeWidth":2,"dashStyle":"4.0,4.0","startArrow":2,"endArrow":2,"orthoMode":2}},"textStyles":{"global":{"face":"Arial","size":"13px","color":"#000000"}}},"metadata":{"title":"untitled","revision":0,"exportBorder":false,"loadPosition":"default","libraries":["com.gliffy.libraries.basic.basic_v1.default","com.gliffy.libraries.flowchart.flowchart_v1.default","com.gliffy.libraries.swimlanes.swimlanes_v1.default","com.gliffy.libraries.images","com.gliffy.libraries.network.network_v4.home","com.gliffy.libraries.network.network_v4.business","com.gliffy.libraries.network.network_v4.rack","com.gliffy.libraries.network.network_v3.home","com.gliffy.libraries.network.network_v3.business","com.gliffy.libraries.network.network_v3.rack"],"lastSerialized":1458117032939,"analyticsProduct":"Confluence"},"embeddedResources":{"index":0,"resources":[]}} \ No newline at end of file diff --git a/vendor/github.com/docker/docker/experimental/images/ipvlan-l3.png b/vendor/github.com/docker/docker/experimental/images/ipvlan-l3.png deleted file mode 100644 index 3227a83..0000000 Binary files a/vendor/github.com/docker/docker/experimental/images/ipvlan-l3.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/experimental/images/ipvlan-l3.svg b/vendor/github.com/docker/docker/experimental/images/ipvlan-l3.svg deleted file mode 100644 index 6ed1430..0000000 --- a/vendor/github.com/docker/docker/experimental/images/ipvlan-l3.svg +++ /dev/null @@ -1 +0,0 @@ -DockerHostUnlessnotifiedaboutthecontainernetworks,thephysicalnetworkdoesnothavearoutetotheirsubnetsWhohas10.16.20.0/24?Whohas10.1.20.0/24?ContainerscanbeondifferentsubnetsandreacheachotherIpvlanL3ModeEth0192.168.50.10/24ParentinterfaceactsasaRouterAllcontainerscanpingeachotherarouterifwithouttheysharetheparentinterface (sameexampleeth0)Container(s)Eth010.1.20.x/24Container(s)Eth0172.16.20.x/24PhysicalNetwork \ No newline at end of file diff --git a/vendor/github.com/docker/docker/experimental/images/ipvlan_l2_simple.gliffy b/vendor/github.com/docker/docker/experimental/images/ipvlan_l2_simple.gliffy deleted file mode 100644 index 41b0475..0000000 --- a/vendor/github.com/docker/docker/experimental/images/ipvlan_l2_simple.gliffy +++ /dev/null @@ -1 +0,0 @@ -{"contentType":"application/gliffy+json","version":"1.3","stage":{"background":"#ffffff","width":323,"height":292,"nodeIndex":211,"autoFit":true,"exportBorder":false,"gridOn":true,"snapToGrid":false,"drawingGuidesOn":false,"pageBreaksOn":false,"printGridOn":false,"printPaper":"LETTER","printShrinkToFit":false,"printPortrait":true,"maxWidth":5000,"maxHeight":5000,"themeData":null,"viewportType":"default","fitBB":{"min":{"x":16,"y":21.51999694824218},"max":{"x":323,"y":291.5}},"printModel":{"pageSize":"a4","portrait":false,"fitToOnePage":false,"displayPageBreaks":false},"objects":[{"x":241.0,"y":36.0,"rotation":0.0,"id":199,"width":73.00000000000003,"height":40.150000000000006,"uid":"com.gliffy.shape.network.network_v4.business.router","order":41,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.network.network_v4.business.router","strokeWidth":1.0,"strokeColor":"#000000","fillColor":"#3966A0","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":85.0,"y":50.0,"rotation":0.0,"id":150,"width":211.0,"height":31.0,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":37,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":6.0,"strokeColor":"#999999","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":10.0,"controlPath":[[3.1159999999999997,6.359996948242184],[85.55799999999999,6.359996948242184],[85.55799999999999,62.0],[84.0,62.0]],"lockSegments":{"1":true},"ortho":true}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":22.803646598905374,"y":21.51999694824218,"rotation":0.0,"id":134,"width":64.31235340109463,"height":90.0,"uid":"com.gliffy.shape.cisco.cisco_v1.servers.standard_host","order":43,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.cisco.cisco_v1.servers.standard_host","strokeWidth":2.0,"strokeColor":"#333333","fillColor":"#3d85c6","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":87.0,"y":24.199996948242188,"rotation":0.0,"id":187,"width":105.0,"height":28.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":39,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

eth0 192.168.1.0/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":147.0,"y":50.0,"rotation":0.0,"id":196,"width":211.0,"height":31.0,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":40,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":199,"py":0.5,"px":0.0}}},"graphic":{"type":"Line","Line":{"strokeWidth":6.0,"strokeColor":"#999999","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-82.00001598011289,6.075000000000003],[94.0,6.075000000000003]],"lockSegments":{"1":true},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":220.0,"y":79.19999694824219,"rotation":0.0,"id":207,"width":105.0,"height":28.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":42,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Network Router

192.168.1.1/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":27.38636363636374,"y":108.14285409109937,"rotation":0.0,"id":129,"width":262.0,"height":124.0,"uid":"com.gliffy.shape.iphone.iphone_ios7.icons_glyphs.glyph_cloud","order":44,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.iphone.iphone_ios7.icons_glyphs.glyph_cloud","strokeWidth":1.0,"strokeColor":"#000000","fillColor":"#929292","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":33.0,"y":157.96785409109907,"rotation":0.0,"id":114,"width":150.0,"height":60.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":16,"lockAspectRatio":false,"lockShape":false,"children":[{"x":44.0,"y":2.9951060358893704,"rotation":0.0,"id":95,"width":62.0,"height":36.17618270799329,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":4,"lockAspectRatio":false,"lockShape":false,"children":[{"x":29.139999999999997,"y":3.2300163132136848,"rotation":0.0,"id":96,"width":3.719999999999998,"height":29.7161500815659,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":13,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":99,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":99,"py":1.0,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[1.8599999999999994,-1.2920065252854727],[1.8599999999999994,31.0081566068514]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":51.46,"y":3.2300163132136848,"rotation":0.0,"id":97,"width":1.2156862745098034,"height":31.008156606851365,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":10,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-1.4193795664340882,-1.292006525285804],[-1.4193795664340882,31.008156606851536]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":9.919999999999993,"y":1.5073409461663854,"rotation":0.0,"id":98,"width":1.239999999999999,"height":31.008156606851365,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":7,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[2.0393795664339223,0.4306688417619762],[2.0393795664339223,32.73083197389853]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":1.9380097879282103,"rotation":0.0,"id":99,"width":62.0,"height":32.300163132136866,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":2,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":2.0,"strokeColor":"#6fa8dc","fillColor":"#3d85c6","gradient":true,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":38.326264274062034,"rotation":0.0,"id":112,"width":150.0,"height":28.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":15,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

container1

192.168.1.2/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":124.0,"y":157.96785409109907,"rotation":0.0,"id":115,"width":150.0,"height":58.99999999999999,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":33,"lockAspectRatio":false,"lockShape":false,"children":[{"x":44.0,"y":2.94518760195788,"rotation":0.0,"id":116,"width":62.0,"height":35.573246329526725,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":21,"lockAspectRatio":false,"lockShape":false,"children":[{"x":29.139999999999997,"y":3.1761827079934557,"rotation":0.0,"id":117,"width":3.719999999999998,"height":29.220880913539798,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":30,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":120,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":120,"py":1.0,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[1.8600000000000136,-1.2704730831974018],[1.8600000000000136,30.49135399673719]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":51.46,"y":3.1761827079934557,"rotation":0.0,"id":118,"width":1.2156862745098034,"height":30.49135399673717,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":27,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-1.4193795664340882,-1.2704730831977067],[-1.4193795664340882,30.491353996737335]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":9.919999999999993,"y":1.482218597063612,"rotation":0.0,"id":119,"width":1.239999999999999,"height":30.49135399673717,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":24,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[2.0393795664339223,0.42349102773260977],[2.0393795664339223,32.185318107666895]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":1.9057096247960732,"rotation":0.0,"id":120,"width":62.0,"height":31.76182707993458,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":19,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":2.0,"strokeColor":"#6fa8dc","fillColor":"#3d85c6","gradient":true,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":36.36247960848299,"rotation":0.0,"id":121,"width":150.0,"height":30.183360522022674,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":32,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

container2

192.168.1.3/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":102.0,"y":130.1999969482422,"rotation":0.0,"id":130,"width":150.0,"height":14.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":34,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

pub_net (eth0)

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":93.0,"y":92.69999694824219,"rotation":0.0,"id":140,"width":150.0,"height":14.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":35,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"


","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":14.0,"y":114.19999694824219,"rotation":0.0,"id":142,"width":78.0,"height":14.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":36,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Docker Host

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":71.0,"y":235.5,"rotation":0.0,"id":184,"width":196.0,"height":56.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":38,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

docker network create -d ipvlan \\

    --subnet=192.168.1.0/24 \\

    --gateway=192.168.1.1 \\

    -o parent=eth0 pub_net

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"layers":[{"guid":"9wom3rMkTrb3","order":0,"name":"Layer 0","active":true,"locked":false,"visible":true,"nodeIndex":45}],"shapeStyles":{},"lineStyles":{"global":{"stroke":"#999999","strokeWidth":6,"orthoMode":1}},"textStyles":{"global":{"bold":true,"face":"Arial","size":"12px","color":"#000000"}}},"metadata":{"title":"untitled","revision":0,"exportBorder":false,"loadPosition":"default","libraries":["com.gliffy.libraries.network.network_v4.home","com.gliffy.libraries.network.network_v4.business","com.gliffy.libraries.network.network_v4.rack","com.gliffy.libraries.network.network_v3.home","com.gliffy.libraries.network.network_v3.business","com.gliffy.libraries.network.network_v3.rack"],"lastSerialized":1457584497063,"analyticsProduct":"Confluence"},"embeddedResources":{"index":0,"resources":[]}} \ No newline at end of file diff --git a/vendor/github.com/docker/docker/experimental/images/ipvlan_l2_simple.png b/vendor/github.com/docker/docker/experimental/images/ipvlan_l2_simple.png deleted file mode 100644 index e489a44..0000000 Binary files a/vendor/github.com/docker/docker/experimental/images/ipvlan_l2_simple.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/experimental/images/ipvlan_l2_simple.svg b/vendor/github.com/docker/docker/experimental/images/ipvlan_l2_simple.svg deleted file mode 100644 index 48097dc..0000000 --- a/vendor/github.com/docker/docker/experimental/images/ipvlan_l2_simple.svg +++ /dev/null @@ -1 +0,0 @@ -container1192.168.1.2/24container2192.168.1.3/24pub_net (eth0)DockerHostdockernetworkcreate -dipvlan \--subnet=192.168.1.0/24 \--gateway=192.168.1.1 \-oparent=eth0pub_neteth0192.168.1.0/24NetworkRouter192.168.1.1/24 \ No newline at end of file diff --git a/vendor/github.com/docker/docker/experimental/images/macvlan-bridge-ipvlan-l2.gliffy b/vendor/github.com/docker/docker/experimental/images/macvlan-bridge-ipvlan-l2.gliffy deleted file mode 100644 index eceec77..0000000 --- a/vendor/github.com/docker/docker/experimental/images/macvlan-bridge-ipvlan-l2.gliffy +++ /dev/null @@ -1 +0,0 @@ -{"contentType":"application/gliffy+json","version":"1.3","stage":{"background":"#FFFFFF","width":541,"height":352,"nodeIndex":290,"autoFit":true,"exportBorder":false,"gridOn":true,"snapToGrid":false,"drawingGuidesOn":false,"pageBreaksOn":false,"printGridOn":false,"printPaper":"LETTER","printShrinkToFit":false,"printPortrait":true,"maxWidth":5000,"maxHeight":5000,"themeData":{"uid":"com.gliffy.theme.beach_day","name":"Beach Day","shape":{"primary":{"strokeWidth":2,"strokeColor":"#00A4DA","fillColor":"#AEE4F4","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#004257"}},"secondary":{"strokeWidth":2,"strokeColor":"#CDB25E","fillColor":"#EACF81","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#332D1A"}},"tertiary":{"strokeWidth":2,"strokeColor":"#FFBE00","fillColor":"#FFF1CB","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#000000"}},"highlight":{"strokeWidth":2,"strokeColor":"#00A4DA","fillColor":"#00A4DA","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#ffffff"}}},"line":{"strokeWidth":2,"strokeColor":"#00A4DA","fillColor":"none","arrowType":2,"interpolationType":"quadratic","cornerRadius":0,"text":{"color":"#002248"}},"text":{"color":"#002248"},"stage":{"color":"#FFFFFF"}},"viewportType":"default","fitBB":{"min":{"x":2,"y":6.5},"max":{"x":541,"y":334.5}},"printModel":{"pageSize":"a4","portrait":false,"fitToOnePage":false,"displayPageBreaks":false},"objects":[{"x":2.0,"y":6.5,"rotation":0.0,"id":288,"width":541.0,"height":22.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":31,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Macvlan Bridge Mode & Ipvlan L2 Mode

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":8.0,"y":177.0,"rotation":0.0,"id":234,"width":252.0,"height":129.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":0,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":2.0,"strokeColor":"#434343","fillColor":"#c5e4fc","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":0.93,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":16.0,"y":240.0,"rotation":0.0,"id":225,"width":111.0,"height":57.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":1,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.73,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[{"x":2.2199999999999993,"y":0.0,"rotation":0.0,"id":235,"width":106.56,"height":45.0,"uid":null,"order":"auto","lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Container #1

eth0

172.16.1.10/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":138.0,"y":240.0,"rotation":0.0,"id":237,"width":111.0,"height":57.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":4,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.73,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[{"x":2.2199999999999993,"y":0.0,"rotation":0.0,"id":238,"width":106.56,"height":44.0,"uid":null,"order":6,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Container #2

eth0 172.16.1.11/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":40.0,"y":-26.067047119140625,"rotation":0.0,"id":258,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":7,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":237,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":241,"py":1.0,"px":0.7071067811865476}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[153.5,266.0670471191406],[117.36753236814712,224.06704711914062]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":50.0,"y":-16.067047119140625,"rotation":0.0,"id":259,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":8,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":225,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":241,"py":0.9999999999999996,"px":0.29289321881345254}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[21.5,256.0670471191406],[62.632467631852876,214.0670471191406]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":60.0,"y":-6.067047119140625,"rotation":0.0,"id":260,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":9,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":241,"py":0.5,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":246,"py":0.5,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[75.0,180.06704711914062],[215.32345076546227,90.06897143333742]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":3.0,"y":184.5,"rotation":0.0,"id":261,"width":79.0,"height":32.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":10,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Docker

Host #1

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":283.0,"y":177.0,"rotation":0.0,"id":276,"width":252.0,"height":129.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":11,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":2.0,"strokeColor":"#434343","fillColor":"#c5e4fc","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":0.93,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":291.0,"y":240.0,"rotation":0.0,"id":274,"width":111.0,"height":57.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":12,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.73,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[{"x":2.2199999999999993,"y":0.0,"rotation":0.0,"id":275,"width":106.56,"height":45.0,"uid":null,"order":14,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Container #3

eth0

172.16.1.12/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":413.0,"y":240.0,"rotation":0.0,"id":272,"width":111.0,"height":57.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":15,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.73,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[{"x":2.2199999999999993,"y":0.0,"rotation":0.0,"id":273,"width":106.56,"height":44.0,"uid":null,"order":17,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Container #4

eth0 172.16.1.13/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":315.0,"y":-26.067047119140625,"rotation":0.0,"id":269,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":18,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":272,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":270,"py":1.0,"px":0.7071067811865476}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[153.5,266.0670471191406],[117.36753236814712,224.06704711914062]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":325.0,"y":-16.067047119140625,"rotation":0.0,"id":268,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":19,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":274,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":270,"py":0.9999999999999996,"px":0.29289321881345254}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[21.5,256.0670471191406],[62.632467631852876,214.0670471191406]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":278.0,"y":184.5,"rotation":0.0,"id":267,"width":79.0,"height":32.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":20,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Docker

Host #2

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":70.0,"y":3.932952880859375,"rotation":0.0,"id":278,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":21,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":270,"py":0.5,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":246,"py":0.5,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[340.0,170.06704711914062],[205.32345076546227,80.06897143333742]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":167.32131882292583,"y":39.0019243141968,"rotation":0.0,"id":246,"width":216.0042638850729,"height":90.0,"uid":"com.gliffy.shape.cisco.cisco_v1.storage.cloud","order":22,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.cisco.cisco_v1.storage.cloud","strokeWidth":2.0,"strokeColor":"#333333","fillColor":"#434343","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":356.0,"y":150.0,"rotation":0.0,"id":270,"width":108.0,"height":48.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":23,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#cccccc","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":1.0,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[{"x":1.8620689655172418,"y":0.0,"rotation":0.0,"id":271,"width":104.27586206896557,"height":42.0,"uid":null,"order":25,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

(Host) eth0

172.16.1.253/24

(IP Optional)

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":81.0,"y":150.0,"rotation":0.0,"id":241,"width":108.0,"height":48.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":26,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#cccccc","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":1.0,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[{"x":1.8620689655172415,"y":0.0,"rotation":0.0,"id":242,"width":104.27586206896555,"height":42.0,"uid":null,"order":28,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

(Host) eth0

172.16.1.254/24

(IP Optional)

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":224.0,"y":64.19999694824219,"rotation":0.0,"id":262,"width":120.00000000000001,"height":32.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":29,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Network Gateway

172.16.1.1/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":307.5,"rotation":0.0,"id":282,"width":541.0,"height":36.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":30,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Containers Attached Directly to Parent Interface. No Bridge Used (Docker0)

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"layers":[{"guid":"9wom3rMkTrb3","order":0,"name":"Layer 0","active":true,"locked":false,"visible":true,"nodeIndex":32}],"shapeStyles":{},"lineStyles":{"global":{"fill":"none","stroke":"#000000","strokeWidth":1,"orthoMode":2}},"textStyles":{"global":{"italic":true,"face":"Arial","size":"20px","color":"#000000","bold":false}}},"metadata":{"title":"untitled","revision":0,"exportBorder":false,"loadPosition":"default","libraries":["com.gliffy.libraries.basic.basic_v1.default","com.gliffy.libraries.flowchart.flowchart_v1.default","com.gliffy.libraries.swimlanes.swimlanes_v1.default","com.gliffy.libraries.images","com.gliffy.libraries.network.network_v4.home","com.gliffy.libraries.network.network_v4.business","com.gliffy.libraries.network.network_v4.rack","com.gliffy.libraries.network.network_v3.home","com.gliffy.libraries.network.network_v3.business","com.gliffy.libraries.network.network_v3.rack"],"lastSerialized":1458124258706,"analyticsProduct":"Confluence"},"embeddedResources":{"index":0,"resources":[]}} \ No newline at end of file diff --git a/vendor/github.com/docker/docker/experimental/images/macvlan-bridge-ipvlan-l2.png b/vendor/github.com/docker/docker/experimental/images/macvlan-bridge-ipvlan-l2.png deleted file mode 100644 index 13aa4f2..0000000 Binary files a/vendor/github.com/docker/docker/experimental/images/macvlan-bridge-ipvlan-l2.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/experimental/images/macvlan-bridge-ipvlan-l2.svg b/vendor/github.com/docker/docker/experimental/images/macvlan-bridge-ipvlan-l2.svg deleted file mode 100644 index 757871e..0000000 --- a/vendor/github.com/docker/docker/experimental/images/macvlan-bridge-ipvlan-l2.svg +++ /dev/null @@ -1 +0,0 @@ -Container #1eth0172.16.1.10/24Container #2eth0172.16.1.11/24DockerHost #1Container #3eth0172.16.1.12/24Container #4eth0172.16.1.13/24DockerHost #2(Host)eth0172.16.1.253/24(IPOptional)(Host)eth0172.16.1.254/24(IPOptional)NetworkGateway172.16.1.1/24ContainersAttachedDirectlytoParentInterface.NoBridgeUsed (Docker0)MacvlanBridgeMode &IpvlanL2Mode \ No newline at end of file diff --git a/vendor/github.com/docker/docker/experimental/images/multi_tenant_8021q_vlans.gliffy b/vendor/github.com/docker/docker/experimental/images/multi_tenant_8021q_vlans.gliffy deleted file mode 100644 index 40eed17..0000000 --- a/vendor/github.com/docker/docker/experimental/images/multi_tenant_8021q_vlans.gliffy +++ /dev/null @@ -1 +0,0 @@ -{"contentType":"application/gliffy+json","version":"1.3","stage":{"background":"#ffffff","width":389,"height":213,"nodeIndex":276,"autoFit":true,"exportBorder":false,"gridOn":true,"snapToGrid":false,"drawingGuidesOn":false,"pageBreaksOn":false,"printGridOn":false,"printPaper":"LETTER","printShrinkToFit":false,"printPortrait":true,"maxWidth":5000,"maxHeight":5000,"themeData":null,"viewportType":"default","fitBB":{"min":{"x":5,"y":6.6999969482421875},"max":{"x":389,"y":212.14285409109937}},"printModel":{"pageSize":"a4","portrait":false,"fitToOnePage":false,"displayPageBreaks":false},"objects":[{"x":64.0,"y":36.0,"rotation":0.0,"id":216,"width":211.0,"height":31.0,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":10,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":5.0,"strokeColor":"#e69138","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":10.0,"controlPath":[[-12.0,33.0],[84.0,33.0],[84.0,86.0],[120.0,86.0]],"lockSegments":{"1":true},"ortho":true}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":190.0,"y":32.0,"rotation":0.0,"id":254,"width":211.0,"height":31.0,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":11,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":5.0,"strokeColor":"#f1c232","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":10.0,"controlPath":[[-142.0,16.0],[54.0,16.0],[54.0,115.0],[87.0,115.0]],"lockSegments":{"1":true},"ortho":true}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":133.38636363636374,"y":108.14285409109937,"rotation":0.0,"id":226,"width":123.00000000000001,"height":104.0,"uid":"com.gliffy.shape.iphone.iphone_ios7.icons_glyphs.glyph_cloud","order":12,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.iphone.iphone_ios7.icons_glyphs.glyph_cloud","strokeWidth":1.0,"strokeColor":"#000000","fillColor":"#999999","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":15.147567221510933,"y":139.96785409109907,"rotation":0.0,"id":115,"width":107.40845070422536,"height":49.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":29,"lockAspectRatio":false,"lockShape":false,"children":[{"x":31.506478873239438,"y":2.4460032626429853,"rotation":0.0,"id":116,"width":44.395492957746484,"height":29.54388254486117,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":17,"lockAspectRatio":false,"lockShape":false,"children":[{"x":20.86588169014084,"y":2.637846655791175,"rotation":0.0,"id":117,"width":2.663729577464789,"height":24.268189233278818,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":26,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":120,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":120,"py":1.0,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[1.3318647887324033,-1.055138662316466],[1.3318647887324033,25.3233278955953]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":36.84825915492961,"y":2.637846655791175,"rotation":0.0,"id":118,"width":1.0000000000000002,"height":25.323327895595277,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":23,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-0.8875219090985048,-1.0551386623167391],[-0.8875219090985048,25.323327895595412]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":7.103278873239435,"y":1.230995106035881,"rotation":0.0,"id":119,"width":1.0000000000000002,"height":25.323327895595277,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":20,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[1.2752008616871728,0.3517128874389471],[1.2752008616871728,26.73017944535047]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":1.5827079934747048,"rotation":0.0,"id":120,"width":44.395492957746484,"height":26.378466557911768,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":15,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":2.0,"strokeColor":"#6fa8dc","fillColor":"#3d85c6","gradient":true,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":37.199347471451986,"rotation":0.0,"id":121,"width":107.40845070422536,"height":28.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":28,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

container1 - vlan10

192.168.1.2/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":68.0,"y":82.69999694824219,"rotation":0.0,"id":140,"width":150.0,"height":14.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":30,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"


","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":71.0,"y":4.1999969482421875,"rotation":0.0,"id":187,"width":108.99999999999999,"height":19.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":31,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

eth0 - 802.1q trunk

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":282.0,"y":8.0,"rotation":0.0,"id":199,"width":73.00000000000003,"height":40.150000000000006,"uid":"com.gliffy.shape.network.network_v4.business.router","order":32,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.network.network_v4.business.router","strokeWidth":1.0,"strokeColor":"#000000","fillColor":"#3966A0","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":62.0,"y":55.0,"rotation":0.0,"id":210,"width":211.0,"height":31.0,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":34,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":5.0,"strokeColor":"#e06666","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":10.0,"controlPath":[[-8.0,11.0],[-8.0,34.0],[26.0,34.0],[26.0,57.0]],"lockSegments":{},"ortho":true}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":12.805718530101615,"y":11.940280333547719,"rotation":0.0,"id":134,"width":59.31028146989837,"height":83.0,"uid":"com.gliffy.shape.cisco.cisco_v1.servers.standard_host","order":35,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.cisco.cisco_v1.servers.standard_host","strokeWidth":2.0,"strokeColor":"#333333","fillColor":"#3d85c6","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":64.0,"y":73.19999694824219,"rotation":0.0,"id":211,"width":60.0,"height":14.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":36,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

eth0.10

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":65.0,"y":52.19999694824219,"rotation":0.0,"id":212,"width":60.0,"height":14.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":37,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

eth0.20

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":7.386363636363733,"y":108.14285409109937,"rotation":0.0,"id":219,"width":123.00000000000001,"height":104.0,"uid":"com.gliffy.shape.iphone.iphone_ios7.icons_glyphs.glyph_cloud","order":38,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.iphone.iphone_ios7.icons_glyphs.glyph_cloud","strokeWidth":1.0,"strokeColor":"#000000","fillColor":"#999999","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":139.1475672215109,"y":139.96785409109907,"rotation":0.0,"id":227,"width":107.40845070422536,"height":49.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":55,"lockAspectRatio":false,"lockShape":false,"children":[{"x":31.506478873239438,"y":2.4460032626429853,"rotation":0.0,"id":228,"width":44.395492957746484,"height":29.54388254486117,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":43,"lockAspectRatio":false,"lockShape":false,"children":[{"x":20.86588169014084,"y":2.637846655791175,"rotation":0.0,"id":229,"width":2.663729577464789,"height":24.268189233278818,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":52,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":232,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":232,"py":1.0,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[1.3318647887323891,-1.055138662316466],[1.3318647887323891,25.3233278955953]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":36.84825915492961,"y":2.637846655791175,"rotation":0.0,"id":230,"width":1.0000000000000002,"height":25.323327895595277,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":49,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-0.8875219090985048,-1.0551386623167391],[-0.8875219090985048,25.323327895595412]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":7.103278873239435,"y":1.230995106035881,"rotation":0.0,"id":231,"width":1.0000000000000002,"height":25.323327895595277,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":46,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[1.2752008616871728,0.3517128874389471],[1.2752008616871728,26.73017944535047]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":1.5827079934747048,"rotation":0.0,"id":232,"width":44.395492957746484,"height":26.378466557911768,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":41,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":2.0,"strokeColor":"#6fa8dc","fillColor":"#3d85c6","gradient":true,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":37.199347471451986,"rotation":0.0,"id":233,"width":107.40845070422536,"height":28.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":54,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

container2 - vlan20

172.16.1.2/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":259.38636363636374,"y":108.14285409109937,"rotation":0.0,"id":248,"width":123.00000000000001,"height":104.0,"uid":"com.gliffy.shape.iphone.iphone_ios7.icons_glyphs.glyph_cloud","order":56,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.iphone.iphone_ios7.icons_glyphs.glyph_cloud","strokeWidth":1.0,"strokeColor":"#000000","fillColor":"#999999","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":265.14756722151094,"y":139.96785409109907,"rotation":0.0,"id":241,"width":107.40845070422536,"height":49.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":73,"lockAspectRatio":false,"lockShape":false,"children":[{"x":31.506478873239438,"y":2.4460032626429853,"rotation":0.0,"id":242,"width":44.395492957746484,"height":29.54388254486117,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":61,"lockAspectRatio":false,"lockShape":false,"children":[{"x":20.86588169014084,"y":2.637846655791175,"rotation":0.0,"id":243,"width":2.663729577464789,"height":24.268189233278818,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":70,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":246,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":246,"py":1.0,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[1.3318647887323891,-1.055138662316466],[1.3318647887323891,25.3233278955953]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":36.84825915492961,"y":2.637846655791175,"rotation":0.0,"id":244,"width":1.0000000000000002,"height":25.323327895595277,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":67,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-0.8875219090985048,-1.0551386623167391],[-0.8875219090985048,25.323327895595412]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":7.103278873239435,"y":1.230995106035881,"rotation":0.0,"id":245,"width":1.0000000000000002,"height":25.323327895595277,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":64,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#0b5394","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[1.2752008616871728,0.3517128874389471],[1.2752008616871728,26.73017944535047]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":1.5827079934747048,"rotation":0.0,"id":246,"width":44.395492957746484,"height":26.378466557911768,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":59,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":2.0,"strokeColor":"#6fa8dc","fillColor":"#3d85c6","gradient":true,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":37.199347471451986,"rotation":0.0,"id":247,"width":107.40845070422536,"height":28.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":72,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

container3 - vlan30

10.1.1.2/16

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":65.0,"y":31.199996948242188,"rotation":0.0,"id":253,"width":60.0,"height":14.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":74,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

eth0.30

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":44.49612211422149,"y":17.874999999999943,"rotation":0.0,"id":266,"width":275.00609168449375,"height":15.70000000000006,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":75,"lockAspectRatio":false,"lockShape":false,"children":[{"x":68.50387788577851,"y":43.12500000000006,"rotation":0.0,"id":258,"width":211.0,"height":31.0,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":9,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#999999","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-64.00387788577851,-31.924999999999997],[197.00221379871527,-31.925000000000153]],"lockSegments":{"1":true},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":68.50387788577851,"y":38.55333333333314,"rotation":0.0,"id":262,"width":211.0,"height":33.06666666666631,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":7,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#999999","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-64.00387788577851,-34.053333333332965],[197.00221379871527,-34.05333333333314]],"lockSegments":{"1":true},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":70.50387788577851,"y":40.7533333333331,"rotation":0.0,"id":261,"width":211.0,"height":33.06666666666631,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":5,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#e06666","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-64.00387788577851,-34.053333333332965],[197.00221379871527,-34.05333333333314]],"lockSegments":{"1":true},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":70.50387788577851,"y":42.88666666666643,"rotation":0.0,"id":260,"width":211.0,"height":33.06666666666631,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":3,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#e69138","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-64.00387788577851,-34.053333333332965],[197.00221379871527,-34.05333333333314]],"lockSegments":{"1":true},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":73.50387788577851,"y":43.95333333333309,"rotation":0.0,"id":259,"width":211.0,"height":33.06666666666631,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":1,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":2.0,"strokeColor":"#ffe599","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-64.00387788577851,-34.053333333332965],[197.00221379871527,-34.05333333333314]],"lockSegments":{"1":true},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":248.0,"y":51.19999694824219,"rotation":0.0,"id":207,"width":143.0,"height":70.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":33,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Network Router (gateway)

vlan10 - 192.168.1.1/24

vlan20 - 172.16.1.1/24

vlan30 - 10.1.1.1/16

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":3.0,"y":88.19999694824219,"rotation":0.0,"id":272,"width":77.99999999999999,"height":28.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":76,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Docker Host

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"layers":[{"guid":"9wom3rMkTrb3","order":0,"name":"Layer 0","active":true,"locked":false,"visible":true,"nodeIndex":80}],"shapeStyles":{},"lineStyles":{"global":{"stroke":"#e06666","strokeWidth":2,"orthoMode":1}},"textStyles":{"global":{"bold":true,"face":"Arial","size":"12px","color":"#000000"}}},"metadata":{"title":"untitled","revision":0,"exportBorder":false,"loadPosition":"default","libraries":["com.gliffy.libraries.network.network_v4.home","com.gliffy.libraries.network.network_v4.business","com.gliffy.libraries.network.network_v4.rack","com.gliffy.libraries.network.network_v3.home","com.gliffy.libraries.network.network_v3.business","com.gliffy.libraries.network.network_v3.rack"],"lastSerialized":1457586821719,"analyticsProduct":"Confluence"},"embeddedResources":{"index":0,"resources":[]}} \ No newline at end of file diff --git a/vendor/github.com/docker/docker/experimental/images/multi_tenant_8021q_vlans.png b/vendor/github.com/docker/docker/experimental/images/multi_tenant_8021q_vlans.png deleted file mode 100644 index a38633c..0000000 Binary files a/vendor/github.com/docker/docker/experimental/images/multi_tenant_8021q_vlans.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/experimental/images/multi_tenant_8021q_vlans.svg b/vendor/github.com/docker/docker/experimental/images/multi_tenant_8021q_vlans.svg deleted file mode 100644 index 5c6c607..0000000 --- a/vendor/github.com/docker/docker/experimental/images/multi_tenant_8021q_vlans.svg +++ /dev/null @@ -1 +0,0 @@ -container1 -vlan10192.168.1.2/24eth0 -802.1qtrunkNetworkRouter (gateway)vlan10 -192.168.1.1/24vlan20172.16.1.1/24vlan3010.1.1.1/16eth0.10eth0.20container2 -vlan20172.16.1.2/24container3 -vlan3010.1.1.2/16eth0.30DockerHost \ No newline at end of file diff --git a/vendor/github.com/docker/docker/experimental/images/vlans-deeper-look.gliffy b/vendor/github.com/docker/docker/experimental/images/vlans-deeper-look.gliffy deleted file mode 100644 index 4d9f276..0000000 --- a/vendor/github.com/docker/docker/experimental/images/vlans-deeper-look.gliffy +++ /dev/null @@ -1 +0,0 @@ -{"contentType":"application/gliffy+json","version":"1.3","stage":{"background":"#FFFFFF","width":566,"height":581,"nodeIndex":500,"autoFit":true,"exportBorder":false,"gridOn":true,"snapToGrid":false,"drawingGuidesOn":false,"pageBreaksOn":false,"printGridOn":false,"printPaper":"LETTER","printShrinkToFit":false,"printPortrait":true,"maxWidth":5000,"maxHeight":5000,"themeData":{"uid":"com.gliffy.theme.beach_day","name":"Beach Day","shape":{"primary":{"strokeWidth":2,"strokeColor":"#00A4DA","fillColor":"#AEE4F4","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#004257"}},"secondary":{"strokeWidth":2,"strokeColor":"#CDB25E","fillColor":"#EACF81","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#332D1A"}},"tertiary":{"strokeWidth":2,"strokeColor":"#FFBE00","fillColor":"#FFF1CB","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#000000"}},"highlight":{"strokeWidth":2,"strokeColor":"#00A4DA","fillColor":"#00A4DA","gradient":false,"dropShadow":false,"opacity":1,"text":{"color":"#ffffff"}}},"line":{"strokeWidth":2,"strokeColor":"#00A4DA","fillColor":"none","arrowType":2,"interpolationType":"quadratic","cornerRadius":0,"text":{"color":"#002248"}},"text":{"color":"#002248"},"stage":{"color":"#FFFFFF"}},"viewportType":"default","fitBB":{"min":{"x":-3,"y":-1.0100878848684474},"max":{"x":566,"y":581}},"printModel":{"pageSize":"a4","portrait":false,"fitToOnePage":false,"displayPageBreaks":false},"objects":[{"x":-5.0,"y":-1.0100878848684474,"rotation":0.0,"id":499,"width":569.0,"height":582.0100878848684,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":103,"lockAspectRatio":false,"lockShape":false,"children":[{"x":374.0,"y":44.510087884868476,"rotation":0.0,"id":497,"width":145.0,"height":32.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":101,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Network & other

Docker Hosts

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":157.40277777777783,"y":108.18042331083174,"rotation":0.0,"id":492,"width":121.19444444444446,"height":256.03113588084784,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":99,"lockAspectRatio":false,"lockShape":false,"children":[{"x":-126.13675213675185,"y":31.971494223140525,"rotation":180.0,"id":453,"width":11.1452323717951,"height":61.19357171974171,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":57,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":6.0,"strokeColor":"#38761d","fillColor":"#38761d","dashStyle":"1.0,1.0","startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":10.0,"controlPath":[[-121.4915197649562,-156.36606993796556],[-121.49151976495622,-99.52846483047983],[-229.68596420939843,-99.52846483047591],[-229.68596420939843,-34.22088765589871]],"lockSegments":{"1":true},"ortho":true}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":289.82598824786317,"y":137.23816896148608,"rotation":180.0,"id":454,"width":11.1452323717951,"height":61.19357171974171,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":55,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":6.0,"strokeColor":"#38761d","fillColor":"#38761d","dashStyle":"1.0,1.0","startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":10.0,"controlPath":[[291.05455395299924,191.93174068122784],[291.05455395299924,106.06051735724502],[186.27677617521402,106.06051735724502],[186.27677617521402,69.78655839914467]],"lockSegments":{},"ortho":true}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":372.0,"y":332.0100878848684,"rotation":0.0,"id":490,"width":144.0,"height":60.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":97,"lockAspectRatio":false,"lockShape":false,"children":[{"x":0.0,"y":9.5,"rotation":0.0,"id":365,"width":141.0,"height":40.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":98,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

 Parent: eth0.30

VLAN: 30

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":0.0,"rotation":0.0,"id":342,"width":144.0,"height":60.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":96,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#eb6c6c","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.99,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":52.0,"y":332.0100878848684,"rotation":0.0,"id":489,"width":144.0,"height":60.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":92,"lockAspectRatio":false,"lockShape":false,"children":[{"x":1.0,"y":10.5,"rotation":0.0,"id":367,"width":138.0,"height":40.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":93,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Parent: eth0.10

VLAN ID: 10

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":0.0,"rotation":0.0,"id":340,"width":144.0,"height":60.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":91,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#5fcc5a","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.99,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":289.40277777777794,"y":126.43727235088903,"rotation":0.0,"id":486,"width":121.19444444444446,"height":250.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":88,"lockAspectRatio":false,"lockShape":false,"children":[{"x":236.18596420940128,"y":158.89044937932732,"rotation":0.0,"id":449,"width":11.1452323717951,"height":59.50782702798556,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":53,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":6.0,"strokeColor":"#cc0000","fillColor":"#cc0000","dashStyle":"1.0,1.0","startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":10.0,"controlPath":[[-121.49151976495682,-152.05853787273531],[-121.49151976495682,-81.64750068755309],[-229.68596420940125,-81.64750068755139],[-229.68596420940125,-33.27817949077674]],"lockSegments":{},"ortho":true}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":-179.77677617521388,"y":56.523633779319084,"rotation":0.0,"id":450,"width":11.1452323717951,"height":59.50782702798556,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":51,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":6.0,"strokeColor":"#cc0000","fillColor":"#cc0000","dashStyle":"1.0,1.0","startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":10.0,"controlPath":[[291.0545539529992,186.6444547140887],[291.0545539529992,117.79470574474337],[186.276776175214,117.79470574474337],[186.276776175214,67.8640963321146]],"lockSegments":{"1":true},"ortho":true}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":447.0,"y":150.01008788486848,"rotation":0.0,"id":472,"width":46.99999999999994,"height":27.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":87,"lockAspectRatio":false,"lockShape":false,"children":[{"x":0.0,"y":0.0,"rotation":0.0,"id":473,"width":37.09803921568625,"height":18.000000000000004,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":86,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#666666","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":5.485490196078445,"y":5.153846153846132,"rotation":0.0,"id":474,"width":37.09803921568625,"height":18.000000000000004,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":84,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#666666","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":9.901960784313701,"y":9.0,"rotation":0.0,"id":475,"width":37.09803921568625,"height":18.000000000000004,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":82,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#666666","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":368.0,"y":101.71008483311067,"rotation":0.0,"id":477,"width":140.0,"height":56.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":80,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Gateway 10.1.30.1

  and other containers on the same VLAN/subnet

 

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":350.51767083236393,"y":87.47159983339776,"rotation":0.0,"id":478,"width":175.20345848455912,"height":73.0,"uid":"com.gliffy.shape.cisco.cisco_v1.storage.cloud","order":79,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.cisco.cisco_v1.storage.cloud","strokeWidth":2.0,"strokeColor":"#333333","fillColor":"#cc0000","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":94.0,"y":155.01008788486848,"rotation":0.0,"id":463,"width":46.99999999999994,"height":27.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":78,"lockAspectRatio":false,"lockShape":false,"children":[{"x":0.0,"y":0.0,"rotation":0.0,"id":464,"width":37.09803921568625,"height":18.000000000000004,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":77,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#666666","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":5.485490196078445,"y":5.153846153846132,"rotation":0.0,"id":465,"width":37.09803921568625,"height":18.000000000000004,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":75,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#666666","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":9.901960784313701,"y":9.0,"rotation":0.0,"id":466,"width":37.09803921568625,"height":18.000000000000004,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":73,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#666666","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":80.0,"y":109.71008483311067,"rotation":0.0,"id":468,"width":140.0,"height":56.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":71,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Gateway 10.1.10.1

  and other containers on the same VLAN/subnet

 

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":62.51767083236396,"y":95.47159983339776,"rotation":0.0,"id":469,"width":175.20345848455912,"height":73.0,"uid":"com.gliffy.shape.cisco.cisco_v1.storage.cloud","order":70,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.cisco.cisco_v1.storage.cloud","strokeWidth":2.0,"strokeColor":"#333333","fillColor":"#38761d","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":341.0,"y":40.010087884868476,"rotation":0.0,"id":460,"width":46.99999999999994,"height":27.0,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":69,"lockAspectRatio":false,"lockShape":false,"children":[{"x":0.0,"y":0.0,"rotation":0.0,"id":417,"width":37.09803921568625,"height":18.000000000000004,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":68,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#666666","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":5.485490196078445,"y":5.153846153846132,"rotation":0.0,"id":418,"width":37.09803921568625,"height":18.000000000000004,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":66,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#666666","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":9.901960784313701,"y":9.0,"rotation":0.0,"id":419,"width":37.09803921568625,"height":18.000000000000004,"uid":"com.gliffy.shape.basic.basic_v1.default.rectangle","order":64,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#666666","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":198.51767083236396,"y":41.471599833397754,"rotation":0.0,"id":459,"width":175.20345848455912,"height":79.73848499971291,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":62,"lockAspectRatio":false,"lockShape":false,"children":[{"x":17.482329167636067,"y":14.23848499971291,"rotation":0.0,"id":458,"width":140.0,"height":56.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":61,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Gateway 10.1.20.1

  and other containers on the same VLAN/subnet

 

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":0.0,"rotation":0.0,"id":330,"width":175.20345848455912,"height":73.0,"uid":"com.gliffy.shape.cisco.cisco_v1.storage.cloud","order":59,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.cisco.cisco_v1.storage.cloud","strokeWidth":2.0,"strokeColor":"#333333","fillColor":"#ff9900","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":279.0,"y":129.01008788486848,"rotation":0.0,"id":440,"width":5.0,"height":227.0,"uid":"com.gliffy.shape.basic.basic_v1.default.line","order":49,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":6.0,"strokeColor":"#ff9900","fillColor":"#ff9900","dashStyle":"1.0,1.0","startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[4.000000000000057,-25.08952732449731],[4.000000000000114,176.01117206537933]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":56.0,"y":503.0913886978766,"rotation":0.0,"id":386,"width":135.0,"height":20.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":48,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Frontend

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":62.0,"y":420.0100878848684,"rotation":0.0,"id":381,"width":120.0,"height":74.18803418803415,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":41,"lockAspectRatio":false,"lockShape":false,"children":[{"x":0.0,"y":0.0,"rotation":0.0,"id":382,"width":102.08955223880598,"height":54.91841491841488,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":44,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.97,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[{"x":2.0417910447761187,"y":0.0,"rotation":0.0,"id":383,"width":98.00597014925374,"height":44.0,"uid":null,"order":47,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Container(s)

Eth0 10.1.10.0/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":8.955223880597016,"y":9.634809634809635,"rotation":0.0,"id":384,"width":102.08955223880598,"height":54.91841491841488,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":42,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.97,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":17.910447761194032,"y":19.26961926961927,"rotation":0.0,"id":385,"width":102.08955223880598,"height":54.91841491841488,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":40,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.97,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":382.0,"y":420.0100878848684,"rotation":0.0,"id":376,"width":120.0,"height":74.18803418803415,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":31,"lockAspectRatio":false,"lockShape":false,"children":[{"x":0.0,"y":0.0,"rotation":0.0,"id":377,"width":102.08955223880598,"height":54.91841491841488,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":34,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.97,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[{"x":2.0417910447761187,"y":0.0,"rotation":0.0,"id":378,"width":98.00597014925374,"height":44.0,"uid":null,"order":37,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Container(s)

Eth0 10.1.30.0/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":8.955223880597016,"y":9.634809634809635,"rotation":0.0,"id":379,"width":102.08955223880598,"height":54.91841491841488,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":32,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.97,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":17.910447761194032,"y":19.26961926961927,"rotation":0.0,"id":380,"width":102.08955223880598,"height":54.91841491841488,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":30,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.97,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":214.0,"y":503.0100878848685,"rotation":0.0,"id":374,"width":135.0,"height":20.162601626016258,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":27,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Backend

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":376.0,"y":502.0100878848684,"rotation":0.0,"id":373,"width":135.0,"height":20.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":26,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Credit Cards

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":627.0,"y":99.94304076572786,"rotation":0.0,"id":364,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":25,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":363,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":342,"py":1.0,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":1.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-183.0,310.0670471191406],[-183.0,292.0670471191406]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":372.0,"y":410.0100878848684,"rotation":0.0,"id":363,"width":144.0,"height":117.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":24,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#eb6c6c","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.99,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":218.0,"y":341.5100878848684,"rotation":0.0,"id":366,"width":132.0,"height":40.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":23,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Parent: eth0.20

VLAN ID: 20

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":297.0,"y":89.94304076572786,"rotation":0.0,"id":356,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":22,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":353,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":343,"py":1.0,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":1.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[-13.0,320.0670471191406],[-13.0,302.0670471191406]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":222.0,"y":420.0100878848684,"rotation":0.0,"id":348,"width":120.0,"height":74.18803418803415,"uid":"com.gliffy.shape.basic.basic_v1.default.group","order":21,"lockAspectRatio":false,"lockShape":false,"children":[{"x":0.0,"y":0.0,"rotation":0.0,"id":349,"width":102.08955223880598,"height":54.91841491841488,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":17,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.97,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[{"x":2.0417910447761187,"y":0.0,"rotation":0.0,"id":350,"width":98.00597014925374,"height":44.0,"uid":null,"order":20,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":8,"paddingRight":8,"paddingBottom":8,"paddingLeft":8,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Container(s)

Eth0 10.1.20.0/24

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":8.955223880597016,"y":9.634809634809635,"rotation":0.0,"id":351,"width":102.08955223880598,"height":54.91841491841488,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":15,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.97,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":17.910447761194032,"y":19.26961926961927,"rotation":0.0,"id":352,"width":102.08955223880598,"height":54.91841491841488,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":13,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#4cacf5","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.97,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":212.0,"y":410.0100878848684,"rotation":0.0,"id":353,"width":144.0,"height":119.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":11,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#fca13f","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.99,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":212.0,"y":332.0100878848684,"rotation":0.0,"id":343,"width":144.0,"height":60.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":10,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#fca13f","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.99,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":203.0,"y":307.5100878848684,"rotation":0.0,"id":333,"width":160.0,"height":22.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":9,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

eth0 Interface

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":303.0,"y":240.51008788486845,"rotation":0.0,"id":323,"width":261.0,"height":48.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":8,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

802.1Q Trunk - can be a single Ethernet link or Multiple Bonded Ethernet links

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":36.0,"y":291.0100878848684,"rotation":0.0,"id":290,"width":497.0,"height":80.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":7,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#cccccc","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":1.0,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":0.0,"y":543.5100878848684,"rotation":0.0,"id":282,"width":569.0,"height":32.0,"uid":"com.gliffy.shape.basic.basic_v1.default.text","order":6,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Text","Text":{"overflow":"none","paddingTop":2,"paddingRight":2,"paddingBottom":2,"paddingLeft":2,"outerPaddingTop":6,"outerPaddingRight":6,"outerPaddingBottom":2,"outerPaddingLeft":6,"type":"fixed","lineTValue":null,"linePerpValue":null,"cardinalityType":null,"html":"

Docker Host: Frontend, Backend & Credit Card App Tiers are Isolated but can still communicate inside parent interface or any other Docker hosts using the VLAN ID

","tid":null,"valign":"middle","vposition":"none","hposition":"none"}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":-33.0,"y":79.94304076572786,"rotation":0.0,"id":269,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":5,"lockAspectRatio":false,"lockShape":false,"constraints":{"constraints":[],"startConstraint":{"type":"StartPositionConstraint","StartPositionConstraint":{"nodeId":345,"py":0.0,"px":0.5}},"endConstraint":{"type":"EndPositionConstraint","EndPositionConstraint":{"nodeId":340,"py":1.0,"px":0.5}}},"graphic":{"type":"Line","Line":{"strokeWidth":1.0,"strokeColor":"#000000","fillColor":"none","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[157.0,330.0670471191406],[157.0,312.0670471191406]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":52.0,"y":410.0100878848684,"rotation":0.0,"id":345,"width":144.0,"height":119.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":4,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":1.0,"strokeColor":"#434343","fillColor":"#5fcc5a","gradient":false,"dashStyle":null,"dropShadow":true,"state":0,"opacity":0.99,"shadowX":4.0,"shadowY":4.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":20.0,"y":323.0100878848684,"rotation":0.0,"id":276,"width":531.0,"height":259.0,"uid":"com.gliffy.shape.basic.basic_v1.default.round_rectangle","order":3,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.round_rectangle.basic_v1","strokeWidth":2.0,"strokeColor":"#434343","fillColor":"#c5e4fc","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":0.93,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":19.609892022503004,"y":20.27621073737908,"rotation":355.62347411485274,"id":246,"width":540.0106597126834,"height":225.00000000000003,"uid":"com.gliffy.shape.cisco.cisco_v1.storage.cloud","order":2,"lockAspectRatio":true,"lockShape":false,"graphic":{"type":"Shape","Shape":{"tid":"com.gliffy.stencil.cisco.cisco_v1.storage.cloud","strokeWidth":2.0,"strokeColor":"#333333","fillColor":"#999999","gradient":false,"dashStyle":null,"dropShadow":false,"state":0,"opacity":1.0,"shadowX":0.0,"shadowY":0.0}},"linkMap":[],"children":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":1.0,"y":99.94304076572786,"rotation":0.0,"id":394,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":1,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":3.0,"strokeColor":"#666666","fillColor":"#999999","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[261.0,233.5670471191406],[261.0,108.05111187584177]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"},{"x":44.0,"y":90.94304076572786,"rotation":0.0,"id":481,"width":100.0,"height":100.0,"uid":"com.gliffy.shape.uml.uml_v2.sequence.anchor_line","order":0,"lockAspectRatio":false,"lockShape":false,"graphic":{"type":"Line","Line":{"strokeWidth":3.0,"strokeColor":"#666666","fillColor":"#999999","dashStyle":null,"startArrow":0,"endArrow":0,"startArrowRotation":"auto","endArrowRotation":"auto","interpolationType":"linear","cornerRadius":null,"controlPath":[[261.0,233.56704711914062],[261.0,108.05111187584174]],"lockSegments":{},"ortho":false}},"linkMap":[],"hidden":false,"layerId":"9wom3rMkTrb3"}],"hidden":false,"layerId":"9wom3rMkTrb3"}],"layers":[{"guid":"9wom3rMkTrb3","order":0,"name":"Layer 0","active":true,"locked":false,"visible":true,"nodeIndex":104}],"shapeStyles":{},"lineStyles":{"global":{"fill":"#999999","stroke":"#38761d","strokeWidth":3,"dashStyle":"1.0,1.0","orthoMode":2}},"textStyles":{"global":{"bold":true,"face":"Arial","size":"14px","color":"#000000"}}},"metadata":{"title":"untitled","revision":0,"exportBorder":false,"loadPosition":"default","libraries":["com.gliffy.libraries.basic.basic_v1.default","com.gliffy.libraries.flowchart.flowchart_v1.default","com.gliffy.libraries.swimlanes.swimlanes_v1.default","com.gliffy.libraries.images","com.gliffy.libraries.network.network_v4.home","com.gliffy.libraries.network.network_v4.business","com.gliffy.libraries.network.network_v4.rack","com.gliffy.libraries.network.network_v3.home","com.gliffy.libraries.network.network_v3.business","com.gliffy.libraries.network.network_v3.rack"],"lastSerialized":1458117295143,"analyticsProduct":"Confluence"},"embeddedResources":{"index":0,"resources":[]}} \ No newline at end of file diff --git a/vendor/github.com/docker/docker/experimental/images/vlans-deeper-look.png b/vendor/github.com/docker/docker/experimental/images/vlans-deeper-look.png deleted file mode 100644 index 32d95f6..0000000 Binary files a/vendor/github.com/docker/docker/experimental/images/vlans-deeper-look.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/experimental/images/vlans-deeper-look.svg b/vendor/github.com/docker/docker/experimental/images/vlans-deeper-look.svg deleted file mode 100644 index 96cd21d..0000000 --- a/vendor/github.com/docker/docker/experimental/images/vlans-deeper-look.svg +++ /dev/null @@ -1 +0,0 @@ -DockerHost:Frontend,Backend &CreditCardAppTiersareIsolatedbutcanstillcommunicateinsideinterfaceoranyotherDockerhostsusingtheparentVLANID802.1QTrunk -canbeasingleEthernetlinkorMultipleBondedEthernetlinksInterfaceeth0Container(s)Eth010.1.20.0/24Parent:eth0.20VLANID:20CreditCardsBackendContainer(s)Eth010.1.30.0/24Container(s)Eth010.1.10.0/24FrontendGateway10.1.20.1andothercontainersonthesameVLAN/subnetGateway10.1.10.1andothercontainersonthesameVLAN/subnetGateway10.1.30.1andothercontainersonthesameVLAN/subnet:Parenteth0.10VLANID:10Parent:eth0.30VLAN:30NetworkotherDockerHosts \ No newline at end of file diff --git a/vendor/github.com/docker/docker/experimental/vlan-networks.md b/vendor/github.com/docker/docker/experimental/vlan-networks.md deleted file mode 100644 index caec6d6..0000000 --- a/vendor/github.com/docker/docker/experimental/vlan-networks.md +++ /dev/null @@ -1,471 +0,0 @@ -# Ipvlan Network Driver - -### Getting Started - -The Ipvlan driver is currently in experimental mode in order to incubate Docker users use cases and vet the implementation to ensure a hardened, production ready driver in a future release. Libnetwork now gives users total control over both IPv4 and IPv6 addressing. The VLAN driver builds on top of that in giving operators complete control of layer 2 VLAN tagging and even Ipvlan L3 routing for users interested in underlay network integration. For overlay deployments that abstract away physical constraints see the [multi-host overlay ](https://docs.docker.com/engine/userguide/networking/get-started-overlay/) driver. - -Ipvlan is a new twist on the tried and true network virtualization technique. The Linux implementations are extremely lightweight because rather than using the traditional Linux bridge for isolation, they are simply associated to a Linux Ethernet interface or sub-interface to enforce separation between networks and connectivity to the physical network. - -Ipvlan offers a number of unique features and plenty of room for further innovations with the various modes. Two high level advantages of these approaches are, the positive performance implications of bypassing the Linux bridge and the simplicity of having less moving parts. Removing the bridge that traditionally resides in between the Docker host NIC and container interface leaves a very simple setup consisting of container interfaces, attached directly to the Docker host interface. This result is easy access for external facing services as there is no port mappings in these scenarios. - -### Pre-Requisites - -- The examples on this page are all single host and setup using Docker experimental builds that can be installed with the following instructions: [Install Docker experimental](https://github.com/docker/docker/tree/master/experimental) - -- All of the examples can be performed on a single host running Docker. Any examples using a sub-interface like `eth0.10` can be replaced with `eth0` or any other valid parent interface on the Docker host. Sub-interfaces with a `.` are created on the fly. `-o parent` interfaces can also be left out of the `docker network create` all together and the driver will create a `dummy` interface that will enable local host connectivity to perform the examples. - -- Kernel requirements: - - - To check your current kernel version, use `uname -r` to display your kernel version - - Ipvlan Linux kernel v4.2+ (support for earlier kernels exists but is buggy) - -### Ipvlan L2 Mode Example Usage - -The ipvlan `L2` mode example is like the following image. The driver is specified with `-d driver_name` option. In this case `-d ipvlan`. - -![Simple Ipvlan L2 Mode Example](images/ipvlan_l2_simple.png) - -The parent interface in the next example `-o parent=eth0` is configured as followed: - -``` -ip addr show eth0 -3: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 - inet 192.168.1.250/24 brd 192.168.1.255 scope global eth0 -``` - -Use the network from the host's interface as the `--subnet` in the `docker network create`. The container will be attached to the same network as the host interface as set via the `-o parent=` option. - -Create the ipvlan network and run a container attaching to it: - -``` -# Ipvlan (-o ipvlan_mode= Defaults to L2 mode if not specified) -docker network create -d ipvlan \ - --subnet=192.168.1.0/24 \ - --gateway=192.168.1.1 \ - -o ipvlan_mode=l2 \ - -o parent=eth0 db_net - -# Start a container on the db_net network -docker run --net=db_net -it --rm alpine /bin/sh - -# NOTE: the containers can NOT ping the underlying host interfaces as -# they are intentionally filtered by Linux for additional isolation. -``` - -The default mode for Ipvlan is `l2`. If `-o ipvlan_mode=` are left unspecified, the default mode will be used. Similarly, if the `--gateway` is left empty, the first usable address on the network will be set as the gateway. For example, if the subnet provided in the network create is `--subnet=192.168.1.0/24` then the gateway the container receives is `192.168.1.1`. - -To help understand how this mode interacts with other hosts, the following figure shows the same layer 2 segment between two Docker hosts that applies to and Ipvlan L2 mode. - -![Multiple Ipvlan Hosts](images/macvlan-bridge-ipvlan-l2.png) - -The following will create the exact same network as the network `db_net` created prior, with the driver defaults for `--gateway=192.168.1.1` and `-o ipvlan_mode=l2`. - -``` -# Ipvlan (-o ipvlan_mode= Defaults to L2 mode if not specified) -docker network create -d ipvlan \ - --subnet=192.168.1.0/24 \ - -o parent=eth0 db_net_ipv - -# Start a container with an explicit name in daemon mode -docker run --net=db_net_ipv --name=ipv1 -itd alpine /bin/sh - -# Start a second container and ping using the container name -# to see the docker included name resolution functionality -docker run --net=db_net_ipv --name=ipv2 -it --rm alpine /bin/sh -ping -c 4 ipv1 - -# NOTE: the containers can NOT ping the underlying host interfaces as -# they are intentionally filtered by Linux for additional isolation. -``` - -The drivers also support the `--internal` flag that will completely isolate containers on a network from any communications external to that network. Since network isolation is tightly coupled to the network's parent interface the result of leaving the `-o parent=` option off of a network create is the exact same as the `--internal` option. If the parent interface is not specified or the `--internal` flag is used, a netlink type `dummy` parent interface is created for the user and used as the parent interface effectively isolating the network completely. - -The following two `docker network create` examples result in identical networks that you can attach container to: - -``` -# Empty '-o parent=' creates an isolated network -docker network create -d ipvlan \ - --subnet=192.168.10.0/24 isolated1 - -# Explicit '--internal' flag is the same: -docker network create -d ipvlan \ - --subnet=192.168.11.0/24 --internal isolated2 - -# Even the '--subnet=' can be left empty and the default -# IPAM subnet of 172.18.0.0/16 will be assigned -docker network create -d ipvlan isolated3 - -docker run --net=isolated1 --name=cid1 -it --rm alpine /bin/sh -docker run --net=isolated2 --name=cid2 -it --rm alpine /bin/sh -docker run --net=isolated3 --name=cid3 -it --rm alpine /bin/sh - -# To attach to any use `docker exec` and start a shell -docker exec -it cid1 /bin/sh -docker exec -it cid2 /bin/sh -docker exec -it cid3 /bin/sh -``` - -### Ipvlan 802.1q Trunk L2 Mode Example Usage - -Architecturally, Ipvlan L2 mode trunking is the same as Macvlan with regard to gateways and L2 path isolation. There are nuances that can be advantageous for CAM table pressure in ToR switches, one MAC per port and MAC exhaustion on a host's parent NIC to name a few. The 802.1q trunk scenario looks the same. Both modes adhere to tagging standards and have seamless integration with the physical network for underlay integration and hardware vendor plugin integrations. - -Hosts on the same VLAN are typically on the same subnet and almost always are grouped together based on their security policy. In most scenarios, a multi-tier application is tiered into different subnets because the security profile of each process requires some form of isolation. For example, hosting your credit card processing on the same virtual network as the frontend webserver would be a regulatory compliance issue, along with circumventing the long standing best practice of layered defense in depth architectures. VLANs or the equivocal VNI (Virtual Network Identifier) when using the Overlay driver, are the first step in isolating tenant traffic. - -![Docker VLANs in Depth](images/vlans-deeper-look.png) - -The Linux sub-interface tagged with a vlan can either already exist or will be created when you call a `docker network create`. `docker network rm` will delete the sub-interface. Parent interfaces such as `eth0` are not deleted, only sub-interfaces with a netlink parent index > 0. - -For the driver to add/delete the vlan sub-interfaces the format needs to be `interface_name.vlan_tag`. Other sub-interface naming can be used as the specified parent, but the link will not be deleted automatically when `docker network rm` is invoked. - -The option to use either existing parent vlan sub-interfaces or let Docker manage them enables the user to either completely manage the Linux interfaces and networking or let Docker create and delete the Vlan parent sub-interfaces (netlink `ip link`) with no effort from the user. - -For example: `eth0.10` to denote a sub-interface of `eth0` tagged with vlan id `10`. The equivalent `ip link` command would be `ip link add link eth0 name eth0.10 type vlan id 10`. - -The example creates the vlan tagged networks and then start two containers to test connectivity between containers. Different Vlans cannot ping one another without a router routing between the two networks. The default namespace is not reachable per ipvlan design in order to isolate container namespaces from the underlying host. - -**Vlan ID 20** - -In the first network tagged and isolated by the Docker host, `eth0.20` is the parent interface tagged with vlan id `20` specified with `-o parent=eth0.20`. Other naming formats can be used, but the links need to be added and deleted manually using `ip link` or Linux configuration files. As long as the `-o parent` exists anything can be used if compliant with Linux netlink. - -``` -# now add networks and hosts as you would normally by attaching to the master (sub)interface that is tagged -docker network create -d ipvlan \ - --subnet=192.168.20.0/24 \ - --gateway=192.168.20.1 \ - -o parent=eth0.20 ipvlan20 - -# in two separate terminals, start a Docker container and the containers can now ping one another. -docker run --net=ipvlan20 -it --name ivlan_test1 --rm alpine /bin/sh -docker run --net=ipvlan20 -it --name ivlan_test2 --rm alpine /bin/sh -``` - -**Vlan ID 30** - -In the second network, tagged and isolated by the Docker host, `eth0.30` is the parent interface tagged with vlan id `30` specified with `-o parent=eth0.30`. The `ipvlan_mode=` defaults to l2 mode `ipvlan_mode=l2`. It can also be explicitly set with the same result as shown in the next example. - -``` -# now add networks and hosts as you would normally by attaching to the master (sub)interface that is tagged. -docker network create -d ipvlan \ - --subnet=192.168.30.0/24 \ - --gateway=192.168.30.1 \ - -o parent=eth0.30 \ - -o ipvlan_mode=l2 ipvlan30 - -# in two separate terminals, start a Docker container and the containers can now ping one another. -docker run --net=ipvlan30 -it --name ivlan_test3 --rm alpine /bin/sh -docker run --net=ipvlan30 -it --name ivlan_test4 --rm alpine /bin/sh -``` - -The gateway is set inside of the container as the default gateway. That gateway would typically be an external router on the network. - -``` -$ ip route - default via 192.168.30.1 dev eth0 - 192.168.30.0/24 dev eth0 src 192.168.30.2 -``` - -Example: Multi-Subnet Ipvlan L2 Mode starting two containers on the same subnet and pinging one another. In order for the `192.168.114.0/24` to reach `192.168.116.0/24` it requires an external router in L2 mode. L3 mode can route between subnets that share a common `-o parent=`. - -Secondary addresses on network routers are common as an address space becomes exhausted to add another secondary to a L3 vlan interface or commonly referred to as a "switched virtual interface" (SVI). - -``` -docker network create -d ipvlan \ - --subnet=192.168.114.0/24 --subnet=192.168.116.0/24 \ - --gateway=192.168.114.254 --gateway=192.168.116.254 \ - -o parent=eth0.114 \ - -o ipvlan_mode=l2 ipvlan114 - -docker run --net=ipvlan114 --ip=192.168.114.10 -it --rm alpine /bin/sh -docker run --net=ipvlan114 --ip=192.168.114.11 -it --rm alpine /bin/sh -``` - -A key takeaway is, operators have the ability to map their physical network into their virtual network for integrating containers into their environment with no operational overhauls required. NetOps simply drops an 802.1q trunk into the Docker host. That virtual link would be the `-o parent=` passed in the network creation. For untagged (non-VLAN) links, it is as simple as `-o parent=eth0` or for 802.1q trunks with VLAN IDs each network gets mapped to the corresponding VLAN/Subnet from the network. - -An example being, NetOps provides VLAN ID and the associated subnets for VLANs being passed on the Ethernet link to the Docker host server. Those values are simply plugged into the `docker network create` commands when provisioning the Docker networks. These are persistent configurations that are applied every time the Docker engine starts which alleviates having to manage often complex configuration files. The network interfaces can also be managed manually by being pre-created and docker networking will never modify them, simply use them as parent interfaces. Example mappings from NetOps to Docker network commands are as follows: - -- VLAN: 10, Subnet: 172.16.80.0/24, Gateway: 172.16.80.1 - - - `--subnet=172.16.80.0/24 --gateway=172.16.80.1 -o parent=eth0.10` - -- VLAN: 20, IP subnet: 172.16.50.0/22, Gateway: 172.16.50.1 - - - `--subnet=172.16.50.0/22 --gateway=172.16.50.1 -o parent=eth0.20 ` - -- VLAN: 30, Subnet: 10.1.100.0/16, Gateway: 10.1.100.1 - - - `--subnet=10.1.100.0/16 --gateway=10.1.100.1 -o parent=eth0.30` - -### IPVlan L3 Mode Example - -IPVlan will require routes to be distributed to each endpoint. The driver only builds the Ipvlan L3 mode port and attaches the container to the interface. Route distribution throughout a cluster is beyond the initial implementation of this single host scoped driver. In L3 mode, the Docker host is very similar to a router starting new networks in the container. They are on networks that the upstream network will not know about without route distribution. For those curious how Ipvlan L3 will fit into container networking see the following examples. - -![Docker Ipvlan L2 Mode](images/ipvlan-l3.png) - -Ipvlan L3 mode drops all broadcast and multicast traffic. This reason alone makes Ipvlan L3 mode a prime candidate for those looking for massive scale and predictable network integrations. It is predictable and in turn will lead to greater uptimes because there is no bridging involved. Bridging loops have been responsible for high profile outages that can be hard to pinpoint depending on the size of the failure domain. This is due to the cascading nature of BPDUs (Bridge Port Data Units) that are flooded throughout a broadcast domain (VLAN) to find and block topology loops. Eliminating bridging domains, or at the least, keeping them isolated to a pair of ToRs (top of rack switches) will reduce hard to troubleshoot bridging instabilities. Ipvlan L2 modes is well suited for isolated VLANs only trunked into a pair of ToRs that can provide a loop-free non-blocking fabric. The next step further is to route at the edge via Ipvlan L3 mode that reduces a failure domain to a local host only. - -- L3 mode needs to be on a separate subnet as the default namespace since it requires a netlink route in the default namespace pointing to the Ipvlan parent interface. - -- The parent interface used in this example is `eth0` and it is on the subnet `192.168.1.0/24`. Notice the `docker network` is **not** on the same subnet as `eth0`. - -- Unlike ipvlan l2 modes, different subnets/networks can ping one another as long as they share the same parent interface `-o parent=`. - -``` -ip a show eth0 -3: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 - link/ether 00:50:56:39:45:2e brd ff:ff:ff:ff:ff:ff - inet 192.168.1.250/24 brd 192.168.1.255 scope global eth0 -``` - --A traditional gateway doesn't mean much to an L3 mode Ipvlan interface since there is no broadcast traffic allowed. Because of that, the container default gateway simply point the the containers `eth0` device. See below for CLI output of `ip route` or `ip -6 route` from inside an L3 container for details. - -The mode ` -o ipvlan_mode=l3` must be explicitly specified since the default ipvlan mode is `l2`. - -The following example does not specify a parent interface. The network drivers will create a dummy type link for the user rather then rejecting the network creation and isolating containers from only communicating with one another. - -``` -# Create the Ipvlan L3 network -docker network create -d ipvlan \ - --subnet=192.168.214.0/24 \ - --subnet=10.1.214.0/24 \ - -o ipvlan_mode=l3 ipnet210 - -# Test 192.168.214.0/24 connectivity -docker run --net=ipnet210 --ip=192.168.214.10 -itd alpine /bin/sh -docker run --net=ipnet210 --ip=10.1.214.10 -itd alpine /bin/sh - -# Test L3 connectivity from 10.1.214.0/24 to 192.168.212.0/24 -docker run --net=ipnet210 --ip=192.168.214.9 -it --rm alpine ping -c 2 10.1.214.10 - -# Test L3 connectivity from 192.168.212.0/24 to 10.1.214.0/24 -docker run --net=ipnet210 --ip=10.1.214.9 -it --rm alpine ping -c 2 192.168.214.10 - -``` - -Notice there is no `--gateway=` option in the network create. The field is ignored if one is specified `l3` mode. Take a look at the container routing table from inside of the container: - -``` -# Inside an L3 mode container -$ ip route - default dev eth0 - 192.168.120.0/24 dev eth0 src 192.168.120.2 -``` - -In order to ping the containers from a remote Docker host or the container be able to ping a remote host, the remote host or the physical network in between need to have a route pointing to the host IP address of the container's Docker host eth interface. More on this as we evolve the Ipvlan `L3` story. - -### Dual Stack IPv4 IPv6 Ipvlan L2 Mode - -- Not only does Libnetwork give you complete control over IPv4 addressing, but it also gives you total control over IPv6 addressing as well as feature parity between the two address families. - -- The next example will start with IPv6 only. Start two containers on the same VLAN `139` and ping one another. Since the IPv4 subnet is not specified, the default IPAM will provision a default IPv4 subnet. That subnet is isolated unless the upstream network is explicitly routing it on VLAN `139`. - -``` -# Create a v6 network -docker network create -d ipvlan \ - --subnet=2001:db8:abc2::/64 --gateway=2001:db8:abc2::22 \ - -o parent=eth0.139 v6ipvlan139 - -# Start a container on the network -docker run --net=v6ipvlan139 -it --rm alpine /bin/sh - -``` - -View the container eth0 interface and v6 routing table: - -``` - eth0@if55: mtu 1500 qdisc noqueue state UNKNOWN group default - link/ether 00:50:56:2b:29:40 brd ff:ff:ff:ff:ff:ff - inet 172.18.0.2/16 scope global eth0 - valid_lft forever preferred_lft forever - inet6 2001:db8:abc4::250:56ff:fe2b:2940/64 scope link - valid_lft forever preferred_lft forever - inet6 2001:db8:abc2::1/64 scope link nodad - valid_lft forever preferred_lft forever - -root@5c1dc74b1daa:/# ip -6 route -2001:db8:abc4::/64 dev eth0 proto kernel metric 256 -2001:db8:abc2::/64 dev eth0 proto kernel metric 256 -default via 2001:db8:abc2::22 dev eth0 metric 1024 -``` - -Start a second container and ping the first container's v6 address. - -``` -$ docker run --net=v6ipvlan139 -it --rm alpine /bin/sh - -root@b817e42fcc54:/# ip a show eth0 -75: eth0@if55: mtu 1500 qdisc noqueue state UNKNOWN group default - link/ether 00:50:56:2b:29:40 brd ff:ff:ff:ff:ff:ff - inet 172.18.0.3/16 scope global eth0 - valid_lft forever preferred_lft forever - inet6 2001:db8:abc4::250:56ff:fe2b:2940/64 scope link tentative dadfailed - valid_lft forever preferred_lft forever - inet6 2001:db8:abc2::2/64 scope link nodad - valid_lft forever preferred_lft forever - -root@b817e42fcc54:/# ping6 2001:db8:abc2::1 -PING 2001:db8:abc2::1 (2001:db8:abc2::1): 56 data bytes -64 bytes from 2001:db8:abc2::1%eth0: icmp_seq=0 ttl=64 time=0.044 ms -64 bytes from 2001:db8:abc2::1%eth0: icmp_seq=1 ttl=64 time=0.058 ms - -2 packets transmitted, 2 packets received, 0% packet loss -round-trip min/avg/max/stddev = 0.044/0.051/0.058/0.000 ms -``` - -The next example with setup a dual stack IPv4/IPv6 network with an example VLAN ID of `140`. - -Next create a network with two IPv4 subnets and one IPv6 subnets, all of which have explicit gateways: - -``` -docker network create -d ipvlan \ - --subnet=192.168.140.0/24 --subnet=192.168.142.0/24 \ - --gateway=192.168.140.1 --gateway=192.168.142.1 \ - --subnet=2001:db8:abc9::/64 --gateway=2001:db8:abc9::22 \ - -o parent=eth0.140 \ - -o ipvlan_mode=l2 ipvlan140 -``` - -Start a container and view eth0 and both v4 & v6 routing tables: - -``` -docker run --net=v6ipvlan139 --ip6=2001:db8:abc2::51 -it --rm alpine /bin/sh - -root@3cce0d3575f3:/# ip a show eth0 -78: eth0@if77: mtu 1500 qdisc noqueue state UNKNOWN group default - link/ether 00:50:56:2b:29:40 brd ff:ff:ff:ff:ff:ff - inet 192.168.140.2/24 scope global eth0 - valid_lft forever preferred_lft forever - inet6 2001:db8:abc4::250:56ff:fe2b:2940/64 scope link - valid_lft forever preferred_lft forever - inet6 2001:db8:abc9::1/64 scope link nodad - valid_lft forever preferred_lft forever - -root@3cce0d3575f3:/# ip route -default via 192.168.140.1 dev eth0 -192.168.140.0/24 dev eth0 proto kernel scope link src 192.168.140.2 - -root@3cce0d3575f3:/# ip -6 route -2001:db8:abc4::/64 dev eth0 proto kernel metric 256 -2001:db8:abc9::/64 dev eth0 proto kernel metric 256 -default via 2001:db8:abc9::22 dev eth0 metric 1024 -``` - -Start a second container with a specific `--ip4` address and ping the first host using IPv4 packets: - -``` -docker run --net=ipvlan140 --ip=192.168.140.10 -it --rm alpine /bin/sh -``` - -**Note**: Different subnets on the same parent interface in Ipvlan `L2` mode cannot ping one another. That requires a router to proxy-arp the requests with a secondary subnet. However, Ipvlan `L3` will route the unicast traffic between disparate subnets as long as they share the same `-o parent` parent link. - -### Dual Stack IPv4 IPv6 Ipvlan L3 Mode - -**Example:** IpVlan L3 Mode Dual Stack IPv4/IPv6, Multi-Subnet w/ 802.1q Vlan Tag:118 - -As in all of the examples, a tagged VLAN interface does not have to be used. The sub-interfaces can be swapped with `eth0`, `eth1`, `bond0` or any other valid interface on the host other then the `lo` loopback. - -The primary difference you will see is that L3 mode does not create a default route with a next-hop but rather sets a default route pointing to `dev eth` only since ARP/Broadcasts/Multicast are all filtered by Linux as per the design. Since the parent interface is essentially acting as a router, the parent interface IP and subnet needs to be different from the container networks. That is the opposite of bridge and L2 modes, which need to be on the same subnet (broadcast domain) in order to forward broadcast and multicast packets. - -``` -# Create an IPv6+IPv4 Dual Stack Ipvlan L3 network -# Gateways for both v4 and v6 are set to a dev e.g. 'default dev eth0' -docker network create -d ipvlan \ - --subnet=192.168.110.0/24 \ - --subnet=192.168.112.0/24 \ - --subnet=2001:db8:abc6::/64 \ - -o parent=eth0 \ - -o ipvlan_mode=l3 ipnet110 - - -# Start a few of containers on the network (ipnet110) -# in separate terminals and check connectivity -docker run --net=ipnet110 -it --rm alpine /bin/sh -# Start a second container specifying the v6 address -docker run --net=ipnet110 --ip6=2001:db8:abc6::10 -it --rm alpine /bin/sh -# Start a third specifying the IPv4 address -docker run --net=ipnet110 --ip=192.168.112.50 -it --rm alpine /bin/sh -# Start a 4th specifying both the IPv4 and IPv6 addresses -docker run --net=ipnet110 --ip6=2001:db8:abc6::50 --ip=192.168.112.50 -it --rm alpine /bin/sh -``` - -Interface and routing table outputs are as follows: - -``` -root@3a368b2a982e:/# ip a show eth0 -63: eth0@if59: mtu 1500 qdisc noqueue state UNKNOWN group default - link/ether 00:50:56:2b:29:40 brd ff:ff:ff:ff:ff:ff - inet 192.168.112.2/24 scope global eth0 - valid_lft forever preferred_lft forever - inet6 2001:db8:abc4::250:56ff:fe2b:2940/64 scope link - valid_lft forever preferred_lft forever - inet6 2001:db8:abc6::10/64 scope link nodad - valid_lft forever preferred_lft forever - -# Note the default route is simply the eth device because ARPs are filtered. -root@3a368b2a982e:/# ip route - default dev eth0 scope link - 192.168.112.0/24 dev eth0 proto kernel scope link src 192.168.112.2 - -root@3a368b2a982e:/# ip -6 route -2001:db8:abc4::/64 dev eth0 proto kernel metric 256 -2001:db8:abc6::/64 dev eth0 proto kernel metric 256 -default dev eth0 metric 1024 -``` - -*Note:* There may be a bug when specifying `--ip6=` addresses when you delete a container with a specified v6 address and then start a new container with the same v6 address it throws the following like the address isn't properly being released to the v6 pool. It will fail to unmount the container and be left dead. - -``` -docker: Error response from daemon: Address already in use. -``` - -### Manually Creating 802.1q Links - -**Vlan ID 40** - -If a user does not want the driver to create the vlan sub-interface it simply needs to exist prior to the `docker network create`. If you have sub-interface naming that is not `interface.vlan_id` it is honored in the `-o parent=` option again as long as the interface exists and us up. - -Links if manually created can be named anything you want. As long as the exist when the network is created that is all that matters. Manually created links do not get deleted regardless of the name when the network is deleted with `docker network rm`. - -``` -# create a new sub-interface tied to dot1q vlan 40 -ip link add link eth0 name eth0.40 type vlan id 40 - -# enable the new sub-interface -ip link set eth0.40 up - -# now add networks and hosts as you would normally by attaching to the master (sub)interface that is tagged -docker network create -d ipvlan \ - --subnet=192.168.40.0/24 \ - --gateway=192.168.40.1 \ - -o parent=eth0.40 ipvlan40 - -# in two separate terminals, start a Docker container and the containers can now ping one another. -docker run --net=ipvlan40 -it --name ivlan_test5 --rm alpine /bin/sh -docker run --net=ipvlan40 -it --name ivlan_test6 --rm alpine /bin/sh -``` - -**Example:** Vlan sub-interface manually created with any name: - -``` -# create a new sub interface tied to dot1q vlan 40 -ip link add link eth0 name foo type vlan id 40 - -# enable the new sub-interface -ip link set foo up - -# now add networks and hosts as you would normally by attaching to the master (sub)interface that is tagged -docker network create -d ipvlan \ - --subnet=192.168.40.0/24 --gateway=192.168.40.1 \ - -o parent=foo ipvlan40 - -# in two separate terminals, start a Docker container and the containers can now ping one another. -docker run --net=ipvlan40 -it --name ivlan_test5 --rm alpine /bin/sh -docker run --net=ipvlan40 -it --name ivlan_test6 --rm alpine /bin/sh -``` - -Manually created links can be cleaned up with: - -``` -ip link del foo -``` - -As with all of the Libnetwork drivers, they can be mixed and matched, even as far as running 3rd party ecosystem drivers in parallel for maximum flexibility to the Docker user. diff --git a/vendor/github.com/docker/docker/hack/Jenkins/W2L/postbuild.sh b/vendor/github.com/docker/docker/hack/Jenkins/W2L/postbuild.sh deleted file mode 100644 index 662e2dc..0000000 --- a/vendor/github.com/docker/docker/hack/Jenkins/W2L/postbuild.sh +++ /dev/null @@ -1,35 +0,0 @@ -set +x -set +e - -echo "" -echo "" -echo "---" -echo "Now starting POST-BUILD steps" -echo "---" -echo "" - -echo INFO: Pointing to $DOCKER_HOST - -if [ ! $(docker ps -aq | wc -l) -eq 0 ]; then - echo INFO: Removing containers... - ! docker rm -vf $(docker ps -aq) -fi - -# Remove all images which don't have docker or debian in the name -if [ ! $(docker images | sed -n '1!p' | grep -v 'docker' | grep -v 'debian' | awk '{ print $3 }' | wc -l) -eq 0 ]; then - echo INFO: Removing images... - ! docker rmi -f $(docker images | sed -n '1!p' | grep -v 'docker' | grep -v 'debian' | awk '{ print $3 }') -fi - -# Kill off any instances of git, go and docker, just in case -! taskkill -F -IM git.exe -T >& /dev/null -! taskkill -F -IM go.exe -T >& /dev/null -! taskkill -F -IM docker.exe -T >& /dev/null - -# Remove everything -! cd /c/jenkins/gopath/src/github.com/docker/docker -! rm -rfd * >& /dev/null -! rm -rfd .* >& /dev/null - -echo INFO: Cleanup complete -exit 0 \ No newline at end of file diff --git a/vendor/github.com/docker/docker/hack/Jenkins/W2L/setup.sh b/vendor/github.com/docker/docker/hack/Jenkins/W2L/setup.sh deleted file mode 100644 index 30e5884..0000000 --- a/vendor/github.com/docker/docker/hack/Jenkins/W2L/setup.sh +++ /dev/null @@ -1,309 +0,0 @@ -# Jenkins CI script for Windows to Linux CI. -# Heavily modified by John Howard (@jhowardmsft) December 2015 to try to make it more reliable. -set +xe -SCRIPT_VER="Wed Apr 20 18:30:19 UTC 2016" - -# TODO to make (even) more resilient: -# - Wait for daemon to be running before executing docker commands -# - Check if jq is installed -# - Make sure bash is v4.3 or later. Can't do until all Azure nodes on the latest version -# - Make sure we are not running as local system. Can't do until all Azure nodes are updated. -# - Error if docker versions are not equal. Can't do until all Azure nodes are updated -# - Error if go versions are not equal. Can't do until all Azure nodes are updated. -# - Error if running 32-bit posix tools. Probably can take from bash --version and check contains "x86_64" -# - Warn if the CI directory cannot be deleted afterwards. Otherwise turdlets are left behind -# - Use %systemdrive% ($SYSTEMDRIVE) rather than hard code to c: for TEMP -# - Consider cross builing the Windows binary and copy across. That's a bit of a heavy lift. Only reason -# for doing that is that it mirrors the actual release process for docker.exe which is cross-built. -# However, should absolutely not be a problem if built natively, so nit-picking. -# - Tidy up of images and containers. Either here, or in the teardown script. - -ec=0 -uniques=1 -echo INFO: Started at `date`. Script version $SCRIPT_VER - - -# !README! -# There are two daemons running on the remote Linux host: -# - outer: specified by DOCKER_HOST, this is the daemon that will build and run the inner docker daemon -# from the sources matching the PR. -# - inner: runs on the host network, on a port number similar to that of DOCKER_HOST but the last two digits are inverted -# (2357 if DOCKER_HOST had port 2375; and 2367 if DOCKER_HOST had port 2376). -# The windows integration tests are run against this inner daemon. - -# get the ip, inner and outer ports. -ip="${DOCKER_HOST#*://}" -port_outer="${ip#*:}" -# inner port is like outer port with last two digits inverted. -port_inner=$(echo "$port_outer" | sed -E 's/(.)(.)$/\2\1/') -ip="${ip%%:*}" - -echo "INFO: IP=$ip PORT_OUTER=$port_outer PORT_INNER=$port_inner" - -# If TLS is enabled -if [ -n "$DOCKER_TLS_VERIFY" ]; then - protocol=https - if [ -z "$DOCKER_MACHINE_NAME" ]; then - ec=1 - echo "ERROR: DOCKER_MACHINE_NAME is undefined" - fi - certs=$(echo ~/.docker/machine/machines/$DOCKER_MACHINE_NAME) - curlopts="--cacert $certs/ca.pem --cert $certs/cert.pem --key $certs/key.pem" - run_extra_args="-v tlscerts:/etc/docker" - daemon_extra_args="--tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem" -else - protocol=http -fi - -# Save for use by make.sh and scripts it invokes -export MAIN_DOCKER_HOST="tcp://$ip:$port_inner" - -# Verify we can get the remote node to respond to _ping -if [ $ec -eq 0 ]; then - reply=`curl -s $curlopts $protocol://$ip:$port_outer/_ping` - if [ "$reply" != "OK" ]; then - ec=1 - echo "ERROR: Failed to get an 'OK' response from the docker daemon on the Linux node" - echo " at $ip:$port_outer when called with an http request for '_ping'. This implies that" - echo " either the daemon has crashed/is not running, or the Linux node is unavailable." - echo - echo " A regular ping to the remote Linux node is below. It should reply. If not, the" - echo " machine cannot be reached at all and may have crashed. If it does reply, it is" - echo " likely a case of the Linux daemon not running or having crashed, which requires" - echo " further investigation." - echo - echo " Try re-running this CI job, or ask on #docker-dev or #docker-maintainers" - echo " for someone to perform further diagnostics, or take this node out of rotation." - echo - ping $ip - else - echo "INFO: The Linux nodes outer daemon replied to a ping. Good!" - fi -fi - -# Get the version from the remote node. Note this may fail if jq is not installed. -# That's probably worth checking to make sure, just in case. -if [ $ec -eq 0 ]; then - remoteVersion=`curl -s $curlopts $protocol://$ip:$port_outer/version | jq -c '.Version'` - echo "INFO: Remote daemon is running docker version $remoteVersion" -fi - -# Compare versions. We should really fail if result is no 1. Output at end of script. -if [ $ec -eq 0 ]; then - uniques=`docker version | grep Version | /usr/bin/sort -u | wc -l` -fi - -# Make sure we are in repo -if [ $ec -eq 0 ]; then - if [ ! -d hack ]; then - echo "ERROR: Are you sure this is being launched from a the root of docker repository?" - echo " If this is a Windows CI machine, it should be c:\jenkins\gopath\src\github.com\docker\docker." - echo " Current directory is `pwd`" - ec=1 - fi -fi - -# Are we in split binary mode? -if [ `grep DOCKER_CLIENTONLY Makefile | wc -l` -gt 0 ]; then - splitBinary=0 - echo "INFO: Running in single binary mode" -else - splitBinary=1 - echo "INFO: Running in split binary mode" -fi - - -# Get the commit has and verify we have something -if [ $ec -eq 0 ]; then - export COMMITHASH=$(git rev-parse --short HEAD) - echo INFO: Commmit hash is $COMMITHASH - if [ -z $COMMITHASH ]; then - echo "ERROR: Failed to get commit hash. Are you sure this is a docker repository?" - ec=1 - fi -fi - -# Redirect to a temporary location. Check is here for local runs from Jenkins machines just in case not -# in the right directory where the repo is cloned. We also redirect TEMP to not use the environment -# TEMP as when running as a standard user (not local system), it otherwise exposes a bug in posix tar which -# will cause CI to fail from Windows to Linux. Obviously it's not best practice to ever run as local system... -if [ $ec -eq 0 ]; then - export TEMP=/c/CI/CI-$COMMITHASH - export TMP=$TEMP - /usr/bin/mkdir -p $TEMP # Make sure Linux mkdir for -p -fi - -# Tidy up time -if [ $ec -eq 0 ]; then - echo INFO: Deleting pre-existing containers and images... - - # Force remove all containers based on a previously built image with this commit - ! docker rm -f $(docker ps -aq --filter "ancestor=docker:$COMMITHASH") &>/dev/null - - # Force remove any container with this commithash as a name - ! docker rm -f $(docker ps -aq --filter "name=docker-$COMMITHASH") &>/dev/null - - # This SHOULD never happen, but just in case, also blow away any containers - # that might be around. - ! if [ ! $(docker ps -aq | wc -l) -eq 0 ]; then - echo WARN: There were some leftover containers. Cleaning them up. - ! docker rm -f $(docker ps -aq) - fi - - # Force remove the image if it exists - ! docker rmi -f "docker-$COMMITHASH" &>/dev/null -fi - -# Provide the docker version for debugging purposes. If these fail, game over. -# as the Linux box isn't responding for some reason. -if [ $ec -eq 0 ]; then - echo INFO: Docker version and info of the outer daemon on the Linux node - echo - docker version - ec=$? - if [ 0 -ne $ec ]; then - echo "ERROR: The main linux daemon does not appear to be running. Has the Linux node crashed?" - fi - echo -fi - -# Same as above, but docker info -if [ $ec -eq 0 ]; then - echo - docker info - ec=$? - if [ 0 -ne $ec ]; then - echo "ERROR: The main linux daemon does not appear to be running. Has the Linux node crashed?" - fi - echo -fi - -# build the daemon image -if [ $ec -eq 0 ]; then - echo "INFO: Running docker build on Linux host at $DOCKER_HOST" - if [ $splitBinary -eq 0 ]; then - set -x - docker build --rm --force-rm --build-arg APT_MIRROR=cdn-fastly.deb.debian.org -t "docker:$COMMITHASH" . - cat < -# See the blog post: https://blog.docker.com/2013/09/docker-can-now-run-within-docker/ -# -# This script should be executed inside a docker container in privileged mode -# ('docker run --privileged', introduced in docker 0.6). - -# Usage: dind CMD [ARG...] - -# apparmor sucks and Docker needs to know that it's in a container (c) @tianon -export container=docker - -if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then - mount -t securityfs none /sys/kernel/security || { - echo >&2 'Could not mount /sys/kernel/security.' - echo >&2 'AppArmor detection and --privileged mode might break.' - } -fi - -# Mount /tmp (conditionally) -if ! mountpoint -q /tmp; then - mount -t tmpfs none /tmp -fi - -if [ $# -gt 0 ]; then - exec "$@" -fi - -echo >&2 'ERROR: No command specified.' -echo >&2 'You probably want to run hack/make.sh, or maybe a shell?' diff --git a/vendor/github.com/docker/docker/hack/dockerfile/binaries-commits b/vendor/github.com/docker/docker/hack/dockerfile/binaries-commits deleted file mode 100755 index 8dfcca3..0000000 --- a/vendor/github.com/docker/docker/hack/dockerfile/binaries-commits +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -TOMLV_COMMIT=9baf8a8a9f2ed20a8e54160840c492f937eeaf9a - -# When updating RUNC_COMMIT, also update runc in vendor.conf accordingly -RUNC_COMMIT=9df8b306d01f59d3a8029be411de015b7304dd8f -CONTAINERD_COMMIT=aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1 -TINI_COMMIT=949e6facb77383876aeff8a6944dde66b3089574 -LIBNETWORK_COMMIT=0f534354b813003a754606689722fe253101bc4e -VNDR_COMMIT=f56bd4504b4fad07a357913687fb652ee54bb3b0 -BINDATA_COMMIT=a0ff2567cfb70903282db057e799fd826784d41d diff --git a/vendor/github.com/docker/docker/hack/dockerfile/install-binaries.sh b/vendor/github.com/docker/docker/hack/dockerfile/install-binaries.sh deleted file mode 100755 index 64f2b57..0000000 --- a/vendor/github.com/docker/docker/hack/dockerfile/install-binaries.sh +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/sh -set -e -set -x - -. $(dirname "$0")/binaries-commits - -RM_GOPATH=0 - -TMP_GOPATH=${TMP_GOPATH:-""} - -if [ -z "$TMP_GOPATH" ]; then - export GOPATH="$(mktemp -d)" - RM_GOPATH=1 -else - export GOPATH="$TMP_GOPATH" -fi - -# Do not build with ambient capabilities support -RUNC_BUILDTAGS="${RUNC_BUILDTAGS:-"seccomp apparmor selinux"}" - -install_runc() { - echo "Install runc version $RUNC_COMMIT" - git clone https://github.com/docker/runc.git "$GOPATH/src/github.com/opencontainers/runc" - cd "$GOPATH/src/github.com/opencontainers/runc" - git checkout -q "$RUNC_COMMIT" - make BUILDTAGS="$RUNC_BUILDTAGS" $1 - cp runc /usr/local/bin/docker-runc -} - -install_containerd() { - echo "Install containerd version $CONTAINERD_COMMIT" - git clone https://github.com/docker/containerd.git "$GOPATH/src/github.com/docker/containerd" - cd "$GOPATH/src/github.com/docker/containerd" - git checkout -q "$CONTAINERD_COMMIT" - make $1 - cp bin/containerd /usr/local/bin/docker-containerd - cp bin/containerd-shim /usr/local/bin/docker-containerd-shim - cp bin/ctr /usr/local/bin/docker-containerd-ctr -} - -install_proxy() { - echo "Install docker-proxy version $LIBNETWORK_COMMIT" - git clone https://github.com/docker/libnetwork.git "$GOPATH/src/github.com/docker/libnetwork" - cd "$GOPATH/src/github.com/docker/libnetwork" - git checkout -q "$LIBNETWORK_COMMIT" - go build -ldflags="$PROXY_LDFLAGS" -o /usr/local/bin/docker-proxy github.com/docker/libnetwork/cmd/proxy -} - -install_bindata() { - echo "Install go-bindata version $BINDATA_COMMIT" - git clone https://github.com/jteeuwen/go-bindata "$GOPATH/src/github.com/jteeuwen/go-bindata" - cd $GOPATH/src/github.com/jteeuwen/go-bindata - git checkout -q "$BINDATA_COMMIT" - go build -o /usr/local/bin/go-bindata github.com/jteeuwen/go-bindata/go-bindata -} - -for prog in "$@" -do - case $prog in - tomlv) - echo "Install tomlv version $TOMLV_COMMIT" - git clone https://github.com/BurntSushi/toml.git "$GOPATH/src/github.com/BurntSushi/toml" - cd "$GOPATH/src/github.com/BurntSushi/toml" && git checkout -q "$TOMLV_COMMIT" - go build -v -o /usr/local/bin/tomlv github.com/BurntSushi/toml/cmd/tomlv - ;; - - runc) - install_runc static - ;; - - runc-dynamic) - install_runc - ;; - - containerd) - install_containerd static - ;; - - containerd-dynamic) - install_containerd - ;; - - tini) - echo "Install tini version $TINI_COMMIT" - git clone https://github.com/krallin/tini.git "$GOPATH/tini" - cd "$GOPATH/tini" - git checkout -q "$TINI_COMMIT" - cmake . - make tini-static - cp tini-static /usr/local/bin/docker-init - ;; - - proxy) - export CGO_ENABLED=0 - install_proxy - ;; - - proxy-dynamic) - PROXY_LDFLAGS="-linkmode=external" install_proxy - ;; - - vndr) - echo "Install vndr version $VNDR_COMMIT" - git clone https://github.com/LK4D4/vndr.git "$GOPATH/src/github.com/LK4D4/vndr" - cd "$GOPATH/src/github.com/LK4D4/vndr" - git checkout -q "$VNDR_COMMIT" - go build -v -o /usr/local/bin/vndr . - ;; - - bindata) - install_bindata - ;; - - *) - echo echo "Usage: $0 [tomlv|runc|containerd|tini|proxy]" - exit 1 - - esac -done - -if [ $RM_GOPATH -eq 1 ]; then - rm -rf "$GOPATH" -fi diff --git a/vendor/github.com/docker/docker/hack/generate-authors.sh b/vendor/github.com/docker/docker/hack/generate-authors.sh deleted file mode 100755 index e78a97f..0000000 --- a/vendor/github.com/docker/docker/hack/generate-authors.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -e - -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")/.." - -# see also ".mailmap" for how email addresses and names are deduplicated - -{ - cat <<-'EOH' - # This file lists all individuals having contributed content to the repository. - # For how it is generated, see `hack/generate-authors.sh`. - EOH - echo - git log --format='%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf -} > AUTHORS diff --git a/vendor/github.com/docker/docker/hack/generate-swagger-api.sh b/vendor/github.com/docker/docker/hack/generate-swagger-api.sh deleted file mode 100755 index a8e9f81..0000000 --- a/vendor/github.com/docker/docker/hack/generate-swagger-api.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -set -eu - -swagger generate model -f api/swagger.yaml \ - -t api -m types --skip-validator -C api/swagger-gen.yaml \ - -n Volume \ - -n Port \ - -n ImageSummary \ - -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \ - -n ErrorResponse \ - -n IdResponse \ - -n ServiceUpdateResponse - -swagger generate operation -f api/swagger.yaml \ - -t api -a types -m types -C api/swagger-gen.yaml \ - -T api/templates --skip-responses --skip-parameters --skip-validator \ - -n VolumesList \ - -n VolumesCreate \ - -n ContainerCreate \ - -n ContainerUpdate \ - -n Authenticate \ - -n ContainerWait diff --git a/vendor/github.com/docker/docker/hack/install.sh b/vendor/github.com/docker/docker/hack/install.sh deleted file mode 100644 index cc20d69..0000000 --- a/vendor/github.com/docker/docker/hack/install.sh +++ /dev/null @@ -1,484 +0,0 @@ -#!/bin/sh -set -e -# -# This script is meant for quick & easy install via: -# 'curl -sSL https://get.docker.com/ | sh' -# or: -# 'wget -qO- https://get.docker.com/ | sh' -# -# For test builds (ie. release candidates): -# 'curl -fsSL https://test.docker.com/ | sh' -# or: -# 'wget -qO- https://test.docker.com/ | sh' -# -# For experimental builds: -# 'curl -fsSL https://experimental.docker.com/ | sh' -# or: -# 'wget -qO- https://experimental.docker.com/ | sh' -# -# Docker Maintainers: -# To update this script on https://get.docker.com, -# use hack/release.sh during a normal release, -# or the following one-liner for script hotfixes: -# aws s3 cp --acl public-read hack/install.sh s3://get.docker.com/index -# - -url="https://get.docker.com/" -apt_url="https://apt.dockerproject.org" -yum_url="https://yum.dockerproject.org" -gpg_fingerprint="58118E89F3A912897C070ADBF76221572C52609D" - -key_servers=" -ha.pool.sks-keyservers.net -pgp.mit.edu -keyserver.ubuntu.com -" - -mirror='' -while [ $# -gt 0 ]; do - case "$1" in - --mirror) - mirror="$2" - shift - ;; - *) - echo "Illegal option $1" - ;; - esac - shift $(( $# > 0 ? 1 : 0 )) -done - -case "$mirror" in - AzureChinaCloud) - apt_url="https://mirror.azure.cn/docker-engine/apt" - yum_url="https://mirror.azure.cn/docker-engine/yum" - ;; -esac - -command_exists() { - command -v "$@" > /dev/null 2>&1 -} - -echo_docker_as_nonroot() { - if command_exists docker && [ -e /var/run/docker.sock ]; then - ( - set -x - $sh_c 'docker version' - ) || true - fi - your_user=your-user - [ "$user" != 'root' ] && your_user="$user" - # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output - cat <<-EOF - - If you would like to use Docker as a non-root user, you should now consider - adding your user to the "docker" group with something like: - - sudo usermod -aG docker $your_user - - Remember that you will have to log out and back in for this to take effect! - - EOF -} - -# Check if this is a forked Linux distro -check_forked() { - - # Check for lsb_release command existence, it usually exists in forked distros - if command_exists lsb_release; then - # Check if the `-u` option is supported - set +e - lsb_release -a -u > /dev/null 2>&1 - lsb_release_exit_code=$? - set -e - - # Check if the command has exited successfully, it means we're in a forked distro - if [ "$lsb_release_exit_code" = "0" ]; then - # Print info about current distro - cat <<-EOF - You're using '$lsb_dist' version '$dist_version'. - EOF - - # Get the upstream release info - lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]') - dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]') - - # Print info about upstream distro - cat <<-EOF - Upstream release is '$lsb_dist' version '$dist_version'. - EOF - else - if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then - # We're Debian and don't even know it! - lsb_dist=debian - dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')" - case "$dist_version" in - 9) - dist_version="stretch" - ;; - 8|'Kali Linux 2') - dist_version="jessie" - ;; - 7) - dist_version="wheezy" - ;; - esac - fi - fi - fi -} - -rpm_import_repository_key() { - local key=$1; shift - local tmpdir=$(mktemp -d) - chmod 600 "$tmpdir" - for key_server in $key_servers ; do - gpg --homedir "$tmpdir" --keyserver "$key_server" --recv-keys "$key" && break - done - gpg --homedir "$tmpdir" -k "$key" >/dev/null - gpg --homedir "$tmpdir" --export --armor "$key" > "$tmpdir"/repo.key - rpm --import "$tmpdir"/repo.key - rm -rf "$tmpdir" -} - -semverParse() { - major="${1%%.*}" - minor="${1#$major.}" - minor="${minor%%.*}" - patch="${1#$major.$minor.}" - patch="${patch%%[-.]*}" -} - -do_install() { - architecture=$(uname -m) - case $architecture in - # officially supported - amd64|x86_64) - ;; - # unofficially supported with available repositories - armv6l|armv7l) - ;; - # unofficially supported without available repositories - aarch64|arm64|ppc64le|s390x) - cat 1>&2 <<-EOF - Error: Docker doesn't officially support $architecture and no Docker $architecture repository exists. - EOF - exit 1 - ;; - # not supported - *) - cat >&2 <<-EOF - Error: $architecture is not a recognized platform. - EOF - exit 1 - ;; - esac - - if command_exists docker; then - version="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)" - MAJOR_W=1 - MINOR_W=10 - - semverParse $version - - shouldWarn=0 - if [ $major -lt $MAJOR_W ]; then - shouldWarn=1 - fi - - if [ $major -le $MAJOR_W ] && [ $minor -lt $MINOR_W ]; then - shouldWarn=1 - fi - - cat >&2 <<-'EOF' - Warning: the "docker" command appears to already exist on this system. - - If you already have Docker installed, this script can cause trouble, which is - why we're displaying this warning and provide the opportunity to cancel the - installation. - - If you installed the current Docker package using this script and are using it - EOF - - if [ $shouldWarn -eq 1 ]; then - cat >&2 <<-'EOF' - again to update Docker, we urge you to migrate your image store before upgrading - to v1.10+. - - You can find instructions for this here: - https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration - EOF - else - cat >&2 <<-'EOF' - again to update Docker, you can safely ignore this message. - EOF - fi - - cat >&2 <<-'EOF' - - You may press Ctrl+C now to abort this script. - EOF - ( set -x; sleep 20 ) - fi - - user="$(id -un 2>/dev/null || true)" - - sh_c='sh -c' - if [ "$user" != 'root' ]; then - if command_exists sudo; then - sh_c='sudo -E sh -c' - elif command_exists su; then - sh_c='su -c' - else - cat >&2 <<-'EOF' - Error: this installer needs the ability to run commands as root. - We are unable to find either "sudo" or "su" available to make this happen. - EOF - exit 1 - fi - fi - - curl='' - if command_exists curl; then - curl='curl -sSL' - elif command_exists wget; then - curl='wget -qO-' - elif command_exists busybox && busybox --list-modules | grep -q wget; then - curl='busybox wget -qO-' - fi - - # check to see which repo they are trying to install from - if [ -z "$repo" ]; then - repo='main' - if [ "https://test.docker.com/" = "$url" ]; then - repo='testing' - elif [ "https://experimental.docker.com/" = "$url" ]; then - repo='experimental' - fi - fi - - # perform some very rudimentary platform detection - lsb_dist='' - dist_version='' - if command_exists lsb_release; then - lsb_dist="$(lsb_release -si)" - fi - if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then - lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")" - fi - if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then - lsb_dist='debian' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then - lsb_dist='fedora' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then - lsb_dist='oracleserver' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/centos-release ]; then - lsb_dist='centos' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/redhat-release ]; then - lsb_dist='redhat' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/photon-release ]; then - lsb_dist='photon' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then - lsb_dist="$(. /etc/os-release && echo "$ID")" - fi - - lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" - - # Special case redhatenterpriseserver - if [ "${lsb_dist}" = "redhatenterpriseserver" ]; then - # Set it to redhat, it will be changed to centos below anyways - lsb_dist='redhat' - fi - - case "$lsb_dist" in - - ubuntu) - if command_exists lsb_release; then - dist_version="$(lsb_release --codename | cut -f2)" - fi - if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then - dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")" - fi - ;; - - debian|raspbian) - dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')" - case "$dist_version" in - 8) - dist_version="jessie" - ;; - 7) - dist_version="wheezy" - ;; - esac - ;; - - oracleserver) - # need to switch lsb_dist to match yum repo URL - lsb_dist="oraclelinux" - dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" - ;; - - fedora|centos|redhat) - dist_version="$(rpm -q --whatprovides ${lsb_dist}-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//' | sort | tail -1)" - ;; - - "vmware photon") - lsb_dist="photon" - dist_version="$(. /etc/os-release && echo "$VERSION_ID")" - ;; - - *) - if command_exists lsb_release; then - dist_version="$(lsb_release --codename | cut -f2)" - fi - if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then - dist_version="$(. /etc/os-release && echo "$VERSION_ID")" - fi - ;; - - - esac - - # Check if this is a forked Linux distro - check_forked - - # Run setup for each distro accordingly - case "$lsb_dist" in - ubuntu|debian|raspbian) - export DEBIAN_FRONTEND=noninteractive - - did_apt_get_update= - apt_get_update() { - if [ -z "$did_apt_get_update" ]; then - ( set -x; $sh_c 'sleep 3; apt-get update' ) - did_apt_get_update=1 - fi - } - - if [ "$lsb_dist" != "raspbian" ]; then - # aufs is preferred over devicemapper; try to ensure the driver is available. - if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then - if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -qE '^ii|^hi' 2>/dev/null; then - kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual" - - apt_get_update - ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true - - if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then - echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)' - echo >&2 ' but we still have no AUFS. Docker may not work. Proceeding anyways!' - ( set -x; sleep 10 ) - fi - else - echo >&2 'Warning: current kernel is not supported by the linux-image-extra-virtual' - echo >&2 ' package. We have no AUFS support. Consider installing the packages' - echo >&2 ' linux-image-virtual kernel and linux-image-extra-virtual for AUFS support.' - ( set -x; sleep 10 ) - fi - fi - fi - - # install apparmor utils if they're missing and apparmor is enabled in the kernel - # otherwise Docker will fail to start - if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then - if command -v apparmor_parser >/dev/null 2>&1; then - echo 'apparmor is enabled in the kernel and apparmor utils were already installed' - else - echo 'apparmor is enabled in the kernel, but apparmor_parser is missing. Trying to install it..' - apt_get_update - ( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' ) - fi - fi - - if [ ! -e /usr/lib/apt/methods/https ]; then - apt_get_update - ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' ) - fi - if [ -z "$curl" ]; then - apt_get_update - ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' ) - curl='curl -sSL' - fi - if ! command -v gpg > /dev/null; then - apt_get_update - ( set -x; $sh_c 'sleep 3; apt-get install -y -q gnupg2 || apt-get install -y -q gnupg' ) - fi - - # dirmngr is a separate package in ubuntu yakkety; see https://bugs.launchpad.net/ubuntu/+source/apt/+bug/1634464 - if ! command -v dirmngr > /dev/null; then - apt_get_update - ( set -x; $sh_c 'sleep 3; apt-get install -y -q dirmngr' ) - fi - - ( - set -x - for key_server in $key_servers ; do - $sh_c "apt-key adv --keyserver hkp://${key_server}:80 --recv-keys ${gpg_fingerprint}" && break - done - $sh_c "apt-key adv -k ${gpg_fingerprint} >/dev/null" - $sh_c "mkdir -p /etc/apt/sources.list.d" - $sh_c "echo deb \[arch=$(dpkg --print-architecture)\] ${apt_url}/repo ${lsb_dist}-${dist_version} ${repo} > /etc/apt/sources.list.d/docker.list" - $sh_c 'sleep 3; apt-get update; apt-get install -y -q docker-engine' - ) - echo_docker_as_nonroot - exit 0 - ;; - - fedora|centos|redhat|oraclelinux|photon) - if [ "${lsb_dist}" = "redhat" ]; then - # we use the centos repository for both redhat and centos releases - lsb_dist='centos' - fi - $sh_c "cat >/etc/yum.repos.d/docker-${repo}.repo" <<-EOF - [docker-${repo}-repo] - name=Docker ${repo} Repository - baseurl=${yum_url}/repo/${repo}/${lsb_dist}/${dist_version} - enabled=1 - gpgcheck=1 - gpgkey=${yum_url}/gpg - EOF - if [ "$lsb_dist" = "fedora" ] && [ "$dist_version" -ge "22" ]; then - ( - set -x - $sh_c 'sleep 3; dnf -y -q install docker-engine' - ) - elif [ "$lsb_dist" = "photon" ]; then - ( - set -x - $sh_c 'sleep 3; tdnf -y install docker-engine' - ) - else - ( - set -x - $sh_c 'sleep 3; yum -y -q install docker-engine' - ) - fi - echo_docker_as_nonroot - exit 0 - ;; - esac - - # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output - cat >&2 <<-'EOF' - - Either your platform is not easily detectable, is not supported by this - installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have - a package for Docker. Please visit the following URL for more detailed - installation instructions: - - https://docs.docker.com/engine/installation/ - - EOF - exit 1 -} - -# wrapped up in a function so that we have some protection against only getting -# half the file during "curl | sh" -do_install diff --git a/vendor/github.com/docker/docker/hack/make.ps1 b/vendor/github.com/docker/docker/hack/make.ps1 deleted file mode 100644 index 14b9603..0000000 --- a/vendor/github.com/docker/docker/hack/make.ps1 +++ /dev/null @@ -1,408 +0,0 @@ -<# -.NOTES - Author: @jhowardmsft - - Summary: Windows native build script. This is similar to functionality provided - by hack\make.sh, but uses native Windows PowerShell semantics. It does - not support the full set of options provided by the Linux counterpart. - For example: - - - You can't cross-build Linux docker binaries on Windows - - Hashes aren't generated on binaries - - 'Releasing' isn't supported. - - Integration tests. This is because they currently cannot run inside a container, - and require significant external setup. - - It does however provided the minimum necessary to support parts of local Windows - development and Windows to Windows CI. - - Usage Examples (run from repo root): - "hack\make.ps1 -Binary" to build the binaries - "hack\make.ps1 -Client" to build just the client 64-bit binary - "hack\make.ps1 -TestUnit" to run unit tests - "hack\make.ps1 -Binary -TestUnit" to build the binaries and run unit tests - "hack\make.ps1 -All" to run everything this script knows about - -.PARAMETER Client - Builds the client binaries. - -.PARAMETER Daemon - Builds the daemon binary. - -.PARAMETER Binary - Builds the client binaries and the daemon binary. A convenient shortcut to `make.ps1 -Client -Daemon`. - -.PARAMETER Race - Use -race in go build and go test. - -.PARAMETER Noisy - Use -v in go build. - -.PARAMETER ForceBuildAll - Use -a in go build. - -.PARAMETER NoOpt - Use -gcflags -N -l in go build to disable optimisation (can aide debugging). - -.PARAMETER CommitSuffix - Adds a custom string to be appended to the commit ID (spaces are stripped). - -.PARAMETER DCO - Runs the DCO (Developer Certificate Of Origin) test. - -.PARAMETER PkgImports - Runs the pkg\ directory imports test. - -.PARAMETER GoFormat - Runs the Go formatting test. - -.PARAMETER TestUnit - Runs unit tests. - -.PARAMETER All - Runs everything this script knows about. - - -TODO -- Unify the head commit -- Sort out the GITCOMMIT environment variable in the absense of a .git (longer term) -- Add golint and other checks (swagger maybe?) - -#> - - -param( - [Parameter(Mandatory=$False)][switch]$Client, - [Parameter(Mandatory=$False)][switch]$Daemon, - [Parameter(Mandatory=$False)][switch]$Binary, - [Parameter(Mandatory=$False)][switch]$Race, - [Parameter(Mandatory=$False)][switch]$Noisy, - [Parameter(Mandatory=$False)][switch]$ForceBuildAll, - [Parameter(Mandatory=$False)][switch]$NoOpt, - [Parameter(Mandatory=$False)][string]$CommitSuffix="", - [Parameter(Mandatory=$False)][switch]$DCO, - [Parameter(Mandatory=$False)][switch]$PkgImports, - [Parameter(Mandatory=$False)][switch]$GoFormat, - [Parameter(Mandatory=$False)][switch]$TestUnit, - [Parameter(Mandatory=$False)][switch]$All -) - -$ErrorActionPreference = "Stop" -$pushed=$False # To restore the directory if we have temporarily pushed to one. - -# Utility function to get the commit ID of the repository -Function Get-GitCommit() { - if (-not (Test-Path ".\.git")) { - # If we don't have a .git directory, but we do have the environment - # variable DOCKER_GITCOMMIT set, that can override it. - if ($env:DOCKER_GITCOMMIT.Length -eq 0) { - Throw ".git directory missing and DOCKER_GITCOMMIT environment variable not specified." - } - Write-Host "INFO: Git commit assumed from DOCKER_GITCOMMIT environment variable" - return $env:DOCKER_GITCOMMIT - } - $gitCommit=$(git rev-parse --short HEAD) - if ($(git status --porcelain --untracked-files=no).Length -ne 0) { - $gitCommit="$gitCommit-unsupported" - Write-Host "" - Write-Warning "This version is unsupported because there are uncommitted file(s)." - Write-Warning "Either commit these changes, or add them to .gitignore." - git status --porcelain --untracked-files=no | Write-Warning - Write-Host "" - } - return $gitCommit -} - -# Utility function to get get the current build version of docker -Function Get-DockerVersion() { - if (-not (Test-Path ".\VERSION")) { Throw "VERSION file not found. Is this running from the root of a docker repository?" } - return $(Get-Content ".\VERSION" -raw).ToString().Replace("`n","").Trim() -} - -# Utility function to determine if we are running in a container or not. -# In Windows, we get this through an environment variable set in `Dockerfile.Windows` -Function Check-InContainer() { - if ($env:FROM_DOCKERFILE.Length -eq 0) { - Write-Host "" - Write-Warning "Not running in a container. The result might be an incorrect build." - Write-Host "" - } -} - -# Utility function to get the commit for HEAD -Function Get-HeadCommit() { - $head = Invoke-Expression "git rev-parse --verify HEAD" - if ($LASTEXITCODE -ne 0) { Throw "Failed getting HEAD commit" } - - return $head -} - -# Utility function to get the commit for upstream -Function Get-UpstreamCommit() { - Invoke-Expression "git fetch -q https://github.com/docker/docker.git refs/heads/master" - if ($LASTEXITCODE -ne 0) { Throw "Failed fetching" } - - $upstream = Invoke-Expression "git rev-parse --verify FETCH_HEAD" - if ($LASTEXITCODE -ne 0) { Throw "Failed getting upstream commit" } - - return $upstream -} - -# Build a binary (client or daemon) -Function Execute-Build($type, $additionalBuildTags, $directory) { - # Generate the build flags - $buildTags = "autogen" - if ($Noisy) { $verboseParm=" -v" } - if ($Race) { Write-Warning "Using race detector"; $raceParm=" -race"} - if ($ForceBuildAll) { $allParm=" -a" } - if ($NoOpt) { $optParm=" -gcflags "+""""+"-N -l"+"""" } - if ($addtionalBuildTags -ne "") { $buildTags += $(" " + $additionalBuildTags) } - - # Do the go build in the appropriate directory - # Note -linkmode=internal is required to be able to debug on Windows. - # https://github.com/golang/go/issues/14319#issuecomment-189576638 - Write-Host "INFO: Building $type..." - Push-Location $root\cmd\$directory; $global:pushed=$True - $buildCommand = "go build" + ` - $raceParm + ` - $verboseParm + ` - $allParm + ` - $optParm + ` - " -tags """ + $buildTags + """" + ` - " -ldflags """ + "-linkmode=internal" + """" + ` - " -o $root\bundles\"+$directory+".exe" - Invoke-Expression $buildCommand - if ($LASTEXITCODE -ne 0) { Throw "Failed to compile $type" } - Pop-Location; $global:pushed=$False -} - - -# Validates the DCO marker is present on each commit -Function Validate-DCO($headCommit, $upstreamCommit) { - Write-Host "INFO: Validating Developer Certificate of Origin..." - # Username may only contain alphanumeric characters or dashes and cannot begin with a dash - $usernameRegex='[a-zA-Z0-9][a-zA-Z0-9-]+' - - $dcoPrefix="Signed-off-by:" - $dcoRegex="^(Docker-DCO-1.1-)?$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)>( \\(github: ($usernameRegex)\\))?$" - - $counts = Invoke-Expression "git diff --numstat $upstreamCommit...$headCommit" - if ($LASTEXITCODE -ne 0) { Throw "Failed git diff --numstat" } - - # Counts of adds and deletes after removing multiple white spaces. AWK anyone? :( - $adds=0; $dels=0; $($counts -replace '\s+', ' ') | %{ - $a=$_.Split(" "); - if ($a[0] -ne "-") { $adds+=[int]$a[0] } - if ($a[1] -ne "-") { $dels+=[int]$a[1] } - } - if (($adds -eq 0) -and ($dels -eq 0)) { - Write-Warning "DCO validation - nothing to validate!" - return - } - - $commits = Invoke-Expression "git log $upstreamCommit..$headCommit --format=format:%H%n" - if ($LASTEXITCODE -ne 0) { Throw "Failed git log --format" } - $commits = $($commits -split '\s+' -match '\S') - $badCommits=@() - $commits | %{ - # Skip commits with no content such as merge commits etc - if ($(git log -1 --format=format: --name-status $_).Length -gt 0) { - # Ignore exit code on next call - always process regardless - $commitMessage = Invoke-Expression "git log -1 --format=format:%B --name-status $_" - if (($commitMessage -match $dcoRegex).Length -eq 0) { $badCommits+=$_ } - } - } - if ($badCommits.Length -eq 0) { - Write-Host "Congratulations! All commits are properly signed with the DCO!" - } else { - $e = "`nThese commits do not have a proper '$dcoPrefix' marker:`n" - $badCommits | %{ $e+=" - $_`n"} - $e += "`nPlease amend each commit to include a properly formatted DCO marker.`n`n" - $e += "Visit the following URL for information about the Docker DCO:`n" - $e += "https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work`n" - Throw $e - } -} - -# Validates that .\pkg\... is safely isolated from internal code -Function Validate-PkgImports($headCommit, $upstreamCommit) { - Write-Host "INFO: Validating pkg import isolation..." - - # Get a list of go source-code files which have changed under pkg\. Ignore exit code on next call - always process regardless - $files=@(); $files = Invoke-Expression "git diff $upstreamCommit...$headCommit --diff-filter=ACMR --name-only -- `'pkg\*.go`'" - $badFiles=@(); $files | %{ - $file=$_ - # For the current changed file, get its list of dependencies, sorted and uniqued. - $imports = Invoke-Expression "go list -e -f `'{{ .Deps }}`' $file" - if ($LASTEXITCODE -ne 0) { Throw "Failed go list for dependencies on $file" } - $imports = $imports -Replace "\[" -Replace "\]", "" -Split(" ") | Sort-Object | Get-Unique - # Filter out what we are looking for - $imports = $imports -NotMatch "^github.com/docker/docker/pkg/" ` - -NotMatch "^github.com/docker/docker/vendor" ` - -Match "^github.com/docker/docker" ` - -Replace "`n", "" - $imports | % { $badFiles+="$file imports $_`n" } - } - if ($badFiles.Length -eq 0) { - Write-Host 'Congratulations! ".\pkg\*.go" is safely isolated from internal code.' - } else { - $e = "`nThese files import internal code: (either directly or indirectly)`n" - $badFiles | %{ $e+=" - $_"} - Throw $e - } -} - -# Validates that changed files are correctly go-formatted -Function Validate-GoFormat($headCommit, $upstreamCommit) { - Write-Host "INFO: Validating go formatting on changed files..." - - # Verify gofmt is installed - if ($(Get-Command gofmt -ErrorAction SilentlyContinue) -eq $nil) { Throw "gofmt does not appear to be installed" } - - # Get a list of all go source-code files which have changed. Ignore exit code on next call - always process regardless - $files=@(); $files = Invoke-Expression "git diff $upstreamCommit...$headCommit --diff-filter=ACMR --name-only -- `'*.go`'" - $files = $files | Select-String -NotMatch "^vendor/" | Select-String -NotMatch "^cli/compose/schema/bindata.go" - $badFiles=@(); $files | %{ - # Deliberately ignore error on next line - treat as failed - $content=Invoke-Expression "git show $headCommit`:$_" - - # Next set of hoops are to ensure we have LF not CRLF semantics as otherwise gofmt on Windows will not succeed. - # Also note that gofmt on Windows does not appear to support stdin piping correctly. Hence go through a temporary file. - $content=$content -join "`n" - $content+="`n" - $outputFile=[System.IO.Path]::GetTempFileName() - if (Test-Path $outputFile) { Remove-Item $outputFile } - [System.IO.File]::WriteAllText($outputFile, $content, (New-Object System.Text.UTF8Encoding($False))) - $valid=Invoke-Expression "gofmt -s -l $outputFile" - Write-Host "Checking $outputFile" - if ($valid.Length -ne 0) { $badFiles+=$_ } - if (Test-Path $outputFile) { Remove-Item $outputFile } - } - if ($badFiles.Length -eq 0) { - Write-Host 'Congratulations! All Go source files are properly formatted.' - } else { - $e = "`nThese files are not properly gofmt`'d:`n" - $badFiles | %{ $e+=" - $_`n"} - $e+= "`nPlease reformat the above files using `"gofmt -s -w`" and commit the result." - Throw $e - } -} - -# Run the unit tests -Function Run-UnitTests() { - Write-Host "INFO: Running unit tests..." - $testPath="./..." - $goListCommand = "go list -e -f '{{if ne .Name """ + '\"github.com/docker/docker\"' + """}}{{.ImportPath}}{{end}}' $testPath" - $pkgList = $(Invoke-Expression $goListCommand) - if ($LASTEXITCODE -ne 0) { Throw "go list for unit tests failed" } - $pkgList = $pkgList | Select-String -Pattern "github.com/docker/docker" - $pkgList = $pkgList | Select-String -NotMatch "github.com/docker/docker/vendor" - $pkgList = $pkgList | Select-String -NotMatch "github.com/docker/docker/man" - $pkgList = $pkgList | Select-String -NotMatch "github.com/docker/docker/integration-cli" - $pkgList = $pkgList -replace "`r`n", " " - $goTestCommand = "go test" + $raceParm + " -cover -ldflags -w -tags """ + "autogen daemon" + """ -a """ + "-test.timeout=10m" + """ $pkgList" - Invoke-Expression $goTestCommand - if ($LASTEXITCODE -ne 0) { Throw "Unit tests failed" } -} - -# Start of main code. -Try { - Write-Host -ForegroundColor Cyan "INFO: make.ps1 starting at $(Get-Date)" - $root=$(pwd) - - # Handle the "-All" shortcut to turn on all things we can handle. - if ($All) { $Client=$True; $Daemon=$True; $DCO=$True; $PkgImports=$True; $GoFormat=$True; $TestUnit=$True } - - # Handle the "-Binary" shortcut to build both client and daemon. - if ($Binary) { $Client = $True; $Daemon = $True } - - # Make sure we have something to do - if (-not($Client) -and -not($Daemon) -and -not($DCO) -and -not($PkgImports) -and -not($GoFormat) -and -not($TestUnit)) { Throw 'Nothing to do. Try adding "-All" for everything I can do' } - - # Verify git is installed - if ($(Get-Command git -ErrorAction SilentlyContinue) -eq $nil) { Throw "Git does not appear to be installed" } - - # Verify go is installed - if ($(Get-Command go -ErrorAction SilentlyContinue) -eq $nil) { Throw "GoLang does not appear to be installed" } - - # Get the git commit. This will also verify if we are in a repo or not. Then add a custom string if supplied. - $gitCommit=Get-GitCommit - if ($CommitSuffix -ne "") { $gitCommit += "-"+$CommitSuffix -Replace ' ', '' } - - # Get the version of docker (eg 1.14.0-dev) - $dockerVersion=Get-DockerVersion - - # Give a warning if we are not running in a container and are building binaries or running unit tests. - # Not relevant for validation tests as these are fine to run outside of a container. - if ($Client -or $Daemon -or $TestUnit) { Check-InContainer } - - # Verify GOPATH is set - if ($env:GOPATH.Length -eq 0) { Throw "Missing GOPATH environment variable. See https://golang.org/doc/code.html#GOPATH" } - - # Run autogen if building binaries or running unit tests. - if ($Client -or $Daemon -or $TestUnit) { - Write-Host "INFO: Invoking autogen..." - Try { .\hack\make\.go-autogen.ps1 -CommitString $gitCommit -DockerVersion $dockerVersion } - Catch [Exception] { Throw $_ } - } - - # DCO, Package import and Go formatting tests. - if ($DCO -or $PkgImports -or $GoFormat) { - # We need the head and upstream commits for these - $headCommit=Get-HeadCommit - $upstreamCommit=Get-UpstreamCommit - - # Run DCO validation - if ($DCO) { Validate-DCO $headCommit $upstreamCommit } - - # Run `gofmt` validation - if ($GoFormat) { Validate-GoFormat $headCommit $upstreamCommit } - - # Run pkg isolation validation - if ($PkgImports) { Validate-PkgImports $headCommit $upstreamCommit } - } - - # Build the binaries - if ($Client -or $Daemon) { - # Create the bundles directory if it doesn't exist - if (-not (Test-Path ".\bundles")) { New-Item ".\bundles" -ItemType Directory | Out-Null } - - # Perform the actual build - if ($Daemon) { Execute-Build "daemon" "daemon" "dockerd" } - if ($Client) { Execute-Build "client" "" "docker" } - } - - # Run unit tests - if ($TestUnit) { Run-UnitTests } - - # Gratuitous ASCII art. - if ($Daemon -or $Client) { - Write-Host - Write-Host -ForegroundColor Green " ________ ____ __." - Write-Host -ForegroundColor Green " \_____ \ `| `|/ _`|" - Write-Host -ForegroundColor Green " / `| \`| `<" - Write-Host -ForegroundColor Green " / `| \ `| \" - Write-Host -ForegroundColor Green " \_______ /____`|__ \" - Write-Host -ForegroundColor Green " \/ \/" - Write-Host - } -} -Catch [Exception] { - Write-Host -ForegroundColor Red ("`nERROR: make.ps1 failed:`n$_") - - # More gratuitous ASCII art. - Write-Host - Write-Host -ForegroundColor Red "___________ .__.__ .___" - Write-Host -ForegroundColor Red "\_ _____/____ `|__`| `| ____ __`| _/" - Write-Host -ForegroundColor Red " `| __) \__ \ `| `| `| _/ __ \ / __ `| " - Write-Host -ForegroundColor Red " `| \ / __ \`| `| `|_\ ___// /_/ `| " - Write-Host -ForegroundColor Red " \___ / (____ /__`|____/\___ `>____ `| " - Write-Host -ForegroundColor Red " \/ \/ \/ \/ " - Write-Host - - Throw $_ -} -Finally { - if ($global:pushed) { Pop-Location } - Write-Host -ForegroundColor Cyan "INFO: make.ps1 ended at $(Get-Date)" -} diff --git a/vendor/github.com/docker/docker/hack/make.sh b/vendor/github.com/docker/docker/hack/make.sh deleted file mode 100755 index f0e482f..0000000 --- a/vendor/github.com/docker/docker/hack/make.sh +++ /dev/null @@ -1,304 +0,0 @@ -#!/usr/bin/env bash -set -e - -# This script builds various binary artifacts from a checkout of the docker -# source code. -# -# Requirements: -# - The current directory should be a checkout of the docker source code -# (https://github.com/docker/docker). Whatever version is checked out -# will be built. -# - The VERSION file, at the root of the repository, should exist, and -# will be used as Docker binary version and package version. -# - The hash of the git commit will also be included in the Docker binary, -# with the suffix -unsupported if the repository isn't clean. -# - The script is intended to be run inside the docker container specified -# in the Dockerfile at the root of the source. In other words: -# DO NOT CALL THIS SCRIPT DIRECTLY. -# - The right way to call this script is to invoke "make" from -# your checkout of the Docker repository. -# the Makefile will do a "docker build -t docker ." and then -# "docker run hack/make.sh" in the resulting image. -# - -set -o pipefail - -export DOCKER_PKG='github.com/docker/docker' -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -export MAKEDIR="$SCRIPTDIR/make" -export PKG_CONFIG=${PKG_CONFIG:-pkg-config} - -# We're a nice, sexy, little shell script, and people might try to run us; -# but really, they shouldn't. We want to be in a container! -inContainer="AssumeSoInitially" -if [ "$(go env GOHOSTOS)" = 'windows' ]; then - if [ -z "$FROM_DOCKERFILE" ]; then - unset inContainer - fi -else - if [ "$PWD" != "/go/src/$DOCKER_PKG" ] || [ -z "$DOCKER_CROSSPLATFORMS" ]; then - unset inContainer - fi -fi - -if [ -z "$inContainer" ]; then - { - echo "# WARNING! I don't seem to be running in a Docker container." - echo "# The result of this command might be an incorrect build, and will not be" - echo "# officially supported." - echo "#" - echo "# Try this instead: make all" - echo "#" - } >&2 -fi - -echo - -# List of bundles to create when no argument is passed -DEFAULT_BUNDLES=( - binary-client - binary-daemon - dynbinary - - test-unit - test-integration-cli - test-docker-py - - cross - tgz -) - -VERSION=$(< ./VERSION) -! BUILDTIME=$(date --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/') -if command -v git &> /dev/null && [ -d .git ] && git rev-parse &> /dev/null; then - GITCOMMIT=$(git rev-parse --short HEAD) - if [ -n "$(git status --porcelain --untracked-files=no)" ]; then - GITCOMMIT="$GITCOMMIT-unsupported" - echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" - echo "# GITCOMMIT = $GITCOMMIT" - echo "# The version you are building is listed as unsupported because" - echo "# there are some files in the git repository that are in an uncommitted state." - echo "# Commit these changes, or add to .gitignore to remove the -unsupported from the version." - echo "# Here is the current list:" - git status --porcelain --untracked-files=no - echo "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" - fi -elif [ "$DOCKER_GITCOMMIT" ]; then - GITCOMMIT="$DOCKER_GITCOMMIT" -else - echo >&2 'error: .git directory missing and DOCKER_GITCOMMIT not specified' - echo >&2 ' Please either build with the .git directory accessible, or specify the' - echo >&2 ' exact (--short) commit hash you are building using DOCKER_GITCOMMIT for' - echo >&2 ' future accountability in diagnosing build issues. Thanks!' - exit 1 -fi - -if [ "$AUTO_GOPATH" ]; then - rm -rf .gopath - mkdir -p .gopath/src/"$(dirname "${DOCKER_PKG}")" - ln -sf ../../../.. .gopath/src/"${DOCKER_PKG}" - export GOPATH="${PWD}/.gopath" - - if [ "$(go env GOOS)" = 'solaris' ]; then - # sys/unix is installed outside the standard library on solaris - # TODO need to allow for version change, need to get version from go - export GO_VERSION=${GO_VERSION:-"1.7.1"} - export GOPATH="${GOPATH}:/usr/lib/gocode/${GO_VERSION}" - fi -fi - -if [ ! "$GOPATH" ]; then - echo >&2 'error: missing GOPATH; please see https://golang.org/doc/code.html#GOPATH' - echo >&2 ' alternatively, set AUTO_GOPATH=1' - exit 1 -fi - -DOCKER_BUILDTAGS+=" daemon" -if ${PKG_CONFIG} 'libsystemd >= 209' 2> /dev/null ; then - DOCKER_BUILDTAGS+=" journald" -elif ${PKG_CONFIG} 'libsystemd-journal' 2> /dev/null ; then - DOCKER_BUILDTAGS+=" journald journald_compat" -fi - -# test whether "btrfs/version.h" exists and apply btrfs_noversion appropriately -if \ - command -v gcc &> /dev/null \ - && ! gcc -E - -o /dev/null &> /dev/null <<<'#include ' \ -; then - DOCKER_BUILDTAGS+=' btrfs_noversion' -fi - -# test whether "libdevmapper.h" is new enough to support deferred remove -# functionality. -if \ - command -v gcc &> /dev/null \ - && ! ( echo -e '#include \nint main() { dm_task_deferred_remove(NULL); }'| gcc -xc - -o /dev/null -ldevmapper &> /dev/null ) \ -; then - DOCKER_BUILDTAGS+=' libdm_no_deferred_remove' -fi - -# Use these flags when compiling the tests and final binary - -IAMSTATIC='true' -source "$SCRIPTDIR/make/.go-autogen" -if [ -z "$DOCKER_DEBUG" ]; then - LDFLAGS='-w' -fi - -LDFLAGS_STATIC='' -EXTLDFLAGS_STATIC='-static' -# ORIG_BUILDFLAGS is necessary for the cross target which cannot always build -# with options like -race. -ORIG_BUILDFLAGS=( -tags "autogen netgo static_build sqlite_omit_load_extension $DOCKER_BUILDTAGS" -installsuffix netgo ) -# see https://github.com/golang/go/issues/9369#issuecomment-69864440 for why -installsuffix is necessary here - -# When $DOCKER_INCREMENTAL_BINARY is set in the environment, enable incremental -# builds by installing dependent packages to the GOPATH. -REBUILD_FLAG="-a" -if [ "$DOCKER_INCREMENTAL_BINARY" ]; then - REBUILD_FLAG="-i" -fi -ORIG_BUILDFLAGS+=( $REBUILD_FLAG ) - -BUILDFLAGS=( $BUILDFLAGS "${ORIG_BUILDFLAGS[@]}" ) -# Test timeout. - -if [ "${DOCKER_ENGINE_GOARCH}" == "arm" ]; then - : ${TIMEOUT:=10m} -elif [ "${DOCKER_ENGINE_GOARCH}" == "windows" ]; then - : ${TIMEOUT:=8m} -else - : ${TIMEOUT:=5m} -fi - -LDFLAGS_STATIC_DOCKER=" - $LDFLAGS_STATIC - -extldflags \"$EXTLDFLAGS_STATIC\" -" - -if [ "$(uname -s)" = 'FreeBSD' ]; then - # Tell cgo the compiler is Clang, not GCC - # https://code.google.com/p/go/source/browse/src/cmd/cgo/gcc.go?spec=svne77e74371f2340ee08622ce602e9f7b15f29d8d3&r=e6794866ebeba2bf8818b9261b54e2eef1c9e588#752 - export CC=clang - - # "-extld clang" is a workaround for - # https://code.google.com/p/go/issues/detail?id=6845 - LDFLAGS="$LDFLAGS -extld clang" -fi - -# If sqlite3.h doesn't exist under /usr/include, -# check /usr/local/include also just in case -# (e.g. FreeBSD Ports installs it under the directory) -if [ ! -e /usr/include/sqlite3.h ] && [ -e /usr/local/include/sqlite3.h ]; then - export CGO_CFLAGS='-I/usr/local/include' - export CGO_LDFLAGS='-L/usr/local/lib' -fi - -HAVE_GO_TEST_COVER= -if \ - go help testflag | grep -- -cover > /dev/null \ - && go tool -n cover > /dev/null 2>&1 \ -; then - HAVE_GO_TEST_COVER=1 -fi - -# a helper to provide ".exe" when it's appropriate -binary_extension() { - if [ "$(go env GOOS)" = 'windows' ]; then - echo -n '.exe' - fi -} - -hash_files() { - while [ $# -gt 0 ]; do - f="$1" - shift - dir="$(dirname "$f")" - base="$(basename "$f")" - for hashAlgo in md5 sha256; do - if command -v "${hashAlgo}sum" &> /dev/null; then - ( - # subshell and cd so that we get output files like: - # $HASH docker-$VERSION - # instead of: - # $HASH /go/src/github.com/.../$VERSION/binary/docker-$VERSION - cd "$dir" - "${hashAlgo}sum" "$base" > "$base.$hashAlgo" - ) - fi - done - done -} - -bundle() { - local bundle="$1"; shift - echo "---> Making bundle: $(basename "$bundle") (in $DEST)" - source "$SCRIPTDIR/make/$bundle" "$@" -} - -copy_binaries() { - dir="$1" - # Add nested executables to bundle dir so we have complete set of - # them available, but only if the native OS/ARCH is the same as the - # OS/ARCH of the build target - if [ "$(go env GOOS)/$(go env GOARCH)" == "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then - if [ -x /usr/local/bin/docker-runc ]; then - echo "Copying nested executables into $dir" - for file in containerd containerd-shim containerd-ctr runc init proxy; do - cp `which "docker-$file"` "$dir/" - if [ "$2" == "hash" ]; then - hash_files "$dir/docker-$file" - fi - done - fi - fi -} - -install_binary() { - file="$1" - target="${DOCKER_MAKE_INSTALL_PREFIX:=/usr/local}/bin/" - if [ "$(go env GOOS)" == "linux" ]; then - echo "Installing $(basename $file) to ${target}" - cp -L "$file" "$target" - else - echo "Install is only supported on linux" - return 1 - fi -} - -main() { - # We want this to fail if the bundles already exist and cannot be removed. - # This is to avoid mixing bundles from different versions of the code. - mkdir -p bundles - if [ -e "bundles/$VERSION" ] && [ -z "$KEEPBUNDLE" ]; then - echo "bundles/$VERSION already exists. Removing." - rm -fr "bundles/$VERSION" && mkdir "bundles/$VERSION" || exit 1 - echo - fi - - if [ "$(go env GOHOSTOS)" != 'windows' ]; then - # Windows and symlinks don't get along well - - rm -f bundles/latest - ln -s "$VERSION" bundles/latest - fi - - if [ $# -lt 1 ]; then - bundles=(${DEFAULT_BUNDLES[@]}) - else - bundles=($@) - fi - for bundle in ${bundles[@]}; do - export DEST="bundles/$VERSION/$(basename "$bundle")" - # Cygdrive paths don't play well with go build -o. - if [[ "$(uname -s)" == CYGWIN* ]]; then - export DEST="$(cygpath -mw "$DEST")" - fi - mkdir -p "$DEST" - ABS_DEST="$(cd "$DEST" && pwd -P)" - bundle "$bundle" - echo - done -} - -main "$@" diff --git a/vendor/github.com/docker/docker/hack/make/.binary b/vendor/github.com/docker/docker/hack/make/.binary deleted file mode 100644 index f5c35c3..0000000 --- a/vendor/github.com/docker/docker/hack/make/.binary +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -set -e - -BINARY_NAME="$BINARY_SHORT_NAME-$VERSION" -BINARY_EXTENSION="$(binary_extension)" -BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION" - -source "${MAKEDIR}/.go-autogen" - -( -export GOGC=${DOCKER_BUILD_GOGC:-1000} - -if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARCH)" ]; then - # must be cross-compiling! - case "$(go env GOOS)/$(go env GOARCH)" in - windows/amd64) - export CC=x86_64-w64-mingw32-gcc - export CGO_ENABLED=1 - ;; - esac -fi - -if [ "$IAMSTATIC" == "true" ] && [ "$(go env GOHOSTOS)" == "linux" ]; then - if [ "${GOOS}/${GOARCH}" == "darwin/amd64" ]; then - export CGO_ENABLED=1 - export CC=o64-clang - export LDFLAGS='-linkmode external -s' - export LDFLAGS_STATIC_DOCKER='-extld='${CC} - else - export BUILDFLAGS=( "${BUILDFLAGS[@]/pkcs11 /}" ) # we cannot dlopen in pkcs11 in a static binary - fi -fi - -echo "Building: $DEST/$BINARY_FULLNAME" -go build \ - -o "$DEST/$BINARY_FULLNAME" \ - "${BUILDFLAGS[@]}" \ - -ldflags " - $LDFLAGS - $LDFLAGS_STATIC_DOCKER - " \ - $GO_PACKAGE -) - -echo "Created binary: $DEST/$BINARY_FULLNAME" -ln -sf "$BINARY_FULLNAME" "$DEST/$BINARY_SHORT_NAME$BINARY_EXTENSION" - -hash_files "$DEST/$BINARY_FULLNAME" diff --git a/vendor/github.com/docker/docker/hack/make/.binary-setup b/vendor/github.com/docker/docker/hack/make/.binary-setup deleted file mode 100644 index b9f8ce2..0000000 --- a/vendor/github.com/docker/docker/hack/make/.binary-setup +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DOCKER_CLIENT_BINARY_NAME='docker' -DOCKER_DAEMON_BINARY_NAME='dockerd' -DOCKER_RUNC_BINARY_NAME='docker-runc' -DOCKER_CONTAINERD_BINARY_NAME='docker-containerd' -DOCKER_CONTAINERD_CTR_BINARY_NAME='docker-containerd-ctr' -DOCKER_CONTAINERD_SHIM_BINARY_NAME='docker-containerd-shim' -DOCKER_PROXY_BINARY_NAME='docker-proxy' -DOCKER_INIT_BINARY_NAME='docker-init' diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/compat b/vendor/github.com/docker/docker/hack/make/.build-deb/compat deleted file mode 100644 index ec63514..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/compat +++ /dev/null @@ -1 +0,0 @@ -9 diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/control b/vendor/github.com/docker/docker/hack/make/.build-deb/control deleted file mode 100644 index 0f54399..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/control +++ /dev/null @@ -1,29 +0,0 @@ -Source: docker-engine -Section: admin -Priority: optional -Maintainer: Docker -Standards-Version: 3.9.6 -Homepage: https://dockerproject.org -Vcs-Browser: https://github.com/docker/docker -Vcs-Git: git://github.com/docker/docker.git - -Package: docker-engine -Architecture: linux-any -Depends: iptables, ${misc:Depends}, ${perl:Depends}, ${shlibs:Depends} -Recommends: aufs-tools, - ca-certificates, - cgroupfs-mount | cgroup-lite, - git, - xz-utils, - ${apparmor:Recommends} -Conflicts: docker (<< 1.5~), docker.io, lxc-docker, lxc-docker-virtual-package, docker-engine-cs -Description: Docker: the open-source application container engine - Docker is an open source project to build, ship and run any application as a - lightweight container - . - Docker containers are both hardware-agnostic and platform-agnostic. This means - they can run anywhere, from your laptop to the largest EC2 compute instance and - everything in between - and they don't require you to use a particular - language, framework or packaging system. That makes them great building blocks - for deploying and scaling web apps, databases, and backend services without - depending on a particular stack or provider. diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.bash-completion b/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.bash-completion deleted file mode 100644 index 6ea1119..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.bash-completion +++ /dev/null @@ -1 +0,0 @@ -contrib/completion/bash/docker diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.docker.default b/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.docker.default deleted file mode 120000 index 4278533..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.docker.default +++ /dev/null @@ -1 +0,0 @@ -../../../contrib/init/sysvinit-debian/docker.default \ No newline at end of file diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.docker.init b/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.docker.init deleted file mode 120000 index 8cb89d3..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.docker.init +++ /dev/null @@ -1 +0,0 @@ -../../../contrib/init/sysvinit-debian/docker \ No newline at end of file diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.docker.upstart b/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.docker.upstart deleted file mode 120000 index 7e1b64a..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.docker.upstart +++ /dev/null @@ -1 +0,0 @@ -../../../contrib/init/upstart/docker.conf \ No newline at end of file diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.install b/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.install deleted file mode 100644 index dc6b25f..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.install +++ /dev/null @@ -1,12 +0,0 @@ -#contrib/syntax/vim/doc/* /usr/share/vim/vimfiles/doc/ -#contrib/syntax/vim/ftdetect/* /usr/share/vim/vimfiles/ftdetect/ -#contrib/syntax/vim/syntax/* /usr/share/vim/vimfiles/syntax/ -contrib/*-integration usr/share/docker-engine/contrib/ -contrib/check-config.sh usr/share/docker-engine/contrib/ -contrib/completion/fish/docker.fish usr/share/fish/vendor_completions.d/ -contrib/completion/zsh/_docker usr/share/zsh/vendor-completions/ -contrib/init/systemd/docker.service lib/systemd/system/ -contrib/init/systemd/docker.socket lib/systemd/system/ -contrib/mk* usr/share/docker-engine/contrib/ -contrib/nuke-graph-directory.sh usr/share/docker-engine/contrib/ -contrib/syntax/nano/Dockerfile.nanorc usr/share/nano/ diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.manpages b/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.manpages deleted file mode 100644 index 1aa6218..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.manpages +++ /dev/null @@ -1 +0,0 @@ -man/man*/* diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.postinst b/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.postinst deleted file mode 100644 index eeef6ca..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.postinst +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -set -e - -case "$1" in - configure) - if [ -z "$2" ]; then - if ! getent group docker > /dev/null; then - groupadd --system docker - fi - fi - ;; - abort-*) - # How'd we get here?? - exit 1 - ;; - *) - ;; -esac - -#DEBHELPER# diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.udev b/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.udev deleted file mode 120000 index 914a361..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/docker-engine.udev +++ /dev/null @@ -1 +0,0 @@ -../../../contrib/udev/80-docker.rules \ No newline at end of file diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/docs b/vendor/github.com/docker/docker/hack/make/.build-deb/docs deleted file mode 100644 index b43bf86..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/docs +++ /dev/null @@ -1 +0,0 @@ -README.md diff --git a/vendor/github.com/docker/docker/hack/make/.build-deb/rules b/vendor/github.com/docker/docker/hack/make/.build-deb/rules deleted file mode 100755 index 6522103..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-deb/rules +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/make -f - -VERSION = $(shell cat VERSION) -SYSTEMD_VERSION := $(shell dpkg-query -W -f='$${Version}\n' systemd | cut -d- -f1) -SYSTEMD_GT_227 := $(shell [ '$(SYSTEMD_VERSION)' ] && [ '$(SYSTEMD_VERSION)' -gt 227 ] && echo true ) - -override_dh_gencontrol: - # if we're on Ubuntu, we need to Recommends: apparmor - echo 'apparmor:Recommends=$(shell dpkg-vendor --is Ubuntu && echo apparmor)' >> debian/docker-engine.substvars - dh_gencontrol - -override_dh_auto_build: - ./hack/make.sh dynbinary - # ./man/md2man-all.sh runs outside the build container (if at all), since we don't have go-md2man here - -override_dh_auto_test: - ./bundles/$(VERSION)/dynbinary-daemon/dockerd -v - ./bundles/$(VERSION)/dynbinary-client/docker -v - -override_dh_strip: - # Go has lots of problems with stripping, so just don't - -override_dh_auto_install: - mkdir -p debian/docker-engine/usr/bin - cp -aT "$$(readlink -f bundles/$(VERSION)/dynbinary-client/docker)" debian/docker-engine/usr/bin/docker - cp -aT "$$(readlink -f bundles/$(VERSION)/dynbinary-daemon/dockerd)" debian/docker-engine/usr/bin/dockerd - cp -aT /usr/local/bin/docker-proxy debian/docker-engine/usr/bin/docker-proxy - cp -aT /usr/local/bin/docker-containerd debian/docker-engine/usr/bin/docker-containerd - cp -aT /usr/local/bin/docker-containerd-shim debian/docker-engine/usr/bin/docker-containerd-shim - cp -aT /usr/local/bin/docker-containerd-ctr debian/docker-engine/usr/bin/docker-containerd-ctr - cp -aT /usr/local/bin/docker-runc debian/docker-engine/usr/bin/docker-runc - cp -aT /usr/local/bin/docker-init debian/docker-engine/usr/bin/docker-init - mkdir -p debian/docker-engine/usr/lib/docker - -override_dh_installinit: - # use "docker" as our service name, not "docker-engine" - dh_installinit --name=docker -ifeq (true, $(SYSTEMD_GT_227)) - $(warning "Setting TasksMax=infinity") - sed -i -- 's/#TasksMax=infinity/TasksMax=infinity/' debian/docker-engine/lib/systemd/system/docker.service -endif - -override_dh_installudev: - # match our existing priority - dh_installudev --priority=z80 - -override_dh_install: - dh_install - dh_apparmor --profile-name=docker-engine -pdocker-engine - -override_dh_shlibdeps: - dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info - -%: - dh $@ --with=bash-completion $(shell command -v dh_systemd_enable > /dev/null 2>&1 && echo --with=systemd) diff --git a/vendor/github.com/docker/docker/hack/make/.build-rpm/docker-engine-selinux.spec b/vendor/github.com/docker/docker/hack/make/.build-rpm/docker-engine-selinux.spec deleted file mode 100644 index ae597bd..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-rpm/docker-engine-selinux.spec +++ /dev/null @@ -1,96 +0,0 @@ -# Some bits borrowed from the openstack-selinux package -Name: docker-engine-selinux -Version: %{_version} -Release: %{_release}%{?dist} -Summary: SELinux Policies for the open-source application container engine -BuildArch: noarch -Group: Tools/Docker - -License: GPLv2 -Source: %{name}.tar.gz - -URL: https://dockerproject.org -Vendor: Docker -Packager: Docker - -%global selinux_policyver 3.13.1-102 -%global selinuxtype targeted -%global moduletype services -%global modulenames docker - -Requires(post): selinux-policy-base >= %{selinux_policyver}, selinux-policy-targeted >= %{selinux_policyver}, policycoreutils, policycoreutils-python libselinux-utils -BuildRequires: selinux-policy selinux-policy-devel - -# conflicting packages -Conflicts: docker-selinux - -# Usage: _format var format -# Expand 'modulenames' into various formats as needed -# Format must contain '$x' somewhere to do anything useful -%global _format() export %1=""; for x in %{modulenames}; do %1+=%2; %1+=" "; done; - -# Relabel files -%global relabel_files() \ - /sbin/restorecon -R %{_bindir}/docker %{_localstatedir}/run/docker.sock %{_localstatedir}/run/docker.pid %{_sysconfdir}/docker %{_localstatedir}/log/docker %{_localstatedir}/log/lxc %{_localstatedir}/lock/lxc %{_usr}/lib/systemd/system/docker.service /root/.docker &> /dev/null || : \ - -%description -SELinux policy modules for use with Docker - -%prep -%if 0%{?centos} <= 6 -%setup -n %{name} -%else -%autosetup -n %{name} -%endif - -%build -make SHARE="%{_datadir}" TARGETS="%{modulenames}" - -%install - -# Install SELinux interfaces -%_format INTERFACES $x.if -install -d %{buildroot}%{_datadir}/selinux/devel/include/%{moduletype} -install -p -m 644 $INTERFACES %{buildroot}%{_datadir}/selinux/devel/include/%{moduletype} - -# Install policy modules -%_format MODULES $x.pp.bz2 -install -d %{buildroot}%{_datadir}/selinux/packages -install -m 0644 $MODULES %{buildroot}%{_datadir}/selinux/packages - -%post -# -# Install all modules in a single transaction -# -if [ $1 -eq 1 ]; then - %{_sbindir}/setsebool -P -N virt_use_nfs=1 virt_sandbox_use_all_caps=1 -fi -%_format MODULES %{_datadir}/selinux/packages/$x.pp.bz2 -%{_sbindir}/semodule -n -s %{selinuxtype} -i $MODULES -if %{_sbindir}/selinuxenabled ; then - %{_sbindir}/load_policy - %relabel_files - if [ $1 -eq 1 ]; then - restorecon -R %{_sharedstatedir}/docker - fi -fi - -%postun -if [ $1 -eq 0 ]; then - %{_sbindir}/semodule -n -r %{modulenames} &> /dev/null || : - if %{_sbindir}/selinuxenabled ; then - %{_sbindir}/load_policy - %relabel_files - fi -fi - -%files -%doc LICENSE -%defattr(-,root,root,0755) -%attr(0644,root,root) %{_datadir}/selinux/packages/*.pp.bz2 -%attr(0644,root,root) %{_datadir}/selinux/devel/include/%{moduletype}/*.if - -%changelog -* Tue Dec 1 2015 Jessica Frazelle 1.9.1-1 -- add licence to rpm -- add selinux-policy and docker-engine-selinux rpm diff --git a/vendor/github.com/docker/docker/hack/make/.build-rpm/docker-engine.spec b/vendor/github.com/docker/docker/hack/make/.build-rpm/docker-engine.spec deleted file mode 100644 index d53e55b..0000000 --- a/vendor/github.com/docker/docker/hack/make/.build-rpm/docker-engine.spec +++ /dev/null @@ -1,254 +0,0 @@ -Name: docker-engine -Version: %{_version} -Release: %{_release}%{?dist} -Summary: The open-source application container engine -Group: Tools/Docker - -License: ASL 2.0 -Source: %{name}.tar.gz - -URL: https://dockerproject.org -Vendor: Docker -Packager: Docker - -# is_systemd conditional -%if 0%{?fedora} >= 21 || 0%{?centos} >= 7 || 0%{?rhel} >= 7 || 0%{?suse_version} >= 1210 -%global is_systemd 1 -%endif - -# required packages for build -# most are already in the container (see contrib/builder/rpm/ARCH/generate.sh) -# only require systemd on those systems -%if 0%{?is_systemd} -%if 0%{?suse_version} >= 1210 -BuildRequires: systemd-rpm-macros -%{?systemd_requires} -%else -%if 0%{?fedora} >= 25 -# Systemd 230 and up no longer have libsystemd-journal (see https://bugzilla.redhat.com/show_bug.cgi?id=1350301) -BuildRequires: pkgconfig(systemd) -Requires: systemd-units -%else -BuildRequires: pkgconfig(systemd) -Requires: systemd-units -BuildRequires: pkgconfig(libsystemd-journal) -%endif -%endif -%else -Requires(post): chkconfig -Requires(preun): chkconfig -# This is for /sbin/service -Requires(preun): initscripts -%endif - -# required packages on install -Requires: /bin/sh -Requires: iptables -%if !0%{?suse_version} -Requires: libcgroup -%else -Requires: libcgroup1 -%endif -Requires: tar -Requires: xz -%if 0%{?fedora} >= 21 || 0%{?centos} >= 7 || 0%{?rhel} >= 7 || 0%{?oraclelinux} >= 7 -# Resolves: rhbz#1165615 -Requires: device-mapper-libs >= 1.02.90-1 -%endif -%if 0%{?oraclelinux} >= 6 -# Require Oracle Unbreakable Enterprise Kernel R4 and newer device-mapper -Requires: kernel-uek >= 4.1 -Requires: device-mapper >= 1.02.90-2 -%endif - -# docker-selinux conditional -%if 0%{?fedora} >= 20 || 0%{?centos} >= 7 || 0%{?rhel} >= 7 || 0%{?oraclelinux} >= 7 -%global with_selinux 1 -%endif - -# DWZ problem with multiple golang binary, see bug -# https://bugzilla.redhat.com/show_bug.cgi?id=995136#c12 -%if 0%{?fedora} >= 20 || 0%{?rhel} >= 7 || 0%{?oraclelinux} >= 7 -%global _dwz_low_mem_die_limit 0 -%endif - -# start if with_selinux -%if 0%{?with_selinux} -# Version of SELinux we were using -%if 0%{?fedora} == 20 -%global selinux_policyver 3.12.1-197 -%endif # fedora 20 -%if 0%{?fedora} == 21 -%global selinux_policyver 3.13.1-105 -%endif # fedora 21 -%if 0%{?fedora} >= 22 -%global selinux_policyver 3.13.1-128 -%endif # fedora 22 -%if 0%{?centos} >= 7 || 0%{?rhel} >= 7 || 0%{?oraclelinux} >= 7 -%global selinux_policyver 3.13.1-23 -%endif # centos,oraclelinux 7 -%endif # with_selinux - -# RE: rhbz#1195804 - ensure min NVR for selinux-policy -%if 0%{?with_selinux} -Requires: selinux-policy >= %{selinux_policyver} -Requires(pre): %{name}-selinux >= %{version}-%{release} -%endif # with_selinux - -# conflicting packages -Conflicts: docker -Conflicts: docker-io -Conflicts: docker-engine-cs - -%description -Docker is an open source project to build, ship and run any application as a -lightweight container. - -Docker containers are both hardware-agnostic and platform-agnostic. This means -they can run anywhere, from your laptop to the largest EC2 compute instance and -everything in between - and they don't require you to use a particular -language, framework or packaging system. That makes them great building blocks -for deploying and scaling web apps, databases, and backend services without -depending on a particular stack or provider. - -%prep -%if 0%{?centos} <= 6 || 0%{?oraclelinux} <=6 -%setup -n %{name} -%else -%autosetup -n %{name} -%endif - -%build -export DOCKER_GITCOMMIT=%{_gitcommit} -./hack/make.sh dynbinary -# ./man/md2man-all.sh runs outside the build container (if at all), since we don't have go-md2man here - -%check -./bundles/%{_origversion}/dynbinary-client/docker -v -./bundles/%{_origversion}/dynbinary-daemon/dockerd -v - -%install -# install binary -install -d $RPM_BUILD_ROOT/%{_bindir} -install -p -m 755 bundles/%{_origversion}/dynbinary-client/docker-%{_origversion} $RPM_BUILD_ROOT/%{_bindir}/docker -install -p -m 755 bundles/%{_origversion}/dynbinary-daemon/dockerd-%{_origversion} $RPM_BUILD_ROOT/%{_bindir}/dockerd - -# install proxy -install -p -m 755 /usr/local/bin/docker-proxy $RPM_BUILD_ROOT/%{_bindir}/docker-proxy - -# install containerd -install -p -m 755 /usr/local/bin/docker-containerd $RPM_BUILD_ROOT/%{_bindir}/docker-containerd -install -p -m 755 /usr/local/bin/docker-containerd-shim $RPM_BUILD_ROOT/%{_bindir}/docker-containerd-shim -install -p -m 755 /usr/local/bin/docker-containerd-ctr $RPM_BUILD_ROOT/%{_bindir}/docker-containerd-ctr - -# install runc -install -p -m 755 /usr/local/bin/docker-runc $RPM_BUILD_ROOT/%{_bindir}/docker-runc - -# install tini -install -p -m 755 /usr/local/bin/docker-init $RPM_BUILD_ROOT/%{_bindir}/docker-init - -# install udev rules -install -d $RPM_BUILD_ROOT/%{_sysconfdir}/udev/rules.d -install -p -m 644 contrib/udev/80-docker.rules $RPM_BUILD_ROOT/%{_sysconfdir}/udev/rules.d/80-docker.rules - -# add init scripts -install -d $RPM_BUILD_ROOT/etc/sysconfig -install -d $RPM_BUILD_ROOT/%{_initddir} - - -%if 0%{?is_systemd} -install -d $RPM_BUILD_ROOT/%{_unitdir} -install -p -m 644 contrib/init/systemd/docker.service.rpm $RPM_BUILD_ROOT/%{_unitdir}/docker.service -%else -install -p -m 644 contrib/init/sysvinit-redhat/docker.sysconfig $RPM_BUILD_ROOT/etc/sysconfig/docker -install -p -m 755 contrib/init/sysvinit-redhat/docker $RPM_BUILD_ROOT/%{_initddir}/docker -%endif -# add bash, zsh, and fish completions -install -d $RPM_BUILD_ROOT/usr/share/bash-completion/completions -install -d $RPM_BUILD_ROOT/usr/share/zsh/vendor-completions -install -d $RPM_BUILD_ROOT/usr/share/fish/vendor_completions.d -install -p -m 644 contrib/completion/bash/docker $RPM_BUILD_ROOT/usr/share/bash-completion/completions/docker -install -p -m 644 contrib/completion/zsh/_docker $RPM_BUILD_ROOT/usr/share/zsh/vendor-completions/_docker -install -p -m 644 contrib/completion/fish/docker.fish $RPM_BUILD_ROOT/usr/share/fish/vendor_completions.d/docker.fish - -# install manpages -install -d %{buildroot}%{_mandir}/man1 -install -p -m 644 man/man1/*.1 $RPM_BUILD_ROOT/%{_mandir}/man1 -install -d %{buildroot}%{_mandir}/man5 -install -p -m 644 man/man5/*.5 $RPM_BUILD_ROOT/%{_mandir}/man5 -install -d %{buildroot}%{_mandir}/man8 -install -p -m 644 man/man8/*.8 $RPM_BUILD_ROOT/%{_mandir}/man8 - -# add vimfiles -install -d $RPM_BUILD_ROOT/usr/share/vim/vimfiles/doc -install -d $RPM_BUILD_ROOT/usr/share/vim/vimfiles/ftdetect -install -d $RPM_BUILD_ROOT/usr/share/vim/vimfiles/syntax -install -p -m 644 contrib/syntax/vim/doc/dockerfile.txt $RPM_BUILD_ROOT/usr/share/vim/vimfiles/doc/dockerfile.txt -install -p -m 644 contrib/syntax/vim/ftdetect/dockerfile.vim $RPM_BUILD_ROOT/usr/share/vim/vimfiles/ftdetect/dockerfile.vim -install -p -m 644 contrib/syntax/vim/syntax/dockerfile.vim $RPM_BUILD_ROOT/usr/share/vim/vimfiles/syntax/dockerfile.vim - -# add nano -install -d $RPM_BUILD_ROOT/usr/share/nano -install -p -m 644 contrib/syntax/nano/Dockerfile.nanorc $RPM_BUILD_ROOT/usr/share/nano/Dockerfile.nanorc - -# list files owned by the package here -%files -%doc AUTHORS CHANGELOG.md CONTRIBUTING.md LICENSE MAINTAINERS NOTICE README.md -/%{_bindir}/docker -/%{_bindir}/dockerd -/%{_bindir}/docker-containerd -/%{_bindir}/docker-containerd-shim -/%{_bindir}/docker-containerd-ctr -/%{_bindir}/docker-proxy -/%{_bindir}/docker-runc -/%{_bindir}/docker-init -/%{_sysconfdir}/udev/rules.d/80-docker.rules -%if 0%{?is_systemd} -/%{_unitdir}/docker.service -%else -%config(noreplace,missingok) /etc/sysconfig/docker -/%{_initddir}/docker -%endif -/usr/share/bash-completion/completions/docker -/usr/share/zsh/vendor-completions/_docker -/usr/share/fish/vendor_completions.d/docker.fish -%doc -/%{_mandir}/man1/* -/%{_mandir}/man5/* -/%{_mandir}/man8/* -/usr/share/vim/vimfiles/doc/dockerfile.txt -/usr/share/vim/vimfiles/ftdetect/dockerfile.vim -/usr/share/vim/vimfiles/syntax/dockerfile.vim -/usr/share/nano/Dockerfile.nanorc - -%post -%if 0%{?is_systemd} -%systemd_post docker -%else -# This adds the proper /etc/rc*.d links for the script -/sbin/chkconfig --add docker -%endif -if ! getent group docker > /dev/null; then - groupadd --system docker -fi - -%preun -%if 0%{?is_systemd} -%systemd_preun docker -%else -if [ $1 -eq 0 ] ; then - /sbin/service docker stop >/dev/null 2>&1 - /sbin/chkconfig --del docker -fi -%endif - -%postun -%if 0%{?is_systemd} -%systemd_postun_with_restart docker -%else -if [ "$1" -ge "1" ] ; then - /sbin/service docker condrestart >/dev/null 2>&1 || : -fi -%endif - -%changelog diff --git a/vendor/github.com/docker/docker/hack/make/.detect-daemon-osarch b/vendor/github.com/docker/docker/hack/make/.detect-daemon-osarch deleted file mode 100644 index 7395539..0000000 --- a/vendor/github.com/docker/docker/hack/make/.detect-daemon-osarch +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash -set -e - -docker-version-osarch() { - local target="$1" # "Client" or "Server" - local fmtStr="{{.${target}.Os}}/{{.${target}.Arch}}" - if docker version -f "$fmtStr" 2>/dev/null; then - # if "docker version -f" works, let's just use that! - return - fi - docker version | awk ' - $1 ~ /^(Client|Server):$/ { section = 0 } - $1 == "'"$target"':" { section = 1; next } - section && $1 == "OS/Arch:" { print $2 } - - # old versions of Docker - $1 == "OS/Arch" && $2 == "('"${target,,}"'):" { print $3 } - ' -} - -# Retrieve OS/ARCH of docker daemon, e.g. linux/amd64 -export DOCKER_ENGINE_OSARCH="$(docker-version-osarch 'Server')" -export DOCKER_ENGINE_GOOS="${DOCKER_ENGINE_OSARCH%/*}" -export DOCKER_ENGINE_GOARCH="${DOCKER_ENGINE_OSARCH##*/}" -DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:=amd64} - -# and the client, just in case -export DOCKER_CLIENT_OSARCH="$(docker-version-osarch 'Client')" -export DOCKER_CLIENT_GOOS="${DOCKER_CLIENT_OSARCH%/*}" -export DOCKER_CLIENT_GOARCH="${DOCKER_CLIENT_OSARCH##*/}" -DOCKER_CLIENT_GOARCH=${DOCKER_CLIENT_GOARCH:=amd64} - -# Retrieve the architecture used in contrib/builder/(deb|rpm)/$PACKAGE_ARCH/ -PACKAGE_ARCH='amd64' -case "${DOCKER_ENGINE_GOARCH:-$DOCKER_CLIENT_GOARCH}" in - arm) - PACKAGE_ARCH='armhf' - ;; - arm64) - PACKAGE_ARCH='aarch64' - ;; - amd64|ppc64le|s390x) - PACKAGE_ARCH="${DOCKER_ENGINE_GOARCH:-$DOCKER_CLIENT_GOARCH}" - ;; - *) - echo >&2 "warning: not sure how to convert '$DOCKER_ENGINE_GOARCH' to a 'Docker' arch, assuming '$PACKAGE_ARCH'" - ;; -esac -export PACKAGE_ARCH - -DOCKERFILE='Dockerfile' -TEST_IMAGE_NAMESPACE= -case "$PACKAGE_ARCH" in - amd64) - case "${DOCKER_ENGINE_GOOS:-$DOCKER_CLIENT_GOOS}" in - windows) - DOCKERFILE='Dockerfile.windows' - ;; - solaris) - DOCKERFILE='Dockerfile.solaris' - ;; - esac - ;; - *) - DOCKERFILE="Dockerfile.$PACKAGE_ARCH" - TEST_IMAGE_NAMESPACE="$PACKAGE_ARCH" - ;; -esac -export DOCKERFILE TEST_IMAGE_NAMESPACE diff --git a/vendor/github.com/docker/docker/hack/make/.ensure-emptyfs b/vendor/github.com/docker/docker/hack/make/.ensure-emptyfs deleted file mode 100644 index e71a30a..0000000 --- a/vendor/github.com/docker/docker/hack/make/.ensure-emptyfs +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -set -e - -if ! docker inspect emptyfs &> /dev/null; then - # let's build a "docker save" tarball for "emptyfs" - # see https://github.com/docker/docker/pull/5262 - # and also https://github.com/docker/docker/issues/4242 - dir="$DEST/emptyfs" - mkdir -p "$dir" - ( - cd "$dir" - echo '{"emptyfs":{"latest":"511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158"}}' > repositories - mkdir -p 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158 - ( - cd 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158 - echo '{"id":"511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158","comment":"Imported from -","created":"2013-06-13T14:03:50.821769-07:00","container_config":{"Hostname":"","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"PortSpecs":null,"ExposedPorts":null,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":null,"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"OnBuild":null},"docker_version":"0.4.0","architecture":"x86_64","Size":0}' > json - echo '1.0' > VERSION - tar -cf layer.tar --files-from /dev/null - ) - ) - ( set -x; tar -cC "$dir" . | docker load ) - rm -rf "$dir" -fi diff --git a/vendor/github.com/docker/docker/hack/make/.go-autogen b/vendor/github.com/docker/docker/hack/make/.go-autogen deleted file mode 100644 index 4d26052..0000000 --- a/vendor/github.com/docker/docker/hack/make/.go-autogen +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash - -rm -rf autogen - -source hack/dockerfile/binaries-commits - -cat > dockerversion/version_autogen.go < dockerversion/version_autogen_unix.go < - -param( - [Parameter(Mandatory=$true)][string]$CommitString, - [Parameter(Mandatory=$true)][string]$DockerVersion -) - -$ErrorActionPreference = "Stop" - -# Utility function to get the build date/time in UTC -Function Get-BuildDateTime() { - return $(Get-Date).ToUniversalTime() -} - -try { - $buildDateTime=Get-BuildDateTime - - if (Test-Path ".\autogen") { - Remove-Item ".\autogen" -Recurse -Force | Out-Null - } - - $fileContents = ' -// +build autogen - -// Package dockerversion is auto-generated at build-time -package dockerversion - -// Default build-time variable for library-import. -// This file is overridden on build with build-time informations. -const ( - GitCommit string = "'+$CommitString+'" - Version string = "'+$DockerVersion+'" - BuildTime string = "'+$buildDateTime+'" -) - -// AUTOGENERATED FILE; see hack\make\.go-autogen.ps1 -' - - # Write the file without BOM - $outputFile="$(pwd)\dockerversion\version_autogen.go" - if (Test-Path $outputFile) { Remove-Item $outputFile } - [System.IO.File]::WriteAllText($outputFile, $fileContents, (New-Object System.Text.UTF8Encoding($False))) - - New-Item -ItemType Directory -Path "autogen\winresources\tmp" | Out-Null - New-Item -ItemType Directory -Path "autogen\winresources\docker" | Out-Null - New-Item -ItemType Directory -Path "autogen\winresources\dockerd" | Out-Null - Copy-Item "hack\make\.resources-windows\resources.go" "autogen\winresources\docker" - Copy-Item "hack\make\.resources-windows\resources.go" "autogen\winresources\dockerd" - - # Generate a version in the form major,minor,patch,build - $versionQuad=$DockerVersion -replace "[^0-9.]*" -replace "\.", "," - - # Compile the messages - windmc hack\make\.resources-windows\event_messages.mc -h autogen\winresources\tmp -r autogen\winresources\tmp - if ($LASTEXITCODE -ne 0) { Throw "Failed to compile event message resources" } - - # If you really want to understand this madness below, search the Internet for powershell variables after verbatim arguments... Needed to get double-quotes passed through to the compiler options. - # Generate the .syso files containing all the resources and manifest needed to compile the final docker binaries. Both 32 and 64-bit clients. - $env:_ag_dockerVersion=$DockerVersion - $env:_ag_gitCommit=$CommitString - - windres -i hack/make/.resources-windows/docker.rc -o autogen/winresources/docker/rsrc_amd64.syso -F pe-x86-64 --use-temp-file -I autogen/winresources/tmp -D DOCKER_VERSION_QUAD=$versionQuad --% -D DOCKER_VERSION=\"%_ag_dockerVersion%\" -D DOCKER_COMMIT=\"%_ag_gitCommit%\" - if ($LASTEXITCODE -ne 0) { Throw "Failed to compile client 64-bit resources" } - - windres -i hack/make/.resources-windows/docker.rc -o autogen/winresources/docker/rsrc_386.syso -F pe-i386 --use-temp-file -I autogen/winresources/tmp -D DOCKER_VERSION_QUAD=$versionQuad --% -D DOCKER_VERSION=\"%_ag_dockerVersion%\" -D DOCKER_COMMIT=\"%_ag_gitCommit%\" - if ($LASTEXITCODE -ne 0) { Throw "Failed to compile client 32-bit resources" } - - windres -i hack/make/.resources-windows/dockerd.rc -o autogen/winresources/dockerd/rsrc_amd64.syso -F pe-x86-64 --use-temp-file -I autogen/winresources/tmp -D DOCKER_VERSION_QUAD=$versionQuad --% -D DOCKER_VERSION=\"%_ag_dockerVersion%\" -D DOCKER_COMMIT=\"%_ag_gitCommit%\" - if ($LASTEXITCODE -ne 0) { Throw "Failed to compile daemon resources" } -} -Catch [Exception] { - # Throw the error onto the caller to display errors. We don't expect this script to be called directly - Throw ".go-autogen.ps1 failed with error $_" -} -Finally { - Remove-Item .\autogen\winresources\tmp -Recurse -Force -ErrorAction SilentlyContinue | Out-Null - $env:_ag_dockerVersion="" - $env:_ag_gitCommit="" -} diff --git a/vendor/github.com/docker/docker/hack/make/.integration-daemon-setup b/vendor/github.com/docker/docker/hack/make/.integration-daemon-setup deleted file mode 100644 index 0efde71..0000000 --- a/vendor/github.com/docker/docker/hack/make/.integration-daemon-setup +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -e - -bundle .detect-daemon-osarch -if [ $DOCKER_ENGINE_GOOS != "windows" ]; then - bundle .ensure-emptyfs -fi diff --git a/vendor/github.com/docker/docker/hack/make/.integration-daemon-start b/vendor/github.com/docker/docker/hack/make/.integration-daemon-start deleted file mode 100644 index b96979b..0000000 --- a/vendor/github.com/docker/docker/hack/make/.integration-daemon-start +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash - -# see test-integration-cli for example usage of this script - -base="$ABS_DEST/.." -export PATH="$base/binary-client:$base/binary-daemon:$base/dynbinary-client:$base/dynbinary-daemon:$PATH" - -if ! command -v docker &> /dev/null; then - echo >&2 'error: binary-client or dynbinary-client must be run before .integration-daemon-start' - false -fi - -# This is a temporary hack for split-binary mode. It can be removed once -# https://github.com/docker/docker/pull/22134 is merged into docker master -if [ "$(go env GOOS)" = 'windows' ]; then - return -fi - -if [ -z "$DOCKER_TEST_HOST" ]; then - if docker version &> /dev/null; then - echo >&2 'skipping daemon start, since daemon appears to be already started' - return - fi -fi - -if ! command -v dockerd &> /dev/null; then - echo >&2 'error: binary-daemon or dynbinary-daemon must be run before .integration-daemon-start' - false -fi - -# intentionally open a couple bogus file descriptors to help test that they get scrubbed in containers -exec 41>&1 42>&2 - -export DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs} -export DOCKER_USERLANDPROXY=${DOCKER_USERLANDPROXY:-true} - -# example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G" -storage_params="" -if [ -n "$DOCKER_STORAGE_OPTS" ]; then - IFS=',' - for i in ${DOCKER_STORAGE_OPTS}; do - storage_params="--storage-opt $i $storage_params" - done - unset IFS -fi - -# example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G" -extra_params="" -if [ "$DOCKER_REMAP_ROOT" ]; then - extra_params="--userns-remap $DOCKER_REMAP_ROOT" -fi - -if [ "$DOCKER_EXPERIMENTAL" ]; then - echo >&2 '# DOCKER_EXPERIMENTAL is set: starting daemon with experimental features enabled! ' - extra_params="$extra_params --experimental" -fi - -if [ -z "$DOCKER_TEST_HOST" ]; then - # Start apparmor if it is enabled - if [ -e "/sys/module/apparmor/parameters/enabled" ] && [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then - # reset container variable so apparmor profile is applied to process - # see https://github.com/docker/libcontainer/blob/master/apparmor/apparmor.go#L16 - export container="" - ( - set -x - /etc/init.d/apparmor start - ) - fi - - export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" # "pwd" tricks to make sure $DEST is an absolute path, not a relative one - ( set -x; exec \ - dockerd --debug \ - --host "$DOCKER_HOST" \ - --storage-driver "$DOCKER_GRAPHDRIVER" \ - --pidfile "$DEST/docker.pid" \ - --userland-proxy="$DOCKER_USERLANDPROXY" \ - $storage_params \ - $extra_params \ - &> "$DEST/docker.log" - ) & - # make sure that if the script exits unexpectedly, we stop this daemon we just started - trap 'bundle .integration-daemon-stop' EXIT -else - export DOCKER_HOST="$DOCKER_TEST_HOST" -fi - -# give it a little time to come up so it's "ready" -tries=60 -echo "INFO: Waiting for daemon to start..." -while ! docker version &> /dev/null; do - (( tries-- )) - if [ $tries -le 0 ]; then - printf "\n" - if [ -z "$DOCKER_HOST" ]; then - echo >&2 "error: daemon failed to start" - echo >&2 " check $DEST/docker.log for details" - else - echo >&2 "error: daemon at $DOCKER_HOST fails to 'docker version':" - docker version >&2 || true - # Additional Windows CI debugging as this is a common error as of - # January 2016 - if [ "$(go env GOOS)" = 'windows' ]; then - echo >&2 "Container log below:" - echo >&2 "---" - # Important - use the docker on the CI host, not the one built locally - # which is currently in our path. - ! /c/bin/docker -H=$MAIN_DOCKER_HOST logs docker-$COMMITHASH - echo >&2 "---" - fi - fi - false - fi - printf "." - sleep 2 -done -printf "\n" diff --git a/vendor/github.com/docker/docker/hack/make/.integration-daemon-stop b/vendor/github.com/docker/docker/hack/make/.integration-daemon-stop deleted file mode 100644 index 03c1b14..0000000 --- a/vendor/github.com/docker/docker/hack/make/.integration-daemon-stop +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -if [ ! "$(go env GOOS)" = 'windows' ]; then - trap - EXIT # reset EXIT trap applied in .integration-daemon-start - - for pidFile in $(find "$DEST" -name docker.pid); do - pid=$(set -x; cat "$pidFile") - ( set -x; kill "$pid" ) - if ! wait "$pid"; then - echo >&2 "warning: PID $pid from $pidFile had a nonzero exit code" - fi - done - - if [ -z "$DOCKER_TEST_HOST" ]; then - # Stop apparmor if it is enabled - if [ -e "/sys/module/apparmor/parameters/enabled" ] && [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then - ( - set -x - /etc/init.d/apparmor stop - ) - fi - fi -else - # Note this script is not actionable on Windows to Linux CI. Instead the - # DIND daemon under test is torn down by the Jenkins tear-down script - echo "INFO: Not stopping daemon on Windows CI" -fi diff --git a/vendor/github.com/docker/docker/hack/make/.integration-test-helpers b/vendor/github.com/docker/docker/hack/make/.integration-test-helpers deleted file mode 100644 index 7b73b2f..0000000 --- a/vendor/github.com/docker/docker/hack/make/.integration-test-helpers +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash - -: ${TEST_REPEAT:=0} - -bundle_test_integration_cli() { - TESTFLAGS="$TESTFLAGS -check.v -check.timeout=${TIMEOUT} -test.timeout=360m" - go_test_dir integration-cli $DOCKER_INTEGRATION_TESTS_VERIFIED -} - -# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. -# You can use this to select certain tests to run, e.g. -# -# TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit -# -# For integration-cli test, we use [gocheck](https://labix.org/gocheck), if you want -# to run certain tests on your local host, you should run with command: -# -# TESTFLAGS='-check.f DockerSuite.TestBuild*' ./hack/make.sh binary test-integration-cli -# -go_test_dir() { - dir=$1 - precompiled=$2 - testbinary="$DEST/test.main" - testcover=() - testcoverprofile=() - ( - mkdir -p "$DEST/coverprofiles" - export DEST="$ABS_DEST" # in a subshell this is safe -- our integration-cli tests need DEST, and "cd" screws it up - if [ -z $precompiled ]; then - ensure_test_dir $1 $testbinary - fi - cd "$dir" - i=0 - while ((++i)); do - test_env "$testbinary" $TESTFLAGS - if [ $i -gt "$TEST_REPEAT" ]; then - break - fi - echo "Repeating test ($i)" - done - ) -} - -ensure_test_dir() { - ( - # make sure a test dir will compile - dir="$1" - out="$2" - echo Building test dir: "$dir" - set -xe - cd "$dir" - go test -c -o "$out" -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" - ) -} - -test_env() { - ( - set -xe - # use "env -i" to tightly control the environment variables that bleed into the tests - env -i \ - DEST="$DEST" \ - DOCKER_TLS_VERIFY="$DOCKER_TEST_TLS_VERIFY" \ - DOCKER_CERT_PATH="$DOCKER_TEST_CERT_PATH" \ - DOCKER_ENGINE_GOARCH="$DOCKER_ENGINE_GOARCH" \ - DOCKER_GRAPHDRIVER="$DOCKER_GRAPHDRIVER" \ - DOCKER_USERLANDPROXY="$DOCKER_USERLANDPROXY" \ - DOCKER_HOST="$DOCKER_HOST" \ - DOCKER_REMAP_ROOT="$DOCKER_REMAP_ROOT" \ - DOCKER_REMOTE_DAEMON="$DOCKER_REMOTE_DAEMON" \ - DOCKERFILE="$DOCKERFILE" \ - GOPATH="$GOPATH" \ - GOTRACEBACK=all \ - HOME="$ABS_DEST/fake-HOME" \ - PATH="$PATH" \ - TEMP="$TEMP" \ - TEST_IMAGE_NAMESPACE="$TEST_IMAGE_NAMESPACE" \ - "$@" - ) -} diff --git a/vendor/github.com/docker/docker/hack/make/.resources-windows/common.rc b/vendor/github.com/docker/docker/hack/make/.resources-windows/common.rc deleted file mode 100644 index 000fb35..0000000 --- a/vendor/github.com/docker/docker/hack/make/.resources-windows/common.rc +++ /dev/null @@ -1,38 +0,0 @@ -// Application icon -1 ICON "docker.ico" - -// Windows executable manifest -1 24 /* RT_MANIFEST */ "docker.exe.manifest" - -// Version information -1 VERSIONINFO - -#ifdef DOCKER_VERSION_QUAD -FILEVERSION DOCKER_VERSION_QUAD -PRODUCTVERSION DOCKER_VERSION_QUAD -#endif - -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004B0" - BEGIN - VALUE "ProductName", DOCKER_NAME - -#ifdef DOCKER_VERSION - VALUE "FileVersion", DOCKER_VERSION - VALUE "ProductVersion", DOCKER_VERSION -#endif - -#ifdef DOCKER_COMMIT - VALUE "OriginalFileName", DOCKER_COMMIT -#endif - - END - END - - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0000, 0x04B0 - END -END diff --git a/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.exe.manifest b/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.exe.manifest deleted file mode 100644 index 674bc94..0000000 --- a/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.exe.manifest +++ /dev/null @@ -1,18 +0,0 @@ - - - Docker - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.ico b/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.ico deleted file mode 100644 index c6506ec..0000000 Binary files a/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.ico and /dev/null differ diff --git a/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.png b/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.png deleted file mode 100644 index 88df0b6..0000000 Binary files a/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.png and /dev/null differ diff --git a/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.rc b/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.rc deleted file mode 100644 index 40c645a..0000000 --- a/vendor/github.com/docker/docker/hack/make/.resources-windows/docker.rc +++ /dev/null @@ -1,3 +0,0 @@ -#define DOCKER_NAME "Docker Client" - -#include "common.rc" diff --git a/vendor/github.com/docker/docker/hack/make/.resources-windows/dockerd.rc b/vendor/github.com/docker/docker/hack/make/.resources-windows/dockerd.rc deleted file mode 100644 index e77fc17..0000000 --- a/vendor/github.com/docker/docker/hack/make/.resources-windows/dockerd.rc +++ /dev/null @@ -1,4 +0,0 @@ -#define DOCKER_NAME "Docker Engine" - -#include "common.rc" -#include "event_messages.rc" diff --git a/vendor/github.com/docker/docker/hack/make/.resources-windows/event_messages.mc b/vendor/github.com/docker/docker/hack/make/.resources-windows/event_messages.mc deleted file mode 100644 index 980107a..0000000 --- a/vendor/github.com/docker/docker/hack/make/.resources-windows/event_messages.mc +++ /dev/null @@ -1,39 +0,0 @@ -MessageId=1 -Language=English -%1 -. - -MessageId=2 -Language=English -debug: %1 -. - -MessageId=3 -Language=English -panic: %1 -. - -MessageId=4 -Language=English -fatal: %1 -. - -MessageId=11 -Language=English -%1 [%2] -. - -MessageId=12 -Language=English -debug: %1 [%2] -. - -MessageId=13 -Language=English -panic: %1 [%2] -. - -MessageId=14 -Language=English -fatal: %1 [%2] -. diff --git a/vendor/github.com/docker/docker/hack/make/.resources-windows/resources.go b/vendor/github.com/docker/docker/hack/make/.resources-windows/resources.go deleted file mode 100644 index b171259..0000000 --- a/vendor/github.com/docker/docker/hack/make/.resources-windows/resources.go +++ /dev/null @@ -1,18 +0,0 @@ -/* - -Package winresources is used to embed Windows resources into docker.exe. -These resources are used to provide - - * Version information - * An icon - * A Windows manifest declaring Windows version support - -The resource object files are generated in hack/make/.go-autogen from -source files in hack/make/.resources-windows. This occurs automatically -when you run hack/make.sh. - -These object files are picked up automatically by go build when this package -is included. - -*/ -package winresources diff --git a/vendor/github.com/docker/docker/hack/make/README.md b/vendor/github.com/docker/docker/hack/make/README.md deleted file mode 100644 index 6574b0e..0000000 --- a/vendor/github.com/docker/docker/hack/make/README.md +++ /dev/null @@ -1,17 +0,0 @@ -This directory holds scripts called by `make.sh` in the parent directory. - -Each script is named after the bundle it creates. -They should not be called directly - instead, pass it as argument to make.sh, for example: - -``` -./hack/make.sh test -./hack/make.sh binary ubuntu - -# Or to run all bundles: -./hack/make.sh -``` - -To add a bundle: - -* Create a shell-compatible file here -* Add it to $DEFAULT_BUNDLES in make.sh diff --git a/vendor/github.com/docker/docker/hack/make/binary b/vendor/github.com/docker/docker/hack/make/binary deleted file mode 100644 index 88b22cd..0000000 --- a/vendor/github.com/docker/docker/hack/make/binary +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -e -rm -rf "$DEST" - -# This script exists as backwards compatibility for CI -( - DEST="${DEST}-client" - ABS_DEST="${ABS_DEST}-client" - . hack/make/binary-client -) -( - DEST="${DEST}-daemon" - ABS_DEST="${ABS_DEST}-daemon" - . hack/make/binary-daemon -) diff --git a/vendor/github.com/docker/docker/hack/make/binary-client b/vendor/github.com/docker/docker/hack/make/binary-client deleted file mode 100644 index 1731fea..0000000 --- a/vendor/github.com/docker/docker/hack/make/binary-client +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -e - -[ -z "$KEEPDEST" ] && \ - rm -rf "$DEST" - -( - source "${MAKEDIR}/.binary-setup" - export BINARY_SHORT_NAME="$DOCKER_CLIENT_BINARY_NAME" - export GO_PACKAGE='github.com/docker/docker/cmd/docker' - source "${MAKEDIR}/.binary" -) diff --git a/vendor/github.com/docker/docker/hack/make/binary-daemon b/vendor/github.com/docker/docker/hack/make/binary-daemon deleted file mode 100644 index e255543..0000000 --- a/vendor/github.com/docker/docker/hack/make/binary-daemon +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -e - -[ -z "$KEEPDEST" ] && \ - rm -rf "$DEST" - -( - source "${MAKEDIR}/.binary-setup" - export BINARY_SHORT_NAME="$DOCKER_DAEMON_BINARY_NAME" - export GO_PACKAGE='github.com/docker/docker/cmd/dockerd' - source "${MAKEDIR}/.binary" - copy_binaries "$DEST" 'hash' -) diff --git a/vendor/github.com/docker/docker/hack/make/build-deb b/vendor/github.com/docker/docker/hack/make/build-deb deleted file mode 100644 index d3c2859..0000000 --- a/vendor/github.com/docker/docker/hack/make/build-deb +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/bash -set -e - -# subshell so that we can export PATH and TZ without breaking other things -( - export TZ=UTC # make sure our "date" variables are UTC-based - bundle .integration-daemon-start - bundle .detect-daemon-osarch - - # TODO consider using frozen images for the dockercore/builder-deb tags - - tilde='~' # ouch Bash 4.2 vs 4.3, you keel me - debVersion="${VERSION//-/$tilde}" # using \~ or '~' here works in 4.3, but not 4.2; just ~ causes $HOME to be inserted, hence the $tilde - # if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better - if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then - gitUnix="$(git log -1 --pretty='%at')" - gitDate="$(date --date "@$gitUnix" +'%Y%m%d.%H%M%S')" - gitCommit="$(git log -1 --pretty='%h')" - gitVersion="git${gitDate}.0.${gitCommit}" - # gitVersion is now something like 'git20150128.112847.0.17e840a' - debVersion="$debVersion~$gitVersion" - - # $ dpkg --compare-versions 1.5.0 gt 1.5.0~rc1 && echo true || echo false - # true - # $ dpkg --compare-versions 1.5.0~rc1 gt 1.5.0~git20150128.112847.17e840a && echo true || echo false - # true - # $ dpkg --compare-versions 1.5.0~git20150128.112847.17e840a gt 1.5.0~dev~git20150128.112847.17e840a && echo true || echo false - # true - - # ie, 1.5.0 > 1.5.0~rc1 > 1.5.0~git20150128.112847.17e840a > 1.5.0~dev~git20150128.112847.17e840a - fi - - debSource="$(awk -F ': ' '$1 == "Source" { print $2; exit }' hack/make/.build-deb/control)" - debMaintainer="$(awk -F ': ' '$1 == "Maintainer" { print $2; exit }' hack/make/.build-deb/control)" - debDate="$(date --rfc-2822)" - - # if go-md2man is available, pre-generate the man pages - make manpages - - builderDir="contrib/builder/deb/${PACKAGE_ARCH}" - pkgs=( $(find "${builderDir}/"*/ -type d) ) - if [ ! -z "$DOCKER_BUILD_PKGS" ]; then - pkgs=() - for p in $DOCKER_BUILD_PKGS; do - pkgs+=( "$builderDir/$p" ) - done - fi - for dir in "${pkgs[@]}"; do - [ -d "$dir" ] || { echo >&2 "skipping nonexistent $dir"; continue; } - version="$(basename "$dir")" - suite="${version##*-}" - - image="dockercore/builder-deb:$version" - if ! docker inspect "$image" &> /dev/null; then - ( - # Add the APT_MIRROR args only if the consuming Dockerfile uses it - # Otherwise this will cause the build to fail - if [ "$(grep 'ARG APT_MIRROR=' $dir/Dockerfile)" ] && [ "$BUILD_APT_MIRROR" ]; then - DOCKER_BUILD_ARGS="$DOCKER_BUILD_ARGS $BUILD_APT_MIRROR" - fi - set -x && docker build ${DOCKER_BUILD_ARGS} -t "$image" "$dir" - ) - fi - - mkdir -p "$DEST/$version" - cat > "$DEST/$version/Dockerfile.build" <<-EOF - FROM $image - WORKDIR /usr/src/docker - COPY . /usr/src/docker - ENV DOCKER_GITCOMMIT $GITCOMMIT - RUN mkdir -p /go/src/github.com/docker && mkdir -p /go/src/github.com/opencontainers \ - && ln -snf /usr/src/docker /go/src/github.com/docker/docker - EOF - - cat >> "$DEST/$version/Dockerfile.build" <<-EOF - # Install runc, containerd, proxy and tini - RUN ./hack/dockerfile/install-binaries.sh runc-dynamic containerd-dynamic proxy-dynamic tini - EOF - cat >> "$DEST/$version/Dockerfile.build" <<-EOF - RUN cp -aL hack/make/.build-deb debian - RUN { echo '$debSource (${debVersion}-0~${version}) $suite; urgency=low'; echo; echo ' * Version: $VERSION'; echo; echo " -- $debMaintainer $debDate"; } > debian/changelog && cat >&2 debian/changelog - RUN dpkg-buildpackage -uc -us -I.git - EOF - tempImage="docker-temp/build-deb:$version" - ( set -x && docker build -t "$tempImage" -f "$DEST/$version/Dockerfile.build" . ) - docker run --rm "$tempImage" bash -c 'cd .. && tar -c *_*' | tar -xvC "$DEST/$version" - docker rmi "$tempImage" - done - - bundle .integration-daemon-stop -) 2>&1 | tee -a "$DEST/test.log" diff --git a/vendor/github.com/docker/docker/hack/make/build-integration-test-binary b/vendor/github.com/docker/docker/hack/make/build-integration-test-binary deleted file mode 100644 index 2039be4..0000000 --- a/vendor/github.com/docker/docker/hack/make/build-integration-test-binary +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e - -rm -rf "$DEST" -DEST="$DEST/../test-integration-cli" - -if [ -z $DOCKER_INTEGRATION_TESTS_VERIFIED ]; then - source ${MAKEDIR}/.integration-test-helpers - ensure_test_dir integration-cli "$DEST/test.main" - export DOCKER_INTEGRATION_TESTS_VERIFIED=1 -fi diff --git a/vendor/github.com/docker/docker/hack/make/build-rpm b/vendor/github.com/docker/docker/hack/make/build-rpm deleted file mode 100644 index 7fec059..0000000 --- a/vendor/github.com/docker/docker/hack/make/build-rpm +++ /dev/null @@ -1,148 +0,0 @@ -#!/bin/bash -set -e - -# subshell so that we can export PATH and TZ without breaking other things -( - export TZ=UTC # make sure our "date" variables are UTC-based - - source "$(dirname "$BASH_SOURCE")/.integration-daemon-start" - source "$(dirname "$BASH_SOURCE")/.detect-daemon-osarch" - - # TODO consider using frozen images for the dockercore/builder-rpm tags - - rpmName=docker-engine - rpmVersion="$VERSION" - rpmRelease=1 - - # rpmRelease versioning is as follows - # Docker 1.7.0: version=1.7.0, release=1 - # Docker 1.7.0-rc1: version=1.7.0, release=0.1.rc1 - # Docker 1.7.0-cs1: version=1.7.0.cs1, release=1 - # Docker 1.7.0-cs1-rc1: version=1.7.0.cs1, release=0.1.rc1 - # Docker 1.7.0-dev nightly: version=1.7.0, release=0.0.YYYYMMDD.HHMMSS.gitHASH - - # if we have a "-rc*" suffix, set appropriate release - if [[ "$rpmVersion" =~ .*-rc[0-9]+$ ]] ; then - rcVersion=${rpmVersion#*-rc} - rpmVersion=${rpmVersion%-rc*} - rpmRelease="0.${rcVersion}.rc${rcVersion}" - fi - - DOCKER_GITCOMMIT=$(git rev-parse --short HEAD) - if [ -n "$(git status --porcelain --untracked-files=no)" ]; then - DOCKER_GITCOMMIT="$DOCKER_GITCOMMIT-unsupported" - fi - - # if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better - if [[ "$rpmVersion" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then - gitUnix="$(git log -1 --pretty='%at')" - gitDate="$(date --date "@$gitUnix" +'%Y%m%d.%H%M%S')" - gitCommit="$(git log -1 --pretty='%h')" - gitVersion="${gitDate}.git${gitCommit}" - # gitVersion is now something like '20150128.112847.17e840a' - rpmVersion="${rpmVersion%-dev}" - rpmRelease="0.0.$gitVersion" - fi - - # Replace any other dashes with periods - rpmVersion="${rpmVersion/-/.}" - - rpmPackager="$(awk -F ': ' '$1 == "Packager" { print $2; exit }' hack/make/.build-rpm/${rpmName}.spec)" - rpmDate="$(date +'%a %b %d %Y')" - - # if go-md2man is available, pre-generate the man pages - make manpages - - # Convert the CHANGELOG.md file into RPM changelog format - VERSION_REGEX="^\W\W (.*) \((.*)\)$" - ENTRY_REGEX="^[-+*] (.*)$" - while read -r line || [[ -n "$line" ]]; do - if [ -z "$line" ]; then continue; fi - if [[ "$line" =~ $VERSION_REGEX ]]; then - echo >> contrib/builder/rpm/${PACKAGE_ARCH}/changelog - echo "* `date -d ${BASH_REMATCH[2]} '+%a %b %d %Y'` ${rpmPackager} - ${BASH_REMATCH[1]}" >> contrib/builder/rpm/${PACKAGE_ARCH}/changelog - fi - if [[ "$line" =~ $ENTRY_REGEX ]]; then - echo "- ${BASH_REMATCH[1]//\`}" >> contrib/builder/rpm/${PACKAGE_ARCH}/changelog - fi - done < CHANGELOG.md - - builderDir="contrib/builder/rpm/${PACKAGE_ARCH}" - pkgs=( $(find "${builderDir}/"*/ -type d) ) - if [ ! -z "$DOCKER_BUILD_PKGS" ]; then - pkgs=() - for p in $DOCKER_BUILD_PKGS; do - pkgs+=( "$builderDir/$p" ) - done - fi - for dir in "${pkgs[@]}"; do - [ -d "$dir" ] || { echo >&2 "skipping nonexistent $dir"; continue; } - version="$(basename "$dir")" - suite="${version##*-}" - - image="dockercore/builder-rpm:$version" - if ! docker inspect "$image" &> /dev/null; then - ( set -x && docker build ${DOCKER_BUILD_ARGS} -t "$image" "$dir" ) - fi - - mkdir -p "$DEST/$version" - cat > "$DEST/$version/Dockerfile.build" <<-EOF - FROM $image - COPY . /usr/src/${rpmName} - WORKDIR /usr/src/${rpmName} - RUN mkdir -p /go/src/github.com/docker && mkdir -p /go/src/github.com/opencontainers - EOF - - cat >> "$DEST/$version/Dockerfile.build" <<-EOF - # Install runc, containerd, proxy and tini - RUN TMP_GOPATH="/go" ./hack/dockerfile/install-binaries.sh runc-dynamic containerd-dynamic proxy-dynamic tini - EOF - if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then - echo 'ENV DOCKER_EXPERIMENTAL 1' >> "$DEST/$version/Dockerfile.build" - fi - cat >> "$DEST/$version/Dockerfile.build" <<-EOF - RUN mkdir -p /root/rpmbuild/SOURCES \ - && echo '%_topdir /root/rpmbuild' > /root/.rpmmacros - WORKDIR /root/rpmbuild - RUN ln -sfv /usr/src/${rpmName}/hack/make/.build-rpm SPECS - WORKDIR /root/rpmbuild/SPECS - RUN tar --exclude .git -r -C /usr/src -f /root/rpmbuild/SOURCES/${rpmName}.tar ${rpmName} - RUN tar --exclude .git -r -C /go/src/github.com/docker -f /root/rpmbuild/SOURCES/${rpmName}.tar containerd - RUN tar --exclude .git -r -C /go/src/github.com/docker/libnetwork/cmd -f /root/rpmbuild/SOURCES/${rpmName}.tar proxy - RUN tar --exclude .git -r -C /go/src/github.com/opencontainers -f /root/rpmbuild/SOURCES/${rpmName}.tar runc - RUN tar --exclude .git -r -C /go/ -f /root/rpmbuild/SOURCES/${rpmName}.tar tini - RUN gzip /root/rpmbuild/SOURCES/${rpmName}.tar - RUN { cat /usr/src/${rpmName}/contrib/builder/rpm/${PACKAGE_ARCH}/changelog; } >> ${rpmName}.spec && tail >&2 ${rpmName}.spec - RUN rpmbuild -ba \ - --define '_gitcommit $DOCKER_GITCOMMIT' \ - --define '_release $rpmRelease' \ - --define '_version $rpmVersion' \ - --define '_origversion $VERSION' \ - --define '_experimental ${DOCKER_EXPERIMENTAL:-0}' \ - ${rpmName}.spec - EOF - # selinux policy referencing systemd things won't work on non-systemd versions - # of centos or rhel, which we don't support anyways - if [ "${suite%.*}" -gt 6 ] && [[ "$version" != opensuse* ]]; then - selinuxDir="selinux" - if [ -d "./contrib/selinux-$version" ]; then - selinuxDir="selinux-${version}" - fi - cat >> "$DEST/$version/Dockerfile.build" <<-EOF - RUN tar -cz -C /usr/src/${rpmName}/contrib/${selinuxDir} -f /root/rpmbuild/SOURCES/${rpmName}-selinux.tar.gz ${rpmName}-selinux - RUN rpmbuild -ba \ - --define '_gitcommit $DOCKER_GITCOMMIT' \ - --define '_release $rpmRelease' \ - --define '_version $rpmVersion' \ - --define '_origversion $VERSION' \ - ${rpmName}-selinux.spec - EOF - fi - tempImage="docker-temp/build-rpm:$version" - ( set -x && docker build -t "$tempImage" -f $DEST/$version/Dockerfile.build . ) - docker run --rm "$tempImage" bash -c 'cd /root/rpmbuild && tar -c *RPMS' | tar -xvC "$DEST/$version" - docker rmi "$tempImage" - done - - source "$(dirname "$BASH_SOURCE")/.integration-daemon-stop" -) 2>&1 | tee -a $DEST/test.log diff --git a/vendor/github.com/docker/docker/hack/make/clean-apt-repo b/vendor/github.com/docker/docker/hack/make/clean-apt-repo deleted file mode 100755 index 1c37d98..0000000 --- a/vendor/github.com/docker/docker/hack/make/clean-apt-repo +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -e - -# This script cleans the experimental pool for the apt repo. -# This is useful when there are a lot of old experimental debs and you only want to keep the most recent. -# - -: ${DOCKER_RELEASE_DIR:=$DEST} -APTDIR=$DOCKER_RELEASE_DIR/apt/repo/pool/experimental -: ${DOCKER_ARCHIVE_DIR:=$DEST/archive} -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -latest_versions=$(dpkg-scanpackages "$APTDIR" /dev/null 2>/dev/null | awk -F ': ' '$1 == "Filename" { print $2 }') - -# get the latest version -latest_docker_engine_file=$(echo "$latest_versions" | grep docker-engine) -latest_docker_engine_version=$(basename ${latest_docker_engine_file%~*}) - -echo "latest docker-engine version: $latest_docker_engine_version" - -# remove all the files that are not that version in experimental -pool_dir=$(dirname "$latest_docker_engine_file") -old_pkgs=( $(ls "$pool_dir" | grep -v "^${latest_docker_engine_version}" | grep "${latest_docker_engine_version%%~git*}") ) - -echo "${old_pkgs[@]}" - -mkdir -p "$DOCKER_ARCHIVE_DIR" -for old_pkg in "${old_pkgs[@]}"; do - echo "moving ${pool_dir}/${old_pkg} to $DOCKER_ARCHIVE_DIR" - mv "${pool_dir}/${old_pkg}" "$DOCKER_ARCHIVE_DIR" -done - -echo -echo "$pool_dir now has contents:" -ls "$pool_dir" - -# now regenerate release files for experimental -export COMPONENT=experimental -source "${DIR}/update-apt-repo" - -echo "You will now want to: " -echo " - re-sign the repo with hack/make/sign-repo" -echo " - re-generate index files with hack/make/generate-index-listing" diff --git a/vendor/github.com/docker/docker/hack/make/clean-yum-repo b/vendor/github.com/docker/docker/hack/make/clean-yum-repo deleted file mode 100755 index 1cafbbd..0000000 --- a/vendor/github.com/docker/docker/hack/make/clean-yum-repo +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -set -e - -# This script cleans the experimental pool for the yum repo. -# This is useful when there are a lot of old experimental rpms and you only want to keep the most recent. -# - -: ${DOCKER_RELEASE_DIR:=$DEST} -YUMDIR=$DOCKER_RELEASE_DIR/yum/repo/experimental - -suites=( $(find "$YUMDIR" -mindepth 1 -maxdepth 1 -type d) ) - -for suite in "${suites[@]}"; do - echo "cleanup in: $suite" - ( set -x; repomanage -k2 --old "$suite" | xargs rm -f ) -done - -echo "You will now want to: " -echo " - re-sign the repo with hack/make/sign-repo" -echo " - re-generate index files with hack/make/generate-index-listing" diff --git a/vendor/github.com/docker/docker/hack/make/cover b/vendor/github.com/docker/docker/hack/make/cover deleted file mode 100644 index 08e28e3..0000000 --- a/vendor/github.com/docker/docker/hack/make/cover +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -e - -bundle_cover() { - coverprofiles=( "$DEST/../"*"/coverprofiles/"* ) - for p in "${coverprofiles[@]}"; do - echo - ( - set -x - go tool cover -func="$p" - ) - done -} - -bundle_cover 2>&1 | tee "$DEST/report.log" diff --git a/vendor/github.com/docker/docker/hack/make/cross b/vendor/github.com/docker/docker/hack/make/cross deleted file mode 100644 index 6d672b1..0000000 --- a/vendor/github.com/docker/docker/hack/make/cross +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -set -e - -# explicit list of os/arch combos that support being a daemon -declare -A daemonSupporting -daemonSupporting=( - [linux/amd64]=1 - [windows/amd64]=1 -) - -# if we have our linux/amd64 version compiled, let's symlink it in -if [ -x "$DEST/../binary-daemon/dockerd-$VERSION" ]; then - arch=$(go env GOHOSTARCH) - mkdir -p "$DEST/linux/${arch}" - ( - cd "$DEST/linux/${arch}" - ln -s ../../../binary-daemon/* ./ - ln -s ../../../binary-client/* ./ - ) - echo "Created symlinks:" "$DEST/linux/${arch}/"* -fi - -for platform in $DOCKER_CROSSPLATFORMS; do - ( - export KEEPDEST=1 - export DEST="$DEST/$platform" # bundles/VERSION/cross/GOOS/GOARCH/docker-VERSION - mkdir -p "$DEST" - ABS_DEST="$(cd "$DEST" && pwd -P)" - export GOOS=${platform%/*} - export GOARCH=${platform##*/} - - if [ "$GOOS" != "solaris" ]; then - # TODO. Solaris cannot be cross build because of CGO calls. - if [ -z "${daemonSupporting[$platform]}" ]; then - # we just need a simple client for these platforms - export LDFLAGS_STATIC_DOCKER="" - # remove the "daemon" build tag from platforms that aren't supported - export BUILDFLAGS=( "${ORIG_BUILDFLAGS[@]/ daemon/}" ) - source "${MAKEDIR}/binary-client" - else - source "${MAKEDIR}/binary-client" - source "${MAKEDIR}/binary-daemon" - fi - fi - ) -done diff --git a/vendor/github.com/docker/docker/hack/make/dynbinary b/vendor/github.com/docker/docker/hack/make/dynbinary deleted file mode 100644 index 1a435dc..0000000 --- a/vendor/github.com/docker/docker/hack/make/dynbinary +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -e - -# This script exists as backwards compatibility for CI -( - DEST="${DEST}-client" - ABS_DEST="${ABS_DEST}-client" - . hack/make/dynbinary-client -) -( - - DEST="${DEST}-daemon" - ABS_DEST="${ABS_DEST}-daemon" - . hack/make/dynbinary-daemon -) diff --git a/vendor/github.com/docker/docker/hack/make/dynbinary-client b/vendor/github.com/docker/docker/hack/make/dynbinary-client deleted file mode 100644 index e4b7741..0000000 --- a/vendor/github.com/docker/docker/hack/make/dynbinary-client +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -e - -( - export BINARY_SHORT_NAME='docker' - export GO_PACKAGE='github.com/docker/docker/cmd/docker' - export IAMSTATIC='false' - export LDFLAGS_STATIC_DOCKER='' - export BUILDFLAGS=( "${BUILDFLAGS[@]/netgo /}" ) # disable netgo, since we don't need it for a dynamic binary - export BUILDFLAGS=( "${BUILDFLAGS[@]/static_build /}" ) # we're not building a "static" binary here - source "${MAKEDIR}/.binary" -) diff --git a/vendor/github.com/docker/docker/hack/make/dynbinary-daemon b/vendor/github.com/docker/docker/hack/make/dynbinary-daemon deleted file mode 100644 index 090a916..0000000 --- a/vendor/github.com/docker/docker/hack/make/dynbinary-daemon +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -e - -( - export BINARY_SHORT_NAME='dockerd' - export GO_PACKAGE='github.com/docker/docker/cmd/dockerd' - export IAMSTATIC='false' - export LDFLAGS_STATIC_DOCKER='' - export BUILDFLAGS=( "${BUILDFLAGS[@]/netgo /}" ) # disable netgo, since we don't need it for a dynamic binary - export BUILDFLAGS=( "${BUILDFLAGS[@]/static_build /}" ) # we're not building a "static" binary here - source "${MAKEDIR}/.binary" -) diff --git a/vendor/github.com/docker/docker/hack/make/generate-index-listing b/vendor/github.com/docker/docker/hack/make/generate-index-listing deleted file mode 100755 index ec44171..0000000 --- a/vendor/github.com/docker/docker/hack/make/generate-index-listing +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash -set -e - -# This script generates index files for the directory structure -# of the apt and yum repos - -: ${DOCKER_RELEASE_DIR:=$DEST} -APTDIR=$DOCKER_RELEASE_DIR/apt -YUMDIR=$DOCKER_RELEASE_DIR/yum - -if [ ! -d $APTDIR ] && [ ! -d $YUMDIR ]; then - echo >&2 'release-rpm or release-deb must be run before generate-index-listing' - exit 1 -fi - -create_index() { - local directory=$1 - local original=$2 - local cleaned=${directory#$original} - - # the index file to create - local index_file="${directory}/index" - - # cd into dir & touch the index file - cd $directory - touch $index_file - - # print the html header - cat <<-EOF > "$index_file" - - - Index of ${cleaned}/ - -

Index of ${cleaned}/


-
../
-	EOF
-
-	# start of content output
-	(
-	# change IFS locally within subshell so the for loop saves line correctly to L var
-	IFS=$'\n';
-
-	# pretty sweet, will mimick the normal apache output. skipping "index" and hidden files
-	for L in $(find -L . -mount -depth -maxdepth 1 -type f ! -name 'index' ! -name '.*' -prune -printf "%f|@_@%Td-%Tb-%TY %Tk:%TM  @%f@\n"|sort|column -t -s '|' | sed 's,\([\ ]\+\)@_@,\1,g');
-	do
-		# file
-		F=$(sed -e 's,^.*@\([^@]\+\)@.*$,\1,g'<<<"$L");
-
-		# file with file size
-		F=$(du -bh $F | cut -f1);
-
-		# output with correct format
-		sed -e 's,\ @.*$, '"$F"',g'<<<"$L";
-	done;
-	) >> $index_file;
-
-	# now output a list of all directories in this dir (maxdepth 1) other than '.' outputting in a sorted manner exactly like apache
-	find -L . -mount -depth -maxdepth 1 -type d ! -name '.' -printf "%-43f@_@%Td-%Tb-%TY %Tk:%TM  -\n"|sort -d|sed 's,\([\ ]\+\)@_@,/\1,g' >> $index_file
-
-	# print the footer html
-	echo "

" >> $index_file - -} - -get_dirs() { - local directory=$1 - - for d in `find ${directory} -type d`; do - create_index $d $directory - done -} - -get_dirs $APTDIR -get_dirs $YUMDIR diff --git a/vendor/github.com/docker/docker/hack/make/install-binary b/vendor/github.com/docker/docker/hack/make/install-binary deleted file mode 100644 index 82cbc79..0000000 --- a/vendor/github.com/docker/docker/hack/make/install-binary +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e -rm -rf "$DEST" - -( - source "${MAKEDIR}/install-binary-client" -) - -( - source "${MAKEDIR}/install-binary-daemon" -) diff --git a/vendor/github.com/docker/docker/hack/make/install-binary-client b/vendor/github.com/docker/docker/hack/make/install-binary-client deleted file mode 100644 index 6c80452..0000000 --- a/vendor/github.com/docker/docker/hack/make/install-binary-client +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -e -rm -rf "$DEST" - -( - DEST="$(dirname $DEST)/binary-client" - source "${MAKEDIR}/.binary-setup" - install_binary "${DEST}/${DOCKER_CLIENT_BINARY_NAME}" -) diff --git a/vendor/github.com/docker/docker/hack/make/install-binary-daemon b/vendor/github.com/docker/docker/hack/make/install-binary-daemon deleted file mode 100644 index 08a2d69..0000000 --- a/vendor/github.com/docker/docker/hack/make/install-binary-daemon +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -e -rm -rf "$DEST" - -( - DEST="$(dirname $DEST)/binary-daemon" - source "${MAKEDIR}/.binary-setup" - install_binary "${DEST}/${DOCKER_DAEMON_BINARY_NAME}" - install_binary "${DEST}/${DOCKER_RUNC_BINARY_NAME}" - install_binary "${DEST}/${DOCKER_CONTAINERD_BINARY_NAME}" - install_binary "${DEST}/${DOCKER_CONTAINERD_CTR_BINARY_NAME}" - install_binary "${DEST}/${DOCKER_CONTAINERD_SHIM_BINARY_NAME}" - install_binary "${DEST}/${DOCKER_PROXY_BINARY_NAME}" - install_binary "${DEST}/${DOCKER_INIT_BINARY_NAME}" -) diff --git a/vendor/github.com/docker/docker/hack/make/install-script b/vendor/github.com/docker/docker/hack/make/install-script deleted file mode 100644 index feadac2..0000000 --- a/vendor/github.com/docker/docker/hack/make/install-script +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash -set -e - -# This script modifies the install.sh script for domains and keys other than -# those used by the primary opensource releases. -# -# You can provide `url`, `yum_url`, `apt_url` and optionally `gpg_fingerprint` -# or `GPG_KEYID` as environment variables, or the defaults for open source are used. -# -# The lower-case variables are substituted into install.sh. -# -# gpg_fingerprint and GPG_KEYID are optional, defaulting to the opensource release -# key ("releasedocker"). Other GPG_KEYIDs will require you to mount a volume with -# the correct contents to /root/.gnupg. -# -# It outputs the modified `install.sh` file to $DOCKER_RELEASE_DIR (default: $DEST) -# -# Example usage: -# -# docker run \ -# --rm \ -# --privileged \ -# -e "GPG_KEYID=deadbeef" \ -# -e "GNUPGHOME=/root/.gnupg" \ -# -v $HOME/.gnupg:/root/.gnupg \ -# -v $(pwd):/go/src/github.com/docker/docker/bundles \ -# "$IMAGE_DOCKER" \ -# hack/make.sh install-script - -: ${DOCKER_RELEASE_DIR:=$DEST} -: ${GPG_KEYID:=releasedocker} - -DEFAULT_URL="https://get.docker.com/" -DEFAULT_APT_URL="https://apt.dockerproject.org" -DEFAULT_YUM_URL="https://yum.dockerproject.org" -DEFAULT_GPG_FINGERPRINT="58118E89F3A912897C070ADBF76221572C52609D" - -: ${url:=$DEFAULT_URL} -: ${apt_url:=$DEFAULT_APT_URL} -: ${yum_url:=$DEFAULT_YUM_URL} -if [[ "$GPG_KEYID" == "releasedocker" ]] ; then - : ${gpg_fingerprint:=$DEFAULT_GPG_FINGERPRINT} -fi - -DEST_FILE="$DOCKER_RELEASE_DIR/install.sh" - -bundle_install_script() { - mkdir -p "$DOCKER_RELEASE_DIR" - - if [[ -z "$gpg_fingerprint" ]] ; then - # NOTE: if no key matching key is in /root/.gnupg, this will fail - gpg_fingerprint=$(gpg --with-fingerprint -k "$GPG_KEYID" | grep "Key fingerprint" | awk -F "=" '{print $2};' | tr -d ' ') - fi - - cp hack/install.sh "$DEST_FILE" - sed -i.bak 's#^url=".*"$#url="'"$url"'"#' "$DEST_FILE" - sed -i.bak 's#^apt_url=".*"$#apt_url="'"$apt_url"'"#' "$DEST_FILE" - sed -i.bak 's#^yum_url=".*"$#yum_url="'"$yum_url"'"#' "$DEST_FILE" - sed -i.bak 's#^gpg_fingerprint=".*"$#gpg_fingerprint="'"$gpg_fingerprint"'"#' "$DEST_FILE" - rm "${DEST_FILE}.bak" -} - -bundle_install_script diff --git a/vendor/github.com/docker/docker/hack/make/release-deb b/vendor/github.com/docker/docker/hack/make/release-deb deleted file mode 100755 index ed65fe2..0000000 --- a/vendor/github.com/docker/docker/hack/make/release-deb +++ /dev/null @@ -1,163 +0,0 @@ -#!/bin/bash -set -e - -# This script creates the apt repos for the .deb files generated by hack/make/build-deb -# -# The following can then be used as apt sources: -# deb http://apt.dockerproject.org/repo $distro-$release $version -# -# For example: -# deb http://apt.dockerproject.org/repo ubuntu-trusty main -# deb http://apt.dockerproject.org/repo ubuntu-trusty testing -# deb http://apt.dockerproject.org/repo debian-wheezy experimental -# deb http://apt.dockerproject.org/repo debian-jessie main -# -# ... and so on and so forth for the builds created by hack/make/build-deb - -: ${DOCKER_RELEASE_DIR:=$DEST} -: ${GPG_KEYID:=releasedocker} -APTDIR=$DOCKER_RELEASE_DIR/apt/repo - -# setup the apt repo (if it does not exist) -mkdir -p "$APTDIR/conf" "$APTDIR/db" "$APTDIR/dists" - -# supported arches/sections -arches=( amd64 i386 armhf ) - -# Preserve existing components but don't add any non-existing ones -for component in main testing experimental ; do - exists=$(find "$APTDIR/dists" -mindepth 2 -maxdepth 2 -type d -name "$component" -print -quit) - if [ -n "$exists" ] ; then - components+=( $component ) - fi -done - -# set the component for the version being released -component="main" - -if [[ "$VERSION" == *-rc* ]]; then - component="testing" -fi - -if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then - component="experimental" -fi - -# Make sure our component is in the list of components -if [[ ! "${components[*]}" =~ $component ]] ; then - components+=( $component ) -fi - -# create apt-ftparchive file on every run. This is essential to avoid -# using stale versions of the config file that could cause unnecessary -# refreshing of bits for EOL-ed releases. -cat <<-EOF > "$APTDIR/conf/apt-ftparchive.conf" -Dir { - ArchiveDir "${APTDIR}"; - CacheDir "${APTDIR}/db"; -}; - -Default { - Packages::Compress ". gzip bzip2"; - Sources::Compress ". gzip bzip2"; - Contents::Compress ". gzip bzip2"; -}; - -TreeDefault { - BinCacheDB "packages-\$(SECTION)-\$(ARCH).db"; - Directory "pool/\$(SECTION)"; - Packages "\$(DIST)/\$(SECTION)/binary-\$(ARCH)/Packages"; - SrcDirectory "pool/\$(SECTION)"; - Sources "\$(DIST)/\$(SECTION)/source/Sources"; - Contents "\$(DIST)/\$(SECTION)/Contents-\$(ARCH)"; - FileList "$APTDIR/\$(DIST)/\$(SECTION)/filelist"; -}; -EOF - -for dir in bundles/$VERSION/build-deb/*/; do - version="$(basename "$dir")" - suite="${version//debootstrap-}" - - cat <<-EOF - Tree "dists/${suite}" { - Sections "${components[*]}"; - Architectures "${arches[*]}"; - } - - EOF -done >> "$APTDIR/conf/apt-ftparchive.conf" - -cat <<-EOF > "$APTDIR/conf/docker-engine-release.conf" -APT::FTPArchive::Release::Origin "Docker"; -APT::FTPArchive::Release::Components "${components[*]}"; -APT::FTPArchive::Release::Label "Docker APT Repository"; -APT::FTPArchive::Release::Architectures "${arches[*]}"; -EOF - -# release the debs -for dir in bundles/$VERSION/build-deb/*/; do - version="$(basename "$dir")" - codename="${version//debootstrap-}" - - tempdir="$(mktemp -d /tmp/tmp-docker-release-deb.XXXXXXXX)" - DEBFILE=( "$dir/docker-engine"*.deb ) - - # add the deb for each component for the distro version into the - # pool (if it is not there already) - mkdir -p "$APTDIR/pool/$component/d/docker-engine/" - for deb in ${DEBFILE[@]}; do - d=$(basename "$deb") - # We do not want to generate a new deb if it has already been - # copied into the APTDIR - if [ ! -f "$APTDIR/pool/$component/d/docker-engine/$d" ]; then - cp "$deb" "$tempdir/" - # if we have a $GPG_PASSPHRASE we may as well - # dpkg-sign before copying the deb into the pool - if [ ! -z "$GPG_PASSPHRASE" ]; then - dpkg-sig -g "--no-tty --digest-algo 'sha512' --passphrase '$GPG_PASSPHRASE'" \ - -k "$GPG_KEYID" --sign builder "$tempdir/$d" - fi - mv "$tempdir/$d" "$APTDIR/pool/$component/d/docker-engine/" - fi - done - - rm -rf "$tempdir" - - # build the right directory structure, needed for apt-ftparchive - for arch in "${arches[@]}"; do - for c in "${components[@]}"; do - mkdir -p "$APTDIR/dists/$codename/$c/binary-$arch" - done - done - - # update the filelist for this codename/component - find "$APTDIR/pool/$component" \ - -name *~${codename}*.deb -o \ - -name *~${codename#*-}*.deb > "$APTDIR/dists/$codename/$component/filelist" -done - -# run the apt-ftparchive commands so we can have pinning -apt-ftparchive generate "$APTDIR/conf/apt-ftparchive.conf" - -for dir in bundles/$VERSION/build-deb/*/; do - version="$(basename "$dir")" - codename="${version//debootstrap-}" - - apt-ftparchive \ - -c "$APTDIR/conf/docker-engine-release.conf" \ - -o "APT::FTPArchive::Release::Codename=$codename" \ - -o "APT::FTPArchive::Release::Suite=$codename" \ - release \ - "$APTDIR/dists/$codename" > "$APTDIR/dists/$codename/Release" - - for arch in "${arches[@]}"; do - apt-ftparchive \ - -c "$APTDIR/conf/docker-engine-release.conf" \ - -o "APT::FTPArchive::Release::Codename=$codename" \ - -o "APT::FTPArchive::Release::Suite=$codename" \ - -o "APT::FTPArchive::Release::Components=$component" \ - -o "APT::FTPArchive::Release::Architecture=$arch" \ - release \ - "$APTDIR/dists/$codename/$component/binary-$arch" > "$APTDIR/dists/$codename/$component/binary-$arch/Release" - done -done diff --git a/vendor/github.com/docker/docker/hack/make/release-rpm b/vendor/github.com/docker/docker/hack/make/release-rpm deleted file mode 100755 index d7e3ec4..0000000 --- a/vendor/github.com/docker/docker/hack/make/release-rpm +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash -set -e - -# This script creates the yum repos for the .rpm files generated by hack/make/build-rpm -# -# The following can then be used as a yum repo: -# http://yum.dockerproject.org/repo/$release/$distro/$distro-version -# -# For example: -# http://yum.dockerproject.org/repo/main/fedora/23 -# http://yum.dockerproject.org/repo/testing/centos/7 -# http://yum.dockerproject.org/repo/experimental/fedora/23 -# http://yum.dockerproject.org/repo/main/centos/7 -# -# ... and so on and so forth for the builds created by hack/make/build-rpm - -: ${DOCKER_RELEASE_DIR:=$DEST} -YUMDIR=$DOCKER_RELEASE_DIR/yum/repo -: ${GPG_KEYID:=releasedocker} - -# get the release -release="main" - -if [[ "$VERSION" == *-rc* ]]; then - release="testing" -fi - -if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then - release="experimental" -fi - -# Setup the yum repo -for dir in bundles/$VERSION/build-rpm/*/; do - version="$(basename "$dir")" - suite="${version##*-}" - distro="${version%-*}" - - REPO=$YUMDIR/$release/$distro - - # if the directory does not exist, initialize the yum repo - if [[ ! -d $REPO/$suite/Packages ]]; then - mkdir -p "$REPO/$suite/Packages" - - createrepo --pretty "$REPO/$suite" - fi - - # path to rpms - RPMFILE=( "bundles/$VERSION/build-rpm/$version/RPMS/"*"/docker-engine"*.rpm "bundles/$VERSION/build-rpm/$version/SRPMS/docker-engine"*.rpm ) - - # if we have a $GPG_PASSPHRASE we may as well - # sign the rpms before adding to repo - if [ ! -z $GPG_PASSPHRASE ]; then - # export our key to rpm import - gpg --armor --export "$GPG_KEYID" > /tmp/gpg - rpm --import /tmp/gpg - - # sign the rpms - echo "yes" | setsid rpm \ - --define "_gpg_name $GPG_KEYID" \ - --define "_signature gpg" \ - --define "__gpg_check_password_cmd /bin/true" \ - --define "__gpg_sign_cmd %{__gpg} gpg --batch --no-armor --digest-algo 'sha512' --passphrase '$GPG_PASSPHRASE' --no-secmem-warning -u '%{_gpg_name}' --sign --detach-sign --output %{__signature_filename} %{__plaintext_filename}" \ - --resign "${RPMFILE[@]}" - fi - - # copy the rpms to the packages folder - cp "${RPMFILE[@]}" "$REPO/$suite/Packages" - - # update the repo - createrepo --pretty --update "$REPO/$suite" -done diff --git a/vendor/github.com/docker/docker/hack/make/run b/vendor/github.com/docker/docker/hack/make/run deleted file mode 100644 index 37cfd53..0000000 --- a/vendor/github.com/docker/docker/hack/make/run +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -set -e -rm -rf "$DEST" - -if ! command -v dockerd &> /dev/null; then - echo >&2 'error: binary-daemon or dynbinary-daemon must be run before run' - false -fi - -DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs} -DOCKER_USERLANDPROXY=${DOCKER_USERLANDPROXY:-true} - -# example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G" -storage_params="" -if [ -n "$DOCKER_STORAGE_OPTS" ]; then - IFS=',' - for i in ${DOCKER_STORAGE_OPTS}; do - storage_params="--storage-opt $i $storage_params" - done - unset IFS -fi - - -listen_port=2375 -if [ -n "$DOCKER_PORT" ]; then - IFS=':' read -r -a ports <<< "$DOCKER_PORT" - listen_port="${ports[-1]}" -fi - -extra_params="" -if [ "$DOCKER_REMAP_ROOT" ]; then - extra_params="--userns-remap $DOCKER_REMAP_ROOT" -fi - -args="--debug \ - --host tcp://0.0.0.0:${listen_port} --host unix:///var/run/docker.sock \ - --storage-driver "$DOCKER_GRAPHDRIVER" \ - --userland-proxy="$DOCKER_USERLANDPROXY" \ - $storage_params \ - $extra_params" - -echo dockerd $args -exec dockerd $args diff --git a/vendor/github.com/docker/docker/hack/make/sign-repos b/vendor/github.com/docker/docker/hack/make/sign-repos deleted file mode 100755 index 6ed1606..0000000 --- a/vendor/github.com/docker/docker/hack/make/sign-repos +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -# This script signs the deliverables from release-deb and release-rpm -# with a designated GPG key. - -: ${DOCKER_RELEASE_DIR:=$DEST} -: ${GPG_KEYID:=releasedocker} -APTDIR=$DOCKER_RELEASE_DIR/apt/repo -YUMDIR=$DOCKER_RELEASE_DIR/yum/repo - -if [ -z "$GPG_PASSPHRASE" ]; then - echo >&2 'you need to set GPG_PASSPHRASE in order to sign artifacts' - exit 1 -fi - -if [ ! -d $APTDIR ] && [ ! -d $YUMDIR ]; then - echo >&2 'release-rpm or release-deb must be run before sign-repos' - exit 1 -fi - -sign_packages(){ - # sign apt repo metadata - if [ -d $APTDIR ]; then - # create file with public key - gpg --armor --export "$GPG_KEYID" > "$DOCKER_RELEASE_DIR/apt/gpg" - - # sign the repo metadata - for F in $(find $APTDIR -name Release); do - if test "$F" -nt "$F.gpg" ; then - gpg -u "$GPG_KEYID" --passphrase "$GPG_PASSPHRASE" \ - --digest-algo "sha512" \ - --armor --sign --detach-sign \ - --batch --yes \ - --output "$F.gpg" "$F" - fi - inRelease="$(dirname "$F")/InRelease" - if test "$F" -nt "$inRelease" ; then - gpg -u "$GPG_KEYID" --passphrase "$GPG_PASSPHRASE" \ - --digest-algo "sha512" \ - --clearsign \ - --batch --yes \ - --output "$inRelease" "$F" - fi - done - fi - - # sign yum repo metadata - if [ -d $YUMDIR ]; then - # create file with public key - gpg --armor --export "$GPG_KEYID" > "$DOCKER_RELEASE_DIR/yum/gpg" - - # sign the repo metadata - for F in $(find $YUMDIR -name repomd.xml); do - if test "$F" -nt "$F.asc" ; then - gpg -u "$GPG_KEYID" --passphrase "$GPG_PASSPHRASE" \ - --digest-algo "sha512" \ - --armor --sign --detach-sign \ - --batch --yes \ - --output "$F.asc" "$F" - fi - done - fi -} - -sign_packages diff --git a/vendor/github.com/docker/docker/hack/make/test-deb-install b/vendor/github.com/docker/docker/hack/make/test-deb-install deleted file mode 100755 index aec5847..0000000 --- a/vendor/github.com/docker/docker/hack/make/test-deb-install +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash -# This script is used for testing install.sh and that it works for -# each of component of our apt and yum repos -set -e - -: ${DEB_DIR:="$(pwd)/bundles/$(cat VERSION)/build-deb"} - -if [[ ! -d "${DEB_DIR}" ]]; then - echo "you must first run `make deb` or hack/make/build-deb" - exit 1 -fi - -test_deb_install(){ - # test for each Dockerfile in contrib/builder - - builderDir="contrib/builder/deb/${PACKAGE_ARCH}" - pkgs=( $(find "${builderDir}/"*/ -type d) ) - if [ ! -z "$DOCKER_BUILD_PKGS" ]; then - pkgs=() - for p in $DOCKER_BUILD_PKGS; do - pkgs+=( "$builderDir/$p" ) - done - fi - for dir in "${pkgs[@]}"; do - [ -d "$dir" ] || { echo >&2 "skipping nonexistent $dir"; continue; } - local from="$(awk 'toupper($1) == "FROM" { print $2; exit }' "$dir/Dockerfile")" - local dir=$(basename "$dir") - - if [[ ! -d "${DEB_DIR}/${dir}" ]]; then - echo "No deb found for ${dir}" - exit 1 - fi - - local script=$(mktemp /tmp/install-XXXXXXXXXX.sh) - cat <<-EOF > "${script}" - #!/bin/bash - set -e - set -x - - apt-get update && apt-get install -y apparmor - - dpkg -i /root/debs/*.deb || true - - apt-get install -yf - - /etc/init.d/apparmor start - - # this will do everything _except_ load the profile into the kernel - ( - cd /etc/apparmor.d - /sbin/apparmor_parser --skip-kernel-load docker-engine - ) - EOF - - chmod +x "${script}" - - echo "testing deb install for ${from}" - docker run --rm -i --privileged \ - -v ${DEB_DIR}/${dir}:/root/debs \ - -v ${script}:/install.sh \ - ${from} /install.sh - - rm -f ${script} - done -} - -( - bundle .integration-daemon-start - test_deb_install - bundle .integration-daemon-stop -) 2>&1 | tee -a "$DEST/test.log" diff --git a/vendor/github.com/docker/docker/hack/make/test-docker-py b/vendor/github.com/docker/docker/hack/make/test-docker-py deleted file mode 100644 index fcacc16..0000000 --- a/vendor/github.com/docker/docker/hack/make/test-docker-py +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -set -e - -source hack/make/.integration-test-helpers - -# subshell so that we can export PATH without breaking other things -( - bundle .integration-daemon-start - - dockerPy='/docker-py' - [ -d "$dockerPy" ] || { - dockerPy="$DEST/docker-py" - git clone https://github.com/docker/docker-py.git "$dockerPy" - } - - # exporting PYTHONPATH to import "docker" from our local docker-py - test_env PYTHONPATH="$dockerPy" py.test --junitxml="$DEST/results.xml" "$dockerPy/tests/integration" - - bundle .integration-daemon-stop -) 2>&1 | tee -a "$DEST/test.log" diff --git a/vendor/github.com/docker/docker/hack/make/test-install-script b/vendor/github.com/docker/docker/hack/make/test-install-script deleted file mode 100755 index 4782cbe..0000000 --- a/vendor/github.com/docker/docker/hack/make/test-install-script +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# This script is used for testing install.sh and that it works for -# each of component of our apt and yum repos -set -e - -test_install_script(){ - # these are equivalent to main, testing, experimental components - # in the repos, but its the url that will do the conversion - components=( experimental test get ) - - for component in "${components[@]}"; do - # change url to specific component for testing - local test_url=https://${component}.docker.com - local script=$(mktemp /tmp/install-XXXXXXXXXX.sh) - sed "s,url='https://get.docker.com/',url='${test_url}/'," hack/install.sh > "${script}" - - chmod +x "${script}" - - # test for each Dockerfile in contrib/builder - for dir in contrib/builder/*/*/; do - local from="$(awk 'toupper($1) == "FROM" { print $2; exit }' "$dir/Dockerfile")" - - echo "running install.sh for ${component} with ${from}" - docker run --rm -i -v ${script}:/install.sh ${from} /install.sh - done - - rm -f ${script} - done -} - -test_install_script diff --git a/vendor/github.com/docker/docker/hack/make/test-integration-cli b/vendor/github.com/docker/docker/hack/make/test-integration-cli deleted file mode 100755 index 689a528..0000000 --- a/vendor/github.com/docker/docker/hack/make/test-integration-cli +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -set -e - -source hack/make/.integration-test-helpers - -# subshell so that we can export PATH without breaking other things -( - bundle .integration-daemon-start - - bundle .integration-daemon-setup - - bundle_test_integration_cli - - bundle .integration-daemon-stop - - if [ "$(go env GOOS)" != 'windows' ] - then - leftovers=$(ps -ax -o pid,cmd | awk '$2 == "docker-containerd-shim" && $4 ~ /.*\/bundles\/.*\/test-integration-cli/ { print $1 }') - if [ -n "$leftovers" ] - then - ps aux - kill -9 $leftovers 2> /dev/null - echo "!!!! WARNING you have left over shim(s), Cleanup your test !!!!" - exit 1 - fi - fi - -) 2>&1 | tee -a "$DEST/test.log" diff --git a/vendor/github.com/docker/docker/hack/make/test-integration-shell b/vendor/github.com/docker/docker/hack/make/test-integration-shell deleted file mode 100644 index 86df965..0000000 --- a/vendor/github.com/docker/docker/hack/make/test-integration-shell +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -bundle .integration-daemon-start -bundle .integration-daemon-setup - -export ABS_DEST -bash +e diff --git a/vendor/github.com/docker/docker/hack/make/test-old-apt-repo b/vendor/github.com/docker/docker/hack/make/test-old-apt-repo deleted file mode 100755 index bb20128..0000000 --- a/vendor/github.com/docker/docker/hack/make/test-old-apt-repo +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -set -e - -versions=( 1.3.3 1.4.1 1.5.0 1.6.2 ) - -install() { - local version=$1 - local tmpdir=$(mktemp -d /tmp/XXXXXXXXXX) - local dockerfile="${tmpdir}/Dockerfile" - cat <<-EOF > "$dockerfile" - FROM debian:jessie - ENV VERSION ${version} - RUN apt-get update && apt-get install -y \ - apt-transport-https \ - ca-certificates \ - --no-install-recommends - RUN echo "deb https://get.docker.com/ubuntu docker main" > /etc/apt/sources.list.d/docker.list - RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 \ - --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 - RUN apt-get update && apt-get install -y \ - lxc-docker-\${VERSION} - EOF - - docker build --rm --force-rm --no-cache -t docker-old-repo:${version} -f $dockerfile $tmpdir -} - -for v in "${versions[@]}"; do - install "$v" -done diff --git a/vendor/github.com/docker/docker/hack/make/test-unit b/vendor/github.com/docker/docker/hack/make/test-unit deleted file mode 100644 index f263345..0000000 --- a/vendor/github.com/docker/docker/hack/make/test-unit +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -set -e - -# Run Docker's test suite, including sub-packages, and store their output as a bundle -# If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. -# You can use this to select certain tests to run, e.g. -# -# TESTFLAGS='-test.run ^TestBuild$' ./hack/make.sh test-unit -# -bundle_test_unit() { - TESTFLAGS+=" -test.timeout=${TIMEOUT}" - INCBUILD="-i" - count=0 - for flag in "${BUILDFLAGS[@]}"; do - if [ "${flag}" == ${INCBUILD} ]; then - unset BUILDFLAGS[${count}] - break - fi - count=$[ ${count} + 1 ] - done - - date - if [ -z "$TESTDIRS" ]; then - TEST_PATH=./... - else - TEST_PATH=./${TESTDIRS} - fi - - if [ "$(go env GOHOSTOS)" = 'solaris' ]; then - pkg_list=$(go list -e \ - -f '{{if ne .Name "github.com/docker/docker"}} - {{.ImportPath}} - {{end}}' \ - "${BUILDFLAGS[@]}" $TEST_PATH \ - | grep github.com/docker/docker \ - | grep -v github.com/docker/docker/vendor \ - | grep -v github.com/docker/docker/daemon/graphdriver \ - | grep -v github.com/docker/docker/man \ - | grep -v github.com/docker/docker/integration-cli) - else - pkg_list=$(go list -e \ - -f '{{if ne .Name "github.com/docker/docker"}} - {{.ImportPath}} - {{end}}' \ - "${BUILDFLAGS[@]}" $TEST_PATH \ - | grep github.com/docker/docker \ - | grep -v github.com/docker/docker/vendor \ - | grep -v github.com/docker/docker/man \ - | grep -v github.com/docker/docker/integration-cli) - fi - - go test -cover -ldflags "$LDFLAGS" "${BUILDFLAGS[@]}" $TESTFLAGS $pkg_list -} - -bundle_test_unit 2>&1 | tee -a "$DEST/test.log" diff --git a/vendor/github.com/docker/docker/hack/make/tgz b/vendor/github.com/docker/docker/hack/make/tgz deleted file mode 100644 index 3ccd93f..0000000 --- a/vendor/github.com/docker/docker/hack/make/tgz +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/bash - -CROSS="$DEST/../cross" - -set -e - -arch=$(go env GOHOSTARCH) -if [ ! -d "$CROSS/linux/${arch}" ]; then - echo >&2 'error: binary and cross must be run before tgz' - false -fi - -( -for d in "$CROSS/"*/*; do - export GOARCH="$(basename "$d")" - export GOOS="$(basename "$(dirname "$d")")" - - source "${MAKEDIR}/.binary-setup" - - BINARY_NAME="${DOCKER_CLIENT_BINARY_NAME}-$VERSION" - DAEMON_BINARY_NAME="${DOCKER_DAEMON_BINARY_NAME}-$VERSION" - PROXY_BINARY_NAME="${DOCKER_PROXY_BINARY_NAME}-$VERSION" - BINARY_EXTENSION="$(export GOOS && binary_extension)" - if [ "$GOOS" = 'windows' ]; then - # if windows use a zip, not tgz - BUNDLE_EXTENSION=".zip" - IS_TAR="false" - elif [ "$GOOS" == "solaris" ]; then - # Solaris bypasses cross due to CGO issues. - continue - else - BUNDLE_EXTENSION=".tgz" - IS_TAR="true" - fi - BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION" - DAEMON_BINARY_FULLNAME="$DAEMON_BINARY_NAME$BINARY_EXTENSION" - PROXY_BINARY_FULLNAME="$PROXY_BINARY_NAME$BINARY_EXTENSION" - mkdir -p "$DEST/$GOOS/$GOARCH" - TGZ="$DEST/$GOOS/$GOARCH/$BINARY_NAME$BUNDLE_EXTENSION" - - # The staging directory for the files in the tgz - BUILD_PATH="$DEST/build" - - # The directory that is at the root of the tar file - TAR_BASE_DIRECTORY="docker" - - # $DEST/build/docker - TAR_PATH="$BUILD_PATH/$TAR_BASE_DIRECTORY" - - # Copy the correct docker binary - mkdir -p $TAR_PATH - cp -L "$d/$BINARY_FULLNAME" "$TAR_PATH/${DOCKER_CLIENT_BINARY_NAME}${BINARY_EXTENSION}" - if [ -f "$d/$DAEMON_BINARY_FULLNAME" ]; then - cp -L "$d/$DAEMON_BINARY_FULLNAME" "$TAR_PATH/${DOCKER_DAEMON_BINARY_NAME}${BINARY_EXTENSION}" - fi - if [ -f "$d/$PROXY_BINARY_FULLNAME" ]; then - cp -L "$d/$PROXY_BINARY_FULLNAME" "$TAR_PATH/${DOCKER_PROXY_BINARY_NAME}${BINARY_EXTENSION}" - fi - - # copy over all the extra binaries - copy_binaries $TAR_PATH - - # add completions - for s in bash fish zsh; do - mkdir -p $TAR_PATH/completion/$s - cp -L contrib/completion/$s/*docker* $TAR_PATH/completion/$s/ - done - - if [ "$IS_TAR" == "true" ]; then - echo "Creating tgz from $BUILD_PATH and naming it $TGZ" - tar --numeric-owner --owner 0 -C "$BUILD_PATH" -czf "$TGZ" $TAR_BASE_DIRECTORY - else - # ZIP needs to full absolute dir path, not the absolute path - ZIP=`pwd`"/$TGZ" - # keep track of where we are, for later. - pushd . - # go into the BUILD_PATH since zip does not have a -C equivalent. - cd $BUILD_PATH - echo "Creating zip from $BUILD_PATH and naming it $ZIP" - zip -q -r $ZIP $TAR_BASE_DIRECTORY - # go back to where we started - popd - fi - - hash_files "$TGZ" - - # cleanup after ourselves - rm -rf "$BUILD_PATH" - - echo "Created tgz: $TGZ" -done -) diff --git a/vendor/github.com/docker/docker/hack/make/ubuntu b/vendor/github.com/docker/docker/hack/make/ubuntu deleted file mode 100644 index 8de5d9c..0000000 --- a/vendor/github.com/docker/docker/hack/make/ubuntu +++ /dev/null @@ -1,190 +0,0 @@ -#!/bin/bash - -PKGVERSION="${VERSION//-/'~'}" -# if we have a "-dev" suffix or have change in Git, let's make this package version more complex so it works better -if [[ "$VERSION" == *-dev ]] || [ -n "$(git status --porcelain)" ]; then - GIT_UNIX="$(git log -1 --pretty='%at')" - GIT_DATE="$(date --date "@$GIT_UNIX" +'%Y%m%d.%H%M%S')" - GIT_COMMIT="$(git log -1 --pretty='%h')" - GIT_VERSION="git${GIT_DATE}.0.${GIT_COMMIT}" - # GIT_VERSION is now something like 'git20150128.112847.0.17e840a' - PKGVERSION="$PKGVERSION~$GIT_VERSION" -fi - -# $ dpkg --compare-versions 1.5.0 gt 1.5.0~rc1 && echo true || echo false -# true -# $ dpkg --compare-versions 1.5.0~rc1 gt 1.5.0~git20150128.112847.17e840a && echo true || echo false -# true -# $ dpkg --compare-versions 1.5.0~git20150128.112847.17e840a gt 1.5.0~dev~git20150128.112847.17e840a && echo true || echo false -# true - -# ie, 1.5.0 > 1.5.0~rc1 > 1.5.0~git20150128.112847.17e840a > 1.5.0~dev~git20150128.112847.17e840a - -PACKAGE_ARCHITECTURE="$(dpkg-architecture -qDEB_HOST_ARCH)" -PACKAGE_URL="https://www.docker.com/" -PACKAGE_MAINTAINER="support@docker.com" -PACKAGE_DESCRIPTION="Linux container runtime -Docker complements LXC with a high-level API which operates at the process -level. It runs unix processes with strong guarantees of isolation and -repeatability across servers. -Docker is a great building block for automating distributed systems: -large-scale web deployments, database clusters, continuous deployment systems, -private PaaS, service-oriented architectures, etc." -PACKAGE_LICENSE="Apache-2.0" - -# Build docker as an ubuntu package using FPM and REPREPRO (sue me). -# bundle_binary must be called first. -bundle_ubuntu() { - DIR="$ABS_DEST/build" - - # Include our udev rules - mkdir -p "$DIR/etc/udev/rules.d" - cp contrib/udev/80-docker.rules "$DIR/etc/udev/rules.d/" - - # Include our init scripts - mkdir -p "$DIR/etc/init" - cp contrib/init/upstart/docker.conf "$DIR/etc/init/" - mkdir -p "$DIR/etc/init.d" - cp contrib/init/sysvinit-debian/docker "$DIR/etc/init.d/" - mkdir -p "$DIR/etc/default" - cp contrib/init/sysvinit-debian/docker.default "$DIR/etc/default/docker" - mkdir -p "$DIR/lib/systemd/system" - cp contrib/init/systemd/docker.{service,socket} "$DIR/lib/systemd/system/" - - # Include contributed completions - mkdir -p "$DIR/etc/bash_completion.d" - cp contrib/completion/bash/docker "$DIR/etc/bash_completion.d/" - mkdir -p "$DIR/usr/share/zsh/vendor-completions" - cp contrib/completion/zsh/_docker "$DIR/usr/share/zsh/vendor-completions/" - mkdir -p "$DIR/etc/fish/completions" - cp contrib/completion/fish/docker.fish "$DIR/etc/fish/completions/" - - # Include man pages - make manpages - manRoot="$DIR/usr/share/man" - mkdir -p "$manRoot" - for manDir in man/man?; do - manBase="$(basename "$manDir")" # "man1" - for manFile in "$manDir"/*; do - manName="$(basename "$manFile")" # "docker-build.1" - mkdir -p "$manRoot/$manBase" - gzip -c "$manFile" > "$manRoot/$manBase/$manName.gz" - done - done - - # Copy the binary - # This will fail if the binary bundle hasn't been built - mkdir -p "$DIR/usr/bin" - cp "$DEST/../binary/docker-$VERSION" "$DIR/usr/bin/docker" - - # Generate postinst/prerm/postrm scripts - cat > "$DEST/postinst" <<'EOF' -#!/bin/sh -set -e -set -u - -if [ "$1" = 'configure' ] && [ -z "$2" ]; then - if ! getent group docker > /dev/null; then - groupadd --system docker - fi -fi - -if ! { [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; }; then - # we only need to do this if upstart isn't in charge - update-rc.d docker defaults > /dev/null || true -fi -if [ -n "$2" ]; then - _dh_action=restart -else - _dh_action=start -fi -service docker $_dh_action 2>/dev/null || true - -#DEBHELPER# -EOF - cat > "$DEST/prerm" <<'EOF' -#!/bin/sh -set -e -set -u - -service docker stop 2>/dev/null || true - -#DEBHELPER# -EOF - cat > "$DEST/postrm" <<'EOF' -#!/bin/sh -set -e -set -u - -if [ "$1" = "purge" ] ; then - update-rc.d docker remove > /dev/null || true -fi - -# In case this system is running systemd, we make systemd reload the unit files -# to pick up changes. -if [ -d /run/systemd/system ] ; then - systemctl --system daemon-reload > /dev/null || true -fi - -#DEBHELPER# -EOF - # TODO swaths of these were borrowed from debhelper's auto-inserted stuff, because we're still using fpm - we need to use debhelper instead, and somehow reconcile Ubuntu that way - chmod +x "$DEST/postinst" "$DEST/prerm" "$DEST/postrm" - - ( - # switch directories so we create *.deb in the right folder - cd "$DEST" - - # create lxc-docker-VERSION package - fpm -s dir -C "$DIR" \ - --name "lxc-docker-$VERSION" --version "$PKGVERSION" \ - --after-install "$ABS_DEST/postinst" \ - --before-remove "$ABS_DEST/prerm" \ - --after-remove "$ABS_DEST/postrm" \ - --architecture "$PACKAGE_ARCHITECTURE" \ - --prefix / \ - --depends iptables \ - --deb-recommends aufs-tools \ - --deb-recommends ca-certificates \ - --deb-recommends git \ - --deb-recommends xz-utils \ - --deb-recommends 'cgroupfs-mount | cgroup-lite' \ - --deb-suggests apparmor \ - --description "$PACKAGE_DESCRIPTION" \ - --maintainer "$PACKAGE_MAINTAINER" \ - --conflicts docker \ - --conflicts docker.io \ - --conflicts lxc-docker-virtual-package \ - --provides lxc-docker \ - --provides lxc-docker-virtual-package \ - --replaces lxc-docker \ - --replaces lxc-docker-virtual-package \ - --url "$PACKAGE_URL" \ - --license "$PACKAGE_LICENSE" \ - --config-files /etc/udev/rules.d/80-docker.rules \ - --config-files /etc/init/docker.conf \ - --config-files /etc/init.d/docker \ - --config-files /etc/default/docker \ - --deb-compression gz \ - -t deb . - # TODO replace "Suggests: cgroup-lite" with "Recommends: cgroupfs-mount | cgroup-lite" once cgroupfs-mount is available - - # create empty lxc-docker wrapper package - fpm -s empty \ - --name lxc-docker --version "$PKGVERSION" \ - --architecture "$PACKAGE_ARCHITECTURE" \ - --depends lxc-docker-$VERSION \ - --description "$PACKAGE_DESCRIPTION" \ - --maintainer "$PACKAGE_MAINTAINER" \ - --url "$PACKAGE_URL" \ - --license "$PACKAGE_LICENSE" \ - --deb-compression gz \ - -t deb - ) - - # clean up after ourselves so we have a clean output directory - rm "$DEST/postinst" "$DEST/prerm" "$DEST/postrm" - rm -r "$DIR" -} - -bundle_ubuntu diff --git a/vendor/github.com/docker/docker/hack/make/update-apt-repo b/vendor/github.com/docker/docker/hack/make/update-apt-repo deleted file mode 100755 index 7354a2e..0000000 --- a/vendor/github.com/docker/docker/hack/make/update-apt-repo +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash -set -e - -# This script updates the apt repo in $DOCKER_RELEASE_DIR/apt/repo. -# This script is a "fix all" for any sort of problems that might have occurred with -# the Release or Package files in the repo. -# It should only be used in the rare case of extreme emergencies to regenerate -# Release and Package files for the apt repo. -# -# NOTE: Always be sure to re-sign the repo with hack/make/sign-repos after running -# this script. - -: ${DOCKER_RELEASE_DIR:=$DEST} -APTDIR=$DOCKER_RELEASE_DIR/apt/repo - -# supported arches/sections -arches=( amd64 i386 ) - -# Preserve existing components but don't add any non-existing ones -for component in main testing experimental ; do - if ls "$APTDIR/dists/*/$component" >/dev/null 2>&1 ; then - components+=( $component ) - fi -done - -dists=( $(find "${APTDIR}/dists" -maxdepth 1 -mindepth 1 -type d) ) - -# override component if it is set -if [ "$COMPONENT" ]; then - components=( $COMPONENT ) -fi - -# release the debs -for version in "${dists[@]}"; do - for component in "${components[@]}"; do - codename="${version//debootstrap-}" - - # update the filelist for this codename/component - find "$APTDIR/pool/$component" \ - -name *~${codename#*-}*.deb > "$APTDIR/dists/$codename/$component/filelist" - done -done - -# run the apt-ftparchive commands so we can have pinning -apt-ftparchive generate "$APTDIR/conf/apt-ftparchive.conf" - -for dist in "${dists[@]}"; do - version=$(basename "$dist") - for component in "${components[@]}"; do - codename="${version//debootstrap-}" - - apt-ftparchive \ - -o "APT::FTPArchive::Release::Codename=$codename" \ - -o "APT::FTPArchive::Release::Suite=$codename" \ - -c "$APTDIR/conf/docker-engine-release.conf" \ - release \ - "$APTDIR/dists/$codename" > "$APTDIR/dists/$codename/Release" - - for arch in "${arches[@]}"; do - apt-ftparchive \ - -o "APT::FTPArchive::Release::Codename=$codename" \ - -o "APT::FTPArchive::Release::Suite=$codename" \ - -o "APT::FTPArchive::Release::Component=$component" \ - -o "APT::FTPArchive::Release::Architecture=$arch" \ - -c "$APTDIR/conf/docker-engine-release.conf" \ - release \ - "$APTDIR/dists/$codename/$component/binary-$arch" > "$APTDIR/dists/$codename/$component/binary-$arch/Release" - done - done -done diff --git a/vendor/github.com/docker/docker/hack/make/win b/vendor/github.com/docker/docker/hack/make/win deleted file mode 100644 index f9f4111..0000000 --- a/vendor/github.com/docker/docker/hack/make/win +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -set -e - -# explicit list of os/arch combos that support being a daemon -declare -A daemonSupporting -daemonSupporting=( - [linux/amd64]=1 - [windows/amd64]=1 -) -platform="windows/amd64" -export DEST="$DEST/$platform" # bundles/VERSION/cross/GOOS/GOARCH/docker-VERSION -mkdir -p "$DEST" -ABS_DEST="$(cd "$DEST" && pwd -P)" -export GOOS=${platform%/*} -export GOARCH=${platform##*/} -if [ -z "${daemonSupporting[$platform]}" ]; then - export LDFLAGS_STATIC_DOCKER="" # we just need a simple client for these platforms - export BUILDFLAGS=( "${ORIG_BUILDFLAGS[@]/ daemon/}" ) # remove the "daemon" build tag from platforms that aren't supported -fi -source "${MAKEDIR}/binary" diff --git a/vendor/github.com/docker/docker/hack/release.sh b/vendor/github.com/docker/docker/hack/release.sh deleted file mode 100755 index 4b02053..0000000 --- a/vendor/github.com/docker/docker/hack/release.sh +++ /dev/null @@ -1,325 +0,0 @@ -#!/usr/bin/env bash -set -e - -# This script looks for bundles built by make.sh, and releases them on a -# public S3 bucket. -# -# Bundles should be available for the VERSION string passed as argument. -# -# The correct way to call this script is inside a container built by the -# official Dockerfile at the root of the Docker source code. The Dockerfile, -# make.sh and release.sh should all be from the same source code revision. - -set -o pipefail - -# Print a usage message and exit. -usage() { - cat >&2 <<'EOF' -To run, I need: -- to be in a container generated by the Dockerfile at the top of the Docker - repository; -- to be provided with the location of an S3 bucket and path, in - environment variables AWS_S3_BUCKET and AWS_S3_BUCKET_PATH (default: ''); -- to be provided with AWS credentials for this S3 bucket, in environment - variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY; -- a generous amount of good will and nice manners. -The canonical way to run me is to run the image produced by the Dockerfile: e.g.:" - -docker run -e AWS_S3_BUCKET=test.docker.com \ - -e AWS_ACCESS_KEY_ID \ - -e AWS_SECRET_ACCESS_KEY \ - -e AWS_DEFAULT_REGION \ - -it --privileged \ - docker ./hack/release.sh -EOF - exit 1 -} - -[ "$AWS_S3_BUCKET" ] || usage -[ "$AWS_ACCESS_KEY_ID" ] || usage -[ "$AWS_SECRET_ACCESS_KEY" ] || usage -[ -d /go/src/github.com/docker/docker ] || usage -cd /go/src/github.com/docker/docker -[ -x hack/make.sh ] || usage - -export AWS_DEFAULT_REGION -: ${AWS_DEFAULT_REGION:=us-west-1} - -AWS_CLI=${AWS_CLI:-'aws'} - -RELEASE_BUNDLES=( - binary - cross - tgz -) - -if [ "$1" != '--release-regardless-of-test-failure' ]; then - RELEASE_BUNDLES=( - test-unit - "${RELEASE_BUNDLES[@]}" - test-integration-cli - ) -fi - -VERSION=$(< VERSION) -BUCKET=$AWS_S3_BUCKET -BUCKET_PATH=$BUCKET -[[ -n "$AWS_S3_BUCKET_PATH" ]] && BUCKET_PATH+=/$AWS_S3_BUCKET_PATH - -if command -v git &> /dev/null && git rev-parse &> /dev/null; then - if [ -n "$(git status --porcelain --untracked-files=no)" ]; then - echo "You cannot run the release script on a repo with uncommitted changes" - usage - fi -fi - -# These are the 2 keys we've used to sign the deb's -# release (get.docker.com) -# GPG_KEY="36A1D7869245C8950F966E92D8576A8BA88D21E9" -# test (test.docker.com) -# GPG_KEY="740B314AE3941731B942C66ADF4FD13717AAD7D6" - -setup_s3() { - echo "Setting up S3" - # Try creating the bucket. Ignore errors (it might already exist). - $AWS_CLI s3 mb "s3://$BUCKET" 2>/dev/null || true - # Check access to the bucket. - $AWS_CLI s3 ls "s3://$BUCKET" >/dev/null - # Make the bucket accessible through website endpoints. - $AWS_CLI s3 website --index-document index --error-document error "s3://$BUCKET" -} - -# write_to_s3 uploads the contents of standard input to the specified S3 url. -write_to_s3() { - DEST=$1 - F=`mktemp` - cat > "$F" - $AWS_CLI s3 cp --acl public-read --content-type 'text/plain' "$F" "$DEST" - rm -f "$F" -} - -s3_url() { - case "$BUCKET" in - get.docker.com|test.docker.com|experimental.docker.com) - echo "https://$BUCKET_PATH" - ;; - *) - BASE_URL="http://${BUCKET}.s3-website-${AWS_DEFAULT_REGION}.amazonaws.com" - if [[ -n "$AWS_S3_BUCKET_PATH" ]] ; then - echo "$BASE_URL/$AWS_S3_BUCKET_PATH" - else - echo "$BASE_URL" - fi - ;; - esac -} - -build_all() { - echo "Building release" - if ! ./hack/make.sh "${RELEASE_BUNDLES[@]}"; then - echo >&2 - echo >&2 'The build or tests appear to have failed.' - echo >&2 - echo >&2 'You, as the release maintainer, now have a couple options:' - echo >&2 '- delay release and fix issues' - echo >&2 '- delay release and fix issues' - echo >&2 '- did we mention how important this is? issues need fixing :)' - echo >&2 - echo >&2 'As a final LAST RESORT, you (because only you, the release maintainer,' - echo >&2 ' really knows all the hairy problems at hand with the current release' - echo >&2 ' issues) may bypass this checking by running this script again with the' - echo >&2 ' single argument of "--release-regardless-of-test-failure", which will skip' - echo >&2 ' running the test suite, and will only build the binaries and packages. Please' - echo >&2 ' avoid using this if at all possible.' - echo >&2 - echo >&2 'Regardless, we cannot stress enough the scarcity with which this bypass' - echo >&2 ' should be used. If there are release issues, we should always err on the' - echo >&2 ' side of caution.' - echo >&2 - exit 1 - fi -} - -upload_release_build() { - src="$1" - dst="$2" - latest="$3" - - echo - echo "Uploading $src" - echo " to $dst" - echo - $AWS_CLI s3 cp --follow-symlinks --acl public-read "$src" "$dst" - if [ "$latest" ]; then - echo - echo "Copying to $latest" - echo - $AWS_CLI s3 cp --acl public-read "$dst" "$latest" - fi - - # get hash files too (see hash_files() in hack/make.sh) - for hashAlgo in md5 sha256; do - if [ -e "$src.$hashAlgo" ]; then - echo - echo "Uploading $src.$hashAlgo" - echo " to $dst.$hashAlgo" - echo - $AWS_CLI s3 cp --follow-symlinks --acl public-read --content-type='text/plain' "$src.$hashAlgo" "$dst.$hashAlgo" - if [ "$latest" ]; then - echo - echo "Copying to $latest.$hashAlgo" - echo - $AWS_CLI s3 cp --acl public-read "$dst.$hashAlgo" "$latest.$hashAlgo" - fi - fi - done -} - -release_build() { - echo "Releasing binaries" - GOOS=$1 - GOARCH=$2 - - binDir=bundles/$VERSION/cross/$GOOS/$GOARCH - tgzDir=bundles/$VERSION/tgz/$GOOS/$GOARCH - binary=docker-$VERSION - zipExt=".tgz" - binaryExt="" - tgz=$binary$zipExt - - latestBase= - if [ -z "$NOLATEST" ]; then - latestBase=docker-latest - fi - - # we need to map our GOOS and GOARCH to uname values - # see https://en.wikipedia.org/wiki/Uname - # ie, GOOS=linux -> "uname -s"=Linux - - s3Os=$GOOS - case "$s3Os" in - darwin) - s3Os=Darwin - ;; - freebsd) - s3Os=FreeBSD - ;; - linux) - s3Os=Linux - ;; - solaris) - echo skipping solaris release - return 0 - ;; - windows) - # this is windows use the .zip and .exe extensions for the files. - s3Os=Windows - zipExt=".zip" - binaryExt=".exe" - tgz=$binary$zipExt - binary+=$binaryExt - ;; - *) - echo >&2 "error: can't convert $s3Os to an appropriate value for 'uname -s'" - exit 1 - ;; - esac - - s3Arch=$GOARCH - case "$s3Arch" in - amd64) - s3Arch=x86_64 - ;; - 386) - s3Arch=i386 - ;; - arm) - s3Arch=armel - # someday, we might potentially support multiple GOARM values, in which case we might get armhf here too - ;; - *) - echo >&2 "error: can't convert $s3Arch to an appropriate value for 'uname -m'" - exit 1 - ;; - esac - - s3Dir="s3://$BUCKET_PATH/builds/$s3Os/$s3Arch" - # latest= - latestTgz= - if [ "$latestBase" ]; then - # commented out since we aren't uploading binaries right now. - # latest="$s3Dir/$latestBase$binaryExt" - # we don't include the $binaryExt because we don't want docker.exe.zip - latestTgz="$s3Dir/$latestBase$zipExt" - fi - - if [ ! -f "$tgzDir/$tgz" ]; then - echo >&2 "error: can't find $tgzDir/$tgz - was it packaged properly?" - exit 1 - fi - # disable binary uploads for now. Only providing tgz downloads - # upload_release_build "$binDir/$binary" "$s3Dir/$binary" "$latest" - upload_release_build "$tgzDir/$tgz" "$s3Dir/$tgz" "$latestTgz" -} - -# Upload binaries and tgz files to S3 -release_binaries() { - [ "$(find bundles/$VERSION -path "bundles/$VERSION/cross/*/*/docker-$VERSION")" != "" ] || { - echo >&2 './hack/make.sh must be run before release_binaries' - exit 1 - } - - for d in bundles/$VERSION/cross/*/*; do - GOARCH="$(basename "$d")" - GOOS="$(basename "$(dirname "$d")")" - release_build "$GOOS" "$GOARCH" - done - - # TODO create redirect from builds/*/i686 to builds/*/i386 - - cat < /dev/null - # Let see if the working directory is clean - diffs="$(git status --porcelain -- cli/compose/schema 2>/dev/null)" - if [ "$diffs" ]; then - { - echo 'The result of `go generate github.com/docker/docker/cli/compose/schema` differs' - echo - echo "$diffs" - echo - echo 'Please run `go generate github.com/docker/docker/cli/compose/schema`' - } >&2 - false - else - echo 'Congratulations! cli/compose/schema/bindata.go is up-to-date.' - fi -else - echo 'No cli/compose/schema/data changes in diff.' -fi diff --git a/vendor/github.com/docker/docker/hack/validate/dco b/vendor/github.com/docker/docker/hack/validate/dco deleted file mode 100755 index 754ce8f..0000000 --- a/vendor/github.com/docker/docker/hack/validate/dco +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }') -dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }') -#notDocs="$(validate_diff --numstat | awk '$3 !~ /^docs\// { print $3 }')" - -: ${adds:=0} -: ${dels:=0} - -# "Username may only contain alphanumeric characters or dashes and cannot begin with a dash" -githubUsernameRegex='[a-zA-Z0-9][a-zA-Z0-9-]+' - -# https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work -dcoPrefix='Signed-off-by:' -dcoRegex="^(Docker-DCO-1.1-)?$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)>( \\(github: ($githubUsernameRegex)\\))?$" - -check_dco() { - grep -qE "$dcoRegex" -} - -if [ $adds -eq 0 -a $dels -eq 0 ]; then - echo '0 adds, 0 deletions; nothing to validate! :)' -else - commits=( $(validate_log --format='format:%H%n') ) - badCommits=() - for commit in "${commits[@]}"; do - if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then - # no content (ie, Merge commit, etc) - continue - fi - if ! git log -1 --format='format:%B' "$commit" | check_dco; then - badCommits+=( "$commit" ) - fi - done - if [ ${#badCommits[@]} -eq 0 ]; then - echo "Congratulations! All commits are properly signed with the DCO!" - else - { - echo "These commits do not have a proper '$dcoPrefix' marker:" - for commit in "${badCommits[@]}"; do - echo " - $commit" - done - echo - echo 'Please amend each commit to include a properly formatted DCO marker.' - echo - echo 'Visit the following URL for information about the Docker DCO:' - echo ' https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work' - echo - } >&2 - false - fi -fi diff --git a/vendor/github.com/docker/docker/hack/validate/default b/vendor/github.com/docker/docker/hack/validate/default deleted file mode 100755 index 29b96ca..0000000 --- a/vendor/github.com/docker/docker/hack/validate/default +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -# -# Run default validation, exclude vendor because it's slow - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -. $SCRIPTDIR/dco -. $SCRIPTDIR/default-seccomp -. $SCRIPTDIR/gofmt -. $SCRIPTDIR/lint -. $SCRIPTDIR/pkg-imports -. $SCRIPTDIR/swagger -. $SCRIPTDIR/swagger-gen -. $SCRIPTDIR/test-imports -. $SCRIPTDIR/toml -. $SCRIPTDIR/vet diff --git a/vendor/github.com/docker/docker/hack/validate/default-seccomp b/vendor/github.com/docker/docker/hack/validate/default-seccomp deleted file mode 100755 index 8fe8435..0000000 --- a/vendor/github.com/docker/docker/hack/validate/default-seccomp +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- 'profiles/seccomp' || true) ) -unset IFS - -if [ ${#files[@]} -gt 0 ]; then - # We run 'go generate' and see if we have a diff afterwards - go generate ./profiles/seccomp/ >/dev/null - # Let see if the working directory is clean - diffs="$(git status --porcelain -- profiles/seccomp 2>/dev/null)" - if [ "$diffs" ]; then - { - echo 'The result of go generate ./profiles/seccomp/ differs' - echo - echo "$diffs" - echo - echo 'Please re-run go generate ./profiles/seccomp/' - echo - } >&2 - false - else - echo 'Congratulations! Seccomp profile generation is done correctly.' - fi -fi diff --git a/vendor/github.com/docker/docker/hack/validate/gofmt b/vendor/github.com/docker/docker/hack/validate/gofmt deleted file mode 100755 index 2040afa..0000000 --- a/vendor/github.com/docker/docker/hack/validate/gofmt +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | - grep -v '^vendor/' | - grep -v '^cli/compose/schema/bindata.go' || true) ) -unset IFS - -badFiles=() -for f in "${files[@]}"; do - # we use "git show" here to validate that what's committed is formatted - if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then - badFiles+=( "$f" ) - fi -done - -if [ ${#badFiles[@]} -eq 0 ]; then - echo 'Congratulations! All Go source files are properly formatted.' -else - { - echo "These files are not properly gofmt'd:" - for f in "${badFiles[@]}"; do - echo " - $f" - done - echo - echo 'Please reformat the above files using "gofmt -s -w" and commit the result.' - echo - } >&2 - false -fi diff --git a/vendor/github.com/docker/docker/hack/validate/lint b/vendor/github.com/docker/docker/hack/validate/lint deleted file mode 100755 index 4ac0a33..0000000 --- a/vendor/github.com/docker/docker/hack/validate/lint +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' | grep -v '^api/types/container/' | grep -v '^cli/compose/schema/bindata.go' || true) ) -unset IFS - -errors=() -for f in "${files[@]}"; do - failedLint=$(golint "$f") - if [ "$failedLint" ]; then - errors+=( "$failedLint" ) - fi -done - -if [ ${#errors[@]} -eq 0 ]; then - echo 'Congratulations! All Go source files have been linted.' -else - { - echo "Errors from golint:" - for err in "${errors[@]}"; do - echo "$err" - done - echo - echo 'Please fix the above errors. You can test via "golint" and commit the result.' - echo - } >&2 - false -fi diff --git a/vendor/github.com/docker/docker/hack/validate/pkg-imports b/vendor/github.com/docker/docker/hack/validate/pkg-imports deleted file mode 100755 index 9e4ea74..0000000 --- a/vendor/github.com/docker/docker/hack/validate/pkg-imports +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -set -e - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- 'pkg/*.go' || true) ) -unset IFS - -badFiles=() -for f in "${files[@]}"; do - IFS=$'\n' - badImports=( $(go list -e -f '{{ join .Deps "\n" }}' "$f" | sort -u | grep -vE '^github.com/docker/docker/pkg/' | grep -vE '^github.com/docker/docker/vendor' | grep -E '^github.com/docker/docker' || true) ) - unset IFS - - for import in "${badImports[@]}"; do - badFiles+=( "$f imports $import" ) - done -done - -if [ ${#badFiles[@]} -eq 0 ]; then - echo 'Congratulations! "./pkg/..." is safely isolated from internal code.' -else - { - echo 'These files import internal code: (either directly or indirectly)' - for f in "${badFiles[@]}"; do - echo " - $f" - done - echo - } >&2 - false -fi diff --git a/vendor/github.com/docker/docker/hack/validate/swagger b/vendor/github.com/docker/docker/hack/validate/swagger deleted file mode 100755 index e754fb8..0000000 --- a/vendor/github.com/docker/docker/hack/validate/swagger +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -e -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- 'api/swagger.yaml' || true) ) -unset IFS - -if [ ${#files[@]} -gt 0 ]; then - yamllint -c ${SCRIPTDIR}/.swagger-yamllint api/swagger.yaml - swagger validate api/swagger.yaml -fi diff --git a/vendor/github.com/docker/docker/hack/validate/swagger-gen b/vendor/github.com/docker/docker/hack/validate/swagger-gen deleted file mode 100755 index 008abc7..0000000 --- a/vendor/github.com/docker/docker/hack/validate/swagger-gen +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- 'api/types/' 'api/swagger.yaml' || true) ) -unset IFS - -if [ ${#files[@]} -gt 0 ]; then - ${SCRIPTDIR}/../generate-swagger-api.sh 2> /dev/null - # Let see if the working directory is clean - diffs="$(git status --porcelain -- api/types/ 2>/dev/null)" - if [ "$diffs" ]; then - { - echo 'The result of hack/generate-swagger-api.sh differs' - echo - echo "$diffs" - echo - echo 'Please update api/swagger.yaml with any api changes, then ' - echo 'run `hack/generate-swagger-api.sh`.' - } >&2 - false - else - echo 'Congratulations! All api changes are done the right way.' - fi -else - echo 'No api/types/ or api/swagger.yaml changes in diff.' -fi diff --git a/vendor/github.com/docker/docker/hack/validate/test-imports b/vendor/github.com/docker/docker/hack/validate/test-imports deleted file mode 100755 index 373caa2..0000000 --- a/vendor/github.com/docker/docker/hack/validate/test-imports +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -# Make sure we're not using gos' Testing package any more in integration-cli - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- 'integration-cli/*.go' || true) ) -unset IFS - -badFiles=() -for f in "${files[@]}"; do - # skip check_test.go since it *does* use the testing package - if [ "$f" = "integration-cli/check_test.go" ]; then - continue - fi - - # we use "git show" here to validate that what's committed doesn't contain golang built-in testing - if git show "$VALIDATE_HEAD:$f" | grep -q testing.T; then - if [ "$(echo $f | grep '_test')" ]; then - # allow testing.T for non- _test files - badFiles+=( "$f" ) - fi - fi -done - -if [ ${#badFiles[@]} -eq 0 ]; then - echo 'Congratulations! No testing.T found.' -else - { - echo "These files use the wrong testing infrastructure:" - for f in "${badFiles[@]}"; do - echo " - $f" - done - echo - } >&2 - false -fi diff --git a/vendor/github.com/docker/docker/hack/validate/toml b/vendor/github.com/docker/docker/hack/validate/toml deleted file mode 100755 index a0cb158..0000000 --- a/vendor/github.com/docker/docker/hack/validate/toml +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- 'MAINTAINERS' || true) ) -unset IFS - -badFiles=() -for f in "${files[@]}"; do - # we use "git show" here to validate that what's committed has valid toml syntax - if ! git show "$VALIDATE_HEAD:$f" | tomlv /proc/self/fd/0 ; then - badFiles+=( "$f" ) - fi -done - -if [ ${#badFiles[@]} -eq 0 ]; then - echo 'Congratulations! All toml source files changed here have valid syntax.' -else - { - echo "These files are not valid toml:" - for f in "${badFiles[@]}"; do - echo " - $f" - done - echo - echo 'Please reformat the above files as valid toml' - echo - } >&2 - false -fi diff --git a/vendor/github.com/docker/docker/hack/validate/vendor b/vendor/github.com/docker/docker/hack/validate/vendor deleted file mode 100755 index 0cb5aab..0000000 --- a/vendor/github.com/docker/docker/hack/validate/vendor +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) ) -unset IFS - -if [ ${#files[@]} -gt 0 ]; then - # We run vndr to and see if we have a diff afterwards - vndr - # Let see if the working directory is clean - diffs="$(git status --porcelain -- vendor 2>/dev/null)" - if [ "$diffs" ]; then - { - echo 'The result of vndr differs' - echo - echo "$diffs" - echo - echo 'Please vendor your package with github.com/LK4D4/vndr.' - echo - } >&2 - false - else - echo 'Congratulations! All vendoring changes are done the right way.' - fi -else - echo 'No vendor changes in diff.' -fi diff --git a/vendor/github.com/docker/docker/hack/validate/vet b/vendor/github.com/docker/docker/hack/validate/vet deleted file mode 100755 index 6476048..0000000 --- a/vendor/github.com/docker/docker/hack/validate/vet +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source "${SCRIPTDIR}/.validate" - -IFS=$'\n' -files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' | grep -v '^api/types/container/' || true) ) -unset IFS - -errors=() -for f in "${files[@]}"; do - failedVet=$(go vet "$f") - if [ "$failedVet" ]; then - errors+=( "$failedVet" ) - fi -done - - -if [ ${#errors[@]} -eq 0 ]; then - echo 'Congratulations! All Go source files have been vetted.' -else - { - echo "Errors from go vet:" - for err in "${errors[@]}"; do - echo " - $err" - done - echo - echo 'Please fix the above errors. You can test via "go vet" and commit the result.' - echo - } >&2 - false -fi diff --git a/vendor/github.com/docker/docker/hack/vendor.sh b/vendor/github.com/docker/docker/hack/vendor.sh deleted file mode 100755 index 9a4d038..0000000 --- a/vendor/github.com/docker/docker/hack/vendor.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# This file is just wrapper around vndr (github.com/LK4D4/vndr) tool. -# For updating dependencies you should change `vendor.conf` file in root of the -# project. Please refer to https://github.com/LK4D4/vndr/blob/master/README.md for -# vndr usage. - -set -e - -if ! hash vndr; then - echo "Please install vndr with \"go get github.com/LK4D4/vndr\" and put it in your \$GOPATH" - exit 1 -fi - -vndr "$@" diff --git a/vendor/github.com/docker/docker/image/fs.go b/vendor/github.com/docker/docker/image/fs.go deleted file mode 100644 index 39cfbf5..0000000 --- a/vendor/github.com/docker/docker/image/fs.go +++ /dev/null @@ -1,173 +0,0 @@ -package image - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/pkg/ioutils" -) - -// DigestWalkFunc is function called by StoreBackend.Walk -type DigestWalkFunc func(id digest.Digest) error - -// StoreBackend provides interface for image.Store persistence -type StoreBackend interface { - Walk(f DigestWalkFunc) error - Get(id digest.Digest) ([]byte, error) - Set(data []byte) (digest.Digest, error) - Delete(id digest.Digest) error - SetMetadata(id digest.Digest, key string, data []byte) error - GetMetadata(id digest.Digest, key string) ([]byte, error) - DeleteMetadata(id digest.Digest, key string) error -} - -// fs implements StoreBackend using the filesystem. -type fs struct { - sync.RWMutex - root string -} - -const ( - contentDirName = "content" - metadataDirName = "metadata" -) - -// NewFSStoreBackend returns new filesystem based backend for image.Store -func NewFSStoreBackend(root string) (StoreBackend, error) { - return newFSStore(root) -} - -func newFSStore(root string) (*fs, error) { - s := &fs{ - root: root, - } - if err := os.MkdirAll(filepath.Join(root, contentDirName, string(digest.Canonical)), 0700); err != nil { - return nil, err - } - if err := os.MkdirAll(filepath.Join(root, metadataDirName, string(digest.Canonical)), 0700); err != nil { - return nil, err - } - return s, nil -} - -func (s *fs) contentFile(dgst digest.Digest) string { - return filepath.Join(s.root, contentDirName, string(dgst.Algorithm()), dgst.Hex()) -} - -func (s *fs) metadataDir(dgst digest.Digest) string { - return filepath.Join(s.root, metadataDirName, string(dgst.Algorithm()), dgst.Hex()) -} - -// Walk calls the supplied callback for each image ID in the storage backend. -func (s *fs) Walk(f DigestWalkFunc) error { - // Only Canonical digest (sha256) is currently supported - s.RLock() - dir, err := ioutil.ReadDir(filepath.Join(s.root, contentDirName, string(digest.Canonical))) - s.RUnlock() - if err != nil { - return err - } - for _, v := range dir { - dgst := digest.NewDigestFromHex(string(digest.Canonical), v.Name()) - if err := dgst.Validate(); err != nil { - logrus.Debugf("Skipping invalid digest %s: %s", dgst, err) - continue - } - if err := f(dgst); err != nil { - return err - } - } - return nil -} - -// Get returns the content stored under a given digest. -func (s *fs) Get(dgst digest.Digest) ([]byte, error) { - s.RLock() - defer s.RUnlock() - - return s.get(dgst) -} - -func (s *fs) get(dgst digest.Digest) ([]byte, error) { - content, err := ioutil.ReadFile(s.contentFile(dgst)) - if err != nil { - return nil, err - } - - // todo: maybe optional - if digest.FromBytes(content) != dgst { - return nil, fmt.Errorf("failed to verify: %v", dgst) - } - - return content, nil -} - -// Set stores content by checksum. -func (s *fs) Set(data []byte) (digest.Digest, error) { - s.Lock() - defer s.Unlock() - - if len(data) == 0 { - return "", fmt.Errorf("Invalid empty data") - } - - dgst := digest.FromBytes(data) - if err := ioutils.AtomicWriteFile(s.contentFile(dgst), data, 0600); err != nil { - return "", err - } - - return dgst, nil -} - -// Delete removes content and metadata files associated with the digest. -func (s *fs) Delete(dgst digest.Digest) error { - s.Lock() - defer s.Unlock() - - if err := os.RemoveAll(s.metadataDir(dgst)); err != nil { - return err - } - if err := os.Remove(s.contentFile(dgst)); err != nil { - return err - } - return nil -} - -// SetMetadata sets metadata for a given ID. It fails if there's no base file. -func (s *fs) SetMetadata(dgst digest.Digest, key string, data []byte) error { - s.Lock() - defer s.Unlock() - if _, err := s.get(dgst); err != nil { - return err - } - - baseDir := filepath.Join(s.metadataDir(dgst)) - if err := os.MkdirAll(baseDir, 0700); err != nil { - return err - } - return ioutils.AtomicWriteFile(filepath.Join(s.metadataDir(dgst), key), data, 0600) -} - -// GetMetadata returns metadata for a given digest. -func (s *fs) GetMetadata(dgst digest.Digest, key string) ([]byte, error) { - s.RLock() - defer s.RUnlock() - - if _, err := s.get(dgst); err != nil { - return nil, err - } - return ioutil.ReadFile(filepath.Join(s.metadataDir(dgst), key)) -} - -// DeleteMetadata removes the metadata associated with a digest. -func (s *fs) DeleteMetadata(dgst digest.Digest, key string) error { - s.Lock() - defer s.Unlock() - - return os.RemoveAll(filepath.Join(s.metadataDir(dgst), key)) -} diff --git a/vendor/github.com/docker/docker/image/fs_test.go b/vendor/github.com/docker/docker/image/fs_test.go deleted file mode 100644 index 8d602d9..0000000 --- a/vendor/github.com/docker/docker/image/fs_test.go +++ /dev/null @@ -1,384 +0,0 @@ -package image - -import ( - "bytes" - "crypto/rand" - "crypto/sha256" - "encoding/hex" - "errors" - "io/ioutil" - "os" - "path/filepath" - "testing" - - "github.com/docker/distribution/digest" -) - -func TestFSGetSet(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - testGetSet(t, fs) -} - -func TestFSGetInvalidData(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - id, err := fs.Set([]byte("foobar")) - if err != nil { - t.Fatal(err) - } - - dgst := digest.Digest(id) - - if err := ioutil.WriteFile(filepath.Join(tmpdir, contentDirName, string(dgst.Algorithm()), dgst.Hex()), []byte("foobar2"), 0600); err != nil { - t.Fatal(err) - } - - _, err = fs.Get(id) - if err == nil { - t.Fatal("Expected get to fail after data modification.") - } -} - -func TestFSInvalidSet(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - id := digest.FromBytes([]byte("foobar")) - err = os.Mkdir(filepath.Join(tmpdir, contentDirName, string(id.Algorithm()), id.Hex()), 0700) - if err != nil { - t.Fatal(err) - } - - _, err = fs.Set([]byte("foobar")) - if err == nil { - t.Fatal("Expecting error from invalid filesystem data.") - } -} - -func TestFSInvalidRoot(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - tcases := []struct { - root, invalidFile string - }{ - {"root", "root"}, - {"root", "root/content"}, - {"root", "root/metadata"}, - } - - for _, tc := range tcases { - root := filepath.Join(tmpdir, tc.root) - filePath := filepath.Join(tmpdir, tc.invalidFile) - err := os.MkdirAll(filepath.Dir(filePath), 0700) - if err != nil { - t.Fatal(err) - } - f, err := os.Create(filePath) - if err != nil { - t.Fatal(err) - } - f.Close() - - _, err = NewFSStoreBackend(root) - if err == nil { - t.Fatalf("Expected error from root %q and invlid file %q", tc.root, tc.invalidFile) - } - - os.RemoveAll(root) - } - -} - -func testMetadataGetSet(t *testing.T, store StoreBackend) { - id, err := store.Set([]byte("foo")) - if err != nil { - t.Fatal(err) - } - id2, err := store.Set([]byte("bar")) - if err != nil { - t.Fatal(err) - } - - tcases := []struct { - id digest.Digest - key string - value []byte - }{ - {id, "tkey", []byte("tval1")}, - {id, "tkey2", []byte("tval2")}, - {id2, "tkey", []byte("tval3")}, - } - - for _, tc := range tcases { - err = store.SetMetadata(tc.id, tc.key, tc.value) - if err != nil { - t.Fatal(err) - } - - actual, err := store.GetMetadata(tc.id, tc.key) - if err != nil { - t.Fatal(err) - } - if bytes.Compare(actual, tc.value) != 0 { - t.Fatalf("Metadata expected %q, got %q", tc.value, actual) - } - } - - _, err = store.GetMetadata(id2, "tkey2") - if err == nil { - t.Fatal("Expected error for getting metadata for unknown key") - } - - id3 := digest.FromBytes([]byte("baz")) - err = store.SetMetadata(id3, "tkey", []byte("tval")) - if err == nil { - t.Fatal("Expected error for setting metadata for unknown ID.") - } - - _, err = store.GetMetadata(id3, "tkey") - if err == nil { - t.Fatal("Expected error for getting metadata for unknown ID.") - } -} - -func TestFSMetadataGetSet(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - testMetadataGetSet(t, fs) -} - -func TestFSDelete(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - testDelete(t, fs) -} - -func TestFSWalker(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - testWalker(t, fs) -} - -func TestFSInvalidWalker(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - fooID, err := fs.Set([]byte("foo")) - if err != nil { - t.Fatal(err) - } - - if err := ioutil.WriteFile(filepath.Join(tmpdir, contentDirName, "sha256/foobar"), []byte("foobar"), 0600); err != nil { - t.Fatal(err) - } - - n := 0 - err = fs.Walk(func(id digest.Digest) error { - if id != fooID { - t.Fatalf("Invalid walker ID %q, expected %q", id, fooID) - } - n++ - return nil - }) - if err != nil { - t.Fatalf("Invalid data should not have caused walker error, got %v", err) - } - if n != 1 { - t.Fatalf("Expected 1 walk initialization, got %d", n) - } -} - -func testGetSet(t *testing.T, store StoreBackend) { - type tcase struct { - input []byte - expected digest.Digest - } - tcases := []tcase{ - {[]byte("foobar"), digest.Digest("sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2")}, - } - - randomInput := make([]byte, 8*1024) - _, err := rand.Read(randomInput) - if err != nil { - t.Fatal(err) - } - // skipping use of digest pkg because its used by the implementation - h := sha256.New() - _, err = h.Write(randomInput) - if err != nil { - t.Fatal(err) - } - tcases = append(tcases, tcase{ - input: randomInput, - expected: digest.Digest("sha256:" + hex.EncodeToString(h.Sum(nil))), - }) - - for _, tc := range tcases { - id, err := store.Set([]byte(tc.input)) - if err != nil { - t.Fatal(err) - } - if id != tc.expected { - t.Fatalf("Expected ID %q, got %q", tc.expected, id) - } - } - - for _, emptyData := range [][]byte{nil, {}} { - _, err := store.Set(emptyData) - if err == nil { - t.Fatal("Expected error for nil input.") - } - } - - for _, tc := range tcases { - data, err := store.Get(tc.expected) - if err != nil { - t.Fatal(err) - } - if bytes.Compare(data, tc.input) != 0 { - t.Fatalf("Expected data %q, got %q", tc.input, data) - } - } - - for _, key := range []digest.Digest{"foobar:abc", "sha256:abc", "sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2a"} { - _, err := store.Get(key) - if err == nil { - t.Fatalf("Expected error for ID %q.", key) - } - } - -} - -func testDelete(t *testing.T, store StoreBackend) { - id, err := store.Set([]byte("foo")) - if err != nil { - t.Fatal(err) - } - id2, err := store.Set([]byte("bar")) - if err != nil { - t.Fatal(err) - } - - err = store.Delete(id) - if err != nil { - t.Fatal(err) - } - - _, err = store.Get(id) - if err == nil { - t.Fatalf("Expected getting deleted item %q to fail", id) - } - _, err = store.Get(id2) - if err != nil { - t.Fatal(err) - } - - err = store.Delete(id2) - if err != nil { - t.Fatal(err) - } - _, err = store.Get(id2) - if err == nil { - t.Fatalf("Expected getting deleted item %q to fail", id2) - } -} - -func testWalker(t *testing.T, store StoreBackend) { - id, err := store.Set([]byte("foo")) - if err != nil { - t.Fatal(err) - } - id2, err := store.Set([]byte("bar")) - if err != nil { - t.Fatal(err) - } - - tcases := make(map[digest.Digest]struct{}) - tcases[id] = struct{}{} - tcases[id2] = struct{}{} - n := 0 - err = store.Walk(func(id digest.Digest) error { - delete(tcases, id) - n++ - return nil - }) - if err != nil { - t.Fatal(err) - } - - if n != 2 { - t.Fatalf("Expected 2 walk initializations, got %d", n) - } - if len(tcases) != 0 { - t.Fatalf("Expected empty unwalked set, got %+v", tcases) - } - - // stop on error - tcases = make(map[digest.Digest]struct{}) - tcases[id] = struct{}{} - err = store.Walk(func(id digest.Digest) error { - return errors.New("") - }) - if err == nil { - t.Fatalf("Exected error from walker.") - } -} diff --git a/vendor/github.com/docker/docker/image/image.go b/vendor/github.com/docker/docker/image/image.go deleted file mode 100644 index 29a990a..0000000 --- a/vendor/github.com/docker/docker/image/image.go +++ /dev/null @@ -1,150 +0,0 @@ -package image - -import ( - "encoding/json" - "errors" - "io" - "time" - - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types/container" -) - -// ID is the content-addressable ID of an image. -type ID digest.Digest - -func (id ID) String() string { - return id.Digest().String() -} - -// Digest converts ID into a digest -func (id ID) Digest() digest.Digest { - return digest.Digest(id) -} - -// IDFromDigest creates an ID from a digest -func IDFromDigest(digest digest.Digest) ID { - return ID(digest) -} - -// V1Image stores the V1 image configuration. -type V1Image struct { - // ID a unique 64 character identifier of the image - ID string `json:"id,omitempty"` - // Parent id of the image - Parent string `json:"parent,omitempty"` - // Comment user added comment - Comment string `json:"comment,omitempty"` - // Created timestamp when image was created - Created time.Time `json:"created"` - // Container is the id of the container used to commit - Container string `json:"container,omitempty"` - // ContainerConfig is the configuration of the container that is committed into the image - ContainerConfig container.Config `json:"container_config,omitempty"` - // DockerVersion specifies version on which image is built - DockerVersion string `json:"docker_version,omitempty"` - // Author of the image - Author string `json:"author,omitempty"` - // Config is the configuration of the container received from the client - Config *container.Config `json:"config,omitempty"` - // Architecture is the hardware that the image is build and runs on - Architecture string `json:"architecture,omitempty"` - // OS is the operating system used to build and run the image - OS string `json:"os,omitempty"` - // Size is the total size of the image including all layers it is composed of - Size int64 `json:",omitempty"` -} - -// Image stores the image configuration -type Image struct { - V1Image - Parent ID `json:"parent,omitempty"` - RootFS *RootFS `json:"rootfs,omitempty"` - History []History `json:"history,omitempty"` - OSVersion string `json:"os.version,omitempty"` - OSFeatures []string `json:"os.features,omitempty"` - - // rawJSON caches the immutable JSON associated with this image. - rawJSON []byte - - // computedID is the ID computed from the hash of the image config. - // Not to be confused with the legacy V1 ID in V1Image. - computedID ID -} - -// RawJSON returns the immutable JSON associated with the image. -func (img *Image) RawJSON() []byte { - return img.rawJSON -} - -// ID returns the image's content-addressable ID. -func (img *Image) ID() ID { - return img.computedID -} - -// ImageID stringifies ID. -func (img *Image) ImageID() string { - return img.ID().String() -} - -// RunConfig returns the image's container config. -func (img *Image) RunConfig() *container.Config { - return img.Config -} - -// MarshalJSON serializes the image to JSON. It sorts the top-level keys so -// that JSON that's been manipulated by a push/pull cycle with a legacy -// registry won't end up with a different key order. -func (img *Image) MarshalJSON() ([]byte, error) { - type MarshalImage Image - - pass1, err := json.Marshal(MarshalImage(*img)) - if err != nil { - return nil, err - } - - var c map[string]*json.RawMessage - if err := json.Unmarshal(pass1, &c); err != nil { - return nil, err - } - return json.Marshal(c) -} - -// History stores build commands that were used to create an image -type History struct { - // Created timestamp for build point - Created time.Time `json:"created"` - // Author of the build point - Author string `json:"author,omitempty"` - // CreatedBy keeps the Dockerfile command used while building image. - CreatedBy string `json:"created_by,omitempty"` - // Comment is custom message set by the user when creating the image. - Comment string `json:"comment,omitempty"` - // EmptyLayer is set to true if this history item did not generate a - // layer. Otherwise, the history item is associated with the next - // layer in the RootFS section. - EmptyLayer bool `json:"empty_layer,omitempty"` -} - -// Exporter provides interface for exporting and importing images -type Exporter interface { - Load(io.ReadCloser, io.Writer, bool) error - // TODO: Load(net.Context, io.ReadCloser, <- chan StatusMessage) error - Save([]string, io.Writer) error -} - -// NewFromJSON creates an Image configuration from json. -func NewFromJSON(src []byte) (*Image, error) { - img := &Image{} - - if err := json.Unmarshal(src, img); err != nil { - return nil, err - } - if img.RootFS == nil { - return nil, errors.New("Invalid image JSON, no RootFS key.") - } - - img.rawJSON = src - - return img, nil -} diff --git a/vendor/github.com/docker/docker/image/image_test.go b/vendor/github.com/docker/docker/image/image_test.go deleted file mode 100644 index 525023b..0000000 --- a/vendor/github.com/docker/docker/image/image_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package image - -import ( - "encoding/json" - "sort" - "strings" - "testing" -) - -const sampleImageJSON = `{ - "architecture": "amd64", - "os": "linux", - "config": {}, - "rootfs": { - "type": "layers", - "diff_ids": [] - } -}` - -func TestJSON(t *testing.T) { - img, err := NewFromJSON([]byte(sampleImageJSON)) - if err != nil { - t.Fatal(err) - } - rawJSON := img.RawJSON() - if string(rawJSON) != sampleImageJSON { - t.Fatalf("Raw JSON of config didn't match: expected %+v, got %v", sampleImageJSON, rawJSON) - } -} - -func TestInvalidJSON(t *testing.T) { - _, err := NewFromJSON([]byte("{}")) - if err == nil { - t.Fatal("Expected JSON parse error") - } -} - -func TestMarshalKeyOrder(t *testing.T) { - b, err := json.Marshal(&Image{ - V1Image: V1Image{ - Comment: "a", - Author: "b", - Architecture: "c", - }, - }) - if err != nil { - t.Fatal(err) - } - - expectedOrder := []string{"architecture", "author", "comment"} - var indexes []int - for _, k := range expectedOrder { - indexes = append(indexes, strings.Index(string(b), k)) - } - - if !sort.IntsAreSorted(indexes) { - t.Fatal("invalid key order in JSON: ", string(b)) - } -} diff --git a/vendor/github.com/docker/docker/image/rootfs.go b/vendor/github.com/docker/docker/image/rootfs.go deleted file mode 100644 index 7b24e3e..0000000 --- a/vendor/github.com/docker/docker/image/rootfs.go +++ /dev/null @@ -1,44 +0,0 @@ -package image - -import ( - "runtime" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/layer" -) - -// TypeLayers is used for RootFS.Type for filesystems organized into layers. -const TypeLayers = "layers" - -// typeLayersWithBase is an older format used by Windows up to v1.12. We -// explicitly handle this as an error case to ensure that a daemon which still -// has an older image like this on disk can still start, even though the -// image itself is not usable. See https://github.com/docker/docker/pull/25806. -const typeLayersWithBase = "layers+base" - -// RootFS describes images root filesystem -// This is currently a placeholder that only supports layers. In the future -// this can be made into an interface that supports different implementations. -type RootFS struct { - Type string `json:"type"` - DiffIDs []layer.DiffID `json:"diff_ids,omitempty"` -} - -// NewRootFS returns empty RootFS struct -func NewRootFS() *RootFS { - return &RootFS{Type: TypeLayers} -} - -// Append appends a new diffID to rootfs -func (r *RootFS) Append(id layer.DiffID) { - r.DiffIDs = append(r.DiffIDs, id) -} - -// ChainID returns the ChainID for the top layer in RootFS. -func (r *RootFS) ChainID() layer.ChainID { - if runtime.GOOS == "windows" && r.Type == typeLayersWithBase { - logrus.Warnf("Layer type is unsupported on this platform. DiffIDs: '%v'", r.DiffIDs) - return "" - } - return layer.CreateChainID(r.DiffIDs) -} diff --git a/vendor/github.com/docker/docker/image/spec/v1.1.md b/vendor/github.com/docker/docker/image/spec/v1.1.md deleted file mode 100644 index 83f1380..0000000 --- a/vendor/github.com/docker/docker/image/spec/v1.1.md +++ /dev/null @@ -1,637 +0,0 @@ -# Docker Image Specification v1.1.0 - -An *Image* is an ordered collection of root filesystem changes and the -corresponding execution parameters for use within a container runtime. This -specification outlines the format of these filesystem changes and corresponding -parameters and describes how to create and use them for use with a container -runtime and execution tool. - -This version of the image specification was adopted starting in Docker 1.10. - -## Terminology - -This specification uses the following terms: - -
-
- Layer -
-
- Images are composed of layers. Each layer is a set of filesystem - changes. Layers do not have configuration metadata such as environment - variables or default arguments - these are properties of the image as a - whole rather than any particular layer. -
-
- Image JSON -
-
- Each image has an associated JSON structure which describes some - basic information about the image such as date created, author, and the - ID of its parent image as well as execution/runtime configuration like - its entry point, default arguments, CPU/memory shares, networking, and - volumes. The JSON structure also references a cryptographic hash of - each layer used by the image, and provides history information for - those layers. This JSON is considered to be immutable, because changing - it would change the computed ImageID. Changing it means creating a new - derived image, instead of changing the existing image. -
-
- Image Filesystem Changeset -
-
- Each layer has an archive of the files which have been added, changed, - or deleted relative to its parent layer. Using a layer-based or union - filesystem such as AUFS, or by computing the diff from filesystem - snapshots, the filesystem changeset can be used to present a series of - image layers as if they were one cohesive filesystem. -
-
- Layer DiffID -
-
- Layers are referenced by cryptographic hashes of their serialized - representation. This is a SHA256 digest over the tar archive used to - transport the layer, represented as a hexadecimal encoding of 256 bits, e.g., - sha256:a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9. - Layers must be packed and unpacked reproducibly to avoid changing the - layer ID, for example by using tar-split to save the tar headers. Note - that the digest used as the layer ID is taken over an uncompressed - version of the tar. -
-
- Layer ChainID -
-
- For convenience, it is sometimes useful to refer to a stack of layers - with a single identifier. This is called a ChainID. For a - single layer (or the layer at the bottom of a stack), the - ChainID is equal to the layer's DiffID. - Otherwise the ChainID is given by the formula: - ChainID(layerN) = SHA256hex(ChainID(layerN-1) + " " + DiffID(layerN)). -
-
- ImageID -
-
- Each image's ID is given by the SHA256 hash of its configuration JSON. It is - represented as a hexadecimal encoding of 256 bits, e.g., - sha256:a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9. - Since the configuration JSON that gets hashed references hashes of each - layer in the image, this formulation of the ImageID makes images - content-addressable. -
-
- Tag -
-
- A tag serves to map a descriptive, user-given name to any single image - ID. Tag values are limited to the set of characters - [a-zA-Z0-9_.-], except they may not start with a . - or - character. Tags are limited to 127 characters. -
-
- Repository -
-
- A collection of tags grouped under a common prefix (the name component - before :). For example, in an image tagged with the name - my-app:3.1.4, my-app is the Repository - component of the name. A repository name is made up of slash-separated - name components, optionally prefixed by a DNS hostname. The hostname - must follow comply with standard DNS rules, but may not contain - _ characters. If a hostname is present, it may optionally - be followed by a port number in the format :8080. - Name components may contain lowercase characters, digits, and - separators. A separator is defined as a period, one or two underscores, - or one or more dashes. A name component may not start or end with - a separator. -
-
- -## Image JSON Description - -Here is an example image JSON file: - -``` -{ - "created": "2015-10-31T22:22:56.015925234Z", - "author": "Alyssa P. Hacker <alyspdev@example.com>", - "architecture": "amd64", - "os": "linux", - "config": { - "User": "alice", - "Memory": 2048, - "MemorySwap": 4096, - "CpuShares": 8, - "ExposedPorts": { - "8080/tcp": {} - }, - "Env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", - "FOO=docker_is_a_really", - "BAR=great_tool_you_know" - ], - "Entrypoint": [ - "/bin/my-app-binary" - ], - "Cmd": [ - "--foreground", - "--config", - "/etc/my-app.d/default.cfg" - ], - "Volumes": { - "/var/job-result-data": {}, - "/var/log/my-app-logs": {}, - }, - "WorkingDir": "/home/alice", - }, - "rootfs": { - "diff_ids": [ - "sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1", - "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef" - ], - "type": "layers" - }, - "history": [ - { - "created": "2015-10-31T22:22:54.690851953Z", - "created_by": "/bin/sh -c #(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /" - }, - { - "created": "2015-10-31T22:22:55.613815829Z", - "created_by": "/bin/sh -c #(nop) CMD [\"sh\"]", - "empty_layer": true - } - ] -} -``` - -Note that image JSON files produced by Docker don't contain formatting -whitespace. It has been added to this example for clarity. - -### Image JSON Field Descriptions - -
-
- created string -
-
- ISO-8601 formatted combined date and time at which the image was - created. -
-
- author string -
-
- Gives the name and/or email address of the person or entity which - created and is responsible for maintaining the image. -
-
- architecture string -
-
- The CPU architecture which the binaries in this image are built to run - on. Possible values include: -
    -
  • 386
  • -
  • amd64
  • -
  • arm
  • -
- More values may be supported in the future and any of these may or may - not be supported by a given container runtime implementation. -
-
- os string -
-
- The name of the operating system which the image is built to run on. - Possible values include: -
    -
  • darwin
  • -
  • freebsd
  • -
  • linux
  • -
- More values may be supported in the future and any of these may or may - not be supported by a given container runtime implementation. -
-
- config struct -
-
- The execution parameters which should be used as a base when running a - container using the image. This field can be null, in - which case any execution parameters should be specified at creation of - the container. - -

Container RunConfig Field Descriptions

- -
-
- User string -
-
-

The username or UID which the process in the container should - run as. This acts as a default value to use when the value is - not specified when creating a container.

- -

All of the following are valid:

- -
    -
  • user
  • -
  • uid
  • -
  • user:group
  • -
  • uid:gid
  • -
  • uid:group
  • -
  • user:gid
  • -
- -

If group/gid is not specified, the - default group and supplementary groups of the given - user/uid in /etc/passwd - from the container are applied.

-
-
- Memory integer -
-
- Memory limit (in bytes). This acts as a default value to use - when the value is not specified when creating a container. -
-
- MemorySwap integer -
-
- Total memory usage (memory + swap); set to -1 to - disable swap. This acts as a default value to use when the - value is not specified when creating a container. -
-
- CpuShares integer -
-
- CPU shares (relative weight vs. other containers). This acts as - a default value to use when the value is not specified when - creating a container. -
-
- ExposedPorts struct -
-
- A set of ports to expose from a container running this image. - This JSON structure value is unusual because it is a direct - JSON serialization of the Go type - map[string]struct{} and is represented in JSON as - an object mapping its keys to an empty object. Here is an - example: - -
{
-    "8080": {},
-    "53/udp": {},
-    "2356/tcp": {}
-}
- - Its keys can be in the format of: -
    -
  • - "port/tcp" -
  • -
  • - "port/udp" -
  • -
  • - "port" -
  • -
- with the default protocol being "tcp" if not - specified. - - These values act as defaults and are merged with any specified - when creating a container. -
-
- Env array of strings -
-
- Entries are in the format of VARNAME="var value". - These values act as defaults and are merged with any specified - when creating a container. -
-
- Entrypoint array of strings -
-
- A list of arguments to use as the command to execute when the - container starts. This value acts as a default and is replaced - by an entrypoint specified when creating a container. -
-
- Cmd array of strings -
-
- Default arguments to the entry point of the container. These - values act as defaults and are replaced with any specified when - creating a container. If an Entrypoint value is - not specified, then the first entry of the Cmd - array should be interpreted as the executable to run. -
-
- Volumes struct -
-
- A set of directories which should be created as data volumes in - a container running this image. This JSON structure value is - unusual because it is a direct JSON serialization of the Go - type map[string]struct{} and is represented in - JSON as an object mapping its keys to an empty object. Here is - an example: -
{
-    "/var/my-app-data/": {},
-    "/etc/some-config.d/": {},
-}
-
-
- WorkingDir string -
-
- Sets the current working directory of the entry point process - in the container. This value acts as a default and is replaced - by a working directory specified when creating a container. -
-
-
-
- rootfs struct -
-
- The rootfs key references the layer content addresses used by the - image. This makes the image config hash depend on the filesystem hash. - rootfs has two subkeys: - -
    -
  • - type is usually set to layers. -
  • -
  • - diff_ids is an array of layer content hashes (DiffIDs), in order from bottom-most to top-most. -
  • -
- - - Here is an example rootfs section: - -
"rootfs": {
-  "diff_ids": [
-    "sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1",
-    "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
-    "sha256:13f53e08df5a220ab6d13c58b2bf83a59cbdc2e04d0a3f041ddf4b0ba4112d49"
-  ],
-  "type": "layers"
-}
-
-
- history struct -
-
- history is an array of objects describing the history of - each layer. The array is ordered from bottom-most layer to top-most - layer. The object has the following fields. - -
    -
  • - created: Creation time, expressed as a ISO-8601 formatted - combined date and time -
  • -
  • - author: The author of the build point -
  • -
  • - created_by: The command which created the layer -
  • -
  • - comment: A custom message set when creating the layer -
  • -
  • - empty_layer: This field is used to mark if the history - item created a filesystem diff. It is set to true if this history - item doesn't correspond to an actual layer in the rootfs section - (for example, a command like ENV which results in no change to the - filesystem). -
  • -
- -Here is an example history section: - -
"history": [
-  {
-    "created": "2015-10-31T22:22:54.690851953Z",
-    "created_by": "/bin/sh -c #(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /"
-  },
-  {
-    "created": "2015-10-31T22:22:55.613815829Z",
-    "created_by": "/bin/sh -c #(nop) CMD [\"sh\"]",
-    "empty_layer": true
-  }
-]
-
-
- -Any extra fields in the Image JSON struct are considered implementation -specific and should be ignored by any implementations which are unable to -interpret them. - -## Creating an Image Filesystem Changeset - -An example of creating an Image Filesystem Changeset follows. - -An image root filesystem is first created as an empty directory. Here is the -initial empty directory structure for the a changeset using the -randomly-generated directory name `c3167915dc9d` ([actual layer DiffIDs are -generated based on the content](#id_desc)). - -``` -c3167915dc9d/ -``` - -Files and directories are then created: - -``` -c3167915dc9d/ - etc/ - my-app-config - bin/ - my-app-binary - my-app-tools -``` - -The `c3167915dc9d` directory is then committed as a plain Tar archive with -entries for the following files: - -``` -etc/my-app-config -bin/my-app-binary -bin/my-app-tools -``` - -To make changes to the filesystem of this container image, create a new -directory, such as `f60c56784b83`, and initialize it with a snapshot of the -parent image's root filesystem, so that the directory is identical to that -of `c3167915dc9d`. NOTE: a copy-on-write or union filesystem can make this very -efficient: - -``` -f60c56784b83/ - etc/ - my-app-config - bin/ - my-app-binary - my-app-tools -``` - -This example change is going add a configuration directory at `/etc/my-app.d` -which contains a default config file. There's also a change to the -`my-app-tools` binary to handle the config layout change. The `f60c56784b83` -directory then looks like this: - -``` -f60c56784b83/ - etc/ - my-app.d/ - default.cfg - bin/ - my-app-binary - my-app-tools -``` - -This reflects the removal of `/etc/my-app-config` and creation of a file and -directory at `/etc/my-app.d/default.cfg`. `/bin/my-app-tools` has also been -replaced with an updated version. Before committing this directory to a -changeset, because it has a parent image, it is first compared with the -directory tree of the parent snapshot, `f60c56784b83`, looking for files and -directories that have been added, modified, or removed. The following changeset -is found: - -``` -Added: /etc/my-app.d/default.cfg -Modified: /bin/my-app-tools -Deleted: /etc/my-app-config -``` - -A Tar Archive is then created which contains *only* this changeset: The added -and modified files and directories in their entirety, and for each deleted item -an entry for an empty file at the same location but with the basename of the -deleted file or directory prefixed with `.wh.`. The filenames prefixed with -`.wh.` are known as "whiteout" files. NOTE: For this reason, it is not possible -to create an image root filesystem which contains a file or directory with a -name beginning with `.wh.`. The resulting Tar archive for `f60c56784b83` has -the following entries: - -``` -/etc/my-app.d/default.cfg -/bin/my-app-tools -/etc/.wh.my-app-config -``` - -Any given image is likely to be composed of several of these Image Filesystem -Changeset tar archives. - -## Combined Image JSON + Filesystem Changeset Format - -There is also a format for a single archive which contains complete information -about an image, including: - - - repository names/tags - - image configuration JSON file - - all tar archives of each layer filesystem changesets - -For example, here's what the full archive of `library/busybox` is (displayed in -`tree` format): - -``` -. -├── 47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb.json -├── 5f29f704785248ddb9d06b90a11b5ea36c534865e9035e4022bb2e71d4ecbb9a -│   ├── VERSION -│   ├── json -│   └── layer.tar -├── a65da33792c5187473faa80fa3e1b975acba06712852d1dea860692ccddf3198 -│   ├── VERSION -│   ├── json -│   └── layer.tar -├── manifest.json -└── repositories -``` - -There is a directory for each layer in the image. Each directory is named with -a 64 character hex name that is deterministically generated from the layer -information. These names are not necessarily layer DiffIDs or ChainIDs. Each of -these directories contains 3 files: - - * `VERSION` - The schema version of the `json` file - * `json` - The legacy JSON metadata for an image layer. In this version of - the image specification, layers don't have JSON metadata, but in - [version 1](v1.md), they did. A file is created for each layer in the - v1 format for backward compatibility. - * `layer.tar` - The Tar archive of the filesystem changeset for an image - layer. - -Note that this directory layout is only important for backward compatibility. -Current implementations use the paths specified in `manifest.json`. - -The content of the `VERSION` files is simply the semantic version of the JSON -metadata schema: - -``` -1.0 -``` - -The `repositories` file is another JSON file which describes names/tags: - -``` -{ - "busybox":{ - "latest":"5f29f704785248ddb9d06b90a11b5ea36c534865e9035e4022bb2e71d4ecbb9a" - } -} -``` - -Every key in this object is the name of a repository, and maps to a collection -of tag suffixes. Each tag maps to the ID of the image represented by that tag. -This file is only used for backwards compatibility. Current implementations use -the `manifest.json` file instead. - -The `manifest.json` file provides the image JSON for the top-level image, and -optionally for parent images that this image was derived from. It consists of -an array of metadata entries: - -``` -[ - { - "Config": "47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb.json", - "RepoTags": ["busybox:latest"], - "Layers": [ - "a65da33792c5187473faa80fa3e1b975acba06712852d1dea860692ccddf3198/layer.tar", - "5f29f704785248ddb9d06b90a11b5ea36c534865e9035e4022bb2e71d4ecbb9a/layer.tar" - ] - } -] -``` - -There is an entry in the array for each image. - -The `Config` field references another file in the tar which includes the image -JSON for this image. - -The `RepoTags` field lists references pointing to this image. - -The `Layers` field points to the filesystem changeset tars. - -An optional `Parent` field references the imageID of the parent image. This -parent must be part of the same `manifest.json` file. - -This file shouldn't be confused with the distribution manifest, used to push -and pull images. - -Generally, implementations that support this version of the spec will use -the `manifest.json` file if available, and older implementations will use the -legacy `*/json` files and `repositories`. diff --git a/vendor/github.com/docker/docker/image/spec/v1.2.md b/vendor/github.com/docker/docker/image/spec/v1.2.md deleted file mode 100644 index 6c641ca..0000000 --- a/vendor/github.com/docker/docker/image/spec/v1.2.md +++ /dev/null @@ -1,696 +0,0 @@ -# Docker Image Specification v1.2.0 - -An *Image* is an ordered collection of root filesystem changes and the -corresponding execution parameters for use within a container runtime. This -specification outlines the format of these filesystem changes and corresponding -parameters and describes how to create and use them for use with a container -runtime and execution tool. - -This version of the image specification was adopted starting in Docker 1.12. - -## Terminology - -This specification uses the following terms: - -
-
- Layer -
-
- Images are composed of layers. Each layer is a set of filesystem - changes. Layers do not have configuration metadata such as environment - variables or default arguments - these are properties of the image as a - whole rather than any particular layer. -
-
- Image JSON -
-
- Each image has an associated JSON structure which describes some - basic information about the image such as date created, author, and the - ID of its parent image as well as execution/runtime configuration like - its entry point, default arguments, CPU/memory shares, networking, and - volumes. The JSON structure also references a cryptographic hash of - each layer used by the image, and provides history information for - those layers. This JSON is considered to be immutable, because changing - it would change the computed ImageID. Changing it means creating a new - derived image, instead of changing the existing image. -
-
- Image Filesystem Changeset -
-
- Each layer has an archive of the files which have been added, changed, - or deleted relative to its parent layer. Using a layer-based or union - filesystem such as AUFS, or by computing the diff from filesystem - snapshots, the filesystem changeset can be used to present a series of - image layers as if they were one cohesive filesystem. -
-
- Layer DiffID -
-
- Layers are referenced by cryptographic hashes of their serialized - representation. This is a SHA256 digest over the tar archive used to - transport the layer, represented as a hexadecimal encoding of 256 bits, e.g., - sha256:a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9. - Layers must be packed and unpacked reproducibly to avoid changing the - layer ID, for example by using tar-split to save the tar headers. Note - that the digest used as the layer ID is taken over an uncompressed - version of the tar. -
-
- Layer ChainID -
-
- For convenience, it is sometimes useful to refer to a stack of layers - with a single identifier. This is called a ChainID. For a - single layer (or the layer at the bottom of a stack), the - ChainID is equal to the layer's DiffID. - Otherwise the ChainID is given by the formula: - ChainID(layerN) = SHA256hex(ChainID(layerN-1) + " " + DiffID(layerN)). -
-
- ImageID -
-
- Each image's ID is given by the SHA256 hash of its configuration JSON. It is - represented as a hexadecimal encoding of 256 bits, e.g., - sha256:a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9. - Since the configuration JSON that gets hashed references hashes of each - layer in the image, this formulation of the ImageID makes images - content-addressable. -
-
- Tag -
-
- A tag serves to map a descriptive, user-given name to any single image - ID. Tag values are limited to the set of characters - [a-zA-Z0-9_.-], except they may not start with a . - or - character. Tags are limited to 127 characters. -
-
- Repository -
-
- A collection of tags grouped under a common prefix (the name component - before :). For example, in an image tagged with the name - my-app:3.1.4, my-app is the Repository - component of the name. A repository name is made up of slash-separated - name components, optionally prefixed by a DNS hostname. The hostname - must follow comply with standard DNS rules, but may not contain - _ characters. If a hostname is present, it may optionally - be followed by a port number in the format :8080. - Name components may contain lowercase characters, digits, and - separators. A separator is defined as a period, one or two underscores, - or one or more dashes. A name component may not start or end with - a separator. -
-
- -## Image JSON Description - -Here is an example image JSON file: - -``` -{ - "created": "2015-10-31T22:22:56.015925234Z", - "author": "Alyssa P. Hacker <alyspdev@example.com>", - "architecture": "amd64", - "os": "linux", - "config": { - "User": "alice", - "Memory": 2048, - "MemorySwap": 4096, - "CpuShares": 8, - "ExposedPorts": { - "8080/tcp": {} - }, - "Env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", - "FOO=docker_is_a_really", - "BAR=great_tool_you_know" - ], - "Entrypoint": [ - "/bin/my-app-binary" - ], - "Cmd": [ - "--foreground", - "--config", - "/etc/my-app.d/default.cfg" - ], - "Volumes": { - "/var/job-result-data": {}, - "/var/log/my-app-logs": {}, - }, - "WorkingDir": "/home/alice", - }, - "rootfs": { - "diff_ids": [ - "sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1", - "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef" - ], - "type": "layers" - }, - "history": [ - { - "created": "2015-10-31T22:22:54.690851953Z", - "created_by": "/bin/sh -c #(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /" - }, - { - "created": "2015-10-31T22:22:55.613815829Z", - "created_by": "/bin/sh -c #(nop) CMD [\"sh\"]", - "empty_layer": true - } - ] -} -``` - -Note that image JSON files produced by Docker don't contain formatting -whitespace. It has been added to this example for clarity. - -### Image JSON Field Descriptions - -
-
- created string -
-
- ISO-8601 formatted combined date and time at which the image was - created. -
-
- author string -
-
- Gives the name and/or email address of the person or entity which - created and is responsible for maintaining the image. -
-
- architecture string -
-
- The CPU architecture which the binaries in this image are built to run - on. Possible values include: -
    -
  • 386
  • -
  • amd64
  • -
  • arm
  • -
- More values may be supported in the future and any of these may or may - not be supported by a given container runtime implementation. -
-
- os string -
-
- The name of the operating system which the image is built to run on. - Possible values include: -
    -
  • darwin
  • -
  • freebsd
  • -
  • linux
  • -
- More values may be supported in the future and any of these may or may - not be supported by a given container runtime implementation. -
-
- config struct -
-
- The execution parameters which should be used as a base when running a - container using the image. This field can be null, in - which case any execution parameters should be specified at creation of - the container. - -

Container RunConfig Field Descriptions

- -
-
- User string -
-
-

The username or UID which the process in the container should - run as. This acts as a default value to use when the value is - not specified when creating a container.

- -

All of the following are valid:

- -
    -
  • user
  • -
  • uid
  • -
  • user:group
  • -
  • uid:gid
  • -
  • uid:group
  • -
  • user:gid
  • -
- -

If group/gid is not specified, the - default group and supplementary groups of the given - user/uid in /etc/passwd - from the container are applied.

-
-
- Memory integer -
-
- Memory limit (in bytes). This acts as a default value to use - when the value is not specified when creating a container. -
-
- MemorySwap integer -
-
- Total memory usage (memory + swap); set to -1 to - disable swap. This acts as a default value to use when the - value is not specified when creating a container. -
-
- CpuShares integer -
-
- CPU shares (relative weight vs. other containers). This acts as - a default value to use when the value is not specified when - creating a container. -
-
- ExposedPorts struct -
-
- A set of ports to expose from a container running this image. - This JSON structure value is unusual because it is a direct - JSON serialization of the Go type - map[string]struct{} and is represented in JSON as - an object mapping its keys to an empty object. Here is an - example: - -
{
-    "8080": {},
-    "53/udp": {},
-    "2356/tcp": {}
-}
- - Its keys can be in the format of: -
    -
  • - "port/tcp" -
  • -
  • - "port/udp" -
  • -
  • - "port" -
  • -
- with the default protocol being "tcp" if not - specified. - - These values act as defaults and are merged with any specified - when creating a container. -
-
- Env array of strings -
-
- Entries are in the format of VARNAME="var value". - These values act as defaults and are merged with any specified - when creating a container. -
-
- Entrypoint array of strings -
-
- A list of arguments to use as the command to execute when the - container starts. This value acts as a default and is replaced - by an entrypoint specified when creating a container. -
-
- Cmd array of strings -
-
- Default arguments to the entry point of the container. These - values act as defaults and are replaced with any specified when - creating a container. If an Entrypoint value is - not specified, then the first entry of the Cmd - array should be interpreted as the executable to run. -
-
- Healthcheck struct -
-
- A test to perform to determine whether the container is healthy. - Here is an example: -
{
-  "Test": [
-      "CMD-SHELL",
-      "/usr/bin/check-health localhost"
-  ],
-  "Interval": 30000000000,
-  "Timeout": 10000000000,
-  "Retries": 3
-}
- The object has the following fields. -
-
- Test array of strings -
-
- The test to perform to check that the container is healthy. - The options are: -
    -
  • [] : inherit healthcheck from base image
  • -
  • ["NONE"] : disable healthcheck
  • -
  • ["CMD", arg1, arg2, ...] : exec arguments directly
  • -
  • ["CMD-SHELL", command] : run command with system's default shell
  • -
- - The test command should exit with a status of 0 if the container is healthy, - or with 1 if it is unhealthy. -
-
- Interval integer -
-
- Number of nanoseconds to wait between probe attempts. -
-
- Timeout integer -
-
- Number of nanoseconds to wait before considering the check to have hung. -
-
- Retries integer -
-
- The number of consecutive failures needed to consider a container as unhealthy. -
-
- - In each case, the field can be omitted to indicate that the - value should be inherited from the base layer. - - These values act as defaults and are merged with any specified - when creating a container. -
-
- Volumes struct -
-
- A set of directories which should be created as data volumes in - a container running this image. This JSON structure value is - unusual because it is a direct JSON serialization of the Go - type map[string]struct{} and is represented in - JSON as an object mapping its keys to an empty object. Here is - an example: -
{
-    "/var/my-app-data/": {},
-    "/etc/some-config.d/": {},
-}
-
-
- WorkingDir string -
-
- Sets the current working directory of the entry point process - in the container. This value acts as a default and is replaced - by a working directory specified when creating a container. -
-
-
-
- rootfs struct -
-
- The rootfs key references the layer content addresses used by the - image. This makes the image config hash depend on the filesystem hash. - rootfs has two subkeys: - -
    -
  • - type is usually set to layers. -
  • -
  • - diff_ids is an array of layer content hashes (DiffIDs), in order from bottom-most to top-most. -
  • -
- - - Here is an example rootfs section: - -
"rootfs": {
-  "diff_ids": [
-    "sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1",
-    "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
-    "sha256:13f53e08df5a220ab6d13c58b2bf83a59cbdc2e04d0a3f041ddf4b0ba4112d49"
-  ],
-  "type": "layers"
-}
-
-
- history struct -
-
- history is an array of objects describing the history of - each layer. The array is ordered from bottom-most layer to top-most - layer. The object has the following fields. - -
    -
  • - created: Creation time, expressed as a ISO-8601 formatted - combined date and time -
  • -
  • - author: The author of the build point -
  • -
  • - created_by: The command which created the layer -
  • -
  • - comment: A custom message set when creating the layer -
  • -
  • - empty_layer: This field is used to mark if the history - item created a filesystem diff. It is set to true if this history - item doesn't correspond to an actual layer in the rootfs section - (for example, a command like ENV which results in no change to the - filesystem). -
  • -
- -Here is an example history section: - -
"history": [
-  {
-    "created": "2015-10-31T22:22:54.690851953Z",
-    "created_by": "/bin/sh -c #(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /"
-  },
-  {
-    "created": "2015-10-31T22:22:55.613815829Z",
-    "created_by": "/bin/sh -c #(nop) CMD [\"sh\"]",
-    "empty_layer": true
-  }
-]
-
-
- -Any extra fields in the Image JSON struct are considered implementation -specific and should be ignored by any implementations which are unable to -interpret them. - -## Creating an Image Filesystem Changeset - -An example of creating an Image Filesystem Changeset follows. - -An image root filesystem is first created as an empty directory. Here is the -initial empty directory structure for the a changeset using the -randomly-generated directory name `c3167915dc9d` ([actual layer DiffIDs are -generated based on the content](#id_desc)). - -``` -c3167915dc9d/ -``` - -Files and directories are then created: - -``` -c3167915dc9d/ - etc/ - my-app-config - bin/ - my-app-binary - my-app-tools -``` - -The `c3167915dc9d` directory is then committed as a plain Tar archive with -entries for the following files: - -``` -etc/my-app-config -bin/my-app-binary -bin/my-app-tools -``` - -To make changes to the filesystem of this container image, create a new -directory, such as `f60c56784b83`, and initialize it with a snapshot of the -parent image's root filesystem, so that the directory is identical to that -of `c3167915dc9d`. NOTE: a copy-on-write or union filesystem can make this very -efficient: - -``` -f60c56784b83/ - etc/ - my-app-config - bin/ - my-app-binary - my-app-tools -``` - -This example change is going add a configuration directory at `/etc/my-app.d` -which contains a default config file. There's also a change to the -`my-app-tools` binary to handle the config layout change. The `f60c56784b83` -directory then looks like this: - -``` -f60c56784b83/ - etc/ - my-app.d/ - default.cfg - bin/ - my-app-binary - my-app-tools -``` - -This reflects the removal of `/etc/my-app-config` and creation of a file and -directory at `/etc/my-app.d/default.cfg`. `/bin/my-app-tools` has also been -replaced with an updated version. Before committing this directory to a -changeset, because it has a parent image, it is first compared with the -directory tree of the parent snapshot, `f60c56784b83`, looking for files and -directories that have been added, modified, or removed. The following changeset -is found: - -``` -Added: /etc/my-app.d/default.cfg -Modified: /bin/my-app-tools -Deleted: /etc/my-app-config -``` - -A Tar Archive is then created which contains *only* this changeset: The added -and modified files and directories in their entirety, and for each deleted item -an entry for an empty file at the same location but with the basename of the -deleted file or directory prefixed with `.wh.`. The filenames prefixed with -`.wh.` are known as "whiteout" files. NOTE: For this reason, it is not possible -to create an image root filesystem which contains a file or directory with a -name beginning with `.wh.`. The resulting Tar archive for `f60c56784b83` has -the following entries: - -``` -/etc/my-app.d/default.cfg -/bin/my-app-tools -/etc/.wh.my-app-config -``` - -Any given image is likely to be composed of several of these Image Filesystem -Changeset tar archives. - -## Combined Image JSON + Filesystem Changeset Format - -There is also a format for a single archive which contains complete information -about an image, including: - - - repository names/tags - - image configuration JSON file - - all tar archives of each layer filesystem changesets - -For example, here's what the full archive of `library/busybox` is (displayed in -`tree` format): - -``` -. -├── 47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb.json -├── 5f29f704785248ddb9d06b90a11b5ea36c534865e9035e4022bb2e71d4ecbb9a -│   ├── VERSION -│   ├── json -│   └── layer.tar -├── a65da33792c5187473faa80fa3e1b975acba06712852d1dea860692ccddf3198 -│   ├── VERSION -│   ├── json -│   └── layer.tar -├── manifest.json -└── repositories -``` - -There is a directory for each layer in the image. Each directory is named with -a 64 character hex name that is deterministically generated from the layer -information. These names are not necessarily layer DiffIDs or ChainIDs. Each of -these directories contains 3 files: - - * `VERSION` - The schema version of the `json` file - * `json` - The legacy JSON metadata for an image layer. In this version of - the image specification, layers don't have JSON metadata, but in - [version 1](v1.md), they did. A file is created for each layer in the - v1 format for backward compatibility. - * `layer.tar` - The Tar archive of the filesystem changeset for an image - layer. - -Note that this directory layout is only important for backward compatibility. -Current implementations use the paths specified in `manifest.json`. - -The content of the `VERSION` files is simply the semantic version of the JSON -metadata schema: - -``` -1.0 -``` - -The `repositories` file is another JSON file which describes names/tags: - -``` -{ - "busybox":{ - "latest":"5f29f704785248ddb9d06b90a11b5ea36c534865e9035e4022bb2e71d4ecbb9a" - } -} -``` - -Every key in this object is the name of a repository, and maps to a collection -of tag suffixes. Each tag maps to the ID of the image represented by that tag. -This file is only used for backwards compatibility. Current implementations use -the `manifest.json` file instead. - -The `manifest.json` file provides the image JSON for the top-level image, and -optionally for parent images that this image was derived from. It consists of -an array of metadata entries: - -``` -[ - { - "Config": "47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb.json", - "RepoTags": ["busybox:latest"], - "Layers": [ - "a65da33792c5187473faa80fa3e1b975acba06712852d1dea860692ccddf3198/layer.tar", - "5f29f704785248ddb9d06b90a11b5ea36c534865e9035e4022bb2e71d4ecbb9a/layer.tar" - ] - } -] -``` - -There is an entry in the array for each image. - -The `Config` field references another file in the tar which includes the image -JSON for this image. - -The `RepoTags` field lists references pointing to this image. - -The `Layers` field points to the filesystem changeset tars. - -An optional `Parent` field references the imageID of the parent image. This -parent must be part of the same `manifest.json` file. - -This file shouldn't be confused with the distribution manifest, used to push -and pull images. - -Generally, implementations that support this version of the spec will use -the `manifest.json` file if available, and older implementations will use the -legacy `*/json` files and `repositories`. diff --git a/vendor/github.com/docker/docker/image/spec/v1.md b/vendor/github.com/docker/docker/image/spec/v1.md deleted file mode 100644 index 57a599b..0000000 --- a/vendor/github.com/docker/docker/image/spec/v1.md +++ /dev/null @@ -1,573 +0,0 @@ -# Docker Image Specification v1.0.0 - -An *Image* is an ordered collection of root filesystem changes and the -corresponding execution parameters for use within a container runtime. This -specification outlines the format of these filesystem changes and corresponding -parameters and describes how to create and use them for use with a container -runtime and execution tool. - -## Terminology - -This specification uses the following terms: - -
-
- Layer -
-
- Images are composed of layers. Image layer is a general - term which may be used to refer to one or both of the following: - -
    -
  1. The metadata for the layer, described in the JSON format.
  2. -
  3. The filesystem changes described by a layer.
  4. -
- - To refer to the former you may use the term Layer JSON or - Layer Metadata. To refer to the latter you may use the term - Image Filesystem Changeset or Image Diff. -
-
- Image JSON -
-
- Each layer has an associated JSON structure which describes some - basic information about the image such as date created, author, and the - ID of its parent image as well as execution/runtime configuration like - its entry point, default arguments, CPU/memory shares, networking, and - volumes. -
-
- Image Filesystem Changeset -
-
- Each layer has an archive of the files which have been added, changed, - or deleted relative to its parent layer. Using a layer-based or union - filesystem such as AUFS, or by computing the diff from filesystem - snapshots, the filesystem changeset can be used to present a series of - image layers as if they were one cohesive filesystem. -
-
- Image ID -
-
- Each layer is given an ID upon its creation. It is - represented as a hexadecimal encoding of 256 bits, e.g., - a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9. - Image IDs should be sufficiently random so as to be globally unique. - 32 bytes read from /dev/urandom is sufficient for all - practical purposes. Alternatively, an image ID may be derived as a - cryptographic hash of image contents as the result is considered - indistinguishable from random. The choice is left up to implementors. -
-
- Image Parent -
-
- Most layer metadata structs contain a parent field which - refers to the Image from which another directly descends. An image - contains a separate JSON metadata file and set of changes relative to - the filesystem of its parent image. Image Ancestor and - Image Descendant are also common terms. -
-
- Image Checksum -
-
- Layer metadata structs contain a cryptographic hash of the contents of - the layer's filesystem changeset. Though the set of changes exists as a - simple Tar archive, two archives with identical filenames and content - will have different SHA digests if the last-access or last-modified - times of any entries differ. For this reason, image checksums are - generated using the TarSum algorithm which produces a cryptographic - hash of file contents and selected headers only. Details of this - algorithm are described in the separate TarSum specification. -
-
- Tag -
-
- A tag serves to map a descriptive, user-given name to any single image - ID. An image name suffix (the name component after :) is - often referred to as a tag as well, though it strictly refers to the - full name of an image. Acceptable values for a tag suffix are - implementation specific, but they SHOULD be limited to the set of - alphanumeric characters [a-zA-z0-9], punctuation - characters [._-], and MUST NOT contain a : - character. -
-
- Repository -
-
- A collection of tags grouped under a common prefix (the name component - before :). For example, in an image tagged with the name - my-app:3.1.4, my-app is the Repository - component of the name. Acceptable values for repository name are - implementation specific, but they SHOULD be limited to the set of - alphanumeric characters [a-zA-z0-9], and punctuation - characters [._-], however it MAY contain additional - / and : characters for organizational - purposes, with the last : character being interpreted - dividing the repository component of the name from the tag suffix - component. -
-
- -## Image JSON Description - -Here is an example image JSON file: - -``` -{ - "id": "a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9", - "parent": "c6e3cedcda2e3982a1a6760e178355e8e65f7b80e4e5248743fa3549d284e024", - "checksum": "tarsum.v1+sha256:e58fcf7418d2390dec8e8fb69d88c06ec07039d651fedc3aa72af9972e7d046b", - "created": "2014-10-13T21:19:18.674353812Z", - "author": "Alyssa P. Hacker <alyspdev@example.com>", - "architecture": "amd64", - "os": "linux", - "Size": 271828, - "config": { - "User": "alice", - "Memory": 2048, - "MemorySwap": 4096, - "CpuShares": 8, - "ExposedPorts": { - "8080/tcp": {} - }, - "Env": [ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", - "FOO=docker_is_a_really", - "BAR=great_tool_you_know" - ], - "Entrypoint": [ - "/bin/my-app-binary" - ], - "Cmd": [ - "--foreground", - "--config", - "/etc/my-app.d/default.cfg" - ], - "Volumes": { - "/var/job-result-data": {}, - "/var/log/my-app-logs": {}, - }, - "WorkingDir": "/home/alice", - } -} -``` - -### Image JSON Field Descriptions - -
-
- id string -
-
- Randomly generated, 256-bit, hexadecimal encoded. Uniquely identifies - the image. -
-
- parent string -
-
- ID of the parent image. If there is no parent image then this field - should be omitted. A collection of images may share many of the same - ancestor layers. This organizational structure is strictly a tree with - any one layer having either no parent or a single parent and zero or - more descendant layers. Cycles are not allowed and implementations - should be careful to avoid creating them or iterating through a cycle - indefinitely. -
-
- created string -
-
- ISO-8601 formatted combined date and time at which the image was - created. -
-
- author string -
-
- Gives the name and/or email address of the person or entity which - created and is responsible for maintaining the image. -
-
- architecture string -
-
- The CPU architecture which the binaries in this image are built to run - on. Possible values include: -
    -
  • 386
  • -
  • amd64
  • -
  • arm
  • -
- More values may be supported in the future and any of these may or may - not be supported by a given container runtime implementation. -
-
- os string -
-
- The name of the operating system which the image is built to run on. - Possible values include: -
    -
  • darwin
  • -
  • freebsd
  • -
  • linux
  • -
- More values may be supported in the future and any of these may or may - not be supported by a given container runtime implementation. -
-
- checksum string -
-
- Image Checksum of the filesystem changeset associated with the image - layer. -
-
- Size integer -
-
- The size in bytes of the filesystem changeset associated with the image - layer. -
-
- config struct -
-
- The execution parameters which should be used as a base when running a - container using the image. This field can be null, in - which case any execution parameters should be specified at creation of - the container. - -

Container RunConfig Field Descriptions

- -
-
- User string -
-
-

The username or UID which the process in the container should - run as. This acts as a default value to use when the value is - not specified when creating a container.

- -

All of the following are valid:

- -
    -
  • user
  • -
  • uid
  • -
  • user:group
  • -
  • uid:gid
  • -
  • uid:group
  • -
  • user:gid
  • -
- -

If group/gid is not specified, the - default group and supplementary groups of the given - user/uid in /etc/passwd - from the container are applied.

-
-
- Memory integer -
-
- Memory limit (in bytes). This acts as a default value to use - when the value is not specified when creating a container. -
-
- MemorySwap integer -
-
- Total memory usage (memory + swap); set to -1 to - disable swap. This acts as a default value to use when the - value is not specified when creating a container. -
-
- CpuShares integer -
-
- CPU shares (relative weight vs. other containers). This acts as - a default value to use when the value is not specified when - creating a container. -
-
- ExposedPorts struct -
-
- A set of ports to expose from a container running this image. - This JSON structure value is unusual because it is a direct - JSON serialization of the Go type - map[string]struct{} and is represented in JSON as - an object mapping its keys to an empty object. Here is an - example: - -
{
-    "8080": {},
-    "53/udp": {},
-    "2356/tcp": {}
-}
- - Its keys can be in the format of: -
    -
  • - "port/tcp" -
  • -
  • - "port/udp" -
  • -
  • - "port" -
  • -
- with the default protocol being "tcp" if not - specified. - - These values act as defaults and are merged with any specified - when creating a container. -
-
- Env array of strings -
-
- Entries are in the format of VARNAME="var value". - These values act as defaults and are merged with any specified - when creating a container. -
-
- Entrypoint array of strings -
-
- A list of arguments to use as the command to execute when the - container starts. This value acts as a default and is replaced - by an entrypoint specified when creating a container. -
-
- Cmd array of strings -
-
- Default arguments to the entry point of the container. These - values act as defaults and are replaced with any specified when - creating a container. If an Entrypoint value is - not specified, then the first entry of the Cmd - array should be interpreted as the executable to run. -
-
- Volumes struct -
-
- A set of directories which should be created as data volumes in - a container running this image. This JSON structure value is - unusual because it is a direct JSON serialization of the Go - type map[string]struct{} and is represented in - JSON as an object mapping its keys to an empty object. Here is - an example: -
{
-    "/var/my-app-data/": {},
-    "/etc/some-config.d/": {},
-}
-
-
- WorkingDir string -
-
- Sets the current working directory of the entry point process - in the container. This value acts as a default and is replaced - by a working directory specified when creating a container. -
-
-
-
- -Any extra fields in the Image JSON struct are considered implementation -specific and should be ignored by any implementations which are unable to -interpret them. - -## Creating an Image Filesystem Changeset - -An example of creating an Image Filesystem Changeset follows. - -An image root filesystem is first created as an empty directory named with the -ID of the image being created. Here is the initial empty directory structure -for the changeset for an image with ID `c3167915dc9d` ([real IDs are much -longer](#id_desc), but this example use a truncated one here for brevity. -Implementations need not name the rootfs directory in this way but it may be -convenient for keeping record of a large number of image layers.): - -``` -c3167915dc9d/ -``` - -Files and directories are then created: - -``` -c3167915dc9d/ - etc/ - my-app-config - bin/ - my-app-binary - my-app-tools -``` - -The `c3167915dc9d` directory is then committed as a plain Tar archive with -entries for the following files: - -``` -etc/my-app-config -bin/my-app-binary -bin/my-app-tools -``` - -The TarSum checksum for the archive file is then computed and placed in the -JSON metadata along with the execution parameters. - -To make changes to the filesystem of this container image, create a new -directory named with a new ID, such as `f60c56784b83`, and initialize it with -a snapshot of the parent image's root filesystem, so that the directory is -identical to that of `c3167915dc9d`. NOTE: a copy-on-write or union filesystem -can make this very efficient: - -``` -f60c56784b83/ - etc/ - my-app-config - bin/ - my-app-binary - my-app-tools -``` - -This example change is going add a configuration directory at `/etc/my-app.d` -which contains a default config file. There's also a change to the -`my-app-tools` binary to handle the config layout change. The `f60c56784b83` -directory then looks like this: - -``` -f60c56784b83/ - etc/ - my-app.d/ - default.cfg - bin/ - my-app-binary - my-app-tools -``` - -This reflects the removal of `/etc/my-app-config` and creation of a file and -directory at `/etc/my-app.d/default.cfg`. `/bin/my-app-tools` has also been -replaced with an updated version. Before committing this directory to a -changeset, because it has a parent image, it is first compared with the -directory tree of the parent snapshot, `f60c56784b83`, looking for files and -directories that have been added, modified, or removed. The following changeset -is found: - -``` -Added: /etc/my-app.d/default.cfg -Modified: /bin/my-app-tools -Deleted: /etc/my-app-config -``` - -A Tar Archive is then created which contains *only* this changeset: The added -and modified files and directories in their entirety, and for each deleted item -an entry for an empty file at the same location but with the basename of the -deleted file or directory prefixed with `.wh.`. The filenames prefixed with -`.wh.` are known as "whiteout" files. NOTE: For this reason, it is not possible -to create an image root filesystem which contains a file or directory with a -name beginning with `.wh.`. The resulting Tar archive for `f60c56784b83` has -the following entries: - -``` -/etc/my-app.d/default.cfg -/bin/my-app-tools -/etc/.wh.my-app-config -``` - -Any given image is likely to be composed of several of these Image Filesystem -Changeset tar archives. - -## Combined Image JSON + Filesystem Changeset Format - -There is also a format for a single archive which contains complete information -about an image, including: - - - repository names/tags - - all image layer JSON files - - all tar archives of each layer filesystem changesets - -For example, here's what the full archive of `library/busybox` is (displayed in -`tree` format): - -``` -. -├── 5785b62b697b99a5af6cd5d0aabc804d5748abbb6d3d07da5d1d3795f2dcc83e -│   ├── VERSION -│   ├── json -│   └── layer.tar -├── a7b8b41220991bfc754d7ad445ad27b7f272ab8b4a2c175b9512b97471d02a8a -│   ├── VERSION -│   ├── json -│   └── layer.tar -├── a936027c5ca8bf8f517923169a233e391cbb38469a75de8383b5228dc2d26ceb -│   ├── VERSION -│   ├── json -│   └── layer.tar -├── f60c56784b832dd990022afc120b8136ab3da9528094752ae13fe63a2d28dc8c -│   ├── VERSION -│   ├── json -│   └── layer.tar -└── repositories -``` - -There are one or more directories named with the ID for each layer in a full -image. Each of these directories contains 3 files: - - * `VERSION` - The schema version of the `json` file - * `json` - The JSON metadata for an image layer - * `layer.tar` - The Tar archive of the filesystem changeset for an image - layer. - -The content of the `VERSION` files is simply the semantic version of the JSON -metadata schema: - -``` -1.0 -``` - -And the `repositories` file is another JSON file which describes names/tags: - -``` -{ - "busybox":{ - "latest":"5785b62b697b99a5af6cd5d0aabc804d5748abbb6d3d07da5d1d3795f2dcc83e" - } -} -``` - -Every key in this object is the name of a repository, and maps to a collection -of tag suffixes. Each tag maps to the ID of the image represented by that tag. - -## Loading an Image Filesystem Changeset - -Unpacking a bundle of image layer JSON files and their corresponding filesystem -changesets can be done using a series of steps: - -1. Follow the parent IDs of image layers to find the root ancestor (an image -with no parent ID specified). -2. For every image layer, in order from root ancestor and descending down, -extract the contents of that layer's filesystem changeset archive into a -directory which will be used as the root of a container filesystem. - - - Extract all contents of each archive. - - Walk the directory tree once more, removing any files with the prefix - `.wh.` and the corresponding file or directory named without this prefix. - - -## Implementations - -This specification is an admittedly imperfect description of an -imperfectly-understood problem. The Docker project is, in turn, an attempt to -implement this specification. Our goal and our execution toward it will evolve -over time, but our primary concern in this specification and in our -implementation is compatibility and interoperability. diff --git a/vendor/github.com/docker/docker/image/store.go b/vendor/github.com/docker/docker/image/store.go deleted file mode 100644 index b61c456..0000000 --- a/vendor/github.com/docker/docker/image/store.go +++ /dev/null @@ -1,295 +0,0 @@ -package image - -import ( - "encoding/json" - "errors" - "fmt" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/layer" -) - -// Store is an interface for creating and accessing images -type Store interface { - Create(config []byte) (ID, error) - Get(id ID) (*Image, error) - Delete(id ID) ([]layer.Metadata, error) - Search(partialID string) (ID, error) - SetParent(id ID, parent ID) error - GetParent(id ID) (ID, error) - Children(id ID) []ID - Map() map[ID]*Image - Heads() map[ID]*Image -} - -// LayerGetReleaser is a minimal interface for getting and releasing images. -type LayerGetReleaser interface { - Get(layer.ChainID) (layer.Layer, error) - Release(layer.Layer) ([]layer.Metadata, error) -} - -type imageMeta struct { - layer layer.Layer - children map[ID]struct{} -} - -type store struct { - sync.Mutex - ls LayerGetReleaser - images map[ID]*imageMeta - fs StoreBackend - digestSet *digest.Set -} - -// NewImageStore returns new store object for given layer store -func NewImageStore(fs StoreBackend, ls LayerGetReleaser) (Store, error) { - is := &store{ - ls: ls, - images: make(map[ID]*imageMeta), - fs: fs, - digestSet: digest.NewSet(), - } - - // load all current images and retain layers - if err := is.restore(); err != nil { - return nil, err - } - - return is, nil -} - -func (is *store) restore() error { - err := is.fs.Walk(func(dgst digest.Digest) error { - img, err := is.Get(IDFromDigest(dgst)) - if err != nil { - logrus.Errorf("invalid image %v, %v", dgst, err) - return nil - } - var l layer.Layer - if chainID := img.RootFS.ChainID(); chainID != "" { - l, err = is.ls.Get(chainID) - if err != nil { - return err - } - } - if err := is.digestSet.Add(dgst); err != nil { - return err - } - - imageMeta := &imageMeta{ - layer: l, - children: make(map[ID]struct{}), - } - - is.images[IDFromDigest(dgst)] = imageMeta - - return nil - }) - if err != nil { - return err - } - - // Second pass to fill in children maps - for id := range is.images { - if parent, err := is.GetParent(id); err == nil { - if parentMeta := is.images[parent]; parentMeta != nil { - parentMeta.children[id] = struct{}{} - } - } - } - - return nil -} - -func (is *store) Create(config []byte) (ID, error) { - var img Image - err := json.Unmarshal(config, &img) - if err != nil { - return "", err - } - - // Must reject any config that references diffIDs from the history - // which aren't among the rootfs layers. - rootFSLayers := make(map[layer.DiffID]struct{}) - for _, diffID := range img.RootFS.DiffIDs { - rootFSLayers[diffID] = struct{}{} - } - - layerCounter := 0 - for _, h := range img.History { - if !h.EmptyLayer { - layerCounter++ - } - } - if layerCounter > len(img.RootFS.DiffIDs) { - return "", errors.New("too many non-empty layers in History section") - } - - dgst, err := is.fs.Set(config) - if err != nil { - return "", err - } - imageID := IDFromDigest(dgst) - - is.Lock() - defer is.Unlock() - - if _, exists := is.images[imageID]; exists { - return imageID, nil - } - - layerID := img.RootFS.ChainID() - - var l layer.Layer - if layerID != "" { - l, err = is.ls.Get(layerID) - if err != nil { - return "", err - } - } - - imageMeta := &imageMeta{ - layer: l, - children: make(map[ID]struct{}), - } - - is.images[imageID] = imageMeta - if err := is.digestSet.Add(imageID.Digest()); err != nil { - delete(is.images, imageID) - return "", err - } - - return imageID, nil -} - -func (is *store) Search(term string) (ID, error) { - is.Lock() - defer is.Unlock() - - dgst, err := is.digestSet.Lookup(term) - if err != nil { - if err == digest.ErrDigestNotFound { - err = fmt.Errorf("No such image: %s", term) - } - return "", err - } - return IDFromDigest(dgst), nil -} - -func (is *store) Get(id ID) (*Image, error) { - // todo: Check if image is in images - // todo: Detect manual insertions and start using them - config, err := is.fs.Get(id.Digest()) - if err != nil { - return nil, err - } - - img, err := NewFromJSON(config) - if err != nil { - return nil, err - } - img.computedID = id - - img.Parent, err = is.GetParent(id) - if err != nil { - img.Parent = "" - } - - return img, nil -} - -func (is *store) Delete(id ID) ([]layer.Metadata, error) { - is.Lock() - defer is.Unlock() - - imageMeta := is.images[id] - if imageMeta == nil { - return nil, fmt.Errorf("unrecognized image ID %s", id.String()) - } - for id := range imageMeta.children { - is.fs.DeleteMetadata(id.Digest(), "parent") - } - if parent, err := is.GetParent(id); err == nil && is.images[parent] != nil { - delete(is.images[parent].children, id) - } - - if err := is.digestSet.Remove(id.Digest()); err != nil { - logrus.Errorf("error removing %s from digest set: %q", id, err) - } - delete(is.images, id) - is.fs.Delete(id.Digest()) - - if imageMeta.layer != nil { - return is.ls.Release(imageMeta.layer) - } - return nil, nil -} - -func (is *store) SetParent(id, parent ID) error { - is.Lock() - defer is.Unlock() - parentMeta := is.images[parent] - if parentMeta == nil { - return fmt.Errorf("unknown parent image ID %s", parent.String()) - } - if parent, err := is.GetParent(id); err == nil && is.images[parent] != nil { - delete(is.images[parent].children, id) - } - parentMeta.children[id] = struct{}{} - return is.fs.SetMetadata(id.Digest(), "parent", []byte(parent)) -} - -func (is *store) GetParent(id ID) (ID, error) { - d, err := is.fs.GetMetadata(id.Digest(), "parent") - if err != nil { - return "", err - } - return ID(d), nil // todo: validate? -} - -func (is *store) Children(id ID) []ID { - is.Lock() - defer is.Unlock() - - return is.children(id) -} - -func (is *store) children(id ID) []ID { - var ids []ID - if is.images[id] != nil { - for id := range is.images[id].children { - ids = append(ids, id) - } - } - return ids -} - -func (is *store) Heads() map[ID]*Image { - return is.imagesMap(false) -} - -func (is *store) Map() map[ID]*Image { - return is.imagesMap(true) -} - -func (is *store) imagesMap(all bool) map[ID]*Image { - is.Lock() - defer is.Unlock() - - images := make(map[ID]*Image) - - for id := range is.images { - if !all && len(is.children(id)) > 0 { - continue - } - img, err := is.Get(id) - if err != nil { - logrus.Errorf("invalid image access: %q, error: %q", id, err) - continue - } - images[id] = img - } - return images -} diff --git a/vendor/github.com/docker/docker/image/store_test.go b/vendor/github.com/docker/docker/image/store_test.go deleted file mode 100644 index 50f8aa8..0000000 --- a/vendor/github.com/docker/docker/image/store_test.go +++ /dev/null @@ -1,300 +0,0 @@ -package image - -import ( - "io/ioutil" - "os" - "testing" - - "github.com/docker/distribution/digest" - "github.com/docker/docker/layer" -) - -func TestRestore(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - id1, err := fs.Set([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`)) - if err != nil { - t.Fatal(err) - } - _, err = fs.Set([]byte(`invalid`)) - if err != nil { - t.Fatal(err) - } - id2, err := fs.Set([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`)) - if err != nil { - t.Fatal(err) - } - err = fs.SetMetadata(id2, "parent", []byte(id1)) - if err != nil { - t.Fatal(err) - } - - is, err := NewImageStore(fs, &mockLayerGetReleaser{}) - if err != nil { - t.Fatal(err) - } - - imgs := is.Map() - if actual, expected := len(imgs), 2; actual != expected { - t.Fatalf("invalid images length, expected 2, got %q", len(imgs)) - } - - img1, err := is.Get(ID(id1)) - if err != nil { - t.Fatal(err) - } - - if actual, expected := img1.computedID, ID(id1); actual != expected { - t.Fatalf("invalid image ID: expected %q, got %q", expected, actual) - } - - if actual, expected := img1.computedID.String(), string(id1); actual != expected { - t.Fatalf("invalid image ID string: expected %q, got %q", expected, actual) - } - - img2, err := is.Get(ID(id2)) - if err != nil { - t.Fatal(err) - } - - if actual, expected := img1.Comment, "abc"; actual != expected { - t.Fatalf("invalid comment for image1: expected %q, got %q", expected, actual) - } - - if actual, expected := img2.Comment, "def"; actual != expected { - t.Fatalf("invalid comment for image2: expected %q, got %q", expected, actual) - } - - p, err := is.GetParent(ID(id1)) - if err == nil { - t.Fatal("expected error for getting parent") - } - - p, err = is.GetParent(ID(id2)) - if err != nil { - t.Fatal(err) - } - if actual, expected := p, ID(id1); actual != expected { - t.Fatalf("invalid parent: expected %q, got %q", expected, actual) - } - - children := is.Children(ID(id1)) - if len(children) != 1 { - t.Fatalf("invalid children length: %q", len(children)) - } - if actual, expected := children[0], ID(id2); actual != expected { - t.Fatalf("invalid child for id1: expected %q, got %q", expected, actual) - } - - heads := is.Heads() - if actual, expected := len(heads), 1; actual != expected { - t.Fatalf("invalid images length: expected %q, got %q", expected, actual) - } - - sid1, err := is.Search(string(id1)[:10]) - if err != nil { - t.Fatal(err) - } - if actual, expected := sid1, ID(id1); actual != expected { - t.Fatalf("searched ID mismatch: expected %q, got %q", expected, actual) - } - - sid1, err = is.Search(digest.Digest(id1).Hex()[:6]) - if err != nil { - t.Fatal(err) - } - if actual, expected := sid1, ID(id1); actual != expected { - t.Fatalf("searched ID mismatch: expected %q, got %q", expected, actual) - } - - invalidPattern := digest.Digest(id1).Hex()[1:6] - _, err = is.Search(invalidPattern) - if err == nil { - t.Fatalf("expected search for %q to fail", invalidPattern) - } - -} - -func TestAddDelete(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - is, err := NewImageStore(fs, &mockLayerGetReleaser{}) - if err != nil { - t.Fatal(err) - } - - id1, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`)) - if err != nil { - t.Fatal(err) - } - - if actual, expected := id1, ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"); actual != expected { - t.Fatalf("create ID mismatch: expected %q, got %q", expected, actual) - } - - img, err := is.Get(id1) - if err != nil { - t.Fatal(err) - } - - if actual, expected := img.Comment, "abc"; actual != expected { - t.Fatalf("invalid comment in image: expected %q, got %q", expected, actual) - } - - id2, err := is.Create([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`)) - if err != nil { - t.Fatal(err) - } - - err = is.SetParent(id2, id1) - if err != nil { - t.Fatal(err) - } - - pid1, err := is.GetParent(id2) - if err != nil { - t.Fatal(err) - } - if actual, expected := pid1, id1; actual != expected { - t.Fatalf("invalid parent for image: expected %q, got %q", expected, actual) - } - - _, err = is.Delete(id1) - if err != nil { - t.Fatal(err) - } - _, err = is.Get(id1) - if err == nil { - t.Fatalf("expected get for deleted image %q to fail", id1) - } - _, err = is.Get(id2) - if err != nil { - t.Fatal(err) - } - pid1, err = is.GetParent(id2) - if err == nil { - t.Fatalf("expected parent check for image %q to fail, got %q", id2, pid1) - } - -} - -func TestSearchAfterDelete(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - is, err := NewImageStore(fs, &mockLayerGetReleaser{}) - if err != nil { - t.Fatal(err) - } - - id, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`)) - if err != nil { - t.Fatal(err) - } - - id1, err := is.Search(string(id)[:15]) - if err != nil { - t.Fatal(err) - } - - if actual, expected := id1, id; expected != actual { - t.Fatalf("wrong id returned from search: expected %q, got %q", expected, actual) - } - - if _, err := is.Delete(id); err != nil { - t.Fatal(err) - } - - if _, err := is.Search(string(id)[:15]); err == nil { - t.Fatal("expected search after deletion to fail") - } -} - -func TestParentReset(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "images-fs-store") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - fs, err := NewFSStoreBackend(tmpdir) - if err != nil { - t.Fatal(err) - } - - is, err := NewImageStore(fs, &mockLayerGetReleaser{}) - if err != nil { - t.Fatal(err) - } - - id, err := is.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`)) - if err != nil { - t.Fatal(err) - } - - id2, err := is.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`)) - if err != nil { - t.Fatal(err) - } - - id3, err := is.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`)) - if err != nil { - t.Fatal(err) - } - - if err := is.SetParent(id, id2); err != nil { - t.Fatal(err) - } - - ids := is.Children(id2) - if actual, expected := len(ids), 1; expected != actual { - t.Fatalf("wrong number of children: %d, got %d", expected, actual) - } - - if err := is.SetParent(id, id3); err != nil { - t.Fatal(err) - } - - ids = is.Children(id2) - if actual, expected := len(ids), 0; expected != actual { - t.Fatalf("wrong number of children after parent reset: %d, got %d", expected, actual) - } - - ids = is.Children(id3) - if actual, expected := len(ids), 1; expected != actual { - t.Fatalf("wrong number of children after parent reset: %d, got %d", expected, actual) - } - -} - -type mockLayerGetReleaser struct{} - -func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) { - return nil, nil -} - -func (ls *mockLayerGetReleaser) Release(layer.Layer) ([]layer.Metadata, error) { - return nil, nil -} diff --git a/vendor/github.com/docker/docker/image/tarexport/load.go b/vendor/github.com/docker/docker/image/tarexport/load.go deleted file mode 100644 index 01edd91..0000000 --- a/vendor/github.com/docker/docker/image/tarexport/load.go +++ /dev/null @@ -1,390 +0,0 @@ -package tarexport - -import ( - "encoding/json" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "reflect" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/docker/image" - "github.com/docker/docker/image/v1" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/chrootarchive" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/pkg/streamformatter" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/symlink" - "github.com/docker/docker/pkg/system" - "github.com/docker/docker/reference" -) - -func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool) error { - var ( - sf = streamformatter.NewJSONStreamFormatter() - progressOutput progress.Output - ) - if !quiet { - progressOutput = sf.NewProgressOutput(outStream, false) - } - outStream = &streamformatter.StdoutFormatter{Writer: outStream, StreamFormatter: streamformatter.NewJSONStreamFormatter()} - - tmpDir, err := ioutil.TempDir("", "docker-import-") - if err != nil { - return err - } - defer os.RemoveAll(tmpDir) - - if err := chrootarchive.Untar(inTar, tmpDir, nil); err != nil { - return err - } - // read manifest, if no file then load in legacy mode - manifestPath, err := safePath(tmpDir, manifestFileName) - if err != nil { - return err - } - manifestFile, err := os.Open(manifestPath) - if err != nil { - if os.IsNotExist(err) { - return l.legacyLoad(tmpDir, outStream, progressOutput) - } - return err - } - defer manifestFile.Close() - - var manifest []manifestItem - if err := json.NewDecoder(manifestFile).Decode(&manifest); err != nil { - return err - } - - var parentLinks []parentLink - var imageIDsStr string - var imageRefCount int - - for _, m := range manifest { - configPath, err := safePath(tmpDir, m.Config) - if err != nil { - return err - } - config, err := ioutil.ReadFile(configPath) - if err != nil { - return err - } - img, err := image.NewFromJSON(config) - if err != nil { - return err - } - var rootFS image.RootFS - rootFS = *img.RootFS - rootFS.DiffIDs = nil - - if expected, actual := len(m.Layers), len(img.RootFS.DiffIDs); expected != actual { - return fmt.Errorf("invalid manifest, layers length mismatch: expected %q, got %q", expected, actual) - } - - for i, diffID := range img.RootFS.DiffIDs { - layerPath, err := safePath(tmpDir, m.Layers[i]) - if err != nil { - return err - } - r := rootFS - r.Append(diffID) - newLayer, err := l.ls.Get(r.ChainID()) - if err != nil { - newLayer, err = l.loadLayer(layerPath, rootFS, diffID.String(), m.LayerSources[diffID], progressOutput) - if err != nil { - return err - } - } - defer layer.ReleaseAndLog(l.ls, newLayer) - if expected, actual := diffID, newLayer.DiffID(); expected != actual { - return fmt.Errorf("invalid diffID for layer %d: expected %q, got %q", i, expected, actual) - } - rootFS.Append(diffID) - } - - imgID, err := l.is.Create(config) - if err != nil { - return err - } - imageIDsStr += fmt.Sprintf("Loaded image ID: %s\n", imgID) - - imageRefCount = 0 - for _, repoTag := range m.RepoTags { - named, err := reference.ParseNamed(repoTag) - if err != nil { - return err - } - ref, ok := named.(reference.NamedTagged) - if !ok { - return fmt.Errorf("invalid tag %q", repoTag) - } - l.setLoadedTag(ref, imgID.Digest(), outStream) - outStream.Write([]byte(fmt.Sprintf("Loaded image: %s\n", ref))) - imageRefCount++ - } - - parentLinks = append(parentLinks, parentLink{imgID, m.Parent}) - l.loggerImgEvent.LogImageEvent(imgID.String(), imgID.String(), "load") - } - - for _, p := range validatedParentLinks(parentLinks) { - if p.parentID != "" { - if err := l.setParentID(p.id, p.parentID); err != nil { - return err - } - } - } - - if imageRefCount == 0 { - outStream.Write([]byte(imageIDsStr)) - } - - return nil -} - -func (l *tarexporter) setParentID(id, parentID image.ID) error { - img, err := l.is.Get(id) - if err != nil { - return err - } - parent, err := l.is.Get(parentID) - if err != nil { - return err - } - if !checkValidParent(img, parent) { - return fmt.Errorf("image %v is not a valid parent for %v", parent.ID(), img.ID()) - } - return l.is.SetParent(id, parentID) -} - -func (l *tarexporter) loadLayer(filename string, rootFS image.RootFS, id string, foreignSrc distribution.Descriptor, progressOutput progress.Output) (layer.Layer, error) { - // We use system.OpenSequential to use sequential file access on Windows, avoiding - // depleting the standby list. On Linux, this equates to a regular os.Open. - rawTar, err := system.OpenSequential(filename) - if err != nil { - logrus.Debugf("Error reading embedded tar: %v", err) - return nil, err - } - defer rawTar.Close() - - var r io.Reader - if progressOutput != nil { - fileInfo, err := rawTar.Stat() - if err != nil { - logrus.Debugf("Error statting file: %v", err) - return nil, err - } - - r = progress.NewProgressReader(rawTar, progressOutput, fileInfo.Size(), stringid.TruncateID(id), "Loading layer") - } else { - r = rawTar - } - - inflatedLayerData, err := archive.DecompressStream(r) - if err != nil { - return nil, err - } - defer inflatedLayerData.Close() - - if ds, ok := l.ls.(layer.DescribableStore); ok { - return ds.RegisterWithDescriptor(inflatedLayerData, rootFS.ChainID(), foreignSrc) - } - return l.ls.Register(inflatedLayerData, rootFS.ChainID()) -} - -func (l *tarexporter) setLoadedTag(ref reference.NamedTagged, imgID digest.Digest, outStream io.Writer) error { - if prevID, err := l.rs.Get(ref); err == nil && prevID != imgID { - fmt.Fprintf(outStream, "The image %s already exists, renaming the old one with ID %s to empty string\n", ref.String(), string(prevID)) // todo: this message is wrong in case of multiple tags - } - - if err := l.rs.AddTag(ref, imgID, true); err != nil { - return err - } - return nil -} - -func (l *tarexporter) legacyLoad(tmpDir string, outStream io.Writer, progressOutput progress.Output) error { - legacyLoadedMap := make(map[string]image.ID) - - dirs, err := ioutil.ReadDir(tmpDir) - if err != nil { - return err - } - - // every dir represents an image - for _, d := range dirs { - if d.IsDir() { - if err := l.legacyLoadImage(d.Name(), tmpDir, legacyLoadedMap, progressOutput); err != nil { - return err - } - } - } - - // load tags from repositories file - repositoriesPath, err := safePath(tmpDir, legacyRepositoriesFileName) - if err != nil { - return err - } - repositoriesFile, err := os.Open(repositoriesPath) - if err != nil { - return err - } - defer repositoriesFile.Close() - - repositories := make(map[string]map[string]string) - if err := json.NewDecoder(repositoriesFile).Decode(&repositories); err != nil { - return err - } - - for name, tagMap := range repositories { - for tag, oldID := range tagMap { - imgID, ok := legacyLoadedMap[oldID] - if !ok { - return fmt.Errorf("invalid target ID: %v", oldID) - } - named, err := reference.WithName(name) - if err != nil { - return err - } - ref, err := reference.WithTag(named, tag) - if err != nil { - return err - } - l.setLoadedTag(ref, imgID.Digest(), outStream) - } - } - - return nil -} - -func (l *tarexporter) legacyLoadImage(oldID, sourceDir string, loadedMap map[string]image.ID, progressOutput progress.Output) error { - if _, loaded := loadedMap[oldID]; loaded { - return nil - } - configPath, err := safePath(sourceDir, filepath.Join(oldID, legacyConfigFileName)) - if err != nil { - return err - } - imageJSON, err := ioutil.ReadFile(configPath) - if err != nil { - logrus.Debugf("Error reading json: %v", err) - return err - } - - var img struct{ Parent string } - if err := json.Unmarshal(imageJSON, &img); err != nil { - return err - } - - var parentID image.ID - if img.Parent != "" { - for { - var loaded bool - if parentID, loaded = loadedMap[img.Parent]; !loaded { - if err := l.legacyLoadImage(img.Parent, sourceDir, loadedMap, progressOutput); err != nil { - return err - } - } else { - break - } - } - } - - // todo: try to connect with migrate code - rootFS := image.NewRootFS() - var history []image.History - - if parentID != "" { - parentImg, err := l.is.Get(parentID) - if err != nil { - return err - } - - rootFS = parentImg.RootFS - history = parentImg.History - } - - layerPath, err := safePath(sourceDir, filepath.Join(oldID, legacyLayerFileName)) - if err != nil { - return err - } - newLayer, err := l.loadLayer(layerPath, *rootFS, oldID, distribution.Descriptor{}, progressOutput) - if err != nil { - return err - } - rootFS.Append(newLayer.DiffID()) - - h, err := v1.HistoryFromConfig(imageJSON, false) - if err != nil { - return err - } - history = append(history, h) - - config, err := v1.MakeConfigFromV1Config(imageJSON, rootFS, history) - if err != nil { - return err - } - imgID, err := l.is.Create(config) - if err != nil { - return err - } - - metadata, err := l.ls.Release(newLayer) - layer.LogReleaseMetadata(metadata) - if err != nil { - return err - } - - if parentID != "" { - if err := l.is.SetParent(imgID, parentID); err != nil { - return err - } - } - - loadedMap[oldID] = imgID - return nil -} - -func safePath(base, path string) (string, error) { - return symlink.FollowSymlinkInScope(filepath.Join(base, path), base) -} - -type parentLink struct { - id, parentID image.ID -} - -func validatedParentLinks(pl []parentLink) (ret []parentLink) { -mainloop: - for i, p := range pl { - ret = append(ret, p) - for _, p2 := range pl { - if p2.id == p.parentID && p2.id != p.id { - continue mainloop - } - } - ret[i].parentID = "" - } - return -} - -func checkValidParent(img, parent *image.Image) bool { - if len(img.History) == 0 && len(parent.History) == 0 { - return true // having history is not mandatory - } - if len(img.History)-len(parent.History) != 1 { - return false - } - for i, h := range parent.History { - if !reflect.DeepEqual(h, img.History[i]) { - return false - } - } - return true -} diff --git a/vendor/github.com/docker/docker/image/tarexport/save.go b/vendor/github.com/docker/docker/image/tarexport/save.go deleted file mode 100644 index 6e3a5bc..0000000 --- a/vendor/github.com/docker/docker/image/tarexport/save.go +++ /dev/null @@ -1,355 +0,0 @@ -package tarexport - -import ( - "encoding/json" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "time" - - "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/docker/image" - "github.com/docker/docker/image/v1" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/system" - "github.com/docker/docker/reference" -) - -type imageDescriptor struct { - refs []reference.NamedTagged - layers []string -} - -type saveSession struct { - *tarexporter - outDir string - images map[image.ID]*imageDescriptor - savedLayers map[string]struct{} - diffIDPaths map[layer.DiffID]string // cache every diffID blob to avoid duplicates -} - -func (l *tarexporter) Save(names []string, outStream io.Writer) error { - images, err := l.parseNames(names) - if err != nil { - return err - } - - return (&saveSession{tarexporter: l, images: images}).save(outStream) -} - -func (l *tarexporter) parseNames(names []string) (map[image.ID]*imageDescriptor, error) { - imgDescr := make(map[image.ID]*imageDescriptor) - - addAssoc := func(id image.ID, ref reference.Named) { - if _, ok := imgDescr[id]; !ok { - imgDescr[id] = &imageDescriptor{} - } - - if ref != nil { - var tagged reference.NamedTagged - if _, ok := ref.(reference.Canonical); ok { - return - } - var ok bool - if tagged, ok = ref.(reference.NamedTagged); !ok { - var err error - if tagged, err = reference.WithTag(ref, reference.DefaultTag); err != nil { - return - } - } - - for _, t := range imgDescr[id].refs { - if tagged.String() == t.String() { - return - } - } - imgDescr[id].refs = append(imgDescr[id].refs, tagged) - } - } - - for _, name := range names { - id, ref, err := reference.ParseIDOrReference(name) - if err != nil { - return nil, err - } - if id != "" { - _, err := l.is.Get(image.IDFromDigest(id)) - if err != nil { - return nil, err - } - addAssoc(image.IDFromDigest(id), nil) - continue - } - if ref.Name() == string(digest.Canonical) { - imgID, err := l.is.Search(name) - if err != nil { - return nil, err - } - addAssoc(imgID, nil) - continue - } - if reference.IsNameOnly(ref) { - assocs := l.rs.ReferencesByName(ref) - for _, assoc := range assocs { - addAssoc(image.IDFromDigest(assoc.ID), assoc.Ref) - } - if len(assocs) == 0 { - imgID, err := l.is.Search(name) - if err != nil { - return nil, err - } - addAssoc(imgID, nil) - } - continue - } - id, err = l.rs.Get(ref) - if err != nil { - return nil, err - } - addAssoc(image.IDFromDigest(id), ref) - - } - return imgDescr, nil -} - -func (s *saveSession) save(outStream io.Writer) error { - s.savedLayers = make(map[string]struct{}) - s.diffIDPaths = make(map[layer.DiffID]string) - - // get image json - tempDir, err := ioutil.TempDir("", "docker-export-") - if err != nil { - return err - } - defer os.RemoveAll(tempDir) - - s.outDir = tempDir - reposLegacy := make(map[string]map[string]string) - - var manifest []manifestItem - var parentLinks []parentLink - - for id, imageDescr := range s.images { - foreignSrcs, err := s.saveImage(id) - if err != nil { - return err - } - - var repoTags []string - var layers []string - - for _, ref := range imageDescr.refs { - if _, ok := reposLegacy[ref.Name()]; !ok { - reposLegacy[ref.Name()] = make(map[string]string) - } - reposLegacy[ref.Name()][ref.Tag()] = imageDescr.layers[len(imageDescr.layers)-1] - repoTags = append(repoTags, ref.String()) - } - - for _, l := range imageDescr.layers { - layers = append(layers, filepath.Join(l, legacyLayerFileName)) - } - - manifest = append(manifest, manifestItem{ - Config: id.Digest().Hex() + ".json", - RepoTags: repoTags, - Layers: layers, - LayerSources: foreignSrcs, - }) - - parentID, _ := s.is.GetParent(id) - parentLinks = append(parentLinks, parentLink{id, parentID}) - s.tarexporter.loggerImgEvent.LogImageEvent(id.String(), id.String(), "save") - } - - for i, p := range validatedParentLinks(parentLinks) { - if p.parentID != "" { - manifest[i].Parent = p.parentID - } - } - - if len(reposLegacy) > 0 { - reposFile := filepath.Join(tempDir, legacyRepositoriesFileName) - rf, err := os.OpenFile(reposFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) - if err != nil { - return err - } - - if err := json.NewEncoder(rf).Encode(reposLegacy); err != nil { - rf.Close() - return err - } - - rf.Close() - - if err := system.Chtimes(reposFile, time.Unix(0, 0), time.Unix(0, 0)); err != nil { - return err - } - } - - manifestFileName := filepath.Join(tempDir, manifestFileName) - f, err := os.OpenFile(manifestFileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) - if err != nil { - return err - } - - if err := json.NewEncoder(f).Encode(manifest); err != nil { - f.Close() - return err - } - - f.Close() - - if err := system.Chtimes(manifestFileName, time.Unix(0, 0), time.Unix(0, 0)); err != nil { - return err - } - - fs, err := archive.Tar(tempDir, archive.Uncompressed) - if err != nil { - return err - } - defer fs.Close() - - if _, err := io.Copy(outStream, fs); err != nil { - return err - } - return nil -} - -func (s *saveSession) saveImage(id image.ID) (map[layer.DiffID]distribution.Descriptor, error) { - img, err := s.is.Get(id) - if err != nil { - return nil, err - } - - if len(img.RootFS.DiffIDs) == 0 { - return nil, fmt.Errorf("empty export - not implemented") - } - - var parent digest.Digest - var layers []string - var foreignSrcs map[layer.DiffID]distribution.Descriptor - for i := range img.RootFS.DiffIDs { - v1Img := image.V1Image{ - Created: img.Created, - } - if i == len(img.RootFS.DiffIDs)-1 { - v1Img = img.V1Image - } - rootFS := *img.RootFS - rootFS.DiffIDs = rootFS.DiffIDs[:i+1] - v1ID, err := v1.CreateID(v1Img, rootFS.ChainID(), parent) - if err != nil { - return nil, err - } - - v1Img.ID = v1ID.Hex() - if parent != "" { - v1Img.Parent = parent.Hex() - } - - src, err := s.saveLayer(rootFS.ChainID(), v1Img, img.Created) - if err != nil { - return nil, err - } - layers = append(layers, v1Img.ID) - parent = v1ID - if src.Digest != "" { - if foreignSrcs == nil { - foreignSrcs = make(map[layer.DiffID]distribution.Descriptor) - } - foreignSrcs[img.RootFS.DiffIDs[i]] = src - } - } - - configFile := filepath.Join(s.outDir, id.Digest().Hex()+".json") - if err := ioutil.WriteFile(configFile, img.RawJSON(), 0644); err != nil { - return nil, err - } - if err := system.Chtimes(configFile, img.Created, img.Created); err != nil { - return nil, err - } - - s.images[id].layers = layers - return foreignSrcs, nil -} - -func (s *saveSession) saveLayer(id layer.ChainID, legacyImg image.V1Image, createdTime time.Time) (distribution.Descriptor, error) { - if _, exists := s.savedLayers[legacyImg.ID]; exists { - return distribution.Descriptor{}, nil - } - - outDir := filepath.Join(s.outDir, legacyImg.ID) - if err := os.Mkdir(outDir, 0755); err != nil { - return distribution.Descriptor{}, err - } - - // todo: why is this version file here? - if err := ioutil.WriteFile(filepath.Join(outDir, legacyVersionFileName), []byte("1.0"), 0644); err != nil { - return distribution.Descriptor{}, err - } - - imageConfig, err := json.Marshal(legacyImg) - if err != nil { - return distribution.Descriptor{}, err - } - - if err := ioutil.WriteFile(filepath.Join(outDir, legacyConfigFileName), imageConfig, 0644); err != nil { - return distribution.Descriptor{}, err - } - - // serialize filesystem - layerPath := filepath.Join(outDir, legacyLayerFileName) - l, err := s.ls.Get(id) - if err != nil { - return distribution.Descriptor{}, err - } - defer layer.ReleaseAndLog(s.ls, l) - - if oldPath, exists := s.diffIDPaths[l.DiffID()]; exists { - relPath, err := filepath.Rel(outDir, oldPath) - if err != nil { - return distribution.Descriptor{}, err - } - os.Symlink(relPath, layerPath) - } else { - // Use system.CreateSequential rather than os.Create. This ensures sequential - // file access on Windows to avoid eating into MM standby list. - // On Linux, this equates to a regular os.Create. - tarFile, err := system.CreateSequential(layerPath) - if err != nil { - return distribution.Descriptor{}, err - } - defer tarFile.Close() - - arch, err := l.TarStream() - if err != nil { - return distribution.Descriptor{}, err - } - defer arch.Close() - - if _, err := io.Copy(tarFile, arch); err != nil { - return distribution.Descriptor{}, err - } - - for _, fname := range []string{"", legacyVersionFileName, legacyConfigFileName, legacyLayerFileName} { - // todo: maybe save layer created timestamp? - if err := system.Chtimes(filepath.Join(outDir, fname), createdTime, createdTime); err != nil { - return distribution.Descriptor{}, err - } - } - - s.diffIDPaths[l.DiffID()] = layerPath - } - s.savedLayers[legacyImg.ID] = struct{}{} - - var src distribution.Descriptor - if fs, ok := l.(distribution.Describable); ok { - src = fs.Descriptor() - } - return src, nil -} diff --git a/vendor/github.com/docker/docker/image/tarexport/tarexport.go b/vendor/github.com/docker/docker/image/tarexport/tarexport.go deleted file mode 100644 index c0be954..0000000 --- a/vendor/github.com/docker/docker/image/tarexport/tarexport.go +++ /dev/null @@ -1,47 +0,0 @@ -package tarexport - -import ( - "github.com/docker/distribution" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/reference" -) - -const ( - manifestFileName = "manifest.json" - legacyLayerFileName = "layer.tar" - legacyConfigFileName = "json" - legacyVersionFileName = "VERSION" - legacyRepositoriesFileName = "repositories" -) - -type manifestItem struct { - Config string - RepoTags []string - Layers []string - Parent image.ID `json:",omitempty"` - LayerSources map[layer.DiffID]distribution.Descriptor `json:",omitempty"` -} - -type tarexporter struct { - is image.Store - ls layer.Store - rs reference.Store - loggerImgEvent LogImageEvent -} - -// LogImageEvent defines interface for event generation related to image tar(load and save) operations -type LogImageEvent interface { - //LogImageEvent generates an event related to an image operation - LogImageEvent(imageID, refName, action string) -} - -// NewTarExporter returns new ImageExporter for tar packages -func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store, loggerImgEvent LogImageEvent) image.Exporter { - return &tarexporter{ - is: is, - ls: ls, - rs: rs, - loggerImgEvent: loggerImgEvent, - } -} diff --git a/vendor/github.com/docker/docker/image/v1/imagev1.go b/vendor/github.com/docker/docker/image/v1/imagev1.go deleted file mode 100644 index d498ddb..0000000 --- a/vendor/github.com/docker/docker/image/v1/imagev1.go +++ /dev/null @@ -1,156 +0,0 @@ -package v1 - -import ( - "encoding/json" - "fmt" - "reflect" - "regexp" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" -) - -var validHex = regexp.MustCompile(`^([a-f0-9]{64})$`) - -// noFallbackMinVersion is the minimum version for which v1compatibility -// information will not be marshaled through the Image struct to remove -// blank fields. -var noFallbackMinVersion = "1.8.3" - -// HistoryFromConfig creates a History struct from v1 configuration JSON -func HistoryFromConfig(imageJSON []byte, emptyLayer bool) (image.History, error) { - h := image.History{} - var v1Image image.V1Image - if err := json.Unmarshal(imageJSON, &v1Image); err != nil { - return h, err - } - - return image.History{ - Author: v1Image.Author, - Created: v1Image.Created, - CreatedBy: strings.Join(v1Image.ContainerConfig.Cmd, " "), - Comment: v1Image.Comment, - EmptyLayer: emptyLayer, - }, nil -} - -// CreateID creates an ID from v1 image, layerID and parent ID. -// Used for backwards compatibility with old clients. -func CreateID(v1Image image.V1Image, layerID layer.ChainID, parent digest.Digest) (digest.Digest, error) { - v1Image.ID = "" - v1JSON, err := json.Marshal(v1Image) - if err != nil { - return "", err - } - - var config map[string]*json.RawMessage - if err := json.Unmarshal(v1JSON, &config); err != nil { - return "", err - } - - // FIXME: note that this is slightly incompatible with RootFS logic - config["layer_id"] = rawJSON(layerID) - if parent != "" { - config["parent"] = rawJSON(parent) - } - - configJSON, err := json.Marshal(config) - if err != nil { - return "", err - } - logrus.Debugf("CreateV1ID %s", configJSON) - - return digest.FromBytes(configJSON), nil -} - -// MakeConfigFromV1Config creates an image config from the legacy V1 config format. -func MakeConfigFromV1Config(imageJSON []byte, rootfs *image.RootFS, history []image.History) ([]byte, error) { - var dver struct { - DockerVersion string `json:"docker_version"` - } - - if err := json.Unmarshal(imageJSON, &dver); err != nil { - return nil, err - } - - useFallback := versions.LessThan(dver.DockerVersion, noFallbackMinVersion) - - if useFallback { - var v1Image image.V1Image - err := json.Unmarshal(imageJSON, &v1Image) - if err != nil { - return nil, err - } - imageJSON, err = json.Marshal(v1Image) - if err != nil { - return nil, err - } - } - - var c map[string]*json.RawMessage - if err := json.Unmarshal(imageJSON, &c); err != nil { - return nil, err - } - - delete(c, "id") - delete(c, "parent") - delete(c, "Size") // Size is calculated from data on disk and is inconsistent - delete(c, "parent_id") - delete(c, "layer_id") - delete(c, "throwaway") - - c["rootfs"] = rawJSON(rootfs) - c["history"] = rawJSON(history) - - return json.Marshal(c) -} - -// MakeV1ConfigFromConfig creates an legacy V1 image config from an Image struct -func MakeV1ConfigFromConfig(img *image.Image, v1ID, parentV1ID string, throwaway bool) ([]byte, error) { - // Top-level v1compatibility string should be a modified version of the - // image config. - var configAsMap map[string]*json.RawMessage - if err := json.Unmarshal(img.RawJSON(), &configAsMap); err != nil { - return nil, err - } - - // Delete fields that didn't exist in old manifest - imageType := reflect.TypeOf(img).Elem() - for i := 0; i < imageType.NumField(); i++ { - f := imageType.Field(i) - jsonName := strings.Split(f.Tag.Get("json"), ",")[0] - // Parent is handled specially below. - if jsonName != "" && jsonName != "parent" { - delete(configAsMap, jsonName) - } - } - configAsMap["id"] = rawJSON(v1ID) - if parentV1ID != "" { - configAsMap["parent"] = rawJSON(parentV1ID) - } - if throwaway { - configAsMap["throwaway"] = rawJSON(true) - } - - return json.Marshal(configAsMap) -} - -func rawJSON(value interface{}) *json.RawMessage { - jsonval, err := json.Marshal(value) - if err != nil { - return nil - } - return (*json.RawMessage)(&jsonval) -} - -// ValidateID checks whether an ID string is a valid image ID. -func ValidateID(id string) error { - if ok := validHex.MatchString(id); !ok { - return fmt.Errorf("image ID %q is invalid", id) - } - return nil -} diff --git a/vendor/github.com/docker/docker/image/v1/imagev1_test.go b/vendor/github.com/docker/docker/image/v1/imagev1_test.go deleted file mode 100644 index 936c55e..0000000 --- a/vendor/github.com/docker/docker/image/v1/imagev1_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package v1 - -import ( - "encoding/json" - "testing" - - "github.com/docker/docker/image" -) - -func TestMakeV1ConfigFromConfig(t *testing.T) { - img := &image.Image{ - V1Image: image.V1Image{ - ID: "v2id", - Parent: "v2parent", - OS: "os", - }, - OSVersion: "osversion", - RootFS: &image.RootFS{ - Type: "layers", - }, - } - v2js, err := json.Marshal(img) - if err != nil { - t.Fatal(err) - } - - // Convert the image back in order to get RawJSON() support. - img, err = image.NewFromJSON(v2js) - if err != nil { - t.Fatal(err) - } - - js, err := MakeV1ConfigFromConfig(img, "v1id", "v1parent", false) - if err != nil { - t.Fatal(err) - } - - newimg := &image.Image{} - err = json.Unmarshal(js, newimg) - if err != nil { - t.Fatal(err) - } - - if newimg.V1Image.ID != "v1id" || newimg.Parent != "v1parent" { - t.Error("ids should have changed", newimg.V1Image.ID, newimg.V1Image.Parent) - } - - if newimg.RootFS != nil { - t.Error("rootfs should have been removed") - } - - if newimg.V1Image.OS != "os" { - t.Error("os should have been preserved") - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/benchmark_test.go b/vendor/github.com/docker/docker/integration-cli/benchmark_test.go deleted file mode 100644 index b87e131..0000000 --- a/vendor/github.com/docker/docker/integration-cli/benchmark_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os" - "runtime" - "strings" - "sync" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) BenchmarkConcurrentContainerActions(c *check.C) { - maxConcurrency := runtime.GOMAXPROCS(0) - numIterations := c.N - outerGroup := &sync.WaitGroup{} - outerGroup.Add(maxConcurrency) - chErr := make(chan error, numIterations*2*maxConcurrency) - - for i := 0; i < maxConcurrency; i++ { - go func() { - defer outerGroup.Done() - innerGroup := &sync.WaitGroup{} - innerGroup.Add(2) - - go func() { - defer innerGroup.Done() - for i := 0; i < numIterations; i++ { - args := []string{"run", "-d", defaultSleepImage} - args = append(args, sleepCommandForDaemonPlatform()...) - out, _, err := dockerCmdWithError(args...) - if err != nil { - chErr <- fmt.Errorf(out) - return - } - - id := strings.TrimSpace(out) - tmpDir, err := ioutil.TempDir("", "docker-concurrent-test-"+id) - if err != nil { - chErr <- err - return - } - defer os.RemoveAll(tmpDir) - out, _, err = dockerCmdWithError("cp", id+":/tmp", tmpDir) - if err != nil { - chErr <- fmt.Errorf(out) - return - } - - out, _, err = dockerCmdWithError("kill", id) - if err != nil { - chErr <- fmt.Errorf(out) - } - - out, _, err = dockerCmdWithError("start", id) - if err != nil { - chErr <- fmt.Errorf(out) - } - - out, _, err = dockerCmdWithError("kill", id) - if err != nil { - chErr <- fmt.Errorf(out) - } - - // don't do an rm -f here since it can potentially ignore errors from the graphdriver - out, _, err = dockerCmdWithError("rm", id) - if err != nil { - chErr <- fmt.Errorf(out) - } - } - }() - - go func() { - defer innerGroup.Done() - for i := 0; i < numIterations; i++ { - out, _, err := dockerCmdWithError("ps") - if err != nil { - chErr <- fmt.Errorf(out) - } - } - }() - - innerGroup.Wait() - }() - } - - outerGroup.Wait() - close(chErr) - - for err := range chErr { - c.Assert(err, checker.IsNil) - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/check_test.go b/vendor/github.com/docker/docker/integration-cli/check_test.go deleted file mode 100644 index 7084d6f..0000000 --- a/vendor/github.com/docker/docker/integration-cli/check_test.go +++ /dev/null @@ -1,383 +0,0 @@ -package main - -import ( - "fmt" - "net/http/httptest" - "os" - "path/filepath" - "sync" - "syscall" - "testing" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/pkg/reexec" - "github.com/go-check/check" -) - -func Test(t *testing.T) { - reexec.Init() // This is required for external graphdriver tests - - if !isLocalDaemon { - fmt.Println("INFO: Testing against a remote daemon") - } else { - fmt.Println("INFO: Testing against a local daemon") - } - - if daemonPlatform == "linux" { - ensureFrozenImagesLinux(t) - } - check.TestingT(t) -} - -func init() { - check.Suite(&DockerSuite{}) -} - -type DockerSuite struct { -} - -func (s *DockerSuite) OnTimeout(c *check.C) { - if daemonPid > 0 && isLocalDaemon { - signalDaemonDump(daemonPid) - } -} - -func (s *DockerSuite) TearDownTest(c *check.C) { - unpauseAllContainers() - deleteAllContainers() - deleteAllImages() - deleteAllVolumes() - deleteAllNetworks() - deleteAllPlugins() -} - -func init() { - check.Suite(&DockerRegistrySuite{ - ds: &DockerSuite{}, - }) -} - -type DockerRegistrySuite struct { - ds *DockerSuite - reg *testRegistryV2 - d *Daemon -} - -func (s *DockerRegistrySuite) OnTimeout(c *check.C) { - s.d.DumpStackAndQuit() -} - -func (s *DockerRegistrySuite) SetUpTest(c *check.C) { - testRequires(c, DaemonIsLinux, RegistryHosting) - s.reg = setupRegistry(c, false, "", "") - s.d = NewDaemon(c) -} - -func (s *DockerRegistrySuite) TearDownTest(c *check.C) { - if s.reg != nil { - s.reg.Close() - } - if s.d != nil { - s.d.Stop() - } - s.ds.TearDownTest(c) -} - -func init() { - check.Suite(&DockerSchema1RegistrySuite{ - ds: &DockerSuite{}, - }) -} - -type DockerSchema1RegistrySuite struct { - ds *DockerSuite - reg *testRegistryV2 - d *Daemon -} - -func (s *DockerSchema1RegistrySuite) OnTimeout(c *check.C) { - s.d.DumpStackAndQuit() -} - -func (s *DockerSchema1RegistrySuite) SetUpTest(c *check.C) { - testRequires(c, DaemonIsLinux, RegistryHosting, NotArm64) - s.reg = setupRegistry(c, true, "", "") - s.d = NewDaemon(c) -} - -func (s *DockerSchema1RegistrySuite) TearDownTest(c *check.C) { - if s.reg != nil { - s.reg.Close() - } - if s.d != nil { - s.d.Stop() - } - s.ds.TearDownTest(c) -} - -func init() { - check.Suite(&DockerRegistryAuthHtpasswdSuite{ - ds: &DockerSuite{}, - }) -} - -type DockerRegistryAuthHtpasswdSuite struct { - ds *DockerSuite - reg *testRegistryV2 - d *Daemon -} - -func (s *DockerRegistryAuthHtpasswdSuite) OnTimeout(c *check.C) { - s.d.DumpStackAndQuit() -} - -func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(c *check.C) { - testRequires(c, DaemonIsLinux, RegistryHosting) - s.reg = setupRegistry(c, false, "htpasswd", "") - s.d = NewDaemon(c) -} - -func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(c *check.C) { - if s.reg != nil { - out, err := s.d.Cmd("logout", privateRegistryURL) - c.Assert(err, check.IsNil, check.Commentf(out)) - s.reg.Close() - } - if s.d != nil { - s.d.Stop() - } - s.ds.TearDownTest(c) -} - -func init() { - check.Suite(&DockerRegistryAuthTokenSuite{ - ds: &DockerSuite{}, - }) -} - -type DockerRegistryAuthTokenSuite struct { - ds *DockerSuite - reg *testRegistryV2 - d *Daemon -} - -func (s *DockerRegistryAuthTokenSuite) OnTimeout(c *check.C) { - s.d.DumpStackAndQuit() -} - -func (s *DockerRegistryAuthTokenSuite) SetUpTest(c *check.C) { - testRequires(c, DaemonIsLinux, RegistryHosting) - s.d = NewDaemon(c) -} - -func (s *DockerRegistryAuthTokenSuite) TearDownTest(c *check.C) { - if s.reg != nil { - out, err := s.d.Cmd("logout", privateRegistryURL) - c.Assert(err, check.IsNil, check.Commentf(out)) - s.reg.Close() - } - if s.d != nil { - s.d.Stop() - } - s.ds.TearDownTest(c) -} - -func (s *DockerRegistryAuthTokenSuite) setupRegistryWithTokenService(c *check.C, tokenURL string) { - if s == nil { - c.Fatal("registry suite isn't initialized") - } - s.reg = setupRegistry(c, false, "token", tokenURL) -} - -func init() { - check.Suite(&DockerDaemonSuite{ - ds: &DockerSuite{}, - }) -} - -type DockerDaemonSuite struct { - ds *DockerSuite - d *Daemon -} - -func (s *DockerDaemonSuite) OnTimeout(c *check.C) { - s.d.DumpStackAndQuit() -} - -func (s *DockerDaemonSuite) SetUpTest(c *check.C) { - testRequires(c, DaemonIsLinux) - s.d = NewDaemon(c) -} - -func (s *DockerDaemonSuite) TearDownTest(c *check.C) { - testRequires(c, DaemonIsLinux) - if s.d != nil { - s.d.Stop() - } - s.ds.TearDownTest(c) -} - -func (s *DockerDaemonSuite) TearDownSuite(c *check.C) { - filepath.Walk(daemonSockRoot, func(path string, fi os.FileInfo, err error) error { - if err != nil { - // ignore errors here - // not cleaning up sockets is not really an error - return nil - } - if fi.Mode() == os.ModeSocket { - syscall.Unlink(path) - } - return nil - }) - os.RemoveAll(daemonSockRoot) -} - -const defaultSwarmPort = 2477 - -func init() { - check.Suite(&DockerSwarmSuite{ - ds: &DockerSuite{}, - }) -} - -type DockerSwarmSuite struct { - server *httptest.Server - ds *DockerSuite - daemons []*SwarmDaemon - daemonsLock sync.Mutex // protect access to daemons - portIndex int -} - -func (s *DockerSwarmSuite) OnTimeout(c *check.C) { - s.daemonsLock.Lock() - defer s.daemonsLock.Unlock() - for _, d := range s.daemons { - d.DumpStackAndQuit() - } -} - -func (s *DockerSwarmSuite) SetUpTest(c *check.C) { - testRequires(c, DaemonIsLinux) -} - -func (s *DockerSwarmSuite) AddDaemon(c *check.C, joinSwarm, manager bool) *SwarmDaemon { - d := &SwarmDaemon{ - Daemon: NewDaemon(c), - port: defaultSwarmPort + s.portIndex, - } - d.listenAddr = fmt.Sprintf("0.0.0.0:%d", d.port) - args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"} // avoid networking conflicts - if experimentalDaemon { - args = append(args, "--experimental") - } - err := d.StartWithBusybox(args...) - c.Assert(err, check.IsNil) - - if joinSwarm == true { - if len(s.daemons) > 0 { - tokens := s.daemons[0].joinTokens(c) - token := tokens.Worker - if manager { - token = tokens.Manager - } - c.Assert(d.Join(swarm.JoinRequest{ - RemoteAddrs: []string{s.daemons[0].listenAddr}, - JoinToken: token, - }), check.IsNil) - } else { - c.Assert(d.Init(swarm.InitRequest{}), check.IsNil) - } - } - - s.portIndex++ - s.daemonsLock.Lock() - s.daemons = append(s.daemons, d) - s.daemonsLock.Unlock() - - return d -} - -func (s *DockerSwarmSuite) TearDownTest(c *check.C) { - testRequires(c, DaemonIsLinux) - s.daemonsLock.Lock() - for _, d := range s.daemons { - d.Stop() - // raft state file is quite big (64MB) so remove it after every test - walDir := filepath.Join(d.root, "swarm/raft/wal") - if err := os.RemoveAll(walDir); err != nil { - c.Logf("error removing %v: %v", walDir, err) - } - - cleanupExecRoot(c, d.execRoot) - } - s.daemons = nil - s.daemonsLock.Unlock() - - s.portIndex = 0 - s.ds.TearDownTest(c) -} - -func init() { - check.Suite(&DockerTrustSuite{ - ds: &DockerSuite{}, - }) -} - -type DockerTrustSuite struct { - ds *DockerSuite - reg *testRegistryV2 - not *testNotary -} - -func (s *DockerTrustSuite) SetUpTest(c *check.C) { - testRequires(c, RegistryHosting, NotaryServerHosting) - s.reg = setupRegistry(c, false, "", "") - s.not = setupNotary(c) -} - -func (s *DockerTrustSuite) TearDownTest(c *check.C) { - if s.reg != nil { - s.reg.Close() - } - if s.not != nil { - s.not.Close() - } - - // Remove trusted keys and metadata after test - os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust")) - s.ds.TearDownTest(c) -} - -func init() { - ds := &DockerSuite{} - check.Suite(&DockerTrustedSwarmSuite{ - trustSuite: DockerTrustSuite{ - ds: ds, - }, - swarmSuite: DockerSwarmSuite{ - ds: ds, - }, - }) -} - -type DockerTrustedSwarmSuite struct { - swarmSuite DockerSwarmSuite - trustSuite DockerTrustSuite - reg *testRegistryV2 - not *testNotary -} - -func (s *DockerTrustedSwarmSuite) SetUpTest(c *check.C) { - s.swarmSuite.SetUpTest(c) - s.trustSuite.SetUpTest(c) -} - -func (s *DockerTrustedSwarmSuite) TearDownTest(c *check.C) { - s.trustSuite.TearDownTest(c) - s.swarmSuite.TearDownTest(c) -} - -func (s *DockerTrustedSwarmSuite) OnTimeout(c *check.C) { - s.swarmSuite.OnTimeout(c) -} diff --git a/vendor/github.com/docker/docker/integration-cli/daemon.go b/vendor/github.com/docker/docker/integration-cli/daemon.go deleted file mode 100644 index 9fd3f1e..0000000 --- a/vendor/github.com/docker/docker/integration-cli/daemon.go +++ /dev/null @@ -1,608 +0,0 @@ -package main - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io" - "net/http" - "os" - "os/exec" - "path/filepath" - "strconv" - "strings" - "time" - - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/go-connections/sockets" - "github.com/docker/go-connections/tlsconfig" - "github.com/go-check/check" -) - -var daemonSockRoot = filepath.Join(os.TempDir(), "docker-integration") - -// Daemon represents a Docker daemon for the testing framework. -type Daemon struct { - GlobalFlags []string - - id string - c *check.C - logFile *os.File - folder string - root string - stdin io.WriteCloser - stdout, stderr io.ReadCloser - cmd *exec.Cmd - storageDriver string - wait chan error - userlandProxy bool - useDefaultHost bool - useDefaultTLSHost bool - execRoot string -} - -type clientConfig struct { - transport *http.Transport - scheme string - addr string -} - -// NewDaemon returns a Daemon instance to be used for testing. -// This will create a directory such as d123456789 in the folder specified by $DEST. -// The daemon will not automatically start. -func NewDaemon(c *check.C) *Daemon { - dest := os.Getenv("DEST") - c.Assert(dest, check.Not(check.Equals), "", check.Commentf("Please set the DEST environment variable")) - - err := os.MkdirAll(daemonSockRoot, 0700) - c.Assert(err, checker.IsNil, check.Commentf("could not create daemon socket root")) - - id := fmt.Sprintf("d%s", stringid.TruncateID(stringid.GenerateRandomID())) - dir := filepath.Join(dest, id) - daemonFolder, err := filepath.Abs(dir) - c.Assert(err, check.IsNil, check.Commentf("Could not make %q an absolute path", dir)) - daemonRoot := filepath.Join(daemonFolder, "root") - - c.Assert(os.MkdirAll(daemonRoot, 0755), check.IsNil, check.Commentf("Could not create daemon root %q", dir)) - - userlandProxy := true - if env := os.Getenv("DOCKER_USERLANDPROXY"); env != "" { - if val, err := strconv.ParseBool(env); err != nil { - userlandProxy = val - } - } - - return &Daemon{ - id: id, - c: c, - folder: daemonFolder, - root: daemonRoot, - storageDriver: os.Getenv("DOCKER_GRAPHDRIVER"), - userlandProxy: userlandProxy, - execRoot: filepath.Join(os.TempDir(), "docker-execroot", id), - } -} - -// RootDir returns the root directory of the daemon. -func (d *Daemon) RootDir() string { - return d.root -} - -func (d *Daemon) getClientConfig() (*clientConfig, error) { - var ( - transport *http.Transport - scheme string - addr string - proto string - ) - if d.useDefaultTLSHost { - option := &tlsconfig.Options{ - CAFile: "fixtures/https/ca.pem", - CertFile: "fixtures/https/client-cert.pem", - KeyFile: "fixtures/https/client-key.pem", - } - tlsConfig, err := tlsconfig.Client(*option) - if err != nil { - return nil, err - } - transport = &http.Transport{ - TLSClientConfig: tlsConfig, - } - addr = fmt.Sprintf("%s:%d", opts.DefaultHTTPHost, opts.DefaultTLSHTTPPort) - scheme = "https" - proto = "tcp" - } else if d.useDefaultHost { - addr = opts.DefaultUnixSocket - proto = "unix" - scheme = "http" - transport = &http.Transport{} - } else { - addr = d.sockPath() - proto = "unix" - scheme = "http" - transport = &http.Transport{} - } - - d.c.Assert(sockets.ConfigureTransport(transport, proto, addr), check.IsNil) - - return &clientConfig{ - transport: transport, - scheme: scheme, - addr: addr, - }, nil -} - -// Start will start the daemon and return once it is ready to receive requests. -// You can specify additional daemon flags. -func (d *Daemon) Start(args ...string) error { - logFile, err := os.OpenFile(filepath.Join(d.folder, "docker.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600) - d.c.Assert(err, check.IsNil, check.Commentf("[%s] Could not create %s/docker.log", d.id, d.folder)) - - return d.StartWithLogFile(logFile, args...) -} - -// StartWithLogFile will start the daemon and attach its streams to a given file. -func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error { - dockerdBinary, err := exec.LookPath(dockerdBinary) - d.c.Assert(err, check.IsNil, check.Commentf("[%s] could not find docker binary in $PATH", d.id)) - - args := append(d.GlobalFlags, - "--containerd", "/var/run/docker/libcontainerd/docker-containerd.sock", - "--graph", d.root, - "--exec-root", d.execRoot, - "--pidfile", fmt.Sprintf("%s/docker.pid", d.folder), - fmt.Sprintf("--userland-proxy=%t", d.userlandProxy), - ) - if experimentalDaemon { - args = append(args, "--experimental", "--init") - } - if !(d.useDefaultHost || d.useDefaultTLSHost) { - args = append(args, []string{"--host", d.sock()}...) - } - if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" { - args = append(args, []string{"--userns-remap", root}...) - } - - // If we don't explicitly set the log-level or debug flag(-D) then - // turn on debug mode - foundLog := false - foundSd := false - for _, a := range providedArgs { - if strings.Contains(a, "--log-level") || strings.Contains(a, "-D") || strings.Contains(a, "--debug") { - foundLog = true - } - if strings.Contains(a, "--storage-driver") { - foundSd = true - } - } - if !foundLog { - args = append(args, "--debug") - } - if d.storageDriver != "" && !foundSd { - args = append(args, "--storage-driver", d.storageDriver) - } - - args = append(args, providedArgs...) - d.cmd = exec.Command(dockerdBinary, args...) - d.cmd.Env = append(os.Environ(), "DOCKER_SERVICE_PREFER_OFFLINE_IMAGE=1") - d.cmd.Stdout = out - d.cmd.Stderr = out - d.logFile = out - - if err := d.cmd.Start(); err != nil { - return fmt.Errorf("[%s] could not start daemon container: %v", d.id, err) - } - - wait := make(chan error) - - go func() { - wait <- d.cmd.Wait() - d.c.Logf("[%s] exiting daemon", d.id) - close(wait) - }() - - d.wait = wait - - tick := time.Tick(500 * time.Millisecond) - // make sure daemon is ready to receive requests - startTime := time.Now().Unix() - for { - d.c.Logf("[%s] waiting for daemon to start", d.id) - if time.Now().Unix()-startTime > 5 { - // After 5 seconds, give up - return fmt.Errorf("[%s] Daemon exited and never started", d.id) - } - select { - case <-time.After(2 * time.Second): - return fmt.Errorf("[%s] timeout: daemon does not respond", d.id) - case <-tick: - clientConfig, err := d.getClientConfig() - if err != nil { - return err - } - - client := &http.Client{ - Transport: clientConfig.transport, - } - - req, err := http.NewRequest("GET", "/_ping", nil) - d.c.Assert(err, check.IsNil, check.Commentf("[%s] could not create new request", d.id)) - req.URL.Host = clientConfig.addr - req.URL.Scheme = clientConfig.scheme - resp, err := client.Do(req) - if err != nil { - continue - } - if resp.StatusCode != http.StatusOK { - d.c.Logf("[%s] received status != 200 OK: %s", d.id, resp.Status) - } - d.c.Logf("[%s] daemon started", d.id) - d.root, err = d.queryRootDir() - if err != nil { - return fmt.Errorf("[%s] error querying daemon for root directory: %v", d.id, err) - } - return nil - case <-d.wait: - return fmt.Errorf("[%s] Daemon exited during startup", d.id) - } - } -} - -// StartWithBusybox will first start the daemon with Daemon.Start() -// then save the busybox image from the main daemon and load it into this Daemon instance. -func (d *Daemon) StartWithBusybox(arg ...string) error { - if err := d.Start(arg...); err != nil { - return err - } - return d.LoadBusybox() -} - -// Kill will send a SIGKILL to the daemon -func (d *Daemon) Kill() error { - if d.cmd == nil || d.wait == nil { - return errors.New("daemon not started") - } - - defer func() { - d.logFile.Close() - d.cmd = nil - }() - - if err := d.cmd.Process.Kill(); err != nil { - d.c.Logf("Could not kill daemon: %v", err) - return err - } - - if err := os.Remove(fmt.Sprintf("%s/docker.pid", d.folder)); err != nil { - return err - } - - return nil -} - -// DumpStackAndQuit sends SIGQUIT to the daemon, which triggers it to dump its -// stack to its log file and exit -// This is used primarily for gathering debug information on test timeout -func (d *Daemon) DumpStackAndQuit() { - if d.cmd == nil || d.cmd.Process == nil { - return - } - signalDaemonDump(d.cmd.Process.Pid) -} - -// Stop will send a SIGINT every second and wait for the daemon to stop. -// If it timeouts, a SIGKILL is sent. -// Stop will not delete the daemon directory. If a purged daemon is needed, -// instantiate a new one with NewDaemon. -func (d *Daemon) Stop() error { - if d.cmd == nil || d.wait == nil { - return errors.New("daemon not started") - } - - defer func() { - d.logFile.Close() - d.cmd = nil - }() - - i := 1 - tick := time.Tick(time.Second) - - if err := d.cmd.Process.Signal(os.Interrupt); err != nil { - return fmt.Errorf("could not send signal: %v", err) - } -out1: - for { - select { - case err := <-d.wait: - return err - case <-time.After(20 * time.Second): - // time for stopping jobs and run onShutdown hooks - d.c.Logf("timeout: %v", d.id) - break out1 - } - } - -out2: - for { - select { - case err := <-d.wait: - return err - case <-tick: - i++ - if i > 5 { - d.c.Logf("tried to interrupt daemon for %d times, now try to kill it", i) - break out2 - } - d.c.Logf("Attempt #%d: daemon is still running with pid %d", i, d.cmd.Process.Pid) - if err := d.cmd.Process.Signal(os.Interrupt); err != nil { - return fmt.Errorf("could not send signal: %v", err) - } - } - } - - if err := d.cmd.Process.Kill(); err != nil { - d.c.Logf("Could not kill daemon: %v", err) - return err - } - - if err := os.Remove(fmt.Sprintf("%s/docker.pid", d.folder)); err != nil { - return err - } - - return nil -} - -// Restart will restart the daemon by first stopping it and then starting it. -func (d *Daemon) Restart(arg ...string) error { - d.Stop() - // in the case of tests running a user namespace-enabled daemon, we have resolved - // d.root to be the actual final path of the graph dir after the "uid.gid" of - // remapped root is added--we need to subtract it from the path before calling - // start or else we will continue making subdirectories rather than truly restarting - // with the same location/root: - if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" { - d.root = filepath.Dir(d.root) - } - return d.Start(arg...) -} - -// LoadBusybox will load the stored busybox into a newly started daemon -func (d *Daemon) LoadBusybox() error { - bb := filepath.Join(d.folder, "busybox.tar") - if _, err := os.Stat(bb); err != nil { - if !os.IsNotExist(err) { - return fmt.Errorf("unexpected error on busybox.tar stat: %v", err) - } - // saving busybox image from main daemon - if out, err := exec.Command(dockerBinary, "save", "--output", bb, "busybox:latest").CombinedOutput(); err != nil { - imagesOut, _ := exec.Command(dockerBinary, "images", "--format", "{{ .Repository }}:{{ .Tag }}").CombinedOutput() - return fmt.Errorf("could not save busybox image: %s\n%s", string(out), strings.TrimSpace(string(imagesOut))) - } - } - // loading busybox image to this daemon - if out, err := d.Cmd("load", "--input", bb); err != nil { - return fmt.Errorf("could not load busybox image: %s", out) - } - if err := os.Remove(bb); err != nil { - d.c.Logf("could not remove %s: %v", bb, err) - } - return nil -} - -func (d *Daemon) queryRootDir() (string, error) { - // update daemon root by asking /info endpoint (to support user - // namespaced daemon with root remapped uid.gid directory) - clientConfig, err := d.getClientConfig() - if err != nil { - return "", err - } - - client := &http.Client{ - Transport: clientConfig.transport, - } - - req, err := http.NewRequest("GET", "/info", nil) - if err != nil { - return "", err - } - req.Header.Set("Content-Type", "application/json") - req.URL.Host = clientConfig.addr - req.URL.Scheme = clientConfig.scheme - - resp, err := client.Do(req) - if err != nil { - return "", err - } - body := ioutils.NewReadCloserWrapper(resp.Body, func() error { - return resp.Body.Close() - }) - - type Info struct { - DockerRootDir string - } - var b []byte - var i Info - b, err = readBody(body) - if err == nil && resp.StatusCode == http.StatusOK { - // read the docker root dir - if err = json.Unmarshal(b, &i); err == nil { - return i.DockerRootDir, nil - } - } - return "", err -} - -func (d *Daemon) sock() string { - return fmt.Sprintf("unix://" + d.sockPath()) -} - -func (d *Daemon) sockPath() string { - return filepath.Join(daemonSockRoot, d.id+".sock") -} - -func (d *Daemon) waitRun(contID string) error { - args := []string{"--host", d.sock()} - return waitInspectWithArgs(contID, "{{.State.Running}}", "true", 10*time.Second, args...) -} - -func (d *Daemon) getBaseDeviceSize(c *check.C) int64 { - infoCmdOutput, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "-H", d.sock(), "info"), - exec.Command("grep", "Base Device Size"), - ) - c.Assert(err, checker.IsNil) - basesizeSlice := strings.Split(infoCmdOutput, ":") - basesize := strings.Trim(basesizeSlice[1], " ") - basesize = strings.Trim(basesize, "\n")[:len(basesize)-3] - basesizeFloat, err := strconv.ParseFloat(strings.Trim(basesize, " "), 64) - c.Assert(err, checker.IsNil) - basesizeBytes := int64(basesizeFloat) * (1024 * 1024 * 1024) - return basesizeBytes -} - -// Cmd will execute a docker CLI command against this Daemon. -// Example: d.Cmd("version") will run docker -H unix://path/to/unix.sock version -func (d *Daemon) Cmd(args ...string) (string, error) { - b, err := d.command(args...).CombinedOutput() - return string(b), err -} - -func (d *Daemon) command(args ...string) *exec.Cmd { - return exec.Command(dockerBinary, d.prependHostArg(args)...) -} - -func (d *Daemon) prependHostArg(args []string) []string { - for _, arg := range args { - if arg == "--host" || arg == "-H" { - return args - } - } - return append([]string{"--host", d.sock()}, args...) -} - -// SockRequest executes a socket request on a daemon and returns statuscode and output. -func (d *Daemon) SockRequest(method, endpoint string, data interface{}) (int, []byte, error) { - jsonData := bytes.NewBuffer(nil) - if err := json.NewEncoder(jsonData).Encode(data); err != nil { - return -1, nil, err - } - - res, body, err := d.SockRequestRaw(method, endpoint, jsonData, "application/json") - if err != nil { - return -1, nil, err - } - b, err := readBody(body) - return res.StatusCode, b, err -} - -// SockRequestRaw executes a socket request on a daemon and returns an http -// response and a reader for the output data. -func (d *Daemon) SockRequestRaw(method, endpoint string, data io.Reader, ct string) (*http.Response, io.ReadCloser, error) { - return sockRequestRawToDaemon(method, endpoint, data, ct, d.sock()) -} - -// LogFileName returns the path the the daemon's log file -func (d *Daemon) LogFileName() string { - return d.logFile.Name() -} - -func (d *Daemon) getIDByName(name string) (string, error) { - return d.inspectFieldWithError(name, "Id") -} - -func (d *Daemon) activeContainers() (ids []string) { - out, _ := d.Cmd("ps", "-q") - for _, id := range strings.Split(out, "\n") { - if id = strings.TrimSpace(id); id != "" { - ids = append(ids, id) - } - } - return -} - -func (d *Daemon) inspectFilter(name, filter string) (string, error) { - format := fmt.Sprintf("{{%s}}", filter) - out, err := d.Cmd("inspect", "-f", format, name) - if err != nil { - return "", fmt.Errorf("failed to inspect %s: %s", name, out) - } - return strings.TrimSpace(out), nil -} - -func (d *Daemon) inspectFieldWithError(name, field string) (string, error) { - return d.inspectFilter(name, fmt.Sprintf(".%s", field)) -} - -func (d *Daemon) findContainerIP(id string) string { - out, err := d.Cmd("inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.bridge.IPAddress }}'"), id) - if err != nil { - d.c.Log(err) - } - return strings.Trim(out, " \r\n'") -} - -func (d *Daemon) buildImageWithOut(name, dockerfile string, useCache bool, buildFlags ...string) (string, int, error) { - buildCmd := buildImageCmdWithHost(name, dockerfile, d.sock(), useCache, buildFlags...) - return runCommandWithOutput(buildCmd) -} - -func (d *Daemon) checkActiveContainerCount(c *check.C) (interface{}, check.CommentInterface) { - out, err := d.Cmd("ps", "-q") - c.Assert(err, checker.IsNil) - if len(strings.TrimSpace(out)) == 0 { - return 0, nil - } - return len(strings.Split(strings.TrimSpace(out), "\n")), check.Commentf("output: %q", string(out)) -} - -func (d *Daemon) reloadConfig() error { - if d.cmd == nil || d.cmd.Process == nil { - return fmt.Errorf("daemon is not running") - } - - errCh := make(chan error) - started := make(chan struct{}) - go func() { - _, body, err := sockRequestRawToDaemon("GET", "/events", nil, "", d.sock()) - close(started) - if err != nil { - errCh <- err - } - defer body.Close() - dec := json.NewDecoder(body) - for { - var e events.Message - if err := dec.Decode(&e); err != nil { - errCh <- err - return - } - if e.Type != events.DaemonEventType { - continue - } - if e.Action != "reload" { - continue - } - close(errCh) // notify that we are done - return - } - }() - - <-started - if err := signalDaemonReload(d.cmd.Process.Pid); err != nil { - return fmt.Errorf("error signaling daemon reload: %v", err) - } - select { - case err := <-errCh: - if err != nil { - return fmt.Errorf("error waiting for daemon reload event: %v", err) - } - case <-time.After(30 * time.Second): - return fmt.Errorf("timeout waiting for daemon reload event") - } - return nil -} diff --git a/vendor/github.com/docker/docker/integration-cli/daemon_swarm.go b/vendor/github.com/docker/docker/integration-cli/daemon_swarm.go deleted file mode 100644 index 199bce0..0000000 --- a/vendor/github.com/docker/docker/integration-cli/daemon_swarm.go +++ /dev/null @@ -1,419 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "net/http" - "strings" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// SwarmDaemon is a test daemon with helpers for participating in a swarm. -type SwarmDaemon struct { - *Daemon - swarm.Info - port int - listenAddr string -} - -// Init initializes a new swarm cluster. -func (d *SwarmDaemon) Init(req swarm.InitRequest) error { - if req.ListenAddr == "" { - req.ListenAddr = d.listenAddr - } - status, out, err := d.SockRequest("POST", "/swarm/init", req) - if status != http.StatusOK { - return fmt.Errorf("initializing swarm: invalid statuscode %v, %q", status, out) - } - if err != nil { - return fmt.Errorf("initializing swarm: %v", err) - } - info, err := d.info() - if err != nil { - return err - } - d.Info = info - return nil -} - -// Join joins a daemon to an existing cluster. -func (d *SwarmDaemon) Join(req swarm.JoinRequest) error { - if req.ListenAddr == "" { - req.ListenAddr = d.listenAddr - } - status, out, err := d.SockRequest("POST", "/swarm/join", req) - if status != http.StatusOK { - return fmt.Errorf("joining swarm: invalid statuscode %v, %q", status, out) - } - if err != nil { - return fmt.Errorf("joining swarm: %v", err) - } - info, err := d.info() - if err != nil { - return err - } - d.Info = info - return nil -} - -// Leave forces daemon to leave current cluster. -func (d *SwarmDaemon) Leave(force bool) error { - url := "/swarm/leave" - if force { - url += "?force=1" - } - status, out, err := d.SockRequest("POST", url, nil) - if status != http.StatusOK { - return fmt.Errorf("leaving swarm: invalid statuscode %v, %q", status, out) - } - if err != nil { - err = fmt.Errorf("leaving swarm: %v", err) - } - return err -} - -func (d *SwarmDaemon) info() (swarm.Info, error) { - var info struct { - Swarm swarm.Info - } - status, dt, err := d.SockRequest("GET", "/info", nil) - if status != http.StatusOK { - return info.Swarm, fmt.Errorf("get swarm info: invalid statuscode %v", status) - } - if err != nil { - return info.Swarm, fmt.Errorf("get swarm info: %v", err) - } - if err := json.Unmarshal(dt, &info); err != nil { - return info.Swarm, err - } - return info.Swarm, nil -} - -type serviceConstructor func(*swarm.Service) -type nodeConstructor func(*swarm.Node) -type specConstructor func(*swarm.Spec) - -func (d *SwarmDaemon) createService(c *check.C, f ...serviceConstructor) string { - var service swarm.Service - for _, fn := range f { - fn(&service) - } - status, out, err := d.SockRequest("POST", "/services/create", service.Spec) - - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf("output: %q", string(out))) - - var scr types.ServiceCreateResponse - c.Assert(json.Unmarshal(out, &scr), checker.IsNil) - return scr.ID -} - -func (d *SwarmDaemon) getService(c *check.C, id string) *swarm.Service { - var service swarm.Service - status, out, err := d.SockRequest("GET", "/services/"+id, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - c.Assert(json.Unmarshal(out, &service), checker.IsNil) - return &service -} - -func (d *SwarmDaemon) getServiceTasks(c *check.C, service string) []swarm.Task { - var tasks []swarm.Task - - filterArgs := filters.NewArgs() - filterArgs.Add("desired-state", "running") - filterArgs.Add("service", service) - filters, err := filters.ToParam(filterArgs) - c.Assert(err, checker.IsNil) - - status, out, err := d.SockRequest("GET", "/tasks?filters="+filters, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - c.Assert(json.Unmarshal(out, &tasks), checker.IsNil) - return tasks -} - -func (d *SwarmDaemon) checkServiceTasksInState(service string, state swarm.TaskState, message string) func(*check.C) (interface{}, check.CommentInterface) { - return func(c *check.C) (interface{}, check.CommentInterface) { - tasks := d.getServiceTasks(c, service) - var count int - for _, task := range tasks { - if task.Status.State == state { - if message == "" || strings.Contains(task.Status.Message, message) { - count++ - } - } - } - return count, nil - } -} - -func (d *SwarmDaemon) checkServiceRunningTasks(service string) func(*check.C) (interface{}, check.CommentInterface) { - return d.checkServiceTasksInState(service, swarm.TaskStateRunning, "") -} - -func (d *SwarmDaemon) checkServiceUpdateState(service string) func(*check.C) (interface{}, check.CommentInterface) { - return func(c *check.C) (interface{}, check.CommentInterface) { - service := d.getService(c, service) - return service.UpdateStatus.State, nil - } -} - -func (d *SwarmDaemon) checkServiceTasks(service string) func(*check.C) (interface{}, check.CommentInterface) { - return func(c *check.C) (interface{}, check.CommentInterface) { - tasks := d.getServiceTasks(c, service) - return len(tasks), nil - } -} - -func (d *SwarmDaemon) checkRunningTaskImages(c *check.C) (interface{}, check.CommentInterface) { - var tasks []swarm.Task - - filterArgs := filters.NewArgs() - filterArgs.Add("desired-state", "running") - filters, err := filters.ToParam(filterArgs) - c.Assert(err, checker.IsNil) - - status, out, err := d.SockRequest("GET", "/tasks?filters="+filters, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - c.Assert(json.Unmarshal(out, &tasks), checker.IsNil) - - result := make(map[string]int) - for _, task := range tasks { - if task.Status.State == swarm.TaskStateRunning { - result[task.Spec.ContainerSpec.Image]++ - } - } - return result, nil -} - -func (d *SwarmDaemon) checkNodeReadyCount(c *check.C) (interface{}, check.CommentInterface) { - nodes := d.listNodes(c) - var readyCount int - for _, node := range nodes { - if node.Status.State == swarm.NodeStateReady { - readyCount++ - } - } - return readyCount, nil -} - -func (d *SwarmDaemon) getTask(c *check.C, id string) swarm.Task { - var task swarm.Task - - status, out, err := d.SockRequest("GET", "/tasks/"+id, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - c.Assert(json.Unmarshal(out, &task), checker.IsNil) - return task -} - -func (d *SwarmDaemon) updateService(c *check.C, service *swarm.Service, f ...serviceConstructor) { - for _, fn := range f { - fn(service) - } - url := fmt.Sprintf("/services/%s/update?version=%d", service.ID, service.Version.Index) - status, out, err := d.SockRequest("POST", url, service.Spec) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) -} - -func (d *SwarmDaemon) removeService(c *check.C, id string) { - status, out, err := d.SockRequest("DELETE", "/services/"+id, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) -} - -func (d *SwarmDaemon) getNode(c *check.C, id string) *swarm.Node { - var node swarm.Node - status, out, err := d.SockRequest("GET", "/nodes/"+id, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - c.Assert(json.Unmarshal(out, &node), checker.IsNil) - c.Assert(node.ID, checker.Equals, id) - return &node -} - -func (d *SwarmDaemon) removeNode(c *check.C, id string, force bool) { - url := "/nodes/" + id - if force { - url += "?force=1" - } - - status, out, err := d.SockRequest("DELETE", url, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) -} - -func (d *SwarmDaemon) updateNode(c *check.C, id string, f ...nodeConstructor) { - for i := 0; ; i++ { - node := d.getNode(c, id) - for _, fn := range f { - fn(node) - } - url := fmt.Sprintf("/nodes/%s/update?version=%d", node.ID, node.Version.Index) - status, out, err := d.SockRequest("POST", url, node.Spec) - if i < 10 && strings.Contains(string(out), "update out of sequence") { - time.Sleep(100 * time.Millisecond) - continue - } - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - return - } -} - -func (d *SwarmDaemon) listNodes(c *check.C) []swarm.Node { - status, out, err := d.SockRequest("GET", "/nodes", nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - - nodes := []swarm.Node{} - c.Assert(json.Unmarshal(out, &nodes), checker.IsNil) - return nodes -} - -func (d *SwarmDaemon) listServices(c *check.C) []swarm.Service { - status, out, err := d.SockRequest("GET", "/services", nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - - services := []swarm.Service{} - c.Assert(json.Unmarshal(out, &services), checker.IsNil) - return services -} - -func (d *SwarmDaemon) createSecret(c *check.C, secretSpec swarm.SecretSpec) string { - status, out, err := d.SockRequest("POST", "/secrets/create", secretSpec) - - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf("output: %q", string(out))) - - var scr types.SecretCreateResponse - c.Assert(json.Unmarshal(out, &scr), checker.IsNil) - return scr.ID -} - -func (d *SwarmDaemon) listSecrets(c *check.C) []swarm.Secret { - status, out, err := d.SockRequest("GET", "/secrets", nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - - secrets := []swarm.Secret{} - c.Assert(json.Unmarshal(out, &secrets), checker.IsNil) - return secrets -} - -func (d *SwarmDaemon) getSecret(c *check.C, id string) *swarm.Secret { - var secret swarm.Secret - status, out, err := d.SockRequest("GET", "/secrets/"+id, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - c.Assert(json.Unmarshal(out, &secret), checker.IsNil) - return &secret -} - -func (d *SwarmDaemon) deleteSecret(c *check.C, id string) { - status, out, err := d.SockRequest("DELETE", "/secrets/"+id, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusNoContent, check.Commentf("output: %q", string(out))) -} - -func (d *SwarmDaemon) getSwarm(c *check.C) swarm.Swarm { - var sw swarm.Swarm - status, out, err := d.SockRequest("GET", "/swarm", nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - c.Assert(json.Unmarshal(out, &sw), checker.IsNil) - return sw -} - -func (d *SwarmDaemon) updateSwarm(c *check.C, f ...specConstructor) { - sw := d.getSwarm(c) - for _, fn := range f { - fn(&sw.Spec) - } - url := fmt.Sprintf("/swarm/update?version=%d", sw.Version.Index) - status, out, err := d.SockRequest("POST", url, sw.Spec) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) -} - -func (d *SwarmDaemon) rotateTokens(c *check.C) { - var sw swarm.Swarm - status, out, err := d.SockRequest("GET", "/swarm", nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - c.Assert(json.Unmarshal(out, &sw), checker.IsNil) - - url := fmt.Sprintf("/swarm/update?version=%d&rotateWorkerToken=true&rotateManagerToken=true", sw.Version.Index) - status, out, err = d.SockRequest("POST", url, sw.Spec) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) -} - -func (d *SwarmDaemon) joinTokens(c *check.C) swarm.JoinTokens { - var sw swarm.Swarm - status, out, err := d.SockRequest("GET", "/swarm", nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - c.Assert(json.Unmarshal(out, &sw), checker.IsNil) - return sw.JoinTokens -} - -func (d *SwarmDaemon) checkLocalNodeState(c *check.C) (interface{}, check.CommentInterface) { - info, err := d.info() - c.Assert(err, checker.IsNil) - return info.LocalNodeState, nil -} - -func (d *SwarmDaemon) checkControlAvailable(c *check.C) (interface{}, check.CommentInterface) { - info, err := d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - return info.ControlAvailable, nil -} - -func (d *SwarmDaemon) checkLeader(c *check.C) (interface{}, check.CommentInterface) { - errList := check.Commentf("could not get node list") - status, out, err := d.SockRequest("GET", "/nodes", nil) - if err != nil { - return err, errList - } - if status != http.StatusOK { - return fmt.Errorf("expected http status OK, got: %d", status), errList - } - - var ls []swarm.Node - if err := json.Unmarshal(out, &ls); err != nil { - return err, errList - } - - for _, node := range ls { - if node.ManagerStatus != nil && node.ManagerStatus.Leader { - return nil, nil - } - } - return fmt.Errorf("no leader"), check.Commentf("could not find leader") -} - -func (d *SwarmDaemon) cmdRetryOutOfSequence(args ...string) (string, error) { - for i := 0; ; i++ { - out, err := d.Cmd(args...) - if err != nil { - if strings.Contains(out, "update out of sequence") { - if i < 10 { - continue - } - } - } - return out, err - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/daemon_swarm_hack.go b/vendor/github.com/docker/docker/integration-cli/daemon_swarm_hack.go deleted file mode 100644 index 0cea901..0000000 --- a/vendor/github.com/docker/docker/integration-cli/daemon_swarm_hack.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import "github.com/go-check/check" - -func (s *DockerSwarmSuite) getDaemon(c *check.C, nodeID string) *SwarmDaemon { - s.daemonsLock.Lock() - defer s.daemonsLock.Unlock() - for _, d := range s.daemons { - if d.NodeID == nodeID { - return d - } - } - c.Fatalf("could not find node with id: %s", nodeID) - return nil -} - -// nodeCmd executes a command on a given node via the normal docker socket -func (s *DockerSwarmSuite) nodeCmd(c *check.C, id string, args ...string) (string, error) { - return s.getDaemon(c, id).Cmd(args...) -} diff --git a/vendor/github.com/docker/docker/integration-cli/daemon_unix.go b/vendor/github.com/docker/docker/integration-cli/daemon_unix.go deleted file mode 100644 index 6ca7daf..0000000 --- a/vendor/github.com/docker/docker/integration-cli/daemon_unix.go +++ /dev/null @@ -1,35 +0,0 @@ -// +build !windows - -package main - -import ( - "os" - "path/filepath" - "syscall" - - "github.com/go-check/check" -) - -func cleanupExecRoot(c *check.C, execRoot string) { - // Cleanup network namespaces in the exec root of this - // daemon because this exec root is specific to this - // daemon instance and has no chance of getting - // cleaned up when a new daemon is instantiated with a - // new exec root. - netnsPath := filepath.Join(execRoot, "netns") - filepath.Walk(netnsPath, func(path string, info os.FileInfo, err error) error { - if err := syscall.Unmount(path, syscall.MNT_FORCE); err != nil { - c.Logf("unmount of %s failed: %v", path, err) - } - os.Remove(path) - return nil - }) -} - -func signalDaemonDump(pid int) { - syscall.Kill(pid, syscall.SIGQUIT) -} - -func signalDaemonReload(pid int) error { - return syscall.Kill(pid, syscall.SIGHUP) -} diff --git a/vendor/github.com/docker/docker/integration-cli/daemon_windows.go b/vendor/github.com/docker/docker/integration-cli/daemon_windows.go deleted file mode 100644 index 885b703..0000000 --- a/vendor/github.com/docker/docker/integration-cli/daemon_windows.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "fmt" - "strconv" - "syscall" - "unsafe" - - "github.com/go-check/check" - "golang.org/x/sys/windows" -) - -func openEvent(desiredAccess uint32, inheritHandle bool, name string, proc *windows.LazyProc) (handle syscall.Handle, err error) { - namep, _ := syscall.UTF16PtrFromString(name) - var _p2 uint32 - if inheritHandle { - _p2 = 1 - } - r0, _, e1 := proc.Call(uintptr(desiredAccess), uintptr(_p2), uintptr(unsafe.Pointer(namep))) - handle = syscall.Handle(r0) - if handle == syscall.InvalidHandle { - err = e1 - } - return -} - -func pulseEvent(handle syscall.Handle, proc *windows.LazyProc) (err error) { - r0, _, _ := proc.Call(uintptr(handle)) - if r0 != 0 { - err = syscall.Errno(r0) - } - return -} - -func signalDaemonDump(pid int) { - modkernel32 := windows.NewLazySystemDLL("kernel32.dll") - procOpenEvent := modkernel32.NewProc("OpenEventW") - procPulseEvent := modkernel32.NewProc("PulseEvent") - - ev := "Global\\docker-daemon-" + strconv.Itoa(pid) - h2, _ := openEvent(0x0002, false, ev, procOpenEvent) - if h2 == 0 { - return - } - pulseEvent(h2, procPulseEvent) -} - -func signalDaemonReload(pid int) error { - return fmt.Errorf("daemon reload not supported") -} - -func cleanupExecRoot(c *check.C, execRoot string) { -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_attach_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_attach_test.go deleted file mode 100644 index d43bf3a..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_attach_test.go +++ /dev/null @@ -1,210 +0,0 @@ -package main - -import ( - "bufio" - "bytes" - "context" - "io" - "net" - "net/http" - "strings" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/client" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/stdcopy" - "github.com/go-check/check" - "golang.org/x/net/websocket" -) - -func (s *DockerSuite) TestGetContainersAttachWebsocket(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-dit", "busybox", "cat") - - rwc, err := sockConn(time.Duration(10*time.Second), "") - c.Assert(err, checker.IsNil) - - cleanedContainerID := strings.TrimSpace(out) - config, err := websocket.NewConfig( - "/containers/"+cleanedContainerID+"/attach/ws?stream=1&stdin=1&stdout=1&stderr=1", - "http://localhost", - ) - c.Assert(err, checker.IsNil) - - ws, err := websocket.NewClient(config, rwc) - c.Assert(err, checker.IsNil) - defer ws.Close() - - expected := []byte("hello") - actual := make([]byte, len(expected)) - - outChan := make(chan error) - go func() { - _, err := io.ReadFull(ws, actual) - outChan <- err - close(outChan) - }() - - inChan := make(chan error) - go func() { - _, err := ws.Write(expected) - inChan <- err - close(inChan) - }() - - select { - case err := <-inChan: - c.Assert(err, checker.IsNil) - case <-time.After(5 * time.Second): - c.Fatal("Timeout writing to ws") - } - - select { - case err := <-outChan: - c.Assert(err, checker.IsNil) - case <-time.After(5 * time.Second): - c.Fatal("Timeout reading from ws") - } - - c.Assert(actual, checker.DeepEquals, expected, check.Commentf("Websocket didn't return the expected data")) -} - -// regression gh14320 -func (s *DockerSuite) TestPostContainersAttachContainerNotFound(c *check.C) { - req, client, err := newRequestClient("POST", "/containers/doesnotexist/attach", nil, "", "") - c.Assert(err, checker.IsNil) - - resp, err := client.Do(req) - // connection will shutdown, err should be "persistent connection closed" - c.Assert(err, checker.NotNil) // Server shutdown connection - - body, err := readBody(resp.Body) - c.Assert(err, checker.IsNil) - c.Assert(resp.StatusCode, checker.Equals, http.StatusNotFound) - expected := "No such container: doesnotexist\r\n" - c.Assert(string(body), checker.Equals, expected) -} - -func (s *DockerSuite) TestGetContainersWsAttachContainerNotFound(c *check.C) { - status, body, err := sockRequest("GET", "/containers/doesnotexist/attach/ws", nil) - c.Assert(status, checker.Equals, http.StatusNotFound) - c.Assert(err, checker.IsNil) - expected := "No such container: doesnotexist" - c.Assert(getErrorMessage(c, body), checker.Contains, expected) -} - -func (s *DockerSuite) TestPostContainersAttach(c *check.C) { - testRequires(c, DaemonIsLinux) - - expectSuccess := func(conn net.Conn, br *bufio.Reader, stream string, tty bool) { - defer conn.Close() - expected := []byte("success") - _, err := conn.Write(expected) - c.Assert(err, checker.IsNil) - - conn.SetReadDeadline(time.Now().Add(time.Second)) - lenHeader := 0 - if !tty { - lenHeader = 8 - } - actual := make([]byte, len(expected)+lenHeader) - _, err = io.ReadFull(br, actual) - c.Assert(err, checker.IsNil) - if !tty { - fdMap := map[string]byte{ - "stdin": 0, - "stdout": 1, - "stderr": 2, - } - c.Assert(actual[0], checker.Equals, fdMap[stream]) - } - c.Assert(actual[lenHeader:], checker.DeepEquals, expected, check.Commentf("Attach didn't return the expected data from %s", stream)) - } - - expectTimeout := func(conn net.Conn, br *bufio.Reader, stream string) { - defer conn.Close() - _, err := conn.Write([]byte{'t'}) - c.Assert(err, checker.IsNil) - - conn.SetReadDeadline(time.Now().Add(time.Second)) - actual := make([]byte, 1) - _, err = io.ReadFull(br, actual) - opErr, ok := err.(*net.OpError) - c.Assert(ok, checker.Equals, true, check.Commentf("Error is expected to be *net.OpError, got %v", err)) - c.Assert(opErr.Timeout(), checker.Equals, true, check.Commentf("Read from %s is expected to timeout", stream)) - } - - // Create a container that only emits stdout. - cid, _ := dockerCmd(c, "run", "-di", "busybox", "cat") - cid = strings.TrimSpace(cid) - // Attach to the container's stdout stream. - conn, br, err := sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain") - c.Assert(err, checker.IsNil) - // Check if the data from stdout can be received. - expectSuccess(conn, br, "stdout", false) - // Attach to the container's stderr stream. - conn, br, err = sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain") - c.Assert(err, checker.IsNil) - // Since the container only emits stdout, attaching to stderr should return nothing. - expectTimeout(conn, br, "stdout") - - // Test the similar functions of the stderr stream. - cid, _ = dockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "cat >&2") - cid = strings.TrimSpace(cid) - conn, br, err = sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain") - c.Assert(err, checker.IsNil) - expectSuccess(conn, br, "stderr", false) - conn, br, err = sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain") - c.Assert(err, checker.IsNil) - expectTimeout(conn, br, "stderr") - - // Test with tty. - cid, _ = dockerCmd(c, "run", "-dit", "busybox", "/bin/sh", "-c", "cat >&2") - cid = strings.TrimSpace(cid) - // Attach to stdout only. - conn, br, err = sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain") - c.Assert(err, checker.IsNil) - expectSuccess(conn, br, "stdout", true) - - // Attach without stdout stream. - conn, br, err = sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain") - c.Assert(err, checker.IsNil) - // Nothing should be received because both the stdout and stderr of the container will be - // sent to the client as stdout when tty is enabled. - expectTimeout(conn, br, "stdout") - - // Test the client API - // Make sure we don't see "hello" if Logs is false - client, err := client.NewEnvClient() - c.Assert(err, checker.IsNil) - - cid, _ = dockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "echo hello; cat") - cid = strings.TrimSpace(cid) - - attachOpts := types.ContainerAttachOptions{ - Stream: true, - Stdin: true, - Stdout: true, - } - - resp, err := client.ContainerAttach(context.Background(), cid, attachOpts) - c.Assert(err, checker.IsNil) - expectSuccess(resp.Conn, resp.Reader, "stdout", false) - - // Make sure we do see "hello" if Logs is true - attachOpts.Logs = true - resp, err = client.ContainerAttach(context.Background(), cid, attachOpts) - c.Assert(err, checker.IsNil) - - defer resp.Conn.Close() - resp.Conn.SetReadDeadline(time.Now().Add(time.Second)) - - _, err = resp.Conn.Write([]byte("success")) - c.Assert(err, checker.IsNil) - - actualStdout := new(bytes.Buffer) - actualStderr := new(bytes.Buffer) - stdcopy.StdCopy(actualStdout, actualStderr, resp.Reader) - c.Assert(actualStdout.Bytes(), checker.DeepEquals, []byte("hello\nsuccess"), check.Commentf("Attach didn't return the expected data from stdout")) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_auth_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_auth_test.go deleted file mode 100644 index bfcae31..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_auth_test.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "net/http" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// Test case for #22244 -func (s *DockerSuite) TestAuthAPI(c *check.C) { - testRequires(c, Network) - config := types.AuthConfig{ - Username: "no-user", - Password: "no-password", - } - - expected := "Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password" - status, body, err := sockRequest("POST", "/auth", config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusUnauthorized) - msg := getErrorMessage(c, body) - c.Assert(msg, checker.Contains, expected, check.Commentf("Expected: %v, got: %v", expected, msg)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_build_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_build_test.go deleted file mode 100644 index 9b069a4..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_build_test.go +++ /dev/null @@ -1,254 +0,0 @@ -package main - -import ( - "archive/tar" - "bytes" - "net/http" - "regexp" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestBuildAPIDockerFileRemote(c *check.C) { - testRequires(c, NotUserNamespace) - var testD string - if daemonPlatform == "windows" { - testD = `FROM busybox -COPY * /tmp/ -RUN find / -name ba* -RUN find /tmp/` - } else { - // -xdev is required because sysfs can cause EPERM - testD = `FROM busybox -COPY * /tmp/ -RUN find / -xdev -name ba* -RUN find /tmp/` - } - server, err := fakeStorage(map[string]string{"testD": testD}) - c.Assert(err, checker.IsNil) - defer server.Close() - - res, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - - buf, err := readBody(body) - c.Assert(err, checker.IsNil) - - // Make sure Dockerfile exists. - // Make sure 'baz' doesn't exist ANYWHERE despite being mentioned in the URL - out := string(buf) - c.Assert(out, checker.Contains, "/tmp/Dockerfile") - c.Assert(out, checker.Not(checker.Contains), "baz") -} - -func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) { - buffer := new(bytes.Buffer) - tw := tar.NewWriter(buffer) - defer tw.Close() - - dockerfile := []byte("FROM busybox") - err := tw.WriteHeader(&tar.Header{ - Name: "Dockerfile", - Size: int64(len(dockerfile)), - }) - // failed to write tar file header - c.Assert(err, checker.IsNil) - - _, err = tw.Write(dockerfile) - // failed to write tar file content - c.Assert(err, checker.IsNil) - - // failed to close tar archive - c.Assert(tw.Close(), checker.IsNil) - - server, err := fakeBinaryStorage(map[string]*bytes.Buffer{ - "testT.tar": buffer, - }) - c.Assert(err, checker.IsNil) - - defer server.Close() - - res, b, err := sockRequestRaw("POST", "/build?remote="+server.URL()+"/testT.tar", nil, "application/tar") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - b.Close() -} - -func (s *DockerSuite) TestBuildAPIRemoteTarballContextWithCustomDockerfile(c *check.C) { - buffer := new(bytes.Buffer) - tw := tar.NewWriter(buffer) - defer tw.Close() - - dockerfile := []byte(`FROM busybox -RUN echo 'wrong'`) - err := tw.WriteHeader(&tar.Header{ - Name: "Dockerfile", - Size: int64(len(dockerfile)), - }) - // failed to write tar file header - c.Assert(err, checker.IsNil) - - _, err = tw.Write(dockerfile) - // failed to write tar file content - c.Assert(err, checker.IsNil) - - custom := []byte(`FROM busybox -RUN echo 'right' -`) - err = tw.WriteHeader(&tar.Header{ - Name: "custom", - Size: int64(len(custom)), - }) - - // failed to write tar file header - c.Assert(err, checker.IsNil) - - _, err = tw.Write(custom) - // failed to write tar file content - c.Assert(err, checker.IsNil) - - // failed to close tar archive - c.Assert(tw.Close(), checker.IsNil) - - server, err := fakeBinaryStorage(map[string]*bytes.Buffer{ - "testT.tar": buffer, - }) - c.Assert(err, checker.IsNil) - - defer server.Close() - url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar" - res, body, err := sockRequestRaw("POST", url, nil, "application/tar") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - - defer body.Close() - content, err := readBody(body) - c.Assert(err, checker.IsNil) - - // Build used the wrong dockerfile. - c.Assert(string(content), checker.Not(checker.Contains), "wrong") -} - -func (s *DockerSuite) TestBuildAPILowerDockerfile(c *check.C) { - git, err := newFakeGit("repo", map[string]string{ - "dockerfile": `FROM busybox -RUN echo from dockerfile`, - }, false) - c.Assert(err, checker.IsNil) - defer git.Close() - - res, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - - buf, err := readBody(body) - c.Assert(err, checker.IsNil) - - out := string(buf) - c.Assert(out, checker.Contains, "from dockerfile") -} - -func (s *DockerSuite) TestBuildAPIBuildGitWithF(c *check.C) { - git, err := newFakeGit("repo", map[string]string{ - "baz": `FROM busybox -RUN echo from baz`, - "Dockerfile": `FROM busybox -RUN echo from Dockerfile`, - }, false) - c.Assert(err, checker.IsNil) - defer git.Close() - - // Make sure it tries to 'dockerfile' query param value - res, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - - buf, err := readBody(body) - c.Assert(err, checker.IsNil) - - out := string(buf) - c.Assert(out, checker.Contains, "from baz") -} - -func (s *DockerSuite) TestBuildAPIDoubleDockerfile(c *check.C) { - testRequires(c, UnixCli) // dockerfile overwrites Dockerfile on Windows - git, err := newFakeGit("repo", map[string]string{ - "Dockerfile": `FROM busybox -RUN echo from Dockerfile`, - "dockerfile": `FROM busybox -RUN echo from dockerfile`, - }, false) - c.Assert(err, checker.IsNil) - defer git.Close() - - // Make sure it tries to 'dockerfile' query param value - res, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - - buf, err := readBody(body) - c.Assert(err, checker.IsNil) - - out := string(buf) - c.Assert(out, checker.Contains, "from Dockerfile") -} - -func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) { - // Make sure that build context tars with entries of the form - // x/./y don't cause caching false positives. - - buildFromTarContext := func(fileContents []byte) string { - buffer := new(bytes.Buffer) - tw := tar.NewWriter(buffer) - defer tw.Close() - - dockerfile := []byte(`FROM busybox - COPY dir /dir/`) - err := tw.WriteHeader(&tar.Header{ - Name: "Dockerfile", - Size: int64(len(dockerfile)), - }) - //failed to write tar file header - c.Assert(err, checker.IsNil) - - _, err = tw.Write(dockerfile) - // failed to write Dockerfile in tar file content - c.Assert(err, checker.IsNil) - - err = tw.WriteHeader(&tar.Header{ - Name: "dir/./file", - Size: int64(len(fileContents)), - }) - //failed to write tar file header - c.Assert(err, checker.IsNil) - - _, err = tw.Write(fileContents) - // failed to write file contents in tar file content - c.Assert(err, checker.IsNil) - - // failed to close tar archive - c.Assert(tw.Close(), checker.IsNil) - - res, body, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - - out, err := readBody(body) - c.Assert(err, checker.IsNil) - lines := strings.Split(string(out), "\n") - c.Assert(len(lines), checker.GreaterThan, 1) - c.Assert(lines[len(lines)-2], checker.Matches, ".*Successfully built [0-9a-f]{12}.*") - - re := regexp.MustCompile("Successfully built ([0-9a-f]{12})") - matches := re.FindStringSubmatch(lines[len(lines)-2]) - return matches[1] - } - - imageA := buildFromTarContext([]byte("abc")) - imageB := buildFromTarContext([]byte("def")) - - c.Assert(imageA, checker.Not(checker.Equals), imageB) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_containers_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_containers_test.go deleted file mode 100644 index d046ec0..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_containers_test.go +++ /dev/null @@ -1,1961 +0,0 @@ -package main - -import ( - "archive/tar" - "bytes" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net/http" - "net/http/httputil" - "net/url" - "os" - "path/filepath" - "regexp" - "strconv" - "strings" - "time" - - "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - mounttypes "github.com/docker/docker/api/types/mount" - networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/pkg/integration" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/volume" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestContainerAPIGetAll(c *check.C) { - startCount, err := getContainerCount() - c.Assert(err, checker.IsNil, check.Commentf("Cannot query container count")) - - name := "getall" - dockerCmd(c, "run", "--name", name, "busybox", "true") - - status, body, err := sockRequest("GET", "/containers/json?all=1", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var inspectJSON []struct { - Names []string - } - err = json.Unmarshal(body, &inspectJSON) - c.Assert(err, checker.IsNil, check.Commentf("unable to unmarshal response body")) - - c.Assert(inspectJSON, checker.HasLen, startCount+1) - - actual := inspectJSON[0].Names[0] - c.Assert(actual, checker.Equals, "/"+name) -} - -// regression test for empty json field being omitted #13691 -func (s *DockerSuite) TestContainerAPIGetJSONNoFieldsOmitted(c *check.C) { - dockerCmd(c, "run", "busybox", "true") - - status, body, err := sockRequest("GET", "/containers/json?all=1", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - // empty Labels field triggered this bug, make sense to check for everything - // cause even Ports for instance can trigger this bug - // better safe than sorry.. - fields := []string{ - "Id", - "Names", - "Image", - "Command", - "Created", - "Ports", - "Labels", - "Status", - "NetworkSettings", - } - - // decoding into types.Container do not work since it eventually unmarshal - // and empty field to an empty go map, so we just check for a string - for _, f := range fields { - if !strings.Contains(string(body), f) { - c.Fatalf("Field %s is missing and it shouldn't", f) - } - } -} - -type containerPs struct { - Names []string - Ports []map[string]interface{} -} - -// regression test for non-empty fields from #13901 -func (s *DockerSuite) TestContainerAPIPsOmitFields(c *check.C) { - // Problematic for Windows porting due to networking not yet being passed back - testRequires(c, DaemonIsLinux) - name := "pstest" - port := 80 - runSleepingContainer(c, "--name", name, "--expose", strconv.Itoa(port)) - - status, body, err := sockRequest("GET", "/containers/json?all=1", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var resp []containerPs - err = json.Unmarshal(body, &resp) - c.Assert(err, checker.IsNil) - - var foundContainer *containerPs - for _, container := range resp { - for _, testName := range container.Names { - if "/"+name == testName { - foundContainer = &container - break - } - } - } - - c.Assert(foundContainer.Ports, checker.HasLen, 1) - c.Assert(foundContainer.Ports[0]["PrivatePort"], checker.Equals, float64(port)) - _, ok := foundContainer.Ports[0]["PublicPort"] - c.Assert(ok, checker.Not(checker.Equals), true) - _, ok = foundContainer.Ports[0]["IP"] - c.Assert(ok, checker.Not(checker.Equals), true) -} - -func (s *DockerSuite) TestContainerAPIGetExport(c *check.C) { - // Not supported on Windows as Windows does not support docker export - testRequires(c, DaemonIsLinux) - name := "exportcontainer" - dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test") - - status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - found := false - for tarReader := tar.NewReader(bytes.NewReader(body)); ; { - h, err := tarReader.Next() - if err != nil && err == io.EOF { - break - } - if h.Name == "test" { - found = true - break - } - } - c.Assert(found, checker.True, check.Commentf("The created test file has not been found in the exported image")) -} - -func (s *DockerSuite) TestContainerAPIGetChanges(c *check.C) { - // Not supported on Windows as Windows does not support docker diff (/containers/name/changes) - testRequires(c, DaemonIsLinux) - name := "changescontainer" - dockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd") - - status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - changes := []struct { - Kind int - Path string - }{} - c.Assert(json.Unmarshal(body, &changes), checker.IsNil, check.Commentf("unable to unmarshal response body")) - - // Check the changelog for removal of /etc/passwd - success := false - for _, elem := range changes { - if elem.Path == "/etc/passwd" && elem.Kind == 2 { - success = true - } - } - c.Assert(success, checker.True, check.Commentf("/etc/passwd has been removed but is not present in the diff")) -} - -func (s *DockerSuite) TestGetContainerStats(c *check.C) { - var ( - name = "statscontainer" - ) - runSleepingContainer(c, "--name", name) - - type b struct { - status int - body []byte - err error - } - bc := make(chan b, 1) - go func() { - status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil) - bc <- b{status, body, err} - }() - - // allow some time to stream the stats from the container - time.Sleep(4 * time.Second) - dockerCmd(c, "rm", "-f", name) - - // collect the results from the stats stream or timeout and fail - // if the stream was not disconnected. - select { - case <-time.After(2 * time.Second): - c.Fatal("stream was not closed after container was removed") - case sr := <-bc: - c.Assert(sr.err, checker.IsNil) - c.Assert(sr.status, checker.Equals, http.StatusOK) - - dec := json.NewDecoder(bytes.NewBuffer(sr.body)) - var s *types.Stats - // decode only one object from the stream - c.Assert(dec.Decode(&s), checker.IsNil) - } -} - -func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) { - out, _ := runSleepingContainer(c) - id := strings.TrimSpace(out) - - buf := &integration.ChannelBuffer{make(chan []byte, 1)} - defer buf.Close() - - _, body, err := sockRequestRaw("GET", "/containers/"+id+"/stats?stream=1", nil, "application/json") - c.Assert(err, checker.IsNil) - defer body.Close() - - chErr := make(chan error, 1) - go func() { - _, err = io.Copy(buf, body) - chErr <- err - }() - - b := make([]byte, 32) - // make sure we've got some stats - _, err = buf.ReadTimeout(b, 2*time.Second) - c.Assert(err, checker.IsNil) - - // Now remove without `-f` and make sure we are still pulling stats - _, _, err = dockerCmdWithError("rm", id) - c.Assert(err, checker.Not(checker.IsNil), check.Commentf("rm should have failed but didn't")) - _, err = buf.ReadTimeout(b, 2*time.Second) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "rm", "-f", id) - c.Assert(<-chErr, checker.IsNil) -} - -// regression test for gh13421 -// previous test was just checking one stat entry so it didn't fail (stats with -// stream false always return one stat) -func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) { - name := "statscontainer" - runSleepingContainer(c, "--name", name) - - type b struct { - status int - body []byte - err error - } - bc := make(chan b, 1) - go func() { - status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil) - bc <- b{status, body, err} - }() - - // allow some time to stream the stats from the container - time.Sleep(4 * time.Second) - dockerCmd(c, "rm", "-f", name) - - // collect the results from the stats stream or timeout and fail - // if the stream was not disconnected. - select { - case <-time.After(2 * time.Second): - c.Fatal("stream was not closed after container was removed") - case sr := <-bc: - c.Assert(sr.err, checker.IsNil) - c.Assert(sr.status, checker.Equals, http.StatusOK) - - s := string(sr.body) - // count occurrences of "read" of types.Stats - if l := strings.Count(s, "read"); l < 2 { - c.Fatalf("Expected more than one stat streamed, got %d", l) - } - } -} - -func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) { - name := "statscontainer" - runSleepingContainer(c, "--name", name) - - type b struct { - status int - body []byte - err error - } - bc := make(chan b, 1) - go func() { - status, body, err := sockRequest("GET", "/containers/"+name+"/stats?stream=0", nil) - bc <- b{status, body, err} - }() - - // allow some time to stream the stats from the container - time.Sleep(4 * time.Second) - dockerCmd(c, "rm", "-f", name) - - // collect the results from the stats stream or timeout and fail - // if the stream was not disconnected. - select { - case <-time.After(2 * time.Second): - c.Fatal("stream was not closed after container was removed") - case sr := <-bc: - c.Assert(sr.err, checker.IsNil) - c.Assert(sr.status, checker.Equals, http.StatusOK) - - s := string(sr.body) - // count occurrences of `"read"` of types.Stats - c.Assert(strings.Count(s, `"read"`), checker.Equals, 1, check.Commentf("Expected only one stat streamed, got %d", strings.Count(s, `"read"`))) - } -} - -func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) { - name := "statscontainer" - dockerCmd(c, "create", "--name", name, "busybox", "ps") - - type stats struct { - status int - err error - } - chResp := make(chan stats) - - // We expect an immediate response, but if it's not immediate, the test would hang, so put it in a goroutine - // below we'll check this on a timeout. - go func() { - resp, body, err := sockRequestRaw("GET", "/containers/"+name+"/stats", nil, "") - body.Close() - chResp <- stats{resp.StatusCode, err} - }() - - select { - case r := <-chResp: - c.Assert(r.err, checker.IsNil) - c.Assert(r.status, checker.Equals, http.StatusOK) - case <-time.After(10 * time.Second): - c.Fatal("timeout waiting for stats response for stopped container") - } -} - -func (s *DockerSuite) TestContainerAPIPause(c *check.C) { - // Problematic on Windows as Windows does not support pause - testRequires(c, DaemonIsLinux) - defer unpauseAllContainers() - out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "30") - ContainerID := strings.TrimSpace(out) - - status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - - pausedContainers, err := getSliceOfPausedContainers() - c.Assert(err, checker.IsNil, check.Commentf("error thrown while checking if containers were paused")) - - if len(pausedContainers) != 1 || stringid.TruncateID(ContainerID) != pausedContainers[0] { - c.Fatalf("there should be one paused container and not %d", len(pausedContainers)) - } - - status, _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - - pausedContainers, err = getSliceOfPausedContainers() - c.Assert(err, checker.IsNil, check.Commentf("error thrown while checking if containers were paused")) - c.Assert(pausedContainers, checker.IsNil, check.Commentf("There should be no paused container.")) -} - -func (s *DockerSuite) TestContainerAPITop(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top") - id := strings.TrimSpace(string(out)) - c.Assert(waitRun(id), checker.IsNil) - - type topResp struct { - Titles []string - Processes [][]string - } - var top topResp - status, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(json.Unmarshal(b, &top), checker.IsNil) - c.Assert(top.Titles, checker.HasLen, 11, check.Commentf("expected 11 titles, found %d: %v", len(top.Titles), top.Titles)) - - if top.Titles[0] != "USER" || top.Titles[10] != "COMMAND" { - c.Fatalf("expected `USER` at `Titles[0]` and `COMMAND` at Titles[10]: %v", top.Titles) - } - c.Assert(top.Processes, checker.HasLen, 2, check.Commentf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes)) - c.Assert(top.Processes[0][10], checker.Equals, "/bin/sh -c top") - c.Assert(top.Processes[1][10], checker.Equals, "top") -} - -func (s *DockerSuite) TestContainerAPITopWindows(c *check.C) { - testRequires(c, DaemonIsWindows) - out, _ := runSleepingContainer(c, "-d") - id := strings.TrimSpace(string(out)) - c.Assert(waitRun(id), checker.IsNil) - - type topResp struct { - Titles []string - Processes [][]string - } - var top topResp - status, b, err := sockRequest("GET", "/containers/"+id+"/top", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(json.Unmarshal(b, &top), checker.IsNil) - c.Assert(top.Titles, checker.HasLen, 4, check.Commentf("expected 4 titles, found %d: %v", len(top.Titles), top.Titles)) - - if top.Titles[0] != "Name" || top.Titles[3] != "Private Working Set" { - c.Fatalf("expected `Name` at `Titles[0]` and `Private Working Set` at Titles[3]: %v", top.Titles) - } - c.Assert(len(top.Processes), checker.GreaterOrEqualThan, 2, check.Commentf("expected at least 2 processes, found %d: %v", len(top.Processes), top.Processes)) - - foundProcess := false - expectedProcess := "busybox.exe" - for _, process := range top.Processes { - if process[0] == expectedProcess { - foundProcess = true - break - } - } - - c.Assert(foundProcess, checker.Equals, true, check.Commentf("expected to find %s: %v", expectedProcess, top.Processes)) -} - -func (s *DockerSuite) TestContainerAPICommit(c *check.C) { - cName := "testapicommit" - dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test") - - name := "testcontainerapicommit" - status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+cName, nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - type resp struct { - ID string - } - var img resp - c.Assert(json.Unmarshal(b, &img), checker.IsNil) - - cmd := inspectField(c, img.ID, "Config.Cmd") - c.Assert(cmd, checker.Equals, "[/bin/sh -c touch /test]", check.Commentf("got wrong Cmd from commit: %q", cmd)) - - // sanity check, make sure the image is what we think it is - dockerCmd(c, "run", img.ID, "ls", "/test") -} - -func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *check.C) { - cName := "testapicommitwithconfig" - dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test") - - config := map[string]interface{}{ - "Labels": map[string]string{"key1": "value1", "key2": "value2"}, - } - - name := "testcontainerapicommitwithconfig" - status, b, err := sockRequest("POST", "/commit?repo="+name+"&container="+cName, config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - type resp struct { - ID string - } - var img resp - c.Assert(json.Unmarshal(b, &img), checker.IsNil) - - label1 := inspectFieldMap(c, img.ID, "Config.Labels", "key1") - c.Assert(label1, checker.Equals, "value1") - - label2 := inspectFieldMap(c, img.ID, "Config.Labels", "key2") - c.Assert(label2, checker.Equals, "value2") - - cmd := inspectField(c, img.ID, "Config.Cmd") - c.Assert(cmd, checker.Equals, "[/bin/sh -c touch /test]", check.Commentf("got wrong Cmd from commit: %q", cmd)) - - // sanity check, make sure the image is what we think it is - dockerCmd(c, "run", img.ID, "ls", "/test") -} - -func (s *DockerSuite) TestContainerAPIBadPort(c *check.C) { - // TODO Windows to Windows CI - Port this test - testRequires(c, DaemonIsLinux) - config := map[string]interface{}{ - "Image": "busybox", - "Cmd": []string{"/bin/sh", "-c", "echo test"}, - "PortBindings": map[string]interface{}{ - "8080/tcp": []map[string]interface{}{ - { - "HostIP": "", - "HostPort": "aa80", - }, - }, - }, - } - - jsonData := bytes.NewBuffer(nil) - json.NewEncoder(jsonData).Encode(config) - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) - c.Assert(getErrorMessage(c, body), checker.Equals, `invalid port specification: "aa80"`, check.Commentf("Incorrect error msg: %s", body)) -} - -func (s *DockerSuite) TestContainerAPICreate(c *check.C) { - config := map[string]interface{}{ - "Image": "busybox", - "Cmd": []string{"/bin/sh", "-c", "touch /test && ls /test"}, - } - - status, b, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - type createResp struct { - ID string - } - var container createResp - c.Assert(json.Unmarshal(b, &container), checker.IsNil) - - out, _ := dockerCmd(c, "start", "-a", container.ID) - c.Assert(strings.TrimSpace(out), checker.Equals, "/test") -} - -func (s *DockerSuite) TestContainerAPICreateEmptyConfig(c *check.C) { - config := map[string]interface{}{} - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) - - expected := "Config cannot be empty in order to create a container" - c.Assert(getErrorMessage(c, body), checker.Equals, expected) -} - -func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *check.C) { - // Container creation must fail if client specified configurations for more than one network - config := map[string]interface{}{ - "Image": "busybox", - "NetworkingConfig": networktypes.NetworkingConfig{ - EndpointsConfig: map[string]*networktypes.EndpointSettings{ - "net1": {}, - "net2": {}, - "net3": {}, - }, - }, - } - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusBadRequest) - msg := getErrorMessage(c, body) - // network name order in error message is not deterministic - c.Assert(msg, checker.Contains, "Container cannot be connected to network endpoints") - c.Assert(msg, checker.Contains, "net1") - c.Assert(msg, checker.Contains, "net2") - c.Assert(msg, checker.Contains, "net3") -} - -func (s *DockerSuite) TestContainerAPICreateWithHostName(c *check.C) { - hostName := "test-host" - config := map[string]interface{}{ - "Image": "busybox", - "Hostname": hostName, - } - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - var container containertypes.ContainerCreateCreatedBody - c.Assert(json.Unmarshal(body, &container), checker.IsNil) - - status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var containerJSON types.ContainerJSON - c.Assert(json.Unmarshal(body, &containerJSON), checker.IsNil) - c.Assert(containerJSON.Config.Hostname, checker.Equals, hostName, check.Commentf("Mismatched Hostname")) -} - -func (s *DockerSuite) TestContainerAPICreateWithDomainName(c *check.C) { - domainName := "test-domain" - config := map[string]interface{}{ - "Image": "busybox", - "Domainname": domainName, - } - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - var container containertypes.ContainerCreateCreatedBody - c.Assert(json.Unmarshal(body, &container), checker.IsNil) - - status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var containerJSON types.ContainerJSON - c.Assert(json.Unmarshal(body, &containerJSON), checker.IsNil) - c.Assert(containerJSON.Config.Domainname, checker.Equals, domainName, check.Commentf("Mismatched Domainname")) -} - -func (s *DockerSuite) TestContainerAPICreateBridgeNetworkMode(c *check.C) { - // Windows does not support bridge - testRequires(c, DaemonIsLinux) - UtilCreateNetworkMode(c, "bridge") -} - -func (s *DockerSuite) TestContainerAPICreateOtherNetworkModes(c *check.C) { - // Windows does not support these network modes - testRequires(c, DaemonIsLinux, NotUserNamespace) - UtilCreateNetworkMode(c, "host") - UtilCreateNetworkMode(c, "container:web1") -} - -func UtilCreateNetworkMode(c *check.C, networkMode string) { - config := map[string]interface{}{ - "Image": "busybox", - "HostConfig": map[string]interface{}{"NetworkMode": networkMode}, - } - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - var container containertypes.ContainerCreateCreatedBody - c.Assert(json.Unmarshal(body, &container), checker.IsNil) - - status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var containerJSON types.ContainerJSON - c.Assert(json.Unmarshal(body, &containerJSON), checker.IsNil) - c.Assert(containerJSON.HostConfig.NetworkMode, checker.Equals, containertypes.NetworkMode(networkMode), check.Commentf("Mismatched NetworkMode")) -} - -func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) { - // TODO Windows to Windows CI. The CpuShares part could be ported. - testRequires(c, DaemonIsLinux) - config := map[string]interface{}{ - "Image": "busybox", - "CpuShares": 512, - "CpusetCpus": "0", - } - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - var container containertypes.ContainerCreateCreatedBody - c.Assert(json.Unmarshal(body, &container), checker.IsNil) - - status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var containerJSON types.ContainerJSON - - c.Assert(json.Unmarshal(body, &containerJSON), checker.IsNil) - - out := inspectField(c, containerJSON.ID, "HostConfig.CpuShares") - c.Assert(out, checker.Equals, "512") - - outCpuset := inspectField(c, containerJSON.ID, "HostConfig.CpusetCpus") - c.Assert(outCpuset, checker.Equals, "0") -} - -func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) { - config := map[string]interface{}{ - "Image": "busybox", - } - - create := func(ct string) (*http.Response, io.ReadCloser, error) { - jsonData := bytes.NewBuffer(nil) - c.Assert(json.NewEncoder(jsonData).Encode(config), checker.IsNil) - return sockRequestRaw("POST", "/containers/create", jsonData, ct) - } - - // Try with no content-type - res, body, err := create("") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) - body.Close() - - // Try with wrong content-type - res, body, err = create("application/xml") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) - body.Close() - - // now application/json - res, body, err = create("application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusCreated) - body.Close() -} - -//Issue 14230. daemon should return 500 for invalid port syntax -func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *check.C) { - config := `{ - "Image": "busybox", - "HostConfig": { - "NetworkMode": "default", - "PortBindings": { - "19039;1230": [ - {} - ] - } - } - }` - - res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) - - b, err := readBody(body) - c.Assert(err, checker.IsNil) - c.Assert(string(b[:]), checker.Contains, "invalid port") -} - -func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C) { - config := `{ - "Image": "busybox", - "HostConfig": { - "RestartPolicy": { - "Name": "something", - "MaximumRetryCount": 0 - } - } - }` - - res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) - - b, err := readBody(body) - c.Assert(err, checker.IsNil) - c.Assert(string(b[:]), checker.Contains, "invalid restart policy") -} - -func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) { - config := `{ - "Image": "busybox", - "HostConfig": { - "RestartPolicy": { - "Name": "always", - "MaximumRetryCount": 2 - } - } - }` - - res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) - - b, err := readBody(body) - c.Assert(err, checker.IsNil) - c.Assert(string(b[:]), checker.Contains, "maximum retry count cannot be used with restart policy") -} - -func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *check.C) { - config := `{ - "Image": "busybox", - "HostConfig": { - "RestartPolicy": { - "Name": "on-failure", - "MaximumRetryCount": -2 - } - } - }` - - res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) - - b, err := readBody(body) - c.Assert(err, checker.IsNil) - c.Assert(string(b[:]), checker.Contains, "maximum retry count cannot be negative") -} - -func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *check.C) { - config := `{ - "Image": "busybox", - "HostConfig": { - "RestartPolicy": { - "Name": "on-failure", - "MaximumRetryCount": 0 - } - } - }` - - res, _, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusCreated) -} - -// Issue 7941 - test to make sure a "null" in JSON is just ignored. -// W/o this fix a null in JSON would be parsed into a string var as "null" -func (s *DockerSuite) TestContainerAPIPostCreateNull(c *check.C) { - config := `{ - "Hostname":"", - "Domainname":"", - "Memory":0, - "MemorySwap":0, - "CpuShares":0, - "Cpuset":null, - "AttachStdin":true, - "AttachStdout":true, - "AttachStderr":true, - "ExposedPorts":{}, - "Tty":true, - "OpenStdin":true, - "StdinOnce":true, - "Env":[], - "Cmd":"ls", - "Image":"busybox", - "Volumes":{}, - "WorkingDir":"", - "Entrypoint":null, - "NetworkDisabled":false, - "OnBuild":null}` - - res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusCreated) - - b, err := readBody(body) - c.Assert(err, checker.IsNil) - type createResp struct { - ID string - } - var container createResp - c.Assert(json.Unmarshal(b, &container), checker.IsNil) - out := inspectField(c, container.ID, "HostConfig.CpusetCpus") - c.Assert(out, checker.Equals, "") - - outMemory := inspectField(c, container.ID, "HostConfig.Memory") - c.Assert(outMemory, checker.Equals, "0") - outMemorySwap := inspectField(c, container.ID, "HostConfig.MemorySwap") - c.Assert(outMemorySwap, checker.Equals, "0") -} - -func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) { - // TODO Windows: Port once memory is supported - testRequires(c, DaemonIsLinux) - config := `{ - "Image": "busybox", - "Cmd": "ls", - "OpenStdin": true, - "CpuShares": 100, - "Memory": 524287 - }` - - res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - b, err2 := readBody(body) - c.Assert(err2, checker.IsNil) - - c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) - c.Assert(string(b), checker.Contains, "Minimum memory limit allowed is 4MB") -} - -func (s *DockerSuite) TestContainerAPIRename(c *check.C) { - out, _ := dockerCmd(c, "run", "--name", "TestContainerAPIRename", "-d", "busybox", "sh") - - containerID := strings.TrimSpace(out) - newName := "TestContainerAPIRenameNew" - statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/rename?name="+newName, nil) - c.Assert(err, checker.IsNil) - // 204 No Content is expected, not 200 - c.Assert(statusCode, checker.Equals, http.StatusNoContent) - - name := inspectField(c, containerID, "Name") - c.Assert(name, checker.Equals, "/"+newName, check.Commentf("Failed to rename container")) -} - -func (s *DockerSuite) TestContainerAPIKill(c *check.C) { - name := "test-api-kill" - runSleepingContainer(c, "-i", "--name", name) - - status, _, err := sockRequest("POST", "/containers/"+name+"/kill", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - - state := inspectField(c, name, "State.Running") - c.Assert(state, checker.Equals, "false", check.Commentf("got wrong State from container %s: %q", name, state)) -} - -func (s *DockerSuite) TestContainerAPIRestart(c *check.C) { - name := "test-api-restart" - runSleepingContainer(c, "-di", "--name", name) - - status, _, err := sockRequest("POST", "/containers/"+name+"/restart?t=1", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - c.Assert(waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second), checker.IsNil) -} - -func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *check.C) { - name := "test-api-restart-no-timeout-param" - out, _ := runSleepingContainer(c, "-di", "--name", name) - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - status, _, err := sockRequest("POST", "/containers/"+name+"/restart", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - c.Assert(waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second), checker.IsNil) -} - -func (s *DockerSuite) TestContainerAPIStart(c *check.C) { - name := "testing-start" - config := map[string]interface{}{ - "Image": "busybox", - "Cmd": append([]string{"/bin/sh", "-c"}, sleepCommandForDaemonPlatform()...), - "OpenStdin": true, - } - - status, _, err := sockRequest("POST", "/containers/create?name="+name, config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - status, _, err = sockRequest("POST", "/containers/"+name+"/start", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - - // second call to start should give 304 - status, _, err = sockRequest("POST", "/containers/"+name+"/start", nil) - c.Assert(err, checker.IsNil) - - // TODO(tibor): figure out why this doesn't work on windows - if isLocalDaemon { - c.Assert(status, checker.Equals, http.StatusNotModified) - } -} - -func (s *DockerSuite) TestContainerAPIStop(c *check.C) { - name := "test-api-stop" - runSleepingContainer(c, "-i", "--name", name) - - status, _, err := sockRequest("POST", "/containers/"+name+"/stop?t=30", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - c.Assert(waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil) - - // second call to start should give 304 - status, _, err = sockRequest("POST", "/containers/"+name+"/stop?t=30", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNotModified) -} - -func (s *DockerSuite) TestContainerAPIWait(c *check.C) { - name := "test-api-wait" - - sleepCmd := "/bin/sleep" - if daemonPlatform == "windows" { - sleepCmd = "sleep" - } - dockerCmd(c, "run", "--name", name, "busybox", sleepCmd, "2") - - status, body, err := sockRequest("POST", "/containers/"+name+"/wait", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil) - - var waitres containertypes.ContainerWaitOKBody - c.Assert(json.Unmarshal(body, &waitres), checker.IsNil) - c.Assert(waitres.StatusCode, checker.Equals, int64(0)) -} - -func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *check.C) { - name := "test-container-api-copy" - dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt") - - postData := types.CopyConfig{ - Resource: "/test.txt", - } - - status, _, err := sockRequest("POST", "/containers/"+name+"/copy", postData) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNotFound) -} - -func (s *DockerSuite) TestContainerAPICopyPre124(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later - name := "test-container-api-copy" - dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt") - - postData := types.CopyConfig{ - Resource: "/test.txt", - } - - status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - found := false - for tarReader := tar.NewReader(bytes.NewReader(body)); ; { - h, err := tarReader.Next() - if err != nil { - if err == io.EOF { - break - } - c.Fatal(err) - } - if h.Name == "test.txt" { - found = true - break - } - } - c.Assert(found, checker.True) -} - -func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPr124(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later - name := "test-container-api-copy-resource-empty" - dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test.txt") - - postData := types.CopyConfig{ - Resource: "", - } - - status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) - c.Assert(string(body), checker.Matches, "Path cannot be empty\n") -} - -func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later - name := "test-container-api-copy-resource-not-found" - dockerCmd(c, "run", "--name", name, "busybox") - - postData := types.CopyConfig{ - Resource: "/notexist", - } - - status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) - c.Assert(string(body), checker.Matches, "Could not find the file /notexist in container "+name+"\n") -} - -func (s *DockerSuite) TestContainerAPICopyContainerNotFoundPr124(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later - postData := types.CopyConfig{ - Resource: "/something", - } - - status, _, err := sockRequest("POST", "/v1.23/containers/notexists/copy", postData) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNotFound) -} - -func (s *DockerSuite) TestContainerAPIDelete(c *check.C) { - out, _ := runSleepingContainer(c) - - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - dockerCmd(c, "stop", id) - - status, _, err := sockRequest("DELETE", "/containers/"+id, nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) -} - -func (s *DockerSuite) TestContainerAPIDeleteNotExist(c *check.C) { - status, body, err := sockRequest("DELETE", "/containers/doesnotexist", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNotFound) - c.Assert(getErrorMessage(c, body), checker.Matches, "No such container: doesnotexist") -} - -func (s *DockerSuite) TestContainerAPIDeleteForce(c *check.C) { - out, _ := runSleepingContainer(c) - - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - status, _, err := sockRequest("DELETE", "/containers/"+id+"?force=1", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) -} - -func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *check.C) { - // Windows does not support links - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "--name", "tlink1", "busybox", "top") - - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - out, _ = dockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top") - - id2 := strings.TrimSpace(out) - c.Assert(waitRun(id2), checker.IsNil) - - links := inspectFieldJSON(c, id2, "HostConfig.Links") - c.Assert(links, checker.Equals, "[\"/tlink1:/tlink2/tlink1\"]", check.Commentf("expected to have links between containers")) - - status, b, err := sockRequest("DELETE", "/containers/tlink2/tlink1?link=1", nil) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusNoContent, check.Commentf(string(b))) - - linksPostRm := inspectFieldJSON(c, id2, "HostConfig.Links") - c.Assert(linksPostRm, checker.Equals, "null", check.Commentf("call to api deleteContainer links should have removed the specified links")) -} - -func (s *DockerSuite) TestContainerAPIDeleteConflict(c *check.C) { - out, _ := runSleepingContainer(c) - - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - status, _, err := sockRequest("DELETE", "/containers/"+id, nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusConflict) -} - -func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) { - testRequires(c, SameHostDaemon) - - vol := "/testvolume" - if daemonPlatform == "windows" { - vol = `c:\testvolume` - } - - out, _ := runSleepingContainer(c, "-v", vol) - - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - source, err := inspectMountSourceField(id, vol) - _, err = os.Stat(source) - c.Assert(err, checker.IsNil) - - status, _, err := sockRequest("DELETE", "/containers/"+id+"?v=1&force=1", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - _, err = os.Stat(source) - c.Assert(os.IsNotExist(err), checker.True, check.Commentf("expected to get ErrNotExist error, got %v", err)) -} - -// Regression test for https://github.com/docker/docker/issues/6231 -func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *check.C) { - conn, err := sockConn(time.Duration(10*time.Second), "") - c.Assert(err, checker.IsNil) - client := httputil.NewClientConn(conn, nil) - defer client.Close() - - config := map[string]interface{}{ - "Image": "busybox", - "Cmd": append([]string{"/bin/sh", "-c"}, sleepCommandForDaemonPlatform()...), - "OpenStdin": true, - } - b, err := json.Marshal(config) - c.Assert(err, checker.IsNil) - - req, err := http.NewRequest("POST", "/containers/create", bytes.NewBuffer(b)) - c.Assert(err, checker.IsNil) - req.Header.Set("Content-Type", "application/json") - // This is a cheat to make the http request do chunked encoding - // Otherwise (just setting the Content-Encoding to chunked) net/http will overwrite - // https://golang.org/src/pkg/net/http/request.go?s=11980:12172 - req.ContentLength = -1 - - resp, err := client.Do(req) - c.Assert(err, checker.IsNil, check.Commentf("error creating container with chunked encoding")) - resp.Body.Close() - c.Assert(resp.StatusCode, checker.Equals, http.StatusCreated) -} - -func (s *DockerSuite) TestContainerAPIPostContainerStop(c *check.C) { - out, _ := runSleepingContainer(c) - - containerID := strings.TrimSpace(out) - c.Assert(waitRun(containerID), checker.IsNil) - - statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/stop", nil) - c.Assert(err, checker.IsNil) - // 204 No Content is expected, not 200 - c.Assert(statusCode, checker.Equals, http.StatusNoContent) - c.Assert(waitInspect(containerID, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil) -} - -// #14170 -func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *check.C) { - config := struct { - Image string - Entrypoint string - Cmd []string - }{"busybox", "echo", []string{"hello", "world"}} - _, _, err := sockRequest("POST", "/containers/create?name=echotest", config) - c.Assert(err, checker.IsNil) - out, _ := dockerCmd(c, "start", "-a", "echotest") - c.Assert(strings.TrimSpace(out), checker.Equals, "hello world") - - config2 := struct { - Image string - Entrypoint []string - Cmd []string - }{"busybox", []string{"echo"}, []string{"hello", "world"}} - _, _, err = sockRequest("POST", "/containers/create?name=echotest2", config2) - c.Assert(err, checker.IsNil) - out, _ = dockerCmd(c, "start", "-a", "echotest2") - c.Assert(strings.TrimSpace(out), checker.Equals, "hello world") -} - -// #14170 -func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *check.C) { - config := struct { - Image string - Entrypoint string - Cmd string - }{"busybox", "echo", "hello world"} - _, _, err := sockRequest("POST", "/containers/create?name=echotest", config) - c.Assert(err, checker.IsNil) - out, _ := dockerCmd(c, "start", "-a", "echotest") - c.Assert(strings.TrimSpace(out), checker.Equals, "hello world") - - config2 := struct { - Image string - Cmd []string - }{"busybox", []string{"echo", "hello", "world"}} - _, _, err = sockRequest("POST", "/containers/create?name=echotest2", config2) - c.Assert(err, checker.IsNil) - out, _ = dockerCmd(c, "start", "-a", "echotest2") - c.Assert(strings.TrimSpace(out), checker.Equals, "hello world") -} - -// regression #14318 -func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *check.C) { - // Windows doesn't support CapAdd/CapDrop - testRequires(c, DaemonIsLinux) - config := struct { - Image string - CapAdd string - CapDrop string - }{"busybox", "NET_ADMIN", "SYS_ADMIN"} - status, _, err := sockRequest("POST", "/containers/create?name=capaddtest0", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - config2 := struct { - Image string - CapAdd []string - CapDrop []string - }{"busybox", []string{"NET_ADMIN", "SYS_ADMIN"}, []string{"SETGID"}} - status, _, err = sockRequest("POST", "/containers/create?name=capaddtest1", config2) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) -} - -// #14915 -func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows only support 1.25 or later - config := struct { - Image string - }{"busybox"} - status, _, err := sockRequest("POST", "/v1.18/containers/create", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) -} - -// Ensure an error occurs when you have a container read-only rootfs but you -// extract an archive to a symlink in a writable volume which points to a -// directory outside of the volume. -func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(c *check.C) { - // Windows does not support read-only rootfs - // Requires local volume mount bind. - // --read-only + userns has remount issues - testRequires(c, SameHostDaemon, NotUserNamespace, DaemonIsLinux) - - testVol := getTestDir(c, "test-put-container-archive-err-symlink-in-volume-to-read-only-rootfs-") - defer os.RemoveAll(testVol) - - makeTestContentInDir(c, testVol) - - cID := makeTestContainer(c, testContainerOptions{ - readOnly: true, - volumes: defaultVolumes(testVol), // Our bind mount is at /vol2 - }) - defer deleteContainer(cID) - - // Attempt to extract to a symlink in the volume which points to a - // directory outside the volume. This should cause an error because the - // rootfs is read-only. - query := make(url.Values, 1) - query.Set("path", "/vol2/symlinkToAbsDir") - urlPath := fmt.Sprintf("/v1.20/containers/%s/archive?%s", cID, query.Encode()) - - statusCode, body, err := sockRequest("PUT", urlPath, nil) - c.Assert(err, checker.IsNil) - - if !isCpCannotCopyReadOnly(fmt.Errorf(string(body))) { - c.Fatalf("expected ErrContainerRootfsReadonly error, but got %d: %s", statusCode, string(body)) - } -} - -func (s *DockerSuite) TestContainerAPIGetContainersJSONEmpty(c *check.C) { - status, body, err := sockRequest("GET", "/containers/json?all=1", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(string(body), checker.Equals, "[]\n") -} - -func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *check.C) { - // Not supported on Windows - testRequires(c, DaemonIsLinux) - - c1 := struct { - Image string - CpusetCpus string - }{"busybox", "1-42,,"} - name := "wrong-cpuset-cpus" - status, body, err := sockRequest("POST", "/containers/create?name="+name, c1) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) - expected := "Invalid value 1-42,, for cpuset cpus" - c.Assert(getErrorMessage(c, body), checker.Equals, expected) - - c2 := struct { - Image string - CpusetMems string - }{"busybox", "42-3,1--"} - name = "wrong-cpuset-mems" - status, body, err = sockRequest("POST", "/containers/create?name="+name, c2) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) - expected = "Invalid value 42-3,1-- for cpuset mems" - c.Assert(getErrorMessage(c, body), checker.Equals, expected) -} - -func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *check.C) { - // ShmSize is not supported on Windows - testRequires(c, DaemonIsLinux) - config := map[string]interface{}{ - "Image": "busybox", - "HostConfig": map[string]interface{}{"ShmSize": -1}, - } - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusInternalServerError) - c.Assert(getErrorMessage(c, body), checker.Contains, "SHM size can not be less than 0") -} - -func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check.C) { - // ShmSize is not supported on Windows - testRequires(c, DaemonIsLinux) - var defaultSHMSize int64 = 67108864 - config := map[string]interface{}{ - "Image": "busybox", - "Cmd": "mount", - } - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusCreated) - - var container containertypes.ContainerCreateCreatedBody - c.Assert(json.Unmarshal(body, &container), check.IsNil) - - status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusOK) - - var containerJSON types.ContainerJSON - c.Assert(json.Unmarshal(body, &containerJSON), check.IsNil) - - c.Assert(containerJSON.HostConfig.ShmSize, check.Equals, defaultSHMSize) - - out, _ := dockerCmd(c, "start", "-i", containerJSON.ID) - shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`) - if !shmRegexp.MatchString(out) { - c.Fatalf("Expected shm of 64MB in mount command, got %v", out) - } -} - -func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) { - // ShmSize is not supported on Windows - testRequires(c, DaemonIsLinux) - config := map[string]interface{}{ - "Image": "busybox", - "HostConfig": map[string]interface{}{}, - "Cmd": "mount", - } - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusCreated) - - var container containertypes.ContainerCreateCreatedBody - c.Assert(json.Unmarshal(body, &container), check.IsNil) - - status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusOK) - - var containerJSON types.ContainerJSON - c.Assert(json.Unmarshal(body, &containerJSON), check.IsNil) - - c.Assert(containerJSON.HostConfig.ShmSize, check.Equals, int64(67108864)) - - out, _ := dockerCmd(c, "start", "-i", containerJSON.ID) - shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`) - if !shmRegexp.MatchString(out) { - c.Fatalf("Expected shm of 64MB in mount command, got %v", out) - } -} - -func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) { - // ShmSize is not supported on Windows - testRequires(c, DaemonIsLinux) - config := map[string]interface{}{ - "Image": "busybox", - "Cmd": "mount", - "HostConfig": map[string]interface{}{"ShmSize": 1073741824}, - } - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusCreated) - - var container containertypes.ContainerCreateCreatedBody - c.Assert(json.Unmarshal(body, &container), check.IsNil) - - status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusOK) - - var containerJSON types.ContainerJSON - c.Assert(json.Unmarshal(body, &containerJSON), check.IsNil) - - c.Assert(containerJSON.HostConfig.ShmSize, check.Equals, int64(1073741824)) - - out, _ := dockerCmd(c, "start", "-i", containerJSON.ID) - shmRegex := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=1048576k`) - if !shmRegex.MatchString(out) { - c.Fatalf("Expected shm of 1GB in mount command, got %v", out) - } -} - -func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(c *check.C) { - // Swappiness is not supported on Windows - testRequires(c, DaemonIsLinux) - config := map[string]interface{}{ - "Image": "busybox", - } - - status, body, err := sockRequest("POST", "/containers/create", config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusCreated) - - var container containertypes.ContainerCreateCreatedBody - c.Assert(json.Unmarshal(body, &container), check.IsNil) - - status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusOK) - - var containerJSON types.ContainerJSON - c.Assert(json.Unmarshal(body, &containerJSON), check.IsNil) - - c.Assert(*containerJSON.HostConfig.MemorySwappiness, check.Equals, int64(-1)) -} - -// check validation is done daemon side and not only in cli -func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *check.C) { - // OomScoreAdj is not supported on Windows - testRequires(c, DaemonIsLinux) - - config := struct { - Image string - OomScoreAdj int - }{"busybox", 1001} - name := "oomscoreadj-over" - status, b, err := sockRequest("POST", "/containers/create?name="+name, config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusInternalServerError) - - expected := "Invalid value 1001, range for oom score adj is [-1000, 1000]" - msg := getErrorMessage(c, b) - if !strings.Contains(msg, expected) { - c.Fatalf("Expected output to contain %q, got %q", expected, msg) - } - - config = struct { - Image string - OomScoreAdj int - }{"busybox", -1001} - name = "oomscoreadj-low" - status, b, err = sockRequest("POST", "/containers/create?name="+name, config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusInternalServerError) - expected = "Invalid value -1001, range for oom score adj is [-1000, 1000]" - msg = getErrorMessage(c, b) - if !strings.Contains(msg, expected) { - c.Fatalf("Expected output to contain %q, got %q", expected, msg) - } -} - -// test case for #22210 where an empty container name caused panic. -func (s *DockerSuite) TestContainerAPIDeleteWithEmptyName(c *check.C) { - status, out, err := sockRequest("DELETE", "/containers/", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusBadRequest) - c.Assert(string(out), checker.Contains, "No container name or ID supplied") -} - -func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *check.C) { - // Problematic on Windows as Windows does not support stats - testRequires(c, DaemonIsLinux) - - name := "testing-network-disabled" - config := map[string]interface{}{ - "Image": "busybox", - "Cmd": []string{"top"}, - "NetworkDisabled": true, - } - - status, _, err := sockRequest("POST", "/containers/create?name="+name, config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - status, _, err = sockRequest("POST", "/containers/"+name+"/start", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - - c.Assert(waitRun(name), check.IsNil) - - type b struct { - status int - body []byte - err error - } - bc := make(chan b, 1) - go func() { - status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil) - bc <- b{status, body, err} - }() - - // allow some time to stream the stats from the container - time.Sleep(4 * time.Second) - dockerCmd(c, "rm", "-f", name) - - // collect the results from the stats stream or timeout and fail - // if the stream was not disconnected. - select { - case <-time.After(2 * time.Second): - c.Fatal("stream was not closed after container was removed") - case sr := <-bc: - c.Assert(sr.err, checker.IsNil) - c.Assert(sr.status, checker.Equals, http.StatusOK) - - // decode only one object from the stream - var s *types.Stats - dec := json.NewDecoder(bytes.NewBuffer(sr.body)) - c.Assert(dec.Decode(&s), checker.IsNil) - } -} - -func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *check.C) { - type m mounttypes.Mount - type hc struct{ Mounts []m } - type cfg struct { - Image string - HostConfig hc - } - type testCase struct { - config cfg - status int - msg string - } - - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - destPath := prefix + slash + "foo" - notExistPath := prefix + slash + "notexist" - - cases := []testCase{ - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "notreal", - Target: destPath}}}}, - status: http.StatusBadRequest, - msg: "mount type unknown", - }, - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "bind"}}}}, - status: http.StatusBadRequest, - msg: "Target must not be empty", - }, - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "bind", - Target: destPath}}}}, - status: http.StatusBadRequest, - msg: "Source must not be empty", - }, - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "bind", - Source: notExistPath, - Target: destPath}}}}, - status: http.StatusBadRequest, - msg: "bind source path does not exist", - }, - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "volume"}}}}, - status: http.StatusBadRequest, - msg: "Target must not be empty", - }, - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "volume", - Source: "hello", - Target: destPath}}}}, - status: http.StatusCreated, - msg: "", - }, - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "volume", - Source: "hello2", - Target: destPath, - VolumeOptions: &mounttypes.VolumeOptions{ - DriverConfig: &mounttypes.Driver{ - Name: "local"}}}}}}, - status: http.StatusCreated, - msg: "", - }, - } - - if SameHostDaemon.Condition() { - tmpDir, err := ioutils.TempDir("", "test-mounts-api") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir) - cases = append(cases, []testCase{ - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "bind", - Source: tmpDir, - Target: destPath}}}}, - status: http.StatusCreated, - msg: "", - }, - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "bind", - Source: tmpDir, - Target: destPath, - VolumeOptions: &mounttypes.VolumeOptions{}}}}}, - status: http.StatusBadRequest, - msg: "VolumeOptions must not be specified", - }, - }...) - } - - if DaemonIsLinux.Condition() { - cases = append(cases, []testCase{ - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "volume", - Source: "hello3", - Target: destPath, - VolumeOptions: &mounttypes.VolumeOptions{ - DriverConfig: &mounttypes.Driver{ - Name: "local", - Options: map[string]string{"o": "size=1"}}}}}}}, - status: http.StatusCreated, - msg: "", - }, - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "tmpfs", - Target: destPath}}}}, - status: http.StatusCreated, - msg: "", - }, - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "tmpfs", - Target: destPath, - TmpfsOptions: &mounttypes.TmpfsOptions{ - SizeBytes: 4096 * 1024, - Mode: 0700, - }}}}}, - status: http.StatusCreated, - msg: "", - }, - - { - config: cfg{ - Image: "busybox", - HostConfig: hc{ - Mounts: []m{{ - Type: "tmpfs", - Source: "/shouldnotbespecified", - Target: destPath}}}}, - status: http.StatusBadRequest, - msg: "Source must not be specified", - }, - }...) - - } - - for i, x := range cases { - c.Logf("case %d", i) - status, b, err := sockRequest("POST", "/containers/create", x.config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, x.status, check.Commentf("%s\n%v", string(b), cases[i].config)) - if len(x.msg) > 0 { - c.Assert(string(b), checker.Contains, x.msg, check.Commentf("%v", cases[i].config)) - } - } -} - -func (s *DockerSuite) TestContainerAPICreateMountsBindRead(c *check.C) { - testRequires(c, NotUserNamespace, SameHostDaemon) - // also with data in the host side - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - destPath := prefix + slash + "foo" - tmpDir, err := ioutil.TempDir("", "test-mounts-api-bind") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir) - err = ioutil.WriteFile(filepath.Join(tmpDir, "bar"), []byte("hello"), 666) - c.Assert(err, checker.IsNil) - - data := map[string]interface{}{ - "Image": "busybox", - "Cmd": []string{"/bin/sh", "-c", "cat /foo/bar"}, - "HostConfig": map[string]interface{}{"Mounts": []map[string]interface{}{{"Type": "bind", "Source": tmpDir, "Target": destPath}}}, - } - status, resp, err := sockRequest("POST", "/containers/create?name=test", data) - c.Assert(err, checker.IsNil, check.Commentf(string(resp))) - c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(resp))) - - out, _ := dockerCmd(c, "start", "-a", "test") - c.Assert(out, checker.Equals, "hello") -} - -// Test Mounts comes out as expected for the MountPoint -func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) { - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - destPath := prefix + slash + "foo" - - var ( - err error - testImg string - ) - if daemonPlatform != "windows" { - testImg, err = buildImage("test-mount-config", ` - FROM busybox - RUN mkdir `+destPath+` && touch `+destPath+slash+`bar - CMD cat `+destPath+slash+`bar - `, true) - } else { - testImg = "busybox" - } - c.Assert(err, checker.IsNil) - - type testCase struct { - cfg mounttypes.Mount - expected types.MountPoint - } - - cases := []testCase{ - // use literal strings here for `Type` instead of the defined constants in the volume package to keep this honest - // Validation of the actual `Mount` struct is done in another test is not needed here - {mounttypes.Mount{Type: "volume", Target: destPath}, types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath}}, - {mounttypes.Mount{Type: "volume", Target: destPath + slash}, types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath}}, - {mounttypes.Mount{Type: "volume", Target: destPath, Source: "test1"}, types.MountPoint{Type: "volume", Name: "test1", RW: true, Destination: destPath}}, - {mounttypes.Mount{Type: "volume", Target: destPath, ReadOnly: true, Source: "test2"}, types.MountPoint{Type: "volume", Name: "test2", RW: false, Destination: destPath}}, - {mounttypes.Mount{Type: "volume", Target: destPath, Source: "test3", VolumeOptions: &mounttypes.VolumeOptions{DriverConfig: &mounttypes.Driver{Name: volume.DefaultDriverName}}}, types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", Name: "test3", RW: true, Destination: destPath}}, - } - - if SameHostDaemon.Condition() { - // setup temp dir for testing binds - tmpDir1, err := ioutil.TempDir("", "test-mounts-api-1") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir1) - cases = append(cases, []testCase{ - {mounttypes.Mount{Type: "bind", Source: tmpDir1, Target: destPath}, types.MountPoint{Type: "bind", RW: true, Destination: destPath, Source: tmpDir1}}, - {mounttypes.Mount{Type: "bind", Source: tmpDir1, Target: destPath, ReadOnly: true}, types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir1}}, - }...) - - // for modes only supported on Linux - if DaemonIsLinux.Condition() { - tmpDir3, err := ioutils.TempDir("", "test-mounts-api-3") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir3) - - c.Assert(mount.Mount(tmpDir3, tmpDir3, "none", "bind,rw"), checker.IsNil) - c.Assert(mount.ForceMount("", tmpDir3, "none", "shared"), checker.IsNil) - - cases = append(cases, []testCase{ - {mounttypes.Mount{Type: "bind", Source: tmpDir3, Target: destPath}, types.MountPoint{Type: "bind", RW: true, Destination: destPath, Source: tmpDir3}}, - {mounttypes.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true}, types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3}}, - {mounttypes.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true, BindOptions: &mounttypes.BindOptions{Propagation: "shared"}}, types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3, Propagation: "shared"}}, - }...) - } - } - - if daemonPlatform != "windows" { // Windows does not support volume populate - cases = append(cases, []testCase{ - {mounttypes.Mount{Type: "volume", Target: destPath, VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}}, types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath}}, - {mounttypes.Mount{Type: "volume", Target: destPath + slash, VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}}, types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath}}, - {mounttypes.Mount{Type: "volume", Target: destPath, Source: "test4", VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}}, types.MountPoint{Type: "volume", Name: "test4", RW: true, Destination: destPath}}, - {mounttypes.Mount{Type: "volume", Target: destPath, Source: "test5", ReadOnly: true, VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}}, types.MountPoint{Type: "volume", Name: "test5", RW: false, Destination: destPath}}, - }...) - } - - type wrapper struct { - containertypes.Config - HostConfig containertypes.HostConfig - } - type createResp struct { - ID string `json:"Id"` - } - for i, x := range cases { - c.Logf("case %d - config: %v", i, x.cfg) - status, data, err := sockRequest("POST", "/containers/create", wrapper{containertypes.Config{Image: testImg}, containertypes.HostConfig{Mounts: []mounttypes.Mount{x.cfg}}}) - c.Assert(err, checker.IsNil, check.Commentf(string(data))) - c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(data))) - - var resp createResp - err = json.Unmarshal(data, &resp) - c.Assert(err, checker.IsNil, check.Commentf(string(data))) - id := resp.ID - - var mps []types.MountPoint - err = json.NewDecoder(strings.NewReader(inspectFieldJSON(c, id, "Mounts"))).Decode(&mps) - c.Assert(err, checker.IsNil) - c.Assert(mps, checker.HasLen, 1) - c.Assert(mps[0].Destination, checker.Equals, x.expected.Destination) - - if len(x.expected.Source) > 0 { - c.Assert(mps[0].Source, checker.Equals, x.expected.Source) - } - if len(x.expected.Name) > 0 { - c.Assert(mps[0].Name, checker.Equals, x.expected.Name) - } - if len(x.expected.Driver) > 0 { - c.Assert(mps[0].Driver, checker.Equals, x.expected.Driver) - } - c.Assert(mps[0].RW, checker.Equals, x.expected.RW) - c.Assert(mps[0].Type, checker.Equals, x.expected.Type) - c.Assert(mps[0].Mode, checker.Equals, x.expected.Mode) - if len(x.expected.Propagation) > 0 { - c.Assert(mps[0].Propagation, checker.Equals, x.expected.Propagation) - } - - out, _, err := dockerCmdWithError("start", "-a", id) - if (x.cfg.Type != "volume" || (x.cfg.VolumeOptions != nil && x.cfg.VolumeOptions.NoCopy)) && daemonPlatform != "windows" { - c.Assert(err, checker.NotNil, check.Commentf("%s\n%v", out, mps[0])) - } else { - c.Assert(err, checker.IsNil, check.Commentf("%s\n%v", out, mps[0])) - } - - dockerCmd(c, "rm", "-fv", id) - if x.cfg.Type == "volume" && len(x.cfg.Source) > 0 { - // This should still exist even though we removed the container - dockerCmd(c, "volume", "inspect", mps[0].Name) - } else { - // This should be removed automatically when we removed the container - out, _, err := dockerCmdWithError("volume", "inspect", mps[0].Name) - c.Assert(err, checker.NotNil, check.Commentf(out)) - } - } -} - -func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *check.C) { - testRequires(c, DaemonIsLinux) - type testCase struct { - cfg map[string]interface{} - expectedOptions []string - } - target := "/foo" - cases := []testCase{ - { - cfg: map[string]interface{}{ - "Type": "tmpfs", - "Target": target}, - expectedOptions: []string{"rw", "nosuid", "nodev", "noexec", "relatime"}, - }, - { - cfg: map[string]interface{}{ - "Type": "tmpfs", - "Target": target, - "TmpfsOptions": map[string]interface{}{ - "SizeBytes": 4096 * 1024, "Mode": 0700}}, - expectedOptions: []string{"rw", "nosuid", "nodev", "noexec", "relatime", "size=4096k", "mode=700"}, - }, - } - - for i, x := range cases { - cName := fmt.Sprintf("test-tmpfs-%d", i) - data := map[string]interface{}{ - "Image": "busybox", - "Cmd": []string{"/bin/sh", "-c", - fmt.Sprintf("mount | grep 'tmpfs on %s'", target)}, - "HostConfig": map[string]interface{}{"Mounts": []map[string]interface{}{x.cfg}}, - } - status, resp, err := sockRequest("POST", "/containers/create?name="+cName, data) - c.Assert(err, checker.IsNil, check.Commentf(string(resp))) - c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(resp))) - out, _ := dockerCmd(c, "start", "-a", cName) - for _, option := range x.expectedOptions { - c.Assert(out, checker.Contains, option) - } - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_create_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_create_test.go deleted file mode 100644 index 41011c3..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_create_test.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -import ( - "net/http" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestAPICreateWithNotExistImage(c *check.C) { - name := "test" - config := map[string]interface{}{ - "Image": "test456:v1", - "Volumes": map[string]struct{}{"/tmp": {}}, - } - - status, body, err := sockRequest("POST", "/containers/create?name="+name, config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusNotFound) - expected := "No such image: test456:v1" - c.Assert(getErrorMessage(c, body), checker.Contains, expected) - - config2 := map[string]interface{}{ - "Image": "test456", - "Volumes": map[string]struct{}{"/tmp": {}}, - } - - status, body, err = sockRequest("POST", "/containers/create?name="+name, config2) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusNotFound) - expected = "No such image: test456:latest" - c.Assert(getErrorMessage(c, body), checker.Equals, expected) - - config3 := map[string]interface{}{ - "Image": "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa", - } - - status, body, err = sockRequest("POST", "/containers/create?name="+name, config3) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusNotFound) - expected = "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa" - c.Assert(getErrorMessage(c, body), checker.Equals, expected) - -} - -// Test for #25099 -func (s *DockerSuite) TestAPICreateEmptyEnv(c *check.C) { - name := "test1" - config := map[string]interface{}{ - "Image": "busybox", - "Env": []string{"", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}, - "Cmd": []string{"true"}, - } - - status, body, err := sockRequest("POST", "/containers/create?name="+name, config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusInternalServerError) - expected := "invalid environment variable:" - c.Assert(getErrorMessage(c, body), checker.Contains, expected) - - name = "test2" - config = map[string]interface{}{ - "Image": "busybox", - "Env": []string{"=", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}, - "Cmd": []string{"true"}, - } - status, body, err = sockRequest("POST", "/containers/create?name="+name, config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusInternalServerError) - expected = "invalid environment variable: =" - c.Assert(getErrorMessage(c, body), checker.Contains, expected) - - name = "test3" - config = map[string]interface{}{ - "Image": "busybox", - "Env": []string{"=foo", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}, - "Cmd": []string{"true"}, - } - status, body, err = sockRequest("POST", "/containers/create?name="+name, config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusInternalServerError) - expected = "invalid environment variable: =foo" - c.Assert(getErrorMessage(c, body), checker.Contains, expected) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_events_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_events_test.go deleted file mode 100644 index 3891c87..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_events_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "encoding/json" - "io" - "net/http" - "net/url" - "strconv" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/jsonmessage" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestEventsAPIEmptyOutput(c *check.C) { - type apiResp struct { - resp *http.Response - err error - } - chResp := make(chan *apiResp) - go func() { - resp, body, err := sockRequestRaw("GET", "/events", nil, "") - body.Close() - chResp <- &apiResp{resp, err} - }() - - select { - case r := <-chResp: - c.Assert(r.err, checker.IsNil) - c.Assert(r.resp.StatusCode, checker.Equals, http.StatusOK) - case <-time.After(3 * time.Second): - c.Fatal("timeout waiting for events api to respond, should have responded immediately") - } -} - -func (s *DockerSuite) TestEventsAPIBackwardsCompatible(c *check.C) { - since := daemonTime(c).Unix() - ts := strconv.FormatInt(since, 10) - - out, _ := runSleepingContainer(c, "--name=foo", "-d") - containerID := strings.TrimSpace(out) - c.Assert(waitRun(containerID), checker.IsNil) - - q := url.Values{} - q.Set("since", ts) - - _, body, err := sockRequestRaw("GET", "/events?"+q.Encode(), nil, "") - c.Assert(err, checker.IsNil) - defer body.Close() - - dec := json.NewDecoder(body) - var containerCreateEvent *jsonmessage.JSONMessage - for { - var event jsonmessage.JSONMessage - if err := dec.Decode(&event); err != nil { - if err == io.EOF { - break - } - c.Fatal(err) - } - if event.Status == "create" && event.ID == containerID { - containerCreateEvent = &event - break - } - } - - c.Assert(containerCreateEvent, checker.Not(checker.IsNil)) - c.Assert(containerCreateEvent.Status, checker.Equals, "create") - c.Assert(containerCreateEvent.ID, checker.Equals, containerID) - c.Assert(containerCreateEvent.From, checker.Equals, "busybox") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_exec_resize_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_exec_resize_test.go deleted file mode 100644 index cf4dded..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_exec_resize_test.go +++ /dev/null @@ -1,103 +0,0 @@ -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "net/http" - "strings" - "sync" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestExecResizeAPIHeightWidthNoInt(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - cleanedContainerID := strings.TrimSpace(out) - - endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar" - status, _, err := sockRequest("POST", endpoint, nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) -} - -// Part of #14845 -func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *check.C) { - name := "exec_resize_test" - dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh") - - testExecResize := func() error { - data := map[string]interface{}{ - "AttachStdin": true, - "Cmd": []string{"/bin/sh"}, - } - uri := fmt.Sprintf("/containers/%s/exec", name) - status, body, err := sockRequest("POST", uri, data) - if err != nil { - return err - } - if status != http.StatusCreated { - return fmt.Errorf("POST %s is expected to return %d, got %d", uri, http.StatusCreated, status) - } - - out := map[string]string{} - err = json.Unmarshal(body, &out) - if err != nil { - return fmt.Errorf("ExecCreate returned invalid json. Error: %q", err.Error()) - } - - execID := out["Id"] - if len(execID) < 1 { - return fmt.Errorf("ExecCreate got invalid execID") - } - - payload := bytes.NewBufferString(`{"Tty":true}`) - conn, _, err := sockRequestHijack("POST", fmt.Sprintf("/exec/%s/start", execID), payload, "application/json") - if err != nil { - return fmt.Errorf("Failed to start the exec: %q", err.Error()) - } - defer conn.Close() - - _, rc, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/resize?h=24&w=80", execID), nil, "text/plain") - // It's probably a panic of the daemon if io.ErrUnexpectedEOF is returned. - if err == io.ErrUnexpectedEOF { - return fmt.Errorf("The daemon might have crashed.") - } - - if err == nil { - rc.Close() - } - - // We only interested in the io.ErrUnexpectedEOF error, so we return nil otherwise. - return nil - } - - // The panic happens when daemon.ContainerExecStart is called but the - // container.Exec is not called. - // Because the panic is not 100% reproducible, we send the requests concurrently - // to increase the probability that the problem is triggered. - var ( - n = 10 - ch = make(chan error, n) - wg sync.WaitGroup - ) - for i := 0; i < n; i++ { - wg.Add(1) - go func() { - defer wg.Done() - if err := testExecResize(); err != nil { - ch <- err - } - }() - } - - wg.Wait() - select { - case err := <-ch: - c.Fatal(err.Error()) - default: - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_exec_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_exec_test.go deleted file mode 100644 index 716e9ac..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_exec_test.go +++ /dev/null @@ -1,198 +0,0 @@ -// +build !test_no_exec - -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "net/http" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// Regression test for #9414 -func (s *DockerSuite) TestExecAPICreateNoCmd(c *check.C) { - name := "exec_test" - dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") - - status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil}) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) - - comment := check.Commentf("Expected message when creating exec command with no Cmd specified") - c.Assert(getErrorMessage(c, body), checker.Contains, "No exec command specified", comment) -} - -func (s *DockerSuite) TestExecAPICreateNoValidContentType(c *check.C) { - name := "exec_test" - dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") - - jsonData := bytes.NewBuffer(nil) - if err := json.NewEncoder(jsonData).Encode(map[string]interface{}{"Cmd": nil}); err != nil { - c.Fatalf("Can not encode data to json %s", err) - } - - res, body, err := sockRequestRaw("POST", fmt.Sprintf("/containers/%s/exec", name), jsonData, "text/plain") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) - - b, err := readBody(body) - c.Assert(err, checker.IsNil) - - comment := check.Commentf("Expected message when creating exec command with invalid Content-Type specified") - c.Assert(getErrorMessage(c, b), checker.Contains, "Content-Type specified", comment) -} - -func (s *DockerSuite) TestExecAPICreateContainerPaused(c *check.C) { - // Not relevant on Windows as Windows containers cannot be paused - testRequires(c, DaemonIsLinux) - name := "exec_create_test" - dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") - - dockerCmd(c, "pause", name) - status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}}) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusConflict) - - comment := check.Commentf("Expected message when creating exec command with Container %s is paused", name) - c.Assert(getErrorMessage(c, body), checker.Contains, "Container "+name+" is paused, unpause the container before exec", comment) -} - -func (s *DockerSuite) TestExecAPIStart(c *check.C) { - testRequires(c, DaemonIsLinux) // Uses pause/unpause but bits may be salvagable to Windows to Windows CI - dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") - - id := createExec(c, "test") - startExec(c, id, http.StatusOK) - - var execJSON struct{ PID int } - inspectExec(c, id, &execJSON) - c.Assert(execJSON.PID, checker.GreaterThan, 1) - - id = createExec(c, "test") - dockerCmd(c, "stop", "test") - - startExec(c, id, http.StatusNotFound) - - dockerCmd(c, "start", "test") - startExec(c, id, http.StatusNotFound) - - // make sure exec is created before pausing - id = createExec(c, "test") - dockerCmd(c, "pause", "test") - startExec(c, id, http.StatusConflict) - dockerCmd(c, "unpause", "test") - startExec(c, id, http.StatusOK) -} - -func (s *DockerSuite) TestExecAPIStartEnsureHeaders(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") - - id := createExec(c, "test") - resp, _, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(resp.Header.Get("Server"), checker.Not(checker.Equals), "") -} - -func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later - runSleepingContainer(c, "-d", "--name", "test") - id := createExec(c, "test") - - resp, body, err := sockRequestRaw("POST", fmt.Sprintf("/v1.20/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "text/plain") - c.Assert(err, checker.IsNil) - - b, err := readBody(body) - comment := check.Commentf("response body: %s", b) - c.Assert(err, checker.IsNil, comment) - c.Assert(resp.StatusCode, checker.Equals, http.StatusOK, comment) -} - -// #19362 -func (s *DockerSuite) TestExecAPIStartMultipleTimesError(c *check.C) { - runSleepingContainer(c, "-d", "--name", "test") - execID := createExec(c, "test") - startExec(c, execID, http.StatusOK) - - timeout := time.After(60 * time.Second) - var execJSON struct{ Running bool } - for { - select { - case <-timeout: - c.Fatal("timeout waiting for exec to start") - default: - } - - inspectExec(c, execID, &execJSON) - if !execJSON.Running { - break - } - } - - startExec(c, execID, http.StatusConflict) -} - -// #20638 -func (s *DockerSuite) TestExecAPIStartWithDetach(c *check.C) { - name := "foo" - runSleepingContainer(c, "-d", "-t", "--name", name) - data := map[string]interface{}{ - "cmd": []string{"true"}, - "AttachStdin": true, - } - _, b, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), data) - c.Assert(err, checker.IsNil, check.Commentf(string(b))) - - createResp := struct { - ID string `json:"Id"` - }{} - c.Assert(json.Unmarshal(b, &createResp), checker.IsNil, check.Commentf(string(b))) - - _, body, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", createResp.ID), strings.NewReader(`{"Detach": true}`), "application/json") - c.Assert(err, checker.IsNil) - - b, err = readBody(body) - comment := check.Commentf("response body: %s", b) - c.Assert(err, checker.IsNil, comment) - - resp, _, err := sockRequestRaw("GET", "/_ping", nil, "") - c.Assert(err, checker.IsNil) - if resp.StatusCode != http.StatusOK { - c.Fatal("daemon is down, it should alive") - } -} - -func createExec(c *check.C, name string) string { - _, b, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}}) - c.Assert(err, checker.IsNil, check.Commentf(string(b))) - - createResp := struct { - ID string `json:"Id"` - }{} - c.Assert(json.Unmarshal(b, &createResp), checker.IsNil, check.Commentf(string(b))) - return createResp.ID -} - -func startExec(c *check.C, id string, code int) { - resp, body, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "application/json") - c.Assert(err, checker.IsNil) - - b, err := readBody(body) - comment := check.Commentf("response body: %s", b) - c.Assert(err, checker.IsNil, comment) - c.Assert(resp.StatusCode, checker.Equals, code, comment) -} - -func inspectExec(c *check.C, id string, out interface{}) { - resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/exec/%s/json", id), nil, "") - c.Assert(err, checker.IsNil) - defer body.Close() - c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) - err = json.NewDecoder(body).Decode(out) - c.Assert(err, checker.IsNil) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_images_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_images_test.go deleted file mode 100644 index b7617ea..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_images_test.go +++ /dev/null @@ -1,165 +0,0 @@ -package main - -import ( - "encoding/json" - "net/http" - "net/url" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestAPIImagesFilter(c *check.C) { - name := "utest:tag1" - name2 := "utest/docker:tag2" - name3 := "utest:5000/docker:tag3" - for _, n := range []string{name, name2, name3} { - dockerCmd(c, "tag", "busybox", n) - } - type image types.ImageSummary - getImages := func(filter string) []image { - v := url.Values{} - v.Set("filter", filter) - status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var images []image - err = json.Unmarshal(b, &images) - c.Assert(err, checker.IsNil) - - return images - } - - //incorrect number of matches returned - images := getImages("utest*/*") - c.Assert(images[0].RepoTags, checker.HasLen, 2) - - images = getImages("utest") - c.Assert(images[0].RepoTags, checker.HasLen, 1) - - images = getImages("utest*") - c.Assert(images[0].RepoTags, checker.HasLen, 1) - - images = getImages("*5000*/*") - c.Assert(images[0].RepoTags, checker.HasLen, 1) -} - -func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *check.C) { - // TODO Windows to Windows CI: Investigate further why this test fails. - testRequires(c, Network) - testRequires(c, DaemonIsLinux) - out, err := buildImage("saveandload", "FROM busybox\nENV FOO bar", false) - c.Assert(err, checker.IsNil) - id := strings.TrimSpace(out) - - res, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "") - c.Assert(err, checker.IsNil) - defer body.Close() - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - - dockerCmd(c, "rmi", id) - - res, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar") - c.Assert(err, checker.IsNil) - defer loadBody.Close() - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - - inspectOut := inspectField(c, id, "Id") - c.Assert(strings.TrimSpace(string(inspectOut)), checker.Equals, id, check.Commentf("load did not work properly")) -} - -func (s *DockerSuite) TestAPIImagesDelete(c *check.C) { - if daemonPlatform != "windows" { - testRequires(c, Network) - } - name := "test-api-images-delete" - out, err := buildImage(name, "FROM busybox\nENV FOO bar", false) - c.Assert(err, checker.IsNil) - id := strings.TrimSpace(out) - - dockerCmd(c, "tag", name, "test:tag1") - - status, _, err := sockRequest("DELETE", "/images/"+id, nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusConflict) - - status, _, err = sockRequest("DELETE", "/images/test:noexist", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNotFound) //Status Codes:404 – no such image - - status, _, err = sockRequest("DELETE", "/images/test:tag1", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) -} - -func (s *DockerSuite) TestAPIImagesHistory(c *check.C) { - if daemonPlatform != "windows" { - testRequires(c, Network) - } - name := "test-api-images-history" - out, err := buildImage(name, "FROM busybox\nENV FOO bar", false) - c.Assert(err, checker.IsNil) - - id := strings.TrimSpace(out) - - status, body, err := sockRequest("GET", "/images/"+id+"/history", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var historydata []types.ImageHistory - err = json.Unmarshal(body, &historydata) - c.Assert(err, checker.IsNil, check.Commentf("Error on unmarshal")) - - c.Assert(historydata, checker.Not(checker.HasLen), 0) - c.Assert(historydata[0].Tags[0], checker.Equals, "test-api-images-history:latest") -} - -// #14846 -func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *check.C) { - testRequires(c, Network) - - res, b, err := sockRequestRaw("GET", "/images/search?term=test", nil, "application/json") - c.Assert(err, check.IsNil) - b.Close() - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - c.Assert(res.Header.Get("Content-Type"), checker.Equals, "application/json") -} - -// Test case for 30027: image size reported as -1 in v1.12 client against v1.13 daemon. -// This test checks to make sure both v1.12 and v1.13 client against v1.13 daemon get correct `Size` after the fix. -func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *check.C) { - status, b, err := sockRequest("GET", "/images/json", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - var images []types.ImageSummary - err = json.Unmarshal(b, &images) - c.Assert(err, checker.IsNil) - c.Assert(len(images), checker.Not(checker.Equals), 0) - for _, image := range images { - c.Assert(image.Size, checker.Not(checker.Equals), int64(-1)) - } - - type v124Image struct { - ID string `json:"Id"` - ParentID string `json:"ParentId"` - RepoTags []string - RepoDigests []string - Created int64 - Size int64 - VirtualSize int64 - Labels map[string]string - } - status, b, err = sockRequest("GET", "/v1.24/images/json", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - var v124Images []v124Image - err = json.Unmarshal(b, &v124Images) - c.Assert(err, checker.IsNil) - c.Assert(len(v124Images), checker.Not(checker.Equals), 0) - for _, image := range v124Images { - c.Assert(image.Size, checker.Not(checker.Equals), int64(-1)) - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_info_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_info_test.go deleted file mode 100644 index 1556099..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_info_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "net/http" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestInfoAPI(c *check.C) { - endpoint := "/info" - - status, body, err := sockRequest("GET", endpoint, nil) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(err, checker.IsNil) - - // always shown fields - stringsToCheck := []string{ - "ID", - "Containers", - "ContainersRunning", - "ContainersPaused", - "ContainersStopped", - "Images", - "LoggingDriver", - "OperatingSystem", - "NCPU", - "OSType", - "Architecture", - "MemTotal", - "KernelVersion", - "Driver", - "ServerVersion", - "SecurityOptions"} - - out := string(body) - for _, linePrefix := range stringsToCheck { - c.Assert(out, checker.Contains, linePrefix) - } -} - -func (s *DockerSuite) TestInfoAPIVersioned(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later - endpoint := "/v1.20/info" - - status, body, err := sockRequest("GET", endpoint, nil) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(err, checker.IsNil) - - out := string(body) - c.Assert(out, checker.Contains, "ExecutionDriver") - c.Assert(out, checker.Contains, "not supported") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_inspect_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_inspect_test.go deleted file mode 100644 index 546b224..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_inspect_test.go +++ /dev/null @@ -1,183 +0,0 @@ -package main - -import ( - "encoding/json" - "net/http" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/versions/v1p20" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/stringutils" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestInspectAPIContainerResponse(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - - cleanedContainerID := strings.TrimSpace(out) - keysBase := []string{"Id", "State", "Created", "Path", "Args", "Config", "Image", "NetworkSettings", - "ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "MountLabel", "ProcessLabel", "GraphDriver"} - - type acase struct { - version string - keys []string - } - - var cases []acase - - if daemonPlatform == "windows" { - cases = []acase{ - {"v1.25", append(keysBase, "Mounts")}, - } - - } else { - cases = []acase{ - {"v1.20", append(keysBase, "Mounts")}, - {"v1.19", append(keysBase, "Volumes", "VolumesRW")}, - } - } - - for _, cs := range cases { - body := getInspectBody(c, cs.version, cleanedContainerID) - - var inspectJSON map[string]interface{} - err := json.Unmarshal(body, &inspectJSON) - c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version %s", cs.version)) - - for _, key := range cs.keys { - _, ok := inspectJSON[key] - c.Check(ok, checker.True, check.Commentf("%s does not exist in response for version %s", key, cs.version)) - } - - //Issue #6830: type not properly converted to JSON/back - _, ok := inspectJSON["Path"].(bool) - c.Assert(ok, checker.False, check.Commentf("Path of `true` should not be converted to boolean `true` via JSON marshalling")) - } -} - -func (s *DockerSuite) TestInspectAPIContainerVolumeDriverLegacy(c *check.C) { - // No legacy implications for Windows - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - - cleanedContainerID := strings.TrimSpace(out) - - cases := []string{"v1.19", "v1.20"} - for _, version := range cases { - body := getInspectBody(c, version, cleanedContainerID) - - var inspectJSON map[string]interface{} - err := json.Unmarshal(body, &inspectJSON) - c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version %s", version)) - - config, ok := inspectJSON["Config"] - c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'")) - cfg := config.(map[string]interface{}) - _, ok = cfg["VolumeDriver"] - c.Assert(ok, checker.True, check.Commentf("API version %s expected to include VolumeDriver in 'Config'", version)) - } -} - -func (s *DockerSuite) TestInspectAPIContainerVolumeDriver(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "--volume-driver", "local", "busybox", "true") - - cleanedContainerID := strings.TrimSpace(out) - - body := getInspectBody(c, "v1.25", cleanedContainerID) - - var inspectJSON map[string]interface{} - err := json.Unmarshal(body, &inspectJSON) - c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version 1.25")) - - config, ok := inspectJSON["Config"] - c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'")) - cfg := config.(map[string]interface{}) - _, ok = cfg["VolumeDriver"] - c.Assert(ok, checker.False, check.Commentf("API version 1.25 expected to not include VolumeDriver in 'Config'")) - - config, ok = inspectJSON["HostConfig"] - c.Assert(ok, checker.True, check.Commentf("Unable to find 'HostConfig'")) - cfg = config.(map[string]interface{}) - _, ok = cfg["VolumeDriver"] - c.Assert(ok, checker.True, check.Commentf("API version 1.25 expected to include VolumeDriver in 'HostConfig'")) -} - -func (s *DockerSuite) TestInspectAPIImageResponse(c *check.C) { - dockerCmd(c, "tag", "busybox:latest", "busybox:mytag") - - endpoint := "/images/busybox/json" - status, body, err := sockRequest("GET", endpoint, nil) - - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var imageJSON types.ImageInspect - err = json.Unmarshal(body, &imageJSON) - c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for latest version")) - c.Assert(imageJSON.RepoTags, checker.HasLen, 2) - - c.Assert(stringutils.InSlice(imageJSON.RepoTags, "busybox:latest"), checker.Equals, true) - c.Assert(stringutils.InSlice(imageJSON.RepoTags, "busybox:mytag"), checker.Equals, true) -} - -// #17131, #17139, #17173 -func (s *DockerSuite) TestInspectAPIEmptyFieldsInConfigPre121(c *check.C) { - // Not relevant on Windows - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - - cleanedContainerID := strings.TrimSpace(out) - - cases := []string{"v1.19", "v1.20"} - for _, version := range cases { - body := getInspectBody(c, version, cleanedContainerID) - - var inspectJSON map[string]interface{} - err := json.Unmarshal(body, &inspectJSON) - c.Assert(err, checker.IsNil, check.Commentf("Unable to unmarshal body for version %s", version)) - config, ok := inspectJSON["Config"] - c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'")) - cfg := config.(map[string]interface{}) - for _, f := range []string{"MacAddress", "NetworkDisabled", "ExposedPorts"} { - _, ok := cfg[f] - c.Check(ok, checker.True, check.Commentf("API version %s expected to include %s in 'Config'", version, f)) - } - } -} - -func (s *DockerSuite) TestInspectAPIBridgeNetworkSettings120(c *check.C) { - // Not relevant on Windows, and besides it doesn't have any bridge network settings - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - containerID := strings.TrimSpace(out) - waitRun(containerID) - - body := getInspectBody(c, "v1.20", containerID) - - var inspectJSON v1p20.ContainerJSON - err := json.Unmarshal(body, &inspectJSON) - c.Assert(err, checker.IsNil) - - settings := inspectJSON.NetworkSettings - c.Assert(settings.IPAddress, checker.Not(checker.HasLen), 0) -} - -func (s *DockerSuite) TestInspectAPIBridgeNetworkSettings121(c *check.C) { - // Windows doesn't have any bridge network settings - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - containerID := strings.TrimSpace(out) - waitRun(containerID) - - body := getInspectBody(c, "v1.21", containerID) - - var inspectJSON types.ContainerJSON - err := json.Unmarshal(body, &inspectJSON) - c.Assert(err, checker.IsNil) - - settings := inspectJSON.NetworkSettings - c.Assert(settings.IPAddress, checker.Not(checker.HasLen), 0) - c.Assert(settings.Networks["bridge"], checker.Not(checker.IsNil)) - c.Assert(settings.IPAddress, checker.Equals, settings.Networks["bridge"].IPAddress) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_inspect_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_inspect_unix_test.go deleted file mode 100644 index f49a139..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_inspect_unix_test.go +++ /dev/null @@ -1,35 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "fmt" - "net/http" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// #16665 -func (s *DockerSuite) TestInspectAPICpusetInConfigPre120(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, cgroupCpuset) - - name := "cpusetinconfig-pre120" - dockerCmd(c, "run", "--name", name, "--cpuset-cpus", "0", "busybox", "true") - - status, body, err := sockRequest("GET", fmt.Sprintf("/v1.19/containers/%s/json", name), nil) - c.Assert(status, check.Equals, http.StatusOK) - c.Assert(err, check.IsNil) - - var inspectJSON map[string]interface{} - err = json.Unmarshal(body, &inspectJSON) - c.Assert(err, checker.IsNil, check.Commentf("unable to unmarshal body for version 1.19")) - - config, ok := inspectJSON["Config"] - c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'")) - cfg := config.(map[string]interface{}) - _, ok = cfg["Cpuset"] - c.Assert(ok, checker.True, check.Commentf("API version 1.19 expected to include Cpuset in 'Config'")) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_logs_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_logs_test.go deleted file mode 100644 index 2e8ffa9..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_logs_test.go +++ /dev/null @@ -1,87 +0,0 @@ -package main - -import ( - "bufio" - "bytes" - "fmt" - "net/http" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestLogsAPIWithStdout(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - type logOut struct { - out string - res *http.Response - err error - } - chLog := make(chan logOut) - - go func() { - res, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", id), nil, "") - if err != nil { - chLog <- logOut{"", nil, err} - return - } - defer body.Close() - out, err := bufio.NewReader(body).ReadString('\n') - if err != nil { - chLog <- logOut{"", nil, err} - return - } - chLog <- logOut{strings.TrimSpace(out), res, err} - }() - - select { - case l := <-chLog: - c.Assert(l.err, checker.IsNil) - c.Assert(l.res.StatusCode, checker.Equals, http.StatusOK) - if !strings.HasSuffix(l.out, "hello") { - c.Fatalf("expected log output to container 'hello', but it does not") - } - case <-time.After(20 * time.Second): - c.Fatal("timeout waiting for logs to exit") - } -} - -func (s *DockerSuite) TestLogsAPINoStdoutNorStderr(c *check.C) { - name := "logs_test" - dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") - - status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil) - c.Assert(status, checker.Equals, http.StatusBadRequest) - c.Assert(err, checker.IsNil) - - expected := "Bad parameters: you must choose at least one stream" - c.Assert(getErrorMessage(c, body), checker.Contains, expected) -} - -// Regression test for #12704 -func (s *DockerSuite) TestLogsAPIFollowEmptyOutput(c *check.C) { - name := "logs_test" - t0 := time.Now() - dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10") - - _, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "") - t1 := time.Now() - c.Assert(err, checker.IsNil) - body.Close() - elapsed := t1.Sub(t0).Seconds() - if elapsed > 20.0 { - c.Fatalf("HTTP response was not immediate (elapsed %.1fs)", elapsed) - } -} - -func (s *DockerSuite) TestLogsAPIContainerNotFound(c *check.C) { - name := "nonExistentContainer" - resp, _, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "") - c.Assert(err, checker.IsNil) - c.Assert(resp.StatusCode, checker.Equals, http.StatusNotFound) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_network_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_network_test.go deleted file mode 100644 index 1cc66f0..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_network_test.go +++ /dev/null @@ -1,353 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "net" - "net/http" - "net/url" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/network" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestAPINetworkGetDefaults(c *check.C) { - testRequires(c, DaemonIsLinux) - // By default docker daemon creates 3 networks. check if they are present - defaults := []string{"bridge", "host", "none"} - for _, nn := range defaults { - c.Assert(isNetworkAvailable(c, nn), checker.Equals, true) - } -} - -func (s *DockerSuite) TestAPINetworkCreateDelete(c *check.C) { - testRequires(c, DaemonIsLinux) - // Create a network - name := "testnetwork" - config := types.NetworkCreateRequest{ - Name: name, - NetworkCreate: types.NetworkCreate{ - CheckDuplicate: true, - }, - } - id := createNetwork(c, config, true) - c.Assert(isNetworkAvailable(c, name), checker.Equals, true) - - // delete the network and make sure it is deleted - deleteNetwork(c, id, true) - c.Assert(isNetworkAvailable(c, name), checker.Equals, false) -} - -func (s *DockerSuite) TestAPINetworkCreateCheckDuplicate(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testcheckduplicate" - configOnCheck := types.NetworkCreateRequest{ - Name: name, - NetworkCreate: types.NetworkCreate{ - CheckDuplicate: true, - }, - } - configNotCheck := types.NetworkCreateRequest{ - Name: name, - NetworkCreate: types.NetworkCreate{ - CheckDuplicate: false, - }, - } - - // Creating a new network first - createNetwork(c, configOnCheck, true) - c.Assert(isNetworkAvailable(c, name), checker.Equals, true) - - // Creating another network with same name and CheckDuplicate must fail - createNetwork(c, configOnCheck, false) - - // Creating another network with same name and not CheckDuplicate must succeed - createNetwork(c, configNotCheck, true) -} - -func (s *DockerSuite) TestAPINetworkFilter(c *check.C) { - testRequires(c, DaemonIsLinux) - nr := getNetworkResource(c, getNetworkIDByName(c, "bridge")) - c.Assert(nr.Name, checker.Equals, "bridge") -} - -func (s *DockerSuite) TestAPINetworkInspect(c *check.C) { - testRequires(c, DaemonIsLinux) - // Inspect default bridge network - nr := getNetworkResource(c, "bridge") - c.Assert(nr.Name, checker.Equals, "bridge") - - // run a container and attach it to the default bridge network - out, _ := dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") - containerID := strings.TrimSpace(out) - containerIP := findContainerIP(c, "test", "bridge") - - // inspect default bridge network again and make sure the container is connected - nr = getNetworkResource(c, nr.ID) - c.Assert(nr.Driver, checker.Equals, "bridge") - c.Assert(nr.Scope, checker.Equals, "local") - c.Assert(nr.Internal, checker.Equals, false) - c.Assert(nr.EnableIPv6, checker.Equals, false) - c.Assert(nr.IPAM.Driver, checker.Equals, "default") - c.Assert(len(nr.Containers), checker.Equals, 1) - c.Assert(nr.Containers[containerID], checker.NotNil) - - ip, _, err := net.ParseCIDR(nr.Containers[containerID].IPv4Address) - c.Assert(err, checker.IsNil) - c.Assert(ip.String(), checker.Equals, containerIP) - - // IPAM configuration inspect - ipam := &network.IPAM{ - Driver: "default", - Config: []network.IPAMConfig{{Subnet: "172.28.0.0/16", IPRange: "172.28.5.0/24", Gateway: "172.28.5.254"}}, - } - config := types.NetworkCreateRequest{ - Name: "br0", - NetworkCreate: types.NetworkCreate{ - Driver: "bridge", - IPAM: ipam, - Options: map[string]string{"foo": "bar", "opts": "dopts"}, - }, - } - id0 := createNetwork(c, config, true) - c.Assert(isNetworkAvailable(c, "br0"), checker.Equals, true) - - nr = getNetworkResource(c, id0) - c.Assert(len(nr.IPAM.Config), checker.Equals, 1) - c.Assert(nr.IPAM.Config[0].Subnet, checker.Equals, "172.28.0.0/16") - c.Assert(nr.IPAM.Config[0].IPRange, checker.Equals, "172.28.5.0/24") - c.Assert(nr.IPAM.Config[0].Gateway, checker.Equals, "172.28.5.254") - c.Assert(nr.Options["foo"], checker.Equals, "bar") - c.Assert(nr.Options["opts"], checker.Equals, "dopts") - - // delete the network and make sure it is deleted - deleteNetwork(c, id0, true) - c.Assert(isNetworkAvailable(c, "br0"), checker.Equals, false) -} - -func (s *DockerSuite) TestAPINetworkConnectDisconnect(c *check.C) { - testRequires(c, DaemonIsLinux) - // Create test network - name := "testnetwork" - config := types.NetworkCreateRequest{ - Name: name, - } - id := createNetwork(c, config, true) - nr := getNetworkResource(c, id) - c.Assert(nr.Name, checker.Equals, name) - c.Assert(nr.ID, checker.Equals, id) - c.Assert(len(nr.Containers), checker.Equals, 0) - - // run a container - out, _ := dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") - containerID := strings.TrimSpace(out) - - // connect the container to the test network - connectNetwork(c, nr.ID, containerID) - - // inspect the network to make sure container is connected - nr = getNetworkResource(c, nr.ID) - c.Assert(len(nr.Containers), checker.Equals, 1) - c.Assert(nr.Containers[containerID], checker.NotNil) - - // check if container IP matches network inspect - ip, _, err := net.ParseCIDR(nr.Containers[containerID].IPv4Address) - c.Assert(err, checker.IsNil) - containerIP := findContainerIP(c, "test", "testnetwork") - c.Assert(ip.String(), checker.Equals, containerIP) - - // disconnect container from the network - disconnectNetwork(c, nr.ID, containerID) - nr = getNetworkResource(c, nr.ID) - c.Assert(nr.Name, checker.Equals, name) - c.Assert(len(nr.Containers), checker.Equals, 0) - - // delete the network - deleteNetwork(c, nr.ID, true) -} - -func (s *DockerSuite) TestAPINetworkIPAMMultipleBridgeNetworks(c *check.C) { - testRequires(c, DaemonIsLinux) - // test0 bridge network - ipam0 := &network.IPAM{ - Driver: "default", - Config: []network.IPAMConfig{{Subnet: "192.178.0.0/16", IPRange: "192.178.128.0/17", Gateway: "192.178.138.100"}}, - } - config0 := types.NetworkCreateRequest{ - Name: "test0", - NetworkCreate: types.NetworkCreate{ - Driver: "bridge", - IPAM: ipam0, - }, - } - id0 := createNetwork(c, config0, true) - c.Assert(isNetworkAvailable(c, "test0"), checker.Equals, true) - - ipam1 := &network.IPAM{ - Driver: "default", - Config: []network.IPAMConfig{{Subnet: "192.178.128.0/17", Gateway: "192.178.128.1"}}, - } - // test1 bridge network overlaps with test0 - config1 := types.NetworkCreateRequest{ - Name: "test1", - NetworkCreate: types.NetworkCreate{ - Driver: "bridge", - IPAM: ipam1, - }, - } - createNetwork(c, config1, false) - c.Assert(isNetworkAvailable(c, "test1"), checker.Equals, false) - - ipam2 := &network.IPAM{ - Driver: "default", - Config: []network.IPAMConfig{{Subnet: "192.169.0.0/16", Gateway: "192.169.100.100"}}, - } - // test2 bridge network does not overlap - config2 := types.NetworkCreateRequest{ - Name: "test2", - NetworkCreate: types.NetworkCreate{ - Driver: "bridge", - IPAM: ipam2, - }, - } - createNetwork(c, config2, true) - c.Assert(isNetworkAvailable(c, "test2"), checker.Equals, true) - - // remove test0 and retry to create test1 - deleteNetwork(c, id0, true) - createNetwork(c, config1, true) - c.Assert(isNetworkAvailable(c, "test1"), checker.Equals, true) - - // for networks w/o ipam specified, docker will choose proper non-overlapping subnets - createNetwork(c, types.NetworkCreateRequest{Name: "test3"}, true) - c.Assert(isNetworkAvailable(c, "test3"), checker.Equals, true) - createNetwork(c, types.NetworkCreateRequest{Name: "test4"}, true) - c.Assert(isNetworkAvailable(c, "test4"), checker.Equals, true) - createNetwork(c, types.NetworkCreateRequest{Name: "test5"}, true) - c.Assert(isNetworkAvailable(c, "test5"), checker.Equals, true) - - for i := 1; i < 6; i++ { - deleteNetwork(c, fmt.Sprintf("test%d", i), true) - } -} - -func (s *DockerSuite) TestAPICreateDeletePredefinedNetworks(c *check.C) { - testRequires(c, DaemonIsLinux) - createDeletePredefinedNetwork(c, "bridge") - createDeletePredefinedNetwork(c, "none") - createDeletePredefinedNetwork(c, "host") -} - -func createDeletePredefinedNetwork(c *check.C, name string) { - // Create pre-defined network - config := types.NetworkCreateRequest{ - Name: name, - NetworkCreate: types.NetworkCreate{ - CheckDuplicate: true, - }, - } - shouldSucceed := false - createNetwork(c, config, shouldSucceed) - deleteNetwork(c, name, shouldSucceed) -} - -func isNetworkAvailable(c *check.C, name string) bool { - status, body, err := sockRequest("GET", "/networks", nil) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(err, checker.IsNil) - - nJSON := []types.NetworkResource{} - err = json.Unmarshal(body, &nJSON) - c.Assert(err, checker.IsNil) - - for _, n := range nJSON { - if n.Name == name { - return true - } - } - return false -} - -func getNetworkIDByName(c *check.C, name string) string { - var ( - v = url.Values{} - filterArgs = filters.NewArgs() - ) - filterArgs.Add("name", name) - filterJSON, err := filters.ToParam(filterArgs) - c.Assert(err, checker.IsNil) - v.Set("filters", filterJSON) - - status, body, err := sockRequest("GET", "/networks?"+v.Encode(), nil) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(err, checker.IsNil) - - nJSON := []types.NetworkResource{} - err = json.Unmarshal(body, &nJSON) - c.Assert(err, checker.IsNil) - c.Assert(len(nJSON), checker.Equals, 1) - - return nJSON[0].ID -} - -func getNetworkResource(c *check.C, id string) *types.NetworkResource { - _, obj, err := sockRequest("GET", "/networks/"+id, nil) - c.Assert(err, checker.IsNil) - - nr := types.NetworkResource{} - err = json.Unmarshal(obj, &nr) - c.Assert(err, checker.IsNil) - - return &nr -} - -func createNetwork(c *check.C, config types.NetworkCreateRequest, shouldSucceed bool) string { - status, resp, err := sockRequest("POST", "/networks/create", config) - if !shouldSucceed { - c.Assert(status, checker.Not(checker.Equals), http.StatusCreated) - return "" - } - - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - var nr types.NetworkCreateResponse - err = json.Unmarshal(resp, &nr) - c.Assert(err, checker.IsNil) - - return nr.ID -} - -func connectNetwork(c *check.C, nid, cid string) { - config := types.NetworkConnect{ - Container: cid, - } - - status, _, err := sockRequest("POST", "/networks/"+nid+"/connect", config) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(err, checker.IsNil) -} - -func disconnectNetwork(c *check.C, nid, cid string) { - config := types.NetworkConnect{ - Container: cid, - } - - status, _, err := sockRequest("POST", "/networks/"+nid+"/disconnect", config) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(err, checker.IsNil) -} - -func deleteNetwork(c *check.C, id string, shouldSucceed bool) { - status, _, err := sockRequest("DELETE", "/networks/"+id, nil) - if !shouldSucceed { - c.Assert(status, checker.Not(checker.Equals), http.StatusOK) - return - } - c.Assert(status, checker.Equals, http.StatusNoContent) - c.Assert(err, checker.IsNil) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_resize_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_resize_test.go deleted file mode 100644 index daf1b05..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_resize_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "net/http" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestResizeAPIResponse(c *check.C) { - out, _ := runSleepingContainer(c, "-d") - cleanedContainerID := strings.TrimSpace(out) - - endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" - status, _, err := sockRequest("POST", endpoint, nil) - c.Assert(status, check.Equals, http.StatusOK) - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestResizeAPIHeightWidthNoInt(c *check.C) { - out, _ := runSleepingContainer(c, "-d") - cleanedContainerID := strings.TrimSpace(out) - - endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar" - status, _, err := sockRequest("POST", endpoint, nil) - c.Assert(status, check.Equals, http.StatusInternalServerError) - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestResizeAPIResponseWhenContainerNotStarted(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - cleanedContainerID := strings.TrimSpace(out) - - // make sure the exited container is not running - dockerCmd(c, "wait", cleanedContainerID) - - endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" - status, body, err := sockRequest("POST", endpoint, nil) - c.Assert(status, check.Equals, http.StatusInternalServerError) - c.Assert(err, check.IsNil) - - c.Assert(getErrorMessage(c, body), checker.Contains, "is not running", check.Commentf("resize should fail with message 'Container is not running'")) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_service_update_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_service_update_test.go deleted file mode 100644 index 15a21e5..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_service_update_test.go +++ /dev/null @@ -1,39 +0,0 @@ -// +build !windows - -package main - -import ( - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func setPortConfig(portConfig []swarm.PortConfig) serviceConstructor { - return func(s *swarm.Service) { - if s.Spec.EndpointSpec == nil { - s.Spec.EndpointSpec = &swarm.EndpointSpec{} - } - s.Spec.EndpointSpec.Ports = portConfig - } -} - -func (s *DockerSwarmSuite) TestAPIServiceUpdatePort(c *check.C) { - d := s.AddDaemon(c, true, true) - - // Create a service with a port mapping of 8080:8081. - portConfig := []swarm.PortConfig{{TargetPort: 8081, PublishedPort: 8080}} - serviceID := d.createService(c, simpleTestService, setInstances(1), setPortConfig(portConfig)) - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - // Update the service: changed the port mapping from 8080:8081 to 8082:8083. - updatedPortConfig := []swarm.PortConfig{{TargetPort: 8083, PublishedPort: 8082}} - remoteService := d.getService(c, serviceID) - d.updateService(c, remoteService, setPortConfig(updatedPortConfig)) - - // Inspect the service and verify port mapping. - updatedService := d.getService(c, serviceID) - c.Assert(updatedService.Spec.EndpointSpec, check.NotNil) - c.Assert(len(updatedService.Spec.EndpointSpec.Ports), check.Equals, 1) - c.Assert(updatedService.Spec.EndpointSpec.Ports[0].TargetPort, check.Equals, uint32(8083)) - c.Assert(updatedService.Spec.EndpointSpec.Ports[0].PublishedPort, check.Equals, uint32(8082)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_stats_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_stats_test.go deleted file mode 100644 index 23fbdbb..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_stats_test.go +++ /dev/null @@ -1,310 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "net/http" - "os/exec" - "runtime" - "strconv" - "strings" - "sync" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/versions" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -var expectedNetworkInterfaceStats = strings.Split("rx_bytes rx_dropped rx_errors rx_packets tx_bytes tx_dropped tx_errors tx_packets", " ") - -func (s *DockerSuite) TestAPIStatsNoStreamGetCpu(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true;do echo 'Hello'; usleep 100000; done") - - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "") - c.Assert(err, checker.IsNil) - c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) - c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json") - - var v *types.Stats - err = json.NewDecoder(body).Decode(&v) - c.Assert(err, checker.IsNil) - body.Close() - - var cpuPercent = 0.0 - - if daemonPlatform != "windows" { - cpuDelta := float64(v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage) - systemDelta := float64(v.CPUStats.SystemUsage - v.PreCPUStats.SystemUsage) - cpuPercent = (cpuDelta / systemDelta) * float64(len(v.CPUStats.CPUUsage.PercpuUsage)) * 100.0 - } else { - // Max number of 100ns intervals between the previous time read and now - possIntervals := uint64(v.Read.Sub(v.PreRead).Nanoseconds()) // Start with number of ns intervals - possIntervals /= 100 // Convert to number of 100ns intervals - possIntervals *= uint64(v.NumProcs) // Multiple by the number of processors - - // Intervals used - intervalsUsed := v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage - - // Percentage avoiding divide-by-zero - if possIntervals > 0 { - cpuPercent = float64(intervalsUsed) / float64(possIntervals) * 100.0 - } - } - - c.Assert(cpuPercent, check.Not(checker.Equals), 0.0, check.Commentf("docker stats with no-stream get cpu usage failed: was %v", cpuPercent)) -} - -func (s *DockerSuite) TestAPIStatsStoppedContainerInGoroutines(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo 1") - id := strings.TrimSpace(out) - - getGoRoutines := func() int { - _, body, err := sockRequestRaw("GET", fmt.Sprintf("/info"), nil, "") - c.Assert(err, checker.IsNil) - info := types.Info{} - err = json.NewDecoder(body).Decode(&info) - c.Assert(err, checker.IsNil) - body.Close() - return info.NGoroutines - } - - // When the HTTP connection is closed, the number of goroutines should not increase. - routines := getGoRoutines() - _, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats", id), nil, "") - c.Assert(err, checker.IsNil) - body.Close() - - t := time.After(30 * time.Second) - for { - select { - case <-t: - c.Assert(getGoRoutines(), checker.LessOrEqualThan, routines) - return - default: - if n := getGoRoutines(); n <= routines { - return - } - time.Sleep(200 * time.Millisecond) - } - } -} - -func (s *DockerSuite) TestAPIStatsNetworkStats(c *check.C) { - testRequires(c, SameHostDaemon) - - out, _ := runSleepingContainer(c) - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - // Retrieve the container address - net := "bridge" - if daemonPlatform == "windows" { - net = "nat" - } - contIP := findContainerIP(c, id, net) - numPings := 1 - - var preRxPackets uint64 - var preTxPackets uint64 - var postRxPackets uint64 - var postTxPackets uint64 - - // Get the container networking stats before and after pinging the container - nwStatsPre := getNetworkStats(c, id) - for _, v := range nwStatsPre { - preRxPackets += v.RxPackets - preTxPackets += v.TxPackets - } - - countParam := "-c" - if runtime.GOOS == "windows" { - countParam = "-n" // Ping count parameter is -n on Windows - } - pingout, err := exec.Command("ping", contIP, countParam, strconv.Itoa(numPings)).CombinedOutput() - if err != nil && runtime.GOOS == "linux" { - // If it fails then try a work-around, but just for linux. - // If this fails too then go back to the old error for reporting. - // - // The ping will sometimes fail due to an apparmor issue where it - // denies access to the libc.so.6 shared library - running it - // via /lib64/ld-linux-x86-64.so.2 seems to work around it. - pingout2, err2 := exec.Command("/lib64/ld-linux-x86-64.so.2", "/bin/ping", contIP, "-c", strconv.Itoa(numPings)).CombinedOutput() - if err2 == nil { - pingout = pingout2 - err = err2 - } - } - c.Assert(err, checker.IsNil) - pingouts := string(pingout[:]) - nwStatsPost := getNetworkStats(c, id) - for _, v := range nwStatsPost { - postRxPackets += v.RxPackets - postTxPackets += v.TxPackets - } - - // Verify the stats contain at least the expected number of packets - // On Linux, account for ARP. - expRxPkts := preRxPackets + uint64(numPings) - expTxPkts := preTxPackets + uint64(numPings) - if daemonPlatform != "windows" { - expRxPkts++ - expTxPkts++ - } - c.Assert(postTxPackets, checker.GreaterOrEqualThan, expTxPkts, - check.Commentf("Reported less TxPackets than expected. Expected >= %d. Found %d. %s", expTxPkts, postTxPackets, pingouts)) - c.Assert(postRxPackets, checker.GreaterOrEqualThan, expRxPkts, - check.Commentf("Reported less Txbytes than expected. Expected >= %d. Found %d. %s", expRxPkts, postRxPackets, pingouts)) -} - -func (s *DockerSuite) TestAPIStatsNetworkStatsVersioning(c *check.C) { - // Windows doesn't support API versions less than 1.25, so no point testing 1.17 .. 1.21 - testRequires(c, SameHostDaemon, DaemonIsLinux) - - out, _ := runSleepingContainer(c) - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - wg := sync.WaitGroup{} - - for i := 17; i <= 21; i++ { - wg.Add(1) - go func(i int) { - defer wg.Done() - apiVersion := fmt.Sprintf("v1.%d", i) - statsJSONBlob := getVersionedStats(c, id, apiVersion) - if versions.LessThan(apiVersion, "v1.21") { - c.Assert(jsonBlobHasLTv121NetworkStats(statsJSONBlob), checker.Equals, true, - check.Commentf("Stats JSON blob from API %s %#v does not look like a =v1.21 API stats structure", apiVersion, statsJSONBlob)) - } - }(i) - } - wg.Wait() -} - -func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats { - var st *types.StatsJSON - - _, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "") - c.Assert(err, checker.IsNil) - - err = json.NewDecoder(body).Decode(&st) - c.Assert(err, checker.IsNil) - body.Close() - - return st.Networks -} - -// getVersionedStats returns stats result for the -// container with id using an API call with version apiVersion. Since the -// stats result type differs between API versions, we simply return -// map[string]interface{}. -func getVersionedStats(c *check.C, id string, apiVersion string) map[string]interface{} { - stats := make(map[string]interface{}) - - _, body, err := sockRequestRaw("GET", fmt.Sprintf("/%s/containers/%s/stats?stream=false", apiVersion, id), nil, "") - c.Assert(err, checker.IsNil) - defer body.Close() - - err = json.NewDecoder(body).Decode(&stats) - c.Assert(err, checker.IsNil, check.Commentf("failed to decode stat: %s", err)) - - return stats -} - -func jsonBlobHasLTv121NetworkStats(blob map[string]interface{}) bool { - networkStatsIntfc, ok := blob["network"] - if !ok { - return false - } - networkStats, ok := networkStatsIntfc.(map[string]interface{}) - if !ok { - return false - } - for _, expectedKey := range expectedNetworkInterfaceStats { - if _, ok := networkStats[expectedKey]; !ok { - return false - } - } - return true -} - -func jsonBlobHasGTE121NetworkStats(blob map[string]interface{}) bool { - networksStatsIntfc, ok := blob["networks"] - if !ok { - return false - } - networksStats, ok := networksStatsIntfc.(map[string]interface{}) - if !ok { - return false - } - for _, networkInterfaceStatsIntfc := range networksStats { - networkInterfaceStats, ok := networkInterfaceStatsIntfc.(map[string]interface{}) - if !ok { - return false - } - for _, expectedKey := range expectedNetworkInterfaceStats { - if _, ok := networkInterfaceStats[expectedKey]; !ok { - return false - } - } - } - return true -} - -func (s *DockerSuite) TestAPIStatsContainerNotFound(c *check.C) { - testRequires(c, DaemonIsLinux) - - status, _, err := sockRequest("GET", "/containers/nonexistent/stats", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNotFound) - - status, _, err = sockRequest("GET", "/containers/nonexistent/stats?stream=0", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNotFound) -} - -func (s *DockerSuite) TestAPIStatsNoStreamConnectedContainers(c *check.C) { - testRequires(c, DaemonIsLinux) - - out1, _ := runSleepingContainer(c) - id1 := strings.TrimSpace(out1) - c.Assert(waitRun(id1), checker.IsNil) - - out2, _ := runSleepingContainer(c, "--net", "container:"+id1) - id2 := strings.TrimSpace(out2) - c.Assert(waitRun(id2), checker.IsNil) - - ch := make(chan error) - go func() { - resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id2), nil, "") - defer body.Close() - if err != nil { - ch <- err - } - if resp.StatusCode != http.StatusOK { - ch <- fmt.Errorf("Invalid StatusCode %v", resp.StatusCode) - } - if resp.Header.Get("Content-Type") != "application/json" { - ch <- fmt.Errorf("Invalid 'Content-Type' %v", resp.Header.Get("Content-Type")) - } - var v *types.Stats - if err := json.NewDecoder(body).Decode(&v); err != nil { - ch <- err - } - ch <- nil - }() - - select { - case err := <-ch: - c.Assert(err, checker.IsNil, check.Commentf("Error in stats Engine API: %v", err)) - case <-time.After(15 * time.Second): - c.Fatalf("Stats did not return after timeout") - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_stats_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_stats_unix_test.go deleted file mode 100644 index 0995ce3..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_stats_unix_test.go +++ /dev/null @@ -1,41 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "fmt" - "net/http" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestAPIStatsContainerGetMemoryLimit(c *check.C) { - testRequires(c, DaemonIsLinux, memoryLimitSupport) - - resp, body, err := sockRequestRaw("GET", "/info", nil, "application/json") - c.Assert(err, checker.IsNil) - c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) - var info types.Info - err = json.NewDecoder(body).Decode(&info) - c.Assert(err, checker.IsNil) - body.Close() - - // don't set a memory limit, the memory limit should be system memory - conName := "foo" - dockerCmd(c, "run", "-d", "--name", conName, "busybox", "top") - c.Assert(waitRun(conName), checker.IsNil) - - resp, body, err = sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", conName), nil, "") - c.Assert(err, checker.IsNil) - c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) - c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json") - - var v *types.Stats - err = json.NewDecoder(body).Decode(&v) - c.Assert(err, checker.IsNil) - body.Close() - c.Assert(fmt.Sprintf("%d", v.MemoryStats.Limit), checker.Equals, fmt.Sprintf("%d", info.MemTotal)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_swarm_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_swarm_test.go deleted file mode 100644 index 1f8eaec..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_swarm_test.go +++ /dev/null @@ -1,1367 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "fmt" - "net/http" - "os" - "path/filepath" - "strconv" - "strings" - "sync" - "syscall" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -var defaultReconciliationTimeout = 30 * time.Second - -func (s *DockerSwarmSuite) TestAPISwarmInit(c *check.C) { - // todo: should find a better way to verify that components are running than /info - d1 := s.AddDaemon(c, true, true) - info, err := d1.info() - c.Assert(err, checker.IsNil) - c.Assert(info.ControlAvailable, checker.True) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - - d2 := s.AddDaemon(c, true, false) - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.ControlAvailable, checker.False) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - - // Leaving cluster - c.Assert(d2.Leave(false), checker.IsNil) - - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.ControlAvailable, checker.False) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive) - - c.Assert(d2.Join(swarm.JoinRequest{JoinToken: d1.joinTokens(c).Worker, RemoteAddrs: []string{d1.listenAddr}}), checker.IsNil) - - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.ControlAvailable, checker.False) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - - // Current state restoring after restarts - err = d1.Stop() - c.Assert(err, checker.IsNil) - err = d2.Stop() - c.Assert(err, checker.IsNil) - - err = d1.Start() - c.Assert(err, checker.IsNil) - err = d2.Start() - c.Assert(err, checker.IsNil) - - info, err = d1.info() - c.Assert(err, checker.IsNil) - c.Assert(info.ControlAvailable, checker.True) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.ControlAvailable, checker.False) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) -} - -func (s *DockerSwarmSuite) TestAPISwarmJoinToken(c *check.C) { - d1 := s.AddDaemon(c, false, false) - c.Assert(d1.Init(swarm.InitRequest{}), checker.IsNil) - - d2 := s.AddDaemon(c, false, false) - err := d2.Join(swarm.JoinRequest{RemoteAddrs: []string{d1.listenAddr}}) - c.Assert(err, checker.NotNil) - c.Assert(err.Error(), checker.Contains, "join token is necessary") - info, err := d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive) - - err = d2.Join(swarm.JoinRequest{JoinToken: "foobaz", RemoteAddrs: []string{d1.listenAddr}}) - c.Assert(err, checker.NotNil) - c.Assert(err.Error(), checker.Contains, "join token is necessary") - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive) - - workerToken := d1.joinTokens(c).Worker - - c.Assert(d2.Join(swarm.JoinRequest{JoinToken: workerToken, RemoteAddrs: []string{d1.listenAddr}}), checker.IsNil) - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - c.Assert(d2.Leave(false), checker.IsNil) - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive) - - // change tokens - d1.rotateTokens(c) - - err = d2.Join(swarm.JoinRequest{JoinToken: workerToken, RemoteAddrs: []string{d1.listenAddr}}) - c.Assert(err, checker.NotNil) - c.Assert(err.Error(), checker.Contains, "join token is necessary") - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive) - - workerToken = d1.joinTokens(c).Worker - - c.Assert(d2.Join(swarm.JoinRequest{JoinToken: workerToken, RemoteAddrs: []string{d1.listenAddr}}), checker.IsNil) - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - c.Assert(d2.Leave(false), checker.IsNil) - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive) - - // change spec, don't change tokens - d1.updateSwarm(c, func(s *swarm.Spec) {}) - - err = d2.Join(swarm.JoinRequest{RemoteAddrs: []string{d1.listenAddr}}) - c.Assert(err, checker.NotNil) - c.Assert(err.Error(), checker.Contains, "join token is necessary") - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive) - - c.Assert(d2.Join(swarm.JoinRequest{JoinToken: workerToken, RemoteAddrs: []string{d1.listenAddr}}), checker.IsNil) - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - c.Assert(d2.Leave(false), checker.IsNil) - info, err = d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive) -} - -func (s *DockerSwarmSuite) TestAPISwarmCAHash(c *check.C) { - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, false, false) - splitToken := strings.Split(d1.joinTokens(c).Worker, "-") - splitToken[2] = "1kxftv4ofnc6mt30lmgipg6ngf9luhwqopfk1tz6bdmnkubg0e" - replacementToken := strings.Join(splitToken, "-") - err := d2.Join(swarm.JoinRequest{JoinToken: replacementToken, RemoteAddrs: []string{d1.listenAddr}}) - c.Assert(err, checker.NotNil) - c.Assert(err.Error(), checker.Contains, "remote CA does not match fingerprint") -} - -func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *check.C) { - d1 := s.AddDaemon(c, false, false) - c.Assert(d1.Init(swarm.InitRequest{}), checker.IsNil) - d2 := s.AddDaemon(c, true, false) - - info, err := d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.ControlAvailable, checker.False) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - - d1.updateNode(c, d2.NodeID, func(n *swarm.Node) { - n.Spec.Role = swarm.NodeRoleManager - }) - - waitAndAssert(c, defaultReconciliationTimeout, d2.checkControlAvailable, checker.True) - - d1.updateNode(c, d2.NodeID, func(n *swarm.Node) { - n.Spec.Role = swarm.NodeRoleWorker - }) - - waitAndAssert(c, defaultReconciliationTimeout, d2.checkControlAvailable, checker.False) - - // Demoting last node should fail - node := d1.getNode(c, d1.NodeID) - node.Spec.Role = swarm.NodeRoleWorker - url := fmt.Sprintf("/nodes/%s/update?version=%d", node.ID, node.Version.Index) - status, out, err := d1.SockRequest("POST", url, node.Spec) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError, check.Commentf("output: %q", string(out))) - c.Assert(string(out), checker.Contains, "last manager of the swarm") - info, err = d1.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - c.Assert(info.ControlAvailable, checker.True) - - // Promote already demoted node - d1.updateNode(c, d2.NodeID, func(n *swarm.Node) { - n.Spec.Role = swarm.NodeRoleManager - }) - - waitAndAssert(c, defaultReconciliationTimeout, d2.checkControlAvailable, checker.True) -} - -func (s *DockerSwarmSuite) TestAPISwarmServicesEmptyList(c *check.C) { - d := s.AddDaemon(c, true, true) - - services := d.listServices(c) - c.Assert(services, checker.NotNil) - c.Assert(len(services), checker.Equals, 0, check.Commentf("services: %#v", services)) -} - -func (s *DockerSwarmSuite) TestAPISwarmServicesCreate(c *check.C) { - d := s.AddDaemon(c, true, true) - - instances := 2 - id := d.createService(c, simpleTestService, setInstances(instances)) - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, instances) - - service := d.getService(c, id) - instances = 5 - d.updateService(c, service, setInstances(instances)) - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, instances) - - d.removeService(c, service.ID) - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 0) -} - -func (s *DockerSwarmSuite) TestAPISwarmServicesMultipleAgents(c *check.C) { - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, false) - d3 := s.AddDaemon(c, true, false) - - time.Sleep(1 * time.Second) // make sure all daemons are ready to accept tasks - - instances := 9 - id := d1.createService(c, simpleTestService, setInstances(instances)) - - waitAndAssert(c, defaultReconciliationTimeout, d1.checkActiveContainerCount, checker.GreaterThan, 0) - waitAndAssert(c, defaultReconciliationTimeout, d2.checkActiveContainerCount, checker.GreaterThan, 0) - waitAndAssert(c, defaultReconciliationTimeout, d3.checkActiveContainerCount, checker.GreaterThan, 0) - - waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d2.checkActiveContainerCount, d3.checkActiveContainerCount), checker.Equals, instances) - - // reconciliation on d2 node down - c.Assert(d2.Stop(), checker.IsNil) - - waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d3.checkActiveContainerCount), checker.Equals, instances) - - // test downscaling - instances = 5 - d1.updateService(c, d1.getService(c, id), setInstances(instances)) - waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d3.checkActiveContainerCount), checker.Equals, instances) - -} - -func (s *DockerSwarmSuite) TestAPISwarmServicesCreateGlobal(c *check.C) { - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, false) - d3 := s.AddDaemon(c, true, false) - - d1.createService(c, simpleTestService, setGlobalMode) - - waitAndAssert(c, defaultReconciliationTimeout, d1.checkActiveContainerCount, checker.Equals, 1) - waitAndAssert(c, defaultReconciliationTimeout, d2.checkActiveContainerCount, checker.Equals, 1) - waitAndAssert(c, defaultReconciliationTimeout, d3.checkActiveContainerCount, checker.Equals, 1) - - d4 := s.AddDaemon(c, true, false) - d5 := s.AddDaemon(c, true, false) - - waitAndAssert(c, defaultReconciliationTimeout, d4.checkActiveContainerCount, checker.Equals, 1) - waitAndAssert(c, defaultReconciliationTimeout, d5.checkActiveContainerCount, checker.Equals, 1) -} - -func (s *DockerSwarmSuite) TestAPISwarmServicesUpdate(c *check.C) { - const nodeCount = 3 - var daemons [nodeCount]*SwarmDaemon - for i := 0; i < nodeCount; i++ { - daemons[i] = s.AddDaemon(c, true, i == 0) - } - // wait for nodes ready - waitAndAssert(c, 5*time.Second, daemons[0].checkNodeReadyCount, checker.Equals, nodeCount) - - // service image at start - image1 := "busybox:latest" - // target image in update - image2 := "busybox:test" - - // create a different tag - for _, d := range daemons { - out, err := d.Cmd("tag", image1, image2) - c.Assert(err, checker.IsNil, check.Commentf(out)) - } - - // create service - instances := 5 - parallelism := 2 - id := daemons[0].createService(c, serviceForUpdate, setInstances(instances)) - - // wait for tasks ready - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkRunningTaskImages, checker.DeepEquals, - map[string]int{image1: instances}) - - // issue service update - service := daemons[0].getService(c, id) - daemons[0].updateService(c, service, setImage(image2)) - - // first batch - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkRunningTaskImages, checker.DeepEquals, - map[string]int{image1: instances - parallelism, image2: parallelism}) - - // 2nd batch - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkRunningTaskImages, checker.DeepEquals, - map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism}) - - // 3nd batch - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkRunningTaskImages, checker.DeepEquals, - map[string]int{image2: instances}) - - // Roll back to the previous version. This uses the CLI because - // rollback is a client-side operation. - out, err := daemons[0].Cmd("service", "update", "--rollback", id) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // first batch - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkRunningTaskImages, checker.DeepEquals, - map[string]int{image2: instances - parallelism, image1: parallelism}) - - // 2nd batch - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkRunningTaskImages, checker.DeepEquals, - map[string]int{image2: instances - 2*parallelism, image1: 2 * parallelism}) - - // 3nd batch - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkRunningTaskImages, checker.DeepEquals, - map[string]int{image1: instances}) -} - -func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *check.C) { - const nodeCount = 3 - var daemons [nodeCount]*SwarmDaemon - for i := 0; i < nodeCount; i++ { - daemons[i] = s.AddDaemon(c, true, i == 0) - } - // wait for nodes ready - waitAndAssert(c, 5*time.Second, daemons[0].checkNodeReadyCount, checker.Equals, nodeCount) - - // service image at start - image1 := "busybox:latest" - // target image in update - image2 := "busybox:badtag" - - // create service - instances := 5 - id := daemons[0].createService(c, serviceForUpdate, setInstances(instances)) - - // wait for tasks ready - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkRunningTaskImages, checker.DeepEquals, - map[string]int{image1: instances}) - - // issue service update - service := daemons[0].getService(c, id) - daemons[0].updateService(c, service, setImage(image2), setFailureAction(swarm.UpdateFailureActionPause), setMaxFailureRatio(0.25), setParallelism(1)) - - // should update 2 tasks and then pause - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkServiceUpdateState(id), checker.Equals, swarm.UpdateStatePaused) - v, _ := daemons[0].checkServiceRunningTasks(id)(c) - c.Assert(v, checker.Equals, instances-2) - - // Roll back to the previous version. This uses the CLI because - // rollback is a client-side operation. - out, err := daemons[0].Cmd("service", "update", "--rollback", id) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkRunningTaskImages, checker.DeepEquals, - map[string]int{image1: instances}) -} - -func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *check.C) { - const nodeCount = 3 - var daemons [nodeCount]*SwarmDaemon - for i := 0; i < nodeCount; i++ { - daemons[i] = s.AddDaemon(c, true, i == 0) - } - // wait for nodes ready - waitAndAssert(c, 5*time.Second, daemons[0].checkNodeReadyCount, checker.Equals, nodeCount) - - // create service - constraints := []string{"node.role==worker"} - instances := 3 - id := daemons[0].createService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) - // wait for tasks ready - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkServiceRunningTasks(id), checker.Equals, instances) - // validate tasks are running on worker nodes - tasks := daemons[0].getServiceTasks(c, id) - for _, task := range tasks { - node := daemons[0].getNode(c, task.NodeID) - c.Assert(node.Spec.Role, checker.Equals, swarm.NodeRoleWorker) - } - //remove service - daemons[0].removeService(c, id) - - // create service - constraints = []string{"node.role!=worker"} - id = daemons[0].createService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) - // wait for tasks ready - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkServiceRunningTasks(id), checker.Equals, instances) - tasks = daemons[0].getServiceTasks(c, id) - // validate tasks are running on manager nodes - for _, task := range tasks { - node := daemons[0].getNode(c, task.NodeID) - c.Assert(node.Spec.Role, checker.Equals, swarm.NodeRoleManager) - } - //remove service - daemons[0].removeService(c, id) - - // create service - constraints = []string{"node.role==nosuchrole"} - id = daemons[0].createService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) - // wait for tasks created - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkServiceTasks(id), checker.Equals, instances) - // let scheduler try - time.Sleep(250 * time.Millisecond) - // validate tasks are not assigned to any node - tasks = daemons[0].getServiceTasks(c, id) - for _, task := range tasks { - c.Assert(task.NodeID, checker.Equals, "") - } -} - -func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *check.C) { - const nodeCount = 3 - var daemons [nodeCount]*SwarmDaemon - for i := 0; i < nodeCount; i++ { - daemons[i] = s.AddDaemon(c, true, i == 0) - } - // wait for nodes ready - waitAndAssert(c, 5*time.Second, daemons[0].checkNodeReadyCount, checker.Equals, nodeCount) - nodes := daemons[0].listNodes(c) - c.Assert(len(nodes), checker.Equals, nodeCount) - - // add labels to nodes - daemons[0].updateNode(c, nodes[0].ID, func(n *swarm.Node) { - n.Spec.Annotations.Labels = map[string]string{ - "security": "high", - } - }) - for i := 1; i < nodeCount; i++ { - daemons[0].updateNode(c, nodes[i].ID, func(n *swarm.Node) { - n.Spec.Annotations.Labels = map[string]string{ - "security": "low", - } - }) - } - - // create service - instances := 3 - constraints := []string{"node.labels.security==high"} - id := daemons[0].createService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) - // wait for tasks ready - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkServiceRunningTasks(id), checker.Equals, instances) - tasks := daemons[0].getServiceTasks(c, id) - // validate all tasks are running on nodes[0] - for _, task := range tasks { - c.Assert(task.NodeID, checker.Equals, nodes[0].ID) - } - //remove service - daemons[0].removeService(c, id) - - // create service - constraints = []string{"node.labels.security!=high"} - id = daemons[0].createService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) - // wait for tasks ready - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkServiceRunningTasks(id), checker.Equals, instances) - tasks = daemons[0].getServiceTasks(c, id) - // validate all tasks are NOT running on nodes[0] - for _, task := range tasks { - c.Assert(task.NodeID, checker.Not(checker.Equals), nodes[0].ID) - } - //remove service - daemons[0].removeService(c, id) - - constraints = []string{"node.labels.security==medium"} - id = daemons[0].createService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) - // wait for tasks created - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkServiceTasks(id), checker.Equals, instances) - // let scheduler try - time.Sleep(250 * time.Millisecond) - tasks = daemons[0].getServiceTasks(c, id) - // validate tasks are not assigned - for _, task := range tasks { - c.Assert(task.NodeID, checker.Equals, "") - } - //remove service - daemons[0].removeService(c, id) - - // multiple constraints - constraints = []string{ - "node.labels.security==high", - fmt.Sprintf("node.id==%s", nodes[1].ID), - } - id = daemons[0].createService(c, simpleTestService, setConstraints(constraints), setInstances(instances)) - // wait for tasks created - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkServiceTasks(id), checker.Equals, instances) - // let scheduler try - time.Sleep(250 * time.Millisecond) - tasks = daemons[0].getServiceTasks(c, id) - // validate tasks are not assigned - for _, task := range tasks { - c.Assert(task.NodeID, checker.Equals, "") - } - // make nodes[1] fulfills the constraints - daemons[0].updateNode(c, nodes[1].ID, func(n *swarm.Node) { - n.Spec.Annotations.Labels = map[string]string{ - "security": "high", - } - }) - // wait for tasks ready - waitAndAssert(c, defaultReconciliationTimeout, daemons[0].checkServiceRunningTasks(id), checker.Equals, instances) - tasks = daemons[0].getServiceTasks(c, id) - for _, task := range tasks { - c.Assert(task.NodeID, checker.Equals, nodes[1].ID) - } -} - -func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *check.C) { - testRequires(c, SameHostDaemon) - testRequires(c, DaemonIsLinux) - - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, true) - d3 := s.AddDaemon(c, true, false) - - time.Sleep(1 * time.Second) // make sure all daemons are ready to accept - - instances := 9 - d1.createService(c, simpleTestService, setInstances(instances)) - - waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d2.checkActiveContainerCount, d3.checkActiveContainerCount), checker.Equals, instances) - - getContainers := func() map[string]*SwarmDaemon { - m := make(map[string]*SwarmDaemon) - for _, d := range []*SwarmDaemon{d1, d2, d3} { - for _, id := range d.activeContainers() { - m[id] = d - } - } - return m - } - - containers := getContainers() - c.Assert(containers, checker.HasLen, instances) - var toRemove string - for i := range containers { - toRemove = i - } - - _, err := containers[toRemove].Cmd("stop", toRemove) - c.Assert(err, checker.IsNil) - - waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d2.checkActiveContainerCount, d3.checkActiveContainerCount), checker.Equals, instances) - - containers2 := getContainers() - c.Assert(containers2, checker.HasLen, instances) - for i := range containers { - if i == toRemove { - c.Assert(containers2[i], checker.IsNil) - } else { - c.Assert(containers2[i], checker.NotNil) - } - } - - containers = containers2 - for i := range containers { - toRemove = i - } - - // try with killing process outside of docker - pidStr, err := containers[toRemove].Cmd("inspect", "-f", "{{.State.Pid}}", toRemove) - c.Assert(err, checker.IsNil) - pid, err := strconv.Atoi(strings.TrimSpace(pidStr)) - c.Assert(err, checker.IsNil) - c.Assert(syscall.Kill(pid, syscall.SIGKILL), checker.IsNil) - - time.Sleep(time.Second) // give some time to handle the signal - - waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d2.checkActiveContainerCount, d3.checkActiveContainerCount), checker.Equals, instances) - - containers2 = getContainers() - c.Assert(containers2, checker.HasLen, instances) - for i := range containers { - if i == toRemove { - c.Assert(containers2[i], checker.IsNil) - } else { - c.Assert(containers2[i], checker.NotNil) - } - } -} - -func (s *DockerSwarmSuite) TestAPISwarmLeaderProxy(c *check.C) { - // add three managers, one of these is leader - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, true) - d3 := s.AddDaemon(c, true, true) - - // start a service by hitting each of the 3 managers - d1.createService(c, simpleTestService, func(s *swarm.Service) { - s.Spec.Name = "test1" - }) - d2.createService(c, simpleTestService, func(s *swarm.Service) { - s.Spec.Name = "test2" - }) - d3.createService(c, simpleTestService, func(s *swarm.Service) { - s.Spec.Name = "test3" - }) - - // 3 services should be started now, because the requests were proxied to leader - // query each node and make sure it returns 3 services - for _, d := range []*SwarmDaemon{d1, d2, d3} { - services := d.listServices(c) - c.Assert(services, checker.HasLen, 3) - } -} - -func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *check.C) { - // Create 3 nodes - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, true) - d3 := s.AddDaemon(c, true, true) - - // assert that the first node we made is the leader, and the other two are followers - c.Assert(d1.getNode(c, d1.NodeID).ManagerStatus.Leader, checker.True) - c.Assert(d1.getNode(c, d2.NodeID).ManagerStatus.Leader, checker.False) - c.Assert(d1.getNode(c, d3.NodeID).ManagerStatus.Leader, checker.False) - - d1.Stop() // stop the leader - - var ( - leader *SwarmDaemon // keep track of leader - followers []*SwarmDaemon // keep track of followers - ) - checkLeader := func(nodes ...*SwarmDaemon) checkF { - return func(c *check.C) (interface{}, check.CommentInterface) { - // clear these out before each run - leader = nil - followers = nil - for _, d := range nodes { - if d.getNode(c, d.NodeID).ManagerStatus.Leader { - leader = d - } else { - followers = append(followers, d) - } - } - - if leader == nil { - return false, check.Commentf("no leader elected") - } - - return true, check.Commentf("elected %v", leader.id) - } - } - - // wait for an election to occur - waitAndAssert(c, defaultReconciliationTimeout, checkLeader(d2, d3), checker.True) - - // assert that we have a new leader - c.Assert(leader, checker.NotNil) - - // Keep track of the current leader, since we want that to be chosen. - stableleader := leader - - // add the d1, the initial leader, back - d1.Start() - - // TODO(stevvooe): may need to wait for rejoin here - - // wait for possible election - waitAndAssert(c, defaultReconciliationTimeout, checkLeader(d1, d2, d3), checker.True) - // pick out the leader and the followers again - - // verify that we still only have 1 leader and 2 followers - c.Assert(leader, checker.NotNil) - c.Assert(followers, checker.HasLen, 2) - // and that after we added d1 back, the leader hasn't changed - c.Assert(leader.NodeID, checker.Equals, stableleader.NodeID) -} - -func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *check.C) { - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, true) - d3 := s.AddDaemon(c, true, true) - - d1.createService(c, simpleTestService) - - c.Assert(d2.Stop(), checker.IsNil) - - // make sure there is a leader - waitAndAssert(c, defaultReconciliationTimeout, d1.checkLeader, checker.IsNil) - - d1.createService(c, simpleTestService, func(s *swarm.Service) { - s.Spec.Name = "top1" - }) - - c.Assert(d3.Stop(), checker.IsNil) - - // make sure there is a leader - waitAndAssert(c, defaultReconciliationTimeout, d1.checkLeader, checker.IsNil) - - var service swarm.Service - simpleTestService(&service) - service.Spec.Name = "top2" - status, out, err := d1.SockRequest("POST", "/services/create", service.Spec) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError, check.Commentf("deadline exceeded", string(out))) - - c.Assert(d2.Start(), checker.IsNil) - - // make sure there is a leader - waitAndAssert(c, defaultReconciliationTimeout, d1.checkLeader, checker.IsNil) - - d1.createService(c, simpleTestService, func(s *swarm.Service) { - s.Spec.Name = "top3" - }) -} - -func (s *DockerSwarmSuite) TestAPISwarmListNodes(c *check.C) { - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, false) - d3 := s.AddDaemon(c, true, false) - - nodes := d1.listNodes(c) - c.Assert(len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes)) - -loop0: - for _, n := range nodes { - for _, d := range []*SwarmDaemon{d1, d2, d3} { - if n.ID == d.NodeID { - continue loop0 - } - } - c.Errorf("unknown nodeID %v", n.ID) - } -} - -func (s *DockerSwarmSuite) TestAPISwarmNodeUpdate(c *check.C) { - d := s.AddDaemon(c, true, true) - - nodes := d.listNodes(c) - - d.updateNode(c, nodes[0].ID, func(n *swarm.Node) { - n.Spec.Availability = swarm.NodeAvailabilityPause - }) - - n := d.getNode(c, nodes[0].ID) - c.Assert(n.Spec.Availability, checker.Equals, swarm.NodeAvailabilityPause) -} - -func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *check.C) { - testRequires(c, Network) - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, false) - _ = s.AddDaemon(c, true, false) - - nodes := d1.listNodes(c) - c.Assert(len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes)) - - // Getting the info so we can take the NodeID - d2Info, err := d2.info() - c.Assert(err, checker.IsNil) - - // forceful removal of d2 should work - d1.removeNode(c, d2Info.NodeID, true) - - nodes = d1.listNodes(c) - c.Assert(len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes)) - - // Restart the node that was removed - err = d2.Restart() - c.Assert(err, checker.IsNil) - - // Give some time for the node to rejoin - time.Sleep(1 * time.Second) - - // Make sure the node didn't rejoin - nodes = d1.listNodes(c) - c.Assert(len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes)) -} - -func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *check.C) { - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, false) - - time.Sleep(1 * time.Second) // make sure all daemons are ready to accept tasks - - // start a service, expect balanced distribution - instances := 8 - id := d1.createService(c, simpleTestService, setInstances(instances)) - - waitAndAssert(c, defaultReconciliationTimeout, d1.checkActiveContainerCount, checker.GreaterThan, 0) - waitAndAssert(c, defaultReconciliationTimeout, d2.checkActiveContainerCount, checker.GreaterThan, 0) - waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d2.checkActiveContainerCount), checker.Equals, instances) - - // drain d2, all containers should move to d1 - d1.updateNode(c, d2.NodeID, func(n *swarm.Node) { - n.Spec.Availability = swarm.NodeAvailabilityDrain - }) - waitAndAssert(c, defaultReconciliationTimeout, d1.checkActiveContainerCount, checker.Equals, instances) - waitAndAssert(c, defaultReconciliationTimeout, d2.checkActiveContainerCount, checker.Equals, 0) - - // set d2 back to active - d1.updateNode(c, d2.NodeID, func(n *swarm.Node) { - n.Spec.Availability = swarm.NodeAvailabilityActive - }) - - instances = 1 - d1.updateService(c, d1.getService(c, id), setInstances(instances)) - - waitAndAssert(c, defaultReconciliationTimeout*2, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d2.checkActiveContainerCount), checker.Equals, instances) - - instances = 8 - d1.updateService(c, d1.getService(c, id), setInstances(instances)) - - // drained node first so we don't get any old containers - waitAndAssert(c, defaultReconciliationTimeout, d2.checkActiveContainerCount, checker.GreaterThan, 0) - waitAndAssert(c, defaultReconciliationTimeout, d1.checkActiveContainerCount, checker.GreaterThan, 0) - waitAndAssert(c, defaultReconciliationTimeout*2, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d2.checkActiveContainerCount), checker.Equals, instances) - - d2ContainerCount := len(d2.activeContainers()) - - // set d2 to paused, scale service up, only d1 gets new tasks - d1.updateNode(c, d2.NodeID, func(n *swarm.Node) { - n.Spec.Availability = swarm.NodeAvailabilityPause - }) - - instances = 14 - d1.updateService(c, d1.getService(c, id), setInstances(instances)) - - waitAndAssert(c, defaultReconciliationTimeout, d1.checkActiveContainerCount, checker.Equals, instances-d2ContainerCount) - waitAndAssert(c, defaultReconciliationTimeout, d2.checkActiveContainerCount, checker.Equals, d2ContainerCount) - -} - -func (s *DockerSwarmSuite) TestAPISwarmLeaveRemovesContainer(c *check.C) { - d := s.AddDaemon(c, true, true) - - instances := 2 - d.createService(c, simpleTestService, setInstances(instances)) - - id, err := d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, checker.IsNil) - id = strings.TrimSpace(id) - - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, instances+1) - - c.Assert(d.Leave(false), checker.NotNil) - c.Assert(d.Leave(true), checker.IsNil) - - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - id2, err := d.Cmd("ps", "-q") - c.Assert(err, checker.IsNil) - c.Assert(id, checker.HasPrefix, strings.TrimSpace(id2)) -} - -// #23629 -func (s *DockerSwarmSuite) TestAPISwarmLeaveOnPendingJoin(c *check.C) { - testRequires(c, Network) - s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, false, false) - - id, err := d2.Cmd("run", "-d", "busybox", "top") - c.Assert(err, checker.IsNil) - id = strings.TrimSpace(id) - - err = d2.Join(swarm.JoinRequest{ - RemoteAddrs: []string{"123.123.123.123:1234"}, - }) - c.Assert(err, check.NotNil) - c.Assert(err.Error(), checker.Contains, "Timeout was reached") - - info, err := d2.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStatePending) - - c.Assert(d2.Leave(true), checker.IsNil) - - waitAndAssert(c, defaultReconciliationTimeout, d2.checkActiveContainerCount, checker.Equals, 1) - - id2, err := d2.Cmd("ps", "-q") - c.Assert(err, checker.IsNil) - c.Assert(id, checker.HasPrefix, strings.TrimSpace(id2)) -} - -// #23705 -func (s *DockerSwarmSuite) TestAPISwarmRestoreOnPendingJoin(c *check.C) { - testRequires(c, Network) - d := s.AddDaemon(c, false, false) - err := d.Join(swarm.JoinRequest{ - RemoteAddrs: []string{"123.123.123.123:1234"}, - }) - c.Assert(err, check.NotNil) - c.Assert(err.Error(), checker.Contains, "Timeout was reached") - - waitAndAssert(c, defaultReconciliationTimeout, d.checkLocalNodeState, checker.Equals, swarm.LocalNodeStatePending) - - c.Assert(d.Stop(), checker.IsNil) - c.Assert(d.Start(), checker.IsNil) - - info, err := d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive) -} - -func (s *DockerSwarmSuite) TestAPISwarmManagerRestore(c *check.C) { - d1 := s.AddDaemon(c, true, true) - - instances := 2 - id := d1.createService(c, simpleTestService, setInstances(instances)) - - d1.getService(c, id) - d1.Stop() - d1.Start() - d1.getService(c, id) - - d2 := s.AddDaemon(c, true, true) - d2.getService(c, id) - d2.Stop() - d2.Start() - d2.getService(c, id) - - d3 := s.AddDaemon(c, true, true) - d3.getService(c, id) - d3.Stop() - d3.Start() - d3.getService(c, id) - - d3.Kill() - time.Sleep(1 * time.Second) // time to handle signal - d3.Start() - d3.getService(c, id) -} - -func (s *DockerSwarmSuite) TestAPISwarmScaleNoRollingUpdate(c *check.C) { - d := s.AddDaemon(c, true, true) - - instances := 2 - id := d.createService(c, simpleTestService, setInstances(instances)) - - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, instances) - containers := d.activeContainers() - instances = 4 - d.updateService(c, d.getService(c, id), setInstances(instances)) - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, instances) - containers2 := d.activeContainers() - -loop0: - for _, c1 := range containers { - for _, c2 := range containers2 { - if c1 == c2 { - continue loop0 - } - } - c.Errorf("container %v not found in new set %#v", c1, containers2) - } -} - -func (s *DockerSwarmSuite) TestAPISwarmInvalidAddress(c *check.C) { - d := s.AddDaemon(c, false, false) - req := swarm.InitRequest{ - ListenAddr: "", - } - status, _, err := d.SockRequest("POST", "/swarm/init", req) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) - - req2 := swarm.JoinRequest{ - ListenAddr: "0.0.0.0:2377", - RemoteAddrs: []string{""}, - } - status, _, err = d.SockRequest("POST", "/swarm/join", req2) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) -} - -func (s *DockerSwarmSuite) TestAPISwarmForceNewCluster(c *check.C) { - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, true) - - instances := 2 - id := d1.createService(c, simpleTestService, setInstances(instances)) - waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d2.checkActiveContainerCount), checker.Equals, instances) - - // drain d2, all containers should move to d1 - d1.updateNode(c, d2.NodeID, func(n *swarm.Node) { - n.Spec.Availability = swarm.NodeAvailabilityDrain - }) - waitAndAssert(c, defaultReconciliationTimeout, d1.checkActiveContainerCount, checker.Equals, instances) - waitAndAssert(c, defaultReconciliationTimeout, d2.checkActiveContainerCount, checker.Equals, 0) - - c.Assert(d2.Stop(), checker.IsNil) - - c.Assert(d1.Init(swarm.InitRequest{ - ForceNewCluster: true, - Spec: swarm.Spec{}, - }), checker.IsNil) - - waitAndAssert(c, defaultReconciliationTimeout, d1.checkActiveContainerCount, checker.Equals, instances) - - d3 := s.AddDaemon(c, true, true) - info, err := d3.info() - c.Assert(err, checker.IsNil) - c.Assert(info.ControlAvailable, checker.True) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - - instances = 4 - d3.updateService(c, d3.getService(c, id), setInstances(instances)) - - waitAndAssert(c, defaultReconciliationTimeout, reducedCheck(sumAsIntegers, d1.checkActiveContainerCount, d3.checkActiveContainerCount), checker.Equals, instances) -} - -func simpleTestService(s *swarm.Service) { - ureplicas := uint64(1) - restartDelay := time.Duration(100 * time.Millisecond) - - s.Spec = swarm.ServiceSpec{ - TaskTemplate: swarm.TaskSpec{ - ContainerSpec: swarm.ContainerSpec{ - Image: "busybox:latest", - Command: []string{"/bin/top"}, - }, - RestartPolicy: &swarm.RestartPolicy{ - Delay: &restartDelay, - }, - }, - Mode: swarm.ServiceMode{ - Replicated: &swarm.ReplicatedService{ - Replicas: &ureplicas, - }, - }, - } - s.Spec.Name = "top" -} - -func serviceForUpdate(s *swarm.Service) { - ureplicas := uint64(1) - restartDelay := time.Duration(100 * time.Millisecond) - - s.Spec = swarm.ServiceSpec{ - TaskTemplate: swarm.TaskSpec{ - ContainerSpec: swarm.ContainerSpec{ - Image: "busybox:latest", - Command: []string{"/bin/top"}, - }, - RestartPolicy: &swarm.RestartPolicy{ - Delay: &restartDelay, - }, - }, - Mode: swarm.ServiceMode{ - Replicated: &swarm.ReplicatedService{ - Replicas: &ureplicas, - }, - }, - UpdateConfig: &swarm.UpdateConfig{ - Parallelism: 2, - Delay: 4 * time.Second, - FailureAction: swarm.UpdateFailureActionContinue, - }, - } - s.Spec.Name = "updatetest" -} - -func setInstances(replicas int) serviceConstructor { - ureplicas := uint64(replicas) - return func(s *swarm.Service) { - s.Spec.Mode = swarm.ServiceMode{ - Replicated: &swarm.ReplicatedService{ - Replicas: &ureplicas, - }, - } - } -} - -func setImage(image string) serviceConstructor { - return func(s *swarm.Service) { - s.Spec.TaskTemplate.ContainerSpec.Image = image - } -} - -func setFailureAction(failureAction string) serviceConstructor { - return func(s *swarm.Service) { - s.Spec.UpdateConfig.FailureAction = failureAction - } -} - -func setMaxFailureRatio(maxFailureRatio float32) serviceConstructor { - return func(s *swarm.Service) { - s.Spec.UpdateConfig.MaxFailureRatio = maxFailureRatio - } -} - -func setParallelism(parallelism uint64) serviceConstructor { - return func(s *swarm.Service) { - s.Spec.UpdateConfig.Parallelism = parallelism - } -} - -func setConstraints(constraints []string) serviceConstructor { - return func(s *swarm.Service) { - if s.Spec.TaskTemplate.Placement == nil { - s.Spec.TaskTemplate.Placement = &swarm.Placement{} - } - s.Spec.TaskTemplate.Placement.Constraints = constraints - } -} - -func setGlobalMode(s *swarm.Service) { - s.Spec.Mode = swarm.ServiceMode{ - Global: &swarm.GlobalService{}, - } -} - -func checkClusterHealth(c *check.C, cl []*SwarmDaemon, managerCount, workerCount int) { - var totalMCount, totalWCount int - - for _, d := range cl { - var ( - info swarm.Info - err error - ) - - // check info in a waitAndAssert, because if the cluster doesn't have a leader, `info` will return an error - checkInfo := func(c *check.C) (interface{}, check.CommentInterface) { - info, err = d.info() - return err, check.Commentf("cluster not ready in time") - } - waitAndAssert(c, defaultReconciliationTimeout, checkInfo, checker.IsNil) - if !info.ControlAvailable { - totalWCount++ - continue - } - - var leaderFound bool - totalMCount++ - var mCount, wCount int - - for _, n := range d.listNodes(c) { - waitReady := func(c *check.C) (interface{}, check.CommentInterface) { - if n.Status.State == swarm.NodeStateReady { - return true, nil - } - nn := d.getNode(c, n.ID) - n = *nn - return n.Status.State == swarm.NodeStateReady, check.Commentf("state of node %s, reported by %s", n.ID, d.Info.NodeID) - } - waitAndAssert(c, defaultReconciliationTimeout, waitReady, checker.True) - - waitActive := func(c *check.C) (interface{}, check.CommentInterface) { - if n.Spec.Availability == swarm.NodeAvailabilityActive { - return true, nil - } - nn := d.getNode(c, n.ID) - n = *nn - return n.Spec.Availability == swarm.NodeAvailabilityActive, check.Commentf("availability of node %s, reported by %s", n.ID, d.Info.NodeID) - } - waitAndAssert(c, defaultReconciliationTimeout, waitActive, checker.True) - - if n.Spec.Role == swarm.NodeRoleManager { - c.Assert(n.ManagerStatus, checker.NotNil, check.Commentf("manager status of node %s (manager), reported by %s", n.ID, d.Info.NodeID)) - if n.ManagerStatus.Leader { - leaderFound = true - } - mCount++ - } else { - c.Assert(n.ManagerStatus, checker.IsNil, check.Commentf("manager status of node %s (worker), reported by %s", n.ID, d.Info.NodeID)) - wCount++ - } - } - c.Assert(leaderFound, checker.True, check.Commentf("lack of leader reported by node %s", info.NodeID)) - c.Assert(mCount, checker.Equals, managerCount, check.Commentf("managers count reported by node %s", info.NodeID)) - c.Assert(wCount, checker.Equals, workerCount, check.Commentf("workers count reported by node %s", info.NodeID)) - } - c.Assert(totalMCount, checker.Equals, managerCount) - c.Assert(totalWCount, checker.Equals, workerCount) -} - -func (s *DockerSwarmSuite) TestAPISwarmRestartCluster(c *check.C) { - mCount, wCount := 5, 1 - - var nodes []*SwarmDaemon - for i := 0; i < mCount; i++ { - manager := s.AddDaemon(c, true, true) - info, err := manager.info() - c.Assert(err, checker.IsNil) - c.Assert(info.ControlAvailable, checker.True) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - nodes = append(nodes, manager) - } - - for i := 0; i < wCount; i++ { - worker := s.AddDaemon(c, true, false) - info, err := worker.info() - c.Assert(err, checker.IsNil) - c.Assert(info.ControlAvailable, checker.False) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - nodes = append(nodes, worker) - } - - // stop whole cluster - { - var wg sync.WaitGroup - wg.Add(len(nodes)) - errs := make(chan error, len(nodes)) - - for _, d := range nodes { - go func(daemon *SwarmDaemon) { - defer wg.Done() - if err := daemon.Stop(); err != nil { - errs <- err - } - if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" { - daemon.root = filepath.Dir(daemon.root) - } - }(d) - } - wg.Wait() - close(errs) - for err := range errs { - c.Assert(err, check.IsNil) - } - } - - // start whole cluster - { - var wg sync.WaitGroup - wg.Add(len(nodes)) - errs := make(chan error, len(nodes)) - - for _, d := range nodes { - go func(daemon *SwarmDaemon) { - defer wg.Done() - if err := daemon.Start("--iptables=false"); err != nil { - errs <- err - } - }(d) - } - wg.Wait() - close(errs) - for err := range errs { - c.Assert(err, check.IsNil) - } - } - - checkClusterHealth(c, nodes, mCount, wCount) -} - -func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *check.C) { - d := s.AddDaemon(c, true, true) - - instances := 2 - id := d.createService(c, simpleTestService, setInstances(instances)) - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, instances) - - service := d.getService(c, id) - instances = 5 - - setInstances(instances)(service) - url := fmt.Sprintf("/services/%s/update?version=%d", service.Spec.Name, service.Version.Index) - status, out, err := d.SockRequest("POST", url, service.Spec) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out))) - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, instances) -} - -func (s *DockerSwarmSuite) TestAPISwarmSecretsEmptyList(c *check.C) { - d := s.AddDaemon(c, true, true) - - secrets := d.listSecrets(c) - c.Assert(secrets, checker.NotNil) - c.Assert(len(secrets), checker.Equals, 0, check.Commentf("secrets: %#v", secrets)) -} - -func (s *DockerSwarmSuite) TestAPISwarmSecretsCreate(c *check.C) { - d := s.AddDaemon(c, true, true) - - testName := "test_secret" - id := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: testName, - }, - []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id)) - - secrets := d.listSecrets(c) - c.Assert(len(secrets), checker.Equals, 1, check.Commentf("secrets: %#v", secrets)) - name := secrets[0].Spec.Annotations.Name - c.Assert(name, checker.Equals, testName, check.Commentf("secret: %s", name)) -} - -func (s *DockerSwarmSuite) TestAPISwarmSecretsDelete(c *check.C) { - d := s.AddDaemon(c, true, true) - - testName := "test_secret" - id := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: testName, - }, - []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id)) - - secret := d.getSecret(c, id) - c.Assert(secret.ID, checker.Equals, id, check.Commentf("secret: %v", secret)) - - d.deleteSecret(c, secret.ID) - status, out, err := d.SockRequest("GET", "/secrets/"+id, nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNotFound, check.Commentf("secret delete: %s", string(out))) -} - -// Test case for 30242, where duplicate networks, with different drivers `bridge` and `overlay`, -// caused both scopes to be `swarm` for `docker network inspect` and `docker network ls`. -// This test makes sure the fixes correctly output scopes instead. -func (s *DockerSwarmSuite) TestAPIDuplicateNetworks(c *check.C) { - d := s.AddDaemon(c, true, true) - - name := "foo" - networkCreateRequest := types.NetworkCreateRequest{ - Name: name, - NetworkCreate: types.NetworkCreate{ - CheckDuplicate: false, - }, - } - - var n1 types.NetworkCreateResponse - networkCreateRequest.NetworkCreate.Driver = "bridge" - - status, out, err := d.SockRequest("POST", "/networks/create", networkCreateRequest) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(out))) - - c.Assert(json.Unmarshal(out, &n1), checker.IsNil) - - var n2 types.NetworkCreateResponse - networkCreateRequest.NetworkCreate.Driver = "overlay" - - status, out, err = d.SockRequest("POST", "/networks/create", networkCreateRequest) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(out))) - - c.Assert(json.Unmarshal(out, &n2), checker.IsNil) - - var r1 types.NetworkResource - - status, out, err = d.SockRequest("GET", "/networks/"+n1.ID, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(out))) - - c.Assert(json.Unmarshal(out, &r1), checker.IsNil) - - c.Assert(r1.Scope, checker.Equals, "local") - - var r2 types.NetworkResource - - status, out, err = d.SockRequest("GET", "/networks/"+n2.ID, nil) - c.Assert(err, checker.IsNil, check.Commentf(string(out))) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(out))) - - c.Assert(json.Unmarshal(out, &r2), checker.IsNil) - - c.Assert(r2.Scope, checker.Equals, "swarm") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_test.go deleted file mode 100644 index 3b38ba9..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "net/http/httptest" - "runtime" - "strconv" - "strings" - - "github.com/docker/docker/api" - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestAPIOptionsRoute(c *check.C) { - status, _, err := sockRequest("OPTIONS", "/", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) -} - -func (s *DockerSuite) TestAPIGetEnabledCORS(c *check.C) { - res, body, err := sockRequestRaw("GET", "/version", nil, "") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusOK) - body.Close() - // TODO: @runcom incomplete tests, why old integration tests had this headers - // and here none of the headers below are in the response? - //c.Log(res.Header) - //c.Assert(res.Header.Get("Access-Control-Allow-Origin"), check.Equals, "*") - //c.Assert(res.Header.Get("Access-Control-Allow-Headers"), check.Equals, "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth") -} - -func (s *DockerSuite) TestAPIClientVersionOldNotSupported(c *check.C) { - if daemonPlatform != runtime.GOOS { - c.Skip("Daemon platform doesn't match test platform") - } - if api.MinVersion == api.DefaultVersion { - c.Skip("API MinVersion==DefaultVersion") - } - v := strings.Split(api.MinVersion, ".") - vMinInt, err := strconv.Atoi(v[1]) - c.Assert(err, checker.IsNil) - vMinInt-- - v[1] = strconv.Itoa(vMinInt) - version := strings.Join(v, ".") - - status, body, err := sockRequest("GET", "/v"+version+"/version", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusBadRequest) - expected := fmt.Sprintf("client version %s is too old. Minimum supported API version is %s, please upgrade your client to a newer version", version, api.MinVersion) - c.Assert(strings.TrimSpace(string(body)), checker.Contains, expected) -} - -func (s *DockerSuite) TestAPIDockerAPIVersion(c *check.C) { - var svrVersion string - - server := httptest.NewServer(http.HandlerFunc( - func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("API-Version", api.DefaultVersion) - url := r.URL.Path - svrVersion = url - })) - defer server.Close() - - // Test using the env var first - result := icmd.RunCmd(icmd.Cmd{ - Command: binaryWithArgs("-H="+server.URL[7:], "version"), - Env: appendBaseEnv(false, "DOCKER_API_VERSION=xxx"), - }) - c.Assert(result, icmd.Matches, icmd.Expected{Out: "API version: xxx", ExitCode: 1}) - c.Assert(svrVersion, check.Equals, "/vxxx/version", check.Commentf("%s", result.Compare(icmd.Success))) -} - -func (s *DockerSuite) TestAPIErrorJSON(c *check.C) { - httpResp, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(`{}`), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(httpResp.StatusCode, checker.Equals, http.StatusInternalServerError) - c.Assert(httpResp.Header.Get("Content-Type"), checker.Equals, "application/json") - b, err := readBody(body) - c.Assert(err, checker.IsNil) - c.Assert(getErrorMessage(c, b), checker.Equals, "Config cannot be empty in order to create a container") -} - -func (s *DockerSuite) TestAPIErrorPlainText(c *check.C) { - // Windows requires API 1.25 or later. This test is validating a behaviour which was present - // in v1.23, but changed in 1.24, hence not applicable on Windows. See apiVersionSupportsJSONErrors - testRequires(c, DaemonIsLinux) - httpResp, body, err := sockRequestRaw("POST", "/v1.23/containers/create", strings.NewReader(`{}`), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(httpResp.StatusCode, checker.Equals, http.StatusInternalServerError) - c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain") - b, err := readBody(body) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(string(b)), checker.Equals, "Config cannot be empty in order to create a container") -} - -func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *check.C) { - // 404 is a different code path to normal errors, so test separately - httpResp, body, err := sockRequestRaw("GET", "/notfound", nil, "application/json") - c.Assert(err, checker.IsNil) - c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound) - c.Assert(httpResp.Header.Get("Content-Type"), checker.Equals, "application/json") - b, err := readBody(body) - c.Assert(err, checker.IsNil) - c.Assert(getErrorMessage(c, b), checker.Equals, "page not found") -} - -func (s *DockerSuite) TestAPIErrorNotFoundPlainText(c *check.C) { - httpResp, body, err := sockRequestRaw("GET", "/v1.23/notfound", nil, "application/json") - c.Assert(err, checker.IsNil) - c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound) - c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain") - b, err := readBody(body) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(string(b)), checker.Equals, "page not found") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_update_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_update_unix_test.go deleted file mode 100644 index dfe14ec..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_update_unix_test.go +++ /dev/null @@ -1,35 +0,0 @@ -// +build !windows - -package main - -import ( - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestAPIUpdateContainer(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - testRequires(c, swapMemorySupport) - - name := "apiUpdateContainer" - hostConfig := map[string]interface{}{ - "Memory": 314572800, - "MemorySwap": 524288000, - } - dockerCmd(c, "run", "-d", "--name", name, "-m", "200M", "busybox", "top") - _, _, err := sockRequest("POST", "/containers/"+name+"/update", hostConfig) - c.Assert(err, check.IsNil) - - c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "314572800") - file := "/sys/fs/cgroup/memory/memory.limit_in_bytes" - out, _ := dockerCmd(c, "exec", name, "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "314572800") - - c.Assert(inspectField(c, name, "HostConfig.MemorySwap"), checker.Equals, "524288000") - file = "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes" - out, _ = dockerCmd(c, "exec", name, "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "524288000") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_version_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_version_test.go deleted file mode 100644 index eb2de59..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_version_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "encoding/json" - "net/http" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestGetVersion(c *check.C) { - status, body, err := sockRequest("GET", "/version", nil) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(err, checker.IsNil) - - var v types.Version - - c.Assert(json.Unmarshal(body, &v), checker.IsNil) - - c.Assert(v.Version, checker.Equals, dockerversion.Version, check.Commentf("Version mismatch")) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_api_volumes_test.go b/vendor/github.com/docker/docker/integration-cli/docker_api_volumes_test.go deleted file mode 100644 index d1d4400..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_api_volumes_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package main - -import ( - "encoding/json" - "net/http" - "path/filepath" - - "github.com/docker/docker/api/types" - volumetypes "github.com/docker/docker/api/types/volume" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestVolumesAPIList(c *check.C) { - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - dockerCmd(c, "run", "-v", prefix+"/foo", "busybox") - - status, b, err := sockRequest("GET", "/volumes", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var volumes volumetypes.VolumesListOKBody - c.Assert(json.Unmarshal(b, &volumes), checker.IsNil) - - c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) -} - -func (s *DockerSuite) TestVolumesAPICreate(c *check.C) { - config := volumetypes.VolumesCreateBody{ - Name: "test", - } - status, b, err := sockRequest("POST", "/volumes/create", config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b))) - - var vol types.Volume - err = json.Unmarshal(b, &vol) - c.Assert(err, checker.IsNil) - - c.Assert(filepath.Base(filepath.Dir(vol.Mountpoint)), checker.Equals, config.Name) -} - -func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) { - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - dockerCmd(c, "run", "-v", prefix+"/foo", "--name=test", "busybox") - - status, b, err := sockRequest("GET", "/volumes", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK) - - var volumes volumetypes.VolumesListOKBody - c.Assert(json.Unmarshal(b, &volumes), checker.IsNil) - c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) - - v := volumes.Volumes[0] - status, _, err = sockRequest("DELETE", "/volumes/"+v.Name, nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusConflict, check.Commentf("Should not be able to remove a volume that is in use")) - - dockerCmd(c, "rm", "-f", "test") - status, data, err := sockRequest("DELETE", "/volumes/"+v.Name, nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent, check.Commentf(string(data))) - -} - -func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) { - config := volumetypes.VolumesCreateBody{ - Name: "test", - } - status, b, err := sockRequest("POST", "/volumes/create", config) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b))) - - status, b, err = sockRequest("GET", "/volumes", nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b))) - - var volumes volumetypes.VolumesListOKBody - c.Assert(json.Unmarshal(b, &volumes), checker.IsNil) - c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes)) - - var vol types.Volume - status, b, err = sockRequest("GET", "/volumes/"+config.Name, nil) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b))) - c.Assert(json.Unmarshal(b, &vol), checker.IsNil) - c.Assert(vol.Name, checker.Equals, config.Name) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_attach_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_attach_test.go deleted file mode 100644 index 2df4fdc..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_attach_test.go +++ /dev/null @@ -1,168 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "io" - "os/exec" - "runtime" - "strings" - "sync" - "time" - - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/go-check/check" -) - -const attachWait = 5 * time.Second - -func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) { - endGroup := &sync.WaitGroup{} - startGroup := &sync.WaitGroup{} - endGroup.Add(3) - startGroup.Add(3) - - err := waitForContainer("attacher", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 1; echo hello; done") - c.Assert(err, check.IsNil) - - startDone := make(chan struct{}) - endDone := make(chan struct{}) - - go func() { - endGroup.Wait() - close(endDone) - }() - - go func() { - startGroup.Wait() - close(startDone) - }() - - for i := 0; i < 3; i++ { - go func() { - cmd := exec.Command(dockerBinary, "attach", "attacher") - - defer func() { - cmd.Wait() - endGroup.Done() - }() - - out, err := cmd.StdoutPipe() - if err != nil { - c.Fatal(err) - } - defer out.Close() - - if err := cmd.Start(); err != nil { - c.Fatal(err) - } - - buf := make([]byte, 1024) - - if _, err := out.Read(buf); err != nil && err != io.EOF { - c.Fatal(err) - } - - startGroup.Done() - - if !strings.Contains(string(buf), "hello") { - c.Fatalf("unexpected output %s expected hello\n", string(buf)) - } - }() - } - - select { - case <-startDone: - case <-time.After(attachWait): - c.Fatalf("Attaches did not initialize properly") - } - - dockerCmd(c, "kill", "attacher") - - select { - case <-endDone: - case <-time.After(attachWait): - c.Fatalf("Attaches did not finish properly") - } -} - -func (s *DockerSuite) TestAttachTTYWithoutStdin(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox") - - id := strings.TrimSpace(out) - c.Assert(waitRun(id), check.IsNil) - - done := make(chan error) - go func() { - defer close(done) - - cmd := exec.Command(dockerBinary, "attach", id) - if _, err := cmd.StdinPipe(); err != nil { - done <- err - return - } - - expected := "the input device is not a TTY" - if runtime.GOOS == "windows" { - expected += ". If you are using mintty, try prefixing the command with 'winpty'" - } - if out, _, err := runCommandWithOutput(cmd); err == nil { - done <- fmt.Errorf("attach should have failed") - return - } else if !strings.Contains(out, expected) { - done <- fmt.Errorf("attach failed with error %q: expected %q", out, expected) - return - } - }() - - select { - case err := <-done: - c.Assert(err, check.IsNil) - case <-time.After(attachWait): - c.Fatal("attach is running but should have failed") - } -} - -func (s *DockerSuite) TestAttachDisconnect(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-di", "busybox", "/bin/cat") - id := strings.TrimSpace(out) - - cmd := exec.Command(dockerBinary, "attach", id) - stdin, err := cmd.StdinPipe() - if err != nil { - c.Fatal(err) - } - defer stdin.Close() - stdout, err := cmd.StdoutPipe() - c.Assert(err, check.IsNil) - defer stdout.Close() - c.Assert(cmd.Start(), check.IsNil) - defer cmd.Process.Kill() - - _, err = stdin.Write([]byte("hello\n")) - c.Assert(err, check.IsNil) - out, err = bufio.NewReader(stdout).ReadString('\n') - c.Assert(err, check.IsNil) - c.Assert(strings.TrimSpace(out), check.Equals, "hello") - - c.Assert(stdin.Close(), check.IsNil) - - // Expect container to still be running after stdin is closed - running := inspectField(c, id, "State.Running") - c.Assert(running, check.Equals, "true") -} - -func (s *DockerSuite) TestAttachPausedContainer(c *check.C) { - testRequires(c, IsPausable) - defer unpauseAllContainers() - runSleepingContainer(c, "-d", "--name=test") - dockerCmd(c, "pause", "test") - - result := dockerCmdWithResult("attach", "test") - c.Assert(result, icmd.Matches, icmd.Expected{ - Error: "exit status 1", - ExitCode: 1, - Err: "You cannot attach to a paused container, unpause it first", - }) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_attach_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_attach_unix_test.go deleted file mode 100644 index fb794cc..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_attach_unix_test.go +++ /dev/null @@ -1,237 +0,0 @@ -// +build !windows - -package main - -import ( - "bufio" - "io/ioutil" - "os/exec" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/stringid" - "github.com/go-check/check" - "github.com/kr/pty" -) - -// #9860 Make sure attach ends when container ends (with no errors) -func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) { - testRequires(c, SameHostDaemon) - - out, _ := dockerCmd(c, "run", "-dti", "busybox", "/bin/sh", "-c", `trap 'exit 0' SIGTERM; while true; do sleep 1; done`) - - id := strings.TrimSpace(out) - c.Assert(waitRun(id), check.IsNil) - - pty, tty, err := pty.Open() - c.Assert(err, check.IsNil) - - attachCmd := exec.Command(dockerBinary, "attach", id) - attachCmd.Stdin = tty - attachCmd.Stdout = tty - attachCmd.Stderr = tty - err = attachCmd.Start() - c.Assert(err, check.IsNil) - - errChan := make(chan error) - go func() { - time.Sleep(300 * time.Millisecond) - defer close(errChan) - // Container is waiting for us to signal it to stop - dockerCmd(c, "stop", id) - // And wait for the attach command to end - errChan <- attachCmd.Wait() - }() - - // Wait for the docker to end (should be done by the - // stop command in the go routine) - dockerCmd(c, "wait", id) - - select { - case err := <-errChan: - tty.Close() - out, _ := ioutil.ReadAll(pty) - c.Assert(err, check.IsNil, check.Commentf("out: %v", string(out))) - case <-time.After(attachWait): - c.Fatal("timed out without attach returning") - } - -} - -func (s *DockerSuite) TestAttachAfterDetach(c *check.C) { - name := "detachtest" - - cpty, tty, err := pty.Open() - c.Assert(err, checker.IsNil, check.Commentf("Could not open pty: %v", err)) - cmd := exec.Command(dockerBinary, "run", "-ti", "--name", name, "busybox") - cmd.Stdin = tty - cmd.Stdout = tty - cmd.Stderr = tty - - errChan := make(chan error) - go func() { - errChan <- cmd.Run() - close(errChan) - }() - - c.Assert(waitRun(name), check.IsNil) - - cpty.Write([]byte{16}) - time.Sleep(100 * time.Millisecond) - cpty.Write([]byte{17}) - - select { - case err := <-errChan: - if err != nil { - buff := make([]byte, 200) - tty.Read(buff) - c.Fatalf("%s: %s", err, buff) - } - case <-time.After(5 * time.Second): - c.Fatal("timeout while detaching") - } - - cpty, tty, err = pty.Open() - c.Assert(err, checker.IsNil, check.Commentf("Could not open pty: %v", err)) - - cmd = exec.Command(dockerBinary, "attach", name) - cmd.Stdin = tty - cmd.Stdout = tty - cmd.Stderr = tty - - err = cmd.Start() - c.Assert(err, checker.IsNil) - - bytes := make([]byte, 10) - var nBytes int - readErr := make(chan error, 1) - - go func() { - time.Sleep(500 * time.Millisecond) - cpty.Write([]byte("\n")) - time.Sleep(500 * time.Millisecond) - - nBytes, err = cpty.Read(bytes) - cpty.Close() - readErr <- err - }() - - select { - case err := <-readErr: - c.Assert(err, check.IsNil) - case <-time.After(2 * time.Second): - c.Fatal("timeout waiting for attach read") - } - - err = cmd.Wait() - c.Assert(err, checker.IsNil) - - c.Assert(string(bytes[:nBytes]), checker.Contains, "/ #") - -} - -// TestAttachDetach checks that attach in tty mode can be detached using the long container ID -func (s *DockerSuite) TestAttachDetach(c *check.C) { - out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), check.IsNil) - - cpty, tty, err := pty.Open() - c.Assert(err, check.IsNil) - defer cpty.Close() - - cmd := exec.Command(dockerBinary, "attach", id) - cmd.Stdin = tty - stdout, err := cmd.StdoutPipe() - c.Assert(err, check.IsNil) - defer stdout.Close() - err = cmd.Start() - c.Assert(err, check.IsNil) - c.Assert(waitRun(id), check.IsNil) - - _, err = cpty.Write([]byte("hello\n")) - c.Assert(err, check.IsNil) - out, err = bufio.NewReader(stdout).ReadString('\n') - c.Assert(err, check.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "hello", check.Commentf("expected 'hello', got %q", out)) - - // escape sequence - _, err = cpty.Write([]byte{16}) - c.Assert(err, checker.IsNil) - time.Sleep(100 * time.Millisecond) - _, err = cpty.Write([]byte{17}) - c.Assert(err, checker.IsNil) - - ch := make(chan struct{}) - go func() { - cmd.Wait() - ch <- struct{}{} - }() - - running := inspectField(c, id, "State.Running") - c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running")) - - go func() { - dockerCmd(c, "kill", id) - }() - - select { - case <-ch: - case <-time.After(10 * time.Millisecond): - c.Fatal("timed out waiting for container to exit") - } - -} - -// TestAttachDetachTruncatedID checks that attach in tty mode can be detached -func (s *DockerSuite) TestAttachDetachTruncatedID(c *check.C) { - out, _ := dockerCmd(c, "run", "-itd", "busybox", "cat") - id := stringid.TruncateID(strings.TrimSpace(out)) - c.Assert(waitRun(id), check.IsNil) - - cpty, tty, err := pty.Open() - c.Assert(err, checker.IsNil) - defer cpty.Close() - - cmd := exec.Command(dockerBinary, "attach", id) - cmd.Stdin = tty - stdout, err := cmd.StdoutPipe() - c.Assert(err, checker.IsNil) - defer stdout.Close() - err = cmd.Start() - c.Assert(err, checker.IsNil) - - _, err = cpty.Write([]byte("hello\n")) - c.Assert(err, checker.IsNil) - out, err = bufio.NewReader(stdout).ReadString('\n') - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "hello", check.Commentf("expected 'hello', got %q", out)) - - // escape sequence - _, err = cpty.Write([]byte{16}) - c.Assert(err, checker.IsNil) - time.Sleep(100 * time.Millisecond) - _, err = cpty.Write([]byte{17}) - c.Assert(err, checker.IsNil) - - ch := make(chan struct{}) - go func() { - cmd.Wait() - ch <- struct{}{} - }() - - running := inspectField(c, id, "State.Running") - c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running")) - - go func() { - dockerCmd(c, "kill", id) - }() - - select { - case <-ch: - case <-time.After(10 * time.Millisecond): - c.Fatal("timed out waiting for container to exit") - } - -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_authz_plugin_v2_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_authz_plugin_v2_test.go deleted file mode 100644 index 8a669fb..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_authz_plugin_v2_test.go +++ /dev/null @@ -1,133 +0,0 @@ -// +build !windows - -package main - -import ( - "fmt" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -var ( - authzPluginName = "riyaz/authz-no-volume-plugin" - authzPluginTag = "latest" - authzPluginNameWithTag = authzPluginName + ":" + authzPluginTag - authzPluginBadManifestName = "riyaz/authz-plugin-bad-manifest" - nonexistentAuthzPluginName = "riyaz/nonexistent-authz-plugin" -) - -func init() { - check.Suite(&DockerAuthzV2Suite{ - ds: &DockerSuite{}, - }) -} - -type DockerAuthzV2Suite struct { - ds *DockerSuite - d *Daemon -} - -func (s *DockerAuthzV2Suite) SetUpTest(c *check.C) { - testRequires(c, DaemonIsLinux, Network) - s.d = NewDaemon(c) - c.Assert(s.d.Start(), check.IsNil) -} - -func (s *DockerAuthzV2Suite) TearDownTest(c *check.C) { - s.d.Stop() - s.ds.TearDownTest(c) -} - -func (s *DockerAuthzV2Suite) TestAuthZPluginAllowNonVolumeRequest(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - // Install authz plugin - _, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", authzPluginNameWithTag) - c.Assert(err, checker.IsNil) - // start the daemon with the plugin and load busybox, --net=none build fails otherwise - // because it needs to pull busybox - c.Assert(s.d.Restart("--authorization-plugin="+authzPluginNameWithTag), check.IsNil) - c.Assert(s.d.LoadBusybox(), check.IsNil) - - // defer disabling the plugin - defer func() { - c.Assert(s.d.Restart(), check.IsNil) - _, err = s.d.Cmd("plugin", "disable", authzPluginNameWithTag) - c.Assert(err, checker.IsNil) - _, err = s.d.Cmd("plugin", "rm", authzPluginNameWithTag) - c.Assert(err, checker.IsNil) - }() - - // Ensure docker run command and accompanying docker ps are successful - out, err := s.d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, check.IsNil) - - id := strings.TrimSpace(out) - - out, err = s.d.Cmd("ps") - c.Assert(err, check.IsNil) - c.Assert(assertContainerList(out, []string{id}), check.Equals, true) -} - -func (s *DockerAuthzV2Suite) TestAuthZPluginRejectVolumeRequests(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - // Install authz plugin - _, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", authzPluginNameWithTag) - c.Assert(err, checker.IsNil) - - // restart the daemon with the plugin - c.Assert(s.d.Restart("--authorization-plugin="+authzPluginNameWithTag), check.IsNil) - - // defer disabling the plugin - defer func() { - c.Assert(s.d.Restart(), check.IsNil) - _, err = s.d.Cmd("plugin", "disable", authzPluginNameWithTag) - c.Assert(err, checker.IsNil) - _, err = s.d.Cmd("plugin", "rm", authzPluginNameWithTag) - c.Assert(err, checker.IsNil) - }() - - out, err := s.d.Cmd("volume", "create") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)) - - out, err = s.d.Cmd("volume", "ls") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)) - - // The plugin will block the command before it can determine the volume does not exist - out, err = s.d.Cmd("volume", "rm", "test") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)) - - out, err = s.d.Cmd("volume", "inspect", "test") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)) - - out, err = s.d.Cmd("volume", "prune", "-f") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)) -} - -func (s *DockerAuthzV2Suite) TestAuthZPluginBadManifestFailsDaemonStart(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - // Install authz plugin with bad manifest - _, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", authzPluginBadManifestName) - c.Assert(err, checker.IsNil) - - // start the daemon with the plugin, it will error - c.Assert(s.d.Restart("--authorization-plugin="+authzPluginBadManifestName), check.NotNil) - - // restarting the daemon without requiring the plugin will succeed - c.Assert(s.d.Restart(), check.IsNil) -} - -func (s *DockerAuthzV2Suite) TestNonexistentAuthZPluginFailsDaemonStart(c *check.C) { - testRequires(c, DaemonIsLinux, Network) - // start the daemon with a non-existent authz plugin, it will error - c.Assert(s.d.Restart("--authorization-plugin="+nonexistentAuthzPluginName), check.NotNil) - - // restarting the daemon without requiring the plugin will succeed - c.Assert(s.d.Restart(), check.IsNil) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_authz_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_authz_unix_test.go deleted file mode 100644 index a826249..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_authz_unix_test.go +++ /dev/null @@ -1,477 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "path/filepath" - "strings" - - "bufio" - "bytes" - "os/exec" - "strconv" - "time" - - "net" - "net/http/httputil" - "net/url" - - "github.com/docker/docker/pkg/authorization" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/plugins" - "github.com/go-check/check" -) - -const ( - testAuthZPlugin = "authzplugin" - unauthorizedMessage = "User unauthorized authz plugin" - errorMessage = "something went wrong..." - containerListAPI = "/containers/json" -) - -var ( - alwaysAllowed = []string{"/_ping", "/info"} -) - -func init() { - check.Suite(&DockerAuthzSuite{ - ds: &DockerSuite{}, - }) -} - -type DockerAuthzSuite struct { - server *httptest.Server - ds *DockerSuite - d *Daemon - ctrl *authorizationController -} - -type authorizationController struct { - reqRes authorization.Response // reqRes holds the plugin response to the initial client request - resRes authorization.Response // resRes holds the plugin response to the daemon response - psRequestCnt int // psRequestCnt counts the number of calls to list container request api - psResponseCnt int // psResponseCnt counts the number of calls to list containers response API - requestsURIs []string // requestsURIs stores all request URIs that are sent to the authorization controller - reqUser string - resUser string -} - -func (s *DockerAuthzSuite) SetUpTest(c *check.C) { - s.d = NewDaemon(c) - s.ctrl = &authorizationController{} -} - -func (s *DockerAuthzSuite) TearDownTest(c *check.C) { - s.d.Stop() - s.ds.TearDownTest(c) - s.ctrl = nil -} - -func (s *DockerAuthzSuite) SetUpSuite(c *check.C) { - mux := http.NewServeMux() - s.server = httptest.NewServer(mux) - - mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) { - b, err := json.Marshal(plugins.Manifest{Implements: []string{authorization.AuthZApiImplements}}) - c.Assert(err, check.IsNil) - w.Write(b) - }) - - mux.HandleFunc("/AuthZPlugin.AuthZReq", func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - body, err := ioutil.ReadAll(r.Body) - c.Assert(err, check.IsNil) - authReq := authorization.Request{} - err = json.Unmarshal(body, &authReq) - c.Assert(err, check.IsNil) - - assertBody(c, authReq.RequestURI, authReq.RequestHeaders, authReq.RequestBody) - assertAuthHeaders(c, authReq.RequestHeaders) - - // Count only container list api - if strings.HasSuffix(authReq.RequestURI, containerListAPI) { - s.ctrl.psRequestCnt++ - } - - s.ctrl.requestsURIs = append(s.ctrl.requestsURIs, authReq.RequestURI) - - reqRes := s.ctrl.reqRes - if isAllowed(authReq.RequestURI) { - reqRes = authorization.Response{Allow: true} - } - if reqRes.Err != "" { - w.WriteHeader(http.StatusInternalServerError) - } - b, err := json.Marshal(reqRes) - c.Assert(err, check.IsNil) - s.ctrl.reqUser = authReq.User - w.Write(b) - }) - - mux.HandleFunc("/AuthZPlugin.AuthZRes", func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - body, err := ioutil.ReadAll(r.Body) - c.Assert(err, check.IsNil) - authReq := authorization.Request{} - err = json.Unmarshal(body, &authReq) - c.Assert(err, check.IsNil) - - assertBody(c, authReq.RequestURI, authReq.ResponseHeaders, authReq.ResponseBody) - assertAuthHeaders(c, authReq.ResponseHeaders) - - // Count only container list api - if strings.HasSuffix(authReq.RequestURI, containerListAPI) { - s.ctrl.psResponseCnt++ - } - resRes := s.ctrl.resRes - if isAllowed(authReq.RequestURI) { - resRes = authorization.Response{Allow: true} - } - if resRes.Err != "" { - w.WriteHeader(http.StatusInternalServerError) - } - b, err := json.Marshal(resRes) - c.Assert(err, check.IsNil) - s.ctrl.resUser = authReq.User - w.Write(b) - }) - - err := os.MkdirAll("/etc/docker/plugins", 0755) - c.Assert(err, checker.IsNil) - - fileName := fmt.Sprintf("/etc/docker/plugins/%s.spec", testAuthZPlugin) - err = ioutil.WriteFile(fileName, []byte(s.server.URL), 0644) - c.Assert(err, checker.IsNil) -} - -// check for always allowed endpoints to not inhibit test framework functions -func isAllowed(reqURI string) bool { - for _, endpoint := range alwaysAllowed { - if strings.HasSuffix(reqURI, endpoint) { - return true - } - } - return false -} - -// assertAuthHeaders validates authentication headers are removed -func assertAuthHeaders(c *check.C, headers map[string]string) error { - for k := range headers { - if strings.Contains(strings.ToLower(k), "auth") || strings.Contains(strings.ToLower(k), "x-registry") { - c.Errorf("Found authentication headers in request '%v'", headers) - } - } - return nil -} - -// assertBody asserts that body is removed for non text/json requests -func assertBody(c *check.C, requestURI string, headers map[string]string, body []byte) { - if strings.Contains(strings.ToLower(requestURI), "auth") && len(body) > 0 { - //return fmt.Errorf("Body included for authentication endpoint %s", string(body)) - c.Errorf("Body included for authentication endpoint %s", string(body)) - } - - for k, v := range headers { - if strings.EqualFold(k, "Content-Type") && strings.HasPrefix(v, "text/") || v == "application/json" { - return - } - } - if len(body) > 0 { - c.Errorf("Body included while it should not (Headers: '%v')", headers) - } -} - -func (s *DockerAuthzSuite) TearDownSuite(c *check.C) { - if s.server == nil { - return - } - - s.server.Close() - - err := os.RemoveAll("/etc/docker/plugins") - c.Assert(err, checker.IsNil) -} - -func (s *DockerAuthzSuite) TestAuthZPluginAllowRequest(c *check.C) { - // start the daemon and load busybox, --net=none build fails otherwise - // cause it needs to pull busybox - c.Assert(s.d.Start("--authorization-plugin="+testAuthZPlugin), check.IsNil) - s.ctrl.reqRes.Allow = true - s.ctrl.resRes.Allow = true - c.Assert(s.d.LoadBusybox(), check.IsNil) - - // Ensure command successful - out, err := s.d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, check.IsNil) - - id := strings.TrimSpace(out) - assertURIRecorded(c, s.ctrl.requestsURIs, "/containers/create") - assertURIRecorded(c, s.ctrl.requestsURIs, fmt.Sprintf("/containers/%s/start", id)) - - out, err = s.d.Cmd("ps") - c.Assert(err, check.IsNil) - c.Assert(assertContainerList(out, []string{id}), check.Equals, true) - c.Assert(s.ctrl.psRequestCnt, check.Equals, 1) - c.Assert(s.ctrl.psResponseCnt, check.Equals, 1) -} - -func (s *DockerAuthzSuite) TestAuthZPluginTls(c *check.C) { - - const testDaemonHTTPSAddr = "tcp://localhost:4271" - // start the daemon and load busybox, --net=none build fails otherwise - // cause it needs to pull busybox - if err := s.d.Start( - "--authorization-plugin="+testAuthZPlugin, - "--tlsverify", - "--tlscacert", - "fixtures/https/ca.pem", - "--tlscert", - "fixtures/https/server-cert.pem", - "--tlskey", - "fixtures/https/server-key.pem", - "-H", testDaemonHTTPSAddr); err != nil { - c.Fatalf("Could not start daemon with busybox: %v", err) - } - - s.ctrl.reqRes.Allow = true - s.ctrl.resRes.Allow = true - - out, _ := dockerCmd( - c, - "--tlsverify", - "--tlscacert", "fixtures/https/ca.pem", - "--tlscert", "fixtures/https/client-cert.pem", - "--tlskey", "fixtures/https/client-key.pem", - "-H", - testDaemonHTTPSAddr, - "version", - ) - if !strings.Contains(out, "Server") { - c.Fatalf("docker version should return information of server side") - } - - c.Assert(s.ctrl.reqUser, check.Equals, "client") - c.Assert(s.ctrl.resUser, check.Equals, "client") -} - -func (s *DockerAuthzSuite) TestAuthZPluginDenyRequest(c *check.C) { - err := s.d.Start("--authorization-plugin=" + testAuthZPlugin) - c.Assert(err, check.IsNil) - s.ctrl.reqRes.Allow = false - s.ctrl.reqRes.Msg = unauthorizedMessage - - // Ensure command is blocked - res, err := s.d.Cmd("ps") - c.Assert(err, check.NotNil) - c.Assert(s.ctrl.psRequestCnt, check.Equals, 1) - c.Assert(s.ctrl.psResponseCnt, check.Equals, 0) - - // Ensure unauthorized message appears in response - c.Assert(res, check.Equals, fmt.Sprintf("Error response from daemon: authorization denied by plugin %s: %s\n", testAuthZPlugin, unauthorizedMessage)) -} - -// TestAuthZPluginAPIDenyResponse validates that when authorization plugin deny the request, the status code is forbidden -func (s *DockerAuthzSuite) TestAuthZPluginAPIDenyResponse(c *check.C) { - err := s.d.Start("--authorization-plugin=" + testAuthZPlugin) - c.Assert(err, check.IsNil) - s.ctrl.reqRes.Allow = false - s.ctrl.resRes.Msg = unauthorizedMessage - - daemonURL, err := url.Parse(s.d.sock()) - - conn, err := net.DialTimeout(daemonURL.Scheme, daemonURL.Path, time.Second*10) - c.Assert(err, check.IsNil) - client := httputil.NewClientConn(conn, nil) - req, err := http.NewRequest("GET", "/version", nil) - c.Assert(err, check.IsNil) - resp, err := client.Do(req) - - c.Assert(err, check.IsNil) - c.Assert(resp.StatusCode, checker.Equals, http.StatusForbidden) - c.Assert(err, checker.IsNil) -} - -func (s *DockerAuthzSuite) TestAuthZPluginDenyResponse(c *check.C) { - err := s.d.Start("--authorization-plugin=" + testAuthZPlugin) - c.Assert(err, check.IsNil) - s.ctrl.reqRes.Allow = true - s.ctrl.resRes.Allow = false - s.ctrl.resRes.Msg = unauthorizedMessage - - // Ensure command is blocked - res, err := s.d.Cmd("ps") - c.Assert(err, check.NotNil) - c.Assert(s.ctrl.psRequestCnt, check.Equals, 1) - c.Assert(s.ctrl.psResponseCnt, check.Equals, 1) - - // Ensure unauthorized message appears in response - c.Assert(res, check.Equals, fmt.Sprintf("Error response from daemon: authorization denied by plugin %s: %s\n", testAuthZPlugin, unauthorizedMessage)) -} - -// TestAuthZPluginAllowEventStream verifies event stream propagates correctly after request pass through by the authorization plugin -func (s *DockerAuthzSuite) TestAuthZPluginAllowEventStream(c *check.C) { - testRequires(c, DaemonIsLinux) - - // start the daemon and load busybox to avoid pulling busybox from Docker Hub - c.Assert(s.d.Start("--authorization-plugin="+testAuthZPlugin), check.IsNil) - s.ctrl.reqRes.Allow = true - s.ctrl.resRes.Allow = true - c.Assert(s.d.LoadBusybox(), check.IsNil) - - startTime := strconv.FormatInt(daemonTime(c).Unix(), 10) - // Add another command to to enable event pipelining - eventsCmd := exec.Command(dockerBinary, "--host", s.d.sock(), "events", "--since", startTime) - stdout, err := eventsCmd.StdoutPipe() - if err != nil { - c.Assert(err, check.IsNil) - } - - observer := eventObserver{ - buffer: new(bytes.Buffer), - command: eventsCmd, - scanner: bufio.NewScanner(stdout), - startTime: startTime, - } - - err = observer.Start() - c.Assert(err, checker.IsNil) - defer observer.Stop() - - // Create a container and wait for the creation events - out, err := s.d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf(out)) - containerID := strings.TrimSpace(out) - c.Assert(s.d.waitRun(containerID), checker.IsNil) - - events := map[string]chan bool{ - "create": make(chan bool, 1), - "start": make(chan bool, 1), - } - - matcher := matchEventLine(containerID, "container", events) - processor := processEventMatch(events) - go observer.Match(matcher, processor) - - // Ensure all events are received - for event, eventChannel := range events { - - select { - case <-time.After(30 * time.Second): - // Fail the test - observer.CheckEventError(c, containerID, event, matcher) - c.FailNow() - case <-eventChannel: - // Ignore, event received - } - } - - // Ensure both events and container endpoints are passed to the authorization plugin - assertURIRecorded(c, s.ctrl.requestsURIs, "/events") - assertURIRecorded(c, s.ctrl.requestsURIs, "/containers/create") - assertURIRecorded(c, s.ctrl.requestsURIs, fmt.Sprintf("/containers/%s/start", containerID)) -} - -func (s *DockerAuthzSuite) TestAuthZPluginErrorResponse(c *check.C) { - err := s.d.Start("--authorization-plugin=" + testAuthZPlugin) - c.Assert(err, check.IsNil) - s.ctrl.reqRes.Allow = true - s.ctrl.resRes.Err = errorMessage - - // Ensure command is blocked - res, err := s.d.Cmd("ps") - c.Assert(err, check.NotNil) - - c.Assert(res, check.Equals, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s\n", testAuthZPlugin, authorization.AuthZApiResponse, errorMessage)) -} - -func (s *DockerAuthzSuite) TestAuthZPluginErrorRequest(c *check.C) { - err := s.d.Start("--authorization-plugin=" + testAuthZPlugin) - c.Assert(err, check.IsNil) - s.ctrl.reqRes.Err = errorMessage - - // Ensure command is blocked - res, err := s.d.Cmd("ps") - c.Assert(err, check.NotNil) - - c.Assert(res, check.Equals, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s\n", testAuthZPlugin, authorization.AuthZApiRequest, errorMessage)) -} - -func (s *DockerAuthzSuite) TestAuthZPluginEnsureNoDuplicatePluginRegistration(c *check.C) { - c.Assert(s.d.Start("--authorization-plugin="+testAuthZPlugin, "--authorization-plugin="+testAuthZPlugin), check.IsNil) - - s.ctrl.reqRes.Allow = true - s.ctrl.resRes.Allow = true - - out, err := s.d.Cmd("ps") - c.Assert(err, check.IsNil, check.Commentf(out)) - - // assert plugin is only called once.. - c.Assert(s.ctrl.psRequestCnt, check.Equals, 1) - c.Assert(s.ctrl.psResponseCnt, check.Equals, 1) -} - -func (s *DockerAuthzSuite) TestAuthZPluginEnsureLoadImportWorking(c *check.C) { - c.Assert(s.d.Start("--authorization-plugin="+testAuthZPlugin, "--authorization-plugin="+testAuthZPlugin), check.IsNil) - s.ctrl.reqRes.Allow = true - s.ctrl.resRes.Allow = true - c.Assert(s.d.LoadBusybox(), check.IsNil) - - tmp, err := ioutil.TempDir("", "test-authz-load-import") - c.Assert(err, check.IsNil) - defer os.RemoveAll(tmp) - - savedImagePath := filepath.Join(tmp, "save.tar") - - out, err := s.d.Cmd("save", "-o", savedImagePath, "busybox") - c.Assert(err, check.IsNil, check.Commentf(out)) - out, err = s.d.Cmd("load", "--input", savedImagePath) - c.Assert(err, check.IsNil, check.Commentf(out)) - - exportedImagePath := filepath.Join(tmp, "export.tar") - - out, err = s.d.Cmd("run", "-d", "--name", "testexport", "busybox") - c.Assert(err, check.IsNil, check.Commentf(out)) - out, err = s.d.Cmd("export", "-o", exportedImagePath, "testexport") - c.Assert(err, check.IsNil, check.Commentf(out)) - out, err = s.d.Cmd("import", exportedImagePath) - c.Assert(err, check.IsNil, check.Commentf(out)) -} - -func (s *DockerAuthzSuite) TestAuthZPluginHeader(c *check.C) { - c.Assert(s.d.Start("--debug", "--authorization-plugin="+testAuthZPlugin), check.IsNil) - s.ctrl.reqRes.Allow = true - s.ctrl.resRes.Allow = true - c.Assert(s.d.LoadBusybox(), check.IsNil) - - daemonURL, err := url.Parse(s.d.sock()) - - conn, err := net.DialTimeout(daemonURL.Scheme, daemonURL.Path, time.Second*10) - c.Assert(err, check.IsNil) - client := httputil.NewClientConn(conn, nil) - req, err := http.NewRequest("GET", "/version", nil) - c.Assert(err, check.IsNil) - resp, err := client.Do(req) - - c.Assert(err, check.IsNil) - c.Assert(resp.Header["Content-Type"][0], checker.Equals, "application/json") -} - -// assertURIRecorded verifies that the given URI was sent and recorded in the authz plugin -func assertURIRecorded(c *check.C, uris []string, uri string) { - var found bool - for _, u := range uris { - if strings.Contains(u, uri) { - found = true - break - } - } - if !found { - c.Fatalf("Expected to find URI '%s', recorded uris '%s'", uri, strings.Join(uris, ",")) - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_build_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_build_test.go deleted file mode 100644 index 49c1062..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_build_test.go +++ /dev/null @@ -1,7392 +0,0 @@ -package main - -import ( - "archive/tar" - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "reflect" - "regexp" - "runtime" - "strconv" - "strings" - "text/template" - "time" - - "github.com/docker/docker/builder/dockerfile/command" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/docker/docker/pkg/stringutils" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestBuildJSONEmptyRun(c *check.C) { - name := "testbuildjsonemptyrun" - - _, err := buildImage( - name, - ` - FROM busybox - RUN [] - `, - true) - - if err != nil { - c.Fatal("error when dealing with a RUN statement with empty JSON array") - } - -} - -func (s *DockerSuite) TestBuildShCmdJSONEntrypoint(c *check.C) { - name := "testbuildshcmdjsonentrypoint" - - _, err := buildImage( - name, - ` - FROM busybox - ENTRYPOINT ["echo"] - CMD echo test - `, - true) - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", "--rm", name) - - if daemonPlatform == "windows" { - if !strings.Contains(out, "cmd /S /C echo test") { - c.Fatalf("CMD did not contain cmd /S /C echo test : %q", out) - } - } else { - if strings.TrimSpace(out) != "/bin/sh -c echo test" { - c.Fatalf("CMD did not contain /bin/sh -c : %q", out) - } - } - -} - -func (s *DockerSuite) TestBuildEnvironmentReplacementUser(c *check.C) { - // Windows does not support FROM scratch or the USER command - testRequires(c, DaemonIsLinux) - name := "testbuildenvironmentreplacement" - - _, err := buildImage(name, ` - FROM scratch - ENV user foo - USER ${user} - `, true) - if err != nil { - c.Fatal(err) - } - - res := inspectFieldJSON(c, name, "Config.User") - - if res != `"foo"` { - c.Fatal("User foo from environment not in Config.User on image") - } - -} - -func (s *DockerSuite) TestBuildEnvironmentReplacementVolume(c *check.C) { - name := "testbuildenvironmentreplacement" - - var volumePath string - - if daemonPlatform == "windows" { - volumePath = "c:/quux" - } else { - volumePath = "/quux" - } - - _, err := buildImage(name, ` - FROM `+minimalBaseImage()+` - ENV volume `+volumePath+` - VOLUME ${volume} - `, true) - if err != nil { - c.Fatal(err) - } - - res := inspectFieldJSON(c, name, "Config.Volumes") - - var volumes map[string]interface{} - - if err := json.Unmarshal([]byte(res), &volumes); err != nil { - c.Fatal(err) - } - - if _, ok := volumes[volumePath]; !ok { - c.Fatal("Volume " + volumePath + " from environment not in Config.Volumes on image") - } - -} - -func (s *DockerSuite) TestBuildEnvironmentReplacementExpose(c *check.C) { - // Windows does not support FROM scratch or the EXPOSE command - testRequires(c, DaemonIsLinux) - name := "testbuildenvironmentreplacement" - - _, err := buildImage(name, ` - FROM scratch - ENV port 80 - EXPOSE ${port} - ENV ports " 99 100 " - EXPOSE ${ports} - `, true) - if err != nil { - c.Fatal(err) - } - - res := inspectFieldJSON(c, name, "Config.ExposedPorts") - - var exposedPorts map[string]interface{} - - if err := json.Unmarshal([]byte(res), &exposedPorts); err != nil { - c.Fatal(err) - } - - exp := []int{80, 99, 100} - - for _, p := range exp { - tmp := fmt.Sprintf("%d/tcp", p) - if _, ok := exposedPorts[tmp]; !ok { - c.Fatalf("Exposed port %d from environment not in Config.ExposedPorts on image", p) - } - } - -} - -func (s *DockerSuite) TestBuildEnvironmentReplacementWorkdir(c *check.C) { - name := "testbuildenvironmentreplacement" - - _, err := buildImage(name, ` - FROM busybox - ENV MYWORKDIR /work - RUN mkdir ${MYWORKDIR} - WORKDIR ${MYWORKDIR} - `, true) - - if err != nil { - c.Fatal(err) - } - -} - -func (s *DockerSuite) TestBuildEnvironmentReplacementAddCopy(c *check.C) { - name := "testbuildenvironmentreplacement" - - ctx, err := fakeContext(` - FROM `+minimalBaseImage()+` - ENV baz foo - ENV quux bar - ENV dot . - ENV fee fff - ENV gee ggg - - ADD ${baz} ${dot} - COPY ${quux} ${dot} - ADD ${zzz:-${fee}} ${dot} - COPY ${zzz:-${gee}} ${dot} - `, - map[string]string{ - "foo": "test1", - "bar": "test2", - "fff": "test3", - "ggg": "test4", - }) - - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - -} - -func (s *DockerSuite) TestBuildEnvironmentReplacementEnv(c *check.C) { - // ENV expansions work differently in Windows - testRequires(c, DaemonIsLinux) - name := "testbuildenvironmentreplacement" - - _, err := buildImage(name, - ` - FROM busybox - ENV foo zzz - ENV bar ${foo} - ENV abc1='$foo' - ENV env1=$foo env2=${foo} env3="$foo" env4="${foo}" - RUN [ "$abc1" = '$foo' ] && (echo "$abc1" | grep -q foo) - ENV abc2="\$foo" - RUN [ "$abc2" = '$foo' ] && (echo "$abc2" | grep -q foo) - ENV abc3 '$foo' - RUN [ "$abc3" = '$foo' ] && (echo "$abc3" | grep -q foo) - ENV abc4 "\$foo" - RUN [ "$abc4" = '$foo' ] && (echo "$abc4" | grep -q foo) - `, true) - - if err != nil { - c.Fatal(err) - } - - res := inspectFieldJSON(c, name, "Config.Env") - - envResult := []string{} - - if err = json.Unmarshal([]byte(res), &envResult); err != nil { - c.Fatal(err) - } - - found := false - envCount := 0 - - for _, env := range envResult { - parts := strings.SplitN(env, "=", 2) - if parts[0] == "bar" { - found = true - if parts[1] != "zzz" { - c.Fatalf("Could not find replaced var for env `bar`: got %q instead of `zzz`", parts[1]) - } - } else if strings.HasPrefix(parts[0], "env") { - envCount++ - if parts[1] != "zzz" { - c.Fatalf("%s should be 'foo' but instead its %q", parts[0], parts[1]) - } - } else if strings.HasPrefix(parts[0], "env") { - envCount++ - if parts[1] != "foo" { - c.Fatalf("%s should be 'foo' but instead its %q", parts[0], parts[1]) - } - } - } - - if !found { - c.Fatal("Never found the `bar` env variable") - } - - if envCount != 4 { - c.Fatalf("Didn't find all env vars - only saw %d\n%s", envCount, envResult) - } - -} - -func (s *DockerSuite) TestBuildHandleEscapes(c *check.C) { - // The volume paths used in this test are invalid on Windows - testRequires(c, DaemonIsLinux) - name := "testbuildhandleescapes" - - _, err := buildImage(name, - ` - FROM scratch - ENV FOO bar - VOLUME ${FOO} - `, true) - - if err != nil { - c.Fatal(err) - } - - var result map[string]map[string]struct{} - - res := inspectFieldJSON(c, name, "Config.Volumes") - - if err = json.Unmarshal([]byte(res), &result); err != nil { - c.Fatal(err) - } - - if _, ok := result["bar"]; !ok { - c.Fatalf("Could not find volume bar set from env foo in volumes table, got %q", result) - } - - deleteImages(name) - - _, err = buildImage(name, - ` - FROM scratch - ENV FOO bar - VOLUME \${FOO} - `, true) - - if err != nil { - c.Fatal(err) - } - - res = inspectFieldJSON(c, name, "Config.Volumes") - - if err = json.Unmarshal([]byte(res), &result); err != nil { - c.Fatal(err) - } - - if _, ok := result["${FOO}"]; !ok { - c.Fatalf("Could not find volume ${FOO} set from env foo in volumes table, got %q", result) - } - - deleteImages(name) - - // this test in particular provides *7* backslashes and expects 6 to come back. - // Like above, the first escape is swallowed and the rest are treated as - // literals, this one is just less obvious because of all the character noise. - - _, err = buildImage(name, - ` - FROM scratch - ENV FOO bar - VOLUME \\\\\\\${FOO} - `, true) - - if err != nil { - c.Fatal(err) - } - - res = inspectFieldJSON(c, name, "Config.Volumes") - - if err = json.Unmarshal([]byte(res), &result); err != nil { - c.Fatal(err) - } - - if _, ok := result[`\\\${FOO}`]; !ok { - c.Fatalf(`Could not find volume \\\${FOO} set from env foo in volumes table, got %q`, result) - } - -} - -func (s *DockerSuite) TestBuildOnBuildLowercase(c *check.C) { - name := "testbuildonbuildlowercase" - name2 := "testbuildonbuildlowercase2" - - _, err := buildImage(name, - ` - FROM busybox - onbuild run echo quux - `, true) - - if err != nil { - c.Fatal(err) - } - - _, out, err := buildImageWithOut(name2, fmt.Sprintf(` - FROM %s - `, name), true) - - if err != nil { - c.Fatal(err) - } - - if !strings.Contains(out, "quux") { - c.Fatalf("Did not receive the expected echo text, got %s", out) - } - - if strings.Contains(out, "ONBUILD ONBUILD") { - c.Fatalf("Got an ONBUILD ONBUILD error with no error: got %s", out) - } - -} - -func (s *DockerSuite) TestBuildEnvEscapes(c *check.C) { - // ENV expansions work differently in Windows - testRequires(c, DaemonIsLinux) - name := "testbuildenvescapes" - _, err := buildImage(name, - ` - FROM busybox - ENV TEST foo - CMD echo \$ - `, - true) - - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", "-t", name) - - if strings.TrimSpace(out) != "$" { - c.Fatalf("Env TEST was not overwritten with bar when foo was supplied to dockerfile: was %q", strings.TrimSpace(out)) - } - -} - -func (s *DockerSuite) TestBuildEnvOverwrite(c *check.C) { - // ENV expansions work differently in Windows - testRequires(c, DaemonIsLinux) - name := "testbuildenvoverwrite" - - _, err := buildImage(name, - ` - FROM busybox - ENV TEST foo - CMD echo ${TEST} - `, - true) - - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", "-e", "TEST=bar", "-t", name) - - if strings.TrimSpace(out) != "bar" { - c.Fatalf("Env TEST was not overwritten with bar when foo was supplied to dockerfile: was %q", strings.TrimSpace(out)) - } - -} - -func (s *DockerSuite) TestBuildOnBuildCmdEntrypointJSON(c *check.C) { - name1 := "onbuildcmd" - name2 := "onbuildgenerated" - - _, err := buildImage(name1, ` -FROM busybox -ONBUILD CMD ["hello world"] -ONBUILD ENTRYPOINT ["echo"] -ONBUILD RUN ["true"]`, - false) - - if err != nil { - c.Fatal(err) - } - - _, err = buildImage(name2, fmt.Sprintf(`FROM %s`, name1), false) - - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", name2) - - if !regexp.MustCompile(`(?m)^hello world`).MatchString(out) { - c.Fatalf("did not get echo output from onbuild. Got: %q", out) - } - -} - -func (s *DockerSuite) TestBuildOnBuildEntrypointJSON(c *check.C) { - name1 := "onbuildcmd" - name2 := "onbuildgenerated" - - _, err := buildImage(name1, ` -FROM busybox -ONBUILD ENTRYPOINT ["echo"]`, - false) - - if err != nil { - c.Fatal(err) - } - - _, err = buildImage(name2, fmt.Sprintf("FROM %s\nCMD [\"hello world\"]\n", name1), false) - - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", name2) - - if !regexp.MustCompile(`(?m)^hello world`).MatchString(out) { - c.Fatal("got malformed output from onbuild", out) - } - -} - -func (s *DockerSuite) TestBuildCacheAdd(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows doesn't have httpserver image yet - name := "testbuildtwoimageswithadd" - server, err := fakeStorage(map[string]string{ - "robots.txt": "hello", - "index.html": "world", - }) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - if _, err := buildImage(name, - fmt.Sprintf(`FROM scratch - ADD %s/robots.txt /`, server.URL()), - true); err != nil { - c.Fatal(err) - } - if err != nil { - c.Fatal(err) - } - deleteImages(name) - _, out, err := buildImageWithOut(name, - fmt.Sprintf(`FROM scratch - ADD %s/index.html /`, server.URL()), - true) - if err != nil { - c.Fatal(err) - } - if strings.Contains(out, "Using cache") { - c.Fatal("2nd build used cache on ADD, it shouldn't") - } - -} - -func (s *DockerSuite) TestBuildLastModified(c *check.C) { - name := "testbuildlastmodified" - - server, err := fakeStorage(map[string]string{ - "file": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - var out, out2 string - - dFmt := `FROM busybox -ADD %s/file /` - - dockerfile := fmt.Sprintf(dFmt, server.URL()) - - if _, _, err = buildImageWithOut(name, dockerfile, false); err != nil { - c.Fatal(err) - } - - out, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") - - // Build it again and make sure the mtime of the file didn't change. - // Wait a few seconds to make sure the time changed enough to notice - time.Sleep(2 * time.Second) - - if _, _, err = buildImageWithOut(name, dockerfile, false); err != nil { - c.Fatal(err) - } - out2, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") - - if out != out2 { - c.Fatalf("MTime changed:\nOrigin:%s\nNew:%s", out, out2) - } - - // Now 'touch' the file and make sure the timestamp DID change this time - // Create a new fakeStorage instead of just using Add() to help windows - server, err = fakeStorage(map[string]string{ - "file": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - dockerfile = fmt.Sprintf(dFmt, server.URL()) - - if _, _, err = buildImageWithOut(name, dockerfile, false); err != nil { - c.Fatal(err) - } - out2, _ = dockerCmd(c, "run", name, "ls", "-le", "/file") - - if out == out2 { - c.Fatalf("MTime didn't change:\nOrigin:%s\nNew:%s", out, out2) - } - -} - -// Regression for https://github.com/docker/docker/pull/27805 -// Makes sure that we don't use the cache if the contents of -// a file in a subfolder of the context is modified and we re-build. -func (s *DockerSuite) TestBuildModifyFileInFolder(c *check.C) { - name := "testbuildmodifyfileinfolder" - - ctx, err := fakeContext(`FROM busybox -RUN ["mkdir", "/test"] -ADD folder/file /test/changetarget`, - map[string]string{}) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - if err := ctx.Add("folder/file", "first"); err != nil { - c.Fatal(err) - } - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - if err := ctx.Add("folder/file", "second"); err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - if id1 == id2 { - c.Fatal("cache was used even though file contents in folder was changed") - } -} - -func (s *DockerSuite) TestBuildAddSingleFileToRoot(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testaddimg" - ctx, err := fakeContext(fmt.Sprintf(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN touch /exists -RUN chown dockerio.dockerio /exists -ADD test_file / -RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /test_file | awk '{print $1}') = '%s' ] -RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expectedFileChmod), - map[string]string{ - "test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -// Issue #3960: "ADD src ." hangs -func (s *DockerSuite) TestBuildAddSingleFileToWorkdir(c *check.C) { - name := "testaddsinglefiletoworkdir" - ctx, err := fakeContext(`FROM busybox -ADD test_file .`, - map[string]string{ - "test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - errChan := make(chan error) - go func() { - _, err := buildImageFromContext(name, ctx, true) - errChan <- err - close(errChan) - }() - select { - case <-time.After(15 * time.Second): - c.Fatal("Build with adding to workdir timed out") - case err := <-errChan: - c.Assert(err, check.IsNil) - } -} - -func (s *DockerSuite) TestBuildAddSingleFileToExistDir(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testaddsinglefiletoexistdir" - ctx, err := fakeContext(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN mkdir /exists -RUN touch /exists/exists_file -RUN chown -R dockerio.dockerio /exists -ADD test_file /exists/ -RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ] -RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, - map[string]string{ - "test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildCopyAddMultipleFiles(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - server, err := fakeStorage(map[string]string{ - "robots.txt": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - name := "testcopymultiplefilestofile" - ctx, err := fakeContext(fmt.Sprintf(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN mkdir /exists -RUN touch /exists/exists_file -RUN chown -R dockerio.dockerio /exists -COPY test_file1 test_file2 /exists/ -ADD test_file3 test_file4 %s/robots.txt /exists/ -RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ] -RUN [ $(ls -l /exists/test_file1 | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /exists/test_file2 | awk '{print $3":"$4}') = 'root:root' ] - -RUN [ $(ls -l /exists/test_file3 | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /exists/test_file4 | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /exists/robots.txt | awk '{print $3":"$4}') = 'root:root' ] - -RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ] -`, server.URL()), - map[string]string{ - "test_file1": "test1", - "test_file2": "test2", - "test_file3": "test3", - "test_file4": "test4", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -// This test is mainly for user namespaces to verify that new directories -// are created as the remapped root uid/gid pair -func (s *DockerSuite) TestBuildAddToNewDestination(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testaddtonewdest" - ctx, err := fakeContext(`FROM busybox -ADD . /new_dir -RUN ls -l / -RUN [ $(ls -l / | grep new_dir | awk '{print $3":"$4}') = 'root:root' ]`, - map[string]string{ - "test_dir/test_file": "test file", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -// This test is mainly for user namespaces to verify that new directories -// are created as the remapped root uid/gid pair -func (s *DockerSuite) TestBuildCopyToNewParentDirectory(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testcopytonewdir" - ctx, err := fakeContext(`FROM busybox -COPY test_dir /new_dir -RUN ls -l /new_dir -RUN [ $(ls -l / | grep new_dir | awk '{print $3":"$4}') = 'root:root' ]`, - map[string]string{ - "test_dir/test_file": "test file", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -// This test is mainly for user namespaces to verify that new directories -// are created as the remapped root uid/gid pair -func (s *DockerSuite) TestBuildWorkdirIsContainerRoot(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testworkdirownership" - if _, err := buildImage(name, `FROM busybox -WORKDIR /new_dir -RUN ls -l / -RUN [ $(ls -l / | grep new_dir | awk '{print $3":"$4}') = 'root:root' ]`, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildAddFileWithWhitespace(c *check.C) { - testRequires(c, DaemonIsLinux) // Not currently passing on Windows - name := "testaddfilewithwhitespace" - ctx, err := fakeContext(`FROM busybox -RUN mkdir "/test dir" -RUN mkdir "/test_dir" -ADD [ "test file1", "/test_file1" ] -ADD [ "test_file2", "/test file2" ] -ADD [ "test file3", "/test file3" ] -ADD [ "test dir/test_file4", "/test_dir/test_file4" ] -ADD [ "test_dir/test_file5", "/test dir/test_file5" ] -ADD [ "test dir/test_file6", "/test dir/test_file6" ] -RUN [ $(cat "/test_file1") = 'test1' ] -RUN [ $(cat "/test file2") = 'test2' ] -RUN [ $(cat "/test file3") = 'test3' ] -RUN [ $(cat "/test_dir/test_file4") = 'test4' ] -RUN [ $(cat "/test dir/test_file5") = 'test5' ] -RUN [ $(cat "/test dir/test_file6") = 'test6' ]`, - map[string]string{ - "test file1": "test1", - "test_file2": "test2", - "test file3": "test3", - "test dir/test_file4": "test4", - "test_dir/test_file5": "test5", - "test dir/test_file6": "test6", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildCopyFileWithWhitespace(c *check.C) { - dockerfile := `FROM busybox -RUN mkdir "/test dir" -RUN mkdir "/test_dir" -COPY [ "test file1", "/test_file1" ] -COPY [ "test_file2", "/test file2" ] -COPY [ "test file3", "/test file3" ] -COPY [ "test dir/test_file4", "/test_dir/test_file4" ] -COPY [ "test_dir/test_file5", "/test dir/test_file5" ] -COPY [ "test dir/test_file6", "/test dir/test_file6" ] -RUN [ $(cat "/test_file1") = 'test1' ] -RUN [ $(cat "/test file2") = 'test2' ] -RUN [ $(cat "/test file3") = 'test3' ] -RUN [ $(cat "/test_dir/test_file4") = 'test4' ] -RUN [ $(cat "/test dir/test_file5") = 'test5' ] -RUN [ $(cat "/test dir/test_file6") = 'test6' ]` - - if daemonPlatform == "windows" { - dockerfile = `FROM ` + WindowsBaseImage + ` -RUN mkdir "C:/test dir" -RUN mkdir "C:/test_dir" -COPY [ "test file1", "/test_file1" ] -COPY [ "test_file2", "/test file2" ] -COPY [ "test file3", "/test file3" ] -COPY [ "test dir/test_file4", "/test_dir/test_file4" ] -COPY [ "test_dir/test_file5", "/test dir/test_file5" ] -COPY [ "test dir/test_file6", "/test dir/test_file6" ] -RUN find "test1" "C:/test_file1" -RUN find "test2" "C:/test file2" -RUN find "test3" "C:/test file3" -RUN find "test4" "C:/test_dir/test_file4" -RUN find "test5" "C:/test dir/test_file5" -RUN find "test6" "C:/test dir/test_file6"` - } - - name := "testcopyfilewithwhitespace" - ctx, err := fakeContext(dockerfile, - map[string]string{ - "test file1": "test1", - "test_file2": "test2", - "test file3": "test3", - "test dir/test_file4": "test4", - "test_dir/test_file5": "test5", - "test dir/test_file6": "test6", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildCopyWildcard(c *check.C) { - name := "testcopywildcard" - server, err := fakeStorage(map[string]string{ - "robots.txt": "hello", - "index.html": "world", - }) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - ctx, err := fakeContext(fmt.Sprintf(`FROM busybox - COPY file*.txt /tmp/ - RUN ls /tmp/file1.txt /tmp/file2.txt - RUN [ "mkdir", "/tmp1" ] - COPY dir* /tmp1/ - RUN ls /tmp1/dirt /tmp1/nested_file /tmp1/nested_dir/nest_nest_file - RUN [ "mkdir", "/tmp2" ] - ADD dir/*dir %s/robots.txt /tmp2/ - RUN ls /tmp2/nest_nest_file /tmp2/robots.txt - `, server.URL()), - map[string]string{ - "file1.txt": "test1", - "file2.txt": "test2", - "dir/nested_file": "nested file", - "dir/nested_dir/nest_nest_file": "2 times nested", - "dirt": "dirty", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - - // Now make sure we use a cache the 2nd time - id2, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - - if id1 != id2 { - c.Fatal("didn't use the cache") - } - -} - -func (s *DockerSuite) TestBuildCopyWildcardInName(c *check.C) { - name := "testcopywildcardinname" - ctx, err := fakeContext(`FROM busybox - COPY *.txt /tmp/ - RUN [ "$(cat /tmp/\*.txt)" = 'hi there' ] - `, map[string]string{"*.txt": "hi there"}) - - if err != nil { - // Normally we would do c.Fatal(err) here but given that - // the odds of this failing are so rare, it must be because - // the OS we're running the client on doesn't support * in - // filenames (like windows). So, instead of failing the test - // just let it pass. Then we don't need to explicitly - // say which OSs this works on or not. - return - } - defer ctx.Close() - - _, err = buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatalf("should have built: %q", err) - } -} - -func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) { - name := "testcopywildcardcache" - ctx, err := fakeContext(`FROM busybox - COPY file1.txt /tmp/`, - map[string]string{ - "file1.txt": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - - // Now make sure we use a cache the 2nd time even with wild cards. - // Use the same context so the file is the same and the checksum will match - ctx.Add("Dockerfile", `FROM busybox - COPY file*.txt /tmp/`) - - id2, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - - if id1 != id2 { - c.Fatal("didn't use the cache") - } - -} - -func (s *DockerSuite) TestBuildAddSingleFileToNonExistingDir(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testaddsinglefiletononexistingdir" - ctx, err := fakeContext(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN touch /exists -RUN chown dockerio.dockerio /exists -ADD test_file /test_dir/ -RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, - map[string]string{ - "test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - -} - -func (s *DockerSuite) TestBuildAddDirContentToRoot(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testadddircontenttoroot" - ctx, err := fakeContext(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN touch /exists -RUN chown dockerio.dockerio exists -ADD test_dir / -RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, - map[string]string{ - "test_dir/test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildAddDirContentToExistingDir(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testadddircontenttoexistingdir" - ctx, err := fakeContext(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN mkdir /exists -RUN touch /exists/exists_file -RUN chown -R dockerio.dockerio /exists -ADD test_dir/ /exists/ -RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ] -RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ] -RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]`, - map[string]string{ - "test_dir/test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildAddWholeDirToRoot(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testaddwholedirtoroot" - ctx, err := fakeContext(fmt.Sprintf(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN touch /exists -RUN chown dockerio.dockerio exists -ADD test_dir /test_dir -RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l / | grep test_dir | awk '{print $1}') = 'drwxr-xr-x' ] -RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /test_dir/test_file | awk '{print $1}') = '%s' ] -RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expectedFileChmod), - map[string]string{ - "test_dir/test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -// Testing #5941 -func (s *DockerSuite) TestBuildAddEtcToRoot(c *check.C) { - name := "testaddetctoroot" - - ctx, err := fakeContext(`FROM `+minimalBaseImage()+` -ADD . /`, - map[string]string{ - "etc/test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -// Testing #9401 -func (s *DockerSuite) TestBuildAddPreservesFilesSpecialBits(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testaddpreservesfilesspecialbits" - ctx, err := fakeContext(`FROM busybox -ADD suidbin /usr/bin/suidbin -RUN chmod 4755 /usr/bin/suidbin -RUN [ $(ls -l /usr/bin/suidbin | awk '{print $1}') = '-rwsr-xr-x' ] -ADD ./data/ / -RUN [ $(ls -l /usr/bin/suidbin | awk '{print $1}') = '-rwsr-xr-x' ]`, - map[string]string{ - "suidbin": "suidbin", - "/data/usr/test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildCopySingleFileToRoot(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testcopysinglefiletoroot" - ctx, err := fakeContext(fmt.Sprintf(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN touch /exists -RUN chown dockerio.dockerio /exists -COPY test_file / -RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /test_file | awk '{print $1}') = '%s' ] -RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expectedFileChmod), - map[string]string{ - "test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -// Issue #3960: "ADD src ." hangs - adapted for COPY -func (s *DockerSuite) TestBuildCopySingleFileToWorkdir(c *check.C) { - name := "testcopysinglefiletoworkdir" - ctx, err := fakeContext(`FROM busybox -COPY test_file .`, - map[string]string{ - "test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - errChan := make(chan error) - go func() { - _, err := buildImageFromContext(name, ctx, true) - errChan <- err - close(errChan) - }() - select { - case <-time.After(15 * time.Second): - c.Fatal("Build with adding to workdir timed out") - case err := <-errChan: - c.Assert(err, check.IsNil) - } -} - -func (s *DockerSuite) TestBuildCopySingleFileToExistDir(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testcopysinglefiletoexistdir" - ctx, err := fakeContext(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN mkdir /exists -RUN touch /exists/exists_file -RUN chown -R dockerio.dockerio /exists -COPY test_file /exists/ -RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ] -RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, - map[string]string{ - "test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildCopySingleFileToNonExistDir(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testcopysinglefiletononexistdir" - ctx, err := fakeContext(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN touch /exists -RUN chown dockerio.dockerio /exists -COPY test_file /test_dir/ -RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, - map[string]string{ - "test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildCopyDirContentToRoot(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testcopydircontenttoroot" - ctx, err := fakeContext(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN touch /exists -RUN chown dockerio.dockerio exists -COPY test_dir / -RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, - map[string]string{ - "test_dir/test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildCopyDirContentToExistDir(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testcopydircontenttoexistdir" - ctx, err := fakeContext(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN mkdir /exists -RUN touch /exists/exists_file -RUN chown -R dockerio.dockerio /exists -COPY test_dir/ /exists/ -RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ] -RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ] -RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]`, - map[string]string{ - "test_dir/test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildCopyWholeDirToRoot(c *check.C) { - testRequires(c, DaemonIsLinux) // Linux specific test - name := "testcopywholedirtoroot" - ctx, err := fakeContext(fmt.Sprintf(`FROM busybox -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd -RUN echo 'dockerio:x:1001:' >> /etc/group -RUN touch /exists -RUN chown dockerio.dockerio exists -COPY test_dir /test_dir -RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l / | grep test_dir | awk '{print $1}') = 'drwxr-xr-x' ] -RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ] -RUN [ $(ls -l /test_dir/test_file | awk '{print $1}') = '%s' ] -RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expectedFileChmod), - map[string]string{ - "test_dir/test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildCopyEtcToRoot(c *check.C) { - name := "testcopyetctoroot" - - ctx, err := fakeContext(`FROM `+minimalBaseImage()+` -COPY . /`, - map[string]string{ - "etc/test_file": "test1", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildAddBadLinks(c *check.C) { - testRequires(c, DaemonIsLinux) // Not currently working on Windows - - dockerfile := ` - FROM scratch - ADD links.tar / - ADD foo.txt /symlink/ - ` - targetFile := "foo.txt" - var ( - name = "test-link-absolute" - ) - ctx, err := fakeContext(dockerfile, nil) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - tempDir, err := ioutil.TempDir("", "test-link-absolute-temp-") - if err != nil { - c.Fatalf("failed to create temporary directory: %s", tempDir) - } - defer os.RemoveAll(tempDir) - - var symlinkTarget string - if runtime.GOOS == "windows" { - var driveLetter string - if abs, err := filepath.Abs(tempDir); err != nil { - c.Fatal(err) - } else { - driveLetter = abs[:1] - } - tempDirWithoutDrive := tempDir[2:] - symlinkTarget = fmt.Sprintf(`%s:\..\..\..\..\..\..\..\..\..\..\..\..%s`, driveLetter, tempDirWithoutDrive) - } else { - symlinkTarget = fmt.Sprintf("/../../../../../../../../../../../..%s", tempDir) - } - - tarPath := filepath.Join(ctx.Dir, "links.tar") - nonExistingFile := filepath.Join(tempDir, targetFile) - fooPath := filepath.Join(ctx.Dir, targetFile) - - tarOut, err := os.Create(tarPath) - if err != nil { - c.Fatal(err) - } - - tarWriter := tar.NewWriter(tarOut) - - header := &tar.Header{ - Name: "symlink", - Typeflag: tar.TypeSymlink, - Linkname: symlinkTarget, - Mode: 0755, - Uid: 0, - Gid: 0, - } - - err = tarWriter.WriteHeader(header) - if err != nil { - c.Fatal(err) - } - - tarWriter.Close() - tarOut.Close() - - foo, err := os.Create(fooPath) - if err != nil { - c.Fatal(err) - } - defer foo.Close() - - if _, err := foo.WriteString("test"); err != nil { - c.Fatal(err) - } - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - - if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) { - c.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile) - } - -} - -func (s *DockerSuite) TestBuildAddBadLinksVolume(c *check.C) { - testRequires(c, DaemonIsLinux) // ln not implemented on Windows busybox - const ( - dockerfileTemplate = ` - FROM busybox - RUN ln -s /../../../../../../../../%s /x - VOLUME /x - ADD foo.txt /x/` - targetFile = "foo.txt" - ) - var ( - name = "test-link-absolute-volume" - dockerfile = "" - ) - - tempDir, err := ioutil.TempDir("", "test-link-absolute-volume-temp-") - if err != nil { - c.Fatalf("failed to create temporary directory: %s", tempDir) - } - defer os.RemoveAll(tempDir) - - dockerfile = fmt.Sprintf(dockerfileTemplate, tempDir) - nonExistingFile := filepath.Join(tempDir, targetFile) - - ctx, err := fakeContext(dockerfile, nil) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - fooPath := filepath.Join(ctx.Dir, targetFile) - - foo, err := os.Create(fooPath) - if err != nil { - c.Fatal(err) - } - defer foo.Close() - - if _, err := foo.WriteString("test"); err != nil { - c.Fatal(err) - } - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - - if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) { - c.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile) - } - -} - -// Issue #5270 - ensure we throw a better error than "unexpected EOF" -// when we can't access files in the context. -func (s *DockerSuite) TestBuildWithInaccessibleFilesInContext(c *check.C) { - testRequires(c, DaemonIsLinux, UnixCli) // test uses chown/chmod: not available on windows - - { - name := "testbuildinaccessiblefiles" - ctx, err := fakeContext("FROM scratch\nADD . /foo/", map[string]string{"fileWithoutReadAccess": "foo"}) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - // This is used to ensure we detect inaccessible files early during build in the cli client - pathToFileWithoutReadAccess := filepath.Join(ctx.Dir, "fileWithoutReadAccess") - - if err = os.Chown(pathToFileWithoutReadAccess, 0, 0); err != nil { - c.Fatalf("failed to chown file to root: %s", err) - } - if err = os.Chmod(pathToFileWithoutReadAccess, 0700); err != nil { - c.Fatalf("failed to chmod file to 700: %s", err) - } - buildCmd := exec.Command("su", "unprivilegeduser", "-c", fmt.Sprintf("%s build -t %s .", dockerBinary, name)) - buildCmd.Dir = ctx.Dir - out, _, err := runCommandWithOutput(buildCmd) - if err == nil { - c.Fatalf("build should have failed: %s %s", err, out) - } - - // check if we've detected the failure before we started building - if !strings.Contains(out, "no permission to read from ") { - c.Fatalf("output should've contained the string: no permission to read from but contained: %s", out) - } - - if !strings.Contains(out, "Error checking context") { - c.Fatalf("output should've contained the string: Error checking context") - } - } - { - name := "testbuildinaccessibledirectory" - ctx, err := fakeContext("FROM scratch\nADD . /foo/", map[string]string{"directoryWeCantStat/bar": "foo"}) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - // This is used to ensure we detect inaccessible directories early during build in the cli client - pathToDirectoryWithoutReadAccess := filepath.Join(ctx.Dir, "directoryWeCantStat") - pathToFileInDirectoryWithoutReadAccess := filepath.Join(pathToDirectoryWithoutReadAccess, "bar") - - if err = os.Chown(pathToDirectoryWithoutReadAccess, 0, 0); err != nil { - c.Fatalf("failed to chown directory to root: %s", err) - } - if err = os.Chmod(pathToDirectoryWithoutReadAccess, 0444); err != nil { - c.Fatalf("failed to chmod directory to 444: %s", err) - } - if err = os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700); err != nil { - c.Fatalf("failed to chmod file to 700: %s", err) - } - - buildCmd := exec.Command("su", "unprivilegeduser", "-c", fmt.Sprintf("%s build -t %s .", dockerBinary, name)) - buildCmd.Dir = ctx.Dir - out, _, err := runCommandWithOutput(buildCmd) - if err == nil { - c.Fatalf("build should have failed: %s %s", err, out) - } - - // check if we've detected the failure before we started building - if !strings.Contains(out, "can't stat") { - c.Fatalf("output should've contained the string: can't access %s", out) - } - - if !strings.Contains(out, "Error checking context") { - c.Fatalf("output should've contained the string: Error checking context\ngot:%s", out) - } - - } - { - name := "testlinksok" - ctx, err := fakeContext("FROM scratch\nADD . /foo/", nil) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - target := "../../../../../../../../../../../../../../../../../../../azA" - if err := os.Symlink(filepath.Join(ctx.Dir, "g"), target); err != nil { - c.Fatal(err) - } - defer os.Remove(target) - // This is used to ensure we don't follow links when checking if everything in the context is accessible - // This test doesn't require that we run commands as an unprivileged user - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - } - { - name := "testbuildignoredinaccessible" - ctx, err := fakeContext("FROM scratch\nADD . /foo/", - map[string]string{ - "directoryWeCantStat/bar": "foo", - ".dockerignore": "directoryWeCantStat", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - // This is used to ensure we don't try to add inaccessible files when they are ignored by a .dockerignore pattern - pathToDirectoryWithoutReadAccess := filepath.Join(ctx.Dir, "directoryWeCantStat") - pathToFileInDirectoryWithoutReadAccess := filepath.Join(pathToDirectoryWithoutReadAccess, "bar") - if err = os.Chown(pathToDirectoryWithoutReadAccess, 0, 0); err != nil { - c.Fatalf("failed to chown directory to root: %s", err) - } - if err = os.Chmod(pathToDirectoryWithoutReadAccess, 0444); err != nil { - c.Fatalf("failed to chmod directory to 444: %s", err) - } - if err = os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700); err != nil { - c.Fatalf("failed to chmod file to 700: %s", err) - } - - result := icmd.RunCmd(icmd.Cmd{ - Dir: ctx.Dir, - Command: []string{"su", "unprivilegeduser", "-c", - fmt.Sprintf("%s build -t %s .", dockerBinary, name)}, - }) - result.Assert(c, icmd.Expected{}) - } -} - -func (s *DockerSuite) TestBuildForceRm(c *check.C) { - containerCountBefore, err := getContainerCount() - if err != nil { - c.Fatalf("failed to get the container count: %s", err) - } - name := "testbuildforcerm" - - ctx, err := fakeContext(`FROM `+minimalBaseImage()+` - RUN true - RUN thiswillfail`, nil) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - dockerCmdInDir(c, ctx.Dir, "build", "-t", name, "--force-rm", ".") - - containerCountAfter, err := getContainerCount() - if err != nil { - c.Fatalf("failed to get the container count: %s", err) - } - - if containerCountBefore != containerCountAfter { - c.Fatalf("--force-rm shouldn't have left containers behind") - } - -} - -func (s *DockerSuite) TestBuildRm(c *check.C) { - name := "testbuildrm" - - ctx, err := fakeContext(`FROM `+minimalBaseImage()+` - ADD foo / - ADD foo /`, map[string]string{"foo": "bar"}) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - { - containerCountBefore, err := getContainerCount() - if err != nil { - c.Fatalf("failed to get the container count: %s", err) - } - - out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--rm", "-t", name, ".") - - if err != nil { - c.Fatal("failed to build the image", out) - } - - containerCountAfter, err := getContainerCount() - if err != nil { - c.Fatalf("failed to get the container count: %s", err) - } - - if containerCountBefore != containerCountAfter { - c.Fatalf("-rm shouldn't have left containers behind") - } - deleteImages(name) - } - - { - containerCountBefore, err := getContainerCount() - if err != nil { - c.Fatalf("failed to get the container count: %s", err) - } - - out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", name, ".") - - if err != nil { - c.Fatal("failed to build the image", out) - } - - containerCountAfter, err := getContainerCount() - if err != nil { - c.Fatalf("failed to get the container count: %s", err) - } - - if containerCountBefore != containerCountAfter { - c.Fatalf("--rm shouldn't have left containers behind") - } - deleteImages(name) - } - - { - containerCountBefore, err := getContainerCount() - if err != nil { - c.Fatalf("failed to get the container count: %s", err) - } - - out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--rm=false", "-t", name, ".") - - if err != nil { - c.Fatal("failed to build the image", out) - } - - containerCountAfter, err := getContainerCount() - if err != nil { - c.Fatalf("failed to get the container count: %s", err) - } - - if containerCountBefore == containerCountAfter { - c.Fatalf("--rm=false should have left containers behind") - } - deleteImages(name) - - } - -} - -func (s *DockerSuite) TestBuildWithVolumes(c *check.C) { - testRequires(c, DaemonIsLinux) // Invalid volume paths on Windows - var ( - result map[string]map[string]struct{} - name = "testbuildvolumes" - emptyMap = make(map[string]struct{}) - expected = map[string]map[string]struct{}{ - "/test1": emptyMap, - "/test2": emptyMap, - "/test3": emptyMap, - "/test4": emptyMap, - "/test5": emptyMap, - "/test6": emptyMap, - "[/test7": emptyMap, - "/test8]": emptyMap, - } - ) - _, err := buildImage(name, - `FROM scratch - VOLUME /test1 - VOLUME /test2 - VOLUME /test3 /test4 - VOLUME ["/test5", "/test6"] - VOLUME [/test7 /test8] - `, - true) - if err != nil { - c.Fatal(err) - } - res := inspectFieldJSON(c, name, "Config.Volumes") - - err = json.Unmarshal([]byte(res), &result) - if err != nil { - c.Fatal(err) - } - - equal := reflect.DeepEqual(&result, &expected) - - if !equal { - c.Fatalf("Volumes %s, expected %s", result, expected) - } - -} - -func (s *DockerSuite) TestBuildMaintainer(c *check.C) { - name := "testbuildmaintainer" - - expected := "dockerio" - _, err := buildImage(name, - `FROM `+minimalBaseImage()+` - MAINTAINER dockerio`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Author") - if res != expected { - c.Fatalf("Maintainer %s, expected %s", res, expected) - } -} - -func (s *DockerSuite) TestBuildUser(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuilduser" - expected := "dockerio" - _, err := buildImage(name, - `FROM busybox - RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd - USER dockerio - RUN [ $(whoami) = 'dockerio' ]`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.User") - if res != expected { - c.Fatalf("User %s, expected %s", res, expected) - } -} - -func (s *DockerSuite) TestBuildRelativeWorkdir(c *check.C) { - name := "testbuildrelativeworkdir" - - var ( - expected1 string - expected2 string - expected3 string - expected4 string - expectedFinal string - ) - - if daemonPlatform == "windows" { - expected1 = `C:/` - expected2 = `C:/test1` - expected3 = `C:/test2` - expected4 = `C:/test2/test3` - expectedFinal = `C:\test2\test3` // Note inspect is going to return Windows paths, as it's not in busybox - } else { - expected1 = `/` - expected2 = `/test1` - expected3 = `/test2` - expected4 = `/test2/test3` - expectedFinal = `/test2/test3` - } - - _, err := buildImage(name, - `FROM busybox - RUN sh -c "[ "$PWD" = "`+expected1+`" ]" - WORKDIR test1 - RUN sh -c "[ "$PWD" = "`+expected2+`" ]" - WORKDIR /test2 - RUN sh -c "[ "$PWD" = "`+expected3+`" ]" - WORKDIR test3 - RUN sh -c "[ "$PWD" = "`+expected4+`" ]"`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.WorkingDir") - if res != expectedFinal { - c.Fatalf("Workdir %s, expected %s", res, expectedFinal) - } -} - -// #22181 Regression test. Single end-to-end test of using -// Windows semantics. Most path handling verifications are in unit tests -func (s *DockerSuite) TestBuildWindowsWorkdirProcessing(c *check.C) { - testRequires(c, DaemonIsWindows) - name := "testbuildwindowsworkdirprocessing" - _, err := buildImage(name, - `FROM busybox - WORKDIR C:\\foo - WORKDIR bar - RUN sh -c "[ "$PWD" = "C:/foo/bar" ]" - `, - true) - if err != nil { - c.Fatal(err) - } -} - -// #22181 Regression test. Most paths handling verifications are in unit test. -// One functional test for end-to-end -func (s *DockerSuite) TestBuildWindowsAddCopyPathProcessing(c *check.C) { - testRequires(c, DaemonIsWindows) - name := "testbuildwindowsaddcopypathprocessing" - // TODO Windows (@jhowardmsft). Needs a follow-up PR to 22181 to - // support backslash such as .\\ being equivalent to ./ and c:\\ being - // equivalent to c:/. This is not currently (nor ever has been) supported - // by docker on the Windows platform. - dockerfile := ` - FROM busybox - # No trailing slash on COPY/ADD - # Results in dir being changed to a file - WORKDIR /wc1 - COPY wc1 c:/wc1 - WORKDIR /wc2 - ADD wc2 c:/wc2 - WORKDIR c:/ - RUN sh -c "[ $(cat c:/wc1/wc1) = 'hellowc1' ]" - RUN sh -c "[ $(cat c:/wc2/wc2) = 'worldwc2' ]" - - # Trailing slash on COPY/ADD, Windows-style path. - WORKDIR /wd1 - COPY wd1 c:/wd1/ - WORKDIR /wd2 - ADD wd2 c:/wd2/ - RUN sh -c "[ $(cat c:/wd1/wd1) = 'hellowd1' ]" - RUN sh -c "[ $(cat c:/wd2/wd2) = 'worldwd2' ]" - ` - ctx, err := fakeContext(dockerfile, map[string]string{ - "wc1": "hellowc1", - "wc2": "worldwc2", - "wd1": "hellowd1", - "wd2": "worldwd2", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - _, err = buildImageFromContext(name, ctx, false) - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildWorkdirWithEnvVariables(c *check.C) { - name := "testbuildworkdirwithenvvariables" - - var expected string - if daemonPlatform == "windows" { - expected = `C:\test1\test2` - } else { - expected = `/test1/test2` - } - - _, err := buildImage(name, - `FROM busybox - ENV DIRPATH /test1 - ENV SUBDIRNAME test2 - WORKDIR $DIRPATH - WORKDIR $SUBDIRNAME/$MISSING_VAR`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.WorkingDir") - if res != expected { - c.Fatalf("Workdir %s, expected %s", res, expected) - } -} - -func (s *DockerSuite) TestBuildRelativeCopy(c *check.C) { - // cat /test1/test2/foo gets permission denied for the user - testRequires(c, NotUserNamespace) - - var expected string - if daemonPlatform == "windows" { - expected = `C:/test1/test2` - } else { - expected = `/test1/test2` - } - - name := "testbuildrelativecopy" - dockerfile := ` - FROM busybox - WORKDIR /test1 - WORKDIR test2 - RUN sh -c "[ "$PWD" = '` + expected + `' ]" - COPY foo ./ - RUN sh -c "[ $(cat /test1/test2/foo) = 'hello' ]" - ADD foo ./bar/baz - RUN sh -c "[ $(cat /test1/test2/bar/baz) = 'hello' ]" - COPY foo ./bar/baz2 - RUN sh -c "[ $(cat /test1/test2/bar/baz2) = 'hello' ]" - WORKDIR .. - COPY foo ./ - RUN sh -c "[ $(cat /test1/foo) = 'hello' ]" - COPY foo /test3/ - RUN sh -c "[ $(cat /test3/foo) = 'hello' ]" - WORKDIR /test4 - COPY . . - RUN sh -c "[ $(cat /test4/foo) = 'hello' ]" - WORKDIR /test5/test6 - COPY foo ../ - RUN sh -c "[ $(cat /test5/foo) = 'hello' ]" - ` - ctx, err := fakeContext(dockerfile, map[string]string{ - "foo": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - _, err = buildImageFromContext(name, ctx, false) - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildBlankName(c *check.C) { - name := "testbuildblankname" - _, _, stderr, err := buildImageWithStdoutStderr(name, - `FROM busybox - ENV =`, - true) - if err == nil { - c.Fatal("Build was supposed to fail but didn't") - } - if !strings.Contains(stderr, "ENV names can not be blank") { - c.Fatalf("Missing error message, got: %s", stderr) - } - - _, _, stderr, err = buildImageWithStdoutStderr(name, - `FROM busybox - LABEL =`, - true) - if err == nil { - c.Fatal("Build was supposed to fail but didn't") - } - if !strings.Contains(stderr, "LABEL names can not be blank") { - c.Fatalf("Missing error message, got: %s", stderr) - } - - _, _, stderr, err = buildImageWithStdoutStderr(name, - `FROM busybox - ARG =foo`, - true) - if err == nil { - c.Fatal("Build was supposed to fail but didn't") - } - if !strings.Contains(stderr, "ARG names can not be blank") { - c.Fatalf("Missing error message, got: %s", stderr) - } -} - -func (s *DockerSuite) TestBuildEnv(c *check.C) { - testRequires(c, DaemonIsLinux) // ENV expansion is different in Windows - name := "testbuildenv" - expected := "[PATH=/test:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PORT=2375]" - _, err := buildImage(name, - `FROM busybox - ENV PATH /test:$PATH - ENV PORT 2375 - RUN [ $(env | grep PORT) = 'PORT=2375' ]`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.Env") - if res != expected { - c.Fatalf("Env %s, expected %s", res, expected) - } -} - -func (s *DockerSuite) TestBuildPATH(c *check.C) { - testRequires(c, DaemonIsLinux) // ENV expansion is different in Windows - - defPath := "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - - fn := func(dockerfile string, exp string) { - _, err := buildImage("testbldpath", dockerfile, true) - c.Assert(err, check.IsNil) - - res := inspectField(c, "testbldpath", "Config.Env") - - if res != exp { - c.Fatalf("Env %q, expected %q for dockerfile:%q", res, exp, dockerfile) - } - } - - tests := []struct{ dockerfile, exp string }{ - {"FROM scratch\nMAINTAINER me", "[PATH=" + defPath + "]"}, - {"FROM busybox\nMAINTAINER me", "[PATH=" + defPath + "]"}, - {"FROM scratch\nENV FOO=bar", "[PATH=" + defPath + " FOO=bar]"}, - {"FROM busybox\nENV FOO=bar", "[PATH=" + defPath + " FOO=bar]"}, - {"FROM scratch\nENV PATH=/test", "[PATH=/test]"}, - {"FROM busybox\nENV PATH=/test", "[PATH=/test]"}, - {"FROM scratch\nENV PATH=''", "[PATH=]"}, - {"FROM busybox\nENV PATH=''", "[PATH=]"}, - } - - for _, test := range tests { - fn(test.dockerfile, test.exp) - } -} - -func (s *DockerSuite) TestBuildContextCleanup(c *check.C) { - testRequires(c, SameHostDaemon) - - name := "testbuildcontextcleanup" - entries, err := ioutil.ReadDir(filepath.Join(dockerBasePath, "tmp")) - if err != nil { - c.Fatalf("failed to list contents of tmp dir: %s", err) - } - _, err = buildImage(name, - `FROM `+minimalBaseImage()+` - ENTRYPOINT ["/bin/echo"]`, - true) - if err != nil { - c.Fatal(err) - } - entriesFinal, err := ioutil.ReadDir(filepath.Join(dockerBasePath, "tmp")) - if err != nil { - c.Fatalf("failed to list contents of tmp dir: %s", err) - } - if err = compareDirectoryEntries(entries, entriesFinal); err != nil { - c.Fatalf("context should have been deleted, but wasn't") - } - -} - -func (s *DockerSuite) TestBuildContextCleanupFailedBuild(c *check.C) { - testRequires(c, SameHostDaemon) - - name := "testbuildcontextcleanup" - entries, err := ioutil.ReadDir(filepath.Join(dockerBasePath, "tmp")) - if err != nil { - c.Fatalf("failed to list contents of tmp dir: %s", err) - } - _, err = buildImage(name, - `FROM `+minimalBaseImage()+` - RUN /non/existing/command`, - true) - if err == nil { - c.Fatalf("expected build to fail, but it didn't") - } - entriesFinal, err := ioutil.ReadDir(filepath.Join(dockerBasePath, "tmp")) - if err != nil { - c.Fatalf("failed to list contents of tmp dir: %s", err) - } - if err = compareDirectoryEntries(entries, entriesFinal); err != nil { - c.Fatalf("context should have been deleted, but wasn't") - } - -} - -func (s *DockerSuite) TestBuildCmd(c *check.C) { - name := "testbuildcmd" - - expected := "[/bin/echo Hello World]" - _, err := buildImage(name, - `FROM `+minimalBaseImage()+` - CMD ["/bin/echo", "Hello World"]`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.Cmd") - if res != expected { - c.Fatalf("Cmd %s, expected %s", res, expected) - } -} - -func (s *DockerSuite) TestBuildExpose(c *check.C) { - testRequires(c, DaemonIsLinux) // Expose not implemented on Windows - name := "testbuildexpose" - expected := "map[2375/tcp:{}]" - _, err := buildImage(name, - `FROM scratch - EXPOSE 2375`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.ExposedPorts") - if res != expected { - c.Fatalf("Exposed ports %s, expected %s", res, expected) - } -} - -func (s *DockerSuite) TestBuildExposeMorePorts(c *check.C) { - testRequires(c, DaemonIsLinux) // Expose not implemented on Windows - // start building docker file with a large number of ports - portList := make([]string, 50) - line := make([]string, 100) - expectedPorts := make([]int, len(portList)*len(line)) - for i := 0; i < len(portList); i++ { - for j := 0; j < len(line); j++ { - p := i*len(line) + j + 1 - line[j] = strconv.Itoa(p) - expectedPorts[p-1] = p - } - if i == len(portList)-1 { - portList[i] = strings.Join(line, " ") - } else { - portList[i] = strings.Join(line, " ") + ` \` - } - } - - dockerfile := `FROM scratch - EXPOSE {{range .}} {{.}} - {{end}}` - tmpl := template.Must(template.New("dockerfile").Parse(dockerfile)) - buf := bytes.NewBuffer(nil) - tmpl.Execute(buf, portList) - - name := "testbuildexpose" - _, err := buildImage(name, buf.String(), true) - if err != nil { - c.Fatal(err) - } - - // check if all the ports are saved inside Config.ExposedPorts - res := inspectFieldJSON(c, name, "Config.ExposedPorts") - var exposedPorts map[string]interface{} - if err := json.Unmarshal([]byte(res), &exposedPorts); err != nil { - c.Fatal(err) - } - - for _, p := range expectedPorts { - ep := fmt.Sprintf("%d/tcp", p) - if _, ok := exposedPorts[ep]; !ok { - c.Errorf("Port(%s) is not exposed", ep) - } else { - delete(exposedPorts, ep) - } - } - if len(exposedPorts) != 0 { - c.Errorf("Unexpected extra exposed ports %v", exposedPorts) - } -} - -func (s *DockerSuite) TestBuildExposeOrder(c *check.C) { - testRequires(c, DaemonIsLinux) // Expose not implemented on Windows - buildID := func(name, exposed string) string { - _, err := buildImage(name, fmt.Sprintf(`FROM scratch - EXPOSE %s`, exposed), true) - if err != nil { - c.Fatal(err) - } - id := inspectField(c, name, "Id") - return id - } - - id1 := buildID("testbuildexpose1", "80 2375") - id2 := buildID("testbuildexpose2", "2375 80") - if id1 != id2 { - c.Errorf("EXPOSE should invalidate the cache only when ports actually changed") - } -} - -func (s *DockerSuite) TestBuildExposeUpperCaseProto(c *check.C) { - testRequires(c, DaemonIsLinux) // Expose not implemented on Windows - name := "testbuildexposeuppercaseproto" - expected := "map[5678/udp:{}]" - _, err := buildImage(name, - `FROM scratch - EXPOSE 5678/UDP`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.ExposedPorts") - if res != expected { - c.Fatalf("Exposed ports %s, expected %s", res, expected) - } -} - -func (s *DockerSuite) TestBuildEmptyEntrypointInheritance(c *check.C) { - name := "testbuildentrypointinheritance" - name2 := "testbuildentrypointinheritance2" - - _, err := buildImage(name, - `FROM busybox - ENTRYPOINT ["/bin/echo"]`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.Entrypoint") - - expected := "[/bin/echo]" - if res != expected { - c.Fatalf("Entrypoint %s, expected %s", res, expected) - } - - _, err = buildImage(name2, - fmt.Sprintf(`FROM %s - ENTRYPOINT []`, name), - true) - if err != nil { - c.Fatal(err) - } - res = inspectField(c, name2, "Config.Entrypoint") - - expected = "[]" - - if res != expected { - c.Fatalf("Entrypoint %s, expected %s", res, expected) - } - -} - -func (s *DockerSuite) TestBuildEmptyEntrypoint(c *check.C) { - name := "testbuildentrypoint" - expected := "[]" - - _, err := buildImage(name, - `FROM busybox - ENTRYPOINT []`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.Entrypoint") - if res != expected { - c.Fatalf("Entrypoint %s, expected %s", res, expected) - } - -} - -func (s *DockerSuite) TestBuildEntrypoint(c *check.C) { - name := "testbuildentrypoint" - - expected := "[/bin/echo]" - _, err := buildImage(name, - `FROM `+minimalBaseImage()+` - ENTRYPOINT ["/bin/echo"]`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.Entrypoint") - if res != expected { - c.Fatalf("Entrypoint %s, expected %s", res, expected) - } - -} - -// #6445 ensure ONBUILD triggers aren't committed to grandchildren -func (s *DockerSuite) TestBuildOnBuildLimitedInheritence(c *check.C) { - var ( - out2, out3 string - ) - { - name1 := "testonbuildtrigger1" - dockerfile1 := ` - FROM busybox - RUN echo "GRANDPARENT" - ONBUILD RUN echo "ONBUILD PARENT" - ` - ctx, err := fakeContext(dockerfile1, nil) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - out1, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", name1, ".") - if err != nil { - c.Fatalf("build failed to complete: %s, %v", out1, err) - } - } - { - name2 := "testonbuildtrigger2" - dockerfile2 := ` - FROM testonbuildtrigger1 - ` - ctx, err := fakeContext(dockerfile2, nil) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - out2, _, err = dockerCmdInDir(c, ctx.Dir, "build", "-t", name2, ".") - if err != nil { - c.Fatalf("build failed to complete: %s, %v", out2, err) - } - } - { - name3 := "testonbuildtrigger3" - dockerfile3 := ` - FROM testonbuildtrigger2 - ` - ctx, err := fakeContext(dockerfile3, nil) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - out3, _, err = dockerCmdInDir(c, ctx.Dir, "build", "-t", name3, ".") - if err != nil { - c.Fatalf("build failed to complete: %s, %v", out3, err) - } - - } - - // ONBUILD should be run in second build. - if !strings.Contains(out2, "ONBUILD PARENT") { - c.Fatalf("ONBUILD instruction did not run in child of ONBUILD parent") - } - - // ONBUILD should *not* be run in third build. - if strings.Contains(out3, "ONBUILD PARENT") { - c.Fatalf("ONBUILD instruction ran in grandchild of ONBUILD parent") - } - -} - -func (s *DockerSuite) TestBuildWithCache(c *check.C) { - testRequires(c, DaemonIsLinux) // Expose not implemented on Windows - name := "testbuildwithcache" - id1, err := buildImage(name, - `FROM scratch - MAINTAINER dockerio - EXPOSE 5432 - ENTRYPOINT ["/bin/echo"]`, - true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImage(name, - `FROM scratch - MAINTAINER dockerio - EXPOSE 5432 - ENTRYPOINT ["/bin/echo"]`, - true) - if err != nil { - c.Fatal(err) - } - if id1 != id2 { - c.Fatal("The cache should have been used but hasn't.") - } -} - -func (s *DockerSuite) TestBuildWithoutCache(c *check.C) { - testRequires(c, DaemonIsLinux) // Expose not implemented on Windows - name := "testbuildwithoutcache" - name2 := "testbuildwithoutcache2" - id1, err := buildImage(name, - `FROM scratch - MAINTAINER dockerio - EXPOSE 5432 - ENTRYPOINT ["/bin/echo"]`, - true) - if err != nil { - c.Fatal(err) - } - - id2, err := buildImage(name2, - `FROM scratch - MAINTAINER dockerio - EXPOSE 5432 - ENTRYPOINT ["/bin/echo"]`, - false) - if err != nil { - c.Fatal(err) - } - if id1 == id2 { - c.Fatal("The cache should have been invalided but hasn't.") - } -} - -func (s *DockerSuite) TestBuildConditionalCache(c *check.C) { - name := "testbuildconditionalcache" - - dockerfile := ` - FROM busybox - ADD foo /tmp/` - ctx, err := fakeContext(dockerfile, map[string]string{ - "foo": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatalf("Error building #1: %s", err) - } - - if err := ctx.Add("foo", "bye"); err != nil { - c.Fatalf("Error modifying foo: %s", err) - } - - id2, err := buildImageFromContext(name, ctx, false) - if err != nil { - c.Fatalf("Error building #2: %s", err) - } - if id2 == id1 { - c.Fatal("Should not have used the cache") - } - - id3, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatalf("Error building #3: %s", err) - } - if id3 != id2 { - c.Fatal("Should have used the cache") - } -} - -func (s *DockerSuite) TestBuildAddLocalFileWithCache(c *check.C) { - // local files are not owned by the correct user - testRequires(c, NotUserNamespace) - name := "testbuildaddlocalfilewithcache" - name2 := "testbuildaddlocalfilewithcache2" - dockerfile := ` - FROM busybox - MAINTAINER dockerio - ADD foo /usr/lib/bla/bar - RUN sh -c "[ $(cat /usr/lib/bla/bar) = "hello" ]"` - ctx, err := fakeContext(dockerfile, map[string]string{ - "foo": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name2, ctx, true) - if err != nil { - c.Fatal(err) - } - if id1 != id2 { - c.Fatal("The cache should have been used but hasn't.") - } -} - -func (s *DockerSuite) TestBuildAddMultipleLocalFileWithCache(c *check.C) { - name := "testbuildaddmultiplelocalfilewithcache" - name2 := "testbuildaddmultiplelocalfilewithcache2" - dockerfile := ` - FROM busybox - MAINTAINER dockerio - ADD foo Dockerfile /usr/lib/bla/ - RUN sh -c "[ $(cat /usr/lib/bla/foo) = "hello" ]"` - ctx, err := fakeContext(dockerfile, map[string]string{ - "foo": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name2, ctx, true) - if err != nil { - c.Fatal(err) - } - if id1 != id2 { - c.Fatal("The cache should have been used but hasn't.") - } -} - -func (s *DockerSuite) TestBuildAddLocalFileWithoutCache(c *check.C) { - // local files are not owned by the correct user - testRequires(c, NotUserNamespace) - name := "testbuildaddlocalfilewithoutcache" - name2 := "testbuildaddlocalfilewithoutcache2" - dockerfile := ` - FROM busybox - MAINTAINER dockerio - ADD foo /usr/lib/bla/bar - RUN sh -c "[ $(cat /usr/lib/bla/bar) = "hello" ]"` - ctx, err := fakeContext(dockerfile, map[string]string{ - "foo": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name2, ctx, false) - if err != nil { - c.Fatal(err) - } - if id1 == id2 { - c.Fatal("The cache should have been invalided but hasn't.") - } -} - -func (s *DockerSuite) TestBuildCopyDirButNotFile(c *check.C) { - name := "testbuildcopydirbutnotfile" - name2 := "testbuildcopydirbutnotfile2" - - dockerfile := ` - FROM ` + minimalBaseImage() + ` - COPY dir /tmp/` - ctx, err := fakeContext(dockerfile, map[string]string{ - "dir/foo": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - // Check that adding file with similar name doesn't mess with cache - if err := ctx.Add("dir_file", "hello2"); err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name2, ctx, true) - if err != nil { - c.Fatal(err) - } - if id1 != id2 { - c.Fatal("The cache should have been used but wasn't") - } -} - -func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) { - name := "testbuildaddcurrentdirwithcache" - name2 := name + "2" - name3 := name + "3" - name4 := name + "4" - dockerfile := ` - FROM ` + minimalBaseImage() + ` - MAINTAINER dockerio - ADD . /usr/lib/bla` - ctx, err := fakeContext(dockerfile, map[string]string{ - "foo": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - // Check that adding file invalidate cache of "ADD ." - if err := ctx.Add("bar", "hello2"); err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name2, ctx, true) - if err != nil { - c.Fatal(err) - } - if id1 == id2 { - c.Fatal("The cache should have been invalided but hasn't.") - } - // Check that changing file invalidate cache of "ADD ." - if err := ctx.Add("foo", "hello1"); err != nil { - c.Fatal(err) - } - id3, err := buildImageFromContext(name3, ctx, true) - if err != nil { - c.Fatal(err) - } - if id2 == id3 { - c.Fatal("The cache should have been invalided but hasn't.") - } - // Check that changing file to same content with different mtime does not - // invalidate cache of "ADD ." - time.Sleep(1 * time.Second) // wait second because of mtime precision - if err := ctx.Add("foo", "hello1"); err != nil { - c.Fatal(err) - } - id4, err := buildImageFromContext(name4, ctx, true) - if err != nil { - c.Fatal(err) - } - if id3 != id4 { - c.Fatal("The cache should have been used but hasn't.") - } -} - -func (s *DockerSuite) TestBuildAddCurrentDirWithoutCache(c *check.C) { - name := "testbuildaddcurrentdirwithoutcache" - name2 := "testbuildaddcurrentdirwithoutcache2" - dockerfile := ` - FROM ` + minimalBaseImage() + ` - MAINTAINER dockerio - ADD . /usr/lib/bla` - ctx, err := fakeContext(dockerfile, map[string]string{ - "foo": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name2, ctx, false) - if err != nil { - c.Fatal(err) - } - if id1 == id2 { - c.Fatal("The cache should have been invalided but hasn't.") - } -} - -func (s *DockerSuite) TestBuildAddRemoteFileWithCache(c *check.C) { - name := "testbuildaddremotefilewithcache" - server, err := fakeStorage(map[string]string{ - "baz": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - id1, err := buildImage(name, - fmt.Sprintf(`FROM `+minimalBaseImage()+` - MAINTAINER dockerio - ADD %s/baz /usr/lib/baz/quux`, server.URL()), - true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImage(name, - fmt.Sprintf(`FROM `+minimalBaseImage()+` - MAINTAINER dockerio - ADD %s/baz /usr/lib/baz/quux`, server.URL()), - true) - if err != nil { - c.Fatal(err) - } - if id1 != id2 { - c.Fatal("The cache should have been used but hasn't.") - } -} - -func (s *DockerSuite) TestBuildAddRemoteFileWithoutCache(c *check.C) { - name := "testbuildaddremotefilewithoutcache" - name2 := "testbuildaddremotefilewithoutcache2" - server, err := fakeStorage(map[string]string{ - "baz": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - id1, err := buildImage(name, - fmt.Sprintf(`FROM `+minimalBaseImage()+` - MAINTAINER dockerio - ADD %s/baz /usr/lib/baz/quux`, server.URL()), - true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImage(name2, - fmt.Sprintf(`FROM `+minimalBaseImage()+` - MAINTAINER dockerio - ADD %s/baz /usr/lib/baz/quux`, server.URL()), - false) - if err != nil { - c.Fatal(err) - } - if id1 == id2 { - c.Fatal("The cache should have been invalided but hasn't.") - } -} - -func (s *DockerSuite) TestBuildAddRemoteFileMTime(c *check.C) { - name := "testbuildaddremotefilemtime" - name2 := name + "2" - name3 := name + "3" - - files := map[string]string{"baz": "hello"} - server, err := fakeStorage(files) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - ctx, err := fakeContext(fmt.Sprintf(`FROM `+minimalBaseImage()+` - MAINTAINER dockerio - ADD %s/baz /usr/lib/baz/quux`, server.URL()), nil) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - - id2, err := buildImageFromContext(name2, ctx, true) - if err != nil { - c.Fatal(err) - } - if id1 != id2 { - c.Fatal("The cache should have been used but wasn't - #1") - } - - // Now create a different server with same contents (causes different mtime) - // The cache should still be used - - // allow some time for clock to pass as mtime precision is only 1s - time.Sleep(2 * time.Second) - - server2, err := fakeStorage(files) - if err != nil { - c.Fatal(err) - } - defer server2.Close() - - ctx2, err := fakeContext(fmt.Sprintf(`FROM `+minimalBaseImage()+` - MAINTAINER dockerio - ADD %s/baz /usr/lib/baz/quux`, server2.URL()), nil) - if err != nil { - c.Fatal(err) - } - defer ctx2.Close() - id3, err := buildImageFromContext(name3, ctx2, true) - if err != nil { - c.Fatal(err) - } - if id1 != id3 { - c.Fatal("The cache should have been used but wasn't") - } -} - -func (s *DockerSuite) TestBuildAddLocalAndRemoteFilesWithCache(c *check.C) { - name := "testbuildaddlocalandremotefilewithcache" - server, err := fakeStorage(map[string]string{ - "baz": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - ctx, err := fakeContext(fmt.Sprintf(`FROM `+minimalBaseImage()+` - MAINTAINER dockerio - ADD foo /usr/lib/bla/bar - ADD %s/baz /usr/lib/baz/quux`, server.URL()), - map[string]string{ - "foo": "hello world", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - if id1 != id2 { - c.Fatal("The cache should have been used but hasn't.") - } -} - -func testContextTar(c *check.C, compression archive.Compression) { - ctx, err := fakeContext( - `FROM busybox -ADD foo /foo -CMD ["cat", "/foo"]`, - map[string]string{ - "foo": "bar", - }, - ) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - context, err := archive.Tar(ctx.Dir, compression) - if err != nil { - c.Fatalf("failed to build context tar: %v", err) - } - name := "contexttar" - buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-") - buildCmd.Stdin = context - - if out, _, err := runCommandWithOutput(buildCmd); err != nil { - c.Fatalf("build failed to complete: %v %v", out, err) - } -} - -func (s *DockerSuite) TestBuildContextTarGzip(c *check.C) { - testContextTar(c, archive.Gzip) -} - -func (s *DockerSuite) TestBuildContextTarNoCompression(c *check.C) { - testContextTar(c, archive.Uncompressed) -} - -func (s *DockerSuite) TestBuildNoContext(c *check.C) { - buildCmd := exec.Command(dockerBinary, "build", "-t", "nocontext", "-") - buildCmd.Stdin = strings.NewReader( - `FROM busybox - CMD ["echo", "ok"]`) - - if out, _, err := runCommandWithOutput(buildCmd); err != nil { - c.Fatalf("build failed to complete: %v %v", out, err) - } - - if out, _ := dockerCmd(c, "run", "--rm", "nocontext"); out != "ok\n" { - c.Fatalf("run produced invalid output: %q, expected %q", out, "ok") - } -} - -// TODO: TestCaching -func (s *DockerSuite) TestBuildAddLocalAndRemoteFilesWithoutCache(c *check.C) { - name := "testbuildaddlocalandremotefilewithoutcache" - name2 := "testbuildaddlocalandremotefilewithoutcache2" - server, err := fakeStorage(map[string]string{ - "baz": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - ctx, err := fakeContext(fmt.Sprintf(`FROM `+minimalBaseImage()+` - MAINTAINER dockerio - ADD foo /usr/lib/bla/bar - ADD %s/baz /usr/lib/baz/quux`, server.URL()), - map[string]string{ - "foo": "hello world", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - id1, err := buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } - id2, err := buildImageFromContext(name2, ctx, false) - if err != nil { - c.Fatal(err) - } - if id1 == id2 { - c.Fatal("The cache should have been invalidated but hasn't.") - } -} - -func (s *DockerSuite) TestBuildWithVolumeOwnership(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildimg" - - _, err := buildImage(name, - `FROM busybox:latest - RUN mkdir /test && chown daemon:daemon /test && chmod 0600 /test - VOLUME /test`, - true) - - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", "--rm", "testbuildimg", "ls", "-la", "/test") - - if expected := "drw-------"; !strings.Contains(out, expected) { - c.Fatalf("expected %s received %s", expected, out) - } - - if expected := "daemon daemon"; !strings.Contains(out, expected) { - c.Fatalf("expected %s received %s", expected, out) - } - -} - -// testing #1405 - config.Cmd does not get cleaned up if -// utilizing cache -func (s *DockerSuite) TestBuildEntrypointRunCleanup(c *check.C) { - name := "testbuildcmdcleanup" - if _, err := buildImage(name, - `FROM busybox - RUN echo "hello"`, - true); err != nil { - c.Fatal(err) - } - - ctx, err := fakeContext(`FROM busybox - RUN echo "hello" - ADD foo /foo - ENTRYPOINT ["/bin/echo"]`, - map[string]string{ - "foo": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.Cmd") - // Cmd must be cleaned up - if res != "[]" { - c.Fatalf("Cmd %s, expected nil", res) - } -} - -func (s *DockerSuite) TestBuildAddFileNotFound(c *check.C) { - name := "testbuildaddnotfound" - expected := "foo: no such file or directory" - - if daemonPlatform == "windows" { - expected = "foo: The system cannot find the file specified" - } - - ctx, err := fakeContext(`FROM `+minimalBaseImage()+` - ADD foo /usr/local/bar`, - map[string]string{"bar": "hello"}) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - if !strings.Contains(err.Error(), expected) { - c.Fatalf("Wrong error %v, must be about missing foo file or directory", err) - } - } else { - c.Fatal("Error must not be nil") - } -} - -func (s *DockerSuite) TestBuildInheritance(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildinheritance" - - _, err := buildImage(name, - `FROM scratch - EXPOSE 2375`, - true) - if err != nil { - c.Fatal(err) - } - ports1 := inspectField(c, name, "Config.ExposedPorts") - - _, err = buildImage(name, - fmt.Sprintf(`FROM %s - ENTRYPOINT ["/bin/echo"]`, name), - true) - if err != nil { - c.Fatal(err) - } - - res := inspectField(c, name, "Config.Entrypoint") - if expected := "[/bin/echo]"; res != expected { - c.Fatalf("Entrypoint %s, expected %s", res, expected) - } - ports2 := inspectField(c, name, "Config.ExposedPorts") - if ports1 != ports2 { - c.Fatalf("Ports must be same: %s != %s", ports1, ports2) - } -} - -func (s *DockerSuite) TestBuildFails(c *check.C) { - name := "testbuildfails" - _, err := buildImage(name, - `FROM busybox - RUN sh -c "exit 23"`, - true) - if err != nil { - if !strings.Contains(err.Error(), "returned a non-zero code: 23") { - c.Fatalf("Wrong error %v, must be about non-zero code 23", err) - } - } else { - c.Fatal("Error must not be nil") - } -} - -func (s *DockerSuite) TestBuildOnBuild(c *check.C) { - name := "testbuildonbuild" - _, err := buildImage(name, - `FROM busybox - ONBUILD RUN touch foobar`, - true) - if err != nil { - c.Fatal(err) - } - _, err = buildImage(name, - fmt.Sprintf(`FROM %s - RUN [ -f foobar ]`, name), - true) - if err != nil { - c.Fatal(err) - } -} - -// gh #2446 -func (s *DockerSuite) TestBuildAddToSymlinkDest(c *check.C) { - makeLink := `ln -s /foo /bar` - if daemonPlatform == "windows" { - makeLink = `mklink /D C:\bar C:\foo` - } - name := "testbuildaddtosymlinkdest" - ctx, err := fakeContext(`FROM busybox - RUN sh -c "mkdir /foo" - RUN `+makeLink+` - ADD foo /bar/ - RUN sh -c "[ -f /bar/foo ]" - RUN sh -c "[ -f /foo/foo ]"`, - map[string]string{ - "foo": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildEscapeWhitespace(c *check.C) { - name := "testbuildescapewhitespace" - - _, err := buildImage(name, ` - # ESCAPE=\ - FROM busybox - MAINTAINER "Docker \ -IO " - `, true) - if err != nil { - c.Fatal(err) - } - - res := inspectField(c, name, "Author") - - if res != "\"Docker IO \"" { - c.Fatalf("Parsed string did not match the escaped string. Got: %q", res) - } - -} - -func (s *DockerSuite) TestBuildVerifyIntString(c *check.C) { - // Verify that strings that look like ints are still passed as strings - name := "testbuildstringing" - - _, err := buildImage(name, ` - FROM busybox - MAINTAINER 123 - `, true) - - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "inspect", name) - - if !strings.Contains(out, "\"123\"") { - c.Fatalf("Output does not contain the int as a string:\n%s", out) - } - -} - -func (s *DockerSuite) TestBuildDockerignore(c *check.C) { - name := "testbuilddockerignore" - dockerfile := ` - FROM busybox - ADD . /bla - RUN sh -c "[[ -f /bla/src/x.go ]]" - RUN sh -c "[[ -f /bla/Makefile ]]" - RUN sh -c "[[ ! -e /bla/src/_vendor ]]" - RUN sh -c "[[ ! -e /bla/.gitignore ]]" - RUN sh -c "[[ ! -e /bla/README.md ]]" - RUN sh -c "[[ ! -e /bla/dir/foo ]]" - RUN sh -c "[[ ! -e /bla/foo ]]" - RUN sh -c "[[ ! -e /bla/.git ]]" - RUN sh -c "[[ ! -e v.cc ]]" - RUN sh -c "[[ ! -e src/v.cc ]]" - RUN sh -c "[[ ! -e src/_vendor/v.cc ]]"` - ctx, err := fakeContext(dockerfile, map[string]string{ - "Makefile": "all:", - ".git/HEAD": "ref: foo", - "src/x.go": "package main", - "src/_vendor/v.go": "package main", - "src/_vendor/v.cc": "package main", - "src/v.cc": "package main", - "v.cc": "package main", - "dir/foo": "", - ".gitignore": "", - "README.md": "readme", - ".dockerignore": ` -.git -pkg -.gitignore -src/_vendor -*.md -**/*.cc -dir`, - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildDockerignoreCleanPaths(c *check.C) { - name := "testbuilddockerignorecleanpaths" - dockerfile := ` - FROM busybox - ADD . /tmp/ - RUN sh -c "(! ls /tmp/foo) && (! ls /tmp/foo2) && (! ls /tmp/dir1/foo)"` - ctx, err := fakeContext(dockerfile, map[string]string{ - "foo": "foo", - "foo2": "foo2", - "dir1/foo": "foo in dir1", - ".dockerignore": "./foo\ndir1//foo\n./dir1/../foo2", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildDockerignoreExceptions(c *check.C) { - name := "testbuilddockerignoreexceptions" - dockerfile := ` - FROM busybox - ADD . /bla - RUN sh -c "[[ -f /bla/src/x.go ]]" - RUN sh -c "[[ -f /bla/Makefile ]]" - RUN sh -c "[[ ! -e /bla/src/_vendor ]]" - RUN sh -c "[[ ! -e /bla/.gitignore ]]" - RUN sh -c "[[ ! -e /bla/README.md ]]" - RUN sh -c "[[ -e /bla/dir/dir/foo ]]" - RUN sh -c "[[ ! -e /bla/dir/foo1 ]]" - RUN sh -c "[[ -f /bla/dir/e ]]" - RUN sh -c "[[ -f /bla/dir/e-dir/foo ]]" - RUN sh -c "[[ ! -e /bla/foo ]]" - RUN sh -c "[[ ! -e /bla/.git ]]" - RUN sh -c "[[ -e /bla/dir/a.cc ]]"` - ctx, err := fakeContext(dockerfile, map[string]string{ - "Makefile": "all:", - ".git/HEAD": "ref: foo", - "src/x.go": "package main", - "src/_vendor/v.go": "package main", - "dir/foo": "", - "dir/foo1": "", - "dir/dir/f1": "", - "dir/dir/foo": "", - "dir/e": "", - "dir/e-dir/foo": "", - ".gitignore": "", - "README.md": "readme", - "dir/a.cc": "hello", - ".dockerignore": ` -.git -pkg -.gitignore -src/_vendor -*.md -dir -!dir/e* -!dir/dir/foo -**/*.cc -!**/*.cc`, - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildDockerignoringDockerfile(c *check.C) { - name := "testbuilddockerignoredockerfile" - dockerfile := ` - FROM busybox - ADD . /tmp/ - RUN sh -c "! ls /tmp/Dockerfile" - RUN ls /tmp/.dockerignore` - ctx, err := fakeContext(dockerfile, map[string]string{ - "Dockerfile": dockerfile, - ".dockerignore": "Dockerfile\n", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't ignore Dockerfile correctly:%s", err) - } - - // now try it with ./Dockerfile - ctx.Add(".dockerignore", "./Dockerfile\n") - if _, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't ignore ./Dockerfile correctly:%s", err) - } - -} - -func (s *DockerSuite) TestBuildDockerignoringRenamedDockerfile(c *check.C) { - name := "testbuilddockerignoredockerfile" - dockerfile := ` - FROM busybox - ADD . /tmp/ - RUN ls /tmp/Dockerfile - RUN sh -c "! ls /tmp/MyDockerfile" - RUN ls /tmp/.dockerignore` - ctx, err := fakeContext(dockerfile, map[string]string{ - "Dockerfile": "Should not use me", - "MyDockerfile": dockerfile, - ".dockerignore": "MyDockerfile\n", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't ignore MyDockerfile correctly:%s", err) - } - - // now try it with ./MyDockerfile - ctx.Add(".dockerignore", "./MyDockerfile\n") - if _, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't ignore ./MyDockerfile correctly:%s", err) - } - -} - -func (s *DockerSuite) TestBuildDockerignoringDockerignore(c *check.C) { - name := "testbuilddockerignoredockerignore" - dockerfile := ` - FROM busybox - ADD . /tmp/ - RUN sh -c "! ls /tmp/.dockerignore" - RUN ls /tmp/Dockerfile` - ctx, err := fakeContext(dockerfile, map[string]string{ - "Dockerfile": dockerfile, - ".dockerignore": ".dockerignore\n", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - if _, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't ignore .dockerignore correctly:%s", err) - } -} - -func (s *DockerSuite) TestBuildDockerignoreTouchDockerfile(c *check.C) { - var id1 string - var id2 string - - name := "testbuilddockerignoretouchdockerfile" - dockerfile := ` - FROM busybox - ADD . /tmp/` - ctx, err := fakeContext(dockerfile, map[string]string{ - "Dockerfile": dockerfile, - ".dockerignore": "Dockerfile\n", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if id1, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't build it correctly:%s", err) - } - - if id2, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't build it correctly:%s", err) - } - if id1 != id2 { - c.Fatalf("Didn't use the cache - 1") - } - - // Now make sure touching Dockerfile doesn't invalidate the cache - if err = ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil { - c.Fatalf("Didn't add Dockerfile: %s", err) - } - if id2, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't build it correctly:%s", err) - } - if id1 != id2 { - c.Fatalf("Didn't use the cache - 2") - } - - // One more time but just 'touch' it instead of changing the content - if err = ctx.Add("Dockerfile", dockerfile+"\n# hi"); err != nil { - c.Fatalf("Didn't add Dockerfile: %s", err) - } - if id2, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("Didn't build it correctly:%s", err) - } - if id1 != id2 { - c.Fatalf("Didn't use the cache - 3") - } - -} - -func (s *DockerSuite) TestBuildDockerignoringWholeDir(c *check.C) { - name := "testbuilddockerignorewholedir" - dockerfile := ` - FROM busybox - COPY . / - RUN sh -c "[[ ! -e /.gitignore ]]" - RUN sh -c "[[ -f /Makefile ]]"` - ctx, err := fakeContext(dockerfile, map[string]string{ - "Dockerfile": "FROM scratch", - "Makefile": "all:", - ".gitignore": "", - ".dockerignore": ".*\n", - }) - c.Assert(err, check.IsNil) - defer ctx.Close() - if _, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - - c.Assert(ctx.Add(".dockerfile", "*"), check.IsNil) - if _, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - - c.Assert(ctx.Add(".dockerfile", "."), check.IsNil) - if _, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - - c.Assert(ctx.Add(".dockerfile", "?"), check.IsNil) - if _, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildDockerignoringBadExclusion(c *check.C) { - name := "testbuilddockerignorebadexclusion" - dockerfile := ` - FROM busybox - COPY . / - RUN sh -c "[[ ! -e /.gitignore ]]" - RUN sh -c "[[ -f /Makefile ]]"` - ctx, err := fakeContext(dockerfile, map[string]string{ - "Dockerfile": "FROM scratch", - "Makefile": "all:", - ".gitignore": "", - ".dockerignore": "!\n", - }) - c.Assert(err, check.IsNil) - defer ctx.Close() - if _, err = buildImageFromContext(name, ctx, true); err == nil { - c.Fatalf("Build was supposed to fail but didn't") - } - - if err.Error() != "failed to build the image: Error checking context: 'Illegal exclusion pattern: !'.\n" { - c.Fatalf("Incorrect output, got:%q", err.Error()) - } -} - -func (s *DockerSuite) TestBuildDockerignoringWildTopDir(c *check.C) { - dockerfile := ` - FROM busybox - COPY . / - RUN sh -c "[[ ! -e /.dockerignore ]]" - RUN sh -c "[[ ! -e /Dockerfile ]]" - RUN sh -c "[[ ! -e /file1 ]]" - RUN sh -c "[[ ! -e /dir ]]"` - - ctx, err := fakeContext(dockerfile, map[string]string{ - "Dockerfile": "FROM scratch", - "file1": "", - "dir/dfile1": "", - }) - c.Assert(err, check.IsNil) - defer ctx.Close() - - // All of these should result in ignoring all files - for _, variant := range []string{"**", "**/", "**/**", "*"} { - ctx.Add(".dockerignore", variant) - _, err = buildImageFromContext("noname", ctx, true) - c.Assert(err, check.IsNil, check.Commentf("variant: %s", variant)) - } -} - -func (s *DockerSuite) TestBuildDockerignoringWildDirs(c *check.C) { - dockerfile := ` - FROM busybox - COPY . / - #RUN sh -c "[[ -e /.dockerignore ]]" - RUN sh -c "[[ -e /Dockerfile ]] && \ - [[ ! -e /file0 ]] && \ - [[ ! -e /dir1/file0 ]] && \ - [[ ! -e /dir2/file0 ]] && \ - [[ ! -e /file1 ]] && \ - [[ ! -e /dir1/file1 ]] && \ - [[ ! -e /dir1/dir2/file1 ]] && \ - [[ ! -e /dir1/file2 ]] && \ - [[ -e /dir1/dir2/file2 ]] && \ - [[ ! -e /dir1/dir2/file4 ]] && \ - [[ ! -e /dir1/dir2/file5 ]] && \ - [[ ! -e /dir1/dir2/file6 ]] && \ - [[ ! -e /dir1/dir3/file7 ]] && \ - [[ ! -e /dir1/dir3/file8 ]] && \ - [[ -e /dir1/dir3 ]] && \ - [[ -e /dir1/dir4 ]] && \ - [[ ! -e 'dir1/dir5/fileAA' ]] && \ - [[ -e 'dir1/dir5/fileAB' ]] && \ - [[ -e 'dir1/dir5/fileB' ]]" # "." in pattern means nothing - - RUN echo all done!` - - ctx, err := fakeContext(dockerfile, map[string]string{ - "Dockerfile": "FROM scratch", - "file0": "", - "dir1/file0": "", - "dir1/dir2/file0": "", - - "file1": "", - "dir1/file1": "", - "dir1/dir2/file1": "", - - "dir1/file2": "", - "dir1/dir2/file2": "", // remains - - "dir1/dir2/file4": "", - "dir1/dir2/file5": "", - "dir1/dir2/file6": "", - "dir1/dir3/file7": "", - "dir1/dir3/file8": "", - "dir1/dir4/file9": "", - - "dir1/dir5/fileAA": "", - "dir1/dir5/fileAB": "", - "dir1/dir5/fileB": "", - - ".dockerignore": ` -**/file0 -**/*file1 -**/dir1/file2 -dir1/**/file4 -**/dir2/file5 -**/dir1/dir2/file6 -dir1/dir3/** -**/dir4/** -**/file?A -**/file\?B -**/dir5/file. -`, - }) - c.Assert(err, check.IsNil) - defer ctx.Close() - - _, err = buildImageFromContext("noname", ctx, true) - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestBuildLineBreak(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildlinebreak" - _, err := buildImage(name, - `FROM busybox -RUN sh -c 'echo root:testpass \ - > /tmp/passwd' -RUN mkdir -p /var/run/sshd -RUN sh -c "[ "$(cat /tmp/passwd)" = "root:testpass" ]" -RUN sh -c "[ "$(ls -d /var/run/sshd)" = "/var/run/sshd" ]"`, - true) - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildEOLInLine(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildeolinline" - _, err := buildImage(name, - `FROM busybox -RUN sh -c 'echo root:testpass > /tmp/passwd' -RUN echo "foo \n bar"; echo "baz" -RUN mkdir -p /var/run/sshd -RUN sh -c "[ "$(cat /tmp/passwd)" = "root:testpass" ]" -RUN sh -c "[ "$(ls -d /var/run/sshd)" = "/var/run/sshd" ]"`, - true) - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildCommentsShebangs(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildcomments" - _, err := buildImage(name, - `FROM busybox -# This is an ordinary comment. -RUN { echo '#!/bin/sh'; echo 'echo hello world'; } > /hello.sh -RUN [ ! -x /hello.sh ] -# comment with line break \ -RUN chmod +x /hello.sh -RUN [ -x /hello.sh ] -RUN [ "$(cat /hello.sh)" = $'#!/bin/sh\necho hello world' ] -RUN [ "$(/hello.sh)" = "hello world" ]`, - true) - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildUsersAndGroups(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildusers" - _, err := buildImage(name, - `FROM busybox - -# Make sure our defaults work -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)" = '0:0/root:root' ] - -# TODO decide if "args.user = strconv.Itoa(syscall.Getuid())" is acceptable behavior for changeUser in sysvinit instead of "return nil" when "USER" isn't specified (so that we get the proper group list even if that is the empty list, even in the default case of not supplying an explicit USER to run as, which implies USER 0) -USER root -RUN [ "$(id -G):$(id -Gn)" = '0 10:root wheel' ] - -# Setup dockerio user and group -RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd && \ - echo 'dockerio:x:1001:' >> /etc/group - -# Make sure we can switch to our user and all the information is exactly as we expect it to be -USER dockerio -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1001/dockerio:dockerio/1001:dockerio' ] - -# Switch back to root and double check that worked exactly as we might expect it to -USER root -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '0:0/root:root/0 10:root wheel' ] && \ - # Add a "supplementary" group for our dockerio user - echo 'supplementary:x:1002:dockerio' >> /etc/group - -# ... and then go verify that we get it like we expect -USER dockerio -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1001/dockerio:dockerio/1001 1002:dockerio supplementary' ] -USER 1001 -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1001/dockerio:dockerio/1001 1002:dockerio supplementary' ] - -# super test the new "user:group" syntax -USER dockerio:dockerio -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1001/dockerio:dockerio/1001:dockerio' ] -USER 1001:dockerio -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1001/dockerio:dockerio/1001:dockerio' ] -USER dockerio:1001 -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1001/dockerio:dockerio/1001:dockerio' ] -USER 1001:1001 -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1001/dockerio:dockerio/1001:dockerio' ] -USER dockerio:supplementary -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1002/dockerio:supplementary/1002:supplementary' ] -USER dockerio:1002 -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1002/dockerio:supplementary/1002:supplementary' ] -USER 1001:supplementary -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1002/dockerio:supplementary/1002:supplementary' ] -USER 1001:1002 -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1001:1002/dockerio:supplementary/1002:supplementary' ] - -# make sure unknown uid/gid still works properly -USER 1042:1043 -RUN [ "$(id -u):$(id -g)/$(id -un):$(id -gn)/$(id -G):$(id -Gn)" = '1042:1043/1042:1043/1043:1043' ]`, - true) - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildEnvUsage(c *check.C) { - // /docker/world/hello is not owned by the correct user - testRequires(c, NotUserNamespace) - testRequires(c, DaemonIsLinux) - name := "testbuildenvusage" - dockerfile := `FROM busybox -ENV HOME /root -ENV PATH $HOME/bin:$PATH -ENV PATH /tmp:$PATH -RUN [ "$PATH" = "/tmp:$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] -ENV FOO /foo/baz -ENV BAR /bar -ENV BAZ $BAR -ENV FOOPATH $PATH:$FOO -RUN [ "$BAR" = "$BAZ" ] -RUN [ "$FOOPATH" = "$PATH:/foo/baz" ] -ENV FROM hello/docker/world -ENV TO /docker/world/hello -ADD $FROM $TO -RUN [ "$(cat $TO)" = "hello" ] -ENV abc=def -ENV ghi=$abc -RUN [ "$ghi" = "def" ] -` - ctx, err := fakeContext(dockerfile, map[string]string{ - "hello/docker/world": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - _, err = buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildEnvUsage2(c *check.C) { - // /docker/world/hello is not owned by the correct user - testRequires(c, NotUserNamespace) - testRequires(c, DaemonIsLinux) - name := "testbuildenvusage2" - dockerfile := `FROM busybox -ENV abc=def def="hello world" -RUN [ "$abc,$def" = "def,hello world" ] -ENV def=hello\ world v1=abc v2="hi there" v3='boogie nights' v4="with'quotes too" -RUN [ "$def,$v1,$v2,$v3,$v4" = "hello world,abc,hi there,boogie nights,with'quotes too" ] -ENV abc=zzz FROM=hello/docker/world -ENV abc=zzz TO=/docker/world/hello -ADD $FROM $TO -RUN [ "$abc,$(cat $TO)" = "zzz,hello" ] -ENV abc 'yyy' -RUN [ $abc = 'yyy' ] -ENV abc= -RUN [ "$abc" = "" ] - -# use grep to make sure if the builder substitutes \$foo by mistake -# we don't get a false positive -ENV abc=\$foo -RUN [ "$abc" = "\$foo" ] && (echo "$abc" | grep foo) -ENV abc \$foo -RUN [ "$abc" = "\$foo" ] && (echo "$abc" | grep foo) - -ENV abc=\'foo\' abc2=\"foo\" -RUN [ "$abc,$abc2" = "'foo',\"foo\"" ] -ENV abc "foo" -RUN [ "$abc" = "foo" ] -ENV abc 'foo' -RUN [ "$abc" = 'foo' ] -ENV abc \'foo\' -RUN [ "$abc" = "'foo'" ] -ENV abc \"foo\" -RUN [ "$abc" = '"foo"' ] - -ENV abc=ABC -RUN [ "$abc" = "ABC" ] -ENV def1=${abc:-DEF} def2=${ccc:-DEF} -ENV def3=${ccc:-${def2}xx} def4=${abc:+ALT} def5=${def2:+${abc}:} def6=${ccc:-\$abc:} def7=${ccc:-\${abc}:} -RUN [ "$def1,$def2,$def3,$def4,$def5,$def6,$def7" = 'ABC,DEF,DEFxx,ALT,ABC:,$abc:,${abc:}' ] -ENV mypath=${mypath:+$mypath:}/home -ENV mypath=${mypath:+$mypath:}/away -RUN [ "$mypath" = '/home:/away' ] - -ENV e1=bar -ENV e2=$e1 e3=$e11 e4=\$e1 e5=\$e11 -RUN [ "$e0,$e1,$e2,$e3,$e4,$e5" = ',bar,bar,,$e1,$e11' ] - -ENV ee1 bar -ENV ee2 $ee1 -ENV ee3 $ee11 -ENV ee4 \$ee1 -ENV ee5 \$ee11 -RUN [ "$ee1,$ee2,$ee3,$ee4,$ee5" = 'bar,bar,,$ee1,$ee11' ] - -ENV eee1="foo" eee2='foo' -ENV eee3 "foo" -ENV eee4 'foo' -RUN [ "$eee1,$eee2,$eee3,$eee4" = 'foo,foo,foo,foo' ] - -` - ctx, err := fakeContext(dockerfile, map[string]string{ - "hello/docker/world": "hello", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - _, err = buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildAddScript(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildaddscript" - dockerfile := ` -FROM busybox -ADD test /test -RUN ["chmod","+x","/test"] -RUN ["/test"] -RUN [ "$(cat /testfile)" = 'test!' ]` - ctx, err := fakeContext(dockerfile, map[string]string{ - "test": "#!/bin/sh\necho 'test!' > /testfile", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - _, err = buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildAddTar(c *check.C) { - // /test/foo is not owned by the correct user - testRequires(c, NotUserNamespace) - name := "testbuildaddtar" - - ctx := func() *FakeContext { - dockerfile := ` -FROM busybox -ADD test.tar / -RUN cat /test/foo | grep Hi -ADD test.tar /test.tar -RUN cat /test.tar/test/foo | grep Hi -ADD test.tar /unlikely-to-exist -RUN cat /unlikely-to-exist/test/foo | grep Hi -ADD test.tar /unlikely-to-exist-trailing-slash/ -RUN cat /unlikely-to-exist-trailing-slash/test/foo | grep Hi -RUN sh -c "mkdir /existing-directory" #sh -c is needed on Windows to use the correct mkdir -ADD test.tar /existing-directory -RUN cat /existing-directory/test/foo | grep Hi -ADD test.tar /existing-directory-trailing-slash/ -RUN cat /existing-directory-trailing-slash/test/foo | grep Hi` - tmpDir, err := ioutil.TempDir("", "fake-context") - c.Assert(err, check.IsNil) - testTar, err := os.Create(filepath.Join(tmpDir, "test.tar")) - if err != nil { - c.Fatalf("failed to create test.tar archive: %v", err) - } - defer testTar.Close() - - tw := tar.NewWriter(testTar) - - if err := tw.WriteHeader(&tar.Header{ - Name: "test/foo", - Size: 2, - }); err != nil { - c.Fatalf("failed to write tar file header: %v", err) - } - if _, err := tw.Write([]byte("Hi")); err != nil { - c.Fatalf("failed to write tar file content: %v", err) - } - if err := tw.Close(); err != nil { - c.Fatalf("failed to close tar archive: %v", err) - } - - if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil { - c.Fatalf("failed to open destination dockerfile: %v", err) - } - return fakeContextFromDir(tmpDir) - }() - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("build failed to complete for TestBuildAddTar: %v", err) - } - -} - -func (s *DockerSuite) TestBuildAddBrokenTar(c *check.C) { - name := "testbuildaddbrokentar" - - ctx := func() *FakeContext { - dockerfile := ` -FROM busybox -ADD test.tar /` - tmpDir, err := ioutil.TempDir("", "fake-context") - c.Assert(err, check.IsNil) - testTar, err := os.Create(filepath.Join(tmpDir, "test.tar")) - if err != nil { - c.Fatalf("failed to create test.tar archive: %v", err) - } - defer testTar.Close() - - tw := tar.NewWriter(testTar) - - if err := tw.WriteHeader(&tar.Header{ - Name: "test/foo", - Size: 2, - }); err != nil { - c.Fatalf("failed to write tar file header: %v", err) - } - if _, err := tw.Write([]byte("Hi")); err != nil { - c.Fatalf("failed to write tar file content: %v", err) - } - if err := tw.Close(); err != nil { - c.Fatalf("failed to close tar archive: %v", err) - } - - // Corrupt the tar by removing one byte off the end - stat, err := testTar.Stat() - if err != nil { - c.Fatalf("failed to stat tar archive: %v", err) - } - if err := testTar.Truncate(stat.Size() - 1); err != nil { - c.Fatalf("failed to truncate tar archive: %v", err) - } - - if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil { - c.Fatalf("failed to open destination dockerfile: %v", err) - } - return fakeContextFromDir(tmpDir) - }() - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err == nil { - c.Fatalf("build should have failed for TestBuildAddBrokenTar") - } -} - -func (s *DockerSuite) TestBuildAddNonTar(c *check.C) { - name := "testbuildaddnontar" - - // Should not try to extract test.tar - ctx, err := fakeContext(` - FROM busybox - ADD test.tar / - RUN test -f /test.tar`, - map[string]string{"test.tar": "not_a_tar_file"}) - - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("build failed for TestBuildAddNonTar") - } -} - -func (s *DockerSuite) TestBuildAddTarXz(c *check.C) { - // /test/foo is not owned by the correct user - testRequires(c, NotUserNamespace) - testRequires(c, DaemonIsLinux) - name := "testbuildaddtarxz" - - ctx := func() *FakeContext { - dockerfile := ` - FROM busybox - ADD test.tar.xz / - RUN cat /test/foo | grep Hi` - tmpDir, err := ioutil.TempDir("", "fake-context") - c.Assert(err, check.IsNil) - testTar, err := os.Create(filepath.Join(tmpDir, "test.tar")) - if err != nil { - c.Fatalf("failed to create test.tar archive: %v", err) - } - defer testTar.Close() - - tw := tar.NewWriter(testTar) - - if err := tw.WriteHeader(&tar.Header{ - Name: "test/foo", - Size: 2, - }); err != nil { - c.Fatalf("failed to write tar file header: %v", err) - } - if _, err := tw.Write([]byte("Hi")); err != nil { - c.Fatalf("failed to write tar file content: %v", err) - } - if err := tw.Close(); err != nil { - c.Fatalf("failed to close tar archive: %v", err) - } - - xzCompressCmd := exec.Command("xz", "-k", "test.tar") - xzCompressCmd.Dir = tmpDir - out, _, err := runCommandWithOutput(xzCompressCmd) - if err != nil { - c.Fatal(err, out) - } - - if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil { - c.Fatalf("failed to open destination dockerfile: %v", err) - } - return fakeContextFromDir(tmpDir) - }() - - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("build failed to complete for TestBuildAddTarXz: %v", err) - } - -} - -func (s *DockerSuite) TestBuildAddTarXzGz(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildaddtarxzgz" - - ctx := func() *FakeContext { - dockerfile := ` - FROM busybox - ADD test.tar.xz.gz / - RUN ls /test.tar.xz.gz` - tmpDir, err := ioutil.TempDir("", "fake-context") - c.Assert(err, check.IsNil) - testTar, err := os.Create(filepath.Join(tmpDir, "test.tar")) - if err != nil { - c.Fatalf("failed to create test.tar archive: %v", err) - } - defer testTar.Close() - - tw := tar.NewWriter(testTar) - - if err := tw.WriteHeader(&tar.Header{ - Name: "test/foo", - Size: 2, - }); err != nil { - c.Fatalf("failed to write tar file header: %v", err) - } - if _, err := tw.Write([]byte("Hi")); err != nil { - c.Fatalf("failed to write tar file content: %v", err) - } - if err := tw.Close(); err != nil { - c.Fatalf("failed to close tar archive: %v", err) - } - - xzCompressCmd := exec.Command("xz", "-k", "test.tar") - xzCompressCmd.Dir = tmpDir - out, _, err := runCommandWithOutput(xzCompressCmd) - if err != nil { - c.Fatal(err, out) - } - - gzipCompressCmd := exec.Command("gzip", "test.tar.xz") - gzipCompressCmd.Dir = tmpDir - out, _, err = runCommandWithOutput(gzipCompressCmd) - if err != nil { - c.Fatal(err, out) - } - - if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil { - c.Fatalf("failed to open destination dockerfile: %v", err) - } - return fakeContextFromDir(tmpDir) - }() - - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("build failed to complete for TestBuildAddTarXz: %v", err) - } - -} - -func (s *DockerSuite) TestBuildFromGit(c *check.C) { - name := "testbuildfromgit" - git, err := newFakeGit("repo", map[string]string{ - "Dockerfile": `FROM busybox - ADD first /first - RUN [ -f /first ] - MAINTAINER docker`, - "first": "test git data", - }, true) - if err != nil { - c.Fatal(err) - } - defer git.Close() - - _, err = buildImageFromPath(name, git.RepoURL, true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Author") - if res != "docker" { - c.Fatalf("Maintainer should be docker, got %s", res) - } -} - -func (s *DockerSuite) TestBuildFromGitWithContext(c *check.C) { - name := "testbuildfromgit" - git, err := newFakeGit("repo", map[string]string{ - "docker/Dockerfile": `FROM busybox - ADD first /first - RUN [ -f /first ] - MAINTAINER docker`, - "docker/first": "test git data", - }, true) - if err != nil { - c.Fatal(err) - } - defer git.Close() - - u := fmt.Sprintf("%s#master:docker", git.RepoURL) - _, err = buildImageFromPath(name, u, true) - if err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Author") - if res != "docker" { - c.Fatalf("Maintainer should be docker, got %s", res) - } -} - -func (s *DockerSuite) TestBuildFromGitwithF(c *check.C) { - name := "testbuildfromgitwithf" - git, err := newFakeGit("repo", map[string]string{ - "myApp/myDockerfile": `FROM busybox - RUN echo hi from Dockerfile`, - }, true) - if err != nil { - c.Fatal(err) - } - defer git.Close() - - out, _, err := dockerCmdWithError("build", "-t", name, "--no-cache", "-f", "myApp/myDockerfile", git.RepoURL) - if err != nil { - c.Fatalf("Error on build. Out: %s\nErr: %v", out, err) - } - - if !strings.Contains(out, "hi from Dockerfile") { - c.Fatalf("Missing expected output, got:\n%s", out) - } -} - -func (s *DockerSuite) TestBuildFromRemoteTarball(c *check.C) { - name := "testbuildfromremotetarball" - - buffer := new(bytes.Buffer) - tw := tar.NewWriter(buffer) - defer tw.Close() - - dockerfile := []byte(`FROM busybox - MAINTAINER docker`) - if err := tw.WriteHeader(&tar.Header{ - Name: "Dockerfile", - Size: int64(len(dockerfile)), - }); err != nil { - c.Fatalf("failed to write tar file header: %v", err) - } - if _, err := tw.Write(dockerfile); err != nil { - c.Fatalf("failed to write tar file content: %v", err) - } - if err := tw.Close(); err != nil { - c.Fatalf("failed to close tar archive: %v", err) - } - - server, err := fakeBinaryStorage(map[string]*bytes.Buffer{ - "testT.tar": buffer, - }) - c.Assert(err, check.IsNil) - - defer server.Close() - - _, err = buildImageFromPath(name, server.URL()+"/testT.tar", true) - c.Assert(err, check.IsNil) - - res := inspectField(c, name, "Author") - - if res != "docker" { - c.Fatalf("Maintainer should be docker, got %s", res) - } -} - -func (s *DockerSuite) TestBuildCleanupCmdOnEntrypoint(c *check.C) { - name := "testbuildcmdcleanuponentrypoint" - if _, err := buildImage(name, - `FROM `+minimalBaseImage()+` - CMD ["test"] - ENTRYPOINT ["echo"]`, - true); err != nil { - c.Fatal(err) - } - if _, err := buildImage(name, - fmt.Sprintf(`FROM %s - ENTRYPOINT ["cat"]`, name), - true); err != nil { - c.Fatal(err) - } - res := inspectField(c, name, "Config.Cmd") - if res != "[]" { - c.Fatalf("Cmd %s, expected nil", res) - } - - res = inspectField(c, name, "Config.Entrypoint") - if expected := "[cat]"; res != expected { - c.Fatalf("Entrypoint %s, expected %s", res, expected) - } -} - -func (s *DockerSuite) TestBuildClearCmd(c *check.C) { - name := "testbuildclearcmd" - _, err := buildImage(name, - `From `+minimalBaseImage()+` - ENTRYPOINT ["/bin/bash"] - CMD []`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectFieldJSON(c, name, "Config.Cmd") - if res != "[]" { - c.Fatalf("Cmd %s, expected %s", res, "[]") - } -} - -func (s *DockerSuite) TestBuildEmptyCmd(c *check.C) { - // Skip on Windows. Base image on Windows has a CMD set in the image. - testRequires(c, DaemonIsLinux) - - name := "testbuildemptycmd" - if _, err := buildImage(name, "FROM "+minimalBaseImage()+"\nMAINTAINER quux\n", true); err != nil { - c.Fatal(err) - } - res := inspectFieldJSON(c, name, "Config.Cmd") - if res != "null" { - c.Fatalf("Cmd %s, expected %s", res, "null") - } -} - -func (s *DockerSuite) TestBuildOnBuildOutput(c *check.C) { - name := "testbuildonbuildparent" - if _, err := buildImage(name, "FROM busybox\nONBUILD RUN echo foo\n", true); err != nil { - c.Fatal(err) - } - - _, out, err := buildImageWithOut(name, "FROM "+name+"\nMAINTAINER quux\n", true) - if err != nil { - c.Fatal(err) - } - - if !strings.Contains(out, "# Executing 1 build trigger") { - c.Fatal("failed to find the build trigger output", out) - } -} - -func (s *DockerSuite) TestBuildInvalidTag(c *check.C) { - name := "abcd:" + stringutils.GenerateRandomAlphaOnlyString(200) - _, out, err := buildImageWithOut(name, "FROM "+minimalBaseImage()+"\nMAINTAINER quux\n", true) - // if the error doesn't check for illegal tag name, or the image is built - // then this should fail - if !strings.Contains(out, "Error parsing reference") || strings.Contains(out, "Sending build context to Docker daemon") { - c.Fatalf("failed to stop before building. Error: %s, Output: %s", err, out) - } -} - -func (s *DockerSuite) TestBuildCmdShDashC(c *check.C) { - name := "testbuildcmdshc" - if _, err := buildImage(name, "FROM busybox\nCMD echo cmd\n", true); err != nil { - c.Fatal(err) - } - - res := inspectFieldJSON(c, name, "Config.Cmd") - - expected := `["/bin/sh","-c","echo cmd"]` - if daemonPlatform == "windows" { - expected = `["cmd","/S","/C","echo cmd"]` - } - - if res != expected { - c.Fatalf("Expected value %s not in Config.Cmd: %s", expected, res) - } - -} - -func (s *DockerSuite) TestBuildCmdSpaces(c *check.C) { - // Test to make sure that when we strcat arrays we take into account - // the arg separator to make sure ["echo","hi"] and ["echo hi"] don't - // look the same - name := "testbuildcmdspaces" - var id1 string - var id2 string - var err error - - if id1, err = buildImage(name, "FROM busybox\nCMD [\"echo hi\"]\n", true); err != nil { - c.Fatal(err) - } - - if id2, err = buildImage(name, "FROM busybox\nCMD [\"echo\", \"hi\"]\n", true); err != nil { - c.Fatal(err) - } - - if id1 == id2 { - c.Fatal("Should not have resulted in the same CMD") - } - - // Now do the same with ENTRYPOINT - if id1, err = buildImage(name, "FROM busybox\nENTRYPOINT [\"echo hi\"]\n", true); err != nil { - c.Fatal(err) - } - - if id2, err = buildImage(name, "FROM busybox\nENTRYPOINT [\"echo\", \"hi\"]\n", true); err != nil { - c.Fatal(err) - } - - if id1 == id2 { - c.Fatal("Should not have resulted in the same ENTRYPOINT") - } - -} - -func (s *DockerSuite) TestBuildCmdJSONNoShDashC(c *check.C) { - name := "testbuildcmdjson" - if _, err := buildImage(name, "FROM busybox\nCMD [\"echo\", \"cmd\"]", true); err != nil { - c.Fatal(err) - } - - res := inspectFieldJSON(c, name, "Config.Cmd") - - expected := `["echo","cmd"]` - - if res != expected { - c.Fatalf("Expected value %s not in Config.Cmd: %s", expected, res) - } - -} - -func (s *DockerSuite) TestBuildEntrypointInheritance(c *check.C) { - - if _, err := buildImage("parent", ` - FROM busybox - ENTRYPOINT exit 130 - `, true); err != nil { - c.Fatal(err) - } - - if _, status, _ := dockerCmdWithError("run", "parent"); status != 130 { - c.Fatalf("expected exit code 130 but received %d", status) - } - - if _, err := buildImage("child", ` - FROM parent - ENTRYPOINT exit 5 - `, true); err != nil { - c.Fatal(err) - } - - if _, status, _ := dockerCmdWithError("run", "child"); status != 5 { - c.Fatalf("expected exit code 5 but received %d", status) - } - -} - -func (s *DockerSuite) TestBuildEntrypointInheritanceInspect(c *check.C) { - var ( - name = "testbuildepinherit" - name2 = "testbuildepinherit2" - expected = `["/bin/sh","-c","echo quux"]` - ) - - if daemonPlatform == "windows" { - expected = `["cmd","/S","/C","echo quux"]` - } - - if _, err := buildImage(name, "FROM busybox\nENTRYPOINT /foo/bar", true); err != nil { - c.Fatal(err) - } - - if _, err := buildImage(name2, fmt.Sprintf("FROM %s\nENTRYPOINT echo quux", name), true); err != nil { - c.Fatal(err) - } - - res := inspectFieldJSON(c, name2, "Config.Entrypoint") - - if res != expected { - c.Fatalf("Expected value %s not in Config.Entrypoint: %s", expected, res) - } - - out, _ := dockerCmd(c, "run", name2) - - expected = "quux" - - if strings.TrimSpace(out) != expected { - c.Fatalf("Expected output is %s, got %s", expected, out) - } - -} - -func (s *DockerSuite) TestBuildRunShEntrypoint(c *check.C) { - name := "testbuildentrypoint" - _, err := buildImage(name, - `FROM busybox - ENTRYPOINT echo`, - true) - if err != nil { - c.Fatal(err) - } - - dockerCmd(c, "run", "--rm", name) -} - -func (s *DockerSuite) TestBuildExoticShellInterpolation(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildexoticshellinterpolation" - - _, err := buildImage(name, ` - FROM busybox - - ENV SOME_VAR a.b.c - - RUN [ "$SOME_VAR" = 'a.b.c' ] - RUN [ "${SOME_VAR}" = 'a.b.c' ] - RUN [ "${SOME_VAR%.*}" = 'a.b' ] - RUN [ "${SOME_VAR%%.*}" = 'a' ] - RUN [ "${SOME_VAR#*.}" = 'b.c' ] - RUN [ "${SOME_VAR##*.}" = 'c' ] - RUN [ "${SOME_VAR/c/d}" = 'a.b.d' ] - RUN [ "${#SOME_VAR}" = '5' ] - - RUN [ "${SOME_UNSET_VAR:-$SOME_VAR}" = 'a.b.c' ] - RUN [ "${SOME_VAR:+Version: ${SOME_VAR}}" = 'Version: a.b.c' ] - RUN [ "${SOME_UNSET_VAR:+${SOME_VAR}}" = '' ] - RUN [ "${SOME_UNSET_VAR:-${SOME_VAR:-d.e.f}}" = 'a.b.c' ] - `, false) - if err != nil { - c.Fatal(err) - } - -} - -func (s *DockerSuite) TestBuildVerifySingleQuoteFails(c *check.C) { - // This testcase is supposed to generate an error because the - // JSON array we're passing in on the CMD uses single quotes instead - // of double quotes (per the JSON spec). This means we interpret it - // as a "string" instead of "JSON array" and pass it on to "sh -c" and - // it should barf on it. - name := "testbuildsinglequotefails" - - if _, err := buildImage(name, - `FROM busybox - CMD [ '/bin/sh', '-c', 'echo hi' ]`, - true); err != nil { - c.Fatal(err) - } - - if _, _, err := dockerCmdWithError("run", "--rm", name); err == nil { - c.Fatal("The image was not supposed to be able to run") - } - -} - -func (s *DockerSuite) TestBuildVerboseOut(c *check.C) { - name := "testbuildverboseout" - expected := "\n123\n" - - if daemonPlatform == "windows" { - expected = "\n123\r\n" - } - - _, out, err := buildImageWithOut(name, - `FROM busybox -RUN echo 123`, - false) - - if err != nil { - c.Fatal(err) - } - if !strings.Contains(out, expected) { - c.Fatalf("Output should contain %q: %q", "123", out) - } - -} - -func (s *DockerSuite) TestBuildWithTabs(c *check.C) { - name := "testbuildwithtabs" - _, err := buildImage(name, - "FROM busybox\nRUN echo\tone\t\ttwo", true) - if err != nil { - c.Fatal(err) - } - res := inspectFieldJSON(c, name, "ContainerConfig.Cmd") - expected1 := `["/bin/sh","-c","echo\tone\t\ttwo"]` - expected2 := `["/bin/sh","-c","echo\u0009one\u0009\u0009two"]` // syntactically equivalent, and what Go 1.3 generates - if daemonPlatform == "windows" { - expected1 = `["cmd","/S","/C","echo\tone\t\ttwo"]` - expected2 = `["cmd","/S","/C","echo\u0009one\u0009\u0009two"]` // syntactically equivalent, and what Go 1.3 generates - } - if res != expected1 && res != expected2 { - c.Fatalf("Missing tabs.\nGot: %s\nExp: %s or %s", res, expected1, expected2) - } -} - -func (s *DockerSuite) TestBuildLabels(c *check.C) { - name := "testbuildlabel" - expected := `{"License":"GPL","Vendor":"Acme"}` - _, err := buildImage(name, - `FROM busybox - LABEL Vendor=Acme - LABEL License GPL`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectFieldJSON(c, name, "Config.Labels") - if res != expected { - c.Fatalf("Labels %s, expected %s", res, expected) - } -} - -func (s *DockerSuite) TestBuildLabelsCache(c *check.C) { - name := "testbuildlabelcache" - - id1, err := buildImage(name, - `FROM busybox - LABEL Vendor=Acme`, false) - if err != nil { - c.Fatalf("Build 1 should have worked: %v", err) - } - - id2, err := buildImage(name, - `FROM busybox - LABEL Vendor=Acme`, true) - if err != nil || id1 != id2 { - c.Fatalf("Build 2 should have worked & used cache(%s,%s): %v", id1, id2, err) - } - - id2, err = buildImage(name, - `FROM busybox - LABEL Vendor=Acme1`, true) - if err != nil || id1 == id2 { - c.Fatalf("Build 3 should have worked & NOT used cache(%s,%s): %v", id1, id2, err) - } - - id2, err = buildImage(name, - `FROM busybox - LABEL Vendor Acme`, true) // Note: " " and "=" should be same - if err != nil || id1 != id2 { - c.Fatalf("Build 4 should have worked & used cache(%s,%s): %v", id1, id2, err) - } - - // Now make sure the cache isn't used by mistake - id1, err = buildImage(name, - `FROM busybox - LABEL f1=b1 f2=b2`, false) - if err != nil { - c.Fatalf("Build 5 should have worked: %q", err) - } - - id2, err = buildImage(name, - `FROM busybox - LABEL f1="b1 f2=b2"`, true) - if err != nil || id1 == id2 { - c.Fatalf("Build 6 should have worked & NOT used the cache(%s,%s): %q", id1, id2, err) - } - -} - -func (s *DockerSuite) TestBuildNotVerboseSuccess(c *check.C) { - // This test makes sure that -q works correctly when build is successful: - // stdout has only the image ID (long image ID) and stderr is empty. - var stdout, stderr string - var err error - outRegexp := regexp.MustCompile("^(sha256:|)[a-z0-9]{64}\\n$") - - tt := []struct { - Name string - BuildFunc func(string) - }{ - { - Name: "quiet_build_stdin_success", - BuildFunc: func(name string) { - _, stdout, stderr, err = buildImageWithStdoutStderr(name, "FROM busybox", true, "-q", "--force-rm", "--rm") - }, - }, - { - Name: "quiet_build_ctx_success", - BuildFunc: func(name string) { - ctx, err := fakeContext("FROM busybox", map[string]string{ - "quiet_build_success_fctx": "test", - }) - if err != nil { - c.Fatalf("Failed to create context: %s", err.Error()) - } - defer ctx.Close() - _, stdout, stderr, err = buildImageFromContextWithStdoutStderr(name, ctx, true, "-q", "--force-rm", "--rm") - }, - }, - { - Name: "quiet_build_git_success", - BuildFunc: func(name string) { - git, err := newFakeGit("repo", map[string]string{ - "Dockerfile": "FROM busybox", - }, true) - if err != nil { - c.Fatalf("Failed to create the git repo: %s", err.Error()) - } - defer git.Close() - _, stdout, stderr, err = buildImageFromGitWithStdoutStderr(name, git, true, "-q", "--force-rm", "--rm") - - }, - }, - } - - for _, te := range tt { - te.BuildFunc(te.Name) - if err != nil { - c.Fatalf("Test %s shouldn't fail, but got the following error: %s", te.Name, err.Error()) - } - if outRegexp.Find([]byte(stdout)) == nil { - c.Fatalf("Test %s expected stdout to match the [%v] regexp, but it is [%v]", te.Name, outRegexp, stdout) - } - - if stderr != "" { - c.Fatalf("Test %s expected stderr to be empty, but it is [%#v]", te.Name, stderr) - } - } - -} - -func (s *DockerSuite) TestBuildNotVerboseFailureWithNonExistImage(c *check.C) { - // This test makes sure that -q works correctly when build fails by - // comparing between the stderr output in quiet mode and in stdout - // and stderr output in verbose mode - testRequires(c, Network) - testName := "quiet_build_not_exists_image" - buildCmd := "FROM busybox11" - _, _, qstderr, qerr := buildImageWithStdoutStderr(testName, buildCmd, false, "-q", "--force-rm", "--rm") - _, vstdout, vstderr, verr := buildImageWithStdoutStderr(testName, buildCmd, false, "--force-rm", "--rm") - if verr == nil || qerr == nil { - c.Fatal(fmt.Errorf("Test [%s] expected to fail but didn't", testName)) - } - if qstderr != vstdout+vstderr { - c.Fatal(fmt.Errorf("Test[%s] expected that quiet stderr and verbose stdout are equal; quiet [%v], verbose [%v]", testName, qstderr, vstdout+vstderr)) - } -} - -func (s *DockerSuite) TestBuildNotVerboseFailure(c *check.C) { - // This test makes sure that -q works correctly when build fails by - // comparing between the stderr output in quiet mode and in stdout - // and stderr output in verbose mode - tt := []struct { - TestName string - BuildCmds string - }{ - {"quiet_build_no_from_at_the_beginning", "RUN whoami"}, - {"quiet_build_unknown_instr", "FROMD busybox"}, - } - - for _, te := range tt { - _, _, qstderr, qerr := buildImageWithStdoutStderr(te.TestName, te.BuildCmds, false, "-q", "--force-rm", "--rm") - _, vstdout, vstderr, verr := buildImageWithStdoutStderr(te.TestName, te.BuildCmds, false, "--force-rm", "--rm") - if verr == nil || qerr == nil { - c.Fatal(fmt.Errorf("Test [%s] expected to fail but didn't", te.TestName)) - } - if qstderr != vstdout+vstderr { - c.Fatal(fmt.Errorf("Test[%s] expected that quiet stderr and verbose stdout are equal; quiet [%v], verbose [%v]", te.TestName, qstderr, vstdout+vstderr)) - } - } -} - -func (s *DockerSuite) TestBuildNotVerboseFailureRemote(c *check.C) { - // This test ensures that when given a wrong URL, stderr in quiet mode and - // stderr in verbose mode are identical. - // TODO(vdemeester) with cobra, stdout has a carriage return too much so this test should not check stdout - URL := "http://something.invalid" - Name := "quiet_build_wrong_remote" - _, _, qstderr, qerr := buildImageWithStdoutStderr(Name, "", false, "-q", "--force-rm", "--rm", URL) - _, _, vstderr, verr := buildImageWithStdoutStderr(Name, "", false, "--force-rm", "--rm", URL) - if qerr == nil || verr == nil { - c.Fatal(fmt.Errorf("Test [%s] expected to fail but didn't", Name)) - } - if qstderr != vstderr { - c.Fatal(fmt.Errorf("Test[%s] expected that quiet stderr and verbose stdout are equal; quiet [%v], verbose [%v]", Name, qstderr, vstderr)) - } -} - -func (s *DockerSuite) TestBuildStderr(c *check.C) { - // This test just makes sure that no non-error output goes - // to stderr - name := "testbuildstderr" - _, _, stderr, err := buildImageWithStdoutStderr(name, - "FROM busybox\nRUN echo one", true) - if err != nil { - c.Fatal(err) - } - - if runtime.GOOS == "windows" && - daemonPlatform != "windows" { - // Windows to non-Windows should have a security warning - if !strings.Contains(stderr, "SECURITY WARNING:") { - c.Fatalf("Stderr contains unexpected output: %q", stderr) - } - } else { - // Other platform combinations should have no stderr written too - if stderr != "" { - c.Fatalf("Stderr should have been empty, instead it's: %q", stderr) - } - } -} - -func (s *DockerSuite) TestBuildChownSingleFile(c *check.C) { - testRequires(c, UnixCli) // test uses chown: not available on windows - testRequires(c, DaemonIsLinux) - - name := "testbuildchownsinglefile" - - ctx, err := fakeContext(` -FROM busybox -COPY test / -RUN ls -l /test -RUN [ $(ls -l /test | awk '{print $3":"$4}') = 'root:root' ] -`, map[string]string{ - "test": "test", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if err := os.Chown(filepath.Join(ctx.Dir, "test"), 4242, 4242); err != nil { - c.Fatal(err) - } - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - -} - -func (s *DockerSuite) TestBuildSymlinkBreakout(c *check.C) { - name := "testbuildsymlinkbreakout" - tmpdir, err := ioutil.TempDir("", name) - c.Assert(err, check.IsNil) - defer os.RemoveAll(tmpdir) - ctx := filepath.Join(tmpdir, "context") - if err := os.MkdirAll(ctx, 0755); err != nil { - c.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(ctx, "Dockerfile"), []byte(` - from busybox - add symlink.tar / - add inject /symlink/ - `), 0644); err != nil { - c.Fatal(err) - } - inject := filepath.Join(ctx, "inject") - if err := ioutil.WriteFile(inject, nil, 0644); err != nil { - c.Fatal(err) - } - f, err := os.Create(filepath.Join(ctx, "symlink.tar")) - if err != nil { - c.Fatal(err) - } - w := tar.NewWriter(f) - w.WriteHeader(&tar.Header{ - Name: "symlink2", - Typeflag: tar.TypeSymlink, - Linkname: "/../../../../../../../../../../../../../../", - Uid: os.Getuid(), - Gid: os.Getgid(), - }) - w.WriteHeader(&tar.Header{ - Name: "symlink", - Typeflag: tar.TypeSymlink, - Linkname: filepath.Join("symlink2", tmpdir), - Uid: os.Getuid(), - Gid: os.Getgid(), - }) - w.Close() - f.Close() - if _, err := buildImageFromContext(name, fakeContextFromDir(ctx), false); err != nil { - c.Fatal(err) - } - if _, err := os.Lstat(filepath.Join(tmpdir, "inject")); err == nil { - c.Fatal("symlink breakout - inject") - } else if !os.IsNotExist(err) { - c.Fatalf("unexpected error: %v", err) - } -} - -func (s *DockerSuite) TestBuildXZHost(c *check.C) { - // /usr/local/sbin/xz gets permission denied for the user - testRequires(c, NotUserNamespace) - testRequires(c, DaemonIsLinux) - name := "testbuildxzhost" - - ctx, err := fakeContext(` -FROM busybox -ADD xz /usr/local/sbin/ -RUN chmod 755 /usr/local/sbin/xz -ADD test.xz / -RUN [ ! -e /injected ]`, - map[string]string{ - "test.xz": "\xfd\x37\x7a\x58\x5a\x00\x00\x04\xe6\xd6\xb4\x46\x02\x00" + - "\x21\x01\x16\x00\x00\x00\x74\x2f\xe5\xa3\x01\x00\x3f\xfd" + - "\x37\x7a\x58\x5a\x00\x00\x04\xe6\xd6\xb4\x46\x02\x00\x21", - "xz": "#!/bin/sh\ntouch /injected", - }) - - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } - -} - -func (s *DockerSuite) TestBuildVolumesRetainContents(c *check.C) { - // /foo/file gets permission denied for the user - testRequires(c, NotUserNamespace) - testRequires(c, DaemonIsLinux) // TODO Windows: Issue #20127 - var ( - name = "testbuildvolumescontent" - expected = "some text" - volName = "/foo" - ) - - if daemonPlatform == "windows" { - volName = "C:/foo" - } - - ctx, err := fakeContext(` -FROM busybox -COPY content /foo/file -VOLUME `+volName+` -CMD cat /foo/file`, - map[string]string{ - "content": expected, - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, false); err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", "--rm", name) - if out != expected { - c.Fatalf("expected file contents for /foo/file to be %q but received %q", expected, out) - } - -} - -func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) { - - ctx, err := fakeContext(`FROM busybox - RUN echo from Dockerfile`, - map[string]string{ - "Dockerfile": "FROM busybox\nRUN echo from Dockerfile", - "files/Dockerfile": "FROM busybox\nRUN echo from files/Dockerfile", - "files/dFile": "FROM busybox\nRUN echo from files/dFile", - "dFile": "FROM busybox\nRUN echo from dFile", - "files/dFile2": "FROM busybox\nRUN echo from files/dFile2", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".") - if err != nil { - c.Fatalf("Failed to build: %s\n%s", out, err) - } - if !strings.Contains(out, "from Dockerfile") { - c.Fatalf("test1 should have used Dockerfile, output:%s", out) - } - - out, _, err = dockerCmdInDir(c, ctx.Dir, "build", "-f", filepath.Join("files", "Dockerfile"), "-t", "test2", ".") - if err != nil { - c.Fatal(err) - } - if !strings.Contains(out, "from files/Dockerfile") { - c.Fatalf("test2 should have used files/Dockerfile, output:%s", out) - } - - out, _, err = dockerCmdInDir(c, ctx.Dir, "build", fmt.Sprintf("--file=%s", filepath.Join("files", "dFile")), "-t", "test3", ".") - if err != nil { - c.Fatal(err) - } - if !strings.Contains(out, "from files/dFile") { - c.Fatalf("test3 should have used files/dFile, output:%s", out) - } - - out, _, err = dockerCmdInDir(c, ctx.Dir, "build", "--file=dFile", "-t", "test4", ".") - if err != nil { - c.Fatal(err) - } - if !strings.Contains(out, "from dFile") { - c.Fatalf("test4 should have used dFile, output:%s", out) - } - - dirWithNoDockerfile, err := ioutil.TempDir(os.TempDir(), "test5") - c.Assert(err, check.IsNil) - nonDockerfileFile := filepath.Join(dirWithNoDockerfile, "notDockerfile") - if _, err = os.Create(nonDockerfileFile); err != nil { - c.Fatal(err) - } - out, _, err = dockerCmdInDir(c, ctx.Dir, "build", fmt.Sprintf("--file=%s", nonDockerfileFile), "-t", "test5", ".") - - if err == nil { - c.Fatalf("test5 was supposed to fail to find passwd") - } - - if expected := fmt.Sprintf("The Dockerfile (%s) must be within the build context (.)", nonDockerfileFile); !strings.Contains(out, expected) { - c.Fatalf("wrong error message:%v\nexpected to contain=%v", out, expected) - } - - out, _, err = dockerCmdInDir(c, filepath.Join(ctx.Dir, "files"), "build", "-f", filepath.Join("..", "Dockerfile"), "-t", "test6", "..") - if err != nil { - c.Fatalf("test6 failed: %s", err) - } - if !strings.Contains(out, "from Dockerfile") { - c.Fatalf("test6 should have used root Dockerfile, output:%s", out) - } - - out, _, err = dockerCmdInDir(c, filepath.Join(ctx.Dir, "files"), "build", "-f", filepath.Join(ctx.Dir, "files", "Dockerfile"), "-t", "test7", "..") - if err != nil { - c.Fatalf("test7 failed: %s", err) - } - if !strings.Contains(out, "from files/Dockerfile") { - c.Fatalf("test7 should have used files Dockerfile, output:%s", out) - } - - out, _, err = dockerCmdInDir(c, filepath.Join(ctx.Dir, "files"), "build", "-f", filepath.Join("..", "Dockerfile"), "-t", "test8", ".") - if err == nil || !strings.Contains(out, "must be within the build context") { - c.Fatalf("test8 should have failed with Dockerfile out of context: %s", err) - } - - tmpDir := os.TempDir() - out, _, err = dockerCmdInDir(c, tmpDir, "build", "-t", "test9", ctx.Dir) - if err != nil { - c.Fatalf("test9 - failed: %s", err) - } - if !strings.Contains(out, "from Dockerfile") { - c.Fatalf("test9 should have used root Dockerfile, output:%s", out) - } - - out, _, err = dockerCmdInDir(c, filepath.Join(ctx.Dir, "files"), "build", "-f", "dFile2", "-t", "test10", ".") - if err != nil { - c.Fatalf("test10 should have worked: %s", err) - } - if !strings.Contains(out, "from files/dFile2") { - c.Fatalf("test10 should have used files/dFile2, output:%s", out) - } - -} - -func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) { - testRequires(c, UnixCli) // Dockerfile overwrites dockerfile on windows - testRequires(c, DaemonIsLinux) - - ctx, err := fakeContext(`FROM busybox - RUN echo from dockerfile`, - map[string]string{ - "dockerfile": "FROM busybox\nRUN echo from dockerfile", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".") - if err != nil { - c.Fatalf("Failed to build: %s\n%s", out, err) - } - - if !strings.Contains(out, "from dockerfile") { - c.Fatalf("Missing proper output: %s", out) - } - -} - -func (s *DockerSuite) TestBuildWithTwoDockerfiles(c *check.C) { - testRequires(c, UnixCli) // Dockerfile overwrites dockerfile on windows - testRequires(c, DaemonIsLinux) - - ctx, err := fakeContext(`FROM busybox -RUN echo from Dockerfile`, - map[string]string{ - "dockerfile": "FROM busybox\nRUN echo from dockerfile", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".") - if err != nil { - c.Fatalf("Failed to build: %s\n%s", out, err) - } - - if !strings.Contains(out, "from Dockerfile") { - c.Fatalf("Missing proper output: %s", out) - } - -} - -func (s *DockerSuite) TestBuildFromURLWithF(c *check.C) { - server, err := fakeStorage(map[string]string{"baz": `FROM busybox -RUN echo from baz -COPY * /tmp/ -RUN find /tmp/`}) - if err != nil { - c.Fatal(err) - } - defer server.Close() - - ctx, err := fakeContext(`FROM busybox -RUN echo from Dockerfile`, - map[string]string{}) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - // Make sure that -f is ignored and that we don't use the Dockerfile - // that's in the current dir - out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-f", "baz", "-t", "test1", server.URL()+"/baz") - if err != nil { - c.Fatalf("Failed to build: %s\n%s", out, err) - } - - if !strings.Contains(out, "from baz") || - strings.Contains(out, "/tmp/baz") || - !strings.Contains(out, "/tmp/Dockerfile") { - c.Fatalf("Missing proper output: %s", out) - } - -} - -func (s *DockerSuite) TestBuildFromStdinWithF(c *check.C) { - testRequires(c, DaemonIsLinux) // TODO Windows: This test is flaky; no idea why - ctx, err := fakeContext(`FROM busybox -RUN echo "from Dockerfile"`, - map[string]string{}) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - // Make sure that -f is ignored and that we don't use the Dockerfile - // that's in the current dir - dockerCommand := exec.Command(dockerBinary, "build", "-f", "baz", "-t", "test1", "-") - dockerCommand.Dir = ctx.Dir - dockerCommand.Stdin = strings.NewReader(`FROM busybox -RUN echo "from baz" -COPY * /tmp/ -RUN sh -c "find /tmp/" # sh -c is needed on Windows to use the correct find`) - out, status, err := runCommandWithOutput(dockerCommand) - if err != nil || status != 0 { - c.Fatalf("Error building: %s", err) - } - - if !strings.Contains(out, "from baz") || - strings.Contains(out, "/tmp/baz") || - !strings.Contains(out, "/tmp/Dockerfile") { - c.Fatalf("Missing proper output: %s", out) - } - -} - -func (s *DockerSuite) TestBuildFromOfficialNames(c *check.C) { - name := "testbuildfromofficial" - fromNames := []string{ - "busybox", - "docker.io/busybox", - "index.docker.io/busybox", - "library/busybox", - "docker.io/library/busybox", - "index.docker.io/library/busybox", - } - for idx, fromName := range fromNames { - imgName := fmt.Sprintf("%s%d", name, idx) - _, err := buildImage(imgName, "FROM "+fromName, true) - if err != nil { - c.Errorf("Build failed using FROM %s: %s", fromName, err) - } - deleteImages(imgName) - } -} - -func (s *DockerSuite) TestBuildDockerfileOutsideContext(c *check.C) { - testRequires(c, UnixCli) // uses os.Symlink: not implemented in windows at the time of writing (go-1.4.2) - testRequires(c, DaemonIsLinux) - - name := "testbuilddockerfileoutsidecontext" - tmpdir, err := ioutil.TempDir("", name) - c.Assert(err, check.IsNil) - defer os.RemoveAll(tmpdir) - ctx := filepath.Join(tmpdir, "context") - if err := os.MkdirAll(ctx, 0755); err != nil { - c.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(ctx, "Dockerfile"), []byte("FROM scratch\nENV X Y"), 0644); err != nil { - c.Fatal(err) - } - wd, err := os.Getwd() - if err != nil { - c.Fatal(err) - } - defer os.Chdir(wd) - if err := os.Chdir(ctx); err != nil { - c.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(tmpdir, "outsideDockerfile"), []byte("FROM scratch\nENV x y"), 0644); err != nil { - c.Fatal(err) - } - if err := os.Symlink(filepath.Join("..", "outsideDockerfile"), filepath.Join(ctx, "dockerfile1")); err != nil { - c.Fatal(err) - } - if err := os.Symlink(filepath.Join(tmpdir, "outsideDockerfile"), filepath.Join(ctx, "dockerfile2")); err != nil { - c.Fatal(err) - } - - for _, dockerfilePath := range []string{ - filepath.Join("..", "outsideDockerfile"), - filepath.Join(ctx, "dockerfile1"), - filepath.Join(ctx, "dockerfile2"), - } { - result := dockerCmdWithResult("build", "-t", name, "--no-cache", "-f", dockerfilePath, ".") - c.Assert(result, icmd.Matches, icmd.Expected{ - Err: "must be within the build context", - ExitCode: 1, - }) - deleteImages(name) - } - - os.Chdir(tmpdir) - - // Path to Dockerfile should be resolved relative to working directory, not relative to context. - // There is a Dockerfile in the context, but since there is no Dockerfile in the current directory, the following should fail - out, _, err := dockerCmdWithError("build", "-t", name, "--no-cache", "-f", "Dockerfile", ctx) - if err == nil { - c.Fatalf("Expected error. Out: %s", out) - } -} - -func (s *DockerSuite) TestBuildSpaces(c *check.C) { - // Test to make sure that leading/trailing spaces on a command - // doesn't change the error msg we get - var ( - err1 error - err2 error - ) - - name := "testspaces" - ctx, err := fakeContext("FROM busybox\nCOPY\n", - map[string]string{ - "Dockerfile": "FROM busybox\nCOPY\n", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err1 = buildImageFromContext(name, ctx, false); err1 == nil { - c.Fatal("Build 1 was supposed to fail, but didn't") - } - - ctx.Add("Dockerfile", "FROM busybox\nCOPY ") - if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil { - c.Fatal("Build 2 was supposed to fail, but didn't") - } - - removeLogTimestamps := func(s string) string { - return regexp.MustCompile(`time="(.*?)"`).ReplaceAllString(s, `time=[TIMESTAMP]`) - } - - // Skip over the times - e1 := removeLogTimestamps(err1.Error()) - e2 := removeLogTimestamps(err2.Error()) - - // Ignore whitespace since that's what were verifying doesn't change stuff - if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) { - c.Fatalf("Build 2's error wasn't the same as build 1's\n1:%s\n2:%s", err1, err2) - } - - ctx.Add("Dockerfile", "FROM busybox\n COPY") - if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil { - c.Fatal("Build 3 was supposed to fail, but didn't") - } - - // Skip over the times - e1 = removeLogTimestamps(err1.Error()) - e2 = removeLogTimestamps(err2.Error()) - - // Ignore whitespace since that's what were verifying doesn't change stuff - if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) { - c.Fatalf("Build 3's error wasn't the same as build 1's\n1:%s\n3:%s", err1, err2) - } - - ctx.Add("Dockerfile", "FROM busybox\n COPY ") - if _, err2 = buildImageFromContext(name, ctx, false); err2 == nil { - c.Fatal("Build 4 was supposed to fail, but didn't") - } - - // Skip over the times - e1 = removeLogTimestamps(err1.Error()) - e2 = removeLogTimestamps(err2.Error()) - - // Ignore whitespace since that's what were verifying doesn't change stuff - if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) { - c.Fatalf("Build 4's error wasn't the same as build 1's\n1:%s\n4:%s", err1, err2) - } - -} - -func (s *DockerSuite) TestBuildSpacesWithQuotes(c *check.C) { - // Test to make sure that spaces in quotes aren't lost - name := "testspacesquotes" - - dockerfile := `FROM busybox -RUN echo " \ - foo "` - - _, out, err := buildImageWithOut(name, dockerfile, false) - if err != nil { - c.Fatal("Build failed:", err) - } - - expecting := "\n foo \n" - // Windows uses the builtin echo, which preserves quotes - if daemonPlatform == "windows" { - expecting = "\" foo \"" - } - if !strings.Contains(out, expecting) { - c.Fatalf("Bad output: %q expecting to contain %q", out, expecting) - } - -} - -// #4393 -func (s *DockerSuite) TestBuildVolumeFileExistsinContainer(c *check.C) { - testRequires(c, DaemonIsLinux) // TODO Windows: This should error out - buildCmd := exec.Command(dockerBinary, "build", "-t", "docker-test-errcreatevolumewithfile", "-") - buildCmd.Stdin = strings.NewReader(` - FROM busybox - RUN touch /foo - VOLUME /foo - `) - - out, _, err := runCommandWithOutput(buildCmd) - if err == nil || !strings.Contains(out, "file exists") { - c.Fatalf("expected build to fail when file exists in container at requested volume path") - } - -} - -func (s *DockerSuite) TestBuildMissingArgs(c *check.C) { - // Test to make sure that all Dockerfile commands (except the ones listed - // in skipCmds) will generate an error if no args are provided. - // Note: INSERT is deprecated so we exclude it because of that. - skipCmds := map[string]struct{}{ - "CMD": {}, - "RUN": {}, - "ENTRYPOINT": {}, - "INSERT": {}, - } - - if daemonPlatform == "windows" { - skipCmds = map[string]struct{}{ - "CMD": {}, - "RUN": {}, - "ENTRYPOINT": {}, - "INSERT": {}, - "STOPSIGNAL": {}, - "ARG": {}, - "USER": {}, - "EXPOSE": {}, - } - } - - for cmd := range command.Commands { - cmd = strings.ToUpper(cmd) - if _, ok := skipCmds[cmd]; ok { - continue - } - - var dockerfile string - if cmd == "FROM" { - dockerfile = cmd - } else { - // Add FROM to make sure we don't complain about it missing - dockerfile = "FROM busybox\n" + cmd - } - - ctx, err := fakeContext(dockerfile, map[string]string{}) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - var out string - if out, err = buildImageFromContext("args", ctx, true); err == nil { - c.Fatalf("%s was supposed to fail. Out:%s", cmd, out) - } - if !strings.Contains(err.Error(), cmd+" requires") { - c.Fatalf("%s returned the wrong type of error:%s", cmd, err) - } - } - -} - -func (s *DockerSuite) TestBuildEmptyScratch(c *check.C) { - testRequires(c, DaemonIsLinux) - _, out, err := buildImageWithOut("sc", "FROM scratch", true) - if err == nil { - c.Fatalf("Build was supposed to fail") - } - if !strings.Contains(out, "No image was generated") { - c.Fatalf("Wrong error message: %v", out) - } -} - -func (s *DockerSuite) TestBuildDotDotFile(c *check.C) { - ctx, err := fakeContext("FROM busybox\n", - map[string]string{ - "..gitme": "", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err = buildImageFromContext("sc", ctx, false); err != nil { - c.Fatalf("Build was supposed to work: %s", err) - } -} - -func (s *DockerSuite) TestBuildRUNoneJSON(c *check.C) { - testRequires(c, DaemonIsLinux) // No hello-world Windows image - name := "testbuildrunonejson" - - ctx, err := fakeContext(`FROM hello-world:frozen -RUN [ "/hello" ]`, map[string]string{}) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "-t", name, ".") - if err != nil { - c.Fatalf("failed to build the image: %s, %v", out, err) - } - - if !strings.Contains(out, "Hello from Docker") { - c.Fatalf("bad output: %s", out) - } - -} - -func (s *DockerSuite) TestBuildEmptyStringVolume(c *check.C) { - name := "testbuildemptystringvolume" - - _, err := buildImage(name, ` - FROM busybox - ENV foo="" - VOLUME $foo - `, false) - if err == nil { - c.Fatal("Should have failed to build") - } - -} - -func (s *DockerSuite) TestBuildContainerWithCgroupParent(c *check.C) { - testRequires(c, SameHostDaemon) - testRequires(c, DaemonIsLinux) - - cgroupParent := "test" - data, err := ioutil.ReadFile("/proc/self/cgroup") - if err != nil { - c.Fatalf("failed to read '/proc/self/cgroup - %v", err) - } - selfCgroupPaths := parseCgroupPaths(string(data)) - _, found := selfCgroupPaths["memory"] - if !found { - c.Fatalf("unable to find self memory cgroup path. CgroupsPath: %v", selfCgroupPaths) - } - cmd := exec.Command(dockerBinary, "build", "--cgroup-parent", cgroupParent, "-") - cmd.Stdin = strings.NewReader(` -FROM busybox -RUN cat /proc/self/cgroup -`) - - out, _, err := runCommandWithOutput(cmd) - if err != nil { - c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err) - } - m, err := regexp.MatchString(fmt.Sprintf("memory:.*/%s/.*", cgroupParent), out) - c.Assert(err, check.IsNil) - if !m { - c.Fatalf("There is no expected memory cgroup with parent /%s/: %s", cgroupParent, out) - } -} - -func (s *DockerSuite) TestBuildNoDupOutput(c *check.C) { - // Check to make sure our build output prints the Dockerfile cmd - // property - there was a bug that caused it to be duplicated on the - // Step X line - name := "testbuildnodupoutput" - - _, out, err := buildImageWithOut(name, ` - FROM busybox - RUN env`, false) - if err != nil { - c.Fatalf("Build should have worked: %q", err) - } - - exp := "\nStep 2/2 : RUN env\n" - if !strings.Contains(out, exp) { - c.Fatalf("Bad output\nGot:%s\n\nExpected to contain:%s\n", out, exp) - } -} - -// GH15826 -func (s *DockerSuite) TestBuildStartsFromOne(c *check.C) { - // Explicit check to ensure that build starts from step 1 rather than 0 - name := "testbuildstartsfromone" - - _, out, err := buildImageWithOut(name, ` - FROM busybox`, false) - if err != nil { - c.Fatalf("Build should have worked: %q", err) - } - - exp := "\nStep 1/1 : FROM busybox\n" - if !strings.Contains(out, exp) { - c.Fatalf("Bad output\nGot:%s\n\nExpected to contain:%s\n", out, exp) - } -} - -func (s *DockerSuite) TestBuildRUNErrMsg(c *check.C) { - // Test to make sure the bad command is quoted with just "s and - // not as a Go []string - name := "testbuildbadrunerrmsg" - _, out, err := buildImageWithOut(name, ` - FROM busybox - RUN badEXE a1 \& a2 a3`, false) // tab between a2 and a3 - if err == nil { - c.Fatal("Should have failed to build") - } - shell := "/bin/sh -c" - exitCode := "127" - if daemonPlatform == "windows" { - shell = "cmd /S /C" - // architectural - Windows has to start the container to determine the exe is bad, Linux does not - exitCode = "1" - } - exp := `The command '` + shell + ` badEXE a1 \& a2 a3' returned a non-zero code: ` + exitCode - if !strings.Contains(out, exp) { - c.Fatalf("RUN doesn't have the correct output:\nGot:%s\nExpected:%s", out, exp) - } -} - -func (s *DockerTrustSuite) TestTrustedBuild(c *check.C) { - repoName := s.setupTrustedImage(c, "trusted-build") - dockerFile := fmt.Sprintf(` - FROM %s - RUN [] - `, repoName) - - name := "testtrustedbuild" - - buildCmd := buildImageCmd(name, dockerFile, true) - s.trustedCmd(buildCmd) - out, _, err := runCommandWithOutput(buildCmd) - if err != nil { - c.Fatalf("Error running trusted build: %s\n%s", err, out) - } - - if !strings.Contains(out, fmt.Sprintf("FROM %s@sha", repoName[:len(repoName)-7])) { - c.Fatalf("Unexpected output on trusted build:\n%s", out) - } - - // We should also have a tag reference for the image. - if out, exitCode := dockerCmd(c, "inspect", repoName); exitCode != 0 { - c.Fatalf("unexpected exit code inspecting image %q: %d: %s", repoName, exitCode, out) - } - - // We should now be able to remove the tag reference. - if out, exitCode := dockerCmd(c, "rmi", repoName); exitCode != 0 { - c.Fatalf("unexpected exit code inspecting image %q: %d: %s", repoName, exitCode, out) - } -} - -func (s *DockerTrustSuite) TestTrustedBuildUntrustedTag(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/build-untrusted-tag:latest", privateRegistryURL) - dockerFile := fmt.Sprintf(` - FROM %s - RUN [] - `, repoName) - - name := "testtrustedbuilduntrustedtag" - - buildCmd := buildImageCmd(name, dockerFile, true) - s.trustedCmd(buildCmd) - out, _, err := runCommandWithOutput(buildCmd) - if err == nil { - c.Fatalf("Expected error on trusted build with untrusted tag: %s\n%s", err, out) - } - - if !strings.Contains(out, "does not have trust data for") { - c.Fatalf("Unexpected output on trusted build with untrusted tag:\n%s", out) - } -} - -func (s *DockerTrustSuite) TestBuildContextDirIsSymlink(c *check.C) { - testRequires(c, DaemonIsLinux) - tempDir, err := ioutil.TempDir("", "test-build-dir-is-symlink-") - c.Assert(err, check.IsNil) - defer os.RemoveAll(tempDir) - - // Make a real context directory in this temp directory with a simple - // Dockerfile. - realContextDirname := filepath.Join(tempDir, "context") - if err := os.Mkdir(realContextDirname, os.FileMode(0755)); err != nil { - c.Fatal(err) - } - - if err = ioutil.WriteFile( - filepath.Join(realContextDirname, "Dockerfile"), - []byte(` - FROM busybox - RUN echo hello world - `), - os.FileMode(0644), - ); err != nil { - c.Fatal(err) - } - - // Make a symlink to the real context directory. - contextSymlinkName := filepath.Join(tempDir, "context_link") - if err := os.Symlink(realContextDirname, contextSymlinkName); err != nil { - c.Fatal(err) - } - - // Executing the build with the symlink as the specified context should - // *not* fail. - if out, exitStatus := dockerCmd(c, "build", contextSymlinkName); exitStatus != 0 { - c.Fatalf("build failed with exit status %d: %s", exitStatus, out) - } -} - -func (s *DockerTrustSuite) TestTrustedBuildTagFromReleasesRole(c *check.C) { - testRequires(c, NotaryHosting) - - latestTag := s.setupTrustedImage(c, "trusted-build-releases-role") - repoName := strings.TrimSuffix(latestTag, ":latest") - - // Now create the releases role - s.notaryCreateDelegation(c, repoName, "targets/releases", s.not.keys[0].Public) - s.notaryImportKey(c, repoName, "targets/releases", s.not.keys[0].Private) - s.notaryPublish(c, repoName) - - // push a different tag to the releases role - otherTag := fmt.Sprintf("%s:other", repoName) - dockerCmd(c, "tag", "busybox", otherTag) - - pushCmd := exec.Command(dockerBinary, "push", otherTag) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("Trusted push failed: %s", out)) - s.assertTargetInRoles(c, repoName, "other", "targets/releases") - s.assertTargetNotInRoles(c, repoName, "other", "targets") - - out, status := dockerCmd(c, "rmi", otherTag) - c.Assert(status, check.Equals, 0, check.Commentf("docker rmi failed: %s", out)) - - dockerFile := fmt.Sprintf(` - FROM %s - RUN [] - `, otherTag) - - name := "testtrustedbuildreleasesrole" - - buildCmd := buildImageCmd(name, dockerFile, true) - s.trustedCmd(buildCmd) - out, _, err = runCommandWithOutput(buildCmd) - c.Assert(err, check.IsNil, check.Commentf("Trusted build failed: %s", out)) - c.Assert(out, checker.Contains, fmt.Sprintf("FROM %s@sha", repoName)) -} - -func (s *DockerTrustSuite) TestTrustedBuildTagIgnoresOtherDelegationRoles(c *check.C) { - testRequires(c, NotaryHosting) - - latestTag := s.setupTrustedImage(c, "trusted-build-releases-role") - repoName := strings.TrimSuffix(latestTag, ":latest") - - // Now create a non-releases delegation role - s.notaryCreateDelegation(c, repoName, "targets/other", s.not.keys[0].Public) - s.notaryImportKey(c, repoName, "targets/other", s.not.keys[0].Private) - s.notaryPublish(c, repoName) - - // push a different tag to the other role - otherTag := fmt.Sprintf("%s:other", repoName) - dockerCmd(c, "tag", "busybox", otherTag) - - pushCmd := exec.Command(dockerBinary, "push", otherTag) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("Trusted push failed: %s", out)) - s.assertTargetInRoles(c, repoName, "other", "targets/other") - s.assertTargetNotInRoles(c, repoName, "other", "targets") - - out, status := dockerCmd(c, "rmi", otherTag) - c.Assert(status, check.Equals, 0, check.Commentf("docker rmi failed: %s", out)) - - dockerFile := fmt.Sprintf(` - FROM %s - RUN [] - `, otherTag) - - name := "testtrustedbuildotherrole" - - buildCmd := buildImageCmd(name, dockerFile, true) - s.trustedCmd(buildCmd) - out, _, err = runCommandWithOutput(buildCmd) - c.Assert(err, check.NotNil, check.Commentf("Trusted build expected to fail: %s", out)) -} - -// Issue #15634: COPY fails when path starts with "null" -func (s *DockerSuite) TestBuildNullStringInAddCopyVolume(c *check.C) { - name := "testbuildnullstringinaddcopyvolume" - - volName := "nullvolume" - - if daemonPlatform == "windows" { - volName = `C:\\nullvolume` - } - - ctx, err := fakeContext(` - FROM busybox - - ADD null / - COPY nullfile / - VOLUME `+volName+` - `, - map[string]string{ - "null": "test1", - "nullfile": "test2", - }, - ) - c.Assert(err, check.IsNil) - defer ctx.Close() - - _, err = buildImageFromContext(name, ctx, true) - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestBuildStopSignal(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support STOPSIGNAL yet - imgName := "test_build_stop_signal" - _, err := buildImage(imgName, - `FROM busybox - STOPSIGNAL SIGKILL`, - true) - c.Assert(err, check.IsNil) - res := inspectFieldJSON(c, imgName, "Config.StopSignal") - if res != `"SIGKILL"` { - c.Fatalf("Signal %s, expected SIGKILL", res) - } - - containerName := "test-container-stop-signal" - dockerCmd(c, "run", "-d", "--name", containerName, imgName, "top") - - res = inspectFieldJSON(c, containerName, "Config.StopSignal") - if res != `"SIGKILL"` { - c.Fatalf("Signal %s, expected SIGKILL", res) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArg(c *check.C) { - imgName := "bldargtest" - envKey := "foo" - envVal := "bar" - args := []string{"--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)} - var dockerfile string - if daemonPlatform == "windows" { - // Bugs in Windows busybox port - use the default base image and native cmd stuff - dockerfile = fmt.Sprintf(`FROM `+minimalBaseImage()+` - ARG %s - RUN echo %%%s%% - CMD setlocal enableextensions && if defined %s (echo %%%s%%)`, envKey, envKey, envKey, envKey) - } else { - dockerfile = fmt.Sprintf(`FROM busybox - ARG %s - RUN echo $%s - CMD echo $%s`, envKey, envKey, envKey) - - } - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || !strings.Contains(out, envVal) { - if err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } - c.Fatalf("failed to access environment variable in output: %q expected: %q", out, envVal) - } - - containerName := "bldargCont" - out, _ := dockerCmd(c, "run", "--name", containerName, imgName) - out = strings.Trim(out, " \r\n'") - if out != "" { - c.Fatalf("run produced invalid output: %q, expected empty string", out) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgHistory(c *check.C) { - imgName := "bldargtest" - envKey := "foo" - envVal := "bar" - envDef := "bar1" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envVal), - } - dockerfile := fmt.Sprintf(`FROM busybox - ARG %s=%s`, envKey, envDef) - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || !strings.Contains(out, envVal) { - if err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } - c.Fatalf("failed to access environment variable in output: %q expected: %q", out, envVal) - } - - out, _ := dockerCmd(c, "history", "--no-trunc", imgName) - outputTabs := strings.Split(out, "\n")[1] - if !strings.Contains(outputTabs, envDef) { - c.Fatalf("failed to find arg default in image history output: %q expected: %q", outputTabs, envDef) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgCacheHit(c *check.C) { - imgName := "bldargtest" - envKey := "foo" - envVal := "bar" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envVal), - } - dockerfile := fmt.Sprintf(`FROM busybox - ARG %s - RUN echo $%s`, envKey, envKey) - - origImgID := "" - var err error - if origImgID, err = buildImage(imgName, dockerfile, true, args...); err != nil { - c.Fatal(err) - } - - imgNameCache := "bldargtestcachehit" - if newImgID, err := buildImage(imgNameCache, dockerfile, true, args...); err != nil || newImgID != origImgID { - if err != nil { - c.Fatal(err) - } - c.Fatalf("build didn't use cache! expected image id: %q built image id: %q", origImgID, newImgID) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgCacheMissExtraArg(c *check.C) { - imgName := "bldargtest" - envKey := "foo" - envVal := "bar" - extraEnvKey := "foo1" - extraEnvVal := "bar1" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envVal), - } - - dockerfile := fmt.Sprintf(`FROM busybox - ARG %s - ARG %s - RUN echo $%s`, envKey, extraEnvKey, envKey) - - origImgID := "" - var err error - if origImgID, err = buildImage(imgName, dockerfile, true, args...); err != nil { - c.Fatal(err) - } - - imgNameCache := "bldargtestcachemiss" - args = append(args, "--build-arg", fmt.Sprintf("%s=%s", extraEnvKey, extraEnvVal)) - if newImgID, err := buildImage(imgNameCache, dockerfile, true, args...); err != nil || newImgID == origImgID { - if err != nil { - c.Fatal(err) - } - c.Fatalf("build used cache, expected a miss!") - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgCacheMissSameArgDiffVal(c *check.C) { - imgName := "bldargtest" - envKey := "foo" - envVal := "bar" - newEnvVal := "bar1" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envVal), - } - - dockerfile := fmt.Sprintf(`FROM busybox - ARG %s - RUN echo $%s`, envKey, envKey) - - origImgID := "" - var err error - if origImgID, err = buildImage(imgName, dockerfile, true, args...); err != nil { - c.Fatal(err) - } - - imgNameCache := "bldargtestcachemiss" - args = []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, newEnvVal), - } - if newImgID, err := buildImage(imgNameCache, dockerfile, true, args...); err != nil || newImgID == origImgID { - if err != nil { - c.Fatal(err) - } - c.Fatalf("build used cache, expected a miss!") - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgOverrideArgDefinedBeforeEnv(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support ARG - imgName := "bldargtest" - envKey := "foo" - envVal := "bar" - envValOveride := "barOverride" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envVal), - } - dockerfile := fmt.Sprintf(`FROM busybox - ARG %s - ENV %s %s - RUN echo $%s - CMD echo $%s - `, envKey, envKey, envValOveride, envKey, envKey) - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || strings.Count(out, envValOveride) != 2 { - if err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } - c.Fatalf("failed to access environment variable in output: %q expected: %q", out, envValOveride) - } - - containerName := "bldargCont" - if out, _ := dockerCmd(c, "run", "--name", containerName, imgName); !strings.Contains(out, envValOveride) { - c.Fatalf("run produced invalid output: %q, expected %q", out, envValOveride) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgOverrideEnvDefinedBeforeArg(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support ARG - imgName := "bldargtest" - envKey := "foo" - envVal := "bar" - envValOveride := "barOverride" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envVal), - } - dockerfile := fmt.Sprintf(`FROM busybox - ENV %s %s - ARG %s - RUN echo $%s - CMD echo $%s - `, envKey, envValOveride, envKey, envKey, envKey) - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || strings.Count(out, envValOveride) != 2 { - if err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } - c.Fatalf("failed to access environment variable in output: %q expected: %q", out, envValOveride) - } - - containerName := "bldargCont" - if out, _ := dockerCmd(c, "run", "--name", containerName, imgName); !strings.Contains(out, envValOveride) { - c.Fatalf("run produced invalid output: %q, expected %q", out, envValOveride) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgExpansion(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support ARG - imgName := "bldvarstest" - - wdVar := "WDIR" - wdVal := "/tmp/" - addVar := "AFILE" - addVal := "addFile" - copyVar := "CFILE" - copyVal := "copyFile" - envVar := "foo" - envVal := "bar" - exposeVar := "EPORT" - exposeVal := "9999" - userVar := "USER" - userVal := "testUser" - volVar := "VOL" - volVal := "/testVol/" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", wdVar, wdVal), - "--build-arg", fmt.Sprintf("%s=%s", addVar, addVal), - "--build-arg", fmt.Sprintf("%s=%s", copyVar, copyVal), - "--build-arg", fmt.Sprintf("%s=%s", envVar, envVal), - "--build-arg", fmt.Sprintf("%s=%s", exposeVar, exposeVal), - "--build-arg", fmt.Sprintf("%s=%s", userVar, userVal), - "--build-arg", fmt.Sprintf("%s=%s", volVar, volVal), - } - ctx, err := fakeContext(fmt.Sprintf(`FROM busybox - ARG %s - WORKDIR ${%s} - ARG %s - ADD ${%s} testDir/ - ARG %s - COPY $%s testDir/ - ARG %s - ENV %s=${%s} - ARG %s - EXPOSE $%s - ARG %s - USER $%s - ARG %s - VOLUME ${%s}`, - wdVar, wdVar, addVar, addVar, copyVar, copyVar, envVar, envVar, - envVar, exposeVar, exposeVar, userVar, userVar, volVar, volVar), - map[string]string{ - addVal: "some stuff", - copyVal: "some stuff", - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if _, err := buildImageFromContext(imgName, ctx, true, args...); err != nil { - c.Fatal(err) - } - - var resMap map[string]interface{} - var resArr []string - res := "" - res = inspectField(c, imgName, "Config.WorkingDir") - if res != filepath.ToSlash(filepath.Clean(wdVal)) { - c.Fatalf("Config.WorkingDir value mismatch. Expected: %s, got: %s", filepath.ToSlash(filepath.Clean(wdVal)), res) - } - - inspectFieldAndMarshall(c, imgName, "Config.Env", &resArr) - - found := false - for _, v := range resArr { - if fmt.Sprintf("%s=%s", envVar, envVal) == v { - found = true - break - } - } - if !found { - c.Fatalf("Config.Env value mismatch. Expected to exist: %s=%s, got: %v", - envVar, envVal, resArr) - } - - inspectFieldAndMarshall(c, imgName, "Config.ExposedPorts", &resMap) - if _, ok := resMap[fmt.Sprintf("%s/tcp", exposeVal)]; !ok { - c.Fatalf("Config.ExposedPorts value mismatch. Expected exposed port: %s/tcp, got: %v", exposeVal, resMap) - } - - res = inspectField(c, imgName, "Config.User") - if res != userVal { - c.Fatalf("Config.User value mismatch. Expected: %s, got: %s", userVal, res) - } - - inspectFieldAndMarshall(c, imgName, "Config.Volumes", &resMap) - if _, ok := resMap[volVal]; !ok { - c.Fatalf("Config.Volumes value mismatch. Expected volume: %s, got: %v", volVal, resMap) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgExpansionOverride(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support ARG - imgName := "bldvarstest" - envKey := "foo" - envVal := "bar" - envKey1 := "foo1" - envValOveride := "barOverride" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envVal), - } - dockerfile := fmt.Sprintf(`FROM busybox - ARG %s - ENV %s %s - ENV %s ${%s} - RUN echo $%s - CMD echo $%s`, envKey, envKey, envValOveride, envKey1, envKey, envKey1, envKey1) - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || strings.Count(out, envValOveride) != 2 { - if err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } - c.Fatalf("failed to access environment variable in output: %q expected: %q", out, envValOveride) - } - - containerName := "bldargCont" - if out, _ := dockerCmd(c, "run", "--name", containerName, imgName); !strings.Contains(out, envValOveride) { - c.Fatalf("run produced invalid output: %q, expected %q", out, envValOveride) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgUntrustedDefinedAfterUse(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support ARG - imgName := "bldargtest" - envKey := "foo" - envVal := "bar" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envVal), - } - dockerfile := fmt.Sprintf(`FROM busybox - RUN echo $%s - ARG %s - CMD echo $%s`, envKey, envKey, envKey) - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || strings.Contains(out, envVal) { - if err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } - c.Fatalf("able to access environment variable in output: %q expected to be missing", out) - } - - containerName := "bldargCont" - if out, _ := dockerCmd(c, "run", "--name", containerName, imgName); out != "\n" { - c.Fatalf("run produced invalid output: %q, expected empty string", out) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgBuiltinArg(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support --build-arg - imgName := "bldargtest" - envKey := "HTTP_PROXY" - envVal := "bar" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envVal), - } - dockerfile := fmt.Sprintf(`FROM busybox - RUN echo $%s - CMD echo $%s`, envKey, envKey) - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || !strings.Contains(out, envVal) { - if err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } - c.Fatalf("failed to access environment variable in output: %q expected: %q", out, envVal) - } - - containerName := "bldargCont" - if out, _ := dockerCmd(c, "run", "--name", containerName, imgName); out != "\n" { - c.Fatalf("run produced invalid output: %q, expected empty string", out) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgDefaultOverride(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support ARG - imgName := "bldargtest" - envKey := "foo" - envVal := "bar" - envValOveride := "barOverride" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envValOveride), - } - dockerfile := fmt.Sprintf(`FROM busybox - ARG %s=%s - ENV %s $%s - RUN echo $%s - CMD echo $%s`, envKey, envVal, envKey, envKey, envKey, envKey) - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || strings.Count(out, envValOveride) != 1 { - if err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } - c.Fatalf("failed to access environment variable in output: %q expected: %q", out, envValOveride) - } - - containerName := "bldargCont" - if out, _ := dockerCmd(c, "run", "--name", containerName, imgName); !strings.Contains(out, envValOveride) { - c.Fatalf("run produced invalid output: %q, expected %q", out, envValOveride) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgUnconsumedArg(c *check.C) { - imgName := "bldargtest" - envKey := "foo" - envVal := "bar" - args := []string{ - "--build-arg", fmt.Sprintf("%s=%s", envKey, envVal), - } - dockerfile := fmt.Sprintf(`FROM busybox - RUN echo $%s - CMD echo $%s`, envKey, envKey) - - warnStr := "[Warning] One or more build-args" - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); !strings.Contains(out, warnStr) { - c.Fatalf("build completed without warning: %q %q", out, err) - } else if err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } - -} - -func (s *DockerSuite) TestBuildBuildTimeArgEnv(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support ARG - args := []string{ - "build", - "--build-arg", fmt.Sprintf("FOO1=fromcmd"), - "--build-arg", fmt.Sprintf("FOO2="), - "--build-arg", fmt.Sprintf("FOO3"), // set in env - "--build-arg", fmt.Sprintf("FOO4"), // not set in env - "--build-arg", fmt.Sprintf("FOO5=fromcmd"), - // FOO6 is not set at all - "--build-arg", fmt.Sprintf("FOO7=fromcmd"), // should produce a warning - "--build-arg", fmt.Sprintf("FOO8="), // should produce a warning - "--build-arg", fmt.Sprintf("FOO9"), // should produce a warning - ".", - } - - dockerfile := fmt.Sprintf(`FROM busybox - ARG FOO1=fromfile - ARG FOO2=fromfile - ARG FOO3=fromfile - ARG FOO4=fromfile - ARG FOO5 - ARG FOO6 - RUN env - RUN [ "$FOO1" == "fromcmd" ] - RUN [ "$FOO2" == "" ] - RUN [ "$FOO3" == "fromenv" ] - RUN [ "$FOO4" == "fromfile" ] - RUN [ "$FOO5" == "fromcmd" ] - # The following should not exist at all in the env - RUN [ "$(env | grep FOO6)" == "" ] - RUN [ "$(env | grep FOO7)" == "" ] - RUN [ "$(env | grep FOO8)" == "" ] - RUN [ "$(env | grep FOO9)" == "" ] - `) - - ctx, err := fakeContext(dockerfile, nil) - c.Assert(err, check.IsNil) - defer ctx.Close() - - cmd := exec.Command(dockerBinary, args...) - cmd.Dir = ctx.Dir - cmd.Env = append(os.Environ(), - "FOO1=fromenv", - "FOO2=fromenv", - "FOO3=fromenv") - out, _, err := runCommandWithOutput(cmd) - if err != nil { - c.Fatal(err, out) - } - - // Now check to make sure we got a warning msg about unused build-args - i := strings.Index(out, "[Warning]") - if i < 0 { - c.Fatalf("Missing the build-arg warning in %q", out) - } - - out = out[i:] // "out" should contain just the warning message now - - // These were specified on a --build-arg but no ARG was in the Dockerfile - c.Assert(out, checker.Contains, "FOO7") - c.Assert(out, checker.Contains, "FOO8") - c.Assert(out, checker.Contains, "FOO9") -} - -func (s *DockerSuite) TestBuildBuildTimeArgQuotedValVariants(c *check.C) { - imgName := "bldargtest" - envKey := "foo" - envKey1 := "foo1" - envKey2 := "foo2" - envKey3 := "foo3" - args := []string{} - dockerfile := fmt.Sprintf(`FROM busybox - ARG %s="" - ARG %s='' - ARG %s="''" - ARG %s='""' - RUN [ "$%s" != "$%s" ] - RUN [ "$%s" != "$%s" ] - RUN [ "$%s" != "$%s" ] - RUN [ "$%s" != "$%s" ] - RUN [ "$%s" != "$%s" ]`, envKey, envKey1, envKey2, envKey3, - envKey, envKey2, envKey, envKey3, envKey1, envKey2, envKey1, envKey3, - envKey2, envKey3) - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgEmptyValVariants(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support ARG - imgName := "bldargtest" - envKey := "foo" - envKey1 := "foo1" - envKey2 := "foo2" - args := []string{} - dockerfile := fmt.Sprintf(`FROM busybox - ARG %s= - ARG %s="" - ARG %s='' - RUN [ "$%s" == "$%s" ] - RUN [ "$%s" == "$%s" ] - RUN [ "$%s" == "$%s" ]`, envKey, envKey1, envKey2, envKey, envKey1, envKey1, envKey2, envKey, envKey2) - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } -} - -func (s *DockerSuite) TestBuildBuildTimeArgDefintionWithNoEnvInjection(c *check.C) { - imgName := "bldargtest" - envKey := "foo" - args := []string{} - dockerfile := fmt.Sprintf(`FROM busybox - ARG %s - RUN env`, envKey) - - if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || strings.Count(out, envKey) != 1 { - if err != nil { - c.Fatalf("build failed to complete: %q %q", out, err) - } - c.Fatalf("unexpected number of occurrences of the arg in output: %q expected: 1", out) - } -} - -func (s *DockerSuite) TestBuildNoNamedVolume(c *check.C) { - volName := "testname:/foo" - - if daemonPlatform == "windows" { - volName = "testname:C:\\foo" - } - dockerCmd(c, "run", "-v", volName, "busybox", "sh", "-c", "touch /foo/oops") - - dockerFile := `FROM busybox - VOLUME ` + volName + ` - RUN ls /foo/oops - ` - _, err := buildImage("test", dockerFile, false) - c.Assert(err, check.NotNil, check.Commentf("image build should have failed")) -} - -func (s *DockerSuite) TestBuildTagEvent(c *check.C) { - since := daemonUnixTime(c) - - dockerFile := `FROM busybox - RUN echo events - ` - _, err := buildImage("test", dockerFile, false) - c.Assert(err, check.IsNil) - - until := daemonUnixTime(c) - out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "type=image") - events := strings.Split(strings.TrimSpace(out), "\n") - actions := eventActionsByIDAndType(c, events, "test:latest", "image") - var foundTag bool - for _, a := range actions { - if a == "tag" { - foundTag = true - break - } - } - - c.Assert(foundTag, checker.True, check.Commentf("No tag event found:\n%s", out)) -} - -// #15780 -func (s *DockerSuite) TestBuildMultipleTags(c *check.C) { - dockerfile := ` - FROM busybox - MAINTAINER test-15780 - ` - cmd := exec.Command(dockerBinary, "build", "-t", "tag1", "-t", "tag2:v2", - "-t", "tag1:latest", "-t", "tag1", "--no-cache", "-") - cmd.Stdin = strings.NewReader(dockerfile) - _, err := runCommand(cmd) - c.Assert(err, check.IsNil) - - id1, err := getIDByName("tag1") - c.Assert(err, check.IsNil) - id2, err := getIDByName("tag2:v2") - c.Assert(err, check.IsNil) - c.Assert(id1, check.Equals, id2) -} - -// #17290 -func (s *DockerSuite) TestBuildCacheBrokenSymlink(c *check.C) { - name := "testbuildbrokensymlink" - ctx, err := fakeContext(` - FROM busybox - COPY . ./`, - map[string]string{ - "foo": "bar", - }) - c.Assert(err, checker.IsNil) - defer ctx.Close() - - err = os.Symlink(filepath.Join(ctx.Dir, "nosuchfile"), filepath.Join(ctx.Dir, "asymlink")) - c.Assert(err, checker.IsNil) - - // warm up cache - _, err = buildImageFromContext(name, ctx, true) - c.Assert(err, checker.IsNil) - - // add new file to context, should invalidate cache - err = ioutil.WriteFile(filepath.Join(ctx.Dir, "newfile"), []byte("foo"), 0644) - c.Assert(err, checker.IsNil) - - _, out, err := buildImageFromContextWithOut(name, ctx, true) - c.Assert(err, checker.IsNil) - - c.Assert(out, checker.Not(checker.Contains), "Using cache") - -} - -func (s *DockerSuite) TestBuildFollowSymlinkToFile(c *check.C) { - name := "testbuildbrokensymlink" - ctx, err := fakeContext(` - FROM busybox - COPY asymlink target`, - map[string]string{ - "foo": "bar", - }) - c.Assert(err, checker.IsNil) - defer ctx.Close() - - err = os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) - c.Assert(err, checker.IsNil) - - id, err := buildImageFromContext(name, ctx, true) - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "run", "--rm", id, "cat", "target") - c.Assert(out, checker.Matches, "bar") - - // change target file should invalidate cache - err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644) - c.Assert(err, checker.IsNil) - - id, out, err = buildImageFromContextWithOut(name, ctx, true) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), "Using cache") - - out, _ = dockerCmd(c, "run", "--rm", id, "cat", "target") - c.Assert(out, checker.Matches, "baz") -} - -func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *check.C) { - name := "testbuildbrokensymlink" - ctx, err := fakeContext(` - FROM busybox - COPY asymlink /`, - map[string]string{ - "foo/abc": "bar", - "foo/def": "baz", - }) - c.Assert(err, checker.IsNil) - defer ctx.Close() - - err = os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) - c.Assert(err, checker.IsNil) - - id, err := buildImageFromContext(name, ctx, true) - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "run", "--rm", id, "cat", "abc", "def") - c.Assert(out, checker.Matches, "barbaz") - - // change target file should invalidate cache - err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo/def"), []byte("bax"), 0644) - c.Assert(err, checker.IsNil) - - id, out, err = buildImageFromContextWithOut(name, ctx, true) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), "Using cache") - - out, _ = dockerCmd(c, "run", "--rm", id, "cat", "abc", "def") - c.Assert(out, checker.Matches, "barbax") - -} - -// TestBuildSymlinkBasename tests that target file gets basename from symlink, -// not from the target file. -func (s *DockerSuite) TestBuildSymlinkBasename(c *check.C) { - name := "testbuildbrokensymlink" - ctx, err := fakeContext(` - FROM busybox - COPY asymlink /`, - map[string]string{ - "foo": "bar", - }) - c.Assert(err, checker.IsNil) - defer ctx.Close() - - err = os.Symlink("foo", filepath.Join(ctx.Dir, "asymlink")) - c.Assert(err, checker.IsNil) - - id, err := buildImageFromContext(name, ctx, true) - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "run", "--rm", id, "cat", "asymlink") - c.Assert(out, checker.Matches, "bar") - -} - -// #17827 -func (s *DockerSuite) TestBuildCacheRootSource(c *check.C) { - name := "testbuildrootsource" - ctx, err := fakeContext(` - FROM busybox - COPY / /data`, - map[string]string{ - "foo": "bar", - }) - c.Assert(err, checker.IsNil) - defer ctx.Close() - - // warm up cache - _, err = buildImageFromContext(name, ctx, true) - c.Assert(err, checker.IsNil) - - // change file, should invalidate cache - err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644) - c.Assert(err, checker.IsNil) - - _, out, err := buildImageFromContextWithOut(name, ctx, true) - c.Assert(err, checker.IsNil) - - c.Assert(out, checker.Not(checker.Contains), "Using cache") -} - -// #19375 -func (s *DockerSuite) TestBuildFailsGitNotCallable(c *check.C) { - cmd := exec.Command(dockerBinary, "build", "github.com/docker/v1.10-migrator.git") - cmd.Env = append(cmd.Env, "PATH=") - out, _, err := runCommandWithOutput(cmd) - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "unable to prepare context: unable to find 'git': ") - - cmd = exec.Command(dockerBinary, "build", "https://github.com/docker/v1.10-migrator.git") - cmd.Env = append(cmd.Env, "PATH=") - out, _, err = runCommandWithOutput(cmd) - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "unable to prepare context: unable to find 'git': ") -} - -// TestBuildWorkdirWindowsPath tests that a Windows style path works as a workdir -func (s *DockerSuite) TestBuildWorkdirWindowsPath(c *check.C) { - testRequires(c, DaemonIsWindows) - name := "testbuildworkdirwindowspath" - - _, err := buildImage(name, ` - FROM `+WindowsBaseImage+` - RUN mkdir C:\\work - WORKDIR C:\\work - RUN if "%CD%" NEQ "C:\work" exit -1 - `, true) - - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestBuildLabel(c *check.C) { - name := "testbuildlabel" - testLabel := "foo" - - _, err := buildImage(name, ` - FROM `+minimalBaseImage()+` - LABEL default foo -`, false, "--label", testLabel) - - c.Assert(err, checker.IsNil) - - res := inspectFieldJSON(c, name, "Config.Labels") - - var labels map[string]string - - if err := json.Unmarshal([]byte(res), &labels); err != nil { - c.Fatal(err) - } - - if _, ok := labels[testLabel]; !ok { - c.Fatal("label not found in image") - } -} - -func (s *DockerSuite) TestBuildLabelOneNode(c *check.C) { - name := "testbuildlabel" - - _, err := buildImage(name, "FROM busybox", false, "--label", "foo=bar") - - c.Assert(err, checker.IsNil) - - res, err := inspectImage(name, "json .Config.Labels") - c.Assert(err, checker.IsNil) - var labels map[string]string - - if err := json.Unmarshal([]byte(res), &labels); err != nil { - c.Fatal(err) - } - - v, ok := labels["foo"] - if !ok { - c.Fatal("label `foo` not found in image") - } - c.Assert(v, checker.Equals, "bar") -} - -func (s *DockerSuite) TestBuildLabelCacheCommit(c *check.C) { - name := "testbuildlabelcachecommit" - testLabel := "foo" - - if _, err := buildImage(name, ` - FROM `+minimalBaseImage()+` - LABEL default foo - `, false); err != nil { - c.Fatal(err) - } - - _, err := buildImage(name, ` - FROM `+minimalBaseImage()+` - LABEL default foo -`, true, "--label", testLabel) - - c.Assert(err, checker.IsNil) - - res := inspectFieldJSON(c, name, "Config.Labels") - - var labels map[string]string - - if err := json.Unmarshal([]byte(res), &labels); err != nil { - c.Fatal(err) - } - - if _, ok := labels[testLabel]; !ok { - c.Fatal("label not found in image") - } -} - -func (s *DockerSuite) TestBuildLabelMultiple(c *check.C) { - name := "testbuildlabelmultiple" - testLabels := map[string]string{ - "foo": "bar", - "123": "456", - } - - labelArgs := []string{} - - for k, v := range testLabels { - labelArgs = append(labelArgs, "--label", k+"="+v) - } - - _, err := buildImage(name, ` - FROM `+minimalBaseImage()+` - LABEL default foo -`, false, labelArgs...) - - if err != nil { - c.Fatal("error building image with labels", err) - } - - res := inspectFieldJSON(c, name, "Config.Labels") - - var labels map[string]string - - if err := json.Unmarshal([]byte(res), &labels); err != nil { - c.Fatal(err) - } - - for k, v := range testLabels { - if x, ok := labels[k]; !ok || x != v { - c.Fatalf("label %s=%s not found in image", k, v) - } - } -} - -func (s *DockerSuite) TestBuildLabelOverwrite(c *check.C) { - name := "testbuildlabeloverwrite" - testLabel := "foo" - testValue := "bar" - - _, err := buildImage(name, ` - FROM `+minimalBaseImage()+` - LABEL `+testLabel+`+ foo -`, false, []string{"--label", testLabel + "=" + testValue}...) - - if err != nil { - c.Fatal("error building image with labels", err) - } - - res := inspectFieldJSON(c, name, "Config.Labels") - - var labels map[string]string - - if err := json.Unmarshal([]byte(res), &labels); err != nil { - c.Fatal(err) - } - - v, ok := labels[testLabel] - if !ok { - c.Fatal("label not found in image") - } - - if v != testValue { - c.Fatal("label not overwritten") - } -} - -func (s *DockerRegistryAuthHtpasswdSuite) TestBuildFromAuthenticatedRegistry(c *check.C) { - dockerCmd(c, "login", "-u", s.reg.username, "-p", s.reg.password, privateRegistryURL) - - baseImage := privateRegistryURL + "/baseimage" - - _, err := buildImage(baseImage, ` - FROM busybox - ENV env1 val1 - `, true) - - c.Assert(err, checker.IsNil) - - dockerCmd(c, "push", baseImage) - dockerCmd(c, "rmi", baseImage) - - _, err = buildImage(baseImage, fmt.Sprintf(` - FROM %s - ENV env2 val2 - `, baseImage), true) - - c.Assert(err, checker.IsNil) -} - -func (s *DockerRegistryAuthHtpasswdSuite) TestBuildWithExternalAuth(c *check.C) { - osPath := os.Getenv("PATH") - defer os.Setenv("PATH", osPath) - - workingDir, err := os.Getwd() - c.Assert(err, checker.IsNil) - absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth")) - c.Assert(err, checker.IsNil) - testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute) - - os.Setenv("PATH", testPath) - - repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL) - - tmp, err := ioutil.TempDir("", "integration-cli-") - c.Assert(err, checker.IsNil) - - externalAuthConfig := `{ "credsStore": "shell-test" }` - - configPath := filepath.Join(tmp, "config.json") - err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "--config", tmp, "login", "-u", s.reg.username, "-p", s.reg.password, privateRegistryURL) - - b, err := ioutil.ReadFile(configPath) - c.Assert(err, checker.IsNil) - c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":") - - dockerCmd(c, "--config", tmp, "tag", "busybox", repoName) - dockerCmd(c, "--config", tmp, "push", repoName) - - // make sure the image is pulled when building - dockerCmd(c, "rmi", repoName) - - buildCmd := exec.Command(dockerBinary, "--config", tmp, "build", "-") - buildCmd.Stdin = strings.NewReader(fmt.Sprintf("FROM %s", repoName)) - - out, _, err := runCommandWithOutput(buildCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) -} - -// Test cases in #22036 -func (s *DockerSuite) TestBuildLabelsOverride(c *check.C) { - // Command line option labels will always override - name := "scratchy" - expected := `{"bar":"from-flag","foo":"from-flag"}` - _, err := buildImage(name, - `FROM `+minimalBaseImage()+` - LABEL foo=from-dockerfile`, - true, "--label", "foo=from-flag", "--label", "bar=from-flag") - c.Assert(err, check.IsNil) - - res := inspectFieldJSON(c, name, "Config.Labels") - if res != expected { - c.Fatalf("Labels %s, expected %s", res, expected) - } - - name = "from" - expected = `{"foo":"from-dockerfile"}` - _, err = buildImage(name, - `FROM `+minimalBaseImage()+` - LABEL foo from-dockerfile`, - true) - c.Assert(err, check.IsNil) - - res = inspectFieldJSON(c, name, "Config.Labels") - if res != expected { - c.Fatalf("Labels %s, expected %s", res, expected) - } - - // Command line option label will override even via `FROM` - name = "new" - expected = `{"bar":"from-dockerfile2","foo":"new"}` - _, err = buildImage(name, - `FROM from - LABEL bar from-dockerfile2`, - true, "--label", "foo=new") - c.Assert(err, check.IsNil) - - res = inspectFieldJSON(c, name, "Config.Labels") - if res != expected { - c.Fatalf("Labels %s, expected %s", res, expected) - } - - // Command line option without a value set (--label foo, --label bar=) - // will be treated as --label foo="", --label bar="" - name = "scratchy2" - expected = `{"bar":"","foo":""}` - _, err = buildImage(name, - `FROM `+minimalBaseImage()+` - LABEL foo=from-dockerfile`, - true, "--label", "foo", "--label", "bar=") - c.Assert(err, check.IsNil) - - res = inspectFieldJSON(c, name, "Config.Labels") - if res != expected { - c.Fatalf("Labels %s, expected %s", res, expected) - } - - // Command line option without a value set (--label foo, --label bar=) - // will be treated as --label foo="", --label bar="" - // This time is for inherited images - name = "new2" - expected = `{"bar":"","foo":""}` - _, err = buildImage(name, - `FROM from - LABEL bar from-dockerfile2`, - true, "--label", "foo=", "--label", "bar") - c.Assert(err, check.IsNil) - - res = inspectFieldJSON(c, name, "Config.Labels") - if res != expected { - c.Fatalf("Labels %s, expected %s", res, expected) - } - - // Command line option labels with only `FROM` - name = "scratchy" - expected = `{"bar":"from-flag","foo":"from-flag"}` - _, err = buildImage(name, - `FROM `+minimalBaseImage(), - true, "--label", "foo=from-flag", "--label", "bar=from-flag") - c.Assert(err, check.IsNil) - - res = inspectFieldJSON(c, name, "Config.Labels") - if res != expected { - c.Fatalf("Labels %s, expected %s", res, expected) - } - - // Command line option labels with env var - name = "scratchz" - expected = `{"bar":"$PATH"}` - _, err = buildImage(name, - `FROM `+minimalBaseImage(), - true, "--label", "bar=$PATH") - c.Assert(err, check.IsNil) - - res = inspectFieldJSON(c, name, "Config.Labels") - if res != expected { - c.Fatalf("Labels %s, expected %s", res, expected) - } - -} - -// Test case for #22855 -func (s *DockerSuite) TestBuildDeleteCommittedFile(c *check.C) { - name := "test-delete-committed-file" - - _, err := buildImage(name, - `FROM busybox - RUN echo test > file - RUN test -e file - RUN rm file - RUN sh -c "! test -e file"`, false) - if err != nil { - c.Fatal(err) - } -} - -// #20083 -func (s *DockerSuite) TestBuildDockerignoreComment(c *check.C) { - // TODO Windows: Figure out why this test is flakey on TP5. If you add - // something like RUN sleep 5, or even RUN ls /tmp after the ADD line, - // it is more reliable, but that's not a good fix. - testRequires(c, DaemonIsLinux) - - name := "testbuilddockerignorecleanpaths" - dockerfile := ` - FROM busybox - ADD . /tmp/ - RUN sh -c "(ls -la /tmp/#1)" - RUN sh -c "(! ls -la /tmp/#2)" - RUN sh -c "(! ls /tmp/foo) && (! ls /tmp/foo2) && (ls /tmp/dir1/foo)"` - ctx, err := fakeContext(dockerfile, map[string]string{ - "foo": "foo", - "foo2": "foo2", - "dir1/foo": "foo in dir1", - "#1": "# file 1", - "#2": "# file 2", - ".dockerignore": `# Visual C++ cache files -# because we have git ;-) -# The above comment is from #20083 -foo -#dir1/foo -foo2 -# The following is considered as comment as # is at the beginning -#1 -# The following is not considered as comment as # is not at the beginning - #2 -`, - }) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -// Test case for #23221 -func (s *DockerSuite) TestBuildWithUTF8BOM(c *check.C) { - name := "test-with-utf8-bom" - dockerfile := []byte(`FROM busybox`) - bomDockerfile := append([]byte{0xEF, 0xBB, 0xBF}, dockerfile...) - ctx, err := fakeContextFromNewTempDir() - c.Assert(err, check.IsNil) - defer ctx.Close() - err = ctx.addFile("Dockerfile", bomDockerfile) - c.Assert(err, check.IsNil) - _, err = buildImageFromContext(name, ctx, true) - c.Assert(err, check.IsNil) -} - -// Test case for UTF-8 BOM in .dockerignore, related to #23221 -func (s *DockerSuite) TestBuildWithUTF8BOMDockerignore(c *check.C) { - name := "test-with-utf8-bom-dockerignore" - dockerfile := ` - FROM busybox - ADD . /tmp/ - RUN ls -la /tmp - RUN sh -c "! ls /tmp/Dockerfile" - RUN ls /tmp/.dockerignore` - dockerignore := []byte("./Dockerfile\n") - bomDockerignore := append([]byte{0xEF, 0xBB, 0xBF}, dockerignore...) - ctx, err := fakeContext(dockerfile, map[string]string{ - "Dockerfile": dockerfile, - }) - c.Assert(err, check.IsNil) - defer ctx.Close() - err = ctx.addFile(".dockerignore", bomDockerignore) - c.Assert(err, check.IsNil) - _, err = buildImageFromContext(name, ctx, true) - if err != nil { - c.Fatal(err) - } -} - -// #22489 Shell test to confirm config gets updated correctly -func (s *DockerSuite) TestBuildShellUpdatesConfig(c *check.C) { - name := "testbuildshellupdatesconfig" - - expected := `["foo","-bar","#(nop) ","SHELL [foo -bar]"]` - _, err := buildImage(name, - `FROM `+minimalBaseImage()+` - SHELL ["foo", "-bar"]`, - true) - if err != nil { - c.Fatal(err) - } - res := inspectFieldJSON(c, name, "ContainerConfig.Cmd") - if res != expected { - c.Fatalf("%s, expected %s", res, expected) - } - res = inspectFieldJSON(c, name, "ContainerConfig.Shell") - if res != `["foo","-bar"]` { - c.Fatalf(`%s, expected ["foo","-bar"]`, res) - } -} - -// #22489 Changing the shell multiple times and CMD after. -func (s *DockerSuite) TestBuildShellMultiple(c *check.C) { - name := "testbuildshellmultiple" - - _, out, _, err := buildImageWithStdoutStderr(name, - `FROM busybox - RUN echo defaultshell - SHELL ["echo"] - RUN echoshell - SHELL ["ls"] - RUN -l - CMD -l`, - true) - if err != nil { - c.Fatal(err) - } - - // Must contain 'defaultshell' twice - if len(strings.Split(out, "defaultshell")) != 3 { - c.Fatalf("defaultshell should have appeared twice in %s", out) - } - - // Must contain 'echoshell' twice - if len(strings.Split(out, "echoshell")) != 3 { - c.Fatalf("echoshell should have appeared twice in %s", out) - } - - // Must contain "total " (part of ls -l) - if !strings.Contains(out, "total ") { - c.Fatalf("%s should have contained 'total '", out) - } - - // A container started from the image uses the shell-form CMD. - // Last shell is ls. CMD is -l. So should contain 'total '. - outrun, _ := dockerCmd(c, "run", "--rm", name) - if !strings.Contains(outrun, "total ") { - c.Fatalf("Expected started container to run ls -l. %s", outrun) - } -} - -// #22489. Changed SHELL with ENTRYPOINT -func (s *DockerSuite) TestBuildShellEntrypoint(c *check.C) { - name := "testbuildshellentrypoint" - - _, err := buildImage(name, - `FROM busybox - SHELL ["ls"] - ENTRYPOINT -l`, - true) - if err != nil { - c.Fatal(err) - } - - // A container started from the image uses the shell-form ENTRYPOINT. - // Shell is ls. ENTRYPOINT is -l. So should contain 'total '. - outrun, _ := dockerCmd(c, "run", "--rm", name) - if !strings.Contains(outrun, "total ") { - c.Fatalf("Expected started container to run ls -l. %s", outrun) - } -} - -// #22489 Shell test to confirm shell is inherited in a subsequent build -func (s *DockerSuite) TestBuildShellInherited(c *check.C) { - name1 := "testbuildshellinherited1" - _, err := buildImage(name1, - `FROM busybox - SHELL ["ls"]`, - true) - if err != nil { - c.Fatal(err) - } - - name2 := "testbuildshellinherited2" - _, out, _, err := buildImageWithStdoutStderr(name2, - `FROM `+name1+` - RUN -l`, - true) - if err != nil { - c.Fatal(err) - } - - // ls -l has "total " followed by some number in it, ls without -l does not. - if !strings.Contains(out, "total ") { - c.Fatalf("Should have seen total in 'ls -l'.\n%s", out) - } -} - -// #22489 Shell test to confirm non-JSON doesn't work -func (s *DockerSuite) TestBuildShellNotJSON(c *check.C) { - name := "testbuildshellnotjson" - - _, err := buildImage(name, - `FROM `+minimalBaseImage()+` - sHeLl exec -form`, // Casing explicit to ensure error is upper-cased. - true) - if err == nil { - c.Fatal("Image build should have failed") - } - if !strings.Contains(err.Error(), "SHELL requires the arguments to be in JSON form") { - c.Fatal("Error didn't indicate that arguments must be in JSON form") - } -} - -// #22489 Windows shell test to confirm native is powershell if executing a PS command -// This would error if the default shell were still cmd. -func (s *DockerSuite) TestBuildShellWindowsPowershell(c *check.C) { - testRequires(c, DaemonIsWindows) - name := "testbuildshellpowershell" - _, out, err := buildImageWithOut(name, - `FROM `+minimalBaseImage()+` - SHELL ["powershell", "-command"] - RUN Write-Host John`, - true) - if err != nil { - c.Fatal(err) - } - if !strings.Contains(out, "\nJohn\n") { - c.Fatalf("Line with 'John' not found in output %q", out) - } -} - -// Verify that escape is being correctly applied to words when escape directive is not \. -// Tests WORKDIR, ADD -func (s *DockerSuite) TestBuildEscapeNotBackslashWordTest(c *check.C) { - testRequires(c, DaemonIsWindows) - name := "testbuildescapenotbackslashwordtesta" - _, out, err := buildImageWithOut(name, - `# escape= `+"`"+` - FROM `+minimalBaseImage()+` - WORKDIR c:\windows - RUN dir /w`, - true) - if err != nil { - c.Fatal(err) - } - if !strings.Contains(strings.ToLower(out), "[system32]") { - c.Fatalf("Line with '[windows]' not found in output %q", out) - } - - name = "testbuildescapenotbackslashwordtestb" - _, out, err = buildImageWithOut(name, - `# escape= `+"`"+` - FROM `+minimalBaseImage()+` - SHELL ["powershell.exe"] - WORKDIR c:\foo - ADD Dockerfile c:\foo\ - RUN dir Dockerfile`, - true) - if err != nil { - c.Fatal(err) - } - if !strings.Contains(strings.ToLower(out), "-a----") { - c.Fatalf("Line with '-a----' not found in output %q", out) - } - -} - -// #22868. Make sure shell-form CMD is marked as escaped in the config of the image -func (s *DockerSuite) TestBuildCmdShellArgsEscaped(c *check.C) { - testRequires(c, DaemonIsWindows) - name := "testbuildcmdshellescaped" - _, err := buildImage(name, ` - FROM `+minimalBaseImage()+` - CMD "ipconfig" - `, true) - if err != nil { - c.Fatal(err) - } - res := inspectFieldJSON(c, name, "Config.ArgsEscaped") - if res != "true" { - c.Fatalf("CMD did not update Config.ArgsEscaped on image: %v", res) - } - dockerCmd(c, "run", "--name", "inspectme", name) - dockerCmd(c, "wait", "inspectme") - res = inspectFieldJSON(c, name, "Config.Cmd") - - if res != `["cmd","/S","/C","\"ipconfig\""]` { - c.Fatalf("CMD was not escaped Config.Cmd: got %v", res) - } -} - -// Test case for #24912. -func (s *DockerSuite) TestBuildStepsWithProgress(c *check.C) { - name := "testbuildstepswithprogress" - - totalRun := 5 - _, out, err := buildImageWithOut(name, "FROM busybox\n"+strings.Repeat("RUN echo foo\n", totalRun), true) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, fmt.Sprintf("Step 1/%d : FROM busybox", 1+totalRun)) - for i := 2; i <= 1+totalRun; i++ { - c.Assert(out, checker.Contains, fmt.Sprintf("Step %d/%d : RUN echo foo", i, 1+totalRun)) - } -} - -func (s *DockerSuite) TestBuildWithFailure(c *check.C) { - name := "testbuildwithfailure" - - // First test case can only detect `nobody` in runtime so all steps will show up - buildCmd := "FROM busybox\nRUN nobody" - _, stdout, _, err := buildImageWithStdoutStderr(name, buildCmd, false, "--force-rm", "--rm") - c.Assert(err, checker.NotNil) - c.Assert(stdout, checker.Contains, "Step 1/2 : FROM busybox") - c.Assert(stdout, checker.Contains, "Step 2/2 : RUN nobody") - - // Second test case `FFOM` should have been detected before build runs so no steps - buildCmd = "FFOM nobody\nRUN nobody" - _, stdout, _, err = buildImageWithStdoutStderr(name, buildCmd, false, "--force-rm", "--rm") - c.Assert(err, checker.NotNil) - c.Assert(stdout, checker.Not(checker.Contains), "Step 1/2 : FROM busybox") - c.Assert(stdout, checker.Not(checker.Contains), "Step 2/2 : RUN nobody") -} - -func (s *DockerSuite) TestBuildCacheFrom(c *check.C) { - testRequires(c, DaemonIsLinux) // All tests that do save are skipped in windows - dockerfile := ` - FROM busybox - ENV FOO=bar - ADD baz / - RUN touch bax` - ctx, err := fakeContext(dockerfile, map[string]string{ - "Dockerfile": dockerfile, - "baz": "baz", - }) - c.Assert(err, checker.IsNil) - defer ctx.Close() - - id1, err := buildImageFromContext("build1", ctx, true) - c.Assert(err, checker.IsNil) - - // rebuild with cache-from - id2, out, err := buildImageFromContextWithOut("build2", ctx, true, "--cache-from=build1") - c.Assert(err, checker.IsNil) - c.Assert(id1, checker.Equals, id2) - c.Assert(strings.Count(out, "Using cache"), checker.Equals, 3) - dockerCmd(c, "rmi", "build2") - - // no cache match with unknown source - id2, out, err = buildImageFromContextWithOut("build2", ctx, true, "--cache-from=nosuchtag") - c.Assert(err, checker.IsNil) - c.Assert(id1, checker.Not(checker.Equals), id2) - c.Assert(strings.Count(out, "Using cache"), checker.Equals, 0) - dockerCmd(c, "rmi", "build2") - - // clear parent images - tempDir, err := ioutil.TempDir("", "test-build-cache-from-") - if err != nil { - c.Fatalf("failed to create temporary directory: %s", tempDir) - } - defer os.RemoveAll(tempDir) - tempFile := filepath.Join(tempDir, "img.tar") - dockerCmd(c, "save", "-o", tempFile, "build1") - dockerCmd(c, "rmi", "build1") - dockerCmd(c, "load", "-i", tempFile) - parentID, _ := dockerCmd(c, "inspect", "-f", "{{.Parent}}", "build1") - c.Assert(strings.TrimSpace(parentID), checker.Equals, "") - - // cache still applies without parents - id2, out, err = buildImageFromContextWithOut("build2", ctx, true, "--cache-from=build1") - c.Assert(err, checker.IsNil) - c.Assert(id1, checker.Equals, id2) - c.Assert(strings.Count(out, "Using cache"), checker.Equals, 3) - history1, _ := dockerCmd(c, "history", "-q", "build2") - - // Retry, no new intermediate images - id3, out, err := buildImageFromContextWithOut("build3", ctx, true, "--cache-from=build1") - c.Assert(err, checker.IsNil) - c.Assert(id1, checker.Equals, id3) - c.Assert(strings.Count(out, "Using cache"), checker.Equals, 3) - history2, _ := dockerCmd(c, "history", "-q", "build3") - - c.Assert(history1, checker.Equals, history2) - dockerCmd(c, "rmi", "build2") - dockerCmd(c, "rmi", "build3") - dockerCmd(c, "rmi", "build1") - dockerCmd(c, "load", "-i", tempFile) - - // Modify file, everything up to last command and layers are reused - dockerfile = ` - FROM busybox - ENV FOO=bar - ADD baz / - RUN touch newfile` - err = ioutil.WriteFile(filepath.Join(ctx.Dir, "Dockerfile"), []byte(dockerfile), 0644) - c.Assert(err, checker.IsNil) - - id2, out, err = buildImageFromContextWithOut("build2", ctx, true, "--cache-from=build1") - c.Assert(err, checker.IsNil) - c.Assert(id1, checker.Not(checker.Equals), id2) - c.Assert(strings.Count(out, "Using cache"), checker.Equals, 2) - - layers1Str, _ := dockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build1") - layers2Str, _ := dockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build2") - - var layers1 []string - var layers2 []string - c.Assert(json.Unmarshal([]byte(layers1Str), &layers1), checker.IsNil) - c.Assert(json.Unmarshal([]byte(layers2Str), &layers2), checker.IsNil) - - c.Assert(len(layers1), checker.Equals, len(layers2)) - for i := 0; i < len(layers1)-1; i++ { - c.Assert(layers1[i], checker.Equals, layers2[i]) - } - c.Assert(layers1[len(layers1)-1], checker.Not(checker.Equals), layers2[len(layers1)-1]) -} - -func (s *DockerSuite) TestBuildNetNone(c *check.C) { - testRequires(c, DaemonIsLinux) - - name := "testbuildnetnone" - _, out, err := buildImageWithOut(name, ` - FROM busybox - RUN ping -c 1 8.8.8.8 - `, true, "--network=none") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "unreachable") -} - -func (s *DockerSuite) TestBuildNetContainer(c *check.C) { - testRequires(c, DaemonIsLinux) - - id, _ := dockerCmd(c, "run", "--hostname", "foobar", "-d", "busybox", "nc", "-ll", "-p", "1234", "-e", "hostname") - - name := "testbuildnetcontainer" - out, err := buildImage(name, ` - FROM busybox - RUN nc localhost 1234 > /otherhost - `, true, "--network=container:"+strings.TrimSpace(id)) - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - - host, _ := dockerCmd(c, "run", "testbuildnetcontainer", "cat", "/otherhost") - c.Assert(strings.TrimSpace(host), check.Equals, "foobar") -} - -func (s *DockerSuite) TestBuildSquashParent(c *check.C) { - testRequires(c, ExperimentalDaemon) - dockerFile := ` - FROM busybox - RUN echo hello > /hello - RUN echo world >> /hello - RUN echo hello > /remove_me - ENV HELLO world - RUN rm /remove_me - ` - // build and get the ID that we can use later for history comparison - origID, err := buildImage("test", dockerFile, false) - c.Assert(err, checker.IsNil) - - // build with squash - id, err := buildImage("test", dockerFile, true, "--squash") - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "run", "--rm", id, "/bin/sh", "-c", "cat /hello") - c.Assert(strings.TrimSpace(out), checker.Equals, "hello\nworld") - - dockerCmd(c, "run", "--rm", id, "/bin/sh", "-c", "[ ! -f /remove_me ]") - dockerCmd(c, "run", "--rm", id, "/bin/sh", "-c", `[ "$(echo $HELLO)" == "world" ]`) - - // make sure the ID produced is the ID of the tag we specified - inspectID, err := inspectImage("test", ".ID") - c.Assert(err, checker.IsNil) - c.Assert(inspectID, checker.Equals, id) - - origHistory, _ := dockerCmd(c, "history", origID) - testHistory, _ := dockerCmd(c, "history", "test") - - splitOrigHistory := strings.Split(strings.TrimSpace(origHistory), "\n") - splitTestHistory := strings.Split(strings.TrimSpace(testHistory), "\n") - c.Assert(len(splitTestHistory), checker.Equals, len(splitOrigHistory)+1) - - out, err = inspectImage(id, "len .RootFS.Layers") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "3") -} - -func (s *DockerSuite) TestBuildContChar(c *check.C) { - name := "testbuildcontchar" - - _, out, err := buildImageWithOut(name, - `FROM busybox\`, true) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "Step 1/1 : FROM busybox") - - _, out, err = buildImageWithOut(name, - `FROM busybox - RUN echo hi \`, true) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "Step 1/2 : FROM busybox") - c.Assert(out, checker.Contains, "Step 2/2 : RUN echo hi\n") - - _, out, err = buildImageWithOut(name, - `FROM busybox - RUN echo hi \\`, true) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "Step 1/2 : FROM busybox") - c.Assert(out, checker.Contains, "Step 2/2 : RUN echo hi \\\n") - - _, out, err = buildImageWithOut(name, - `FROM busybox - RUN echo hi \\\`, true) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "Step 1/2 : FROM busybox") - c.Assert(out, checker.Contains, "Step 2/2 : RUN echo hi \\\\\n") -} - -// TestBuildOpaqueDirectory tests that a build succeeds which -// creates opaque directories. -// See https://github.com/docker/docker/issues/25244 -func (s *DockerSuite) TestBuildOpaqueDirectory(c *check.C) { - testRequires(c, DaemonIsLinux) - - dockerFile := ` - FROM busybox - RUN mkdir /dir1 && touch /dir1/f1 - RUN rm -rf /dir1 && mkdir /dir1 && touch /dir1/f2 - RUN touch /dir1/f3 - RUN [ -f /dir1/f2 ] - ` - - // Test that build succeeds, last command fails if opaque directory - // was not handled correctly - _, err := buildImage("testopaquedirectory", dockerFile, false) - c.Assert(err, checker.IsNil) -} - -// Windows test for USER in dockerfile -func (s *DockerSuite) TestBuildWindowsUser(c *check.C) { - testRequires(c, DaemonIsWindows) - name := "testbuildwindowsuser" - _, out, err := buildImageWithOut(name, - `FROM `+WindowsBaseImage+` - RUN net user user /add - USER user - RUN set username - `, - true) - if err != nil { - c.Fatal(err) - } - c.Assert(strings.ToLower(out), checker.Contains, "username=user") -} - -// Verifies if COPY file . when WORKDIR is set to a non-existing directory, -// the directory is created and the file is copied into the directory, -// as opposed to the file being copied as a file with the name of the -// directory. Fix for 27545 (found on Windows, but regression good for Linux too). -// Note 27545 was reverted in 28505, but a new fix was added subsequently in 28514. -func (s *DockerSuite) TestBuildCopyFileDotWithWorkdir(c *check.C) { - name := "testbuildcopyfiledotwithworkdir" - ctx, err := fakeContext(`FROM busybox -WORKDIR /foo -COPY file . -RUN ["cat", "/foo/file"] -`, - map[string]string{}) - - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - if err := ctx.Add("file", "content"); err != nil { - c.Fatal(err) - } - - if _, err = buildImageFromContext(name, ctx, true); err != nil { - c.Fatal(err) - } -} - -// Case-insensitive environment variables on Windows -func (s *DockerSuite) TestBuildWindowsEnvCaseInsensitive(c *check.C) { - testRequires(c, DaemonIsWindows) - name := "testbuildwindowsenvcaseinsensitive" - if _, err := buildImage(name, ` - FROM `+WindowsBaseImage+` - ENV FOO=bar foo=bar - `, true); err != nil { - c.Fatal(err) - } - res := inspectFieldJSON(c, name, "Config.Env") - if res != `["foo=bar"]` { // Should not have FOO=bar in it - takes the last one processed. And only one entry as deduped. - c.Fatalf("Case insensitive environment variables on Windows failed. Got %s", res) - } -} - -// Test case for 29667 -func (s *DockerSuite) TestBuildWorkdirImageCmd(c *check.C) { - testRequires(c, DaemonIsLinux) - - image := "testworkdirimagecmd" - dockerfile := ` -FROM busybox -WORKDIR /foo/bar -` - out, err := buildImage(image, dockerfile, true) - c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) - - out, _ = dockerCmd(c, "inspect", "--format", "{{ json .Config.Cmd }}", image) - c.Assert(strings.TrimSpace(out), checker.Equals, `["sh"]`) - - image = "testworkdirlabelimagecmd" - dockerfile = ` -FROM busybox -WORKDIR /foo/bar -LABEL a=b -` - out, err = buildImage(image, dockerfile, true) - c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) - - out, _ = dockerCmd(c, "inspect", "--format", "{{ json .Config.Cmd }}", image) - c.Assert(strings.TrimSpace(out), checker.Equals, `["sh"]`) -} - -// Test case for 28902/28090 -func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) { - testRequires(c, DaemonIsLinux) - - dockerFile := ` - FROM golang:1.7-alpine - WORKDIR / - ` - _, err := buildImage("testbuildworkdircmd", dockerFile, true) - c.Assert(err, checker.IsNil) - - _, out, err := buildImageWithOut("testbuildworkdircmd", dockerFile, true) - c.Assert(err, checker.IsNil) - c.Assert(strings.Count(out, "Using cache"), checker.Equals, 1) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_build_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_build_unix_test.go deleted file mode 100644 index 0205a92..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_build_unix_test.go +++ /dev/null @@ -1,207 +0,0 @@ -// +build !windows - -package main - -import ( - "bufio" - "bytes" - "encoding/json" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "regexp" - "strings" - "time" - - "github.com/docker/docker/pkg/integration" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/go-units" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) { - testRequires(c, cpuCfsQuota) - name := "testbuildresourceconstraints" - - ctx, err := fakeContext(` - FROM hello-world:frozen - RUN ["/hello"] - `, map[string]string{}) - c.Assert(err, checker.IsNil) - - _, _, err = dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "--ulimit", "nofile=42", "-t", name, ".") - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "ps", "-lq") - cID := strings.TrimSpace(out) - - type hostConfig struct { - Memory int64 - MemorySwap int64 - CpusetCpus string - CpusetMems string - CPUShares int64 - CPUQuota int64 - Ulimits []*units.Ulimit - } - - cfg := inspectFieldJSON(c, cID, "HostConfig") - - var c1 hostConfig - err = json.Unmarshal([]byte(cfg), &c1) - c.Assert(err, checker.IsNil, check.Commentf(cfg)) - - c.Assert(c1.Memory, checker.Equals, int64(64*1024*1024), check.Commentf("resource constraints not set properly for Memory")) - c.Assert(c1.MemorySwap, checker.Equals, int64(-1), check.Commentf("resource constraints not set properly for MemorySwap")) - c.Assert(c1.CpusetCpus, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetCpus")) - c.Assert(c1.CpusetMems, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetMems")) - c.Assert(c1.CPUShares, checker.Equals, int64(100), check.Commentf("resource constraints not set properly for CPUShares")) - c.Assert(c1.CPUQuota, checker.Equals, int64(8000), check.Commentf("resource constraints not set properly for CPUQuota")) - c.Assert(c1.Ulimits[0].Name, checker.Equals, "nofile", check.Commentf("resource constraints not set properly for Ulimits")) - c.Assert(c1.Ulimits[0].Hard, checker.Equals, int64(42), check.Commentf("resource constraints not set properly for Ulimits")) - - // Make sure constraints aren't saved to image - dockerCmd(c, "run", "--name=test", name) - - cfg = inspectFieldJSON(c, "test", "HostConfig") - - var c2 hostConfig - err = json.Unmarshal([]byte(cfg), &c2) - c.Assert(err, checker.IsNil, check.Commentf(cfg)) - - c.Assert(c2.Memory, check.Not(checker.Equals), int64(64*1024*1024), check.Commentf("resource leaked from build for Memory")) - c.Assert(c2.MemorySwap, check.Not(checker.Equals), int64(-1), check.Commentf("resource leaked from build for MemorySwap")) - c.Assert(c2.CpusetCpus, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetCpus")) - c.Assert(c2.CpusetMems, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetMems")) - c.Assert(c2.CPUShares, check.Not(checker.Equals), int64(100), check.Commentf("resource leaked from build for CPUShares")) - c.Assert(c2.CPUQuota, check.Not(checker.Equals), int64(8000), check.Commentf("resource leaked from build for CPUQuota")) - c.Assert(c2.Ulimits, checker.IsNil, check.Commentf("resource leaked from build for Ulimits")) -} - -func (s *DockerSuite) TestBuildAddChangeOwnership(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildaddown" - - ctx := func() *FakeContext { - dockerfile := ` - FROM busybox - ADD foo /bar/ - RUN [ $(stat -c %U:%G "/bar") = 'root:root' ] - RUN [ $(stat -c %U:%G "/bar/foo") = 'root:root' ] - ` - tmpDir, err := ioutil.TempDir("", "fake-context") - c.Assert(err, check.IsNil) - testFile, err := os.Create(filepath.Join(tmpDir, "foo")) - if err != nil { - c.Fatalf("failed to create foo file: %v", err) - } - defer testFile.Close() - - chownCmd := exec.Command("chown", "daemon:daemon", "foo") - chownCmd.Dir = tmpDir - out, _, err := runCommandWithOutput(chownCmd) - if err != nil { - c.Fatal(err, out) - } - - if err := ioutil.WriteFile(filepath.Join(tmpDir, "Dockerfile"), []byte(dockerfile), 0644); err != nil { - c.Fatalf("failed to open destination dockerfile: %v", err) - } - return fakeContextFromDir(tmpDir) - }() - - defer ctx.Close() - - if _, err := buildImageFromContext(name, ctx, true); err != nil { - c.Fatalf("build failed to complete for TestBuildAddChangeOwnership: %v", err) - } -} - -// Test that an infinite sleep during a build is killed if the client disconnects. -// This test is fairly hairy because there are lots of ways to race. -// Strategy: -// * Monitor the output of docker events starting from before -// * Run a 1-year-long sleep from a docker build. -// * When docker events sees container start, close the "docker build" command -// * Wait for docker events to emit a dying event. -func (s *DockerSuite) TestBuildCancellationKillsSleep(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testbuildcancellation" - - observer, err := newEventObserver(c) - c.Assert(err, checker.IsNil) - err = observer.Start() - c.Assert(err, checker.IsNil) - defer observer.Stop() - - // (Note: one year, will never finish) - ctx, err := fakeContext("FROM busybox\nRUN sleep 31536000", nil) - if err != nil { - c.Fatal(err) - } - defer ctx.Close() - - buildCmd := exec.Command(dockerBinary, "build", "-t", name, ".") - buildCmd.Dir = ctx.Dir - - stdoutBuild, err := buildCmd.StdoutPipe() - if err := buildCmd.Start(); err != nil { - c.Fatalf("failed to run build: %s", err) - } - - matchCID := regexp.MustCompile("Running in (.+)") - scanner := bufio.NewScanner(stdoutBuild) - - outputBuffer := new(bytes.Buffer) - var buildID string - for scanner.Scan() { - line := scanner.Text() - outputBuffer.WriteString(line) - outputBuffer.WriteString("\n") - if matches := matchCID.FindStringSubmatch(line); len(matches) > 0 { - buildID = matches[1] - break - } - } - - if buildID == "" { - c.Fatalf("Unable to find build container id in build output:\n%s", outputBuffer.String()) - } - - testActions := map[string]chan bool{ - "start": make(chan bool, 1), - "die": make(chan bool, 1), - } - - matcher := matchEventLine(buildID, "container", testActions) - processor := processEventMatch(testActions) - go observer.Match(matcher, processor) - - select { - case <-time.After(10 * time.Second): - observer.CheckEventError(c, buildID, "start", matcher) - case <-testActions["start"]: - // ignore, done - } - - // Send a kill to the `docker build` command. - // Causes the underlying build to be cancelled due to socket close. - if err := buildCmd.Process.Kill(); err != nil { - c.Fatalf("error killing build command: %s", err) - } - - // Get the exit status of `docker build`, check it exited because killed. - if err := buildCmd.Wait(); err != nil && !integration.IsKilled(err) { - c.Fatalf("wait failed during build run: %T %s", err, err) - } - - select { - case <-time.After(10 * time.Second): - observer.CheckEventError(c, buildID, "die", matcher) - case <-testActions["die"]: - // ignore, done - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_by_digest_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_by_digest_test.go deleted file mode 100644 index c2d8546..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_by_digest_test.go +++ /dev/null @@ -1,693 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - "regexp" - "strings" - - "github.com/docker/distribution/digest" - "github.com/docker/distribution/manifest/schema1" - "github.com/docker/distribution/manifest/schema2" - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/stringutils" - "github.com/go-check/check" -) - -var ( - remoteRepoName = "dockercli/busybox-by-dgst" - repoName = fmt.Sprintf("%s/%s", privateRegistryURL, remoteRepoName) - pushDigestRegex = regexp.MustCompile("[\\S]+: digest: ([\\S]+) size: [0-9]+") - digestRegex = regexp.MustCompile("Digest: ([\\S]+)") -) - -func setupImage(c *check.C) (digest.Digest, error) { - return setupImageWithTag(c, "latest") -} - -func setupImageWithTag(c *check.C, tag string) (digest.Digest, error) { - containerName := "busyboxbydigest" - - dockerCmd(c, "run", "-e", "digest=1", "--name", containerName, "busybox") - - // tag the image to upload it to the private registry - repoAndTag := repoName + ":" + tag - out, _, err := dockerCmdWithError("commit", containerName, repoAndTag) - c.Assert(err, checker.IsNil, check.Commentf("image tagging failed: %s", out)) - - // delete the container as we don't need it any more - err = deleteContainer(containerName) - c.Assert(err, checker.IsNil) - - // push the image - out, _, err = dockerCmdWithError("push", repoAndTag) - c.Assert(err, checker.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out)) - - // delete our local repo that we previously tagged - rmiout, _, err := dockerCmdWithError("rmi", repoAndTag) - c.Assert(err, checker.IsNil, check.Commentf("error deleting images prior to real test: %s", rmiout)) - - matches := pushDigestRegex.FindStringSubmatch(out) - c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from push output: %s", out)) - pushDigest := matches[1] - - return digest.Digest(pushDigest), nil -} - -func testPullByTagDisplaysDigest(c *check.C) { - testRequires(c, DaemonIsLinux) - pushDigest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - // pull from the registry using the tag - out, _ := dockerCmd(c, "pull", repoName) - - // the pull output includes "Digest: ", so find that - matches := digestRegex.FindStringSubmatch(out) - c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out)) - pullDigest := matches[1] - - // make sure the pushed and pull digests match - c.Assert(pushDigest.String(), checker.Equals, pullDigest) -} - -func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *check.C) { - testPullByTagDisplaysDigest(c) -} - -func (s *DockerSchema1RegistrySuite) TestPullByTagDisplaysDigest(c *check.C) { - testPullByTagDisplaysDigest(c) -} - -func testPullByDigest(c *check.C) { - testRequires(c, DaemonIsLinux) - pushDigest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - // pull from the registry using the @ reference - imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) - out, _ := dockerCmd(c, "pull", imageReference) - - // the pull output includes "Digest: ", so find that - matches := digestRegex.FindStringSubmatch(out) - c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out)) - pullDigest := matches[1] - - // make sure the pushed and pull digests match - c.Assert(pushDigest.String(), checker.Equals, pullDigest) -} - -func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) { - testPullByDigest(c) -} - -func (s *DockerSchema1RegistrySuite) TestPullByDigest(c *check.C) { - testPullByDigest(c) -} - -func testPullByDigestNoFallback(c *check.C) { - testRequires(c, DaemonIsLinux) - // pull from the registry using the @ reference - imageReference := fmt.Sprintf("%s@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", repoName) - out, _, err := dockerCmdWithError("pull", imageReference) - c.Assert(err, checker.NotNil, check.Commentf("expected non-zero exit status and correct error message when pulling non-existing image")) - c.Assert(out, checker.Contains, fmt.Sprintf("manifest for %s not found", imageReference), check.Commentf("expected non-zero exit status and correct error message when pulling non-existing image")) -} - -func (s *DockerRegistrySuite) TestPullByDigestNoFallback(c *check.C) { - testPullByDigestNoFallback(c) -} - -func (s *DockerSchema1RegistrySuite) TestPullByDigestNoFallback(c *check.C) { - testPullByDigestNoFallback(c) -} - -func (s *DockerRegistrySuite) TestCreateByDigest(c *check.C) { - pushDigest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) - - containerName := "createByDigest" - dockerCmd(c, "create", "--name", containerName, imageReference) - - res := inspectField(c, containerName, "Config.Image") - c.Assert(res, checker.Equals, imageReference) -} - -func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) { - pushDigest, err := setupImage(c) - c.Assert(err, checker.IsNil) - - imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) - - containerName := "runByDigest" - out, _ := dockerCmd(c, "run", "--name", containerName, imageReference, "sh", "-c", "echo found=$digest") - - foundRegex := regexp.MustCompile("found=([^\n]+)") - matches := foundRegex.FindStringSubmatch(out) - c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out)) - c.Assert(matches[1], checker.Equals, "1", check.Commentf("Expected %q, got %q", "1", matches[1])) - - res := inspectField(c, containerName, "Config.Image") - c.Assert(res, checker.Equals, imageReference) -} - -func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) { - digest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - imageReference := fmt.Sprintf("%s@%s", repoName, digest) - - // pull from the registry using the @ reference - dockerCmd(c, "pull", imageReference) - - // make sure inspect runs ok - inspectField(c, imageReference, "Id") - - // do the delete - err = deleteImages(imageReference) - c.Assert(err, checker.IsNil, check.Commentf("unexpected error deleting image")) - - // try to inspect again - it should error this time - _, err = inspectFieldWithError(imageReference, "Id") - //unexpected nil err trying to inspect what should be a non-existent image - c.Assert(err, checker.NotNil) - c.Assert(err.Error(), checker.Contains, "No such object") -} - -func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) { - digest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - imageReference := fmt.Sprintf("%s@%s", repoName, digest) - - // pull from the registry using the @ reference - dockerCmd(c, "pull", imageReference) - - // get the image id - imageID := inspectField(c, imageReference, "Id") - - // do the build - name := "buildbydigest" - _, err = buildImage(name, fmt.Sprintf( - `FROM %s - CMD ["/bin/echo", "Hello World"]`, imageReference), - true) - c.Assert(err, checker.IsNil) - - // get the build's image id - res := inspectField(c, name, "Config.Image") - // make sure they match - c.Assert(res, checker.Equals, imageID) -} - -func (s *DockerRegistrySuite) TestTagByDigest(c *check.C) { - digest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - imageReference := fmt.Sprintf("%s@%s", repoName, digest) - - // pull from the registry using the @ reference - dockerCmd(c, "pull", imageReference) - - // tag it - tag := "tagbydigest" - dockerCmd(c, "tag", imageReference, tag) - - expectedID := inspectField(c, imageReference, "Id") - - tagID := inspectField(c, tag, "Id") - c.Assert(tagID, checker.Equals, expectedID) -} - -func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) { - digest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - imageReference := fmt.Sprintf("%s@%s", repoName, digest) - - // pull from the registry using the @ reference - dockerCmd(c, "pull", imageReference) - - out, _ := dockerCmd(c, "images") - c.Assert(out, checker.Not(checker.Contains), "DIGEST", check.Commentf("list output should not have contained DIGEST header")) -} - -func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) { - - // setup image1 - digest1, err := setupImageWithTag(c, "tag1") - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - imageReference1 := fmt.Sprintf("%s@%s", repoName, digest1) - c.Logf("imageReference1 = %s", imageReference1) - - // pull image1 by digest - dockerCmd(c, "pull", imageReference1) - - // list images - out, _ := dockerCmd(c, "images", "--digests") - - // make sure repo shown, tag=, digest = $digest1 - re1 := regexp.MustCompile(`\s*` + repoName + `\s*\s*` + digest1.String() + `\s`) - c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out)) - // setup image2 - digest2, err := setupImageWithTag(c, "tag2") - //error setting up image - c.Assert(err, checker.IsNil) - imageReference2 := fmt.Sprintf("%s@%s", repoName, digest2) - c.Logf("imageReference2 = %s", imageReference2) - - // pull image1 by digest - dockerCmd(c, "pull", imageReference1) - - // pull image2 by digest - dockerCmd(c, "pull", imageReference2) - - // list images - out, _ = dockerCmd(c, "images", "--digests") - - // make sure repo shown, tag=, digest = $digest1 - c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out)) - - // make sure repo shown, tag=, digest = $digest2 - re2 := regexp.MustCompile(`\s*` + repoName + `\s*\s*` + digest2.String() + `\s`) - c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out)) - - // pull tag1 - dockerCmd(c, "pull", repoName+":tag1") - - // list images - out, _ = dockerCmd(c, "images", "--digests") - - // make sure image 1 has repo, tag, AND repo, , digest - reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*tag1\s*` + digest1.String() + `\s`) - c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out)) - // make sure image 2 has repo, , digest - c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out)) - - // pull tag 2 - dockerCmd(c, "pull", repoName+":tag2") - - // list images - out, _ = dockerCmd(c, "images", "--digests") - - // make sure image 1 has repo, tag, digest - c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out)) - - // make sure image 2 has repo, tag, digest - reWithDigest2 := regexp.MustCompile(`\s*` + repoName + `\s*tag2\s*` + digest2.String() + `\s`) - c.Assert(reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out)) - - // list images - out, _ = dockerCmd(c, "images", "--digests") - - // make sure image 1 has repo, tag, digest - c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out)) - // make sure image 2 has repo, tag, digest - c.Assert(reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out)) - // make sure busybox has tag, but not digest - busyboxRe := regexp.MustCompile(`\s*busybox\s*latest\s*\s`) - c.Assert(busyboxRe.MatchString(out), checker.True, check.Commentf("expected %q: %s", busyboxRe.String(), out)) -} - -func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *check.C) { - // setup image1 - digest1, err := setupImageWithTag(c, "dangle1") - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - imageReference1 := fmt.Sprintf("%s@%s", repoName, digest1) - c.Logf("imageReference1 = %s", imageReference1) - - // pull image1 by digest - dockerCmd(c, "pull", imageReference1) - - // list images - out, _ := dockerCmd(c, "images", "--digests") - - // make sure repo shown, tag=, digest = $digest1 - re1 := regexp.MustCompile(`\s*` + repoName + `\s*\s*` + digest1.String() + `\s`) - c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out)) - // setup image2 - digest2, err := setupImageWithTag(c, "dangle2") - //error setting up image - c.Assert(err, checker.IsNil) - imageReference2 := fmt.Sprintf("%s@%s", repoName, digest2) - c.Logf("imageReference2 = %s", imageReference2) - - // pull image1 by digest - dockerCmd(c, "pull", imageReference1) - - // pull image2 by digest - dockerCmd(c, "pull", imageReference2) - - // list images - out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true") - - // make sure repo shown, tag=, digest = $digest1 - c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out)) - - // make sure repo shown, tag=, digest = $digest2 - re2 := regexp.MustCompile(`\s*` + repoName + `\s*\s*` + digest2.String() + `\s`) - c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out)) - - // pull dangle1 tag - dockerCmd(c, "pull", repoName+":dangle1") - - // list images - out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true") - - // make sure image 1 has repo, tag, AND repo, , digest - reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*dangle1\s*` + digest1.String() + `\s`) - c.Assert(reWithDigest1.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest1.String(), out)) - // make sure image 2 has repo, , digest - c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out)) - - // pull dangle2 tag - dockerCmd(c, "pull", repoName+":dangle2") - - // list images, show tagged images - out, _ = dockerCmd(c, "images", "--digests") - - // make sure image 1 has repo, tag, digest - c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out)) - - // make sure image 2 has repo, tag, digest - reWithDigest2 := regexp.MustCompile(`\s*` + repoName + `\s*dangle2\s*` + digest2.String() + `\s`) - c.Assert(reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out)) - - // list images, no longer dangling, should not match - out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true") - - // make sure image 1 has repo, tag, digest - c.Assert(reWithDigest1.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest1.String(), out)) - // make sure image 2 has repo, tag, digest - c.Assert(reWithDigest2.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest2.String(), out)) -} - -func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *check.C) { - digest, err := setupImage(c) - c.Assert(err, check.IsNil, check.Commentf("error setting up image")) - - imageReference := fmt.Sprintf("%s@%s", repoName, digest) - - // pull from the registry using the @ reference - dockerCmd(c, "pull", imageReference) - - out, _ := dockerCmd(c, "inspect", imageReference) - - var imageJSON []types.ImageInspect - err = json.Unmarshal([]byte(out), &imageJSON) - c.Assert(err, checker.IsNil) - c.Assert(imageJSON, checker.HasLen, 1) - c.Assert(imageJSON[0].RepoDigests, checker.HasLen, 1) - c.Assert(stringutils.InSlice(imageJSON[0].RepoDigests, imageReference), checker.Equals, true) -} - -func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c *check.C) { - digest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - imageReference := fmt.Sprintf("%s@%s", repoName, digest) - - // pull from the registry using the @ reference - dockerCmd(c, "pull", imageReference) - - // build an image from it - imageName1 := "images_ps_filter_test" - _, err = buildImage(imageName1, fmt.Sprintf( - `FROM %s - LABEL match me 1`, imageReference), true) - c.Assert(err, checker.IsNil) - - // run a container based on that - dockerCmd(c, "run", "--name=test1", imageReference, "echo", "hello") - expectedID, err := getIDByName("test1") - c.Assert(err, check.IsNil) - - // run a container based on the a descendant of that too - dockerCmd(c, "run", "--name=test2", imageName1, "echo", "hello") - expectedID1, err := getIDByName("test2") - c.Assert(err, check.IsNil) - - expectedIDs := []string{expectedID, expectedID1} - - // Invalid imageReference - out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", fmt.Sprintf("--filter=ancestor=busybox@%s", digest)) - // Filter container for ancestor filter should be empty - c.Assert(strings.TrimSpace(out), checker.Equals, "") - - // Valid imageReference - out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+imageReference) - checkPsAncestorFilterOutput(c, out, imageReference, expectedIDs) -} - -func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *check.C) { - pushDigest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - // pull from the registry using the @ reference - imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) - dockerCmd(c, "pull", imageReference) - // just in case... - - dockerCmd(c, "tag", imageReference, repoName+":sometag") - - imageID := inspectField(c, imageReference, "Id") - - dockerCmd(c, "rmi", imageID) - - _, err = inspectFieldWithError(imageID, "Id") - c.Assert(err, checker.NotNil, check.Commentf("image should have been deleted")) -} - -func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndTag(c *check.C) { - pushDigest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - // pull from the registry using the @ reference - imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) - dockerCmd(c, "pull", imageReference) - - imageID := inspectField(c, imageReference, "Id") - - repoTag := repoName + ":sometag" - repoTag2 := repoName + ":othertag" - dockerCmd(c, "tag", imageReference, repoTag) - dockerCmd(c, "tag", imageReference, repoTag2) - - dockerCmd(c, "rmi", repoTag2) - - // rmi should have deleted only repoTag2, because there's another tag - inspectField(c, repoTag, "Id") - - dockerCmd(c, "rmi", repoTag) - - // rmi should have deleted the tag, the digest reference, and the image itself - _, err = inspectFieldWithError(imageID, "Id") - c.Assert(err, checker.NotNil, check.Commentf("image should have been deleted")) -} - -func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndMultiRepoTag(c *check.C) { - pushDigest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - repo2 := fmt.Sprintf("%s/%s", repoName, "repo2") - - // pull from the registry using the @ reference - imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) - dockerCmd(c, "pull", imageReference) - - imageID := inspectField(c, imageReference, "Id") - - repoTag := repoName + ":sometag" - repoTag2 := repo2 + ":othertag" - dockerCmd(c, "tag", imageReference, repoTag) - dockerCmd(c, "tag", imageReference, repoTag2) - - dockerCmd(c, "rmi", repoTag) - - // rmi should have deleted repoTag and image reference, but left repoTag2 - inspectField(c, repoTag2, "Id") - _, err = inspectFieldWithError(imageReference, "Id") - c.Assert(err, checker.NotNil, check.Commentf("image digest reference should have been removed")) - - _, err = inspectFieldWithError(repoTag, "Id") - c.Assert(err, checker.NotNil, check.Commentf("image tag reference should have been removed")) - - dockerCmd(c, "rmi", repoTag2) - - // rmi should have deleted the tag, the digest reference, and the image itself - _, err = inspectFieldWithError(imageID, "Id") - c.Assert(err, checker.NotNil, check.Commentf("image should have been deleted")) -} - -// TestPullFailsWithAlteredManifest tests that a `docker pull` fails when -// we have modified a manifest blob and its digest cannot be verified. -// This is the schema2 version of the test. -func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) { - testRequires(c, DaemonIsLinux) - manifestDigest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - // Load the target manifest blob. - manifestBlob := s.reg.readBlobContents(c, manifestDigest) - - var imgManifest schema2.Manifest - err = json.Unmarshal(manifestBlob, &imgManifest) - c.Assert(err, checker.IsNil, check.Commentf("unable to decode image manifest from blob")) - - // Change a layer in the manifest. - imgManifest.Layers[0].Digest = digest.Digest("sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") - - // Move the existing data file aside, so that we can replace it with a - // malicious blob of data. NOTE: we defer the returned undo func. - undo := s.reg.tempMoveBlobData(c, manifestDigest) - defer undo() - - alteredManifestBlob, err := json.MarshalIndent(imgManifest, "", " ") - c.Assert(err, checker.IsNil, check.Commentf("unable to encode altered image manifest to JSON")) - - s.reg.writeBlobContents(c, manifestDigest, alteredManifestBlob) - - // Now try pulling that image by digest. We should get an error about - // digest verification for the manifest digest. - - // Pull from the registry using the @ reference. - imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest) - out, exitStatus, _ := dockerCmdWithError("pull", imageReference) - c.Assert(exitStatus, checker.Not(check.Equals), 0) - - expectedErrorMsg := fmt.Sprintf("manifest verification failed for digest %s", manifestDigest) - c.Assert(out, checker.Contains, expectedErrorMsg) -} - -// TestPullFailsWithAlteredManifest tests that a `docker pull` fails when -// we have modified a manifest blob and its digest cannot be verified. -// This is the schema1 version of the test. -func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) { - testRequires(c, DaemonIsLinux) - manifestDigest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - // Load the target manifest blob. - manifestBlob := s.reg.readBlobContents(c, manifestDigest) - - var imgManifest schema1.Manifest - err = json.Unmarshal(manifestBlob, &imgManifest) - c.Assert(err, checker.IsNil, check.Commentf("unable to decode image manifest from blob")) - - // Change a layer in the manifest. - imgManifest.FSLayers[0] = schema1.FSLayer{ - BlobSum: digest.Digest("sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"), - } - - // Move the existing data file aside, so that we can replace it with a - // malicious blob of data. NOTE: we defer the returned undo func. - undo := s.reg.tempMoveBlobData(c, manifestDigest) - defer undo() - - alteredManifestBlob, err := json.MarshalIndent(imgManifest, "", " ") - c.Assert(err, checker.IsNil, check.Commentf("unable to encode altered image manifest to JSON")) - - s.reg.writeBlobContents(c, manifestDigest, alteredManifestBlob) - - // Now try pulling that image by digest. We should get an error about - // digest verification for the manifest digest. - - // Pull from the registry using the @ reference. - imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest) - out, exitStatus, _ := dockerCmdWithError("pull", imageReference) - c.Assert(exitStatus, checker.Not(check.Equals), 0) - - expectedErrorMsg := fmt.Sprintf("image verification failed for digest %s", manifestDigest) - c.Assert(out, checker.Contains, expectedErrorMsg) -} - -// TestPullFailsWithAlteredLayer tests that a `docker pull` fails when -// we have modified a layer blob and its digest cannot be verified. -// This is the schema2 version of the test. -func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) { - testRequires(c, DaemonIsLinux) - manifestDigest, err := setupImage(c) - c.Assert(err, checker.IsNil) - - // Load the target manifest blob. - manifestBlob := s.reg.readBlobContents(c, manifestDigest) - - var imgManifest schema2.Manifest - err = json.Unmarshal(manifestBlob, &imgManifest) - c.Assert(err, checker.IsNil) - - // Next, get the digest of one of the layers from the manifest. - targetLayerDigest := imgManifest.Layers[0].Digest - - // Move the existing data file aside, so that we can replace it with a - // malicious blob of data. NOTE: we defer the returned undo func. - undo := s.reg.tempMoveBlobData(c, targetLayerDigest) - defer undo() - - // Now make a fake data blob in this directory. - s.reg.writeBlobContents(c, targetLayerDigest, []byte("This is not the data you are looking for.")) - - // Now try pulling that image by digest. We should get an error about - // digest verification for the target layer digest. - - // Remove distribution cache to force a re-pull of the blobs - if err := os.RemoveAll(filepath.Join(dockerBasePath, "image", s.d.storageDriver, "distribution")); err != nil { - c.Fatalf("error clearing distribution cache: %v", err) - } - - // Pull from the registry using the @ reference. - imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest) - out, exitStatus, _ := dockerCmdWithError("pull", imageReference) - c.Assert(exitStatus, checker.Not(check.Equals), 0, check.Commentf("expected a non-zero exit status")) - - expectedErrorMsg := fmt.Sprintf("filesystem layer verification failed for digest %s", targetLayerDigest) - c.Assert(out, checker.Contains, expectedErrorMsg, check.Commentf("expected error message in output: %s", out)) -} - -// TestPullFailsWithAlteredLayer tests that a `docker pull` fails when -// we have modified a layer blob and its digest cannot be verified. -// This is the schema1 version of the test. -func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) { - testRequires(c, DaemonIsLinux) - manifestDigest, err := setupImage(c) - c.Assert(err, checker.IsNil) - - // Load the target manifest blob. - manifestBlob := s.reg.readBlobContents(c, manifestDigest) - - var imgManifest schema1.Manifest - err = json.Unmarshal(manifestBlob, &imgManifest) - c.Assert(err, checker.IsNil) - - // Next, get the digest of one of the layers from the manifest. - targetLayerDigest := imgManifest.FSLayers[0].BlobSum - - // Move the existing data file aside, so that we can replace it with a - // malicious blob of data. NOTE: we defer the returned undo func. - undo := s.reg.tempMoveBlobData(c, targetLayerDigest) - defer undo() - - // Now make a fake data blob in this directory. - s.reg.writeBlobContents(c, targetLayerDigest, []byte("This is not the data you are looking for.")) - - // Now try pulling that image by digest. We should get an error about - // digest verification for the target layer digest. - - // Remove distribution cache to force a re-pull of the blobs - if err := os.RemoveAll(filepath.Join(dockerBasePath, "image", s.d.storageDriver, "distribution")); err != nil { - c.Fatalf("error clearing distribution cache: %v", err) - } - - // Pull from the registry using the @ reference. - imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest) - out, exitStatus, _ := dockerCmdWithError("pull", imageReference) - c.Assert(exitStatus, checker.Not(check.Equals), 0, check.Commentf("expected a non-zero exit status")) - - expectedErrorMsg := fmt.Sprintf("filesystem layer verification failed for digest %s", targetLayerDigest) - c.Assert(out, checker.Contains, expectedErrorMsg, check.Commentf("expected error message in output: %s", out)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_commit_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_commit_test.go deleted file mode 100644 index 8008ae1..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_commit_test.go +++ /dev/null @@ -1,157 +0,0 @@ -package main - -import ( - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestCommitAfterContainerIsDone(c *check.C) { - out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo") - - cleanedContainerID := strings.TrimSpace(out) - - dockerCmd(c, "wait", cleanedContainerID) - - out, _ = dockerCmd(c, "commit", cleanedContainerID) - - cleanedImageID := strings.TrimSpace(out) - - dockerCmd(c, "inspect", cleanedImageID) -} - -func (s *DockerSuite) TestCommitWithoutPause(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-i", "-a", "stdin", "busybox", "echo", "foo") - - cleanedContainerID := strings.TrimSpace(out) - - dockerCmd(c, "wait", cleanedContainerID) - - out, _ = dockerCmd(c, "commit", "-p=false", cleanedContainerID) - - cleanedImageID := strings.TrimSpace(out) - - dockerCmd(c, "inspect", cleanedImageID) -} - -//test commit a paused container should not unpause it after commit -func (s *DockerSuite) TestCommitPausedContainer(c *check.C) { - testRequires(c, DaemonIsLinux) - defer unpauseAllContainers() - out, _ := dockerCmd(c, "run", "-i", "-d", "busybox") - - cleanedContainerID := strings.TrimSpace(out) - - dockerCmd(c, "pause", cleanedContainerID) - - out, _ = dockerCmd(c, "commit", cleanedContainerID) - - out = inspectField(c, cleanedContainerID, "State.Paused") - // commit should not unpause a paused container - c.Assert(out, checker.Contains, "true") -} - -func (s *DockerSuite) TestCommitNewFile(c *check.C) { - dockerCmd(c, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo") - - imageID, _ := dockerCmd(c, "commit", "commiter") - imageID = strings.TrimSpace(imageID) - - out, _ := dockerCmd(c, "run", imageID, "cat", "/foo") - actual := strings.TrimSpace(out) - c.Assert(actual, checker.Equals, "koye") -} - -func (s *DockerSuite) TestCommitHardlink(c *check.C) { - testRequires(c, DaemonIsLinux) - firstOutput, _ := dockerCmd(c, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2") - - chunks := strings.Split(strings.TrimSpace(firstOutput), " ") - inode := chunks[0] - chunks = strings.SplitAfterN(strings.TrimSpace(firstOutput), " ", 2) - c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])) - - imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks") - imageID = strings.TrimSpace(imageID) - - secondOutput, _ := dockerCmd(c, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2") - - chunks = strings.Split(strings.TrimSpace(secondOutput), " ") - inode = chunks[0] - chunks = strings.SplitAfterN(strings.TrimSpace(secondOutput), " ", 2) - c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])) -} - -func (s *DockerSuite) TestCommitTTY(c *check.C) { - dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls") - - imageID, _ := dockerCmd(c, "commit", "tty", "ttytest") - imageID = strings.TrimSpace(imageID) - - dockerCmd(c, "run", "ttytest", "/bin/ls") -} - -func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true") - - imageID, _ := dockerCmd(c, "commit", "bind-commit", "bindtest") - imageID = strings.TrimSpace(imageID) - - dockerCmd(c, "run", "bindtest", "true") -} - -func (s *DockerSuite) TestCommitChange(c *check.C) { - dockerCmd(c, "run", "--name", "test", "busybox", "true") - - imageID, _ := dockerCmd(c, "commit", - "--change", "EXPOSE 8080", - "--change", "ENV DEBUG true", - "--change", "ENV test 1", - "--change", "ENV PATH /foo", - "--change", "LABEL foo bar", - "--change", "CMD [\"/bin/sh\"]", - "--change", "WORKDIR /opt", - "--change", "ENTRYPOINT [\"/bin/sh\"]", - "--change", "USER testuser", - "--change", "VOLUME /var/lib/docker", - "--change", "ONBUILD /usr/local/bin/python-build --dir /app/src", - "test", "test-commit") - imageID = strings.TrimSpace(imageID) - - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - prefix = strings.ToUpper(prefix) // Force C: as that's how WORKDIR is normalised on Windows - expected := map[string]string{ - "Config.ExposedPorts": "map[8080/tcp:{}]", - "Config.Env": "[DEBUG=true test=1 PATH=/foo]", - "Config.Labels": "map[foo:bar]", - "Config.Cmd": "[/bin/sh]", - "Config.WorkingDir": prefix + slash + "opt", - "Config.Entrypoint": "[/bin/sh]", - "Config.User": "testuser", - "Config.Volumes": "map[/var/lib/docker:{}]", - "Config.OnBuild": "[/usr/local/bin/python-build --dir /app/src]", - } - - for conf, value := range expected { - res := inspectField(c, imageID, conf) - if res != value { - c.Errorf("%s('%s'), expected %s", conf, res, value) - } - } -} - -func (s *DockerSuite) TestCommitChangeLabels(c *check.C) { - dockerCmd(c, "run", "--name", "test", "--label", "some=label", "busybox", "true") - - imageID, _ := dockerCmd(c, "commit", - "--change", "LABEL some=label2", - "test", "test-commit") - imageID = strings.TrimSpace(imageID) - - c.Assert(inspectField(c, imageID, "Config.Labels"), checker.Equals, "map[some:label2]") - // check that container labels didn't change - c.Assert(inspectField(c, "test", "Config.Labels"), checker.Equals, "map[some:label]") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_config_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_config_test.go deleted file mode 100644 index 1d5e5ad..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_config_test.go +++ /dev/null @@ -1,140 +0,0 @@ -package main - -import ( - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "os/exec" - "path/filepath" - "runtime" - - "github.com/docker/docker/api" - "github.com/docker/docker/dockerversion" - "github.com/docker/docker/pkg/homedir" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestConfigHTTPHeader(c *check.C) { - testRequires(c, UnixCli) // Can't set/unset HOME on windows right now - // We either need a level of Go that supports Unsetenv (for cases - // when HOME/USERPROFILE isn't set), or we need to be able to use - // os/user but user.Current() only works if we aren't statically compiling - - var headers map[string][]string - - server := httptest.NewServer(http.HandlerFunc( - func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("API-Version", api.DefaultVersion) - headers = r.Header - })) - defer server.Close() - - homeKey := homedir.Key() - homeVal := homedir.Get() - tmpDir, err := ioutil.TempDir("", "fake-home") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir) - - dotDocker := filepath.Join(tmpDir, ".docker") - os.Mkdir(dotDocker, 0600) - tmpCfg := filepath.Join(dotDocker, "config.json") - - defer func() { os.Setenv(homeKey, homeVal) }() - os.Setenv(homeKey, tmpDir) - - data := `{ - "HttpHeaders": { "MyHeader": "MyValue" } - }` - - err = ioutil.WriteFile(tmpCfg, []byte(data), 0600) - c.Assert(err, checker.IsNil) - - cmd := exec.Command(dockerBinary, "-H="+server.URL[7:], "ps") - out, _, _ := runCommandWithOutput(cmd) - - c.Assert(headers["User-Agent"], checker.NotNil, check.Commentf("Missing User-Agent")) - - c.Assert(headers["User-Agent"][0], checker.Equals, "Docker-Client/"+dockerversion.Version+" ("+runtime.GOOS+")", check.Commentf("Badly formatted User-Agent,out:%v", out)) - - c.Assert(headers["Myheader"], checker.NotNil) - c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("Missing/bad header,out:%v", out)) - -} - -func (s *DockerSuite) TestConfigDir(c *check.C) { - cDir, err := ioutil.TempDir("", "fake-home") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(cDir) - - // First make sure pointing to empty dir doesn't generate an error - dockerCmd(c, "--config", cDir, "ps") - - // Test with env var too - cmd := exec.Command(dockerBinary, "ps") - cmd.Env = appendBaseEnv(true, "DOCKER_CONFIG="+cDir) - out, _, err := runCommandWithOutput(cmd) - - c.Assert(err, checker.IsNil, check.Commentf("ps2 didn't work,out:%v", out)) - - // Start a server so we can check to see if the config file was - // loaded properly - var headers map[string][]string - - server := httptest.NewServer(http.HandlerFunc( - func(w http.ResponseWriter, r *http.Request) { - headers = r.Header - })) - defer server.Close() - - // Create a dummy config file in our new config dir - data := `{ - "HttpHeaders": { "MyHeader": "MyValue" } - }` - - tmpCfg := filepath.Join(cDir, "config.json") - err = ioutil.WriteFile(tmpCfg, []byte(data), 0600) - c.Assert(err, checker.IsNil, check.Commentf("Err creating file")) - - env := appendBaseEnv(false) - - cmd = exec.Command(dockerBinary, "--config", cDir, "-H="+server.URL[7:], "ps") - cmd.Env = env - out, _, err = runCommandWithOutput(cmd) - - c.Assert(err, checker.NotNil, check.Commentf("out:%v", out)) - c.Assert(headers["Myheader"], checker.NotNil) - c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps3 - Missing header,out:%v", out)) - - // Reset headers and try again using env var this time - headers = map[string][]string{} - cmd = exec.Command(dockerBinary, "-H="+server.URL[7:], "ps") - cmd.Env = append(env, "DOCKER_CONFIG="+cDir) - out, _, err = runCommandWithOutput(cmd) - - c.Assert(err, checker.NotNil, check.Commentf("%v", out)) - c.Assert(headers["Myheader"], checker.NotNil) - c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps4 - Missing header,out:%v", out)) - - // Reset headers and make sure flag overrides the env var - headers = map[string][]string{} - cmd = exec.Command(dockerBinary, "--config", cDir, "-H="+server.URL[7:], "ps") - cmd.Env = append(env, "DOCKER_CONFIG=MissingDir") - out, _, err = runCommandWithOutput(cmd) - - c.Assert(err, checker.NotNil, check.Commentf("out:%v", out)) - c.Assert(headers["Myheader"], checker.NotNil) - c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps5 - Missing header,out:%v", out)) - - // Reset headers and make sure flag overrides the env var. - // Almost same as previous but make sure the "MissingDir" isn't - // ignore - we don't want to default back to the env var. - headers = map[string][]string{} - cmd = exec.Command(dockerBinary, "--config", "MissingDir", "-H="+server.URL[7:], "ps") - cmd.Env = append(env, "DOCKER_CONFIG="+cDir) - out, _, err = runCommandWithOutput(cmd) - - c.Assert(err, checker.NotNil, check.Commentf("out:%v", out)) - c.Assert(headers["Myheader"], checker.IsNil, check.Commentf("ps6 - Headers shouldn't be the expected value,out:%v", out)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_from_container_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_from_container_test.go deleted file mode 100644 index 9ed7e8c..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_from_container_test.go +++ /dev/null @@ -1,488 +0,0 @@ -package main - -import ( - "os" - "path/filepath" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// docker cp CONTAINER:PATH LOCALPATH - -// Try all of the test cases from the archive package which implements the -// internals of `docker cp` and ensure that the behavior matches when actually -// copying to and from containers. - -// Basic assumptions about SRC and DST: -// 1. SRC must exist. -// 2. If SRC ends with a trailing separator, it must be a directory. -// 3. DST parent directory must exist. -// 4. If DST exists as a file, it must not end with a trailing separator. - -// First get these easy error cases out of the way. - -// Test for error when SRC does not exist. -func (s *DockerSuite) TestCpFromErrSrcNotExists(c *check.C) { - containerID := makeTestContainer(c, testContainerOptions{}) - - tmpDir := getTestDir(c, "test-cp-from-err-src-not-exists") - defer os.RemoveAll(tmpDir) - - err := runDockerCp(c, containerCpPath(containerID, "file1"), tmpDir) - c.Assert(err, checker.NotNil) - - c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err)) -} - -// Test for error when SRC ends in a trailing -// path separator but it exists as a file. -func (s *DockerSuite) TestCpFromErrSrcNotDir(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{addContent: true}) - - tmpDir := getTestDir(c, "test-cp-from-err-src-not-dir") - defer os.RemoveAll(tmpDir) - - err := runDockerCp(c, containerCpPathTrailingSep(containerID, "file1"), tmpDir) - c.Assert(err, checker.NotNil) - - c.Assert(isCpNotDir(err), checker.True, check.Commentf("expected IsNotDir error, but got %T: %s", err, err)) -} - -// Test for error when SRC is a valid file or directory, -// bu the DST parent directory does not exist. -func (s *DockerSuite) TestCpFromErrDstParentNotExists(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{addContent: true}) - - tmpDir := getTestDir(c, "test-cp-from-err-dst-parent-not-exists") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - // Try with a file source. - srcPath := containerCpPath(containerID, "/file1") - dstPath := cpPath(tmpDir, "notExists", "file1") - - err := runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err)) - - // Try with a directory source. - srcPath = containerCpPath(containerID, "/dir1") - - err = runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err)) -} - -// Test for error when DST ends in a trailing -// path separator but exists as a file. -func (s *DockerSuite) TestCpFromErrDstNotDir(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{addContent: true}) - - tmpDir := getTestDir(c, "test-cp-from-err-dst-not-dir") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - // Try with a file source. - srcPath := containerCpPath(containerID, "/file1") - dstPath := cpPathTrailingSep(tmpDir, "file1") - - err := runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCpNotDir(err), checker.True, check.Commentf("expected IsNotDir error, but got %T: %s", err, err)) - - // Try with a directory source. - srcPath = containerCpPath(containerID, "/dir1") - - err = runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCpNotDir(err), checker.True, check.Commentf("expected IsNotDir error, but got %T: %s", err, err)) -} - -// Check that copying from a container to a local symlink copies to the symlink -// target and does not overwrite the local symlink itself. -func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{addContent: true}) - - tmpDir := getTestDir(c, "test-cp-from-err-dst-not-dir") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - // First, copy a file from the container to a symlink to a file. This - // should overwrite the symlink target contents with the source contents. - srcPath := containerCpPath(containerID, "/file2") - dstPath := cpPath(tmpDir, "symlinkToFile1") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // The symlink should not have been modified. - c.Assert(symlinkTargetEquals(c, dstPath, "file1"), checker.IsNil) - - // The file should have the contents of "file2" now. - c.Assert(fileContentEquals(c, cpPath(tmpDir, "file1"), "file2\n"), checker.IsNil) - - // Next, copy a file from the container to a symlink to a directory. This - // should copy the file into the symlink target directory. - dstPath = cpPath(tmpDir, "symlinkToDir1") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // The symlink should not have been modified. - c.Assert(symlinkTargetEquals(c, dstPath, "dir1"), checker.IsNil) - - // The file should have the contents of "file2" now. - c.Assert(fileContentEquals(c, cpPath(tmpDir, "file2"), "file2\n"), checker.IsNil) - - // Next, copy a file from the container to a symlink to a file that does - // not exist (a broken symlink). This should create the target file with - // the contents of the source file. - dstPath = cpPath(tmpDir, "brokenSymlinkToFileX") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // The symlink should not have been modified. - c.Assert(symlinkTargetEquals(c, dstPath, "fileX"), checker.IsNil) - - // The file should have the contents of "file2" now. - c.Assert(fileContentEquals(c, cpPath(tmpDir, "fileX"), "file2\n"), checker.IsNil) - - // Next, copy a directory from the container to a symlink to a local - // directory. This should copy the directory into the symlink target - // directory and not modify the symlink. - srcPath = containerCpPath(containerID, "/dir2") - dstPath = cpPath(tmpDir, "symlinkToDir1") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // The symlink should not have been modified. - c.Assert(symlinkTargetEquals(c, dstPath, "dir1"), checker.IsNil) - - // The directory should now contain a copy of "dir2". - c.Assert(fileContentEquals(c, cpPath(tmpDir, "dir1/dir2/file2-1"), "file2-1\n"), checker.IsNil) - - // Next, copy a directory from the container to a symlink to a local - // directory that does not exist (a broken symlink). This should create - // the target as a directory with the contents of the source directory. It - // should not modify the symlink. - dstPath = cpPath(tmpDir, "brokenSymlinkToDirX") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // The symlink should not have been modified. - c.Assert(symlinkTargetEquals(c, dstPath, "dirX"), checker.IsNil) - - // The "dirX" directory should now be a copy of "dir2". - c.Assert(fileContentEquals(c, cpPath(tmpDir, "dirX/file2-1"), "file2-1\n"), checker.IsNil) -} - -// Possibilities are reduced to the remaining 10 cases: -// -// case | srcIsDir | onlyDirContents | dstExists | dstIsDir | dstTrSep | action -// =================================================================================================== -// A | no | - | no | - | no | create file -// B | no | - | no | - | yes | error -// C | no | - | yes | no | - | overwrite file -// D | no | - | yes | yes | - | create file in dst dir -// E | yes | no | no | - | - | create dir, copy contents -// F | yes | no | yes | no | - | error -// G | yes | no | yes | yes | - | copy dir and contents -// H | yes | yes | no | - | - | create dir, copy contents -// I | yes | yes | yes | no | - | error -// J | yes | yes | yes | yes | - | copy dir contents -// - -// A. SRC specifies a file and DST (no trailing path separator) doesn't -// exist. This should create a file with the name DST and copy the -// contents of the source file into it. -func (s *DockerSuite) TestCpFromCaseA(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - }) - - tmpDir := getTestDir(c, "test-cp-from-case-a") - defer os.RemoveAll(tmpDir) - - srcPath := containerCpPath(containerID, "/root/file1") - dstPath := cpPath(tmpDir, "itWorks.txt") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil) -} - -// B. SRC specifies a file and DST (with trailing path separator) doesn't -// exist. This should cause an error because the copy operation cannot -// create a directory when copying a single file. -func (s *DockerSuite) TestCpFromCaseB(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{addContent: true}) - - tmpDir := getTestDir(c, "test-cp-from-case-b") - defer os.RemoveAll(tmpDir) - - srcPath := containerCpPath(containerID, "/file1") - dstDir := cpPathTrailingSep(tmpDir, "testDir") - - err := runDockerCp(c, srcPath, dstDir) - c.Assert(err, checker.NotNil) - - c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err)) -} - -// C. SRC specifies a file and DST exists as a file. This should overwrite -// the file at DST with the contents of the source file. -func (s *DockerSuite) TestCpFromCaseC(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - }) - - tmpDir := getTestDir(c, "test-cp-from-case-c") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcPath := containerCpPath(containerID, "/root/file1") - dstPath := cpPath(tmpDir, "file2") - - // Ensure the local file starts with different content. - c.Assert(fileContentEquals(c, dstPath, "file2\n"), checker.IsNil) - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil) -} - -// D. SRC specifies a file and DST exists as a directory. This should place -// a copy of the source file inside it using the basename from SRC. Ensure -// this works whether DST has a trailing path separator or not. -func (s *DockerSuite) TestCpFromCaseD(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{addContent: true}) - - tmpDir := getTestDir(c, "test-cp-from-case-d") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcPath := containerCpPath(containerID, "/file1") - dstDir := cpPath(tmpDir, "dir1") - dstPath := filepath.Join(dstDir, "file1") - - // Ensure that dstPath doesn't exist. - _, err := os.Stat(dstPath) - c.Assert(os.IsNotExist(err), checker.True, check.Commentf("did not expect dstPath %q to exist", dstPath)) - - c.Assert(runDockerCp(c, srcPath, dstDir), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil) - - // Now try again but using a trailing path separator for dstDir. - - // unable to remove dstDir - c.Assert(os.RemoveAll(dstDir), checker.IsNil) - - // unable to make dstDir - c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil) - - dstDir = cpPathTrailingSep(tmpDir, "dir1") - - c.Assert(runDockerCp(c, srcPath, dstDir), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil) -} - -// E. SRC specifies a directory and DST does not exist. This should create a -// directory at DST and copy the contents of the SRC directory into the DST -// directory. Ensure this works whether DST has a trailing path separator or -// not. -func (s *DockerSuite) TestCpFromCaseE(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{addContent: true}) - - tmpDir := getTestDir(c, "test-cp-from-case-e") - defer os.RemoveAll(tmpDir) - - srcDir := containerCpPath(containerID, "dir1") - dstDir := cpPath(tmpDir, "testDir") - dstPath := filepath.Join(dstDir, "file1-1") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil) - - // Now try again but using a trailing path separator for dstDir. - - // unable to remove dstDir - c.Assert(os.RemoveAll(dstDir), checker.IsNil) - - dstDir = cpPathTrailingSep(tmpDir, "testDir") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil) -} - -// F. SRC specifies a directory and DST exists as a file. This should cause an -// error as it is not possible to overwrite a file with a directory. -func (s *DockerSuite) TestCpFromCaseF(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - }) - - tmpDir := getTestDir(c, "test-cp-from-case-f") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcDir := containerCpPath(containerID, "/root/dir1") - dstFile := cpPath(tmpDir, "file1") - - err := runDockerCp(c, srcDir, dstFile) - c.Assert(err, checker.NotNil) - - c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err)) -} - -// G. SRC specifies a directory and DST exists as a directory. This should copy -// the SRC directory and all its contents to the DST directory. Ensure this -// works whether DST has a trailing path separator or not. -func (s *DockerSuite) TestCpFromCaseG(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - }) - - tmpDir := getTestDir(c, "test-cp-from-case-g") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcDir := containerCpPath(containerID, "/root/dir1") - dstDir := cpPath(tmpDir, "dir2") - resultDir := filepath.Join(dstDir, "dir1") - dstPath := filepath.Join(resultDir, "file1-1") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil) - - // Now try again but using a trailing path separator for dstDir. - - // unable to remove dstDir - c.Assert(os.RemoveAll(dstDir), checker.IsNil) - - // unable to make dstDir - c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil) - - dstDir = cpPathTrailingSep(tmpDir, "dir2") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil) -} - -// H. SRC specifies a directory's contents only and DST does not exist. This -// should create a directory at DST and copy the contents of the SRC -// directory (but not the directory itself) into the DST directory. Ensure -// this works whether DST has a trailing path separator or not. -func (s *DockerSuite) TestCpFromCaseH(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{addContent: true}) - - tmpDir := getTestDir(c, "test-cp-from-case-h") - defer os.RemoveAll(tmpDir) - - srcDir := containerCpPathTrailingSep(containerID, "dir1") + "." - dstDir := cpPath(tmpDir, "testDir") - dstPath := filepath.Join(dstDir, "file1-1") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil) - - // Now try again but using a trailing path separator for dstDir. - - // unable to remove resultDir - c.Assert(os.RemoveAll(dstDir), checker.IsNil) - - dstDir = cpPathTrailingSep(tmpDir, "testDir") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil) -} - -// I. SRC specifies a directory's contents only and DST exists as a file. This -// should cause an error as it is not possible to overwrite a file with a -// directory. -func (s *DockerSuite) TestCpFromCaseI(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - }) - - tmpDir := getTestDir(c, "test-cp-from-case-i") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcDir := containerCpPathTrailingSep(containerID, "/root/dir1") + "." - dstFile := cpPath(tmpDir, "file1") - - err := runDockerCp(c, srcDir, dstFile) - c.Assert(err, checker.NotNil) - - c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err)) -} - -// J. SRC specifies a directory's contents only and DST exists as a directory. -// This should copy the contents of the SRC directory (but not the directory -// itself) into the DST directory. Ensure this works whether DST has a -// trailing path separator or not. -func (s *DockerSuite) TestCpFromCaseJ(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - }) - - tmpDir := getTestDir(c, "test-cp-from-case-j") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcDir := containerCpPathTrailingSep(containerID, "/root/dir1") + "." - dstDir := cpPath(tmpDir, "dir2") - dstPath := filepath.Join(dstDir, "file1-1") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil) - - // Now try again but using a trailing path separator for dstDir. - - // unable to remove dstDir - c.Assert(os.RemoveAll(dstDir), checker.IsNil) - - // unable to make dstDir - c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil) - - dstDir = cpPathTrailingSep(tmpDir, "dir2") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_test.go deleted file mode 100644 index 4e5c39e..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_test.go +++ /dev/null @@ -1,660 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path" - "path/filepath" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/go-check/check" -) - -const ( - cpTestPathParent = "/some" - cpTestPath = "/some/path" - cpTestName = "test" - cpFullPath = "/some/path/test" - - cpContainerContents = "holla, i am the container" - cpHostContents = "hello, i am the host" -) - -// Ensure that an all-local path case returns an error. -func (s *DockerSuite) TestCpLocalOnly(c *check.C) { - err := runDockerCp(c, "foo", "bar") - c.Assert(err, checker.NotNil) - - c.Assert(err.Error(), checker.Contains, "must specify at least one container source") -} - -// Test for #5656 -// Check that garbage paths don't escape the container's rootfs -func (s *DockerSuite) TestCpGarbagePath(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath) - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - c.Assert(os.MkdirAll(cpTestPath, os.ModeDir), checker.IsNil) - - hostFile, err := os.Create(cpFullPath) - c.Assert(err, checker.IsNil) - defer hostFile.Close() - defer os.RemoveAll(cpTestPathParent) - - fmt.Fprintf(hostFile, "%s", cpHostContents) - - tmpdir, err := ioutil.TempDir("", "docker-integration") - c.Assert(err, checker.IsNil) - - tmpname := filepath.Join(tmpdir, cpTestName) - defer os.RemoveAll(tmpdir) - - path := path.Join("../../../../../../../../../../../../", cpFullPath) - - dockerCmd(c, "cp", containerID+":"+path, tmpdir) - - file, _ := os.Open(tmpname) - defer file.Close() - - test, err := ioutil.ReadAll(file) - c.Assert(err, checker.IsNil) - - // output matched host file -- garbage path can escape container rootfs - c.Assert(string(test), checker.Not(checker.Equals), cpHostContents) - - // output doesn't match the input for garbage path - c.Assert(string(test), checker.Equals, cpContainerContents) -} - -// Check that relative paths are relative to the container's rootfs -func (s *DockerSuite) TestCpRelativePath(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath) - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - c.Assert(os.MkdirAll(cpTestPath, os.ModeDir), checker.IsNil) - - hostFile, err := os.Create(cpFullPath) - c.Assert(err, checker.IsNil) - defer hostFile.Close() - defer os.RemoveAll(cpTestPathParent) - - fmt.Fprintf(hostFile, "%s", cpHostContents) - - tmpdir, err := ioutil.TempDir("", "docker-integration") - c.Assert(err, checker.IsNil) - - tmpname := filepath.Join(tmpdir, cpTestName) - defer os.RemoveAll(tmpdir) - - var relPath string - if path.IsAbs(cpFullPath) { - // normally this is `filepath.Rel("/", cpFullPath)` but we cannot - // get this unix-path manipulation on windows with filepath. - relPath = cpFullPath[1:] - } - c.Assert(path.IsAbs(cpFullPath), checker.True, check.Commentf("path %s was assumed to be an absolute path", cpFullPath)) - - dockerCmd(c, "cp", containerID+":"+relPath, tmpdir) - - file, _ := os.Open(tmpname) - defer file.Close() - - test, err := ioutil.ReadAll(file) - c.Assert(err, checker.IsNil) - - // output matched host file -- relative path can escape container rootfs - c.Assert(string(test), checker.Not(checker.Equals), cpHostContents) - - // output doesn't match the input for relative path - c.Assert(string(test), checker.Equals, cpContainerContents) -} - -// Check that absolute paths are relative to the container's rootfs -func (s *DockerSuite) TestCpAbsolutePath(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath) - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - c.Assert(os.MkdirAll(cpTestPath, os.ModeDir), checker.IsNil) - - hostFile, err := os.Create(cpFullPath) - c.Assert(err, checker.IsNil) - defer hostFile.Close() - defer os.RemoveAll(cpTestPathParent) - - fmt.Fprintf(hostFile, "%s", cpHostContents) - - tmpdir, err := ioutil.TempDir("", "docker-integration") - c.Assert(err, checker.IsNil) - - tmpname := filepath.Join(tmpdir, cpTestName) - defer os.RemoveAll(tmpdir) - - path := cpFullPath - - dockerCmd(c, "cp", containerID+":"+path, tmpdir) - - file, _ := os.Open(tmpname) - defer file.Close() - - test, err := ioutil.ReadAll(file) - c.Assert(err, checker.IsNil) - - // output matched host file -- absolute path can escape container rootfs - c.Assert(string(test), checker.Not(checker.Equals), cpHostContents) - - // output doesn't match the input for absolute path - c.Assert(string(test), checker.Equals, cpContainerContents) -} - -// Test for #5619 -// Check that absolute symlinks are still relative to the container's rootfs -func (s *DockerSuite) TestCpAbsoluteSymlink(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path") - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - c.Assert(os.MkdirAll(cpTestPath, os.ModeDir), checker.IsNil) - - hostFile, err := os.Create(cpFullPath) - c.Assert(err, checker.IsNil) - defer hostFile.Close() - defer os.RemoveAll(cpTestPathParent) - - fmt.Fprintf(hostFile, "%s", cpHostContents) - - tmpdir, err := ioutil.TempDir("", "docker-integration") - c.Assert(err, checker.IsNil) - - tmpname := filepath.Join(tmpdir, "container_path") - defer os.RemoveAll(tmpdir) - - path := path.Join("/", "container_path") - - dockerCmd(c, "cp", containerID+":"+path, tmpdir) - - // We should have copied a symlink *NOT* the file itself! - linkTarget, err := os.Readlink(tmpname) - c.Assert(err, checker.IsNil) - - c.Assert(linkTarget, checker.Equals, filepath.FromSlash(cpFullPath)) -} - -// Check that symlinks to a directory behave as expected when copying one from -// a container. -func (s *DockerSuite) TestCpFromSymlinkToDirectory(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPathParent+" /dir_link") - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - testDir, err := ioutil.TempDir("", "test-cp-from-symlink-to-dir-") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(testDir) - - // This copy command should copy the symlink, not the target, into the - // temporary directory. - dockerCmd(c, "cp", containerID+":"+"/dir_link", testDir) - - expectedPath := filepath.Join(testDir, "dir_link") - linkTarget, err := os.Readlink(expectedPath) - c.Assert(err, checker.IsNil) - - c.Assert(linkTarget, checker.Equals, filepath.FromSlash(cpTestPathParent)) - - os.Remove(expectedPath) - - // This copy command should resolve the symlink (note the trailing - // separator), copying the target into the temporary directory. - dockerCmd(c, "cp", containerID+":"+"/dir_link/", testDir) - - // It *should not* have copied the directory using the target's name, but - // used the given name instead. - unexpectedPath := filepath.Join(testDir, cpTestPathParent) - stat, err := os.Lstat(unexpectedPath) - if err == nil { - out = fmt.Sprintf("target name was copied: %q - %q", stat.Mode(), stat.Name()) - } - c.Assert(err, checker.NotNil, check.Commentf(out)) - - // It *should* have copied the directory using the asked name "dir_link". - stat, err = os.Lstat(expectedPath) - c.Assert(err, checker.IsNil, check.Commentf("unable to stat resource at %q", expectedPath)) - - c.Assert(stat.IsDir(), checker.True, check.Commentf("should have copied a directory but got %q instead", stat.Mode())) -} - -// Check that symlinks to a directory behave as expected when copying one to a -// container. -func (s *DockerSuite) TestCpToSymlinkToDirectory(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, SameHostDaemon) // Requires local volume mount bind. - - testVol, err := ioutil.TempDir("", "test-cp-to-symlink-to-dir-") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(testVol) - - // Create a test container with a local volume. We will test by copying - // to the volume path in the container which we can then verify locally. - out, _ := dockerCmd(c, "create", "-v", testVol+":/testVol", "busybox") - - containerID := strings.TrimSpace(out) - - // Create a temp directory to hold a test file nested in a directory. - testDir, err := ioutil.TempDir("", "test-cp-to-symlink-to-dir-") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(testDir) - - // This file will be at "/testDir/some/path/test" and will be copied into - // the test volume later. - hostTestFilename := filepath.Join(testDir, cpFullPath) - c.Assert(os.MkdirAll(filepath.Dir(hostTestFilename), os.FileMode(0700)), checker.IsNil) - c.Assert(ioutil.WriteFile(hostTestFilename, []byte(cpHostContents), os.FileMode(0600)), checker.IsNil) - - // Now create another temp directory to hold a symlink to the - // "/testDir/some" directory. - linkDir, err := ioutil.TempDir("", "test-cp-to-symlink-to-dir-") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(linkDir) - - // Then symlink "/linkDir/dir_link" to "/testdir/some". - linkTarget := filepath.Join(testDir, cpTestPathParent) - localLink := filepath.Join(linkDir, "dir_link") - c.Assert(os.Symlink(linkTarget, localLink), checker.IsNil) - - // Now copy that symlink into the test volume in the container. - dockerCmd(c, "cp", localLink, containerID+":/testVol") - - // This copy command should have copied the symlink *not* the target. - expectedPath := filepath.Join(testVol, "dir_link") - actualLinkTarget, err := os.Readlink(expectedPath) - c.Assert(err, checker.IsNil, check.Commentf("unable to read symlink at %q", expectedPath)) - - c.Assert(actualLinkTarget, checker.Equals, linkTarget) - - // Good, now remove that copied link for the next test. - os.Remove(expectedPath) - - // This copy command should resolve the symlink (note the trailing - // separator), copying the target into the test volume directory in the - // container. - dockerCmd(c, "cp", localLink+"/", containerID+":/testVol") - - // It *should not* have copied the directory using the target's name, but - // used the given name instead. - unexpectedPath := filepath.Join(testVol, cpTestPathParent) - stat, err := os.Lstat(unexpectedPath) - if err == nil { - out = fmt.Sprintf("target name was copied: %q - %q", stat.Mode(), stat.Name()) - } - c.Assert(err, checker.NotNil, check.Commentf(out)) - - // It *should* have copied the directory using the asked name "dir_link". - stat, err = os.Lstat(expectedPath) - c.Assert(err, checker.IsNil, check.Commentf("unable to stat resource at %q", expectedPath)) - - c.Assert(stat.IsDir(), checker.True, check.Commentf("should have copied a directory but got %q instead", stat.Mode())) - - // And this directory should contain the file copied from the host at the - // expected location: "/testVol/dir_link/path/test" - expectedFilepath := filepath.Join(testVol, "dir_link/path/test") - fileContents, err := ioutil.ReadFile(expectedFilepath) - c.Assert(err, checker.IsNil) - - c.Assert(string(fileContents), checker.Equals, cpHostContents) -} - -// Test for #5619 -// Check that symlinks which are part of the resource path are still relative to the container's rootfs -func (s *DockerSuite) TestCpSymlinkComponent(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path") - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - c.Assert(os.MkdirAll(cpTestPath, os.ModeDir), checker.IsNil) - - hostFile, err := os.Create(cpFullPath) - c.Assert(err, checker.IsNil) - defer hostFile.Close() - defer os.RemoveAll(cpTestPathParent) - - fmt.Fprintf(hostFile, "%s", cpHostContents) - - tmpdir, err := ioutil.TempDir("", "docker-integration") - - c.Assert(err, checker.IsNil) - - tmpname := filepath.Join(tmpdir, cpTestName) - defer os.RemoveAll(tmpdir) - - path := path.Join("/", "container_path", cpTestName) - - dockerCmd(c, "cp", containerID+":"+path, tmpdir) - - file, _ := os.Open(tmpname) - defer file.Close() - - test, err := ioutil.ReadAll(file) - c.Assert(err, checker.IsNil) - - // output matched host file -- symlink path component can escape container rootfs - c.Assert(string(test), checker.Not(checker.Equals), cpHostContents) - - // output doesn't match the input for symlink path component - c.Assert(string(test), checker.Equals, cpContainerContents) -} - -// Check that cp with unprivileged user doesn't return any error -func (s *DockerSuite) TestCpUnprivilegedUser(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, UnixCli) // uses chmod/su: not available on windows - - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName) - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - tmpdir, err := ioutil.TempDir("", "docker-integration") - c.Assert(err, checker.IsNil) - - defer os.RemoveAll(tmpdir) - - c.Assert(os.Chmod(tmpdir, 0777), checker.IsNil) - - result := icmd.RunCommand("su", "unprivilegeduser", "-c", - fmt.Sprintf("%s cp %s:%s %s", dockerBinary, containerID, cpTestName, tmpdir)) - result.Assert(c, icmd.Expected{}) -} - -func (s *DockerSuite) TestCpSpecialFiles(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, SameHostDaemon) - - outDir, err := ioutil.TempDir("", "cp-test-special-files") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(outDir) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch /foo") - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - // Copy actual /etc/resolv.conf - dockerCmd(c, "cp", containerID+":/etc/resolv.conf", outDir) - - expected, err := readContainerFile(containerID, "resolv.conf") - actual, err := ioutil.ReadFile(outDir + "/resolv.conf") - - // Expected copied file to be duplicate of the container resolvconf - c.Assert(bytes.Equal(actual, expected), checker.True) - - // Copy actual /etc/hosts - dockerCmd(c, "cp", containerID+":/etc/hosts", outDir) - - expected, err = readContainerFile(containerID, "hosts") - actual, err = ioutil.ReadFile(outDir + "/hosts") - - // Expected copied file to be duplicate of the container hosts - c.Assert(bytes.Equal(actual, expected), checker.True) - - // Copy actual /etc/resolv.conf - dockerCmd(c, "cp", containerID+":/etc/hostname", outDir) - - expected, err = readContainerFile(containerID, "hostname") - actual, err = ioutil.ReadFile(outDir + "/hostname") - - // Expected copied file to be duplicate of the container resolvconf - c.Assert(bytes.Equal(actual, expected), checker.True) -} - -func (s *DockerSuite) TestCpVolumePath(c *check.C) { - // stat /tmp/cp-test-volumepath851508420/test gets permission denied for the user - testRequires(c, NotUserNamespace) - testRequires(c, DaemonIsLinux) - testRequires(c, SameHostDaemon) - - tmpDir, err := ioutil.TempDir("", "cp-test-volumepath") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir) - outDir, err := ioutil.TempDir("", "cp-test-volumepath-out") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(outDir) - _, err = os.Create(tmpDir + "/test") - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "run", "-d", "-v", "/foo", "-v", tmpDir+"/test:/test", "-v", tmpDir+":/baz", "busybox", "/bin/sh", "-c", "touch /foo/bar") - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - // Copy actual volume path - dockerCmd(c, "cp", containerID+":/foo", outDir) - - stat, err := os.Stat(outDir + "/foo") - c.Assert(err, checker.IsNil) - // expected copied content to be dir - c.Assert(stat.IsDir(), checker.True) - stat, err = os.Stat(outDir + "/foo/bar") - c.Assert(err, checker.IsNil) - // Expected file `bar` to be a file - c.Assert(stat.IsDir(), checker.False) - - // Copy file nested in volume - dockerCmd(c, "cp", containerID+":/foo/bar", outDir) - - stat, err = os.Stat(outDir + "/bar") - c.Assert(err, checker.IsNil) - // Expected file `bar` to be a file - c.Assert(stat.IsDir(), checker.False) - - // Copy Bind-mounted dir - dockerCmd(c, "cp", containerID+":/baz", outDir) - stat, err = os.Stat(outDir + "/baz") - c.Assert(err, checker.IsNil) - // Expected `baz` to be a dir - c.Assert(stat.IsDir(), checker.True) - - // Copy file nested in bind-mounted dir - dockerCmd(c, "cp", containerID+":/baz/test", outDir) - fb, err := ioutil.ReadFile(outDir + "/baz/test") - c.Assert(err, checker.IsNil) - fb2, err := ioutil.ReadFile(tmpDir + "/test") - c.Assert(err, checker.IsNil) - // Expected copied file to be duplicate of bind-mounted file - c.Assert(bytes.Equal(fb, fb2), checker.True) - - // Copy bind-mounted file - dockerCmd(c, "cp", containerID+":/test", outDir) - fb, err = ioutil.ReadFile(outDir + "/test") - c.Assert(err, checker.IsNil) - fb2, err = ioutil.ReadFile(tmpDir + "/test") - c.Assert(err, checker.IsNil) - // Expected copied file to be duplicate of bind-mounted file - c.Assert(bytes.Equal(fb, fb2), checker.True) -} - -func (s *DockerSuite) TestCpToDot(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test") - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - tmpdir, err := ioutil.TempDir("", "docker-integration") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpdir) - cwd, err := os.Getwd() - c.Assert(err, checker.IsNil) - defer os.Chdir(cwd) - c.Assert(os.Chdir(tmpdir), checker.IsNil) - dockerCmd(c, "cp", containerID+":/test", ".") - content, err := ioutil.ReadFile("./test") - c.Assert(string(content), checker.Equals, "lololol\n") -} - -func (s *DockerSuite) TestCpToStdout(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test") - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - out, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "cp", containerID+":/test", "-"), - exec.Command("tar", "-vtf", "-")) - - c.Assert(err, checker.IsNil) - - c.Assert(out, checker.Contains, "test") - c.Assert(out, checker.Contains, "-rw") -} - -func (s *DockerSuite) TestCpNameHasColon(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t") - - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - tmpdir, err := ioutil.TempDir("", "docker-integration") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpdir) - dockerCmd(c, "cp", containerID+":/te:s:t", tmpdir) - content, err := ioutil.ReadFile(tmpdir + "/te:s:t") - c.Assert(string(content), checker.Equals, "lololol\n") -} - -func (s *DockerSuite) TestCopyAndRestart(c *check.C) { - testRequires(c, DaemonIsLinux) - expectedMsg := "hello" - out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", expectedMsg) - containerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - // failed to set up container - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - tmpDir, err := ioutil.TempDir("", "test-docker-restart-after-copy-") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir) - - dockerCmd(c, "cp", fmt.Sprintf("%s:/etc/group", containerID), tmpDir) - - out, _ = dockerCmd(c, "start", "-a", containerID) - - c.Assert(strings.TrimSpace(out), checker.Equals, expectedMsg) -} - -func (s *DockerSuite) TestCopyCreatedContainer(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "create", "--name", "test_cp", "-v", "/test", "busybox") - - tmpDir, err := ioutil.TempDir("", "test") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir) - dockerCmd(c, "cp", "test_cp:/bin/sh", tmpDir) -} - -// test copy with option `-L`: following symbol link -// Check that symlinks to a file behave as expected when copying one from -// a container to host following symbol link -func (s *DockerSuite) TestCpSymlinkFromConToHostFollowSymlink(c *check.C) { - testRequires(c, DaemonIsLinux) - out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" /dir_link") - if exitCode != 0 { - c.Fatal("failed to create a container", out) - } - - cleanedContainerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", cleanedContainerID) - if strings.TrimSpace(out) != "0" { - c.Fatal("failed to set up container", out) - } - - testDir, err := ioutil.TempDir("", "test-cp-symlink-container-to-host-follow-symlink") - if err != nil { - c.Fatal(err) - } - defer os.RemoveAll(testDir) - - // This copy command should copy the symlink, not the target, into the - // temporary directory. - dockerCmd(c, "cp", "-L", cleanedContainerID+":"+"/dir_link", testDir) - - expectedPath := filepath.Join(testDir, "dir_link") - - expected := []byte(cpContainerContents) - actual, err := ioutil.ReadFile(expectedPath) - - if !bytes.Equal(actual, expected) { - c.Fatalf("Expected copied file to be duplicate of the container symbol link target") - } - os.Remove(expectedPath) - - // now test copy symbol link to a non-existing file in host - expectedPath = filepath.Join(testDir, "somefile_host") - // expectedPath shouldn't exist, if exists, remove it - if _, err := os.Lstat(expectedPath); err == nil { - os.Remove(expectedPath) - } - - dockerCmd(c, "cp", "-L", cleanedContainerID+":"+"/dir_link", expectedPath) - - actual, err = ioutil.ReadFile(expectedPath) - - if !bytes.Equal(actual, expected) { - c.Fatalf("Expected copied file to be duplicate of the container symbol link target") - } - defer os.Remove(expectedPath) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_to_container_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_to_container_test.go deleted file mode 100644 index f981cb8..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_to_container_test.go +++ /dev/null @@ -1,599 +0,0 @@ -package main - -import ( - "os" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// docker cp LOCALPATH CONTAINER:PATH - -// Try all of the test cases from the archive package which implements the -// internals of `docker cp` and ensure that the behavior matches when actually -// copying to and from containers. - -// Basic assumptions about SRC and DST: -// 1. SRC must exist. -// 2. If SRC ends with a trailing separator, it must be a directory. -// 3. DST parent directory must exist. -// 4. If DST exists as a file, it must not end with a trailing separator. - -// First get these easy error cases out of the way. - -// Test for error when SRC does not exist. -func (s *DockerSuite) TestCpToErrSrcNotExists(c *check.C) { - containerID := makeTestContainer(c, testContainerOptions{}) - - tmpDir := getTestDir(c, "test-cp-to-err-src-not-exists") - defer os.RemoveAll(tmpDir) - - srcPath := cpPath(tmpDir, "file1") - dstPath := containerCpPath(containerID, "file1") - - err := runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err)) -} - -// Test for error when SRC ends in a trailing -// path separator but it exists as a file. -func (s *DockerSuite) TestCpToErrSrcNotDir(c *check.C) { - containerID := makeTestContainer(c, testContainerOptions{}) - - tmpDir := getTestDir(c, "test-cp-to-err-src-not-dir") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcPath := cpPathTrailingSep(tmpDir, "file1") - dstPath := containerCpPath(containerID, "testDir") - - err := runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCpNotDir(err), checker.True, check.Commentf("expected IsNotDir error, but got %T: %s", err, err)) -} - -// Test for error when SRC is a valid file or directory, -// bu the DST parent directory does not exist. -func (s *DockerSuite) TestCpToErrDstParentNotExists(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{addContent: true}) - - tmpDir := getTestDir(c, "test-cp-to-err-dst-parent-not-exists") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - // Try with a file source. - srcPath := cpPath(tmpDir, "file1") - dstPath := containerCpPath(containerID, "/notExists", "file1") - - err := runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err)) - - // Try with a directory source. - srcPath = cpPath(tmpDir, "dir1") - - c.Assert(err, checker.NotNil) - - c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err)) -} - -// Test for error when DST ends in a trailing path separator but exists as a -// file. Also test that we cannot overwrite an existing directory with a -// non-directory and cannot overwrite an existing -func (s *DockerSuite) TestCpToErrDstNotDir(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{addContent: true}) - - tmpDir := getTestDir(c, "test-cp-to-err-dst-not-dir") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - // Try with a file source. - srcPath := cpPath(tmpDir, "dir1/file1-1") - dstPath := containerCpPathTrailingSep(containerID, "file1") - - // The client should encounter an error trying to stat the destination - // and then be unable to copy since the destination is asserted to be a - // directory but does not exist. - err := runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExist error, but got %T: %s", err, err)) - - // Try with a directory source. - srcPath = cpPath(tmpDir, "dir1") - - // The client should encounter an error trying to stat the destination and - // then decide to extract to the parent directory instead with a rebased - // name in the source archive, but this directory would overwrite the - // existing file with the same name. - err = runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCannotOverwriteNonDirWithDir(err), checker.True, check.Commentf("expected CannotOverwriteNonDirWithDir error, but got %T: %s", err, err)) -} - -// Check that copying from a local path to a symlink in a container copies to -// the symlink target and does not overwrite the container symlink itself. -func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) { - // stat /tmp/test-cp-to-symlink-destination-262430901/vol3 gets permission denied for the user - testRequires(c, NotUserNamespace) - testRequires(c, DaemonIsLinux) - testRequires(c, SameHostDaemon) // Requires local volume mount bind. - - testVol := getTestDir(c, "test-cp-to-symlink-destination-") - defer os.RemoveAll(testVol) - - makeTestContentInDir(c, testVol) - - containerID := makeTestContainer(c, testContainerOptions{ - volumes: defaultVolumes(testVol), // Our bind mount is at /vol2 - }) - - // First, copy a local file to a symlink to a file in the container. This - // should overwrite the symlink target contents with the source contents. - srcPath := cpPath(testVol, "file2") - dstPath := containerCpPath(containerID, "/vol2/symlinkToFile1") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // The symlink should not have been modified. - c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToFile1"), "file1"), checker.IsNil) - - // The file should have the contents of "file2" now. - c.Assert(fileContentEquals(c, cpPath(testVol, "file1"), "file2\n"), checker.IsNil) - - // Next, copy a local file to a symlink to a directory in the container. - // This should copy the file into the symlink target directory. - dstPath = containerCpPath(containerID, "/vol2/symlinkToDir1") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // The symlink should not have been modified. - c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil) - - // The file should have the contents of "file2" now. - c.Assert(fileContentEquals(c, cpPath(testVol, "file2"), "file2\n"), checker.IsNil) - - // Next, copy a file to a symlink to a file that does not exist (a broken - // symlink) in the container. This should create the target file with the - // contents of the source file. - dstPath = containerCpPath(containerID, "/vol2/brokenSymlinkToFileX") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // The symlink should not have been modified. - c.Assert(symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToFileX"), "fileX"), checker.IsNil) - - // The file should have the contents of "file2" now. - c.Assert(fileContentEquals(c, cpPath(testVol, "fileX"), "file2\n"), checker.IsNil) - - // Next, copy a local directory to a symlink to a directory in the - // container. This should copy the directory into the symlink target - // directory and not modify the symlink. - srcPath = cpPath(testVol, "/dir2") - dstPath = containerCpPath(containerID, "/vol2/symlinkToDir1") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // The symlink should not have been modified. - c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil) - - // The directory should now contain a copy of "dir2". - c.Assert(fileContentEquals(c, cpPath(testVol, "dir1/dir2/file2-1"), "file2-1\n"), checker.IsNil) - - // Next, copy a local directory to a symlink to a local directory that does - // not exist (a broken symlink) in the container. This should create the - // target as a directory with the contents of the source directory. It - // should not modify the symlink. - dstPath = containerCpPath(containerID, "/vol2/brokenSymlinkToDirX") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // The symlink should not have been modified. - c.Assert(symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToDirX"), "dirX"), checker.IsNil) - - // The "dirX" directory should now be a copy of "dir2". - c.Assert(fileContentEquals(c, cpPath(testVol, "dirX/file2-1"), "file2-1\n"), checker.IsNil) -} - -// Possibilities are reduced to the remaining 10 cases: -// -// case | srcIsDir | onlyDirContents | dstExists | dstIsDir | dstTrSep | action -// =================================================================================================== -// A | no | - | no | - | no | create file -// B | no | - | no | - | yes | error -// C | no | - | yes | no | - | overwrite file -// D | no | - | yes | yes | - | create file in dst dir -// E | yes | no | no | - | - | create dir, copy contents -// F | yes | no | yes | no | - | error -// G | yes | no | yes | yes | - | copy dir and contents -// H | yes | yes | no | - | - | create dir, copy contents -// I | yes | yes | yes | no | - | error -// J | yes | yes | yes | yes | - | copy dir contents -// - -// A. SRC specifies a file and DST (no trailing path separator) doesn't -// exist. This should create a file with the name DST and copy the -// contents of the source file into it. -func (s *DockerSuite) TestCpToCaseA(c *check.C) { - containerID := makeTestContainer(c, testContainerOptions{ - workDir: "/root", command: makeCatFileCommand("itWorks.txt"), - }) - - tmpDir := getTestDir(c, "test-cp-to-case-a") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcPath := cpPath(tmpDir, "file1") - dstPath := containerCpPath(containerID, "/root/itWorks.txt") - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil) -} - -// B. SRC specifies a file and DST (with trailing path separator) doesn't -// exist. This should cause an error because the copy operation cannot -// create a directory when copying a single file. -func (s *DockerSuite) TestCpToCaseB(c *check.C) { - containerID := makeTestContainer(c, testContainerOptions{ - command: makeCatFileCommand("testDir/file1"), - }) - - tmpDir := getTestDir(c, "test-cp-to-case-b") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcPath := cpPath(tmpDir, "file1") - dstDir := containerCpPathTrailingSep(containerID, "testDir") - - err := runDockerCp(c, srcPath, dstDir) - c.Assert(err, checker.NotNil) - - c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err)) -} - -// C. SRC specifies a file and DST exists as a file. This should overwrite -// the file at DST with the contents of the source file. -func (s *DockerSuite) TestCpToCaseC(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - command: makeCatFileCommand("file2"), - }) - - tmpDir := getTestDir(c, "test-cp-to-case-c") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcPath := cpPath(tmpDir, "file1") - dstPath := containerCpPath(containerID, "/root/file2") - - // Ensure the container's file starts with the original content. - c.Assert(containerStartOutputEquals(c, containerID, "file2\n"), checker.IsNil) - - c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil) - - // Should now contain file1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil) -} - -// D. SRC specifies a file and DST exists as a directory. This should place -// a copy of the source file inside it using the basename from SRC. Ensure -// this works whether DST has a trailing path separator or not. -func (s *DockerSuite) TestCpToCaseD(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, - command: makeCatFileCommand("/dir1/file1"), - }) - - tmpDir := getTestDir(c, "test-cp-to-case-d") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcPath := cpPath(tmpDir, "file1") - dstDir := containerCpPath(containerID, "dir1") - - // Ensure that dstPath doesn't exist. - c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil) - - c.Assert(runDockerCp(c, srcPath, dstDir), checker.IsNil) - - // Should now contain file1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil) - - // Now try again but using a trailing path separator for dstDir. - - // Make new destination container. - containerID = makeTestContainer(c, testContainerOptions{ - addContent: true, - command: makeCatFileCommand("/dir1/file1"), - }) - - dstDir = containerCpPathTrailingSep(containerID, "dir1") - - // Ensure that dstPath doesn't exist. - c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil) - - c.Assert(runDockerCp(c, srcPath, dstDir), checker.IsNil) - - // Should now contain file1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil) -} - -// E. SRC specifies a directory and DST does not exist. This should create a -// directory at DST and copy the contents of the SRC directory into the DST -// directory. Ensure this works whether DST has a trailing path separator or -// not. -func (s *DockerSuite) TestCpToCaseE(c *check.C) { - containerID := makeTestContainer(c, testContainerOptions{ - command: makeCatFileCommand("/testDir/file1-1"), - }) - - tmpDir := getTestDir(c, "test-cp-to-case-e") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcDir := cpPath(tmpDir, "dir1") - dstDir := containerCpPath(containerID, "testDir") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - // Should now contain file1-1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil) - - // Now try again but using a trailing path separator for dstDir. - - // Make new destination container. - containerID = makeTestContainer(c, testContainerOptions{ - command: makeCatFileCommand("/testDir/file1-1"), - }) - - dstDir = containerCpPathTrailingSep(containerID, "testDir") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - // Should now contain file1-1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil) -} - -// F. SRC specifies a directory and DST exists as a file. This should cause an -// error as it is not possible to overwrite a file with a directory. -func (s *DockerSuite) TestCpToCaseF(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - }) - - tmpDir := getTestDir(c, "test-cp-to-case-f") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcDir := cpPath(tmpDir, "dir1") - dstFile := containerCpPath(containerID, "/root/file1") - - err := runDockerCp(c, srcDir, dstFile) - c.Assert(err, checker.NotNil) - - c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err)) -} - -// G. SRC specifies a directory and DST exists as a directory. This should copy -// the SRC directory and all its contents to the DST directory. Ensure this -// works whether DST has a trailing path separator or not. -func (s *DockerSuite) TestCpToCaseG(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - command: makeCatFileCommand("dir2/dir1/file1-1"), - }) - - tmpDir := getTestDir(c, "test-cp-to-case-g") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcDir := cpPath(tmpDir, "dir1") - dstDir := containerCpPath(containerID, "/root/dir2") - - // Ensure that dstPath doesn't exist. - c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil) - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - // Should now contain file1-1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil) - - // Now try again but using a trailing path separator for dstDir. - - // Make new destination container. - containerID = makeTestContainer(c, testContainerOptions{ - addContent: true, - command: makeCatFileCommand("/dir2/dir1/file1-1"), - }) - - dstDir = containerCpPathTrailingSep(containerID, "/dir2") - - // Ensure that dstPath doesn't exist. - c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil) - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - // Should now contain file1-1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil) -} - -// H. SRC specifies a directory's contents only and DST does not exist. This -// should create a directory at DST and copy the contents of the SRC -// directory (but not the directory itself) into the DST directory. Ensure -// this works whether DST has a trailing path separator or not. -func (s *DockerSuite) TestCpToCaseH(c *check.C) { - containerID := makeTestContainer(c, testContainerOptions{ - command: makeCatFileCommand("/testDir/file1-1"), - }) - - tmpDir := getTestDir(c, "test-cp-to-case-h") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcDir := cpPathTrailingSep(tmpDir, "dir1") + "." - dstDir := containerCpPath(containerID, "testDir") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - // Should now contain file1-1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil) - - // Now try again but using a trailing path separator for dstDir. - - // Make new destination container. - containerID = makeTestContainer(c, testContainerOptions{ - command: makeCatFileCommand("/testDir/file1-1"), - }) - - dstDir = containerCpPathTrailingSep(containerID, "testDir") - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - // Should now contain file1-1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil) -} - -// I. SRC specifies a directory's contents only and DST exists as a file. This -// should cause an error as it is not possible to overwrite a file with a -// directory. -func (s *DockerSuite) TestCpToCaseI(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - }) - - tmpDir := getTestDir(c, "test-cp-to-case-i") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcDir := cpPathTrailingSep(tmpDir, "dir1") + "." - dstFile := containerCpPath(containerID, "/root/file1") - - err := runDockerCp(c, srcDir, dstFile) - c.Assert(err, checker.NotNil) - - c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err)) -} - -// J. SRC specifies a directory's contents only and DST exists as a directory. -// This should copy the contents of the SRC directory (but not the directory -// itself) into the DST directory. Ensure this works whether DST has a -// trailing path separator or not. -func (s *DockerSuite) TestCpToCaseJ(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := makeTestContainer(c, testContainerOptions{ - addContent: true, workDir: "/root", - command: makeCatFileCommand("/dir2/file1-1"), - }) - - tmpDir := getTestDir(c, "test-cp-to-case-j") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcDir := cpPathTrailingSep(tmpDir, "dir1") + "." - dstDir := containerCpPath(containerID, "/dir2") - - // Ensure that dstPath doesn't exist. - c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil) - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - // Should now contain file1-1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil) - - // Now try again but using a trailing path separator for dstDir. - - // Make new destination container. - containerID = makeTestContainer(c, testContainerOptions{ - command: makeCatFileCommand("/dir2/file1-1"), - }) - - dstDir = containerCpPathTrailingSep(containerID, "/dir2") - - // Ensure that dstPath doesn't exist. - c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil) - - c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil) - - // Should now contain file1-1's contents. - c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil) -} - -// The `docker cp` command should also ensure that you cannot -// write to a container rootfs that is marked as read-only. -func (s *DockerSuite) TestCpToErrReadOnlyRootfs(c *check.C) { - // --read-only + userns has remount issues - testRequires(c, DaemonIsLinux, NotUserNamespace) - tmpDir := getTestDir(c, "test-cp-to-err-read-only-rootfs") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - containerID := makeTestContainer(c, testContainerOptions{ - readOnly: true, workDir: "/root", - command: makeCatFileCommand("shouldNotExist"), - }) - - srcPath := cpPath(tmpDir, "file1") - dstPath := containerCpPath(containerID, "/root/shouldNotExist") - - err := runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrContainerRootfsReadonly error, but got %T: %s", err, err)) - - // Ensure that dstPath doesn't exist. - c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil) -} - -// The `docker cp` command should also ensure that you -// cannot write to a volume that is mounted as read-only. -func (s *DockerSuite) TestCpToErrReadOnlyVolume(c *check.C) { - // --read-only + userns has remount issues - testRequires(c, DaemonIsLinux, NotUserNamespace) - tmpDir := getTestDir(c, "test-cp-to-err-read-only-volume") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - containerID := makeTestContainer(c, testContainerOptions{ - volumes: defaultVolumes(tmpDir), workDir: "/root", - command: makeCatFileCommand("/vol_ro/shouldNotExist"), - }) - - srcPath := cpPath(tmpDir, "file1") - dstPath := containerCpPath(containerID, "/vol_ro/shouldNotExist") - - err := runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.NotNil) - - c.Assert(isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrVolumeReadonly error, but got %T: %s", err, err)) - - // Ensure that dstPath doesn't exist. - c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_to_container_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_to_container_unix_test.go deleted file mode 100644 index 45d85ba..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_to_container_unix_test.go +++ /dev/null @@ -1,39 +0,0 @@ -// +build !windows - -package main - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/system" - "github.com/go-check/check" -) - -// Check ownership is root, both in non-userns and userns enabled modes -func (s *DockerSuite) TestCpCheckDestOwnership(c *check.C) { - testRequires(c, DaemonIsLinux, SameHostDaemon) - tmpVolDir := getTestDir(c, "test-cp-tmpvol") - containerID := makeTestContainer(c, - testContainerOptions{volumes: []string{fmt.Sprintf("%s:/tmpvol", tmpVolDir)}}) - - tmpDir := getTestDir(c, "test-cp-to-check-ownership") - defer os.RemoveAll(tmpDir) - - makeTestContentInDir(c, tmpDir) - - srcPath := cpPath(tmpDir, "file1") - dstPath := containerCpPath(containerID, "/tmpvol", "file1") - - err := runDockerCp(c, srcPath, dstPath) - c.Assert(err, checker.IsNil) - - stat, err := system.Stat(filepath.Join(tmpVolDir, "file1")) - c.Assert(err, checker.IsNil) - uid, gid, err := getRootUIDGID() - c.Assert(err, checker.IsNil) - c.Assert(stat.UID(), checker.Equals, uint32(uid), check.Commentf("Copied file not owned by container root UID")) - c.Assert(stat.GID(), checker.Equals, uint32(gid), check.Commentf("Copied file not owned by container root GID")) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_utils.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_utils.go deleted file mode 100644 index 0501c5d..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_cp_utils.go +++ /dev/null @@ -1,303 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -type fileType uint32 - -const ( - ftRegular fileType = iota - ftDir - ftSymlink -) - -type fileData struct { - filetype fileType - path string - contents string -} - -func (fd fileData) creationCommand() string { - var command string - - switch fd.filetype { - case ftRegular: - // Don't overwrite the file if it already exists! - command = fmt.Sprintf("if [ ! -f %s ]; then echo %q > %s; fi", fd.path, fd.contents, fd.path) - case ftDir: - command = fmt.Sprintf("mkdir -p %s", fd.path) - case ftSymlink: - command = fmt.Sprintf("ln -fs %s %s", fd.contents, fd.path) - } - - return command -} - -func mkFilesCommand(fds []fileData) string { - commands := make([]string, len(fds)) - - for i, fd := range fds { - commands[i] = fd.creationCommand() - } - - return strings.Join(commands, " && ") -} - -var defaultFileData = []fileData{ - {ftRegular, "file1", "file1"}, - {ftRegular, "file2", "file2"}, - {ftRegular, "file3", "file3"}, - {ftRegular, "file4", "file4"}, - {ftRegular, "file5", "file5"}, - {ftRegular, "file6", "file6"}, - {ftRegular, "file7", "file7"}, - {ftDir, "dir1", ""}, - {ftRegular, "dir1/file1-1", "file1-1"}, - {ftRegular, "dir1/file1-2", "file1-2"}, - {ftDir, "dir2", ""}, - {ftRegular, "dir2/file2-1", "file2-1"}, - {ftRegular, "dir2/file2-2", "file2-2"}, - {ftDir, "dir3", ""}, - {ftRegular, "dir3/file3-1", "file3-1"}, - {ftRegular, "dir3/file3-2", "file3-2"}, - {ftDir, "dir4", ""}, - {ftRegular, "dir4/file3-1", "file4-1"}, - {ftRegular, "dir4/file3-2", "file4-2"}, - {ftDir, "dir5", ""}, - {ftSymlink, "symlinkToFile1", "file1"}, - {ftSymlink, "symlinkToDir1", "dir1"}, - {ftSymlink, "brokenSymlinkToFileX", "fileX"}, - {ftSymlink, "brokenSymlinkToDirX", "dirX"}, - {ftSymlink, "symlinkToAbsDir", "/root"}, -} - -func defaultMkContentCommand() string { - return mkFilesCommand(defaultFileData) -} - -func makeTestContentInDir(c *check.C, dir string) { - for _, fd := range defaultFileData { - path := filepath.Join(dir, filepath.FromSlash(fd.path)) - switch fd.filetype { - case ftRegular: - c.Assert(ioutil.WriteFile(path, []byte(fd.contents+"\n"), os.FileMode(0666)), checker.IsNil) - case ftDir: - c.Assert(os.Mkdir(path, os.FileMode(0777)), checker.IsNil) - case ftSymlink: - c.Assert(os.Symlink(fd.contents, path), checker.IsNil) - } - } -} - -type testContainerOptions struct { - addContent bool - readOnly bool - volumes []string - workDir string - command string -} - -func makeTestContainer(c *check.C, options testContainerOptions) (containerID string) { - if options.addContent { - mkContentCmd := defaultMkContentCommand() - if options.command == "" { - options.command = mkContentCmd - } else { - options.command = fmt.Sprintf("%s && %s", defaultMkContentCommand(), options.command) - } - } - - if options.command == "" { - options.command = "#(nop)" - } - - args := []string{"run", "-d"} - - for _, volume := range options.volumes { - args = append(args, "-v", volume) - } - - if options.workDir != "" { - args = append(args, "-w", options.workDir) - } - - if options.readOnly { - args = append(args, "--read-only") - } - - args = append(args, "busybox", "/bin/sh", "-c", options.command) - - out, _ := dockerCmd(c, args...) - - containerID = strings.TrimSpace(out) - - out, _ = dockerCmd(c, "wait", containerID) - - exitCode := strings.TrimSpace(out) - if exitCode != "0" { - out, _ = dockerCmd(c, "logs", containerID) - } - c.Assert(exitCode, checker.Equals, "0", check.Commentf("failed to make test container: %s", out)) - - return -} - -func makeCatFileCommand(path string) string { - return fmt.Sprintf("if [ -f %s ]; then cat %s; fi", path, path) -} - -func cpPath(pathElements ...string) string { - localizedPathElements := make([]string, len(pathElements)) - for i, path := range pathElements { - localizedPathElements[i] = filepath.FromSlash(path) - } - return strings.Join(localizedPathElements, string(filepath.Separator)) -} - -func cpPathTrailingSep(pathElements ...string) string { - return fmt.Sprintf("%s%c", cpPath(pathElements...), filepath.Separator) -} - -func containerCpPath(containerID string, pathElements ...string) string { - joined := strings.Join(pathElements, "/") - return fmt.Sprintf("%s:%s", containerID, joined) -} - -func containerCpPathTrailingSep(containerID string, pathElements ...string) string { - return fmt.Sprintf("%s/", containerCpPath(containerID, pathElements...)) -} - -func runDockerCp(c *check.C, src, dst string) (err error) { - c.Logf("running `docker cp %s %s`", src, dst) - - args := []string{"cp", src, dst} - - out, _, err := runCommandWithOutput(exec.Command(dockerBinary, args...)) - if err != nil { - err = fmt.Errorf("error executing `docker cp` command: %s: %s", err, out) - } - - return -} - -func startContainerGetOutput(c *check.C, containerID string) (out string, err error) { - c.Logf("running `docker start -a %s`", containerID) - - args := []string{"start", "-a", containerID} - - out, _, err = runCommandWithOutput(exec.Command(dockerBinary, args...)) - if err != nil { - err = fmt.Errorf("error executing `docker start` command: %s: %s", err, out) - } - - return -} - -func getTestDir(c *check.C, label string) (tmpDir string) { - var err error - - tmpDir, err = ioutil.TempDir("", label) - // unable to make temporary directory - c.Assert(err, checker.IsNil) - - return -} - -func isCpNotExist(err error) bool { - return strings.Contains(err.Error(), "no such file or directory") || strings.Contains(err.Error(), "cannot find the file specified") -} - -func isCpDirNotExist(err error) bool { - return strings.Contains(err.Error(), archive.ErrDirNotExists.Error()) -} - -func isCpNotDir(err error) bool { - return strings.Contains(err.Error(), archive.ErrNotDirectory.Error()) || strings.Contains(err.Error(), "filename, directory name, or volume label syntax is incorrect") -} - -func isCpCannotCopyDir(err error) bool { - return strings.Contains(err.Error(), archive.ErrCannotCopyDir.Error()) -} - -func isCpCannotCopyReadOnly(err error) bool { - return strings.Contains(err.Error(), "marked read-only") -} - -func isCannotOverwriteNonDirWithDir(err error) bool { - return strings.Contains(err.Error(), "cannot overwrite non-directory") -} - -func fileContentEquals(c *check.C, filename, contents string) (err error) { - c.Logf("checking that file %q contains %q\n", filename, contents) - - fileBytes, err := ioutil.ReadFile(filename) - if err != nil { - return - } - - expectedBytes, err := ioutil.ReadAll(strings.NewReader(contents)) - if err != nil { - return - } - - if !bytes.Equal(fileBytes, expectedBytes) { - err = fmt.Errorf("file content not equal - expected %q, got %q", string(expectedBytes), string(fileBytes)) - } - - return -} - -func symlinkTargetEquals(c *check.C, symlink, expectedTarget string) (err error) { - c.Logf("checking that the symlink %q points to %q\n", symlink, expectedTarget) - - actualTarget, err := os.Readlink(symlink) - if err != nil { - return - } - - if actualTarget != expectedTarget { - err = fmt.Errorf("symlink target points to %q not %q", actualTarget, expectedTarget) - } - - return -} - -func containerStartOutputEquals(c *check.C, containerID, contents string) (err error) { - c.Logf("checking that container %q start output contains %q\n", containerID, contents) - - out, err := startContainerGetOutput(c, containerID) - if err != nil { - return - } - - if out != contents { - err = fmt.Errorf("output contents not equal - expected %q, got %q", contents, out) - } - - return -} - -func defaultVolumes(tmpDir string) []string { - if SameHostDaemon.Condition() { - return []string{ - "/vol1", - fmt.Sprintf("%s:/vol2", tmpDir), - fmt.Sprintf("%s:/vol3", filepath.Join(tmpDir, "vol3")), - fmt.Sprintf("%s:/vol_ro:ro", filepath.Join(tmpDir, "vol_ro")), - } - } - - // Can't bind-mount volumes with separate host daemon. - return []string{"/vol1", "/vol2", "/vol3", "/vol_ro:/vol_ro:ro"} -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_create_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_create_test.go deleted file mode 100644 index 515a340..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_create_test.go +++ /dev/null @@ -1,513 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "os" - "reflect" - "strings" - "time" - - "os/exec" - - "io/ioutil" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/go-connections/nat" - "github.com/go-check/check" -) - -// Make sure we can create a simple container with some args -func (s *DockerSuite) TestCreateArgs(c *check.C) { - // Intentionally clear entrypoint, as the Windows busybox image needs an entrypoint, which breaks this test - out, _ := dockerCmd(c, "create", "--entrypoint=", "busybox", "command", "arg1", "arg2", "arg with space", "-c", "flags") - - cleanedContainerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "inspect", cleanedContainerID) - - containers := []struct { - ID string - Created time.Time - Path string - Args []string - Image string - }{} - - err := json.Unmarshal([]byte(out), &containers) - c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err)) - c.Assert(containers, checker.HasLen, 1) - - cont := containers[0] - c.Assert(string(cont.Path), checker.Equals, "command", check.Commentf("Unexpected container path. Expected command, received: %s", cont.Path)) - - b := false - expected := []string{"arg1", "arg2", "arg with space", "-c", "flags"} - for i, arg := range expected { - if arg != cont.Args[i] { - b = true - break - } - } - if len(cont.Args) != len(expected) || b { - c.Fatalf("Unexpected args. Expected %v, received: %v", expected, cont.Args) - } - -} - -// Make sure we can grow the container's rootfs at creation time. -func (s *DockerSuite) TestCreateGrowRootfs(c *check.C) { - // Windows and Devicemapper support growing the rootfs - if daemonPlatform != "windows" { - testRequires(c, Devicemapper) - } - out, _ := dockerCmd(c, "create", "--storage-opt", "size=120G", "busybox") - - cleanedContainerID := strings.TrimSpace(out) - - inspectOut := inspectField(c, cleanedContainerID, "HostConfig.StorageOpt") - c.Assert(inspectOut, checker.Equals, "map[size:120G]") -} - -// Make sure we cannot shrink the container's rootfs at creation time. -func (s *DockerSuite) TestCreateShrinkRootfs(c *check.C) { - testRequires(c, Devicemapper) - - // Ensure this fails because of the defaultBaseFsSize is 10G - out, _, err := dockerCmdWithError("create", "--storage-opt", "size=5G", "busybox") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Container size cannot be smaller than") -} - -// Make sure we can set hostconfig options too -func (s *DockerSuite) TestCreateHostConfig(c *check.C) { - out, _ := dockerCmd(c, "create", "-P", "busybox", "echo") - - cleanedContainerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "inspect", cleanedContainerID) - - containers := []struct { - HostConfig *struct { - PublishAllPorts bool - } - }{} - - err := json.Unmarshal([]byte(out), &containers) - c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err)) - c.Assert(containers, checker.HasLen, 1) - - cont := containers[0] - c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none")) - c.Assert(cont.HostConfig.PublishAllPorts, check.NotNil, check.Commentf("Expected PublishAllPorts, got false")) -} - -func (s *DockerSuite) TestCreateWithPortRange(c *check.C) { - out, _ := dockerCmd(c, "create", "-p", "3300-3303:3300-3303/tcp", "busybox", "echo") - - cleanedContainerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "inspect", cleanedContainerID) - - containers := []struct { - HostConfig *struct { - PortBindings map[nat.Port][]nat.PortBinding - } - }{} - err := json.Unmarshal([]byte(out), &containers) - c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err)) - c.Assert(containers, checker.HasLen, 1) - - cont := containers[0] - - c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none")) - c.Assert(cont.HostConfig.PortBindings, checker.HasLen, 4, check.Commentf("Expected 4 ports bindings, got %d", len(cont.HostConfig.PortBindings))) - - for k, v := range cont.HostConfig.PortBindings { - c.Assert(v, checker.HasLen, 1, check.Commentf("Expected 1 ports binding, for the port %s but found %s", k, v)) - c.Assert(k.Port(), checker.Equals, v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort)) - - } - -} - -func (s *DockerSuite) TestCreateWithLargePortRange(c *check.C) { - out, _ := dockerCmd(c, "create", "-p", "1-65535:1-65535/tcp", "busybox", "echo") - - cleanedContainerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "inspect", cleanedContainerID) - - containers := []struct { - HostConfig *struct { - PortBindings map[nat.Port][]nat.PortBinding - } - }{} - - err := json.Unmarshal([]byte(out), &containers) - c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err)) - c.Assert(containers, checker.HasLen, 1) - - cont := containers[0] - c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none")) - c.Assert(cont.HostConfig.PortBindings, checker.HasLen, 65535) - - for k, v := range cont.HostConfig.PortBindings { - c.Assert(v, checker.HasLen, 1) - c.Assert(k.Port(), checker.Equals, v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort)) - } - -} - -// "test123" should be printed by docker create + start -func (s *DockerSuite) TestCreateEchoStdout(c *check.C) { - out, _ := dockerCmd(c, "create", "busybox", "echo", "test123") - - cleanedContainerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "start", "-ai", cleanedContainerID) - c.Assert(out, checker.Equals, "test123\n", check.Commentf("container should've printed 'test123', got %q", out)) - -} - -func (s *DockerSuite) TestCreateVolumesCreated(c *check.C) { - testRequires(c, SameHostDaemon) - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - - name := "test_create_volume" - dockerCmd(c, "create", "--name", name, "-v", prefix+slash+"foo", "busybox") - - dir, err := inspectMountSourceField(name, prefix+slash+"foo") - c.Assert(err, check.IsNil, check.Commentf("Error getting volume host path: %q", err)) - - if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) { - c.Fatalf("Volume was not created") - } - if err != nil { - c.Fatalf("Error statting volume host path: %q", err) - } - -} - -func (s *DockerSuite) TestCreateLabels(c *check.C) { - name := "test_create_labels" - expected := map[string]string{"k1": "v1", "k2": "v2"} - dockerCmd(c, "create", "--name", name, "-l", "k1=v1", "--label", "k2=v2", "busybox") - - actual := make(map[string]string) - inspectFieldAndMarshall(c, name, "Config.Labels", &actual) - - if !reflect.DeepEqual(expected, actual) { - c.Fatalf("Expected %s got %s", expected, actual) - } -} - -func (s *DockerSuite) TestCreateLabelFromImage(c *check.C) { - imageName := "testcreatebuildlabel" - _, err := buildImage(imageName, - `FROM busybox - LABEL k1=v1 k2=v2`, - true) - - c.Assert(err, check.IsNil) - - name := "test_create_labels_from_image" - expected := map[string]string{"k2": "x", "k3": "v3", "k1": "v1"} - dockerCmd(c, "create", "--name", name, "-l", "k2=x", "--label", "k3=v3", imageName) - - actual := make(map[string]string) - inspectFieldAndMarshall(c, name, "Config.Labels", &actual) - - if !reflect.DeepEqual(expected, actual) { - c.Fatalf("Expected %s got %s", expected, actual) - } -} - -func (s *DockerSuite) TestCreateHostnameWithNumber(c *check.C) { - image := "busybox" - // Busybox on Windows does not implement hostname command - if daemonPlatform == "windows" { - image = WindowsBaseImage - } - out, _ := dockerCmd(c, "run", "-h", "web.0", image, "hostname") - c.Assert(strings.TrimSpace(out), checker.Equals, "web.0", check.Commentf("hostname not set, expected `web.0`, got: %s", out)) - -} - -func (s *DockerSuite) TestCreateRM(c *check.C) { - // Test to make sure we can 'rm' a new container that is in - // "Created" state, and has ever been run. Test "rm -f" too. - - // create a container - out, _ := dockerCmd(c, "create", "busybox") - cID := strings.TrimSpace(out) - - dockerCmd(c, "rm", cID) - - // Now do it again so we can "rm -f" this time - out, _ = dockerCmd(c, "create", "busybox") - - cID = strings.TrimSpace(out) - dockerCmd(c, "rm", "-f", cID) -} - -func (s *DockerSuite) TestCreateModeIpcContainer(c *check.C) { - // Uses Linux specific functionality (--ipc) - testRequires(c, DaemonIsLinux, SameHostDaemon) - - out, _ := dockerCmd(c, "create", "busybox") - id := strings.TrimSpace(out) - - dockerCmd(c, "create", fmt.Sprintf("--ipc=container:%s", id), "busybox") -} - -func (s *DockerSuite) TestCreateByImageID(c *check.C) { - imageName := "testcreatebyimageid" - imageID, err := buildImage(imageName, - `FROM busybox - MAINTAINER dockerio`, - true) - if err != nil { - c.Fatal(err) - } - truncatedImageID := stringid.TruncateID(imageID) - - dockerCmd(c, "create", imageID) - dockerCmd(c, "create", truncatedImageID) - dockerCmd(c, "create", fmt.Sprintf("%s:%s", imageName, truncatedImageID)) - - // Ensure this fails - out, exit, _ := dockerCmdWithError("create", fmt.Sprintf("%s:%s", imageName, imageID)) - if exit == 0 { - c.Fatalf("expected non-zero exit code; received %d", exit) - } - - if expected := "Error parsing reference"; !strings.Contains(out, expected) { - c.Fatalf(`Expected %q in output; got: %s`, expected, out) - } - - out, exit, _ = dockerCmdWithError("create", fmt.Sprintf("%s:%s", "wrongimage", truncatedImageID)) - if exit == 0 { - c.Fatalf("expected non-zero exit code; received %d", exit) - } - - if expected := "Unable to find image"; !strings.Contains(out, expected) { - c.Fatalf(`Expected %q in output; got: %s`, expected, out) - } -} - -func (s *DockerTrustSuite) TestTrustedCreate(c *check.C) { - repoName := s.setupTrustedImage(c, "trusted-create") - - // Try create - createCmd := exec.Command(dockerBinary, "create", repoName) - s.trustedCmd(createCmd) - out, _, err := runCommandWithOutput(createCmd) - c.Assert(err, check.IsNil) - c.Assert(string(out), checker.Contains, "Tagging", check.Commentf("Missing expected output on trusted push:\n%s", out)) - - dockerCmd(c, "rmi", repoName) - - // Try untrusted create to ensure we pushed the tag to the registry - createCmd = exec.Command(dockerBinary, "create", "--disable-content-trust=true", repoName) - s.trustedCmd(createCmd) - out, _, err = runCommandWithOutput(createCmd) - c.Assert(err, check.IsNil) - c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf("Missing expected output on trusted create with --disable-content-trust:\n%s", out)) - -} - -func (s *DockerTrustSuite) TestUntrustedCreate(c *check.C) { - repoName := fmt.Sprintf("%v/dockercliuntrusted/createtest", privateRegistryURL) - withTagName := fmt.Sprintf("%s:latest", repoName) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", withTagName) - dockerCmd(c, "push", withTagName) - dockerCmd(c, "rmi", withTagName) - - // Try trusted create on untrusted tag - createCmd := exec.Command(dockerBinary, "create", withTagName) - s.trustedCmd(createCmd) - out, _, err := runCommandWithOutput(createCmd) - c.Assert(err, check.Not(check.IsNil)) - c.Assert(string(out), checker.Contains, fmt.Sprintf("does not have trust data for %s", repoName), check.Commentf("Missing expected output on trusted create:\n%s", out)) - -} - -func (s *DockerTrustSuite) TestTrustedIsolatedCreate(c *check.C) { - repoName := s.setupTrustedImage(c, "trusted-isolated-create") - - // Try create - createCmd := exec.Command(dockerBinary, "--config", "/tmp/docker-isolated-create", "create", repoName) - s.trustedCmd(createCmd) - out, _, err := runCommandWithOutput(createCmd) - c.Assert(err, check.IsNil) - c.Assert(string(out), checker.Contains, "Tagging", check.Commentf("Missing expected output on trusted push:\n%s", out)) - - dockerCmd(c, "rmi", repoName) -} - -func (s *DockerTrustSuite) TestCreateWhenCertExpired(c *check.C) { - c.Skip("Currently changes system time, causing instability") - repoName := s.setupTrustedImage(c, "trusted-create-expired") - - // Certificates have 10 years of expiration - elevenYearsFromNow := time.Now().Add(time.Hour * 24 * 365 * 11) - - runAtDifferentDate(elevenYearsFromNow, func() { - // Try create - createCmd := exec.Command(dockerBinary, "create", repoName) - s.trustedCmd(createCmd) - out, _, err := runCommandWithOutput(createCmd) - c.Assert(err, check.Not(check.IsNil)) - c.Assert(string(out), checker.Contains, "could not validate the path to a trusted root", check.Commentf("Missing expected output on trusted create in the distant future:\n%s", out)) - }) - - runAtDifferentDate(elevenYearsFromNow, func() { - // Try create - createCmd := exec.Command(dockerBinary, "create", "--disable-content-trust", repoName) - s.trustedCmd(createCmd) - out, _, err := runCommandWithOutput(createCmd) - c.Assert(err, check.Not(check.IsNil)) - c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf("Missing expected output on trusted create in the distant future:\n%s", out)) - - }) -} - -func (s *DockerTrustSuite) TestTrustedCreateFromBadTrustServer(c *check.C) { - repoName := fmt.Sprintf("%v/dockerclievilcreate/trusted:latest", privateRegistryURL) - evilLocalConfigDir, err := ioutil.TempDir("", "evilcreate-local-config-dir") - c.Assert(err, check.IsNil) - - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil) - c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push:\n%s", out)) - - dockerCmd(c, "rmi", repoName) - - // Try create - createCmd := exec.Command(dockerBinary, "create", repoName) - s.trustedCmd(createCmd) - out, _, err = runCommandWithOutput(createCmd) - c.Assert(err, check.IsNil) - c.Assert(string(out), checker.Contains, "Tagging", check.Commentf("Missing expected output on trusted push:\n%s", out)) - - dockerCmd(c, "rmi", repoName) - - // Kill the notary server, start a new "evil" one. - s.not.Close() - s.not, err = newTestNotary(c) - c.Assert(err, check.IsNil) - - // In order to make an evil server, lets re-init a client (with a different trust dir) and push new data. - // tag an image and upload it to the private registry - dockerCmd(c, "--config", evilLocalConfigDir, "tag", "busybox", repoName) - - // Push up to the new server - pushCmd = exec.Command(dockerBinary, "--config", evilLocalConfigDir, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err = runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil) - c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push:\n%s", out)) - - // Now, try creating with the original client from this new trust server. This should fail because the new root is invalid. - createCmd = exec.Command(dockerBinary, "create", repoName) - s.trustedCmd(createCmd) - out, _, err = runCommandWithOutput(createCmd) - if err == nil { - c.Fatalf("Continuing with cached data even though it's an invalid root rotation: %s\n%s", err, out) - } - if !strings.Contains(out, "could not rotate trust to a new trusted root") { - c.Fatalf("Missing expected output on trusted create:\n%s", out) - } - -} - -func (s *DockerSuite) TestCreateStopSignal(c *check.C) { - name := "test_create_stop_signal" - dockerCmd(c, "create", "--name", name, "--stop-signal", "9", "busybox") - - res := inspectFieldJSON(c, name, "Config.StopSignal") - c.Assert(res, checker.Contains, "9") - -} - -func (s *DockerSuite) TestCreateWithWorkdir(c *check.C) { - name := "foo" - - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - dir := prefix + slash + "home" + slash + "foo" + slash + "bar" - - dockerCmd(c, "create", "--name", name, "-w", dir, "busybox") - // Windows does not create the workdir until the container is started - if daemonPlatform == "windows" { - dockerCmd(c, "start", name) - } - dockerCmd(c, "cp", fmt.Sprintf("%s:%s", name, dir), prefix+slash+"tmp") -} - -func (s *DockerSuite) TestCreateWithInvalidLogOpts(c *check.C) { - name := "test-invalidate-log-opts" - out, _, err := dockerCmdWithError("create", "--name", name, "--log-opt", "invalid=true", "busybox") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "unknown log opt") - - out, _ = dockerCmd(c, "ps", "-a") - c.Assert(out, checker.Not(checker.Contains), name) -} - -// #20972 -func (s *DockerSuite) TestCreate64ByteHexID(c *check.C) { - out := inspectField(c, "busybox", "Id") - imageID := strings.TrimPrefix(strings.TrimSpace(string(out)), "sha256:") - - dockerCmd(c, "create", imageID) -} - -// Test case for #23498 -func (s *DockerSuite) TestCreateUnsetEntrypoint(c *check.C) { - name := "test-entrypoint" - dockerfile := `FROM busybox -ADD entrypoint.sh /entrypoint.sh -RUN chmod 755 /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] -CMD echo foobar` - - ctx, err := fakeContext(dockerfile, map[string]string{ - "entrypoint.sh": `#!/bin/sh -echo "I am an entrypoint" -exec "$@"`, - }) - c.Assert(err, check.IsNil) - defer ctx.Close() - - _, err = buildImageFromContext(name, ctx, true) - c.Assert(err, check.IsNil) - - out, _ := dockerCmd(c, "create", "--entrypoint=", name, "echo", "foo") - id := strings.TrimSpace(out) - c.Assert(id, check.Not(check.Equals), "") - out, _ = dockerCmd(c, "start", "-a", id) - c.Assert(strings.TrimSpace(out), check.Equals, "foo") -} - -// #22471 -func (s *DockerSuite) TestCreateStopTimeout(c *check.C) { - name1 := "test_create_stop_timeout_1" - dockerCmd(c, "create", "--name", name1, "--stop-timeout", "15", "busybox") - - res := inspectFieldJSON(c, name1, "Config.StopTimeout") - c.Assert(res, checker.Contains, "15") - - name2 := "test_create_stop_timeout_2" - dockerCmd(c, "create", "--name", name2, "busybox") - - res = inspectFieldJSON(c, name2, "Config.StopTimeout") - c.Assert(res, checker.Contains, "null") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_daemon_plugins_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_daemon_plugins_test.go deleted file mode 100644 index f91edc6..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_daemon_plugins_test.go +++ /dev/null @@ -1,317 +0,0 @@ -// +build linux - -package main - -import ( - "os" - "os/exec" - "path/filepath" - "strings" - "syscall" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/mount" - "github.com/go-check/check" -) - -// TestDaemonRestartWithPluginEnabled tests state restore for an enabled plugin -func (s *DockerDaemonSuite) TestDaemonRestartWithPluginEnabled(c *check.C) { - testRequires(c, IsAmd64, Network) - - if err := s.d.Start(); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - - if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName); err != nil { - c.Fatalf("Could not install plugin: %v %s", err, out) - } - - defer func() { - if out, err := s.d.Cmd("plugin", "disable", pName); err != nil { - c.Fatalf("Could not disable plugin: %v %s", err, out) - } - if out, err := s.d.Cmd("plugin", "remove", pName); err != nil { - c.Fatalf("Could not remove plugin: %v %s", err, out) - } - }() - - if err := s.d.Restart(); err != nil { - c.Fatalf("Could not restart daemon: %v", err) - } - - out, err := s.d.Cmd("plugin", "ls") - if err != nil { - c.Fatalf("Could not list plugins: %v %s", err, out) - } - c.Assert(out, checker.Contains, pName) - c.Assert(out, checker.Contains, "true") -} - -// TestDaemonRestartWithPluginDisabled tests state restore for a disabled plugin -func (s *DockerDaemonSuite) TestDaemonRestartWithPluginDisabled(c *check.C) { - testRequires(c, IsAmd64, Network) - - if err := s.d.Start(); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - - if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName, "--disable"); err != nil { - c.Fatalf("Could not install plugin: %v %s", err, out) - } - - defer func() { - if out, err := s.d.Cmd("plugin", "remove", pName); err != nil { - c.Fatalf("Could not remove plugin: %v %s", err, out) - } - }() - - if err := s.d.Restart(); err != nil { - c.Fatalf("Could not restart daemon: %v", err) - } - - out, err := s.d.Cmd("plugin", "ls") - if err != nil { - c.Fatalf("Could not list plugins: %v %s", err, out) - } - c.Assert(out, checker.Contains, pName) - c.Assert(out, checker.Contains, "false") -} - -// TestDaemonKillLiveRestoreWithPlugins SIGKILLs daemon started with --live-restore. -// Plugins should continue to run. -func (s *DockerDaemonSuite) TestDaemonKillLiveRestoreWithPlugins(c *check.C) { - testRequires(c, IsAmd64, Network) - - if err := s.d.Start("--live-restore"); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName); err != nil { - c.Fatalf("Could not install plugin: %v %s", err, out) - } - defer func() { - if err := s.d.Restart("--live-restore"); err != nil { - c.Fatalf("Could not restart daemon: %v", err) - } - if out, err := s.d.Cmd("plugin", "disable", pName); err != nil { - c.Fatalf("Could not disable plugin: %v %s", err, out) - } - if out, err := s.d.Cmd("plugin", "remove", pName); err != nil { - c.Fatalf("Could not remove plugin: %v %s", err, out) - } - }() - - if err := s.d.Kill(); err != nil { - c.Fatalf("Could not kill daemon: %v", err) - } - - cmd := exec.Command("pgrep", "-f", pluginProcessName) - if out, ec, err := runCommandWithOutput(cmd); ec != 0 { - c.Fatalf("Expected exit code '0', got %d err: %v output: %s ", ec, err, out) - } -} - -// TestDaemonShutdownLiveRestoreWithPlugins SIGTERMs daemon started with --live-restore. -// Plugins should continue to run. -func (s *DockerDaemonSuite) TestDaemonShutdownLiveRestoreWithPlugins(c *check.C) { - testRequires(c, IsAmd64, Network) - - if err := s.d.Start("--live-restore"); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName); err != nil { - c.Fatalf("Could not install plugin: %v %s", err, out) - } - defer func() { - if err := s.d.Restart("--live-restore"); err != nil { - c.Fatalf("Could not restart daemon: %v", err) - } - if out, err := s.d.Cmd("plugin", "disable", pName); err != nil { - c.Fatalf("Could not disable plugin: %v %s", err, out) - } - if out, err := s.d.Cmd("plugin", "remove", pName); err != nil { - c.Fatalf("Could not remove plugin: %v %s", err, out) - } - }() - - if err := s.d.cmd.Process.Signal(os.Interrupt); err != nil { - c.Fatalf("Could not kill daemon: %v", err) - } - - cmd := exec.Command("pgrep", "-f", pluginProcessName) - if out, ec, err := runCommandWithOutput(cmd); ec != 0 { - c.Fatalf("Expected exit code '0', got %d err: %v output: %s ", ec, err, out) - } -} - -// TestDaemonShutdownWithPlugins shuts down running plugins. -func (s *DockerDaemonSuite) TestDaemonShutdownWithPlugins(c *check.C) { - testRequires(c, IsAmd64, Network, SameHostDaemon) - - if err := s.d.Start(); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - if out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName); err != nil { - c.Fatalf("Could not install plugin: %v %s", err, out) - } - - defer func() { - if err := s.d.Restart(); err != nil { - c.Fatalf("Could not restart daemon: %v", err) - } - if out, err := s.d.Cmd("plugin", "disable", pName); err != nil { - c.Fatalf("Could not disable plugin: %v %s", err, out) - } - if out, err := s.d.Cmd("plugin", "remove", pName); err != nil { - c.Fatalf("Could not remove plugin: %v %s", err, out) - } - }() - - if err := s.d.cmd.Process.Signal(os.Interrupt); err != nil { - c.Fatalf("Could not kill daemon: %v", err) - } - - for { - if err := syscall.Kill(s.d.cmd.Process.Pid, 0); err == syscall.ESRCH { - break - } - } - - cmd := exec.Command("pgrep", "-f", pluginProcessName) - if out, ec, err := runCommandWithOutput(cmd); ec != 1 { - c.Fatalf("Expected exit code '1', got %d err: %v output: %s ", ec, err, out) - } - - s.d.Start("--live-restore") - cmd = exec.Command("pgrep", "-f", pluginProcessName) - out, _, err := runCommandWithOutput(cmd) - c.Assert(err, checker.IsNil, check.Commentf(out)) -} - -// TestVolumePlugin tests volume creation using a plugin. -func (s *DockerDaemonSuite) TestVolumePlugin(c *check.C) { - testRequires(c, IsAmd64, Network) - - volName := "plugin-volume" - destDir := "/tmp/data/" - destFile := "foo" - - if err := s.d.Start(); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - out, err := s.d.Cmd("plugin", "install", pName, "--grant-all-permissions") - if err != nil { - c.Fatalf("Could not install plugin: %v %s", err, out) - } - pluginID, err := s.d.Cmd("plugin", "inspect", "-f", "{{.Id}}", pName) - pluginID = strings.TrimSpace(pluginID) - if err != nil { - c.Fatalf("Could not retrieve plugin ID: %v %s", err, pluginID) - } - mountpointPrefix := filepath.Join(s.d.RootDir(), "plugins", pluginID, "rootfs") - defer func() { - if out, err := s.d.Cmd("plugin", "disable", pName); err != nil { - c.Fatalf("Could not disable plugin: %v %s", err, out) - } - - if out, err := s.d.Cmd("plugin", "remove", pName); err != nil { - c.Fatalf("Could not remove plugin: %v %s", err, out) - } - - exists, err := existsMountpointWithPrefix(mountpointPrefix) - c.Assert(err, checker.IsNil) - c.Assert(exists, checker.Equals, false) - - }() - - out, err = s.d.Cmd("volume", "create", "-d", pName, volName) - if err != nil { - c.Fatalf("Could not create volume: %v %s", err, out) - } - defer func() { - if out, err := s.d.Cmd("volume", "remove", volName); err != nil { - c.Fatalf("Could not remove volume: %v %s", err, out) - } - }() - - out, err = s.d.Cmd("volume", "ls") - if err != nil { - c.Fatalf("Could not list volume: %v %s", err, out) - } - c.Assert(out, checker.Contains, volName) - c.Assert(out, checker.Contains, pName) - - mountPoint, err := s.d.Cmd("volume", "inspect", volName, "--format", "{{.Mountpoint}}") - if err != nil { - c.Fatalf("Could not inspect volume: %v %s", err, mountPoint) - } - mountPoint = strings.TrimSpace(mountPoint) - - out, err = s.d.Cmd("run", "--rm", "-v", volName+":"+destDir, "busybox", "touch", destDir+destFile) - c.Assert(err, checker.IsNil, check.Commentf(out)) - path := filepath.Join(s.d.RootDir(), "plugins", pluginID, "rootfs", mountPoint, destFile) - _, err = os.Lstat(path) - c.Assert(err, checker.IsNil) - - exists, err := existsMountpointWithPrefix(mountpointPrefix) - c.Assert(err, checker.IsNil) - c.Assert(exists, checker.Equals, true) -} - -func (s *DockerDaemonSuite) TestGraphdriverPlugin(c *check.C) { - testRequires(c, Network, IsAmd64, DaemonIsLinux, overlay2Supported, ExperimentalDaemon) - - s.d.Start() - - // install the plugin - plugin := "cpuguy83/docker-overlay2-graphdriver-plugin" - out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", plugin) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // restart the daemon with the plugin set as the storage driver - s.d.Restart("-s", plugin, "--storage-opt", "overlay2.override_kernel_check=1") - - // run a container - out, err = s.d.Cmd("run", "--rm", "busybox", "true") // this will pull busybox using the plugin - c.Assert(err, checker.IsNil, check.Commentf(out)) -} - -func (s *DockerDaemonSuite) TestPluginVolumeRemoveOnRestart(c *check.C) { - testRequires(c, DaemonIsLinux, Network, IsAmd64) - - s.d.Start("--live-restore=true") - - out, err := s.d.Cmd("plugin", "install", "--grant-all-permissions", pName) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Contains, pName) - - out, err = s.d.Cmd("volume", "create", "--driver", pName, "test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - s.d.Restart("--live-restore=true") - - out, err = s.d.Cmd("plugin", "disable", pName) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "in use") - - out, err = s.d.Cmd("volume", "rm", "test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("plugin", "disable", pName) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("plugin", "rm", pName) - c.Assert(err, checker.IsNil, check.Commentf(out)) -} - -func existsMountpointWithPrefix(mountpointPrefix string) (bool, error) { - mounts, err := mount.GetMounts() - if err != nil { - return false, err - } - for _, mnt := range mounts { - if strings.HasPrefix(mnt.Mountpoint, mountpointPrefix) { - return true, nil - } - } - return false, nil -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_daemon_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_daemon_test.go deleted file mode 100644 index 3a74fe2..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_daemon_test.go +++ /dev/null @@ -1,2988 +0,0 @@ -// +build linux - -package main - -import ( - "bufio" - "bytes" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net" - "os" - "os/exec" - "path" - "path/filepath" - "regexp" - "strconv" - "strings" - "sync" - "syscall" - "time" - - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/go-units" - "github.com/docker/libnetwork/iptables" - "github.com/docker/libtrust" - "github.com/go-check/check" - "github.com/kr/pty" -) - -// TestLegacyDaemonCommand test starting docker daemon using "deprecated" docker daemon -// command. Remove this test when we remove this. -func (s *DockerDaemonSuite) TestLegacyDaemonCommand(c *check.C) { - cmd := exec.Command(dockerBinary, "daemon", "--storage-driver=vfs", "--debug") - err := cmd.Start() - c.Assert(err, checker.IsNil, check.Commentf("could not start daemon using 'docker daemon'")) - - c.Assert(cmd.Process.Kill(), checker.IsNil) -} - -func (s *DockerDaemonSuite) TestDaemonRestartWithRunningContainersPorts(c *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - c.Fatalf("Could not start daemon with busybox: %v", err) - } - - if out, err := s.d.Cmd("run", "-d", "--name", "top1", "-p", "1234:80", "--restart", "always", "busybox:latest", "top"); err != nil { - c.Fatalf("Could not run top1: err=%v\n%s", err, out) - } - // --restart=no by default - if out, err := s.d.Cmd("run", "-d", "--name", "top2", "-p", "80", "busybox:latest", "top"); err != nil { - c.Fatalf("Could not run top2: err=%v\n%s", err, out) - } - - testRun := func(m map[string]bool, prefix string) { - var format string - for cont, shouldRun := range m { - out, err := s.d.Cmd("ps") - if err != nil { - c.Fatalf("Could not run ps: err=%v\n%q", err, out) - } - if shouldRun { - format = "%scontainer %q is not running" - } else { - format = "%scontainer %q is running" - } - if shouldRun != strings.Contains(out, cont) { - c.Fatalf(format, prefix, cont) - } - } - } - - testRun(map[string]bool{"top1": true, "top2": true}, "") - - if err := s.d.Restart(); err != nil { - c.Fatalf("Could not restart daemon: %v", err) - } - testRun(map[string]bool{"top1": true, "top2": false}, "After daemon restart: ") -} - -func (s *DockerDaemonSuite) TestDaemonRestartWithVolumesRefs(c *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - c.Fatal(err) - } - - if out, err := s.d.Cmd("run", "--name", "volrestarttest1", "-v", "/foo", "busybox"); err != nil { - c.Fatal(err, out) - } - - if err := s.d.Restart(); err != nil { - c.Fatal(err) - } - - if _, err := s.d.Cmd("run", "-d", "--volumes-from", "volrestarttest1", "--name", "volrestarttest2", "busybox", "top"); err != nil { - c.Fatal(err) - } - - if out, err := s.d.Cmd("rm", "-fv", "volrestarttest2"); err != nil { - c.Fatal(err, out) - } - - out, err := s.d.Cmd("inspect", "-f", "{{json .Mounts}}", "volrestarttest1") - c.Assert(err, check.IsNil) - - if _, err := inspectMountPointJSON(out, "/foo"); err != nil { - c.Fatalf("Expected volume to exist: /foo, error: %v\n", err) - } -} - -// #11008 -func (s *DockerDaemonSuite) TestDaemonRestartUnlessStopped(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, check.IsNil) - - out, err := s.d.Cmd("run", "-d", "--name", "top1", "--restart", "always", "busybox:latest", "top") - c.Assert(err, check.IsNil, check.Commentf("run top1: %v", out)) - - out, err = s.d.Cmd("run", "-d", "--name", "top2", "--restart", "unless-stopped", "busybox:latest", "top") - c.Assert(err, check.IsNil, check.Commentf("run top2: %v", out)) - - testRun := func(m map[string]bool, prefix string) { - var format string - for name, shouldRun := range m { - out, err := s.d.Cmd("ps") - c.Assert(err, check.IsNil, check.Commentf("run ps: %v", out)) - if shouldRun { - format = "%scontainer %q is not running" - } else { - format = "%scontainer %q is running" - } - c.Assert(strings.Contains(out, name), check.Equals, shouldRun, check.Commentf(format, prefix, name)) - } - } - - // both running - testRun(map[string]bool{"top1": true, "top2": true}, "") - - out, err = s.d.Cmd("stop", "top1") - c.Assert(err, check.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("stop", "top2") - c.Assert(err, check.IsNil, check.Commentf(out)) - - // both stopped - testRun(map[string]bool{"top1": false, "top2": false}, "") - - err = s.d.Restart() - c.Assert(err, check.IsNil) - - // restart=always running - testRun(map[string]bool{"top1": true, "top2": false}, "After daemon restart: ") - - out, err = s.d.Cmd("start", "top2") - c.Assert(err, check.IsNil, check.Commentf("start top2: %v", out)) - - err = s.d.Restart() - c.Assert(err, check.IsNil) - - // both running - testRun(map[string]bool{"top1": true, "top2": true}, "After second daemon restart: ") - -} - -func (s *DockerDaemonSuite) TestDaemonRestartOnFailure(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, check.IsNil) - - out, err := s.d.Cmd("run", "-d", "--name", "test1", "--restart", "on-failure:3", "busybox:latest", "false") - c.Assert(err, check.IsNil, check.Commentf("run top1: %v", out)) - - // wait test1 to stop - hostArgs := []string{"--host", s.d.sock()} - err = waitInspectWithArgs("test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 10*time.Second, hostArgs...) - c.Assert(err, checker.IsNil, check.Commentf("test1 should exit but not")) - - // record last start time - out, err = s.d.Cmd("inspect", "-f={{.State.StartedAt}}", "test1") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - lastStartTime := out - - err = s.d.Restart() - c.Assert(err, check.IsNil) - - // test1 shouldn't restart at all - err = waitInspectWithArgs("test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 0, hostArgs...) - c.Assert(err, checker.IsNil, check.Commentf("test1 should exit but not")) - - // make sure test1 isn't restarted when daemon restart - // if "StartAt" time updates, means test1 was once restarted. - out, err = s.d.Cmd("inspect", "-f={{.State.StartedAt}}", "test1") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - c.Assert(out, checker.Equals, lastStartTime, check.Commentf("test1 shouldn't start after daemon restarts")) -} - -func (s *DockerDaemonSuite) TestDaemonStartIptablesFalse(c *check.C) { - if err := s.d.Start("--iptables=false"); err != nil { - c.Fatalf("we should have been able to start the daemon with passing iptables=false: %v", err) - } -} - -// Make sure we cannot shrink base device at daemon restart. -func (s *DockerDaemonSuite) TestDaemonRestartWithInvalidBasesize(c *check.C) { - testRequires(c, Devicemapper) - c.Assert(s.d.Start(), check.IsNil) - - oldBasesizeBytes := s.d.getBaseDeviceSize(c) - var newBasesizeBytes int64 = 1073741824 //1GB in bytes - - if newBasesizeBytes < oldBasesizeBytes { - err := s.d.Restart("--storage-opt", fmt.Sprintf("dm.basesize=%d", newBasesizeBytes)) - c.Assert(err, check.IsNil, check.Commentf("daemon should not have started as new base device size is less than existing base device size: %v", err)) - } - c.Assert(s.d.Stop(), check.IsNil) -} - -// Make sure we can grow base device at daemon restart. -func (s *DockerDaemonSuite) TestDaemonRestartWithIncreasedBasesize(c *check.C) { - testRequires(c, Devicemapper) - c.Assert(s.d.Start(), check.IsNil) - - oldBasesizeBytes := s.d.getBaseDeviceSize(c) - - var newBasesizeBytes int64 = 53687091200 //50GB in bytes - - if newBasesizeBytes < oldBasesizeBytes { - c.Skip(fmt.Sprintf("New base device size (%v) must be greater than (%s)", units.HumanSize(float64(newBasesizeBytes)), units.HumanSize(float64(oldBasesizeBytes)))) - } - - err := s.d.Restart("--storage-opt", fmt.Sprintf("dm.basesize=%d", newBasesizeBytes)) - c.Assert(err, check.IsNil, check.Commentf("we should have been able to start the daemon with increased base device size: %v", err)) - - basesizeAfterRestart := s.d.getBaseDeviceSize(c) - newBasesize, err := convertBasesize(newBasesizeBytes) - c.Assert(err, check.IsNil, check.Commentf("Error in converting base device size: %v", err)) - c.Assert(newBasesize, check.Equals, basesizeAfterRestart, check.Commentf("Basesize passed is not equal to Basesize set")) - c.Assert(s.d.Stop(), check.IsNil) -} - -// Issue #8444: If docker0 bridge is modified (intentionally or unintentionally) and -// no longer has an IP associated, we should gracefully handle that case and associate -// an IP with it rather than fail daemon start -func (s *DockerDaemonSuite) TestDaemonStartBridgeWithoutIPAssociation(c *check.C) { - // rather than depending on brctl commands to verify docker0 is created and up - // let's start the daemon and stop it, and then make a modification to run the - // actual test - if err := s.d.Start(); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - if err := s.d.Stop(); err != nil { - c.Fatalf("Could not stop daemon: %v", err) - } - - // now we will remove the ip from docker0 and then try starting the daemon - ipCmd := exec.Command("ip", "addr", "flush", "dev", "docker0") - stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd) - if err != nil { - c.Fatalf("failed to remove docker0 IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr) - } - - if err := s.d.Start(); err != nil { - warning := "**WARNING: Docker bridge network in bad state--delete docker0 bridge interface to fix" - c.Fatalf("Could not start daemon when docker0 has no IP address: %v\n%s", err, warning) - } -} - -func (s *DockerDaemonSuite) TestDaemonIptablesClean(c *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - c.Fatalf("Could not start daemon with busybox: %v", err) - } - - if out, err := s.d.Cmd("run", "-d", "--name", "top", "-p", "80", "busybox:latest", "top"); err != nil { - c.Fatalf("Could not run top: %s, %v", out, err) - } - - // get output from iptables with container running - ipTablesSearchString := "tcp dpt:80" - ipTablesCmd := exec.Command("iptables", "-nvL") - out, _, err := runCommandWithOutput(ipTablesCmd) - if err != nil { - c.Fatalf("Could not run iptables -nvL: %s, %v", out, err) - } - - if !strings.Contains(out, ipTablesSearchString) { - c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, out) - } - - if err := s.d.Stop(); err != nil { - c.Fatalf("Could not stop daemon: %v", err) - } - - // get output from iptables after restart - ipTablesCmd = exec.Command("iptables", "-nvL") - out, _, err = runCommandWithOutput(ipTablesCmd) - if err != nil { - c.Fatalf("Could not run iptables -nvL: %s, %v", out, err) - } - - if strings.Contains(out, ipTablesSearchString) { - c.Fatalf("iptables output should not have contained %q, but was %q", ipTablesSearchString, out) - } -} - -func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - c.Fatalf("Could not start daemon with busybox: %v", err) - } - - if out, err := s.d.Cmd("run", "-d", "--name", "top", "--restart=always", "-p", "80", "busybox:latest", "top"); err != nil { - c.Fatalf("Could not run top: %s, %v", out, err) - } - - // get output from iptables with container running - ipTablesSearchString := "tcp dpt:80" - ipTablesCmd := exec.Command("iptables", "-nvL") - out, _, err := runCommandWithOutput(ipTablesCmd) - if err != nil { - c.Fatalf("Could not run iptables -nvL: %s, %v", out, err) - } - - if !strings.Contains(out, ipTablesSearchString) { - c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, out) - } - - if err := s.d.Restart(); err != nil { - c.Fatalf("Could not restart daemon: %v", err) - } - - // make sure the container is not running - runningOut, err := s.d.Cmd("inspect", "--format={{.State.Running}}", "top") - if err != nil { - c.Fatalf("Could not inspect on container: %s, %v", out, err) - } - if strings.TrimSpace(runningOut) != "true" { - c.Fatalf("Container should have been restarted after daemon restart. Status running should have been true but was: %q", strings.TrimSpace(runningOut)) - } - - // get output from iptables after restart - ipTablesCmd = exec.Command("iptables", "-nvL") - out, _, err = runCommandWithOutput(ipTablesCmd) - if err != nil { - c.Fatalf("Could not run iptables -nvL: %s, %v", out, err) - } - - if !strings.Contains(out, ipTablesSearchString) { - c.Fatalf("iptables output after restart should have contained %q, but was %q", ipTablesSearchString, out) - } -} - -// TestDaemonIPv6Enabled checks that when the daemon is started with --ipv6=true that the docker0 bridge -// has the fe80::1 address and that a container is assigned a link-local address -func (s *DockerDaemonSuite) TestDaemonIPv6Enabled(c *check.C) { - testRequires(c, IPv6) - - setupV6(c) - defer teardownV6(c) - - if err := s.d.StartWithBusybox("--ipv6"); err != nil { - c.Fatal(err) - } - - iface, err := net.InterfaceByName("docker0") - if err != nil { - c.Fatalf("Error getting docker0 interface: %v", err) - } - - addrs, err := iface.Addrs() - if err != nil { - c.Fatalf("Error getting addresses for docker0 interface: %v", err) - } - - var found bool - expected := "fe80::1/64" - - for i := range addrs { - if addrs[i].String() == expected { - found = true - break - } - } - - if !found { - c.Fatalf("Bridge does not have an IPv6 Address") - } - - if out, err := s.d.Cmd("run", "-itd", "--name=ipv6test", "busybox:latest"); err != nil { - c.Fatalf("Could not run container: %s, %v", out, err) - } - - out, err := s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.Networks.bridge.LinkLocalIPv6Address}}'", "ipv6test") - out = strings.Trim(out, " \r\n'") - - if err != nil { - c.Fatalf("Error inspecting container: %s, %v", out, err) - } - - if ip := net.ParseIP(out); ip == nil { - c.Fatalf("Container should have a link-local IPv6 address") - } - - out, err = s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}'", "ipv6test") - out = strings.Trim(out, " \r\n'") - - if err != nil { - c.Fatalf("Error inspecting container: %s, %v", out, err) - } - - if ip := net.ParseIP(out); ip != nil { - c.Fatalf("Container should not have a global IPv6 address: %v", out) - } -} - -// TestDaemonIPv6FixedCIDR checks that when the daemon is started with --ipv6=true and a fixed CIDR -// that running containers are given a link-local and global IPv6 address -func (s *DockerDaemonSuite) TestDaemonIPv6FixedCIDR(c *check.C) { - // IPv6 setup is messing with local bridge address. - testRequires(c, SameHostDaemon) - setupV6(c) - defer teardownV6(c) - - err := s.d.StartWithBusybox("--ipv6", "--fixed-cidr-v6=2001:db8:2::/64", "--default-gateway-v6=2001:db8:2::100") - c.Assert(err, checker.IsNil, check.Commentf("Could not start daemon with busybox: %v", err)) - - out, err := s.d.Cmd("run", "-itd", "--name=ipv6test", "busybox:latest") - c.Assert(err, checker.IsNil, check.Commentf("Could not run container: %s, %v", out, err)) - - out, err = s.d.Cmd("inspect", "--format", "{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}", "ipv6test") - out = strings.Trim(out, " \r\n'") - - c.Assert(err, checker.IsNil, check.Commentf(out)) - - ip := net.ParseIP(out) - c.Assert(ip, checker.NotNil, check.Commentf("Container should have a global IPv6 address")) - - out, err = s.d.Cmd("inspect", "--format", "{{.NetworkSettings.Networks.bridge.IPv6Gateway}}", "ipv6test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - c.Assert(strings.Trim(out, " \r\n'"), checker.Equals, "2001:db8:2::100", check.Commentf("Container should have a global IPv6 gateway")) -} - -// TestDaemonIPv6FixedCIDRAndMac checks that when the daemon is started with ipv6 fixed CIDR -// the running containers are given an IPv6 address derived from the MAC address and the ipv6 fixed CIDR -func (s *DockerDaemonSuite) TestDaemonIPv6FixedCIDRAndMac(c *check.C) { - // IPv6 setup is messing with local bridge address. - testRequires(c, SameHostDaemon) - setupV6(c) - defer teardownV6(c) - - err := s.d.StartWithBusybox("--ipv6", "--fixed-cidr-v6=2001:db8:1::/64") - c.Assert(err, checker.IsNil) - - out, err := s.d.Cmd("run", "-itd", "--name=ipv6test", "--mac-address", "AA:BB:CC:DD:EE:FF", "busybox") - c.Assert(err, checker.IsNil) - - out, err = s.d.Cmd("inspect", "--format", "{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}", "ipv6test") - c.Assert(err, checker.IsNil) - c.Assert(strings.Trim(out, " \r\n'"), checker.Equals, "2001:db8:1::aabb:ccdd:eeff") -} - -func (s *DockerDaemonSuite) TestDaemonLogLevelWrong(c *check.C) { - c.Assert(s.d.Start("--log-level=bogus"), check.NotNil, check.Commentf("Daemon shouldn't start with wrong log level")) -} - -func (s *DockerDaemonSuite) TestDaemonLogLevelDebug(c *check.C) { - if err := s.d.Start("--log-level=debug"); err != nil { - c.Fatal(err) - } - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - if !strings.Contains(string(content), `level=debug`) { - c.Fatalf(`Missing level="debug" in log file:\n%s`, string(content)) - } -} - -func (s *DockerDaemonSuite) TestDaemonLogLevelFatal(c *check.C) { - // we creating new daemons to create new logFile - if err := s.d.Start("--log-level=fatal"); err != nil { - c.Fatal(err) - } - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - if strings.Contains(string(content), `level=debug`) { - c.Fatalf(`Should not have level="debug" in log file:\n%s`, string(content)) - } -} - -func (s *DockerDaemonSuite) TestDaemonFlagD(c *check.C) { - if err := s.d.Start("-D"); err != nil { - c.Fatal(err) - } - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - if !strings.Contains(string(content), `level=debug`) { - c.Fatalf(`Should have level="debug" in log file using -D:\n%s`, string(content)) - } -} - -func (s *DockerDaemonSuite) TestDaemonFlagDebug(c *check.C) { - if err := s.d.Start("--debug"); err != nil { - c.Fatal(err) - } - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - if !strings.Contains(string(content), `level=debug`) { - c.Fatalf(`Should have level="debug" in log file using --debug:\n%s`, string(content)) - } -} - -func (s *DockerDaemonSuite) TestDaemonFlagDebugLogLevelFatal(c *check.C) { - if err := s.d.Start("--debug", "--log-level=fatal"); err != nil { - c.Fatal(err) - } - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - if !strings.Contains(string(content), `level=debug`) { - c.Fatalf(`Should have level="debug" in log file when using both --debug and --log-level=fatal:\n%s`, string(content)) - } -} - -func (s *DockerDaemonSuite) TestDaemonAllocatesListeningPort(c *check.C) { - listeningPorts := [][]string{ - {"0.0.0.0", "0.0.0.0", "5678"}, - {"127.0.0.1", "127.0.0.1", "1234"}, - {"localhost", "127.0.0.1", "1235"}, - } - - cmdArgs := make([]string, 0, len(listeningPorts)*2) - for _, hostDirective := range listeningPorts { - cmdArgs = append(cmdArgs, "--host", fmt.Sprintf("tcp://%s:%s", hostDirective[0], hostDirective[2])) - } - - if err := s.d.StartWithBusybox(cmdArgs...); err != nil { - c.Fatalf("Could not start daemon with busybox: %v", err) - } - - for _, hostDirective := range listeningPorts { - output, err := s.d.Cmd("run", "-p", fmt.Sprintf("%s:%s:80", hostDirective[1], hostDirective[2]), "busybox", "true") - if err == nil { - c.Fatalf("Container should not start, expected port already allocated error: %q", output) - } else if !strings.Contains(output, "port is already allocated") { - c.Fatalf("Expected port is already allocated error: %q", output) - } - } -} - -func (s *DockerDaemonSuite) TestDaemonKeyGeneration(c *check.C) { - // TODO: skip or update for Windows daemon - os.Remove("/etc/docker/key.json") - if err := s.d.Start(); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - s.d.Stop() - - k, err := libtrust.LoadKeyFile("/etc/docker/key.json") - if err != nil { - c.Fatalf("Error opening key file") - } - kid := k.KeyID() - // Test Key ID is a valid fingerprint (e.g. QQXN:JY5W:TBXI:MK3X:GX6P:PD5D:F56N:NHCS:LVRZ:JA46:R24J:XEFF) - if len(kid) != 59 { - c.Fatalf("Bad key ID: %s", kid) - } -} - -func (s *DockerDaemonSuite) TestDaemonKeyMigration(c *check.C) { - // TODO: skip or update for Windows daemon - os.Remove("/etc/docker/key.json") - k1, err := libtrust.GenerateECP256PrivateKey() - if err != nil { - c.Fatalf("Error generating private key: %s", err) - } - if err := os.MkdirAll(filepath.Join(os.Getenv("HOME"), ".docker"), 0755); err != nil { - c.Fatalf("Error creating .docker directory: %s", err) - } - if err := libtrust.SaveKey(filepath.Join(os.Getenv("HOME"), ".docker", "key.json"), k1); err != nil { - c.Fatalf("Error saving private key: %s", err) - } - - if err := s.d.Start(); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - s.d.Stop() - - k2, err := libtrust.LoadKeyFile("/etc/docker/key.json") - if err != nil { - c.Fatalf("Error opening key file") - } - if k1.KeyID() != k2.KeyID() { - c.Fatalf("Key not migrated") - } -} - -// GH#11320 - verify that the daemon exits on failure properly -// Note that this explicitly tests the conflict of {-b,--bridge} and {--bip} options as the means -// to get a daemon init failure; no other tests for -b/--bip conflict are therefore required -func (s *DockerDaemonSuite) TestDaemonExitOnFailure(c *check.C) { - //attempt to start daemon with incorrect flags (we know -b and --bip conflict) - if err := s.d.Start("--bridge", "nosuchbridge", "--bip", "1.1.1.1"); err != nil { - //verify we got the right error - if !strings.Contains(err.Error(), "Daemon exited") { - c.Fatalf("Expected daemon not to start, got %v", err) - } - // look in the log and make sure we got the message that daemon is shutting down - runCmd := exec.Command("grep", "Error starting daemon", s.d.LogFileName()) - if out, _, err := runCommandWithOutput(runCmd); err != nil { - c.Fatalf("Expected 'Error starting daemon' message; but doesn't exist in log: %q, err: %v", out, err) - } - } else { - //if we didn't get an error and the daemon is running, this is a failure - c.Fatal("Conflicting options should cause the daemon to error out with a failure") - } -} - -func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) { - d := s.d - err := d.Start("--bridge", "nosuchbridge") - c.Assert(err, check.NotNil, check.Commentf("--bridge option with an invalid bridge should cause the daemon to fail")) - defer d.Restart() - - bridgeName := "external-bridge" - bridgeIP := "192.169.1.1/24" - _, bridgeIPNet, _ := net.ParseCIDR(bridgeIP) - - out, err := createInterface(c, "bridge", bridgeName, bridgeIP) - c.Assert(err, check.IsNil, check.Commentf(out)) - defer deleteInterface(c, bridgeName) - - err = d.StartWithBusybox("--bridge", bridgeName) - c.Assert(err, check.IsNil) - - ipTablesSearchString := bridgeIPNet.String() - ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL") - out, _, err = runCommandWithOutput(ipTablesCmd) - c.Assert(err, check.IsNil) - - c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true, - check.Commentf("iptables output should have contained %q, but was %q", - ipTablesSearchString, out)) - - _, err = d.Cmd("run", "-d", "--name", "ExtContainer", "busybox", "top") - c.Assert(err, check.IsNil) - - containerIP := d.findContainerIP("ExtContainer") - ip := net.ParseIP(containerIP) - c.Assert(bridgeIPNet.Contains(ip), check.Equals, true, - check.Commentf("Container IP-Address must be in the same subnet range : %s", - containerIP)) -} - -func (s *DockerDaemonSuite) TestDaemonBridgeNone(c *check.C) { - // start with bridge none - d := s.d - err := d.StartWithBusybox("--bridge", "none") - c.Assert(err, check.IsNil) - defer d.Restart() - - // verify docker0 iface is not there - out, _, err := runCommandWithOutput(exec.Command("ifconfig", "docker0")) - c.Assert(err, check.NotNil, check.Commentf("docker0 should not be present if daemon started with --bridge=none")) - c.Assert(strings.Contains(out, "Device not found"), check.Equals, true) - - // verify default "bridge" network is not there - out, err = d.Cmd("network", "inspect", "bridge") - c.Assert(err, check.NotNil, check.Commentf("\"bridge\" network should not be present if daemon started with --bridge=none")) - c.Assert(strings.Contains(out, "No such network"), check.Equals, true) -} - -func createInterface(c *check.C, ifType string, ifName string, ipNet string) (string, error) { - args := []string{"link", "add", "name", ifName, "type", ifType} - ipLinkCmd := exec.Command("ip", args...) - out, _, err := runCommandWithOutput(ipLinkCmd) - if err != nil { - return out, err - } - - ifCfgCmd := exec.Command("ifconfig", ifName, ipNet, "up") - out, _, err = runCommandWithOutput(ifCfgCmd) - return out, err -} - -func deleteInterface(c *check.C, ifName string) { - ifCmd := exec.Command("ip", "link", "delete", ifName) - out, _, err := runCommandWithOutput(ifCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - - flushCmd := exec.Command("iptables", "-t", "nat", "--flush") - out, _, err = runCommandWithOutput(flushCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - - flushCmd = exec.Command("iptables", "--flush") - out, _, err = runCommandWithOutput(flushCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) -} - -func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) { - // TestDaemonBridgeIP Steps - // 1. Delete the existing docker0 Bridge - // 2. Set --bip daemon configuration and start the new Docker Daemon - // 3. Check if the bip config has taken effect using ifconfig and iptables commands - // 4. Launch a Container and make sure the IP-Address is in the expected subnet - // 5. Delete the docker0 Bridge - // 6. Restart the Docker Daemon (via deferred action) - // This Restart takes care of bringing docker0 interface back to auto-assigned IP - - defaultNetworkBridge := "docker0" - deleteInterface(c, defaultNetworkBridge) - - d := s.d - - bridgeIP := "192.169.1.1/24" - ip, bridgeIPNet, _ := net.ParseCIDR(bridgeIP) - - err := d.StartWithBusybox("--bip", bridgeIP) - c.Assert(err, check.IsNil) - defer d.Restart() - - ifconfigSearchString := ip.String() - ifconfigCmd := exec.Command("ifconfig", defaultNetworkBridge) - out, _, _, err := runCommandWithStdoutStderr(ifconfigCmd) - c.Assert(err, check.IsNil) - - c.Assert(strings.Contains(out, ifconfigSearchString), check.Equals, true, - check.Commentf("ifconfig output should have contained %q, but was %q", - ifconfigSearchString, out)) - - ipTablesSearchString := bridgeIPNet.String() - ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL") - out, _, err = runCommandWithOutput(ipTablesCmd) - c.Assert(err, check.IsNil) - - c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true, - check.Commentf("iptables output should have contained %q, but was %q", - ipTablesSearchString, out)) - - out, err = d.Cmd("run", "-d", "--name", "test", "busybox", "top") - c.Assert(err, check.IsNil) - - containerIP := d.findContainerIP("test") - ip = net.ParseIP(containerIP) - c.Assert(bridgeIPNet.Contains(ip), check.Equals, true, - check.Commentf("Container IP-Address must be in the same subnet range : %s", - containerIP)) - deleteInterface(c, defaultNetworkBridge) -} - -func (s *DockerDaemonSuite) TestDaemonRestartWithBridgeIPChange(c *check.C) { - if err := s.d.Start(); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - defer s.d.Restart() - if err := s.d.Stop(); err != nil { - c.Fatalf("Could not stop daemon: %v", err) - } - - // now we will change the docker0's IP and then try starting the daemon - bridgeIP := "192.169.100.1/24" - _, bridgeIPNet, _ := net.ParseCIDR(bridgeIP) - - ipCmd := exec.Command("ifconfig", "docker0", bridgeIP) - stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd) - if err != nil { - c.Fatalf("failed to change docker0's IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr) - } - - if err := s.d.Start("--bip", bridgeIP); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - - //check if the iptables contains new bridgeIP MASQUERADE rule - ipTablesSearchString := bridgeIPNet.String() - ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL") - out, _, err := runCommandWithOutput(ipTablesCmd) - if err != nil { - c.Fatalf("Could not run iptables -nvL: %s, %v", out, err) - } - if !strings.Contains(out, ipTablesSearchString) { - c.Fatalf("iptables output should have contained new MASQUERADE rule with IP %q, but was %q", ipTablesSearchString, out) - } -} - -func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr(c *check.C) { - d := s.d - - bridgeName := "external-bridge" - bridgeIP := "192.169.1.1/24" - - out, err := createInterface(c, "bridge", bridgeName, bridgeIP) - c.Assert(err, check.IsNil, check.Commentf(out)) - defer deleteInterface(c, bridgeName) - - args := []string{"--bridge", bridgeName, "--fixed-cidr", "192.169.1.0/30"} - err = d.StartWithBusybox(args...) - c.Assert(err, check.IsNil) - defer d.Restart() - - for i := 0; i < 4; i++ { - cName := "Container" + strconv.Itoa(i) - out, err := d.Cmd("run", "-d", "--name", cName, "busybox", "top") - if err != nil { - c.Assert(strings.Contains(out, "no available IPv4 addresses"), check.Equals, true, - check.Commentf("Could not run a Container : %s %s", err.Error(), out)) - } - } -} - -func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr2(c *check.C) { - d := s.d - - bridgeName := "external-bridge" - bridgeIP := "10.2.2.1/16" - - out, err := createInterface(c, "bridge", bridgeName, bridgeIP) - c.Assert(err, check.IsNil, check.Commentf(out)) - defer deleteInterface(c, bridgeName) - - err = d.StartWithBusybox("--bip", bridgeIP, "--fixed-cidr", "10.2.2.0/24") - c.Assert(err, check.IsNil) - defer s.d.Restart() - - out, err = d.Cmd("run", "-d", "--name", "bb", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - defer d.Cmd("stop", "bb") - - out, err = d.Cmd("exec", "bb", "/bin/sh", "-c", "ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'") - c.Assert(out, checker.Equals, "10.2.2.0\n") - - out, err = d.Cmd("run", "--rm", "busybox", "/bin/sh", "-c", "ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(out, checker.Equals, "10.2.2.2\n") -} - -func (s *DockerDaemonSuite) TestDaemonBridgeFixedCIDREqualBridgeNetwork(c *check.C) { - d := s.d - - bridgeName := "external-bridge" - bridgeIP := "172.27.42.1/16" - - out, err := createInterface(c, "bridge", bridgeName, bridgeIP) - c.Assert(err, check.IsNil, check.Commentf(out)) - defer deleteInterface(c, bridgeName) - - err = d.StartWithBusybox("--bridge", bridgeName, "--fixed-cidr", bridgeIP) - c.Assert(err, check.IsNil) - defer s.d.Restart() - - out, err = d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf(out)) - cid1 := strings.TrimSpace(out) - defer d.Cmd("stop", cid1) -} - -func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Implicit(c *check.C) { - defaultNetworkBridge := "docker0" - deleteInterface(c, defaultNetworkBridge) - - d := s.d - - bridgeIP := "192.169.1.1" - bridgeIPNet := fmt.Sprintf("%s/24", bridgeIP) - - err := d.StartWithBusybox("--bip", bridgeIPNet) - c.Assert(err, check.IsNil) - defer d.Restart() - - expectedMessage := fmt.Sprintf("default via %s dev", bridgeIP) - out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0") - c.Assert(strings.Contains(out, expectedMessage), check.Equals, true, - check.Commentf("Implicit default gateway should be bridge IP %s, but default route was '%s'", - bridgeIP, strings.TrimSpace(out))) - deleteInterface(c, defaultNetworkBridge) -} - -func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Explicit(c *check.C) { - defaultNetworkBridge := "docker0" - deleteInterface(c, defaultNetworkBridge) - - d := s.d - - bridgeIP := "192.169.1.1" - bridgeIPNet := fmt.Sprintf("%s/24", bridgeIP) - gatewayIP := "192.169.1.254" - - err := d.StartWithBusybox("--bip", bridgeIPNet, "--default-gateway", gatewayIP) - c.Assert(err, check.IsNil) - defer d.Restart() - - expectedMessage := fmt.Sprintf("default via %s dev", gatewayIP) - out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0") - c.Assert(strings.Contains(out, expectedMessage), check.Equals, true, - check.Commentf("Explicit default gateway should be %s, but default route was '%s'", - gatewayIP, strings.TrimSpace(out))) - deleteInterface(c, defaultNetworkBridge) -} - -func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4ExplicitOutsideContainerSubnet(c *check.C) { - defaultNetworkBridge := "docker0" - deleteInterface(c, defaultNetworkBridge) - - // Program a custom default gateway outside of the container subnet, daemon should accept it and start - err := s.d.StartWithBusybox("--bip", "172.16.0.10/16", "--fixed-cidr", "172.16.1.0/24", "--default-gateway", "172.16.0.254") - c.Assert(err, check.IsNil) - - deleteInterface(c, defaultNetworkBridge) - s.d.Restart() -} - -func (s *DockerDaemonSuite) TestDaemonDefaultNetworkInvalidClusterConfig(c *check.C) { - testRequires(c, DaemonIsLinux, SameHostDaemon) - - // Start daemon without docker0 bridge - defaultNetworkBridge := "docker0" - deleteInterface(c, defaultNetworkBridge) - - discoveryBackend := "consul://consuladdr:consulport/some/path" - err := s.d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend)) - c.Assert(err, checker.IsNil) - - // Start daemon with docker0 bridge - result := icmd.RunCommand("ifconfig", defaultNetworkBridge) - c.Assert(result, icmd.Matches, icmd.Success) - - err = s.d.Restart(fmt.Sprintf("--cluster-store=%s", discoveryBackend)) - c.Assert(err, checker.IsNil) -} - -func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) { - d := s.d - - ipStr := "192.170.1.1/24" - ip, _, _ := net.ParseCIDR(ipStr) - args := []string{"--ip", ip.String()} - err := d.StartWithBusybox(args...) - c.Assert(err, check.IsNil) - defer d.Restart() - - out, err := d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top") - c.Assert(err, check.NotNil, - check.Commentf("Running a container must fail with an invalid --ip option")) - c.Assert(strings.Contains(out, "Error starting userland proxy"), check.Equals, true) - - ifName := "dummy" - out, err = createInterface(c, "dummy", ifName, ipStr) - c.Assert(err, check.IsNil, check.Commentf(out)) - defer deleteInterface(c, ifName) - - _, err = d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top") - c.Assert(err, check.IsNil) - - ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL") - out, _, err = runCommandWithOutput(ipTablesCmd) - c.Assert(err, check.IsNil) - - regex := fmt.Sprintf("DNAT.*%s.*dpt:8000", ip.String()) - matched, _ := regexp.MatchString(regex, out) - c.Assert(matched, check.Equals, true, - check.Commentf("iptables output should have contained %q, but was %q", regex, out)) -} - -func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) { - testRequires(c, bridgeNfIptables) - d := s.d - - bridgeName := "external-bridge" - bridgeIP := "192.169.1.1/24" - - out, err := createInterface(c, "bridge", bridgeName, bridgeIP) - c.Assert(err, check.IsNil, check.Commentf(out)) - defer deleteInterface(c, bridgeName) - - args := []string{"--bridge", bridgeName, "--icc=false"} - err = d.StartWithBusybox(args...) - c.Assert(err, check.IsNil) - defer d.Restart() - - ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD") - out, _, err = runCommandWithOutput(ipTablesCmd) - c.Assert(err, check.IsNil) - - regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName) - matched, _ := regexp.MatchString(regex, out) - c.Assert(matched, check.Equals, true, - check.Commentf("iptables output should have contained %q, but was %q", regex, out)) - - // Pinging another container must fail with --icc=false - pingContainers(c, d, true) - - ipStr := "192.171.1.1/24" - ip, _, _ := net.ParseCIDR(ipStr) - ifName := "icc-dummy" - - createInterface(c, "dummy", ifName, ipStr) - - // But, Pinging external or a Host interface must succeed - pingCmd := fmt.Sprintf("ping -c 1 %s -W 1", ip.String()) - runArgs := []string{"run", "--rm", "busybox", "sh", "-c", pingCmd} - _, err = d.Cmd(runArgs...) - c.Assert(err, check.IsNil) -} - -func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *check.C) { - d := s.d - - bridgeName := "external-bridge" - bridgeIP := "192.169.1.1/24" - - out, err := createInterface(c, "bridge", bridgeName, bridgeIP) - c.Assert(err, check.IsNil, check.Commentf(out)) - defer deleteInterface(c, bridgeName) - - args := []string{"--bridge", bridgeName, "--icc=false"} - err = d.StartWithBusybox(args...) - c.Assert(err, check.IsNil) - defer d.Restart() - - ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD") - out, _, err = runCommandWithOutput(ipTablesCmd) - c.Assert(err, check.IsNil) - - regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName) - matched, _ := regexp.MatchString(regex, out) - c.Assert(matched, check.Equals, true, - check.Commentf("iptables output should have contained %q, but was %q", regex, out)) - - out, err = d.Cmd("run", "-d", "--expose", "4567", "--name", "icc1", "busybox", "nc", "-l", "-p", "4567") - c.Assert(err, check.IsNil, check.Commentf(out)) - - out, err = d.Cmd("run", "--link", "icc1:icc1", "busybox", "nc", "icc1", "4567") - c.Assert(err, check.IsNil, check.Commentf(out)) -} - -func (s *DockerDaemonSuite) TestDaemonLinksIpTablesRulesWhenLinkAndUnlink(c *check.C) { - bridgeName := "external-bridge" - bridgeIP := "192.169.1.1/24" - - out, err := createInterface(c, "bridge", bridgeName, bridgeIP) - c.Assert(err, check.IsNil, check.Commentf(out)) - defer deleteInterface(c, bridgeName) - - err = s.d.StartWithBusybox("--bridge", bridgeName, "--icc=false") - c.Assert(err, check.IsNil) - defer s.d.Restart() - - _, err = s.d.Cmd("run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "top") - c.Assert(err, check.IsNil) - _, err = s.d.Cmd("run", "-d", "--name", "parent", "--link", "child:http", "busybox", "top") - c.Assert(err, check.IsNil) - - childIP := s.d.findContainerIP("child") - parentIP := s.d.findContainerIP("parent") - - sourceRule := []string{"-i", bridgeName, "-o", bridgeName, "-p", "tcp", "-s", childIP, "--sport", "80", "-d", parentIP, "-j", "ACCEPT"} - destinationRule := []string{"-i", bridgeName, "-o", bridgeName, "-p", "tcp", "-s", parentIP, "--dport", "80", "-d", childIP, "-j", "ACCEPT"} - if !iptables.Exists("filter", "DOCKER", sourceRule...) || !iptables.Exists("filter", "DOCKER", destinationRule...) { - c.Fatal("Iptables rules not found") - } - - s.d.Cmd("rm", "--link", "parent/http") - if iptables.Exists("filter", "DOCKER", sourceRule...) || iptables.Exists("filter", "DOCKER", destinationRule...) { - c.Fatal("Iptables rules should be removed when unlink") - } - - s.d.Cmd("kill", "child") - s.d.Cmd("kill", "parent") -} - -func (s *DockerDaemonSuite) TestDaemonUlimitDefaults(c *check.C) { - testRequires(c, DaemonIsLinux) - - if err := s.d.StartWithBusybox("--default-ulimit", "nofile=42:42", "--default-ulimit", "nproc=1024:1024"); err != nil { - c.Fatal(err) - } - - out, err := s.d.Cmd("run", "--ulimit", "nproc=2048", "--name=test", "busybox", "/bin/sh", "-c", "echo $(ulimit -n); echo $(ulimit -p)") - if err != nil { - c.Fatal(out, err) - } - - outArr := strings.Split(out, "\n") - if len(outArr) < 2 { - c.Fatalf("got unexpected output: %s", out) - } - nofile := strings.TrimSpace(outArr[0]) - nproc := strings.TrimSpace(outArr[1]) - - if nofile != "42" { - c.Fatalf("expected `ulimit -n` to be `42`, got: %s", nofile) - } - if nproc != "2048" { - c.Fatalf("exepcted `ulimit -p` to be 2048, got: %s", nproc) - } - - // Now restart daemon with a new default - if err := s.d.Restart("--default-ulimit", "nofile=43"); err != nil { - c.Fatal(err) - } - - out, err = s.d.Cmd("start", "-a", "test") - if err != nil { - c.Fatal(err) - } - - outArr = strings.Split(out, "\n") - if len(outArr) < 2 { - c.Fatalf("got unexpected output: %s", out) - } - nofile = strings.TrimSpace(outArr[0]) - nproc = strings.TrimSpace(outArr[1]) - - if nofile != "43" { - c.Fatalf("expected `ulimit -n` to be `43`, got: %s", nofile) - } - if nproc != "2048" { - c.Fatalf("exepcted `ulimit -p` to be 2048, got: %s", nproc) - } -} - -// #11315 -func (s *DockerDaemonSuite) TestDaemonRestartRenameContainer(c *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - c.Fatal(err) - } - - if out, err := s.d.Cmd("run", "--name=test", "busybox"); err != nil { - c.Fatal(err, out) - } - - if out, err := s.d.Cmd("rename", "test", "test2"); err != nil { - c.Fatal(err, out) - } - - if err := s.d.Restart(); err != nil { - c.Fatal(err) - } - - if out, err := s.d.Cmd("start", "test2"); err != nil { - c.Fatal(err, out) - } -} - -func (s *DockerDaemonSuite) TestDaemonLoggingDriverDefault(c *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - c.Fatal(err) - } - - out, err := s.d.Cmd("run", "--name=test", "busybox", "echo", "testline") - c.Assert(err, check.IsNil, check.Commentf(out)) - id, err := s.d.getIDByName("test") - c.Assert(err, check.IsNil) - - logPath := filepath.Join(s.d.root, "containers", id, id+"-json.log") - - if _, err := os.Stat(logPath); err != nil { - c.Fatal(err) - } - f, err := os.Open(logPath) - if err != nil { - c.Fatal(err) - } - defer f.Close() - - var res struct { - Log string `json:"log"` - Stream string `json:"stream"` - Time time.Time `json:"time"` - } - if err := json.NewDecoder(f).Decode(&res); err != nil { - c.Fatal(err) - } - if res.Log != "testline\n" { - c.Fatalf("Unexpected log line: %q, expected: %q", res.Log, "testline\n") - } - if res.Stream != "stdout" { - c.Fatalf("Unexpected stream: %q, expected: %q", res.Stream, "stdout") - } - if !time.Now().After(res.Time) { - c.Fatalf("Log time %v in future", res.Time) - } -} - -func (s *DockerDaemonSuite) TestDaemonLoggingDriverDefaultOverride(c *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - c.Fatal(err) - } - - out, err := s.d.Cmd("run", "--name=test", "--log-driver=none", "busybox", "echo", "testline") - if err != nil { - c.Fatal(out, err) - } - id, err := s.d.getIDByName("test") - c.Assert(err, check.IsNil) - - logPath := filepath.Join(s.d.root, "containers", id, id+"-json.log") - - if _, err := os.Stat(logPath); err == nil || !os.IsNotExist(err) { - c.Fatalf("%s shouldn't exits, error on Stat: %s", logPath, err) - } -} - -func (s *DockerDaemonSuite) TestDaemonLoggingDriverNone(c *check.C) { - if err := s.d.StartWithBusybox("--log-driver=none"); err != nil { - c.Fatal(err) - } - - out, err := s.d.Cmd("run", "--name=test", "busybox", "echo", "testline") - if err != nil { - c.Fatal(out, err) - } - id, err := s.d.getIDByName("test") - c.Assert(err, check.IsNil) - - logPath := filepath.Join(s.d.folder, "graph", "containers", id, id+"-json.log") - - if _, err := os.Stat(logPath); err == nil || !os.IsNotExist(err) { - c.Fatalf("%s shouldn't exits, error on Stat: %s", logPath, err) - } -} - -func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneOverride(c *check.C) { - if err := s.d.StartWithBusybox("--log-driver=none"); err != nil { - c.Fatal(err) - } - - out, err := s.d.Cmd("run", "--name=test", "--log-driver=json-file", "busybox", "echo", "testline") - if err != nil { - c.Fatal(out, err) - } - id, err := s.d.getIDByName("test") - c.Assert(err, check.IsNil) - - logPath := filepath.Join(s.d.root, "containers", id, id+"-json.log") - - if _, err := os.Stat(logPath); err != nil { - c.Fatal(err) - } - f, err := os.Open(logPath) - if err != nil { - c.Fatal(err) - } - defer f.Close() - - var res struct { - Log string `json:"log"` - Stream string `json:"stream"` - Time time.Time `json:"time"` - } - if err := json.NewDecoder(f).Decode(&res); err != nil { - c.Fatal(err) - } - if res.Log != "testline\n" { - c.Fatalf("Unexpected log line: %q, expected: %q", res.Log, "testline\n") - } - if res.Stream != "stdout" { - c.Fatalf("Unexpected stream: %q, expected: %q", res.Stream, "stdout") - } - if !time.Now().After(res.Time) { - c.Fatalf("Log time %v in future", res.Time) - } -} - -func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneLogsError(c *check.C) { - c.Assert(s.d.StartWithBusybox("--log-driver=none"), checker.IsNil) - - out, err := s.d.Cmd("run", "--name=test", "busybox", "echo", "testline") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("logs", "test") - c.Assert(err, check.NotNil, check.Commentf("Logs should fail with 'none' driver")) - expected := `"logs" command is supported only for "json-file" and "journald" logging drivers (got: none)` - c.Assert(out, checker.Contains, expected) -} - -func (s *DockerDaemonSuite) TestDaemonUnixSockCleanedUp(c *check.C) { - dir, err := ioutil.TempDir("", "socket-cleanup-test") - if err != nil { - c.Fatal(err) - } - defer os.RemoveAll(dir) - - sockPath := filepath.Join(dir, "docker.sock") - if err := s.d.Start("--host", "unix://"+sockPath); err != nil { - c.Fatal(err) - } - - if _, err := os.Stat(sockPath); err != nil { - c.Fatal("socket does not exist") - } - - if err := s.d.Stop(); err != nil { - c.Fatal(err) - } - - if _, err := os.Stat(sockPath); err == nil || !os.IsNotExist(err) { - c.Fatal("unix socket is not cleaned up") - } -} - -func (s *DockerDaemonSuite) TestDaemonWithWrongkey(c *check.C) { - type Config struct { - Crv string `json:"crv"` - D string `json:"d"` - Kid string `json:"kid"` - Kty string `json:"kty"` - X string `json:"x"` - Y string `json:"y"` - } - - os.Remove("/etc/docker/key.json") - if err := s.d.Start(); err != nil { - c.Fatalf("Failed to start daemon: %v", err) - } - - if err := s.d.Stop(); err != nil { - c.Fatalf("Could not stop daemon: %v", err) - } - - config := &Config{} - bytes, err := ioutil.ReadFile("/etc/docker/key.json") - if err != nil { - c.Fatalf("Error reading key.json file: %s", err) - } - - // byte[] to Data-Struct - if err := json.Unmarshal(bytes, &config); err != nil { - c.Fatalf("Error Unmarshal: %s", err) - } - - //replace config.Kid with the fake value - config.Kid = "VSAJ:FUYR:X3H2:B2VZ:KZ6U:CJD5:K7BX:ZXHY:UZXT:P4FT:MJWG:HRJ4" - - // NEW Data-Struct to byte[] - newBytes, err := json.Marshal(&config) - if err != nil { - c.Fatalf("Error Marshal: %s", err) - } - - // write back - if err := ioutil.WriteFile("/etc/docker/key.json", newBytes, 0400); err != nil { - c.Fatalf("Error ioutil.WriteFile: %s", err) - } - - defer os.Remove("/etc/docker/key.json") - - if err := s.d.Start(); err == nil { - c.Fatalf("It should not be successful to start daemon with wrong key: %v", err) - } - - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - - if !strings.Contains(string(content), "Public Key ID does not match") { - c.Fatalf("Missing KeyID message from daemon logs: %s", string(content)) - } -} - -func (s *DockerDaemonSuite) TestDaemonRestartKillWait(c *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - c.Fatalf("Could not start daemon with busybox: %v", err) - } - - out, err := s.d.Cmd("run", "-id", "busybox", "/bin/cat") - if err != nil { - c.Fatalf("Could not run /bin/cat: err=%v\n%s", err, out) - } - containerID := strings.TrimSpace(out) - - if out, err := s.d.Cmd("kill", containerID); err != nil { - c.Fatalf("Could not kill %s: err=%v\n%s", containerID, err, out) - } - - if err := s.d.Restart(); err != nil { - c.Fatalf("Could not restart daemon: %v", err) - } - - errchan := make(chan error) - go func() { - if out, err := s.d.Cmd("wait", containerID); err != nil { - errchan <- fmt.Errorf("%v:\n%s", err, out) - } - close(errchan) - }() - - select { - case <-time.After(5 * time.Second): - c.Fatal("Waiting on a stopped (killed) container timed out") - case err := <-errchan: - if err != nil { - c.Fatal(err) - } - } -} - -// TestHTTPSInfo connects via two-way authenticated HTTPS to the info endpoint -func (s *DockerDaemonSuite) TestHTTPSInfo(c *check.C) { - const ( - testDaemonHTTPSAddr = "tcp://localhost:4271" - ) - - if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem", - "--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr); err != nil { - c.Fatalf("Could not start daemon with busybox: %v", err) - } - - args := []string{ - "--host", testDaemonHTTPSAddr, - "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", - "--tlscert", "fixtures/https/client-cert.pem", - "--tlskey", "fixtures/https/client-key.pem", - "info", - } - out, err := s.d.Cmd(args...) - if err != nil { - c.Fatalf("Error Occurred: %s and output: %s", err, out) - } -} - -// TestHTTPSRun connects via two-way authenticated HTTPS to the create, attach, start, and wait endpoints. -// https://github.com/docker/docker/issues/19280 -func (s *DockerDaemonSuite) TestHTTPSRun(c *check.C) { - const ( - testDaemonHTTPSAddr = "tcp://localhost:4271" - ) - - if err := s.d.StartWithBusybox("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem", - "--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr); err != nil { - c.Fatalf("Could not start daemon with busybox: %v", err) - } - - args := []string{ - "--host", testDaemonHTTPSAddr, - "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", - "--tlscert", "fixtures/https/client-cert.pem", - "--tlskey", "fixtures/https/client-key.pem", - "run", "busybox", "echo", "TLS response", - } - out, err := s.d.Cmd(args...) - if err != nil { - c.Fatalf("Error Occurred: %s and output: %s", err, out) - } - - if !strings.Contains(out, "TLS response") { - c.Fatalf("expected output to include `TLS response`, got %v", out) - } -} - -// TestTLSVerify verifies that --tlsverify=false turns on tls -func (s *DockerDaemonSuite) TestTLSVerify(c *check.C) { - out, err := exec.Command(dockerdBinary, "--tlsverify=false").CombinedOutput() - if err == nil || !strings.Contains(string(out), "Could not load X509 key pair") { - c.Fatalf("Daemon should not have started due to missing certs: %v\n%s", err, string(out)) - } -} - -// TestHTTPSInfoRogueCert connects via two-way authenticated HTTPS to the info endpoint -// by using a rogue client certificate and checks that it fails with the expected error. -func (s *DockerDaemonSuite) TestHTTPSInfoRogueCert(c *check.C) { - const ( - errBadCertificate = "bad certificate" - testDaemonHTTPSAddr = "tcp://localhost:4271" - ) - - if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem", - "--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr); err != nil { - c.Fatalf("Could not start daemon with busybox: %v", err) - } - - args := []string{ - "--host", testDaemonHTTPSAddr, - "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", - "--tlscert", "fixtures/https/client-rogue-cert.pem", - "--tlskey", "fixtures/https/client-rogue-key.pem", - "info", - } - out, err := s.d.Cmd(args...) - if err == nil || !strings.Contains(out, errBadCertificate) { - c.Fatalf("Expected err: %s, got instead: %s and output: %s", errBadCertificate, err, out) - } -} - -// TestHTTPSInfoRogueServerCert connects via two-way authenticated HTTPS to the info endpoint -// which provides a rogue server certificate and checks that it fails with the expected error -func (s *DockerDaemonSuite) TestHTTPSInfoRogueServerCert(c *check.C) { - const ( - errCaUnknown = "x509: certificate signed by unknown authority" - testDaemonRogueHTTPSAddr = "tcp://localhost:4272" - ) - if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-rogue-cert.pem", - "--tlskey", "fixtures/https/server-rogue-key.pem", "-H", testDaemonRogueHTTPSAddr); err != nil { - c.Fatalf("Could not start daemon with busybox: %v", err) - } - - args := []string{ - "--host", testDaemonRogueHTTPSAddr, - "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", - "--tlscert", "fixtures/https/client-rogue-cert.pem", - "--tlskey", "fixtures/https/client-rogue-key.pem", - "info", - } - out, err := s.d.Cmd(args...) - if err == nil || !strings.Contains(out, errCaUnknown) { - c.Fatalf("Expected err: %s, got instead: %s and output: %s", errCaUnknown, err, out) - } -} - -func pingContainers(c *check.C, d *Daemon, expectFailure bool) { - var dargs []string - if d != nil { - dargs = []string{"--host", d.sock()} - } - - args := append(dargs, "run", "-d", "--name", "container1", "busybox", "top") - dockerCmd(c, args...) - - args = append(dargs, "run", "--rm", "--link", "container1:alias1", "busybox", "sh", "-c") - pingCmd := "ping -c 1 %s -W 1" - args = append(args, fmt.Sprintf(pingCmd, "alias1")) - _, _, err := dockerCmdWithError(args...) - - if expectFailure { - c.Assert(err, check.NotNil) - } else { - c.Assert(err, check.IsNil) - } - - args = append(dargs, "rm", "-f", "container1") - dockerCmd(c, args...) -} - -func (s *DockerDaemonSuite) TestDaemonRestartWithSocketAsVolume(c *check.C) { - c.Assert(s.d.StartWithBusybox(), check.IsNil) - - socket := filepath.Join(s.d.folder, "docker.sock") - - out, err := s.d.Cmd("run", "--restart=always", "-v", socket+":/sock", "busybox") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - c.Assert(s.d.Restart(), check.IsNil) -} - -// os.Kill should kill daemon ungracefully, leaving behind container mounts. -// A subsequent daemon restart shoud clean up said mounts. -func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonAndContainerKill(c *check.C) { - c.Assert(s.d.StartWithBusybox(), check.IsNil) - - out, err := s.d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - id := strings.TrimSpace(out) - c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil) - mountOut, err := ioutil.ReadFile("/proc/self/mountinfo") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) - - // container mounts should exist even after daemon has crashed. - comment := check.Commentf("%s should stay mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut) - c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment) - - // kill the container - runCmd := exec.Command(ctrBinary, "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", "containers", "kill", id) - if out, ec, err := runCommandWithOutput(runCmd); err != nil { - c.Fatalf("Failed to run ctr, ExitCode: %d, err: %v output: %s id: %s\n", ec, err, out, id) - } - - // restart daemon. - if err := s.d.Restart(); err != nil { - c.Fatal(err) - } - - // Now, container mounts should be gone. - mountOut, err = ioutil.ReadFile("/proc/self/mountinfo") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) - comment = check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut) - c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment) -} - -// os.Interrupt should perform a graceful daemon shutdown and hence cleanup mounts. -func (s *DockerDaemonSuite) TestCleanupMountsAfterGracefulShutdown(c *check.C) { - c.Assert(s.d.StartWithBusybox(), check.IsNil) - - out, err := s.d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - id := strings.TrimSpace(out) - - // Send SIGINT and daemon should clean up - c.Assert(s.d.cmd.Process.Signal(os.Interrupt), check.IsNil) - // Wait for the daemon to stop. - c.Assert(<-s.d.wait, checker.IsNil) - - mountOut, err := ioutil.ReadFile("/proc/self/mountinfo") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) - - comment := check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut) - c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment) -} - -func (s *DockerDaemonSuite) TestRunContainerWithBridgeNone(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - c.Assert(s.d.StartWithBusybox("-b", "none"), check.IsNil) - - out, err := s.d.Cmd("run", "--rm", "busybox", "ip", "l") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - c.Assert(strings.Contains(out, "eth0"), check.Equals, false, - check.Commentf("There shouldn't be eth0 in container in default(bridge) mode when bridge network is disabled: %s", out)) - - out, err = s.d.Cmd("run", "--rm", "--net=bridge", "busybox", "ip", "l") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - c.Assert(strings.Contains(out, "eth0"), check.Equals, false, - check.Commentf("There shouldn't be eth0 in container in bridge mode when bridge network is disabled: %s", out)) - // the extra grep and awk clean up the output of `ip` to only list the number and name of - // interfaces, allowing for different versions of ip (e.g. inside and outside the container) to - // be used while still verifying that the interface list is the exact same - cmd := exec.Command("sh", "-c", "ip l | grep -E '^[0-9]+:' | awk -F: ' { print $1\":\"$2 } '") - stdout := bytes.NewBuffer(nil) - cmd.Stdout = stdout - if err := cmd.Run(); err != nil { - c.Fatal("Failed to get host network interface") - } - out, err = s.d.Cmd("run", "--rm", "--net=host", "busybox", "sh", "-c", "ip l | grep -E '^[0-9]+:' | awk -F: ' { print $1\":\"$2 } '") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - c.Assert(out, check.Equals, fmt.Sprintf("%s", stdout), - check.Commentf("The network interfaces in container should be the same with host when --net=host when bridge network is disabled: %s", out)) -} - -func (s *DockerDaemonSuite) TestDaemonRestartWithContainerRunning(t *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - t.Fatal(err) - } - if out, err := s.d.Cmd("run", "-d", "--name", "test", "busybox", "top"); err != nil { - t.Fatal(out, err) - } - - if err := s.d.Restart(); err != nil { - t.Fatal(err) - } - // Container 'test' should be removed without error - if out, err := s.d.Cmd("rm", "test"); err != nil { - t.Fatal(out, err) - } -} - -func (s *DockerDaemonSuite) TestDaemonRestartCleanupNetns(c *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - c.Fatal(err) - } - out, err := s.d.Cmd("run", "--name", "netns", "-d", "busybox", "top") - if err != nil { - c.Fatal(out, err) - } - - // Get sandbox key via inspect - out, err = s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.SandboxKey}}'", "netns") - if err != nil { - c.Fatalf("Error inspecting container: %s, %v", out, err) - } - fileName := strings.Trim(out, " \r\n'") - - if out, err := s.d.Cmd("stop", "netns"); err != nil { - c.Fatal(out, err) - } - - // Test if the file still exists - out, _, err = runCommandWithOutput(exec.Command("stat", "-c", "%n", fileName)) - out = strings.TrimSpace(out) - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - c.Assert(out, check.Equals, fileName, check.Commentf("Output: %s", out)) - - // Remove the container and restart the daemon - if out, err := s.d.Cmd("rm", "netns"); err != nil { - c.Fatal(out, err) - } - - if err := s.d.Restart(); err != nil { - c.Fatal(err) - } - - // Test again and see now the netns file does not exist - out, _, err = runCommandWithOutput(exec.Command("stat", "-c", "%n", fileName)) - out = strings.TrimSpace(out) - c.Assert(err, check.Not(check.IsNil), check.Commentf("Output: %s", out)) -} - -// tests regression detailed in #13964 where DOCKER_TLS_VERIFY env is ignored -func (s *DockerDaemonSuite) TestDaemonTLSVerifyIssue13964(c *check.C) { - host := "tcp://localhost:4271" - c.Assert(s.d.Start("-H", host), check.IsNil) - cmd := exec.Command(dockerBinary, "-H", host, "info") - cmd.Env = []string{"DOCKER_TLS_VERIFY=1", "DOCKER_CERT_PATH=fixtures/https"} - out, _, err := runCommandWithOutput(cmd) - c.Assert(err, check.Not(check.IsNil), check.Commentf("%s", out)) - c.Assert(strings.Contains(out, "error during connect"), check.Equals, true) - -} - -func setupV6(c *check.C) { - // Hack to get the right IPv6 address on docker0, which has already been created - result := icmd.RunCommand("ip", "addr", "add", "fe80::1/64", "dev", "docker0") - result.Assert(c, icmd.Expected{}) -} - -func teardownV6(c *check.C) { - result := icmd.RunCommand("ip", "addr", "del", "fe80::1/64", "dev", "docker0") - result.Assert(c, icmd.Expected{}) -} - -func (s *DockerDaemonSuite) TestDaemonRestartWithContainerWithRestartPolicyAlways(c *check.C) { - c.Assert(s.d.StartWithBusybox(), check.IsNil) - - out, err := s.d.Cmd("run", "-d", "--restart", "always", "busybox", "top") - c.Assert(err, check.IsNil) - id := strings.TrimSpace(out) - - _, err = s.d.Cmd("stop", id) - c.Assert(err, check.IsNil) - _, err = s.d.Cmd("wait", id) - c.Assert(err, check.IsNil) - - out, err = s.d.Cmd("ps", "-q") - c.Assert(err, check.IsNil) - c.Assert(out, check.Equals, "") - - c.Assert(s.d.Restart(), check.IsNil) - - out, err = s.d.Cmd("ps", "-q") - c.Assert(err, check.IsNil) - c.Assert(strings.TrimSpace(out), check.Equals, id[:12]) -} - -func (s *DockerDaemonSuite) TestDaemonWideLogConfig(c *check.C) { - if err := s.d.StartWithBusybox("--log-opt=max-size=1k"); err != nil { - c.Fatal(err) - } - name := "logtest" - out, err := s.d.Cmd("run", "-d", "--log-opt=max-file=5", "--name", name, "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf("Output: %s, err: %v", out, err)) - - out, err = s.d.Cmd("inspect", "-f", "{{ .HostConfig.LogConfig.Config }}", name) - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - c.Assert(out, checker.Contains, "max-size:1k") - c.Assert(out, checker.Contains, "max-file:5") - - out, err = s.d.Cmd("inspect", "-f", "{{ .HostConfig.LogConfig.Type }}", name) - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - c.Assert(strings.TrimSpace(out), checker.Equals, "json-file") -} - -func (s *DockerDaemonSuite) TestDaemonRestartWithPausedContainer(c *check.C) { - if err := s.d.StartWithBusybox(); err != nil { - c.Fatal(err) - } - if out, err := s.d.Cmd("run", "-i", "-d", "--name", "test", "busybox", "top"); err != nil { - c.Fatal(err, out) - } - if out, err := s.d.Cmd("pause", "test"); err != nil { - c.Fatal(err, out) - } - if err := s.d.Restart(); err != nil { - c.Fatal(err) - } - - errchan := make(chan error) - go func() { - out, err := s.d.Cmd("start", "test") - if err != nil { - errchan <- fmt.Errorf("%v:\n%s", err, out) - } - name := strings.TrimSpace(out) - if name != "test" { - errchan <- fmt.Errorf("Paused container start error on docker daemon restart, expected 'test' but got '%s'", name) - } - close(errchan) - }() - - select { - case <-time.After(5 * time.Second): - c.Fatal("Waiting on start a container timed out") - case err := <-errchan: - if err != nil { - c.Fatal(err) - } - } -} - -func (s *DockerDaemonSuite) TestDaemonRestartRmVolumeInUse(c *check.C) { - c.Assert(s.d.StartWithBusybox(), check.IsNil) - - out, err := s.d.Cmd("create", "-v", "test:/foo", "busybox") - c.Assert(err, check.IsNil, check.Commentf(out)) - - c.Assert(s.d.Restart(), check.IsNil) - - out, err = s.d.Cmd("volume", "rm", "test") - c.Assert(err, check.NotNil, check.Commentf("should not be able to remove in use volume after daemon restart")) - c.Assert(out, checker.Contains, "in use") -} - -func (s *DockerDaemonSuite) TestDaemonRestartLocalVolumes(c *check.C) { - c.Assert(s.d.Start(), check.IsNil) - - _, err := s.d.Cmd("volume", "create", "test") - c.Assert(err, check.IsNil) - c.Assert(s.d.Restart(), check.IsNil) - - _, err = s.d.Cmd("volume", "inspect", "test") - c.Assert(err, check.IsNil) -} - -func (s *DockerDaemonSuite) TestDaemonCorruptedLogDriverAddress(c *check.C) { - c.Assert(s.d.Start("--log-driver=syslog", "--log-opt", "syslog-address=corrupted:42"), check.NotNil) - expected := "Failed to set log opts: syslog-address should be in form proto://address" - runCmd := exec.Command("grep", expected, s.d.LogFileName()) - if out, _, err := runCommandWithOutput(runCmd); err != nil { - c.Fatalf("Expected %q message; but doesn't exist in log: %q, err: %v", expected, out, err) - } -} - -func (s *DockerDaemonSuite) TestDaemonCorruptedFluentdAddress(c *check.C) { - c.Assert(s.d.Start("--log-driver=fluentd", "--log-opt", "fluentd-address=corrupted:c"), check.NotNil) - expected := "Failed to set log opts: invalid fluentd-address corrupted:c: " - runCmd := exec.Command("grep", expected, s.d.LogFileName()) - if out, _, err := runCommandWithOutput(runCmd); err != nil { - c.Fatalf("Expected %q message; but doesn't exist in log: %q, err: %v", expected, out, err) - } -} - -func (s *DockerDaemonSuite) TestDaemonStartWithoutHost(c *check.C) { - s.d.useDefaultHost = true - defer func() { - s.d.useDefaultHost = false - }() - c.Assert(s.d.Start(), check.IsNil) -} - -func (s *DockerDaemonSuite) TestDaemonStartWithDefalutTLSHost(c *check.C) { - s.d.useDefaultTLSHost = true - defer func() { - s.d.useDefaultTLSHost = false - }() - if err := s.d.Start( - "--tlsverify", - "--tlscacert", "fixtures/https/ca.pem", - "--tlscert", "fixtures/https/server-cert.pem", - "--tlskey", "fixtures/https/server-key.pem"); err != nil { - c.Fatalf("Could not start daemon: %v", err) - } - - // The client with --tlsverify should also use default host localhost:2376 - tmpHost := os.Getenv("DOCKER_HOST") - defer func() { - os.Setenv("DOCKER_HOST", tmpHost) - }() - - os.Setenv("DOCKER_HOST", "") - - out, _ := dockerCmd( - c, - "--tlsverify", - "--tlscacert", "fixtures/https/ca.pem", - "--tlscert", "fixtures/https/client-cert.pem", - "--tlskey", "fixtures/https/client-key.pem", - "version", - ) - if !strings.Contains(out, "Server") { - c.Fatalf("docker version should return information of server side") - } -} - -func (s *DockerDaemonSuite) TestBridgeIPIsExcludedFromAllocatorPool(c *check.C) { - defaultNetworkBridge := "docker0" - deleteInterface(c, defaultNetworkBridge) - - bridgeIP := "192.169.1.1" - bridgeRange := bridgeIP + "/30" - - err := s.d.StartWithBusybox("--bip", bridgeRange) - c.Assert(err, check.IsNil) - defer s.d.Restart() - - var cont int - for { - contName := fmt.Sprintf("container%d", cont) - _, err = s.d.Cmd("run", "--name", contName, "-d", "busybox", "/bin/sleep", "2") - if err != nil { - // pool exhausted - break - } - ip, err := s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.IPAddress}}'", contName) - c.Assert(err, check.IsNil) - - c.Assert(ip, check.Not(check.Equals), bridgeIP) - cont++ - } -} - -// Test daemon for no space left on device error -func (s *DockerDaemonSuite) TestDaemonNoSpaceLeftOnDeviceError(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux, Network) - - testDir, err := ioutil.TempDir("", "no-space-left-on-device-test") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(testDir) - c.Assert(mount.MakeRShared(testDir), checker.IsNil) - defer mount.Unmount(testDir) - - // create a 2MiB image and mount it as graph root - // Why in a container? Because `mount` sometimes behaves weirdly and often fails outright on this test in debian:jessie (which is what the test suite runs under if run from the Makefile) - dockerCmd(c, "run", "--rm", "-v", testDir+":/test", "busybox", "sh", "-c", "dd of=/test/testfs.img bs=1M seek=2 count=0") - out, _, err := runCommandWithOutput(exec.Command("mkfs.ext4", "-F", filepath.Join(testDir, "testfs.img"))) // `mkfs.ext4` is not in busybox - c.Assert(err, checker.IsNil, check.Commentf(out)) - - cmd := exec.Command("losetup", "-f", "--show", filepath.Join(testDir, "testfs.img")) - loout, err := cmd.CombinedOutput() - c.Assert(err, checker.IsNil) - loopname := strings.TrimSpace(string(loout)) - defer exec.Command("losetup", "-d", loopname).Run() - - dockerCmd(c, "run", "--privileged", "--rm", "-v", testDir+":/test:shared", "busybox", "sh", "-c", fmt.Sprintf("mkdir -p /test/test-mount && mount -t ext4 -no loop,rw %v /test/test-mount", loopname)) - defer mount.Unmount(filepath.Join(testDir, "test-mount")) - - err = s.d.Start("--graph", filepath.Join(testDir, "test-mount")) - defer s.d.Stop() - c.Assert(err, check.IsNil) - - // pull a repository large enough to fill the mount point - pullOut, err := s.d.Cmd("pull", "registry:2") - c.Assert(err, checker.NotNil, check.Commentf(pullOut)) - c.Assert(pullOut, checker.Contains, "no space left on device") -} - -// Test daemon restart with container links + auto restart -func (s *DockerDaemonSuite) TestDaemonRestartContainerLinksRestart(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - parent1Args := []string{} - parent2Args := []string{} - wg := sync.WaitGroup{} - maxChildren := 10 - chErr := make(chan error, maxChildren) - - for i := 0; i < maxChildren; i++ { - wg.Add(1) - name := fmt.Sprintf("test%d", i) - - if i < maxChildren/2 { - parent1Args = append(parent1Args, []string{"--link", name}...) - } else { - parent2Args = append(parent2Args, []string{"--link", name}...) - } - - go func() { - _, err = s.d.Cmd("run", "-d", "--name", name, "--restart=always", "busybox", "top") - chErr <- err - wg.Done() - }() - } - - wg.Wait() - close(chErr) - for err := range chErr { - c.Assert(err, check.IsNil) - } - - parent1Args = append([]string{"run", "-d"}, parent1Args...) - parent1Args = append(parent1Args, []string{"--name=parent1", "--restart=always", "busybox", "top"}...) - parent2Args = append([]string{"run", "-d"}, parent2Args...) - parent2Args = append(parent2Args, []string{"--name=parent2", "--restart=always", "busybox", "top"}...) - - _, err = s.d.Cmd(parent1Args...) - c.Assert(err, check.IsNil) - _, err = s.d.Cmd(parent2Args...) - c.Assert(err, check.IsNil) - - err = s.d.Stop() - c.Assert(err, check.IsNil) - // clear the log file -- we don't need any of it but may for the next part - // can ignore the error here, this is just a cleanup - os.Truncate(s.d.LogFileName(), 0) - err = s.d.Start() - c.Assert(err, check.IsNil) - - for _, num := range []string{"1", "2"} { - out, err := s.d.Cmd("inspect", "-f", "{{ .State.Running }}", "parent"+num) - c.Assert(err, check.IsNil) - if strings.TrimSpace(out) != "true" { - log, _ := ioutil.ReadFile(s.d.LogFileName()) - c.Fatalf("parent container is not running\n%s", string(log)) - } - } -} - -func (s *DockerDaemonSuite) TestDaemonCgroupParent(c *check.C) { - testRequires(c, DaemonIsLinux) - - cgroupParent := "test" - name := "cgroup-test" - - err := s.d.StartWithBusybox("--cgroup-parent", cgroupParent) - c.Assert(err, check.IsNil) - defer s.d.Restart() - - out, err := s.d.Cmd("run", "--name", name, "busybox", "cat", "/proc/self/cgroup") - c.Assert(err, checker.IsNil) - cgroupPaths := parseCgroupPaths(string(out)) - c.Assert(len(cgroupPaths), checker.Not(checker.Equals), 0, check.Commentf("unexpected output - %q", string(out))) - out, err = s.d.Cmd("inspect", "-f", "{{.Id}}", name) - c.Assert(err, checker.IsNil) - id := strings.TrimSpace(string(out)) - expectedCgroup := path.Join(cgroupParent, id) - found := false - for _, path := range cgroupPaths { - if strings.HasSuffix(path, expectedCgroup) { - found = true - break - } - } - c.Assert(found, checker.True, check.Commentf("Cgroup path for container (%s) doesn't found in cgroups file: %s", expectedCgroup, cgroupPaths)) -} - -func (s *DockerDaemonSuite) TestDaemonRestartWithLinks(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support links - err := s.d.StartWithBusybox() - c.Assert(err, check.IsNil) - - out, err := s.d.Cmd("run", "-d", "--name=test", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("run", "--name=test2", "--link", "test:abc", "busybox", "sh", "-c", "ping -c 1 -w 1 abc") - c.Assert(err, check.IsNil, check.Commentf(out)) - - c.Assert(s.d.Restart(), check.IsNil) - - // should fail since test is not running yet - out, err = s.d.Cmd("start", "test2") - c.Assert(err, check.NotNil, check.Commentf(out)) - - out, err = s.d.Cmd("start", "test") - c.Assert(err, check.IsNil, check.Commentf(out)) - out, err = s.d.Cmd("start", "-a", "test2") - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(strings.Contains(out, "1 packets transmitted, 1 packets received"), check.Equals, true, check.Commentf(out)) -} - -func (s *DockerDaemonSuite) TestDaemonRestartWithNames(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support links - err := s.d.StartWithBusybox() - c.Assert(err, check.IsNil) - - out, err := s.d.Cmd("create", "--name=test", "busybox") - c.Assert(err, check.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("run", "-d", "--name=test2", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf(out)) - test2ID := strings.TrimSpace(out) - - out, err = s.d.Cmd("run", "-d", "--name=test3", "--link", "test2:abc", "busybox", "top") - test3ID := strings.TrimSpace(out) - - c.Assert(s.d.Restart(), check.IsNil) - - out, err = s.d.Cmd("create", "--name=test", "busybox") - c.Assert(err, check.NotNil, check.Commentf("expected error trying to create container with duplicate name")) - // this one is no longer needed, removing simplifies the remainder of the test - out, err = s.d.Cmd("rm", "-f", "test") - c.Assert(err, check.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("ps", "-a", "--no-trunc") - c.Assert(err, check.IsNil, check.Commentf(out)) - - lines := strings.Split(strings.TrimSpace(out), "\n")[1:] - - test2validated := false - test3validated := false - for _, line := range lines { - fields := strings.Fields(line) - names := fields[len(fields)-1] - switch fields[0] { - case test2ID: - c.Assert(names, check.Equals, "test2,test3/abc") - test2validated = true - case test3ID: - c.Assert(names, check.Equals, "test3") - test3validated = true - } - } - - c.Assert(test2validated, check.Equals, true) - c.Assert(test3validated, check.Equals, true) -} - -// TestDaemonRestartWithKilledRunningContainer requires live restore of running containers -func (s *DockerDaemonSuite) TestDaemonRestartWithKilledRunningContainer(t *check.C) { - // TODO(mlaventure): Not sure what would the exit code be on windows - testRequires(t, DaemonIsLinux) - if err := s.d.StartWithBusybox(); err != nil { - t.Fatal(err) - } - - cid, err := s.d.Cmd("run", "-d", "--name", "test", "busybox", "top") - defer s.d.Stop() - if err != nil { - t.Fatal(cid, err) - } - cid = strings.TrimSpace(cid) - - pid, err := s.d.Cmd("inspect", "-f", "{{.State.Pid}}", cid) - t.Assert(err, check.IsNil) - pid = strings.TrimSpace(pid) - - // Kill the daemon - if err := s.d.Kill(); err != nil { - t.Fatal(err) - } - - // kill the container - runCmd := exec.Command(ctrBinary, "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", "containers", "kill", cid) - if out, ec, err := runCommandWithOutput(runCmd); err != nil { - t.Fatalf("Failed to run ctr, ExitCode: %d, err: '%v' output: '%s' cid: '%s'\n", ec, err, out, cid) - } - - // Give time to containerd to process the command if we don't - // the exit event might be received after we do the inspect - pidCmd := exec.Command("kill", "-0", pid) - _, ec, _ := runCommandWithOutput(pidCmd) - for ec == 0 { - time.Sleep(1 * time.Second) - _, ec, _ = runCommandWithOutput(pidCmd) - } - - // restart the daemon - if err := s.d.Start(); err != nil { - t.Fatal(err) - } - - // Check that we've got the correct exit code - out, err := s.d.Cmd("inspect", "-f", "{{.State.ExitCode}}", cid) - t.Assert(err, check.IsNil) - - out = strings.TrimSpace(out) - if out != "143" { - t.Fatalf("Expected exit code '%s' got '%s' for container '%s'\n", "143", out, cid) - } - -} - -// os.Kill should kill daemon ungracefully, leaving behind live containers. -// The live containers should be known to the restarted daemon. Stopping -// them now, should remove the mounts. -func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) { - testRequires(c, DaemonIsLinux) - c.Assert(s.d.StartWithBusybox("--live-restore"), check.IsNil) - - out, err := s.d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - id := strings.TrimSpace(out) - - c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil) - mountOut, err := ioutil.ReadFile("/proc/self/mountinfo") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) - - // container mounts should exist even after daemon has crashed. - comment := check.Commentf("%s should stay mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut) - c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment) - - // restart daemon. - if err := s.d.Restart("--live-restore"); err != nil { - c.Fatal(err) - } - - // container should be running. - out, err = s.d.Cmd("inspect", "--format={{.State.Running}}", id) - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - out = strings.TrimSpace(out) - if out != "true" { - c.Fatalf("Container %s expected to stay alive after daemon restart", id) - } - - // 'docker stop' should work. - out, err = s.d.Cmd("stop", id) - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - - // Now, container mounts should be gone. - mountOut, err = ioutil.ReadFile("/proc/self/mountinfo") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) - comment = check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut) - c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment) -} - -// TestDaemonRestartWithUnpausedRunningContainer requires live restore of running containers. -func (s *DockerDaemonSuite) TestDaemonRestartWithUnpausedRunningContainer(t *check.C) { - // TODO(mlaventure): Not sure what would the exit code be on windows - testRequires(t, DaemonIsLinux) - if err := s.d.StartWithBusybox("--live-restore"); err != nil { - t.Fatal(err) - } - - cid, err := s.d.Cmd("run", "-d", "--name", "test", "busybox", "top") - defer s.d.Stop() - if err != nil { - t.Fatal(cid, err) - } - cid = strings.TrimSpace(cid) - - pid, err := s.d.Cmd("inspect", "-f", "{{.State.Pid}}", cid) - t.Assert(err, check.IsNil) - - // pause the container - if _, err := s.d.Cmd("pause", cid); err != nil { - t.Fatal(cid, err) - } - - // Kill the daemon - if err := s.d.Kill(); err != nil { - t.Fatal(err) - } - - // resume the container - result := icmd.RunCommand( - ctrBinary, - "--address", "unix:///var/run/docker/libcontainerd/docker-containerd.sock", - "containers", "resume", cid) - t.Assert(result, icmd.Matches, icmd.Success) - - // Give time to containerd to process the command if we don't - // the resume event might be received after we do the inspect - waitAndAssert(t, defaultReconciliationTimeout, func(*check.C) (interface{}, check.CommentInterface) { - result := icmd.RunCommand("kill", "-0", strings.TrimSpace(pid)) - return result.ExitCode, nil - }, checker.Equals, 0) - - // restart the daemon - if err := s.d.Start("--live-restore"); err != nil { - t.Fatal(err) - } - - // Check that we've got the correct status - out, err := s.d.Cmd("inspect", "-f", "{{.State.Status}}", cid) - t.Assert(err, check.IsNil) - - out = strings.TrimSpace(out) - if out != "running" { - t.Fatalf("Expected exit code '%s' got '%s' for container '%s'\n", "running", out, cid) - } - if _, err := s.d.Cmd("kill", cid); err != nil { - t.Fatal(err) - } -} - -// TestRunLinksChanged checks that creating a new container with the same name does not update links -// this ensures that the old, pre gh#16032 functionality continues on -func (s *DockerDaemonSuite) TestRunLinksChanged(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support links - err := s.d.StartWithBusybox() - c.Assert(err, check.IsNil) - - out, err := s.d.Cmd("run", "-d", "--name=test", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("run", "--name=test2", "--link=test:abc", "busybox", "sh", "-c", "ping -c 1 abc") - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "1 packets transmitted, 1 packets received") - - out, err = s.d.Cmd("rm", "-f", "test") - c.Assert(err, check.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("run", "-d", "--name=test", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf(out)) - out, err = s.d.Cmd("start", "-a", "test2") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, check.Not(checker.Contains), "1 packets transmitted, 1 packets received") - - err = s.d.Restart() - c.Assert(err, check.IsNil) - out, err = s.d.Cmd("start", "-a", "test2") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, check.Not(checker.Contains), "1 packets transmitted, 1 packets received") -} - -func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) { - testRequires(c, DaemonIsLinux, NotPpc64le) - - infoLog := "\x1b[34mINFO\x1b" - - p, tty, err := pty.Open() - c.Assert(err, checker.IsNil) - defer func() { - tty.Close() - p.Close() - }() - - b := bytes.NewBuffer(nil) - go io.Copy(b, p) - - // Enable coloring explicitly - s.d.StartWithLogFile(tty, "--raw-logs=false") - s.d.Stop() - c.Assert(b.String(), checker.Contains, infoLog) - - b.Reset() - - // Disable coloring explicitly - s.d.StartWithLogFile(tty, "--raw-logs=true") - s.d.Stop() - c.Assert(b.String(), check.Not(checker.Contains), infoLog) -} - -func (s *DockerDaemonSuite) TestDaemonDebugLog(c *check.C) { - testRequires(c, DaemonIsLinux, NotPpc64le) - - debugLog := "\x1b[37mDEBU\x1b" - - p, tty, err := pty.Open() - c.Assert(err, checker.IsNil) - defer func() { - tty.Close() - p.Close() - }() - - b := bytes.NewBuffer(nil) - go io.Copy(b, p) - - s.d.StartWithLogFile(tty, "--debug") - s.d.Stop() - c.Assert(b.String(), checker.Contains, debugLog) -} - -func (s *DockerDaemonSuite) TestDaemonDiscoveryBackendConfigReload(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - // daemon config file - daemonConfig := `{ "debug" : false }` - configFile, err := ioutil.TempFile("", "test-daemon-discovery-backend-config-reload-config") - c.Assert(err, checker.IsNil, check.Commentf("could not create temp file for config reload")) - configFilePath := configFile.Name() - defer func() { - configFile.Close() - os.RemoveAll(configFile.Name()) - }() - - _, err = configFile.Write([]byte(daemonConfig)) - c.Assert(err, checker.IsNil) - - // --log-level needs to be set so that d.Start() doesn't add --debug causing - // a conflict with the config - err = s.d.Start("--config-file", configFilePath, "--log-level=info") - c.Assert(err, checker.IsNil) - - // daemon config file - daemonConfig = `{ - "cluster-store": "consul://consuladdr:consulport/some/path", - "cluster-advertise": "192.168.56.100:0", - "debug" : false - }` - - err = configFile.Truncate(0) - c.Assert(err, checker.IsNil) - _, err = configFile.Seek(0, os.SEEK_SET) - c.Assert(err, checker.IsNil) - - _, err = configFile.Write([]byte(daemonConfig)) - c.Assert(err, checker.IsNil) - - err = s.d.reloadConfig() - c.Assert(err, checker.IsNil, check.Commentf("error reloading daemon config")) - - out, err := s.d.Cmd("info") - c.Assert(err, checker.IsNil) - - c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: consul://consuladdr:consulport/some/path")) - c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: 192.168.56.100:0")) -} - -// Test for #21956 -func (s *DockerDaemonSuite) TestDaemonLogOptions(c *check.C) { - err := s.d.StartWithBusybox("--log-driver=syslog", "--log-opt=syslog-address=udp://127.0.0.1:514") - c.Assert(err, check.IsNil) - - out, err := s.d.Cmd("run", "-d", "--log-driver=json-file", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf(out)) - id := strings.TrimSpace(out) - - out, err = s.d.Cmd("inspect", "--format='{{.HostConfig.LogConfig}}'", id) - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "{json-file map[]}") -} - -// Test case for #20936, #22443 -func (s *DockerDaemonSuite) TestDaemonMaxConcurrency(c *check.C) { - c.Assert(s.d.Start("--max-concurrent-uploads=6", "--max-concurrent-downloads=8"), check.IsNil) - - expectedMaxConcurrentUploads := `level=debug msg="Max Concurrent Uploads: 6"` - expectedMaxConcurrentDownloads := `level=debug msg="Max Concurrent Downloads: 8"` - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads) -} - -// Test case for #20936, #22443 -func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFile(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - // daemon config file - configFilePath := "test.json" - configFile, err := os.Create(configFilePath) - c.Assert(err, checker.IsNil) - defer os.Remove(configFilePath) - - daemonConfig := `{ "max-concurrent-downloads" : 8 }` - fmt.Fprintf(configFile, "%s", daemonConfig) - configFile.Close() - c.Assert(s.d.Start(fmt.Sprintf("--config-file=%s", configFilePath)), check.IsNil) - - expectedMaxConcurrentUploads := `level=debug msg="Max Concurrent Uploads: 5"` - expectedMaxConcurrentDownloads := `level=debug msg="Max Concurrent Downloads: 8"` - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads) - - configFile, err = os.Create(configFilePath) - c.Assert(err, checker.IsNil) - daemonConfig = `{ "max-concurrent-uploads" : 7, "max-concurrent-downloads" : 9 }` - fmt.Fprintf(configFile, "%s", daemonConfig) - configFile.Close() - - syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGHUP) - - time.Sleep(3 * time.Second) - - expectedMaxConcurrentUploads = `level=debug msg="Reset Max Concurrent Uploads: 7"` - expectedMaxConcurrentDownloads = `level=debug msg="Reset Max Concurrent Downloads: 9"` - content, _ = ioutil.ReadFile(s.d.logFile.Name()) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads) -} - -// Test case for #20936, #22443 -func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFileReload(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - // daemon config file - configFilePath := "test.json" - configFile, err := os.Create(configFilePath) - c.Assert(err, checker.IsNil) - defer os.Remove(configFilePath) - - daemonConfig := `{ "max-concurrent-uploads" : null }` - fmt.Fprintf(configFile, "%s", daemonConfig) - configFile.Close() - c.Assert(s.d.Start(fmt.Sprintf("--config-file=%s", configFilePath)), check.IsNil) - - expectedMaxConcurrentUploads := `level=debug msg="Max Concurrent Uploads: 5"` - expectedMaxConcurrentDownloads := `level=debug msg="Max Concurrent Downloads: 3"` - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads) - - configFile, err = os.Create(configFilePath) - c.Assert(err, checker.IsNil) - daemonConfig = `{ "max-concurrent-uploads" : 1, "max-concurrent-downloads" : null }` - fmt.Fprintf(configFile, "%s", daemonConfig) - configFile.Close() - - syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGHUP) - - time.Sleep(3 * time.Second) - - expectedMaxConcurrentUploads = `level=debug msg="Reset Max Concurrent Uploads: 1"` - expectedMaxConcurrentDownloads = `level=debug msg="Reset Max Concurrent Downloads: 3"` - content, _ = ioutil.ReadFile(s.d.logFile.Name()) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads) - - configFile, err = os.Create(configFilePath) - c.Assert(err, checker.IsNil) - daemonConfig = `{ "labels":["foo=bar"] }` - fmt.Fprintf(configFile, "%s", daemonConfig) - configFile.Close() - - syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGHUP) - - time.Sleep(3 * time.Second) - - expectedMaxConcurrentUploads = `level=debug msg="Reset Max Concurrent Uploads: 5"` - expectedMaxConcurrentDownloads = `level=debug msg="Reset Max Concurrent Downloads: 3"` - content, _ = ioutil.ReadFile(s.d.logFile.Name()) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads) - c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads) -} - -func (s *DockerDaemonSuite) TestBuildOnDisabledBridgeNetworkDaemon(c *check.C) { - err := s.d.StartWithBusybox("-b=none", "--iptables=false") - c.Assert(err, check.IsNil) - s.d.c.Logf("dockerBinary %s", dockerBinary) - out, code, err := s.d.buildImageWithOut("busyboxs", - `FROM busybox - RUN cat /etc/hosts`, false) - comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", out, code, err) - c.Assert(err, check.IsNil, comment) - c.Assert(code, check.Equals, 0, comment) -} - -// Test case for #21976 -func (s *DockerDaemonSuite) TestDaemonDNSInHostMode(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - err := s.d.StartWithBusybox("--dns", "1.2.3.4") - c.Assert(err, checker.IsNil) - - expectedOutput := "nameserver 1.2.3.4" - out, _ := s.d.Cmd("run", "--net=host", "busybox", "cat", "/etc/resolv.conf") - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) -} - -// Test case for #21976 -func (s *DockerDaemonSuite) TestDaemonDNSSearchInHostMode(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - err := s.d.StartWithBusybox("--dns-search", "example.com") - c.Assert(err, checker.IsNil) - - expectedOutput := "search example.com" - out, _ := s.d.Cmd("run", "--net=host", "busybox", "cat", "/etc/resolv.conf") - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) -} - -// Test case for #21976 -func (s *DockerDaemonSuite) TestDaemonDNSOptionsInHostMode(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - err := s.d.StartWithBusybox("--dns-opt", "timeout:3") - c.Assert(err, checker.IsNil) - - expectedOutput := "options timeout:3" - out, _ := s.d.Cmd("run", "--net=host", "busybox", "cat", "/etc/resolv.conf") - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) -} - -func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *check.C) { - conf, err := ioutil.TempFile("", "config-file-") - c.Assert(err, check.IsNil) - configName := conf.Name() - conf.Close() - defer os.Remove(configName) - - config := ` -{ - "runtimes": { - "oci": { - "path": "docker-runc" - }, - "vm": { - "path": "/usr/local/bin/vm-manager", - "runtimeArgs": [ - "--debug" - ] - } - } -} -` - ioutil.WriteFile(configName, []byte(config), 0644) - err = s.d.StartWithBusybox("--config-file", configName) - c.Assert(err, check.IsNil) - - // Run with default runtime - out, err := s.d.Cmd("run", "--rm", "busybox", "ls") - c.Assert(err, check.IsNil, check.Commentf(out)) - - // Run with default runtime explicitly - out, err = s.d.Cmd("run", "--rm", "--runtime=runc", "busybox", "ls") - c.Assert(err, check.IsNil, check.Commentf(out)) - - // Run with oci (same path as default) but keep it around - out, err = s.d.Cmd("run", "--name", "oci-runtime-ls", "--runtime=oci", "busybox", "ls") - c.Assert(err, check.IsNil, check.Commentf(out)) - - // Run with "vm" - out, err = s.d.Cmd("run", "--rm", "--runtime=vm", "busybox", "ls") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory") - - // Reset config to only have the default - config = ` -{ - "runtimes": { - } -} -` - ioutil.WriteFile(configName, []byte(config), 0644) - syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGHUP) - // Give daemon time to reload config - <-time.After(1 * time.Second) - - // Run with default runtime - out, err = s.d.Cmd("run", "--rm", "--runtime=runc", "busybox", "ls") - c.Assert(err, check.IsNil, check.Commentf(out)) - - // Run with "oci" - out, err = s.d.Cmd("run", "--rm", "--runtime=oci", "busybox", "ls") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Unknown runtime specified oci") - - // Start previously created container with oci - out, err = s.d.Cmd("start", "oci-runtime-ls") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Unknown runtime specified oci") - - // Check that we can't override the default runtime - config = ` -{ - "runtimes": { - "runc": { - "path": "my-runc" - } - } -} -` - ioutil.WriteFile(configName, []byte(config), 0644) - syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGHUP) - // Give daemon time to reload config - <-time.After(1 * time.Second) - - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - c.Assert(string(content), checker.Contains, `file configuration validation failed (runtime name 'runc' is reserved)`) - - // Check that we can select a default runtime - config = ` -{ - "default-runtime": "vm", - "runtimes": { - "oci": { - "path": "docker-runc" - }, - "vm": { - "path": "/usr/local/bin/vm-manager", - "runtimeArgs": [ - "--debug" - ] - } - } -} -` - ioutil.WriteFile(configName, []byte(config), 0644) - syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGHUP) - // Give daemon time to reload config - <-time.After(1 * time.Second) - - out, err = s.d.Cmd("run", "--rm", "busybox", "ls") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory") - - // Run with default runtime explicitly - out, err = s.d.Cmd("run", "--rm", "--runtime=runc", "busybox", "ls") - c.Assert(err, check.IsNil, check.Commentf(out)) -} - -func (s *DockerDaemonSuite) TestRunWithRuntimeFromCommandLine(c *check.C) { - err := s.d.StartWithBusybox("--add-runtime", "oci=docker-runc", "--add-runtime", "vm=/usr/local/bin/vm-manager") - c.Assert(err, check.IsNil) - - // Run with default runtime - out, err := s.d.Cmd("run", "--rm", "busybox", "ls") - c.Assert(err, check.IsNil, check.Commentf(out)) - - // Run with default runtime explicitly - out, err = s.d.Cmd("run", "--rm", "--runtime=runc", "busybox", "ls") - c.Assert(err, check.IsNil, check.Commentf(out)) - - // Run with oci (same path as default) but keep it around - out, err = s.d.Cmd("run", "--name", "oci-runtime-ls", "--runtime=oci", "busybox", "ls") - c.Assert(err, check.IsNil, check.Commentf(out)) - - // Run with "vm" - out, err = s.d.Cmd("run", "--rm", "--runtime=vm", "busybox", "ls") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory") - - // Start a daemon without any extra runtimes - s.d.Stop() - err = s.d.StartWithBusybox() - c.Assert(err, check.IsNil) - - // Run with default runtime - out, err = s.d.Cmd("run", "--rm", "--runtime=runc", "busybox", "ls") - c.Assert(err, check.IsNil, check.Commentf(out)) - - // Run with "oci" - out, err = s.d.Cmd("run", "--rm", "--runtime=oci", "busybox", "ls") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Unknown runtime specified oci") - - // Start previously created container with oci - out, err = s.d.Cmd("start", "oci-runtime-ls") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Unknown runtime specified oci") - - // Check that we can't override the default runtime - s.d.Stop() - err = s.d.Start("--add-runtime", "runc=my-runc") - c.Assert(err, check.NotNil) - - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - c.Assert(string(content), checker.Contains, `runtime name 'runc' is reserved`) - - // Check that we can select a default runtime - s.d.Stop() - err = s.d.StartWithBusybox("--default-runtime=vm", "--add-runtime", "oci=docker-runc", "--add-runtime", "vm=/usr/local/bin/vm-manager") - c.Assert(err, check.IsNil) - - out, err = s.d.Cmd("run", "--rm", "busybox", "ls") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory") - - // Run with default runtime explicitly - out, err = s.d.Cmd("run", "--rm", "--runtime=runc", "busybox", "ls") - c.Assert(err, check.IsNil, check.Commentf(out)) -} - -func (s *DockerDaemonSuite) TestDaemonRestartWithAutoRemoveContainer(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - // top1 will exist after daemon restarts - out, err := s.d.Cmd("run", "-d", "--name", "top1", "busybox:latest", "top") - c.Assert(err, checker.IsNil, check.Commentf("run top1: %v", out)) - // top2 will be removed after daemon restarts - out, err = s.d.Cmd("run", "-d", "--rm", "--name", "top2", "busybox:latest", "top") - c.Assert(err, checker.IsNil, check.Commentf("run top2: %v", out)) - - out, err = s.d.Cmd("ps") - c.Assert(out, checker.Contains, "top1", check.Commentf("top1 should be running")) - c.Assert(out, checker.Contains, "top2", check.Commentf("top2 should be running")) - - // now restart daemon gracefully - err = s.d.Restart() - c.Assert(err, checker.IsNil) - - out, err = s.d.Cmd("ps", "-a") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - c.Assert(out, checker.Contains, "top1", check.Commentf("top1 should exist after daemon restarts")) - c.Assert(out, checker.Not(checker.Contains), "top2", check.Commentf("top2 should be removed after daemon restarts")) -} - -func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - containerName := "error-values" - // Make a container with both a non 0 exit code and an error message - out, err := s.d.Cmd("run", "--name", containerName, "busybox", "toto") - c.Assert(err, checker.NotNil) - - // Check that those values were saved on disk - out, err = s.d.Cmd("inspect", "-f", "{{.State.ExitCode}}", containerName) - out = strings.TrimSpace(out) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Equals, "127") - - out, err = s.d.Cmd("inspect", "-f", "{{.State.Error}}", containerName) - out = strings.TrimSpace(out) - c.Assert(err, checker.IsNil) - - // now restart daemon - err = s.d.Restart() - c.Assert(err, checker.IsNil) - - // Check that those values are still around - out, err = s.d.Cmd("inspect", "-f", "{{.State.ExitCode}}", containerName) - out = strings.TrimSpace(out) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Equals, "127") - - out, err = s.d.Cmd("inspect", "-f", "{{.State.Error}}", containerName) - out = strings.TrimSpace(out) - c.Assert(err, checker.IsNil) -} - -func (s *DockerDaemonSuite) TestDaemonBackcompatPre17Volumes(c *check.C) { - testRequires(c, SameHostDaemon) - d := s.d - err := d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - // hack to be able to side-load a container config - out, err := d.Cmd("create", "busybox:latest") - c.Assert(err, checker.IsNil, check.Commentf(out)) - id := strings.TrimSpace(out) - - out, err = d.Cmd("inspect", "--type=image", "--format={{.ID}}", "busybox:latest") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(d.Stop(), checker.IsNil) - <-d.wait - - imageID := strings.TrimSpace(out) - volumeID := stringid.GenerateNonCryptoID() - vfsPath := filepath.Join(d.root, "vfs", "dir", volumeID) - c.Assert(os.MkdirAll(vfsPath, 0755), checker.IsNil) - - config := []byte(` - { - "ID": "` + id + `", - "Name": "hello", - "Driver": "` + d.storageDriver + `", - "Image": "` + imageID + `", - "Config": {"Image": "busybox:latest"}, - "NetworkSettings": {}, - "Volumes": { - "/bar":"/foo", - "/foo": "` + vfsPath + `", - "/quux":"/quux" - }, - "VolumesRW": { - "/bar": true, - "/foo": true, - "/quux": false - } - } - `) - - configPath := filepath.Join(d.root, "containers", id, "config.v2.json") - err = ioutil.WriteFile(configPath, config, 600) - err = d.Start() - c.Assert(err, checker.IsNil) - - out, err = d.Cmd("inspect", "--type=container", "--format={{ json .Mounts }}", id) - c.Assert(err, checker.IsNil, check.Commentf(out)) - type mount struct { - Name string - Source string - Destination string - Driver string - RW bool - } - - ls := []mount{} - err = json.NewDecoder(strings.NewReader(out)).Decode(&ls) - c.Assert(err, checker.IsNil) - - expected := []mount{ - {Source: "/foo", Destination: "/bar", RW: true}, - {Name: volumeID, Destination: "/foo", RW: true}, - {Source: "/quux", Destination: "/quux", RW: false}, - } - c.Assert(ls, checker.HasLen, len(expected)) - - for _, m := range ls { - var matched bool - for _, x := range expected { - if m.Source == x.Source && m.Destination == x.Destination && m.RW == x.RW || m.Name != x.Name { - matched = true - break - } - } - c.Assert(matched, checker.True, check.Commentf("did find match for %+v", m)) - } -} - -func (s *DockerDaemonSuite) TestDaemonWithUserlandProxyPath(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - dockerProxyPath, err := exec.LookPath("docker-proxy") - c.Assert(err, checker.IsNil) - tmpDir, err := ioutil.TempDir("", "test-docker-proxy") - c.Assert(err, checker.IsNil) - - newProxyPath := filepath.Join(tmpDir, "docker-proxy") - cmd := exec.Command("cp", dockerProxyPath, newProxyPath) - c.Assert(cmd.Run(), checker.IsNil) - - // custom one - c.Assert(s.d.StartWithBusybox("--userland-proxy-path", newProxyPath), checker.IsNil) - out, err := s.d.Cmd("run", "-p", "5000:5000", "busybox:latest", "true") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // try with the original one - c.Assert(s.d.Restart("--userland-proxy-path", dockerProxyPath), checker.IsNil) - out, err = s.d.Cmd("run", "-p", "5000:5000", "busybox:latest", "true") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // not exist - c.Assert(s.d.Restart("--userland-proxy-path", "/does/not/exist"), checker.IsNil) - out, err = s.d.Cmd("run", "-p", "5000:5000", "busybox:latest", "true") - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "driver failed programming external connectivity on endpoint") - c.Assert(out, checker.Contains, "/does/not/exist: no such file or directory") -} - -// Test case for #22471 -func (s *DockerDaemonSuite) TestDaemonShutdownTimeout(c *check.C) { - testRequires(c, SameHostDaemon) - - c.Assert(s.d.StartWithBusybox("--shutdown-timeout=3"), check.IsNil) - - _, err := s.d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, check.IsNil) - - syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGINT) - - select { - case <-s.d.wait: - case <-time.After(5 * time.Second): - } - - expectedMessage := `level=debug msg="start clean shutdown of all containers with a 3 seconds timeout..."` - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - c.Assert(string(content), checker.Contains, expectedMessage) -} - -// Test case for #22471 -func (s *DockerDaemonSuite) TestDaemonShutdownTimeoutWithConfigFile(c *check.C) { - testRequires(c, SameHostDaemon) - - // daemon config file - configFilePath := "test.json" - configFile, err := os.Create(configFilePath) - c.Assert(err, checker.IsNil) - defer os.Remove(configFilePath) - - daemonConfig := `{ "shutdown-timeout" : 8 }` - fmt.Fprintf(configFile, "%s", daemonConfig) - configFile.Close() - c.Assert(s.d.Start(fmt.Sprintf("--config-file=%s", configFilePath)), check.IsNil) - - configFile, err = os.Create(configFilePath) - c.Assert(err, checker.IsNil) - daemonConfig = `{ "shutdown-timeout" : 5 }` - fmt.Fprintf(configFile, "%s", daemonConfig) - configFile.Close() - - syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGHUP) - - select { - case <-s.d.wait: - case <-time.After(3 * time.Second): - } - - expectedMessage := `level=debug msg="Reset Shutdown Timeout: 5"` - content, _ := ioutil.ReadFile(s.d.logFile.Name()) - c.Assert(string(content), checker.Contains, expectedMessage) -} - -// Test case for 29342 -func (s *DockerDaemonSuite) TestExecWithUserAfterLiveRestore(c *check.C) { - testRequires(c, DaemonIsLinux) - s.d.StartWithBusybox("--live-restore") - - out, err := s.d.Cmd("run", "-d", "--name=top", "busybox", "sh", "-c", "addgroup -S test && adduser -S -G test test -D -s /bin/sh && top") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - - s.d.waitRun("top") - - out1, err := s.d.Cmd("exec", "-u", "test", "top", "id") - // uid=100(test) gid=101(test) groups=101(test) - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out1)) - - // restart daemon. - s.d.Restart("--live-restore") - - out2, err := s.d.Cmd("exec", "-u", "test", "top", "id") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out2)) - c.Assert(out1, check.Equals, out2, check.Commentf("Output: before restart '%s', after restart '%s'", out1, out2)) - - out, err = s.d.Cmd("stop", "top") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) -} - -func (s *DockerDaemonSuite) TestRemoveContainerAfterLiveRestore(c *check.C) { - testRequires(c, DaemonIsLinux, overlayFSSupported, SameHostDaemon) - s.d.StartWithBusybox("--live-restore", "--storage-driver", "overlay") - out, err := s.d.Cmd("run", "-d", "--name=top", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - - s.d.waitRun("top") - - // restart daemon. - s.d.Restart("--live-restore", "--storage-driver", "overlay") - - out, err = s.d.Cmd("stop", "top") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - - // test if the rootfs mountpoint still exist - mountpoint, err := s.d.inspectFilter("top", ".GraphDriver.Data.MergedDir") - c.Assert(err, check.IsNil) - f, err := os.Open("/proc/self/mountinfo") - c.Assert(err, check.IsNil) - defer f.Close() - sc := bufio.NewScanner(f) - for sc.Scan() { - line := sc.Text() - if strings.Contains(line, mountpoint) { - c.Fatalf("mountinfo should not include the mountpoint of stop container") - } - } - - out, err = s.d.Cmd("rm", "top") - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) - -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_diff_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_diff_test.go deleted file mode 100644 index 08cf6e1..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_diff_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package main - -import ( - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// ensure that an added file shows up in docker diff -func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) { - containerCmd := `mkdir /foo; echo xyzzy > /foo/bar` - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd) - - // Wait for it to exit as cannot diff a running container on Windows, and - // it will take a few seconds to exit. Also there's no way in Windows to - // differentiate between an Add or a Modify, and all files are under - // a "Files/" prefix. - containerID := strings.TrimSpace(out) - lookingFor := "A /foo/bar" - if daemonPlatform == "windows" { - err := waitExited(containerID, 60*time.Second) - c.Assert(err, check.IsNil) - lookingFor = "C Files/foo/bar" - } - - cleanCID := strings.TrimSpace(out) - out, _ = dockerCmd(c, "diff", cleanCID) - - found := false - for _, line := range strings.Split(out, "\n") { - if strings.Contains(line, lookingFor) { - found = true - break - } - } - c.Assert(found, checker.True) -} - -// test to ensure GH #3840 doesn't occur any more -func (s *DockerSuite) TestDiffEnsureInitLayerFilesAreIgnored(c *check.C) { - testRequires(c, DaemonIsLinux) - // this is a list of files which shouldn't show up in `docker diff` - initLayerFiles := []string{"/etc/resolv.conf", "/etc/hostname", "/etc/hosts", "/.dockerenv"} - containerCount := 5 - - // we might not run into this problem from the first run, so start a few containers - for i := 0; i < containerCount; i++ { - containerCmd := `echo foo > /root/bar` - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd) - - cleanCID := strings.TrimSpace(out) - out, _ = dockerCmd(c, "diff", cleanCID) - - for _, filename := range initLayerFiles { - c.Assert(out, checker.Not(checker.Contains), filename) - } - } -} - -func (s *DockerSuite) TestDiffEnsureDefaultDevs(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "0") - - cleanCID := strings.TrimSpace(out) - out, _ = dockerCmd(c, "diff", cleanCID) - - expected := map[string]bool{ - "C /dev": true, - "A /dev/full": true, // busybox - "C /dev/ptmx": true, // libcontainer - "A /dev/mqueue": true, - "A /dev/kmsg": true, - "A /dev/fd": true, - "A /dev/ptmx": true, - "A /dev/null": true, - "A /dev/random": true, - "A /dev/stdout": true, - "A /dev/stderr": true, - "A /dev/tty1": true, - "A /dev/stdin": true, - "A /dev/tty": true, - "A /dev/urandom": true, - "A /dev/zero": true, - } - - for _, line := range strings.Split(out, "\n") { - c.Assert(line == "" || expected[line], checker.True, check.Commentf(line)) - } -} - -// https://github.com/docker/docker/pull/14381#discussion_r33859347 -func (s *DockerSuite) TestDiffEmptyArgClientError(c *check.C) { - out, _, err := dockerCmdWithError("diff", "") - c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Contains, "Container name cannot be empty") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_events_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_events_test.go deleted file mode 100644 index 1fbfc74..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_events_test.go +++ /dev/null @@ -1,794 +0,0 @@ -package main - -import ( - "bufio" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net/http" - "os" - "os/exec" - "strings" - "time" - - eventtypes "github.com/docker/docker/api/types/events" - eventstestutils "github.com/docker/docker/daemon/events/testutils" - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) { - name := "events-time-format-test" - - // Start stopwatch, generate an event - start := daemonTime(c) - time.Sleep(1100 * time.Millisecond) // so that first event occur in different second from since (just for the case) - dockerCmd(c, "run", "--rm", "--name", name, "busybox", "true") - time.Sleep(1100 * time.Millisecond) // so that until > since - end := daemonTime(c) - - // List of available time formats to --since - unixTs := func(t time.Time) string { return fmt.Sprintf("%v", t.Unix()) } - rfc3339 := func(t time.Time) string { return t.Format(time.RFC3339) } - duration := func(t time.Time) string { return time.Now().Sub(t).String() } - - // --since=$start must contain only the 'untag' event - for _, f := range []func(time.Time) string{unixTs, rfc3339, duration} { - since, until := f(start), f(end) - out, _ := dockerCmd(c, "events", "--since="+since, "--until="+until) - events := strings.Split(out, "\n") - events = events[:len(events)-1] - - nEvents := len(events) - c.Assert(nEvents, checker.GreaterOrEqualThan, 5) //Missing expected event - containerEvents := eventActionsByIDAndType(c, events, name, "container") - c.Assert(containerEvents, checker.HasLen, 5, check.Commentf("events: %v", events)) - - c.Assert(containerEvents[0], checker.Equals, "create", check.Commentf(out)) - c.Assert(containerEvents[1], checker.Equals, "attach", check.Commentf(out)) - c.Assert(containerEvents[2], checker.Equals, "start", check.Commentf(out)) - c.Assert(containerEvents[3], checker.Equals, "die", check.Commentf(out)) - c.Assert(containerEvents[4], checker.Equals, "destroy", check.Commentf(out)) - } -} - -func (s *DockerSuite) TestEventsUntag(c *check.C) { - image := "busybox" - dockerCmd(c, "tag", image, "utest:tag1") - dockerCmd(c, "tag", image, "utest:tag2") - dockerCmd(c, "rmi", "utest:tag1") - dockerCmd(c, "rmi", "utest:tag2") - - result := icmd.RunCmd(icmd.Cmd{ - Command: []string{dockerBinary, "events", "--since=1"}, - Timeout: time.Millisecond * 2500, - }) - c.Assert(result, icmd.Matches, icmd.Expected{Timeout: true}) - - events := strings.Split(result.Stdout(), "\n") - nEvents := len(events) - // The last element after the split above will be an empty string, so we - // get the two elements before the last, which are the untags we're - // looking for. - for _, v := range events[nEvents-3 : nEvents-1] { - c.Assert(v, checker.Contains, "untag", check.Commentf("event should be untag")) - } -} - -func (s *DockerSuite) TestEventsLimit(c *check.C) { - // Limit to 8 goroutines creating containers in order to prevent timeouts - // creating so many containers simultaneously on Windows - sem := make(chan bool, 8) - numContainers := 17 - errChan := make(chan error, numContainers) - - args := []string{"run", "--rm", "busybox", "true"} - for i := 0; i < numContainers; i++ { - sem <- true - go func() { - defer func() { <-sem }() - out, err := exec.Command(dockerBinary, args...).CombinedOutput() - if err != nil { - err = fmt.Errorf("%v: %s", err, string(out)) - } - errChan <- err - }() - } - - // Wait for all goroutines to finish - for i := 0; i < cap(sem); i++ { - sem <- true - } - close(errChan) - - for err := range errChan { - c.Assert(err, checker.IsNil, check.Commentf("%q failed with error", strings.Join(args, " "))) - } - - out, _ := dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c)) - events := strings.Split(out, "\n") - nEvents := len(events) - 1 - c.Assert(nEvents, checker.Equals, 64, check.Commentf("events should be limited to 64, but received %d", nEvents)) -} - -func (s *DockerSuite) TestEventsContainerEvents(c *check.C) { - dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true") - - out, _ := dockerCmd(c, "events", "--until", daemonUnixTime(c)) - events := strings.Split(out, "\n") - events = events[:len(events)-1] - - nEvents := len(events) - c.Assert(nEvents, checker.GreaterOrEqualThan, 5) //Missing expected event - containerEvents := eventActionsByIDAndType(c, events, "container-events-test", "container") - c.Assert(containerEvents, checker.HasLen, 5, check.Commentf("events: %v", events)) - - c.Assert(containerEvents[0], checker.Equals, "create", check.Commentf(out)) - c.Assert(containerEvents[1], checker.Equals, "attach", check.Commentf(out)) - c.Assert(containerEvents[2], checker.Equals, "start", check.Commentf(out)) - c.Assert(containerEvents[3], checker.Equals, "die", check.Commentf(out)) - c.Assert(containerEvents[4], checker.Equals, "destroy", check.Commentf(out)) -} - -func (s *DockerSuite) TestEventsContainerEventsAttrSort(c *check.C) { - since := daemonUnixTime(c) - dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true") - - out, _ := dockerCmd(c, "events", "--filter", "container=container-events-test", "--since", since, "--until", daemonUnixTime(c)) - events := strings.Split(out, "\n") - - nEvents := len(events) - c.Assert(nEvents, checker.GreaterOrEqualThan, 3) //Missing expected event - matchedEvents := 0 - for _, event := range events { - matches := eventstestutils.ScanMap(event) - if matches["eventType"] == "container" && matches["action"] == "create" { - matchedEvents++ - c.Assert(out, checker.Contains, "(image=busybox, name=container-events-test)", check.Commentf("Event attributes not sorted")) - } else if matches["eventType"] == "container" && matches["action"] == "start" { - matchedEvents++ - c.Assert(out, checker.Contains, "(image=busybox, name=container-events-test)", check.Commentf("Event attributes not sorted")) - } - } - c.Assert(matchedEvents, checker.Equals, 2, check.Commentf("missing events for container container-events-test:\n%s", out)) -} - -func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *check.C) { - dockerCmd(c, "run", "--rm", "--name", "since-epoch-test", "busybox", "true") - timeBeginning := time.Unix(0, 0).Format(time.RFC3339Nano) - timeBeginning = strings.Replace(timeBeginning, "Z", ".000000000Z", -1) - out, _ := dockerCmd(c, "events", "--since", timeBeginning, "--until", daemonUnixTime(c)) - events := strings.Split(out, "\n") - events = events[:len(events)-1] - - nEvents := len(events) - c.Assert(nEvents, checker.GreaterOrEqualThan, 5) //Missing expected event - containerEvents := eventActionsByIDAndType(c, events, "since-epoch-test", "container") - c.Assert(containerEvents, checker.HasLen, 5, check.Commentf("events: %v", events)) - - c.Assert(containerEvents[0], checker.Equals, "create", check.Commentf(out)) - c.Assert(containerEvents[1], checker.Equals, "attach", check.Commentf(out)) - c.Assert(containerEvents[2], checker.Equals, "start", check.Commentf(out)) - c.Assert(containerEvents[3], checker.Equals, "die", check.Commentf(out)) - c.Assert(containerEvents[4], checker.Equals, "destroy", check.Commentf(out)) -} - -func (s *DockerSuite) TestEventsImageTag(c *check.C) { - time.Sleep(1 * time.Second) // because API has seconds granularity - since := daemonUnixTime(c) - image := "testimageevents:tag" - dockerCmd(c, "tag", "busybox", image) - - out, _ := dockerCmd(c, "events", - "--since", since, "--until", daemonUnixTime(c)) - - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(events, checker.HasLen, 1, check.Commentf("was expecting 1 event. out=%s", out)) - event := strings.TrimSpace(events[0]) - - matches := eventstestutils.ScanMap(event) - c.Assert(matchEventID(matches, image), checker.True, check.Commentf("matches: %v\nout:\n%s", matches, out)) - c.Assert(matches["action"], checker.Equals, "tag") -} - -func (s *DockerSuite) TestEventsImagePull(c *check.C) { - // TODO Windows: Enable this test once pull and reliable image names are available - testRequires(c, DaemonIsLinux) - since := daemonUnixTime(c) - testRequires(c, Network) - - dockerCmd(c, "pull", "hello-world") - - out, _ := dockerCmd(c, "events", - "--since", since, "--until", daemonUnixTime(c)) - - events := strings.Split(strings.TrimSpace(out), "\n") - event := strings.TrimSpace(events[len(events)-1]) - matches := eventstestutils.ScanMap(event) - c.Assert(matches["id"], checker.Equals, "hello-world:latest") - c.Assert(matches["action"], checker.Equals, "pull") - -} - -func (s *DockerSuite) TestEventsImageImport(c *check.C) { - // TODO Windows CI. This should be portable once export/import are - // more reliable (@swernli) - testRequires(c, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - cleanedContainerID := strings.TrimSpace(out) - - since := daemonUnixTime(c) - out, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "export", cleanedContainerID), - exec.Command(dockerBinary, "import", "-"), - ) - c.Assert(err, checker.IsNil, check.Commentf("import failed with output: %q", out)) - imageRef := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=import") - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(events, checker.HasLen, 1) - matches := eventstestutils.ScanMap(events[0]) - c.Assert(matches["id"], checker.Equals, imageRef, check.Commentf("matches: %v\nout:\n%s\n", matches, out)) - c.Assert(matches["action"], checker.Equals, "import", check.Commentf("matches: %v\nout:\n%s\n", matches, out)) -} - -func (s *DockerSuite) TestEventsImageLoad(c *check.C) { - testRequires(c, DaemonIsLinux) - myImageName := "footest:v1" - dockerCmd(c, "tag", "busybox", myImageName) - since := daemonUnixTime(c) - - out, _ := dockerCmd(c, "images", "-q", "--no-trunc", myImageName) - longImageID := strings.TrimSpace(out) - c.Assert(longImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty")) - - dockerCmd(c, "save", "-o", "saveimg.tar", myImageName) - dockerCmd(c, "rmi", myImageName) - out, _ = dockerCmd(c, "images", "-q", myImageName) - noImageID := strings.TrimSpace(out) - c.Assert(noImageID, checker.Equals, "", check.Commentf("Should not have any image")) - dockerCmd(c, "load", "-i", "saveimg.tar") - - result := icmd.RunCommand("rm", "-rf", "saveimg.tar") - c.Assert(result, icmd.Matches, icmd.Success) - - out, _ = dockerCmd(c, "images", "-q", "--no-trunc", myImageName) - imageID := strings.TrimSpace(out) - c.Assert(imageID, checker.Equals, longImageID, check.Commentf("Should have same image id as before")) - - out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=load") - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(events, checker.HasLen, 1) - matches := eventstestutils.ScanMap(events[0]) - c.Assert(matches["id"], checker.Equals, imageID, check.Commentf("matches: %v\nout:\n%s\n", matches, out)) - c.Assert(matches["action"], checker.Equals, "load", check.Commentf("matches: %v\nout:\n%s\n", matches, out)) - - out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=save") - events = strings.Split(strings.TrimSpace(out), "\n") - c.Assert(events, checker.HasLen, 1) - matches = eventstestutils.ScanMap(events[0]) - c.Assert(matches["id"], checker.Equals, imageID, check.Commentf("matches: %v\nout:\n%s\n", matches, out)) - c.Assert(matches["action"], checker.Equals, "save", check.Commentf("matches: %v\nout:\n%s\n", matches, out)) -} - -func (s *DockerSuite) TestEventsPluginOps(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - - since := daemonUnixTime(c) - - dockerCmd(c, "plugin", "install", pNameWithTag, "--grant-all-permissions") - dockerCmd(c, "plugin", "disable", pNameWithTag) - dockerCmd(c, "plugin", "remove", pNameWithTag) - - out, _ := dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c)) - events := strings.Split(out, "\n") - events = events[:len(events)-1] - - nEvents := len(events) - c.Assert(nEvents, checker.GreaterOrEqualThan, 4) - - pluginEvents := eventActionsByIDAndType(c, events, pNameWithTag, "plugin") - c.Assert(pluginEvents, checker.HasLen, 4, check.Commentf("events: %v", events)) - - c.Assert(pluginEvents[0], checker.Equals, "pull", check.Commentf(out)) - c.Assert(pluginEvents[1], checker.Equals, "enable", check.Commentf(out)) - c.Assert(pluginEvents[2], checker.Equals, "disable", check.Commentf(out)) - c.Assert(pluginEvents[3], checker.Equals, "remove", check.Commentf(out)) -} - -func (s *DockerSuite) TestEventsFilters(c *check.C) { - since := daemonUnixTime(c) - dockerCmd(c, "run", "--rm", "busybox", "true") - dockerCmd(c, "run", "--rm", "busybox", "true") - out, _ := dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=die") - parseEvents(c, out, "die") - - out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=die", "--filter", "event=start") - parseEvents(c, out, "die|start") - - // make sure we at least got 2 start events - count := strings.Count(out, "start") - c.Assert(strings.Count(out, "start"), checker.GreaterOrEqualThan, 2, check.Commentf("should have had 2 start events but had %d, out: %s", count, out)) - -} - -func (s *DockerSuite) TestEventsFilterImageName(c *check.C) { - since := daemonUnixTime(c) - - out, _ := dockerCmd(c, "run", "--name", "container_1", "-d", "busybox:latest", "true") - container1 := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "run", "--name", "container_2", "-d", "busybox", "true") - container2 := strings.TrimSpace(out) - - name := "busybox" - out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", fmt.Sprintf("image=%s", name)) - events := strings.Split(out, "\n") - events = events[:len(events)-1] - c.Assert(events, checker.Not(checker.HasLen), 0) //Expected events but found none for the image busybox:latest - count1 := 0 - count2 := 0 - - for _, e := range events { - if strings.Contains(e, container1) { - count1++ - } else if strings.Contains(e, container2) { - count2++ - } - } - c.Assert(count1, checker.Not(checker.Equals), 0, check.Commentf("Expected event from container but got %d from %s", count1, container1)) - c.Assert(count2, checker.Not(checker.Equals), 0, check.Commentf("Expected event from container but got %d from %s", count2, container2)) - -} - -func (s *DockerSuite) TestEventsFilterLabels(c *check.C) { - since := daemonUnixTime(c) - label := "io.docker.testing=foo" - - out, _ := dockerCmd(c, "run", "-d", "-l", label, "busybox:latest", "true") - container1 := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "run", "-d", "busybox", "true") - container2 := strings.TrimSpace(out) - - out, _ = dockerCmd( - c, - "events", - "--since", since, - "--until", daemonUnixTime(c), - "--filter", fmt.Sprintf("label=%s", label)) - - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(events), checker.Equals, 3) - - for _, e := range events { - c.Assert(e, checker.Contains, container1) - c.Assert(e, checker.Not(checker.Contains), container2) - } -} - -func (s *DockerSuite) TestEventsFilterImageLabels(c *check.C) { - since := daemonUnixTime(c) - name := "labelfiltertest" - label := "io.docker.testing=image" - - // Build a test image. - _, err := buildImage(name, fmt.Sprintf(` - FROM busybox:latest - LABEL %s`, label), true) - c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image")) - - dockerCmd(c, "tag", name, "labelfiltertest:tag1") - dockerCmd(c, "tag", name, "labelfiltertest:tag2") - dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3") - - out, _ := dockerCmd( - c, - "events", - "--since", since, - "--until", daemonUnixTime(c), - "--filter", fmt.Sprintf("label=%s", label), - "--filter", "type=image") - - events := strings.Split(strings.TrimSpace(out), "\n") - - // 2 events from the "docker tag" command, another one is from "docker build" - c.Assert(events, checker.HasLen, 3, check.Commentf("Events == %s", events)) - for _, e := range events { - c.Assert(e, checker.Contains, "labelfiltertest") - } -} - -func (s *DockerSuite) TestEventsFilterContainer(c *check.C) { - since := daemonUnixTime(c) - nameID := make(map[string]string) - - for _, name := range []string{"container_1", "container_2"} { - dockerCmd(c, "run", "--name", name, "busybox", "true") - id := inspectField(c, name, "Id") - nameID[name] = id - } - - until := daemonUnixTime(c) - - checkEvents := func(id string, events []string) error { - if len(events) != 4 { // create, attach, start, die - return fmt.Errorf("expected 4 events, got %v", events) - } - for _, event := range events { - matches := eventstestutils.ScanMap(event) - if !matchEventID(matches, id) { - return fmt.Errorf("expected event for container id %s: %s - parsed container id: %s", id, event, matches["id"]) - } - } - return nil - } - - for name, ID := range nameID { - // filter by names - out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+name) - events := strings.Split(strings.TrimSuffix(out, "\n"), "\n") - c.Assert(checkEvents(ID, events), checker.IsNil) - - // filter by ID's - out, _ = dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+ID) - events = strings.Split(strings.TrimSuffix(out, "\n"), "\n") - c.Assert(checkEvents(ID, events), checker.IsNil) - } -} - -func (s *DockerSuite) TestEventsCommit(c *check.C) { - // Problematic on Windows as cannot commit a running container - testRequires(c, DaemonIsLinux) - - out, _ := runSleepingContainer(c) - cID := strings.TrimSpace(out) - c.Assert(waitRun(cID), checker.IsNil) - - dockerCmd(c, "commit", "-m", "test", cID) - dockerCmd(c, "stop", cID) - c.Assert(waitExited(cID, 5*time.Second), checker.IsNil) - - until := daemonUnixTime(c) - out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until) - c.Assert(out, checker.Contains, "commit", check.Commentf("Missing 'commit' log event")) -} - -func (s *DockerSuite) TestEventsCopy(c *check.C) { - // Build a test image. - id, err := buildImage("cpimg", ` - FROM busybox - RUN echo HI > /file`, true) - c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image")) - - // Create an empty test file. - tempFile, err := ioutil.TempFile("", "test-events-copy-") - c.Assert(err, checker.IsNil) - defer os.Remove(tempFile.Name()) - - c.Assert(tempFile.Close(), checker.IsNil) - - dockerCmd(c, "create", "--name=cptest", id) - - dockerCmd(c, "cp", "cptest:/file", tempFile.Name()) - - until := daemonUnixTime(c) - out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+until) - c.Assert(out, checker.Contains, "archive-path", check.Commentf("Missing 'archive-path' log event\n")) - - dockerCmd(c, "cp", tempFile.Name(), "cptest:/filecopy") - - until = daemonUnixTime(c) - out, _ = dockerCmd(c, "events", "-f", "container=cptest", "--until="+until) - c.Assert(out, checker.Contains, "extract-to-dir", check.Commentf("Missing 'extract-to-dir' log event")) -} - -func (s *DockerSuite) TestEventsResize(c *check.C) { - out, _ := runSleepingContainer(c, "-d") - cID := strings.TrimSpace(out) - c.Assert(waitRun(cID), checker.IsNil) - - endpoint := "/containers/" + cID + "/resize?h=80&w=24" - status, _, err := sockRequest("POST", endpoint, nil) - c.Assert(status, checker.Equals, http.StatusOK) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "stop", cID) - - until := daemonUnixTime(c) - out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until) - c.Assert(out, checker.Contains, "resize", check.Commentf("Missing 'resize' log event")) -} - -func (s *DockerSuite) TestEventsAttach(c *check.C) { - // TODO Windows CI: Figure out why this test fails intermittently (TP5). - testRequires(c, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-di", "busybox", "cat") - cID := strings.TrimSpace(out) - c.Assert(waitRun(cID), checker.IsNil) - - cmd := exec.Command(dockerBinary, "attach", cID) - stdin, err := cmd.StdinPipe() - c.Assert(err, checker.IsNil) - defer stdin.Close() - stdout, err := cmd.StdoutPipe() - c.Assert(err, checker.IsNil) - defer stdout.Close() - c.Assert(cmd.Start(), checker.IsNil) - defer cmd.Process.Kill() - - // Make sure we're done attaching by writing/reading some stuff - _, err = stdin.Write([]byte("hello\n")) - c.Assert(err, checker.IsNil) - out, err = bufio.NewReader(stdout).ReadString('\n') - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "hello", check.Commentf("expected 'hello'")) - - c.Assert(stdin.Close(), checker.IsNil) - - dockerCmd(c, "kill", cID) - c.Assert(waitExited(cID, 5*time.Second), checker.IsNil) - - until := daemonUnixTime(c) - out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until) - c.Assert(out, checker.Contains, "attach", check.Commentf("Missing 'attach' log event")) -} - -func (s *DockerSuite) TestEventsRename(c *check.C) { - out, _ := dockerCmd(c, "run", "--name", "oldName", "busybox", "true") - cID := strings.TrimSpace(out) - dockerCmd(c, "rename", "oldName", "newName") - - until := daemonUnixTime(c) - // filter by the container id because the name in the event will be the new name. - out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until", until) - c.Assert(out, checker.Contains, "rename", check.Commentf("Missing 'rename' log event\n")) -} - -func (s *DockerSuite) TestEventsTop(c *check.C) { - // Problematic on Windows as Windows does not support top - testRequires(c, DaemonIsLinux) - - out, _ := runSleepingContainer(c, "-d") - cID := strings.TrimSpace(out) - c.Assert(waitRun(cID), checker.IsNil) - - dockerCmd(c, "top", cID) - dockerCmd(c, "stop", cID) - - until := daemonUnixTime(c) - out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until) - c.Assert(out, checker.Contains, " top", check.Commentf("Missing 'top' log event")) -} - -// #14316 -func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) { - // Problematic to port for Windows CI during TP5 timeframe until - // supporting push - testRequires(c, DaemonIsLinux) - testRequires(c, Network) - repoName := fmt.Sprintf("%v/dockercli/testf", privateRegistryURL) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - cID := strings.TrimSpace(out) - c.Assert(waitRun(cID), checker.IsNil) - - dockerCmd(c, "commit", cID, repoName) - dockerCmd(c, "stop", cID) - dockerCmd(c, "push", repoName) - - until := daemonUnixTime(c) - out, _ = dockerCmd(c, "events", "-f", "image="+repoName, "-f", "event=push", "--until", until) - c.Assert(out, checker.Contains, repoName, check.Commentf("Missing 'push' log event for %s", repoName)) -} - -func (s *DockerSuite) TestEventsFilterType(c *check.C) { - since := daemonUnixTime(c) - name := "labelfiltertest" - label := "io.docker.testing=image" - - // Build a test image. - _, err := buildImage(name, fmt.Sprintf(` - FROM busybox:latest - LABEL %s`, label), true) - c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image")) - - dockerCmd(c, "tag", name, "labelfiltertest:tag1") - dockerCmd(c, "tag", name, "labelfiltertest:tag2") - dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3") - - out, _ := dockerCmd( - c, - "events", - "--since", since, - "--until", daemonUnixTime(c), - "--filter", fmt.Sprintf("label=%s", label), - "--filter", "type=image") - - events := strings.Split(strings.TrimSpace(out), "\n") - - // 2 events from the "docker tag" command, another one is from "docker build" - c.Assert(events, checker.HasLen, 3, check.Commentf("Events == %s", events)) - for _, e := range events { - c.Assert(e, checker.Contains, "labelfiltertest") - } - - out, _ = dockerCmd( - c, - "events", - "--since", since, - "--until", daemonUnixTime(c), - "--filter", fmt.Sprintf("label=%s", label), - "--filter", "type=container") - events = strings.Split(strings.TrimSpace(out), "\n") - - // Events generated by the container that builds the image - c.Assert(events, checker.HasLen, 3, check.Commentf("Events == %s", events)) - - out, _ = dockerCmd( - c, - "events", - "--since", since, - "--until", daemonUnixTime(c), - "--filter", "type=network") - events = strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(events), checker.GreaterOrEqualThan, 1, check.Commentf("Events == %s", events)) -} - -// #25798 -func (s *DockerSuite) TestEventsSpecialFiltersWithExecCreate(c *check.C) { - since := daemonUnixTime(c) - runSleepingContainer(c, "--name", "test-container", "-d") - waitRun("test-container") - - dockerCmd(c, "exec", "test-container", "echo", "hello-world") - - out, _ := dockerCmd( - c, - "events", - "--since", since, - "--until", daemonUnixTime(c), - "--filter", - "event='exec_create: echo hello-world'", - ) - - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(events), checker.Equals, 1, check.Commentf(out)) - - out, _ = dockerCmd( - c, - "events", - "--since", since, - "--until", daemonUnixTime(c), - "--filter", - "event=exec_create", - ) - c.Assert(len(events), checker.Equals, 1, check.Commentf(out)) -} - -func (s *DockerSuite) TestEventsFilterImageInContainerAction(c *check.C) { - since := daemonUnixTime(c) - dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") - waitRun("test-container") - - out, _ := dockerCmd(c, "events", "--filter", "image=busybox", "--since", since, "--until", daemonUnixTime(c)) - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(events), checker.GreaterThan, 1, check.Commentf(out)) -} - -func (s *DockerSuite) TestEventsContainerRestart(c *check.C) { - dockerCmd(c, "run", "-d", "--name=testEvent", "--restart=on-failure:3", "busybox", "false") - - // wait until test2 is auto removed. - waitTime := 10 * time.Second - if daemonPlatform == "windows" { - // Windows takes longer... - waitTime = 90 * time.Second - } - - err := waitInspect("testEvent", "{{ .State.Restarting }} {{ .State.Running }}", "false false", waitTime) - c.Assert(err, checker.IsNil) - - var ( - createCount int - startCount int - dieCount int - ) - out, _ := dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c), "-f", "container=testEvent") - events := strings.Split(strings.TrimSpace(out), "\n") - - nEvents := len(events) - c.Assert(nEvents, checker.GreaterOrEqualThan, 1) //Missing expected event - actions := eventActionsByIDAndType(c, events, "testEvent", "container") - - for _, a := range actions { - switch a { - case "create": - createCount++ - case "start": - startCount++ - case "die": - dieCount++ - } - } - c.Assert(createCount, checker.Equals, 1, check.Commentf("testEvent should be created 1 times: %v", actions)) - c.Assert(startCount, checker.Equals, 4, check.Commentf("testEvent should start 4 times: %v", actions)) - c.Assert(dieCount, checker.Equals, 4, check.Commentf("testEvent should die 4 times: %v", actions)) -} - -func (s *DockerSuite) TestEventsSinceInTheFuture(c *check.C) { - dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") - waitRun("test-container") - - since := daemonTime(c) - until := since.Add(time.Duration(-24) * time.Hour) - out, _, err := dockerCmdWithError("events", "--filter", "image=busybox", "--since", parseEventTime(since), "--until", parseEventTime(until)) - - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "cannot be after `until`") -} - -func (s *DockerSuite) TestEventsUntilInThePast(c *check.C) { - since := daemonUnixTime(c) - - dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") - waitRun("test-container") - - until := daemonUnixTime(c) - - dockerCmd(c, "run", "--name", "test-container2", "-d", "busybox", "true") - waitRun("test-container2") - - out, _ := dockerCmd(c, "events", "--filter", "image=busybox", "--since", since, "--until", until) - - c.Assert(out, checker.Not(checker.Contains), "test-container2") - c.Assert(out, checker.Contains, "test-container") -} - -func (s *DockerSuite) TestEventsFormat(c *check.C) { - since := daemonUnixTime(c) - dockerCmd(c, "run", "--rm", "busybox", "true") - dockerCmd(c, "run", "--rm", "busybox", "true") - out, _ := dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--format", "{{json .}}") - dec := json.NewDecoder(strings.NewReader(out)) - // make sure we got 2 start events - startCount := 0 - for { - var err error - var ev eventtypes.Message - if err = dec.Decode(&ev); err == io.EOF { - break - } - c.Assert(err, checker.IsNil) - if ev.Status == "start" { - startCount++ - } - } - - c.Assert(startCount, checker.Equals, 2, check.Commentf("should have had 2 start events but had %d, out: %s", startCount, out)) -} - -func (s *DockerSuite) TestEventsFormatBadFunc(c *check.C) { - // make sure it fails immediately, without receiving any event - result := dockerCmdWithResult("events", "--format", "{{badFuncString .}}") - c.Assert(result, icmd.Matches, icmd.Expected{ - Error: "exit status 64", - ExitCode: 64, - Err: "Error parsing format: template: :1: function \"badFuncString\" not defined", - }) -} - -func (s *DockerSuite) TestEventsFormatBadField(c *check.C) { - // make sure it fails immediately, without receiving any event - result := dockerCmdWithResult("events", "--format", "{{.badFieldString}}") - c.Assert(result, icmd.Matches, icmd.Expected{ - Error: "exit status 64", - ExitCode: 64, - Err: "Error parsing format: template: :1:2: executing \"\" at <.badFieldString>: can't evaluate field badFieldString in type *events.Message", - }) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_events_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_events_unix_test.go deleted file mode 100644 index dc91667..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_events_unix_test.go +++ /dev/null @@ -1,486 +0,0 @@ -// +build !windows - -package main - -import ( - "bufio" - "bytes" - "fmt" - "io/ioutil" - "os" - "os/exec" - "strings" - "syscall" - "time" - "unicode" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" - "github.com/kr/pty" -) - -// #5979 -func (s *DockerSuite) TestEventsRedirectStdout(c *check.C) { - since := daemonUnixTime(c) - dockerCmd(c, "run", "busybox", "true") - - file, err := ioutil.TempFile("", "") - c.Assert(err, checker.IsNil, check.Commentf("could not create temp file")) - defer os.Remove(file.Name()) - - command := fmt.Sprintf("%s events --since=%s --until=%s > %s", dockerBinary, since, daemonUnixTime(c), file.Name()) - _, tty, err := pty.Open() - c.Assert(err, checker.IsNil, check.Commentf("Could not open pty")) - cmd := exec.Command("sh", "-c", command) - cmd.Stdin = tty - cmd.Stdout = tty - cmd.Stderr = tty - c.Assert(cmd.Run(), checker.IsNil, check.Commentf("run err for command %q", command)) - - scanner := bufio.NewScanner(file) - for scanner.Scan() { - for _, ch := range scanner.Text() { - c.Assert(unicode.IsControl(ch), checker.False, check.Commentf("found control character %v", []byte(string(ch)))) - } - } - c.Assert(scanner.Err(), checker.IsNil, check.Commentf("Scan err for command %q", command)) - -} - -func (s *DockerSuite) TestEventsOOMDisableFalse(c *check.C) { - testRequires(c, DaemonIsLinux, oomControl, memoryLimitSupport, swapMemorySupport) - - errChan := make(chan error) - go func() { - defer close(errChan) - out, exitCode, _ := dockerCmdWithError("run", "--name", "oomFalse", "-m", "10MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done") - if expected := 137; exitCode != expected { - errChan <- fmt.Errorf("wrong exit code for OOM container: expected %d, got %d (output: %q)", expected, exitCode, out) - } - }() - select { - case err := <-errChan: - c.Assert(err, checker.IsNil) - case <-time.After(30 * time.Second): - c.Fatal("Timeout waiting for container to die on OOM") - } - - out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=oomFalse", "--until", daemonUnixTime(c)) - events := strings.Split(strings.TrimSuffix(out, "\n"), "\n") - nEvents := len(events) - - c.Assert(nEvents, checker.GreaterOrEqualThan, 5) //Missing expected event - c.Assert(parseEventAction(c, events[nEvents-5]), checker.Equals, "create") - c.Assert(parseEventAction(c, events[nEvents-4]), checker.Equals, "attach") - c.Assert(parseEventAction(c, events[nEvents-3]), checker.Equals, "start") - c.Assert(parseEventAction(c, events[nEvents-2]), checker.Equals, "oom") - c.Assert(parseEventAction(c, events[nEvents-1]), checker.Equals, "die") -} - -func (s *DockerSuite) TestEventsOOMDisableTrue(c *check.C) { - testRequires(c, DaemonIsLinux, oomControl, memoryLimitSupport, NotArm, swapMemorySupport) - - errChan := make(chan error) - observer, err := newEventObserver(c) - c.Assert(err, checker.IsNil) - err = observer.Start() - c.Assert(err, checker.IsNil) - defer observer.Stop() - - go func() { - defer close(errChan) - out, exitCode, _ := dockerCmdWithError("run", "--oom-kill-disable=true", "--name", "oomTrue", "-m", "10MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done") - if expected := 137; exitCode != expected { - errChan <- fmt.Errorf("wrong exit code for OOM container: expected %d, got %d (output: %q)", expected, exitCode, out) - } - }() - - c.Assert(waitRun("oomTrue"), checker.IsNil) - defer dockerCmd(c, "kill", "oomTrue") - containerID := inspectField(c, "oomTrue", "Id") - - testActions := map[string]chan bool{ - "oom": make(chan bool), - } - - matcher := matchEventLine(containerID, "container", testActions) - processor := processEventMatch(testActions) - go observer.Match(matcher, processor) - - select { - case <-time.After(20 * time.Second): - observer.CheckEventError(c, containerID, "oom", matcher) - case <-testActions["oom"]: - // ignore, done - case errRun := <-errChan: - if errRun != nil { - c.Fatalf("%v", errRun) - } else { - c.Fatalf("container should be still running but it's not") - } - } - - status := inspectField(c, "oomTrue", "State.Status") - c.Assert(strings.TrimSpace(status), checker.Equals, "running", check.Commentf("container should be still running")) -} - -// #18453 -func (s *DockerSuite) TestEventsContainerFilterByName(c *check.C) { - testRequires(c, DaemonIsLinux) - cOut, _ := dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top") - c1 := strings.TrimSpace(cOut) - waitRun("foo") - cOut, _ = dockerCmd(c, "run", "--name=bar", "-d", "busybox", "top") - c2 := strings.TrimSpace(cOut) - waitRun("bar") - out, _ := dockerCmd(c, "events", "-f", "container=foo", "--since=0", "--until", daemonUnixTime(c)) - c.Assert(out, checker.Contains, c1, check.Commentf(out)) - c.Assert(out, checker.Not(checker.Contains), c2, check.Commentf(out)) -} - -// #18453 -func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *check.C) { - testRequires(c, DaemonIsLinux) - buf := &bytes.Buffer{} - cmd := exec.Command(dockerBinary, "events", "-f", "container=foo", "--since=0") - cmd.Stdout = buf - c.Assert(cmd.Start(), check.IsNil) - defer cmd.Wait() - defer cmd.Process.Kill() - - // Sleep for a second to make sure we are testing the case where events are listened before container starts. - time.Sleep(time.Second) - id, _ := dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top") - cID := strings.TrimSpace(id) - for i := 0; ; i++ { - out := buf.String() - if strings.Contains(out, cID) { - break - } - if i > 30 { - c.Fatalf("Missing event of container (foo, %v), got %q", cID, out) - } - time.Sleep(500 * time.Millisecond) - } -} - -func (s *DockerSuite) TestVolumeEvents(c *check.C) { - testRequires(c, DaemonIsLinux) - - since := daemonUnixTime(c) - - // Observe create/mount volume actions - dockerCmd(c, "volume", "create", "test-event-volume-local") - dockerCmd(c, "run", "--name", "test-volume-container", "--volume", "test-event-volume-local:/foo", "-d", "busybox", "true") - waitRun("test-volume-container") - - // Observe unmount/destroy volume actions - dockerCmd(c, "rm", "-f", "test-volume-container") - dockerCmd(c, "volume", "rm", "test-event-volume-local") - - until := daemonUnixTime(c) - out, _ := dockerCmd(c, "events", "--since", since, "--until", until) - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(events), checker.GreaterThan, 4) - - volumeEvents := eventActionsByIDAndType(c, events, "test-event-volume-local", "volume") - c.Assert(volumeEvents, checker.HasLen, 4) - c.Assert(volumeEvents[0], checker.Equals, "create") - c.Assert(volumeEvents[1], checker.Equals, "mount") - c.Assert(volumeEvents[2], checker.Equals, "unmount") - c.Assert(volumeEvents[3], checker.Equals, "destroy") -} - -func (s *DockerSuite) TestNetworkEvents(c *check.C) { - testRequires(c, DaemonIsLinux) - - since := daemonUnixTime(c) - - // Observe create/connect network actions - dockerCmd(c, "network", "create", "test-event-network-local") - dockerCmd(c, "run", "--name", "test-network-container", "--net", "test-event-network-local", "-d", "busybox", "true") - waitRun("test-network-container") - - // Observe disconnect/destroy network actions - dockerCmd(c, "rm", "-f", "test-network-container") - dockerCmd(c, "network", "rm", "test-event-network-local") - - until := daemonUnixTime(c) - out, _ := dockerCmd(c, "events", "--since", since, "--until", until) - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(events), checker.GreaterThan, 4) - - netEvents := eventActionsByIDAndType(c, events, "test-event-network-local", "network") - c.Assert(netEvents, checker.HasLen, 4) - c.Assert(netEvents[0], checker.Equals, "create") - c.Assert(netEvents[1], checker.Equals, "connect") - c.Assert(netEvents[2], checker.Equals, "disconnect") - c.Assert(netEvents[3], checker.Equals, "destroy") -} - -func (s *DockerSuite) TestEventsContainerWithMultiNetwork(c *check.C) { - testRequires(c, DaemonIsLinux) - - // Observe create/connect network actions - dockerCmd(c, "network", "create", "test-event-network-local-1") - dockerCmd(c, "network", "create", "test-event-network-local-2") - dockerCmd(c, "run", "--name", "test-network-container", "--net", "test-event-network-local-1", "-td", "busybox", "sh") - waitRun("test-network-container") - dockerCmd(c, "network", "connect", "test-event-network-local-2", "test-network-container") - - since := daemonUnixTime(c) - - dockerCmd(c, "stop", "-t", "1", "test-network-container") - - until := daemonUnixTime(c) - out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "-f", "type=network") - netEvents := strings.Split(strings.TrimSpace(out), "\n") - - // received two network disconnect events - c.Assert(len(netEvents), checker.Equals, 2) - c.Assert(netEvents[0], checker.Contains, "disconnect") - c.Assert(netEvents[1], checker.Contains, "disconnect") - - //both networks appeared in the network event output - c.Assert(out, checker.Contains, "test-event-network-local-1") - c.Assert(out, checker.Contains, "test-event-network-local-2") -} - -func (s *DockerSuite) TestEventsStreaming(c *check.C) { - testRequires(c, DaemonIsLinux) - - observer, err := newEventObserver(c) - c.Assert(err, checker.IsNil) - err = observer.Start() - c.Assert(err, checker.IsNil) - defer observer.Stop() - - out, _ := dockerCmd(c, "run", "-d", "busybox:latest", "true") - containerID := strings.TrimSpace(out) - - testActions := map[string]chan bool{ - "create": make(chan bool, 1), - "start": make(chan bool, 1), - "die": make(chan bool, 1), - "destroy": make(chan bool, 1), - } - - matcher := matchEventLine(containerID, "container", testActions) - processor := processEventMatch(testActions) - go observer.Match(matcher, processor) - - select { - case <-time.After(5 * time.Second): - observer.CheckEventError(c, containerID, "create", matcher) - case <-testActions["create"]: - // ignore, done - } - - select { - case <-time.After(5 * time.Second): - observer.CheckEventError(c, containerID, "start", matcher) - case <-testActions["start"]: - // ignore, done - } - - select { - case <-time.After(5 * time.Second): - observer.CheckEventError(c, containerID, "die", matcher) - case <-testActions["die"]: - // ignore, done - } - - dockerCmd(c, "rm", containerID) - - select { - case <-time.After(5 * time.Second): - observer.CheckEventError(c, containerID, "destroy", matcher) - case <-testActions["destroy"]: - // ignore, done - } -} - -func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) { - testRequires(c, DaemonIsLinux) - - observer, err := newEventObserver(c) - c.Assert(err, checker.IsNil) - err = observer.Start() - c.Assert(err, checker.IsNil) - defer observer.Stop() - - name := "testimageevents" - imageID, err := buildImage(name, - `FROM scratch - MAINTAINER "docker"`, - true) - c.Assert(err, checker.IsNil) - c.Assert(deleteImages(name), checker.IsNil) - - testActions := map[string]chan bool{ - "untag": make(chan bool, 1), - "delete": make(chan bool, 1), - } - - matcher := matchEventLine(imageID, "image", testActions) - processor := processEventMatch(testActions) - go observer.Match(matcher, processor) - - select { - case <-time.After(10 * time.Second): - observer.CheckEventError(c, imageID, "untag", matcher) - case <-testActions["untag"]: - // ignore, done - } - - select { - case <-time.After(10 * time.Second): - observer.CheckEventError(c, imageID, "delete", matcher) - case <-testActions["delete"]: - // ignore, done - } -} - -func (s *DockerSuite) TestEventsFilterVolumeAndNetworkType(c *check.C) { - testRequires(c, DaemonIsLinux) - - since := daemonUnixTime(c) - - dockerCmd(c, "network", "create", "test-event-network-type") - dockerCmd(c, "volume", "create", "test-event-volume-type") - - out, _ := dockerCmd(c, "events", "--filter", "type=volume", "--filter", "type=network", "--since", since, "--until", daemonUnixTime(c)) - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(events), checker.GreaterOrEqualThan, 2, check.Commentf(out)) - - networkActions := eventActionsByIDAndType(c, events, "test-event-network-type", "network") - volumeActions := eventActionsByIDAndType(c, events, "test-event-volume-type", "volume") - - c.Assert(volumeActions[0], checker.Equals, "create") - c.Assert(networkActions[0], checker.Equals, "create") -} - -func (s *DockerSuite) TestEventsFilterVolumeID(c *check.C) { - testRequires(c, DaemonIsLinux) - - since := daemonUnixTime(c) - - dockerCmd(c, "volume", "create", "test-event-volume-id") - out, _ := dockerCmd(c, "events", "--filter", "volume=test-event-volume-id", "--since", since, "--until", daemonUnixTime(c)) - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(events, checker.HasLen, 1) - - c.Assert(events[0], checker.Contains, "test-event-volume-id") - c.Assert(events[0], checker.Contains, "driver=local") -} - -func (s *DockerSuite) TestEventsFilterNetworkID(c *check.C) { - testRequires(c, DaemonIsLinux) - - since := daemonUnixTime(c) - - dockerCmd(c, "network", "create", "test-event-network-local") - out, _ := dockerCmd(c, "events", "--filter", "network=test-event-network-local", "--since", since, "--until", daemonUnixTime(c)) - events := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(events, checker.HasLen, 1) - - c.Assert(events[0], checker.Contains, "test-event-network-local") - c.Assert(events[0], checker.Contains, "type=bridge") -} - -func (s *DockerDaemonSuite) TestDaemonEvents(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - // daemon config file - configFilePath := "test.json" - configFile, err := os.Create(configFilePath) - c.Assert(err, checker.IsNil) - defer os.Remove(configFilePath) - - daemonConfig := `{"labels":["foo=bar"]}` - fmt.Fprintf(configFile, "%s", daemonConfig) - configFile.Close() - c.Assert(s.d.Start(fmt.Sprintf("--config-file=%s", configFilePath)), check.IsNil) - - // Get daemon ID - out, err := s.d.Cmd("info") - c.Assert(err, checker.IsNil) - daemonID := "" - daemonName := "" - for _, line := range strings.Split(out, "\n") { - if strings.HasPrefix(line, "ID: ") { - daemonID = strings.TrimPrefix(line, "ID: ") - } else if strings.HasPrefix(line, "Name: ") { - daemonName = strings.TrimPrefix(line, "Name: ") - } - } - c.Assert(daemonID, checker.Not(checker.Equals), "") - - configFile, err = os.Create(configFilePath) - c.Assert(err, checker.IsNil) - daemonConfig = `{"max-concurrent-downloads":1,"labels":["bar=foo"], "shutdown-timeout": 10}` - fmt.Fprintf(configFile, "%s", daemonConfig) - configFile.Close() - - syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGHUP) - - time.Sleep(3 * time.Second) - - out, err = s.d.Cmd("events", "--since=0", "--until", daemonUnixTime(c)) - c.Assert(err, checker.IsNil) - - c.Assert(out, checker.Contains, fmt.Sprintf("daemon reload %s (cluster-advertise=, cluster-store=, cluster-store-opts={}, debug=true, default-runtime=runc, insecure-registries=[], labels=[\"bar=foo\"], live-restore=false, max-concurrent-downloads=1, max-concurrent-uploads=5, name=%s, runtimes=runc:{docker-runc []}, shutdown-timeout=10)", daemonID, daemonName)) -} - -func (s *DockerDaemonSuite) TestDaemonEventsWithFilters(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - // daemon config file - configFilePath := "test.json" - configFile, err := os.Create(configFilePath) - c.Assert(err, checker.IsNil) - defer os.Remove(configFilePath) - - daemonConfig := `{"labels":["foo=bar"]}` - fmt.Fprintf(configFile, "%s", daemonConfig) - configFile.Close() - c.Assert(s.d.Start(fmt.Sprintf("--config-file=%s", configFilePath)), check.IsNil) - - // Get daemon ID - out, err := s.d.Cmd("info") - c.Assert(err, checker.IsNil) - daemonID := "" - daemonName := "" - for _, line := range strings.Split(out, "\n") { - if strings.HasPrefix(line, "ID: ") { - daemonID = strings.TrimPrefix(line, "ID: ") - } else if strings.HasPrefix(line, "Name: ") { - daemonName = strings.TrimPrefix(line, "Name: ") - } - } - c.Assert(daemonID, checker.Not(checker.Equals), "") - - syscall.Kill(s.d.cmd.Process.Pid, syscall.SIGHUP) - - time.Sleep(3 * time.Second) - - out, err = s.d.Cmd("events", "--since=0", "--until", daemonUnixTime(c), "--filter", fmt.Sprintf("daemon=%s", daemonID)) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, fmt.Sprintf("daemon reload %s", daemonID)) - - out, err = s.d.Cmd("events", "--since=0", "--until", daemonUnixTime(c), "--filter", fmt.Sprintf("daemon=%s", daemonName)) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, fmt.Sprintf("daemon reload %s", daemonID)) - - out, err = s.d.Cmd("events", "--since=0", "--until", daemonUnixTime(c), "--filter", "daemon=foo") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), fmt.Sprintf("daemon reload %s", daemonID)) - - out, err = s.d.Cmd("events", "--since=0", "--until", daemonUnixTime(c), "--filter", "type=daemon") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, fmt.Sprintf("daemon reload %s", daemonID)) - - out, err = s.d.Cmd("events", "--since=0", "--until", daemonUnixTime(c), "--filter", "type=container") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), fmt.Sprintf("daemon reload %s", daemonID)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_exec_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_exec_test.go deleted file mode 100644 index cac76d9..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_exec_test.go +++ /dev/null @@ -1,601 +0,0 @@ -// +build !test_no_exec - -package main - -import ( - "bufio" - "fmt" - "net/http" - "os" - "os/exec" - "reflect" - "runtime" - "sort" - "strings" - "sync" - "time" - - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestExec(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top") - c.Assert(waitRun(strings.TrimSpace(out)), check.IsNil) - - out, _ = dockerCmd(c, "exec", "testing", "cat", "/tmp/file") - out = strings.Trim(out, "\r\n") - c.Assert(out, checker.Equals, "test") - -} - -func (s *DockerSuite) TestExecInteractive(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top") - - execCmd := exec.Command(dockerBinary, "exec", "-i", "testing", "sh") - stdin, err := execCmd.StdinPipe() - c.Assert(err, checker.IsNil) - stdout, err := execCmd.StdoutPipe() - c.Assert(err, checker.IsNil) - - err = execCmd.Start() - c.Assert(err, checker.IsNil) - _, err = stdin.Write([]byte("cat /tmp/file\n")) - c.Assert(err, checker.IsNil) - - r := bufio.NewReader(stdout) - line, err := r.ReadString('\n') - c.Assert(err, checker.IsNil) - line = strings.TrimSpace(line) - c.Assert(line, checker.Equals, "test") - err = stdin.Close() - c.Assert(err, checker.IsNil) - errChan := make(chan error) - go func() { - errChan <- execCmd.Wait() - close(errChan) - }() - select { - case err := <-errChan: - c.Assert(err, checker.IsNil) - case <-time.After(1 * time.Second): - c.Fatal("docker exec failed to exit on stdin close") - } - -} - -func (s *DockerSuite) TestExecAfterContainerRestart(c *check.C) { - out, _ := runSleepingContainer(c) - cleanedContainerID := strings.TrimSpace(out) - c.Assert(waitRun(cleanedContainerID), check.IsNil) - dockerCmd(c, "restart", cleanedContainerID) - c.Assert(waitRun(cleanedContainerID), check.IsNil) - - out, _ = dockerCmd(c, "exec", cleanedContainerID, "echo", "hello") - outStr := strings.TrimSpace(out) - c.Assert(outStr, checker.Equals, "hello") -} - -func (s *DockerDaemonSuite) TestExecAfterDaemonRestart(c *check.C) { - // TODO Windows CI: Requires a little work to get this ported. - testRequires(c, DaemonIsLinux) - testRequires(c, SameHostDaemon) - - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - out, err := s.d.Cmd("run", "-d", "--name", "top", "-p", "80", "busybox:latest", "top") - c.Assert(err, checker.IsNil, check.Commentf("Could not run top: %s", out)) - - err = s.d.Restart() - c.Assert(err, checker.IsNil, check.Commentf("Could not restart daemon")) - - out, err = s.d.Cmd("start", "top") - c.Assert(err, checker.IsNil, check.Commentf("Could not start top after daemon restart: %s", out)) - - out, err = s.d.Cmd("exec", "top", "echo", "hello") - c.Assert(err, checker.IsNil, check.Commentf("Could not exec on container top: %s", out)) - - outStr := strings.TrimSpace(string(out)) - c.Assert(outStr, checker.Equals, "hello") -} - -// Regression test for #9155, #9044 -func (s *DockerSuite) TestExecEnv(c *check.C) { - // TODO Windows CI: This one is interesting and may just end up being a feature - // difference between Windows and Linux. On Windows, the environment is passed - // into the process that is launched, not into the machine environment. Hence - // a subsequent exec will not have LALA set/ - testRequires(c, DaemonIsLinux) - runSleepingContainer(c, "-e", "LALA=value1", "-e", "LALA=value2", "-d", "--name", "testing") - c.Assert(waitRun("testing"), check.IsNil) - - out, _ := dockerCmd(c, "exec", "testing", "env") - c.Assert(out, checker.Not(checker.Contains), "LALA=value1") - c.Assert(out, checker.Contains, "LALA=value2") - c.Assert(out, checker.Contains, "HOME=/root") -} - -func (s *DockerSuite) TestExecSetEnv(c *check.C) { - testRequires(c, DaemonIsLinux) - runSleepingContainer(c, "-e", "HOME=/root", "-d", "--name", "testing") - c.Assert(waitRun("testing"), check.IsNil) - - out, _ := dockerCmd(c, "exec", "-e", "HOME=/another", "-e", "ABC=xyz", "testing", "env") - c.Assert(out, checker.Not(checker.Contains), "HOME=/root") - c.Assert(out, checker.Contains, "HOME=/another") - c.Assert(out, checker.Contains, "ABC=xyz") -} - -func (s *DockerSuite) TestExecExitStatus(c *check.C) { - runSleepingContainer(c, "-d", "--name", "top") - - result := icmd.RunCommand(dockerBinary, "exec", "top", "sh", "-c", "exit 23") - c.Assert(result, icmd.Matches, icmd.Expected{ExitCode: 23, Error: "exit status 23"}) -} - -func (s *DockerSuite) TestExecPausedContainer(c *check.C) { - testRequires(c, IsPausable) - defer unpauseAllContainers() - - out, _ := runSleepingContainer(c, "-d", "--name", "testing") - ContainerID := strings.TrimSpace(out) - - dockerCmd(c, "pause", "testing") - out, _, err := dockerCmdWithError("exec", "-i", "-t", ContainerID, "echo", "hello") - c.Assert(err, checker.NotNil, check.Commentf("container should fail to exec new conmmand if it is paused")) - - expected := ContainerID + " is paused, unpause the container before exec" - c.Assert(out, checker.Contains, expected, check.Commentf("container should not exec new command if it is paused")) -} - -// regression test for #9476 -func (s *DockerSuite) TestExecTTYCloseStdin(c *check.C) { - // TODO Windows CI: This requires some work to port to Windows. - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "-it", "--name", "exec_tty_stdin", "busybox") - - cmd := exec.Command(dockerBinary, "exec", "-i", "exec_tty_stdin", "cat") - stdinRw, err := cmd.StdinPipe() - c.Assert(err, checker.IsNil) - - stdinRw.Write([]byte("test")) - stdinRw.Close() - - out, _, err := runCommandWithOutput(cmd) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, _ = dockerCmd(c, "top", "exec_tty_stdin") - outArr := strings.Split(out, "\n") - c.Assert(len(outArr), checker.LessOrEqualThan, 3, check.Commentf("exec process left running")) - c.Assert(out, checker.Not(checker.Contains), "nsenter-exec") -} - -func (s *DockerSuite) TestExecTTYWithoutStdin(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "-ti", "busybox") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - errChan := make(chan error) - go func() { - defer close(errChan) - - cmd := exec.Command(dockerBinary, "exec", "-ti", id, "true") - if _, err := cmd.StdinPipe(); err != nil { - errChan <- err - return - } - - expected := "the input device is not a TTY" - if runtime.GOOS == "windows" { - expected += ". If you are using mintty, try prefixing the command with 'winpty'" - } - if out, _, err := runCommandWithOutput(cmd); err == nil { - errChan <- fmt.Errorf("exec should have failed") - return - } else if !strings.Contains(out, expected) { - errChan <- fmt.Errorf("exec failed with error %q: expected %q", out, expected) - return - } - }() - - select { - case err := <-errChan: - c.Assert(err, check.IsNil) - case <-time.After(3 * time.Second): - c.Fatal("exec is running but should have failed") - } -} - -func (s *DockerSuite) TestExecParseError(c *check.C) { - // TODO Windows CI: Requires some extra work. Consider copying the - // runSleepingContainer helper to have an exec version. - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top") - - // Test normal (non-detached) case first - cmd := exec.Command(dockerBinary, "exec", "top") - _, stderr, _, err := runCommandWithStdoutStderr(cmd) - c.Assert(err, checker.NotNil) - c.Assert(stderr, checker.Contains, "See 'docker exec --help'") -} - -func (s *DockerSuite) TestExecStopNotHanging(c *check.C) { - // TODO Windows CI: Requires some extra work. Consider copying the - // runSleepingContainer helper to have an exec version. - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top") - - err := exec.Command(dockerBinary, "exec", "testing", "top").Start() - c.Assert(err, checker.IsNil) - - type dstop struct { - out []byte - err error - } - - ch := make(chan dstop) - go func() { - out, err := exec.Command(dockerBinary, "stop", "testing").CombinedOutput() - ch <- dstop{out, err} - close(ch) - }() - select { - case <-time.After(3 * time.Second): - c.Fatal("Container stop timed out") - case s := <-ch: - c.Assert(s.err, check.IsNil) - } -} - -func (s *DockerSuite) TestExecCgroup(c *check.C) { - // Not applicable on Windows - using Linux specific functionality - testRequires(c, NotUserNamespace) - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name", "testing", "busybox", "top") - - out, _ := dockerCmd(c, "exec", "testing", "cat", "/proc/1/cgroup") - containerCgroups := sort.StringSlice(strings.Split(out, "\n")) - - var wg sync.WaitGroup - var mu sync.Mutex - execCgroups := []sort.StringSlice{} - errChan := make(chan error) - // exec a few times concurrently to get consistent failure - for i := 0; i < 5; i++ { - wg.Add(1) - go func() { - out, _, err := dockerCmdWithError("exec", "testing", "cat", "/proc/self/cgroup") - if err != nil { - errChan <- err - return - } - cg := sort.StringSlice(strings.Split(out, "\n")) - - mu.Lock() - execCgroups = append(execCgroups, cg) - mu.Unlock() - wg.Done() - }() - } - wg.Wait() - close(errChan) - - for err := range errChan { - c.Assert(err, checker.IsNil) - } - - for _, cg := range execCgroups { - if !reflect.DeepEqual(cg, containerCgroups) { - fmt.Println("exec cgroups:") - for _, name := range cg { - fmt.Printf(" %s\n", name) - } - - fmt.Println("container cgroups:") - for _, name := range containerCgroups { - fmt.Printf(" %s\n", name) - } - c.Fatal("cgroups mismatched") - } - } -} - -func (s *DockerSuite) TestExecInspectID(c *check.C) { - out, _ := runSleepingContainer(c, "-d") - id := strings.TrimSuffix(out, "\n") - - out = inspectField(c, id, "ExecIDs") - c.Assert(out, checker.Equals, "[]", check.Commentf("ExecIDs should be empty, got: %s", out)) - - // Start an exec, have it block waiting so we can do some checking - cmd := exec.Command(dockerBinary, "exec", id, "sh", "-c", - "while ! test -e /execid1; do sleep 1; done") - - err := cmd.Start() - c.Assert(err, checker.IsNil, check.Commentf("failed to start the exec cmd")) - - // Give the exec 10 chances/seconds to start then give up and stop the test - tries := 10 - for i := 0; i < tries; i++ { - // Since its still running we should see exec as part of the container - out = strings.TrimSpace(inspectField(c, id, "ExecIDs")) - - if out != "[]" && out != "" { - break - } - c.Assert(i+1, checker.Not(checker.Equals), tries, check.Commentf("ExecIDs still empty after 10 second")) - time.Sleep(1 * time.Second) - } - - // Save execID for later - execID, err := inspectFilter(id, "index .ExecIDs 0") - c.Assert(err, checker.IsNil, check.Commentf("failed to get the exec id")) - - // End the exec by creating the missing file - err = exec.Command(dockerBinary, "exec", id, - "sh", "-c", "touch /execid1").Run() - - c.Assert(err, checker.IsNil, check.Commentf("failed to run the 2nd exec cmd")) - - // Wait for 1st exec to complete - cmd.Wait() - - // Give the exec 10 chances/seconds to stop then give up and stop the test - for i := 0; i < tries; i++ { - // Since its still running we should see exec as part of the container - out = strings.TrimSpace(inspectField(c, id, "ExecIDs")) - - if out == "[]" { - break - } - c.Assert(i+1, checker.Not(checker.Equals), tries, check.Commentf("ExecIDs still not empty after 10 second")) - time.Sleep(1 * time.Second) - } - - // But we should still be able to query the execID - sc, body, err := sockRequest("GET", "/exec/"+execID+"/json", nil) - c.Assert(sc, checker.Equals, http.StatusOK, check.Commentf("received status != 200 OK: %d\n%s", sc, body)) - - // Now delete the container and then an 'inspect' on the exec should - // result in a 404 (not 'container not running') - out, ec := dockerCmd(c, "rm", "-f", id) - c.Assert(ec, checker.Equals, 0, check.Commentf("error removing container: %s", out)) - sc, body, err = sockRequest("GET", "/exec/"+execID+"/json", nil) - c.Assert(sc, checker.Equals, http.StatusNotFound, check.Commentf("received status != 404: %d\n%s", sc, body)) -} - -func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *check.C) { - // Problematic on Windows as Windows does not support links - testRequires(c, DaemonIsLinux) - var out string - out, _ = dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") - idA := strings.TrimSpace(out) - c.Assert(idA, checker.Not(checker.Equals), "", check.Commentf("%s, id should not be nil", out)) - out, _ = dockerCmd(c, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "top") - idB := strings.TrimSpace(out) - c.Assert(idB, checker.Not(checker.Equals), "", check.Commentf("%s, id should not be nil", out)) - - dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") - dockerCmd(c, "rename", "container1", "container_new") - dockerCmd(c, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") -} - -func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) { - // Not applicable on Windows to Windows CI. - testRequires(c, SameHostDaemon, DaemonIsLinux) - for _, fn := range []string{"resolv.conf", "hosts"} { - deleteAllContainers() - - content, err := runCommandAndReadContainerFile(fn, exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s && top", fn))) - c.Assert(err, checker.IsNil) - - c.Assert(strings.TrimSpace(string(content)), checker.Equals, "success", check.Commentf("Content was not what was modified in the container", string(content))) - - out, _ := dockerCmd(c, "run", "-d", "--name", "c2", "busybox", "top") - contID := strings.TrimSpace(out) - netFilePath := containerStorageFile(contID, fn) - - f, err := os.OpenFile(netFilePath, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0644) - c.Assert(err, checker.IsNil) - - if _, err := f.Seek(0, 0); err != nil { - f.Close() - c.Fatal(err) - } - - if err := f.Truncate(0); err != nil { - f.Close() - c.Fatal(err) - } - - if _, err := f.Write([]byte("success2\n")); err != nil { - f.Close() - c.Fatal(err) - } - f.Close() - - res, _ := dockerCmd(c, "exec", contID, "cat", "/etc/"+fn) - c.Assert(res, checker.Equals, "success2\n") - } -} - -func (s *DockerSuite) TestExecWithUser(c *check.C) { - // TODO Windows CI: This may be fixable in the future once Windows - // supports users - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top") - - out, _ := dockerCmd(c, "exec", "-u", "1", "parent", "id") - c.Assert(out, checker.Contains, "uid=1(daemon) gid=1(daemon)") - - out, _ = dockerCmd(c, "exec", "-u", "root", "parent", "id") - c.Assert(out, checker.Contains, "uid=0(root) gid=0(root)", check.Commentf("exec with user by id expected daemon user got %s", out)) -} - -func (s *DockerSuite) TestExecWithPrivileged(c *check.C) { - // Not applicable on Windows - testRequires(c, DaemonIsLinux, NotUserNamespace) - // Start main loop which attempts mknod repeatedly - dockerCmd(c, "run", "-d", "--name", "parent", "--cap-drop=ALL", "busybox", "sh", "-c", `while (true); do if [ -e /exec_priv ]; then cat /exec_priv && mknod /tmp/sda b 8 0 && echo "Success"; else echo "Privileged exec has not run yet"; fi; usleep 10000; done`) - - // Check exec mknod doesn't work - cmd := exec.Command(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sdb b 8 16") - out, _, err := runCommandWithOutput(cmd) - c.Assert(err, checker.NotNil, check.Commentf("exec mknod in --cap-drop=ALL container without --privileged should fail")) - c.Assert(out, checker.Contains, "Operation not permitted", check.Commentf("exec mknod in --cap-drop=ALL container without --privileged should fail")) - - // Check exec mknod does work with --privileged - cmd = exec.Command(dockerBinary, "exec", "--privileged", "parent", "sh", "-c", `echo "Running exec --privileged" > /exec_priv && mknod /tmp/sdb b 8 16 && usleep 50000 && echo "Finished exec --privileged" > /exec_priv && echo ok`) - out, _, err = runCommandWithOutput(cmd) - c.Assert(err, checker.IsNil) - - actual := strings.TrimSpace(out) - c.Assert(actual, checker.Equals, "ok", check.Commentf("exec mknod in --cap-drop=ALL container with --privileged failed, output: %q", out)) - - // Check subsequent unprivileged exec cannot mknod - cmd = exec.Command(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sdc b 8 32") - out, _, err = runCommandWithOutput(cmd) - c.Assert(err, checker.NotNil, check.Commentf("repeating exec mknod in --cap-drop=ALL container after --privileged without --privileged should fail")) - c.Assert(out, checker.Contains, "Operation not permitted", check.Commentf("repeating exec mknod in --cap-drop=ALL container after --privileged without --privileged should fail")) - - // Confirm at no point was mknod allowed - logCmd := exec.Command(dockerBinary, "logs", "parent") - out, _, err = runCommandWithOutput(logCmd) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), "Success") - -} - -func (s *DockerSuite) TestExecWithImageUser(c *check.C) { - // Not applicable on Windows - testRequires(c, DaemonIsLinux) - name := "testbuilduser" - _, err := buildImage(name, - `FROM busybox - RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd - USER dockerio`, - true) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "run", "-d", "--name", "dockerioexec", name, "top") - - out, _ := dockerCmd(c, "exec", "dockerioexec", "whoami") - c.Assert(out, checker.Contains, "dockerio", check.Commentf("exec with user by id expected dockerio user got %s", out)) -} - -func (s *DockerSuite) TestExecOnReadonlyContainer(c *check.C) { - // Windows does not support read-only - // --read-only + userns has remount issues - testRequires(c, DaemonIsLinux, NotUserNamespace) - dockerCmd(c, "run", "-d", "--read-only", "--name", "parent", "busybox", "top") - dockerCmd(c, "exec", "parent", "true") -} - -func (s *DockerSuite) TestExecUlimits(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "testexeculimits" - runSleepingContainer(c, "-d", "--ulimit", "nproc=21", "--name", name) - c.Assert(waitRun(name), checker.IsNil) - - out, _, err := dockerCmdWithError("exec", name, "sh", "-c", "ulimit -p") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "21") -} - -// #15750 -func (s *DockerSuite) TestExecStartFails(c *check.C) { - // TODO Windows CI. This test should be portable. Figure out why it fails - // currently. - testRequires(c, DaemonIsLinux) - name := "exec-15750" - runSleepingContainer(c, "-d", "--name", name) - c.Assert(waitRun(name), checker.IsNil) - - out, _, err := dockerCmdWithError("exec", name, "no-such-cmd") - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "executable file not found") -} - -// Fix regression in https://github.com/docker/docker/pull/26461#issuecomment-250287297 -func (s *DockerSuite) TestExecWindowsPathNotWiped(c *check.C) { - testRequires(c, DaemonIsWindows) - out, _ := dockerCmd(c, "run", "-d", "--name", "testing", minimalBaseImage(), "powershell", "start-sleep", "60") - c.Assert(waitRun(strings.TrimSpace(out)), check.IsNil) - - out, _ = dockerCmd(c, "exec", "testing", "powershell", "write-host", "$env:PATH") - out = strings.ToLower(strings.Trim(out, "\r\n")) - c.Assert(out, checker.Contains, `windowspowershell\v1.0`) -} - -func (s *DockerSuite) TestExecEnvLinksHost(c *check.C) { - testRequires(c, DaemonIsLinux) - runSleepingContainer(c, "-d", "--name", "foo") - runSleepingContainer(c, "-d", "--link", "foo:db", "--hostname", "myhost", "--name", "bar") - out, _ := dockerCmd(c, "exec", "bar", "env") - c.Assert(out, checker.Contains, "HOSTNAME=myhost") - c.Assert(out, checker.Contains, "DB_NAME=/bar/db") -} - -func (s *DockerSuite) TestExecWindowsOpenHandles(c *check.C) { - testRequires(c, DaemonIsWindows) - runSleepingContainer(c, "-d", "--name", "test") - exec := make(chan bool) - go func() { - dockerCmd(c, "exec", "test", "cmd", "/c", "start sleep 10") - exec <- true - }() - - for { - top := make(chan string) - var out string - go func() { - out, _ := dockerCmd(c, "top", "test") - top <- out - }() - - select { - case <-time.After(time.Second * 5): - c.Error("timed out waiting for top while exec is exiting") - case out = <-top: - break - } - - if strings.Count(out, "busybox.exe") == 2 && !strings.Contains(out, "cmd.exe") { - // The initial exec process (cmd.exe) has exited, and both sleeps are currently running - break - } - time.Sleep(1 * time.Second) - } - - inspect := make(chan bool) - go func() { - dockerCmd(c, "inspect", "test") - inspect <- true - }() - - select { - case <-time.After(time.Second * 5): - c.Error("timed out waiting for inspect while exec is exiting") - case <-inspect: - break - } - - // Ensure the background sleep is still running - out, _ := dockerCmd(c, "top", "test") - c.Assert(strings.Count(out, "busybox.exe"), checker.Equals, 2) - - // The exec should exit when the background sleep exits - select { - case <-time.After(time.Second * 15): - c.Error("timed out waiting for async exec to exit") - case <-exec: - // Ensure the background sleep has actually exited - out, _ := dockerCmd(c, "top", "test") - c.Assert(strings.Count(out, "busybox.exe"), checker.Equals, 1) - break - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_exec_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_exec_unix_test.go deleted file mode 100644 index 5f69119..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_exec_unix_test.go +++ /dev/null @@ -1,93 +0,0 @@ -// +build !windows,!test_no_exec - -package main - -import ( - "bytes" - "io" - "os/exec" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" - "github.com/kr/pty" -) - -// regression test for #12546 -func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat") - contID := strings.TrimSpace(out) - - cmd := exec.Command(dockerBinary, "exec", "-i", contID, "echo", "-n", "hello") - p, err := pty.Start(cmd) - c.Assert(err, checker.IsNil) - - b := bytes.NewBuffer(nil) - go io.Copy(b, p) - - ch := make(chan error) - go func() { ch <- cmd.Wait() }() - - select { - case err := <-ch: - c.Assert(err, checker.IsNil) - output := b.String() - c.Assert(strings.TrimSpace(output), checker.Equals, "hello") - case <-time.After(5 * time.Second): - c.Fatal("timed out running docker exec") - } -} - -func (s *DockerSuite) TestExecTTY(c *check.C) { - testRequires(c, DaemonIsLinux, SameHostDaemon) - dockerCmd(c, "run", "-d", "--name=test", "busybox", "sh", "-c", "echo hello > /foo && top") - - cmd := exec.Command(dockerBinary, "exec", "-it", "test", "sh") - p, err := pty.Start(cmd) - c.Assert(err, checker.IsNil) - defer p.Close() - - _, err = p.Write([]byte("cat /foo && exit\n")) - c.Assert(err, checker.IsNil) - - chErr := make(chan error) - go func() { - chErr <- cmd.Wait() - }() - select { - case err := <-chErr: - c.Assert(err, checker.IsNil) - case <-time.After(3 * time.Second): - c.Fatal("timeout waiting for exec to exit") - } - - buf := make([]byte, 256) - read, err := p.Read(buf) - c.Assert(err, checker.IsNil) - c.Assert(bytes.Contains(buf, []byte("hello")), checker.Equals, true, check.Commentf(string(buf[:read]))) -} - -// Test the the TERM env var is set when -t is provided on exec -func (s *DockerSuite) TestExecWithTERM(c *check.C) { - testRequires(c, DaemonIsLinux, SameHostDaemon) - out, _ := dockerCmd(c, "run", "-id", "busybox", "/bin/cat") - contID := strings.TrimSpace(out) - cmd := exec.Command(dockerBinary, "exec", "-t", contID, "sh", "-c", "if [ -z $TERM ]; then exit 1; else exit 0; fi") - if err := cmd.Run(); err != nil { - c.Assert(err, checker.IsNil) - } -} - -// Test that the TERM env var is not set on exec when -t is not provided, even if it was set -// on run -func (s *DockerSuite) TestExecWithNoTERM(c *check.C) { - testRequires(c, DaemonIsLinux, SameHostDaemon) - out, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat") - contID := strings.TrimSpace(out) - cmd := exec.Command(dockerBinary, "exec", contID, "sh", "-c", "if [ -z $TERM ]; then exit 0; else exit 1; fi") - if err := cmd.Run(); err != nil { - c.Assert(err, checker.IsNil) - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_experimental_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_experimental_test.go deleted file mode 100644 index 6a49cc8..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_experimental_test.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestExperimentalVersionTrue(c *check.C) { - testRequires(c, ExperimentalDaemon) - - out, _ := dockerCmd(c, "version") - for _, line := range strings.Split(out, "\n") { - if strings.HasPrefix(strings.TrimSpace(line), "Experimental:") { - c.Assert(line, checker.Matches, "*true") - return - } - } - - c.Fatal(`"Experimental" not found in version output`) -} - -func (s *DockerSuite) TestExperimentalVersionFalse(c *check.C) { - testRequires(c, NotExperimentalDaemon) - - out, _ := dockerCmd(c, "version") - for _, line := range strings.Split(out, "\n") { - if strings.HasPrefix(strings.TrimSpace(line), "Experimental:") { - c.Assert(line, checker.Matches, "*false") - return - } - } - - c.Fatal(`"Experimental" not found in version output`) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_export_import_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_export_import_test.go deleted file mode 100644 index 069dc08..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_export_import_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package main - -import ( - "os" - "os/exec" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// export an image and try to import it into a new one -func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := "testexportcontainerandimportimage" - - dockerCmd(c, "run", "--name", containerID, "busybox", "true") - - out, _ := dockerCmd(c, "export", containerID) - - importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1") - importCmd.Stdin = strings.NewReader(out) - out, _, err := runCommandWithOutput(importCmd) - c.Assert(err, checker.IsNil, check.Commentf("failed to import image repo/testexp:v1: %s", out)) - - cleanedImageID := strings.TrimSpace(out) - c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id")) -} - -// Used to test output flag in the export command -func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) { - testRequires(c, DaemonIsLinux) - containerID := "testexportcontainerwithoutputandimportimage" - - dockerCmd(c, "run", "--name", containerID, "busybox", "true") - dockerCmd(c, "export", "--output=testexp.tar", containerID) - defer os.Remove("testexp.tar") - - out, _, err := runCommandWithOutput(exec.Command("cat", "testexp.tar")) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1") - importCmd.Stdin = strings.NewReader(out) - out, _, err = runCommandWithOutput(importCmd) - c.Assert(err, checker.IsNil, check.Commentf("failed to import image repo/testexp:v1: %s", out)) - - cleanedImageID := strings.TrimSpace(out) - c.Assert(cleanedImageID, checker.Not(checker.Equals), "", check.Commentf("output should have been an image id")) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_external_graphdriver_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_external_graphdriver_unix_test.go deleted file mode 100644 index a794ca7..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_external_graphdriver_unix_test.go +++ /dev/null @@ -1,405 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "strings" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/daemon/graphdriver/vfs" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/plugins" - "github.com/go-check/check" -) - -func init() { - check.Suite(&DockerExternalGraphdriverSuite{ - ds: &DockerSuite{}, - }) -} - -type DockerExternalGraphdriverSuite struct { - server *httptest.Server - jserver *httptest.Server - ds *DockerSuite - d *Daemon - ec map[string]*graphEventsCounter -} - -type graphEventsCounter struct { - activations int - creations int - removals int - gets int - puts int - stats int - cleanups int - exists int - init int - metadata int - diff int - applydiff int - changes int - diffsize int -} - -func (s *DockerExternalGraphdriverSuite) SetUpTest(c *check.C) { - s.d = NewDaemon(c) -} - -func (s *DockerExternalGraphdriverSuite) OnTimeout(c *check.C) { - s.d.DumpStackAndQuit() -} - -func (s *DockerExternalGraphdriverSuite) TearDownTest(c *check.C) { - s.d.Stop() - s.ds.TearDownTest(c) -} - -func (s *DockerExternalGraphdriverSuite) SetUpSuite(c *check.C) { - s.ec = make(map[string]*graphEventsCounter) - s.setUpPluginViaSpecFile(c) - s.setUpPluginViaJSONFile(c) -} - -func (s *DockerExternalGraphdriverSuite) setUpPluginViaSpecFile(c *check.C) { - mux := http.NewServeMux() - s.server = httptest.NewServer(mux) - - s.setUpPlugin(c, "test-external-graph-driver", "spec", mux, []byte(s.server.URL)) -} - -func (s *DockerExternalGraphdriverSuite) setUpPluginViaJSONFile(c *check.C) { - mux := http.NewServeMux() - s.jserver = httptest.NewServer(mux) - - p := plugins.NewLocalPlugin("json-external-graph-driver", s.jserver.URL) - b, err := json.Marshal(p) - c.Assert(err, check.IsNil) - - s.setUpPlugin(c, "json-external-graph-driver", "json", mux, b) -} - -func (s *DockerExternalGraphdriverSuite) setUpPlugin(c *check.C, name string, ext string, mux *http.ServeMux, b []byte) { - type graphDriverRequest struct { - ID string `json:",omitempty"` - Parent string `json:",omitempty"` - MountLabel string `json:",omitempty"` - ReadOnly bool `json:",omitempty"` - } - - type graphDriverResponse struct { - Err error `json:",omitempty"` - Dir string `json:",omitempty"` - Exists bool `json:",omitempty"` - Status [][2]string `json:",omitempty"` - Metadata map[string]string `json:",omitempty"` - Changes []archive.Change `json:",omitempty"` - Size int64 `json:",omitempty"` - } - - respond := func(w http.ResponseWriter, data interface{}) { - w.Header().Set("Content-Type", "appplication/vnd.docker.plugins.v1+json") - switch t := data.(type) { - case error: - fmt.Fprintln(w, fmt.Sprintf(`{"Err": %q}`, t.Error())) - case string: - fmt.Fprintln(w, t) - default: - json.NewEncoder(w).Encode(&data) - } - } - - decReq := func(b io.ReadCloser, out interface{}, w http.ResponseWriter) error { - defer b.Close() - if err := json.NewDecoder(b).Decode(&out); err != nil { - http.Error(w, fmt.Sprintf("error decoding json: %s", err.Error()), 500) - } - return nil - } - - base, err := ioutil.TempDir("", name) - c.Assert(err, check.IsNil) - vfsProto, err := vfs.Init(base, []string{}, nil, nil) - c.Assert(err, check.IsNil, check.Commentf("error initializing graph driver")) - driver := graphdriver.NewNaiveDiffDriver(vfsProto, nil, nil) - - s.ec[ext] = &graphEventsCounter{} - mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].activations++ - respond(w, `{"Implements": ["GraphDriver"]}`) - }) - - mux.HandleFunc("/GraphDriver.Init", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].init++ - respond(w, "{}") - }) - - mux.HandleFunc("/GraphDriver.CreateReadWrite", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].creations++ - - var req graphDriverRequest - if err := decReq(r.Body, &req, w); err != nil { - return - } - if err := driver.CreateReadWrite(req.ID, req.Parent, nil); err != nil { - respond(w, err) - return - } - respond(w, "{}") - }) - - mux.HandleFunc("/GraphDriver.Create", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].creations++ - - var req graphDriverRequest - if err := decReq(r.Body, &req, w); err != nil { - return - } - if err := driver.Create(req.ID, req.Parent, nil); err != nil { - respond(w, err) - return - } - respond(w, "{}") - }) - - mux.HandleFunc("/GraphDriver.Remove", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].removals++ - - var req graphDriverRequest - if err := decReq(r.Body, &req, w); err != nil { - return - } - - if err := driver.Remove(req.ID); err != nil { - respond(w, err) - return - } - respond(w, "{}") - }) - - mux.HandleFunc("/GraphDriver.Get", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].gets++ - - var req graphDriverRequest - if err := decReq(r.Body, &req, w); err != nil { - return - } - - dir, err := driver.Get(req.ID, req.MountLabel) - if err != nil { - respond(w, err) - return - } - respond(w, &graphDriverResponse{Dir: dir}) - }) - - mux.HandleFunc("/GraphDriver.Put", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].puts++ - - var req graphDriverRequest - if err := decReq(r.Body, &req, w); err != nil { - return - } - - if err := driver.Put(req.ID); err != nil { - respond(w, err) - return - } - respond(w, "{}") - }) - - mux.HandleFunc("/GraphDriver.Exists", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].exists++ - - var req graphDriverRequest - if err := decReq(r.Body, &req, w); err != nil { - return - } - respond(w, &graphDriverResponse{Exists: driver.Exists(req.ID)}) - }) - - mux.HandleFunc("/GraphDriver.Status", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].stats++ - respond(w, &graphDriverResponse{Status: driver.Status()}) - }) - - mux.HandleFunc("/GraphDriver.Cleanup", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].cleanups++ - err := driver.Cleanup() - if err != nil { - respond(w, err) - return - } - respond(w, `{}`) - }) - - mux.HandleFunc("/GraphDriver.GetMetadata", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].metadata++ - - var req graphDriverRequest - if err := decReq(r.Body, &req, w); err != nil { - return - } - - data, err := driver.GetMetadata(req.ID) - if err != nil { - respond(w, err) - return - } - respond(w, &graphDriverResponse{Metadata: data}) - }) - - mux.HandleFunc("/GraphDriver.Diff", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].diff++ - - var req graphDriverRequest - if err := decReq(r.Body, &req, w); err != nil { - return - } - - diff, err := driver.Diff(req.ID, req.Parent) - if err != nil { - respond(w, err) - return - } - io.Copy(w, diff) - }) - - mux.HandleFunc("/GraphDriver.Changes", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].changes++ - var req graphDriverRequest - if err := decReq(r.Body, &req, w); err != nil { - return - } - - changes, err := driver.Changes(req.ID, req.Parent) - if err != nil { - respond(w, err) - return - } - respond(w, &graphDriverResponse{Changes: changes}) - }) - - mux.HandleFunc("/GraphDriver.ApplyDiff", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].applydiff++ - diff := r.Body - defer r.Body.Close() - - id := r.URL.Query().Get("id") - parent := r.URL.Query().Get("parent") - - if id == "" { - http.Error(w, fmt.Sprintf("missing id"), 409) - } - - size, err := driver.ApplyDiff(id, parent, diff) - if err != nil { - respond(w, err) - return - } - respond(w, &graphDriverResponse{Size: size}) - }) - - mux.HandleFunc("/GraphDriver.DiffSize", func(w http.ResponseWriter, r *http.Request) { - s.ec[ext].diffsize++ - - var req graphDriverRequest - if err := decReq(r.Body, &req, w); err != nil { - return - } - - size, err := driver.DiffSize(req.ID, req.Parent) - if err != nil { - respond(w, err) - return - } - respond(w, &graphDriverResponse{Size: size}) - }) - - err = os.MkdirAll("/etc/docker/plugins", 0755) - c.Assert(err, check.IsNil, check.Commentf("error creating /etc/docker/plugins")) - - specFile := "/etc/docker/plugins/" + name + "." + ext - err = ioutil.WriteFile(specFile, b, 0644) - c.Assert(err, check.IsNil, check.Commentf("error writing to %s", specFile)) -} - -func (s *DockerExternalGraphdriverSuite) TearDownSuite(c *check.C) { - s.server.Close() - s.jserver.Close() - - err := os.RemoveAll("/etc/docker/plugins") - c.Assert(err, check.IsNil, check.Commentf("error removing /etc/docker/plugins")) -} - -func (s *DockerExternalGraphdriverSuite) TestExternalGraphDriver(c *check.C) { - testRequires(c, ExperimentalDaemon) - - s.testExternalGraphDriver("test-external-graph-driver", "spec", c) - s.testExternalGraphDriver("json-external-graph-driver", "json", c) -} - -func (s *DockerExternalGraphdriverSuite) testExternalGraphDriver(name string, ext string, c *check.C) { - if err := s.d.StartWithBusybox("-s", name); err != nil { - b, _ := ioutil.ReadFile(s.d.LogFileName()) - c.Assert(err, check.IsNil, check.Commentf("\n%s", string(b))) - } - - out, err := s.d.Cmd("run", "--name=graphtest", "busybox", "sh", "-c", "echo hello > /hello") - c.Assert(err, check.IsNil, check.Commentf(out)) - - err = s.d.Restart("-s", name) - - out, err = s.d.Cmd("inspect", "--format={{.GraphDriver.Name}}", "graphtest") - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), check.Equals, name) - - out, err = s.d.Cmd("diff", "graphtest") - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(strings.Contains(out, "A /hello"), check.Equals, true, check.Commentf("diff output: %s", out)) - - out, err = s.d.Cmd("rm", "-f", "graphtest") - c.Assert(err, check.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("info") - c.Assert(err, check.IsNil, check.Commentf(out)) - - err = s.d.Stop() - c.Assert(err, check.IsNil) - - // Don't check s.ec.exists, because the daemon no longer calls the - // Exists function. - c.Assert(s.ec[ext].activations, check.Equals, 2) - c.Assert(s.ec[ext].init, check.Equals, 2) - c.Assert(s.ec[ext].creations >= 1, check.Equals, true) - c.Assert(s.ec[ext].removals >= 1, check.Equals, true) - c.Assert(s.ec[ext].gets >= 1, check.Equals, true) - c.Assert(s.ec[ext].puts >= 1, check.Equals, true) - c.Assert(s.ec[ext].stats, check.Equals, 5) - c.Assert(s.ec[ext].cleanups, check.Equals, 2) - c.Assert(s.ec[ext].applydiff >= 1, check.Equals, true) - c.Assert(s.ec[ext].changes, check.Equals, 1) - c.Assert(s.ec[ext].diffsize, check.Equals, 0) - c.Assert(s.ec[ext].diff, check.Equals, 0) - c.Assert(s.ec[ext].metadata, check.Equals, 1) -} - -func (s *DockerExternalGraphdriverSuite) TestExternalGraphDriverPull(c *check.C) { - testRequires(c, Network, ExperimentalDaemon) - - c.Assert(s.d.Start(), check.IsNil) - - out, err := s.d.Cmd("pull", "busybox:latest") - c.Assert(err, check.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, check.IsNil, check.Commentf(out)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_external_volume_driver_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_external_volume_driver_unix_test.go deleted file mode 100644 index 806d87e..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_external_volume_driver_unix_test.go +++ /dev/null @@ -1,627 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "os/exec" - "path/filepath" - "strings" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/volume" - "github.com/go-check/check" -) - -const volumePluginName = "test-external-volume-driver" - -func init() { - check.Suite(&DockerExternalVolumeSuite{ - ds: &DockerSuite{}, - }) -} - -type eventCounter struct { - activations int - creations int - removals int - mounts int - unmounts int - paths int - lists int - gets int - caps int -} - -type DockerExternalVolumeSuite struct { - ds *DockerSuite - d *Daemon - *volumePlugin -} - -func (s *DockerExternalVolumeSuite) SetUpTest(c *check.C) { - s.d = NewDaemon(c) - s.ec = &eventCounter{} -} - -func (s *DockerExternalVolumeSuite) TearDownTest(c *check.C) { - s.d.Stop() - s.ds.TearDownTest(c) -} - -func (s *DockerExternalVolumeSuite) SetUpSuite(c *check.C) { - s.volumePlugin = newVolumePlugin(c, volumePluginName) -} - -type volumePlugin struct { - ec *eventCounter - *httptest.Server - vols map[string]vol -} - -type vol struct { - Name string - Mountpoint string - Ninja bool // hack used to trigger a null volume return on `Get` - Status map[string]interface{} - Options map[string]string -} - -func (p *volumePlugin) Close() { - p.Server.Close() -} - -func newVolumePlugin(c *check.C, name string) *volumePlugin { - mux := http.NewServeMux() - s := &volumePlugin{Server: httptest.NewServer(mux), ec: &eventCounter{}, vols: make(map[string]vol)} - - type pluginRequest struct { - Name string - Opts map[string]string - ID string - } - - type pluginResp struct { - Mountpoint string `json:",omitempty"` - Err string `json:",omitempty"` - } - - read := func(b io.ReadCloser) (pluginRequest, error) { - defer b.Close() - var pr pluginRequest - if err := json.NewDecoder(b).Decode(&pr); err != nil { - return pr, err - } - return pr, nil - } - - send := func(w http.ResponseWriter, data interface{}) { - switch t := data.(type) { - case error: - http.Error(w, t.Error(), 500) - case string: - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintln(w, t) - default: - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - json.NewEncoder(w).Encode(&data) - } - } - - mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) { - s.ec.activations++ - send(w, `{"Implements": ["VolumeDriver"]}`) - }) - - mux.HandleFunc("/VolumeDriver.Create", func(w http.ResponseWriter, r *http.Request) { - s.ec.creations++ - pr, err := read(r.Body) - if err != nil { - send(w, err) - return - } - _, isNinja := pr.Opts["ninja"] - status := map[string]interface{}{"Hello": "world"} - s.vols[pr.Name] = vol{Name: pr.Name, Ninja: isNinja, Status: status, Options: pr.Opts} - send(w, nil) - }) - - mux.HandleFunc("/VolumeDriver.List", func(w http.ResponseWriter, r *http.Request) { - s.ec.lists++ - vols := make([]vol, 0, len(s.vols)) - for _, v := range s.vols { - if v.Ninja { - continue - } - vols = append(vols, v) - } - send(w, map[string][]vol{"Volumes": vols}) - }) - - mux.HandleFunc("/VolumeDriver.Get", func(w http.ResponseWriter, r *http.Request) { - s.ec.gets++ - pr, err := read(r.Body) - if err != nil { - send(w, err) - return - } - - v, exists := s.vols[pr.Name] - if !exists { - send(w, `{"Err": "no such volume"}`) - } - - if v.Ninja { - send(w, map[string]vol{}) - return - } - - v.Mountpoint = hostVolumePath(pr.Name) - send(w, map[string]vol{"Volume": v}) - return - }) - - mux.HandleFunc("/VolumeDriver.Remove", func(w http.ResponseWriter, r *http.Request) { - s.ec.removals++ - pr, err := read(r.Body) - if err != nil { - send(w, err) - return - } - - v, ok := s.vols[pr.Name] - if !ok { - send(w, nil) - return - } - - if err := os.RemoveAll(hostVolumePath(v.Name)); err != nil { - send(w, &pluginResp{Err: err.Error()}) - return - } - delete(s.vols, v.Name) - send(w, nil) - }) - - mux.HandleFunc("/VolumeDriver.Path", func(w http.ResponseWriter, r *http.Request) { - s.ec.paths++ - - pr, err := read(r.Body) - if err != nil { - send(w, err) - return - } - p := hostVolumePath(pr.Name) - send(w, &pluginResp{Mountpoint: p}) - }) - - mux.HandleFunc("/VolumeDriver.Mount", func(w http.ResponseWriter, r *http.Request) { - s.ec.mounts++ - - pr, err := read(r.Body) - if err != nil { - send(w, err) - return - } - - if v, exists := s.vols[pr.Name]; exists { - // Use this to simulate a mount failure - if _, exists := v.Options["invalidOption"]; exists { - send(w, fmt.Errorf("invalid argument")) - return - } - } - - p := hostVolumePath(pr.Name) - if err := os.MkdirAll(p, 0755); err != nil { - send(w, &pluginResp{Err: err.Error()}) - return - } - - if err := ioutil.WriteFile(filepath.Join(p, "test"), []byte(s.Server.URL), 0644); err != nil { - send(w, err) - return - } - - if err := ioutil.WriteFile(filepath.Join(p, "mountID"), []byte(pr.ID), 0644); err != nil { - send(w, err) - return - } - - send(w, &pluginResp{Mountpoint: p}) - }) - - mux.HandleFunc("/VolumeDriver.Unmount", func(w http.ResponseWriter, r *http.Request) { - s.ec.unmounts++ - - _, err := read(r.Body) - if err != nil { - send(w, err) - return - } - - send(w, nil) - }) - - mux.HandleFunc("/VolumeDriver.Capabilities", func(w http.ResponseWriter, r *http.Request) { - s.ec.caps++ - - _, err := read(r.Body) - if err != nil { - send(w, err) - return - } - - send(w, `{"Capabilities": { "Scope": "global" }}`) - }) - - err := os.MkdirAll("/etc/docker/plugins", 0755) - c.Assert(err, checker.IsNil) - - err = ioutil.WriteFile("/etc/docker/plugins/"+name+".spec", []byte(s.Server.URL), 0644) - c.Assert(err, checker.IsNil) - return s -} - -func (s *DockerExternalVolumeSuite) TearDownSuite(c *check.C) { - s.volumePlugin.Close() - - err := os.RemoveAll("/etc/docker/plugins") - c.Assert(err, checker.IsNil) -} - -func (s *DockerExternalVolumeSuite) TestVolumeCLICreateOptionConflict(c *check.C) { - dockerCmd(c, "volume", "create", "test") - - out, _, err := dockerCmdWithError("volume", "create", "test", "--driver", volumePluginName) - c.Assert(err, check.NotNil, check.Commentf("volume create exception name already in use with another driver")) - c.Assert(out, checker.Contains, "A volume named test already exists") - - out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Driver }}", "test") - _, _, err = dockerCmdWithError("volume", "create", "test", "--driver", strings.TrimSpace(out)) - c.Assert(err, check.IsNil) - - // make sure hidden --name option conflicts with positional arg name - out, _, err = dockerCmdWithError("volume", "create", "--name", "test2", "test2") - c.Assert(err, check.NotNil, check.Commentf("Conflicting options: either specify --name or provide positional arg, not both")) -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamed(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - out, err := s.d.Cmd("run", "--rm", "--name", "test-data", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, s.Server.URL) - - _, err = s.d.Cmd("volume", "rm", "external-volume-test") - c.Assert(err, checker.IsNil) - - p := hostVolumePath("external-volume-test") - _, err = os.Lstat(p) - c.Assert(err, checker.NotNil) - c.Assert(os.IsNotExist(err), checker.True, check.Commentf("Expected volume path in host to not exist: %s, %v\n", p, err)) - - c.Assert(s.ec.activations, checker.Equals, 1) - c.Assert(s.ec.creations, checker.Equals, 1) - c.Assert(s.ec.removals, checker.Equals, 1) - c.Assert(s.ec.mounts, checker.Equals, 1) - c.Assert(s.ec.unmounts, checker.Equals, 1) -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnnamed(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - out, err := s.d.Cmd("run", "--rm", "--name", "test-data", "-v", "/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, s.Server.URL) - - c.Assert(s.ec.activations, checker.Equals, 1) - c.Assert(s.ec.creations, checker.Equals, 1) - c.Assert(s.ec.removals, checker.Equals, 1) - c.Assert(s.ec.mounts, checker.Equals, 1) - c.Assert(s.ec.unmounts, checker.Equals, 1) -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverVolumesFrom(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - out, err := s.d.Cmd("run", "--name", "vol-test1", "-v", "/foo", "--volume-driver", volumePluginName, "busybox:latest") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("run", "--rm", "--volumes-from", "vol-test1", "--name", "vol-test2", "busybox", "ls", "/tmp") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("rm", "-fv", "vol-test1") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - c.Assert(s.ec.activations, checker.Equals, 1) - c.Assert(s.ec.creations, checker.Equals, 1) - c.Assert(s.ec.removals, checker.Equals, 1) - c.Assert(s.ec.mounts, checker.Equals, 2) - c.Assert(s.ec.unmounts, checker.Equals, 2) -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverDeleteContainer(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - out, err := s.d.Cmd("run", "--name", "vol-test1", "-v", "/foo", "--volume-driver", volumePluginName, "busybox:latest") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("rm", "-fv", "vol-test1") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - c.Assert(s.ec.activations, checker.Equals, 1) - c.Assert(s.ec.creations, checker.Equals, 1) - c.Assert(s.ec.removals, checker.Equals, 1) - c.Assert(s.ec.mounts, checker.Equals, 1) - c.Assert(s.ec.unmounts, checker.Equals, 1) -} - -func hostVolumePath(name string) string { - return fmt.Sprintf("/var/lib/docker/volumes/%s", name) -} - -// Make sure a request to use a down driver doesn't block other requests -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *check.C) { - specPath := "/etc/docker/plugins/down-driver.spec" - err := ioutil.WriteFile(specPath, []byte("tcp://127.0.0.7:9999"), 0644) - c.Assert(err, check.IsNil) - defer os.RemoveAll(specPath) - - chCmd1 := make(chan struct{}) - chCmd2 := make(chan error) - cmd1 := exec.Command(dockerBinary, "volume", "create", "-d", "down-driver") - cmd2 := exec.Command(dockerBinary, "volume", "create") - - c.Assert(cmd1.Start(), checker.IsNil) - defer cmd1.Process.Kill() - time.Sleep(100 * time.Millisecond) // ensure API has been called - c.Assert(cmd2.Start(), checker.IsNil) - - go func() { - cmd1.Wait() - close(chCmd1) - }() - go func() { - chCmd2 <- cmd2.Wait() - }() - - select { - case <-chCmd1: - cmd2.Process.Kill() - c.Fatalf("volume create with down driver finished unexpectedly") - case err := <-chCmd2: - c.Assert(err, checker.IsNil) - case <-time.After(5 * time.Second): - cmd2.Process.Kill() - c.Fatal("volume creates are blocked by previous create requests when previous driver is down") - } -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverRetryNotImmediatelyExists(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - specPath := "/etc/docker/plugins/test-external-volume-driver-retry.spec" - os.RemoveAll(specPath) - defer os.RemoveAll(specPath) - - errchan := make(chan error) - go func() { - if out, err := s.d.Cmd("run", "--rm", "--name", "test-data-retry", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", "test-external-volume-driver-retry", "busybox:latest"); err != nil { - errchan <- fmt.Errorf("%v:\n%s", err, out) - } - close(errchan) - }() - go func() { - // wait for a retry to occur, then create spec to allow plugin to register - time.Sleep(2000 * time.Millisecond) - // no need to check for an error here since it will get picked up by the timeout later - ioutil.WriteFile(specPath, []byte(s.Server.URL), 0644) - }() - - select { - case err := <-errchan: - c.Assert(err, checker.IsNil) - case <-time.After(8 * time.Second): - c.Fatal("volume creates fail when plugin not immediately available") - } - - _, err = s.d.Cmd("volume", "rm", "external-volume-test") - c.Assert(err, checker.IsNil) - - c.Assert(s.ec.activations, checker.Equals, 1) - c.Assert(s.ec.creations, checker.Equals, 1) - c.Assert(s.ec.removals, checker.Equals, 1) - c.Assert(s.ec.mounts, checker.Equals, 1) - c.Assert(s.ec.unmounts, checker.Equals, 1) -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c *check.C) { - dockerCmd(c, "volume", "create", "-d", volumePluginName, "foo") - dockerCmd(c, "run", "-d", "--name", "testing", "-v", "foo:/bar", "busybox", "top") - - var mounts []struct { - Name string - Driver string - } - out := inspectFieldJSON(c, "testing", "Mounts") - c.Assert(json.NewDecoder(strings.NewReader(out)).Decode(&mounts), checker.IsNil) - c.Assert(len(mounts), checker.Equals, 1, check.Commentf(out)) - c.Assert(mounts[0].Name, checker.Equals, "foo") - c.Assert(mounts[0].Driver, checker.Equals, volumePluginName) -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverList(c *check.C) { - dockerCmd(c, "volume", "create", "-d", volumePluginName, "abc3") - out, _ := dockerCmd(c, "volume", "ls") - ls := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(ls), check.Equals, 2, check.Commentf("\n%s", out)) - - vol := strings.Fields(ls[len(ls)-1]) - c.Assert(len(vol), check.Equals, 2, check.Commentf("%v", vol)) - c.Assert(vol[0], check.Equals, volumePluginName) - c.Assert(vol[1], check.Equals, "abc3") - - c.Assert(s.ec.lists, check.Equals, 1) -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *check.C) { - out, _, err := dockerCmdWithError("volume", "inspect", "dummy") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "No such volume") - c.Assert(s.ec.gets, check.Equals, 1) - - dockerCmd(c, "volume", "create", "test", "-d", volumePluginName) - out, _ = dockerCmd(c, "volume", "inspect", "test") - - type vol struct { - Status map[string]string - } - var st []vol - - c.Assert(json.Unmarshal([]byte(out), &st), checker.IsNil) - c.Assert(st, checker.HasLen, 1) - c.Assert(st[0].Status, checker.HasLen, 1, check.Commentf("%v", st[0])) - c.Assert(st[0].Status["Hello"], checker.Equals, "world", check.Commentf("%v", st[0].Status)) -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c *check.C) { - dockerCmd(c, "volume", "create", "-d", volumePluginName, "abc1") - err := s.d.Restart() - c.Assert(err, checker.IsNil) - - dockerCmd(c, "run", "--name=test", "-v", "abc1:/foo", "busybox", "true") - var mounts []types.MountPoint - inspectFieldAndMarshall(c, "test", "Mounts", &mounts) - c.Assert(mounts, checker.HasLen, 1) - c.Assert(mounts[0].Driver, checker.Equals, volumePluginName) -} - -// Ensures that the daemon handles when the plugin responds to a `Get` request with a null volume and a null error. -// Prior the daemon would panic in this scenario. -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGetEmptyResponse(c *check.C) { - c.Assert(s.d.Start(), checker.IsNil) - - out, err := s.d.Cmd("volume", "create", "-d", volumePluginName, "abc2", "--opt", "ninja=1") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("volume", "inspect", "abc2") - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "No such volume") -} - -// Ensure only cached paths are used in volume list to prevent N+1 calls to `VolumeDriver.Path` -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverPathCalls(c *check.C) { - c.Assert(s.d.Start(), checker.IsNil) - c.Assert(s.ec.paths, checker.Equals, 0) - - out, err := s.d.Cmd("volume", "create", "test", "--driver=test-external-volume-driver") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(s.ec.paths, checker.Equals, 1) - - out, err = s.d.Cmd("volume", "ls") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(s.ec.paths, checker.Equals, 1) - - out, err = s.d.Cmd("volume", "inspect", "--format='{{.Mountpoint}}'", "test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - c.Assert(s.ec.paths, checker.Equals, 1) -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverMountID(c *check.C) { - err := s.d.StartWithBusybox() - c.Assert(err, checker.IsNil) - - out, err := s.d.Cmd("run", "--rm", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") -} - -// Check that VolumeDriver.Capabilities gets called, and only called once -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverCapabilities(c *check.C) { - c.Assert(s.d.Start(), checker.IsNil) - c.Assert(s.ec.caps, checker.Equals, 0) - - for i := 0; i < 3; i++ { - out, err := s.d.Cmd("volume", "create", "-d", volumePluginName, fmt.Sprintf("test%d", i)) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(s.ec.caps, checker.Equals, 1) - out, err = s.d.Cmd("volume", "inspect", "--format={{.Scope}}", fmt.Sprintf("test%d", i)) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, volume.GlobalScope) - } -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *check.C) { - driverName := stringid.GenerateNonCryptoID() - p := newVolumePlugin(c, driverName) - defer p.Close() - - c.Assert(s.d.StartWithBusybox(), checker.IsNil) - - out, err := s.d.Cmd("volume", "create", "-d", driverName, "--name", "test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("volume", "create", "-d", "local", "--name", "test") - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "volume named test already exists") - - // simulate out of band volume deletion on plugin level - delete(p.vols, "test") - - // test re-create with same driver - out, err = s.d.Cmd("volume", "create", "-d", driverName, "--opt", "foo=bar", "--name", "test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - out, err = s.d.Cmd("volume", "inspect", "test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - var vs []types.Volume - err = json.Unmarshal([]byte(out), &vs) - c.Assert(err, checker.IsNil) - c.Assert(vs, checker.HasLen, 1) - c.Assert(vs[0].Driver, checker.Equals, driverName) - c.Assert(vs[0].Options, checker.NotNil) - c.Assert(vs[0].Options["foo"], checker.Equals, "bar") - c.Assert(vs[0].Driver, checker.Equals, driverName) - - // simulate out of band volume deletion on plugin level - delete(p.vols, "test") - - // test create with different driver - out, err = s.d.Cmd("volume", "create", "-d", "local", "--name", "test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = s.d.Cmd("volume", "inspect", "test") - c.Assert(err, checker.IsNil, check.Commentf(out)) - vs = nil - err = json.Unmarshal([]byte(out), &vs) - c.Assert(err, checker.IsNil) - c.Assert(vs, checker.HasLen, 1) - c.Assert(vs[0].Options, checker.HasLen, 0) - c.Assert(vs[0].Driver, checker.Equals, "local") -} - -func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnMountFail(c *check.C) { - c.Assert(s.d.StartWithBusybox(), checker.IsNil) - s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", "--opt=invalidOption=1", "--name=testumount") - - out, _ := s.d.Cmd("run", "-v", "testumount:/foo", "busybox", "true") - c.Assert(s.ec.unmounts, checker.Equals, 0, check.Commentf(out)) - out, _ = s.d.Cmd("run", "-w", "/foo", "-v", "testumount:/foo", "busybox", "true") - c.Assert(s.ec.unmounts, checker.Equals, 0, check.Commentf(out)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_health_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_health_test.go deleted file mode 100644 index 6b7baeb..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_health_test.go +++ /dev/null @@ -1,169 +0,0 @@ -package main - -import ( - "encoding/json" - - "strconv" - "strings" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func waitForStatus(c *check.C, name string, prev string, expected string) { - prev = prev + "\n" - expected = expected + "\n" - for { - out, _ := dockerCmd(c, "inspect", "--format={{.State.Status}}", name) - if out == expected { - return - } - c.Check(out, checker.Equals, prev) - if out != prev { - return - } - time.Sleep(100 * time.Millisecond) - } -} - -func waitForHealthStatus(c *check.C, name string, prev string, expected string) { - prev = prev + "\n" - expected = expected + "\n" - for { - out, _ := dockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name) - if out == expected { - return - } - c.Check(out, checker.Equals, prev) - if out != prev { - return - } - time.Sleep(100 * time.Millisecond) - } -} - -func getHealth(c *check.C, name string) *types.Health { - out, _ := dockerCmd(c, "inspect", "--format={{json .State.Health}}", name) - var health types.Health - err := json.Unmarshal([]byte(out), &health) - c.Check(err, checker.Equals, nil) - return &health -} - -func (s *DockerSuite) TestHealth(c *check.C) { - testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows - - imageName := "testhealth" - _, err := buildImage(imageName, - `FROM busybox - RUN echo OK > /status - CMD ["/bin/sleep", "120"] - STOPSIGNAL SIGKILL - HEALTHCHECK --interval=1s --timeout=30s \ - CMD cat /status`, - true) - - c.Check(err, check.IsNil) - - // No health status before starting - name := "test_health" - dockerCmd(c, "create", "--name", name, imageName) - out, _ := dockerCmd(c, "ps", "-a", "--format={{.Status}}") - c.Check(out, checker.Equals, "Created\n") - - // Inspect the options - out, _ = dockerCmd(c, "inspect", - "--format=timeout={{.Config.Healthcheck.Timeout}} "+ - "interval={{.Config.Healthcheck.Interval}} "+ - "retries={{.Config.Healthcheck.Retries}} "+ - "test={{.Config.Healthcheck.Test}}", name) - c.Check(out, checker.Equals, "timeout=30s interval=1s retries=0 test=[CMD-SHELL cat /status]\n") - - // Start - dockerCmd(c, "start", name) - waitForHealthStatus(c, name, "starting", "healthy") - - // Make it fail - dockerCmd(c, "exec", name, "rm", "/status") - waitForHealthStatus(c, name, "healthy", "unhealthy") - - // Inspect the status - out, _ = dockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name) - c.Check(out, checker.Equals, "unhealthy\n") - - // Make it healthy again - dockerCmd(c, "exec", name, "touch", "/status") - waitForHealthStatus(c, name, "unhealthy", "healthy") - - // Remove container - dockerCmd(c, "rm", "-f", name) - - // Disable the check from the CLI - out, _ = dockerCmd(c, "create", "--name=noh", "--no-healthcheck", imageName) - out, _ = dockerCmd(c, "inspect", "--format={{.Config.Healthcheck.Test}}", "noh") - c.Check(out, checker.Equals, "[NONE]\n") - dockerCmd(c, "rm", "noh") - - // Disable the check with a new build - _, err = buildImage("no_healthcheck", - `FROM testhealth - HEALTHCHECK NONE`, true) - c.Check(err, check.IsNil) - - out, _ = dockerCmd(c, "inspect", "--format={{.ContainerConfig.Healthcheck.Test}}", "no_healthcheck") - c.Check(out, checker.Equals, "[NONE]\n") - - // Enable the checks from the CLI - _, _ = dockerCmd(c, "run", "-d", "--name=fatal_healthcheck", - "--health-interval=0.5s", - "--health-retries=3", - "--health-cmd=cat /status", - "no_healthcheck") - waitForHealthStatus(c, "fatal_healthcheck", "starting", "healthy") - health := getHealth(c, "fatal_healthcheck") - c.Check(health.Status, checker.Equals, "healthy") - c.Check(health.FailingStreak, checker.Equals, 0) - last := health.Log[len(health.Log)-1] - c.Check(last.ExitCode, checker.Equals, 0) - c.Check(last.Output, checker.Equals, "OK\n") - - // Fail the check - dockerCmd(c, "exec", "fatal_healthcheck", "rm", "/status") - waitForHealthStatus(c, "fatal_healthcheck", "healthy", "unhealthy") - - failsStr, _ := dockerCmd(c, "inspect", "--format={{.State.Health.FailingStreak}}", "fatal_healthcheck") - fails, err := strconv.Atoi(strings.TrimSpace(failsStr)) - c.Check(err, check.IsNil) - c.Check(fails >= 3, checker.Equals, true) - dockerCmd(c, "rm", "-f", "fatal_healthcheck") - - // Check timeout - // Note: if the interval is too small, it seems that Docker spends all its time running health - // checks and never gets around to killing it. - _, _ = dockerCmd(c, "run", "-d", "--name=test", - "--health-interval=1s", "--health-cmd=sleep 5m", "--health-timeout=1ms", imageName) - waitForHealthStatus(c, "test", "starting", "unhealthy") - health = getHealth(c, "test") - last = health.Log[len(health.Log)-1] - c.Check(health.Status, checker.Equals, "unhealthy") - c.Check(last.ExitCode, checker.Equals, -1) - c.Check(last.Output, checker.Equals, "Health check exceeded timeout (1ms)") - dockerCmd(c, "rm", "-f", "test") - - // Check JSON-format - _, err = buildImage(imageName, - `FROM busybox - RUN echo OK > /status - CMD ["/bin/sleep", "120"] - STOPSIGNAL SIGKILL - HEALTHCHECK --interval=1s --timeout=30s \ - CMD ["cat", "/my status"]`, - true) - c.Check(err, check.IsNil) - out, _ = dockerCmd(c, "inspect", - "--format={{.Config.Healthcheck.Test}}", imageName) - c.Check(out, checker.Equals, "[CMD cat /my status]\n") - -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_help_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_help_test.go deleted file mode 100644 index 29b6553..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_help_test.go +++ /dev/null @@ -1,321 +0,0 @@ -package main - -import ( - "fmt" - "os/exec" - "runtime" - "strings" - "unicode" - - "github.com/docker/docker/pkg/homedir" - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestHelpTextVerify(c *check.C) { - testRequires(c, DaemonIsLinux) - - // Make sure main help text fits within 80 chars and that - // on non-windows system we use ~ when possible (to shorten things). - // Test for HOME set to its default value and set to "/" on linux - // Yes on windows setting up an array and looping (right now) isn't - // necessary because we just have one value, but we'll need the - // array/loop on linux so we might as well set it up so that we can - // test any number of home dirs later on and all we need to do is - // modify the array - the rest of the testing infrastructure should work - homes := []string{homedir.Get()} - - // Non-Windows machines need to test for this special case of $HOME - if runtime.GOOS != "windows" { - homes = append(homes, "/") - } - - homeKey := homedir.Key() - baseEnvs := appendBaseEnv(true) - - // Remove HOME env var from list so we can add a new value later. - for i, env := range baseEnvs { - if strings.HasPrefix(env, homeKey+"=") { - baseEnvs = append(baseEnvs[:i], baseEnvs[i+1:]...) - break - } - } - - for _, home := range homes { - - // Dup baseEnvs and add our new HOME value - newEnvs := make([]string, len(baseEnvs)+1) - copy(newEnvs, baseEnvs) - newEnvs[len(newEnvs)-1] = homeKey + "=" + home - - scanForHome := runtime.GOOS != "windows" && home != "/" - - // Check main help text to make sure its not over 80 chars - helpCmd := exec.Command(dockerBinary, "help") - helpCmd.Env = newEnvs - out, _, err := runCommandWithOutput(helpCmd) - c.Assert(err, checker.IsNil, check.Commentf(out)) - lines := strings.Split(out, "\n") - for _, line := range lines { - // All lines should not end with a space - c.Assert(line, checker.Not(checker.HasSuffix), " ", check.Commentf("Line should not end with a space")) - - if scanForHome && strings.Contains(line, `=`+home) { - c.Fatalf("Line should use '%q' instead of %q:\n%s", homedir.GetShortcutString(), home, line) - } - if runtime.GOOS != "windows" { - i := strings.Index(line, homedir.GetShortcutString()) - if i >= 0 && i != len(line)-1 && line[i+1] != '/' { - c.Fatalf("Main help should not have used home shortcut:\n%s", line) - } - } - } - - // Make sure each cmd's help text fits within 90 chars and that - // on non-windows system we use ~ when possible (to shorten things). - // Pull the list of commands from the "Commands:" section of docker help - helpCmd = exec.Command(dockerBinary, "help") - helpCmd.Env = newEnvs - out, _, err = runCommandWithOutput(helpCmd) - c.Assert(err, checker.IsNil, check.Commentf(out)) - i := strings.Index(out, "Commands:") - c.Assert(i, checker.GreaterOrEqualThan, 0, check.Commentf("Missing 'Commands:' in:\n%s", out)) - - cmds := []string{} - // Grab all chars starting at "Commands:" - helpOut := strings.Split(out[i:], "\n") - // Skip first line, it is just "Commands:" - helpOut = helpOut[1:] - - // Create the list of commands we want to test - cmdsToTest := []string{} - for _, cmd := range helpOut { - // Stop on blank line or non-idented line - if cmd == "" || !unicode.IsSpace(rune(cmd[0])) { - break - } - - // Grab just the first word of each line - cmd = strings.Split(strings.TrimSpace(cmd), " ")[0] - cmds = append(cmds, cmd) // Saving count for later - - cmdsToTest = append(cmdsToTest, cmd) - } - - // Add some 'two word' commands - would be nice to automatically - // calculate this list - somehow - cmdsToTest = append(cmdsToTest, "volume create") - cmdsToTest = append(cmdsToTest, "volume inspect") - cmdsToTest = append(cmdsToTest, "volume ls") - cmdsToTest = append(cmdsToTest, "volume rm") - cmdsToTest = append(cmdsToTest, "network connect") - cmdsToTest = append(cmdsToTest, "network create") - cmdsToTest = append(cmdsToTest, "network disconnect") - cmdsToTest = append(cmdsToTest, "network inspect") - cmdsToTest = append(cmdsToTest, "network ls") - cmdsToTest = append(cmdsToTest, "network rm") - - if experimentalDaemon { - cmdsToTest = append(cmdsToTest, "checkpoint create") - cmdsToTest = append(cmdsToTest, "checkpoint ls") - cmdsToTest = append(cmdsToTest, "checkpoint rm") - } - - // Divide the list of commands into go routines and run the func testcommand on the commands in parallel - // to save runtime of test - - errChan := make(chan error) - - for index := 0; index < len(cmdsToTest); index++ { - go func(index int) { - errChan <- testCommand(cmdsToTest[index], newEnvs, scanForHome, home) - }(index) - } - - for index := 0; index < len(cmdsToTest); index++ { - err := <-errChan - if err != nil { - c.Fatal(err) - } - } - } -} - -func (s *DockerSuite) TestHelpExitCodesHelpOutput(c *check.C) { - // Test to make sure the exit code and output (stdout vs stderr) of - // various good and bad cases are what we expect - - // docker : stdout=all, stderr=empty, rc=0 - out, _, err := dockerCmdWithError() - c.Assert(err, checker.IsNil, check.Commentf(out)) - // Be really pick - c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker'\n")) - - // docker help: stdout=all, stderr=empty, rc=0 - out, _, err = dockerCmdWithError("help") - c.Assert(err, checker.IsNil, check.Commentf(out)) - // Be really pick - c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker help'\n")) - - // docker --help: stdout=all, stderr=empty, rc=0 - out, _, err = dockerCmdWithError("--help") - c.Assert(err, checker.IsNil, check.Commentf(out)) - // Be really pick - c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker --help'\n")) - - // docker inspect busybox: stdout=all, stderr=empty, rc=0 - // Just making sure stderr is empty on valid cmd - out, _, err = dockerCmdWithError("inspect", "busybox") - c.Assert(err, checker.IsNil, check.Commentf(out)) - // Be really pick - c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker inspect busyBox'\n")) - - // docker rm: stdout=empty, stderr=all, rc!=0 - // testing the min arg error msg - cmd := exec.Command(dockerBinary, "rm") - stdout, stderr, _, err := runCommandWithStdoutStderr(cmd) - c.Assert(err, checker.NotNil) - c.Assert(stdout, checker.Equals, "") - // Should not contain full help text but should contain info about - // # of args and Usage line - c.Assert(stderr, checker.Contains, "requires at least 1 argument", check.Commentf("Missing # of args text from 'docker rm'\n")) - - // docker rm NoSuchContainer: stdout=empty, stderr=all, rc=0 - // testing to make sure no blank line on error - cmd = exec.Command(dockerBinary, "rm", "NoSuchContainer") - stdout, stderr, _, err = runCommandWithStdoutStderr(cmd) - c.Assert(err, checker.NotNil) - c.Assert(len(stderr), checker.Not(checker.Equals), 0) - c.Assert(stdout, checker.Equals, "") - // Be really picky - c.Assert(stderr, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker rm'\n")) - - // docker BadCmd: stdout=empty, stderr=all, rc=0 - cmd = exec.Command(dockerBinary, "BadCmd") - stdout, stderr, _, err = runCommandWithStdoutStderr(cmd) - c.Assert(err, checker.NotNil) - c.Assert(stdout, checker.Equals, "") - c.Assert(stderr, checker.Equals, "docker: 'BadCmd' is not a docker command.\nSee 'docker --help'\n", check.Commentf("Unexcepted output for 'docker badCmd'\n")) -} - -func testCommand(cmd string, newEnvs []string, scanForHome bool, home string) error { - - args := strings.Split(cmd+" --help", " ") - - // Check the full usage text - helpCmd := exec.Command(dockerBinary, args...) - helpCmd.Env = newEnvs - out, stderr, _, err := runCommandWithStdoutStderr(helpCmd) - if len(stderr) != 0 { - return fmt.Errorf("Error on %q help. non-empty stderr:%q\n", cmd, stderr) - } - if strings.HasSuffix(out, "\n\n") { - return fmt.Errorf("Should not have blank line on %q\n", cmd) - } - if !strings.Contains(out, "--help") { - return fmt.Errorf("All commands should mention '--help'. Command '%v' did not.\n", cmd) - } - - if err != nil { - return fmt.Errorf(out) - } - - // Check each line for lots of stuff - lines := strings.Split(out, "\n") - for _, line := range lines { - i := strings.Index(line, "~") - if i >= 0 && i != len(line)-1 && line[i+1] != '/' { - return fmt.Errorf("Help for %q should not have used ~:\n%s", cmd, line) - } - - // If a line starts with 4 spaces then assume someone - // added a multi-line description for an option and we need - // to flag it - if strings.HasPrefix(line, " ") && - !strings.HasPrefix(strings.TrimLeft(line, " "), "--") { - return fmt.Errorf("Help for %q should not have a multi-line option", cmd) - } - - // Options should NOT end with a period - if strings.HasPrefix(line, " -") && strings.HasSuffix(line, ".") { - return fmt.Errorf("Help for %q should not end with a period: %s", cmd, line) - } - - // Options should NOT end with a space - if strings.HasSuffix(line, " ") { - return fmt.Errorf("Help for %q should not end with a space: %s", cmd, line) - } - - } - - // For each command make sure we generate an error - // if we give a bad arg - args = strings.Split(cmd+" --badArg", " ") - - out, _, err = dockerCmdWithError(args...) - if err == nil { - return fmt.Errorf(out) - } - - // Be really picky - if strings.HasSuffix(stderr, "\n\n") { - return fmt.Errorf("Should not have a blank line at the end of 'docker rm'\n") - } - - // Now make sure that each command will print a short-usage - // (not a full usage - meaning no opts section) if we - // are missing a required arg or pass in a bad arg - - // These commands will never print a short-usage so don't test - noShortUsage := map[string]string{ - "images": "", - "login": "", - "logout": "", - "network": "", - "stats": "", - "volume create": "", - } - - if _, ok := noShortUsage[cmd]; !ok { - // skipNoArgs are ones that we don't want to try w/o - // any args. Either because it'll hang the test or - // lead to incorrect test result (like false negative). - // Whatever the reason, skip trying to run w/o args and - // jump to trying with a bogus arg. - skipNoArgs := map[string]struct{}{ - "daemon": {}, - "events": {}, - "load": {}, - } - - var result *icmd.Result - if _, ok := skipNoArgs[cmd]; !ok { - result = dockerCmdWithResult(strings.Split(cmd, " ")...) - } - - // If its ok w/o any args then try again with an arg - if result == nil || result.ExitCode == 0 { - result = dockerCmdWithResult(strings.Split(cmd+" badArg", " ")...) - } - - if err := result.Compare(icmd.Expected{ - Out: icmd.None, - Err: "\nUsage:", - ExitCode: 1, - }); err != nil { - return err - } - - stderr := result.Stderr() - // Shouldn't have full usage - if strings.Contains(stderr, "--help=false") { - return fmt.Errorf("Should not have full usage on %q:%v", result.Cmd.Args, stderr) - } - if strings.HasSuffix(stderr, "\n\n") { - return fmt.Errorf("Should not have a blank line on %q\n%v", result.Cmd.Args, stderr) - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_history_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_history_test.go deleted file mode 100644 index 9979080..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_history_test.go +++ /dev/null @@ -1,121 +0,0 @@ -package main - -import ( - "fmt" - "regexp" - "strconv" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// This is a heisen-test. Because the created timestamp of images and the behavior of -// sort is not predictable it doesn't always fail. -func (s *DockerSuite) TestBuildHistory(c *check.C) { - name := "testbuildhistory" - _, err := buildImage(name, `FROM `+minimalBaseImage()+` -LABEL label.A="A" -LABEL label.B="B" -LABEL label.C="C" -LABEL label.D="D" -LABEL label.E="E" -LABEL label.F="F" -LABEL label.G="G" -LABEL label.H="H" -LABEL label.I="I" -LABEL label.J="J" -LABEL label.K="K" -LABEL label.L="L" -LABEL label.M="M" -LABEL label.N="N" -LABEL label.O="O" -LABEL label.P="P" -LABEL label.Q="Q" -LABEL label.R="R" -LABEL label.S="S" -LABEL label.T="T" -LABEL label.U="U" -LABEL label.V="V" -LABEL label.W="W" -LABEL label.X="X" -LABEL label.Y="Y" -LABEL label.Z="Z"`, - true) - - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "history", "testbuildhistory") - actualValues := strings.Split(out, "\n")[1:27] - expectedValues := [26]string{"Z", "Y", "X", "W", "V", "U", "T", "S", "R", "Q", "P", "O", "N", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"} - - for i := 0; i < 26; i++ { - echoValue := fmt.Sprintf("LABEL label.%s=%s", expectedValues[i], expectedValues[i]) - actualValue := actualValues[i] - c.Assert(actualValue, checker.Contains, echoValue) - } - -} - -func (s *DockerSuite) TestHistoryExistentImage(c *check.C) { - dockerCmd(c, "history", "busybox") -} - -func (s *DockerSuite) TestHistoryNonExistentImage(c *check.C) { - _, _, err := dockerCmdWithError("history", "testHistoryNonExistentImage") - c.Assert(err, checker.NotNil, check.Commentf("history on a non-existent image should fail.")) -} - -func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) { - name := "testhistoryimagewithcomment" - - // make an image through docker commit [ -m messages ] - - dockerCmd(c, "run", "--name", name, "busybox", "true") - dockerCmd(c, "wait", name) - - comment := "This_is_a_comment" - dockerCmd(c, "commit", "-m="+comment, name, name) - - // test docker history to check comment messages - - out, _ := dockerCmd(c, "history", name) - outputTabs := strings.Fields(strings.Split(out, "\n")[1]) - actualValue := outputTabs[len(outputTabs)-1] - c.Assert(actualValue, checker.Contains, comment) -} - -func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) { - out, _ := dockerCmd(c, "history", "--human=false", "busybox") - lines := strings.Split(out, "\n") - sizeColumnRegex, _ := regexp.Compile("SIZE +") - indices := sizeColumnRegex.FindStringIndex(lines[0]) - startIndex := indices[0] - endIndex := indices[1] - for i := 1; i < len(lines)-1; i++ { - if endIndex > len(lines[i]) { - endIndex = len(lines[i]) - } - sizeString := lines[i][startIndex:endIndex] - - _, err := strconv.Atoi(strings.TrimSpace(sizeString)) - c.Assert(err, checker.IsNil, check.Commentf("The size '%s' was not an Integer", sizeString)) - } -} - -func (s *DockerSuite) TestHistoryHumanOptionTrue(c *check.C) { - out, _ := dockerCmd(c, "history", "--human=true", "busybox") - lines := strings.Split(out, "\n") - sizeColumnRegex, _ := regexp.Compile("SIZE +") - humanSizeRegexRaw := "\\d+.*B" // Matches human sizes like 10 MB, 3.2 KB, etc - indices := sizeColumnRegex.FindStringIndex(lines[0]) - startIndex := indices[0] - endIndex := indices[1] - for i := 1; i < len(lines)-1; i++ { - if endIndex > len(lines[i]) { - endIndex = len(lines[i]) - } - sizeString := lines[i][startIndex:endIndex] - c.Assert(strings.TrimSpace(sizeString), checker.Matches, humanSizeRegexRaw, check.Commentf("The size '%s' was not in human format", sizeString)) - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_images_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_images_test.go deleted file mode 100644 index 3b678a2..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_images_test.go +++ /dev/null @@ -1,364 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "reflect" - "sort" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/stringid" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestImagesEnsureImageIsListed(c *check.C) { - imagesOut, _ := dockerCmd(c, "images") - c.Assert(imagesOut, checker.Contains, "busybox") -} - -func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *check.C) { - name := "imagewithtag" - dockerCmd(c, "tag", "busybox", name+":v1") - dockerCmd(c, "tag", "busybox", name+":v1v1") - dockerCmd(c, "tag", "busybox", name+":v2") - - imagesOut, _ := dockerCmd(c, "images", name+":v1") - c.Assert(imagesOut, checker.Contains, name) - c.Assert(imagesOut, checker.Contains, "v1") - c.Assert(imagesOut, checker.Not(checker.Contains), "v2") - c.Assert(imagesOut, checker.Not(checker.Contains), "v1v1") - - imagesOut, _ = dockerCmd(c, "images", name) - c.Assert(imagesOut, checker.Contains, name) - c.Assert(imagesOut, checker.Contains, "v1") - c.Assert(imagesOut, checker.Contains, "v1v1") - c.Assert(imagesOut, checker.Contains, "v2") -} - -func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *check.C) { - imagesOut, _ := dockerCmd(c, "images", "busybox:nonexistent") - c.Assert(imagesOut, checker.Not(checker.Contains), "busybox") -} - -func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) { - id1, err := buildImage("order:test_a", - `FROM busybox - MAINTAINER dockerio1`, true) - c.Assert(err, checker.IsNil) - time.Sleep(1 * time.Second) - id2, err := buildImage("order:test_c", - `FROM busybox - MAINTAINER dockerio2`, true) - c.Assert(err, checker.IsNil) - time.Sleep(1 * time.Second) - id3, err := buildImage("order:test_b", - `FROM busybox - MAINTAINER dockerio3`, true) - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "images", "-q", "--no-trunc") - imgs := strings.Split(out, "\n") - c.Assert(imgs[0], checker.Equals, id3, check.Commentf("First image must be %s, got %s", id3, imgs[0])) - c.Assert(imgs[1], checker.Equals, id2, check.Commentf("First image must be %s, got %s", id2, imgs[1])) - c.Assert(imgs[2], checker.Equals, id1, check.Commentf("First image must be %s, got %s", id1, imgs[2])) -} - -func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *check.C) { - out, _, err := dockerCmdWithError("images", "-f", "FOO=123") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "Invalid filter") -} - -func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) { - imageName1 := "images_filter_test1" - imageName2 := "images_filter_test2" - imageName3 := "images_filter_test3" - image1ID, err := buildImage(imageName1, - `FROM busybox - LABEL match me`, true) - c.Assert(err, check.IsNil) - - image2ID, err := buildImage(imageName2, - `FROM busybox - LABEL match="me too"`, true) - c.Assert(err, check.IsNil) - - image3ID, err := buildImage(imageName3, - `FROM busybox - LABEL nomatch me`, true) - c.Assert(err, check.IsNil) - - out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match") - out = strings.TrimSpace(out) - c.Assert(out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image1ID)) - c.Assert(out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image2ID)) - c.Assert(out, check.Not(check.Matches), fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image3ID)) - - out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match=me too") - out = strings.TrimSpace(out) - c.Assert(out, check.Equals, image2ID) -} - -// Regression : #15659 -func (s *DockerSuite) TestImagesFilterLabelWithCommit(c *check.C) { - // Create a container - dockerCmd(c, "run", "--name", "bar", "busybox", "/bin/sh") - // Commit with labels "using changes" - out, _ := dockerCmd(c, "commit", "-c", "LABEL foo.version=1.0.0-1", "-c", "LABEL foo.name=bar", "-c", "LABEL foo.author=starlord", "bar", "bar:1.0.0-1") - imageID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=foo.version=1.0.0-1") - out = strings.TrimSpace(out) - c.Assert(out, check.Equals, imageID) -} - -func (s *DockerSuite) TestImagesFilterSinceAndBefore(c *check.C) { - imageID1, err := buildImage("image:1", `FROM `+minimalBaseImage()+` -LABEL number=1`, true) - c.Assert(err, checker.IsNil) - imageID2, err := buildImage("image:2", `FROM `+minimalBaseImage()+` -LABEL number=2`, true) - c.Assert(err, checker.IsNil) - imageID3, err := buildImage("image:3", `FROM `+minimalBaseImage()+` -LABEL number=3`, true) - c.Assert(err, checker.IsNil) - - expected := []string{imageID3, imageID2} - - out, _ := dockerCmd(c, "images", "-f", "since=image:1", "image") - c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out)) - - out, _ = dockerCmd(c, "images", "-f", "since="+imageID1, "image") - c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out)) - - expected = []string{imageID3} - - out, _ = dockerCmd(c, "images", "-f", "since=image:2", "image") - c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out)) - - out, _ = dockerCmd(c, "images", "-f", "since="+imageID2, "image") - c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out)) - - expected = []string{imageID2, imageID1} - - out, _ = dockerCmd(c, "images", "-f", "before=image:3", "image") - c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out)) - - out, _ = dockerCmd(c, "images", "-f", "before="+imageID3, "image") - c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out)) - - expected = []string{imageID1} - - out, _ = dockerCmd(c, "images", "-f", "before=image:2", "image") - c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out)) - - out, _ = dockerCmd(c, "images", "-f", "before="+imageID2, "image") - c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out)) -} - -func assertImageList(out string, expected []string) bool { - lines := strings.Split(strings.Trim(out, "\n "), "\n") - - if len(lines)-1 != len(expected) { - return false - } - - imageIDIndex := strings.Index(lines[0], "IMAGE ID") - for i := 0; i < len(expected); i++ { - imageID := lines[i+1][imageIDIndex : imageIDIndex+12] - found := false - for _, e := range expected { - if imageID == e[7:19] { - found = true - break - } - } - if !found { - return false - } - } - - return true -} - -func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) { - imageName := "images_filter_test" - buildImage(imageName, - `FROM busybox - RUN touch /test/foo - RUN touch /test/bar - RUN touch /test/baz`, true) - - filters := []string{ - "dangling=true", - "Dangling=true", - " dangling=true", - "dangling=true ", - "dangling = true", - } - - imageListings := make([][]string, 5, 5) - for idx, filter := range filters { - out, _ := dockerCmd(c, "images", "-q", "-f", filter) - listing := strings.Split(out, "\n") - sort.Strings(listing) - imageListings[idx] = listing - } - - for idx, listing := range imageListings { - if idx < 4 && !reflect.DeepEqual(listing, imageListings[idx+1]) { - for idx, errListing := range imageListings { - fmt.Printf("out %d\n", idx) - for _, image := range errListing { - fmt.Print(image) - } - fmt.Print("") - } - c.Fatalf("All output must be the same") - } - } -} - -func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) { - testRequires(c, DaemonIsLinux) - // create container 1 - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - containerID1 := strings.TrimSpace(out) - - // tag as foobox - out, _ = dockerCmd(c, "commit", containerID1, "foobox") - imageID := stringid.TruncateID(strings.TrimSpace(out)) - - // overwrite the tag, making the previous image dangling - dockerCmd(c, "tag", "busybox", "foobox") - - out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true") - // Expect one dangling image - c.Assert(strings.Count(out, imageID), checker.Equals, 1) - - out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=false") - //dangling=false would not include dangling images - c.Assert(out, checker.Not(checker.Contains), imageID) - - out, _ = dockerCmd(c, "images") - //docker images still include dangling images - c.Assert(out, checker.Contains, imageID) - -} - -func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) { - out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, "Invalid filter") -} - -func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) { - dockerfile := ` - FROM busybox - MAINTAINER docker - ENV foo bar` - - head, out, err := buildImageWithOut("scratch-image", dockerfile, false) - c.Assert(err, check.IsNil) - - // this is just the output of docker build - // we're interested in getting the image id of the MAINTAINER instruction - // and that's located at output, line 5, from 7 to end - split := strings.Split(out, "\n") - intermediate := strings.TrimSpace(split[5][7:]) - - out, _ = dockerCmd(c, "images") - // images shouldn't show non-heads images - c.Assert(out, checker.Not(checker.Contains), intermediate) - // images should contain final built images - c.Assert(out, checker.Contains, stringid.TruncateID(head)) -} - -func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support FROM scratch - - dockerfile := ` - FROM scratch - MAINTAINER docker` - - id, _, err := buildImageWithOut("scratch-image", dockerfile, false) - c.Assert(err, check.IsNil) - - out, _ := dockerCmd(c, "images") - // images should contain images built from scratch - c.Assert(out, checker.Contains, stringid.TruncateID(id)) -} - -// For W2W - equivalent to TestImagesEnsureImagesFromScratchShown but Windows -// doesn't support from scratch -func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *check.C) { - dockerfile := ` - FROM busybox - MAINTAINER docker` - - id, _, err := buildImageWithOut("busybox-image", dockerfile, false) - c.Assert(err, check.IsNil) - - out, _ := dockerCmd(c, "images") - // images should contain images built from busybox - c.Assert(out, checker.Contains, stringid.TruncateID(id)) -} - -// #18181 -func (s *DockerSuite) TestImagesFilterNameWithPort(c *check.C) { - tag := "a.b.c.d:5000/hello" - dockerCmd(c, "tag", "busybox", tag) - out, _ := dockerCmd(c, "images", tag) - c.Assert(out, checker.Contains, tag) - - out, _ = dockerCmd(c, "images", tag+":latest") - c.Assert(out, checker.Contains, tag) - - out, _ = dockerCmd(c, "images", tag+":no-such-tag") - c.Assert(out, checker.Not(checker.Contains), tag) -} - -func (s *DockerSuite) TestImagesFormat(c *check.C) { - // testRequires(c, DaemonIsLinux) - tag := "myimage" - dockerCmd(c, "tag", "busybox", tag+":v1") - dockerCmd(c, "tag", "busybox", tag+":v2") - - out, _ := dockerCmd(c, "images", "--format", "{{.Repository}}", tag) - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - - expected := []string{"myimage", "myimage"} - var names []string - names = append(names, lines...) - c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names)) -} - -// ImagesDefaultFormatAndQuiet -func (s *DockerSuite) TestImagesFormatDefaultFormat(c *check.C) { - testRequires(c, DaemonIsLinux) - - // create container 1 - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - containerID1 := strings.TrimSpace(out) - - // tag as foobox - out, _ = dockerCmd(c, "commit", containerID1, "myimage") - imageID := stringid.TruncateID(strings.TrimSpace(out)) - - config := `{ - "imagesFormat": "{{ .ID }} default" -}` - d, err := ioutil.TempDir("", "integration-cli-") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(d) - - err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644) - c.Assert(err, checker.IsNil) - - out, _ = dockerCmd(c, "--config", d, "images", "-q", "myimage") - c.Assert(out, checker.Equals, imageID+"\n", check.Commentf("Expected to print only the image id, got %v\n", out)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_import_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_import_test.go deleted file mode 100644 index 57dc2a6..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_import_test.go +++ /dev/null @@ -1,150 +0,0 @@ -package main - -import ( - "bufio" - "compress/gzip" - "io/ioutil" - "os" - "os/exec" - "regexp" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestImportDisplay(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - cleanedContainerID := strings.TrimSpace(out) - - out, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "export", cleanedContainerID), - exec.Command(dockerBinary, "import", "-"), - ) - c.Assert(err, checker.IsNil) - - c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't")) - - image := strings.TrimSpace(out) - out, _ = dockerCmd(c, "run", "--rm", image, "true") - c.Assert(out, checker.Equals, "", check.Commentf("command output should've been nothing.")) -} - -func (s *DockerSuite) TestImportBadURL(c *check.C) { - out, _, err := dockerCmdWithError("import", "http://nourl/bad") - c.Assert(err, checker.NotNil, check.Commentf("import was supposed to fail but didn't")) - // Depending on your system you can get either of these errors - if !strings.Contains(out, "dial tcp") && - !strings.Contains(out, "ApplyLayer exit status 1 stdout: stderr: archive/tar: invalid tar header") && - !strings.Contains(out, "Error processing tar file") { - c.Fatalf("expected an error msg but didn't get one.\nErr: %v\nOut: %v", err, out) - } -} - -func (s *DockerSuite) TestImportFile(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "--name", "test-import", "busybox", "true") - - temporaryFile, err := ioutil.TempFile("", "exportImportTest") - c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file")) - defer os.Remove(temporaryFile.Name()) - - runCmd := exec.Command(dockerBinary, "export", "test-import") - runCmd.Stdout = bufio.NewWriter(temporaryFile) - - _, err = runCommand(runCmd) - c.Assert(err, checker.IsNil, check.Commentf("failed to export a container")) - - out, _ := dockerCmd(c, "import", temporaryFile.Name()) - c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't")) - image := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "run", "--rm", image, "true") - c.Assert(out, checker.Equals, "", check.Commentf("command output should've been nothing.")) -} - -func (s *DockerSuite) TestImportGzipped(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "--name", "test-import", "busybox", "true") - - temporaryFile, err := ioutil.TempFile("", "exportImportTest") - c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file")) - defer os.Remove(temporaryFile.Name()) - - runCmd := exec.Command(dockerBinary, "export", "test-import") - w := gzip.NewWriter(temporaryFile) - runCmd.Stdout = w - - _, err = runCommand(runCmd) - c.Assert(err, checker.IsNil, check.Commentf("failed to export a container")) - err = w.Close() - c.Assert(err, checker.IsNil, check.Commentf("failed to close gzip writer")) - temporaryFile.Close() - out, _ := dockerCmd(c, "import", temporaryFile.Name()) - c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't")) - image := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "run", "--rm", image, "true") - c.Assert(out, checker.Equals, "", check.Commentf("command output should've been nothing.")) -} - -func (s *DockerSuite) TestImportFileWithMessage(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "--name", "test-import", "busybox", "true") - - temporaryFile, err := ioutil.TempFile("", "exportImportTest") - c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file")) - defer os.Remove(temporaryFile.Name()) - - runCmd := exec.Command(dockerBinary, "export", "test-import") - runCmd.Stdout = bufio.NewWriter(temporaryFile) - - _, err = runCommand(runCmd) - c.Assert(err, checker.IsNil, check.Commentf("failed to export a container")) - - message := "Testing commit message" - out, _ := dockerCmd(c, "import", "-m", message, temporaryFile.Name()) - c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't")) - image := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "history", image) - split := strings.Split(out, "\n") - - c.Assert(split, checker.HasLen, 3, check.Commentf("expected 3 lines from image history")) - r := regexp.MustCompile("[\\s]{2,}") - split = r.Split(split[1], -1) - - c.Assert(message, checker.Equals, split[3], check.Commentf("didn't get expected value in commit message")) - - out, _ = dockerCmd(c, "run", "--rm", image, "true") - c.Assert(out, checker.Equals, "", check.Commentf("command output should've been nothing")) -} - -func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) { - _, _, err := dockerCmdWithError("import", "example.com/myImage.tar") - c.Assert(err, checker.NotNil, check.Commentf("import non-existing file must failed")) -} - -func (s *DockerSuite) TestImportWithQuotedChanges(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "--name", "test-import", "busybox", "true") - - temporaryFile, err := ioutil.TempFile("", "exportImportTest") - c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file")) - defer os.Remove(temporaryFile.Name()) - - result := icmd.RunCmd(icmd.Cmd{ - Command: binaryWithArgs("export", "test-import"), - Stdout: bufio.NewWriter(temporaryFile), - }) - c.Assert(result, icmd.Matches, icmd.Success) - - result = dockerCmdWithResult("import", "-c", `ENTRYPOINT ["/bin/sh", "-c"]`, temporaryFile.Name()) - c.Assert(result, icmd.Matches, icmd.Success) - image := strings.TrimSpace(result.Stdout()) - - result = dockerCmdWithResult("run", "--rm", image, "true") - c.Assert(result, icmd.Matches, icmd.Expected{Out: icmd.None}) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_info_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_info_test.go deleted file mode 100644 index 62ce7e2..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_info_test.go +++ /dev/null @@ -1,234 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "net" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// ensure docker info succeeds -func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) { - out, _ := dockerCmd(c, "info") - - // always shown fields - stringsToCheck := []string{ - "ID:", - "Containers:", - " Running:", - " Paused:", - " Stopped:", - "Images:", - "OSType:", - "Architecture:", - "Logging Driver:", - "Operating System:", - "CPUs:", - "Total Memory:", - "Kernel Version:", - "Storage Driver:", - "Volume:", - "Network:", - "Live Restore Enabled:", - } - - if daemonPlatform == "linux" { - stringsToCheck = append(stringsToCheck, "Init Binary:", "Security Options:", "containerd version:", "runc version:", "init version:") - } - - if DaemonIsLinux.Condition() { - stringsToCheck = append(stringsToCheck, "Runtimes:", "Default Runtime: runc") - } - - if experimentalDaemon { - stringsToCheck = append(stringsToCheck, "Experimental: true") - } else { - stringsToCheck = append(stringsToCheck, "Experimental: false") - } - - for _, linePrefix := range stringsToCheck { - c.Assert(out, checker.Contains, linePrefix, check.Commentf("couldn't find string %v in output", linePrefix)) - } -} - -// TestInfoFormat tests `docker info --format` -func (s *DockerSuite) TestInfoFormat(c *check.C) { - out, status := dockerCmd(c, "info", "--format", "{{json .}}") - c.Assert(status, checker.Equals, 0) - var m map[string]interface{} - err := json.Unmarshal([]byte(out), &m) - c.Assert(err, checker.IsNil) - _, _, err = dockerCmdWithError("info", "--format", "{{.badString}}") - c.Assert(err, checker.NotNil) -} - -// TestInfoDiscoveryBackend verifies that a daemon run with `--cluster-advertise` and -// `--cluster-store` properly show the backend's endpoint in info output. -func (s *DockerSuite) TestInfoDiscoveryBackend(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - d := NewDaemon(c) - discoveryBackend := "consul://consuladdr:consulport/some/path" - discoveryAdvertise := "1.1.1.1:2375" - err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s", discoveryAdvertise)) - c.Assert(err, checker.IsNil) - defer d.Stop() - - out, err := d.Cmd("info") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend)) - c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s\n", discoveryAdvertise)) -} - -// TestInfoDiscoveryInvalidAdvertise verifies that a daemon run with -// an invalid `--cluster-advertise` configuration -func (s *DockerSuite) TestInfoDiscoveryInvalidAdvertise(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - d := NewDaemon(c) - discoveryBackend := "consul://consuladdr:consulport/some/path" - - // --cluster-advertise with an invalid string is an error - err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), "--cluster-advertise=invalid") - c.Assert(err, checker.Not(checker.IsNil)) - - // --cluster-advertise without --cluster-store is also an error - err = d.Start("--cluster-advertise=1.1.1.1:2375") - c.Assert(err, checker.Not(checker.IsNil)) -} - -// TestInfoDiscoveryAdvertiseInterfaceName verifies that a daemon run with `--cluster-advertise` -// configured with interface name properly show the advertise ip-address in info output. -func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) { - testRequires(c, SameHostDaemon, Network, DaemonIsLinux) - - d := NewDaemon(c) - discoveryBackend := "consul://consuladdr:consulport/some/path" - discoveryAdvertise := "eth0" - - err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s:2375", discoveryAdvertise)) - c.Assert(err, checker.IsNil) - defer d.Stop() - - iface, err := net.InterfaceByName(discoveryAdvertise) - c.Assert(err, checker.IsNil) - addrs, err := iface.Addrs() - c.Assert(err, checker.IsNil) - c.Assert(len(addrs), checker.GreaterThan, 0) - ip, _, err := net.ParseCIDR(addrs[0].String()) - c.Assert(err, checker.IsNil) - - out, err := d.Cmd("info") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend)) - c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s:2375\n", ip.String())) -} - -func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *check.C) { - testRequires(c, DaemonIsLinux) - - dockerCmd(c, "run", "-d", "busybox", "top") - out, _ := dockerCmd(c, "info") - c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1)) - c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 1)) - c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0)) - c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0)) -} - -func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) { - testRequires(c, IsPausable) - - out, _ := runSleepingContainer(c, "-d") - cleanedContainerID := strings.TrimSpace(out) - - dockerCmd(c, "pause", cleanedContainerID) - - out, _ = dockerCmd(c, "info") - c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1)) - c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0)) - c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 1)) - c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0)) -} - -func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) { - testRequires(c, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - cleanedContainerID := strings.TrimSpace(out) - - dockerCmd(c, "stop", cleanedContainerID) - - out, _ = dockerCmd(c, "info") - c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1)) - c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0)) - c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0)) - c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 1)) -} - -func (s *DockerSuite) TestInfoDebug(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - d := NewDaemon(c) - err := d.Start("--debug") - c.Assert(err, checker.IsNil) - defer d.Stop() - - out, err := d.Cmd("--debug", "info") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "Debug Mode (client): true\n") - c.Assert(out, checker.Contains, "Debug Mode (server): true\n") - c.Assert(out, checker.Contains, "File Descriptors") - c.Assert(out, checker.Contains, "Goroutines") - c.Assert(out, checker.Contains, "System Time") - c.Assert(out, checker.Contains, "EventsListeners") - c.Assert(out, checker.Contains, "Docker Root Dir") -} - -func (s *DockerSuite) TestInsecureRegistries(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - registryCIDR := "192.168.1.0/24" - registryHost := "insecurehost.com:5000" - - d := NewDaemon(c) - err := d.Start("--insecure-registry="+registryCIDR, "--insecure-registry="+registryHost) - c.Assert(err, checker.IsNil) - defer d.Stop() - - out, err := d.Cmd("info") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "Insecure Registries:\n") - c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryHost)) - c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryCIDR)) -} - -func (s *DockerDaemonSuite) TestRegistryMirrors(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - registryMirror1 := "https://192.168.1.2" - registryMirror2 := "http://registry.mirror.com:5000" - - err := s.d.Start("--registry-mirror="+registryMirror1, "--registry-mirror="+registryMirror2) - c.Assert(err, checker.IsNil) - - out, err := s.d.Cmd("info") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "Registry Mirrors:\n") - c.Assert(out, checker.Contains, fmt.Sprintf(" %s", registryMirror1)) - c.Assert(out, checker.Contains, fmt.Sprintf(" %s", registryMirror2)) -} - -// Test case for #24392 -func (s *DockerDaemonSuite) TestInfoLabels(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - err := s.d.Start("--label", `test.empty=`, "--label", `test.empty=`, "--label", `test.label="1"`, "--label", `test.label="2"`) - c.Assert(err, checker.IsNil) - - out, err := s.d.Cmd("info") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "WARNING: labels with duplicate keys and conflicting values have been deprecated") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_info_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_info_unix_test.go deleted file mode 100644 index b932306..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_info_unix_test.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build !windows - -package main - -import ( - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestInfoSecurityOptions(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled, Apparmor, DaemonIsLinux) - - out, _ := dockerCmd(c, "info") - c.Assert(out, checker.Contains, "Security Options:\n apparmor\n seccomp\n Profile: default\n") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_inspect_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_inspect_test.go deleted file mode 100644 index 32ed28a..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_inspect_test.go +++ /dev/null @@ -1,466 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "strconv" - "strings" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func checkValidGraphDriver(c *check.C, name string) { - if name != "devicemapper" && name != "overlay" && name != "vfs" && name != "zfs" && name != "btrfs" && name != "aufs" { - c.Fatalf("%v is not a valid graph driver name", name) - } -} - -func (s *DockerSuite) TestInspectImage(c *check.C) { - testRequires(c, DaemonIsLinux) - imageTest := "emptyfs" - // It is important that this ID remain stable. If a code change causes - // it to be different, this is equivalent to a cache bust when pulling - // a legacy-format manifest. If the check at the end of this function - // fails, fix the difference in the image serialization instead of - // updating this hash. - imageTestID := "sha256:11f64303f0f7ffdc71f001788132bca5346831939a956e3e975c93267d89a16d" - id := inspectField(c, imageTest, "Id") - - c.Assert(id, checker.Equals, imageTestID) -} - -func (s *DockerSuite) TestInspectInt64(c *check.C) { - dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true") - inspectOut := inspectField(c, "inspectTest", "HostConfig.Memory") - c.Assert(inspectOut, checker.Equals, "314572800") -} - -func (s *DockerSuite) TestInspectDefault(c *check.C) { - //Both the container and image are named busybox. docker inspect will fetch the container JSON. - //If the container JSON is not available, it will go for the image JSON. - - out, _ := dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") - containerID := strings.TrimSpace(out) - - inspectOut := inspectField(c, "busybox", "Id") - c.Assert(strings.TrimSpace(inspectOut), checker.Equals, containerID) -} - -func (s *DockerSuite) TestInspectStatus(c *check.C) { - if daemonPlatform != "windows" { - defer unpauseAllContainers() - } - out, _ := runSleepingContainer(c, "-d") - out = strings.TrimSpace(out) - - inspectOut := inspectField(c, out, "State.Status") - c.Assert(inspectOut, checker.Equals, "running") - - // Windows does not support pause/unpause on Windows Server Containers. - // (RS1 does for Hyper-V Containers, but production CI is not setup for that) - if daemonPlatform != "windows" { - dockerCmd(c, "pause", out) - inspectOut = inspectField(c, out, "State.Status") - c.Assert(inspectOut, checker.Equals, "paused") - - dockerCmd(c, "unpause", out) - inspectOut = inspectField(c, out, "State.Status") - c.Assert(inspectOut, checker.Equals, "running") - } - - dockerCmd(c, "stop", out) - inspectOut = inspectField(c, out, "State.Status") - c.Assert(inspectOut, checker.Equals, "exited") - -} - -func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) { - //Both the container and image are named busybox. docker inspect will fetch container - //JSON State.Running field. If the field is true, it's a container. - runSleepingContainer(c, "--name=busybox", "-d") - - formatStr := "--format={{.State.Running}}" - out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox") - c.Assert(out, checker.Equals, "true\n") // not a container JSON -} - -func (s *DockerSuite) TestInspectTypeFlagWithNoContainer(c *check.C) { - //Run this test on an image named busybox. docker inspect will try to fetch container - //JSON. Since there is no container named busybox and --type=container, docker inspect will - //not try to get the image JSON. It will throw an error. - - dockerCmd(c, "run", "-d", "busybox", "true") - - _, _, err := dockerCmdWithError("inspect", "--type=container", "busybox") - // docker inspect should fail, as there is no container named busybox - c.Assert(err, checker.NotNil) -} - -func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) { - //Both the container and image are named busybox. docker inspect will fetch image - //JSON as --type=image. if there is no image with name busybox, docker inspect - //will throw an error. - - dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") - - out, _ := dockerCmd(c, "inspect", "--type=image", "busybox") - c.Assert(out, checker.Not(checker.Contains), "State") // not an image JSON -} - -func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) { - //Both the container and image are named busybox. docker inspect will fail - //as --type=foobar is not a valid value for the flag. - - dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true") - - out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox") - c.Assert(err, checker.NotNil, check.Commentf("%s", exitCode)) - c.Assert(exitCode, checker.Equals, 1, check.Commentf("%s", err)) - c.Assert(out, checker.Contains, "not a valid value for --type") -} - -func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) { - testRequires(c, DaemonIsLinux) - imageTest := "emptyfs" - out := inspectField(c, imageTest, "Size") - - size, err := strconv.Atoi(out) - c.Assert(err, checker.IsNil, check.Commentf("failed to inspect size of the image: %s, %v", out, err)) - - //now see if the size turns out to be the same - formatStr := fmt.Sprintf("--format={{eq .Size %d}}", size) - out, _ = dockerCmd(c, "inspect", formatStr, imageTest) - result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")) - c.Assert(err, checker.IsNil) - c.Assert(result, checker.Equals, true) -} - -func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) { - runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat") - runCmd.Stdin = strings.NewReader("blahblah") - out, _, _, err := runCommandWithStdoutStderr(runCmd) - c.Assert(err, checker.IsNil, check.Commentf("failed to run container: %v, output: %q", err, out)) - - id := strings.TrimSpace(out) - - out = inspectField(c, id, "State.ExitCode") - - exitCode, err := strconv.Atoi(out) - c.Assert(err, checker.IsNil, check.Commentf("failed to inspect exitcode of the container: %s, %v", out, err)) - - //now get the exit code to verify - formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode) - out, _ = dockerCmd(c, "inspect", formatStr, id) - result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")) - c.Assert(err, checker.IsNil) - c.Assert(result, checker.Equals, true) -} - -func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) { - testRequires(c, DaemonIsLinux, Devicemapper) - imageTest := "emptyfs" - name := inspectField(c, imageTest, "GraphDriver.Name") - - checkValidGraphDriver(c, name) - - deviceID := inspectField(c, imageTest, "GraphDriver.Data.DeviceId") - - _, err := strconv.Atoi(deviceID) - c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err)) - - deviceSize := inspectField(c, imageTest, "GraphDriver.Data.DeviceSize") - - _, err = strconv.ParseUint(deviceSize, 10, 64) - c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err)) -} - -func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) { - testRequires(c, DaemonIsLinux, Devicemapper) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - out = strings.TrimSpace(out) - - name := inspectField(c, out, "GraphDriver.Name") - - checkValidGraphDriver(c, name) - - imageDeviceID := inspectField(c, "busybox", "GraphDriver.Data.DeviceId") - - deviceID := inspectField(c, out, "GraphDriver.Data.DeviceId") - - c.Assert(imageDeviceID, checker.Not(checker.Equals), deviceID) - - _, err := strconv.Atoi(deviceID) - c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err)) - - deviceSize := inspectField(c, out, "GraphDriver.Data.DeviceSize") - - _, err = strconv.ParseUint(deviceSize, 10, 64) - c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err)) -} - -func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) { - modifier := ",z" - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - if daemonPlatform == "windows" { - modifier = "" - // TODO Windows: Temporary check - remove once TP5 support is dropped - if windowsDaemonKV < 14350 { - c.Skip("Needs later Windows build for RO volumes") - } - // Linux creates the host directory if it doesn't exist. Windows does not. - os.Mkdir(`c:\data`, os.ModeDir) - } - - dockerCmd(c, "run", "-d", "--name", "test", "-v", prefix+slash+"data:"+prefix+slash+"data:ro"+modifier, "busybox", "cat") - - vol := inspectFieldJSON(c, "test", "Mounts") - - var mp []types.MountPoint - err := json.Unmarshal([]byte(vol), &mp) - c.Assert(err, checker.IsNil) - - // check that there is only one mountpoint - c.Assert(mp, check.HasLen, 1) - - m := mp[0] - - c.Assert(m.Name, checker.Equals, "") - c.Assert(m.Driver, checker.Equals, "") - c.Assert(m.Source, checker.Equals, prefix+slash+"data") - c.Assert(m.Destination, checker.Equals, prefix+slash+"data") - if daemonPlatform != "windows" { // Windows does not set mode - c.Assert(m.Mode, checker.Equals, "ro"+modifier) - } - c.Assert(m.RW, checker.Equals, false) -} - -func (s *DockerSuite) TestInspectNamedMountPoint(c *check.C) { - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - - dockerCmd(c, "run", "-d", "--name", "test", "-v", "data:"+prefix+slash+"data", "busybox", "cat") - - vol := inspectFieldJSON(c, "test", "Mounts") - - var mp []types.MountPoint - err := json.Unmarshal([]byte(vol), &mp) - c.Assert(err, checker.IsNil) - - // check that there is only one mountpoint - c.Assert(mp, checker.HasLen, 1) - - m := mp[0] - - c.Assert(m.Name, checker.Equals, "data") - c.Assert(m.Driver, checker.Equals, "local") - c.Assert(m.Source, checker.Not(checker.Equals), "") - c.Assert(m.Destination, checker.Equals, prefix+slash+"data") - c.Assert(m.RW, checker.Equals, true) -} - -// #14947 -func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - id := strings.TrimSpace(out) - startedAt := inspectField(c, id, "State.StartedAt") - finishedAt := inspectField(c, id, "State.FinishedAt") - created := inspectField(c, id, "Created") - - _, err := time.Parse(time.RFC3339Nano, startedAt) - c.Assert(err, checker.IsNil) - _, err = time.Parse(time.RFC3339Nano, finishedAt) - c.Assert(err, checker.IsNil) - _, err = time.Parse(time.RFC3339Nano, created) - c.Assert(err, checker.IsNil) - - created = inspectField(c, "busybox", "Created") - - _, err = time.Parse(time.RFC3339Nano, created) - c.Assert(err, checker.IsNil) -} - -// #15633 -func (s *DockerSuite) TestInspectLogConfigNoType(c *check.C) { - dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox") - var logConfig container.LogConfig - - out := inspectFieldJSON(c, "test", "HostConfig.LogConfig") - - err := json.NewDecoder(strings.NewReader(out)).Decode(&logConfig) - c.Assert(err, checker.IsNil, check.Commentf("%v", out)) - - c.Assert(logConfig.Type, checker.Equals, "json-file") - c.Assert(logConfig.Config["max-file"], checker.Equals, "42", check.Commentf("%v", logConfig)) -} - -func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) { - - //Both the container and image are named busybox. docker inspect will fetch container - //JSON SizeRw and SizeRootFs field. If there is no flag --size/-s, there are no size fields. - - runSleepingContainer(c, "--name=busybox", "-d") - - formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}" - out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox") - c.Assert(strings.TrimSpace(out), check.Equals, ",", check.Commentf("Exepcted not to display size info: %s", out)) -} - -func (s *DockerSuite) TestInspectSizeFlagContainer(c *check.C) { - runSleepingContainer(c, "--name=busybox", "-d") - - formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'" - out, _ := dockerCmd(c, "inspect", "-s", "--type=container", formatStr, "busybox") - sz := strings.Split(out, ",") - - c.Assert(strings.TrimSpace(sz[0]), check.Not(check.Equals), "") - c.Assert(strings.TrimSpace(sz[1]), check.Not(check.Equals), "") -} - -func (s *DockerSuite) TestInspectTemplateError(c *check.C) { - // Template parsing error for both the container and image. - - runSleepingContainer(c, "--name=container1", "-d") - - out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "container1") - c.Assert(err, check.Not(check.IsNil)) - c.Assert(out, checker.Contains, "Template parsing error") - - out, _, err = dockerCmdWithError("inspect", "--type=image", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox") - c.Assert(err, check.Not(check.IsNil)) - c.Assert(out, checker.Contains, "Template parsing error") -} - -func (s *DockerSuite) TestInspectJSONFields(c *check.C) { - runSleepingContainer(c, "--name=busybox", "-d") - out, _, err := dockerCmdWithError("inspect", "--type=container", "--format={{.HostConfig.Dns}}", "busybox") - - c.Assert(err, check.IsNil) - c.Assert(out, checker.Equals, "[]\n") -} - -func (s *DockerSuite) TestInspectByPrefix(c *check.C) { - id := inspectField(c, "busybox", "Id") - c.Assert(id, checker.HasPrefix, "sha256:") - - id2 := inspectField(c, id[:12], "Id") - c.Assert(id, checker.Equals, id2) - - id3 := inspectField(c, strings.TrimPrefix(id, "sha256:")[:12], "Id") - c.Assert(id, checker.Equals, id3) -} - -func (s *DockerSuite) TestInspectStopWhenNotFound(c *check.C) { - runSleepingContainer(c, "--name=busybox", "-d") - runSleepingContainer(c, "--name=not-shown", "-d") - out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='{{.Name}}'", "busybox", "missing", "not-shown") - - c.Assert(err, checker.Not(check.IsNil)) - c.Assert(out, checker.Contains, "busybox") - c.Assert(out, checker.Not(checker.Contains), "not-shown") - c.Assert(out, checker.Contains, "Error: No such container: missing") -} - -func (s *DockerSuite) TestInspectHistory(c *check.C) { - dockerCmd(c, "run", "--name=testcont", "busybox", "echo", "hello") - dockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg") - out, _, err := dockerCmdWithError("inspect", "--format='{{.Comment}}'", "testimg") - c.Assert(err, check.IsNil) - c.Assert(out, checker.Contains, "test comment") -} - -func (s *DockerSuite) TestInspectContainerNetworkDefault(c *check.C) { - testRequires(c, DaemonIsLinux) - - contName := "test1" - dockerCmd(c, "run", "--name", contName, "-d", "busybox", "top") - netOut, _ := dockerCmd(c, "network", "inspect", "--format={{.ID}}", "bridge") - out := inspectField(c, contName, "NetworkSettings.Networks") - c.Assert(out, checker.Contains, "bridge") - out = inspectField(c, contName, "NetworkSettings.Networks.bridge.NetworkID") - c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(netOut)) -} - -func (s *DockerSuite) TestInspectContainerNetworkCustom(c *check.C) { - testRequires(c, DaemonIsLinux) - - netOut, _ := dockerCmd(c, "network", "create", "net1") - dockerCmd(c, "run", "--name=container1", "--net=net1", "-d", "busybox", "top") - out := inspectField(c, "container1", "NetworkSettings.Networks") - c.Assert(out, checker.Contains, "net1") - out = inspectField(c, "container1", "NetworkSettings.Networks.net1.NetworkID") - c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(netOut)) -} - -func (s *DockerSuite) TestInspectRootFS(c *check.C) { - out, _, err := dockerCmdWithError("inspect", "busybox") - c.Assert(err, check.IsNil) - - var imageJSON []types.ImageInspect - err = json.Unmarshal([]byte(out), &imageJSON) - c.Assert(err, checker.IsNil) - - c.Assert(len(imageJSON[0].RootFS.Layers), checker.GreaterOrEqualThan, 1) -} - -func (s *DockerSuite) TestInspectAmpersand(c *check.C) { - testRequires(c, DaemonIsLinux) - - name := "test" - out, _ := dockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env") - c.Assert(out, checker.Contains, `soanni&rtr`) - out, _ = dockerCmd(c, "inspect", name) - c.Assert(out, checker.Contains, `soanni&rtr`) -} - -func (s *DockerSuite) TestInspectPlugin(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err := dockerCmdWithError("inspect", "--type", "plugin", "--format", "{{.Name}}", pNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, pNameWithTag) - - out, _, err = dockerCmdWithError("inspect", "--format", "{{.Name}}", pNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, pNameWithTag) - - // Even without tag the inspect still work - out, _, err = dockerCmdWithError("inspect", "--type", "plugin", "--format", "{{.Name}}", pNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, pNameWithTag) - - out, _, err = dockerCmdWithError("inspect", "--format", "{{.Name}}", pNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, pNameWithTag) - - _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, pNameWithTag) -} - -// Test case for 29185 -func (s *DockerSuite) TestInspectUnknownObject(c *check.C) { - // This test should work on both Windows and Linux - out, _, err := dockerCmdWithError("inspect", "foobar") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "Error: No such object: foobar") - c.Assert(err.Error(), checker.Contains, "Error: No such object: foobar") -} - -func (s *DockerSuite) TestInpectInvalidReference(c *check.C) { - // This test should work on both Windows and Linux - out, _, err := dockerCmdWithError("inspect", "FooBar") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "Error: No such object: FooBar") - c.Assert(err.Error(), checker.Contains, "Error: No such object: FooBar") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_kill_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_kill_test.go deleted file mode 100644 index 4316480..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_kill_test.go +++ /dev/null @@ -1,134 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestKillContainer(c *check.C) { - out, _ := runSleepingContainer(c, "-d") - cleanedContainerID := strings.TrimSpace(out) - c.Assert(waitRun(cleanedContainerID), check.IsNil) - - dockerCmd(c, "kill", cleanedContainerID) - c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil) - - out, _ = dockerCmd(c, "ps", "-q") - c.Assert(out, checker.Not(checker.Contains), cleanedContainerID, check.Commentf("killed container is still running")) - -} - -func (s *DockerSuite) TestKillOffStoppedContainer(c *check.C) { - out, _ := runSleepingContainer(c, "-d") - cleanedContainerID := strings.TrimSpace(out) - - dockerCmd(c, "stop", cleanedContainerID) - c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil) - - _, _, err := dockerCmdWithError("kill", "-s", "30", cleanedContainerID) - c.Assert(err, check.Not(check.IsNil), check.Commentf("Container %s is not running", cleanedContainerID)) -} - -func (s *DockerSuite) TestKillDifferentUserContainer(c *check.C) { - // TODO Windows: Windows does not yet support -u (Feb 2016). - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-u", "daemon", "-d", "busybox", "top") - cleanedContainerID := strings.TrimSpace(out) - c.Assert(waitRun(cleanedContainerID), check.IsNil) - - dockerCmd(c, "kill", cleanedContainerID) - c.Assert(waitExited(cleanedContainerID, 10*time.Second), check.IsNil) - - out, _ = dockerCmd(c, "ps", "-q") - c.Assert(out, checker.Not(checker.Contains), cleanedContainerID, check.Commentf("killed container is still running")) - -} - -// regression test about correct signal parsing see #13665 -func (s *DockerSuite) TestKillWithSignal(c *check.C) { - // Cannot port to Windows - does not support signals in the same way Linux does - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - cid := strings.TrimSpace(out) - c.Assert(waitRun(cid), check.IsNil) - - dockerCmd(c, "kill", "-s", "SIGWINCH", cid) - time.Sleep(250 * time.Millisecond) - - running := inspectField(c, cid, "State.Running") - - c.Assert(running, checker.Equals, "true", check.Commentf("Container should be in running state after SIGWINCH")) -} - -func (s *DockerSuite) TestKillWithStopSignalWithSameSignalShouldDisableRestartPolicy(c *check.C) { - // Cannot port to Windows - does not support signals int the same way as Linux does - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "--stop-signal=TERM", "--restart=always", "busybox", "top") - cid := strings.TrimSpace(out) - c.Assert(waitRun(cid), check.IsNil) - - // Let docker send a TERM signal to the container - // It will kill the process and disable the restart policy - dockerCmd(c, "kill", "-s", "TERM", cid) - c.Assert(waitExited(cid, 10*time.Second), check.IsNil) - - out, _ = dockerCmd(c, "ps", "-q") - c.Assert(out, checker.Not(checker.Contains), cid, check.Commentf("killed container is still running")) -} - -func (s *DockerSuite) TestKillWithStopSignalWithDifferentSignalShouldKeepRestartPolicy(c *check.C) { - // Cannot port to Windows - does not support signals int the same way as Linux does - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "--stop-signal=CONT", "--restart=always", "busybox", "top") - cid := strings.TrimSpace(out) - c.Assert(waitRun(cid), check.IsNil) - - // Let docker send a TERM signal to the container - // It will kill the process, but not disable the restart policy - dockerCmd(c, "kill", "-s", "TERM", cid) - c.Assert(waitRestart(cid, 10*time.Second), check.IsNil) - - // Restart policy should still be in place, so it should be still running - c.Assert(waitRun(cid), check.IsNil) -} - -// FIXME(vdemeester) should be a unit test -func (s *DockerSuite) TestKillWithInvalidSignal(c *check.C) { - out, _ := runSleepingContainer(c, "-d") - cid := strings.TrimSpace(out) - c.Assert(waitRun(cid), check.IsNil) - - out, _, err := dockerCmdWithError("kill", "-s", "0", cid) - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, "Invalid signal: 0", check.Commentf("Kill with an invalid signal didn't error out correctly")) - - running := inspectField(c, cid, "State.Running") - c.Assert(running, checker.Equals, "true", check.Commentf("Container should be in running state after an invalid signal")) - - out, _ = runSleepingContainer(c, "-d") - cid = strings.TrimSpace(out) - c.Assert(waitRun(cid), check.IsNil) - - out, _, err = dockerCmdWithError("kill", "-s", "SIG42", cid) - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, "Invalid signal: SIG42", check.Commentf("Kill with an invalid signal error out correctly")) - - running = inspectField(c, cid, "State.Running") - c.Assert(running, checker.Equals, "true", check.Commentf("Container should be in running state after an invalid signal")) - -} - -func (s *DockerSuite) TestKillStoppedContainerAPIPre120(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later - runSleepingContainer(c, "--name", "docker-kill-test-api", "-d") - dockerCmd(c, "stop", "docker-kill-test-api") - - status, _, err := sockRequest("POST", fmt.Sprintf("/v1.19/containers/%s/kill", "docker-kill-test-api"), nil) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusNoContent) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_links_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_links_test.go deleted file mode 100644 index a5872d9..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_links_test.go +++ /dev/null @@ -1,240 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "regexp" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/runconfig" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) { - testRequires(c, DaemonIsLinux) - _, exitCode, err := dockerCmdWithError("run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1") - - // run ping failed with error - c.Assert(exitCode, checker.Equals, 1, check.Commentf("error: %v", err)) -} - -// Test for appropriate error when calling --link with an invalid target container -func (s *DockerSuite) TestLinksInvalidContainerTarget(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "--link", "bogus:alias", "busybox", "true") - - // an invalid container target should produce an error - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - // an invalid container target should produce an error - c.Assert(out, checker.Contains, "Could not get container") -} - -func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) { - testRequires(c, DaemonIsLinux) - // Test with the three different ways of specifying the default network on Linux - testLinkPingOnNetwork(c, "") - testLinkPingOnNetwork(c, "default") - testLinkPingOnNetwork(c, "bridge") -} - -func testLinkPingOnNetwork(c *check.C, network string) { - var postArgs []string - if network != "" { - postArgs = append(postArgs, []string{"--net", network}...) - } - postArgs = append(postArgs, []string{"busybox", "top"}...) - runArgs1 := append([]string{"run", "-d", "--name", "container1", "--hostname", "fred"}, postArgs...) - runArgs2 := append([]string{"run", "-d", "--name", "container2", "--hostname", "wilma"}, postArgs...) - - // Run the two named containers - dockerCmd(c, runArgs1...) - dockerCmd(c, runArgs2...) - - postArgs = []string{} - if network != "" { - postArgs = append(postArgs, []string{"--net", network}...) - } - postArgs = append(postArgs, []string{"busybox", "sh", "-c"}...) - - // Format a run for a container which links to the other two - runArgs := append([]string{"run", "--rm", "--link", "container1:alias1", "--link", "container2:alias2"}, postArgs...) - pingCmd := "ping -c 1 %s -W 1 && ping -c 1 %s -W 1" - - // test ping by alias, ping by name, and ping by hostname - // 1. Ping by alias - dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "alias1", "alias2"))...) - // 2. Ping by container name - dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "container1", "container2"))...) - // 3. Ping by hostname - dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...) - - // Clean for next round - dockerCmd(c, "rm", "-f", "container1") - dockerCmd(c, "rm", "-f", "container2") -} - -func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") - idA := strings.TrimSpace(out) - out, _ = dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top") - idB := strings.TrimSpace(out) - dockerCmd(c, "rename", "container1", "container_new") - dockerCmd(c, "run", "--rm", "--link", "container_new:alias1", "--link", "container2:alias2", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1") - dockerCmd(c, "kill", idA) - dockerCmd(c, "kill", idB) - -} - -func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) { - testRequires(c, DaemonIsLinux) - var ( - expected = map[string]struct{}{"/container1:/testinspectlink/alias1": {}, "/container2:/testinspectlink/alias2": {}} - result []string - ) - dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") - dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top") - dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top") - links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links") - - err := json.Unmarshal([]byte(links), &result) - c.Assert(err, checker.IsNil) - - output := convertSliceOfStringsToMap(result) - - c.Assert(output, checker.DeepEquals, expected) -} - -func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) { - testRequires(c, DaemonIsLinux) - var ( - expected = map[string]struct{}{"/container1:/testinspectlink/alias1": {}, "/container2:/testinspectlink/alias2": {}} - result []string - ) - dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") - dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top") - dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true") - links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links") - - err := json.Unmarshal([]byte(links), &result) - c.Assert(err, checker.IsNil) - - output := convertSliceOfStringsToMap(result) - - c.Assert(output, checker.DeepEquals, expected) -} - -func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "create", "--name=first", "busybox", "top") - dockerCmd(c, "create", "--name=second", "--link=first:first", "busybox", "top") - dockerCmd(c, "start", "first") - -} - -func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, SameHostDaemon, ExecSupport) - - out, _ := dockerCmd(c, "run", "-itd", "--name", "one", "busybox", "top") - idOne := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top") - idTwo := strings.TrimSpace(out) - - c.Assert(waitRun(idTwo), checker.IsNil) - - contentOne, err := readContainerFileWithExec(idOne, "/etc/hosts") - c.Assert(err, checker.IsNil, check.Commentf("contentOne: %s", string(contentOne))) - - contentTwo, err := readContainerFileWithExec(idTwo, "/etc/hosts") - c.Assert(err, checker.IsNil, check.Commentf("contentTwo: %s", string(contentTwo))) - // Host is not present in updated hosts file - c.Assert(string(contentTwo), checker.Contains, "onetwo") -} - -func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, SameHostDaemon, ExecSupport) - dockerCmd(c, "run", "-d", "--name", "one", "busybox", "top") - out, _ := dockerCmd(c, "run", "-d", "--name", "two", "--link", "one:onetwo", "--link", "one:one", "busybox", "top") - id := strings.TrimSpace(string(out)) - - realIP := inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress") - content, err := readContainerFileWithExec(id, "/etc/hosts") - c.Assert(err, checker.IsNil) - - getIP := func(hosts []byte, hostname string) string { - re := regexp.MustCompile(fmt.Sprintf(`(\S*)\t%s`, regexp.QuoteMeta(hostname))) - matches := re.FindSubmatch(hosts) - c.Assert(matches, checker.NotNil, check.Commentf("Hostname %s have no matches in hosts", hostname)) - return string(matches[1]) - } - ip := getIP(content, "one") - c.Assert(ip, checker.Equals, realIP) - - ip = getIP(content, "onetwo") - c.Assert(ip, checker.Equals, realIP) - - dockerCmd(c, "restart", "one") - realIP = inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress") - - content, err = readContainerFileWithExec(id, "/etc/hosts") - c.Assert(err, checker.IsNil, check.Commentf("content: %s", string(content))) - ip = getIP(content, "one") - c.Assert(ip, checker.Equals, realIP) - - ip = getIP(content, "onetwo") - c.Assert(ip, checker.Equals, realIP) -} - -func (s *DockerSuite) TestLinksEnvs(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top") - out, _ := dockerCmd(c, "run", "--name=second", "--link=first:first", "busybox", "env") - c.Assert(out, checker.Contains, "FIRST_ENV_e1=\n") - c.Assert(out, checker.Contains, "FIRST_ENV_e2=v2") - c.Assert(out, checker.Contains, "FIRST_ENV_e3=v3=v3") -} - -func (s *DockerSuite) TestLinkShortDefinition(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top") - - cid := strings.TrimSpace(out) - c.Assert(waitRun(cid), checker.IsNil) - - out, _ = dockerCmd(c, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top") - - cid2 := strings.TrimSpace(out) - c.Assert(waitRun(cid2), checker.IsNil) - - links := inspectFieldJSON(c, cid2, "HostConfig.Links") - c.Assert(links, checker.Equals, "[\"/shortlinkdef:/link2/shortlinkdef\"]") -} - -func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - dockerCmd(c, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top") - out, _, err := dockerCmdWithError("run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true") - - // Running container linking to a container with --net host should have failed - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - // Running container linking to a container with --net host should have failed - c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetworkAndLinks.Error()) -} - -func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts") - // /etc/hosts should be a regular file - c.Assert(out, checker.Matches, "^-.+\n") -} - -func (s *DockerSuite) TestLinksMultipleWithSameName(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name=upstream-a", "busybox", "top") - dockerCmd(c, "run", "-d", "--name=upstream-b", "busybox", "top") - dockerCmd(c, "run", "--link", "upstream-a:upstream", "--link", "upstream-b:upstream", "busybox", "sh", "-c", "ping -c 1 upstream") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_links_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_links_unix_test.go deleted file mode 100644 index 1af9279..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_links_unix_test.go +++ /dev/null @@ -1,26 +0,0 @@ -// +build !windows - -package main - -import ( - "io/ioutil" - "os" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestLinksEtcHostsContentMatch(c *check.C) { - // In a _unix file as using Unix specific files, and must be on the - // same host as the daemon. - testRequires(c, SameHostDaemon, NotUserNamespace) - - out, _ := dockerCmd(c, "run", "--net=host", "busybox", "cat", "/etc/hosts") - hosts, err := ioutil.ReadFile("/etc/hosts") - if os.IsNotExist(err) { - c.Skip("/etc/hosts does not exist, skip this test") - } - - c.Assert(out, checker.Equals, string(hosts), check.Commentf("container: %s\n\nhost:%s", out, hosts)) - -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_login_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_login_test.go deleted file mode 100644 index 01de75d..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_login_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "bytes" - "os/exec" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestLoginWithoutTTY(c *check.C) { - cmd := exec.Command(dockerBinary, "login") - - // Send to stdin so the process does not get the TTY - cmd.Stdin = bytes.NewBufferString("buffer test string \n") - - // run the command and block until it's done - err := cmd.Run() - c.Assert(err, checker.NotNil) //"Expected non nil err when loginning in & TTY not available" -} - -func (s *DockerRegistryAuthHtpasswdSuite) TestLoginToPrivateRegistry(c *check.C) { - // wrong credentials - out, _, err := dockerCmdWithError("login", "-u", s.reg.username, "-p", "WRONGPASSWORD", privateRegistryURL) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "401 Unauthorized") - - // now it's fine - dockerCmd(c, "login", "-u", s.reg.username, "-p", s.reg.password, privateRegistryURL) -} - -func (s *DockerRegistryAuthHtpasswdSuite) TestLoginToPrivateRegistryDeprecatedEmailFlag(c *check.C) { - // Test to make sure login still works with the deprecated -e and --email flags - // wrong credentials - out, _, err := dockerCmdWithError("login", "-u", s.reg.username, "-p", "WRONGPASSWORD", "-e", s.reg.email, privateRegistryURL) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "401 Unauthorized") - - // now it's fine - // -e flag - dockerCmd(c, "login", "-u", s.reg.username, "-p", s.reg.password, "-e", s.reg.email, privateRegistryURL) - // --email flag - dockerCmd(c, "login", "-u", s.reg.username, "-p", s.reg.password, "--email", s.reg.email, privateRegistryURL) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_logout_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_logout_test.go deleted file mode 100644 index a5f4b10..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_logout_test.go +++ /dev/null @@ -1,100 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *check.C) { - osPath := os.Getenv("PATH") - defer os.Setenv("PATH", osPath) - - workingDir, err := os.Getwd() - c.Assert(err, checker.IsNil) - absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth")) - c.Assert(err, checker.IsNil) - testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute) - - os.Setenv("PATH", testPath) - - repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL) - - tmp, err := ioutil.TempDir("", "integration-cli-") - c.Assert(err, checker.IsNil) - - externalAuthConfig := `{ "credsStore": "shell-test" }` - - configPath := filepath.Join(tmp, "config.json") - err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "--config", tmp, "login", "-u", s.reg.username, "-p", s.reg.password, privateRegistryURL) - - b, err := ioutil.ReadFile(configPath) - c.Assert(err, checker.IsNil) - c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":") - c.Assert(string(b), checker.Contains, privateRegistryURL) - - dockerCmd(c, "--config", tmp, "tag", "busybox", repoName) - dockerCmd(c, "--config", tmp, "push", repoName) - - dockerCmd(c, "--config", tmp, "logout", privateRegistryURL) - - b, err = ioutil.ReadFile(configPath) - c.Assert(err, checker.IsNil) - c.Assert(string(b), checker.Not(checker.Contains), privateRegistryURL) - - // check I cannot pull anymore - out, _, err := dockerCmdWithError("--config", tmp, "pull", repoName) - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Error: image dockercli/busybox:authtest not found") -} - -// #23100 -func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c *check.C) { - osPath := os.Getenv("PATH") - defer os.Setenv("PATH", osPath) - - workingDir, err := os.Getwd() - c.Assert(err, checker.IsNil) - absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth")) - c.Assert(err, checker.IsNil) - testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute) - - os.Setenv("PATH", testPath) - - cmd := exec.Command("docker-credential-shell-test", "store") - stdin := bytes.NewReader([]byte(fmt.Sprintf(`{"ServerURL": "https://%s", "Username": "%s", "Secret": "%s"}`, privateRegistryURL, s.reg.username, s.reg.password))) - cmd.Stdin = stdin - c.Assert(cmd.Run(), checker.IsNil) - - tmp, err := ioutil.TempDir("", "integration-cli-") - c.Assert(err, checker.IsNil) - - externalAuthConfig := fmt.Sprintf(`{ "auths": {"https://%s": {}}, "credsStore": "shell-test" }`, privateRegistryURL) - - configPath := filepath.Join(tmp, "config.json") - err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "--config", tmp, "login", "-u", s.reg.username, "-p", s.reg.password, privateRegistryURL) - - b, err := ioutil.ReadFile(configPath) - c.Assert(err, checker.IsNil) - c.Assert(string(b), checker.Contains, fmt.Sprintf("\"https://%s\": {}", privateRegistryURL)) - c.Assert(string(b), checker.Contains, fmt.Sprintf("\"%s\": {}", privateRegistryURL)) - - dockerCmd(c, "--config", tmp, "logout", privateRegistryURL) - - b, err = ioutil.ReadFile(configPath) - c.Assert(err, checker.IsNil) - c.Assert(string(b), checker.Not(checker.Contains), fmt.Sprintf("\"https://%s\": {}", privateRegistryURL)) - c.Assert(string(b), checker.Not(checker.Contains), fmt.Sprintf("\"%s\": {}", privateRegistryURL)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_logs_bench_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_logs_bench_test.go deleted file mode 100644 index eeb008d..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_logs_bench_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "fmt" - "strings" - "time" - - "github.com/go-check/check" -) - -func (s *DockerSuite) BenchmarkLogsCLIRotateFollow(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "--log-opt", "max-size=1b", "--log-opt", "max-file=10", "busybox", "sh", "-c", "while true; do usleep 50000; echo hello; done") - id := strings.TrimSpace(out) - ch := make(chan error, 1) - go func() { - ch <- nil - out, _, _ := dockerCmdWithError("logs", "-f", id) - // if this returns at all, it's an error - ch <- fmt.Errorf(out) - }() - - <-ch - select { - case <-time.After(30 * time.Second): - // ran for 30 seconds with no problem - return - case err := <-ch: - if err != nil { - c.Fatal(err) - } - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_logs_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_logs_test.go deleted file mode 100644 index d2dcad1..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_logs_test.go +++ /dev/null @@ -1,328 +0,0 @@ -package main - -import ( - "fmt" - "io" - "os/exec" - "regexp" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/jsonlog" - "github.com/go-check/check" -) - -// This used to work, it test a log of PageSize-1 (gh#4851) -func (s *DockerSuite) TestLogsContainerSmallerThanPage(c *check.C) { - testLen := 32767 - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n = >> a.a; done; echo >> a.a; cat a.a", testLen)) - - id := strings.TrimSpace(out) - dockerCmd(c, "wait", id) - - out, _ = dockerCmd(c, "logs", id) - - c.Assert(out, checker.HasLen, testLen+1) -} - -// Regression test: When going over the PageSize, it used to panic (gh#4851) -func (s *DockerSuite) TestLogsContainerBiggerThanPage(c *check.C) { - testLen := 32768 - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n = >> a.a; done; echo >> a.a; cat a.a", testLen)) - - id := strings.TrimSpace(out) - dockerCmd(c, "wait", id) - - out, _ = dockerCmd(c, "logs", id) - - c.Assert(out, checker.HasLen, testLen+1) -} - -// Regression test: When going much over the PageSize, it used to block (gh#4851) -func (s *DockerSuite) TestLogsContainerMuchBiggerThanPage(c *check.C) { - testLen := 33000 - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n = >> a.a; done; echo >> a.a; cat a.a", testLen)) - - id := strings.TrimSpace(out) - dockerCmd(c, "wait", id) - - out, _ = dockerCmd(c, "logs", id) - - c.Assert(out, checker.HasLen, testLen+1) -} - -func (s *DockerSuite) TestLogsTimestamps(c *check.C) { - testLen := 100 - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo = >> a.a; done; cat a.a", testLen)) - - id := strings.TrimSpace(out) - dockerCmd(c, "wait", id) - - out, _ = dockerCmd(c, "logs", "-t", id) - - lines := strings.Split(out, "\n") - - c.Assert(lines, checker.HasLen, testLen+1) - - ts := regexp.MustCompile(`^.* `) - - for _, l := range lines { - if l != "" { - _, err := time.Parse(jsonlog.RFC3339NanoFixed+" ", ts.FindString(l)) - c.Assert(err, checker.IsNil, check.Commentf("Failed to parse timestamp from %v", l)) - // ensure we have padded 0's - c.Assert(l[29], checker.Equals, uint8('Z')) - } - } -} - -func (s *DockerSuite) TestLogsSeparateStderr(c *check.C) { - msg := "stderr_log" - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)) - - id := strings.TrimSpace(out) - dockerCmd(c, "wait", id) - - stdout, stderr, _ := dockerCmdWithStdoutStderr(c, "logs", id) - - c.Assert(stdout, checker.Equals, "") - - stderr = strings.TrimSpace(stderr) - - c.Assert(stderr, checker.Equals, msg) -} - -func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) { - // TODO Windows: Needs investigation why this fails. Obtained string includes - // a bunch of ANSI escape sequences before the "stderr_log" message. - testRequires(c, DaemonIsLinux) - msg := "stderr_log" - out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)) - - id := strings.TrimSpace(out) - dockerCmd(c, "wait", id) - - stdout, stderr, _ := dockerCmdWithStdoutStderr(c, "logs", id) - c.Assert(stderr, checker.Equals, "") - - stdout = strings.TrimSpace(stdout) - c.Assert(stdout, checker.Equals, msg) -} - -func (s *DockerSuite) TestLogsTail(c *check.C) { - testLen := 100 - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen)) - - id := strings.TrimSpace(out) - dockerCmd(c, "wait", id) - - out, _ = dockerCmd(c, "logs", "--tail", "0", id) - lines := strings.Split(out, "\n") - c.Assert(lines, checker.HasLen, 1) - - out, _ = dockerCmd(c, "logs", "--tail", "5", id) - lines = strings.Split(out, "\n") - c.Assert(lines, checker.HasLen, 6) - - out, _ = dockerCmd(c, "logs", "--tail", "99", id) - lines = strings.Split(out, "\n") - c.Assert(lines, checker.HasLen, 100) - - out, _ = dockerCmd(c, "logs", "--tail", "all", id) - lines = strings.Split(out, "\n") - c.Assert(lines, checker.HasLen, testLen+1) - - out, _ = dockerCmd(c, "logs", "--tail", "-1", id) - lines = strings.Split(out, "\n") - c.Assert(lines, checker.HasLen, testLen+1) - - out, _, _ = dockerCmdWithStdoutStderr(c, "logs", "--tail", "random", id) - lines = strings.Split(out, "\n") - c.Assert(lines, checker.HasLen, testLen+1) -} - -func (s *DockerSuite) TestLogsFollowStopped(c *check.C) { - dockerCmd(c, "run", "--name=test", "busybox", "echo", "hello") - id, err := getIDByName("test") - c.Assert(err, check.IsNil) - - logsCmd := exec.Command(dockerBinary, "logs", "-f", id) - c.Assert(logsCmd.Start(), checker.IsNil) - - errChan := make(chan error) - go func() { - errChan <- logsCmd.Wait() - close(errChan) - }() - - select { - case err := <-errChan: - c.Assert(err, checker.IsNil) - case <-time.After(30 * time.Second): - c.Fatal("Following logs is hanged") - } -} - -func (s *DockerSuite) TestLogsSince(c *check.C) { - name := "testlogssince" - dockerCmd(c, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo log$i; done") - out, _ := dockerCmd(c, "logs", "-t", name) - - log2Line := strings.Split(strings.Split(out, "\n")[1], " ") - t, err := time.Parse(time.RFC3339Nano, log2Line[0]) // the timestamp log2 is written - c.Assert(err, checker.IsNil) - since := t.Unix() + 1 // add 1s so log1 & log2 doesn't show up - out, _ = dockerCmd(c, "logs", "-t", fmt.Sprintf("--since=%v", since), name) - - // Skip 2 seconds - unexpected := []string{"log1", "log2"} - for _, v := range unexpected { - c.Assert(out, checker.Not(checker.Contains), v, check.Commentf("unexpected log message returned, since=%v", since)) - } - - // Test to make sure a bad since format is caught by the client - out, _, _ = dockerCmdWithError("logs", "-t", "--since=2006-01-02T15:04:0Z", name) - c.Assert(out, checker.Contains, "cannot parse \"0Z\" as \"05\"", check.Commentf("bad since format passed to server")) - - // Test with default value specified and parameter omitted - expected := []string{"log1", "log2", "log3"} - for _, cmd := range []*exec.Cmd{ - exec.Command(dockerBinary, "logs", "-t", name), - exec.Command(dockerBinary, "logs", "-t", "--since=0", name), - } { - out, _, err = runCommandWithOutput(cmd) - c.Assert(err, checker.IsNil, check.Commentf("failed to log container: %s", out)) - for _, v := range expected { - c.Assert(out, checker.Contains, v) - } - } -} - -func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) { - // TODO Windows TP5 - Figure out why this test is so flakey. Disabled for now. - testRequires(c, DaemonIsLinux) - name := "testlogssincefuturefollow" - out, _ := dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do echo log$i; sleep 1; done`) - - // Extract one timestamp from the log file to give us a starting point for - // our `--since` argument. Because the log producer runs in the background, - // we need to check repeatedly for some output to be produced. - var timestamp string - for i := 0; i != 100 && timestamp == ""; i++ { - if out, _ = dockerCmd(c, "logs", "-t", name); out == "" { - time.Sleep(time.Millisecond * 100) // Retry - } else { - timestamp = strings.Split(strings.Split(out, "\n")[0], " ")[0] - } - } - - c.Assert(timestamp, checker.Not(checker.Equals), "") - t, err := time.Parse(time.RFC3339Nano, timestamp) - c.Assert(err, check.IsNil) - - since := t.Unix() + 2 - out, _ = dockerCmd(c, "logs", "-t", "-f", fmt.Sprintf("--since=%v", since), name) - c.Assert(out, checker.Not(checker.HasLen), 0, check.Commentf("cannot read from empty log")) - lines := strings.Split(strings.TrimSpace(out), "\n") - for _, v := range lines { - ts, err := time.Parse(time.RFC3339Nano, strings.Split(v, " ")[0]) - c.Assert(err, checker.IsNil, check.Commentf("cannot parse timestamp output from log: '%v'", v)) - c.Assert(ts.Unix() >= since, checker.Equals, true, check.Commentf("earlier log found. since=%v logdate=%v", since, ts)) - } -} - -// Regression test for #8832 -func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) { - // TODO Windows: Fix this test for TP5. - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", `usleep 600000;yes X | head -c 200000`) - - id := strings.TrimSpace(out) - - stopSlowRead := make(chan bool) - - go func() { - exec.Command(dockerBinary, "wait", id).Run() - stopSlowRead <- true - }() - - logCmd := exec.Command(dockerBinary, "logs", "-f", id) - stdout, err := logCmd.StdoutPipe() - c.Assert(err, checker.IsNil) - c.Assert(logCmd.Start(), checker.IsNil) - - // First read slowly - bytes1, err := consumeWithSpeed(stdout, 10, 50*time.Millisecond, stopSlowRead) - c.Assert(err, checker.IsNil) - - // After the container has finished we can continue reading fast - bytes2, err := consumeWithSpeed(stdout, 32*1024, 0, nil) - c.Assert(err, checker.IsNil) - - actual := bytes1 + bytes2 - expected := 200000 - c.Assert(actual, checker.Equals, expected) -} - -func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 2; done") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - nroutines, err := getGoroutineNumber() - c.Assert(err, checker.IsNil) - cmd := exec.Command(dockerBinary, "logs", "-f", id) - r, w := io.Pipe() - cmd.Stdout = w - c.Assert(cmd.Start(), checker.IsNil) - - // Make sure pipe is written to - chErr := make(chan error) - go func() { - b := make([]byte, 1) - _, err := r.Read(b) - chErr <- err - }() - c.Assert(<-chErr, checker.IsNil) - c.Assert(cmd.Process.Kill(), checker.IsNil) - - // NGoroutines is not updated right away, so we need to wait before failing - c.Assert(waitForGoroutines(nroutines), checker.IsNil) -} - -func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 2; done") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - nroutines, err := getGoroutineNumber() - c.Assert(err, checker.IsNil) - cmd := exec.Command(dockerBinary, "logs", "-f", id) - c.Assert(cmd.Start(), checker.IsNil) - time.Sleep(200 * time.Millisecond) - c.Assert(cmd.Process.Kill(), checker.IsNil) - - // NGoroutines is not updated right away, so we need to wait before failing - c.Assert(waitForGoroutines(nroutines), checker.IsNil) -} - -func (s *DockerSuite) TestLogsCLIContainerNotFound(c *check.C) { - name := "testlogsnocontainer" - out, _, _ := dockerCmdWithError("logs", name) - message := fmt.Sprintf("Error: No such container: %s\n", name) - c.Assert(out, checker.Equals, message) -} - -func (s *DockerSuite) TestLogsWithDetails(c *check.C) { - dockerCmd(c, "run", "--name=test", "--label", "foo=bar", "-e", "baz=qux", "--log-opt", "labels=foo", "--log-opt", "env=baz", "busybox", "echo", "hello") - out, _ := dockerCmd(c, "logs", "--details", "--timestamps", "test") - - logFields := strings.Fields(strings.TrimSpace(out)) - c.Assert(len(logFields), checker.Equals, 3, check.Commentf(out)) - - details := strings.Split(logFields[1], ",") - c.Assert(details, checker.HasLen, 2) - c.Assert(details[0], checker.Equals, "baz=qux") - c.Assert(details[1], checker.Equals, "foo=bar") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_nat_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_nat_test.go deleted file mode 100644 index 7f4cc2c..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_nat_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "net" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func startServerContainer(c *check.C, msg string, port int) string { - name := "server" - cmd := []string{ - "-d", - "-p", fmt.Sprintf("%d:%d", port, port), - "busybox", - "sh", "-c", fmt.Sprintf("echo %q | nc -lp %d", msg, port), - } - c.Assert(waitForContainer(name, cmd...), check.IsNil) - return name -} - -func getExternalAddress(c *check.C) net.IP { - iface, err := net.InterfaceByName("eth0") - if err != nil { - c.Skip(fmt.Sprintf("Test not running with `make test`. Interface eth0 not found: %v", err)) - } - - ifaceAddrs, err := iface.Addrs() - c.Assert(err, check.IsNil) - c.Assert(ifaceAddrs, checker.Not(checker.HasLen), 0) - - ifaceIP, _, err := net.ParseCIDR(ifaceAddrs[0].String()) - c.Assert(err, check.IsNil) - - return ifaceIP -} - -func getContainerLogs(c *check.C, containerID string) string { - out, _ := dockerCmd(c, "logs", containerID) - return strings.Trim(out, "\r\n") -} - -func getContainerStatus(c *check.C, containerID string) string { - out := inspectField(c, containerID, "State.Running") - return out -} - -func (s *DockerSuite) TestNetworkNat(c *check.C) { - testRequires(c, DaemonIsLinux, SameHostDaemon) - msg := "it works" - startServerContainer(c, msg, 8080) - endpoint := getExternalAddress(c) - conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", endpoint.String(), 8080)) - c.Assert(err, check.IsNil) - - data, err := ioutil.ReadAll(conn) - conn.Close() - c.Assert(err, check.IsNil) - - final := strings.TrimRight(string(data), "\n") - c.Assert(final, checker.Equals, msg) -} - -func (s *DockerSuite) TestNetworkLocalhostTCPNat(c *check.C) { - testRequires(c, DaemonIsLinux, SameHostDaemon) - var ( - msg = "hi yall" - ) - startServerContainer(c, msg, 8081) - conn, err := net.Dial("tcp", "localhost:8081") - c.Assert(err, check.IsNil) - - data, err := ioutil.ReadAll(conn) - conn.Close() - c.Assert(err, check.IsNil) - - final := strings.TrimRight(string(data), "\n") - c.Assert(final, checker.Equals, msg) -} - -func (s *DockerSuite) TestNetworkLoopbackNat(c *check.C) { - testRequires(c, DaemonIsLinux, SameHostDaemon, NotUserNamespace) - msg := "it works" - startServerContainer(c, msg, 8080) - endpoint := getExternalAddress(c) - out, _ := dockerCmd(c, "run", "-t", "--net=container:server", "busybox", - "sh", "-c", fmt.Sprintf("stty raw && nc -w 5 %s 8080", endpoint.String())) - final := strings.TrimRight(string(out), "\n") - c.Assert(final, checker.Equals, msg) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_netmode_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_netmode_test.go deleted file mode 100644 index 4dfad93..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_netmode_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package main - -import ( - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/runconfig" - "github.com/go-check/check" -) - -// GH14530. Validates combinations of --net= with other options - -// stringCheckPS is how the output of PS starts in order to validate that -// the command executed in a container did really run PS correctly. -const stringCheckPS = "PID USER" - -// DockerCmdWithFail executes a docker command that is supposed to fail and returns -// the output, the exit code. If the command returns a Nil error, it will fail and -// stop the tests. -func dockerCmdWithFail(c *check.C, args ...string) (string, int) { - out, status, err := dockerCmdWithError(args...) - c.Assert(err, check.NotNil, check.Commentf("%v", out)) - return out, status -} - -func (s *DockerSuite) TestNetHostnameWithNetHost(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - - out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ps") - c.Assert(out, checker.Contains, stringCheckPS) -} - -func (s *DockerSuite) TestNetHostname(c *check.C) { - testRequires(c, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-h=name", "busybox", "ps") - c.Assert(out, checker.Contains, stringCheckPS) - - out, _ = dockerCmd(c, "run", "-h=name", "--net=bridge", "busybox", "ps") - c.Assert(out, checker.Contains, stringCheckPS) - - out, _ = dockerCmd(c, "run", "-h=name", "--net=none", "busybox", "ps") - c.Assert(out, checker.Contains, stringCheckPS) - - out, _ = dockerCmdWithFail(c, "run", "-h=name", "--net=container:other", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkHostname.Error()) - - out, _ = dockerCmdWithFail(c, "run", "--net=container", "busybox", "ps") - c.Assert(out, checker.Contains, "--net: invalid net mode: invalid container format container:") - - out, _ = dockerCmdWithFail(c, "run", "--net=weird", "busybox", "ps") - c.Assert(out, checker.Contains, "network weird not found") -} - -func (s *DockerSuite) TestConflictContainerNetworkAndLinks(c *check.C) { - testRequires(c, DaemonIsLinux) - - out, _ := dockerCmdWithFail(c, "run", "--net=container:other", "--link=zip:zap", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictContainerNetworkAndLinks.Error()) -} - -func (s *DockerSuite) TestConflictContainerNetworkHostAndLinks(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - - out, _ := dockerCmdWithFail(c, "run", "--net=host", "--link=zip:zap", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetworkAndLinks.Error()) -} - -func (s *DockerSuite) TestConflictNetworkModeNetHostAndOptions(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - - out, _ := dockerCmdWithFail(c, "run", "--net=host", "--mac-address=92:d0:c6:0a:29:33", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictContainerNetworkAndMac.Error()) -} - -func (s *DockerSuite) TestConflictNetworkModeAndOptions(c *check.C) { - testRequires(c, DaemonIsLinux) - - out, _ := dockerCmdWithFail(c, "run", "--net=container:other", "--dns=8.8.8.8", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkAndDNS.Error()) - - out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "--add-host=name:8.8.8.8", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkHosts.Error()) - - out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "--mac-address=92:d0:c6:0a:29:33", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictContainerNetworkAndMac.Error()) - - out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "-P", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkPublishPorts.Error()) - - out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "-p", "8080", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkPublishPorts.Error()) - - out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "--expose", "8000-9000", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkExposePorts.Error()) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_network_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_network_unix_test.go deleted file mode 100644 index 97f204a..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_network_unix_test.go +++ /dev/null @@ -1,1791 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net" - "net/http" - "net/http/httptest" - "os" - "path/filepath" - "strings" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/versions/v1p20" - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/runconfig" - "github.com/docker/libnetwork/driverapi" - remoteapi "github.com/docker/libnetwork/drivers/remote/api" - "github.com/docker/libnetwork/ipamapi" - remoteipam "github.com/docker/libnetwork/ipams/remote/api" - "github.com/docker/libnetwork/netlabel" - "github.com/go-check/check" - "github.com/vishvananda/netlink" -) - -const dummyNetworkDriver = "dummy-network-driver" -const dummyIPAMDriver = "dummy-ipam-driver" - -var remoteDriverNetworkRequest remoteapi.CreateNetworkRequest - -func init() { - check.Suite(&DockerNetworkSuite{ - ds: &DockerSuite{}, - }) -} - -type DockerNetworkSuite struct { - server *httptest.Server - ds *DockerSuite - d *Daemon -} - -func (s *DockerNetworkSuite) SetUpTest(c *check.C) { - s.d = NewDaemon(c) -} - -func (s *DockerNetworkSuite) TearDownTest(c *check.C) { - s.d.Stop() - s.ds.TearDownTest(c) -} - -func (s *DockerNetworkSuite) SetUpSuite(c *check.C) { - mux := http.NewServeMux() - s.server = httptest.NewServer(mux) - c.Assert(s.server, check.NotNil, check.Commentf("Failed to start an HTTP Server")) - setupRemoteNetworkDrivers(c, mux, s.server.URL, dummyNetworkDriver, dummyIPAMDriver) -} - -func setupRemoteNetworkDrivers(c *check.C, mux *http.ServeMux, url, netDrv, ipamDrv string) { - - mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, `{"Implements": ["%s", "%s"]}`, driverapi.NetworkPluginEndpointType, ipamapi.PluginEndpointType) - }) - - // Network driver implementation - mux.HandleFunc(fmt.Sprintf("/%s.GetCapabilities", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, `{"Scope":"local"}`) - }) - - mux.HandleFunc(fmt.Sprintf("/%s.CreateNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&remoteDriverNetworkRequest) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, "null") - }) - - mux.HandleFunc(fmt.Sprintf("/%s.DeleteNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, "null") - }) - - mux.HandleFunc(fmt.Sprintf("/%s.CreateEndpoint", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, `{"Interface":{"MacAddress":"a0:b1:c2:d3:e4:f5"}}`) - }) - - mux.HandleFunc(fmt.Sprintf("/%s.Join", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - - veth := &netlink.Veth{ - LinkAttrs: netlink.LinkAttrs{Name: "randomIfName", TxQLen: 0}, PeerName: "cnt0"} - if err := netlink.LinkAdd(veth); err != nil { - fmt.Fprintf(w, `{"Error":"failed to add veth pair: `+err.Error()+`"}`) - } else { - fmt.Fprintf(w, `{"InterfaceName":{ "SrcName":"cnt0", "DstPrefix":"veth"}}`) - } - }) - - mux.HandleFunc(fmt.Sprintf("/%s.Leave", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, "null") - }) - - mux.HandleFunc(fmt.Sprintf("/%s.DeleteEndpoint", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - if link, err := netlink.LinkByName("cnt0"); err == nil { - netlink.LinkDel(link) - } - fmt.Fprintf(w, "null") - }) - - // IPAM Driver implementation - var ( - poolRequest remoteipam.RequestPoolRequest - poolReleaseReq remoteipam.ReleasePoolRequest - addressRequest remoteipam.RequestAddressRequest - addressReleaseReq remoteipam.ReleaseAddressRequest - lAS = "localAS" - gAS = "globalAS" - pool = "172.28.0.0/16" - poolID = lAS + "/" + pool - gw = "172.28.255.254/16" - ) - - mux.HandleFunc(fmt.Sprintf("/%s.GetDefaultAddressSpaces", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, `{"LocalDefaultAddressSpace":"`+lAS+`", "GlobalDefaultAddressSpace": "`+gAS+`"}`) - }) - - mux.HandleFunc(fmt.Sprintf("/%s.RequestPool", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&poolRequest) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - if poolRequest.AddressSpace != lAS && poolRequest.AddressSpace != gAS { - fmt.Fprintf(w, `{"Error":"Unknown address space in pool request: `+poolRequest.AddressSpace+`"}`) - } else if poolRequest.Pool != "" && poolRequest.Pool != pool { - fmt.Fprintf(w, `{"Error":"Cannot handle explicit pool requests yet"}`) - } else { - fmt.Fprintf(w, `{"PoolID":"`+poolID+`", "Pool":"`+pool+`"}`) - } - }) - - mux.HandleFunc(fmt.Sprintf("/%s.RequestAddress", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&addressRequest) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - // make sure libnetwork is now querying on the expected pool id - if addressRequest.PoolID != poolID { - fmt.Fprintf(w, `{"Error":"unknown pool id"}`) - } else if addressRequest.Address != "" { - fmt.Fprintf(w, `{"Error":"Cannot handle explicit address requests yet"}`) - } else { - fmt.Fprintf(w, `{"Address":"`+gw+`"}`) - } - }) - - mux.HandleFunc(fmt.Sprintf("/%s.ReleaseAddress", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&addressReleaseReq) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - // make sure libnetwork is now asking to release the expected address from the expected poolid - if addressRequest.PoolID != poolID { - fmt.Fprintf(w, `{"Error":"unknown pool id"}`) - } else if addressReleaseReq.Address != gw { - fmt.Fprintf(w, `{"Error":"unknown address"}`) - } else { - fmt.Fprintf(w, "null") - } - }) - - mux.HandleFunc(fmt.Sprintf("/%s.ReleasePool", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&poolReleaseReq) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - // make sure libnetwork is now asking to release the expected poolid - if addressRequest.PoolID != poolID { - fmt.Fprintf(w, `{"Error":"unknown pool id"}`) - } else { - fmt.Fprintf(w, "null") - } - }) - - err := os.MkdirAll("/etc/docker/plugins", 0755) - c.Assert(err, checker.IsNil) - - fileName := fmt.Sprintf("/etc/docker/plugins/%s.spec", netDrv) - err = ioutil.WriteFile(fileName, []byte(url), 0644) - c.Assert(err, checker.IsNil) - - ipamFileName := fmt.Sprintf("/etc/docker/plugins/%s.spec", ipamDrv) - err = ioutil.WriteFile(ipamFileName, []byte(url), 0644) - c.Assert(err, checker.IsNil) -} - -func (s *DockerNetworkSuite) TearDownSuite(c *check.C) { - if s.server == nil { - return - } - - s.server.Close() - - err := os.RemoveAll("/etc/docker/plugins") - c.Assert(err, checker.IsNil) -} - -func assertNwIsAvailable(c *check.C, name string) { - if !isNwPresent(c, name) { - c.Fatalf("Network %s not found in network ls o/p", name) - } -} - -func assertNwNotAvailable(c *check.C, name string) { - if isNwPresent(c, name) { - c.Fatalf("Found network %s in network ls o/p", name) - } -} - -func isNwPresent(c *check.C, name string) bool { - out, _ := dockerCmd(c, "network", "ls") - lines := strings.Split(out, "\n") - for i := 1; i < len(lines)-1; i++ { - netFields := strings.Fields(lines[i]) - if netFields[1] == name { - return true - } - } - return false -} - -// assertNwList checks network list retrieved with ls command -// equals to expected network list -// note: out should be `network ls [option]` result -func assertNwList(c *check.C, out string, expectNws []string) { - lines := strings.Split(out, "\n") - var nwList []string - for _, line := range lines[1 : len(lines)-1] { - netFields := strings.Fields(line) - // wrap all network name in nwList - nwList = append(nwList, netFields[1]) - } - - // network ls should contains all expected networks - c.Assert(nwList, checker.DeepEquals, expectNws) -} - -func getNwResource(c *check.C, name string) *types.NetworkResource { - out, _ := dockerCmd(c, "network", "inspect", name) - nr := []types.NetworkResource{} - err := json.Unmarshal([]byte(out), &nr) - c.Assert(err, check.IsNil) - return &nr[0] -} - -func (s *DockerNetworkSuite) TestDockerNetworkLsDefault(c *check.C) { - defaults := []string{"bridge", "host", "none"} - for _, nn := range defaults { - assertNwIsAvailable(c, nn) - } -} - -func (s *DockerSuite) TestNetworkLsFormat(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "network", "ls", "--format", "{{.Name}}") - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - - expected := []string{"bridge", "host", "none"} - var names []string - names = append(names, lines...) - c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names)) -} - -func (s *DockerSuite) TestNetworkLsFormatDefaultFormat(c *check.C) { - testRequires(c, DaemonIsLinux) - - config := `{ - "networksFormat": "{{ .Name }} default" -}` - d, err := ioutil.TempDir("", "integration-cli-") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(d) - - err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644) - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "--config", d, "network", "ls") - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - - expected := []string{"bridge default", "host default", "none default"} - var names []string - names = append(names, lines...) - c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names)) -} - -func (s *DockerNetworkSuite) TestDockerNetworkCreatePredefined(c *check.C) { - predefined := []string{"bridge", "host", "none", "default"} - for _, net := range predefined { - // predefined networks can't be created again - out, _, err := dockerCmdWithError("network", "create", net) - c.Assert(err, checker.NotNil, check.Commentf("%v", out)) - } -} - -func (s *DockerNetworkSuite) TestDockerNetworkCreateHostBind(c *check.C) { - dockerCmd(c, "network", "create", "--subnet=192.168.10.0/24", "--gateway=192.168.10.1", "-o", "com.docker.network.bridge.host_binding_ipv4=192.168.10.1", "testbind") - assertNwIsAvailable(c, "testbind") - - out, _ := runSleepingContainer(c, "--net=testbind", "-p", "5000:5000") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - out, _ = dockerCmd(c, "ps") - c.Assert(out, checker.Contains, "192.168.10.1:5000->5000/tcp") -} - -func (s *DockerNetworkSuite) TestDockerNetworkRmPredefined(c *check.C) { - predefined := []string{"bridge", "host", "none", "default"} - for _, net := range predefined { - // predefined networks can't be removed - out, _, err := dockerCmdWithError("network", "rm", net) - c.Assert(err, checker.NotNil, check.Commentf("%v", out)) - } -} - -func (s *DockerNetworkSuite) TestDockerNetworkLsFilter(c *check.C) { - testNet := "testnet1" - testLabel := "foo" - testValue := "bar" - out, _ := dockerCmd(c, "network", "create", "dev") - defer func() { - dockerCmd(c, "network", "rm", "dev") - dockerCmd(c, "network", "rm", testNet) - }() - networkID := strings.TrimSpace(out) - - // filter with partial ID - // only show 'dev' network - out, _ = dockerCmd(c, "network", "ls", "-f", "id="+networkID[0:5]) - assertNwList(c, out, []string{"dev"}) - - out, _ = dockerCmd(c, "network", "ls", "-f", "name=dge") - assertNwList(c, out, []string{"bridge"}) - - // only show built-in network (bridge, none, host) - out, _ = dockerCmd(c, "network", "ls", "-f", "type=builtin") - assertNwList(c, out, []string{"bridge", "host", "none"}) - - // only show custom networks (dev) - out, _ = dockerCmd(c, "network", "ls", "-f", "type=custom") - assertNwList(c, out, []string{"dev"}) - - // show all networks with filter - // it should be equivalent of ls without option - out, _ = dockerCmd(c, "network", "ls", "-f", "type=custom", "-f", "type=builtin") - assertNwList(c, out, []string{"bridge", "dev", "host", "none"}) - - out, _ = dockerCmd(c, "network", "create", "--label", testLabel+"="+testValue, testNet) - assertNwIsAvailable(c, testNet) - - out, _ = dockerCmd(c, "network", "ls", "-f", "label="+testLabel) - assertNwList(c, out, []string{testNet}) - - out, _ = dockerCmd(c, "network", "ls", "-f", "label="+testLabel+"="+testValue) - assertNwList(c, out, []string{testNet}) - - out, _ = dockerCmd(c, "network", "ls", "-f", "label=nonexistent") - outArr := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out)) - - out, _ = dockerCmd(c, "network", "ls", "-f", "driver=null") - assertNwList(c, out, []string{"none"}) - - out, _ = dockerCmd(c, "network", "ls", "-f", "driver=host") - assertNwList(c, out, []string{"host"}) - - out, _ = dockerCmd(c, "network", "ls", "-f", "driver=bridge") - assertNwList(c, out, []string{"bridge", "dev", testNet}) -} - -func (s *DockerNetworkSuite) TestDockerNetworkCreateDelete(c *check.C) { - dockerCmd(c, "network", "create", "test") - assertNwIsAvailable(c, "test") - - dockerCmd(c, "network", "rm", "test") - assertNwNotAvailable(c, "test") -} - -func (s *DockerNetworkSuite) TestDockerNetworkCreateLabel(c *check.C) { - testNet := "testnetcreatelabel" - testLabel := "foo" - testValue := "bar" - - dockerCmd(c, "network", "create", "--label", testLabel+"="+testValue, testNet) - assertNwIsAvailable(c, testNet) - - out, _, err := dockerCmdWithError("network", "inspect", "--format={{ .Labels."+testLabel+" }}", testNet) - c.Assert(err, check.IsNil) - c.Assert(strings.TrimSpace(out), check.Equals, testValue) - - dockerCmd(c, "network", "rm", testNet) - assertNwNotAvailable(c, testNet) -} - -func (s *DockerSuite) TestDockerNetworkDeleteNotExists(c *check.C) { - out, _, err := dockerCmdWithError("network", "rm", "test") - c.Assert(err, checker.NotNil, check.Commentf("%v", out)) -} - -func (s *DockerSuite) TestDockerNetworkDeleteMultiple(c *check.C) { - dockerCmd(c, "network", "create", "testDelMulti0") - assertNwIsAvailable(c, "testDelMulti0") - dockerCmd(c, "network", "create", "testDelMulti1") - assertNwIsAvailable(c, "testDelMulti1") - dockerCmd(c, "network", "create", "testDelMulti2") - assertNwIsAvailable(c, "testDelMulti2") - out, _ := dockerCmd(c, "run", "-d", "--net", "testDelMulti2", "busybox", "top") - containerID := strings.TrimSpace(out) - waitRun(containerID) - - // delete three networks at the same time, since testDelMulti2 - // contains active container, its deletion should fail. - out, _, err := dockerCmdWithError("network", "rm", "testDelMulti0", "testDelMulti1", "testDelMulti2") - // err should not be nil due to deleting testDelMulti2 failed. - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - // testDelMulti2 should fail due to network has active endpoints - c.Assert(out, checker.Contains, "has active endpoints") - assertNwNotAvailable(c, "testDelMulti0") - assertNwNotAvailable(c, "testDelMulti1") - // testDelMulti2 can't be deleted, so it should exist - assertNwIsAvailable(c, "testDelMulti2") -} - -func (s *DockerSuite) TestDockerNetworkInspect(c *check.C) { - out, _ := dockerCmd(c, "network", "inspect", "host") - networkResources := []types.NetworkResource{} - err := json.Unmarshal([]byte(out), &networkResources) - c.Assert(err, check.IsNil) - c.Assert(networkResources, checker.HasLen, 1) - - out, _ = dockerCmd(c, "network", "inspect", "--format={{ .Name }}", "host") - c.Assert(strings.TrimSpace(out), check.Equals, "host") -} - -func (s *DockerSuite) TestDockerNetworkInspectWithID(c *check.C) { - out, _ := dockerCmd(c, "network", "create", "test2") - networkID := strings.TrimSpace(out) - assertNwIsAvailable(c, "test2") - out, _ = dockerCmd(c, "network", "inspect", "--format={{ .Id }}", "test2") - c.Assert(strings.TrimSpace(out), check.Equals, networkID) - - out, _ = dockerCmd(c, "network", "inspect", "--format={{ .ID }}", "test2") - c.Assert(strings.TrimSpace(out), check.Equals, networkID) -} - -func (s *DockerSuite) TestDockerInspectMultipleNetwork(c *check.C) { - result := dockerCmdWithResult("network", "inspect", "host", "none") - c.Assert(result, icmd.Matches, icmd.Success) - - networkResources := []types.NetworkResource{} - err := json.Unmarshal([]byte(result.Stdout()), &networkResources) - c.Assert(err, check.IsNil) - c.Assert(networkResources, checker.HasLen, 2) - - // Should print an error, return an exitCode 1 *but* should print the host network - result = dockerCmdWithResult("network", "inspect", "host", "nonexistent") - c.Assert(result, icmd.Matches, icmd.Expected{ - ExitCode: 1, - Err: "Error: No such network: nonexistent", - Out: "host", - }) - - networkResources = []types.NetworkResource{} - err = json.Unmarshal([]byte(result.Stdout()), &networkResources) - c.Assert(networkResources, checker.HasLen, 1) - - // Should print an error and return an exitCode, nothing else - result = dockerCmdWithResult("network", "inspect", "nonexistent") - c.Assert(result, icmd.Matches, icmd.Expected{ - ExitCode: 1, - Err: "Error: No such network: nonexistent", - Out: "[]", - }) -} - -func (s *DockerSuite) TestDockerInspectNetworkWithContainerName(c *check.C) { - dockerCmd(c, "network", "create", "brNetForInspect") - assertNwIsAvailable(c, "brNetForInspect") - defer func() { - dockerCmd(c, "network", "rm", "brNetForInspect") - assertNwNotAvailable(c, "brNetForInspect") - }() - - out, _ := dockerCmd(c, "run", "-d", "--name", "testNetInspect1", "--net", "brNetForInspect", "busybox", "top") - c.Assert(waitRun("testNetInspect1"), check.IsNil) - containerID := strings.TrimSpace(out) - defer func() { - // we don't stop container by name, because we'll rename it later - dockerCmd(c, "stop", containerID) - }() - - out, _ = dockerCmd(c, "network", "inspect", "brNetForInspect") - networkResources := []types.NetworkResource{} - err := json.Unmarshal([]byte(out), &networkResources) - c.Assert(err, check.IsNil) - c.Assert(networkResources, checker.HasLen, 1) - container, ok := networkResources[0].Containers[containerID] - c.Assert(ok, checker.True) - c.Assert(container.Name, checker.Equals, "testNetInspect1") - - // rename container and check docker inspect output update - newName := "HappyNewName" - dockerCmd(c, "rename", "testNetInspect1", newName) - - // check whether network inspect works properly - out, _ = dockerCmd(c, "network", "inspect", "brNetForInspect") - newNetRes := []types.NetworkResource{} - err = json.Unmarshal([]byte(out), &newNetRes) - c.Assert(err, check.IsNil) - c.Assert(newNetRes, checker.HasLen, 1) - container1, ok := newNetRes[0].Containers[containerID] - c.Assert(ok, checker.True) - c.Assert(container1.Name, checker.Equals, newName) - -} - -func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnect(c *check.C) { - dockerCmd(c, "network", "create", "test") - assertNwIsAvailable(c, "test") - nr := getNwResource(c, "test") - - c.Assert(nr.Name, checker.Equals, "test") - c.Assert(len(nr.Containers), checker.Equals, 0) - - // run a container - out, _ := dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") - c.Assert(waitRun("test"), check.IsNil) - containerID := strings.TrimSpace(out) - - // connect the container to the test network - dockerCmd(c, "network", "connect", "test", containerID) - - // inspect the network to make sure container is connected - nr = getNetworkResource(c, nr.ID) - c.Assert(len(nr.Containers), checker.Equals, 1) - c.Assert(nr.Containers[containerID], check.NotNil) - - // check if container IP matches network inspect - ip, _, err := net.ParseCIDR(nr.Containers[containerID].IPv4Address) - c.Assert(err, check.IsNil) - containerIP := findContainerIP(c, "test", "test") - c.Assert(ip.String(), checker.Equals, containerIP) - - // disconnect container from the network - dockerCmd(c, "network", "disconnect", "test", containerID) - nr = getNwResource(c, "test") - c.Assert(nr.Name, checker.Equals, "test") - c.Assert(len(nr.Containers), checker.Equals, 0) - - // run another container - out, _ = dockerCmd(c, "run", "-d", "--net", "test", "--name", "test2", "busybox", "top") - c.Assert(waitRun("test2"), check.IsNil) - containerID = strings.TrimSpace(out) - - nr = getNwResource(c, "test") - c.Assert(nr.Name, checker.Equals, "test") - c.Assert(len(nr.Containers), checker.Equals, 1) - - // force disconnect the container to the test network - dockerCmd(c, "network", "disconnect", "-f", "test", containerID) - - nr = getNwResource(c, "test") - c.Assert(nr.Name, checker.Equals, "test") - c.Assert(len(nr.Containers), checker.Equals, 0) - - dockerCmd(c, "network", "rm", "test") - assertNwNotAvailable(c, "test") -} - -func (s *DockerNetworkSuite) TestDockerNetworkIPAMMultipleNetworks(c *check.C) { - // test0 bridge network - dockerCmd(c, "network", "create", "--subnet=192.168.0.0/16", "test1") - assertNwIsAvailable(c, "test1") - - // test2 bridge network does not overlap - dockerCmd(c, "network", "create", "--subnet=192.169.0.0/16", "test2") - assertNwIsAvailable(c, "test2") - - // for networks w/o ipam specified, docker will choose proper non-overlapping subnets - dockerCmd(c, "network", "create", "test3") - assertNwIsAvailable(c, "test3") - dockerCmd(c, "network", "create", "test4") - assertNwIsAvailable(c, "test4") - dockerCmd(c, "network", "create", "test5") - assertNwIsAvailable(c, "test5") - - // test network with multiple subnets - // bridge network doesn't support multiple subnets. hence, use a dummy driver that supports - - dockerCmd(c, "network", "create", "-d", dummyNetworkDriver, "--subnet=192.168.0.0/16", "--subnet=192.170.0.0/16", "test6") - assertNwIsAvailable(c, "test6") - - // test network with multiple subnets with valid ipam combinations - // also check same subnet across networks when the driver supports it. - dockerCmd(c, "network", "create", "-d", dummyNetworkDriver, - "--subnet=192.168.0.0/16", "--subnet=192.170.0.0/16", - "--gateway=192.168.0.100", "--gateway=192.170.0.100", - "--ip-range=192.168.1.0/24", - "--aux-address", "a=192.168.1.5", "--aux-address", "b=192.168.1.6", - "--aux-address", "c=192.170.1.5", "--aux-address", "d=192.170.1.6", - "test7") - assertNwIsAvailable(c, "test7") - - // cleanup - for i := 1; i < 8; i++ { - dockerCmd(c, "network", "rm", fmt.Sprintf("test%d", i)) - } -} - -func (s *DockerNetworkSuite) TestDockerNetworkCustomIPAM(c *check.C) { - // Create a bridge network using custom ipam driver - dockerCmd(c, "network", "create", "--ipam-driver", dummyIPAMDriver, "br0") - assertNwIsAvailable(c, "br0") - - // Verify expected network ipam fields are there - nr := getNetworkResource(c, "br0") - c.Assert(nr.Driver, checker.Equals, "bridge") - c.Assert(nr.IPAM.Driver, checker.Equals, dummyIPAMDriver) - - // remove network and exercise remote ipam driver - dockerCmd(c, "network", "rm", "br0") - assertNwNotAvailable(c, "br0") -} - -func (s *DockerNetworkSuite) TestDockerNetworkIPAMOptions(c *check.C) { - // Create a bridge network using custom ipam driver and options - dockerCmd(c, "network", "create", "--ipam-driver", dummyIPAMDriver, "--ipam-opt", "opt1=drv1", "--ipam-opt", "opt2=drv2", "br0") - assertNwIsAvailable(c, "br0") - - // Verify expected network ipam options - nr := getNetworkResource(c, "br0") - opts := nr.IPAM.Options - c.Assert(opts["opt1"], checker.Equals, "drv1") - c.Assert(opts["opt2"], checker.Equals, "drv2") -} - -func (s *DockerNetworkSuite) TestDockerNetworkInspectDefault(c *check.C) { - nr := getNetworkResource(c, "none") - c.Assert(nr.Driver, checker.Equals, "null") - c.Assert(nr.Scope, checker.Equals, "local") - c.Assert(nr.Internal, checker.Equals, false) - c.Assert(nr.EnableIPv6, checker.Equals, false) - c.Assert(nr.IPAM.Driver, checker.Equals, "default") - c.Assert(len(nr.IPAM.Config), checker.Equals, 0) - - nr = getNetworkResource(c, "host") - c.Assert(nr.Driver, checker.Equals, "host") - c.Assert(nr.Scope, checker.Equals, "local") - c.Assert(nr.Internal, checker.Equals, false) - c.Assert(nr.EnableIPv6, checker.Equals, false) - c.Assert(nr.IPAM.Driver, checker.Equals, "default") - c.Assert(len(nr.IPAM.Config), checker.Equals, 0) - - nr = getNetworkResource(c, "bridge") - c.Assert(nr.Driver, checker.Equals, "bridge") - c.Assert(nr.Scope, checker.Equals, "local") - c.Assert(nr.Internal, checker.Equals, false) - c.Assert(nr.EnableIPv6, checker.Equals, false) - c.Assert(nr.IPAM.Driver, checker.Equals, "default") - c.Assert(len(nr.IPAM.Config), checker.Equals, 1) - c.Assert(nr.IPAM.Config[0].Subnet, checker.NotNil) - c.Assert(nr.IPAM.Config[0].Gateway, checker.NotNil) -} - -func (s *DockerNetworkSuite) TestDockerNetworkInspectCustomUnspecified(c *check.C) { - // if unspecified, network subnet will be selected from inside preferred pool - dockerCmd(c, "network", "create", "test01") - assertNwIsAvailable(c, "test01") - - nr := getNetworkResource(c, "test01") - c.Assert(nr.Driver, checker.Equals, "bridge") - c.Assert(nr.Scope, checker.Equals, "local") - c.Assert(nr.Internal, checker.Equals, false) - c.Assert(nr.EnableIPv6, checker.Equals, false) - c.Assert(nr.IPAM.Driver, checker.Equals, "default") - c.Assert(len(nr.IPAM.Config), checker.Equals, 1) - c.Assert(nr.IPAM.Config[0].Subnet, checker.NotNil) - c.Assert(nr.IPAM.Config[0].Gateway, checker.NotNil) - - dockerCmd(c, "network", "rm", "test01") - assertNwNotAvailable(c, "test01") -} - -func (s *DockerNetworkSuite) TestDockerNetworkInspectCustomSpecified(c *check.C) { - dockerCmd(c, "network", "create", "--driver=bridge", "--ipv6", "--subnet=fd80:24e2:f998:72d6::/64", "--subnet=172.28.0.0/16", "--ip-range=172.28.5.0/24", "--gateway=172.28.5.254", "br0") - assertNwIsAvailable(c, "br0") - - nr := getNetworkResource(c, "br0") - c.Assert(nr.Driver, checker.Equals, "bridge") - c.Assert(nr.Scope, checker.Equals, "local") - c.Assert(nr.Internal, checker.Equals, false) - c.Assert(nr.EnableIPv6, checker.Equals, true) - c.Assert(nr.IPAM.Driver, checker.Equals, "default") - c.Assert(len(nr.IPAM.Config), checker.Equals, 2) - c.Assert(nr.IPAM.Config[0].Subnet, checker.Equals, "172.28.0.0/16") - c.Assert(nr.IPAM.Config[0].IPRange, checker.Equals, "172.28.5.0/24") - c.Assert(nr.IPAM.Config[0].Gateway, checker.Equals, "172.28.5.254") - c.Assert(nr.Internal, checker.False) - dockerCmd(c, "network", "rm", "br0") - assertNwNotAvailable(c, "test01") -} - -func (s *DockerNetworkSuite) TestDockerNetworkIPAMInvalidCombinations(c *check.C) { - // network with ip-range out of subnet range - _, _, err := dockerCmdWithError("network", "create", "--subnet=192.168.0.0/16", "--ip-range=192.170.0.0/16", "test") - c.Assert(err, check.NotNil) - - // network with multiple gateways for a single subnet - _, _, err = dockerCmdWithError("network", "create", "--subnet=192.168.0.0/16", "--gateway=192.168.0.1", "--gateway=192.168.0.2", "test") - c.Assert(err, check.NotNil) - - // Multiple overlapping subnets in the same network must fail - _, _, err = dockerCmdWithError("network", "create", "--subnet=192.168.0.0/16", "--subnet=192.168.1.0/16", "test") - c.Assert(err, check.NotNil) - - // overlapping subnets across networks must fail - // create a valid test0 network - dockerCmd(c, "network", "create", "--subnet=192.168.0.0/16", "test0") - assertNwIsAvailable(c, "test0") - // create an overlapping test1 network - _, _, err = dockerCmdWithError("network", "create", "--subnet=192.168.128.0/17", "test1") - c.Assert(err, check.NotNil) - dockerCmd(c, "network", "rm", "test0") - assertNwNotAvailable(c, "test0") -} - -func (s *DockerNetworkSuite) TestDockerNetworkDriverOptions(c *check.C) { - dockerCmd(c, "network", "create", "-d", dummyNetworkDriver, "-o", "opt1=drv1", "-o", "opt2=drv2", "testopt") - assertNwIsAvailable(c, "testopt") - gopts := remoteDriverNetworkRequest.Options[netlabel.GenericData] - c.Assert(gopts, checker.NotNil) - opts, ok := gopts.(map[string]interface{}) - c.Assert(ok, checker.Equals, true) - c.Assert(opts["opt1"], checker.Equals, "drv1") - c.Assert(opts["opt2"], checker.Equals, "drv2") - dockerCmd(c, "network", "rm", "testopt") - assertNwNotAvailable(c, "testopt") - -} - -func (s *DockerNetworkSuite) TestDockerPluginV2NetworkDriver(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - - var ( - npName = "tiborvass/test-docker-netplugin" - npTag = "latest" - npNameWithTag = npName + ":" + npTag - ) - _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err := dockerCmdWithError("plugin", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, npName) - c.Assert(out, checker.Contains, npTag) - c.Assert(out, checker.Contains, "true") - - dockerCmd(c, "network", "create", "-d", npNameWithTag, "v2net") - assertNwIsAvailable(c, "v2net") - dockerCmd(c, "network", "rm", "v2net") - assertNwNotAvailable(c, "v2net") - -} - -func (s *DockerDaemonSuite) TestDockerNetworkNoDiscoveryDefaultBridgeNetwork(c *check.C) { - testRequires(c, ExecSupport) - // On default bridge network built-in service discovery should not happen - hostsFile := "/etc/hosts" - bridgeName := "external-bridge" - bridgeIP := "192.169.255.254/24" - out, err := createInterface(c, "bridge", bridgeName, bridgeIP) - c.Assert(err, check.IsNil, check.Commentf(out)) - defer deleteInterface(c, bridgeName) - - err = s.d.StartWithBusybox("--bridge", bridgeName) - c.Assert(err, check.IsNil) - defer s.d.Restart() - - // run two containers and store first container's etc/hosts content - out, err = s.d.Cmd("run", "-d", "busybox", "top") - c.Assert(err, check.IsNil) - cid1 := strings.TrimSpace(out) - defer s.d.Cmd("stop", cid1) - - hosts, err := s.d.Cmd("exec", cid1, "cat", hostsFile) - c.Assert(err, checker.IsNil) - - out, err = s.d.Cmd("run", "-d", "--name", "container2", "busybox", "top") - c.Assert(err, check.IsNil) - cid2 := strings.TrimSpace(out) - - // verify first container's etc/hosts file has not changed after spawning the second named container - hostsPost, err := s.d.Cmd("exec", cid1, "cat", hostsFile) - c.Assert(err, checker.IsNil) - c.Assert(string(hosts), checker.Equals, string(hostsPost), - check.Commentf("Unexpected %s change on second container creation", hostsFile)) - - // stop container 2 and verify first container's etc/hosts has not changed - _, err = s.d.Cmd("stop", cid2) - c.Assert(err, check.IsNil) - - hostsPost, err = s.d.Cmd("exec", cid1, "cat", hostsFile) - c.Assert(err, checker.IsNil) - c.Assert(string(hosts), checker.Equals, string(hostsPost), - check.Commentf("Unexpected %s change on second container creation", hostsFile)) - - // but discovery is on when connecting to non default bridge network - network := "anotherbridge" - out, err = s.d.Cmd("network", "create", network) - c.Assert(err, check.IsNil, check.Commentf(out)) - defer s.d.Cmd("network", "rm", network) - - out, err = s.d.Cmd("network", "connect", network, cid1) - c.Assert(err, check.IsNil, check.Commentf(out)) - - hosts, err = s.d.Cmd("exec", cid1, "cat", hostsFile) - c.Assert(err, checker.IsNil) - - hostsPost, err = s.d.Cmd("exec", cid1, "cat", hostsFile) - c.Assert(err, checker.IsNil) - c.Assert(string(hosts), checker.Equals, string(hostsPost), - check.Commentf("Unexpected %s change on second network connection", hostsFile)) -} - -func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) { - testRequires(c, ExecSupport, NotArm) - hostsFile := "/etc/hosts" - cstmBridgeNw := "custom-bridge-nw" - cstmBridgeNw1 := "custom-bridge-nw1" - - dockerCmd(c, "network", "create", "-d", "bridge", cstmBridgeNw) - assertNwIsAvailable(c, cstmBridgeNw) - - // run two anonymous containers and store their etc/hosts content - out, _ := dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "busybox", "top") - cid1 := strings.TrimSpace(out) - - hosts1, err := readContainerFileWithExec(cid1, hostsFile) - c.Assert(err, checker.IsNil) - - out, _ = dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "busybox", "top") - cid2 := strings.TrimSpace(out) - - hosts2, err := readContainerFileWithExec(cid2, hostsFile) - c.Assert(err, checker.IsNil) - - // verify first container etc/hosts file has not changed - hosts1post, err := readContainerFileWithExec(cid1, hostsFile) - c.Assert(err, checker.IsNil) - c.Assert(string(hosts1), checker.Equals, string(hosts1post), - check.Commentf("Unexpected %s change on anonymous container creation", hostsFile)) - - // Connect the 2nd container to a new network and verify the - // first container /etc/hosts file still hasn't changed. - dockerCmd(c, "network", "create", "-d", "bridge", cstmBridgeNw1) - assertNwIsAvailable(c, cstmBridgeNw1) - - dockerCmd(c, "network", "connect", cstmBridgeNw1, cid2) - - hosts2, err = readContainerFileWithExec(cid2, hostsFile) - c.Assert(err, checker.IsNil) - - hosts1post, err = readContainerFileWithExec(cid1, hostsFile) - c.Assert(err, checker.IsNil) - c.Assert(string(hosts1), checker.Equals, string(hosts1post), - check.Commentf("Unexpected %s change on container connect", hostsFile)) - - // start a named container - cName := "AnyName" - out, _ = dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "--name", cName, "busybox", "top") - cid3 := strings.TrimSpace(out) - - // verify that container 1 and 2 can ping the named container - dockerCmd(c, "exec", cid1, "ping", "-c", "1", cName) - dockerCmd(c, "exec", cid2, "ping", "-c", "1", cName) - - // Stop named container and verify first two containers' etc/hosts file hasn't changed - dockerCmd(c, "stop", cid3) - hosts1post, err = readContainerFileWithExec(cid1, hostsFile) - c.Assert(err, checker.IsNil) - c.Assert(string(hosts1), checker.Equals, string(hosts1post), - check.Commentf("Unexpected %s change on name container creation", hostsFile)) - - hosts2post, err := readContainerFileWithExec(cid2, hostsFile) - c.Assert(err, checker.IsNil) - c.Assert(string(hosts2), checker.Equals, string(hosts2post), - check.Commentf("Unexpected %s change on name container creation", hostsFile)) - - // verify that container 1 and 2 can't ping the named container now - _, _, err = dockerCmdWithError("exec", cid1, "ping", "-c", "1", cName) - c.Assert(err, check.NotNil) - _, _, err = dockerCmdWithError("exec", cid2, "ping", "-c", "1", cName) - c.Assert(err, check.NotNil) -} - -func (s *DockerNetworkSuite) TestDockerNetworkLinkOnDefaultNetworkOnly(c *check.C) { - // Legacy Link feature must work only on default network, and not across networks - cnt1 := "container1" - cnt2 := "container2" - network := "anotherbridge" - - // Run first container on default network - dockerCmd(c, "run", "-d", "--name", cnt1, "busybox", "top") - - // Create another network and run the second container on it - dockerCmd(c, "network", "create", network) - assertNwIsAvailable(c, network) - dockerCmd(c, "run", "-d", "--net", network, "--name", cnt2, "busybox", "top") - - // Try launching a container on default network, linking to the first container. Must succeed - dockerCmd(c, "run", "-d", "--link", fmt.Sprintf("%s:%s", cnt1, cnt1), "busybox", "top") - - // Try launching a container on default network, linking to the second container. Must fail - _, _, err := dockerCmdWithError("run", "-d", "--link", fmt.Sprintf("%s:%s", cnt2, cnt2), "busybox", "top") - c.Assert(err, checker.NotNil) - - // Connect second container to default network. Now a container on default network can link to it - dockerCmd(c, "network", "connect", "bridge", cnt2) - dockerCmd(c, "run", "-d", "--link", fmt.Sprintf("%s:%s", cnt2, cnt2), "busybox", "top") -} - -func (s *DockerNetworkSuite) TestDockerNetworkOverlayPortMapping(c *check.C) { - // Verify exposed ports are present in ps output when running a container on - // a network managed by a driver which does not provide the default gateway - // for the container - nwn := "ov" - ctn := "bb" - port1 := 80 - port2 := 443 - expose1 := fmt.Sprintf("--expose=%d", port1) - expose2 := fmt.Sprintf("--expose=%d", port2) - - dockerCmd(c, "network", "create", "-d", dummyNetworkDriver, nwn) - assertNwIsAvailable(c, nwn) - - dockerCmd(c, "run", "-d", "--net", nwn, "--name", ctn, expose1, expose2, "busybox", "top") - - // Check docker ps o/p for last created container reports the unpublished ports - unpPort1 := fmt.Sprintf("%d/tcp", port1) - unpPort2 := fmt.Sprintf("%d/tcp", port2) - out, _ := dockerCmd(c, "ps", "-n=1") - // Missing unpublished ports in docker ps output - c.Assert(out, checker.Contains, unpPort1) - // Missing unpublished ports in docker ps output - c.Assert(out, checker.Contains, unpPort2) -} - -func (s *DockerNetworkSuite) TestDockerNetworkDriverUngracefulRestart(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - dnd := "dnd" - did := "did" - - mux := http.NewServeMux() - server := httptest.NewServer(mux) - setupRemoteNetworkDrivers(c, mux, server.URL, dnd, did) - - s.d.StartWithBusybox() - _, err := s.d.Cmd("network", "create", "-d", dnd, "--subnet", "1.1.1.0/24", "net1") - c.Assert(err, checker.IsNil) - - _, err = s.d.Cmd("run", "-itd", "--net", "net1", "--name", "foo", "--ip", "1.1.1.10", "busybox", "sh") - c.Assert(err, checker.IsNil) - - // Kill daemon and restart - if err = s.d.cmd.Process.Kill(); err != nil { - c.Fatal(err) - } - - server.Close() - - startTime := time.Now().Unix() - if err = s.d.Restart(); err != nil { - c.Fatal(err) - } - lapse := time.Now().Unix() - startTime - if lapse > 60 { - // In normal scenarios, daemon restart takes ~1 second. - // Plugin retry mechanism can delay the daemon start. systemd may not like it. - // Avoid accessing plugins during daemon bootup - c.Logf("daemon restart took too long : %d seconds", lapse) - } - - // Restart the custom dummy plugin - mux = http.NewServeMux() - server = httptest.NewServer(mux) - setupRemoteNetworkDrivers(c, mux, server.URL, dnd, did) - - // trying to reuse the same ip must succeed - _, err = s.d.Cmd("run", "-itd", "--net", "net1", "--name", "bar", "--ip", "1.1.1.10", "busybox", "sh") - c.Assert(err, checker.IsNil) -} - -func (s *DockerNetworkSuite) TestDockerNetworkMacInspect(c *check.C) { - // Verify endpoint MAC address is correctly populated in container's network settings - nwn := "ov" - ctn := "bb" - - dockerCmd(c, "network", "create", "-d", dummyNetworkDriver, nwn) - assertNwIsAvailable(c, nwn) - - dockerCmd(c, "run", "-d", "--net", nwn, "--name", ctn, "busybox", "top") - - mac := inspectField(c, ctn, "NetworkSettings.Networks."+nwn+".MacAddress") - c.Assert(mac, checker.Equals, "a0:b1:c2:d3:e4:f5") -} - -func (s *DockerSuite) TestInspectAPIMultipleNetworks(c *check.C) { - dockerCmd(c, "network", "create", "mybridge1") - dockerCmd(c, "network", "create", "mybridge2") - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), check.IsNil) - - dockerCmd(c, "network", "connect", "mybridge1", id) - dockerCmd(c, "network", "connect", "mybridge2", id) - - body := getInspectBody(c, "v1.20", id) - var inspect120 v1p20.ContainerJSON - err := json.Unmarshal(body, &inspect120) - c.Assert(err, checker.IsNil) - - versionedIP := inspect120.NetworkSettings.IPAddress - - body = getInspectBody(c, "v1.21", id) - var inspect121 types.ContainerJSON - err = json.Unmarshal(body, &inspect121) - c.Assert(err, checker.IsNil) - c.Assert(inspect121.NetworkSettings.Networks, checker.HasLen, 3) - - bridge := inspect121.NetworkSettings.Networks["bridge"] - c.Assert(bridge.IPAddress, checker.Equals, versionedIP) - c.Assert(bridge.IPAddress, checker.Equals, inspect121.NetworkSettings.IPAddress) -} - -func connectContainerToNetworks(c *check.C, d *Daemon, cName string, nws []string) { - // Run a container on the default network - out, err := d.Cmd("run", "-d", "--name", cName, "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // Attach the container to other networks - for _, nw := range nws { - out, err = d.Cmd("network", "create", nw) - c.Assert(err, checker.IsNil, check.Commentf(out)) - out, err = d.Cmd("network", "connect", nw, cName) - c.Assert(err, checker.IsNil, check.Commentf(out)) - } -} - -func verifyContainerIsConnectedToNetworks(c *check.C, d *Daemon, cName string, nws []string) { - // Verify container is connected to all the networks - for _, nw := range nws { - out, err := d.Cmd("inspect", "-f", fmt.Sprintf("{{.NetworkSettings.Networks.%s}}", nw), cName) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(out, checker.Not(checker.Equals), "\n") - } -} - -func (s *DockerNetworkSuite) TestDockerNetworkMultipleNetworksGracefulDaemonRestart(c *check.C) { - cName := "bb" - nwList := []string{"nw1", "nw2", "nw3"} - - s.d.StartWithBusybox() - - connectContainerToNetworks(c, s.d, cName, nwList) - verifyContainerIsConnectedToNetworks(c, s.d, cName, nwList) - - // Reload daemon - s.d.Restart() - - _, err := s.d.Cmd("start", cName) - c.Assert(err, checker.IsNil) - - verifyContainerIsConnectedToNetworks(c, s.d, cName, nwList) -} - -func (s *DockerNetworkSuite) TestDockerNetworkMultipleNetworksUngracefulDaemonRestart(c *check.C) { - cName := "cc" - nwList := []string{"nw1", "nw2", "nw3"} - - s.d.StartWithBusybox() - - connectContainerToNetworks(c, s.d, cName, nwList) - verifyContainerIsConnectedToNetworks(c, s.d, cName, nwList) - - // Kill daemon and restart - if err := s.d.cmd.Process.Kill(); err != nil { - c.Fatal(err) - } - s.d.Restart() - - // Restart container - _, err := s.d.Cmd("start", cName) - c.Assert(err, checker.IsNil) - - verifyContainerIsConnectedToNetworks(c, s.d, cName, nwList) -} - -func (s *DockerNetworkSuite) TestDockerNetworkRunNetByID(c *check.C) { - out, _ := dockerCmd(c, "network", "create", "one") - containerOut, _, err := dockerCmdWithError("run", "-d", "--net", strings.TrimSpace(out), "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(containerOut)) -} - -func (s *DockerNetworkSuite) TestDockerNetworkHostModeUngracefulDaemonRestart(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - s.d.StartWithBusybox() - - // Run a few containers on host network - for i := 0; i < 10; i++ { - cName := fmt.Sprintf("hostc-%d", i) - out, err := s.d.Cmd("run", "-d", "--name", cName, "--net=host", "--restart=always", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // verfiy container has finished starting before killing daemon - err = s.d.waitRun(cName) - c.Assert(err, checker.IsNil) - } - - // Kill daemon ungracefully and restart - if err := s.d.cmd.Process.Kill(); err != nil { - c.Fatal(err) - } - if err := s.d.Restart(); err != nil { - c.Fatal(err) - } - - // make sure all the containers are up and running - for i := 0; i < 10; i++ { - err := s.d.waitRun(fmt.Sprintf("hostc-%d", i)) - c.Assert(err, checker.IsNil) - } -} - -func (s *DockerNetworkSuite) TestDockerNetworkConnectToHostFromOtherNetwork(c *check.C) { - dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") - c.Assert(waitRun("container1"), check.IsNil) - dockerCmd(c, "network", "disconnect", "bridge", "container1") - out, _, err := dockerCmdWithError("network", "connect", "host", "container1") - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetwork.Error()) -} - -func (s *DockerNetworkSuite) TestDockerNetworkDisconnectFromHost(c *check.C) { - dockerCmd(c, "run", "-d", "--name", "container1", "--net=host", "busybox", "top") - c.Assert(waitRun("container1"), check.IsNil) - out, _, err := dockerCmdWithError("network", "disconnect", "host", "container1") - c.Assert(err, checker.NotNil, check.Commentf("Should err out disconnect from host")) - c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetwork.Error()) -} - -func (s *DockerNetworkSuite) TestDockerNetworkConnectWithPortMapping(c *check.C) { - testRequires(c, NotArm) - dockerCmd(c, "network", "create", "test1") - dockerCmd(c, "run", "-d", "--name", "c1", "-p", "5000:5000", "busybox", "top") - c.Assert(waitRun("c1"), check.IsNil) - dockerCmd(c, "network", "connect", "test1", "c1") -} - -func verifyPortMap(c *check.C, container, port, originalMapping string, mustBeEqual bool) { - chk := checker.Equals - if !mustBeEqual { - chk = checker.Not(checker.Equals) - } - currentMapping, _ := dockerCmd(c, "port", container, port) - c.Assert(currentMapping, chk, originalMapping) -} - -func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectWithPortMapping(c *check.C) { - // Connect and disconnect a container with explicit and non-explicit - // host port mapping to/from networks which do cause and do not cause - // the container default gateway to change, and verify docker port cmd - // returns congruent information - testRequires(c, NotArm) - cnt := "c1" - dockerCmd(c, "network", "create", "aaa") - dockerCmd(c, "network", "create", "ccc") - - dockerCmd(c, "run", "-d", "--name", cnt, "-p", "9000:90", "-p", "70", "busybox", "top") - c.Assert(waitRun(cnt), check.IsNil) - curPortMap, _ := dockerCmd(c, "port", cnt, "70") - curExplPortMap, _ := dockerCmd(c, "port", cnt, "90") - - // Connect to a network which causes the container's default gw switch - dockerCmd(c, "network", "connect", "aaa", cnt) - verifyPortMap(c, cnt, "70", curPortMap, false) - verifyPortMap(c, cnt, "90", curExplPortMap, true) - - // Read current mapping - curPortMap, _ = dockerCmd(c, "port", cnt, "70") - - // Disconnect from a network which causes the container's default gw switch - dockerCmd(c, "network", "disconnect", "aaa", cnt) - verifyPortMap(c, cnt, "70", curPortMap, false) - verifyPortMap(c, cnt, "90", curExplPortMap, true) - - // Read current mapping - curPortMap, _ = dockerCmd(c, "port", cnt, "70") - - // Connect to a network which does not cause the container's default gw switch - dockerCmd(c, "network", "connect", "ccc", cnt) - verifyPortMap(c, cnt, "70", curPortMap, true) - verifyPortMap(c, cnt, "90", curExplPortMap, true) -} - -func (s *DockerNetworkSuite) TestDockerNetworkConnectWithMac(c *check.C) { - macAddress := "02:42:ac:11:00:02" - dockerCmd(c, "network", "create", "mynetwork") - dockerCmd(c, "run", "--name=test", "-d", "--mac-address", macAddress, "busybox", "top") - c.Assert(waitRun("test"), check.IsNil) - mac1 := inspectField(c, "test", "NetworkSettings.Networks.bridge.MacAddress") - c.Assert(strings.TrimSpace(mac1), checker.Equals, macAddress) - dockerCmd(c, "network", "connect", "mynetwork", "test") - mac2 := inspectField(c, "test", "NetworkSettings.Networks.mynetwork.MacAddress") - c.Assert(strings.TrimSpace(mac2), checker.Not(checker.Equals), strings.TrimSpace(mac1)) -} - -func (s *DockerNetworkSuite) TestDockerNetworkInspectCreatedContainer(c *check.C) { - dockerCmd(c, "create", "--name", "test", "busybox") - networks := inspectField(c, "test", "NetworkSettings.Networks") - c.Assert(networks, checker.Contains, "bridge", check.Commentf("Should return 'bridge' network")) -} - -func (s *DockerNetworkSuite) TestDockerNetworkRestartWithMultipleNetworks(c *check.C) { - dockerCmd(c, "network", "create", "test") - dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top") - c.Assert(waitRun("foo"), checker.IsNil) - dockerCmd(c, "network", "connect", "test", "foo") - dockerCmd(c, "restart", "foo") - networks := inspectField(c, "foo", "NetworkSettings.Networks") - c.Assert(networks, checker.Contains, "bridge", check.Commentf("Should contain 'bridge' network")) - c.Assert(networks, checker.Contains, "test", check.Commentf("Should contain 'test' network")) -} - -func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectToStoppedContainer(c *check.C) { - dockerCmd(c, "network", "create", "test") - dockerCmd(c, "create", "--name=foo", "busybox", "top") - dockerCmd(c, "network", "connect", "test", "foo") - networks := inspectField(c, "foo", "NetworkSettings.Networks") - c.Assert(networks, checker.Contains, "test", check.Commentf("Should contain 'test' network")) - - // Restart docker daemon to test the config has persisted to disk - s.d.Restart() - networks = inspectField(c, "foo", "NetworkSettings.Networks") - c.Assert(networks, checker.Contains, "test", check.Commentf("Should contain 'test' network")) - - // start the container and test if we can ping it from another container in the same network - dockerCmd(c, "start", "foo") - c.Assert(waitRun("foo"), checker.IsNil) - ip := inspectField(c, "foo", "NetworkSettings.Networks.test.IPAddress") - ip = strings.TrimSpace(ip) - dockerCmd(c, "run", "--net=test", "busybox", "sh", "-c", fmt.Sprintf("ping -c 1 %s", ip)) - - dockerCmd(c, "stop", "foo") - - // Test disconnect - dockerCmd(c, "network", "disconnect", "test", "foo") - networks = inspectField(c, "foo", "NetworkSettings.Networks") - c.Assert(networks, checker.Not(checker.Contains), "test", check.Commentf("Should not contain 'test' network")) - - // Restart docker daemon to test the config has persisted to disk - s.d.Restart() - networks = inspectField(c, "foo", "NetworkSettings.Networks") - c.Assert(networks, checker.Not(checker.Contains), "test", check.Commentf("Should not contain 'test' network")) - -} - -func (s *DockerNetworkSuite) TestDockerNetworkDisconnectContainerNonexistingNetwork(c *check.C) { - dockerCmd(c, "network", "create", "test") - dockerCmd(c, "run", "--net=test", "-d", "--name=foo", "busybox", "top") - networks := inspectField(c, "foo", "NetworkSettings.Networks") - c.Assert(networks, checker.Contains, "test", check.Commentf("Should contain 'test' network")) - - // Stop container and remove network - dockerCmd(c, "stop", "foo") - dockerCmd(c, "network", "rm", "test") - - // Test disconnecting stopped container from nonexisting network - dockerCmd(c, "network", "disconnect", "-f", "test", "foo") - networks = inspectField(c, "foo", "NetworkSettings.Networks") - c.Assert(networks, checker.Not(checker.Contains), "test", check.Commentf("Should not contain 'test' network")) -} - -func (s *DockerNetworkSuite) TestDockerNetworkConnectPreferredIP(c *check.C) { - // create two networks - dockerCmd(c, "network", "create", "--ipv6", "--subnet=172.28.0.0/16", "--subnet=2001:db8:1234::/64", "n0") - assertNwIsAvailable(c, "n0") - - dockerCmd(c, "network", "create", "--ipv6", "--subnet=172.30.0.0/16", "--ip-range=172.30.5.0/24", "--subnet=2001:db8:abcd::/64", "--ip-range=2001:db8:abcd::/80", "n1") - assertNwIsAvailable(c, "n1") - - // run a container on first network specifying the ip addresses - dockerCmd(c, "run", "-d", "--name", "c0", "--net=n0", "--ip", "172.28.99.88", "--ip6", "2001:db8:1234::9988", "busybox", "top") - c.Assert(waitRun("c0"), check.IsNil) - verifyIPAddressConfig(c, "c0", "n0", "172.28.99.88", "2001:db8:1234::9988") - verifyIPAddresses(c, "c0", "n0", "172.28.99.88", "2001:db8:1234::9988") - - // connect the container to the second network specifying an ip addresses - dockerCmd(c, "network", "connect", "--ip", "172.30.55.44", "--ip6", "2001:db8:abcd::5544", "n1", "c0") - verifyIPAddressConfig(c, "c0", "n1", "172.30.55.44", "2001:db8:abcd::5544") - verifyIPAddresses(c, "c0", "n1", "172.30.55.44", "2001:db8:abcd::5544") - - // Stop and restart the container - dockerCmd(c, "stop", "c0") - dockerCmd(c, "start", "c0") - - // verify requested addresses are applied and configs are still there - verifyIPAddressConfig(c, "c0", "n0", "172.28.99.88", "2001:db8:1234::9988") - verifyIPAddresses(c, "c0", "n0", "172.28.99.88", "2001:db8:1234::9988") - verifyIPAddressConfig(c, "c0", "n1", "172.30.55.44", "2001:db8:abcd::5544") - verifyIPAddresses(c, "c0", "n1", "172.30.55.44", "2001:db8:abcd::5544") - - // Still it should fail to connect to the default network with a specified IP (whatever ip) - out, _, err := dockerCmdWithError("network", "connect", "--ip", "172.21.55.44", "bridge", "c0") - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkAndIP.Error()) - -} - -func (s *DockerNetworkSuite) TestDockerNetworkConnectPreferredIPStoppedContainer(c *check.C) { - // create a container - dockerCmd(c, "create", "--name", "c0", "busybox", "top") - - // create a network - dockerCmd(c, "network", "create", "--ipv6", "--subnet=172.30.0.0/16", "--subnet=2001:db8:abcd::/64", "n0") - assertNwIsAvailable(c, "n0") - - // connect the container to the network specifying an ip addresses - dockerCmd(c, "network", "connect", "--ip", "172.30.55.44", "--ip6", "2001:db8:abcd::5544", "n0", "c0") - verifyIPAddressConfig(c, "c0", "n0", "172.30.55.44", "2001:db8:abcd::5544") - - // start the container, verify config has not changed and ip addresses are assigned - dockerCmd(c, "start", "c0") - c.Assert(waitRun("c0"), check.IsNil) - verifyIPAddressConfig(c, "c0", "n0", "172.30.55.44", "2001:db8:abcd::5544") - verifyIPAddresses(c, "c0", "n0", "172.30.55.44", "2001:db8:abcd::5544") - - // stop the container and check ip config has not changed - dockerCmd(c, "stop", "c0") - verifyIPAddressConfig(c, "c0", "n0", "172.30.55.44", "2001:db8:abcd::5544") -} - -func (s *DockerNetworkSuite) TestDockerNetworkUnsupportedRequiredIP(c *check.C) { - // requested IP is not supported on predefined networks - for _, mode := range []string{"none", "host", "bridge", "default"} { - checkUnsupportedNetworkAndIP(c, mode) - } - - // requested IP is not supported on networks with no user defined subnets - dockerCmd(c, "network", "create", "n0") - assertNwIsAvailable(c, "n0") - - out, _, err := dockerCmdWithError("run", "-d", "--ip", "172.28.99.88", "--net", "n0", "busybox", "top") - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkNoSubnetAndIP.Error()) - - out, _, err = dockerCmdWithError("run", "-d", "--ip6", "2001:db8:1234::9988", "--net", "n0", "busybox", "top") - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkNoSubnetAndIP.Error()) - - dockerCmd(c, "network", "rm", "n0") - assertNwNotAvailable(c, "n0") -} - -func checkUnsupportedNetworkAndIP(c *check.C, nwMode string) { - out, _, err := dockerCmdWithError("run", "-d", "--net", nwMode, "--ip", "172.28.99.88", "--ip6", "2001:db8:1234::9988", "busybox", "top") - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkAndIP.Error()) -} - -func verifyIPAddressConfig(c *check.C, cName, nwname, ipv4, ipv6 string) { - if ipv4 != "" { - out := inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAMConfig.IPv4Address", nwname)) - c.Assert(strings.TrimSpace(out), check.Equals, ipv4) - } - - if ipv6 != "" { - out := inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAMConfig.IPv6Address", nwname)) - c.Assert(strings.TrimSpace(out), check.Equals, ipv6) - } -} - -func verifyIPAddresses(c *check.C, cName, nwname, ipv4, ipv6 string) { - out := inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAddress", nwname)) - c.Assert(strings.TrimSpace(out), check.Equals, ipv4) - - out = inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.GlobalIPv6Address", nwname)) - c.Assert(strings.TrimSpace(out), check.Equals, ipv6) -} - -func (s *DockerNetworkSuite) TestDockerNetworkConnectLinkLocalIP(c *check.C) { - // create one test network - dockerCmd(c, "network", "create", "n0") - assertNwIsAvailable(c, "n0") - - // run a container with incorrect link-local address - _, _, err := dockerCmdWithError("run", "--link-local-ip", "169.253.5.5", "busybox", "top") - c.Assert(err, check.NotNil) - _, _, err = dockerCmdWithError("run", "--link-local-ip", "2001:db8::89", "busybox", "top") - c.Assert(err, check.NotNil) - - // run two containers with link-local ip on the test network - dockerCmd(c, "run", "-d", "--name", "c0", "--net=n0", "--link-local-ip", "169.254.7.7", "--link-local-ip", "fe80::254:77", "busybox", "top") - c.Assert(waitRun("c0"), check.IsNil) - dockerCmd(c, "run", "-d", "--name", "c1", "--net=n0", "--link-local-ip", "169.254.8.8", "--link-local-ip", "fe80::254:88", "busybox", "top") - c.Assert(waitRun("c1"), check.IsNil) - - // run a container on the default network and connect it to the test network specifying a link-local address - dockerCmd(c, "run", "-d", "--name", "c2", "busybox", "top") - c.Assert(waitRun("c2"), check.IsNil) - dockerCmd(c, "network", "connect", "--link-local-ip", "169.254.9.9", "n0", "c2") - - // verify the three containers can ping each other via the link-local addresses - _, _, err = dockerCmdWithError("exec", "c0", "ping", "-c", "1", "169.254.8.8") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "c1", "ping", "-c", "1", "169.254.9.9") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "c2", "ping", "-c", "1", "169.254.7.7") - c.Assert(err, check.IsNil) - - // Stop and restart the three containers - dockerCmd(c, "stop", "c0") - dockerCmd(c, "stop", "c1") - dockerCmd(c, "stop", "c2") - dockerCmd(c, "start", "c0") - dockerCmd(c, "start", "c1") - dockerCmd(c, "start", "c2") - - // verify the ping again - _, _, err = dockerCmdWithError("exec", "c0", "ping", "-c", "1", "169.254.8.8") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "c1", "ping", "-c", "1", "169.254.9.9") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "c2", "ping", "-c", "1", "169.254.7.7") - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestUserDefinedNetworkConnectDisconnectLink(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - dockerCmd(c, "network", "create", "-d", "bridge", "foo1") - dockerCmd(c, "network", "create", "-d", "bridge", "foo2") - - dockerCmd(c, "run", "-d", "--net=foo1", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - - // run a container in a user-defined network with a link for an existing container - // and a link for a container that doesn't exist - dockerCmd(c, "run", "-d", "--net=foo1", "--name=second", "--link=first:FirstInFoo1", - "--link=third:bar", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // ping to first and its alias FirstInFoo1 must succeed - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "FirstInFoo1") - c.Assert(err, check.IsNil) - - // connect first container to foo2 network - dockerCmd(c, "network", "connect", "foo2", "first") - // connect second container to foo2 network with a different alias for first container - dockerCmd(c, "network", "connect", "--link=first:FirstInFoo2", "foo2", "second") - - // ping the new alias in network foo2 - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "FirstInFoo2") - c.Assert(err, check.IsNil) - - // disconnect first container from foo1 network - dockerCmd(c, "network", "disconnect", "foo1", "first") - - // link in foo1 network must fail - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "FirstInFoo1") - c.Assert(err, check.NotNil) - - // link in foo2 network must succeed - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "FirstInFoo2") - c.Assert(err, check.IsNil) -} - -func (s *DockerNetworkSuite) TestDockerNetworkDisconnectDefault(c *check.C) { - netWorkName1 := "test1" - netWorkName2 := "test2" - containerName := "foo" - - dockerCmd(c, "network", "create", netWorkName1) - dockerCmd(c, "network", "create", netWorkName2) - dockerCmd(c, "create", "--name", containerName, "busybox", "top") - dockerCmd(c, "network", "connect", netWorkName1, containerName) - dockerCmd(c, "network", "connect", netWorkName2, containerName) - dockerCmd(c, "network", "disconnect", "bridge", containerName) - - dockerCmd(c, "start", containerName) - c.Assert(waitRun(containerName), checker.IsNil) - networks := inspectField(c, containerName, "NetworkSettings.Networks") - c.Assert(networks, checker.Contains, netWorkName1, check.Commentf(fmt.Sprintf("Should contain '%s' network", netWorkName1))) - c.Assert(networks, checker.Contains, netWorkName2, check.Commentf(fmt.Sprintf("Should contain '%s' network", netWorkName2))) - c.Assert(networks, checker.Not(checker.Contains), "bridge", check.Commentf("Should not contain 'bridge' network")) -} - -func (s *DockerNetworkSuite) TestDockerNetworkConnectWithAliasOnDefaultNetworks(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - - defaults := []string{"bridge", "host", "none"} - out, _ := dockerCmd(c, "run", "-d", "--net=none", "busybox", "top") - containerID := strings.TrimSpace(out) - for _, net := range defaults { - res, _, err := dockerCmdWithError("network", "connect", "--alias", "alias"+net, net, containerID) - c.Assert(err, checker.NotNil) - c.Assert(res, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error()) - } -} - -func (s *DockerSuite) TestUserDefinedNetworkConnectDisconnectAlias(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - dockerCmd(c, "network", "create", "-d", "bridge", "net1") - dockerCmd(c, "network", "create", "-d", "bridge", "net2") - - cid, _ := dockerCmd(c, "run", "-d", "--net=net1", "--name=first", "--net-alias=foo", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - - dockerCmd(c, "run", "-d", "--net=net1", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // ping first container and its alias - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo") - c.Assert(err, check.IsNil) - - // ping first container's short-id alias - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", stringid.TruncateID(cid)) - c.Assert(err, check.IsNil) - - // connect first container to net2 network - dockerCmd(c, "network", "connect", "--alias=bar", "net2", "first") - // connect second container to foo2 network with a different alias for first container - dockerCmd(c, "network", "connect", "net2", "second") - - // ping the new alias in network foo2 - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "bar") - c.Assert(err, check.IsNil) - - // disconnect first container from net1 network - dockerCmd(c, "network", "disconnect", "net1", "first") - - // ping to net1 scoped alias "foo" must fail - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo") - c.Assert(err, check.NotNil) - - // ping to net2 scoped alias "bar" must still succeed - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "bar") - c.Assert(err, check.IsNil) - // ping to net2 scoped alias short-id must still succeed - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", stringid.TruncateID(cid)) - c.Assert(err, check.IsNil) - - // verify the alias option is rejected when running on predefined network - out, _, err := dockerCmdWithError("run", "--rm", "--name=any", "--net-alias=any", "busybox", "top") - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error()) - - // verify the alias option is rejected when connecting to predefined network - out, _, err = dockerCmdWithError("network", "connect", "--alias=any", "bridge", "first") - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error()) -} - -func (s *DockerSuite) TestUserDefinedNetworkConnectivity(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - dockerCmd(c, "network", "create", "-d", "bridge", "br.net1") - - dockerCmd(c, "run", "-d", "--net=br.net1", "--name=c1.net1", "busybox", "top") - c.Assert(waitRun("c1.net1"), check.IsNil) - - dockerCmd(c, "run", "-d", "--net=br.net1", "--name=c2.net1", "busybox", "top") - c.Assert(waitRun("c2.net1"), check.IsNil) - - // ping first container by its unqualified name - _, _, err := dockerCmdWithError("exec", "c2.net1", "ping", "-c", "1", "c1.net1") - c.Assert(err, check.IsNil) - - // ping first container by its qualified name - _, _, err = dockerCmdWithError("exec", "c2.net1", "ping", "-c", "1", "c1.net1.br.net1") - c.Assert(err, check.IsNil) - - // ping with first qualified name masked by an additional domain. should fail - _, _, err = dockerCmdWithError("exec", "c2.net1", "ping", "-c", "1", "c1.net1.br.net1.google.com") - c.Assert(err, check.NotNil) -} - -func (s *DockerSuite) TestEmbeddedDNSInvalidInput(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - dockerCmd(c, "network", "create", "-d", "bridge", "nw1") - - // Sending garbage to embedded DNS shouldn't crash the daemon - dockerCmd(c, "run", "-i", "--net=nw1", "--name=c1", "debian:jessie", "bash", "-c", "echo InvalidQuery > /dev/udp/127.0.0.11/53") -} - -func (s *DockerSuite) TestDockerNetworkConnectFailsNoInspectChange(c *check.C) { - dockerCmd(c, "run", "-d", "--name=bb", "busybox", "top") - c.Assert(waitRun("bb"), check.IsNil) - - ns0 := inspectField(c, "bb", "NetworkSettings.Networks.bridge") - - // A failing redundant network connect should not alter current container's endpoint settings - _, _, err := dockerCmdWithError("network", "connect", "bridge", "bb") - c.Assert(err, check.NotNil) - - ns1 := inspectField(c, "bb", "NetworkSettings.Networks.bridge") - c.Assert(ns1, check.Equals, ns0) -} - -func (s *DockerSuite) TestDockerNetworkInternalMode(c *check.C) { - dockerCmd(c, "network", "create", "--driver=bridge", "--internal", "internal") - assertNwIsAvailable(c, "internal") - nr := getNetworkResource(c, "internal") - c.Assert(nr.Internal, checker.True) - - dockerCmd(c, "run", "-d", "--net=internal", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--net=internal", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - out, _, err := dockerCmdWithError("exec", "first", "ping", "-W", "4", "-c", "1", "www.google.com") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, "ping: bad address") - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) -} - -// Test for #21401 -func (s *DockerNetworkSuite) TestDockerNetworkCreateDeleteSpecialCharacters(c *check.C) { - dockerCmd(c, "network", "create", "test@#$") - assertNwIsAvailable(c, "test@#$") - dockerCmd(c, "network", "rm", "test@#$") - assertNwNotAvailable(c, "test@#$") - - dockerCmd(c, "network", "create", "kiwl$%^") - assertNwIsAvailable(c, "kiwl$%^") - dockerCmd(c, "network", "rm", "kiwl$%^") - assertNwNotAvailable(c, "kiwl$%^") -} - -func (s *DockerDaemonSuite) TestDaemonRestartRestoreBridgeNetwork(t *check.C) { - testRequires(t, DaemonIsLinux) - if err := s.d.StartWithBusybox("--live-restore"); err != nil { - t.Fatal(err) - } - defer s.d.Stop() - oldCon := "old" - - _, err := s.d.Cmd("run", "-d", "--name", oldCon, "-p", "80:80", "busybox", "top") - if err != nil { - t.Fatal(err) - } - oldContainerIP, err := s.d.Cmd("inspect", "-f", "{{ .NetworkSettings.Networks.bridge.IPAddress }}", oldCon) - if err != nil { - t.Fatal(err) - } - // Kill the daemon - if err := s.d.Kill(); err != nil { - t.Fatal(err) - } - - // restart the daemon - if err := s.d.Start("--live-restore"); err != nil { - t.Fatal(err) - } - - // start a new container, the new container's ip should not be the same with - // old running container. - newCon := "new" - _, err = s.d.Cmd("run", "-d", "--name", newCon, "busybox", "top") - if err != nil { - t.Fatal(err) - } - newContainerIP, err := s.d.Cmd("inspect", "-f", "{{ .NetworkSettings.Networks.bridge.IPAddress }}", newCon) - if err != nil { - t.Fatal(err) - } - if strings.Compare(strings.TrimSpace(oldContainerIP), strings.TrimSpace(newContainerIP)) == 0 { - t.Fatalf("new container ip should not equal to old running container ip") - } - - // start a new container, the new container should ping old running container - _, err = s.d.Cmd("run", "-t", "busybox", "ping", "-c", "1", oldContainerIP) - if err != nil { - t.Fatal(err) - } - - // start a new container, trying to publish port 80:80 should fail - out, err := s.d.Cmd("run", "-p", "80:80", "-d", "busybox", "top") - if err == nil || !strings.Contains(out, "Bind for 0.0.0.0:80 failed: port is already allocated") { - t.Fatalf("80 port is allocated to old running container, it should failed on allocating to new container") - } - - // kill old running container and try to allocate again - _, err = s.d.Cmd("kill", oldCon) - if err != nil { - t.Fatal(err) - } - id, err := s.d.Cmd("run", "-p", "80:80", "-d", "busybox", "top") - if err != nil { - t.Fatal(err) - } - - // Cleanup because these containers will not be shut down by daemon - out, err = s.d.Cmd("stop", newCon) - if err != nil { - t.Fatalf("err: %v %v", err, string(out)) - } - _, err = s.d.Cmd("stop", strings.TrimSpace(id)) - if err != nil { - t.Fatal(err) - } -} - -func (s *DockerNetworkSuite) TestDockerNetworkFlagAlias(c *check.C) { - dockerCmd(c, "network", "create", "user") - output, status := dockerCmd(c, "run", "--rm", "--network=user", "--network-alias=foo", "busybox", "true") - c.Assert(status, checker.Equals, 0, check.Commentf("unexpected status code %d (%s)", status, output)) - - output, status, _ = dockerCmdWithError("run", "--rm", "--net=user", "--network=user", "busybox", "true") - c.Assert(status, checker.Equals, 0, check.Commentf("unexpected status code %d (%s)", status, output)) - - output, status, _ = dockerCmdWithError("run", "--rm", "--network=user", "--net-alias=foo", "--network-alias=bar", "busybox", "true") - c.Assert(status, checker.Equals, 0, check.Commentf("unexpected status code %d (%s)", status, output)) -} - -func (s *DockerNetworkSuite) TestDockerNetworkValidateIP(c *check.C) { - _, _, err := dockerCmdWithError("network", "create", "--ipv6", "--subnet=172.28.0.0/16", "--subnet=2001:db8:1234::/64", "mynet") - c.Assert(err, check.IsNil) - assertNwIsAvailable(c, "mynet") - - _, _, err = dockerCmdWithError("run", "-d", "--name", "mynet0", "--net=mynet", "--ip", "172.28.99.88", "--ip6", "2001:db8:1234::9988", "busybox", "top") - c.Assert(err, check.IsNil) - c.Assert(waitRun("mynet0"), check.IsNil) - verifyIPAddressConfig(c, "mynet0", "mynet", "172.28.99.88", "2001:db8:1234::9988") - verifyIPAddresses(c, "mynet0", "mynet", "172.28.99.88", "2001:db8:1234::9988") - - _, _, err = dockerCmdWithError("run", "--net=mynet", "--ip", "mynet_ip", "--ip6", "2001:db8:1234::9999", "busybox", "top") - c.Assert(err.Error(), checker.Contains, "invalid IPv4 address") - _, _, err = dockerCmdWithError("run", "--net=mynet", "--ip", "172.28.99.99", "--ip6", "mynet_ip6", "busybox", "top") - c.Assert(err.Error(), checker.Contains, "invalid IPv6 address") - // This is a case of IPv4 address to `--ip6` - _, _, err = dockerCmdWithError("run", "--net=mynet", "--ip6", "172.28.99.99", "busybox", "top") - c.Assert(err.Error(), checker.Contains, "invalid IPv6 address") - // This is a special case of an IPv4-mapped IPv6 address - _, _, err = dockerCmdWithError("run", "--net=mynet", "--ip6", "::ffff:172.28.99.99", "busybox", "top") - c.Assert(err.Error(), checker.Contains, "invalid IPv6 address") -} - -// Test case for 26220 -func (s *DockerNetworkSuite) TestDockerNetworkDisconnectFromBridge(c *check.C) { - out, _ := dockerCmd(c, "network", "inspect", "--format", "{{.Id}}", "bridge") - - network := strings.TrimSpace(out) - - name := "test" - dockerCmd(c, "create", "--name", name, "busybox", "top") - - _, _, err := dockerCmdWithError("network", "disconnect", network, name) - c.Assert(err, check.IsNil) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_oom_killed_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_oom_killed_test.go deleted file mode 100644 index bcf59f8..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_oom_killed_test.go +++ /dev/null @@ -1,30 +0,0 @@ -// +build !windows - -package main - -import ( - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestInspectOomKilledTrue(c *check.C) { - testRequires(c, DaemonIsLinux, memoryLimitSupport, swapMemorySupport) - - name := "testoomkilled" - _, exitCode, _ := dockerCmdWithError("run", "--name", name, "--memory", "32MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done") - - c.Assert(exitCode, checker.Equals, 137, check.Commentf("OOM exit should be 137")) - - oomKilled := inspectField(c, name, "State.OOMKilled") - c.Assert(oomKilled, checker.Equals, "true") -} - -func (s *DockerSuite) TestInspectOomKilledFalse(c *check.C) { - testRequires(c, DaemonIsLinux, memoryLimitSupport, swapMemorySupport) - - name := "testoomkilled" - dockerCmd(c, "run", "--name", name, "--memory", "32MB", "busybox", "sh", "-c", "echo hello world") - - oomKilled := inspectField(c, name, "State.OOMKilled") - c.Assert(oomKilled, checker.Equals, "false") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_pause_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_pause_test.go deleted file mode 100644 index 9217a69..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_pause_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package main - -import ( - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestPause(c *check.C) { - testRequires(c, IsPausable) - defer unpauseAllContainers() - - name := "testeventpause" - runSleepingContainer(c, "-d", "--name", name) - - dockerCmd(c, "pause", name) - pausedContainers, err := getSliceOfPausedContainers() - c.Assert(err, checker.IsNil) - c.Assert(len(pausedContainers), checker.Equals, 1) - - dockerCmd(c, "unpause", name) - - out, _ := dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c)) - events := strings.Split(strings.TrimSpace(out), "\n") - actions := eventActionsByIDAndType(c, events, name, "container") - - c.Assert(actions[len(actions)-2], checker.Equals, "pause") - c.Assert(actions[len(actions)-1], checker.Equals, "unpause") -} - -func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) { - testRequires(c, IsPausable) - defer unpauseAllContainers() - - containers := []string{ - "testpausewithmorecontainers1", - "testpausewithmorecontainers2", - } - for _, name := range containers { - runSleepingContainer(c, "-d", "--name", name) - } - dockerCmd(c, append([]string{"pause"}, containers...)...) - pausedContainers, err := getSliceOfPausedContainers() - c.Assert(err, checker.IsNil) - c.Assert(len(pausedContainers), checker.Equals, len(containers)) - - dockerCmd(c, append([]string{"unpause"}, containers...)...) - - out, _ := dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c)) - events := strings.Split(strings.TrimSpace(out), "\n") - - for _, name := range containers { - actions := eventActionsByIDAndType(c, events, name, "container") - - c.Assert(actions[len(actions)-2], checker.Equals, "pause") - c.Assert(actions[len(actions)-1], checker.Equals, "unpause") - } -} - -func (s *DockerSuite) TestPauseFailsOnWindowsServerContainers(c *check.C) { - testRequires(c, DaemonIsWindows, NotPausable) - runSleepingContainer(c, "-d", "--name=test") - out, _, _ := dockerCmdWithError("pause", "test") - c.Assert(out, checker.Contains, "cannot pause Windows Server Containers") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_plugins_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_plugins_test.go deleted file mode 100644 index 380357d..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_plugins_test.go +++ /dev/null @@ -1,393 +0,0 @@ -package main - -import ( - "fmt" - "os/exec" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" - - "io/ioutil" - "os" - "path/filepath" - "strings" -) - -var ( - pluginProcessName = "sample-volume-plugin" - pName = "tiborvass/sample-volume-plugin" - npName = "tiborvass/test-docker-netplugin" - pTag = "latest" - pNameWithTag = pName + ":" + pTag - npNameWithTag = npName + ":" + pTag -) - -func (s *DockerSuite) TestPluginBasicOps(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err := dockerCmdWithError("plugin", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, pName) - c.Assert(out, checker.Contains, pTag) - c.Assert(out, checker.Contains, "true") - - id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag) - id = strings.TrimSpace(id) - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "is enabled") - - _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, pNameWithTag) - - _, err = os.Stat(filepath.Join(dockerBasePath, "plugins", id)) - if !os.IsNotExist(err) { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestPluginForceRemove(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) - c.Assert(out, checker.Contains, "is enabled") - - out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, pNameWithTag) -} - -func (s *DockerSuite) TestPluginActive(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) - c.Assert(err, checker.IsNil) - - _, _, err = dockerCmdWithError("volume", "create", "-d", pNameWithTag, "--name", "testvol1") - c.Assert(err, checker.IsNil) - - out, _, err := dockerCmdWithError("plugin", "disable", pNameWithTag) - c.Assert(out, checker.Contains, "in use") - - _, _, err = dockerCmdWithError("volume", "rm", "testvol1") - c.Assert(err, checker.IsNil) - - _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, pNameWithTag) -} - -func (s *DockerSuite) TestPluginActiveNetwork(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", npNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("network", "create", "-d", npNameWithTag, "test") - c.Assert(err, checker.IsNil) - - nID := strings.TrimSpace(out) - - out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag) - c.Assert(out, checker.Contains, "is in use") - - _, _, err = dockerCmdWithError("network", "rm", nID) - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag) - c.Assert(out, checker.Contains, "is enabled") - - _, _, err = dockerCmdWithError("plugin", "disable", npNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, npNameWithTag) -} - -func (s *DockerSuite) TestPluginInstallDisable(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, pName) - - out, _, err = dockerCmdWithError("plugin", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "false") - - out, _, err = dockerCmdWithError("plugin", "enable", pName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, pName) - - out, _, err = dockerCmdWithError("plugin", "disable", pName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, pName) - - out, _, err = dockerCmdWithError("plugin", "remove", pName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, pName) -} - -func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, pName) - - dockerCmd(c, "volume", "ls") -} - -func (s *DockerSuite) TestPluginSet(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName) - c.Assert(strings.TrimSpace(out), checker.Contains, pName) - - env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName) - c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]") - - dockerCmd(c, "plugin", "set", pName, "DEBUG=1") - - env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName) - c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]") -} - -func (s *DockerSuite) TestPluginInstallArgs(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1") - c.Assert(strings.TrimSpace(out), checker.Contains, pName) - - env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName) - c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]") -} - -func (s *DockerRegistrySuite) TestPluginInstallImage(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64) - - repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - // tag the image to upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - // push the image to the registry - dockerCmd(c, "push", repoName) - - out, _, err := dockerCmdWithError("plugin", "install", repoName) - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "target is image") -} - -func (s *DockerSuite) TestPluginEnableDisableNegative(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, pName) - - out, _, err = dockerCmdWithError("plugin", "enable", pName) - c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled") - - _, _, err = dockerCmdWithError("plugin", "disable", pName) - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("plugin", "disable", pName) - c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled") - - _, _, err = dockerCmdWithError("plugin", "remove", pName) - c.Assert(err, checker.IsNil) -} - -func (s *DockerSuite) TestPluginCreate(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - - name := "foo/bar-driver" - temp, err := ioutil.TempDir("", "foo") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(temp) - - data := `{"description": "foo plugin"}` - err = ioutil.WriteFile(filepath.Join(temp, "config.json"), []byte(data), 0644) - c.Assert(err, checker.IsNil) - - err = os.MkdirAll(filepath.Join(temp, "rootfs"), 0700) - c.Assert(err, checker.IsNil) - - out, _, err := dockerCmdWithError("plugin", "create", name, temp) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name) - - out, _, err = dockerCmdWithError("plugin", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name) - - out, _, err = dockerCmdWithError("plugin", "create", name, temp) - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "already exist") - - out, _, err = dockerCmdWithError("plugin", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name) - // The output will consists of one HEADER line and one line of foo/bar-driver - c.Assert(len(strings.Split(strings.TrimSpace(out), "\n")), checker.Equals, 2) -} - -func (s *DockerSuite) TestPluginInspect(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - _, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err := dockerCmdWithError("plugin", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, pName) - c.Assert(out, checker.Contains, pTag) - c.Assert(out, checker.Contains, "true") - - // Find the ID first - out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag) - c.Assert(err, checker.IsNil) - id := strings.TrimSpace(out) - c.Assert(id, checker.Not(checker.Equals), "") - - // Long form - out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, id) - - // Short form - out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5]) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, id) - - // Name with tag form - out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, id) - - // Name without tag form - out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, id) - - _, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag) - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, pNameWithTag) - - // After remove nothing should be found - _, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5]) - c.Assert(err, checker.NotNil) -} - -// Test case for https://github.com/docker/docker/pull/29186#discussion_r91277345 -func (s *DockerSuite) TestPluginInspectOnWindows(c *check.C) { - // This test should work on Windows only - testRequires(c, DaemonIsWindows) - - out, _, err := dockerCmdWithError("plugin", "inspect", "foobar") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "plugins are not supported on this platform") - c.Assert(err.Error(), checker.Contains, "plugins are not supported on this platform") -} - -func (s *DockerTrustSuite) TestPluginTrustedInstall(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - - trustedName := s.setupTrustedplugin(c, pNameWithTag, "trusted-plugin-install") - - installCmd := exec.Command(dockerBinary, "plugin", "install", "--grant-all-permissions", trustedName) - s.trustedCmd(installCmd) - out, _, err := runCommandWithOutput(installCmd) - - c.Assert(strings.TrimSpace(out), checker.Contains, trustedName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, trustedName) - - out, _, err = dockerCmdWithError("plugin", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "true") - - out, _, err = dockerCmdWithError("plugin", "disable", trustedName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, trustedName) - - out, _, err = dockerCmdWithError("plugin", "enable", trustedName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, trustedName) - - out, _, err = dockerCmdWithError("plugin", "rm", "-f", trustedName) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, trustedName) - - // Try untrusted pull to ensure we pushed the tag to the registry - installCmd = exec.Command(dockerBinary, "plugin", "install", "--disable-content-trust=true", "--grant-all-permissions", trustedName) - s.trustedCmd(installCmd) - out, _, err = runCommandWithOutput(installCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out)) - - out, _, err = dockerCmdWithError("plugin", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "true") - -} - -func (s *DockerTrustSuite) TestPluginUntrustedInstall(c *check.C) { - testRequires(c, DaemonIsLinux, IsAmd64, Network) - - pluginName := fmt.Sprintf("%v/dockercliuntrusted/plugintest:latest", privateRegistryURL) - // install locally and push to private registry - dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--alias", pluginName, pNameWithTag) - dockerCmd(c, "plugin", "push", pluginName) - dockerCmd(c, "plugin", "rm", "-f", pluginName) - - // Try trusted install on untrusted plugin - installCmd := exec.Command(dockerBinary, "plugin", "install", "--grant-all-permissions", pluginName) - s.trustedCmd(installCmd) - out, _, err := runCommandWithOutput(installCmd) - - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Error: remote trust data does not exist", check.Commentf(out)) -} - -func (s *DockerSuite) TestPluginUpgrade(c *check.C) { - testRequires(c, DaemonIsLinux, Network, SameHostDaemon, IsAmd64) - plugin := "cpuguy83/docker-volume-driver-plugin-local:latest" - pluginV2 := "cpuguy83/docker-volume-driver-plugin-local:v2" - - dockerCmd(c, "plugin", "install", "--grant-all-permissions", plugin) - dockerCmd(c, "volume", "create", "--driver", plugin, "bananas") - dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "touch /apple/core") - - out, _, err := dockerCmdWithError("plugin", "upgrade", "--grant-all-permissions", plugin, pluginV2) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "disabled before upgrading") - - out, _ = dockerCmd(c, "plugin", "inspect", "--format={{.ID}}", plugin) - id := strings.TrimSpace(out) - - // make sure "v2" does not exists - _, err = os.Stat(filepath.Join(dockerBasePath, "plugins", id, "rootfs", "v2")) - c.Assert(os.IsNotExist(err), checker.True, check.Commentf(out)) - - dockerCmd(c, "plugin", "disable", "-f", plugin) - dockerCmd(c, "plugin", "upgrade", "--grant-all-permissions", "--skip-remote-check", plugin, pluginV2) - - // make sure "v2" file exists - _, err = os.Stat(filepath.Join(dockerBasePath, "plugins", id, "rootfs", "v2")) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "plugin", "enable", plugin) - dockerCmd(c, "volume", "inspect", "bananas") - dockerCmd(c, "run", "--rm", "-v", "bananas:/apple", "busybox", "sh", "-c", "ls -lh /apple/core") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_port_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_port_test.go deleted file mode 100644 index 80b00fe..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_port_test.go +++ /dev/null @@ -1,319 +0,0 @@ -package main - -import ( - "fmt" - "net" - "regexp" - "sort" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestPortList(c *check.C) { - testRequires(c, DaemonIsLinux) - // one port - out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox", "top") - firstID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "port", firstID, "80") - - err := assertPortList(c, out, []string{"0.0.0.0:9876"}) - // Port list is not correct - c.Assert(err, checker.IsNil) - - out, _ = dockerCmd(c, "port", firstID) - - err = assertPortList(c, out, []string{"80/tcp -> 0.0.0.0:9876"}) - // Port list is not correct - c.Assert(err, checker.IsNil) - - dockerCmd(c, "rm", "-f", firstID) - - // three port - out, _ = dockerCmd(c, "run", "-d", - "-p", "9876:80", - "-p", "9877:81", - "-p", "9878:82", - "busybox", "top") - ID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "port", ID, "80") - - err = assertPortList(c, out, []string{"0.0.0.0:9876"}) - // Port list is not correct - c.Assert(err, checker.IsNil) - - out, _ = dockerCmd(c, "port", ID) - - err = assertPortList(c, out, []string{ - "80/tcp -> 0.0.0.0:9876", - "81/tcp -> 0.0.0.0:9877", - "82/tcp -> 0.0.0.0:9878"}) - // Port list is not correct - c.Assert(err, checker.IsNil) - - dockerCmd(c, "rm", "-f", ID) - - // more and one port mapped to the same container port - out, _ = dockerCmd(c, "run", "-d", - "-p", "9876:80", - "-p", "9999:80", - "-p", "9877:81", - "-p", "9878:82", - "busybox", "top") - ID = strings.TrimSpace(out) - - out, _ = dockerCmd(c, "port", ID, "80") - - err = assertPortList(c, out, []string{"0.0.0.0:9876", "0.0.0.0:9999"}) - // Port list is not correct - c.Assert(err, checker.IsNil) - - out, _ = dockerCmd(c, "port", ID) - - err = assertPortList(c, out, []string{ - "80/tcp -> 0.0.0.0:9876", - "80/tcp -> 0.0.0.0:9999", - "81/tcp -> 0.0.0.0:9877", - "82/tcp -> 0.0.0.0:9878"}) - // Port list is not correct - c.Assert(err, checker.IsNil) - dockerCmd(c, "rm", "-f", ID) - - testRange := func() { - // host port ranges used - IDs := make([]string, 3) - for i := 0; i < 3; i++ { - out, _ = dockerCmd(c, "run", "-d", - "-p", "9090-9092:80", - "busybox", "top") - IDs[i] = strings.TrimSpace(out) - - out, _ = dockerCmd(c, "port", IDs[i]) - - err = assertPortList(c, out, []string{fmt.Sprintf("80/tcp -> 0.0.0.0:%d", 9090+i)}) - // Port list is not correct - c.Assert(err, checker.IsNil) - } - - // test port range exhaustion - out, _, err = dockerCmdWithError("run", "-d", - "-p", "9090-9092:80", - "busybox", "top") - // Exhausted port range did not return an error - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - - for i := 0; i < 3; i++ { - dockerCmd(c, "rm", "-f", IDs[i]) - } - } - testRange() - // Verify we ran re-use port ranges after they are no longer in use. - testRange() - - // test invalid port ranges - for _, invalidRange := range []string{"9090-9089:80", "9090-:80", "-9090:80"} { - out, _, err = dockerCmdWithError("run", "-d", - "-p", invalidRange, - "busybox", "top") - // Port range should have returned an error - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - } - - // test host range:container range spec. - out, _ = dockerCmd(c, "run", "-d", - "-p", "9800-9803:80-83", - "busybox", "top") - ID = strings.TrimSpace(out) - - out, _ = dockerCmd(c, "port", ID) - - err = assertPortList(c, out, []string{ - "80/tcp -> 0.0.0.0:9800", - "81/tcp -> 0.0.0.0:9801", - "82/tcp -> 0.0.0.0:9802", - "83/tcp -> 0.0.0.0:9803"}) - // Port list is not correct - c.Assert(err, checker.IsNil) - dockerCmd(c, "rm", "-f", ID) - - // test mixing protocols in same port range - out, _ = dockerCmd(c, "run", "-d", - "-p", "8000-8080:80", - "-p", "8000-8080:80/udp", - "busybox", "top") - ID = strings.TrimSpace(out) - - out, _ = dockerCmd(c, "port", ID) - - err = assertPortList(c, out, []string{ - "80/tcp -> 0.0.0.0:8000", - "80/udp -> 0.0.0.0:8000"}) - // Port list is not correct - c.Assert(err, checker.IsNil) - dockerCmd(c, "rm", "-f", ID) -} - -func assertPortList(c *check.C, out string, expected []string) error { - lines := strings.Split(strings.Trim(out, "\n "), "\n") - if len(lines) != len(expected) { - return fmt.Errorf("different size lists %s, %d, %d", out, len(lines), len(expected)) - } - sort.Strings(lines) - sort.Strings(expected) - - for i := 0; i < len(expected); i++ { - if lines[i] != expected[i] { - return fmt.Errorf("|" + lines[i] + "!=" + expected[i] + "|") - } - } - - return nil -} - -func stopRemoveContainer(id string, c *check.C) { - dockerCmd(c, "rm", "-f", id) -} - -func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) { - testRequires(c, DaemonIsLinux) - // Run busybox with command line expose (equivalent to EXPOSE in image's Dockerfile) for the following ports - port1 := 80 - port2 := 443 - expose1 := fmt.Sprintf("--expose=%d", port1) - expose2 := fmt.Sprintf("--expose=%d", port2) - dockerCmd(c, "run", "-d", expose1, expose2, "busybox", "sleep", "5") - - // Check docker ps o/p for last created container reports the unpublished ports - unpPort1 := fmt.Sprintf("%d/tcp", port1) - unpPort2 := fmt.Sprintf("%d/tcp", port2) - out, _ := dockerCmd(c, "ps", "-n=1") - // Missing unpublished ports in docker ps output - c.Assert(out, checker.Contains, unpPort1) - // Missing unpublished ports in docker ps output - c.Assert(out, checker.Contains, unpPort2) - - // Run the container forcing to publish the exposed ports - dockerCmd(c, "run", "-d", "-P", expose1, expose2, "busybox", "sleep", "5") - - // Check docker ps o/p for last created container reports the exposed ports in the port bindings - expBndRegx1 := regexp.MustCompile(`0.0.0.0:\d\d\d\d\d->` + unpPort1) - expBndRegx2 := regexp.MustCompile(`0.0.0.0:\d\d\d\d\d->` + unpPort2) - out, _ = dockerCmd(c, "ps", "-n=1") - // Cannot find expected port binding port (0.0.0.0:xxxxx->unpPort1) in docker ps output - c.Assert(expBndRegx1.MatchString(out), checker.Equals, true, check.Commentf("out: %s; unpPort1: %s", out, unpPort1)) - // Cannot find expected port binding port (0.0.0.0:xxxxx->unpPort2) in docker ps output - c.Assert(expBndRegx2.MatchString(out), checker.Equals, true, check.Commentf("out: %s; unpPort2: %s", out, unpPort2)) - - // Run the container specifying explicit port bindings for the exposed ports - offset := 10000 - pFlag1 := fmt.Sprintf("%d:%d", offset+port1, port1) - pFlag2 := fmt.Sprintf("%d:%d", offset+port2, port2) - out, _ = dockerCmd(c, "run", "-d", "-p", pFlag1, "-p", pFlag2, expose1, expose2, "busybox", "sleep", "5") - id := strings.TrimSpace(out) - - // Check docker ps o/p for last created container reports the specified port mappings - expBnd1 := fmt.Sprintf("0.0.0.0:%d->%s", offset+port1, unpPort1) - expBnd2 := fmt.Sprintf("0.0.0.0:%d->%s", offset+port2, unpPort2) - out, _ = dockerCmd(c, "ps", "-n=1") - // Cannot find expected port binding (expBnd1) in docker ps output - c.Assert(out, checker.Contains, expBnd1) - // Cannot find expected port binding (expBnd2) in docker ps output - c.Assert(out, checker.Contains, expBnd2) - - // Remove container now otherwise it will interfere with next test - stopRemoveContainer(id, c) - - // Run the container with explicit port bindings and no exposed ports - out, _ = dockerCmd(c, "run", "-d", "-p", pFlag1, "-p", pFlag2, "busybox", "sleep", "5") - id = strings.TrimSpace(out) - - // Check docker ps o/p for last created container reports the specified port mappings - out, _ = dockerCmd(c, "ps", "-n=1") - // Cannot find expected port binding (expBnd1) in docker ps output - c.Assert(out, checker.Contains, expBnd1) - // Cannot find expected port binding (expBnd2) in docker ps output - c.Assert(out, checker.Contains, expBnd2) - // Remove container now otherwise it will interfere with next test - stopRemoveContainer(id, c) - - // Run the container with one unpublished exposed port and one explicit port binding - dockerCmd(c, "run", "-d", expose1, "-p", pFlag2, "busybox", "sleep", "5") - - // Check docker ps o/p for last created container reports the specified unpublished port and port mapping - out, _ = dockerCmd(c, "ps", "-n=1") - // Missing unpublished exposed ports (unpPort1) in docker ps output - c.Assert(out, checker.Contains, unpPort1) - // Missing port binding (expBnd2) in docker ps output - c.Assert(out, checker.Contains, expBnd2) -} - -func (s *DockerSuite) TestPortHostBinding(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "-d", "-p", "9876:80", "busybox", - "nc", "-l", "-p", "80") - firstID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "port", firstID, "80") - - err := assertPortList(c, out, []string{"0.0.0.0:9876"}) - // Port list is not correct - c.Assert(err, checker.IsNil) - - dockerCmd(c, "run", "--net=host", "busybox", - "nc", "localhost", "9876") - - dockerCmd(c, "rm", "-f", firstID) - - out, _, err = dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "9876") - // Port is still bound after the Container is removed - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) -} - -func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "-d", "-P", "--expose", "80", "busybox", - "nc", "-l", "-p", "80") - firstID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "port", firstID, "80") - - _, exposedPort, err := net.SplitHostPort(out) - c.Assert(err, checker.IsNil, check.Commentf("out: %s", out)) - - dockerCmd(c, "run", "--net=host", "busybox", - "nc", "localhost", strings.TrimSpace(exposedPort)) - - dockerCmd(c, "rm", "-f", firstID) - - out, _, err = dockerCmdWithError("run", "--net=host", "busybox", - "nc", "localhost", strings.TrimSpace(exposedPort)) - // Port is still bound after the Container is removed - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) -} - -func (s *DockerSuite) TestPortBindingOnSandbox(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - dockerCmd(c, "network", "create", "--internal", "-d", "bridge", "internal-net") - nr := getNetworkResource(c, "internal-net") - c.Assert(nr.Internal, checker.Equals, true) - - dockerCmd(c, "run", "--net", "internal-net", "-d", "--name", "c1", - "-p", "8080:8080", "busybox", "nc", "-l", "-p", "8080") - c.Assert(waitRun("c1"), check.IsNil) - - _, _, err := dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "8080") - c.Assert(err, check.NotNil, - check.Commentf("Port mapping on internal network is expected to fail")) - - // Connect container to another normal bridge network - dockerCmd(c, "network", "create", "-d", "bridge", "foo-net") - dockerCmd(c, "network", "connect", "foo-net", "c1") - - _, _, err = dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "8080") - c.Assert(err, check.IsNil, - check.Commentf("Port mapping on the new network is expected to succeed")) - -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_proxy_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_proxy_test.go deleted file mode 100644 index 1cf569b..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_proxy_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "net" - "os/exec" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, SameHostDaemon) // test is valid when DOCKER_HOST=unix://.. - - cmd := exec.Command(dockerBinary, "info") - cmd.Env = appendBaseEnv(false, "HTTP_PROXY=http://127.0.0.1:9999") - - out, _, err := runCommandWithOutput(cmd) - c.Assert(err, checker.IsNil, check.Commentf("%v", out)) - -} - -// Can't use localhost here since go has a special case to not use proxy if connecting to localhost -// See https://golang.org/pkg/net/http/#ProxyFromEnvironment -func (s *DockerDaemonSuite) TestCLIProxyProxyTCPSock(c *check.C) { - testRequires(c, SameHostDaemon) - // get the IP to use to connect since we can't use localhost - addrs, err := net.InterfaceAddrs() - c.Assert(err, checker.IsNil) - var ip string - for _, addr := range addrs { - sAddr := addr.String() - if !strings.Contains(sAddr, "127.0.0.1") { - addrArr := strings.Split(sAddr, "/") - ip = addrArr[0] - break - } - } - - c.Assert(ip, checker.Not(checker.Equals), "") - - err = s.d.Start("-H", "tcp://"+ip+":2375") - c.Assert(err, checker.IsNil) - cmd := exec.Command(dockerBinary, "info") - cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"} - out, _, err := runCommandWithOutput(cmd) - c.Assert(err, checker.NotNil, check.Commentf("%v", out)) - // Test with no_proxy - cmd.Env = append(cmd.Env, "NO_PROXY="+ip) - out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "info")) - c.Assert(err, checker.IsNil, check.Commentf("%v", out)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_prune_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_prune_unix_test.go deleted file mode 100644 index dabbc72..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_prune_unix_test.go +++ /dev/null @@ -1,91 +0,0 @@ -// +build !windows - -package main - -import ( - "strconv" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func pruneNetworkAndVerify(c *check.C, d *SwarmDaemon, kept, pruned []string) { - _, err := d.Cmd("network", "prune", "--force") - c.Assert(err, checker.IsNil) - out, err := d.Cmd("network", "ls", "--format", "{{.Name}}") - c.Assert(err, checker.IsNil) - for _, s := range kept { - c.Assert(out, checker.Contains, s) - } - for _, s := range pruned { - c.Assert(out, checker.Not(checker.Contains), s) - } -} - -func (s *DockerSwarmSuite) TestPruneNetwork(c *check.C) { - d := s.AddDaemon(c, true, true) - _, err := d.Cmd("network", "create", "n1") // used by container (testprune) - c.Assert(err, checker.IsNil) - _, err = d.Cmd("network", "create", "n2") - c.Assert(err, checker.IsNil) - _, err = d.Cmd("network", "create", "n3", "--driver", "overlay") // used by service (testprunesvc) - c.Assert(err, checker.IsNil) - _, err = d.Cmd("network", "create", "n4", "--driver", "overlay") - c.Assert(err, checker.IsNil) - - cName := "testprune" - _, err = d.Cmd("run", "-d", "--name", cName, "--net", "n1", "busybox", "top") - c.Assert(err, checker.IsNil) - - serviceName := "testprunesvc" - replicas := 1 - out, err := d.Cmd("service", "create", "--name", serviceName, - "--replicas", strconv.Itoa(replicas), - "--network", "n3", - "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, replicas+1) - - // prune and verify - pruneNetworkAndVerify(c, d, []string{"n1", "n3"}, []string{"n2", "n4"}) - - // remove containers, then prune and verify again - _, err = d.Cmd("rm", "-f", cName) - c.Assert(err, checker.IsNil) - _, err = d.Cmd("service", "rm", serviceName) - c.Assert(err, checker.IsNil) - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 0) - pruneNetworkAndVerify(c, d, []string{}, []string{"n1", "n3"}) -} - -func (s *DockerDaemonSuite) TestPruneImageDangling(c *check.C) { - c.Assert(s.d.StartWithBusybox(), checker.IsNil) - - out, _, err := s.d.buildImageWithOut("test", - `FROM busybox - LABEL foo=bar`, true, "-q") - c.Assert(err, checker.IsNil) - id := strings.TrimSpace(out) - - out, err = s.d.Cmd("images", "-q", "--no-trunc") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, id) - - out, err = s.d.Cmd("image", "prune", "--force") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id) - - out, err = s.d.Cmd("images", "-q", "--no-trunc") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, id) - - out, err = s.d.Cmd("image", "prune", "--force", "--all") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Contains, id) - - out, err = s.d.Cmd("images", "-q", "--no-trunc") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_ps_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_ps_test.go deleted file mode 100644 index 19ede90..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_ps_test.go +++ /dev/null @@ -1,952 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "sort" - "strconv" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/docker/docker/pkg/stringid" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestPsListContainersBase(c *check.C) { - out, _ := runSleepingContainer(c, "-d") - firstID := strings.TrimSpace(out) - - out, _ = runSleepingContainer(c, "-d") - secondID := strings.TrimSpace(out) - - // not long running - out, _ = dockerCmd(c, "run", "-d", "busybox", "true") - thirdID := strings.TrimSpace(out) - - out, _ = runSleepingContainer(c, "-d") - fourthID := strings.TrimSpace(out) - - // make sure the second is running - c.Assert(waitRun(secondID), checker.IsNil) - - // make sure third one is not running - dockerCmd(c, "wait", thirdID) - - // make sure the forth is running - c.Assert(waitRun(fourthID), checker.IsNil) - - // all - out, _ = dockerCmd(c, "ps", "-a") - c.Assert(assertContainerList(out, []string{fourthID, thirdID, secondID, firstID}), checker.Equals, true, check.Commentf("ALL: Container list is not in the correct order: \n%s", out)) - - // running - out, _ = dockerCmd(c, "ps") - c.Assert(assertContainerList(out, []string{fourthID, secondID, firstID}), checker.Equals, true, check.Commentf("RUNNING: Container list is not in the correct order: \n%s", out)) - - // limit - out, _ = dockerCmd(c, "ps", "-n=2", "-a") - expected := []string{fourthID, thirdID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("LIMIT & ALL: Container list is not in the correct order: \n%s", out)) - - out, _ = dockerCmd(c, "ps", "-n=2") - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("LIMIT: Container list is not in the correct order: \n%s", out)) - - // filter since - out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-a") - expected = []string{fourthID, thirdID, secondID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter & ALL: Container list is not in the correct order: \n%s", out)) - - out, _ = dockerCmd(c, "ps", "-f", "since="+firstID) - expected = []string{fourthID, secondID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out)) - - out, _ = dockerCmd(c, "ps", "-f", "since="+thirdID) - expected = []string{fourthID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out)) - - // filter before - out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-a") - expected = []string{thirdID, secondID, firstID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter & ALL: Container list is not in the correct order: \n%s", out)) - - out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID) - expected = []string{secondID, firstID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Container list is not in the correct order: \n%s", out)) - - out, _ = dockerCmd(c, "ps", "-f", "before="+thirdID) - expected = []string{secondID, firstID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out)) - - // filter since & before - out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-a") - expected = []string{thirdID, secondID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s", out)) - - out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID) - expected = []string{secondID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s", out)) - - // filter since & limit - out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2", "-a") - expected = []string{fourthID, thirdID} - - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out)) - - out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2") - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT: Container list is not in the correct order: \n%s", out)) - - // filter before & limit - out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1", "-a") - expected = []string{thirdID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out)) - - out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1") - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out)) - - // filter since & filter before & limit - out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1", "-a") - expected = []string{thirdID} - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out)) - - out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1") - c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out)) - -} - -func assertContainerList(out string, expected []string) bool { - lines := strings.Split(strings.Trim(out, "\n "), "\n") - - if len(lines)-1 != len(expected) { - return false - } - - containerIDIndex := strings.Index(lines[0], "CONTAINER ID") - for i := 0; i < len(expected); i++ { - foundID := lines[i+1][containerIDIndex : containerIDIndex+12] - if foundID != expected[i][:12] { - return false - } - } - - return true -} - -// FIXME(vdemeester) Move this into a unit test in daemon package -func (s *DockerSuite) TestPsListContainersInvalidFilterName(c *check.C) { - out, _, err := dockerCmdWithError("ps", "-f", "invalidFilter=test") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "Invalid filter") -} - -func (s *DockerSuite) TestPsListContainersSize(c *check.C) { - // Problematic on Windows as it doesn't report the size correctly @swernli - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "busybox") - - baseOut, _ := dockerCmd(c, "ps", "-s", "-n=1") - baseLines := strings.Split(strings.Trim(baseOut, "\n "), "\n") - baseSizeIndex := strings.Index(baseLines[0], "SIZE") - baseFoundsize := baseLines[1][baseSizeIndex:] - baseBytes, err := strconv.Atoi(strings.Split(baseFoundsize, " ")[0]) - c.Assert(err, checker.IsNil) - - name := "test_size" - dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test") - id, err := getIDByName(name) - c.Assert(err, checker.IsNil) - - runCmd := exec.Command(dockerBinary, "ps", "-s", "-n=1") - var out string - - wait := make(chan struct{}) - go func() { - out, _, err = runCommandWithOutput(runCmd) - close(wait) - }() - select { - case <-wait: - case <-time.After(3 * time.Second): - c.Fatalf("Calling \"docker ps -s\" timed out!") - } - c.Assert(err, checker.IsNil) - lines := strings.Split(strings.Trim(out, "\n "), "\n") - c.Assert(lines, checker.HasLen, 2, check.Commentf("Expected 2 lines for 'ps -s -n=1' output, got %d", len(lines))) - sizeIndex := strings.Index(lines[0], "SIZE") - idIndex := strings.Index(lines[0], "CONTAINER ID") - foundID := lines[1][idIndex : idIndex+12] - c.Assert(foundID, checker.Equals, id[:12], check.Commentf("Expected id %s, got %s", id[:12], foundID)) - expectedSize := fmt.Sprintf("%d B", (2 + baseBytes)) - foundSize := lines[1][sizeIndex:] - c.Assert(foundSize, checker.Contains, expectedSize, check.Commentf("Expected size %q, got %q", expectedSize, foundSize)) -} - -func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) { - // start exited container - out, _ := dockerCmd(c, "run", "-d", "busybox") - firstID := strings.TrimSpace(out) - - // make sure the exited container is not running - dockerCmd(c, "wait", firstID) - - // start running container - out, _ = dockerCmd(c, "run", "-itd", "busybox") - secondID := strings.TrimSpace(out) - - // filter containers by exited - out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=exited") - containerOut := strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, firstID) - - out, _ = dockerCmd(c, "ps", "-a", "--no-trunc", "-q", "--filter=status=running") - containerOut = strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, secondID) - - result := dockerCmdWithTimeout(time.Second*60, "ps", "-a", "-q", "--filter=status=rubbish") - c.Assert(result, icmd.Matches, icmd.Expected{ - ExitCode: 1, - Err: "Unrecognised filter value for status", - }) - - // Windows doesn't support pausing of containers - if daemonPlatform != "windows" { - // pause running container - out, _ = dockerCmd(c, "run", "-itd", "busybox") - pausedID := strings.TrimSpace(out) - dockerCmd(c, "pause", pausedID) - // make sure the container is unpaused to let the daemon stop it properly - defer func() { dockerCmd(c, "unpause", pausedID) }() - - out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=paused") - containerOut = strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, pausedID) - } -} - -func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) { - // Test legacy no health check - out, _ := runSleepingContainer(c, "--name=none_legacy") - containerID := strings.TrimSpace(out) - - waitForContainer(containerID) - - out, _ = dockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none") - containerOut := strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for legacy none filter, output: %q", containerID, containerOut, out)) - - // Test no health check specified explicitly - out, _ = runSleepingContainer(c, "--name=none", "--no-healthcheck") - containerID = strings.TrimSpace(out) - - waitForContainer(containerID) - - out, _ = dockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none") - containerOut = strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for none filter, output: %q", containerID, containerOut, out)) - - // Test failing health check - out, _ = runSleepingContainer(c, "--name=failing_container", "--health-cmd=exit 1", "--health-interval=1s") - containerID = strings.TrimSpace(out) - - waitForHealthStatus(c, "failing_container", "starting", "unhealthy") - - out, _ = dockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=unhealthy") - containerOut = strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for unhealthy filter, output: %q", containerID, containerOut, out)) - - // Check passing healthcheck - out, _ = runSleepingContainer(c, "--name=passing_container", "--health-cmd=exit 0", "--health-interval=1s") - containerID = strings.TrimSpace(out) - - waitForHealthStatus(c, "passing_container", "starting", "healthy") - - out, _ = dockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy") - containerOut = strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out)) -} - -func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) { - // start container - out, _ := dockerCmd(c, "run", "-d", "busybox") - firstID := strings.TrimSpace(out) - - // start another container - runSleepingContainer(c) - - // filter containers by id - out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=id="+firstID) - containerOut := strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, firstID[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)) -} - -func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) { - // start container - dockerCmd(c, "run", "--name=a_name_to_match", "busybox") - id, err := getIDByName("a_name_to_match") - c.Assert(err, check.IsNil) - - // start another container - runSleepingContainer(c, "--name=b_name_to_match") - - // filter containers by name - out, _ := dockerCmd(c, "ps", "-a", "-q", "--filter=name=a_name_to_match") - containerOut := strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, id[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", id[:12], containerOut, out)) -} - -// Test for the ancestor filter for ps. -// There is also the same test but with image:tag@digest in docker_cli_by_digest_test.go -// -// What the test setups : -// - Create 2 image based on busybox using the same repository but different tags -// - Create an image based on the previous image (images_ps_filter_test2) -// - Run containers for each of those image (busybox, images_ps_filter_test1, images_ps_filter_test2) -// - Filter them out :P -func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) { - // Build images - imageName1 := "images_ps_filter_test1" - imageID1, err := buildImage(imageName1, - `FROM busybox - LABEL match me 1`, true) - c.Assert(err, checker.IsNil) - - imageName1Tagged := "images_ps_filter_test1:tag" - imageID1Tagged, err := buildImage(imageName1Tagged, - `FROM busybox - LABEL match me 1 tagged`, true) - c.Assert(err, checker.IsNil) - - imageName2 := "images_ps_filter_test2" - imageID2, err := buildImage(imageName2, - fmt.Sprintf(`FROM %s - LABEL match me 2`, imageName1), true) - c.Assert(err, checker.IsNil) - - // start containers - dockerCmd(c, "run", "--name=first", "busybox", "echo", "hello") - firstID, err := getIDByName("first") - c.Assert(err, check.IsNil) - - // start another container - dockerCmd(c, "run", "--name=second", "busybox", "echo", "hello") - secondID, err := getIDByName("second") - c.Assert(err, check.IsNil) - - // start third container - dockerCmd(c, "run", "--name=third", imageName1, "echo", "hello") - thirdID, err := getIDByName("third") - c.Assert(err, check.IsNil) - - // start fourth container - dockerCmd(c, "run", "--name=fourth", imageName1Tagged, "echo", "hello") - fourthID, err := getIDByName("fourth") - c.Assert(err, check.IsNil) - - // start fifth container - dockerCmd(c, "run", "--name=fifth", imageName2, "echo", "hello") - fifthID, err := getIDByName("fifth") - c.Assert(err, check.IsNil) - - var filterTestSuite = []struct { - filterName string - expectedIDs []string - }{ - // non existent stuff - {"nonexistent", []string{}}, - {"nonexistent:tag", []string{}}, - // image - {"busybox", []string{firstID, secondID, thirdID, fourthID, fifthID}}, - {imageName1, []string{thirdID, fifthID}}, - {imageName2, []string{fifthID}}, - // image:tag - {fmt.Sprintf("%s:latest", imageName1), []string{thirdID, fifthID}}, - {imageName1Tagged, []string{fourthID}}, - // short-id - {stringid.TruncateID(imageID1), []string{thirdID, fifthID}}, - {stringid.TruncateID(imageID2), []string{fifthID}}, - // full-id - {imageID1, []string{thirdID, fifthID}}, - {imageID1Tagged, []string{fourthID}}, - {imageID2, []string{fifthID}}, - } - - var out string - for _, filter := range filterTestSuite { - out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+filter.filterName) - checkPsAncestorFilterOutput(c, out, filter.filterName, filter.expectedIDs) - } - - // Multiple ancestor filter - out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+imageName2, "--filter=ancestor="+imageName1Tagged) - checkPsAncestorFilterOutput(c, out, imageName2+","+imageName1Tagged, []string{fourthID, fifthID}) -} - -func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expectedIDs []string) { - actualIDs := []string{} - if out != "" { - actualIDs = strings.Split(out[:len(out)-1], "\n") - } - sort.Strings(actualIDs) - sort.Strings(expectedIDs) - - c.Assert(actualIDs, checker.HasLen, len(expectedIDs), check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs)) - if len(expectedIDs) > 0 { - same := true - for i := range expectedIDs { - if actualIDs[i] != expectedIDs[i] { - c.Logf("%s, %s", actualIDs[i], expectedIDs[i]) - same = false - break - } - } - c.Assert(same, checker.Equals, true, check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs)) - } -} - -func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) { - // start container - dockerCmd(c, "run", "--name=first", "-l", "match=me", "-l", "second=tag", "busybox") - firstID, err := getIDByName("first") - c.Assert(err, check.IsNil) - - // start another container - dockerCmd(c, "run", "--name=second", "-l", "match=me too", "busybox") - secondID, err := getIDByName("second") - c.Assert(err, check.IsNil) - - // start third container - dockerCmd(c, "run", "--name=third", "-l", "nomatch=me", "busybox") - thirdID, err := getIDByName("third") - c.Assert(err, check.IsNil) - - // filter containers by exact match - out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me") - containerOut := strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)) - - // filter containers by two labels - out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag") - containerOut = strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)) - - // filter containers by two labels, but expect not found because of AND behavior - out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag-no") - containerOut = strings.TrimSpace(out) - c.Assert(containerOut, checker.Equals, "", check.Commentf("Expected nothing, got %s for exited filter, output: %q", containerOut, out)) - - // filter containers by exact key - out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match") - containerOut = strings.TrimSpace(out) - c.Assert(containerOut, checker.Contains, firstID) - c.Assert(containerOut, checker.Contains, secondID) - c.Assert(containerOut, checker.Not(checker.Contains), thirdID) -} - -func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) { - runSleepingContainer(c, "--name=sleep") - - dockerCmd(c, "run", "--name", "zero1", "busybox", "true") - firstZero, err := getIDByName("zero1") - c.Assert(err, checker.IsNil) - - dockerCmd(c, "run", "--name", "zero2", "busybox", "true") - secondZero, err := getIDByName("zero2") - c.Assert(err, checker.IsNil) - - out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false") - c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err)) - - firstNonZero, err := getIDByName("nonzero1") - c.Assert(err, checker.IsNil) - - out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false") - c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err)) - secondNonZero, err := getIDByName("nonzero2") - c.Assert(err, checker.IsNil) - - // filter containers by exited=0 - out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0") - ids := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(ids, checker.HasLen, 2, check.Commentf("Should be 2 zero exited containers got %d: %s", len(ids), out)) - c.Assert(ids[0], checker.Equals, secondZero, check.Commentf("First in list should be %q, got %q", secondZero, ids[0])) - c.Assert(ids[1], checker.Equals, firstZero, check.Commentf("Second in list should be %q, got %q", firstZero, ids[1])) - - out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1") - ids = strings.Split(strings.TrimSpace(out), "\n") - c.Assert(ids, checker.HasLen, 2, check.Commentf("Should be 2 zero exited containers got %d", len(ids))) - c.Assert(ids[0], checker.Equals, secondNonZero, check.Commentf("First in list should be %q, got %q", secondNonZero, ids[0])) - c.Assert(ids[1], checker.Equals, firstNonZero, check.Commentf("Second in list should be %q, got %q", firstNonZero, ids[1])) - -} - -func (s *DockerSuite) TestPsRightTagName(c *check.C) { - // TODO Investigate further why this fails on Windows to Windows CI - testRequires(c, DaemonIsLinux) - tag := "asybox:shmatest" - dockerCmd(c, "tag", "busybox", tag) - - var id1 string - out, _ := runSleepingContainer(c) - id1 = strings.TrimSpace(string(out)) - - var id2 string - out, _ = runSleepingContainerInImage(c, tag) - id2 = strings.TrimSpace(string(out)) - - var imageID string - out = inspectField(c, "busybox", "Id") - imageID = strings.TrimSpace(string(out)) - - var id3 string - out, _ = runSleepingContainerInImage(c, imageID) - id3 = strings.TrimSpace(string(out)) - - out, _ = dockerCmd(c, "ps", "--no-trunc") - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - // skip header - lines = lines[1:] - c.Assert(lines, checker.HasLen, 3, check.Commentf("There should be 3 running container, got %d", len(lines))) - for _, line := range lines { - f := strings.Fields(line) - switch f[0] { - case id1: - c.Assert(f[1], checker.Equals, "busybox", check.Commentf("Expected %s tag for id %s, got %s", "busybox", id1, f[1])) - case id2: - c.Assert(f[1], checker.Equals, tag, check.Commentf("Expected %s tag for id %s, got %s", tag, id2, f[1])) - case id3: - c.Assert(f[1], checker.Equals, imageID, check.Commentf("Expected %s imageID for id %s, got %s", tag, id3, f[1])) - default: - c.Fatalf("Unexpected id %s, expected %s and %s and %s", f[0], id1, id2, id3) - } - } -} - -func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) { - // Problematic on Windows as it doesn't support links as of Jan 2016 - testRequires(c, DaemonIsLinux) - runSleepingContainer(c, "--name=first") - runSleepingContainer(c, "--name=second", "--link=first:first") - - out, _ := dockerCmd(c, "ps", "--no-trunc") - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - // strip header - lines = lines[1:] - expected := []string{"second", "first,second/first"} - var names []string - for _, l := range lines { - fields := strings.Fields(l) - names = append(names, fields[len(fields)-1]) - } - c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array: %v, got: %v", expected, names)) -} - -func (s *DockerSuite) TestPsGroupPortRange(c *check.C) { - // Problematic on Windows as it doesn't support port ranges as of Jan 2016 - testRequires(c, DaemonIsLinux) - portRange := "3850-3900" - dockerCmd(c, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top") - - out, _ := dockerCmd(c, "ps") - - c.Assert(string(out), checker.Contains, portRange, check.Commentf("docker ps output should have had the port range %q: %s", portRange, string(out))) - -} - -func (s *DockerSuite) TestPsWithSize(c *check.C) { - // Problematic on Windows as it doesn't report the size correctly @swernli - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name", "sizetest", "busybox", "top") - - out, _ := dockerCmd(c, "ps", "--size") - c.Assert(out, checker.Contains, "virtual", check.Commentf("docker ps with --size should show virtual size of container")) -} - -func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) { - // create a container - out, _ := dockerCmd(c, "create", "busybox") - cID := strings.TrimSpace(out) - shortCID := cID[:12] - - // Make sure it DOESN'T show up w/o a '-a' for normal 'ps' - out, _ = dockerCmd(c, "ps", "-q") - c.Assert(out, checker.Not(checker.Contains), shortCID, check.Commentf("Should have not seen '%s' in ps output:\n%s", shortCID, out)) - - // Make sure it DOES show up as 'Created' for 'ps -a' - out, _ = dockerCmd(c, "ps", "-a") - - hits := 0 - for _, line := range strings.Split(out, "\n") { - if !strings.Contains(line, shortCID) { - continue - } - hits++ - c.Assert(line, checker.Contains, "Created", check.Commentf("Missing 'Created' on '%s'", line)) - } - - c.Assert(hits, checker.Equals, 1, check.Commentf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out)) - - // filter containers by 'create' - note, no -a needed - out, _ = dockerCmd(c, "ps", "-q", "-f", "status=created") - containerOut := strings.TrimSpace(out) - c.Assert(cID, checker.HasPrefix, containerOut) -} - -func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) { - // Problematic on Windows as it doesn't support link as of Jan 2016 - testRequires(c, DaemonIsLinux) - //create 2 containers and link them - dockerCmd(c, "run", "--name=child", "-d", "busybox", "top") - dockerCmd(c, "run", "--name=parent", "--link=child:linkedone", "-d", "busybox", "top") - - //use the new format capabilities to only list the names and --no-trunc to get all names - out, _ := dockerCmd(c, "ps", "--format", "{{.Names}}", "--no-trunc") - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - expected := []string{"parent", "child,parent/linkedone"} - var names []string - names = append(names, lines...) - c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with non-truncated names: %v, got: %v", expected, names)) - - //now list without turning off truncation and make sure we only get the non-link names - out, _ = dockerCmd(c, "ps", "--format", "{{.Names}}") - lines = strings.Split(strings.TrimSpace(string(out)), "\n") - expected = []string{"parent", "child"} - var truncNames []string - truncNames = append(truncNames, lines...) - c.Assert(expected, checker.DeepEquals, truncNames, check.Commentf("Expected array with truncated names: %v, got: %v", expected, truncNames)) -} - -// Test for GitHub issue #21772 -func (s *DockerSuite) TestPsNamesMultipleTime(c *check.C) { - runSleepingContainer(c, "--name=test1") - runSleepingContainer(c, "--name=test2") - - //use the new format capabilities to list the names twice - out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Names}}") - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - expected := []string{"test2 test2", "test1 test1"} - var names []string - names = append(names, lines...) - c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with names displayed twice: %v, got: %v", expected, names)) -} - -func (s *DockerSuite) TestPsFormatHeaders(c *check.C) { - // make sure no-container "docker ps" still prints the header row - out, _ := dockerCmd(c, "ps", "--format", "table {{.ID}}") - c.Assert(out, checker.Equals, "CONTAINER ID\n", check.Commentf(`Expected 'CONTAINER ID\n', got %v`, out)) - - // verify that "docker ps" with a container still prints the header row also - runSleepingContainer(c, "--name=test") - out, _ = dockerCmd(c, "ps", "--format", "table {{.Names}}") - c.Assert(out, checker.Equals, "NAMES\ntest\n", check.Commentf(`Expected 'NAMES\ntest\n', got %v`, out)) -} - -func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) { - config := `{ - "psFormat": "default {{ .ID }}" -}` - d, err := ioutil.TempDir("", "integration-cli-") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(d) - - err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644) - c.Assert(err, checker.IsNil) - - out, _ := runSleepingContainer(c, "--name=test") - id := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "--config", d, "ps", "-q") - c.Assert(id, checker.HasPrefix, strings.TrimSpace(out), check.Commentf("Expected to print only the container id, got %v\n", out)) -} - -// Test for GitHub issue #12595 -func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) { - // TODO: Investigate why this fails on Windows to Windows CI further. - testRequires(c, DaemonIsLinux) - originalImageName := "busybox:TestPsImageIDAfterUpdate-original" - updatedImageName := "busybox:TestPsImageIDAfterUpdate-updated" - - runCmd := exec.Command(dockerBinary, "tag", "busybox:latest", originalImageName) - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, checker.IsNil) - - originalImageID, err := getIDByName(originalImageName) - c.Assert(err, checker.IsNil) - - runCmd = exec.Command(dockerBinary, append([]string{"run", "-d", originalImageName}, sleepCommandForDaemonPlatform()...)...) - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, checker.IsNil) - containerID := strings.TrimSpace(out) - - linesOut, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput() - c.Assert(err, checker.IsNil) - - lines := strings.Split(strings.TrimSpace(string(linesOut)), "\n") - // skip header - lines = lines[1:] - c.Assert(len(lines), checker.Equals, 1) - - for _, line := range lines { - f := strings.Fields(line) - c.Assert(f[1], checker.Equals, originalImageName) - } - - runCmd = exec.Command(dockerBinary, "commit", containerID, updatedImageName) - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, checker.IsNil) - - runCmd = exec.Command(dockerBinary, "tag", updatedImageName, originalImageName) - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, checker.IsNil) - - linesOut, err = exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput() - c.Assert(err, checker.IsNil) - - lines = strings.Split(strings.TrimSpace(string(linesOut)), "\n") - // skip header - lines = lines[1:] - c.Assert(len(lines), checker.Equals, 1) - - for _, line := range lines { - f := strings.Fields(line) - c.Assert(f[1], checker.Equals, originalImageID) - } - -} - -func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "--name=foo", "-d", "-p", "5000:5000", "busybox", "top") - c.Assert(waitRun("foo"), checker.IsNil) - out, _ := dockerCmd(c, "ps") - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - expected := "0.0.0.0:5000->5000/tcp" - fields := strings.Fields(lines[1]) - c.Assert(fields[len(fields)-2], checker.Equals, expected, check.Commentf("Expected: %v, got: %v", expected, fields[len(fields)-2])) - - dockerCmd(c, "kill", "foo") - dockerCmd(c, "wait", "foo") - out, _ = dockerCmd(c, "ps", "-l") - lines = strings.Split(strings.TrimSpace(string(out)), "\n") - fields = strings.Fields(lines[1]) - c.Assert(fields[len(fields)-2], checker.Not(checker.Equals), expected, check.Commentf("Should not got %v", expected)) -} - -func (s *DockerSuite) TestPsShowMounts(c *check.C) { - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - - mp := prefix + slash + "test" - - dockerCmd(c, "volume", "create", "ps-volume-test") - // volume mount containers - runSleepingContainer(c, "--name=volume-test-1", "--volume", "ps-volume-test:"+mp) - c.Assert(waitRun("volume-test-1"), checker.IsNil) - runSleepingContainer(c, "--name=volume-test-2", "--volume", mp) - c.Assert(waitRun("volume-test-2"), checker.IsNil) - // bind mount container - var bindMountSource string - var bindMountDestination string - if DaemonIsWindows.Condition() { - bindMountSource = "c:\\" - bindMountDestination = "c:\\t" - } else { - bindMountSource = "/tmp" - bindMountDestination = "/t" - } - runSleepingContainer(c, "--name=bind-mount-test", "-v", bindMountSource+":"+bindMountDestination) - c.Assert(waitRun("bind-mount-test"), checker.IsNil) - - out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}") - - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - c.Assert(lines, checker.HasLen, 3) - - fields := strings.Fields(lines[0]) - c.Assert(fields, checker.HasLen, 2) - c.Assert(fields[0], checker.Equals, "bind-mount-test") - c.Assert(fields[1], checker.Equals, bindMountSource) - - fields = strings.Fields(lines[1]) - c.Assert(fields, checker.HasLen, 2) - - annonymounsVolumeID := fields[1] - - fields = strings.Fields(lines[2]) - c.Assert(fields[1], checker.Equals, "ps-volume-test") - - // filter by volume name - out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume=ps-volume-test") - - lines = strings.Split(strings.TrimSpace(string(out)), "\n") - c.Assert(lines, checker.HasLen, 1) - - fields = strings.Fields(lines[0]) - c.Assert(fields[1], checker.Equals, "ps-volume-test") - - // empty results filtering by unknown volume - out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume=this-volume-should-not-exist") - c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0) - - // filter by mount destination - out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+mp) - - lines = strings.Split(strings.TrimSpace(string(out)), "\n") - c.Assert(lines, checker.HasLen, 2) - - fields = strings.Fields(lines[0]) - c.Assert(fields[1], checker.Equals, annonymounsVolumeID) - fields = strings.Fields(lines[1]) - c.Assert(fields[1], checker.Equals, "ps-volume-test") - - // filter by bind mount source - out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountSource) - - lines = strings.Split(strings.TrimSpace(string(out)), "\n") - c.Assert(lines, checker.HasLen, 1) - - fields = strings.Fields(lines[0]) - c.Assert(fields, checker.HasLen, 2) - c.Assert(fields[0], checker.Equals, "bind-mount-test") - c.Assert(fields[1], checker.Equals, bindMountSource) - - // filter by bind mount destination - out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountDestination) - - lines = strings.Split(strings.TrimSpace(string(out)), "\n") - c.Assert(lines, checker.HasLen, 1) - - fields = strings.Fields(lines[0]) - c.Assert(fields, checker.HasLen, 2) - c.Assert(fields[0], checker.Equals, "bind-mount-test") - c.Assert(fields[1], checker.Equals, bindMountSource) - - // empty results filtering by unknown mount point - out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+prefix+slash+"this-path-was-never-mounted") - c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0) -} - -func (s *DockerSuite) TestPsFormatSize(c *check.C) { - testRequires(c, DaemonIsLinux) - runSleepingContainer(c) - - out, _ := dockerCmd(c, "ps", "--format", "table {{.Size}}") - lines := strings.Split(out, "\n") - c.Assert(lines[1], checker.Not(checker.Equals), "0 B", check.Commentf("Should not display a size of 0 B")) - - out, _ = dockerCmd(c, "ps", "--size", "--format", "table {{.Size}}") - lines = strings.Split(out, "\n") - c.Assert(lines[0], checker.Equals, "SIZE", check.Commentf("Should only have one size column")) - - out, _ = dockerCmd(c, "ps", "--size", "--format", "raw") - lines = strings.Split(out, "\n") - c.Assert(lines[8], checker.HasPrefix, "size:", check.Commentf("Size should be appended on a newline")) -} - -func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) { - // TODO default network on Windows is not called "bridge", and creating a - // custom network fails on Windows fails with "Error response from daemon: plugin not found") - testRequires(c, DaemonIsLinux) - - // create some containers - runSleepingContainer(c, "--net=bridge", "--name=onbridgenetwork") - runSleepingContainer(c, "--net=none", "--name=onnonenetwork") - - // Filter docker ps on non existing network - out, _ := dockerCmd(c, "ps", "--filter", "network=doesnotexist") - containerOut := strings.TrimSpace(string(out)) - lines := strings.Split(containerOut, "\n") - - // skip header - lines = lines[1:] - - // ps output should have no containers - c.Assert(lines, checker.HasLen, 0) - - // Filter docker ps on network bridge - out, _ = dockerCmd(c, "ps", "--filter", "network=bridge") - containerOut = strings.TrimSpace(string(out)) - - lines = strings.Split(containerOut, "\n") - - // skip header - lines = lines[1:] - - // ps output should have only one container - c.Assert(lines, checker.HasLen, 1) - - // Making sure onbridgenetwork is on the output - c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n")) - - // Filter docker ps on networks bridge and none - out, _ = dockerCmd(c, "ps", "--filter", "network=bridge", "--filter", "network=none") - containerOut = strings.TrimSpace(string(out)) - - lines = strings.Split(containerOut, "\n") - - // skip header - lines = lines[1:] - - //ps output should have both the containers - c.Assert(lines, checker.HasLen, 2) - - // Making sure onbridgenetwork and onnonenetwork is on the output - c.Assert(containerOut, checker.Contains, "onnonenetwork", check.Commentf("Missing the container on none network\n")) - c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on bridge network\n")) - - nwID, _ := dockerCmd(c, "network", "inspect", "--format", "{{.ID}}", "bridge") - - // Filter by network ID - out, _ = dockerCmd(c, "ps", "--filter", "network="+nwID) - containerOut = strings.TrimSpace(string(out)) - - c.Assert(containerOut, checker.Contains, "onbridgenetwork") -} - -func (s *DockerSuite) TestPsByOrder(c *check.C) { - name1 := "xyz-abc" - out, err := runSleepingContainer(c, "--name", name1) - c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - container1 := strings.TrimSpace(out) - - name2 := "xyz-123" - out, err = runSleepingContainer(c, "--name", name2) - c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - container2 := strings.TrimSpace(out) - - name3 := "789-abc" - out, err = runSleepingContainer(c, "--name", name3) - c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - name4 := "789-123" - out, err = runSleepingContainer(c, "--name", name4) - c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - // Run multiple time should have the same result - out, err = dockerCmd(c, "ps", "--no-trunc", "-q", "-f", "name=xyz") - c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Equals, fmt.Sprintf("%s\n%s", container2, container1)) - - // Run multiple time should have the same result - out, err = dockerCmd(c, "ps", "--no-trunc", "-q", "-f", "name=xyz") - c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Equals, fmt.Sprintf("%s\n%s", container2, container1)) -} - -func (s *DockerSuite) TestPsFilterMissingArgErrorCode(c *check.C) { - _, errCode, _ := dockerCmdWithError("ps", "--filter") - c.Assert(errCode, checker.Equals, 125) -} - -// Test case for 30291 -func (s *DockerSuite) TestPsFormatTemplateWithArg(c *check.C) { - runSleepingContainer(c, "-d", "--name", "top", "--label", "some.label=label.foo-bar") - out, _ := dockerCmd(c, "ps", "--format", `{{.Names}} {{.Label "some.label"}}`) - c.Assert(strings.TrimSpace(out), checker.Equals, "top label.foo-bar") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_pull_local_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_pull_local_test.go deleted file mode 100644 index cb14c2c..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_pull_local_test.go +++ /dev/null @@ -1,492 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "runtime" - "strings" - - "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/distribution/manifest" - "github.com/docker/distribution/manifest/manifestlist" - "github.com/docker/distribution/manifest/schema2" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// testPullImageWithAliases pulls a specific image tag and verifies that any aliases (i.e., other -// tags for the same image) are not also pulled down. -// -// Ref: docker/docker#8141 -func testPullImageWithAliases(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - - repos := []string{} - for _, tag := range []string{"recent", "fresh"} { - repos = append(repos, fmt.Sprintf("%v:%v", repoName, tag)) - } - - // Tag and push the same image multiple times. - for _, repo := range repos { - dockerCmd(c, "tag", "busybox", repo) - dockerCmd(c, "push", repo) - } - - // Clear local images store. - args := append([]string{"rmi"}, repos...) - dockerCmd(c, args...) - - // Pull a single tag and verify it doesn't bring down all aliases. - dockerCmd(c, "pull", repos[0]) - dockerCmd(c, "inspect", repos[0]) - for _, repo := range repos[1:] { - _, _, err := dockerCmdWithError("inspect", repo) - c.Assert(err, checker.NotNil, check.Commentf("Image %v shouldn't have been pulled down", repo)) - } -} - -func (s *DockerRegistrySuite) TestPullImageWithAliases(c *check.C) { - testPullImageWithAliases(c) -} - -func (s *DockerSchema1RegistrySuite) TestPullImageWithAliases(c *check.C) { - testPullImageWithAliases(c) -} - -// testConcurrentPullWholeRepo pulls the same repo concurrently. -func testConcurrentPullWholeRepo(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - - repos := []string{} - for _, tag := range []string{"recent", "fresh", "todays"} { - repo := fmt.Sprintf("%v:%v", repoName, tag) - _, err := buildImage(repo, fmt.Sprintf(` - FROM busybox - ENTRYPOINT ["/bin/echo"] - ENV FOO foo - ENV BAR bar - CMD echo %s - `, repo), true) - c.Assert(err, checker.IsNil) - dockerCmd(c, "push", repo) - repos = append(repos, repo) - } - - // Clear local images store. - args := append([]string{"rmi"}, repos...) - dockerCmd(c, args...) - - // Run multiple re-pulls concurrently - results := make(chan error) - numPulls := 3 - - for i := 0; i != numPulls; i++ { - go func() { - _, _, err := runCommandWithOutput(exec.Command(dockerBinary, "pull", "-a", repoName)) - results <- err - }() - } - - // These checks are separate from the loop above because the check - // package is not goroutine-safe. - for i := 0; i != numPulls; i++ { - err := <-results - c.Assert(err, checker.IsNil, check.Commentf("concurrent pull failed with error: %v", err)) - } - - // Ensure all tags were pulled successfully - for _, repo := range repos { - dockerCmd(c, "inspect", repo) - out, _ := dockerCmd(c, "run", "--rm", repo) - c.Assert(strings.TrimSpace(out), checker.Equals, "/bin/sh -c echo "+repo) - } -} - -func (s *DockerRegistrySuite) testConcurrentPullWholeRepo(c *check.C) { - testConcurrentPullWholeRepo(c) -} - -func (s *DockerSchema1RegistrySuite) testConcurrentPullWholeRepo(c *check.C) { - testConcurrentPullWholeRepo(c) -} - -// testConcurrentFailingPull tries a concurrent pull that doesn't succeed. -func testConcurrentFailingPull(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - - // Run multiple pulls concurrently - results := make(chan error) - numPulls := 3 - - for i := 0; i != numPulls; i++ { - go func() { - _, _, err := runCommandWithOutput(exec.Command(dockerBinary, "pull", repoName+":asdfasdf")) - results <- err - }() - } - - // These checks are separate from the loop above because the check - // package is not goroutine-safe. - for i := 0; i != numPulls; i++ { - err := <-results - c.Assert(err, checker.NotNil, check.Commentf("expected pull to fail")) - } -} - -func (s *DockerRegistrySuite) testConcurrentFailingPull(c *check.C) { - testConcurrentFailingPull(c) -} - -func (s *DockerSchema1RegistrySuite) testConcurrentFailingPull(c *check.C) { - testConcurrentFailingPull(c) -} - -// testConcurrentPullMultipleTags pulls multiple tags from the same repo -// concurrently. -func testConcurrentPullMultipleTags(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - - repos := []string{} - for _, tag := range []string{"recent", "fresh", "todays"} { - repo := fmt.Sprintf("%v:%v", repoName, tag) - _, err := buildImage(repo, fmt.Sprintf(` - FROM busybox - ENTRYPOINT ["/bin/echo"] - ENV FOO foo - ENV BAR bar - CMD echo %s - `, repo), true) - c.Assert(err, checker.IsNil) - dockerCmd(c, "push", repo) - repos = append(repos, repo) - } - - // Clear local images store. - args := append([]string{"rmi"}, repos...) - dockerCmd(c, args...) - - // Re-pull individual tags, in parallel - results := make(chan error) - - for _, repo := range repos { - go func(repo string) { - _, _, err := runCommandWithOutput(exec.Command(dockerBinary, "pull", repo)) - results <- err - }(repo) - } - - // These checks are separate from the loop above because the check - // package is not goroutine-safe. - for range repos { - err := <-results - c.Assert(err, checker.IsNil, check.Commentf("concurrent pull failed with error: %v", err)) - } - - // Ensure all tags were pulled successfully - for _, repo := range repos { - dockerCmd(c, "inspect", repo) - out, _ := dockerCmd(c, "run", "--rm", repo) - c.Assert(strings.TrimSpace(out), checker.Equals, "/bin/sh -c echo "+repo) - } -} - -func (s *DockerRegistrySuite) TestConcurrentPullMultipleTags(c *check.C) { - testConcurrentPullMultipleTags(c) -} - -func (s *DockerSchema1RegistrySuite) TestConcurrentPullMultipleTags(c *check.C) { - testConcurrentPullMultipleTags(c) -} - -// testPullIDStability verifies that pushing an image and pulling it back -// preserves the image ID. -func testPullIDStability(c *check.C) { - derivedImage := privateRegistryURL + "/dockercli/id-stability" - baseImage := "busybox" - - _, err := buildImage(derivedImage, fmt.Sprintf(` - FROM %s - ENV derived true - ENV asdf true - RUN dd if=/dev/zero of=/file bs=1024 count=1024 - CMD echo %s - `, baseImage, derivedImage), true) - if err != nil { - c.Fatal(err) - } - - originalID, err := getIDByName(derivedImage) - if err != nil { - c.Fatalf("error inspecting: %v", err) - } - dockerCmd(c, "push", derivedImage) - - // Pull - out, _ := dockerCmd(c, "pull", derivedImage) - if strings.Contains(out, "Pull complete") { - c.Fatalf("repull redownloaded a layer: %s", out) - } - - derivedIDAfterPull, err := getIDByName(derivedImage) - if err != nil { - c.Fatalf("error inspecting: %v", err) - } - - if derivedIDAfterPull != originalID { - c.Fatal("image's ID unexpectedly changed after a repush/repull") - } - - // Make sure the image runs correctly - out, _ = dockerCmd(c, "run", "--rm", derivedImage) - if strings.TrimSpace(out) != derivedImage { - c.Fatalf("expected %s; got %s", derivedImage, out) - } - - // Confirm that repushing and repulling does not change the computed ID - dockerCmd(c, "push", derivedImage) - dockerCmd(c, "rmi", derivedImage) - dockerCmd(c, "pull", derivedImage) - - derivedIDAfterPull, err = getIDByName(derivedImage) - if err != nil { - c.Fatalf("error inspecting: %v", err) - } - - if derivedIDAfterPull != originalID { - c.Fatal("image's ID unexpectedly changed after a repush/repull") - } - if err != nil { - c.Fatalf("error inspecting: %v", err) - } - - // Make sure the image still runs - out, _ = dockerCmd(c, "run", "--rm", derivedImage) - if strings.TrimSpace(out) != derivedImage { - c.Fatalf("expected %s; got %s", derivedImage, out) - } -} - -func (s *DockerRegistrySuite) TestPullIDStability(c *check.C) { - testPullIDStability(c) -} - -func (s *DockerSchema1RegistrySuite) TestPullIDStability(c *check.C) { - testPullIDStability(c) -} - -// #21213 -func testPullNoLayers(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/scratch", privateRegistryURL) - - _, err := buildImage(repoName, ` - FROM scratch - ENV foo bar`, - true) - if err != nil { - c.Fatal(err) - } - - dockerCmd(c, "push", repoName) - dockerCmd(c, "rmi", repoName) - dockerCmd(c, "pull", repoName) -} - -func (s *DockerRegistrySuite) TestPullNoLayers(c *check.C) { - testPullNoLayers(c) -} - -func (s *DockerSchema1RegistrySuite) TestPullNoLayers(c *check.C) { - testPullNoLayers(c) -} - -func (s *DockerRegistrySuite) TestPullManifestList(c *check.C) { - testRequires(c, NotArm) - pushDigest, err := setupImage(c) - c.Assert(err, checker.IsNil, check.Commentf("error setting up image")) - - // Inject a manifest list into the registry - manifestList := &manifestlist.ManifestList{ - Versioned: manifest.Versioned{ - SchemaVersion: 2, - MediaType: manifestlist.MediaTypeManifestList, - }, - Manifests: []manifestlist.ManifestDescriptor{ - { - Descriptor: distribution.Descriptor{ - Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b", - Size: 3253, - MediaType: schema2.MediaTypeManifest, - }, - Platform: manifestlist.PlatformSpec{ - Architecture: "bogus_arch", - OS: "bogus_os", - }, - }, - { - Descriptor: distribution.Descriptor{ - Digest: pushDigest, - Size: 3253, - MediaType: schema2.MediaTypeManifest, - }, - Platform: manifestlist.PlatformSpec{ - Architecture: runtime.GOARCH, - OS: runtime.GOOS, - }, - }, - }, - } - - manifestListJSON, err := json.MarshalIndent(manifestList, "", " ") - c.Assert(err, checker.IsNil, check.Commentf("error marshalling manifest list")) - - manifestListDigest := digest.FromBytes(manifestListJSON) - hexDigest := manifestListDigest.Hex() - - registryV2Path := filepath.Join(s.reg.dir, "docker", "registry", "v2") - - // Write manifest list to blob store - blobDir := filepath.Join(registryV2Path, "blobs", "sha256", hexDigest[:2], hexDigest) - err = os.MkdirAll(blobDir, 0755) - c.Assert(err, checker.IsNil, check.Commentf("error creating blob dir")) - blobPath := filepath.Join(blobDir, "data") - err = ioutil.WriteFile(blobPath, []byte(manifestListJSON), 0644) - c.Assert(err, checker.IsNil, check.Commentf("error writing manifest list")) - - // Add to revision store - revisionDir := filepath.Join(registryV2Path, "repositories", remoteRepoName, "_manifests", "revisions", "sha256", hexDigest) - err = os.Mkdir(revisionDir, 0755) - c.Assert(err, checker.IsNil, check.Commentf("error creating revision dir")) - revisionPath := filepath.Join(revisionDir, "link") - err = ioutil.WriteFile(revisionPath, []byte(manifestListDigest.String()), 0644) - c.Assert(err, checker.IsNil, check.Commentf("error writing revision link")) - - // Update tag - tagPath := filepath.Join(registryV2Path, "repositories", remoteRepoName, "_manifests", "tags", "latest", "current", "link") - err = ioutil.WriteFile(tagPath, []byte(manifestListDigest.String()), 0644) - c.Assert(err, checker.IsNil, check.Commentf("error writing tag link")) - - // Verify that the image can be pulled through the manifest list. - out, _ := dockerCmd(c, "pull", repoName) - - // The pull output includes "Digest: ", so find that - matches := digestRegex.FindStringSubmatch(out) - c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out)) - pullDigest := matches[1] - - // Make sure the pushed and pull digests match - c.Assert(manifestListDigest.String(), checker.Equals, pullDigest) - - // Was the image actually created? - dockerCmd(c, "inspect", repoName) - - dockerCmd(c, "rmi", repoName) -} - -// #23100 -func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithScheme(c *check.C) { - osPath := os.Getenv("PATH") - defer os.Setenv("PATH", osPath) - - workingDir, err := os.Getwd() - c.Assert(err, checker.IsNil) - absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth")) - c.Assert(err, checker.IsNil) - testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute) - - os.Setenv("PATH", testPath) - - repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL) - - tmp, err := ioutil.TempDir("", "integration-cli-") - c.Assert(err, checker.IsNil) - - externalAuthConfig := `{ "credsStore": "shell-test" }` - - configPath := filepath.Join(tmp, "config.json") - err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "--config", tmp, "login", "-u", s.reg.username, "-p", s.reg.password, privateRegistryURL) - - b, err := ioutil.ReadFile(configPath) - c.Assert(err, checker.IsNil) - c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":") - - dockerCmd(c, "--config", tmp, "tag", "busybox", repoName) - dockerCmd(c, "--config", tmp, "push", repoName) - - dockerCmd(c, "--config", tmp, "logout", privateRegistryURL) - dockerCmd(c, "--config", tmp, "login", "-u", s.reg.username, "-p", s.reg.password, "https://"+privateRegistryURL) - dockerCmd(c, "--config", tmp, "pull", repoName) - - // likewise push should work - repoName2 := fmt.Sprintf("%v/dockercli/busybox:nocreds", privateRegistryURL) - dockerCmd(c, "tag", repoName, repoName2) - dockerCmd(c, "--config", tmp, "push", repoName2) - - // logout should work w scheme also because it will be stripped - dockerCmd(c, "--config", tmp, "logout", "https://"+privateRegistryURL) -} - -func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *check.C) { - osPath := os.Getenv("PATH") - defer os.Setenv("PATH", osPath) - - workingDir, err := os.Getwd() - c.Assert(err, checker.IsNil) - absolute, err := filepath.Abs(filepath.Join(workingDir, "fixtures", "auth")) - c.Assert(err, checker.IsNil) - testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute) - - os.Setenv("PATH", testPath) - - repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL) - - tmp, err := ioutil.TempDir("", "integration-cli-") - c.Assert(err, checker.IsNil) - - externalAuthConfig := `{ "credsStore": "shell-test" }` - - configPath := filepath.Join(tmp, "config.json") - err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "--config", tmp, "login", "-u", s.reg.username, "-p", s.reg.password, privateRegistryURL) - - b, err := ioutil.ReadFile(configPath) - c.Assert(err, checker.IsNil) - c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":") - - dockerCmd(c, "--config", tmp, "tag", "busybox", repoName) - dockerCmd(c, "--config", tmp, "push", repoName) - - dockerCmd(c, "--config", tmp, "pull", repoName) -} - -// TestRunImplicitPullWithNoTag should pull implicitly only the default tag (latest) -func (s *DockerRegistrySuite) TestRunImplicitPullWithNoTag(c *check.C) { - testRequires(c, DaemonIsLinux) - repo := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - repoTag1 := fmt.Sprintf("%v:latest", repo) - repoTag2 := fmt.Sprintf("%v:t1", repo) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoTag1) - dockerCmd(c, "tag", "busybox", repoTag2) - dockerCmd(c, "push", repo) - dockerCmd(c, "rmi", repoTag1) - dockerCmd(c, "rmi", repoTag2) - - out, _, err := dockerCmdWithError("run", repo) - c.Assert(err, check.IsNil) - c.Assert(out, checker.Contains, fmt.Sprintf("Unable to find image '%s:latest' locally", repo)) - - // There should be only one line for repo, the one with repo:latest - outImageCmd, _, err := dockerCmdWithError("images", repo) - splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n") - c.Assert(splitOutImageCmd, checker.HasLen, 2) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_pull_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_pull_test.go deleted file mode 100644 index a0118a8..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_pull_test.go +++ /dev/null @@ -1,274 +0,0 @@ -package main - -import ( - "fmt" - "regexp" - "strings" - "sync" - "time" - - "github.com/docker/distribution/digest" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// TestPullFromCentralRegistry pulls an image from the central registry and verifies that the client -// prints all expected output. -func (s *DockerHubPullSuite) TestPullFromCentralRegistry(c *check.C) { - testRequires(c, DaemonIsLinux) - out := s.Cmd(c, "pull", "hello-world") - defer deleteImages("hello-world") - - c.Assert(out, checker.Contains, "Using default tag: latest", check.Commentf("expected the 'latest' tag to be automatically assumed")) - c.Assert(out, checker.Contains, "Pulling from library/hello-world", check.Commentf("expected the 'library/' prefix to be automatically assumed")) - c.Assert(out, checker.Contains, "Downloaded newer image for hello-world:latest") - - matches := regexp.MustCompile(`Digest: (.+)\n`).FindAllStringSubmatch(out, -1) - c.Assert(len(matches), checker.Equals, 1, check.Commentf("expected exactly one image digest in the output")) - c.Assert(len(matches[0]), checker.Equals, 2, check.Commentf("unexpected number of submatches for the digest")) - _, err := digest.ParseDigest(matches[0][1]) - c.Check(err, checker.IsNil, check.Commentf("invalid digest %q in output", matches[0][1])) - - // We should have a single entry in images. - img := strings.TrimSpace(s.Cmd(c, "images")) - splitImg := strings.Split(img, "\n") - c.Assert(splitImg, checker.HasLen, 2) - c.Assert(splitImg[1], checker.Matches, `hello-world\s+latest.*?`, check.Commentf("invalid output for `docker images` (expected image and tag name")) -} - -// TestPullNonExistingImage pulls non-existing images from the central registry, with different -// combinations of implicit tag and library prefix. -func (s *DockerHubPullSuite) TestPullNonExistingImage(c *check.C) { - testRequires(c, DaemonIsLinux) - - type entry struct { - repo string - alias string - tag string - } - - entries := []entry{ - {"asdfasdf", "asdfasdf", "foobar"}, - {"asdfasdf", "library/asdfasdf", "foobar"}, - {"asdfasdf", "asdfasdf", ""}, - {"asdfasdf", "asdfasdf", "latest"}, - {"asdfasdf", "library/asdfasdf", ""}, - {"asdfasdf", "library/asdfasdf", "latest"}, - } - - // The option field indicates "-a" or not. - type record struct { - e entry - option string - out string - err error - } - - // Execute 'docker pull' in parallel, pass results (out, err) and - // necessary information ("-a" or not, and the image name) to channel. - var group sync.WaitGroup - recordChan := make(chan record, len(entries)*2) - for _, e := range entries { - group.Add(1) - go func(e entry) { - defer group.Done() - repoName := e.alias - if e.tag != "" { - repoName += ":" + e.tag - } - out, err := s.CmdWithError("pull", repoName) - recordChan <- record{e, "", out, err} - }(e) - if e.tag == "" { - // pull -a on a nonexistent registry should fall back as well - group.Add(1) - go func(e entry) { - defer group.Done() - out, err := s.CmdWithError("pull", "-a", e.alias) - recordChan <- record{e, "-a", out, err} - }(e) - } - } - - // Wait for completion - group.Wait() - close(recordChan) - - // Process the results (out, err). - for record := range recordChan { - if len(record.option) == 0 { - c.Assert(record.err, checker.NotNil, check.Commentf("expected non-zero exit status when pulling non-existing image: %s", record.out)) - c.Assert(record.out, checker.Contains, fmt.Sprintf("repository %s not found: does not exist or no pull access", record.e.repo), check.Commentf("expected image not found error messages")) - } else { - // pull -a on a nonexistent registry should fall back as well - c.Assert(record.err, checker.NotNil, check.Commentf("expected non-zero exit status when pulling non-existing image: %s", record.out)) - c.Assert(record.out, checker.Contains, fmt.Sprintf("repository %s not found", record.e.repo), check.Commentf("expected image not found error messages")) - c.Assert(record.out, checker.Not(checker.Contains), "unauthorized", check.Commentf(`message should not contain "unauthorized"`)) - } - } - -} - -// TestPullFromCentralRegistryImplicitRefParts pulls an image from the central registry and verifies -// that pulling the same image with different combinations of implicit elements of the the image -// reference (tag, repository, central registry url, ...) doesn't trigger a new pull nor leads to -// multiple images. -func (s *DockerHubPullSuite) TestPullFromCentralRegistryImplicitRefParts(c *check.C) { - testRequires(c, DaemonIsLinux) - - // Pull hello-world from v2 - pullFromV2 := func(ref string) (int, string) { - out := s.Cmd(c, "pull", "hello-world") - v1Retries := 0 - for strings.Contains(out, "this image was pulled from a legacy registry") { - // Some network errors may cause fallbacks to the v1 - // protocol, which would violate the test's assumption - // that it will get the same images. To make the test - // more robust against these network glitches, allow a - // few retries if we end up with a v1 pull. - - if v1Retries > 2 { - c.Fatalf("too many v1 fallback incidents when pulling %s", ref) - } - - s.Cmd(c, "rmi", ref) - out = s.Cmd(c, "pull", ref) - - v1Retries++ - } - - return v1Retries, out - } - - pullFromV2("hello-world") - defer deleteImages("hello-world") - - s.Cmd(c, "tag", "hello-world", "hello-world-backup") - - for _, ref := range []string{ - "hello-world", - "hello-world:latest", - "library/hello-world", - "library/hello-world:latest", - "docker.io/library/hello-world", - "index.docker.io/library/hello-world", - } { - var out string - for { - var v1Retries int - v1Retries, out = pullFromV2(ref) - - // Keep repeating the test case until we don't hit a v1 - // fallback case. We won't get the right "Image is up - // to date" message if the local image was replaced - // with one pulled from v1. - if v1Retries == 0 { - break - } - s.Cmd(c, "rmi", ref) - s.Cmd(c, "tag", "hello-world-backup", "hello-world") - } - c.Assert(out, checker.Contains, "Image is up to date for hello-world:latest") - } - - s.Cmd(c, "rmi", "hello-world-backup") - - // We should have a single entry in images. - img := strings.TrimSpace(s.Cmd(c, "images")) - splitImg := strings.Split(img, "\n") - c.Assert(splitImg, checker.HasLen, 2) - c.Assert(splitImg[1], checker.Matches, `hello-world\s+latest.*?`, check.Commentf("invalid output for `docker images` (expected image and tag name")) -} - -// TestPullScratchNotAllowed verifies that pulling 'scratch' is rejected. -func (s *DockerHubPullSuite) TestPullScratchNotAllowed(c *check.C) { - testRequires(c, DaemonIsLinux) - out, err := s.CmdWithError("pull", "scratch") - c.Assert(err, checker.NotNil, check.Commentf("expected pull of scratch to fail")) - c.Assert(out, checker.Contains, "'scratch' is a reserved name") - c.Assert(out, checker.Not(checker.Contains), "Pulling repository scratch") -} - -// TestPullAllTagsFromCentralRegistry pulls using `all-tags` for a given image and verifies that it -// results in more images than a naked pull. -func (s *DockerHubPullSuite) TestPullAllTagsFromCentralRegistry(c *check.C) { - testRequires(c, DaemonIsLinux) - s.Cmd(c, "pull", "busybox") - outImageCmd := s.Cmd(c, "images", "busybox") - splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n") - c.Assert(splitOutImageCmd, checker.HasLen, 2) - - s.Cmd(c, "pull", "--all-tags=true", "busybox") - outImageAllTagCmd := s.Cmd(c, "images", "busybox") - linesCount := strings.Count(outImageAllTagCmd, "\n") - c.Assert(linesCount, checker.GreaterThan, 2, check.Commentf("pulling all tags should provide more than two images, got %s", outImageAllTagCmd)) - - // Verify that the line for 'busybox:latest' is left unchanged. - var latestLine string - for _, line := range strings.Split(outImageAllTagCmd, "\n") { - if strings.HasPrefix(line, "busybox") && strings.Contains(line, "latest") { - latestLine = line - break - } - } - c.Assert(latestLine, checker.Not(checker.Equals), "", check.Commentf("no entry for busybox:latest found after pulling all tags")) - splitLatest := strings.Fields(latestLine) - splitCurrent := strings.Fields(splitOutImageCmd[1]) - - // Clear relative creation times, since these can easily change between - // two invocations of "docker images". Without this, the test can fail - // like this: - // ... obtained []string = []string{"busybox", "latest", "d9551b4026f0", "27", "minutes", "ago", "1.113", "MB"} - // ... expected []string = []string{"busybox", "latest", "d9551b4026f0", "26", "minutes", "ago", "1.113", "MB"} - splitLatest[3] = "" - splitLatest[4] = "" - splitLatest[5] = "" - splitCurrent[3] = "" - splitCurrent[4] = "" - splitCurrent[5] = "" - - c.Assert(splitLatest, checker.DeepEquals, splitCurrent, check.Commentf("busybox:latest was changed after pulling all tags")) -} - -// TestPullClientDisconnect kills the client during a pull operation and verifies that the operation -// gets cancelled. -// -// Ref: docker/docker#15589 -func (s *DockerHubPullSuite) TestPullClientDisconnect(c *check.C) { - testRequires(c, DaemonIsLinux) - repoName := "hello-world:latest" - - pullCmd := s.MakeCmd("pull", repoName) - stdout, err := pullCmd.StdoutPipe() - c.Assert(err, checker.IsNil) - err = pullCmd.Start() - c.Assert(err, checker.IsNil) - - // Cancel as soon as we get some output. - buf := make([]byte, 10) - _, err = stdout.Read(buf) - c.Assert(err, checker.IsNil) - - err = pullCmd.Process.Kill() - c.Assert(err, checker.IsNil) - - time.Sleep(2 * time.Second) - _, err = s.CmdWithError("inspect", repoName) - c.Assert(err, checker.NotNil, check.Commentf("image was pulled after client disconnected")) -} - -func (s *DockerRegistryAuthHtpasswdSuite) TestPullNoCredentialsNotFound(c *check.C) { - // we don't care about the actual image, we just want to see image not found - // because that means v2 call returned 401 and we fell back to v1 which usually - // gives a 404 (in this case the test registry doesn't handle v1 at all) - out, _, err := dockerCmdWithError("pull", privateRegistryURL+"/busybox") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Error: image busybox:latest not found") -} - -// Regression test for https://github.com/docker/docker/issues/26429 -func (s *DockerSuite) TestPullLinuxImageFailsOnWindows(c *check.C) { - testRequires(c, DaemonIsWindows, Network) - _, _, err := dockerCmdWithError("pull", "ubuntu") - c.Assert(err.Error(), checker.Contains, "cannot be used on this platform") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_pull_trusted_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_pull_trusted_test.go deleted file mode 100644 index 96a42d6..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_pull_trusted_test.go +++ /dev/null @@ -1,365 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os/exec" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerTrustSuite) TestTrustedPull(c *check.C) { - repoName := s.setupTrustedImage(c, "trusted-pull") - - // Try pull - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err := runCommandWithOutput(pullCmd) - - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out)) - - dockerCmd(c, "rmi", repoName) - // Try untrusted pull to ensure we pushed the tag to the registry - pullCmd = exec.Command(dockerBinary, "pull", "--disable-content-trust=true", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out)) - -} - -func (s *DockerTrustSuite) TestTrustedIsolatedPull(c *check.C) { - repoName := s.setupTrustedImage(c, "trusted-isolated-pull") - - // Try pull (run from isolated directory without trust information) - pullCmd := exec.Command(dockerBinary, "--config", "/tmp/docker-isolated", "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err := runCommandWithOutput(pullCmd) - - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(string(out))) - - dockerCmd(c, "rmi", repoName) -} - -func (s *DockerTrustSuite) TestUntrustedPull(c *check.C) { - repoName := fmt.Sprintf("%v/dockercliuntrusted/pulltest:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - dockerCmd(c, "push", repoName) - dockerCmd(c, "rmi", repoName) - - // Try trusted pull on untrusted tag - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err := runCommandWithOutput(pullCmd) - - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Error: remote trust data does not exist", check.Commentf(out)) -} - -func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) { - c.Skip("Currently changes system time, causing instability") - repoName := s.setupTrustedImage(c, "trusted-cert-expired") - - // Certificates have 10 years of expiration - elevenYearsFromNow := time.Now().Add(time.Hour * 24 * 365 * 11) - - runAtDifferentDate(elevenYearsFromNow, func() { - // Try pull - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err := runCommandWithOutput(pullCmd) - - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "could not validate the path to a trusted root", check.Commentf(out)) - }) - - runAtDifferentDate(elevenYearsFromNow, func() { - // Try pull - pullCmd := exec.Command(dockerBinary, "pull", "--disable-content-trust", repoName) - s.trustedCmd(pullCmd) - out, _, err := runCommandWithOutput(pullCmd) - - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out)) - }) -} - -func (s *DockerTrustSuite) TestTrustedPullFromBadTrustServer(c *check.C) { - repoName := fmt.Sprintf("%v/dockerclievilpull/trusted:latest", privateRegistryURL) - evilLocalConfigDir, err := ioutil.TempDir("", "evil-local-config-dir") - if err != nil { - c.Fatalf("Failed to create local temp dir") - } - - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf(out)) - dockerCmd(c, "rmi", repoName) - - // Try pull - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out)) - dockerCmd(c, "rmi", repoName) - - // Kill the notary server, start a new "evil" one. - s.not.Close() - s.not, err = newTestNotary(c) - - c.Assert(err, check.IsNil, check.Commentf("Restarting notary server failed.")) - - // In order to make an evil server, lets re-init a client (with a different trust dir) and push new data. - // tag an image and upload it to the private registry - dockerCmd(c, "--config", evilLocalConfigDir, "tag", "busybox", repoName) - - // Push up to the new server - pushCmd = exec.Command(dockerBinary, "--config", evilLocalConfigDir, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err = runCommandWithOutput(pushCmd) - - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf(out)) - - // Now, try pulling with the original client from this new trust server. This should fail because the new root is invalid. - pullCmd = exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - if err == nil { - c.Fatalf("Continuing with cached data even though it's an invalid root rotation: %s\n%s", err, out) - } - if !strings.Contains(out, "could not rotate trust to a new trusted root") { - c.Fatalf("Missing expected output on trusted pull:\n%s", out) - } -} - -func (s *DockerTrustSuite) TestTrustedPullWithExpiredSnapshot(c *check.C) { - c.Skip("Currently changes system time, causing instability") - repoName := fmt.Sprintf("%v/dockercliexpiredtimestamppull/trusted:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - // Push with default passphrases - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf(out)) - - dockerCmd(c, "rmi", repoName) - - // Snapshots last for three years. This should be expired - fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4) - - runAtDifferentDate(fourYearsLater, func() { - // Try pull - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - - c.Assert(err, check.NotNil, check.Commentf("Missing expected error running trusted pull with expired snapshots")) - c.Assert(string(out), checker.Contains, "repository out-of-date", check.Commentf(out)) - }) -} - -func (s *DockerTrustSuite) TestTrustedOfflinePull(c *check.C) { - repoName := s.setupTrustedImage(c, "trusted-offline-pull") - - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmdWithServer(pullCmd, "https://invalidnotaryserver") - out, _, err := runCommandWithOutput(pullCmd) - - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "error contacting notary server", check.Commentf(out)) - // Do valid trusted pull to warm cache - pullCmd = exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out)) - - dockerCmd(c, "rmi", repoName) - - // Try pull again with invalid notary server, should use cache - pullCmd = exec.Command(dockerBinary, "pull", repoName) - s.trustedCmdWithServer(pullCmd, "https://invalidnotaryserver") - out, _, err = runCommandWithOutput(pullCmd) - - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out)) -} - -func (s *DockerTrustSuite) TestTrustedPullDelete(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/%s:latest", privateRegistryURL, "trusted-pull-delete") - // tag the image and upload it to the private registry - _, err := buildImage(repoName, ` - FROM busybox - CMD echo trustedpulldelete - `, true) - - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - if err != nil { - c.Fatalf("Error running trusted push: %s\n%s", err, out) - } - if !strings.Contains(string(out), "Signing and pushing trust metadata") { - c.Fatalf("Missing expected output on trusted push:\n%s", out) - } - - if out, status := dockerCmd(c, "rmi", repoName); status != 0 { - c.Fatalf("Error removing image %q\n%s", repoName, out) - } - - // Try pull - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - - c.Assert(err, check.IsNil, check.Commentf(out)) - - matches := digestRegex.FindStringSubmatch(out) - c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out)) - pullDigest := matches[1] - - imageID := inspectField(c, repoName, "Id") - - imageByDigest := repoName + "@" + pullDigest - byDigestID := inspectField(c, imageByDigest, "Id") - - c.Assert(byDigestID, checker.Equals, imageID) - - // rmi of tag should also remove the digest reference - dockerCmd(c, "rmi", repoName) - - _, err = inspectFieldWithError(imageByDigest, "Id") - c.Assert(err, checker.NotNil, check.Commentf("digest reference should have been removed")) - - _, err = inspectFieldWithError(imageID, "Id") - c.Assert(err, checker.NotNil, check.Commentf("image should have been deleted")) -} - -func (s *DockerTrustSuite) TestTrustedPullReadsFromReleasesRole(c *check.C) { - testRequires(c, NotaryHosting) - repoName := fmt.Sprintf("%v/dockerclireleasesdelegationpulling/trusted", privateRegistryURL) - targetName := fmt.Sprintf("%s:latest", repoName) - - // Push with targets first, initializing the repo - dockerCmd(c, "tag", "busybox", targetName) - pushCmd := exec.Command(dockerBinary, "push", targetName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - s.assertTargetInRoles(c, repoName, "latest", "targets") - - // Try pull, check we retrieve from targets role - pullCmd := exec.Command(dockerBinary, "-D", "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "retrieving target for targets role") - - // Now we'll create the releases role, and try pushing and pulling - s.notaryCreateDelegation(c, repoName, "targets/releases", s.not.keys[0].Public) - s.notaryImportKey(c, repoName, "targets/releases", s.not.keys[0].Private) - s.notaryPublish(c, repoName) - - // try a pull, check that we can still pull because we can still read the - // old tag in the targets role - pullCmd = exec.Command(dockerBinary, "-D", "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "retrieving target for targets role") - - // try a pull -a, check that it succeeds because we can still pull from the - // targets role - pullCmd = exec.Command(dockerBinary, "-D", "pull", "-a", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - - // Push, should sign with targets/releases - dockerCmd(c, "tag", "busybox", targetName) - pushCmd = exec.Command(dockerBinary, "push", targetName) - s.trustedCmd(pushCmd) - out, _, err = runCommandWithOutput(pushCmd) - s.assertTargetInRoles(c, repoName, "latest", "targets", "targets/releases") - - // Try pull, check we retrieve from targets/releases role - pullCmd = exec.Command(dockerBinary, "-D", "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(out, checker.Contains, "retrieving target for targets/releases role") - - // Create another delegation that we'll sign with - s.notaryCreateDelegation(c, repoName, "targets/other", s.not.keys[1].Public) - s.notaryImportKey(c, repoName, "targets/other", s.not.keys[1].Private) - s.notaryPublish(c, repoName) - - dockerCmd(c, "tag", "busybox", targetName) - pushCmd = exec.Command(dockerBinary, "push", targetName) - s.trustedCmd(pushCmd) - out, _, err = runCommandWithOutput(pushCmd) - s.assertTargetInRoles(c, repoName, "latest", "targets", "targets/releases", "targets/other") - - // Try pull, check we retrieve from targets/releases role - pullCmd = exec.Command(dockerBinary, "-D", "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(out, checker.Contains, "retrieving target for targets/releases role") -} - -func (s *DockerTrustSuite) TestTrustedPullIgnoresOtherDelegationRoles(c *check.C) { - testRequires(c, NotaryHosting) - repoName := fmt.Sprintf("%v/dockerclipullotherdelegation/trusted", privateRegistryURL) - targetName := fmt.Sprintf("%s:latest", repoName) - - // We'll create a repo first with a non-release delegation role, so that when we - // push we'll sign it into the delegation role - s.notaryInitRepo(c, repoName) - s.notaryCreateDelegation(c, repoName, "targets/other", s.not.keys[0].Public) - s.notaryImportKey(c, repoName, "targets/other", s.not.keys[0].Private) - s.notaryPublish(c, repoName) - - // Push should write to the delegation role, not targets - dockerCmd(c, "tag", "busybox", targetName) - pushCmd := exec.Command(dockerBinary, "push", targetName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - s.assertTargetInRoles(c, repoName, "latest", "targets/other") - s.assertTargetNotInRoles(c, repoName, "latest", "targets") - - // Try pull - we should fail, since pull will only pull from the targets/releases - // role or the targets role - pullCmd := exec.Command(dockerBinary, "-D", "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "No trust data for") - - // try a pull -a: we should fail since pull will only pull from the targets/releases - // role or the targets role - pullCmd = exec.Command(dockerBinary, "-D", "pull", "-a", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "No trusted tags for") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_push_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_push_test.go deleted file mode 100644 index f750c12..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_push_test.go +++ /dev/null @@ -1,715 +0,0 @@ -package main - -import ( - "archive/tar" - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "os/exec" - "path/filepath" - "strings" - "sync" - "time" - - "github.com/docker/distribution/reference" - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// Pushing an image to a private registry. -func testPushBusyboxImage(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - // tag the image to upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - // push the image to the registry - dockerCmd(c, "push", repoName) -} - -func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) { - testPushBusyboxImage(c) -} - -func (s *DockerSchema1RegistrySuite) TestPushBusyboxImage(c *check.C) { - testPushBusyboxImage(c) -} - -// pushing an image without a prefix should throw an error -func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) { - out, _, err := dockerCmdWithError("push", "busybox") - c.Assert(err, check.NotNil, check.Commentf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)) -} - -func testPushUntagged(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - expected := "An image does not exist locally with the tag" - - out, _, err := dockerCmdWithError("push", repoName) - c.Assert(err, check.NotNil, check.Commentf("pushing the image to the private registry should have failed: output %q", out)) - c.Assert(out, checker.Contains, expected, check.Commentf("pushing the image failed")) -} - -func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) { - testPushUntagged(c) -} - -func (s *DockerSchema1RegistrySuite) TestPushUntagged(c *check.C) { - testPushUntagged(c) -} - -func testPushBadTag(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL) - expected := "does not exist" - - out, _, err := dockerCmdWithError("push", repoName) - c.Assert(err, check.NotNil, check.Commentf("pushing the image to the private registry should have failed: output %q", out)) - c.Assert(out, checker.Contains, expected, check.Commentf("pushing the image failed")) -} - -func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) { - testPushBadTag(c) -} - -func (s *DockerSchema1RegistrySuite) TestPushBadTag(c *check.C) { - testPushBadTag(c) -} - -func testPushMultipleTags(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL) - repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoTag1) - - dockerCmd(c, "tag", "busybox", repoTag2) - - dockerCmd(c, "push", repoName) - - // Ensure layer list is equivalent for repoTag1 and repoTag2 - out1, _ := dockerCmd(c, "pull", repoTag1) - - imageAlreadyExists := ": Image already exists" - var out1Lines []string - for _, outputLine := range strings.Split(out1, "\n") { - if strings.Contains(outputLine, imageAlreadyExists) { - out1Lines = append(out1Lines, outputLine) - } - } - - out2, _ := dockerCmd(c, "pull", repoTag2) - - var out2Lines []string - for _, outputLine := range strings.Split(out2, "\n") { - if strings.Contains(outputLine, imageAlreadyExists) { - out1Lines = append(out1Lines, outputLine) - } - } - c.Assert(out2Lines, checker.HasLen, len(out1Lines)) - - for i := range out1Lines { - c.Assert(out1Lines[i], checker.Equals, out2Lines[i]) - } -} - -func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) { - testPushMultipleTags(c) -} - -func (s *DockerSchema1RegistrySuite) TestPushMultipleTags(c *check.C) { - testPushMultipleTags(c) -} - -func testPushEmptyLayer(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL) - emptyTarball, err := ioutil.TempFile("", "empty_tarball") - c.Assert(err, check.IsNil, check.Commentf("Unable to create test file")) - - tw := tar.NewWriter(emptyTarball) - err = tw.Close() - c.Assert(err, check.IsNil, check.Commentf("Error creating empty tarball")) - - freader, err := os.Open(emptyTarball.Name()) - c.Assert(err, check.IsNil, check.Commentf("Could not open test tarball")) - defer freader.Close() - - importCmd := exec.Command(dockerBinary, "import", "-", repoName) - importCmd.Stdin = freader - out, _, err := runCommandWithOutput(importCmd) - c.Assert(err, check.IsNil, check.Commentf("import failed: %q", out)) - - // Now verify we can push it - out, _, err = dockerCmdWithError("push", repoName) - c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out)) -} - -func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) { - testPushEmptyLayer(c) -} - -func (s *DockerSchema1RegistrySuite) TestPushEmptyLayer(c *check.C) { - testPushEmptyLayer(c) -} - -// testConcurrentPush pushes multiple tags to the same repo -// concurrently. -func testConcurrentPush(c *check.C) { - repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - - repos := []string{} - for _, tag := range []string{"push1", "push2", "push3"} { - repo := fmt.Sprintf("%v:%v", repoName, tag) - _, err := buildImage(repo, fmt.Sprintf(` - FROM busybox - ENTRYPOINT ["/bin/echo"] - ENV FOO foo - ENV BAR bar - CMD echo %s -`, repo), true) - c.Assert(err, checker.IsNil) - repos = append(repos, repo) - } - - // Push tags, in parallel - results := make(chan error) - - for _, repo := range repos { - go func(repo string) { - _, _, err := runCommandWithOutput(exec.Command(dockerBinary, "push", repo)) - results <- err - }(repo) - } - - for range repos { - err := <-results - c.Assert(err, checker.IsNil, check.Commentf("concurrent push failed with error: %v", err)) - } - - // Clear local images store. - args := append([]string{"rmi"}, repos...) - dockerCmd(c, args...) - - // Re-pull and run individual tags, to make sure pushes succeeded - for _, repo := range repos { - dockerCmd(c, "pull", repo) - dockerCmd(c, "inspect", repo) - out, _ := dockerCmd(c, "run", "--rm", repo) - c.Assert(strings.TrimSpace(out), checker.Equals, "/bin/sh -c echo "+repo) - } -} - -func (s *DockerRegistrySuite) TestConcurrentPush(c *check.C) { - testConcurrentPush(c) -} - -func (s *DockerSchema1RegistrySuite) TestConcurrentPush(c *check.C) { - testConcurrentPush(c) -} - -func (s *DockerRegistrySuite) TestCrossRepositoryLayerPush(c *check.C) { - sourceRepoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - // tag the image to upload it to the private registry - dockerCmd(c, "tag", "busybox", sourceRepoName) - // push the image to the registry - out1, _, err := dockerCmdWithError("push", sourceRepoName) - c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out1)) - // ensure that none of the layers were mounted from another repository during push - c.Assert(strings.Contains(out1, "Mounted from"), check.Equals, false) - - digest1 := reference.DigestRegexp.FindString(out1) - c.Assert(len(digest1), checker.GreaterThan, 0, check.Commentf("no digest found for pushed manifest")) - - destRepoName := fmt.Sprintf("%v/dockercli/crossrepopush", privateRegistryURL) - // retag the image to upload the same layers to another repo in the same registry - dockerCmd(c, "tag", "busybox", destRepoName) - // push the image to the registry - out2, _, err := dockerCmdWithError("push", destRepoName) - c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out2)) - // ensure that layers were mounted from the first repo during push - c.Assert(strings.Contains(out2, "Mounted from dockercli/busybox"), check.Equals, true) - - digest2 := reference.DigestRegexp.FindString(out2) - c.Assert(len(digest2), checker.GreaterThan, 0, check.Commentf("no digest found for pushed manifest")) - c.Assert(digest1, check.Equals, digest2) - - // ensure that pushing again produces the same digest - out3, _, err := dockerCmdWithError("push", destRepoName) - c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out2)) - - digest3 := reference.DigestRegexp.FindString(out3) - c.Assert(len(digest2), checker.GreaterThan, 0, check.Commentf("no digest found for pushed manifest")) - c.Assert(digest3, check.Equals, digest2) - - // ensure that we can pull and run the cross-repo-pushed repository - dockerCmd(c, "rmi", destRepoName) - dockerCmd(c, "pull", destRepoName) - out4, _ := dockerCmd(c, "run", destRepoName, "echo", "-n", "hello world") - c.Assert(out4, check.Equals, "hello world") -} - -func (s *DockerSchema1RegistrySuite) TestCrossRepositoryLayerPushNotSupported(c *check.C) { - sourceRepoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) - // tag the image to upload it to the private registry - dockerCmd(c, "tag", "busybox", sourceRepoName) - // push the image to the registry - out1, _, err := dockerCmdWithError("push", sourceRepoName) - c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out1)) - // ensure that none of the layers were mounted from another repository during push - c.Assert(strings.Contains(out1, "Mounted from"), check.Equals, false) - - digest1 := reference.DigestRegexp.FindString(out1) - c.Assert(len(digest1), checker.GreaterThan, 0, check.Commentf("no digest found for pushed manifest")) - - destRepoName := fmt.Sprintf("%v/dockercli/crossrepopush", privateRegistryURL) - // retag the image to upload the same layers to another repo in the same registry - dockerCmd(c, "tag", "busybox", destRepoName) - // push the image to the registry - out2, _, err := dockerCmdWithError("push", destRepoName) - c.Assert(err, check.IsNil, check.Commentf("pushing the image to the private registry has failed: %s", out2)) - // schema1 registry should not support cross-repo layer mounts, so ensure that this does not happen - c.Assert(strings.Contains(out2, "Mounted from"), check.Equals, false) - - digest2 := reference.DigestRegexp.FindString(out2) - c.Assert(len(digest2), checker.GreaterThan, 0, check.Commentf("no digest found for pushed manifest")) - c.Assert(digest1, check.Not(check.Equals), digest2) - - // ensure that we can pull and run the second pushed repository - dockerCmd(c, "rmi", destRepoName) - dockerCmd(c, "pull", destRepoName) - out3, _ := dockerCmd(c, "run", destRepoName, "echo", "-n", "hello world") - c.Assert(out3, check.Equals, "hello world") -} - -func (s *DockerTrustSuite) TestTrustedPush(c *check.C) { - repoName := fmt.Sprintf("%v/dockerclitrusted/pushtest:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push")) - - // Try pull after push - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Status: Image is up to date", check.Commentf(out)) - - // Assert that we rotated the snapshot key to the server by checking our local keystore - contents, err := ioutil.ReadDir(filepath.Join(cliconfig.ConfigDir(), "trust/private/tuf_keys", privateRegistryURL, "dockerclitrusted/pushtest")) - c.Assert(err, check.IsNil, check.Commentf("Unable to read local tuf key files")) - // Check that we only have 1 key (targets key) - c.Assert(contents, checker.HasLen, 1) -} - -func (s *DockerTrustSuite) TestTrustedPushWithEnvPasswords(c *check.C) { - repoName := fmt.Sprintf("%v/dockerclienv/trusted:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmdWithPassphrases(pushCmd, "12345678", "12345678") - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push")) - - // Try pull after push - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Status: Image is up to date", check.Commentf(out)) -} - -func (s *DockerTrustSuite) TestTrustedPushWithFailingServer(c *check.C) { - repoName := fmt.Sprintf("%v/dockerclitrusted/failingserver:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - pushCmd := exec.Command(dockerBinary, "push", repoName) - // Using a name that doesn't resolve to an address makes this test faster - s.trustedCmdWithServer(pushCmd, "https://server.invalid:81/") - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.NotNil, check.Commentf("Missing error while running trusted push w/ no server")) - c.Assert(out, checker.Contains, "error contacting notary server", check.Commentf("Missing expected output on trusted push")) -} - -func (s *DockerTrustSuite) TestTrustedPushWithoutServerAndUntrusted(c *check.C) { - repoName := fmt.Sprintf("%v/dockerclitrusted/trustedandnot:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - pushCmd := exec.Command(dockerBinary, "push", "--disable-content-trust", repoName) - // Using a name that doesn't resolve to an address makes this test faster - s.trustedCmdWithServer(pushCmd, "https://server.invalid") - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("trusted push with no server and --disable-content-trust failed: %s\n%s", err, out)) - c.Assert(out, check.Not(checker.Contains), "Error establishing connection to notary repository", check.Commentf("Missing expected output on trusted push with --disable-content-trust:")) -} - -func (s *DockerTrustSuite) TestTrustedPushWithExistingTag(c *check.C) { - repoName := fmt.Sprintf("%v/dockerclitag/trusted:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - dockerCmd(c, "push", repoName) - - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag")) - - // Try pull after push - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Status: Image is up to date", check.Commentf(out)) -} - -func (s *DockerTrustSuite) TestTrustedPushWithExistingSignedTag(c *check.C) { - repoName := fmt.Sprintf("%v/dockerclipushpush/trusted:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - // Do a trusted push - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag")) - - // Do another trusted push - pushCmd = exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err = runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag")) - - dockerCmd(c, "rmi", repoName) - - // Try pull to ensure the double push did not break our ability to pull - pullCmd := exec.Command(dockerBinary, "pull", repoName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.IsNil, check.Commentf("Error running trusted pull: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Status: Downloaded", check.Commentf("Missing expected output on trusted pull with --disable-content-trust")) - -} - -func (s *DockerTrustSuite) TestTrustedPushWithIncorrectPassphraseForNonRoot(c *check.C) { - repoName := fmt.Sprintf("%v/dockercliincorretpwd/trusted:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - // Push with default passphrases - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push:\n%s", out)) - - // Push with wrong passphrases - pushCmd = exec.Command(dockerBinary, "push", repoName) - s.trustedCmdWithPassphrases(pushCmd, "12345678", "87654321") - out, _, err = runCommandWithOutput(pushCmd) - c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with short targets passphrase: \n%s", out)) - c.Assert(out, checker.Contains, "could not find necessary signing keys", check.Commentf("Missing expected output on trusted push with short targets/snapsnot passphrase")) -} - -func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) { - c.Skip("Currently changes system time, causing instability") - repoName := fmt.Sprintf("%v/dockercliexpiredsnapshot/trusted:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - // Push with default passphrases - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push")) - - // Snapshots last for three years. This should be expired - fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4) - - runAtDifferentDate(fourYearsLater, func() { - // Push with wrong passphrases - pushCmd = exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err = runCommandWithOutput(pushCmd) - c.Assert(err, check.NotNil, check.Commentf("Error missing from trusted push with expired snapshot: \n%s", out)) - c.Assert(out, checker.Contains, "repository out-of-date", check.Commentf("Missing expected output on trusted push with expired snapshot")) - }) -} - -func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) { - c.Skip("Currently changes system time, causing instability") - repoName := fmt.Sprintf("%v/dockercliexpiredtimestamppush/trusted:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - // Push with default passphrases - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push")) - - // The timestamps expire in two weeks. Lets check three - threeWeeksLater := time.Now().Add(time.Hour * 24 * 21) - - // Should succeed because the server transparently re-signs one - runAtDifferentDate(threeWeeksLater, func() { - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with expired timestamp")) - }) -} - -func (s *DockerTrustSuite) TestTrustedPushWithReleasesDelegationOnly(c *check.C) { - testRequires(c, NotaryHosting) - repoName := fmt.Sprintf("%v/dockerclireleasedelegationinitfirst/trusted", privateRegistryURL) - targetName := fmt.Sprintf("%s:latest", repoName) - s.notaryInitRepo(c, repoName) - s.notaryCreateDelegation(c, repoName, "targets/releases", s.not.keys[0].Public) - s.notaryPublish(c, repoName) - - s.notaryImportKey(c, repoName, "targets/releases", s.not.keys[0].Private) - - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", targetName) - - pushCmd := exec.Command(dockerBinary, "push", targetName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag")) - // check to make sure that the target has been added to targets/releases and not targets - s.assertTargetInRoles(c, repoName, "latest", "targets/releases") - s.assertTargetNotInRoles(c, repoName, "latest", "targets") - - // Try pull after push - os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust")) - - pullCmd := exec.Command(dockerBinary, "pull", targetName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Status: Image is up to date", check.Commentf(out)) -} - -func (s *DockerTrustSuite) TestTrustedPushSignsAllFirstLevelRolesWeHaveKeysFor(c *check.C) { - testRequires(c, NotaryHosting) - repoName := fmt.Sprintf("%v/dockerclimanyroles/trusted", privateRegistryURL) - targetName := fmt.Sprintf("%s:latest", repoName) - s.notaryInitRepo(c, repoName) - s.notaryCreateDelegation(c, repoName, "targets/role1", s.not.keys[0].Public) - s.notaryCreateDelegation(c, repoName, "targets/role2", s.not.keys[1].Public) - s.notaryCreateDelegation(c, repoName, "targets/role3", s.not.keys[2].Public) - - // import everything except the third key - s.notaryImportKey(c, repoName, "targets/role1", s.not.keys[0].Private) - s.notaryImportKey(c, repoName, "targets/role2", s.not.keys[1].Private) - - s.notaryCreateDelegation(c, repoName, "targets/role1/subrole", s.not.keys[3].Public) - s.notaryImportKey(c, repoName, "targets/role1/subrole", s.not.keys[3].Private) - - s.notaryPublish(c, repoName) - - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", targetName) - - pushCmd := exec.Command(dockerBinary, "push", targetName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag")) - - // check to make sure that the target has been added to targets/role1 and targets/role2, and - // not targets (because there are delegations) or targets/role3 (due to missing key) or - // targets/role1/subrole (due to it being a second level delegation) - s.assertTargetInRoles(c, repoName, "latest", "targets/role1", "targets/role2") - s.assertTargetNotInRoles(c, repoName, "latest", "targets") - - // Try pull after push - os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust")) - - // pull should fail because none of these are the releases role - pullCmd := exec.Command(dockerBinary, "pull", targetName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.NotNil, check.Commentf(out)) -} - -func (s *DockerTrustSuite) TestTrustedPushSignsForRolesWithKeysAndValidPaths(c *check.C) { - repoName := fmt.Sprintf("%v/dockerclirolesbykeysandpaths/trusted", privateRegistryURL) - targetName := fmt.Sprintf("%s:latest", repoName) - s.notaryInitRepo(c, repoName) - s.notaryCreateDelegation(c, repoName, "targets/role1", s.not.keys[0].Public, "l", "z") - s.notaryCreateDelegation(c, repoName, "targets/role2", s.not.keys[1].Public, "x", "y") - s.notaryCreateDelegation(c, repoName, "targets/role3", s.not.keys[2].Public, "latest") - s.notaryCreateDelegation(c, repoName, "targets/role4", s.not.keys[3].Public, "latest") - - // import everything except the third key - s.notaryImportKey(c, repoName, "targets/role1", s.not.keys[0].Private) - s.notaryImportKey(c, repoName, "targets/role2", s.not.keys[1].Private) - s.notaryImportKey(c, repoName, "targets/role4", s.not.keys[3].Private) - - s.notaryPublish(c, repoName) - - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", targetName) - - pushCmd := exec.Command(dockerBinary, "push", targetName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out)) - c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with existing tag")) - - // check to make sure that the target has been added to targets/role1 and targets/role4, and - // not targets (because there are delegations) or targets/role2 (due to path restrictions) or - // targets/role3 (due to missing key) - s.assertTargetInRoles(c, repoName, "latest", "targets/role1", "targets/role4") - s.assertTargetNotInRoles(c, repoName, "latest", "targets") - - // Try pull after push - os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust")) - - // pull should fail because none of these are the releases role - pullCmd := exec.Command(dockerBinary, "pull", targetName) - s.trustedCmd(pullCmd) - out, _, err = runCommandWithOutput(pullCmd) - c.Assert(err, check.NotNil, check.Commentf(out)) -} - -func (s *DockerTrustSuite) TestTrustedPushDoesntSignTargetsIfDelegationsExist(c *check.C) { - testRequires(c, NotaryHosting) - repoName := fmt.Sprintf("%v/dockerclireleasedelegationnotsignable/trusted", privateRegistryURL) - targetName := fmt.Sprintf("%s:latest", repoName) - s.notaryInitRepo(c, repoName) - s.notaryCreateDelegation(c, repoName, "targets/role1", s.not.keys[0].Public) - s.notaryPublish(c, repoName) - - // do not import any delegations key - - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", targetName) - - pushCmd := exec.Command(dockerBinary, "push", targetName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - c.Assert(err, check.NotNil, check.Commentf("trusted push succeeded but should have failed:\n%s", out)) - c.Assert(out, checker.Contains, "no valid signing keys", - check.Commentf("Missing expected output on trusted push without keys")) - - s.assertTargetNotInRoles(c, repoName, "latest", "targets", "targets/role1") -} - -func (s *DockerRegistryAuthHtpasswdSuite) TestPushNoCredentialsNoRetry(c *check.C) { - repoName := fmt.Sprintf("%s/busybox", privateRegistryURL) - dockerCmd(c, "tag", "busybox", repoName) - out, _, err := dockerCmdWithError("push", repoName) - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, check.Not(checker.Contains), "Retrying") - c.Assert(out, checker.Contains, "no basic auth credentials") -} - -// This may be flaky but it's needed not to regress on unauthorized push, see #21054 -func (s *DockerSuite) TestPushToCentralRegistryUnauthorized(c *check.C) { - testRequires(c, Network) - repoName := "test/busybox" - dockerCmd(c, "tag", "busybox", repoName) - out, _, err := dockerCmdWithError("push", repoName) - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, check.Not(checker.Contains), "Retrying") -} - -func getTestTokenService(status int, body string, retries int) *httptest.Server { - var mu sync.Mutex - return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - mu.Lock() - if retries > 0 { - w.WriteHeader(http.StatusServiceUnavailable) - w.Header().Set("Content-Type", "application/json") - w.Write([]byte(`{"errors":[{"code":"UNAVAILABLE","message":"cannot create token at this time"}]}`)) - retries-- - } else { - w.WriteHeader(status) - w.Header().Set("Content-Type", "application/json") - w.Write([]byte(body)) - } - mu.Unlock() - })) -} - -func (s *DockerRegistryAuthTokenSuite) TestPushTokenServiceUnauthResponse(c *check.C) { - ts := getTestTokenService(http.StatusUnauthorized, `{"errors": [{"Code":"UNAUTHORIZED", "message": "a message", "detail": null}]}`, 0) - defer ts.Close() - s.setupRegistryWithTokenService(c, ts.URL) - repoName := fmt.Sprintf("%s/busybox", privateRegistryURL) - dockerCmd(c, "tag", "busybox", repoName) - out, _, err := dockerCmdWithError("push", repoName) - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Not(checker.Contains), "Retrying") - c.Assert(out, checker.Contains, "unauthorized: a message") -} - -func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseUnauthorized(c *check.C) { - ts := getTestTokenService(http.StatusUnauthorized, `{"error": "unauthorized"}`, 0) - defer ts.Close() - s.setupRegistryWithTokenService(c, ts.URL) - repoName := fmt.Sprintf("%s/busybox", privateRegistryURL) - dockerCmd(c, "tag", "busybox", repoName) - out, _, err := dockerCmdWithError("push", repoName) - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Not(checker.Contains), "Retrying") - split := strings.Split(out, "\n") - c.Assert(split[len(split)-2], check.Equals, "unauthorized: authentication required") -} - -func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseError(c *check.C) { - ts := getTestTokenService(http.StatusTooManyRequests, `{"errors": [{"code":"TOOMANYREQUESTS","message":"out of tokens"}]}`, 4) - defer ts.Close() - s.setupRegistryWithTokenService(c, ts.URL) - repoName := fmt.Sprintf("%s/busybox", privateRegistryURL) - dockerCmd(c, "tag", "busybox", repoName) - out, _, err := dockerCmdWithError("push", repoName) - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Retrying") - c.Assert(out, checker.Not(checker.Contains), "Retrying in 15") - split := strings.Split(out, "\n") - c.Assert(split[len(split)-2], check.Equals, "toomanyrequests: out of tokens") -} - -func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseUnparsable(c *check.C) { - ts := getTestTokenService(http.StatusForbidden, `no way`, 0) - defer ts.Close() - s.setupRegistryWithTokenService(c, ts.URL) - repoName := fmt.Sprintf("%s/busybox", privateRegistryURL) - dockerCmd(c, "tag", "busybox", repoName) - out, _, err := dockerCmdWithError("push", repoName) - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Not(checker.Contains), "Retrying") - split := strings.Split(out, "\n") - c.Assert(split[len(split)-2], checker.Contains, "error parsing HTTP 403 response body: ") -} - -func (s *DockerRegistryAuthTokenSuite) TestPushMisconfiguredTokenServiceResponseNoToken(c *check.C) { - ts := getTestTokenService(http.StatusOK, `{"something": "wrong"}`, 0) - defer ts.Close() - s.setupRegistryWithTokenService(c, ts.URL) - repoName := fmt.Sprintf("%s/busybox", privateRegistryURL) - dockerCmd(c, "tag", "busybox", repoName) - out, _, err := dockerCmdWithError("push", repoName) - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Not(checker.Contains), "Retrying") - split := strings.Split(out, "\n") - c.Assert(split[len(split)-2], check.Equals, "authorization server did not include a token in the response") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_registry_user_agent_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_registry_user_agent_test.go deleted file mode 100644 index fb9a66a..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_registry_user_agent_test.go +++ /dev/null @@ -1,120 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "regexp" - - "github.com/go-check/check" -) - -// unescapeBackslashSemicolonParens unescapes \;() -func unescapeBackslashSemicolonParens(s string) string { - re := regexp.MustCompile(`\\;`) - ret := re.ReplaceAll([]byte(s), []byte(";")) - - re = regexp.MustCompile(`\\\(`) - ret = re.ReplaceAll([]byte(ret), []byte("(")) - - re = regexp.MustCompile(`\\\)`) - ret = re.ReplaceAll([]byte(ret), []byte(")")) - - re = regexp.MustCompile(`\\\\`) - ret = re.ReplaceAll([]byte(ret), []byte(`\`)) - - return string(ret) -} - -func regexpCheckUA(c *check.C, ua string) { - re := regexp.MustCompile("(?P.+) UpstreamClient(?P.+)") - substrArr := re.FindStringSubmatch(ua) - - c.Assert(substrArr, check.HasLen, 3, check.Commentf("Expected 'UpstreamClient()' with upstream client UA")) - dockerUA := substrArr[1] - upstreamUAEscaped := substrArr[2] - - // check dockerUA looks correct - reDockerUA := regexp.MustCompile("^docker/[0-9A-Za-z+]") - bMatchDockerUA := reDockerUA.MatchString(dockerUA) - c.Assert(bMatchDockerUA, check.Equals, true, check.Commentf("Docker Engine User-Agent malformed")) - - // check upstreamUA looks correct - // Expecting something like: Docker-Client/1.11.0-dev (linux) - upstreamUA := unescapeBackslashSemicolonParens(upstreamUAEscaped) - reUpstreamUA := regexp.MustCompile("^\\(Docker-Client/[0-9A-Za-z+]") - bMatchUpstreamUA := reUpstreamUA.MatchString(upstreamUA) - c.Assert(bMatchUpstreamUA, check.Equals, true, check.Commentf("(Upstream) Docker Client User-Agent malformed")) -} - -func registerUserAgentHandler(reg *testRegistry, result *string) { - reg.registerHandler("/v2/", func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(404) - var ua string - for k, v := range r.Header { - if k == "User-Agent" { - ua = v[0] - } - } - *result = ua - }) -} - -// TestUserAgentPassThrough verifies that when an image is pulled from -// a registry, the registry should see a User-Agent string of the form -// [docker engine UA] UptreamClientSTREAM-CLIENT([client UA]) -func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *check.C) { - var ( - buildUA string - pullUA string - pushUA string - loginUA string - ) - - buildReg, err := newTestRegistry(c) - c.Assert(err, check.IsNil) - registerUserAgentHandler(buildReg, &buildUA) - buildRepoName := fmt.Sprintf("%s/busybox", buildReg.hostport) - - pullReg, err := newTestRegistry(c) - c.Assert(err, check.IsNil) - registerUserAgentHandler(pullReg, &pullUA) - pullRepoName := fmt.Sprintf("%s/busybox", pullReg.hostport) - - pushReg, err := newTestRegistry(c) - c.Assert(err, check.IsNil) - registerUserAgentHandler(pushReg, &pushUA) - pushRepoName := fmt.Sprintf("%s/busybox", pushReg.hostport) - - loginReg, err := newTestRegistry(c) - c.Assert(err, check.IsNil) - registerUserAgentHandler(loginReg, &loginUA) - - err = s.d.Start( - "--insecure-registry", buildReg.hostport, - "--insecure-registry", pullReg.hostport, - "--insecure-registry", pushReg.hostport, - "--insecure-registry", loginReg.hostport, - "--disable-legacy-registry=true") - c.Assert(err, check.IsNil) - - dockerfileName, cleanup1, err := makefile(fmt.Sprintf("FROM %s", buildRepoName)) - c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile")) - defer cleanup1() - s.d.Cmd("build", "--file", dockerfileName, ".") - regexpCheckUA(c, buildUA) - - s.d.Cmd("login", "-u", "richard", "-p", "testtest", "-e", "testuser@testdomain.com", loginReg.hostport) - regexpCheckUA(c, loginUA) - - s.d.Cmd("pull", pullRepoName) - regexpCheckUA(c, pullUA) - - dockerfileName, cleanup2, err := makefile(`FROM scratch - ENV foo bar`) - c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile")) - defer cleanup2() - s.d.Cmd("build", "-t", pushRepoName, "--file", dockerfileName, ".") - - s.d.Cmd("push", pushRepoName) - regexpCheckUA(c, pushUA) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_rename_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_rename_test.go deleted file mode 100644 index 373d614..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_rename_test.go +++ /dev/null @@ -1,138 +0,0 @@ -package main - -import ( - "strings" - - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/docker/docker/pkg/stringid" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) { - out, _ := dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh") - - cleanedContainerID := strings.TrimSpace(out) - dockerCmd(c, "wait", cleanedContainerID) - - name := inspectField(c, cleanedContainerID, "Name") - newName := "new_name" + stringid.GenerateNonCryptoID() - dockerCmd(c, "rename", "first_name", newName) - - name = inspectField(c, cleanedContainerID, "Name") - c.Assert(name, checker.Equals, "/"+newName, check.Commentf("Failed to rename container %s", name)) - -} - -func (s *DockerSuite) TestRenameRunningContainer(c *check.C) { - out, _ := dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh") - - newName := "new_name" + stringid.GenerateNonCryptoID() - cleanedContainerID := strings.TrimSpace(out) - dockerCmd(c, "rename", "first_name", newName) - - name := inspectField(c, cleanedContainerID, "Name") - c.Assert(name, checker.Equals, "/"+newName, check.Commentf("Failed to rename container %s", name)) -} - -func (s *DockerSuite) TestRenameRunningContainerAndReuse(c *check.C) { - out, _ := runSleepingContainer(c, "--name", "first_name") - c.Assert(waitRun("first_name"), check.IsNil) - - newName := "new_name" - ContainerID := strings.TrimSpace(out) - dockerCmd(c, "rename", "first_name", newName) - - name := inspectField(c, ContainerID, "Name") - c.Assert(name, checker.Equals, "/"+newName, check.Commentf("Failed to rename container")) - - out, _ = runSleepingContainer(c, "--name", "first_name") - c.Assert(waitRun("first_name"), check.IsNil) - newContainerID := strings.TrimSpace(out) - name = inspectField(c, newContainerID, "Name") - c.Assert(name, checker.Equals, "/first_name", check.Commentf("Failed to reuse container name")) -} - -func (s *DockerSuite) TestRenameCheckNames(c *check.C) { - dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh") - - newName := "new_name" + stringid.GenerateNonCryptoID() - dockerCmd(c, "rename", "first_name", newName) - - name := inspectField(c, newName, "Name") - c.Assert(name, checker.Equals, "/"+newName, check.Commentf("Failed to rename container %s", name)) - - result := dockerCmdWithResult("inspect", "-f={{.Name}}", "--type=container", "first_name") - c.Assert(result, icmd.Matches, icmd.Expected{ - ExitCode: 1, - Err: "No such container: first_name", - }) -} - -func (s *DockerSuite) TestRenameInvalidName(c *check.C) { - runSleepingContainer(c, "--name", "myname") - - out, _, err := dockerCmdWithError("rename", "myname", "new:invalid") - c.Assert(err, checker.NotNil, check.Commentf("Renaming container to invalid name should have failed: %s", out)) - c.Assert(out, checker.Contains, "Invalid container name", check.Commentf("%v", err)) - - out, _, err = dockerCmdWithError("rename", "myname") - c.Assert(err, checker.NotNil, check.Commentf("Renaming container to invalid name should have failed: %s", out)) - c.Assert(out, checker.Contains, "requires exactly 2 argument(s).", check.Commentf("%v", err)) - - out, _, err = dockerCmdWithError("rename", "myname", "") - c.Assert(err, checker.NotNil, check.Commentf("Renaming container to invalid name should have failed: %s", out)) - c.Assert(out, checker.Contains, "may be empty", check.Commentf("%v", err)) - - out, _, err = dockerCmdWithError("rename", "", "newname") - c.Assert(err, checker.NotNil, check.Commentf("Renaming container with empty name should have failed: %s", out)) - c.Assert(out, checker.Contains, "may be empty", check.Commentf("%v", err)) - - out, _ = dockerCmd(c, "ps", "-a") - c.Assert(out, checker.Contains, "myname", check.Commentf("Output of docker ps should have included 'myname': %s", out)) -} - -func (s *DockerSuite) TestRenameAnonymousContainer(c *check.C) { - testRequires(c, DaemonIsLinux) - - dockerCmd(c, "network", "create", "network1") - out, _ := dockerCmd(c, "create", "-it", "--net", "network1", "busybox", "top") - - anonymousContainerID := strings.TrimSpace(out) - - dockerCmd(c, "rename", anonymousContainerID, "container1") - dockerCmd(c, "start", "container1") - - count := "-c" - if daemonPlatform == "windows" { - count = "-n" - } - - _, _, err := dockerCmdWithError("run", "--net", "network1", "busybox", "ping", count, "1", "container1") - c.Assert(err, check.IsNil, check.Commentf("Embedded DNS lookup fails after renaming anonymous container: %v", err)) -} - -func (s *DockerSuite) TestRenameContainerWithSameName(c *check.C) { - out, _ := runSleepingContainer(c, "--name", "old") - ContainerID := strings.TrimSpace(out) - - out, _, err := dockerCmdWithError("rename", "old", "old") - c.Assert(err, checker.NotNil, check.Commentf("Renaming a container with the same name should have failed")) - c.Assert(out, checker.Contains, "Renaming a container with the same name", check.Commentf("%v", err)) - - out, _, err = dockerCmdWithError("rename", ContainerID, "old") - c.Assert(err, checker.NotNil, check.Commentf("Renaming a container with the same name should have failed")) - c.Assert(out, checker.Contains, "Renaming a container with the same name", check.Commentf("%v", err)) -} - -// Test case for #23973 -func (s *DockerSuite) TestRenameContainerWithLinkedContainer(c *check.C) { - testRequires(c, DaemonIsLinux) - - db1, _ := dockerCmd(c, "run", "--name", "db1", "-d", "busybox", "top") - dockerCmd(c, "run", "--name", "app1", "-d", "--link", "db1:/mysql", "busybox", "top") - dockerCmd(c, "rename", "app1", "app2") - out, _, err := dockerCmdWithError("inspect", "--format={{ .Id }}", "app2/mysql") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(db1)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_restart_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_restart_test.go deleted file mode 100644 index 7d58528..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_restart_test.go +++ /dev/null @@ -1,278 +0,0 @@ -package main - -import ( - "os" - "strconv" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestRestartStoppedContainer(c *check.C) { - dockerCmd(c, "run", "--name=test", "busybox", "echo", "foobar") - cleanedContainerID, err := getIDByName("test") - c.Assert(err, check.IsNil) - - out, _ := dockerCmd(c, "logs", cleanedContainerID) - c.Assert(out, checker.Equals, "foobar\n") - - dockerCmd(c, "restart", cleanedContainerID) - - // Wait until the container has stopped - err = waitInspect(cleanedContainerID, "{{.State.Running}}", "false", 20*time.Second) - c.Assert(err, checker.IsNil) - - out, _ = dockerCmd(c, "logs", cleanedContainerID) - c.Assert(out, checker.Equals, "foobar\nfoobar\n") -} - -func (s *DockerSuite) TestRestartRunningContainer(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "echo foobar && sleep 30 && echo 'should not print this'") - - cleanedContainerID := strings.TrimSpace(out) - - c.Assert(waitRun(cleanedContainerID), checker.IsNil) - - out, _ = dockerCmd(c, "logs", cleanedContainerID) - c.Assert(out, checker.Equals, "foobar\n") - - dockerCmd(c, "restart", "-t", "1", cleanedContainerID) - - out, _ = dockerCmd(c, "logs", cleanedContainerID) - - c.Assert(waitRun(cleanedContainerID), checker.IsNil) - - c.Assert(out, checker.Equals, "foobar\nfoobar\n") -} - -// Test that restarting a container with a volume does not create a new volume on restart. Regression test for #819. -func (s *DockerSuite) TestRestartWithVolumes(c *check.C) { - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - out, _ := runSleepingContainer(c, "-d", "-v", prefix+slash+"test") - - cleanedContainerID := strings.TrimSpace(out) - out, err := inspectFilter(cleanedContainerID, "len .Mounts") - c.Assert(err, check.IsNil, check.Commentf("failed to inspect %s: %s", cleanedContainerID, out)) - out = strings.Trim(out, " \n\r") - c.Assert(out, checker.Equals, "1") - - source, err := inspectMountSourceField(cleanedContainerID, prefix+slash+"test") - c.Assert(err, checker.IsNil) - - dockerCmd(c, "restart", cleanedContainerID) - - out, err = inspectFilter(cleanedContainerID, "len .Mounts") - c.Assert(err, check.IsNil, check.Commentf("failed to inspect %s: %s", cleanedContainerID, out)) - out = strings.Trim(out, " \n\r") - c.Assert(out, checker.Equals, "1") - - sourceAfterRestart, err := inspectMountSourceField(cleanedContainerID, prefix+slash+"test") - c.Assert(err, checker.IsNil) - c.Assert(source, checker.Equals, sourceAfterRestart) -} - -func (s *DockerSuite) TestRestartPolicyNO(c *check.C) { - out, _ := dockerCmd(c, "create", "--restart=no", "busybox") - - id := strings.TrimSpace(string(out)) - name := inspectField(c, id, "HostConfig.RestartPolicy.Name") - c.Assert(name, checker.Equals, "no") -} - -func (s *DockerSuite) TestRestartPolicyAlways(c *check.C) { - out, _ := dockerCmd(c, "create", "--restart=always", "busybox") - - id := strings.TrimSpace(string(out)) - name := inspectField(c, id, "HostConfig.RestartPolicy.Name") - c.Assert(name, checker.Equals, "always") - - MaximumRetryCount := inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount") - - // MaximumRetryCount=0 if the restart policy is always - c.Assert(MaximumRetryCount, checker.Equals, "0") -} - -func (s *DockerSuite) TestRestartPolicyOnFailure(c *check.C) { - out, _, err := dockerCmdWithError("create", "--restart=on-failure:-1", "busybox") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "maximum retry count cannot be negative") - - out, _ = dockerCmd(c, "create", "--restart=on-failure:1", "busybox") - - id := strings.TrimSpace(string(out)) - name := inspectField(c, id, "HostConfig.RestartPolicy.Name") - maxRetry := inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount") - - c.Assert(name, checker.Equals, "on-failure") - c.Assert(maxRetry, checker.Equals, "1") - - out, _ = dockerCmd(c, "create", "--restart=on-failure:0", "busybox") - - id = strings.TrimSpace(string(out)) - name = inspectField(c, id, "HostConfig.RestartPolicy.Name") - maxRetry = inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount") - - c.Assert(name, checker.Equals, "on-failure") - c.Assert(maxRetry, checker.Equals, "0") - - out, _ = dockerCmd(c, "create", "--restart=on-failure", "busybox") - - id = strings.TrimSpace(string(out)) - name = inspectField(c, id, "HostConfig.RestartPolicy.Name") - maxRetry = inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount") - - c.Assert(name, checker.Equals, "on-failure") - c.Assert(maxRetry, checker.Equals, "0") -} - -// a good container with --restart=on-failure:3 -// MaximumRetryCount!=0; RestartCount=0 -func (s *DockerSuite) TestRestartContainerwithGoodContainer(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "true") - - id := strings.TrimSpace(string(out)) - err := waitInspect(id, "{{ .State.Restarting }} {{ .State.Running }}", "false false", 30*time.Second) - c.Assert(err, checker.IsNil) - - count := inspectField(c, id, "RestartCount") - c.Assert(count, checker.Equals, "0") - - MaximumRetryCount := inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount") - c.Assert(MaximumRetryCount, checker.Equals, "3") - -} - -func (s *DockerSuite) TestRestartContainerSuccess(c *check.C) { - testRequires(c, SameHostDaemon) - - out, _ := runSleepingContainer(c, "-d", "--restart=always") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), check.IsNil) - - pidStr := inspectField(c, id, "State.Pid") - - pid, err := strconv.Atoi(pidStr) - c.Assert(err, check.IsNil) - - p, err := os.FindProcess(pid) - c.Assert(err, check.IsNil) - c.Assert(p, check.NotNil) - - err = p.Kill() - c.Assert(err, check.IsNil) - - err = waitInspect(id, "{{.RestartCount}}", "1", 30*time.Second) - c.Assert(err, check.IsNil) - - err = waitInspect(id, "{{.State.Status}}", "running", 30*time.Second) - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestRestartWithPolicyUserDefinedNetwork(c *check.C) { - // TODO Windows. This may be portable following HNS integration post TP5. - testRequires(c, DaemonIsLinux, SameHostDaemon, NotUserNamespace, NotArm) - dockerCmd(c, "network", "create", "-d", "bridge", "udNet") - - dockerCmd(c, "run", "-d", "--net=udNet", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - - dockerCmd(c, "run", "-d", "--restart=always", "--net=udNet", "--name=second", - "--link=first:foo", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // ping to first and its alias foo must succeed - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo") - c.Assert(err, check.IsNil) - - // Now kill the second container and let the restart policy kick in - pidStr := inspectField(c, "second", "State.Pid") - - pid, err := strconv.Atoi(pidStr) - c.Assert(err, check.IsNil) - - p, err := os.FindProcess(pid) - c.Assert(err, check.IsNil) - c.Assert(p, check.NotNil) - - err = p.Kill() - c.Assert(err, check.IsNil) - - err = waitInspect("second", "{{.RestartCount}}", "1", 5*time.Second) - c.Assert(err, check.IsNil) - - err = waitInspect("second", "{{.State.Status}}", "running", 5*time.Second) - - // ping to first and its alias foo must still succeed - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo") - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestRestartPolicyAfterRestart(c *check.C) { - testRequires(c, SameHostDaemon) - - out, _ := runSleepingContainer(c, "-d", "--restart=always") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), check.IsNil) - - dockerCmd(c, "restart", id) - - c.Assert(waitRun(id), check.IsNil) - - pidStr := inspectField(c, id, "State.Pid") - - pid, err := strconv.Atoi(pidStr) - c.Assert(err, check.IsNil) - - p, err := os.FindProcess(pid) - c.Assert(err, check.IsNil) - c.Assert(p, check.NotNil) - - err = p.Kill() - c.Assert(err, check.IsNil) - - err = waitInspect(id, "{{.RestartCount}}", "1", 30*time.Second) - c.Assert(err, check.IsNil) - - err = waitInspect(id, "{{.State.Status}}", "running", 30*time.Second) - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestRestartContainerwithRestartPolicy(c *check.C) { - out1, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "false") - out2, _ := dockerCmd(c, "run", "-d", "--restart=always", "busybox", "false") - - id1 := strings.TrimSpace(string(out1)) - id2 := strings.TrimSpace(string(out2)) - waitTimeout := 15 * time.Second - if daemonPlatform == "windows" { - waitTimeout = 150 * time.Second - } - err := waitInspect(id1, "{{ .State.Restarting }} {{ .State.Running }}", "false false", waitTimeout) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "restart", id1) - dockerCmd(c, "restart", id2) - - dockerCmd(c, "stop", id1) - dockerCmd(c, "stop", id2) - dockerCmd(c, "start", id1) - dockerCmd(c, "start", id2) -} - -func (s *DockerSuite) TestRestartAutoRemoveContainer(c *check.C) { - out, _ := runSleepingContainer(c, "--rm") - - id := strings.TrimSpace(string(out)) - dockerCmd(c, "restart", id) - err := waitInspect(id, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) - c.Assert(err, checker.IsNil) - - out, _ = dockerCmd(c, "ps") - c.Assert(out, checker.Contains, id[:12], check.Commentf("container should be restarted instead of removed: %v", out)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_rm_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_rm_test.go deleted file mode 100644 index 0186c56..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_rm_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package main - -import ( - "io/ioutil" - "os" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) { - testRequires(c, SameHostDaemon) - - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - - tempDir, err := ioutil.TempDir("", "test-rm-container-with-removed-volume-") - if err != nil { - c.Fatalf("failed to create temporary directory: %s", tempDir) - } - defer os.RemoveAll(tempDir) - - dockerCmd(c, "run", "--name", "losemyvolumes", "-v", tempDir+":"+prefix+slash+"test", "busybox", "true") - - err = os.RemoveAll(tempDir) - c.Assert(err, check.IsNil) - - dockerCmd(c, "rm", "-v", "losemyvolumes") -} - -func (s *DockerSuite) TestRmContainerWithVolume(c *check.C) { - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - - dockerCmd(c, "run", "--name", "foo", "-v", prefix+slash+"srv", "busybox", "true") - - dockerCmd(c, "rm", "-v", "foo") -} - -func (s *DockerSuite) TestRmContainerRunning(c *check.C) { - createRunningContainer(c, "foo") - - _, _, err := dockerCmdWithError("rm", "foo") - c.Assert(err, checker.NotNil, check.Commentf("Expected error, can't rm a running container")) -} - -func (s *DockerSuite) TestRmContainerForceRemoveRunning(c *check.C) { - createRunningContainer(c, "foo") - - // Stop then remove with -s - dockerCmd(c, "rm", "-f", "foo") -} - -func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) { - dockerfile1 := `FROM busybox:latest - ENTRYPOINT ["true"]` - img := "test-container-orphaning" - dockerfile2 := `FROM busybox:latest - ENTRYPOINT ["true"] - MAINTAINER Integration Tests` - - // build first dockerfile - img1, err := buildImage(img, dockerfile1, true) - c.Assert(err, check.IsNil, check.Commentf("Could not build image %s", img)) - // run container on first image - dockerCmd(c, "run", img) - // rebuild dockerfile with a small addition at the end - _, err = buildImage(img, dockerfile2, true) - c.Assert(err, check.IsNil, check.Commentf("Could not rebuild image %s", img)) - // try to remove the image, should not error out. - out, _, err := dockerCmdWithError("rmi", img) - c.Assert(err, check.IsNil, check.Commentf("Expected to removing the image, but failed: %s", out)) - - // check if we deleted the first image - out, _ = dockerCmd(c, "images", "-q", "--no-trunc") - c.Assert(out, checker.Contains, img1, check.Commentf("Orphaned container (could not find %q in docker images): %s", img1, out)) - -} - -func (s *DockerSuite) TestRmInvalidContainer(c *check.C) { - out, _, err := dockerCmdWithError("rm", "unknown") - c.Assert(err, checker.NotNil, check.Commentf("Expected error on rm unknown container, got none")) - c.Assert(out, checker.Contains, "No such container") -} - -func createRunningContainer(c *check.C, name string) { - runSleepingContainer(c, "-dt", "--name", name) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_rmi_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_rmi_test.go deleted file mode 100644 index cb16d9d..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_rmi_test.go +++ /dev/null @@ -1,352 +0,0 @@ -package main - -import ( - "fmt" - "os/exec" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/stringid" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestRmiWithContainerFails(c *check.C) { - errSubstr := "is using it" - - // create a container - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - - cleanedContainerID := strings.TrimSpace(out) - - // try to delete the image - out, _, err := dockerCmdWithError("rmi", "busybox") - // Container is using image, should not be able to rmi - c.Assert(err, checker.NotNil) - // Container is using image, error message should contain errSubstr - c.Assert(out, checker.Contains, errSubstr, check.Commentf("Container: %q", cleanedContainerID)) - - // make sure it didn't delete the busybox name - images, _ := dockerCmd(c, "images") - // The name 'busybox' should not have been removed from images - c.Assert(images, checker.Contains, "busybox") -} - -func (s *DockerSuite) TestRmiTag(c *check.C) { - imagesBefore, _ := dockerCmd(c, "images", "-a") - dockerCmd(c, "tag", "busybox", "utest:tag1") - dockerCmd(c, "tag", "busybox", "utest/docker:tag2") - dockerCmd(c, "tag", "busybox", "utest:5000/docker:tag3") - { - imagesAfter, _ := dockerCmd(c, "images", "-a") - c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+3, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter)) - } - dockerCmd(c, "rmi", "utest/docker:tag2") - { - imagesAfter, _ := dockerCmd(c, "images", "-a") - c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+2, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter)) - } - dockerCmd(c, "rmi", "utest:5000/docker:tag3") - { - imagesAfter, _ := dockerCmd(c, "images", "-a") - c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+1, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter)) - - } - dockerCmd(c, "rmi", "utest:tag1") - { - imagesAfter, _ := dockerCmd(c, "images", "-a") - c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n"), check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter)) - - } -} - -func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-one'") - - containerID := strings.TrimSpace(out) - - // Wait for it to exit as cannot commit a running container on Windows, and - // it will take a few seconds to exit - if daemonPlatform == "windows" { - err := waitExited(containerID, 60*time.Second) - c.Assert(err, check.IsNil) - } - - dockerCmd(c, "commit", containerID, "busybox-one") - - imagesBefore, _ := dockerCmd(c, "images", "-a") - dockerCmd(c, "tag", "busybox-one", "busybox-one:tag1") - dockerCmd(c, "tag", "busybox-one", "busybox-one:tag2") - - imagesAfter, _ := dockerCmd(c, "images", "-a") - // tag busybox to create 2 more images with same imageID - c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+2, check.Commentf("docker images shows: %q\n", imagesAfter)) - - imgID := inspectField(c, "busybox-one:tag1", "Id") - - // run a container with the image - out, _ = runSleepingContainerInImage(c, "busybox-one") - - containerID = strings.TrimSpace(out) - - // first checkout without force it fails - out, _, err := dockerCmdWithError("rmi", imgID) - expected := fmt.Sprintf("conflict: unable to delete %s (cannot be forced) - image is being used by running container %s", stringid.TruncateID(imgID), stringid.TruncateID(containerID)) - // rmi tagged in multiple repos should have failed without force - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, expected) - - dockerCmd(c, "stop", containerID) - dockerCmd(c, "rmi", "-f", imgID) - - imagesAfter, _ = dockerCmd(c, "images", "-a") - // rmi -f failed, image still exists - c.Assert(imagesAfter, checker.Not(checker.Contains), imgID[:12], check.Commentf("ImageID:%q; ImagesAfter: %q", imgID, imagesAfter)) -} - -func (s *DockerSuite) TestRmiImgIDForce(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'") - - containerID := strings.TrimSpace(out) - - // Wait for it to exit as cannot commit a running container on Windows, and - // it will take a few seconds to exit - if daemonPlatform == "windows" { - err := waitExited(containerID, 60*time.Second) - c.Assert(err, check.IsNil) - } - - dockerCmd(c, "commit", containerID, "busybox-test") - - imagesBefore, _ := dockerCmd(c, "images", "-a") - dockerCmd(c, "tag", "busybox-test", "utest:tag1") - dockerCmd(c, "tag", "busybox-test", "utest:tag2") - dockerCmd(c, "tag", "busybox-test", "utest/docker:tag3") - dockerCmd(c, "tag", "busybox-test", "utest:5000/docker:tag4") - { - imagesAfter, _ := dockerCmd(c, "images", "-a") - c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+4, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter)) - } - imgID := inspectField(c, "busybox-test", "Id") - - // first checkout without force it fails - out, _, err := dockerCmdWithError("rmi", imgID) - // rmi tagged in multiple repos should have failed without force - c.Assert(err, checker.NotNil) - // rmi tagged in multiple repos should have failed without force - c.Assert(out, checker.Contains, "(must be forced) - image is referenced in multiple repositories", check.Commentf("out: %s; err: %v;", out, err)) - - dockerCmd(c, "rmi", "-f", imgID) - { - imagesAfter, _ := dockerCmd(c, "images", "-a") - // rmi failed, image still exists - c.Assert(imagesAfter, checker.Not(checker.Contains), imgID[:12]) - } -} - -// See https://github.com/docker/docker/issues/14116 -func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c *check.C) { - dockerfile := "FROM busybox\nRUN echo test 14116\n" - imgID, err := buildImage("test-14116", dockerfile, false) - c.Assert(err, checker.IsNil) - - newTag := "newtag" - dockerCmd(c, "tag", imgID, newTag) - runSleepingContainerInImage(c, imgID) - - out, _, err := dockerCmdWithError("rmi", "-f", imgID) - // rmi -f should not delete image with running containers - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "(cannot be forced) - image is being used by running container") -} - -func (s *DockerSuite) TestRmiTagWithExistingContainers(c *check.C) { - container := "test-delete-tag" - newtag := "busybox:newtag" - bb := "busybox:latest" - dockerCmd(c, "tag", bb, newtag) - - dockerCmd(c, "run", "--name", container, bb, "/bin/true") - - out, _ := dockerCmd(c, "rmi", newtag) - c.Assert(strings.Count(out, "Untagged: "), checker.Equals, 1) -} - -func (s *DockerSuite) TestRmiForceWithExistingContainers(c *check.C) { - image := "busybox-clone" - - cmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", image, "-") - cmd.Stdin = strings.NewReader(`FROM busybox -MAINTAINER foo`) - - out, _, err := runCommandWithOutput(cmd) - c.Assert(err, checker.IsNil, check.Commentf("Could not build %s: %s", image, out)) - - dockerCmd(c, "run", "--name", "test-force-rmi", image, "/bin/true") - - dockerCmd(c, "rmi", "-f", image) -} - -func (s *DockerSuite) TestRmiWithMultipleRepositories(c *check.C) { - newRepo := "127.0.0.1:5000/busybox" - oldRepo := "busybox" - newTag := "busybox:test" - dockerCmd(c, "tag", oldRepo, newRepo) - - dockerCmd(c, "run", "--name", "test", oldRepo, "touch", "/abcd") - - dockerCmd(c, "commit", "test", newTag) - - out, _ := dockerCmd(c, "rmi", newTag) - c.Assert(out, checker.Contains, "Untagged: "+newTag) -} - -func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *check.C) { - imageName := "rmiimage" - tag1 := imageName + ":tag1" - tag2 := imageName + ":tag2" - - _, err := buildImage(tag1, - `FROM busybox - MAINTAINER "docker"`, - true) - if err != nil { - c.Fatal(err) - } - - dockerCmd(c, "tag", tag1, tag2) - - out, _ := dockerCmd(c, "rmi", "-f", tag2) - c.Assert(out, checker.Contains, "Untagged: "+tag2) - c.Assert(out, checker.Not(checker.Contains), "Untagged: "+tag1) - - // Check built image still exists - images, _ := dockerCmd(c, "images", "-a") - c.Assert(images, checker.Contains, imageName, check.Commentf("Built image missing %q; Images: %q", imageName, images)) -} - -func (s *DockerSuite) TestRmiBlank(c *check.C) { - out, _, err := dockerCmdWithError("rmi", " ") - // Should have failed to delete ' ' image - c.Assert(err, checker.NotNil) - // Wrong error message generated - c.Assert(out, checker.Not(checker.Contains), "no such id", check.Commentf("out: %s", out)) - // Expected error message not generated - c.Assert(out, checker.Contains, "image name cannot be blank", check.Commentf("out: %s", out)) -} - -func (s *DockerSuite) TestRmiContainerImageNotFound(c *check.C) { - // Build 2 images for testing. - imageNames := []string{"test1", "test2"} - imageIds := make([]string, 2) - for i, name := range imageNames { - dockerfile := fmt.Sprintf("FROM busybox\nMAINTAINER %s\nRUN echo %s\n", name, name) - id, err := buildImage(name, dockerfile, false) - c.Assert(err, checker.IsNil) - imageIds[i] = id - } - - // Create a long-running container. - runSleepingContainerInImage(c, imageNames[0]) - - // Create a stopped container, and then force remove its image. - dockerCmd(c, "run", imageNames[1], "true") - dockerCmd(c, "rmi", "-f", imageIds[1]) - - // Try to remove the image of the running container and see if it fails as expected. - out, _, err := dockerCmdWithError("rmi", "-f", imageIds[0]) - // The image of the running container should not be removed. - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "image is being used by running container", check.Commentf("out: %s", out)) -} - -// #13422 -func (s *DockerSuite) TestRmiUntagHistoryLayer(c *check.C) { - image := "tmp1" - // Build an image for testing. - dockerfile := `FROM busybox -MAINTAINER foo -RUN echo 0 #layer0 -RUN echo 1 #layer1 -RUN echo 2 #layer2 -` - _, err := buildImage(image, dockerfile, false) - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "history", "-q", image) - ids := strings.Split(out, "\n") - idToTag := ids[2] - - // Tag layer0 to "tmp2". - newTag := "tmp2" - dockerCmd(c, "tag", idToTag, newTag) - // Create a container based on "tmp1". - dockerCmd(c, "run", "-d", image, "true") - - // See if the "tmp2" can be untagged. - out, _ = dockerCmd(c, "rmi", newTag) - // Expected 1 untagged entry - c.Assert(strings.Count(out, "Untagged: "), checker.Equals, 1, check.Commentf("out: %s", out)) - - // Now let's add the tag again and create a container based on it. - dockerCmd(c, "tag", idToTag, newTag) - out, _ = dockerCmd(c, "run", "-d", newTag, "true") - cid := strings.TrimSpace(out) - - // At this point we have 2 containers, one based on layer2 and another based on layer0. - // Try to untag "tmp2" without the -f flag. - out, _, err = dockerCmdWithError("rmi", newTag) - // should not be untagged without the -f flag - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, cid[:12]) - c.Assert(out, checker.Contains, "(must force)") - - // Add the -f flag and test again. - out, _ = dockerCmd(c, "rmi", "-f", newTag) - // should be allowed to untag with the -f flag - c.Assert(out, checker.Contains, fmt.Sprintf("Untagged: %s:latest", newTag)) -} - -func (*DockerSuite) TestRmiParentImageFail(c *check.C) { - _, err := buildImage("test", ` - FROM busybox - RUN echo hello`, false) - c.Assert(err, checker.IsNil) - - id := inspectField(c, "busybox", "ID") - out, _, err := dockerCmdWithError("rmi", id) - c.Assert(err, check.NotNil) - if !strings.Contains(out, "image has dependent child images") { - c.Fatalf("rmi should have failed because it's a parent image, got %s", out) - } -} - -func (s *DockerSuite) TestRmiWithParentInUse(c *check.C) { - out, _ := dockerCmd(c, "create", "busybox") - cID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "commit", cID) - imageID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "create", imageID) - cID = strings.TrimSpace(out) - - out, _ = dockerCmd(c, "commit", cID) - imageID = strings.TrimSpace(out) - - dockerCmd(c, "rmi", imageID) -} - -// #18873 -func (s *DockerSuite) TestRmiByIDHardConflict(c *check.C) { - dockerCmd(c, "create", "busybox") - - imgID := inspectField(c, "busybox:latest", "Id") - - _, _, err := dockerCmdWithError("rmi", imgID[:12]) - c.Assert(err, checker.NotNil) - - // check that tag was not removed - imgID2 := inspectField(c, "busybox:latest", "Id") - c.Assert(imgID, checker.Equals, imgID2) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_run_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_run_test.go deleted file mode 100644 index 9462aef..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_run_test.go +++ /dev/null @@ -1,4689 +0,0 @@ -package main - -import ( - "bufio" - "bytes" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net" - "os" - "os/exec" - "path" - "path/filepath" - "reflect" - "regexp" - "runtime" - "sort" - "strconv" - "strings" - "sync" - "time" - - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/stringutils" - "github.com/docker/docker/runconfig" - "github.com/docker/go-connections/nat" - "github.com/docker/libnetwork/resolvconf" - "github.com/docker/libnetwork/types" - "github.com/go-check/check" - libcontainerUser "github.com/opencontainers/runc/libcontainer/user" -) - -// "test123" should be printed by docker run -func (s *DockerSuite) TestRunEchoStdout(c *check.C) { - out, _ := dockerCmd(c, "run", "busybox", "echo", "test123") - if out != "test123\n" { - c.Fatalf("container should've printed 'test123', got '%s'", out) - } -} - -// "test" should be printed -func (s *DockerSuite) TestRunEchoNamedContainer(c *check.C) { - out, _ := dockerCmd(c, "run", "--name", "testfoonamedcontainer", "busybox", "echo", "test") - if out != "test\n" { - c.Errorf("container should've printed 'test'") - } -} - -// docker run should not leak file descriptors. This test relies on Unix -// specific functionality and cannot run on Windows. -func (s *DockerSuite) TestRunLeakyFileDescriptors(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "busybox", "ls", "-C", "/proc/self/fd") - - // normally, we should only get 0, 1, and 2, but 3 gets created by "ls" when it does "opendir" on the "fd" directory - if out != "0 1 2 3\n" { - c.Errorf("container should've printed '0 1 2 3', not: %s", out) - } -} - -// it should be possible to lookup Google DNS -// this will fail when Internet access is unavailable -func (s *DockerSuite) TestRunLookupGoogleDNS(c *check.C) { - testRequires(c, Network, NotArm) - if daemonPlatform == "windows" { - // nslookup isn't present in Windows busybox. Is built-in. Further, - // nslookup isn't present in nanoserver. Hence just use PowerShell... - dockerCmd(c, "run", WindowsBaseImage, "powershell", "Resolve-DNSName", "google.com") - } else { - dockerCmd(c, "run", DefaultImage, "nslookup", "google.com") - } - -} - -// the exit code should be 0 -func (s *DockerSuite) TestRunExitCodeZero(c *check.C) { - dockerCmd(c, "run", "busybox", "true") -} - -// the exit code should be 1 -func (s *DockerSuite) TestRunExitCodeOne(c *check.C) { - _, exitCode, err := dockerCmdWithError("run", "busybox", "false") - c.Assert(err, checker.NotNil) - c.Assert(exitCode, checker.Equals, 1) -} - -// it should be possible to pipe in data via stdin to a process running in a container -func (s *DockerSuite) TestRunStdinPipe(c *check.C) { - // TODO Windows: This needs some work to make compatible. - testRequires(c, DaemonIsLinux) - runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat") - runCmd.Stdin = strings.NewReader("blahblah") - out, _, _, err := runCommandWithStdoutStderr(runCmd) - if err != nil { - c.Fatalf("failed to run container: %v, output: %q", err, out) - } - - out = strings.TrimSpace(out) - dockerCmd(c, "wait", out) - - logsOut, _ := dockerCmd(c, "logs", out) - - containerLogs := strings.TrimSpace(logsOut) - if containerLogs != "blahblah" { - c.Errorf("logs didn't print the container's logs %s", containerLogs) - } - - dockerCmd(c, "rm", out) -} - -// the container's ID should be printed when starting a container in detached mode -func (s *DockerSuite) TestRunDetachedContainerIDPrinting(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") - - out = strings.TrimSpace(out) - dockerCmd(c, "wait", out) - - rmOut, _ := dockerCmd(c, "rm", out) - - rmOut = strings.TrimSpace(rmOut) - if rmOut != out { - c.Errorf("rm didn't print the container ID %s %s", out, rmOut) - } -} - -// the working directory should be set correctly -func (s *DockerSuite) TestRunWorkingDirectory(c *check.C) { - dir := "/root" - image := "busybox" - if daemonPlatform == "windows" { - dir = `C:/Windows` - } - - // First with -w - out, _ := dockerCmd(c, "run", "-w", dir, image, "pwd") - out = strings.TrimSpace(out) - if out != dir { - c.Errorf("-w failed to set working directory") - } - - // Then with --workdir - out, _ = dockerCmd(c, "run", "--workdir", dir, image, "pwd") - out = strings.TrimSpace(out) - if out != dir { - c.Errorf("--workdir failed to set working directory") - } -} - -// pinging Google's DNS resolver should fail when we disable the networking -func (s *DockerSuite) TestRunWithoutNetworking(c *check.C) { - count := "-c" - image := "busybox" - if daemonPlatform == "windows" { - count = "-n" - image = WindowsBaseImage - } - - // First using the long form --net - out, exitCode, err := dockerCmdWithError("run", "--net=none", image, "ping", count, "1", "8.8.8.8") - if err != nil && exitCode != 1 { - c.Fatal(out, err) - } - if exitCode != 1 { - c.Errorf("--net=none should've disabled the network; the container shouldn't have been able to ping 8.8.8.8") - } -} - -//test --link use container name to link target -func (s *DockerSuite) TestRunLinksContainerWithContainerName(c *check.C) { - // TODO Windows: This test cannot run on a Windows daemon as the networking - // settings are not populated back yet on inspect. - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-i", "-t", "-d", "--name", "parent", "busybox") - - ip := inspectField(c, "parent", "NetworkSettings.Networks.bridge.IPAddress") - - out, _ := dockerCmd(c, "run", "--link", "parent:test", "busybox", "/bin/cat", "/etc/hosts") - if !strings.Contains(out, ip+" test") { - c.Fatalf("use a container name to link target failed") - } -} - -//test --link use container id to link target -func (s *DockerSuite) TestRunLinksContainerWithContainerID(c *check.C) { - // TODO Windows: This test cannot run on a Windows daemon as the networking - // settings are not populated back yet on inspect. - testRequires(c, DaemonIsLinux) - cID, _ := dockerCmd(c, "run", "-i", "-t", "-d", "busybox") - - cID = strings.TrimSpace(cID) - ip := inspectField(c, cID, "NetworkSettings.Networks.bridge.IPAddress") - - out, _ := dockerCmd(c, "run", "--link", cID+":test", "busybox", "/bin/cat", "/etc/hosts") - if !strings.Contains(out, ip+" test") { - c.Fatalf("use a container id to link target failed") - } -} - -func (s *DockerSuite) TestUserDefinedNetworkLinks(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - dockerCmd(c, "network", "create", "-d", "bridge", "udlinkNet") - - dockerCmd(c, "run", "-d", "--net=udlinkNet", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - - // run a container in user-defined network udlinkNet with a link for an existing container - // and a link for a container that doesn't exist - dockerCmd(c, "run", "-d", "--net=udlinkNet", "--name=second", "--link=first:foo", - "--link=third:bar", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // ping to first and its alias foo must succeed - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo") - c.Assert(err, check.IsNil) - - // ping to third and its alias must fail - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "third") - c.Assert(err, check.NotNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "bar") - c.Assert(err, check.NotNil) - - // start third container now - dockerCmd(c, "run", "-d", "--net=udlinkNet", "--name=third", "busybox", "top") - c.Assert(waitRun("third"), check.IsNil) - - // ping to third and its alias must succeed now - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "third") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "bar") - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestUserDefinedNetworkLinksWithRestart(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - dockerCmd(c, "network", "create", "-d", "bridge", "udlinkNet") - - dockerCmd(c, "run", "-d", "--net=udlinkNet", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - - dockerCmd(c, "run", "-d", "--net=udlinkNet", "--name=second", "--link=first:foo", - "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // ping to first and its alias foo must succeed - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo") - c.Assert(err, check.IsNil) - - // Restart first container - dockerCmd(c, "restart", "first") - c.Assert(waitRun("first"), check.IsNil) - - // ping to first and its alias foo must still succeed - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo") - c.Assert(err, check.IsNil) - - // Restart second container - dockerCmd(c, "restart", "second") - c.Assert(waitRun("second"), check.IsNil) - - // ping to first and its alias foo must still succeed - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo") - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestRunWithNetAliasOnDefaultNetworks(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - - defaults := []string{"bridge", "host", "none"} - for _, net := range defaults { - out, _, err := dockerCmdWithError("run", "-d", "--net", net, "--net-alias", "alias_"+net, "busybox", "top") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error()) - } -} - -func (s *DockerSuite) TestUserDefinedNetworkAlias(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - dockerCmd(c, "network", "create", "-d", "bridge", "net1") - - cid1, _ := dockerCmd(c, "run", "-d", "--net=net1", "--name=first", "--net-alias=foo1", "--net-alias=foo2", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - - // Check if default short-id alias is added automatically - id := strings.TrimSpace(cid1) - aliases := inspectField(c, id, "NetworkSettings.Networks.net1.Aliases") - c.Assert(aliases, checker.Contains, stringid.TruncateID(id)) - - cid2, _ := dockerCmd(c, "run", "-d", "--net=net1", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // Check if default short-id alias is added automatically - id = strings.TrimSpace(cid2) - aliases = inspectField(c, id, "NetworkSettings.Networks.net1.Aliases") - c.Assert(aliases, checker.Contains, stringid.TruncateID(id)) - - // ping to first and its network-scoped aliases - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo1") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo2") - c.Assert(err, check.IsNil) - // ping first container's short-id alias - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", stringid.TruncateID(cid1)) - c.Assert(err, check.IsNil) - - // Restart first container - dockerCmd(c, "restart", "first") - c.Assert(waitRun("first"), check.IsNil) - - // ping to first and its network-scoped aliases must succeed - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo1") - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "foo2") - c.Assert(err, check.IsNil) - // ping first container's short-id alias - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", stringid.TruncateID(cid1)) - c.Assert(err, check.IsNil) -} - -// Issue 9677. -func (s *DockerSuite) TestRunWithDaemonFlags(c *check.C) { - out, _, err := dockerCmdWithError("--exec-opt", "foo=bar", "run", "-i", "busybox", "true") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "unknown flag: --exec-opt") -} - -// Regression test for #4979 -func (s *DockerSuite) TestRunWithVolumesFromExited(c *check.C) { - - var ( - out string - exitCode int - ) - - // Create a file in a volume - if daemonPlatform == "windows" { - out, exitCode = dockerCmd(c, "run", "--name", "test-data", "--volume", `c:\some\dir`, WindowsBaseImage, "cmd", "/c", `echo hello > c:\some\dir\file`) - } else { - out, exitCode = dockerCmd(c, "run", "--name", "test-data", "--volume", "/some/dir", "busybox", "touch", "/some/dir/file") - } - if exitCode != 0 { - c.Fatal("1", out, exitCode) - } - - // Read the file from another container using --volumes-from to access the volume in the second container - if daemonPlatform == "windows" { - out, exitCode = dockerCmd(c, "run", "--volumes-from", "test-data", WindowsBaseImage, "cmd", "/c", `type c:\some\dir\file`) - } else { - out, exitCode = dockerCmd(c, "run", "--volumes-from", "test-data", "busybox", "cat", "/some/dir/file") - } - if exitCode != 0 { - c.Fatal("2", out, exitCode) - } -} - -// Volume path is a symlink which also exists on the host, and the host side is a file not a dir -// But the volume call is just a normal volume, not a bind mount -func (s *DockerSuite) TestRunCreateVolumesInSymlinkDir(c *check.C) { - var ( - dockerFile string - containerPath string - cmd string - ) - // TODO Windows (Post TP5): This test cannot run on a Windows daemon as - // Windows does not support symlinks inside a volume path - testRequires(c, SameHostDaemon, DaemonIsLinux) - name := "test-volume-symlink" - - dir, err := ioutil.TempDir("", name) - if err != nil { - c.Fatal(err) - } - defer os.RemoveAll(dir) - - // In the case of Windows to Windows CI, if the machine is setup so that - // the temp directory is not the C: drive, this test is invalid and will - // not work. - if daemonPlatform == "windows" && strings.ToLower(dir[:1]) != "c" { - c.Skip("Requires TEMP to point to C: drive") - } - - f, err := os.OpenFile(filepath.Join(dir, "test"), os.O_CREATE, 0700) - if err != nil { - c.Fatal(err) - } - f.Close() - - if daemonPlatform == "windows" { - dockerFile = fmt.Sprintf("FROM %s\nRUN mkdir %s\nRUN mklink /D c:\\test %s", WindowsBaseImage, dir, dir) - containerPath = `c:\test\test` - cmd = "tasklist" - } else { - dockerFile = fmt.Sprintf("FROM busybox\nRUN mkdir -p %s\nRUN ln -s %s /test", dir, dir) - containerPath = "/test/test" - cmd = "true" - } - if _, err := buildImage(name, dockerFile, false); err != nil { - c.Fatal(err) - } - - dockerCmd(c, "run", "-v", containerPath, name, cmd) -} - -// Volume path is a symlink in the container -func (s *DockerSuite) TestRunCreateVolumesInSymlinkDir2(c *check.C) { - var ( - dockerFile string - containerPath string - cmd string - ) - // TODO Windows (Post TP5): This test cannot run on a Windows daemon as - // Windows does not support symlinks inside a volume path - testRequires(c, SameHostDaemon, DaemonIsLinux) - name := "test-volume-symlink2" - - if daemonPlatform == "windows" { - dockerFile = fmt.Sprintf("FROM %s\nRUN mkdir c:\\%s\nRUN mklink /D c:\\test c:\\%s", WindowsBaseImage, name, name) - containerPath = `c:\test\test` - cmd = "tasklist" - } else { - dockerFile = fmt.Sprintf("FROM busybox\nRUN mkdir -p /%s\nRUN ln -s /%s /test", name, name) - containerPath = "/test/test" - cmd = "true" - } - if _, err := buildImage(name, dockerFile, false); err != nil { - c.Fatal(err) - } - - dockerCmd(c, "run", "-v", containerPath, name, cmd) -} - -func (s *DockerSuite) TestRunVolumesMountedAsReadonly(c *check.C) { - // TODO Windows: Temporary check - remove once TP5 support is dropped - if daemonPlatform == "windows" && windowsDaemonKV < 14350 { - c.Skip("Needs later Windows build for RO volumes") - } - if _, code, err := dockerCmdWithError("run", "-v", "/test:/test:ro", "busybox", "touch", "/test/somefile"); err == nil || code == 0 { - c.Fatalf("run should fail because volume is ro: exit code %d", code) - } -} - -func (s *DockerSuite) TestRunVolumesFromInReadonlyModeFails(c *check.C) { - // TODO Windows: Temporary check - remove once TP5 support is dropped - if daemonPlatform == "windows" && windowsDaemonKV < 14350 { - c.Skip("Needs later Windows build for RO volumes") - } - var ( - volumeDir string - fileInVol string - ) - if daemonPlatform == "windows" { - volumeDir = `c:/test` // Forward-slash as using busybox - fileInVol = `c:/test/file` - } else { - testRequires(c, DaemonIsLinux) - volumeDir = "/test" - fileInVol = `/test/file` - } - dockerCmd(c, "run", "--name", "parent", "-v", volumeDir, "busybox", "true") - - if _, code, err := dockerCmdWithError("run", "--volumes-from", "parent:ro", "busybox", "touch", fileInVol); err == nil || code == 0 { - c.Fatalf("run should fail because volume is ro: exit code %d", code) - } -} - -// Regression test for #1201 -func (s *DockerSuite) TestRunVolumesFromInReadWriteMode(c *check.C) { - var ( - volumeDir string - fileInVol string - ) - if daemonPlatform == "windows" { - volumeDir = `c:/test` // Forward-slash as using busybox - fileInVol = `c:/test/file` - } else { - volumeDir = "/test" - fileInVol = "/test/file" - } - - dockerCmd(c, "run", "--name", "parent", "-v", volumeDir, "busybox", "true") - dockerCmd(c, "run", "--volumes-from", "parent:rw", "busybox", "touch", fileInVol) - - if out, _, err := dockerCmdWithError("run", "--volumes-from", "parent:bar", "busybox", "touch", fileInVol); err == nil || !strings.Contains(out, `invalid mode: bar`) { - c.Fatalf("running --volumes-from parent:bar should have failed with invalid mode: %q", out) - } - - dockerCmd(c, "run", "--volumes-from", "parent", "busybox", "touch", fileInVol) -} - -func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) { - testRequires(c, SameHostDaemon) - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - hostpath := randomTmpDirPath("test", daemonPlatform) - if err := os.MkdirAll(hostpath, 0755); err != nil { - c.Fatalf("Failed to create %s: %q", hostpath, err) - } - defer os.RemoveAll(hostpath) - - // TODO Windows: Temporary check - remove once TP5 support is dropped - if daemonPlatform == "windows" && windowsDaemonKV < 14350 { - c.Skip("Needs later Windows build for RO volumes") - } - dockerCmd(c, "run", "--name", "parent", "-v", hostpath+":"+prefix+slash+"test:ro", "busybox", "true") - - // Expect this "rw" mode to be be ignored since the inherited volume is "ro" - if _, _, err := dockerCmdWithError("run", "--volumes-from", "parent:rw", "busybox", "touch", prefix+slash+"test"+slash+"file"); err == nil { - c.Fatal("Expected volumes-from to inherit read-only volume even when passing in `rw`") - } - - dockerCmd(c, "run", "--name", "parent2", "-v", hostpath+":"+prefix+slash+"test:ro", "busybox", "true") - - // Expect this to be read-only since both are "ro" - if _, _, err := dockerCmdWithError("run", "--volumes-from", "parent2:ro", "busybox", "touch", prefix+slash+"test"+slash+"file"); err == nil { - c.Fatal("Expected volumes-from to inherit read-only volume even when passing in `ro`") - } -} - -// Test for GH#10618 -func (s *DockerSuite) TestRunNoDupVolumes(c *check.C) { - path1 := randomTmpDirPath("test1", daemonPlatform) - path2 := randomTmpDirPath("test2", daemonPlatform) - - someplace := ":/someplace" - if daemonPlatform == "windows" { - // Windows requires that the source directory exists before calling HCS - testRequires(c, SameHostDaemon) - someplace = `:c:\someplace` - if err := os.MkdirAll(path1, 0755); err != nil { - c.Fatalf("Failed to create %s: %q", path1, err) - } - defer os.RemoveAll(path1) - if err := os.MkdirAll(path2, 0755); err != nil { - c.Fatalf("Failed to create %s: %q", path1, err) - } - defer os.RemoveAll(path2) - } - mountstr1 := path1 + someplace - mountstr2 := path2 + someplace - - if out, _, err := dockerCmdWithError("run", "-v", mountstr1, "-v", mountstr2, "busybox", "true"); err == nil { - c.Fatal("Expected error about duplicate mount definitions") - } else { - if !strings.Contains(out, "Duplicate mount point") { - c.Fatalf("Expected 'duplicate mount point' error, got %v", out) - } - } - - // Test for https://github.com/docker/docker/issues/22093 - volumename1 := "test1" - volumename2 := "test2" - volume1 := volumename1 + someplace - volume2 := volumename2 + someplace - if out, _, err := dockerCmdWithError("run", "-v", volume1, "-v", volume2, "busybox", "true"); err == nil { - c.Fatal("Expected error about duplicate mount definitions") - } else { - if !strings.Contains(out, "Duplicate mount point") { - c.Fatalf("Expected 'duplicate mount point' error, got %v", out) - } - } - // create failed should have create volume volumename1 or volumename2 - // we should remove volumename2 or volumename2 successfully - out, _ := dockerCmd(c, "volume", "ls") - if strings.Contains(out, volumename1) { - dockerCmd(c, "volume", "rm", volumename1) - } else { - dockerCmd(c, "volume", "rm", volumename2) - } -} - -// Test for #1351 -func (s *DockerSuite) TestRunApplyVolumesFromBeforeVolumes(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = `c:` - } - dockerCmd(c, "run", "--name", "parent", "-v", prefix+"/test", "busybox", "touch", prefix+"/test/foo") - dockerCmd(c, "run", "--volumes-from", "parent", "-v", prefix+"/test", "busybox", "cat", prefix+"/test/foo") -} - -func (s *DockerSuite) TestRunMultipleVolumesFrom(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = `c:` - } - dockerCmd(c, "run", "--name", "parent1", "-v", prefix+"/test", "busybox", "touch", prefix+"/test/foo") - dockerCmd(c, "run", "--name", "parent2", "-v", prefix+"/other", "busybox", "touch", prefix+"/other/bar") - dockerCmd(c, "run", "--volumes-from", "parent1", "--volumes-from", "parent2", "busybox", "sh", "-c", "cat /test/foo && cat /other/bar") -} - -// this tests verifies the ID format for the container -func (s *DockerSuite) TestRunVerifyContainerID(c *check.C) { - out, exit, err := dockerCmdWithError("run", "-d", "busybox", "true") - if err != nil { - c.Fatal(err) - } - if exit != 0 { - c.Fatalf("expected exit code 0 received %d", exit) - } - - match, err := regexp.MatchString("^[0-9a-f]{64}$", strings.TrimSuffix(out, "\n")) - if err != nil { - c.Fatal(err) - } - if !match { - c.Fatalf("Invalid container ID: %s", out) - } -} - -// Test that creating a container with a volume doesn't crash. Regression test for #995. -func (s *DockerSuite) TestRunCreateVolume(c *check.C) { - prefix := "" - if daemonPlatform == "windows" { - prefix = `c:` - } - dockerCmd(c, "run", "-v", prefix+"/var/lib/data", "busybox", "true") -} - -// Test that creating a volume with a symlink in its path works correctly. Test for #5152. -// Note that this bug happens only with symlinks with a target that starts with '/'. -func (s *DockerSuite) TestRunCreateVolumeWithSymlink(c *check.C) { - // Cannot run on Windows as relies on Linux-specific functionality (sh -c mount...) - testRequires(c, DaemonIsLinux) - image := "docker-test-createvolumewithsymlink" - - buildCmd := exec.Command(dockerBinary, "build", "-t", image, "-") - buildCmd.Stdin = strings.NewReader(`FROM busybox - RUN ln -s home /bar`) - buildCmd.Dir = workingDirectory - err := buildCmd.Run() - if err != nil { - c.Fatalf("could not build '%s': %v", image, err) - } - - _, exitCode, err := dockerCmdWithError("run", "-v", "/bar/foo", "--name", "test-createvolumewithsymlink", image, "sh", "-c", "mount | grep -q /home/foo") - if err != nil || exitCode != 0 { - c.Fatalf("[run] err: %v, exitcode: %d", err, exitCode) - } - - volPath, err := inspectMountSourceField("test-createvolumewithsymlink", "/bar/foo") - c.Assert(err, checker.IsNil) - - _, exitCode, err = dockerCmdWithError("rm", "-v", "test-createvolumewithsymlink") - if err != nil || exitCode != 0 { - c.Fatalf("[rm] err: %v, exitcode: %d", err, exitCode) - } - - _, err = os.Stat(volPath) - if !os.IsNotExist(err) { - c.Fatalf("[open] (expecting 'file does not exist' error) err: %v, volPath: %s", err, volPath) - } -} - -// Tests that a volume path that has a symlink exists in a container mounting it with `--volumes-from`. -func (s *DockerSuite) TestRunVolumesFromSymlinkPath(c *check.C) { - // TODO Windows (Post TP5): This test cannot run on a Windows daemon as - // Windows does not support symlinks inside a volume path - testRequires(c, DaemonIsLinux) - name := "docker-test-volumesfromsymlinkpath" - prefix := "" - dfContents := `FROM busybox - RUN ln -s home /foo - VOLUME ["/foo/bar"]` - - if daemonPlatform == "windows" { - prefix = `c:` - dfContents = `FROM ` + WindowsBaseImage + ` - RUN mkdir c:\home - RUN mklink /D c:\foo c:\home - VOLUME ["c:/foo/bar"] - ENTRYPOINT c:\windows\system32\cmd.exe` - } - - buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-") - buildCmd.Stdin = strings.NewReader(dfContents) - buildCmd.Dir = workingDirectory - err := buildCmd.Run() - if err != nil { - c.Fatalf("could not build 'docker-test-volumesfromsymlinkpath': %v", err) - } - - out, exitCode, err := dockerCmdWithError("run", "--name", "test-volumesfromsymlinkpath", name) - if err != nil || exitCode != 0 { - c.Fatalf("[run] (volume) err: %v, exitcode: %d, out: %s", err, exitCode, out) - } - - _, exitCode, err = dockerCmdWithError("run", "--volumes-from", "test-volumesfromsymlinkpath", "busybox", "sh", "-c", "ls "+prefix+"/foo | grep -q bar") - if err != nil || exitCode != 0 { - c.Fatalf("[run] err: %v, exitcode: %d", err, exitCode) - } -} - -func (s *DockerSuite) TestRunExitCode(c *check.C) { - var ( - exit int - err error - ) - - _, exit, err = dockerCmdWithError("run", "busybox", "/bin/sh", "-c", "exit 72") - - if err == nil { - c.Fatal("should not have a non nil error") - } - if exit != 72 { - c.Fatalf("expected exit code 72 received %d", exit) - } -} - -func (s *DockerSuite) TestRunUserDefaults(c *check.C) { - expected := "uid=0(root) gid=0(root)" - if daemonPlatform == "windows" { - expected = "uid=1000(ContainerAdministrator) gid=1000(ContainerAdministrator)" - } - out, _ := dockerCmd(c, "run", "busybox", "id") - if !strings.Contains(out, expected) { - c.Fatalf("expected '%s' got %s", expected, out) - } -} - -func (s *DockerSuite) TestRunUserByName(c *check.C) { - // TODO Windows: This test cannot run on a Windows daemon as Windows does - // not support the use of -u - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-u", "root", "busybox", "id") - if !strings.Contains(out, "uid=0(root) gid=0(root)") { - c.Fatalf("expected root user got %s", out) - } -} - -func (s *DockerSuite) TestRunUserByID(c *check.C) { - // TODO Windows: This test cannot run on a Windows daemon as Windows does - // not support the use of -u - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-u", "1", "busybox", "id") - if !strings.Contains(out, "uid=1(daemon) gid=1(daemon)") { - c.Fatalf("expected daemon user got %s", out) - } -} - -func (s *DockerSuite) TestRunUserByIDBig(c *check.C) { - // TODO Windows: This test cannot run on a Windows daemon as Windows does - // not support the use of -u - testRequires(c, DaemonIsLinux, NotArm) - out, _, err := dockerCmdWithError("run", "-u", "2147483648", "busybox", "id") - if err == nil { - c.Fatal("No error, but must be.", out) - } - if !strings.Contains(strings.ToUpper(out), strings.ToUpper(libcontainerUser.ErrRange.Error())) { - c.Fatalf("expected error about uids range, got %s", out) - } -} - -func (s *DockerSuite) TestRunUserByIDNegative(c *check.C) { - // TODO Windows: This test cannot run on a Windows daemon as Windows does - // not support the use of -u - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "-u", "-1", "busybox", "id") - if err == nil { - c.Fatal("No error, but must be.", out) - } - if !strings.Contains(strings.ToUpper(out), strings.ToUpper(libcontainerUser.ErrRange.Error())) { - c.Fatalf("expected error about uids range, got %s", out) - } -} - -func (s *DockerSuite) TestRunUserByIDZero(c *check.C) { - // TODO Windows: This test cannot run on a Windows daemon as Windows does - // not support the use of -u - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "-u", "0", "busybox", "id") - if err != nil { - c.Fatal(err, out) - } - if !strings.Contains(out, "uid=0(root) gid=0(root) groups=10(wheel)") { - c.Fatalf("expected daemon user got %s", out) - } -} - -func (s *DockerSuite) TestRunUserNotFound(c *check.C) { - // TODO Windows: This test cannot run on a Windows daemon as Windows does - // not support the use of -u - testRequires(c, DaemonIsLinux) - _, _, err := dockerCmdWithError("run", "-u", "notme", "busybox", "id") - if err == nil { - c.Fatal("unknown user should cause container to fail") - } -} - -func (s *DockerSuite) TestRunTwoConcurrentContainers(c *check.C) { - sleepTime := "2" - group := sync.WaitGroup{} - group.Add(2) - - errChan := make(chan error, 2) - for i := 0; i < 2; i++ { - go func() { - defer group.Done() - _, _, err := dockerCmdWithError("run", "busybox", "sleep", sleepTime) - errChan <- err - }() - } - - group.Wait() - close(errChan) - - for err := range errChan { - c.Assert(err, check.IsNil) - } -} - -func (s *DockerSuite) TestRunEnvironment(c *check.C) { - // TODO Windows: Environment handling is different between Linux and - // Windows and this test relies currently on unix functionality. - testRequires(c, DaemonIsLinux) - cmd := exec.Command(dockerBinary, "run", "-h", "testing", "-e=FALSE=true", "-e=TRUE", "-e=TRICKY", "-e=HOME=", "busybox", "env") - cmd.Env = append(os.Environ(), - "TRUE=false", - "TRICKY=tri\ncky\n", - ) - - out, _, err := runCommandWithOutput(cmd) - if err != nil { - c.Fatal(err, out) - } - - actualEnv := strings.Split(strings.TrimSpace(out), "\n") - sort.Strings(actualEnv) - - goodEnv := []string{ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", - "HOSTNAME=testing", - "FALSE=true", - "TRUE=false", - "TRICKY=tri", - "cky", - "", - "HOME=/root", - } - sort.Strings(goodEnv) - if len(goodEnv) != len(actualEnv) { - c.Fatalf("Wrong environment: should be %d variables, not %d: %q", len(goodEnv), len(actualEnv), strings.Join(actualEnv, ", ")) - } - for i := range goodEnv { - if actualEnv[i] != goodEnv[i] { - c.Fatalf("Wrong environment variable: should be %s, not %s", goodEnv[i], actualEnv[i]) - } - } -} - -func (s *DockerSuite) TestRunEnvironmentErase(c *check.C) { - // TODO Windows: Environment handling is different between Linux and - // Windows and this test relies currently on unix functionality. - testRequires(c, DaemonIsLinux) - - // Test to make sure that when we use -e on env vars that are - // not set in our local env that they're removed (if present) in - // the container - - cmd := exec.Command(dockerBinary, "run", "-e", "FOO", "-e", "HOSTNAME", "busybox", "env") - cmd.Env = appendBaseEnv(true) - - out, _, err := runCommandWithOutput(cmd) - if err != nil { - c.Fatal(err, out) - } - - actualEnv := strings.Split(strings.TrimSpace(out), "\n") - sort.Strings(actualEnv) - - goodEnv := []string{ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", - "HOME=/root", - } - sort.Strings(goodEnv) - if len(goodEnv) != len(actualEnv) { - c.Fatalf("Wrong environment: should be %d variables, not %d: %q", len(goodEnv), len(actualEnv), strings.Join(actualEnv, ", ")) - } - for i := range goodEnv { - if actualEnv[i] != goodEnv[i] { - c.Fatalf("Wrong environment variable: should be %s, not %s", goodEnv[i], actualEnv[i]) - } - } -} - -func (s *DockerSuite) TestRunEnvironmentOverride(c *check.C) { - // TODO Windows: Environment handling is different between Linux and - // Windows and this test relies currently on unix functionality. - testRequires(c, DaemonIsLinux) - - // Test to make sure that when we use -e on env vars that are - // already in the env that we're overriding them - - cmd := exec.Command(dockerBinary, "run", "-e", "HOSTNAME", "-e", "HOME=/root2", "busybox", "env") - cmd.Env = appendBaseEnv(true, "HOSTNAME=bar") - - out, _, err := runCommandWithOutput(cmd) - if err != nil { - c.Fatal(err, out) - } - - actualEnv := strings.Split(strings.TrimSpace(out), "\n") - sort.Strings(actualEnv) - - goodEnv := []string{ - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", - "HOME=/root2", - "HOSTNAME=bar", - } - sort.Strings(goodEnv) - if len(goodEnv) != len(actualEnv) { - c.Fatalf("Wrong environment: should be %d variables, not %d: %q", len(goodEnv), len(actualEnv), strings.Join(actualEnv, ", ")) - } - for i := range goodEnv { - if actualEnv[i] != goodEnv[i] { - c.Fatalf("Wrong environment variable: should be %s, not %s", goodEnv[i], actualEnv[i]) - } - } -} - -func (s *DockerSuite) TestRunContainerNetwork(c *check.C) { - if daemonPlatform == "windows" { - // Windows busybox does not have ping. Use built in ping instead. - dockerCmd(c, "run", WindowsBaseImage, "ping", "-n", "1", "127.0.0.1") - } else { - dockerCmd(c, "run", "busybox", "ping", "-c", "1", "127.0.0.1") - } -} - -func (s *DockerSuite) TestRunNetHostNotAllowedWithLinks(c *check.C) { - // TODO Windows: This is Linux specific as --link is not supported and - // this will be deprecated in favor of container networking model. - testRequires(c, DaemonIsLinux, NotUserNamespace) - dockerCmd(c, "run", "--name", "linked", "busybox", "true") - - _, _, err := dockerCmdWithError("run", "--net=host", "--link", "linked:linked", "busybox", "true") - if err == nil { - c.Fatal("Expected error") - } -} - -// #7851 hostname outside container shows FQDN, inside only shortname -// For testing purposes it is not required to set host's hostname directly -// and use "--net=host" (as the original issue submitter did), as the same -// codepath is executed with "docker run -h ". Both were manually -// tested, but this testcase takes the simpler path of using "run -h .." -func (s *DockerSuite) TestRunFullHostnameSet(c *check.C) { - // TODO Windows: -h is not yet functional. - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-h", "foo.bar.baz", "busybox", "hostname") - if actual := strings.Trim(out, "\r\n"); actual != "foo.bar.baz" { - c.Fatalf("expected hostname 'foo.bar.baz', received %s", actual) - } -} - -func (s *DockerSuite) TestRunPrivilegedCanMknod(c *check.C) { - // Not applicable for Windows as Windows daemon does not support - // the concept of --privileged, and mknod is a Unix concept. - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "--privileged", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok") - if actual := strings.Trim(out, "\r\n"); actual != "ok" { - c.Fatalf("expected output ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunUnprivilegedCanMknod(c *check.C) { - // Not applicable for Windows as Windows daemon does not support - // the concept of --privileged, and mknod is a Unix concept. - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok") - if actual := strings.Trim(out, "\r\n"); actual != "ok" { - c.Fatalf("expected output ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunCapDropInvalid(c *check.C) { - // Not applicable for Windows as there is no concept of --cap-drop - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "--cap-drop=CHPASS", "busybox", "ls") - if err == nil { - c.Fatal(err, out) - } -} - -func (s *DockerSuite) TestRunCapDropCannotMknod(c *check.C) { - // Not applicable for Windows as there is no concept of --cap-drop or mknod - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "--cap-drop=MKNOD", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok") - - if err == nil { - c.Fatal(err, out) - } - if actual := strings.Trim(out, "\r\n"); actual == "ok" { - c.Fatalf("expected output not ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunCapDropCannotMknodLowerCase(c *check.C) { - // Not applicable for Windows as there is no concept of --cap-drop or mknod - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "--cap-drop=mknod", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok") - - if err == nil { - c.Fatal(err, out) - } - if actual := strings.Trim(out, "\r\n"); actual == "ok" { - c.Fatalf("expected output not ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunCapDropALLCannotMknod(c *check.C) { - // Not applicable for Windows as there is no concept of --cap-drop or mknod - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "--cap-drop=ALL", "--cap-add=SETGID", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok") - if err == nil { - c.Fatal(err, out) - } - if actual := strings.Trim(out, "\r\n"); actual == "ok" { - c.Fatalf("expected output not ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunCapDropALLAddMknodCanMknod(c *check.C) { - // Not applicable for Windows as there is no concept of --cap-drop or mknod - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "--cap-drop=ALL", "--cap-add=MKNOD", "--cap-add=SETGID", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok") - - if actual := strings.Trim(out, "\r\n"); actual != "ok" { - c.Fatalf("expected output ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunCapAddInvalid(c *check.C) { - // Not applicable for Windows as there is no concept of --cap-add - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "--cap-add=CHPASS", "busybox", "ls") - if err == nil { - c.Fatal(err, out) - } -} - -func (s *DockerSuite) TestRunCapAddCanDownInterface(c *check.C) { - // Not applicable for Windows as there is no concept of --cap-add - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "--cap-add=NET_ADMIN", "busybox", "sh", "-c", "ip link set eth0 down && echo ok") - - if actual := strings.Trim(out, "\r\n"); actual != "ok" { - c.Fatalf("expected output ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunCapAddALLCanDownInterface(c *check.C) { - // Not applicable for Windows as there is no concept of --cap-add - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "--cap-add=ALL", "busybox", "sh", "-c", "ip link set eth0 down && echo ok") - - if actual := strings.Trim(out, "\r\n"); actual != "ok" { - c.Fatalf("expected output ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunCapAddALLDropNetAdminCanDownInterface(c *check.C) { - // Not applicable for Windows as there is no concept of --cap-add - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "--cap-add=ALL", "--cap-drop=NET_ADMIN", "busybox", "sh", "-c", "ip link set eth0 down && echo ok") - if err == nil { - c.Fatal(err, out) - } - if actual := strings.Trim(out, "\r\n"); actual == "ok" { - c.Fatalf("expected output not ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunGroupAdd(c *check.C) { - // Not applicable for Windows as there is no concept of --group-add - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "--group-add=audio", "--group-add=staff", "--group-add=777", "busybox", "sh", "-c", "id") - - groupsList := "uid=0(root) gid=0(root) groups=10(wheel),29(audio),50(staff),777" - if actual := strings.Trim(out, "\r\n"); actual != groupsList { - c.Fatalf("expected output %s received %s", groupsList, actual) - } -} - -func (s *DockerSuite) TestRunPrivilegedCanMount(c *check.C) { - // Not applicable for Windows as there is no concept of --privileged - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "--privileged", "busybox", "sh", "-c", "mount -t tmpfs none /tmp && echo ok") - - if actual := strings.Trim(out, "\r\n"); actual != "ok" { - c.Fatalf("expected output ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunUnprivilegedCannotMount(c *check.C) { - // Not applicable for Windows as there is no concept of unprivileged - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "busybox", "sh", "-c", "mount -t tmpfs none /tmp && echo ok") - - if err == nil { - c.Fatal(err, out) - } - if actual := strings.Trim(out, "\r\n"); actual == "ok" { - c.Fatalf("expected output not ok received %s", actual) - } -} - -func (s *DockerSuite) TestRunSysNotWritableInNonPrivilegedContainers(c *check.C) { - // Not applicable for Windows as there is no concept of unprivileged - testRequires(c, DaemonIsLinux, NotArm) - if _, code, err := dockerCmdWithError("run", "busybox", "touch", "/sys/kernel/profiling"); err == nil || code == 0 { - c.Fatal("sys should not be writable in a non privileged container") - } -} - -func (s *DockerSuite) TestRunSysWritableInPrivilegedContainers(c *check.C) { - // Not applicable for Windows as there is no concept of unprivileged - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - if _, code, err := dockerCmdWithError("run", "--privileged", "busybox", "touch", "/sys/kernel/profiling"); err != nil || code != 0 { - c.Fatalf("sys should be writable in privileged container") - } -} - -func (s *DockerSuite) TestRunProcNotWritableInNonPrivilegedContainers(c *check.C) { - // Not applicable for Windows as there is no concept of unprivileged - testRequires(c, DaemonIsLinux) - if _, code, err := dockerCmdWithError("run", "busybox", "touch", "/proc/sysrq-trigger"); err == nil || code == 0 { - c.Fatal("proc should not be writable in a non privileged container") - } -} - -func (s *DockerSuite) TestRunProcWritableInPrivilegedContainers(c *check.C) { - // Not applicable for Windows as there is no concept of --privileged - testRequires(c, DaemonIsLinux, NotUserNamespace) - if _, code := dockerCmd(c, "run", "--privileged", "busybox", "sh", "-c", "touch /proc/sysrq-trigger"); code != 0 { - c.Fatalf("proc should be writable in privileged container") - } -} - -func (s *DockerSuite) TestRunDeviceNumbers(c *check.C) { - // Not applicable on Windows as /dev/ is a Unix specific concept - // TODO: NotUserNamespace could be removed here if "root" "root" is replaced w user - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "busybox", "sh", "-c", "ls -l /dev/null") - deviceLineFields := strings.Fields(out) - deviceLineFields[6] = "" - deviceLineFields[7] = "" - deviceLineFields[8] = "" - expected := []string{"crw-rw-rw-", "1", "root", "root", "1,", "3", "", "", "", "/dev/null"} - - if !(reflect.DeepEqual(deviceLineFields, expected)) { - c.Fatalf("expected output\ncrw-rw-rw- 1 root root 1, 3 May 24 13:29 /dev/null\n received\n %s\n", out) - } -} - -func (s *DockerSuite) TestRunThatCharacterDevicesActLikeCharacterDevices(c *check.C) { - // Not applicable on Windows as /dev/ is a Unix specific concept - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "busybox", "sh", "-c", "dd if=/dev/zero of=/zero bs=1k count=5 2> /dev/null ; du -h /zero") - if actual := strings.Trim(out, "\r\n"); actual[0] == '0' { - c.Fatalf("expected a new file called /zero to be create that is greater than 0 bytes long, but du says: %s", actual) - } -} - -func (s *DockerSuite) TestRunUnprivilegedWithChroot(c *check.C) { - // Not applicable on Windows as it does not support chroot - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "busybox", "chroot", "/", "true") -} - -func (s *DockerSuite) TestRunAddingOptionalDevices(c *check.C) { - // Not applicable on Windows as Windows does not support --device - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "--device", "/dev/zero:/dev/nulo", "busybox", "sh", "-c", "ls /dev/nulo") - if actual := strings.Trim(out, "\r\n"); actual != "/dev/nulo" { - c.Fatalf("expected output /dev/nulo, received %s", actual) - } -} - -func (s *DockerSuite) TestRunAddingOptionalDevicesNoSrc(c *check.C) { - // Not applicable on Windows as Windows does not support --device - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "--device", "/dev/zero:rw", "busybox", "sh", "-c", "ls /dev/zero") - if actual := strings.Trim(out, "\r\n"); actual != "/dev/zero" { - c.Fatalf("expected output /dev/zero, received %s", actual) - } -} - -func (s *DockerSuite) TestRunAddingOptionalDevicesInvalidMode(c *check.C) { - // Not applicable on Windows as Windows does not support --device - testRequires(c, DaemonIsLinux, NotUserNamespace) - _, _, err := dockerCmdWithError("run", "--device", "/dev/zero:ro", "busybox", "sh", "-c", "ls /dev/zero") - if err == nil { - c.Fatalf("run container with device mode ro should fail") - } -} - -func (s *DockerSuite) TestRunModeHostname(c *check.C) { - // Not applicable on Windows as Windows does not support -h - testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - - out, _ := dockerCmd(c, "run", "-h=testhostname", "busybox", "cat", "/etc/hostname") - - if actual := strings.Trim(out, "\r\n"); actual != "testhostname" { - c.Fatalf("expected 'testhostname', but says: %q", actual) - } - - out, _ = dockerCmd(c, "run", "--net=host", "busybox", "cat", "/etc/hostname") - - hostname, err := os.Hostname() - if err != nil { - c.Fatal(err) - } - if actual := strings.Trim(out, "\r\n"); actual != hostname { - c.Fatalf("expected %q, but says: %q", hostname, actual) - } -} - -func (s *DockerSuite) TestRunRootWorkdir(c *check.C) { - out, _ := dockerCmd(c, "run", "--workdir", "/", "busybox", "pwd") - expected := "/\n" - if daemonPlatform == "windows" { - expected = "C:" + expected - } - if out != expected { - c.Fatalf("pwd returned %q (expected %s)", s, expected) - } -} - -func (s *DockerSuite) TestRunAllowBindMountingRoot(c *check.C) { - if daemonPlatform == "windows" { - // Windows busybox will fail with Permission Denied on items such as pagefile.sys - dockerCmd(c, "run", "-v", `c:\:c:\host`, WindowsBaseImage, "cmd", "-c", "dir", `c:\host`) - } else { - dockerCmd(c, "run", "-v", "/:/host", "busybox", "ls", "/host") - } -} - -func (s *DockerSuite) TestRunDisallowBindMountingRootToRoot(c *check.C) { - mount := "/:/" - targetDir := "/host" - if daemonPlatform == "windows" { - mount = `c:\:c\` - targetDir = "c:/host" // Forward slash as using busybox - } - out, _, err := dockerCmdWithError("run", "-v", mount, "busybox", "ls", targetDir) - if err == nil { - c.Fatal(out, err) - } -} - -// Verify that a container gets default DNS when only localhost resolvers exist -func (s *DockerSuite) TestRunDNSDefaultOptions(c *check.C) { - // Not applicable on Windows as this is testing Unix specific functionality - testRequires(c, SameHostDaemon, DaemonIsLinux) - - // preserve original resolv.conf for restoring after test - origResolvConf, err := ioutil.ReadFile("/etc/resolv.conf") - if os.IsNotExist(err) { - c.Fatalf("/etc/resolv.conf does not exist") - } - // defer restored original conf - defer func() { - if err := ioutil.WriteFile("/etc/resolv.conf", origResolvConf, 0644); err != nil { - c.Fatal(err) - } - }() - - // test 3 cases: standard IPv4 localhost, commented out localhost, and IPv6 localhost - // 2 are removed from the file at container start, and the 3rd (commented out) one is ignored by - // GetNameservers(), leading to a replacement of nameservers with the default set - tmpResolvConf := []byte("nameserver 127.0.0.1\n#nameserver 127.0.2.1\nnameserver ::1") - if err := ioutil.WriteFile("/etc/resolv.conf", tmpResolvConf, 0644); err != nil { - c.Fatal(err) - } - - actual, _ := dockerCmd(c, "run", "busybox", "cat", "/etc/resolv.conf") - // check that the actual defaults are appended to the commented out - // localhost resolver (which should be preserved) - // NOTE: if we ever change the defaults from google dns, this will break - expected := "#nameserver 127.0.2.1\n\nnameserver 8.8.8.8\nnameserver 8.8.4.4\n" - if actual != expected { - c.Fatalf("expected resolv.conf be: %q, but was: %q", expected, actual) - } -} - -func (s *DockerSuite) TestRunDNSOptions(c *check.C) { - // Not applicable on Windows as Windows does not support --dns*, or - // the Unix-specific functionality of resolv.conf. - testRequires(c, DaemonIsLinux) - out, stderr, _ := dockerCmdWithStdoutStderr(c, "run", "--dns=127.0.0.1", "--dns-search=mydomain", "--dns-opt=ndots:9", "busybox", "cat", "/etc/resolv.conf") - - // The client will get a warning on stderr when setting DNS to a localhost address; verify this: - if !strings.Contains(stderr, "Localhost DNS setting") { - c.Fatalf("Expected warning on stderr about localhost resolver, but got %q", stderr) - } - - actual := strings.Replace(strings.Trim(out, "\r\n"), "\n", " ", -1) - if actual != "search mydomain nameserver 127.0.0.1 options ndots:9" { - c.Fatalf("expected 'search mydomain nameserver 127.0.0.1 options ndots:9', but says: %q", actual) - } - - out, stderr, _ = dockerCmdWithStdoutStderr(c, "run", "--dns=127.0.0.1", "--dns-search=.", "--dns-opt=ndots:3", "busybox", "cat", "/etc/resolv.conf") - - actual = strings.Replace(strings.Trim(strings.Trim(out, "\r\n"), " "), "\n", " ", -1) - if actual != "nameserver 127.0.0.1 options ndots:3" { - c.Fatalf("expected 'nameserver 127.0.0.1 options ndots:3', but says: %q", actual) - } -} - -func (s *DockerSuite) TestRunDNSRepeatOptions(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _, _ := dockerCmdWithStdoutStderr(c, "run", "--dns=1.1.1.1", "--dns=2.2.2.2", "--dns-search=mydomain", "--dns-search=mydomain2", "--dns-opt=ndots:9", "--dns-opt=timeout:3", "busybox", "cat", "/etc/resolv.conf") - - actual := strings.Replace(strings.Trim(out, "\r\n"), "\n", " ", -1) - if actual != "search mydomain mydomain2 nameserver 1.1.1.1 nameserver 2.2.2.2 options ndots:9 timeout:3" { - c.Fatalf("expected 'search mydomain mydomain2 nameserver 1.1.1.1 nameserver 2.2.2.2 options ndots:9 timeout:3', but says: %q", actual) - } -} - -func (s *DockerSuite) TestRunDNSOptionsBasedOnHostResolvConf(c *check.C) { - // Not applicable on Windows as testing Unix specific functionality - testRequires(c, SameHostDaemon, DaemonIsLinux) - - origResolvConf, err := ioutil.ReadFile("/etc/resolv.conf") - if os.IsNotExist(err) { - c.Fatalf("/etc/resolv.conf does not exist") - } - - hostNameservers := resolvconf.GetNameservers(origResolvConf, types.IP) - hostSearch := resolvconf.GetSearchDomains(origResolvConf) - - var out string - out, _ = dockerCmd(c, "run", "--dns=127.0.0.1", "busybox", "cat", "/etc/resolv.conf") - - if actualNameservers := resolvconf.GetNameservers([]byte(out), types.IP); string(actualNameservers[0]) != "127.0.0.1" { - c.Fatalf("expected '127.0.0.1', but says: %q", string(actualNameservers[0])) - } - - actualSearch := resolvconf.GetSearchDomains([]byte(out)) - if len(actualSearch) != len(hostSearch) { - c.Fatalf("expected %q search domain(s), but it has: %q", len(hostSearch), len(actualSearch)) - } - for i := range actualSearch { - if actualSearch[i] != hostSearch[i] { - c.Fatalf("expected %q domain, but says: %q", actualSearch[i], hostSearch[i]) - } - } - - out, _ = dockerCmd(c, "run", "--dns-search=mydomain", "busybox", "cat", "/etc/resolv.conf") - - actualNameservers := resolvconf.GetNameservers([]byte(out), types.IP) - if len(actualNameservers) != len(hostNameservers) { - c.Fatalf("expected %q nameserver(s), but it has: %q", len(hostNameservers), len(actualNameservers)) - } - for i := range actualNameservers { - if actualNameservers[i] != hostNameservers[i] { - c.Fatalf("expected %q nameserver, but says: %q", actualNameservers[i], hostNameservers[i]) - } - } - - if actualSearch = resolvconf.GetSearchDomains([]byte(out)); string(actualSearch[0]) != "mydomain" { - c.Fatalf("expected 'mydomain', but says: %q", string(actualSearch[0])) - } - - // test with file - tmpResolvConf := []byte("search example.com\nnameserver 12.34.56.78\nnameserver 127.0.0.1") - if err := ioutil.WriteFile("/etc/resolv.conf", tmpResolvConf, 0644); err != nil { - c.Fatal(err) - } - // put the old resolvconf back - defer func() { - if err := ioutil.WriteFile("/etc/resolv.conf", origResolvConf, 0644); err != nil { - c.Fatal(err) - } - }() - - resolvConf, err := ioutil.ReadFile("/etc/resolv.conf") - if os.IsNotExist(err) { - c.Fatalf("/etc/resolv.conf does not exist") - } - - hostNameservers = resolvconf.GetNameservers(resolvConf, types.IP) - hostSearch = resolvconf.GetSearchDomains(resolvConf) - - out, _ = dockerCmd(c, "run", "busybox", "cat", "/etc/resolv.conf") - if actualNameservers = resolvconf.GetNameservers([]byte(out), types.IP); string(actualNameservers[0]) != "12.34.56.78" || len(actualNameservers) != 1 { - c.Fatalf("expected '12.34.56.78', but has: %v", actualNameservers) - } - - actualSearch = resolvconf.GetSearchDomains([]byte(out)) - if len(actualSearch) != len(hostSearch) { - c.Fatalf("expected %q search domain(s), but it has: %q", len(hostSearch), len(actualSearch)) - } - for i := range actualSearch { - if actualSearch[i] != hostSearch[i] { - c.Fatalf("expected %q domain, but says: %q", actualSearch[i], hostSearch[i]) - } - } -} - -// Test to see if a non-root user can resolve a DNS name. Also -// check if the container resolv.conf file has at least 0644 perm. -func (s *DockerSuite) TestRunNonRootUserResolvName(c *check.C) { - // Not applicable on Windows as Windows does not support --user - testRequires(c, SameHostDaemon, Network, DaemonIsLinux, NotArm) - - dockerCmd(c, "run", "--name=testperm", "--user=nobody", "busybox", "nslookup", "apt.dockerproject.org") - - cID, err := getIDByName("testperm") - if err != nil { - c.Fatal(err) - } - - fmode := (os.FileMode)(0644) - finfo, err := os.Stat(containerStorageFile(cID, "resolv.conf")) - if err != nil { - c.Fatal(err) - } - - if (finfo.Mode() & fmode) != fmode { - c.Fatalf("Expected container resolv.conf mode to be at least %s, instead got %s", fmode.String(), finfo.Mode().String()) - } -} - -// Test if container resolv.conf gets updated the next time it restarts -// if host /etc/resolv.conf has changed. This only applies if the container -// uses the host's /etc/resolv.conf and does not have any dns options provided. -func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) { - // Not applicable on Windows as testing unix specific functionality - testRequires(c, SameHostDaemon, DaemonIsLinux) - c.Skip("Unstable test, to be re-activated once #19937 is resolved") - - tmpResolvConf := []byte("search pommesfrites.fr\nnameserver 12.34.56.78\n") - tmpLocalhostResolvConf := []byte("nameserver 127.0.0.1") - - //take a copy of resolv.conf for restoring after test completes - resolvConfSystem, err := ioutil.ReadFile("/etc/resolv.conf") - if err != nil { - c.Fatal(err) - } - - // This test case is meant to test monitoring resolv.conf when it is - // a regular file not a bind mounc. So we unmount resolv.conf and replace - // it with a file containing the original settings. - mounted, err := mount.Mounted("/etc/resolv.conf") - if err != nil { - c.Fatal(err) - } - if mounted { - cmd := exec.Command("umount", "/etc/resolv.conf") - if _, err = runCommand(cmd); err != nil { - c.Fatal(err) - } - } - - //cleanup - defer func() { - if err := ioutil.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil { - c.Fatal(err) - } - }() - - //1. test that a restarting container gets an updated resolv.conf - dockerCmd(c, "run", "--name=first", "busybox", "true") - containerID1, err := getIDByName("first") - if err != nil { - c.Fatal(err) - } - - // replace resolv.conf with our temporary copy - bytesResolvConf := []byte(tmpResolvConf) - if err := ioutil.WriteFile("/etc/resolv.conf", bytesResolvConf, 0644); err != nil { - c.Fatal(err) - } - - // start the container again to pickup changes - dockerCmd(c, "start", "first") - - // check for update in container - containerResolv, err := readContainerFile(containerID1, "resolv.conf") - if err != nil { - c.Fatal(err) - } - if !bytes.Equal(containerResolv, bytesResolvConf) { - c.Fatalf("Restarted container does not have updated resolv.conf; expected %q, got %q", tmpResolvConf, string(containerResolv)) - } - - /* //make a change to resolv.conf (in this case replacing our tmp copy with orig copy) - if err := ioutil.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil { - c.Fatal(err) - } */ - //2. test that a restarting container does not receive resolv.conf updates - // if it modified the container copy of the starting point resolv.conf - dockerCmd(c, "run", "--name=second", "busybox", "sh", "-c", "echo 'search mylittlepony.com' >>/etc/resolv.conf") - containerID2, err := getIDByName("second") - if err != nil { - c.Fatal(err) - } - - //make a change to resolv.conf (in this case replacing our tmp copy with orig copy) - if err := ioutil.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil { - c.Fatal(err) - } - - // start the container again - dockerCmd(c, "start", "second") - - // check for update in container - containerResolv, err = readContainerFile(containerID2, "resolv.conf") - if err != nil { - c.Fatal(err) - } - - if bytes.Equal(containerResolv, resolvConfSystem) { - c.Fatalf("Container's resolv.conf should not have been updated with host resolv.conf: %q", string(containerResolv)) - } - - //3. test that a running container's resolv.conf is not modified while running - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - runningContainerID := strings.TrimSpace(out) - - // replace resolv.conf - if err := ioutil.WriteFile("/etc/resolv.conf", bytesResolvConf, 0644); err != nil { - c.Fatal(err) - } - - // check for update in container - containerResolv, err = readContainerFile(runningContainerID, "resolv.conf") - if err != nil { - c.Fatal(err) - } - - if bytes.Equal(containerResolv, bytesResolvConf) { - c.Fatalf("Running container should not have updated resolv.conf; expected %q, got %q", string(resolvConfSystem), string(containerResolv)) - } - - //4. test that a running container's resolv.conf is updated upon restart - // (the above container is still running..) - dockerCmd(c, "restart", runningContainerID) - - // check for update in container - containerResolv, err = readContainerFile(runningContainerID, "resolv.conf") - if err != nil { - c.Fatal(err) - } - if !bytes.Equal(containerResolv, bytesResolvConf) { - c.Fatalf("Restarted container should have updated resolv.conf; expected %q, got %q", string(bytesResolvConf), string(containerResolv)) - } - - //5. test that additions of a localhost resolver are cleaned from - // host resolv.conf before updating container's resolv.conf copies - - // replace resolv.conf with a localhost-only nameserver copy - bytesResolvConf = []byte(tmpLocalhostResolvConf) - if err = ioutil.WriteFile("/etc/resolv.conf", bytesResolvConf, 0644); err != nil { - c.Fatal(err) - } - - // start the container again to pickup changes - dockerCmd(c, "start", "first") - - // our first exited container ID should have been updated, but with default DNS - // after the cleanup of resolv.conf found only a localhost nameserver: - containerResolv, err = readContainerFile(containerID1, "resolv.conf") - if err != nil { - c.Fatal(err) - } - - expected := "\nnameserver 8.8.8.8\nnameserver 8.8.4.4\n" - if !bytes.Equal(containerResolv, []byte(expected)) { - c.Fatalf("Container does not have cleaned/replaced DNS in resolv.conf; expected %q, got %q", expected, string(containerResolv)) - } - - //6. Test that replacing (as opposed to modifying) resolv.conf triggers an update - // of containers' resolv.conf. - - // Restore the original resolv.conf - if err := ioutil.WriteFile("/etc/resolv.conf", resolvConfSystem, 0644); err != nil { - c.Fatal(err) - } - - // Run the container so it picks up the old settings - dockerCmd(c, "run", "--name=third", "busybox", "true") - containerID3, err := getIDByName("third") - if err != nil { - c.Fatal(err) - } - - // Create a modified resolv.conf.aside and override resolv.conf with it - bytesResolvConf = []byte(tmpResolvConf) - if err := ioutil.WriteFile("/etc/resolv.conf.aside", bytesResolvConf, 0644); err != nil { - c.Fatal(err) - } - - err = os.Rename("/etc/resolv.conf.aside", "/etc/resolv.conf") - if err != nil { - c.Fatal(err) - } - - // start the container again to pickup changes - dockerCmd(c, "start", "third") - - // check for update in container - containerResolv, err = readContainerFile(containerID3, "resolv.conf") - if err != nil { - c.Fatal(err) - } - if !bytes.Equal(containerResolv, bytesResolvConf) { - c.Fatalf("Stopped container does not have updated resolv.conf; expected\n%q\n got\n%q", tmpResolvConf, string(containerResolv)) - } - - //cleanup, restore original resolv.conf happens in defer func() -} - -func (s *DockerSuite) TestRunAddHost(c *check.C) { - // Not applicable on Windows as it does not support --add-host - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "--add-host=extra:86.75.30.9", "busybox", "grep", "extra", "/etc/hosts") - - actual := strings.Trim(out, "\r\n") - if actual != "86.75.30.9\textra" { - c.Fatalf("expected '86.75.30.9\textra', but says: %q", actual) - } -} - -// Regression test for #6983 -func (s *DockerSuite) TestRunAttachStdErrOnlyTTYMode(c *check.C) { - _, exitCode := dockerCmd(c, "run", "-t", "-a", "stderr", "busybox", "true") - if exitCode != 0 { - c.Fatalf("Container should have exited with error code 0") - } -} - -// Regression test for #6983 -func (s *DockerSuite) TestRunAttachStdOutOnlyTTYMode(c *check.C) { - _, exitCode := dockerCmd(c, "run", "-t", "-a", "stdout", "busybox", "true") - if exitCode != 0 { - c.Fatalf("Container should have exited with error code 0") - } -} - -// Regression test for #6983 -func (s *DockerSuite) TestRunAttachStdOutAndErrTTYMode(c *check.C) { - _, exitCode := dockerCmd(c, "run", "-t", "-a", "stdout", "-a", "stderr", "busybox", "true") - if exitCode != 0 { - c.Fatalf("Container should have exited with error code 0") - } -} - -// Test for #10388 - this will run the same test as TestRunAttachStdOutAndErrTTYMode -// but using --attach instead of -a to make sure we read the flag correctly -func (s *DockerSuite) TestRunAttachWithDetach(c *check.C) { - cmd := exec.Command(dockerBinary, "run", "-d", "--attach", "stdout", "busybox", "true") - _, stderr, _, err := runCommandWithStdoutStderr(cmd) - if err == nil { - c.Fatal("Container should have exited with error code different than 0") - } else if !strings.Contains(stderr, "Conflicting options: -a and -d") { - c.Fatal("Should have been returned an error with conflicting options -a and -d") - } -} - -func (s *DockerSuite) TestRunState(c *check.C) { - // TODO Windows: This needs some rework as Windows busybox does not support top - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - - id := strings.TrimSpace(out) - state := inspectField(c, id, "State.Running") - if state != "true" { - c.Fatal("Container state is 'not running'") - } - pid1 := inspectField(c, id, "State.Pid") - if pid1 == "0" { - c.Fatal("Container state Pid 0") - } - - dockerCmd(c, "stop", id) - state = inspectField(c, id, "State.Running") - if state != "false" { - c.Fatal("Container state is 'running'") - } - pid2 := inspectField(c, id, "State.Pid") - if pid2 == pid1 { - c.Fatalf("Container state Pid %s, but expected %s", pid2, pid1) - } - - dockerCmd(c, "start", id) - state = inspectField(c, id, "State.Running") - if state != "true" { - c.Fatal("Container state is 'not running'") - } - pid3 := inspectField(c, id, "State.Pid") - if pid3 == pid1 { - c.Fatalf("Container state Pid %s, but expected %s", pid2, pid1) - } -} - -// Test for #1737 -func (s *DockerSuite) TestRunCopyVolumeUIDGID(c *check.C) { - // Not applicable on Windows as it does not support uid or gid in this way - testRequires(c, DaemonIsLinux) - name := "testrunvolumesuidgid" - _, err := buildImage(name, - `FROM busybox - RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd - RUN echo 'dockerio:x:1001:' >> /etc/group - RUN mkdir -p /hello && touch /hello/test && chown dockerio.dockerio /hello`, - true) - if err != nil { - c.Fatal(err) - } - - // Test that the uid and gid is copied from the image to the volume - out, _ := dockerCmd(c, "run", "--rm", "-v", "/hello", name, "sh", "-c", "ls -l / | grep hello | awk '{print $3\":\"$4}'") - out = strings.TrimSpace(out) - if out != "dockerio:dockerio" { - c.Fatalf("Wrong /hello ownership: %s, expected dockerio:dockerio", out) - } -} - -// Test for #1582 -func (s *DockerSuite) TestRunCopyVolumeContent(c *check.C) { - // TODO Windows, post TP5. Windows does not yet support volume functionality - // that copies from the image to the volume. - testRequires(c, DaemonIsLinux) - name := "testruncopyvolumecontent" - _, err := buildImage(name, - `FROM busybox - RUN mkdir -p /hello/local && echo hello > /hello/local/world`, - true) - if err != nil { - c.Fatal(err) - } - - // Test that the content is copied from the image to the volume - out, _ := dockerCmd(c, "run", "--rm", "-v", "/hello", name, "find", "/hello") - if !(strings.Contains(out, "/hello/local/world") && strings.Contains(out, "/hello/local")) { - c.Fatal("Container failed to transfer content to volume") - } -} - -func (s *DockerSuite) TestRunCleanupCmdOnEntrypoint(c *check.C) { - name := "testrunmdcleanuponentrypoint" - if _, err := buildImage(name, - `FROM busybox - ENTRYPOINT ["echo"] - CMD ["testingpoint"]`, - true); err != nil { - c.Fatal(err) - } - - out, exit := dockerCmd(c, "run", "--entrypoint", "whoami", name) - if exit != 0 { - c.Fatalf("expected exit code 0 received %d, out: %q", exit, out) - } - out = strings.TrimSpace(out) - expected := "root" - if daemonPlatform == "windows" { - if strings.Contains(WindowsBaseImage, "windowsservercore") { - expected = `user manager\containeradministrator` - } else { - expected = `ContainerAdministrator` // nanoserver - } - } - if out != expected { - c.Fatalf("Expected output %s, got %q. %s", expected, out, WindowsBaseImage) - } -} - -// TestRunWorkdirExistsAndIsFile checks that if 'docker run -w' with existing file can be detected -func (s *DockerSuite) TestRunWorkdirExistsAndIsFile(c *check.C) { - existingFile := "/bin/cat" - expected := "not a directory" - if daemonPlatform == "windows" { - existingFile = `\windows\system32\ntdll.dll` - expected = `The directory name is invalid.` - } - - out, exitCode, err := dockerCmdWithError("run", "-w", existingFile, "busybox") - if !(err != nil && exitCode == 125 && strings.Contains(out, expected)) { - c.Fatalf("Existing binary as a directory should error out with exitCode 125; we got: %s, exitCode: %d", out, exitCode) - } -} - -func (s *DockerSuite) TestRunExitOnStdinClose(c *check.C) { - name := "testrunexitonstdinclose" - - meow := "/bin/cat" - delay := 60 - if daemonPlatform == "windows" { - meow = "cat" - } - runCmd := exec.Command(dockerBinary, "run", "--name", name, "-i", "busybox", meow) - - stdin, err := runCmd.StdinPipe() - if err != nil { - c.Fatal(err) - } - stdout, err := runCmd.StdoutPipe() - if err != nil { - c.Fatal(err) - } - - if err := runCmd.Start(); err != nil { - c.Fatal(err) - } - if _, err := stdin.Write([]byte("hello\n")); err != nil { - c.Fatal(err) - } - - r := bufio.NewReader(stdout) - line, err := r.ReadString('\n') - if err != nil { - c.Fatal(err) - } - line = strings.TrimSpace(line) - if line != "hello" { - c.Fatalf("Output should be 'hello', got '%q'", line) - } - if err := stdin.Close(); err != nil { - c.Fatal(err) - } - finish := make(chan error) - go func() { - finish <- runCmd.Wait() - close(finish) - }() - select { - case err := <-finish: - c.Assert(err, check.IsNil) - case <-time.After(time.Duration(delay) * time.Second): - c.Fatal("docker run failed to exit on stdin close") - } - state := inspectField(c, name, "State.Running") - - if state != "false" { - c.Fatal("Container must be stopped after stdin closing") - } -} - -// Test run -i --restart xxx doesn't hang -func (s *DockerSuite) TestRunInteractiveWithRestartPolicy(c *check.C) { - name := "test-inter-restart" - - result := icmd.StartCmd(icmd.Cmd{ - Command: []string{dockerBinary, "run", "-i", "--name", name, "--restart=always", "busybox", "sh"}, - Stdin: bytes.NewBufferString("exit 11"), - }) - c.Assert(result.Error, checker.IsNil) - defer func() { - dockerCmdWithResult("stop", name).Assert(c, icmd.Success) - }() - - result = icmd.WaitOnCmd(60*time.Second, result) - c.Assert(result, icmd.Matches, icmd.Expected{ExitCode: 11}) -} - -// Test for #2267 -func (s *DockerSuite) TestRunWriteHostsFileAndNotCommit(c *check.C) { - // Cannot run on Windows as Windows does not support diff. - testRequires(c, DaemonIsLinux) - name := "writehosts" - out, _ := dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hosts && cat /etc/hosts") - if !strings.Contains(out, "test2267") { - c.Fatal("/etc/hosts should contain 'test2267'") - } - - out, _ = dockerCmd(c, "diff", name) - if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, c) { - c.Fatal("diff should be empty") - } -} - -func eqToBaseDiff(out string, c *check.C) bool { - name := "eqToBaseDiff" + stringutils.GenerateRandomAlphaOnlyString(32) - dockerCmd(c, "run", "--name", name, "busybox", "echo", "hello") - cID, err := getIDByName(name) - c.Assert(err, check.IsNil) - - baseDiff, _ := dockerCmd(c, "diff", cID) - baseArr := strings.Split(baseDiff, "\n") - sort.Strings(baseArr) - outArr := strings.Split(out, "\n") - sort.Strings(outArr) - return sliceEq(baseArr, outArr) -} - -func sliceEq(a, b []string) bool { - if len(a) != len(b) { - return false - } - - for i := range a { - if a[i] != b[i] { - return false - } - } - - return true -} - -// Test for #2267 -func (s *DockerSuite) TestRunWriteHostnameFileAndNotCommit(c *check.C) { - // Cannot run on Windows as Windows does not support diff. - testRequires(c, DaemonIsLinux) - name := "writehostname" - out, _ := dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hostname && cat /etc/hostname") - if !strings.Contains(out, "test2267") { - c.Fatal("/etc/hostname should contain 'test2267'") - } - - out, _ = dockerCmd(c, "diff", name) - if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, c) { - c.Fatal("diff should be empty") - } -} - -// Test for #2267 -func (s *DockerSuite) TestRunWriteResolvFileAndNotCommit(c *check.C) { - // Cannot run on Windows as Windows does not support diff. - testRequires(c, DaemonIsLinux) - name := "writeresolv" - out, _ := dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/resolv.conf && cat /etc/resolv.conf") - if !strings.Contains(out, "test2267") { - c.Fatal("/etc/resolv.conf should contain 'test2267'") - } - - out, _ = dockerCmd(c, "diff", name) - if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, c) { - c.Fatal("diff should be empty") - } -} - -func (s *DockerSuite) TestRunWithBadDevice(c *check.C) { - // Cannot run on Windows as Windows does not support --device - testRequires(c, DaemonIsLinux) - name := "baddevice" - out, _, err := dockerCmdWithError("run", "--name", name, "--device", "/etc", "busybox", "true") - - if err == nil { - c.Fatal("Run should fail with bad device") - } - expected := `"/etc": not a device node` - if !strings.Contains(out, expected) { - c.Fatalf("Output should contain %q, actual out: %q", expected, out) - } -} - -func (s *DockerSuite) TestRunEntrypoint(c *check.C) { - name := "entrypoint" - - out, _ := dockerCmd(c, "run", "--name", name, "--entrypoint", "echo", "busybox", "-n", "foobar") - expected := "foobar" - - if out != expected { - c.Fatalf("Output should be %q, actual out: %q", expected, out) - } -} - -func (s *DockerSuite) TestRunBindMounts(c *check.C) { - testRequires(c, SameHostDaemon) - if daemonPlatform == "linux" { - testRequires(c, DaemonIsLinux, NotUserNamespace) - } - - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - - tmpDir, err := ioutil.TempDir("", "docker-test-container") - if err != nil { - c.Fatal(err) - } - - defer os.RemoveAll(tmpDir) - writeFile(path.Join(tmpDir, "touch-me"), "", c) - - // TODO Windows: Temporary check - remove once TP5 support is dropped - if daemonPlatform != "windows" || windowsDaemonKV >= 14350 { - // Test reading from a read-only bind mount - out, _ := dockerCmd(c, "run", "-v", fmt.Sprintf("%s:%s/tmp:ro", tmpDir, prefix), "busybox", "ls", prefix+"/tmp") - if !strings.Contains(out, "touch-me") { - c.Fatal("Container failed to read from bind mount") - } - } - - // test writing to bind mount - if daemonPlatform == "windows" { - dockerCmd(c, "run", "-v", fmt.Sprintf(`%s:c:\tmp:rw`, tmpDir), "busybox", "touch", "c:/tmp/holla") - } else { - dockerCmd(c, "run", "-v", fmt.Sprintf("%s:/tmp:rw", tmpDir), "busybox", "touch", "/tmp/holla") - } - - readFile(path.Join(tmpDir, "holla"), c) // Will fail if the file doesn't exist - - // test mounting to an illegal destination directory - _, _, err = dockerCmdWithError("run", "-v", fmt.Sprintf("%s:.", tmpDir), "busybox", "ls", ".") - if err == nil { - c.Fatal("Container bind mounted illegal directory") - } - - // Windows does not (and likely never will) support mounting a single file - if daemonPlatform != "windows" { - // test mount a file - dockerCmd(c, "run", "-v", fmt.Sprintf("%s/holla:/tmp/holla:rw", tmpDir), "busybox", "sh", "-c", "echo -n 'yotta' > /tmp/holla") - content := readFile(path.Join(tmpDir, "holla"), c) // Will fail if the file doesn't exist - expected := "yotta" - if content != expected { - c.Fatalf("Output should be %q, actual out: %q", expected, content) - } - } -} - -// Ensure that CIDFile gets deleted if it's empty -// Perform this test by making `docker run` fail -func (s *DockerSuite) TestRunCidFileCleanupIfEmpty(c *check.C) { - // Skip on Windows. Base image on Windows has a CMD set in the image. - testRequires(c, DaemonIsLinux) - - tmpDir, err := ioutil.TempDir("", "TestRunCidFile") - if err != nil { - c.Fatal(err) - } - defer os.RemoveAll(tmpDir) - tmpCidFile := path.Join(tmpDir, "cid") - - image := "emptyfs" - if daemonPlatform == "windows" { - // Windows can't support an emptyfs image. Just use the regular Windows image - image = WindowsBaseImage - } - out, _, err := dockerCmdWithError("run", "--cidfile", tmpCidFile, image) - if err == nil { - c.Fatalf("Run without command must fail. out=%s", out) - } else if !strings.Contains(out, "No command specified") { - c.Fatalf("Run without command failed with wrong output. out=%s\nerr=%v", out, err) - } - - if _, err := os.Stat(tmpCidFile); err == nil { - c.Fatalf("empty CIDFile %q should've been deleted", tmpCidFile) - } -} - -// #2098 - Docker cidFiles only contain short version of the containerId -//sudo docker run --cidfile /tmp/docker_tesc.cid ubuntu echo "test" -// TestRunCidFile tests that run --cidfile returns the longid -func (s *DockerSuite) TestRunCidFileCheckIDLength(c *check.C) { - tmpDir, err := ioutil.TempDir("", "TestRunCidFile") - if err != nil { - c.Fatal(err) - } - tmpCidFile := path.Join(tmpDir, "cid") - defer os.RemoveAll(tmpDir) - - out, _ := dockerCmd(c, "run", "-d", "--cidfile", tmpCidFile, "busybox", "true") - - id := strings.TrimSpace(out) - buffer, err := ioutil.ReadFile(tmpCidFile) - if err != nil { - c.Fatal(err) - } - cid := string(buffer) - if len(cid) != 64 { - c.Fatalf("--cidfile should be a long id, not %q", id) - } - if cid != id { - c.Fatalf("cid must be equal to %s, got %s", id, cid) - } -} - -func (s *DockerSuite) TestRunSetMacAddress(c *check.C) { - mac := "12:34:56:78:9a:bc" - var out string - if daemonPlatform == "windows" { - out, _ = dockerCmd(c, "run", "-i", "--rm", fmt.Sprintf("--mac-address=%s", mac), "busybox", "sh", "-c", "ipconfig /all | grep 'Physical Address' | awk '{print $12}'") - mac = strings.Replace(strings.ToUpper(mac), ":", "-", -1) // To Windows-style MACs - } else { - out, _ = dockerCmd(c, "run", "-i", "--rm", fmt.Sprintf("--mac-address=%s", mac), "busybox", "/bin/sh", "-c", "ip link show eth0 | tail -1 | awk '{print $2}'") - } - - actualMac := strings.TrimSpace(out) - if actualMac != mac { - c.Fatalf("Set MAC address with --mac-address failed. The container has an incorrect MAC address: %q, expected: %q", actualMac, mac) - } -} - -func (s *DockerSuite) TestRunInspectMacAddress(c *check.C) { - // TODO Windows. Network settings are not propagated back to inspect. - testRequires(c, DaemonIsLinux) - mac := "12:34:56:78:9a:bc" - out, _ := dockerCmd(c, "run", "-d", "--mac-address="+mac, "busybox", "top") - - id := strings.TrimSpace(out) - inspectedMac := inspectField(c, id, "NetworkSettings.Networks.bridge.MacAddress") - if inspectedMac != mac { - c.Fatalf("docker inspect outputs wrong MAC address: %q, should be: %q", inspectedMac, mac) - } -} - -// test docker run use an invalid mac address -func (s *DockerSuite) TestRunWithInvalidMacAddress(c *check.C) { - out, _, err := dockerCmdWithError("run", "--mac-address", "92:d0:c6:0a:29", "busybox") - //use an invalid mac address should with an error out - if err == nil || !strings.Contains(out, "is not a valid mac address") { - c.Fatalf("run with an invalid --mac-address should with error out") - } -} - -func (s *DockerSuite) TestRunDeallocatePortOnMissingIptablesRule(c *check.C) { - // TODO Windows. Network settings are not propagated back to inspect. - testRequires(c, SameHostDaemon, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-d", "-p", "23:23", "busybox", "top") - - id := strings.TrimSpace(out) - ip := inspectField(c, id, "NetworkSettings.Networks.bridge.IPAddress") - iptCmd := exec.Command("iptables", "-D", "DOCKER", "-d", fmt.Sprintf("%s/32", ip), - "!", "-i", "docker0", "-o", "docker0", "-p", "tcp", "-m", "tcp", "--dport", "23", "-j", "ACCEPT") - out, _, err := runCommandWithOutput(iptCmd) - if err != nil { - c.Fatal(err, out) - } - if err := deleteContainer(id); err != nil { - c.Fatal(err) - } - - dockerCmd(c, "run", "-d", "-p", "23:23", "busybox", "top") -} - -func (s *DockerSuite) TestRunPortInUse(c *check.C) { - // TODO Windows. The duplicate NAT message returned by Windows will be - // changing as is currently completely undecipherable. Does need modifying - // to run sh rather than top though as top isn't in Windows busybox. - testRequires(c, SameHostDaemon, DaemonIsLinux) - - port := "1234" - dockerCmd(c, "run", "-d", "-p", port+":80", "busybox", "top") - - out, _, err := dockerCmdWithError("run", "-d", "-p", port+":80", "busybox", "top") - if err == nil { - c.Fatalf("Binding on used port must fail") - } - if !strings.Contains(out, "port is already allocated") { - c.Fatalf("Out must be about \"port is already allocated\", got %s", out) - } -} - -// https://github.com/docker/docker/issues/12148 -func (s *DockerSuite) TestRunAllocatePortInReservedRange(c *check.C) { - // TODO Windows. -P is not yet supported - testRequires(c, DaemonIsLinux) - // allocate a dynamic port to get the most recent - out, _ := dockerCmd(c, "run", "-d", "-P", "-p", "80", "busybox", "top") - - id := strings.TrimSpace(out) - out, _ = dockerCmd(c, "port", id, "80") - - strPort := strings.Split(strings.TrimSpace(out), ":")[1] - port, err := strconv.ParseInt(strPort, 10, 64) - if err != nil { - c.Fatalf("invalid port, got: %s, error: %s", strPort, err) - } - - // allocate a static port and a dynamic port together, with static port - // takes the next recent port in dynamic port range. - dockerCmd(c, "run", "-d", "-P", "-p", "80", "-p", fmt.Sprintf("%d:8080", port+1), "busybox", "top") -} - -// Regression test for #7792 -func (s *DockerSuite) TestRunMountOrdering(c *check.C) { - // TODO Windows: Post TP5. Updated, but Windows does not support nested mounts currently. - testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - - tmpDir, err := ioutil.TempDir("", "docker_nested_mount_test") - if err != nil { - c.Fatal(err) - } - defer os.RemoveAll(tmpDir) - - tmpDir2, err := ioutil.TempDir("", "docker_nested_mount_test2") - if err != nil { - c.Fatal(err) - } - defer os.RemoveAll(tmpDir2) - - // Create a temporary tmpfs mounc. - fooDir := filepath.Join(tmpDir, "foo") - if err := os.MkdirAll(filepath.Join(tmpDir, "foo"), 0755); err != nil { - c.Fatalf("failed to mkdir at %s - %s", fooDir, err) - } - - if err := ioutil.WriteFile(fmt.Sprintf("%s/touch-me", fooDir), []byte{}, 0644); err != nil { - c.Fatal(err) - } - - if err := ioutil.WriteFile(fmt.Sprintf("%s/touch-me", tmpDir), []byte{}, 0644); err != nil { - c.Fatal(err) - } - - if err := ioutil.WriteFile(fmt.Sprintf("%s/touch-me", tmpDir2), []byte{}, 0644); err != nil { - c.Fatal(err) - } - - dockerCmd(c, "run", - "-v", fmt.Sprintf("%s:"+prefix+"/tmp", tmpDir), - "-v", fmt.Sprintf("%s:"+prefix+"/tmp/foo", fooDir), - "-v", fmt.Sprintf("%s:"+prefix+"/tmp/tmp2", tmpDir2), - "-v", fmt.Sprintf("%s:"+prefix+"/tmp/tmp2/foo", fooDir), - "busybox:latest", "sh", "-c", - "ls "+prefix+"/tmp/touch-me && ls "+prefix+"/tmp/foo/touch-me && ls "+prefix+"/tmp/tmp2/touch-me && ls "+prefix+"/tmp/tmp2/foo/touch-me") -} - -// Regression test for https://github.com/docker/docker/issues/8259 -func (s *DockerSuite) TestRunReuseBindVolumeThatIsSymlink(c *check.C) { - // Not applicable on Windows as Windows does not support volumes - testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - - tmpDir, err := ioutil.TempDir(os.TempDir(), "testlink") - if err != nil { - c.Fatal(err) - } - defer os.RemoveAll(tmpDir) - - linkPath := os.TempDir() + "/testlink2" - if err := os.Symlink(tmpDir, linkPath); err != nil { - c.Fatal(err) - } - defer os.RemoveAll(linkPath) - - // Create first container - dockerCmd(c, "run", "-v", fmt.Sprintf("%s:"+prefix+"/tmp/test", linkPath), "busybox", "ls", prefix+"/tmp/test") - - // Create second container with same symlinked path - // This will fail if the referenced issue is hit with a "Volume exists" error - dockerCmd(c, "run", "-v", fmt.Sprintf("%s:"+prefix+"/tmp/test", linkPath), "busybox", "ls", prefix+"/tmp/test") -} - -//GH#10604: Test an "/etc" volume doesn't overlay special bind mounts in container -func (s *DockerSuite) TestRunCreateVolumeEtc(c *check.C) { - // While Windows supports volumes, it does not support --add-host hence - // this test is not applicable on Windows. - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "--dns=127.0.0.1", "-v", "/etc", "busybox", "cat", "/etc/resolv.conf") - if !strings.Contains(out, "nameserver 127.0.0.1") { - c.Fatal("/etc volume mount hides /etc/resolv.conf") - } - - out, _ = dockerCmd(c, "run", "-h=test123", "-v", "/etc", "busybox", "cat", "/etc/hostname") - if !strings.Contains(out, "test123") { - c.Fatal("/etc volume mount hides /etc/hostname") - } - - out, _ = dockerCmd(c, "run", "--add-host=test:192.168.0.1", "-v", "/etc", "busybox", "cat", "/etc/hosts") - out = strings.Replace(out, "\n", " ", -1) - if !strings.Contains(out, "192.168.0.1\ttest") || !strings.Contains(out, "127.0.0.1\tlocalhost") { - c.Fatal("/etc volume mount hides /etc/hosts") - } -} - -func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) { - // TODO Windows (Post RS1). Windows does not support volumes which - // are pre-populated such as is built in the dockerfile used in this test. - testRequires(c, DaemonIsLinux) - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - if _, err := buildImage("dataimage", - `FROM busybox - RUN ["mkdir", "-p", "/foo"] - RUN ["touch", "/foo/bar"]`, - true); err != nil { - c.Fatal(err) - } - - dockerCmd(c, "run", "--name", "test", "-v", prefix+slash+"foo", "busybox") - - if out, _, err := dockerCmdWithError("run", "--volumes-from", "test", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") { - c.Fatalf("Data was copied on volumes-from but shouldn't be:\n%q", out) - } - - tmpDir := randomTmpDirPath("docker_test_bind_mount_copy_data", daemonPlatform) - if out, _, err := dockerCmdWithError("run", "-v", tmpDir+":/foo", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") { - c.Fatalf("Data was copied on bind-mount but shouldn't be:\n%q", out) - } -} - -func (s *DockerSuite) TestRunNoOutputFromPullInStdout(c *check.C) { - // just run with unknown image - cmd := exec.Command(dockerBinary, "run", "asdfsg") - stdout := bytes.NewBuffer(nil) - cmd.Stdout = stdout - if err := cmd.Run(); err == nil { - c.Fatal("Run with unknown image should fail") - } - if stdout.Len() != 0 { - c.Fatalf("Stdout contains output from pull: %s", stdout) - } -} - -func (s *DockerSuite) TestRunVolumesCleanPaths(c *check.C) { - testRequires(c, SameHostDaemon) - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - if _, err := buildImage("run_volumes_clean_paths", - `FROM busybox - VOLUME `+prefix+`/foo/`, - true); err != nil { - c.Fatal(err) - } - - dockerCmd(c, "run", "-v", prefix+"/foo", "-v", prefix+"/bar/", "--name", "dark_helmet", "run_volumes_clean_paths") - - out, err := inspectMountSourceField("dark_helmet", prefix+slash+"foo"+slash) - if err != errMountNotFound { - c.Fatalf("Found unexpected volume entry for '%s/foo/' in volumes\n%q", prefix, out) - } - - out, err = inspectMountSourceField("dark_helmet", prefix+slash+`foo`) - c.Assert(err, check.IsNil) - if !strings.Contains(strings.ToLower(out), strings.ToLower(volumesConfigPath)) { - c.Fatalf("Volume was not defined for %s/foo\n%q", prefix, out) - } - - out, err = inspectMountSourceField("dark_helmet", prefix+slash+"bar"+slash) - if err != errMountNotFound { - c.Fatalf("Found unexpected volume entry for '%s/bar/' in volumes\n%q", prefix, out) - } - - out, err = inspectMountSourceField("dark_helmet", prefix+slash+"bar") - c.Assert(err, check.IsNil) - if !strings.Contains(strings.ToLower(out), strings.ToLower(volumesConfigPath)) { - c.Fatalf("Volume was not defined for %s/bar\n%q", prefix, out) - } -} - -// Regression test for #3631 -func (s *DockerSuite) TestRunSlowStdoutConsumer(c *check.C) { - // TODO Windows: This should be able to run on Windows if can find an - // alternate to /dev/zero and /dev/stdout. - testRequires(c, DaemonIsLinux) - cont := exec.Command(dockerBinary, "run", "--rm", "busybox", "/bin/sh", "-c", "dd if=/dev/zero of=/dev/stdout bs=1024 count=2000 | catv") - - stdout, err := cont.StdoutPipe() - if err != nil { - c.Fatal(err) - } - - if err := cont.Start(); err != nil { - c.Fatal(err) - } - n, err := consumeWithSpeed(stdout, 10000, 5*time.Millisecond, nil) - if err != nil { - c.Fatal(err) - } - - expected := 2 * 1024 * 2000 - if n != expected { - c.Fatalf("Expected %d, got %d", expected, n) - } -} - -func (s *DockerSuite) TestRunAllowPortRangeThroughExpose(c *check.C) { - // TODO Windows: -P is not currently supported. Also network - // settings are not propagated back. - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "--expose", "3000-3003", "-P", "busybox", "top") - - id := strings.TrimSpace(out) - portstr := inspectFieldJSON(c, id, "NetworkSettings.Ports") - var ports nat.PortMap - if err := json.Unmarshal([]byte(portstr), &ports); err != nil { - c.Fatal(err) - } - for port, binding := range ports { - portnum, _ := strconv.Atoi(strings.Split(string(port), "/")[0]) - if portnum < 3000 || portnum > 3003 { - c.Fatalf("Port %d is out of range ", portnum) - } - if binding == nil || len(binding) != 1 || len(binding[0].HostPort) == 0 { - c.Fatalf("Port is not mapped for the port %s", port) - } - } -} - -func (s *DockerSuite) TestRunExposePort(c *check.C) { - out, _, err := dockerCmdWithError("run", "--expose", "80000", "busybox") - c.Assert(err, checker.NotNil, check.Commentf("--expose with an invalid port should error out")) - c.Assert(out, checker.Contains, "invalid range format for --expose") -} - -func (s *DockerSuite) TestRunModeIpcHost(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - - hostIpc, err := os.Readlink("/proc/1/ns/ipc") - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", "--ipc=host", "busybox", "readlink", "/proc/self/ns/ipc") - out = strings.Trim(out, "\n") - if hostIpc != out { - c.Fatalf("IPC different with --ipc=host %s != %s\n", hostIpc, out) - } - - out, _ = dockerCmd(c, "run", "busybox", "readlink", "/proc/self/ns/ipc") - out = strings.Trim(out, "\n") - if hostIpc == out { - c.Fatalf("IPC should be different without --ipc=host %s == %s\n", hostIpc, out) - } -} - -func (s *DockerSuite) TestRunModeIpcContainer(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "echo -n test > /dev/shm/test && touch /dev/mqueue/toto && top") - - id := strings.TrimSpace(out) - state := inspectField(c, id, "State.Running") - if state != "true" { - c.Fatal("Container state is 'not running'") - } - pid1 := inspectField(c, id, "State.Pid") - - parentContainerIpc, err := os.Readlink(fmt.Sprintf("/proc/%s/ns/ipc", pid1)) - if err != nil { - c.Fatal(err) - } - - out, _ = dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "readlink", "/proc/self/ns/ipc") - out = strings.Trim(out, "\n") - if parentContainerIpc != out { - c.Fatalf("IPC different with --ipc=container:%s %s != %s\n", id, parentContainerIpc, out) - } - - catOutput, _ := dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "cat", "/dev/shm/test") - if catOutput != "test" { - c.Fatalf("Output of /dev/shm/test expected test but found: %s", catOutput) - } - - // check that /dev/mqueue is actually of mqueue type - grepOutput, _ := dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "grep", "/dev/mqueue", "/proc/mounts") - if !strings.HasPrefix(grepOutput, "mqueue /dev/mqueue mqueue rw") { - c.Fatalf("Output of 'grep /proc/mounts' expected 'mqueue /dev/mqueue mqueue rw' but found: %s", grepOutput) - } - - lsOutput, _ := dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "ls", "/dev/mqueue") - lsOutput = strings.Trim(lsOutput, "\n") - if lsOutput != "toto" { - c.Fatalf("Output of 'ls /dev/mqueue' expected 'toto' but found: %s", lsOutput) - } -} - -func (s *DockerSuite) TestRunModeIpcContainerNotExists(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "-d", "--ipc", "container:abcd1234", "busybox", "top") - if !strings.Contains(out, "abcd1234") || err == nil { - c.Fatalf("run IPC from a non exists container should with correct error out") - } -} - -func (s *DockerSuite) TestRunModeIpcContainerNotRunning(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux) - - out, _ := dockerCmd(c, "create", "busybox") - - id := strings.TrimSpace(out) - out, _, err := dockerCmdWithError("run", fmt.Sprintf("--ipc=container:%s", id), "busybox") - if err == nil { - c.Fatalf("Run container with ipc mode container should fail with non running container: %s\n%s", out, err) - } -} - -func (s *DockerSuite) TestRunModePIDContainer(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "top") - - id := strings.TrimSpace(out) - state := inspectField(c, id, "State.Running") - if state != "true" { - c.Fatal("Container state is 'not running'") - } - pid1 := inspectField(c, id, "State.Pid") - - parentContainerPid, err := os.Readlink(fmt.Sprintf("/proc/%s/ns/pid", pid1)) - if err != nil { - c.Fatal(err) - } - - out, _ = dockerCmd(c, "run", fmt.Sprintf("--pid=container:%s", id), "busybox", "readlink", "/proc/self/ns/pid") - out = strings.Trim(out, "\n") - if parentContainerPid != out { - c.Fatalf("PID different with --pid=container:%s %s != %s\n", id, parentContainerPid, out) - } -} - -func (s *DockerSuite) TestRunModePIDContainerNotExists(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "-d", "--pid", "container:abcd1234", "busybox", "top") - if !strings.Contains(out, "abcd1234") || err == nil { - c.Fatalf("run PID from a non exists container should with correct error out") - } -} - -func (s *DockerSuite) TestRunModePIDContainerNotRunning(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux) - - out, _ := dockerCmd(c, "create", "busybox") - - id := strings.TrimSpace(out) - out, _, err := dockerCmdWithError("run", fmt.Sprintf("--pid=container:%s", id), "busybox") - if err == nil { - c.Fatalf("Run container with pid mode container should fail with non running container: %s\n%s", out, err) - } -} - -func (s *DockerSuite) TestRunMountShmMqueueFromHost(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - - dockerCmd(c, "run", "-d", "--name", "shmfromhost", "-v", "/dev/shm:/dev/shm", "-v", "/dev/mqueue:/dev/mqueue", "busybox", "sh", "-c", "echo -n test > /dev/shm/test && touch /dev/mqueue/toto && top") - defer os.Remove("/dev/mqueue/toto") - defer os.Remove("/dev/shm/test") - volPath, err := inspectMountSourceField("shmfromhost", "/dev/shm") - c.Assert(err, checker.IsNil) - if volPath != "/dev/shm" { - c.Fatalf("volumePath should have been /dev/shm, was %s", volPath) - } - - out, _ := dockerCmd(c, "run", "--name", "ipchost", "--ipc", "host", "busybox", "cat", "/dev/shm/test") - if out != "test" { - c.Fatalf("Output of /dev/shm/test expected test but found: %s", out) - } - - // Check that the mq was created - if _, err := os.Stat("/dev/mqueue/toto"); err != nil { - c.Fatalf("Failed to confirm '/dev/mqueue/toto' presence on host: %s", err.Error()) - } -} - -func (s *DockerSuite) TestContainerNetworkMode(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), check.IsNil) - pid1 := inspectField(c, id, "State.Pid") - - parentContainerNet, err := os.Readlink(fmt.Sprintf("/proc/%s/ns/net", pid1)) - if err != nil { - c.Fatal(err) - } - - out, _ = dockerCmd(c, "run", fmt.Sprintf("--net=container:%s", id), "busybox", "readlink", "/proc/self/ns/net") - out = strings.Trim(out, "\n") - if parentContainerNet != out { - c.Fatalf("NET different with --net=container:%s %s != %s\n", id, parentContainerNet, out) - } -} - -func (s *DockerSuite) TestRunModePIDHost(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - - hostPid, err := os.Readlink("/proc/1/ns/pid") - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", "--pid=host", "busybox", "readlink", "/proc/self/ns/pid") - out = strings.Trim(out, "\n") - if hostPid != out { - c.Fatalf("PID different with --pid=host %s != %s\n", hostPid, out) - } - - out, _ = dockerCmd(c, "run", "busybox", "readlink", "/proc/self/ns/pid") - out = strings.Trim(out, "\n") - if hostPid == out { - c.Fatalf("PID should be different without --pid=host %s == %s\n", hostPid, out) - } -} - -func (s *DockerSuite) TestRunModeUTSHost(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux) - - hostUTS, err := os.Readlink("/proc/1/ns/uts") - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", "--uts=host", "busybox", "readlink", "/proc/self/ns/uts") - out = strings.Trim(out, "\n") - if hostUTS != out { - c.Fatalf("UTS different with --uts=host %s != %s\n", hostUTS, out) - } - - out, _ = dockerCmd(c, "run", "busybox", "readlink", "/proc/self/ns/uts") - out = strings.Trim(out, "\n") - if hostUTS == out { - c.Fatalf("UTS should be different without --uts=host %s == %s\n", hostUTS, out) - } - - out, _ = dockerCmdWithFail(c, "run", "-h=name", "--uts=host", "busybox", "ps") - c.Assert(out, checker.Contains, runconfig.ErrConflictUTSHostname.Error()) -} - -func (s *DockerSuite) TestRunTLSVerify(c *check.C) { - // Remote daemons use TLS and this test is not applicable when TLS is required. - testRequires(c, SameHostDaemon) - if out, code, err := dockerCmdWithError("ps"); err != nil || code != 0 { - c.Fatalf("Should have worked: %v:\n%v", err, out) - } - - // Regardless of whether we specify true or false we need to - // test to make sure tls is turned on if --tlsverify is specified at all - result := dockerCmdWithResult("--tlsverify=false", "ps") - result.Assert(c, icmd.Expected{ExitCode: 1, Err: "error during connect"}) - - result = dockerCmdWithResult("--tlsverify=true", "ps") - result.Assert(c, icmd.Expected{ExitCode: 1, Err: "cert"}) -} - -func (s *DockerSuite) TestRunPortFromDockerRangeInUse(c *check.C) { - // TODO Windows. Once moved to libnetwork/CNM, this may be able to be - // re-instated. - testRequires(c, DaemonIsLinux) - // first find allocator current position - out, _ := dockerCmd(c, "run", "-d", "-p", ":80", "busybox", "top") - - id := strings.TrimSpace(out) - out, _ = dockerCmd(c, "port", id) - - out = strings.TrimSpace(out) - if out == "" { - c.Fatal("docker port command output is empty") - } - out = strings.Split(out, ":")[1] - lastPort, err := strconv.Atoi(out) - if err != nil { - c.Fatal(err) - } - port := lastPort + 1 - l, err := net.Listen("tcp", ":"+strconv.Itoa(port)) - if err != nil { - c.Fatal(err) - } - defer l.Close() - - out, _ = dockerCmd(c, "run", "-d", "-p", ":80", "busybox", "top") - - id = strings.TrimSpace(out) - dockerCmd(c, "port", id) -} - -func (s *DockerSuite) TestRunTTYWithPipe(c *check.C) { - errChan := make(chan error) - go func() { - defer close(errChan) - - cmd := exec.Command(dockerBinary, "run", "-ti", "busybox", "true") - if _, err := cmd.StdinPipe(); err != nil { - errChan <- err - return - } - - expected := "the input device is not a TTY" - if runtime.GOOS == "windows" { - expected += ". If you are using mintty, try prefixing the command with 'winpty'" - } - if out, _, err := runCommandWithOutput(cmd); err == nil { - errChan <- fmt.Errorf("run should have failed") - return - } else if !strings.Contains(out, expected) { - errChan <- fmt.Errorf("run failed with error %q: expected %q", out, expected) - return - } - }() - - select { - case err := <-errChan: - c.Assert(err, check.IsNil) - case <-time.After(30 * time.Second): - c.Fatal("container is running but should have failed") - } -} - -func (s *DockerSuite) TestRunNonLocalMacAddress(c *check.C) { - addr := "00:16:3E:08:00:50" - args := []string{"run", "--mac-address", addr} - expected := addr - - if daemonPlatform != "windows" { - args = append(args, "busybox", "ifconfig") - } else { - args = append(args, WindowsBaseImage, "ipconfig", "/all") - expected = strings.Replace(strings.ToUpper(addr), ":", "-", -1) - } - - if out, _ := dockerCmd(c, args...); !strings.Contains(out, expected) { - c.Fatalf("Output should have contained %q: %s", expected, out) - } -} - -func (s *DockerSuite) TestRunNetHost(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - - hostNet, err := os.Readlink("/proc/1/ns/net") - if err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "run", "--net=host", "busybox", "readlink", "/proc/self/ns/net") - out = strings.Trim(out, "\n") - if hostNet != out { - c.Fatalf("Net namespace different with --net=host %s != %s\n", hostNet, out) - } - - out, _ = dockerCmd(c, "run", "busybox", "readlink", "/proc/self/ns/net") - out = strings.Trim(out, "\n") - if hostNet == out { - c.Fatalf("Net namespace should be different without --net=host %s == %s\n", hostNet, out) - } -} - -func (s *DockerSuite) TestRunNetHostTwiceSameName(c *check.C) { - // TODO Windows. As Windows networking evolves and converges towards - // CNM, this test may be possible to enable on Windows. - testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - - dockerCmd(c, "run", "--rm", "--name=thost", "--net=host", "busybox", "true") - dockerCmd(c, "run", "--rm", "--name=thost", "--net=host", "busybox", "true") -} - -func (s *DockerSuite) TestRunNetContainerWhichHost(c *check.C) { - // Not applicable on Windows as uses Unix-specific capabilities - testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - - hostNet, err := os.Readlink("/proc/1/ns/net") - if err != nil { - c.Fatal(err) - } - - dockerCmd(c, "run", "-d", "--net=host", "--name=test", "busybox", "top") - - out, _ := dockerCmd(c, "run", "--net=container:test", "busybox", "readlink", "/proc/self/ns/net") - out = strings.Trim(out, "\n") - if hostNet != out { - c.Fatalf("Container should have host network namespace") - } -} - -func (s *DockerSuite) TestRunAllowPortRangeThroughPublish(c *check.C) { - // TODO Windows. This may be possible to enable in the future. However, - // Windows does not currently support --expose, or populate the network - // settings seen through inspect. - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "--expose", "3000-3003", "-p", "3000-3003", "busybox", "top") - - id := strings.TrimSpace(out) - portstr := inspectFieldJSON(c, id, "NetworkSettings.Ports") - - var ports nat.PortMap - err := json.Unmarshal([]byte(portstr), &ports) - c.Assert(err, checker.IsNil, check.Commentf("failed to unmarshal: %v", portstr)) - for port, binding := range ports { - portnum, _ := strconv.Atoi(strings.Split(string(port), "/")[0]) - if portnum < 3000 || portnum > 3003 { - c.Fatalf("Port %d is out of range ", portnum) - } - if binding == nil || len(binding) != 1 || len(binding[0].HostPort) == 0 { - c.Fatal("Port is not mapped for the port "+port, out) - } - } -} - -func (s *DockerSuite) TestRunSetDefaultRestartPolicy(c *check.C) { - runSleepingContainer(c, "--name=testrunsetdefaultrestartpolicy") - out := inspectField(c, "testrunsetdefaultrestartpolicy", "HostConfig.RestartPolicy.Name") - if out != "no" { - c.Fatalf("Set default restart policy failed") - } -} - -func (s *DockerSuite) TestRunRestartMaxRetries(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "false") - timeout := 10 * time.Second - if daemonPlatform == "windows" { - timeout = 120 * time.Second - } - - id := strings.TrimSpace(string(out)) - if err := waitInspect(id, "{{ .State.Restarting }} {{ .State.Running }}", "false false", timeout); err != nil { - c.Fatal(err) - } - - count := inspectField(c, id, "RestartCount") - if count != "3" { - c.Fatalf("Container was restarted %s times, expected %d", count, 3) - } - - MaximumRetryCount := inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount") - if MaximumRetryCount != "3" { - c.Fatalf("Container Maximum Retry Count is %s, expected %s", MaximumRetryCount, "3") - } -} - -func (s *DockerSuite) TestRunContainerWithWritableRootfs(c *check.C) { - dockerCmd(c, "run", "--rm", "busybox", "touch", "/file") -} - -func (s *DockerSuite) TestRunContainerWithReadonlyRootfs(c *check.C) { - // Not applicable on Windows which does not support --read-only - testRequires(c, DaemonIsLinux, UserNamespaceROMount) - - testPriv := true - // don't test privileged mode subtest if user namespaces enabled - if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" { - testPriv = false - } - testReadOnlyFile(c, testPriv, "/file", "/etc/hosts", "/etc/resolv.conf", "/etc/hostname", "/sys/kernel", "/dev/.dont.touch.me") -} - -func (s *DockerSuite) TestPermissionsPtsReadonlyRootfs(c *check.C) { - // Not applicable on Windows due to use of Unix specific functionality, plus - // the use of --read-only which is not supported. - testRequires(c, DaemonIsLinux, UserNamespaceROMount) - - // Ensure we have not broken writing /dev/pts - out, status := dockerCmd(c, "run", "--read-only", "--rm", "busybox", "mount") - if status != 0 { - c.Fatal("Could not obtain mounts when checking /dev/pts mntpnt.") - } - expected := "type devpts (rw," - if !strings.Contains(string(out), expected) { - c.Fatalf("expected output to contain %s but contains %s", expected, out) - } -} - -func testReadOnlyFile(c *check.C, testPriv bool, filenames ...string) { - touch := "touch " + strings.Join(filenames, " ") - out, _, err := dockerCmdWithError("run", "--read-only", "--rm", "busybox", "sh", "-c", touch) - c.Assert(err, checker.NotNil) - - for _, f := range filenames { - expected := "touch: " + f + ": Read-only file system" - c.Assert(out, checker.Contains, expected) - } - - if !testPriv { - return - } - - out, _, err = dockerCmdWithError("run", "--read-only", "--privileged", "--rm", "busybox", "sh", "-c", touch) - c.Assert(err, checker.NotNil) - - for _, f := range filenames { - expected := "touch: " + f + ": Read-only file system" - c.Assert(out, checker.Contains, expected) - } -} - -func (s *DockerSuite) TestRunContainerWithReadonlyEtcHostsAndLinkedContainer(c *check.C) { - // Not applicable on Windows which does not support --link - testRequires(c, DaemonIsLinux, UserNamespaceROMount) - - dockerCmd(c, "run", "-d", "--name", "test-etc-hosts-ro-linked", "busybox", "top") - - out, _ := dockerCmd(c, "run", "--read-only", "--link", "test-etc-hosts-ro-linked:testlinked", "busybox", "cat", "/etc/hosts") - if !strings.Contains(string(out), "testlinked") { - c.Fatal("Expected /etc/hosts to be updated even if --read-only enabled") - } -} - -func (s *DockerSuite) TestRunContainerWithReadonlyRootfsWithDNSFlag(c *check.C) { - // Not applicable on Windows which does not support either --read-only or --dns. - testRequires(c, DaemonIsLinux, UserNamespaceROMount) - - out, _ := dockerCmd(c, "run", "--read-only", "--dns", "1.1.1.1", "busybox", "/bin/cat", "/etc/resolv.conf") - if !strings.Contains(string(out), "1.1.1.1") { - c.Fatal("Expected /etc/resolv.conf to be updated even if --read-only enabled and --dns flag used") - } -} - -func (s *DockerSuite) TestRunContainerWithReadonlyRootfsWithAddHostFlag(c *check.C) { - // Not applicable on Windows which does not support --read-only - testRequires(c, DaemonIsLinux, UserNamespaceROMount) - - out, _ := dockerCmd(c, "run", "--read-only", "--add-host", "testreadonly:127.0.0.1", "busybox", "/bin/cat", "/etc/hosts") - if !strings.Contains(string(out), "testreadonly") { - c.Fatal("Expected /etc/hosts to be updated even if --read-only enabled and --add-host flag used") - } -} - -func (s *DockerSuite) TestRunVolumesFromRestartAfterRemoved(c *check.C) { - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - runSleepingContainer(c, "--name=voltest", "-v", prefix+"/foo") - runSleepingContainer(c, "--name=restarter", "--volumes-from", "voltest") - - // Remove the main volume container and restart the consuming container - dockerCmd(c, "rm", "-f", "voltest") - - // This should not fail since the volumes-from were already applied - dockerCmd(c, "restart", "restarter") -} - -// run container with --rm should remove container if exit code != 0 -func (s *DockerSuite) TestRunContainerWithRmFlagExitCodeNotEqualToZero(c *check.C) { - name := "flowers" - out, _, err := dockerCmdWithError("run", "--name", name, "--rm", "busybox", "ls", "/notexists") - if err == nil { - c.Fatal("Expected docker run to fail", out, err) - } - - out, err = getAllContainers() - if err != nil { - c.Fatal(out, err) - } - - if out != "" { - c.Fatal("Expected not to have containers", out) - } -} - -func (s *DockerSuite) TestRunContainerWithRmFlagCannotStartContainer(c *check.C) { - name := "sparkles" - out, _, err := dockerCmdWithError("run", "--name", name, "--rm", "busybox", "commandNotFound") - if err == nil { - c.Fatal("Expected docker run to fail", out, err) - } - - out, err = getAllContainers() - if err != nil { - c.Fatal(out, err) - } - - if out != "" { - c.Fatal("Expected not to have containers", out) - } -} - -func (s *DockerSuite) TestRunPIDHostWithChildIsKillable(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux, NotUserNamespace) - name := "ibuildthecloud" - dockerCmd(c, "run", "-d", "--pid=host", "--name", name, "busybox", "sh", "-c", "sleep 30; echo hi") - - c.Assert(waitRun(name), check.IsNil) - - errchan := make(chan error) - go func() { - if out, _, err := dockerCmdWithError("kill", name); err != nil { - errchan <- fmt.Errorf("%v:\n%s", err, out) - } - close(errchan) - }() - select { - case err := <-errchan: - c.Assert(err, check.IsNil) - case <-time.After(5 * time.Second): - c.Fatal("Kill container timed out") - } -} - -func (s *DockerSuite) TestRunWithTooSmallMemoryLimit(c *check.C) { - // TODO Windows. This may be possible to enable once Windows supports - // memory limits on containers - testRequires(c, DaemonIsLinux) - // this memory limit is 1 byte less than the min, which is 4MB - // https://github.com/docker/docker/blob/v1.5.0/daemon/create.go#L22 - out, _, err := dockerCmdWithError("run", "-m", "4194303", "busybox") - if err == nil || !strings.Contains(out, "Minimum memory limit allowed is 4MB") { - c.Fatalf("expected run to fail when using too low a memory limit: %q", out) - } -} - -func (s *DockerSuite) TestRunWriteToProcAsound(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - _, code, err := dockerCmdWithError("run", "busybox", "sh", "-c", "echo 111 >> /proc/asound/version") - if err == nil || code == 0 { - c.Fatal("standard container should not be able to write to /proc/asound") - } -} - -func (s *DockerSuite) TestRunReadProcTimer(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - out, code, err := dockerCmdWithError("run", "busybox", "cat", "/proc/timer_stats") - if code != 0 { - return - } - if err != nil { - c.Fatal(err) - } - if strings.Trim(out, "\n ") != "" { - c.Fatalf("expected to receive no output from /proc/timer_stats but received %q", out) - } -} - -func (s *DockerSuite) TestRunReadProcLatency(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - // some kernels don't have this configured so skip the test if this file is not found - // on the host running the tests. - if _, err := os.Stat("/proc/latency_stats"); err != nil { - c.Skip("kernel doesn't have latency_stats configured") - return - } - out, code, err := dockerCmdWithError("run", "busybox", "cat", "/proc/latency_stats") - if code != 0 { - return - } - if err != nil { - c.Fatal(err) - } - if strings.Trim(out, "\n ") != "" { - c.Fatalf("expected to receive no output from /proc/latency_stats but received %q", out) - } -} - -func (s *DockerSuite) TestRunReadFilteredProc(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, Apparmor, DaemonIsLinux, NotUserNamespace) - - testReadPaths := []string{ - "/proc/latency_stats", - "/proc/timer_stats", - "/proc/kcore", - } - for i, filePath := range testReadPaths { - name := fmt.Sprintf("procsieve-%d", i) - shellCmd := fmt.Sprintf("exec 3<%s", filePath) - - out, exitCode, err := dockerCmdWithError("run", "--privileged", "--security-opt", "apparmor=docker-default", "--name", name, "busybox", "sh", "-c", shellCmd) - if exitCode != 0 { - return - } - if err != nil { - c.Fatalf("Open FD for read should have failed with permission denied, got: %s, %v", out, err) - } - } -} - -func (s *DockerSuite) TestMountIntoProc(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - _, code, err := dockerCmdWithError("run", "-v", "/proc//sys", "busybox", "true") - if err == nil || code == 0 { - c.Fatal("container should not be able to mount into /proc") - } -} - -func (s *DockerSuite) TestMountIntoSys(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - testRequires(c, NotUserNamespace) - dockerCmd(c, "run", "-v", "/sys/fs/cgroup", "busybox", "true") -} - -func (s *DockerSuite) TestRunUnshareProc(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, Apparmor, DaemonIsLinux, NotUserNamespace) - - // In this test goroutines are used to run test cases in parallel to prevent the test from taking a long time to run. - errChan := make(chan error) - - go func() { - name := "acidburn" - out, _, err := dockerCmdWithError("run", "--name", name, "--security-opt", "seccomp=unconfined", "debian:jessie", "unshare", "-p", "-m", "-f", "-r", "--mount-proc=/proc", "mount") - if err == nil || - !(strings.Contains(strings.ToLower(out), "permission denied") || - strings.Contains(strings.ToLower(out), "operation not permitted")) { - errChan <- fmt.Errorf("unshare with --mount-proc should have failed with 'permission denied' or 'operation not permitted', got: %s, %v", out, err) - } else { - errChan <- nil - } - }() - - go func() { - name := "cereal" - out, _, err := dockerCmdWithError("run", "--name", name, "--security-opt", "seccomp=unconfined", "debian:jessie", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc") - if err == nil || - !(strings.Contains(strings.ToLower(out), "mount: cannot mount none") || - strings.Contains(strings.ToLower(out), "permission denied") || - strings.Contains(strings.ToLower(out), "operation not permitted")) { - errChan <- fmt.Errorf("unshare and mount of /proc should have failed with 'mount: cannot mount none' or 'permission denied', got: %s, %v", out, err) - } else { - errChan <- nil - } - }() - - /* Ensure still fails if running privileged with the default policy */ - go func() { - name := "crashoverride" - out, _, err := dockerCmdWithError("run", "--privileged", "--security-opt", "seccomp=unconfined", "--security-opt", "apparmor=docker-default", "--name", name, "debian:jessie", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc") - if err == nil || - !(strings.Contains(strings.ToLower(out), "mount: cannot mount none") || - strings.Contains(strings.ToLower(out), "permission denied") || - strings.Contains(strings.ToLower(out), "operation not permitted")) { - errChan <- fmt.Errorf("privileged unshare with apparmor should have failed with 'mount: cannot mount none' or 'permission denied', got: %s, %v", out, err) - } else { - errChan <- nil - } - }() - - for i := 0; i < 3; i++ { - err := <-errChan - if err != nil { - c.Fatal(err) - } - } -} - -func (s *DockerSuite) TestRunPublishPort(c *check.C) { - // TODO Windows: This may be possible once Windows moves to libnetwork and CNM - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name", "test", "--expose", "8080", "busybox", "top") - out, _ := dockerCmd(c, "port", "test") - out = strings.Trim(out, "\r\n") - if out != "" { - c.Fatalf("run without --publish-all should not publish port, out should be nil, but got: %s", out) - } -} - -// Issue #10184. -func (s *DockerSuite) TestDevicePermissions(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - const permissions = "crw-rw-rw-" - out, status := dockerCmd(c, "run", "--device", "/dev/fuse:/dev/fuse:mrw", "busybox:latest", "ls", "-l", "/dev/fuse") - if status != 0 { - c.Fatalf("expected status 0, got %d", status) - } - if !strings.HasPrefix(out, permissions) { - c.Fatalf("output should begin with %q, got %q", permissions, out) - } -} - -func (s *DockerSuite) TestRunCapAddCHOWN(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "--cap-drop=ALL", "--cap-add=CHOWN", "busybox", "sh", "-c", "adduser -D -H newuser && chown newuser /home && echo ok") - - if actual := strings.Trim(out, "\r\n"); actual != "ok" { - c.Fatalf("expected output ok received %s", actual) - } -} - -// https://github.com/docker/docker/pull/14498 -func (s *DockerSuite) TestVolumeFromMixedRWOptions(c *check.C) { - prefix, slash := getPrefixAndSlashFromDaemonPlatform() - - dockerCmd(c, "run", "--name", "parent", "-v", prefix+"/test", "busybox", "true") - - // TODO Windows: Temporary check - remove once TP5 support is dropped - if daemonPlatform != "windows" || windowsDaemonKV >= 14350 { - dockerCmd(c, "run", "--volumes-from", "parent:ro", "--name", "test-volumes-1", "busybox", "true") - } - dockerCmd(c, "run", "--volumes-from", "parent:rw", "--name", "test-volumes-2", "busybox", "true") - - if daemonPlatform != "windows" { - mRO, err := inspectMountPoint("test-volumes-1", prefix+slash+"test") - c.Assert(err, checker.IsNil, check.Commentf("failed to inspect mount point")) - if mRO.RW { - c.Fatalf("Expected RO volume was RW") - } - } - - mRW, err := inspectMountPoint("test-volumes-2", prefix+slash+"test") - c.Assert(err, checker.IsNil, check.Commentf("failed to inspect mount point")) - if !mRW.RW { - c.Fatalf("Expected RW volume was RO") - } -} - -func (s *DockerSuite) TestRunWriteFilteredProc(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, Apparmor, DaemonIsLinux, NotUserNamespace) - - testWritePaths := []string{ - /* modprobe and core_pattern should both be denied by generic - * policy of denials for /proc/sys/kernel. These files have been - * picked to be checked as they are particularly sensitive to writes */ - "/proc/sys/kernel/modprobe", - "/proc/sys/kernel/core_pattern", - "/proc/sysrq-trigger", - "/proc/kcore", - } - for i, filePath := range testWritePaths { - name := fmt.Sprintf("writeprocsieve-%d", i) - - shellCmd := fmt.Sprintf("exec 3>%s", filePath) - out, code, err := dockerCmdWithError("run", "--privileged", "--security-opt", "apparmor=docker-default", "--name", name, "busybox", "sh", "-c", shellCmd) - if code != 0 { - return - } - if err != nil { - c.Fatalf("Open FD for write should have failed with permission denied, got: %s, %v", out, err) - } - } -} - -func (s *DockerSuite) TestRunNetworkFilesBindMount(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, SameHostDaemon, DaemonIsLinux) - - expected := "test123" - - filename := createTmpFile(c, expected) - defer os.Remove(filename) - - nwfiles := []string{"/etc/resolv.conf", "/etc/hosts", "/etc/hostname"} - - for i := range nwfiles { - actual, _ := dockerCmd(c, "run", "-v", filename+":"+nwfiles[i], "busybox", "cat", nwfiles[i]) - if actual != expected { - c.Fatalf("expected %s be: %q, but was: %q", nwfiles[i], expected, actual) - } - } -} - -func (s *DockerSuite) TestRunNetworkFilesBindMountRO(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, SameHostDaemon, DaemonIsLinux) - - filename := createTmpFile(c, "test123") - defer os.Remove(filename) - - nwfiles := []string{"/etc/resolv.conf", "/etc/hosts", "/etc/hostname"} - - for i := range nwfiles { - _, exitCode, err := dockerCmdWithError("run", "-v", filename+":"+nwfiles[i]+":ro", "busybox", "touch", nwfiles[i]) - if err == nil || exitCode == 0 { - c.Fatalf("run should fail because bind mount of %s is ro: exit code %d", nwfiles[i], exitCode) - } - } -} - -func (s *DockerSuite) TestRunNetworkFilesBindMountROFilesystem(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, SameHostDaemon, DaemonIsLinux, UserNamespaceROMount) - - filename := createTmpFile(c, "test123") - defer os.Remove(filename) - - nwfiles := []string{"/etc/resolv.conf", "/etc/hosts", "/etc/hostname"} - - for i := range nwfiles { - _, exitCode := dockerCmd(c, "run", "-v", filename+":"+nwfiles[i], "--read-only", "busybox", "touch", nwfiles[i]) - if exitCode != 0 { - c.Fatalf("run should not fail because %s is mounted writable on read-only root filesystem: exit code %d", nwfiles[i], exitCode) - } - } - - for i := range nwfiles { - _, exitCode, err := dockerCmdWithError("run", "-v", filename+":"+nwfiles[i]+":ro", "--read-only", "busybox", "touch", nwfiles[i]) - if err == nil || exitCode == 0 { - c.Fatalf("run should fail because %s is mounted read-only on read-only root filesystem: exit code %d", nwfiles[i], exitCode) - } - } -} - -func (s *DockerTrustSuite) TestTrustedRun(c *check.C) { - // Windows does not support this functionality - testRequires(c, DaemonIsLinux) - repoName := s.setupTrustedImage(c, "trusted-run") - - // Try run - runCmd := exec.Command(dockerBinary, "run", repoName) - s.trustedCmd(runCmd) - out, _, err := runCommandWithOutput(runCmd) - if err != nil { - c.Fatalf("Error running trusted run: %s\n%s\n", err, out) - } - - if !strings.Contains(string(out), "Tagging") { - c.Fatalf("Missing expected output on trusted push:\n%s", out) - } - - dockerCmd(c, "rmi", repoName) - - // Try untrusted run to ensure we pushed the tag to the registry - runCmd = exec.Command(dockerBinary, "run", "--disable-content-trust=true", repoName) - s.trustedCmd(runCmd) - out, _, err = runCommandWithOutput(runCmd) - if err != nil { - c.Fatalf("Error running trusted run: %s\n%s", err, out) - } - - if !strings.Contains(string(out), "Status: Downloaded") { - c.Fatalf("Missing expected output on trusted run with --disable-content-trust:\n%s", out) - } -} - -func (s *DockerTrustSuite) TestUntrustedRun(c *check.C) { - // Windows does not support this functionality - testRequires(c, DaemonIsLinux) - repoName := fmt.Sprintf("%v/dockercliuntrusted/runtest:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - dockerCmd(c, "push", repoName) - dockerCmd(c, "rmi", repoName) - - // Try trusted run on untrusted tag - runCmd := exec.Command(dockerBinary, "run", repoName) - s.trustedCmd(runCmd) - out, _, err := runCommandWithOutput(runCmd) - if err == nil { - c.Fatalf("Error expected when running trusted run with:\n%s", out) - } - - if !strings.Contains(string(out), "does not have trust data for") { - c.Fatalf("Missing expected output on trusted run:\n%s", out) - } -} - -func (s *DockerTrustSuite) TestRunWhenCertExpired(c *check.C) { - // Windows does not support this functionality - testRequires(c, DaemonIsLinux) - c.Skip("Currently changes system time, causing instability") - repoName := s.setupTrustedImage(c, "trusted-run-expired") - - // Certificates have 10 years of expiration - elevenYearsFromNow := time.Now().Add(time.Hour * 24 * 365 * 11) - - runAtDifferentDate(elevenYearsFromNow, func() { - // Try run - runCmd := exec.Command(dockerBinary, "run", repoName) - s.trustedCmd(runCmd) - out, _, err := runCommandWithOutput(runCmd) - if err == nil { - c.Fatalf("Error running trusted run in the distant future: %s\n%s", err, out) - } - - if !strings.Contains(string(out), "could not validate the path to a trusted root") { - c.Fatalf("Missing expected output on trusted run in the distant future:\n%s", out) - } - }) - - runAtDifferentDate(elevenYearsFromNow, func() { - // Try run - runCmd := exec.Command(dockerBinary, "run", "--disable-content-trust", repoName) - s.trustedCmd(runCmd) - out, _, err := runCommandWithOutput(runCmd) - if err != nil { - c.Fatalf("Error running untrusted run in the distant future: %s\n%s", err, out) - } - - if !strings.Contains(string(out), "Status: Downloaded") { - c.Fatalf("Missing expected output on untrusted run in the distant future:\n%s", out) - } - }) -} - -func (s *DockerTrustSuite) TestTrustedRunFromBadTrustServer(c *check.C) { - // Windows does not support this functionality - testRequires(c, DaemonIsLinux) - repoName := fmt.Sprintf("%v/dockerclievilrun/trusted:latest", privateRegistryURL) - evilLocalConfigDir, err := ioutil.TempDir("", "evilrun-local-config-dir") - if err != nil { - c.Fatalf("Failed to create local temp dir") - } - - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - if err != nil { - c.Fatalf("Error running trusted push: %s\n%s", err, out) - } - if !strings.Contains(string(out), "Signing and pushing trust metadata") { - c.Fatalf("Missing expected output on trusted push:\n%s", out) - } - - dockerCmd(c, "rmi", repoName) - - // Try run - runCmd := exec.Command(dockerBinary, "run", repoName) - s.trustedCmd(runCmd) - out, _, err = runCommandWithOutput(runCmd) - if err != nil { - c.Fatalf("Error running trusted run: %s\n%s", err, out) - } - - if !strings.Contains(string(out), "Tagging") { - c.Fatalf("Missing expected output on trusted push:\n%s", out) - } - - dockerCmd(c, "rmi", repoName) - - // Kill the notary server, start a new "evil" one. - s.not.Close() - s.not, err = newTestNotary(c) - if err != nil { - c.Fatalf("Restarting notary server failed.") - } - - // In order to make an evil server, lets re-init a client (with a different trust dir) and push new data. - // tag an image and upload it to the private registry - dockerCmd(c, "--config", evilLocalConfigDir, "tag", "busybox", repoName) - - // Push up to the new server - pushCmd = exec.Command(dockerBinary, "--config", evilLocalConfigDir, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err = runCommandWithOutput(pushCmd) - if err != nil { - c.Fatalf("Error running trusted push: %s\n%s", err, out) - } - if !strings.Contains(string(out), "Signing and pushing trust metadata") { - c.Fatalf("Missing expected output on trusted push:\n%s", out) - } - - // Now, try running with the original client from this new trust server. This should fail because the new root is invalid. - runCmd = exec.Command(dockerBinary, "run", repoName) - s.trustedCmd(runCmd) - out, _, err = runCommandWithOutput(runCmd) - - if err == nil { - c.Fatalf("Continuing with cached data even though it's an invalid root rotation: %s\n%s", err, out) - } - if !strings.Contains(out, "could not rotate trust to a new trusted root") { - c.Fatalf("Missing expected output on trusted run:\n%s", out) - } -} - -func (s *DockerSuite) TestPtraceContainerProcsFromHost(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux, SameHostDaemon) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), check.IsNil) - pid1 := inspectField(c, id, "State.Pid") - - _, err := os.Readlink(fmt.Sprintf("/proc/%s/ns/net", pid1)) - if err != nil { - c.Fatal(err) - } -} - -func (s *DockerSuite) TestAppArmorDeniesPtrace(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, SameHostDaemon, Apparmor, DaemonIsLinux) - - // Run through 'sh' so we are NOT pid 1. Pid 1 may be able to trace - // itself, but pid>1 should not be able to trace pid1. - _, exitCode, _ := dockerCmdWithError("run", "busybox", "sh", "-c", "sh -c readlink /proc/1/ns/net") - if exitCode == 0 { - c.Fatal("ptrace was not successfully restricted by AppArmor") - } -} - -func (s *DockerSuite) TestAppArmorTraceSelf(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux, SameHostDaemon, Apparmor) - - _, exitCode, _ := dockerCmdWithError("run", "busybox", "readlink", "/proc/1/ns/net") - if exitCode != 0 { - c.Fatal("ptrace of self failed.") - } -} - -func (s *DockerSuite) TestAppArmorDeniesChmodProc(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, SameHostDaemon, Apparmor, DaemonIsLinux, NotUserNamespace) - _, exitCode, _ := dockerCmdWithError("run", "busybox", "chmod", "744", "/proc/cpuinfo") - if exitCode == 0 { - // If our test failed, attempt to repair the host system... - _, exitCode, _ := dockerCmdWithError("run", "busybox", "chmod", "444", "/proc/cpuinfo") - if exitCode == 0 { - c.Fatal("AppArmor was unsuccessful in prohibiting chmod of /proc/* files.") - } - } -} - -func (s *DockerSuite) TestRunCapAddSYSTIME(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - - dockerCmd(c, "run", "--cap-drop=ALL", "--cap-add=SYS_TIME", "busybox", "sh", "-c", "grep ^CapEff /proc/self/status | sed 's/^CapEff:\t//' | grep ^0000000002000000$") -} - -// run create container failed should clean up the container -func (s *DockerSuite) TestRunCreateContainerFailedCleanUp(c *check.C) { - // TODO Windows. This may be possible to enable once link is supported - testRequires(c, DaemonIsLinux) - name := "unique_name" - _, _, err := dockerCmdWithError("run", "--name", name, "--link", "nothing:nothing", "busybox") - c.Assert(err, check.NotNil, check.Commentf("Expected docker run to fail!")) - - containerID, err := inspectFieldWithError(name, "Id") - c.Assert(err, checker.NotNil, check.Commentf("Expected not to have this container: %s!", containerID)) - c.Assert(containerID, check.Equals, "", check.Commentf("Expected not to have this container: %s!", containerID)) -} - -func (s *DockerSuite) TestRunNamedVolume(c *check.C) { - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "--name=test", "-v", "testing:"+prefix+"/foo", "busybox", "sh", "-c", "echo hello > "+prefix+"/foo/bar") - - out, _ := dockerCmd(c, "run", "--volumes-from", "test", "busybox", "sh", "-c", "cat "+prefix+"/foo/bar") - c.Assert(strings.TrimSpace(out), check.Equals, "hello") - - out, _ = dockerCmd(c, "run", "-v", "testing:"+prefix+"/foo", "busybox", "sh", "-c", "cat "+prefix+"/foo/bar") - c.Assert(strings.TrimSpace(out), check.Equals, "hello") -} - -func (s *DockerSuite) TestRunWithUlimits(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "--name=testulimits", "--ulimit", "nofile=42", "busybox", "/bin/sh", "-c", "ulimit -n") - ul := strings.TrimSpace(out) - if ul != "42" { - c.Fatalf("expected `ulimit -n` to be 42, got %s", ul) - } -} - -func (s *DockerSuite) TestRunContainerWithCgroupParent(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - - cgroupParent := "test" - name := "cgroup-test" - - out, _, err := dockerCmdWithError("run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup") - if err != nil { - c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err) - } - cgroupPaths := parseCgroupPaths(string(out)) - if len(cgroupPaths) == 0 { - c.Fatalf("unexpected output - %q", string(out)) - } - id, err := getIDByName(name) - c.Assert(err, check.IsNil) - expectedCgroup := path.Join(cgroupParent, id) - found := false - for _, path := range cgroupPaths { - if strings.HasSuffix(path, expectedCgroup) { - found = true - break - } - } - if !found { - c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths) - } -} - -func (s *DockerSuite) TestRunContainerWithCgroupParentAbsPath(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - - cgroupParent := "/cgroup-parent/test" - name := "cgroup-test" - out, _, err := dockerCmdWithError("run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup") - if err != nil { - c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err) - } - cgroupPaths := parseCgroupPaths(string(out)) - if len(cgroupPaths) == 0 { - c.Fatalf("unexpected output - %q", string(out)) - } - id, err := getIDByName(name) - c.Assert(err, check.IsNil) - expectedCgroup := path.Join(cgroupParent, id) - found := false - for _, path := range cgroupPaths { - if strings.HasSuffix(path, expectedCgroup) { - found = true - break - } - } - if !found { - c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths) - } -} - -// TestRunInvalidCgroupParent checks that a specially-crafted cgroup parent doesn't cause Docker to crash or start modifying /. -func (s *DockerSuite) TestRunInvalidCgroupParent(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - - cgroupParent := "../../../../../../../../SHOULD_NOT_EXIST" - cleanCgroupParent := "SHOULD_NOT_EXIST" - name := "cgroup-invalid-test" - - out, _, err := dockerCmdWithError("run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup") - if err != nil { - // XXX: This may include a daemon crash. - c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err) - } - - // We expect "/SHOULD_NOT_EXIST" to not exist. If not, we have a security issue. - if _, err := os.Stat("/SHOULD_NOT_EXIST"); err == nil || !os.IsNotExist(err) { - c.Fatalf("SECURITY: --cgroup-parent with ../../ relative paths cause files to be created in the host (this is bad) !!") - } - - cgroupPaths := parseCgroupPaths(string(out)) - if len(cgroupPaths) == 0 { - c.Fatalf("unexpected output - %q", string(out)) - } - id, err := getIDByName(name) - c.Assert(err, check.IsNil) - expectedCgroup := path.Join(cleanCgroupParent, id) - found := false - for _, path := range cgroupPaths { - if strings.HasSuffix(path, expectedCgroup) { - found = true - break - } - } - if !found { - c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths) - } -} - -// TestRunInvalidCgroupParent checks that a specially-crafted cgroup parent doesn't cause Docker to crash or start modifying /. -func (s *DockerSuite) TestRunAbsoluteInvalidCgroupParent(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - testRequires(c, DaemonIsLinux) - - cgroupParent := "/../../../../../../../../SHOULD_NOT_EXIST" - cleanCgroupParent := "/SHOULD_NOT_EXIST" - name := "cgroup-absolute-invalid-test" - - out, _, err := dockerCmdWithError("run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup") - if err != nil { - // XXX: This may include a daemon crash. - c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err) - } - - // We expect "/SHOULD_NOT_EXIST" to not exist. If not, we have a security issue. - if _, err := os.Stat("/SHOULD_NOT_EXIST"); err == nil || !os.IsNotExist(err) { - c.Fatalf("SECURITY: --cgroup-parent with /../../ garbage paths cause files to be created in the host (this is bad) !!") - } - - cgroupPaths := parseCgroupPaths(string(out)) - if len(cgroupPaths) == 0 { - c.Fatalf("unexpected output - %q", string(out)) - } - id, err := getIDByName(name) - c.Assert(err, check.IsNil) - expectedCgroup := path.Join(cleanCgroupParent, id) - found := false - for _, path := range cgroupPaths { - if strings.HasSuffix(path, expectedCgroup) { - found = true - break - } - } - if !found { - c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths) - } -} - -func (s *DockerSuite) TestRunContainerWithCgroupMountRO(c *check.C) { - // Not applicable on Windows as uses Unix specific functionality - // --read-only + userns has remount issues - testRequires(c, DaemonIsLinux, NotUserNamespace) - - filename := "/sys/fs/cgroup/devices/test123" - out, _, err := dockerCmdWithError("run", "busybox", "touch", filename) - if err == nil { - c.Fatal("expected cgroup mount point to be read-only, touch file should fail") - } - expected := "Read-only file system" - if !strings.Contains(out, expected) { - c.Fatalf("expected output from failure to contain %s but contains %s", expected, out) - } -} - -func (s *DockerSuite) TestRunContainerNetworkModeToSelf(c *check.C) { - // Not applicable on Windows which does not support --net=container - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "--name=me", "--net=container:me", "busybox", "true") - if err == nil || !strings.Contains(out, "cannot join own network") { - c.Fatalf("using container net mode to self should result in an error\nerr: %q\nout: %s", err, out) - } -} - -func (s *DockerSuite) TestRunContainerNetModeWithDNSMacHosts(c *check.C) { - // Not applicable on Windows which does not support --net=container - testRequires(c, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "-d", "--name", "parent", "busybox", "top") - if err != nil { - c.Fatalf("failed to run container: %v, output: %q", err, out) - } - - out, _, err = dockerCmdWithError("run", "--dns", "1.2.3.4", "--net=container:parent", "busybox") - if err == nil || !strings.Contains(out, runconfig.ErrConflictNetworkAndDNS.Error()) { - c.Fatalf("run --net=container with --dns should error out") - } - - out, _, err = dockerCmdWithError("run", "--mac-address", "92:d0:c6:0a:29:33", "--net=container:parent", "busybox") - if err == nil || !strings.Contains(out, runconfig.ErrConflictContainerNetworkAndMac.Error()) { - c.Fatalf("run --net=container with --mac-address should error out") - } - - out, _, err = dockerCmdWithError("run", "--add-host", "test:192.168.2.109", "--net=container:parent", "busybox") - if err == nil || !strings.Contains(out, runconfig.ErrConflictNetworkHosts.Error()) { - c.Fatalf("run --net=container with --add-host should error out") - } -} - -func (s *DockerSuite) TestRunContainerNetModeWithExposePort(c *check.C) { - // Not applicable on Windows which does not support --net=container - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top") - - out, _, err := dockerCmdWithError("run", "-p", "5000:5000", "--net=container:parent", "busybox") - if err == nil || !strings.Contains(out, runconfig.ErrConflictNetworkPublishPorts.Error()) { - c.Fatalf("run --net=container with -p should error out") - } - - out, _, err = dockerCmdWithError("run", "-P", "--net=container:parent", "busybox") - if err == nil || !strings.Contains(out, runconfig.ErrConflictNetworkPublishPorts.Error()) { - c.Fatalf("run --net=container with -P should error out") - } - - out, _, err = dockerCmdWithError("run", "--expose", "5000", "--net=container:parent", "busybox") - if err == nil || !strings.Contains(out, runconfig.ErrConflictNetworkExposePorts.Error()) { - c.Fatalf("run --net=container with --expose should error out") - } -} - -func (s *DockerSuite) TestRunLinkToContainerNetMode(c *check.C) { - // Not applicable on Windows which does not support --net=container or --link - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "--name", "test", "-d", "busybox", "top") - dockerCmd(c, "run", "--name", "parent", "-d", "--net=container:test", "busybox", "top") - dockerCmd(c, "run", "-d", "--link=parent:parent", "busybox", "top") - dockerCmd(c, "run", "--name", "child", "-d", "--net=container:parent", "busybox", "top") - dockerCmd(c, "run", "-d", "--link=child:child", "busybox", "top") -} - -func (s *DockerSuite) TestRunLoopbackOnlyExistsWhenNetworkingDisabled(c *check.C) { - // TODO Windows: This may be possible to convert. - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "--net=none", "busybox", "ip", "-o", "-4", "a", "show", "up") - - var ( - count = 0 - parts = strings.Split(out, "\n") - ) - - for _, l := range parts { - if l != "" { - count++ - } - } - - if count != 1 { - c.Fatalf("Wrong interface count in container %d", count) - } - - if !strings.HasPrefix(out, "1: lo") { - c.Fatalf("Wrong interface in test container: expected [1: lo], got %s", out) - } -} - -// Issue #4681 -func (s *DockerSuite) TestRunLoopbackWhenNetworkDisabled(c *check.C) { - if daemonPlatform == "windows" { - dockerCmd(c, "run", "--net=none", WindowsBaseImage, "ping", "-n", "1", "127.0.0.1") - } else { - dockerCmd(c, "run", "--net=none", "busybox", "ping", "-c", "1", "127.0.0.1") - } -} - -func (s *DockerSuite) TestRunModeNetContainerHostname(c *check.C) { - // Windows does not support --net=container - testRequires(c, DaemonIsLinux, ExecSupport) - - dockerCmd(c, "run", "-i", "-d", "--name", "parent", "busybox", "top") - out, _ := dockerCmd(c, "exec", "parent", "cat", "/etc/hostname") - out1, _ := dockerCmd(c, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname") - - if out1 != out { - c.Fatal("containers with shared net namespace should have same hostname") - } -} - -func (s *DockerSuite) TestRunNetworkNotInitializedNoneMode(c *check.C) { - // TODO Windows: Network settings are not currently propagated. This may - // be resolved in the future with the move to libnetwork and CNM. - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "--net=none", "busybox", "top") - id := strings.TrimSpace(out) - res := inspectField(c, id, "NetworkSettings.Networks.none.IPAddress") - if res != "" { - c.Fatalf("For 'none' mode network must not be initialized, but container got IP: %s", res) - } -} - -func (s *DockerSuite) TestTwoContainersInNetHost(c *check.C) { - // Not applicable as Windows does not support --net=host - testRequires(c, DaemonIsLinux, NotUserNamespace, NotUserNamespace) - dockerCmd(c, "run", "-d", "--net=host", "--name=first", "busybox", "top") - dockerCmd(c, "run", "-d", "--net=host", "--name=second", "busybox", "top") - dockerCmd(c, "stop", "first") - dockerCmd(c, "stop", "second") -} - -func (s *DockerSuite) TestContainersInUserDefinedNetwork(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork") - dockerCmd(c, "run", "-d", "--net=testnetwork", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-t", "--net=testnetwork", "--name=second", "busybox", "ping", "-c", "1", "first") -} - -func (s *DockerSuite) TestContainersInMultipleNetworks(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - // Create 2 networks using bridge driver - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1") - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork2") - // Run and connect containers to testnetwork1 - dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - // Check connectivity between containers in testnetwork2 - dockerCmd(c, "exec", "first", "ping", "-c", "1", "second.testnetwork1") - // Connect containers to testnetwork2 - dockerCmd(c, "network", "connect", "testnetwork2", "first") - dockerCmd(c, "network", "connect", "testnetwork2", "second") - // Check connectivity between containers - dockerCmd(c, "exec", "second", "ping", "-c", "1", "first.testnetwork2") -} - -func (s *DockerSuite) TestContainersNetworkIsolation(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - // Create 2 networks using bridge driver - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1") - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork2") - // Run 1 container in testnetwork1 and another in testnetwork2 - dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--net=testnetwork2", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // Check Isolation between containers : ping must fail - _, _, err := dockerCmdWithError("exec", "first", "ping", "-c", "1", "second") - c.Assert(err, check.NotNil) - // Connect first container to testnetwork2 - dockerCmd(c, "network", "connect", "testnetwork2", "first") - // ping must succeed now - _, _, err = dockerCmdWithError("exec", "first", "ping", "-c", "1", "second") - c.Assert(err, check.IsNil) - - // Disconnect first container from testnetwork2 - dockerCmd(c, "network", "disconnect", "testnetwork2", "first") - // ping must fail again - _, _, err = dockerCmdWithError("exec", "first", "ping", "-c", "1", "second") - c.Assert(err, check.NotNil) -} - -func (s *DockerSuite) TestNetworkRmWithActiveContainers(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - // Create 2 networks using bridge driver - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1") - // Run and connect containers to testnetwork1 - dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - // Network delete with active containers must fail - _, _, err := dockerCmdWithError("network", "rm", "testnetwork1") - c.Assert(err, check.NotNil) - - dockerCmd(c, "stop", "first") - _, _, err = dockerCmdWithError("network", "rm", "testnetwork1") - c.Assert(err, check.NotNil) -} - -func (s *DockerSuite) TestContainerRestartInMultipleNetworks(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - // Create 2 networks using bridge driver - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1") - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork2") - - // Run and connect containers to testnetwork1 - dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - // Check connectivity between containers in testnetwork2 - dockerCmd(c, "exec", "first", "ping", "-c", "1", "second.testnetwork1") - // Connect containers to testnetwork2 - dockerCmd(c, "network", "connect", "testnetwork2", "first") - dockerCmd(c, "network", "connect", "testnetwork2", "second") - // Check connectivity between containers - dockerCmd(c, "exec", "second", "ping", "-c", "1", "first.testnetwork2") - - // Stop second container and test ping failures on both networks - dockerCmd(c, "stop", "second") - _, _, err := dockerCmdWithError("exec", "first", "ping", "-c", "1", "second.testnetwork1") - c.Assert(err, check.NotNil) - _, _, err = dockerCmdWithError("exec", "first", "ping", "-c", "1", "second.testnetwork2") - c.Assert(err, check.NotNil) - - // Start second container and connectivity must be restored on both networks - dockerCmd(c, "start", "second") - dockerCmd(c, "exec", "first", "ping", "-c", "1", "second.testnetwork1") - dockerCmd(c, "exec", "second", "ping", "-c", "1", "first.testnetwork2") -} - -func (s *DockerSuite) TestContainerWithConflictingHostNetworks(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - // Run a container with --net=host - dockerCmd(c, "run", "-d", "--net=host", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - - // Create a network using bridge driver - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1") - - // Connecting to the user defined network must fail - _, _, err := dockerCmdWithError("network", "connect", "testnetwork1", "first") - c.Assert(err, check.NotNil) -} - -func (s *DockerSuite) TestContainerWithConflictingSharedNetwork(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - // Run second container in first container's network namespace - dockerCmd(c, "run", "-d", "--net=container:first", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // Create a network using bridge driver - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1") - - // Connecting to the user defined network must fail - out, _, err := dockerCmdWithError("network", "connect", "testnetwork1", "second") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, runconfig.ErrConflictSharedNetwork.Error()) -} - -func (s *DockerSuite) TestContainerWithConflictingNoneNetwork(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "-d", "--net=none", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - - // Create a network using bridge driver - dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1") - - // Connecting to the user defined network must fail - out, _, err := dockerCmdWithError("network", "connect", "testnetwork1", "first") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, runconfig.ErrConflictNoNetwork.Error()) - - // create a container connected to testnetwork1 - dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // Connect second container to none network. it must fail as well - _, _, err = dockerCmdWithError("network", "connect", "none", "second") - c.Assert(err, check.NotNil) -} - -// #11957 - stdin with no tty does not exit if stdin is not closed even though container exited -func (s *DockerSuite) TestRunStdinBlockedAfterContainerExit(c *check.C) { - cmd := exec.Command(dockerBinary, "run", "-i", "--name=test", "busybox", "true") - in, err := cmd.StdinPipe() - c.Assert(err, check.IsNil) - defer in.Close() - stdout := bytes.NewBuffer(nil) - cmd.Stdout = stdout - cmd.Stderr = stdout - c.Assert(cmd.Start(), check.IsNil) - - waitChan := make(chan error) - go func() { - waitChan <- cmd.Wait() - }() - - select { - case err := <-waitChan: - c.Assert(err, check.IsNil, check.Commentf(stdout.String())) - case <-time.After(30 * time.Second): - c.Fatal("timeout waiting for command to exit") - } -} - -func (s *DockerSuite) TestRunWrongCpusetCpusFlagValue(c *check.C) { - // TODO Windows: This needs validation (error out) in the daemon. - testRequires(c, DaemonIsLinux) - out, exitCode, err := dockerCmdWithError("run", "--cpuset-cpus", "1-10,11--", "busybox", "true") - c.Assert(err, check.NotNil) - expected := "Error response from daemon: Invalid value 1-10,11-- for cpuset cpus.\n" - if !(strings.Contains(out, expected) || exitCode == 125) { - c.Fatalf("Expected output to contain %q with exitCode 125, got out: %q exitCode: %v", expected, out, exitCode) - } -} - -func (s *DockerSuite) TestRunWrongCpusetMemsFlagValue(c *check.C) { - // TODO Windows: This needs validation (error out) in the daemon. - testRequires(c, DaemonIsLinux) - out, exitCode, err := dockerCmdWithError("run", "--cpuset-mems", "1-42--", "busybox", "true") - c.Assert(err, check.NotNil) - expected := "Error response from daemon: Invalid value 1-42-- for cpuset mems.\n" - if !(strings.Contains(out, expected) || exitCode == 125) { - c.Fatalf("Expected output to contain %q with exitCode 125, got out: %q exitCode: %v", expected, out, exitCode) - } -} - -// TestRunNonExecutableCmd checks that 'docker run busybox foo' exits with error code 127' -func (s *DockerSuite) TestRunNonExecutableCmd(c *check.C) { - name := "testNonExecutableCmd" - runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "foo") - _, exit, _ := runCommandWithOutput(runCmd) - stateExitCode := findContainerExitCode(c, name) - if !(exit == 127 && strings.Contains(stateExitCode, "127")) { - c.Fatalf("Run non-executable command should have errored with exit code 127, but we got exit: %d, State.ExitCode: %s", exit, stateExitCode) - } -} - -// TestRunNonExistingCmd checks that 'docker run busybox /bin/foo' exits with code 127. -func (s *DockerSuite) TestRunNonExistingCmd(c *check.C) { - name := "testNonExistingCmd" - runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "/bin/foo") - _, exit, _ := runCommandWithOutput(runCmd) - stateExitCode := findContainerExitCode(c, name) - if !(exit == 127 && strings.Contains(stateExitCode, "127")) { - c.Fatalf("Run non-existing command should have errored with exit code 127, but we got exit: %d, State.ExitCode: %s", exit, stateExitCode) - } -} - -// TestCmdCannotBeInvoked checks that 'docker run busybox /etc' exits with 126, or -// 127 on Windows. The difference is that in Windows, the container must be started -// as that's when the check is made (and yes, by its design...) -func (s *DockerSuite) TestCmdCannotBeInvoked(c *check.C) { - expected := 126 - if daemonPlatform == "windows" { - expected = 127 - } - name := "testCmdCannotBeInvoked" - runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "/etc") - _, exit, _ := runCommandWithOutput(runCmd) - stateExitCode := findContainerExitCode(c, name) - if !(exit == expected && strings.Contains(stateExitCode, strconv.Itoa(expected))) { - c.Fatalf("Run cmd that cannot be invoked should have errored with code %d, but we got exit: %d, State.ExitCode: %s", expected, exit, stateExitCode) - } -} - -// TestRunNonExistingImage checks that 'docker run foo' exits with error msg 125 and contains 'Unable to find image' -func (s *DockerSuite) TestRunNonExistingImage(c *check.C) { - runCmd := exec.Command(dockerBinary, "run", "foo") - out, exit, err := runCommandWithOutput(runCmd) - if !(err != nil && exit == 125 && strings.Contains(out, "Unable to find image")) { - c.Fatalf("Run non-existing image should have errored with 'Unable to find image' code 125, but we got out: %s, exit: %d, err: %s", out, exit, err) - } -} - -// TestDockerFails checks that 'docker run -foo busybox' exits with 125 to signal docker run failed -func (s *DockerSuite) TestDockerFails(c *check.C) { - runCmd := exec.Command(dockerBinary, "run", "-foo", "busybox") - out, exit, err := runCommandWithOutput(runCmd) - if !(err != nil && exit == 125) { - c.Fatalf("Docker run with flag not defined should exit with 125, but we got out: %s, exit: %d, err: %s", out, exit, err) - } -} - -// TestRunInvalidReference invokes docker run with a bad reference. -func (s *DockerSuite) TestRunInvalidReference(c *check.C) { - out, exit, _ := dockerCmdWithError("run", "busybox@foo") - if exit == 0 { - c.Fatalf("expected non-zero exist code; received %d", exit) - } - - if !strings.Contains(out, "Error parsing reference") { - c.Fatalf(`Expected "Error parsing reference" in output; got: %s`, out) - } -} - -// Test fix for issue #17854 -func (s *DockerSuite) TestRunInitLayerPathOwnership(c *check.C) { - // Not applicable on Windows as it does not support Linux uid/gid ownership - testRequires(c, DaemonIsLinux) - name := "testetcfileownership" - _, err := buildImage(name, - `FROM busybox - RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd - RUN echo 'dockerio:x:1001:' >> /etc/group - RUN chown dockerio:dockerio /etc`, - true) - if err != nil { - c.Fatal(err) - } - - // Test that dockerio ownership of /etc is retained at runtime - out, _ := dockerCmd(c, "run", "--rm", name, "stat", "-c", "%U:%G", "/etc") - out = strings.TrimSpace(out) - if out != "dockerio:dockerio" { - c.Fatalf("Wrong /etc ownership: expected dockerio:dockerio, got %q", out) - } -} - -func (s *DockerSuite) TestRunWithOomScoreAdj(c *check.C) { - testRequires(c, DaemonIsLinux) - - expected := "642" - out, _ := dockerCmd(c, "run", "--oom-score-adj", expected, "busybox", "cat", "/proc/self/oom_score_adj") - oomScoreAdj := strings.TrimSpace(out) - if oomScoreAdj != "642" { - c.Fatalf("Expected oom_score_adj set to %q, got %q instead", expected, oomScoreAdj) - } -} - -func (s *DockerSuite) TestRunWithOomScoreAdjInvalidRange(c *check.C) { - testRequires(c, DaemonIsLinux) - - out, _, err := dockerCmdWithError("run", "--oom-score-adj", "1001", "busybox", "true") - c.Assert(err, check.NotNil) - expected := "Invalid value 1001, range for oom score adj is [-1000, 1000]." - if !strings.Contains(out, expected) { - c.Fatalf("Expected output to contain %q, got %q instead", expected, out) - } - out, _, err = dockerCmdWithError("run", "--oom-score-adj", "-1001", "busybox", "true") - c.Assert(err, check.NotNil) - expected = "Invalid value -1001, range for oom score adj is [-1000, 1000]." - if !strings.Contains(out, expected) { - c.Fatalf("Expected output to contain %q, got %q instead", expected, out) - } -} - -func (s *DockerSuite) TestRunVolumesMountedAsShared(c *check.C) { - // Volume propagation is linux only. Also it creates directories for - // bind mounting, so needs to be same host. - testRequires(c, DaemonIsLinux, SameHostDaemon, NotUserNamespace) - - // Prepare a source directory to bind mount - tmpDir, err := ioutil.TempDir("", "volume-source") - if err != nil { - c.Fatal(err) - } - defer os.RemoveAll(tmpDir) - - if err := os.Mkdir(path.Join(tmpDir, "mnt1"), 0755); err != nil { - c.Fatal(err) - } - - // Convert this directory into a shared mount point so that we do - // not rely on propagation properties of parent mount. - cmd := exec.Command("mount", "--bind", tmpDir, tmpDir) - if _, err = runCommand(cmd); err != nil { - c.Fatal(err) - } - - cmd = exec.Command("mount", "--make-private", "--make-shared", tmpDir) - if _, err = runCommand(cmd); err != nil { - c.Fatal(err) - } - - dockerCmd(c, "run", "--privileged", "-v", fmt.Sprintf("%s:/volume-dest:shared", tmpDir), "busybox", "mount", "--bind", "/volume-dest/mnt1", "/volume-dest/mnt1") - - // Make sure a bind mount under a shared volume propagated to host. - if mounted, _ := mount.Mounted(path.Join(tmpDir, "mnt1")); !mounted { - c.Fatalf("Bind mount under shared volume did not propagate to host") - } - - mount.Unmount(path.Join(tmpDir, "mnt1")) -} - -func (s *DockerSuite) TestRunVolumesMountedAsSlave(c *check.C) { - // Volume propagation is linux only. Also it creates directories for - // bind mounting, so needs to be same host. - testRequires(c, DaemonIsLinux, SameHostDaemon, NotUserNamespace) - - // Prepare a source directory to bind mount - tmpDir, err := ioutil.TempDir("", "volume-source") - if err != nil { - c.Fatal(err) - } - defer os.RemoveAll(tmpDir) - - if err := os.Mkdir(path.Join(tmpDir, "mnt1"), 0755); err != nil { - c.Fatal(err) - } - - // Prepare a source directory with file in it. We will bind mount this - // directory and see if file shows up. - tmpDir2, err := ioutil.TempDir("", "volume-source2") - if err != nil { - c.Fatal(err) - } - defer os.RemoveAll(tmpDir2) - - if err := ioutil.WriteFile(path.Join(tmpDir2, "slave-testfile"), []byte("Test"), 0644); err != nil { - c.Fatal(err) - } - - // Convert this directory into a shared mount point so that we do - // not rely on propagation properties of parent mount. - cmd := exec.Command("mount", "--bind", tmpDir, tmpDir) - if _, err = runCommand(cmd); err != nil { - c.Fatal(err) - } - - cmd = exec.Command("mount", "--make-private", "--make-shared", tmpDir) - if _, err = runCommand(cmd); err != nil { - c.Fatal(err) - } - - dockerCmd(c, "run", "-i", "-d", "--name", "parent", "-v", fmt.Sprintf("%s:/volume-dest:slave", tmpDir), "busybox", "top") - - // Bind mount tmpDir2/ onto tmpDir/mnt1. If mount propagates inside - // container then contents of tmpDir2/slave-testfile should become - // visible at "/volume-dest/mnt1/slave-testfile" - cmd = exec.Command("mount", "--bind", tmpDir2, path.Join(tmpDir, "mnt1")) - if _, err = runCommand(cmd); err != nil { - c.Fatal(err) - } - - out, _ := dockerCmd(c, "exec", "parent", "cat", "/volume-dest/mnt1/slave-testfile") - - mount.Unmount(path.Join(tmpDir, "mnt1")) - - if out != "Test" { - c.Fatalf("Bind mount under slave volume did not propagate to container") - } -} - -func (s *DockerSuite) TestRunNamedVolumesMountedAsShared(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, exitCode, _ := dockerCmdWithError("run", "-v", "foo:/test:shared", "busybox", "touch", "/test/somefile") - c.Assert(exitCode, checker.Not(checker.Equals), 0) - c.Assert(out, checker.Contains, "invalid mount config") -} - -func (s *DockerSuite) TestRunNamedVolumeCopyImageData(c *check.C) { - testRequires(c, DaemonIsLinux) - - testImg := "testvolumecopy" - _, err := buildImage(testImg, ` - FROM busybox - RUN mkdir -p /foo && echo hello > /foo/hello - `, true) - c.Assert(err, check.IsNil) - - dockerCmd(c, "run", "-v", "foo:/foo", testImg) - out, _ := dockerCmd(c, "run", "-v", "foo:/foo", "busybox", "cat", "/foo/hello") - c.Assert(strings.TrimSpace(out), check.Equals, "hello") -} - -func (s *DockerSuite) TestRunNamedVolumeNotRemoved(c *check.C) { - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - - dockerCmd(c, "volume", "create", "test") - - dockerCmd(c, "run", "--rm", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true") - dockerCmd(c, "volume", "inspect", "test") - out, _ := dockerCmd(c, "volume", "ls", "-q") - c.Assert(strings.TrimSpace(out), checker.Equals, "test") - - dockerCmd(c, "run", "--name=test", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true") - dockerCmd(c, "rm", "-fv", "test") - dockerCmd(c, "volume", "inspect", "test") - out, _ = dockerCmd(c, "volume", "ls", "-q") - c.Assert(strings.TrimSpace(out), checker.Equals, "test") -} - -func (s *DockerSuite) TestRunNamedVolumesFromNotRemoved(c *check.C) { - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - - dockerCmd(c, "volume", "create", "test") - dockerCmd(c, "run", "--name=parent", "-v", "test:"+prefix+"/foo", "-v", prefix+"/bar", "busybox", "true") - dockerCmd(c, "run", "--name=child", "--volumes-from=parent", "busybox", "true") - - // Remove the parent so there are not other references to the volumes - dockerCmd(c, "rm", "-f", "parent") - // now remove the child and ensure the named volume (and only the named volume) still exists - dockerCmd(c, "rm", "-fv", "child") - dockerCmd(c, "volume", "inspect", "test") - out, _ := dockerCmd(c, "volume", "ls", "-q") - c.Assert(strings.TrimSpace(out), checker.Equals, "test") -} - -func (s *DockerSuite) TestRunAttachFailedNoLeak(c *check.C) { - nroutines, err := getGoroutineNumber() - c.Assert(err, checker.IsNil) - - runSleepingContainer(c, "--name=test", "-p", "8000:8000") - - // Wait until container is fully up and running - c.Assert(waitRun("test"), check.IsNil) - - out, _, err := dockerCmdWithError("run", "--name=fail", "-p", "8000:8000", "busybox", "true") - // We will need the following `inspect` to diagnose the issue if test fails (#21247) - out1, err1 := dockerCmd(c, "inspect", "--format", "{{json .State}}", "test") - out2, err2 := dockerCmd(c, "inspect", "--format", "{{json .State}}", "fail") - c.Assert(err, checker.NotNil, check.Commentf("Command should have failed but succeeded with: %s\nContainer 'test' [%+v]: %s\nContainer 'fail' [%+v]: %s", out, err1, out1, err2, out2)) - // check for windows error as well - // TODO Windows Post TP5. Fix the error message string - c.Assert(strings.Contains(string(out), "port is already allocated") || - strings.Contains(string(out), "were not connected because a duplicate name exists") || - strings.Contains(string(out), "HNS failed with error : Failed to create endpoint") || - strings.Contains(string(out), "HNS failed with error : The object already exists"), checker.Equals, true, check.Commentf("Output: %s", out)) - dockerCmd(c, "rm", "-f", "test") - - // NGoroutines is not updated right away, so we need to wait before failing - c.Assert(waitForGoroutines(nroutines), checker.IsNil) -} - -// Test for one character directory name case (#20122) -func (s *DockerSuite) TestRunVolumeWithOneCharacter(c *check.C) { - testRequires(c, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-v", "/tmp/q:/foo", "busybox", "sh", "-c", "find /foo") - c.Assert(strings.TrimSpace(out), checker.Equals, "/foo") -} - -func (s *DockerSuite) TestRunVolumeCopyFlag(c *check.C) { - testRequires(c, DaemonIsLinux) // Windows does not support copying data from image to the volume - _, err := buildImage("volumecopy", - `FROM busybox - RUN mkdir /foo && echo hello > /foo/bar - CMD cat /foo/bar`, - true, - ) - c.Assert(err, checker.IsNil) - - dockerCmd(c, "volume", "create", "test") - - // test with the nocopy flag - out, _, err := dockerCmdWithError("run", "-v", "test:/foo:nocopy", "volumecopy") - c.Assert(err, checker.NotNil, check.Commentf(out)) - // test default behavior which is to copy for non-binds - out, _ = dockerCmd(c, "run", "-v", "test:/foo", "volumecopy") - c.Assert(strings.TrimSpace(out), checker.Equals, "hello") - // error out when the volume is already populated - out, _, err = dockerCmdWithError("run", "-v", "test:/foo:copy", "volumecopy") - c.Assert(err, checker.NotNil, check.Commentf(out)) - // do not error out when copy isn't explicitly set even though it's already populated - out, _ = dockerCmd(c, "run", "-v", "test:/foo", "volumecopy") - c.Assert(strings.TrimSpace(out), checker.Equals, "hello") - - // do not allow copy modes on volumes-from - dockerCmd(c, "run", "--name=test", "-v", "/foo", "busybox", "true") - out, _, err = dockerCmdWithError("run", "--volumes-from=test:copy", "busybox", "true") - c.Assert(err, checker.NotNil, check.Commentf(out)) - out, _, err = dockerCmdWithError("run", "--volumes-from=test:nocopy", "busybox", "true") - c.Assert(err, checker.NotNil, check.Commentf(out)) - - // do not allow copy modes on binds - out, _, err = dockerCmdWithError("run", "-v", "/foo:/bar:copy", "busybox", "true") - c.Assert(err, checker.NotNil, check.Commentf(out)) - out, _, err = dockerCmdWithError("run", "-v", "/foo:/bar:nocopy", "busybox", "true") - c.Assert(err, checker.NotNil, check.Commentf(out)) -} - -// Test case for #21976 -func (s *DockerSuite) TestRunDNSInHostMode(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - - expectedOutput := "nameserver 127.0.0.1" - expectedWarning := "Localhost DNS setting" - out, stderr, _ := dockerCmdWithStdoutStderr(c, "run", "--dns=127.0.0.1", "--net=host", "busybox", "cat", "/etc/resolv.conf") - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) - c.Assert(stderr, checker.Contains, expectedWarning, check.Commentf("Expected warning on stderr about localhost resolver, but got %q", stderr)) - - expectedOutput = "nameserver 1.2.3.4" - out, _ = dockerCmd(c, "run", "--dns=1.2.3.4", "--net=host", "busybox", "cat", "/etc/resolv.conf") - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) - - expectedOutput = "search example.com" - out, _ = dockerCmd(c, "run", "--dns-search=example.com", "--net=host", "busybox", "cat", "/etc/resolv.conf") - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) - - expectedOutput = "options timeout:3" - out, _ = dockerCmd(c, "run", "--dns-opt=timeout:3", "--net=host", "busybox", "cat", "/etc/resolv.conf") - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) - - expectedOutput1 := "nameserver 1.2.3.4" - expectedOutput2 := "search example.com" - expectedOutput3 := "options timeout:3" - out, _ = dockerCmd(c, "run", "--dns=1.2.3.4", "--dns-search=example.com", "--dns-opt=timeout:3", "--net=host", "busybox", "cat", "/etc/resolv.conf") - c.Assert(out, checker.Contains, expectedOutput1, check.Commentf("Expected '%s', but got %q", expectedOutput1, out)) - c.Assert(out, checker.Contains, expectedOutput2, check.Commentf("Expected '%s', but got %q", expectedOutput2, out)) - c.Assert(out, checker.Contains, expectedOutput3, check.Commentf("Expected '%s', but got %q", expectedOutput3, out)) -} - -// Test case for #21976 -func (s *DockerSuite) TestRunAddHostInHostMode(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - - expectedOutput := "1.2.3.4\textra" - out, _ := dockerCmd(c, "run", "--add-host=extra:1.2.3.4", "--net=host", "busybox", "cat", "/etc/hosts") - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) -} - -func (s *DockerSuite) TestRunRmAndWait(c *check.C) { - dockerCmd(c, "run", "--name=test", "--rm", "-d", "busybox", "sh", "-c", "sleep 3;exit 2") - - out, code, err := dockerCmdWithError("wait", "test") - c.Assert(err, checker.IsNil, check.Commentf("out: %s; exit code: %d", out, code)) - c.Assert(out, checker.Equals, "2\n", check.Commentf("exit code: %d", code)) - c.Assert(code, checker.Equals, 0) -} - -// Test case for #23498 -func (s *DockerSuite) TestRunUnsetEntrypoint(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "test-entrypoint" - dockerfile := `FROM busybox -ADD entrypoint.sh /entrypoint.sh -RUN chmod 755 /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] -CMD echo foobar` - - ctx, err := fakeContext(dockerfile, map[string]string{ - "entrypoint.sh": `#!/bin/sh -echo "I am an entrypoint" -exec "$@"`, - }) - c.Assert(err, check.IsNil) - defer ctx.Close() - - _, err = buildImageFromContext(name, ctx, true) - c.Assert(err, check.IsNil) - - out, _ := dockerCmd(c, "run", "--entrypoint=", "-t", name, "echo", "foo") - c.Assert(strings.TrimSpace(out), check.Equals, "foo") - - // CMD will be reset as well (the same as setting a custom entrypoint) - _, _, err = dockerCmdWithError("run", "--entrypoint=", "-t", name) - c.Assert(err, check.NotNil) - c.Assert(err.Error(), checker.Contains, "No command specified") -} - -func (s *DockerDaemonSuite) TestRunWithUlimitAndDaemonDefault(c *check.C) { - c.Assert(s.d.StartWithBusybox("--debug", "--default-ulimit=nofile=65535"), checker.IsNil) - - name := "test-A" - _, err := s.d.Cmd("run", "--name", name, "-d", "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(s.d.waitRun(name), check.IsNil) - - out, err := s.d.Cmd("inspect", "--format", "{{.HostConfig.Ulimits}}", name) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "[nofile=65535:65535]") - - name = "test-B" - _, err = s.d.Cmd("run", "--name", name, "--ulimit=nofile=42", "-d", "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(s.d.waitRun(name), check.IsNil) - - out, err = s.d.Cmd("inspect", "--format", "{{.HostConfig.Ulimits}}", name) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "[nofile=42:42]") -} - -func (s *DockerSuite) TestRunStoppedLoggingDriverNoLeak(c *check.C) { - nroutines, err := getGoroutineNumber() - c.Assert(err, checker.IsNil) - - out, _, err := dockerCmdWithError("run", "--name=fail", "--log-driver=splunk", "busybox", "true") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "Failed to initialize logging driver", check.Commentf("error should be about logging driver, got output %s", out)) - - // NGoroutines is not updated right away, so we need to wait before failing - c.Assert(waitForGoroutines(nroutines), checker.IsNil) -} - -// Handles error conditions for --credentialspec. Validating E2E success cases -// requires additional infrastructure (AD for example) on CI servers. -func (s *DockerSuite) TestRunCredentialSpecFailures(c *check.C) { - testRequires(c, DaemonIsWindows) - attempts := []struct{ value, expectedError string }{ - {"rubbish", "invalid credential spec security option - value must be prefixed file:// or registry://"}, - {"rubbish://", "invalid credential spec security option - value must be prefixed file:// or registry://"}, - {"file://", "no value supplied for file:// credential spec security option"}, - {"registry://", "no value supplied for registry:// credential spec security option"}, - {`file://c:\blah.txt`, "path cannot be absolute"}, - {`file://doesnotexist.txt`, "The system cannot find the file specified"}, - } - for _, attempt := range attempts { - _, _, err := dockerCmdWithError("run", "--security-opt=credentialspec="+attempt.value, "busybox", "true") - c.Assert(err, checker.NotNil, check.Commentf("%s expected non-nil err", attempt.value)) - c.Assert(err.Error(), checker.Contains, attempt.expectedError, check.Commentf("%s expected %s got %s", attempt.value, attempt.expectedError, err)) - } -} - -// Windows specific test to validate credential specs with a well-formed spec. -// Note it won't actually do anything in CI configuration with the spec, but -// it should not fail to run a container. -func (s *DockerSuite) TestRunCredentialSpecWellFormed(c *check.C) { - testRequires(c, DaemonIsWindows, SameHostDaemon) - validCS := readFile(`fixtures\credentialspecs\valid.json`, c) - writeFile(filepath.Join(dockerBasePath, `credentialspecs\valid.json`), validCS, c) - dockerCmd(c, "run", `--security-opt=credentialspec=file://valid.json`, "busybox", "true") -} - -// Windows specific test to ensure that a servicing app container is started -// if necessary once a container exits. It does this by forcing a no-op -// servicing event and verifying the event from Hyper-V-Compute -func (s *DockerSuite) TestRunServicingContainer(c *check.C) { - testRequires(c, DaemonIsWindows, SameHostDaemon) - - out, _ := dockerCmd(c, "run", "-d", WindowsBaseImage, "cmd", "/c", "mkdir c:\\programdata\\Microsoft\\Windows\\ContainerUpdates\\000_000_d99f45d0-ffc8-4af7-bd9c-ea6a62e035c9_200 && sc control cexecsvc 255") - containerID := strings.TrimSpace(out) - err := waitExited(containerID, 60*time.Second) - c.Assert(err, checker.IsNil) - - cmd := exec.Command("powershell", "echo", `(Get-WinEvent -ProviderName "Microsoft-Windows-Hyper-V-Compute" -FilterXPath 'Event[System[EventID=2010]]' -MaxEvents 1).Message`) - out2, _, err := runCommandWithOutput(cmd) - c.Assert(err, checker.IsNil) - c.Assert(out2, checker.Contains, `"Servicing":true`, check.Commentf("Servicing container does not appear to have been started: %s", out2)) - c.Assert(out2, checker.Contains, `Windows Container (Servicing)`, check.Commentf("Didn't find 'Windows Container (Servicing): %s", out2)) - c.Assert(out2, checker.Contains, containerID+"_servicing", check.Commentf("Didn't find '%s_servicing': %s", containerID+"_servicing", out2)) -} - -func (s *DockerSuite) TestRunDuplicateMount(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace) - - tmpFile, err := ioutil.TempFile("", "touch-me") - c.Assert(err, checker.IsNil) - defer tmpFile.Close() - - data := "touch-me-foo-bar\n" - if _, err := tmpFile.Write([]byte(data)); err != nil { - c.Fatal(err) - } - - name := "test" - out, _ := dockerCmd(c, "run", "--name", name, "-v", "/tmp:/tmp", "-v", "/tmp:/tmp", "busybox", "sh", "-c", "cat "+tmpFile.Name()+" && ls /") - c.Assert(out, checker.Not(checker.Contains), "tmp:") - c.Assert(out, checker.Contains, data) - - out = inspectFieldJSON(c, name, "Config.Volumes") - c.Assert(out, checker.Contains, "null") -} - -func (s *DockerSuite) TestRunWindowsWithCPUCount(c *check.C) { - testRequires(c, DaemonIsWindows) - - out, _ := dockerCmd(c, "run", "--cpu-count=1", "--name", "test", "busybox", "echo", "testing") - c.Assert(strings.TrimSpace(out), checker.Equals, "testing") - - out = inspectField(c, "test", "HostConfig.CPUCount") - c.Assert(out, check.Equals, "1") -} - -func (s *DockerSuite) TestRunWindowsWithCPUShares(c *check.C) { - testRequires(c, DaemonIsWindows) - - out, _ := dockerCmd(c, "run", "--cpu-shares=1000", "--name", "test", "busybox", "echo", "testing") - c.Assert(strings.TrimSpace(out), checker.Equals, "testing") - - out = inspectField(c, "test", "HostConfig.CPUShares") - c.Assert(out, check.Equals, "1000") -} - -func (s *DockerSuite) TestRunWindowsWithCPUPercent(c *check.C) { - testRequires(c, DaemonIsWindows) - - out, _ := dockerCmd(c, "run", "--cpu-percent=80", "--name", "test", "busybox", "echo", "testing") - c.Assert(strings.TrimSpace(out), checker.Equals, "testing") - - out = inspectField(c, "test", "HostConfig.CPUPercent") - c.Assert(out, check.Equals, "80") -} - -func (s *DockerSuite) TestRunProcessIsolationWithCPUCountCPUSharesAndCPUPercent(c *check.C) { - testRequires(c, DaemonIsWindows, IsolationIsProcess) - - out, _ := dockerCmd(c, "run", "--cpu-count=1", "--cpu-shares=1000", "--cpu-percent=80", "--name", "test", "busybox", "echo", "testing") - c.Assert(strings.TrimSpace(out), checker.Contains, "WARNING: Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded") - c.Assert(strings.TrimSpace(out), checker.Contains, "WARNING: Conflicting options: CPU count takes priority over CPU percent on Windows Server Containers. CPU percent discarded") - c.Assert(strings.TrimSpace(out), checker.Contains, "testing") - - out = inspectField(c, "test", "HostConfig.CPUCount") - c.Assert(out, check.Equals, "1") - - out = inspectField(c, "test", "HostConfig.CPUShares") - c.Assert(out, check.Equals, "0") - - out = inspectField(c, "test", "HostConfig.CPUPercent") - c.Assert(out, check.Equals, "0") -} - -func (s *DockerSuite) TestRunHypervIsolationWithCPUCountCPUSharesAndCPUPercent(c *check.C) { - testRequires(c, DaemonIsWindows, IsolationIsHyperv) - - out, _ := dockerCmd(c, "run", "--cpu-count=1", "--cpu-shares=1000", "--cpu-percent=80", "--name", "test", "busybox", "echo", "testing") - c.Assert(strings.TrimSpace(out), checker.Contains, "testing") - - out = inspectField(c, "test", "HostConfig.CPUCount") - c.Assert(out, check.Equals, "1") - - out = inspectField(c, "test", "HostConfig.CPUShares") - c.Assert(out, check.Equals, "1000") - - out = inspectField(c, "test", "HostConfig.CPUPercent") - c.Assert(out, check.Equals, "80") -} - -// Test for #25099 -func (s *DockerSuite) TestRunEmptyEnv(c *check.C) { - testRequires(c, DaemonIsLinux) - - expectedOutput := "invalid environment variable:" - - out, _, err := dockerCmdWithError("run", "-e", "", "busybox", "true") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, expectedOutput) - - out, _, err = dockerCmdWithError("run", "-e", "=", "busybox", "true") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, expectedOutput) - - out, _, err = dockerCmdWithError("run", "-e", "=foo", "busybox", "true") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, expectedOutput) -} - -// #28658 -func (s *DockerSuite) TestSlowStdinClosing(c *check.C) { - name := "testslowstdinclosing" - repeat := 3 // regression happened 50% of the time - for i := 0; i < repeat; i++ { - cmd := exec.Command(dockerBinary, "run", "--rm", "--name", name, "-i", "busybox", "cat") - cmd.Stdin = &delayedReader{} - done := make(chan error, 1) - go func() { - _, err := runCommand(cmd) - done <- err - }() - - select { - case <-time.After(15 * time.Second): - c.Fatal("running container timed out") // cleanup in teardown - case err := <-done: - c.Assert(err, checker.IsNil) - } - } -} - -type delayedReader struct{} - -func (s *delayedReader) Read([]byte) (int, error) { - time.Sleep(500 * time.Millisecond) - return 0, io.EOF -} - -// #28823 (originally #28639) -func (s *DockerSuite) TestRunMountReadOnlyDevShm(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - emptyDir, err := ioutil.TempDir("", "test-read-only-dev-shm") - c.Assert(err, check.IsNil) - defer os.RemoveAll(emptyDir) - out, _, err := dockerCmdWithError("run", "--rm", "--read-only", - "-v", fmt.Sprintf("%s:/dev/shm:ro", emptyDir), - "busybox", "touch", "/dev/shm/foo") - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Read-only file system") -} - -// Test case for 29129 -func (s *DockerSuite) TestRunHostnameInHostMode(c *check.C) { - testRequires(c, DaemonIsLinux) - - expectedOutput := "foobar\nfoobar" - out, _ := dockerCmd(c, "run", "--net=host", "--hostname=foobar", "busybox", "sh", "-c", `echo $HOSTNAME && hostname`) - c.Assert(strings.TrimSpace(out), checker.Equals, expectedOutput) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_run_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_run_unix_test.go deleted file mode 100644 index e346c19..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_run_unix_test.go +++ /dev/null @@ -1,1592 +0,0 @@ -// +build !windows - -package main - -import ( - "bufio" - "encoding/json" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "regexp" - "strconv" - "strings" - "syscall" - "time" - - "github.com/docker/docker/pkg/homedir" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/parsers" - "github.com/docker/docker/pkg/sysinfo" - "github.com/go-check/check" - "github.com/kr/pty" -) - -// #6509 -func (s *DockerSuite) TestRunRedirectStdout(c *check.C) { - checkRedirect := func(command string) { - _, tty, err := pty.Open() - c.Assert(err, checker.IsNil, check.Commentf("Could not open pty")) - cmd := exec.Command("sh", "-c", command) - cmd.Stdin = tty - cmd.Stdout = tty - cmd.Stderr = tty - c.Assert(cmd.Start(), checker.IsNil) - ch := make(chan error) - go func() { - ch <- cmd.Wait() - close(ch) - }() - - select { - case <-time.After(10 * time.Second): - c.Fatal("command timeout") - case err := <-ch: - c.Assert(err, checker.IsNil, check.Commentf("wait err")) - } - } - - checkRedirect(dockerBinary + " run -i busybox cat /etc/passwd | grep -q root") - checkRedirect(dockerBinary + " run busybox cat /etc/passwd | grep -q root") -} - -// Test recursive bind mount works by default -func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *check.C) { - // /tmp gets permission denied - testRequires(c, NotUserNamespace, SameHostDaemon) - tmpDir, err := ioutil.TempDir("", "docker_recursive_mount_test") - c.Assert(err, checker.IsNil) - - defer os.RemoveAll(tmpDir) - - // Create a temporary tmpfs mount. - tmpfsDir := filepath.Join(tmpDir, "tmpfs") - c.Assert(os.MkdirAll(tmpfsDir, 0777), checker.IsNil, check.Commentf("failed to mkdir at %s", tmpfsDir)) - c.Assert(mount.Mount("tmpfs", tmpfsDir, "tmpfs", ""), checker.IsNil, check.Commentf("failed to create a tmpfs mount at %s", tmpfsDir)) - - f, err := ioutil.TempFile(tmpfsDir, "touch-me") - c.Assert(err, checker.IsNil) - defer f.Close() - - runCmd := exec.Command(dockerBinary, "run", "--name", "test-data", "--volume", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox:latest", "ls", "/tmp/tmpfs") - out, _, _, err := runCommandWithStdoutStderr(runCmd) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, filepath.Base(f.Name()), check.Commentf("Recursive bind mount test failed. Expected file not found")) -} - -func (s *DockerSuite) TestRunDeviceDirectory(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm) - if _, err := os.Stat("/dev/snd"); err != nil { - c.Skip("Host does not have /dev/snd") - } - - out, _ := dockerCmd(c, "run", "--device", "/dev/snd:/dev/snd", "busybox", "sh", "-c", "ls /dev/snd/") - c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "timer", check.Commentf("expected output /dev/snd/timer")) - - out, _ = dockerCmd(c, "run", "--device", "/dev/snd:/dev/othersnd", "busybox", "sh", "-c", "ls /dev/othersnd/") - c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "seq", check.Commentf("expected output /dev/othersnd/seq")) -} - -// TestRunDetach checks attaching and detaching with the default escape sequence. -func (s *DockerSuite) TestRunAttachDetach(c *check.C) { - name := "attach-detach" - - dockerCmd(c, "run", "--name", name, "-itd", "busybox", "cat") - - cmd := exec.Command(dockerBinary, "attach", name) - stdout, err := cmd.StdoutPipe() - c.Assert(err, checker.IsNil) - cpty, tty, err := pty.Open() - c.Assert(err, checker.IsNil) - defer cpty.Close() - cmd.Stdin = tty - c.Assert(cmd.Start(), checker.IsNil) - c.Assert(waitRun(name), check.IsNil) - - _, err = cpty.Write([]byte("hello\n")) - c.Assert(err, checker.IsNil) - - out, err := bufio.NewReader(stdout).ReadString('\n') - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "hello") - - // escape sequence - _, err = cpty.Write([]byte{16}) - c.Assert(err, checker.IsNil) - time.Sleep(100 * time.Millisecond) - _, err = cpty.Write([]byte{17}) - c.Assert(err, checker.IsNil) - - ch := make(chan struct{}) - go func() { - cmd.Wait() - ch <- struct{}{} - }() - - select { - case <-ch: - case <-time.After(10 * time.Second): - c.Fatal("timed out waiting for container to exit") - } - - running := inspectField(c, name, "State.Running") - c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running")) - - out, _ = dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c), "-f", "container="+name) - // attach and detach event should be monitored - c.Assert(out, checker.Contains, "attach") - c.Assert(out, checker.Contains, "detach") -} - -// TestRunDetach checks attaching and detaching with the escape sequence specified via flags. -func (s *DockerSuite) TestRunAttachDetachFromFlag(c *check.C) { - name := "attach-detach" - keyCtrlA := []byte{1} - keyA := []byte{97} - - dockerCmd(c, "run", "--name", name, "-itd", "busybox", "cat") - - cmd := exec.Command(dockerBinary, "attach", "--detach-keys=ctrl-a,a", name) - stdout, err := cmd.StdoutPipe() - if err != nil { - c.Fatal(err) - } - cpty, tty, err := pty.Open() - if err != nil { - c.Fatal(err) - } - defer cpty.Close() - cmd.Stdin = tty - if err := cmd.Start(); err != nil { - c.Fatal(err) - } - c.Assert(waitRun(name), check.IsNil) - - if _, err := cpty.Write([]byte("hello\n")); err != nil { - c.Fatal(err) - } - - out, err := bufio.NewReader(stdout).ReadString('\n') - if err != nil { - c.Fatal(err) - } - if strings.TrimSpace(out) != "hello" { - c.Fatalf("expected 'hello', got %q", out) - } - - // escape sequence - if _, err := cpty.Write(keyCtrlA); err != nil { - c.Fatal(err) - } - time.Sleep(100 * time.Millisecond) - if _, err := cpty.Write(keyA); err != nil { - c.Fatal(err) - } - - ch := make(chan struct{}) - go func() { - cmd.Wait() - ch <- struct{}{} - }() - - select { - case <-ch: - case <-time.After(10 * time.Second): - c.Fatal("timed out waiting for container to exit") - } - - running := inspectField(c, name, "State.Running") - c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running")) -} - -// TestRunDetach checks attaching and detaching with the escape sequence specified via flags. -func (s *DockerSuite) TestRunAttachDetachFromInvalidFlag(c *check.C) { - name := "attach-detach" - dockerCmd(c, "run", "--name", name, "-itd", "busybox", "top") - c.Assert(waitRun(name), check.IsNil) - - // specify an invalid detach key, container will ignore it and use default - cmd := exec.Command(dockerBinary, "attach", "--detach-keys=ctrl-A,a", name) - stdout, err := cmd.StdoutPipe() - if err != nil { - c.Fatal(err) - } - cpty, tty, err := pty.Open() - if err != nil { - c.Fatal(err) - } - defer cpty.Close() - cmd.Stdin = tty - if err := cmd.Start(); err != nil { - c.Fatal(err) - } - - bufReader := bufio.NewReader(stdout) - out, err := bufReader.ReadString('\n') - if err != nil { - c.Fatal(err) - } - // it should print a warning to indicate the detach key flag is invalid - errStr := "Invalid escape keys (ctrl-A,a) provided" - c.Assert(strings.TrimSpace(out), checker.Equals, errStr) -} - -// TestRunDetach checks attaching and detaching with the escape sequence specified via config file. -func (s *DockerSuite) TestRunAttachDetachFromConfig(c *check.C) { - keyCtrlA := []byte{1} - keyA := []byte{97} - - // Setup config - homeKey := homedir.Key() - homeVal := homedir.Get() - tmpDir, err := ioutil.TempDir("", "fake-home") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir) - - dotDocker := filepath.Join(tmpDir, ".docker") - os.Mkdir(dotDocker, 0600) - tmpCfg := filepath.Join(dotDocker, "config.json") - - defer func() { os.Setenv(homeKey, homeVal) }() - os.Setenv(homeKey, tmpDir) - - data := `{ - "detachKeys": "ctrl-a,a" - }` - - err = ioutil.WriteFile(tmpCfg, []byte(data), 0600) - c.Assert(err, checker.IsNil) - - // Then do the work - name := "attach-detach" - dockerCmd(c, "run", "--name", name, "-itd", "busybox", "cat") - - cmd := exec.Command(dockerBinary, "attach", name) - stdout, err := cmd.StdoutPipe() - if err != nil { - c.Fatal(err) - } - cpty, tty, err := pty.Open() - if err != nil { - c.Fatal(err) - } - defer cpty.Close() - cmd.Stdin = tty - if err := cmd.Start(); err != nil { - c.Fatal(err) - } - c.Assert(waitRun(name), check.IsNil) - - if _, err := cpty.Write([]byte("hello\n")); err != nil { - c.Fatal(err) - } - - out, err := bufio.NewReader(stdout).ReadString('\n') - if err != nil { - c.Fatal(err) - } - if strings.TrimSpace(out) != "hello" { - c.Fatalf("expected 'hello', got %q", out) - } - - // escape sequence - if _, err := cpty.Write(keyCtrlA); err != nil { - c.Fatal(err) - } - time.Sleep(100 * time.Millisecond) - if _, err := cpty.Write(keyA); err != nil { - c.Fatal(err) - } - - ch := make(chan struct{}) - go func() { - cmd.Wait() - ch <- struct{}{} - }() - - select { - case <-ch: - case <-time.After(10 * time.Second): - c.Fatal("timed out waiting for container to exit") - } - - running := inspectField(c, name, "State.Running") - c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running")) -} - -// TestRunDetach checks attaching and detaching with the detach flags, making sure it overrides config file -func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *check.C) { - keyCtrlA := []byte{1} - keyA := []byte{97} - - // Setup config - homeKey := homedir.Key() - homeVal := homedir.Get() - tmpDir, err := ioutil.TempDir("", "fake-home") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir) - - dotDocker := filepath.Join(tmpDir, ".docker") - os.Mkdir(dotDocker, 0600) - tmpCfg := filepath.Join(dotDocker, "config.json") - - defer func() { os.Setenv(homeKey, homeVal) }() - os.Setenv(homeKey, tmpDir) - - data := `{ - "detachKeys": "ctrl-e,e" - }` - - err = ioutil.WriteFile(tmpCfg, []byte(data), 0600) - c.Assert(err, checker.IsNil) - - // Then do the work - name := "attach-detach" - dockerCmd(c, "run", "--name", name, "-itd", "busybox", "cat") - - cmd := exec.Command(dockerBinary, "attach", "--detach-keys=ctrl-a,a", name) - stdout, err := cmd.StdoutPipe() - if err != nil { - c.Fatal(err) - } - cpty, tty, err := pty.Open() - if err != nil { - c.Fatal(err) - } - defer cpty.Close() - cmd.Stdin = tty - if err := cmd.Start(); err != nil { - c.Fatal(err) - } - c.Assert(waitRun(name), check.IsNil) - - if _, err := cpty.Write([]byte("hello\n")); err != nil { - c.Fatal(err) - } - - out, err := bufio.NewReader(stdout).ReadString('\n') - if err != nil { - c.Fatal(err) - } - if strings.TrimSpace(out) != "hello" { - c.Fatalf("expected 'hello', got %q", out) - } - - // escape sequence - if _, err := cpty.Write(keyCtrlA); err != nil { - c.Fatal(err) - } - time.Sleep(100 * time.Millisecond) - if _, err := cpty.Write(keyA); err != nil { - c.Fatal(err) - } - - ch := make(chan struct{}) - go func() { - cmd.Wait() - ch <- struct{}{} - }() - - select { - case <-ch: - case <-time.After(10 * time.Second): - c.Fatal("timed out waiting for container to exit") - } - - running := inspectField(c, name, "State.Running") - c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running")) -} - -func (s *DockerSuite) TestRunAttachInvalidDetachKeySequencePreserved(c *check.C) { - name := "attach-detach" - keyA := []byte{97} - keyB := []byte{98} - - dockerCmd(c, "run", "--name", name, "-itd", "busybox", "cat") - - cmd := exec.Command(dockerBinary, "attach", "--detach-keys=a,b,c", name) - stdout, err := cmd.StdoutPipe() - if err != nil { - c.Fatal(err) - } - cpty, tty, err := pty.Open() - if err != nil { - c.Fatal(err) - } - defer cpty.Close() - cmd.Stdin = tty - if err := cmd.Start(); err != nil { - c.Fatal(err) - } - c.Assert(waitRun(name), check.IsNil) - - // Invalid escape sequence aba, should print aba in output - if _, err := cpty.Write(keyA); err != nil { - c.Fatal(err) - } - time.Sleep(100 * time.Millisecond) - if _, err := cpty.Write(keyB); err != nil { - c.Fatal(err) - } - time.Sleep(100 * time.Millisecond) - if _, err := cpty.Write(keyA); err != nil { - c.Fatal(err) - } - time.Sleep(100 * time.Millisecond) - if _, err := cpty.Write([]byte("\n")); err != nil { - c.Fatal(err) - } - - out, err := bufio.NewReader(stdout).ReadString('\n') - if err != nil { - c.Fatal(err) - } - if strings.TrimSpace(out) != "aba" { - c.Fatalf("expected 'aba', got %q", out) - } -} - -// "test" should be printed -func (s *DockerSuite) TestRunWithCPUQuota(c *check.C) { - testRequires(c, cpuCfsQuota) - - file := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us" - out, _ := dockerCmd(c, "run", "--cpu-quota", "8000", "--name", "test", "busybox", "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "8000") - - out = inspectField(c, "test", "HostConfig.CpuQuota") - c.Assert(out, checker.Equals, "8000", check.Commentf("setting the CPU CFS quota failed")) -} - -func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) { - testRequires(c, cpuCfsPeriod) - - file := "/sys/fs/cgroup/cpu/cpu.cfs_period_us" - out, _ := dockerCmd(c, "run", "--cpu-period", "50000", "--name", "test", "busybox", "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "50000") - - out, _ = dockerCmd(c, "run", "--cpu-period", "0", "busybox", "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "100000") - - out = inspectField(c, "test", "HostConfig.CpuPeriod") - c.Assert(out, checker.Equals, "50000", check.Commentf("setting the CPU CFS period failed")) -} - -func (s *DockerSuite) TestRunWithInvalidCpuPeriod(c *check.C) { - testRequires(c, cpuCfsPeriod) - out, _, err := dockerCmdWithError("run", "--cpu-period", "900", "busybox", "true") - c.Assert(err, check.NotNil) - expected := "CPU cfs period can not be less than 1ms (i.e. 1000) or larger than 1s (i.e. 1000000)" - c.Assert(out, checker.Contains, expected) - - out, _, err = dockerCmdWithError("run", "--cpu-period", "2000000", "busybox", "true") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, expected) - - out, _, err = dockerCmdWithError("run", "--cpu-period", "-3", "busybox", "true") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, expected) -} - -func (s *DockerSuite) TestRunWithKernelMemory(c *check.C) { - testRequires(c, kernelMemorySupport) - - file := "/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes" - stdout, _, _ := dockerCmdWithStdoutStderr(c, "run", "--kernel-memory", "50M", "--name", "test1", "busybox", "cat", file) - c.Assert(strings.TrimSpace(stdout), checker.Equals, "52428800") - - out := inspectField(c, "test1", "HostConfig.KernelMemory") - c.Assert(out, check.Equals, "52428800") -} - -func (s *DockerSuite) TestRunWithInvalidKernelMemory(c *check.C) { - testRequires(c, kernelMemorySupport) - - out, _, err := dockerCmdWithError("run", "--kernel-memory", "2M", "busybox", "true") - c.Assert(err, check.NotNil) - expected := "Minimum kernel memory limit allowed is 4MB" - c.Assert(out, checker.Contains, expected) - - out, _, err = dockerCmdWithError("run", "--kernel-memory", "-16m", "--name", "test2", "busybox", "echo", "test") - c.Assert(err, check.NotNil) - expected = "invalid size" - c.Assert(out, checker.Contains, expected) -} - -func (s *DockerSuite) TestRunWithCPUShares(c *check.C) { - testRequires(c, cpuShare) - - file := "/sys/fs/cgroup/cpu/cpu.shares" - out, _ := dockerCmd(c, "run", "--cpu-shares", "1000", "--name", "test", "busybox", "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "1000") - - out = inspectField(c, "test", "HostConfig.CPUShares") - c.Assert(out, check.Equals, "1000") -} - -// "test" should be printed -func (s *DockerSuite) TestRunEchoStdoutWithCPUSharesAndMemoryLimit(c *check.C) { - testRequires(c, cpuShare) - testRequires(c, memoryLimitSupport) - out, _, _ := dockerCmdWithStdoutStderr(c, "run", "--cpu-shares", "1000", "-m", "32m", "busybox", "echo", "test") - c.Assert(out, checker.Equals, "test\n", check.Commentf("container should've printed 'test'")) -} - -func (s *DockerSuite) TestRunWithCpusetCpus(c *check.C) { - testRequires(c, cgroupCpuset) - - file := "/sys/fs/cgroup/cpuset/cpuset.cpus" - out, _ := dockerCmd(c, "run", "--cpuset-cpus", "0", "--name", "test", "busybox", "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - out = inspectField(c, "test", "HostConfig.CpusetCpus") - c.Assert(out, check.Equals, "0") -} - -func (s *DockerSuite) TestRunWithCpusetMems(c *check.C) { - testRequires(c, cgroupCpuset) - - file := "/sys/fs/cgroup/cpuset/cpuset.mems" - out, _ := dockerCmd(c, "run", "--cpuset-mems", "0", "--name", "test", "busybox", "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - out = inspectField(c, "test", "HostConfig.CpusetMems") - c.Assert(out, check.Equals, "0") -} - -func (s *DockerSuite) TestRunWithBlkioWeight(c *check.C) { - testRequires(c, blkioWeight) - - file := "/sys/fs/cgroup/blkio/blkio.weight" - out, _ := dockerCmd(c, "run", "--blkio-weight", "300", "--name", "test", "busybox", "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "300") - - out = inspectField(c, "test", "HostConfig.BlkioWeight") - c.Assert(out, check.Equals, "300") -} - -func (s *DockerSuite) TestRunWithInvalidBlkioWeight(c *check.C) { - testRequires(c, blkioWeight) - out, _, err := dockerCmdWithError("run", "--blkio-weight", "5", "busybox", "true") - c.Assert(err, check.NotNil, check.Commentf(out)) - expected := "Range of blkio weight is from 10 to 1000" - c.Assert(out, checker.Contains, expected) -} - -func (s *DockerSuite) TestRunWithInvalidPathforBlkioWeightDevice(c *check.C) { - testRequires(c, blkioWeight) - out, _, err := dockerCmdWithError("run", "--blkio-weight-device", "/dev/sdX:100", "busybox", "true") - c.Assert(err, check.NotNil, check.Commentf(out)) -} - -func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceReadBps(c *check.C) { - testRequires(c, blkioWeight) - out, _, err := dockerCmdWithError("run", "--device-read-bps", "/dev/sdX:500", "busybox", "true") - c.Assert(err, check.NotNil, check.Commentf(out)) -} - -func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceWriteBps(c *check.C) { - testRequires(c, blkioWeight) - out, _, err := dockerCmdWithError("run", "--device-write-bps", "/dev/sdX:500", "busybox", "true") - c.Assert(err, check.NotNil, check.Commentf(out)) -} - -func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceReadIOps(c *check.C) { - testRequires(c, blkioWeight) - out, _, err := dockerCmdWithError("run", "--device-read-iops", "/dev/sdX:500", "busybox", "true") - c.Assert(err, check.NotNil, check.Commentf(out)) -} - -func (s *DockerSuite) TestRunWithInvalidPathforBlkioDeviceWriteIOps(c *check.C) { - testRequires(c, blkioWeight) - out, _, err := dockerCmdWithError("run", "--device-write-iops", "/dev/sdX:500", "busybox", "true") - c.Assert(err, check.NotNil, check.Commentf(out)) -} - -func (s *DockerSuite) TestRunOOMExitCode(c *check.C) { - testRequires(c, memoryLimitSupport, swapMemorySupport) - errChan := make(chan error) - go func() { - defer close(errChan) - out, exitCode, _ := dockerCmdWithError("run", "-m", "4MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done") - if expected := 137; exitCode != expected { - errChan <- fmt.Errorf("wrong exit code for OOM container: expected %d, got %d (output: %q)", expected, exitCode, out) - } - }() - - select { - case err := <-errChan: - c.Assert(err, check.IsNil) - case <-time.After(600 * time.Second): - c.Fatal("Timeout waiting for container to die on OOM") - } -} - -func (s *DockerSuite) TestRunWithMemoryLimit(c *check.C) { - testRequires(c, memoryLimitSupport) - - file := "/sys/fs/cgroup/memory/memory.limit_in_bytes" - stdout, _, _ := dockerCmdWithStdoutStderr(c, "run", "-m", "32M", "--name", "test", "busybox", "cat", file) - c.Assert(strings.TrimSpace(stdout), checker.Equals, "33554432") - - out := inspectField(c, "test", "HostConfig.Memory") - c.Assert(out, check.Equals, "33554432") -} - -// TestRunWithoutMemoryswapLimit sets memory limit and disables swap -// memory limit, this means the processes in the container can use -// 16M memory and as much swap memory as they need (if the host -// supports swap memory). -func (s *DockerSuite) TestRunWithoutMemoryswapLimit(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - testRequires(c, swapMemorySupport) - dockerCmd(c, "run", "-m", "32m", "--memory-swap", "-1", "busybox", "true") -} - -func (s *DockerSuite) TestRunWithSwappiness(c *check.C) { - testRequires(c, memorySwappinessSupport) - file := "/sys/fs/cgroup/memory/memory.swappiness" - out, _ := dockerCmd(c, "run", "--memory-swappiness", "0", "--name", "test", "busybox", "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "0") - - out = inspectField(c, "test", "HostConfig.MemorySwappiness") - c.Assert(out, check.Equals, "0") -} - -func (s *DockerSuite) TestRunWithSwappinessInvalid(c *check.C) { - testRequires(c, memorySwappinessSupport) - out, _, err := dockerCmdWithError("run", "--memory-swappiness", "101", "busybox", "true") - c.Assert(err, check.NotNil) - expected := "Valid memory swappiness range is 0-100" - c.Assert(out, checker.Contains, expected, check.Commentf("Expected output to contain %q, not %q", out, expected)) - - out, _, err = dockerCmdWithError("run", "--memory-swappiness", "-10", "busybox", "true") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, expected, check.Commentf("Expected output to contain %q, not %q", out, expected)) -} - -func (s *DockerSuite) TestRunWithMemoryReservation(c *check.C) { - testRequires(c, memoryReservationSupport) - - file := "/sys/fs/cgroup/memory/memory.soft_limit_in_bytes" - out, _ := dockerCmd(c, "run", "--memory-reservation", "200M", "--name", "test", "busybox", "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "209715200") - - out = inspectField(c, "test", "HostConfig.MemoryReservation") - c.Assert(out, check.Equals, "209715200") -} - -func (s *DockerSuite) TestRunWithMemoryReservationInvalid(c *check.C) { - testRequires(c, memoryLimitSupport) - testRequires(c, memoryReservationSupport) - out, _, err := dockerCmdWithError("run", "-m", "500M", "--memory-reservation", "800M", "busybox", "true") - c.Assert(err, check.NotNil) - expected := "Minimum memory limit can not be less than memory reservation limit" - c.Assert(strings.TrimSpace(out), checker.Contains, expected, check.Commentf("run container should fail with invalid memory reservation")) - - out, _, err = dockerCmdWithError("run", "--memory-reservation", "1k", "busybox", "true") - c.Assert(err, check.NotNil) - expected = "Minimum memory reservation allowed is 4MB" - c.Assert(strings.TrimSpace(out), checker.Contains, expected, check.Commentf("run container should fail with invalid memory reservation")) -} - -func (s *DockerSuite) TestStopContainerSignal(c *check.C) { - out, _ := dockerCmd(c, "run", "--stop-signal", "SIGUSR1", "-d", "busybox", "/bin/sh", "-c", `trap 'echo "exit trapped"; exit 0' USR1; while true; do sleep 1; done`) - containerID := strings.TrimSpace(out) - - c.Assert(waitRun(containerID), checker.IsNil) - - dockerCmd(c, "stop", containerID) - out, _ = dockerCmd(c, "logs", containerID) - - c.Assert(out, checker.Contains, "exit trapped", check.Commentf("Expected `exit trapped` in the log")) -} - -func (s *DockerSuite) TestRunSwapLessThanMemoryLimit(c *check.C) { - testRequires(c, memoryLimitSupport) - testRequires(c, swapMemorySupport) - out, _, err := dockerCmdWithError("run", "-m", "16m", "--memory-swap", "15m", "busybox", "echo", "test") - expected := "Minimum memoryswap limit should be larger than memory limit" - c.Assert(err, check.NotNil) - - c.Assert(out, checker.Contains, expected) -} - -func (s *DockerSuite) TestRunInvalidCpusetCpusFlagValue(c *check.C) { - testRequires(c, cgroupCpuset, SameHostDaemon) - - sysInfo := sysinfo.New(true) - cpus, err := parsers.ParseUintList(sysInfo.Cpus) - c.Assert(err, check.IsNil) - var invalid int - for i := 0; i <= len(cpus)+1; i++ { - if !cpus[i] { - invalid = i - break - } - } - out, _, err := dockerCmdWithError("run", "--cpuset-cpus", strconv.Itoa(invalid), "busybox", "true") - c.Assert(err, check.NotNil) - expected := fmt.Sprintf("Error response from daemon: Requested CPUs are not available - requested %s, available: %s", strconv.Itoa(invalid), sysInfo.Cpus) - c.Assert(out, checker.Contains, expected) -} - -func (s *DockerSuite) TestRunInvalidCpusetMemsFlagValue(c *check.C) { - testRequires(c, cgroupCpuset) - - sysInfo := sysinfo.New(true) - mems, err := parsers.ParseUintList(sysInfo.Mems) - c.Assert(err, check.IsNil) - var invalid int - for i := 0; i <= len(mems)+1; i++ { - if !mems[i] { - invalid = i - break - } - } - out, _, err := dockerCmdWithError("run", "--cpuset-mems", strconv.Itoa(invalid), "busybox", "true") - c.Assert(err, check.NotNil) - expected := fmt.Sprintf("Error response from daemon: Requested memory nodes are not available - requested %s, available: %s", strconv.Itoa(invalid), sysInfo.Mems) - c.Assert(out, checker.Contains, expected) -} - -func (s *DockerSuite) TestRunInvalidCPUShares(c *check.C) { - testRequires(c, cpuShare, DaemonIsLinux) - out, _, err := dockerCmdWithError("run", "--cpu-shares", "1", "busybox", "echo", "test") - c.Assert(err, check.NotNil, check.Commentf(out)) - expected := "The minimum allowed cpu-shares is 2" - c.Assert(out, checker.Contains, expected) - - out, _, err = dockerCmdWithError("run", "--cpu-shares", "-1", "busybox", "echo", "test") - c.Assert(err, check.NotNil, check.Commentf(out)) - expected = "shares: invalid argument" - c.Assert(out, checker.Contains, expected) - - out, _, err = dockerCmdWithError("run", "--cpu-shares", "99999999", "busybox", "echo", "test") - c.Assert(err, check.NotNil, check.Commentf(out)) - expected = "The maximum allowed cpu-shares is" - c.Assert(out, checker.Contains, expected) -} - -func (s *DockerSuite) TestRunWithDefaultShmSize(c *check.C) { - testRequires(c, DaemonIsLinux) - - name := "shm-default" - out, _ := dockerCmd(c, "run", "--name", name, "busybox", "mount") - shmRegex := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`) - if !shmRegex.MatchString(out) { - c.Fatalf("Expected shm of 64MB in mount command, got %v", out) - } - shmSize := inspectField(c, name, "HostConfig.ShmSize") - c.Assert(shmSize, check.Equals, "67108864") -} - -func (s *DockerSuite) TestRunWithShmSize(c *check.C) { - testRequires(c, DaemonIsLinux) - - name := "shm" - out, _ := dockerCmd(c, "run", "--name", name, "--shm-size=1G", "busybox", "mount") - shmRegex := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=1048576k`) - if !shmRegex.MatchString(out) { - c.Fatalf("Expected shm of 1GB in mount command, got %v", out) - } - shmSize := inspectField(c, name, "HostConfig.ShmSize") - c.Assert(shmSize, check.Equals, "1073741824") -} - -func (s *DockerSuite) TestRunTmpfsMountsEnsureOrdered(c *check.C) { - tmpFile, err := ioutil.TempFile("", "test") - c.Assert(err, check.IsNil) - defer tmpFile.Close() - out, _ := dockerCmd(c, "run", "--tmpfs", "/run", "-v", tmpFile.Name()+":/run/test", "busybox", "ls", "/run") - c.Assert(out, checker.Contains, "test") -} - -func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) { - // TODO Windows (Post TP5): This test cannot run on a Windows daemon as - // Windows does not support tmpfs mounts. - testRequires(c, DaemonIsLinux) - if out, _, err := dockerCmdWithError("run", "--tmpfs", "/run", "busybox", "touch", "/run/somefile"); err != nil { - c.Fatalf("/run directory not mounted on tmpfs %q %s", err, out) - } - if out, _, err := dockerCmdWithError("run", "--tmpfs", "/run:noexec", "busybox", "touch", "/run/somefile"); err != nil { - c.Fatalf("/run directory not mounted on tmpfs %q %s", err, out) - } - if out, _, err := dockerCmdWithError("run", "--tmpfs", "/run:noexec,nosuid,rw,size=5k,mode=700", "busybox", "touch", "/run/somefile"); err != nil { - c.Fatalf("/run failed to mount on tmpfs with valid options %q %s", err, out) - } - if _, _, err := dockerCmdWithError("run", "--tmpfs", "/run:foobar", "busybox", "touch", "/run/somefile"); err == nil { - c.Fatalf("/run mounted on tmpfs when it should have vailed within invalid mount option") - } - if _, _, err := dockerCmdWithError("run", "--tmpfs", "/run", "-v", "/run:/run", "busybox", "touch", "/run/somefile"); err == nil { - c.Fatalf("Should have generated an error saying Duplicate mount points") - } -} - -func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *check.C) { - name := "img-with-volumes" - _, err := buildImage( - name, - ` - FROM busybox - VOLUME /run - RUN touch /run/stuff - `, - true) - if err != nil { - c.Fatal(err) - } - out, _ := dockerCmd(c, "run", "--tmpfs", "/run", name, "ls", "/run") - c.Assert(out, checker.Not(checker.Contains), "stuff") -} - -// Test case for #22420 -func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *check.C) { - testRequires(c, DaemonIsLinux) - - expectedOptions := []string{"rw", "nosuid", "nodev", "noexec", "relatime"} - out, _ := dockerCmd(c, "run", "--tmpfs", "/tmp", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'") - for _, option := range expectedOptions { - c.Assert(out, checker.Contains, option) - } - c.Assert(out, checker.Not(checker.Contains), "size=") - - expectedOptions = []string{"rw", "nosuid", "nodev", "noexec", "relatime"} - out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:rw", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'") - for _, option := range expectedOptions { - c.Assert(out, checker.Contains, option) - } - c.Assert(out, checker.Not(checker.Contains), "size=") - - expectedOptions = []string{"rw", "nosuid", "nodev", "relatime", "size=8192k"} - out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:rw,exec,size=8192k", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'") - for _, option := range expectedOptions { - c.Assert(out, checker.Contains, option) - } - - expectedOptions = []string{"rw", "nosuid", "nodev", "noexec", "relatime", "size=4096k"} - out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:rw,size=8192k,exec,size=4096k,noexec", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'") - for _, option := range expectedOptions { - c.Assert(out, checker.Contains, option) - } - - // We use debian:jessie as there is no findmnt in busybox. Also the output will be in the format of - // TARGET PROPAGATION - // /tmp shared - // so we only capture `shared` here. - expectedOptions = []string{"shared"} - out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:shared", "debian:jessie", "findmnt", "-o", "TARGET,PROPAGATION", "/tmp") - for _, option := range expectedOptions { - c.Assert(out, checker.Contains, option) - } -} - -func (s *DockerSuite) TestRunSysctls(c *check.C) { - - testRequires(c, DaemonIsLinux) - var err error - - out, _ := dockerCmd(c, "run", "--sysctl", "net.ipv4.ip_forward=1", "--name", "test", "busybox", "cat", "/proc/sys/net/ipv4/ip_forward") - c.Assert(strings.TrimSpace(out), check.Equals, "1") - - out = inspectFieldJSON(c, "test", "HostConfig.Sysctls") - - sysctls := make(map[string]string) - err = json.Unmarshal([]byte(out), &sysctls) - c.Assert(err, check.IsNil) - c.Assert(sysctls["net.ipv4.ip_forward"], check.Equals, "1") - - out, _ = dockerCmd(c, "run", "--sysctl", "net.ipv4.ip_forward=0", "--name", "test1", "busybox", "cat", "/proc/sys/net/ipv4/ip_forward") - c.Assert(strings.TrimSpace(out), check.Equals, "0") - - out = inspectFieldJSON(c, "test1", "HostConfig.Sysctls") - - err = json.Unmarshal([]byte(out), &sysctls) - c.Assert(err, check.IsNil) - c.Assert(sysctls["net.ipv4.ip_forward"], check.Equals, "0") - - runCmd := exec.Command(dockerBinary, "run", "--sysctl", "kernel.foobar=1", "--name", "test2", "busybox", "cat", "/proc/sys/kernel/foobar") - out, _, _ = runCommandWithOutput(runCmd) - if !strings.Contains(out, "invalid argument") { - c.Fatalf("expected --sysctl to fail, got %s", out) - } -} - -// TestRunSeccompProfileDenyUnshare checks that 'docker run --security-opt seccomp=/tmp/profile.json debian:jessie unshare' exits with operation not permitted. -func (s *DockerSuite) TestRunSeccompProfileDenyUnshare(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled, NotArm, Apparmor) - jsonData := `{ - "defaultAction": "SCMP_ACT_ALLOW", - "syscalls": [ - { - "name": "unshare", - "action": "SCMP_ACT_ERRNO" - } - ] -}` - tmpFile, err := ioutil.TempFile("", "profile.json") - if err != nil { - c.Fatal(err) - } - defer tmpFile.Close() - - if _, err := tmpFile.Write([]byte(jsonData)); err != nil { - c.Fatal(err) - } - runCmd := exec.Command(dockerBinary, "run", "--security-opt", "apparmor=unconfined", "--security-opt", "seccomp="+tmpFile.Name(), "debian:jessie", "unshare", "-p", "-m", "-f", "-r", "mount", "-t", "proc", "none", "/proc") - out, _, _ := runCommandWithOutput(runCmd) - if !strings.Contains(out, "Operation not permitted") { - c.Fatalf("expected unshare with seccomp profile denied to fail, got %s", out) - } -} - -// TestRunSeccompProfileDenyChmod checks that 'docker run --security-opt seccomp=/tmp/profile.json busybox chmod 400 /etc/hostname' exits with operation not permitted. -func (s *DockerSuite) TestRunSeccompProfileDenyChmod(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled) - jsonData := `{ - "defaultAction": "SCMP_ACT_ALLOW", - "syscalls": [ - { - "name": "chmod", - "action": "SCMP_ACT_ERRNO" - }, - { - "name":"fchmod", - "action": "SCMP_ACT_ERRNO" - }, - { - "name": "fchmodat", - "action":"SCMP_ACT_ERRNO" - } - ] -}` - tmpFile, err := ioutil.TempFile("", "profile.json") - c.Assert(err, check.IsNil) - defer tmpFile.Close() - - if _, err := tmpFile.Write([]byte(jsonData)); err != nil { - c.Fatal(err) - } - runCmd := exec.Command(dockerBinary, "run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "400", "/etc/hostname") - out, _, _ := runCommandWithOutput(runCmd) - if !strings.Contains(out, "Operation not permitted") { - c.Fatalf("expected chmod with seccomp profile denied to fail, got %s", out) - } -} - -// TestRunSeccompProfileDenyUnshareUserns checks that 'docker run debian:jessie unshare --map-root-user --user sh -c whoami' with a specific profile to -// deny unhare of a userns exits with operation not permitted. -func (s *DockerSuite) TestRunSeccompProfileDenyUnshareUserns(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled, NotArm, Apparmor) - // from sched.h - jsonData := fmt.Sprintf(`{ - "defaultAction": "SCMP_ACT_ALLOW", - "syscalls": [ - { - "name": "unshare", - "action": "SCMP_ACT_ERRNO", - "args": [ - { - "index": 0, - "value": %d, - "op": "SCMP_CMP_EQ" - } - ] - } - ] -}`, uint64(0x10000000)) - tmpFile, err := ioutil.TempFile("", "profile.json") - if err != nil { - c.Fatal(err) - } - defer tmpFile.Close() - - if _, err := tmpFile.Write([]byte(jsonData)); err != nil { - c.Fatal(err) - } - runCmd := exec.Command(dockerBinary, "run", "--security-opt", "apparmor=unconfined", "--security-opt", "seccomp="+tmpFile.Name(), "debian:jessie", "unshare", "--map-root-user", "--user", "sh", "-c", "whoami") - out, _, _ := runCommandWithOutput(runCmd) - if !strings.Contains(out, "Operation not permitted") { - c.Fatalf("expected unshare userns with seccomp profile denied to fail, got %s", out) - } -} - -// TestRunSeccompProfileDenyCloneUserns checks that 'docker run syscall-test' -// with a the default seccomp profile exits with operation not permitted. -func (s *DockerSuite) TestRunSeccompProfileDenyCloneUserns(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled) - ensureSyscallTest(c) - - runCmd := exec.Command(dockerBinary, "run", "syscall-test", "userns-test", "id") - out, _, err := runCommandWithOutput(runCmd) - if err == nil || !strings.Contains(out, "clone failed: Operation not permitted") { - c.Fatalf("expected clone userns with default seccomp profile denied to fail, got %s: %v", out, err) - } -} - -// TestRunSeccompUnconfinedCloneUserns checks that -// 'docker run --security-opt seccomp=unconfined syscall-test' allows creating a userns. -func (s *DockerSuite) TestRunSeccompUnconfinedCloneUserns(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled, UserNamespaceInKernel, NotUserNamespace, unprivilegedUsernsClone) - ensureSyscallTest(c) - - // make sure running w privileged is ok - runCmd := exec.Command(dockerBinary, "run", "--security-opt", "seccomp=unconfined", "syscall-test", "userns-test", "id") - if out, _, err := runCommandWithOutput(runCmd); err != nil || !strings.Contains(out, "nobody") { - c.Fatalf("expected clone userns with --security-opt seccomp=unconfined to succeed, got %s: %v", out, err) - } -} - -// TestRunSeccompAllowPrivCloneUserns checks that 'docker run --privileged syscall-test' -// allows creating a userns. -func (s *DockerSuite) TestRunSeccompAllowPrivCloneUserns(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled, UserNamespaceInKernel, NotUserNamespace) - ensureSyscallTest(c) - - // make sure running w privileged is ok - runCmd := exec.Command(dockerBinary, "run", "--privileged", "syscall-test", "userns-test", "id") - if out, _, err := runCommandWithOutput(runCmd); err != nil || !strings.Contains(out, "nobody") { - c.Fatalf("expected clone userns with --privileged to succeed, got %s: %v", out, err) - } -} - -// TestRunSeccompProfileAllow32Bit checks that 32 bit code can run on x86_64 -// with the default seccomp profile. -func (s *DockerSuite) TestRunSeccompProfileAllow32Bit(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled, IsAmd64) - ensureSyscallTest(c) - - runCmd := exec.Command(dockerBinary, "run", "syscall-test", "exit32-test", "id") - if out, _, err := runCommandWithOutput(runCmd); err != nil { - c.Fatalf("expected to be able to run 32 bit code, got %s: %v", out, err) - } -} - -// TestRunSeccompAllowSetrlimit checks that 'docker run debian:jessie ulimit -v 1048510' succeeds. -func (s *DockerSuite) TestRunSeccompAllowSetrlimit(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled) - - // ulimit uses setrlimit, so we want to make sure we don't break it - runCmd := exec.Command(dockerBinary, "run", "debian:jessie", "bash", "-c", "ulimit -v 1048510") - if out, _, err := runCommandWithOutput(runCmd); err != nil { - c.Fatalf("expected ulimit with seccomp to succeed, got %s: %v", out, err) - } -} - -func (s *DockerSuite) TestRunSeccompDefaultProfileAcct(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled, NotUserNamespace) - ensureSyscallTest(c) - - out, _, err := dockerCmdWithError("run", "syscall-test", "acct-test") - if err == nil || !strings.Contains(out, "Operation not permitted") { - c.Fatalf("test 0: expected Operation not permitted, got: %s", out) - } - - out, _, err = dockerCmdWithError("run", "--cap-add", "sys_admin", "syscall-test", "acct-test") - if err == nil || !strings.Contains(out, "Operation not permitted") { - c.Fatalf("test 1: expected Operation not permitted, got: %s", out) - } - - out, _, err = dockerCmdWithError("run", "--cap-add", "sys_pacct", "syscall-test", "acct-test") - if err == nil || !strings.Contains(out, "No such file or directory") { - c.Fatalf("test 2: expected No such file or directory, got: %s", out) - } - - out, _, err = dockerCmdWithError("run", "--cap-add", "ALL", "syscall-test", "acct-test") - if err == nil || !strings.Contains(out, "No such file or directory") { - c.Fatalf("test 3: expected No such file or directory, got: %s", out) - } - - out, _, err = dockerCmdWithError("run", "--cap-drop", "ALL", "--cap-add", "sys_pacct", "syscall-test", "acct-test") - if err == nil || !strings.Contains(out, "No such file or directory") { - c.Fatalf("test 4: expected No such file or directory, got: %s", out) - } -} - -func (s *DockerSuite) TestRunSeccompDefaultProfileNS(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled, NotUserNamespace) - ensureSyscallTest(c) - - out, _, err := dockerCmdWithError("run", "syscall-test", "ns-test", "echo", "hello0") - if err == nil || !strings.Contains(out, "Operation not permitted") { - c.Fatalf("test 0: expected Operation not permitted, got: %s", out) - } - - out, _, err = dockerCmdWithError("run", "--cap-add", "sys_admin", "syscall-test", "ns-test", "echo", "hello1") - if err != nil || !strings.Contains(out, "hello1") { - c.Fatalf("test 1: expected hello1, got: %s, %v", out, err) - } - - out, _, err = dockerCmdWithError("run", "--cap-drop", "all", "--cap-add", "sys_admin", "syscall-test", "ns-test", "echo", "hello2") - if err != nil || !strings.Contains(out, "hello2") { - c.Fatalf("test 2: expected hello2, got: %s, %v", out, err) - } - - out, _, err = dockerCmdWithError("run", "--cap-add", "ALL", "syscall-test", "ns-test", "echo", "hello3") - if err != nil || !strings.Contains(out, "hello3") { - c.Fatalf("test 3: expected hello3, got: %s, %v", out, err) - } - - out, _, err = dockerCmdWithError("run", "--cap-add", "ALL", "--security-opt", "seccomp=unconfined", "syscall-test", "acct-test") - if err == nil || !strings.Contains(out, "No such file or directory") { - c.Fatalf("test 4: expected No such file or directory, got: %s", out) - } - - out, _, err = dockerCmdWithError("run", "--cap-add", "ALL", "--security-opt", "seccomp=unconfined", "syscall-test", "ns-test", "echo", "hello4") - if err != nil || !strings.Contains(out, "hello4") { - c.Fatalf("test 5: expected hello4, got: %s, %v", out, err) - } -} - -// TestRunNoNewPrivSetuid checks that --security-opt=no-new-privileges prevents -// effective uid transtions on executing setuid binaries. -func (s *DockerSuite) TestRunNoNewPrivSetuid(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, SameHostDaemon) - ensureNNPTest(c) - - // test that running a setuid binary results in no effective uid transition - runCmd := exec.Command(dockerBinary, "run", "--security-opt", "no-new-privileges", "--user", "1000", "nnp-test", "/usr/bin/nnp-test") - if out, _, err := runCommandWithOutput(runCmd); err != nil || !strings.Contains(out, "EUID=1000") { - c.Fatalf("expected output to contain EUID=1000, got %s: %v", out, err) - } -} - -func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChown(c *check.C) { - testRequires(c, DaemonIsLinux) - ensureSyscallTest(c) - - // test that a root user has default capability CAP_CHOWN - runCmd := exec.Command(dockerBinary, "run", "busybox", "chown", "100", "/tmp") - _, _, err := runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) - // test that non root user does not have default capability CAP_CHOWN - runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "busybox", "chown", "100", "/tmp") - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") - // test that root user can drop default capability CAP_CHOWN - runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "chown", "busybox", "chown", "100", "/tmp") - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") -} - -func (s *DockerSuite) TestUserNoEffectiveCapabilitiesDacOverride(c *check.C) { - testRequires(c, DaemonIsLinux) - ensureSyscallTest(c) - - // test that a root user has default capability CAP_DAC_OVERRIDE - runCmd := exec.Command(dockerBinary, "run", "busybox", "sh", "-c", "echo test > /etc/passwd") - _, _, err := runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) - // test that non root user does not have default capability CAP_DAC_OVERRIDE - runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "busybox", "sh", "-c", "echo test > /etc/passwd") - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Permission denied") - // TODO test that root user can drop default capability CAP_DAC_OVERRIDE -} - -func (s *DockerSuite) TestUserNoEffectiveCapabilitiesFowner(c *check.C) { - testRequires(c, DaemonIsLinux) - ensureSyscallTest(c) - - // test that a root user has default capability CAP_FOWNER - runCmd := exec.Command(dockerBinary, "run", "busybox", "chmod", "777", "/etc/passwd") - _, _, err := runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) - // test that non root user does not have default capability CAP_FOWNER - runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "busybox", "chmod", "777", "/etc/passwd") - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") - // TODO test that root user can drop default capability CAP_FOWNER -} - -// TODO CAP_KILL - -func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetuid(c *check.C) { - testRequires(c, DaemonIsLinux) - ensureSyscallTest(c) - - // test that a root user has default capability CAP_SETUID - runCmd := exec.Command(dockerBinary, "run", "syscall-test", "setuid-test") - _, _, err := runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) - // test that non root user does not have default capability CAP_SETUID - runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "setuid-test") - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") - // test that root user can drop default capability CAP_SETUID - runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "setuid", "syscall-test", "setuid-test") - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") -} - -func (s *DockerSuite) TestUserNoEffectiveCapabilitiesSetgid(c *check.C) { - testRequires(c, DaemonIsLinux) - ensureSyscallTest(c) - - // test that a root user has default capability CAP_SETGID - runCmd := exec.Command(dockerBinary, "run", "syscall-test", "setgid-test") - _, _, err := runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) - // test that non root user does not have default capability CAP_SETGID - runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "setgid-test") - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") - // test that root user can drop default capability CAP_SETGID - runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "setgid", "syscall-test", "setgid-test") - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") -} - -// TODO CAP_SETPCAP - -func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetBindService(c *check.C) { - testRequires(c, DaemonIsLinux) - ensureSyscallTest(c) - - // test that a root user has default capability CAP_NET_BIND_SERVICE - runCmd := exec.Command(dockerBinary, "run", "syscall-test", "socket-test") - _, _, err := runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) - // test that non root user does not have default capability CAP_NET_BIND_SERVICE - runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "socket-test") - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Permission denied") - // test that root user can drop default capability CAP_NET_BIND_SERVICE - runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "net_bind_service", "syscall-test", "socket-test") - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Permission denied") -} - -func (s *DockerSuite) TestUserNoEffectiveCapabilitiesNetRaw(c *check.C) { - testRequires(c, DaemonIsLinux) - ensureSyscallTest(c) - - // test that a root user has default capability CAP_NET_RAW - runCmd := exec.Command(dockerBinary, "run", "syscall-test", "raw-test") - _, _, err := runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) - // test that non root user does not have default capability CAP_NET_RAW - runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "syscall-test", "raw-test") - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") - // test that root user can drop default capability CAP_NET_RAW - runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "net_raw", "syscall-test", "raw-test") - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") -} - -func (s *DockerSuite) TestUserNoEffectiveCapabilitiesChroot(c *check.C) { - testRequires(c, DaemonIsLinux) - ensureSyscallTest(c) - - // test that a root user has default capability CAP_SYS_CHROOT - runCmd := exec.Command(dockerBinary, "run", "busybox", "chroot", "/", "/bin/true") - _, _, err := runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) - // test that non root user does not have default capability CAP_SYS_CHROOT - runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "busybox", "chroot", "/", "/bin/true") - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") - // test that root user can drop default capability CAP_SYS_CHROOT - runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "sys_chroot", "busybox", "chroot", "/", "/bin/true") - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") -} - -func (s *DockerSuite) TestUserNoEffectiveCapabilitiesMknod(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - ensureSyscallTest(c) - - // test that a root user has default capability CAP_MKNOD - runCmd := exec.Command(dockerBinary, "run", "busybox", "mknod", "/tmp/node", "b", "1", "2") - _, _, err := runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) - // test that non root user does not have default capability CAP_MKNOD - runCmd = exec.Command(dockerBinary, "run", "--user", "1000:1000", "busybox", "mknod", "/tmp/node", "b", "1", "2") - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") - // test that root user can drop default capability CAP_MKNOD - runCmd = exec.Command(dockerBinary, "run", "--cap-drop", "mknod", "busybox", "mknod", "/tmp/node", "b", "1", "2") - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Operation not permitted") -} - -// TODO CAP_AUDIT_WRITE -// TODO CAP_SETFCAP - -func (s *DockerSuite) TestRunApparmorProcDirectory(c *check.C) { - testRequires(c, SameHostDaemon, Apparmor) - - // running w seccomp unconfined tests the apparmor profile - runCmd := exec.Command(dockerBinary, "run", "--security-opt", "seccomp=unconfined", "busybox", "chmod", "777", "/proc/1/cgroup") - if out, _, err := runCommandWithOutput(runCmd); err == nil || !(strings.Contains(out, "Permission denied") || strings.Contains(out, "Operation not permitted")) { - c.Fatalf("expected chmod 777 /proc/1/cgroup to fail, got %s: %v", out, err) - } - - runCmd = exec.Command(dockerBinary, "run", "--security-opt", "seccomp=unconfined", "busybox", "chmod", "777", "/proc/1/attr/current") - if out, _, err := runCommandWithOutput(runCmd); err == nil || !(strings.Contains(out, "Permission denied") || strings.Contains(out, "Operation not permitted")) { - c.Fatalf("expected chmod 777 /proc/1/attr/current to fail, got %s: %v", out, err) - } -} - -// make sure the default profile can be successfully parsed (using unshare as it is -// something which we know is blocked in the default profile) -func (s *DockerSuite) TestRunSeccompWithDefaultProfile(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled) - - out, _, err := dockerCmdWithError("run", "--security-opt", "seccomp=../profiles/seccomp/default.json", "debian:jessie", "unshare", "--map-root-user", "--user", "sh", "-c", "whoami") - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Equals, "unshare: unshare failed: Operation not permitted") -} - -// TestRunDeviceSymlink checks run with device that follows symlink (#13840 and #22271) -func (s *DockerSuite) TestRunDeviceSymlink(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm, SameHostDaemon) - if _, err := os.Stat("/dev/zero"); err != nil { - c.Skip("Host does not have /dev/zero") - } - - // Create a temporary directory to create symlink - tmpDir, err := ioutil.TempDir("", "docker_device_follow_symlink_tests") - c.Assert(err, checker.IsNil) - - defer os.RemoveAll(tmpDir) - - // Create a symbolic link to /dev/zero - symZero := filepath.Join(tmpDir, "zero") - err = os.Symlink("/dev/zero", symZero) - c.Assert(err, checker.IsNil) - - // Create a temporary file "temp" inside tmpDir, write some data to "tmpDir/temp", - // then create a symlink "tmpDir/file" to the temporary file "tmpDir/temp". - tmpFile := filepath.Join(tmpDir, "temp") - err = ioutil.WriteFile(tmpFile, []byte("temp"), 0666) - c.Assert(err, checker.IsNil) - symFile := filepath.Join(tmpDir, "file") - err = os.Symlink(tmpFile, symFile) - c.Assert(err, checker.IsNil) - - // Create a symbolic link to /dev/zero, this time with a relative path (#22271) - err = os.Symlink("zero", "/dev/symzero") - if err != nil { - c.Fatal("/dev/symzero creation failed") - } - // We need to remove this symbolic link here as it is created in /dev/, not temporary directory as above - defer os.Remove("/dev/symzero") - - // md5sum of 'dd if=/dev/zero bs=4K count=8' is bb7df04e1b0a2570657527a7e108ae23 - out, _ := dockerCmd(c, "run", "--device", symZero+":/dev/symzero", "busybox", "sh", "-c", "dd if=/dev/symzero bs=4K count=8 | md5sum") - c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "bb7df04e1b0a2570657527a7e108ae23", check.Commentf("expected output bb7df04e1b0a2570657527a7e108ae23")) - - // symlink "tmpDir/file" to a file "tmpDir/temp" will result in an error as it is not a device. - out, _, err = dockerCmdWithError("run", "--device", symFile+":/dev/symzero", "busybox", "sh", "-c", "dd if=/dev/symzero bs=4K count=8 | md5sum") - c.Assert(err, check.NotNil) - c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "not a device node", check.Commentf("expected output 'not a device node'")) - - // md5sum of 'dd if=/dev/zero bs=4K count=8' is bb7df04e1b0a2570657527a7e108ae23 (this time check with relative path backed, see #22271) - out, _ = dockerCmd(c, "run", "--device", "/dev/symzero:/dev/symzero", "busybox", "sh", "-c", "dd if=/dev/symzero bs=4K count=8 | md5sum") - c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "bb7df04e1b0a2570657527a7e108ae23", check.Commentf("expected output bb7df04e1b0a2570657527a7e108ae23")) -} - -// TestRunPIDsLimit makes sure the pids cgroup is set with --pids-limit -func (s *DockerSuite) TestRunPIDsLimit(c *check.C) { - testRequires(c, pidsLimit) - - file := "/sys/fs/cgroup/pids/pids.max" - out, _ := dockerCmd(c, "run", "--name", "skittles", "--pids-limit", "4", "busybox", "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "4") - - out = inspectField(c, "skittles", "HostConfig.PidsLimit") - c.Assert(out, checker.Equals, "4", check.Commentf("setting the pids limit failed")) -} - -func (s *DockerSuite) TestRunPrivilegedAllowedDevices(c *check.C) { - testRequires(c, DaemonIsLinux, NotUserNamespace) - - file := "/sys/fs/cgroup/devices/devices.list" - out, _ := dockerCmd(c, "run", "--privileged", "busybox", "cat", file) - c.Logf("out: %q", out) - c.Assert(strings.TrimSpace(out), checker.Equals, "a *:* rwm") -} - -func (s *DockerSuite) TestRunUserDeviceAllowed(c *check.C) { - testRequires(c, DaemonIsLinux) - - fi, err := os.Stat("/dev/snd/timer") - if err != nil { - c.Skip("Host does not have /dev/snd/timer") - } - stat, ok := fi.Sys().(*syscall.Stat_t) - if !ok { - c.Skip("Could not stat /dev/snd/timer") - } - - file := "/sys/fs/cgroup/devices/devices.list" - out, _ := dockerCmd(c, "run", "--device", "/dev/snd/timer:w", "busybox", "cat", file) - c.Assert(out, checker.Contains, fmt.Sprintf("c %d:%d w", stat.Rdev/256, stat.Rdev%256)) -} - -func (s *DockerDaemonSuite) TestRunSeccompJSONNewFormat(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled) - - err := s.d.StartWithBusybox() - c.Assert(err, check.IsNil) - - jsonData := `{ - "defaultAction": "SCMP_ACT_ALLOW", - "syscalls": [ - { - "names": ["chmod", "fchmod", "fchmodat"], - "action": "SCMP_ACT_ERRNO" - } - ] -}` - tmpFile, err := ioutil.TempFile("", "profile.json") - c.Assert(err, check.IsNil) - defer tmpFile.Close() - _, err = tmpFile.Write([]byte(jsonData)) - c.Assert(err, check.IsNil) - - out, err := s.d.Cmd("run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "777", ".") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, "Operation not permitted") -} - -func (s *DockerDaemonSuite) TestRunSeccompJSONNoNameAndNames(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled) - - err := s.d.StartWithBusybox() - c.Assert(err, check.IsNil) - - jsonData := `{ - "defaultAction": "SCMP_ACT_ALLOW", - "syscalls": [ - { - "name": "chmod", - "names": ["fchmod", "fchmodat"], - "action": "SCMP_ACT_ERRNO" - } - ] -}` - tmpFile, err := ioutil.TempFile("", "profile.json") - c.Assert(err, check.IsNil) - defer tmpFile.Close() - _, err = tmpFile.Write([]byte(jsonData)) - c.Assert(err, check.IsNil) - - out, err := s.d.Cmd("run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "777", ".") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, "'name' and 'names' were specified in the seccomp profile, use either 'name' or 'names'") -} - -func (s *DockerDaemonSuite) TestRunSeccompJSONNoArchAndArchMap(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled) - - err := s.d.StartWithBusybox() - c.Assert(err, check.IsNil) - - jsonData := `{ - "archMap": [ - { - "architecture": "SCMP_ARCH_X86_64", - "subArchitectures": [ - "SCMP_ARCH_X86", - "SCMP_ARCH_X32" - ] - } - ], - "architectures": [ - "SCMP_ARCH_X32" - ], - "defaultAction": "SCMP_ACT_ALLOW", - "syscalls": [ - { - "names": ["chmod", "fchmod", "fchmodat"], - "action": "SCMP_ACT_ERRNO" - } - ] -}` - tmpFile, err := ioutil.TempFile("", "profile.json") - c.Assert(err, check.IsNil) - defer tmpFile.Close() - _, err = tmpFile.Write([]byte(jsonData)) - c.Assert(err, check.IsNil) - - out, err := s.d.Cmd("run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "777", ".") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, "'architectures' and 'archMap' were specified in the seccomp profile, use either 'architectures' or 'archMap'") -} - -func (s *DockerDaemonSuite) TestRunWithDaemonDefaultSeccompProfile(c *check.C) { - testRequires(c, SameHostDaemon, seccompEnabled) - - err := s.d.StartWithBusybox() - c.Assert(err, check.IsNil) - - // 1) verify I can run containers with the Docker default shipped profile which allows chmod - _, err = s.d.Cmd("run", "busybox", "chmod", "777", ".") - c.Assert(err, check.IsNil) - - jsonData := `{ - "defaultAction": "SCMP_ACT_ALLOW", - "syscalls": [ - { - "name": "chmod", - "action": "SCMP_ACT_ERRNO" - } - ] -}` - tmpFile, err := ioutil.TempFile("", "profile.json") - c.Assert(err, check.IsNil) - defer tmpFile.Close() - _, err = tmpFile.Write([]byte(jsonData)) - c.Assert(err, check.IsNil) - - // 2) restart the daemon and add a custom seccomp profile in which we deny chmod - err = s.d.Restart("--seccomp-profile=" + tmpFile.Name()) - c.Assert(err, check.IsNil) - - out, err := s.d.Cmd("run", "busybox", "chmod", "777", ".") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, "Operation not permitted") -} - -func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) { - testRequires(c, cpuCfsQuota, cpuCfsPeriod) - - file1 := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us" - file2 := "/sys/fs/cgroup/cpu/cpu.cfs_period_us" - out, _ := dockerCmd(c, "run", "--cpus", "0.5", "--name", "test", "busybox", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2)) - c.Assert(strings.TrimSpace(out), checker.Equals, "50000\n100000") - - out = inspectField(c, "test", "HostConfig.NanoCpus") - c.Assert(out, checker.Equals, "5e+08", check.Commentf("setting the Nano CPUs failed")) - out = inspectField(c, "test", "HostConfig.CpuQuota") - c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS quota should be 0")) - out = inspectField(c, "test", "HostConfig.CpuPeriod") - c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS period should be 0")) - - out, _, err := dockerCmdWithError("run", "--cpus", "0.5", "--cpu-quota", "50000", "--cpu-period", "100000", "busybox", "sh") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, "Conflicting options: Nano CPUs and CPU Period cannot both be set") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_save_load_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_save_load_test.go deleted file mode 100644 index 70139a5..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_save_load_test.go +++ /dev/null @@ -1,383 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "reflect" - "regexp" - "sort" - "strings" - "time" - - "github.com/docker/distribution/digest" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// save a repo using gz compression and try to load it using stdout -func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "test-save-xz-and-load-repo-stdout" - dockerCmd(c, "run", "--name", name, "busybox", "true") - - repoName := "foobar-save-load-test-xz-gz" - out, _ := dockerCmd(c, "commit", name, repoName) - - dockerCmd(c, "inspect", repoName) - - repoTarball, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "save", repoName), - exec.Command("xz", "-c"), - exec.Command("gzip", "-c")) - c.Assert(err, checker.IsNil, check.Commentf("failed to save repo: %v %v", out, err)) - deleteImages(repoName) - - loadCmd := exec.Command(dockerBinary, "load") - loadCmd.Stdin = strings.NewReader(repoTarball) - out, _, err = runCommandWithOutput(loadCmd) - c.Assert(err, checker.NotNil, check.Commentf("expected error, but succeeded with no error and output: %v", out)) - - after, _, err := dockerCmdWithError("inspect", repoName) - c.Assert(err, checker.NotNil, check.Commentf("the repo should not exist: %v", after)) -} - -// save a repo using xz+gz compression and try to load it using stdout -func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "test-save-xz-gz-and-load-repo-stdout" - dockerCmd(c, "run", "--name", name, "busybox", "true") - - repoName := "foobar-save-load-test-xz-gz" - dockerCmd(c, "commit", name, repoName) - - dockerCmd(c, "inspect", repoName) - - out, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "save", repoName), - exec.Command("xz", "-c"), - exec.Command("gzip", "-c")) - c.Assert(err, checker.IsNil, check.Commentf("failed to save repo: %v %v", out, err)) - - deleteImages(repoName) - - loadCmd := exec.Command(dockerBinary, "load") - loadCmd.Stdin = strings.NewReader(out) - out, _, err = runCommandWithOutput(loadCmd) - c.Assert(err, checker.NotNil, check.Commentf("expected error, but succeeded with no error and output: %v", out)) - - after, _, err := dockerCmdWithError("inspect", repoName) - c.Assert(err, checker.NotNil, check.Commentf("the repo should not exist: %v", after)) -} - -func (s *DockerSuite) TestSaveSingleTag(c *check.C) { - testRequires(c, DaemonIsLinux) - repoName := "foobar-save-single-tag-test" - dockerCmd(c, "tag", "busybox:latest", fmt.Sprintf("%v:latest", repoName)) - - out, _ := dockerCmd(c, "images", "-q", "--no-trunc", repoName) - cleanedImageID := strings.TrimSpace(out) - - out, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", repoName)), - exec.Command("tar", "t"), - exec.Command("grep", "-E", fmt.Sprintf("(^repositories$|%v)", cleanedImageID))) - c.Assert(err, checker.IsNil, check.Commentf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err)) -} - -func (s *DockerSuite) TestSaveCheckTimes(c *check.C) { - testRequires(c, DaemonIsLinux) - repoName := "busybox:latest" - out, _ := dockerCmd(c, "inspect", repoName) - data := []struct { - ID string - Created time.Time - }{} - err := json.Unmarshal([]byte(out), &data) - c.Assert(err, checker.IsNil, check.Commentf("failed to marshal from %q: err %v", repoName, err)) - c.Assert(len(data), checker.Not(checker.Equals), 0, check.Commentf("failed to marshal the data from %q", repoName)) - tarTvTimeFormat := "2006-01-02 15:04" - out, _, err = runCommandPipelineWithOutput( - exec.Command(dockerBinary, "save", repoName), - exec.Command("tar", "tv"), - exec.Command("grep", "-E", fmt.Sprintf("%s %s", data[0].Created.Format(tarTvTimeFormat), digest.Digest(data[0].ID).Hex()))) - c.Assert(err, checker.IsNil, check.Commentf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err)) -} - -func (s *DockerSuite) TestSaveImageId(c *check.C) { - testRequires(c, DaemonIsLinux) - repoName := "foobar-save-image-id-test" - dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", repoName)) - - out, _ := dockerCmd(c, "images", "-q", "--no-trunc", repoName) - cleanedLongImageID := strings.TrimPrefix(strings.TrimSpace(out), "sha256:") - - out, _ = dockerCmd(c, "images", "-q", repoName) - cleanedShortImageID := strings.TrimSpace(out) - - // Make sure IDs are not empty - c.Assert(cleanedLongImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty.")) - c.Assert(cleanedShortImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty.")) - - saveCmd := exec.Command(dockerBinary, "save", cleanedShortImageID) - tarCmd := exec.Command("tar", "t") - - var err error - tarCmd.Stdin, err = saveCmd.StdoutPipe() - c.Assert(err, checker.IsNil, check.Commentf("cannot set stdout pipe for tar: %v", err)) - grepCmd := exec.Command("grep", cleanedLongImageID) - grepCmd.Stdin, err = tarCmd.StdoutPipe() - c.Assert(err, checker.IsNil, check.Commentf("cannot set stdout pipe for grep: %v", err)) - - c.Assert(tarCmd.Start(), checker.IsNil, check.Commentf("tar failed with error: %v", err)) - c.Assert(saveCmd.Start(), checker.IsNil, check.Commentf("docker save failed with error: %v", err)) - defer func() { - saveCmd.Wait() - tarCmd.Wait() - dockerCmd(c, "rmi", repoName) - }() - - out, _, err = runCommandWithOutput(grepCmd) - - c.Assert(err, checker.IsNil, check.Commentf("failed to save repo with image ID: %s, %v", out, err)) -} - -// save a repo and try to load it using flags -func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *check.C) { - testRequires(c, DaemonIsLinux) - name := "test-save-and-load-repo-flags" - dockerCmd(c, "run", "--name", name, "busybox", "true") - - repoName := "foobar-save-load-test" - - deleteImages(repoName) - dockerCmd(c, "commit", name, repoName) - - before, _ := dockerCmd(c, "inspect", repoName) - - out, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "save", repoName), - exec.Command(dockerBinary, "load")) - c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err)) - - after, _ := dockerCmd(c, "inspect", repoName) - c.Assert(before, checker.Equals, after, check.Commentf("inspect is not the same after a save / load")) -} - -func (s *DockerSuite) TestSaveWithNoExistImage(c *check.C) { - testRequires(c, DaemonIsLinux) - - imgName := "foobar-non-existing-image" - - out, _, err := dockerCmdWithError("save", "-o", "test-img.tar", imgName) - c.Assert(err, checker.NotNil, check.Commentf("save image should fail for non-existing image")) - c.Assert(out, checker.Contains, fmt.Sprintf("No such image: %s", imgName)) -} - -func (s *DockerSuite) TestSaveMultipleNames(c *check.C) { - testRequires(c, DaemonIsLinux) - repoName := "foobar-save-multi-name-test" - - // Make one image - dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v-one:latest", repoName)) - - // Make two images - dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v-two:latest", repoName)) - - out, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "save", fmt.Sprintf("%v-one", repoName), fmt.Sprintf("%v-two:latest", repoName)), - exec.Command("tar", "xO", "repositories"), - exec.Command("grep", "-q", "-E", "(-one|-two)"), - ) - c.Assert(err, checker.IsNil, check.Commentf("failed to save multiple repos: %s, %v", out, err)) -} - -func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) { - testRequires(c, DaemonIsLinux) - makeImage := func(from string, tag string) string { - var ( - out string - ) - out, _ = dockerCmd(c, "run", "-d", from, "true") - cleanedContainerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "commit", cleanedContainerID, tag) - imageID := strings.TrimSpace(out) - return imageID - } - - repoName := "foobar-save-multi-images-test" - tagFoo := repoName + ":foo" - tagBar := repoName + ":bar" - - idFoo := makeImage("busybox:latest", tagFoo) - idBar := makeImage("busybox:latest", tagBar) - - deleteImages(repoName) - - // create the archive - out, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "save", repoName, "busybox:latest"), - exec.Command("tar", "t")) - c.Assert(err, checker.IsNil, check.Commentf("failed to save multiple images: %s, %v", out, err)) - - lines := strings.Split(strings.TrimSpace(out), "\n") - var actual []string - for _, l := range lines { - if regexp.MustCompile("^[a-f0-9]{64}\\.json$").Match([]byte(l)) { - actual = append(actual, strings.TrimSuffix(l, ".json")) - } - } - - // make the list of expected layers - out = inspectField(c, "busybox:latest", "Id") - expected := []string{strings.TrimSpace(out), idFoo, idBar} - - // prefixes are not in tar - for i := range expected { - expected[i] = digest.Digest(expected[i]).Hex() - } - - sort.Strings(actual) - sort.Strings(expected) - c.Assert(actual, checker.DeepEquals, expected, check.Commentf("archive does not contains the right layers: got %v, expected %v, output: %q", actual, expected, out)) -} - -// Issue #6722 #5892 ensure directories are included in changes -func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) { - testRequires(c, DaemonIsLinux) - layerEntries := []string{"opt/", "opt/a/", "opt/a/b/", "opt/a/b/c"} - layerEntriesAUFS := []string{"./", ".wh..wh.aufs", ".wh..wh.orph/", ".wh..wh.plnk/", "opt/", "opt/a/", "opt/a/b/", "opt/a/b/c"} - - name := "save-directory-permissions" - tmpDir, err := ioutil.TempDir("", "save-layers-with-directories") - c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary directory: %s", err)) - extractionDirectory := filepath.Join(tmpDir, "image-extraction-dir") - os.Mkdir(extractionDirectory, 0777) - - defer os.RemoveAll(tmpDir) - _, err = buildImage(name, - `FROM busybox - RUN adduser -D user && mkdir -p /opt/a/b && chown -R user:user /opt/a - RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`, - true) - c.Assert(err, checker.IsNil, check.Commentf("%v", err)) - - out, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "save", name), - exec.Command("tar", "-xf", "-", "-C", extractionDirectory), - ) - c.Assert(err, checker.IsNil, check.Commentf("failed to save and extract image: %s", out)) - - dirs, err := ioutil.ReadDir(extractionDirectory) - c.Assert(err, checker.IsNil, check.Commentf("failed to get a listing of the layer directories: %s", err)) - - found := false - for _, entry := range dirs { - var entriesSansDev []string - if entry.IsDir() { - layerPath := filepath.Join(extractionDirectory, entry.Name(), "layer.tar") - - f, err := os.Open(layerPath) - c.Assert(err, checker.IsNil, check.Commentf("failed to open %s: %s", layerPath, err)) - defer f.Close() - - entries, err := listTar(f) - for _, e := range entries { - if !strings.Contains(e, "dev/") { - entriesSansDev = append(entriesSansDev, e) - } - } - c.Assert(err, checker.IsNil, check.Commentf("encountered error while listing tar entries: %s", err)) - - if reflect.DeepEqual(entriesSansDev, layerEntries) || reflect.DeepEqual(entriesSansDev, layerEntriesAUFS) { - found = true - break - } - } - } - - c.Assert(found, checker.Equals, true, check.Commentf("failed to find the layer with the right content listing")) - -} - -// Test loading a weird image where one of the layers is of zero size. -// The layer.tar file is actually zero bytes, no padding or anything else. -// See issue: 18170 -func (s *DockerSuite) TestLoadZeroSizeLayer(c *check.C) { - testRequires(c, DaemonIsLinux) - - dockerCmd(c, "load", "-i", "fixtures/load/emptyLayer.tar") -} - -func (s *DockerSuite) TestSaveLoadParents(c *check.C) { - testRequires(c, DaemonIsLinux) - - makeImage := func(from string, addfile string) string { - var ( - out string - ) - out, _ = dockerCmd(c, "run", "-d", from, "touch", addfile) - cleanedContainerID := strings.TrimSpace(out) - - out, _ = dockerCmd(c, "commit", cleanedContainerID) - imageID := strings.TrimSpace(out) - - dockerCmd(c, "rm", "-f", cleanedContainerID) - return imageID - } - - idFoo := makeImage("busybox", "foo") - idBar := makeImage(idFoo, "bar") - - tmpDir, err := ioutil.TempDir("", "save-load-parents") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(tmpDir) - - c.Log("tmpdir", tmpDir) - - outfile := filepath.Join(tmpDir, "out.tar") - - dockerCmd(c, "save", "-o", outfile, idBar, idFoo) - dockerCmd(c, "rmi", idBar) - dockerCmd(c, "load", "-i", outfile) - - inspectOut := inspectField(c, idBar, "Parent") - c.Assert(inspectOut, checker.Equals, idFoo) - - inspectOut = inspectField(c, idFoo, "Parent") - c.Assert(inspectOut, checker.Equals, "") -} - -func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) { - testRequires(c, DaemonIsLinux) - - name := "saveloadnotag" - - _, err := buildImage(name, "FROM busybox\nENV foo=bar", true) - c.Assert(err, checker.IsNil, check.Commentf("%v", err)) - - id := inspectField(c, name, "Id") - - // Test to make sure that save w/o name just shows imageID during load - out, _, err := runCommandPipelineWithOutput( - exec.Command(dockerBinary, "save", id), - exec.Command(dockerBinary, "load")) - c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err)) - - // Should not show 'name' but should show the image ID during the load - c.Assert(out, checker.Not(checker.Contains), "Loaded image: ") - c.Assert(out, checker.Contains, "Loaded image ID:") - c.Assert(out, checker.Contains, id) - - // Test to make sure that save by name shows that name during load - out, _, err = runCommandPipelineWithOutput( - exec.Command(dockerBinary, "save", name), - exec.Command(dockerBinary, "load")) - c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err)) - c.Assert(out, checker.Contains, "Loaded image: "+name+":latest") - c.Assert(out, checker.Not(checker.Contains), "Loaded image ID:") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_save_load_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_save_load_unix_test.go deleted file mode 100644 index 22445e5..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_save_load_unix_test.go +++ /dev/null @@ -1,109 +0,0 @@ -// +build !windows - -package main - -import ( - "context" - "fmt" - "io/ioutil" - "os" - "os/exec" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" - "github.com/kr/pty" -) - -// save a repo and try to load it using stdout -func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) { - name := "test-save-and-load-repo-stdout" - dockerCmd(c, "run", "--name", name, "busybox", "true") - - repoName := "foobar-save-load-test" - before, _ := dockerCmd(c, "commit", name, repoName) - before = strings.TrimRight(before, "\n") - - tmpFile, err := ioutil.TempFile("", "foobar-save-load-test.tar") - c.Assert(err, check.IsNil) - defer os.Remove(tmpFile.Name()) - - saveCmd := exec.Command(dockerBinary, "save", repoName) - saveCmd.Stdout = tmpFile - - _, err = runCommand(saveCmd) - c.Assert(err, check.IsNil) - - tmpFile, err = os.Open(tmpFile.Name()) - c.Assert(err, check.IsNil) - defer tmpFile.Close() - - deleteImages(repoName) - - loadCmd := exec.Command(dockerBinary, "load") - loadCmd.Stdin = tmpFile - - out, _, err := runCommandWithOutput(loadCmd) - c.Assert(err, check.IsNil, check.Commentf(out)) - - after := inspectField(c, repoName, "Id") - after = strings.TrimRight(after, "\n") - - c.Assert(after, check.Equals, before) //inspect is not the same after a save / load - - deleteImages(repoName) - - pty, tty, err := pty.Open() - c.Assert(err, check.IsNil) - cmd := exec.Command(dockerBinary, "save", repoName) - cmd.Stdin = tty - cmd.Stdout = tty - cmd.Stderr = tty - c.Assert(cmd.Start(), check.IsNil) - c.Assert(cmd.Wait(), check.NotNil) //did not break writing to a TTY - - buf := make([]byte, 1024) - - n, err := pty.Read(buf) - c.Assert(err, check.IsNil) //could not read tty output - c.Assert(string(buf[:n]), checker.Contains, "Cowardly refusing", check.Commentf("help output is not being yielded", out)) -} - -func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *check.C) { - name := "test-load" - _, err := buildImage(name, ` - FROM busybox - RUN touch aa - `, true) - c.Assert(err, check.IsNil) - - tmptar := name + ".tar" - dockerCmd(c, "save", "-o", tmptar, name) - defer os.Remove(tmptar) - - dockerCmd(c, "rmi", name) - dockerCmd(c, "tag", "busybox", name) - out, _ := dockerCmd(c, "load", "-i", tmptar) - expected := fmt.Sprintf("The image %s:latest already exists, renaming the old one with ID", name) - c.Assert(out, checker.Contains, expected) -} - -// fail because load didn't receive data from stdin -func (s *DockerSuite) TestLoadNoStdinFail(c *check.C) { - pty, tty, err := pty.Open() - c.Assert(err, check.IsNil) - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - cmd := exec.CommandContext(ctx, dockerBinary, "load") - cmd.Stdin = tty - cmd.Stdout = tty - cmd.Stderr = tty - c.Assert(cmd.Run(), check.NotNil) // docker-load should fail - - buf := make([]byte, 1024) - - n, err := pty.Read(buf) - c.Assert(err, check.IsNil) //could not read tty output - c.Assert(string(buf[:n]), checker.Contains, "requested load from stdin, but stdin is empty") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_search_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_search_test.go deleted file mode 100644 index 5a32f2a..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_search_test.go +++ /dev/null @@ -1,131 +0,0 @@ -package main - -import ( - "fmt" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// search for repos named "registry" on the central registry -func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) { - testRequires(c, Network, DaemonIsLinux) - - out, _ := dockerCmd(c, "search", "busybox") - c.Assert(out, checker.Contains, "Busybox base image.", check.Commentf("couldn't find any repository named (or containing) 'Busybox base image.'")) -} - -func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) { - out, _, err := dockerCmdWithError("search", "--filter", "stars=a", "busybox") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning")) - - out, _, err = dockerCmdWithError("search", "-f", "stars=a", "busybox") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning")) - - out, _, err = dockerCmdWithError("search", "-f", "is-automated=a", "busybox") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning")) - - out, _, err = dockerCmdWithError("search", "-f", "is-official=a", "busybox") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning")) - - // -s --stars deprecated since Docker 1.13 - out, _, err = dockerCmdWithError("search", "--stars=a", "busybox") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "invalid syntax", check.Commentf("couldn't find the invalid value warning")) - - // -s --stars deprecated since Docker 1.13 - out, _, err = dockerCmdWithError("search", "-s=-1", "busybox") - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "invalid syntax", check.Commentf("couldn't find the invalid value warning")) -} - -func (s *DockerSuite) TestSearchCmdOptions(c *check.C) { - testRequires(c, Network, DaemonIsLinux) - - out, _ := dockerCmd(c, "search", "--help") - c.Assert(out, checker.Contains, "Usage:\tdocker search [OPTIONS] TERM") - - outSearchCmd, _ := dockerCmd(c, "search", "busybox") - outSearchCmdNotrunc, _ := dockerCmd(c, "search", "--no-trunc=true", "busybox") - - c.Assert(len(outSearchCmd) > len(outSearchCmdNotrunc), check.Equals, false, check.Commentf("The no-trunc option can't take effect.")) - - outSearchCmdautomated, _ := dockerCmd(c, "search", "--filter", "is-automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image. - outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n") - for i := range outSearchCmdautomatedSlice { - c.Assert(strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox "), check.Equals, false, check.Commentf("The busybox is not an AUTOMATED image: %s", outSearchCmdautomated)) - } - - outSearchCmdNotOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=false", "busybox") //The busybox is a busybox base image, official image. - outSearchCmdNotOfficialSlice := strings.Split(outSearchCmdNotOfficial, "\n") - for i := range outSearchCmdNotOfficialSlice { - c.Assert(strings.HasPrefix(outSearchCmdNotOfficialSlice[i], "busybox "), check.Equals, false, check.Commentf("The busybox is not an OFFICIAL image: %s", outSearchCmdNotOfficial)) - } - - outSearchCmdOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=true", "busybox") //The busybox is a busybox base image, official image. - outSearchCmdOfficialSlice := strings.Split(outSearchCmdOfficial, "\n") - c.Assert(outSearchCmdOfficialSlice, checker.HasLen, 3) // 1 header, 1 line, 1 carriage return - c.Assert(strings.HasPrefix(outSearchCmdOfficialSlice[1], "busybox "), check.Equals, true, check.Commentf("The busybox is an OFFICIAL image: %s", outSearchCmdNotOfficial)) - - outSearchCmdStars, _ := dockerCmd(c, "search", "--filter", "stars=2", "busybox") - c.Assert(strings.Count(outSearchCmdStars, "[OK]") > strings.Count(outSearchCmd, "[OK]"), check.Equals, false, check.Commentf("The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars)) - - dockerCmd(c, "search", "--filter", "is-automated=true", "--filter", "stars=2", "--no-trunc=true", "busybox") - - // --automated deprecated since Docker 1.13 - outSearchCmdautomated1, _ := dockerCmd(c, "search", "--automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image. - outSearchCmdautomatedSlice1 := strings.Split(outSearchCmdautomated1, "\n") - for i := range outSearchCmdautomatedSlice1 { - c.Assert(strings.HasPrefix(outSearchCmdautomatedSlice1[i], "busybox "), check.Equals, false, check.Commentf("The busybox is not an AUTOMATED image: %s", outSearchCmdautomated)) - } - - // -s --stars deprecated since Docker 1.13 - outSearchCmdStars1, _ := dockerCmd(c, "search", "--stars=2", "busybox") - c.Assert(strings.Count(outSearchCmdStars1, "[OK]") > strings.Count(outSearchCmd, "[OK]"), check.Equals, false, check.Commentf("The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars1)) - - // -s --stars deprecated since Docker 1.13 - dockerCmd(c, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox") -} - -// search for repos which start with "ubuntu-" on the central registry -func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) { - testRequires(c, Network, DaemonIsLinux) - - dockerCmd(c, "search", "ubuntu-") -} - -// test case for #23055 -func (s *DockerSuite) TestSearchWithLimit(c *check.C) { - testRequires(c, Network, DaemonIsLinux) - - limit := 10 - out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") - c.Assert(err, checker.IsNil) - outSlice := strings.Split(out, "\n") - c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return - - limit = 50 - out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") - c.Assert(err, checker.IsNil) - outSlice = strings.Split(out, "\n") - c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return - - limit = 100 - out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") - c.Assert(err, checker.IsNil) - outSlice = strings.Split(out, "\n") - c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return - - limit = 0 - out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") - c.Assert(err, checker.Not(checker.IsNil)) - - limit = 200 - out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker") - c.Assert(err, checker.Not(checker.IsNil)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_secret_create_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_secret_create_test.go deleted file mode 100644 index b79fdbe..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_secret_create_test.go +++ /dev/null @@ -1,131 +0,0 @@ -// +build !windows - -package main - -import ( - "io/ioutil" - "os" - "strings" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSwarmSuite) TestSecretCreate(c *check.C) { - d := s.AddDaemon(c, true, true) - - testName := "test_secret" - id := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: testName, - }, - []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id)) - - secret := d.getSecret(c, id) - c.Assert(secret.Spec.Name, checker.Equals, testName) -} - -func (s *DockerSwarmSuite) TestSecretCreateWithLabels(c *check.C) { - d := s.AddDaemon(c, true, true) - - testName := "test_secret" - id := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: testName, - Labels: map[string]string{ - "key1": "value1", - "key2": "value2", - }, - }, - []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id)) - - secret := d.getSecret(c, id) - c.Assert(secret.Spec.Name, checker.Equals, testName) - c.Assert(len(secret.Spec.Labels), checker.Equals, 2) - c.Assert(secret.Spec.Labels["key1"], checker.Equals, "value1") - c.Assert(secret.Spec.Labels["key2"], checker.Equals, "value2") -} - -// Test case for 28884 -func (s *DockerSwarmSuite) TestSecretCreateResolve(c *check.C) { - d := s.AddDaemon(c, true, true) - - name := "foo" - id := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: name, - }, - []byte("foo"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id)) - - fake := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: id, - }, - []byte("fake foo"), - }) - c.Assert(fake, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", fake)) - - out, err := d.Cmd("secret", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name) - c.Assert(out, checker.Contains, fake) - - out, err = d.Cmd("secret", "rm", id) - c.Assert(out, checker.Contains, id) - - // Fake one will remain - out, err = d.Cmd("secret", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), name) - c.Assert(out, checker.Contains, fake) - - // Remove based on name prefix of the fake one - // (which is the same as the ID of foo one) should not work - // as search is only done based on: - // - Full ID - // - Full Name - // - Partial ID (prefix) - out, err = d.Cmd("secret", "rm", id[:5]) - c.Assert(out, checker.Not(checker.Contains), id) - out, err = d.Cmd("secret", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), name) - c.Assert(out, checker.Contains, fake) - - // Remove based on ID prefix of the fake one should succeed - out, err = d.Cmd("secret", "rm", fake[:5]) - c.Assert(out, checker.Contains, fake) - out, err = d.Cmd("secret", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), name) - c.Assert(out, checker.Not(checker.Contains), id) - c.Assert(out, checker.Not(checker.Contains), fake) -} - -func (s *DockerSwarmSuite) TestSecretCreateWithFile(c *check.C) { - d := s.AddDaemon(c, true, true) - - testFile, err := ioutil.TempFile("", "secretCreateTest") - c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file")) - defer os.Remove(testFile.Name()) - - testData := "TESTINGDATA" - _, err = testFile.Write([]byte(testData)) - c.Assert(err, checker.IsNil, check.Commentf("failed to write to temporary file")) - - testName := "test_secret" - out, err := d.Cmd("secret", "create", testName, testFile.Name()) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "", check.Commentf(out)) - - id := strings.TrimSpace(out) - secret := d.getSecret(c, id) - c.Assert(secret.Spec.Name, checker.Equals, testName) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_secret_inspect_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_secret_inspect_test.go deleted file mode 100644 index 0985a2b..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_secret_inspect_test.go +++ /dev/null @@ -1,68 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSwarmSuite) TestSecretInspect(c *check.C) { - d := s.AddDaemon(c, true, true) - - testName := "test_secret" - id := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: testName, - }, - []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id)) - - secret := d.getSecret(c, id) - c.Assert(secret.Spec.Name, checker.Equals, testName) - - out, err := d.Cmd("secret", "inspect", testName) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - var secrets []swarm.Secret - c.Assert(json.Unmarshal([]byte(out), &secrets), checker.IsNil) - c.Assert(secrets, checker.HasLen, 1) -} - -func (s *DockerSwarmSuite) TestSecretInspectMultiple(c *check.C) { - d := s.AddDaemon(c, true, true) - - testNames := []string{ - "test0", - "test1", - } - for _, n := range testNames { - id := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: n, - }, - []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id)) - - secret := d.getSecret(c, id) - c.Assert(secret.Spec.Name, checker.Equals, n) - - } - - args := []string{ - "secret", - "inspect", - } - args = append(args, testNames...) - out, err := d.Cmd(args...) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - var secrets []swarm.Secret - c.Assert(json.Unmarshal([]byte(out), &secrets), checker.IsNil) - c.Assert(secrets, checker.HasLen, 2) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_service_create_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_service_create_test.go deleted file mode 100644 index 9e8b1e9..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_service_create_test.go +++ /dev/null @@ -1,175 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "fmt" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *check.C) { - d := s.AddDaemon(c, true, true) - out, err := d.Cmd("service", "create", "--mount", "type=volume,source=foo,target=/foo,volume-nocopy", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - id := strings.TrimSpace(out) - - var tasks []swarm.Task - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - tasks = d.getServiceTasks(c, id) - return len(tasks) > 0, nil - }, checker.Equals, true) - - task := tasks[0] - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" { - task = d.getTask(c, task.ID) - } - return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil - }, checker.Equals, true) - - // check container mount config - out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - var mountConfig []mount.Mount - c.Assert(json.Unmarshal([]byte(out), &mountConfig), checker.IsNil) - c.Assert(mountConfig, checker.HasLen, 1) - - c.Assert(mountConfig[0].Source, checker.Equals, "foo") - c.Assert(mountConfig[0].Target, checker.Equals, "/foo") - c.Assert(mountConfig[0].Type, checker.Equals, mount.TypeVolume) - c.Assert(mountConfig[0].VolumeOptions, checker.NotNil) - c.Assert(mountConfig[0].VolumeOptions.NoCopy, checker.True) - - // check container mounts actual - out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - var mounts []types.MountPoint - c.Assert(json.Unmarshal([]byte(out), &mounts), checker.IsNil) - c.Assert(mounts, checker.HasLen, 1) - - c.Assert(mounts[0].Type, checker.Equals, mount.TypeVolume) - c.Assert(mounts[0].Name, checker.Equals, "foo") - c.Assert(mounts[0].Destination, checker.Equals, "/foo") - c.Assert(mounts[0].RW, checker.Equals, true) -} - -func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *check.C) { - d := s.AddDaemon(c, true, true) - - serviceName := "test-service-secret" - testName := "test_secret" - id := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: testName, - }, - []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id)) - - out, err := d.Cmd("service", "create", "--name", serviceName, "--secret", testName, "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName) - c.Assert(err, checker.IsNil) - - var refs []swarm.SecretReference - c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil) - c.Assert(refs, checker.HasLen, 1) - - c.Assert(refs[0].SecretName, checker.Equals, testName) - c.Assert(refs[0].File, checker.Not(checker.IsNil)) - c.Assert(refs[0].File.Name, checker.Equals, testName) - c.Assert(refs[0].File.UID, checker.Equals, "0") - c.Assert(refs[0].File.GID, checker.Equals, "0") -} - -func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTarget(c *check.C) { - d := s.AddDaemon(c, true, true) - - serviceName := "test-service-secret" - testName := "test_secret" - id := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: testName, - }, - []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id)) - testTarget := "testing" - - out, err := d.Cmd("service", "create", "--name", serviceName, "--secret", fmt.Sprintf("source=%s,target=%s", testName, testTarget), "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName) - c.Assert(err, checker.IsNil) - - var refs []swarm.SecretReference - c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil) - c.Assert(refs, checker.HasLen, 1) - - c.Assert(refs[0].SecretName, checker.Equals, testName) - c.Assert(refs[0].File, checker.Not(checker.IsNil)) - c.Assert(refs[0].File.Name, checker.Equals, testTarget) -} - -func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *check.C) { - d := s.AddDaemon(c, true, true) - out, err := d.Cmd("service", "create", "--mount", "type=tmpfs,target=/foo,tmpfs-size=1MB", "busybox", "sh", "-c", "mount | grep foo; tail -f /dev/null") - c.Assert(err, checker.IsNil, check.Commentf(out)) - id := strings.TrimSpace(out) - - var tasks []swarm.Task - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - tasks = d.getServiceTasks(c, id) - return len(tasks) > 0, nil - }, checker.Equals, true) - - task := tasks[0] - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - if task.NodeID == "" || task.Status.ContainerStatus.ContainerID == "" { - task = d.getTask(c, task.ID) - } - return task.NodeID != "" && task.Status.ContainerStatus.ContainerID != "", nil - }, checker.Equals, true) - - // check container mount config - out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .HostConfig.Mounts}}", task.Status.ContainerStatus.ContainerID) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - var mountConfig []mount.Mount - c.Assert(json.Unmarshal([]byte(out), &mountConfig), checker.IsNil) - c.Assert(mountConfig, checker.HasLen, 1) - - c.Assert(mountConfig[0].Source, checker.Equals, "") - c.Assert(mountConfig[0].Target, checker.Equals, "/foo") - c.Assert(mountConfig[0].Type, checker.Equals, mount.TypeTmpfs) - c.Assert(mountConfig[0].TmpfsOptions, checker.NotNil) - c.Assert(mountConfig[0].TmpfsOptions.SizeBytes, checker.Equals, int64(1048576)) - - // check container mounts actual - out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - var mounts []types.MountPoint - c.Assert(json.Unmarshal([]byte(out), &mounts), checker.IsNil) - c.Assert(mounts, checker.HasLen, 1) - - c.Assert(mounts[0].Type, checker.Equals, mount.TypeTmpfs) - c.Assert(mounts[0].Name, checker.Equals, "") - c.Assert(mounts[0].Destination, checker.Equals, "/foo") - c.Assert(mounts[0].RW, checker.Equals, true) - - out, err = s.nodeCmd(c, task.NodeID, "logs", task.Status.ContainerStatus.ContainerID) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.HasPrefix, "tmpfs on /foo type tmpfs") - c.Assert(strings.TrimSpace(out), checker.Contains, "size=1024k") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_service_health_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_service_health_test.go deleted file mode 100644 index 30580f6..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_service_health_test.go +++ /dev/null @@ -1,191 +0,0 @@ -// +build !windows - -package main - -import ( - "strconv" - "strings" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/daemon/cluster/executor/container" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// start a service, and then make its task unhealthy during running -// finally, unhealthy task should be detected and killed -func (s *DockerSwarmSuite) TestServiceHealthRun(c *check.C) { - testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows - - d := s.AddDaemon(c, true, true) - - // build image with health-check - // note: use `daemon.buildImageWithOut` to build, do not use `buildImage` to build - imageName := "testhealth" - _, _, err := d.buildImageWithOut(imageName, - `FROM busybox - RUN touch /status - HEALTHCHECK --interval=1s --timeout=1s --retries=1\ - CMD cat /status`, - true) - c.Check(err, check.IsNil) - - serviceName := "healthServiceRun" - out, err := d.Cmd("service", "create", "--name", serviceName, imageName, "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - id := strings.TrimSpace(out) - - var tasks []swarm.Task - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - tasks = d.getServiceTasks(c, id) - return tasks, nil - }, checker.HasLen, 1) - - task := tasks[0] - - // wait for task to start - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - task = d.getTask(c, task.ID) - return task.Status.State, nil - }, checker.Equals, swarm.TaskStateRunning) - containerID := task.Status.ContainerStatus.ContainerID - - // wait for container to be healthy - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID) - return strings.TrimSpace(out), nil - }, checker.Equals, "healthy") - - // make it fail - d.Cmd("exec", containerID, "rm", "/status") - // wait for container to be unhealthy - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID) - return strings.TrimSpace(out), nil - }, checker.Equals, "unhealthy") - - // Task should be terminated - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - task = d.getTask(c, task.ID) - return task.Status.State, nil - }, checker.Equals, swarm.TaskStateFailed) - - if !strings.Contains(task.Status.Err, container.ErrContainerUnhealthy.Error()) { - c.Fatal("unhealthy task exits because of other error") - } -} - -// start a service whose task is unhealthy at beginning -// its tasks should be blocked in starting stage, until health check is passed -func (s *DockerSwarmSuite) TestServiceHealthStart(c *check.C) { - testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows - - d := s.AddDaemon(c, true, true) - - // service started from this image won't pass health check - imageName := "testhealth" - _, _, err := d.buildImageWithOut(imageName, - `FROM busybox - HEALTHCHECK --interval=1s --timeout=1s --retries=1024\ - CMD cat /status`, - true) - c.Check(err, check.IsNil) - - serviceName := "healthServiceStart" - out, err := d.Cmd("service", "create", "--name", serviceName, imageName, "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - id := strings.TrimSpace(out) - - var tasks []swarm.Task - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - tasks = d.getServiceTasks(c, id) - return tasks, nil - }, checker.HasLen, 1) - - task := tasks[0] - - // wait for task to start - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - task = d.getTask(c, task.ID) - return task.Status.State, nil - }, checker.Equals, swarm.TaskStateStarting) - - containerID := task.Status.ContainerStatus.ContainerID - - // wait for health check to work - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - out, _ := d.Cmd("inspect", "--format={{.State.Health.FailingStreak}}", containerID) - failingStreak, _ := strconv.Atoi(strings.TrimSpace(out)) - return failingStreak, nil - }, checker.GreaterThan, 0) - - // task should be blocked at starting status - task = d.getTask(c, task.ID) - c.Assert(task.Status.State, check.Equals, swarm.TaskStateStarting) - - // make it healthy - d.Cmd("exec", containerID, "touch", "/status") - - // Task should be at running status - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - task = d.getTask(c, task.ID) - return task.Status.State, nil - }, checker.Equals, swarm.TaskStateRunning) -} - -// start a service whose task is unhealthy at beginning -// its tasks should be blocked in starting stage, until health check is passed -func (s *DockerSwarmSuite) TestServiceHealthUpdate(c *check.C) { - testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows - - d := s.AddDaemon(c, true, true) - - // service started from this image won't pass health check - imageName := "testhealth" - _, _, err := d.buildImageWithOut(imageName, - `FROM busybox - HEALTHCHECK --interval=1s --timeout=1s --retries=1024\ - CMD cat /status`, - true) - c.Check(err, check.IsNil) - - serviceName := "healthServiceStart" - out, err := d.Cmd("service", "create", "--name", serviceName, imageName, "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - id := strings.TrimSpace(out) - - var tasks []swarm.Task - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - tasks = d.getServiceTasks(c, id) - return tasks, nil - }, checker.HasLen, 1) - - task := tasks[0] - - // wait for task to start - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - task = d.getTask(c, task.ID) - return task.Status.State, nil - }, checker.Equals, swarm.TaskStateStarting) - - containerID := task.Status.ContainerStatus.ContainerID - - // wait for health check to work - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - out, _ := d.Cmd("inspect", "--format={{.State.Health.FailingStreak}}", containerID) - failingStreak, _ := strconv.Atoi(strings.TrimSpace(out)) - return failingStreak, nil - }, checker.GreaterThan, 0) - - // task should be blocked at starting status - task = d.getTask(c, task.ID) - c.Assert(task.Status.State, check.Equals, swarm.TaskStateStarting) - - // make it healthy - d.Cmd("exec", containerID, "touch", "/status") - // Task should be at running status - waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { - task = d.getTask(c, task.ID) - return task.Status.State, nil - }, checker.Equals, swarm.TaskStateRunning) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_service_logs_experimental_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_service_logs_experimental_test.go deleted file mode 100644 index c221654..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_service_logs_experimental_test.go +++ /dev/null @@ -1,96 +0,0 @@ -// +build !windows - -package main - -import ( - "bufio" - "fmt" - "io" - "os/exec" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -type logMessage struct { - err error - data []byte -} - -func (s *DockerSwarmSuite) TestServiceLogs(c *check.C) { - testRequires(c, ExperimentalDaemon) - - d := s.AddDaemon(c, true, true) - - // we have multiple services here for detecting the goroutine issue #28915 - services := map[string]string{ - "TestServiceLogs1": "hello1", - "TestServiceLogs2": "hello2", - } - - for name, message := range services { - out, err := d.Cmd("service", "create", "--name", name, "busybox", - "sh", "-c", fmt.Sprintf("echo %s; tail -f /dev/null", message)) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - } - - // make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, - d.checkActiveContainerCount, checker.Equals, len(services)) - - for name, message := range services { - out, err := d.Cmd("service", "logs", name) - c.Assert(err, checker.IsNil) - c.Logf("log for %q: %q", name, out) - c.Assert(out, checker.Contains, message) - } -} - -func (s *DockerSwarmSuite) TestServiceLogsFollow(c *check.C) { - testRequires(c, ExperimentalDaemon) - - d := s.AddDaemon(c, true, true) - - name := "TestServiceLogsFollow" - - out, err := d.Cmd("service", "create", "--name", name, "busybox", "sh", "-c", "while true; do echo log test; sleep 0.1; done") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - // make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - args := []string{"service", "logs", "-f", name} - cmd := exec.Command(dockerBinary, d.prependHostArg(args)...) - r, w := io.Pipe() - cmd.Stdout = w - cmd.Stderr = w - c.Assert(cmd.Start(), checker.IsNil) - - // Make sure pipe is written to - ch := make(chan *logMessage) - done := make(chan struct{}) - go func() { - reader := bufio.NewReader(r) - for { - msg := &logMessage{} - msg.data, _, msg.err = reader.ReadLine() - select { - case ch <- msg: - case <-done: - return - } - } - }() - - for i := 0; i < 3; i++ { - msg := <-ch - c.Assert(msg.err, checker.IsNil) - c.Assert(string(msg.data), checker.Contains, "log test") - } - close(done) - - c.Assert(cmd.Process.Kill(), checker.IsNil) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_service_scale_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_service_scale_test.go deleted file mode 100644 index 29cca23..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_service_scale_test.go +++ /dev/null @@ -1,57 +0,0 @@ -// +build !windows - -package main - -import ( - "fmt" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSwarmSuite) TestServiceScale(c *check.C) { - d := s.AddDaemon(c, true, true) - - service1Name := "TestService1" - service1Args := append([]string{"service", "create", "--name", service1Name, defaultSleepImage}, sleepCommandForDaemonPlatform()...) - - // global mode - service2Name := "TestService2" - service2Args := append([]string{"service", "create", "--name", service2Name, "--mode=global", defaultSleepImage}, sleepCommandForDaemonPlatform()...) - - // Create services - out, err := d.Cmd(service1Args...) - c.Assert(err, checker.IsNil) - - out, err = d.Cmd(service2Args...) - c.Assert(err, checker.IsNil) - - out, err = d.Cmd("service", "scale", "TestService1=2") - c.Assert(err, checker.IsNil) - - out, err = d.Cmd("service", "scale", "TestService1=foobar") - c.Assert(err, checker.NotNil) - - str := fmt.Sprintf("%s: invalid replicas value %s", service1Name, "foobar") - if !strings.Contains(out, str) { - c.Errorf("got: %s, expected has sub string: %s", out, str) - } - - out, err = d.Cmd("service", "scale", "TestService1=-1") - c.Assert(err, checker.NotNil) - - str = fmt.Sprintf("%s: invalid replicas value %s", service1Name, "-1") - if !strings.Contains(out, str) { - c.Errorf("got: %s, expected has sub string: %s", out, str) - } - - // TestService2 is a global mode - out, err = d.Cmd("service", "scale", "TestService2=2") - c.Assert(err, checker.NotNil) - - str = fmt.Sprintf("%s: scale can only be used with replicated mode\n", service2Name) - if out != str { - c.Errorf("got: %s, expected: %s", out, str) - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_service_update_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_service_update_test.go deleted file mode 100644 index 837370c..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_service_update_test.go +++ /dev/null @@ -1,130 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "fmt" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSwarmSuite) TestServiceUpdatePort(c *check.C) { - d := s.AddDaemon(c, true, true) - - serviceName := "TestServiceUpdatePort" - serviceArgs := append([]string{"service", "create", "--name", serviceName, "-p", "8080:8081", defaultSleepImage}, sleepCommandForDaemonPlatform()...) - - // Create a service with a port mapping of 8080:8081. - out, err := d.Cmd(serviceArgs...) - c.Assert(err, checker.IsNil) - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - // Update the service: changed the port mapping from 8080:8081 to 8082:8083. - _, err = d.Cmd("service", "update", "--publish-add", "8082:8083", "--publish-rm", "8081", serviceName) - c.Assert(err, checker.IsNil) - - // Inspect the service and verify port mapping - expected := []swarm.PortConfig{ - { - Protocol: "tcp", - PublishedPort: 8082, - TargetPort: 8083, - PublishMode: "ingress", - }, - } - - out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.EndpointSpec.Ports }}", serviceName) - c.Assert(err, checker.IsNil) - - var portConfig []swarm.PortConfig - if err := json.Unmarshal([]byte(out), &portConfig); err != nil { - c.Fatalf("invalid JSON in inspect result: %v (%s)", err, out) - } - c.Assert(portConfig, checker.DeepEquals, expected) -} - -func (s *DockerSwarmSuite) TestServiceUpdateLabel(c *check.C) { - d := s.AddDaemon(c, true, true) - out, err := d.Cmd("service", "create", "--name=test", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - service := d.getService(c, "test") - c.Assert(service.Spec.Labels, checker.HasLen, 0) - - // add label to empty set - out, err = d.Cmd("service", "update", "test", "--label-add", "foo=bar") - c.Assert(err, checker.IsNil, check.Commentf(out)) - service = d.getService(c, "test") - c.Assert(service.Spec.Labels, checker.HasLen, 1) - c.Assert(service.Spec.Labels["foo"], checker.Equals, "bar") - - // add label to non-empty set - out, err = d.Cmd("service", "update", "test", "--label-add", "foo2=bar") - c.Assert(err, checker.IsNil, check.Commentf(out)) - service = d.getService(c, "test") - c.Assert(service.Spec.Labels, checker.HasLen, 2) - c.Assert(service.Spec.Labels["foo2"], checker.Equals, "bar") - - out, err = d.Cmd("service", "update", "test", "--label-rm", "foo2") - c.Assert(err, checker.IsNil, check.Commentf(out)) - service = d.getService(c, "test") - c.Assert(service.Spec.Labels, checker.HasLen, 1) - c.Assert(service.Spec.Labels["foo2"], checker.Equals, "") - - out, err = d.Cmd("service", "update", "test", "--label-rm", "foo") - c.Assert(err, checker.IsNil, check.Commentf(out)) - service = d.getService(c, "test") - c.Assert(service.Spec.Labels, checker.HasLen, 0) - c.Assert(service.Spec.Labels["foo"], checker.Equals, "") - - // now make sure we can add again - out, err = d.Cmd("service", "update", "test", "--label-add", "foo=bar") - c.Assert(err, checker.IsNil, check.Commentf(out)) - service = d.getService(c, "test") - c.Assert(service.Spec.Labels, checker.HasLen, 1) - c.Assert(service.Spec.Labels["foo"], checker.Equals, "bar") -} - -func (s *DockerSwarmSuite) TestServiceUpdateSecrets(c *check.C) { - d := s.AddDaemon(c, true, true) - testName := "test_secret" - id := d.createSecret(c, swarm.SecretSpec{ - swarm.Annotations{ - Name: testName, - }, - []byte("TESTINGDATA"), - }) - c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id)) - testTarget := "testing" - serviceName := "test" - - out, err := d.Cmd("service", "create", "--name", serviceName, "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // add secret - out, err = d.cmdRetryOutOfSequence("service", "update", "test", "--secret-add", fmt.Sprintf("source=%s,target=%s", testName, testTarget)) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName) - c.Assert(err, checker.IsNil) - - var refs []swarm.SecretReference - c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil) - c.Assert(refs, checker.HasLen, 1) - - c.Assert(refs[0].SecretName, checker.Equals, testName) - c.Assert(refs[0].File, checker.Not(checker.IsNil)) - c.Assert(refs[0].File.Name, checker.Equals, testTarget) - - // remove - out, err = d.cmdRetryOutOfSequence("service", "update", "test", "--secret-rm", testName) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", serviceName) - c.Assert(err, checker.IsNil) - - c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil) - c.Assert(refs, checker.HasLen, 0) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_sni_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_sni_test.go deleted file mode 100644 index fb896d5..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_sni_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "log" - "net/http" - "net/http/httptest" - "net/url" - "os/exec" - "strings" - - "github.com/go-check/check" -) - -func (s *DockerSuite) TestClientSetsTLSServerName(c *check.C) { - c.Skip("Flakey test") - // there may be more than one hit to the server for each registry request - serverNameReceived := []string{} - var serverName string - - virtualHostServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - serverNameReceived = append(serverNameReceived, r.TLS.ServerName) - })) - defer virtualHostServer.Close() - // discard TLS handshake errors written by default to os.Stderr - virtualHostServer.Config.ErrorLog = log.New(ioutil.Discard, "", 0) - - u, err := url.Parse(virtualHostServer.URL) - c.Assert(err, check.IsNil) - hostPort := u.Host - serverName = strings.Split(hostPort, ":")[0] - - repoName := fmt.Sprintf("%v/dockercli/image:latest", hostPort) - cmd := exec.Command(dockerBinary, "pull", repoName) - cmd.Run() - - // check that the fake server was hit at least once - c.Assert(len(serverNameReceived) > 0, check.Equals, true) - // check that for each hit the right server name was received - for _, item := range serverNameReceived { - c.Check(item, check.Equals, serverName) - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_stack_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_stack_test.go deleted file mode 100644 index fd9b154..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_stack_test.go +++ /dev/null @@ -1,186 +0,0 @@ -package main - -import ( - "encoding/json" - "io/ioutil" - "os" - "sort" - "strings" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSwarmSuite) TestStackRemoveUnknown(c *check.C) { - d := s.AddDaemon(c, true, true) - - stackArgs := append([]string{"stack", "remove", "UNKNOWN_STACK"}) - - out, err := d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil) - c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n") -} - -func (s *DockerSwarmSuite) TestStackPSUnknown(c *check.C) { - d := s.AddDaemon(c, true, true) - - stackArgs := append([]string{"stack", "ps", "UNKNOWN_STACK"}) - - out, err := d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil) - c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n") -} - -func (s *DockerSwarmSuite) TestStackServicesUnknown(c *check.C) { - d := s.AddDaemon(c, true, true) - - stackArgs := append([]string{"stack", "services", "UNKNOWN_STACK"}) - - out, err := d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil) - c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n") -} - -func (s *DockerSwarmSuite) TestStackDeployComposeFile(c *check.C) { - d := s.AddDaemon(c, true, true) - - testStackName := "testdeploy" - stackArgs := []string{ - "stack", "deploy", - "--compose-file", "fixtures/deploy/default.yaml", - testStackName, - } - out, err := d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = d.Cmd("stack", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, check.Equals, "NAME SERVICES\n"+"testdeploy 2\n") - - out, err = d.Cmd("stack", "rm", testStackName) - c.Assert(err, checker.IsNil) - out, err = d.Cmd("stack", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, check.Equals, "NAME SERVICES\n") -} - -func (s *DockerSwarmSuite) TestStackDeployWithSecretsTwice(c *check.C) { - d := s.AddDaemon(c, true, true) - - out, err := d.Cmd("secret", "create", "outside", "fixtures/secrets/default") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - testStackName := "testdeploy" - stackArgs := []string{ - "stack", "deploy", - "--compose-file", "fixtures/deploy/secrets.yaml", - testStackName, - } - out, err = d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = d.Cmd("service", "inspect", "--format", "{{ json .Spec.TaskTemplate.ContainerSpec.Secrets }}", "testdeploy_web") - c.Assert(err, checker.IsNil) - - var refs []swarm.SecretReference - c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil) - c.Assert(refs, checker.HasLen, 3) - - sort.Sort(sortSecrets(refs)) - c.Assert(refs[0].SecretName, checker.Equals, "outside") - c.Assert(refs[1].SecretName, checker.Equals, "testdeploy_special") - c.Assert(refs[1].File.Name, checker.Equals, "special") - c.Assert(refs[2].SecretName, checker.Equals, "testdeploy_super") - c.Assert(refs[2].File.Name, checker.Equals, "foo.txt") - c.Assert(refs[2].File.Mode, checker.Equals, os.FileMode(0400)) - - // Deploy again to ensure there are no errors when secret hasn't changed - out, err = d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil, check.Commentf(out)) -} - -func (s *DockerSwarmSuite) TestStackRemove(c *check.C) { - d := s.AddDaemon(c, true, true) - - stackName := "testdeploy" - stackArgs := []string{ - "stack", "deploy", - "--compose-file", "fixtures/deploy/remove.yaml", - stackName, - } - out, err := d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = d.Cmd("stack", "ps", stackName) - c.Assert(err, checker.IsNil) - c.Assert(strings.Split(strings.TrimSpace(out), "\n"), checker.HasLen, 2) - - out, err = d.Cmd("stack", "rm", stackName) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Removing service testdeploy_web") - c.Assert(out, checker.Contains, "Removing network testdeploy_default") - c.Assert(out, checker.Contains, "Removing secret testdeploy_special") -} - -type sortSecrets []swarm.SecretReference - -func (s sortSecrets) Len() int { return len(s) } -func (s sortSecrets) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -func (s sortSecrets) Less(i, j int) bool { return s[i].SecretName < s[j].SecretName } - -// testDAB is the DAB JSON used for testing. -// TODO: Use template/text and substitute "Image" with the result of -// `docker inspect --format '{{index .RepoDigests 0}}' busybox:latest` -const testDAB = `{ - "Version": "0.1", - "Services": { - "srv1": { - "Image": "busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0", - "Command": ["top"] - }, - "srv2": { - "Image": "busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0", - "Command": ["tail"], - "Args": ["-f", "/dev/null"] - } - } -}` - -func (s *DockerSwarmSuite) TestStackDeployWithDAB(c *check.C) { - testRequires(c, ExperimentalDaemon) - // setup - testStackName := "test" - testDABFileName := testStackName + ".dab" - defer os.RemoveAll(testDABFileName) - err := ioutil.WriteFile(testDABFileName, []byte(testDAB), 0444) - c.Assert(err, checker.IsNil) - d := s.AddDaemon(c, true, true) - // deploy - stackArgs := []string{ - "stack", "deploy", - "--bundle-file", testDABFileName, - testStackName, - } - out, err := d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "Loading bundle from test.dab\n") - c.Assert(out, checker.Contains, "Creating service test_srv1\n") - c.Assert(out, checker.Contains, "Creating service test_srv2\n") - // ls - stackArgs = []string{"stack", "ls"} - out, err = d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil) - c.Assert(out, check.Equals, "NAME SERVICES\n"+"test 2\n") - // rm - stackArgs = []string{"stack", "rm", testStackName} - out, err = d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "Removing service test_srv1\n") - c.Assert(out, checker.Contains, "Removing service test_srv2\n") - // ls (empty) - stackArgs = []string{"stack", "ls"} - out, err = d.Cmd(stackArgs...) - c.Assert(err, checker.IsNil) - c.Assert(out, check.Equals, "NAME SERVICES\n") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_start_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_start_test.go deleted file mode 100644 index b1cea35..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_start_test.go +++ /dev/null @@ -1,199 +0,0 @@ -package main - -import ( - "fmt" - "os/exec" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// Regression test for https://github.com/docker/docker/issues/7843 -func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) { - // Windows does not support link - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "--name", "test", "busybox") - - // Expect this to fail because the above container is stopped, this is what we want - out, _, err := dockerCmdWithError("run", "--name", "test2", "--link", "test:test", "busybox") - // err shouldn't be nil because container test2 try to link to stopped container - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - - ch := make(chan error) - go func() { - // Attempt to start attached to the container that won't start - // This should return an error immediately since the container can't be started - if out, _, err := dockerCmdWithError("start", "-a", "test2"); err == nil { - ch <- fmt.Errorf("Expected error but got none:\n%s", out) - } - close(ch) - }() - - select { - case err := <-ch: - c.Assert(err, check.IsNil) - case <-time.After(5 * time.Second): - c.Fatalf("Attach did not exit properly") - } -} - -// gh#8555: Exit code should be passed through when using start -a -func (s *DockerSuite) TestStartAttachCorrectExitCode(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _, _ := dockerCmdWithStdoutStderr(c, "run", "-d", "busybox", "sh", "-c", "sleep 2; exit 1") - out = strings.TrimSpace(out) - - // make sure the container has exited before trying the "start -a" - dockerCmd(c, "wait", out) - - startOut, exitCode, err := dockerCmdWithError("start", "-a", out) - // start command should fail - c.Assert(err, checker.NotNil, check.Commentf("startOut: %s", startOut)) - // start -a did not respond with proper exit code - c.Assert(exitCode, checker.Equals, 1, check.Commentf("startOut: %s", startOut)) - -} - -func (s *DockerSuite) TestStartAttachSilent(c *check.C) { - name := "teststartattachcorrectexitcode" - dockerCmd(c, "run", "--name", name, "busybox", "echo", "test") - - // make sure the container has exited before trying the "start -a" - dockerCmd(c, "wait", name) - - startOut, _ := dockerCmd(c, "start", "-a", name) - // start -a produced unexpected output - c.Assert(startOut, checker.Equals, "test\n") -} - -func (s *DockerSuite) TestStartRecordError(c *check.C) { - // TODO Windows CI: Requires further porting work. Should be possible. - testRequires(c, DaemonIsLinux) - // when container runs successfully, we should not have state.Error - dockerCmd(c, "run", "-d", "-p", "9999:9999", "--name", "test", "busybox", "top") - stateErr := inspectField(c, "test", "State.Error") - // Expected to not have state error - c.Assert(stateErr, checker.Equals, "") - - // Expect this to fail and records error because of ports conflict - out, _, err := dockerCmdWithError("run", "-d", "--name", "test2", "-p", "9999:9999", "busybox", "top") - // err shouldn't be nil because docker run will fail - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - - stateErr = inspectField(c, "test2", "State.Error") - c.Assert(stateErr, checker.Contains, "port is already allocated") - - // Expect the conflict to be resolved when we stop the initial container - dockerCmd(c, "stop", "test") - dockerCmd(c, "start", "test2") - stateErr = inspectField(c, "test2", "State.Error") - // Expected to not have state error but got one - c.Assert(stateErr, checker.Equals, "") -} - -func (s *DockerSuite) TestStartPausedContainer(c *check.C) { - // Windows does not support pausing containers - testRequires(c, IsPausable) - defer unpauseAllContainers() - - runSleepingContainer(c, "-d", "--name", "testing") - - dockerCmd(c, "pause", "testing") - - out, _, err := dockerCmdWithError("start", "testing") - // an error should have been shown that you cannot start paused container - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - // an error should have been shown that you cannot start paused container - c.Assert(out, checker.Contains, "Cannot start a paused container, try unpause instead.") -} - -func (s *DockerSuite) TestStartMultipleContainers(c *check.C) { - // Windows does not support --link - testRequires(c, DaemonIsLinux) - // run a container named 'parent' and create two container link to `parent` - dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top") - - for _, container := range []string{"child_first", "child_second"} { - dockerCmd(c, "create", "--name", container, "--link", "parent:parent", "busybox", "top") - } - - // stop 'parent' container - dockerCmd(c, "stop", "parent") - - out := inspectField(c, "parent", "State.Running") - // Container should be stopped - c.Assert(out, checker.Equals, "false") - - // start all the three containers, container `child_first` start first which should be failed - // container 'parent' start second and then start container 'child_second' - expOut := "Cannot link to a non running container" - expErr := "failed to start containers: [child_first]" - out, _, err := dockerCmdWithError("start", "child_first", "parent", "child_second") - // err shouldn't be nil because start will fail - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - // output does not correspond to what was expected - if !(strings.Contains(out, expOut) || strings.Contains(err.Error(), expErr)) { - c.Fatalf("Expected out: %v with err: %v but got out: %v with err: %v", expOut, expErr, out, err) - } - - for container, expected := range map[string]string{"parent": "true", "child_first": "false", "child_second": "true"} { - out := inspectField(c, container, "State.Running") - // Container running state wrong - c.Assert(out, checker.Equals, expected) - } -} - -func (s *DockerSuite) TestStartAttachMultipleContainers(c *check.C) { - // run multiple containers to test - for _, container := range []string{"test1", "test2", "test3"} { - runSleepingContainer(c, "--name", container) - } - - // stop all the containers - for _, container := range []string{"test1", "test2", "test3"} { - dockerCmd(c, "stop", container) - } - - // test start and attach multiple containers at once, expected error - for _, option := range []string{"-a", "-i", "-ai"} { - out, _, err := dockerCmdWithError("start", option, "test1", "test2", "test3") - // err shouldn't be nil because start will fail - c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) - // output does not correspond to what was expected - c.Assert(out, checker.Contains, "You cannot start and attach multiple containers at once.") - } - - // confirm the state of all the containers be stopped - for container, expected := range map[string]string{"test1": "false", "test2": "false", "test3": "false"} { - out := inspectField(c, container, "State.Running") - // Container running state wrong - c.Assert(out, checker.Equals, expected) - } -} - -// Test case for #23716 -func (s *DockerSuite) TestStartAttachWithRename(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "create", "-t", "--name", "before", "busybox") - go func() { - c.Assert(waitRun("before"), checker.IsNil) - dockerCmd(c, "rename", "before", "after") - dockerCmd(c, "stop", "--time=2", "after") - }() - _, stderr, _, _ := runCommandWithStdoutStderr(exec.Command(dockerBinary, "start", "-a", "before")) - c.Assert(stderr, checker.Not(checker.Contains), "No such container") -} - -func (s *DockerSuite) TestStartReturnCorrectExitCode(c *check.C) { - dockerCmd(c, "create", "--restart=on-failure:2", "--name", "withRestart", "busybox", "sh", "-c", "exit 11") - dockerCmd(c, "create", "--rm", "--name", "withRm", "busybox", "sh", "-c", "exit 12") - - _, exitCode, err := dockerCmdWithError("start", "-a", "withRestart") - c.Assert(err, checker.NotNil) - c.Assert(exitCode, checker.Equals, 11) - _, exitCode, err = dockerCmdWithError("start", "-a", "withRm") - c.Assert(err, checker.NotNil) - c.Assert(exitCode, checker.Equals, 12) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_stats_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_stats_test.go deleted file mode 100644 index 5cb1a3e..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_stats_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package main - -import ( - "bufio" - "os/exec" - "regexp" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestStatsNoStream(c *check.C) { - // Windows does not support stats - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - id := strings.TrimSpace(out) - c.Assert(waitRun(id), checker.IsNil) - - statsCmd := exec.Command(dockerBinary, "stats", "--no-stream", id) - type output struct { - out []byte - err error - } - - ch := make(chan output) - go func() { - out, err := statsCmd.Output() - ch <- output{out, err} - }() - - select { - case outerr := <-ch: - c.Assert(outerr.err, checker.IsNil, check.Commentf("Error running stats: %v", outerr.err)) - c.Assert(string(outerr.out), checker.Contains, id) //running container wasn't present in output - case <-time.After(3 * time.Second): - statsCmd.Process.Kill() - c.Fatalf("stats did not return immediately when not streaming") - } -} - -func (s *DockerSuite) TestStatsContainerNotFound(c *check.C) { - // Windows does not support stats - testRequires(c, DaemonIsLinux) - - out, _, err := dockerCmdWithError("stats", "notfound") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "No such container: notfound", check.Commentf("Expected to fail on not found container stats, got %q instead", out)) - - out, _, err = dockerCmdWithError("stats", "--no-stream", "notfound") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "No such container: notfound", check.Commentf("Expected to fail on not found container stats with --no-stream, got %q instead", out)) -} - -func (s *DockerSuite) TestStatsAllRunningNoStream(c *check.C) { - // Windows does not support stats - testRequires(c, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - id1 := strings.TrimSpace(out)[:12] - c.Assert(waitRun(id1), check.IsNil) - out, _ = dockerCmd(c, "run", "-d", "busybox", "top") - id2 := strings.TrimSpace(out)[:12] - c.Assert(waitRun(id2), check.IsNil) - out, _ = dockerCmd(c, "run", "-d", "busybox", "top") - id3 := strings.TrimSpace(out)[:12] - c.Assert(waitRun(id3), check.IsNil) - dockerCmd(c, "stop", id3) - - out, _ = dockerCmd(c, "stats", "--no-stream") - if !strings.Contains(out, id1) || !strings.Contains(out, id2) { - c.Fatalf("Expected stats output to contain both %s and %s, got %s", id1, id2, out) - } - if strings.Contains(out, id3) { - c.Fatalf("Did not expect %s in stats, got %s", id3, out) - } - - // check output contains real data, but not all zeros - reg, _ := regexp.Compile("[1-9]+") - // split output with "\n", outLines[1] is id2's output - // outLines[2] is id1's output - outLines := strings.Split(out, "\n") - // check stat result of id2 contains real data - realData := reg.Find([]byte(outLines[1][12:])) - c.Assert(realData, checker.NotNil, check.Commentf("stat result are empty: %s", out)) - // check stat result of id1 contains real data - realData = reg.Find([]byte(outLines[2][12:])) - c.Assert(realData, checker.NotNil, check.Commentf("stat result are empty: %s", out)) -} - -func (s *DockerSuite) TestStatsAllNoStream(c *check.C) { - // Windows does not support stats - testRequires(c, DaemonIsLinux) - - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") - id1 := strings.TrimSpace(out)[:12] - c.Assert(waitRun(id1), check.IsNil) - dockerCmd(c, "stop", id1) - out, _ = dockerCmd(c, "run", "-d", "busybox", "top") - id2 := strings.TrimSpace(out)[:12] - c.Assert(waitRun(id2), check.IsNil) - - out, _ = dockerCmd(c, "stats", "--all", "--no-stream") - if !strings.Contains(out, id1) || !strings.Contains(out, id2) { - c.Fatalf("Expected stats output to contain both %s and %s, got %s", id1, id2, out) - } - - // check output contains real data, but not all zeros - reg, _ := regexp.Compile("[1-9]+") - // split output with "\n", outLines[1] is id2's output - outLines := strings.Split(out, "\n") - // check stat result of id2 contains real data - realData := reg.Find([]byte(outLines[1][12:])) - c.Assert(realData, checker.NotNil, check.Commentf("stat result of %s is empty: %s", id2, out)) - // check stat result of id1 contains all zero - realData = reg.Find([]byte(outLines[2][12:])) - c.Assert(realData, checker.IsNil, check.Commentf("stat result of %s should be empty : %s", id1, out)) -} - -func (s *DockerSuite) TestStatsAllNewContainersAdded(c *check.C) { - // Windows does not support stats - testRequires(c, DaemonIsLinux) - - id := make(chan string) - addedChan := make(chan struct{}) - - runSleepingContainer(c, "-d") - statsCmd := exec.Command(dockerBinary, "stats") - stdout, err := statsCmd.StdoutPipe() - c.Assert(err, check.IsNil) - c.Assert(statsCmd.Start(), check.IsNil) - defer statsCmd.Process.Kill() - - go func() { - containerID := <-id - matchID := regexp.MustCompile(containerID) - - scanner := bufio.NewScanner(stdout) - for scanner.Scan() { - switch { - case matchID.MatchString(scanner.Text()): - close(addedChan) - return - } - } - }() - - out, _ := runSleepingContainer(c, "-d") - c.Assert(waitRun(strings.TrimSpace(out)), check.IsNil) - id <- strings.TrimSpace(out)[:12] - - select { - case <-time.After(30 * time.Second): - c.Fatal("failed to observe new container created added to stats") - case <-addedChan: - // ignore, done - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_stop_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_stop_test.go deleted file mode 100644 index 103d013..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_stop_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestStopContainerWithRestartPolicyAlways(c *check.C) { - dockerCmd(c, "run", "--name", "verifyRestart1", "-d", "--restart=always", "busybox", "false") - dockerCmd(c, "run", "--name", "verifyRestart2", "-d", "--restart=always", "busybox", "false") - - c.Assert(waitRun("verifyRestart1"), checker.IsNil) - c.Assert(waitRun("verifyRestart2"), checker.IsNil) - - dockerCmd(c, "stop", "verifyRestart1") - dockerCmd(c, "stop", "verifyRestart2") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_swarm_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_swarm_test.go deleted file mode 100644 index 8eae162..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_swarm_test.go +++ /dev/null @@ -1,1254 +0,0 @@ -// +build !windows - -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "path/filepath" - "strings" - "time" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/libnetwork/driverapi" - "github.com/docker/libnetwork/ipamapi" - remoteipam "github.com/docker/libnetwork/ipams/remote/api" - "github.com/go-check/check" - "github.com/vishvananda/netlink" -) - -func (s *DockerSwarmSuite) TestSwarmUpdate(c *check.C) { - d := s.AddDaemon(c, true, true) - - getSpec := func() swarm.Spec { - sw := d.getSwarm(c) - return sw.Spec - } - - out, err := d.Cmd("swarm", "update", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - - spec := getSpec() - c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour) - c.Assert(spec.Dispatcher.HeartbeatPeriod, checker.Equals, 11*time.Second) - - // setting anything under 30m for cert-expiry is not allowed - out, err = d.Cmd("swarm", "update", "--cert-expiry", "15m") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "minimum certificate expiry time") - spec = getSpec() - c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour) -} - -func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) { - d := s.AddDaemon(c, false, false) - - getSpec := func() swarm.Spec { - sw := d.getSwarm(c) - return sw.Spec - } - - out, err := d.Cmd("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - - spec := getSpec() - c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour) - c.Assert(spec.Dispatcher.HeartbeatPeriod, checker.Equals, 11*time.Second) - - c.Assert(d.Leave(true), checker.IsNil) - time.Sleep(500 * time.Millisecond) // https://github.com/docker/swarmkit/issues/1421 - out, err = d.Cmd("swarm", "init") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - - spec = getSpec() - c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 90*24*time.Hour) - c.Assert(spec.Dispatcher.HeartbeatPeriod, checker.Equals, 5*time.Second) -} - -func (s *DockerSwarmSuite) TestSwarmInitIPv6(c *check.C) { - testRequires(c, IPv6) - d1 := s.AddDaemon(c, false, false) - out, err := d1.Cmd("swarm", "init", "--listen-addr", "::1") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - - d2 := s.AddDaemon(c, false, false) - out, err = d2.Cmd("swarm", "join", "::1") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - - out, err = d2.Cmd("info") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - c.Assert(out, checker.Contains, "Swarm: active") -} - -func (s *DockerSwarmSuite) TestSwarmInitUnspecifiedAdvertiseAddr(c *check.C) { - d := s.AddDaemon(c, false, false) - out, err := d.Cmd("swarm", "init", "--advertise-addr", "0.0.0.0") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "advertise address must be a non-zero IP address") -} - -func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *check.C) { - // init swarm mode and stop a daemon - d := s.AddDaemon(c, true, true) - info, err := d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - c.Assert(d.Stop(), checker.IsNil) - - // start a daemon with --cluster-store and --cluster-advertise - err = d.Start("--cluster-store=consul://consuladdr:consulport/some/path", "--cluster-advertise=1.1.1.1:2375") - c.Assert(err, checker.NotNil) - content, _ := ioutil.ReadFile(d.logFile.Name()) - c.Assert(string(content), checker.Contains, "--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode") - - // start a daemon with --live-restore - err = d.Start("--live-restore") - c.Assert(err, checker.NotNil) - content, _ = ioutil.ReadFile(d.logFile.Name()) - c.Assert(string(content), checker.Contains, "--live-restore daemon configuration is incompatible with swarm mode") - // restart for teardown - c.Assert(d.Start(), checker.IsNil) -} - -// Test case for #24090 -func (s *DockerSwarmSuite) TestSwarmNodeListHostname(c *check.C) { - d := s.AddDaemon(c, true, true) - - // The first line should contain "HOSTNAME" - out, err := d.Cmd("node", "ls") - c.Assert(err, checker.IsNil) - c.Assert(strings.Split(out, "\n")[0], checker.Contains, "HOSTNAME") -} - -func (s *DockerSwarmSuite) TestSwarmServiceTemplatingHostname(c *check.C) { - d := s.AddDaemon(c, true, true) - - out, err := d.Cmd("service", "create", "--name", "test", "--hostname", "{{.Service.Name}}-{{.Task.Slot}}", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - containers := d.activeContainers() - out, err = d.Cmd("inspect", "--type", "container", "--format", "{{.Config.Hostname}}", containers[0]) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.Split(out, "\n")[0], checker.Equals, "test-1", check.Commentf("hostname with templating invalid")) -} - -// Test case for #24270 -func (s *DockerSwarmSuite) TestSwarmServiceListFilter(c *check.C) { - d := s.AddDaemon(c, true, true) - - name1 := "redis-cluster-md5" - name2 := "redis-cluster" - name3 := "other-cluster" - out, err := d.Cmd("service", "create", "--name", name1, "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - out, err = d.Cmd("service", "create", "--name", name2, "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - out, err = d.Cmd("service", "create", "--name", name3, "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - filter1 := "name=redis-cluster-md5" - filter2 := "name=redis-cluster" - - // We search checker.Contains with `name+" "` to prevent prefix only. - out, err = d.Cmd("service", "ls", "--filter", filter1) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name1+" ") - c.Assert(out, checker.Not(checker.Contains), name2+" ") - c.Assert(out, checker.Not(checker.Contains), name3+" ") - - out, err = d.Cmd("service", "ls", "--filter", filter2) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name1+" ") - c.Assert(out, checker.Contains, name2+" ") - c.Assert(out, checker.Not(checker.Contains), name3+" ") - - out, err = d.Cmd("service", "ls") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name1+" ") - c.Assert(out, checker.Contains, name2+" ") - c.Assert(out, checker.Contains, name3+" ") -} - -func (s *DockerSwarmSuite) TestSwarmNodeListFilter(c *check.C) { - d := s.AddDaemon(c, true, true) - - out, err := d.Cmd("node", "inspect", "--format", "{{ .Description.Hostname }}", "self") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - name := strings.TrimSpace(out) - - filter := "name=" + name[:4] - - out, err = d.Cmd("node", "ls", "--filter", filter) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name) - - out, err = d.Cmd("node", "ls", "--filter", "name=none") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), name) -} - -func (s *DockerSwarmSuite) TestSwarmNodeTaskListFilter(c *check.C) { - d := s.AddDaemon(c, true, true) - - name := "redis-cluster-md5" - out, err := d.Cmd("service", "create", "--name", name, "--replicas=3", "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - // make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 3) - - filter := "name=redis-cluster" - - out, err = d.Cmd("node", "ps", "--filter", filter, "self") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name+".1") - c.Assert(out, checker.Contains, name+".2") - c.Assert(out, checker.Contains, name+".3") - - out, err = d.Cmd("node", "ps", "--filter", "name=none", "self") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), name+".1") - c.Assert(out, checker.Not(checker.Contains), name+".2") - c.Assert(out, checker.Not(checker.Contains), name+".3") -} - -// Test case for #25375 -func (s *DockerSwarmSuite) TestSwarmPublishAdd(c *check.C) { - d := s.AddDaemon(c, true, true) - - testCases := []struct { - name string - publishAdd []string - ports string - }{ - { - name: "simple-syntax", - publishAdd: []string{ - "80:80", - "80:80", - "80:80", - "80:20", - }, - ports: "[{ tcp 80 80 ingress}]", - }, - { - name: "complex-syntax", - publishAdd: []string{ - "target=90,published=90,protocol=tcp,mode=ingress", - "target=90,published=90,protocol=tcp,mode=ingress", - "target=90,published=90,protocol=tcp,mode=ingress", - "target=30,published=90,protocol=tcp,mode=ingress", - }, - ports: "[{ tcp 90 90 ingress}]", - }, - } - - for _, tc := range testCases { - out, err := d.Cmd("service", "create", "--name", tc.name, "--label", "x=y", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - out, err = d.cmdRetryOutOfSequence("service", "update", "--publish-add", tc.publishAdd[0], tc.name) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = d.cmdRetryOutOfSequence("service", "update", "--publish-add", tc.publishAdd[1], tc.name) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - out, err = d.cmdRetryOutOfSequence("service", "update", "--publish-add", tc.publishAdd[2], "--publish-add", tc.publishAdd[3], tc.name) - c.Assert(err, checker.NotNil, check.Commentf(out)) - - out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.EndpointSpec.Ports }}", tc.name) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, tc.ports) - } -} - -func (s *DockerSwarmSuite) TestSwarmServiceWithGroup(c *check.C) { - d := s.AddDaemon(c, true, true) - - name := "top" - out, err := d.Cmd("service", "create", "--name", name, "--user", "root:root", "--group", "wheel", "--group", "audio", "--group", "staff", "--group", "777", "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - // make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - out, err = d.Cmd("ps", "-q") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - container := strings.TrimSpace(out) - - out, err = d.Cmd("exec", container, "id") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "uid=0(root) gid=0(root) groups=10(wheel),29(audio),50(staff),777") -} - -func (s *DockerSwarmSuite) TestSwarmContainerAutoStart(c *check.C) { - d := s.AddDaemon(c, true, true) - - out, err := d.Cmd("network", "create", "--attachable", "-d", "overlay", "foo") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - out, err = d.Cmd("run", "-id", "--restart=always", "--net=foo", "--name=test", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - out, err = d.Cmd("ps", "-q") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - d.Restart() - - out, err = d.Cmd("ps", "-q") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") -} - -func (s *DockerSwarmSuite) TestSwarmContainerEndpointOptions(c *check.C) { - d := s.AddDaemon(c, true, true) - - out, err := d.Cmd("network", "create", "--attachable", "-d", "overlay", "foo") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - _, err = d.Cmd("run", "-d", "--net=foo", "--name=first", "--net-alias=first-alias", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - _, err = d.Cmd("run", "-d", "--net=foo", "--name=second", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // ping first container and its alias - _, err = d.Cmd("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil, check.Commentf(out)) - _, err = d.Cmd("exec", "second", "ping", "-c", "1", "first-alias") - c.Assert(err, check.IsNil, check.Commentf(out)) -} - -func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *check.C) { - d := s.AddDaemon(c, true, true) - - out, err := d.Cmd("network", "create", "--attachable", "-d", "overlay", "testnet") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - networkID := strings.TrimSpace(out) - - out, err = d.Cmd("run", "-d", "--net", networkID, "busybox", "top") - c.Assert(err, checker.IsNil) - cID := strings.TrimSpace(out) - d.waitRun(cID) - - _, err = d.Cmd("rm", "-f", cID) - c.Assert(err, checker.IsNil) - - out, err = d.Cmd("network", "rm", "testnet") - c.Assert(err, checker.IsNil) - - checkNetwork := func(*check.C) (interface{}, check.CommentInterface) { - out, err := d.Cmd("network", "ls") - c.Assert(err, checker.IsNil) - return out, nil - } - - waitAndAssert(c, 3*time.Second, checkNetwork, checker.Not(checker.Contains), "testnet") -} - -func (s *DockerSwarmSuite) TestOverlayAttachable(c *check.C) { - d := s.AddDaemon(c, true, true) - - out, err := d.Cmd("network", "create", "-d", "overlay", "--attachable", "ovnet") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // validate attachable - out, err = d.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Equals, "true") - - // validate containers can attache to this overlay network - out, err = d.Cmd("run", "-d", "--network", "ovnet", "--name", "c1", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // redo validation, there was a bug that the value of attachable changes after - // containers attach to the network - out, err = d.Cmd("network", "inspect", "--format", "{{json .Attachable}}", "ovnet") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Equals, "true") -} - -func (s *DockerSwarmSuite) TestOverlayAttachableOnSwarmLeave(c *check.C) { - d := s.AddDaemon(c, true, true) - - // Create an attachable swarm network - nwName := "attovl" - out, err := d.Cmd("network", "create", "-d", "overlay", "--attachable", nwName) - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // Connect a container to the network - out, err = d.Cmd("run", "-d", "--network", nwName, "--name", "c1", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // Leave the swarm - err = d.Leave(true) - c.Assert(err, checker.IsNil) - - // Check the container is disconnected - out, err = d.Cmd("inspect", "c1", "--format", "{{.NetworkSettings.Networks."+nwName+"}}") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "") - - // Check the network is gone - out, err = d.Cmd("network", "ls", "--format", "{{.Name}}") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), nwName) -} - -func (s *DockerSwarmSuite) TestSwarmRemoveInternalNetwork(c *check.C) { - d := s.AddDaemon(c, true, true) - - name := "ingress" - out, err := d.Cmd("network", "rm", name) - c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Contains, name) - c.Assert(strings.TrimSpace(out), checker.Contains, "is a pre-defined network and cannot be removed") -} - -// Test case for #24108, also the case from: -// https://github.com/docker/docker/pull/24620#issuecomment-233715656 -func (s *DockerSwarmSuite) TestSwarmTaskListFilter(c *check.C) { - d := s.AddDaemon(c, true, true) - - name := "redis-cluster-md5" - out, err := d.Cmd("service", "create", "--name", name, "--replicas=3", "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - filter := "name=redis-cluster" - - checkNumTasks := func(*check.C) (interface{}, check.CommentInterface) { - out, err := d.Cmd("service", "ps", "--filter", filter, name) - c.Assert(err, checker.IsNil) - return len(strings.Split(out, "\n")) - 2, nil // includes header and nl in last line - } - - // wait until all tasks have been created - waitAndAssert(c, defaultReconciliationTimeout, checkNumTasks, checker.Equals, 3) - - out, err = d.Cmd("service", "ps", "--filter", filter, name) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name+".1") - c.Assert(out, checker.Contains, name+".2") - c.Assert(out, checker.Contains, name+".3") - - out, err = d.Cmd("service", "ps", "--filter", "name="+name+".1", name) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name+".1") - c.Assert(out, checker.Not(checker.Contains), name+".2") - c.Assert(out, checker.Not(checker.Contains), name+".3") - - out, err = d.Cmd("service", "ps", "--filter", "name=none", name) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), name+".1") - c.Assert(out, checker.Not(checker.Contains), name+".2") - c.Assert(out, checker.Not(checker.Contains), name+".3") - - name = "redis-cluster-sha1" - out, err = d.Cmd("service", "create", "--name", name, "--mode=global", "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - waitAndAssert(c, defaultReconciliationTimeout, checkNumTasks, checker.Equals, 1) - - filter = "name=redis-cluster" - out, err = d.Cmd("service", "ps", "--filter", filter, name) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name) - - out, err = d.Cmd("service", "ps", "--filter", "name="+name, name) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, name) - - out, err = d.Cmd("service", "ps", "--filter", "name=none", name) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Not(checker.Contains), name) -} - -func (s *DockerSwarmSuite) TestPsListContainersFilterIsTask(c *check.C) { - d := s.AddDaemon(c, true, true) - - // Create a bare container - out, err := d.Cmd("run", "-d", "--name=bare-container", "busybox", "top") - c.Assert(err, checker.IsNil) - bareID := strings.TrimSpace(out)[:12] - // Create a service - name := "busybox-top" - out, err = d.Cmd("service", "create", "--name", name, "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - // make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkServiceRunningTasks(name), checker.Equals, 1) - - // Filter non-tasks - out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=false") - c.Assert(err, checker.IsNil) - psOut := strings.TrimSpace(out) - c.Assert(psOut, checker.Equals, bareID, check.Commentf("Expected id %s, got %s for is-task label, output %q", bareID, psOut, out)) - - // Filter tasks - out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=true") - c.Assert(err, checker.IsNil) - lines := strings.Split(strings.Trim(out, "\n "), "\n") - c.Assert(lines, checker.HasLen, 1) - c.Assert(lines[0], checker.Not(checker.Equals), bareID, check.Commentf("Expected not %s, but got it for is-task label, output %q", bareID, out)) -} - -const globalNetworkPlugin = "global-network-plugin" -const globalIPAMPlugin = "global-ipam-plugin" - -func setupRemoteGlobalNetworkPlugin(c *check.C, mux *http.ServeMux, url, netDrv, ipamDrv string) { - - mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, `{"Implements": ["%s", "%s"]}`, driverapi.NetworkPluginEndpointType, ipamapi.PluginEndpointType) - }) - - // Network driver implementation - mux.HandleFunc(fmt.Sprintf("/%s.GetCapabilities", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, `{"Scope":"global"}`) - }) - - mux.HandleFunc(fmt.Sprintf("/%s.AllocateNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&remoteDriverNetworkRequest) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, "null") - }) - - mux.HandleFunc(fmt.Sprintf("/%s.FreeNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, "null") - }) - - mux.HandleFunc(fmt.Sprintf("/%s.CreateNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&remoteDriverNetworkRequest) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, "null") - }) - - mux.HandleFunc(fmt.Sprintf("/%s.DeleteNetwork", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, "null") - }) - - mux.HandleFunc(fmt.Sprintf("/%s.CreateEndpoint", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, `{"Interface":{"MacAddress":"a0:b1:c2:d3:e4:f5"}}`) - }) - - mux.HandleFunc(fmt.Sprintf("/%s.Join", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - - veth := &netlink.Veth{ - LinkAttrs: netlink.LinkAttrs{Name: "randomIfName", TxQLen: 0}, PeerName: "cnt0"} - if err := netlink.LinkAdd(veth); err != nil { - fmt.Fprintf(w, `{"Error":"failed to add veth pair: `+err.Error()+`"}`) - } else { - fmt.Fprintf(w, `{"InterfaceName":{ "SrcName":"cnt0", "DstPrefix":"veth"}}`) - } - }) - - mux.HandleFunc(fmt.Sprintf("/%s.Leave", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, "null") - }) - - mux.HandleFunc(fmt.Sprintf("/%s.DeleteEndpoint", driverapi.NetworkPluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - if link, err := netlink.LinkByName("cnt0"); err == nil { - netlink.LinkDel(link) - } - fmt.Fprintf(w, "null") - }) - - // IPAM Driver implementation - var ( - poolRequest remoteipam.RequestPoolRequest - poolReleaseReq remoteipam.ReleasePoolRequest - addressRequest remoteipam.RequestAddressRequest - addressReleaseReq remoteipam.ReleaseAddressRequest - lAS = "localAS" - gAS = "globalAS" - pool = "172.28.0.0/16" - poolID = lAS + "/" + pool - gw = "172.28.255.254/16" - ) - - mux.HandleFunc(fmt.Sprintf("/%s.GetDefaultAddressSpaces", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintf(w, `{"LocalDefaultAddressSpace":"`+lAS+`", "GlobalDefaultAddressSpace": "`+gAS+`"}`) - }) - - mux.HandleFunc(fmt.Sprintf("/%s.RequestPool", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&poolRequest) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - if poolRequest.AddressSpace != lAS && poolRequest.AddressSpace != gAS { - fmt.Fprintf(w, `{"Error":"Unknown address space in pool request: `+poolRequest.AddressSpace+`"}`) - } else if poolRequest.Pool != "" && poolRequest.Pool != pool { - fmt.Fprintf(w, `{"Error":"Cannot handle explicit pool requests yet"}`) - } else { - fmt.Fprintf(w, `{"PoolID":"`+poolID+`", "Pool":"`+pool+`"}`) - } - }) - - mux.HandleFunc(fmt.Sprintf("/%s.RequestAddress", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&addressRequest) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - // make sure libnetwork is now querying on the expected pool id - if addressRequest.PoolID != poolID { - fmt.Fprintf(w, `{"Error":"unknown pool id"}`) - } else if addressRequest.Address != "" { - fmt.Fprintf(w, `{"Error":"Cannot handle explicit address requests yet"}`) - } else { - fmt.Fprintf(w, `{"Address":"`+gw+`"}`) - } - }) - - mux.HandleFunc(fmt.Sprintf("/%s.ReleaseAddress", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&addressReleaseReq) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - // make sure libnetwork is now asking to release the expected address from the expected poolid - if addressRequest.PoolID != poolID { - fmt.Fprintf(w, `{"Error":"unknown pool id"}`) - } else if addressReleaseReq.Address != gw { - fmt.Fprintf(w, `{"Error":"unknown address"}`) - } else { - fmt.Fprintf(w, "null") - } - }) - - mux.HandleFunc(fmt.Sprintf("/%s.ReleasePool", ipamapi.PluginEndpointType), func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(&poolReleaseReq) - if err != nil { - http.Error(w, "Unable to decode JSON payload: "+err.Error(), http.StatusBadRequest) - return - } - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - // make sure libnetwork is now asking to release the expected poolid - if addressRequest.PoolID != poolID { - fmt.Fprintf(w, `{"Error":"unknown pool id"}`) - } else { - fmt.Fprintf(w, "null") - } - }) - - err := os.MkdirAll("/etc/docker/plugins", 0755) - c.Assert(err, checker.IsNil) - - fileName := fmt.Sprintf("/etc/docker/plugins/%s.spec", netDrv) - err = ioutil.WriteFile(fileName, []byte(url), 0644) - c.Assert(err, checker.IsNil) - - ipamFileName := fmt.Sprintf("/etc/docker/plugins/%s.spec", ipamDrv) - err = ioutil.WriteFile(ipamFileName, []byte(url), 0644) - c.Assert(err, checker.IsNil) -} - -func (s *DockerSwarmSuite) TestSwarmNetworkPlugin(c *check.C) { - mux := http.NewServeMux() - s.server = httptest.NewServer(mux) - c.Assert(s.server, check.NotNil, check.Commentf("Failed to start an HTTP Server")) - setupRemoteGlobalNetworkPlugin(c, mux, s.server.URL, globalNetworkPlugin, globalIPAMPlugin) - defer func() { - s.server.Close() - err := os.RemoveAll("/etc/docker/plugins") - c.Assert(err, checker.IsNil) - }() - - d := s.AddDaemon(c, true, true) - - out, err := d.Cmd("network", "create", "-d", globalNetworkPlugin, "foo") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "not supported in swarm mode") -} - -// Test case for #24712 -func (s *DockerSwarmSuite) TestSwarmServiceEnvFile(c *check.C) { - d := s.AddDaemon(c, true, true) - - path := filepath.Join(d.folder, "env.txt") - err := ioutil.WriteFile(path, []byte("VAR1=A\nVAR2=A\n"), 0644) - c.Assert(err, checker.IsNil) - - name := "worker" - out, err := d.Cmd("service", "create", "--env-file", path, "--env", "VAR1=B", "--env", "VAR1=C", "--env", "VAR2=", "--env", "VAR2", "--name", name, "busybox", "top") - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - // The complete env is [VAR1=A VAR2=A VAR1=B VAR1=C VAR2= VAR2] and duplicates will be removed => [VAR1=C VAR2] - out, err = d.Cmd("inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.Env }}", name) - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, "[VAR1=C VAR2]") -} - -func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *check.C) { - d := s.AddDaemon(c, true, true) - - name := "top" - - ttyCheck := "if [ -t 0 ]; then echo TTY > /status && top; else echo none > /status && top; fi" - - // Without --tty - expectedOutput := "none" - out, err := d.Cmd("service", "create", "--name", name, "busybox", "sh", "-c", ttyCheck) - c.Assert(err, checker.IsNil) - - // Make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - // We need to get the container id. - out, err = d.Cmd("ps", "-a", "-q", "--no-trunc") - c.Assert(err, checker.IsNil) - id := strings.TrimSpace(out) - - out, err = d.Cmd("exec", id, "cat", "/status") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) - - // Remove service - out, err = d.Cmd("service", "rm", name) - c.Assert(err, checker.IsNil) - // Make sure container has been destroyed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 0) - - // With --tty - expectedOutput = "TTY" - out, err = d.Cmd("service", "create", "--name", name, "--tty", "busybox", "sh", "-c", ttyCheck) - c.Assert(err, checker.IsNil) - - // Make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - // We need to get the container id. - out, err = d.Cmd("ps", "-a", "-q", "--no-trunc") - c.Assert(err, checker.IsNil) - id = strings.TrimSpace(out) - - out, err = d.Cmd("exec", id, "cat", "/status") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) -} - -func (s *DockerSwarmSuite) TestSwarmServiceTTYUpdate(c *check.C) { - d := s.AddDaemon(c, true, true) - - // Create a service - name := "top" - _, err := d.Cmd("service", "create", "--name", name, "busybox", "top") - c.Assert(err, checker.IsNil) - - // Make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - out, err := d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.TTY }}", name) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "false") - - _, err = d.Cmd("service", "update", "--tty", name) - c.Assert(err, checker.IsNil) - - out, err = d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.TTY }}", name) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "true") -} - -func (s *DockerSwarmSuite) TestDNSConfig(c *check.C) { - d := s.AddDaemon(c, true, true) - - // Create a service - name := "top" - _, err := d.Cmd("service", "create", "--name", name, "--dns=1.2.3.4", "--dns-search=example.com", "--dns-option=timeout:3", "busybox", "top") - c.Assert(err, checker.IsNil) - - // Make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - // We need to get the container id. - out, err := d.Cmd("ps", "-a", "-q", "--no-trunc") - c.Assert(err, checker.IsNil) - id := strings.TrimSpace(out) - - // Compare against expected output. - expectedOutput1 := "nameserver 1.2.3.4" - expectedOutput2 := "search example.com" - expectedOutput3 := "options timeout:3" - out, err = d.Cmd("exec", id, "cat", "/etc/resolv.conf") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, expectedOutput1, check.Commentf("Expected '%s', but got %q", expectedOutput1, out)) - c.Assert(out, checker.Contains, expectedOutput2, check.Commentf("Expected '%s', but got %q", expectedOutput2, out)) - c.Assert(out, checker.Contains, expectedOutput3, check.Commentf("Expected '%s', but got %q", expectedOutput3, out)) -} - -func (s *DockerSwarmSuite) TestDNSConfigUpdate(c *check.C) { - d := s.AddDaemon(c, true, true) - - // Create a service - name := "top" - _, err := d.Cmd("service", "create", "--name", name, "busybox", "top") - c.Assert(err, checker.IsNil) - - // Make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - _, err = d.Cmd("service", "update", "--dns-add=1.2.3.4", "--dns-search-add=example.com", "--dns-option-add=timeout:3", name) - c.Assert(err, checker.IsNil) - - out, err := d.Cmd("service", "inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.DNSConfig }}", name) - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "{[1.2.3.4] [example.com] [timeout:3]}") -} - -func (s *DockerSwarmSuite) TestSwarmInitLocked(c *check.C) { - d := s.AddDaemon(c, false, false) - - outs, err := d.Cmd("swarm", "init", "--autolock") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs)) - - c.Assert(outs, checker.Contains, "docker swarm unlock") - - var unlockKey string - for _, line := range strings.Split(outs, "\n") { - if strings.Contains(line, "SWMKEY") { - unlockKey = strings.TrimSpace(line) - break - } - } - - c.Assert(unlockKey, checker.Not(checker.Equals), "") - - outs, err = d.Cmd("swarm", "unlock-key", "-q") - c.Assert(outs, checker.Equals, unlockKey+"\n") - - info, err := d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - - c.Assert(d.Restart(), checker.IsNil) - - info, err = d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateLocked) - - cmd := d.command("swarm", "unlock") - cmd.Stdin = bytes.NewBufferString("wrong-secret-key") - out, err := cmd.CombinedOutput() - c.Assert(err, checker.NotNil, check.Commentf("out: %v", string(out))) - c.Assert(string(out), checker.Contains, "invalid key") - - cmd = d.command("swarm", "unlock") - cmd.Stdin = bytes.NewBufferString(unlockKey) - out, err = cmd.CombinedOutput() - c.Assert(err, checker.IsNil, check.Commentf("out: %v", string(out))) - - info, err = d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - - outs, err = d.Cmd("node", "ls") - c.Assert(err, checker.IsNil) - c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked") - - outs, err = d.Cmd("swarm", "update", "--autolock=false") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs)) - - // Wait for autolock to be turned off - time.Sleep(time.Second) - - c.Assert(d.Restart(), checker.IsNil) - - info, err = d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - - outs, err = d.Cmd("node", "ls") - c.Assert(err, checker.IsNil) - c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked") -} - -func (s *DockerSwarmSuite) TestSwarmLeaveLocked(c *check.C) { - d := s.AddDaemon(c, false, false) - - outs, err := d.Cmd("swarm", "init", "--autolock") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs)) - - c.Assert(d.Restart("--swarm-default-advertise-addr=lo"), checker.IsNil) - - info, err := d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateLocked) - - outs, _ = d.Cmd("node", "ls") - c.Assert(outs, checker.Contains, "Swarm is encrypted and needs to be unlocked") - - outs, err = d.Cmd("swarm", "leave", "--force") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs)) - - info, err = d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateInactive) - - outs, err = d.Cmd("swarm", "init") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs)) - - info, err = d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) -} - -func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) { - d := s.AddDaemon(c, true, true) - - outs, err := d.Cmd("swarm", "update", "--autolock") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs)) - - c.Assert(outs, checker.Contains, "docker swarm unlock") - - var unlockKey string - for _, line := range strings.Split(outs, "\n") { - if strings.Contains(line, "SWMKEY") { - unlockKey = strings.TrimSpace(line) - break - } - } - - c.Assert(unlockKey, checker.Not(checker.Equals), "") - - outs, err = d.Cmd("swarm", "unlock-key", "-q") - c.Assert(outs, checker.Equals, unlockKey+"\n") - - // Rotate multiple times - for i := 0; i != 3; i++ { - outs, err = d.Cmd("swarm", "unlock-key", "-q", "--rotate") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs)) - // Strip \n - newUnlockKey := outs[:len(outs)-1] - c.Assert(newUnlockKey, checker.Not(checker.Equals), "") - c.Assert(newUnlockKey, checker.Not(checker.Equals), unlockKey) - - c.Assert(d.Restart(), checker.IsNil) - - info, err := d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateLocked) - - outs, _ = d.Cmd("node", "ls") - c.Assert(outs, checker.Contains, "Swarm is encrypted and needs to be unlocked") - - cmd := d.command("swarm", "unlock") - cmd.Stdin = bytes.NewBufferString(unlockKey) - out, err := cmd.CombinedOutput() - - if err == nil { - // On occasion, the daemon may not have finished - // rotating the KEK before restarting. The test is - // intentionally written to explore this behavior. - // When this happens, unlocking with the old key will - // succeed. If we wait for the rotation to happen and - // restart again, the new key should be required this - // time. - - time.Sleep(3 * time.Second) - - c.Assert(d.Restart(), checker.IsNil) - - cmd = d.command("swarm", "unlock") - cmd.Stdin = bytes.NewBufferString(unlockKey) - out, err = cmd.CombinedOutput() - } - c.Assert(err, checker.NotNil, check.Commentf("out: %v", string(out))) - c.Assert(string(out), checker.Contains, "invalid key") - - outs, _ = d.Cmd("node", "ls") - c.Assert(outs, checker.Contains, "Swarm is encrypted and needs to be unlocked") - - cmd = d.command("swarm", "unlock") - cmd.Stdin = bytes.NewBufferString(newUnlockKey) - out, err = cmd.CombinedOutput() - c.Assert(err, checker.IsNil, check.Commentf("out: %v", string(out))) - - info, err = d.info() - c.Assert(err, checker.IsNil) - c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive) - - outs, err = d.Cmd("node", "ls") - c.Assert(err, checker.IsNil) - c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked") - - unlockKey = newUnlockKey - } -} - -func (s *DockerSwarmSuite) TestExtraHosts(c *check.C) { - d := s.AddDaemon(c, true, true) - - // Create a service - name := "top" - _, err := d.Cmd("service", "create", "--name", name, "--host=example.com:1.2.3.4", "busybox", "top") - c.Assert(err, checker.IsNil) - - // Make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - // We need to get the container id. - out, err := d.Cmd("ps", "-a", "-q", "--no-trunc") - c.Assert(err, checker.IsNil) - id := strings.TrimSpace(out) - - // Compare against expected output. - expectedOutput := "1.2.3.4\texample.com" - out, err = d.Cmd("exec", id, "cat", "/etc/hosts") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out)) -} - -func (s *DockerSwarmSuite) TestSwarmManagerAddress(c *check.C) { - d1 := s.AddDaemon(c, true, true) - d2 := s.AddDaemon(c, true, false) - d3 := s.AddDaemon(c, true, false) - - // Manager Addresses will always show Node 1's address - expectedOutput := fmt.Sprintf("Manager Addresses:\n 127.0.0.1:%d\n", d1.port) - - out, err := d1.Cmd("info") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, expectedOutput) - - out, err = d2.Cmd("info") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, expectedOutput) - - out, err = d3.Cmd("info") - c.Assert(err, checker.IsNil) - c.Assert(out, checker.Contains, expectedOutput) -} - -func (s *DockerSwarmSuite) TestSwarmServiceInspectPretty(c *check.C) { - d := s.AddDaemon(c, true, true) - - name := "top" - out, err := d.Cmd("service", "create", "--name", name, "--limit-cpu=0.5", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - expectedOutput := ` -Resources: - Limits: - CPU: 0.5` - out, err = d.Cmd("service", "inspect", "--pretty", name) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, expectedOutput, check.Commentf(out)) -} - -func (s *DockerSwarmSuite) TestSwarmNetworkIPAMOptions(c *check.C) { - d := s.AddDaemon(c, true, true) - - out, err := d.Cmd("network", "create", "-d", "overlay", "--ipam-opt", "foo=bar", "foo") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - - out, err = d.Cmd("network", "inspect", "--format", "{{.IPAM.Options}}", "foo") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Equals, "map[foo:bar]") - - out, err = d.Cmd("service", "create", "--network=foo", "--name", "top", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - out, err = d.Cmd("network", "inspect", "--format", "{{.IPAM.Options}}", "foo") - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(strings.TrimSpace(out), checker.Equals, "map[foo:bar]") -} - -// TODO: migrate to a unit test -// This test could be migrated to unit test and save costly integration test, -// once PR #29143 is merged. -func (s *DockerSwarmSuite) TestSwarmUpdateWithoutArgs(c *check.C) { - d := s.AddDaemon(c, true, true) - - expectedOutput := ` -Usage: docker swarm update [OPTIONS] - -Update the swarm - -Options:` - - out, err := d.Cmd("swarm", "update") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - c.Assert(out, checker.Contains, expectedOutput, check.Commentf(out)) -} - -func (s *DockerTrustedSwarmSuite) TestTrustedServiceCreate(c *check.C) { - d := s.swarmSuite.AddDaemon(c, true, true) - - // Attempt creating a service from an image that is known to notary. - repoName := s.trustSuite.setupTrustedImage(c, "trusted-pull") - - name := "trusted" - serviceCmd := d.command("-D", "service", "create", "--name", name, repoName, "top") - s.trustSuite.trustedCmd(serviceCmd) - out, _, err := runCommandWithOutput(serviceCmd) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "resolved image tag to", check.Commentf(out)) - - out, err = d.Cmd("service", "inspect", "--pretty", name) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, repoName+"@", check.Commentf(out)) - - // Try trusted service create on an untrusted tag. - - repoName = fmt.Sprintf("%v/untrustedservicecreate/createtest:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - dockerCmd(c, "push", repoName) - dockerCmd(c, "rmi", repoName) - - name = "untrusted" - serviceCmd = d.command("service", "create", "--name", name, repoName, "top") - s.trustSuite.trustedCmd(serviceCmd) - out, _, err = runCommandWithOutput(serviceCmd) - - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Error: remote trust data does not exist", check.Commentf(out)) - - out, err = d.Cmd("service", "inspect", "--pretty", name) - c.Assert(err, checker.NotNil, check.Commentf(out)) -} - -func (s *DockerTrustedSwarmSuite) TestTrustedServiceUpdate(c *check.C) { - d := s.swarmSuite.AddDaemon(c, true, true) - - // Attempt creating a service from an image that is known to notary. - repoName := s.trustSuite.setupTrustedImage(c, "trusted-pull") - - name := "myservice" - - // Create a service without content trust - _, err := d.Cmd("service", "create", "--name", name, repoName, "top") - c.Assert(err, checker.IsNil) - - out, err := d.Cmd("service", "inspect", "--pretty", name) - c.Assert(err, checker.IsNil, check.Commentf(out)) - // Daemon won't insert the digest because this is disabled by - // DOCKER_SERVICE_PREFER_OFFLINE_IMAGE. - c.Assert(out, check.Not(checker.Contains), repoName+"@", check.Commentf(out)) - - serviceCmd := d.command("-D", "service", "update", "--image", repoName, name) - s.trustSuite.trustedCmd(serviceCmd) - out, _, err = runCommandWithOutput(serviceCmd) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "resolved image tag to", check.Commentf(out)) - - out, err = d.Cmd("service", "inspect", "--pretty", name) - c.Assert(err, checker.IsNil, check.Commentf(out)) - c.Assert(out, checker.Contains, repoName+"@", check.Commentf(out)) - - // Try trusted service update on an untrusted tag. - - repoName = fmt.Sprintf("%v/untrustedservicecreate/createtest:latest", privateRegistryURL) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - dockerCmd(c, "push", repoName) - dockerCmd(c, "rmi", repoName) - - serviceCmd = d.command("service", "update", "--image", repoName, name) - s.trustSuite.trustedCmd(serviceCmd) - out, _, err = runCommandWithOutput(serviceCmd) - - c.Assert(err, check.NotNil, check.Commentf(out)) - c.Assert(string(out), checker.Contains, "Error: remote trust data does not exist", check.Commentf(out)) -} - -// Test case for issue #27866, which did not allow NW name that is the prefix of a swarm NW ID. -// e.g. if the ingress ID starts with "n1", it was impossible to create a NW named "n1". -func (s *DockerSwarmSuite) TestSwarmNetworkCreateIssue27866(c *check.C) { - d := s.AddDaemon(c, true, true) - out, err := d.Cmd("network", "inspect", "-f", "{{.Id}}", "ingress") - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - ingressID := strings.TrimSpace(out) - c.Assert(ingressID, checker.Not(checker.Equals), "") - - // create a network of which name is the prefix of the ID of an overlay network - // (ingressID in this case) - newNetName := ingressID[0:2] - out, err = d.Cmd("network", "create", "--driver", "overlay", newNetName) - // In #27866, it was failing because of "network with name %s already exists" - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - out, err = d.Cmd("network", "rm", newNetName) - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) -} - -// Test case for https://github.com/docker/docker/pull/27938#issuecomment-265768303 -// This test creates two networks with the same name sequentially, with various drivers. -// Since the operations in this test are done sequentially, the 2nd call should fail with -// "network with name FOO already exists". -// Note that it is to ok have multiple networks with the same name if the operations are done -// in parallel. (#18864) -func (s *DockerSwarmSuite) TestSwarmNetworkCreateDup(c *check.C) { - d := s.AddDaemon(c, true, true) - drivers := []string{"bridge", "overlay"} - for i, driver1 := range drivers { - nwName := fmt.Sprintf("network-test-%d", i) - for _, driver2 := range drivers { - c.Logf("Creating a network named %q with %q, then %q", - nwName, driver1, driver2) - out, err := d.Cmd("network", "create", "--driver", driver1, nwName) - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - out, err = d.Cmd("network", "create", "--driver", driver2, nwName) - c.Assert(out, checker.Contains, - fmt.Sprintf("network with name %s already exists", nwName)) - c.Assert(err, checker.NotNil) - c.Logf("As expected, the attempt to network %q with %q failed: %s", - nwName, driver2, out) - out, err = d.Cmd("network", "rm", nwName) - c.Assert(err, checker.IsNil, check.Commentf("out: %v", out)) - } - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_swarm_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_swarm_unix_test.go deleted file mode 100644 index d9e56ce..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_swarm_unix_test.go +++ /dev/null @@ -1,52 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "strings" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSwarmSuite) TestSwarmVolumePlugin(c *check.C) { - d := s.AddDaemon(c, true, true) - - out, err := d.Cmd("service", "create", "--mount", "type=volume,source=my-volume,destination=/foo,volume-driver=customvolumedriver", "--name", "top", "busybox", "top") - c.Assert(err, checker.IsNil, check.Commentf(out)) - - // Make sure task stays pending before plugin is available - waitAndAssert(c, defaultReconciliationTimeout, d.checkServiceTasksInState("top", swarm.TaskStatePending, "missing plugin on 1 node"), checker.Equals, 1) - - plugin := newVolumePlugin(c, "customvolumedriver") - defer plugin.Close() - - // create a dummy volume to trigger lazy loading of the plugin - out, err = d.Cmd("volume", "create", "-d", "customvolumedriver", "hello") - - // TODO(aaronl): It will take about 15 seconds for swarm to realize the - // plugin was loaded. Switching the test over to plugin v2 would avoid - // this long delay. - - // make sure task has been deployed. - waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1) - - out, err = d.Cmd("ps", "-q") - c.Assert(err, checker.IsNil) - containerID := strings.TrimSpace(out) - - out, err = d.Cmd("inspect", "-f", "{{json .Mounts}}", containerID) - c.Assert(err, checker.IsNil) - - var mounts []struct { - Name string - Driver string - } - - c.Assert(json.NewDecoder(strings.NewReader(out)).Decode(&mounts), checker.IsNil) - c.Assert(len(mounts), checker.Equals, 1, check.Commentf(out)) - c.Assert(mounts[0].Name, checker.Equals, "my-volume") - c.Assert(mounts[0].Driver, checker.Equals, "customvolumedriver") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_tag_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_tag_test.go deleted file mode 100644 index b7d2b1d..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_tag_test.go +++ /dev/null @@ -1,225 +0,0 @@ -package main - -import ( - "fmt" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/stringutils" - "github.com/go-check/check" -) - -// tagging a named image in a new unprefixed repo should work -func (s *DockerSuite) TestTagUnprefixedRepoByName(c *check.C) { - // Don't attempt to pull on Windows as not in hub. It's installed - // as an image through .ensure-frozen-images-windows - if daemonPlatform != "windows" { - if err := pullImageIfNotExist("busybox:latest"); err != nil { - c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") - } - } - - dockerCmd(c, "tag", "busybox:latest", "testfoobarbaz") -} - -// tagging an image by ID in a new unprefixed repo should work -func (s *DockerSuite) TestTagUnprefixedRepoByID(c *check.C) { - imageID := inspectField(c, "busybox", "Id") - dockerCmd(c, "tag", imageID, "testfoobarbaz") -} - -// ensure we don't allow the use of invalid repository names; these tag operations should fail -func (s *DockerSuite) TestTagInvalidUnprefixedRepo(c *check.C) { - invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd", "FOO/bar"} - - for _, repo := range invalidRepos { - out, _, err := dockerCmdWithError("tag", "busybox", repo) - c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repo, out)) - } -} - -// ensure we don't allow the use of invalid tags; these tag operations should fail -func (s *DockerSuite) TestTagInvalidPrefixedRepo(c *check.C) { - longTag := stringutils.GenerateRandomAlphaOnlyString(121) - - invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag} - - for _, repotag := range invalidTags { - out, _, err := dockerCmdWithError("tag", "busybox", repotag) - c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repotag, out)) - } -} - -// ensure we allow the use of valid tags -func (s *DockerSuite) TestTagValidPrefixedRepo(c *check.C) { - // Don't attempt to pull on Windows as not in hub. It's installed - // as an image through .ensure-frozen-images-windows - if daemonPlatform != "windows" { - if err := pullImageIfNotExist("busybox:latest"); err != nil { - c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") - } - } - - validRepos := []string{"fooo/bar", "fooaa/test", "foooo:t", "HOSTNAME.DOMAIN.COM:443/foo/bar"} - - for _, repo := range validRepos { - _, _, err := dockerCmdWithError("tag", "busybox:latest", repo) - if err != nil { - c.Errorf("tag busybox %v should have worked: %s", repo, err) - continue - } - deleteImages(repo) - } -} - -// tag an image with an existed tag name without -f option should work -func (s *DockerSuite) TestTagExistedNameWithoutForce(c *check.C) { - // Don't attempt to pull on Windows as not in hub. It's installed - // as an image through .ensure-frozen-images-windows - if daemonPlatform != "windows" { - if err := pullImageIfNotExist("busybox:latest"); err != nil { - c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") - } - } - - dockerCmd(c, "tag", "busybox:latest", "busybox:test") -} - -func (s *DockerSuite) TestTagWithPrefixHyphen(c *check.C) { - // Don't attempt to pull on Windows as not in hub. It's installed - // as an image through .ensure-frozen-images-windows - if daemonPlatform != "windows" { - if err := pullImageIfNotExist("busybox:latest"); err != nil { - c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") - } - } - // test repository name begin with '-' - out, _, err := dockerCmdWithError("tag", "busybox:latest", "-busybox:test") - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed")) - - // test namespace name begin with '-' - out, _, err = dockerCmdWithError("tag", "busybox:latest", "-test/busybox:test") - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed")) - - // test index name begin with '-' - out, _, err = dockerCmdWithError("tag", "busybox:latest", "-index:5000/busybox:test") - c.Assert(err, checker.NotNil, check.Commentf(out)) - c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed")) -} - -// ensure tagging using official names works -// ensure all tags result in the same name -func (s *DockerSuite) TestTagOfficialNames(c *check.C) { - names := []string{ - "docker.io/busybox", - "index.docker.io/busybox", - "library/busybox", - "docker.io/library/busybox", - "index.docker.io/library/busybox", - } - - for _, name := range names { - out, exitCode, err := dockerCmdWithError("tag", "busybox:latest", name+":latest") - if err != nil || exitCode != 0 { - c.Errorf("tag busybox %v should have worked: %s, %s", name, err, out) - continue - } - - // ensure we don't have multiple tag names. - out, _, err = dockerCmdWithError("images") - if err != nil { - c.Errorf("listing images failed with errors: %v, %s", err, out) - } else if strings.Contains(out, name) { - c.Errorf("images should not have listed '%s'", name) - deleteImages(name + ":latest") - } - } - - for _, name := range names { - _, exitCode, err := dockerCmdWithError("tag", name+":latest", "fooo/bar:latest") - if err != nil || exitCode != 0 { - c.Errorf("tag %v fooo/bar should have worked: %s", name, err) - continue - } - deleteImages("fooo/bar:latest") - } -} - -// ensure tags can not match digests -func (s *DockerSuite) TestTagMatchesDigest(c *check.C) { - // Don't attempt to pull on Windows as not in hub. It's installed - // as an image through .ensure-frozen-images-windows - if daemonPlatform != "windows" { - if err := pullImageIfNotExist("busybox:latest"); err != nil { - c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") - } - } - digest := "busybox@sha256:abcdef76720241213f5303bda7704ec4c2ef75613173910a56fb1b6e20251507" - // test setting tag fails - _, _, err := dockerCmdWithError("tag", "busybox:latest", digest) - if err == nil { - c.Fatal("digest tag a name should have failed") - } - // check that no new image matches the digest - _, _, err = dockerCmdWithError("inspect", digest) - if err == nil { - c.Fatal("inspecting by digest should have failed") - } -} - -func (s *DockerSuite) TestTagInvalidRepoName(c *check.C) { - // Don't attempt to pull on Windows as not in hub. It's installed - // as an image through .ensure-frozen-images-windows - if daemonPlatform != "windows" { - if err := pullImageIfNotExist("busybox:latest"); err != nil { - c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") - } - } - - // test setting tag fails - _, _, err := dockerCmdWithError("tag", "busybox:latest", "sha256:sometag") - if err == nil { - c.Fatal("tagging with image named \"sha256\" should have failed") - } -} - -// ensure tags cannot create ambiguity with image ids -func (s *DockerSuite) TestTagTruncationAmbiguity(c *check.C) { - //testRequires(c, DaemonIsLinux) - // Don't attempt to pull on Windows as not in hub. It's installed - // as an image through .ensure-frozen-images-windows - if daemonPlatform != "windows" { - if err := pullImageIfNotExist("busybox:latest"); err != nil { - c.Fatal("couldn't find the busybox:latest image locally and failed to pull it") - } - } - imageID, err := buildImage("notbusybox:latest", - `FROM busybox - MAINTAINER dockerio`, - true) - if err != nil { - c.Fatal(err) - } - truncatedImageID := stringid.TruncateID(imageID) - truncatedTag := fmt.Sprintf("notbusybox:%s", truncatedImageID) - - id := inspectField(c, truncatedTag, "Id") - - // Ensure inspect by image id returns image for image id - c.Assert(id, checker.Equals, imageID) - c.Logf("Built image: %s", imageID) - - // test setting tag fails - _, _, err = dockerCmdWithError("tag", "busybox:latest", truncatedTag) - if err != nil { - c.Fatalf("Error tagging with an image id: %s", err) - } - - id = inspectField(c, truncatedTag, "Id") - - // Ensure id is imageID and not busybox:latest - c.Assert(id, checker.Not(checker.Equals), imageID) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_top_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_top_test.go deleted file mode 100644 index caae290..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_top_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "strings" - - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestTopMultipleArgs(c *check.C) { - out, _ := runSleepingContainer(c, "-d") - cleanedContainerID := strings.TrimSpace(out) - - var expected icmd.Expected - switch daemonPlatform { - case "windows": - expected = icmd.Expected{ExitCode: 1, Err: "Windows does not support arguments to top"} - default: - expected = icmd.Expected{Out: "PID"} - } - result := dockerCmdWithResult("top", cleanedContainerID, "-o", "pid") - c.Assert(result, icmd.Matches, expected) -} - -func (s *DockerSuite) TestTopNonPrivileged(c *check.C) { - out, _ := runSleepingContainer(c, "-d") - cleanedContainerID := strings.TrimSpace(out) - - out1, _ := dockerCmd(c, "top", cleanedContainerID) - out2, _ := dockerCmd(c, "top", cleanedContainerID) - dockerCmd(c, "kill", cleanedContainerID) - - // Windows will list the name of the launched executable which in this case is busybox.exe, without the parameters. - // Linux will display the command executed in the container - var lookingFor string - if daemonPlatform == "windows" { - lookingFor = "busybox.exe" - } else { - lookingFor = "top" - } - - c.Assert(out1, checker.Contains, lookingFor, check.Commentf("top should've listed `%s` in the process list, but failed the first time", lookingFor)) - c.Assert(out2, checker.Contains, lookingFor, check.Commentf("top should've listed `%s` in the process list, but failed the second time", lookingFor)) -} - -// TestTopWindowsCoreProcesses validates that there are lines for the critical -// processes which are found in a Windows container. Note Windows is architecturally -// very different to Linux in this regard. -func (s *DockerSuite) TestTopWindowsCoreProcesses(c *check.C) { - testRequires(c, DaemonIsWindows) - out, _ := runSleepingContainer(c, "-d") - cleanedContainerID := strings.TrimSpace(out) - out1, _ := dockerCmd(c, "top", cleanedContainerID) - lookingFor := []string{"smss.exe", "csrss.exe", "wininit.exe", "services.exe", "lsass.exe", "CExecSvc.exe"} - for i, s := range lookingFor { - c.Assert(out1, checker.Contains, s, check.Commentf("top should've listed `%s` in the process list, but failed. Test case %d", s, i)) - } -} - -func (s *DockerSuite) TestTopPrivileged(c *check.C) { - // Windows does not support --privileged - testRequires(c, DaemonIsLinux, NotUserNamespace) - out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top") - cleanedContainerID := strings.TrimSpace(out) - - out1, _ := dockerCmd(c, "top", cleanedContainerID) - out2, _ := dockerCmd(c, "top", cleanedContainerID) - dockerCmd(c, "kill", cleanedContainerID) - - c.Assert(out1, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the first time")) - c.Assert(out2, checker.Contains, "top", check.Commentf("top should've listed `top` in the process list, but failed the second time")) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_update_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_update_test.go deleted file mode 100644 index 0b31bb4..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_update_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestUpdateRestartPolicy(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "sh", "-c", "sleep 1 && false") - timeout := 60 * time.Second - if daemonPlatform == "windows" { - timeout = 180 * time.Second - } - - id := strings.TrimSpace(string(out)) - - // update restart policy to on-failure:5 - dockerCmd(c, "update", "--restart=on-failure:5", id) - - err := waitExited(id, timeout) - c.Assert(err, checker.IsNil) - - count := inspectField(c, id, "RestartCount") - c.Assert(count, checker.Equals, "5") - - maximumRetryCount := inspectField(c, id, "HostConfig.RestartPolicy.MaximumRetryCount") - c.Assert(maximumRetryCount, checker.Equals, "5") -} - -func (s *DockerSuite) TestUpdateRestartWithAutoRemoveFlag(c *check.C) { - out, _ := runSleepingContainer(c, "--rm") - id := strings.TrimSpace(out) - - // update restart policy for an AutoRemove container - out, _, err := dockerCmdWithError("update", "--restart=always", id) - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "Restart policy cannot be updated because AutoRemove is enabled for the container") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_update_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_update_unix_test.go deleted file mode 100644 index 580ff02..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_update_unix_test.go +++ /dev/null @@ -1,283 +0,0 @@ -// +build !windows - -package main - -import ( - "encoding/json" - "fmt" - "github.com/kr/pty" - "os/exec" - "strings" - "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/parsers/kernel" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestUpdateRunningContainer(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "top") - dockerCmd(c, "update", "-m", "500M", name) - - c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "524288000") - - file := "/sys/fs/cgroup/memory/memory.limit_in_bytes" - out, _ := dockerCmd(c, "exec", name, "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "524288000") -} - -func (s *DockerSuite) TestUpdateRunningContainerWithRestart(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "top") - dockerCmd(c, "update", "-m", "500M", name) - dockerCmd(c, "restart", name) - - c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "524288000") - - file := "/sys/fs/cgroup/memory/memory.limit_in_bytes" - out, _ := dockerCmd(c, "exec", name, "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "524288000") -} - -func (s *DockerSuite) TestUpdateStoppedContainer(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - - name := "test-update-container" - file := "/sys/fs/cgroup/memory/memory.limit_in_bytes" - dockerCmd(c, "run", "--name", name, "-m", "300M", "busybox", "cat", file) - dockerCmd(c, "update", "-m", "500M", name) - - c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "524288000") - - out, _ := dockerCmd(c, "start", "-a", name) - c.Assert(strings.TrimSpace(out), checker.Equals, "524288000") -} - -func (s *DockerSuite) TestUpdatePausedContainer(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, cpuShare) - - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "--cpu-shares", "1000", "busybox", "top") - dockerCmd(c, "pause", name) - dockerCmd(c, "update", "--cpu-shares", "500", name) - - c.Assert(inspectField(c, name, "HostConfig.CPUShares"), checker.Equals, "500") - - dockerCmd(c, "unpause", name) - file := "/sys/fs/cgroup/cpu/cpu.shares" - out, _ := dockerCmd(c, "exec", name, "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "500") -} - -func (s *DockerSuite) TestUpdateWithUntouchedFields(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - testRequires(c, cpuShare) - - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "--cpu-shares", "800", "busybox", "top") - dockerCmd(c, "update", "-m", "500M", name) - - // Update memory and not touch cpus, `cpuset.cpus` should still have the old value - out := inspectField(c, name, "HostConfig.CPUShares") - c.Assert(out, check.Equals, "800") - - file := "/sys/fs/cgroup/cpu/cpu.shares" - out, _ = dockerCmd(c, "exec", name, "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "800") -} - -func (s *DockerSuite) TestUpdateContainerInvalidValue(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "true") - out, _, err := dockerCmdWithError("update", "-m", "2M", name) - c.Assert(err, check.NotNil) - expected := "Minimum memory limit allowed is 4MB" - c.Assert(out, checker.Contains, expected) -} - -func (s *DockerSuite) TestUpdateContainerWithoutFlags(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "true") - _, _, err := dockerCmdWithError("update", name) - c.Assert(err, check.NotNil) -} - -func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) { - testRequires(c, DaemonIsLinux, kernelMemorySupport) - - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "--kernel-memory", "50M", "busybox", "top") - dockerCmd(c, "update", "--kernel-memory", "100M", name) - - c.Assert(inspectField(c, name, "HostConfig.KernelMemory"), checker.Equals, "104857600") - - file := "/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes" - out, _ := dockerCmd(c, "exec", name, "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "104857600") -} - -func (s *DockerSuite) TestUpdateKernelMemoryUninitialized(c *check.C) { - testRequires(c, DaemonIsLinux, kernelMemorySupport) - - isNewKernel := kernel.CheckKernelVersion(4, 6, 0) - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "busybox", "top") - _, _, err := dockerCmdWithError("update", "--kernel-memory", "100M", name) - // Update kernel memory to a running container without kernel memory initialized - // is not allowed before kernel version 4.6. - if !isNewKernel { - c.Assert(err, check.NotNil) - } else { - c.Assert(err, check.IsNil) - } - - dockerCmd(c, "pause", name) - _, _, err = dockerCmdWithError("update", "--kernel-memory", "200M", name) - if !isNewKernel { - c.Assert(err, check.NotNil) - } else { - c.Assert(err, check.IsNil) - } - dockerCmd(c, "unpause", name) - - dockerCmd(c, "stop", name) - dockerCmd(c, "update", "--kernel-memory", "300M", name) - dockerCmd(c, "start", name) - - c.Assert(inspectField(c, name, "HostConfig.KernelMemory"), checker.Equals, "314572800") - - file := "/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes" - out, _ := dockerCmd(c, "exec", name, "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "314572800") -} - -func (s *DockerSuite) TestUpdateSwapMemoryOnly(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - testRequires(c, swapMemorySupport) - - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "--memory", "300M", "--memory-swap", "500M", "busybox", "top") - dockerCmd(c, "update", "--memory-swap", "600M", name) - - c.Assert(inspectField(c, name, "HostConfig.MemorySwap"), checker.Equals, "629145600") - - file := "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes" - out, _ := dockerCmd(c, "exec", name, "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "629145600") -} - -func (s *DockerSuite) TestUpdateInvalidSwapMemory(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - testRequires(c, swapMemorySupport) - - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "--memory", "300M", "--memory-swap", "500M", "busybox", "top") - _, _, err := dockerCmdWithError("update", "--memory-swap", "200M", name) - // Update invalid swap memory should fail. - // This will pass docker config validation, but failed at kernel validation - c.Assert(err, check.NotNil) - - // Update invalid swap memory with failure should not change HostConfig - c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "314572800") - c.Assert(inspectField(c, name, "HostConfig.MemorySwap"), checker.Equals, "524288000") - - dockerCmd(c, "update", "--memory-swap", "600M", name) - - c.Assert(inspectField(c, name, "HostConfig.MemorySwap"), checker.Equals, "629145600") - - file := "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes" - out, _ := dockerCmd(c, "exec", name, "cat", file) - c.Assert(strings.TrimSpace(out), checker.Equals, "629145600") -} - -func (s *DockerSuite) TestUpdateStats(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - testRequires(c, cpuCfsQuota) - name := "foo" - dockerCmd(c, "run", "-d", "-ti", "--name", name, "-m", "500m", "busybox") - - c.Assert(waitRun(name), checker.IsNil) - - getMemLimit := func(id string) uint64 { - resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "") - c.Assert(err, checker.IsNil) - c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json") - - var v *types.Stats - err = json.NewDecoder(body).Decode(&v) - c.Assert(err, checker.IsNil) - body.Close() - - return v.MemoryStats.Limit - } - preMemLimit := getMemLimit(name) - - dockerCmd(c, "update", "--cpu-quota", "2000", name) - - curMemLimit := getMemLimit(name) - - c.Assert(preMemLimit, checker.Equals, curMemLimit) - -} - -func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *check.C) { - testRequires(c, DaemonIsLinux) - testRequires(c, memoryLimitSupport) - testRequires(c, swapMemorySupport) - - name := "test-update-container" - dockerCmd(c, "run", "-d", "--name", name, "--memory", "300M", "busybox", "top") - out, _, err := dockerCmdWithError("update", "--memory", "800M", name) - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "Memory limit should be smaller than already set memoryswap limit") - - dockerCmd(c, "update", "--memory", "800M", "--memory-swap", "1000M", name) -} - -func (s *DockerSuite) TestUpdateNotAffectMonitorRestartPolicy(c *check.C) { - testRequires(c, DaemonIsLinux, cpuShare) - - out, _ := dockerCmd(c, "run", "-tid", "--restart=always", "busybox", "sh") - id := strings.TrimSpace(string(out)) - dockerCmd(c, "update", "--cpu-shares", "512", id) - - cpty, tty, err := pty.Open() - c.Assert(err, checker.IsNil) - defer cpty.Close() - - cmd := exec.Command(dockerBinary, "attach", id) - cmd.Stdin = tty - - c.Assert(cmd.Start(), checker.IsNil) - defer cmd.Process.Kill() - - _, err = cpty.Write([]byte("exit\n")) - c.Assert(err, checker.IsNil) - - c.Assert(cmd.Wait(), checker.IsNil) - - // container should restart again and keep running - err = waitInspect(id, "{{.RestartCount}}", "1", 30*time.Second) - c.Assert(err, checker.IsNil) - c.Assert(waitRun(id), checker.IsNil) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_userns_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_userns_test.go deleted file mode 100644 index acf7423..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_userns_test.go +++ /dev/null @@ -1,98 +0,0 @@ -// +build !windows - -package main - -import ( - "fmt" - "io/ioutil" - "os" - "os/exec" - "path" - "path/filepath" - "strconv" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/system" - "github.com/go-check/check" -) - -// user namespaces test: run daemon with remapped root setting -// 1. validate uid/gid maps are set properly -// 2. verify that files created are owned by remapped root -func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) { - testRequires(c, DaemonIsLinux, SameHostDaemon, UserNamespaceInKernel) - - c.Assert(s.d.StartWithBusybox("--userns-remap", "default"), checker.IsNil) - - tmpDir, err := ioutil.TempDir("", "userns") - c.Assert(err, checker.IsNil) - - defer os.RemoveAll(tmpDir) - - // Set a non-existent path - tmpDirNotExists := path.Join(os.TempDir(), "userns"+stringid.GenerateRandomID()) - defer os.RemoveAll(tmpDirNotExists) - - // we need to find the uid and gid of the remapped root from the daemon's root dir info - uidgid := strings.Split(filepath.Base(s.d.root), ".") - c.Assert(uidgid, checker.HasLen, 2, check.Commentf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.root))) - uid, err := strconv.Atoi(uidgid[0]) - c.Assert(err, checker.IsNil, check.Commentf("Can't parse uid")) - gid, err := strconv.Atoi(uidgid[1]) - c.Assert(err, checker.IsNil, check.Commentf("Can't parse gid")) - - // writable by the remapped root UID/GID pair - c.Assert(os.Chown(tmpDir, uid, gid), checker.IsNil) - - out, err := s.d.Cmd("run", "-d", "--name", "userns", "-v", tmpDir+":/goofy", "-v", tmpDirNotExists+":/donald", "busybox", "sh", "-c", "touch /goofy/testfile; top") - c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) - user := s.findUser(c, "userns") - c.Assert(uidgid[0], checker.Equals, user) - - // check that the created directory is owned by remapped uid:gid - statNotExists, err := system.Stat(tmpDirNotExists) - c.Assert(err, checker.IsNil) - c.Assert(statNotExists.UID(), checker.Equals, uint32(uid), check.Commentf("Created directory not owned by remapped root UID")) - c.Assert(statNotExists.GID(), checker.Equals, uint32(gid), check.Commentf("Created directory not owned by remapped root GID")) - - pid, err := s.d.Cmd("inspect", "--format={{.State.Pid}}", "userns") - c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid)) - // check the uid and gid maps for the PID to ensure root is remapped - // (cmd = cat /proc//uid_map | grep -E '0\s+9999\s+1') - out, rc1, err := runCommandPipelineWithOutput( - exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/uid_map"), - exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", uid))) - c.Assert(rc1, checker.Equals, 0, check.Commentf("Didn't match uid_map: output: %s", out)) - - out, rc2, err := runCommandPipelineWithOutput( - exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/gid_map"), - exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", gid))) - c.Assert(rc2, checker.Equals, 0, check.Commentf("Didn't match gid_map: output: %s", out)) - - // check that the touched file is owned by remapped uid:gid - stat, err := system.Stat(filepath.Join(tmpDir, "testfile")) - c.Assert(err, checker.IsNil) - c.Assert(stat.UID(), checker.Equals, uint32(uid), check.Commentf("Touched file not owned by remapped root UID")) - c.Assert(stat.GID(), checker.Equals, uint32(gid), check.Commentf("Touched file not owned by remapped root GID")) - - // use host usernamespace - out, err = s.d.Cmd("run", "-d", "--name", "userns_skip", "--userns", "host", "busybox", "sh", "-c", "touch /goofy/testfile; top") - c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) - user = s.findUser(c, "userns_skip") - // userns are skipped, user is root - c.Assert(user, checker.Equals, "root") -} - -// findUser finds the uid or name of the user of the first process that runs in a container -func (s *DockerDaemonSuite) findUser(c *check.C, container string) string { - out, err := s.d.Cmd("top", container) - c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) - rows := strings.Split(out, "\n") - if len(rows) < 2 { - // No process rows founds - c.FailNow() - } - return strings.Fields(rows[1])[0] -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_v2_only_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_v2_only_test.go deleted file mode 100644 index 889936a..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_v2_only_test.go +++ /dev/null @@ -1,125 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "net/http" - "os" - - "github.com/go-check/check" -) - -func makefile(contents string) (string, func(), error) { - cleanup := func() { - - } - - f, err := ioutil.TempFile(".", "tmp") - if err != nil { - return "", cleanup, err - } - err = ioutil.WriteFile(f.Name(), []byte(contents), os.ModePerm) - if err != nil { - return "", cleanup, err - } - - cleanup = func() { - err := os.Remove(f.Name()) - if err != nil { - fmt.Println("Error removing tmpfile") - } - } - return f.Name(), cleanup, nil - -} - -// TestV2Only ensures that a daemon in v2-only mode does not -// attempt to contact any v1 registry endpoints. -func (s *DockerRegistrySuite) TestV2Only(c *check.C) { - reg, err := newTestRegistry(c) - c.Assert(err, check.IsNil) - - reg.registerHandler("/v2/", func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(404) - }) - - reg.registerHandler("/v1/.*", func(w http.ResponseWriter, r *http.Request) { - c.Fatal("V1 registry contacted") - }) - - repoName := fmt.Sprintf("%s/busybox", reg.hostport) - - err = s.d.Start("--insecure-registry", reg.hostport, "--disable-legacy-registry=true") - c.Assert(err, check.IsNil) - - dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.hostport)) - c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile")) - defer cleanup() - - s.d.Cmd("build", "--file", dockerfileName, ".") - - s.d.Cmd("run", repoName) - s.d.Cmd("login", "-u", "richard", "-p", "testtest", "-e", "testuser@testdomain.com", reg.hostport) - s.d.Cmd("tag", "busybox", repoName) - s.d.Cmd("push", repoName) - s.d.Cmd("pull", repoName) -} - -// TestV1 starts a daemon in 'normal' mode -// and ensure v1 endpoints are hit for the following operations: -// login, push, pull, build & run -func (s *DockerRegistrySuite) TestV1(c *check.C) { - reg, err := newTestRegistry(c) - c.Assert(err, check.IsNil) - - v2Pings := 0 - reg.registerHandler("/v2/", func(w http.ResponseWriter, r *http.Request) { - v2Pings++ - // V2 ping 404 causes fallback to v1 - w.WriteHeader(404) - }) - - v1Pings := 0 - reg.registerHandler("/v1/_ping", func(w http.ResponseWriter, r *http.Request) { - v1Pings++ - }) - - v1Logins := 0 - reg.registerHandler("/v1/users/", func(w http.ResponseWriter, r *http.Request) { - v1Logins++ - }) - - v1Repo := 0 - reg.registerHandler("/v1/repositories/busybox/", func(w http.ResponseWriter, r *http.Request) { - v1Repo++ - }) - - reg.registerHandler("/v1/repositories/busybox/images", func(w http.ResponseWriter, r *http.Request) { - v1Repo++ - }) - - err = s.d.Start("--insecure-registry", reg.hostport, "--disable-legacy-registry=false") - c.Assert(err, check.IsNil) - - dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.hostport)) - c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile")) - defer cleanup() - - s.d.Cmd("build", "--file", dockerfileName, ".") - c.Assert(v1Repo, check.Equals, 1, check.Commentf("Expected v1 repository access after build")) - - repoName := fmt.Sprintf("%s/busybox", reg.hostport) - s.d.Cmd("run", repoName) - c.Assert(v1Repo, check.Equals, 2, check.Commentf("Expected v1 repository access after run")) - - s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.hostport) - c.Assert(v1Logins, check.Equals, 1, check.Commentf("Expected v1 login attempt")) - - s.d.Cmd("tag", "busybox", repoName) - s.d.Cmd("push", repoName) - - c.Assert(v1Repo, check.Equals, 2) - - s.d.Cmd("pull", repoName) - c.Assert(v1Repo, check.Equals, 3, check.Commentf("Expected v1 repository access after pull")) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_version_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_version_test.go deleted file mode 100644 index 7672beb..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_version_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package main - -import ( - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// ensure docker version works -func (s *DockerSuite) TestVersionEnsureSucceeds(c *check.C) { - out, _ := dockerCmd(c, "version") - stringsToCheck := map[string]int{ - "Client:": 1, - "Server:": 1, - " Version:": 2, - " API version:": 2, - " Go version:": 2, - " Git commit:": 2, - " OS/Arch:": 2, - " Built:": 2, - } - - for k, v := range stringsToCheck { - c.Assert(strings.Count(out, k), checker.Equals, v, check.Commentf("The count of %v in %s does not match excepted", k, out)) - } -} - -// ensure the Windows daemon return the correct platform string -func (s *DockerSuite) TestVersionPlatform_w(c *check.C) { - testRequires(c, DaemonIsWindows) - testVersionPlatform(c, "windows/amd64") -} - -// ensure the Linux daemon return the correct platform string -func (s *DockerSuite) TestVersionPlatform_l(c *check.C) { - testRequires(c, DaemonIsLinux) - testVersionPlatform(c, "linux") -} - -func testVersionPlatform(c *check.C, platform string) { - out, _ := dockerCmd(c, "version") - expected := "OS/Arch: " + platform - - split := strings.Split(out, "\n") - c.Assert(len(split) >= 14, checker.Equals, true, check.Commentf("got %d lines from version", len(split))) - - // Verify the second 'OS/Arch' matches the platform. Experimental has - // more lines of output than 'regular' - bFound := false - for i := 14; i < len(split); i++ { - if strings.Contains(split[i], expected) { - bFound = true - break - } - } - c.Assert(bFound, checker.Equals, true, check.Commentf("Could not find server '%s' in '%s'", expected, out)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_volume_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_volume_test.go deleted file mode 100644 index 61a9413..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_volume_test.go +++ /dev/null @@ -1,427 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/go-check/check" -) - -func (s *DockerSuite) TestVolumeCLICreate(c *check.C) { - dockerCmd(c, "volume", "create") - - _, err := runCommand(exec.Command(dockerBinary, "volume", "create", "-d", "nosuchdriver")) - c.Assert(err, check.Not(check.IsNil)) - - // test using hidden --name option - out, _ := dockerCmd(c, "volume", "create", "--name=test") - name := strings.TrimSpace(out) - c.Assert(name, check.Equals, "test") - - out, _ = dockerCmd(c, "volume", "create", "test2") - name = strings.TrimSpace(out) - c.Assert(name, check.Equals, "test2") -} - -func (s *DockerSuite) TestVolumeCLIInspect(c *check.C) { - c.Assert( - exec.Command(dockerBinary, "volume", "inspect", "doesntexist").Run(), - check.Not(check.IsNil), - check.Commentf("volume inspect should error on non-existent volume"), - ) - - out, _ := dockerCmd(c, "volume", "create") - name := strings.TrimSpace(out) - out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Name }}", name) - c.Assert(strings.TrimSpace(out), check.Equals, name) - - dockerCmd(c, "volume", "create", "test") - out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Name }}", "test") - c.Assert(strings.TrimSpace(out), check.Equals, "test") -} - -func (s *DockerSuite) TestVolumeCLIInspectMulti(c *check.C) { - dockerCmd(c, "volume", "create", "test1") - dockerCmd(c, "volume", "create", "test2") - dockerCmd(c, "volume", "create", "not-shown") - - result := dockerCmdWithResult("volume", "inspect", "--format={{ .Name }}", "test1", "test2", "doesntexist", "not-shown") - c.Assert(result, icmd.Matches, icmd.Expected{ - ExitCode: 1, - Err: "No such volume: doesntexist", - }) - - out := result.Stdout() - outArr := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(outArr), check.Equals, 2, check.Commentf("\n%s", out)) - - c.Assert(out, checker.Contains, "test1") - c.Assert(out, checker.Contains, "test2") - c.Assert(out, checker.Not(checker.Contains), "not-shown") -} - -func (s *DockerSuite) TestVolumeCLILs(c *check.C) { - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - dockerCmd(c, "volume", "create", "aaa") - - dockerCmd(c, "volume", "create", "test") - - dockerCmd(c, "volume", "create", "soo") - dockerCmd(c, "run", "-v", "soo:"+prefix+"/foo", "busybox", "ls", "/") - - out, _ := dockerCmd(c, "volume", "ls") - outArr := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out)) - - assertVolList(c, out, []string{"aaa", "soo", "test"}) -} - -func (s *DockerSuite) TestVolumeLsFormat(c *check.C) { - dockerCmd(c, "volume", "create", "aaa") - dockerCmd(c, "volume", "create", "test") - dockerCmd(c, "volume", "create", "soo") - - out, _ := dockerCmd(c, "volume", "ls", "--format", "{{.Name}}") - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - - expected := []string{"aaa", "soo", "test"} - var names []string - names = append(names, lines...) - c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names)) -} - -func (s *DockerSuite) TestVolumeLsFormatDefaultFormat(c *check.C) { - dockerCmd(c, "volume", "create", "aaa") - dockerCmd(c, "volume", "create", "test") - dockerCmd(c, "volume", "create", "soo") - - config := `{ - "volumesFormat": "{{ .Name }} default" -}` - d, err := ioutil.TempDir("", "integration-cli-") - c.Assert(err, checker.IsNil) - defer os.RemoveAll(d) - - err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644) - c.Assert(err, checker.IsNil) - - out, _ := dockerCmd(c, "--config", d, "volume", "ls") - lines := strings.Split(strings.TrimSpace(string(out)), "\n") - - expected := []string{"aaa default", "soo default", "test default"} - var names []string - names = append(names, lines...) - c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names)) -} - -// assertVolList checks volume retrieved with ls command -// equals to expected volume list -// note: out should be `volume ls [option]` result -func assertVolList(c *check.C, out string, expectVols []string) { - lines := strings.Split(out, "\n") - var volList []string - for _, line := range lines[1 : len(lines)-1] { - volFields := strings.Fields(line) - // wrap all volume name in volList - volList = append(volList, volFields[1]) - } - - // volume ls should contains all expected volumes - c.Assert(volList, checker.DeepEquals, expectVols) -} - -func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *check.C) { - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - dockerCmd(c, "volume", "create", "testnotinuse1") - dockerCmd(c, "volume", "create", "testisinuse1") - dockerCmd(c, "volume", "create", "testisinuse2") - - // Make sure both "created" (but not started), and started - // containers are included in reference counting - dockerCmd(c, "run", "--name", "volume-test1", "-v", "testisinuse1:"+prefix+"/foo", "busybox", "true") - dockerCmd(c, "create", "--name", "volume-test2", "-v", "testisinuse2:"+prefix+"/foo", "busybox", "true") - - out, _ := dockerCmd(c, "volume", "ls") - - // No filter, all volumes should show - c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output")) - c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output")) - c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output")) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=false") - - // Explicitly disabling dangling - c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output")) - c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output")) - c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output")) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=true") - - // Filter "dangling" volumes; only "dangling" (unused) volumes should be in the output - c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output")) - c.Assert(out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected")) - c.Assert(out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected")) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=1") - // Filter "dangling" volumes; only "dangling" (unused) volumes should be in the output, dangling also accept 1 - c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output")) - c.Assert(out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected")) - c.Assert(out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected")) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=0") - // dangling=0 is same as dangling=false case - c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output")) - c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output")) - c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output")) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "name=testisin") - c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output")) - c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("execpeted volume 'testisinuse1' in output")) - c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output")) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invalidDriver") - outArr := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out)) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=local") - outArr = strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out)) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loc") - outArr = strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(outArr), check.Equals, 4, check.Commentf("\n%s", out)) - -} - -func (s *DockerSuite) TestVolumeCLILsErrorWithInvalidFilterName(c *check.C) { - out, _, err := dockerCmdWithError("volume", "ls", "-f", "FOO=123") - c.Assert(err, checker.NotNil) - c.Assert(out, checker.Contains, "Invalid filter") -} - -func (s *DockerSuite) TestVolumeCLILsWithIncorrectFilterValue(c *check.C) { - out, _, err := dockerCmdWithError("volume", "ls", "-f", "dangling=invalid") - c.Assert(err, check.NotNil) - c.Assert(out, checker.Contains, "Invalid filter") -} - -func (s *DockerSuite) TestVolumeCLIRm(c *check.C) { - prefix, _ := getPrefixAndSlashFromDaemonPlatform() - out, _ := dockerCmd(c, "volume", "create") - id := strings.TrimSpace(out) - - dockerCmd(c, "volume", "create", "test") - dockerCmd(c, "volume", "rm", id) - dockerCmd(c, "volume", "rm", "test") - - out, _ = dockerCmd(c, "volume", "ls") - outArr := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out)) - - volumeID := "testing" - dockerCmd(c, "run", "-v", volumeID+":"+prefix+"/foo", "--name=test", "busybox", "sh", "-c", "echo hello > /foo/bar") - out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "volume", "rm", "testing")) - c.Assert( - err, - check.Not(check.IsNil), - check.Commentf("Should not be able to remove volume that is in use by a container\n%s", out)) - - out, _ = dockerCmd(c, "run", "--volumes-from=test", "--name=test2", "busybox", "sh", "-c", "cat /foo/bar") - c.Assert(strings.TrimSpace(out), check.Equals, "hello") - dockerCmd(c, "rm", "-fv", "test2") - dockerCmd(c, "volume", "inspect", volumeID) - dockerCmd(c, "rm", "-f", "test") - - out, _ = dockerCmd(c, "run", "--name=test2", "-v", volumeID+":"+prefix+"/foo", "busybox", "sh", "-c", "cat /foo/bar") - c.Assert(strings.TrimSpace(out), check.Equals, "hello", check.Commentf("volume data was removed")) - dockerCmd(c, "rm", "test2") - - dockerCmd(c, "volume", "rm", volumeID) - c.Assert( - exec.Command("volume", "rm", "doesntexist").Run(), - check.Not(check.IsNil), - check.Commentf("volume rm should fail with non-existent volume"), - ) -} - -func (s *DockerSuite) TestVolumeCLINoArgs(c *check.C) { - out, _ := dockerCmd(c, "volume") - // no args should produce the cmd usage output - usage := "Usage: docker volume COMMAND" - c.Assert(out, checker.Contains, usage) - - // invalid arg should error and show the command usage on stderr - _, stderr, _, err := runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "somearg")) - c.Assert(err, check.NotNil, check.Commentf(stderr)) - c.Assert(stderr, checker.Contains, usage) - - // invalid flag should error and show the flag error and cmd usage - _, stderr, _, err = runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "--no-such-flag")) - c.Assert(err, check.NotNil, check.Commentf(stderr)) - c.Assert(stderr, checker.Contains, usage) - c.Assert(stderr, checker.Contains, "unknown flag: --no-such-flag") -} - -func (s *DockerSuite) TestVolumeCLIInspectTmplError(c *check.C) { - out, _ := dockerCmd(c, "volume", "create") - name := strings.TrimSpace(out) - - out, exitCode, err := dockerCmdWithError("volume", "inspect", "--format='{{ .FooBar }}'", name) - c.Assert(err, checker.NotNil, check.Commentf("Output: %s", out)) - c.Assert(exitCode, checker.Equals, 1, check.Commentf("Output: %s", out)) - c.Assert(out, checker.Contains, "Template parsing error") -} - -func (s *DockerSuite) TestVolumeCLICreateWithOpts(c *check.C) { - testRequires(c, DaemonIsLinux) - - dockerCmd(c, "volume", "create", "-d", "local", "test", "--opt=type=tmpfs", "--opt=device=tmpfs", "--opt=o=size=1m,uid=1000") - out, _ := dockerCmd(c, "run", "-v", "test:/foo", "busybox", "mount") - - mounts := strings.Split(out, "\n") - var found bool - for _, m := range mounts { - if strings.Contains(m, "/foo") { - found = true - info := strings.Fields(m) - // tmpfs on type tmpfs (rw,relatime,size=1024k,uid=1000) - c.Assert(info[0], checker.Equals, "tmpfs") - c.Assert(info[2], checker.Equals, "/foo") - c.Assert(info[4], checker.Equals, "tmpfs") - c.Assert(info[5], checker.Contains, "uid=1000") - c.Assert(info[5], checker.Contains, "size=1024k") - } - } - c.Assert(found, checker.Equals, true) -} - -func (s *DockerSuite) TestVolumeCLICreateLabel(c *check.C) { - testVol := "testvolcreatelabel" - testLabel := "foo" - testValue := "bar" - - out, _, err := dockerCmdWithError("volume", "create", "--label", testLabel+"="+testValue, testVol) - c.Assert(err, check.IsNil) - - out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+testLabel+" }}", testVol) - c.Assert(strings.TrimSpace(out), check.Equals, testValue) -} - -func (s *DockerSuite) TestVolumeCLICreateLabelMultiple(c *check.C) { - testVol := "testvolcreatelabel" - - testLabels := map[string]string{ - "foo": "bar", - "baz": "foo", - } - - args := []string{ - "volume", - "create", - testVol, - } - - for k, v := range testLabels { - args = append(args, "--label", k+"="+v) - } - - out, _, err := dockerCmdWithError(args...) - c.Assert(err, check.IsNil) - - for k, v := range testLabels { - out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+k+" }}", testVol) - c.Assert(strings.TrimSpace(out), check.Equals, v) - } -} - -func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *check.C) { - testVol1 := "testvolcreatelabel-1" - out, _, err := dockerCmdWithError("volume", "create", "--label", "foo=bar1", testVol1) - c.Assert(err, check.IsNil) - - testVol2 := "testvolcreatelabel-2" - out, _, err = dockerCmdWithError("volume", "create", "--label", "foo=bar2", testVol2) - c.Assert(err, check.IsNil) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo") - - // filter with label=key - c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output")) - c.Assert(out, checker.Contains, "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2' in output")) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=bar1") - - // filter with label=key=value - c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output")) - c.Assert(out, check.Not(checker.Contains), "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2 in output")) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=non-exist") - outArr := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out)) - - out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=non-exist") - outArr = strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out)) -} - -func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *check.C) { - out, _ := dockerCmd(c, "volume", "create") - id := strings.TrimSpace(out) - - dockerCmd(c, "volume", "rm", "-f", id) - dockerCmd(c, "volume", "rm", "--force", "nonexist") - - out, _ = dockerCmd(c, "volume", "ls") - outArr := strings.Split(strings.TrimSpace(out), "\n") - c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out)) -} - -func (s *DockerSuite) TestVolumeCLIRmForce(c *check.C) { - testRequires(c, SameHostDaemon, DaemonIsLinux) - - name := "test" - out, _ := dockerCmd(c, "volume", "create", name) - id := strings.TrimSpace(out) - c.Assert(id, checker.Equals, name) - - out, _ = dockerCmd(c, "volume", "inspect", "--format", "{{.Mountpoint}}", name) - c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "") - // Mountpoint is in the form of "/var/lib/docker/volumes/.../_data", removing `/_data` - path := strings.TrimSuffix(strings.TrimSpace(out), "/_data") - out, _, err := runCommandWithOutput(exec.Command("rm", "-rf", path)) - c.Assert(err, check.IsNil) - - dockerCmd(c, "volume", "rm", "-f", "test") - out, _ = dockerCmd(c, "volume", "ls") - c.Assert(out, checker.Not(checker.Contains), name) - dockerCmd(c, "volume", "create", "test") - out, _ = dockerCmd(c, "volume", "ls") - c.Assert(out, checker.Contains, name) -} - -func (s *DockerSuite) TestVolumeCliInspectWithVolumeOpts(c *check.C) { - testRequires(c, DaemonIsLinux) - - // Without options - name := "test1" - dockerCmd(c, "volume", "create", "-d", "local", name) - out, _ := dockerCmd(c, "volume", "inspect", "--format={{ .Options }}", name) - c.Assert(strings.TrimSpace(out), checker.Contains, "map[]") - - // With options - name = "test2" - k1, v1 := "type", "tmpfs" - k2, v2 := "device", "tmpfs" - k3, v3 := "o", "size=1m,uid=1000" - dockerCmd(c, "volume", "create", "-d", "local", name, "--opt", fmt.Sprintf("%s=%s", k1, v1), "--opt", fmt.Sprintf("%s=%s", k2, v2), "--opt", fmt.Sprintf("%s=%s", k3, v3)) - out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Options }}", name) - c.Assert(strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k1, v1)) - c.Assert(strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k2, v2)) - c.Assert(strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k3, v3)) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_cli_wait_test.go b/vendor/github.com/docker/docker/integration-cli/docker_cli_wait_test.go deleted file mode 100644 index 961aef5..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_cli_wait_test.go +++ /dev/null @@ -1,97 +0,0 @@ -package main - -import ( - "bytes" - "os/exec" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// non-blocking wait with 0 exit code -func (s *DockerSuite) TestWaitNonBlockedExitZero(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "true") - containerID := strings.TrimSpace(out) - - err := waitInspect(containerID, "{{.State.Running}}", "false", 30*time.Second) - c.Assert(err, checker.IsNil) //Container should have stopped by now - - out, _ = dockerCmd(c, "wait", containerID) - c.Assert(strings.TrimSpace(out), checker.Equals, "0", check.Commentf("failed to set up container, %v", out)) - -} - -// blocking wait with 0 exit code -func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) { - // Windows busybox does not support trap in this way, not sleep with sub-second - // granularity. It will always exit 0x40010004. - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 0' TERM; while true; do usleep 10; done") - containerID := strings.TrimSpace(out) - - c.Assert(waitRun(containerID), checker.IsNil) - - chWait := make(chan string) - go func() { - chWait <- "" - out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "wait", containerID)) - chWait <- out - }() - - <-chWait // make sure the goroutine is started - time.Sleep(100 * time.Millisecond) - dockerCmd(c, "stop", containerID) - - select { - case status := <-chWait: - c.Assert(strings.TrimSpace(status), checker.Equals, "0", check.Commentf("expected exit 0, got %s", status)) - case <-time.After(2 * time.Second): - c.Fatal("timeout waiting for `docker wait` to exit") - } - -} - -// non-blocking wait with random exit code -func (s *DockerSuite) TestWaitNonBlockedExitRandom(c *check.C) { - out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "exit 99") - containerID := strings.TrimSpace(out) - - err := waitInspect(containerID, "{{.State.Running}}", "false", 30*time.Second) - c.Assert(err, checker.IsNil) //Container should have stopped by now - out, _ = dockerCmd(c, "wait", containerID) - c.Assert(strings.TrimSpace(out), checker.Equals, "99", check.Commentf("failed to set up container, %v", out)) - -} - -// blocking wait with random exit code -func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) { - // Cannot run on Windows as trap in Windows busybox does not support trap in this way. - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 99' TERM; while true; do usleep 10; done") - containerID := strings.TrimSpace(out) - c.Assert(waitRun(containerID), checker.IsNil) - - chWait := make(chan error) - waitCmd := exec.Command(dockerBinary, "wait", containerID) - waitCmdOut := bytes.NewBuffer(nil) - waitCmd.Stdout = waitCmdOut - c.Assert(waitCmd.Start(), checker.IsNil) - go func() { - chWait <- waitCmd.Wait() - }() - - dockerCmd(c, "stop", containerID) - - select { - case err := <-chWait: - c.Assert(err, checker.IsNil, check.Commentf(waitCmdOut.String())) - status, err := waitCmdOut.ReadString('\n') - c.Assert(err, checker.IsNil) - c.Assert(strings.TrimSpace(status), checker.Equals, "99", check.Commentf("expected exit 99, got %s", status)) - case <-time.After(2 * time.Second): - waitCmd.Process.Kill() - c.Fatal("timeout waiting for `docker wait` to exit") - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_deprecated_api_v124_test.go b/vendor/github.com/docker/docker/integration-cli/docker_deprecated_api_v124_test.go deleted file mode 100644 index 7bc287e..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_deprecated_api_v124_test.go +++ /dev/null @@ -1,227 +0,0 @@ -// This file will be removed when we completely drop support for -// passing HostConfig to container start API. - -package main - -import ( - "net/http" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func formatV123StartAPIURL(url string) string { - return "/v1.23" + url -} - -func (s *DockerSuite) TestDeprecatedContainerAPIStartHostConfig(c *check.C) { - name := "test-deprecated-api-124" - dockerCmd(c, "create", "--name", name, "busybox") - config := map[string]interface{}{ - "Binds": []string{"/aa:/bb"}, - } - status, body, err := sockRequest("POST", "/containers/"+name+"/start", config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusBadRequest) - c.Assert(string(body), checker.Contains, "was deprecated since v1.10") -} - -func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) { - // TODO Windows CI: Investigate further why this fails on Windows to Windows CI. - testRequires(c, DaemonIsLinux) - path := "/foo" - if daemonPlatform == "windows" { - path = `c:\foo` - } - name := "testing" - config := map[string]interface{}{ - "Image": "busybox", - "Volumes": map[string]struct{}{path: {}}, - } - - status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - bindPath := randomTmpDirPath("test", daemonPlatform) - config = map[string]interface{}{ - "Binds": []string{bindPath + ":" + path}, - } - status, _, err = sockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - - pth, err := inspectMountSourceField(name, path) - c.Assert(err, checker.IsNil) - c.Assert(pth, checker.Equals, bindPath, check.Commentf("expected volume host path to be %s, got %s", bindPath, pth)) -} - -// Test for GH#10618 -func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *check.C) { - // TODO Windows to Windows CI - Port this - testRequires(c, DaemonIsLinux) - name := "testdups" - config := map[string]interface{}{ - "Image": "busybox", - "Volumes": map[string]struct{}{"/tmp": {}}, - } - - status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - bindPath1 := randomTmpDirPath("test1", daemonPlatform) - bindPath2 := randomTmpDirPath("test2", daemonPlatform) - - config = map[string]interface{}{ - "Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"}, - } - status, body, err := sockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusInternalServerError) - c.Assert(string(body), checker.Contains, "Duplicate mount point", check.Commentf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)) -} - -func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumesFrom(c *check.C) { - // TODO Windows to Windows CI - Port this - testRequires(c, DaemonIsLinux) - volName := "voltst" - volPath := "/tmp" - - dockerCmd(c, "run", "--name", volName, "-v", volPath, "busybox") - - name := "TestContainerAPIStartVolumesFrom" - config := map[string]interface{}{ - "Image": "busybox", - "Volumes": map[string]struct{}{volPath: {}}, - } - - status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusCreated) - - config = map[string]interface{}{ - "VolumesFrom": []string{volName}, - } - status, _, err = sockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - - pth, err := inspectMountSourceField(name, volPath) - c.Assert(err, checker.IsNil) - pth2, err := inspectMountSourceField(volName, volPath) - c.Assert(err, checker.IsNil) - c.Assert(pth, checker.Equals, pth2, check.Commentf("expected volume host path to be %s, got %s", pth, pth2)) -} - -// #9981 - Allow a docker created volume (ie, one in /var/lib/docker/volumes) to be used to overwrite (via passing in Binds on api start) an existing volume -func (s *DockerSuite) TestDeprecatedPostContainerBindNormalVolume(c *check.C) { - // TODO Windows to Windows CI - Port this - testRequires(c, DaemonIsLinux) - dockerCmd(c, "create", "-v", "/foo", "--name=one", "busybox") - - fooDir, err := inspectMountSourceField("one", "/foo") - c.Assert(err, checker.IsNil) - - dockerCmd(c, "create", "-v", "/foo", "--name=two", "busybox") - - bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}} - status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/two/start"), bindSpec) - c.Assert(err, checker.IsNil) - c.Assert(status, checker.Equals, http.StatusNoContent) - - fooDir2, err := inspectMountSourceField("two", "/foo") - c.Assert(err, checker.IsNil) - c.Assert(fooDir2, checker.Equals, fooDir, check.Commentf("expected volume path to be %s, got: %s", fooDir, fooDir2)) -} - -func (s *DockerSuite) TestDeprecatedStartWithTooLowMemoryLimit(c *check.C) { - // TODO Windows: Port once memory is supported - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "create", "busybox") - - containerID := strings.TrimSpace(out) - - config := `{ - "CpuShares": 100, - "Memory": 524287 - }` - - res, body, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+containerID+"/start"), strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - b, err2 := readBody(body) - c.Assert(err2, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) - c.Assert(string(b), checker.Contains, "Minimum memory limit allowed is 4MB") -} - -// #14640 -func (s *DockerSuite) TestDeprecatedPostContainersStartWithoutLinksInHostConfig(c *check.C) { - // TODO Windows: Windows doesn't support supplying a hostconfig on start. - // An alternate test could be written to validate the negative testing aspect of this - testRequires(c, DaemonIsLinux) - name := "test-host-config-links" - dockerCmd(c, append([]string{"create", "--name", name, "busybox"}, sleepCommandForDaemonPlatform()...)...) - - hc := inspectFieldJSON(c, name, "HostConfig") - config := `{"HostConfig":` + hc + `}` - - res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) - b.Close() -} - -// #14640 -func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(c *check.C) { - // TODO Windows: Windows doesn't support supplying a hostconfig on start. - // An alternate test could be written to validate the negative testing aspect of this - testRequires(c, DaemonIsLinux) - name := "test-host-config-links" - dockerCmd(c, "run", "--name", "foo", "-d", "busybox", "top") - dockerCmd(c, "create", "--name", name, "--link", "foo:bar", "busybox", "top") - - hc := inspectFieldJSON(c, name, "HostConfig") - config := `{"HostConfig":` + hc + `}` - - res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) - b.Close() -} - -// #14640 -func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLinked(c *check.C) { - // Windows does not support links - testRequires(c, DaemonIsLinux) - name := "test-host-config-links" - out, _ := dockerCmd(c, "run", "--name", "link0", "-d", "busybox", "top") - id := strings.TrimSpace(out) - dockerCmd(c, "create", "--name", name, "--link", id, "busybox", "top") - - hc := inspectFieldJSON(c, name, "HostConfig") - config := `{"HostConfig":` + hc + `}` - - res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) - b.Close() -} - -func (s *DockerSuite) TestDeprecatedStartWithNilDNS(c *check.C) { - // TODO Windows: Add once DNS is supported - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "create", "busybox") - containerID := strings.TrimSpace(out) - - config := `{"HostConfig": {"Dns": null}}` - - res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+containerID+"/start"), strings.NewReader(config), "application/json") - c.Assert(err, checker.IsNil) - c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) - b.Close() - - dns := inspectFieldJSON(c, containerID, "HostConfig.Dns") - c.Assert(dns, checker.Equals, "[]") -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_deprecated_api_v124_unix_test.go b/vendor/github.com/docker/docker/integration-cli/docker_deprecated_api_v124_unix_test.go deleted file mode 100644 index 94ef9b1..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_deprecated_api_v124_unix_test.go +++ /dev/null @@ -1,30 +0,0 @@ -// +build !windows - -package main - -import ( - "fmt" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// #19100 This is a deprecated feature test, it should be removed in Docker 1.12 -func (s *DockerNetworkSuite) TestDeprecatedDockerNetworkStartAPIWithHostconfig(c *check.C) { - netName := "test" - conName := "foo" - dockerCmd(c, "network", "create", netName) - dockerCmd(c, "create", "--name", conName, "busybox", "top") - - config := map[string]interface{}{ - "HostConfig": map[string]interface{}{ - "NetworkMode": netName, - }, - } - _, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/"+conName+"/start"), config) - c.Assert(err, checker.IsNil) - c.Assert(waitRun(conName), checker.IsNil) - networks := inspectField(c, conName, "NetworkSettings.Networks") - c.Assert(networks, checker.Contains, netName, check.Commentf(fmt.Sprintf("Should contain '%s' network", netName))) - c.Assert(networks, checker.Not(checker.Contains), "bridge", check.Commentf("Should not contain 'bridge' network")) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_experimental_network_test.go b/vendor/github.com/docker/docker/integration-cli/docker_experimental_network_test.go deleted file mode 100644 index 85dec31..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_experimental_network_test.go +++ /dev/null @@ -1,594 +0,0 @@ -// +build !windows - -package main - -import ( - "os/exec" - "strings" - "time" - - "github.com/docker/docker/pkg/integration/checker" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/docker/docker/pkg/parsers/kernel" - "github.com/go-check/check" -) - -var ( - MacvlanKernelSupport = testRequirement{ - func() bool { - const macvlanKernelVer = 3 // minimum macvlan kernel support - const macvlanMajorVer = 9 // minimum macvlan major kernel support - kv, err := kernel.GetKernelVersion() - if err != nil { - return false - } - // ensure Kernel version is >= v3.9 for macvlan support - if kv.Kernel < macvlanKernelVer || (kv.Kernel == macvlanKernelVer && kv.Major < macvlanMajorVer) { - return false - } - return true - }, - "kernel version failed to meet the minimum macvlan kernel requirement of 3.9", - } - IpvlanKernelSupport = testRequirement{ - func() bool { - const ipvlanKernelVer = 4 // minimum ipvlan kernel support - const ipvlanMajorVer = 2 // minimum ipvlan major kernel support - kv, err := kernel.GetKernelVersion() - if err != nil { - return false - } - // ensure Kernel version is >= v4.2 for ipvlan support - if kv.Kernel < ipvlanKernelVer || (kv.Kernel == ipvlanKernelVer && kv.Major < ipvlanMajorVer) { - return false - } - return true - }, - "kernel version failed to meet the minimum ipvlan kernel requirement of 4.0.0", - } -) - -func (s *DockerNetworkSuite) TestDockerNetworkMacvlanPersistance(c *check.C) { - // verify the driver automatically provisions the 802.1q link (dm-dummy0.60) - testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - - // master dummy interface 'dm' abbreviation represents 'docker macvlan' - master := "dm-dummy0" - // simulate the master link the vlan tagged subinterface parent link will use - out, err := createMasterDummy(c, master) - c.Assert(err, check.IsNil, check.Commentf(out)) - // create a network specifying the desired sub-interface name - dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.60", "dm-persist") - assertNwIsAvailable(c, "dm-persist") - // Restart docker daemon to test the config has persisted to disk - s.d.Restart() - // verify network is recreated from persistence - assertNwIsAvailable(c, "dm-persist") - // cleanup the master interface that also collects the slave dev - deleteInterface(c, "dm-dummy0") -} - -func (s *DockerNetworkSuite) TestDockerNetworkIpvlanPersistance(c *check.C) { - // verify the driver automatically provisions the 802.1q link (di-dummy0.70) - testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - // master dummy interface 'di' notation represent 'docker ipvlan' - master := "di-dummy0" - // simulate the master link the vlan tagged subinterface parent link will use - out, err := createMasterDummy(c, master) - c.Assert(err, check.IsNil, check.Commentf(out)) - // create a network specifying the desired sub-interface name - dockerCmd(c, "network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.70", "di-persist") - assertNwIsAvailable(c, "di-persist") - // Restart docker daemon to test the config has persisted to disk - s.d.Restart() - // verify network is recreated from persistence - assertNwIsAvailable(c, "di-persist") - // cleanup the master interface that also collects the slave dev - deleteInterface(c, "di-dummy0") -} - -func (s *DockerNetworkSuite) TestDockerNetworkMacvlanSubIntCreate(c *check.C) { - // verify the driver automatically provisions the 802.1q link (dm-dummy0.50) - testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - // master dummy interface 'dm' abbreviation represents 'docker macvlan' - master := "dm-dummy0" - // simulate the master link the vlan tagged subinterface parent link will use - out, err := createMasterDummy(c, master) - c.Assert(err, check.IsNil, check.Commentf(out)) - // create a network specifying the desired sub-interface name - dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.50", "dm-subinterface") - assertNwIsAvailable(c, "dm-subinterface") - // cleanup the master interface which also collects the slave dev - deleteInterface(c, "dm-dummy0") -} - -func (s *DockerNetworkSuite) TestDockerNetworkIpvlanSubIntCreate(c *check.C) { - // verify the driver automatically provisions the 802.1q link (di-dummy0.50) - testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - // master dummy interface 'dm' abbreviation represents 'docker ipvlan' - master := "di-dummy0" - // simulate the master link the vlan tagged subinterface parent link will use - out, err := createMasterDummy(c, master) - c.Assert(err, check.IsNil, check.Commentf(out)) - // create a network specifying the desired sub-interface name - dockerCmd(c, "network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.60", "di-subinterface") - assertNwIsAvailable(c, "di-subinterface") - // cleanup the master interface which also collects the slave dev - deleteInterface(c, "di-dummy0") -} - -func (s *DockerNetworkSuite) TestDockerNetworkMacvlanOverlapParent(c *check.C) { - // verify the same parent interface cannot be used if already in use by an existing network - testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - // master dummy interface 'dm' abbreviation represents 'docker macvlan' - master := "dm-dummy0" - out, err := createMasterDummy(c, master) - c.Assert(err, check.IsNil, check.Commentf(out)) - out, err = createVlanInterface(c, master, "dm-dummy0.40", "40") - c.Assert(err, check.IsNil, check.Commentf(out)) - // create a network using an existing parent interface - dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.40", "dm-subinterface") - assertNwIsAvailable(c, "dm-subinterface") - // attempt to create another network using the same parent iface that should fail - out, _, err = dockerCmdWithError("network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.40", "dm-parent-net-overlap") - // verify that the overlap returns an error - c.Assert(err, check.NotNil) - // cleanup the master interface which also collects the slave dev - deleteInterface(c, "dm-dummy0") -} - -func (s *DockerNetworkSuite) TestDockerNetworkIpvlanOverlapParent(c *check.C) { - // verify the same parent interface cannot be used if already in use by an existing network - testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - // master dummy interface 'dm' abbreviation represents 'docker ipvlan' - master := "di-dummy0" - out, err := createMasterDummy(c, master) - c.Assert(err, check.IsNil, check.Commentf(out)) - out, err = createVlanInterface(c, master, "di-dummy0.30", "30") - c.Assert(err, check.IsNil, check.Commentf(out)) - // create a network using an existing parent interface - dockerCmd(c, "network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.30", "di-subinterface") - assertNwIsAvailable(c, "di-subinterface") - // attempt to create another network using the same parent iface that should fail - out, _, err = dockerCmdWithError("network", "create", "--driver=ipvlan", "-o", "parent=di-dummy0.30", "di-parent-net-overlap") - // verify that the overlap returns an error - c.Assert(err, check.NotNil) - // cleanup the master interface which also collects the slave dev - deleteInterface(c, "di-dummy0") -} - -func (s *DockerNetworkSuite) TestDockerNetworkMacvlanMultiSubnet(c *check.C) { - // create a dual stack multi-subnet Macvlan bridge mode network and validate connectivity between four containers, two on each subnet - testRequires(c, DaemonIsLinux, IPv6, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - dockerCmd(c, "network", "create", "--driver=macvlan", "--ipv6", "--subnet=172.28.100.0/24", "--subnet=172.28.102.0/24", "--gateway=172.28.102.254", - "--subnet=2001:db8:abc2::/64", "--subnet=2001:db8:abc4::/64", "--gateway=2001:db8:abc4::254", "dualstackbridge") - // Ensure the network was created - assertNwIsAvailable(c, "dualstackbridge") - // start dual stack containers and verify the user specified --ip and --ip6 addresses on subnets 172.28.100.0/24 and 2001:db8:abc2::/64 - dockerCmd(c, "run", "-d", "--net=dualstackbridge", "--name=first", "--ip", "172.28.100.20", "--ip6", "2001:db8:abc2::20", "busybox", "top") - dockerCmd(c, "run", "-d", "--net=dualstackbridge", "--name=second", "--ip", "172.28.100.21", "--ip6", "2001:db8:abc2::21", "busybox", "top") - - // Inspect and store the v4 address from specified container on the network dualstackbridge - ip := inspectField(c, "first", "NetworkSettings.Networks.dualstackbridge.IPAddress") - // Inspect and store the v6 address from specified container on the network dualstackbridge - ip6 := inspectField(c, "first", "NetworkSettings.Networks.dualstackbridge.GlobalIPv6Address") - - // verify ipv4 connectivity to the explicit --ipv address second to first - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", strings.TrimSpace(ip)) - c.Assert(err, check.IsNil) - // verify ipv6 connectivity to the explicit --ipv6 address second to first - c.Skip("Temporarily skipping while invesitigating sporadic v6 CI issues") - _, _, err = dockerCmdWithError("exec", "second", "ping6", "-c", "1", strings.TrimSpace(ip6)) - c.Assert(err, check.IsNil) - - // start dual stack containers and verify the user specified --ip and --ip6 addresses on subnets 172.28.102.0/24 and 2001:db8:abc4::/64 - dockerCmd(c, "run", "-d", "--net=dualstackbridge", "--name=third", "--ip", "172.28.102.20", "--ip6", "2001:db8:abc4::20", "busybox", "top") - dockerCmd(c, "run", "-d", "--net=dualstackbridge", "--name=fourth", "--ip", "172.28.102.21", "--ip6", "2001:db8:abc4::21", "busybox", "top") - - // Inspect and store the v4 address from specified container on the network dualstackbridge - ip = inspectField(c, "third", "NetworkSettings.Networks.dualstackbridge.IPAddress") - // Inspect and store the v6 address from specified container on the network dualstackbridge - ip6 = inspectField(c, "third", "NetworkSettings.Networks.dualstackbridge.GlobalIPv6Address") - - // verify ipv4 connectivity to the explicit --ipv address from third to fourth - _, _, err = dockerCmdWithError("exec", "fourth", "ping", "-c", "1", strings.TrimSpace(ip)) - c.Assert(err, check.IsNil) - // verify ipv6 connectivity to the explicit --ipv6 address from third to fourth - _, _, err = dockerCmdWithError("exec", "fourth", "ping6", "-c", "1", strings.TrimSpace(ip6)) - c.Assert(err, check.IsNil) - - // Inspect the v4 gateway to ensure the proper default GW was assigned - ip4gw := inspectField(c, "first", "NetworkSettings.Networks.dualstackbridge.Gateway") - c.Assert(strings.TrimSpace(ip4gw), check.Equals, "172.28.100.1") - // Inspect the v6 gateway to ensure the proper default GW was assigned - ip6gw := inspectField(c, "first", "NetworkSettings.Networks.dualstackbridge.IPv6Gateway") - c.Assert(strings.TrimSpace(ip6gw), check.Equals, "2001:db8:abc2::1") - - // Inspect the v4 gateway to ensure the proper explicitly assigned default GW was assigned - ip4gw = inspectField(c, "third", "NetworkSettings.Networks.dualstackbridge.Gateway") - c.Assert(strings.TrimSpace(ip4gw), check.Equals, "172.28.102.254") - // Inspect the v6 gateway to ensure the proper explicitly assigned default GW was assigned - ip6gw = inspectField(c, "third", "NetworkSettings.Networks.dualstackbridge.IPv6Gateway") - c.Assert(strings.TrimSpace(ip6gw), check.Equals, "2001:db8:abc4::254") -} - -func (s *DockerNetworkSuite) TestDockerNetworkIpvlanL2MultiSubnet(c *check.C) { - // create a dual stack multi-subnet Ipvlan L2 network and validate connectivity within the subnets, two on each subnet - testRequires(c, DaemonIsLinux, IPv6, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - dockerCmd(c, "network", "create", "--driver=ipvlan", "--ipv6", "--subnet=172.28.200.0/24", "--subnet=172.28.202.0/24", "--gateway=172.28.202.254", - "--subnet=2001:db8:abc8::/64", "--subnet=2001:db8:abc6::/64", "--gateway=2001:db8:abc6::254", "dualstackl2") - // Ensure the network was created - assertNwIsAvailable(c, "dualstackl2") - // start dual stack containers and verify the user specified --ip and --ip6 addresses on subnets 172.28.200.0/24 and 2001:db8:abc8::/64 - dockerCmd(c, "run", "-d", "--net=dualstackl2", "--name=first", "--ip", "172.28.200.20", "--ip6", "2001:db8:abc8::20", "busybox", "top") - dockerCmd(c, "run", "-d", "--net=dualstackl2", "--name=second", "--ip", "172.28.200.21", "--ip6", "2001:db8:abc8::21", "busybox", "top") - - // Inspect and store the v4 address from specified container on the network dualstackl2 - ip := inspectField(c, "first", "NetworkSettings.Networks.dualstackl2.IPAddress") - // Inspect and store the v6 address from specified container on the network dualstackl2 - ip6 := inspectField(c, "first", "NetworkSettings.Networks.dualstackl2.GlobalIPv6Address") - - // verify ipv4 connectivity to the explicit --ipv address second to first - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", strings.TrimSpace(ip)) - c.Assert(err, check.IsNil) - // verify ipv6 connectivity to the explicit --ipv6 address second to first - _, _, err = dockerCmdWithError("exec", "second", "ping6", "-c", "1", strings.TrimSpace(ip6)) - c.Assert(err, check.IsNil) - - // start dual stack containers and verify the user specified --ip and --ip6 addresses on subnets 172.28.202.0/24 and 2001:db8:abc6::/64 - dockerCmd(c, "run", "-d", "--net=dualstackl2", "--name=third", "--ip", "172.28.202.20", "--ip6", "2001:db8:abc6::20", "busybox", "top") - dockerCmd(c, "run", "-d", "--net=dualstackl2", "--name=fourth", "--ip", "172.28.202.21", "--ip6", "2001:db8:abc6::21", "busybox", "top") - - // Inspect and store the v4 address from specified container on the network dualstackl2 - ip = inspectField(c, "third", "NetworkSettings.Networks.dualstackl2.IPAddress") - // Inspect and store the v6 address from specified container on the network dualstackl2 - ip6 = inspectField(c, "third", "NetworkSettings.Networks.dualstackl2.GlobalIPv6Address") - - // verify ipv4 connectivity to the explicit --ipv address from third to fourth - _, _, err = dockerCmdWithError("exec", "fourth", "ping", "-c", "1", strings.TrimSpace(ip)) - c.Assert(err, check.IsNil) - // verify ipv6 connectivity to the explicit --ipv6 address from third to fourth - _, _, err = dockerCmdWithError("exec", "fourth", "ping6", "-c", "1", strings.TrimSpace(ip6)) - c.Assert(err, check.IsNil) - - // Inspect the v4 gateway to ensure the proper default GW was assigned - ip4gw := inspectField(c, "first", "NetworkSettings.Networks.dualstackl2.Gateway") - c.Assert(strings.TrimSpace(ip4gw), check.Equals, "172.28.200.1") - // Inspect the v6 gateway to ensure the proper default GW was assigned - ip6gw := inspectField(c, "first", "NetworkSettings.Networks.dualstackl2.IPv6Gateway") - c.Assert(strings.TrimSpace(ip6gw), check.Equals, "2001:db8:abc8::1") - - // Inspect the v4 gateway to ensure the proper explicitly assigned default GW was assigned - ip4gw = inspectField(c, "third", "NetworkSettings.Networks.dualstackl2.Gateway") - c.Assert(strings.TrimSpace(ip4gw), check.Equals, "172.28.202.254") - // Inspect the v6 gateway to ensure the proper explicitly assigned default GW was assigned - ip6gw = inspectField(c, "third", "NetworkSettings.Networks.dualstackl2.IPv6Gateway") - c.Assert(strings.TrimSpace(ip6gw), check.Equals, "2001:db8:abc6::254") -} - -func (s *DockerNetworkSuite) TestDockerNetworkIpvlanL3MultiSubnet(c *check.C) { - // create a dual stack multi-subnet Ipvlan L3 network and validate connectivity between all four containers per L3 mode - testRequires(c, DaemonIsLinux, IPv6, IpvlanKernelSupport, NotUserNamespace, NotArm, IPv6, ExperimentalDaemon) - dockerCmd(c, "network", "create", "--driver=ipvlan", "--ipv6", "--subnet=172.28.10.0/24", "--subnet=172.28.12.0/24", "--gateway=172.28.12.254", - "--subnet=2001:db8:abc9::/64", "--subnet=2001:db8:abc7::/64", "--gateway=2001:db8:abc7::254", "-o", "ipvlan_mode=l3", "dualstackl3") - // Ensure the network was created - assertNwIsAvailable(c, "dualstackl3") - - // start dual stack containers and verify the user specified --ip and --ip6 addresses on subnets 172.28.10.0/24 and 2001:db8:abc9::/64 - dockerCmd(c, "run", "-d", "--net=dualstackl3", "--name=first", "--ip", "172.28.10.20", "--ip6", "2001:db8:abc9::20", "busybox", "top") - dockerCmd(c, "run", "-d", "--net=dualstackl3", "--name=second", "--ip", "172.28.10.21", "--ip6", "2001:db8:abc9::21", "busybox", "top") - - // Inspect and store the v4 address from specified container on the network dualstackl3 - ip := inspectField(c, "first", "NetworkSettings.Networks.dualstackl3.IPAddress") - // Inspect and store the v6 address from specified container on the network dualstackl3 - ip6 := inspectField(c, "first", "NetworkSettings.Networks.dualstackl3.GlobalIPv6Address") - - // verify ipv4 connectivity to the explicit --ipv address second to first - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", strings.TrimSpace(ip)) - c.Assert(err, check.IsNil) - // verify ipv6 connectivity to the explicit --ipv6 address second to first - _, _, err = dockerCmdWithError("exec", "second", "ping6", "-c", "1", strings.TrimSpace(ip6)) - c.Assert(err, check.IsNil) - - // start dual stack containers and verify the user specified --ip and --ip6 addresses on subnets 172.28.12.0/24 and 2001:db8:abc7::/64 - dockerCmd(c, "run", "-d", "--net=dualstackl3", "--name=third", "--ip", "172.28.12.20", "--ip6", "2001:db8:abc7::20", "busybox", "top") - dockerCmd(c, "run", "-d", "--net=dualstackl3", "--name=fourth", "--ip", "172.28.12.21", "--ip6", "2001:db8:abc7::21", "busybox", "top") - - // Inspect and store the v4 address from specified container on the network dualstackl3 - ip = inspectField(c, "third", "NetworkSettings.Networks.dualstackl3.IPAddress") - // Inspect and store the v6 address from specified container on the network dualstackl3 - ip6 = inspectField(c, "third", "NetworkSettings.Networks.dualstackl3.GlobalIPv6Address") - - // verify ipv4 connectivity to the explicit --ipv address from third to fourth - _, _, err = dockerCmdWithError("exec", "fourth", "ping", "-c", "1", strings.TrimSpace(ip)) - c.Assert(err, check.IsNil) - // verify ipv6 connectivity to the explicit --ipv6 address from third to fourth - _, _, err = dockerCmdWithError("exec", "fourth", "ping6", "-c", "1", strings.TrimSpace(ip6)) - c.Assert(err, check.IsNil) - - // Inspect and store the v4 address from specified container on the network dualstackl3 - ip = inspectField(c, "second", "NetworkSettings.Networks.dualstackl3.IPAddress") - // Inspect and store the v6 address from specified container on the network dualstackl3 - ip6 = inspectField(c, "second", "NetworkSettings.Networks.dualstackl3.GlobalIPv6Address") - - // Verify connectivity across disparate subnets which is unique to L3 mode only - _, _, err = dockerCmdWithError("exec", "third", "ping", "-c", "1", strings.TrimSpace(ip)) - c.Assert(err, check.IsNil) - _, _, err = dockerCmdWithError("exec", "third", "ping6", "-c", "1", strings.TrimSpace(ip6)) - c.Assert(err, check.IsNil) - - // Inspect the v4 gateway to ensure no next hop is assigned in L3 mode - ip4gw := inspectField(c, "first", "NetworkSettings.Networks.dualstackl3.Gateway") - c.Assert(strings.TrimSpace(ip4gw), check.Equals, "") - // Inspect the v6 gateway to ensure the explicitly specified default GW is ignored per L3 mode enabled - ip6gw := inspectField(c, "third", "NetworkSettings.Networks.dualstackl3.IPv6Gateway") - c.Assert(strings.TrimSpace(ip6gw), check.Equals, "") -} - -func (s *DockerNetworkSuite) TestDockerNetworkIpvlanAddressing(c *check.C) { - // Ensure the default gateways, next-hops and default dev devices are properly set - testRequires(c, DaemonIsLinux, IPv6, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - dockerCmd(c, "network", "create", "--driver=macvlan", "--ipv6", "--subnet=172.28.130.0/24", - "--subnet=2001:db8:abca::/64", "--gateway=2001:db8:abca::254", "-o", "macvlan_mode=bridge", "dualstackbridge") - assertNwIsAvailable(c, "dualstackbridge") - dockerCmd(c, "run", "-d", "--net=dualstackbridge", "--name=first", "busybox", "top") - // Validate macvlan bridge mode defaults gateway sets the default IPAM next-hop inferred from the subnet - out, _, err := dockerCmdWithError("exec", "first", "ip", "route") - c.Assert(err, check.IsNil) - c.Assert(out, checker.Contains, "default via 172.28.130.1 dev eth0") - // Validate macvlan bridge mode sets the v6 gateway to the user specified default gateway/next-hop - out, _, err = dockerCmdWithError("exec", "first", "ip", "-6", "route") - c.Assert(err, check.IsNil) - c.Assert(out, checker.Contains, "default via 2001:db8:abca::254 dev eth0") - - // Verify ipvlan l2 mode sets the proper default gateway routes via netlink - // for either an explicitly set route by the user or inferred via default IPAM - dockerCmd(c, "network", "create", "--driver=ipvlan", "--ipv6", "--subnet=172.28.140.0/24", "--gateway=172.28.140.254", - "--subnet=2001:db8:abcb::/64", "-o", "ipvlan_mode=l2", "dualstackl2") - assertNwIsAvailable(c, "dualstackl2") - dockerCmd(c, "run", "-d", "--net=dualstackl2", "--name=second", "busybox", "top") - // Validate ipvlan l2 mode defaults gateway sets the default IPAM next-hop inferred from the subnet - out, _, err = dockerCmdWithError("exec", "second", "ip", "route") - c.Assert(err, check.IsNil) - c.Assert(out, checker.Contains, "default via 172.28.140.254 dev eth0") - // Validate ipvlan l2 mode sets the v6 gateway to the user specified default gateway/next-hop - out, _, err = dockerCmdWithError("exec", "second", "ip", "-6", "route") - c.Assert(err, check.IsNil) - c.Assert(out, checker.Contains, "default via 2001:db8:abcb::1 dev eth0") - - // Validate ipvlan l3 mode sets the v4 gateway to dev eth0 and disregards any explicit or inferred next-hops - dockerCmd(c, "network", "create", "--driver=ipvlan", "--ipv6", "--subnet=172.28.160.0/24", "--gateway=172.28.160.254", - "--subnet=2001:db8:abcd::/64", "--gateway=2001:db8:abcd::254", "-o", "ipvlan_mode=l3", "dualstackl3") - assertNwIsAvailable(c, "dualstackl3") - dockerCmd(c, "run", "-d", "--net=dualstackl3", "--name=third", "busybox", "top") - // Validate ipvlan l3 mode sets the v4 gateway to dev eth0 and disregards any explicit or inferred next-hops - out, _, err = dockerCmdWithError("exec", "third", "ip", "route") - c.Assert(err, check.IsNil) - c.Assert(out, checker.Contains, "default dev eth0") - // Validate ipvlan l3 mode sets the v6 gateway to dev eth0 and disregards any explicit or inferred next-hops - out, _, err = dockerCmdWithError("exec", "third", "ip", "-6", "route") - c.Assert(err, check.IsNil) - c.Assert(out, checker.Contains, "default dev eth0") -} - -func (s *DockerSuite) TestDockerNetworkMacVlanBridgeNilParent(c *check.C) { - // macvlan bridge mode - dummy parent interface is provisioned dynamically - testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - dockerCmd(c, "network", "create", "--driver=macvlan", "dm-nil-parent") - assertNwIsAvailable(c, "dm-nil-parent") - - // start two containers on the same subnet - dockerCmd(c, "run", "-d", "--net=dm-nil-parent", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--net=dm-nil-parent", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // intra-network communications should succeed - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestDockerNetworkMacVlanBridgeInternalMode(c *check.C) { - // macvlan bridge mode --internal containers can communicate inside the network but not externally - testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - dockerCmd(c, "network", "create", "--driver=macvlan", "--internal", "dm-internal") - assertNwIsAvailable(c, "dm-internal") - nr := getNetworkResource(c, "dm-internal") - c.Assert(nr.Internal, checker.True) - - // start two containers on the same subnet - dockerCmd(c, "run", "-d", "--net=dm-internal", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--net=dm-internal", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // access outside of the network should fail - result := dockerCmdWithTimeout(time.Second, "exec", "first", "ping", "-c", "1", "-w", "1", "8.8.8.8") - c.Assert(result, icmd.Matches, icmd.Expected{Timeout: true}) - - // intra-network communications should succeed - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestDockerNetworkIpvlanL2NilParent(c *check.C) { - // ipvlan l2 mode - dummy parent interface is provisioned dynamically - testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - dockerCmd(c, "network", "create", "--driver=ipvlan", "di-nil-parent") - assertNwIsAvailable(c, "di-nil-parent") - - // start two containers on the same subnet - dockerCmd(c, "run", "-d", "--net=di-nil-parent", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--net=di-nil-parent", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // intra-network communications should succeed - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestDockerNetworkIpvlanL2InternalMode(c *check.C) { - // ipvlan l2 mode --internal containers can communicate inside the network but not externally - testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - dockerCmd(c, "network", "create", "--driver=ipvlan", "--internal", "di-internal") - assertNwIsAvailable(c, "di-internal") - nr := getNetworkResource(c, "di-internal") - c.Assert(nr.Internal, checker.True) - - // start two containers on the same subnet - dockerCmd(c, "run", "-d", "--net=di-internal", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--net=di-internal", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // access outside of the network should fail - result := dockerCmdWithTimeout(time.Second, "exec", "first", "ping", "-c", "1", "-w", "1", "8.8.8.8") - c.Assert(result, icmd.Matches, icmd.Expected{Timeout: true}) - // intra-network communications should succeed - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestDockerNetworkIpvlanL3NilParent(c *check.C) { - // ipvlan l3 mode - dummy parent interface is provisioned dynamically - testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - dockerCmd(c, "network", "create", "--driver=ipvlan", "--subnet=172.28.230.0/24", - "--subnet=172.28.220.0/24", "-o", "ipvlan_mode=l3", "di-nil-parent-l3") - assertNwIsAvailable(c, "di-nil-parent-l3") - - // start two containers on separate subnets - dockerCmd(c, "run", "-d", "--ip=172.28.220.10", "--net=di-nil-parent-l3", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--ip=172.28.230.10", "--net=di-nil-parent-l3", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // intra-network communications should succeed - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestDockerNetworkIpvlanL3InternalMode(c *check.C) { - // ipvlan l3 mode --internal containers can communicate inside the network but not externally - testRequires(c, DaemonIsLinux, IpvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - dockerCmd(c, "network", "create", "--driver=ipvlan", "--subnet=172.28.230.0/24", - "--subnet=172.28.220.0/24", "-o", "ipvlan_mode=l3", "--internal", "di-internal-l3") - assertNwIsAvailable(c, "di-internal-l3") - nr := getNetworkResource(c, "di-internal-l3") - c.Assert(nr.Internal, checker.True) - - // start two containers on separate subnets - dockerCmd(c, "run", "-d", "--ip=172.28.220.10", "--net=di-internal-l3", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--ip=172.28.230.10", "--net=di-internal-l3", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - - // access outside of the network should fail - result := dockerCmdWithTimeout(time.Second, "exec", "first", "ping", "-c", "1", "-w", "1", "8.8.8.8") - c.Assert(result, icmd.Matches, icmd.Expected{Timeout: true}) - // intra-network communications should succeed - _, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) -} - -func (s *DockerSuite) TestDockerNetworkMacVlanExistingParent(c *check.C) { - // macvlan bridge mode - empty parent interface containers can reach each other internally but not externally - testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - netName := "dm-parent-exists" - out, err := createMasterDummy(c, "dm-dummy0") - //out, err := createVlanInterface(c, "dm-parent", "dm-slave", "macvlan", "bridge") - c.Assert(err, check.IsNil, check.Commentf(out)) - // create a network using an existing parent interface - dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0", netName) - assertNwIsAvailable(c, netName) - // delete the network while preserving the parent link - dockerCmd(c, "network", "rm", netName) - assertNwNotAvailable(c, netName) - // verify the network delete did not delete the predefined link - out, err = linkExists(c, "dm-dummy0") - c.Assert(err, check.IsNil, check.Commentf(out)) - deleteInterface(c, "dm-dummy0") - c.Assert(err, check.IsNil, check.Commentf(out)) -} - -func (s *DockerSuite) TestDockerNetworkMacVlanSubinterface(c *check.C) { - // macvlan bridge mode - empty parent interface containers can reach each other internally but not externally - testRequires(c, DaemonIsLinux, MacvlanKernelSupport, NotUserNamespace, NotArm, ExperimentalDaemon) - netName := "dm-subinterface" - out, err := createMasterDummy(c, "dm-dummy0") - c.Assert(err, check.IsNil, check.Commentf(out)) - out, err = createVlanInterface(c, "dm-dummy0", "dm-dummy0.20", "20") - c.Assert(err, check.IsNil, check.Commentf(out)) - // create a network using an existing parent interface - dockerCmd(c, "network", "create", "--driver=macvlan", "-o", "parent=dm-dummy0.20", netName) - assertNwIsAvailable(c, netName) - - // start containers on 802.1q tagged '-o parent' sub-interface - dockerCmd(c, "run", "-d", "--net=dm-subinterface", "--name=first", "busybox", "top") - c.Assert(waitRun("first"), check.IsNil) - dockerCmd(c, "run", "-d", "--net=dm-subinterface", "--name=second", "busybox", "top") - c.Assert(waitRun("second"), check.IsNil) - // verify containers can communicate - _, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first") - c.Assert(err, check.IsNil) - - // remove the containers - dockerCmd(c, "rm", "-f", "first") - dockerCmd(c, "rm", "-f", "second") - // delete the network while preserving the parent link - dockerCmd(c, "network", "rm", netName) - assertNwNotAvailable(c, netName) - // verify the network delete did not delete the predefined sub-interface - out, err = linkExists(c, "dm-dummy0.20") - c.Assert(err, check.IsNil, check.Commentf(out)) - // delete the parent interface which also collects the slave - deleteInterface(c, "dm-dummy0") - c.Assert(err, check.IsNil, check.Commentf(out)) -} - -func createMasterDummy(c *check.C, master string) (string, error) { - // ip link add type dummy - args := []string{"link", "add", master, "type", "dummy"} - ipLinkCmd := exec.Command("ip", args...) - out, _, err := runCommandWithOutput(ipLinkCmd) - if err != nil { - return out, err - } - // ip link set dummy_name up - args = []string{"link", "set", master, "up"} - ipLinkCmd = exec.Command("ip", args...) - out, _, err = runCommandWithOutput(ipLinkCmd) - if err != nil { - return out, err - } - return out, err -} - -func createVlanInterface(c *check.C, master, slave, id string) (string, error) { - // ip link add link name . type vlan id - args := []string{"link", "add", "link", master, "name", slave, "type", "vlan", "id", id} - ipLinkCmd := exec.Command("ip", args...) - out, _, err := runCommandWithOutput(ipLinkCmd) - if err != nil { - return out, err - } - // ip link set up - args = []string{"link", "set", slave, "up"} - ipLinkCmd = exec.Command("ip", args...) - out, _, err = runCommandWithOutput(ipLinkCmd) - if err != nil { - return out, err - } - return out, err -} - -func linkExists(c *check.C, master string) (string, error) { - // verify the specified link exists, ip link show - args := []string{"link", "show", master} - ipLinkCmd := exec.Command("ip", args...) - out, _, err := runCommandWithOutput(ipLinkCmd) - if err != nil { - return out, err - } - return out, err -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_hub_pull_suite_test.go b/vendor/github.com/docker/docker/integration-cli/docker_hub_pull_suite_test.go deleted file mode 100644 index df52cae..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_hub_pull_suite_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package main - -import ( - "os/exec" - "runtime" - "strings" - - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -func init() { - // FIXME. Temporarily turning this off for Windows as GH16039 was breaking - // Windows to Linux CI @icecrime - if runtime.GOOS != "windows" { - check.Suite(newDockerHubPullSuite()) - } -} - -// DockerHubPullSuite provides an isolated daemon that doesn't have all the -// images that are baked into our 'global' test environment daemon (e.g., -// busybox, httpserver, ...). -// -// We use it for push/pull tests where we want to start fresh, and measure the -// relative impact of each individual operation. As part of this suite, all -// images are removed after each test. -type DockerHubPullSuite struct { - d *Daemon - ds *DockerSuite -} - -// newDockerHubPullSuite returns a new instance of a DockerHubPullSuite. -func newDockerHubPullSuite() *DockerHubPullSuite { - return &DockerHubPullSuite{ - ds: &DockerSuite{}, - } -} - -// SetUpSuite starts the suite daemon. -func (s *DockerHubPullSuite) SetUpSuite(c *check.C) { - testRequires(c, DaemonIsLinux) - s.d = NewDaemon(c) - err := s.d.Start() - c.Assert(err, checker.IsNil, check.Commentf("starting push/pull test daemon: %v", err)) -} - -// TearDownSuite stops the suite daemon. -func (s *DockerHubPullSuite) TearDownSuite(c *check.C) { - if s.d != nil { - err := s.d.Stop() - c.Assert(err, checker.IsNil, check.Commentf("stopping push/pull test daemon: %v", err)) - } -} - -// SetUpTest declares that all tests of this suite require network. -func (s *DockerHubPullSuite) SetUpTest(c *check.C) { - testRequires(c, Network) -} - -// TearDownTest removes all images from the suite daemon. -func (s *DockerHubPullSuite) TearDownTest(c *check.C) { - out := s.Cmd(c, "images", "-aq") - images := strings.Split(out, "\n") - images = append([]string{"rmi", "-f"}, images...) - s.d.Cmd(images...) - s.ds.TearDownTest(c) -} - -// Cmd executes a command against the suite daemon and returns the combined -// output. The function fails the test when the command returns an error. -func (s *DockerHubPullSuite) Cmd(c *check.C, name string, arg ...string) string { - out, err := s.CmdWithError(name, arg...) - c.Assert(err, checker.IsNil, check.Commentf("%q failed with errors: %s, %v", strings.Join(arg, " "), out, err)) - return out -} - -// CmdWithError executes a command against the suite daemon and returns the -// combined output as well as any error. -func (s *DockerHubPullSuite) CmdWithError(name string, arg ...string) (string, error) { - c := s.MakeCmd(name, arg...) - b, err := c.CombinedOutput() - return string(b), err -} - -// MakeCmd returns an exec.Cmd command to run against the suite daemon. -func (s *DockerHubPullSuite) MakeCmd(name string, arg ...string) *exec.Cmd { - args := []string{"--host", s.d.sock(), name} - args = append(args, arg...) - return exec.Command(dockerBinary, args...) -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_test_vars.go b/vendor/github.com/docker/docker/integration-cli/docker_test_vars.go deleted file mode 100644 index 3559bfd..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_test_vars.go +++ /dev/null @@ -1,165 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strconv" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/reexec" -) - -var ( - // the docker client binary to use - dockerBinary = "docker" - // the docker daemon binary to use - dockerdBinary = "dockerd" - - // path to containerd's ctr binary - ctrBinary = "docker-containerd-ctr" - - // the private registry image to use for tests involving the registry - registryImageName = "registry" - - // the private registry to use for tests - privateRegistryURL = "127.0.0.1:5000" - - // TODO Windows CI. These are incorrect and need fixing into - // platform specific pieces. - runtimePath = "/var/run/docker" - - workingDirectory string - - // isLocalDaemon is true if the daemon under test is on the same - // host as the CLI. - isLocalDaemon bool - - // daemonPlatform is held globally so that tests can make intelligent - // decisions on how to configure themselves according to the platform - // of the daemon. This is initialized in docker_utils by sending - // a version call to the daemon and examining the response header. - daemonPlatform string - - // windowsDaemonKV is used on Windows to distinguish between different - // versions. This is necessary to enable certain tests based on whether - // the platform supports it. For example, Windows Server 2016 TP3 did - // not support volumes, but TP4 did. - windowsDaemonKV int - - // daemonDefaultImage is the name of the default image to use when running - // tests. This is platform dependent. - daemonDefaultImage string - - // For a local daemon on Linux, these values will be used for testing - // user namespace support as the standard graph path(s) will be - // appended with the root remapped uid.gid prefix - dockerBasePath string - volumesConfigPath string - containerStoragePath string - - // experimentalDaemon tell whether the main daemon has - // experimental features enabled or not - experimentalDaemon bool - - // daemonStorageDriver is held globally so that tests can know the storage - // driver of the daemon. This is initialized in docker_utils by sending - // a version call to the daemon and examining the response header. - daemonStorageDriver string - - // WindowsBaseImage is the name of the base image for Windows testing - // Environment variable WINDOWS_BASE_IMAGE can override this - WindowsBaseImage = "microsoft/windowsservercore" - - // isolation is the isolation mode of the daemon under test - isolation container.Isolation - - // daemonPid is the pid of the main test daemon - daemonPid int - - daemonKernelVersion string -) - -const ( - // DefaultImage is the name of the base image for the majority of tests that - // are run across suites - DefaultImage = "busybox" -) - -func init() { - reexec.Init() - if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" { - dockerBinary = dockerBin - } - var err error - dockerBinary, err = exec.LookPath(dockerBinary) - if err != nil { - fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)\n", err) - os.Exit(1) - } - if registryImage := os.Getenv("REGISTRY_IMAGE"); registryImage != "" { - registryImageName = registryImage - } - if registry := os.Getenv("REGISTRY_URL"); registry != "" { - privateRegistryURL = registry - } - workingDirectory, _ = os.Getwd() - - // Deterministically working out the environment in which CI is running - // to evaluate whether the daemon is local or remote is not possible through - // a build tag. - // - // For example Windows to Linux CI under Jenkins tests the 64-bit - // Windows binary build with the daemon build tag, but calls a remote - // Linux daemon. - // - // We can't just say if Windows then assume the daemon is local as at - // some point, we will be testing the Windows CLI against a Windows daemon. - // - // Similarly, it will be perfectly valid to also run CLI tests from - // a Linux CLI (built with the daemon tag) against a Windows daemon. - if len(os.Getenv("DOCKER_REMOTE_DAEMON")) > 0 { - isLocalDaemon = false - } else { - isLocalDaemon = true - } - - // TODO Windows CI. This are incorrect and need fixing into - // platform specific pieces. - // This is only used for a tests with local daemon true (Linux-only today) - // default is "/var/lib/docker", but we'll try and ask the - // /info endpoint for the specific root dir - dockerBasePath = "/var/lib/docker" - type Info struct { - DockerRootDir string - ExperimentalBuild bool - KernelVersion string - } - var i Info - status, b, err := sockRequest("GET", "/info", nil) - if err == nil && status == 200 { - if err = json.Unmarshal(b, &i); err == nil { - dockerBasePath = i.DockerRootDir - experimentalDaemon = i.ExperimentalBuild - daemonKernelVersion = i.KernelVersion - } - } - volumesConfigPath = dockerBasePath + "/volumes" - containerStoragePath = dockerBasePath + "/containers" - - if len(os.Getenv("WINDOWS_BASE_IMAGE")) > 0 { - WindowsBaseImage = os.Getenv("WINDOWS_BASE_IMAGE") - fmt.Println("INFO: Windows Base image is ", WindowsBaseImage) - } - - dest := os.Getenv("DEST") - b, err = ioutil.ReadFile(filepath.Join(dest, "docker.pid")) - if err == nil { - if p, err := strconv.ParseInt(string(b), 10, 32); err == nil { - daemonPid = int(p) - } - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/docker_utils.go b/vendor/github.com/docker/docker/integration-cli/docker_utils.go deleted file mode 100644 index 749e4b3..0000000 --- a/vendor/github.com/docker/docker/integration-cli/docker_utils.go +++ /dev/null @@ -1,1607 +0,0 @@ -package main - -import ( - "bufio" - "bytes" - "crypto/tls" - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "net/http/httptest" - "net/http/httputil" - "net/url" - "os" - "os/exec" - "path" - "path/filepath" - "strconv" - "strings" - "time" - - "github.com/docker/docker/api/types" - volumetypes "github.com/docker/docker/api/types/volume" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/httputils" - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/stringutils" - "github.com/docker/go-connections/tlsconfig" - units "github.com/docker/go-units" - "github.com/go-check/check" -) - -func init() { - cmd := exec.Command(dockerBinary, "images", "-f", "dangling=false", "--format", "{{.Repository}}:{{.Tag}}") - cmd.Env = appendBaseEnv(true) - out, err := cmd.CombinedOutput() - if err != nil { - panic(fmt.Errorf("err=%v\nout=%s\n", err, out)) - } - images := strings.Split(strings.TrimSpace(string(out)), "\n") - for _, img := range images { - protectedImages[img] = struct{}{} - } - - res, body, err := sockRequestRaw("GET", "/info", nil, "application/json") - if err != nil { - panic(fmt.Errorf("Init failed to get /info: %v", err)) - } - defer body.Close() - if res.StatusCode != http.StatusOK { - panic(fmt.Errorf("Init failed to get /info. Res=%v", res)) - } - - svrHeader, _ := httputils.ParseServerHeader(res.Header.Get("Server")) - daemonPlatform = svrHeader.OS - if daemonPlatform != "linux" && daemonPlatform != "windows" { - panic("Cannot run tests against platform: " + daemonPlatform) - } - - // Now we know the daemon platform, can set paths used by tests. - var info types.Info - err = json.NewDecoder(body).Decode(&info) - if err != nil { - panic(fmt.Errorf("Init failed to unmarshal docker info: %v", err)) - } - - daemonStorageDriver = info.Driver - dockerBasePath = info.DockerRootDir - volumesConfigPath = filepath.Join(dockerBasePath, "volumes") - containerStoragePath = filepath.Join(dockerBasePath, "containers") - // Make sure in context of daemon, not the local platform. Note we can't - // use filepath.FromSlash or ToSlash here as they are a no-op on Unix. - if daemonPlatform == "windows" { - volumesConfigPath = strings.Replace(volumesConfigPath, `/`, `\`, -1) - containerStoragePath = strings.Replace(containerStoragePath, `/`, `\`, -1) - // On Windows, extract out the version as we need to make selective - // decisions during integration testing as and when features are implemented. - // eg in "10.0 10550 (10550.1000.amd64fre.branch.date-time)" we want 10550 - windowsDaemonKV, _ = strconv.Atoi(strings.Split(info.KernelVersion, " ")[1]) - } else { - volumesConfigPath = strings.Replace(volumesConfigPath, `\`, `/`, -1) - containerStoragePath = strings.Replace(containerStoragePath, `\`, `/`, -1) - } - isolation = info.Isolation -} - -func convertBasesize(basesizeBytes int64) (int64, error) { - basesize := units.HumanSize(float64(basesizeBytes)) - basesize = strings.Trim(basesize, " ")[:len(basesize)-3] - basesizeFloat, err := strconv.ParseFloat(strings.Trim(basesize, " "), 64) - if err != nil { - return 0, err - } - return int64(basesizeFloat) * 1024 * 1024 * 1024, nil -} - -func daemonHost() string { - daemonURLStr := "unix://" + opts.DefaultUnixSocket - if daemonHostVar := os.Getenv("DOCKER_HOST"); daemonHostVar != "" { - daemonURLStr = daemonHostVar - } - return daemonURLStr -} - -func getTLSConfig() (*tls.Config, error) { - dockerCertPath := os.Getenv("DOCKER_CERT_PATH") - - if dockerCertPath == "" { - return nil, fmt.Errorf("DOCKER_TLS_VERIFY specified, but no DOCKER_CERT_PATH environment variable") - } - - option := &tlsconfig.Options{ - CAFile: filepath.Join(dockerCertPath, "ca.pem"), - CertFile: filepath.Join(dockerCertPath, "cert.pem"), - KeyFile: filepath.Join(dockerCertPath, "key.pem"), - } - tlsConfig, err := tlsconfig.Client(*option) - if err != nil { - return nil, err - } - - return tlsConfig, nil -} - -func sockConn(timeout time.Duration, daemon string) (net.Conn, error) { - if daemon == "" { - daemon = daemonHost() - } - daemonURL, err := url.Parse(daemon) - if err != nil { - return nil, fmt.Errorf("could not parse url %q: %v", daemon, err) - } - - var c net.Conn - switch daemonURL.Scheme { - case "npipe": - return npipeDial(daemonURL.Path, timeout) - case "unix": - return net.DialTimeout(daemonURL.Scheme, daemonURL.Path, timeout) - case "tcp": - if os.Getenv("DOCKER_TLS_VERIFY") != "" { - // Setup the socket TLS configuration. - tlsConfig, err := getTLSConfig() - if err != nil { - return nil, err - } - dialer := &net.Dialer{Timeout: timeout} - return tls.DialWithDialer(dialer, daemonURL.Scheme, daemonURL.Host, tlsConfig) - } - return net.DialTimeout(daemonURL.Scheme, daemonURL.Host, timeout) - default: - return c, fmt.Errorf("unknown scheme %v (%s)", daemonURL.Scheme, daemon) - } -} - -func sockRequest(method, endpoint string, data interface{}) (int, []byte, error) { - jsonData := bytes.NewBuffer(nil) - if err := json.NewEncoder(jsonData).Encode(data); err != nil { - return -1, nil, err - } - - res, body, err := sockRequestRaw(method, endpoint, jsonData, "application/json") - if err != nil { - return -1, nil, err - } - b, err := readBody(body) - return res.StatusCode, b, err -} - -func sockRequestRaw(method, endpoint string, data io.Reader, ct string) (*http.Response, io.ReadCloser, error) { - return sockRequestRawToDaemon(method, endpoint, data, ct, "") -} - -func sockRequestRawToDaemon(method, endpoint string, data io.Reader, ct, daemon string) (*http.Response, io.ReadCloser, error) { - req, client, err := newRequestClient(method, endpoint, data, ct, daemon) - if err != nil { - return nil, nil, err - } - - resp, err := client.Do(req) - if err != nil { - client.Close() - return nil, nil, err - } - body := ioutils.NewReadCloserWrapper(resp.Body, func() error { - defer resp.Body.Close() - return client.Close() - }) - - return resp, body, nil -} - -func sockRequestHijack(method, endpoint string, data io.Reader, ct string) (net.Conn, *bufio.Reader, error) { - req, client, err := newRequestClient(method, endpoint, data, ct, "") - if err != nil { - return nil, nil, err - } - - client.Do(req) - conn, br := client.Hijack() - return conn, br, nil -} - -func newRequestClient(method, endpoint string, data io.Reader, ct, daemon string) (*http.Request, *httputil.ClientConn, error) { - c, err := sockConn(time.Duration(10*time.Second), daemon) - if err != nil { - return nil, nil, fmt.Errorf("could not dial docker daemon: %v", err) - } - - client := httputil.NewClientConn(c, nil) - - req, err := http.NewRequest(method, endpoint, data) - if err != nil { - client.Close() - return nil, nil, fmt.Errorf("could not create new request: %v", err) - } - - if ct != "" { - req.Header.Set("Content-Type", ct) - } - return req, client, nil -} - -func readBody(b io.ReadCloser) ([]byte, error) { - defer b.Close() - return ioutil.ReadAll(b) -} - -func deleteContainer(container ...string) error { - result := icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, container...)...) - return result.Compare(icmd.Success) -} - -func getAllContainers() (string, error) { - getContainersCmd := exec.Command(dockerBinary, "ps", "-q", "-a") - out, exitCode, err := runCommandWithOutput(getContainersCmd) - if exitCode != 0 && err == nil { - err = fmt.Errorf("failed to get a list of containers: %v\n", out) - } - - return out, err -} - -func deleteAllContainers() error { - containers, err := getAllContainers() - if err != nil { - fmt.Println(containers) - return err - } - if containers == "" { - return nil - } - - err = deleteContainer(strings.Split(strings.TrimSpace(containers), "\n")...) - if err != nil { - fmt.Println(err.Error()) - } - return err -} - -func deleteAllNetworks() error { - networks, err := getAllNetworks() - if err != nil { - return err - } - var errors []string - for _, n := range networks { - if n.Name == "bridge" || n.Name == "none" || n.Name == "host" { - continue - } - if daemonPlatform == "windows" && strings.ToLower(n.Name) == "nat" { - // nat is a pre-defined network on Windows and cannot be removed - continue - } - status, b, err := sockRequest("DELETE", "/networks/"+n.Name, nil) - if err != nil { - errors = append(errors, err.Error()) - continue - } - if status != http.StatusNoContent { - errors = append(errors, fmt.Sprintf("error deleting network %s: %s", n.Name, string(b))) - } - } - if len(errors) > 0 { - return fmt.Errorf(strings.Join(errors, "\n")) - } - return nil -} - -func getAllNetworks() ([]types.NetworkResource, error) { - var networks []types.NetworkResource - _, b, err := sockRequest("GET", "/networks", nil) - if err != nil { - return nil, err - } - if err := json.Unmarshal(b, &networks); err != nil { - return nil, err - } - return networks, nil -} - -func deleteAllPlugins() error { - plugins, err := getAllPlugins() - if err != nil { - return err - } - var errors []string - for _, p := range plugins { - status, b, err := sockRequest("DELETE", "/plugins/"+p.Name+"?force=1", nil) - if err != nil { - errors = append(errors, err.Error()) - continue - } - if status != http.StatusNoContent { - errors = append(errors, fmt.Sprintf("error deleting plugin %s: %s", p.Name, string(b))) - } - } - if len(errors) > 0 { - return fmt.Errorf(strings.Join(errors, "\n")) - } - return nil -} - -func getAllPlugins() (types.PluginsListResponse, error) { - var plugins types.PluginsListResponse - _, b, err := sockRequest("GET", "/plugins", nil) - if err != nil { - return nil, err - } - if err := json.Unmarshal(b, &plugins); err != nil { - return nil, err - } - return plugins, nil -} - -func deleteAllVolumes() error { - volumes, err := getAllVolumes() - if err != nil { - return err - } - var errors []string - for _, v := range volumes { - status, b, err := sockRequest("DELETE", "/volumes/"+v.Name, nil) - if err != nil { - errors = append(errors, err.Error()) - continue - } - if status != http.StatusNoContent { - errors = append(errors, fmt.Sprintf("error deleting volume %s: %s", v.Name, string(b))) - } - } - if len(errors) > 0 { - return fmt.Errorf(strings.Join(errors, "\n")) - } - return nil -} - -func getAllVolumes() ([]*types.Volume, error) { - var volumes volumetypes.VolumesListOKBody - _, b, err := sockRequest("GET", "/volumes", nil) - if err != nil { - return nil, err - } - if err := json.Unmarshal(b, &volumes); err != nil { - return nil, err - } - return volumes.Volumes, nil -} - -var protectedImages = map[string]struct{}{} - -func deleteAllImages() error { - cmd := exec.Command(dockerBinary, "images") - cmd.Env = appendBaseEnv(true) - out, err := cmd.CombinedOutput() - if err != nil { - return err - } - lines := strings.Split(string(out), "\n")[1:] - var imgs []string - for _, l := range lines { - if l == "" { - continue - } - fields := strings.Fields(l) - imgTag := fields[0] + ":" + fields[1] - if _, ok := protectedImages[imgTag]; !ok { - if fields[0] == "" { - imgs = append(imgs, fields[2]) - continue - } - imgs = append(imgs, imgTag) - } - } - if len(imgs) == 0 { - return nil - } - args := append([]string{"rmi", "-f"}, imgs...) - if err := exec.Command(dockerBinary, args...).Run(); err != nil { - return err - } - return nil -} - -func getPausedContainers() (string, error) { - getPausedContainersCmd := exec.Command(dockerBinary, "ps", "-f", "status=paused", "-q", "-a") - out, exitCode, err := runCommandWithOutput(getPausedContainersCmd) - if exitCode != 0 && err == nil { - err = fmt.Errorf("failed to get a list of paused containers: %v\n", out) - } - - return out, err -} - -func getSliceOfPausedContainers() ([]string, error) { - out, err := getPausedContainers() - if err == nil { - if len(out) == 0 { - return nil, err - } - slice := strings.Split(strings.TrimSpace(out), "\n") - return slice, err - } - return []string{out}, err -} - -func unpauseContainer(container string) error { - return icmd.RunCommand(dockerBinary, "unpause", container).Error -} - -func unpauseAllContainers() error { - containers, err := getPausedContainers() - if err != nil { - fmt.Println(containers) - return err - } - - containers = strings.Replace(containers, "\n", " ", -1) - containers = strings.Trim(containers, " ") - containerList := strings.Split(containers, " ") - - for _, value := range containerList { - if err = unpauseContainer(value); err != nil { - return err - } - } - - return nil -} - -func deleteImages(images ...string) error { - args := []string{dockerBinary, "rmi", "-f"} - return icmd.RunCmd(icmd.Cmd{Command: append(args, images...)}).Error -} - -func imageExists(image string) error { - return icmd.RunCommand(dockerBinary, "inspect", image).Error -} - -func pullImageIfNotExist(image string) error { - if err := imageExists(image); err != nil { - pullCmd := exec.Command(dockerBinary, "pull", image) - _, exitCode, err := runCommandWithOutput(pullCmd) - - if err != nil || exitCode != 0 { - return fmt.Errorf("image %q wasn't found locally and it couldn't be pulled: %s", image, err) - } - } - return nil -} - -func dockerCmdWithError(args ...string) (string, int, error) { - if err := validateArgs(args...); err != nil { - return "", 0, err - } - result := icmd.RunCommand(dockerBinary, args...) - if result.Error != nil { - return result.Combined(), result.ExitCode, result.Compare(icmd.Success) - } - return result.Combined(), result.ExitCode, result.Error -} - -func dockerCmdWithStdoutStderr(c *check.C, args ...string) (string, string, int) { - if err := validateArgs(args...); err != nil { - c.Fatalf(err.Error()) - } - - result := icmd.RunCommand(dockerBinary, args...) - // TODO: why is c ever nil? - if c != nil { - c.Assert(result, icmd.Matches, icmd.Success) - } - return result.Stdout(), result.Stderr(), result.ExitCode -} - -func dockerCmd(c *check.C, args ...string) (string, int) { - if err := validateArgs(args...); err != nil { - c.Fatalf(err.Error()) - } - result := icmd.RunCommand(dockerBinary, args...) - c.Assert(result, icmd.Matches, icmd.Success) - return result.Combined(), result.ExitCode -} - -func dockerCmdWithResult(args ...string) *icmd.Result { - return icmd.RunCommand(dockerBinary, args...) -} - -func binaryWithArgs(args ...string) []string { - return append([]string{dockerBinary}, args...) -} - -// execute a docker command with a timeout -func dockerCmdWithTimeout(timeout time.Duration, args ...string) *icmd.Result { - if err := validateArgs(args...); err != nil { - return &icmd.Result{Error: err} - } - return icmd.RunCmd(icmd.Cmd{Command: binaryWithArgs(args...), Timeout: timeout}) -} - -// execute a docker command in a directory -func dockerCmdInDir(c *check.C, path string, args ...string) (string, int, error) { - if err := validateArgs(args...); err != nil { - c.Fatalf(err.Error()) - } - result := icmd.RunCmd(icmd.Cmd{Command: binaryWithArgs(args...), Dir: path}) - return result.Combined(), result.ExitCode, result.Error -} - -// execute a docker command in a directory with a timeout -func dockerCmdInDirWithTimeout(timeout time.Duration, path string, args ...string) *icmd.Result { - if err := validateArgs(args...); err != nil { - return &icmd.Result{Error: err} - } - return icmd.RunCmd(icmd.Cmd{ - Command: binaryWithArgs(args...), - Timeout: timeout, - Dir: path, - }) -} - -// validateArgs is a checker to ensure tests are not running commands which are -// not supported on platforms. Specifically on Windows this is 'busybox top'. -func validateArgs(args ...string) error { - if daemonPlatform != "windows" { - return nil - } - foundBusybox := -1 - for key, value := range args { - if strings.ToLower(value) == "busybox" { - foundBusybox = key - } - if (foundBusybox != -1) && (key == foundBusybox+1) && (strings.ToLower(value) == "top") { - return errors.New("cannot use 'busybox top' in tests on Windows. Use runSleepingContainer()") - } - } - return nil -} - -// find the State.ExitCode in container metadata -func findContainerExitCode(c *check.C, name string, vargs ...string) string { - args := append(vargs, "inspect", "--format='{{ .State.ExitCode }} {{ .State.Error }}'", name) - cmd := exec.Command(dockerBinary, args...) - out, _, err := runCommandWithOutput(cmd) - if err != nil { - c.Fatal(err, out) - } - return out -} - -func findContainerIP(c *check.C, id string, network string) string { - out, _ := dockerCmd(c, "inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.%s.IPAddress }}'", network), id) - return strings.Trim(out, " \r\n'") -} - -func getContainerCount() (int, error) { - const containers = "Containers:" - - cmd := exec.Command(dockerBinary, "info") - out, _, err := runCommandWithOutput(cmd) - if err != nil { - return 0, err - } - - lines := strings.Split(out, "\n") - for _, line := range lines { - if strings.Contains(line, containers) { - output := strings.TrimSpace(line) - output = strings.TrimLeft(output, containers) - output = strings.Trim(output, " ") - containerCount, err := strconv.Atoi(output) - if err != nil { - return 0, err - } - return containerCount, nil - } - } - return 0, fmt.Errorf("couldn't find the Container count in the output") -} - -// FakeContext creates directories that can be used as a build context -type FakeContext struct { - Dir string -} - -// Add a file at a path, creating directories where necessary -func (f *FakeContext) Add(file, content string) error { - return f.addFile(file, []byte(content)) -} - -func (f *FakeContext) addFile(file string, content []byte) error { - fp := filepath.Join(f.Dir, filepath.FromSlash(file)) - dirpath := filepath.Dir(fp) - if dirpath != "." { - if err := os.MkdirAll(dirpath, 0755); err != nil { - return err - } - } - return ioutil.WriteFile(fp, content, 0644) - -} - -// Delete a file at a path -func (f *FakeContext) Delete(file string) error { - fp := filepath.Join(f.Dir, filepath.FromSlash(file)) - return os.RemoveAll(fp) -} - -// Close deletes the context -func (f *FakeContext) Close() error { - return os.RemoveAll(f.Dir) -} - -func fakeContextFromNewTempDir() (*FakeContext, error) { - tmp, err := ioutil.TempDir("", "fake-context") - if err != nil { - return nil, err - } - if err := os.Chmod(tmp, 0755); err != nil { - return nil, err - } - return fakeContextFromDir(tmp), nil -} - -func fakeContextFromDir(dir string) *FakeContext { - return &FakeContext{dir} -} - -func fakeContextWithFiles(files map[string]string) (*FakeContext, error) { - ctx, err := fakeContextFromNewTempDir() - if err != nil { - return nil, err - } - for file, content := range files { - if err := ctx.Add(file, content); err != nil { - ctx.Close() - return nil, err - } - } - return ctx, nil -} - -func fakeContextAddDockerfile(ctx *FakeContext, dockerfile string) error { - if err := ctx.Add("Dockerfile", dockerfile); err != nil { - ctx.Close() - return err - } - return nil -} - -func fakeContext(dockerfile string, files map[string]string) (*FakeContext, error) { - ctx, err := fakeContextWithFiles(files) - if err != nil { - return nil, err - } - if err := fakeContextAddDockerfile(ctx, dockerfile); err != nil { - return nil, err - } - return ctx, nil -} - -// FakeStorage is a static file server. It might be running locally or remotely -// on test host. -type FakeStorage interface { - Close() error - URL() string - CtxDir() string -} - -func fakeBinaryStorage(archives map[string]*bytes.Buffer) (FakeStorage, error) { - ctx, err := fakeContextFromNewTempDir() - if err != nil { - return nil, err - } - for name, content := range archives { - if err := ctx.addFile(name, content.Bytes()); err != nil { - return nil, err - } - } - return fakeStorageWithContext(ctx) -} - -// fakeStorage returns either a local or remote (at daemon machine) file server -func fakeStorage(files map[string]string) (FakeStorage, error) { - ctx, err := fakeContextWithFiles(files) - if err != nil { - return nil, err - } - return fakeStorageWithContext(ctx) -} - -// fakeStorageWithContext returns either a local or remote (at daemon machine) file server -func fakeStorageWithContext(ctx *FakeContext) (FakeStorage, error) { - if isLocalDaemon { - return newLocalFakeStorage(ctx) - } - return newRemoteFileServer(ctx) -} - -// localFileStorage is a file storage on the running machine -type localFileStorage struct { - *FakeContext - *httptest.Server -} - -func (s *localFileStorage) URL() string { - return s.Server.URL -} - -func (s *localFileStorage) CtxDir() string { - return s.FakeContext.Dir -} - -func (s *localFileStorage) Close() error { - defer s.Server.Close() - return s.FakeContext.Close() -} - -func newLocalFakeStorage(ctx *FakeContext) (*localFileStorage, error) { - handler := http.FileServer(http.Dir(ctx.Dir)) - server := httptest.NewServer(handler) - return &localFileStorage{ - FakeContext: ctx, - Server: server, - }, nil -} - -// remoteFileServer is a containerized static file server started on the remote -// testing machine to be used in URL-accepting docker build functionality. -type remoteFileServer struct { - host string // hostname/port web server is listening to on docker host e.g. 0.0.0.0:43712 - container string - image string - ctx *FakeContext -} - -func (f *remoteFileServer) URL() string { - u := url.URL{ - Scheme: "http", - Host: f.host} - return u.String() -} - -func (f *remoteFileServer) CtxDir() string { - return f.ctx.Dir -} - -func (f *remoteFileServer) Close() error { - defer func() { - if f.ctx != nil { - f.ctx.Close() - } - if f.image != "" { - deleteImages(f.image) - } - }() - if f.container == "" { - return nil - } - return deleteContainer(f.container) -} - -func newRemoteFileServer(ctx *FakeContext) (*remoteFileServer, error) { - var ( - image = fmt.Sprintf("fileserver-img-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10))) - container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(stringutils.GenerateRandomAlphaOnlyString(10))) - ) - - if err := ensureHTTPServerImage(); err != nil { - return nil, err - } - - // Build the image - if err := fakeContextAddDockerfile(ctx, `FROM httpserver -COPY . /static`); err != nil { - return nil, fmt.Errorf("Cannot add Dockerfile to context: %v", err) - } - if _, err := buildImageFromContext(image, ctx, false); err != nil { - return nil, fmt.Errorf("failed building file storage container image: %v", err) - } - - // Start the container - runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--name", container, image) - if out, ec, err := runCommandWithOutput(runCmd); err != nil { - return nil, fmt.Errorf("failed to start file storage container. ec=%v\nout=%s\nerr=%v", ec, out, err) - } - - // Find out the system assigned port - out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "port", container, "80/tcp")) - if err != nil { - return nil, fmt.Errorf("failed to find container port: err=%v\nout=%s", err, out) - } - - fileserverHostPort := strings.Trim(out, "\n") - _, port, err := net.SplitHostPort(fileserverHostPort) - if err != nil { - return nil, fmt.Errorf("unable to parse file server host:port: %v", err) - } - - dockerHostURL, err := url.Parse(daemonHost()) - if err != nil { - return nil, fmt.Errorf("unable to parse daemon host URL: %v", err) - } - - host, _, err := net.SplitHostPort(dockerHostURL.Host) - if err != nil { - return nil, fmt.Errorf("unable to parse docker daemon host:port: %v", err) - } - - return &remoteFileServer{ - container: container, - image: image, - host: fmt.Sprintf("%s:%s", host, port), - ctx: ctx}, nil -} - -func inspectFieldAndMarshall(c *check.C, name, field string, output interface{}) { - str := inspectFieldJSON(c, name, field) - err := json.Unmarshal([]byte(str), output) - if c != nil { - c.Assert(err, check.IsNil, check.Commentf("failed to unmarshal: %v", err)) - } -} - -func inspectFilter(name, filter string) (string, error) { - format := fmt.Sprintf("{{%s}}", filter) - inspectCmd := exec.Command(dockerBinary, "inspect", "-f", format, name) - out, exitCode, err := runCommandWithOutput(inspectCmd) - if err != nil || exitCode != 0 { - return "", fmt.Errorf("failed to inspect %s: %s", name, out) - } - return strings.TrimSpace(out), nil -} - -func inspectFieldWithError(name, field string) (string, error) { - return inspectFilter(name, fmt.Sprintf(".%s", field)) -} - -func inspectField(c *check.C, name, field string) string { - out, err := inspectFilter(name, fmt.Sprintf(".%s", field)) - if c != nil { - c.Assert(err, check.IsNil) - } - return out -} - -func inspectFieldJSON(c *check.C, name, field string) string { - out, err := inspectFilter(name, fmt.Sprintf("json .%s", field)) - if c != nil { - c.Assert(err, check.IsNil) - } - return out -} - -func inspectFieldMap(c *check.C, name, path, field string) string { - out, err := inspectFilter(name, fmt.Sprintf("index .%s %q", path, field)) - if c != nil { - c.Assert(err, check.IsNil) - } - return out -} - -func inspectMountSourceField(name, destination string) (string, error) { - m, err := inspectMountPoint(name, destination) - if err != nil { - return "", err - } - return m.Source, nil -} - -func inspectMountPoint(name, destination string) (types.MountPoint, error) { - out, err := inspectFilter(name, "json .Mounts") - if err != nil { - return types.MountPoint{}, err - } - - return inspectMountPointJSON(out, destination) -} - -var errMountNotFound = errors.New("mount point not found") - -func inspectMountPointJSON(j, destination string) (types.MountPoint, error) { - var mp []types.MountPoint - if err := json.Unmarshal([]byte(j), &mp); err != nil { - return types.MountPoint{}, err - } - - var m *types.MountPoint - for _, c := range mp { - if c.Destination == destination { - m = &c - break - } - } - - if m == nil { - return types.MountPoint{}, errMountNotFound - } - - return *m, nil -} - -func inspectImage(name, filter string) (string, error) { - args := []string{"inspect", "--type", "image"} - if filter != "" { - format := fmt.Sprintf("{{%s}}", filter) - args = append(args, "-f", format) - } - args = append(args, name) - inspectCmd := exec.Command(dockerBinary, args...) - out, exitCode, err := runCommandWithOutput(inspectCmd) - if err != nil || exitCode != 0 { - return "", fmt.Errorf("failed to inspect %s: %s", name, out) - } - return strings.TrimSpace(out), nil -} - -func getIDByName(name string) (string, error) { - return inspectFieldWithError(name, "Id") -} - -// getContainerState returns the exit code of the container -// and true if it's running -// the exit code should be ignored if it's running -func getContainerState(c *check.C, id string) (int, bool, error) { - var ( - exitStatus int - running bool - ) - out, exitCode := dockerCmd(c, "inspect", "--format={{.State.Running}} {{.State.ExitCode}}", id) - if exitCode != 0 { - return 0, false, fmt.Errorf("%q doesn't exist: %s", id, out) - } - - out = strings.Trim(out, "\n") - splitOutput := strings.Split(out, " ") - if len(splitOutput) != 2 { - return 0, false, fmt.Errorf("failed to get container state: output is broken") - } - if splitOutput[0] == "true" { - running = true - } - if n, err := strconv.Atoi(splitOutput[1]); err == nil { - exitStatus = n - } else { - return 0, false, fmt.Errorf("failed to get container state: couldn't parse integer") - } - - return exitStatus, running, nil -} - -func buildImageCmd(name, dockerfile string, useCache bool, buildFlags ...string) *exec.Cmd { - return buildImageCmdWithHost(name, dockerfile, "", useCache, buildFlags...) -} - -func buildImageCmdWithHost(name, dockerfile, host string, useCache bool, buildFlags ...string) *exec.Cmd { - args := []string{} - if host != "" { - args = append(args, "--host", host) - } - args = append(args, "build", "-t", name) - if !useCache { - args = append(args, "--no-cache") - } - args = append(args, buildFlags...) - args = append(args, "-") - buildCmd := exec.Command(dockerBinary, args...) - buildCmd.Stdin = strings.NewReader(dockerfile) - return buildCmd -} - -func buildImageWithOut(name, dockerfile string, useCache bool, buildFlags ...string) (string, string, error) { - buildCmd := buildImageCmd(name, dockerfile, useCache, buildFlags...) - out, exitCode, err := runCommandWithOutput(buildCmd) - if err != nil || exitCode != 0 { - return "", out, fmt.Errorf("failed to build the image: %s", out) - } - id, err := getIDByName(name) - if err != nil { - return "", out, err - } - return id, out, nil -} - -func buildImageWithStdoutStderr(name, dockerfile string, useCache bool, buildFlags ...string) (string, string, string, error) { - buildCmd := buildImageCmd(name, dockerfile, useCache, buildFlags...) - stdout, stderr, exitCode, err := runCommandWithStdoutStderr(buildCmd) - if err != nil || exitCode != 0 { - return "", stdout, stderr, fmt.Errorf("failed to build the image: %s", stdout) - } - id, err := getIDByName(name) - if err != nil { - return "", stdout, stderr, err - } - return id, stdout, stderr, nil -} - -func buildImage(name, dockerfile string, useCache bool, buildFlags ...string) (string, error) { - id, _, err := buildImageWithOut(name, dockerfile, useCache, buildFlags...) - return id, err -} - -func buildImageFromContext(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, error) { - id, _, err := buildImageFromContextWithOut(name, ctx, useCache, buildFlags...) - if err != nil { - return "", err - } - return id, nil -} - -func buildImageFromContextWithOut(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, string, error) { - args := []string{"build", "-t", name} - if !useCache { - args = append(args, "--no-cache") - } - args = append(args, buildFlags...) - args = append(args, ".") - buildCmd := exec.Command(dockerBinary, args...) - buildCmd.Dir = ctx.Dir - out, exitCode, err := runCommandWithOutput(buildCmd) - if err != nil || exitCode != 0 { - return "", "", fmt.Errorf("failed to build the image: %s", out) - } - id, err := getIDByName(name) - if err != nil { - return "", "", err - } - return id, out, nil -} - -func buildImageFromContextWithStdoutStderr(name string, ctx *FakeContext, useCache bool, buildFlags ...string) (string, string, string, error) { - args := []string{"build", "-t", name} - if !useCache { - args = append(args, "--no-cache") - } - args = append(args, buildFlags...) - args = append(args, ".") - buildCmd := exec.Command(dockerBinary, args...) - buildCmd.Dir = ctx.Dir - - stdout, stderr, exitCode, err := runCommandWithStdoutStderr(buildCmd) - if err != nil || exitCode != 0 { - return "", stdout, stderr, fmt.Errorf("failed to build the image: %s", stdout) - } - id, err := getIDByName(name) - if err != nil { - return "", stdout, stderr, err - } - return id, stdout, stderr, nil -} - -func buildImageFromGitWithStdoutStderr(name string, ctx *fakeGit, useCache bool, buildFlags ...string) (string, string, string, error) { - args := []string{"build", "-t", name} - if !useCache { - args = append(args, "--no-cache") - } - args = append(args, buildFlags...) - args = append(args, ctx.RepoURL) - buildCmd := exec.Command(dockerBinary, args...) - - stdout, stderr, exitCode, err := runCommandWithStdoutStderr(buildCmd) - if err != nil || exitCode != 0 { - return "", stdout, stderr, fmt.Errorf("failed to build the image: %s", stdout) - } - id, err := getIDByName(name) - if err != nil { - return "", stdout, stderr, err - } - return id, stdout, stderr, nil -} - -func buildImageFromPath(name, path string, useCache bool, buildFlags ...string) (string, error) { - args := []string{"build", "-t", name} - if !useCache { - args = append(args, "--no-cache") - } - args = append(args, buildFlags...) - args = append(args, path) - buildCmd := exec.Command(dockerBinary, args...) - out, exitCode, err := runCommandWithOutput(buildCmd) - if err != nil || exitCode != 0 { - return "", fmt.Errorf("failed to build the image: %s", out) - } - return getIDByName(name) -} - -type gitServer interface { - URL() string - Close() error -} - -type localGitServer struct { - *httptest.Server -} - -func (r *localGitServer) Close() error { - r.Server.Close() - return nil -} - -func (r *localGitServer) URL() string { - return r.Server.URL -} - -type fakeGit struct { - root string - server gitServer - RepoURL string -} - -func (g *fakeGit) Close() { - g.server.Close() - os.RemoveAll(g.root) -} - -func newFakeGit(name string, files map[string]string, enforceLocalServer bool) (*fakeGit, error) { - ctx, err := fakeContextWithFiles(files) - if err != nil { - return nil, err - } - defer ctx.Close() - curdir, err := os.Getwd() - if err != nil { - return nil, err - } - defer os.Chdir(curdir) - - if output, err := exec.Command("git", "init", ctx.Dir).CombinedOutput(); err != nil { - return nil, fmt.Errorf("error trying to init repo: %s (%s)", err, output) - } - err = os.Chdir(ctx.Dir) - if err != nil { - return nil, err - } - if output, err := exec.Command("git", "config", "user.name", "Fake User").CombinedOutput(); err != nil { - return nil, fmt.Errorf("error trying to set 'user.name': %s (%s)", err, output) - } - if output, err := exec.Command("git", "config", "user.email", "fake.user@example.com").CombinedOutput(); err != nil { - return nil, fmt.Errorf("error trying to set 'user.email': %s (%s)", err, output) - } - if output, err := exec.Command("git", "add", "*").CombinedOutput(); err != nil { - return nil, fmt.Errorf("error trying to add files to repo: %s (%s)", err, output) - } - if output, err := exec.Command("git", "commit", "-a", "-m", "Initial commit").CombinedOutput(); err != nil { - return nil, fmt.Errorf("error trying to commit to repo: %s (%s)", err, output) - } - - root, err := ioutil.TempDir("", "docker-test-git-repo") - if err != nil { - return nil, err - } - repoPath := filepath.Join(root, name+".git") - if output, err := exec.Command("git", "clone", "--bare", ctx.Dir, repoPath).CombinedOutput(); err != nil { - os.RemoveAll(root) - return nil, fmt.Errorf("error trying to clone --bare: %s (%s)", err, output) - } - err = os.Chdir(repoPath) - if err != nil { - os.RemoveAll(root) - return nil, err - } - if output, err := exec.Command("git", "update-server-info").CombinedOutput(); err != nil { - os.RemoveAll(root) - return nil, fmt.Errorf("error trying to git update-server-info: %s (%s)", err, output) - } - err = os.Chdir(curdir) - if err != nil { - os.RemoveAll(root) - return nil, err - } - - var server gitServer - if !enforceLocalServer { - // use fakeStorage server, which might be local or remote (at test daemon) - server, err = fakeStorageWithContext(fakeContextFromDir(root)) - if err != nil { - return nil, fmt.Errorf("cannot start fake storage: %v", err) - } - } else { - // always start a local http server on CLI test machine - httpServer := httptest.NewServer(http.FileServer(http.Dir(root))) - server = &localGitServer{httpServer} - } - return &fakeGit{ - root: root, - server: server, - RepoURL: fmt.Sprintf("%s/%s.git", server.URL(), name), - }, nil -} - -// Write `content` to the file at path `dst`, creating it if necessary, -// as well as any missing directories. -// The file is truncated if it already exists. -// Fail the test when error occurs. -func writeFile(dst, content string, c *check.C) { - // Create subdirectories if necessary - c.Assert(os.MkdirAll(path.Dir(dst), 0700), check.IsNil) - f, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0700) - c.Assert(err, check.IsNil) - defer f.Close() - // Write content (truncate if it exists) - _, err = io.Copy(f, strings.NewReader(content)) - c.Assert(err, check.IsNil) -} - -// Return the contents of file at path `src`. -// Fail the test when error occurs. -func readFile(src string, c *check.C) (content string) { - data, err := ioutil.ReadFile(src) - c.Assert(err, check.IsNil) - - return string(data) -} - -func containerStorageFile(containerID, basename string) string { - return filepath.Join(containerStoragePath, containerID, basename) -} - -// docker commands that use this function must be run with the '-d' switch. -func runCommandAndReadContainerFile(filename string, cmd *exec.Cmd) ([]byte, error) { - out, _, err := runCommandWithOutput(cmd) - if err != nil { - return nil, fmt.Errorf("%v: %q", err, out) - } - - contID := strings.TrimSpace(out) - - if err := waitRun(contID); err != nil { - return nil, fmt.Errorf("%v: %q", contID, err) - } - - return readContainerFile(contID, filename) -} - -func readContainerFile(containerID, filename string) ([]byte, error) { - f, err := os.Open(containerStorageFile(containerID, filename)) - if err != nil { - return nil, err - } - defer f.Close() - - content, err := ioutil.ReadAll(f) - if err != nil { - return nil, err - } - - return content, nil -} - -func readContainerFileWithExec(containerID, filename string) ([]byte, error) { - out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "exec", containerID, "cat", filename)) - return []byte(out), err -} - -// daemonTime provides the current time on the daemon host -func daemonTime(c *check.C) time.Time { - if isLocalDaemon { - return time.Now() - } - - status, body, err := sockRequest("GET", "/info", nil) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusOK) - - type infoJSON struct { - SystemTime string - } - var info infoJSON - err = json.Unmarshal(body, &info) - c.Assert(err, check.IsNil, check.Commentf("unable to unmarshal GET /info response")) - - dt, err := time.Parse(time.RFC3339Nano, info.SystemTime) - c.Assert(err, check.IsNil, check.Commentf("invalid time format in GET /info response")) - return dt -} - -// daemonUnixTime returns the current time on the daemon host with nanoseconds precision. -// It return the time formatted how the client sends timestamps to the server. -func daemonUnixTime(c *check.C) string { - return parseEventTime(daemonTime(c)) -} - -func parseEventTime(t time.Time) string { - return fmt.Sprintf("%d.%09d", t.Unix(), int64(t.Nanosecond())) -} - -func setupRegistry(c *check.C, schema1 bool, auth, tokenURL string) *testRegistryV2 { - reg, err := newTestRegistryV2(c, schema1, auth, tokenURL) - c.Assert(err, check.IsNil) - - // Wait for registry to be ready to serve requests. - for i := 0; i != 50; i++ { - if err = reg.Ping(); err == nil { - break - } - time.Sleep(100 * time.Millisecond) - } - - c.Assert(err, check.IsNil, check.Commentf("Timeout waiting for test registry to become available: %v", err)) - return reg -} - -func setupNotary(c *check.C) *testNotary { - ts, err := newTestNotary(c) - c.Assert(err, check.IsNil) - - return ts -} - -// appendBaseEnv appends the minimum set of environment variables to exec the -// docker cli binary for testing with correct configuration to the given env -// list. -func appendBaseEnv(isTLS bool, env ...string) []string { - preserveList := []string{ - // preserve remote test host - "DOCKER_HOST", - - // windows: requires preserving SystemRoot, otherwise dial tcp fails - // with "GetAddrInfoW: A non-recoverable error occurred during a database lookup." - "SystemRoot", - - // testing help text requires the $PATH to dockerd is set - "PATH", - } - if isTLS { - preserveList = append(preserveList, "DOCKER_TLS_VERIFY", "DOCKER_CERT_PATH") - } - - for _, key := range preserveList { - if val := os.Getenv(key); val != "" { - env = append(env, fmt.Sprintf("%s=%s", key, val)) - } - } - return env -} - -func createTmpFile(c *check.C, content string) string { - f, err := ioutil.TempFile("", "testfile") - c.Assert(err, check.IsNil) - - filename := f.Name() - - err = ioutil.WriteFile(filename, []byte(content), 0644) - c.Assert(err, check.IsNil) - - return filename -} - -func buildImageWithOutInDamon(socket string, name, dockerfile string, useCache bool) (string, error) { - args := []string{"--host", socket} - buildCmd := buildImageCmdArgs(args, name, dockerfile, useCache) - out, exitCode, err := runCommandWithOutput(buildCmd) - if err != nil || exitCode != 0 { - return out, fmt.Errorf("failed to build the image: %s, error: %v", out, err) - } - return out, nil -} - -func buildImageCmdArgs(args []string, name, dockerfile string, useCache bool) *exec.Cmd { - args = append(args, []string{"-D", "build", "-t", name}...) - if !useCache { - args = append(args, "--no-cache") - } - args = append(args, "-") - buildCmd := exec.Command(dockerBinary, args...) - buildCmd.Stdin = strings.NewReader(dockerfile) - return buildCmd - -} - -func waitForContainer(contID string, args ...string) error { - args = append([]string{dockerBinary, "run", "--name", contID}, args...) - result := icmd.RunCmd(icmd.Cmd{Command: args}) - if result.Error != nil { - return result.Error - } - return waitRun(contID) -} - -// waitRestart will wait for the specified container to restart once -func waitRestart(contID string, duration time.Duration) error { - return waitInspect(contID, "{{.RestartCount}}", "1", duration) -} - -// waitRun will wait for the specified container to be running, maximum 5 seconds. -func waitRun(contID string) error { - return waitInspect(contID, "{{.State.Running}}", "true", 5*time.Second) -} - -// waitExited will wait for the specified container to state exit, subject -// to a maximum time limit in seconds supplied by the caller -func waitExited(contID string, duration time.Duration) error { - return waitInspect(contID, "{{.State.Status}}", "exited", duration) -} - -// waitInspect will wait for the specified container to have the specified string -// in the inspect output. It will wait until the specified timeout (in seconds) -// is reached. -func waitInspect(name, expr, expected string, timeout time.Duration) error { - return waitInspectWithArgs(name, expr, expected, timeout) -} - -func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg ...string) error { - after := time.After(timeout) - - args := append(arg, "inspect", "-f", expr, name) - for { - result := icmd.RunCommand(dockerBinary, args...) - if result.Error != nil { - if !strings.Contains(result.Stderr(), "No such") { - return fmt.Errorf("error executing docker inspect: %v\n%s", - result.Stderr(), result.Stdout()) - } - select { - case <-after: - return result.Error - default: - time.Sleep(10 * time.Millisecond) - continue - } - } - - out := strings.TrimSpace(result.Stdout()) - if out == expected { - break - } - - select { - case <-after: - return fmt.Errorf("condition \"%q == %q\" not true in time", out, expected) - default: - } - - time.Sleep(100 * time.Millisecond) - } - return nil -} - -func getInspectBody(c *check.C, version, id string) []byte { - endpoint := fmt.Sprintf("/%s/containers/%s/json", version, id) - status, body, err := sockRequest("GET", endpoint, nil) - c.Assert(err, check.IsNil) - c.Assert(status, check.Equals, http.StatusOK) - return body -} - -// Run a long running idle task in a background container using the -// system-specific default image and command. -func runSleepingContainer(c *check.C, extraArgs ...string) (string, int) { - return runSleepingContainerInImage(c, defaultSleepImage, extraArgs...) -} - -// Run a long running idle task in a background container using the specified -// image and the system-specific command. -func runSleepingContainerInImage(c *check.C, image string, extraArgs ...string) (string, int) { - args := []string{"run", "-d"} - args = append(args, extraArgs...) - args = append(args, image) - args = append(args, sleepCommandForDaemonPlatform()...) - return dockerCmd(c, args...) -} - -func getRootUIDGID() (int, int, error) { - uidgid := strings.Split(filepath.Base(dockerBasePath), ".") - if len(uidgid) == 1 { - //user namespace remapping is not turned on; return 0 - return 0, 0, nil - } - uid, err := strconv.Atoi(uidgid[0]) - if err != nil { - return 0, 0, err - } - gid, err := strconv.Atoi(uidgid[1]) - if err != nil { - return 0, 0, err - } - return uid, gid, nil -} - -// minimalBaseImage returns the name of the minimal base image for the current -// daemon platform. -func minimalBaseImage() string { - if daemonPlatform == "windows" { - return WindowsBaseImage - } - return "scratch" -} - -func getGoroutineNumber() (int, error) { - i := struct { - NGoroutines int - }{} - status, b, err := sockRequest("GET", "/info", nil) - if err != nil { - return 0, err - } - if status != http.StatusOK { - return 0, fmt.Errorf("http status code: %d", status) - } - if err := json.Unmarshal(b, &i); err != nil { - return 0, err - } - return i.NGoroutines, nil -} - -func waitForGoroutines(expected int) error { - t := time.After(30 * time.Second) - for { - select { - case <-t: - n, err := getGoroutineNumber() - if err != nil { - return err - } - if n > expected { - return fmt.Errorf("leaked goroutines: expected less than or equal to %d, got: %d", expected, n) - } - default: - n, err := getGoroutineNumber() - if err != nil { - return err - } - if n <= expected { - return nil - } - time.Sleep(200 * time.Millisecond) - } - } -} - -// getErrorMessage returns the error message from an error API response -func getErrorMessage(c *check.C, body []byte) string { - var resp types.ErrorResponse - c.Assert(json.Unmarshal(body, &resp), check.IsNil) - return strings.TrimSpace(resp.Message) -} - -func waitAndAssert(c *check.C, timeout time.Duration, f checkF, checker check.Checker, args ...interface{}) { - after := time.After(timeout) - for { - v, comment := f(c) - assert, _ := checker.Check(append([]interface{}{v}, args...), checker.Info().Params) - select { - case <-after: - assert = true - default: - } - if assert { - if comment != nil { - args = append(args, comment) - } - c.Assert(v, checker, args...) - return - } - time.Sleep(100 * time.Millisecond) - } -} - -type checkF func(*check.C) (interface{}, check.CommentInterface) -type reducer func(...interface{}) interface{} - -func reducedCheck(r reducer, funcs ...checkF) checkF { - return func(c *check.C) (interface{}, check.CommentInterface) { - var values []interface{} - var comments []string - for _, f := range funcs { - v, comment := f(c) - values = append(values, v) - if comment != nil { - comments = append(comments, comment.CheckCommentString()) - } - } - return r(values...), check.Commentf("%v", strings.Join(comments, ", ")) - } -} - -func sumAsIntegers(vals ...interface{}) interface{} { - var s int - for _, v := range vals { - s += v.(int) - } - return s -} diff --git a/vendor/github.com/docker/docker/integration-cli/events_utils.go b/vendor/github.com/docker/docker/integration-cli/events_utils.go deleted file mode 100644 index ba24179..0000000 --- a/vendor/github.com/docker/docker/integration-cli/events_utils.go +++ /dev/null @@ -1,206 +0,0 @@ -package main - -import ( - "bufio" - "bytes" - "io" - "os/exec" - "regexp" - "strconv" - "strings" - - "github.com/Sirupsen/logrus" - eventstestutils "github.com/docker/docker/daemon/events/testutils" - "github.com/docker/docker/pkg/integration/checker" - "github.com/go-check/check" -) - -// eventMatcher is a function that tries to match an event input. -// It returns true if the event matches and a map with -// a set of key/value to identify the match. -type eventMatcher func(text string) (map[string]string, bool) - -// eventMatchProcessor is a function to handle an event match. -// It receives a map of key/value with the information extracted in a match. -type eventMatchProcessor func(matches map[string]string) - -// eventObserver runs an events commands and observes its output. -type eventObserver struct { - buffer *bytes.Buffer - command *exec.Cmd - scanner *bufio.Scanner - startTime string - disconnectionError error -} - -// newEventObserver creates the observer and initializes the command -// without running it. Users must call `eventObserver.Start` to start the command. -func newEventObserver(c *check.C, args ...string) (*eventObserver, error) { - since := daemonTime(c).Unix() - return newEventObserverWithBacklog(c, since, args...) -} - -// newEventObserverWithBacklog creates a new observer changing the start time of the backlog to return. -func newEventObserverWithBacklog(c *check.C, since int64, args ...string) (*eventObserver, error) { - startTime := strconv.FormatInt(since, 10) - cmdArgs := []string{"events", "--since", startTime} - if len(args) > 0 { - cmdArgs = append(cmdArgs, args...) - } - eventsCmd := exec.Command(dockerBinary, cmdArgs...) - stdout, err := eventsCmd.StdoutPipe() - if err != nil { - return nil, err - } - - return &eventObserver{ - buffer: new(bytes.Buffer), - command: eventsCmd, - scanner: bufio.NewScanner(stdout), - startTime: startTime, - }, nil -} - -// Start starts the events command. -func (e *eventObserver) Start() error { - return e.command.Start() -} - -// Stop stops the events command. -func (e *eventObserver) Stop() { - e.command.Process.Kill() - e.command.Process.Release() -} - -// Match tries to match the events output with a given matcher. -func (e *eventObserver) Match(match eventMatcher, process eventMatchProcessor) { - for e.scanner.Scan() { - text := e.scanner.Text() - e.buffer.WriteString(text) - e.buffer.WriteString("\n") - - if matches, ok := match(text); ok { - process(matches) - } - } - - err := e.scanner.Err() - if err == nil { - err = io.EOF - } - - logrus.Debugf("EventObserver scanner loop finished: %v", err) - e.disconnectionError = err -} - -func (e *eventObserver) CheckEventError(c *check.C, id, event string, match eventMatcher) { - var foundEvent bool - scannerOut := e.buffer.String() - - if e.disconnectionError != nil { - until := daemonUnixTime(c) - out, _ := dockerCmd(c, "events", "--since", e.startTime, "--until", until) - events := strings.Split(strings.TrimSpace(out), "\n") - for _, e := range events { - if _, ok := match(e); ok { - foundEvent = true - break - } - } - scannerOut = out - } - if !foundEvent { - c.Fatalf("failed to observe event `%s` for %s. Disconnection error: %v\nout:\n%v", event, id, e.disconnectionError, scannerOut) - } -} - -// matchEventLine matches a text with the event regular expression. -// It returns the matches and true if the regular expression matches with the given id and event type. -// It returns an empty map and false if there is no match. -func matchEventLine(id, eventType string, actions map[string]chan bool) eventMatcher { - return func(text string) (map[string]string, bool) { - matches := eventstestutils.ScanMap(text) - if len(matches) == 0 { - return matches, false - } - - if matchIDAndEventType(matches, id, eventType) { - if _, ok := actions[matches["action"]]; ok { - return matches, true - } - } - return matches, false - } -} - -// processEventMatch closes an action channel when an event line matches the expected action. -func processEventMatch(actions map[string]chan bool) eventMatchProcessor { - return func(matches map[string]string) { - if ch, ok := actions[matches["action"]]; ok { - ch <- true - } - } -} - -// parseEventAction parses an event text and returns the action. -// It fails if the text is not in the event format. -func parseEventAction(c *check.C, text string) string { - matches := eventstestutils.ScanMap(text) - return matches["action"] -} - -// eventActionsByIDAndType returns the actions for a given id and type. -// It fails if the text is not in the event format. -func eventActionsByIDAndType(c *check.C, events []string, id, eventType string) []string { - var filtered []string - for _, event := range events { - matches := eventstestutils.ScanMap(event) - c.Assert(matches, checker.Not(checker.IsNil)) - if matchIDAndEventType(matches, id, eventType) { - filtered = append(filtered, matches["action"]) - } - } - return filtered -} - -// matchIDAndEventType returns true if an event matches a given id and type. -// It also resolves names in the event attributes if the id doesn't match. -func matchIDAndEventType(matches map[string]string, id, eventType string) bool { - return matchEventID(matches, id) && matches["eventType"] == eventType -} - -func matchEventID(matches map[string]string, id string) bool { - matchID := matches["id"] == id || strings.HasPrefix(matches["id"], id) - if !matchID && matches["attributes"] != "" { - // try matching a name in the attributes - attributes := map[string]string{} - for _, a := range strings.Split(matches["attributes"], ", ") { - kv := strings.Split(a, "=") - attributes[kv[0]] = kv[1] - } - matchID = attributes["name"] == id - } - return matchID -} - -func parseEvents(c *check.C, out, match string) { - events := strings.Split(strings.TrimSpace(out), "\n") - for _, event := range events { - matches := eventstestutils.ScanMap(event) - matched, err := regexp.MatchString(match, matches["action"]) - c.Assert(err, checker.IsNil) - c.Assert(matched, checker.True, check.Commentf("Matcher: %s did not match %s", match, matches["action"])) - } -} - -func parseEventsWithID(c *check.C, out, match, id string) { - events := strings.Split(strings.TrimSpace(out), "\n") - for _, event := range events { - matches := eventstestutils.ScanMap(event) - c.Assert(matchEventID(matches, id), checker.True) - - matched, err := regexp.MatchString(match, matches["action"]) - c.Assert(err, checker.IsNil) - c.Assert(matched, checker.True, check.Commentf("Matcher: %s did not match %s", match, matches["action"])) - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures.go b/vendor/github.com/docker/docker/integration-cli/fixtures.go deleted file mode 100644 index e99b738..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures.go +++ /dev/null @@ -1,69 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "sync" -) - -var ensureHTTPServerOnce sync.Once - -func ensureHTTPServerImage() error { - var doIt bool - ensureHTTPServerOnce.Do(func() { - doIt = true - }) - - if !doIt { - return nil - } - - protectedImages["httpserver:latest"] = struct{}{} - - tmp, err := ioutil.TempDir("", "docker-http-server-test") - if err != nil { - return fmt.Errorf("could not build http server: %v", err) - } - defer os.RemoveAll(tmp) - - goos := daemonPlatform - if goos == "" { - goos = "linux" - } - goarch := os.Getenv("DOCKER_ENGINE_GOARCH") - if goarch == "" { - goarch = "amd64" - } - - goCmd, lookErr := exec.LookPath("go") - if lookErr != nil { - return fmt.Errorf("could not build http server: %v", lookErr) - } - - cmd := exec.Command(goCmd, "build", "-o", filepath.Join(tmp, "httpserver"), "github.com/docker/docker/contrib/httpserver") - cmd.Env = append(os.Environ(), []string{ - "CGO_ENABLED=0", - "GOOS=" + goos, - "GOARCH=" + goarch, - }...) - var out []byte - if out, err = cmd.CombinedOutput(); err != nil { - return fmt.Errorf("could not build http server: %s", string(out)) - } - - cpCmd, lookErr := exec.LookPath("cp") - if lookErr != nil { - return fmt.Errorf("could not build http server: %v", lookErr) - } - if out, err = exec.Command(cpCmd, "../contrib/httpserver/Dockerfile", filepath.Join(tmp, "Dockerfile")).CombinedOutput(); err != nil { - return fmt.Errorf("could not build http server: %v", string(out)) - } - - if out, err = exec.Command(dockerBinary, "build", "-q", "-t", "httpserver", tmp).CombinedOutput(); err != nil { - return fmt.Errorf("could not build http server: %v", string(out)) - } - return nil -} diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/auth/docker-credential-shell-test b/vendor/github.com/docker/docker/integration-cli/fixtures/auth/docker-credential-shell-test deleted file mode 100755 index a7be56b..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/auth/docker-credential-shell-test +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -set -e - -listFile=shell_test_list.json - -case $1 in - "store") - in=$( $TEMP/$serverHash - # add the server to the list file - if [[ ! -f $TEMP/$listFile ]]; then - echo "{ \"${server}\": \"${username}\" }" > $TEMP/$listFile - else - list=$(<$TEMP/$listFile) - echo "$list" | jq ". + {\"${server}\": \"${username}\"}" > $TEMP/$listFile - fi - ;; - "get") - in=$( $TEMP/$listFile - ;; - "list") - if [[ ! -f $TEMP/$listFile ]]; then - echo "{}" - else - payload=$(<$TEMP/$listFile) - echo "$payload" - fi - ;; - *) - echo "unknown credential option" - exit 1 - ;; -esac diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/credentialspecs/valid.json b/vendor/github.com/docker/docker/integration-cli/fixtures/credentialspecs/valid.json deleted file mode 100644 index 28913e4..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/credentialspecs/valid.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "CmsPlugins": [ - "ActiveDirectory" - ], - "DomainJoinConfig": { - "Sid": "S-1-5-21-4288985-3632099173-1864715694", - "MachineAccountName": "MusicStoreAcct", - "Guid": "3705d4c3-0b80-42a9-ad97-ebc1801c74b9", - "DnsTreeName": "hyperv.local", - "DnsName": "hyperv.local", - "NetBiosName": "hyperv" - }, - "ActiveDirectoryConfig": { - "GroupManagedServiceAccounts": [ - { - "Name": "MusicStoreAcct", - "Scope": "hyperv.local" - }, - { - "Name": "MusicStoreAcct", - "Scope": "hyperv" - } - ] - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/deploy/default.yaml b/vendor/github.com/docker/docker/integration-cli/fixtures/deploy/default.yaml deleted file mode 100644 index f30c04f..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/deploy/default.yaml +++ /dev/null @@ -1,9 +0,0 @@ - -version: "3" -services: - web: - image: busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0 - command: top - db: - image: busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0 - command: "tail -f /dev/null" diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/deploy/remove.yaml b/vendor/github.com/docker/docker/integration-cli/fixtures/deploy/remove.yaml deleted file mode 100644 index 4ec8cac..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/deploy/remove.yaml +++ /dev/null @@ -1,11 +0,0 @@ - -version: "3.1" -services: - web: - image: busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0 - command: top - secrets: - - special -secrets: - special: - file: fixtures/secrets/default diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/deploy/secrets.yaml b/vendor/github.com/docker/docker/integration-cli/fixtures/deploy/secrets.yaml deleted file mode 100644 index 6ac92cd..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/deploy/secrets.yaml +++ /dev/null @@ -1,20 +0,0 @@ - -version: "3.1" -services: - web: - image: busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0 - command: top - secrets: - - special - - source: super - target: foo.txt - mode: 0400 - - star -secrets: - special: - file: fixtures/secrets/default - super: - file: fixtures/secrets/default - star: - external: - name: outside diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/https/ca.pem b/vendor/github.com/docker/docker/integration-cli/fixtures/https/ca.pem deleted file mode 100644 index 6825d6d..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/https/ca.pem +++ /dev/null @@ -1,23 +0,0 @@ ------BEGIN CERTIFICATE----- -MIID0TCCAzqgAwIBAgIJAP2r7GqEJwSnMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD -VQQGEwJVUzELMAkGA1UECBMCQ0ExFTATBgNVBAcTDFNhbkZyYW5jaXNjbzEVMBMG -A1UEChMMRm9ydC1GdW5zdG9uMREwDwYDVQQLEwhjaGFuZ2VtZTERMA8GA1UEAxMI -Y2hhbmdlbWUxETAPBgNVBCkTCGNoYW5nZW1lMR8wHQYJKoZIhvcNAQkBFhBtYWls -QGhvc3QuZG9tYWluMB4XDTEzMTIwMzE2NTYzMFoXDTIzMTIwMTE2NTYzMFowgaIx -CzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEVMBMGA1UEBxMMU2FuRnJhbmNpc2Nv -MRUwEwYDVQQKEwxGb3J0LUZ1bnN0b24xETAPBgNVBAsTCGNoYW5nZW1lMREwDwYD -VQQDEwhjaGFuZ2VtZTERMA8GA1UEKRMIY2hhbmdlbWUxHzAdBgkqhkiG9w0BCQEW -EG1haWxAaG9zdC5kb21haW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALAn -0xDw+5y7ZptQacq66pUhRu82JP2WU6IDgo5QUtNU6/CX5PwQATe/OnYTZQFbksxp -AU9boG0FCkgxfsgPYXEuZxVEGKI2fxfKHOZZI8mrkWmj6eWU/0cvCjGVc9rTITP5 -sNQvg+hORyVDdNp2IdsbMJayiB3AQYMFx3vSDOMTAgMBAAGjggELMIIBBzAdBgNV -HQ4EFgQUZu7DFz09q0QBa2+ymRm9qgK1NPswgdcGA1UdIwSBzzCBzIAUZu7DFz09 -q0QBa2+ymRm9qgK1NPuhgaikgaUwgaIxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJD -QTEVMBMGA1UEBxMMU2FuRnJhbmNpc2NvMRUwEwYDVQQKEwxGb3J0LUZ1bnN0b24x -ETAPBgNVBAsTCGNoYW5nZW1lMREwDwYDVQQDEwhjaGFuZ2VtZTERMA8GA1UEKRMI -Y2hhbmdlbWUxHzAdBgkqhkiG9w0BCQEWEG1haWxAaG9zdC5kb21haW6CCQD9q+xq -hCcEpzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAF8fJKKM+/oOdnNi -zEd0M1+PmZOyqvjYQn/2ZR8UHH6Imgc/OPQKZXf0bVE1Txc/DaUNn9Isd1SuCuaE -ic3vAIYYU7PmgeNN6vwec48V96T7jr+GAi6AVMhQEc2hHCfVtx11Xx+x6aHDZzJt -Zxtf5lL6KSO9Y+EFwM+rju6hm5hW ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-cert.pem b/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-cert.pem deleted file mode 100644 index c05ed47..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-cert.pem +++ /dev/null @@ -1,73 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 3 (0x3) - Signature Algorithm: sha1WithRSAEncryption - Issuer: C=US, ST=CA, L=SanFrancisco, O=Fort-Funston, OU=changeme, CN=changeme/name=changeme/emailAddress=mail@host.domain - Validity - Not Before: Dec 4 14:17:54 2013 GMT - Not After : Dec 2 14:17:54 2023 GMT - Subject: C=US, ST=CA, L=SanFrancisco, O=Fort-Funston, OU=changeme, CN=client/name=changeme/emailAddress=mail@host.domain - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - Public-Key: (1024 bit) - Modulus: - 00:ca:c9:05:d0:09:4e:3e:a4:fc:d5:14:f4:a5:e8: - 34:d3:6b:51:e3:f3:62:ea:a1:f0:e8:ed:c4:2a:bc: - f0:4f:ca:07:df:e3:88:fa:f4:21:99:35:0e:3d:ea: - b0:86:e7:c4:d2:8a:83:2b:42:b8:ec:a3:99:62:70: - 81:46:cc:fc:a5:1d:d2:63:e8:eb:07:25:9a:e2:25: - 6d:11:56:f2:1a:51:a1:b6:3e:1c:57:32:e9:7b:2c: - aa:1b:cc:97:2d:89:2d:b1:c9:5e:35:28:4d:7c:fa: - 65:31:3e:f7:70:dd:6e:0b:3c:58:af:a8:2e:24:c0: - 7e:4e:78:7d:0a:9e:8f:42:43 - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - Easy-RSA Generated Certificate - X509v3 Subject Key Identifier: - DE:42:EF:2D:98:A3:6C:A8:AA:E0:8C:71:2C:9D:64:23:A9:E2:7E:81 - X509v3 Authority Key Identifier: - keyid:66:EE:C3:17:3D:3D:AB:44:01:6B:6F:B2:99:19:BD:AA:02:B5:34:FB - DirName:/C=US/ST=CA/L=SanFrancisco/O=Fort-Funston/OU=changeme/CN=changeme/name=changeme/emailAddress=mail@host.domain - serial:FD:AB:EC:6A:84:27:04:A7 - - X509v3 Extended Key Usage: - TLS Web Client Authentication - X509v3 Key Usage: - Digital Signature - Signature Algorithm: sha1WithRSAEncryption - 1c:44:26:ea:e1:66:25:cb:e4:8e:57:1c:f6:b9:17:22:62:40: - 12:90:8f:3b:b2:61:7a:54:94:8f:b1:20:0b:bf:a3:51:e3:fa: - 1c:a1:be:92:3a:d0:76:44:c0:57:83:ab:6a:e4:1a:45:49:a4: - af:39:0d:60:32:fc:3a:be:d7:fb:5d:99:7a:1f:87:e7:d5:ab: - 84:a2:5e:90:d8:bf:fa:89:6d:32:26:02:5e:31:35:68:7f:31: - f5:6b:51:46:bc:af:70:ed:5a:09:7d:ec:b2:48:4f:fe:c5:2f: - 56:04:ad:f6:c1:d2:2a:e4:6a:c4:87:fe:08:35:c5:38:cb:5e: - 4a:c4 ------BEGIN CERTIFICATE----- -MIIEFTCCA36gAwIBAgIBAzANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMCVVMx -CzAJBgNVBAgTAkNBMRUwEwYDVQQHEwxTYW5GcmFuY2lzY28xFTATBgNVBAoTDEZv -cnQtRnVuc3RvbjERMA8GA1UECxMIY2hhbmdlbWUxETAPBgNVBAMTCGNoYW5nZW1l -MREwDwYDVQQpEwhjaGFuZ2VtZTEfMB0GCSqGSIb3DQEJARYQbWFpbEBob3N0LmRv -bWFpbjAeFw0xMzEyMDQxNDE3NTRaFw0yMzEyMDIxNDE3NTRaMIGgMQswCQYDVQQG -EwJVUzELMAkGA1UECBMCQ0ExFTATBgNVBAcTDFNhbkZyYW5jaXNjbzEVMBMGA1UE -ChMMRm9ydC1GdW5zdG9uMREwDwYDVQQLEwhjaGFuZ2VtZTEPMA0GA1UEAxMGY2xp -ZW50MREwDwYDVQQpEwhjaGFuZ2VtZTEfMB0GCSqGSIb3DQEJARYQbWFpbEBob3N0 -LmRvbWFpbjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyskF0AlOPqT81RT0 -peg002tR4/Ni6qHw6O3EKrzwT8oH3+OI+vQhmTUOPeqwhufE0oqDK0K47KOZYnCB -Rsz8pR3SY+jrByWa4iVtEVbyGlGhtj4cVzLpeyyqG8yXLYktscleNShNfPplMT73 -cN1uCzxYr6guJMB+Tnh9Cp6PQkMCAwEAAaOCAVkwggFVMAkGA1UdEwQCMAAwLQYJ -YIZIAYb4QgENBCAWHkVhc3ktUlNBIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNV -HQ4EFgQU3kLvLZijbKiq4IxxLJ1kI6nifoEwgdcGA1UdIwSBzzCBzIAUZu7DFz09 -q0QBa2+ymRm9qgK1NPuhgaikgaUwgaIxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJD -QTEVMBMGA1UEBxMMU2FuRnJhbmNpc2NvMRUwEwYDVQQKEwxGb3J0LUZ1bnN0b24x -ETAPBgNVBAsTCGNoYW5nZW1lMREwDwYDVQQDEwhjaGFuZ2VtZTERMA8GA1UEKRMI -Y2hhbmdlbWUxHzAdBgkqhkiG9w0BCQEWEG1haWxAaG9zdC5kb21haW6CCQD9q+xq -hCcEpzATBgNVHSUEDDAKBggrBgEFBQcDAjALBgNVHQ8EBAMCB4AwDQYJKoZIhvcN -AQEFBQADgYEAHEQm6uFmJcvkjlcc9rkXImJAEpCPO7JhelSUj7EgC7+jUeP6HKG+ -kjrQdkTAV4OrauQaRUmkrzkNYDL8Or7X+12Zeh+H59WrhKJekNi/+oltMiYCXjE1 -aH8x9WtRRryvcO1aCX3sskhP/sUvVgSt9sHSKuRqxIf+CDXFOMteSsQ= ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-key.pem b/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-key.pem deleted file mode 100644 index b5c15f8..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-key.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMrJBdAJTj6k/NUU -9KXoNNNrUePzYuqh8OjtxCq88E/KB9/jiPr0IZk1Dj3qsIbnxNKKgytCuOyjmWJw -gUbM/KUd0mPo6wclmuIlbRFW8hpRobY+HFcy6XssqhvMly2JLbHJXjUoTXz6ZTE+ -93Ddbgs8WK+oLiTAfk54fQqej0JDAgMBAAECgYBOFEzKp2qbMEexe9ofL2N3rDDh -xkrl8OijpzkLA6i78BxMFn4dsnZlWUpciMrjhsYAExkiRRSS+QMMJimAq1jzQqc3 -FAQV2XGYwkd0cUn7iZGvfNnEPysjsfyYQM+m+sT0ATj4BZjVShC6kkSjTdm1leLN -OSvcHdcu3Xxg9ufF0QJBAPYdnNt5sIndt2WECePuRVi+uF4mlxTobFY0fjn26yhC -4RsnhhD3Vldygo9gvnkwrAZYaALGSPBewes2InxvjA8CQQDS7erKiNXpwoqz5XiU -SVEsIIVTdWzBjGbIqMOu/hUwM5FK4j6JTBks0aTGMyh0YV9L1EzM0X79J29JahCe -iQKNAkBKNMOGqTpBV0hko1sYDk96YobUXG5RL4L6uvkUIQ7mJMQam+AgXXL7Ctuy -v0iu4a38e8tgisiTMP7nHHtpaXihAkAOiN54/lzfMsykANgCP9scE1GcoqbP34Dl -qttxH4kOPT9xzY1JoLjLYdbc4YGUI3GRpBt2sajygNkmUey7P+2xAkBBsVCZFvTw -qHvOpPS2kX5ml5xoc/QAHK9N7kR+X7XFYx82RTVSqJEK4lPb+aEWn+CjiIewO4Q5 -ksDFuNxAzbhl ------END PRIVATE KEY----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-rogue-cert.pem b/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-rogue-cert.pem deleted file mode 100644 index 21ae4bd..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-rogue-cert.pem +++ /dev/null @@ -1,73 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 2 (0x2) - Signature Algorithm: sha1WithRSAEncryption - Issuer: C=US, ST=CA, L=SanFrancisco, O=Evil Inc, OU=changeme, CN=changeme/name=changeme/emailAddress=mail@host.domain - Validity - Not Before: Feb 24 17:54:59 2014 GMT - Not After : Feb 22 17:54:59 2024 GMT - Subject: C=US, ST=CA, L=SanFrancisco, O=Fort-Funston, OU=changeme, CN=client/name=changeme/emailAddress=mail@host.domain - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - Public-Key: (1024 bit) - Modulus: - 00:e8:e2:2c:b8:d4:db:89:50:4f:47:1e:68:db:f7: - e4:cc:47:41:63:75:03:37:50:7a:a8:4d:27:36:d5: - 15:01:08:b6:cf:56:f7:56:6d:3d:f9:e2:8d:1a:5d: - bf:a0:24:5e:07:55:8e:d0:dc:f1:fa:19:87:1d:d6: - b6:58:82:2e:ba:69:6d:e9:d9:c8:16:0d:1d:59:7f: - f4:8e:58:10:01:3d:21:14:16:3c:ec:cd:8c:b7:0e: - e6:7b:77:b4:f9:90:a5:17:01:bb:84:c6:b2:12:87: - 70:eb:9f:6d:4f:d0:68:8b:96:c0:e7:0b:51:b4:9d: - 1d:7b:6c:7b:be:89:6b:88:8b - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - Easy-RSA Generated Certificate - X509v3 Subject Key Identifier: - 9E:F8:49:D0:A2:76:30:5C:AB:2B:8A:B5:8D:C6:45:1F:A7:F8:CF:85 - X509v3 Authority Key Identifier: - keyid:DC:A5:F1:76:DB:4E:CD:8E:EF:B1:23:56:1D:92:80:99:74:3B:EA:6F - DirName:/C=US/ST=CA/L=SanFrancisco/O=Evil Inc/OU=changeme/CN=changeme/name=changeme/emailAddress=mail@host.domain - serial:E7:21:1E:18:41:1B:96:83 - - X509v3 Extended Key Usage: - TLS Web Client Authentication - X509v3 Key Usage: - Digital Signature - Signature Algorithm: sha1WithRSAEncryption - 48:76:c0:18:fa:0a:ee:4e:1a:ec:02:9d:d4:83:ca:94:54:a1: - 3f:51:2f:3e:4b:95:c3:42:9b:71:a0:4b:d9:af:47:23:b9:1c: - fb:85:ba:76:e2:09:cb:65:bb:d2:7d:44:3d:4b:67:ba:80:83: - be:a8:ed:c4:b9:ea:1a:1b:c7:59:3b:d9:5c:0d:46:d8:c9:92: - cb:10:c5:f2:1a:38:a4:aa:07:2c:e3:84:16:79:c7:95:09:e3: - 01:d2:15:a2:77:0b:8b:bf:94:04:e9:7f:c0:cd:e6:2e:64:cd: - 1e:a3:32:ec:11:cc:62:ce:c7:4e:cd:ad:48:5c:b1:b8:e9:76: - b3:f9 ------BEGIN CERTIFICATE----- -MIIEDTCCA3agAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBnjELMAkGA1UEBhMCVVMx -CzAJBgNVBAgTAkNBMRUwEwYDVQQHEwxTYW5GcmFuY2lzY28xETAPBgNVBAoTCEV2 -aWwgSW5jMREwDwYDVQQLEwhjaGFuZ2VtZTERMA8GA1UEAxMIY2hhbmdlbWUxETAP -BgNVBCkTCGNoYW5nZW1lMR8wHQYJKoZIhvcNAQkBFhBtYWlsQGhvc3QuZG9tYWlu -MB4XDTE0MDIyNDE3NTQ1OVoXDTI0MDIyMjE3NTQ1OVowgaAxCzAJBgNVBAYTAlVT -MQswCQYDVQQIEwJDQTEVMBMGA1UEBxMMU2FuRnJhbmNpc2NvMRUwEwYDVQQKEwxG -b3J0LUZ1bnN0b24xETAPBgNVBAsTCGNoYW5nZW1lMQ8wDQYDVQQDEwZjbGllbnQx -ETAPBgNVBCkTCGNoYW5nZW1lMR8wHQYJKoZIhvcNAQkBFhBtYWlsQGhvc3QuZG9t -YWluMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDo4iy41NuJUE9HHmjb9+TM -R0FjdQM3UHqoTSc21RUBCLbPVvdWbT354o0aXb+gJF4HVY7Q3PH6GYcd1rZYgi66 -aW3p2cgWDR1Zf/SOWBABPSEUFjzszYy3DuZ7d7T5kKUXAbuExrISh3Drn21P0GiL -lsDnC1G0nR17bHu+iWuIiwIDAQABo4IBVTCCAVEwCQYDVR0TBAIwADAtBglghkgB -hvhCAQ0EIBYeRWFzeS1SU0EgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQW -BBSe+EnQonYwXKsrirWNxkUfp/jPhTCB0wYDVR0jBIHLMIHIgBTcpfF2207Nju+x -I1YdkoCZdDvqb6GBpKSBoTCBnjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRUw -EwYDVQQHEwxTYW5GcmFuY2lzY28xETAPBgNVBAoTCEV2aWwgSW5jMREwDwYDVQQL -EwhjaGFuZ2VtZTERMA8GA1UEAxMIY2hhbmdlbWUxETAPBgNVBCkTCGNoYW5nZW1l -MR8wHQYJKoZIhvcNAQkBFhBtYWlsQGhvc3QuZG9tYWluggkA5yEeGEEbloMwEwYD -VR0lBAwwCgYIKwYBBQUHAwIwCwYDVR0PBAQDAgeAMA0GCSqGSIb3DQEBBQUAA4GB -AEh2wBj6Cu5OGuwCndSDypRUoT9RLz5LlcNCm3GgS9mvRyO5HPuFunbiCctlu9J9 -RD1LZ7qAg76o7cS56hobx1k72VwNRtjJkssQxfIaOKSqByzjhBZ5x5UJ4wHSFaJ3 -C4u/lATpf8DN5i5kzR6jMuwRzGLOx07NrUhcsbjpdrP5 ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-rogue-key.pem b/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-rogue-key.pem deleted file mode 100644 index 53c122a..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/https/client-rogue-key.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAOjiLLjU24lQT0ce -aNv35MxHQWN1AzdQeqhNJzbVFQEIts9W91ZtPfnijRpdv6AkXgdVjtDc8foZhx3W -tliCLrppbenZyBYNHVl/9I5YEAE9IRQWPOzNjLcO5nt3tPmQpRcBu4TGshKHcOuf -bU/QaIuWwOcLUbSdHXtse76Ja4iLAgMBAAECgYADs+TmI2xCKKa6CL++D5jxrohZ -nnionnz0xBVFh+nHlG3jqgxQsXf0yydXLfpn/2wHTdLxezHVuiYt0UYg7iD0CglW -+IjcgMebzyjLeYqYOE5llPlMvhp2HoEMYJNb+7bRrZ1WCITbu+Su0w1cgA7Cs+Ej -VlfvGzN+qqnDThRUYQJBAPY0sMWZJKly8QhUmUvmcXdPczzSOf6Mm7gc5LR6wzxd -vW7syuqk50qjqVqFpN81vCV7GoDxRUWbTM9ftf7JGFkCQQDyJc/1RMygE2o+enU1 -6UBxJyclXITEYtDn8aoEpLNc7RakP1WoPUKjZOnjkcoKcIkFNkSPeCfQujrb5f3F -MkuDAkByAI/hzzmkpK5rFxEsjfX4Mve/L/DepyjrpaVY1IdWimlO1aJX6CeY7hNa -8QsYt/74s/nfvtg+lNyKIV1aLq9xAkB+WSSNgfyTeg3x08vc+Xxajmdqoz/TiQwg -OoTQL3A3iK5LvZBgXLasszcnOycFE3srcQmNItEDpGiZ3QPxJTEpAkEA45EE9NMJ -SA7EGWSFlbz4f4u4oBeiDiJRJbGGfAyVxZlpCWUjPpg9+swsWoFEOjnGYaChAMk5 -nrOdMf15T6QF7Q== ------END PRIVATE KEY----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-cert.pem b/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-cert.pem deleted file mode 100644 index 08abfd1..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-cert.pem +++ /dev/null @@ -1,76 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 4 (0x4) - Signature Algorithm: sha1WithRSAEncryption - Issuer: C=US, ST=CA, L=SanFrancisco, O=Fort-Funston, OU=changeme, CN=changeme/name=changeme/emailAddress=mail@host.domain - Validity - Not Before: Dec 4 15:01:20 2013 GMT - Not After : Dec 2 15:01:20 2023 GMT - Subject: C=US, ST=CA, L=SanFrancisco, O=Fort-Funston, OU=changeme, CN=*/name=changeme/emailAddress=mail@host.domain - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - Public-Key: (1024 bit) - Modulus: - 00:c1:ff:7d:30:6f:64:4a:b1:92:b1:71:d1:c1:74: - e2:1d:db:2d:11:24:e1:00:d4:00:ae:6f:c8:9e:ae: - 67:b3:4a:bd:f7:e6:9e:57:6d:19:4c:3c:23:94:2d: - 3d:d6:63:84:d8:fa:76:2b:38:12:c1:ed:20:9d:32: - e0:e8:c2:bf:9a:77:70:04:3f:7f:ca:8c:2c:82:d6: - 3d:25:5c:02:1a:4f:64:93:03:dd:9c:42:97:5e:09: - 49:af:f0:c2:e1:30:08:0e:21:46:95:d1:13:59:c0: - c8:76:be:94:0d:8b:43:67:21:33:b2:08:60:9d:76: - a8:05:32:1e:f9:95:09:14:75 - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Cert Type: - SSL Server - Netscape Comment: - Easy-RSA Generated Server Certificate - X509v3 Subject Key Identifier: - 14:02:FD:FD:DD:13:38:E0:71:EA:D1:BE:C0:0E:89:1A:2D:B6:19:06 - X509v3 Authority Key Identifier: - keyid:66:EE:C3:17:3D:3D:AB:44:01:6B:6F:B2:99:19:BD:AA:02:B5:34:FB - DirName:/C=US/ST=CA/L=SanFrancisco/O=Fort-Funston/OU=changeme/CN=changeme/name=changeme/emailAddress=mail@host.domain - serial:FD:AB:EC:6A:84:27:04:A7 - - X509v3 Extended Key Usage: - TLS Web Server Authentication - X509v3 Key Usage: - Digital Signature, Key Encipherment - Signature Algorithm: sha1WithRSAEncryption - 40:0f:10:39:c4:b7:0f:0d:2f:bf:d2:16:cc:8e:d3:9a:fb:8b: - ce:4b:7b:0d:48:77:ce:f1:fe:d5:8f:ea:b1:71:ed:49:1d:9f: - 23:3a:16:d4:70:7c:c5:29:bf:e4:90:34:d0:f0:00:24:f4:e4: - df:2c:c3:83:01:66:61:c9:a8:ab:29:e7:98:6d:27:89:4a:76: - c9:2e:19:8e:fe:6e:d5:f8:99:11:0e:97:67:4b:34:e3:1e:e3: - 9f:35:00:a5:32:f9:b5:2c:f2:e0:c5:2e:cc:81:bd:18:dd:5c: - 12:c8:6b:fa:0c:17:74:30:55:f6:6e:20:9a:6c:1e:09:b4:0c: - 15:42 ------BEGIN CERTIFICATE----- -MIIEKjCCA5OgAwIBAgIBBDANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMCVVMx -CzAJBgNVBAgTAkNBMRUwEwYDVQQHEwxTYW5GcmFuY2lzY28xFTATBgNVBAoTDEZv -cnQtRnVuc3RvbjERMA8GA1UECxMIY2hhbmdlbWUxETAPBgNVBAMTCGNoYW5nZW1l -MREwDwYDVQQpEwhjaGFuZ2VtZTEfMB0GCSqGSIb3DQEJARYQbWFpbEBob3N0LmRv -bWFpbjAeFw0xMzEyMDQxNTAxMjBaFw0yMzEyMDIxNTAxMjBaMIGbMQswCQYDVQQG -EwJVUzELMAkGA1UECBMCQ0ExFTATBgNVBAcTDFNhbkZyYW5jaXNjbzEVMBMGA1UE -ChMMRm9ydC1GdW5zdG9uMREwDwYDVQQLEwhjaGFuZ2VtZTEKMAgGA1UEAxQBKjER -MA8GA1UEKRMIY2hhbmdlbWUxHzAdBgkqhkiG9w0BCQEWEG1haWxAaG9zdC5kb21h -aW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMH/fTBvZEqxkrFx0cF04h3b -LREk4QDUAK5vyJ6uZ7NKvffmnldtGUw8I5QtPdZjhNj6dis4EsHtIJ0y4OjCv5p3 -cAQ/f8qMLILWPSVcAhpPZJMD3ZxCl14JSa/wwuEwCA4hRpXRE1nAyHa+lA2LQ2ch -M7IIYJ12qAUyHvmVCRR1AgMBAAGjggFzMIIBbzAJBgNVHRMEAjAAMBEGCWCGSAGG -+EIBAQQEAwIGQDA0BglghkgBhvhCAQ0EJxYlRWFzeS1SU0EgR2VuZXJhdGVkIFNl -cnZlciBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQUFAL9/d0TOOBx6tG+wA6JGi22GQYw -gdcGA1UdIwSBzzCBzIAUZu7DFz09q0QBa2+ymRm9qgK1NPuhgaikgaUwgaIxCzAJ -BgNVBAYTAlVTMQswCQYDVQQIEwJDQTEVMBMGA1UEBxMMU2FuRnJhbmNpc2NvMRUw -EwYDVQQKEwxGb3J0LUZ1bnN0b24xETAPBgNVBAsTCGNoYW5nZW1lMREwDwYDVQQD -EwhjaGFuZ2VtZTERMA8GA1UEKRMIY2hhbmdlbWUxHzAdBgkqhkiG9w0BCQEWEG1h -aWxAaG9zdC5kb21haW6CCQD9q+xqhCcEpzATBgNVHSUEDDAKBggrBgEFBQcDATAL -BgNVHQ8EBAMCBaAwDQYJKoZIhvcNAQEFBQADgYEAQA8QOcS3Dw0vv9IWzI7TmvuL -zkt7DUh3zvH+1Y/qsXHtSR2fIzoW1HB8xSm/5JA00PAAJPTk3yzDgwFmYcmoqynn -mG0niUp2yS4Zjv5u1fiZEQ6XZ0s04x7jnzUApTL5tSzy4MUuzIG9GN1cEshr+gwX -dDBV9m4gmmweCbQMFUI= ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-key.pem b/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-key.pem deleted file mode 100644 index c269320..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-key.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAMH/fTBvZEqxkrFx -0cF04h3bLREk4QDUAK5vyJ6uZ7NKvffmnldtGUw8I5QtPdZjhNj6dis4EsHtIJ0y -4OjCv5p3cAQ/f8qMLILWPSVcAhpPZJMD3ZxCl14JSa/wwuEwCA4hRpXRE1nAyHa+ -lA2LQ2chM7IIYJ12qAUyHvmVCRR1AgMBAAECgYAmwckb9RUfSwyYgLm8IYLPHiuJ -wkllZfVg5Bo7gXJcQnFjZmJ56uTj8xvUjZlODIHM63TSO5ibv6kFXtXKCqZGd2M+ -wGbhZ0f+2GvKcwMmJERnIQjuoNaYSQLT0tM0VB9Iz0rJlZC+tzPZ+5pPqEumRdsS -IzWNXfF42AhcbwAQYQJBAPVXtMYIJc9EZsz86ZcQiMPWUpCX5vnRmtwL8kKyR8D5 -4KfYeiowyFffSRMMcclwNHq7TgSXN+nIXM9WyzyzwikCQQDKbNA28AgZp9aT54HP -WnbeE2pmt+uk/zl/BtxJSoK6H+69Jec+lf7EgL7HgOWYRSNot4uQWu8IhsHLTiUq -+0FtAkEAqwlRxRy4/x24bP+D+QRV0/D97j93joFJbE4Hved7jlSlAV4xDGilwlyv -HNB4Iu5OJ6Gcaibhm+FKkmD3noHSwQJBAIpu3fokLzX0bS+bDFBU6qO3HXX/47xj -+tsfQvkwZrSI8AkU6c8IX0HdVhsz0FBRQAT2ORDQz1XCarfxykNZrwUCQQCGCBIc -BBCWzhHlswlGidWJg3HqqO6hPPClEr3B5G87oCsdeYwiO23XT6rUnoJXfJHp6oCW -5nCwDu5ZTP+khltg ------END PRIVATE KEY----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-rogue-cert.pem b/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-rogue-cert.pem deleted file mode 100644 index 28feba6..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-rogue-cert.pem +++ /dev/null @@ -1,76 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 3 (0x3) - Signature Algorithm: sha1WithRSAEncryption - Issuer: C=US, ST=CA, L=SanFrancisco, O=Evil Inc, OU=changeme, CN=changeme/name=changeme/emailAddress=mail@host.domain - Validity - Not Before: Feb 28 18:49:31 2014 GMT - Not After : Feb 26 18:49:31 2024 GMT - Subject: C=US, ST=CA, L=SanFrancisco, O=Fort-Funston, OU=changeme, CN=localhost/name=changeme/emailAddress=mail@host.domain - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - Public-Key: (1024 bit) - Modulus: - 00:d1:08:58:24:60:a1:69:65:4b:76:46:8f:88:75: - 7c:49:3a:d8:03:cc:5b:58:c5:d1:bb:e5:f9:54:b9: - 75:65:df:7e:bb:fb:54:d4:b2:e9:6f:58:a2:a4:84: - 43:94:77:24:81:38:36:36:f0:66:65:26:e5:5b:2a: - 14:1c:a9:ae:57:7f:75:00:23:14:4b:61:58:e4:82: - aa:15:97:94:bd:50:35:0d:5d:18:18:ed:10:6a:bb: - d3:64:5a:eb:36:98:5b:58:a7:fe:67:48:c1:6c:3f: - 51:2f:02:65:96:54:77:9b:34:f9:a7:d2:63:54:6a: - 9e:02:5c:be:65:98:a4:b4:b5 - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Cert Type: - SSL Server - Netscape Comment: - Easy-RSA Generated Server Certificate - X509v3 Subject Key Identifier: - 1F:E0:57:CA:CB:76:C9:C4:86:B9:EA:69:17:C0:F3:51:CE:95:40:EC - X509v3 Authority Key Identifier: - keyid:DC:A5:F1:76:DB:4E:CD:8E:EF:B1:23:56:1D:92:80:99:74:3B:EA:6F - DirName:/C=US/ST=CA/L=SanFrancisco/O=Evil Inc/OU=changeme/CN=changeme/name=changeme/emailAddress=mail@host.domain - serial:E7:21:1E:18:41:1B:96:83 - - X509v3 Extended Key Usage: - TLS Web Server Authentication - X509v3 Key Usage: - Digital Signature, Key Encipherment - Signature Algorithm: sha1WithRSAEncryption - 04:93:0e:28:01:94:18:f0:8c:7c:d3:0c:ad:e9:b7:46:b1:30: - 65:ed:68:7c:8c:91:cd:1a:86:66:87:4a:4f:c0:97:bc:f7:85: - 4b:38:79:31:b2:65:88:b1:76:16:9e:80:93:38:f4:b9:eb:65: - 00:6d:bb:89:e0:a1:bf:95:5e:80:13:8e:01:73:d3:f1:08:73: - 85:a5:33:75:0b:42:8a:a3:07:09:35:ef:d7:c6:58:eb:60:a3: - 06:89:a0:53:99:e2:aa:41:90:e0:1a:d2:12:4b:48:7d:c3:9c: - ad:bd:0e:5e:5f:f7:09:0c:5d:7c:86:24:dd:92:d5:b3:14:06: - c7:9f ------BEGIN CERTIFICATE----- -MIIEKjCCA5OgAwIBAgIBAzANBgkqhkiG9w0BAQUFADCBnjELMAkGA1UEBhMCVVMx -CzAJBgNVBAgTAkNBMRUwEwYDVQQHEwxTYW5GcmFuY2lzY28xETAPBgNVBAoTCEV2 -aWwgSW5jMREwDwYDVQQLEwhjaGFuZ2VtZTERMA8GA1UEAxMIY2hhbmdlbWUxETAP -BgNVBCkTCGNoYW5nZW1lMR8wHQYJKoZIhvcNAQkBFhBtYWlsQGhvc3QuZG9tYWlu -MB4XDTE0MDIyODE4NDkzMVoXDTI0MDIyNjE4NDkzMVowgaMxCzAJBgNVBAYTAlVT -MQswCQYDVQQIEwJDQTEVMBMGA1UEBxMMU2FuRnJhbmNpc2NvMRUwEwYDVQQKEwxG -b3J0LUZ1bnN0b24xETAPBgNVBAsTCGNoYW5nZW1lMRIwEAYDVQQDEwlsb2NhbGhv -c3QxETAPBgNVBCkTCGNoYW5nZW1lMR8wHQYJKoZIhvcNAQkBFhBtYWlsQGhvc3Qu -ZG9tYWluMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRCFgkYKFpZUt2Ro+I -dXxJOtgDzFtYxdG75flUuXVl3367+1TUsulvWKKkhEOUdySBODY28GZlJuVbKhQc -qa5Xf3UAIxRLYVjkgqoVl5S9UDUNXRgY7RBqu9NkWus2mFtYp/5nSMFsP1EvAmWW -VHebNPmn0mNUap4CXL5lmKS0tQIDAQABo4IBbzCCAWswCQYDVR0TBAIwADARBglg -hkgBhvhCAQEEBAMCBkAwNAYJYIZIAYb4QgENBCcWJUVhc3ktUlNBIEdlbmVyYXRl -ZCBTZXJ2ZXIgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFB/gV8rLdsnEhrnqaRfA81HO -lUDsMIHTBgNVHSMEgcswgciAFNyl8XbbTs2O77EjVh2SgJl0O+pvoYGkpIGhMIGe -MQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFTATBgNVBAcTDFNhbkZyYW5jaXNj -bzERMA8GA1UEChMIRXZpbCBJbmMxETAPBgNVBAsTCGNoYW5nZW1lMREwDwYDVQQD -EwhjaGFuZ2VtZTERMA8GA1UEKRMIY2hhbmdlbWUxHzAdBgkqhkiG9w0BCQEWEG1h -aWxAaG9zdC5kb21haW6CCQDnIR4YQRuWgzATBgNVHSUEDDAKBggrBgEFBQcDATAL -BgNVHQ8EBAMCBaAwDQYJKoZIhvcNAQEFBQADgYEABJMOKAGUGPCMfNMMrem3RrEw -Ze1ofIyRzRqGZodKT8CXvPeFSzh5MbJliLF2Fp6Akzj0uetlAG27ieChv5VegBOO -AXPT8QhzhaUzdQtCiqMHCTXv18ZY62CjBomgU5niqkGQ4BrSEktIfcOcrb0OXl/3 -CQxdfIYk3ZLVsxQGx58= ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-rogue-key.pem b/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-rogue-key.pem deleted file mode 100644 index 10f7c65..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/https/server-rogue-key.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBANEIWCRgoWllS3ZG -j4h1fEk62APMW1jF0bvl+VS5dWXffrv7VNSy6W9YoqSEQ5R3JIE4NjbwZmUm5Vsq -FByprld/dQAjFEthWOSCqhWXlL1QNQ1dGBjtEGq702Ra6zaYW1in/mdIwWw/US8C -ZZZUd5s0+afSY1RqngJcvmWYpLS1AgMBAAECgYAJXh9dGfuB1qlIFqduDR3RxlJR -8UGSu+LHUeoXkuwg8aAjWoMVuSLe+5DmYIsKx0AajmNXmPRtyg1zRXJ7SltmubJ8 -6qQVDsRk6biMdkpkl6a9Gk2av40psD9/VPGxagEoop7IKYhf3AeKPvPiwVB2qFrl -1aYMZm0aMR55pgRajQJBAOk8IsJDf0beooDZXVdv/oe4hcbM9fxO8Cn3qzoGImqD -37LL+PCzDP7AEV3fk43SsZDeSk+LDX+h0o9nPyhzHasCQQDlb3aDgcQY9NaGLUWO -moOCB3148eBVcAwCocu+OSkf7sbQdvXxgThBOrZl11wwRIMQqh99c2yeUwj+tELl -3VcfAkBZTiNpCvtDIaBLge9RuZpWUXs3wec2cutWxnSTxSGMc25GQf/R+l0xdk2w -ChmvpktDUzpU9sN2aXn8WuY+EMX9AkEApbLpUbKPUELLB958RLA819TW/lkZXjrs -wZ3eSoR3ufM1rOqtVvyvBxUDE+wETWu9iHSFB5Ir2PA5J9JCGkbPmwJAFI1ndfBj -iuyU93nFX0p+JE2wVHKx4dMzKCearNKiJh/lGDtUq3REGgamTNUnG8RAITUbxFs+ -Z1hrIq8xYl2LOQ== ------END PRIVATE KEY----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/load/emptyLayer.tar b/vendor/github.com/docker/docker/integration-cli/fixtures/load/emptyLayer.tar deleted file mode 100644 index beabb56..0000000 Binary files a/vendor/github.com/docker/docker/integration-cli/fixtures/load/emptyLayer.tar and /dev/null differ diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/load/frozen.go b/vendor/github.com/docker/docker/integration-cli/fixtures/load/frozen.go deleted file mode 100644 index 13cd393..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/load/frozen.go +++ /dev/null @@ -1,182 +0,0 @@ -package load - -import ( - "bufio" - "bytes" - "os" - "os/exec" - "path/filepath" - "strings" - "sync" - - "github.com/pkg/errors" -) - -var frozenImgDir = "/docker-frozen-images" - -// FrozenImagesLinux loads the frozen image set for the integration suite -// If the images are not available locally it will download them -// TODO: This loads whatever is in the frozen image dir, regardless of what -// images were passed in. If the images need to be downloaded, then it will respect -// the passed in images -func FrozenImagesLinux(dockerBinary string, images ...string) error { - imgNS := os.Getenv("TEST_IMAGE_NAMESPACE") - var loadImages []struct{ srcName, destName string } - for _, img := range images { - if err := exec.Command(dockerBinary, "inspect", "--type=image", img).Run(); err != nil { - srcName := img - // hello-world:latest gets re-tagged as hello-world:frozen - // there are some tests that use hello-world:latest specifically so it pulls - // the image and hello-world:frozen is used for when we just want a super - // small image - if img == "hello-world:frozen" { - srcName = "hello-world:latest" - } - if imgNS != "" { - srcName = imgNS + "/" + srcName - } - loadImages = append(loadImages, struct{ srcName, destName string }{ - srcName: srcName, - destName: img, - }) - } - } - if len(loadImages) == 0 { - // everything is loaded, we're done - return nil - } - - fi, err := os.Stat(frozenImgDir) - if err != nil || !fi.IsDir() { - srcImages := make([]string, 0, len(loadImages)) - for _, img := range loadImages { - srcImages = append(srcImages, img.srcName) - } - if err := pullImages(dockerBinary, srcImages); err != nil { - return errors.Wrap(err, "error pulling image list") - } - } else { - if err := loadFrozenImages(dockerBinary); err != nil { - return err - } - } - - for _, img := range loadImages { - if img.srcName != img.destName { - if out, err := exec.Command(dockerBinary, "tag", img.srcName, img.destName).CombinedOutput(); err != nil { - return errors.Errorf("%v: %s", err, string(out)) - } - if out, err := exec.Command(dockerBinary, "rmi", img.srcName).CombinedOutput(); err != nil { - return errors.Errorf("%v: %s", err, string(out)) - } - } - } - return nil -} - -func loadFrozenImages(dockerBinary string) error { - tar, err := exec.LookPath("tar") - if err != nil { - return errors.Wrap(err, "could not find tar binary") - } - tarCmd := exec.Command(tar, "-cC", frozenImgDir, ".") - out, err := tarCmd.StdoutPipe() - if err != nil { - return errors.Wrap(err, "error getting stdout pipe for tar command") - } - - errBuf := bytes.NewBuffer(nil) - tarCmd.Stderr = errBuf - tarCmd.Start() - defer tarCmd.Wait() - - cmd := exec.Command(dockerBinary, "load") - cmd.Stdin = out - if out, err := cmd.CombinedOutput(); err != nil { - return errors.Errorf("%v: %s", err, string(out)) - } - return nil -} - -func pullImages(dockerBinary string, images []string) error { - cwd, err := os.Getwd() - if err != nil { - return errors.Wrap(err, "error getting path to dockerfile") - } - dockerfile := os.Getenv("DOCKERFILE") - if dockerfile == "" { - dockerfile = "Dockerfile" - } - dockerfilePath := filepath.Join(filepath.Dir(filepath.Clean(cwd)), dockerfile) - pullRefs, err := readFrozenImageList(dockerfilePath, images) - if err != nil { - return errors.Wrap(err, "error reading frozen image list") - } - - var wg sync.WaitGroup - chErr := make(chan error, len(images)) - for tag, ref := range pullRefs { - wg.Add(1) - go func(tag, ref string) { - defer wg.Done() - if out, err := exec.Command(dockerBinary, "pull", ref).CombinedOutput(); err != nil { - chErr <- errors.Errorf("%v: %s", string(out), err) - return - } - if out, err := exec.Command(dockerBinary, "tag", ref, tag).CombinedOutput(); err != nil { - chErr <- errors.Errorf("%v: %s", string(out), err) - return - } - if out, err := exec.Command(dockerBinary, "rmi", ref).CombinedOutput(); err != nil { - chErr <- errors.Errorf("%v: %s", string(out), err) - return - } - }(tag, ref) - } - wg.Wait() - close(chErr) - return <-chErr -} - -func readFrozenImageList(dockerfilePath string, images []string) (map[string]string, error) { - f, err := os.Open(dockerfilePath) - if err != nil { - return nil, errors.Wrap(err, "error reading dockerfile") - } - defer f.Close() - ls := make(map[string]string) - - scanner := bufio.NewScanner(f) - for scanner.Scan() { - line := strings.Fields(scanner.Text()) - if len(line) < 3 { - continue - } - if !(line[0] == "RUN" && line[1] == "./contrib/download-frozen-image-v2.sh") { - continue - } - - frozenImgDir = line[2] - if line[2] == frozenImgDir { - frozenImgDir = filepath.Join(os.Getenv("DEST"), "frozen-images") - } - - for scanner.Scan() { - img := strings.TrimSpace(scanner.Text()) - img = strings.TrimSuffix(img, "\\") - img = strings.TrimSpace(img) - split := strings.Split(img, "@") - if len(split) < 2 { - break - } - - for _, i := range images { - if split[0] == i { - ls[i] = img - break - } - } - } - } - return ls, nil -} diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey1.crt b/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey1.crt deleted file mode 100644 index 2218f23..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey1.crt +++ /dev/null @@ -1,21 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDhTCCAm2gAwIBAgIJAP2EcMN2UXPcMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNV -BAYTAlVTMQswCQYDVQQIEwJDQTEVMBMGA1UEBxMMU2FuRnJhbmNpc2NvMQ8wDQYD -VQQKEwZEb2NrZXIxEzARBgNVBAMTCmRlbGVnYXRpb24wHhcNMTYwOTI4MTc0ODQ4 -WhcNMjYwNjI4MTc0ODQ4WjBXMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFTAT -BgNVBAcTDFNhbkZyYW5jaXNjbzEPMA0GA1UEChMGRG9ja2VyMRMwEQYDVQQDEwpk -ZWxlZ2F0aW9uMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvgewhaYs -Ke5s2AM7xxKrT4A6n7hW17qSnBjonCcPcwTFmYqIOdxWjYITgJuHrTwB4ZhBqWS7 -tTsUUu6hWLMeB7Uo5/GEQAAZspKkT9G/rNKF9lbWK9PPhGGkeR01c/Q932m92Hsn -fCQ0Pp/OzD3nVTh0v9HKk+PObNMOCcqG87eYs4ylPRxs0RrE/rP+bEGssKQSbeCZ -wazDnO+kiatVgKQZ2CK23iFdRE1z2rzqVDeaFWdvBqrRdWnkOZClhlLgEQ5nK2yV -B6tSqOiI3MmHyHzIkGOQJp2/s7Pe0ckEkzsjTsJW8oKHlBBl6pRxHIKzNN4VFbeB -vvYvrogrDrC/owIDAQABo1QwUjAMBgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIF -oDATBgNVHSUEDDAKBggrBgEFBQcDAzAdBgNVHQ4EFgQUFoHfukRa6qGk1ncON64Z -ASKlZdkwDQYJKoZIhvcNAQELBQADggEBAEq9Adpd03CPmpbRtTAJGAkjjLFr60sV -2r+/l/m9R31ZCN9ymM9nxToQ8zfMdeAh/nnPcErziil2gDVqXueCNDkRj09tmDIE -Q1Oc92uyNZNgcECow77cKZCTZSTku+qsJrYaykH5vSnia8ltcKj8inJedIcpBR+p -608HEQvF0Eg5eaLPJwH48BCb0Gqdri1dJgrNnqptz7MDr8M+u7tHVulbAd3YxLlq -JH1W2bkVUx6esbn/MUE5HL5iTuOYREEINvBSmLdmmFkampmCnCB/bDEyJeL9bAkt -ZPIi0UNSnqFKLSP1Vf8AGLXt6iO7+1OGvtsDXEEYdXVOMsSXZtUuT7A= ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey1.key b/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey1.key deleted file mode 100644 index cb37efc..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey1.key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAvgewhaYsKe5s2AM7xxKrT4A6n7hW17qSnBjonCcPcwTFmYqI -OdxWjYITgJuHrTwB4ZhBqWS7tTsUUu6hWLMeB7Uo5/GEQAAZspKkT9G/rNKF9lbW -K9PPhGGkeR01c/Q932m92HsnfCQ0Pp/OzD3nVTh0v9HKk+PObNMOCcqG87eYs4yl -PRxs0RrE/rP+bEGssKQSbeCZwazDnO+kiatVgKQZ2CK23iFdRE1z2rzqVDeaFWdv -BqrRdWnkOZClhlLgEQ5nK2yVB6tSqOiI3MmHyHzIkGOQJp2/s7Pe0ckEkzsjTsJW -8oKHlBBl6pRxHIKzNN4VFbeBvvYvrogrDrC/owIDAQABAoIBAB/o8KZwsgfUhqh7 -WoViSCwQb0e0z7hoFwhpUl4uXPTGf1v6HEgDDPG0PwwgkdbwNaypQZVtWevj4NTQ -R326jjdjH1xbfQa2PZpz722L3jDqJR6plEtFxRoIv3KrCffPsrgabIu2mnnJJpDB -ixtW5cq0sT4ov2i4H0i85CWWwbSY/G/MHsvCuK9PhoCj9uToVqrf1KrAESE5q4fh -mPSYUL99KVnj7SZkUz+79rc8sLLPVks3szZACMlm1n05ZTj/d6Nd2ZZUO45DllIj -1XJghfWmnChrB/P/KYXgQ3Y9BofIAw1ra2y3wOZeqRFNsbmojcGldfdtN/iQzhEj -uk4ThokCgYEA9FTmv36N8qSPWuqX/KzkixDQ8WrDGohcB54kK98Wx4ijXx3i38SY -tFjO8YUS9GVo1+UgmRjZbzVX7xeum6+TdBBwOjNOxEQ4tzwiQBWDdGpli8BccdJ2 -OOIVxSslWhiUWfpYloXVetrR88iHbT882g795pbonDaJdXSLnij4UW8CgYEAxxrr -QFpsmOEZvI/yPSOGdG7A1RIsCeH+cEOf4cKghs7+aCtAHlIweztNOrqirl3oKI1r -I0zQl46WsaW8S/y99v9lmmnZbWwqLa4vIu0NWs0zaZdzKZw3xljMhgp4Ge69hHa2 -utCtAxcX+7q/yLlHoTiYwKdxX54iLkheCB8csw0CgYEAleEG820kkjXUIodJ2JwO -Tihwo8dEC6CeI6YktizRgnEVFqH0rCOjMO5Rc+KX8AfNOrK5PnD54LguSuKSH7qi -j04OKgWTSd43lF90+y63RtCFnibQDpp2HwrBJAQFk7EEP/XMJfnPLN/SbuMSADgM -kg8kPTFRW5Iw3DYz9z9WpE0CgYAkn6/8Q2XMbUOFqti9JEa8Lg8sYk5VdwuNbPMA -3QMYKQUk9ieyLB4c3Nik3+XCuyVUKEc31A5egmz3umu7cn8i6vGuiJ/k/8t2YZ7s -Bry5Ihu95Yzab5DW3Eiqs0xKQN79ebS9AluAwQO5Wy2h52rknfuDHIm/M+BHsSoS -xl5KFQKBgQCokCsYuX1z2GojHw369/R2aX3ovCGuHqy4k7fWxUrpHTHvth2+qNPr -84qLJ9rLWoZE5sUiZ5YdwCgW877EdfkT+v4aaBX79ixso5VdqgJ/PdnoNntah/Vq -njQiW1skn6/P5V/eyimN2n0VsyBr/zMDEtYTRP/Tb1zi/njFLQkZEA== ------END RSA PRIVATE KEY----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey2.crt b/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey2.crt deleted file mode 100644 index bec0847..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey2.crt +++ /dev/null @@ -1,21 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDhTCCAm2gAwIBAgIJAIq8naKlYAQfMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNV -BAYTAlVTMQswCQYDVQQIEwJDQTEVMBMGA1UEBxMMU2FuRnJhbmNpc2NvMQ8wDQYD -VQQKEwZEb2NrZXIxEzARBgNVBAMTCmRlbGVnYXRpb24wHhcNMTYwOTI4MTc0ODQ4 -WhcNMjYwNjI4MTc0ODQ4WjBXMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFTAT -BgNVBAcTDFNhbkZyYW5jaXNjbzEPMA0GA1UEChMGRG9ja2VyMRMwEQYDVQQDEwpk -ZWxlZ2F0aW9uMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyY2EWYTW -5VHipw08t675upmD6a+akiuZ1z+XpuOxZCgjZ0aHfoOe8wGKg3Ohz7UCBdD5Mob/ -L/qvRlsCaqPHGZKIyyX1HDO4mpuQQFBhYxt+ZAO3AaawEUOw2rwwMDEjLnDDTSZM -z8jxCMvsJjBDqgb8g3z+AmjducQ/OH6llldgHIBY8ioRbROCL2PGgqywWq2fThav -c70YMxtKviBGDNCouYeQ8JMK/PuLwPNDXNQAagFHVARXiUv/ILHk7ImYnSGJUcuk -JTUGN2MBnpY0eakg7i+4za8sjjqOdn+2I6aVzlGJDSiRP72nkg/cE4BqMl9FrMwK -9iS8xa9yMDLUvwIDAQABo1QwUjAMBgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIF -oDATBgNVHSUEDDAKBggrBgEFBQcDAzAdBgNVHQ4EFgQUvQzzFmh3Sv3HcdExY3wx -/1u6JLAwDQYJKoZIhvcNAQELBQADggEBAJcmDme2Xj/HPUPwaN/EyCmjhY73EiHO -x6Pm16tscg5JGn5A+u3CZ1DmxUYl8Hp6MaW/sWzdtL0oKJg76pynadCWh5EacFR8 -u+2GV/IcN9mSX6JQzvrqbjSqo5/FehqBD+W5h3euwwApWA3STAadYeyEfmdOA3SQ -W1vzrA1y7i8qgTqeJ7UX1sEAXlIhBK2zPYaMB+en+ZOiPyNxJYj6IDdGdD2paC9L -6H9wKC+GAUTSdCWp89HP7ETSXEGr94AXkrwU+qNsiN+OyK8ke0EMngEPh5IQoplw -/7zEZCth3oKxvR1/4S5LmTVaHI2ZlbU4q9bnY72G4tw8YQr2gcBGo4w= ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey2.key b/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey2.key deleted file mode 100644 index 5ccabe9..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey2.key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEAyY2EWYTW5VHipw08t675upmD6a+akiuZ1z+XpuOxZCgjZ0aH -foOe8wGKg3Ohz7UCBdD5Mob/L/qvRlsCaqPHGZKIyyX1HDO4mpuQQFBhYxt+ZAO3 -AaawEUOw2rwwMDEjLnDDTSZMz8jxCMvsJjBDqgb8g3z+AmjducQ/OH6llldgHIBY -8ioRbROCL2PGgqywWq2fThavc70YMxtKviBGDNCouYeQ8JMK/PuLwPNDXNQAagFH -VARXiUv/ILHk7ImYnSGJUcukJTUGN2MBnpY0eakg7i+4za8sjjqOdn+2I6aVzlGJ -DSiRP72nkg/cE4BqMl9FrMwK9iS8xa9yMDLUvwIDAQABAoIBAHmffvzx7ydESWwa -zcfdu26BkptiTvjjfJrqEd4wSewxWGPKqJqMXE8xX99A2KTZClZuKuH1mmnecQQY -iRXGrK9ewFMuHYGeKEiLlPlqR8ohXhyGLVm+t0JDwaXMp5t9G0i73O5iLTm5fNGd -FGxa9YnVW20Q8MqNczbVGH1D1zInhxzzOyFzBd4bBBJ8PdrUdyLpd7+RxY2ghnbT -p9ZANR2vk5zmDLJgZx72n/u+miJWuhY6p0v3Vq4z/HHgdhf+K6vpDdzTcYlA0rO4 -c/c+RKED3ZadGUD5QoLsmEN0e3FVSMPN1kt4ZRTqWfH8f2X4mLz33aBryTjktP6+ -1rX6ThECgYEA74wc1Tq23B5R0/GaMm1AK3Ko2zzTD8wK7NSCElh2dls02B+GzrEB -aE3A2GMQSuzb+EA0zkipwANBaqs3ZemH5G1pu4hstQsXCMd4jAJn0TmTXlplXBCf -PSc8ZUU6XcJENRr9Q7O9/TGlgahX+z0ndxYx/CMCsSu7XsMg4IZsbAcCgYEA12Vb -wKOVG15GGp7pMshr+2rQfVimARUP4gf3JnQmenktI4PfdnMW3a4L3DEHfLhIerwT -6lRp/NpxSADmuT4h1UO1l2lc+gmTVPw0Vbl6VwHpgS5Kfu4ZyM6n3S66f/dE4nu7 -hQF9yZz7vn5Agghak4p6a1wC1gdMzR1tvxFzk4kCgYByBMTskWfcWeok8Yitm+bB -R3Ar+kWT7VD97SCETusD5uG+RTNLSmEbHnc+B9kHcLo67YS0800pAeOvPBPARGnU -RmffRU5I1iB+o0MzkSmNItSMQoagTaEd4IEUyuC/I+qHRHNsOC+kRm86ycAm67LP -MhdUpe1wGxqyPjp15EXTHQKBgDKzFu+3EWfJvvKRKQ7dAh3BvKVkcl6a2Iw5l8Ej -YdM+JpPPfI/i8yTmzL/dgoem0Nii4IUtrWzo9fUe0TAVId2S/HFRSaNJEbbVTnRH -HjbQqmfPv5U08jjD+9siHp/0UfCFc1QRT8xe+RqTmReCY9+KntoaZEiAm2FEZgqt -TukRAoGAf7QqbTP5/UH1KSkX89F5qy/6GS3pw6TLj9Ufm/l/NO8Um8gag6YhEKWR -7HpkpCqjfWj8Av8ESR9cqddPGrbdqXFm9z7dCjlAd5T3Q3h/h+v+JzLQWbsI6WOb -SsOSWNyE006ZZdIiFwO6GfxpLI24sVtYKgyob6Q71oxSqfnrnT0= ------END RSA PRIVATE KEY----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey3.crt b/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey3.crt deleted file mode 100644 index f434b45..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey3.crt +++ /dev/null @@ -1,21 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDhTCCAm2gAwIBAgIJAKHt/jxiWqMtMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNV -BAYTAlVTMQswCQYDVQQIEwJDQTEVMBMGA1UEBxMMU2FuRnJhbmNpc2NvMQ8wDQYD -VQQKEwZEb2NrZXIxEzARBgNVBAMTCmRlbGVnYXRpb24wHhcNMTYwOTI4MTc0ODQ5 -WhcNMjYwNjI4MTc0ODQ5WjBXMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFTAT -BgNVBAcTDFNhbkZyYW5jaXNjbzEPMA0GA1UEChMGRG9ja2VyMRMwEQYDVQQDEwpk -ZWxlZ2F0aW9uMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqfbJk2Dk -C9FJVjV2+Q2CQrJphG3vFc1Qlu9jgVA5RhGmF9jJzetsclsV/95nBhinIGcSmPQA -l318G7Bz/cG/6O2n5+hj+S1+YOvQweReZj3d4kCeS86SOyLNTpMD9gsF0S8nR1RN -h0jD4t1vxAVeGD1o61U8/k0O5eDoeOfOSWZagKk5PhyrMZgNip4IrG46umCkFlrw -zMMcgQdwTQXywPqkr/LmYpqT1WpMlzHYTQEY8rKorIJQbPtHVYdr4UxYnNmk6fbU -biEP1DQlwjBWcFTsDLqXKP/K+e3O0/e/hMB0y7Tj9fZ7Viw0t5IKXZPsxMhwknUT -9vmPzIJO6NiniwIDAQABo1QwUjAMBgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIF -oDATBgNVHSUEDDAKBggrBgEFBQcDAzAdBgNVHQ4EFgQUdTXRP1EzxQ+UDZSoheVo -Mobud1cwDQYJKoZIhvcNAQELBQADggEBADV9asTWWdbmpkeRuKyi0xGho39ONK88 -xxkFlco766BVgemo/rGQj3oPuw6M6SzHFoJ6JUPjmLiAQDIGEU/2/b6LcOuLjP+4 -YejCcDTY3lSW/HMNoAmzr2foo/LngNGfe/qhVFUqV7GjFT9+XzFFBfIZ1cQiL2ed -kc8rgQxFPwWXFCSwaENWeFnMDugkd+7xanoAHq8GsJpg5fTruDTmJkUqC2RNiMLn -WM7QaqW7+lmUnMnc1IBoz0hFhgoiadWM/1RQxx51zTVw6Au1koIm4ZXu5a+/WyC8 -K1+HyUbc0AVaDaRBpRSOR9aHRwLGh6WQ4aUZQNyJroc999qfYrDEEV8= ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey3.key b/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey3.key deleted file mode 100644 index a61d18c..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey3.key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpQIBAAKCAQEAqfbJk2DkC9FJVjV2+Q2CQrJphG3vFc1Qlu9jgVA5RhGmF9jJ -zetsclsV/95nBhinIGcSmPQAl318G7Bz/cG/6O2n5+hj+S1+YOvQweReZj3d4kCe -S86SOyLNTpMD9gsF0S8nR1RNh0jD4t1vxAVeGD1o61U8/k0O5eDoeOfOSWZagKk5 -PhyrMZgNip4IrG46umCkFlrwzMMcgQdwTQXywPqkr/LmYpqT1WpMlzHYTQEY8rKo -rIJQbPtHVYdr4UxYnNmk6fbUbiEP1DQlwjBWcFTsDLqXKP/K+e3O0/e/hMB0y7Tj -9fZ7Viw0t5IKXZPsxMhwknUT9vmPzIJO6NiniwIDAQABAoIBAQCAr/ed3A2umO7T -FDYZik3nXBiiiW4t7r+nGGgZ3/kNgY1lnuHlROxehXLZwbX1mrLnyML/BjhwezV9 -7ZNVPd6laVPpNj6DyxtWHRZ5yARlm1Al39E7CpQTrF0QsiWcpGnqIa62xjDRTpnq -askV/Q5qggyvqmE9FnFCQpEiAjlhvp7F0kVHVJm9s3MK3zSyR0UTZ3cpYus2Jr2z -OotHgAMHq5Hgb3dvxOeE2xRMeYAVDujbkNzXm2SddAtiRdLhWDh7JIr3zXhp0HyN -4rLOyhlgz00oIGeDt/C0q3fRmghr3iZOG+7m2sUx0FD1Ru1dI9v2A+jYmIVNW6+x -YJk5PzxJAoGBANDj7AGdcHSci/LDBPoTTUiz3uucAd27/IJma/iy8mdbVfOAb0Fy -PRSPvoozlpZyOxg2J4eH/o4QxQR4lVKtnLKZLNHK2tg3LarwyBX1LiI3vVlB+DT1 -AmV8i5bJAckDhqFeEH5qdWZFi03oZsSXWEqX5iMYCrdK5lTZggcrFZeHAoGBANBL -fkk3knAdcVfTYpmHx18GBi2AsCWTd20KD49YBdbVy0Y2Jaa1EJAmGWpTUKdYx40R -H5CuGgcAviXQz3bugdTU1I3tAclBtpJNU7JkhuE+Epz0CM/6WERJrE0YxcGQA5ui -6fOguFyiXD1/85jrDBOKy74aoS7lYz9r/a6eqmjdAoGBAJpm/nmrIAZx+Ff2ouUe -A1Ar9Ch/Zjm5zEmu3zwzOU4AiyWz14iuoktifNq2iyalRNz+mnVpplToPFizsNwu -C9dPtXtU0DJlhtIFrD/evLz6KnGhe4/ZUm4lgyBvb2xfuNHqL5Lhqelwmil6EQxb -Oh3Y7XkfOjyFln89TwlxZUJdAoGAJRMa4kta7EvBTeGZLjyltvsqhFTghX+vBSCC -ToBbYbbiHJgssXSPAylU4sD7nR3HPwuqM6VZip+OOMrm8oNXZpuPTce+xqTEq1vK -JvmPrG3RAFDLdMFZjqYSXhKnuGE60yv3Ol8EEbDwfB3XLQPBPYU56Jdy0xcPSE2f -dMJXEJ0CgYEAisZw0nXw6lFeYecu642EGuU0wv1O9i21p7eho9QwOcsoTl4Q9l+M -M8iBv+qTHO+D19l4JbkGvy2H2diKoYduUFACcuiFYs8fjrT+4Z6DyOQAQGAf6Ylw -BFbU15k6KbA9v4mZDfd1tY9x62L/XO55ZxYG+J+q0e26tEThgD8cEog= ------END RSA PRIVATE KEY----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey4.crt b/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey4.crt deleted file mode 100644 index c8cbe46..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey4.crt +++ /dev/null @@ -1,21 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDhTCCAm2gAwIBAgIJANae++ZkUEWMMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNV -BAYTAlVTMQswCQYDVQQIEwJDQTEVMBMGA1UEBxMMU2FuRnJhbmNpc2NvMQ8wDQYD -VQQKEwZEb2NrZXIxEzARBgNVBAMTCmRlbGVnYXRpb24wHhcNMTYwOTI4MTc0ODQ5 -WhcNMjYwNjI4MTc0ODQ5WjBXMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFTAT -BgNVBAcTDFNhbkZyYW5jaXNjbzEPMA0GA1UEChMGRG9ja2VyMRMwEQYDVQQDEwpk -ZWxlZ2F0aW9uMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqULAjgba -Y2I10WfqdmYnPfEqEe6iMDbzcgECb2xKafXcI4ltkQj1iO4zBTs0Ft9EzXFc5ZBh -pTjZrL6vrIa0y/CH2BiIHBJ0wRHx/40HXp4DSj3HZpVOlEMI3npRfBGNIBllUaRN -PWG7zL7DcKMIepBfPXyjBsxzH3yNiISq0W5hSiy+ImhSo3aipJUHHcp9Z9NgvpNC -3QvnxsGKRnECmDRDlxkq+FQu9Iqs/HWFYWgyfcsw+YTrWZq3qVnnqUouHO//c9PG -Ry3sZSDU97MwvkjvWys1e01Xvd3AbHx08YAsxih58i/OBKe81eD9NuZDP2KrjTxI -5xkXKhj6DV2NnQIDAQABo1QwUjAMBgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIF -oDATBgNVHSUEDDAKBggrBgEFBQcDAzAdBgNVHQ4EFgQUDt95hiqbQvi0KcvZGAUu -VisnztQwDQYJKoZIhvcNAQELBQADggEBAGi7qHai7MWbfeu6SlXhzIP3AIMa8TMi -lp/+mvPUFPswIVqYJ71MAN8uA7CTH3z50a2vYupGeOEtZqVJeRf+xgOEpwycncxp -Qz6wc6TWPVIoT5q1Hqxw1RD2MyKL+Y+QBDYwFxFkthpDMlX48I9frcqoJUWFxBF2 -lnRr/cE7BbPE3sMbXV3wGPlH7+eUf+CgzXJo2HB6THzagyEgNrDiz/0rCQa1ipFd -mNU3D/U6BFGmJNxhvSOtXX9escg8yjr05YwwzokHS2K4jE0ZuJPBd50C/Rvo3Mf4 -0h7/2Q95e7d42zPe9WYPu2F8KTWsf4r+6ddhKrKhYzXIcTAfHIOiO+U= ------END CERTIFICATE----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey4.key b/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey4.key deleted file mode 100644 index f473cc4..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/delgkey4.key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAqULAjgbaY2I10WfqdmYnPfEqEe6iMDbzcgECb2xKafXcI4lt -kQj1iO4zBTs0Ft9EzXFc5ZBhpTjZrL6vrIa0y/CH2BiIHBJ0wRHx/40HXp4DSj3H -ZpVOlEMI3npRfBGNIBllUaRNPWG7zL7DcKMIepBfPXyjBsxzH3yNiISq0W5hSiy+ -ImhSo3aipJUHHcp9Z9NgvpNC3QvnxsGKRnECmDRDlxkq+FQu9Iqs/HWFYWgyfcsw -+YTrWZq3qVnnqUouHO//c9PGRy3sZSDU97MwvkjvWys1e01Xvd3AbHx08YAsxih5 -8i/OBKe81eD9NuZDP2KrjTxI5xkXKhj6DV2NnQIDAQABAoIBAGK0ZKnuYSiXux60 -5MvK4pOCsa/nY3mOcgVHhW4IzpRgJdIrcFOlz9ncXrBsSAIWjX7o3u2Ydvjs4DOW -t8d6frB3QiDInYcRVDjLCD6otWV97Bk9Ua0G4N4hAWkMF7ysV4oihS1JDSoAdo39 -qOdki6s9yeyHZGKwk2oHLlowU5TxQMBA8DHmxqBII1HTm+8xRz45bcEqRXydYSUn -P1JuSU9jFqdylxU+Nrq6ehslMQ3y7qNWQyiLGxu6EmR+vgrzSU0s3iAOqCHthaOS -VBBXPL3DNEYUS+0QGnGrACuJhanOMBfdiO6Orelx6ZzWZm38PNGv0yBt0WCM+8/A -TtQNGkECgYEA1LqR6AH9XikUQ0+rM4526BgVuYqtjw21h4Lj9alaA+YTQntBBJOv -iAcUpnJiV4T8jzAMLeqpK8R/rbxRnK5S9jOV2gr+puk4L6tH46cgahBUESDigDp8 -6vK8ur6ubBcXNPh3AT6rsPj+Ph2EU3raqiYdouvCdga/OCYZb+jr6UkCgYEAy7Cr -l8WssI/8/ORcQ4MFJFNyfz/Y2beNXyLd1PX0H+wRSiGcKzeUuTHNtzFFpMbrK/nx -ZOPCT2ROdHsBHzp1L+WquCb0fyMVSiYiXBU+VCFDbUU5tBr3ycTc7VwuFPENOiha -IdlWgew/aW110FQHIaqe9g+htRe+mXe++faZtbUCgYB/MSJmNzJX53XvHSZ/CBJ+ -iVAMBSfq3caJRLCqRNzGcf1YBbwFUYxlZ95n+wJj0+byckcF+UW3HqE8rtmZNf3y -qTtTCLnj8JQgpGeybU4LPMIXD7N9+fqQvBwuCC7gABpnGJyHCQK9KNNTLnDdPRqb -G3ki3ZYC3dvdZaJV8E2FyQKBgQCMa5Mf4kqWvezueo+QizZ0QILibqWUEhIH0AWV -1qkhiKCytlDvCjYhJdBnxjP40Jk3i+t6XfmKud/MNTAk0ywOhQoYQeKz8v+uSnPN -f2ekn/nXzq1lGGJSWsDjcXTjQvqXaVIZm7cjgjaE+80IfaUc9H75qvUT3vaq3f5u -XC7DMQKBgQDMAzCCpWlEPbZoFMl6F49+7jG0/TiqM/WRUSQnNtufPMbrR9Je4QM1 -L1UCANCPaHFOncKYer15NfIV1ctt5MZKImevDsUaQO8CUlO+dzd5H8KvHw9E29gA -B22v8k3jIjsYeRL+UJ/sBnWHgxdAe/NEM+TdlP2oP9D1gTifutPqAg== ------END RSA PRIVATE KEY----- diff --git a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/gen.sh b/vendor/github.com/docker/docker/integration-cli/fixtures/notary/gen.sh deleted file mode 100755 index 8d6381c..0000000 --- a/vendor/github.com/docker/docker/integration-cli/fixtures/notary/gen.sh +++ /dev/null @@ -1,18 +0,0 @@ -for selfsigned in delgkey1 delgkey2 delgkey3 delgkey4; do - subj='/C=US/ST=CA/L=SanFrancisco/O=Docker/CN=delegation' - - openssl genrsa -out "${selfsigned}.key" 2048 - openssl req -new -key "${selfsigned}.key" -out "${selfsigned}.csr" -sha256 -subj "${subj}" - cat > "${selfsigned}.cnf" < 1 && buf[0] == 'Y' - }, - "Test requires apparmor is enabled.", - } - RegistryHosting = testRequirement{ - func() bool { - // for now registry binary is built only if we're running inside - // container through `make test`. Figure that out by testing if - // registry binary is in PATH. - _, err := exec.LookPath(v2binary) - return err == nil - }, - fmt.Sprintf("Test requires an environment that can host %s in the same host", v2binary), - } - NotaryHosting = testRequirement{ - func() bool { - // for now notary binary is built only if we're running inside - // container through `make test`. Figure that out by testing if - // notary-server binary is in PATH. - _, err := exec.LookPath(notaryServerBinary) - return err == nil - }, - fmt.Sprintf("Test requires an environment that can host %s in the same host", notaryServerBinary), - } - NotaryServerHosting = testRequirement{ - func() bool { - // for now notary-server binary is built only if we're running inside - // container through `make test`. Figure that out by testing if - // notary-server binary is in PATH. - _, err := exec.LookPath(notaryServerBinary) - return err == nil - }, - fmt.Sprintf("Test requires an environment that can host %s in the same host", notaryServerBinary), - } - NotOverlay = testRequirement{ - func() bool { - return !strings.HasPrefix(daemonStorageDriver, "overlay") - }, - "Test requires underlying root filesystem not be backed by overlay.", - } - - Devicemapper = testRequirement{ - func() bool { - return strings.HasPrefix(daemonStorageDriver, "devicemapper") - }, - "Test requires underlying root filesystem to be backed by devicemapper.", - } - - IPv6 = testRequirement{ - func() bool { - cmd := exec.Command("test", "-f", "/proc/net/if_inet6") - - if err := cmd.Run(); err != nil { - return true - } - return false - }, - "Test requires support for IPv6", - } - UserNamespaceROMount = testRequirement{ - func() bool { - // quick case--userns not enabled in this test run - if os.Getenv("DOCKER_REMAP_ROOT") == "" { - return true - } - if _, _, err := dockerCmdWithError("run", "--rm", "--read-only", "busybox", "date"); err != nil { - return false - } - return true - }, - "Test cannot be run if user namespaces enabled but readonly mounts fail on this kernel.", - } - UserNamespaceInKernel = testRequirement{ - func() bool { - if _, err := os.Stat("/proc/self/uid_map"); os.IsNotExist(err) { - /* - * This kernel-provided file only exists if user namespaces are - * supported - */ - return false - } - - // We need extra check on redhat based distributions - if f, err := os.Open("/sys/module/user_namespace/parameters/enable"); err == nil { - defer f.Close() - b := make([]byte, 1) - _, _ = f.Read(b) - if string(b) == "N" { - return false - } - return true - } - - return true - }, - "Kernel must have user namespaces configured and enabled.", - } - NotUserNamespace = testRequirement{ - func() bool { - root := os.Getenv("DOCKER_REMAP_ROOT") - if root != "" { - return false - } - return true - }, - "Test cannot be run when remapping root", - } - IsPausable = testRequirement{ - func() bool { - if daemonPlatform == "windows" { - return isolation == "hyperv" - } - return true - }, - "Test requires containers are pausable.", - } - NotPausable = testRequirement{ - func() bool { - if daemonPlatform == "windows" { - return isolation == "process" - } - return false - }, - "Test requires containers are not pausable.", - } - IsolationIsHyperv = testRequirement{ - func() bool { - return daemonPlatform == "windows" && isolation == "hyperv" - }, - "Test requires a Windows daemon running default isolation mode of hyperv.", - } - IsolationIsProcess = testRequirement{ - func() bool { - return daemonPlatform == "windows" && isolation == "process" - }, - "Test requires a Windows daemon running default isolation mode of process.", - } -) - -// testRequires checks if the environment satisfies the requirements -// for the test to run or skips the tests. -func testRequires(c *check.C, requirements ...testRequirement) { - for _, r := range requirements { - if !r.Condition() { - c.Skip(r.SkipMessage) - } - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/requirements_unix.go b/vendor/github.com/docker/docker/integration-cli/requirements_unix.go deleted file mode 100644 index ef017d8..0000000 --- a/vendor/github.com/docker/docker/integration-cli/requirements_unix.go +++ /dev/null @@ -1,159 +0,0 @@ -// +build !windows - -package main - -import ( - "bytes" - "io/ioutil" - "os/exec" - "strings" - - "github.com/docker/docker/pkg/parsers/kernel" - "github.com/docker/docker/pkg/sysinfo" -) - -var ( - // SysInfo stores information about which features a kernel supports. - SysInfo *sysinfo.SysInfo - cpuCfsPeriod = testRequirement{ - func() bool { - return SysInfo.CPUCfsPeriod - }, - "Test requires an environment that supports cgroup cfs period.", - } - cpuCfsQuota = testRequirement{ - func() bool { - return SysInfo.CPUCfsQuota - }, - "Test requires an environment that supports cgroup cfs quota.", - } - cpuShare = testRequirement{ - func() bool { - return SysInfo.CPUShares - }, - "Test requires an environment that supports cgroup cpu shares.", - } - oomControl = testRequirement{ - func() bool { - return SysInfo.OomKillDisable - }, - "Test requires Oom control enabled.", - } - pidsLimit = testRequirement{ - func() bool { - return SysInfo.PidsLimit - }, - "Test requires pids limit enabled.", - } - kernelMemorySupport = testRequirement{ - func() bool { - return SysInfo.KernelMemory - }, - "Test requires an environment that supports cgroup kernel memory.", - } - memoryLimitSupport = testRequirement{ - func() bool { - return SysInfo.MemoryLimit - }, - "Test requires an environment that supports cgroup memory limit.", - } - memoryReservationSupport = testRequirement{ - func() bool { - return SysInfo.MemoryReservation - }, - "Test requires an environment that supports cgroup memory reservation.", - } - swapMemorySupport = testRequirement{ - func() bool { - return SysInfo.SwapLimit - }, - "Test requires an environment that supports cgroup swap memory limit.", - } - memorySwappinessSupport = testRequirement{ - func() bool { - return SysInfo.MemorySwappiness - }, - "Test requires an environment that supports cgroup memory swappiness.", - } - blkioWeight = testRequirement{ - func() bool { - return SysInfo.BlkioWeight - }, - "Test requires an environment that supports blkio weight.", - } - cgroupCpuset = testRequirement{ - func() bool { - return SysInfo.Cpuset - }, - "Test requires an environment that supports cgroup cpuset.", - } - seccompEnabled = testRequirement{ - func() bool { - return supportsSeccomp && SysInfo.Seccomp - }, - "Test requires that seccomp support be enabled in the daemon.", - } - bridgeNfIptables = testRequirement{ - func() bool { - return !SysInfo.BridgeNFCallIPTablesDisabled - }, - "Test requires that bridge-nf-call-iptables support be enabled in the daemon.", - } - bridgeNfIP6tables = testRequirement{ - func() bool { - return !SysInfo.BridgeNFCallIP6TablesDisabled - }, - "Test requires that bridge-nf-call-ip6tables support be enabled in the daemon.", - } - unprivilegedUsernsClone = testRequirement{ - func() bool { - content, err := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone") - if err == nil && strings.Contains(string(content), "0") { - return false - } - return true - }, - "Test cannot be run with 'sysctl kernel.unprivileged_userns_clone' = 0", - } - ambientCapabilities = testRequirement{ - func() bool { - content, err := ioutil.ReadFile("/proc/self/status") - if err == nil && strings.Contains(string(content), "CapAmb:") { - return true - } - return false - }, - "Test cannot be run without a kernel (4.3+) supporting ambient capabilities", - } - overlayFSSupported = testRequirement{ - func() bool { - cmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "/bin/sh", "-c", "cat /proc/filesystems") - out, err := cmd.CombinedOutput() - if err != nil { - return false - } - return bytes.Contains(out, []byte("overlay\n")) - }, - "Test cannot be run without suppport for overlayfs", - } - overlay2Supported = testRequirement{ - func() bool { - if !overlayFSSupported.Condition() { - return false - } - - daemonV, err := kernel.ParseRelease(daemonKernelVersion) - if err != nil { - return false - } - requiredV := kernel.VersionInfo{Kernel: 4} - return kernel.CompareKernelVersion(*daemonV, requiredV) > -1 - - }, - "Test cannot be run without overlay2 support (kernel 4.0+)", - } -) - -func init() { - SysInfo = sysinfo.New(true) -} diff --git a/vendor/github.com/docker/docker/integration-cli/test_vars.go b/vendor/github.com/docker/docker/integration-cli/test_vars.go deleted file mode 100644 index 97bcddd..0000000 --- a/vendor/github.com/docker/docker/integration-cli/test_vars.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -// sleepCommandForDaemonPlatform is a helper function that determines what -// the command is for a sleeping container based on the daemon platform. -// The Windows busybox image does not have a `top` command. -func sleepCommandForDaemonPlatform() []string { - if daemonPlatform == "windows" { - return []string{"sleep", "240"} - } - return []string{"top"} -} diff --git a/vendor/github.com/docker/docker/integration-cli/test_vars_exec.go b/vendor/github.com/docker/docker/integration-cli/test_vars_exec.go deleted file mode 100644 index 7633b34..0000000 --- a/vendor/github.com/docker/docker/integration-cli/test_vars_exec.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !test_no_exec - -package main - -const ( - // indicates docker daemon tested supports 'docker exec' - supportsExec = true -) diff --git a/vendor/github.com/docker/docker/integration-cli/test_vars_noexec.go b/vendor/github.com/docker/docker/integration-cli/test_vars_noexec.go deleted file mode 100644 index 0845090..0000000 --- a/vendor/github.com/docker/docker/integration-cli/test_vars_noexec.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build test_no_exec - -package main - -const ( - // indicates docker daemon tested supports 'docker exec' - supportsExec = false -) diff --git a/vendor/github.com/docker/docker/integration-cli/test_vars_noseccomp.go b/vendor/github.com/docker/docker/integration-cli/test_vars_noseccomp.go deleted file mode 100644 index 2f47ab0..0000000 --- a/vendor/github.com/docker/docker/integration-cli/test_vars_noseccomp.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !seccomp - -package main - -const ( - // indicates docker daemon built with seccomp support - supportsSeccomp = false -) diff --git a/vendor/github.com/docker/docker/integration-cli/test_vars_seccomp.go b/vendor/github.com/docker/docker/integration-cli/test_vars_seccomp.go deleted file mode 100644 index 00cf697..0000000 --- a/vendor/github.com/docker/docker/integration-cli/test_vars_seccomp.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build seccomp - -package main - -const ( - // indicates docker daemon built with seccomp support - supportsSeccomp = true -) diff --git a/vendor/github.com/docker/docker/integration-cli/test_vars_unix.go b/vendor/github.com/docker/docker/integration-cli/test_vars_unix.go deleted file mode 100644 index f9ecc01..0000000 --- a/vendor/github.com/docker/docker/integration-cli/test_vars_unix.go +++ /dev/null @@ -1,14 +0,0 @@ -// +build !windows - -package main - -const ( - // identifies if test suite is running on a unix platform - isUnixCli = true - - expectedFileChmod = "-rw-r--r--" - - // On Unix variants, the busybox image comes with the `top` command which - // runs indefinitely while still being interruptible by a signal. - defaultSleepImage = "busybox" -) diff --git a/vendor/github.com/docker/docker/integration-cli/test_vars_windows.go b/vendor/github.com/docker/docker/integration-cli/test_vars_windows.go deleted file mode 100644 index bfc9a5a..0000000 --- a/vendor/github.com/docker/docker/integration-cli/test_vars_windows.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build windows - -package main - -const ( - // identifies if test suite is running on a unix platform - isUnixCli = false - - // this is the expected file permission set on windows: gh#11395 - expectedFileChmod = "-rwxr-xr-x" - - // On Windows, the busybox image doesn't have the `top` command, so we rely - // on `sleep` with a high duration. - defaultSleepImage = "busybox" -) diff --git a/vendor/github.com/docker/docker/integration-cli/trust_server.go b/vendor/github.com/docker/docker/integration-cli/trust_server.go deleted file mode 100644 index 1887631..0000000 --- a/vendor/github.com/docker/docker/integration-cli/trust_server.go +++ /dev/null @@ -1,344 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "net" - "net/http" - "os" - "os/exec" - "path/filepath" - "strings" - "time" - - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/pkg/integration/checker" - "github.com/docker/go-connections/tlsconfig" - "github.com/go-check/check" -) - -var notaryBinary = "notary" -var notaryServerBinary = "notary-server" - -type keyPair struct { - Public string - Private string -} - -type testNotary struct { - cmd *exec.Cmd - dir string - keys []keyPair -} - -const notaryHost = "localhost:4443" -const notaryURL = "https://" + notaryHost - -func newTestNotary(c *check.C) (*testNotary, error) { - // generate server config - template := `{ - "server": { - "http_addr": "%s", - "tls_key_file": "%s", - "tls_cert_file": "%s" - }, - "trust_service": { - "type": "local", - "hostname": "", - "port": "", - "key_algorithm": "ed25519" - }, - "logging": { - "level": "debug" - }, - "storage": { - "backend": "memory" - } -}` - tmp, err := ioutil.TempDir("", "notary-test-") - if err != nil { - return nil, err - } - confPath := filepath.Join(tmp, "config.json") - config, err := os.Create(confPath) - if err != nil { - return nil, err - } - defer config.Close() - - workingDir, err := os.Getwd() - if err != nil { - return nil, err - } - if _, err := fmt.Fprintf(config, template, notaryHost, filepath.Join(workingDir, "fixtures/notary/localhost.key"), filepath.Join(workingDir, "fixtures/notary/localhost.cert")); err != nil { - os.RemoveAll(tmp) - return nil, err - } - - // generate client config - clientConfPath := filepath.Join(tmp, "client-config.json") - clientConfig, err := os.Create(clientConfPath) - if err != nil { - return nil, err - } - defer clientConfig.Close() - - template = `{ - "trust_dir" : "%s", - "remote_server": { - "url": "%s", - "skipTLSVerify": true - } -}` - if _, err = fmt.Fprintf(clientConfig, template, filepath.Join(cliconfig.ConfigDir(), "trust"), notaryURL); err != nil { - os.RemoveAll(tmp) - return nil, err - } - - // load key fixture filenames - var keys []keyPair - for i := 1; i < 5; i++ { - keys = append(keys, keyPair{ - Public: filepath.Join(workingDir, fmt.Sprintf("fixtures/notary/delgkey%v.crt", i)), - Private: filepath.Join(workingDir, fmt.Sprintf("fixtures/notary/delgkey%v.key", i)), - }) - } - - // run notary-server - cmd := exec.Command(notaryServerBinary, "-config", confPath) - if err := cmd.Start(); err != nil { - os.RemoveAll(tmp) - if os.IsNotExist(err) { - c.Skip(err.Error()) - } - return nil, err - } - - testNotary := &testNotary{ - cmd: cmd, - dir: tmp, - keys: keys, - } - - // Wait for notary to be ready to serve requests. - for i := 1; i <= 20; i++ { - if err = testNotary.Ping(); err == nil { - break - } - time.Sleep(10 * time.Millisecond * time.Duration(i*i)) - } - - if err != nil { - c.Fatalf("Timeout waiting for test notary to become available: %s", err) - } - - return testNotary, nil -} - -func (t *testNotary) Ping() error { - tlsConfig := tlsconfig.ClientDefault() - tlsConfig.InsecureSkipVerify = true - client := http.Client{ - Transport: &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - }).Dial, - TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: tlsConfig, - }, - } - resp, err := client.Get(fmt.Sprintf("%s/v2/", notaryURL)) - if err != nil { - return err - } - if resp.StatusCode != http.StatusOK { - return fmt.Errorf("notary ping replied with an unexpected status code %d", resp.StatusCode) - } - return nil -} - -func (t *testNotary) Close() { - t.cmd.Process.Kill() - os.RemoveAll(t.dir) -} - -func (s *DockerTrustSuite) trustedCmd(cmd *exec.Cmd) { - pwd := "12345678" - trustCmdEnv(cmd, notaryURL, pwd, pwd) -} - -func (s *DockerTrustSuite) trustedCmdWithServer(cmd *exec.Cmd, server string) { - pwd := "12345678" - trustCmdEnv(cmd, server, pwd, pwd) -} - -func (s *DockerTrustSuite) trustedCmdWithPassphrases(cmd *exec.Cmd, rootPwd, repositoryPwd string) { - trustCmdEnv(cmd, notaryURL, rootPwd, repositoryPwd) -} - -func trustCmdEnv(cmd *exec.Cmd, server, rootPwd, repositoryPwd string) { - env := []string{ - "DOCKER_CONTENT_TRUST=1", - fmt.Sprintf("DOCKER_CONTENT_TRUST_SERVER=%s", server), - fmt.Sprintf("DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE=%s", rootPwd), - fmt.Sprintf("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE=%s", repositoryPwd), - } - cmd.Env = append(os.Environ(), env...) -} - -func (s *DockerTrustSuite) setupTrustedImage(c *check.C, name string) string { - repoName := fmt.Sprintf("%v/dockercli/%s:latest", privateRegistryURL, name) - // tag the image and upload it to the private registry - dockerCmd(c, "tag", "busybox", repoName) - - pushCmd := exec.Command(dockerBinary, "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - - if err != nil { - c.Fatalf("Error running trusted push: %s\n%s", err, out) - } - if !strings.Contains(string(out), "Signing and pushing trust metadata") { - c.Fatalf("Missing expected output on trusted push:\n%s", out) - } - - if out, status := dockerCmd(c, "rmi", repoName); status != 0 { - c.Fatalf("Error removing image %q\n%s", repoName, out) - } - - return repoName -} - -func (s *DockerTrustSuite) setupTrustedplugin(c *check.C, source, name string) string { - repoName := fmt.Sprintf("%v/dockercli/%s:latest", privateRegistryURL, name) - // tag the image and upload it to the private registry - dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--alias", repoName, source) - - pushCmd := exec.Command(dockerBinary, "plugin", "push", repoName) - s.trustedCmd(pushCmd) - out, _, err := runCommandWithOutput(pushCmd) - - if err != nil { - c.Fatalf("Error running trusted plugin push: %s\n%s", err, out) - } - if !strings.Contains(string(out), "Signing and pushing trust metadata") { - c.Fatalf("Missing expected output on trusted push:\n%s", out) - } - - if out, status := dockerCmd(c, "plugin", "rm", "-f", repoName); status != 0 { - c.Fatalf("Error removing plugin %q\n%s", repoName, out) - } - - return repoName -} - -func notaryClientEnv(cmd *exec.Cmd) { - pwd := "12345678" - env := []string{ - fmt.Sprintf("NOTARY_ROOT_PASSPHRASE=%s", pwd), - fmt.Sprintf("NOTARY_TARGETS_PASSPHRASE=%s", pwd), - fmt.Sprintf("NOTARY_SNAPSHOT_PASSPHRASE=%s", pwd), - fmt.Sprintf("NOTARY_DELEGATION_PASSPHRASE=%s", pwd), - } - cmd.Env = append(os.Environ(), env...) -} - -func (s *DockerTrustSuite) notaryInitRepo(c *check.C, repoName string) { - initCmd := exec.Command(notaryBinary, "-c", filepath.Join(s.not.dir, "client-config.json"), "init", repoName) - notaryClientEnv(initCmd) - out, _, err := runCommandWithOutput(initCmd) - if err != nil { - c.Fatalf("Error initializing notary repository: %s\n", out) - } -} - -func (s *DockerTrustSuite) notaryCreateDelegation(c *check.C, repoName, role string, pubKey string, paths ...string) { - pathsArg := "--all-paths" - if len(paths) > 0 { - pathsArg = "--paths=" + strings.Join(paths, ",") - } - - delgCmd := exec.Command(notaryBinary, "-c", filepath.Join(s.not.dir, "client-config.json"), - "delegation", "add", repoName, role, pubKey, pathsArg) - notaryClientEnv(delgCmd) - out, _, err := runCommandWithOutput(delgCmd) - if err != nil { - c.Fatalf("Error adding %s role to notary repository: %s\n", role, out) - } -} - -func (s *DockerTrustSuite) notaryPublish(c *check.C, repoName string) { - pubCmd := exec.Command(notaryBinary, "-c", filepath.Join(s.not.dir, "client-config.json"), "publish", repoName) - notaryClientEnv(pubCmd) - out, _, err := runCommandWithOutput(pubCmd) - if err != nil { - c.Fatalf("Error publishing notary repository: %s\n", out) - } -} - -func (s *DockerTrustSuite) notaryImportKey(c *check.C, repoName, role string, privKey string) { - impCmd := exec.Command(notaryBinary, "-c", filepath.Join(s.not.dir, "client-config.json"), "key", - "import", privKey, "-g", repoName, "-r", role) - notaryClientEnv(impCmd) - out, _, err := runCommandWithOutput(impCmd) - if err != nil { - c.Fatalf("Error importing key to notary repository: %s\n", out) - } -} - -func (s *DockerTrustSuite) notaryListTargetsInRole(c *check.C, repoName, role string) map[string]string { - listCmd := exec.Command(notaryBinary, "-c", filepath.Join(s.not.dir, "client-config.json"), "list", - repoName, "-r", role) - notaryClientEnv(listCmd) - out, _, err := runCommandWithOutput(listCmd) - if err != nil { - c.Fatalf("Error listing targets in notary repository: %s\n", out) - } - - // should look something like: - // NAME DIGEST SIZE (BYTES) ROLE - // ------------------------------------------------------------------------------------------------------ - // latest 24a36bbc059b1345b7e8be0df20f1b23caa3602e85d42fff7ecd9d0bd255de56 1377 targets - - targets := make(map[string]string) - - // no target - lines := strings.Split(strings.TrimSpace(out), "\n") - if len(lines) == 1 && strings.Contains(out, "No targets present in this repository.") { - return targets - } - - // otherwise, there is at least one target - c.Assert(len(lines), checker.GreaterOrEqualThan, 3) - - for _, line := range lines[2:] { - tokens := strings.Fields(line) - c.Assert(tokens, checker.HasLen, 4) - targets[tokens[0]] = tokens[3] - } - - return targets -} - -func (s *DockerTrustSuite) assertTargetInRoles(c *check.C, repoName, target string, roles ...string) { - // check all the roles - for _, role := range roles { - targets := s.notaryListTargetsInRole(c, repoName, role) - roleName, ok := targets[target] - c.Assert(ok, checker.True) - c.Assert(roleName, checker.Equals, role) - } -} - -func (s *DockerTrustSuite) assertTargetNotInRoles(c *check.C, repoName, target string, roles ...string) { - targets := s.notaryListTargetsInRole(c, repoName, "targets") - - roleName, ok := targets[target] - if ok { - for _, role := range roles { - c.Assert(roleName, checker.Not(checker.Equals), role) - } - } -} diff --git a/vendor/github.com/docker/docker/integration-cli/utils.go b/vendor/github.com/docker/docker/integration-cli/utils.go deleted file mode 100644 index 87d48e4..0000000 --- a/vendor/github.com/docker/docker/integration-cli/utils.go +++ /dev/null @@ -1,79 +0,0 @@ -package main - -import ( - "io" - "os" - "os/exec" - "time" - - "github.com/docker/docker/pkg/integration" - "github.com/docker/docker/pkg/integration/cmd" -) - -func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) { - if daemonPlatform == "windows" { - return "c:", `\` - } - return "", "/" -} - -// TODO: update code to call cmd.RunCmd directly, and remove this function -func runCommandWithOutput(execCmd *exec.Cmd) (string, int, error) { - result := cmd.RunCmd(transformCmd(execCmd)) - return result.Combined(), result.ExitCode, result.Error -} - -// TODO: update code to call cmd.RunCmd directly, and remove this function -func runCommandWithStdoutStderr(execCmd *exec.Cmd) (string, string, int, error) { - result := cmd.RunCmd(transformCmd(execCmd)) - return result.Stdout(), result.Stderr(), result.ExitCode, result.Error -} - -// TODO: update code to call cmd.RunCmd directly, and remove this function -func runCommand(execCmd *exec.Cmd) (exitCode int, err error) { - result := cmd.RunCmd(transformCmd(execCmd)) - return result.ExitCode, result.Error -} - -// Temporary shim for migrating commands to the new function -func transformCmd(execCmd *exec.Cmd) cmd.Cmd { - return cmd.Cmd{ - Command: execCmd.Args, - Env: execCmd.Env, - Dir: execCmd.Dir, - Stdin: execCmd.Stdin, - Stdout: execCmd.Stdout, - } -} - -func runCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode int, err error) { - return integration.RunCommandPipelineWithOutput(cmds...) -} - -func convertSliceOfStringsToMap(input []string) map[string]struct{} { - return integration.ConvertSliceOfStringsToMap(input) -} - -func compareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error { - return integration.CompareDirectoryEntries(e1, e2) -} - -func listTar(f io.Reader) ([]string, error) { - return integration.ListTar(f) -} - -func randomTmpDirPath(s string, platform string) string { - return integration.RandomTmpDirPath(s, platform) -} - -func consumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) { - return integration.ConsumeWithSpeed(reader, chunkSize, interval, stop) -} - -func parseCgroupPaths(procCgroupData string) map[string]string { - return integration.ParseCgroupPaths(procCgroupData) -} - -func runAtDifferentDate(date time.Time, block func()) { - integration.RunAtDifferentDate(date, block) -} diff --git a/vendor/github.com/docker/docker/layer/empty.go b/vendor/github.com/docker/docker/layer/empty.go deleted file mode 100644 index 3b6ffc8..0000000 --- a/vendor/github.com/docker/docker/layer/empty.go +++ /dev/null @@ -1,56 +0,0 @@ -package layer - -import ( - "archive/tar" - "bytes" - "fmt" - "io" - "io/ioutil" -) - -// DigestSHA256EmptyTar is the canonical sha256 digest of empty tar file - -// (1024 NULL bytes) -const DigestSHA256EmptyTar = DiffID("sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef") - -type emptyLayer struct{} - -// EmptyLayer is a layer that corresponds to empty tar. -var EmptyLayer = &emptyLayer{} - -func (el *emptyLayer) TarStream() (io.ReadCloser, error) { - buf := new(bytes.Buffer) - tarWriter := tar.NewWriter(buf) - tarWriter.Close() - return ioutil.NopCloser(buf), nil -} - -func (el *emptyLayer) TarStreamFrom(p ChainID) (io.ReadCloser, error) { - if p == "" { - return el.TarStream() - } - return nil, fmt.Errorf("can't get parent tar stream of an empty layer") -} - -func (el *emptyLayer) ChainID() ChainID { - return ChainID(DigestSHA256EmptyTar) -} - -func (el *emptyLayer) DiffID() DiffID { - return DigestSHA256EmptyTar -} - -func (el *emptyLayer) Parent() Layer { - return nil -} - -func (el *emptyLayer) Size() (size int64, err error) { - return 0, nil -} - -func (el *emptyLayer) DiffSize() (size int64, err error) { - return 0, nil -} - -func (el *emptyLayer) Metadata() (map[string]string, error) { - return make(map[string]string), nil -} diff --git a/vendor/github.com/docker/docker/layer/empty_test.go b/vendor/github.com/docker/docker/layer/empty_test.go deleted file mode 100644 index c22da76..0000000 --- a/vendor/github.com/docker/docker/layer/empty_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package layer - -import ( - "io" - "testing" - - "github.com/docker/distribution/digest" -) - -func TestEmptyLayer(t *testing.T) { - if EmptyLayer.ChainID() != ChainID(DigestSHA256EmptyTar) { - t.Fatal("wrong ID for empty layer") - } - - if EmptyLayer.DiffID() != DigestSHA256EmptyTar { - t.Fatal("wrong DiffID for empty layer") - } - - if EmptyLayer.Parent() != nil { - t.Fatal("expected no parent for empty layer") - } - - if size, err := EmptyLayer.Size(); err != nil || size != 0 { - t.Fatal("expected zero size for empty layer") - } - - if diffSize, err := EmptyLayer.DiffSize(); err != nil || diffSize != 0 { - t.Fatal("expected zero diffsize for empty layer") - } - - tarStream, err := EmptyLayer.TarStream() - if err != nil { - t.Fatalf("error streaming tar for empty layer: %v", err) - } - - digester := digest.Canonical.New() - _, err = io.Copy(digester.Hash(), tarStream) - - if err != nil { - t.Fatalf("error hashing empty tar layer: %v", err) - } - - if digester.Digest() != digest.Digest(DigestSHA256EmptyTar) { - t.Fatal("empty layer tar stream hashes to wrong value") - } -} diff --git a/vendor/github.com/docker/docker/layer/filestore.go b/vendor/github.com/docker/docker/layer/filestore.go deleted file mode 100644 index 42b4555..0000000 --- a/vendor/github.com/docker/docker/layer/filestore.go +++ /dev/null @@ -1,354 +0,0 @@ -package layer - -import ( - "compress/gzip" - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "regexp" - "strconv" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/docker/pkg/ioutils" -) - -var ( - stringIDRegexp = regexp.MustCompile(`^[a-f0-9]{64}(-init)?$`) - supportedAlgorithms = []digest.Algorithm{ - digest.SHA256, - // digest.SHA384, // Currently not used - // digest.SHA512, // Currently not used - } -) - -type fileMetadataStore struct { - root string -} - -type fileMetadataTransaction struct { - store *fileMetadataStore - ws *ioutils.AtomicWriteSet -} - -// NewFSMetadataStore returns an instance of a metadata store -// which is backed by files on disk using the provided root -// as the root of metadata files. -func NewFSMetadataStore(root string) (MetadataStore, error) { - if err := os.MkdirAll(root, 0700); err != nil { - return nil, err - } - return &fileMetadataStore{ - root: root, - }, nil -} - -func (fms *fileMetadataStore) getLayerDirectory(layer ChainID) string { - dgst := digest.Digest(layer) - return filepath.Join(fms.root, string(dgst.Algorithm()), dgst.Hex()) -} - -func (fms *fileMetadataStore) getLayerFilename(layer ChainID, filename string) string { - return filepath.Join(fms.getLayerDirectory(layer), filename) -} - -func (fms *fileMetadataStore) getMountDirectory(mount string) string { - return filepath.Join(fms.root, "mounts", mount) -} - -func (fms *fileMetadataStore) getMountFilename(mount, filename string) string { - return filepath.Join(fms.getMountDirectory(mount), filename) -} - -func (fms *fileMetadataStore) StartTransaction() (MetadataTransaction, error) { - tmpDir := filepath.Join(fms.root, "tmp") - if err := os.MkdirAll(tmpDir, 0755); err != nil { - return nil, err - } - ws, err := ioutils.NewAtomicWriteSet(tmpDir) - if err != nil { - return nil, err - } - - return &fileMetadataTransaction{ - store: fms, - ws: ws, - }, nil -} - -func (fm *fileMetadataTransaction) SetSize(size int64) error { - content := fmt.Sprintf("%d", size) - return fm.ws.WriteFile("size", []byte(content), 0644) -} - -func (fm *fileMetadataTransaction) SetParent(parent ChainID) error { - return fm.ws.WriteFile("parent", []byte(digest.Digest(parent).String()), 0644) -} - -func (fm *fileMetadataTransaction) SetDiffID(diff DiffID) error { - return fm.ws.WriteFile("diff", []byte(digest.Digest(diff).String()), 0644) -} - -func (fm *fileMetadataTransaction) SetCacheID(cacheID string) error { - return fm.ws.WriteFile("cache-id", []byte(cacheID), 0644) -} - -func (fm *fileMetadataTransaction) SetDescriptor(ref distribution.Descriptor) error { - jsonRef, err := json.Marshal(ref) - if err != nil { - return err - } - return fm.ws.WriteFile("descriptor.json", jsonRef, 0644) -} - -func (fm *fileMetadataTransaction) TarSplitWriter(compressInput bool) (io.WriteCloser, error) { - f, err := fm.ws.FileWriter("tar-split.json.gz", os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return nil, err - } - var wc io.WriteCloser - if compressInput { - wc = gzip.NewWriter(f) - } else { - wc = f - } - - return ioutils.NewWriteCloserWrapper(wc, func() error { - wc.Close() - return f.Close() - }), nil -} - -func (fm *fileMetadataTransaction) Commit(layer ChainID) error { - finalDir := fm.store.getLayerDirectory(layer) - if err := os.MkdirAll(filepath.Dir(finalDir), 0755); err != nil { - return err - } - - return fm.ws.Commit(finalDir) -} - -func (fm *fileMetadataTransaction) Cancel() error { - return fm.ws.Cancel() -} - -func (fm *fileMetadataTransaction) String() string { - return fm.ws.String() -} - -func (fms *fileMetadataStore) GetSize(layer ChainID) (int64, error) { - content, err := ioutil.ReadFile(fms.getLayerFilename(layer, "size")) - if err != nil { - return 0, err - } - - size, err := strconv.ParseInt(string(content), 10, 64) - if err != nil { - return 0, err - } - - return size, nil -} - -func (fms *fileMetadataStore) GetParent(layer ChainID) (ChainID, error) { - content, err := ioutil.ReadFile(fms.getLayerFilename(layer, "parent")) - if err != nil { - if os.IsNotExist(err) { - return "", nil - } - return "", err - } - - dgst, err := digest.ParseDigest(strings.TrimSpace(string(content))) - if err != nil { - return "", err - } - - return ChainID(dgst), nil -} - -func (fms *fileMetadataStore) GetDiffID(layer ChainID) (DiffID, error) { - content, err := ioutil.ReadFile(fms.getLayerFilename(layer, "diff")) - if err != nil { - return "", err - } - - dgst, err := digest.ParseDigest(strings.TrimSpace(string(content))) - if err != nil { - return "", err - } - - return DiffID(dgst), nil -} - -func (fms *fileMetadataStore) GetCacheID(layer ChainID) (string, error) { - contentBytes, err := ioutil.ReadFile(fms.getLayerFilename(layer, "cache-id")) - if err != nil { - return "", err - } - content := strings.TrimSpace(string(contentBytes)) - - if !stringIDRegexp.MatchString(content) { - return "", errors.New("invalid cache id value") - } - - return content, nil -} - -func (fms *fileMetadataStore) GetDescriptor(layer ChainID) (distribution.Descriptor, error) { - content, err := ioutil.ReadFile(fms.getLayerFilename(layer, "descriptor.json")) - if err != nil { - if os.IsNotExist(err) { - // only return empty descriptor to represent what is stored - return distribution.Descriptor{}, nil - } - return distribution.Descriptor{}, err - } - - var ref distribution.Descriptor - err = json.Unmarshal(content, &ref) - if err != nil { - return distribution.Descriptor{}, err - } - return ref, err -} - -func (fms *fileMetadataStore) TarSplitReader(layer ChainID) (io.ReadCloser, error) { - fz, err := os.Open(fms.getLayerFilename(layer, "tar-split.json.gz")) - if err != nil { - return nil, err - } - f, err := gzip.NewReader(fz) - if err != nil { - return nil, err - } - - return ioutils.NewReadCloserWrapper(f, func() error { - f.Close() - return fz.Close() - }), nil -} - -func (fms *fileMetadataStore) SetMountID(mount string, mountID string) error { - if err := os.MkdirAll(fms.getMountDirectory(mount), 0755); err != nil { - return err - } - return ioutil.WriteFile(fms.getMountFilename(mount, "mount-id"), []byte(mountID), 0644) -} - -func (fms *fileMetadataStore) SetInitID(mount string, init string) error { - if err := os.MkdirAll(fms.getMountDirectory(mount), 0755); err != nil { - return err - } - return ioutil.WriteFile(fms.getMountFilename(mount, "init-id"), []byte(init), 0644) -} - -func (fms *fileMetadataStore) SetMountParent(mount string, parent ChainID) error { - if err := os.MkdirAll(fms.getMountDirectory(mount), 0755); err != nil { - return err - } - return ioutil.WriteFile(fms.getMountFilename(mount, "parent"), []byte(digest.Digest(parent).String()), 0644) -} - -func (fms *fileMetadataStore) GetMountID(mount string) (string, error) { - contentBytes, err := ioutil.ReadFile(fms.getMountFilename(mount, "mount-id")) - if err != nil { - return "", err - } - content := strings.TrimSpace(string(contentBytes)) - - if !stringIDRegexp.MatchString(content) { - return "", errors.New("invalid mount id value") - } - - return content, nil -} - -func (fms *fileMetadataStore) GetInitID(mount string) (string, error) { - contentBytes, err := ioutil.ReadFile(fms.getMountFilename(mount, "init-id")) - if err != nil { - if os.IsNotExist(err) { - return "", nil - } - return "", err - } - content := strings.TrimSpace(string(contentBytes)) - - if !stringIDRegexp.MatchString(content) { - return "", errors.New("invalid init id value") - } - - return content, nil -} - -func (fms *fileMetadataStore) GetMountParent(mount string) (ChainID, error) { - content, err := ioutil.ReadFile(fms.getMountFilename(mount, "parent")) - if err != nil { - if os.IsNotExist(err) { - return "", nil - } - return "", err - } - - dgst, err := digest.ParseDigest(strings.TrimSpace(string(content))) - if err != nil { - return "", err - } - - return ChainID(dgst), nil -} - -func (fms *fileMetadataStore) List() ([]ChainID, []string, error) { - var ids []ChainID - for _, algorithm := range supportedAlgorithms { - fileInfos, err := ioutil.ReadDir(filepath.Join(fms.root, string(algorithm))) - if err != nil { - if os.IsNotExist(err) { - continue - } - return nil, nil, err - } - - for _, fi := range fileInfos { - if fi.IsDir() && fi.Name() != "mounts" { - dgst := digest.NewDigestFromHex(string(algorithm), fi.Name()) - if err := dgst.Validate(); err != nil { - logrus.Debugf("Ignoring invalid digest %s:%s", algorithm, fi.Name()) - } else { - ids = append(ids, ChainID(dgst)) - } - } - } - } - - fileInfos, err := ioutil.ReadDir(filepath.Join(fms.root, "mounts")) - if err != nil { - if os.IsNotExist(err) { - return ids, []string{}, nil - } - return nil, nil, err - } - - var mounts []string - for _, fi := range fileInfos { - if fi.IsDir() { - mounts = append(mounts, fi.Name()) - } - } - - return ids, mounts, nil -} - -func (fms *fileMetadataStore) Remove(layer ChainID) error { - return os.RemoveAll(fms.getLayerDirectory(layer)) -} - -func (fms *fileMetadataStore) RemoveMount(mount string) error { - return os.RemoveAll(fms.getMountDirectory(mount)) -} diff --git a/vendor/github.com/docker/docker/layer/filestore_test.go b/vendor/github.com/docker/docker/layer/filestore_test.go deleted file mode 100644 index 55e3b28..0000000 --- a/vendor/github.com/docker/docker/layer/filestore_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package layer - -import ( - "fmt" - "io/ioutil" - "math/rand" - "os" - "path/filepath" - "strings" - "syscall" - "testing" - - "github.com/docker/distribution/digest" -) - -func randomLayerID(seed int64) ChainID { - r := rand.New(rand.NewSource(seed)) - - return ChainID(digest.FromBytes([]byte(fmt.Sprintf("%d", r.Int63())))) -} - -func newFileMetadataStore(t *testing.T) (*fileMetadataStore, string, func()) { - td, err := ioutil.TempDir("", "layers-") - if err != nil { - t.Fatal(err) - } - fms, err := NewFSMetadataStore(td) - if err != nil { - t.Fatal(err) - } - - return fms.(*fileMetadataStore), td, func() { - if err := os.RemoveAll(td); err != nil { - t.Logf("Failed to cleanup %q: %s", td, err) - } - } -} - -func assertNotDirectoryError(t *testing.T, err error) { - perr, ok := err.(*os.PathError) - if !ok { - t.Fatalf("Unexpected error %#v, expected path error", err) - } - - if perr.Err != syscall.ENOTDIR { - t.Fatalf("Unexpected error %s, expected %s", perr.Err, syscall.ENOTDIR) - } -} - -func TestCommitFailure(t *testing.T) { - fms, td, cleanup := newFileMetadataStore(t) - defer cleanup() - - if err := ioutil.WriteFile(filepath.Join(td, "sha256"), []byte("was here first!"), 0644); err != nil { - t.Fatal(err) - } - - tx, err := fms.StartTransaction() - if err != nil { - t.Fatal(err) - } - - if err := tx.SetSize(0); err != nil { - t.Fatal(err) - } - - err = tx.Commit(randomLayerID(5)) - if err == nil { - t.Fatalf("Expected error committing with invalid layer parent directory") - } - assertNotDirectoryError(t, err) -} - -func TestStartTransactionFailure(t *testing.T) { - fms, td, cleanup := newFileMetadataStore(t) - defer cleanup() - - if err := ioutil.WriteFile(filepath.Join(td, "tmp"), []byte("was here first!"), 0644); err != nil { - t.Fatal(err) - } - - _, err := fms.StartTransaction() - if err == nil { - t.Fatalf("Expected error starting transaction with invalid layer parent directory") - } - assertNotDirectoryError(t, err) - - if err := os.Remove(filepath.Join(td, "tmp")); err != nil { - t.Fatal(err) - } - - tx, err := fms.StartTransaction() - if err != nil { - t.Fatal(err) - } - - if expected := filepath.Join(td, "tmp"); strings.HasPrefix(expected, tx.String()) { - t.Fatalf("Unexpected transaction string %q, expected prefix %q", tx.String(), expected) - } - - if err := tx.Cancel(); err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/layer/layer.go b/vendor/github.com/docker/docker/layer/layer.go deleted file mode 100644 index ec1d434..0000000 --- a/vendor/github.com/docker/docker/layer/layer.go +++ /dev/null @@ -1,275 +0,0 @@ -// Package layer is package for managing read-only -// and read-write mounts on the union file system -// driver. Read-only mounts are referenced using a -// content hash and are protected from mutation in -// the exposed interface. The tar format is used -// to create read-only layers and export both -// read-only and writable layers. The exported -// tar data for a read-only layer should match -// the tar used to create the layer. -package layer - -import ( - "errors" - "io" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/docker/pkg/archive" -) - -var ( - // ErrLayerDoesNotExist is used when an operation is - // attempted on a layer which does not exist. - ErrLayerDoesNotExist = errors.New("layer does not exist") - - // ErrLayerNotRetained is used when a release is - // attempted on a layer which is not retained. - ErrLayerNotRetained = errors.New("layer not retained") - - // ErrMountDoesNotExist is used when an operation is - // attempted on a mount layer which does not exist. - ErrMountDoesNotExist = errors.New("mount does not exist") - - // ErrMountNameConflict is used when a mount is attempted - // to be created but there is already a mount with the name - // used for creation. - ErrMountNameConflict = errors.New("mount already exists with name") - - // ErrActiveMount is used when an operation on a - // mount is attempted but the layer is still - // mounted and the operation cannot be performed. - ErrActiveMount = errors.New("mount still active") - - // ErrNotMounted is used when requesting an active - // mount but the layer is not mounted. - ErrNotMounted = errors.New("not mounted") - - // ErrMaxDepthExceeded is used when a layer is attempted - // to be created which would result in a layer depth - // greater than the 125 max. - ErrMaxDepthExceeded = errors.New("max depth exceeded") - - // ErrNotSupported is used when the action is not supported - // on the current platform - ErrNotSupported = errors.New("not support on this platform") -) - -// ChainID is the content-addressable ID of a layer. -type ChainID digest.Digest - -// String returns a string rendition of a layer ID -func (id ChainID) String() string { - return string(id) -} - -// DiffID is the hash of an individual layer tar. -type DiffID digest.Digest - -// String returns a string rendition of a layer DiffID -func (diffID DiffID) String() string { - return string(diffID) -} - -// TarStreamer represents an object which may -// have its contents exported as a tar stream. -type TarStreamer interface { - // TarStream returns a tar archive stream - // for the contents of a layer. - TarStream() (io.ReadCloser, error) -} - -// Layer represents a read-only layer -type Layer interface { - TarStreamer - - // TarStreamFrom returns a tar archive stream for all the layer chain with - // arbitrary depth. - TarStreamFrom(ChainID) (io.ReadCloser, error) - - // ChainID returns the content hash of the entire layer chain. The hash - // chain is made up of DiffID of top layer and all of its parents. - ChainID() ChainID - - // DiffID returns the content hash of the layer - // tar stream used to create this layer. - DiffID() DiffID - - // Parent returns the next layer in the layer chain. - Parent() Layer - - // Size returns the size of the entire layer chain. The size - // is calculated from the total size of all files in the layers. - Size() (int64, error) - - // DiffSize returns the size difference of the top layer - // from parent layer. - DiffSize() (int64, error) - - // Metadata returns the low level storage metadata associated - // with layer. - Metadata() (map[string]string, error) -} - -// RWLayer represents a layer which is -// read and writable -type RWLayer interface { - TarStreamer - - // Name of mounted layer - Name() string - - // Parent returns the layer which the writable - // layer was created from. - Parent() Layer - - // Mount mounts the RWLayer and returns the filesystem path - // the to the writable layer. - Mount(mountLabel string) (string, error) - - // Unmount unmounts the RWLayer. This should be called - // for every mount. If there are multiple mount calls - // this operation will only decrement the internal mount counter. - Unmount() error - - // Size represents the size of the writable layer - // as calculated by the total size of the files - // changed in the mutable layer. - Size() (int64, error) - - // Changes returns the set of changes for the mutable layer - // from the base layer. - Changes() ([]archive.Change, error) - - // Metadata returns the low level metadata for the mutable layer - Metadata() (map[string]string, error) -} - -// Metadata holds information about a -// read-only layer -type Metadata struct { - // ChainID is the content hash of the layer - ChainID ChainID - - // DiffID is the hash of the tar data used to - // create the layer - DiffID DiffID - - // Size is the size of the layer and all parents - Size int64 - - // DiffSize is the size of the top layer - DiffSize int64 -} - -// MountInit is a function to initialize a -// writable mount. Changes made here will -// not be included in the Tar stream of the -// RWLayer. -type MountInit func(root string) error - -// Store represents a backend for managing both -// read-only and read-write layers. -type Store interface { - Register(io.Reader, ChainID) (Layer, error) - Get(ChainID) (Layer, error) - Map() map[ChainID]Layer - Release(Layer) ([]Metadata, error) - - CreateRWLayer(id string, parent ChainID, mountLabel string, initFunc MountInit, storageOpt map[string]string) (RWLayer, error) - GetRWLayer(id string) (RWLayer, error) - GetMountID(id string) (string, error) - ReleaseRWLayer(RWLayer) ([]Metadata, error) - - Cleanup() error - DriverStatus() [][2]string - DriverName() string -} - -// DescribableStore represents a layer store capable of storing -// descriptors for layers. -type DescribableStore interface { - RegisterWithDescriptor(io.Reader, ChainID, distribution.Descriptor) (Layer, error) -} - -// MetadataTransaction represents functions for setting layer metadata -// with a single transaction. -type MetadataTransaction interface { - SetSize(int64) error - SetParent(parent ChainID) error - SetDiffID(DiffID) error - SetCacheID(string) error - SetDescriptor(distribution.Descriptor) error - TarSplitWriter(compressInput bool) (io.WriteCloser, error) - - Commit(ChainID) error - Cancel() error - String() string -} - -// MetadataStore represents a backend for persisting -// metadata about layers and providing the metadata -// for restoring a Store. -type MetadataStore interface { - // StartTransaction starts an update for new metadata - // which will be used to represent an ID on commit. - StartTransaction() (MetadataTransaction, error) - - GetSize(ChainID) (int64, error) - GetParent(ChainID) (ChainID, error) - GetDiffID(ChainID) (DiffID, error) - GetCacheID(ChainID) (string, error) - GetDescriptor(ChainID) (distribution.Descriptor, error) - TarSplitReader(ChainID) (io.ReadCloser, error) - - SetMountID(string, string) error - SetInitID(string, string) error - SetMountParent(string, ChainID) error - - GetMountID(string) (string, error) - GetInitID(string) (string, error) - GetMountParent(string) (ChainID, error) - - // List returns the full list of referenced - // read-only and read-write layers - List() ([]ChainID, []string, error) - - Remove(ChainID) error - RemoveMount(string) error -} - -// CreateChainID returns ID for a layerDigest slice -func CreateChainID(dgsts []DiffID) ChainID { - return createChainIDFromParent("", dgsts...) -} - -func createChainIDFromParent(parent ChainID, dgsts ...DiffID) ChainID { - if len(dgsts) == 0 { - return parent - } - if parent == "" { - return createChainIDFromParent(ChainID(dgsts[0]), dgsts[1:]...) - } - // H = "H(n-1) SHA256(n)" - dgst := digest.FromBytes([]byte(string(parent) + " " + string(dgsts[0]))) - return createChainIDFromParent(ChainID(dgst), dgsts[1:]...) -} - -// ReleaseAndLog releases the provided layer from the given layer -// store, logging any error and release metadata -func ReleaseAndLog(ls Store, l Layer) { - metadata, err := ls.Release(l) - if err != nil { - logrus.Errorf("Error releasing layer %s: %v", l.ChainID(), err) - } - LogReleaseMetadata(metadata) -} - -// LogReleaseMetadata logs a metadata array, uses this to -// ensure consistent logging for release metadata -func LogReleaseMetadata(metadatas []Metadata) { - for _, metadata := range metadatas { - logrus.Infof("Layer %s cleaned up", metadata.ChainID) - } -} diff --git a/vendor/github.com/docker/docker/layer/layer_store.go b/vendor/github.com/docker/docker/layer/layer_store.go deleted file mode 100644 index 1a1ff9f..0000000 --- a/vendor/github.com/docker/docker/layer/layer_store.go +++ /dev/null @@ -1,684 +0,0 @@ -package layer - -import ( - "errors" - "fmt" - "io" - "io/ioutil" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution" - "github.com/docker/distribution/digest" - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/plugingetter" - "github.com/docker/docker/pkg/stringid" - "github.com/vbatts/tar-split/tar/asm" - "github.com/vbatts/tar-split/tar/storage" -) - -// maxLayerDepth represents the maximum number of -// layers which can be chained together. 125 was -// chosen to account for the 127 max in some -// graphdrivers plus the 2 additional layers -// used to create a rwlayer. -const maxLayerDepth = 125 - -type layerStore struct { - store MetadataStore - driver graphdriver.Driver - - layerMap map[ChainID]*roLayer - layerL sync.Mutex - - mounts map[string]*mountedLayer - mountL sync.Mutex -} - -// StoreOptions are the options used to create a new Store instance -type StoreOptions struct { - StorePath string - MetadataStorePathTemplate string - GraphDriver string - GraphDriverOptions []string - UIDMaps []idtools.IDMap - GIDMaps []idtools.IDMap - PluginGetter plugingetter.PluginGetter - ExperimentalEnabled bool -} - -// NewStoreFromOptions creates a new Store instance -func NewStoreFromOptions(options StoreOptions) (Store, error) { - driver, err := graphdriver.New(options.GraphDriver, options.PluginGetter, graphdriver.Options{ - Root: options.StorePath, - DriverOptions: options.GraphDriverOptions, - UIDMaps: options.UIDMaps, - GIDMaps: options.GIDMaps, - ExperimentalEnabled: options.ExperimentalEnabled, - }) - if err != nil { - return nil, fmt.Errorf("error initializing graphdriver: %v", err) - } - logrus.Debugf("Using graph driver %s", driver) - - fms, err := NewFSMetadataStore(fmt.Sprintf(options.MetadataStorePathTemplate, driver)) - if err != nil { - return nil, err - } - - return NewStoreFromGraphDriver(fms, driver) -} - -// NewStoreFromGraphDriver creates a new Store instance using the provided -// metadata store and graph driver. The metadata store will be used to restore -// the Store. -func NewStoreFromGraphDriver(store MetadataStore, driver graphdriver.Driver) (Store, error) { - ls := &layerStore{ - store: store, - driver: driver, - layerMap: map[ChainID]*roLayer{}, - mounts: map[string]*mountedLayer{}, - } - - ids, mounts, err := store.List() - if err != nil { - return nil, err - } - - for _, id := range ids { - l, err := ls.loadLayer(id) - if err != nil { - logrus.Debugf("Failed to load layer %s: %s", id, err) - continue - } - if l.parent != nil { - l.parent.referenceCount++ - } - } - - for _, mount := range mounts { - if err := ls.loadMount(mount); err != nil { - logrus.Debugf("Failed to load mount %s: %s", mount, err) - } - } - - return ls, nil -} - -func (ls *layerStore) loadLayer(layer ChainID) (*roLayer, error) { - cl, ok := ls.layerMap[layer] - if ok { - return cl, nil - } - - diff, err := ls.store.GetDiffID(layer) - if err != nil { - return nil, fmt.Errorf("failed to get diff id for %s: %s", layer, err) - } - - size, err := ls.store.GetSize(layer) - if err != nil { - return nil, fmt.Errorf("failed to get size for %s: %s", layer, err) - } - - cacheID, err := ls.store.GetCacheID(layer) - if err != nil { - return nil, fmt.Errorf("failed to get cache id for %s: %s", layer, err) - } - - parent, err := ls.store.GetParent(layer) - if err != nil { - return nil, fmt.Errorf("failed to get parent for %s: %s", layer, err) - } - - descriptor, err := ls.store.GetDescriptor(layer) - if err != nil { - return nil, fmt.Errorf("failed to get descriptor for %s: %s", layer, err) - } - - cl = &roLayer{ - chainID: layer, - diffID: diff, - size: size, - cacheID: cacheID, - layerStore: ls, - references: map[Layer]struct{}{}, - descriptor: descriptor, - } - - if parent != "" { - p, err := ls.loadLayer(parent) - if err != nil { - return nil, err - } - cl.parent = p - } - - ls.layerMap[cl.chainID] = cl - - return cl, nil -} - -func (ls *layerStore) loadMount(mount string) error { - if _, ok := ls.mounts[mount]; ok { - return nil - } - - mountID, err := ls.store.GetMountID(mount) - if err != nil { - return err - } - - initID, err := ls.store.GetInitID(mount) - if err != nil { - return err - } - - parent, err := ls.store.GetMountParent(mount) - if err != nil { - return err - } - - ml := &mountedLayer{ - name: mount, - mountID: mountID, - initID: initID, - layerStore: ls, - references: map[RWLayer]*referencedRWLayer{}, - } - - if parent != "" { - p, err := ls.loadLayer(parent) - if err != nil { - return err - } - ml.parent = p - - p.referenceCount++ - } - - ls.mounts[ml.name] = ml - - return nil -} - -func (ls *layerStore) applyTar(tx MetadataTransaction, ts io.Reader, parent string, layer *roLayer) error { - digester := digest.Canonical.New() - tr := io.TeeReader(ts, digester.Hash()) - - tsw, err := tx.TarSplitWriter(true) - if err != nil { - return err - } - metaPacker := storage.NewJSONPacker(tsw) - defer tsw.Close() - - // we're passing nil here for the file putter, because the ApplyDiff will - // handle the extraction of the archive - rdr, err := asm.NewInputTarStream(tr, metaPacker, nil) - if err != nil { - return err - } - - applySize, err := ls.driver.ApplyDiff(layer.cacheID, parent, rdr) - if err != nil { - return err - } - - // Discard trailing data but ensure metadata is picked up to reconstruct stream - io.Copy(ioutil.Discard, rdr) // ignore error as reader may be closed - - layer.size = applySize - layer.diffID = DiffID(digester.Digest()) - - logrus.Debugf("Applied tar %s to %s, size: %d", layer.diffID, layer.cacheID, applySize) - - return nil -} - -func (ls *layerStore) Register(ts io.Reader, parent ChainID) (Layer, error) { - return ls.registerWithDescriptor(ts, parent, distribution.Descriptor{}) -} - -func (ls *layerStore) registerWithDescriptor(ts io.Reader, parent ChainID, descriptor distribution.Descriptor) (Layer, error) { - // err is used to hold the error which will always trigger - // cleanup of creates sources but may not be an error returned - // to the caller (already exists). - var err error - var pid string - var p *roLayer - if string(parent) != "" { - p = ls.get(parent) - if p == nil { - return nil, ErrLayerDoesNotExist - } - pid = p.cacheID - // Release parent chain if error - defer func() { - if err != nil { - ls.layerL.Lock() - ls.releaseLayer(p) - ls.layerL.Unlock() - } - }() - if p.depth() >= maxLayerDepth { - err = ErrMaxDepthExceeded - return nil, err - } - } - - // Create new roLayer - layer := &roLayer{ - parent: p, - cacheID: stringid.GenerateRandomID(), - referenceCount: 1, - layerStore: ls, - references: map[Layer]struct{}{}, - descriptor: descriptor, - } - - if err = ls.driver.Create(layer.cacheID, pid, nil); err != nil { - return nil, err - } - - tx, err := ls.store.StartTransaction() - if err != nil { - return nil, err - } - - defer func() { - if err != nil { - logrus.Debugf("Cleaning up layer %s: %v", layer.cacheID, err) - if err := ls.driver.Remove(layer.cacheID); err != nil { - logrus.Errorf("Error cleaning up cache layer %s: %v", layer.cacheID, err) - } - if err := tx.Cancel(); err != nil { - logrus.Errorf("Error canceling metadata transaction %q: %s", tx.String(), err) - } - } - }() - - if err = ls.applyTar(tx, ts, pid, layer); err != nil { - return nil, err - } - - if layer.parent == nil { - layer.chainID = ChainID(layer.diffID) - } else { - layer.chainID = createChainIDFromParent(layer.parent.chainID, layer.diffID) - } - - if err = storeLayer(tx, layer); err != nil { - return nil, err - } - - ls.layerL.Lock() - defer ls.layerL.Unlock() - - if existingLayer := ls.getWithoutLock(layer.chainID); existingLayer != nil { - // Set error for cleanup, but do not return the error - err = errors.New("layer already exists") - return existingLayer.getReference(), nil - } - - if err = tx.Commit(layer.chainID); err != nil { - return nil, err - } - - ls.layerMap[layer.chainID] = layer - - return layer.getReference(), nil -} - -func (ls *layerStore) getWithoutLock(layer ChainID) *roLayer { - l, ok := ls.layerMap[layer] - if !ok { - return nil - } - - l.referenceCount++ - - return l -} - -func (ls *layerStore) get(l ChainID) *roLayer { - ls.layerL.Lock() - defer ls.layerL.Unlock() - return ls.getWithoutLock(l) -} - -func (ls *layerStore) Get(l ChainID) (Layer, error) { - ls.layerL.Lock() - defer ls.layerL.Unlock() - - layer := ls.getWithoutLock(l) - if layer == nil { - return nil, ErrLayerDoesNotExist - } - - return layer.getReference(), nil -} - -func (ls *layerStore) Map() map[ChainID]Layer { - ls.layerL.Lock() - defer ls.layerL.Unlock() - - layers := map[ChainID]Layer{} - - for k, v := range ls.layerMap { - layers[k] = v - } - - return layers -} - -func (ls *layerStore) deleteLayer(layer *roLayer, metadata *Metadata) error { - err := ls.driver.Remove(layer.cacheID) - if err != nil { - return err - } - - err = ls.store.Remove(layer.chainID) - if err != nil { - return err - } - metadata.DiffID = layer.diffID - metadata.ChainID = layer.chainID - metadata.Size, err = layer.Size() - if err != nil { - return err - } - metadata.DiffSize = layer.size - - return nil -} - -func (ls *layerStore) releaseLayer(l *roLayer) ([]Metadata, error) { - depth := 0 - removed := []Metadata{} - for { - if l.referenceCount == 0 { - panic("layer not retained") - } - l.referenceCount-- - if l.referenceCount != 0 { - return removed, nil - } - - if len(removed) == 0 && depth > 0 { - panic("cannot remove layer with child") - } - if l.hasReferences() { - panic("cannot delete referenced layer") - } - var metadata Metadata - if err := ls.deleteLayer(l, &metadata); err != nil { - return nil, err - } - - delete(ls.layerMap, l.chainID) - removed = append(removed, metadata) - - if l.parent == nil { - return removed, nil - } - - depth++ - l = l.parent - } -} - -func (ls *layerStore) Release(l Layer) ([]Metadata, error) { - ls.layerL.Lock() - defer ls.layerL.Unlock() - layer, ok := ls.layerMap[l.ChainID()] - if !ok { - return []Metadata{}, nil - } - if !layer.hasReference(l) { - return nil, ErrLayerNotRetained - } - - layer.deleteReference(l) - - return ls.releaseLayer(layer) -} - -func (ls *layerStore) CreateRWLayer(name string, parent ChainID, mountLabel string, initFunc MountInit, storageOpt map[string]string) (RWLayer, error) { - ls.mountL.Lock() - defer ls.mountL.Unlock() - m, ok := ls.mounts[name] - if ok { - return nil, ErrMountNameConflict - } - - var err error - var pid string - var p *roLayer - if string(parent) != "" { - p = ls.get(parent) - if p == nil { - return nil, ErrLayerDoesNotExist - } - pid = p.cacheID - - // Release parent chain if error - defer func() { - if err != nil { - ls.layerL.Lock() - ls.releaseLayer(p) - ls.layerL.Unlock() - } - }() - } - - m = &mountedLayer{ - name: name, - parent: p, - mountID: ls.mountID(name), - layerStore: ls, - references: map[RWLayer]*referencedRWLayer{}, - } - - if initFunc != nil { - pid, err = ls.initMount(m.mountID, pid, mountLabel, initFunc, storageOpt) - if err != nil { - return nil, err - } - m.initID = pid - } - - createOpts := &graphdriver.CreateOpts{ - StorageOpt: storageOpt, - } - - if err = ls.driver.CreateReadWrite(m.mountID, pid, createOpts); err != nil { - return nil, err - } - - if err = ls.saveMount(m); err != nil { - return nil, err - } - - return m.getReference(), nil -} - -func (ls *layerStore) GetRWLayer(id string) (RWLayer, error) { - ls.mountL.Lock() - defer ls.mountL.Unlock() - mount, ok := ls.mounts[id] - if !ok { - return nil, ErrMountDoesNotExist - } - - return mount.getReference(), nil -} - -func (ls *layerStore) GetMountID(id string) (string, error) { - ls.mountL.Lock() - defer ls.mountL.Unlock() - mount, ok := ls.mounts[id] - if !ok { - return "", ErrMountDoesNotExist - } - logrus.Debugf("GetMountID id: %s -> mountID: %s", id, mount.mountID) - - return mount.mountID, nil -} - -func (ls *layerStore) ReleaseRWLayer(l RWLayer) ([]Metadata, error) { - ls.mountL.Lock() - defer ls.mountL.Unlock() - m, ok := ls.mounts[l.Name()] - if !ok { - return []Metadata{}, nil - } - - if err := m.deleteReference(l); err != nil { - return nil, err - } - - if m.hasReferences() { - return []Metadata{}, nil - } - - if err := ls.driver.Remove(m.mountID); err != nil { - logrus.Errorf("Error removing mounted layer %s: %s", m.name, err) - m.retakeReference(l) - return nil, err - } - - if m.initID != "" { - if err := ls.driver.Remove(m.initID); err != nil { - logrus.Errorf("Error removing init layer %s: %s", m.name, err) - m.retakeReference(l) - return nil, err - } - } - - if err := ls.store.RemoveMount(m.name); err != nil { - logrus.Errorf("Error removing mount metadata: %s: %s", m.name, err) - m.retakeReference(l) - return nil, err - } - - delete(ls.mounts, m.Name()) - - ls.layerL.Lock() - defer ls.layerL.Unlock() - if m.parent != nil { - return ls.releaseLayer(m.parent) - } - - return []Metadata{}, nil -} - -func (ls *layerStore) saveMount(mount *mountedLayer) error { - if err := ls.store.SetMountID(mount.name, mount.mountID); err != nil { - return err - } - - if mount.initID != "" { - if err := ls.store.SetInitID(mount.name, mount.initID); err != nil { - return err - } - } - - if mount.parent != nil { - if err := ls.store.SetMountParent(mount.name, mount.parent.chainID); err != nil { - return err - } - } - - ls.mounts[mount.name] = mount - - return nil -} - -func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc MountInit, storageOpt map[string]string) (string, error) { - // Use "-init" to maintain compatibility with graph drivers - // which are expecting this layer with this special name. If all - // graph drivers can be updated to not rely on knowing about this layer - // then the initID should be randomly generated. - initID := fmt.Sprintf("%s-init", graphID) - - createOpts := &graphdriver.CreateOpts{ - MountLabel: mountLabel, - StorageOpt: storageOpt, - } - - if err := ls.driver.CreateReadWrite(initID, parent, createOpts); err != nil { - return "", err - } - p, err := ls.driver.Get(initID, "") - if err != nil { - return "", err - } - - if err := initFunc(p); err != nil { - ls.driver.Put(initID) - return "", err - } - - if err := ls.driver.Put(initID); err != nil { - return "", err - } - - return initID, nil -} - -func (ls *layerStore) assembleTarTo(graphID string, metadata io.ReadCloser, size *int64, w io.Writer) error { - diffDriver, ok := ls.driver.(graphdriver.DiffGetterDriver) - if !ok { - diffDriver = &naiveDiffPathDriver{ls.driver} - } - - defer metadata.Close() - - // get our relative path to the container - fileGetCloser, err := diffDriver.DiffGetter(graphID) - if err != nil { - return err - } - defer fileGetCloser.Close() - - metaUnpacker := storage.NewJSONUnpacker(metadata) - upackerCounter := &unpackSizeCounter{metaUnpacker, size} - logrus.Debugf("Assembling tar data for %s", graphID) - return asm.WriteOutputTarStream(fileGetCloser, upackerCounter, w) -} - -func (ls *layerStore) Cleanup() error { - return ls.driver.Cleanup() -} - -func (ls *layerStore) DriverStatus() [][2]string { - return ls.driver.Status() -} - -func (ls *layerStore) DriverName() string { - return ls.driver.String() -} - -type naiveDiffPathDriver struct { - graphdriver.Driver -} - -type fileGetPutter struct { - storage.FileGetter - driver graphdriver.Driver - id string -} - -func (w *fileGetPutter) Close() error { - return w.driver.Put(w.id) -} - -func (n *naiveDiffPathDriver) DiffGetter(id string) (graphdriver.FileGetCloser, error) { - p, err := n.Driver.Get(id, "") - if err != nil { - return nil, err - } - return &fileGetPutter{storage.NewPathFileGetter(p), n.Driver, id}, nil -} diff --git a/vendor/github.com/docker/docker/layer/layer_store_windows.go b/vendor/github.com/docker/docker/layer/layer_store_windows.go deleted file mode 100644 index 1276a91..0000000 --- a/vendor/github.com/docker/docker/layer/layer_store_windows.go +++ /dev/null @@ -1,11 +0,0 @@ -package layer - -import ( - "io" - - "github.com/docker/distribution" -) - -func (ls *layerStore) RegisterWithDescriptor(ts io.Reader, parent ChainID, descriptor distribution.Descriptor) (Layer, error) { - return ls.registerWithDescriptor(ts, parent, descriptor) -} diff --git a/vendor/github.com/docker/docker/layer/layer_test.go b/vendor/github.com/docker/docker/layer/layer_test.go deleted file mode 100644 index 10712df..0000000 --- a/vendor/github.com/docker/docker/layer/layer_test.go +++ /dev/null @@ -1,771 +0,0 @@ -package layer - -import ( - "bytes" - "io" - "io/ioutil" - "os" - "path/filepath" - "runtime" - "strings" - "testing" - - "github.com/docker/distribution/digest" - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/daemon/graphdriver/vfs" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/stringid" -) - -func init() { - graphdriver.ApplyUncompressedLayer = archive.UnpackLayer - vfs.CopyWithTar = archive.CopyWithTar -} - -func newVFSGraphDriver(td string) (graphdriver.Driver, error) { - uidMap := []idtools.IDMap{ - { - ContainerID: 0, - HostID: os.Getuid(), - Size: 1, - }, - } - gidMap := []idtools.IDMap{ - { - ContainerID: 0, - HostID: os.Getgid(), - Size: 1, - }, - } - - options := graphdriver.Options{Root: td, UIDMaps: uidMap, GIDMaps: gidMap} - return graphdriver.GetDriver("vfs", nil, options) -} - -func newTestGraphDriver(t *testing.T) (graphdriver.Driver, func()) { - td, err := ioutil.TempDir("", "graph-") - if err != nil { - t.Fatal(err) - } - - driver, err := newVFSGraphDriver(td) - if err != nil { - t.Fatal(err) - } - - return driver, func() { - os.RemoveAll(td) - } -} - -func newTestStore(t *testing.T) (Store, string, func()) { - td, err := ioutil.TempDir("", "layerstore-") - if err != nil { - t.Fatal(err) - } - - graph, graphcleanup := newTestGraphDriver(t) - fms, err := NewFSMetadataStore(td) - if err != nil { - t.Fatal(err) - } - ls, err := NewStoreFromGraphDriver(fms, graph) - if err != nil { - t.Fatal(err) - } - - return ls, td, func() { - graphcleanup() - os.RemoveAll(td) - } -} - -type layerInit func(root string) error - -func createLayer(ls Store, parent ChainID, layerFunc layerInit) (Layer, error) { - containerID := stringid.GenerateRandomID() - mount, err := ls.CreateRWLayer(containerID, parent, "", nil, nil) - if err != nil { - return nil, err - } - - path, err := mount.Mount("") - if err != nil { - return nil, err - } - - if err := layerFunc(path); err != nil { - return nil, err - } - - ts, err := mount.TarStream() - if err != nil { - return nil, err - } - defer ts.Close() - - layer, err := ls.Register(ts, parent) - if err != nil { - return nil, err - } - - if err := mount.Unmount(); err != nil { - return nil, err - } - - if _, err := ls.ReleaseRWLayer(mount); err != nil { - return nil, err - } - - return layer, nil -} - -type FileApplier interface { - ApplyFile(root string) error -} - -type testFile struct { - name string - content []byte - permission os.FileMode -} - -func newTestFile(name string, content []byte, perm os.FileMode) FileApplier { - return &testFile{ - name: name, - content: content, - permission: perm, - } -} - -func (tf *testFile) ApplyFile(root string) error { - fullPath := filepath.Join(root, tf.name) - if err := os.MkdirAll(filepath.Dir(fullPath), 0755); err != nil { - return err - } - // Check if already exists - if stat, err := os.Stat(fullPath); err == nil && stat.Mode().Perm() != tf.permission { - if err := os.Chmod(fullPath, tf.permission); err != nil { - return err - } - } - if err := ioutil.WriteFile(fullPath, tf.content, tf.permission); err != nil { - return err - } - return nil -} - -func initWithFiles(files ...FileApplier) layerInit { - return func(root string) error { - for _, f := range files { - if err := f.ApplyFile(root); err != nil { - return err - } - } - return nil - } -} - -func getCachedLayer(l Layer) *roLayer { - if rl, ok := l.(*referencedCacheLayer); ok { - return rl.roLayer - } - return l.(*roLayer) -} - -func getMountLayer(l RWLayer) *mountedLayer { - return l.(*referencedRWLayer).mountedLayer -} - -func createMetadata(layers ...Layer) []Metadata { - metadata := make([]Metadata, len(layers)) - for i := range layers { - size, err := layers[i].Size() - if err != nil { - panic(err) - } - - metadata[i].ChainID = layers[i].ChainID() - metadata[i].DiffID = layers[i].DiffID() - metadata[i].Size = size - metadata[i].DiffSize = getCachedLayer(layers[i]).size - } - - return metadata -} - -func assertMetadata(t *testing.T, metadata, expectedMetadata []Metadata) { - if len(metadata) != len(expectedMetadata) { - t.Fatalf("Unexpected number of deletes %d, expected %d", len(metadata), len(expectedMetadata)) - } - - for i := range metadata { - if metadata[i] != expectedMetadata[i] { - t.Errorf("Unexpected metadata\n\tExpected: %#v\n\tActual: %#v", expectedMetadata[i], metadata[i]) - } - } - if t.Failed() { - t.FailNow() - } -} - -func releaseAndCheckDeleted(t *testing.T, ls Store, layer Layer, removed ...Layer) { - layerCount := len(ls.(*layerStore).layerMap) - expectedMetadata := createMetadata(removed...) - metadata, err := ls.Release(layer) - if err != nil { - t.Fatal(err) - } - - assertMetadata(t, metadata, expectedMetadata) - - if expected := layerCount - len(removed); len(ls.(*layerStore).layerMap) != expected { - t.Fatalf("Unexpected number of layers %d, expected %d", len(ls.(*layerStore).layerMap), expected) - } -} - -func cacheID(l Layer) string { - return getCachedLayer(l).cacheID -} - -func assertLayerEqual(t *testing.T, l1, l2 Layer) { - if l1.ChainID() != l2.ChainID() { - t.Fatalf("Mismatched ID: %s vs %s", l1.ChainID(), l2.ChainID()) - } - if l1.DiffID() != l2.DiffID() { - t.Fatalf("Mismatched DiffID: %s vs %s", l1.DiffID(), l2.DiffID()) - } - - size1, err := l1.Size() - if err != nil { - t.Fatal(err) - } - - size2, err := l2.Size() - if err != nil { - t.Fatal(err) - } - - if size1 != size2 { - t.Fatalf("Mismatched size: %d vs %d", size1, size2) - } - - if cacheID(l1) != cacheID(l2) { - t.Fatalf("Mismatched cache id: %s vs %s", cacheID(l1), cacheID(l2)) - } - - p1 := l1.Parent() - p2 := l2.Parent() - if p1 != nil && p2 != nil { - assertLayerEqual(t, p1, p2) - } else if p1 != nil || p2 != nil { - t.Fatalf("Mismatched parents: %v vs %v", p1, p2) - } -} - -func TestMountAndRegister(t *testing.T) { - ls, _, cleanup := newTestStore(t) - defer cleanup() - - li := initWithFiles(newTestFile("testfile.txt", []byte("some test data"), 0644)) - layer, err := createLayer(ls, "", li) - if err != nil { - t.Fatal(err) - } - - size, _ := layer.Size() - t.Logf("Layer size: %d", size) - - mount2, err := ls.CreateRWLayer("new-test-mount", layer.ChainID(), "", nil, nil) - if err != nil { - t.Fatal(err) - } - - path2, err := mount2.Mount("") - if err != nil { - t.Fatal(err) - } - - b, err := ioutil.ReadFile(filepath.Join(path2, "testfile.txt")) - if err != nil { - t.Fatal(err) - } - - if expected := "some test data"; string(b) != expected { - t.Fatalf("Wrong file data, expected %q, got %q", expected, string(b)) - } - - if err := mount2.Unmount(); err != nil { - t.Fatal(err) - } - - if _, err := ls.ReleaseRWLayer(mount2); err != nil { - t.Fatal(err) - } -} - -func TestLayerRelease(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - ls, _, cleanup := newTestStore(t) - defer cleanup() - - layer1, err := createLayer(ls, "", initWithFiles(newTestFile("layer1.txt", []byte("layer 1 file"), 0644))) - if err != nil { - t.Fatal(err) - } - - layer2, err := createLayer(ls, layer1.ChainID(), initWithFiles(newTestFile("layer2.txt", []byte("layer 2 file"), 0644))) - if err != nil { - t.Fatal(err) - } - - if _, err := ls.Release(layer1); err != nil { - t.Fatal(err) - } - - layer3a, err := createLayer(ls, layer2.ChainID(), initWithFiles(newTestFile("layer3.txt", []byte("layer 3a file"), 0644))) - if err != nil { - t.Fatal(err) - } - - layer3b, err := createLayer(ls, layer2.ChainID(), initWithFiles(newTestFile("layer3.txt", []byte("layer 3b file"), 0644))) - if err != nil { - t.Fatal(err) - } - - if _, err := ls.Release(layer2); err != nil { - t.Fatal(err) - } - - t.Logf("Layer1: %s", layer1.ChainID()) - t.Logf("Layer2: %s", layer2.ChainID()) - t.Logf("Layer3a: %s", layer3a.ChainID()) - t.Logf("Layer3b: %s", layer3b.ChainID()) - - if expected := 4; len(ls.(*layerStore).layerMap) != expected { - t.Fatalf("Unexpected number of layers %d, expected %d", len(ls.(*layerStore).layerMap), expected) - } - - releaseAndCheckDeleted(t, ls, layer3b, layer3b) - releaseAndCheckDeleted(t, ls, layer3a, layer3a, layer2, layer1) -} - -func TestStoreRestore(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - ls, _, cleanup := newTestStore(t) - defer cleanup() - - layer1, err := createLayer(ls, "", initWithFiles(newTestFile("layer1.txt", []byte("layer 1 file"), 0644))) - if err != nil { - t.Fatal(err) - } - - layer2, err := createLayer(ls, layer1.ChainID(), initWithFiles(newTestFile("layer2.txt", []byte("layer 2 file"), 0644))) - if err != nil { - t.Fatal(err) - } - - if _, err := ls.Release(layer1); err != nil { - t.Fatal(err) - } - - layer3, err := createLayer(ls, layer2.ChainID(), initWithFiles(newTestFile("layer3.txt", []byte("layer 3 file"), 0644))) - if err != nil { - t.Fatal(err) - } - - if _, err := ls.Release(layer2); err != nil { - t.Fatal(err) - } - - m, err := ls.CreateRWLayer("some-mount_name", layer3.ChainID(), "", nil, nil) - if err != nil { - t.Fatal(err) - } - - path, err := m.Mount("") - if err != nil { - t.Fatal(err) - } - - if err := ioutil.WriteFile(filepath.Join(path, "testfile.txt"), []byte("nothing here"), 0644); err != nil { - t.Fatal(err) - } - - if err := m.Unmount(); err != nil { - t.Fatal(err) - } - - ls2, err := NewStoreFromGraphDriver(ls.(*layerStore).store, ls.(*layerStore).driver) - if err != nil { - t.Fatal(err) - } - - layer3b, err := ls2.Get(layer3.ChainID()) - if err != nil { - t.Fatal(err) - } - - assertLayerEqual(t, layer3b, layer3) - - // Create again with same name, should return error - if _, err := ls2.CreateRWLayer("some-mount_name", layer3b.ChainID(), "", nil, nil); err == nil { - t.Fatal("Expected error creating mount with same name") - } else if err != ErrMountNameConflict { - t.Fatal(err) - } - - m2, err := ls2.GetRWLayer("some-mount_name") - if err != nil { - t.Fatal(err) - } - - if mountPath, err := m2.Mount(""); err != nil { - t.Fatal(err) - } else if path != mountPath { - t.Fatalf("Unexpected path %s, expected %s", mountPath, path) - } - - if mountPath, err := m2.Mount(""); err != nil { - t.Fatal(err) - } else if path != mountPath { - t.Fatalf("Unexpected path %s, expected %s", mountPath, path) - } - if err := m2.Unmount(); err != nil { - t.Fatal(err) - } - - b, err := ioutil.ReadFile(filepath.Join(path, "testfile.txt")) - if err != nil { - t.Fatal(err) - } - if expected := "nothing here"; string(b) != expected { - t.Fatalf("Unexpected content %q, expected %q", string(b), expected) - } - - if err := m2.Unmount(); err != nil { - t.Fatal(err) - } - - if metadata, err := ls2.ReleaseRWLayer(m2); err != nil { - t.Fatal(err) - } else if len(metadata) != 0 { - t.Fatalf("Unexpectedly deleted layers: %#v", metadata) - } - - if metadata, err := ls2.ReleaseRWLayer(m2); err != nil { - t.Fatal(err) - } else if len(metadata) != 0 { - t.Fatalf("Unexpectedly deleted layers: %#v", metadata) - } - - releaseAndCheckDeleted(t, ls2, layer3b, layer3, layer2, layer1) -} - -func TestTarStreamStability(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - ls, _, cleanup := newTestStore(t) - defer cleanup() - - files1 := []FileApplier{ - newTestFile("/etc/hosts", []byte("mydomain 10.0.0.1"), 0644), - newTestFile("/etc/profile", []byte("PATH=/usr/bin"), 0644), - } - addedFile := newTestFile("/etc/shadow", []byte("root:::::::"), 0644) - files2 := []FileApplier{ - newTestFile("/etc/hosts", []byte("mydomain 10.0.0.2"), 0644), - newTestFile("/etc/profile", []byte("PATH=/usr/bin"), 0664), - newTestFile("/root/.bashrc", []byte("PATH=/usr/sbin:/usr/bin"), 0644), - } - - tar1, err := tarFromFiles(files1...) - if err != nil { - t.Fatal(err) - } - - tar2, err := tarFromFiles(files2...) - if err != nil { - t.Fatal(err) - } - - layer1, err := ls.Register(bytes.NewReader(tar1), "") - if err != nil { - t.Fatal(err) - } - - // hack layer to add file - p, err := ls.(*layerStore).driver.Get(layer1.(*referencedCacheLayer).cacheID, "") - if err != nil { - t.Fatal(err) - } - - if err := addedFile.ApplyFile(p); err != nil { - t.Fatal(err) - } - - if err := ls.(*layerStore).driver.Put(layer1.(*referencedCacheLayer).cacheID); err != nil { - t.Fatal(err) - } - - layer2, err := ls.Register(bytes.NewReader(tar2), layer1.ChainID()) - if err != nil { - t.Fatal(err) - } - - id1 := layer1.ChainID() - t.Logf("Layer 1: %s", layer1.ChainID()) - t.Logf("Layer 2: %s", layer2.ChainID()) - - if _, err := ls.Release(layer1); err != nil { - t.Fatal(err) - } - - assertLayerDiff(t, tar2, layer2) - - layer1b, err := ls.Get(id1) - if err != nil { - t.Logf("Content of layer map: %#v", ls.(*layerStore).layerMap) - t.Fatal(err) - } - - if _, err := ls.Release(layer2); err != nil { - t.Fatal(err) - } - - assertLayerDiff(t, tar1, layer1b) - - if _, err := ls.Release(layer1b); err != nil { - t.Fatal(err) - } -} - -func assertLayerDiff(t *testing.T, expected []byte, layer Layer) { - expectedDigest := digest.FromBytes(expected) - - if digest.Digest(layer.DiffID()) != expectedDigest { - t.Fatalf("Mismatched diff id for %s, got %s, expected %s", layer.ChainID(), layer.DiffID(), expected) - } - - ts, err := layer.TarStream() - if err != nil { - t.Fatal(err) - } - defer ts.Close() - - actual, err := ioutil.ReadAll(ts) - if err != nil { - t.Fatal(err) - } - - if len(actual) != len(expected) { - logByteDiff(t, actual, expected) - t.Fatalf("Mismatched tar stream size for %s, got %d, expected %d", layer.ChainID(), len(actual), len(expected)) - } - - actualDigest := digest.FromBytes(actual) - - if actualDigest != expectedDigest { - logByteDiff(t, actual, expected) - t.Fatalf("Wrong digest of tar stream, got %s, expected %s", actualDigest, expectedDigest) - } -} - -const maxByteLog = 4 * 1024 - -func logByteDiff(t *testing.T, actual, expected []byte) { - d1, d2 := byteDiff(actual, expected) - if len(d1) == 0 && len(d2) == 0 { - return - } - - prefix := len(actual) - len(d1) - if len(d1) > maxByteLog || len(d2) > maxByteLog { - t.Logf("Byte diff after %d matching bytes", prefix) - } else { - t.Logf("Byte diff after %d matching bytes\nActual bytes after prefix:\n%x\nExpected bytes after prefix:\n%x", prefix, d1, d2) - } -} - -// byteDiff returns the differing bytes after the matching prefix -func byteDiff(b1, b2 []byte) ([]byte, []byte) { - i := 0 - for i < len(b1) && i < len(b2) { - if b1[i] != b2[i] { - break - } - i++ - } - - return b1[i:], b2[i:] -} - -func tarFromFiles(files ...FileApplier) ([]byte, error) { - td, err := ioutil.TempDir("", "tar-") - if err != nil { - return nil, err - } - defer os.RemoveAll(td) - - for _, f := range files { - if err := f.ApplyFile(td); err != nil { - return nil, err - } - } - - r, err := archive.Tar(td, archive.Uncompressed) - if err != nil { - return nil, err - } - - buf := bytes.NewBuffer(nil) - if _, err := io.Copy(buf, r); err != nil { - return nil, err - } - - return buf.Bytes(), nil -} - -// assertReferences asserts that all the references are to the same -// image and represent the full set of references to that image. -func assertReferences(t *testing.T, references ...Layer) { - if len(references) == 0 { - return - } - base := references[0].(*referencedCacheLayer).roLayer - seenReferences := map[Layer]struct{}{ - references[0]: {}, - } - for i := 1; i < len(references); i++ { - other := references[i].(*referencedCacheLayer).roLayer - if base != other { - t.Fatalf("Unexpected referenced cache layer %s, expecting %s", other.ChainID(), base.ChainID()) - } - if _, ok := base.references[references[i]]; !ok { - t.Fatalf("Reference not part of reference list: %v", references[i]) - } - if _, ok := seenReferences[references[i]]; ok { - t.Fatalf("Duplicated reference %v", references[i]) - } - } - if rc := len(base.references); rc != len(references) { - t.Fatalf("Unexpected number of references %d, expecting %d", rc, len(references)) - } -} - -func TestRegisterExistingLayer(t *testing.T) { - ls, _, cleanup := newTestStore(t) - defer cleanup() - - baseFiles := []FileApplier{ - newTestFile("/etc/profile", []byte("# Base configuration"), 0644), - } - - layerFiles := []FileApplier{ - newTestFile("/root/.bashrc", []byte("# Root configuration"), 0644), - } - - li := initWithFiles(baseFiles...) - layer1, err := createLayer(ls, "", li) - if err != nil { - t.Fatal(err) - } - - tar1, err := tarFromFiles(layerFiles...) - if err != nil { - t.Fatal(err) - } - - layer2a, err := ls.Register(bytes.NewReader(tar1), layer1.ChainID()) - if err != nil { - t.Fatal(err) - } - - layer2b, err := ls.Register(bytes.NewReader(tar1), layer1.ChainID()) - if err != nil { - t.Fatal(err) - } - - assertReferences(t, layer2a, layer2b) -} - -func TestTarStreamVerification(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - ls, tmpdir, cleanup := newTestStore(t) - defer cleanup() - - files1 := []FileApplier{ - newTestFile("/foo", []byte("abc"), 0644), - newTestFile("/bar", []byte("def"), 0644), - } - files2 := []FileApplier{ - newTestFile("/foo", []byte("abc"), 0644), - newTestFile("/bar", []byte("def"), 0600), // different perm - } - - tar1, err := tarFromFiles(files1...) - if err != nil { - t.Fatal(err) - } - - tar2, err := tarFromFiles(files2...) - if err != nil { - t.Fatal(err) - } - - layer1, err := ls.Register(bytes.NewReader(tar1), "") - if err != nil { - t.Fatal(err) - } - - layer2, err := ls.Register(bytes.NewReader(tar2), "") - if err != nil { - t.Fatal(err) - } - id1 := digest.Digest(layer1.ChainID()) - id2 := digest.Digest(layer2.ChainID()) - - // Replace tar data files - src, err := os.Open(filepath.Join(tmpdir, id1.Algorithm().String(), id1.Hex(), "tar-split.json.gz")) - if err != nil { - t.Fatal(err) - } - defer src.Close() - - dst, err := os.Create(filepath.Join(tmpdir, id2.Algorithm().String(), id2.Hex(), "tar-split.json.gz")) - if err != nil { - t.Fatal(err) - } - defer dst.Close() - - if _, err := io.Copy(dst, src); err != nil { - t.Fatal(err) - } - - src.Sync() - dst.Sync() - - ts, err := layer2.TarStream() - if err != nil { - t.Fatal(err) - } - _, err = io.Copy(ioutil.Discard, ts) - if err == nil { - t.Fatal("expected data verification to fail") - } - if !strings.Contains(err.Error(), "could not verify layer data") { - t.Fatalf("wrong error returned from tarstream: %q", err) - } -} diff --git a/vendor/github.com/docker/docker/layer/layer_unix.go b/vendor/github.com/docker/docker/layer/layer_unix.go deleted file mode 100644 index 776b78a..0000000 --- a/vendor/github.com/docker/docker/layer/layer_unix.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build linux freebsd darwin openbsd solaris - -package layer - -import "github.com/docker/docker/pkg/stringid" - -func (ls *layerStore) mountID(name string) string { - return stringid.GenerateRandomID() -} diff --git a/vendor/github.com/docker/docker/layer/layer_unix_test.go b/vendor/github.com/docker/docker/layer/layer_unix_test.go deleted file mode 100644 index 9aa1afd..0000000 --- a/vendor/github.com/docker/docker/layer/layer_unix_test.go +++ /dev/null @@ -1,71 +0,0 @@ -// +build !windows - -package layer - -import "testing" - -func graphDiffSize(ls Store, l Layer) (int64, error) { - cl := getCachedLayer(l) - var parent string - if cl.parent != nil { - parent = cl.parent.cacheID - } - return ls.(*layerStore).driver.DiffSize(cl.cacheID, parent) -} - -// Unix as Windows graph driver does not support Changes which is indirectly -// invoked by calling DiffSize on the driver -func TestLayerSize(t *testing.T) { - ls, _, cleanup := newTestStore(t) - defer cleanup() - - content1 := []byte("Base contents") - content2 := []byte("Added contents") - - layer1, err := createLayer(ls, "", initWithFiles(newTestFile("file1", content1, 0644))) - if err != nil { - t.Fatal(err) - } - - layer2, err := createLayer(ls, layer1.ChainID(), initWithFiles(newTestFile("file2", content2, 0644))) - if err != nil { - t.Fatal(err) - } - - layer1DiffSize, err := graphDiffSize(ls, layer1) - if err != nil { - t.Fatal(err) - } - - if int(layer1DiffSize) != len(content1) { - t.Fatalf("Unexpected diff size %d, expected %d", layer1DiffSize, len(content1)) - } - - layer1Size, err := layer1.Size() - if err != nil { - t.Fatal(err) - } - - if expected := len(content1); int(layer1Size) != expected { - t.Fatalf("Unexpected size %d, expected %d", layer1Size, expected) - } - - layer2DiffSize, err := graphDiffSize(ls, layer2) - if err != nil { - t.Fatal(err) - } - - if int(layer2DiffSize) != len(content2) { - t.Fatalf("Unexpected diff size %d, expected %d", layer2DiffSize, len(content2)) - } - - layer2Size, err := layer2.Size() - if err != nil { - t.Fatal(err) - } - - if expected := len(content1) + len(content2); int(layer2Size) != expected { - t.Fatalf("Unexpected size %d, expected %d", layer2Size, expected) - } - -} diff --git a/vendor/github.com/docker/docker/layer/layer_windows.go b/vendor/github.com/docker/docker/layer/layer_windows.go deleted file mode 100644 index e20311a..0000000 --- a/vendor/github.com/docker/docker/layer/layer_windows.go +++ /dev/null @@ -1,98 +0,0 @@ -package layer - -import ( - "errors" - "fmt" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/daemon/graphdriver" -) - -// GetLayerPath returns the path to a layer -func GetLayerPath(s Store, layer ChainID) (string, error) { - ls, ok := s.(*layerStore) - if !ok { - return "", errors.New("unsupported layer store") - } - ls.layerL.Lock() - defer ls.layerL.Unlock() - - rl, ok := ls.layerMap[layer] - if !ok { - return "", ErrLayerDoesNotExist - } - - path, err := ls.driver.Get(rl.cacheID, "") - if err != nil { - return "", err - } - - if err := ls.driver.Put(rl.cacheID); err != nil { - return "", err - } - - return path, nil -} - -func (ls *layerStore) RegisterDiffID(graphID string, size int64) (Layer, error) { - var err error // this is used for cleanup in existingLayer case - diffID := digest.FromBytes([]byte(graphID)) - - // Create new roLayer - layer := &roLayer{ - cacheID: graphID, - diffID: DiffID(diffID), - referenceCount: 1, - layerStore: ls, - references: map[Layer]struct{}{}, - size: size, - } - - tx, err := ls.store.StartTransaction() - if err != nil { - return nil, err - } - defer func() { - if err != nil { - if err := tx.Cancel(); err != nil { - logrus.Errorf("Error canceling metadata transaction %q: %s", tx.String(), err) - } - } - }() - - layer.chainID = createChainIDFromParent("", layer.diffID) - - if !ls.driver.Exists(layer.cacheID) { - return nil, fmt.Errorf("layer %q is unknown to driver", layer.cacheID) - } - if err = storeLayer(tx, layer); err != nil { - return nil, err - } - - ls.layerL.Lock() - defer ls.layerL.Unlock() - - if existingLayer := ls.getWithoutLock(layer.chainID); existingLayer != nil { - // Set error for cleanup, but do not return - err = errors.New("layer already exists") - return existingLayer.getReference(), nil - } - - if err = tx.Commit(layer.chainID); err != nil { - return nil, err - } - - ls.layerMap[layer.chainID] = layer - - return layer.getReference(), nil -} - -func (ls *layerStore) mountID(name string) string { - // windows has issues if container ID doesn't match mount ID - return name -} - -func (ls *layerStore) GraphDriver() graphdriver.Driver { - return ls.driver -} diff --git a/vendor/github.com/docker/docker/layer/migration.go b/vendor/github.com/docker/docker/layer/migration.go deleted file mode 100644 index b45c310..0000000 --- a/vendor/github.com/docker/docker/layer/migration.go +++ /dev/null @@ -1,256 +0,0 @@ -package layer - -import ( - "compress/gzip" - "errors" - "fmt" - "io" - "os" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/vbatts/tar-split/tar/asm" - "github.com/vbatts/tar-split/tar/storage" -) - -// CreateRWLayerByGraphID creates a RWLayer in the layer store using -// the provided name with the given graphID. To get the RWLayer -// after migration the layer may be retrieved by the given name. -func (ls *layerStore) CreateRWLayerByGraphID(name string, graphID string, parent ChainID) (err error) { - ls.mountL.Lock() - defer ls.mountL.Unlock() - m, ok := ls.mounts[name] - if ok { - if m.parent.chainID != parent { - return errors.New("name conflict, mismatched parent") - } - if m.mountID != graphID { - return errors.New("mount already exists") - } - - return nil - } - - if !ls.driver.Exists(graphID) { - return fmt.Errorf("graph ID does not exist: %q", graphID) - } - - var p *roLayer - if string(parent) != "" { - p = ls.get(parent) - if p == nil { - return ErrLayerDoesNotExist - } - - // Release parent chain if error - defer func() { - if err != nil { - ls.layerL.Lock() - ls.releaseLayer(p) - ls.layerL.Unlock() - } - }() - } - - // TODO: Ensure graphID has correct parent - - m = &mountedLayer{ - name: name, - parent: p, - mountID: graphID, - layerStore: ls, - references: map[RWLayer]*referencedRWLayer{}, - } - - // Check for existing init layer - initID := fmt.Sprintf("%s-init", graphID) - if ls.driver.Exists(initID) { - m.initID = initID - } - - if err = ls.saveMount(m); err != nil { - return err - } - - return nil -} - -func (ls *layerStore) ChecksumForGraphID(id, parent, oldTarDataPath, newTarDataPath string) (diffID DiffID, size int64, err error) { - defer func() { - if err != nil { - logrus.Debugf("could not get checksum for %q with tar-split: %q", id, err) - diffID, size, err = ls.checksumForGraphIDNoTarsplit(id, parent, newTarDataPath) - } - }() - - if oldTarDataPath == "" { - err = errors.New("no tar-split file") - return - } - - tarDataFile, err := os.Open(oldTarDataPath) - if err != nil { - return - } - defer tarDataFile.Close() - uncompressed, err := gzip.NewReader(tarDataFile) - if err != nil { - return - } - - dgst := digest.Canonical.New() - err = ls.assembleTarTo(id, uncompressed, &size, dgst.Hash()) - if err != nil { - return - } - - diffID = DiffID(dgst.Digest()) - err = os.RemoveAll(newTarDataPath) - if err != nil { - return - } - err = os.Link(oldTarDataPath, newTarDataPath) - - return -} - -func (ls *layerStore) checksumForGraphIDNoTarsplit(id, parent, newTarDataPath string) (diffID DiffID, size int64, err error) { - rawarchive, err := ls.driver.Diff(id, parent) - if err != nil { - return - } - defer rawarchive.Close() - - f, err := os.Create(newTarDataPath) - if err != nil { - return - } - defer f.Close() - mfz := gzip.NewWriter(f) - defer mfz.Close() - metaPacker := storage.NewJSONPacker(mfz) - - packerCounter := &packSizeCounter{metaPacker, &size} - - archive, err := asm.NewInputTarStream(rawarchive, packerCounter, nil) - if err != nil { - return - } - dgst, err := digest.FromReader(archive) - if err != nil { - return - } - diffID = DiffID(dgst) - return -} - -func (ls *layerStore) RegisterByGraphID(graphID string, parent ChainID, diffID DiffID, tarDataFile string, size int64) (Layer, error) { - // err is used to hold the error which will always trigger - // cleanup of creates sources but may not be an error returned - // to the caller (already exists). - var err error - var p *roLayer - if string(parent) != "" { - p = ls.get(parent) - if p == nil { - return nil, ErrLayerDoesNotExist - } - - // Release parent chain if error - defer func() { - if err != nil { - ls.layerL.Lock() - ls.releaseLayer(p) - ls.layerL.Unlock() - } - }() - } - - // Create new roLayer - layer := &roLayer{ - parent: p, - cacheID: graphID, - referenceCount: 1, - layerStore: ls, - references: map[Layer]struct{}{}, - diffID: diffID, - size: size, - chainID: createChainIDFromParent(parent, diffID), - } - - ls.layerL.Lock() - defer ls.layerL.Unlock() - - if existingLayer := ls.getWithoutLock(layer.chainID); existingLayer != nil { - // Set error for cleanup, but do not return - err = errors.New("layer already exists") - return existingLayer.getReference(), nil - } - - tx, err := ls.store.StartTransaction() - if err != nil { - return nil, err - } - - defer func() { - if err != nil { - logrus.Debugf("Cleaning up transaction after failed migration for %s: %v", graphID, err) - if err := tx.Cancel(); err != nil { - logrus.Errorf("Error canceling metadata transaction %q: %s", tx.String(), err) - } - } - }() - - tsw, err := tx.TarSplitWriter(false) - if err != nil { - return nil, err - } - defer tsw.Close() - tdf, err := os.Open(tarDataFile) - if err != nil { - return nil, err - } - defer tdf.Close() - _, err = io.Copy(tsw, tdf) - if err != nil { - return nil, err - } - - if err = storeLayer(tx, layer); err != nil { - return nil, err - } - - if err = tx.Commit(layer.chainID); err != nil { - return nil, err - } - - ls.layerMap[layer.chainID] = layer - - return layer.getReference(), nil -} - -type unpackSizeCounter struct { - unpacker storage.Unpacker - size *int64 -} - -func (u *unpackSizeCounter) Next() (*storage.Entry, error) { - e, err := u.unpacker.Next() - if err == nil && u.size != nil { - *u.size += e.Size - } - return e, err -} - -type packSizeCounter struct { - packer storage.Packer - size *int64 -} - -func (p *packSizeCounter) AddEntry(e storage.Entry) (int, error) { - n, err := p.packer.AddEntry(e) - if err == nil && p.size != nil { - *p.size += e.Size - } - return n, err -} diff --git a/vendor/github.com/docker/docker/layer/migration_test.go b/vendor/github.com/docker/docker/layer/migration_test.go deleted file mode 100644 index 07b4b68..0000000 --- a/vendor/github.com/docker/docker/layer/migration_test.go +++ /dev/null @@ -1,435 +0,0 @@ -package layer - -import ( - "bytes" - "compress/gzip" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "runtime" - "testing" - - "github.com/docker/docker/daemon/graphdriver" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/stringid" - "github.com/vbatts/tar-split/tar/asm" - "github.com/vbatts/tar-split/tar/storage" -) - -func writeTarSplitFile(name string, tarContent []byte) error { - f, err := os.OpenFile(name, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return err - } - defer f.Close() - - fz := gzip.NewWriter(f) - - metaPacker := storage.NewJSONPacker(fz) - defer fz.Close() - - rdr, err := asm.NewInputTarStream(bytes.NewReader(tarContent), metaPacker, nil) - if err != nil { - return err - } - - if _, err := io.Copy(ioutil.Discard, rdr); err != nil { - return err - } - - return nil -} - -func TestLayerMigration(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - td, err := ioutil.TempDir("", "migration-test-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(td) - - layer1Files := []FileApplier{ - newTestFile("/root/.bashrc", []byte("# Boring configuration"), 0644), - newTestFile("/etc/profile", []byte("# Base configuration"), 0644), - } - - layer2Files := []FileApplier{ - newTestFile("/root/.bashrc", []byte("# Updated configuration"), 0644), - } - - tar1, err := tarFromFiles(layer1Files...) - if err != nil { - t.Fatal(err) - } - - tar2, err := tarFromFiles(layer2Files...) - if err != nil { - t.Fatal(err) - } - - graph, err := newVFSGraphDriver(filepath.Join(td, "graphdriver-")) - if err != nil { - t.Fatal(err) - } - - graphID1 := stringid.GenerateRandomID() - if err := graph.Create(graphID1, "", nil); err != nil { - t.Fatal(err) - } - if _, err := graph.ApplyDiff(graphID1, "", bytes.NewReader(tar1)); err != nil { - t.Fatal(err) - } - - tf1 := filepath.Join(td, "tar1.json.gz") - if err := writeTarSplitFile(tf1, tar1); err != nil { - t.Fatal(err) - } - - fms, err := NewFSMetadataStore(filepath.Join(td, "layers")) - if err != nil { - t.Fatal(err) - } - ls, err := NewStoreFromGraphDriver(fms, graph) - if err != nil { - t.Fatal(err) - } - - newTarDataPath := filepath.Join(td, ".migration-tardata") - diffID, size, err := ls.(*layerStore).ChecksumForGraphID(graphID1, "", tf1, newTarDataPath) - if err != nil { - t.Fatal(err) - } - - layer1a, err := ls.(*layerStore).RegisterByGraphID(graphID1, "", diffID, newTarDataPath, size) - if err != nil { - t.Fatal(err) - } - - layer1b, err := ls.Register(bytes.NewReader(tar1), "") - if err != nil { - t.Fatal(err) - } - - assertReferences(t, layer1a, layer1b) - // Attempt register, should be same - layer2a, err := ls.Register(bytes.NewReader(tar2), layer1a.ChainID()) - if err != nil { - t.Fatal(err) - } - - graphID2 := stringid.GenerateRandomID() - if err := graph.Create(graphID2, graphID1, nil); err != nil { - t.Fatal(err) - } - if _, err := graph.ApplyDiff(graphID2, graphID1, bytes.NewReader(tar2)); err != nil { - t.Fatal(err) - } - - tf2 := filepath.Join(td, "tar2.json.gz") - if err := writeTarSplitFile(tf2, tar2); err != nil { - t.Fatal(err) - } - diffID, size, err = ls.(*layerStore).ChecksumForGraphID(graphID2, graphID1, tf2, newTarDataPath) - if err != nil { - t.Fatal(err) - } - - layer2b, err := ls.(*layerStore).RegisterByGraphID(graphID2, layer1a.ChainID(), diffID, tf2, size) - if err != nil { - t.Fatal(err) - } - assertReferences(t, layer2a, layer2b) - - if metadata, err := ls.Release(layer2a); err != nil { - t.Fatal(err) - } else if len(metadata) > 0 { - t.Fatalf("Unexpected layer removal after first release: %#v", metadata) - } - - metadata, err := ls.Release(layer2b) - if err != nil { - t.Fatal(err) - } - - assertMetadata(t, metadata, createMetadata(layer2a)) -} - -func tarFromFilesInGraph(graph graphdriver.Driver, graphID, parentID string, files ...FileApplier) ([]byte, error) { - t, err := tarFromFiles(files...) - if err != nil { - return nil, err - } - - if err := graph.Create(graphID, parentID, nil); err != nil { - return nil, err - } - if _, err := graph.ApplyDiff(graphID, parentID, bytes.NewReader(t)); err != nil { - return nil, err - } - - ar, err := graph.Diff(graphID, parentID) - if err != nil { - return nil, err - } - defer ar.Close() - - return ioutil.ReadAll(ar) -} - -func TestLayerMigrationNoTarsplit(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - td, err := ioutil.TempDir("", "migration-test-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(td) - - layer1Files := []FileApplier{ - newTestFile("/root/.bashrc", []byte("# Boring configuration"), 0644), - newTestFile("/etc/profile", []byte("# Base configuration"), 0644), - } - - layer2Files := []FileApplier{ - newTestFile("/root/.bashrc", []byte("# Updated configuration"), 0644), - } - - graph, err := newVFSGraphDriver(filepath.Join(td, "graphdriver-")) - if err != nil { - t.Fatal(err) - } - graphID1 := stringid.GenerateRandomID() - graphID2 := stringid.GenerateRandomID() - - tar1, err := tarFromFilesInGraph(graph, graphID1, "", layer1Files...) - if err != nil { - t.Fatal(err) - } - - tar2, err := tarFromFilesInGraph(graph, graphID2, graphID1, layer2Files...) - if err != nil { - t.Fatal(err) - } - - fms, err := NewFSMetadataStore(filepath.Join(td, "layers")) - if err != nil { - t.Fatal(err) - } - ls, err := NewStoreFromGraphDriver(fms, graph) - if err != nil { - t.Fatal(err) - } - - newTarDataPath := filepath.Join(td, ".migration-tardata") - diffID, size, err := ls.(*layerStore).ChecksumForGraphID(graphID1, "", "", newTarDataPath) - if err != nil { - t.Fatal(err) - } - - layer1a, err := ls.(*layerStore).RegisterByGraphID(graphID1, "", diffID, newTarDataPath, size) - if err != nil { - t.Fatal(err) - } - - layer1b, err := ls.Register(bytes.NewReader(tar1), "") - if err != nil { - t.Fatal(err) - } - - assertReferences(t, layer1a, layer1b) - - // Attempt register, should be same - layer2a, err := ls.Register(bytes.NewReader(tar2), layer1a.ChainID()) - if err != nil { - t.Fatal(err) - } - - diffID, size, err = ls.(*layerStore).ChecksumForGraphID(graphID2, graphID1, "", newTarDataPath) - if err != nil { - t.Fatal(err) - } - - layer2b, err := ls.(*layerStore).RegisterByGraphID(graphID2, layer1a.ChainID(), diffID, newTarDataPath, size) - if err != nil { - t.Fatal(err) - } - assertReferences(t, layer2a, layer2b) - - if metadata, err := ls.Release(layer2a); err != nil { - t.Fatal(err) - } else if len(metadata) > 0 { - t.Fatalf("Unexpected layer removal after first release: %#v", metadata) - } - - metadata, err := ls.Release(layer2b) - if err != nil { - t.Fatal(err) - } - - assertMetadata(t, metadata, createMetadata(layer2a)) -} - -func TestMountMigration(t *testing.T) { - // TODO Windows: Figure out why this is failing (obvious - paths... needs porting) - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - ls, _, cleanup := newTestStore(t) - defer cleanup() - - baseFiles := []FileApplier{ - newTestFile("/root/.bashrc", []byte("# Boring configuration"), 0644), - newTestFile("/etc/profile", []byte("# Base configuration"), 0644), - } - initFiles := []FileApplier{ - newTestFile("/etc/hosts", []byte{}, 0644), - newTestFile("/etc/resolv.conf", []byte{}, 0644), - } - mountFiles := []FileApplier{ - newTestFile("/etc/hosts", []byte("localhost 127.0.0.1"), 0644), - newTestFile("/root/.bashrc", []byte("# Updated configuration"), 0644), - newTestFile("/root/testfile1.txt", []byte("nothing valuable"), 0644), - } - - initTar, err := tarFromFiles(initFiles...) - if err != nil { - t.Fatal(err) - } - - mountTar, err := tarFromFiles(mountFiles...) - if err != nil { - t.Fatal(err) - } - - graph := ls.(*layerStore).driver - - layer1, err := createLayer(ls, "", initWithFiles(baseFiles...)) - if err != nil { - t.Fatal(err) - } - - graphID1 := layer1.(*referencedCacheLayer).cacheID - - containerID := stringid.GenerateRandomID() - containerInit := fmt.Sprintf("%s-init", containerID) - - if err := graph.Create(containerInit, graphID1, nil); err != nil { - t.Fatal(err) - } - if _, err := graph.ApplyDiff(containerInit, graphID1, bytes.NewReader(initTar)); err != nil { - t.Fatal(err) - } - - if err := graph.Create(containerID, containerInit, nil); err != nil { - t.Fatal(err) - } - if _, err := graph.ApplyDiff(containerID, containerInit, bytes.NewReader(mountTar)); err != nil { - t.Fatal(err) - } - - if err := ls.(*layerStore).CreateRWLayerByGraphID("migration-mount", containerID, layer1.ChainID()); err != nil { - t.Fatal(err) - } - - rwLayer1, err := ls.GetRWLayer("migration-mount") - if err != nil { - t.Fatal(err) - } - - if _, err := rwLayer1.Mount(""); err != nil { - t.Fatal(err) - } - - changes, err := rwLayer1.Changes() - if err != nil { - t.Fatal(err) - } - - if expected := 5; len(changes) != expected { - t.Logf("Changes %#v", changes) - t.Fatalf("Wrong number of changes %d, expected %d", len(changes), expected) - } - - sortChanges(changes) - - assertChange(t, changes[0], archive.Change{ - Path: "/etc", - Kind: archive.ChangeModify, - }) - assertChange(t, changes[1], archive.Change{ - Path: "/etc/hosts", - Kind: archive.ChangeModify, - }) - assertChange(t, changes[2], archive.Change{ - Path: "/root", - Kind: archive.ChangeModify, - }) - assertChange(t, changes[3], archive.Change{ - Path: "/root/.bashrc", - Kind: archive.ChangeModify, - }) - assertChange(t, changes[4], archive.Change{ - Path: "/root/testfile1.txt", - Kind: archive.ChangeAdd, - }) - - if _, err := ls.CreateRWLayer("migration-mount", layer1.ChainID(), "", nil, nil); err == nil { - t.Fatal("Expected error creating mount with same name") - } else if err != ErrMountNameConflict { - t.Fatal(err) - } - - rwLayer2, err := ls.GetRWLayer("migration-mount") - if err != nil { - t.Fatal(err) - } - - if getMountLayer(rwLayer1) != getMountLayer(rwLayer2) { - t.Fatal("Expected same layer from get with same name as from migrate") - } - - if _, err := rwLayer2.Mount(""); err != nil { - t.Fatal(err) - } - - if _, err := rwLayer2.Mount(""); err != nil { - t.Fatal(err) - } - - if metadata, err := ls.Release(layer1); err != nil { - t.Fatal(err) - } else if len(metadata) > 0 { - t.Fatalf("Expected no layers to be deleted, deleted %#v", metadata) - } - - if err := rwLayer1.Unmount(); err != nil { - t.Fatal(err) - } - - if _, err := ls.ReleaseRWLayer(rwLayer1); err != nil { - t.Fatal(err) - } - - if err := rwLayer2.Unmount(); err != nil { - t.Fatal(err) - } - if err := rwLayer2.Unmount(); err != nil { - t.Fatal(err) - } - metadata, err := ls.ReleaseRWLayer(rwLayer2) - if err != nil { - t.Fatal(err) - } - if len(metadata) == 0 { - t.Fatal("Expected base layer to be deleted when deleting mount") - } - - assertMetadata(t, metadata, createMetadata(layer1)) -} diff --git a/vendor/github.com/docker/docker/layer/mount_test.go b/vendor/github.com/docker/docker/layer/mount_test.go deleted file mode 100644 index 7a8637e..0000000 --- a/vendor/github.com/docker/docker/layer/mount_test.go +++ /dev/null @@ -1,230 +0,0 @@ -package layer - -import ( - "io/ioutil" - "os" - "path/filepath" - "runtime" - "sort" - "testing" - - "github.com/docker/docker/pkg/archive" -) - -func TestMountInit(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - ls, _, cleanup := newTestStore(t) - defer cleanup() - - basefile := newTestFile("testfile.txt", []byte("base data!"), 0644) - initfile := newTestFile("testfile.txt", []byte("init data!"), 0777) - - li := initWithFiles(basefile) - layer, err := createLayer(ls, "", li) - if err != nil { - t.Fatal(err) - } - - mountInit := func(root string) error { - return initfile.ApplyFile(root) - } - - m, err := ls.CreateRWLayer("fun-mount", layer.ChainID(), "", mountInit, nil) - if err != nil { - t.Fatal(err) - } - - path, err := m.Mount("") - if err != nil { - t.Fatal(err) - } - - f, err := os.Open(filepath.Join(path, "testfile.txt")) - if err != nil { - t.Fatal(err) - } - defer f.Close() - - fi, err := f.Stat() - if err != nil { - t.Fatal(err) - } - - b, err := ioutil.ReadAll(f) - if err != nil { - t.Fatal(err) - } - - if expected := "init data!"; string(b) != expected { - t.Fatalf("Unexpected test file contents %q, expected %q", string(b), expected) - } - - if fi.Mode().Perm() != 0777 { - t.Fatalf("Unexpected filemode %o, expecting %o", fi.Mode().Perm(), 0777) - } -} - -func TestMountSize(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - ls, _, cleanup := newTestStore(t) - defer cleanup() - - content1 := []byte("Base contents") - content2 := []byte("Mutable contents") - contentInit := []byte("why am I excluded from the size ☹") - - li := initWithFiles(newTestFile("file1", content1, 0644)) - layer, err := createLayer(ls, "", li) - if err != nil { - t.Fatal(err) - } - - mountInit := func(root string) error { - return newTestFile("file-init", contentInit, 0777).ApplyFile(root) - } - - m, err := ls.CreateRWLayer("mount-size", layer.ChainID(), "", mountInit, nil) - if err != nil { - t.Fatal(err) - } - - path, err := m.Mount("") - if err != nil { - t.Fatal(err) - } - - if err := ioutil.WriteFile(filepath.Join(path, "file2"), content2, 0755); err != nil { - t.Fatal(err) - } - - mountSize, err := m.Size() - if err != nil { - t.Fatal(err) - } - - if expected := len(content2); int(mountSize) != expected { - t.Fatalf("Unexpected mount size %d, expected %d", int(mountSize), expected) - } -} - -func TestMountChanges(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - ls, _, cleanup := newTestStore(t) - defer cleanup() - - basefiles := []FileApplier{ - newTestFile("testfile1.txt", []byte("base data!"), 0644), - newTestFile("testfile2.txt", []byte("base data!"), 0644), - newTestFile("testfile3.txt", []byte("base data!"), 0644), - } - initfile := newTestFile("testfile1.txt", []byte("init data!"), 0777) - - li := initWithFiles(basefiles...) - layer, err := createLayer(ls, "", li) - if err != nil { - t.Fatal(err) - } - - mountInit := func(root string) error { - return initfile.ApplyFile(root) - } - - m, err := ls.CreateRWLayer("mount-changes", layer.ChainID(), "", mountInit, nil) - if err != nil { - t.Fatal(err) - } - - path, err := m.Mount("") - if err != nil { - t.Fatal(err) - } - - if err := os.Chmod(filepath.Join(path, "testfile1.txt"), 0755); err != nil { - t.Fatal(err) - } - - if err := ioutil.WriteFile(filepath.Join(path, "testfile1.txt"), []byte("mount data!"), 0755); err != nil { - t.Fatal(err) - } - - if err := os.Remove(filepath.Join(path, "testfile2.txt")); err != nil { - t.Fatal(err) - } - - if err := os.Chmod(filepath.Join(path, "testfile3.txt"), 0755); err != nil { - t.Fatal(err) - } - - if err := ioutil.WriteFile(filepath.Join(path, "testfile4.txt"), []byte("mount data!"), 0644); err != nil { - t.Fatal(err) - } - - changes, err := m.Changes() - if err != nil { - t.Fatal(err) - } - - if expected := 4; len(changes) != expected { - t.Fatalf("Wrong number of changes %d, expected %d", len(changes), expected) - } - - sortChanges(changes) - - assertChange(t, changes[0], archive.Change{ - Path: "/testfile1.txt", - Kind: archive.ChangeModify, - }) - assertChange(t, changes[1], archive.Change{ - Path: "/testfile2.txt", - Kind: archive.ChangeDelete, - }) - assertChange(t, changes[2], archive.Change{ - Path: "/testfile3.txt", - Kind: archive.ChangeModify, - }) - assertChange(t, changes[3], archive.Change{ - Path: "/testfile4.txt", - Kind: archive.ChangeAdd, - }) -} - -func assertChange(t *testing.T, actual, expected archive.Change) { - if actual.Path != expected.Path { - t.Fatalf("Unexpected change path %s, expected %s", actual.Path, expected.Path) - } - if actual.Kind != expected.Kind { - t.Fatalf("Unexpected change type %s, expected %s", actual.Kind, expected.Kind) - } -} - -func sortChanges(changes []archive.Change) { - cs := &changeSorter{ - changes: changes, - } - sort.Sort(cs) -} - -type changeSorter struct { - changes []archive.Change -} - -func (cs *changeSorter) Len() int { - return len(cs.changes) -} - -func (cs *changeSorter) Swap(i, j int) { - cs.changes[i], cs.changes[j] = cs.changes[j], cs.changes[i] -} - -func (cs *changeSorter) Less(i, j int) bool { - return cs.changes[i].Path < cs.changes[j].Path -} diff --git a/vendor/github.com/docker/docker/layer/mounted_layer.go b/vendor/github.com/docker/docker/layer/mounted_layer.go deleted file mode 100644 index a5cfcfa..0000000 --- a/vendor/github.com/docker/docker/layer/mounted_layer.go +++ /dev/null @@ -1,99 +0,0 @@ -package layer - -import ( - "io" - - "github.com/docker/docker/pkg/archive" -) - -type mountedLayer struct { - name string - mountID string - initID string - parent *roLayer - path string - layerStore *layerStore - - references map[RWLayer]*referencedRWLayer -} - -func (ml *mountedLayer) cacheParent() string { - if ml.initID != "" { - return ml.initID - } - if ml.parent != nil { - return ml.parent.cacheID - } - return "" -} - -func (ml *mountedLayer) TarStream() (io.ReadCloser, error) { - return ml.layerStore.driver.Diff(ml.mountID, ml.cacheParent()) -} - -func (ml *mountedLayer) Name() string { - return ml.name -} - -func (ml *mountedLayer) Parent() Layer { - if ml.parent != nil { - return ml.parent - } - - // Return a nil interface instead of an interface wrapping a nil - // pointer. - return nil -} - -func (ml *mountedLayer) Size() (int64, error) { - return ml.layerStore.driver.DiffSize(ml.mountID, ml.cacheParent()) -} - -func (ml *mountedLayer) Changes() ([]archive.Change, error) { - return ml.layerStore.driver.Changes(ml.mountID, ml.cacheParent()) -} - -func (ml *mountedLayer) Metadata() (map[string]string, error) { - return ml.layerStore.driver.GetMetadata(ml.mountID) -} - -func (ml *mountedLayer) getReference() RWLayer { - ref := &referencedRWLayer{ - mountedLayer: ml, - } - ml.references[ref] = ref - - return ref -} - -func (ml *mountedLayer) hasReferences() bool { - return len(ml.references) > 0 -} - -func (ml *mountedLayer) deleteReference(ref RWLayer) error { - if _, ok := ml.references[ref]; !ok { - return ErrLayerNotRetained - } - delete(ml.references, ref) - return nil -} - -func (ml *mountedLayer) retakeReference(r RWLayer) { - if ref, ok := r.(*referencedRWLayer); ok { - ml.references[ref] = ref - } -} - -type referencedRWLayer struct { - *mountedLayer -} - -func (rl *referencedRWLayer) Mount(mountLabel string) (string, error) { - return rl.layerStore.driver.Get(rl.mountedLayer.mountID, mountLabel) -} - -// Unmount decrements the activity count and unmounts the underlying layer -// Callers should only call `Unmount` once per call to `Mount`, even on error. -func (rl *referencedRWLayer) Unmount() error { - return rl.layerStore.driver.Put(rl.mountedLayer.mountID) -} diff --git a/vendor/github.com/docker/docker/layer/ro_layer.go b/vendor/github.com/docker/docker/layer/ro_layer.go deleted file mode 100644 index 7c8d233..0000000 --- a/vendor/github.com/docker/docker/layer/ro_layer.go +++ /dev/null @@ -1,192 +0,0 @@ -package layer - -import ( - "fmt" - "io" - - "github.com/docker/distribution" - "github.com/docker/distribution/digest" -) - -type roLayer struct { - chainID ChainID - diffID DiffID - parent *roLayer - cacheID string - size int64 - layerStore *layerStore - descriptor distribution.Descriptor - - referenceCount int - references map[Layer]struct{} -} - -// TarStream for roLayer guarentees that the data that is produced is the exact -// data that the layer was registered with. -func (rl *roLayer) TarStream() (io.ReadCloser, error) { - r, err := rl.layerStore.store.TarSplitReader(rl.chainID) - if err != nil { - return nil, err - } - - pr, pw := io.Pipe() - go func() { - err := rl.layerStore.assembleTarTo(rl.cacheID, r, nil, pw) - if err != nil { - pw.CloseWithError(err) - } else { - pw.Close() - } - }() - rc, err := newVerifiedReadCloser(pr, digest.Digest(rl.diffID)) - if err != nil { - return nil, err - } - return rc, nil -} - -// TarStreamFrom does not make any guarentees to the correctness of the produced -// data. As such it should not be used when the layer content must be verified -// to be an exact match to the registered layer. -func (rl *roLayer) TarStreamFrom(parent ChainID) (io.ReadCloser, error) { - var parentCacheID string - for pl := rl.parent; pl != nil; pl = pl.parent { - if pl.chainID == parent { - parentCacheID = pl.cacheID - break - } - } - - if parent != ChainID("") && parentCacheID == "" { - return nil, fmt.Errorf("layer ID '%s' is not a parent of the specified layer: cannot provide diff to non-parent", parent) - } - return rl.layerStore.driver.Diff(rl.cacheID, parentCacheID) -} - -func (rl *roLayer) ChainID() ChainID { - return rl.chainID -} - -func (rl *roLayer) DiffID() DiffID { - return rl.diffID -} - -func (rl *roLayer) Parent() Layer { - if rl.parent == nil { - return nil - } - return rl.parent -} - -func (rl *roLayer) Size() (size int64, err error) { - if rl.parent != nil { - size, err = rl.parent.Size() - if err != nil { - return - } - } - - return size + rl.size, nil -} - -func (rl *roLayer) DiffSize() (size int64, err error) { - return rl.size, nil -} - -func (rl *roLayer) Metadata() (map[string]string, error) { - return rl.layerStore.driver.GetMetadata(rl.cacheID) -} - -type referencedCacheLayer struct { - *roLayer -} - -func (rl *roLayer) getReference() Layer { - ref := &referencedCacheLayer{ - roLayer: rl, - } - rl.references[ref] = struct{}{} - - return ref -} - -func (rl *roLayer) hasReference(ref Layer) bool { - _, ok := rl.references[ref] - return ok -} - -func (rl *roLayer) hasReferences() bool { - return len(rl.references) > 0 -} - -func (rl *roLayer) deleteReference(ref Layer) { - delete(rl.references, ref) -} - -func (rl *roLayer) depth() int { - if rl.parent == nil { - return 1 - } - return rl.parent.depth() + 1 -} - -func storeLayer(tx MetadataTransaction, layer *roLayer) error { - if err := tx.SetDiffID(layer.diffID); err != nil { - return err - } - if err := tx.SetSize(layer.size); err != nil { - return err - } - if err := tx.SetCacheID(layer.cacheID); err != nil { - return err - } - // Do not store empty descriptors - if layer.descriptor.Digest != "" { - if err := tx.SetDescriptor(layer.descriptor); err != nil { - return err - } - } - if layer.parent != nil { - if err := tx.SetParent(layer.parent.chainID); err != nil { - return err - } - } - - return nil -} - -func newVerifiedReadCloser(rc io.ReadCloser, dgst digest.Digest) (io.ReadCloser, error) { - verifier, err := digest.NewDigestVerifier(dgst) - if err != nil { - return nil, err - } - return &verifiedReadCloser{ - rc: rc, - dgst: dgst, - verifier: verifier, - }, nil -} - -type verifiedReadCloser struct { - rc io.ReadCloser - dgst digest.Digest - verifier digest.Verifier -} - -func (vrc *verifiedReadCloser) Read(p []byte) (n int, err error) { - n, err = vrc.rc.Read(p) - if n > 0 { - if n, err := vrc.verifier.Write(p[:n]); err != nil { - return n, err - } - } - if err == io.EOF { - if !vrc.verifier.Verified() { - err = fmt.Errorf("could not verify layer data for: %s. This may be because internal files in the layer store were modified. Re-pulling or rebuilding this image may resolve the issue", vrc.dgst) - } - } - return -} -func (vrc *verifiedReadCloser) Close() error { - return vrc.rc.Close() -} diff --git a/vendor/github.com/docker/docker/layer/ro_layer_windows.go b/vendor/github.com/docker/docker/layer/ro_layer_windows.go deleted file mode 100644 index 32bd718..0000000 --- a/vendor/github.com/docker/docker/layer/ro_layer_windows.go +++ /dev/null @@ -1,9 +0,0 @@ -package layer - -import "github.com/docker/distribution" - -var _ distribution.Describable = &roLayer{} - -func (rl *roLayer) Descriptor() distribution.Descriptor { - return rl.descriptor -} diff --git a/vendor/github.com/docker/docker/libcontainerd/client.go b/vendor/github.com/docker/docker/libcontainerd/client.go deleted file mode 100644 index c14c1c5..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/client.go +++ /dev/null @@ -1,46 +0,0 @@ -package libcontainerd - -import ( - "fmt" - "sync" - - "github.com/docker/docker/pkg/locker" -) - -// clientCommon contains the platform agnostic fields used in the client structure -type clientCommon struct { - backend Backend - containers map[string]*container - locker *locker.Locker - mapMutex sync.RWMutex // protects read/write oprations from containers map -} - -func (clnt *client) lock(containerID string) { - clnt.locker.Lock(containerID) -} - -func (clnt *client) unlock(containerID string) { - clnt.locker.Unlock(containerID) -} - -// must hold a lock for cont.containerID -func (clnt *client) appendContainer(cont *container) { - clnt.mapMutex.Lock() - clnt.containers[cont.containerID] = cont - clnt.mapMutex.Unlock() -} -func (clnt *client) deleteContainer(containerID string) { - clnt.mapMutex.Lock() - delete(clnt.containers, containerID) - clnt.mapMutex.Unlock() -} - -func (clnt *client) getContainer(containerID string) (*container, error) { - clnt.mapMutex.RLock() - container, ok := clnt.containers[containerID] - defer clnt.mapMutex.RUnlock() - if !ok { - return nil, fmt.Errorf("invalid container: %s", containerID) // fixme: typed error - } - return container, nil -} diff --git a/vendor/github.com/docker/docker/libcontainerd/client_linux.go b/vendor/github.com/docker/docker/libcontainerd/client_linux.go deleted file mode 100644 index 190f981..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/client_linux.go +++ /dev/null @@ -1,605 +0,0 @@ -package libcontainerd - -import ( - "fmt" - "os" - "strings" - "sync" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/mount" - "github.com/golang/protobuf/ptypes" - "github.com/golang/protobuf/ptypes/timestamp" - specs "github.com/opencontainers/runtime-spec/specs-go" - "golang.org/x/net/context" -) - -type client struct { - clientCommon - - // Platform specific properties below here. - remote *remote - q queue - exitNotifiers map[string]*exitNotifier - liveRestore bool -} - -// GetServerVersion returns the connected server version information -func (clnt *client) GetServerVersion(ctx context.Context) (*ServerVersion, error) { - resp, err := clnt.remote.apiClient.GetServerVersion(ctx, &containerd.GetServerVersionRequest{}) - if err != nil { - return nil, err - } - - sv := &ServerVersion{ - GetServerVersionResponse: *resp, - } - - return sv, nil -} - -// AddProcess is the handler for adding a process to an already running -// container. It's called through docker exec. It returns the system pid of the -// exec'd process. -func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendlyName string, specp Process, attachStdio StdioCallback) (pid int, err error) { - clnt.lock(containerID) - defer clnt.unlock(containerID) - container, err := clnt.getContainer(containerID) - if err != nil { - return -1, err - } - - spec, err := container.spec() - if err != nil { - return -1, err - } - sp := spec.Process - sp.Args = specp.Args - sp.Terminal = specp.Terminal - if len(specp.Env) > 0 { - sp.Env = specp.Env - } - if specp.Cwd != nil { - sp.Cwd = *specp.Cwd - } - if specp.User != nil { - sp.User = specs.User{ - UID: specp.User.UID, - GID: specp.User.GID, - AdditionalGids: specp.User.AdditionalGids, - } - } - if specp.Capabilities != nil { - sp.Capabilities = specp.Capabilities - } - - p := container.newProcess(processFriendlyName) - - r := &containerd.AddProcessRequest{ - Args: sp.Args, - Cwd: sp.Cwd, - Terminal: sp.Terminal, - Id: containerID, - Env: sp.Env, - User: &containerd.User{ - Uid: sp.User.UID, - Gid: sp.User.GID, - AdditionalGids: sp.User.AdditionalGids, - }, - Pid: processFriendlyName, - Stdin: p.fifo(syscall.Stdin), - Stdout: p.fifo(syscall.Stdout), - Stderr: p.fifo(syscall.Stderr), - Capabilities: sp.Capabilities, - ApparmorProfile: sp.ApparmorProfile, - SelinuxLabel: sp.SelinuxLabel, - NoNewPrivileges: sp.NoNewPrivileges, - Rlimits: convertRlimits(sp.Rlimits), - } - - fifoCtx, cancel := context.WithCancel(context.Background()) - defer func() { - if err != nil { - cancel() - } - }() - - iopipe, err := p.openFifos(fifoCtx, sp.Terminal) - if err != nil { - return -1, err - } - - resp, err := clnt.remote.apiClient.AddProcess(ctx, r) - if err != nil { - p.closeFifos(iopipe) - return -1, err - } - - var stdinOnce sync.Once - stdin := iopipe.Stdin - iopipe.Stdin = ioutils.NewWriteCloserWrapper(stdin, func() error { - var err error - stdinOnce.Do(func() { // on error from attach we don't know if stdin was already closed - err = stdin.Close() - if err2 := p.sendCloseStdin(); err == nil { - err = err2 - } - }) - return err - }) - - container.processes[processFriendlyName] = p - - if err := attachStdio(*iopipe); err != nil { - p.closeFifos(iopipe) - return -1, err - } - - return int(resp.SystemPid), nil -} - -func (clnt *client) SignalProcess(containerID string, pid string, sig int) error { - clnt.lock(containerID) - defer clnt.unlock(containerID) - _, err := clnt.remote.apiClient.Signal(context.Background(), &containerd.SignalRequest{ - Id: containerID, - Pid: pid, - Signal: uint32(sig), - }) - return err -} - -func (clnt *client) Resize(containerID, processFriendlyName string, width, height int) error { - clnt.lock(containerID) - defer clnt.unlock(containerID) - if _, err := clnt.getContainer(containerID); err != nil { - return err - } - _, err := clnt.remote.apiClient.UpdateProcess(context.Background(), &containerd.UpdateProcessRequest{ - Id: containerID, - Pid: processFriendlyName, - Width: uint32(width), - Height: uint32(height), - }) - return err -} - -func (clnt *client) Pause(containerID string) error { - return clnt.setState(containerID, StatePause) -} - -func (clnt *client) setState(containerID, state string) error { - clnt.lock(containerID) - container, err := clnt.getContainer(containerID) - if err != nil { - clnt.unlock(containerID) - return err - } - if container.systemPid == 0 { - clnt.unlock(containerID) - return fmt.Errorf("No active process for container %s", containerID) - } - st := "running" - if state == StatePause { - st = "paused" - } - chstate := make(chan struct{}) - _, err = clnt.remote.apiClient.UpdateContainer(context.Background(), &containerd.UpdateContainerRequest{ - Id: containerID, - Pid: InitFriendlyName, - Status: st, - }) - if err != nil { - clnt.unlock(containerID) - return err - } - container.pauseMonitor.append(state, chstate) - clnt.unlock(containerID) - <-chstate - return nil -} - -func (clnt *client) Resume(containerID string) error { - return clnt.setState(containerID, StateResume) -} - -func (clnt *client) Stats(containerID string) (*Stats, error) { - resp, err := clnt.remote.apiClient.Stats(context.Background(), &containerd.StatsRequest{containerID}) - if err != nil { - return nil, err - } - return (*Stats)(resp), nil -} - -// Take care of the old 1.11.0 behavior in case the version upgrade -// happened without a clean daemon shutdown -func (clnt *client) cleanupOldRootfs(containerID string) { - // Unmount and delete the bundle folder - if mts, err := mount.GetMounts(); err == nil { - for _, mts := range mts { - if strings.HasSuffix(mts.Mountpoint, containerID+"/rootfs") { - if err := syscall.Unmount(mts.Mountpoint, syscall.MNT_DETACH); err == nil { - os.RemoveAll(strings.TrimSuffix(mts.Mountpoint, "/rootfs")) - } - break - } - } - } -} - -func (clnt *client) setExited(containerID string, exitCode uint32) error { - clnt.lock(containerID) - defer clnt.unlock(containerID) - - err := clnt.backend.StateChanged(containerID, StateInfo{ - CommonStateInfo: CommonStateInfo{ - State: StateExit, - ExitCode: exitCode, - }}) - - clnt.cleanupOldRootfs(containerID) - - return err -} - -func (clnt *client) GetPidsForContainer(containerID string) ([]int, error) { - cont, err := clnt.getContainerdContainer(containerID) - if err != nil { - return nil, err - } - pids := make([]int, len(cont.Pids)) - for i, p := range cont.Pids { - pids[i] = int(p) - } - return pids, nil -} - -// Summary returns a summary of the processes running in a container. -// This is a no-op on Linux. -func (clnt *client) Summary(containerID string) ([]Summary, error) { - return nil, nil -} - -func (clnt *client) getContainerdContainer(containerID string) (*containerd.Container, error) { - resp, err := clnt.remote.apiClient.State(context.Background(), &containerd.StateRequest{Id: containerID}) - if err != nil { - return nil, err - } - for _, cont := range resp.Containers { - if cont.Id == containerID { - return cont, nil - } - } - return nil, fmt.Errorf("invalid state response") -} - -func (clnt *client) UpdateResources(containerID string, resources Resources) error { - clnt.lock(containerID) - defer clnt.unlock(containerID) - container, err := clnt.getContainer(containerID) - if err != nil { - return err - } - if container.systemPid == 0 { - return fmt.Errorf("No active process for container %s", containerID) - } - _, err = clnt.remote.apiClient.UpdateContainer(context.Background(), &containerd.UpdateContainerRequest{ - Id: containerID, - Pid: InitFriendlyName, - Resources: (*containerd.UpdateResource)(&resources), - }) - if err != nil { - return err - } - return nil -} - -func (clnt *client) getExitNotifier(containerID string) *exitNotifier { - clnt.mapMutex.RLock() - defer clnt.mapMutex.RUnlock() - return clnt.exitNotifiers[containerID] -} - -func (clnt *client) getOrCreateExitNotifier(containerID string) *exitNotifier { - clnt.mapMutex.Lock() - w, ok := clnt.exitNotifiers[containerID] - defer clnt.mapMutex.Unlock() - if !ok { - w = &exitNotifier{c: make(chan struct{}), client: clnt} - clnt.exitNotifiers[containerID] = w - } - return w -} - -func (clnt *client) restore(cont *containerd.Container, lastEvent *containerd.Event, attachStdio StdioCallback, options ...CreateOption) (err error) { - clnt.lock(cont.Id) - defer clnt.unlock(cont.Id) - - logrus.Debugf("libcontainerd: restore container %s state %s", cont.Id, cont.Status) - - containerID := cont.Id - if _, err := clnt.getContainer(containerID); err == nil { - return fmt.Errorf("container %s is already active", containerID) - } - - defer func() { - if err != nil { - clnt.deleteContainer(cont.Id) - } - }() - - container := clnt.newContainer(cont.BundlePath, options...) - container.systemPid = systemPid(cont) - - var terminal bool - for _, p := range cont.Processes { - if p.Pid == InitFriendlyName { - terminal = p.Terminal - } - } - - fifoCtx, cancel := context.WithCancel(context.Background()) - defer func() { - if err != nil { - cancel() - } - }() - - iopipe, err := container.openFifos(fifoCtx, terminal) - if err != nil { - return err - } - var stdinOnce sync.Once - stdin := iopipe.Stdin - iopipe.Stdin = ioutils.NewWriteCloserWrapper(stdin, func() error { - var err error - stdinOnce.Do(func() { // on error from attach we don't know if stdin was already closed - err = stdin.Close() - }) - return err - }) - - if err := attachStdio(*iopipe); err != nil { - container.closeFifos(iopipe) - return err - } - - clnt.appendContainer(container) - - err = clnt.backend.StateChanged(containerID, StateInfo{ - CommonStateInfo: CommonStateInfo{ - State: StateRestore, - Pid: container.systemPid, - }}) - - if err != nil { - container.closeFifos(iopipe) - return err - } - - if lastEvent != nil { - // This should only be a pause or resume event - if lastEvent.Type == StatePause || lastEvent.Type == StateResume { - return clnt.backend.StateChanged(containerID, StateInfo{ - CommonStateInfo: CommonStateInfo{ - State: lastEvent.Type, - Pid: container.systemPid, - }}) - } - - logrus.Warnf("libcontainerd: unexpected backlog event: %#v", lastEvent) - } - - return nil -} - -func (clnt *client) getContainerLastEventSinceTime(id string, tsp *timestamp.Timestamp) (*containerd.Event, error) { - er := &containerd.EventsRequest{ - Timestamp: tsp, - StoredOnly: true, - Id: id, - } - events, err := clnt.remote.apiClient.Events(context.Background(), er) - if err != nil { - logrus.Errorf("libcontainerd: failed to get container events stream for %s: %q", er.Id, err) - return nil, err - } - - var ev *containerd.Event - for { - e, err := events.Recv() - if err != nil { - if err.Error() == "EOF" { - break - } - logrus.Errorf("libcontainerd: failed to get container event for %s: %q", id, err) - return nil, err - } - ev = e - logrus.Debugf("libcontainerd: received past event %#v", ev) - } - - return ev, nil -} - -func (clnt *client) getContainerLastEvent(id string) (*containerd.Event, error) { - ev, err := clnt.getContainerLastEventSinceTime(id, clnt.remote.restoreFromTimestamp) - if err == nil && ev == nil { - // If ev is nil and the container is running in containerd, - // we already consumed all the event of the - // container, included the "exit" one. - // Thus, we request all events containerd has in memory for - // this container in order to get the last one (which should - // be an exit event) - logrus.Warnf("libcontainerd: client is out of sync, restore was called on a fully synced container (%s).", id) - // Request all events since beginning of time - t := time.Unix(0, 0) - tsp, err := ptypes.TimestampProto(t) - if err != nil { - logrus.Errorf("libcontainerd: getLastEventSinceTime() failed to convert timestamp: %q", err) - return nil, err - } - - return clnt.getContainerLastEventSinceTime(id, tsp) - } - - return ev, err -} - -func (clnt *client) Restore(containerID string, attachStdio StdioCallback, options ...CreateOption) error { - // Synchronize with live events - clnt.remote.Lock() - defer clnt.remote.Unlock() - // Check that containerd still knows this container. - // - // In the unlikely event that Restore for this container process - // the its past event before the main loop, the event will be - // processed twice. However, this is not an issue as all those - // events will do is change the state of the container to be - // exactly the same. - cont, err := clnt.getContainerdContainer(containerID) - // Get its last event - ev, eerr := clnt.getContainerLastEvent(containerID) - if err != nil || cont.Status == "Stopped" { - if err != nil { - logrus.Warnf("libcontainerd: failed to retrieve container %s state: %v", containerID, err) - } - if ev != nil && (ev.Pid != InitFriendlyName || ev.Type != StateExit) { - // Wait a while for the exit event - timeout := time.NewTimer(10 * time.Second) - tick := time.NewTicker(100 * time.Millisecond) - stop: - for { - select { - case <-timeout.C: - break stop - case <-tick.C: - ev, eerr = clnt.getContainerLastEvent(containerID) - if eerr != nil { - break stop - } - if ev != nil && ev.Pid == InitFriendlyName && ev.Type == StateExit { - break stop - } - } - } - timeout.Stop() - tick.Stop() - } - - // get the exit status for this container, if we don't have - // one, indicate an error - ec := uint32(255) - if eerr == nil && ev != nil && ev.Pid == InitFriendlyName && ev.Type == StateExit { - ec = ev.Status - } - clnt.setExited(containerID, ec) - - return nil - } - - // container is still alive - if clnt.liveRestore { - if err := clnt.restore(cont, ev, attachStdio, options...); err != nil { - logrus.Errorf("libcontainerd: error restoring %s: %v", containerID, err) - } - return nil - } - - // Kill the container if liveRestore == false - w := clnt.getOrCreateExitNotifier(containerID) - clnt.lock(cont.Id) - container := clnt.newContainer(cont.BundlePath) - container.systemPid = systemPid(cont) - clnt.appendContainer(container) - clnt.unlock(cont.Id) - - container.discardFifos() - - if err := clnt.Signal(containerID, int(syscall.SIGTERM)); err != nil { - logrus.Errorf("libcontainerd: error sending sigterm to %v: %v", containerID, err) - } - // Let the main loop handle the exit event - clnt.remote.Unlock() - select { - case <-time.After(10 * time.Second): - if err := clnt.Signal(containerID, int(syscall.SIGKILL)); err != nil { - logrus.Errorf("libcontainerd: error sending sigkill to %v: %v", containerID, err) - } - select { - case <-time.After(2 * time.Second): - case <-w.wait(): - // relock because of the defer - clnt.remote.Lock() - return nil - } - case <-w.wait(): - // relock because of the defer - clnt.remote.Lock() - return nil - } - // relock because of the defer - clnt.remote.Lock() - - clnt.deleteContainer(containerID) - - return clnt.setExited(containerID, uint32(255)) -} - -func (clnt *client) CreateCheckpoint(containerID string, checkpointID string, checkpointDir string, exit bool) error { - clnt.lock(containerID) - defer clnt.unlock(containerID) - if _, err := clnt.getContainer(containerID); err != nil { - return err - } - - _, err := clnt.remote.apiClient.CreateCheckpoint(context.Background(), &containerd.CreateCheckpointRequest{ - Id: containerID, - Checkpoint: &containerd.Checkpoint{ - Name: checkpointID, - Exit: exit, - Tcp: true, - UnixSockets: true, - Shell: false, - EmptyNS: []string{"network"}, - }, - CheckpointDir: checkpointDir, - }) - return err -} - -func (clnt *client) DeleteCheckpoint(containerID string, checkpointID string, checkpointDir string) error { - clnt.lock(containerID) - defer clnt.unlock(containerID) - if _, err := clnt.getContainer(containerID); err != nil { - return err - } - - _, err := clnt.remote.apiClient.DeleteCheckpoint(context.Background(), &containerd.DeleteCheckpointRequest{ - Id: containerID, - Name: checkpointID, - CheckpointDir: checkpointDir, - }) - return err -} - -func (clnt *client) ListCheckpoints(containerID string, checkpointDir string) (*Checkpoints, error) { - clnt.lock(containerID) - defer clnt.unlock(containerID) - if _, err := clnt.getContainer(containerID); err != nil { - return nil, err - } - - resp, err := clnt.remote.apiClient.ListCheckpoint(context.Background(), &containerd.ListCheckpointRequest{ - Id: containerID, - CheckpointDir: checkpointDir, - }) - if err != nil { - return nil, err - } - return (*Checkpoints)(resp), nil -} diff --git a/vendor/github.com/docker/docker/libcontainerd/client_solaris.go b/vendor/github.com/docker/docker/libcontainerd/client_solaris.go deleted file mode 100644 index cb93997..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/client_solaris.go +++ /dev/null @@ -1,101 +0,0 @@ -package libcontainerd - -import "golang.org/x/net/context" - -type client struct { - clientCommon - - // Platform specific properties below here. - remote *remote - q queue - exitNotifiers map[string]*exitNotifier - liveRestore bool -} - -// GetServerVersion returns the connected server version information -func (clnt *client) GetServerVersion(ctx context.Context) (*ServerVersion, error) { - resp, err := clnt.remote.apiClient.GetServerVersion(ctx, &containerd.GetServerVersionRequest{}) - if err != nil { - return nil, err - } - - sv := &ServerVersion{ - GetServerVersionResponse: *resp, - } - - return sv, nil -} - -func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendlyName string, specp Process, attachStdio StdioCallback) (int, error) { - return -1, nil -} - -func (clnt *client) SignalProcess(containerID string, pid string, sig int) error { - return nil -} - -func (clnt *client) Resize(containerID, processFriendlyName string, width, height int) error { - return nil -} - -func (clnt *client) Pause(containerID string) error { - return nil -} - -func (clnt *client) Resume(containerID string) error { - return nil -} - -func (clnt *client) Stats(containerID string) (*Stats, error) { - return nil, nil -} - -func (clnt *client) getExitNotifier(containerID string) *exitNotifier { - clnt.mapMutex.RLock() - defer clnt.mapMutex.RUnlock() - return clnt.exitNotifiers[containerID] -} - -func (clnt *client) getOrCreateExitNotifier(containerID string) *exitNotifier { - clnt.mapMutex.Lock() - defer clnt.mapMutex.Unlock() - w, ok := clnt.exitNotifiers[containerID] - if !ok { - w = &exitNotifier{c: make(chan struct{}), client: clnt} - clnt.exitNotifiers[containerID] = w - } - return w -} - -// Restore is the handler for restoring a container -func (clnt *client) Restore(containerID string, attachStdio StdioCallback, options ...CreateOption) error { - return nil -} - -func (clnt *client) GetPidsForContainer(containerID string) ([]int, error) { - return nil, nil -} - -// Summary returns a summary of the processes running in a container. -func (clnt *client) Summary(containerID string) ([]Summary, error) { - return nil, nil -} - -// UpdateResources updates resources for a running container. -func (clnt *client) UpdateResources(containerID string, resources Resources) error { - // Updating resource isn't supported on Solaris - // but we should return nil for enabling updating container - return nil -} - -func (clnt *client) CreateCheckpoint(containerID string, checkpointID string, checkpointDir string, exit bool) error { - return nil -} - -func (clnt *client) DeleteCheckpoint(containerID string, checkpointID string, checkpointDir string) error { - return nil -} - -func (clnt *client) ListCheckpoints(containerID string, checkpointDir string) (*Checkpoints, error) { - return nil, nil -} diff --git a/vendor/github.com/docker/docker/libcontainerd/client_unix.go b/vendor/github.com/docker/docker/libcontainerd/client_unix.go deleted file mode 100644 index 21e8fea..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/client_unix.go +++ /dev/null @@ -1,142 +0,0 @@ -// +build linux solaris - -package libcontainerd - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - "strings" - "sync" - - "github.com/Sirupsen/logrus" - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/docker/docker/pkg/idtools" - specs "github.com/opencontainers/runtime-spec/specs-go" - "golang.org/x/net/context" -) - -func (clnt *client) prepareBundleDir(uid, gid int) (string, error) { - root, err := filepath.Abs(clnt.remote.stateDir) - if err != nil { - return "", err - } - if uid == 0 && gid == 0 { - return root, nil - } - p := string(filepath.Separator) - for _, d := range strings.Split(root, string(filepath.Separator))[1:] { - p = filepath.Join(p, d) - fi, err := os.Stat(p) - if err != nil && !os.IsNotExist(err) { - return "", err - } - if os.IsNotExist(err) || fi.Mode()&1 == 0 { - p = fmt.Sprintf("%s.%d.%d", p, uid, gid) - if err := idtools.MkdirAs(p, 0700, uid, gid); err != nil && !os.IsExist(err) { - return "", err - } - } - } - return p, nil -} - -func (clnt *client) Create(containerID string, checkpoint string, checkpointDir string, spec specs.Spec, attachStdio StdioCallback, options ...CreateOption) (err error) { - clnt.lock(containerID) - defer clnt.unlock(containerID) - - if _, err := clnt.getContainer(containerID); err == nil { - return fmt.Errorf("Container %s is already active", containerID) - } - - uid, gid, err := getRootIDs(specs.Spec(spec)) - if err != nil { - return err - } - dir, err := clnt.prepareBundleDir(uid, gid) - if err != nil { - return err - } - - container := clnt.newContainer(filepath.Join(dir, containerID), options...) - if err := container.clean(); err != nil { - return err - } - - defer func() { - if err != nil { - container.clean() - clnt.deleteContainer(containerID) - } - }() - - if err := idtools.MkdirAllAs(container.dir, 0700, uid, gid); err != nil && !os.IsExist(err) { - return err - } - - f, err := os.Create(filepath.Join(container.dir, configFilename)) - if err != nil { - return err - } - defer f.Close() - if err := json.NewEncoder(f).Encode(spec); err != nil { - return err - } - - return container.start(checkpoint, checkpointDir, attachStdio) -} - -func (clnt *client) Signal(containerID string, sig int) error { - clnt.lock(containerID) - defer clnt.unlock(containerID) - _, err := clnt.remote.apiClient.Signal(context.Background(), &containerd.SignalRequest{ - Id: containerID, - Pid: InitFriendlyName, - Signal: uint32(sig), - }) - return err -} - -func (clnt *client) newContainer(dir string, options ...CreateOption) *container { - container := &container{ - containerCommon: containerCommon{ - process: process{ - dir: dir, - processCommon: processCommon{ - containerID: filepath.Base(dir), - client: clnt, - friendlyName: InitFriendlyName, - }, - }, - processes: make(map[string]*process), - }, - } - for _, option := range options { - if err := option.Apply(container); err != nil { - logrus.Errorf("libcontainerd: newContainer(): %v", err) - } - } - return container -} - -type exitNotifier struct { - id string - client *client - c chan struct{} - once sync.Once -} - -func (en *exitNotifier) close() { - en.once.Do(func() { - close(en.c) - en.client.mapMutex.Lock() - if en == en.client.exitNotifiers[en.id] { - delete(en.client.exitNotifiers, en.id) - } - en.client.mapMutex.Unlock() - }) -} -func (en *exitNotifier) wait() <-chan struct{} { - return en.c -} diff --git a/vendor/github.com/docker/docker/libcontainerd/client_windows.go b/vendor/github.com/docker/docker/libcontainerd/client_windows.go deleted file mode 100644 index ddcf321..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/client_windows.go +++ /dev/null @@ -1,631 +0,0 @@ -package libcontainerd - -import ( - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - "syscall" - - "golang.org/x/net/context" - - "github.com/Microsoft/hcsshim" - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/sysinfo" - "github.com/opencontainers/runtime-spec/specs-go" -) - -type client struct { - clientCommon - - // Platform specific properties below here (none presently on Windows) -} - -// Win32 error codes that are used for various workarounds -// These really should be ALL_CAPS to match golangs syscall library and standard -// Win32 error conventions, but golint insists on CamelCase. -const ( - CoEClassstring = syscall.Errno(0x800401F3) // Invalid class string - ErrorNoNetwork = syscall.Errno(1222) // The network is not present or not started - ErrorBadPathname = syscall.Errno(161) // The specified path is invalid - ErrorInvalidObject = syscall.Errno(0x800710D8) // The object identifier does not represent a valid object -) - -// defaultOwner is a tag passed to HCS to allow it to differentiate between -// container creator management stacks. We hard code "docker" in the case -// of docker. -const defaultOwner = "docker" - -// Create is the entrypoint to create a container from a spec, and if successfully -// created, start it too. Table below shows the fields required for HCS JSON calling parameters, -// where if not populated, is omitted. -// +-----------------+--------------------------------------------+---------------------------------------------------+ -// | | Isolation=Process | Isolation=Hyper-V | -// +-----------------+--------------------------------------------+---------------------------------------------------+ -// | VolumePath | \\?\\Volume{GUIDa} | | -// | LayerFolderPath | %root%\windowsfilter\containerID | %root%\windowsfilter\containerID (servicing only) | -// | Layers[] | ID=GUIDb;Path=%root%\windowsfilter\layerID | ID=GUIDb;Path=%root%\windowsfilter\layerID | -// | SandboxPath | | %root%\windowsfilter | -// | HvRuntime | | ImagePath=%root%\BaseLayerID\UtilityVM | -// +-----------------+--------------------------------------------+---------------------------------------------------+ -// -// Isolation=Process example: -// -// { -// "SystemType": "Container", -// "Name": "5e0055c814a6005b8e57ac59f9a522066e0af12b48b3c26a9416e23907698776", -// "Owner": "docker", -// "IsDummy": false, -// "VolumePath": "\\\\\\\\?\\\\Volume{66d1ef4c-7a00-11e6-8948-00155ddbef9d}", -// "IgnoreFlushesDuringBoot": true, -// "LayerFolderPath": "C:\\\\control\\\\windowsfilter\\\\5e0055c814a6005b8e57ac59f9a522066e0af12b48b3c26a9416e23907698776", -// "Layers": [{ -// "ID": "18955d65-d45a-557b-bf1c-49d6dfefc526", -// "Path": "C:\\\\control\\\\windowsfilter\\\\65bf96e5760a09edf1790cb229e2dfb2dbd0fcdc0bf7451bae099106bfbfea0c" -// }], -// "HostName": "5e0055c814a6", -// "MappedDirectories": [], -// "HvPartition": false, -// "EndpointList": ["eef2649d-bb17-4d53-9937-295a8efe6f2c"], -// "Servicing": false -//} -// -// Isolation=Hyper-V example: -// -//{ -// "SystemType": "Container", -// "Name": "475c2c58933b72687a88a441e7e0ca4bd72d76413c5f9d5031fee83b98f6045d", -// "Owner": "docker", -// "IsDummy": false, -// "IgnoreFlushesDuringBoot": true, -// "Layers": [{ -// "ID": "18955d65-d45a-557b-bf1c-49d6dfefc526", -// "Path": "C:\\\\control\\\\windowsfilter\\\\65bf96e5760a09edf1790cb229e2dfb2dbd0fcdc0bf7451bae099106bfbfea0c" -// }], -// "HostName": "475c2c58933b", -// "MappedDirectories": [], -// "SandboxPath": "C:\\\\control\\\\windowsfilter", -// "HvPartition": true, -// "EndpointList": ["e1bb1e61-d56f-405e-b75d-fd520cefa0cb"], -// "HvRuntime": { -// "ImagePath": "C:\\\\control\\\\windowsfilter\\\\65bf96e5760a09edf1790cb229e2dfb2dbd0fcdc0bf7451bae099106bfbfea0c\\\\UtilityVM" -// }, -// "Servicing": false -//} -func (clnt *client) Create(containerID string, checkpoint string, checkpointDir string, spec specs.Spec, attachStdio StdioCallback, options ...CreateOption) error { - clnt.lock(containerID) - defer clnt.unlock(containerID) - logrus.Debugln("libcontainerd: client.Create() with spec", spec) - - configuration := &hcsshim.ContainerConfig{ - SystemType: "Container", - Name: containerID, - Owner: defaultOwner, - IgnoreFlushesDuringBoot: false, - HostName: spec.Hostname, - HvPartition: false, - } - - if spec.Windows.Resources != nil { - if spec.Windows.Resources.CPU != nil { - if spec.Windows.Resources.CPU.Count != nil { - // This check is being done here rather than in adaptContainerSettings - // because we don't want to update the HostConfig in case this container - // is moved to a host with more CPUs than this one. - cpuCount := *spec.Windows.Resources.CPU.Count - hostCPUCount := uint64(sysinfo.NumCPU()) - if cpuCount > hostCPUCount { - logrus.Warnf("Changing requested CPUCount of %d to current number of processors, %d", cpuCount, hostCPUCount) - cpuCount = hostCPUCount - } - configuration.ProcessorCount = uint32(cpuCount) - } - if spec.Windows.Resources.CPU.Shares != nil { - configuration.ProcessorWeight = uint64(*spec.Windows.Resources.CPU.Shares) - } - if spec.Windows.Resources.CPU.Percent != nil { - configuration.ProcessorMaximum = int64(*spec.Windows.Resources.CPU.Percent) * 100 // ProcessorMaximum is a value between 1 and 10000 - } - } - if spec.Windows.Resources.Memory != nil { - if spec.Windows.Resources.Memory.Limit != nil { - configuration.MemoryMaximumInMB = int64(*spec.Windows.Resources.Memory.Limit) / 1024 / 1024 - } - } - if spec.Windows.Resources.Storage != nil { - if spec.Windows.Resources.Storage.Bps != nil { - configuration.StorageBandwidthMaximum = *spec.Windows.Resources.Storage.Bps - } - if spec.Windows.Resources.Storage.Iops != nil { - configuration.StorageIOPSMaximum = *spec.Windows.Resources.Storage.Iops - } - } - } - - var layerOpt *LayerOption - for _, option := range options { - if s, ok := option.(*ServicingOption); ok { - configuration.Servicing = s.IsServicing - continue - } - if f, ok := option.(*FlushOption); ok { - configuration.IgnoreFlushesDuringBoot = f.IgnoreFlushesDuringBoot - continue - } - if h, ok := option.(*HyperVIsolationOption); ok { - configuration.HvPartition = h.IsHyperV - configuration.SandboxPath = h.SandboxPath - continue - } - if l, ok := option.(*LayerOption); ok { - layerOpt = l - } - if n, ok := option.(*NetworkEndpointsOption); ok { - configuration.EndpointList = n.Endpoints - configuration.AllowUnqualifiedDNSQuery = n.AllowUnqualifiedDNSQuery - continue - } - if c, ok := option.(*CredentialsOption); ok { - configuration.Credentials = c.Credentials - continue - } - } - - // We must have a layer option with at least one path - if layerOpt == nil || layerOpt.LayerPaths == nil { - return fmt.Errorf("no layer option or paths were supplied to the runtime") - } - - if configuration.HvPartition { - // Find the upper-most utility VM image, since the utility VM does not - // use layering in RS1. - // TODO @swernli/jhowardmsft at some point post RS1 this may be re-locatable. - var uvmImagePath string - for _, path := range layerOpt.LayerPaths { - fullPath := filepath.Join(path, "UtilityVM") - _, err := os.Stat(fullPath) - if err == nil { - uvmImagePath = fullPath - break - } - if !os.IsNotExist(err) { - return err - } - } - if uvmImagePath == "" { - return errors.New("utility VM image could not be found") - } - configuration.HvRuntime = &hcsshim.HvRuntime{ImagePath: uvmImagePath} - } else { - configuration.VolumePath = spec.Root.Path - } - - configuration.LayerFolderPath = layerOpt.LayerFolderPath - - for _, layerPath := range layerOpt.LayerPaths { - _, filename := filepath.Split(layerPath) - g, err := hcsshim.NameToGuid(filename) - if err != nil { - return err - } - configuration.Layers = append(configuration.Layers, hcsshim.Layer{ - ID: g.ToString(), - Path: layerPath, - }) - } - - // Add the mounts (volumes, bind mounts etc) to the structure - mds := make([]hcsshim.MappedDir, len(spec.Mounts)) - for i, mount := range spec.Mounts { - mds[i] = hcsshim.MappedDir{ - HostPath: mount.Source, - ContainerPath: mount.Destination, - ReadOnly: false, - } - for _, o := range mount.Options { - if strings.ToLower(o) == "ro" { - mds[i].ReadOnly = true - } - } - } - configuration.MappedDirectories = mds - - hcsContainer, err := hcsshim.CreateContainer(containerID, configuration) - if err != nil { - return err - } - - // Construct a container object for calling start on it. - container := &container{ - containerCommon: containerCommon{ - process: process{ - processCommon: processCommon{ - containerID: containerID, - client: clnt, - friendlyName: InitFriendlyName, - }, - commandLine: strings.Join(spec.Process.Args, " "), - }, - processes: make(map[string]*process), - }, - ociSpec: spec, - hcsContainer: hcsContainer, - } - - container.options = options - for _, option := range options { - if err := option.Apply(container); err != nil { - logrus.Errorf("libcontainerd: %v", err) - } - } - - // Call start, and if it fails, delete the container from our - // internal structure, start will keep HCS in sync by deleting the - // container there. - logrus.Debugf("libcontainerd: Create() id=%s, Calling start()", containerID) - if err := container.start(attachStdio); err != nil { - clnt.deleteContainer(containerID) - return err - } - - logrus.Debugf("libcontainerd: Create() id=%s completed successfully", containerID) - return nil - -} - -// AddProcess is the handler for adding a process to an already running -// container. It's called through docker exec. It returns the system pid of the -// exec'd process. -func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendlyName string, procToAdd Process, attachStdio StdioCallback) (int, error) { - clnt.lock(containerID) - defer clnt.unlock(containerID) - container, err := clnt.getContainer(containerID) - if err != nil { - return -1, err - } - // Note we always tell HCS to - // create stdout as it's required regardless of '-i' or '-t' options, so that - // docker can always grab the output through logs. We also tell HCS to always - // create stdin, even if it's not used - it will be closed shortly. Stderr - // is only created if it we're not -t. - createProcessParms := hcsshim.ProcessConfig{ - EmulateConsole: procToAdd.Terminal, - CreateStdInPipe: true, - CreateStdOutPipe: true, - CreateStdErrPipe: !procToAdd.Terminal, - } - createProcessParms.ConsoleSize[0] = uint(procToAdd.ConsoleSize.Height) - createProcessParms.ConsoleSize[1] = uint(procToAdd.ConsoleSize.Width) - - // Take working directory from the process to add if it is defined, - // otherwise take from the first process. - if procToAdd.Cwd != "" { - createProcessParms.WorkingDirectory = procToAdd.Cwd - } else { - createProcessParms.WorkingDirectory = container.ociSpec.Process.Cwd - } - - // Configure the environment for the process - createProcessParms.Environment = setupEnvironmentVariables(procToAdd.Env) - createProcessParms.CommandLine = strings.Join(procToAdd.Args, " ") - createProcessParms.User = procToAdd.User.Username - - logrus.Debugf("libcontainerd: commandLine: %s", createProcessParms.CommandLine) - - // Start the command running in the container. - var stdout, stderr io.ReadCloser - var stdin io.WriteCloser - newProcess, err := container.hcsContainer.CreateProcess(&createProcessParms) - if err != nil { - logrus.Errorf("libcontainerd: AddProcess(%s) CreateProcess() failed %s", containerID, err) - return -1, err - } - - pid := newProcess.Pid() - - stdin, stdout, stderr, err = newProcess.Stdio() - if err != nil { - logrus.Errorf("libcontainerd: %s getting std pipes failed %s", containerID, err) - return -1, err - } - - iopipe := &IOPipe{Terminal: procToAdd.Terminal} - iopipe.Stdin = createStdInCloser(stdin, newProcess) - - // Convert io.ReadClosers to io.Readers - if stdout != nil { - iopipe.Stdout = ioutil.NopCloser(&autoClosingReader{ReadCloser: stdout}) - } - if stderr != nil { - iopipe.Stderr = ioutil.NopCloser(&autoClosingReader{ReadCloser: stderr}) - } - - proc := &process{ - processCommon: processCommon{ - containerID: containerID, - friendlyName: processFriendlyName, - client: clnt, - systemPid: uint32(pid), - }, - commandLine: createProcessParms.CommandLine, - hcsProcess: newProcess, - } - - // Add the process to the container's list of processes - container.processes[processFriendlyName] = proc - - // Tell the engine to attach streams back to the client - if err := attachStdio(*iopipe); err != nil { - return -1, err - } - - // Spin up a go routine waiting for exit to handle cleanup - go container.waitExit(proc, false) - - return pid, nil -} - -// Signal handles `docker stop` on Windows. While Linux has support for -// the full range of signals, signals aren't really implemented on Windows. -// We fake supporting regular stop and -9 to force kill. -func (clnt *client) Signal(containerID string, sig int) error { - var ( - cont *container - err error - ) - - // Get the container as we need it to get the container handle. - clnt.lock(containerID) - defer clnt.unlock(containerID) - if cont, err = clnt.getContainer(containerID); err != nil { - return err - } - - cont.manualStopRequested = true - - logrus.Debugf("libcontainerd: Signal() containerID=%s sig=%d pid=%d", containerID, sig, cont.systemPid) - - if syscall.Signal(sig) == syscall.SIGKILL { - // Terminate the compute system - if err := cont.hcsContainer.Terminate(); err != nil { - if !hcsshim.IsPending(err) { - logrus.Errorf("libcontainerd: failed to terminate %s - %q", containerID, err) - } - } - } else { - // Terminate Process - if err := cont.hcsProcess.Kill(); err != nil && !hcsshim.IsAlreadyStopped(err) { - // ignore errors - logrus.Warnf("libcontainerd: failed to terminate pid %d in %s: %q", cont.systemPid, containerID, err) - } - } - - return nil -} - -// While Linux has support for the full range of signals, signals aren't really implemented on Windows. -// We try to terminate the specified process whatever signal is requested. -func (clnt *client) SignalProcess(containerID string, processFriendlyName string, sig int) error { - clnt.lock(containerID) - defer clnt.unlock(containerID) - cont, err := clnt.getContainer(containerID) - if err != nil { - return err - } - - for _, p := range cont.processes { - if p.friendlyName == processFriendlyName { - return p.hcsProcess.Kill() - } - } - - return fmt.Errorf("SignalProcess could not find process %s in %s", processFriendlyName, containerID) -} - -// Resize handles a CLI event to resize an interactive docker run or docker exec -// window. -func (clnt *client) Resize(containerID, processFriendlyName string, width, height int) error { - // Get the libcontainerd container object - clnt.lock(containerID) - defer clnt.unlock(containerID) - cont, err := clnt.getContainer(containerID) - if err != nil { - return err - } - - h, w := uint16(height), uint16(width) - - if processFriendlyName == InitFriendlyName { - logrus.Debugln("libcontainerd: resizing systemPID in", containerID, cont.process.systemPid) - return cont.process.hcsProcess.ResizeConsole(w, h) - } - - for _, p := range cont.processes { - if p.friendlyName == processFriendlyName { - logrus.Debugln("libcontainerd: resizing exec'd process", containerID, p.systemPid) - return p.hcsProcess.ResizeConsole(w, h) - } - } - - return fmt.Errorf("Resize could not find containerID %s to resize", containerID) - -} - -// Pause handles pause requests for containers -func (clnt *client) Pause(containerID string) error { - unlockContainer := true - // Get the libcontainerd container object - clnt.lock(containerID) - defer func() { - if unlockContainer { - clnt.unlock(containerID) - } - }() - container, err := clnt.getContainer(containerID) - if err != nil { - return err - } - - for _, option := range container.options { - if h, ok := option.(*HyperVIsolationOption); ok { - if !h.IsHyperV { - return errors.New("cannot pause Windows Server Containers") - } - break - } - } - - err = container.hcsContainer.Pause() - if err != nil { - return err - } - - // Unlock container before calling back into the daemon - unlockContainer = false - clnt.unlock(containerID) - - return clnt.backend.StateChanged(containerID, StateInfo{ - CommonStateInfo: CommonStateInfo{ - State: StatePause, - }}) -} - -// Resume handles resume requests for containers -func (clnt *client) Resume(containerID string) error { - unlockContainer := true - // Get the libcontainerd container object - clnt.lock(containerID) - defer func() { - if unlockContainer { - clnt.unlock(containerID) - } - }() - container, err := clnt.getContainer(containerID) - if err != nil { - return err - } - - // This should never happen, since Windows Server Containers cannot be paused - for _, option := range container.options { - if h, ok := option.(*HyperVIsolationOption); ok { - if !h.IsHyperV { - return errors.New("cannot resume Windows Server Containers") - } - break - } - } - - err = container.hcsContainer.Resume() - if err != nil { - return err - } - - // Unlock container before calling back into the daemon - unlockContainer = false - clnt.unlock(containerID) - - return clnt.backend.StateChanged(containerID, StateInfo{ - CommonStateInfo: CommonStateInfo{ - State: StateResume, - }}) -} - -// Stats handles stats requests for containers -func (clnt *client) Stats(containerID string) (*Stats, error) { - // Get the libcontainerd container object - clnt.lock(containerID) - defer clnt.unlock(containerID) - container, err := clnt.getContainer(containerID) - if err != nil { - return nil, err - } - s, err := container.hcsContainer.Statistics() - if err != nil { - return nil, err - } - st := Stats(s) - return &st, nil -} - -// Restore is the handler for restoring a container -func (clnt *client) Restore(containerID string, _ StdioCallback, unusedOnWindows ...CreateOption) error { - // TODO Windows: Implement this. For now, just tell the backend the container exited. - logrus.Debugf("libcontainerd: Restore(%s)", containerID) - return clnt.backend.StateChanged(containerID, StateInfo{ - CommonStateInfo: CommonStateInfo{ - State: StateExit, - ExitCode: 1 << 31, - }}) -} - -// GetPidsForContainer returns a list of process IDs running in a container. -// Although implemented, this is not used in Windows. -func (clnt *client) GetPidsForContainer(containerID string) ([]int, error) { - var pids []int - clnt.lock(containerID) - defer clnt.unlock(containerID) - cont, err := clnt.getContainer(containerID) - if err != nil { - return nil, err - } - - // Add the first process - pids = append(pids, int(cont.containerCommon.systemPid)) - // And add all the exec'd processes - for _, p := range cont.processes { - pids = append(pids, int(p.processCommon.systemPid)) - } - return pids, nil -} - -// Summary returns a summary of the processes running in a container. -// This is present in Windows to support docker top. In linux, the -// engine shells out to ps to get process information. On Windows, as -// the containers could be Hyper-V containers, they would not be -// visible on the container host. However, libcontainerd does have -// that information. -func (clnt *client) Summary(containerID string) ([]Summary, error) { - - // Get the libcontainerd container object - clnt.lock(containerID) - defer clnt.unlock(containerID) - container, err := clnt.getContainer(containerID) - if err != nil { - return nil, err - } - p, err := container.hcsContainer.ProcessList() - if err != nil { - return nil, err - } - pl := make([]Summary, len(p)) - for i := range p { - pl[i] = Summary(p[i]) - } - return pl, nil -} - -// UpdateResources updates resources for a running container. -func (clnt *client) UpdateResources(containerID string, resources Resources) error { - // Updating resource isn't supported on Windows - // but we should return nil for enabling updating container - return nil -} - -func (clnt *client) CreateCheckpoint(containerID string, checkpointID string, checkpointDir string, exit bool) error { - return errors.New("Windows: Containers do not support checkpoints") -} - -func (clnt *client) DeleteCheckpoint(containerID string, checkpointID string, checkpointDir string) error { - return errors.New("Windows: Containers do not support checkpoints") -} - -func (clnt *client) ListCheckpoints(containerID string, checkpointDir string) (*Checkpoints, error) { - return nil, errors.New("Windows: Containers do not support checkpoints") -} - -func (clnt *client) GetServerVersion(ctx context.Context) (*ServerVersion, error) { - return &ServerVersion{}, nil -} diff --git a/vendor/github.com/docker/docker/libcontainerd/container.go b/vendor/github.com/docker/docker/libcontainerd/container.go deleted file mode 100644 index b403213..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/container.go +++ /dev/null @@ -1,13 +0,0 @@ -package libcontainerd - -const ( - // InitFriendlyName is the name given in the lookup map of processes - // for the first process started in a container. - InitFriendlyName = "init" - configFilename = "config.json" -) - -type containerCommon struct { - process - processes map[string]*process -} diff --git a/vendor/github.com/docker/docker/libcontainerd/container_unix.go b/vendor/github.com/docker/docker/libcontainerd/container_unix.go deleted file mode 100644 index 61bab14..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/container_unix.go +++ /dev/null @@ -1,250 +0,0 @@ -// +build linux solaris - -package libcontainerd - -import ( - "encoding/json" - "io" - "io/ioutil" - "os" - "path/filepath" - "sync" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/docker/docker/pkg/ioutils" - specs "github.com/opencontainers/runtime-spec/specs-go" - "github.com/tonistiigi/fifo" - "golang.org/x/net/context" -) - -type container struct { - containerCommon - - // Platform specific fields are below here. - pauseMonitor - oom bool - runtime string - runtimeArgs []string -} - -type runtime struct { - path string - args []string -} - -// WithRuntime sets the runtime to be used for the created container -func WithRuntime(path string, args []string) CreateOption { - return runtime{path, args} -} - -func (rt runtime) Apply(p interface{}) error { - if pr, ok := p.(*container); ok { - pr.runtime = rt.path - pr.runtimeArgs = rt.args - } - return nil -} - -func (ctr *container) clean() error { - if os.Getenv("LIBCONTAINERD_NOCLEAN") == "1" { - return nil - } - if _, err := os.Lstat(ctr.dir); err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - - if err := os.RemoveAll(ctr.dir); err != nil { - return err - } - return nil -} - -// cleanProcess removes the fifos used by an additional process. -// Caller needs to lock container ID before calling this method. -func (ctr *container) cleanProcess(id string) { - if p, ok := ctr.processes[id]; ok { - for _, i := range []int{syscall.Stdin, syscall.Stdout, syscall.Stderr} { - if err := os.Remove(p.fifo(i)); err != nil && !os.IsNotExist(err) { - logrus.Warnf("libcontainerd: failed to remove %v for process %v: %v", p.fifo(i), id, err) - } - } - } - delete(ctr.processes, id) -} - -func (ctr *container) spec() (*specs.Spec, error) { - var spec specs.Spec - dt, err := ioutil.ReadFile(filepath.Join(ctr.dir, configFilename)) - if err != nil { - return nil, err - } - if err := json.Unmarshal(dt, &spec); err != nil { - return nil, err - } - return &spec, nil -} - -func (ctr *container) start(checkpoint string, checkpointDir string, attachStdio StdioCallback) (err error) { - spec, err := ctr.spec() - if err != nil { - return nil - } - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - ready := make(chan struct{}) - - fifoCtx, cancel := context.WithCancel(context.Background()) - defer func() { - if err != nil { - cancel() - } - }() - - iopipe, err := ctr.openFifos(fifoCtx, spec.Process.Terminal) - if err != nil { - return err - } - - var stdinOnce sync.Once - - // we need to delay stdin closure after container start or else "stdin close" - // event will be rejected by containerd. - // stdin closure happens in attachStdio - stdin := iopipe.Stdin - iopipe.Stdin = ioutils.NewWriteCloserWrapper(stdin, func() error { - var err error - stdinOnce.Do(func() { // on error from attach we don't know if stdin was already closed - err = stdin.Close() - go func() { - select { - case <-ready: - case <-ctx.Done(): - } - select { - case <-ready: - if err := ctr.sendCloseStdin(); err != nil { - logrus.Warnf("failed to close stdin: %+v", err) - } - default: - } - }() - }) - return err - }) - - r := &containerd.CreateContainerRequest{ - Id: ctr.containerID, - BundlePath: ctr.dir, - Stdin: ctr.fifo(syscall.Stdin), - Stdout: ctr.fifo(syscall.Stdout), - Stderr: ctr.fifo(syscall.Stderr), - Checkpoint: checkpoint, - CheckpointDir: checkpointDir, - // check to see if we are running in ramdisk to disable pivot root - NoPivotRoot: os.Getenv("DOCKER_RAMDISK") != "", - Runtime: ctr.runtime, - RuntimeArgs: ctr.runtimeArgs, - } - ctr.client.appendContainer(ctr) - - if err := attachStdio(*iopipe); err != nil { - ctr.closeFifos(iopipe) - return err - } - - resp, err := ctr.client.remote.apiClient.CreateContainer(context.Background(), r) - if err != nil { - ctr.closeFifos(iopipe) - return err - } - ctr.systemPid = systemPid(resp.Container) - close(ready) - - return ctr.client.backend.StateChanged(ctr.containerID, StateInfo{ - CommonStateInfo: CommonStateInfo{ - State: StateStart, - Pid: ctr.systemPid, - }}) -} - -func (ctr *container) newProcess(friendlyName string) *process { - return &process{ - dir: ctr.dir, - processCommon: processCommon{ - containerID: ctr.containerID, - friendlyName: friendlyName, - client: ctr.client, - }, - } -} - -func (ctr *container) handleEvent(e *containerd.Event) error { - ctr.client.lock(ctr.containerID) - defer ctr.client.unlock(ctr.containerID) - switch e.Type { - case StateExit, StatePause, StateResume, StateOOM: - st := StateInfo{ - CommonStateInfo: CommonStateInfo{ - State: e.Type, - ExitCode: e.Status, - }, - OOMKilled: e.Type == StateExit && ctr.oom, - } - if e.Type == StateOOM { - ctr.oom = true - } - if e.Type == StateExit && e.Pid != InitFriendlyName { - st.ProcessID = e.Pid - st.State = StateExitProcess - } - - // Remove process from list if we have exited - switch st.State { - case StateExit: - ctr.clean() - ctr.client.deleteContainer(e.Id) - case StateExitProcess: - ctr.cleanProcess(st.ProcessID) - } - ctr.client.q.append(e.Id, func() { - if err := ctr.client.backend.StateChanged(e.Id, st); err != nil { - logrus.Errorf("libcontainerd: backend.StateChanged(): %v", err) - } - if e.Type == StatePause || e.Type == StateResume { - ctr.pauseMonitor.handle(e.Type) - } - if e.Type == StateExit { - if en := ctr.client.getExitNotifier(e.Id); en != nil { - en.close() - } - } - }) - - default: - logrus.Debugf("libcontainerd: event unhandled: %+v", e) - } - return nil -} - -// discardFifos attempts to fully read the container fifos to unblock processes -// that may be blocked on the writer side. -func (ctr *container) discardFifos() { - ctx, _ := context.WithTimeout(context.Background(), 3*time.Second) - for _, i := range []int{syscall.Stdout, syscall.Stderr} { - f, err := fifo.OpenFifo(ctx, ctr.fifo(i), syscall.O_RDONLY|syscall.O_NONBLOCK, 0) - if err != nil { - logrus.Warnf("error opening fifo %v for discarding: %+v", f, err) - continue - } - go func() { - io.Copy(ioutil.Discard, f) - }() - } -} diff --git a/vendor/github.com/docker/docker/libcontainerd/container_windows.go b/vendor/github.com/docker/docker/libcontainerd/container_windows.go deleted file mode 100644 index 9b19650..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/container_windows.go +++ /dev/null @@ -1,311 +0,0 @@ -package libcontainerd - -import ( - "fmt" - "io" - "io/ioutil" - "strings" - "syscall" - "time" - - "github.com/Microsoft/hcsshim" - "github.com/Sirupsen/logrus" - "github.com/opencontainers/runtime-spec/specs-go" -) - -type container struct { - containerCommon - - // Platform specific fields are below here. There are none presently on Windows. - options []CreateOption - - // The ociSpec is required, as client.Create() needs a spec, - // but can be called from the RestartManager context which does not - // otherwise have access to the Spec - ociSpec specs.Spec - - manualStopRequested bool - hcsContainer hcsshim.Container -} - -func (ctr *container) newProcess(friendlyName string) *process { - return &process{ - processCommon: processCommon{ - containerID: ctr.containerID, - friendlyName: friendlyName, - client: ctr.client, - }, - } -} - -// start starts a created container. -// Caller needs to lock container ID before calling this method. -func (ctr *container) start(attachStdio StdioCallback) error { - var err error - isServicing := false - - for _, option := range ctr.options { - if s, ok := option.(*ServicingOption); ok && s.IsServicing { - isServicing = true - } - } - - // Start the container. If this is a servicing container, this call will block - // until the container is done with the servicing execution. - logrus.Debugln("libcontainerd: starting container ", ctr.containerID) - if err = ctr.hcsContainer.Start(); err != nil { - logrus.Errorf("libcontainerd: failed to start container: %s", err) - if err := ctr.terminate(); err != nil { - logrus.Errorf("libcontainerd: failed to cleanup after a failed Start. %s", err) - } else { - logrus.Debugln("libcontainerd: cleaned up after failed Start by calling Terminate") - } - return err - } - - // Note we always tell HCS to - // create stdout as it's required regardless of '-i' or '-t' options, so that - // docker can always grab the output through logs. We also tell HCS to always - // create stdin, even if it's not used - it will be closed shortly. Stderr - // is only created if it we're not -t. - createProcessParms := &hcsshim.ProcessConfig{ - EmulateConsole: ctr.ociSpec.Process.Terminal, - WorkingDirectory: ctr.ociSpec.Process.Cwd, - CreateStdInPipe: !isServicing, - CreateStdOutPipe: !isServicing, - CreateStdErrPipe: !ctr.ociSpec.Process.Terminal && !isServicing, - } - createProcessParms.ConsoleSize[0] = uint(ctr.ociSpec.Process.ConsoleSize.Height) - createProcessParms.ConsoleSize[1] = uint(ctr.ociSpec.Process.ConsoleSize.Width) - - // Configure the environment for the process - createProcessParms.Environment = setupEnvironmentVariables(ctr.ociSpec.Process.Env) - createProcessParms.CommandLine = strings.Join(ctr.ociSpec.Process.Args, " ") - createProcessParms.User = ctr.ociSpec.Process.User.Username - - // Start the command running in the container. - newProcess, err := ctr.hcsContainer.CreateProcess(createProcessParms) - if err != nil { - logrus.Errorf("libcontainerd: CreateProcess() failed %s", err) - if err := ctr.terminate(); err != nil { - logrus.Errorf("libcontainerd: failed to cleanup after a failed CreateProcess. %s", err) - } else { - logrus.Debugln("libcontainerd: cleaned up after failed CreateProcess by calling Terminate") - } - return err - } - - pid := newProcess.Pid() - - // Save the hcs Process and PID - ctr.process.friendlyName = InitFriendlyName - ctr.process.hcsProcess = newProcess - - // If this is a servicing container, wait on the process synchronously here and - // if it succeeds, wait for it cleanly shutdown and merge into the parent container. - if isServicing { - exitCode := ctr.waitProcessExitCode(&ctr.process) - - if exitCode != 0 { - if err := ctr.terminate(); err != nil { - logrus.Warnf("libcontainerd: terminating servicing container %s failed: %s", ctr.containerID, err) - } - return fmt.Errorf("libcontainerd: servicing container %s returned non-zero exit code %d", ctr.containerID, exitCode) - } - - return ctr.hcsContainer.WaitTimeout(time.Minute * 5) - } - - var stdout, stderr io.ReadCloser - var stdin io.WriteCloser - stdin, stdout, stderr, err = newProcess.Stdio() - if err != nil { - logrus.Errorf("libcontainerd: failed to get stdio pipes: %s", err) - if err := ctr.terminate(); err != nil { - logrus.Errorf("libcontainerd: failed to cleanup after a failed Stdio. %s", err) - } - return err - } - - iopipe := &IOPipe{Terminal: ctr.ociSpec.Process.Terminal} - - iopipe.Stdin = createStdInCloser(stdin, newProcess) - - // Convert io.ReadClosers to io.Readers - if stdout != nil { - iopipe.Stdout = ioutil.NopCloser(&autoClosingReader{ReadCloser: stdout}) - } - if stderr != nil { - iopipe.Stderr = ioutil.NopCloser(&autoClosingReader{ReadCloser: stderr}) - } - - // Save the PID - logrus.Debugf("libcontainerd: process started - PID %d", pid) - ctr.systemPid = uint32(pid) - - // Spin up a go routine waiting for exit to handle cleanup - go ctr.waitExit(&ctr.process, true) - - ctr.client.appendContainer(ctr) - - if err := attachStdio(*iopipe); err != nil { - // OK to return the error here, as waitExit will handle tear-down in HCS - return err - } - - // Tell the docker engine that the container has started. - si := StateInfo{ - CommonStateInfo: CommonStateInfo{ - State: StateStart, - Pid: ctr.systemPid, // Not sure this is needed? Double-check monitor.go in daemon BUGBUG @jhowardmsft - }} - logrus.Debugf("libcontainerd: start() completed OK, %+v", si) - return ctr.client.backend.StateChanged(ctr.containerID, si) - -} - -// waitProcessExitCode will wait for the given process to exit and return its error code. -func (ctr *container) waitProcessExitCode(process *process) int { - // Block indefinitely for the process to exit. - err := process.hcsProcess.Wait() - if err != nil { - if herr, ok := err.(*hcsshim.ProcessError); ok && herr.Err != syscall.ERROR_BROKEN_PIPE { - logrus.Warnf("libcontainerd: Wait() failed (container may have been killed): %s", err) - } - // Fall through here, do not return. This ensures we attempt to continue the - // shutdown in HCS and tell the docker engine that the process/container - // has exited to avoid a container being dropped on the floor. - } - - exitCode, err := process.hcsProcess.ExitCode() - if err != nil { - if herr, ok := err.(*hcsshim.ProcessError); ok && herr.Err != syscall.ERROR_BROKEN_PIPE { - logrus.Warnf("libcontainerd: unable to get exit code from container %s", ctr.containerID) - } - // Since we got an error retrieving the exit code, make sure that the code we return - // doesn't incorrectly indicate success. - exitCode = -1 - - // Fall through here, do not return. This ensures we attempt to continue the - // shutdown in HCS and tell the docker engine that the process/container - // has exited to avoid a container being dropped on the floor. - } - - return exitCode -} - -// waitExit runs as a goroutine waiting for the process to exit. It's -// equivalent to (in the linux containerd world) where events come in for -// state change notifications from containerd. -func (ctr *container) waitExit(process *process, isFirstProcessToStart bool) error { - logrus.Debugln("libcontainerd: waitExit() on pid", process.systemPid) - - exitCode := ctr.waitProcessExitCode(process) - // Lock the container while shutting down - ctr.client.lock(ctr.containerID) - - // Assume the container has exited - si := StateInfo{ - CommonStateInfo: CommonStateInfo{ - State: StateExit, - ExitCode: uint32(exitCode), - Pid: process.systemPid, - ProcessID: process.friendlyName, - }, - UpdatePending: false, - } - - // But it could have been an exec'd process which exited - if !isFirstProcessToStart { - si.State = StateExitProcess - ctr.cleanProcess(process.friendlyName) - } else { - updatePending, err := ctr.hcsContainer.HasPendingUpdates() - if err != nil { - logrus.Warnf("libcontainerd: HasPendingUpdates() failed (container may have been killed): %s", err) - } else { - si.UpdatePending = updatePending - } - - logrus.Debugf("libcontainerd: shutting down container %s", ctr.containerID) - if err := ctr.shutdown(); err != nil { - logrus.Debugf("libcontainerd: failed to shutdown container %s", ctr.containerID) - } else { - logrus.Debugf("libcontainerd: completed shutting down container %s", ctr.containerID) - } - if err := ctr.hcsContainer.Close(); err != nil { - logrus.Error(err) - } - - // Remove process from list if we have exited - if si.State == StateExit { - ctr.client.deleteContainer(ctr.containerID) - } - } - - if err := process.hcsProcess.Close(); err != nil { - logrus.Errorf("libcontainerd: hcsProcess.Close(): %v", err) - } - - // Unlock here before we call back into the daemon to update state - ctr.client.unlock(ctr.containerID) - - // Call into the backend to notify it of the state change. - logrus.Debugf("libcontainerd: waitExit() calling backend.StateChanged %+v", si) - if err := ctr.client.backend.StateChanged(ctr.containerID, si); err != nil { - logrus.Error(err) - } - - logrus.Debugf("libcontainerd: waitExit() completed OK, %+v", si) - - return nil -} - -// cleanProcess removes process from the map. -// Caller needs to lock container ID before calling this method. -func (ctr *container) cleanProcess(id string) { - delete(ctr.processes, id) -} - -// shutdown shuts down the container in HCS -// Caller needs to lock container ID before calling this method. -func (ctr *container) shutdown() error { - const shutdownTimeout = time.Minute * 5 - err := ctr.hcsContainer.Shutdown() - if hcsshim.IsPending(err) { - // Explicit timeout to avoid a (remote) possibility that shutdown hangs indefinitely. - err = ctr.hcsContainer.WaitTimeout(shutdownTimeout) - } else if hcsshim.IsAlreadyStopped(err) { - err = nil - } - - if err != nil { - logrus.Debugf("libcontainerd: error shutting down container %s %v calling terminate", ctr.containerID, err) - if err := ctr.terminate(); err != nil { - return err - } - return err - } - - return nil -} - -// terminate terminates the container in HCS -// Caller needs to lock container ID before calling this method. -func (ctr *container) terminate() error { - const terminateTimeout = time.Minute * 5 - err := ctr.hcsContainer.Terminate() - - if hcsshim.IsPending(err) { - err = ctr.hcsContainer.WaitTimeout(terminateTimeout) - } else if hcsshim.IsAlreadyStopped(err) { - err = nil - } - - if err != nil { - logrus.Debugf("libcontainerd: error terminating container %s %v", ctr.containerID, err) - return err - } - - return nil -} diff --git a/vendor/github.com/docker/docker/libcontainerd/oom_linux.go b/vendor/github.com/docker/docker/libcontainerd/oom_linux.go deleted file mode 100644 index e126b7a..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/oom_linux.go +++ /dev/null @@ -1,31 +0,0 @@ -package libcontainerd - -import ( - "fmt" - "os" - "strconv" - - "github.com/Sirupsen/logrus" - "github.com/opencontainers/runc/libcontainer/system" -) - -func setOOMScore(pid, score int) error { - oomScoreAdjPath := fmt.Sprintf("/proc/%d/oom_score_adj", pid) - f, err := os.OpenFile(oomScoreAdjPath, os.O_WRONLY, 0) - if err != nil { - return err - } - stringScore := strconv.Itoa(score) - _, err = f.WriteString(stringScore) - f.Close() - if os.IsPermission(err) { - // Setting oom_score_adj does not work in an - // unprivileged container. Ignore the error, but log - // it if we appear not to be in that situation. - if !system.RunningInUserNS() { - logrus.Debugf("Permission denied writing %q to %s", stringScore, oomScoreAdjPath) - } - return nil - } - return err -} diff --git a/vendor/github.com/docker/docker/libcontainerd/oom_solaris.go b/vendor/github.com/docker/docker/libcontainerd/oom_solaris.go deleted file mode 100644 index 2ebe5e8..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/oom_solaris.go +++ /dev/null @@ -1,5 +0,0 @@ -package libcontainerd - -func setOOMScore(pid, score int) error { - return nil -} diff --git a/vendor/github.com/docker/docker/libcontainerd/pausemonitor_unix.go b/vendor/github.com/docker/docker/libcontainerd/pausemonitor_unix.go deleted file mode 100644 index 4f3766d..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/pausemonitor_unix.go +++ /dev/null @@ -1,42 +0,0 @@ -// +build !windows - -package libcontainerd - -import ( - "sync" -) - -// pauseMonitor is helper to get notifications from pause state changes. -type pauseMonitor struct { - sync.Mutex - waiters map[string][]chan struct{} -} - -func (m *pauseMonitor) handle(t string) { - m.Lock() - defer m.Unlock() - if m.waiters == nil { - return - } - q, ok := m.waiters[t] - if !ok { - return - } - if len(q) > 0 { - close(q[0]) - m.waiters[t] = q[1:] - } -} - -func (m *pauseMonitor) append(t string, waiter chan struct{}) { - m.Lock() - defer m.Unlock() - if m.waiters == nil { - m.waiters = make(map[string][]chan struct{}) - } - _, ok := m.waiters[t] - if !ok { - m.waiters[t] = make([]chan struct{}, 0) - } - m.waiters[t] = append(m.waiters[t], waiter) -} diff --git a/vendor/github.com/docker/docker/libcontainerd/process.go b/vendor/github.com/docker/docker/libcontainerd/process.go deleted file mode 100644 index 57562c8..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/process.go +++ /dev/null @@ -1,18 +0,0 @@ -package libcontainerd - -// processCommon are the platform common fields as part of the process structure -// which keeps the state for the main container process, as well as any exec -// processes. -type processCommon struct { - client *client - - // containerID is the Container ID - containerID string - - // friendlyName is an identifier for the process (or `InitFriendlyName` - // for the first process) - friendlyName string - - // systemPid is the PID of the main container process - systemPid uint32 -} diff --git a/vendor/github.com/docker/docker/libcontainerd/process_unix.go b/vendor/github.com/docker/docker/libcontainerd/process_unix.go deleted file mode 100644 index 506fca6..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/process_unix.go +++ /dev/null @@ -1,107 +0,0 @@ -// +build linux solaris - -package libcontainerd - -import ( - "io" - "io/ioutil" - "os" - "path/filepath" - goruntime "runtime" - "strings" - - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/tonistiigi/fifo" - "golang.org/x/net/context" - "golang.org/x/sys/unix" -) - -var fdNames = map[int]string{ - unix.Stdin: "stdin", - unix.Stdout: "stdout", - unix.Stderr: "stderr", -} - -// process keeps the state for both main container process and exec process. -type process struct { - processCommon - - // Platform specific fields are below here. - dir string -} - -func (p *process) openFifos(ctx context.Context, terminal bool) (pipe *IOPipe, err error) { - if err := os.MkdirAll(p.dir, 0700); err != nil { - return nil, err - } - - io := &IOPipe{} - - io.Stdin, err = fifo.OpenFifo(ctx, p.fifo(unix.Stdin), unix.O_WRONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700) - if err != nil { - return nil, err - } - - defer func() { - if err != nil { - io.Stdin.Close() - } - }() - - io.Stdout, err = fifo.OpenFifo(ctx, p.fifo(unix.Stdout), unix.O_RDONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700) - if err != nil { - return nil, err - } - - defer func() { - if err != nil { - io.Stdout.Close() - } - }() - - if goruntime.GOOS == "solaris" || !terminal { - // For Solaris terminal handling is done exclusively by the runtime therefore we make no distinction - // in the processing for terminal and !terminal cases. - io.Stderr, err = fifo.OpenFifo(ctx, p.fifo(unix.Stderr), unix.O_RDONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700) - if err != nil { - return nil, err - } - defer func() { - if err != nil { - io.Stderr.Close() - } - }() - } else { - io.Stderr = ioutil.NopCloser(emptyReader{}) - } - - return io, nil -} - -func (p *process) sendCloseStdin() error { - _, err := p.client.remote.apiClient.UpdateProcess(context.Background(), &containerd.UpdateProcessRequest{ - Id: p.containerID, - Pid: p.friendlyName, - CloseStdin: true, - }) - if err != nil && (strings.Contains(err.Error(), "container not found") || strings.Contains(err.Error(), "process not found")) { - return nil - } - return err -} - -func (p *process) closeFifos(io *IOPipe) { - io.Stdin.Close() - io.Stdout.Close() - io.Stderr.Close() -} - -type emptyReader struct{} - -func (r emptyReader) Read(b []byte) (int, error) { - return 0, io.EOF -} - -func (p *process) fifo(index int) string { - return filepath.Join(p.dir, p.friendlyName+"-"+fdNames[index]) -} diff --git a/vendor/github.com/docker/docker/libcontainerd/process_windows.go b/vendor/github.com/docker/docker/libcontainerd/process_windows.go deleted file mode 100644 index 57ecc94..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/process_windows.go +++ /dev/null @@ -1,51 +0,0 @@ -package libcontainerd - -import ( - "io" - "sync" - - "github.com/Microsoft/hcsshim" - "github.com/docker/docker/pkg/ioutils" -) - -// process keeps the state for both main container process and exec process. -type process struct { - processCommon - - // Platform specific fields are below here. - - // commandLine is to support returning summary information for docker top - commandLine string - hcsProcess hcsshim.Process -} - -type autoClosingReader struct { - io.ReadCloser - sync.Once -} - -func (r *autoClosingReader) Read(b []byte) (n int, err error) { - n, err = r.ReadCloser.Read(b) - if err == io.EOF { - r.Once.Do(func() { r.ReadCloser.Close() }) - } - return -} - -func createStdInCloser(pipe io.WriteCloser, process hcsshim.Process) io.WriteCloser { - return ioutils.NewWriteCloserWrapper(pipe, func() error { - if err := pipe.Close(); err != nil { - return err - } - - err := process.CloseStdin() - if err != nil && !hcsshim.IsNotExist(err) && !hcsshim.IsAlreadyClosed(err) { - // This error will occur if the compute system is currently shutting down - if perr, ok := err.(*hcsshim.ProcessError); ok && perr.Err != hcsshim.ErrVmcomputeOperationInvalidState { - return err - } - } - - return nil - }) -} diff --git a/vendor/github.com/docker/docker/libcontainerd/queue_unix.go b/vendor/github.com/docker/docker/libcontainerd/queue_unix.go deleted file mode 100644 index b848b98..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/queue_unix.go +++ /dev/null @@ -1,31 +0,0 @@ -// +build linux solaris - -package libcontainerd - -import "sync" - -type queue struct { - sync.Mutex - fns map[string]chan struct{} -} - -func (q *queue) append(id string, f func()) { - q.Lock() - defer q.Unlock() - - if q.fns == nil { - q.fns = make(map[string]chan struct{}) - } - - done := make(chan struct{}) - - fn, ok := q.fns[id] - q.fns[id] = done - go func() { - if ok { - <-fn - } - f() - close(done) - }() -} diff --git a/vendor/github.com/docker/docker/libcontainerd/remote.go b/vendor/github.com/docker/docker/libcontainerd/remote.go deleted file mode 100644 index 9031e3a..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/remote.go +++ /dev/null @@ -1,20 +0,0 @@ -package libcontainerd - -// Remote on Linux defines the accesspoint to the containerd grpc API. -// Remote on Windows is largely an unimplemented interface as there is -// no remote containerd. -type Remote interface { - // Client returns a new Client instance connected with given Backend. - Client(Backend) (Client, error) - // Cleanup stops containerd if it was started by libcontainerd. - // Note this is not used on Windows as there is no remote containerd. - Cleanup() - // UpdateOptions allows various remote options to be updated at runtime. - UpdateOptions(...RemoteOption) error -} - -// RemoteOption allows to configure parameters of remotes. -// This is unused on Windows. -type RemoteOption interface { - Apply(Remote) error -} diff --git a/vendor/github.com/docker/docker/libcontainerd/remote_unix.go b/vendor/github.com/docker/docker/libcontainerd/remote_unix.go deleted file mode 100644 index 64a2864..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/remote_unix.go +++ /dev/null @@ -1,544 +0,0 @@ -// +build linux solaris - -package libcontainerd - -import ( - "fmt" - "io" - "io/ioutil" - "log" - "net" - "os" - "os/exec" - "path/filepath" - goruntime "runtime" - "strconv" - "strings" - "sync" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/docker/docker/pkg/locker" - sysinfo "github.com/docker/docker/pkg/system" - "github.com/docker/docker/utils" - "github.com/golang/protobuf/ptypes" - "github.com/golang/protobuf/ptypes/timestamp" - "golang.org/x/net/context" - "google.golang.org/grpc" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/health/grpc_health_v1" - "google.golang.org/grpc/transport" -) - -const ( - maxConnectionRetryCount = 3 - containerdHealthCheckTimeout = 3 * time.Second - containerdShutdownTimeout = 15 * time.Second - containerdBinary = "docker-containerd" - containerdPidFilename = "docker-containerd.pid" - containerdSockFilename = "docker-containerd.sock" - containerdStateDir = "containerd" - eventTimestampFilename = "event.ts" -) - -type remote struct { - sync.RWMutex - apiClient containerd.APIClient - daemonPid int - stateDir string - rpcAddr string - startDaemon bool - closeManually bool - debugLog bool - rpcConn *grpc.ClientConn - clients []*client - eventTsPath string - runtime string - runtimeArgs []string - daemonWaitCh chan struct{} - liveRestore bool - oomScore int - restoreFromTimestamp *timestamp.Timestamp -} - -// New creates a fresh instance of libcontainerd remote. -func New(stateDir string, options ...RemoteOption) (_ Remote, err error) { - defer func() { - if err != nil { - err = fmt.Errorf("Failed to connect to containerd. Please make sure containerd is installed in your PATH or you have specified the correct address. Got error: %v", err) - } - }() - r := &remote{ - stateDir: stateDir, - daemonPid: -1, - eventTsPath: filepath.Join(stateDir, eventTimestampFilename), - } - for _, option := range options { - if err := option.Apply(r); err != nil { - return nil, err - } - } - - if err := sysinfo.MkdirAll(stateDir, 0700); err != nil { - return nil, err - } - - if r.rpcAddr == "" { - r.rpcAddr = filepath.Join(stateDir, containerdSockFilename) - } - - if r.startDaemon { - if err := r.runContainerdDaemon(); err != nil { - return nil, err - } - } - - // don't output the grpc reconnect logging - grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags)) - dialOpts := append([]grpc.DialOption{grpc.WithInsecure()}, - grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { - return net.DialTimeout("unix", addr, timeout) - }), - ) - conn, err := grpc.Dial(r.rpcAddr, dialOpts...) - if err != nil { - return nil, fmt.Errorf("error connecting to containerd: %v", err) - } - - r.rpcConn = conn - r.apiClient = containerd.NewAPIClient(conn) - - // Get the timestamp to restore from - t := r.getLastEventTimestamp() - tsp, err := ptypes.TimestampProto(t) - if err != nil { - logrus.Errorf("libcontainerd: failed to convert timestamp: %q", err) - } - r.restoreFromTimestamp = tsp - - go r.handleConnectionChange() - - if err := r.startEventsMonitor(); err != nil { - return nil, err - } - - return r, nil -} - -func (r *remote) UpdateOptions(options ...RemoteOption) error { - for _, option := range options { - if err := option.Apply(r); err != nil { - return err - } - } - return nil -} - -func (r *remote) handleConnectionChange() { - var transientFailureCount = 0 - - ticker := time.NewTicker(500 * time.Millisecond) - defer ticker.Stop() - healthClient := grpc_health_v1.NewHealthClient(r.rpcConn) - - for { - <-ticker.C - ctx, cancel := context.WithTimeout(context.Background(), containerdHealthCheckTimeout) - _, err := healthClient.Check(ctx, &grpc_health_v1.HealthCheckRequest{}) - cancel() - if err == nil { - continue - } - - logrus.Debugf("libcontainerd: containerd health check returned error: %v", err) - - if r.daemonPid != -1 { - if strings.Contains(err.Error(), "is closing") { - // Well, we asked for it to stop, just return - return - } - // all other errors are transient - // Reset state to be notified of next failure - transientFailureCount++ - if transientFailureCount >= maxConnectionRetryCount { - transientFailureCount = 0 - if utils.IsProcessAlive(r.daemonPid) { - utils.KillProcess(r.daemonPid) - } - <-r.daemonWaitCh - if err := r.runContainerdDaemon(); err != nil { //FIXME: Handle error - logrus.Errorf("libcontainerd: error restarting containerd: %v", err) - } - continue - } - } - } -} - -func (r *remote) Cleanup() { - if r.daemonPid == -1 { - return - } - r.closeManually = true - r.rpcConn.Close() - // Ask the daemon to quit - syscall.Kill(r.daemonPid, syscall.SIGTERM) - - // Wait up to 15secs for it to stop - for i := time.Duration(0); i < containerdShutdownTimeout; i += time.Second { - if !utils.IsProcessAlive(r.daemonPid) { - break - } - time.Sleep(time.Second) - } - - if utils.IsProcessAlive(r.daemonPid) { - logrus.Warnf("libcontainerd: containerd (%d) didn't stop within 15 secs, killing it\n", r.daemonPid) - syscall.Kill(r.daemonPid, syscall.SIGKILL) - } - - // cleanup some files - os.Remove(filepath.Join(r.stateDir, containerdPidFilename)) - os.Remove(filepath.Join(r.stateDir, containerdSockFilename)) -} - -func (r *remote) Client(b Backend) (Client, error) { - c := &client{ - clientCommon: clientCommon{ - backend: b, - containers: make(map[string]*container), - locker: locker.New(), - }, - remote: r, - exitNotifiers: make(map[string]*exitNotifier), - liveRestore: r.liveRestore, - } - - r.Lock() - r.clients = append(r.clients, c) - r.Unlock() - return c, nil -} - -func (r *remote) updateEventTimestamp(t time.Time) { - f, err := os.OpenFile(r.eventTsPath, syscall.O_CREAT|syscall.O_WRONLY|syscall.O_TRUNC, 0600) - if err != nil { - logrus.Warnf("libcontainerd: failed to open event timestamp file: %v", err) - return - } - defer f.Close() - - b, err := t.MarshalText() - if err != nil { - logrus.Warnf("libcontainerd: failed to encode timestamp: %v", err) - return - } - - n, err := f.Write(b) - if err != nil || n != len(b) { - logrus.Warnf("libcontainerd: failed to update event timestamp file: %v", err) - f.Truncate(0) - return - } -} - -func (r *remote) getLastEventTimestamp() time.Time { - t := time.Now() - - fi, err := os.Stat(r.eventTsPath) - if os.IsNotExist(err) || fi.Size() == 0 { - return t - } - - f, err := os.Open(r.eventTsPath) - if err != nil { - logrus.Warnf("libcontainerd: Unable to access last event ts: %v", err) - return t - } - defer f.Close() - - b := make([]byte, fi.Size()) - n, err := f.Read(b) - if err != nil || n != len(b) { - logrus.Warnf("libcontainerd: Unable to read last event ts: %v", err) - return t - } - - t.UnmarshalText(b) - - return t -} - -func (r *remote) startEventsMonitor() error { - // First, get past events - t := r.getLastEventTimestamp() - tsp, err := ptypes.TimestampProto(t) - if err != nil { - logrus.Errorf("libcontainerd: failed to convert timestamp: %q", err) - } - er := &containerd.EventsRequest{ - Timestamp: tsp, - } - events, err := r.apiClient.Events(context.Background(), er, grpc.FailFast(false)) - if err != nil { - return err - } - go r.handleEventStream(events) - return nil -} - -func (r *remote) handleEventStream(events containerd.API_EventsClient) { - for { - e, err := events.Recv() - if err != nil { - if grpc.ErrorDesc(err) == transport.ErrConnClosing.Desc && - r.closeManually { - // ignore error if grpc remote connection is closed manually - return - } - logrus.Errorf("libcontainerd: failed to receive event from containerd: %v", err) - go r.startEventsMonitor() - return - } - - logrus.Debugf("libcontainerd: received containerd event: %#v", e) - - var container *container - var c *client - r.RLock() - for _, c = range r.clients { - container, err = c.getContainer(e.Id) - if err == nil { - break - } - } - r.RUnlock() - if container == nil { - logrus.Warnf("libcontainerd: unknown container %s", e.Id) - continue - } - - if err := container.handleEvent(e); err != nil { - logrus.Errorf("libcontainerd: error processing state change for %s: %v", e.Id, err) - } - - tsp, err := ptypes.Timestamp(e.Timestamp) - if err != nil { - logrus.Errorf("libcontainerd: failed to convert event timestamp: %q", err) - continue - } - - r.updateEventTimestamp(tsp) - } -} - -func (r *remote) runContainerdDaemon() error { - pidFilename := filepath.Join(r.stateDir, containerdPidFilename) - f, err := os.OpenFile(pidFilename, os.O_RDWR|os.O_CREATE, 0600) - if err != nil { - return err - } - defer f.Close() - - // File exist, check if the daemon is alive - b := make([]byte, 8) - n, err := f.Read(b) - if err != nil && err != io.EOF { - return err - } - - if n > 0 { - pid, err := strconv.ParseUint(string(b[:n]), 10, 64) - if err != nil { - return err - } - if utils.IsProcessAlive(int(pid)) { - logrus.Infof("libcontainerd: previous instance of containerd still alive (%d)", pid) - r.daemonPid = int(pid) - return nil - } - } - - // rewind the file - _, err = f.Seek(0, os.SEEK_SET) - if err != nil { - return err - } - - // Truncate it - err = f.Truncate(0) - if err != nil { - return err - } - - // Start a new instance - args := []string{ - "-l", fmt.Sprintf("unix://%s", r.rpcAddr), - "--metrics-interval=0", - "--start-timeout", "2m", - "--state-dir", filepath.Join(r.stateDir, containerdStateDir), - } - if goruntime.GOOS == "solaris" { - args = append(args, "--shim", "containerd-shim", "--runtime", "runc") - } else { - args = append(args, "--shim", "docker-containerd-shim") - if r.runtime != "" { - args = append(args, "--runtime") - args = append(args, r.runtime) - } - } - if r.debugLog { - args = append(args, "--debug") - } - if len(r.runtimeArgs) > 0 { - for _, v := range r.runtimeArgs { - args = append(args, "--runtime-args") - args = append(args, v) - } - logrus.Debugf("libcontainerd: runContainerdDaemon: runtimeArgs: %s", args) - } - - cmd := exec.Command(containerdBinary, args...) - // redirect containerd logs to docker logs - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.SysProcAttr = setSysProcAttr(true) - cmd.Env = nil - // clear the NOTIFY_SOCKET from the env when starting containerd - for _, e := range os.Environ() { - if !strings.HasPrefix(e, "NOTIFY_SOCKET") { - cmd.Env = append(cmd.Env, e) - } - } - if err := cmd.Start(); err != nil { - return err - } - logrus.Infof("libcontainerd: new containerd process, pid: %d", cmd.Process.Pid) - if err := setOOMScore(cmd.Process.Pid, r.oomScore); err != nil { - utils.KillProcess(cmd.Process.Pid) - return err - } - if _, err := f.WriteString(fmt.Sprintf("%d", cmd.Process.Pid)); err != nil { - utils.KillProcess(cmd.Process.Pid) - return err - } - - r.daemonWaitCh = make(chan struct{}) - go func() { - cmd.Wait() - close(r.daemonWaitCh) - }() // Reap our child when needed - r.daemonPid = cmd.Process.Pid - return nil -} - -// WithRemoteAddr sets the external containerd socket to connect to. -func WithRemoteAddr(addr string) RemoteOption { - return rpcAddr(addr) -} - -type rpcAddr string - -func (a rpcAddr) Apply(r Remote) error { - if remote, ok := r.(*remote); ok { - remote.rpcAddr = string(a) - return nil - } - return fmt.Errorf("WithRemoteAddr option not supported for this remote") -} - -// WithRuntimePath sets the path of the runtime to be used as the -// default by containerd -func WithRuntimePath(rt string) RemoteOption { - return runtimePath(rt) -} - -type runtimePath string - -func (rt runtimePath) Apply(r Remote) error { - if remote, ok := r.(*remote); ok { - remote.runtime = string(rt) - return nil - } - return fmt.Errorf("WithRuntime option not supported for this remote") -} - -// WithRuntimeArgs sets the list of runtime args passed to containerd -func WithRuntimeArgs(args []string) RemoteOption { - return runtimeArgs(args) -} - -type runtimeArgs []string - -func (rt runtimeArgs) Apply(r Remote) error { - if remote, ok := r.(*remote); ok { - remote.runtimeArgs = rt - return nil - } - return fmt.Errorf("WithRuntimeArgs option not supported for this remote") -} - -// WithStartDaemon defines if libcontainerd should also run containerd daemon. -func WithStartDaemon(start bool) RemoteOption { - return startDaemon(start) -} - -type startDaemon bool - -func (s startDaemon) Apply(r Remote) error { - if remote, ok := r.(*remote); ok { - remote.startDaemon = bool(s) - return nil - } - return fmt.Errorf("WithStartDaemon option not supported for this remote") -} - -// WithDebugLog defines if containerd debug logs will be enabled for daemon. -func WithDebugLog(debug bool) RemoteOption { - return debugLog(debug) -} - -type debugLog bool - -func (d debugLog) Apply(r Remote) error { - if remote, ok := r.(*remote); ok { - remote.debugLog = bool(d) - return nil - } - return fmt.Errorf("WithDebugLog option not supported for this remote") -} - -// WithLiveRestore defines if containers are stopped on shutdown or restored. -func WithLiveRestore(v bool) RemoteOption { - return liveRestore(v) -} - -type liveRestore bool - -func (l liveRestore) Apply(r Remote) error { - if remote, ok := r.(*remote); ok { - remote.liveRestore = bool(l) - for _, c := range remote.clients { - c.liveRestore = bool(l) - } - return nil - } - return fmt.Errorf("WithLiveRestore option not supported for this remote") -} - -// WithOOMScore defines the oom_score_adj to set for the containerd process. -func WithOOMScore(score int) RemoteOption { - return oomScore(score) -} - -type oomScore int - -func (o oomScore) Apply(r Remote) error { - if remote, ok := r.(*remote); ok { - remote.oomScore = int(o) - return nil - } - return fmt.Errorf("WithOOMScore option not supported for this remote") -} diff --git a/vendor/github.com/docker/docker/libcontainerd/remote_windows.go b/vendor/github.com/docker/docker/libcontainerd/remote_windows.go deleted file mode 100644 index 74c1044..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/remote_windows.go +++ /dev/null @@ -1,36 +0,0 @@ -package libcontainerd - -import "github.com/docker/docker/pkg/locker" - -type remote struct { -} - -func (r *remote) Client(b Backend) (Client, error) { - c := &client{ - clientCommon: clientCommon{ - backend: b, - containers: make(map[string]*container), - locker: locker.New(), - }, - } - return c, nil -} - -// Cleanup is a no-op on Windows. It is here to implement the interface. -func (r *remote) Cleanup() { -} - -func (r *remote) UpdateOptions(opts ...RemoteOption) error { - return nil -} - -// New creates a fresh instance of libcontainerd remote. On Windows, -// this is not used as there is no remote containerd process. -func New(_ string, _ ...RemoteOption) (Remote, error) { - return &remote{}, nil -} - -// WithLiveRestore is a noop on windows. -func WithLiveRestore(v bool) RemoteOption { - return nil -} diff --git a/vendor/github.com/docker/docker/libcontainerd/types.go b/vendor/github.com/docker/docker/libcontainerd/types.go deleted file mode 100644 index 3d981e3..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/types.go +++ /dev/null @@ -1,75 +0,0 @@ -package libcontainerd - -import ( - "io" - - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/opencontainers/runtime-spec/specs-go" - "golang.org/x/net/context" -) - -// State constants used in state change reporting. -const ( - StateStart = "start-container" - StatePause = "pause" - StateResume = "resume" - StateExit = "exit" - StateRestore = "restore" - StateExitProcess = "exit-process" - StateOOM = "oom" // fake state -) - -// CommonStateInfo contains the state info common to all platforms. -type CommonStateInfo struct { // FIXME: event? - State string - Pid uint32 - ExitCode uint32 - ProcessID string -} - -// Backend defines callbacks that the client of the library needs to implement. -type Backend interface { - StateChanged(containerID string, state StateInfo) error -} - -// Client provides access to containerd features. -type Client interface { - GetServerVersion(ctx context.Context) (*ServerVersion, error) - Create(containerID string, checkpoint string, checkpointDir string, spec specs.Spec, attachStdio StdioCallback, options ...CreateOption) error - Signal(containerID string, sig int) error - SignalProcess(containerID string, processFriendlyName string, sig int) error - AddProcess(ctx context.Context, containerID, processFriendlyName string, process Process, attachStdio StdioCallback) (int, error) - Resize(containerID, processFriendlyName string, width, height int) error - Pause(containerID string) error - Resume(containerID string) error - Restore(containerID string, attachStdio StdioCallback, options ...CreateOption) error - Stats(containerID string) (*Stats, error) - GetPidsForContainer(containerID string) ([]int, error) - Summary(containerID string) ([]Summary, error) - UpdateResources(containerID string, resources Resources) error - CreateCheckpoint(containerID string, checkpointID string, checkpointDir string, exit bool) error - DeleteCheckpoint(containerID string, checkpointID string, checkpointDir string) error - ListCheckpoints(containerID string, checkpointDir string) (*Checkpoints, error) -} - -// CreateOption allows to configure parameters of container creation. -type CreateOption interface { - Apply(interface{}) error -} - -// StdioCallback is called to connect a container or process stdio. -type StdioCallback func(IOPipe) error - -// IOPipe contains the stdio streams. -type IOPipe struct { - Stdin io.WriteCloser - Stdout io.ReadCloser - Stderr io.ReadCloser - Terminal bool // Whether stderr is connected on Windows -} - -// ServerVersion contains version information as retrieved from the -// server -type ServerVersion struct { - containerd.GetServerVersionResponse -} diff --git a/vendor/github.com/docker/docker/libcontainerd/types_linux.go b/vendor/github.com/docker/docker/libcontainerd/types_linux.go deleted file mode 100644 index cc2a17a..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/types_linux.go +++ /dev/null @@ -1,49 +0,0 @@ -package libcontainerd - -import ( - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/opencontainers/runtime-spec/specs-go" -) - -// Process contains information to start a specific application inside the container. -type Process struct { - // Terminal creates an interactive terminal for the container. - Terminal bool `json:"terminal"` - // User specifies user information for the process. - User *specs.User `json:"user"` - // Args specifies the binary and arguments for the application to execute. - Args []string `json:"args"` - // Env populates the process environment for the process. - Env []string `json:"env,omitempty"` - // Cwd is the current working directory for the process and must be - // relative to the container's root. - Cwd *string `json:"cwd"` - // Capabilities are linux capabilities that are kept for the container. - Capabilities []string `json:"capabilities,omitempty"` - // Rlimits specifies rlimit options to apply to the process. - Rlimits []specs.Rlimit `json:"rlimits,omitempty"` - // ApparmorProfile specifies the apparmor profile for the container. - ApparmorProfile *string `json:"apparmorProfile,omitempty"` - // SelinuxLabel specifies the selinux context that the container process is run as. - SelinuxLabel *string `json:"selinuxLabel,omitempty"` -} - -// StateInfo contains description about the new state container has entered. -type StateInfo struct { - CommonStateInfo - - // Platform specific StateInfo - OOMKilled bool -} - -// Stats contains a stats properties from containerd. -type Stats containerd.StatsResponse - -// Summary contains a container summary from containerd -type Summary struct{} - -// Resources defines updatable container resource values. -type Resources containerd.UpdateResource - -// Checkpoints contains the details of a checkpoint -type Checkpoints containerd.ListCheckpointResponse diff --git a/vendor/github.com/docker/docker/libcontainerd/types_solaris.go b/vendor/github.com/docker/docker/libcontainerd/types_solaris.go deleted file mode 100644 index dbafef6..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/types_solaris.go +++ /dev/null @@ -1,43 +0,0 @@ -package libcontainerd - -import ( - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/opencontainers/runtime-spec/specs-go" -) - -// Process contains information to start a specific application inside the container. -type Process struct { - // Terminal creates an interactive terminal for the container. - Terminal bool `json:"terminal"` - // User specifies user information for the process. - User *specs.User `json:"user"` - // Args specifies the binary and arguments for the application to execute. - Args []string `json:"args"` - // Env populates the process environment for the process. - Env []string `json:"env,omitempty"` - // Cwd is the current working directory for the process and must be - // relative to the container's root. - Cwd *string `json:"cwd"` - // Capabilities are linux capabilities that are kept for the container. - Capabilities []string `json:"capabilities,omitempty"` -} - -// Stats contains a stats properties from containerd. -type Stats struct{} - -// Summary contains a container summary from containerd -type Summary struct{} - -// StateInfo contains description about the new state container has entered. -type StateInfo struct { - CommonStateInfo - - // Platform specific StateInfo - OOMKilled bool -} - -// Resources defines updatable container resource values. -type Resources struct{} - -// Checkpoints contains the details of a checkpoint -type Checkpoints containerd.ListCheckpointResponse diff --git a/vendor/github.com/docker/docker/libcontainerd/types_windows.go b/vendor/github.com/docker/docker/libcontainerd/types_windows.go deleted file mode 100644 index 24a9a96..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/types_windows.go +++ /dev/null @@ -1,79 +0,0 @@ -package libcontainerd - -import ( - "github.com/Microsoft/hcsshim" - "github.com/opencontainers/runtime-spec/specs-go" -) - -// Process contains information to start a specific application inside the container. -type Process specs.Process - -// Summary contains a ProcessList item from HCS to support `top` -type Summary hcsshim.ProcessListItem - -// StateInfo contains description about the new state container has entered. -type StateInfo struct { - CommonStateInfo - - // Platform specific StateInfo - - UpdatePending bool // Indicates that there are some update operations pending that should be completed by a servicing container. -} - -// Stats contains statics from HCS -type Stats hcsshim.Statistics - -// Resources defines updatable container resource values. -type Resources struct{} - -// ServicingOption is a CreateOption with a no-op application that signifies -// the container needs to be used for a Windows servicing operation. -type ServicingOption struct { - IsServicing bool -} - -// FlushOption is a CreateOption that signifies if the container should be -// started with flushes ignored until boot has completed. This is an optimisation -// for first boot of a container. -type FlushOption struct { - IgnoreFlushesDuringBoot bool -} - -// HyperVIsolationOption is a CreateOption that indicates whether the runtime -// should start the container as a Hyper-V container, and if so, the sandbox path. -type HyperVIsolationOption struct { - IsHyperV bool - SandboxPath string `json:",omitempty"` -} - -// LayerOption is a CreateOption that indicates to the runtime the layer folder -// and layer paths for a container. -type LayerOption struct { - // LayerFolder is the path to the current layer folder. Empty for Hyper-V containers. - LayerFolderPath string `json:",omitempty"` - // Layer paths of the parent layers - LayerPaths []string -} - -// NetworkEndpointsOption is a CreateOption that provides the runtime list -// of network endpoints to which a container should be attached during its creation. -type NetworkEndpointsOption struct { - Endpoints []string - AllowUnqualifiedDNSQuery bool -} - -// CredentialsOption is a CreateOption that indicates the credentials from -// a credential spec to be used to the runtime -type CredentialsOption struct { - Credentials string -} - -// Checkpoint holds the details of a checkpoint (not supported in windows) -type Checkpoint struct { - Name string -} - -// Checkpoints contains the details of a checkpoint -type Checkpoints struct { - Checkpoints []*Checkpoint -} diff --git a/vendor/github.com/docker/docker/libcontainerd/utils_linux.go b/vendor/github.com/docker/docker/libcontainerd/utils_linux.go deleted file mode 100644 index 78828bc..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/utils_linux.go +++ /dev/null @@ -1,62 +0,0 @@ -package libcontainerd - -import ( - "syscall" - - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/opencontainers/runtime-spec/specs-go" -) - -func getRootIDs(s specs.Spec) (int, int, error) { - var hasUserns bool - for _, ns := range s.Linux.Namespaces { - if ns.Type == specs.UserNamespace { - hasUserns = true - break - } - } - if !hasUserns { - return 0, 0, nil - } - uid := hostIDFromMap(0, s.Linux.UIDMappings) - gid := hostIDFromMap(0, s.Linux.GIDMappings) - return uid, gid, nil -} - -func hostIDFromMap(id uint32, mp []specs.IDMapping) int { - for _, m := range mp { - if id >= m.ContainerID && id <= m.ContainerID+m.Size-1 { - return int(m.HostID + id - m.ContainerID) - } - } - return 0 -} - -func systemPid(ctr *containerd.Container) uint32 { - var pid uint32 - for _, p := range ctr.Processes { - if p.Pid == InitFriendlyName { - pid = p.SystemPid - } - } - return pid -} - -func convertRlimits(sr []specs.Rlimit) (cr []*containerd.Rlimit) { - for _, r := range sr { - cr = append(cr, &containerd.Rlimit{ - Type: r.Type, - Hard: r.Hard, - Soft: r.Soft, - }) - } - return -} - -// setPDeathSig sets the parent death signal to SIGKILL -func setSysProcAttr(sid bool) *syscall.SysProcAttr { - return &syscall.SysProcAttr{ - Setsid: sid, - Pdeathsig: syscall.SIGKILL, - } -} diff --git a/vendor/github.com/docker/docker/libcontainerd/utils_solaris.go b/vendor/github.com/docker/docker/libcontainerd/utils_solaris.go deleted file mode 100644 index 49632b4..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/utils_solaris.go +++ /dev/null @@ -1,27 +0,0 @@ -package libcontainerd - -import ( - "syscall" - - containerd "github.com/docker/containerd/api/grpc/types" - "github.com/opencontainers/runtime-spec/specs-go" -) - -func getRootIDs(s specs.Spec) (int, int, error) { - return 0, 0, nil -} - -func systemPid(ctr *containerd.Container) uint32 { - var pid uint32 - for _, p := range ctr.Processes { - if p.Pid == InitFriendlyName { - pid = p.SystemPid - } - } - return pid -} - -// setPDeathSig sets the parent death signal to SIGKILL -func setSysProcAttr(sid bool) *syscall.SysProcAttr { - return nil -} diff --git a/vendor/github.com/docker/docker/libcontainerd/utils_windows.go b/vendor/github.com/docker/docker/libcontainerd/utils_windows.go deleted file mode 100644 index 41ac40d..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/utils_windows.go +++ /dev/null @@ -1,46 +0,0 @@ -package libcontainerd - -import "strings" - -// setupEnvironmentVariables converts a string array of environment variables -// into a map as required by the HCS. Source array is in format [v1=k1] [v2=k2] etc. -func setupEnvironmentVariables(a []string) map[string]string { - r := make(map[string]string) - for _, s := range a { - arr := strings.SplitN(s, "=", 2) - if len(arr) == 2 { - r[arr[0]] = arr[1] - } - } - return r -} - -// Apply for a servicing option is a no-op. -func (s *ServicingOption) Apply(interface{}) error { - return nil -} - -// Apply for the flush option is a no-op. -func (f *FlushOption) Apply(interface{}) error { - return nil -} - -// Apply for the hypervisolation option is a no-op. -func (h *HyperVIsolationOption) Apply(interface{}) error { - return nil -} - -// Apply for the layer option is a no-op. -func (h *LayerOption) Apply(interface{}) error { - return nil -} - -// Apply for the network endpoints option is a no-op. -func (s *NetworkEndpointsOption) Apply(interface{}) error { - return nil -} - -// Apply for the credentials option is a no-op. -func (s *CredentialsOption) Apply(interface{}) error { - return nil -} diff --git a/vendor/github.com/docker/docker/libcontainerd/utils_windows_test.go b/vendor/github.com/docker/docker/libcontainerd/utils_windows_test.go deleted file mode 100644 index f3679bf..0000000 --- a/vendor/github.com/docker/docker/libcontainerd/utils_windows_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package libcontainerd - -import ( - "testing" -) - -func TestEnvironmentParsing(t *testing.T) { - env := []string{"foo=bar", "car=hat", "a=b=c"} - result := setupEnvironmentVariables(env) - if len(result) != 3 || result["foo"] != "bar" || result["car"] != "hat" || result["a"] != "b=c" { - t.Fatalf("Expected map[foo:bar car:hat a:b=c], got %v", result) - } -} diff --git a/vendor/github.com/docker/docker/man/Dockerfile b/vendor/github.com/docker/docker/man/Dockerfile deleted file mode 100644 index 80e97ff..0000000 --- a/vendor/github.com/docker/docker/man/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM golang:1.7.5-alpine - -RUN apk add -U git bash curl gcc musl-dev make - -RUN mkdir -p /go/src /go/bin /go/pkg -RUN export GLIDE=v0.11.1; \ - export TARGET=/go/src/github.com/Masterminds; \ - mkdir -p ${TARGET} && \ - git clone https://github.com/Masterminds/glide.git ${TARGET}/glide && \ - cd ${TARGET}/glide && \ - git checkout $GLIDE && \ - make build && \ - cp ./glide /usr/bin/glide && \ - cd / && rm -rf /go/src/* /go/bin/* /go/pkg/* - -COPY glide.yaml /manvendor/ -COPY glide.lock /manvendor/ -WORKDIR /manvendor/ -RUN glide install && mv vendor src -ENV GOPATH=$GOPATH:/manvendor -RUN go build -o /usr/bin/go-md2man github.com/cpuguy83/go-md2man - -WORKDIR /go/src/github.com/docker/docker/ -ENTRYPOINT ["man/generate.sh"] diff --git a/vendor/github.com/docker/docker/man/Dockerfile.5.md b/vendor/github.com/docker/docker/man/Dockerfile.5.md deleted file mode 100644 index 5191b19..0000000 --- a/vendor/github.com/docker/docker/man/Dockerfile.5.md +++ /dev/null @@ -1,474 +0,0 @@ -% DOCKERFILE(5) Docker User Manuals -% Zac Dover -% May 2014 -# NAME - -Dockerfile - automate the steps of creating a Docker image - -# INTRODUCTION - -The **Dockerfile** is a configuration file that automates the steps of creating -a Docker image. It is similar to a Makefile. Docker reads instructions from the -**Dockerfile** to automate the steps otherwise performed manually to create an -image. To build an image, create a file called **Dockerfile**. - -The **Dockerfile** describes the steps taken to assemble the image. When the -**Dockerfile** has been created, call the `docker build` command, using the -path of directory that contains **Dockerfile** as the argument. - -# SYNOPSIS - -INSTRUCTION arguments - -For example: - - FROM image - -# DESCRIPTION - -A Dockerfile is a file that automates the steps of creating a Docker image. -A Dockerfile is similar to a Makefile. - -# USAGE - - docker build . - - -- Runs the steps and commits them, building a final image. - The path to the source repository defines where to find the context of the - build. The build is run by the Docker daemon, not the CLI. The whole - context must be transferred to the daemon. The Docker CLI reports - `"Sending build context to Docker daemon"` when the context is sent to the - daemon. - - ``` - docker build -t repository/tag . - ``` - - -- specifies a repository and tag at which to save the new image if the build - succeeds. The Docker daemon runs the steps one-by-one, committing the result - to a new image if necessary, before finally outputting the ID of the new - image. The Docker daemon automatically cleans up the context it is given. - - Docker re-uses intermediate images whenever possible. This significantly - accelerates the *docker build* process. - -# FORMAT - - `FROM image` - - `FROM image:tag` - - `FROM image@digest` - - -- The **FROM** instruction sets the base image for subsequent instructions. A - valid Dockerfile must have **FROM** as its first instruction. The image can be any - valid image. It is easy to start by pulling an image from the public - repositories. - - -- **FROM** must be the first non-comment instruction in Dockerfile. - - -- **FROM** may appear multiple times within a single Dockerfile in order to create - multiple images. Make a note of the last image ID output by the commit before - each new **FROM** command. - - -- If no tag is given to the **FROM** instruction, Docker applies the - `latest` tag. If the used tag does not exist, an error is returned. - - -- If no digest is given to the **FROM** instruction, Docker applies the - `latest` tag. If the used tag does not exist, an error is returned. - -**MAINTAINER** - -- **MAINTAINER** sets the Author field for the generated images. - Useful for providing users with an email or url for support. - -**RUN** - -- **RUN** has two forms: - - ``` - # the command is run in a shell - /bin/sh -c - RUN - - # Executable form - RUN ["executable", "param1", "param2"] - ``` - - - -- The **RUN** instruction executes any commands in a new layer on top of the current - image and commits the results. The committed image is used for the next step in - Dockerfile. - - -- Layering **RUN** instructions and generating commits conforms to the core - concepts of Docker where commits are cheap and containers can be created from - any point in the history of an image. This is similar to source control. The - exec form makes it possible to avoid shell string munging. The exec form makes - it possible to **RUN** commands using a base image that does not contain `/bin/sh`. - - Note that the exec form is parsed as a JSON array, which means that you must - use double-quotes (") around words not single-quotes ('). - -**CMD** - -- **CMD** has three forms: - - ``` - # Executable form - CMD ["executable", "param1", "param2"]` - - # Provide default arguments to ENTRYPOINT - CMD ["param1", "param2"]` - - # the command is run in a shell - /bin/sh -c - CMD command param1 param2 - ``` - - -- There should be only one **CMD** in a Dockerfile. If more than one **CMD** is listed, only - the last **CMD** takes effect. - The main purpose of a **CMD** is to provide defaults for an executing container. - These defaults may include an executable, or they can omit the executable. If - they omit the executable, an **ENTRYPOINT** must be specified. - When used in the shell or exec formats, the **CMD** instruction sets the command to - be executed when running the image. - If you use the shell form of the **CMD**, the `` executes in `/bin/sh -c`: - - Note that the exec form is parsed as a JSON array, which means that you must - use double-quotes (") around words not single-quotes ('). - - ``` - FROM ubuntu - CMD echo "This is a test." | wc - - ``` - - -- If you run **command** without a shell, then you must express the command as a - JSON array and give the full path to the executable. This array form is the - preferred form of **CMD**. All additional parameters must be individually expressed - as strings in the array: - - ``` - FROM ubuntu - CMD ["/usr/bin/wc","--help"] - ``` - - -- To make the container run the same executable every time, use **ENTRYPOINT** in - combination with **CMD**. - If the user specifies arguments to `docker run`, the specified commands - override the default in **CMD**. - Do not confuse **RUN** with **CMD**. **RUN** runs a command and commits the result. - **CMD** executes nothing at build time, but specifies the intended command for - the image. - -**LABEL** - -- `LABEL = [= ...]`or - ``` - LABEL [ ] - LABEL [ ] - ... - ``` - The **LABEL** instruction adds metadata to an image. A **LABEL** is a - key-value pair. To specify a **LABEL** without a value, simply use an empty - string. To include spaces within a **LABEL** value, use quotes and - backslashes as you would in command-line parsing. - - ``` - LABEL com.example.vendor="ACME Incorporated" - LABEL com.example.vendor "ACME Incorporated" - LABEL com.example.vendor.is-beta "" - LABEL com.example.vendor.is-beta= - LABEL com.example.vendor.is-beta="" - ``` - - An image can have more than one label. To specify multiple labels, separate - each key-value pair by a space. - - Labels are additive including `LABEL`s in `FROM` images. As the system - encounters and then applies a new label, new `key`s override any previous - labels with identical keys. - - To display an image's labels, use the `docker inspect` command. - -**EXPOSE** - -- `EXPOSE [...]` - The **EXPOSE** instruction informs Docker that the container listens on the - specified network ports at runtime. Docker uses this information to - interconnect containers using links and to set up port redirection on the host - system. - -**ENV** - -- `ENV ` - The **ENV** instruction sets the environment variable to - the value ``. This value is passed to all future - **RUN**, **ENTRYPOINT**, and **CMD** instructions. This is - functionally equivalent to prefixing the command with `=`. The - environment variables that are set with **ENV** persist when a container is run - from the resulting image. Use `docker inspect` to inspect these values, and - change them using `docker run --env =`. - - Note that setting "`ENV DEBIAN_FRONTEND noninteractive`" may cause - unintended consequences, because it will persist when the container is run - interactively, as with the following command: `docker run -t -i image bash` - -**ADD** - -- **ADD** has two forms: - - ``` - ADD - - # Required for paths with whitespace - ADD ["",... ""] - ``` - - The **ADD** instruction copies new files, directories - or remote file URLs to the filesystem of the container at path ``. - Multiple `` resources may be specified but if they are files or directories - then they must be relative to the source directory that is being built - (the context of the build). The `` is the absolute path, or path relative - to **WORKDIR**, into which the source is copied inside the target container. - If the `` argument is a local file in a recognized compression format - (tar, gzip, bzip2, etc) then it is unpacked at the specified `` in the - container's filesystem. Note that only local compressed files will be unpacked, - i.e., the URL download and archive unpacking features cannot be used together. - All new directories are created with mode 0755 and with the uid and gid of **0**. - -**COPY** - -- **COPY** has two forms: - - ``` - COPY - - # Required for paths with whitespace - COPY ["",... ""] - ``` - - The **COPY** instruction copies new files from `` and - adds them to the filesystem of the container at path . The `` must be - the path to a file or directory relative to the source directory that is - being built (the context of the build) or a remote file URL. The `` is an - absolute path, or a path relative to **WORKDIR**, into which the source will - be copied inside the target container. If you **COPY** an archive file it will - land in the container exactly as it appears in the build context without any - attempt to unpack it. All new files and directories are created with mode **0755** - and with the uid and gid of **0**. - -**ENTRYPOINT** - -- **ENTRYPOINT** has two forms: - - ``` - # executable form - ENTRYPOINT ["executable", "param1", "param2"]` - - # run command in a shell - /bin/sh -c - ENTRYPOINT command param1 param2 - ``` - - -- An **ENTRYPOINT** helps you configure a - container that can be run as an executable. When you specify an **ENTRYPOINT**, - the whole container runs as if it was only that executable. The **ENTRYPOINT** - instruction adds an entry command that is not overwritten when arguments are - passed to docker run. This is different from the behavior of **CMD**. This allows - arguments to be passed to the entrypoint, for instance `docker run -d` - passes the -d argument to the **ENTRYPOINT**. Specify parameters either in the - **ENTRYPOINT** JSON array (as in the preferred exec form above), or by using a **CMD** - statement. Parameters in the **ENTRYPOINT** are not overwritten by the docker run - arguments. Parameters specified via **CMD** are overwritten by docker run - arguments. Specify a plain string for the **ENTRYPOINT**, and it will execute in - `/bin/sh -c`, like a **CMD** instruction: - - ``` - FROM ubuntu - ENTRYPOINT wc -l - - ``` - - This means that the Dockerfile's image always takes stdin as input (that's - what "-" means), and prints the number of lines (that's what "-l" means). To - make this optional but default, use a **CMD**: - - ``` - FROM ubuntu - CMD ["-l", "-"] - ENTRYPOINT ["/usr/bin/wc"] - ``` - -**VOLUME** - -- `VOLUME ["/data"]` - The **VOLUME** instruction creates a mount point with the specified name and marks - it as holding externally-mounted volumes from the native host or from other - containers. - -**USER** - -- `USER daemon` - Sets the username or UID used for running subsequent commands. - - The **USER** instruction can optionally be used to set the group or GID. The - followings examples are all valid: - USER [user | user:group | uid | uid:gid | user:gid | uid:group ] - - Until the **USER** instruction is set, instructions will be run as root. The USER - instruction can be used any number of times in a Dockerfile, and will only affect - subsequent commands. - -**WORKDIR** - -- `WORKDIR /path/to/workdir` - The **WORKDIR** instruction sets the working directory for the **RUN**, **CMD**, - **ENTRYPOINT**, **COPY** and **ADD** Dockerfile commands that follow it. It can - be used multiple times in a single Dockerfile. Relative paths are defined - relative to the path of the previous **WORKDIR** instruction. For example: - - ``` - WORKDIR /a - WORKDIR b - WORKDIR c - RUN pwd - ``` - - In the above example, the output of the **pwd** command is **a/b/c**. - -**ARG** - -- ARG [=] - - The `ARG` instruction defines a variable that users can pass at build-time to - the builder with the `docker build` command using the `--build-arg - =` flag. If a user specifies a build argument that was not - defined in the Dockerfile, the build outputs a warning. - - ``` - [Warning] One or more build-args [foo] were not consumed - ``` - - The Dockerfile author can define a single variable by specifying `ARG` once or many - variables by specifying `ARG` more than once. For example, a valid Dockerfile: - - ``` - FROM busybox - ARG user1 - ARG buildno - ... - ``` - - A Dockerfile author may optionally specify a default value for an `ARG` instruction: - - ``` - FROM busybox - ARG user1=someuser - ARG buildno=1 - ... - ``` - - If an `ARG` value has a default and if there is no value passed at build-time, the - builder uses the default. - - An `ARG` variable definition comes into effect from the line on which it is - defined in the `Dockerfile` not from the argument's use on the command-line or - elsewhere. For example, consider this Dockerfile: - - ``` - 1 FROM busybox - 2 USER ${user:-some_user} - 3 ARG user - 4 USER $user - ... - ``` - A user builds this file by calling: - - ``` - $ docker build --build-arg user=what_user Dockerfile - ``` - - The `USER` at line 2 evaluates to `some_user` as the `user` variable is defined on the - subsequent line 3. The `USER` at line 4 evaluates to `what_user` as `user` is - defined and the `what_user` value was passed on the command line. Prior to its definition by an - `ARG` instruction, any use of a variable results in an empty string. - - > **Warning:** It is not recommended to use build-time variables for - > passing secrets like github keys, user credentials etc. Build-time variable - > values are visible to any user of the image with the `docker history` command. - - You can use an `ARG` or an `ENV` instruction to specify variables that are - available to the `RUN` instruction. Environment variables defined using the - `ENV` instruction always override an `ARG` instruction of the same name. Consider - this Dockerfile with an `ENV` and `ARG` instruction. - - ``` - 1 FROM ubuntu - 2 ARG CONT_IMG_VER - 3 ENV CONT_IMG_VER v1.0.0 - 4 RUN echo $CONT_IMG_VER - ``` - Then, assume this image is built with this command: - - ``` - $ docker build --build-arg CONT_IMG_VER=v2.0.1 Dockerfile - ``` - - In this case, the `RUN` instruction uses `v1.0.0` instead of the `ARG` setting - passed by the user:`v2.0.1` This behavior is similar to a shell - script where a locally scoped variable overrides the variables passed as - arguments or inherited from environment, from its point of definition. - - Using the example above but a different `ENV` specification you can create more - useful interactions between `ARG` and `ENV` instructions: - - ``` - 1 FROM ubuntu - 2 ARG CONT_IMG_VER - 3 ENV CONT_IMG_VER ${CONT_IMG_VER:-v1.0.0} - 4 RUN echo $CONT_IMG_VER - ``` - - Unlike an `ARG` instruction, `ENV` values are always persisted in the built - image. Consider a docker build without the --build-arg flag: - - ``` - $ docker build Dockerfile - ``` - - Using this Dockerfile example, `CONT_IMG_VER` is still persisted in the image but - its value would be `v1.0.0` as it is the default set in line 3 by the `ENV` instruction. - - The variable expansion technique in this example allows you to pass arguments - from the command line and persist them in the final image by leveraging the - `ENV` instruction. Variable expansion is only supported for [a limited set of - Dockerfile instructions.](#environment-replacement) - - Docker has a set of predefined `ARG` variables that you can use without a - corresponding `ARG` instruction in the Dockerfile. - - * `HTTP_PROXY` - * `http_proxy` - * `HTTPS_PROXY` - * `https_proxy` - * `FTP_PROXY` - * `ftp_proxy` - * `NO_PROXY` - * `no_proxy` - - To use these, simply pass them on the command line using the `--build-arg - =` flag. - -**ONBUILD** - -- `ONBUILD [INSTRUCTION]` - The **ONBUILD** instruction adds a trigger instruction to an image. The - trigger is executed at a later time, when the image is used as the base for - another build. Docker executes the trigger in the context of the downstream - build, as if the trigger existed immediately after the **FROM** instruction in - the downstream Dockerfile. - - You can register any build instruction as a trigger. A trigger is useful if - you are defining an image to use as a base for building other images. For - example, if you are defining an application build environment or a daemon that - is customized with a user-specific configuration. - - Consider an image intended as a reusable python application builder. It must - add application source code to a particular directory, and might need a build - script called after that. You can't just call **ADD** and **RUN** now, because - you don't yet have access to the application source code, and it is different - for each application build. - - -- Providing application developers with a boilerplate Dockerfile to copy-paste - into their application is inefficient, error-prone, and - difficult to update because it mixes with application-specific code. - The solution is to use **ONBUILD** to register instructions in advance, to - run later, during the next build stage. - -# HISTORY -*May 2014, Compiled by Zac Dover (zdover at redhat dot com) based on docker.com Dockerfile documentation. -*Feb 2015, updated by Brian Goff (cpuguy83@gmail.com) for readability -*Sept 2015, updated by Sally O'Malley (somalley@redhat.com) -*Oct 2016, updated by Addam Hardy (addam.hardy@gmail.com) diff --git a/vendor/github.com/docker/docker/man/Dockerfile.aarch64 b/vendor/github.com/docker/docker/man/Dockerfile.aarch64 deleted file mode 100644 index e788eb1..0000000 --- a/vendor/github.com/docker/docker/man/Dockerfile.aarch64 +++ /dev/null @@ -1,25 +0,0 @@ -FROM aarch64/ubuntu:xenial - -RUN apt-get update && apt-get install -y git golang-go - -RUN mkdir -p /go/src /go/bin /go/pkg -ENV GOPATH=/go -RUN export GLIDE=v0.11.1; \ - export TARGET=/go/src/github.com/Masterminds; \ - mkdir -p ${TARGET} && \ - git clone https://github.com/Masterminds/glide.git ${TARGET}/glide && \ - cd ${TARGET}/glide && \ - git checkout $GLIDE && \ - make build && \ - cp ./glide /usr/bin/glide && \ - cd / && rm -rf /go/src/* /go/bin/* /go/pkg/* - -COPY glide.yaml /manvendor/ -COPY glide.lock /manvendor/ -WORKDIR /manvendor/ -RUN glide install && mv vendor src -ENV GOPATH=$GOPATH:/manvendor -RUN go build -o /usr/bin/go-md2man github.com/cpuguy83/go-md2man - -WORKDIR /go/src/github.com/docker/docker/ -ENTRYPOINT ["man/generate.sh"] diff --git a/vendor/github.com/docker/docker/man/Dockerfile.armhf b/vendor/github.com/docker/docker/man/Dockerfile.armhf deleted file mode 100644 index e7ea495..0000000 --- a/vendor/github.com/docker/docker/man/Dockerfile.armhf +++ /dev/null @@ -1,43 +0,0 @@ -FROM armhf/debian:jessie - -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list - -RUN apt-get update && apt-get install -y \ - git \ - bash \ - curl \ - gcc \ - make - -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-armv6l.tar.gz" \ - | tar -xzC /usr/local -ENV PATH /go/bin:/usr/local/go/bin:$PATH -ENV GOPATH /go - -# We're building for armhf, which is ARMv7, so let's be explicit about that -ENV GOARCH arm -ENV GOARM 7 - -RUN mkdir -p /go/src /go/bin /go/pkg -RUN export GLIDE=v0.11.1; \ - export TARGET=/go/src/github.com/Masterminds; \ - mkdir -p ${TARGET} && \ - git clone https://github.com/Masterminds/glide.git ${TARGET}/glide && \ - cd ${TARGET}/glide && \ - git checkout $GLIDE && \ - make build && \ - cp ./glide /usr/bin/glide && \ - cd / && rm -rf /go/src/* /go/bin/* /go/pkg/* - -COPY glide.yaml /manvendor/ -COPY glide.lock /manvendor/ -WORKDIR /manvendor/ -RUN glide install && mv vendor src -ENV GOPATH=$GOPATH:/manvendor -RUN go build -o /usr/bin/go-md2man github.com/cpuguy83/go-md2man - -WORKDIR /go/src/github.com/docker/docker/ -ENTRYPOINT ["man/generate.sh"] diff --git a/vendor/github.com/docker/docker/man/Dockerfile.ppc64le b/vendor/github.com/docker/docker/man/Dockerfile.ppc64le deleted file mode 100644 index fc96ca7..0000000 --- a/vendor/github.com/docker/docker/man/Dockerfile.ppc64le +++ /dev/null @@ -1,35 +0,0 @@ -FROM ppc64le/ubuntu:xenial - -RUN apt-get update && apt-get install -y \ - curl \ - gcc \ - git \ - make \ - tar - -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" \ - | tar -xzC /usr/local -ENV PATH /usr/local/go/bin:$PATH -ENV GOPATH=/go - -RUN mkdir -p /go/src /go/bin /go/pkg -RUN export GLIDE=v0.11.1; \ - export TARGET=/go/src/github.com/Masterminds; \ - mkdir -p ${TARGET} && \ - git clone https://github.com/Masterminds/glide.git ${TARGET}/glide && \ - cd ${TARGET}/glide && \ - git checkout $GLIDE && \ - make build && \ - cp ./glide /usr/bin/glide && \ - cd / && rm -rf /go/src/* /go/bin/* /go/pkg/* - -COPY glide.yaml /manvendor/ -COPY glide.lock /manvendor/ -WORKDIR /manvendor/ -RUN glide install && mv vendor src -ENV GOPATH=$GOPATH:/manvendor -RUN go build -o /usr/bin/go-md2man github.com/cpuguy83/go-md2man - -WORKDIR /go/src/github.com/docker/docker/ -ENTRYPOINT ["man/generate.sh"] diff --git a/vendor/github.com/docker/docker/man/Dockerfile.s390x b/vendor/github.com/docker/docker/man/Dockerfile.s390x deleted file mode 100644 index d4bcf1d..0000000 --- a/vendor/github.com/docker/docker/man/Dockerfile.s390x +++ /dev/null @@ -1,35 +0,0 @@ -FROM s390x/ubuntu:xenial - -RUN apt-get update && apt-get install -y \ - curl \ - gcc \ - git \ - make \ - tar - -ENV GO_VERSION 1.7.5 -RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" \ - | tar -xzC /usr/local -ENV PATH /usr/local/go/bin:$PATH -ENV GOPATH=/go - -RUN mkdir -p /go/src /go/bin /go/pkg -RUN export GLIDE=v0.11.1; \ - export TARGET=/go/src/github.com/Masterminds; \ - mkdir -p ${TARGET} && \ - git clone https://github.com/Masterminds/glide.git ${TARGET}/glide && \ - cd ${TARGET}/glide && \ - git checkout $GLIDE && \ - make build && \ - cp ./glide /usr/bin/glide && \ - cd / && rm -rf /go/src/* /go/bin/* /go/pkg/* - -COPY glide.yaml /manvendor/ -COPY glide.lock /manvendor/ -WORKDIR /manvendor/ -RUN glide install && mv vendor src -ENV GOPATH=$GOPATH:/manvendor -RUN go build -o /usr/bin/go-md2man github.com/cpuguy83/go-md2man - -WORKDIR /go/src/github.com/docker/docker/ -ENTRYPOINT ["man/generate.sh"] diff --git a/vendor/github.com/docker/docker/man/README.md b/vendor/github.com/docker/docker/man/README.md deleted file mode 100644 index 82dac65..0000000 --- a/vendor/github.com/docker/docker/man/README.md +++ /dev/null @@ -1,15 +0,0 @@ -Docker Documentation -==================== - -This directory contains scripts for generating the man pages. Many of the man -pages are generated directly from the `spf13/cobra` `Command` definition. Some -legacy pages are still generated from the markdown files in this directory. -Do *not* edit the man pages in the man1 directory. Instead, update the -Cobra command or amend the Markdown files for legacy pages. - - -## Generate the man pages - -From within the project root directory run: - - make manpages diff --git a/vendor/github.com/docker/docker/man/docker-attach.1.md b/vendor/github.com/docker/docker/man/docker-attach.1.md deleted file mode 100644 index c39d1c9..0000000 --- a/vendor/github.com/docker/docker/man/docker-attach.1.md +++ /dev/null @@ -1,99 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-attach - Attach to a running container - -# SYNOPSIS -**docker attach** -[**--detach-keys**[=*[]*]] -[**--help**] -[**--no-stdin**] -[**--sig-proxy**[=*true*]] -CONTAINER - -# DESCRIPTION -The **docker attach** command allows you to attach to a running container using -the container's ID or name, either to view its ongoing output or to control it -interactively. You can attach to the same contained process multiple times -simultaneously, screen sharing style, or quickly view the progress of your -detached process. - -To stop a container, use `CTRL-c`. This key sequence sends `SIGKILL` to the -container. You can detach from the container (and leave it running) using a -configurable key sequence. The default sequence is `CTRL-p CTRL-q`. You -configure the key sequence using the **--detach-keys** option or a configuration -file. See **config-json(5)** for documentation on using a configuration file. - -It is forbidden to redirect the standard input of a `docker attach` command while -attaching to a tty-enabled container (i.e.: launched with `-t`). - -# OPTIONS -**--detach-keys**="" - Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-` where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. - -**--help** - Print usage statement - -**--no-stdin**=*true*|*false* - Do not attach STDIN. The default is *false*. - -**--sig-proxy**=*true*|*false* - Proxy all received signals to the process (non-TTY mode only). SIGCHLD, SIGKILL, and SIGSTOP are not proxied. The default is *true*. - -# Override the detach sequence - -If you want, you can configure an override the Docker key sequence for detach. -This is useful if the Docker default sequence conflicts with key sequence you -use for other applications. There are two ways to define your own detach key -sequence, as a per-container override or as a configuration property on your -entire configuration. - -To override the sequence for an individual container, use the -`--detach-keys=""` flag with the `docker attach` command. The format of -the `` is either a letter [a-Z], or the `ctrl-` combined with any of -the following: - -* `a-z` (a single lowercase alpha character ) -* `@` (at sign) -* `[` (left bracket) -* `\\` (two backward slashes) -* `_` (underscore) -* `^` (caret) - -These `a`, `ctrl-a`, `X`, or `ctrl-\\` values are all examples of valid key -sequences. To configure a different configuration default key sequence for all -containers, see **docker(1)**. - -# EXAMPLES - -## Attaching to a container - -In this example the top command is run inside a container, from an image called -fedora, in detached mode. The ID from the container is passed into the **docker -attach** command: - - # ID=$(sudo docker run -d fedora /usr/bin/top -b) - # sudo docker attach $ID - top - 02:05:52 up 3:05, 0 users, load average: 0.01, 0.02, 0.05 - Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie - Cpu(s): 0.1%us, 0.2%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st - Mem: 373572k total, 355560k used, 18012k free, 27872k buffers - Swap: 786428k total, 0k used, 786428k free, 221740k cached - - PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND - 1 root 20 0 17200 1116 912 R 0 0.3 0:00.03 top - - top - 02:05:55 up 3:05, 0 users, load average: 0.01, 0.02, 0.05 - Tasks: 1 total, 1 running, 0 sleeping, 0 stopped, 0 zombie - Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st - Mem: 373572k total, 355244k used, 18328k free, 27872k buffers - Swap: 786428k total, 0k used, 786428k free, 221776k cached - - PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND - 1 root 20 0 17208 1144 932 R 0 0.3 0:00.03 top - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-build.1.md b/vendor/github.com/docker/docker/man/docker-build.1.md deleted file mode 100644 index 4beee88..0000000 --- a/vendor/github.com/docker/docker/man/docker-build.1.md +++ /dev/null @@ -1,340 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-build - Build an image from a Dockerfile - -# SYNOPSIS -**docker build** -[**--build-arg**[=*[]*]] -[**--cpu-shares**[=*0*]] -[**--cgroup-parent**[=*CGROUP-PARENT*]] -[**--help**] -[**-f**|**--file**[=*PATH/Dockerfile*]] -[**-squash**] *Experimental* -[**--force-rm**] -[**--isolation**[=*default*]] -[**--label**[=*[]*]] -[**--no-cache**] -[**--pull**] -[**--compress**] -[**-q**|**--quiet**] -[**--rm**[=*true*]] -[**-t**|**--tag**[=*[]*]] -[**-m**|**--memory**[=*MEMORY*]] -[**--memory-swap**[=*LIMIT*]] -[**--network**[=*"default"*]] -[**--shm-size**[=*SHM-SIZE*]] -[**--cpu-period**[=*0*]] -[**--cpu-quota**[=*0*]] -[**--cpuset-cpus**[=*CPUSET-CPUS*]] -[**--cpuset-mems**[=*CPUSET-MEMS*]] -[**--ulimit**[=*[]*]] -PATH | URL | - - -# DESCRIPTION -This will read the Dockerfile from the directory specified in **PATH**. -It also sends any other files and directories found in the current -directory to the Docker daemon. The contents of this directory would -be used by **ADD** commands found within the Dockerfile. - -Warning, this will send a lot of data to the Docker daemon depending -on the contents of the current directory. The build is run by the Docker -daemon, not by the CLI, so the whole context must be transferred to the daemon. -The Docker CLI reports "Sending build context to Docker daemon" when the context is sent to -the daemon. - -When the URL to a tarball archive or to a single Dockerfile is given, no context is sent from -the client to the Docker daemon. In this case, the Dockerfile at the root of the archive and -the rest of the archive will get used as the context of the build. When a Git repository is -set as the **URL**, the repository is cloned locally and then sent as the context. - -# OPTIONS -**-f**, **--file**=*PATH/Dockerfile* - Path to the Dockerfile to use. If the path is a relative path and you are - building from a local directory, then the path must be relative to that - directory. If you are building from a remote URL pointing to either a - tarball or a Git repository, then the path must be relative to the root of - the remote context. In all cases, the file must be within the build context. - The default is *Dockerfile*. - -**--squash**=*true*|*false* - **Experimental Only** - Once the image is built, squash the new layers into a new image with a single - new layer. Squashing does not destroy any existing image, rather it creates a new - image with the content of the squshed layers. This effectively makes it look - like all `Dockerfile` commands were created with a single layer. The build - cache is preserved with this method. - - **Note**: using this option means the new image will not be able to take - advantage of layer sharing with other images and may use significantly more - space. - - **Note**: using this option you may see significantly more space used due to - storing two copies of the image, one for the build cache with all the cache - layers in tact, and one for the squashed version. - -**--build-arg**=*variable* - name and value of a **buildarg**. - - For example, if you want to pass a value for `http_proxy`, use - `--build-arg=http_proxy="http://some.proxy.url"` - - Users pass these values at build-time. Docker uses the `buildargs` as the - environment context for command(s) run via the Dockerfile's `RUN` instruction - or for variable expansion in other Dockerfile instructions. This is not meant - for passing secret values. [Read more about the buildargs instruction](https://docs.docker.com/engine/reference/builder/#arg) - -**--force-rm**=*true*|*false* - Always remove intermediate containers, even after unsuccessful builds. The default is *false*. - -**--isolation**="*default*" - Isolation specifies the type of isolation technology used by containers. - -**--label**=*label* - Set metadata for an image - -**--no-cache**=*true*|*false* - Do not use cache when building the image. The default is *false*. - -**--help** - Print usage statement - -**--pull**=*true*|*false* - Always attempt to pull a newer version of the image. The default is *false*. - -**--compress**=*true*|*false* - Compress the build context using gzip. The default is *false*. - -**-q**, **--quiet**=*true*|*false* - Suppress the build output and print image ID on success. The default is *false*. - -**--rm**=*true*|*false* - Remove intermediate containers after a successful build. The default is *true*. - -**-t**, **--tag**="" - Repository names (and optionally with tags) to be applied to the resulting - image in case of success. Refer to **docker-tag(1)** for more information - about valid tag names. - -**-m**, **--memory**=*MEMORY* - Memory limit - -**--memory-swap**=*LIMIT* - A limit value equal to memory plus swap. Must be used with the **-m** -(**--memory**) flag. The swap `LIMIT` should always be larger than **-m** -(**--memory**) value. - - The format of `LIMIT` is `[]`. Unit can be `b` (bytes), -`k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you don't specify a -unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap. - -**--network**=*bridge* - Set the networking mode for the RUN instructions during build. Supported standard - values are: `bridge`, `host`, `none` and `container:`. Any other value - is taken as a custom network's name or ID which this container should connect to. - -**--shm-size**=*SHM-SIZE* - Size of `/dev/shm`. The format is ``. `number` must be greater than `0`. - Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you omit the unit, the system uses bytes. - If you omit the size entirely, the system uses `64m`. - -**--cpu-shares**=*0* - CPU shares (relative weight). - - By default, all containers get the same proportion of CPU cycles. - CPU shares is a 'relative weight', relative to the default setting of 1024. - This default value is defined here: - ``` - cat /sys/fs/cgroup/cpu/cpu.shares - 1024 - ``` - You can change this proportion by adjusting the container's CPU share - weighting relative to the weighting of all other running containers. - - To modify the proportion from the default of 1024, use the **--cpu-shares** - flag to set the weighting to 2 or higher. - - Container CPU share Flag - {C0} 60% of CPU --cpu-shares=614 (614 is 60% of 1024) - {C1} 40% of CPU --cpu-shares=410 (410 is 40% of 1024) - - The proportion is only applied when CPU-intensive processes are running. - When tasks in one container are idle, the other containers can use the - left-over CPU time. The actual amount of CPU time used varies depending on - the number of containers running on the system. - - For example, consider three containers, where one has **--cpu-shares=1024** and - two others have **--cpu-shares=512**. When processes in all three - containers attempt to use 100% of CPU, the first container would receive - 50% of the total CPU time. If you add a fourth container with **--cpu-shares=1024**, - the first container only gets 33% of the CPU. The remaining containers - receive 16.5%, 16.5% and 33% of the CPU. - - - Container CPU share Flag CPU time - {C0} 100% --cpu-shares=1024 33% - {C1} 50% --cpu-shares=512 16.5% - {C2} 50% --cpu-shares=512 16.5% - {C4} 100% --cpu-shares=1024 33% - - - On a multi-core system, the shares of CPU time are distributed across the CPU - cores. Even if a container is limited to less than 100% of CPU time, it can - use 100% of each individual CPU core. - - For example, consider a system with more than three cores. If you start one - container **{C0}** with **--cpu-shares=512** running one process, and another container - **{C1}** with **--cpu-shares=1024** running two processes, this can result in the following - division of CPU shares: - - PID container CPU CPU share - 100 {C0} 0 100% of CPU0 - 101 {C1} 1 100% of CPU1 - 102 {C1} 2 100% of CPU2 - -**--cpu-period**=*0* - Limit the CPU CFS (Completely Fair Scheduler) period. - - Limit the container's CPU usage. This flag causes the kernel to restrict the - container's CPU usage to the period you specify. - -**--cpu-quota**=*0* - Limit the CPU CFS (Completely Fair Scheduler) quota. - - By default, containers run with the full CPU resource. This flag causes the -kernel to restrict the container's CPU usage to the quota you specify. - -**--cpuset-cpus**=*CPUSET-CPUS* - CPUs in which to allow execution (0-3, 0,1). - -**--cpuset-mems**=*CPUSET-MEMS* - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on - NUMA systems. - - For example, if you have four memory nodes on your system (0-3), use `--cpuset-mems=0,1` -to ensure the processes in your Docker container only use memory from the first -two memory nodes. - -**--cgroup-parent**=*CGROUP-PARENT* - Path to `cgroups` under which the container's `cgroup` are created. - - If the path is not absolute, the path is considered relative to the `cgroups` path of the init process. -Cgroups are created if they do not already exist. - -**--ulimit**=[] - Ulimit options - - For more information about `ulimit` see [Setting ulimits in a -container](https://docs.docker.com/engine/reference/commandline/run/#set-ulimits-in-container---ulimit) - -# EXAMPLES - -## Building an image using a Dockerfile located inside the current directory - -Docker images can be built using the build command and a Dockerfile: - - docker build . - -During the build process Docker creates intermediate images. In order to -keep them, you must explicitly set `--rm=false`. - - docker build --rm=false . - -A good practice is to make a sub-directory with a related name and create -the Dockerfile in that directory. For example, a directory called mongo may -contain a Dockerfile to create a Docker MongoDB image. Likewise, another -directory called httpd may be used to store Dockerfiles for Apache web -server images. - -It is also a good practice to add the files required for the image to the -sub-directory. These files will then be specified with the `COPY` or `ADD` -instructions in the `Dockerfile`. - -Note: If you include a tar file (a good practice), then Docker will -automatically extract the contents of the tar file specified within the `ADD` -instruction into the specified target. - -## Building an image and naming that image - -A good practice is to give a name to the image you are building. Note that -only a-z0-9-_. should be used for consistency. There are no hard rules here but it is best to give the names consideration. - -The **-t**/**--tag** flag is used to rename an image. Here are some examples: - -Though it is not a good practice, image names can be arbitrary: - - docker build -t myimage . - -A better approach is to provide a fully qualified and meaningful repository, -name, and tag (where the tag in this context means the qualifier after -the ":"). In this example we build a JBoss image for the Fedora repository -and give it the version 1.0: - - docker build -t fedora/jboss:1.0 . - -The next example is for the "whenry" user repository and uses Fedora and -JBoss and gives it the version 2.1 : - - docker build -t whenry/fedora-jboss:v2.1 . - -If you do not provide a version tag then Docker will assign `latest`: - - docker build -t whenry/fedora-jboss . - -When you list the images, the image above will have the tag `latest`. - -You can apply multiple tags to an image. For example, you can apply the `latest` -tag to a newly built image and add another tag that references a specific -version. -For example, to tag an image both as `whenry/fedora-jboss:latest` and -`whenry/fedora-jboss:v2.1`, use the following: - - docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 . - -So renaming an image is arbitrary but consideration should be given to -a useful convention that makes sense for consumers and should also take -into account Docker community conventions. - - -## Building an image using a URL - -This will clone the specified GitHub repository from the URL and use it -as context. The Dockerfile at the root of the repository is used as -Dockerfile. This only works if the GitHub repository is a dedicated -repository. - - docker build github.com/scollier/purpletest - -Note: You can set an arbitrary Git repository via the `git://` scheme. - -## Building an image using a URL to a tarball'ed context - -This will send the URL itself to the Docker daemon. The daemon will fetch the -tarball archive, decompress it and use its contents as the build context. The -Dockerfile at the root of the archive and the rest of the archive will get used -as the context of the build. If you pass an **-f PATH/Dockerfile** option as well, -the system will look for that file inside the contents of the tarball. - - docker build -f dev/Dockerfile https://10.10.10.1/docker/context.tar.gz - -Note: supported compression formats are 'xz', 'bzip2', 'gzip' and 'identity' (no compression). - -## Specify isolation technology for container (--isolation) - -This option is useful in situations where you are running Docker containers on -Windows. The `--isolation=` option sets a container's isolation -technology. On Linux, the only supported is the `default` option which uses -Linux namespaces. On Microsoft Windows, you can specify these values: - -* `default`: Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value. -* `process`: Namespace isolation only. -* `hyperv`: Hyper-V hypervisor partition-based isolation. - -Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`. - -# HISTORY -March 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -June 2015, updated by Sally O'Malley diff --git a/vendor/github.com/docker/docker/man/docker-commit.1.md b/vendor/github.com/docker/docker/man/docker-commit.1.md deleted file mode 100644 index d8a4cf8..0000000 --- a/vendor/github.com/docker/docker/man/docker-commit.1.md +++ /dev/null @@ -1,71 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-commit - Create a new image from a container's changes - -# SYNOPSIS -**docker commit** -[**-a**|**--author**[=*AUTHOR*]] -[**-c**|**--change**[=\[*DOCKERFILE INSTRUCTIONS*\]]] -[**--help**] -[**-m**|**--message**[=*MESSAGE*]] -[**-p**|**--pause**[=*true*]] -CONTAINER [REPOSITORY[:TAG]] - -# DESCRIPTION -Create a new image from an existing container specified by name or -container ID. The new image will contain the contents of the -container filesystem, *excluding* any data volumes. Refer to **docker-tag(1)** -for more information about valid image and tag names. - -While the `docker commit` command is a convenient way of extending an -existing image, you should prefer the use of a Dockerfile and `docker -build` for generating images that you intend to share with other -people. - -# OPTIONS -**-a**, **--author**="" - Author (e.g., "John Hannibal Smith ") - -**-c** , **--change**=[] - Apply specified Dockerfile instructions while committing the image - Supported Dockerfile instructions: `CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`LABEL`|`ONBUILD`|`USER`|`VOLUME`|`WORKDIR` - -**--help** - Print usage statement - -**-m**, **--message**="" - Commit message - -**-p**, **--pause**=*true*|*false* - Pause container during commit. The default is *true*. - -# EXAMPLES - -## Creating a new image from an existing container -An existing Fedora based container has had Apache installed while running -in interactive mode with the bash shell. Apache is also running. To -create a new image run `docker ps` to find the container's ID and then run: - - # docker commit -m="Added Apache to Fedora base image" \ - -a="A D Ministrator" 98bd7fc99854 fedora/fedora_httpd:20 - -Note that only a-z0-9-_. are allowed when naming images from an -existing container. - -## Apply specified Dockerfile instructions while committing the image -If an existing container was created without the DEBUG environment -variable set to "true", you can create a new image based on that -container by first getting the container's ID with `docker ps` and -then running: - - # docker commit -c="ENV DEBUG true" 98bd7fc99854 debug-image - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and in -June 2014, updated by Sven Dowideit -July 2014, updated by Sven Dowideit -Oct 2014, updated by Daniel, Dao Quang Minh -June 2015, updated by Sally O'Malley diff --git a/vendor/github.com/docker/docker/man/docker-config-json.5.md b/vendor/github.com/docker/docker/man/docker-config-json.5.md deleted file mode 100644 index 49987f0..0000000 --- a/vendor/github.com/docker/docker/man/docker-config-json.5.md +++ /dev/null @@ -1,72 +0,0 @@ -% CONFIG.JSON(5) Docker User Manuals -% Docker Community -% JANUARY 2016 -# NAME -HOME/.docker/config.json - Default Docker configuration file - -# INTRODUCTION - -By default, the Docker command line stores its configuration files in a -directory called `.docker` within your `$HOME` directory. Docker manages most of -the files in the configuration directory and you should not modify them. -However, you *can modify* the `config.json` file to control certain aspects of -how the `docker` command behaves. - -Currently, you can modify the `docker` command behavior using environment -variables or command-line options. You can also use options within -`config.json` to modify some of the same behavior. When using these -mechanisms, you must keep in mind the order of precedence among them. Command -line options override environment variables and environment variables override -properties you specify in a `config.json` file. - -The `config.json` file stores a JSON encoding of several properties: - -* The `HttpHeaders` property specifies a set of headers to include in all messages -sent from the Docker client to the daemon. Docker does not try to interpret or -understand these header; it simply puts them into the messages. Docker does not -allow these headers to change any headers it sets for itself. - -* The `psFormat` property specifies the default format for `docker ps` output. -When the `--format` flag is not provided with the `docker ps` command, -Docker's client uses this property. If this property is not set, the client -falls back to the default table format. For a list of supported formatting -directives, see **docker-ps(1)**. - -* The `detachKeys` property specifies the default key sequence which -detaches the container. When the `--detach-keys` flag is not provide -with the `docker attach`, `docker exec`, `docker run` or `docker -start`, Docker's client uses this property. If this property is not -set, the client falls back to the default sequence `ctrl-p,ctrl-q`. - - -* The `imagesFormat` property specifies the default format for `docker images` -output. When the `--format` flag is not provided with the `docker images` -command, Docker's client uses this property. If this property is not set, the -client falls back to the default table format. For a list of supported -formatting directives, see **docker-images(1)**. - -You can specify a different location for the configuration files via the -`DOCKER_CONFIG` environment variable or the `--config` command line option. If -both are specified, then the `--config` option overrides the `DOCKER_CONFIG` -environment variable: - - docker --config ~/testconfigs/ ps - -This command instructs Docker to use the configuration files in the -`~/testconfigs/` directory when running the `ps` command. - -## Examples - -Following is a sample `config.json` file: - - { - "HttpHeaders": { - "MyHeader": "MyValue" - }, - "psFormat": "table {{.ID}}\\t{{.Image}}\\t{{.Command}}\\t{{.Labels}}", - "imagesFormat": "table {{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.CreatedAt}}", - "detachKeys": "ctrl-e,e" - } - -# HISTORY -January 2016, created by Moxiegirl diff --git a/vendor/github.com/docker/docker/man/docker-cp.1.md b/vendor/github.com/docker/docker/man/docker-cp.1.md deleted file mode 100644 index 949d60b..0000000 --- a/vendor/github.com/docker/docker/man/docker-cp.1.md +++ /dev/null @@ -1,175 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-cp - Copy files/folders between a container and the local filesystem. - -# SYNOPSIS -**docker cp** -[**--help**] -CONTAINER:SRC_PATH DEST_PATH|- - -**docker cp** -[**--help**] -SRC_PATH|- CONTAINER:DEST_PATH - -# DESCRIPTION - -The `docker cp` utility copies the contents of `SRC_PATH` to the `DEST_PATH`. -You can copy from the container's file system to the local machine or the -reverse, from the local filesystem to the container. If `-` is specified for -either the `SRC_PATH` or `DEST_PATH`, you can also stream a tar archive from -`STDIN` or to `STDOUT`. The `CONTAINER` can be a running or stopped container. -The `SRC_PATH` or `DEST_PATH` can be a file or directory. - -The `docker cp` command assumes container paths are relative to the container's -`/` (root) directory. This means supplying the initial forward slash is optional; -The command sees `compassionate_darwin:/tmp/foo/myfile.txt` and -`compassionate_darwin:tmp/foo/myfile.txt` as identical. Local machine paths can -be an absolute or relative value. The command interprets a local machine's -relative paths as relative to the current working directory where `docker cp` is -run. - -The `cp` command behaves like the Unix `cp -a` command in that directories are -copied recursively with permissions preserved if possible. Ownership is set to -the user and primary group at the destination. For example, files copied to a -container are created with `UID:GID` of the root user. Files copied to the local -machine are created with the `UID:GID` of the user which invoked the `docker cp` -command. If you specify the `-L` option, `docker cp` follows any symbolic link -in the `SRC_PATH`. `docker cp` does *not* create parent directories for -`DEST_PATH` if they do not exist. - -Assuming a path separator of `/`, a first argument of `SRC_PATH` and second -argument of `DEST_PATH`, the behavior is as follows: - -- `SRC_PATH` specifies a file - - `DEST_PATH` does not exist - - the file is saved to a file created at `DEST_PATH` - - `DEST_PATH` does not exist and ends with `/` - - Error condition: the destination directory must exist. - - `DEST_PATH` exists and is a file - - the destination is overwritten with the source file's contents - - `DEST_PATH` exists and is a directory - - the file is copied into this directory using the basename from - `SRC_PATH` -- `SRC_PATH` specifies a directory - - `DEST_PATH` does not exist - - `DEST_PATH` is created as a directory and the *contents* of the source - directory are copied into this directory - - `DEST_PATH` exists and is a file - - Error condition: cannot copy a directory to a file - - `DEST_PATH` exists and is a directory - - `SRC_PATH` does not end with `/.` - - the source directory is copied into this directory - - `SRC_PATH` does end with `/.` - - the *content* of the source directory is copied into this - directory - -The command requires `SRC_PATH` and `DEST_PATH` to exist according to the above -rules. If `SRC_PATH` is local and is a symbolic link, the symbolic link, not -the target, is copied by default. To copy the link target and not the link, -specify the `-L` option. - -A colon (`:`) is used as a delimiter between `CONTAINER` and its path. You can -also use `:` when specifying paths to a `SRC_PATH` or `DEST_PATH` on a local -machine, for example `file:name.txt`. If you use a `:` in a local machine path, -you must be explicit with a relative or absolute path, for example: - - `/path/to/file:name.txt` or `./file:name.txt` - -It is not possible to copy certain system files such as resources under -`/proc`, `/sys`, `/dev`, tmpfs, and mounts created by the user in the container. -However, you can still copy such files by manually running `tar` in `docker exec`. -For example (consider `SRC_PATH` and `DEST_PATH` are directories): - - $ docker exec foo tar Ccf $(dirname SRC_PATH) - $(basename SRC_PATH) | tar Cxf DEST_PATH - - -or - - $ tar Ccf $(dirname SRC_PATH) - $(basename SRC_PATH) | docker exec -i foo tar Cxf DEST_PATH - - - -Using `-` as the `SRC_PATH` streams the contents of `STDIN` as a tar archive. -The command extracts the content of the tar to the `DEST_PATH` in container's -filesystem. In this case, `DEST_PATH` must specify a directory. Using `-` as -the `DEST_PATH` streams the contents of the resource as a tar archive to `STDOUT`. - -# OPTIONS -**-L**, **--follow-link**=*true*|*false* - Follow symbol link in SRC_PATH - -**--help** - Print usage statement - -# EXAMPLES - -Suppose a container has finished producing some output as a file it saves -to somewhere in its filesystem. This could be the output of a build job or -some other computation. You can copy these outputs from the container to a -location on your local host. - -If you want to copy the `/tmp/foo` directory from a container to the -existing `/tmp` directory on your host. If you run `docker cp` in your `~` -(home) directory on the local host: - - $ docker cp compassionate_darwin:tmp/foo /tmp - -Docker creates a `/tmp/foo` directory on your host. Alternatively, you can omit -the leading slash in the command. If you execute this command from your home -directory: - - $ docker cp compassionate_darwin:tmp/foo tmp - -If `~/tmp` does not exist, Docker will create it and copy the contents of -`/tmp/foo` from the container into this new directory. If `~/tmp` already -exists as a directory, then Docker will copy the contents of `/tmp/foo` from -the container into a directory at `~/tmp/foo`. - -When copying a single file to an existing `LOCALPATH`, the `docker cp` command -will either overwrite the contents of `LOCALPATH` if it is a file or place it -into `LOCALPATH` if it is a directory, overwriting an existing file of the same -name if one exists. For example, this command: - - $ docker cp sharp_ptolemy:/tmp/foo/myfile.txt /test - -If `/test` does not exist on the local machine, it will be created as a file -with the contents of `/tmp/foo/myfile.txt` from the container. If `/test` -exists as a file, it will be overwritten. Lastly, if `/test` exists as a -directory, the file will be copied to `/test/myfile.txt`. - -Next, suppose you want to copy a file or folder into a container. For example, -this could be a configuration file or some other input to a long running -computation that you would like to place into a created container before it -starts. This is useful because it does not require the configuration file or -other input to exist in the container image. - -If you have a file, `config.yml`, in the current directory on your local host -and wish to copy it to an existing directory at `/etc/my-app.d` in a container, -this command can be used: - - $ docker cp config.yml myappcontainer:/etc/my-app.d - -If you have several files in a local directory `/config` which you need to copy -to a directory `/etc/my-app.d` in a container: - - $ docker cp /config/. myappcontainer:/etc/my-app.d - -The above command will copy the contents of the local `/config` directory into -the directory `/etc/my-app.d` in the container. - -Finally, if you want to copy a symbolic link into a container, you typically -want to copy the linked target and not the link itself. To copy the target, use -the `-L` option, for example: - - $ ln -s /tmp/somefile /tmp/somefile.ln - $ docker cp -L /tmp/somefile.ln myappcontainer:/tmp/ - -This command copies content of the local `/tmp/somefile` into the file -`/tmp/somefile.ln` in the container. Without `-L` option, the `/tmp/somefile.ln` -preserves its symbolic link but not its content. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -May 2015, updated by Josh Hawn diff --git a/vendor/github.com/docker/docker/man/docker-create.1.md b/vendor/github.com/docker/docker/man/docker-create.1.md deleted file mode 100644 index 3f8a076..0000000 --- a/vendor/github.com/docker/docker/man/docker-create.1.md +++ /dev/null @@ -1,553 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-create - Create a new container - -# SYNOPSIS -**docker create** -[**-a**|**--attach**[=*[]*]] -[**--add-host**[=*[]*]] -[**--blkio-weight**[=*[BLKIO-WEIGHT]*]] -[**--blkio-weight-device**[=*[]*]] -[**--cpu-shares**[=*0*]] -[**--cap-add**[=*[]*]] -[**--cap-drop**[=*[]*]] -[**--cgroup-parent**[=*CGROUP-PATH*]] -[**--cidfile**[=*CIDFILE*]] -[**--cpu-count**[=*0*]] -[**--cpu-percent**[=*0*]] -[**--cpu-period**[=*0*]] -[**--cpu-quota**[=*0*]] -[**--cpu-rt-period**[=*0*]] -[**--cpu-rt-runtime**[=*0*]] -[**--cpus**[=*0.0*]] -[**--cpuset-cpus**[=*CPUSET-CPUS*]] -[**--cpuset-mems**[=*CPUSET-MEMS*]] -[**--device**[=*[]*]] -[**--device-read-bps**[=*[]*]] -[**--device-read-iops**[=*[]*]] -[**--device-write-bps**[=*[]*]] -[**--device-write-iops**[=*[]*]] -[**--dns**[=*[]*]] -[**--dns-search**[=*[]*]] -[**--dns-option**[=*[]*]] -[**-e**|**--env**[=*[]*]] -[**--entrypoint**[=*ENTRYPOINT*]] -[**--env-file**[=*[]*]] -[**--expose**[=*[]*]] -[**--group-add**[=*[]*]] -[**-h**|**--hostname**[=*HOSTNAME*]] -[**--help**] -[**-i**|**--interactive**] -[**--ip**[=*IPv4-ADDRESS*]] -[**--ip6**[=*IPv6-ADDRESS*]] -[**--ipc**[=*IPC*]] -[**--isolation**[=*default*]] -[**--kernel-memory**[=*KERNEL-MEMORY*]] -[**-l**|**--label**[=*[]*]] -[**--label-file**[=*[]*]] -[**--link**[=*[]*]] -[**--link-local-ip**[=*[]*]] -[**--log-driver**[=*[]*]] -[**--log-opt**[=*[]*]] -[**-m**|**--memory**[=*MEMORY*]] -[**--mac-address**[=*MAC-ADDRESS*]] -[**--memory-reservation**[=*MEMORY-RESERVATION*]] -[**--memory-swap**[=*LIMIT*]] -[**--memory-swappiness**[=*MEMORY-SWAPPINESS*]] -[**--name**[=*NAME*]] -[**--network-alias**[=*[]*]] -[**--network**[=*"bridge"*]] -[**--oom-kill-disable**] -[**--oom-score-adj**[=*0*]] -[**-P**|**--publish-all**] -[**-p**|**--publish**[=*[]*]] -[**--pid**[=*[PID]*]] -[**--userns**[=*[]*]] -[**--pids-limit**[=*PIDS_LIMIT*]] -[**--privileged**] -[**--read-only**] -[**--restart**[=*RESTART*]] -[**--rm**] -[**--security-opt**[=*[]*]] -[**--storage-opt**[=*[]*]] -[**--stop-signal**[=*SIGNAL*]] -[**--stop-timeout**[=*TIMEOUT*]] -[**--shm-size**[=*[]*]] -[**--sysctl**[=*[]*]] -[**-t**|**--tty**] -[**--tmpfs**[=*[CONTAINER-DIR[:]*]] -[**-u**|**--user**[=*USER*]] -[**--ulimit**[=*[]*]] -[**--uts**[=*[]*]] -[**-v**|**--volume**[=*[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]*]] -[**--volume-driver**[=*DRIVER*]] -[**--volumes-from**[=*[]*]] -[**-w**|**--workdir**[=*WORKDIR*]] -IMAGE [COMMAND] [ARG...] - -# DESCRIPTION - -Creates a writeable container layer over the specified image and prepares it for -running the specified command. The container ID is then printed to STDOUT. This -is similar to **docker run -d** except the container is never started. You can -then use the **docker start ** command to start the container at -any point. - -The initial status of the container created with **docker create** is 'created'. - -# OPTIONS -**-a**, **--attach**=[] - Attach to STDIN, STDOUT or STDERR. - -**--add-host**=[] - Add a custom host-to-IP mapping (host:ip) - -**--blkio-weight**=*0* - Block IO weight (relative weight) accepts a weight value between 10 and 1000. - -**--blkio-weight-device**=[] - Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`). - -**--cpu-shares**=*0* - CPU shares (relative weight) - -**--cap-add**=[] - Add Linux capabilities - -**--cap-drop**=[] - Drop Linux capabilities - -**--cgroup-parent**="" - Path to cgroups under which the cgroup for the container will be created. If the path is not absolute, the path is considered to be relative to the cgroups path of the init process. Cgroups will be created if they do not already exist. - -**--cidfile**="" - Write the container ID to the file - -**--cpu-count**=*0* - Limit the number of CPUs available for execution by the container. - - On Windows Server containers, this is approximated as a percentage of total CPU usage. - - On Windows Server containers, the processor resource controls are mutually exclusive, the order of precedence is CPUCount first, then CPUShares, and CPUPercent last. - -**--cpu-percent**=*0* - Limit the percentage of CPU available for execution by a container running on a Windows daemon. - - On Windows Server containers, the processor resource controls are mutually exclusive, the order of precedence is CPUCount first, then CPUShares, and CPUPercent last. - -**--cpu-period**=*0* - Limit the CPU CFS (Completely Fair Scheduler) period - - Limit the container's CPU usage. This flag tell the kernel to restrict the container's CPU usage to the period you specify. - -**--cpuset-cpus**="" - CPUs in which to allow execution (0-3, 0,1) - -**--cpuset-mems**="" - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. - - If you have four memory nodes on your system (0-3), use `--cpuset-mems=0,1` -then processes in your Docker container will only use memory from the first -two memory nodes. - -**--cpu-quota**=*0* - Limit the CPU CFS (Completely Fair Scheduler) quota - -**--cpu-rt-period**=0 - Limit the CPU real-time period in microseconds - - Limit the container's Real Time CPU usage. This flag tell the kernel to restrict the container's Real Time CPU usage to the period you specify. - -**--cpu-rt-runtime**=0 - Limit the CPU real-time runtime in microseconds - - Limit the containers Real Time CPU usage. This flag tells the kernel to limit the amount of time in a given CPU period Real Time tasks may consume. Ex: - Period of 1,000,000us and Runtime of 950,000us means that this container could consume 95% of available CPU and leave the remaining 5% to normal priority tasks. - - The sum of all runtimes across containers cannot exceed the amount allotted to the parent cgroup. - -**--cpus**=0.0 - Number of CPUs. The default is *0.0*. - -**--device**=[] - Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm) - -**--device-read-bps**=[] - Limit read rate (bytes per second) from a device (e.g. --device-read-bps=/dev/sda:1mb) - -**--device-read-iops**=[] - Limit read rate (IO per second) from a device (e.g. --device-read-iops=/dev/sda:1000) - -**--device-write-bps**=[] - Limit write rate (bytes per second) to a device (e.g. --device-write-bps=/dev/sda:1mb) - -**--device-write-iops**=[] - Limit write rate (IO per second) to a device (e.g. --device-write-iops=/dev/sda:1000) - -**--dns**=[] - Set custom DNS servers - -**--dns-option**=[] - Set custom DNS options - -**--dns-search**=[] - Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain) - -**-e**, **--env**=[] - Set environment variables - -**--entrypoint**="" - Overwrite the default ENTRYPOINT of the image - -**--env-file**=[] - Read in a line-delimited file of environment variables - -**--expose**=[] - Expose a port or a range of ports (e.g. --expose=3300-3310) from the container without publishing it to your host - -**--group-add**=[] - Add additional groups to run as - -**-h**, **--hostname**="" - Container host name - -**--help** - Print usage statement - -**-i**, **--interactive**=*true*|*false* - Keep STDIN open even if not attached. The default is *false*. - -**--ip**="" - Sets the container's interface IPv4 address (e.g. 172.23.0.9) - - It can only be used in conjunction with **--network** for user-defined networks - -**--ip6**="" - Sets the container's interface IPv6 address (e.g. 2001:db8::1b99) - - It can only be used in conjunction with **--network** for user-defined networks - -**--ipc**="" - Default is to create a private IPC namespace (POSIX SysV IPC) for the container - 'container:': reuses another container shared memory, semaphores and message queues - 'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure. - -**--isolation**="*default*" - Isolation specifies the type of isolation technology used by containers. Note -that the default on Windows server is `process`, and the default on Windows client -is `hyperv`. Linux only supports `default`. - -**--kernel-memory**="" - Kernel memory limit (format: `[]`, where unit = b, k, m or g) - - Constrains the kernel memory available to a container. If a limit of 0 -is specified (not using `--kernel-memory`), the container's kernel memory -is not limited. If you specify a limit, it may be rounded up to a multiple -of the operating system's page size and the value can be very large, -millions of trillions. - -**-l**, **--label**=[] - Adds metadata to a container (e.g., --label=com.example.key=value) - -**--label-file**=[] - Read labels from a file. Delimit each label with an EOL. - -**--link**=[] - Add link to another container in the form of :alias or just - in which case the alias will match the name. - -**--link-local-ip**=[] - Add one or more link-local IPv4/IPv6 addresses to the container's interface - -**--log-driver**="*json-file*|*syslog*|*journald*|*gelf*|*fluentd*|*awslogs*|*splunk*|*etwlogs*|*gcplogs*|*none*" - Logging driver for the container. Default is defined by daemon `--log-driver` flag. - **Warning**: the `docker logs` command works only for the `json-file` and - `journald` logging drivers. - -**--log-opt**=[] - Logging driver specific options. - -**-m**, **--memory**="" - Memory limit (format: [], where unit = b, k, m or g) - - Allows you to constrain the memory available to a container. If the host -supports swap memory, then the **-m** memory setting can be larger than physical -RAM. If a limit of 0 is specified (not using **-m**), the container's memory is -not limited. The actual limit may be rounded up to a multiple of the operating -system's page size (the value would be very large, that's millions of trillions). - -**--mac-address**="" - Container MAC address (e.g. 92:d0:c6:0a:29:33) - -**--memory-reservation**="" - Memory soft limit (format: [], where unit = b, k, m or g) - - After setting memory reservation, when the system detects memory contention -or low memory, containers are forced to restrict their consumption to their -reservation. So you should always set the value below **--memory**, otherwise the -hard limit will take precedence. By default, memory reservation will be the same -as memory limit. - -**--memory-swap**="LIMIT" - A limit value equal to memory plus swap. Must be used with the **-m** -(**--memory**) flag. The swap `LIMIT` should always be larger than **-m** -(**--memory**) value. - - The format of `LIMIT` is `[]`. Unit can be `b` (bytes), -`k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you don't specify a -unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap. - -**--memory-swappiness**="" - Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. - -**--name**="" - Assign a name to the container - -**--network**="*bridge*" - Set the Network mode for the container - 'bridge': create a network stack on the default Docker bridge - 'none': no networking - 'container:': reuse another container's network stack - 'host': use the Docker host network stack. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure. - '|': connect to a user-defined network - -**--network-alias**=[] - Add network-scoped alias for the container - -**--oom-kill-disable**=*true*|*false* - Whether to disable OOM Killer for the container or not. - -**--oom-score-adj**="" - Tune the host's OOM preferences for containers (accepts -1000 to 1000) - -**-P**, **--publish-all**=*true*|*false* - Publish all exposed ports to random ports on the host interfaces. The default is *false*. - -**-p**, **--publish**=[] - Publish a container's port, or a range of ports, to the host - format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort - Both hostPort and containerPort can be specified as a range of ports. - When specifying ranges for both, the number of container ports in the range must match the number of host ports in the range. (e.g., `-p 1234-1236:1234-1236/tcp`) - (use 'docker port' to see the actual mapping) - -**--pid**="" - Set the PID mode for the container - Default is to create a private PID namespace for the container - 'container:': join another container's PID namespace - 'host': use the host's PID namespace for the container. Note: the host mode gives the container full access to local PID and is therefore considered insecure. - -**--userns**="" - Set the usernamespace mode for the container when `userns-remap` option is enabled. - **host**: use the host usernamespace and enable all privileged options (e.g., `pid=host` or `--privileged`). - -**--pids-limit**="" - Tune the container's pids limit. Set `-1` to have unlimited pids for the container. - -**--privileged**=*true*|*false* - Give extended privileges to this container. The default is *false*. - -**--read-only**=*true*|*false* - Mount the container's root filesystem as read only. - -**--restart**="*no*" - Restart policy to apply when a container exits (no, on-failure[:max-retry], always, unless-stopped). - -**--rm**=*true*|*false* - Automatically remove the container when it exits. The default is *false*. - -**--shm-size**="" - Size of `/dev/shm`. The format is ``. `number` must be greater than `0`. - Unit is optional and can be `b` (bytes), `k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you omit the unit, the system uses bytes. - If you omit the size entirely, the system uses `64m`. - -**--security-opt**=[] - Security Options - - "label:user:USER" : Set the label user for the container - "label:role:ROLE" : Set the label role for the container - "label:type:TYPE" : Set the label type for the container - "label:level:LEVEL" : Set the label level for the container - "label:disable" : Turn off label confinement for the container - "no-new-privileges" : Disable container processes from gaining additional privileges - "seccomp:unconfined" : Turn off seccomp confinement for the container - "seccomp:profile.json : White listed syscalls seccomp Json file to be used as a seccomp filter - -**--storage-opt**=[] - Storage driver options per container - - $ docker create -it --storage-opt size=120G fedora /bin/bash - - This (size) will allow to set the container rootfs size to 120G at creation time. - This option is only available for the `devicemapper`, `btrfs`, `overlay2` and `zfs` graph drivers. - For the `devicemapper`, `btrfs` and `zfs` storage drivers, user cannot pass a size less than the Default BaseFS Size. - For the `overlay2` storage driver, the size option is only available if the backing fs is `xfs` and mounted with the `pquota` mount option. - Under these conditions, user can pass any size less then the backing fs size. - -**--stop-signal**=*SIGTERM* - Signal to stop a container. Default is SIGTERM. - -**--stop-timeout**=*10* - Timeout (in seconds) to stop a container. Default is 10. - -**--sysctl**=SYSCTL - Configure namespaced kernel parameters at runtime - - IPC Namespace - current sysctls allowed: - - kernel.msgmax, kernel.msgmnb, kernel.msgmni, kernel.sem, kernel.shmall, kernel.shmmax, kernel.shmmni, kernel.shm_rmid_forced - Sysctls beginning with fs.mqueue.* - - Note: if you use --ipc=host using these sysctls will not be allowed. - - Network Namespace - current sysctls allowed: - Sysctls beginning with net.* - - Note: if you use --network=host using these sysctls will not be allowed. - -**-t**, **--tty**=*true*|*false* - Allocate a pseudo-TTY. The default is *false*. - -**--tmpfs**=[] Create a tmpfs mount - - Mount a temporary filesystem (`tmpfs`) mount into a container, for example: - - $ docker run -d --tmpfs /tmp:rw,size=787448k,mode=1777 my_image - - This command mounts a `tmpfs` at `/tmp` within the container. The supported mount -options are the same as the Linux default `mount` flags. If you do not specify -any options, the systems uses the following options: -`rw,noexec,nosuid,nodev,size=65536k`. - -**-u**, **--user**="" - Sets the username or UID used and optionally the groupname or GID for the specified command. - - The followings examples are all valid: - --user [user | user:group | uid | uid:gid | user:gid | uid:group ] - - Without this argument root user will be used in the container by default. - -**--ulimit**=[] - Ulimit options - -**--uts**=*host* - Set the UTS mode for the container - **host**: use the host's UTS namespace inside the container. - Note: the host mode gives the container access to changing the host's hostname and is therefore considered insecure. - -**-v**|**--volume**[=*[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]*] - Create a bind mount. If you specify, ` -v /HOST-DIR:/CONTAINER-DIR`, Docker - bind mounts `/HOST-DIR` in the host to `/CONTAINER-DIR` in the Docker - container. If 'HOST-DIR' is omitted, Docker automatically creates the new - volume on the host. The `OPTIONS` are a comma delimited list and can be: - - * [rw|ro] - * [z|Z] - * [`[r]shared`|`[r]slave`|`[r]private`] - -The `CONTAINER-DIR` must be an absolute path such as `/src/docs`. The `HOST-DIR` -can be an absolute path or a `name` value. A `name` value must start with an -alphanumeric character, followed by `a-z0-9`, `_` (underscore), `.` (period) or -`-` (hyphen). An absolute path starts with a `/` (forward slash). - -If you supply a `HOST-DIR` that is an absolute path, Docker bind-mounts to the -path you specify. If you supply a `name`, Docker creates a named volume by that -`name`. For example, you can specify either `/foo` or `foo` for a `HOST-DIR` -value. If you supply the `/foo` value, Docker creates a bind-mount. If you -supply the `foo` specification, Docker creates a named volume. - -You can specify multiple **-v** options to mount one or more mounts to a -container. To use these same mounts in other containers, specify the -**--volumes-from** option also. - -You can add `:ro` or `:rw` suffix to a volume to mount it read-only or -read-write mode, respectively. By default, the volumes are mounted read-write. -See examples. - -Labeling systems like SELinux require that proper labels are placed on volume -content mounted into a container. Without a label, the security system might -prevent the processes running inside the container from using the content. By -default, Docker does not change the labels set by the OS. - -To change a label in the container context, you can add either of two suffixes -`:z` or `:Z` to the volume mount. These suffixes tell Docker to relabel file -objects on the shared volumes. The `z` option tells Docker that two containers -share the volume content. As a result, Docker labels the content with a shared -content label. Shared volume labels allow all containers to read/write content. -The `Z` option tells Docker to label the content with a private unshared label. -Only the current container can use a private volume. - -By default bind mounted volumes are `private`. That means any mounts done -inside container will not be visible on host and vice-a-versa. One can change -this behavior by specifying a volume mount propagation property. Making a -volume `shared` mounts done under that volume inside container will be -visible on host and vice-a-versa. Making a volume `slave` enables only one -way mount propagation and that is mounts done on host under that volume -will be visible inside container but not the other way around. - -To control mount propagation property of volume one can use `:[r]shared`, -`:[r]slave` or `:[r]private` propagation flag. Propagation property can -be specified only for bind mounted volumes and not for internal volumes or -named volumes. For mount propagation to work source mount point (mount point -where source dir is mounted on) has to have right propagation properties. For -shared volumes, source mount point has to be shared. And for slave volumes, -source mount has to be either shared or slave. - -Use `df ` to figure out the source mount and then use -`findmnt -o TARGET,PROPAGATION ` to figure out propagation -properties of source mount. If `findmnt` utility is not available, then one -can look at mount entry for source mount point in `/proc/self/mountinfo`. Look -at `optional fields` and see if any propagaion properties are specified. -`shared:X` means mount is `shared`, `master:X` means mount is `slave` and if -nothing is there that means mount is `private`. - -To change propagation properties of a mount point use `mount` command. For -example, if one wants to bind mount source directory `/foo` one can do -`mount --bind /foo /foo` and `mount --make-private --make-shared /foo`. This -will convert /foo into a `shared` mount point. Alternatively one can directly -change propagation properties of source mount. Say `/` is source mount for -`/foo`, then use `mount --make-shared /` to convert `/` into a `shared` mount. - -> **Note**: -> When using systemd to manage the Docker daemon's start and stop, in the systemd -> unit file there is an option to control mount propagation for the Docker daemon -> itself, called `MountFlags`. The value of this setting may cause Docker to not -> see mount propagation changes made on the mount point. For example, if this value -> is `slave`, you may not be able to use the `shared` or `rshared` propagation on -> a volume. - - -To disable automatic copying of data from the container path to the volume, use -the `nocopy` flag. The `nocopy` flag can be set on bind mounts and named volumes. - -**--volume-driver**="" - Container's volume driver. This driver creates volumes specified either from - a Dockerfile's `VOLUME` instruction or from the `docker run -v` flag. - See **docker-volume-create(1)** for full details. - -**--volumes-from**=[] - Mount volumes from the specified container(s) - -**-w**, **--workdir**="" - Working directory inside the container - -# EXAMPLES - -## Specify isolation technology for container (--isolation) - -This option is useful in situations where you are running Docker containers on -Windows. The `--isolation=` option sets a container's isolation -technology. On Linux, the only supported is the `default` option which uses -Linux namespaces. On Microsoft Windows, you can specify these values: - -* `default`: Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value. -* `process`: Namespace isolation only. -* `hyperv`: Hyper-V hypervisor partition-based isolation. - -Specifying the `--isolation` flag without a value is the same as setting `--isolation="default"`. - -# HISTORY -August 2014, updated by Sven Dowideit -September 2014, updated by Sven Dowideit -November 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-diff.1.md b/vendor/github.com/docker/docker/man/docker-diff.1.md deleted file mode 100644 index 6c6c502..0000000 --- a/vendor/github.com/docker/docker/man/docker-diff.1.md +++ /dev/null @@ -1,49 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-diff - Inspect changes on a container's filesystem - -# SYNOPSIS -**docker diff** -[**--help**] -CONTAINER - -# DESCRIPTION -Inspect changes on a container's filesystem. You can use the full or -shortened container ID or the container name set using -**docker run --name** option. - -# OPTIONS -**--help** - Print usage statement - -# EXAMPLES -Inspect the changes to on a nginx container: - - # docker diff 1fdfd1f54c1b - C /dev - C /dev/console - C /dev/core - C /dev/stdout - C /dev/fd - C /dev/ptmx - C /dev/stderr - C /dev/stdin - C /run - A /run/nginx.pid - C /var/lib/nginx/tmp - A /var/lib/nginx/tmp/client_body - A /var/lib/nginx/tmp/fastcgi - A /var/lib/nginx/tmp/proxy - A /var/lib/nginx/tmp/scgi - A /var/lib/nginx/tmp/uwsgi - C /var/log/nginx - A /var/log/nginx/access.log - A /var/log/nginx/error.log - - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-events.1.md b/vendor/github.com/docker/docker/man/docker-events.1.md deleted file mode 100644 index 51b0427..0000000 --- a/vendor/github.com/docker/docker/man/docker-events.1.md +++ /dev/null @@ -1,180 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-events - Get real time events from the server - -# SYNOPSIS -**docker events** -[**--help**] -[**-f**|**--filter**[=*[]*]] -[**--since**[=*SINCE*]] -[**--until**[=*UNTIL*]] -[**--format**[=*FORMAT*]] - - -# DESCRIPTION -Get event information from the Docker daemon. Information can include historical -information and real-time information. - -Docker containers will report the following events: - - attach, commit, copy, create, destroy, detach, die, exec_create, exec_detach, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update - -Docker images report the following events: - - delete, import, load, pull, push, save, tag, untag - -Docker volumes report the following events: - - create, mount, unmount, destroy - -Docker networks report the following events: - - create, connect, disconnect, destroy - -# OPTIONS -**--help** - Print usage statement - -**-f**, **--filter**=[] - Filter output based on these conditions - - container (`container=`) - - event (`event=`) - - image (`image=`) - - plugin (experimental) (`plugin=`) - - label (`label=` or `label==`) - - type (`type=`) - - volume (`volume=`) - - network (`network=`) - - daemon (`daemon=`) - -**--since**="" - Show all events created since timestamp - -**--until**="" - Stream events until this timestamp - -**--format**="" - Format the output using the given Go template - -The `--since` and `--until` parameters can be Unix timestamps, date formatted -timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed -relative to the client machine's time. If you do not provide the `--since` option, -the command returns only new and/or live events. Supported formats for date -formatted time stamps include RFC3339Nano, RFC3339, `2006-01-02T15:04:05`, -`2006-01-02T15:04:05.999999999`, `2006-01-02Z07:00`, and `2006-01-02`. The local -timezone on the client will be used if you do not provide either a `Z` or a -`+-00:00` timezone offset at the end of the timestamp. When providing Unix -timestamps enter seconds[.nanoseconds], where seconds is the number of seconds -that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap -seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a -fraction of a second no more than nine digits long. - -# EXAMPLES - -## Listening for Docker events - -After running docker events a container 786d698004576 is started and stopped -(The container name has been shortened in the output below): - - # docker events - 2015-01-28T20:21:31.000000000-08:00 59211849bc10: (from whenry/testimage:latest) start - 2015-01-28T20:21:31.000000000-08:00 59211849bc10: (from whenry/testimage:latest) die - 2015-01-28T20:21:32.000000000-08:00 59211849bc10: (from whenry/testimage:latest) stop - -## Listening for events since a given date -Again the output container IDs have been shortened for the purposes of this document: - - # docker events --since '2015-01-28' - 2015-01-28T20:25:38.000000000-08:00 c21f6c22ba27: (from whenry/testimage:latest) create - 2015-01-28T20:25:38.000000000-08:00 c21f6c22ba27: (from whenry/testimage:latest) start - 2015-01-28T20:25:39.000000000-08:00 c21f6c22ba27: (from whenry/testimage:latest) create - 2015-01-28T20:25:39.000000000-08:00 c21f6c22ba27: (from whenry/testimage:latest) start - 2015-01-28T20:25:40.000000000-08:00 c21f6c22ba27: (from whenry/testimage:latest) die - 2015-01-28T20:25:42.000000000-08:00 c21f6c22ba27: (from whenry/testimage:latest) stop - 2015-01-28T20:25:45.000000000-08:00 c21f6c22ba27: (from whenry/testimage:latest) start - 2015-01-28T20:25:45.000000000-08:00 c21f6c22ba27: (from whenry/testimage:latest) die - 2015-01-28T20:25:46.000000000-08:00 c21f6c22ba27: (from whenry/testimage:latest) stop - -The following example outputs all events that were generated in the last 3 minutes, -relative to the current time on the client machine: - - # docker events --since '3m' - 2015-05-12T11:51:30.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) die - 2015-05-12T15:52:12.999999999Z07:00 4386fb97867d: (from ubuntu-1:14.04) stop - 2015-05-12T15:53:45.999999999Z07:00 7805c1d35632: (from redis:2.8) die - 2015-05-12T15:54:03.999999999Z07:00 7805c1d35632: (from redis:2.8) stop - -If you do not provide the --since option, the command returns only new and/or -live events. - -## Format - -If a format (`--format`) is specified, the given template will be executed -instead of the default format. Go's **text/template** package describes all the -details of the format. - - # docker events --filter 'type=container' --format 'Type={{.Type}} Status={{.Status}} ID={{.ID}}' - Type=container Status=create ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - Type=container Status=attach ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - Type=container Status=start ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - Type=container Status=resize ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - Type=container Status=die ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - Type=container Status=destroy ID=2ee349dac409e97974ce8d01b70d250b85e0ba8189299c126a87812311951e26 - -If a format is set to `{{json .}}`, the events are streamed as valid JSON -Lines. For information about JSON Lines, please refer to http://jsonlines.org/ . - - # docker events --format '{{json .}}' - {"status":"create","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f4.. - {"status":"attach","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f4.. - {"Type":"network","Action":"connect","Actor":{"ID":"1b50a5bf755f6021dfa78e.. - {"status":"start","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f42.. - {"status":"resize","id":"196016a57679bf42424484918746a9474cd905dd993c4d0f4.. - -## Filters - - $ docker events --filter 'event=stop' - 2014-05-10T17:42:14.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - 2014-09-03T17:42:14.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - - $ docker events --filter 'image=ubuntu-1:14.04' - 2014-05-10T17:42:14.999999999Z07:00 container start 4386fb97867d (image=ubuntu-1:14.04) - 2014-05-10T17:42:14.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) - 2014-05-10T17:42:14.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - - $ docker events --filter 'container=7805c1d35632' - 2014-05-10T17:42:14.999999999Z07:00 container die 7805c1d35632 (image=redis:2.8) - 2014-09-03T15:49:29.999999999Z07:00 container stop 7805c1d35632 (image= redis:2.8) - - $ docker events --filter 'container=7805c1d35632' --filter 'container=4386fb97867d' - 2014-09-03T15:49:29.999999999Z07:00 container die 4386fb97867d (image=ubuntu-1:14.04) - 2014-05-10T17:42:14.999999999Z07:00 container stop 4386fb97867d (image=ubuntu-1:14.04) - 2014-05-10T17:42:14.999999999Z07:00 container die 7805c1d35632 (image=redis:2.8) - 2014-09-03T15:49:29.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - - $ docker events --filter 'container=7805c1d35632' --filter 'event=stop' - 2014-09-03T15:49:29.999999999Z07:00 container stop 7805c1d35632 (image=redis:2.8) - - $ docker events --filter 'type=volume' - 2015-12-23T21:05:28.136212689Z volume create test-event-volume-local (driver=local) - 2015-12-23T21:05:28.383462717Z volume mount test-event-volume-local (read/write=true, container=562fe10671e9273da25eed36cdce26159085ac7ee6707105fd534866340a5025, destination=/foo, driver=local, propagation=rprivate) - 2015-12-23T21:05:28.650314265Z volume unmount test-event-volume-local (container=562fe10671e9273da25eed36cdce26159085ac7ee6707105fd534866340a5025, driver=local) - 2015-12-23T21:05:28.716218405Z volume destroy test-event-volume-local (driver=local) - - $ docker events --filter 'type=network' - 2015-12-23T21:38:24.705709133Z network create 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (name=test-event-network-local, type=bridge) - 2015-12-23T21:38:25.119625123Z network connect 8b111217944ba0ba844a65b13efcd57dc494932ee2527577758f939315ba2c5b (name=test-event-network-local, container=b4be644031a3d90b400f88ab3d4bdf4dc23adb250e696b6328b85441abe2c54e, type=bridge) - - $ docker events --filter 'type=plugin' (experimental) - 2016-07-25T17:30:14.825557616Z plugin pull ec7b87f2ce84330fe076e666f17dfc049d2d7ae0b8190763de94e1f2d105993f (name=tiborvass/sample-volume-plugin:latest) - 2016-07-25T17:30:14.888127370Z plugin enable ec7b87f2ce84330fe076e666f17dfc049d2d7ae0b8190763de94e1f2d105993f (name=tiborvass/sample-volume-plugin:latest) - - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -June 2015, updated by Brian Goff -October 2015, updated by Mike Brown diff --git a/vendor/github.com/docker/docker/man/docker-exec.1.md b/vendor/github.com/docker/docker/man/docker-exec.1.md deleted file mode 100644 index fe9c279..0000000 --- a/vendor/github.com/docker/docker/man/docker-exec.1.md +++ /dev/null @@ -1,71 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-exec - Run a command in a running container - -# SYNOPSIS -**docker exec** -[**-d**|**--detach**] -[**--detach-keys**[=*[]*]] -[**-e**|**--env**[=*[]*]] -[**--help**] -[**-i**|**--interactive**] -[**--privileged**] -[**-t**|**--tty**] -[**-u**|**--user**[=*USER*]] -CONTAINER COMMAND [ARG...] - -# DESCRIPTION - -Run a process in a running container. - -The command started using `docker exec` will only run while the container's primary -process (`PID 1`) is running, and will not be restarted if the container is restarted. - -If the container is paused, then the `docker exec` command will wait until the -container is unpaused, and then run - -# OPTIONS -**-d**, **--detach**=*true*|*false* - Detached mode: run command in the background. The default is *false*. - -**--detach-keys**="" - Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-` where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. - -**-e**, **--env**=[] - Set environment variables - - This option allows you to specify arbitrary environment variables that are -available for the command to be executed. - -**--help** - Print usage statement - -**-i**, **--interactive**=*true*|*false* - Keep STDIN open even if not attached. The default is *false*. - -**--privileged**=*true*|*false* - Give the process extended [Linux capabilities](http://man7.org/linux/man-pages/man7/capabilities.7.html) -when running in a container. The default is *false*. - - Without this flag, the process run by `docker exec` in a running container has -the same capabilities as the container, which may be limited. Set -`--privileged` to give all capabilities to the process. - -**-t**, **--tty**=*true*|*false* - Allocate a pseudo-TTY. The default is *false*. - -**-u**, **--user**="" - Sets the username or UID used and optionally the groupname or GID for the specified command. - - The followings examples are all valid: - --user [user | user:group | uid | uid:gid | user:gid | uid:group ] - - Without this argument the command will be run as root in the container. - -The **-t** option is incompatible with a redirection of the docker client -standard input. - -# HISTORY -November 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-export.1.md b/vendor/github.com/docker/docker/man/docker-export.1.md deleted file mode 100644 index 3d59e47..0000000 --- a/vendor/github.com/docker/docker/man/docker-export.1.md +++ /dev/null @@ -1,46 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-export - Export the contents of a container's filesystem as a tar archive - -# SYNOPSIS -**docker export** -[**--help**] -[**-o**|**--output**[=*""*]] -CONTAINER - -# DESCRIPTION -Export the contents of a container's filesystem using the full or shortened -container ID or container name. The output is exported to STDOUT and can be -redirected to a tar file. - -Stream to a file instead of STDOUT by using **-o**. - -# OPTIONS -**--help** - Print usage statement - -**-o**, **--output**="" - Write to a file, instead of STDOUT - -# EXAMPLES -Export the contents of the container called angry_bell to a tar file -called angry_bell.tar: - - # docker export angry_bell > angry_bell.tar - # docker export --output=angry_bell-latest.tar angry_bell - # ls -sh angry_bell.tar - 321M angry_bell.tar - # ls -sh angry_bell-latest.tar - 321M angry_bell-latest.tar - -# See also -**docker-import(1)** to create an empty filesystem image -and import the contents of the tarball into it, then optionally tag it. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -January 2015, updated by Joseph Kern (josephakern at gmail dot com) diff --git a/vendor/github.com/docker/docker/man/docker-history.1.md b/vendor/github.com/docker/docker/man/docker-history.1.md deleted file mode 100644 index 91edefe..0000000 --- a/vendor/github.com/docker/docker/man/docker-history.1.md +++ /dev/null @@ -1,52 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-history - Show the history of an image - -# SYNOPSIS -**docker history** -[**--help**] -[**-H**|**--human**[=*true*]] -[**--no-trunc**] -[**-q**|**--quiet**] -IMAGE - -# DESCRIPTION - -Show the history of when and how an image was created. - -# OPTIONS -**--help** - Print usage statement - -**-H**, **--human**=*true*|*false* - Print sizes and dates in human readable format. The default is *true*. - -**--no-trunc**=*true*|*false* - Don't truncate output. The default is *false*. - -**-q**, **--quiet**=*true*|*false* - Only show numeric IDs. The default is *false*. - -# EXAMPLES - $ docker history fedora - IMAGE CREATED CREATED BY SIZE COMMENT - 105182bb5e8b 5 days ago /bin/sh -c #(nop) ADD file:71356d2ad59aa3119d 372.7 MB - 73bd853d2ea5 13 days ago /bin/sh -c #(nop) MAINTAINER Lokesh Mandvekar 0 B - 511136ea3c5a 10 months ago 0 B Imported from - - -## Display comments in the image history -The `docker commit` command has a **-m** flag for adding comments to the image. These comments will be displayed in the image history. - - $ sudo docker history docker:scm - IMAGE CREATED CREATED BY SIZE COMMENT - 2ac9d1098bf1 3 months ago /bin/bash 241.4 MB Added Apache to Fedora base image - 88b42ffd1f7c 5 months ago /bin/sh -c #(nop) ADD file:1fd8d7f9f6557cafc7 373.7 MB - c69cab00d6ef 5 months ago /bin/sh -c #(nop) MAINTAINER Lokesh Mandvekar 0 B - 511136ea3c5a 19 months ago 0 B Imported from - - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-images.1.md b/vendor/github.com/docker/docker/man/docker-images.1.md deleted file mode 100644 index d7958d0..0000000 --- a/vendor/github.com/docker/docker/man/docker-images.1.md +++ /dev/null @@ -1,153 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-images - List images - -# SYNOPSIS -**docker images** -[**--help**] -[**-a**|**--all**] -[**--digests**] -[**-f**|**--filter**[=*[]*]] -[**--format**=*"TEMPLATE"*] -[**--no-trunc**] -[**-q**|**--quiet**] -[REPOSITORY[:TAG]] - -# DESCRIPTION -This command lists the images stored in the local Docker repository. - -By default, intermediate images, used during builds, are not listed. Some of the -output, e.g., image ID, is truncated, for space reasons. However the truncated -image ID, and often the first few characters, are enough to be used in other -Docker commands that use the image ID. The output includes repository, tag, image -ID, date created and the virtual size. - -The title REPOSITORY for the first title may seem confusing. It is essentially -the image name. However, because you can tag a specific image, and multiple tags -(image instances) can be associated with a single name, the name is really a -repository for all tagged images of the same name. For example consider an image -called fedora. It may be tagged with 18, 19, or 20, etc. to manage different -versions. - -# OPTIONS -**-a**, **--all**=*true*|*false* - Show all images (by default filter out the intermediate image layers). The default is *false*. - -**--digests**=*true*|*false* - Show image digests. The default is *false*. - -**-f**, **--filter**=[] - Filters the output based on these conditions: - - dangling=(true|false) - find unused images - - label= or label== - - before=([:tag]||) - - since=([:tag]||) - -**--format**="*TEMPLATE*" - Pretty-print images using a Go template. - Valid placeholders: - .ID - Image ID - .Repository - Image repository - .Tag - Image tag - .Digest - Image digest - .CreatedSince - Elapsed time since the image was created - .CreatedAt - Time when the image was created - .Size - Image disk size - -**--help** - Print usage statement - -**--no-trunc**=*true*|*false* - Don't truncate output. The default is *false*. - -**-q**, **--quiet**=*true*|*false* - Only show numeric IDs. The default is *false*. - -# EXAMPLES - -## Listing the images - -To list the images in a local repository (not the registry) run: - - docker images - -The list will contain the image repository name, a tag for the image, and an -image ID, when it was created and its virtual size. Columns: REPOSITORY, TAG, -IMAGE ID, CREATED, and SIZE. - -The `docker images` command takes an optional `[REPOSITORY[:TAG]]` argument -that restricts the list to images that match the argument. If you specify -`REPOSITORY`but no `TAG`, the `docker images` command lists all images in the -given repository. - - docker images java - -The `[REPOSITORY[:TAG]]` value must be an "exact match". This means that, for example, -`docker images jav` does not match the image `java`. - -If both `REPOSITORY` and `TAG` are provided, only images matching that -repository and tag are listed. To find all local images in the "java" -repository with tag "8" you can use: - - docker images java:8 - -To get a verbose list of images which contains all the intermediate images -used in builds use **-a**: - - docker images -a - -Previously, the docker images command supported the --tree and --dot arguments, -which displayed different visualizations of the image data. Docker core removed -this functionality in the 1.7 version. If you liked this functionality, you can -still find it in the third-party dockviz tool: https://github.com/justone/dockviz. - -## Listing images in a desired format - -When using the --format option, the image command will either output the data -exactly as the template declares or, when using the `table` directive, will -include column headers as well. You can use special characters like `\t` for -inserting tab spacing between columns. - -The following example uses a template without headers and outputs the ID and -Repository entries separated by a colon for all images: - - docker images --format "{{.ID}}: {{.Repository}}" - 77af4d6b9913: - b6fa739cedf5: committ - 78a85c484bad: ipbabble - 30557a29d5ab: docker - 5ed6274db6ce: - 746b819f315e: postgres - 746b819f315e: postgres - 746b819f315e: postgres - 746b819f315e: postgres - -To list all images with their repository and tag in a table format you can use: - - docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}" - IMAGE ID REPOSITORY TAG - 77af4d6b9913 - b6fa739cedf5 committ latest - 78a85c484bad ipbabble - 30557a29d5ab docker latest - 5ed6274db6ce - 746b819f315e postgres 9 - 746b819f315e postgres 9.3 - 746b819f315e postgres 9.3.5 - 746b819f315e postgres latest - -Valid template placeholders are listed above. - -## Listing only the shortened image IDs - -Listing just the shortened image IDs. This can be useful for some automated -tools. - - docker images -q - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-import.1.md b/vendor/github.com/docker/docker/man/docker-import.1.md deleted file mode 100644 index 43d65ef..0000000 --- a/vendor/github.com/docker/docker/man/docker-import.1.md +++ /dev/null @@ -1,72 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-import - Create an empty filesystem image and import the contents of the tarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) into it, then optionally tag it. - -# SYNOPSIS -**docker import** -[**-c**|**--change**[=*[]*]] -[**-m**|**--message**[=*MESSAGE*]] -[**--help**] -file|URL|**-**[REPOSITORY[:TAG]] - -# OPTIONS -**-c**, **--change**=[] - Apply specified Dockerfile instructions while importing the image - Supported Dockerfile instructions: `CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`ONBUILD`|`USER`|`VOLUME`|`WORKDIR` - -**--help** - Print usage statement - -**-m**, **--message**="" - Set commit message for imported image - -# DESCRIPTION -Create a new filesystem image from the contents of a tarball (`.tar`, -`.tar.gz`, `.tgz`, `.bzip`, `.tar.xz`, `.txz`) into it, then optionally tag it. - - -# EXAMPLES - -## Import from a remote location - - # docker import http://example.com/exampleimage.tgz example/imagerepo - -## Import from a local file - -Import to docker via pipe and stdin: - - # cat exampleimage.tgz | docker import - example/imagelocal - -Import with a commit message. - - # cat exampleimage.tgz | docker import --message "New image imported from tarball" - exampleimagelocal:new - -Import to a Docker image from a local file. - - # docker import /path/to/exampleimage.tgz - - -## Import from a local file and tag - -Import to docker via pipe and stdin: - - # cat exampleimageV2.tgz | docker import - example/imagelocal:V-2.0 - -## Import from a local directory - - # tar -c . | docker import - exampleimagedir - -## Apply specified Dockerfile instructions while importing the image -This example sets the docker image ENV variable DEBUG to true by default. - - # tar -c . | docker import -c="ENV DEBUG true" - exampleimagedir - -# See also -**docker-export(1)** to export the contents of a filesystem as a tar archive to STDOUT. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-info.1.md b/vendor/github.com/docker/docker/man/docker-info.1.md deleted file mode 100644 index bb7a8fb..0000000 --- a/vendor/github.com/docker/docker/man/docker-info.1.md +++ /dev/null @@ -1,187 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-info - Display system-wide information - -# SYNOPSIS -**docker info** -[**--help**] -[**-f**|**--format**[=*FORMAT*]] - -# DESCRIPTION -This command displays system wide information regarding the Docker installation. -Information displayed includes the kernel version, number of containers and images. -The number of images shown is the number of unique images. The same image tagged -under different names is counted only once. - -If a format is specified, the given template will be executed instead of the -default format. Go's **text/template** package -describes all the details of the format. - -Depending on the storage driver in use, additional information can be shown, such -as pool name, data file, metadata file, data space used, total data space, metadata -space used, and total metadata space. - -The data file is where the images are stored and the metadata file is where the -meta data regarding those images are stored. When run for the first time Docker -allocates a certain amount of data space and meta data space from the space -available on the volume where `/var/lib/docker` is mounted. - -# OPTIONS -**--help** - Print usage statement - -**-f**, **--format**="" - Format the output using the given Go template - -# EXAMPLES - -## Display Docker system information - -Here is a sample output for a daemon running on Ubuntu, using the overlay2 -storage driver: - - $ docker -D info - Containers: 14 - Running: 3 - Paused: 1 - Stopped: 10 - Images: 52 - Server Version: 1.13.0 - Storage Driver: overlay2 - Backing Filesystem: extfs - Supports d_type: true - Native Overlay Diff: false - Logging Driver: json-file - Cgroup Driver: cgroupfs - Plugins: - Volume: local - Network: bridge host macvlan null overlay - Swarm: active - NodeID: rdjq45w1op418waxlairloqbm - Is Manager: true - ClusterID: te8kdyw33n36fqiz74bfjeixd - Managers: 1 - Nodes: 2 - Orchestration: - Task History Retention Limit: 5 - Raft: - Snapshot Interval: 10000 - Number of Old Snapshots to Retain: 0 - Heartbeat Tick: 1 - Election Tick: 3 - Dispatcher: - Heartbeat Period: 5 seconds - CA Configuration: - Expiry Duration: 3 months - Node Address: 172.16.66.128 172.16.66.129 - Manager Addresses: - 172.16.66.128:2477 - Runtimes: runc - Default Runtime: runc - Init Binary: docker-init - containerd version: 8517738ba4b82aff5662c97ca4627e7e4d03b531 - runc version: ac031b5bf1cc92239461125f4c1ffb760522bbf2 - init version: N/A (expected: v0.13.0) - Security Options: - apparmor - seccomp - Profile: default - Kernel Version: 4.4.0-31-generic - Operating System: Ubuntu 16.04.1 LTS - OSType: linux - Architecture: x86_64 - CPUs: 2 - Total Memory: 1.937 GiB - Name: ubuntu - ID: H52R:7ZR6:EIIA:76JG:ORIY:BVKF:GSFU:HNPG:B5MK:APSC:SZ3Q:N326 - Docker Root Dir: /var/lib/docker - Debug Mode (client): true - Debug Mode (server): true - File Descriptors: 30 - Goroutines: 123 - System Time: 2016-11-12T17:24:37.955404361-08:00 - EventsListeners: 0 - Http Proxy: http://test:test@proxy.example.com:8080 - Https Proxy: https://test:test@proxy.example.com:8080 - No Proxy: localhost,127.0.0.1,docker-registry.somecorporation.com - Registry: https://index.docker.io/v1/ - WARNING: No swap limit support - Labels: - storage=ssd - staging=true - Experimental: false - Insecure Registries: - 127.0.0.0/8 - Registry Mirrors: - http://192.168.1.2/ - http://registry-mirror.example.com:5000/ - Live Restore Enabled: false - - - -The global `-D` option tells all `docker` commands to output debug information. - -The example below shows the output for a daemon running on Red Hat Enterprise Linux, -using the devicemapper storage driver. As can be seen in the output, additional -information about the devicemapper storage driver is shown: - - $ docker info - Containers: 14 - Running: 3 - Paused: 1 - Stopped: 10 - Untagged Images: 52 - Server Version: 1.10.3 - Storage Driver: devicemapper - Pool Name: docker-202:2-25583803-pool - Pool Blocksize: 65.54 kB - Base Device Size: 10.74 GB - Backing Filesystem: xfs - Data file: /dev/loop0 - Metadata file: /dev/loop1 - Data Space Used: 1.68 GB - Data Space Total: 107.4 GB - Data Space Available: 7.548 GB - Metadata Space Used: 2.322 MB - Metadata Space Total: 2.147 GB - Metadata Space Available: 2.145 GB - Udev Sync Supported: true - Deferred Removal Enabled: false - Deferred Deletion Enabled: false - Deferred Deleted Device Count: 0 - Data loop file: /var/lib/docker/devicemapper/devicemapper/data - Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata - Library Version: 1.02.107-RHEL7 (2015-12-01) - Execution Driver: native-0.2 - Logging Driver: json-file - Plugins: - Volume: local - Network: null host bridge - Kernel Version: 3.10.0-327.el7.x86_64 - Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo) - OSType: linux - Architecture: x86_64 - CPUs: 1 - Total Memory: 991.7 MiB - Name: ip-172-30-0-91.ec2.internal - ID: I54V:OLXT:HVMM:TPKO:JPHQ:CQCD:JNLC:O3BZ:4ZVJ:43XJ:PFHZ:6N2S - Docker Root Dir: /var/lib/docker - Debug mode (client): false - Debug mode (server): false - Username: gordontheturtle - Registry: https://index.docker.io/v1/ - Insecure registries: - myinsecurehost:5000 - 127.0.0.0/8 - -You can also specify the output format: - - $ docker info --format '{{json .}}' - {"ID":"I54V:OLXT:HVMM:TPKO:JPHQ:CQCD:JNLC:O3BZ:4ZVJ:43XJ:PFHZ:6N2S","Containers":14, ...} - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-inspect.1.md b/vendor/github.com/docker/docker/man/docker-inspect.1.md deleted file mode 100644 index 21d7ba6..0000000 --- a/vendor/github.com/docker/docker/man/docker-inspect.1.md +++ /dev/null @@ -1,323 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-inspect - Return low-level information on docker objects - -# SYNOPSIS -**docker inspect** -[**--help**] -[**-f**|**--format**[=*FORMAT*]] -[**-s**|**--size**] -[**--type**=*container*|*image*|*network*|*node*|*service*|*task*|*volume*] -NAME|ID [NAME|ID...] - -# DESCRIPTION - -This displays the low-level information on Docker object(s) (e.g. container, -image, volume,network, node, service, or task) identified by name or ID. By default, -this will render all results in a JSON array. If the container and image have -the same name, this will return container JSON for unspecified type. If a format -is specified, the given template will be executed for each result. - -# OPTIONS -**--help** - Print usage statement - -**-f**, **--format**="" - Format the output using the given Go template - -**-s**, **--size** - Display total file sizes if the type is container - -**--type**=*container*|*image*|*network*|*node*|*service*|*task*|*volume* - Return JSON for specified type, permissible values are "image", "container", - "network", "node", "service", "task", and "volume" - -# EXAMPLES - -Get information about an image when image name conflicts with the container name, -e.g. both image and container are named rhel7: - - $ docker inspect --type=image rhel7 - [ - { - "Id": "fe01a428b9d9de35d29531e9994157978e8c48fa693e1bf1d221dffbbb67b170", - "Parent": "10acc31def5d6f249b548e01e8ffbaccfd61af0240c17315a7ad393d022c5ca2", - .... - } - ] - -## Getting information on a container - -To get information on a container use its ID or instance name: - - $ docker inspect d2cc496561d6 - [{ - "Id": "d2cc496561d6d520cbc0236b4ba88c362c446a7619992123f11c809cded25b47", - "Created": "2015-06-08T16:18:02.505155285Z", - "Path": "bash", - "Args": [], - "State": { - "Running": false, - "Paused": false, - "Restarting": false, - "OOMKilled": false, - "Dead": false, - "Pid": 0, - "ExitCode": 0, - "Error": "", - "StartedAt": "2015-06-08T16:18:03.643865954Z", - "FinishedAt": "2015-06-08T16:57:06.448552862Z" - }, - "Image": "ded7cd95e059788f2586a51c275a4f151653779d6a7f4dad77c2bd34601d94e4", - "NetworkSettings": { - "Bridge": "", - "SandboxID": "6b4851d1903e16dd6a567bd526553a86664361f31036eaaa2f8454d6f4611f6f", - "HairpinMode": false, - "LinkLocalIPv6Address": "", - "LinkLocalIPv6PrefixLen": 0, - "Ports": {}, - "SandboxKey": "/var/run/docker/netns/6b4851d1903e", - "SecondaryIPAddresses": null, - "SecondaryIPv6Addresses": null, - "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", - "Gateway": "172.17.0.1", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "IPAddress": "172.17.0.2", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "MacAddress": "02:42:ac:12:00:02", - "Networks": { - "bridge": { - "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", - "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", - "Gateway": "172.17.0.1", - "IPAddress": "172.17.0.2", - "IPPrefixLen": 16, - "IPv6Gateway": "", - "GlobalIPv6Address": "", - "GlobalIPv6PrefixLen": 0, - "MacAddress": "02:42:ac:12:00:02" - } - } - - }, - "ResolvConfPath": "/var/lib/docker/containers/d2cc496561d6d520cbc0236b4ba88c362c446a7619992123f11c809cded25b47/resolv.conf", - "HostnamePath": "/var/lib/docker/containers/d2cc496561d6d520cbc0236b4ba88c362c446a7619992123f11c809cded25b47/hostname", - "HostsPath": "/var/lib/docker/containers/d2cc496561d6d520cbc0236b4ba88c362c446a7619992123f11c809cded25b47/hosts", - "LogPath": "/var/lib/docker/containers/d2cc496561d6d520cbc0236b4ba88c362c446a7619992123f11c809cded25b47/d2cc496561d6d520cbc0236b4ba88c362c446a7619992123f11c809cded25b47-json.log", - "Name": "/adoring_wozniak", - "RestartCount": 0, - "Driver": "devicemapper", - "MountLabel": "", - "ProcessLabel": "", - "Mounts": [ - { - "Source": "/data", - "Destination": "/data", - "Mode": "ro,Z", - "RW": false - "Propagation": "" - } - ], - "AppArmorProfile": "", - "ExecIDs": null, - "HostConfig": { - "Binds": null, - "ContainerIDFile": "", - "Memory": 0, - "MemorySwap": 0, - "CpuShares": 0, - "CpuPeriod": 0, - "CpusetCpus": "", - "CpusetMems": "", - "CpuQuota": 0, - "BlkioWeight": 0, - "OomKillDisable": false, - "Privileged": false, - "PortBindings": {}, - "Links": null, - "PublishAllPorts": false, - "Dns": null, - "DnsSearch": null, - "DnsOptions": null, - "ExtraHosts": null, - "VolumesFrom": null, - "Devices": [], - "NetworkMode": "bridge", - "IpcMode": "", - "PidMode": "", - "UTSMode": "", - "CapAdd": null, - "CapDrop": null, - "RestartPolicy": { - "Name": "no", - "MaximumRetryCount": 0 - }, - "SecurityOpt": null, - "ReadonlyRootfs": false, - "Ulimits": null, - "LogConfig": { - "Type": "json-file", - "Config": {} - }, - "CgroupParent": "" - }, - "GraphDriver": { - "Name": "devicemapper", - "Data": { - "DeviceId": "5", - "DeviceName": "docker-253:1-2763198-d2cc496561d6d520cbc0236b4ba88c362c446a7619992123f11c809cded25b47", - "DeviceSize": "171798691840" - } - }, - "Config": { - "Hostname": "d2cc496561d6", - "Domainname": "", - "User": "", - "AttachStdin": true, - "AttachStdout": true, - "AttachStderr": true, - "ExposedPorts": null, - "Tty": true, - "OpenStdin": true, - "StdinOnce": true, - "Env": null, - "Cmd": [ - "bash" - ], - "Image": "fedora", - "Volumes": null, - "VolumeDriver": "", - "WorkingDir": "", - "Entrypoint": null, - "NetworkDisabled": false, - "MacAddress": "", - "OnBuild": null, - "Labels": {}, - "Memory": 0, - "MemorySwap": 0, - "CpuShares": 0, - "Cpuset": "", - "StopSignal": "SIGTERM" - } - } - ] -## Getting the IP address of a container instance - -To get the IP address of a container use: - - $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' d2cc496561d6 - 172.17.0.2 - -## Listing all port bindings - -One can loop over arrays and maps in the results to produce simple text -output: - - $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} \ - {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' d2cc496561d6 - 80/tcp -> 80 - -You can get more information about how to write a Go template from: -https://golang.org/pkg/text/template/. - -## Getting size information on a container - - $ docker inspect -s d2cc496561d6 - [ - { - .... - "SizeRw": 0, - "SizeRootFs": 972, - .... - } - ] - -## Getting information on an image - -Use an image's ID or name (e.g., repository/name[:tag]) to get information -about the image: - - $ docker inspect ded7cd95e059 - [{ - "Id": "ded7cd95e059788f2586a51c275a4f151653779d6a7f4dad77c2bd34601d94e4", - "Parent": "48ecf305d2cf7046c1f5f8fcbcd4994403173441d4a7f125b1bb0ceead9de731", - "Comment": "", - "Created": "2015-05-27T16:58:22.937503085Z", - "Container": "76cf7f67d83a7a047454b33007d03e32a8f474ad332c3a03c94537edd22b312b", - "ContainerConfig": { - "Hostname": "76cf7f67d83a", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": false, - "AttachStderr": false, - "ExposedPorts": null, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "/bin/sh", - "-c", - "#(nop) ADD file:4be46382bcf2b095fcb9fe8334206b584eff60bb3fad8178cbd97697fcb2ea83 in /" - ], - "Image": "48ecf305d2cf7046c1f5f8fcbcd4994403173441d4a7f125b1bb0ceead9de731", - "Volumes": null, - "VolumeDriver": "", - "WorkingDir": "", - "Entrypoint": null, - "NetworkDisabled": false, - "MacAddress": "", - "OnBuild": null, - "Labels": {} - }, - "DockerVersion": "1.6.0", - "Author": "Lokesh Mandvekar \u003clsm5@fedoraproject.org\u003e", - "Config": { - "Hostname": "76cf7f67d83a", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": false, - "AttachStderr": false, - "ExposedPorts": null, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": null, - "Image": "48ecf305d2cf7046c1f5f8fcbcd4994403173441d4a7f125b1bb0ceead9de731", - "Volumes": null, - "VolumeDriver": "", - "WorkingDir": "", - "Entrypoint": null, - "NetworkDisabled": false, - "MacAddress": "", - "OnBuild": null, - "Labels": {} - }, - "Architecture": "amd64", - "Os": "linux", - "Size": 186507296, - "VirtualSize": 186507296, - "GraphDriver": { - "Name": "devicemapper", - "Data": { - "DeviceId": "3", - "DeviceName": "docker-253:1-2763198-ded7cd95e059788f2586a51c275a4f151653779d6a7f4dad77c2bd34601d94e4", - "DeviceSize": "171798691840" - } - } - } - ] - -# HISTORY -April 2014, originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -April 2015, updated by Qiang Huang -October 2015, updated by Sally O'Malley diff --git a/vendor/github.com/docker/docker/man/docker-kill.1.md b/vendor/github.com/docker/docker/man/docker-kill.1.md deleted file mode 100644 index 36cbdb9..0000000 --- a/vendor/github.com/docker/docker/man/docker-kill.1.md +++ /dev/null @@ -1,28 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-kill - Kill a running container using SIGKILL or a specified signal - -# SYNOPSIS -**docker kill** -[**--help**] -[**-s**|**--signal**[=*"KILL"*]] -CONTAINER [CONTAINER...] - -# DESCRIPTION - -The main process inside each container specified will be sent SIGKILL, - or any signal specified with option --signal. - -# OPTIONS -**--help** - Print usage statement - -**-s**, **--signal**="*KILL*" - Signal to send to the container - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) - based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-load.1.md b/vendor/github.com/docker/docker/man/docker-load.1.md deleted file mode 100644 index b165173..0000000 --- a/vendor/github.com/docker/docker/man/docker-load.1.md +++ /dev/null @@ -1,56 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-load - Load an image from a tar archive or STDIN - -# SYNOPSIS -**docker load** -[**--help**] -[**-i**|**--input**[=*INPUT*]] -[**-q**|**--quiet**] - -# DESCRIPTION - -Loads a tarred repository from a file or the standard input stream. -Restores both images and tags. Write image names or IDs imported it -standard output stream. - -# OPTIONS -**--help** - Print usage statement - -**-i**, **--input**="" - Read from a tar archive file, instead of STDIN. The tarball may be compressed with gzip, bzip, or xz. - -**-q**, **--quiet** - Suppress the load progress bar but still outputs the imported images. - -# EXAMPLES - - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - busybox latest 769b9341d937 7 weeks ago 2.489 MB - $ docker load --input fedora.tar - # […] - Loaded image: fedora:rawhide - # […] - Loaded image: fedora:20 - # […] - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - busybox latest 769b9341d937 7 weeks ago 2.489 MB - fedora rawhide 0d20aec6529d 7 weeks ago 387 MB - fedora 20 58394af37342 7 weeks ago 385.5 MB - fedora heisenbug 58394af37342 7 weeks ago 385.5 MB - fedora latest 58394af37342 7 weeks ago 385.5 MB - -# See also -**docker-save(1)** to save one or more images to a tar archive (streamed to STDOUT by default). - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -July 2015 update by Mary Anthony -June 2016 update by Vincent Demeester diff --git a/vendor/github.com/docker/docker/man/docker-login.1.md b/vendor/github.com/docker/docker/man/docker-login.1.md deleted file mode 100644 index c0d4f79..0000000 --- a/vendor/github.com/docker/docker/man/docker-login.1.md +++ /dev/null @@ -1,53 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-login - Log in to a Docker registry. - -# SYNOPSIS -**docker login** -[**--help**] -[**-p**|**--password**[=*PASSWORD*]] -[**-u**|**--username**[=*USERNAME*]] -[SERVER] - -# DESCRIPTION -Log in to a Docker Registry located on the specified -`SERVER`. You can specify a URL or a `hostname` for the `SERVER` value. If you -do not specify a `SERVER`, the command uses Docker's public registry located at -`https://registry-1.docker.io/` by default. To get a username/password for Docker's public registry, create an account on Docker Hub. - -`docker login` requires user to use `sudo` or be `root`, except when: - -1. connecting to a remote daemon, such as a `docker-machine` provisioned `docker engine`. -2. user is added to the `docker` group. This will impact the security of your system; the `docker` group is `root` equivalent. See [Docker Daemon Attack Surface](https://docs.docker.com/engine/articles/security/#docker-daemon-attack-surface) for details. - -You can log into any public or private repository for which you have -credentials. When you log in, the command stores encoded credentials in -`$HOME/.docker/config.json` on Linux or `%USERPROFILE%/.docker/config.json` on Windows. - -# OPTIONS -**--help** - Print usage statement - -**-p**, **--password**="" - Password - -**-u**, **--username**="" - Username - -# EXAMPLES - -## Login to a registry on your localhost - - # docker login localhost:8080 - -# See also -**docker-logout(1)** to log out from a Docker registry. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -April 2015, updated by Mary Anthony for v2 -November 2015, updated by Sally O'Malley diff --git a/vendor/github.com/docker/docker/man/docker-logout.1.md b/vendor/github.com/docker/docker/man/docker-logout.1.md deleted file mode 100644 index a8a4b7c..0000000 --- a/vendor/github.com/docker/docker/man/docker-logout.1.md +++ /dev/null @@ -1,32 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-logout - Log out from a Docker registry. - -# SYNOPSIS -**docker logout** -[SERVER] - -# DESCRIPTION -Log out of a Docker Registry located on the specified `SERVER`. You can -specify a URL or a `hostname` for the `SERVER` value. If you do not specify a -`SERVER`, the command attempts to log you out of Docker's public registry -located at `https://registry-1.docker.io/` by default. - -# OPTIONS -There are no available options. - -# EXAMPLES - -## Log out from a registry on your localhost - - # docker logout localhost:8080 - -# See also -**docker-login(1)** to log in to a Docker registry server. - -# HISTORY -June 2014, Originally compiled by Daniel, Dao Quang Minh (daniel at nitrous dot io) -July 2014, updated by Sven Dowideit -April 2015, updated by Mary Anthony for v2 diff --git a/vendor/github.com/docker/docker/man/docker-logs.1.md b/vendor/github.com/docker/docker/man/docker-logs.1.md deleted file mode 100644 index e70f796..0000000 --- a/vendor/github.com/docker/docker/man/docker-logs.1.md +++ /dev/null @@ -1,71 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-logs - Fetch the logs of a container - -# SYNOPSIS -**docker logs** -[**-f**|**--follow**] -[**--help**] -[**--since**[=*SINCE*]] -[**-t**|**--timestamps**] -[**--tail**[=*"all"*]] -CONTAINER - -# DESCRIPTION -The **docker logs** command batch-retrieves whatever logs are present for -a container at the time of execution. This does not guarantee execution -order when combined with a docker run (i.e., your run may not have generated -any logs at the time you execute docker logs). - -The **docker logs --follow** command combines commands **docker logs** and -**docker attach**. It will first return all logs from the beginning and -then continue streaming new output from the container's stdout and stderr. - -**Warning**: This command works only for the **json-file** or **journald** -logging drivers. - -# OPTIONS -**--help** - Print usage statement - -**--details**=*true*|*false* - Show extra details provided to logs - -**-f**, **--follow**=*true*|*false* - Follow log output. The default is *false*. - -**--since**="" - Show logs since timestamp - -**-t**, **--timestamps**=*true*|*false* - Show timestamps. The default is *false*. - -**--tail**="*all*" - Output the specified number of lines at the end of logs (defaults to all logs) - -The `--since` option can be Unix timestamps, date formatted timestamps, or Go -duration strings (e.g. `10m`, `1h30m`) computed relative to the client machine's -time. Supported formats for date formatted time stamps include RFC3339Nano, -RFC3339, `2006-01-02T15:04:05`, `2006-01-02T15:04:05.999999999`, -`2006-01-02Z07:00`, and `2006-01-02`. The local timezone on the client will be -used if you do not provide either a `Z` or a `+-00:00` timezone offset at the -end of the timestamp. When providing Unix timestamps enter -seconds[.nanoseconds], where seconds is the number of seconds that have elapsed -since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (aka Unix -epoch or Unix time), and the optional .nanoseconds field is a fraction of a -second no more than nine digits long. You can combine the `--since` option with -either or both of the `--follow` or `--tail` options. - -The `docker logs --details` command will add on extra attributes, such as -environment variables and labels, provided to `--log-opt` when creating the -container. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -July 2014, updated by Sven Dowideit -April 2015, updated by Ahmet Alp Balkan -October 2015, updated by Mike Brown diff --git a/vendor/github.com/docker/docker/man/docker-network-connect.1.md b/vendor/github.com/docker/docker/man/docker-network-connect.1.md deleted file mode 100644 index 096ec77..0000000 --- a/vendor/github.com/docker/docker/man/docker-network-connect.1.md +++ /dev/null @@ -1,66 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% OCT 2015 -# NAME -docker-network-connect - connect a container to a network - -# SYNOPSIS -**docker network connect** -[**--help**] -NETWORK CONTAINER - -# DESCRIPTION - -Connects a container to a network. You can connect a container by name -or by ID. Once connected, the container can communicate with other containers in -the same network. - -```bash -$ docker network connect multi-host-network container1 -``` - -You can also use the `docker run --network=` option to start a container and immediately connect it to a network. - -```bash -$ docker run -itd --network=multi-host-network --ip 172.20.88.22 --ip6 2001:db8::8822 busybox -``` -You can pause, restart, and stop containers that are connected to a network. -A container connects to its configured networks when it runs. - -If specified, the container's IP address(es) is reapplied when a stopped -container is restarted. If the IP address is no longer available, the container -fails to start. One way to guarantee that the IP address is available is -to specify an `--ip-range` when creating the network, and choose the static IP -address(es) from outside that range. This ensures that the IP address is not -given to another container while this container is not on the network. - -```bash -$ docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 multi-host-network -``` - -```bash -$ docker network connect --ip 172.20.128.2 multi-host-network container2 -``` - -To verify the container is connected, use the `docker network inspect` command. Use `docker network disconnect` to remove a container from the network. - -Once connected in network, containers can communicate using only another -container's IP address or name. For `overlay` networks or custom plugins that -support multi-host connectivity, containers connected to the same multi-host -network but launched from different Engines can also communicate in this way. - -You can connect a container to one or more networks. The networks need not be the same type. For example, you can connect a single container bridge and overlay networks. - - -# OPTIONS -**NETWORK** - Specify network name - -**CONTAINER** - Specify container name - -**--help** - Print usage statement - -# HISTORY -OCT 2015, created by Mary Anthony diff --git a/vendor/github.com/docker/docker/man/docker-network-create.1.md b/vendor/github.com/docker/docker/man/docker-network-create.1.md deleted file mode 100644 index 44ce8e1..0000000 --- a/vendor/github.com/docker/docker/man/docker-network-create.1.md +++ /dev/null @@ -1,187 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% OCT 2015 -# NAME -docker-network-create - create a new network - -# SYNOPSIS -**docker network create** -[**--attachable**] -[**--aux-address**=*map[]*] -[**-d**|**--driver**=*DRIVER*] -[**--gateway**=*[]*] -[**--help**] -[**--internal**] -[**--ip-range**=*[]*] -[**--ipam-driver**=*default*] -[**--ipam-opt**=*map[]*] -[**--ipv6**] -[**--label**[=*[]*]] -[**-o**|**--opt**=*map[]*] -[**--subnet**=*[]*] -NETWORK-NAME - -# DESCRIPTION - -Creates a new network. The `DRIVER` accepts `bridge` or `overlay` which are the -built-in network drivers. If you have installed a third party or your own custom -network driver you can specify that `DRIVER` here also. If you don't specify the -`--driver` option, the command automatically creates a `bridge` network for you. -When you install Docker Engine it creates a `bridge` network automatically. This -network corresponds to the `docker0` bridge that Engine has traditionally relied -on. When launch a new container with `docker run` it automatically connects to -this bridge network. You cannot remove this default bridge network but you can -create new ones using the `network create` command. - -```bash -$ docker network create -d bridge my-bridge-network -``` - -Bridge networks are isolated networks on a single Engine installation. If you -want to create a network that spans multiple Docker hosts each running an -Engine, you must create an `overlay` network. Unlike `bridge` networks overlay -networks require some pre-existing conditions before you can create one. These -conditions are: - -* Access to a key-value store. Engine supports Consul, Etcd, and Zookeeper (Distributed store) key-value stores. -* A cluster of hosts with connectivity to the key-value store. -* A properly configured Engine `daemon` on each host in the cluster. - -The `dockerd` options that support the `overlay` network are: - -* `--cluster-store` -* `--cluster-store-opt` -* `--cluster-advertise` - -To read more about these options and how to configure them, see ["*Get started -with multi-host -network*"](https://docs.docker.com/engine/userguide/networking/get-started-overlay/). - -It is also a good idea, though not required, that you install Docker Swarm on to -manage the cluster that makes up your network. Swarm provides sophisticated -discovery and server management that can assist your implementation. - -Once you have prepared the `overlay` network prerequisites you simply choose a -Docker host in the cluster and issue the following to create the network: - -```bash -$ docker network create -d overlay my-multihost-network -``` - -Network names must be unique. The Docker daemon attempts to identify naming -conflicts but this is not guaranteed. It is the user's responsibility to avoid -name conflicts. - -## Connect containers - -When you start a container use the `--network` flag to connect it to a network. -This adds the `busybox` container to the `mynet` network. - -```bash -$ docker run -itd --network=mynet busybox -``` - -If you want to add a container to a network after the container is already -running use the `docker network connect` subcommand. - -You can connect multiple containers to the same network. Once connected, the -containers can communicate using only another container's IP address or name. -For `overlay` networks or custom plugins that support multi-host connectivity, -containers connected to the same multi-host network but launched from different -Engines can also communicate in this way. - -You can disconnect a container from a network using the `docker network -disconnect` command. - -## Specifying advanced options - -When you create a network, Engine creates a non-overlapping subnetwork for the -network by default. This subnetwork is not a subdivision of an existing network. -It is purely for ip-addressing purposes. You can override this default and -specify subnetwork values directly using the `--subnet` option. On a -`bridge` network you can only create a single subnet: - -```bash -$ docker network create -d bridge --subnet=192.168.0.0/16 br0 -``` - -Additionally, you also specify the `--gateway` `--ip-range` and `--aux-address` -options. - -```bash -$ docker network create \ - --driver=bridge \ - --subnet=172.28.0.0/16 \ - --ip-range=172.28.5.0/24 \ - --gateway=172.28.5.254 \ - br0 -``` - -If you omit the `--gateway` flag the Engine selects one for you from inside a -preferred pool. For `overlay` networks and for network driver plugins that -support it you can create multiple subnetworks. - -```bash -$ docker network create -d overlay \ - --subnet=192.168.0.0/16 \ - --subnet=192.170.0.0/16 \ - --gateway=192.168.0.100 \ - --gateway=192.170.0.100 \ - --ip-range=192.168.1.0/24 \ - --aux-address="my-router=192.168.1.5" --aux-address="my-switch=192.168.1.6" \ - --aux-address="my-printer=192.170.1.5" --aux-address="my-nas=192.170.1.6" \ - my-multihost-network -``` - -Be sure that your subnetworks do not overlap. If they do, the network create -fails and Engine returns an error. - -### Network internal mode - -By default, when you connect a container to an `overlay` network, Docker also -connects a bridge network to it to provide external connectivity. If you want -to create an externally isolated `overlay` network, you can specify the -`--internal` option. - -# OPTIONS -**--attachable** - Enable manual container attachment - -**--aux-address**=map[] - Auxiliary IPv4 or IPv6 addresses used by network driver - -**-d**, **--driver**=*DRIVER* - Driver to manage the Network bridge or overlay. The default is bridge. - -**--gateway**=[] - IPv4 or IPv6 Gateway for the master subnet - -**--help** - Print usage - -**--internal** - Restrict external access to the network - -**--ip-range**=[] - Allocate container ip from a sub-range - -**--ipam-driver**=*default* - IP Address Management Driver - -**--ipam-opt**=map[] - Set custom IPAM driver options - -**--ipv6** - Enable IPv6 networking - -**--label**=*label* - Set metadata for a network - -**-o**, **--opt**=map[] - Set custom driver options - -**--subnet**=[] - Subnet in CIDR format that represents a network segment - -# HISTORY -OCT 2015, created by Mary Anthony diff --git a/vendor/github.com/docker/docker/man/docker-network-disconnect.1.md b/vendor/github.com/docker/docker/man/docker-network-disconnect.1.md deleted file mode 100644 index 09bcac5..0000000 --- a/vendor/github.com/docker/docker/man/docker-network-disconnect.1.md +++ /dev/null @@ -1,36 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% OCT 2015 -# NAME -docker-network-disconnect - disconnect a container from a network - -# SYNOPSIS -**docker network disconnect** -[**--help**] -[**--force**] -NETWORK CONTAINER - -# DESCRIPTION - -Disconnects a container from a network. - -```bash - $ docker network disconnect multi-host-network container1 -``` - - -# OPTIONS -**NETWORK** - Specify network name - -**CONTAINER** - Specify container name - -**--force** - Force the container to disconnect from a network - -**--help** - Print usage statement - -# HISTORY -OCT 2015, created by Mary Anthony diff --git a/vendor/github.com/docker/docker/man/docker-network-inspect.1.md b/vendor/github.com/docker/docker/man/docker-network-inspect.1.md deleted file mode 100644 index f27c98c..0000000 --- a/vendor/github.com/docker/docker/man/docker-network-inspect.1.md +++ /dev/null @@ -1,112 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% OCT 2015 -# NAME -docker-network-inspect - inspect a network - -# SYNOPSIS -**docker network inspect** -[**-f**|**--format**[=*FORMAT*]] -[**--help**] -NETWORK [NETWORK...] - -# DESCRIPTION - -Returns information about one or more networks. By default, this command renders all results in a JSON object. For example, if you connect two containers to the default `bridge` network: - -```bash -$ sudo docker run -itd --name=container1 busybox -f2870c98fd504370fb86e59f32cd0753b1ac9b69b7d80566ffc7192a82b3ed27 - -$ sudo docker run -itd --name=container2 busybox -bda12f8922785d1f160be70736f26c1e331ab8aaf8ed8d56728508f2e2fd4727 -``` - -The `network inspect` command shows the containers, by id, in its -results. You can specify an alternate format to execute a given -template for each result. Go's -[text/template](http://golang.org/pkg/text/template/) package -describes all the details of the format. - -```bash -$ sudo docker network inspect bridge -[ - { - "Name": "bridge", - "Id": "b2b1a2cba717161d984383fd68218cf70bbbd17d328496885f7c921333228b0f", - "Scope": "local", - "Driver": "bridge", - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.17.42.1/16", - "Gateway": "172.17.42.1" - } - ] - }, - "Internal": false, - "Containers": { - "bda12f8922785d1f160be70736f26c1e331ab8aaf8ed8d56728508f2e2fd4727": { - "Name": "container2", - "EndpointID": "0aebb8fcd2b282abe1365979536f21ee4ceaf3ed56177c628eae9f706e00e019", - "MacAddress": "02:42:ac:11:00:02", - "IPv4Address": "172.17.0.2/16", - "IPv6Address": "" - }, - "f2870c98fd504370fb86e59f32cd0753b1ac9b69b7d80566ffc7192a82b3ed27": { - "Name": "container1", - "EndpointID": "a00676d9c91a96bbe5bcfb34f705387a33d7cc365bac1a29e4e9728df92d10ad", - "MacAddress": "02:42:ac:11:00:01", - "IPv4Address": "172.17.0.1/16", - "IPv6Address": "" - } - }, - "Options": { - "com.docker.network.bridge.default_bridge": "true", - "com.docker.network.bridge.enable_icc": "true", - "com.docker.network.bridge.enable_ip_masquerade": "true", - "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", - "com.docker.network.bridge.name": "docker0", - "com.docker.network.driver.mtu": "1500" - } - } -] -``` - -Returns the information about the user-defined network: - -```bash -$ docker network create simple-network -69568e6336d8c96bbf57869030919f7c69524f71183b44d80948bd3927c87f6a -$ docker network inspect simple-network -[ - { - "Name": "simple-network", - "Id": "69568e6336d8c96bbf57869030919f7c69524f71183b44d80948bd3927c87f6a", - "Scope": "local", - "Driver": "bridge", - "IPAM": { - "Driver": "default", - "Config": [ - { - "Subnet": "172.22.0.0/16", - "Gateway": "172.22.0.1" - } - ] - }, - "Containers": {}, - "Options": {} - } -] -``` - -# OPTIONS -**-f**, **--format**="" - Format the output using the given Go template. - -**--help** - Print usage statement - -# HISTORY -OCT 2015, created by Mary Anthony diff --git a/vendor/github.com/docker/docker/man/docker-network-ls.1.md b/vendor/github.com/docker/docker/man/docker-network-ls.1.md deleted file mode 100644 index f319e66..0000000 --- a/vendor/github.com/docker/docker/man/docker-network-ls.1.md +++ /dev/null @@ -1,188 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% OCT 2015 -# NAME -docker-network-ls - list networks - -# SYNOPSIS -**docker network ls** -[**-f**|**--filter**[=*[]*]] -[**--format**=*"TEMPLATE"*] -[**--no-trunc**[=*true*|*false*]] -[**-q**|**--quiet**[=*true*|*false*]] -[**--help**] - -# DESCRIPTION - -Lists all the networks the Engine `daemon` knows about. This includes the -networks that span across multiple hosts in a cluster, for example: - -```bash - $ docker network ls - NETWORK ID NAME DRIVER SCOPE - 7fca4eb8c647 bridge bridge local - 9f904ee27bf5 none null local - cf03ee007fb4 host host local - 78b03ee04fc4 multi-host overlay swarm -``` - -Use the `--no-trunc` option to display the full network id: - -```bash -$ docker network ls --no-trunc -NETWORK ID NAME DRIVER -18a2866682b85619a026c81b98a5e375bd33e1b0936a26cc497c283d27bae9b3 none null -c288470c46f6c8949c5f7e5099b5b7947b07eabe8d9a27d79a9cbf111adcbf47 host host -7b369448dccbf865d397c8d2be0cda7cf7edc6b0945f77d2529912ae917a0185 bridge bridge -95e74588f40db048e86320c6526440c504650a1ff3e9f7d60a497c4d2163e5bd foo bridge -63d1ff1f77b07ca51070a8c227e962238358bd310bde1529cf62e6c307ade161 dev bridge -``` - -## Filtering - -The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there -is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`). -Multiple filter flags are combined as an `OR` filter. For example, -`-f type=custom -f type=builtin` returns both `custom` and `builtin` networks. - -The currently supported filters are: - -* driver -* id (network's id) -* label (`label=` or `label==`) -* name (network's name) -* type (custom|builtin) - -#### Driver - -The `driver` filter matches networks based on their driver. - -The following example matches networks with the `bridge` driver: - -```bash -$ docker network ls --filter driver=bridge -NETWORK ID NAME DRIVER -db9db329f835 test1 bridge -f6e212da9dfd test2 bridge -``` - -#### ID - -The `id` filter matches on all or part of a network's ID. - -The following filter matches all networks with an ID containing the -`63d1ff1f77b0...` string. - -```bash -$ docker network ls --filter id=63d1ff1f77b07ca51070a8c227e962238358bd310bde1529cf62e6c307ade161 -NETWORK ID NAME DRIVER -63d1ff1f77b0 dev bridge -``` - -You can also filter for a substring in an ID as this shows: - -```bash -$ docker network ls --filter id=95e74588f40d -NETWORK ID NAME DRIVER -95e74588f40d foo bridge - -$ docker network ls --filter id=95e -NETWORK ID NAME DRIVER -95e74588f40d foo bridge -``` - -#### Label - -The `label` filter matches networks based on the presence of a `label` alone or a `label` and a -value. - -The following filter matches networks with the `usage` label regardless of its value. - -```bash -$ docker network ls -f "label=usage" -NETWORK ID NAME DRIVER -db9db329f835 test1 bridge -f6e212da9dfd test2 bridge -``` - -The following filter matches networks with the `usage` label with the `prod` value. - -```bash -$ docker network ls -f "label=usage=prod" -NETWORK ID NAME DRIVER -f6e212da9dfd test2 bridge -``` - -#### Name - -The `name` filter matches on all or part of a network's name. - -The following filter matches all networks with a name containing the `foobar` string. - -```bash -$ docker network ls --filter name=foobar -NETWORK ID NAME DRIVER -06e7eef0a170 foobar bridge -``` - -You can also filter for a substring in a name as this shows: - -```bash -$ docker network ls --filter name=foo -NETWORK ID NAME DRIVER -95e74588f40d foo bridge -06e7eef0a170 foobar bridge -``` - -#### Type - -The `type` filter supports two values; `builtin` displays predefined networks -(`bridge`, `none`, `host`), whereas `custom` displays user defined networks. - -The following filter matches all user defined networks: - -```bash -$ docker network ls --filter type=custom -NETWORK ID NAME DRIVER -95e74588f40d foo bridge -63d1ff1f77b0 dev bridge -``` - -By having this flag it allows for batch cleanup. For example, use this filter -to delete all user defined networks: - -```bash -$ docker network rm `docker network ls --filter type=custom -q` -``` - -A warning will be issued when trying to remove a network that has containers -attached. - -# OPTIONS - -**-f**, **--filter**=*[]* - filter output based on conditions provided. - -**--format**="*TEMPLATE*" - Pretty-print networks using a Go template. - Valid placeholders: - .ID - Network ID - .Name - Network name - .Driver - Network driver - .Scope - Network scope (local, global) - .IPv6 - Whether IPv6 is enabled on the network or not - .Internal - Whether the network is internal or not - .Labels - All labels assigned to the network - .Label - Value of a specific label for this network. For example `{{.Label "project.version"}}` - -**--no-trunc**=*true*|*false* - Do not truncate the output - -**-q**, **--quiet**=*true*|*false* - Only display network IDs - -**--help** - Print usage statement - -# HISTORY -OCT 2015, created by Mary Anthony diff --git a/vendor/github.com/docker/docker/man/docker-network-rm.1.md b/vendor/github.com/docker/docker/man/docker-network-rm.1.md deleted file mode 100644 index c094a15..0000000 --- a/vendor/github.com/docker/docker/man/docker-network-rm.1.md +++ /dev/null @@ -1,43 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% OCT 2015 -# NAME -docker-network-rm - remove one or more networks - -# SYNOPSIS -**docker network rm** -[**--help**] -NETWORK [NETWORK...] - -# DESCRIPTION - -Removes one or more networks by name or identifier. To remove a network, -you must first disconnect any containers connected to it. -To remove the network named 'my-network': - -```bash - $ docker network rm my-network -``` - -To delete multiple networks in a single `docker network rm` command, provide -multiple network names or ids. The following example deletes a network with id -`3695c422697f` and a network named `my-network`: - -```bash - $ docker network rm 3695c422697f my-network -``` - -When you specify multiple networks, the command attempts to delete each in turn. -If the deletion of one network fails, the command continues to the next on the -list and tries to delete that. The command reports success or failure for each -deletion. - -# OPTIONS -**NETWORK** - Specify network name or id - -**--help** - Print usage statement - -# HISTORY -OCT 2015, created by Mary Anthony diff --git a/vendor/github.com/docker/docker/man/docker-pause.1.md b/vendor/github.com/docker/docker/man/docker-pause.1.md deleted file mode 100644 index 11eef53..0000000 --- a/vendor/github.com/docker/docker/man/docker-pause.1.md +++ /dev/null @@ -1,32 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-pause - Pause all processes within one or more containers - -# SYNOPSIS -**docker pause** -CONTAINER [CONTAINER...] - -# DESCRIPTION - -The `docker pause` command suspends all processes in the specified containers. -On Linux, this uses the cgroups freezer. Traditionally, when suspending a process -the `SIGSTOP` signal is used, which is observable by the process being suspended. -With the cgroups freezer the process is unaware, and unable to capture, -that it is being suspended, and subsequently resumed. On Windows, only Hyper-V -containers can be paused. - -See the [cgroups freezer documentation] -(https://www.kernel.org/doc/Documentation/cgroup-v1/freezer-subsystem.txt) for -further details. - -# OPTIONS -**--help** - Print usage statement - -# See also -**docker-unpause(1)** to unpause all processes within one or more containers. - -# HISTORY -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-port.1.md b/vendor/github.com/docker/docker/man/docker-port.1.md deleted file mode 100644 index 83e9cf9..0000000 --- a/vendor/github.com/docker/docker/man/docker-port.1.md +++ /dev/null @@ -1,47 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-port - List port mappings for the CONTAINER, or lookup the public-facing port that is NAT-ed to the PRIVATE_PORT - -# SYNOPSIS -**docker port** -[**--help**] -CONTAINER [PRIVATE_PORT[/PROTO]] - -# DESCRIPTION -List port mappings for the CONTAINER, or lookup the public-facing port that is NAT-ed to the PRIVATE_PORT - -# OPTIONS -**--help** - Print usage statement - -# EXAMPLES - - # docker ps - CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES - b650456536c7 busybox:latest top 54 minutes ago Up 54 minutes 0.0.0.0:1234->9876/tcp, 0.0.0.0:4321->7890/tcp test - -## Find out all the ports mapped - - # docker port test - 7890/tcp -> 0.0.0.0:4321 - 9876/tcp -> 0.0.0.0:1234 - -## Find out a specific mapping - - # docker port test 7890/tcp - 0.0.0.0:4321 - - # docker port test 7890 - 0.0.0.0:4321 - -## An example showing error for non-existent mapping - - # docker port test 7890/udp - 2014/06/24 11:53:36 Error: No public port '7890/udp' published for test - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -June 2014, updated by Sven Dowideit -November 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-ps.1.md b/vendor/github.com/docker/docker/man/docker-ps.1.md deleted file mode 100644 index d9aa39f..0000000 --- a/vendor/github.com/docker/docker/man/docker-ps.1.md +++ /dev/null @@ -1,145 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% FEBRUARY 2015 -# NAME -docker-ps - List containers - -# SYNOPSIS -**docker ps** -[**-a**|**--all**] -[**-f**|**--filter**[=*[]*]] -[**--format**=*"TEMPLATE"*] -[**--help**] -[**-l**|**--latest**] -[**-n**[=*-1*]] -[**--no-trunc**] -[**-q**|**--quiet**] -[**-s**|**--size**] - -# DESCRIPTION - -List the containers in the local repository. By default this shows only -the running containers. - -# OPTIONS -**-a**, **--all**=*true*|*false* - Show all containers. Only running containers are shown by default. The default is *false*. - -**-f**, **--filter**=[] - Filter output based on these conditions: - - exited= an exit code of - - label= or label== - - status=(created|restarting|running|paused|exited|dead) - - name= a container's name - - id= a container's ID - - is-task=(true|false) - containers that are a task (part of a service managed by swarm) - - before=(|) - - since=(|) - - ancestor=([:tag]||) - containers created from an image or a descendant. - - volume=(|) - - network=(|) - containers connected to the provided network - - health=(starting|healthy|unhealthy|none) - filters containers based on healthcheck status - -**--format**="*TEMPLATE*" - Pretty-print containers using a Go template. - Valid placeholders: - .ID - Container ID - .Image - Image ID - .Command - Quoted command - .CreatedAt - Time when the container was created. - .RunningFor - Elapsed time since the container was started. - .Ports - Exposed ports. - .Status - Container status. - .Size - Container disk size. - .Names - Container names. - .Labels - All labels assigned to the container. - .Label - Value of a specific label for this container. For example `{{.Label "com.docker.swarm.cpu"}}` - .Mounts - Names of the volumes mounted in this container. - -**--help** - Print usage statement - -**-l**, **--latest**=*true*|*false* - Show only the latest created container (includes all states). The default is *false*. - -**-n**=*-1* - Show n last created containers (includes all states). - -**--no-trunc**=*true*|*false* - Don't truncate output. The default is *false*. - -**-q**, **--quiet**=*true*|*false* - Only display numeric IDs. The default is *false*. - -**-s**, **--size**=*true*|*false* - Display total file sizes. The default is *false*. - -# EXAMPLES -# Display all containers, including non-running - - # docker ps -a - CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES - a87ecb4f327c fedora:20 /bin/sh -c #(nop) MA 20 minutes ago Exit 0 desperate_brattain - 01946d9d34d8 vpavlin/rhel7:latest /bin/sh -c #(nop) MA 33 minutes ago Exit 0 thirsty_bell - c1d3b0166030 acffc0358b9e /bin/sh -c yum -y up 2 weeks ago Exit 1 determined_torvalds - 41d50ecd2f57 fedora:20 /bin/sh -c #(nop) MA 2 weeks ago Exit 0 drunk_pike - -# Display only IDs of all containers, including non-running - - # docker ps -a -q - a87ecb4f327c - 01946d9d34d8 - c1d3b0166030 - 41d50ecd2f57 - -# Display only IDs of all containers that have the name `determined_torvalds` - - # docker ps -a -q --filter=name=determined_torvalds - c1d3b0166030 - -# Display containers with their commands - - # docker ps --format "{{.ID}}: {{.Command}}" - a87ecb4f327c: /bin/sh -c #(nop) MA - 01946d9d34d8: /bin/sh -c #(nop) MA - c1d3b0166030: /bin/sh -c yum -y up - 41d50ecd2f57: /bin/sh -c #(nop) MA - -# Display containers with their labels in a table - - # docker ps --format "table {{.ID}}\t{{.Labels}}" - CONTAINER ID LABELS - a87ecb4f327c com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd - 01946d9d34d8 - c1d3b0166030 com.docker.swarm.node=debian,com.docker.swarm.cpu=6 - 41d50ecd2f57 com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd - -# Display containers with their node label in a table - - # docker ps --format 'table {{.ID}}\t{{(.Label "com.docker.swarm.node")}}' - CONTAINER ID NODE - a87ecb4f327c ubuntu - 01946d9d34d8 - c1d3b0166030 debian - 41d50ecd2f57 fedora - -# Display containers with `remote-volume` mounted - - $ docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}" - CONTAINER ID MOUNTS - 9c3527ed70ce remote-volume - -# Display containers with a volume mounted in `/data` - - $ docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}" - CONTAINER ID MOUNTS - 9c3527ed70ce remote-volume - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -August 2014, updated by Sven Dowideit -November 2014, updated by Sven Dowideit -February 2015, updated by André Martins -October 2016, updated by Josh Horwitz diff --git a/vendor/github.com/docker/docker/man/docker-pull.1.md b/vendor/github.com/docker/docker/man/docker-pull.1.md deleted file mode 100644 index c61d005..0000000 --- a/vendor/github.com/docker/docker/man/docker-pull.1.md +++ /dev/null @@ -1,220 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-pull - Pull an image or a repository from a registry - -# SYNOPSIS -**docker pull** -[**-a**|**--all-tags**] -[**--help**] -NAME[:TAG] | [REGISTRY_HOST[:REGISTRY_PORT]/]NAME[:TAG] - -# DESCRIPTION - -This command pulls down an image or a repository from a registry. If -there is more than one image for a repository (e.g., fedora) then all -images for that repository name can be pulled down including any tags -(see the option **-a** or **--all-tags**). - -If you do not specify a `REGISTRY_HOST`, the command uses Docker's public -registry located at `registry-1.docker.io` by default. - -# OPTIONS -**-a**, **--all-tags**=*true*|*false* - Download all tagged images in the repository. The default is *false*. - -**--help** - Print usage statement - -# EXAMPLES - -### Pull an image from Docker Hub - -To download a particular image, or set of images (i.e., a repository), use -`docker pull`. If no tag is provided, Docker Engine uses the `:latest` tag as a -default. This command pulls the `debian:latest` image: - - $ docker pull debian - - Using default tag: latest - latest: Pulling from library/debian - fdd5d7827f33: Pull complete - a3ed95caeb02: Pull complete - Digest: sha256:e7d38b3517548a1c71e41bffe9c8ae6d6d29546ce46bf62159837aad072c90aa - Status: Downloaded newer image for debian:latest - -Docker images can consist of multiple layers. In the example above, the image -consists of two layers; `fdd5d7827f33` and `a3ed95caeb02`. - -Layers can be reused by images. For example, the `debian:jessie` image shares -both layers with `debian:latest`. Pulling the `debian:jessie` image therefore -only pulls its metadata, but not its layers, because all layers are already -present locally: - - $ docker pull debian:jessie - - jessie: Pulling from library/debian - fdd5d7827f33: Already exists - a3ed95caeb02: Already exists - Digest: sha256:a9c958be96d7d40df920e7041608f2f017af81800ca5ad23e327bc402626b58e - Status: Downloaded newer image for debian:jessie - -To see which images are present locally, use the **docker-images(1)** -command: - - $ docker images - - REPOSITORY TAG IMAGE ID CREATED SIZE - debian jessie f50f9524513f 5 days ago 125.1 MB - debian latest f50f9524513f 5 days ago 125.1 MB - -Docker uses a content-addressable image store, and the image ID is a SHA256 -digest covering the image's configuration and layers. In the example above, -`debian:jessie` and `debian:latest` have the same image ID because they are -actually the *same* image tagged with different names. Because they are the -same image, their layers are stored only once and do not consume extra disk -space. - -For more information about images, layers, and the content-addressable store, -refer to [understand images, containers, and storage drivers](https://docs.docker.com/engine/userguide/storagedriver/imagesandcontainers/) -in the online documentation. - - -## Pull an image by digest (immutable identifier) - -So far, you've pulled images by their name (and "tag"). Using names and tags is -a convenient way to work with images. When using tags, you can `docker pull` an -image again to make sure you have the most up-to-date version of that image. -For example, `docker pull ubuntu:14.04` pulls the latest version of the Ubuntu -14.04 image. - -In some cases you don't want images to be updated to newer versions, but prefer -to use a fixed version of an image. Docker enables you to pull an image by its -*digest*. When pulling an image by digest, you specify *exactly* which version -of an image to pull. Doing so, allows you to "pin" an image to that version, -and guarantee that the image you're using is always the same. - -To know the digest of an image, pull the image first. Let's pull the latest -`ubuntu:14.04` image from Docker Hub: - - $ docker pull ubuntu:14.04 - - 14.04: Pulling from library/ubuntu - 5a132a7e7af1: Pull complete - fd2731e4c50c: Pull complete - 28a2f68d1120: Pull complete - a3ed95caeb02: Pull complete - Digest: sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 - Status: Downloaded newer image for ubuntu:14.04 - -Docker prints the digest of the image after the pull has finished. In the example -above, the digest of the image is: - - sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 - -Docker also prints the digest of an image when *pushing* to a registry. This -may be useful if you want to pin to a version of the image you just pushed. - -A digest takes the place of the tag when pulling an image, for example, to -pull the above image by digest, run the following command: - - $ docker pull ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 - - sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2: Pulling from library/ubuntu - 5a132a7e7af1: Already exists - fd2731e4c50c: Already exists - 28a2f68d1120: Already exists - a3ed95caeb02: Already exists - Digest: sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 - Status: Downloaded newer image for ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 - -Digest can also be used in the `FROM` of a Dockerfile, for example: - - FROM ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2 - MAINTAINER some maintainer - -> **Note**: Using this feature "pins" an image to a specific version in time. -> Docker will therefore not pull updated versions of an image, which may include -> security updates. If you want to pull an updated image, you need to change the -> digest accordingly. - -## Pulling from a different registry - -By default, `docker pull` pulls images from Docker Hub. It is also possible to -manually specify the path of a registry to pull from. For example, if you have -set up a local registry, you can specify its path to pull from it. A registry -path is similar to a URL, but does not contain a protocol specifier (`https://`). - -The following command pulls the `testing/test-image` image from a local registry -listening on port 5000 (`myregistry.local:5000`): - - $ docker pull myregistry.local:5000/testing/test-image - -Registry credentials are managed by **docker-login(1)**. - -Docker uses the `https://` protocol to communicate with a registry, unless the -registry is allowed to be accessed over an insecure connection. Refer to the -[insecure registries](https://docs.docker.com/engine/reference/commandline/daemon/#insecure-registries) -section in the online documentation for more information. - - -## Pull a repository with multiple images - -By default, `docker pull` pulls a *single* image from the registry. A repository -can contain multiple images. To pull all images from a repository, provide the -`-a` (or `--all-tags`) option when using `docker pull`. - -This command pulls all images from the `fedora` repository: - - $ docker pull --all-tags fedora - - Pulling repository fedora - ad57ef8d78d7: Download complete - 105182bb5e8b: Download complete - 511136ea3c5a: Download complete - 73bd853d2ea5: Download complete - .... - - Status: Downloaded newer image for fedora - -After the pull has completed use the `docker images` command to see the -images that were pulled. The example below shows all the `fedora` images -that are present locally: - - $ docker images fedora - - REPOSITORY TAG IMAGE ID CREATED SIZE - fedora rawhide ad57ef8d78d7 5 days ago 359.3 MB - fedora 20 105182bb5e8b 5 days ago 372.7 MB - fedora heisenbug 105182bb5e8b 5 days ago 372.7 MB - fedora latest 105182bb5e8b 5 days ago 372.7 MB - - -## Canceling a pull - -Killing the `docker pull` process, for example by pressing `CTRL-c` while it is -running in a terminal, will terminate the pull operation. - - $ docker pull fedora - - Using default tag: latest - latest: Pulling from library/fedora - a3ed95caeb02: Pulling fs layer - 236608c7b546: Pulling fs layer - ^C - -> **Note**: Technically, the Engine terminates a pull operation when the -> connection between the Docker Engine daemon and the Docker Engine client -> initiating the pull is lost. If the connection with the Engine daemon is -> lost for other reasons than a manual interaction, the pull is also aborted. - - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -August 2014, updated by Sven Dowideit -April 2015, updated by John Willis -April 2015, updated by Mary Anthony for v2 -September 2015, updated by Sally O'Malley diff --git a/vendor/github.com/docker/docker/man/docker-push.1.md b/vendor/github.com/docker/docker/man/docker-push.1.md deleted file mode 100644 index 847e66d..0000000 --- a/vendor/github.com/docker/docker/man/docker-push.1.md +++ /dev/null @@ -1,63 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-push - Push an image or a repository to a registry - -# SYNOPSIS -**docker push** -[**--help**] -NAME[:TAG] | [REGISTRY_HOST[:REGISTRY_PORT]/]NAME[:TAG] - -# DESCRIPTION - -Use `docker push` to share your images to the [Docker Hub](https://hub.docker.com) -registry or to a self-hosted one. - -Refer to **docker-tag(1)** for more information about valid image and tag names. - -Killing the **docker push** process, for example by pressing **CTRL-c** while it -is running in a terminal, terminates the push operation. - -Registry credentials are managed by **docker-login(1)**. - - -# OPTIONS - -**--disable-content-trust** - Skip image verification (default true) - -**--help** - Print usage statement - -# EXAMPLES - -## Pushing a new image to a registry - -First save the new image by finding the container ID (using **docker ps**) -and then committing it to a new image name. Note that only a-z0-9-_. are -allowed when naming images: - - # docker commit c16378f943fe rhel-httpd - -Now, push the image to the registry using the image ID. In this example the -registry is on host named `registry-host` and listening on port `5000`. To do -this, tag the image with the host name or IP address, and the port of the -registry: - - # docker tag rhel-httpd registry-host:5000/myadmin/rhel-httpd - # docker push registry-host:5000/myadmin/rhel-httpd - -Check that this worked by running: - - # docker images - -You should see both `rhel-httpd` and `registry-host:5000/myadmin/rhel-httpd` -listed. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -April 2015, updated by Mary Anthony for v2 -June 2015, updated by Sally O'Malley diff --git a/vendor/github.com/docker/docker/man/docker-rename.1.md b/vendor/github.com/docker/docker/man/docker-rename.1.md deleted file mode 100644 index eaeea5c..0000000 --- a/vendor/github.com/docker/docker/man/docker-rename.1.md +++ /dev/null @@ -1,15 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% OCTOBER 2014 -# NAME -docker-rename - Rename a container - -# SYNOPSIS -**docker rename** -CONTAINER NEW_NAME - -# OPTIONS -There are no available options. - -# DESCRIPTION -Rename a container. Container may be running, paused or stopped. diff --git a/vendor/github.com/docker/docker/man/docker-restart.1.md b/vendor/github.com/docker/docker/man/docker-restart.1.md deleted file mode 100644 index 271c4ee..0000000 --- a/vendor/github.com/docker/docker/man/docker-restart.1.md +++ /dev/null @@ -1,26 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-restart - Restart one or more containers - -# SYNOPSIS -**docker restart** -[**--help**] -[**-t**|**--time**[=*10*]] -CONTAINER [CONTAINER...] - -# DESCRIPTION -Restart each container listed. - -# OPTIONS -**--help** - Print usage statement - -**-t**, **--time**=*10* - Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default is 10 seconds. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-rm.1.md b/vendor/github.com/docker/docker/man/docker-rm.1.md deleted file mode 100644 index 2105288..0000000 --- a/vendor/github.com/docker/docker/man/docker-rm.1.md +++ /dev/null @@ -1,72 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-rm - Remove one or more containers - -# SYNOPSIS -**docker rm** -[**-f**|**--force**] -[**-l**|**--link**] -[**-v**|**--volumes**] -CONTAINER [CONTAINER...] - -# DESCRIPTION - -**docker rm** will remove one or more containers from the host node. The -container name or ID can be used. This does not remove images. You cannot -remove a running container unless you use the **-f** option. To see all -containers on a host use the **docker ps -a** command. - -# OPTIONS -**--help** - Print usage statement - -**-f**, **--force**=*true*|*false* - Force the removal of a running container (uses SIGKILL). The default is *false*. - -**-l**, **--link**=*true*|*false* - Remove the specified link and not the underlying container. The default is *false*. - -**-v**, **--volumes**=*true*|*false* - Remove the volumes associated with the container. The default is *false*. - -# EXAMPLES - -## Removing a container using its ID - -To remove a container using its ID, find either from a **docker ps -a** -command, or use the ID returned from the **docker run** command, or retrieve -it from a file used to store it using the **docker run --cidfile**: - - docker rm abebf7571666 - -## Removing a container using the container name - -The name of the container can be found using the **docker ps -a** -command. The use that name as follows: - - docker rm hopeful_morse - -## Removing a container and all associated volumes - - $ docker rm -v redis - redis - -This command will remove the container and any volumes associated with it. -Note that if a volume was specified with a name, it will not be removed. - - $ docker create -v awesome:/foo -v /bar --name hello redis - hello - $ docker rm -v hello - -In this example, the volume for `/foo` will remain in tact, but the volume for -`/bar` will be removed. The same behavior holds for volumes inherited with -`--volumes-from`. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -July 2014, updated by Sven Dowideit -August 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-rmi.1.md b/vendor/github.com/docker/docker/man/docker-rmi.1.md deleted file mode 100644 index 35bf8aa..0000000 --- a/vendor/github.com/docker/docker/man/docker-rmi.1.md +++ /dev/null @@ -1,42 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-rmi - Remove one or more images - -# SYNOPSIS -**docker rmi** -[**-f**|**--force**] -[**--help**] -[**--no-prune**] -IMAGE [IMAGE...] - -# DESCRIPTION - -Removes one or more images from the host node. This does not remove images from -a registry. You cannot remove an image of a running container unless you use the -**-f** option. To see all images on a host use the **docker images** command. - -# OPTIONS -**-f**, **--force**=*true*|*false* - Force removal of the image. The default is *false*. - -**--help** - Print usage statement - -**--no-prune**=*true*|*false* - Do not delete untagged parents. The default is *false*. - -# EXAMPLES - -## Removing an image - -Here is an example of removing an image: - - docker rmi fedora/httpd - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -April 2015, updated by Mary Anthony for v2 diff --git a/vendor/github.com/docker/docker/man/docker-run.1.md b/vendor/github.com/docker/docker/man/docker-run.1.md deleted file mode 100644 index 8c1018a..0000000 --- a/vendor/github.com/docker/docker/man/docker-run.1.md +++ /dev/null @@ -1,1055 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-run - Run a command in a new container - -# SYNOPSIS -**docker run** -[**-a**|**--attach**[=*[]*]] -[**--add-host**[=*[]*]] -[**--blkio-weight**[=*[BLKIO-WEIGHT]*]] -[**--blkio-weight-device**[=*[]*]] -[**--cpu-shares**[=*0*]] -[**--cap-add**[=*[]*]] -[**--cap-drop**[=*[]*]] -[**--cgroup-parent**[=*CGROUP-PATH*]] -[**--cidfile**[=*CIDFILE*]] -[**--cpu-count**[=*0*]] -[**--cpu-percent**[=*0*]] -[**--cpu-period**[=*0*]] -[**--cpu-quota**[=*0*]] -[**--cpu-rt-period**[=*0*]] -[**--cpu-rt-runtime**[=*0*]] -[**--cpus**[=*0.0*]] -[**--cpuset-cpus**[=*CPUSET-CPUS*]] -[**--cpuset-mems**[=*CPUSET-MEMS*]] -[**-d**|**--detach**] -[**--detach-keys**[=*[]*]] -[**--device**[=*[]*]] -[**--device-read-bps**[=*[]*]] -[**--device-read-iops**[=*[]*]] -[**--device-write-bps**[=*[]*]] -[**--device-write-iops**[=*[]*]] -[**--dns**[=*[]*]] -[**--dns-option**[=*[]*]] -[**--dns-search**[=*[]*]] -[**-e**|**--env**[=*[]*]] -[**--entrypoint**[=*ENTRYPOINT*]] -[**--env-file**[=*[]*]] -[**--expose**[=*[]*]] -[**--group-add**[=*[]*]] -[**-h**|**--hostname**[=*HOSTNAME*]] -[**--help**] -[**--init**] -[**--init-path**[=*[]*]] -[**-i**|**--interactive**] -[**--ip**[=*IPv4-ADDRESS*]] -[**--ip6**[=*IPv6-ADDRESS*]] -[**--ipc**[=*IPC*]] -[**--isolation**[=*default*]] -[**--kernel-memory**[=*KERNEL-MEMORY*]] -[**-l**|**--label**[=*[]*]] -[**--label-file**[=*[]*]] -[**--link**[=*[]*]] -[**--link-local-ip**[=*[]*]] -[**--log-driver**[=*[]*]] -[**--log-opt**[=*[]*]] -[**-m**|**--memory**[=*MEMORY*]] -[**--mac-address**[=*MAC-ADDRESS*]] -[**--memory-reservation**[=*MEMORY-RESERVATION*]] -[**--memory-swap**[=*LIMIT*]] -[**--memory-swappiness**[=*MEMORY-SWAPPINESS*]] -[**--name**[=*NAME*]] -[**--network-alias**[=*[]*]] -[**--network**[=*"bridge"*]] -[**--oom-kill-disable**] -[**--oom-score-adj**[=*0*]] -[**-P**|**--publish-all**] -[**-p**|**--publish**[=*[]*]] -[**--pid**[=*[PID]*]] -[**--userns**[=*[]*]] -[**--pids-limit**[=*PIDS_LIMIT*]] -[**--privileged**] -[**--read-only**] -[**--restart**[=*RESTART*]] -[**--rm**] -[**--security-opt**[=*[]*]] -[**--storage-opt**[=*[]*]] -[**--stop-signal**[=*SIGNAL*]] -[**--stop-timeout**[=*TIMEOUT*]] -[**--shm-size**[=*[]*]] -[**--sig-proxy**[=*true*]] -[**--sysctl**[=*[]*]] -[**-t**|**--tty**] -[**--tmpfs**[=*[CONTAINER-DIR[:]*]] -[**-u**|**--user**[=*USER*]] -[**--ulimit**[=*[]*]] -[**--uts**[=*[]*]] -[**-v**|**--volume**[=*[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]*]] -[**--volume-driver**[=*DRIVER*]] -[**--volumes-from**[=*[]*]] -[**-w**|**--workdir**[=*WORKDIR*]] -IMAGE [COMMAND] [ARG...] - -# DESCRIPTION - -Run a process in a new container. **docker run** starts a process with its own -file system, its own networking, and its own isolated process tree. The IMAGE -which starts the process may define defaults related to the process that will be -run in the container, the networking to expose, and more, but **docker run** -gives final control to the operator or administrator who starts the container -from the image. For that reason **docker run** has more options than any other -Docker command. - -If the IMAGE is not already loaded then **docker run** will pull the IMAGE, and -all image dependencies, from the repository in the same way running **docker -pull** IMAGE, before it starts the container from that image. - -# OPTIONS -**-a**, **--attach**=[] - Attach to STDIN, STDOUT or STDERR. - - In foreground mode (the default when **-d** -is not specified), **docker run** can start the process in the container -and attach the console to the process's standard input, output, and standard -error. It can even pretend to be a TTY (this is what most commandline -executables expect) and pass along signals. The **-a** option can be set for -each of stdin, stdout, and stderr. - -**--add-host**=[] - Add a custom host-to-IP mapping (host:ip) - - Add a line to /etc/hosts. The format is hostname:ip. The **--add-host** -option can be set multiple times. - -**--blkio-weight**=*0* - Block IO weight (relative weight) accepts a weight value between 10 and 1000. - -**--blkio-weight-device**=[] - Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`). - -**--cpu-shares**=*0* - CPU shares (relative weight) - - By default, all containers get the same proportion of CPU cycles. This proportion -can be modified by changing the container's CPU share weighting relative -to the weighting of all other running containers. - -To modify the proportion from the default of 1024, use the **--cpu-shares** -flag to set the weighting to 2 or higher. - -The proportion will only apply when CPU-intensive processes are running. -When tasks in one container are idle, other containers can use the -left-over CPU time. The actual amount of CPU time will vary depending on -the number of containers running on the system. - -For example, consider three containers, one has a cpu-share of 1024 and -two others have a cpu-share setting of 512. When processes in all three -containers attempt to use 100% of CPU, the first container would receive -50% of the total CPU time. If you add a fourth container with a cpu-share -of 1024, the first container only gets 33% of the CPU. The remaining containers -receive 16.5%, 16.5% and 33% of the CPU. - -On a multi-core system, the shares of CPU time are distributed over all CPU -cores. Even if a container is limited to less than 100% of CPU time, it can -use 100% of each individual CPU core. - -For example, consider a system with more than three cores. If you start one -container **{C0}** with **-c=512** running one process, and another container -**{C1}** with **-c=1024** running two processes, this can result in the following -division of CPU shares: - - PID container CPU CPU share - 100 {C0} 0 100% of CPU0 - 101 {C1} 1 100% of CPU1 - 102 {C1} 2 100% of CPU2 - -**--cap-add**=[] - Add Linux capabilities - -**--cap-drop**=[] - Drop Linux capabilities - -**--cgroup-parent**="" - Path to cgroups under which the cgroup for the container will be created. If the path is not absolute, the path is considered to be relative to the cgroups path of the init process. Cgroups will be created if they do not already exist. - -**--cidfile**="" - Write the container ID to the file - -**--cpu-count**=*0* - Limit the number of CPUs available for execution by the container. - - On Windows Server containers, this is approximated as a percentage of total CPU usage. - - On Windows Server containers, the processor resource controls are mutually exclusive, the order of precedence is CPUCount first, then CPUShares, and CPUPercent last. - -**--cpu-percent**=*0* - Limit the percentage of CPU available for execution by a container running on a Windows daemon. - - On Windows Server containers, the processor resource controls are mutually exclusive, the order of precedence is CPUCount first, then CPUShares, and CPUPercent last. - -**--cpu-period**=*0* - Limit the CPU CFS (Completely Fair Scheduler) period - - Limit the container's CPU usage. This flag tell the kernel to restrict the container's CPU usage to the period you specify. - -**--cpuset-cpus**="" - CPUs in which to allow execution (0-3, 0,1) - -**--cpuset-mems**="" - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. - - If you have four memory nodes on your system (0-3), use `--cpuset-mems=0,1` -then processes in your Docker container will only use memory from the first -two memory nodes. - -**--cpu-quota**=*0* - Limit the CPU CFS (Completely Fair Scheduler) quota - - Limit the container's CPU usage. By default, containers run with the full -CPU resource. This flag tell the kernel to restrict the container's CPU usage -to the quota you specify. - -**--cpu-rt-period**=0 - Limit the CPU real-time period in microseconds - - Limit the container's Real Time CPU usage. This flag tell the kernel to restrict the container's Real Time CPU usage to the period you specify. - -**--cpu-rt-runtime**=0 - Limit the CPU real-time runtime in microseconds - - Limit the containers Real Time CPU usage. This flag tells the kernel to limit the amount of time in a given CPU period Real Time tasks may consume. Ex: - Period of 1,000,000us and Runtime of 950,000us means that this container could consume 95% of available CPU and leave the remaining 5% to normal priority tasks. - - The sum of all runtimes across containers cannot exceed the amount allotted to the parent cgroup. - -**--cpus**=0.0 - Number of CPUs. The default is *0.0* which means no limit. - -**-d**, **--detach**=*true*|*false* - Detached mode: run the container in the background and print the new container ID. The default is *false*. - - At any time you can run **docker ps** in -the other shell to view a list of the running containers. You can reattach to a -detached container with **docker attach**. If you choose to run a container in -the detached mode, then you cannot use the **-rm** option. - - When attached in the tty mode, you can detach from the container (and leave it -running) using a configurable key sequence. The default sequence is `CTRL-p CTRL-q`. -You configure the key sequence using the **--detach-keys** option or a configuration file. -See **config-json(5)** for documentation on using a configuration file. - -**--detach-keys**="" - Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-` where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. - -**--device**=[] - Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm) - -**--device-read-bps**=[] - Limit read rate from a device (e.g. --device-read-bps=/dev/sda:1mb) - -**--device-read-iops**=[] - Limit read rate from a device (e.g. --device-read-iops=/dev/sda:1000) - -**--device-write-bps**=[] - Limit write rate to a device (e.g. --device-write-bps=/dev/sda:1mb) - -**--device-write-iops**=[] - Limit write rate to a device (e.g. --device-write-iops=/dev/sda:1000) - -**--dns-search**=[] - Set custom DNS search domains (Use --dns-search=. if you don't wish to set the search domain) - -**--dns-option**=[] - Set custom DNS options - -**--dns**=[] - Set custom DNS servers - - This option can be used to override the DNS -configuration passed to the container. Typically this is necessary when the -host DNS configuration is invalid for the container (e.g., 127.0.0.1). When this -is the case the **--dns** flags is necessary for every run. - -**-e**, **--env**=[] - Set environment variables - - This option allows you to specify arbitrary -environment variables that are available for the process that will be launched -inside of the container. - -**--entrypoint**="" - Overwrite the default ENTRYPOINT of the image - - This option allows you to overwrite the default entrypoint of the image that -is set in the Dockerfile. The ENTRYPOINT of an image is similar to a COMMAND -because it specifies what executable to run when the container starts, but it is -(purposely) more difficult to override. The ENTRYPOINT gives a container its -default nature or behavior, so that when you set an ENTRYPOINT you can run the -container as if it were that binary, complete with default options, and you can -pass in more options via the COMMAND. But, sometimes an operator may want to run -something else inside the container, so you can override the default ENTRYPOINT -at runtime by using a **--entrypoint** and a string to specify the new -ENTRYPOINT. - -**--env-file**=[] - Read in a line delimited file of environment variables - -**--expose**=[] - Expose a port, or a range of ports (e.g. --expose=3300-3310) informs Docker -that the container listens on the specified network ports at runtime. Docker -uses this information to interconnect containers using links and to set up port -redirection on the host system. - -**--group-add**=[] - Add additional groups to run as - -**-h**, **--hostname**="" - Container host name - - Sets the container host name that is available inside the container. - -**--help** - Print usage statement - -**--init** - Run an init inside the container that forwards signals and reaps processes - -**--init-path**="" - Path to the docker-init binary - -**-i**, **--interactive**=*true*|*false* - Keep STDIN open even if not attached. The default is *false*. - - When set to true, keep stdin open even if not attached. The default is false. - -**--ip**="" - Sets the container's interface IPv4 address (e.g. 172.23.0.9) - - It can only be used in conjunction with **--network** for user-defined networks - -**--ip6**="" - Sets the container's interface IPv6 address (e.g. 2001:db8::1b99) - - It can only be used in conjunction with **--network** for user-defined networks - -**--ipc**="" - Default is to create a private IPC namespace (POSIX SysV IPC) for the container - 'container:': reuses another container shared memory, semaphores and message queues - 'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure. - -**--isolation**="*default*" - Isolation specifies the type of isolation technology used by containers. Note -that the default on Windows server is `process`, and the default on Windows client -is `hyperv`. Linux only supports `default`. - -**-l**, **--label**=[] - Set metadata on the container (e.g., --label com.example.key=value) - -**--kernel-memory**="" - Kernel memory limit (format: `[]`, where unit = b, k, m or g) - - Constrains the kernel memory available to a container. If a limit of 0 -is specified (not using `--kernel-memory`), the container's kernel memory -is not limited. If you specify a limit, it may be rounded up to a multiple -of the operating system's page size and the value can be very large, -millions of trillions. - -**--label-file**=[] - Read in a line delimited file of labels - -**--link**=[] - Add link to another container in the form of :alias or just -in which case the alias will match the name - - If the operator -uses **--link** when starting the new client container, then the client -container can access the exposed port via a private networking interface. Docker -will set some environment variables in the client container to help indicate -which interface and port to use. - -**--link-local-ip**=[] - Add one or more link-local IPv4/IPv6 addresses to the container's interface - -**--log-driver**="*json-file*|*syslog*|*journald*|*gelf*|*fluentd*|*awslogs*|*splunk*|*etwlogs*|*gcplogs*|*none*" - Logging driver for the container. Default is defined by daemon `--log-driver` flag. - **Warning**: the `docker logs` command works only for the `json-file` and - `journald` logging drivers. - -**--log-opt**=[] - Logging driver specific options. - -**-m**, **--memory**="" - Memory limit (format: [], where unit = b, k, m or g) - - Allows you to constrain the memory available to a container. If the host -supports swap memory, then the **-m** memory setting can be larger than physical -RAM. If a limit of 0 is specified (not using **-m**), the container's memory is -not limited. The actual limit may be rounded up to a multiple of the operating -system's page size (the value would be very large, that's millions of trillions). - -**--memory-reservation**="" - Memory soft limit (format: [], where unit = b, k, m or g) - - After setting memory reservation, when the system detects memory contention -or low memory, containers are forced to restrict their consumption to their -reservation. So you should always set the value below **--memory**, otherwise the -hard limit will take precedence. By default, memory reservation will be the same -as memory limit. - -**--memory-swap**="LIMIT" - A limit value equal to memory plus swap. Must be used with the **-m** -(**--memory**) flag. The swap `LIMIT` should always be larger than **-m** -(**--memory**) value. By default, the swap `LIMIT` will be set to double -the value of --memory. - - The format of `LIMIT` is `[]`. Unit can be `b` (bytes), -`k` (kilobytes), `m` (megabytes), or `g` (gigabytes). If you don't specify a -unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap. - -**--mac-address**="" - Container MAC address (e.g. 92:d0:c6:0a:29:33) - - Remember that the MAC address in an Ethernet network must be unique. -The IPv6 link-local address will be based on the device's MAC address -according to RFC4862. - -**--name**="" - Assign a name to the container - - The operator can identify a container in three ways: - UUID long identifier (“f78375b1c487e03c9438c729345e54db9d20cfa2ac1fc3494b6eb60872e74778”) - UUID short identifier (“f78375b1c487”) - Name (“jonah”) - - The UUID identifiers come from the Docker daemon, and if a name is not assigned -to the container with **--name** then the daemon will also generate a random -string name. The name is useful when defining links (see **--link**) (or any -other place you need to identify a container). This works for both background -and foreground Docker containers. - -**--network**="*bridge*" - Set the Network mode for the container - 'bridge': create a network stack on the default Docker bridge - 'none': no networking - 'container:': reuse another container's network stack - 'host': use the Docker host network stack. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure. - '|': connect to a user-defined network - -**--network-alias**=[] - Add network-scoped alias for the container - -**--oom-kill-disable**=*true*|*false* - Whether to disable OOM Killer for the container or not. - -**--oom-score-adj**="" - Tune the host's OOM preferences for containers (accepts -1000 to 1000) - -**-P**, **--publish-all**=*true*|*false* - Publish all exposed ports to random ports on the host interfaces. The default is *false*. - - When set to true publish all exposed ports to the host interfaces. The -default is false. If the operator uses -P (or -p) then Docker will make the -exposed port accessible on the host and the ports will be available to any -client that can reach the host. When using -P, Docker will bind any exposed -port to a random port on the host within an *ephemeral port range* defined by -`/proc/sys/net/ipv4/ip_local_port_range`. To find the mapping between the host -ports and the exposed ports, use `docker port`. - -**-p**, **--publish**=[] - Publish a container's port, or range of ports, to the host. - - Format: `ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort` -Both hostPort and containerPort can be specified as a range of ports. -When specifying ranges for both, the number of container ports in the range must match the number of host ports in the range. -(e.g., `docker run -p 1234-1236:1222-1224 --name thisWorks -t busybox` -but not `docker run -p 1230-1236:1230-1240 --name RangeContainerPortsBiggerThanRangeHostPorts -t busybox`) -With ip: `docker run -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT --name CONTAINER -t someimage` -Use `docker port` to see the actual mapping: `docker port CONTAINER $CONTAINERPORT` - -**--pid**="" - Set the PID mode for the container - Default is to create a private PID namespace for the container - 'container:': join another container's PID namespace - 'host': use the host's PID namespace for the container. Note: the host mode gives the container full access to local PID and is therefore considered insecure. - -**--userns**="" - Set the usernamespace mode for the container when `userns-remap` option is enabled. - **host**: use the host usernamespace and enable all privileged options (e.g., `pid=host` or `--privileged`). - -**--pids-limit**="" - Tune the container's pids limit. Set `-1` to have unlimited pids for the container. - -**--uts**=*host* - Set the UTS mode for the container - **host**: use the host's UTS namespace inside the container. - Note: the host mode gives the container access to changing the host's hostname and is therefore considered insecure. - -**--privileged**=*true*|*false* - Give extended privileges to this container. The default is *false*. - - By default, Docker containers are -“unprivileged” (=false) and cannot, for example, run a Docker daemon inside the -Docker container. This is because by default a container is not allowed to -access any devices. A “privileged” container is given access to all devices. - - When the operator executes **docker run --privileged**, Docker will enable access -to all devices on the host as well as set some configuration in AppArmor to -allow the container nearly all the same access to the host as processes running -outside of a container on the host. - -**--read-only**=*true*|*false* - Mount the container's root filesystem as read only. - - By default a container will have its root filesystem writable allowing processes -to write files anywhere. By specifying the `--read-only` flag the container will have -its root filesystem mounted as read only prohibiting any writes. - -**--restart**="*no*" - Restart policy to apply when a container exits (no, on-failure[:max-retry], always, unless-stopped). - -**--rm**=*true*|*false* - Automatically remove the container when it exits. The default is *false*. - `--rm` flag can work together with `-d`, and auto-removal will be done on daemon side. Note that it's -incompatible with any restart policy other than `none`. - -**--security-opt**=[] - Security Options - - "label=user:USER" : Set the label user for the container - "label=role:ROLE" : Set the label role for the container - "label=type:TYPE" : Set the label type for the container - "label=level:LEVEL" : Set the label level for the container - "label=disable" : Turn off label confinement for the container - "no-new-privileges" : Disable container processes from gaining additional privileges - - "seccomp=unconfined" : Turn off seccomp confinement for the container - "seccomp=profile.json : White listed syscalls seccomp Json file to be used as a seccomp filter - - "apparmor=unconfined" : Turn off apparmor confinement for the container - "apparmor=your-profile" : Set the apparmor confinement profile for the container - -**--storage-opt**=[] - Storage driver options per container - - $ docker run -it --storage-opt size=120G fedora /bin/bash - - This (size) will allow to set the container rootfs size to 120G at creation time. - This option is only available for the `devicemapper`, `btrfs`, `overlay2` and `zfs` graph drivers. - For the `devicemapper`, `btrfs` and `zfs` storage drivers, user cannot pass a size less than the Default BaseFS Size. - For the `overlay2` storage driver, the size option is only available if the backing fs is `xfs` and mounted with the `pquota` mount option. - Under these conditions, user can pass any size less then the backing fs size. - -**--stop-signal**=*SIGTERM* - Signal to stop a container. Default is SIGTERM. - -**--stop-timeout**=*10* - Timeout (in seconds) to stop a container. Default is 10. - -**--shm-size**="" - Size of `/dev/shm`. The format is ``. - `number` must be greater than `0`. Unit is optional and can be `b` (bytes), `k` (kilobytes), `m`(megabytes), or `g` (gigabytes). - If you omit the unit, the system uses bytes. If you omit the size entirely, the system uses `64m`. - -**--sysctl**=SYSCTL - Configure namespaced kernel parameters at runtime - - IPC Namespace - current sysctls allowed: - - kernel.msgmax, kernel.msgmnb, kernel.msgmni, kernel.sem, kernel.shmall, kernel.shmmax, kernel.shmmni, kernel.shm_rmid_forced - Sysctls beginning with fs.mqueue.* - - If you use the `--ipc=host` option these sysctls will not be allowed. - - Network Namespace - current sysctls allowed: - Sysctls beginning with net.* - - If you use the `--network=host` option these sysctls will not be allowed. - -**--sig-proxy**=*true*|*false* - Proxy received signals to the process (non-TTY mode only). SIGCHLD, SIGSTOP, and SIGKILL are not proxied. The default is *true*. - -**--memory-swappiness**="" - Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. - -**-t**, **--tty**=*true*|*false* - Allocate a pseudo-TTY. The default is *false*. - - When set to true Docker can allocate a pseudo-tty and attach to the standard -input of any container. This can be used, for example, to run a throwaway -interactive shell. The default is false. - -The **-t** option is incompatible with a redirection of the docker client -standard input. - -**--tmpfs**=[] Create a tmpfs mount - - Mount a temporary filesystem (`tmpfs`) mount into a container, for example: - - $ docker run -d --tmpfs /tmp:rw,size=787448k,mode=1777 my_image - - This command mounts a `tmpfs` at `/tmp` within the container. The supported mount -options are the same as the Linux default `mount` flags. If you do not specify -any options, the systems uses the following options: -`rw,noexec,nosuid,nodev,size=65536k`. - -**-u**, **--user**="" - Sets the username or UID used and optionally the groupname or GID for the specified command. - - The followings examples are all valid: - --user [user | user:group | uid | uid:gid | user:gid | uid:group ] - - Without this argument the command will be run as root in the container. - -**--ulimit**=[] - Ulimit options - -**-v**|**--volume**[=*[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]*] - Create a bind mount. If you specify, ` -v /HOST-DIR:/CONTAINER-DIR`, Docker - bind mounts `/HOST-DIR` in the host to `/CONTAINER-DIR` in the Docker - container. If 'HOST-DIR' is omitted, Docker automatically creates the new - volume on the host. The `OPTIONS` are a comma delimited list and can be: - - * [rw|ro] - * [z|Z] - * [`[r]shared`|`[r]slave`|`[r]private`] - * [nocopy] - -The `CONTAINER-DIR` must be an absolute path such as `/src/docs`. The `HOST-DIR` -can be an absolute path or a `name` value. A `name` value must start with an -alphanumeric character, followed by `a-z0-9`, `_` (underscore), `.` (period) or -`-` (hyphen). An absolute path starts with a `/` (forward slash). - -If you supply a `HOST-DIR` that is an absolute path, Docker bind-mounts to the -path you specify. If you supply a `name`, Docker creates a named volume by that -`name`. For example, you can specify either `/foo` or `foo` for a `HOST-DIR` -value. If you supply the `/foo` value, Docker creates a bind-mount. If you -supply the `foo` specification, Docker creates a named volume. - -You can specify multiple **-v** options to mount one or more mounts to a -container. To use these same mounts in other containers, specify the -**--volumes-from** option also. - -You can add `:ro` or `:rw` suffix to a volume to mount it read-only or -read-write mode, respectively. By default, the volumes are mounted read-write. -See examples. - -Labeling systems like SELinux require that proper labels are placed on volume -content mounted into a container. Without a label, the security system might -prevent the processes running inside the container from using the content. By -default, Docker does not change the labels set by the OS. - -To change a label in the container context, you can add either of two suffixes -`:z` or `:Z` to the volume mount. These suffixes tell Docker to relabel file -objects on the shared volumes. The `z` option tells Docker that two containers -share the volume content. As a result, Docker labels the content with a shared -content label. Shared volume labels allow all containers to read/write content. -The `Z` option tells Docker to label the content with a private unshared label. -Only the current container can use a private volume. - -By default bind mounted volumes are `private`. That means any mounts done -inside container will not be visible on host and vice-a-versa. One can change -this behavior by specifying a volume mount propagation property. Making a -volume `shared` mounts done under that volume inside container will be -visible on host and vice-a-versa. Making a volume `slave` enables only one -way mount propagation and that is mounts done on host under that volume -will be visible inside container but not the other way around. - -To control mount propagation property of volume one can use `:[r]shared`, -`:[r]slave` or `:[r]private` propagation flag. Propagation property can -be specified only for bind mounted volumes and not for internal volumes or -named volumes. For mount propagation to work source mount point (mount point -where source dir is mounted on) has to have right propagation properties. For -shared volumes, source mount point has to be shared. And for slave volumes, -source mount has to be either shared or slave. - -Use `df ` to figure out the source mount and then use -`findmnt -o TARGET,PROPAGATION ` to figure out propagation -properties of source mount. If `findmnt` utility is not available, then one -can look at mount entry for source mount point in `/proc/self/mountinfo`. Look -at `optional fields` and see if any propagaion properties are specified. -`shared:X` means mount is `shared`, `master:X` means mount is `slave` and if -nothing is there that means mount is `private`. - -To change propagation properties of a mount point use `mount` command. For -example, if one wants to bind mount source directory `/foo` one can do -`mount --bind /foo /foo` and `mount --make-private --make-shared /foo`. This -will convert /foo into a `shared` mount point. Alternatively one can directly -change propagation properties of source mount. Say `/` is source mount for -`/foo`, then use `mount --make-shared /` to convert `/` into a `shared` mount. - -> **Note**: -> When using systemd to manage the Docker daemon's start and stop, in the systemd -> unit file there is an option to control mount propagation for the Docker daemon -> itself, called `MountFlags`. The value of this setting may cause Docker to not -> see mount propagation changes made on the mount point. For example, if this value -> is `slave`, you may not be able to use the `shared` or `rshared` propagation on -> a volume. - -To disable automatic copying of data from the container path to the volume, use -the `nocopy` flag. The `nocopy` flag can be set on bind mounts and named volumes. - -**--volume-driver**="" - Container's volume driver. This driver creates volumes specified either from - a Dockerfile's `VOLUME` instruction or from the `docker run -v` flag. - See **docker-volume-create(1)** for full details. - -**--volumes-from**=[] - Mount volumes from the specified container(s) - - Mounts already mounted volumes from a source container onto another - container. You must supply the source's container-id. To share - a volume, use the **--volumes-from** option when running - the target container. You can share volumes even if the source container - is not running. - - By default, Docker mounts the volumes in the same mode (read-write or - read-only) as it is mounted in the source container. Optionally, you - can change this by suffixing the container-id with either the `:ro` or - `:rw ` keyword. - - If the location of the volume from the source container overlaps with - data residing on a target container, then the volume hides - that data on the target. - -**-w**, **--workdir**="" - Working directory inside the container - - The default working directory for -running binaries within a container is the root directory (/). The developer can -set a different default with the Dockerfile WORKDIR instruction. The operator -can override the working directory by using the **-w** option. - -# Exit Status - -The exit code from `docker run` gives information about why the container -failed to run or why it exited. When `docker run` exits with a non-zero code, -the exit codes follow the `chroot` standard, see below: - -**_125_** if the error is with Docker daemon **_itself_** - - $ docker run --foo busybox; echo $? - # flag provided but not defined: --foo - See 'docker run --help'. - 125 - -**_126_** if the **_contained command_** cannot be invoked - - $ docker run busybox /etc; echo $? - # exec: "/etc": permission denied - docker: Error response from daemon: Contained command could not be invoked - 126 - -**_127_** if the **_contained command_** cannot be found - - $ docker run busybox foo; echo $? - # exec: "foo": executable file not found in $PATH - docker: Error response from daemon: Contained command not found or does not exist - 127 - -**_Exit code_** of **_contained command_** otherwise - - $ docker run busybox /bin/sh -c 'exit 3' - # 3 - -# EXAMPLES - -## Running container in read-only mode - -During container image development, containers often need to write to the image -content. Installing packages into /usr, for example. In production, -applications seldom need to write to the image. Container applications write -to volumes if they need to write to file systems at all. Applications can be -made more secure by running them in read-only mode using the --read-only switch. -This protects the containers image from modification. Read only containers may -still need to write temporary data. The best way to handle this is to mount -tmpfs directories on /run and /tmp. - - # docker run --read-only --tmpfs /run --tmpfs /tmp -i -t fedora /bin/bash - -## Exposing log messages from the container to the host's log - -If you want messages that are logged in your container to show up in the host's -syslog/journal then you should bind mount the /dev/log directory as follows. - - # docker run -v /dev/log:/dev/log -i -t fedora /bin/bash - -From inside the container you can test this by sending a message to the log. - - (bash)# logger "Hello from my container" - -Then exit and check the journal. - - # exit - - # journalctl -b | grep Hello - -This should list the message sent to logger. - -## Attaching to one or more from STDIN, STDOUT, STDERR - -If you do not specify -a then Docker will attach everything (stdin,stdout,stderr) -. You can specify to which of the three standard streams (stdin, stdout, stderr) -you'd like to connect instead, as in: - - # docker run -a stdin -a stdout -i -t fedora /bin/bash - -## Sharing IPC between containers - -Using shm_server.c available here: https://www.cs.cf.ac.uk/Dave/C/node27.html - -Testing `--ipc=host` mode: - -Host shows a shared memory segment with 7 pids attached, happens to be from httpd: - -``` - $ sudo ipcs -m - - ------ Shared Memory Segments -------- - key shmid owner perms bytes nattch status - 0x01128e25 0 root 600 1000 7 -``` - -Now run a regular container, and it correctly does NOT see the shared memory segment from the host: - -``` - $ docker run -it shm ipcs -m - - ------ Shared Memory Segments -------- - key shmid owner perms bytes nattch status -``` - -Run a container with the new `--ipc=host` option, and it now sees the shared memory segment from the host httpd: - - ``` - $ docker run -it --ipc=host shm ipcs -m - - ------ Shared Memory Segments -------- - key shmid owner perms bytes nattch status - 0x01128e25 0 root 600 1000 7 -``` -Testing `--ipc=container:CONTAINERID` mode: - -Start a container with a program to create a shared memory segment: -``` - $ docker run -it shm bash - $ sudo shm/shm_server & - $ sudo ipcs -m - - ------ Shared Memory Segments -------- - key shmid owner perms bytes nattch status - 0x0000162e 0 root 666 27 1 -``` -Create a 2nd container correctly shows no shared memory segment from 1st container: -``` - $ docker run shm ipcs -m - - ------ Shared Memory Segments -------- - key shmid owner perms bytes nattch status -``` - -Create a 3rd container using the new --ipc=container:CONTAINERID option, now it shows the shared memory segment from the first: - -``` - $ docker run -it --ipc=container:ed735b2264ac shm ipcs -m - $ sudo ipcs -m - - ------ Shared Memory Segments -------- - key shmid owner perms bytes nattch status - 0x0000162e 0 root 666 27 1 -``` - -## Linking Containers - -> **Note**: This section describes linking between containers on the -> default (bridge) network, also known as "legacy links". Using `--link` -> on user-defined networks uses the DNS-based discovery, which does not add -> entries to `/etc/hosts`, and does not set environment variables for -> discovery. - -The link feature allows multiple containers to communicate with each other. For -example, a container whose Dockerfile has exposed port 80 can be run and named -as follows: - - # docker run --name=link-test -d -i -t fedora/httpd - -A second container, in this case called linker, can communicate with the httpd -container, named link-test, by running with the **--link=:** - - # docker run -t -i --link=link-test:lt --name=linker fedora /bin/bash - -Now the container linker is linked to container link-test with the alias lt. -Running the **env** command in the linker container shows environment variables - with the LT (alias) context (**LT_**) - - # env - HOSTNAME=668231cb0978 - TERM=xterm - LT_PORT_80_TCP=tcp://172.17.0.3:80 - LT_PORT_80_TCP_PORT=80 - LT_PORT_80_TCP_PROTO=tcp - LT_PORT=tcp://172.17.0.3:80 - PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - PWD=/ - LT_NAME=/linker/lt - SHLVL=1 - HOME=/ - LT_PORT_80_TCP_ADDR=172.17.0.3 - _=/usr/bin/env - -When linking two containers Docker will use the exposed ports of the container -to create a secure tunnel for the parent to access. - -If a container is connected to the default bridge network and `linked` -with other containers, then the container's `/etc/hosts` file is updated -with the linked container's name. - -> **Note** Since Docker may live update the container's `/etc/hosts` file, there -may be situations when processes inside the container can end up reading an -empty or incomplete `/etc/hosts` file. In most cases, retrying the read again -should fix the problem. - - -## Mapping Ports for External Usage - -The exposed port of an application can be mapped to a host port using the **-p** -flag. For example, an httpd port 80 can be mapped to the host port 8080 using the -following: - - # docker run -p 8080:80 -d -i -t fedora/httpd - -## Creating and Mounting a Data Volume Container - -Many applications require the sharing of persistent data across several -containers. Docker allows you to create a Data Volume Container that other -containers can mount from. For example, create a named container that contains -directories /var/volume1 and /tmp/volume2. The image will need to contain these -directories so a couple of RUN mkdir instructions might be required for you -fedora-data image: - - # docker run --name=data -v /var/volume1 -v /tmp/volume2 -i -t fedora-data true - # docker run --volumes-from=data --name=fedora-container1 -i -t fedora bash - -Multiple --volumes-from parameters will bring together multiple data volumes from -multiple containers. And it's possible to mount the volumes that came from the -DATA container in yet another container via the fedora-container1 intermediary -container, allowing to abstract the actual data source from users of that data: - - # docker run --volumes-from=fedora-container1 --name=fedora-container2 -i -t fedora bash - -## Mounting External Volumes - -To mount a host directory as a container volume, specify the absolute path to -the directory and the absolute path for the container directory separated by a -colon: - - # docker run -v /var/db:/data1 -i -t fedora bash - -When using SELinux, be aware that the host has no knowledge of container SELinux -policy. Therefore, in the above example, if SELinux policy is enforced, the -`/var/db` directory is not writable to the container. A "Permission Denied" -message will occur and an avc: message in the host's syslog. - - -To work around this, at time of writing this man page, the following command -needs to be run in order for the proper SELinux policy type label to be attached -to the host directory: - - # chcon -Rt svirt_sandbox_file_t /var/db - - -Now, writing to the /data1 volume in the container will be allowed and the -changes will also be reflected on the host in /var/db. - -## Using alternative security labeling - -You can override the default labeling scheme for each container by specifying -the `--security-opt` flag. For example, you can specify the MCS/MLS level, a -requirement for MLS systems. Specifying the level in the following command -allows you to share the same content between containers. - - # docker run --security-opt label=level:s0:c100,c200 -i -t fedora bash - -An MLS example might be: - - # docker run --security-opt label=level:TopSecret -i -t rhel7 bash - -To disable the security labeling for this container versus running with the -`--permissive` flag, use the following command: - - # docker run --security-opt label=disable -i -t fedora bash - -If you want a tighter security policy on the processes within a container, -you can specify an alternate type for the container. You could run a container -that is only allowed to listen on Apache ports by executing the following -command: - - # docker run --security-opt label=type:svirt_apache_t -i -t centos bash - -Note: - -You would have to write policy defining a `svirt_apache_t` type. - -## Setting device weight - -If you want to set `/dev/sda` device weight to `200`, you can specify the device -weight by `--blkio-weight-device` flag. Use the following command: - - # docker run -it --blkio-weight-device "/dev/sda:200" ubuntu - -## Specify isolation technology for container (--isolation) - -This option is useful in situations where you are running Docker containers on -Microsoft Windows. The `--isolation ` option sets a container's isolation -technology. On Linux, the only supported is the `default` option which uses -Linux namespaces. These two commands are equivalent on Linux: - -``` -$ docker run -d busybox top -$ docker run -d --isolation default busybox top -``` - -On Microsoft Windows, can take any of these values: - -* `default`: Use the value specified by the Docker daemon's `--exec-opt` . If the `daemon` does not specify an isolation technology, Microsoft Windows uses `process` as its default value. -* `process`: Namespace isolation only. -* `hyperv`: Hyper-V hypervisor partition-based isolation. - -In practice, when running on Microsoft Windows without a `daemon` option set, these two commands are equivalent: - -``` -$ docker run -d --isolation default busybox top -$ docker run -d --isolation process busybox top -``` - -If you have set the `--exec-opt isolation=hyperv` option on the Docker `daemon`, any of these commands also result in `hyperv` isolation: - -``` -$ docker run -d --isolation default busybox top -$ docker run -d --isolation hyperv busybox top -``` - -## Setting Namespaced Kernel Parameters (Sysctls) - -The `--sysctl` sets namespaced kernel parameters (sysctls) in the -container. For example, to turn on IP forwarding in the containers -network namespace, run this command: - - $ docker run --sysctl net.ipv4.ip_forward=1 someimage - -Note: - -Not all sysctls are namespaced. Docker does not support changing sysctls -inside of a container that also modify the host system. As the kernel -evolves we expect to see more sysctls become namespaced. - -See the definition of the `--sysctl` option above for the current list of -supported sysctls. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -July 2014, updated by Sven Dowideit -November 2015, updated by Sally O'Malley diff --git a/vendor/github.com/docker/docker/man/docker-save.1.md b/vendor/github.com/docker/docker/man/docker-save.1.md deleted file mode 100644 index 1d1de8a..0000000 --- a/vendor/github.com/docker/docker/man/docker-save.1.md +++ /dev/null @@ -1,45 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-save - Save one or more images to a tar archive (streamed to STDOUT by default) - -# SYNOPSIS -**docker save** -[**--help**] -[**-o**|**--output**[=*OUTPUT*]] -IMAGE [IMAGE...] - -# DESCRIPTION -Produces a tarred repository to the standard output stream. Contains all -parent layers, and all tags + versions, or specified repo:tag. - -Stream to a file instead of STDOUT by using **-o**. - -# OPTIONS -**--help** - Print usage statement - -**-o**, **--output**="" - Write to a file, instead of STDOUT - -# EXAMPLES - -Save all fedora repository images to a fedora-all.tar and save the latest -fedora image to a fedora-latest.tar: - - $ docker save fedora > fedora-all.tar - $ docker save --output=fedora-latest.tar fedora:latest - $ ls -sh fedora-all.tar - 721M fedora-all.tar - $ ls -sh fedora-latest.tar - 367M fedora-latest.tar - -# See also -**docker-load(1)** to load an image from a tar archive on STDIN. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -November 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-search.1.md b/vendor/github.com/docker/docker/man/docker-search.1.md deleted file mode 100644 index ad8bbc7..0000000 --- a/vendor/github.com/docker/docker/man/docker-search.1.md +++ /dev/null @@ -1,70 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-search - Search the Docker Hub for images - -# SYNOPSIS -**docker search** -[**-f**|**--filter**[=*[]*]] -[**--help**] -[**--limit**[=*LIMIT*]] -[**--no-trunc**] -TERM - -# DESCRIPTION - -Search Docker Hub for images that match the specified `TERM`. The table -of images returned displays the name, description (truncated by default), number -of stars awarded, whether the image is official, and whether it is automated. - -*Note* - Search queries will only return up to 25 results - -# OPTIONS - -**-f**, **--filter**=[] - Filter output based on these conditions: - - stars= - - is-automated=(true|false) - - is-official=(true|false) - -**--help** - Print usage statement - -**--limit**=*LIMIT* - Maximum returned search results. The default is 25. - -**--no-trunc**=*true*|*false* - Don't truncate output. The default is *false*. - -# EXAMPLES - -## Search Docker Hub for ranked images - -Search a registry for the term 'fedora' and only display those images -ranked 3 or higher: - - $ docker search --filter=stars=3 fedora - NAME DESCRIPTION STARS OFFICIAL AUTOMATED - mattdm/fedora A basic Fedora image corresponding roughly... 50 - fedora (Semi) Official Fedora base image. 38 - mattdm/fedora-small A small Fedora image on which to build. Co... 8 - goldmann/wildfly A WildFly application server running on a ... 3 [OK] - -## Search Docker Hub for automated images - -Search Docker Hub for the term 'fedora' and only display automated images -ranked 1 or higher: - - $ docker search --filter=is-automated=true --filter=stars=1 fedora - NAME DESCRIPTION STARS OFFICIAL AUTOMATED - goldmann/wildfly A WildFly application server running on a ... 3 [OK] - tutum/fedora-20 Fedora 20 image with SSH access. For the r... 1 [OK] - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -April 2015, updated by Mary Anthony for v2 -April 2016, updated by Vincent Demeester - diff --git a/vendor/github.com/docker/docker/man/docker-start.1.md b/vendor/github.com/docker/docker/man/docker-start.1.md deleted file mode 100644 index c00b0a1..0000000 --- a/vendor/github.com/docker/docker/man/docker-start.1.md +++ /dev/null @@ -1,39 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-start - Start one or more containers - -# SYNOPSIS -**docker start** -[**-a**|**--attach**] -[**--detach-keys**[=*[]*]] -[**--help**] -[**-i**|**--interactive**] -CONTAINER [CONTAINER...] - -# DESCRIPTION - -Start one or more containers. - -# OPTIONS -**-a**, **--attach**=*true*|*false* - Attach container's STDOUT and STDERR and forward all signals to the - process. The default is *false*. - -**--detach-keys**="" - Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-` where `` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`. - -**--help** - Print usage statement - -**-i**, **--interactive**=*true*|*false* - Attach container's STDIN. The default is *false*. - -# See also -**docker-stop(1)** to stop a container. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-stats.1.md b/vendor/github.com/docker/docker/man/docker-stats.1.md deleted file mode 100644 index 0f022cd..0000000 --- a/vendor/github.com/docker/docker/man/docker-stats.1.md +++ /dev/null @@ -1,57 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-stats - Display a live stream of one or more containers' resource usage statistics - -# SYNOPSIS -**docker stats** -[**-a**|**--all**] -[**--help**] -[**--no-stream**] -[**--format[="*TEMPLATE*"]**] -[CONTAINER...] - -# DESCRIPTION - -Display a live stream of one or more containers' resource usage statistics - -# OPTIONS -**-a**, **--all**=*true*|*false* - Show all containers. Only running containers are shown by default. The default is *false*. - -**--help** - Print usage statement - -**--no-stream**=*true*|*false* - Disable streaming stats and only pull the first result, default setting is false. - -**--format**="*TEMPLATE*" - Pretty-print containers statistics using a Go template. - Valid placeholders: - .Container - Container name or ID. - .Name - Container name. - .ID - Container ID. - .CPUPerc - CPU percentage. - .MemUsage - Memory usage. - .NetIO - Network IO. - .BlockIO - Block IO. - .MemPerc - Memory percentage (Not available on Windows). - .PIDs - Number of PIDs (Not available on Windows). - -# EXAMPLES - -Running `docker stats` on all running containers - - $ docker stats - CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O - 1285939c1fd3 0.07% 796 KiB / 64 MiB 1.21% 788 B / 648 B 3.568 MB / 512 KB - 9c76f7834ae2 0.07% 2.746 MiB / 64 MiB 4.29% 1.266 KB / 648 B 12.4 MB / 0 B - d1ea048f04e4 0.03% 4.583 MiB / 64 MiB 6.30% 2.854 KB / 648 B 27.7 MB / 0 B - -Running `docker stats` on multiple containers by name and id. - - $ docker stats fervent_panini 5acfcb1b4fd1 - CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O - 5acfcb1b4fd1 0.00% 115.2 MiB/1.045 GiB 11.03% 1.422 kB/648 B - fervent_panini 0.02% 11.08 MiB/1.045 GiB 1.06% 648 B/648 B diff --git a/vendor/github.com/docker/docker/man/docker-stop.1.md b/vendor/github.com/docker/docker/man/docker-stop.1.md deleted file mode 100644 index fa377c9..0000000 --- a/vendor/github.com/docker/docker/man/docker-stop.1.md +++ /dev/null @@ -1,30 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-stop - Stop a container by sending SIGTERM and then SIGKILL after a grace period - -# SYNOPSIS -**docker stop** -[**--help**] -[**-t**|**--time**[=*10*]] -CONTAINER [CONTAINER...] - -# DESCRIPTION -Stop a container (Send SIGTERM, and then SIGKILL after - grace period) - -# OPTIONS -**--help** - Print usage statement - -**-t**, **--time**=*10* - Number of seconds to wait for the container to stop before killing it. Default is 10 seconds. - -#See also -**docker-start(1)** to restart a stopped container. - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-tag.1.md b/vendor/github.com/docker/docker/man/docker-tag.1.md deleted file mode 100644 index 7f27e1b..0000000 --- a/vendor/github.com/docker/docker/man/docker-tag.1.md +++ /dev/null @@ -1,76 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-tag - Create a tag `TARGET_IMAGE` that refers to `SOURCE_IMAGE` - -# SYNOPSIS -**docker tag** -[**--help**] -SOURCE_NAME[:TAG] TARGET_NAME[:TAG] - -# DESCRIPTION -Assigns a new alias to an image in a registry. An alias refers to the -entire image name including the optional `TAG` after the ':'. - -# "OPTIONS" -**--help** - Print usage statement. - -**NAME** - The image name which is made up of slash-separated name components, - optionally prefixed by a registry hostname. The hostname must comply with - standard DNS rules, but may not contain underscores. If a hostname is - present, it may optionally be followed by a port number in the format - `:8080`. If not present, the command uses Docker's public registry located at - `registry-1.docker.io` by default. Name components may contain lowercase - characters, digits and separators. A separator is defined as a period, one or - two underscores, or one or more dashes. A name component may not start or end - with a separator. - -**TAG** - The tag assigned to the image to version and distinguish images with the same - name. The tag name may contain lowercase and uppercase characters, digits, - underscores, periods and dashes. A tag name may not start with a period or a - dash and may contain a maximum of 128 characters. - -# EXAMPLES - -## Tagging an image referenced by ID - -To tag a local image with ID "0e5574283393" into the "fedora" repository with -"version1.0": - - docker tag 0e5574283393 fedora/httpd:version1.0 - -## Tagging an image referenced by Name - -To tag a local image with name "httpd" into the "fedora" repository with -"version1.0": - - docker tag httpd fedora/httpd:version1.0 - -Note that since the tag name is not specified, the alias is created for an -existing local version `httpd:latest`. - -## Tagging an image referenced by Name and Tag - -To tag a local image with name "httpd" and tag "test" into the "fedora" -repository with "version1.0.test": - - docker tag httpd:test fedora/httpd:version1.0.test - -## Tagging an image for a private repository - -To push an image to a private registry and not the central Docker -registry you must tag it with the registry hostname and port (if needed). - - docker tag 0e5574283393 myregistryhost:5000/fedora/httpd:version1.0 - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -July 2014, updated by Sven Dowideit -April 2015, updated by Mary Anthony for v2 -June 2015, updated by Sally O'Malley diff --git a/vendor/github.com/docker/docker/man/docker-top.1.md b/vendor/github.com/docker/docker/man/docker-top.1.md deleted file mode 100644 index a666f7c..0000000 --- a/vendor/github.com/docker/docker/man/docker-top.1.md +++ /dev/null @@ -1,36 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-top - Display the running processes of a container - -# SYNOPSIS -**docker top** -[**--help**] -CONTAINER [ps OPTIONS] - -# DESCRIPTION - -Display the running process of the container. ps-OPTION can be any of the options you would pass to a Linux ps command. - -All displayed information is from host's point of view. - -# OPTIONS -**--help** - Print usage statement - -# EXAMPLES - -Run **docker top** with the ps option of -x: - - $ docker top 8601afda2b -x - PID TTY STAT TIME COMMAND - 16623 ? Ss 0:00 sleep 99999 - - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit -June 2015, updated by Ma Shimiao -December 2015, updated by Pavel Pospisil diff --git a/vendor/github.com/docker/docker/man/docker-unpause.1.md b/vendor/github.com/docker/docker/man/docker-unpause.1.md deleted file mode 100644 index e6fd3c4..0000000 --- a/vendor/github.com/docker/docker/man/docker-unpause.1.md +++ /dev/null @@ -1,28 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-unpause - Unpause all processes within one or more containers - -# SYNOPSIS -**docker unpause** -CONTAINER [CONTAINER...] - -# DESCRIPTION - -The `docker unpause` command un-suspends all processes in the specified containers. -On Linux, it does this using the cgroups freezer. - -See the [cgroups freezer documentation] -(https://www.kernel.org/doc/Documentation/cgroup-v1/freezer-subsystem.txt) for -further details. - -# OPTIONS -**--help** - Print usage statement - -# See also -**docker-pause(1)** to pause all processes within one or more containers. - -# HISTORY -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker-update.1.md b/vendor/github.com/docker/docker/man/docker-update.1.md deleted file mode 100644 index 85f3dd0..0000000 --- a/vendor/github.com/docker/docker/man/docker-update.1.md +++ /dev/null @@ -1,171 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-update - Update configuration of one or more containers - -# SYNOPSIS -**docker update** -[**--blkio-weight**[=*[BLKIO-WEIGHT]*]] -[**--cpu-shares**[=*0*]] -[**--cpu-period**[=*0*]] -[**--cpu-quota**[=*0*]] -[**--cpu-rt-period**[=*0*]] -[**--cpu-rt-runtime**[=*0*]] -[**--cpuset-cpus**[=*CPUSET-CPUS*]] -[**--cpuset-mems**[=*CPUSET-MEMS*]] -[**--help**] -[**--kernel-memory**[=*KERNEL-MEMORY*]] -[**-m**|**--memory**[=*MEMORY*]] -[**--memory-reservation**[=*MEMORY-RESERVATION*]] -[**--memory-swap**[=*MEMORY-SWAP*]] -[**--restart**[=*""*]] -CONTAINER [CONTAINER...] - -# DESCRIPTION - -The **docker update** command dynamically updates container configuration. -You can use this command to prevent containers from consuming too many -resources from their Docker host. With a single command, you can place -limits on a single container or on many. To specify more than one container, -provide space-separated list of container names or IDs. - -With the exception of the **--kernel-memory** option, you can specify these -options on a running or a stopped container. On kernel version older than -4.6, You can only update **--kernel-memory** on a stopped container or on -a running container with kernel memory initialized. - -# OPTIONS - -**--blkio-weight**=0 - Block IO weight (relative weight) accepts a weight value between 10 and 1000. - -**--cpu-shares**=0 - CPU shares (relative weight) - -**--cpu-period**=0 - Limit the CPU CFS (Completely Fair Scheduler) period - - Limit the container's CPU usage. This flag tell the kernel to restrict the container's CPU usage to the period you specify. - -**--cpu-quota**=0 - Limit the CPU CFS (Completely Fair Scheduler) quota - -**--cpu-rt-period**=0 - Limit the CPU real-time period in microseconds - - Limit the container's Real Time CPU usage. This flag tell the kernel to restrict the container's Real Time CPU usage to the period you specify. - -**--cpu-rt-runtime**=0 - Limit the CPU real-time runtime in microseconds - - Limit the containers Real Time CPU usage. This flag tells the kernel to limit the amount of time in a given CPU period Real Time tasks may consume. Ex: - Period of 1,000,000us and Runtime of 950,000us means that this container could consume 95% of available CPU and leave the remaining 5% to normal priority tasks. - - The sum of all runtimes across containers cannot exceed the amount allotted to the parent cgroup. - -**--cpuset-cpus**="" - CPUs in which to allow execution (0-3, 0,1) - -**--cpuset-mems**="" - Memory nodes(MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. - -**--help** - Print usage statement - -**--kernel-memory**="" - Kernel memory limit (format: `[]`, where unit = b, k, m or g) - - Note that on kernel version older than 4.6, you can not update kernel memory on - a running container if the container is started without kernel memory initialized, - in this case, it can only be updated after it's stopped. The new setting takes - effect when the container is started. - -**-m**, **--memory**="" - Memory limit (format: , where unit = b, k, m or g) - - Note that the memory should be smaller than the already set swap memory limit. - If you want update a memory limit bigger than the already set swap memory limit, - you should update swap memory limit at the same time. If you don't set swap memory - limit on docker create/run but only memory limit, the swap memory is double - the memory limit. - -**--memory-reservation**="" - Memory soft limit (format: [], where unit = b, k, m or g) - -**--memory-swap**="" - Total memory limit (memory + swap) - -**--restart**="" - Restart policy to apply when a container exits (no, on-failure[:max-retry], always, unless-stopped). - -# EXAMPLES - -The following sections illustrate ways to use this command. - -### Update a container's cpu-shares - -To limit a container's cpu-shares to 512, first identify the container -name or ID. You can use **docker ps** to find these values. You can also -use the ID returned from the **docker run** command. Then, do the following: - -```bash -$ docker update --cpu-shares 512 abebf7571666 -``` - -### Update a container with cpu-shares and memory - -To update multiple resource configurations for multiple containers: - -```bash -$ docker update --cpu-shares 512 -m 300M abebf7571666 hopeful_morse -``` - -### Update a container's kernel memory constraints - -You can update a container's kernel memory limit using the **--kernel-memory** -option. On kernel version older than 4.6, this option can be updated on a -running container only if the container was started with **--kernel-memory**. -If the container was started *without* **--kernel-memory** you need to stop -the container before updating kernel memory. - -For example, if you started a container with this command: - -```bash -$ docker run -dit --name test --kernel-memory 50M ubuntu bash -``` - -You can update kernel memory while the container is running: - -```bash -$ docker update --kernel-memory 80M test -``` - -If you started a container *without* kernel memory initialized: - -```bash -$ docker run -dit --name test2 --memory 300M ubuntu bash -``` - -Update kernel memory of running container `test2` will fail. You need to stop -the container before updating the **--kernel-memory** setting. The next time you -start it, the container uses the new value. - -Kernel version newer than (include) 4.6 does not have this limitation, you -can use `--kernel-memory` the same way as other options. - -### Update a container's restart policy - -You can change a container's restart policy on a running container. The new -restart policy takes effect instantly after you run `docker update` on a -container. - -To update restart policy for one or more containers: - -```bash -$ docker update --restart=on-failure:3 abebf7571666 hopeful_morse -``` - -Note that if the container is started with "--rm" flag, you cannot update the restart -policy for it. The `AutoRemove` and `RestartPolicy` are mutually exclusive for the -container. diff --git a/vendor/github.com/docker/docker/man/docker-version.1.md b/vendor/github.com/docker/docker/man/docker-version.1.md deleted file mode 100644 index 1838f82..0000000 --- a/vendor/github.com/docker/docker/man/docker-version.1.md +++ /dev/null @@ -1,62 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2015 -# NAME -docker-version - Show the Docker version information. - -# SYNOPSIS -**docker version** -[**--help**] -[**-f**|**--format**[=*FORMAT*]] - -# DESCRIPTION -This command displays version information for both the Docker client and -daemon. - -# OPTIONS -**--help** - Print usage statement - -**-f**, **--format**="" - Format the output using the given Go template. - -# EXAMPLES - -## Display Docker version information - -The default output: - - $ docker version - Client: - Version: 1.8.0 - API version: 1.20 - Go version: go1.4.2 - Git commit: f5bae0a - Built: Tue Jun 23 17:56:00 UTC 2015 - OS/Arch: linux/amd64 - - Server: - Version: 1.8.0 - API version: 1.20 - Go version: go1.4.2 - Git commit: f5bae0a - Built: Tue Jun 23 17:56:00 UTC 2015 - OS/Arch: linux/amd64 - -Get server version: - - $ docker version --format '{{.Server.Version}}' - 1.8.0 - -Dump raw data: - -To view all available fields, you can use the format `{{json .}}`. - - $ docker version --format '{{json .}}' - {"Client":{"Version":"1.8.0","ApiVersion":"1.20","GitCommit":"f5bae0a","GoVersion":"go1.4.2","Os":"linux","Arch":"amd64","BuildTime":"Tue Jun 23 17:56:00 UTC 2015"},"ServerOK":true,"Server":{"Version":"1.8.0","ApiVersion":"1.20","GitCommit":"f5bae0a","GoVersion":"go1.4.2","Os":"linux","Arch":"amd64","KernelVersion":"3.13.2-gentoo","BuildTime":"Tue Jun 23 17:56:00 UTC 2015"}} - - -# HISTORY -June 2014, updated by Sven Dowideit -June 2015, updated by John Howard -June 2015, updated by Patrick Hemmer diff --git a/vendor/github.com/docker/docker/man/docker-wait.1.md b/vendor/github.com/docker/docker/man/docker-wait.1.md deleted file mode 100644 index 6788009..0000000 --- a/vendor/github.com/docker/docker/man/docker-wait.1.md +++ /dev/null @@ -1,30 +0,0 @@ -% DOCKER(1) Docker User Manuals -% Docker Community -% JUNE 2014 -# NAME -docker-wait - Block until one or more containers stop, then print their exit codes - -# SYNOPSIS -**docker wait** -[**--help**] -CONTAINER [CONTAINER...] - -# DESCRIPTION - -Block until one or more containers stop, then print their exit codes. - -# OPTIONS -**--help** - Print usage statement - -# EXAMPLES - - $ docker run -d fedora sleep 99 - 079b83f558a2bc52ecad6b2a5de13622d584e6bb1aea058c11b36511e85e7622 - $ docker wait 079b83f558a2bc - 0 - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.com source material and internal work. -June 2014, updated by Sven Dowideit diff --git a/vendor/github.com/docker/docker/man/docker.1.md b/vendor/github.com/docker/docker/man/docker.1.md deleted file mode 100644 index 2a96184..0000000 --- a/vendor/github.com/docker/docker/man/docker.1.md +++ /dev/null @@ -1,237 +0,0 @@ -% DOCKER(1) Docker User Manuals -% William Henry -% APRIL 2014 -# NAME -docker \- Docker image and container command line interface - -# SYNOPSIS -**docker** [OPTIONS] COMMAND [ARG...] - -**docker** daemon [--help|...] - -**docker** [--help|-v|--version] - -# DESCRIPTION -is a client for interacting with the daemon (see **dockerd(8)**) through the CLI. - -The Docker CLI has over 30 commands. The commands are listed below and each has -its own man page which explain usage and arguments. - -To see the man page for a command run **man docker **. - -# OPTIONS -**--help** - Print usage statement - -**--config**="" - Specifies the location of the Docker client configuration files. The default is '~/.docker'. - -**-D**, **--debug**=*true*|*false* - Enable debug mode. Default is false. - -**-H**, **--host**=[*unix:///var/run/docker.sock*]: tcp://[host]:[port][path] to bind or -unix://[/path/to/socket] to use. - The socket(s) to bind to in daemon mode specified using one or more - tcp://host:port/path, unix:///path/to/socket, fd://* or fd://socketfd. - If the tcp port is not specified, then it will default to either `2375` when - `--tls` is off, or `2376` when `--tls` is on, or `--tlsverify` is specified. - -**-l**, **--log-level**="*debug*|*info*|*warn*|*error*|*fatal*" - Set the logging level. Default is `info`. - -**--tls**=*true*|*false* - Use TLS; implied by --tlsverify. Default is false. - -**--tlscacert**=*~/.docker/ca.pem* - Trust certs signed only by this CA. - -**--tlscert**=*~/.docker/cert.pem* - Path to TLS certificate file. - -**--tlskey**=*~/.docker/key.pem* - Path to TLS key file. - -**--tlsverify**=*true*|*false* - Use TLS and verify the remote (daemon: verify client, client: verify daemon). - Default is false. - -**-v**, **--version**=*true*|*false* - Print version information and quit. Default is false. - -# COMMANDS -**attach** - Attach to a running container - See **docker-attach(1)** for full documentation on the **attach** command. - -**build** - Build an image from a Dockerfile - See **docker-build(1)** for full documentation on the **build** command. - -**commit** - Create a new image from a container's changes - See **docker-commit(1)** for full documentation on the **commit** command. - -**cp** - Copy files/folders between a container and the local filesystem - See **docker-cp(1)** for full documentation on the **cp** command. - -**create** - Create a new container - See **docker-create(1)** for full documentation on the **create** command. - -**diff** - Inspect changes on a container's filesystem - See **docker-diff(1)** for full documentation on the **diff** command. - -**events** - Get real time events from the server - See **docker-events(1)** for full documentation on the **events** command. - -**exec** - Run a command in a running container - See **docker-exec(1)** for full documentation on the **exec** command. - -**export** - Stream the contents of a container as a tar archive - See **docker-export(1)** for full documentation on the **export** command. - -**history** - Show the history of an image - See **docker-history(1)** for full documentation on the **history** command. - -**images** - List images - See **docker-images(1)** for full documentation on the **images** command. - -**import** - Create a new filesystem image from the contents of a tarball - See **docker-import(1)** for full documentation on the **import** command. - -**info** - Display system-wide information - See **docker-info(1)** for full documentation on the **info** command. - -**inspect** - Return low-level information on a container or image - See **docker-inspect(1)** for full documentation on the **inspect** command. - -**kill** - Kill a running container (which includes the wrapper process and everything -inside it) - See **docker-kill(1)** for full documentation on the **kill** command. - -**load** - Load an image from a tar archive - See **docker-load(1)** for full documentation on the **load** command. - -**login** - Log in to a Docker Registry - See **docker-login(1)** for full documentation on the **login** command. - -**logout** - Log the user out of a Docker Registry - See **docker-logout(1)** for full documentation on the **logout** command. - -**logs** - Fetch the logs of a container - See **docker-logs(1)** for full documentation on the **logs** command. - -**pause** - Pause all processes within a container - See **docker-pause(1)** for full documentation on the **pause** command. - -**port** - Lookup the public-facing port which is NAT-ed to PRIVATE_PORT - See **docker-port(1)** for full documentation on the **port** command. - -**ps** - List containers - See **docker-ps(1)** for full documentation on the **ps** command. - -**pull** - Pull an image or a repository from a Docker Registry - See **docker-pull(1)** for full documentation on the **pull** command. - -**push** - Push an image or a repository to a Docker Registry - See **docker-push(1)** for full documentation on the **push** command. - -**rename** - Rename a container. - See **docker-rename(1)** for full documentation on the **rename** command. - -**restart** - Restart one or more containers - See **docker-restart(1)** for full documentation on the **restart** command. - -**rm** - Remove one or more containers - See **docker-rm(1)** for full documentation on the **rm** command. - -**rmi** - Remove one or more images - See **docker-rmi(1)** for full documentation on the **rmi** command. - -**run** - Run a command in a new container - See **docker-run(1)** for full documentation on the **run** command. - -**save** - Save an image to a tar archive - See **docker-save(1)** for full documentation on the **save** command. - -**search** - Search for an image in the Docker index - See **docker-search(1)** for full documentation on the **search** command. - -**start** - Start a container - See **docker-start(1)** for full documentation on the **start** command. - -**stats** - Display a live stream of one or more containers' resource usage statistics - See **docker-stats(1)** for full documentation on the **stats** command. - -**stop** - Stop a container - See **docker-stop(1)** for full documentation on the **stop** command. - -**tag** - Tag an image into a repository - See **docker-tag(1)** for full documentation on the **tag** command. - -**top** - Lookup the running processes of a container - See **docker-top(1)** for full documentation on the **top** command. - -**unpause** - Unpause all processes within a container - See **docker-unpause(1)** for full documentation on the **unpause** command. - -**version** - Show the Docker version information - See **docker-version(1)** for full documentation on the **version** command. - -**wait** - Block until a container stops, then print its exit code - See **docker-wait(1)** for full documentation on the **wait** command. - - -# RUNTIME EXECUTION OPTIONS - -Use the **--exec-opt** flags to specify options to the execution driver. -The following options are available: - -#### native.cgroupdriver -Specifies the management of the container's `cgroups`. You can specify `cgroupfs` -or `systemd`. If you specify `systemd` and it is not available, the system errors -out. - -#### Client -For specific client examples please see the man page for the specific Docker -command. For example: - - man docker-run - -# HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) based on docker.com source material and internal work. diff --git a/vendor/github.com/docker/docker/man/dockerd.8.md b/vendor/github.com/docker/docker/man/dockerd.8.md deleted file mode 100644 index 761dc6b..0000000 --- a/vendor/github.com/docker/docker/man/dockerd.8.md +++ /dev/null @@ -1,710 +0,0 @@ -% DOCKER(8) Docker User Manuals -% Shishir Mahajan -% SEPTEMBER 2015 -# NAME -dockerd - Enable daemon mode - -# SYNOPSIS -**dockerd** -[**--add-runtime**[=*[]*]] -[**--api-cors-header**=[=*API-CORS-HEADER*]] -[**--authorization-plugin**[=*[]*]] -[**-b**|**--bridge**[=*BRIDGE*]] -[**--bip**[=*BIP*]] -[**--cgroup-parent**[=*[]*]] -[**--cluster-store**[=*[]*]] -[**--cluster-advertise**[=*[]*]] -[**--cluster-store-opt**[=*map[]*]] -[**--config-file**[=*/etc/docker/daemon.json*]] -[**--containerd**[=*SOCKET-PATH*]] -[**-D**|**--debug**] -[**--default-gateway**[=*DEFAULT-GATEWAY*]] -[**--default-gateway-v6**[=*DEFAULT-GATEWAY-V6*]] -[**--default-runtime**[=*runc*]] -[**--default-ulimit**[=*[]*]] -[**--disable-legacy-registry**] -[**--dns**[=*[]*]] -[**--dns-opt**[=*[]*]] -[**--dns-search**[=*[]*]] -[**--exec-opt**[=*[]*]] -[**--exec-root**[=*/var/run/docker*]] -[**--experimental**[=*false*]] -[**--fixed-cidr**[=*FIXED-CIDR*]] -[**--fixed-cidr-v6**[=*FIXED-CIDR-V6*]] -[**-G**|**--group**[=*docker*]] -[**-g**|**--graph**[=*/var/lib/docker*]] -[**-H**|**--host**[=*[]*]] -[**--help**] -[**--icc**[=*true*]] -[**--init**[=*false*]] -[**--init-path**[=*""*]] -[**--insecure-registry**[=*[]*]] -[**--ip**[=*0.0.0.0*]] -[**--ip-forward**[=*true*]] -[**--ip-masq**[=*true*]] -[**--iptables**[=*true*]] -[**--ipv6**] -[**--isolation**[=*default*]] -[**-l**|**--log-level**[=*info*]] -[**--label**[=*[]*]] -[**--live-restore**[=*false*]] -[**--log-driver**[=*json-file*]] -[**--log-opt**[=*map[]*]] -[**--mtu**[=*0*]] -[**--max-concurrent-downloads**[=*3*]] -[**--max-concurrent-uploads**[=*5*]] -[**-p**|**--pidfile**[=*/var/run/docker.pid*]] -[**--raw-logs**] -[**--registry-mirror**[=*[]*]] -[**-s**|**--storage-driver**[=*STORAGE-DRIVER*]] -[**--seccomp-profile**[=*SECCOMP-PROFILE-PATH*]] -[**--selinux-enabled**] -[**--shutdown-timeout**[=*15*]] -[**--storage-opt**[=*[]*]] -[**--swarm-default-advertise-addr**[=*IP|INTERFACE*]] -[**--tls**] -[**--tlscacert**[=*~/.docker/ca.pem*]] -[**--tlscert**[=*~/.docker/cert.pem*]] -[**--tlskey**[=*~/.docker/key.pem*]] -[**--tlsverify**] -[**--userland-proxy**[=*true*]] -[**--userland-proxy-path**[=*""*]] -[**--userns-remap**[=*default*]] - -# DESCRIPTION -**dockerd** is used for starting the Docker daemon (i.e., to command the daemon -to manage images, containers etc). So **dockerd** is a server, as a daemon. - -To run the Docker daemon you can specify **dockerd**. -You can check the daemon options using **dockerd --help**. -Daemon options should be specified after the **dockerd** keyword in the -following format. - -**dockerd [OPTIONS]** - -# OPTIONS - -**--add-runtime**=[] - Runtimes can be registered with the daemon either via the -configuration file or using the `--add-runtime` command line argument. - - The following is an example adding 2 runtimes via the configuration: - -```json -{ - "default-runtime": "runc", - "runtimes": { - "runc": { - "path": "runc" - }, - "custom": { - "path": "/usr/local/bin/my-runc-replacement", - "runtimeArgs": [ - "--debug" - ] - } - } -} -``` - - This is the same example via the command line: - -```bash -$ sudo dockerd --add-runtime runc=runc --add-runtime custom=/usr/local/bin/my-runc-replacement -``` - - **Note**: defining runtime arguments via the command line is not supported. - -**--api-cors-header**="" - Set CORS headers in the Engine API. Default is cors disabled. Give urls like - "http://foo, http://bar, ...". Give "*" to allow all. - -**--authorization-plugin**="" - Set authorization plugins to load - -**-b**, **--bridge**="" - Attach containers to a pre\-existing network bridge; use 'none' to disable - container networking - -**--bip**="" - Use the provided CIDR notation address for the dynamically created bridge - (docker0); Mutually exclusive of \-b - -**--cgroup-parent**="" - Set parent cgroup for all containers. Default is "/docker" for fs cgroup - driver and "system.slice" for systemd cgroup driver. - -**--cluster-store**="" - URL of the distributed storage backend - -**--cluster-advertise**="" - Specifies the 'host:port' or `interface:port` combination that this - particular daemon instance should use when advertising itself to the cluster. - The daemon is reached through this value. - -**--cluster-store-opt**="" - Specifies options for the Key/Value store. - -**--config-file**="/etc/docker/daemon.json" - Specifies the JSON file path to load the configuration from. - -**--containerd**="" - Path to containerd socket. - -**-D**, **--debug**=*true*|*false* - Enable debug mode. Default is false. - -**--default-gateway**="" - IPv4 address of the container default gateway; this address must be part of - the bridge subnet (which is defined by \-b or \--bip) - -**--default-gateway-v6**="" - IPv6 address of the container default gateway - -**--default-runtime**="runc" - Set default runtime if there're more than one specified by `--add-runtime`. - -**--default-ulimit**=[] - Default ulimits for containers. - -**--disable-legacy-registry**=*true*|*false* - Disable contacting legacy registries - -**--dns**="" - Force Docker to use specific DNS servers - -**--dns-opt**="" - DNS options to use. - -**--dns-search**=[] - DNS search domains to use. - -**--exec-opt**=[] - Set runtime execution options. See RUNTIME EXECUTION OPTIONS. - -**--exec-root**="" - Path to use as the root of the Docker execution state files. Default is - `/var/run/docker`. - -**--experimental**="" - Enable the daemon experimental features. - -**--fixed-cidr**="" - IPv4 subnet for fixed IPs (e.g., 10.20.0.0/16); this subnet must be nested in - the bridge subnet (which is defined by \-b or \-\-bip). - -**--fixed-cidr-v6**="" - IPv6 subnet for global IPv6 addresses (e.g., 2a00:1450::/64) - -**-G**, **--group**="" - Group to assign the unix socket specified by -H when running in daemon mode. - use '' (the empty string) to disable setting of a group. Default is `docker`. - -**-g**, **--graph**="" - Path to use as the root of the Docker runtime. Default is `/var/lib/docker`. - -**-H**, **--host**=[*unix:///var/run/docker.sock*]: tcp://[host:port] to bind or -unix://[/path/to/socket] to use. - The socket(s) to bind to in daemon mode specified using one or more - tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd. - -**--help** - Print usage statement - -**--icc**=*true*|*false* - Allow unrestricted inter\-container and Docker daemon host communication. If - disabled, containers can still be linked together using the **--link** option - (see **docker-run(1)**). Default is true. - -**--init** - Run an init process inside containers for signal forwarding and process - reaping. - -**--init-path** - Path to the docker-init binary. - -**--insecure-registry**=[] - Enable insecure registry communication, i.e., enable un-encrypted and/or - untrusted communication. - - List of insecure registries can contain an element with CIDR notation to - specify a whole subnet. Insecure registries accept HTTP and/or accept HTTPS - with certificates from unknown CAs. - - Enabling `--insecure-registry` is useful when running a local registry. - However, because its use creates security vulnerabilities it should ONLY be - enabled for testing purposes. For increased security, users should add their - CA to their system's list of trusted CAs instead of using - `--insecure-registry`. - -**--ip**="" - Default IP address to use when binding container ports. Default is `0.0.0.0`. - -**--ip-forward**=*true*|*false* - Enables IP forwarding on the Docker host. The default is `true`. This flag - interacts with the IP forwarding setting on your host system's kernel. If - your system has IP forwarding disabled, this setting enables it. If your - system has IP forwarding enabled, setting this flag to `--ip-forward=false` - has no effect. - - This setting will also enable IPv6 forwarding if you have both - `--ip-forward=true` and `--fixed-cidr-v6` set. Note that this may reject - Router Advertisements and interfere with the host's existing IPv6 - configuration. For more information, please consult the documentation about - "Advanced Networking - IPv6". - -**--ip-masq**=*true*|*false* - Enable IP masquerading for bridge's IP range. Default is true. - -**--iptables**=*true*|*false* - Enable Docker's addition of iptables rules. Default is true. - -**--ipv6**=*true*|*false* - Enable IPv6 support. Default is false. Docker will create an IPv6-enabled - bridge with address fe80::1 which will allow you to create IPv6-enabled - containers. Use together with `--fixed-cidr-v6` to provide globally routable - IPv6 addresses. IPv6 forwarding will be enabled if not used with - `--ip-forward=false`. This may collide with your host's current IPv6 - settings. For more information please consult the documentation about - "Advanced Networking - IPv6". - -**--isolation**="*default*" - Isolation specifies the type of isolation technology used by containers. - Note that the default on Windows server is `process`, and the default on - Windows client is `hyperv`. Linux only supports `default`. - -**-l**, **--log-level**="*debug*|*info*|*warn*|*error*|*fatal*" - Set the logging level. Default is `info`. - -**--label**="[]" - Set key=value labels to the daemon (displayed in `docker info`) - -**--live-restore**=*false* - Enable live restore of running containers when the daemon starts so that they - are not restarted. This option is applicable only for docker daemon running - on Linux host. - -**--log-driver**="*json-file*|*syslog*|*journald*|*gelf*|*fluentd*|*awslogs*|*splunk*|*etwlogs*|*gcplogs*|*none*" - Default driver for container logs. Default is `json-file`. - **Warning**: `docker logs` command works only for `json-file` logging driver. - -**--log-opt**=[] - Logging driver specific options. - -**--mtu**=*0* - Set the containers network mtu. Default is `0`. - -**--max-concurrent-downloads**=*3* - Set the max concurrent downloads for each pull. Default is `3`. - -**--max-concurrent-uploads**=*5* - Set the max concurrent uploads for each push. Default is `5`. - -**-p**, **--pidfile**="" - Path to use for daemon PID file. Default is `/var/run/docker.pid` - -**--raw-logs** - Output daemon logs in full timestamp format without ANSI coloring. If this - flag is not set, the daemon outputs condensed, colorized logs if a terminal - is detected, or full ("raw") output otherwise. - -**--registry-mirror**=*://* - Prepend a registry mirror to be used for image pulls. May be specified - multiple times. - -**-s**, **--storage-driver**="" - Force the Docker runtime to use a specific storage driver. - -**--seccomp-profile**="" - Path to seccomp profile. - -**--selinux-enabled**=*true*|*false* - Enable selinux support. Default is false. - -**--shutdown-timeout**=*15* - Set the shutdown timeout value in seconds. Default is `15`. - -**--storage-opt**=[] - Set storage driver options. See STORAGE DRIVER OPTIONS. - -**--swarm-default-advertise-addr**=*IP|INTERFACE* - Set default address or interface for swarm to advertise as its - externally-reachable address to other cluster members. This can be a - hostname, an IP address, or an interface such as `eth0`. A port cannot be - specified with this option. - -**--tls**=*true*|*false* - Use TLS; implied by --tlsverify. Default is false. - -**--tlscacert**=*~/.docker/ca.pem* - Trust certs signed only by this CA. - -**--tlscert**=*~/.docker/cert.pem* - Path to TLS certificate file. - -**--tlskey**=*~/.docker/key.pem* - Path to TLS key file. - -**--tlsverify**=*true*|*false* - Use TLS and verify the remote (daemon: verify client, client: verify daemon). - Default is false. - -**--userland-proxy**=*true*|*false* - Rely on a userland proxy implementation for inter-container and - outside-to-container loopback communications. Default is true. - -**--userland-proxy-path**="" - Path to the userland proxy binary. - -**--userns-remap**=*default*|*uid:gid*|*user:group*|*user*|*uid* - Enable user namespaces for containers on the daemon. Specifying "default" - will cause a new user and group to be created to handle UID and GID range - remapping for the user namespace mappings used for contained processes. - Specifying a user (or uid) and optionally a group (or gid) will cause the - daemon to lookup the user and group's subordinate ID ranges for use as the - user namespace mappings for contained processes. - -# STORAGE DRIVER OPTIONS - -Docker uses storage backends (known as "graphdrivers" in the Docker -internals) to create writable containers from images. Many of these -backends use operating system level technologies and can be -configured. - -Specify options to the storage backend with **--storage-opt** flags. The -backends that currently take options are *devicemapper*, *zfs* and *btrfs*. -Options for *devicemapper* are prefixed with *dm*, options for *zfs* -start with *zfs* and options for *btrfs* start with *btrfs*. - -Specifically for devicemapper, the default is a "loopback" model which -requires no pre-configuration, but is extremely inefficient. Do not -use it in production. - -To make the best use of Docker with the devicemapper backend, you must -have a recent version of LVM. Use `lvm` to create a thin pool; for -more information see `man lvmthin`. Then, use `--storage-opt -dm.thinpooldev` to tell the Docker engine to use that pool for -allocating images and container snapshots. - -## Devicemapper options - -#### dm.thinpooldev - -Specifies a custom block storage device to use for the thin pool. - -If using a block device for device mapper storage, it is best to use `lvm` -to create and manage the thin-pool volume. This volume is then handed to Docker -to exclusively create snapshot volumes needed for images and containers. - -Managing the thin-pool outside of Engine makes for the most feature-rich -method of having Docker utilize device mapper thin provisioning as the -backing storage for Docker containers. The highlights of the lvm-based -thin-pool management feature include: automatic or interactive thin-pool -resize support, dynamically changing thin-pool features, automatic thinp -metadata checking when lvm activates the thin-pool, etc. - -As a fallback if no thin pool is provided, loopback files are -created. Loopback is very slow, but can be used without any -pre-configuration of storage. It is strongly recommended that you do -not use loopback in production. Ensure your Engine daemon has a -`--storage-opt dm.thinpooldev` argument provided. - -Example use: - - $ dockerd \ - --storage-opt dm.thinpooldev=/dev/mapper/thin-pool - -#### dm.basesize - -Specifies the size to use when creating the base device, which limits -the size of images and containers. The default value is 10G. Note, -thin devices are inherently "sparse", so a 10G device which is mostly -empty doesn't use 10 GB of space on the pool. However, the filesystem -will use more space for base images the larger the device -is. - -The base device size can be increased at daemon restart which will allow -all future images and containers (based on those new images) to be of the -new base device size. - -Example use: `dockerd --storage-opt dm.basesize=50G` - -This will increase the base device size to 50G. The Docker daemon will throw an -error if existing base device size is larger than 50G. A user can use -this option to expand the base device size however shrinking is not permitted. - -This value affects the system-wide "base" empty filesystem that may already -be initialized and inherited by pulled images. Typically, a change to this -value requires additional steps to take effect: - - $ sudo service docker stop - $ sudo rm -rf /var/lib/docker - $ sudo service docker start - -Example use: `dockerd --storage-opt dm.basesize=20G` - -#### dm.fs - -Specifies the filesystem type to use for the base device. The -supported options are `ext4` and `xfs`. The default is `ext4`. - -Example use: `dockerd --storage-opt dm.fs=xfs` - -#### dm.mkfsarg - -Specifies extra mkfs arguments to be used when creating the base device. - -Example use: `dockerd --storage-opt "dm.mkfsarg=-O ^has_journal"` - -#### dm.mountopt - -Specifies extra mount options used when mounting the thin devices. - -Example use: `dockerd --storage-opt dm.mountopt=nodiscard` - -#### dm.use_deferred_removal - -Enables use of deferred device removal if `libdm` and the kernel driver -support the mechanism. - -Deferred device removal means that if device is busy when devices are -being removed/deactivated, then a deferred removal is scheduled on -device. And devices automatically go away when last user of the device -exits. - -For example, when a container exits, its associated thin device is removed. If -that device has leaked into some other mount namespace and can't be removed, -the container exit still succeeds and this option causes the system to schedule -the device for deferred removal. It does not wait in a loop trying to remove a -busy device. - -Example use: `dockerd --storage-opt dm.use_deferred_removal=true` - -#### dm.use_deferred_deletion - -Enables use of deferred device deletion for thin pool devices. By default, -thin pool device deletion is synchronous. Before a container is deleted, the -Docker daemon removes any associated devices. If the storage driver can not -remove a device, the container deletion fails and daemon returns. - -`Error deleting container: Error response from daemon: Cannot destroy container` - -To avoid this failure, enable both deferred device deletion and deferred -device removal on the daemon. - -`dockerd --storage-opt dm.use_deferred_deletion=true --storage-opt dm.use_deferred_removal=true` - -With these two options enabled, if a device is busy when the driver is -deleting a container, the driver marks the device as deleted. Later, when the -device isn't in use, the driver deletes it. - -In general it should be safe to enable this option by default. It will help -when unintentional leaking of mount point happens across multiple mount -namespaces. - -#### dm.loopdatasize - -**Note**: This option configures devicemapper loopback, which should not be -used in production. - -Specifies the size to use when creating the loopback file for the "data" device -which is used for the thin pool. The default size is 100G. The file is sparse, -so it will not initially take up this much space. - -Example use: `dockerd --storage-opt dm.loopdatasize=200G` - -#### dm.loopmetadatasize - -**Note**: This option configures devicemapper loopback, which should not be -used in production. - -Specifies the size to use when creating the loopback file for the "metadata" -device which is used for the thin pool. The default size is 2G. The file is -sparse, so it will not initially take up this much space. - -Example use: `dockerd --storage-opt dm.loopmetadatasize=4G` - -#### dm.datadev - -(Deprecated, use `dm.thinpooldev`) - -Specifies a custom blockdevice to use for data for a Docker-managed thin pool. -It is better to use `dm.thinpooldev` - see the documentation for it above for -discussion of the advantages. - -#### dm.metadatadev - -(Deprecated, use `dm.thinpooldev`) - -Specifies a custom blockdevice to use for metadata for a Docker-managed thin -pool. See `dm.datadev` for why this is deprecated. - -#### dm.blocksize - -Specifies a custom blocksize to use for the thin pool. The default -blocksize is 64K. - -Example use: `dockerd --storage-opt dm.blocksize=512K` - -#### dm.blkdiscard - -Enables or disables the use of `blkdiscard` when removing devicemapper devices. -This is disabled by default due to the additional latency, but as a special -case with loopback devices it will be enabled, in order to re-sparsify the -loopback file on image/container removal. - -Disabling this on loopback can lead to *much* faster container removal times, -but it also prevents the space used in `/var/lib/docker` directory from being -returned to the system for other use when containers are removed. - -Example use: `dockerd --storage-opt dm.blkdiscard=false` - -#### dm.override_udev_sync_check - -By default, the devicemapper backend attempts to synchronize with the `udev` -device manager for the Linux kernel. This option allows disabling that -synchronization, to continue even though the configuration may be buggy. - -To view the `udev` sync support of a Docker daemon that is using the -`devicemapper` driver, run: - - $ docker info - [...] - Udev Sync Supported: true - [...] - -When `udev` sync support is `true`, then `devicemapper` and `udev` can -coordinate the activation and deactivation of devices for containers. - -When `udev` sync support is `false`, a race condition occurs between the -`devicemapper` and `udev` during create and cleanup. The race condition results -in errors and failures. (For information on these failures, see -[docker#4036](https://github.com/docker/docker/issues/4036)) - -To allow the `docker` daemon to start, regardless of whether `udev` sync is -`false`, set `dm.override_udev_sync_check` to true: - - $ dockerd --storage-opt dm.override_udev_sync_check=true - -When this value is `true`, the driver continues and simply warns you the errors -are happening. - -**Note**: The ideal is to pursue a `docker` daemon and environment that does -support synchronizing with `udev`. For further discussion on this topic, see -[docker#4036](https://github.com/docker/docker/issues/4036). -Otherwise, set this flag for migrating existing Docker daemons to a daemon with -a supported environment. - -#### dm.min_free_space - -Specifies the min free space percent in a thin pool require for new device -creation to succeed. This check applies to both free data space as well -as free metadata space. Valid values are from 0% - 99%. Value 0% disables -free space checking logic. If user does not specify a value for this option, -the Engine uses a default value of 10%. - -Whenever a new a thin pool device is created (during `docker pull` or during -container creation), the Engine checks if the minimum free space is available. -If the space is unavailable, then device creation fails and any relevant -`docker` operation fails. - -To recover from this error, you must create more free space in the thin pool to -recover from the error. You can create free space by deleting some images and -containers from tge thin pool. You can also add more storage to the thin pool. - -To add more space to an LVM (logical volume management) thin pool, just add -more storage to the group container thin pool; this should automatically -resolve any errors. If your configuration uses loop devices, then stop the -Engine daemon, grow the size of loop files and restart the daemon to resolve -the issue. - -Example use:: `dockerd --storage-opt dm.min_free_space=10%` - -#### dm.xfs_nospace_max_retries - -Specifies the maximum number of retries XFS should attempt to complete IO when -ENOSPC (no space) error is returned by underlying storage device. - -By default XFS retries infinitely for IO to finish and this can result in -unkillable process. To change this behavior one can set xfs_nospace_max_retries -to say 0 and XFS will not retry IO after getting ENOSPC and will shutdown -filesystem. - -Example use: - - $ sudo dockerd --storage-opt dm.xfs_nospace_max_retries=0 - - -## ZFS options - -#### zfs.fsname - -Set zfs filesystem under which docker will create its own datasets. By default -docker will pick up the zfs filesystem where docker graph (`/var/lib/docker`) -is located. - -Example use: `dockerd -s zfs --storage-opt zfs.fsname=zroot/docker` - -## Btrfs options - -#### btrfs.min_space - -Specifies the mininum size to use when creating the subvolume which is used for -containers. If user uses disk quota for btrfs when creating or running a -container with **--storage-opt size** option, docker should ensure the **size** -cannot be smaller than **btrfs.min_space**. - -Example use: `docker daemon -s btrfs --storage-opt btrfs.min_space=10G` - -# CLUSTER STORE OPTIONS - -The daemon uses libkv to advertise the node within the cluster. Some Key/Value -backends support mutual TLS, and the client TLS settings used by the daemon can -be configured using the **--cluster-store-opt** flag, specifying the paths to -PEM encoded files. - -#### kv.cacertfile - -Specifies the path to a local file with PEM encoded CA certificates to trust - -#### kv.certfile - -Specifies the path to a local file with a PEM encoded certificate. This -certificate is used as the client cert for communication with the Key/Value -store. - -#### kv.keyfile - -Specifies the path to a local file with a PEM encoded private key. This -private key is used as the client key for communication with the Key/Value -store. - -# Access authorization - -Docker's access authorization can be extended by authorization plugins that -your organization can purchase or build themselves. You can install one or more -authorization plugins when you start the Docker `daemon` using the -`--authorization-plugin=PLUGIN_ID` option. - -```bash -dockerd --authorization-plugin=plugin1 --authorization-plugin=plugin2,... -``` - -The `PLUGIN_ID` value is either the plugin's name or a path to its -specification file. The plugin's implementation determines whether you can -specify a name or path. Consult with your Docker administrator to get -information about the plugins available to you. - -Once a plugin is installed, requests made to the `daemon` through the command -line or Docker's Engine API are allowed or denied by the plugin. If you have -multiple plugins installed, at least one must allow the request for it to -complete. - -For information about how to create an authorization plugin, see [authorization -plugin](https://docs.docker.com/engine/extend/authorization/) section in the -Docker extend section of this documentation. - - -# HISTORY -Sept 2015, Originally compiled by Shishir Mahajan -based on docker.com source material and internal work. diff --git a/vendor/github.com/docker/docker/man/generate.go b/vendor/github.com/docker/docker/man/generate.go deleted file mode 100644 index f21614d..0000000 --- a/vendor/github.com/docker/docker/man/generate.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/docker/docker/cli/command" - "github.com/docker/docker/cli/command/commands" - "github.com/docker/docker/pkg/term" - "github.com/spf13/cobra" - "github.com/spf13/cobra/doc" -) - -func generateManPages(path string) error { - header := &doc.GenManHeader{ - Title: "DOCKER", - Section: "1", - Source: "Docker Community", - } - - stdin, stdout, stderr := term.StdStreams() - dockerCli := command.NewDockerCli(stdin, stdout, stderr) - cmd := &cobra.Command{Use: "docker"} - commands.AddCommands(cmd, dockerCli) - - cmd.DisableAutoGenTag = true - return doc.GenManTreeFromOpts(cmd, doc.GenManTreeOptions{ - Header: header, - Path: path, - CommandSeparator: "-", - }) -} - -func main() { - path := "/tmp" - if len(os.Args) > 1 { - path = os.Args[1] - } - fmt.Printf("Generating man pages into %s\n", path) - if err := generateManPages(path); err != nil { - fmt.Fprintf(os.Stderr, "Failed to generate man pages: %s\n", err.Error()) - } -} diff --git a/vendor/github.com/docker/docker/man/generate.sh b/vendor/github.com/docker/docker/man/generate.sh deleted file mode 100755 index e4126ba..0000000 --- a/vendor/github.com/docker/docker/man/generate.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -# -# Generate man pages for docker/docker -# - -set -eu - -mkdir -p ./man/man1 - -# Generate man pages from cobra commands -go build -o /tmp/gen-manpages ./man -/tmp/gen-manpages ./man/man1 - -# Generate legacy pages from markdown -./man/md2man-all.sh -q diff --git a/vendor/github.com/docker/docker/man/glide.lock b/vendor/github.com/docker/docker/man/glide.lock deleted file mode 100644 index 5ec765a..0000000 --- a/vendor/github.com/docker/docker/man/glide.lock +++ /dev/null @@ -1,52 +0,0 @@ -hash: ead3ea293a6143fe41069ebec814bf197d8c43a92cc7666b1f7e21a419b46feb -updated: 2016-06-20T21:53:35.420817456Z -imports: -- name: github.com/BurntSushi/toml - version: f0aeabca5a127c4078abb8c8d64298b147264b55 -- name: github.com/cpuguy83/go-md2man - version: a65d4d2de4d5f7c74868dfa9b202a3c8be315aaa - subpackages: - - md2man -- name: github.com/fsnotify/fsnotify - version: 30411dbcefb7a1da7e84f75530ad3abe4011b4f8 -- name: github.com/hashicorp/hcl - version: da486364306ed66c218be9b7953e19173447c18b - subpackages: - - hcl/ast - - hcl/parser - - hcl/token - - json/parser - - hcl/scanner - - hcl/strconv - - json/scanner - - json/token -- name: github.com/inconshreveable/mousetrap - version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 -- name: github.com/magiconair/properties - version: c265cfa48dda6474e208715ca93e987829f572f8 -- name: github.com/mitchellh/mapstructure - version: d2dd0262208475919e1a362f675cfc0e7c10e905 -- name: github.com/russross/blackfriday - version: 1d6b8e9301e720b08a8938b8c25c018285885438 -- name: github.com/shurcooL/sanitized_anchor_name - version: 10ef21a441db47d8b13ebcc5fd2310f636973c77 -- name: github.com/spf13/cast - version: 27b586b42e29bec072fe7379259cc719e1289da6 -- name: github.com/spf13/jwalterweatherman - version: 33c24e77fb80341fe7130ee7c594256ff08ccc46 -- name: github.com/spf13/pflag - version: dabebe21bf790f782ea4c7bbd2efc430de182afd -- name: github.com/spf13/viper - version: c1ccc378a054ea8d4e38d8c67f6938d4760b53dd -- name: golang.org/x/sys - version: 62bee037599929a6e9146f29d10dd5208c43507d - subpackages: - - unix -- name: gopkg.in/yaml.v2 - version: a83829b6f1293c91addabc89d0571c246397bbf4 -- name: github.com/spf13/cobra - repo: https://github.com/dnephin/cobra - subpackages: - - doc - version: v1.3 -devImports: [] diff --git a/vendor/github.com/docker/docker/man/glide.yaml b/vendor/github.com/docker/docker/man/glide.yaml deleted file mode 100644 index e99b267..0000000 --- a/vendor/github.com/docker/docker/man/glide.yaml +++ /dev/null @@ -1,12 +0,0 @@ -package: github.com/docker/docker/man -import: -- package: github.com/cpuguy83/go-md2man - subpackages: - - md2man -- package: github.com/inconshreveable/mousetrap -- package: github.com/spf13/pflag -- package: github.com/spf13/viper -- package: github.com/spf13/cobra - repo: https://github.com/dnephin/cobra - subpackages: - - doc diff --git a/vendor/github.com/docker/docker/man/md2man-all.sh b/vendor/github.com/docker/docker/man/md2man-all.sh deleted file mode 100755 index 97c65c9..0000000 --- a/vendor/github.com/docker/docker/man/md2man-all.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -set -e - -# get into this script's directory -cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" - -[ "$1" = '-q' ] || { - set -x - pwd -} - -for FILE in *.md; do - base="$(basename "$FILE")" - name="${base%.md}" - num="${name##*.}" - if [ -z "$num" -o "$name" = "$num" ]; then - # skip files that aren't of the format xxxx.N.md (like README.md) - continue - fi - mkdir -p "./man${num}" - go-md2man -in "$FILE" -out "./man${num}/${name}" -done diff --git a/vendor/github.com/docker/docker/migrate/v1/migratev1.go b/vendor/github.com/docker/docker/migrate/v1/migratev1.go deleted file mode 100644 index bc42dd2..0000000 --- a/vendor/github.com/docker/docker/migrate/v1/migratev1.go +++ /dev/null @@ -1,504 +0,0 @@ -package v1 - -import ( - "errors" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "runtime" - "strconv" - "sync" - "time" - - "encoding/json" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/image" - imagev1 "github.com/docker/docker/image/v1" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/reference" -) - -type graphIDRegistrar interface { - RegisterByGraphID(string, layer.ChainID, layer.DiffID, string, int64) (layer.Layer, error) - Release(layer.Layer) ([]layer.Metadata, error) -} - -type graphIDMounter interface { - CreateRWLayerByGraphID(string, string, layer.ChainID) error -} - -type checksumCalculator interface { - ChecksumForGraphID(id, parent, oldTarDataPath, newTarDataPath string) (diffID layer.DiffID, size int64, err error) -} - -const ( - graphDirName = "graph" - tarDataFileName = "tar-data.json.gz" - migrationFileName = ".migration-v1-images.json" - migrationTagsFileName = ".migration-v1-tags" - migrationDiffIDFileName = ".migration-diffid" - migrationSizeFileName = ".migration-size" - migrationTarDataFileName = ".migration-tardata" - containersDirName = "containers" - configFileNameLegacy = "config.json" - configFileName = "config.v2.json" - repositoriesFilePrefixLegacy = "repositories-" -) - -var ( - errUnsupported = errors.New("migration is not supported") -) - -// Migrate takes an old graph directory and transforms the metadata into the -// new format. -func Migrate(root, driverName string, ls layer.Store, is image.Store, rs reference.Store, ms metadata.Store) error { - graphDir := filepath.Join(root, graphDirName) - if _, err := os.Lstat(graphDir); os.IsNotExist(err) { - return nil - } - - mappings, err := restoreMappings(root) - if err != nil { - return err - } - - if cc, ok := ls.(checksumCalculator); ok { - CalculateLayerChecksums(root, cc, mappings) - } - - if registrar, ok := ls.(graphIDRegistrar); !ok { - return errUnsupported - } else if err := migrateImages(root, registrar, is, ms, mappings); err != nil { - return err - } - - err = saveMappings(root, mappings) - if err != nil { - return err - } - - if mounter, ok := ls.(graphIDMounter); !ok { - return errUnsupported - } else if err := migrateContainers(root, mounter, is, mappings); err != nil { - return err - } - - if err := migrateRefs(root, driverName, rs, mappings); err != nil { - return err - } - - return nil -} - -// CalculateLayerChecksums walks an old graph directory and calculates checksums -// for each layer. These checksums are later used for migration. -func CalculateLayerChecksums(root string, ls checksumCalculator, mappings map[string]image.ID) { - graphDir := filepath.Join(root, graphDirName) - // spawn some extra workers also for maximum performance because the process is bounded by both cpu and io - workers := runtime.NumCPU() * 3 - workQueue := make(chan string, workers) - - wg := sync.WaitGroup{} - - for i := 0; i < workers; i++ { - wg.Add(1) - go func() { - for id := range workQueue { - start := time.Now() - if err := calculateLayerChecksum(graphDir, id, ls); err != nil { - logrus.Errorf("could not calculate checksum for %q, %q", id, err) - } - elapsed := time.Since(start) - logrus.Debugf("layer %s took %.2f seconds", id, elapsed.Seconds()) - } - wg.Done() - }() - } - - dir, err := ioutil.ReadDir(graphDir) - if err != nil { - logrus.Errorf("could not read directory %q", graphDir) - return - } - for _, v := range dir { - v1ID := v.Name() - if err := imagev1.ValidateID(v1ID); err != nil { - continue - } - if _, ok := mappings[v1ID]; ok { // support old migrations without helper files - continue - } - workQueue <- v1ID - } - close(workQueue) - wg.Wait() -} - -func calculateLayerChecksum(graphDir, id string, ls checksumCalculator) error { - diffIDFile := filepath.Join(graphDir, id, migrationDiffIDFileName) - if _, err := os.Lstat(diffIDFile); err == nil { - return nil - } else if !os.IsNotExist(err) { - return err - } - - parent, err := getParent(filepath.Join(graphDir, id)) - if err != nil { - return err - } - - diffID, size, err := ls.ChecksumForGraphID(id, parent, filepath.Join(graphDir, id, tarDataFileName), filepath.Join(graphDir, id, migrationTarDataFileName)) - if err != nil { - return err - } - - if err := ioutil.WriteFile(filepath.Join(graphDir, id, migrationSizeFileName), []byte(strconv.Itoa(int(size))), 0600); err != nil { - return err - } - - if err := ioutils.AtomicWriteFile(filepath.Join(graphDir, id, migrationDiffIDFileName), []byte(diffID), 0600); err != nil { - return err - } - - logrus.Infof("calculated checksum for layer %s: %s", id, diffID) - return nil -} - -func restoreMappings(root string) (map[string]image.ID, error) { - mappings := make(map[string]image.ID) - - mfile := filepath.Join(root, migrationFileName) - f, err := os.Open(mfile) - if err != nil && !os.IsNotExist(err) { - return nil, err - } else if err == nil { - err := json.NewDecoder(f).Decode(&mappings) - if err != nil { - f.Close() - return nil, err - } - f.Close() - } - - return mappings, nil -} - -func saveMappings(root string, mappings map[string]image.ID) error { - mfile := filepath.Join(root, migrationFileName) - f, err := os.OpenFile(mfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - return err - } - defer f.Close() - if err := json.NewEncoder(f).Encode(mappings); err != nil { - return err - } - return nil -} - -func migrateImages(root string, ls graphIDRegistrar, is image.Store, ms metadata.Store, mappings map[string]image.ID) error { - graphDir := filepath.Join(root, graphDirName) - - dir, err := ioutil.ReadDir(graphDir) - if err != nil { - return err - } - for _, v := range dir { - v1ID := v.Name() - if err := imagev1.ValidateID(v1ID); err != nil { - continue - } - if _, exists := mappings[v1ID]; exists { - continue - } - if err := migrateImage(v1ID, root, ls, is, ms, mappings); err != nil { - continue - } - } - - return nil -} - -func migrateContainers(root string, ls graphIDMounter, is image.Store, imageMappings map[string]image.ID) error { - containersDir := filepath.Join(root, containersDirName) - dir, err := ioutil.ReadDir(containersDir) - if err != nil { - return err - } - for _, v := range dir { - id := v.Name() - - if _, err := os.Stat(filepath.Join(containersDir, id, configFileName)); err == nil { - continue - } - - containerJSON, err := ioutil.ReadFile(filepath.Join(containersDir, id, configFileNameLegacy)) - if err != nil { - logrus.Errorf("migrate container error: %v", err) - continue - } - - var c map[string]*json.RawMessage - if err := json.Unmarshal(containerJSON, &c); err != nil { - logrus.Errorf("migrate container error: %v", err) - continue - } - - imageStrJSON, ok := c["Image"] - if !ok { - return fmt.Errorf("invalid container configuration for %v", id) - } - - var image string - if err := json.Unmarshal([]byte(*imageStrJSON), &image); err != nil { - logrus.Errorf("migrate container error: %v", err) - continue - } - - imageID, ok := imageMappings[image] - if !ok { - logrus.Errorf("image not migrated %v", imageID) // non-fatal error - continue - } - - c["Image"] = rawJSON(imageID) - - containerJSON, err = json.Marshal(c) - if err != nil { - return err - } - - if err := ioutil.WriteFile(filepath.Join(containersDir, id, configFileName), containerJSON, 0600); err != nil { - return err - } - - img, err := is.Get(imageID) - if err != nil { - return err - } - - if err := ls.CreateRWLayerByGraphID(id, id, img.RootFS.ChainID()); err != nil { - logrus.Errorf("migrate container error: %v", err) - continue - } - - logrus.Infof("migrated container %s to point to %s", id, imageID) - - } - return nil -} - -type refAdder interface { - AddTag(ref reference.Named, id digest.Digest, force bool) error - AddDigest(ref reference.Canonical, id digest.Digest, force bool) error -} - -func migrateRefs(root, driverName string, rs refAdder, mappings map[string]image.ID) error { - migrationFile := filepath.Join(root, migrationTagsFileName) - if _, err := os.Lstat(migrationFile); !os.IsNotExist(err) { - return err - } - - type repositories struct { - Repositories map[string]map[string]string - } - - var repos repositories - - f, err := os.Open(filepath.Join(root, repositoriesFilePrefixLegacy+driverName)) - if err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - defer f.Close() - if err := json.NewDecoder(f).Decode(&repos); err != nil { - return err - } - - for name, repo := range repos.Repositories { - for tag, id := range repo { - if strongID, exists := mappings[id]; exists { - ref, err := reference.WithName(name) - if err != nil { - logrus.Errorf("migrate tags: invalid name %q, %q", name, err) - continue - } - if dgst, err := digest.ParseDigest(tag); err == nil { - canonical, err := reference.WithDigest(reference.TrimNamed(ref), dgst) - if err != nil { - logrus.Errorf("migrate tags: invalid digest %q, %q", dgst, err) - continue - } - if err := rs.AddDigest(canonical, strongID.Digest(), false); err != nil { - logrus.Errorf("can't migrate digest %q for %q, err: %q", ref.String(), strongID, err) - } - } else { - tagRef, err := reference.WithTag(ref, tag) - if err != nil { - logrus.Errorf("migrate tags: invalid tag %q, %q", tag, err) - continue - } - if err := rs.AddTag(tagRef, strongID.Digest(), false); err != nil { - logrus.Errorf("can't migrate tag %q for %q, err: %q", ref.String(), strongID, err) - } - } - logrus.Infof("migrated tag %s:%s to point to %s", name, tag, strongID) - } - } - } - - mf, err := os.Create(migrationFile) - if err != nil { - return err - } - mf.Close() - - return nil -} - -func getParent(confDir string) (string, error) { - jsonFile := filepath.Join(confDir, "json") - imageJSON, err := ioutil.ReadFile(jsonFile) - if err != nil { - return "", err - } - var parent struct { - Parent string - ParentID digest.Digest `json:"parent_id"` - } - if err := json.Unmarshal(imageJSON, &parent); err != nil { - return "", err - } - if parent.Parent == "" && parent.ParentID != "" { // v1.9 - parent.Parent = parent.ParentID.Hex() - } - // compatibilityID for parent - parentCompatibilityID, err := ioutil.ReadFile(filepath.Join(confDir, "parent")) - if err == nil && len(parentCompatibilityID) > 0 { - parent.Parent = string(parentCompatibilityID) - } - return parent.Parent, nil -} - -func migrateImage(id, root string, ls graphIDRegistrar, is image.Store, ms metadata.Store, mappings map[string]image.ID) (err error) { - defer func() { - if err != nil { - logrus.Errorf("migration failed for %v, err: %v", id, err) - } - }() - - parent, err := getParent(filepath.Join(root, graphDirName, id)) - if err != nil { - return err - } - - var parentID image.ID - if parent != "" { - var exists bool - if parentID, exists = mappings[parent]; !exists { - if err := migrateImage(parent, root, ls, is, ms, mappings); err != nil { - // todo: fail or allow broken chains? - return err - } - parentID = mappings[parent] - } - } - - rootFS := image.NewRootFS() - var history []image.History - - if parentID != "" { - parentImg, err := is.Get(parentID) - if err != nil { - return err - } - - rootFS = parentImg.RootFS - history = parentImg.History - } - - diffIDData, err := ioutil.ReadFile(filepath.Join(root, graphDirName, id, migrationDiffIDFileName)) - if err != nil { - return err - } - diffID, err := digest.ParseDigest(string(diffIDData)) - if err != nil { - return err - } - - sizeStr, err := ioutil.ReadFile(filepath.Join(root, graphDirName, id, migrationSizeFileName)) - if err != nil { - return err - } - size, err := strconv.ParseInt(string(sizeStr), 10, 64) - if err != nil { - return err - } - - layer, err := ls.RegisterByGraphID(id, rootFS.ChainID(), layer.DiffID(diffID), filepath.Join(root, graphDirName, id, migrationTarDataFileName), size) - if err != nil { - return err - } - logrus.Infof("migrated layer %s to %s", id, layer.DiffID()) - - jsonFile := filepath.Join(root, graphDirName, id, "json") - imageJSON, err := ioutil.ReadFile(jsonFile) - if err != nil { - return err - } - - h, err := imagev1.HistoryFromConfig(imageJSON, false) - if err != nil { - return err - } - history = append(history, h) - - rootFS.Append(layer.DiffID()) - - config, err := imagev1.MakeConfigFromV1Config(imageJSON, rootFS, history) - if err != nil { - return err - } - strongID, err := is.Create(config) - if err != nil { - return err - } - logrus.Infof("migrated image %s to %s", id, strongID) - - if parentID != "" { - if err := is.SetParent(strongID, parentID); err != nil { - return err - } - } - - checksum, err := ioutil.ReadFile(filepath.Join(root, graphDirName, id, "checksum")) - if err == nil { // best effort - dgst, err := digest.ParseDigest(string(checksum)) - if err == nil { - V2MetadataService := metadata.NewV2MetadataService(ms) - V2MetadataService.Add(layer.DiffID(), metadata.V2Metadata{Digest: dgst}) - } - } - _, err = ls.Release(layer) - if err != nil { - return err - } - - mappings[id] = strongID - return -} - -func rawJSON(value interface{}) *json.RawMessage { - jsonval, err := json.Marshal(value) - if err != nil { - return nil - } - return (*json.RawMessage)(&jsonval) -} diff --git a/vendor/github.com/docker/docker/migrate/v1/migratev1_test.go b/vendor/github.com/docker/docker/migrate/v1/migratev1_test.go deleted file mode 100644 index be82fdc..0000000 --- a/vendor/github.com/docker/docker/migrate/v1/migratev1_test.go +++ /dev/null @@ -1,438 +0,0 @@ -package v1 - -import ( - "crypto/rand" - "encoding/hex" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "reflect" - "runtime" - "testing" - - "github.com/docker/distribution/digest" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/reference" -) - -func TestMigrateRefs(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "migrate-tags") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - ioutil.WriteFile(filepath.Join(tmpdir, "repositories-generic"), []byte(`{"Repositories":{"busybox":{"latest":"b3ca410aa2c115c05969a7b2c8cf8a9fcf62c1340ed6a601c9ee50df337ec108","sha256:16a2a52884c2a9481ed267c2d46483eac7693b813a63132368ab098a71303f8a":"b3ca410aa2c115c05969a7b2c8cf8a9fcf62c1340ed6a601c9ee50df337ec108"},"registry":{"2":"5d165b8e4b203685301c815e95663231691d383fd5e3d3185d1ce3f8dddead3d","latest":"8d5547a9f329b1d3f93198cd661fb5117e5a96b721c5cf9a2c389e7dd4877128"}}}`), 0600) - - ta := &mockTagAdder{} - err = migrateRefs(tmpdir, "generic", ta, map[string]image.ID{ - "5d165b8e4b203685301c815e95663231691d383fd5e3d3185d1ce3f8dddead3d": image.ID("sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"), - "b3ca410aa2c115c05969a7b2c8cf8a9fcf62c1340ed6a601c9ee50df337ec108": image.ID("sha256:fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"), - "abcdef3434c115c05969a7b2c8cf8a9fcf62c1340ed6a601c9ee50df337ec108": image.ID("sha256:56434342345ae68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"), - }) - if err != nil { - t.Fatal(err) - } - - expected := map[string]string{ - "busybox:latest": "sha256:fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9", - "busybox@sha256:16a2a52884c2a9481ed267c2d46483eac7693b813a63132368ab098a71303f8a": "sha256:fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9", - "registry:2": "sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae", - } - - if !reflect.DeepEqual(expected, ta.refs) { - t.Fatalf("Invalid migrated tags: expected %q, got %q", expected, ta.refs) - } - - // second migration is no-op - ioutil.WriteFile(filepath.Join(tmpdir, "repositories-generic"), []byte(`{"Repositories":{"busybox":{"latest":"b3ca410aa2c115c05969a7b2c8cf8a9fcf62c1340ed6a601c9ee50df337ec108"`), 0600) - err = migrateRefs(tmpdir, "generic", ta, map[string]image.ID{ - "b3ca410aa2c115c05969a7b2c8cf8a9fcf62c1340ed6a601c9ee50df337ec108": image.ID("sha256:fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"), - }) - if err != nil { - t.Fatal(err) - } - if !reflect.DeepEqual(expected, ta.refs) { - t.Fatalf("Invalid migrated tags: expected %q, got %q", expected, ta.refs) - } -} - -func TestMigrateContainers(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - if runtime.GOARCH != "amd64" { - t.Skip("Test tailored to amd64 architecture") - } - tmpdir, err := ioutil.TempDir("", "migrate-containers") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - err = addContainer(tmpdir, `{"State":{"Running":false,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":0,"ExitCode":0,"Error":"","StartedAt":"2015-11-10T21:42:40.604267436Z","FinishedAt":"2015-11-10T21:42:41.869265487Z"},"ID":"f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c","Created":"2015-11-10T21:42:40.433831551Z","Path":"sh","Args":[],"Config":{"Hostname":"f780ee3f80e6","Domainname":"","User":"","AttachStdin":true,"AttachStdout":true,"AttachStderr":true,"Tty":true,"OpenStdin":true,"StdinOnce":true,"Env":null,"Cmd":["sh"],"Image":"busybox","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":{}},"Image":"2c5ac3f849df8627fcf2822727f87c57f38b7129d3604fbc11d861fe856ff093","NetworkSettings":{"Bridge":"","EndpointID":"","Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"HairpinMode":false,"IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","LinkLocalIPv6Address":"","LinkLocalIPv6PrefixLen":0,"MacAddress":"","NetworkID":"","PortMapping":null,"Ports":null,"SandboxKey":"","SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null},"ResolvConfPath":"/var/lib/docker/containers/f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c/resolv.conf","HostnamePath":"/var/lib/docker/containers/f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c/hostname","HostsPath":"/var/lib/docker/containers/f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c/hosts","LogPath":"/var/lib/docker/containers/f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c/f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c-json.log","Name":"/determined_euclid","Driver":"overlay","ExecDriver":"native-0.2","MountLabel":"","ProcessLabel":"","RestartCount":0,"UpdateDns":false,"HasBeenStartedBefore":false,"MountPoints":{},"Volumes":{},"VolumesRW":{},"AppArmorProfile":""}`) - if err != nil { - t.Fatal(err) - } - - // container with invalid image - err = addContainer(tmpdir, `{"State":{"Running":false,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":0,"ExitCode":0,"Error":"","StartedAt":"2015-11-10T21:42:40.604267436Z","FinishedAt":"2015-11-10T21:42:41.869265487Z"},"ID":"e780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c","Created":"2015-11-10T21:42:40.433831551Z","Path":"sh","Args":[],"Config":{"Hostname":"f780ee3f80e6","Domainname":"","User":"","AttachStdin":true,"AttachStdout":true,"AttachStderr":true,"Tty":true,"OpenStdin":true,"StdinOnce":true,"Env":null,"Cmd":["sh"],"Image":"busybox","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":{}},"Image":"4c5ac3f849df8627fcf2822727f87c57f38b7129d3604fbc11d861fe856ff093","NetworkSettings":{"Bridge":"","EndpointID":"","Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"HairpinMode":false,"IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","LinkLocalIPv6Address":"","LinkLocalIPv6PrefixLen":0,"MacAddress":"","NetworkID":"","PortMapping":null,"Ports":null,"SandboxKey":"","SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null},"ResolvConfPath":"/var/lib/docker/containers/f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c/resolv.conf","HostnamePath":"/var/lib/docker/containers/f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c/hostname","HostsPath":"/var/lib/docker/containers/f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c/hosts","LogPath":"/var/lib/docker/containers/f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c/f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c-json.log","Name":"/determined_euclid","Driver":"overlay","ExecDriver":"native-0.2","MountLabel":"","ProcessLabel":"","RestartCount":0,"UpdateDns":false,"HasBeenStartedBefore":false,"MountPoints":{},"Volumes":{},"VolumesRW":{},"AppArmorProfile":""}`) - if err != nil { - t.Fatal(err) - } - - ls := &mockMounter{} - - ifs, err := image.NewFSStoreBackend(filepath.Join(tmpdir, "imagedb")) - if err != nil { - t.Fatal(err) - } - - is, err := image.NewImageStore(ifs, ls) - if err != nil { - t.Fatal(err) - } - - imgID, err := is.Create([]byte(`{"architecture":"amd64","config":{"AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Cmd":["sh"],"Entrypoint":null,"Env":null,"Hostname":"23304fc829f9","Image":"d1592a710ac323612bd786fa8ac20727c58d8a67847e5a65177c594f43919498","Labels":null,"OnBuild":null,"OpenStdin":false,"StdinOnce":false,"Tty":false,"Volumes":null,"WorkingDir":"","Domainname":"","User":""},"container":"349b014153779e30093d94f6df2a43c7a0a164e05aa207389917b540add39b51","container_config":{"AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Cmd":["/bin/sh","-c","#(nop) CMD [\"sh\"]"],"Entrypoint":null,"Env":null,"Hostname":"23304fc829f9","Image":"d1592a710ac323612bd786fa8ac20727c58d8a67847e5a65177c594f43919498","Labels":null,"OnBuild":null,"OpenStdin":false,"StdinOnce":false,"Tty":false,"Volumes":null,"WorkingDir":"","Domainname":"","User":""},"created":"2015-10-31T22:22:55.613815829Z","docker_version":"1.8.2","history":[{"created":"2015-10-31T22:22:54.690851953Z","created_by":"/bin/sh -c #(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /"},{"created":"2015-10-31T22:22:55.613815829Z","created_by":"/bin/sh -c #(nop) CMD [\"sh\"]"}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1","sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"]}}`)) - if err != nil { - t.Fatal(err) - } - - err = migrateContainers(tmpdir, ls, is, map[string]image.ID{ - "2c5ac3f849df8627fcf2822727f87c57f38b7129d3604fbc11d861fe856ff093": imgID, - }) - if err != nil { - t.Fatal(err) - } - - expected := []mountInfo{{ - "f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c", - "f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c", - "sha256:c3191d32a37d7159b2e30830937d2e30268ad6c375a773a8994911a3aba9b93f", - }} - if !reflect.DeepEqual(expected, ls.mounts) { - t.Fatalf("invalid mounts: expected %q, got %q", expected, ls.mounts) - } - - if actual, expected := ls.count, 0; actual != expected { - t.Fatalf("invalid active mounts: expected %d, got %d", expected, actual) - } - - config2, err := ioutil.ReadFile(filepath.Join(tmpdir, "containers", "f780ee3f80e66e9b432a57049597118a66aab8932be88e5628d4c824edbee37c", "config.v2.json")) - if err != nil { - t.Fatal(err) - } - var config struct{ Image string } - err = json.Unmarshal(config2, &config) - if err != nil { - t.Fatal(err) - } - - if actual, expected := config.Image, string(imgID); actual != expected { - t.Fatalf("invalid image pointer in migrated config: expected %q, got %q", expected, actual) - } - -} - -func TestMigrateImages(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - if runtime.GOARCH != "amd64" { - t.Skip("Test tailored to amd64 architecture") - } - tmpdir, err := ioutil.TempDir("", "migrate-images") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - // busybox from 1.9 - id1, err := addImage(tmpdir, `{"architecture":"amd64","config":{"Hostname":"23304fc829f9","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":null,"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"container":"23304fc829f9b9349416f6eb1afec162907eba3a328f51d53a17f8986f865d65","container_config":{"Hostname":"23304fc829f9","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":["/bin/sh","-c","#(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /"],"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"created":"2015-10-31T22:22:54.690851953Z","docker_version":"1.8.2","layer_id":"sha256:55dc925c23d1ed82551fd018c27ac3ee731377b6bad3963a2a4e76e753d70e57","os":"linux"}`, "", "") - if err != nil { - t.Fatal(err) - } - - id2, err := addImage(tmpdir, `{"architecture":"amd64","config":{"Hostname":"23304fc829f9","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":["sh"],"Image":"d1592a710ac323612bd786fa8ac20727c58d8a67847e5a65177c594f43919498","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"container":"349b014153779e30093d94f6df2a43c7a0a164e05aa207389917b540add39b51","container_config":{"Hostname":"23304fc829f9","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":["/bin/sh","-c","#(nop) CMD [\"sh\"]"],"Image":"d1592a710ac323612bd786fa8ac20727c58d8a67847e5a65177c594f43919498","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"created":"2015-10-31T22:22:55.613815829Z","docker_version":"1.8.2","layer_id":"sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4","os":"linux","parent_id":"sha256:039b63dd2cbaa10d6015ea574392530571ed8d7b174090f032211285a71881d0"}`, id1, "") - if err != nil { - t.Fatal(err) - } - - ls := &mockRegistrar{} - - ifs, err := image.NewFSStoreBackend(filepath.Join(tmpdir, "imagedb")) - if err != nil { - t.Fatal(err) - } - - is, err := image.NewImageStore(ifs, ls) - if err != nil { - t.Fatal(err) - } - - ms, err := metadata.NewFSMetadataStore(filepath.Join(tmpdir, "distribution")) - if err != nil { - t.Fatal(err) - } - mappings := make(map[string]image.ID) - - err = migrateImages(tmpdir, ls, is, ms, mappings) - if err != nil { - t.Fatal(err) - } - - expected := map[string]image.ID{ - id1: image.ID("sha256:ca406eaf9c26898414ff5b7b3a023c33310759d6203be0663dbf1b3a712f432d"), - id2: image.ID("sha256:a488bec94bb96b26a968f913d25ef7d8d204d727ca328b52b4b059c7d03260b6"), - } - - if !reflect.DeepEqual(mappings, expected) { - t.Fatalf("invalid image mappings: expected %q, got %q", expected, mappings) - } - - if actual, expected := ls.count, 2; actual != expected { - t.Fatalf("invalid register count: expected %q, got %q", expected, actual) - } - ls.count = 0 - - // next images are busybox from 1.8.2 - _, err = addImage(tmpdir, `{"id":"17583c7dd0dae6244203b8029733bdb7d17fccbb2b5d93e2b24cf48b8bfd06e2","parent":"d1592a710ac323612bd786fa8ac20727c58d8a67847e5a65177c594f43919498","created":"2015-10-31T22:22:55.613815829Z","container":"349b014153779e30093d94f6df2a43c7a0a164e05aa207389917b540add39b51","container_config":{"Hostname":"23304fc829f9","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":null,"PublishService":"","Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":["/bin/sh","-c","#(nop) CMD [\"sh\"]"],"Image":"d1592a710ac323612bd786fa8ac20727c58d8a67847e5a65177c594f43919498","Volumes":null,"VolumeDriver":"","WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"MacAddress":"","OnBuild":null,"Labels":null},"docker_version":"1.8.2","config":{"Hostname":"23304fc829f9","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":null,"PublishService":"","Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":["sh"],"Image":"d1592a710ac323612bd786fa8ac20727c58d8a67847e5a65177c594f43919498","Volumes":null,"VolumeDriver":"","WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"MacAddress":"","OnBuild":null,"Labels":null},"architecture":"amd64","os":"linux","Size":0}`, "", "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4") - if err != nil { - t.Fatal(err) - } - - _, err = addImage(tmpdir, `{"id":"d1592a710ac323612bd786fa8ac20727c58d8a67847e5a65177c594f43919498","created":"2015-10-31T22:22:54.690851953Z","container":"23304fc829f9b9349416f6eb1afec162907eba3a328f51d53a17f8986f865d65","container_config":{"Hostname":"23304fc829f9","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":null,"PublishService":"","Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":["/bin/sh","-c","#(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /"],"Image":"","Volumes":null,"VolumeDriver":"","WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"MacAddress":"","OnBuild":null,"Labels":null},"docker_version":"1.8.2","config":{"Hostname":"23304fc829f9","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":null,"PublishService":"","Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":null,"Image":"","Volumes":null,"VolumeDriver":"","WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"MacAddress":"","OnBuild":null,"Labels":null},"architecture":"amd64","os":"linux","Size":1108935}`, "", "sha256:55dc925c23d1ed82551fd018c27ac3ee731377b6bad3963a2a4e76e753d70e57") - if err != nil { - t.Fatal(err) - } - - err = migrateImages(tmpdir, ls, is, ms, mappings) - if err != nil { - t.Fatal(err) - } - - expected["d1592a710ac323612bd786fa8ac20727c58d8a67847e5a65177c594f43919498"] = image.ID("sha256:c091bb33854e57e6902b74c08719856d30b5593c7db6143b2b48376b8a588395") - expected["17583c7dd0dae6244203b8029733bdb7d17fccbb2b5d93e2b24cf48b8bfd06e2"] = image.ID("sha256:d963020e755ff2715b936065949472c1f8a6300144b922992a1a421999e71f07") - - if actual, expected := ls.count, 2; actual != expected { - t.Fatalf("invalid register count: expected %q, got %q", expected, actual) - } - - v2MetadataService := metadata.NewV2MetadataService(ms) - receivedMetadata, err := v2MetadataService.GetMetadata(layer.EmptyLayer.DiffID()) - if err != nil { - t.Fatal(err) - } - - expectedMetadata := []metadata.V2Metadata{ - {Digest: digest.Digest("sha256:55dc925c23d1ed82551fd018c27ac3ee731377b6bad3963a2a4e76e753d70e57")}, - {Digest: digest.Digest("sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4")}, - } - - if !reflect.DeepEqual(expectedMetadata, receivedMetadata) { - t.Fatalf("invalid metadata: expected %q, got %q", expectedMetadata, receivedMetadata) - } - -} - -func TestMigrateUnsupported(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "migrate-empty") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - err = os.MkdirAll(filepath.Join(tmpdir, "graph"), 0700) - if err != nil { - t.Fatal(err) - } - - err = Migrate(tmpdir, "generic", nil, nil, nil, nil) - if err != errUnsupported { - t.Fatalf("expected unsupported error, got %q", err) - } -} - -func TestMigrateEmptyDir(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "migrate-empty") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - err = Migrate(tmpdir, "generic", nil, nil, nil, nil) - if err != nil { - t.Fatal(err) - } -} - -func addImage(dest, jsonConfig, parent, checksum string) (string, error) { - var config struct{ ID string } - if err := json.Unmarshal([]byte(jsonConfig), &config); err != nil { - return "", err - } - if config.ID == "" { - b := make([]byte, 32) - rand.Read(b) - config.ID = hex.EncodeToString(b) - } - contDir := filepath.Join(dest, "graph", config.ID) - if err := os.MkdirAll(contDir, 0700); err != nil { - return "", err - } - if err := ioutil.WriteFile(filepath.Join(contDir, "json"), []byte(jsonConfig), 0600); err != nil { - return "", err - } - if checksum != "" { - if err := ioutil.WriteFile(filepath.Join(contDir, "checksum"), []byte(checksum), 0600); err != nil { - return "", err - } - } - if err := ioutil.WriteFile(filepath.Join(contDir, ".migration-diffid"), []byte(layer.EmptyLayer.DiffID()), 0600); err != nil { - return "", err - } - if err := ioutil.WriteFile(filepath.Join(contDir, ".migration-size"), []byte("0"), 0600); err != nil { - return "", err - } - if parent != "" { - if err := ioutil.WriteFile(filepath.Join(contDir, "parent"), []byte(parent), 0600); err != nil { - return "", err - } - } - if checksum != "" { - if err := ioutil.WriteFile(filepath.Join(contDir, "checksum"), []byte(checksum), 0600); err != nil { - return "", err - } - } - return config.ID, nil -} - -func addContainer(dest, jsonConfig string) error { - var config struct{ ID string } - if err := json.Unmarshal([]byte(jsonConfig), &config); err != nil { - return err - } - contDir := filepath.Join(dest, "containers", config.ID) - if err := os.MkdirAll(contDir, 0700); err != nil { - return err - } - if err := ioutil.WriteFile(filepath.Join(contDir, "config.json"), []byte(jsonConfig), 0600); err != nil { - return err - } - return nil -} - -type mockTagAdder struct { - refs map[string]string -} - -func (t *mockTagAdder) AddTag(ref reference.Named, id digest.Digest, force bool) error { - if t.refs == nil { - t.refs = make(map[string]string) - } - t.refs[ref.String()] = id.String() - return nil -} -func (t *mockTagAdder) AddDigest(ref reference.Canonical, id digest.Digest, force bool) error { - return t.AddTag(ref, id, force) -} - -type mockRegistrar struct { - layers map[layer.ChainID]*mockLayer - count int -} - -func (r *mockRegistrar) RegisterByGraphID(graphID string, parent layer.ChainID, diffID layer.DiffID, tarDataFile string, size int64) (layer.Layer, error) { - r.count++ - l := &mockLayer{} - if parent != "" { - p, exists := r.layers[parent] - if !exists { - return nil, fmt.Errorf("invalid parent %q", parent) - } - l.parent = p - l.diffIDs = append(l.diffIDs, p.diffIDs...) - } - l.diffIDs = append(l.diffIDs, diffID) - if r.layers == nil { - r.layers = make(map[layer.ChainID]*mockLayer) - } - r.layers[l.ChainID()] = l - return l, nil -} -func (r *mockRegistrar) Release(l layer.Layer) ([]layer.Metadata, error) { - return nil, nil -} -func (r *mockRegistrar) Get(layer.ChainID) (layer.Layer, error) { - return nil, nil -} - -type mountInfo struct { - name, graphID, parent string -} -type mockMounter struct { - mounts []mountInfo - count int -} - -func (r *mockMounter) CreateRWLayerByGraphID(name string, graphID string, parent layer.ChainID) error { - r.mounts = append(r.mounts, mountInfo{name, graphID, string(parent)}) - return nil -} -func (r *mockMounter) Unmount(string) error { - r.count-- - return nil -} -func (r *mockMounter) Get(layer.ChainID) (layer.Layer, error) { - return nil, nil -} - -func (r *mockMounter) Release(layer.Layer) ([]layer.Metadata, error) { - return nil, nil -} - -type mockLayer struct { - diffIDs []layer.DiffID - parent *mockLayer -} - -func (l *mockLayer) TarStream() (io.ReadCloser, error) { - return nil, nil -} -func (l *mockLayer) TarStreamFrom(layer.ChainID) (io.ReadCloser, error) { - return nil, nil -} - -func (l *mockLayer) ChainID() layer.ChainID { - return layer.CreateChainID(l.diffIDs) -} - -func (l *mockLayer) DiffID() layer.DiffID { - return l.diffIDs[len(l.diffIDs)-1] -} - -func (l *mockLayer) Parent() layer.Layer { - if l.parent == nil { - return nil - } - return l.parent -} - -func (l *mockLayer) Size() (int64, error) { - return 0, nil -} - -func (l *mockLayer) DiffSize() (int64, error) { - return 0, nil -} - -func (l *mockLayer) Metadata() (map[string]string, error) { - return nil, nil -} diff --git a/vendor/github.com/docker/docker/oci/defaults_linux.go b/vendor/github.com/docker/docker/oci/defaults_linux.go deleted file mode 100644 index 8b3ce72..0000000 --- a/vendor/github.com/docker/docker/oci/defaults_linux.go +++ /dev/null @@ -1,168 +0,0 @@ -package oci - -import ( - "os" - "runtime" - - "github.com/opencontainers/runtime-spec/specs-go" -) - -func sPtr(s string) *string { return &s } -func iPtr(i int64) *int64 { return &i } -func u32Ptr(i int64) *uint32 { u := uint32(i); return &u } -func fmPtr(i int64) *os.FileMode { fm := os.FileMode(i); return &fm } - -// DefaultSpec returns default oci spec used by docker. -func DefaultSpec() specs.Spec { - s := specs.Spec{ - Version: specs.Version, - Platform: specs.Platform{ - OS: runtime.GOOS, - Arch: runtime.GOARCH, - }, - } - s.Mounts = []specs.Mount{ - { - Destination: "/proc", - Type: "proc", - Source: "proc", - Options: []string{"nosuid", "noexec", "nodev"}, - }, - { - Destination: "/dev", - Type: "tmpfs", - Source: "tmpfs", - Options: []string{"nosuid", "strictatime", "mode=755"}, - }, - { - Destination: "/dev/pts", - Type: "devpts", - Source: "devpts", - Options: []string{"nosuid", "noexec", "newinstance", "ptmxmode=0666", "mode=0620", "gid=5"}, - }, - { - Destination: "/sys", - Type: "sysfs", - Source: "sysfs", - Options: []string{"nosuid", "noexec", "nodev", "ro"}, - }, - { - Destination: "/sys/fs/cgroup", - Type: "cgroup", - Source: "cgroup", - Options: []string{"ro", "nosuid", "noexec", "nodev"}, - }, - { - Destination: "/dev/mqueue", - Type: "mqueue", - Source: "mqueue", - Options: []string{"nosuid", "noexec", "nodev"}, - }, - } - s.Process.Capabilities = []string{ - "CAP_CHOWN", - "CAP_DAC_OVERRIDE", - "CAP_FSETID", - "CAP_FOWNER", - "CAP_MKNOD", - "CAP_NET_RAW", - "CAP_SETGID", - "CAP_SETUID", - "CAP_SETFCAP", - "CAP_SETPCAP", - "CAP_NET_BIND_SERVICE", - "CAP_SYS_CHROOT", - "CAP_KILL", - "CAP_AUDIT_WRITE", - } - - s.Linux = &specs.Linux{ - MaskedPaths: []string{ - "/proc/kcore", - "/proc/latency_stats", - "/proc/timer_list", - "/proc/timer_stats", - "/proc/sched_debug", - "/sys/firmware", - }, - ReadonlyPaths: []string{ - "/proc/asound", - "/proc/bus", - "/proc/fs", - "/proc/irq", - "/proc/sys", - "/proc/sysrq-trigger", - }, - Namespaces: []specs.Namespace{ - {Type: "mount"}, - {Type: "network"}, - {Type: "uts"}, - {Type: "pid"}, - {Type: "ipc"}, - }, - // Devices implicitly contains the following devices: - // null, zero, full, random, urandom, tty, console, and ptmx. - // ptmx is a bind-mount or symlink of the container's ptmx. - // See also: https://github.com/opencontainers/runtime-spec/blob/master/config-linux.md#default-devices - Devices: []specs.Device{}, - Resources: &specs.Resources{ - Devices: []specs.DeviceCgroup{ - { - Allow: false, - Access: sPtr("rwm"), - }, - { - Allow: true, - Type: sPtr("c"), - Major: iPtr(1), - Minor: iPtr(5), - Access: sPtr("rwm"), - }, - { - Allow: true, - Type: sPtr("c"), - Major: iPtr(1), - Minor: iPtr(3), - Access: sPtr("rwm"), - }, - { - Allow: true, - Type: sPtr("c"), - Major: iPtr(1), - Minor: iPtr(9), - Access: sPtr("rwm"), - }, - { - Allow: true, - Type: sPtr("c"), - Major: iPtr(1), - Minor: iPtr(8), - Access: sPtr("rwm"), - }, - { - Allow: true, - Type: sPtr("c"), - Major: iPtr(5), - Minor: iPtr(0), - Access: sPtr("rwm"), - }, - { - Allow: true, - Type: sPtr("c"), - Major: iPtr(5), - Minor: iPtr(1), - Access: sPtr("rwm"), - }, - { - Allow: false, - Type: sPtr("c"), - Major: iPtr(10), - Minor: iPtr(229), - Access: sPtr("rwm"), - }, - }, - }, - } - - return s -} diff --git a/vendor/github.com/docker/docker/oci/defaults_solaris.go b/vendor/github.com/docker/docker/oci/defaults_solaris.go deleted file mode 100644 index 85c8b68..0000000 --- a/vendor/github.com/docker/docker/oci/defaults_solaris.go +++ /dev/null @@ -1,20 +0,0 @@ -package oci - -import ( - "runtime" - - "github.com/opencontainers/runtime-spec/specs-go" -) - -// DefaultSpec returns default oci spec used by docker. -func DefaultSpec() specs.Spec { - s := specs.Spec{ - Version: "0.6.0", - Platform: specs.Platform{ - OS: "SunOS", - Arch: runtime.GOARCH, - }, - } - s.Solaris = &specs.Solaris{} - return s -} diff --git a/vendor/github.com/docker/docker/oci/defaults_windows.go b/vendor/github.com/docker/docker/oci/defaults_windows.go deleted file mode 100644 index ab51904..0000000 --- a/vendor/github.com/docker/docker/oci/defaults_windows.go +++ /dev/null @@ -1,19 +0,0 @@ -package oci - -import ( - "runtime" - - "github.com/opencontainers/runtime-spec/specs-go" -) - -// DefaultSpec returns default spec used by docker. -func DefaultSpec() specs.Spec { - return specs.Spec{ - Version: specs.Version, - Platform: specs.Platform{ - OS: runtime.GOOS, - Arch: runtime.GOARCH, - }, - Windows: &specs.Windows{}, - } -} diff --git a/vendor/github.com/docker/docker/oci/devices_linux.go b/vendor/github.com/docker/docker/oci/devices_linux.go deleted file mode 100644 index 2840d25..0000000 --- a/vendor/github.com/docker/docker/oci/devices_linux.go +++ /dev/null @@ -1,86 +0,0 @@ -package oci - -import ( - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/opencontainers/runc/libcontainer/configs" - "github.com/opencontainers/runc/libcontainer/devices" - specs "github.com/opencontainers/runtime-spec/specs-go" -) - -// Device transforms a libcontainer configs.Device to a specs.Device object. -func Device(d *configs.Device) specs.Device { - return specs.Device{ - Type: string(d.Type), - Path: d.Path, - Major: d.Major, - Minor: d.Minor, - FileMode: fmPtr(int64(d.FileMode)), - UID: u32Ptr(int64(d.Uid)), - GID: u32Ptr(int64(d.Gid)), - } -} - -func deviceCgroup(d *configs.Device) specs.DeviceCgroup { - t := string(d.Type) - return specs.DeviceCgroup{ - Allow: true, - Type: &t, - Major: &d.Major, - Minor: &d.Minor, - Access: &d.Permissions, - } -} - -// DevicesFromPath computes a list of devices and device permissions from paths (pathOnHost and pathInContainer) and cgroup permissions. -func DevicesFromPath(pathOnHost, pathInContainer, cgroupPermissions string) (devs []specs.Device, devPermissions []specs.DeviceCgroup, err error) { - resolvedPathOnHost := pathOnHost - - // check if it is a symbolic link - if src, e := os.Lstat(pathOnHost); e == nil && src.Mode()&os.ModeSymlink == os.ModeSymlink { - if linkedPathOnHost, e := filepath.EvalSymlinks(pathOnHost); e == nil { - resolvedPathOnHost = linkedPathOnHost - } - } - - device, err := devices.DeviceFromPath(resolvedPathOnHost, cgroupPermissions) - // if there was no error, return the device - if err == nil { - device.Path = pathInContainer - return append(devs, Device(device)), append(devPermissions, deviceCgroup(device)), nil - } - - // if the device is not a device node - // try to see if it's a directory holding many devices - if err == devices.ErrNotADevice { - - // check if it is a directory - if src, e := os.Stat(resolvedPathOnHost); e == nil && src.IsDir() { - - // mount the internal devices recursively - filepath.Walk(resolvedPathOnHost, func(dpath string, f os.FileInfo, e error) error { - childDevice, e := devices.DeviceFromPath(dpath, cgroupPermissions) - if e != nil { - // ignore the device - return nil - } - - // add the device to userSpecified devices - childDevice.Path = strings.Replace(dpath, resolvedPathOnHost, pathInContainer, 1) - devs = append(devs, Device(childDevice)) - devPermissions = append(devPermissions, deviceCgroup(childDevice)) - - return nil - }) - } - } - - if len(devs) > 0 { - return devs, devPermissions, nil - } - - return devs, devPermissions, fmt.Errorf("error gathering device information while adding custom device %q: %s", pathOnHost, err) -} diff --git a/vendor/github.com/docker/docker/oci/devices_unsupported.go b/vendor/github.com/docker/docker/oci/devices_unsupported.go deleted file mode 100644 index 6252cab..0000000 --- a/vendor/github.com/docker/docker/oci/devices_unsupported.go +++ /dev/null @@ -1,20 +0,0 @@ -// +build !linux - -package oci - -import ( - "errors" - - "github.com/opencontainers/runc/libcontainer/configs" - specs "github.com/opencontainers/runtime-spec/specs-go" -) - -// Device transforms a libcontainer configs.Device to a specs.Device object. -// Not implemented -func Device(d *configs.Device) specs.Device { return specs.Device{} } - -// DevicesFromPath computes a list of devices and device permissions from paths (pathOnHost and pathInContainer) and cgroup permissions. -// Not implemented -func DevicesFromPath(pathOnHost, pathInContainer, cgroupPermissions string) (devs []specs.Device, devPermissions []specs.DeviceCgroup, err error) { - return nil, nil, errors.New("oci/devices: unsupported platform") -} diff --git a/vendor/github.com/docker/docker/oci/namespaces.go b/vendor/github.com/docker/docker/oci/namespaces.go deleted file mode 100644 index 4902482..0000000 --- a/vendor/github.com/docker/docker/oci/namespaces.go +++ /dev/null @@ -1,16 +0,0 @@ -package oci - -import specs "github.com/opencontainers/runtime-spec/specs-go" - -// RemoveNamespace removes the `nsType` namespace from OCI spec `s` -func RemoveNamespace(s *specs.Spec, nsType specs.NamespaceType) { - idx := -1 - for i, n := range s.Linux.Namespaces { - if n.Type == nsType { - idx = i - } - } - if idx >= 0 { - s.Linux.Namespaces = append(s.Linux.Namespaces[:idx], s.Linux.Namespaces[idx+1:]...) - } -} diff --git a/vendor/github.com/docker/docker/opts/hosts.go b/vendor/github.com/docker/docker/opts/hosts.go deleted file mode 100644 index 266df1e..0000000 --- a/vendor/github.com/docker/docker/opts/hosts.go +++ /dev/null @@ -1,151 +0,0 @@ -package opts - -import ( - "fmt" - "net" - "net/url" - "strconv" - "strings" -) - -var ( - // DefaultHTTPPort Default HTTP Port used if only the protocol is provided to -H flag e.g. docker daemon -H tcp:// - // These are the IANA registered port numbers for use with Docker - // see http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=docker - DefaultHTTPPort = 2375 // Default HTTP Port - // DefaultTLSHTTPPort Default HTTP Port used when TLS enabled - DefaultTLSHTTPPort = 2376 // Default TLS encrypted HTTP Port - // DefaultUnixSocket Path for the unix socket. - // Docker daemon by default always listens on the default unix socket - DefaultUnixSocket = "/var/run/docker.sock" - // DefaultTCPHost constant defines the default host string used by docker on Windows - DefaultTCPHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultHTTPPort) - // DefaultTLSHost constant defines the default host string used by docker for TLS sockets - DefaultTLSHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultTLSHTTPPort) - // DefaultNamedPipe defines the default named pipe used by docker on Windows - DefaultNamedPipe = `//./pipe/docker_engine` -) - -// ValidateHost validates that the specified string is a valid host and returns it. -func ValidateHost(val string) (string, error) { - host := strings.TrimSpace(val) - // The empty string means default and is not handled by parseDockerDaemonHost - if host != "" { - _, err := parseDockerDaemonHost(host) - if err != nil { - return val, err - } - } - // Note: unlike most flag validators, we don't return the mutated value here - // we need to know what the user entered later (using ParseHost) to adjust for tls - return val, nil -} - -// ParseHost and set defaults for a Daemon host string -func ParseHost(defaultToTLS bool, val string) (string, error) { - host := strings.TrimSpace(val) - if host == "" { - if defaultToTLS { - host = DefaultTLSHost - } else { - host = DefaultHost - } - } else { - var err error - host, err = parseDockerDaemonHost(host) - if err != nil { - return val, err - } - } - return host, nil -} - -// parseDockerDaemonHost parses the specified address and returns an address that will be used as the host. -// Depending of the address specified, this may return one of the global Default* strings defined in hosts.go. -func parseDockerDaemonHost(addr string) (string, error) { - addrParts := strings.SplitN(addr, "://", 2) - if len(addrParts) == 1 && addrParts[0] != "" { - addrParts = []string{"tcp", addrParts[0]} - } - - switch addrParts[0] { - case "tcp": - return ParseTCPAddr(addrParts[1], DefaultTCPHost) - case "unix": - return parseSimpleProtoAddr("unix", addrParts[1], DefaultUnixSocket) - case "npipe": - return parseSimpleProtoAddr("npipe", addrParts[1], DefaultNamedPipe) - case "fd": - return addr, nil - default: - return "", fmt.Errorf("Invalid bind address format: %s", addr) - } -} - -// parseSimpleProtoAddr parses and validates that the specified address is a valid -// socket address for simple protocols like unix and npipe. It returns a formatted -// socket address, either using the address parsed from addr, or the contents of -// defaultAddr if addr is a blank string. -func parseSimpleProtoAddr(proto, addr, defaultAddr string) (string, error) { - addr = strings.TrimPrefix(addr, proto+"://") - if strings.Contains(addr, "://") { - return "", fmt.Errorf("Invalid proto, expected %s: %s", proto, addr) - } - if addr == "" { - addr = defaultAddr - } - return fmt.Sprintf("%s://%s", proto, addr), nil -} - -// ParseTCPAddr parses and validates that the specified address is a valid TCP -// address. It returns a formatted TCP address, either using the address parsed -// from tryAddr, or the contents of defaultAddr if tryAddr is a blank string. -// tryAddr is expected to have already been Trim()'d -// defaultAddr must be in the full `tcp://host:port` form -func ParseTCPAddr(tryAddr string, defaultAddr string) (string, error) { - if tryAddr == "" || tryAddr == "tcp://" { - return defaultAddr, nil - } - addr := strings.TrimPrefix(tryAddr, "tcp://") - if strings.Contains(addr, "://") || addr == "" { - return "", fmt.Errorf("Invalid proto, expected tcp: %s", tryAddr) - } - - defaultAddr = strings.TrimPrefix(defaultAddr, "tcp://") - defaultHost, defaultPort, err := net.SplitHostPort(defaultAddr) - if err != nil { - return "", err - } - // url.Parse fails for trailing colon on IPv6 brackets on Go 1.5, but - // not 1.4. See https://github.com/golang/go/issues/12200 and - // https://github.com/golang/go/issues/6530. - if strings.HasSuffix(addr, "]:") { - addr += defaultPort - } - - u, err := url.Parse("tcp://" + addr) - if err != nil { - return "", err - } - host, port, err := net.SplitHostPort(u.Host) - if err != nil { - // try port addition once - host, port, err = net.SplitHostPort(net.JoinHostPort(u.Host, defaultPort)) - } - if err != nil { - return "", fmt.Errorf("Invalid bind address format: %s", tryAddr) - } - - if host == "" { - host = defaultHost - } - if port == "" { - port = defaultPort - } - p, err := strconv.Atoi(port) - if err != nil && p == 0 { - return "", fmt.Errorf("Invalid bind address format: %s", tryAddr) - } - - return fmt.Sprintf("tcp://%s%s", net.JoinHostPort(host, port), u.Path), nil -} diff --git a/vendor/github.com/docker/docker/opts/hosts_test.go b/vendor/github.com/docker/docker/opts/hosts_test.go deleted file mode 100644 index a5bec30..0000000 --- a/vendor/github.com/docker/docker/opts/hosts_test.go +++ /dev/null @@ -1,148 +0,0 @@ -package opts - -import ( - "fmt" - "testing" -) - -func TestParseHost(t *testing.T) { - invalid := []string{ - "something with spaces", - "://", - "unknown://", - "tcp://:port", - "tcp://invalid:port", - } - - valid := map[string]string{ - "": DefaultHost, - " ": DefaultHost, - " ": DefaultHost, - "fd://": "fd://", - "fd://something": "fd://something", - "tcp://host:": fmt.Sprintf("tcp://host:%d", DefaultHTTPPort), - "tcp://": DefaultTCPHost, - "tcp://:2375": fmt.Sprintf("tcp://%s:2375", DefaultHTTPHost), - "tcp://:2376": fmt.Sprintf("tcp://%s:2376", DefaultHTTPHost), - "tcp://0.0.0.0:8080": "tcp://0.0.0.0:8080", - "tcp://192.168.0.0:12000": "tcp://192.168.0.0:12000", - "tcp://192.168:8080": "tcp://192.168:8080", - "tcp://0.0.0.0:1234567890": "tcp://0.0.0.0:1234567890", // yeah it's valid :P - " tcp://:7777/path ": fmt.Sprintf("tcp://%s:7777/path", DefaultHTTPHost), - "tcp://docker.com:2375": "tcp://docker.com:2375", - "unix://": "unix://" + DefaultUnixSocket, - "unix://path/to/socket": "unix://path/to/socket", - "npipe://": "npipe://" + DefaultNamedPipe, - "npipe:////./pipe/foo": "npipe:////./pipe/foo", - } - - for _, value := range invalid { - if _, err := ParseHost(false, value); err == nil { - t.Errorf("Expected an error for %v, got [nil]", value) - } - } - - for value, expected := range valid { - if actual, err := ParseHost(false, value); err != nil || actual != expected { - t.Errorf("Expected for %v [%v], got [%v, %v]", value, expected, actual, err) - } - } -} - -func TestParseDockerDaemonHost(t *testing.T) { - invalids := map[string]string{ - - "tcp:a.b.c.d": "Invalid bind address format: tcp:a.b.c.d", - "tcp:a.b.c.d/path": "Invalid bind address format: tcp:a.b.c.d/path", - "udp://127.0.0.1": "Invalid bind address format: udp://127.0.0.1", - "udp://127.0.0.1:2375": "Invalid bind address format: udp://127.0.0.1:2375", - "tcp://unix:///run/docker.sock": "Invalid proto, expected tcp: unix:///run/docker.sock", - " tcp://:7777/path ": "Invalid bind address format: tcp://:7777/path ", - "": "Invalid bind address format: ", - } - valids := map[string]string{ - "0.0.0.1:": "tcp://0.0.0.1:2375", - "0.0.0.1:5555": "tcp://0.0.0.1:5555", - "0.0.0.1:5555/path": "tcp://0.0.0.1:5555/path", - "[::1]:": "tcp://[::1]:2375", - "[::1]:5555/path": "tcp://[::1]:5555/path", - "[0:0:0:0:0:0:0:1]:": "tcp://[0:0:0:0:0:0:0:1]:2375", - "[0:0:0:0:0:0:0:1]:5555/path": "tcp://[0:0:0:0:0:0:0:1]:5555/path", - ":6666": fmt.Sprintf("tcp://%s:6666", DefaultHTTPHost), - ":6666/path": fmt.Sprintf("tcp://%s:6666/path", DefaultHTTPHost), - "tcp://": DefaultTCPHost, - "tcp://:7777": fmt.Sprintf("tcp://%s:7777", DefaultHTTPHost), - "tcp://:7777/path": fmt.Sprintf("tcp://%s:7777/path", DefaultHTTPHost), - "unix:///run/docker.sock": "unix:///run/docker.sock", - "unix://": "unix://" + DefaultUnixSocket, - "fd://": "fd://", - "fd://something": "fd://something", - "localhost:": "tcp://localhost:2375", - "localhost:5555": "tcp://localhost:5555", - "localhost:5555/path": "tcp://localhost:5555/path", - } - for invalidAddr, expectedError := range invalids { - if addr, err := parseDockerDaemonHost(invalidAddr); err == nil || err.Error() != expectedError { - t.Errorf("tcp %v address expected error %q return, got %q and addr %v", invalidAddr, expectedError, err, addr) - } - } - for validAddr, expectedAddr := range valids { - if addr, err := parseDockerDaemonHost(validAddr); err != nil || addr != expectedAddr { - t.Errorf("%v -> expected %v, got (%v) addr (%v)", validAddr, expectedAddr, err, addr) - } - } -} - -func TestParseTCP(t *testing.T) { - var ( - defaultHTTPHost = "tcp://127.0.0.1:2376" - ) - invalids := map[string]string{ - "tcp:a.b.c.d": "Invalid bind address format: tcp:a.b.c.d", - "tcp:a.b.c.d/path": "Invalid bind address format: tcp:a.b.c.d/path", - "udp://127.0.0.1": "Invalid proto, expected tcp: udp://127.0.0.1", - "udp://127.0.0.1:2375": "Invalid proto, expected tcp: udp://127.0.0.1:2375", - } - valids := map[string]string{ - "": defaultHTTPHost, - "tcp://": defaultHTTPHost, - "0.0.0.1:": "tcp://0.0.0.1:2376", - "0.0.0.1:5555": "tcp://0.0.0.1:5555", - "0.0.0.1:5555/path": "tcp://0.0.0.1:5555/path", - ":6666": "tcp://127.0.0.1:6666", - ":6666/path": "tcp://127.0.0.1:6666/path", - "tcp://:7777": "tcp://127.0.0.1:7777", - "tcp://:7777/path": "tcp://127.0.0.1:7777/path", - "[::1]:": "tcp://[::1]:2376", - "[::1]:5555": "tcp://[::1]:5555", - "[::1]:5555/path": "tcp://[::1]:5555/path", - "[0:0:0:0:0:0:0:1]:": "tcp://[0:0:0:0:0:0:0:1]:2376", - "[0:0:0:0:0:0:0:1]:5555": "tcp://[0:0:0:0:0:0:0:1]:5555", - "[0:0:0:0:0:0:0:1]:5555/path": "tcp://[0:0:0:0:0:0:0:1]:5555/path", - "localhost:": "tcp://localhost:2376", - "localhost:5555": "tcp://localhost:5555", - "localhost:5555/path": "tcp://localhost:5555/path", - } - for invalidAddr, expectedError := range invalids { - if addr, err := ParseTCPAddr(invalidAddr, defaultHTTPHost); err == nil || err.Error() != expectedError { - t.Errorf("tcp %v address expected error %v return, got %s and addr %v", invalidAddr, expectedError, err, addr) - } - } - for validAddr, expectedAddr := range valids { - if addr, err := ParseTCPAddr(validAddr, defaultHTTPHost); err != nil || addr != expectedAddr { - t.Errorf("%v -> expected %v, got %v and addr %v", validAddr, expectedAddr, err, addr) - } - } -} - -func TestParseInvalidUnixAddrInvalid(t *testing.T) { - if _, err := parseSimpleProtoAddr("unix", "tcp://127.0.0.1", "unix:///var/run/docker.sock"); err == nil || err.Error() != "Invalid proto, expected unix: tcp://127.0.0.1" { - t.Fatalf("Expected an error, got %v", err) - } - if _, err := parseSimpleProtoAddr("unix", "unix://tcp://127.0.0.1", "/var/run/docker.sock"); err == nil || err.Error() != "Invalid proto, expected unix: tcp://127.0.0.1" { - t.Fatalf("Expected an error, got %v", err) - } - if v, err := parseSimpleProtoAddr("unix", "", "/var/run/docker.sock"); err != nil || v != "unix:///var/run/docker.sock" { - t.Fatalf("Expected an %v, got %v", v, "unix:///var/run/docker.sock") - } -} diff --git a/vendor/github.com/docker/docker/opts/hosts_unix.go b/vendor/github.com/docker/docker/opts/hosts_unix.go deleted file mode 100644 index 611407a..0000000 --- a/vendor/github.com/docker/docker/opts/hosts_unix.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !windows - -package opts - -import "fmt" - -// DefaultHost constant defines the default host string used by docker on other hosts than Windows -var DefaultHost = fmt.Sprintf("unix://%s", DefaultUnixSocket) diff --git a/vendor/github.com/docker/docker/opts/hosts_windows.go b/vendor/github.com/docker/docker/opts/hosts_windows.go deleted file mode 100644 index 7c239e0..0000000 --- a/vendor/github.com/docker/docker/opts/hosts_windows.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build windows - -package opts - -// DefaultHost constant defines the default host string used by docker on Windows -var DefaultHost = "npipe://" + DefaultNamedPipe diff --git a/vendor/github.com/docker/docker/opts/ip.go b/vendor/github.com/docker/docker/opts/ip.go deleted file mode 100644 index fb03b50..0000000 --- a/vendor/github.com/docker/docker/opts/ip.go +++ /dev/null @@ -1,47 +0,0 @@ -package opts - -import ( - "fmt" - "net" -) - -// IPOpt holds an IP. It is used to store values from CLI flags. -type IPOpt struct { - *net.IP -} - -// NewIPOpt creates a new IPOpt from a reference net.IP and a -// string representation of an IP. If the string is not a valid -// IP it will fallback to the specified reference. -func NewIPOpt(ref *net.IP, defaultVal string) *IPOpt { - o := &IPOpt{ - IP: ref, - } - o.Set(defaultVal) - return o -} - -// Set sets an IPv4 or IPv6 address from a given string. If the given -// string is not parseable as an IP address it returns an error. -func (o *IPOpt) Set(val string) error { - ip := net.ParseIP(val) - if ip == nil { - return fmt.Errorf("%s is not an ip address", val) - } - *o.IP = ip - return nil -} - -// String returns the IP address stored in the IPOpt. If stored IP is a -// nil pointer, it returns an empty string. -func (o *IPOpt) String() string { - if *o.IP == nil { - return "" - } - return o.IP.String() -} - -// Type returns the type of the option -func (o *IPOpt) Type() string { - return "ip" -} diff --git a/vendor/github.com/docker/docker/opts/ip_test.go b/vendor/github.com/docker/docker/opts/ip_test.go deleted file mode 100644 index 1027d84..0000000 --- a/vendor/github.com/docker/docker/opts/ip_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package opts - -import ( - "net" - "testing" -) - -func TestIpOptString(t *testing.T) { - addresses := []string{"", "0.0.0.0"} - var ip net.IP - - for _, address := range addresses { - stringAddress := NewIPOpt(&ip, address).String() - if stringAddress != address { - t.Fatalf("IpOpt string should be `%s`, not `%s`", address, stringAddress) - } - } -} - -func TestNewIpOptInvalidDefaultVal(t *testing.T) { - ip := net.IPv4(127, 0, 0, 1) - defaultVal := "Not an ip" - - ipOpt := NewIPOpt(&ip, defaultVal) - - expected := "127.0.0.1" - if ipOpt.String() != expected { - t.Fatalf("Expected [%v], got [%v]", expected, ipOpt.String()) - } -} - -func TestNewIpOptValidDefaultVal(t *testing.T) { - ip := net.IPv4(127, 0, 0, 1) - defaultVal := "192.168.1.1" - - ipOpt := NewIPOpt(&ip, defaultVal) - - expected := "192.168.1.1" - if ipOpt.String() != expected { - t.Fatalf("Expected [%v], got [%v]", expected, ipOpt.String()) - } -} - -func TestIpOptSetInvalidVal(t *testing.T) { - ip := net.IPv4(127, 0, 0, 1) - ipOpt := &IPOpt{IP: &ip} - - invalidIP := "invalid ip" - expectedError := "invalid ip is not an ip address" - err := ipOpt.Set(invalidIP) - if err == nil || err.Error() != expectedError { - t.Fatalf("Expected an Error with [%v], got [%v]", expectedError, err.Error()) - } -} diff --git a/vendor/github.com/docker/docker/opts/mount.go b/vendor/github.com/docker/docker/opts/mount.go deleted file mode 100644 index ce6383d..0000000 --- a/vendor/github.com/docker/docker/opts/mount.go +++ /dev/null @@ -1,171 +0,0 @@ -package opts - -import ( - "encoding/csv" - "fmt" - "os" - "strconv" - "strings" - - mounttypes "github.com/docker/docker/api/types/mount" - "github.com/docker/go-units" -) - -// MountOpt is a Value type for parsing mounts -type MountOpt struct { - values []mounttypes.Mount -} - -// Set a new mount value -func (m *MountOpt) Set(value string) error { - csvReader := csv.NewReader(strings.NewReader(value)) - fields, err := csvReader.Read() - if err != nil { - return err - } - - mount := mounttypes.Mount{} - - volumeOptions := func() *mounttypes.VolumeOptions { - if mount.VolumeOptions == nil { - mount.VolumeOptions = &mounttypes.VolumeOptions{ - Labels: make(map[string]string), - } - } - if mount.VolumeOptions.DriverConfig == nil { - mount.VolumeOptions.DriverConfig = &mounttypes.Driver{} - } - return mount.VolumeOptions - } - - bindOptions := func() *mounttypes.BindOptions { - if mount.BindOptions == nil { - mount.BindOptions = new(mounttypes.BindOptions) - } - return mount.BindOptions - } - - tmpfsOptions := func() *mounttypes.TmpfsOptions { - if mount.TmpfsOptions == nil { - mount.TmpfsOptions = new(mounttypes.TmpfsOptions) - } - return mount.TmpfsOptions - } - - setValueOnMap := func(target map[string]string, value string) { - parts := strings.SplitN(value, "=", 2) - if len(parts) == 1 { - target[value] = "" - } else { - target[parts[0]] = parts[1] - } - } - - mount.Type = mounttypes.TypeVolume // default to volume mounts - // Set writable as the default - for _, field := range fields { - parts := strings.SplitN(field, "=", 2) - key := strings.ToLower(parts[0]) - - if len(parts) == 1 { - switch key { - case "readonly", "ro": - mount.ReadOnly = true - continue - case "volume-nocopy": - volumeOptions().NoCopy = true - continue - } - } - - if len(parts) != 2 { - return fmt.Errorf("invalid field '%s' must be a key=value pair", field) - } - - value := parts[1] - switch key { - case "type": - mount.Type = mounttypes.Type(strings.ToLower(value)) - case "source", "src": - mount.Source = value - case "target", "dst", "destination": - mount.Target = value - case "readonly", "ro": - mount.ReadOnly, err = strconv.ParseBool(value) - if err != nil { - return fmt.Errorf("invalid value for %s: %s", key, value) - } - case "bind-propagation": - bindOptions().Propagation = mounttypes.Propagation(strings.ToLower(value)) - case "volume-nocopy": - volumeOptions().NoCopy, err = strconv.ParseBool(value) - if err != nil { - return fmt.Errorf("invalid value for populate: %s", value) - } - case "volume-label": - setValueOnMap(volumeOptions().Labels, value) - case "volume-driver": - volumeOptions().DriverConfig.Name = value - case "volume-opt": - if volumeOptions().DriverConfig.Options == nil { - volumeOptions().DriverConfig.Options = make(map[string]string) - } - setValueOnMap(volumeOptions().DriverConfig.Options, value) - case "tmpfs-size": - sizeBytes, err := units.RAMInBytes(value) - if err != nil { - return fmt.Errorf("invalid value for %s: %s", key, value) - } - tmpfsOptions().SizeBytes = sizeBytes - case "tmpfs-mode": - ui64, err := strconv.ParseUint(value, 8, 32) - if err != nil { - return fmt.Errorf("invalid value for %s: %s", key, value) - } - tmpfsOptions().Mode = os.FileMode(ui64) - default: - return fmt.Errorf("unexpected key '%s' in '%s'", key, field) - } - } - - if mount.Type == "" { - return fmt.Errorf("type is required") - } - - if mount.Target == "" { - return fmt.Errorf("target is required") - } - - if mount.VolumeOptions != nil && mount.Type != mounttypes.TypeVolume { - return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mount.Type) - } - if mount.BindOptions != nil && mount.Type != mounttypes.TypeBind { - return fmt.Errorf("cannot mix 'bind-*' options with mount type '%s'", mount.Type) - } - if mount.TmpfsOptions != nil && mount.Type != mounttypes.TypeTmpfs { - return fmt.Errorf("cannot mix 'tmpfs-*' options with mount type '%s'", mount.Type) - } - - m.values = append(m.values, mount) - return nil -} - -// Type returns the type of this option -func (m *MountOpt) Type() string { - return "mount" -} - -// String returns a string repr of this option -func (m *MountOpt) String() string { - mounts := []string{} - for _, mount := range m.values { - repr := fmt.Sprintf("%s %s %s", mount.Type, mount.Source, mount.Target) - mounts = append(mounts, repr) - } - return strings.Join(mounts, ", ") -} - -// Value returns the mounts -func (m *MountOpt) Value() []mounttypes.Mount { - return m.values -} diff --git a/vendor/github.com/docker/docker/opts/mount_test.go b/vendor/github.com/docker/docker/opts/mount_test.go deleted file mode 100644 index 59606c3..0000000 --- a/vendor/github.com/docker/docker/opts/mount_test.go +++ /dev/null @@ -1,184 +0,0 @@ -package opts - -import ( - "os" - "testing" - - mounttypes "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestMountOptString(t *testing.T) { - mount := MountOpt{ - values: []mounttypes.Mount{ - { - Type: mounttypes.TypeBind, - Source: "/home/path", - Target: "/target", - }, - { - Type: mounttypes.TypeVolume, - Source: "foo", - Target: "/target/foo", - }, - }, - } - expected := "bind /home/path /target, volume foo /target/foo" - assert.Equal(t, mount.String(), expected) -} - -func TestMountOptSetBindNoErrorBind(t *testing.T) { - for _, testcase := range []string{ - // tests several aliases that should have same result. - "type=bind,target=/target,source=/source", - "type=bind,src=/source,dst=/target", - "type=bind,source=/source,dst=/target", - "type=bind,src=/source,target=/target", - } { - var mount MountOpt - - assert.NilError(t, mount.Set(testcase)) - - mounts := mount.Value() - assert.Equal(t, len(mounts), 1) - assert.Equal(t, mounts[0], mounttypes.Mount{ - Type: mounttypes.TypeBind, - Source: "/source", - Target: "/target", - }) - } -} - -func TestMountOptSetVolumeNoError(t *testing.T) { - for _, testcase := range []string{ - // tests several aliases that should have same result. - "type=volume,target=/target,source=/source", - "type=volume,src=/source,dst=/target", - "type=volume,source=/source,dst=/target", - "type=volume,src=/source,target=/target", - } { - var mount MountOpt - - assert.NilError(t, mount.Set(testcase)) - - mounts := mount.Value() - assert.Equal(t, len(mounts), 1) - assert.Equal(t, mounts[0], mounttypes.Mount{ - Type: mounttypes.TypeVolume, - Source: "/source", - Target: "/target", - }) - } -} - -// TestMountOptDefaultType ensures that a mount without the type defaults to a -// volume mount. -func TestMountOptDefaultType(t *testing.T) { - var mount MountOpt - assert.NilError(t, mount.Set("target=/target,source=/foo")) - assert.Equal(t, mount.values[0].Type, mounttypes.TypeVolume) -} - -func TestMountOptSetErrorNoTarget(t *testing.T) { - var mount MountOpt - assert.Error(t, mount.Set("type=volume,source=/foo"), "target is required") -} - -func TestMountOptSetErrorInvalidKey(t *testing.T) { - var mount MountOpt - assert.Error(t, mount.Set("type=volume,bogus=foo"), "unexpected key 'bogus'") -} - -func TestMountOptSetErrorInvalidField(t *testing.T) { - var mount MountOpt - assert.Error(t, mount.Set("type=volume,bogus"), "invalid field 'bogus'") -} - -func TestMountOptSetErrorInvalidReadOnly(t *testing.T) { - var mount MountOpt - assert.Error(t, mount.Set("type=volume,readonly=no"), "invalid value for readonly: no") - assert.Error(t, mount.Set("type=volume,readonly=invalid"), "invalid value for readonly: invalid") -} - -func TestMountOptDefaultEnableReadOnly(t *testing.T) { - var m MountOpt - assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo")) - assert.Equal(t, m.values[0].ReadOnly, false) - - m = MountOpt{} - assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly")) - assert.Equal(t, m.values[0].ReadOnly, true) - - m = MountOpt{} - assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=1")) - assert.Equal(t, m.values[0].ReadOnly, true) - - m = MountOpt{} - assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=true")) - assert.Equal(t, m.values[0].ReadOnly, true) - - m = MountOpt{} - assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0")) - assert.Equal(t, m.values[0].ReadOnly, false) -} - -func TestMountOptVolumeNoCopy(t *testing.T) { - var m MountOpt - assert.NilError(t, m.Set("type=volume,target=/foo,volume-nocopy")) - assert.Equal(t, m.values[0].Source, "") - - m = MountOpt{} - assert.NilError(t, m.Set("type=volume,target=/foo,source=foo")) - assert.Equal(t, m.values[0].VolumeOptions == nil, true) - - m = MountOpt{} - assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=true")) - assert.Equal(t, m.values[0].VolumeOptions != nil, true) - assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true) - - m = MountOpt{} - assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy")) - assert.Equal(t, m.values[0].VolumeOptions != nil, true) - assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true) - - m = MountOpt{} - assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=1")) - assert.Equal(t, m.values[0].VolumeOptions != nil, true) - assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true) -} - -func TestMountOptTypeConflict(t *testing.T) { - var m MountOpt - assert.Error(t, m.Set("type=bind,target=/foo,source=/foo,volume-nocopy=true"), "cannot mix") - assert.Error(t, m.Set("type=volume,target=/foo,source=/foo,bind-propagation=rprivate"), "cannot mix") -} - -func TestMountOptSetTmpfsNoError(t *testing.T) { - for _, testcase := range []string{ - // tests several aliases that should have same result. - "type=tmpfs,target=/target,tmpfs-size=1m,tmpfs-mode=0700", - "type=tmpfs,target=/target,tmpfs-size=1MB,tmpfs-mode=700", - } { - var mount MountOpt - - assert.NilError(t, mount.Set(testcase)) - - mounts := mount.Value() - assert.Equal(t, len(mounts), 1) - assert.DeepEqual(t, mounts[0], mounttypes.Mount{ - Type: mounttypes.TypeTmpfs, - Target: "/target", - TmpfsOptions: &mounttypes.TmpfsOptions{ - SizeBytes: 1024 * 1024, // not 1000 * 1000 - Mode: os.FileMode(0700), - }, - }) - } -} - -func TestMountOptSetTmpfsError(t *testing.T) { - var m MountOpt - assert.Error(t, m.Set("type=tmpfs,target=/foo,tmpfs-size=foo"), "invalid value for tmpfs-size") - assert.Error(t, m.Set("type=tmpfs,target=/foo,tmpfs-mode=foo"), "invalid value for tmpfs-mode") - assert.Error(t, m.Set("type=tmpfs"), "target is required") -} diff --git a/vendor/github.com/docker/docker/opts/opts.go b/vendor/github.com/docker/docker/opts/opts.go deleted file mode 100644 index ae85153..0000000 --- a/vendor/github.com/docker/docker/opts/opts.go +++ /dev/null @@ -1,360 +0,0 @@ -package opts - -import ( - "fmt" - "math/big" - "net" - "regexp" - "strings" - - "github.com/docker/docker/api/types/filters" -) - -var ( - alphaRegexp = regexp.MustCompile(`[a-zA-Z]`) - domainRegexp = regexp.MustCompile(`^(:?(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]))(:?\.(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])))*)\.?\s*$`) -) - -// ListOpts holds a list of values and a validation function. -type ListOpts struct { - values *[]string - validator ValidatorFctType -} - -// NewListOpts creates a new ListOpts with the specified validator. -func NewListOpts(validator ValidatorFctType) ListOpts { - var values []string - return *NewListOptsRef(&values, validator) -} - -// NewListOptsRef creates a new ListOpts with the specified values and validator. -func NewListOptsRef(values *[]string, validator ValidatorFctType) *ListOpts { - return &ListOpts{ - values: values, - validator: validator, - } -} - -func (opts *ListOpts) String() string { - return fmt.Sprintf("%v", []string((*opts.values))) -} - -// Set validates if needed the input value and adds it to the -// internal slice. -func (opts *ListOpts) Set(value string) error { - if opts.validator != nil { - v, err := opts.validator(value) - if err != nil { - return err - } - value = v - } - (*opts.values) = append((*opts.values), value) - return nil -} - -// Delete removes the specified element from the slice. -func (opts *ListOpts) Delete(key string) { - for i, k := range *opts.values { - if k == key { - (*opts.values) = append((*opts.values)[:i], (*opts.values)[i+1:]...) - return - } - } -} - -// GetMap returns the content of values in a map in order to avoid -// duplicates. -func (opts *ListOpts) GetMap() map[string]struct{} { - ret := make(map[string]struct{}) - for _, k := range *opts.values { - ret[k] = struct{}{} - } - return ret -} - -// GetAll returns the values of slice. -func (opts *ListOpts) GetAll() []string { - return (*opts.values) -} - -// GetAllOrEmpty returns the values of the slice -// or an empty slice when there are no values. -func (opts *ListOpts) GetAllOrEmpty() []string { - v := *opts.values - if v == nil { - return make([]string, 0) - } - return v -} - -// Get checks the existence of the specified key. -func (opts *ListOpts) Get(key string) bool { - for _, k := range *opts.values { - if k == key { - return true - } - } - return false -} - -// Len returns the amount of element in the slice. -func (opts *ListOpts) Len() int { - return len((*opts.values)) -} - -// Type returns a string name for this Option type -func (opts *ListOpts) Type() string { - return "list" -} - -// NamedOption is an interface that list and map options -// with names implement. -type NamedOption interface { - Name() string -} - -// NamedListOpts is a ListOpts with a configuration name. -// This struct is useful to keep reference to the assigned -// field name in the internal configuration struct. -type NamedListOpts struct { - name string - ListOpts -} - -var _ NamedOption = &NamedListOpts{} - -// NewNamedListOptsRef creates a reference to a new NamedListOpts struct. -func NewNamedListOptsRef(name string, values *[]string, validator ValidatorFctType) *NamedListOpts { - return &NamedListOpts{ - name: name, - ListOpts: *NewListOptsRef(values, validator), - } -} - -// Name returns the name of the NamedListOpts in the configuration. -func (o *NamedListOpts) Name() string { - return o.name -} - -// MapOpts holds a map of values and a validation function. -type MapOpts struct { - values map[string]string - validator ValidatorFctType -} - -// Set validates if needed the input value and add it to the -// internal map, by splitting on '='. -func (opts *MapOpts) Set(value string) error { - if opts.validator != nil { - v, err := opts.validator(value) - if err != nil { - return err - } - value = v - } - vals := strings.SplitN(value, "=", 2) - if len(vals) == 1 { - (opts.values)[vals[0]] = "" - } else { - (opts.values)[vals[0]] = vals[1] - } - return nil -} - -// GetAll returns the values of MapOpts as a map. -func (opts *MapOpts) GetAll() map[string]string { - return opts.values -} - -func (opts *MapOpts) String() string { - return fmt.Sprintf("%v", map[string]string((opts.values))) -} - -// Type returns a string name for this Option type -func (opts *MapOpts) Type() string { - return "map" -} - -// NewMapOpts creates a new MapOpts with the specified map of values and a validator. -func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts { - if values == nil { - values = make(map[string]string) - } - return &MapOpts{ - values: values, - validator: validator, - } -} - -// NamedMapOpts is a MapOpts struct with a configuration name. -// This struct is useful to keep reference to the assigned -// field name in the internal configuration struct. -type NamedMapOpts struct { - name string - MapOpts -} - -var _ NamedOption = &NamedMapOpts{} - -// NewNamedMapOpts creates a reference to a new NamedMapOpts struct. -func NewNamedMapOpts(name string, values map[string]string, validator ValidatorFctType) *NamedMapOpts { - return &NamedMapOpts{ - name: name, - MapOpts: *NewMapOpts(values, validator), - } -} - -// Name returns the name of the NamedMapOpts in the configuration. -func (o *NamedMapOpts) Name() string { - return o.name -} - -// ValidatorFctType defines a validator function that returns a validated string and/or an error. -type ValidatorFctType func(val string) (string, error) - -// ValidatorFctListType defines a validator function that returns a validated list of string and/or an error -type ValidatorFctListType func(val string) ([]string, error) - -// ValidateIPAddress validates an Ip address. -func ValidateIPAddress(val string) (string, error) { - var ip = net.ParseIP(strings.TrimSpace(val)) - if ip != nil { - return ip.String(), nil - } - return "", fmt.Errorf("%s is not an ip address", val) -} - -// ValidateDNSSearch validates domain for resolvconf search configuration. -// A zero length domain is represented by a dot (.). -func ValidateDNSSearch(val string) (string, error) { - if val = strings.Trim(val, " "); val == "." { - return val, nil - } - return validateDomain(val) -} - -func validateDomain(val string) (string, error) { - if alphaRegexp.FindString(val) == "" { - return "", fmt.Errorf("%s is not a valid domain", val) - } - ns := domainRegexp.FindSubmatch([]byte(val)) - if len(ns) > 0 && len(ns[1]) < 255 { - return string(ns[1]), nil - } - return "", fmt.Errorf("%s is not a valid domain", val) -} - -// ValidateLabel validates that the specified string is a valid label, and returns it. -// Labels are in the form on key=value. -func ValidateLabel(val string) (string, error) { - if strings.Count(val, "=") < 1 { - return "", fmt.Errorf("bad attribute format: %s", val) - } - return val, nil -} - -// ValidateSysctl validates a sysctl and returns it. -func ValidateSysctl(val string) (string, error) { - validSysctlMap := map[string]bool{ - "kernel.msgmax": true, - "kernel.msgmnb": true, - "kernel.msgmni": true, - "kernel.sem": true, - "kernel.shmall": true, - "kernel.shmmax": true, - "kernel.shmmni": true, - "kernel.shm_rmid_forced": true, - } - validSysctlPrefixes := []string{ - "net.", - "fs.mqueue.", - } - arr := strings.Split(val, "=") - if len(arr) < 2 { - return "", fmt.Errorf("sysctl '%s' is not whitelisted", val) - } - if validSysctlMap[arr[0]] { - return val, nil - } - - for _, vp := range validSysctlPrefixes { - if strings.HasPrefix(arr[0], vp) { - return val, nil - } - } - return "", fmt.Errorf("sysctl '%s' is not whitelisted", val) -} - -// FilterOpt is a flag type for validating filters -type FilterOpt struct { - filter filters.Args -} - -// NewFilterOpt returns a new FilterOpt -func NewFilterOpt() FilterOpt { - return FilterOpt{filter: filters.NewArgs()} -} - -func (o *FilterOpt) String() string { - repr, err := filters.ToParam(o.filter) - if err != nil { - return "invalid filters" - } - return repr -} - -// Set sets the value of the opt by parsing the command line value -func (o *FilterOpt) Set(value string) error { - var err error - o.filter, err = filters.ParseFlag(value, o.filter) - return err -} - -// Type returns the option type -func (o *FilterOpt) Type() string { - return "filter" -} - -// Value returns the value of this option -func (o *FilterOpt) Value() filters.Args { - return o.filter -} - -// NanoCPUs is a type for fixed point fractional number. -type NanoCPUs int64 - -// String returns the string format of the number -func (c *NanoCPUs) String() string { - return big.NewRat(c.Value(), 1e9).FloatString(3) -} - -// Set sets the value of the NanoCPU by passing a string -func (c *NanoCPUs) Set(value string) error { - cpus, err := ParseCPUs(value) - *c = NanoCPUs(cpus) - return err -} - -// Type returns the type -func (c *NanoCPUs) Type() string { - return "decimal" -} - -// Value returns the value in int64 -func (c *NanoCPUs) Value() int64 { - return int64(*c) -} - -// ParseCPUs takes a string ratio and returns an integer value of nano cpus -func ParseCPUs(value string) (int64, error) { - cpu, ok := new(big.Rat).SetString(value) - if !ok { - return 0, fmt.Errorf("failed to parse %v as a rational number", value) - } - nano := cpu.Mul(cpu, big.NewRat(1e9, 1)) - if !nano.IsInt() { - return 0, fmt.Errorf("value is too precise") - } - return nano.Num().Int64(), nil -} diff --git a/vendor/github.com/docker/docker/opts/opts_test.go b/vendor/github.com/docker/docker/opts/opts_test.go deleted file mode 100644 index 9f41e47..0000000 --- a/vendor/github.com/docker/docker/opts/opts_test.go +++ /dev/null @@ -1,232 +0,0 @@ -package opts - -import ( - "fmt" - "strings" - "testing" -) - -func TestValidateIPAddress(t *testing.T) { - if ret, err := ValidateIPAddress(`1.2.3.4`); err != nil || ret == "" { - t.Fatalf("ValidateIPAddress(`1.2.3.4`) got %s %s", ret, err) - } - - if ret, err := ValidateIPAddress(`127.0.0.1`); err != nil || ret == "" { - t.Fatalf("ValidateIPAddress(`127.0.0.1`) got %s %s", ret, err) - } - - if ret, err := ValidateIPAddress(`::1`); err != nil || ret == "" { - t.Fatalf("ValidateIPAddress(`::1`) got %s %s", ret, err) - } - - if ret, err := ValidateIPAddress(`127`); err == nil || ret != "" { - t.Fatalf("ValidateIPAddress(`127`) got %s %s", ret, err) - } - - if ret, err := ValidateIPAddress(`random invalid string`); err == nil || ret != "" { - t.Fatalf("ValidateIPAddress(`random invalid string`) got %s %s", ret, err) - } - -} - -func TestMapOpts(t *testing.T) { - tmpMap := make(map[string]string) - o := NewMapOpts(tmpMap, logOptsValidator) - o.Set("max-size=1") - if o.String() != "map[max-size:1]" { - t.Errorf("%s != [map[max-size:1]", o.String()) - } - - o.Set("max-file=2") - if len(tmpMap) != 2 { - t.Errorf("map length %d != 2", len(tmpMap)) - } - - if tmpMap["max-file"] != "2" { - t.Errorf("max-file = %s != 2", tmpMap["max-file"]) - } - - if tmpMap["max-size"] != "1" { - t.Errorf("max-size = %s != 1", tmpMap["max-size"]) - } - if o.Set("dummy-val=3") == nil { - t.Errorf("validator is not being called") - } -} - -func TestListOptsWithoutValidator(t *testing.T) { - o := NewListOpts(nil) - o.Set("foo") - if o.String() != "[foo]" { - t.Errorf("%s != [foo]", o.String()) - } - o.Set("bar") - if o.Len() != 2 { - t.Errorf("%d != 2", o.Len()) - } - o.Set("bar") - if o.Len() != 3 { - t.Errorf("%d != 3", o.Len()) - } - if !o.Get("bar") { - t.Error("o.Get(\"bar\") == false") - } - if o.Get("baz") { - t.Error("o.Get(\"baz\") == true") - } - o.Delete("foo") - if o.String() != "[bar bar]" { - t.Errorf("%s != [bar bar]", o.String()) - } - listOpts := o.GetAll() - if len(listOpts) != 2 || listOpts[0] != "bar" || listOpts[1] != "bar" { - t.Errorf("Expected [[bar bar]], got [%v]", listOpts) - } - mapListOpts := o.GetMap() - if len(mapListOpts) != 1 { - t.Errorf("Expected [map[bar:{}]], got [%v]", mapListOpts) - } - -} - -func TestListOptsWithValidator(t *testing.T) { - // Re-using logOptsvalidator (used by MapOpts) - o := NewListOpts(logOptsValidator) - o.Set("foo") - if o.String() != "[]" { - t.Errorf("%s != []", o.String()) - } - o.Set("foo=bar") - if o.String() != "[]" { - t.Errorf("%s != []", o.String()) - } - o.Set("max-file=2") - if o.Len() != 1 { - t.Errorf("%d != 1", o.Len()) - } - if !o.Get("max-file=2") { - t.Error("o.Get(\"max-file=2\") == false") - } - if o.Get("baz") { - t.Error("o.Get(\"baz\") == true") - } - o.Delete("max-file=2") - if o.String() != "[]" { - t.Errorf("%s != []", o.String()) - } -} - -func TestValidateDNSSearch(t *testing.T) { - valid := []string{ - `.`, - `a`, - `a.`, - `1.foo`, - `17.foo`, - `foo.bar`, - `foo.bar.baz`, - `foo.bar.`, - `foo.bar.baz`, - `foo1.bar2`, - `foo1.bar2.baz`, - `1foo.2bar.`, - `1foo.2bar.baz`, - `foo-1.bar-2`, - `foo-1.bar-2.baz`, - `foo-1.bar-2.`, - `foo-1.bar-2.baz`, - `1-foo.2-bar`, - `1-foo.2-bar.baz`, - `1-foo.2-bar.`, - `1-foo.2-bar.baz`, - } - - invalid := []string{ - ``, - ` `, - ` `, - `17`, - `17.`, - `.17`, - `17-.`, - `17-.foo`, - `.foo`, - `foo-.bar`, - `-foo.bar`, - `foo.bar-`, - `foo.bar-.baz`, - `foo.-bar`, - `foo.-bar.baz`, - `foo.bar.baz.this.should.fail.on.long.name.beause.it.is.longer.thanisshouldbethis.should.fail.on.long.name.beause.it.is.longer.thanisshouldbethis.should.fail.on.long.name.beause.it.is.longer.thanisshouldbethis.should.fail.on.long.name.beause.it.is.longer.thanisshouldbe`, - } - - for _, domain := range valid { - if ret, err := ValidateDNSSearch(domain); err != nil || ret == "" { - t.Fatalf("ValidateDNSSearch(`"+domain+"`) got %s %s", ret, err) - } - } - - for _, domain := range invalid { - if ret, err := ValidateDNSSearch(domain); err == nil || ret != "" { - t.Fatalf("ValidateDNSSearch(`"+domain+"`) got %s %s", ret, err) - } - } -} - -func TestValidateLabel(t *testing.T) { - if _, err := ValidateLabel("label"); err == nil || err.Error() != "bad attribute format: label" { - t.Fatalf("Expected an error [bad attribute format: label], go %v", err) - } - if actual, err := ValidateLabel("key1=value1"); err != nil || actual != "key1=value1" { - t.Fatalf("Expected [key1=value1], got [%v,%v]", actual, err) - } - // Validate it's working with more than one = - if actual, err := ValidateLabel("key1=value1=value2"); err != nil { - t.Fatalf("Expected [key1=value1=value2], got [%v,%v]", actual, err) - } - // Validate it's working with one more - if actual, err := ValidateLabel("key1=value1=value2=value3"); err != nil { - t.Fatalf("Expected [key1=value1=value2=value2], got [%v,%v]", actual, err) - } -} - -func logOptsValidator(val string) (string, error) { - allowedKeys := map[string]string{"max-size": "1", "max-file": "2"} - vals := strings.Split(val, "=") - if allowedKeys[vals[0]] != "" { - return val, nil - } - return "", fmt.Errorf("invalid key %s", vals[0]) -} - -func TestNamedListOpts(t *testing.T) { - var v []string - o := NewNamedListOptsRef("foo-name", &v, nil) - - o.Set("foo") - if o.String() != "[foo]" { - t.Errorf("%s != [foo]", o.String()) - } - if o.Name() != "foo-name" { - t.Errorf("%s != foo-name", o.Name()) - } - if len(v) != 1 { - t.Errorf("expected foo to be in the values, got %v", v) - } -} - -func TestNamedMapOpts(t *testing.T) { - tmpMap := make(map[string]string) - o := NewNamedMapOpts("max-name", tmpMap, nil) - - o.Set("max-size=1") - if o.String() != "map[max-size:1]" { - t.Errorf("%s != [map[max-size:1]", o.String()) - } - if o.Name() != "max-name" { - t.Errorf("%s != max-name", o.Name()) - } - if _, exist := tmpMap["max-size"]; !exist { - t.Errorf("expected map-size to be in the values, got %v", tmpMap) - } -} diff --git a/vendor/github.com/docker/docker/opts/opts_unix.go b/vendor/github.com/docker/docker/opts/opts_unix.go deleted file mode 100644 index f1ce844..0000000 --- a/vendor/github.com/docker/docker/opts/opts_unix.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build !windows - -package opts - -// DefaultHTTPHost Default HTTP Host used if only port is provided to -H flag e.g. docker daemon -H tcp://:8080 -const DefaultHTTPHost = "localhost" diff --git a/vendor/github.com/docker/docker/opts/opts_windows.go b/vendor/github.com/docker/docker/opts/opts_windows.go deleted file mode 100644 index ebe40c9..0000000 --- a/vendor/github.com/docker/docker/opts/opts_windows.go +++ /dev/null @@ -1,56 +0,0 @@ -package opts - -// TODO Windows. Identify bug in GOLang 1.5.1+ and/or Windows Server 2016 TP5. -// @jhowardmsft, @swernli. -// -// On Windows, this mitigates a problem with the default options of running -// a docker client against a local docker daemon on TP5. -// -// What was found that if the default host is "localhost", even if the client -// (and daemon as this is local) is not physically on a network, and the DNS -// cache is flushed (ipconfig /flushdns), then the client will pause for -// exactly one second when connecting to the daemon for calls. For example -// using docker run windowsservercore cmd, the CLI will send a create followed -// by an attach. You see the delay between the attach finishing and the attach -// being seen by the daemon. -// -// Here's some daemon debug logs with additional debug spew put in. The -// AfterWriteJSON log is the very last thing the daemon does as part of the -// create call. The POST /attach is the second CLI call. Notice the second -// time gap. -// -// time="2015-11-06T13:38:37.259627400-08:00" level=debug msg="After createRootfs" -// time="2015-11-06T13:38:37.263626300-08:00" level=debug msg="After setHostConfig" -// time="2015-11-06T13:38:37.267631200-08:00" level=debug msg="before createContainerPl...." -// time="2015-11-06T13:38:37.271629500-08:00" level=debug msg=ToDiskLocking.... -// time="2015-11-06T13:38:37.275643200-08:00" level=debug msg="loggin event...." -// time="2015-11-06T13:38:37.277627600-08:00" level=debug msg="logged event...." -// time="2015-11-06T13:38:37.279631800-08:00" level=debug msg="In defer func" -// time="2015-11-06T13:38:37.282628100-08:00" level=debug msg="After daemon.create" -// time="2015-11-06T13:38:37.286651700-08:00" level=debug msg="return 2" -// time="2015-11-06T13:38:37.289629500-08:00" level=debug msg="Returned from daemon.ContainerCreate" -// time="2015-11-06T13:38:37.311629100-08:00" level=debug msg="After WriteJSON" -// ... 1 second gap here.... -// time="2015-11-06T13:38:38.317866200-08:00" level=debug msg="Calling POST /v1.22/containers/984758282b842f779e805664b2c95d563adc9a979c8a3973e68c807843ee4757/attach" -// time="2015-11-06T13:38:38.326882500-08:00" level=info msg="POST /v1.22/containers/984758282b842f779e805664b2c95d563adc9a979c8a3973e68c807843ee4757/attach?stderr=1&stdin=1&stdout=1&stream=1" -// -// We suspect this is either a bug introduced in GOLang 1.5.1, or that a change -// in GOLang 1.5.1 (from 1.4.3) is exposing a bug in Windows. In theory, -// the Windows networking stack is supposed to resolve "localhost" internally, -// without hitting DNS, or even reading the hosts file (which is why localhost -// is commented out in the hosts file on Windows). -// -// We have validated that working around this using the actual IPv4 localhost -// address does not cause the delay. -// -// This does not occur with the docker client built with 1.4.3 on the same -// Windows build, regardless of whether the daemon is built using 1.5.1 -// or 1.4.3. It does not occur on Linux. We also verified we see the same thing -// on a cross-compiled Windows binary (from Linux). -// -// Final note: This is a mitigation, not a 'real' fix. It is still susceptible -// to the delay if a user were to do 'docker run -H=tcp://localhost:2375...' -// explicitly. - -// DefaultHTTPHost Default HTTP Host used if only port is provided to -H flag e.g. docker daemon -H tcp://:8080 -const DefaultHTTPHost = "127.0.0.1" diff --git a/vendor/github.com/docker/docker/opts/port.go b/vendor/github.com/docker/docker/opts/port.go deleted file mode 100644 index 020a5d1..0000000 --- a/vendor/github.com/docker/docker/opts/port.go +++ /dev/null @@ -1,146 +0,0 @@ -package opts - -import ( - "encoding/csv" - "fmt" - "regexp" - "strconv" - "strings" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/go-connections/nat" -) - -const ( - portOptTargetPort = "target" - portOptPublishedPort = "published" - portOptProtocol = "protocol" - portOptMode = "mode" -) - -// PortOpt represents a port config in swarm mode. -type PortOpt struct { - ports []swarm.PortConfig -} - -// Set a new port value -func (p *PortOpt) Set(value string) error { - longSyntax, err := regexp.MatchString(`\w+=\w+(,\w+=\w+)*`, value) - if err != nil { - return err - } - if longSyntax { - csvReader := csv.NewReader(strings.NewReader(value)) - fields, err := csvReader.Read() - if err != nil { - return err - } - - pConfig := swarm.PortConfig{} - for _, field := range fields { - parts := strings.SplitN(field, "=", 2) - if len(parts) != 2 { - return fmt.Errorf("invalid field %s", field) - } - - key := strings.ToLower(parts[0]) - value := strings.ToLower(parts[1]) - - switch key { - case portOptProtocol: - if value != string(swarm.PortConfigProtocolTCP) && value != string(swarm.PortConfigProtocolUDP) { - return fmt.Errorf("invalid protocol value %s", value) - } - - pConfig.Protocol = swarm.PortConfigProtocol(value) - case portOptMode: - if value != string(swarm.PortConfigPublishModeIngress) && value != string(swarm.PortConfigPublishModeHost) { - return fmt.Errorf("invalid publish mode value %s", value) - } - - pConfig.PublishMode = swarm.PortConfigPublishMode(value) - case portOptTargetPort: - tPort, err := strconv.ParseUint(value, 10, 16) - if err != nil { - return err - } - - pConfig.TargetPort = uint32(tPort) - case portOptPublishedPort: - pPort, err := strconv.ParseUint(value, 10, 16) - if err != nil { - return err - } - - pConfig.PublishedPort = uint32(pPort) - default: - return fmt.Errorf("invalid field key %s", key) - } - } - - if pConfig.TargetPort == 0 { - return fmt.Errorf("missing mandatory field %q", portOptTargetPort) - } - - if pConfig.PublishMode == "" { - pConfig.PublishMode = swarm.PortConfigPublishModeIngress - } - - if pConfig.Protocol == "" { - pConfig.Protocol = swarm.PortConfigProtocolTCP - } - - p.ports = append(p.ports, pConfig) - } else { - // short syntax - portConfigs := []swarm.PortConfig{} - // We can ignore errors because the format was already validated by ValidatePort - ports, portBindings, _ := nat.ParsePortSpecs([]string{value}) - - for port := range ports { - portConfigs = append(portConfigs, ConvertPortToPortConfig(port, portBindings)...) - } - p.ports = append(p.ports, portConfigs...) - } - return nil -} - -// Type returns the type of this option -func (p *PortOpt) Type() string { - return "port" -} - -// String returns a string repr of this option -func (p *PortOpt) String() string { - ports := []string{} - for _, port := range p.ports { - repr := fmt.Sprintf("%v:%v/%s/%s", port.PublishedPort, port.TargetPort, port.Protocol, port.PublishMode) - ports = append(ports, repr) - } - return strings.Join(ports, ", ") -} - -// Value returns the ports -func (p *PortOpt) Value() []swarm.PortConfig { - return p.ports -} - -// ConvertPortToPortConfig converts ports to the swarm type -func ConvertPortToPortConfig( - port nat.Port, - portBindings map[nat.Port][]nat.PortBinding, -) []swarm.PortConfig { - ports := []swarm.PortConfig{} - - for _, binding := range portBindings[port] { - hostPort, _ := strconv.ParseUint(binding.HostPort, 10, 16) - ports = append(ports, swarm.PortConfig{ - //TODO Name: ? - Protocol: swarm.PortConfigProtocol(strings.ToLower(port.Proto())), - TargetPort: uint32(port.Int()), - PublishedPort: uint32(hostPort), - PublishMode: swarm.PortConfigPublishModeIngress, - }) - } - return ports -} diff --git a/vendor/github.com/docker/docker/opts/port_test.go b/vendor/github.com/docker/docker/opts/port_test.go deleted file mode 100644 index 67bcf8f..0000000 --- a/vendor/github.com/docker/docker/opts/port_test.go +++ /dev/null @@ -1,259 +0,0 @@ -package opts - -import ( - "testing" - - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestPortOptValidSimpleSyntax(t *testing.T) { - testCases := []struct { - value string - expected []swarm.PortConfig - }{ - { - value: "80", - expected: []swarm.PortConfig{ - { - Protocol: "tcp", - TargetPort: 80, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - }, - }, - { - value: "80:8080", - expected: []swarm.PortConfig{ - { - Protocol: "tcp", - TargetPort: 8080, - PublishedPort: 80, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - }, - }, - { - value: "8080:80/tcp", - expected: []swarm.PortConfig{ - { - Protocol: "tcp", - TargetPort: 80, - PublishedPort: 8080, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - }, - }, - { - value: "80:8080/udp", - expected: []swarm.PortConfig{ - { - Protocol: "udp", - TargetPort: 8080, - PublishedPort: 80, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - }, - }, - { - value: "80-81:8080-8081/tcp", - expected: []swarm.PortConfig{ - { - Protocol: "tcp", - TargetPort: 8080, - PublishedPort: 80, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - { - Protocol: "tcp", - TargetPort: 8081, - PublishedPort: 81, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - }, - }, - { - value: "80-82:8080-8082/udp", - expected: []swarm.PortConfig{ - { - Protocol: "udp", - TargetPort: 8080, - PublishedPort: 80, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - { - Protocol: "udp", - TargetPort: 8081, - PublishedPort: 81, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - { - Protocol: "udp", - TargetPort: 8082, - PublishedPort: 82, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - }, - }, - } - for _, tc := range testCases { - var port PortOpt - assert.NilError(t, port.Set(tc.value)) - assert.Equal(t, len(port.Value()), len(tc.expected)) - for _, expectedPortConfig := range tc.expected { - assertContains(t, port.Value(), expectedPortConfig) - } - } -} - -func TestPortOptValidComplexSyntax(t *testing.T) { - testCases := []struct { - value string - expected []swarm.PortConfig - }{ - { - value: "target=80", - expected: []swarm.PortConfig{ - { - TargetPort: 80, - Protocol: "tcp", - PublishMode: swarm.PortConfigPublishModeIngress, - }, - }, - }, - { - value: "target=80,protocol=tcp", - expected: []swarm.PortConfig{ - { - Protocol: "tcp", - TargetPort: 80, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - }, - }, - { - value: "target=80,published=8080,protocol=tcp", - expected: []swarm.PortConfig{ - { - Protocol: "tcp", - TargetPort: 80, - PublishedPort: 8080, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - }, - }, - { - value: "published=80,target=8080,protocol=tcp", - expected: []swarm.PortConfig{ - { - Protocol: "tcp", - TargetPort: 8080, - PublishedPort: 80, - PublishMode: swarm.PortConfigPublishModeIngress, - }, - }, - }, - { - value: "target=80,published=8080,protocol=tcp,mode=host", - expected: []swarm.PortConfig{ - { - Protocol: "tcp", - TargetPort: 80, - PublishedPort: 8080, - PublishMode: "host", - }, - }, - }, - { - value: "target=80,published=8080,mode=host", - expected: []swarm.PortConfig{ - { - TargetPort: 80, - PublishedPort: 8080, - PublishMode: "host", - Protocol: "tcp", - }, - }, - }, - { - value: "target=80,published=8080,mode=ingress", - expected: []swarm.PortConfig{ - { - TargetPort: 80, - PublishedPort: 8080, - PublishMode: "ingress", - Protocol: "tcp", - }, - }, - }, - } - for _, tc := range testCases { - var port PortOpt - assert.NilError(t, port.Set(tc.value)) - assert.Equal(t, len(port.Value()), len(tc.expected)) - for _, expectedPortConfig := range tc.expected { - assertContains(t, port.Value(), expectedPortConfig) - } - } -} - -func TestPortOptInvalidComplexSyntax(t *testing.T) { - testCases := []struct { - value string - expectedError string - }{ - { - value: "invalid,target=80", - expectedError: "invalid field", - }, - { - value: "invalid=field", - expectedError: "invalid field", - }, - { - value: "protocol=invalid", - expectedError: "invalid protocol value", - }, - { - value: "target=invalid", - expectedError: "invalid syntax", - }, - { - value: "published=invalid", - expectedError: "invalid syntax", - }, - { - value: "mode=invalid", - expectedError: "invalid publish mode value", - }, - { - value: "published=8080,protocol=tcp,mode=ingress", - expectedError: "missing mandatory field", - }, - { - value: `target=80,protocol="tcp,mode=ingress"`, - expectedError: "non-quoted-field", - }, - { - value: `target=80,"protocol=tcp,mode=ingress"`, - expectedError: "invalid protocol value", - }, - } - for _, tc := range testCases { - var port PortOpt - assert.Error(t, port.Set(tc.value), tc.expectedError) - } -} - -func assertContains(t *testing.T, portConfigs []swarm.PortConfig, expected swarm.PortConfig) { - var contains = false - for _, portConfig := range portConfigs { - if portConfig == expected { - contains = true - break - } - } - if !contains { - t.Errorf("expected %v to contain %v, did not", portConfigs, expected) - } -} diff --git a/vendor/github.com/docker/docker/opts/quotedstring.go b/vendor/github.com/docker/docker/opts/quotedstring.go deleted file mode 100644 index fb1e537..0000000 --- a/vendor/github.com/docker/docker/opts/quotedstring.go +++ /dev/null @@ -1,37 +0,0 @@ -package opts - -// QuotedString is a string that may have extra quotes around the value. The -// quotes are stripped from the value. -type QuotedString struct { - value *string -} - -// Set sets a new value -func (s *QuotedString) Set(val string) error { - *s.value = trimQuotes(val) - return nil -} - -// Type returns the type of the value -func (s *QuotedString) Type() string { - return "string" -} - -func (s *QuotedString) String() string { - return string(*s.value) -} - -func trimQuotes(value string) string { - lastIndex := len(value) - 1 - for _, char := range []byte{'\'', '"'} { - if value[0] == char && value[lastIndex] == char { - return value[1:lastIndex] - } - } - return value -} - -// NewQuotedString returns a new quoted string option -func NewQuotedString(value *string) *QuotedString { - return &QuotedString{value: value} -} diff --git a/vendor/github.com/docker/docker/opts/quotedstring_test.go b/vendor/github.com/docker/docker/opts/quotedstring_test.go deleted file mode 100644 index 0ebf04b..0000000 --- a/vendor/github.com/docker/docker/opts/quotedstring_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package opts - -import ( - "github.com/docker/docker/pkg/testutil/assert" - "testing" -) - -func TestQuotedStringSetWithQuotes(t *testing.T) { - value := "" - qs := NewQuotedString(&value) - assert.NilError(t, qs.Set("\"something\"")) - assert.Equal(t, qs.String(), "something") - assert.Equal(t, value, "something") -} - -func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) { - value := "" - qs := NewQuotedString(&value) - assert.NilError(t, qs.Set("\"something'")) - assert.Equal(t, qs.String(), "\"something'") -} - -func TestQuotedStringSetWithNoQuotes(t *testing.T) { - value := "" - qs := NewQuotedString(&value) - assert.NilError(t, qs.Set("something")) - assert.Equal(t, qs.String(), "something") -} diff --git a/vendor/github.com/docker/docker/opts/secret.go b/vendor/github.com/docker/docker/opts/secret.go deleted file mode 100644 index 1fefcf8..0000000 --- a/vendor/github.com/docker/docker/opts/secret.go +++ /dev/null @@ -1,107 +0,0 @@ -package opts - -import ( - "encoding/csv" - "fmt" - "os" - "path/filepath" - "strconv" - "strings" - - "github.com/docker/docker/api/types" -) - -// SecretOpt is a Value type for parsing secrets -type SecretOpt struct { - values []*types.SecretRequestOption -} - -// Set a new secret value -func (o *SecretOpt) Set(value string) error { - csvReader := csv.NewReader(strings.NewReader(value)) - fields, err := csvReader.Read() - if err != nil { - return err - } - - options := &types.SecretRequestOption{ - Source: "", - Target: "", - UID: "0", - GID: "0", - Mode: 0444, - } - - // support a simple syntax of --secret foo - if len(fields) == 1 { - options.Source = fields[0] - options.Target = fields[0] - o.values = append(o.values, options) - return nil - } - - for _, field := range fields { - parts := strings.SplitN(field, "=", 2) - key := strings.ToLower(parts[0]) - - if len(parts) != 2 { - return fmt.Errorf("invalid field '%s' must be a key=value pair", field) - } - - value := parts[1] - switch key { - case "source", "src": - options.Source = value - case "target": - tDir, _ := filepath.Split(value) - if tDir != "" { - return fmt.Errorf("target must not be a path") - } - options.Target = value - case "uid": - options.UID = value - case "gid": - options.GID = value - case "mode": - m, err := strconv.ParseUint(value, 0, 32) - if err != nil { - return fmt.Errorf("invalid mode specified: %v", err) - } - - options.Mode = os.FileMode(m) - default: - if len(fields) == 1 && value == "" { - - } else { - return fmt.Errorf("invalid field in secret request: %s", key) - } - } - } - - if options.Source == "" { - return fmt.Errorf("source is required") - } - - o.values = append(o.values, options) - return nil -} - -// Type returns the type of this option -func (o *SecretOpt) Type() string { - return "secret" -} - -// String returns a string repr of this option -func (o *SecretOpt) String() string { - secrets := []string{} - for _, secret := range o.values { - repr := fmt.Sprintf("%s -> %s", secret.Source, secret.Target) - secrets = append(secrets, repr) - } - return strings.Join(secrets, ", ") -} - -// Value returns the secret requests -func (o *SecretOpt) Value() []*types.SecretRequestOption { - return o.values -} diff --git a/vendor/github.com/docker/docker/opts/secret_test.go b/vendor/github.com/docker/docker/opts/secret_test.go deleted file mode 100644 index d978c86..0000000 --- a/vendor/github.com/docker/docker/opts/secret_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package opts - -import ( - "os" - "testing" - - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestSecretOptionsSimple(t *testing.T) { - var opt SecretOpt - - testCase := "app-secret" - assert.NilError(t, opt.Set(testCase)) - - reqs := opt.Value() - assert.Equal(t, len(reqs), 1) - req := reqs[0] - assert.Equal(t, req.Source, "app-secret") - assert.Equal(t, req.Target, "app-secret") - assert.Equal(t, req.UID, "0") - assert.Equal(t, req.GID, "0") -} - -func TestSecretOptionsSourceTarget(t *testing.T) { - var opt SecretOpt - - testCase := "source=foo,target=testing" - assert.NilError(t, opt.Set(testCase)) - - reqs := opt.Value() - assert.Equal(t, len(reqs), 1) - req := reqs[0] - assert.Equal(t, req.Source, "foo") - assert.Equal(t, req.Target, "testing") -} - -func TestSecretOptionsShorthand(t *testing.T) { - var opt SecretOpt - - testCase := "src=foo,target=testing" - assert.NilError(t, opt.Set(testCase)) - - reqs := opt.Value() - assert.Equal(t, len(reqs), 1) - req := reqs[0] - assert.Equal(t, req.Source, "foo") -} - -func TestSecretOptionsCustomUidGid(t *testing.T) { - var opt SecretOpt - - testCase := "source=foo,target=testing,uid=1000,gid=1001" - assert.NilError(t, opt.Set(testCase)) - - reqs := opt.Value() - assert.Equal(t, len(reqs), 1) - req := reqs[0] - assert.Equal(t, req.Source, "foo") - assert.Equal(t, req.Target, "testing") - assert.Equal(t, req.UID, "1000") - assert.Equal(t, req.GID, "1001") -} - -func TestSecretOptionsCustomMode(t *testing.T) { - var opt SecretOpt - - testCase := "source=foo,target=testing,uid=1000,gid=1001,mode=0444" - assert.NilError(t, opt.Set(testCase)) - - reqs := opt.Value() - assert.Equal(t, len(reqs), 1) - req := reqs[0] - assert.Equal(t, req.Source, "foo") - assert.Equal(t, req.Target, "testing") - assert.Equal(t, req.UID, "1000") - assert.Equal(t, req.GID, "1001") - assert.Equal(t, req.Mode, os.FileMode(0444)) -} diff --git a/vendor/github.com/docker/docker/pkg/README.md b/vendor/github.com/docker/docker/pkg/README.md deleted file mode 100644 index c4b78a8..0000000 --- a/vendor/github.com/docker/docker/pkg/README.md +++ /dev/null @@ -1,11 +0,0 @@ -pkg/ is a collection of utility packages used by the Docker project without being specific to its internals. - -Utility packages are kept separate from the docker core codebase to keep it as small and concise as possible. -If some utilities grow larger and their APIs stabilize, they may be moved to their own repository under the -Docker organization, to facilitate re-use by other projects. However that is not the priority. - -The directory `pkg` is named after the same directory in the camlistore project. Since Brad is a core -Go maintainer, we thought it made sense to copy his methods for organizing Go code :) Thanks Brad! - -Because utility packages are small and neatly separated from the rest of the codebase, they are a good -place to start for aspiring maintainers and contributors. Get in touch if you want to help maintain them! diff --git a/vendor/github.com/docker/docker/pkg/aaparser/aaparser.go b/vendor/github.com/docker/docker/pkg/aaparser/aaparser.go deleted file mode 100644 index ffcc564..0000000 --- a/vendor/github.com/docker/docker/pkg/aaparser/aaparser.go +++ /dev/null @@ -1,91 +0,0 @@ -// Package aaparser is a convenience package interacting with `apparmor_parser`. -package aaparser - -import ( - "fmt" - "os/exec" - "strconv" - "strings" -) - -const ( - binary = "apparmor_parser" -) - -// GetVersion returns the major and minor version of apparmor_parser. -func GetVersion() (int, error) { - output, err := cmd("", "--version") - if err != nil { - return -1, err - } - - return parseVersion(output) -} - -// LoadProfile runs `apparmor_parser -r` on a specified apparmor profile to -// replace the profile. -func LoadProfile(profilePath string) error { - _, err := cmd("", "-r", profilePath) - if err != nil { - return err - } - return nil -} - -// cmd runs `apparmor_parser` with the passed arguments. -func cmd(dir string, arg ...string) (string, error) { - c := exec.Command(binary, arg...) - c.Dir = dir - - output, err := c.CombinedOutput() - if err != nil { - return "", fmt.Errorf("running `%s %s` failed with output: %s\nerror: %v", c.Path, strings.Join(c.Args, " "), string(output), err) - } - - return string(output), nil -} - -// parseVersion takes the output from `apparmor_parser --version` and returns -// a representation of the {major, minor, patch} version as a single number of -// the form MMmmPPP {major, minor, patch}. -func parseVersion(output string) (int, error) { - // output is in the form of the following: - // AppArmor parser version 2.9.1 - // Copyright (C) 1999-2008 Novell Inc. - // Copyright 2009-2012 Canonical Ltd. - - lines := strings.SplitN(output, "\n", 2) - words := strings.Split(lines[0], " ") - version := words[len(words)-1] - - // split by major minor version - v := strings.Split(version, ".") - if len(v) == 0 || len(v) > 3 { - return -1, fmt.Errorf("parsing version failed for output: `%s`", output) - } - - // Default the versions to 0. - var majorVersion, minorVersion, patchLevel int - - majorVersion, err := strconv.Atoi(v[0]) - if err != nil { - return -1, err - } - - if len(v) > 1 { - minorVersion, err = strconv.Atoi(v[1]) - if err != nil { - return -1, err - } - } - if len(v) > 2 { - patchLevel, err = strconv.Atoi(v[2]) - if err != nil { - return -1, err - } - } - - // major*10^5 + minor*10^3 + patch*10^0 - numericVersion := majorVersion*1e5 + minorVersion*1e3 + patchLevel - return numericVersion, nil -} diff --git a/vendor/github.com/docker/docker/pkg/aaparser/aaparser_test.go b/vendor/github.com/docker/docker/pkg/aaparser/aaparser_test.go deleted file mode 100644 index 69bc8d2..0000000 --- a/vendor/github.com/docker/docker/pkg/aaparser/aaparser_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package aaparser - -import ( - "testing" -) - -type versionExpected struct { - output string - version int -} - -func TestParseVersion(t *testing.T) { - versions := []versionExpected{ - { - output: `AppArmor parser version 2.10 -Copyright (C) 1999-2008 Novell Inc. -Copyright 2009-2012 Canonical Ltd. - -`, - version: 210000, - }, - { - output: `AppArmor parser version 2.8 -Copyright (C) 1999-2008 Novell Inc. -Copyright 2009-2012 Canonical Ltd. - -`, - version: 208000, - }, - { - output: `AppArmor parser version 2.20 -Copyright (C) 1999-2008 Novell Inc. -Copyright 2009-2012 Canonical Ltd. - -`, - version: 220000, - }, - { - output: `AppArmor parser version 2.05 -Copyright (C) 1999-2008 Novell Inc. -Copyright 2009-2012 Canonical Ltd. - -`, - version: 205000, - }, - { - output: `AppArmor parser version 2.9.95 -Copyright (C) 1999-2008 Novell Inc. -Copyright 2009-2012 Canonical Ltd. - -`, - version: 209095, - }, - { - output: `AppArmor parser version 3.14.159 -Copyright (C) 1999-2008 Novell Inc. -Copyright 2009-2012 Canonical Ltd. - -`, - version: 314159, - }, - } - - for _, v := range versions { - version, err := parseVersion(v.output) - if err != nil { - t.Fatalf("expected error to be nil for %#v, got: %v", v, err) - } - if version != v.version { - t.Fatalf("expected version to be %d, was %d, for: %#v\n", v.version, version, v) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/archive/README.md b/vendor/github.com/docker/docker/pkg/archive/README.md deleted file mode 100644 index 7307d96..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/README.md +++ /dev/null @@ -1 +0,0 @@ -This code provides helper functions for dealing with archive files. diff --git a/vendor/github.com/docker/docker/pkg/archive/archive.go b/vendor/github.com/docker/docker/pkg/archive/archive.go deleted file mode 100644 index 3261c4f..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/archive.go +++ /dev/null @@ -1,1175 +0,0 @@ -package archive - -import ( - "archive/tar" - "bufio" - "bytes" - "compress/bzip2" - "compress/gzip" - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "runtime" - "strings" - "syscall" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/fileutils" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/pools" - "github.com/docker/docker/pkg/promise" - "github.com/docker/docker/pkg/system" -) - -type ( - // Compression is the state represents if compressed or not. - Compression int - // WhiteoutFormat is the format of whiteouts unpacked - WhiteoutFormat int - // TarChownOptions wraps the chown options UID and GID. - TarChownOptions struct { - UID, GID int - } - - // TarOptions wraps the tar options. - TarOptions struct { - IncludeFiles []string - ExcludePatterns []string - Compression Compression - NoLchown bool - UIDMaps []idtools.IDMap - GIDMaps []idtools.IDMap - ChownOpts *TarChownOptions - IncludeSourceDir bool - // WhiteoutFormat is the expected on disk format for whiteout files. - // This format will be converted to the standard format on pack - // and from the standard format on unpack. - WhiteoutFormat WhiteoutFormat - // When unpacking, specifies whether overwriting a directory with a - // non-directory is allowed and vice versa. - NoOverwriteDirNonDir bool - // For each include when creating an archive, the included name will be - // replaced with the matching name from this map. - RebaseNames map[string]string - InUserNS bool - } - - // Archiver allows the reuse of most utility functions of this package - // with a pluggable Untar function. Also, to facilitate the passing of - // specific id mappings for untar, an archiver can be created with maps - // which will then be passed to Untar operations - Archiver struct { - Untar func(io.Reader, string, *TarOptions) error - UIDMaps []idtools.IDMap - GIDMaps []idtools.IDMap - } - - // breakoutError is used to differentiate errors related to breaking out - // When testing archive breakout in the unit tests, this error is expected - // in order for the test to pass. - breakoutError error -) - -var ( - // ErrNotImplemented is the error message of function not implemented. - ErrNotImplemented = errors.New("Function not implemented") - defaultArchiver = &Archiver{Untar: Untar, UIDMaps: nil, GIDMaps: nil} -) - -const ( - // HeaderSize is the size in bytes of a tar header - HeaderSize = 512 -) - -const ( - // Uncompressed represents the uncompressed. - Uncompressed Compression = iota - // Bzip2 is bzip2 compression algorithm. - Bzip2 - // Gzip is gzip compression algorithm. - Gzip - // Xz is xz compression algorithm. - Xz -) - -const ( - // AUFSWhiteoutFormat is the default format for whiteouts - AUFSWhiteoutFormat WhiteoutFormat = iota - // OverlayWhiteoutFormat formats whiteout according to the overlay - // standard. - OverlayWhiteoutFormat -) - -// IsArchive checks for the magic bytes of a tar or any supported compression -// algorithm. -func IsArchive(header []byte) bool { - compression := DetectCompression(header) - if compression != Uncompressed { - return true - } - r := tar.NewReader(bytes.NewBuffer(header)) - _, err := r.Next() - return err == nil -} - -// IsArchivePath checks if the (possibly compressed) file at the given path -// starts with a tar file header. -func IsArchivePath(path string) bool { - file, err := os.Open(path) - if err != nil { - return false - } - defer file.Close() - rdr, err := DecompressStream(file) - if err != nil { - return false - } - r := tar.NewReader(rdr) - _, err = r.Next() - return err == nil -} - -// DetectCompression detects the compression algorithm of the source. -func DetectCompression(source []byte) Compression { - for compression, m := range map[Compression][]byte{ - Bzip2: {0x42, 0x5A, 0x68}, - Gzip: {0x1F, 0x8B, 0x08}, - Xz: {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00}, - } { - if len(source) < len(m) { - logrus.Debug("Len too short") - continue - } - if bytes.Compare(m, source[:len(m)]) == 0 { - return compression - } - } - return Uncompressed -} - -func xzDecompress(archive io.Reader) (io.ReadCloser, <-chan struct{}, error) { - args := []string{"xz", "-d", "-c", "-q"} - - return cmdStream(exec.Command(args[0], args[1:]...), archive) -} - -// DecompressStream decompresses the archive and returns a ReaderCloser with the decompressed archive. -func DecompressStream(archive io.Reader) (io.ReadCloser, error) { - p := pools.BufioReader32KPool - buf := p.Get(archive) - bs, err := buf.Peek(10) - if err != nil && err != io.EOF { - // Note: we'll ignore any io.EOF error because there are some odd - // cases where the layer.tar file will be empty (zero bytes) and - // that results in an io.EOF from the Peek() call. So, in those - // cases we'll just treat it as a non-compressed stream and - // that means just create an empty layer. - // See Issue 18170 - return nil, err - } - - compression := DetectCompression(bs) - switch compression { - case Uncompressed: - readBufWrapper := p.NewReadCloserWrapper(buf, buf) - return readBufWrapper, nil - case Gzip: - gzReader, err := gzip.NewReader(buf) - if err != nil { - return nil, err - } - readBufWrapper := p.NewReadCloserWrapper(buf, gzReader) - return readBufWrapper, nil - case Bzip2: - bz2Reader := bzip2.NewReader(buf) - readBufWrapper := p.NewReadCloserWrapper(buf, bz2Reader) - return readBufWrapper, nil - case Xz: - xzReader, chdone, err := xzDecompress(buf) - if err != nil { - return nil, err - } - readBufWrapper := p.NewReadCloserWrapper(buf, xzReader) - return ioutils.NewReadCloserWrapper(readBufWrapper, func() error { - <-chdone - return readBufWrapper.Close() - }), nil - default: - return nil, fmt.Errorf("Unsupported compression format %s", (&compression).Extension()) - } -} - -// CompressStream compresseses the dest with specified compression algorithm. -func CompressStream(dest io.Writer, compression Compression) (io.WriteCloser, error) { - p := pools.BufioWriter32KPool - buf := p.Get(dest) - switch compression { - case Uncompressed: - writeBufWrapper := p.NewWriteCloserWrapper(buf, buf) - return writeBufWrapper, nil - case Gzip: - gzWriter := gzip.NewWriter(dest) - writeBufWrapper := p.NewWriteCloserWrapper(buf, gzWriter) - return writeBufWrapper, nil - case Bzip2, Xz: - // archive/bzip2 does not support writing, and there is no xz support at all - // However, this is not a problem as docker only currently generates gzipped tars - return nil, fmt.Errorf("Unsupported compression format %s", (&compression).Extension()) - default: - return nil, fmt.Errorf("Unsupported compression format %s", (&compression).Extension()) - } -} - -// Extension returns the extension of a file that uses the specified compression algorithm. -func (compression *Compression) Extension() string { - switch *compression { - case Uncompressed: - return "tar" - case Bzip2: - return "tar.bz2" - case Gzip: - return "tar.gz" - case Xz: - return "tar.xz" - } - return "" -} - -type tarWhiteoutConverter interface { - ConvertWrite(*tar.Header, string, os.FileInfo) (*tar.Header, error) - ConvertRead(*tar.Header, string) (bool, error) -} - -type tarAppender struct { - TarWriter *tar.Writer - Buffer *bufio.Writer - - // for hardlink mapping - SeenFiles map[uint64]string - UIDMaps []idtools.IDMap - GIDMaps []idtools.IDMap - - // For packing and unpacking whiteout files in the - // non standard format. The whiteout files defined - // by the AUFS standard are used as the tar whiteout - // standard. - WhiteoutConverter tarWhiteoutConverter -} - -// canonicalTarName provides a platform-independent and consistent posix-style -//path for files and directories to be archived regardless of the platform. -func canonicalTarName(name string, isDir bool) (string, error) { - name, err := CanonicalTarNameForPath(name) - if err != nil { - return "", err - } - - // suffix with '/' for directories - if isDir && !strings.HasSuffix(name, "/") { - name += "/" - } - return name, nil -} - -// addTarFile adds to the tar archive a file from `path` as `name` -func (ta *tarAppender) addTarFile(path, name string) error { - fi, err := os.Lstat(path) - if err != nil { - return err - } - - link := "" - if fi.Mode()&os.ModeSymlink != 0 { - if link, err = os.Readlink(path); err != nil { - return err - } - } - - hdr, err := tar.FileInfoHeader(fi, link) - if err != nil { - return err - } - hdr.Mode = int64(chmodTarEntry(os.FileMode(hdr.Mode))) - - name, err = canonicalTarName(name, fi.IsDir()) - if err != nil { - return fmt.Errorf("tar: cannot canonicalize path: %v", err) - } - hdr.Name = name - - inode, err := setHeaderForSpecialDevice(hdr, ta, name, fi.Sys()) - if err != nil { - return err - } - - // if it's not a directory and has more than 1 link, - // it's hard linked, so set the type flag accordingly - if !fi.IsDir() && hasHardlinks(fi) { - // a link should have a name that it links too - // and that linked name should be first in the tar archive - if oldpath, ok := ta.SeenFiles[inode]; ok { - hdr.Typeflag = tar.TypeLink - hdr.Linkname = oldpath - hdr.Size = 0 // This Must be here for the writer math to add up! - } else { - ta.SeenFiles[inode] = name - } - } - - capability, _ := system.Lgetxattr(path, "security.capability") - if capability != nil { - hdr.Xattrs = make(map[string]string) - hdr.Xattrs["security.capability"] = string(capability) - } - - //handle re-mapping container ID mappings back to host ID mappings before - //writing tar headers/files. We skip whiteout files because they were written - //by the kernel and already have proper ownership relative to the host - if !strings.HasPrefix(filepath.Base(hdr.Name), WhiteoutPrefix) && (ta.UIDMaps != nil || ta.GIDMaps != nil) { - uid, gid, err := getFileUIDGID(fi.Sys()) - if err != nil { - return err - } - xUID, err := idtools.ToContainer(uid, ta.UIDMaps) - if err != nil { - return err - } - xGID, err := idtools.ToContainer(gid, ta.GIDMaps) - if err != nil { - return err - } - hdr.Uid = xUID - hdr.Gid = xGID - } - - if ta.WhiteoutConverter != nil { - wo, err := ta.WhiteoutConverter.ConvertWrite(hdr, path, fi) - if err != nil { - return err - } - - // If a new whiteout file exists, write original hdr, then - // replace hdr with wo to be written after. Whiteouts should - // always be written after the original. Note the original - // hdr may have been updated to be a whiteout with returning - // a whiteout header - if wo != nil { - if err := ta.TarWriter.WriteHeader(hdr); err != nil { - return err - } - if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 { - return fmt.Errorf("tar: cannot use whiteout for non-empty file") - } - hdr = wo - } - } - - if err := ta.TarWriter.WriteHeader(hdr); err != nil { - return err - } - - if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 { - // We use system.OpenSequential to ensure we use sequential file - // access on Windows to avoid depleting the standby list. - // On Linux, this equates to a regular os.Open. - file, err := system.OpenSequential(path) - if err != nil { - return err - } - - ta.Buffer.Reset(ta.TarWriter) - defer ta.Buffer.Reset(nil) - _, err = io.Copy(ta.Buffer, file) - file.Close() - if err != nil { - return err - } - err = ta.Buffer.Flush() - if err != nil { - return err - } - } - - return nil -} - -func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, Lchown bool, chownOpts *TarChownOptions, inUserns bool) error { - // hdr.Mode is in linux format, which we can use for sycalls, - // but for os.Foo() calls we need the mode converted to os.FileMode, - // so use hdrInfo.Mode() (they differ for e.g. setuid bits) - hdrInfo := hdr.FileInfo() - - switch hdr.Typeflag { - case tar.TypeDir: - // Create directory unless it exists as a directory already. - // In that case we just want to merge the two - if fi, err := os.Lstat(path); !(err == nil && fi.IsDir()) { - if err := os.Mkdir(path, hdrInfo.Mode()); err != nil { - return err - } - } - - case tar.TypeReg, tar.TypeRegA: - // Source is regular file. We use system.OpenFileSequential to use sequential - // file access to avoid depleting the standby list on Windows. - // On Linux, this equates to a regular os.OpenFile - file, err := system.OpenFileSequential(path, os.O_CREATE|os.O_WRONLY, hdrInfo.Mode()) - if err != nil { - return err - } - if _, err := io.Copy(file, reader); err != nil { - file.Close() - return err - } - file.Close() - - case tar.TypeBlock, tar.TypeChar: - if inUserns { // cannot create devices in a userns - return nil - } - // Handle this is an OS-specific way - if err := handleTarTypeBlockCharFifo(hdr, path); err != nil { - return err - } - - case tar.TypeFifo: - // Handle this is an OS-specific way - if err := handleTarTypeBlockCharFifo(hdr, path); err != nil { - return err - } - - case tar.TypeLink: - targetPath := filepath.Join(extractDir, hdr.Linkname) - // check for hardlink breakout - if !strings.HasPrefix(targetPath, extractDir) { - return breakoutError(fmt.Errorf("invalid hardlink %q -> %q", targetPath, hdr.Linkname)) - } - if err := os.Link(targetPath, path); err != nil { - return err - } - - case tar.TypeSymlink: - // path -> hdr.Linkname = targetPath - // e.g. /extractDir/path/to/symlink -> ../2/file = /extractDir/path/2/file - targetPath := filepath.Join(filepath.Dir(path), hdr.Linkname) - - // the reason we don't need to check symlinks in the path (with FollowSymlinkInScope) is because - // that symlink would first have to be created, which would be caught earlier, at this very check: - if !strings.HasPrefix(targetPath, extractDir) { - return breakoutError(fmt.Errorf("invalid symlink %q -> %q", path, hdr.Linkname)) - } - if err := os.Symlink(hdr.Linkname, path); err != nil { - return err - } - - case tar.TypeXGlobalHeader: - logrus.Debug("PAX Global Extended Headers found and ignored") - return nil - - default: - return fmt.Errorf("Unhandled tar header type %d\n", hdr.Typeflag) - } - - // Lchown is not supported on Windows. - if Lchown && runtime.GOOS != "windows" { - if chownOpts == nil { - chownOpts = &TarChownOptions{UID: hdr.Uid, GID: hdr.Gid} - } - if err := os.Lchown(path, chownOpts.UID, chownOpts.GID); err != nil { - return err - } - } - - var errors []string - for key, value := range hdr.Xattrs { - if err := system.Lsetxattr(path, key, []byte(value), 0); err != nil { - if err == syscall.ENOTSUP { - // We ignore errors here because not all graphdrivers support - // xattrs *cough* old versions of AUFS *cough*. However only - // ENOTSUP should be emitted in that case, otherwise we still - // bail. - errors = append(errors, err.Error()) - continue - } - return err - } - - } - - if len(errors) > 0 { - logrus.WithFields(logrus.Fields{ - "errors": errors, - }).Warn("ignored xattrs in archive: underlying filesystem doesn't support them") - } - - // There is no LChmod, so ignore mode for symlink. Also, this - // must happen after chown, as that can modify the file mode - if err := handleLChmod(hdr, path, hdrInfo); err != nil { - return err - } - - aTime := hdr.AccessTime - if aTime.Before(hdr.ModTime) { - // Last access time should never be before last modified time. - aTime = hdr.ModTime - } - - // system.Chtimes doesn't support a NOFOLLOW flag atm - if hdr.Typeflag == tar.TypeLink { - if fi, err := os.Lstat(hdr.Linkname); err == nil && (fi.Mode()&os.ModeSymlink == 0) { - if err := system.Chtimes(path, aTime, hdr.ModTime); err != nil { - return err - } - } - } else if hdr.Typeflag != tar.TypeSymlink { - if err := system.Chtimes(path, aTime, hdr.ModTime); err != nil { - return err - } - } else { - ts := []syscall.Timespec{timeToTimespec(aTime), timeToTimespec(hdr.ModTime)} - if err := system.LUtimesNano(path, ts); err != nil && err != system.ErrNotSupportedPlatform { - return err - } - } - return nil -} - -// Tar creates an archive from the directory at `path`, and returns it as a -// stream of bytes. -func Tar(path string, compression Compression) (io.ReadCloser, error) { - return TarWithOptions(path, &TarOptions{Compression: compression}) -} - -// TarWithOptions creates an archive from the directory at `path`, only including files whose relative -// paths are included in `options.IncludeFiles` (if non-nil) or not in `options.ExcludePatterns`. -func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error) { - - // Fix the source path to work with long path names. This is a no-op - // on platforms other than Windows. - srcPath = fixVolumePathPrefix(srcPath) - - patterns, patDirs, exceptions, err := fileutils.CleanPatterns(options.ExcludePatterns) - - if err != nil { - return nil, err - } - - pipeReader, pipeWriter := io.Pipe() - - compressWriter, err := CompressStream(pipeWriter, options.Compression) - if err != nil { - return nil, err - } - - go func() { - ta := &tarAppender{ - TarWriter: tar.NewWriter(compressWriter), - Buffer: pools.BufioWriter32KPool.Get(nil), - SeenFiles: make(map[uint64]string), - UIDMaps: options.UIDMaps, - GIDMaps: options.GIDMaps, - WhiteoutConverter: getWhiteoutConverter(options.WhiteoutFormat), - } - - defer func() { - // Make sure to check the error on Close. - if err := ta.TarWriter.Close(); err != nil { - logrus.Errorf("Can't close tar writer: %s", err) - } - if err := compressWriter.Close(); err != nil { - logrus.Errorf("Can't close compress writer: %s", err) - } - if err := pipeWriter.Close(); err != nil { - logrus.Errorf("Can't close pipe writer: %s", err) - } - }() - - // this buffer is needed for the duration of this piped stream - defer pools.BufioWriter32KPool.Put(ta.Buffer) - - // In general we log errors here but ignore them because - // during e.g. a diff operation the container can continue - // mutating the filesystem and we can see transient errors - // from this - - stat, err := os.Lstat(srcPath) - if err != nil { - return - } - - if !stat.IsDir() { - // We can't later join a non-dir with any includes because the - // 'walk' will error if "file/." is stat-ed and "file" is not a - // directory. So, we must split the source path and use the - // basename as the include. - if len(options.IncludeFiles) > 0 { - logrus.Warn("Tar: Can't archive a file with includes") - } - - dir, base := SplitPathDirEntry(srcPath) - srcPath = dir - options.IncludeFiles = []string{base} - } - - if len(options.IncludeFiles) == 0 { - options.IncludeFiles = []string{"."} - } - - seen := make(map[string]bool) - - for _, include := range options.IncludeFiles { - rebaseName := options.RebaseNames[include] - - walkRoot := getWalkRoot(srcPath, include) - filepath.Walk(walkRoot, func(filePath string, f os.FileInfo, err error) error { - if err != nil { - logrus.Errorf("Tar: Can't stat file %s to tar: %s", srcPath, err) - return nil - } - - relFilePath, err := filepath.Rel(srcPath, filePath) - if err != nil || (!options.IncludeSourceDir && relFilePath == "." && f.IsDir()) { - // Error getting relative path OR we are looking - // at the source directory path. Skip in both situations. - return nil - } - - if options.IncludeSourceDir && include == "." && relFilePath != "." { - relFilePath = strings.Join([]string{".", relFilePath}, string(filepath.Separator)) - } - - skip := false - - // If "include" is an exact match for the current file - // then even if there's an "excludePatterns" pattern that - // matches it, don't skip it. IOW, assume an explicit 'include' - // is asking for that file no matter what - which is true - // for some files, like .dockerignore and Dockerfile (sometimes) - if include != relFilePath { - skip, err = fileutils.OptimizedMatches(relFilePath, patterns, patDirs) - if err != nil { - logrus.Errorf("Error matching %s: %v", relFilePath, err) - return err - } - } - - if skip { - // If we want to skip this file and its a directory - // then we should first check to see if there's an - // excludes pattern (eg !dir/file) that starts with this - // dir. If so then we can't skip this dir. - - // Its not a dir then so we can just return/skip. - if !f.IsDir() { - return nil - } - - // No exceptions (!...) in patterns so just skip dir - if !exceptions { - return filepath.SkipDir - } - - dirSlash := relFilePath + string(filepath.Separator) - - for _, pat := range patterns { - if pat[0] != '!' { - continue - } - pat = pat[1:] + string(filepath.Separator) - if strings.HasPrefix(pat, dirSlash) { - // found a match - so can't skip this dir - return nil - } - } - - // No matching exclusion dir so just skip dir - return filepath.SkipDir - } - - if seen[relFilePath] { - return nil - } - seen[relFilePath] = true - - // Rename the base resource. - if rebaseName != "" { - var replacement string - if rebaseName != string(filepath.Separator) { - // Special case the root directory to replace with an - // empty string instead so that we don't end up with - // double slashes in the paths. - replacement = rebaseName - } - - relFilePath = strings.Replace(relFilePath, include, replacement, 1) - } - - if err := ta.addTarFile(filePath, relFilePath); err != nil { - logrus.Errorf("Can't add file %s to tar: %s", filePath, err) - // if pipe is broken, stop writing tar stream to it - if err == io.ErrClosedPipe { - return err - } - } - return nil - }) - } - }() - - return pipeReader, nil -} - -// Unpack unpacks the decompressedArchive to dest with options. -func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) error { - tr := tar.NewReader(decompressedArchive) - trBuf := pools.BufioReader32KPool.Get(nil) - defer pools.BufioReader32KPool.Put(trBuf) - - var dirs []*tar.Header - remappedRootUID, remappedRootGID, err := idtools.GetRootUIDGID(options.UIDMaps, options.GIDMaps) - if err != nil { - return err - } - whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat) - - // Iterate through the files in the archive. -loop: - for { - hdr, err := tr.Next() - if err == io.EOF { - // end of tar archive - break - } - if err != nil { - return err - } - - // Normalize name, for safety and for a simple is-root check - // This keeps "../" as-is, but normalizes "/../" to "/". Or Windows: - // This keeps "..\" as-is, but normalizes "\..\" to "\". - hdr.Name = filepath.Clean(hdr.Name) - - for _, exclude := range options.ExcludePatterns { - if strings.HasPrefix(hdr.Name, exclude) { - continue loop - } - } - - // After calling filepath.Clean(hdr.Name) above, hdr.Name will now be in - // the filepath format for the OS on which the daemon is running. Hence - // the check for a slash-suffix MUST be done in an OS-agnostic way. - if !strings.HasSuffix(hdr.Name, string(os.PathSeparator)) { - // Not the root directory, ensure that the parent directory exists - parent := filepath.Dir(hdr.Name) - parentPath := filepath.Join(dest, parent) - if _, err := os.Lstat(parentPath); err != nil && os.IsNotExist(err) { - err = idtools.MkdirAllNewAs(parentPath, 0777, remappedRootUID, remappedRootGID) - if err != nil { - return err - } - } - } - - path := filepath.Join(dest, hdr.Name) - rel, err := filepath.Rel(dest, path) - if err != nil { - return err - } - if strings.HasPrefix(rel, ".."+string(os.PathSeparator)) { - return breakoutError(fmt.Errorf("%q is outside of %q", hdr.Name, dest)) - } - - // If path exits we almost always just want to remove and replace it - // The only exception is when it is a directory *and* the file from - // the layer is also a directory. Then we want to merge them (i.e. - // just apply the metadata from the layer). - if fi, err := os.Lstat(path); err == nil { - if options.NoOverwriteDirNonDir && fi.IsDir() && hdr.Typeflag != tar.TypeDir { - // If NoOverwriteDirNonDir is true then we cannot replace - // an existing directory with a non-directory from the archive. - return fmt.Errorf("cannot overwrite directory %q with non-directory %q", path, dest) - } - - if options.NoOverwriteDirNonDir && !fi.IsDir() && hdr.Typeflag == tar.TypeDir { - // If NoOverwriteDirNonDir is true then we cannot replace - // an existing non-directory with a directory from the archive. - return fmt.Errorf("cannot overwrite non-directory %q with directory %q", path, dest) - } - - if fi.IsDir() && hdr.Name == "." { - continue - } - - if !(fi.IsDir() && hdr.Typeflag == tar.TypeDir) { - if err := os.RemoveAll(path); err != nil { - return err - } - } - } - trBuf.Reset(tr) - - // if the options contain a uid & gid maps, convert header uid/gid - // entries using the maps such that lchown sets the proper mapped - // uid/gid after writing the file. We only perform this mapping if - // the file isn't already owned by the remapped root UID or GID, as - // that specific uid/gid has no mapping from container -> host, and - // those files already have the proper ownership for inside the - // container. - if hdr.Uid != remappedRootUID { - xUID, err := idtools.ToHost(hdr.Uid, options.UIDMaps) - if err != nil { - return err - } - hdr.Uid = xUID - } - if hdr.Gid != remappedRootGID { - xGID, err := idtools.ToHost(hdr.Gid, options.GIDMaps) - if err != nil { - return err - } - hdr.Gid = xGID - } - - if whiteoutConverter != nil { - writeFile, err := whiteoutConverter.ConvertRead(hdr, path) - if err != nil { - return err - } - if !writeFile { - continue - } - } - - if err := createTarFile(path, dest, hdr, trBuf, !options.NoLchown, options.ChownOpts, options.InUserNS); err != nil { - return err - } - - // Directory mtimes must be handled at the end to avoid further - // file creation in them to modify the directory mtime - if hdr.Typeflag == tar.TypeDir { - dirs = append(dirs, hdr) - } - } - - for _, hdr := range dirs { - path := filepath.Join(dest, hdr.Name) - - if err := system.Chtimes(path, hdr.AccessTime, hdr.ModTime); err != nil { - return err - } - } - return nil -} - -// Untar reads a stream of bytes from `archive`, parses it as a tar archive, -// and unpacks it into the directory at `dest`. -// The archive may be compressed with one of the following algorithms: -// identity (uncompressed), gzip, bzip2, xz. -// FIXME: specify behavior when target path exists vs. doesn't exist. -func Untar(tarArchive io.Reader, dest string, options *TarOptions) error { - return untarHandler(tarArchive, dest, options, true) -} - -// UntarUncompressed reads a stream of bytes from `archive`, parses it as a tar archive, -// and unpacks it into the directory at `dest`. -// The archive must be an uncompressed stream. -func UntarUncompressed(tarArchive io.Reader, dest string, options *TarOptions) error { - return untarHandler(tarArchive, dest, options, false) -} - -// Handler for teasing out the automatic decompression -func untarHandler(tarArchive io.Reader, dest string, options *TarOptions, decompress bool) error { - if tarArchive == nil { - return fmt.Errorf("Empty archive") - } - dest = filepath.Clean(dest) - if options == nil { - options = &TarOptions{} - } - if options.ExcludePatterns == nil { - options.ExcludePatterns = []string{} - } - - r := tarArchive - if decompress { - decompressedArchive, err := DecompressStream(tarArchive) - if err != nil { - return err - } - defer decompressedArchive.Close() - r = decompressedArchive - } - - return Unpack(r, dest, options) -} - -// TarUntar is a convenience function which calls Tar and Untar, with the output of one piped into the other. -// If either Tar or Untar fails, TarUntar aborts and returns the error. -func (archiver *Archiver) TarUntar(src, dst string) error { - logrus.Debugf("TarUntar(%s %s)", src, dst) - archive, err := TarWithOptions(src, &TarOptions{Compression: Uncompressed}) - if err != nil { - return err - } - defer archive.Close() - - var options *TarOptions - if archiver.UIDMaps != nil || archiver.GIDMaps != nil { - options = &TarOptions{ - UIDMaps: archiver.UIDMaps, - GIDMaps: archiver.GIDMaps, - } - } - return archiver.Untar(archive, dst, options) -} - -// TarUntar is a convenience function which calls Tar and Untar, with the output of one piped into the other. -// If either Tar or Untar fails, TarUntar aborts and returns the error. -func TarUntar(src, dst string) error { - return defaultArchiver.TarUntar(src, dst) -} - -// UntarPath untar a file from path to a destination, src is the source tar file path. -func (archiver *Archiver) UntarPath(src, dst string) error { - archive, err := os.Open(src) - if err != nil { - return err - } - defer archive.Close() - var options *TarOptions - if archiver.UIDMaps != nil || archiver.GIDMaps != nil { - options = &TarOptions{ - UIDMaps: archiver.UIDMaps, - GIDMaps: archiver.GIDMaps, - } - } - return archiver.Untar(archive, dst, options) -} - -// UntarPath is a convenience function which looks for an archive -// at filesystem path `src`, and unpacks it at `dst`. -func UntarPath(src, dst string) error { - return defaultArchiver.UntarPath(src, dst) -} - -// CopyWithTar creates a tar archive of filesystem path `src`, and -// unpacks it at filesystem path `dst`. -// The archive is streamed directly with fixed buffering and no -// intermediary disk IO. -func (archiver *Archiver) CopyWithTar(src, dst string) error { - srcSt, err := os.Stat(src) - if err != nil { - return err - } - if !srcSt.IsDir() { - return archiver.CopyFileWithTar(src, dst) - } - - // if this archiver is set up with ID mapping we need to create - // the new destination directory with the remapped root UID/GID pair - // as owner - rootUID, rootGID, err := idtools.GetRootUIDGID(archiver.UIDMaps, archiver.GIDMaps) - if err != nil { - return err - } - // Create dst, copy src's content into it - logrus.Debugf("Creating dest directory: %s", dst) - if err := idtools.MkdirAllNewAs(dst, 0755, rootUID, rootGID); err != nil { - return err - } - logrus.Debugf("Calling TarUntar(%s, %s)", src, dst) - return archiver.TarUntar(src, dst) -} - -// CopyWithTar creates a tar archive of filesystem path `src`, and -// unpacks it at filesystem path `dst`. -// The archive is streamed directly with fixed buffering and no -// intermediary disk IO. -func CopyWithTar(src, dst string) error { - return defaultArchiver.CopyWithTar(src, dst) -} - -// CopyFileWithTar emulates the behavior of the 'cp' command-line -// for a single file. It copies a regular file from path `src` to -// path `dst`, and preserves all its metadata. -func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) { - logrus.Debugf("CopyFileWithTar(%s, %s)", src, dst) - srcSt, err := os.Stat(src) - if err != nil { - return err - } - - if srcSt.IsDir() { - return fmt.Errorf("Can't copy a directory") - } - - // Clean up the trailing slash. This must be done in an operating - // system specific manner. - if dst[len(dst)-1] == os.PathSeparator { - dst = filepath.Join(dst, filepath.Base(src)) - } - // Create the holding directory if necessary - if err := system.MkdirAll(filepath.Dir(dst), 0700); err != nil { - return err - } - - r, w := io.Pipe() - errC := promise.Go(func() error { - defer w.Close() - - srcF, err := os.Open(src) - if err != nil { - return err - } - defer srcF.Close() - - hdr, err := tar.FileInfoHeader(srcSt, "") - if err != nil { - return err - } - hdr.Name = filepath.Base(dst) - hdr.Mode = int64(chmodTarEntry(os.FileMode(hdr.Mode))) - - remappedRootUID, remappedRootGID, err := idtools.GetRootUIDGID(archiver.UIDMaps, archiver.GIDMaps) - if err != nil { - return err - } - - // only perform mapping if the file being copied isn't already owned by the - // uid or gid of the remapped root in the container - if remappedRootUID != hdr.Uid { - xUID, err := idtools.ToHost(hdr.Uid, archiver.UIDMaps) - if err != nil { - return err - } - hdr.Uid = xUID - } - if remappedRootGID != hdr.Gid { - xGID, err := idtools.ToHost(hdr.Gid, archiver.GIDMaps) - if err != nil { - return err - } - hdr.Gid = xGID - } - - tw := tar.NewWriter(w) - defer tw.Close() - if err := tw.WriteHeader(hdr); err != nil { - return err - } - if _, err := io.Copy(tw, srcF); err != nil { - return err - } - return nil - }) - defer func() { - if er := <-errC; err == nil && er != nil { - err = er - } - }() - - err = archiver.Untar(r, filepath.Dir(dst), nil) - if err != nil { - r.CloseWithError(err) - } - return err -} - -// CopyFileWithTar emulates the behavior of the 'cp' command-line -// for a single file. It copies a regular file from path `src` to -// path `dst`, and preserves all its metadata. -// -// Destination handling is in an operating specific manner depending -// where the daemon is running. If `dst` ends with a trailing slash -// the final destination path will be `dst/base(src)` (Linux) or -// `dst\base(src)` (Windows). -func CopyFileWithTar(src, dst string) (err error) { - return defaultArchiver.CopyFileWithTar(src, dst) -} - -// cmdStream executes a command, and returns its stdout as a stream. -// If the command fails to run or doesn't complete successfully, an error -// will be returned, including anything written on stderr. -func cmdStream(cmd *exec.Cmd, input io.Reader) (io.ReadCloser, <-chan struct{}, error) { - chdone := make(chan struct{}) - cmd.Stdin = input - pipeR, pipeW := io.Pipe() - cmd.Stdout = pipeW - var errBuf bytes.Buffer - cmd.Stderr = &errBuf - - // Run the command and return the pipe - if err := cmd.Start(); err != nil { - return nil, nil, err - } - - // Copy stdout to the returned pipe - go func() { - if err := cmd.Wait(); err != nil { - pipeW.CloseWithError(fmt.Errorf("%s: %s", err, errBuf.String())) - } else { - pipeW.Close() - } - close(chdone) - }() - - return pipeR, chdone, nil -} - -// NewTempArchive reads the content of src into a temporary file, and returns the contents -// of that file as an archive. The archive can only be read once - as soon as reading completes, -// the file will be deleted. -func NewTempArchive(src io.Reader, dir string) (*TempArchive, error) { - f, err := ioutil.TempFile(dir, "") - if err != nil { - return nil, err - } - if _, err := io.Copy(f, src); err != nil { - return nil, err - } - if _, err := f.Seek(0, 0); err != nil { - return nil, err - } - st, err := f.Stat() - if err != nil { - return nil, err - } - size := st.Size() - return &TempArchive{File: f, Size: size}, nil -} - -// TempArchive is a temporary archive. The archive can only be read once - as soon as reading completes, -// the file will be deleted. -type TempArchive struct { - *os.File - Size int64 // Pre-computed from Stat().Size() as a convenience - read int64 - closed bool -} - -// Close closes the underlying file if it's still open, or does a no-op -// to allow callers to try to close the TempArchive multiple times safely. -func (archive *TempArchive) Close() error { - if archive.closed { - return nil - } - - archive.closed = true - - return archive.File.Close() -} - -func (archive *TempArchive) Read(data []byte) (int, error) { - n, err := archive.File.Read(data) - archive.read += int64(n) - if err != nil || archive.read == archive.Size { - archive.Close() - os.Remove(archive.File.Name()) - } - return n, err -} diff --git a/vendor/github.com/docker/docker/pkg/archive/archive_linux.go b/vendor/github.com/docker/docker/pkg/archive/archive_linux.go deleted file mode 100644 index 6b2a31f..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/archive_linux.go +++ /dev/null @@ -1,95 +0,0 @@ -package archive - -import ( - "archive/tar" - "os" - "path/filepath" - "strings" - "syscall" - - "github.com/docker/docker/pkg/system" -) - -func getWhiteoutConverter(format WhiteoutFormat) tarWhiteoutConverter { - if format == OverlayWhiteoutFormat { - return overlayWhiteoutConverter{} - } - return nil -} - -type overlayWhiteoutConverter struct{} - -func (overlayWhiteoutConverter) ConvertWrite(hdr *tar.Header, path string, fi os.FileInfo) (wo *tar.Header, err error) { - // convert whiteouts to AUFS format - if fi.Mode()&os.ModeCharDevice != 0 && hdr.Devmajor == 0 && hdr.Devminor == 0 { - // we just rename the file and make it normal - dir, filename := filepath.Split(hdr.Name) - hdr.Name = filepath.Join(dir, WhiteoutPrefix+filename) - hdr.Mode = 0600 - hdr.Typeflag = tar.TypeReg - hdr.Size = 0 - } - - if fi.Mode()&os.ModeDir != 0 { - // convert opaque dirs to AUFS format by writing an empty file with the prefix - opaque, err := system.Lgetxattr(path, "trusted.overlay.opaque") - if err != nil { - return nil, err - } - if len(opaque) == 1 && opaque[0] == 'y' { - if hdr.Xattrs != nil { - delete(hdr.Xattrs, "trusted.overlay.opaque") - } - - // create a header for the whiteout file - // it should inherit some properties from the parent, but be a regular file - wo = &tar.Header{ - Typeflag: tar.TypeReg, - Mode: hdr.Mode & int64(os.ModePerm), - Name: filepath.Join(hdr.Name, WhiteoutOpaqueDir), - Size: 0, - Uid: hdr.Uid, - Uname: hdr.Uname, - Gid: hdr.Gid, - Gname: hdr.Gname, - AccessTime: hdr.AccessTime, - ChangeTime: hdr.ChangeTime, - } - } - } - - return -} - -func (overlayWhiteoutConverter) ConvertRead(hdr *tar.Header, path string) (bool, error) { - base := filepath.Base(path) - dir := filepath.Dir(path) - - // if a directory is marked as opaque by the AUFS special file, we need to translate that to overlay - if base == WhiteoutOpaqueDir { - if err := syscall.Setxattr(dir, "trusted.overlay.opaque", []byte{'y'}, 0); err != nil { - return false, err - } - - // don't write the file itself - return false, nil - } - - // if a file was deleted and we are using overlay, we need to create a character device - if strings.HasPrefix(base, WhiteoutPrefix) { - originalBase := base[len(WhiteoutPrefix):] - originalPath := filepath.Join(dir, originalBase) - - if err := syscall.Mknod(originalPath, syscall.S_IFCHR, 0); err != nil { - return false, err - } - if err := os.Chown(originalPath, hdr.Uid, hdr.Gid); err != nil { - return false, err - } - - // don't write the file itself - return false, nil - } - - return true, nil -} diff --git a/vendor/github.com/docker/docker/pkg/archive/archive_linux_test.go b/vendor/github.com/docker/docker/pkg/archive/archive_linux_test.go deleted file mode 100644 index d5f046e..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/archive_linux_test.go +++ /dev/null @@ -1,187 +0,0 @@ -package archive - -import ( - "io/ioutil" - "os" - "path/filepath" - "syscall" - "testing" - - "github.com/docker/docker/pkg/system" -) - -// setupOverlayTestDir creates files in a directory with overlay whiteouts -// Tree layout -// . -// ├── d1 # opaque, 0700 -// │   └── f1 # empty file, 0600 -// ├── d2 # opaque, 0750 -// │   └── f1 # empty file, 0660 -// └── d3 # 0700 -// └── f1 # whiteout, 0644 -func setupOverlayTestDir(t *testing.T, src string) { - // Create opaque directory containing single file and permission 0700 - if err := os.Mkdir(filepath.Join(src, "d1"), 0700); err != nil { - t.Fatal(err) - } - - if err := system.Lsetxattr(filepath.Join(src, "d1"), "trusted.overlay.opaque", []byte("y"), 0); err != nil { - t.Fatal(err) - } - - if err := ioutil.WriteFile(filepath.Join(src, "d1", "f1"), []byte{}, 0600); err != nil { - t.Fatal(err) - } - - // Create another opaque directory containing single file but with permission 0750 - if err := os.Mkdir(filepath.Join(src, "d2"), 0750); err != nil { - t.Fatal(err) - } - - if err := system.Lsetxattr(filepath.Join(src, "d2"), "trusted.overlay.opaque", []byte("y"), 0); err != nil { - t.Fatal(err) - } - - if err := ioutil.WriteFile(filepath.Join(src, "d2", "f1"), []byte{}, 0660); err != nil { - t.Fatal(err) - } - - // Create regular directory with deleted file - if err := os.Mkdir(filepath.Join(src, "d3"), 0700); err != nil { - t.Fatal(err) - } - - if err := system.Mknod(filepath.Join(src, "d3", "f1"), syscall.S_IFCHR, 0); err != nil { - t.Fatal(err) - } -} - -func checkOpaqueness(t *testing.T, path string, opaque string) { - xattrOpaque, err := system.Lgetxattr(path, "trusted.overlay.opaque") - if err != nil { - t.Fatal(err) - } - if string(xattrOpaque) != opaque { - t.Fatalf("Unexpected opaque value: %q, expected %q", string(xattrOpaque), opaque) - } - -} - -func checkOverlayWhiteout(t *testing.T, path string) { - stat, err := os.Stat(path) - if err != nil { - t.Fatal(err) - } - statT, ok := stat.Sys().(*syscall.Stat_t) - if !ok { - t.Fatalf("Unexpected type: %t, expected *syscall.Stat_t", stat.Sys()) - } - if statT.Rdev != 0 { - t.Fatalf("Non-zero device number for whiteout") - } -} - -func checkFileMode(t *testing.T, path string, perm os.FileMode) { - stat, err := os.Stat(path) - if err != nil { - t.Fatal(err) - } - if stat.Mode() != perm { - t.Fatalf("Unexpected file mode for %s: %o, expected %o", path, stat.Mode(), perm) - } -} - -func TestOverlayTarUntar(t *testing.T) { - oldmask, err := system.Umask(0) - if err != nil { - t.Fatal(err) - } - defer system.Umask(oldmask) - - src, err := ioutil.TempDir("", "docker-test-overlay-tar-src") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(src) - - setupOverlayTestDir(t, src) - - dst, err := ioutil.TempDir("", "docker-test-overlay-tar-dst") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dst) - - options := &TarOptions{ - Compression: Uncompressed, - WhiteoutFormat: OverlayWhiteoutFormat, - } - archive, err := TarWithOptions(src, options) - if err != nil { - t.Fatal(err) - } - defer archive.Close() - - if err := Untar(archive, dst, options); err != nil { - t.Fatal(err) - } - - checkFileMode(t, filepath.Join(dst, "d1"), 0700|os.ModeDir) - checkFileMode(t, filepath.Join(dst, "d2"), 0750|os.ModeDir) - checkFileMode(t, filepath.Join(dst, "d3"), 0700|os.ModeDir) - checkFileMode(t, filepath.Join(dst, "d1", "f1"), 0600) - checkFileMode(t, filepath.Join(dst, "d2", "f1"), 0660) - checkFileMode(t, filepath.Join(dst, "d3", "f1"), os.ModeCharDevice|os.ModeDevice) - - checkOpaqueness(t, filepath.Join(dst, "d1"), "y") - checkOpaqueness(t, filepath.Join(dst, "d2"), "y") - checkOpaqueness(t, filepath.Join(dst, "d3"), "") - checkOverlayWhiteout(t, filepath.Join(dst, "d3", "f1")) -} - -func TestOverlayTarAUFSUntar(t *testing.T) { - oldmask, err := system.Umask(0) - if err != nil { - t.Fatal(err) - } - defer system.Umask(oldmask) - - src, err := ioutil.TempDir("", "docker-test-overlay-tar-src") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(src) - - setupOverlayTestDir(t, src) - - dst, err := ioutil.TempDir("", "docker-test-overlay-tar-dst") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dst) - - archive, err := TarWithOptions(src, &TarOptions{ - Compression: Uncompressed, - WhiteoutFormat: OverlayWhiteoutFormat, - }) - if err != nil { - t.Fatal(err) - } - defer archive.Close() - - if err := Untar(archive, dst, &TarOptions{ - Compression: Uncompressed, - WhiteoutFormat: AUFSWhiteoutFormat, - }); err != nil { - t.Fatal(err) - } - - checkFileMode(t, filepath.Join(dst, "d1"), 0700|os.ModeDir) - checkFileMode(t, filepath.Join(dst, "d1", WhiteoutOpaqueDir), 0700) - checkFileMode(t, filepath.Join(dst, "d2"), 0750|os.ModeDir) - checkFileMode(t, filepath.Join(dst, "d2", WhiteoutOpaqueDir), 0750) - checkFileMode(t, filepath.Join(dst, "d3"), 0700|os.ModeDir) - checkFileMode(t, filepath.Join(dst, "d1", "f1"), 0600) - checkFileMode(t, filepath.Join(dst, "d2", "f1"), 0660) - checkFileMode(t, filepath.Join(dst, "d3", WhiteoutPrefix+"f1"), 0600) -} diff --git a/vendor/github.com/docker/docker/pkg/archive/archive_other.go b/vendor/github.com/docker/docker/pkg/archive/archive_other.go deleted file mode 100644 index 54acbf2..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/archive_other.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build !linux - -package archive - -func getWhiteoutConverter(format WhiteoutFormat) tarWhiteoutConverter { - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/archive/archive_test.go b/vendor/github.com/docker/docker/pkg/archive/archive_test.go deleted file mode 100644 index b883be3..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/archive_test.go +++ /dev/null @@ -1,1162 +0,0 @@ -package archive - -import ( - "archive/tar" - "bytes" - "fmt" - "io" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "runtime" - "strings" - "testing" - "time" -) - -var tmp string - -func init() { - tmp = "/tmp/" - if runtime.GOOS == "windows" { - tmp = os.Getenv("TEMP") + `\` - } -} - -func TestIsArchiveNilHeader(t *testing.T) { - out := IsArchive(nil) - if out { - t.Fatalf("isArchive should return false as nil is not a valid archive header") - } -} - -func TestIsArchiveInvalidHeader(t *testing.T) { - header := []byte{0x00, 0x01, 0x02} - out := IsArchive(header) - if out { - t.Fatalf("isArchive should return false as %s is not a valid archive header", header) - } -} - -func TestIsArchiveBzip2(t *testing.T) { - header := []byte{0x42, 0x5A, 0x68} - out := IsArchive(header) - if !out { - t.Fatalf("isArchive should return true as %s is a bz2 header", header) - } -} - -func TestIsArchive7zip(t *testing.T) { - header := []byte{0x50, 0x4b, 0x03, 0x04} - out := IsArchive(header) - if out { - t.Fatalf("isArchive should return false as %s is a 7z header and it is not supported", header) - } -} - -func TestIsArchivePathDir(t *testing.T) { - cmd := exec.Command("sh", "-c", "mkdir -p /tmp/archivedir") - output, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("Fail to create an archive file for test : %s.", output) - } - if IsArchivePath(tmp + "archivedir") { - t.Fatalf("Incorrectly recognised directory as an archive") - } -} - -func TestIsArchivePathInvalidFile(t *testing.T) { - cmd := exec.Command("sh", "-c", "dd if=/dev/zero bs=1024 count=1 of=/tmp/archive && gzip --stdout /tmp/archive > /tmp/archive.gz") - output, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("Fail to create an archive file for test : %s.", output) - } - if IsArchivePath(tmp + "archive") { - t.Fatalf("Incorrectly recognised invalid tar path as archive") - } - if IsArchivePath(tmp + "archive.gz") { - t.Fatalf("Incorrectly recognised invalid compressed tar path as archive") - } -} - -func TestIsArchivePathTar(t *testing.T) { - var whichTar string - if runtime.GOOS == "solaris" { - whichTar = "gtar" - } else { - whichTar = "tar" - } - cmdStr := fmt.Sprintf("touch /tmp/archivedata && %s -cf /tmp/archive /tmp/archivedata && gzip --stdout /tmp/archive > /tmp/archive.gz", whichTar) - cmd := exec.Command("sh", "-c", cmdStr) - output, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("Fail to create an archive file for test : %s.", output) - } - if !IsArchivePath(tmp + "/archive") { - t.Fatalf("Did not recognise valid tar path as archive") - } - if !IsArchivePath(tmp + "archive.gz") { - t.Fatalf("Did not recognise valid compressed tar path as archive") - } -} - -func testDecompressStream(t *testing.T, ext, compressCommand string) { - cmd := exec.Command("sh", "-c", - fmt.Sprintf("touch /tmp/archive && %s /tmp/archive", compressCommand)) - output, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("Failed to create an archive file for test : %s.", output) - } - filename := "archive." + ext - archive, err := os.Open(tmp + filename) - if err != nil { - t.Fatalf("Failed to open file %s: %v", filename, err) - } - defer archive.Close() - - r, err := DecompressStream(archive) - if err != nil { - t.Fatalf("Failed to decompress %s: %v", filename, err) - } - if _, err = ioutil.ReadAll(r); err != nil { - t.Fatalf("Failed to read the decompressed stream: %v ", err) - } - if err = r.Close(); err != nil { - t.Fatalf("Failed to close the decompressed stream: %v ", err) - } -} - -func TestDecompressStreamGzip(t *testing.T) { - testDecompressStream(t, "gz", "gzip -f") -} - -func TestDecompressStreamBzip2(t *testing.T) { - testDecompressStream(t, "bz2", "bzip2 -f") -} - -func TestDecompressStreamXz(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Xz not present in msys2") - } - testDecompressStream(t, "xz", "xz -f") -} - -func TestCompressStreamXzUnsuported(t *testing.T) { - dest, err := os.Create(tmp + "dest") - if err != nil { - t.Fatalf("Fail to create the destination file") - } - defer dest.Close() - - _, err = CompressStream(dest, Xz) - if err == nil { - t.Fatalf("Should fail as xz is unsupported for compression format.") - } -} - -func TestCompressStreamBzip2Unsupported(t *testing.T) { - dest, err := os.Create(tmp + "dest") - if err != nil { - t.Fatalf("Fail to create the destination file") - } - defer dest.Close() - - _, err = CompressStream(dest, Xz) - if err == nil { - t.Fatalf("Should fail as xz is unsupported for compression format.") - } -} - -func TestCompressStreamInvalid(t *testing.T) { - dest, err := os.Create(tmp + "dest") - if err != nil { - t.Fatalf("Fail to create the destination file") - } - defer dest.Close() - - _, err = CompressStream(dest, -1) - if err == nil { - t.Fatalf("Should fail as xz is unsupported for compression format.") - } -} - -func TestExtensionInvalid(t *testing.T) { - compression := Compression(-1) - output := compression.Extension() - if output != "" { - t.Fatalf("The extension of an invalid compression should be an empty string.") - } -} - -func TestExtensionUncompressed(t *testing.T) { - compression := Uncompressed - output := compression.Extension() - if output != "tar" { - t.Fatalf("The extension of an uncompressed archive should be 'tar'.") - } -} -func TestExtensionBzip2(t *testing.T) { - compression := Bzip2 - output := compression.Extension() - if output != "tar.bz2" { - t.Fatalf("The extension of a bzip2 archive should be 'tar.bz2'") - } -} -func TestExtensionGzip(t *testing.T) { - compression := Gzip - output := compression.Extension() - if output != "tar.gz" { - t.Fatalf("The extension of a bzip2 archive should be 'tar.gz'") - } -} -func TestExtensionXz(t *testing.T) { - compression := Xz - output := compression.Extension() - if output != "tar.xz" { - t.Fatalf("The extension of a bzip2 archive should be 'tar.xz'") - } -} - -func TestCmdStreamLargeStderr(t *testing.T) { - cmd := exec.Command("sh", "-c", "dd if=/dev/zero bs=1k count=1000 of=/dev/stderr; echo hello") - out, _, err := cmdStream(cmd, nil) - if err != nil { - t.Fatalf("Failed to start command: %s", err) - } - errCh := make(chan error) - go func() { - _, err := io.Copy(ioutil.Discard, out) - errCh <- err - }() - select { - case err := <-errCh: - if err != nil { - t.Fatalf("Command should not have failed (err=%.100s...)", err) - } - case <-time.After(5 * time.Second): - t.Fatalf("Command did not complete in 5 seconds; probable deadlock") - } -} - -func TestCmdStreamBad(t *testing.T) { - // TODO Windows: Figure out why this is failing in CI but not locally - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows CI machines") - } - badCmd := exec.Command("sh", "-c", "echo hello; echo >&2 error couldn\\'t reverse the phase pulser; exit 1") - out, _, err := cmdStream(badCmd, nil) - if err != nil { - t.Fatalf("Failed to start command: %s", err) - } - if output, err := ioutil.ReadAll(out); err == nil { - t.Fatalf("Command should have failed") - } else if err.Error() != "exit status 1: error couldn't reverse the phase pulser\n" { - t.Fatalf("Wrong error value (%s)", err) - } else if s := string(output); s != "hello\n" { - t.Fatalf("Command output should be '%s', not '%s'", "hello\\n", output) - } -} - -func TestCmdStreamGood(t *testing.T) { - cmd := exec.Command("sh", "-c", "echo hello; exit 0") - out, _, err := cmdStream(cmd, nil) - if err != nil { - t.Fatal(err) - } - if output, err := ioutil.ReadAll(out); err != nil { - t.Fatalf("Command should not have failed (err=%s)", err) - } else if s := string(output); s != "hello\n" { - t.Fatalf("Command output should be '%s', not '%s'", "hello\\n", output) - } -} - -func TestUntarPathWithInvalidDest(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tempFolder) - invalidDestFolder := filepath.Join(tempFolder, "invalidDest") - // Create a src file - srcFile := filepath.Join(tempFolder, "src") - tarFile := filepath.Join(tempFolder, "src.tar") - os.Create(srcFile) - os.Create(invalidDestFolder) // being a file (not dir) should cause an error - - // Translate back to Unix semantics as next exec.Command is run under sh - srcFileU := srcFile - tarFileU := tarFile - if runtime.GOOS == "windows" { - tarFileU = "/tmp/" + filepath.Base(filepath.Dir(tarFile)) + "/src.tar" - srcFileU = "/tmp/" + filepath.Base(filepath.Dir(srcFile)) + "/src" - } - - cmd := exec.Command("sh", "-c", "tar cf "+tarFileU+" "+srcFileU) - _, err = cmd.CombinedOutput() - if err != nil { - t.Fatal(err) - } - - err = UntarPath(tarFile, invalidDestFolder) - if err == nil { - t.Fatalf("UntarPath with invalid destination path should throw an error.") - } -} - -func TestUntarPathWithInvalidSrc(t *testing.T) { - dest, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatalf("Fail to create the destination file") - } - defer os.RemoveAll(dest) - err = UntarPath("/invalid/path", dest) - if err == nil { - t.Fatalf("UntarPath with invalid src path should throw an error.") - } -} - -func TestUntarPath(t *testing.T) { - tmpFolder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpFolder) - srcFile := filepath.Join(tmpFolder, "src") - tarFile := filepath.Join(tmpFolder, "src.tar") - os.Create(filepath.Join(tmpFolder, "src")) - - destFolder := filepath.Join(tmpFolder, "dest") - err = os.MkdirAll(destFolder, 0740) - if err != nil { - t.Fatalf("Fail to create the destination file") - } - - // Translate back to Unix semantics as next exec.Command is run under sh - srcFileU := srcFile - tarFileU := tarFile - if runtime.GOOS == "windows" { - tarFileU = "/tmp/" + filepath.Base(filepath.Dir(tarFile)) + "/src.tar" - srcFileU = "/tmp/" + filepath.Base(filepath.Dir(srcFile)) + "/src" - } - cmd := exec.Command("sh", "-c", "tar cf "+tarFileU+" "+srcFileU) - _, err = cmd.CombinedOutput() - if err != nil { - t.Fatal(err) - } - - err = UntarPath(tarFile, destFolder) - if err != nil { - t.Fatalf("UntarPath shouldn't throw an error, %s.", err) - } - expectedFile := filepath.Join(destFolder, srcFileU) - _, err = os.Stat(expectedFile) - if err != nil { - t.Fatalf("Destination folder should contain the source file but did not.") - } -} - -// Do the same test as above but with the destination as file, it should fail -func TestUntarPathWithDestinationFile(t *testing.T) { - tmpFolder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpFolder) - srcFile := filepath.Join(tmpFolder, "src") - tarFile := filepath.Join(tmpFolder, "src.tar") - os.Create(filepath.Join(tmpFolder, "src")) - - // Translate back to Unix semantics as next exec.Command is run under sh - srcFileU := srcFile - tarFileU := tarFile - if runtime.GOOS == "windows" { - tarFileU = "/tmp/" + filepath.Base(filepath.Dir(tarFile)) + "/src.tar" - srcFileU = "/tmp/" + filepath.Base(filepath.Dir(srcFile)) + "/src" - } - cmd := exec.Command("sh", "-c", "tar cf "+tarFileU+" "+srcFileU) - _, err = cmd.CombinedOutput() - if err != nil { - t.Fatal(err) - } - destFile := filepath.Join(tmpFolder, "dest") - _, err = os.Create(destFile) - if err != nil { - t.Fatalf("Fail to create the destination file") - } - err = UntarPath(tarFile, destFile) - if err == nil { - t.Fatalf("UntarPath should throw an error if the destination if a file") - } -} - -// Do the same test as above but with the destination folder already exists -// and the destination file is a directory -// It's working, see https://github.com/docker/docker/issues/10040 -func TestUntarPathWithDestinationSrcFileAsFolder(t *testing.T) { - tmpFolder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpFolder) - srcFile := filepath.Join(tmpFolder, "src") - tarFile := filepath.Join(tmpFolder, "src.tar") - os.Create(srcFile) - - // Translate back to Unix semantics as next exec.Command is run under sh - srcFileU := srcFile - tarFileU := tarFile - if runtime.GOOS == "windows" { - tarFileU = "/tmp/" + filepath.Base(filepath.Dir(tarFile)) + "/src.tar" - srcFileU = "/tmp/" + filepath.Base(filepath.Dir(srcFile)) + "/src" - } - - cmd := exec.Command("sh", "-c", "tar cf "+tarFileU+" "+srcFileU) - _, err = cmd.CombinedOutput() - if err != nil { - t.Fatal(err) - } - destFolder := filepath.Join(tmpFolder, "dest") - err = os.MkdirAll(destFolder, 0740) - if err != nil { - t.Fatalf("Fail to create the destination folder") - } - // Let's create a folder that will has the same path as the extracted file (from tar) - destSrcFileAsFolder := filepath.Join(destFolder, srcFileU) - err = os.MkdirAll(destSrcFileAsFolder, 0740) - if err != nil { - t.Fatal(err) - } - err = UntarPath(tarFile, destFolder) - if err != nil { - t.Fatalf("UntarPath should throw not throw an error if the extracted file already exists and is a folder") - } -} - -func TestCopyWithTarInvalidSrc(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(nil) - } - destFolder := filepath.Join(tempFolder, "dest") - invalidSrc := filepath.Join(tempFolder, "doesnotexists") - err = os.MkdirAll(destFolder, 0740) - if err != nil { - t.Fatal(err) - } - err = CopyWithTar(invalidSrc, destFolder) - if err == nil { - t.Fatalf("archiver.CopyWithTar with invalid src path should throw an error.") - } -} - -func TestCopyWithTarInexistentDestWillCreateIt(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(nil) - } - srcFolder := filepath.Join(tempFolder, "src") - inexistentDestFolder := filepath.Join(tempFolder, "doesnotexists") - err = os.MkdirAll(srcFolder, 0740) - if err != nil { - t.Fatal(err) - } - err = CopyWithTar(srcFolder, inexistentDestFolder) - if err != nil { - t.Fatalf("CopyWithTar with an inexistent folder shouldn't fail.") - } - _, err = os.Stat(inexistentDestFolder) - if err != nil { - t.Fatalf("CopyWithTar with an inexistent folder should create it.") - } -} - -// Test CopyWithTar with a file as src -func TestCopyWithTarSrcFile(t *testing.T) { - folder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(folder) - dest := filepath.Join(folder, "dest") - srcFolder := filepath.Join(folder, "src") - src := filepath.Join(folder, filepath.Join("src", "src")) - err = os.MkdirAll(srcFolder, 0740) - if err != nil { - t.Fatal(err) - } - err = os.MkdirAll(dest, 0740) - if err != nil { - t.Fatal(err) - } - ioutil.WriteFile(src, []byte("content"), 0777) - err = CopyWithTar(src, dest) - if err != nil { - t.Fatalf("archiver.CopyWithTar shouldn't throw an error, %s.", err) - } - _, err = os.Stat(dest) - // FIXME Check the content - if err != nil { - t.Fatalf("Destination file should be the same as the source.") - } -} - -// Test CopyWithTar with a folder as src -func TestCopyWithTarSrcFolder(t *testing.T) { - folder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(folder) - dest := filepath.Join(folder, "dest") - src := filepath.Join(folder, filepath.Join("src", "folder")) - err = os.MkdirAll(src, 0740) - if err != nil { - t.Fatal(err) - } - err = os.MkdirAll(dest, 0740) - if err != nil { - t.Fatal(err) - } - ioutil.WriteFile(filepath.Join(src, "file"), []byte("content"), 0777) - err = CopyWithTar(src, dest) - if err != nil { - t.Fatalf("archiver.CopyWithTar shouldn't throw an error, %s.", err) - } - _, err = os.Stat(dest) - // FIXME Check the content (the file inside) - if err != nil { - t.Fatalf("Destination folder should contain the source file but did not.") - } -} - -func TestCopyFileWithTarInvalidSrc(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tempFolder) - destFolder := filepath.Join(tempFolder, "dest") - err = os.MkdirAll(destFolder, 0740) - if err != nil { - t.Fatal(err) - } - invalidFile := filepath.Join(tempFolder, "doesnotexists") - err = CopyFileWithTar(invalidFile, destFolder) - if err == nil { - t.Fatalf("archiver.CopyWithTar with invalid src path should throw an error.") - } -} - -func TestCopyFileWithTarInexistentDestWillCreateIt(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(nil) - } - defer os.RemoveAll(tempFolder) - srcFile := filepath.Join(tempFolder, "src") - inexistentDestFolder := filepath.Join(tempFolder, "doesnotexists") - _, err = os.Create(srcFile) - if err != nil { - t.Fatal(err) - } - err = CopyFileWithTar(srcFile, inexistentDestFolder) - if err != nil { - t.Fatalf("CopyWithTar with an inexistent folder shouldn't fail.") - } - _, err = os.Stat(inexistentDestFolder) - if err != nil { - t.Fatalf("CopyWithTar with an inexistent folder should create it.") - } - // FIXME Test the src file and content -} - -func TestCopyFileWithTarSrcFolder(t *testing.T) { - folder, err := ioutil.TempDir("", "docker-archive-copyfilewithtar-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(folder) - dest := filepath.Join(folder, "dest") - src := filepath.Join(folder, "srcfolder") - err = os.MkdirAll(src, 0740) - if err != nil { - t.Fatal(err) - } - err = os.MkdirAll(dest, 0740) - if err != nil { - t.Fatal(err) - } - err = CopyFileWithTar(src, dest) - if err == nil { - t.Fatalf("CopyFileWithTar should throw an error with a folder.") - } -} - -func TestCopyFileWithTarSrcFile(t *testing.T) { - folder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(folder) - dest := filepath.Join(folder, "dest") - srcFolder := filepath.Join(folder, "src") - src := filepath.Join(folder, filepath.Join("src", "src")) - err = os.MkdirAll(srcFolder, 0740) - if err != nil { - t.Fatal(err) - } - err = os.MkdirAll(dest, 0740) - if err != nil { - t.Fatal(err) - } - ioutil.WriteFile(src, []byte("content"), 0777) - err = CopyWithTar(src, dest+"/") - if err != nil { - t.Fatalf("archiver.CopyFileWithTar shouldn't throw an error, %s.", err) - } - _, err = os.Stat(dest) - if err != nil { - t.Fatalf("Destination folder should contain the source file but did not.") - } -} - -func TestTarFiles(t *testing.T) { - // TODO Windows: Figure out how to port this test. - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - // try without hardlinks - if err := checkNoChanges(1000, false); err != nil { - t.Fatal(err) - } - // try with hardlinks - if err := checkNoChanges(1000, true); err != nil { - t.Fatal(err) - } -} - -func checkNoChanges(fileNum int, hardlinks bool) error { - srcDir, err := ioutil.TempDir("", "docker-test-srcDir") - if err != nil { - return err - } - defer os.RemoveAll(srcDir) - - destDir, err := ioutil.TempDir("", "docker-test-destDir") - if err != nil { - return err - } - defer os.RemoveAll(destDir) - - _, err = prepareUntarSourceDirectory(fileNum, srcDir, hardlinks) - if err != nil { - return err - } - - err = TarUntar(srcDir, destDir) - if err != nil { - return err - } - - changes, err := ChangesDirs(destDir, srcDir) - if err != nil { - return err - } - if len(changes) > 0 { - return fmt.Errorf("with %d files and %v hardlinks: expected 0 changes, got %d", fileNum, hardlinks, len(changes)) - } - return nil -} - -func tarUntar(t *testing.T, origin string, options *TarOptions) ([]Change, error) { - archive, err := TarWithOptions(origin, options) - if err != nil { - t.Fatal(err) - } - defer archive.Close() - - buf := make([]byte, 10) - if _, err := archive.Read(buf); err != nil { - return nil, err - } - wrap := io.MultiReader(bytes.NewReader(buf), archive) - - detectedCompression := DetectCompression(buf) - compression := options.Compression - if detectedCompression.Extension() != compression.Extension() { - return nil, fmt.Errorf("Wrong compression detected. Actual compression: %s, found %s", compression.Extension(), detectedCompression.Extension()) - } - - tmp, err := ioutil.TempDir("", "docker-test-untar") - if err != nil { - return nil, err - } - defer os.RemoveAll(tmp) - if err := Untar(wrap, tmp, nil); err != nil { - return nil, err - } - if _, err := os.Stat(tmp); err != nil { - return nil, err - } - - return ChangesDirs(origin, tmp) -} - -func TestTarUntar(t *testing.T) { - // TODO Windows: Figure out how to fix this test. - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - origin, err := ioutil.TempDir("", "docker-test-untar-origin") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(origin) - if err := ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(origin, "2"), []byte("welcome!"), 0700); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(origin, "3"), []byte("will be ignored"), 0700); err != nil { - t.Fatal(err) - } - - for _, c := range []Compression{ - Uncompressed, - Gzip, - } { - changes, err := tarUntar(t, origin, &TarOptions{ - Compression: c, - ExcludePatterns: []string{"3"}, - }) - - if err != nil { - t.Fatalf("Error tar/untar for compression %s: %s", c.Extension(), err) - } - - if len(changes) != 1 || changes[0].Path != "/3" { - t.Fatalf("Unexpected differences after tarUntar: %v", changes) - } - } -} - -func TestTarWithOptions(t *testing.T) { - // TODO Windows: Figure out how to fix this test. - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - origin, err := ioutil.TempDir("", "docker-test-untar-origin") - if err != nil { - t.Fatal(err) - } - if _, err := ioutil.TempDir(origin, "folder"); err != nil { - t.Fatal(err) - } - defer os.RemoveAll(origin) - if err := ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(origin, "2"), []byte("welcome!"), 0700); err != nil { - t.Fatal(err) - } - - cases := []struct { - opts *TarOptions - numChanges int - }{ - {&TarOptions{IncludeFiles: []string{"1"}}, 2}, - {&TarOptions{ExcludePatterns: []string{"2"}}, 1}, - {&TarOptions{ExcludePatterns: []string{"1", "folder*"}}, 2}, - {&TarOptions{IncludeFiles: []string{"1", "1"}}, 2}, - {&TarOptions{IncludeFiles: []string{"1"}, RebaseNames: map[string]string{"1": "test"}}, 4}, - } - for _, testCase := range cases { - changes, err := tarUntar(t, origin, testCase.opts) - if err != nil { - t.Fatalf("Error tar/untar when testing inclusion/exclusion: %s", err) - } - if len(changes) != testCase.numChanges { - t.Errorf("Expected %d changes, got %d for %+v:", - testCase.numChanges, len(changes), testCase.opts) - } - } -} - -// Some tar archives such as http://haproxy.1wt.eu/download/1.5/src/devel/haproxy-1.5-dev21.tar.gz -// use PAX Global Extended Headers. -// Failing prevents the archives from being uncompressed during ADD -func TestTypeXGlobalHeaderDoesNotFail(t *testing.T) { - hdr := tar.Header{Typeflag: tar.TypeXGlobalHeader} - tmpDir, err := ioutil.TempDir("", "docker-test-archive-pax-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpDir) - err = createTarFile(filepath.Join(tmpDir, "pax_global_header"), tmpDir, &hdr, nil, true, nil, false) - if err != nil { - t.Fatal(err) - } -} - -// Some tar have both GNU specific (huge uid) and Ustar specific (long name) things. -// Not supposed to happen (should use PAX instead of Ustar for long name) but it does and it should still work. -func TestUntarUstarGnuConflict(t *testing.T) { - f, err := os.Open("testdata/broken.tar") - if err != nil { - t.Fatal(err) - } - defer f.Close() - - found := false - tr := tar.NewReader(f) - // Iterate through the files in the archive. - for { - hdr, err := tr.Next() - if err == io.EOF { - // end of tar archive - break - } - if err != nil { - t.Fatal(err) - } - if hdr.Name == "root/.cpanm/work/1395823785.24209/Plack-1.0030/blib/man3/Plack::Middleware::LighttpdScriptNameFix.3pm" { - found = true - break - } - } - if !found { - t.Fatalf("%s not found in the archive", "root/.cpanm/work/1395823785.24209/Plack-1.0030/blib/man3/Plack::Middleware::LighttpdScriptNameFix.3pm") - } -} - -func prepareUntarSourceDirectory(numberOfFiles int, targetPath string, makeLinks bool) (int, error) { - fileData := []byte("fooo") - for n := 0; n < numberOfFiles; n++ { - fileName := fmt.Sprintf("file-%d", n) - if err := ioutil.WriteFile(filepath.Join(targetPath, fileName), fileData, 0700); err != nil { - return 0, err - } - if makeLinks { - if err := os.Link(filepath.Join(targetPath, fileName), filepath.Join(targetPath, fileName+"-link")); err != nil { - return 0, err - } - } - } - totalSize := numberOfFiles * len(fileData) - return totalSize, nil -} - -func BenchmarkTarUntar(b *testing.B) { - origin, err := ioutil.TempDir("", "docker-test-untar-origin") - if err != nil { - b.Fatal(err) - } - tempDir, err := ioutil.TempDir("", "docker-test-untar-destination") - if err != nil { - b.Fatal(err) - } - target := filepath.Join(tempDir, "dest") - n, err := prepareUntarSourceDirectory(100, origin, false) - if err != nil { - b.Fatal(err) - } - defer os.RemoveAll(origin) - defer os.RemoveAll(tempDir) - - b.ResetTimer() - b.SetBytes(int64(n)) - for n := 0; n < b.N; n++ { - err := TarUntar(origin, target) - if err != nil { - b.Fatal(err) - } - os.RemoveAll(target) - } -} - -func BenchmarkTarUntarWithLinks(b *testing.B) { - origin, err := ioutil.TempDir("", "docker-test-untar-origin") - if err != nil { - b.Fatal(err) - } - tempDir, err := ioutil.TempDir("", "docker-test-untar-destination") - if err != nil { - b.Fatal(err) - } - target := filepath.Join(tempDir, "dest") - n, err := prepareUntarSourceDirectory(100, origin, true) - if err != nil { - b.Fatal(err) - } - defer os.RemoveAll(origin) - defer os.RemoveAll(tempDir) - - b.ResetTimer() - b.SetBytes(int64(n)) - for n := 0; n < b.N; n++ { - err := TarUntar(origin, target) - if err != nil { - b.Fatal(err) - } - os.RemoveAll(target) - } -} - -func TestUntarInvalidFilenames(t *testing.T) { - // TODO Windows: Figure out how to fix this test. - if runtime.GOOS == "windows" { - t.Skip("Passes but hits breakoutError: platform and architecture is not supported") - } - for i, headers := range [][]*tar.Header{ - { - { - Name: "../victim/dotdot", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - { - { - // Note the leading slash - Name: "/../victim/slash-dotdot", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - } { - if err := testBreakout("untar", "docker-TestUntarInvalidFilenames", headers); err != nil { - t.Fatalf("i=%d. %v", i, err) - } - } -} - -func TestUntarHardlinkToSymlink(t *testing.T) { - // TODO Windows. There may be a way of running this, but turning off for now - if runtime.GOOS == "windows" { - t.Skip("hardlinks on Windows") - } - for i, headers := range [][]*tar.Header{ - { - { - Name: "symlink1", - Typeflag: tar.TypeSymlink, - Linkname: "regfile", - Mode: 0644, - }, - { - Name: "symlink2", - Typeflag: tar.TypeLink, - Linkname: "symlink1", - Mode: 0644, - }, - { - Name: "regfile", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - } { - if err := testBreakout("untar", "docker-TestUntarHardlinkToSymlink", headers); err != nil { - t.Fatalf("i=%d. %v", i, err) - } - } -} - -func TestUntarInvalidHardlink(t *testing.T) { - // TODO Windows. There may be a way of running this, but turning off for now - if runtime.GOOS == "windows" { - t.Skip("hardlinks on Windows") - } - for i, headers := range [][]*tar.Header{ - { // try reading victim/hello (../) - { - Name: "dotdot", - Typeflag: tar.TypeLink, - Linkname: "../victim/hello", - Mode: 0644, - }, - }, - { // try reading victim/hello (/../) - { - Name: "slash-dotdot", - Typeflag: tar.TypeLink, - // Note the leading slash - Linkname: "/../victim/hello", - Mode: 0644, - }, - }, - { // try writing victim/file - { - Name: "loophole-victim", - Typeflag: tar.TypeLink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "loophole-victim/file", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - { // try reading victim/hello (hardlink, symlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeLink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "symlink", - Typeflag: tar.TypeSymlink, - Linkname: "loophole-victim/hello", - Mode: 0644, - }, - }, - { // Try reading victim/hello (hardlink, hardlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeLink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "hardlink", - Typeflag: tar.TypeLink, - Linkname: "loophole-victim/hello", - Mode: 0644, - }, - }, - { // Try removing victim directory (hardlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeLink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "loophole-victim", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - } { - if err := testBreakout("untar", "docker-TestUntarInvalidHardlink", headers); err != nil { - t.Fatalf("i=%d. %v", i, err) - } - } -} - -func TestUntarInvalidSymlink(t *testing.T) { - // TODO Windows. There may be a way of running this, but turning off for now - if runtime.GOOS == "windows" { - t.Skip("hardlinks on Windows") - } - for i, headers := range [][]*tar.Header{ - { // try reading victim/hello (../) - { - Name: "dotdot", - Typeflag: tar.TypeSymlink, - Linkname: "../victim/hello", - Mode: 0644, - }, - }, - { // try reading victim/hello (/../) - { - Name: "slash-dotdot", - Typeflag: tar.TypeSymlink, - // Note the leading slash - Linkname: "/../victim/hello", - Mode: 0644, - }, - }, - { // try writing victim/file - { - Name: "loophole-victim", - Typeflag: tar.TypeSymlink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "loophole-victim/file", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - { // try reading victim/hello (symlink, symlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeSymlink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "symlink", - Typeflag: tar.TypeSymlink, - Linkname: "loophole-victim/hello", - Mode: 0644, - }, - }, - { // try reading victim/hello (symlink, hardlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeSymlink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "hardlink", - Typeflag: tar.TypeLink, - Linkname: "loophole-victim/hello", - Mode: 0644, - }, - }, - { // try removing victim directory (symlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeSymlink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "loophole-victim", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - { // try writing to victim/newdir/newfile with a symlink in the path - { - // this header needs to be before the next one, or else there is an error - Name: "dir/loophole", - Typeflag: tar.TypeSymlink, - Linkname: "../../victim", - Mode: 0755, - }, - { - Name: "dir/loophole/newdir/newfile", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - } { - if err := testBreakout("untar", "docker-TestUntarInvalidSymlink", headers); err != nil { - t.Fatalf("i=%d. %v", i, err) - } - } -} - -func TestTempArchiveCloseMultipleTimes(t *testing.T) { - reader := ioutil.NopCloser(strings.NewReader("hello")) - tempArchive, err := NewTempArchive(reader, "") - buf := make([]byte, 10) - n, err := tempArchive.Read(buf) - if n != 5 { - t.Fatalf("Expected to read 5 bytes. Read %d instead", n) - } - for i := 0; i < 3; i++ { - if err = tempArchive.Close(); err != nil { - t.Fatalf("i=%d. Unexpected error closing temp archive: %v", i, err) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/archive/archive_unix.go b/vendor/github.com/docker/docker/pkg/archive/archive_unix.go deleted file mode 100644 index 7083f2f..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/archive_unix.go +++ /dev/null @@ -1,118 +0,0 @@ -// +build !windows - -package archive - -import ( - "archive/tar" - "errors" - "os" - "path/filepath" - "syscall" - - "github.com/docker/docker/pkg/system" - rsystem "github.com/opencontainers/runc/libcontainer/system" -) - -// fixVolumePathPrefix does platform specific processing to ensure that if -// the path being passed in is not in a volume path format, convert it to one. -func fixVolumePathPrefix(srcPath string) string { - return srcPath -} - -// getWalkRoot calculates the root path when performing a TarWithOptions. -// We use a separate function as this is platform specific. On Linux, we -// can't use filepath.Join(srcPath,include) because this will clean away -// a trailing "." or "/" which may be important. -func getWalkRoot(srcPath string, include string) string { - return srcPath + string(filepath.Separator) + include -} - -// CanonicalTarNameForPath returns platform-specific filepath -// to canonical posix-style path for tar archival. p is relative -// path. -func CanonicalTarNameForPath(p string) (string, error) { - return p, nil // already unix-style -} - -// chmodTarEntry is used to adjust the file permissions used in tar header based -// on the platform the archival is done. - -func chmodTarEntry(perm os.FileMode) os.FileMode { - return perm // noop for unix as golang APIs provide perm bits correctly -} - -func setHeaderForSpecialDevice(hdr *tar.Header, ta *tarAppender, name string, stat interface{}) (inode uint64, err error) { - s, ok := stat.(*syscall.Stat_t) - - if !ok { - err = errors.New("cannot convert stat value to syscall.Stat_t") - return - } - - inode = uint64(s.Ino) - - // Currently go does not fill in the major/minors - if s.Mode&syscall.S_IFBLK != 0 || - s.Mode&syscall.S_IFCHR != 0 { - hdr.Devmajor = int64(major(uint64(s.Rdev))) - hdr.Devminor = int64(minor(uint64(s.Rdev))) - } - - return -} - -func getFileUIDGID(stat interface{}) (int, int, error) { - s, ok := stat.(*syscall.Stat_t) - - if !ok { - return -1, -1, errors.New("cannot convert stat value to syscall.Stat_t") - } - return int(s.Uid), int(s.Gid), nil -} - -func major(device uint64) uint64 { - return (device >> 8) & 0xfff -} - -func minor(device uint64) uint64 { - return (device & 0xff) | ((device >> 12) & 0xfff00) -} - -// handleTarTypeBlockCharFifo is an OS-specific helper function used by -// createTarFile to handle the following types of header: Block; Char; Fifo -func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error { - if rsystem.RunningInUserNS() { - // cannot create a device if running in user namespace - return nil - } - - mode := uint32(hdr.Mode & 07777) - switch hdr.Typeflag { - case tar.TypeBlock: - mode |= syscall.S_IFBLK - case tar.TypeChar: - mode |= syscall.S_IFCHR - case tar.TypeFifo: - mode |= syscall.S_IFIFO - } - - if err := system.Mknod(path, mode, int(system.Mkdev(hdr.Devmajor, hdr.Devminor))); err != nil { - return err - } - return nil -} - -func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error { - if hdr.Typeflag == tar.TypeLink { - if fi, err := os.Lstat(hdr.Linkname); err == nil && (fi.Mode()&os.ModeSymlink == 0) { - if err := os.Chmod(path, hdrInfo.Mode()); err != nil { - return err - } - } - } else if hdr.Typeflag != tar.TypeSymlink { - if err := os.Chmod(path, hdrInfo.Mode()); err != nil { - return err - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/archive/archive_unix_test.go b/vendor/github.com/docker/docker/pkg/archive/archive_unix_test.go deleted file mode 100644 index 4eeafdd..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/archive_unix_test.go +++ /dev/null @@ -1,249 +0,0 @@ -// +build !windows - -package archive - -import ( - "bytes" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "runtime" - "syscall" - "testing" - - "github.com/docker/docker/pkg/system" -) - -func TestCanonicalTarNameForPath(t *testing.T) { - cases := []struct{ in, expected string }{ - {"foo", "foo"}, - {"foo/bar", "foo/bar"}, - {"foo/dir/", "foo/dir/"}, - } - for _, v := range cases { - if out, err := CanonicalTarNameForPath(v.in); err != nil { - t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err) - } else if out != v.expected { - t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out) - } - } -} - -func TestCanonicalTarName(t *testing.T) { - cases := []struct { - in string - isDir bool - expected string - }{ - {"foo", false, "foo"}, - {"foo", true, "foo/"}, - {"foo/bar", false, "foo/bar"}, - {"foo/bar", true, "foo/bar/"}, - } - for _, v := range cases { - if out, err := canonicalTarName(v.in, v.isDir); err != nil { - t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err) - } else if out != v.expected { - t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out) - } - } -} - -func TestChmodTarEntry(t *testing.T) { - cases := []struct { - in, expected os.FileMode - }{ - {0000, 0000}, - {0777, 0777}, - {0644, 0644}, - {0755, 0755}, - {0444, 0444}, - } - for _, v := range cases { - if out := chmodTarEntry(v.in); out != v.expected { - t.Fatalf("wrong chmod. expected:%v got:%v", v.expected, out) - } - } -} - -func TestTarWithHardLink(t *testing.T) { - origin, err := ioutil.TempDir("", "docker-test-tar-hardlink") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(origin) - if err := ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700); err != nil { - t.Fatal(err) - } - if err := os.Link(filepath.Join(origin, "1"), filepath.Join(origin, "2")); err != nil { - t.Fatal(err) - } - - var i1, i2 uint64 - if i1, err = getNlink(filepath.Join(origin, "1")); err != nil { - t.Fatal(err) - } - // sanity check that we can hardlink - if i1 != 2 { - t.Skipf("skipping since hardlinks don't work here; expected 2 links, got %d", i1) - } - - dest, err := ioutil.TempDir("", "docker-test-tar-hardlink-dest") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dest) - - // we'll do this in two steps to separate failure - fh, err := Tar(origin, Uncompressed) - if err != nil { - t.Fatal(err) - } - - // ensure we can read the whole thing with no error, before writing back out - buf, err := ioutil.ReadAll(fh) - if err != nil { - t.Fatal(err) - } - - bRdr := bytes.NewReader(buf) - err = Untar(bRdr, dest, &TarOptions{Compression: Uncompressed}) - if err != nil { - t.Fatal(err) - } - - if i1, err = getInode(filepath.Join(dest, "1")); err != nil { - t.Fatal(err) - } - if i2, err = getInode(filepath.Join(dest, "2")); err != nil { - t.Fatal(err) - } - - if i1 != i2 { - t.Errorf("expected matching inodes, but got %d and %d", i1, i2) - } -} - -func getNlink(path string) (uint64, error) { - stat, err := os.Stat(path) - if err != nil { - return 0, err - } - statT, ok := stat.Sys().(*syscall.Stat_t) - if !ok { - return 0, fmt.Errorf("expected type *syscall.Stat_t, got %t", stat.Sys()) - } - // We need this conversion on ARM64 - return uint64(statT.Nlink), nil -} - -func getInode(path string) (uint64, error) { - stat, err := os.Stat(path) - if err != nil { - return 0, err - } - statT, ok := stat.Sys().(*syscall.Stat_t) - if !ok { - return 0, fmt.Errorf("expected type *syscall.Stat_t, got %t", stat.Sys()) - } - return statT.Ino, nil -} - -func TestTarWithBlockCharFifo(t *testing.T) { - origin, err := ioutil.TempDir("", "docker-test-tar-hardlink") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(origin) - if err := ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700); err != nil { - t.Fatal(err) - } - if err := system.Mknod(filepath.Join(origin, "2"), syscall.S_IFBLK, int(system.Mkdev(int64(12), int64(5)))); err != nil { - t.Fatal(err) - } - if err := system.Mknod(filepath.Join(origin, "3"), syscall.S_IFCHR, int(system.Mkdev(int64(12), int64(5)))); err != nil { - t.Fatal(err) - } - if err := system.Mknod(filepath.Join(origin, "4"), syscall.S_IFIFO, int(system.Mkdev(int64(12), int64(5)))); err != nil { - t.Fatal(err) - } - - dest, err := ioutil.TempDir("", "docker-test-tar-hardlink-dest") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dest) - - // we'll do this in two steps to separate failure - fh, err := Tar(origin, Uncompressed) - if err != nil { - t.Fatal(err) - } - - // ensure we can read the whole thing with no error, before writing back out - buf, err := ioutil.ReadAll(fh) - if err != nil { - t.Fatal(err) - } - - bRdr := bytes.NewReader(buf) - err = Untar(bRdr, dest, &TarOptions{Compression: Uncompressed}) - if err != nil { - t.Fatal(err) - } - - changes, err := ChangesDirs(origin, dest) - if err != nil { - t.Fatal(err) - } - if len(changes) > 0 { - t.Fatalf("Tar with special device (block, char, fifo) should keep them (recreate them when untar) : %v", changes) - } -} - -// TestTarUntarWithXattr is Unix as Lsetxattr is not supported on Windows -func TestTarUntarWithXattr(t *testing.T) { - if runtime.GOOS == "solaris" { - t.Skip() - } - origin, err := ioutil.TempDir("", "docker-test-untar-origin") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(origin) - if err := ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(origin, "2"), []byte("welcome!"), 0700); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(origin, "3"), []byte("will be ignored"), 0700); err != nil { - t.Fatal(err) - } - if err := system.Lsetxattr(filepath.Join(origin, "2"), "security.capability", []byte{0x00}, 0); err != nil { - t.Fatal(err) - } - - for _, c := range []Compression{ - Uncompressed, - Gzip, - } { - changes, err := tarUntar(t, origin, &TarOptions{ - Compression: c, - ExcludePatterns: []string{"3"}, - }) - - if err != nil { - t.Fatalf("Error tar/untar for compression %s: %s", c.Extension(), err) - } - - if len(changes) != 1 || changes[0].Path != "/3" { - t.Fatalf("Unexpected differences after tarUntar: %v", changes) - } - capability, _ := system.Lgetxattr(filepath.Join(origin, "2"), "security.capability") - if capability == nil && capability[0] != 0x00 { - t.Fatalf("Untar should have kept the 'security.capability' xattr.") - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/archive/archive_windows.go b/vendor/github.com/docker/docker/pkg/archive/archive_windows.go deleted file mode 100644 index 5c3a1be..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/archive_windows.go +++ /dev/null @@ -1,70 +0,0 @@ -// +build windows - -package archive - -import ( - "archive/tar" - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/docker/docker/pkg/longpath" -) - -// fixVolumePathPrefix does platform specific processing to ensure that if -// the path being passed in is not in a volume path format, convert it to one. -func fixVolumePathPrefix(srcPath string) string { - return longpath.AddPrefix(srcPath) -} - -// getWalkRoot calculates the root path when performing a TarWithOptions. -// We use a separate function as this is platform specific. -func getWalkRoot(srcPath string, include string) string { - return filepath.Join(srcPath, include) -} - -// CanonicalTarNameForPath returns platform-specific filepath -// to canonical posix-style path for tar archival. p is relative -// path. -func CanonicalTarNameForPath(p string) (string, error) { - // windows: convert windows style relative path with backslashes - // into forward slashes. Since windows does not allow '/' or '\' - // in file names, it is mostly safe to replace however we must - // check just in case - if strings.Contains(p, "/") { - return "", fmt.Errorf("Windows path contains forward slash: %s", p) - } - return strings.Replace(p, string(os.PathSeparator), "/", -1), nil - -} - -// chmodTarEntry is used to adjust the file permissions used in tar header based -// on the platform the archival is done. -func chmodTarEntry(perm os.FileMode) os.FileMode { - perm &= 0755 - // Add the x bit: make everything +x from windows - perm |= 0111 - - return perm -} - -func setHeaderForSpecialDevice(hdr *tar.Header, ta *tarAppender, name string, stat interface{}) (inode uint64, err error) { - // do nothing. no notion of Rdev, Inode, Nlink in stat on Windows - return -} - -// handleTarTypeBlockCharFifo is an OS-specific helper function used by -// createTarFile to handle the following types of header: Block; Char; Fifo -func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error { - return nil -} - -func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error { - return nil -} - -func getFileUIDGID(stat interface{}) (int, int, error) { - // no notion of file ownership mapping yet on Windows - return 0, 0, nil -} diff --git a/vendor/github.com/docker/docker/pkg/archive/archive_windows_test.go b/vendor/github.com/docker/docker/pkg/archive/archive_windows_test.go deleted file mode 100644 index 0c6733d..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/archive_windows_test.go +++ /dev/null @@ -1,91 +0,0 @@ -// +build windows - -package archive - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func TestCopyFileWithInvalidDest(t *testing.T) { - // TODO Windows: This is currently failing. Not sure what has - // recently changed in CopyWithTar as used to pass. Further investigation - // is required. - t.Skip("Currently fails") - folder, err := ioutil.TempDir("", "docker-archive-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(folder) - dest := "c:dest" - srcFolder := filepath.Join(folder, "src") - src := filepath.Join(folder, "src", "src") - err = os.MkdirAll(srcFolder, 0740) - if err != nil { - t.Fatal(err) - } - ioutil.WriteFile(src, []byte("content"), 0777) - err = CopyWithTar(src, dest) - if err == nil { - t.Fatalf("archiver.CopyWithTar should throw an error on invalid dest.") - } -} - -func TestCanonicalTarNameForPath(t *testing.T) { - cases := []struct { - in, expected string - shouldFail bool - }{ - {"foo", "foo", false}, - {"foo/bar", "___", true}, // unix-styled windows path must fail - {`foo\bar`, "foo/bar", false}, - } - for _, v := range cases { - if out, err := CanonicalTarNameForPath(v.in); err != nil && !v.shouldFail { - t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err) - } else if v.shouldFail && err == nil { - t.Fatalf("canonical path call should have failed with error. in=%s out=%s", v.in, out) - } else if !v.shouldFail && out != v.expected { - t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out) - } - } -} - -func TestCanonicalTarName(t *testing.T) { - cases := []struct { - in string - isDir bool - expected string - }{ - {"foo", false, "foo"}, - {"foo", true, "foo/"}, - {`foo\bar`, false, "foo/bar"}, - {`foo\bar`, true, "foo/bar/"}, - } - for _, v := range cases { - if out, err := canonicalTarName(v.in, v.isDir); err != nil { - t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err) - } else if out != v.expected { - t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out) - } - } -} - -func TestChmodTarEntry(t *testing.T) { - cases := []struct { - in, expected os.FileMode - }{ - {0000, 0111}, - {0777, 0755}, - {0644, 0755}, - {0755, 0755}, - {0444, 0555}, - } - for _, v := range cases { - if out := chmodTarEntry(v.in); out != v.expected { - t.Fatalf("wrong chmod. expected:%v got:%v", v.expected, out) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/archive/changes.go b/vendor/github.com/docker/docker/pkg/archive/changes.go deleted file mode 100644 index c07d55c..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/changes.go +++ /dev/null @@ -1,446 +0,0 @@ -package archive - -import ( - "archive/tar" - "bytes" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "sort" - "strings" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/pools" - "github.com/docker/docker/pkg/system" -) - -// ChangeType represents the change type. -type ChangeType int - -const ( - // ChangeModify represents the modify operation. - ChangeModify = iota - // ChangeAdd represents the add operation. - ChangeAdd - // ChangeDelete represents the delete operation. - ChangeDelete -) - -func (c ChangeType) String() string { - switch c { - case ChangeModify: - return "C" - case ChangeAdd: - return "A" - case ChangeDelete: - return "D" - } - return "" -} - -// Change represents a change, it wraps the change type and path. -// It describes changes of the files in the path respect to the -// parent layers. The change could be modify, add, delete. -// This is used for layer diff. -type Change struct { - Path string - Kind ChangeType -} - -func (change *Change) String() string { - return fmt.Sprintf("%s %s", change.Kind, change.Path) -} - -// for sort.Sort -type changesByPath []Change - -func (c changesByPath) Less(i, j int) bool { return c[i].Path < c[j].Path } -func (c changesByPath) Len() int { return len(c) } -func (c changesByPath) Swap(i, j int) { c[j], c[i] = c[i], c[j] } - -// Gnu tar and the go tar writer don't have sub-second mtime -// precision, which is problematic when we apply changes via tar -// files, we handle this by comparing for exact times, *or* same -// second count and either a or b having exactly 0 nanoseconds -func sameFsTime(a, b time.Time) bool { - return a == b || - (a.Unix() == b.Unix() && - (a.Nanosecond() == 0 || b.Nanosecond() == 0)) -} - -func sameFsTimeSpec(a, b syscall.Timespec) bool { - return a.Sec == b.Sec && - (a.Nsec == b.Nsec || a.Nsec == 0 || b.Nsec == 0) -} - -// Changes walks the path rw and determines changes for the files in the path, -// with respect to the parent layers -func Changes(layers []string, rw string) ([]Change, error) { - return changes(layers, rw, aufsDeletedFile, aufsMetadataSkip) -} - -func aufsMetadataSkip(path string) (skip bool, err error) { - skip, err = filepath.Match(string(os.PathSeparator)+WhiteoutMetaPrefix+"*", path) - if err != nil { - skip = true - } - return -} - -func aufsDeletedFile(root, path string, fi os.FileInfo) (string, error) { - f := filepath.Base(path) - - // If there is a whiteout, then the file was removed - if strings.HasPrefix(f, WhiteoutPrefix) { - originalFile := f[len(WhiteoutPrefix):] - return filepath.Join(filepath.Dir(path), originalFile), nil - } - - return "", nil -} - -type skipChange func(string) (bool, error) -type deleteChange func(string, string, os.FileInfo) (string, error) - -func changes(layers []string, rw string, dc deleteChange, sc skipChange) ([]Change, error) { - var ( - changes []Change - changedDirs = make(map[string]struct{}) - ) - - err := filepath.Walk(rw, func(path string, f os.FileInfo, err error) error { - if err != nil { - return err - } - - // Rebase path - path, err = filepath.Rel(rw, path) - if err != nil { - return err - } - - // As this runs on the daemon side, file paths are OS specific. - path = filepath.Join(string(os.PathSeparator), path) - - // Skip root - if path == string(os.PathSeparator) { - return nil - } - - if sc != nil { - if skip, err := sc(path); skip { - return err - } - } - - change := Change{ - Path: path, - } - - deletedFile, err := dc(rw, path, f) - if err != nil { - return err - } - - // Find out what kind of modification happened - if deletedFile != "" { - change.Path = deletedFile - change.Kind = ChangeDelete - } else { - // Otherwise, the file was added - change.Kind = ChangeAdd - - // ...Unless it already existed in a top layer, in which case, it's a modification - for _, layer := range layers { - stat, err := os.Stat(filepath.Join(layer, path)) - if err != nil && !os.IsNotExist(err) { - return err - } - if err == nil { - // The file existed in the top layer, so that's a modification - - // However, if it's a directory, maybe it wasn't actually modified. - // If you modify /foo/bar/baz, then /foo will be part of the changed files only because it's the parent of bar - if stat.IsDir() && f.IsDir() { - if f.Size() == stat.Size() && f.Mode() == stat.Mode() && sameFsTime(f.ModTime(), stat.ModTime()) { - // Both directories are the same, don't record the change - return nil - } - } - change.Kind = ChangeModify - break - } - } - } - - // If /foo/bar/file.txt is modified, then /foo/bar must be part of the changed files. - // This block is here to ensure the change is recorded even if the - // modify time, mode and size of the parent directory in the rw and ro layers are all equal. - // Check https://github.com/docker/docker/pull/13590 for details. - if f.IsDir() { - changedDirs[path] = struct{}{} - } - if change.Kind == ChangeAdd || change.Kind == ChangeDelete { - parent := filepath.Dir(path) - if _, ok := changedDirs[parent]; !ok && parent != "/" { - changes = append(changes, Change{Path: parent, Kind: ChangeModify}) - changedDirs[parent] = struct{}{} - } - } - - // Record change - changes = append(changes, change) - return nil - }) - if err != nil && !os.IsNotExist(err) { - return nil, err - } - return changes, nil -} - -// FileInfo describes the information of a file. -type FileInfo struct { - parent *FileInfo - name string - stat *system.StatT - children map[string]*FileInfo - capability []byte - added bool -} - -// LookUp looks up the file information of a file. -func (info *FileInfo) LookUp(path string) *FileInfo { - // As this runs on the daemon side, file paths are OS specific. - parent := info - if path == string(os.PathSeparator) { - return info - } - - pathElements := strings.Split(path, string(os.PathSeparator)) - for _, elem := range pathElements { - if elem != "" { - child := parent.children[elem] - if child == nil { - return nil - } - parent = child - } - } - return parent -} - -func (info *FileInfo) path() string { - if info.parent == nil { - // As this runs on the daemon side, file paths are OS specific. - return string(os.PathSeparator) - } - return filepath.Join(info.parent.path(), info.name) -} - -func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) { - - sizeAtEntry := len(*changes) - - if oldInfo == nil { - // add - change := Change{ - Path: info.path(), - Kind: ChangeAdd, - } - *changes = append(*changes, change) - info.added = true - } - - // We make a copy so we can modify it to detect additions - // also, we only recurse on the old dir if the new info is a directory - // otherwise any previous delete/change is considered recursive - oldChildren := make(map[string]*FileInfo) - if oldInfo != nil && info.isDir() { - for k, v := range oldInfo.children { - oldChildren[k] = v - } - } - - for name, newChild := range info.children { - oldChild, _ := oldChildren[name] - if oldChild != nil { - // change? - oldStat := oldChild.stat - newStat := newChild.stat - // Note: We can't compare inode or ctime or blocksize here, because these change - // when copying a file into a container. However, that is not generally a problem - // because any content change will change mtime, and any status change should - // be visible when actually comparing the stat fields. The only time this - // breaks down is if some code intentionally hides a change by setting - // back mtime - if statDifferent(oldStat, newStat) || - bytes.Compare(oldChild.capability, newChild.capability) != 0 { - change := Change{ - Path: newChild.path(), - Kind: ChangeModify, - } - *changes = append(*changes, change) - newChild.added = true - } - - // Remove from copy so we can detect deletions - delete(oldChildren, name) - } - - newChild.addChanges(oldChild, changes) - } - for _, oldChild := range oldChildren { - // delete - change := Change{ - Path: oldChild.path(), - Kind: ChangeDelete, - } - *changes = append(*changes, change) - } - - // If there were changes inside this directory, we need to add it, even if the directory - // itself wasn't changed. This is needed to properly save and restore filesystem permissions. - // As this runs on the daemon side, file paths are OS specific. - if len(*changes) > sizeAtEntry && info.isDir() && !info.added && info.path() != string(os.PathSeparator) { - change := Change{ - Path: info.path(), - Kind: ChangeModify, - } - // Let's insert the directory entry before the recently added entries located inside this dir - *changes = append(*changes, change) // just to resize the slice, will be overwritten - copy((*changes)[sizeAtEntry+1:], (*changes)[sizeAtEntry:]) - (*changes)[sizeAtEntry] = change - } - -} - -// Changes add changes to file information. -func (info *FileInfo) Changes(oldInfo *FileInfo) []Change { - var changes []Change - - info.addChanges(oldInfo, &changes) - - return changes -} - -func newRootFileInfo() *FileInfo { - // As this runs on the daemon side, file paths are OS specific. - root := &FileInfo{ - name: string(os.PathSeparator), - children: make(map[string]*FileInfo), - } - return root -} - -// ChangesDirs compares two directories and generates an array of Change objects describing the changes. -// If oldDir is "", then all files in newDir will be Add-Changes. -func ChangesDirs(newDir, oldDir string) ([]Change, error) { - var ( - oldRoot, newRoot *FileInfo - ) - if oldDir == "" { - emptyDir, err := ioutil.TempDir("", "empty") - if err != nil { - return nil, err - } - defer os.Remove(emptyDir) - oldDir = emptyDir - } - oldRoot, newRoot, err := collectFileInfoForChanges(oldDir, newDir) - if err != nil { - return nil, err - } - - return newRoot.Changes(oldRoot), nil -} - -// ChangesSize calculates the size in bytes of the provided changes, based on newDir. -func ChangesSize(newDir string, changes []Change) int64 { - var ( - size int64 - sf = make(map[uint64]struct{}) - ) - for _, change := range changes { - if change.Kind == ChangeModify || change.Kind == ChangeAdd { - file := filepath.Join(newDir, change.Path) - fileInfo, err := os.Lstat(file) - if err != nil { - logrus.Errorf("Can not stat %q: %s", file, err) - continue - } - - if fileInfo != nil && !fileInfo.IsDir() { - if hasHardlinks(fileInfo) { - inode := getIno(fileInfo) - if _, ok := sf[inode]; !ok { - size += fileInfo.Size() - sf[inode] = struct{}{} - } - } else { - size += fileInfo.Size() - } - } - } - } - return size -} - -// ExportChanges produces an Archive from the provided changes, relative to dir. -func ExportChanges(dir string, changes []Change, uidMaps, gidMaps []idtools.IDMap) (io.ReadCloser, error) { - reader, writer := io.Pipe() - go func() { - ta := &tarAppender{ - TarWriter: tar.NewWriter(writer), - Buffer: pools.BufioWriter32KPool.Get(nil), - SeenFiles: make(map[uint64]string), - UIDMaps: uidMaps, - GIDMaps: gidMaps, - } - // this buffer is needed for the duration of this piped stream - defer pools.BufioWriter32KPool.Put(ta.Buffer) - - sort.Sort(changesByPath(changes)) - - // In general we log errors here but ignore them because - // during e.g. a diff operation the container can continue - // mutating the filesystem and we can see transient errors - // from this - for _, change := range changes { - if change.Kind == ChangeDelete { - whiteOutDir := filepath.Dir(change.Path) - whiteOutBase := filepath.Base(change.Path) - whiteOut := filepath.Join(whiteOutDir, WhiteoutPrefix+whiteOutBase) - timestamp := time.Now() - hdr := &tar.Header{ - Name: whiteOut[1:], - Size: 0, - ModTime: timestamp, - AccessTime: timestamp, - ChangeTime: timestamp, - } - if err := ta.TarWriter.WriteHeader(hdr); err != nil { - logrus.Debugf("Can't write whiteout header: %s", err) - } - } else { - path := filepath.Join(dir, change.Path) - if err := ta.addTarFile(path, change.Path[1:]); err != nil { - logrus.Debugf("Can't add file %s to tar: %s", path, err) - } - } - } - - // Make sure to check the error on Close. - if err := ta.TarWriter.Close(); err != nil { - logrus.Debugf("Can't close layer: %s", err) - } - if err := writer.Close(); err != nil { - logrus.Debugf("failed close Changes writer: %s", err) - } - }() - return reader, nil -} diff --git a/vendor/github.com/docker/docker/pkg/archive/changes_linux.go b/vendor/github.com/docker/docker/pkg/archive/changes_linux.go deleted file mode 100644 index fc5a9df..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/changes_linux.go +++ /dev/null @@ -1,312 +0,0 @@ -package archive - -import ( - "bytes" - "fmt" - "os" - "path/filepath" - "sort" - "syscall" - "unsafe" - - "github.com/docker/docker/pkg/system" -) - -// walker is used to implement collectFileInfoForChanges on linux. Where this -// method in general returns the entire contents of two directory trees, we -// optimize some FS calls out on linux. In particular, we take advantage of the -// fact that getdents(2) returns the inode of each file in the directory being -// walked, which, when walking two trees in parallel to generate a list of -// changes, can be used to prune subtrees without ever having to lstat(2) them -// directly. Eliminating stat calls in this way can save up to seconds on large -// images. -type walker struct { - dir1 string - dir2 string - root1 *FileInfo - root2 *FileInfo -} - -// collectFileInfoForChanges returns a complete representation of the trees -// rooted at dir1 and dir2, with one important exception: any subtree or -// leaf where the inode and device numbers are an exact match between dir1 -// and dir2 will be pruned from the results. This method is *only* to be used -// to generating a list of changes between the two directories, as it does not -// reflect the full contents. -func collectFileInfoForChanges(dir1, dir2 string) (*FileInfo, *FileInfo, error) { - w := &walker{ - dir1: dir1, - dir2: dir2, - root1: newRootFileInfo(), - root2: newRootFileInfo(), - } - - i1, err := os.Lstat(w.dir1) - if err != nil { - return nil, nil, err - } - i2, err := os.Lstat(w.dir2) - if err != nil { - return nil, nil, err - } - - if err := w.walk("/", i1, i2); err != nil { - return nil, nil, err - } - - return w.root1, w.root2, nil -} - -// Given a FileInfo, its path info, and a reference to the root of the tree -// being constructed, register this file with the tree. -func walkchunk(path string, fi os.FileInfo, dir string, root *FileInfo) error { - if fi == nil { - return nil - } - parent := root.LookUp(filepath.Dir(path)) - if parent == nil { - return fmt.Errorf("collectFileInfoForChanges: Unexpectedly no parent for %s", path) - } - info := &FileInfo{ - name: filepath.Base(path), - children: make(map[string]*FileInfo), - parent: parent, - } - cpath := filepath.Join(dir, path) - stat, err := system.FromStatT(fi.Sys().(*syscall.Stat_t)) - if err != nil { - return err - } - info.stat = stat - info.capability, _ = system.Lgetxattr(cpath, "security.capability") // lgetxattr(2): fs access - parent.children[info.name] = info - return nil -} - -// Walk a subtree rooted at the same path in both trees being iterated. For -// example, /docker/overlay/1234/a/b/c/d and /docker/overlay/8888/a/b/c/d -func (w *walker) walk(path string, i1, i2 os.FileInfo) (err error) { - // Register these nodes with the return trees, unless we're still at the - // (already-created) roots: - if path != "/" { - if err := walkchunk(path, i1, w.dir1, w.root1); err != nil { - return err - } - if err := walkchunk(path, i2, w.dir2, w.root2); err != nil { - return err - } - } - - is1Dir := i1 != nil && i1.IsDir() - is2Dir := i2 != nil && i2.IsDir() - - sameDevice := false - if i1 != nil && i2 != nil { - si1 := i1.Sys().(*syscall.Stat_t) - si2 := i2.Sys().(*syscall.Stat_t) - if si1.Dev == si2.Dev { - sameDevice = true - } - } - - // If these files are both non-existent, or leaves (non-dirs), we are done. - if !is1Dir && !is2Dir { - return nil - } - - // Fetch the names of all the files contained in both directories being walked: - var names1, names2 []nameIno - if is1Dir { - names1, err = readdirnames(filepath.Join(w.dir1, path)) // getdents(2): fs access - if err != nil { - return err - } - } - if is2Dir { - names2, err = readdirnames(filepath.Join(w.dir2, path)) // getdents(2): fs access - if err != nil { - return err - } - } - - // We have lists of the files contained in both parallel directories, sorted - // in the same order. Walk them in parallel, generating a unique merged list - // of all items present in either or both directories. - var names []string - ix1 := 0 - ix2 := 0 - - for { - if ix1 >= len(names1) { - break - } - if ix2 >= len(names2) { - break - } - - ni1 := names1[ix1] - ni2 := names2[ix2] - - switch bytes.Compare([]byte(ni1.name), []byte(ni2.name)) { - case -1: // ni1 < ni2 -- advance ni1 - // we will not encounter ni1 in names2 - names = append(names, ni1.name) - ix1++ - case 0: // ni1 == ni2 - if ni1.ino != ni2.ino || !sameDevice { - names = append(names, ni1.name) - } - ix1++ - ix2++ - case 1: // ni1 > ni2 -- advance ni2 - // we will not encounter ni2 in names1 - names = append(names, ni2.name) - ix2++ - } - } - for ix1 < len(names1) { - names = append(names, names1[ix1].name) - ix1++ - } - for ix2 < len(names2) { - names = append(names, names2[ix2].name) - ix2++ - } - - // For each of the names present in either or both of the directories being - // iterated, stat the name under each root, and recurse the pair of them: - for _, name := range names { - fname := filepath.Join(path, name) - var cInfo1, cInfo2 os.FileInfo - if is1Dir { - cInfo1, err = os.Lstat(filepath.Join(w.dir1, fname)) // lstat(2): fs access - if err != nil && !os.IsNotExist(err) { - return err - } - } - if is2Dir { - cInfo2, err = os.Lstat(filepath.Join(w.dir2, fname)) // lstat(2): fs access - if err != nil && !os.IsNotExist(err) { - return err - } - } - if err = w.walk(fname, cInfo1, cInfo2); err != nil { - return err - } - } - return nil -} - -// {name,inode} pairs used to support the early-pruning logic of the walker type -type nameIno struct { - name string - ino uint64 -} - -type nameInoSlice []nameIno - -func (s nameInoSlice) Len() int { return len(s) } -func (s nameInoSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -func (s nameInoSlice) Less(i, j int) bool { return s[i].name < s[j].name } - -// readdirnames is a hacked-apart version of the Go stdlib code, exposing inode -// numbers further up the stack when reading directory contents. Unlike -// os.Readdirnames, which returns a list of filenames, this function returns a -// list of {filename,inode} pairs. -func readdirnames(dirname string) (names []nameIno, err error) { - var ( - size = 100 - buf = make([]byte, 4096) - nbuf int - bufp int - nb int - ) - - f, err := os.Open(dirname) - if err != nil { - return nil, err - } - defer f.Close() - - names = make([]nameIno, 0, size) // Empty with room to grow. - for { - // Refill the buffer if necessary - if bufp >= nbuf { - bufp = 0 - nbuf, err = syscall.ReadDirent(int(f.Fd()), buf) // getdents on linux - if nbuf < 0 { - nbuf = 0 - } - if err != nil { - return nil, os.NewSyscallError("readdirent", err) - } - if nbuf <= 0 { - break // EOF - } - } - - // Drain the buffer - nb, names = parseDirent(buf[bufp:nbuf], names) - bufp += nb - } - - sl := nameInoSlice(names) - sort.Sort(sl) - return sl, nil -} - -// parseDirent is a minor modification of syscall.ParseDirent (linux version) -// which returns {name,inode} pairs instead of just names. -func parseDirent(buf []byte, names []nameIno) (consumed int, newnames []nameIno) { - origlen := len(buf) - for len(buf) > 0 { - dirent := (*syscall.Dirent)(unsafe.Pointer(&buf[0])) - buf = buf[dirent.Reclen:] - if dirent.Ino == 0 { // File absent in directory. - continue - } - bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0])) - var name = string(bytes[0:clen(bytes[:])]) - if name == "." || name == ".." { // Useless names - continue - } - names = append(names, nameIno{name, dirent.Ino}) - } - return origlen - len(buf), names -} - -func clen(n []byte) int { - for i := 0; i < len(n); i++ { - if n[i] == 0 { - return i - } - } - return len(n) -} - -// OverlayChanges walks the path rw and determines changes for the files in the path, -// with respect to the parent layers -func OverlayChanges(layers []string, rw string) ([]Change, error) { - return changes(layers, rw, overlayDeletedFile, nil) -} - -func overlayDeletedFile(root, path string, fi os.FileInfo) (string, error) { - if fi.Mode()&os.ModeCharDevice != 0 { - s := fi.Sys().(*syscall.Stat_t) - if major(uint64(s.Rdev)) == 0 && minor(uint64(s.Rdev)) == 0 { - return path, nil - } - } - if fi.Mode()&os.ModeDir != 0 { - opaque, err := system.Lgetxattr(filepath.Join(root, path), "trusted.overlay.opaque") - if err != nil { - return "", err - } - if len(opaque) == 1 && opaque[0] == 'y' { - return path, nil - } - } - - return "", nil - -} diff --git a/vendor/github.com/docker/docker/pkg/archive/changes_other.go b/vendor/github.com/docker/docker/pkg/archive/changes_other.go deleted file mode 100644 index da70ed3..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/changes_other.go +++ /dev/null @@ -1,97 +0,0 @@ -// +build !linux - -package archive - -import ( - "fmt" - "os" - "path/filepath" - "runtime" - "strings" - - "github.com/docker/docker/pkg/system" -) - -func collectFileInfoForChanges(oldDir, newDir string) (*FileInfo, *FileInfo, error) { - var ( - oldRoot, newRoot *FileInfo - err1, err2 error - errs = make(chan error, 2) - ) - go func() { - oldRoot, err1 = collectFileInfo(oldDir) - errs <- err1 - }() - go func() { - newRoot, err2 = collectFileInfo(newDir) - errs <- err2 - }() - - // block until both routines have returned - for i := 0; i < 2; i++ { - if err := <-errs; err != nil { - return nil, nil, err - } - } - - return oldRoot, newRoot, nil -} - -func collectFileInfo(sourceDir string) (*FileInfo, error) { - root := newRootFileInfo() - - err := filepath.Walk(sourceDir, func(path string, f os.FileInfo, err error) error { - if err != nil { - return err - } - - // Rebase path - relPath, err := filepath.Rel(sourceDir, path) - if err != nil { - return err - } - - // As this runs on the daemon side, file paths are OS specific. - relPath = filepath.Join(string(os.PathSeparator), relPath) - - // See https://github.com/golang/go/issues/9168 - bug in filepath.Join. - // Temporary workaround. If the returned path starts with two backslashes, - // trim it down to a single backslash. Only relevant on Windows. - if runtime.GOOS == "windows" { - if strings.HasPrefix(relPath, `\\`) { - relPath = relPath[1:] - } - } - - if relPath == string(os.PathSeparator) { - return nil - } - - parent := root.LookUp(filepath.Dir(relPath)) - if parent == nil { - return fmt.Errorf("collectFileInfo: Unexpectedly no parent for %s", relPath) - } - - info := &FileInfo{ - name: filepath.Base(relPath), - children: make(map[string]*FileInfo), - parent: parent, - } - - s, err := system.Lstat(path) - if err != nil { - return err - } - info.stat = s - - info.capability, _ = system.Lgetxattr(path, "security.capability") - - parent.children[info.name] = info - - return nil - }) - if err != nil { - return nil, err - } - return root, nil -} diff --git a/vendor/github.com/docker/docker/pkg/archive/changes_posix_test.go b/vendor/github.com/docker/docker/pkg/archive/changes_posix_test.go deleted file mode 100644 index 095102e..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/changes_posix_test.go +++ /dev/null @@ -1,132 +0,0 @@ -package archive - -import ( - "archive/tar" - "fmt" - "io" - "io/ioutil" - "os" - "path" - "runtime" - "sort" - "testing" -) - -func TestHardLinkOrder(t *testing.T) { - //TODO Should run for Solaris - if runtime.GOOS == "solaris" { - t.Skip("gcp failures on Solaris") - } - names := []string{"file1.txt", "file2.txt", "file3.txt"} - msg := []byte("Hey y'all") - - // Create dir - src, err := ioutil.TempDir("", "docker-hardlink-test-src-") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(src) - for _, name := range names { - func() { - fh, err := os.Create(path.Join(src, name)) - if err != nil { - t.Fatal(err) - } - defer fh.Close() - if _, err = fh.Write(msg); err != nil { - t.Fatal(err) - } - }() - } - // Create dest, with changes that includes hardlinks - dest, err := ioutil.TempDir("", "docker-hardlink-test-dest-") - if err != nil { - t.Fatal(err) - } - os.RemoveAll(dest) // we just want the name, at first - if err := copyDir(src, dest); err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dest) - for _, name := range names { - for i := 0; i < 5; i++ { - if err := os.Link(path.Join(dest, name), path.Join(dest, fmt.Sprintf("%s.link%d", name, i))); err != nil { - t.Fatal(err) - } - } - } - - // get changes - changes, err := ChangesDirs(dest, src) - if err != nil { - t.Fatal(err) - } - - // sort - sort.Sort(changesByPath(changes)) - - // ExportChanges - ar, err := ExportChanges(dest, changes, nil, nil) - if err != nil { - t.Fatal(err) - } - hdrs, err := walkHeaders(ar) - if err != nil { - t.Fatal(err) - } - - // reverse sort - sort.Sort(sort.Reverse(changesByPath(changes))) - // ExportChanges - arRev, err := ExportChanges(dest, changes, nil, nil) - if err != nil { - t.Fatal(err) - } - hdrsRev, err := walkHeaders(arRev) - if err != nil { - t.Fatal(err) - } - - // line up the two sets - sort.Sort(tarHeaders(hdrs)) - sort.Sort(tarHeaders(hdrsRev)) - - // compare Size and LinkName - for i := range hdrs { - if hdrs[i].Name != hdrsRev[i].Name { - t.Errorf("headers - expected name %q; but got %q", hdrs[i].Name, hdrsRev[i].Name) - } - if hdrs[i].Size != hdrsRev[i].Size { - t.Errorf("headers - %q expected size %d; but got %d", hdrs[i].Name, hdrs[i].Size, hdrsRev[i].Size) - } - if hdrs[i].Typeflag != hdrsRev[i].Typeflag { - t.Errorf("headers - %q expected type %d; but got %d", hdrs[i].Name, hdrs[i].Typeflag, hdrsRev[i].Typeflag) - } - if hdrs[i].Linkname != hdrsRev[i].Linkname { - t.Errorf("headers - %q expected linkname %q; but got %q", hdrs[i].Name, hdrs[i].Linkname, hdrsRev[i].Linkname) - } - } - -} - -type tarHeaders []tar.Header - -func (th tarHeaders) Len() int { return len(th) } -func (th tarHeaders) Swap(i, j int) { th[j], th[i] = th[i], th[j] } -func (th tarHeaders) Less(i, j int) bool { return th[i].Name < th[j].Name } - -func walkHeaders(r io.Reader) ([]tar.Header, error) { - t := tar.NewReader(r) - headers := []tar.Header{} - for { - hdr, err := t.Next() - if err != nil { - if err == io.EOF { - break - } - return headers, err - } - headers = append(headers, *hdr) - } - return headers, nil -} diff --git a/vendor/github.com/docker/docker/pkg/archive/changes_test.go b/vendor/github.com/docker/docker/pkg/archive/changes_test.go deleted file mode 100644 index eae1d02..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/changes_test.go +++ /dev/null @@ -1,572 +0,0 @@ -package archive - -import ( - "io/ioutil" - "os" - "os/exec" - "path" - "runtime" - "sort" - "testing" - "time" - - "github.com/docker/docker/pkg/system" -) - -func max(x, y int) int { - if x >= y { - return x - } - return y -} - -func copyDir(src, dst string) error { - cmd := exec.Command("cp", "-a", src, dst) - if runtime.GOOS == "solaris" { - cmd = exec.Command("gcp", "-a", src, dst) - } - - if err := cmd.Run(); err != nil { - return err - } - return nil -} - -type FileType uint32 - -const ( - Regular FileType = iota - Dir - Symlink -) - -type FileData struct { - filetype FileType - path string - contents string - permissions os.FileMode -} - -func createSampleDir(t *testing.T, root string) { - files := []FileData{ - {Regular, "file1", "file1\n", 0600}, - {Regular, "file2", "file2\n", 0666}, - {Regular, "file3", "file3\n", 0404}, - {Regular, "file4", "file4\n", 0600}, - {Regular, "file5", "file5\n", 0600}, - {Regular, "file6", "file6\n", 0600}, - {Regular, "file7", "file7\n", 0600}, - {Dir, "dir1", "", 0740}, - {Regular, "dir1/file1-1", "file1-1\n", 01444}, - {Regular, "dir1/file1-2", "file1-2\n", 0666}, - {Dir, "dir2", "", 0700}, - {Regular, "dir2/file2-1", "file2-1\n", 0666}, - {Regular, "dir2/file2-2", "file2-2\n", 0666}, - {Dir, "dir3", "", 0700}, - {Regular, "dir3/file3-1", "file3-1\n", 0666}, - {Regular, "dir3/file3-2", "file3-2\n", 0666}, - {Dir, "dir4", "", 0700}, - {Regular, "dir4/file3-1", "file4-1\n", 0666}, - {Regular, "dir4/file3-2", "file4-2\n", 0666}, - {Symlink, "symlink1", "target1", 0666}, - {Symlink, "symlink2", "target2", 0666}, - {Symlink, "symlink3", root + "/file1", 0666}, - {Symlink, "symlink4", root + "/symlink3", 0666}, - {Symlink, "dirSymlink", root + "/dir1", 0740}, - } - - now := time.Now() - for _, info := range files { - p := path.Join(root, info.path) - if info.filetype == Dir { - if err := os.MkdirAll(p, info.permissions); err != nil { - t.Fatal(err) - } - } else if info.filetype == Regular { - if err := ioutil.WriteFile(p, []byte(info.contents), info.permissions); err != nil { - t.Fatal(err) - } - } else if info.filetype == Symlink { - if err := os.Symlink(info.contents, p); err != nil { - t.Fatal(err) - } - } - - if info.filetype != Symlink { - // Set a consistent ctime, atime for all files and dirs - if err := system.Chtimes(p, now, now); err != nil { - t.Fatal(err) - } - } - } -} - -func TestChangeString(t *testing.T) { - modifiyChange := Change{"change", ChangeModify} - toString := modifiyChange.String() - if toString != "C change" { - t.Fatalf("String() of a change with ChangeModifiy Kind should have been %s but was %s", "C change", toString) - } - addChange := Change{"change", ChangeAdd} - toString = addChange.String() - if toString != "A change" { - t.Fatalf("String() of a change with ChangeAdd Kind should have been %s but was %s", "A change", toString) - } - deleteChange := Change{"change", ChangeDelete} - toString = deleteChange.String() - if toString != "D change" { - t.Fatalf("String() of a change with ChangeDelete Kind should have been %s but was %s", "D change", toString) - } -} - -func TestChangesWithNoChanges(t *testing.T) { - // TODO Windows. There may be a way of running this, but turning off for now - // as createSampleDir uses symlinks. - if runtime.GOOS == "windows" { - t.Skip("symlinks on Windows") - } - rwLayer, err := ioutil.TempDir("", "docker-changes-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(rwLayer) - layer, err := ioutil.TempDir("", "docker-changes-test-layer") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(layer) - createSampleDir(t, layer) - changes, err := Changes([]string{layer}, rwLayer) - if err != nil { - t.Fatal(err) - } - if len(changes) != 0 { - t.Fatalf("Changes with no difference should have detect no changes, but detected %d", len(changes)) - } -} - -func TestChangesWithChanges(t *testing.T) { - // TODO Windows. There may be a way of running this, but turning off for now - // as createSampleDir uses symlinks. - if runtime.GOOS == "windows" { - t.Skip("symlinks on Windows") - } - // Mock the readonly layer - layer, err := ioutil.TempDir("", "docker-changes-test-layer") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(layer) - createSampleDir(t, layer) - os.MkdirAll(path.Join(layer, "dir1/subfolder"), 0740) - - // Mock the RW layer - rwLayer, err := ioutil.TempDir("", "docker-changes-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(rwLayer) - - // Create a folder in RW layer - dir1 := path.Join(rwLayer, "dir1") - os.MkdirAll(dir1, 0740) - deletedFile := path.Join(dir1, ".wh.file1-2") - ioutil.WriteFile(deletedFile, []byte{}, 0600) - modifiedFile := path.Join(dir1, "file1-1") - ioutil.WriteFile(modifiedFile, []byte{0x00}, 01444) - // Let's add a subfolder for a newFile - subfolder := path.Join(dir1, "subfolder") - os.MkdirAll(subfolder, 0740) - newFile := path.Join(subfolder, "newFile") - ioutil.WriteFile(newFile, []byte{}, 0740) - - changes, err := Changes([]string{layer}, rwLayer) - if err != nil { - t.Fatal(err) - } - - expectedChanges := []Change{ - {"/dir1", ChangeModify}, - {"/dir1/file1-1", ChangeModify}, - {"/dir1/file1-2", ChangeDelete}, - {"/dir1/subfolder", ChangeModify}, - {"/dir1/subfolder/newFile", ChangeAdd}, - } - checkChanges(expectedChanges, changes, t) -} - -// See https://github.com/docker/docker/pull/13590 -func TestChangesWithChangesGH13590(t *testing.T) { - // TODO Windows. There may be a way of running this, but turning off for now - // as createSampleDir uses symlinks. - if runtime.GOOS == "windows" { - t.Skip("symlinks on Windows") - } - baseLayer, err := ioutil.TempDir("", "docker-changes-test.") - defer os.RemoveAll(baseLayer) - - dir3 := path.Join(baseLayer, "dir1/dir2/dir3") - os.MkdirAll(dir3, 07400) - - file := path.Join(dir3, "file.txt") - ioutil.WriteFile(file, []byte("hello"), 0666) - - layer, err := ioutil.TempDir("", "docker-changes-test2.") - defer os.RemoveAll(layer) - - // Test creating a new file - if err := copyDir(baseLayer+"/dir1", layer+"/"); err != nil { - t.Fatalf("Cmd failed: %q", err) - } - - os.Remove(path.Join(layer, "dir1/dir2/dir3/file.txt")) - file = path.Join(layer, "dir1/dir2/dir3/file1.txt") - ioutil.WriteFile(file, []byte("bye"), 0666) - - changes, err := Changes([]string{baseLayer}, layer) - if err != nil { - t.Fatal(err) - } - - expectedChanges := []Change{ - {"/dir1/dir2/dir3", ChangeModify}, - {"/dir1/dir2/dir3/file1.txt", ChangeAdd}, - } - checkChanges(expectedChanges, changes, t) - - // Now test changing a file - layer, err = ioutil.TempDir("", "docker-changes-test3.") - defer os.RemoveAll(layer) - - if err := copyDir(baseLayer+"/dir1", layer+"/"); err != nil { - t.Fatalf("Cmd failed: %q", err) - } - - file = path.Join(layer, "dir1/dir2/dir3/file.txt") - ioutil.WriteFile(file, []byte("bye"), 0666) - - changes, err = Changes([]string{baseLayer}, layer) - if err != nil { - t.Fatal(err) - } - - expectedChanges = []Change{ - {"/dir1/dir2/dir3/file.txt", ChangeModify}, - } - checkChanges(expectedChanges, changes, t) -} - -// Create a directory, copy it, make sure we report no changes between the two -func TestChangesDirsEmpty(t *testing.T) { - // TODO Windows. There may be a way of running this, but turning off for now - // as createSampleDir uses symlinks. - // TODO Should work for Solaris - if runtime.GOOS == "windows" || runtime.GOOS == "solaris" { - t.Skip("symlinks on Windows; gcp failure on Solaris") - } - src, err := ioutil.TempDir("", "docker-changes-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(src) - createSampleDir(t, src) - dst := src + "-copy" - if err := copyDir(src, dst); err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dst) - changes, err := ChangesDirs(dst, src) - if err != nil { - t.Fatal(err) - } - - if len(changes) != 0 { - t.Fatalf("Reported changes for identical dirs: %v", changes) - } - os.RemoveAll(src) - os.RemoveAll(dst) -} - -func mutateSampleDir(t *testing.T, root string) { - // Remove a regular file - if err := os.RemoveAll(path.Join(root, "file1")); err != nil { - t.Fatal(err) - } - - // Remove a directory - if err := os.RemoveAll(path.Join(root, "dir1")); err != nil { - t.Fatal(err) - } - - // Remove a symlink - if err := os.RemoveAll(path.Join(root, "symlink1")); err != nil { - t.Fatal(err) - } - - // Rewrite a file - if err := ioutil.WriteFile(path.Join(root, "file2"), []byte("fileNN\n"), 0777); err != nil { - t.Fatal(err) - } - - // Replace a file - if err := os.RemoveAll(path.Join(root, "file3")); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(path.Join(root, "file3"), []byte("fileMM\n"), 0404); err != nil { - t.Fatal(err) - } - - // Touch file - if err := system.Chtimes(path.Join(root, "file4"), time.Now().Add(time.Second), time.Now().Add(time.Second)); err != nil { - t.Fatal(err) - } - - // Replace file with dir - if err := os.RemoveAll(path.Join(root, "file5")); err != nil { - t.Fatal(err) - } - if err := os.MkdirAll(path.Join(root, "file5"), 0666); err != nil { - t.Fatal(err) - } - - // Create new file - if err := ioutil.WriteFile(path.Join(root, "filenew"), []byte("filenew\n"), 0777); err != nil { - t.Fatal(err) - } - - // Create new dir - if err := os.MkdirAll(path.Join(root, "dirnew"), 0766); err != nil { - t.Fatal(err) - } - - // Create a new symlink - if err := os.Symlink("targetnew", path.Join(root, "symlinknew")); err != nil { - t.Fatal(err) - } - - // Change a symlink - if err := os.RemoveAll(path.Join(root, "symlink2")); err != nil { - t.Fatal(err) - } - if err := os.Symlink("target2change", path.Join(root, "symlink2")); err != nil { - t.Fatal(err) - } - - // Replace dir with file - if err := os.RemoveAll(path.Join(root, "dir2")); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(path.Join(root, "dir2"), []byte("dir2\n"), 0777); err != nil { - t.Fatal(err) - } - - // Touch dir - if err := system.Chtimes(path.Join(root, "dir3"), time.Now().Add(time.Second), time.Now().Add(time.Second)); err != nil { - t.Fatal(err) - } -} - -func TestChangesDirsMutated(t *testing.T) { - // TODO Windows. There may be a way of running this, but turning off for now - // as createSampleDir uses symlinks. - // TODO Should work for Solaris - if runtime.GOOS == "windows" || runtime.GOOS == "solaris" { - t.Skip("symlinks on Windows; gcp failures on Solaris") - } - src, err := ioutil.TempDir("", "docker-changes-test") - if err != nil { - t.Fatal(err) - } - createSampleDir(t, src) - dst := src + "-copy" - if err := copyDir(src, dst); err != nil { - t.Fatal(err) - } - defer os.RemoveAll(src) - defer os.RemoveAll(dst) - - mutateSampleDir(t, dst) - - changes, err := ChangesDirs(dst, src) - if err != nil { - t.Fatal(err) - } - - sort.Sort(changesByPath(changes)) - - expectedChanges := []Change{ - {"/dir1", ChangeDelete}, - {"/dir2", ChangeModify}, - {"/dirnew", ChangeAdd}, - {"/file1", ChangeDelete}, - {"/file2", ChangeModify}, - {"/file3", ChangeModify}, - {"/file4", ChangeModify}, - {"/file5", ChangeModify}, - {"/filenew", ChangeAdd}, - {"/symlink1", ChangeDelete}, - {"/symlink2", ChangeModify}, - {"/symlinknew", ChangeAdd}, - } - - for i := 0; i < max(len(changes), len(expectedChanges)); i++ { - if i >= len(expectedChanges) { - t.Fatalf("unexpected change %s\n", changes[i].String()) - } - if i >= len(changes) { - t.Fatalf("no change for expected change %s\n", expectedChanges[i].String()) - } - if changes[i].Path == expectedChanges[i].Path { - if changes[i] != expectedChanges[i] { - t.Fatalf("Wrong change for %s, expected %s, got %s\n", changes[i].Path, changes[i].String(), expectedChanges[i].String()) - } - } else if changes[i].Path < expectedChanges[i].Path { - t.Fatalf("unexpected change %s\n", changes[i].String()) - } else { - t.Fatalf("no change for expected change %s != %s\n", expectedChanges[i].String(), changes[i].String()) - } - } -} - -func TestApplyLayer(t *testing.T) { - // TODO Windows. There may be a way of running this, but turning off for now - // as createSampleDir uses symlinks. - // TODO Should work for Solaris - if runtime.GOOS == "windows" || runtime.GOOS == "solaris" { - t.Skip("symlinks on Windows; gcp failures on Solaris") - } - src, err := ioutil.TempDir("", "docker-changes-test") - if err != nil { - t.Fatal(err) - } - createSampleDir(t, src) - defer os.RemoveAll(src) - dst := src + "-copy" - if err := copyDir(src, dst); err != nil { - t.Fatal(err) - } - mutateSampleDir(t, dst) - defer os.RemoveAll(dst) - - changes, err := ChangesDirs(dst, src) - if err != nil { - t.Fatal(err) - } - - layer, err := ExportChanges(dst, changes, nil, nil) - if err != nil { - t.Fatal(err) - } - - layerCopy, err := NewTempArchive(layer, "") - if err != nil { - t.Fatal(err) - } - - if _, err := ApplyLayer(src, layerCopy); err != nil { - t.Fatal(err) - } - - changes2, err := ChangesDirs(src, dst) - if err != nil { - t.Fatal(err) - } - - if len(changes2) != 0 { - t.Fatalf("Unexpected differences after reapplying mutation: %v", changes2) - } -} - -func TestChangesSizeWithHardlinks(t *testing.T) { - // TODO Windows. There may be a way of running this, but turning off for now - // as createSampleDir uses symlinks. - if runtime.GOOS == "windows" { - t.Skip("hardlinks on Windows") - } - srcDir, err := ioutil.TempDir("", "docker-test-srcDir") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(srcDir) - - destDir, err := ioutil.TempDir("", "docker-test-destDir") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(destDir) - - creationSize, err := prepareUntarSourceDirectory(100, destDir, true) - if err != nil { - t.Fatal(err) - } - - changes, err := ChangesDirs(destDir, srcDir) - if err != nil { - t.Fatal(err) - } - - got := ChangesSize(destDir, changes) - if got != int64(creationSize) { - t.Errorf("Expected %d bytes of changes, got %d", creationSize, got) - } -} - -func TestChangesSizeWithNoChanges(t *testing.T) { - size := ChangesSize("/tmp", nil) - if size != 0 { - t.Fatalf("ChangesSizes with no changes should be 0, was %d", size) - } -} - -func TestChangesSizeWithOnlyDeleteChanges(t *testing.T) { - changes := []Change{ - {Path: "deletedPath", Kind: ChangeDelete}, - } - size := ChangesSize("/tmp", changes) - if size != 0 { - t.Fatalf("ChangesSizes with only delete changes should be 0, was %d", size) - } -} - -func TestChangesSize(t *testing.T) { - parentPath, err := ioutil.TempDir("", "docker-changes-test") - defer os.RemoveAll(parentPath) - addition := path.Join(parentPath, "addition") - if err := ioutil.WriteFile(addition, []byte{0x01, 0x01, 0x01}, 0744); err != nil { - t.Fatal(err) - } - modification := path.Join(parentPath, "modification") - if err = ioutil.WriteFile(modification, []byte{0x01, 0x01, 0x01}, 0744); err != nil { - t.Fatal(err) - } - changes := []Change{ - {Path: "addition", Kind: ChangeAdd}, - {Path: "modification", Kind: ChangeModify}, - } - size := ChangesSize(parentPath, changes) - if size != 6 { - t.Fatalf("Expected 6 bytes of changes, got %d", size) - } -} - -func checkChanges(expectedChanges, changes []Change, t *testing.T) { - sort.Sort(changesByPath(expectedChanges)) - sort.Sort(changesByPath(changes)) - for i := 0; i < max(len(changes), len(expectedChanges)); i++ { - if i >= len(expectedChanges) { - t.Fatalf("unexpected change %s\n", changes[i].String()) - } - if i >= len(changes) { - t.Fatalf("no change for expected change %s\n", expectedChanges[i].String()) - } - if changes[i].Path == expectedChanges[i].Path { - if changes[i] != expectedChanges[i] { - t.Fatalf("Wrong change for %s, expected %s, got %s\n", changes[i].Path, changes[i].String(), expectedChanges[i].String()) - } - } else if changes[i].Path < expectedChanges[i].Path { - t.Fatalf("unexpected change %s\n", changes[i].String()) - } else { - t.Fatalf("no change for expected change %s != %s\n", expectedChanges[i].String(), changes[i].String()) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/archive/changes_unix.go b/vendor/github.com/docker/docker/pkg/archive/changes_unix.go deleted file mode 100644 index 3778b73..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/changes_unix.go +++ /dev/null @@ -1,36 +0,0 @@ -// +build !windows - -package archive - -import ( - "os" - "syscall" - - "github.com/docker/docker/pkg/system" -) - -func statDifferent(oldStat *system.StatT, newStat *system.StatT) bool { - // Don't look at size for dirs, its not a good measure of change - if oldStat.Mode() != newStat.Mode() || - oldStat.UID() != newStat.UID() || - oldStat.GID() != newStat.GID() || - oldStat.Rdev() != newStat.Rdev() || - // Don't look at size for dirs, its not a good measure of change - (oldStat.Mode()&syscall.S_IFDIR != syscall.S_IFDIR && - (!sameFsTimeSpec(oldStat.Mtim(), newStat.Mtim()) || (oldStat.Size() != newStat.Size()))) { - return true - } - return false -} - -func (info *FileInfo) isDir() bool { - return info.parent == nil || info.stat.Mode()&syscall.S_IFDIR != 0 -} - -func getIno(fi os.FileInfo) uint64 { - return uint64(fi.Sys().(*syscall.Stat_t).Ino) -} - -func hasHardlinks(fi os.FileInfo) bool { - return fi.Sys().(*syscall.Stat_t).Nlink > 1 -} diff --git a/vendor/github.com/docker/docker/pkg/archive/changes_windows.go b/vendor/github.com/docker/docker/pkg/archive/changes_windows.go deleted file mode 100644 index af94243..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/changes_windows.go +++ /dev/null @@ -1,30 +0,0 @@ -package archive - -import ( - "os" - - "github.com/docker/docker/pkg/system" -) - -func statDifferent(oldStat *system.StatT, newStat *system.StatT) bool { - - // Don't look at size for dirs, its not a good measure of change - if oldStat.ModTime() != newStat.ModTime() || - oldStat.Mode() != newStat.Mode() || - oldStat.Size() != newStat.Size() && !oldStat.IsDir() { - return true - } - return false -} - -func (info *FileInfo) isDir() bool { - return info.parent == nil || info.stat.IsDir() -} - -func getIno(fi os.FileInfo) (inode uint64) { - return -} - -func hasHardlinks(fi os.FileInfo) bool { - return false -} diff --git a/vendor/github.com/docker/docker/pkg/archive/copy.go b/vendor/github.com/docker/docker/pkg/archive/copy.go deleted file mode 100644 index 0614c67..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/copy.go +++ /dev/null @@ -1,458 +0,0 @@ -package archive - -import ( - "archive/tar" - "errors" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/system" -) - -// Errors used or returned by this file. -var ( - ErrNotDirectory = errors.New("not a directory") - ErrDirNotExists = errors.New("no such directory") - ErrCannotCopyDir = errors.New("cannot copy directory") - ErrInvalidCopySource = errors.New("invalid copy source content") -) - -// PreserveTrailingDotOrSeparator returns the given cleaned path (after -// processing using any utility functions from the path or filepath stdlib -// packages) and appends a trailing `/.` or `/` if its corresponding original -// path (from before being processed by utility functions from the path or -// filepath stdlib packages) ends with a trailing `/.` or `/`. If the cleaned -// path already ends in a `.` path segment, then another is not added. If the -// clean path already ends in a path separator, then another is not added. -func PreserveTrailingDotOrSeparator(cleanedPath, originalPath string) string { - // Ensure paths are in platform semantics - cleanedPath = normalizePath(cleanedPath) - originalPath = normalizePath(originalPath) - - if !specifiesCurrentDir(cleanedPath) && specifiesCurrentDir(originalPath) { - if !hasTrailingPathSeparator(cleanedPath) { - // Add a separator if it doesn't already end with one (a cleaned - // path would only end in a separator if it is the root). - cleanedPath += string(filepath.Separator) - } - cleanedPath += "." - } - - if !hasTrailingPathSeparator(cleanedPath) && hasTrailingPathSeparator(originalPath) { - cleanedPath += string(filepath.Separator) - } - - return cleanedPath -} - -// assertsDirectory returns whether the given path is -// asserted to be a directory, i.e., the path ends with -// a trailing '/' or `/.`, assuming a path separator of `/`. -func assertsDirectory(path string) bool { - return hasTrailingPathSeparator(path) || specifiesCurrentDir(path) -} - -// hasTrailingPathSeparator returns whether the given -// path ends with the system's path separator character. -func hasTrailingPathSeparator(path string) bool { - return len(path) > 0 && os.IsPathSeparator(path[len(path)-1]) -} - -// specifiesCurrentDir returns whether the given path specifies -// a "current directory", i.e., the last path segment is `.`. -func specifiesCurrentDir(path string) bool { - return filepath.Base(path) == "." -} - -// SplitPathDirEntry splits the given path between its directory name and its -// basename by first cleaning the path but preserves a trailing "." if the -// original path specified the current directory. -func SplitPathDirEntry(path string) (dir, base string) { - cleanedPath := filepath.Clean(normalizePath(path)) - - if specifiesCurrentDir(path) { - cleanedPath += string(filepath.Separator) + "." - } - - return filepath.Dir(cleanedPath), filepath.Base(cleanedPath) -} - -// TarResource archives the resource described by the given CopyInfo to a Tar -// archive. A non-nil error is returned if sourcePath does not exist or is -// asserted to be a directory but exists as another type of file. -// -// This function acts as a convenient wrapper around TarWithOptions, which -// requires a directory as the source path. TarResource accepts either a -// directory or a file path and correctly sets the Tar options. -func TarResource(sourceInfo CopyInfo) (content io.ReadCloser, err error) { - return TarResourceRebase(sourceInfo.Path, sourceInfo.RebaseName) -} - -// TarResourceRebase is like TarResource but renames the first path element of -// items in the resulting tar archive to match the given rebaseName if not "". -func TarResourceRebase(sourcePath, rebaseName string) (content io.ReadCloser, err error) { - sourcePath = normalizePath(sourcePath) - if _, err = os.Lstat(sourcePath); err != nil { - // Catches the case where the source does not exist or is not a - // directory if asserted to be a directory, as this also causes an - // error. - return - } - - // Separate the source path between its directory and - // the entry in that directory which we are archiving. - sourceDir, sourceBase := SplitPathDirEntry(sourcePath) - - filter := []string{sourceBase} - - logrus.Debugf("copying %q from %q", sourceBase, sourceDir) - - return TarWithOptions(sourceDir, &TarOptions{ - Compression: Uncompressed, - IncludeFiles: filter, - IncludeSourceDir: true, - RebaseNames: map[string]string{ - sourceBase: rebaseName, - }, - }) -} - -// CopyInfo holds basic info about the source -// or destination path of a copy operation. -type CopyInfo struct { - Path string - Exists bool - IsDir bool - RebaseName string -} - -// CopyInfoSourcePath stats the given path to create a CopyInfo -// struct representing that resource for the source of an archive copy -// operation. The given path should be an absolute local path. A source path -// has all symlinks evaluated that appear before the last path separator ("/" -// on Unix). As it is to be a copy source, the path must exist. -func CopyInfoSourcePath(path string, followLink bool) (CopyInfo, error) { - // normalize the file path and then evaluate the symbol link - // we will use the target file instead of the symbol link if - // followLink is set - path = normalizePath(path) - - resolvedPath, rebaseName, err := ResolveHostSourcePath(path, followLink) - if err != nil { - return CopyInfo{}, err - } - - stat, err := os.Lstat(resolvedPath) - if err != nil { - return CopyInfo{}, err - } - - return CopyInfo{ - Path: resolvedPath, - Exists: true, - IsDir: stat.IsDir(), - RebaseName: rebaseName, - }, nil -} - -// CopyInfoDestinationPath stats the given path to create a CopyInfo -// struct representing that resource for the destination of an archive copy -// operation. The given path should be an absolute local path. -func CopyInfoDestinationPath(path string) (info CopyInfo, err error) { - maxSymlinkIter := 10 // filepath.EvalSymlinks uses 255, but 10 already seems like a lot. - path = normalizePath(path) - originalPath := path - - stat, err := os.Lstat(path) - - if err == nil && stat.Mode()&os.ModeSymlink == 0 { - // The path exists and is not a symlink. - return CopyInfo{ - Path: path, - Exists: true, - IsDir: stat.IsDir(), - }, nil - } - - // While the path is a symlink. - for n := 0; err == nil && stat.Mode()&os.ModeSymlink != 0; n++ { - if n > maxSymlinkIter { - // Don't follow symlinks more than this arbitrary number of times. - return CopyInfo{}, errors.New("too many symlinks in " + originalPath) - } - - // The path is a symbolic link. We need to evaluate it so that the - // destination of the copy operation is the link target and not the - // link itself. This is notably different than CopyInfoSourcePath which - // only evaluates symlinks before the last appearing path separator. - // Also note that it is okay if the last path element is a broken - // symlink as the copy operation should create the target. - var linkTarget string - - linkTarget, err = os.Readlink(path) - if err != nil { - return CopyInfo{}, err - } - - if !system.IsAbs(linkTarget) { - // Join with the parent directory. - dstParent, _ := SplitPathDirEntry(path) - linkTarget = filepath.Join(dstParent, linkTarget) - } - - path = linkTarget - stat, err = os.Lstat(path) - } - - if err != nil { - // It's okay if the destination path doesn't exist. We can still - // continue the copy operation if the parent directory exists. - if !os.IsNotExist(err) { - return CopyInfo{}, err - } - - // Ensure destination parent dir exists. - dstParent, _ := SplitPathDirEntry(path) - - parentDirStat, err := os.Lstat(dstParent) - if err != nil { - return CopyInfo{}, err - } - if !parentDirStat.IsDir() { - return CopyInfo{}, ErrNotDirectory - } - - return CopyInfo{Path: path}, nil - } - - // The path exists after resolving symlinks. - return CopyInfo{ - Path: path, - Exists: true, - IsDir: stat.IsDir(), - }, nil -} - -// PrepareArchiveCopy prepares the given srcContent archive, which should -// contain the archived resource described by srcInfo, to the destination -// described by dstInfo. Returns the possibly modified content archive along -// with the path to the destination directory which it should be extracted to. -func PrepareArchiveCopy(srcContent io.Reader, srcInfo, dstInfo CopyInfo) (dstDir string, content io.ReadCloser, err error) { - // Ensure in platform semantics - srcInfo.Path = normalizePath(srcInfo.Path) - dstInfo.Path = normalizePath(dstInfo.Path) - - // Separate the destination path between its directory and base - // components in case the source archive contents need to be rebased. - dstDir, dstBase := SplitPathDirEntry(dstInfo.Path) - _, srcBase := SplitPathDirEntry(srcInfo.Path) - - switch { - case dstInfo.Exists && dstInfo.IsDir: - // The destination exists as a directory. No alteration - // to srcContent is needed as its contents can be - // simply extracted to the destination directory. - return dstInfo.Path, ioutil.NopCloser(srcContent), nil - case dstInfo.Exists && srcInfo.IsDir: - // The destination exists as some type of file and the source - // content is a directory. This is an error condition since - // you cannot copy a directory to an existing file location. - return "", nil, ErrCannotCopyDir - case dstInfo.Exists: - // The destination exists as some type of file and the source content - // is also a file. The source content entry will have to be renamed to - // have a basename which matches the destination path's basename. - if len(srcInfo.RebaseName) != 0 { - srcBase = srcInfo.RebaseName - } - return dstDir, RebaseArchiveEntries(srcContent, srcBase, dstBase), nil - case srcInfo.IsDir: - // The destination does not exist and the source content is an archive - // of a directory. The archive should be extracted to the parent of - // the destination path instead, and when it is, the directory that is - // created as a result should take the name of the destination path. - // The source content entries will have to be renamed to have a - // basename which matches the destination path's basename. - if len(srcInfo.RebaseName) != 0 { - srcBase = srcInfo.RebaseName - } - return dstDir, RebaseArchiveEntries(srcContent, srcBase, dstBase), nil - case assertsDirectory(dstInfo.Path): - // The destination does not exist and is asserted to be created as a - // directory, but the source content is not a directory. This is an - // error condition since you cannot create a directory from a file - // source. - return "", nil, ErrDirNotExists - default: - // The last remaining case is when the destination does not exist, is - // not asserted to be a directory, and the source content is not an - // archive of a directory. It this case, the destination file will need - // to be created when the archive is extracted and the source content - // entry will have to be renamed to have a basename which matches the - // destination path's basename. - if len(srcInfo.RebaseName) != 0 { - srcBase = srcInfo.RebaseName - } - return dstDir, RebaseArchiveEntries(srcContent, srcBase, dstBase), nil - } - -} - -// RebaseArchiveEntries rewrites the given srcContent archive replacing -// an occurrence of oldBase with newBase at the beginning of entry names. -func RebaseArchiveEntries(srcContent io.Reader, oldBase, newBase string) io.ReadCloser { - if oldBase == string(os.PathSeparator) { - // If oldBase specifies the root directory, use an empty string as - // oldBase instead so that newBase doesn't replace the path separator - // that all paths will start with. - oldBase = "" - } - - rebased, w := io.Pipe() - - go func() { - srcTar := tar.NewReader(srcContent) - rebasedTar := tar.NewWriter(w) - - for { - hdr, err := srcTar.Next() - if err == io.EOF { - // Signals end of archive. - rebasedTar.Close() - w.Close() - return - } - if err != nil { - w.CloseWithError(err) - return - } - - hdr.Name = strings.Replace(hdr.Name, oldBase, newBase, 1) - - if err = rebasedTar.WriteHeader(hdr); err != nil { - w.CloseWithError(err) - return - } - - if _, err = io.Copy(rebasedTar, srcTar); err != nil { - w.CloseWithError(err) - return - } - } - }() - - return rebased -} - -// CopyResource performs an archive copy from the given source path to the -// given destination path. The source path MUST exist and the destination -// path's parent directory must exist. -func CopyResource(srcPath, dstPath string, followLink bool) error { - var ( - srcInfo CopyInfo - err error - ) - - // Ensure in platform semantics - srcPath = normalizePath(srcPath) - dstPath = normalizePath(dstPath) - - // Clean the source and destination paths. - srcPath = PreserveTrailingDotOrSeparator(filepath.Clean(srcPath), srcPath) - dstPath = PreserveTrailingDotOrSeparator(filepath.Clean(dstPath), dstPath) - - if srcInfo, err = CopyInfoSourcePath(srcPath, followLink); err != nil { - return err - } - - content, err := TarResource(srcInfo) - if err != nil { - return err - } - defer content.Close() - - return CopyTo(content, srcInfo, dstPath) -} - -// CopyTo handles extracting the given content whose -// entries should be sourced from srcInfo to dstPath. -func CopyTo(content io.Reader, srcInfo CopyInfo, dstPath string) error { - // The destination path need not exist, but CopyInfoDestinationPath will - // ensure that at least the parent directory exists. - dstInfo, err := CopyInfoDestinationPath(normalizePath(dstPath)) - if err != nil { - return err - } - - dstDir, copyArchive, err := PrepareArchiveCopy(content, srcInfo, dstInfo) - if err != nil { - return err - } - defer copyArchive.Close() - - options := &TarOptions{ - NoLchown: true, - NoOverwriteDirNonDir: true, - } - - return Untar(copyArchive, dstDir, options) -} - -// ResolveHostSourcePath decides real path need to be copied with parameters such as -// whether to follow symbol link or not, if followLink is true, resolvedPath will return -// link target of any symbol link file, else it will only resolve symlink of directory -// but return symbol link file itself without resolving. -func ResolveHostSourcePath(path string, followLink bool) (resolvedPath, rebaseName string, err error) { - if followLink { - resolvedPath, err = filepath.EvalSymlinks(path) - if err != nil { - return - } - - resolvedPath, rebaseName = GetRebaseName(path, resolvedPath) - } else { - dirPath, basePath := filepath.Split(path) - - // if not follow symbol link, then resolve symbol link of parent dir - var resolvedDirPath string - resolvedDirPath, err = filepath.EvalSymlinks(dirPath) - if err != nil { - return - } - // resolvedDirPath will have been cleaned (no trailing path separators) so - // we can manually join it with the base path element. - resolvedPath = resolvedDirPath + string(filepath.Separator) + basePath - if hasTrailingPathSeparator(path) && filepath.Base(path) != filepath.Base(resolvedPath) { - rebaseName = filepath.Base(path) - } - } - return resolvedPath, rebaseName, nil -} - -// GetRebaseName normalizes and compares path and resolvedPath, -// return completed resolved path and rebased file name -func GetRebaseName(path, resolvedPath string) (string, string) { - // linkTarget will have been cleaned (no trailing path separators and dot) so - // we can manually join it with them - var rebaseName string - if specifiesCurrentDir(path) && !specifiesCurrentDir(resolvedPath) { - resolvedPath += string(filepath.Separator) + "." - } - - if hasTrailingPathSeparator(path) && !hasTrailingPathSeparator(resolvedPath) { - resolvedPath += string(filepath.Separator) - } - - if filepath.Base(path) != filepath.Base(resolvedPath) { - // In the case where the path had a trailing separator and a symlink - // evaluation has changed the last path component, we will need to - // rebase the name in the archive that is being copied to match the - // originally requested name. - rebaseName = filepath.Base(path) - } - return resolvedPath, rebaseName -} diff --git a/vendor/github.com/docker/docker/pkg/archive/copy_unix.go b/vendor/github.com/docker/docker/pkg/archive/copy_unix.go deleted file mode 100644 index e305b5e..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/copy_unix.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !windows - -package archive - -import ( - "path/filepath" -) - -func normalizePath(path string) string { - return filepath.ToSlash(path) -} diff --git a/vendor/github.com/docker/docker/pkg/archive/copy_unix_test.go b/vendor/github.com/docker/docker/pkg/archive/copy_unix_test.go deleted file mode 100644 index ecbfc17..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/copy_unix_test.go +++ /dev/null @@ -1,978 +0,0 @@ -// +build !windows - -// TODO Windows: Some of these tests may be salvagable and portable to Windows. - -package archive - -import ( - "bytes" - "crypto/sha256" - "encoding/hex" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - "testing" -) - -func removeAllPaths(paths ...string) { - for _, path := range paths { - os.RemoveAll(path) - } -} - -func getTestTempDirs(t *testing.T) (tmpDirA, tmpDirB string) { - var err error - - if tmpDirA, err = ioutil.TempDir("", "archive-copy-test"); err != nil { - t.Fatal(err) - } - - if tmpDirB, err = ioutil.TempDir("", "archive-copy-test"); err != nil { - t.Fatal(err) - } - - return -} - -func isNotDir(err error) bool { - return strings.Contains(err.Error(), "not a directory") -} - -func joinTrailingSep(pathElements ...string) string { - joined := filepath.Join(pathElements...) - - return fmt.Sprintf("%s%c", joined, filepath.Separator) -} - -func fileContentsEqual(t *testing.T, filenameA, filenameB string) (err error) { - t.Logf("checking for equal file contents: %q and %q\n", filenameA, filenameB) - - fileA, err := os.Open(filenameA) - if err != nil { - return - } - defer fileA.Close() - - fileB, err := os.Open(filenameB) - if err != nil { - return - } - defer fileB.Close() - - hasher := sha256.New() - - if _, err = io.Copy(hasher, fileA); err != nil { - return - } - - hashA := hasher.Sum(nil) - hasher.Reset() - - if _, err = io.Copy(hasher, fileB); err != nil { - return - } - - hashB := hasher.Sum(nil) - - if !bytes.Equal(hashA, hashB) { - err = fmt.Errorf("file content hashes not equal - expected %s, got %s", hex.EncodeToString(hashA), hex.EncodeToString(hashB)) - } - - return -} - -func dirContentsEqual(t *testing.T, newDir, oldDir string) (err error) { - t.Logf("checking for equal directory contents: %q and %q\n", newDir, oldDir) - - var changes []Change - - if changes, err = ChangesDirs(newDir, oldDir); err != nil { - return - } - - if len(changes) != 0 { - err = fmt.Errorf("expected no changes between directories, but got: %v", changes) - } - - return -} - -func logDirContents(t *testing.T, dirPath string) { - logWalkedPaths := filepath.WalkFunc(func(path string, info os.FileInfo, err error) error { - if err != nil { - t.Errorf("stat error for path %q: %s", path, err) - return nil - } - - if info.IsDir() { - path = joinTrailingSep(path) - } - - t.Logf("\t%s", path) - - return nil - }) - - t.Logf("logging directory contents: %q", dirPath) - - if err := filepath.Walk(dirPath, logWalkedPaths); err != nil { - t.Fatal(err) - } -} - -func testCopyHelper(t *testing.T, srcPath, dstPath string) (err error) { - t.Logf("copying from %q to %q (not follow symbol link)", srcPath, dstPath) - - return CopyResource(srcPath, dstPath, false) -} - -func testCopyHelperFSym(t *testing.T, srcPath, dstPath string) (err error) { - t.Logf("copying from %q to %q (follow symbol link)", srcPath, dstPath) - - return CopyResource(srcPath, dstPath, true) -} - -// Basic assumptions about SRC and DST: -// 1. SRC must exist. -// 2. If SRC ends with a trailing separator, it must be a directory. -// 3. DST parent directory must exist. -// 4. If DST exists as a file, it must not end with a trailing separator. - -// First get these easy error cases out of the way. - -// Test for error when SRC does not exist. -func TestCopyErrSrcNotExists(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - if _, err := CopyInfoSourcePath(filepath.Join(tmpDirA, "file1"), false); !os.IsNotExist(err) { - t.Fatalf("expected IsNotExist error, but got %T: %s", err, err) - } -} - -// Test for error when SRC ends in a trailing -// path separator but it exists as a file. -func TestCopyErrSrcNotDir(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A with some sample files and directories. - createSampleDir(t, tmpDirA) - - if _, err := CopyInfoSourcePath(joinTrailingSep(tmpDirA, "file1"), false); !isNotDir(err) { - t.Fatalf("expected IsNotDir error, but got %T: %s", err, err) - } -} - -// Test for error when SRC is a valid file or directory, -// but the DST parent directory does not exist. -func TestCopyErrDstParentNotExists(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A with some sample files and directories. - createSampleDir(t, tmpDirA) - - srcInfo := CopyInfo{Path: filepath.Join(tmpDirA, "file1"), Exists: true, IsDir: false} - - // Try with a file source. - content, err := TarResource(srcInfo) - if err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - defer content.Close() - - // Copy to a file whose parent does not exist. - if err = CopyTo(content, srcInfo, filepath.Join(tmpDirB, "fakeParentDir", "file1")); err == nil { - t.Fatal("expected IsNotExist error, but got nil instead") - } - - if !os.IsNotExist(err) { - t.Fatalf("expected IsNotExist error, but got %T: %s", err, err) - } - - // Try with a directory source. - srcInfo = CopyInfo{Path: filepath.Join(tmpDirA, "dir1"), Exists: true, IsDir: true} - - content, err = TarResource(srcInfo) - if err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - defer content.Close() - - // Copy to a directory whose parent does not exist. - if err = CopyTo(content, srcInfo, joinTrailingSep(tmpDirB, "fakeParentDir", "fakeDstDir")); err == nil { - t.Fatal("expected IsNotExist error, but got nil instead") - } - - if !os.IsNotExist(err) { - t.Fatalf("expected IsNotExist error, but got %T: %s", err, err) - } -} - -// Test for error when DST ends in a trailing -// path separator but exists as a file. -func TestCopyErrDstNotDir(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - // Try with a file source. - srcInfo := CopyInfo{Path: filepath.Join(tmpDirA, "file1"), Exists: true, IsDir: false} - - content, err := TarResource(srcInfo) - if err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - defer content.Close() - - if err = CopyTo(content, srcInfo, joinTrailingSep(tmpDirB, "file1")); err == nil { - t.Fatal("expected IsNotDir error, but got nil instead") - } - - if !isNotDir(err) { - t.Fatalf("expected IsNotDir error, but got %T: %s", err, err) - } - - // Try with a directory source. - srcInfo = CopyInfo{Path: filepath.Join(tmpDirA, "dir1"), Exists: true, IsDir: true} - - content, err = TarResource(srcInfo) - if err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - defer content.Close() - - if err = CopyTo(content, srcInfo, joinTrailingSep(tmpDirB, "file1")); err == nil { - t.Fatal("expected IsNotDir error, but got nil instead") - } - - if !isNotDir(err) { - t.Fatalf("expected IsNotDir error, but got %T: %s", err, err) - } -} - -// Possibilities are reduced to the remaining 10 cases: -// -// case | srcIsDir | onlyDirContents | dstExists | dstIsDir | dstTrSep | action -// =================================================================================================== -// A | no | - | no | - | no | create file -// B | no | - | no | - | yes | error -// C | no | - | yes | no | - | overwrite file -// D | no | - | yes | yes | - | create file in dst dir -// E | yes | no | no | - | - | create dir, copy contents -// F | yes | no | yes | no | - | error -// G | yes | no | yes | yes | - | copy dir and contents -// H | yes | yes | no | - | - | create dir, copy contents -// I | yes | yes | yes | no | - | error -// J | yes | yes | yes | yes | - | copy dir contents -// - -// A. SRC specifies a file and DST (no trailing path separator) doesn't -// exist. This should create a file with the name DST and copy the -// contents of the source file into it. -func TestCopyCaseA(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A with some sample files and directories. - createSampleDir(t, tmpDirA) - - srcPath := filepath.Join(tmpDirA, "file1") - dstPath := filepath.Join(tmpDirB, "itWorks.txt") - - var err error - - if err = testCopyHelper(t, srcPath, dstPath); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = fileContentsEqual(t, srcPath, dstPath); err != nil { - t.Fatal(err) - } - os.Remove(dstPath) - - symlinkPath := filepath.Join(tmpDirA, "symlink3") - symlinkPath1 := filepath.Join(tmpDirA, "symlink4") - linkTarget := filepath.Join(tmpDirA, "file1") - - if err = testCopyHelperFSym(t, symlinkPath, dstPath); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = fileContentsEqual(t, linkTarget, dstPath); err != nil { - t.Fatal(err) - } - os.Remove(dstPath) - if err = testCopyHelperFSym(t, symlinkPath1, dstPath); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = fileContentsEqual(t, linkTarget, dstPath); err != nil { - t.Fatal(err) - } -} - -// B. SRC specifies a file and DST (with trailing path separator) doesn't -// exist. This should cause an error because the copy operation cannot -// create a directory when copying a single file. -func TestCopyCaseB(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A with some sample files and directories. - createSampleDir(t, tmpDirA) - - srcPath := filepath.Join(tmpDirA, "file1") - dstDir := joinTrailingSep(tmpDirB, "testDir") - - var err error - - if err = testCopyHelper(t, srcPath, dstDir); err == nil { - t.Fatal("expected ErrDirNotExists error, but got nil instead") - } - - if err != ErrDirNotExists { - t.Fatalf("expected ErrDirNotExists error, but got %T: %s", err, err) - } - - symlinkPath := filepath.Join(tmpDirA, "symlink3") - - if err = testCopyHelperFSym(t, symlinkPath, dstDir); err == nil { - t.Fatal("expected ErrDirNotExists error, but got nil instead") - } - if err != ErrDirNotExists { - t.Fatalf("expected ErrDirNotExists error, but got %T: %s", err, err) - } - -} - -// C. SRC specifies a file and DST exists as a file. This should overwrite -// the file at DST with the contents of the source file. -func TestCopyCaseC(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - srcPath := filepath.Join(tmpDirA, "file1") - dstPath := filepath.Join(tmpDirB, "file2") - - var err error - - // Ensure they start out different. - if err = fileContentsEqual(t, srcPath, dstPath); err == nil { - t.Fatal("expected different file contents") - } - - if err = testCopyHelper(t, srcPath, dstPath); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = fileContentsEqual(t, srcPath, dstPath); err != nil { - t.Fatal(err) - } -} - -// C. Symbol link following version: -// SRC specifies a file and DST exists as a file. This should overwrite -// the file at DST with the contents of the source file. -func TestCopyCaseCFSym(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - symlinkPathBad := filepath.Join(tmpDirA, "symlink1") - symlinkPath := filepath.Join(tmpDirA, "symlink3") - linkTarget := filepath.Join(tmpDirA, "file1") - dstPath := filepath.Join(tmpDirB, "file2") - - var err error - - // first to test broken link - if err = testCopyHelperFSym(t, symlinkPathBad, dstPath); err == nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - // test symbol link -> symbol link -> target - // Ensure they start out different. - if err = fileContentsEqual(t, linkTarget, dstPath); err == nil { - t.Fatal("expected different file contents") - } - - if err = testCopyHelperFSym(t, symlinkPath, dstPath); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = fileContentsEqual(t, linkTarget, dstPath); err != nil { - t.Fatal(err) - } -} - -// D. SRC specifies a file and DST exists as a directory. This should place -// a copy of the source file inside it using the basename from SRC. Ensure -// this works whether DST has a trailing path separator or not. -func TestCopyCaseD(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - srcPath := filepath.Join(tmpDirA, "file1") - dstDir := filepath.Join(tmpDirB, "dir1") - dstPath := filepath.Join(dstDir, "file1") - - var err error - - // Ensure that dstPath doesn't exist. - if _, err = os.Stat(dstPath); !os.IsNotExist(err) { - t.Fatalf("did not expect dstPath %q to exist", dstPath) - } - - if err = testCopyHelper(t, srcPath, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = fileContentsEqual(t, srcPath, dstPath); err != nil { - t.Fatal(err) - } - - // Now try again but using a trailing path separator for dstDir. - - if err = os.RemoveAll(dstDir); err != nil { - t.Fatalf("unable to remove dstDir: %s", err) - } - - if err = os.MkdirAll(dstDir, os.FileMode(0755)); err != nil { - t.Fatalf("unable to make dstDir: %s", err) - } - - dstDir = joinTrailingSep(tmpDirB, "dir1") - - if err = testCopyHelper(t, srcPath, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = fileContentsEqual(t, srcPath, dstPath); err != nil { - t.Fatal(err) - } -} - -// D. Symbol link following version: -// SRC specifies a file and DST exists as a directory. This should place -// a copy of the source file inside it using the basename from SRC. Ensure -// this works whether DST has a trailing path separator or not. -func TestCopyCaseDFSym(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - srcPath := filepath.Join(tmpDirA, "symlink4") - linkTarget := filepath.Join(tmpDirA, "file1") - dstDir := filepath.Join(tmpDirB, "dir1") - dstPath := filepath.Join(dstDir, "symlink4") - - var err error - - // Ensure that dstPath doesn't exist. - if _, err = os.Stat(dstPath); !os.IsNotExist(err) { - t.Fatalf("did not expect dstPath %q to exist", dstPath) - } - - if err = testCopyHelperFSym(t, srcPath, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = fileContentsEqual(t, linkTarget, dstPath); err != nil { - t.Fatal(err) - } - - // Now try again but using a trailing path separator for dstDir. - - if err = os.RemoveAll(dstDir); err != nil { - t.Fatalf("unable to remove dstDir: %s", err) - } - - if err = os.MkdirAll(dstDir, os.FileMode(0755)); err != nil { - t.Fatalf("unable to make dstDir: %s", err) - } - - dstDir = joinTrailingSep(tmpDirB, "dir1") - - if err = testCopyHelperFSym(t, srcPath, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = fileContentsEqual(t, linkTarget, dstPath); err != nil { - t.Fatal(err) - } -} - -// E. SRC specifies a directory and DST does not exist. This should create a -// directory at DST and copy the contents of the SRC directory into the DST -// directory. Ensure this works whether DST has a trailing path separator or -// not. -func TestCopyCaseE(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A with some sample files and directories. - createSampleDir(t, tmpDirA) - - srcDir := filepath.Join(tmpDirA, "dir1") - dstDir := filepath.Join(tmpDirB, "testDir") - - var err error - - if err = testCopyHelper(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, srcDir); err != nil { - t.Log("dir contents not equal") - logDirContents(t, tmpDirA) - logDirContents(t, tmpDirB) - t.Fatal(err) - } - - // Now try again but using a trailing path separator for dstDir. - - if err = os.RemoveAll(dstDir); err != nil { - t.Fatalf("unable to remove dstDir: %s", err) - } - - dstDir = joinTrailingSep(tmpDirB, "testDir") - - if err = testCopyHelper(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, srcDir); err != nil { - t.Fatal(err) - } -} - -// E. Symbol link following version: -// SRC specifies a directory and DST does not exist. This should create a -// directory at DST and copy the contents of the SRC directory into the DST -// directory. Ensure this works whether DST has a trailing path separator or -// not. -func TestCopyCaseEFSym(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A with some sample files and directories. - createSampleDir(t, tmpDirA) - - srcDir := filepath.Join(tmpDirA, "dirSymlink") - linkTarget := filepath.Join(tmpDirA, "dir1") - dstDir := filepath.Join(tmpDirB, "testDir") - - var err error - - if err = testCopyHelperFSym(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, linkTarget); err != nil { - t.Log("dir contents not equal") - logDirContents(t, tmpDirA) - logDirContents(t, tmpDirB) - t.Fatal(err) - } - - // Now try again but using a trailing path separator for dstDir. - - if err = os.RemoveAll(dstDir); err != nil { - t.Fatalf("unable to remove dstDir: %s", err) - } - - dstDir = joinTrailingSep(tmpDirB, "testDir") - - if err = testCopyHelperFSym(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, linkTarget); err != nil { - t.Fatal(err) - } -} - -// F. SRC specifies a directory and DST exists as a file. This should cause an -// error as it is not possible to overwrite a file with a directory. -func TestCopyCaseF(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - srcDir := filepath.Join(tmpDirA, "dir1") - symSrcDir := filepath.Join(tmpDirA, "dirSymlink") - dstFile := filepath.Join(tmpDirB, "file1") - - var err error - - if err = testCopyHelper(t, srcDir, dstFile); err == nil { - t.Fatal("expected ErrCannotCopyDir error, but got nil instead") - } - - if err != ErrCannotCopyDir { - t.Fatalf("expected ErrCannotCopyDir error, but got %T: %s", err, err) - } - - // now test with symbol link - if err = testCopyHelperFSym(t, symSrcDir, dstFile); err == nil { - t.Fatal("expected ErrCannotCopyDir error, but got nil instead") - } - - if err != ErrCannotCopyDir { - t.Fatalf("expected ErrCannotCopyDir error, but got %T: %s", err, err) - } -} - -// G. SRC specifies a directory and DST exists as a directory. This should copy -// the SRC directory and all its contents to the DST directory. Ensure this -// works whether DST has a trailing path separator or not. -func TestCopyCaseG(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - srcDir := filepath.Join(tmpDirA, "dir1") - dstDir := filepath.Join(tmpDirB, "dir2") - resultDir := filepath.Join(dstDir, "dir1") - - var err error - - if err = testCopyHelper(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, resultDir, srcDir); err != nil { - t.Fatal(err) - } - - // Now try again but using a trailing path separator for dstDir. - - if err = os.RemoveAll(dstDir); err != nil { - t.Fatalf("unable to remove dstDir: %s", err) - } - - if err = os.MkdirAll(dstDir, os.FileMode(0755)); err != nil { - t.Fatalf("unable to make dstDir: %s", err) - } - - dstDir = joinTrailingSep(tmpDirB, "dir2") - - if err = testCopyHelper(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, resultDir, srcDir); err != nil { - t.Fatal(err) - } -} - -// G. Symbol link version: -// SRC specifies a directory and DST exists as a directory. This should copy -// the SRC directory and all its contents to the DST directory. Ensure this -// works whether DST has a trailing path separator or not. -func TestCopyCaseGFSym(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - srcDir := filepath.Join(tmpDirA, "dirSymlink") - linkTarget := filepath.Join(tmpDirA, "dir1") - dstDir := filepath.Join(tmpDirB, "dir2") - resultDir := filepath.Join(dstDir, "dirSymlink") - - var err error - - if err = testCopyHelperFSym(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, resultDir, linkTarget); err != nil { - t.Fatal(err) - } - - // Now try again but using a trailing path separator for dstDir. - - if err = os.RemoveAll(dstDir); err != nil { - t.Fatalf("unable to remove dstDir: %s", err) - } - - if err = os.MkdirAll(dstDir, os.FileMode(0755)); err != nil { - t.Fatalf("unable to make dstDir: %s", err) - } - - dstDir = joinTrailingSep(tmpDirB, "dir2") - - if err = testCopyHelperFSym(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, resultDir, linkTarget); err != nil { - t.Fatal(err) - } -} - -// H. SRC specifies a directory's contents only and DST does not exist. This -// should create a directory at DST and copy the contents of the SRC -// directory (but not the directory itself) into the DST directory. Ensure -// this works whether DST has a trailing path separator or not. -func TestCopyCaseH(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A with some sample files and directories. - createSampleDir(t, tmpDirA) - - srcDir := joinTrailingSep(tmpDirA, "dir1") + "." - dstDir := filepath.Join(tmpDirB, "testDir") - - var err error - - if err = testCopyHelper(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, srcDir); err != nil { - t.Log("dir contents not equal") - logDirContents(t, tmpDirA) - logDirContents(t, tmpDirB) - t.Fatal(err) - } - - // Now try again but using a trailing path separator for dstDir. - - if err = os.RemoveAll(dstDir); err != nil { - t.Fatalf("unable to remove dstDir: %s", err) - } - - dstDir = joinTrailingSep(tmpDirB, "testDir") - - if err = testCopyHelper(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, srcDir); err != nil { - t.Log("dir contents not equal") - logDirContents(t, tmpDirA) - logDirContents(t, tmpDirB) - t.Fatal(err) - } -} - -// H. Symbol link following version: -// SRC specifies a directory's contents only and DST does not exist. This -// should create a directory at DST and copy the contents of the SRC -// directory (but not the directory itself) into the DST directory. Ensure -// this works whether DST has a trailing path separator or not. -func TestCopyCaseHFSym(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A with some sample files and directories. - createSampleDir(t, tmpDirA) - - srcDir := joinTrailingSep(tmpDirA, "dirSymlink") + "." - linkTarget := filepath.Join(tmpDirA, "dir1") - dstDir := filepath.Join(tmpDirB, "testDir") - - var err error - - if err = testCopyHelperFSym(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, linkTarget); err != nil { - t.Log("dir contents not equal") - logDirContents(t, tmpDirA) - logDirContents(t, tmpDirB) - t.Fatal(err) - } - - // Now try again but using a trailing path separator for dstDir. - - if err = os.RemoveAll(dstDir); err != nil { - t.Fatalf("unable to remove dstDir: %s", err) - } - - dstDir = joinTrailingSep(tmpDirB, "testDir") - - if err = testCopyHelperFSym(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, linkTarget); err != nil { - t.Log("dir contents not equal") - logDirContents(t, tmpDirA) - logDirContents(t, tmpDirB) - t.Fatal(err) - } -} - -// I. SRC specifies a directory's contents only and DST exists as a file. This -// should cause an error as it is not possible to overwrite a file with a -// directory. -func TestCopyCaseI(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - srcDir := joinTrailingSep(tmpDirA, "dir1") + "." - symSrcDir := filepath.Join(tmpDirB, "dirSymlink") - dstFile := filepath.Join(tmpDirB, "file1") - - var err error - - if err = testCopyHelper(t, srcDir, dstFile); err == nil { - t.Fatal("expected ErrCannotCopyDir error, but got nil instead") - } - - if err != ErrCannotCopyDir { - t.Fatalf("expected ErrCannotCopyDir error, but got %T: %s", err, err) - } - - // now try with symbol link of dir - if err = testCopyHelperFSym(t, symSrcDir, dstFile); err == nil { - t.Fatal("expected ErrCannotCopyDir error, but got nil instead") - } - - if err != ErrCannotCopyDir { - t.Fatalf("expected ErrCannotCopyDir error, but got %T: %s", err, err) - } -} - -// J. SRC specifies a directory's contents only and DST exists as a directory. -// This should copy the contents of the SRC directory (but not the directory -// itself) into the DST directory. Ensure this works whether DST has a -// trailing path separator or not. -func TestCopyCaseJ(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - srcDir := joinTrailingSep(tmpDirA, "dir1") + "." - dstDir := filepath.Join(tmpDirB, "dir5") - - var err error - - // first to create an empty dir - if err = os.MkdirAll(dstDir, os.FileMode(0755)); err != nil { - t.Fatalf("unable to make dstDir: %s", err) - } - - if err = testCopyHelper(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, srcDir); err != nil { - t.Fatal(err) - } - - // Now try again but using a trailing path separator for dstDir. - - if err = os.RemoveAll(dstDir); err != nil { - t.Fatalf("unable to remove dstDir: %s", err) - } - - if err = os.MkdirAll(dstDir, os.FileMode(0755)); err != nil { - t.Fatalf("unable to make dstDir: %s", err) - } - - dstDir = joinTrailingSep(tmpDirB, "dir5") - - if err = testCopyHelper(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, srcDir); err != nil { - t.Fatal(err) - } -} - -// J. Symbol link following version: -// SRC specifies a directory's contents only and DST exists as a directory. -// This should copy the contents of the SRC directory (but not the directory -// itself) into the DST directory. Ensure this works whether DST has a -// trailing path separator or not. -func TestCopyCaseJFSym(t *testing.T) { - tmpDirA, tmpDirB := getTestTempDirs(t) - defer removeAllPaths(tmpDirA, tmpDirB) - - // Load A and B with some sample files and directories. - createSampleDir(t, tmpDirA) - createSampleDir(t, tmpDirB) - - srcDir := joinTrailingSep(tmpDirA, "dirSymlink") + "." - linkTarget := filepath.Join(tmpDirA, "dir1") - dstDir := filepath.Join(tmpDirB, "dir5") - - var err error - - // first to create an empty dir - if err = os.MkdirAll(dstDir, os.FileMode(0755)); err != nil { - t.Fatalf("unable to make dstDir: %s", err) - } - - if err = testCopyHelperFSym(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, linkTarget); err != nil { - t.Fatal(err) - } - - // Now try again but using a trailing path separator for dstDir. - - if err = os.RemoveAll(dstDir); err != nil { - t.Fatalf("unable to remove dstDir: %s", err) - } - - if err = os.MkdirAll(dstDir, os.FileMode(0755)); err != nil { - t.Fatalf("unable to make dstDir: %s", err) - } - - dstDir = joinTrailingSep(tmpDirB, "dir5") - - if err = testCopyHelperFSym(t, srcDir, dstDir); err != nil { - t.Fatalf("unexpected error %T: %s", err, err) - } - - if err = dirContentsEqual(t, dstDir, linkTarget); err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/pkg/archive/copy_windows.go b/vendor/github.com/docker/docker/pkg/archive/copy_windows.go deleted file mode 100644 index 2b775b4..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/copy_windows.go +++ /dev/null @@ -1,9 +0,0 @@ -package archive - -import ( - "path/filepath" -) - -func normalizePath(path string) string { - return filepath.FromSlash(path) -} diff --git a/vendor/github.com/docker/docker/pkg/archive/diff.go b/vendor/github.com/docker/docker/pkg/archive/diff.go deleted file mode 100644 index 9e1a58c..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/diff.go +++ /dev/null @@ -1,279 +0,0 @@ -package archive - -import ( - "archive/tar" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "runtime" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/pools" - "github.com/docker/docker/pkg/system" -) - -// UnpackLayer unpack `layer` to a `dest`. The stream `layer` can be -// compressed or uncompressed. -// Returns the size in bytes of the contents of the layer. -func UnpackLayer(dest string, layer io.Reader, options *TarOptions) (size int64, err error) { - tr := tar.NewReader(layer) - trBuf := pools.BufioReader32KPool.Get(tr) - defer pools.BufioReader32KPool.Put(trBuf) - - var dirs []*tar.Header - unpackedPaths := make(map[string]struct{}) - - if options == nil { - options = &TarOptions{} - } - if options.ExcludePatterns == nil { - options.ExcludePatterns = []string{} - } - remappedRootUID, remappedRootGID, err := idtools.GetRootUIDGID(options.UIDMaps, options.GIDMaps) - if err != nil { - return 0, err - } - - aufsTempdir := "" - aufsHardlinks := make(map[string]*tar.Header) - - if options == nil { - options = &TarOptions{} - } - // Iterate through the files in the archive. - for { - hdr, err := tr.Next() - if err == io.EOF { - // end of tar archive - break - } - if err != nil { - return 0, err - } - - size += hdr.Size - - // Normalize name, for safety and for a simple is-root check - hdr.Name = filepath.Clean(hdr.Name) - - // Windows does not support filenames with colons in them. Ignore - // these files. This is not a problem though (although it might - // appear that it is). Let's suppose a client is running docker pull. - // The daemon it points to is Windows. Would it make sense for the - // client to be doing a docker pull Ubuntu for example (which has files - // with colons in the name under /usr/share/man/man3)? No, absolutely - // not as it would really only make sense that they were pulling a - // Windows image. However, for development, it is necessary to be able - // to pull Linux images which are in the repository. - // - // TODO Windows. Once the registry is aware of what images are Windows- - // specific or Linux-specific, this warning should be changed to an error - // to cater for the situation where someone does manage to upload a Linux - // image but have it tagged as Windows inadvertently. - if runtime.GOOS == "windows" { - if strings.Contains(hdr.Name, ":") { - logrus.Warnf("Windows: Ignoring %s (is this a Linux image?)", hdr.Name) - continue - } - } - - // Note as these operations are platform specific, so must the slash be. - if !strings.HasSuffix(hdr.Name, string(os.PathSeparator)) { - // Not the root directory, ensure that the parent directory exists. - // This happened in some tests where an image had a tarfile without any - // parent directories. - parent := filepath.Dir(hdr.Name) - parentPath := filepath.Join(dest, parent) - - if _, err := os.Lstat(parentPath); err != nil && os.IsNotExist(err) { - err = system.MkdirAll(parentPath, 0600) - if err != nil { - return 0, err - } - } - } - - // Skip AUFS metadata dirs - if strings.HasPrefix(hdr.Name, WhiteoutMetaPrefix) { - // Regular files inside /.wh..wh.plnk can be used as hardlink targets - // We don't want this directory, but we need the files in them so that - // such hardlinks can be resolved. - if strings.HasPrefix(hdr.Name, WhiteoutLinkDir) && hdr.Typeflag == tar.TypeReg { - basename := filepath.Base(hdr.Name) - aufsHardlinks[basename] = hdr - if aufsTempdir == "" { - if aufsTempdir, err = ioutil.TempDir("", "dockerplnk"); err != nil { - return 0, err - } - defer os.RemoveAll(aufsTempdir) - } - if err := createTarFile(filepath.Join(aufsTempdir, basename), dest, hdr, tr, true, nil, options.InUserNS); err != nil { - return 0, err - } - } - - if hdr.Name != WhiteoutOpaqueDir { - continue - } - } - path := filepath.Join(dest, hdr.Name) - rel, err := filepath.Rel(dest, path) - if err != nil { - return 0, err - } - - // Note as these operations are platform specific, so must the slash be. - if strings.HasPrefix(rel, ".."+string(os.PathSeparator)) { - return 0, breakoutError(fmt.Errorf("%q is outside of %q", hdr.Name, dest)) - } - base := filepath.Base(path) - - if strings.HasPrefix(base, WhiteoutPrefix) { - dir := filepath.Dir(path) - if base == WhiteoutOpaqueDir { - _, err := os.Lstat(dir) - if err != nil { - return 0, err - } - err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { - if err != nil { - if os.IsNotExist(err) { - err = nil // parent was deleted - } - return err - } - if path == dir { - return nil - } - if _, exists := unpackedPaths[path]; !exists { - err := os.RemoveAll(path) - return err - } - return nil - }) - if err != nil { - return 0, err - } - } else { - originalBase := base[len(WhiteoutPrefix):] - originalPath := filepath.Join(dir, originalBase) - if err := os.RemoveAll(originalPath); err != nil { - return 0, err - } - } - } else { - // If path exits we almost always just want to remove and replace it. - // The only exception is when it is a directory *and* the file from - // the layer is also a directory. Then we want to merge them (i.e. - // just apply the metadata from the layer). - if fi, err := os.Lstat(path); err == nil { - if !(fi.IsDir() && hdr.Typeflag == tar.TypeDir) { - if err := os.RemoveAll(path); err != nil { - return 0, err - } - } - } - - trBuf.Reset(tr) - srcData := io.Reader(trBuf) - srcHdr := hdr - - // Hard links into /.wh..wh.plnk don't work, as we don't extract that directory, so - // we manually retarget these into the temporary files we extracted them into - if hdr.Typeflag == tar.TypeLink && strings.HasPrefix(filepath.Clean(hdr.Linkname), WhiteoutLinkDir) { - linkBasename := filepath.Base(hdr.Linkname) - srcHdr = aufsHardlinks[linkBasename] - if srcHdr == nil { - return 0, fmt.Errorf("Invalid aufs hardlink") - } - tmpFile, err := os.Open(filepath.Join(aufsTempdir, linkBasename)) - if err != nil { - return 0, err - } - defer tmpFile.Close() - srcData = tmpFile - } - - // if the options contain a uid & gid maps, convert header uid/gid - // entries using the maps such that lchown sets the proper mapped - // uid/gid after writing the file. We only perform this mapping if - // the file isn't already owned by the remapped root UID or GID, as - // that specific uid/gid has no mapping from container -> host, and - // those files already have the proper ownership for inside the - // container. - if srcHdr.Uid != remappedRootUID { - xUID, err := idtools.ToHost(srcHdr.Uid, options.UIDMaps) - if err != nil { - return 0, err - } - srcHdr.Uid = xUID - } - if srcHdr.Gid != remappedRootGID { - xGID, err := idtools.ToHost(srcHdr.Gid, options.GIDMaps) - if err != nil { - return 0, err - } - srcHdr.Gid = xGID - } - if err := createTarFile(path, dest, srcHdr, srcData, true, nil, options.InUserNS); err != nil { - return 0, err - } - - // Directory mtimes must be handled at the end to avoid further - // file creation in them to modify the directory mtime - if hdr.Typeflag == tar.TypeDir { - dirs = append(dirs, hdr) - } - unpackedPaths[path] = struct{}{} - } - } - - for _, hdr := range dirs { - path := filepath.Join(dest, hdr.Name) - if err := system.Chtimes(path, hdr.AccessTime, hdr.ModTime); err != nil { - return 0, err - } - } - - return size, nil -} - -// ApplyLayer parses a diff in the standard layer format from `layer`, -// and applies it to the directory `dest`. The stream `layer` can be -// compressed or uncompressed. -// Returns the size in bytes of the contents of the layer. -func ApplyLayer(dest string, layer io.Reader) (int64, error) { - return applyLayerHandler(dest, layer, &TarOptions{}, true) -} - -// ApplyUncompressedLayer parses a diff in the standard layer format from -// `layer`, and applies it to the directory `dest`. The stream `layer` -// can only be uncompressed. -// Returns the size in bytes of the contents of the layer. -func ApplyUncompressedLayer(dest string, layer io.Reader, options *TarOptions) (int64, error) { - return applyLayerHandler(dest, layer, options, false) -} - -// do the bulk load of ApplyLayer, but allow for not calling DecompressStream -func applyLayerHandler(dest string, layer io.Reader, options *TarOptions, decompress bool) (int64, error) { - dest = filepath.Clean(dest) - - // We need to be able to set any perms - oldmask, err := system.Umask(0) - if err != nil { - return 0, err - } - defer system.Umask(oldmask) // ignore err, ErrNotSupportedPlatform - - if decompress { - layer, err = DecompressStream(layer) - if err != nil { - return 0, err - } - } - return UnpackLayer(dest, layer, options) -} diff --git a/vendor/github.com/docker/docker/pkg/archive/diff_test.go b/vendor/github.com/docker/docker/pkg/archive/diff_test.go deleted file mode 100644 index 8167941..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/diff_test.go +++ /dev/null @@ -1,386 +0,0 @@ -package archive - -import ( - "archive/tar" - "io" - "io/ioutil" - "os" - "path/filepath" - "reflect" - "runtime" - "testing" - - "github.com/docker/docker/pkg/ioutils" -) - -func TestApplyLayerInvalidFilenames(t *testing.T) { - // TODO Windows: Figure out how to fix this test. - if runtime.GOOS == "windows" { - t.Skip("Passes but hits breakoutError: platform and architecture is not supported") - } - for i, headers := range [][]*tar.Header{ - { - { - Name: "../victim/dotdot", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - { - { - // Note the leading slash - Name: "/../victim/slash-dotdot", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - } { - if err := testBreakout("applylayer", "docker-TestApplyLayerInvalidFilenames", headers); err != nil { - t.Fatalf("i=%d. %v", i, err) - } - } -} - -func TestApplyLayerInvalidHardlink(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("TypeLink support on Windows") - } - for i, headers := range [][]*tar.Header{ - { // try reading victim/hello (../) - { - Name: "dotdot", - Typeflag: tar.TypeLink, - Linkname: "../victim/hello", - Mode: 0644, - }, - }, - { // try reading victim/hello (/../) - { - Name: "slash-dotdot", - Typeflag: tar.TypeLink, - // Note the leading slash - Linkname: "/../victim/hello", - Mode: 0644, - }, - }, - { // try writing victim/file - { - Name: "loophole-victim", - Typeflag: tar.TypeLink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "loophole-victim/file", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - { // try reading victim/hello (hardlink, symlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeLink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "symlink", - Typeflag: tar.TypeSymlink, - Linkname: "loophole-victim/hello", - Mode: 0644, - }, - }, - { // Try reading victim/hello (hardlink, hardlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeLink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "hardlink", - Typeflag: tar.TypeLink, - Linkname: "loophole-victim/hello", - Mode: 0644, - }, - }, - { // Try removing victim directory (hardlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeLink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "loophole-victim", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - } { - if err := testBreakout("applylayer", "docker-TestApplyLayerInvalidHardlink", headers); err != nil { - t.Fatalf("i=%d. %v", i, err) - } - } -} - -func TestApplyLayerInvalidSymlink(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("TypeSymLink support on Windows") - } - for i, headers := range [][]*tar.Header{ - { // try reading victim/hello (../) - { - Name: "dotdot", - Typeflag: tar.TypeSymlink, - Linkname: "../victim/hello", - Mode: 0644, - }, - }, - { // try reading victim/hello (/../) - { - Name: "slash-dotdot", - Typeflag: tar.TypeSymlink, - // Note the leading slash - Linkname: "/../victim/hello", - Mode: 0644, - }, - }, - { // try writing victim/file - { - Name: "loophole-victim", - Typeflag: tar.TypeSymlink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "loophole-victim/file", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - { // try reading victim/hello (symlink, symlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeSymlink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "symlink", - Typeflag: tar.TypeSymlink, - Linkname: "loophole-victim/hello", - Mode: 0644, - }, - }, - { // try reading victim/hello (symlink, hardlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeSymlink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "hardlink", - Typeflag: tar.TypeLink, - Linkname: "loophole-victim/hello", - Mode: 0644, - }, - }, - { // try removing victim directory (symlink) - { - Name: "loophole-victim", - Typeflag: tar.TypeSymlink, - Linkname: "../victim", - Mode: 0755, - }, - { - Name: "loophole-victim", - Typeflag: tar.TypeReg, - Mode: 0644, - }, - }, - } { - if err := testBreakout("applylayer", "docker-TestApplyLayerInvalidSymlink", headers); err != nil { - t.Fatalf("i=%d. %v", i, err) - } - } -} - -func TestApplyLayerWhiteouts(t *testing.T) { - // TODO Windows: Figure out why this test fails - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - - wd, err := ioutil.TempDir("", "graphdriver-test-whiteouts") - if err != nil { - return - } - defer os.RemoveAll(wd) - - base := []string{ - ".baz", - "bar/", - "bar/bax", - "bar/bay/", - "baz", - "foo/", - "foo/.abc", - "foo/.bcd/", - "foo/.bcd/a", - "foo/cde/", - "foo/cde/def", - "foo/cde/efg", - "foo/fgh", - "foobar", - } - - type tcase struct { - change, expected []string - } - - tcases := []tcase{ - { - base, - base, - }, - { - []string{ - ".bay", - ".wh.baz", - "foo/", - "foo/.bce", - "foo/.wh..wh..opq", - "foo/cde/", - "foo/cde/efg", - }, - []string{ - ".bay", - ".baz", - "bar/", - "bar/bax", - "bar/bay/", - "foo/", - "foo/.bce", - "foo/cde/", - "foo/cde/efg", - "foobar", - }, - }, - { - []string{ - ".bay", - ".wh..baz", - ".wh.foobar", - "foo/", - "foo/.abc", - "foo/.wh.cde", - "bar/", - }, - []string{ - ".bay", - "bar/", - "bar/bax", - "bar/bay/", - "foo/", - "foo/.abc", - "foo/.bce", - }, - }, - { - []string{ - ".abc", - ".wh..wh..opq", - "foobar", - }, - []string{ - ".abc", - "foobar", - }, - }, - } - - for i, tc := range tcases { - l, err := makeTestLayer(tc.change) - if err != nil { - t.Fatal(err) - } - - _, err = UnpackLayer(wd, l, nil) - if err != nil { - t.Fatal(err) - } - err = l.Close() - if err != nil { - t.Fatal(err) - } - - paths, err := readDirContents(wd) - if err != nil { - t.Fatal(err) - } - - if !reflect.DeepEqual(tc.expected, paths) { - t.Fatalf("invalid files for layer %d: expected %q, got %q", i, tc.expected, paths) - } - } - -} - -func makeTestLayer(paths []string) (rc io.ReadCloser, err error) { - tmpDir, err := ioutil.TempDir("", "graphdriver-test-mklayer") - if err != nil { - return - } - defer func() { - if err != nil { - os.RemoveAll(tmpDir) - } - }() - for _, p := range paths { - if p[len(p)-1] == filepath.Separator { - if err = os.MkdirAll(filepath.Join(tmpDir, p), 0700); err != nil { - return - } - } else { - if err = ioutil.WriteFile(filepath.Join(tmpDir, p), nil, 0600); err != nil { - return - } - } - } - archive, err := Tar(tmpDir, Uncompressed) - if err != nil { - return - } - return ioutils.NewReadCloserWrapper(archive, func() error { - err := archive.Close() - os.RemoveAll(tmpDir) - return err - }), nil -} - -func readDirContents(root string) ([]string, error) { - var files []string - err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if path == root { - return nil - } - rel, err := filepath.Rel(root, path) - if err != nil { - return err - } - if info.IsDir() { - rel = rel + "/" - } - files = append(files, rel) - return nil - }) - if err != nil { - return nil, err - } - return files, nil -} diff --git a/vendor/github.com/docker/docker/pkg/archive/example_changes.go b/vendor/github.com/docker/docker/pkg/archive/example_changes.go deleted file mode 100644 index cedd46a..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/example_changes.go +++ /dev/null @@ -1,97 +0,0 @@ -// +build ignore - -// Simple tool to create an archive stream from an old and new directory -// -// By default it will stream the comparison of two temporary directories with junk files -package main - -import ( - "flag" - "fmt" - "io" - "io/ioutil" - "os" - "path" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/archive" -) - -var ( - flDebug = flag.Bool("D", false, "debugging output") - flNewDir = flag.String("newdir", "", "") - flOldDir = flag.String("olddir", "", "") - log = logrus.New() -) - -func main() { - flag.Usage = func() { - fmt.Println("Produce a tar from comparing two directory paths. By default a demo tar is created of around 200 files (including hardlinks)") - fmt.Printf("%s [OPTIONS]\n", os.Args[0]) - flag.PrintDefaults() - } - flag.Parse() - log.Out = os.Stderr - if (len(os.Getenv("DEBUG")) > 0) || *flDebug { - logrus.SetLevel(logrus.DebugLevel) - } - var newDir, oldDir string - - if len(*flNewDir) == 0 { - var err error - newDir, err = ioutil.TempDir("", "docker-test-newDir") - if err != nil { - log.Fatal(err) - } - defer os.RemoveAll(newDir) - if _, err := prepareUntarSourceDirectory(100, newDir, true); err != nil { - log.Fatal(err) - } - } else { - newDir = *flNewDir - } - - if len(*flOldDir) == 0 { - oldDir, err := ioutil.TempDir("", "docker-test-oldDir") - if err != nil { - log.Fatal(err) - } - defer os.RemoveAll(oldDir) - } else { - oldDir = *flOldDir - } - - changes, err := archive.ChangesDirs(newDir, oldDir) - if err != nil { - log.Fatal(err) - } - - a, err := archive.ExportChanges(newDir, changes) - if err != nil { - log.Fatal(err) - } - defer a.Close() - - i, err := io.Copy(os.Stdout, a) - if err != nil && err != io.EOF { - log.Fatal(err) - } - fmt.Fprintf(os.Stderr, "wrote archive of %d bytes", i) -} - -func prepareUntarSourceDirectory(numberOfFiles int, targetPath string, makeLinks bool) (int, error) { - fileData := []byte("fooo") - for n := 0; n < numberOfFiles; n++ { - fileName := fmt.Sprintf("file-%d", n) - if err := ioutil.WriteFile(path.Join(targetPath, fileName), fileData, 0700); err != nil { - return 0, err - } - if makeLinks { - if err := os.Link(path.Join(targetPath, fileName), path.Join(targetPath, fileName+"-link")); err != nil { - return 0, err - } - } - } - totalSize := numberOfFiles * len(fileData) - return totalSize, nil -} diff --git a/vendor/github.com/docker/docker/pkg/archive/testdata/broken.tar b/vendor/github.com/docker/docker/pkg/archive/testdata/broken.tar deleted file mode 100644 index 8f10ea6..0000000 Binary files a/vendor/github.com/docker/docker/pkg/archive/testdata/broken.tar and /dev/null differ diff --git a/vendor/github.com/docker/docker/pkg/archive/time_linux.go b/vendor/github.com/docker/docker/pkg/archive/time_linux.go deleted file mode 100644 index 3448569..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/time_linux.go +++ /dev/null @@ -1,16 +0,0 @@ -package archive - -import ( - "syscall" - "time" -) - -func timeToTimespec(time time.Time) (ts syscall.Timespec) { - if time.IsZero() { - // Return UTIME_OMIT special value - ts.Sec = 0 - ts.Nsec = ((1 << 30) - 2) - return - } - return syscall.NsecToTimespec(time.UnixNano()) -} diff --git a/vendor/github.com/docker/docker/pkg/archive/time_unsupported.go b/vendor/github.com/docker/docker/pkg/archive/time_unsupported.go deleted file mode 100644 index e85aac0..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/time_unsupported.go +++ /dev/null @@ -1,16 +0,0 @@ -// +build !linux - -package archive - -import ( - "syscall" - "time" -) - -func timeToTimespec(time time.Time) (ts syscall.Timespec) { - nsec := int64(0) - if !time.IsZero() { - nsec = time.UnixNano() - } - return syscall.NsecToTimespec(nsec) -} diff --git a/vendor/github.com/docker/docker/pkg/archive/utils_test.go b/vendor/github.com/docker/docker/pkg/archive/utils_test.go deleted file mode 100644 index 01b9e92..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/utils_test.go +++ /dev/null @@ -1,166 +0,0 @@ -package archive - -import ( - "archive/tar" - "bytes" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "time" -) - -var testUntarFns = map[string]func(string, io.Reader) error{ - "untar": func(dest string, r io.Reader) error { - return Untar(r, dest, nil) - }, - "applylayer": func(dest string, r io.Reader) error { - _, err := ApplyLayer(dest, r) - return err - }, -} - -// testBreakout is a helper function that, within the provided `tmpdir` directory, -// creates a `victim` folder with a generated `hello` file in it. -// `untar` extracts to a directory named `dest`, the tar file created from `headers`. -// -// Here are the tested scenarios: -// - removed `victim` folder (write) -// - removed files from `victim` folder (write) -// - new files in `victim` folder (write) -// - modified files in `victim` folder (write) -// - file in `dest` with same content as `victim/hello` (read) -// -// When using testBreakout make sure you cover one of the scenarios listed above. -func testBreakout(untarFn string, tmpdir string, headers []*tar.Header) error { - tmpdir, err := ioutil.TempDir("", tmpdir) - if err != nil { - return err - } - defer os.RemoveAll(tmpdir) - - dest := filepath.Join(tmpdir, "dest") - if err := os.Mkdir(dest, 0755); err != nil { - return err - } - - victim := filepath.Join(tmpdir, "victim") - if err := os.Mkdir(victim, 0755); err != nil { - return err - } - hello := filepath.Join(victim, "hello") - helloData, err := time.Now().MarshalText() - if err != nil { - return err - } - if err := ioutil.WriteFile(hello, helloData, 0644); err != nil { - return err - } - helloStat, err := os.Stat(hello) - if err != nil { - return err - } - - reader, writer := io.Pipe() - go func() { - t := tar.NewWriter(writer) - for _, hdr := range headers { - t.WriteHeader(hdr) - } - t.Close() - }() - - untar := testUntarFns[untarFn] - if untar == nil { - return fmt.Errorf("could not find untar function %q in testUntarFns", untarFn) - } - if err := untar(dest, reader); err != nil { - if _, ok := err.(breakoutError); !ok { - // If untar returns an error unrelated to an archive breakout, - // then consider this an unexpected error and abort. - return err - } - // Here, untar detected the breakout. - // Let's move on verifying that indeed there was no breakout. - fmt.Printf("breakoutError: %v\n", err) - } - - // Check victim folder - f, err := os.Open(victim) - if err != nil { - // codepath taken if victim folder was removed - return fmt.Errorf("archive breakout: error reading %q: %v", victim, err) - } - defer f.Close() - - // Check contents of victim folder - // - // We are only interested in getting 2 files from the victim folder, because if all is well - // we expect only one result, the `hello` file. If there is a second result, it cannot - // hold the same name `hello` and we assume that a new file got created in the victim folder. - // That is enough to detect an archive breakout. - names, err := f.Readdirnames(2) - if err != nil { - // codepath taken if victim is not a folder - return fmt.Errorf("archive breakout: error reading directory content of %q: %v", victim, err) - } - for _, name := range names { - if name != "hello" { - // codepath taken if new file was created in victim folder - return fmt.Errorf("archive breakout: new file %q", name) - } - } - - // Check victim/hello - f, err = os.Open(hello) - if err != nil { - // codepath taken if read permissions were removed - return fmt.Errorf("archive breakout: could not lstat %q: %v", hello, err) - } - defer f.Close() - b, err := ioutil.ReadAll(f) - if err != nil { - return err - } - fi, err := f.Stat() - if err != nil { - return err - } - if helloStat.IsDir() != fi.IsDir() || - // TODO: cannot check for fi.ModTime() change - helloStat.Mode() != fi.Mode() || - helloStat.Size() != fi.Size() || - !bytes.Equal(helloData, b) { - // codepath taken if hello has been modified - return fmt.Errorf("archive breakout: file %q has been modified. Contents: expected=%q, got=%q. FileInfo: expected=%#v, got=%#v", hello, helloData, b, helloStat, fi) - } - - // Check that nothing in dest/ has the same content as victim/hello. - // Since victim/hello was generated with time.Now(), it is safe to assume - // that any file whose content matches exactly victim/hello, managed somehow - // to access victim/hello. - return filepath.Walk(dest, func(path string, info os.FileInfo, err error) error { - if info.IsDir() { - if err != nil { - // skip directory if error - return filepath.SkipDir - } - // enter directory - return nil - } - if err != nil { - // skip file if error - return nil - } - b, err := ioutil.ReadFile(path) - if err != nil { - // Houston, we have a problem. Aborting (space)walk. - return err - } - if bytes.Equal(helloData, b) { - return fmt.Errorf("archive breakout: file %q has been accessed via %q", hello, path) - } - return nil - }) -} diff --git a/vendor/github.com/docker/docker/pkg/archive/whiteouts.go b/vendor/github.com/docker/docker/pkg/archive/whiteouts.go deleted file mode 100644 index d20478a..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/whiteouts.go +++ /dev/null @@ -1,23 +0,0 @@ -package archive - -// Whiteouts are files with a special meaning for the layered filesystem. -// Docker uses AUFS whiteout files inside exported archives. In other -// filesystems these files are generated/handled on tar creation/extraction. - -// WhiteoutPrefix prefix means file is a whiteout. If this is followed by a -// filename this means that file has been removed from the base layer. -const WhiteoutPrefix = ".wh." - -// WhiteoutMetaPrefix prefix means whiteout has a special meaning and is not -// for removing an actual file. Normally these files are excluded from exported -// archives. -const WhiteoutMetaPrefix = WhiteoutPrefix + WhiteoutPrefix - -// WhiteoutLinkDir is a directory AUFS uses for storing hardlink links to other -// layers. Normally these should not go into exported archives and all changed -// hardlinks should be copied to the top layer. -const WhiteoutLinkDir = WhiteoutMetaPrefix + "plnk" - -// WhiteoutOpaqueDir file means directory has been made opaque - meaning -// readdir calls to this directory do not follow to lower layers. -const WhiteoutOpaqueDir = WhiteoutMetaPrefix + ".opq" diff --git a/vendor/github.com/docker/docker/pkg/archive/wrap.go b/vendor/github.com/docker/docker/pkg/archive/wrap.go deleted file mode 100644 index b39d12c..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/wrap.go +++ /dev/null @@ -1,59 +0,0 @@ -package archive - -import ( - "archive/tar" - "bytes" - "io" -) - -// Generate generates a new archive from the content provided -// as input. -// -// `files` is a sequence of path/content pairs. A new file is -// added to the archive for each pair. -// If the last pair is incomplete, the file is created with an -// empty content. For example: -// -// Generate("foo.txt", "hello world", "emptyfile") -// -// The above call will return an archive with 2 files: -// * ./foo.txt with content "hello world" -// * ./empty with empty content -// -// FIXME: stream content instead of buffering -// FIXME: specify permissions and other archive metadata -func Generate(input ...string) (io.Reader, error) { - files := parseStringPairs(input...) - buf := new(bytes.Buffer) - tw := tar.NewWriter(buf) - for _, file := range files { - name, content := file[0], file[1] - hdr := &tar.Header{ - Name: name, - Size: int64(len(content)), - } - if err := tw.WriteHeader(hdr); err != nil { - return nil, err - } - if _, err := tw.Write([]byte(content)); err != nil { - return nil, err - } - } - if err := tw.Close(); err != nil { - return nil, err - } - return buf, nil -} - -func parseStringPairs(input ...string) (output [][2]string) { - output = make([][2]string, 0, len(input)/2+1) - for i := 0; i < len(input); i += 2 { - var pair [2]string - pair[0] = input[i] - if i+1 < len(input) { - pair[1] = input[i+1] - } - output = append(output, pair) - } - return -} diff --git a/vendor/github.com/docker/docker/pkg/archive/wrap_test.go b/vendor/github.com/docker/docker/pkg/archive/wrap_test.go deleted file mode 100644 index 46ab366..0000000 --- a/vendor/github.com/docker/docker/pkg/archive/wrap_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package archive - -import ( - "archive/tar" - "bytes" - "io" - "testing" -) - -func TestGenerateEmptyFile(t *testing.T) { - archive, err := Generate("emptyFile") - if err != nil { - t.Fatal(err) - } - if archive == nil { - t.Fatal("The generated archive should not be nil.") - } - - expectedFiles := [][]string{ - {"emptyFile", ""}, - } - - tr := tar.NewReader(archive) - actualFiles := make([][]string, 0, 10) - i := 0 - for { - hdr, err := tr.Next() - if err == io.EOF { - break - } - if err != nil { - t.Fatal(err) - } - buf := new(bytes.Buffer) - buf.ReadFrom(tr) - content := buf.String() - actualFiles = append(actualFiles, []string{hdr.Name, content}) - i++ - } - if len(actualFiles) != len(expectedFiles) { - t.Fatalf("Number of expected file %d, got %d.", len(expectedFiles), len(actualFiles)) - } - for i := 0; i < len(expectedFiles); i++ { - actual := actualFiles[i] - expected := expectedFiles[i] - if actual[0] != expected[0] { - t.Fatalf("Expected name '%s', Actual name '%s'", expected[0], actual[0]) - } - if actual[1] != expected[1] { - t.Fatalf("Expected content '%s', Actual content '%s'", expected[1], actual[1]) - } - } -} - -func TestGenerateWithContent(t *testing.T) { - archive, err := Generate("file", "content") - if err != nil { - t.Fatal(err) - } - if archive == nil { - t.Fatal("The generated archive should not be nil.") - } - - expectedFiles := [][]string{ - {"file", "content"}, - } - - tr := tar.NewReader(archive) - actualFiles := make([][]string, 0, 10) - i := 0 - for { - hdr, err := tr.Next() - if err == io.EOF { - break - } - if err != nil { - t.Fatal(err) - } - buf := new(bytes.Buffer) - buf.ReadFrom(tr) - content := buf.String() - actualFiles = append(actualFiles, []string{hdr.Name, content}) - i++ - } - if len(actualFiles) != len(expectedFiles) { - t.Fatalf("Number of expected file %d, got %d.", len(expectedFiles), len(actualFiles)) - } - for i := 0; i < len(expectedFiles); i++ { - actual := actualFiles[i] - expected := expectedFiles[i] - if actual[0] != expected[0] { - t.Fatalf("Expected name '%s', Actual name '%s'", expected[0], actual[0]) - } - if actual[1] != expected[1] { - t.Fatalf("Expected content '%s', Actual content '%s'", expected[1], actual[1]) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/authorization/api.go b/vendor/github.com/docker/docker/pkg/authorization/api.go deleted file mode 100644 index 05c75f1..0000000 --- a/vendor/github.com/docker/docker/pkg/authorization/api.go +++ /dev/null @@ -1,88 +0,0 @@ -package authorization - -import ( - "crypto/x509" - "encoding/json" - "encoding/pem" -) - -const ( - // AuthZApiRequest is the url for daemon request authorization - AuthZApiRequest = "AuthZPlugin.AuthZReq" - - // AuthZApiResponse is the url for daemon response authorization - AuthZApiResponse = "AuthZPlugin.AuthZRes" - - // AuthZApiImplements is the name of the interface all AuthZ plugins implement - AuthZApiImplements = "authz" -) - -// PeerCertificate is a wrapper around x509.Certificate which provides a sane -// enconding/decoding to/from PEM format and JSON. -type PeerCertificate x509.Certificate - -// MarshalJSON returns the JSON encoded pem bytes of a PeerCertificate. -func (pc *PeerCertificate) MarshalJSON() ([]byte, error) { - b := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: pc.Raw}) - return json.Marshal(b) -} - -// UnmarshalJSON populates a new PeerCertificate struct from JSON data. -func (pc *PeerCertificate) UnmarshalJSON(b []byte) error { - var buf []byte - if err := json.Unmarshal(b, &buf); err != nil { - return err - } - derBytes, _ := pem.Decode(buf) - c, err := x509.ParseCertificate(derBytes.Bytes) - if err != nil { - return err - } - *pc = PeerCertificate(*c) - return nil -} - -// Request holds data required for authZ plugins -type Request struct { - // User holds the user extracted by AuthN mechanism - User string `json:"User,omitempty"` - - // UserAuthNMethod holds the mechanism used to extract user details (e.g., krb) - UserAuthNMethod string `json:"UserAuthNMethod,omitempty"` - - // RequestMethod holds the HTTP method (GET/POST/PUT) - RequestMethod string `json:"RequestMethod,omitempty"` - - // RequestUri holds the full HTTP uri (e.g., /v1.21/version) - RequestURI string `json:"RequestUri,omitempty"` - - // RequestBody stores the raw request body sent to the docker daemon - RequestBody []byte `json:"RequestBody,omitempty"` - - // RequestHeaders stores the raw request headers sent to the docker daemon - RequestHeaders map[string]string `json:"RequestHeaders,omitempty"` - - // RequestPeerCertificates stores the request's TLS peer certificates in PEM format - RequestPeerCertificates []*PeerCertificate `json:"RequestPeerCertificates,omitempty"` - - // ResponseStatusCode stores the status code returned from docker daemon - ResponseStatusCode int `json:"ResponseStatusCode,omitempty"` - - // ResponseBody stores the raw response body sent from docker daemon - ResponseBody []byte `json:"ResponseBody,omitempty"` - - // ResponseHeaders stores the response headers sent to the docker daemon - ResponseHeaders map[string]string `json:"ResponseHeaders,omitempty"` -} - -// Response represents authZ plugin response -type Response struct { - // Allow indicating whether the user is allowed or not - Allow bool `json:"Allow"` - - // Msg stores the authorization message - Msg string `json:"Msg,omitempty"` - - // Err stores a message in case there's an error - Err string `json:"Err,omitempty"` -} diff --git a/vendor/github.com/docker/docker/pkg/authorization/authz.go b/vendor/github.com/docker/docker/pkg/authorization/authz.go deleted file mode 100644 index dc9a9ae..0000000 --- a/vendor/github.com/docker/docker/pkg/authorization/authz.go +++ /dev/null @@ -1,186 +0,0 @@ -package authorization - -import ( - "bufio" - "bytes" - "fmt" - "io" - "net/http" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/ioutils" -) - -const maxBodySize = 1048576 // 1MB - -// NewCtx creates new authZ context, it is used to store authorization information related to a specific docker -// REST http session -// A context provides two method: -// Authenticate Request: -// Call authZ plugins with current REST request and AuthN response -// Request contains full HTTP packet sent to the docker daemon -// https://docs.docker.com/engine/reference/api/ -// -// Authenticate Response: -// Call authZ plugins with full info about current REST request, REST response and AuthN response -// The response from this method may contains content that overrides the daemon response -// This allows authZ plugins to filter privileged content -// -// If multiple authZ plugins are specified, the block/allow decision is based on ANDing all plugin results -// For response manipulation, the response from each plugin is piped between plugins. Plugin execution order -// is determined according to daemon parameters -func NewCtx(authZPlugins []Plugin, user, userAuthNMethod, requestMethod, requestURI string) *Ctx { - return &Ctx{ - plugins: authZPlugins, - user: user, - userAuthNMethod: userAuthNMethod, - requestMethod: requestMethod, - requestURI: requestURI, - } -} - -// Ctx stores a single request-response interaction context -type Ctx struct { - user string - userAuthNMethod string - requestMethod string - requestURI string - plugins []Plugin - // authReq stores the cached request object for the current transaction - authReq *Request -} - -// AuthZRequest authorized the request to the docker daemon using authZ plugins -func (ctx *Ctx) AuthZRequest(w http.ResponseWriter, r *http.Request) error { - var body []byte - if sendBody(ctx.requestURI, r.Header) && r.ContentLength > 0 && r.ContentLength < maxBodySize { - var err error - body, r.Body, err = drainBody(r.Body) - if err != nil { - return err - } - } - - var h bytes.Buffer - if err := r.Header.Write(&h); err != nil { - return err - } - - ctx.authReq = &Request{ - User: ctx.user, - UserAuthNMethod: ctx.userAuthNMethod, - RequestMethod: ctx.requestMethod, - RequestURI: ctx.requestURI, - RequestBody: body, - RequestHeaders: headers(r.Header), - } - - if r.TLS != nil { - for _, c := range r.TLS.PeerCertificates { - pc := PeerCertificate(*c) - ctx.authReq.RequestPeerCertificates = append(ctx.authReq.RequestPeerCertificates, &pc) - } - } - - for _, plugin := range ctx.plugins { - logrus.Debugf("AuthZ request using plugin %s", plugin.Name()) - - authRes, err := plugin.AuthZRequest(ctx.authReq) - if err != nil { - return fmt.Errorf("plugin %s failed with error: %s", plugin.Name(), err) - } - - if !authRes.Allow { - return newAuthorizationError(plugin.Name(), authRes.Msg) - } - } - - return nil -} - -// AuthZResponse authorized and manipulates the response from docker daemon using authZ plugins -func (ctx *Ctx) AuthZResponse(rm ResponseModifier, r *http.Request) error { - ctx.authReq.ResponseStatusCode = rm.StatusCode() - ctx.authReq.ResponseHeaders = headers(rm.Header()) - - if sendBody(ctx.requestURI, rm.Header()) { - ctx.authReq.ResponseBody = rm.RawBody() - } - - for _, plugin := range ctx.plugins { - logrus.Debugf("AuthZ response using plugin %s", plugin.Name()) - - authRes, err := plugin.AuthZResponse(ctx.authReq) - if err != nil { - return fmt.Errorf("plugin %s failed with error: %s", plugin.Name(), err) - } - - if !authRes.Allow { - return newAuthorizationError(plugin.Name(), authRes.Msg) - } - } - - rm.FlushAll() - - return nil -} - -// drainBody dump the body (if its length is less than 1MB) without modifying the request state -func drainBody(body io.ReadCloser) ([]byte, io.ReadCloser, error) { - bufReader := bufio.NewReaderSize(body, maxBodySize) - newBody := ioutils.NewReadCloserWrapper(bufReader, func() error { return body.Close() }) - - data, err := bufReader.Peek(maxBodySize) - // Body size exceeds max body size - if err == nil { - logrus.Warnf("Request body is larger than: '%d' skipping body", maxBodySize) - return nil, newBody, nil - } - // Body size is less than maximum size - if err == io.EOF { - return data, newBody, nil - } - // Unknown error - return nil, newBody, err -} - -// sendBody returns true when request/response body should be sent to AuthZPlugin -func sendBody(url string, header http.Header) bool { - // Skip body for auth endpoint - if strings.HasSuffix(url, "/auth") { - return false - } - - // body is sent only for text or json messages - return header.Get("Content-Type") == "application/json" -} - -// headers returns flatten version of the http headers excluding authorization -func headers(header http.Header) map[string]string { - v := make(map[string]string, 0) - for k, values := range header { - // Skip authorization headers - if strings.EqualFold(k, "Authorization") || strings.EqualFold(k, "X-Registry-Config") || strings.EqualFold(k, "X-Registry-Auth") { - continue - } - for _, val := range values { - v[k] = val - } - } - return v -} - -// authorizationError represents an authorization deny error -type authorizationError struct { - error -} - -// HTTPErrorStatusCode returns the authorization error status code (forbidden) -func (e authorizationError) HTTPErrorStatusCode() int { - return http.StatusForbidden -} - -func newAuthorizationError(plugin, msg string) authorizationError { - return authorizationError{error: fmt.Errorf("authorization denied by plugin %s: %s", plugin, msg)} -} diff --git a/vendor/github.com/docker/docker/pkg/authorization/authz_unix_test.go b/vendor/github.com/docker/docker/pkg/authorization/authz_unix_test.go deleted file mode 100644 index a787f3c..0000000 --- a/vendor/github.com/docker/docker/pkg/authorization/authz_unix_test.go +++ /dev/null @@ -1,282 +0,0 @@ -// +build !windows - -// TODO Windows: This uses a Unix socket for testing. This might be possible -// to port to Windows using a named pipe instead. - -package authorization - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net" - "net/http" - "net/http/httptest" - "os" - "path" - "reflect" - "strings" - "testing" - - "github.com/docker/docker/pkg/plugins" - "github.com/docker/go-connections/tlsconfig" - "github.com/gorilla/mux" -) - -const ( - pluginAddress = "authz-test-plugin.sock" -) - -func TestAuthZRequestPluginError(t *testing.T) { - server := authZPluginTestServer{t: t} - server.start() - defer server.stop() - - authZPlugin := createTestPlugin(t) - - request := Request{ - User: "user", - RequestBody: []byte("sample body"), - RequestURI: "www.authz.com/auth", - RequestMethod: "GET", - RequestHeaders: map[string]string{"header": "value"}, - } - server.replayResponse = Response{ - Err: "an error", - } - - actualResponse, err := authZPlugin.AuthZRequest(&request) - if err != nil { - t.Fatalf("Failed to authorize request %v", err) - } - - if !reflect.DeepEqual(server.replayResponse, *actualResponse) { - t.Fatal("Response must be equal") - } - if !reflect.DeepEqual(request, server.recordedRequest) { - t.Fatal("Requests must be equal") - } -} - -func TestAuthZRequestPlugin(t *testing.T) { - server := authZPluginTestServer{t: t} - server.start() - defer server.stop() - - authZPlugin := createTestPlugin(t) - - request := Request{ - User: "user", - RequestBody: []byte("sample body"), - RequestURI: "www.authz.com/auth", - RequestMethod: "GET", - RequestHeaders: map[string]string{"header": "value"}, - } - server.replayResponse = Response{ - Allow: true, - Msg: "Sample message", - } - - actualResponse, err := authZPlugin.AuthZRequest(&request) - if err != nil { - t.Fatalf("Failed to authorize request %v", err) - } - - if !reflect.DeepEqual(server.replayResponse, *actualResponse) { - t.Fatal("Response must be equal") - } - if !reflect.DeepEqual(request, server.recordedRequest) { - t.Fatal("Requests must be equal") - } -} - -func TestAuthZResponsePlugin(t *testing.T) { - server := authZPluginTestServer{t: t} - server.start() - defer server.stop() - - authZPlugin := createTestPlugin(t) - - request := Request{ - User: "user", - RequestURI: "someting.com/auth", - RequestBody: []byte("sample body"), - } - server.replayResponse = Response{ - Allow: true, - Msg: "Sample message", - } - - actualResponse, err := authZPlugin.AuthZResponse(&request) - if err != nil { - t.Fatalf("Failed to authorize request %v", err) - } - - if !reflect.DeepEqual(server.replayResponse, *actualResponse) { - t.Fatal("Response must be equal") - } - if !reflect.DeepEqual(request, server.recordedRequest) { - t.Fatal("Requests must be equal") - } -} - -func TestResponseModifier(t *testing.T) { - r := httptest.NewRecorder() - m := NewResponseModifier(r) - m.Header().Set("h1", "v1") - m.Write([]byte("body")) - m.WriteHeader(http.StatusInternalServerError) - - m.FlushAll() - if r.Header().Get("h1") != "v1" { - t.Fatalf("Header value must exists %s", r.Header().Get("h1")) - } - if !reflect.DeepEqual(r.Body.Bytes(), []byte("body")) { - t.Fatalf("Body value must exists %s", r.Body.Bytes()) - } - if r.Code != http.StatusInternalServerError { - t.Fatalf("Status code must be correct %d", r.Code) - } -} - -func TestDrainBody(t *testing.T) { - tests := []struct { - length int // length is the message length send to drainBody - expectedBodyLength int // expectedBodyLength is the expected body length after drainBody is called - }{ - {10, 10}, // Small message size - {maxBodySize - 1, maxBodySize - 1}, // Max message size - {maxBodySize * 2, 0}, // Large message size (skip copying body) - - } - - for _, test := range tests { - msg := strings.Repeat("a", test.length) - body, closer, err := drainBody(ioutil.NopCloser(bytes.NewReader([]byte(msg)))) - if err != nil { - t.Fatal(err) - } - if len(body) != test.expectedBodyLength { - t.Fatalf("Body must be copied, actual length: '%d'", len(body)) - } - if closer == nil { - t.Fatal("Closer must not be nil") - } - modified, err := ioutil.ReadAll(closer) - if err != nil { - t.Fatalf("Error must not be nil: '%v'", err) - } - if len(modified) != len(msg) { - t.Fatalf("Result should not be truncated. Original length: '%d', new length: '%d'", len(msg), len(modified)) - } - } -} - -func TestResponseModifierOverride(t *testing.T) { - r := httptest.NewRecorder() - m := NewResponseModifier(r) - m.Header().Set("h1", "v1") - m.Write([]byte("body")) - m.WriteHeader(http.StatusInternalServerError) - - overrideHeader := make(http.Header) - overrideHeader.Add("h1", "v2") - overrideHeaderBytes, err := json.Marshal(overrideHeader) - if err != nil { - t.Fatalf("override header failed %v", err) - } - - m.OverrideHeader(overrideHeaderBytes) - m.OverrideBody([]byte("override body")) - m.OverrideStatusCode(http.StatusNotFound) - m.FlushAll() - if r.Header().Get("h1") != "v2" { - t.Fatalf("Header value must exists %s", r.Header().Get("h1")) - } - if !reflect.DeepEqual(r.Body.Bytes(), []byte("override body")) { - t.Fatalf("Body value must exists %s", r.Body.Bytes()) - } - if r.Code != http.StatusNotFound { - t.Fatalf("Status code must be correct %d", r.Code) - } -} - -// createTestPlugin creates a new sample authorization plugin -func createTestPlugin(t *testing.T) *authorizationPlugin { - pwd, err := os.Getwd() - if err != nil { - t.Fatal(err) - } - - client, err := plugins.NewClient("unix:///"+path.Join(pwd, pluginAddress), &tlsconfig.Options{InsecureSkipVerify: true}) - if err != nil { - t.Fatalf("Failed to create client %v", err) - } - - return &authorizationPlugin{name: "plugin", plugin: client} -} - -// AuthZPluginTestServer is a simple server that implements the authZ plugin interface -type authZPluginTestServer struct { - listener net.Listener - t *testing.T - // request stores the request sent from the daemon to the plugin - recordedRequest Request - // response stores the response sent from the plugin to the daemon - replayResponse Response - server *httptest.Server -} - -// start starts the test server that implements the plugin -func (t *authZPluginTestServer) start() { - r := mux.NewRouter() - l, err := net.Listen("unix", pluginAddress) - if err != nil { - t.t.Fatal(err) - } - t.listener = l - r.HandleFunc("/Plugin.Activate", t.activate) - r.HandleFunc("/"+AuthZApiRequest, t.auth) - r.HandleFunc("/"+AuthZApiResponse, t.auth) - t.server = &httptest.Server{ - Listener: l, - Config: &http.Server{ - Handler: r, - Addr: pluginAddress, - }, - } - t.server.Start() -} - -// stop stops the test server that implements the plugin -func (t *authZPluginTestServer) stop() { - t.server.Close() - os.Remove(pluginAddress) - if t.listener != nil { - t.listener.Close() - } -} - -// auth is a used to record/replay the authentication api messages -func (t *authZPluginTestServer) auth(w http.ResponseWriter, r *http.Request) { - t.recordedRequest = Request{} - body, err := ioutil.ReadAll(r.Body) - if err != nil { - t.t.Fatal(err) - } - r.Body.Close() - json.Unmarshal(body, &t.recordedRequest) - b, err := json.Marshal(t.replayResponse) - if err != nil { - t.t.Fatal(err) - } - w.Write(b) -} - -func (t *authZPluginTestServer) activate(w http.ResponseWriter, r *http.Request) { - b, err := json.Marshal(plugins.Manifest{Implements: []string{AuthZApiImplements}}) - if err != nil { - t.t.Fatal(err) - } - w.Write(b) -} diff --git a/vendor/github.com/docker/docker/pkg/authorization/middleware.go b/vendor/github.com/docker/docker/pkg/authorization/middleware.go deleted file mode 100644 index 52890dd..0000000 --- a/vendor/github.com/docker/docker/pkg/authorization/middleware.go +++ /dev/null @@ -1,84 +0,0 @@ -package authorization - -import ( - "net/http" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/plugingetter" - "golang.org/x/net/context" -) - -// Middleware uses a list of plugins to -// handle authorization in the API requests. -type Middleware struct { - mu sync.Mutex - plugins []Plugin -} - -// NewMiddleware creates a new Middleware -// with a slice of plugins names. -func NewMiddleware(names []string, pg plugingetter.PluginGetter) *Middleware { - SetPluginGetter(pg) - return &Middleware{ - plugins: newPlugins(names), - } -} - -// SetPlugins sets the plugin used for authorization -func (m *Middleware) SetPlugins(names []string) { - m.mu.Lock() - m.plugins = newPlugins(names) - m.mu.Unlock() -} - -// WrapHandler returns a new handler function wrapping the previous one in the request chain. -func (m *Middleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - - m.mu.Lock() - plugins := m.plugins - m.mu.Unlock() - if len(plugins) == 0 { - return handler(ctx, w, r, vars) - } - - user := "" - userAuthNMethod := "" - - // Default authorization using existing TLS connection credentials - // FIXME: Non trivial authorization mechanisms (such as advanced certificate validations, kerberos support - // and ldap) will be extracted using AuthN feature, which is tracked under: - // https://github.com/docker/docker/pull/20883 - if r.TLS != nil && len(r.TLS.PeerCertificates) > 0 { - user = r.TLS.PeerCertificates[0].Subject.CommonName - userAuthNMethod = "TLS" - } - - authCtx := NewCtx(plugins, user, userAuthNMethod, r.Method, r.RequestURI) - - if err := authCtx.AuthZRequest(w, r); err != nil { - logrus.Errorf("AuthZRequest for %s %s returned error: %s", r.Method, r.RequestURI, err) - return err - } - - rw := NewResponseModifier(w) - - var errD error - - if errD = handler(ctx, rw, r, vars); errD != nil { - logrus.Errorf("Handler for %s %s returned error: %s", r.Method, r.RequestURI, errD) - } - - if err := authCtx.AuthZResponse(rw, r); errD == nil && err != nil { - logrus.Errorf("AuthZResponse for %s %s returned error: %s", r.Method, r.RequestURI, err) - return err - } - - if errD != nil { - return errD - } - - return nil - } -} diff --git a/vendor/github.com/docker/docker/pkg/authorization/plugin.go b/vendor/github.com/docker/docker/pkg/authorization/plugin.go deleted file mode 100644 index 4b1c71b..0000000 --- a/vendor/github.com/docker/docker/pkg/authorization/plugin.go +++ /dev/null @@ -1,112 +0,0 @@ -package authorization - -import ( - "sync" - - "github.com/docker/docker/pkg/plugingetter" - "github.com/docker/docker/pkg/plugins" -) - -// Plugin allows third party plugins to authorize requests and responses -// in the context of docker API -type Plugin interface { - // Name returns the registered plugin name - Name() string - - // AuthZRequest authorizes the request from the client to the daemon - AuthZRequest(*Request) (*Response, error) - - // AuthZResponse authorizes the response from the daemon to the client - AuthZResponse(*Request) (*Response, error) -} - -// newPlugins constructs and initializes the authorization plugins based on plugin names -func newPlugins(names []string) []Plugin { - plugins := []Plugin{} - pluginsMap := make(map[string]struct{}) - for _, name := range names { - if _, ok := pluginsMap[name]; ok { - continue - } - pluginsMap[name] = struct{}{} - plugins = append(plugins, newAuthorizationPlugin(name)) - } - return plugins -} - -var getter plugingetter.PluginGetter - -// SetPluginGetter sets the plugingetter -func SetPluginGetter(pg plugingetter.PluginGetter) { - getter = pg -} - -// GetPluginGetter gets the plugingetter -func GetPluginGetter() plugingetter.PluginGetter { - return getter -} - -// authorizationPlugin is an internal adapter to docker plugin system -type authorizationPlugin struct { - plugin *plugins.Client - name string - once sync.Once -} - -func newAuthorizationPlugin(name string) Plugin { - return &authorizationPlugin{name: name} -} - -func (a *authorizationPlugin) Name() string { - return a.name -} - -func (a *authorizationPlugin) AuthZRequest(authReq *Request) (*Response, error) { - if err := a.initPlugin(); err != nil { - return nil, err - } - - authRes := &Response{} - if err := a.plugin.Call(AuthZApiRequest, authReq, authRes); err != nil { - return nil, err - } - - return authRes, nil -} - -func (a *authorizationPlugin) AuthZResponse(authReq *Request) (*Response, error) { - if err := a.initPlugin(); err != nil { - return nil, err - } - - authRes := &Response{} - if err := a.plugin.Call(AuthZApiResponse, authReq, authRes); err != nil { - return nil, err - } - - return authRes, nil -} - -// initPlugin initializes the authorization plugin if needed -func (a *authorizationPlugin) initPlugin() error { - // Lazy loading of plugins - var err error - a.once.Do(func() { - if a.plugin == nil { - var plugin plugingetter.CompatPlugin - var e error - - if pg := GetPluginGetter(); pg != nil { - plugin, e = pg.Get(a.name, AuthZApiImplements, plugingetter.LOOKUP) - } else { - plugin, e = plugins.Get(a.name, AuthZApiImplements) - } - if e != nil { - err = e - return - } - a.plugin = plugin.Client() - } - }) - return err -} diff --git a/vendor/github.com/docker/docker/pkg/authorization/response.go b/vendor/github.com/docker/docker/pkg/authorization/response.go deleted file mode 100644 index 129bf2f..0000000 --- a/vendor/github.com/docker/docker/pkg/authorization/response.go +++ /dev/null @@ -1,203 +0,0 @@ -package authorization - -import ( - "bufio" - "bytes" - "encoding/json" - "fmt" - "net" - "net/http" - - "github.com/Sirupsen/logrus" -) - -// ResponseModifier allows authorization plugins to read and modify the content of the http.response -type ResponseModifier interface { - http.ResponseWriter - http.Flusher - http.CloseNotifier - - // RawBody returns the current http content - RawBody() []byte - - // RawHeaders returns the current content of the http headers - RawHeaders() ([]byte, error) - - // StatusCode returns the current status code - StatusCode() int - - // OverrideBody replaces the body of the HTTP reply - OverrideBody(b []byte) - - // OverrideHeader replaces the headers of the HTTP reply - OverrideHeader(b []byte) error - - // OverrideStatusCode replaces the status code of the HTTP reply - OverrideStatusCode(statusCode int) - - // FlushAll flushes all data to the HTTP response - FlushAll() error - - // Hijacked indicates the response has been hijacked by the Docker daemon - Hijacked() bool -} - -// NewResponseModifier creates a wrapper to an http.ResponseWriter to allow inspecting and modifying the content -func NewResponseModifier(rw http.ResponseWriter) ResponseModifier { - return &responseModifier{rw: rw, header: make(http.Header)} -} - -// responseModifier is used as an adapter to http.ResponseWriter in order to manipulate and explore -// the http request/response from docker daemon -type responseModifier struct { - // The original response writer - rw http.ResponseWriter - // body holds the response body - body []byte - // header holds the response header - header http.Header - // statusCode holds the response status code - statusCode int - // hijacked indicates the request has been hijacked - hijacked bool -} - -func (rm *responseModifier) Hijacked() bool { - return rm.hijacked -} - -// WriterHeader stores the http status code -func (rm *responseModifier) WriteHeader(s int) { - - // Use original request if hijacked - if rm.hijacked { - rm.rw.WriteHeader(s) - return - } - - rm.statusCode = s -} - -// Header returns the internal http header -func (rm *responseModifier) Header() http.Header { - - // Use original header if hijacked - if rm.hijacked { - return rm.rw.Header() - } - - return rm.header -} - -// StatusCode returns the http status code -func (rm *responseModifier) StatusCode() int { - return rm.statusCode -} - -// OverrideBody replaces the body of the HTTP response -func (rm *responseModifier) OverrideBody(b []byte) { - rm.body = b -} - -// OverrideStatusCode replaces the status code of the HTTP response -func (rm *responseModifier) OverrideStatusCode(statusCode int) { - rm.statusCode = statusCode -} - -// OverrideHeader replaces the headers of the HTTP response -func (rm *responseModifier) OverrideHeader(b []byte) error { - header := http.Header{} - if err := json.Unmarshal(b, &header); err != nil { - return err - } - rm.header = header - return nil -} - -// Write stores the byte array inside content -func (rm *responseModifier) Write(b []byte) (int, error) { - - if rm.hijacked { - return rm.rw.Write(b) - } - - rm.body = append(rm.body, b...) - return len(b), nil -} - -// Body returns the response body -func (rm *responseModifier) RawBody() []byte { - return rm.body -} - -func (rm *responseModifier) RawHeaders() ([]byte, error) { - var b bytes.Buffer - if err := rm.header.Write(&b); err != nil { - return nil, err - } - return b.Bytes(), nil -} - -// Hijack returns the internal connection of the wrapped http.ResponseWriter -func (rm *responseModifier) Hijack() (net.Conn, *bufio.ReadWriter, error) { - - rm.hijacked = true - rm.FlushAll() - - hijacker, ok := rm.rw.(http.Hijacker) - if !ok { - return nil, nil, fmt.Errorf("Internal response writer doesn't support the Hijacker interface") - } - return hijacker.Hijack() -} - -// CloseNotify uses the internal close notify API of the wrapped http.ResponseWriter -func (rm *responseModifier) CloseNotify() <-chan bool { - closeNotifier, ok := rm.rw.(http.CloseNotifier) - if !ok { - logrus.Error("Internal response writer doesn't support the CloseNotifier interface") - return nil - } - return closeNotifier.CloseNotify() -} - -// Flush uses the internal flush API of the wrapped http.ResponseWriter -func (rm *responseModifier) Flush() { - flusher, ok := rm.rw.(http.Flusher) - if !ok { - logrus.Error("Internal response writer doesn't support the Flusher interface") - return - } - - rm.FlushAll() - flusher.Flush() -} - -// FlushAll flushes all data to the HTTP response -func (rm *responseModifier) FlushAll() error { - // Copy the header - for k, vv := range rm.header { - for _, v := range vv { - rm.rw.Header().Add(k, v) - } - } - - // Copy the status code - // Also WriteHeader needs to be done after all the headers - // have been copied (above). - if rm.statusCode > 0 { - rm.rw.WriteHeader(rm.statusCode) - } - - var err error - if len(rm.body) > 0 { - // Write body - _, err = rm.rw.Write(rm.body) - } - - // Clean previous data - rm.body = nil - rm.statusCode = 0 - rm.header = http.Header{} - return err -} diff --git a/vendor/github.com/docker/docker/pkg/broadcaster/unbuffered.go b/vendor/github.com/docker/docker/pkg/broadcaster/unbuffered.go deleted file mode 100644 index 784d65d..0000000 --- a/vendor/github.com/docker/docker/pkg/broadcaster/unbuffered.go +++ /dev/null @@ -1,49 +0,0 @@ -package broadcaster - -import ( - "io" - "sync" -) - -// Unbuffered accumulates multiple io.WriteCloser by stream. -type Unbuffered struct { - mu sync.Mutex - writers []io.WriteCloser -} - -// Add adds new io.WriteCloser. -func (w *Unbuffered) Add(writer io.WriteCloser) { - w.mu.Lock() - w.writers = append(w.writers, writer) - w.mu.Unlock() -} - -// Write writes bytes to all writers. Failed writers will be evicted during -// this call. -func (w *Unbuffered) Write(p []byte) (n int, err error) { - w.mu.Lock() - var evict []int - for i, sw := range w.writers { - if n, err := sw.Write(p); err != nil || n != len(p) { - // On error, evict the writer - evict = append(evict, i) - } - } - for n, i := range evict { - w.writers = append(w.writers[:i-n], w.writers[i-n+1:]...) - } - w.mu.Unlock() - return len(p), nil -} - -// Clean closes and removes all writers. Last non-eol-terminated part of data -// will be saved. -func (w *Unbuffered) Clean() error { - w.mu.Lock() - for _, sw := range w.writers { - sw.Close() - } - w.writers = nil - w.mu.Unlock() - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/broadcaster/unbuffered_test.go b/vendor/github.com/docker/docker/pkg/broadcaster/unbuffered_test.go deleted file mode 100644 index 9f8e72b..0000000 --- a/vendor/github.com/docker/docker/pkg/broadcaster/unbuffered_test.go +++ /dev/null @@ -1,162 +0,0 @@ -package broadcaster - -import ( - "bytes" - "errors" - "strings" - - "testing" -) - -type dummyWriter struct { - buffer bytes.Buffer - failOnWrite bool -} - -func (dw *dummyWriter) Write(p []byte) (n int, err error) { - if dw.failOnWrite { - return 0, errors.New("Fake fail") - } - return dw.buffer.Write(p) -} - -func (dw *dummyWriter) String() string { - return dw.buffer.String() -} - -func (dw *dummyWriter) Close() error { - return nil -} - -func TestUnbuffered(t *testing.T) { - writer := new(Unbuffered) - - // Test 1: Both bufferA and bufferB should contain "foo" - bufferA := &dummyWriter{} - writer.Add(bufferA) - bufferB := &dummyWriter{} - writer.Add(bufferB) - writer.Write([]byte("foo")) - - if bufferA.String() != "foo" { - t.Errorf("Buffer contains %v", bufferA.String()) - } - - if bufferB.String() != "foo" { - t.Errorf("Buffer contains %v", bufferB.String()) - } - - // Test2: bufferA and bufferB should contain "foobar", - // while bufferC should only contain "bar" - bufferC := &dummyWriter{} - writer.Add(bufferC) - writer.Write([]byte("bar")) - - if bufferA.String() != "foobar" { - t.Errorf("Buffer contains %v", bufferA.String()) - } - - if bufferB.String() != "foobar" { - t.Errorf("Buffer contains %v", bufferB.String()) - } - - if bufferC.String() != "bar" { - t.Errorf("Buffer contains %v", bufferC.String()) - } - - // Test3: Test eviction on failure - bufferA.failOnWrite = true - writer.Write([]byte("fail")) - if bufferA.String() != "foobar" { - t.Errorf("Buffer contains %v", bufferA.String()) - } - if bufferC.String() != "barfail" { - t.Errorf("Buffer contains %v", bufferC.String()) - } - // Even though we reset the flag, no more writes should go in there - bufferA.failOnWrite = false - writer.Write([]byte("test")) - if bufferA.String() != "foobar" { - t.Errorf("Buffer contains %v", bufferA.String()) - } - if bufferC.String() != "barfailtest" { - t.Errorf("Buffer contains %v", bufferC.String()) - } - - // Test4: Test eviction on multiple simultaneous failures - bufferB.failOnWrite = true - bufferC.failOnWrite = true - bufferD := &dummyWriter{} - writer.Add(bufferD) - writer.Write([]byte("yo")) - writer.Write([]byte("ink")) - if strings.Contains(bufferB.String(), "yoink") { - t.Errorf("bufferB received write. contents: %q", bufferB) - } - if strings.Contains(bufferC.String(), "yoink") { - t.Errorf("bufferC received write. contents: %q", bufferC) - } - if g, w := bufferD.String(), "yoink"; g != w { - t.Errorf("bufferD = %q, want %q", g, w) - } - - writer.Clean() -} - -type devNullCloser int - -func (d devNullCloser) Close() error { - return nil -} - -func (d devNullCloser) Write(buf []byte) (int, error) { - return len(buf), nil -} - -// This test checks for races. It is only useful when run with the race detector. -func TestRaceUnbuffered(t *testing.T) { - writer := new(Unbuffered) - c := make(chan bool) - go func() { - writer.Add(devNullCloser(0)) - c <- true - }() - writer.Write([]byte("hello")) - <-c -} - -func BenchmarkUnbuffered(b *testing.B) { - writer := new(Unbuffered) - setUpWriter := func() { - for i := 0; i < 100; i++ { - writer.Add(devNullCloser(0)) - writer.Add(devNullCloser(0)) - writer.Add(devNullCloser(0)) - } - } - testLine := "Line that thinks that it is log line from docker" - var buf bytes.Buffer - for i := 0; i < 100; i++ { - buf.Write([]byte(testLine + "\n")) - } - // line without eol - buf.Write([]byte(testLine)) - testText := buf.Bytes() - b.SetBytes(int64(5 * len(testText))) - b.ResetTimer() - for i := 0; i < b.N; i++ { - b.StopTimer() - setUpWriter() - b.StartTimer() - - for j := 0; j < 5; j++ { - if _, err := writer.Write(testText); err != nil { - b.Fatal(err) - } - } - - b.StopTimer() - writer.Clean() - b.StartTimer() - } -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/archive.go b/vendor/github.com/docker/docker/pkg/chrootarchive/archive.go deleted file mode 100644 index a7814f5..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/archive.go +++ /dev/null @@ -1,97 +0,0 @@ -package chrootarchive - -import ( - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/idtools" -) - -var chrootArchiver = &archive.Archiver{Untar: Untar} - -// Untar reads a stream of bytes from `archive`, parses it as a tar archive, -// and unpacks it into the directory at `dest`. -// The archive may be compressed with one of the following algorithms: -// identity (uncompressed), gzip, bzip2, xz. -func Untar(tarArchive io.Reader, dest string, options *archive.TarOptions) error { - return untarHandler(tarArchive, dest, options, true) -} - -// UntarUncompressed reads a stream of bytes from `archive`, parses it as a tar archive, -// and unpacks it into the directory at `dest`. -// The archive must be an uncompressed stream. -func UntarUncompressed(tarArchive io.Reader, dest string, options *archive.TarOptions) error { - return untarHandler(tarArchive, dest, options, false) -} - -// Handler for teasing out the automatic decompression -func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions, decompress bool) error { - - if tarArchive == nil { - return fmt.Errorf("Empty archive") - } - if options == nil { - options = &archive.TarOptions{} - } - if options.ExcludePatterns == nil { - options.ExcludePatterns = []string{} - } - - rootUID, rootGID, err := idtools.GetRootUIDGID(options.UIDMaps, options.GIDMaps) - if err != nil { - return err - } - - dest = filepath.Clean(dest) - if _, err := os.Stat(dest); os.IsNotExist(err) { - if err := idtools.MkdirAllNewAs(dest, 0755, rootUID, rootGID); err != nil { - return err - } - } - - r := ioutil.NopCloser(tarArchive) - if decompress { - decompressedArchive, err := archive.DecompressStream(tarArchive) - if err != nil { - return err - } - defer decompressedArchive.Close() - r = decompressedArchive - } - - return invokeUnpack(r, dest, options) -} - -// TarUntar is a convenience function which calls Tar and Untar, with the output of one piped into the other. -// If either Tar or Untar fails, TarUntar aborts and returns the error. -func TarUntar(src, dst string) error { - return chrootArchiver.TarUntar(src, dst) -} - -// CopyWithTar creates a tar archive of filesystem path `src`, and -// unpacks it at filesystem path `dst`. -// The archive is streamed directly with fixed buffering and no -// intermediary disk IO. -func CopyWithTar(src, dst string) error { - return chrootArchiver.CopyWithTar(src, dst) -} - -// CopyFileWithTar emulates the behavior of the 'cp' command-line -// for a single file. It copies a regular file from path `src` to -// path `dst`, and preserves all its metadata. -// -// If `dst` ends with a trailing slash '/' ('\' on Windows), the final -// destination path will be `dst/base(src)` or `dst\base(src)` -func CopyFileWithTar(src, dst string) (err error) { - return chrootArchiver.CopyFileWithTar(src, dst) -} - -// UntarPath is a convenience function which looks for an archive -// at filesystem path `src`, and unpacks it at `dst`. -func UntarPath(src, dst string) error { - return chrootArchiver.UntarPath(src, dst) -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/archive_test.go b/vendor/github.com/docker/docker/pkg/chrootarchive/archive_test.go deleted file mode 100644 index d2d7e62..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/archive_test.go +++ /dev/null @@ -1,394 +0,0 @@ -package chrootarchive - -import ( - "bytes" - "fmt" - "hash/crc32" - "io" - "io/ioutil" - "os" - "path/filepath" - "runtime" - "strings" - "testing" - "time" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/reexec" - "github.com/docker/docker/pkg/system" -) - -func init() { - reexec.Init() -} - -func TestChrootTarUntar(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntar") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - src := filepath.Join(tmpdir, "src") - if err := system.MkdirAll(src, 0700); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(src, "toto"), []byte("hello toto"), 0644); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(src, "lolo"), []byte("hello lolo"), 0644); err != nil { - t.Fatal(err) - } - stream, err := archive.Tar(src, archive.Uncompressed) - if err != nil { - t.Fatal(err) - } - dest := filepath.Join(tmpdir, "src") - if err := system.MkdirAll(dest, 0700); err != nil { - t.Fatal(err) - } - if err := Untar(stream, dest, &archive.TarOptions{ExcludePatterns: []string{"lolo"}}); err != nil { - t.Fatal(err) - } -} - -// gh#10426: Verify the fix for having a huge excludes list (like on `docker load` with large # of -// local images) -func TestChrootUntarWithHugeExcludesList(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarHugeExcludes") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - src := filepath.Join(tmpdir, "src") - if err := system.MkdirAll(src, 0700); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(src, "toto"), []byte("hello toto"), 0644); err != nil { - t.Fatal(err) - } - stream, err := archive.Tar(src, archive.Uncompressed) - if err != nil { - t.Fatal(err) - } - dest := filepath.Join(tmpdir, "dest") - if err := system.MkdirAll(dest, 0700); err != nil { - t.Fatal(err) - } - options := &archive.TarOptions{} - //65534 entries of 64-byte strings ~= 4MB of environment space which should overflow - //on most systems when passed via environment or command line arguments - excludes := make([]string, 65534, 65534) - for i := 0; i < 65534; i++ { - excludes[i] = strings.Repeat(string(i), 64) - } - options.ExcludePatterns = excludes - if err := Untar(stream, dest, options); err != nil { - t.Fatal(err) - } -} - -func TestChrootUntarEmptyArchive(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarEmptyArchive") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - if err := Untar(nil, tmpdir, nil); err == nil { - t.Fatal("expected error on empty archive") - } -} - -func prepareSourceDirectory(numberOfFiles int, targetPath string, makeSymLinks bool) (int, error) { - fileData := []byte("fooo") - for n := 0; n < numberOfFiles; n++ { - fileName := fmt.Sprintf("file-%d", n) - if err := ioutil.WriteFile(filepath.Join(targetPath, fileName), fileData, 0700); err != nil { - return 0, err - } - if makeSymLinks { - if err := os.Symlink(filepath.Join(targetPath, fileName), filepath.Join(targetPath, fileName+"-link")); err != nil { - return 0, err - } - } - } - totalSize := numberOfFiles * len(fileData) - return totalSize, nil -} - -func getHash(filename string) (uint32, error) { - stream, err := ioutil.ReadFile(filename) - if err != nil { - return 0, err - } - hash := crc32.NewIEEE() - hash.Write(stream) - return hash.Sum32(), nil -} - -func compareDirectories(src string, dest string) error { - changes, err := archive.ChangesDirs(dest, src) - if err != nil { - return err - } - if len(changes) > 0 { - return fmt.Errorf("Unexpected differences after untar: %v", changes) - } - return nil -} - -func compareFiles(src string, dest string) error { - srcHash, err := getHash(src) - if err != nil { - return err - } - destHash, err := getHash(dest) - if err != nil { - return err - } - if srcHash != destHash { - return fmt.Errorf("%s is different from %s", src, dest) - } - return nil -} - -func TestChrootTarUntarWithSymlink(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntarWithSymlink") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - src := filepath.Join(tmpdir, "src") - if err := system.MkdirAll(src, 0700); err != nil { - t.Fatal(err) - } - if _, err := prepareSourceDirectory(10, src, false); err != nil { - t.Fatal(err) - } - dest := filepath.Join(tmpdir, "dest") - if err := TarUntar(src, dest); err != nil { - t.Fatal(err) - } - if err := compareDirectories(src, dest); err != nil { - t.Fatal(err) - } -} - -func TestChrootCopyWithTar(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" || runtime.GOOS == "solaris" { - t.Skip("Failing on Windows and Solaris") - } - tmpdir, err := ioutil.TempDir("", "docker-TestChrootCopyWithTar") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - src := filepath.Join(tmpdir, "src") - if err := system.MkdirAll(src, 0700); err != nil { - t.Fatal(err) - } - if _, err := prepareSourceDirectory(10, src, true); err != nil { - t.Fatal(err) - } - - // Copy directory - dest := filepath.Join(tmpdir, "dest") - if err := CopyWithTar(src, dest); err != nil { - t.Fatal(err) - } - if err := compareDirectories(src, dest); err != nil { - t.Fatal(err) - } - - // Copy file - srcfile := filepath.Join(src, "file-1") - dest = filepath.Join(tmpdir, "destFile") - destfile := filepath.Join(dest, "file-1") - if err := CopyWithTar(srcfile, destfile); err != nil { - t.Fatal(err) - } - if err := compareFiles(srcfile, destfile); err != nil { - t.Fatal(err) - } - - // Copy symbolic link - srcLinkfile := filepath.Join(src, "file-1-link") - dest = filepath.Join(tmpdir, "destSymlink") - destLinkfile := filepath.Join(dest, "file-1-link") - if err := CopyWithTar(srcLinkfile, destLinkfile); err != nil { - t.Fatal(err) - } - if err := compareFiles(srcLinkfile, destLinkfile); err != nil { - t.Fatal(err) - } -} - -func TestChrootCopyFileWithTar(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "docker-TestChrootCopyFileWithTar") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - src := filepath.Join(tmpdir, "src") - if err := system.MkdirAll(src, 0700); err != nil { - t.Fatal(err) - } - if _, err := prepareSourceDirectory(10, src, true); err != nil { - t.Fatal(err) - } - - // Copy directory - dest := filepath.Join(tmpdir, "dest") - if err := CopyFileWithTar(src, dest); err == nil { - t.Fatal("Expected error on copying directory") - } - - // Copy file - srcfile := filepath.Join(src, "file-1") - dest = filepath.Join(tmpdir, "destFile") - destfile := filepath.Join(dest, "file-1") - if err := CopyFileWithTar(srcfile, destfile); err != nil { - t.Fatal(err) - } - if err := compareFiles(srcfile, destfile); err != nil { - t.Fatal(err) - } - - // Copy symbolic link - srcLinkfile := filepath.Join(src, "file-1-link") - dest = filepath.Join(tmpdir, "destSymlink") - destLinkfile := filepath.Join(dest, "file-1-link") - if err := CopyFileWithTar(srcLinkfile, destLinkfile); err != nil { - t.Fatal(err) - } - if err := compareFiles(srcLinkfile, destLinkfile); err != nil { - t.Fatal(err) - } -} - -func TestChrootUntarPath(t *testing.T) { - // TODO Windows: Figure out why this is failing - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows") - } - tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarPath") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - src := filepath.Join(tmpdir, "src") - if err := system.MkdirAll(src, 0700); err != nil { - t.Fatal(err) - } - if _, err := prepareSourceDirectory(10, src, false); err != nil { - t.Fatal(err) - } - dest := filepath.Join(tmpdir, "dest") - // Untar a directory - if err := UntarPath(src, dest); err == nil { - t.Fatal("Expected error on untaring a directory") - } - - // Untar a tar file - stream, err := archive.Tar(src, archive.Uncompressed) - if err != nil { - t.Fatal(err) - } - buf := new(bytes.Buffer) - buf.ReadFrom(stream) - tarfile := filepath.Join(tmpdir, "src.tar") - if err := ioutil.WriteFile(tarfile, buf.Bytes(), 0644); err != nil { - t.Fatal(err) - } - if err := UntarPath(tarfile, dest); err != nil { - t.Fatal(err) - } - if err := compareDirectories(src, dest); err != nil { - t.Fatal(err) - } -} - -type slowEmptyTarReader struct { - size int - offset int - chunkSize int -} - -// Read is a slow reader of an empty tar (like the output of "tar c --files-from /dev/null") -func (s *slowEmptyTarReader) Read(p []byte) (int, error) { - time.Sleep(100 * time.Millisecond) - count := s.chunkSize - if len(p) < s.chunkSize { - count = len(p) - } - for i := 0; i < count; i++ { - p[i] = 0 - } - s.offset += count - if s.offset > s.size { - return count, io.EOF - } - return count, nil -} - -func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarEmptyArchiveFromSlowReader") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - dest := filepath.Join(tmpdir, "dest") - if err := system.MkdirAll(dest, 0700); err != nil { - t.Fatal(err) - } - stream := &slowEmptyTarReader{size: 10240, chunkSize: 1024} - if err := Untar(stream, dest, nil); err != nil { - t.Fatal(err) - } -} - -func TestChrootApplyEmptyArchiveFromSlowReader(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "docker-TestChrootApplyEmptyArchiveFromSlowReader") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - dest := filepath.Join(tmpdir, "dest") - if err := system.MkdirAll(dest, 0700); err != nil { - t.Fatal(err) - } - stream := &slowEmptyTarReader{size: 10240, chunkSize: 1024} - if _, err := ApplyLayer(dest, stream); err != nil { - t.Fatal(err) - } -} - -func TestChrootApplyDotDotFile(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "docker-TestChrootApplyDotDotFile") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - src := filepath.Join(tmpdir, "src") - if err := system.MkdirAll(src, 0700); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(filepath.Join(src, "..gitme"), []byte(""), 0644); err != nil { - t.Fatal(err) - } - stream, err := archive.Tar(src, archive.Uncompressed) - if err != nil { - t.Fatal(err) - } - dest := filepath.Join(tmpdir, "dest") - if err := system.MkdirAll(dest, 0700); err != nil { - t.Fatal(err) - } - if _, err := ApplyLayer(dest, stream); err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/archive_unix.go b/vendor/github.com/docker/docker/pkg/chrootarchive/archive_unix.go deleted file mode 100644 index f2325ab..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/archive_unix.go +++ /dev/null @@ -1,86 +0,0 @@ -// +build !windows - -package chrootarchive - -import ( - "bytes" - "encoding/json" - "flag" - "fmt" - "io" - "io/ioutil" - "os" - "runtime" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/reexec" -) - -// untar is the entry-point for docker-untar on re-exec. This is not used on -// Windows as it does not support chroot, hence no point sandboxing through -// chroot and rexec. -func untar() { - runtime.LockOSThread() - flag.Parse() - - var options *archive.TarOptions - - //read the options from the pipe "ExtraFiles" - if err := json.NewDecoder(os.NewFile(3, "options")).Decode(&options); err != nil { - fatal(err) - } - - if err := chroot(flag.Arg(0)); err != nil { - fatal(err) - } - - if err := archive.Unpack(os.Stdin, "/", options); err != nil { - fatal(err) - } - // fully consume stdin in case it is zero padded - if _, err := flush(os.Stdin); err != nil { - fatal(err) - } - - os.Exit(0) -} - -func invokeUnpack(decompressedArchive io.Reader, dest string, options *archive.TarOptions) error { - - // We can't pass a potentially large exclude list directly via cmd line - // because we easily overrun the kernel's max argument/environment size - // when the full image list is passed (e.g. when this is used by - // `docker load`). We will marshall the options via a pipe to the - // child - r, w, err := os.Pipe() - if err != nil { - return fmt.Errorf("Untar pipe failure: %v", err) - } - - cmd := reexec.Command("docker-untar", dest) - cmd.Stdin = decompressedArchive - - cmd.ExtraFiles = append(cmd.ExtraFiles, r) - output := bytes.NewBuffer(nil) - cmd.Stdout = output - cmd.Stderr = output - - if err := cmd.Start(); err != nil { - return fmt.Errorf("Untar error on re-exec cmd: %v", err) - } - //write the options to the pipe for the untar exec to read - if err := json.NewEncoder(w).Encode(options); err != nil { - return fmt.Errorf("Untar json encode to pipe failed: %v", err) - } - w.Close() - - if err := cmd.Wait(); err != nil { - // when `xz -d -c -q | docker-untar ...` failed on docker-untar side, - // we need to exhaust `xz`'s output, otherwise the `xz` side will be - // pending on write pipe forever - io.Copy(ioutil.Discard, decompressedArchive) - - return fmt.Errorf("Error processing tar file(%v): %s", err, output) - } - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/archive_windows.go b/vendor/github.com/docker/docker/pkg/chrootarchive/archive_windows.go deleted file mode 100644 index 0a500ed..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/archive_windows.go +++ /dev/null @@ -1,22 +0,0 @@ -package chrootarchive - -import ( - "io" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/longpath" -) - -// chroot is not supported by Windows -func chroot(path string) error { - return nil -} - -func invokeUnpack(decompressedArchive io.ReadCloser, - dest string, - options *archive.TarOptions) error { - // Windows is different to Linux here because Windows does not support - // chroot. Hence there is no point sandboxing a chrooted process to - // do the unpack. We call inline instead within the daemon process. - return archive.Unpack(decompressedArchive, longpath.AddPrefix(dest), options) -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/chroot_linux.go b/vendor/github.com/docker/docker/pkg/chrootarchive/chroot_linux.go deleted file mode 100644 index f9d7fed..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/chroot_linux.go +++ /dev/null @@ -1,108 +0,0 @@ -package chrootarchive - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "syscall" - - "github.com/docker/docker/pkg/mount" - rsystem "github.com/opencontainers/runc/libcontainer/system" -) - -// chroot on linux uses pivot_root instead of chroot -// pivot_root takes a new root and an old root. -// Old root must be a sub-dir of new root, it is where the current rootfs will reside after the call to pivot_root. -// New root is where the new rootfs is set to. -// Old root is removed after the call to pivot_root so it is no longer available under the new root. -// This is similar to how libcontainer sets up a container's rootfs -func chroot(path string) (err error) { - // if the engine is running in a user namespace we need to use actual chroot - if rsystem.RunningInUserNS() { - return realChroot(path) - } - if err := syscall.Unshare(syscall.CLONE_NEWNS); err != nil { - return fmt.Errorf("Error creating mount namespace before pivot: %v", err) - } - - // make everything in new ns private - if err := mount.MakeRPrivate("/"); err != nil { - return err - } - - if mounted, _ := mount.Mounted(path); !mounted { - if err := mount.Mount(path, path, "bind", "rbind,rw"); err != nil { - return realChroot(path) - } - } - - // setup oldRoot for pivot_root - pivotDir, err := ioutil.TempDir(path, ".pivot_root") - if err != nil { - return fmt.Errorf("Error setting up pivot dir: %v", err) - } - - var mounted bool - defer func() { - if mounted { - // make sure pivotDir is not mounted before we try to remove it - if errCleanup := syscall.Unmount(pivotDir, syscall.MNT_DETACH); errCleanup != nil { - if err == nil { - err = errCleanup - } - return - } - } - - errCleanup := os.Remove(pivotDir) - // pivotDir doesn't exist if pivot_root failed and chroot+chdir was successful - // because we already cleaned it up on failed pivot_root - if errCleanup != nil && !os.IsNotExist(errCleanup) { - errCleanup = fmt.Errorf("Error cleaning up after pivot: %v", errCleanup) - if err == nil { - err = errCleanup - } - } - }() - - if err := syscall.PivotRoot(path, pivotDir); err != nil { - // If pivot fails, fall back to the normal chroot after cleaning up temp dir - if err := os.Remove(pivotDir); err != nil { - return fmt.Errorf("Error cleaning up after failed pivot: %v", err) - } - return realChroot(path) - } - mounted = true - - // This is the new path for where the old root (prior to the pivot) has been moved to - // This dir contains the rootfs of the caller, which we need to remove so it is not visible during extraction - pivotDir = filepath.Join("/", filepath.Base(pivotDir)) - - if err := syscall.Chdir("/"); err != nil { - return fmt.Errorf("Error changing to new root: %v", err) - } - - // Make the pivotDir (where the old root lives) private so it can be unmounted without propagating to the host - if err := syscall.Mount("", pivotDir, "", syscall.MS_PRIVATE|syscall.MS_REC, ""); err != nil { - return fmt.Errorf("Error making old root private after pivot: %v", err) - } - - // Now unmount the old root so it's no longer visible from the new root - if err := syscall.Unmount(pivotDir, syscall.MNT_DETACH); err != nil { - return fmt.Errorf("Error while unmounting old root after pivot: %v", err) - } - mounted = false - - return nil -} - -func realChroot(path string) error { - if err := syscall.Chroot(path); err != nil { - return fmt.Errorf("Error after fallback to chroot: %v", err) - } - if err := syscall.Chdir("/"); err != nil { - return fmt.Errorf("Error changing to new root after chroot: %v", err) - } - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/chroot_unix.go b/vendor/github.com/docker/docker/pkg/chrootarchive/chroot_unix.go deleted file mode 100644 index 16354bf..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/chroot_unix.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !windows,!linux - -package chrootarchive - -import "syscall" - -func chroot(path string) error { - if err := syscall.Chroot(path); err != nil { - return err - } - return syscall.Chdir("/") -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/diff.go b/vendor/github.com/docker/docker/pkg/chrootarchive/diff.go deleted file mode 100644 index 49acad7..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/diff.go +++ /dev/null @@ -1,23 +0,0 @@ -package chrootarchive - -import ( - "io" - - "github.com/docker/docker/pkg/archive" -) - -// ApplyLayer parses a diff in the standard layer format from `layer`, -// and applies it to the directory `dest`. The stream `layer` can only be -// uncompressed. -// Returns the size in bytes of the contents of the layer. -func ApplyLayer(dest string, layer io.Reader) (size int64, err error) { - return applyLayerHandler(dest, layer, &archive.TarOptions{}, true) -} - -// ApplyUncompressedLayer parses a diff in the standard layer format from -// `layer`, and applies it to the directory `dest`. The stream `layer` -// can only be uncompressed. -// Returns the size in bytes of the contents of the layer. -func ApplyUncompressedLayer(dest string, layer io.Reader, options *archive.TarOptions) (int64, error) { - return applyLayerHandler(dest, layer, options, false) -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/diff_unix.go b/vendor/github.com/docker/docker/pkg/chrootarchive/diff_unix.go deleted file mode 100644 index eb0aacc..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/diff_unix.go +++ /dev/null @@ -1,130 +0,0 @@ -//+build !windows - -package chrootarchive - -import ( - "bytes" - "encoding/json" - "flag" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "runtime" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/reexec" - "github.com/docker/docker/pkg/system" - rsystem "github.com/opencontainers/runc/libcontainer/system" -) - -type applyLayerResponse struct { - LayerSize int64 `json:"layerSize"` -} - -// applyLayer is the entry-point for docker-applylayer on re-exec. This is not -// used on Windows as it does not support chroot, hence no point sandboxing -// through chroot and rexec. -func applyLayer() { - - var ( - tmpDir = "" - err error - options *archive.TarOptions - ) - runtime.LockOSThread() - flag.Parse() - - inUserns := rsystem.RunningInUserNS() - if err := chroot(flag.Arg(0)); err != nil { - fatal(err) - } - - // We need to be able to set any perms - oldmask, err := system.Umask(0) - defer system.Umask(oldmask) - if err != nil { - fatal(err) - } - - if err := json.Unmarshal([]byte(os.Getenv("OPT")), &options); err != nil { - fatal(err) - } - - if inUserns { - options.InUserNS = true - } - - if tmpDir, err = ioutil.TempDir("/", "temp-docker-extract"); err != nil { - fatal(err) - } - - os.Setenv("TMPDIR", tmpDir) - size, err := archive.UnpackLayer("/", os.Stdin, options) - os.RemoveAll(tmpDir) - if err != nil { - fatal(err) - } - - encoder := json.NewEncoder(os.Stdout) - if err := encoder.Encode(applyLayerResponse{size}); err != nil { - fatal(fmt.Errorf("unable to encode layerSize JSON: %s", err)) - } - - if _, err := flush(os.Stdin); err != nil { - fatal(err) - } - - os.Exit(0) -} - -// applyLayerHandler parses a diff in the standard layer format from `layer`, and -// applies it to the directory `dest`. Returns the size in bytes of the -// contents of the layer. -func applyLayerHandler(dest string, layer io.Reader, options *archive.TarOptions, decompress bool) (size int64, err error) { - dest = filepath.Clean(dest) - if decompress { - decompressed, err := archive.DecompressStream(layer) - if err != nil { - return 0, err - } - defer decompressed.Close() - - layer = decompressed - } - if options == nil { - options = &archive.TarOptions{} - if rsystem.RunningInUserNS() { - options.InUserNS = true - } - } - if options.ExcludePatterns == nil { - options.ExcludePatterns = []string{} - } - - data, err := json.Marshal(options) - if err != nil { - return 0, fmt.Errorf("ApplyLayer json encode: %v", err) - } - - cmd := reexec.Command("docker-applyLayer", dest) - cmd.Stdin = layer - cmd.Env = append(cmd.Env, fmt.Sprintf("OPT=%s", data)) - - outBuf, errBuf := new(bytes.Buffer), new(bytes.Buffer) - cmd.Stdout, cmd.Stderr = outBuf, errBuf - - if err = cmd.Run(); err != nil { - return 0, fmt.Errorf("ApplyLayer %s stdout: %s stderr: %s", err, outBuf, errBuf) - } - - // Stdout should be a valid JSON struct representing an applyLayerResponse. - response := applyLayerResponse{} - decoder := json.NewDecoder(outBuf) - if err = decoder.Decode(&response); err != nil { - return 0, fmt.Errorf("unable to decode ApplyLayer JSON response: %s", err) - } - - return response.LayerSize, nil -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/diff_windows.go b/vendor/github.com/docker/docker/pkg/chrootarchive/diff_windows.go deleted file mode 100644 index 9dd9988..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/diff_windows.go +++ /dev/null @@ -1,45 +0,0 @@ -package chrootarchive - -import ( - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/longpath" -) - -// applyLayerHandler parses a diff in the standard layer format from `layer`, and -// applies it to the directory `dest`. Returns the size in bytes of the -// contents of the layer. -func applyLayerHandler(dest string, layer io.Reader, options *archive.TarOptions, decompress bool) (size int64, err error) { - dest = filepath.Clean(dest) - - // Ensure it is a Windows-style volume path - dest = longpath.AddPrefix(dest) - - if decompress { - decompressed, err := archive.DecompressStream(layer) - if err != nil { - return 0, err - } - defer decompressed.Close() - - layer = decompressed - } - - tmpDir, err := ioutil.TempDir(os.Getenv("temp"), "temp-docker-extract") - if err != nil { - return 0, fmt.Errorf("ApplyLayer failed to create temp-docker-extract under %s. %s", dest, err) - } - - s, err := archive.UnpackLayer(dest, layer, nil) - os.RemoveAll(tmpDir) - if err != nil { - return 0, fmt.Errorf("ApplyLayer %s failed UnpackLayer to %s", err, dest) - } - - return s, nil -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/init_unix.go b/vendor/github.com/docker/docker/pkg/chrootarchive/init_unix.go deleted file mode 100644 index 4f637f1..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/init_unix.go +++ /dev/null @@ -1,28 +0,0 @@ -// +build !windows - -package chrootarchive - -import ( - "fmt" - "io" - "io/ioutil" - "os" - - "github.com/docker/docker/pkg/reexec" -) - -func init() { - reexec.Register("docker-applyLayer", applyLayer) - reexec.Register("docker-untar", untar) -} - -func fatal(err error) { - fmt.Fprint(os.Stderr, err) - os.Exit(1) -} - -// flush consumes all the bytes from the reader discarding -// any errors -func flush(r io.Reader) (bytes int64, err error) { - return io.Copy(ioutil.Discard, r) -} diff --git a/vendor/github.com/docker/docker/pkg/chrootarchive/init_windows.go b/vendor/github.com/docker/docker/pkg/chrootarchive/init_windows.go deleted file mode 100644 index fa17c9b..0000000 --- a/vendor/github.com/docker/docker/pkg/chrootarchive/init_windows.go +++ /dev/null @@ -1,4 +0,0 @@ -package chrootarchive - -func init() { -} diff --git a/vendor/github.com/docker/docker/pkg/devicemapper/devmapper.go b/vendor/github.com/docker/docker/pkg/devicemapper/devmapper.go deleted file mode 100644 index 94b5530..0000000 --- a/vendor/github.com/docker/docker/pkg/devicemapper/devmapper.go +++ /dev/null @@ -1,828 +0,0 @@ -// +build linux - -package devicemapper - -import ( - "errors" - "fmt" - "os" - "runtime" - "syscall" - "unsafe" - - "github.com/Sirupsen/logrus" -) - -// DevmapperLogger defines methods for logging with devicemapper. -type DevmapperLogger interface { - DMLog(level int, file string, line int, dmError int, message string) -} - -const ( - deviceCreate TaskType = iota - deviceReload - deviceRemove - deviceRemoveAll - deviceSuspend - deviceResume - deviceInfo - deviceDeps - deviceRename - deviceVersion - deviceStatus - deviceTable - deviceWaitevent - deviceList - deviceClear - deviceMknodes - deviceListVersions - deviceTargetMsg - deviceSetGeometry -) - -const ( - addNodeOnResume AddNodeType = iota - addNodeOnCreate -) - -// List of errors returned when using devicemapper. -var ( - ErrTaskRun = errors.New("dm_task_run failed") - ErrTaskSetName = errors.New("dm_task_set_name failed") - ErrTaskSetMessage = errors.New("dm_task_set_message failed") - ErrTaskSetAddNode = errors.New("dm_task_set_add_node failed") - ErrTaskSetRo = errors.New("dm_task_set_ro failed") - ErrTaskAddTarget = errors.New("dm_task_add_target failed") - ErrTaskSetSector = errors.New("dm_task_set_sector failed") - ErrTaskGetDeps = errors.New("dm_task_get_deps failed") - ErrTaskGetInfo = errors.New("dm_task_get_info failed") - ErrTaskGetDriverVersion = errors.New("dm_task_get_driver_version failed") - ErrTaskDeferredRemove = errors.New("dm_task_deferred_remove failed") - ErrTaskSetCookie = errors.New("dm_task_set_cookie failed") - ErrNilCookie = errors.New("cookie ptr can't be nil") - ErrGetBlockSize = errors.New("Can't get block size") - ErrUdevWait = errors.New("wait on udev cookie failed") - ErrSetDevDir = errors.New("dm_set_dev_dir failed") - ErrGetLibraryVersion = errors.New("dm_get_library_version failed") - ErrCreateRemoveTask = errors.New("Can't create task of type deviceRemove") - ErrRunRemoveDevice = errors.New("running RemoveDevice failed") - ErrInvalidAddNode = errors.New("Invalid AddNode type") - ErrBusy = errors.New("Device is Busy") - ErrDeviceIDExists = errors.New("Device Id Exists") - ErrEnxio = errors.New("No such device or address") -) - -var ( - dmSawBusy bool - dmSawExist bool - dmSawEnxio bool // No Such Device or Address -) - -type ( - // Task represents a devicemapper task (like lvcreate, etc.) ; a task is needed for each ioctl - // command to execute. - Task struct { - unmanaged *cdmTask - } - // Deps represents dependents (layer) of a device. - Deps struct { - Count uint32 - Filler uint32 - Device []uint64 - } - // Info represents information about a device. - Info struct { - Exists int - Suspended int - LiveTable int - InactiveTable int - OpenCount int32 - EventNr uint32 - Major uint32 - Minor uint32 - ReadOnly int - TargetCount int32 - DeferredRemove int - } - // TaskType represents a type of task - TaskType int - // AddNodeType represents a type of node to be added - AddNodeType int -) - -// DeviceIDExists returns whether error conveys the information about device Id already -// exist or not. This will be true if device creation or snap creation -// operation fails if device or snap device already exists in pool. -// Current implementation is little crude as it scans the error string -// for exact pattern match. Replacing it with more robust implementation -// is desirable. -func DeviceIDExists(err error) bool { - return fmt.Sprint(err) == fmt.Sprint(ErrDeviceIDExists) -} - -func (t *Task) destroy() { - if t != nil { - DmTaskDestroy(t.unmanaged) - runtime.SetFinalizer(t, nil) - } -} - -// TaskCreateNamed is a convenience function for TaskCreate when a name -// will be set on the task as well -func TaskCreateNamed(t TaskType, name string) (*Task, error) { - task := TaskCreate(t) - if task == nil { - return nil, fmt.Errorf("devicemapper: Can't create task of type %d", int(t)) - } - if err := task.setName(name); err != nil { - return nil, fmt.Errorf("devicemapper: Can't set task name %s", name) - } - return task, nil -} - -// TaskCreate initializes a devicemapper task of tasktype -func TaskCreate(tasktype TaskType) *Task { - Ctask := DmTaskCreate(int(tasktype)) - if Ctask == nil { - return nil - } - task := &Task{unmanaged: Ctask} - runtime.SetFinalizer(task, (*Task).destroy) - return task -} - -func (t *Task) run() error { - if res := DmTaskRun(t.unmanaged); res != 1 { - return ErrTaskRun - } - return nil -} - -func (t *Task) setName(name string) error { - if res := DmTaskSetName(t.unmanaged, name); res != 1 { - return ErrTaskSetName - } - return nil -} - -func (t *Task) setMessage(message string) error { - if res := DmTaskSetMessage(t.unmanaged, message); res != 1 { - return ErrTaskSetMessage - } - return nil -} - -func (t *Task) setSector(sector uint64) error { - if res := DmTaskSetSector(t.unmanaged, sector); res != 1 { - return ErrTaskSetSector - } - return nil -} - -func (t *Task) setCookie(cookie *uint, flags uint16) error { - if cookie == nil { - return ErrNilCookie - } - if res := DmTaskSetCookie(t.unmanaged, cookie, flags); res != 1 { - return ErrTaskSetCookie - } - return nil -} - -func (t *Task) setAddNode(addNode AddNodeType) error { - if addNode != addNodeOnResume && addNode != addNodeOnCreate { - return ErrInvalidAddNode - } - if res := DmTaskSetAddNode(t.unmanaged, addNode); res != 1 { - return ErrTaskSetAddNode - } - return nil -} - -func (t *Task) setRo() error { - if res := DmTaskSetRo(t.unmanaged); res != 1 { - return ErrTaskSetRo - } - return nil -} - -func (t *Task) addTarget(start, size uint64, ttype, params string) error { - if res := DmTaskAddTarget(t.unmanaged, start, size, - ttype, params); res != 1 { - return ErrTaskAddTarget - } - return nil -} - -func (t *Task) getDeps() (*Deps, error) { - var deps *Deps - if deps = DmTaskGetDeps(t.unmanaged); deps == nil { - return nil, ErrTaskGetDeps - } - return deps, nil -} - -func (t *Task) getInfo() (*Info, error) { - info := &Info{} - if res := DmTaskGetInfo(t.unmanaged, info); res != 1 { - return nil, ErrTaskGetInfo - } - return info, nil -} - -func (t *Task) getInfoWithDeferred() (*Info, error) { - info := &Info{} - if res := DmTaskGetInfoWithDeferred(t.unmanaged, info); res != 1 { - return nil, ErrTaskGetInfo - } - return info, nil -} - -func (t *Task) getDriverVersion() (string, error) { - res := DmTaskGetDriverVersion(t.unmanaged) - if res == "" { - return "", ErrTaskGetDriverVersion - } - return res, nil -} - -func (t *Task) getNextTarget(next unsafe.Pointer) (nextPtr unsafe.Pointer, start uint64, - length uint64, targetType string, params string) { - - return DmGetNextTarget(t.unmanaged, next, &start, &length, - &targetType, ¶ms), - start, length, targetType, params -} - -// UdevWait waits for any processes that are waiting for udev to complete the specified cookie. -func UdevWait(cookie *uint) error { - if res := DmUdevWait(*cookie); res != 1 { - logrus.Debugf("devicemapper: Failed to wait on udev cookie %d", *cookie) - return ErrUdevWait - } - return nil -} - -// LogInitVerbose is an interface to initialize the verbose logger for the device mapper library. -func LogInitVerbose(level int) { - DmLogInitVerbose(level) -} - -var dmLogger DevmapperLogger - -// LogInit initializes the logger for the device mapper library. -func LogInit(logger DevmapperLogger) { - dmLogger = logger - LogWithErrnoInit() -} - -// SetDevDir sets the dev folder for the device mapper library (usually /dev). -func SetDevDir(dir string) error { - if res := DmSetDevDir(dir); res != 1 { - logrus.Debug("devicemapper: Error dm_set_dev_dir") - return ErrSetDevDir - } - return nil -} - -// GetLibraryVersion returns the device mapper library version. -func GetLibraryVersion() (string, error) { - var version string - if res := DmGetLibraryVersion(&version); res != 1 { - return "", ErrGetLibraryVersion - } - return version, nil -} - -// UdevSyncSupported returns whether device-mapper is able to sync with udev -// -// This is essential otherwise race conditions can arise where both udev and -// device-mapper attempt to create and destroy devices. -func UdevSyncSupported() bool { - return DmUdevGetSyncSupport() != 0 -} - -// UdevSetSyncSupport allows setting whether the udev sync should be enabled. -// The return bool indicates the state of whether the sync is enabled. -func UdevSetSyncSupport(enable bool) bool { - if enable { - DmUdevSetSyncSupport(1) - } else { - DmUdevSetSyncSupport(0) - } - - return UdevSyncSupported() -} - -// CookieSupported returns whether the version of device-mapper supports the -// use of cookie's in the tasks. -// This is largely a lower level call that other functions use. -func CookieSupported() bool { - return DmCookieSupported() != 0 -} - -// RemoveDevice is a useful helper for cleaning up a device. -func RemoveDevice(name string) error { - task, err := TaskCreateNamed(deviceRemove, name) - if task == nil { - return err - } - - var cookie uint - if err := task.setCookie(&cookie, 0); err != nil { - return fmt.Errorf("devicemapper: Can not set cookie: %s", err) - } - defer UdevWait(&cookie) - - dmSawBusy = false // reset before the task is run - if err = task.run(); err != nil { - if dmSawBusy { - return ErrBusy - } - return fmt.Errorf("devicemapper: Error running RemoveDevice %s", err) - } - - return nil -} - -// RemoveDeviceDeferred is a useful helper for cleaning up a device, but deferred. -func RemoveDeviceDeferred(name string) error { - logrus.Debugf("devicemapper: RemoveDeviceDeferred START(%s)", name) - defer logrus.Debugf("devicemapper: RemoveDeviceDeferred END(%s)", name) - task, err := TaskCreateNamed(deviceRemove, name) - if task == nil { - return err - } - - if err := DmTaskDeferredRemove(task.unmanaged); err != 1 { - return ErrTaskDeferredRemove - } - - // set a task cookie and disable library fallback, or else libdevmapper will - // disable udev dm rules and delete the symlink under /dev/mapper by itself, - // even if the removal is deferred by the kernel. - var cookie uint - var flags uint16 - flags = DmUdevDisableLibraryFallback - if err := task.setCookie(&cookie, flags); err != nil { - return fmt.Errorf("devicemapper: Can not set cookie: %s", err) - } - - // libdevmapper and udev relies on System V semaphore for synchronization, - // semaphores created in `task.setCookie` will be cleaned up in `UdevWait`. - // So these two function call must come in pairs, otherwise semaphores will - // be leaked, and the limit of number of semaphores defined in `/proc/sys/kernel/sem` - // will be reached, which will eventually make all follwing calls to 'task.SetCookie' - // fail. - // this call will not wait for the deferred removal's final executing, since no - // udev event will be generated, and the semaphore's value will not be incremented - // by udev, what UdevWait is just cleaning up the semaphore. - defer UdevWait(&cookie) - - if err = task.run(); err != nil { - return fmt.Errorf("devicemapper: Error running RemoveDeviceDeferred %s", err) - } - - return nil -} - -// CancelDeferredRemove cancels a deferred remove for a device. -func CancelDeferredRemove(deviceName string) error { - task, err := TaskCreateNamed(deviceTargetMsg, deviceName) - if task == nil { - return err - } - - if err := task.setSector(0); err != nil { - return fmt.Errorf("devicemapper: Can't set sector %s", err) - } - - if err := task.setMessage(fmt.Sprintf("@cancel_deferred_remove")); err != nil { - return fmt.Errorf("devicemapper: Can't set message %s", err) - } - - dmSawBusy = false - dmSawEnxio = false - if err := task.run(); err != nil { - // A device might be being deleted already - if dmSawBusy { - return ErrBusy - } else if dmSawEnxio { - return ErrEnxio - } - return fmt.Errorf("devicemapper: Error running CancelDeferredRemove %s", err) - - } - return nil -} - -// GetBlockDeviceSize returns the size of a block device identified by the specified file. -func GetBlockDeviceSize(file *os.File) (uint64, error) { - size, err := ioctlBlkGetSize64(file.Fd()) - if err != nil { - logrus.Errorf("devicemapper: Error getblockdevicesize: %s", err) - return 0, ErrGetBlockSize - } - return uint64(size), nil -} - -// BlockDeviceDiscard runs discard for the given path. -// This is used as a workaround for the kernel not discarding block so -// on the thin pool when we remove a thinp device, so we do it -// manually -func BlockDeviceDiscard(path string) error { - file, err := os.OpenFile(path, os.O_RDWR, 0) - if err != nil { - return err - } - defer file.Close() - - size, err := GetBlockDeviceSize(file) - if err != nil { - return err - } - - if err := ioctlBlkDiscard(file.Fd(), 0, size); err != nil { - return err - } - - // Without this sometimes the remove of the device that happens after - // discard fails with EBUSY. - syscall.Sync() - - return nil -} - -// CreatePool is the programmatic example of "dmsetup create". -// It creates a device with the specified poolName, data and metadata file and block size. -func CreatePool(poolName string, dataFile, metadataFile *os.File, poolBlockSize uint32) error { - task, err := TaskCreateNamed(deviceCreate, poolName) - if task == nil { - return err - } - - size, err := GetBlockDeviceSize(dataFile) - if err != nil { - return fmt.Errorf("devicemapper: Can't get data size %s", err) - } - - params := fmt.Sprintf("%s %s %d 32768 1 skip_block_zeroing", metadataFile.Name(), dataFile.Name(), poolBlockSize) - if err := task.addTarget(0, size/512, "thin-pool", params); err != nil { - return fmt.Errorf("devicemapper: Can't add target %s", err) - } - - var cookie uint - var flags uint16 - flags = DmUdevDisableSubsystemRulesFlag | DmUdevDisableDiskRulesFlag | DmUdevDisableOtherRulesFlag - if err := task.setCookie(&cookie, flags); err != nil { - return fmt.Errorf("devicemapper: Can't set cookie %s", err) - } - defer UdevWait(&cookie) - - if err := task.run(); err != nil { - return fmt.Errorf("devicemapper: Error running deviceCreate (CreatePool) %s", err) - } - - return nil -} - -// ReloadPool is the programmatic example of "dmsetup reload". -// It reloads the table with the specified poolName, data and metadata file and block size. -func ReloadPool(poolName string, dataFile, metadataFile *os.File, poolBlockSize uint32) error { - task, err := TaskCreateNamed(deviceReload, poolName) - if task == nil { - return err - } - - size, err := GetBlockDeviceSize(dataFile) - if err != nil { - return fmt.Errorf("devicemapper: Can't get data size %s", err) - } - - params := fmt.Sprintf("%s %s %d 32768 1 skip_block_zeroing", metadataFile.Name(), dataFile.Name(), poolBlockSize) - if err := task.addTarget(0, size/512, "thin-pool", params); err != nil { - return fmt.Errorf("devicemapper: Can't add target %s", err) - } - - if err := task.run(); err != nil { - return fmt.Errorf("devicemapper: Error running deviceCreate %s", err) - } - - return nil -} - -// GetDeps is the programmatic example of "dmsetup deps". -// It outputs a list of devices referenced by the live table for the specified device. -func GetDeps(name string) (*Deps, error) { - task, err := TaskCreateNamed(deviceDeps, name) - if task == nil { - return nil, err - } - if err := task.run(); err != nil { - return nil, err - } - return task.getDeps() -} - -// GetInfo is the programmatic example of "dmsetup info". -// It outputs some brief information about the device. -func GetInfo(name string) (*Info, error) { - task, err := TaskCreateNamed(deviceInfo, name) - if task == nil { - return nil, err - } - if err := task.run(); err != nil { - return nil, err - } - return task.getInfo() -} - -// GetInfoWithDeferred is the programmatic example of "dmsetup info", but deferred. -// It outputs some brief information about the device. -func GetInfoWithDeferred(name string) (*Info, error) { - task, err := TaskCreateNamed(deviceInfo, name) - if task == nil { - return nil, err - } - if err := task.run(); err != nil { - return nil, err - } - return task.getInfoWithDeferred() -} - -// GetDriverVersion is the programmatic example of "dmsetup version". -// It outputs version information of the driver. -func GetDriverVersion() (string, error) { - task := TaskCreate(deviceVersion) - if task == nil { - return "", fmt.Errorf("devicemapper: Can't create deviceVersion task") - } - if err := task.run(); err != nil { - return "", err - } - return task.getDriverVersion() -} - -// GetStatus is the programmatic example of "dmsetup status". -// It outputs status information for the specified device name. -func GetStatus(name string) (uint64, uint64, string, string, error) { - task, err := TaskCreateNamed(deviceStatus, name) - if task == nil { - logrus.Debugf("devicemapper: GetStatus() Error TaskCreateNamed: %s", err) - return 0, 0, "", "", err - } - if err := task.run(); err != nil { - logrus.Debugf("devicemapper: GetStatus() Error Run: %s", err) - return 0, 0, "", "", err - } - - devinfo, err := task.getInfo() - if err != nil { - logrus.Debugf("devicemapper: GetStatus() Error GetInfo: %s", err) - return 0, 0, "", "", err - } - if devinfo.Exists == 0 { - logrus.Debugf("devicemapper: GetStatus() Non existing device %s", name) - return 0, 0, "", "", fmt.Errorf("devicemapper: Non existing device %s", name) - } - - _, start, length, targetType, params := task.getNextTarget(unsafe.Pointer(nil)) - return start, length, targetType, params, nil -} - -// GetTable is the programmatic example for "dmsetup table". -// It outputs the current table for the specified device name. -func GetTable(name string) (uint64, uint64, string, string, error) { - task, err := TaskCreateNamed(deviceTable, name) - if task == nil { - logrus.Debugf("devicemapper: GetTable() Error TaskCreateNamed: %s", err) - return 0, 0, "", "", err - } - if err := task.run(); err != nil { - logrus.Debugf("devicemapper: GetTable() Error Run: %s", err) - return 0, 0, "", "", err - } - - devinfo, err := task.getInfo() - if err != nil { - logrus.Debugf("devicemapper: GetTable() Error GetInfo: %s", err) - return 0, 0, "", "", err - } - if devinfo.Exists == 0 { - logrus.Debugf("devicemapper: GetTable() Non existing device %s", name) - return 0, 0, "", "", fmt.Errorf("devicemapper: Non existing device %s", name) - } - - _, start, length, targetType, params := task.getNextTarget(unsafe.Pointer(nil)) - return start, length, targetType, params, nil -} - -// SetTransactionID sets a transaction id for the specified device name. -func SetTransactionID(poolName string, oldID uint64, newID uint64) error { - task, err := TaskCreateNamed(deviceTargetMsg, poolName) - if task == nil { - return err - } - - if err := task.setSector(0); err != nil { - return fmt.Errorf("devicemapper: Can't set sector %s", err) - } - - if err := task.setMessage(fmt.Sprintf("set_transaction_id %d %d", oldID, newID)); err != nil { - return fmt.Errorf("devicemapper: Can't set message %s", err) - } - - if err := task.run(); err != nil { - return fmt.Errorf("devicemapper: Error running SetTransactionID %s", err) - } - return nil -} - -// SuspendDevice is the programmatic example of "dmsetup suspend". -// It suspends the specified device. -func SuspendDevice(name string) error { - task, err := TaskCreateNamed(deviceSuspend, name) - if task == nil { - return err - } - if err := task.run(); err != nil { - return fmt.Errorf("devicemapper: Error running deviceSuspend %s", err) - } - return nil -} - -// ResumeDevice is the programmatic example of "dmsetup resume". -// It un-suspends the specified device. -func ResumeDevice(name string) error { - task, err := TaskCreateNamed(deviceResume, name) - if task == nil { - return err - } - - var cookie uint - if err := task.setCookie(&cookie, 0); err != nil { - return fmt.Errorf("devicemapper: Can't set cookie %s", err) - } - defer UdevWait(&cookie) - - if err := task.run(); err != nil { - return fmt.Errorf("devicemapper: Error running deviceResume %s", err) - } - - return nil -} - -// CreateDevice creates a device with the specified poolName with the specified device id. -func CreateDevice(poolName string, deviceID int) error { - logrus.Debugf("devicemapper: CreateDevice(poolName=%v, deviceID=%v)", poolName, deviceID) - task, err := TaskCreateNamed(deviceTargetMsg, poolName) - if task == nil { - return err - } - - if err := task.setSector(0); err != nil { - return fmt.Errorf("devicemapper: Can't set sector %s", err) - } - - if err := task.setMessage(fmt.Sprintf("create_thin %d", deviceID)); err != nil { - return fmt.Errorf("devicemapper: Can't set message %s", err) - } - - dmSawExist = false // reset before the task is run - if err := task.run(); err != nil { - // Caller wants to know about ErrDeviceIDExists so that it can try with a different device id. - if dmSawExist { - return ErrDeviceIDExists - } - - return fmt.Errorf("devicemapper: Error running CreateDevice %s", err) - - } - return nil -} - -// DeleteDevice deletes a device with the specified poolName with the specified device id. -func DeleteDevice(poolName string, deviceID int) error { - task, err := TaskCreateNamed(deviceTargetMsg, poolName) - if task == nil { - return err - } - - if err := task.setSector(0); err != nil { - return fmt.Errorf("devicemapper: Can't set sector %s", err) - } - - if err := task.setMessage(fmt.Sprintf("delete %d", deviceID)); err != nil { - return fmt.Errorf("devicemapper: Can't set message %s", err) - } - - dmSawBusy = false - if err := task.run(); err != nil { - if dmSawBusy { - return ErrBusy - } - return fmt.Errorf("devicemapper: Error running DeleteDevice %s", err) - } - return nil -} - -// ActivateDevice activates the device identified by the specified -// poolName, name and deviceID with the specified size. -func ActivateDevice(poolName string, name string, deviceID int, size uint64) error { - return activateDevice(poolName, name, deviceID, size, "") -} - -// ActivateDeviceWithExternal activates the device identified by the specified -// poolName, name and deviceID with the specified size. -func ActivateDeviceWithExternal(poolName string, name string, deviceID int, size uint64, external string) error { - return activateDevice(poolName, name, deviceID, size, external) -} - -func activateDevice(poolName string, name string, deviceID int, size uint64, external string) error { - task, err := TaskCreateNamed(deviceCreate, name) - if task == nil { - return err - } - - var params string - if len(external) > 0 { - params = fmt.Sprintf("%s %d %s", poolName, deviceID, external) - } else { - params = fmt.Sprintf("%s %d", poolName, deviceID) - } - if err := task.addTarget(0, size/512, "thin", params); err != nil { - return fmt.Errorf("devicemapper: Can't add target %s", err) - } - if err := task.setAddNode(addNodeOnCreate); err != nil { - return fmt.Errorf("devicemapper: Can't add node %s", err) - } - - var cookie uint - if err := task.setCookie(&cookie, 0); err != nil { - return fmt.Errorf("devicemapper: Can't set cookie %s", err) - } - - defer UdevWait(&cookie) - - if err := task.run(); err != nil { - return fmt.Errorf("devicemapper: Error running deviceCreate (ActivateDevice) %s", err) - } - - return nil -} - -// CreateSnapDeviceRaw creates a snapshot device. Caller needs to suspend and resume the origin device if it is active. -func CreateSnapDeviceRaw(poolName string, deviceID int, baseDeviceID int) error { - task, err := TaskCreateNamed(deviceTargetMsg, poolName) - if task == nil { - return err - } - - if err := task.setSector(0); err != nil { - return fmt.Errorf("devicemapper: Can't set sector %s", err) - } - - if err := task.setMessage(fmt.Sprintf("create_snap %d %d", deviceID, baseDeviceID)); err != nil { - return fmt.Errorf("devicemapper: Can't set message %s", err) - } - - dmSawExist = false // reset before the task is run - if err := task.run(); err != nil { - // Caller wants to know about ErrDeviceIDExists so that it can try with a different device id. - if dmSawExist { - return ErrDeviceIDExists - } - return fmt.Errorf("devicemapper: Error running deviceCreate (createSnapDevice) %s", err) - } - - return nil -} - -// CreateSnapDevice creates a snapshot based on the device identified by the baseName and baseDeviceId, -func CreateSnapDevice(poolName string, deviceID int, baseName string, baseDeviceID int) error { - devinfo, _ := GetInfo(baseName) - doSuspend := devinfo != nil && devinfo.Exists != 0 - - if doSuspend { - if err := SuspendDevice(baseName); err != nil { - return err - } - } - - if err := CreateSnapDeviceRaw(poolName, deviceID, baseDeviceID); err != nil { - if doSuspend { - if err2 := ResumeDevice(baseName); err2 != nil { - return fmt.Errorf("CreateSnapDeviceRaw Error: (%v): ResumeDevice Error: (%v)", err, err2) - } - } - return err - } - - if doSuspend { - if err := ResumeDevice(baseName); err != nil { - return err - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_log.go b/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_log.go deleted file mode 100644 index 8477e36..0000000 --- a/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_log.go +++ /dev/null @@ -1,35 +0,0 @@ -// +build linux - -package devicemapper - -import "C" - -import ( - "strings" -) - -// Due to the way cgo works this has to be in a separate file, as devmapper.go has -// definitions in the cgo block, which is incompatible with using "//export" - -// DevmapperLogCallback exports the devmapper log callback for cgo. -//export DevmapperLogCallback -func DevmapperLogCallback(level C.int, file *C.char, line C.int, dmErrnoOrClass C.int, message *C.char) { - msg := C.GoString(message) - if level < 7 { - if strings.Contains(msg, "busy") { - dmSawBusy = true - } - - if strings.Contains(msg, "File exists") { - dmSawExist = true - } - - if strings.Contains(msg, "No such device or address") { - dmSawEnxio = true - } - } - - if dmLogger != nil { - dmLogger.DMLog(int(level), C.GoString(file), int(line), int(dmErrnoOrClass), msg) - } -} diff --git a/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_wrapper.go b/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_wrapper.go deleted file mode 100644 index 91fbc85..0000000 --- a/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_wrapper.go +++ /dev/null @@ -1,251 +0,0 @@ -// +build linux - -package devicemapper - -/* -#cgo LDFLAGS: -L. -ldevmapper -#include -#include // FIXME: present only for BLKGETSIZE64, maybe we can remove it? - -// FIXME: Can't we find a way to do the logging in pure Go? -extern void DevmapperLogCallback(int level, char *file, int line, int dm_errno_or_class, char *str); - -static void log_cb(int level, const char *file, int line, int dm_errno_or_class, const char *f, ...) -{ - char buffer[256]; - va_list ap; - - va_start(ap, f); - vsnprintf(buffer, 256, f, ap); - va_end(ap); - - DevmapperLogCallback(level, (char *)file, line, dm_errno_or_class, buffer); -} - -static void log_with_errno_init() -{ - dm_log_with_errno_init(log_cb); -} -*/ -import "C" - -import ( - "reflect" - "unsafe" -) - -type ( - cdmTask C.struct_dm_task -) - -// IOCTL consts -const ( - BlkGetSize64 = C.BLKGETSIZE64 - BlkDiscard = C.BLKDISCARD -) - -// Devicemapper cookie flags. -const ( - DmUdevDisableSubsystemRulesFlag = C.DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG - DmUdevDisableDiskRulesFlag = C.DM_UDEV_DISABLE_DISK_RULES_FLAG - DmUdevDisableOtherRulesFlag = C.DM_UDEV_DISABLE_OTHER_RULES_FLAG - DmUdevDisableLibraryFallback = C.DM_UDEV_DISABLE_LIBRARY_FALLBACK -) - -// DeviceMapper mapped functions. -var ( - DmGetLibraryVersion = dmGetLibraryVersionFct - DmGetNextTarget = dmGetNextTargetFct - DmLogInitVerbose = dmLogInitVerboseFct - DmSetDevDir = dmSetDevDirFct - DmTaskAddTarget = dmTaskAddTargetFct - DmTaskCreate = dmTaskCreateFct - DmTaskDestroy = dmTaskDestroyFct - DmTaskGetDeps = dmTaskGetDepsFct - DmTaskGetInfo = dmTaskGetInfoFct - DmTaskGetDriverVersion = dmTaskGetDriverVersionFct - DmTaskRun = dmTaskRunFct - DmTaskSetAddNode = dmTaskSetAddNodeFct - DmTaskSetCookie = dmTaskSetCookieFct - DmTaskSetMessage = dmTaskSetMessageFct - DmTaskSetName = dmTaskSetNameFct - DmTaskSetRo = dmTaskSetRoFct - DmTaskSetSector = dmTaskSetSectorFct - DmUdevWait = dmUdevWaitFct - DmUdevSetSyncSupport = dmUdevSetSyncSupportFct - DmUdevGetSyncSupport = dmUdevGetSyncSupportFct - DmCookieSupported = dmCookieSupportedFct - LogWithErrnoInit = logWithErrnoInitFct - DmTaskDeferredRemove = dmTaskDeferredRemoveFct - DmTaskGetInfoWithDeferred = dmTaskGetInfoWithDeferredFct -) - -func free(p *C.char) { - C.free(unsafe.Pointer(p)) -} - -func dmTaskDestroyFct(task *cdmTask) { - C.dm_task_destroy((*C.struct_dm_task)(task)) -} - -func dmTaskCreateFct(taskType int) *cdmTask { - return (*cdmTask)(C.dm_task_create(C.int(taskType))) -} - -func dmTaskRunFct(task *cdmTask) int { - ret, _ := C.dm_task_run((*C.struct_dm_task)(task)) - return int(ret) -} - -func dmTaskSetNameFct(task *cdmTask, name string) int { - Cname := C.CString(name) - defer free(Cname) - - return int(C.dm_task_set_name((*C.struct_dm_task)(task), Cname)) -} - -func dmTaskSetMessageFct(task *cdmTask, message string) int { - Cmessage := C.CString(message) - defer free(Cmessage) - - return int(C.dm_task_set_message((*C.struct_dm_task)(task), Cmessage)) -} - -func dmTaskSetSectorFct(task *cdmTask, sector uint64) int { - return int(C.dm_task_set_sector((*C.struct_dm_task)(task), C.uint64_t(sector))) -} - -func dmTaskSetCookieFct(task *cdmTask, cookie *uint, flags uint16) int { - cCookie := C.uint32_t(*cookie) - defer func() { - *cookie = uint(cCookie) - }() - return int(C.dm_task_set_cookie((*C.struct_dm_task)(task), &cCookie, C.uint16_t(flags))) -} - -func dmTaskSetAddNodeFct(task *cdmTask, addNode AddNodeType) int { - return int(C.dm_task_set_add_node((*C.struct_dm_task)(task), C.dm_add_node_t(addNode))) -} - -func dmTaskSetRoFct(task *cdmTask) int { - return int(C.dm_task_set_ro((*C.struct_dm_task)(task))) -} - -func dmTaskAddTargetFct(task *cdmTask, - start, size uint64, ttype, params string) int { - - Cttype := C.CString(ttype) - defer free(Cttype) - - Cparams := C.CString(params) - defer free(Cparams) - - return int(C.dm_task_add_target((*C.struct_dm_task)(task), C.uint64_t(start), C.uint64_t(size), Cttype, Cparams)) -} - -func dmTaskGetDepsFct(task *cdmTask) *Deps { - Cdeps := C.dm_task_get_deps((*C.struct_dm_task)(task)) - if Cdeps == nil { - return nil - } - - // golang issue: https://github.com/golang/go/issues/11925 - hdr := reflect.SliceHeader{ - Data: uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(Cdeps)) + unsafe.Sizeof(*Cdeps))), - Len: int(Cdeps.count), - Cap: int(Cdeps.count), - } - devices := *(*[]C.uint64_t)(unsafe.Pointer(&hdr)) - - deps := &Deps{ - Count: uint32(Cdeps.count), - Filler: uint32(Cdeps.filler), - } - for _, device := range devices { - deps.Device = append(deps.Device, uint64(device)) - } - return deps -} - -func dmTaskGetInfoFct(task *cdmTask, info *Info) int { - Cinfo := C.struct_dm_info{} - defer func() { - info.Exists = int(Cinfo.exists) - info.Suspended = int(Cinfo.suspended) - info.LiveTable = int(Cinfo.live_table) - info.InactiveTable = int(Cinfo.inactive_table) - info.OpenCount = int32(Cinfo.open_count) - info.EventNr = uint32(Cinfo.event_nr) - info.Major = uint32(Cinfo.major) - info.Minor = uint32(Cinfo.minor) - info.ReadOnly = int(Cinfo.read_only) - info.TargetCount = int32(Cinfo.target_count) - }() - return int(C.dm_task_get_info((*C.struct_dm_task)(task), &Cinfo)) -} - -func dmTaskGetDriverVersionFct(task *cdmTask) string { - buffer := C.malloc(128) - defer C.free(buffer) - res := C.dm_task_get_driver_version((*C.struct_dm_task)(task), (*C.char)(buffer), 128) - if res == 0 { - return "" - } - return C.GoString((*C.char)(buffer)) -} - -func dmGetNextTargetFct(task *cdmTask, next unsafe.Pointer, start, length *uint64, target, params *string) unsafe.Pointer { - var ( - Cstart, Clength C.uint64_t - CtargetType, Cparams *C.char - ) - defer func() { - *start = uint64(Cstart) - *length = uint64(Clength) - *target = C.GoString(CtargetType) - *params = C.GoString(Cparams) - }() - - nextp := C.dm_get_next_target((*C.struct_dm_task)(task), next, &Cstart, &Clength, &CtargetType, &Cparams) - return nextp -} - -func dmUdevSetSyncSupportFct(syncWithUdev int) { - (C.dm_udev_set_sync_support(C.int(syncWithUdev))) -} - -func dmUdevGetSyncSupportFct() int { - return int(C.dm_udev_get_sync_support()) -} - -func dmUdevWaitFct(cookie uint) int { - return int(C.dm_udev_wait(C.uint32_t(cookie))) -} - -func dmCookieSupportedFct() int { - return int(C.dm_cookie_supported()) -} - -func dmLogInitVerboseFct(level int) { - C.dm_log_init_verbose(C.int(level)) -} - -func logWithErrnoInitFct() { - C.log_with_errno_init() -} - -func dmSetDevDirFct(dir string) int { - Cdir := C.CString(dir) - defer free(Cdir) - - return int(C.dm_set_dev_dir(Cdir)) -} - -func dmGetLibraryVersionFct(version *string) int { - buffer := C.CString(string(make([]byte, 128))) - defer free(buffer) - defer func() { - *version = C.GoString(buffer) - }() - return int(C.dm_get_library_version(buffer, 128)) -} diff --git a/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_wrapper_deferred_remove.go b/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_wrapper_deferred_remove.go deleted file mode 100644 index dc361ea..0000000 --- a/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_wrapper_deferred_remove.go +++ /dev/null @@ -1,34 +0,0 @@ -// +build linux,!libdm_no_deferred_remove - -package devicemapper - -/* -#cgo LDFLAGS: -L. -ldevmapper -#include -*/ -import "C" - -// LibraryDeferredRemovalSupport is supported when statically linked. -const LibraryDeferredRemovalSupport = true - -func dmTaskDeferredRemoveFct(task *cdmTask) int { - return int(C.dm_task_deferred_remove((*C.struct_dm_task)(task))) -} - -func dmTaskGetInfoWithDeferredFct(task *cdmTask, info *Info) int { - Cinfo := C.struct_dm_info{} - defer func() { - info.Exists = int(Cinfo.exists) - info.Suspended = int(Cinfo.suspended) - info.LiveTable = int(Cinfo.live_table) - info.InactiveTable = int(Cinfo.inactive_table) - info.OpenCount = int32(Cinfo.open_count) - info.EventNr = uint32(Cinfo.event_nr) - info.Major = uint32(Cinfo.major) - info.Minor = uint32(Cinfo.minor) - info.ReadOnly = int(Cinfo.read_only) - info.TargetCount = int32(Cinfo.target_count) - info.DeferredRemove = int(Cinfo.deferred_remove) - }() - return int(C.dm_task_get_info((*C.struct_dm_task)(task), &Cinfo)) -} diff --git a/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_wrapper_no_deferred_remove.go b/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_wrapper_no_deferred_remove.go deleted file mode 100644 index 8249ccf..0000000 --- a/vendor/github.com/docker/docker/pkg/devicemapper/devmapper_wrapper_no_deferred_remove.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build linux,libdm_no_deferred_remove - -package devicemapper - -// LibraryDeferredRemovalSupport is not supported when statically linked. -const LibraryDeferredRemovalSupport = false - -func dmTaskDeferredRemoveFct(task *cdmTask) int { - // Error. Nobody should be calling it. - return -1 -} - -func dmTaskGetInfoWithDeferredFct(task *cdmTask, info *Info) int { - return -1 -} diff --git a/vendor/github.com/docker/docker/pkg/devicemapper/ioctl.go b/vendor/github.com/docker/docker/pkg/devicemapper/ioctl.go deleted file mode 100644 index 581b57e..0000000 --- a/vendor/github.com/docker/docker/pkg/devicemapper/ioctl.go +++ /dev/null @@ -1,27 +0,0 @@ -// +build linux - -package devicemapper - -import ( - "syscall" - "unsafe" -) - -func ioctlBlkGetSize64(fd uintptr) (int64, error) { - var size int64 - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, BlkGetSize64, uintptr(unsafe.Pointer(&size))); err != 0 { - return 0, err - } - return size, nil -} - -func ioctlBlkDiscard(fd uintptr, offset, length uint64) error { - var r [2]uint64 - r[0] = offset - r[1] = length - - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, BlkDiscard, uintptr(unsafe.Pointer(&r[0]))); err != 0 { - return err - } - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/devicemapper/log.go b/vendor/github.com/docker/docker/pkg/devicemapper/log.go deleted file mode 100644 index cee5e54..0000000 --- a/vendor/github.com/docker/docker/pkg/devicemapper/log.go +++ /dev/null @@ -1,11 +0,0 @@ -package devicemapper - -// definitions from lvm2 lib/log/log.h -const ( - LogLevelFatal = 2 + iota // _LOG_FATAL - LogLevelErr // _LOG_ERR - LogLevelWarn // _LOG_WARN - LogLevelNotice // _LOG_NOTICE - LogLevelInfo // _LOG_INFO - LogLevelDebug // _LOG_DEBUG -) diff --git a/vendor/github.com/docker/docker/pkg/directory/directory.go b/vendor/github.com/docker/docker/pkg/directory/directory.go deleted file mode 100644 index 1715ef4..0000000 --- a/vendor/github.com/docker/docker/pkg/directory/directory.go +++ /dev/null @@ -1,26 +0,0 @@ -package directory - -import ( - "io/ioutil" - "os" - "path/filepath" -) - -// MoveToSubdir moves all contents of a directory to a subdirectory underneath the original path -func MoveToSubdir(oldpath, subdir string) error { - - infos, err := ioutil.ReadDir(oldpath) - if err != nil { - return err - } - for _, info := range infos { - if info.Name() != subdir { - oldName := filepath.Join(oldpath, info.Name()) - newName := filepath.Join(oldpath, subdir, info.Name()) - if err := os.Rename(oldName, newName); err != nil { - return err - } - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/directory/directory_test.go b/vendor/github.com/docker/docker/pkg/directory/directory_test.go deleted file mode 100644 index 2b7a465..0000000 --- a/vendor/github.com/docker/docker/pkg/directory/directory_test.go +++ /dev/null @@ -1,192 +0,0 @@ -package directory - -import ( - "io/ioutil" - "os" - "path/filepath" - "reflect" - "sort" - "testing" -) - -// Size of an empty directory should be 0 -func TestSizeEmpty(t *testing.T) { - var dir string - var err error - if dir, err = ioutil.TempDir(os.TempDir(), "testSizeEmptyDirectory"); err != nil { - t.Fatalf("failed to create directory: %s", err) - } - - var size int64 - if size, _ = Size(dir); size != 0 { - t.Fatalf("empty directory has size: %d", size) - } -} - -// Size of a directory with one empty file should be 0 -func TestSizeEmptyFile(t *testing.T) { - var dir string - var err error - if dir, err = ioutil.TempDir(os.TempDir(), "testSizeEmptyFile"); err != nil { - t.Fatalf("failed to create directory: %s", err) - } - - var file *os.File - if file, err = ioutil.TempFile(dir, "file"); err != nil { - t.Fatalf("failed to create file: %s", err) - } - - var size int64 - if size, _ = Size(file.Name()); size != 0 { - t.Fatalf("directory with one file has size: %d", size) - } -} - -// Size of a directory with one 5-byte file should be 5 -func TestSizeNonemptyFile(t *testing.T) { - var dir string - var err error - if dir, err = ioutil.TempDir(os.TempDir(), "testSizeNonemptyFile"); err != nil { - t.Fatalf("failed to create directory: %s", err) - } - - var file *os.File - if file, err = ioutil.TempFile(dir, "file"); err != nil { - t.Fatalf("failed to create file: %s", err) - } - - d := []byte{97, 98, 99, 100, 101} - file.Write(d) - - var size int64 - if size, _ = Size(file.Name()); size != 5 { - t.Fatalf("directory with one 5-byte file has size: %d", size) - } -} - -// Size of a directory with one empty directory should be 0 -func TestSizeNestedDirectoryEmpty(t *testing.T) { - var dir string - var err error - if dir, err = ioutil.TempDir(os.TempDir(), "testSizeNestedDirectoryEmpty"); err != nil { - t.Fatalf("failed to create directory: %s", err) - } - if dir, err = ioutil.TempDir(dir, "nested"); err != nil { - t.Fatalf("failed to create nested directory: %s", err) - } - - var size int64 - if size, _ = Size(dir); size != 0 { - t.Fatalf("directory with one empty directory has size: %d", size) - } -} - -// Test directory with 1 file and 1 empty directory -func TestSizeFileAndNestedDirectoryEmpty(t *testing.T) { - var dir string - var err error - if dir, err = ioutil.TempDir(os.TempDir(), "testSizeFileAndNestedDirectoryEmpty"); err != nil { - t.Fatalf("failed to create directory: %s", err) - } - if dir, err = ioutil.TempDir(dir, "nested"); err != nil { - t.Fatalf("failed to create nested directory: %s", err) - } - - var file *os.File - if file, err = ioutil.TempFile(dir, "file"); err != nil { - t.Fatalf("failed to create file: %s", err) - } - - d := []byte{100, 111, 99, 107, 101, 114} - file.Write(d) - - var size int64 - if size, _ = Size(dir); size != 6 { - t.Fatalf("directory with 6-byte file and empty directory has size: %d", size) - } -} - -// Test directory with 1 file and 1 non-empty directory -func TestSizeFileAndNestedDirectoryNonempty(t *testing.T) { - var dir, dirNested string - var err error - if dir, err = ioutil.TempDir(os.TempDir(), "TestSizeFileAndNestedDirectoryNonempty"); err != nil { - t.Fatalf("failed to create directory: %s", err) - } - if dirNested, err = ioutil.TempDir(dir, "nested"); err != nil { - t.Fatalf("failed to create nested directory: %s", err) - } - - var file *os.File - if file, err = ioutil.TempFile(dir, "file"); err != nil { - t.Fatalf("failed to create file: %s", err) - } - - data := []byte{100, 111, 99, 107, 101, 114} - file.Write(data) - - var nestedFile *os.File - if nestedFile, err = ioutil.TempFile(dirNested, "file"); err != nil { - t.Fatalf("failed to create file in nested directory: %s", err) - } - - nestedData := []byte{100, 111, 99, 107, 101, 114} - nestedFile.Write(nestedData) - - var size int64 - if size, _ = Size(dir); size != 12 { - t.Fatalf("directory with 6-byte file and nested directory with 6-byte file has size: %d", size) - } -} - -// Test migration of directory to a subdir underneath itself -func TestMoveToSubdir(t *testing.T) { - var outerDir, subDir string - var err error - - if outerDir, err = ioutil.TempDir(os.TempDir(), "TestMoveToSubdir"); err != nil { - t.Fatalf("failed to create directory: %v", err) - } - - if subDir, err = ioutil.TempDir(outerDir, "testSub"); err != nil { - t.Fatalf("failed to create subdirectory: %v", err) - } - - // write 4 temp files in the outer dir to get moved - filesList := []string{"a", "b", "c", "d"} - for _, fName := range filesList { - if file, err := os.Create(filepath.Join(outerDir, fName)); err != nil { - t.Fatalf("couldn't create temp file %q: %v", fName, err) - } else { - file.WriteString(fName) - file.Close() - } - } - - if err = MoveToSubdir(outerDir, filepath.Base(subDir)); err != nil { - t.Fatalf("Error during migration of content to subdirectory: %v", err) - } - // validate that the files were moved to the subdirectory - infos, err := ioutil.ReadDir(subDir) - if err != nil { - t.Fatal(err) - } - if len(infos) != 4 { - t.Fatalf("Should be four files in the subdir after the migration: actual length: %d", len(infos)) - } - var results []string - for _, info := range infos { - results = append(results, info.Name()) - } - sort.Sort(sort.StringSlice(results)) - if !reflect.DeepEqual(filesList, results) { - t.Fatalf("Results after migration do not equal list of files: expected: %v, got: %v", filesList, results) - } -} - -// Test a non-existing directory -func TestSizeNonExistingDirectory(t *testing.T) { - if _, err := Size("/thisdirectoryshouldnotexist/TestSizeNonExistingDirectory"); err == nil { - t.Fatalf("error is expected") - } -} diff --git a/vendor/github.com/docker/docker/pkg/directory/directory_unix.go b/vendor/github.com/docker/docker/pkg/directory/directory_unix.go deleted file mode 100644 index 397251b..0000000 --- a/vendor/github.com/docker/docker/pkg/directory/directory_unix.go +++ /dev/null @@ -1,48 +0,0 @@ -// +build linux freebsd solaris - -package directory - -import ( - "os" - "path/filepath" - "syscall" -) - -// Size walks a directory tree and returns its total size in bytes. -func Size(dir string) (size int64, err error) { - data := make(map[uint64]struct{}) - err = filepath.Walk(dir, func(d string, fileInfo os.FileInfo, err error) error { - if err != nil { - // if dir does not exist, Size() returns the error. - // if dir/x disappeared while walking, Size() ignores dir/x. - if os.IsNotExist(err) && d != dir { - return nil - } - return err - } - - // Ignore directory sizes - if fileInfo == nil { - return nil - } - - s := fileInfo.Size() - if fileInfo.IsDir() || s == 0 { - return nil - } - - // Check inode to handle hard links correctly - inode := fileInfo.Sys().(*syscall.Stat_t).Ino - // inode is not a uint64 on all platforms. Cast it to avoid issues. - if _, exists := data[uint64(inode)]; exists { - return nil - } - // inode is not a uint64 on all platforms. Cast it to avoid issues. - data[uint64(inode)] = struct{}{} - - size += s - - return nil - }) - return -} diff --git a/vendor/github.com/docker/docker/pkg/directory/directory_windows.go b/vendor/github.com/docker/docker/pkg/directory/directory_windows.go deleted file mode 100644 index 6fb0917..0000000 --- a/vendor/github.com/docker/docker/pkg/directory/directory_windows.go +++ /dev/null @@ -1,37 +0,0 @@ -// +build windows - -package directory - -import ( - "os" - "path/filepath" -) - -// Size walks a directory tree and returns its total size in bytes. -func Size(dir string) (size int64, err error) { - err = filepath.Walk(dir, func(d string, fileInfo os.FileInfo, err error) error { - if err != nil { - // if dir does not exist, Size() returns the error. - // if dir/x disappeared while walking, Size() ignores dir/x. - if os.IsNotExist(err) && d != dir { - return nil - } - return err - } - - // Ignore directory sizes - if fileInfo == nil { - return nil - } - - s := fileInfo.Size() - if fileInfo.IsDir() || s == 0 { - return nil - } - - size += s - - return nil - }) - return -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/README.md b/vendor/github.com/docker/docker/pkg/discovery/README.md deleted file mode 100644 index 39777c2..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/README.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -page_title: Docker discovery -page_description: discovery -page_keywords: docker, clustering, discovery ---- - -# Discovery - -Docker comes with multiple Discovery backends. - -## Backends - -### Using etcd - -Point your Docker Engine instances to a common etcd instance. You can specify -the address Docker uses to advertise the node using the `--cluster-advertise` -flag. - -```bash -$ docker daemon -H= --cluster-advertise= --cluster-store etcd://,/ -``` - -### Using consul - -Point your Docker Engine instances to a common Consul instance. You can specify -the address Docker uses to advertise the node using the `--cluster-advertise` -flag. - -```bash -$ docker daemon -H= --cluster-advertise= --cluster-store consul:/// -``` - -### Using zookeeper - -Point your Docker Engine instances to a common Zookeeper instance. You can specify -the address Docker uses to advertise the node using the `--cluster-advertise` -flag. - -```bash -$ docker daemon -H= --cluster-advertise= --cluster-store zk://,/ -``` diff --git a/vendor/github.com/docker/docker/pkg/discovery/backends.go b/vendor/github.com/docker/docker/pkg/discovery/backends.go deleted file mode 100644 index 2eab550..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/backends.go +++ /dev/null @@ -1,107 +0,0 @@ -package discovery - -import ( - "fmt" - "net" - "strings" - "time" - - "github.com/Sirupsen/logrus" -) - -var ( - // Backends is a global map of discovery backends indexed by their - // associated scheme. - backends = make(map[string]Backend) -) - -// Register makes a discovery backend available by the provided scheme. -// If Register is called twice with the same scheme an error is returned. -func Register(scheme string, d Backend) error { - if _, exists := backends[scheme]; exists { - return fmt.Errorf("scheme already registered %s", scheme) - } - logrus.WithField("name", scheme).Debugf("Registering discovery service") - backends[scheme] = d - return nil -} - -func parse(rawurl string) (string, string) { - parts := strings.SplitN(rawurl, "://", 2) - - // nodes:port,node2:port => nodes://node1:port,node2:port - if len(parts) == 1 { - return "nodes", parts[0] - } - return parts[0], parts[1] -} - -// ParseAdvertise parses the --cluster-advertise daemon config which accepts -// : or : -func ParseAdvertise(advertise string) (string, error) { - var ( - iface *net.Interface - addrs []net.Addr - err error - ) - - addr, port, err := net.SplitHostPort(advertise) - - if err != nil { - return "", fmt.Errorf("invalid --cluster-advertise configuration: %s: %v", advertise, err) - } - - ip := net.ParseIP(addr) - // If it is a valid ip-address, use it as is - if ip != nil { - return advertise, nil - } - - // If advertise is a valid interface name, get the valid IPv4 address and use it to advertise - ifaceName := addr - iface, err = net.InterfaceByName(ifaceName) - if err != nil { - return "", fmt.Errorf("invalid cluster advertise IP address or interface name (%s) : %v", advertise, err) - } - - addrs, err = iface.Addrs() - if err != nil { - return "", fmt.Errorf("unable to get advertise IP address from interface (%s) : %v", advertise, err) - } - - if len(addrs) == 0 { - return "", fmt.Errorf("no available advertise IP address in interface (%s)", advertise) - } - - addr = "" - for _, a := range addrs { - ip, _, err := net.ParseCIDR(a.String()) - if err != nil { - return "", fmt.Errorf("error deriving advertise ip-address in interface (%s) : %v", advertise, err) - } - if ip.To4() == nil || ip.IsLoopback() { - continue - } - addr = ip.String() - break - } - if addr == "" { - return "", fmt.Errorf("could not find a valid ip-address in interface %s", advertise) - } - - addr = net.JoinHostPort(addr, port) - return addr, nil -} - -// New returns a new Discovery given a URL, heartbeat and ttl settings. -// Returns an error if the URL scheme is not supported. -func New(rawurl string, heartbeat time.Duration, ttl time.Duration, clusterOpts map[string]string) (Backend, error) { - scheme, uri := parse(rawurl) - if backend, exists := backends[scheme]; exists { - logrus.WithFields(logrus.Fields{"name": scheme, "uri": uri}).Debugf("Initializing discovery service") - err := backend.Initialize(uri, heartbeat, ttl, clusterOpts) - return backend, err - } - - return nil, ErrNotSupported -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/discovery.go b/vendor/github.com/docker/docker/pkg/discovery/discovery.go deleted file mode 100644 index ca7f587..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/discovery.go +++ /dev/null @@ -1,35 +0,0 @@ -package discovery - -import ( - "errors" - "time" -) - -var ( - // ErrNotSupported is returned when a discovery service is not supported. - ErrNotSupported = errors.New("discovery service not supported") - - // ErrNotImplemented is returned when discovery feature is not implemented - // by discovery backend. - ErrNotImplemented = errors.New("not implemented in this discovery service") -) - -// Watcher provides watching over a cluster for nodes joining and leaving. -type Watcher interface { - // Watch the discovery for entry changes. - // Returns a channel that will receive changes or an error. - // Providing a non-nil stopCh can be used to stop watching. - Watch(stopCh <-chan struct{}) (<-chan Entries, <-chan error) -} - -// Backend is implemented by discovery backends which manage cluster entries. -type Backend interface { - // Watcher must be provided by every backend. - Watcher - - // Initialize the discovery with URIs, a heartbeat, a ttl and optional settings. - Initialize(string, time.Duration, time.Duration, map[string]string) error - - // Register to the discovery. - Register(string) error -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/discovery_test.go b/vendor/github.com/docker/docker/pkg/discovery/discovery_test.go deleted file mode 100644 index 6084f3e..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/discovery_test.go +++ /dev/null @@ -1,137 +0,0 @@ -package discovery - -import ( - "testing" - - "github.com/go-check/check" -) - -// Hook up gocheck into the "go test" runner. -func Test(t *testing.T) { check.TestingT(t) } - -type DiscoverySuite struct{} - -var _ = check.Suite(&DiscoverySuite{}) - -func (s *DiscoverySuite) TestNewEntry(c *check.C) { - entry, err := NewEntry("127.0.0.1:2375") - c.Assert(err, check.IsNil) - c.Assert(entry.Equals(&Entry{Host: "127.0.0.1", Port: "2375"}), check.Equals, true) - c.Assert(entry.String(), check.Equals, "127.0.0.1:2375") - - entry, err = NewEntry("[2001:db8:0:f101::2]:2375") - c.Assert(err, check.IsNil) - c.Assert(entry.Equals(&Entry{Host: "2001:db8:0:f101::2", Port: "2375"}), check.Equals, true) - c.Assert(entry.String(), check.Equals, "[2001:db8:0:f101::2]:2375") - - _, err = NewEntry("127.0.0.1") - c.Assert(err, check.NotNil) -} - -func (s *DiscoverySuite) TestParse(c *check.C) { - scheme, uri := parse("127.0.0.1:2375") - c.Assert(scheme, check.Equals, "nodes") - c.Assert(uri, check.Equals, "127.0.0.1:2375") - - scheme, uri = parse("localhost:2375") - c.Assert(scheme, check.Equals, "nodes") - c.Assert(uri, check.Equals, "localhost:2375") - - scheme, uri = parse("scheme://127.0.0.1:2375") - c.Assert(scheme, check.Equals, "scheme") - c.Assert(uri, check.Equals, "127.0.0.1:2375") - - scheme, uri = parse("scheme://localhost:2375") - c.Assert(scheme, check.Equals, "scheme") - c.Assert(uri, check.Equals, "localhost:2375") - - scheme, uri = parse("") - c.Assert(scheme, check.Equals, "nodes") - c.Assert(uri, check.Equals, "") -} - -func (s *DiscoverySuite) TestCreateEntries(c *check.C) { - entries, err := CreateEntries(nil) - c.Assert(entries, check.DeepEquals, Entries{}) - c.Assert(err, check.IsNil) - - entries, err = CreateEntries([]string{"127.0.0.1:2375", "127.0.0.2:2375", "[2001:db8:0:f101::2]:2375", ""}) - c.Assert(err, check.IsNil) - expected := Entries{ - &Entry{Host: "127.0.0.1", Port: "2375"}, - &Entry{Host: "127.0.0.2", Port: "2375"}, - &Entry{Host: "2001:db8:0:f101::2", Port: "2375"}, - } - c.Assert(entries.Equals(expected), check.Equals, true) - - _, err = CreateEntries([]string{"127.0.0.1", "127.0.0.2"}) - c.Assert(err, check.NotNil) -} - -func (s *DiscoverySuite) TestContainsEntry(c *check.C) { - entries, err := CreateEntries([]string{"127.0.0.1:2375", "127.0.0.2:2375", ""}) - c.Assert(err, check.IsNil) - c.Assert(entries.Contains(&Entry{Host: "127.0.0.1", Port: "2375"}), check.Equals, true) - c.Assert(entries.Contains(&Entry{Host: "127.0.0.3", Port: "2375"}), check.Equals, false) -} - -func (s *DiscoverySuite) TestEntriesEquality(c *check.C) { - entries := Entries{ - &Entry{Host: "127.0.0.1", Port: "2375"}, - &Entry{Host: "127.0.0.2", Port: "2375"}, - } - - // Same - c.Assert(entries.Equals(Entries{ - &Entry{Host: "127.0.0.1", Port: "2375"}, - &Entry{Host: "127.0.0.2", Port: "2375"}, - }), check. - Equals, true) - - // Different size - c.Assert(entries.Equals(Entries{ - &Entry{Host: "127.0.0.1", Port: "2375"}, - &Entry{Host: "127.0.0.2", Port: "2375"}, - &Entry{Host: "127.0.0.3", Port: "2375"}, - }), check. - Equals, false) - - // Different content - c.Assert(entries.Equals(Entries{ - &Entry{Host: "127.0.0.1", Port: "2375"}, - &Entry{Host: "127.0.0.42", Port: "2375"}, - }), check. - Equals, false) - -} - -func (s *DiscoverySuite) TestEntriesDiff(c *check.C) { - entry1 := &Entry{Host: "1.1.1.1", Port: "1111"} - entry2 := &Entry{Host: "2.2.2.2", Port: "2222"} - entry3 := &Entry{Host: "3.3.3.3", Port: "3333"} - entries := Entries{entry1, entry2} - - // No diff - added, removed := entries.Diff(Entries{entry2, entry1}) - c.Assert(added, check.HasLen, 0) - c.Assert(removed, check.HasLen, 0) - - // Add - added, removed = entries.Diff(Entries{entry2, entry3, entry1}) - c.Assert(added, check.HasLen, 1) - c.Assert(added.Contains(entry3), check.Equals, true) - c.Assert(removed, check.HasLen, 0) - - // Remove - added, removed = entries.Diff(Entries{entry2}) - c.Assert(added, check.HasLen, 0) - c.Assert(removed, check.HasLen, 1) - c.Assert(removed.Contains(entry1), check.Equals, true) - - // Add and remove - added, removed = entries.Diff(Entries{entry1, entry3}) - c.Assert(added, check.HasLen, 1) - c.Assert(added.Contains(entry3), check.Equals, true) - c.Assert(removed, check.HasLen, 1) - c.Assert(removed.Contains(entry2), check.Equals, true) -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/entry.go b/vendor/github.com/docker/docker/pkg/discovery/entry.go deleted file mode 100644 index ce23bbf..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/entry.go +++ /dev/null @@ -1,94 +0,0 @@ -package discovery - -import "net" - -// NewEntry creates a new entry. -func NewEntry(url string) (*Entry, error) { - host, port, err := net.SplitHostPort(url) - if err != nil { - return nil, err - } - return &Entry{host, port}, nil -} - -// An Entry represents a host. -type Entry struct { - Host string - Port string -} - -// Equals returns true if cmp contains the same data. -func (e *Entry) Equals(cmp *Entry) bool { - return e.Host == cmp.Host && e.Port == cmp.Port -} - -// String returns the string form of an entry. -func (e *Entry) String() string { - return net.JoinHostPort(e.Host, e.Port) -} - -// Entries is a list of *Entry with some helpers. -type Entries []*Entry - -// Equals returns true if cmp contains the same data. -func (e Entries) Equals(cmp Entries) bool { - // Check if the file has really changed. - if len(e) != len(cmp) { - return false - } - for i := range e { - if !e[i].Equals(cmp[i]) { - return false - } - } - return true -} - -// Contains returns true if the Entries contain a given Entry. -func (e Entries) Contains(entry *Entry) bool { - for _, curr := range e { - if curr.Equals(entry) { - return true - } - } - return false -} - -// Diff compares two entries and returns the added and removed entries. -func (e Entries) Diff(cmp Entries) (Entries, Entries) { - added := Entries{} - for _, entry := range cmp { - if !e.Contains(entry) { - added = append(added, entry) - } - } - - removed := Entries{} - for _, entry := range e { - if !cmp.Contains(entry) { - removed = append(removed, entry) - } - } - - return added, removed -} - -// CreateEntries returns an array of entries based on the given addresses. -func CreateEntries(addrs []string) (Entries, error) { - entries := Entries{} - if addrs == nil { - return entries, nil - } - - for _, addr := range addrs { - if len(addr) == 0 { - continue - } - entry, err := NewEntry(addr) - if err != nil { - return nil, err - } - entries = append(entries, entry) - } - return entries, nil -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/file/file.go b/vendor/github.com/docker/docker/pkg/discovery/file/file.go deleted file mode 100644 index 2b8e27b..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/file/file.go +++ /dev/null @@ -1,107 +0,0 @@ -package file - -import ( - "fmt" - "io/ioutil" - "strings" - "time" - - "github.com/docker/docker/pkg/discovery" -) - -// Discovery is exported -type Discovery struct { - heartbeat time.Duration - path string -} - -func init() { - Init() -} - -// Init is exported -func Init() { - discovery.Register("file", &Discovery{}) -} - -// Initialize is exported -func (s *Discovery) Initialize(path string, heartbeat time.Duration, ttl time.Duration, _ map[string]string) error { - s.path = path - s.heartbeat = heartbeat - return nil -} - -func parseFileContent(content []byte) []string { - var result []string - for _, line := range strings.Split(strings.TrimSpace(string(content)), "\n") { - line = strings.TrimSpace(line) - // Ignoring line starts with # - if strings.HasPrefix(line, "#") { - continue - } - // Inlined # comment also ignored. - if strings.Contains(line, "#") { - line = line[0:strings.Index(line, "#")] - // Trim additional spaces caused by above stripping. - line = strings.TrimSpace(line) - } - result = append(result, discovery.Generate(line)...) - } - return result -} - -func (s *Discovery) fetch() (discovery.Entries, error) { - fileContent, err := ioutil.ReadFile(s.path) - if err != nil { - return nil, fmt.Errorf("failed to read '%s': %v", s.path, err) - } - return discovery.CreateEntries(parseFileContent(fileContent)) -} - -// Watch is exported -func (s *Discovery) Watch(stopCh <-chan struct{}) (<-chan discovery.Entries, <-chan error) { - ch := make(chan discovery.Entries) - errCh := make(chan error) - ticker := time.NewTicker(s.heartbeat) - - go func() { - defer close(errCh) - defer close(ch) - - // Send the initial entries if available. - currentEntries, err := s.fetch() - if err != nil { - errCh <- err - } else { - ch <- currentEntries - } - - // Periodically send updates. - for { - select { - case <-ticker.C: - newEntries, err := s.fetch() - if err != nil { - errCh <- err - continue - } - - // Check if the file has really changed. - if !newEntries.Equals(currentEntries) { - ch <- newEntries - } - currentEntries = newEntries - case <-stopCh: - ticker.Stop() - return - } - } - }() - - return ch, errCh -} - -// Register is exported -func (s *Discovery) Register(addr string) error { - return discovery.ErrNotImplemented -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/file/file_test.go b/vendor/github.com/docker/docker/pkg/discovery/file/file_test.go deleted file mode 100644 index 667f00b..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/file/file_test.go +++ /dev/null @@ -1,114 +0,0 @@ -package file - -import ( - "io/ioutil" - "os" - "testing" - - "github.com/docker/docker/pkg/discovery" - - "github.com/go-check/check" -) - -// Hook up gocheck into the "go test" runner. -func Test(t *testing.T) { check.TestingT(t) } - -type DiscoverySuite struct{} - -var _ = check.Suite(&DiscoverySuite{}) - -func (s *DiscoverySuite) TestInitialize(c *check.C) { - d := &Discovery{} - d.Initialize("/path/to/file", 1000, 0, nil) - c.Assert(d.path, check.Equals, "/path/to/file") -} - -func (s *DiscoverySuite) TestNew(c *check.C) { - d, err := discovery.New("file:///path/to/file", 0, 0, nil) - c.Assert(err, check.IsNil) - c.Assert(d.(*Discovery).path, check.Equals, "/path/to/file") -} - -func (s *DiscoverySuite) TestContent(c *check.C) { - data := ` -1.1.1.[1:2]:1111 -2.2.2.[2:4]:2222 -` - ips := parseFileContent([]byte(data)) - c.Assert(ips, check.HasLen, 5) - c.Assert(ips[0], check.Equals, "1.1.1.1:1111") - c.Assert(ips[1], check.Equals, "1.1.1.2:1111") - c.Assert(ips[2], check.Equals, "2.2.2.2:2222") - c.Assert(ips[3], check.Equals, "2.2.2.3:2222") - c.Assert(ips[4], check.Equals, "2.2.2.4:2222") -} - -func (s *DiscoverySuite) TestRegister(c *check.C) { - discovery := &Discovery{path: "/path/to/file"} - c.Assert(discovery.Register("0.0.0.0"), check.NotNil) -} - -func (s *DiscoverySuite) TestParsingContentsWithComments(c *check.C) { - data := ` -### test ### -1.1.1.1:1111 # inline comment -# 2.2.2.2:2222 - ### empty line with comment - 3.3.3.3:3333 -### test ### -` - ips := parseFileContent([]byte(data)) - c.Assert(ips, check.HasLen, 2) - c.Assert("1.1.1.1:1111", check.Equals, ips[0]) - c.Assert("3.3.3.3:3333", check.Equals, ips[1]) -} - -func (s *DiscoverySuite) TestWatch(c *check.C) { - data := ` -1.1.1.1:1111 -2.2.2.2:2222 -` - expected := discovery.Entries{ - &discovery.Entry{Host: "1.1.1.1", Port: "1111"}, - &discovery.Entry{Host: "2.2.2.2", Port: "2222"}, - } - - // Create a temporary file and remove it. - tmp, err := ioutil.TempFile(os.TempDir(), "discovery-file-test") - c.Assert(err, check.IsNil) - c.Assert(tmp.Close(), check.IsNil) - c.Assert(os.Remove(tmp.Name()), check.IsNil) - - // Set up file discovery. - d := &Discovery{} - d.Initialize(tmp.Name(), 1000, 0, nil) - stopCh := make(chan struct{}) - ch, errCh := d.Watch(stopCh) - - // Make sure it fires errors since the file doesn't exist. - c.Assert(<-errCh, check.NotNil) - // We have to drain the error channel otherwise Watch will get stuck. - go func() { - for range errCh { - } - }() - - // Write the file and make sure we get the expected value back. - c.Assert(ioutil.WriteFile(tmp.Name(), []byte(data), 0600), check.IsNil) - c.Assert(<-ch, check.DeepEquals, expected) - - // Add a new entry and look it up. - expected = append(expected, &discovery.Entry{Host: "3.3.3.3", Port: "3333"}) - f, err := os.OpenFile(tmp.Name(), os.O_APPEND|os.O_WRONLY, 0600) - c.Assert(err, check.IsNil) - c.Assert(f, check.NotNil) - _, err = f.WriteString("\n3.3.3.3:3333\n") - c.Assert(err, check.IsNil) - f.Close() - c.Assert(<-ch, check.DeepEquals, expected) - - // Stop and make sure it closes all channels. - close(stopCh) - c.Assert(<-ch, check.IsNil) - c.Assert(<-errCh, check.IsNil) -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/generator.go b/vendor/github.com/docker/docker/pkg/discovery/generator.go deleted file mode 100644 index d222982..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/generator.go +++ /dev/null @@ -1,35 +0,0 @@ -package discovery - -import ( - "fmt" - "regexp" - "strconv" -) - -// Generate takes care of IP generation -func Generate(pattern string) []string { - re, _ := regexp.Compile(`\[(.+):(.+)\]`) - submatch := re.FindStringSubmatch(pattern) - if submatch == nil { - return []string{pattern} - } - - from, err := strconv.Atoi(submatch[1]) - if err != nil { - return []string{pattern} - } - to, err := strconv.Atoi(submatch[2]) - if err != nil { - return []string{pattern} - } - - template := re.ReplaceAllString(pattern, "%d") - - var result []string - for val := from; val <= to; val++ { - entry := fmt.Sprintf(template, val) - result = append(result, entry) - } - - return result -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/generator_test.go b/vendor/github.com/docker/docker/pkg/discovery/generator_test.go deleted file mode 100644 index 6281c46..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/generator_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package discovery - -import ( - "github.com/go-check/check" -) - -func (s *DiscoverySuite) TestGeneratorNotGenerate(c *check.C) { - ips := Generate("127.0.0.1") - c.Assert(len(ips), check.Equals, 1) - c.Assert(ips[0], check.Equals, "127.0.0.1") -} - -func (s *DiscoverySuite) TestGeneratorWithPortNotGenerate(c *check.C) { - ips := Generate("127.0.0.1:8080") - c.Assert(len(ips), check.Equals, 1) - c.Assert(ips[0], check.Equals, "127.0.0.1:8080") -} - -func (s *DiscoverySuite) TestGeneratorMatchFailedNotGenerate(c *check.C) { - ips := Generate("127.0.0.[1]") - c.Assert(len(ips), check.Equals, 1) - c.Assert(ips[0], check.Equals, "127.0.0.[1]") -} - -func (s *DiscoverySuite) TestGeneratorWithPort(c *check.C) { - ips := Generate("127.0.0.[1:11]:2375") - c.Assert(len(ips), check.Equals, 11) - c.Assert(ips[0], check.Equals, "127.0.0.1:2375") - c.Assert(ips[1], check.Equals, "127.0.0.2:2375") - c.Assert(ips[2], check.Equals, "127.0.0.3:2375") - c.Assert(ips[3], check.Equals, "127.0.0.4:2375") - c.Assert(ips[4], check.Equals, "127.0.0.5:2375") - c.Assert(ips[5], check.Equals, "127.0.0.6:2375") - c.Assert(ips[6], check.Equals, "127.0.0.7:2375") - c.Assert(ips[7], check.Equals, "127.0.0.8:2375") - c.Assert(ips[8], check.Equals, "127.0.0.9:2375") - c.Assert(ips[9], check.Equals, "127.0.0.10:2375") - c.Assert(ips[10], check.Equals, "127.0.0.11:2375") -} - -func (s *DiscoverySuite) TestGenerateWithMalformedInputAtRangeStart(c *check.C) { - malformedInput := "127.0.0.[x:11]:2375" - ips := Generate(malformedInput) - c.Assert(len(ips), check.Equals, 1) - c.Assert(ips[0], check.Equals, malformedInput) -} - -func (s *DiscoverySuite) TestGenerateWithMalformedInputAtRangeEnd(c *check.C) { - malformedInput := "127.0.0.[1:x]:2375" - ips := Generate(malformedInput) - c.Assert(len(ips), check.Equals, 1) - c.Assert(ips[0], check.Equals, malformedInput) -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/kv/kv.go b/vendor/github.com/docker/docker/pkg/discovery/kv/kv.go deleted file mode 100644 index 77eee7d..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/kv/kv.go +++ /dev/null @@ -1,192 +0,0 @@ -package kv - -import ( - "fmt" - "path" - "strings" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/discovery" - "github.com/docker/go-connections/tlsconfig" - "github.com/docker/libkv" - "github.com/docker/libkv/store" - "github.com/docker/libkv/store/consul" - "github.com/docker/libkv/store/etcd" - "github.com/docker/libkv/store/zookeeper" -) - -const ( - defaultDiscoveryPath = "docker/nodes" -) - -// Discovery is exported -type Discovery struct { - backend store.Backend - store store.Store - heartbeat time.Duration - ttl time.Duration - prefix string - path string -} - -func init() { - Init() -} - -// Init is exported -func Init() { - // Register to libkv - zookeeper.Register() - consul.Register() - etcd.Register() - - // Register to internal discovery service - discovery.Register("zk", &Discovery{backend: store.ZK}) - discovery.Register("consul", &Discovery{backend: store.CONSUL}) - discovery.Register("etcd", &Discovery{backend: store.ETCD}) -} - -// Initialize is exported -func (s *Discovery) Initialize(uris string, heartbeat time.Duration, ttl time.Duration, clusterOpts map[string]string) error { - var ( - parts = strings.SplitN(uris, "/", 2) - addrs = strings.Split(parts[0], ",") - err error - ) - - // A custom prefix to the path can be optionally used. - if len(parts) == 2 { - s.prefix = parts[1] - } - - s.heartbeat = heartbeat - s.ttl = ttl - - // Use a custom path if specified in discovery options - dpath := defaultDiscoveryPath - if clusterOpts["kv.path"] != "" { - dpath = clusterOpts["kv.path"] - } - - s.path = path.Join(s.prefix, dpath) - - var config *store.Config - if clusterOpts["kv.cacertfile"] != "" && clusterOpts["kv.certfile"] != "" && clusterOpts["kv.keyfile"] != "" { - logrus.Info("Initializing discovery with TLS") - tlsConfig, err := tlsconfig.Client(tlsconfig.Options{ - CAFile: clusterOpts["kv.cacertfile"], - CertFile: clusterOpts["kv.certfile"], - KeyFile: clusterOpts["kv.keyfile"], - }) - if err != nil { - return err - } - config = &store.Config{ - // Set ClientTLS to trigger https (bug in libkv/etcd) - ClientTLS: &store.ClientTLSConfig{ - CACertFile: clusterOpts["kv.cacertfile"], - CertFile: clusterOpts["kv.certfile"], - KeyFile: clusterOpts["kv.keyfile"], - }, - // The actual TLS config that will be used - TLS: tlsConfig, - } - } else { - logrus.Info("Initializing discovery without TLS") - } - - // Creates a new store, will ignore options given - // if not supported by the chosen store - s.store, err = libkv.NewStore(s.backend, addrs, config) - return err -} - -// Watch the store until either there's a store error or we receive a stop request. -// Returns false if we shouldn't attempt watching the store anymore (stop request received). -func (s *Discovery) watchOnce(stopCh <-chan struct{}, watchCh <-chan []*store.KVPair, discoveryCh chan discovery.Entries, errCh chan error) bool { - for { - select { - case pairs := <-watchCh: - if pairs == nil { - return true - } - - logrus.WithField("discovery", s.backend).Debugf("Watch triggered with %d nodes", len(pairs)) - - // Convert `KVPair` into `discovery.Entry`. - addrs := make([]string, len(pairs)) - for _, pair := range pairs { - addrs = append(addrs, string(pair.Value)) - } - - entries, err := discovery.CreateEntries(addrs) - if err != nil { - errCh <- err - } else { - discoveryCh <- entries - } - case <-stopCh: - // We were requested to stop watching. - return false - } - } -} - -// Watch is exported -func (s *Discovery) Watch(stopCh <-chan struct{}) (<-chan discovery.Entries, <-chan error) { - ch := make(chan discovery.Entries) - errCh := make(chan error) - - go func() { - defer close(ch) - defer close(errCh) - - // Forever: Create a store watch, watch until we get an error and then try again. - // Will only stop if we receive a stopCh request. - for { - // Create the path to watch if it does not exist yet - exists, err := s.store.Exists(s.path) - if err != nil { - errCh <- err - } - if !exists { - if err := s.store.Put(s.path, []byte(""), &store.WriteOptions{IsDir: true}); err != nil { - errCh <- err - } - } - - // Set up a watch. - watchCh, err := s.store.WatchTree(s.path, stopCh) - if err != nil { - errCh <- err - } else { - if !s.watchOnce(stopCh, watchCh, ch, errCh) { - return - } - } - - // If we get here it means the store watch channel was closed. This - // is unexpected so let's retry later. - errCh <- fmt.Errorf("Unexpected watch error") - time.Sleep(s.heartbeat) - } - }() - return ch, errCh -} - -// Register is exported -func (s *Discovery) Register(addr string) error { - opts := &store.WriteOptions{TTL: s.ttl} - return s.store.Put(path.Join(s.path, addr), []byte(addr), opts) -} - -// Store returns the underlying store used by KV discovery. -func (s *Discovery) Store() store.Store { - return s.store -} - -// Prefix returns the store prefix -func (s *Discovery) Prefix() string { - return s.prefix -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/kv/kv_test.go b/vendor/github.com/docker/docker/pkg/discovery/kv/kv_test.go deleted file mode 100644 index dab3939..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/kv/kv_test.go +++ /dev/null @@ -1,324 +0,0 @@ -package kv - -import ( - "errors" - "io/ioutil" - "os" - "path" - "testing" - "time" - - "github.com/docker/docker/pkg/discovery" - "github.com/docker/libkv" - "github.com/docker/libkv/store" - - "github.com/go-check/check" -) - -// Hook up gocheck into the "go test" runner. -func Test(t *testing.T) { check.TestingT(t) } - -type DiscoverySuite struct{} - -var _ = check.Suite(&DiscoverySuite{}) - -func (ds *DiscoverySuite) TestInitialize(c *check.C) { - storeMock := &FakeStore{ - Endpoints: []string{"127.0.0.1"}, - } - d := &Discovery{backend: store.CONSUL} - d.Initialize("127.0.0.1", 0, 0, nil) - d.store = storeMock - - s := d.store.(*FakeStore) - c.Assert(s.Endpoints, check.HasLen, 1) - c.Assert(s.Endpoints[0], check.Equals, "127.0.0.1") - c.Assert(d.path, check.Equals, defaultDiscoveryPath) - - storeMock = &FakeStore{ - Endpoints: []string{"127.0.0.1:1234"}, - } - d = &Discovery{backend: store.CONSUL} - d.Initialize("127.0.0.1:1234/path", 0, 0, nil) - d.store = storeMock - - s = d.store.(*FakeStore) - c.Assert(s.Endpoints, check.HasLen, 1) - c.Assert(s.Endpoints[0], check.Equals, "127.0.0.1:1234") - c.Assert(d.path, check.Equals, "path/"+defaultDiscoveryPath) - - storeMock = &FakeStore{ - Endpoints: []string{"127.0.0.1:1234", "127.0.0.2:1234", "127.0.0.3:1234"}, - } - d = &Discovery{backend: store.CONSUL} - d.Initialize("127.0.0.1:1234,127.0.0.2:1234,127.0.0.3:1234/path", 0, 0, nil) - d.store = storeMock - - s = d.store.(*FakeStore) - c.Assert(s.Endpoints, check.HasLen, 3) - c.Assert(s.Endpoints[0], check.Equals, "127.0.0.1:1234") - c.Assert(s.Endpoints[1], check.Equals, "127.0.0.2:1234") - c.Assert(s.Endpoints[2], check.Equals, "127.0.0.3:1234") - - c.Assert(d.path, check.Equals, "path/"+defaultDiscoveryPath) -} - -// Extremely limited mock store so we can test initialization -type Mock struct { - // Endpoints passed to InitializeMock - Endpoints []string - - // Options passed to InitializeMock - Options *store.Config -} - -func NewMock(endpoints []string, options *store.Config) (store.Store, error) { - s := &Mock{} - s.Endpoints = endpoints - s.Options = options - return s, nil -} -func (s *Mock) Put(key string, value []byte, opts *store.WriteOptions) error { - return errors.New("Put not supported") -} -func (s *Mock) Get(key string) (*store.KVPair, error) { - return nil, errors.New("Get not supported") -} -func (s *Mock) Delete(key string) error { - return errors.New("Delete not supported") -} - -// Exists mock -func (s *Mock) Exists(key string) (bool, error) { - return false, errors.New("Exists not supported") -} - -// Watch mock -func (s *Mock) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error) { - return nil, errors.New("Watch not supported") -} - -// WatchTree mock -func (s *Mock) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error) { - return nil, errors.New("WatchTree not supported") -} - -// NewLock mock -func (s *Mock) NewLock(key string, options *store.LockOptions) (store.Locker, error) { - return nil, errors.New("NewLock not supported") -} - -// List mock -func (s *Mock) List(prefix string) ([]*store.KVPair, error) { - return nil, errors.New("List not supported") -} - -// DeleteTree mock -func (s *Mock) DeleteTree(prefix string) error { - return errors.New("DeleteTree not supported") -} - -// AtomicPut mock -func (s *Mock) AtomicPut(key string, value []byte, previous *store.KVPair, opts *store.WriteOptions) (bool, *store.KVPair, error) { - return false, nil, errors.New("AtomicPut not supported") -} - -// AtomicDelete mock -func (s *Mock) AtomicDelete(key string, previous *store.KVPair) (bool, error) { - return false, errors.New("AtomicDelete not supported") -} - -// Close mock -func (s *Mock) Close() { - return -} - -func (ds *DiscoverySuite) TestInitializeWithCerts(c *check.C) { - cert := `-----BEGIN CERTIFICATE----- -MIIDCDCCAfKgAwIBAgIICifG7YeiQOEwCwYJKoZIhvcNAQELMBIxEDAOBgNVBAMT -B1Rlc3QgQ0EwHhcNMTUxMDAxMjMwMDAwWhcNMjAwOTI5MjMwMDAwWjASMRAwDgYD -VQQDEwdUZXN0IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1wRC -O+flnLTK5ImjTurNRHwSejuqGbc4CAvpB0hS+z0QlSs4+zE9h80aC4hz+6caRpds -+J908Q+RvAittMHbpc7VjbZP72G6fiXk7yPPl6C10HhRSoSi3nY+B7F2E8cuz14q -V2e+ejhWhSrBb/keyXpcyjoW1BOAAJ2TIclRRkICSCZrpXUyXxAvzXfpFXo1RhSb -UywN11pfiCQzDUN7sPww9UzFHuAHZHoyfTr27XnJYVUerVYrCPq8vqfn//01qz55 -Xs0hvzGdlTFXhuabFtQnKFH5SNwo/fcznhB7rePOwHojxOpXTBepUCIJLbtNnWFT -V44t9gh5IqIWtoBReQIDAQABo2YwZDAOBgNVHQ8BAf8EBAMCAAYwEgYDVR0TAQH/ -BAgwBgEB/wIBAjAdBgNVHQ4EFgQUZKUI8IIjIww7X/6hvwggQK4bD24wHwYDVR0j -BBgwFoAUZKUI8IIjIww7X/6hvwggQK4bD24wCwYJKoZIhvcNAQELA4IBAQDES2cz -7sCQfDCxCIWH7X8kpi/JWExzUyQEJ0rBzN1m3/x8ySRxtXyGekimBqQwQdFqlwMI -xzAQKkh3ue8tNSzRbwqMSyH14N1KrSxYS9e9szJHfUasoTpQGPmDmGIoRJuq1h6M -ej5x1SCJ7GWCR6xEXKUIE9OftXm9TdFzWa7Ja3OHz/mXteii8VXDuZ5ACq6EE5bY -8sP4gcICfJ5fTrpTlk9FIqEWWQrCGa5wk95PGEj+GJpNogjXQ97wVoo/Y3p1brEn -t5zjN9PAq4H1fuCMdNNA+p1DHNwd+ELTxcMAnb2ajwHvV6lKPXutrTFc4umJToBX -FpTxDmJHEV4bzUzh ------END CERTIFICATE----- -` - key := `-----BEGIN RSA PRIVATE KEY----- -MIIEpQIBAAKCAQEA1wRCO+flnLTK5ImjTurNRHwSejuqGbc4CAvpB0hS+z0QlSs4 -+zE9h80aC4hz+6caRpds+J908Q+RvAittMHbpc7VjbZP72G6fiXk7yPPl6C10HhR -SoSi3nY+B7F2E8cuz14qV2e+ejhWhSrBb/keyXpcyjoW1BOAAJ2TIclRRkICSCZr -pXUyXxAvzXfpFXo1RhSbUywN11pfiCQzDUN7sPww9UzFHuAHZHoyfTr27XnJYVUe -rVYrCPq8vqfn//01qz55Xs0hvzGdlTFXhuabFtQnKFH5SNwo/fcznhB7rePOwHoj -xOpXTBepUCIJLbtNnWFTV44t9gh5IqIWtoBReQIDAQABAoIBAHSWipORGp/uKFXj -i/mut776x8ofsAxhnLBARQr93ID+i49W8H7EJGkOfaDjTICYC1dbpGrri61qk8sx -qX7p3v/5NzKwOIfEpirgwVIqSNYe/ncbxnhxkx6tXtUtFKmEx40JskvSpSYAhmmO -1XSx0E/PWaEN/nLgX/f1eWJIlxlQkk3QeqL+FGbCXI48DEtlJ9+MzMu4pAwZTpj5 -5qtXo5JJ0jRGfJVPAOznRsYqv864AhMdMIWguzk6EGnbaCWwPcfcn+h9a5LMdony -MDHfBS7bb5tkF3+AfnVY3IBMVx7YlsD9eAyajlgiKu4zLbwTRHjXgShy+4Oussz0 -ugNGnkECgYEA/hi+McrZC8C4gg6XqK8+9joD8tnyDZDz88BQB7CZqABUSwvjDqlP -L8hcwo/lzvjBNYGkqaFPUICGWKjeCtd8pPS2DCVXxDQX4aHF1vUur0uYNncJiV3N -XQz4Iemsa6wnKf6M67b5vMXICw7dw0HZCdIHD1hnhdtDz0uVpeevLZ8CgYEA2KCT -Y43lorjrbCgMqtlefkr3GJA9dey+hTzCiWEOOqn9RqGoEGUday0sKhiLofOgmN2B -LEukpKIey8s+Q/cb6lReajDVPDsMweX8i7hz3Wa4Ugp4Xa5BpHqu8qIAE2JUZ7bU -t88aQAYE58pUF+/Lq1QzAQdrjjzQBx6SrBxieecCgYEAvukoPZEC8mmiN1VvbTX+ -QFHmlZha3QaDxChB+QUe7bMRojEUL/fVnzkTOLuVFqSfxevaI/km9n0ac5KtAchV -xjp2bTnBb5EUQFqjopYktWA+xO07JRJtMfSEmjZPbbay1kKC7rdTfBm961EIHaRj -xZUf6M+rOE8964oGrdgdLlECgYEA046GQmx6fh7/82FtdZDRQp9tj3SWQUtSiQZc -qhO59Lq8mjUXz+MgBuJXxkiwXRpzlbaFB0Bca1fUoYw8o915SrDYf/Zu2OKGQ/qa -V81sgiVmDuEgycR7YOlbX6OsVUHrUlpwhY3hgfMe6UtkMvhBvHF/WhroBEIJm1pV -PXZ/CbMCgYEApNWVktFBjOaYfY6SNn4iSts1jgsQbbpglg3kT7PLKjCAhI6lNsbk -dyT7ut01PL6RaW4SeQWtrJIVQaM6vF3pprMKqlc5XihOGAmVqH7rQx9rtQB5TicL -BFrwkQE4HQtQBV60hYQUzzlSk44VFDz+jxIEtacRHaomDRh2FtOTz+I= ------END RSA PRIVATE KEY----- -` - certFile, err := ioutil.TempFile("", "cert") - c.Assert(err, check.IsNil) - defer os.Remove(certFile.Name()) - certFile.Write([]byte(cert)) - certFile.Close() - keyFile, err := ioutil.TempFile("", "key") - c.Assert(err, check.IsNil) - defer os.Remove(keyFile.Name()) - keyFile.Write([]byte(key)) - keyFile.Close() - - libkv.AddStore("mock", NewMock) - d := &Discovery{backend: "mock"} - err = d.Initialize("127.0.0.3:1234", 0, 0, map[string]string{ - "kv.cacertfile": certFile.Name(), - "kv.certfile": certFile.Name(), - "kv.keyfile": keyFile.Name(), - }) - c.Assert(err, check.IsNil) - s := d.store.(*Mock) - c.Assert(s.Options.TLS, check.NotNil) - c.Assert(s.Options.TLS.RootCAs, check.NotNil) - c.Assert(s.Options.TLS.Certificates, check.HasLen, 1) -} - -func (ds *DiscoverySuite) TestWatch(c *check.C) { - mockCh := make(chan []*store.KVPair) - - storeMock := &FakeStore{ - Endpoints: []string{"127.0.0.1:1234"}, - mockKVChan: mockCh, - } - - d := &Discovery{backend: store.CONSUL} - d.Initialize("127.0.0.1:1234/path", 0, 0, nil) - d.store = storeMock - - expected := discovery.Entries{ - &discovery.Entry{Host: "1.1.1.1", Port: "1111"}, - &discovery.Entry{Host: "2.2.2.2", Port: "2222"}, - } - kvs := []*store.KVPair{ - {Key: path.Join("path", defaultDiscoveryPath, "1.1.1.1"), Value: []byte("1.1.1.1:1111")}, - {Key: path.Join("path", defaultDiscoveryPath, "2.2.2.2"), Value: []byte("2.2.2.2:2222")}, - } - - stopCh := make(chan struct{}) - ch, errCh := d.Watch(stopCh) - - // It should fire an error since the first WatchTree call failed. - c.Assert(<-errCh, check.ErrorMatches, "test error") - // We have to drain the error channel otherwise Watch will get stuck. - go func() { - for range errCh { - } - }() - - // Push the entries into the store channel and make sure discovery emits. - mockCh <- kvs - c.Assert(<-ch, check.DeepEquals, expected) - - // Add a new entry. - expected = append(expected, &discovery.Entry{Host: "3.3.3.3", Port: "3333"}) - kvs = append(kvs, &store.KVPair{Key: path.Join("path", defaultDiscoveryPath, "3.3.3.3"), Value: []byte("3.3.3.3:3333")}) - mockCh <- kvs - c.Assert(<-ch, check.DeepEquals, expected) - - close(mockCh) - // Give it enough time to call WatchTree. - time.Sleep(3 * time.Second) - - // Stop and make sure it closes all channels. - close(stopCh) - c.Assert(<-ch, check.IsNil) - c.Assert(<-errCh, check.IsNil) -} - -// FakeStore implements store.Store methods. It mocks all store -// function in a simple, naive way. -type FakeStore struct { - Endpoints []string - Options *store.Config - mockKVChan <-chan []*store.KVPair - - watchTreeCallCount int -} - -func (s *FakeStore) Put(key string, value []byte, options *store.WriteOptions) error { - return nil -} - -func (s *FakeStore) Get(key string) (*store.KVPair, error) { - return nil, nil -} - -func (s *FakeStore) Delete(key string) error { - return nil -} - -func (s *FakeStore) Exists(key string) (bool, error) { - return true, nil -} - -func (s *FakeStore) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error) { - return nil, nil -} - -// WatchTree will fail the first time, and return the mockKVchan afterwards. -// This is the behavior we need for testing.. If we need 'moar', should update this. -func (s *FakeStore) WatchTree(directory string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error) { - if s.watchTreeCallCount == 0 { - s.watchTreeCallCount = 1 - return nil, errors.New("test error") - } - // First calls error - return s.mockKVChan, nil -} - -func (s *FakeStore) NewLock(key string, options *store.LockOptions) (store.Locker, error) { - return nil, nil -} - -func (s *FakeStore) List(directory string) ([]*store.KVPair, error) { - return []*store.KVPair{}, nil -} - -func (s *FakeStore) DeleteTree(directory string) error { - return nil -} - -func (s *FakeStore) AtomicPut(key string, value []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error) { - return true, nil, nil -} - -func (s *FakeStore) AtomicDelete(key string, previous *store.KVPair) (bool, error) { - return true, nil -} - -func (s *FakeStore) Close() { -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/memory/memory.go b/vendor/github.com/docker/docker/pkg/discovery/memory/memory.go deleted file mode 100644 index ba8b1f5..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/memory/memory.go +++ /dev/null @@ -1,93 +0,0 @@ -package memory - -import ( - "sync" - "time" - - "github.com/docker/docker/pkg/discovery" -) - -// Discovery implements a discovery backend that keeps -// data in memory. -type Discovery struct { - heartbeat time.Duration - values []string - mu sync.Mutex -} - -func init() { - Init() -} - -// Init registers the memory backend on demand. -func Init() { - discovery.Register("memory", &Discovery{}) -} - -// Initialize sets the heartbeat for the memory backend. -func (s *Discovery) Initialize(_ string, heartbeat time.Duration, _ time.Duration, _ map[string]string) error { - s.heartbeat = heartbeat - s.values = make([]string, 0) - return nil -} - -// Watch sends periodic discovery updates to a channel. -func (s *Discovery) Watch(stopCh <-chan struct{}) (<-chan discovery.Entries, <-chan error) { - ch := make(chan discovery.Entries) - errCh := make(chan error) - ticker := time.NewTicker(s.heartbeat) - - go func() { - defer close(errCh) - defer close(ch) - - // Send the initial entries if available. - var currentEntries discovery.Entries - var err error - - s.mu.Lock() - if len(s.values) > 0 { - currentEntries, err = discovery.CreateEntries(s.values) - } - s.mu.Unlock() - - if err != nil { - errCh <- err - } else if currentEntries != nil { - ch <- currentEntries - } - - // Periodically send updates. - for { - select { - case <-ticker.C: - s.mu.Lock() - newEntries, err := discovery.CreateEntries(s.values) - s.mu.Unlock() - if err != nil { - errCh <- err - continue - } - - // Check if the file has really changed. - if !newEntries.Equals(currentEntries) { - ch <- newEntries - } - currentEntries = newEntries - case <-stopCh: - ticker.Stop() - return - } - } - }() - - return ch, errCh -} - -// Register adds a new address to the discovery. -func (s *Discovery) Register(addr string) error { - s.mu.Lock() - s.values = append(s.values, addr) - s.mu.Unlock() - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/memory/memory_test.go b/vendor/github.com/docker/docker/pkg/discovery/memory/memory_test.go deleted file mode 100644 index c2da0a0..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/memory/memory_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package memory - -import ( - "testing" - - "github.com/docker/docker/pkg/discovery" - "github.com/go-check/check" -) - -// Hook up gocheck into the "go test" runner. -func Test(t *testing.T) { check.TestingT(t) } - -type discoverySuite struct{} - -var _ = check.Suite(&discoverySuite{}) - -func (s *discoverySuite) TestWatch(c *check.C) { - d := &Discovery{} - d.Initialize("foo", 1000, 0, nil) - stopCh := make(chan struct{}) - ch, errCh := d.Watch(stopCh) - - // We have to drain the error channel otherwise Watch will get stuck. - go func() { - for range errCh { - } - }() - - expected := discovery.Entries{ - &discovery.Entry{Host: "1.1.1.1", Port: "1111"}, - } - - c.Assert(d.Register("1.1.1.1:1111"), check.IsNil) - c.Assert(<-ch, check.DeepEquals, expected) - - expected = discovery.Entries{ - &discovery.Entry{Host: "1.1.1.1", Port: "1111"}, - &discovery.Entry{Host: "2.2.2.2", Port: "2222"}, - } - - c.Assert(d.Register("2.2.2.2:2222"), check.IsNil) - c.Assert(<-ch, check.DeepEquals, expected) - - // Stop and make sure it closes all channels. - close(stopCh) - c.Assert(<-ch, check.IsNil) - c.Assert(<-errCh, check.IsNil) -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/nodes/nodes.go b/vendor/github.com/docker/docker/pkg/discovery/nodes/nodes.go deleted file mode 100644 index c0e3c07..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/nodes/nodes.go +++ /dev/null @@ -1,54 +0,0 @@ -package nodes - -import ( - "fmt" - "strings" - "time" - - "github.com/docker/docker/pkg/discovery" -) - -// Discovery is exported -type Discovery struct { - entries discovery.Entries -} - -func init() { - Init() -} - -// Init is exported -func Init() { - discovery.Register("nodes", &Discovery{}) -} - -// Initialize is exported -func (s *Discovery) Initialize(uris string, _ time.Duration, _ time.Duration, _ map[string]string) error { - for _, input := range strings.Split(uris, ",") { - for _, ip := range discovery.Generate(input) { - entry, err := discovery.NewEntry(ip) - if err != nil { - return fmt.Errorf("%s, please check you are using the correct discovery (missing token:// ?)", err.Error()) - } - s.entries = append(s.entries, entry) - } - } - - return nil -} - -// Watch is exported -func (s *Discovery) Watch(stopCh <-chan struct{}) (<-chan discovery.Entries, <-chan error) { - ch := make(chan discovery.Entries) - go func() { - defer close(ch) - ch <- s.entries - <-stopCh - }() - return ch, nil -} - -// Register is exported -func (s *Discovery) Register(addr string) error { - return discovery.ErrNotImplemented -} diff --git a/vendor/github.com/docker/docker/pkg/discovery/nodes/nodes_test.go b/vendor/github.com/docker/docker/pkg/discovery/nodes/nodes_test.go deleted file mode 100644 index e26568c..0000000 --- a/vendor/github.com/docker/docker/pkg/discovery/nodes/nodes_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package nodes - -import ( - "testing" - - "github.com/docker/docker/pkg/discovery" - - "github.com/go-check/check" -) - -// Hook up gocheck into the "go test" runner. -func Test(t *testing.T) { check.TestingT(t) } - -type DiscoverySuite struct{} - -var _ = check.Suite(&DiscoverySuite{}) - -func (s *DiscoverySuite) TestInitialize(c *check.C) { - d := &Discovery{} - d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0, nil) - c.Assert(len(d.entries), check.Equals, 2) - c.Assert(d.entries[0].String(), check.Equals, "1.1.1.1:1111") - c.Assert(d.entries[1].String(), check.Equals, "2.2.2.2:2222") -} - -func (s *DiscoverySuite) TestInitializeWithPattern(c *check.C) { - d := &Discovery{} - d.Initialize("1.1.1.[1:2]:1111,2.2.2.[2:4]:2222", 0, 0, nil) - c.Assert(len(d.entries), check.Equals, 5) - c.Assert(d.entries[0].String(), check.Equals, "1.1.1.1:1111") - c.Assert(d.entries[1].String(), check.Equals, "1.1.1.2:1111") - c.Assert(d.entries[2].String(), check.Equals, "2.2.2.2:2222") - c.Assert(d.entries[3].String(), check.Equals, "2.2.2.3:2222") - c.Assert(d.entries[4].String(), check.Equals, "2.2.2.4:2222") -} - -func (s *DiscoverySuite) TestWatch(c *check.C) { - d := &Discovery{} - d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0, nil) - expected := discovery.Entries{ - &discovery.Entry{Host: "1.1.1.1", Port: "1111"}, - &discovery.Entry{Host: "2.2.2.2", Port: "2222"}, - } - ch, _ := d.Watch(nil) - c.Assert(expected.Equals(<-ch), check.Equals, true) -} - -func (s *DiscoverySuite) TestRegister(c *check.C) { - d := &Discovery{} - c.Assert(d.Register("0.0.0.0"), check.NotNil) -} diff --git a/vendor/github.com/docker/docker/pkg/filenotify/filenotify.go b/vendor/github.com/docker/docker/pkg/filenotify/filenotify.go deleted file mode 100644 index 7a81cbd..0000000 --- a/vendor/github.com/docker/docker/pkg/filenotify/filenotify.go +++ /dev/null @@ -1,40 +0,0 @@ -// Package filenotify provides a mechanism for watching file(s) for changes. -// Generally leans on fsnotify, but provides a poll-based notifier which fsnotify does not support. -// These are wrapped up in a common interface so that either can be used interchangeably in your code. -package filenotify - -import "github.com/fsnotify/fsnotify" - -// FileWatcher is an interface for implementing file notification watchers -type FileWatcher interface { - Events() <-chan fsnotify.Event - Errors() <-chan error - Add(name string) error - Remove(name string) error - Close() error -} - -// New tries to use an fs-event watcher, and falls back to the poller if there is an error -func New() (FileWatcher, error) { - if watcher, err := NewEventWatcher(); err == nil { - return watcher, nil - } - return NewPollingWatcher(), nil -} - -// NewPollingWatcher returns a poll-based file watcher -func NewPollingWatcher() FileWatcher { - return &filePoller{ - events: make(chan fsnotify.Event), - errors: make(chan error), - } -} - -// NewEventWatcher returns an fs-event based file watcher -func NewEventWatcher() (FileWatcher, error) { - watcher, err := fsnotify.NewWatcher() - if err != nil { - return nil, err - } - return &fsNotifyWatcher{watcher}, nil -} diff --git a/vendor/github.com/docker/docker/pkg/filenotify/fsnotify.go b/vendor/github.com/docker/docker/pkg/filenotify/fsnotify.go deleted file mode 100644 index 5d08a99..0000000 --- a/vendor/github.com/docker/docker/pkg/filenotify/fsnotify.go +++ /dev/null @@ -1,18 +0,0 @@ -package filenotify - -import "github.com/fsnotify/fsnotify" - -// fsNotifyWatcher wraps the fsnotify package to satisfy the FileNotifer interface -type fsNotifyWatcher struct { - *fsnotify.Watcher -} - -// Events returns the fsnotify event channel receiver -func (w *fsNotifyWatcher) Events() <-chan fsnotify.Event { - return w.Watcher.Events -} - -// Errors returns the fsnotify error channel receiver -func (w *fsNotifyWatcher) Errors() <-chan error { - return w.Watcher.Errors -} diff --git a/vendor/github.com/docker/docker/pkg/filenotify/poller.go b/vendor/github.com/docker/docker/pkg/filenotify/poller.go deleted file mode 100644 index dc5ccd0..0000000 --- a/vendor/github.com/docker/docker/pkg/filenotify/poller.go +++ /dev/null @@ -1,204 +0,0 @@ -package filenotify - -import ( - "errors" - "fmt" - "os" - "sync" - "time" - - "github.com/Sirupsen/logrus" - - "github.com/fsnotify/fsnotify" -) - -var ( - // errPollerClosed is returned when the poller is closed - errPollerClosed = errors.New("poller is closed") - // errNoSuchPoller is returned when trying to remove a watch that doesn't exist - errNoSuchWatch = errors.New("poller does not exist") -) - -// watchWaitTime is the time to wait between file poll loops -const watchWaitTime = 200 * time.Millisecond - -// filePoller is used to poll files for changes, especially in cases where fsnotify -// can't be run (e.g. when inotify handles are exhausted) -// filePoller satisfies the FileWatcher interface -type filePoller struct { - // watches is the list of files currently being polled, close the associated channel to stop the watch - watches map[string]chan struct{} - // events is the channel to listen to for watch events - events chan fsnotify.Event - // errors is the channel to listen to for watch errors - errors chan error - // mu locks the poller for modification - mu sync.Mutex - // closed is used to specify when the poller has already closed - closed bool -} - -// Add adds a filename to the list of watches -// once added the file is polled for changes in a separate goroutine -func (w *filePoller) Add(name string) error { - w.mu.Lock() - defer w.mu.Unlock() - - if w.closed == true { - return errPollerClosed - } - - f, err := os.Open(name) - if err != nil { - return err - } - fi, err := os.Stat(name) - if err != nil { - return err - } - - if w.watches == nil { - w.watches = make(map[string]chan struct{}) - } - if _, exists := w.watches[name]; exists { - return fmt.Errorf("watch exists") - } - chClose := make(chan struct{}) - w.watches[name] = chClose - - go w.watch(f, fi, chClose) - return nil -} - -// Remove stops and removes watch with the specified name -func (w *filePoller) Remove(name string) error { - w.mu.Lock() - defer w.mu.Unlock() - return w.remove(name) -} - -func (w *filePoller) remove(name string) error { - if w.closed == true { - return errPollerClosed - } - - chClose, exists := w.watches[name] - if !exists { - return errNoSuchWatch - } - close(chClose) - delete(w.watches, name) - return nil -} - -// Events returns the event channel -// This is used for notifications on events about watched files -func (w *filePoller) Events() <-chan fsnotify.Event { - return w.events -} - -// Errors returns the errors channel -// This is used for notifications about errors on watched files -func (w *filePoller) Errors() <-chan error { - return w.errors -} - -// Close closes the poller -// All watches are stopped, removed, and the poller cannot be added to -func (w *filePoller) Close() error { - w.mu.Lock() - defer w.mu.Unlock() - - if w.closed { - return nil - } - - w.closed = true - for name := range w.watches { - w.remove(name) - delete(w.watches, name) - } - return nil -} - -// sendEvent publishes the specified event to the events channel -func (w *filePoller) sendEvent(e fsnotify.Event, chClose <-chan struct{}) error { - select { - case w.events <- e: - case <-chClose: - return fmt.Errorf("closed") - } - return nil -} - -// sendErr publishes the specified error to the errors channel -func (w *filePoller) sendErr(e error, chClose <-chan struct{}) error { - select { - case w.errors <- e: - case <-chClose: - return fmt.Errorf("closed") - } - return nil -} - -// watch is responsible for polling the specified file for changes -// upon finding changes to a file or errors, sendEvent/sendErr is called -func (w *filePoller) watch(f *os.File, lastFi os.FileInfo, chClose chan struct{}) { - defer f.Close() - for { - time.Sleep(watchWaitTime) - select { - case <-chClose: - logrus.Debugf("watch for %s closed", f.Name()) - return - default: - } - - fi, err := os.Stat(f.Name()) - if err != nil { - // if we got an error here and lastFi is not set, we can presume that nothing has changed - // This should be safe since before `watch()` is called, a stat is performed, there is any error `watch` is not called - if lastFi == nil { - continue - } - // If it doesn't exist at this point, it must have been removed - // no need to send the error here since this is a valid operation - if os.IsNotExist(err) { - if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Remove, Name: f.Name()}, chClose); err != nil { - return - } - lastFi = nil - continue - } - // at this point, send the error - if err := w.sendErr(err, chClose); err != nil { - return - } - continue - } - - if lastFi == nil { - if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Create, Name: fi.Name()}, chClose); err != nil { - return - } - lastFi = fi - continue - } - - if fi.Mode() != lastFi.Mode() { - if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Chmod, Name: fi.Name()}, chClose); err != nil { - return - } - lastFi = fi - continue - } - - if fi.ModTime() != lastFi.ModTime() || fi.Size() != lastFi.Size() { - if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Write, Name: fi.Name()}, chClose); err != nil { - return - } - lastFi = fi - continue - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/filenotify/poller_test.go b/vendor/github.com/docker/docker/pkg/filenotify/poller_test.go deleted file mode 100644 index b4c7825..0000000 --- a/vendor/github.com/docker/docker/pkg/filenotify/poller_test.go +++ /dev/null @@ -1,119 +0,0 @@ -package filenotify - -import ( - "fmt" - "io/ioutil" - "os" - "runtime" - "testing" - "time" - - "github.com/fsnotify/fsnotify" -) - -func TestPollerAddRemove(t *testing.T) { - w := NewPollingWatcher() - - if err := w.Add("no-such-file"); err == nil { - t.Fatal("should have gotten error when adding a non-existent file") - } - if err := w.Remove("no-such-file"); err == nil { - t.Fatal("should have gotten error when removing non-existent watch") - } - - f, err := ioutil.TempFile("", "asdf") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(f.Name()) - - if err := w.Add(f.Name()); err != nil { - t.Fatal(err) - } - - if err := w.Remove(f.Name()); err != nil { - t.Fatal(err) - } -} - -func TestPollerEvent(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("No chmod on Windows") - } - w := NewPollingWatcher() - - f, err := ioutil.TempFile("", "test-poller") - if err != nil { - t.Fatal("error creating temp file") - } - defer os.RemoveAll(f.Name()) - f.Close() - - if err := w.Add(f.Name()); err != nil { - t.Fatal(err) - } - - select { - case <-w.Events(): - t.Fatal("got event before anything happened") - case <-w.Errors(): - t.Fatal("got error before anything happened") - default: - } - - if err := ioutil.WriteFile(f.Name(), []byte("hello"), 644); err != nil { - t.Fatal(err) - } - if err := assertEvent(w, fsnotify.Write); err != nil { - t.Fatal(err) - } - - if err := os.Chmod(f.Name(), 600); err != nil { - t.Fatal(err) - } - if err := assertEvent(w, fsnotify.Chmod); err != nil { - t.Fatal(err) - } - - if err := os.Remove(f.Name()); err != nil { - t.Fatal(err) - } - if err := assertEvent(w, fsnotify.Remove); err != nil { - t.Fatal(err) - } -} - -func TestPollerClose(t *testing.T) { - w := NewPollingWatcher() - if err := w.Close(); err != nil { - t.Fatal(err) - } - // test double-close - if err := w.Close(); err != nil { - t.Fatal(err) - } - - f, err := ioutil.TempFile("", "asdf") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(f.Name()) - if err := w.Add(f.Name()); err == nil { - t.Fatal("should have gotten error adding watch for closed watcher") - } -} - -func assertEvent(w FileWatcher, eType fsnotify.Op) error { - var err error - select { - case e := <-w.Events(): - if e.Op != eType { - err = fmt.Errorf("got wrong event type, expected %q: %v", eType, e) - } - case e := <-w.Errors(): - err = fmt.Errorf("got unexpected error waiting for events %v: %v", eType, e) - case <-time.After(watchWaitTime * 3): - err = fmt.Errorf("timeout waiting for event %v", eType) - } - return err -} diff --git a/vendor/github.com/docker/docker/pkg/fileutils/fileutils.go b/vendor/github.com/docker/docker/pkg/fileutils/fileutils.go deleted file mode 100644 index c63ae75..0000000 --- a/vendor/github.com/docker/docker/pkg/fileutils/fileutils.go +++ /dev/null @@ -1,283 +0,0 @@ -package fileutils - -import ( - "errors" - "fmt" - "io" - "os" - "path/filepath" - "regexp" - "strings" - "text/scanner" - - "github.com/Sirupsen/logrus" -) - -// exclusion returns true if the specified pattern is an exclusion -func exclusion(pattern string) bool { - return pattern[0] == '!' -} - -// empty returns true if the specified pattern is empty -func empty(pattern string) bool { - return pattern == "" -} - -// CleanPatterns takes a slice of patterns returns a new -// slice of patterns cleaned with filepath.Clean, stripped -// of any empty patterns and lets the caller know whether the -// slice contains any exception patterns (prefixed with !). -func CleanPatterns(patterns []string) ([]string, [][]string, bool, error) { - // Loop over exclusion patterns and: - // 1. Clean them up. - // 2. Indicate whether we are dealing with any exception rules. - // 3. Error if we see a single exclusion marker on its own (!). - cleanedPatterns := []string{} - patternDirs := [][]string{} - exceptions := false - for _, pattern := range patterns { - // Eliminate leading and trailing whitespace. - pattern = strings.TrimSpace(pattern) - if empty(pattern) { - continue - } - if exclusion(pattern) { - if len(pattern) == 1 { - return nil, nil, false, errors.New("Illegal exclusion pattern: !") - } - exceptions = true - } - pattern = filepath.Clean(pattern) - cleanedPatterns = append(cleanedPatterns, pattern) - if exclusion(pattern) { - pattern = pattern[1:] - } - patternDirs = append(patternDirs, strings.Split(pattern, string(os.PathSeparator))) - } - - return cleanedPatterns, patternDirs, exceptions, nil -} - -// Matches returns true if file matches any of the patterns -// and isn't excluded by any of the subsequent patterns. -func Matches(file string, patterns []string) (bool, error) { - file = filepath.Clean(file) - - if file == "." { - // Don't let them exclude everything, kind of silly. - return false, nil - } - - patterns, patDirs, _, err := CleanPatterns(patterns) - if err != nil { - return false, err - } - - return OptimizedMatches(file, patterns, patDirs) -} - -// OptimizedMatches is basically the same as fileutils.Matches() but optimized for archive.go. -// It will assume that the inputs have been preprocessed and therefore the function -// doesn't need to do as much error checking and clean-up. This was done to avoid -// repeating these steps on each file being checked during the archive process. -// The more generic fileutils.Matches() can't make these assumptions. -func OptimizedMatches(file string, patterns []string, patDirs [][]string) (bool, error) { - matched := false - file = filepath.FromSlash(file) - parentPath := filepath.Dir(file) - parentPathDirs := strings.Split(parentPath, string(os.PathSeparator)) - - for i, pattern := range patterns { - negative := false - - if exclusion(pattern) { - negative = true - pattern = pattern[1:] - } - - match, err := regexpMatch(pattern, file) - if err != nil { - return false, fmt.Errorf("Error in pattern (%s): %s", pattern, err) - } - - if !match && parentPath != "." { - // Check to see if the pattern matches one of our parent dirs. - if len(patDirs[i]) <= len(parentPathDirs) { - match, _ = regexpMatch(strings.Join(patDirs[i], string(os.PathSeparator)), - strings.Join(parentPathDirs[:len(patDirs[i])], string(os.PathSeparator))) - } - } - - if match { - matched = !negative - } - } - - if matched { - logrus.Debugf("Skipping excluded path: %s", file) - } - - return matched, nil -} - -// regexpMatch tries to match the logic of filepath.Match but -// does so using regexp logic. We do this so that we can expand the -// wildcard set to include other things, like "**" to mean any number -// of directories. This means that we should be backwards compatible -// with filepath.Match(). We'll end up supporting more stuff, due to -// the fact that we're using regexp, but that's ok - it does no harm. -// -// As per the comment in golangs filepath.Match, on Windows, escaping -// is disabled. Instead, '\\' is treated as path separator. -func regexpMatch(pattern, path string) (bool, error) { - regStr := "^" - - // Do some syntax checking on the pattern. - // filepath's Match() has some really weird rules that are inconsistent - // so instead of trying to dup their logic, just call Match() for its - // error state and if there is an error in the pattern return it. - // If this becomes an issue we can remove this since its really only - // needed in the error (syntax) case - which isn't really critical. - if _, err := filepath.Match(pattern, path); err != nil { - return false, err - } - - // Go through the pattern and convert it to a regexp. - // We use a scanner so we can support utf-8 chars. - var scan scanner.Scanner - scan.Init(strings.NewReader(pattern)) - - sl := string(os.PathSeparator) - escSL := sl - if sl == `\` { - escSL += `\` - } - - for scan.Peek() != scanner.EOF { - ch := scan.Next() - - if ch == '*' { - if scan.Peek() == '*' { - // is some flavor of "**" - scan.Next() - - if scan.Peek() == scanner.EOF { - // is "**EOF" - to align with .gitignore just accept all - regStr += ".*" - } else { - // is "**" - regStr += "((.*" + escSL + ")|([^" + escSL + "]*))" - } - - // Treat **/ as ** so eat the "/" - if string(scan.Peek()) == sl { - scan.Next() - } - } else { - // is "*" so map it to anything but "/" - regStr += "[^" + escSL + "]*" - } - } else if ch == '?' { - // "?" is any char except "/" - regStr += "[^" + escSL + "]" - } else if ch == '.' || ch == '$' { - // Escape some regexp special chars that have no meaning - // in golang's filepath.Match - regStr += `\` + string(ch) - } else if ch == '\\' { - // escape next char. Note that a trailing \ in the pattern - // will be left alone (but need to escape it) - if sl == `\` { - // On windows map "\" to "\\", meaning an escaped backslash, - // and then just continue because filepath.Match on - // Windows doesn't allow escaping at all - regStr += escSL - continue - } - if scan.Peek() != scanner.EOF { - regStr += `\` + string(scan.Next()) - } else { - regStr += `\` - } - } else { - regStr += string(ch) - } - } - - regStr += "$" - - res, err := regexp.MatchString(regStr, path) - - // Map regexp's error to filepath's so no one knows we're not using filepath - if err != nil { - err = filepath.ErrBadPattern - } - - return res, err -} - -// CopyFile copies from src to dst until either EOF is reached -// on src or an error occurs. It verifies src exists and removes -// the dst if it exists. -func CopyFile(src, dst string) (int64, error) { - cleanSrc := filepath.Clean(src) - cleanDst := filepath.Clean(dst) - if cleanSrc == cleanDst { - return 0, nil - } - sf, err := os.Open(cleanSrc) - if err != nil { - return 0, err - } - defer sf.Close() - if err := os.Remove(cleanDst); err != nil && !os.IsNotExist(err) { - return 0, err - } - df, err := os.Create(cleanDst) - if err != nil { - return 0, err - } - defer df.Close() - return io.Copy(df, sf) -} - -// ReadSymlinkedDirectory returns the target directory of a symlink. -// The target of the symbolic link may not be a file. -func ReadSymlinkedDirectory(path string) (string, error) { - var realPath string - var err error - if realPath, err = filepath.Abs(path); err != nil { - return "", fmt.Errorf("unable to get absolute path for %s: %s", path, err) - } - if realPath, err = filepath.EvalSymlinks(realPath); err != nil { - return "", fmt.Errorf("failed to canonicalise path for %s: %s", path, err) - } - realPathInfo, err := os.Stat(realPath) - if err != nil { - return "", fmt.Errorf("failed to stat target '%s' of '%s': %s", realPath, path, err) - } - if !realPathInfo.Mode().IsDir() { - return "", fmt.Errorf("canonical path points to a file '%s'", realPath) - } - return realPath, nil -} - -// CreateIfNotExists creates a file or a directory only if it does not already exist. -func CreateIfNotExists(path string, isDir bool) error { - if _, err := os.Stat(path); err != nil { - if os.IsNotExist(err) { - if isDir { - return os.MkdirAll(path, 0755) - } - if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { - return err - } - f, err := os.OpenFile(path, os.O_CREATE, 0755) - if err != nil { - return err - } - f.Close() - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/fileutils/fileutils_darwin.go b/vendor/github.com/docker/docker/pkg/fileutils/fileutils_darwin.go deleted file mode 100644 index ccd648f..0000000 --- a/vendor/github.com/docker/docker/pkg/fileutils/fileutils_darwin.go +++ /dev/null @@ -1,27 +0,0 @@ -package fileutils - -import ( - "os" - "os/exec" - "strconv" - "strings" -) - -// GetTotalUsedFds returns the number of used File Descriptors by -// executing `lsof -p PID` -func GetTotalUsedFds() int { - pid := os.Getpid() - - cmd := exec.Command("lsof", "-p", strconv.Itoa(pid)) - - output, err := cmd.CombinedOutput() - if err != nil { - return -1 - } - - outputStr := strings.TrimSpace(string(output)) - - fds := strings.Split(outputStr, "\n") - - return len(fds) - 1 -} diff --git a/vendor/github.com/docker/docker/pkg/fileutils/fileutils_solaris.go b/vendor/github.com/docker/docker/pkg/fileutils/fileutils_solaris.go deleted file mode 100644 index 0f2cb7a..0000000 --- a/vendor/github.com/docker/docker/pkg/fileutils/fileutils_solaris.go +++ /dev/null @@ -1,7 +0,0 @@ -package fileutils - -// GetTotalUsedFds Returns the number of used File Descriptors. -// On Solaris these limits are per process and not systemwide -func GetTotalUsedFds() int { - return -1 -} diff --git a/vendor/github.com/docker/docker/pkg/fileutils/fileutils_test.go b/vendor/github.com/docker/docker/pkg/fileutils/fileutils_test.go deleted file mode 100644 index 6df1be8..0000000 --- a/vendor/github.com/docker/docker/pkg/fileutils/fileutils_test.go +++ /dev/null @@ -1,585 +0,0 @@ -package fileutils - -import ( - "io/ioutil" - "os" - "path" - "path/filepath" - "runtime" - "strings" - "testing" -) - -// CopyFile with invalid src -func TestCopyFileWithInvalidSrc(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-fileutils-test") - defer os.RemoveAll(tempFolder) - if err != nil { - t.Fatal(err) - } - bytes, err := CopyFile("/invalid/file/path", path.Join(tempFolder, "dest")) - if err == nil { - t.Fatal("Should have fail to copy an invalid src file") - } - if bytes != 0 { - t.Fatal("Should have written 0 bytes") - } - -} - -// CopyFile with invalid dest -func TestCopyFileWithInvalidDest(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-fileutils-test") - defer os.RemoveAll(tempFolder) - if err != nil { - t.Fatal(err) - } - src := path.Join(tempFolder, "file") - err = ioutil.WriteFile(src, []byte("content"), 0740) - if err != nil { - t.Fatal(err) - } - bytes, err := CopyFile(src, path.Join(tempFolder, "/invalid/dest/path")) - if err == nil { - t.Fatal("Should have fail to copy an invalid src file") - } - if bytes != 0 { - t.Fatal("Should have written 0 bytes") - } - -} - -// CopyFile with same src and dest -func TestCopyFileWithSameSrcAndDest(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-fileutils-test") - defer os.RemoveAll(tempFolder) - if err != nil { - t.Fatal(err) - } - file := path.Join(tempFolder, "file") - err = ioutil.WriteFile(file, []byte("content"), 0740) - if err != nil { - t.Fatal(err) - } - bytes, err := CopyFile(file, file) - if err != nil { - t.Fatal(err) - } - if bytes != 0 { - t.Fatal("Should have written 0 bytes as it is the same file.") - } -} - -// CopyFile with same src and dest but path is different and not clean -func TestCopyFileWithSameSrcAndDestWithPathNameDifferent(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-fileutils-test") - defer os.RemoveAll(tempFolder) - if err != nil { - t.Fatal(err) - } - testFolder := path.Join(tempFolder, "test") - err = os.MkdirAll(testFolder, 0740) - if err != nil { - t.Fatal(err) - } - file := path.Join(testFolder, "file") - sameFile := testFolder + "/../test/file" - err = ioutil.WriteFile(file, []byte("content"), 0740) - if err != nil { - t.Fatal(err) - } - bytes, err := CopyFile(file, sameFile) - if err != nil { - t.Fatal(err) - } - if bytes != 0 { - t.Fatal("Should have written 0 bytes as it is the same file.") - } -} - -func TestCopyFile(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-fileutils-test") - defer os.RemoveAll(tempFolder) - if err != nil { - t.Fatal(err) - } - src := path.Join(tempFolder, "src") - dest := path.Join(tempFolder, "dest") - ioutil.WriteFile(src, []byte("content"), 0777) - ioutil.WriteFile(dest, []byte("destContent"), 0777) - bytes, err := CopyFile(src, dest) - if err != nil { - t.Fatal(err) - } - if bytes != 7 { - t.Fatalf("Should have written %d bytes but wrote %d", 7, bytes) - } - actual, err := ioutil.ReadFile(dest) - if err != nil { - t.Fatal(err) - } - if string(actual) != "content" { - t.Fatalf("Dest content was '%s', expected '%s'", string(actual), "content") - } -} - -// Reading a symlink to a directory must return the directory -func TestReadSymlinkedDirectoryExistingDirectory(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - var err error - if err = os.Mkdir("/tmp/testReadSymlinkToExistingDirectory", 0777); err != nil { - t.Errorf("failed to create directory: %s", err) - } - - if err = os.Symlink("/tmp/testReadSymlinkToExistingDirectory", "/tmp/dirLinkTest"); err != nil { - t.Errorf("failed to create symlink: %s", err) - } - - var path string - if path, err = ReadSymlinkedDirectory("/tmp/dirLinkTest"); err != nil { - t.Fatalf("failed to read symlink to directory: %s", err) - } - - if path != "/tmp/testReadSymlinkToExistingDirectory" { - t.Fatalf("symlink returned unexpected directory: %s", path) - } - - if err = os.Remove("/tmp/testReadSymlinkToExistingDirectory"); err != nil { - t.Errorf("failed to remove temporary directory: %s", err) - } - - if err = os.Remove("/tmp/dirLinkTest"); err != nil { - t.Errorf("failed to remove symlink: %s", err) - } -} - -// Reading a non-existing symlink must fail -func TestReadSymlinkedDirectoryNonExistingSymlink(t *testing.T) { - var path string - var err error - if path, err = ReadSymlinkedDirectory("/tmp/test/foo/Non/ExistingPath"); err == nil { - t.Fatalf("error expected for non-existing symlink") - } - - if path != "" { - t.Fatalf("expected empty path, but '%s' was returned", path) - } -} - -// Reading a symlink to a file must fail -func TestReadSymlinkedDirectoryToFile(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - var err error - var file *os.File - - if file, err = os.Create("/tmp/testReadSymlinkToFile"); err != nil { - t.Fatalf("failed to create file: %s", err) - } - - file.Close() - - if err = os.Symlink("/tmp/testReadSymlinkToFile", "/tmp/fileLinkTest"); err != nil { - t.Errorf("failed to create symlink: %s", err) - } - - var path string - if path, err = ReadSymlinkedDirectory("/tmp/fileLinkTest"); err == nil { - t.Fatalf("ReadSymlinkedDirectory on a symlink to a file should've failed") - } - - if path != "" { - t.Fatalf("path should've been empty: %s", path) - } - - if err = os.Remove("/tmp/testReadSymlinkToFile"); err != nil { - t.Errorf("failed to remove file: %s", err) - } - - if err = os.Remove("/tmp/fileLinkTest"); err != nil { - t.Errorf("failed to remove symlink: %s", err) - } -} - -func TestWildcardMatches(t *testing.T) { - match, _ := Matches("fileutils.go", []string{"*"}) - if match != true { - t.Errorf("failed to get a wildcard match, got %v", match) - } -} - -// A simple pattern match should return true. -func TestPatternMatches(t *testing.T) { - match, _ := Matches("fileutils.go", []string{"*.go"}) - if match != true { - t.Errorf("failed to get a match, got %v", match) - } -} - -// An exclusion followed by an inclusion should return true. -func TestExclusionPatternMatchesPatternBefore(t *testing.T) { - match, _ := Matches("fileutils.go", []string{"!fileutils.go", "*.go"}) - if match != true { - t.Errorf("failed to get true match on exclusion pattern, got %v", match) - } -} - -// A folder pattern followed by an exception should return false. -func TestPatternMatchesFolderExclusions(t *testing.T) { - match, _ := Matches("docs/README.md", []string{"docs", "!docs/README.md"}) - if match != false { - t.Errorf("failed to get a false match on exclusion pattern, got %v", match) - } -} - -// A folder pattern followed by an exception should return false. -func TestPatternMatchesFolderWithSlashExclusions(t *testing.T) { - match, _ := Matches("docs/README.md", []string{"docs/", "!docs/README.md"}) - if match != false { - t.Errorf("failed to get a false match on exclusion pattern, got %v", match) - } -} - -// A folder pattern followed by an exception should return false. -func TestPatternMatchesFolderWildcardExclusions(t *testing.T) { - match, _ := Matches("docs/README.md", []string{"docs/*", "!docs/README.md"}) - if match != false { - t.Errorf("failed to get a false match on exclusion pattern, got %v", match) - } -} - -// A pattern followed by an exclusion should return false. -func TestExclusionPatternMatchesPatternAfter(t *testing.T) { - match, _ := Matches("fileutils.go", []string{"*.go", "!fileutils.go"}) - if match != false { - t.Errorf("failed to get false match on exclusion pattern, got %v", match) - } -} - -// A filename evaluating to . should return false. -func TestExclusionPatternMatchesWholeDirectory(t *testing.T) { - match, _ := Matches(".", []string{"*.go"}) - if match != false { - t.Errorf("failed to get false match on ., got %v", match) - } -} - -// A single ! pattern should return an error. -func TestSingleExclamationError(t *testing.T) { - _, err := Matches("fileutils.go", []string{"!"}) - if err == nil { - t.Errorf("failed to get an error for a single exclamation point, got %v", err) - } -} - -// A string preceded with a ! should return true from Exclusion. -func TestExclusion(t *testing.T) { - exclusion := exclusion("!") - if !exclusion { - t.Errorf("failed to get true for a single !, got %v", exclusion) - } -} - -// Matches with no patterns -func TestMatchesWithNoPatterns(t *testing.T) { - matches, err := Matches("/any/path/there", []string{}) - if err != nil { - t.Fatal(err) - } - if matches { - t.Fatalf("Should not have match anything") - } -} - -// Matches with malformed patterns -func TestMatchesWithMalformedPatterns(t *testing.T) { - matches, err := Matches("/any/path/there", []string{"["}) - if err == nil { - t.Fatal("Should have failed because of a malformed syntax in the pattern") - } - if matches { - t.Fatalf("Should not have match anything") - } -} - -// Test lots of variants of patterns & strings -func TestMatches(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - tests := []struct { - pattern string - text string - pass bool - }{ - {"**", "file", true}, - {"**", "file/", true}, - {"**/", "file", true}, // weird one - {"**/", "file/", true}, - {"**", "/", true}, - {"**/", "/", true}, - {"**", "dir/file", true}, - {"**/", "dir/file", false}, - {"**", "dir/file/", true}, - {"**/", "dir/file/", true}, - {"**/**", "dir/file", true}, - {"**/**", "dir/file/", true}, - {"dir/**", "dir/file", true}, - {"dir/**", "dir/file/", true}, - {"dir/**", "dir/dir2/file", true}, - {"dir/**", "dir/dir2/file/", true}, - {"**/dir2/*", "dir/dir2/file", true}, - {"**/dir2/*", "dir/dir2/file/", false}, - {"**/dir2/**", "dir/dir2/dir3/file", true}, - {"**/dir2/**", "dir/dir2/dir3/file/", true}, - {"**file", "file", true}, - {"**file", "dir/file", true}, - {"**/file", "dir/file", true}, - {"**file", "dir/dir/file", true}, - {"**/file", "dir/dir/file", true}, - {"**/file*", "dir/dir/file", true}, - {"**/file*", "dir/dir/file.txt", true}, - {"**/file*txt", "dir/dir/file.txt", true}, - {"**/file*.txt", "dir/dir/file.txt", true}, - {"**/file*.txt*", "dir/dir/file.txt", true}, - {"**/**/*.txt", "dir/dir/file.txt", true}, - {"**/**/*.txt2", "dir/dir/file.txt", false}, - {"**/*.txt", "file.txt", true}, - {"**/**/*.txt", "file.txt", true}, - {"a**/*.txt", "a/file.txt", true}, - {"a**/*.txt", "a/dir/file.txt", true}, - {"a**/*.txt", "a/dir/dir/file.txt", true}, - {"a/*.txt", "a/dir/file.txt", false}, - {"a/*.txt", "a/file.txt", true}, - {"a/*.txt**", "a/file.txt", true}, - {"a[b-d]e", "ae", false}, - {"a[b-d]e", "ace", true}, - {"a[b-d]e", "aae", false}, - {"a[^b-d]e", "aze", true}, - {".*", ".foo", true}, - {".*", "foo", false}, - {"abc.def", "abcdef", false}, - {"abc.def", "abc.def", true}, - {"abc.def", "abcZdef", false}, - {"abc?def", "abcZdef", true}, - {"abc?def", "abcdef", false}, - {"a\\*b", "a*b", true}, - {"a\\", "a", false}, - {"a\\", "a\\", false}, - {"a\\\\", "a\\", true}, - {"**/foo/bar", "foo/bar", true}, - {"**/foo/bar", "dir/foo/bar", true}, - {"**/foo/bar", "dir/dir2/foo/bar", true}, - {"abc/**", "abc", false}, - {"abc/**", "abc/def", true}, - {"abc/**", "abc/def/ghi", true}, - } - - for _, test := range tests { - res, _ := regexpMatch(test.pattern, test.text) - if res != test.pass { - t.Fatalf("Failed: %v - res:%v", test, res) - } - } -} - -// An empty string should return true from Empty. -func TestEmpty(t *testing.T) { - empty := empty("") - if !empty { - t.Errorf("failed to get true for an empty string, got %v", empty) - } -} - -func TestCleanPatterns(t *testing.T) { - cleaned, _, _, _ := CleanPatterns([]string{"docs", "config"}) - if len(cleaned) != 2 { - t.Errorf("expected 2 element slice, got %v", len(cleaned)) - } -} - -func TestCleanPatternsStripEmptyPatterns(t *testing.T) { - cleaned, _, _, _ := CleanPatterns([]string{"docs", "config", ""}) - if len(cleaned) != 2 { - t.Errorf("expected 2 element slice, got %v", len(cleaned)) - } -} - -func TestCleanPatternsExceptionFlag(t *testing.T) { - _, _, exceptions, _ := CleanPatterns([]string{"docs", "!docs/README.md"}) - if !exceptions { - t.Errorf("expected exceptions to be true, got %v", exceptions) - } -} - -func TestCleanPatternsLeadingSpaceTrimmed(t *testing.T) { - _, _, exceptions, _ := CleanPatterns([]string{"docs", " !docs/README.md"}) - if !exceptions { - t.Errorf("expected exceptions to be true, got %v", exceptions) - } -} - -func TestCleanPatternsTrailingSpaceTrimmed(t *testing.T) { - _, _, exceptions, _ := CleanPatterns([]string{"docs", "!docs/README.md "}) - if !exceptions { - t.Errorf("expected exceptions to be true, got %v", exceptions) - } -} - -func TestCleanPatternsErrorSingleException(t *testing.T) { - _, _, _, err := CleanPatterns([]string{"!"}) - if err == nil { - t.Errorf("expected error on single exclamation point, got %v", err) - } -} - -func TestCleanPatternsFolderSplit(t *testing.T) { - _, dirs, _, _ := CleanPatterns([]string{"docs/config/CONFIG.md"}) - if dirs[0][0] != "docs" { - t.Errorf("expected first element in dirs slice to be docs, got %v", dirs[0][1]) - } - if dirs[0][1] != "config" { - t.Errorf("expected first element in dirs slice to be config, got %v", dirs[0][1]) - } -} - -func TestCreateIfNotExistsDir(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-fileutils-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tempFolder) - - folderToCreate := filepath.Join(tempFolder, "tocreate") - - if err := CreateIfNotExists(folderToCreate, true); err != nil { - t.Fatal(err) - } - fileinfo, err := os.Stat(folderToCreate) - if err != nil { - t.Fatalf("Should have create a folder, got %v", err) - } - - if !fileinfo.IsDir() { - t.Fatalf("Should have been a dir, seems it's not") - } -} - -func TestCreateIfNotExistsFile(t *testing.T) { - tempFolder, err := ioutil.TempDir("", "docker-fileutils-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tempFolder) - - fileToCreate := filepath.Join(tempFolder, "file/to/create") - - if err := CreateIfNotExists(fileToCreate, false); err != nil { - t.Fatal(err) - } - fileinfo, err := os.Stat(fileToCreate) - if err != nil { - t.Fatalf("Should have create a file, got %v", err) - } - - if fileinfo.IsDir() { - t.Fatalf("Should have been a file, seems it's not") - } -} - -// These matchTests are stolen from go's filepath Match tests. -type matchTest struct { - pattern, s string - match bool - err error -} - -var matchTests = []matchTest{ - {"abc", "abc", true, nil}, - {"*", "abc", true, nil}, - {"*c", "abc", true, nil}, - {"a*", "a", true, nil}, - {"a*", "abc", true, nil}, - {"a*", "ab/c", false, nil}, - {"a*/b", "abc/b", true, nil}, - {"a*/b", "a/c/b", false, nil}, - {"a*b*c*d*e*/f", "axbxcxdxe/f", true, nil}, - {"a*b*c*d*e*/f", "axbxcxdxexxx/f", true, nil}, - {"a*b*c*d*e*/f", "axbxcxdxe/xxx/f", false, nil}, - {"a*b*c*d*e*/f", "axbxcxdxexxx/fff", false, nil}, - {"a*b?c*x", "abxbbxdbxebxczzx", true, nil}, - {"a*b?c*x", "abxbbxdbxebxczzy", false, nil}, - {"ab[c]", "abc", true, nil}, - {"ab[b-d]", "abc", true, nil}, - {"ab[e-g]", "abc", false, nil}, - {"ab[^c]", "abc", false, nil}, - {"ab[^b-d]", "abc", false, nil}, - {"ab[^e-g]", "abc", true, nil}, - {"a\\*b", "a*b", true, nil}, - {"a\\*b", "ab", false, nil}, - {"a?b", "a☺b", true, nil}, - {"a[^a]b", "a☺b", true, nil}, - {"a???b", "a☺b", false, nil}, - {"a[^a][^a][^a]b", "a☺b", false, nil}, - {"[a-ζ]*", "α", true, nil}, - {"*[a-ζ]", "A", false, nil}, - {"a?b", "a/b", false, nil}, - {"a*b", "a/b", false, nil}, - {"[\\]a]", "]", true, nil}, - {"[\\-]", "-", true, nil}, - {"[x\\-]", "x", true, nil}, - {"[x\\-]", "-", true, nil}, - {"[x\\-]", "z", false, nil}, - {"[\\-x]", "x", true, nil}, - {"[\\-x]", "-", true, nil}, - {"[\\-x]", "a", false, nil}, - {"[]a]", "]", false, filepath.ErrBadPattern}, - {"[-]", "-", false, filepath.ErrBadPattern}, - {"[x-]", "x", false, filepath.ErrBadPattern}, - {"[x-]", "-", false, filepath.ErrBadPattern}, - {"[x-]", "z", false, filepath.ErrBadPattern}, - {"[-x]", "x", false, filepath.ErrBadPattern}, - {"[-x]", "-", false, filepath.ErrBadPattern}, - {"[-x]", "a", false, filepath.ErrBadPattern}, - {"\\", "a", false, filepath.ErrBadPattern}, - {"[a-b-c]", "a", false, filepath.ErrBadPattern}, - {"[", "a", false, filepath.ErrBadPattern}, - {"[^", "a", false, filepath.ErrBadPattern}, - {"[^bc", "a", false, filepath.ErrBadPattern}, - {"a[", "a", false, filepath.ErrBadPattern}, // was nil but IMO its wrong - {"a[", "ab", false, filepath.ErrBadPattern}, - {"*x", "xxx", true, nil}, -} - -func errp(e error) string { - if e == nil { - return "" - } - return e.Error() -} - -// TestMatch test's our version of filepath.Match, called regexpMatch. -func TestMatch(t *testing.T) { - for _, tt := range matchTests { - pattern := tt.pattern - s := tt.s - if runtime.GOOS == "windows" { - if strings.Index(pattern, "\\") >= 0 { - // no escape allowed on windows. - continue - } - pattern = filepath.Clean(pattern) - s = filepath.Clean(s) - } - ok, err := regexpMatch(pattern, s) - if ok != tt.match || err != tt.err { - t.Fatalf("Match(%#q, %#q) = %v, %q want %v, %q", pattern, s, ok, errp(err), tt.match, errp(tt.err)) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/fileutils/fileutils_unix.go b/vendor/github.com/docker/docker/pkg/fileutils/fileutils_unix.go deleted file mode 100644 index d5c3abf..0000000 --- a/vendor/github.com/docker/docker/pkg/fileutils/fileutils_unix.go +++ /dev/null @@ -1,22 +0,0 @@ -// +build linux freebsd - -package fileutils - -import ( - "fmt" - "io/ioutil" - "os" - - "github.com/Sirupsen/logrus" -) - -// GetTotalUsedFds Returns the number of used File Descriptors by -// reading it via /proc filesystem. -func GetTotalUsedFds() int { - if fds, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/fd", os.Getpid())); err != nil { - logrus.Errorf("Error opening /proc/%d/fd: %s", os.Getpid(), err) - } else { - return len(fds) - } - return -1 -} diff --git a/vendor/github.com/docker/docker/pkg/fileutils/fileutils_windows.go b/vendor/github.com/docker/docker/pkg/fileutils/fileutils_windows.go deleted file mode 100644 index 5ec21ca..0000000 --- a/vendor/github.com/docker/docker/pkg/fileutils/fileutils_windows.go +++ /dev/null @@ -1,7 +0,0 @@ -package fileutils - -// GetTotalUsedFds Returns the number of used File Descriptors. Not supported -// on Windows. -func GetTotalUsedFds() int { - return -1 -} diff --git a/vendor/github.com/docker/docker/pkg/fsutils/fsutils_linux.go b/vendor/github.com/docker/docker/pkg/fsutils/fsutils_linux.go deleted file mode 100644 index 9fd054e..0000000 --- a/vendor/github.com/docker/docker/pkg/fsutils/fsutils_linux.go +++ /dev/null @@ -1,89 +0,0 @@ -// +build linux - -package fsutils - -import ( - "fmt" - "io/ioutil" - "os" - "syscall" - "unsafe" -) - -func locateDummyIfEmpty(path string) (string, error) { - children, err := ioutil.ReadDir(path) - if err != nil { - return "", err - } - if len(children) != 0 { - return "", nil - } - dummyFile, err := ioutil.TempFile(path, "fsutils-dummy") - if err != nil { - return "", err - } - name := dummyFile.Name() - if err = dummyFile.Close(); err != nil { - return name, err - } - return name, nil -} - -// SupportsDType returns whether the filesystem mounted on path supports d_type -func SupportsDType(path string) (bool, error) { - // locate dummy so that we have at least one dirent - dummy, err := locateDummyIfEmpty(path) - if err != nil { - return false, err - } - if dummy != "" { - defer os.Remove(dummy) - } - - visited := 0 - supportsDType := true - fn := func(ent *syscall.Dirent) bool { - visited++ - if ent.Type == syscall.DT_UNKNOWN { - supportsDType = false - // stop iteration - return true - } - // continue iteration - return false - } - if err = iterateReadDir(path, fn); err != nil { - return false, err - } - if visited == 0 { - return false, fmt.Errorf("did not hit any dirent during iteration %s", path) - } - return supportsDType, nil -} - -func iterateReadDir(path string, fn func(*syscall.Dirent) bool) error { - d, err := os.Open(path) - if err != nil { - return err - } - defer d.Close() - fd := int(d.Fd()) - buf := make([]byte, 4096) - for { - nbytes, err := syscall.ReadDirent(fd, buf) - if err != nil { - return err - } - if nbytes == 0 { - break - } - for off := 0; off < nbytes; { - ent := (*syscall.Dirent)(unsafe.Pointer(&buf[off])) - if stop := fn(ent); stop { - return nil - } - off += int(ent.Reclen) - } - } - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/fsutils/fsutils_linux_test.go b/vendor/github.com/docker/docker/pkg/fsutils/fsutils_linux_test.go deleted file mode 100644 index 4a64823..0000000 --- a/vendor/github.com/docker/docker/pkg/fsutils/fsutils_linux_test.go +++ /dev/null @@ -1,91 +0,0 @@ -// +build linux - -package fsutils - -import ( - "io/ioutil" - "os" - "os/exec" - "syscall" - "testing" -) - -func testSupportsDType(t *testing.T, expected bool, mkfsCommand string, mkfsArg ...string) { - // check whether mkfs is installed - if _, err := exec.LookPath(mkfsCommand); err != nil { - t.Skipf("%s not installed: %v", mkfsCommand, err) - } - - // create a sparse image - imageSize := int64(32 * 1024 * 1024) - imageFile, err := ioutil.TempFile("", "fsutils-image") - if err != nil { - t.Fatal(err) - } - imageFileName := imageFile.Name() - defer os.Remove(imageFileName) - if _, err = imageFile.Seek(imageSize-1, 0); err != nil { - t.Fatal(err) - } - if _, err = imageFile.Write([]byte{0}); err != nil { - t.Fatal(err) - } - if err = imageFile.Close(); err != nil { - t.Fatal(err) - } - - // create a mountpoint - mountpoint, err := ioutil.TempDir("", "fsutils-mountpoint") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(mountpoint) - - // format the image - args := append(mkfsArg, imageFileName) - t.Logf("Executing `%s %v`", mkfsCommand, args) - out, err := exec.Command(mkfsCommand, args...).CombinedOutput() - if len(out) > 0 { - t.Log(string(out)) - } - if err != nil { - t.Fatal(err) - } - - // loopback-mount the image. - // for ease of setting up loopback device, we use os/exec rather than syscall.Mount - out, err = exec.Command("mount", "-o", "loop", imageFileName, mountpoint).CombinedOutput() - if len(out) > 0 { - t.Log(string(out)) - } - if err != nil { - t.Skip("skipping the test because mount failed") - } - defer func() { - if err := syscall.Unmount(mountpoint, 0); err != nil { - t.Fatal(err) - } - }() - - // check whether it supports d_type - result, err := SupportsDType(mountpoint) - if err != nil { - t.Fatal(err) - } - t.Logf("Supports d_type: %v", result) - if result != expected { - t.Fatalf("expected %v, got %v", expected, result) - } -} - -func TestSupportsDTypeWithFType0XFS(t *testing.T) { - testSupportsDType(t, false, "mkfs.xfs", "-m", "crc=0", "-n", "ftype=0") -} - -func TestSupportsDTypeWithFType1XFS(t *testing.T) { - testSupportsDType(t, true, "mkfs.xfs", "-m", "crc=0", "-n", "ftype=1") -} - -func TestSupportsDTypeWithExt4(t *testing.T) { - testSupportsDType(t, true, "mkfs.ext4") -} diff --git a/vendor/github.com/docker/docker/pkg/gitutils/gitutils.go b/vendor/github.com/docker/docker/pkg/gitutils/gitutils.go deleted file mode 100644 index ded091f..0000000 --- a/vendor/github.com/docker/docker/pkg/gitutils/gitutils.go +++ /dev/null @@ -1,100 +0,0 @@ -package gitutils - -import ( - "fmt" - "io/ioutil" - "net/http" - "net/url" - "os" - "os/exec" - "path/filepath" - "strings" - - "github.com/docker/docker/pkg/symlink" - "github.com/docker/docker/pkg/urlutil" -) - -// Clone clones a repository into a newly created directory which -// will be under "docker-build-git" -func Clone(remoteURL string) (string, error) { - if !urlutil.IsGitTransport(remoteURL) { - remoteURL = "https://" + remoteURL - } - root, err := ioutil.TempDir("", "docker-build-git") - if err != nil { - return "", err - } - - u, err := url.Parse(remoteURL) - if err != nil { - return "", err - } - - fragment := u.Fragment - clone := cloneArgs(u, root) - - if output, err := git(clone...); err != nil { - return "", fmt.Errorf("Error trying to use git: %s (%s)", err, output) - } - - return checkoutGit(fragment, root) -} - -func cloneArgs(remoteURL *url.URL, root string) []string { - args := []string{"clone", "--recursive"} - shallow := len(remoteURL.Fragment) == 0 - - if shallow && strings.HasPrefix(remoteURL.Scheme, "http") { - res, err := http.Head(fmt.Sprintf("%s/info/refs?service=git-upload-pack", remoteURL)) - if err != nil || res.Header.Get("Content-Type") != "application/x-git-upload-pack-advertisement" { - shallow = false - } - } - - if shallow { - args = append(args, "--depth", "1") - } - - if remoteURL.Fragment != "" { - remoteURL.Fragment = "" - } - - return append(args, remoteURL.String(), root) -} - -func checkoutGit(fragment, root string) (string, error) { - refAndDir := strings.SplitN(fragment, ":", 2) - - if len(refAndDir[0]) != 0 { - if output, err := gitWithinDir(root, "checkout", refAndDir[0]); err != nil { - return "", fmt.Errorf("Error trying to use git: %s (%s)", err, output) - } - } - - if len(refAndDir) > 1 && len(refAndDir[1]) != 0 { - newCtx, err := symlink.FollowSymlinkInScope(filepath.Join(root, refAndDir[1]), root) - if err != nil { - return "", fmt.Errorf("Error setting git context, %q not within git root: %s", refAndDir[1], err) - } - - fi, err := os.Stat(newCtx) - if err != nil { - return "", err - } - if !fi.IsDir() { - return "", fmt.Errorf("Error setting git context, not a directory: %s", newCtx) - } - root = newCtx - } - - return root, nil -} - -func gitWithinDir(dir string, args ...string) ([]byte, error) { - a := []string{"--work-tree", dir, "--git-dir", filepath.Join(dir, ".git")} - return git(append(a, args...)...) -} - -func git(args ...string) ([]byte, error) { - return exec.Command("git", args...).CombinedOutput() -} diff --git a/vendor/github.com/docker/docker/pkg/gitutils/gitutils_test.go b/vendor/github.com/docker/docker/pkg/gitutils/gitutils_test.go deleted file mode 100644 index d197058..0000000 --- a/vendor/github.com/docker/docker/pkg/gitutils/gitutils_test.go +++ /dev/null @@ -1,220 +0,0 @@ -package gitutils - -import ( - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "net/url" - "os" - "path/filepath" - "reflect" - "runtime" - "strings" - "testing" -) - -func TestCloneArgsSmartHttp(t *testing.T) { - mux := http.NewServeMux() - server := httptest.NewServer(mux) - serverURL, _ := url.Parse(server.URL) - - serverURL.Path = "/repo.git" - gitURL := serverURL.String() - - mux.HandleFunc("/repo.git/info/refs", func(w http.ResponseWriter, r *http.Request) { - q := r.URL.Query().Get("service") - w.Header().Set("Content-Type", fmt.Sprintf("application/x-%s-advertisement", q)) - }) - - args := cloneArgs(serverURL, "/tmp") - exp := []string{"clone", "--recursive", "--depth", "1", gitURL, "/tmp"} - if !reflect.DeepEqual(args, exp) { - t.Fatalf("Expected %v, got %v", exp, args) - } -} - -func TestCloneArgsDumbHttp(t *testing.T) { - mux := http.NewServeMux() - server := httptest.NewServer(mux) - serverURL, _ := url.Parse(server.URL) - - serverURL.Path = "/repo.git" - gitURL := serverURL.String() - - mux.HandleFunc("/repo.git/info/refs", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") - }) - - args := cloneArgs(serverURL, "/tmp") - exp := []string{"clone", "--recursive", gitURL, "/tmp"} - if !reflect.DeepEqual(args, exp) { - t.Fatalf("Expected %v, got %v", exp, args) - } -} - -func TestCloneArgsGit(t *testing.T) { - u, _ := url.Parse("git://github.com/docker/docker") - args := cloneArgs(u, "/tmp") - exp := []string{"clone", "--recursive", "--depth", "1", "git://github.com/docker/docker", "/tmp"} - if !reflect.DeepEqual(args, exp) { - t.Fatalf("Expected %v, got %v", exp, args) - } -} - -func TestCloneArgsStripFragment(t *testing.T) { - u, _ := url.Parse("git://github.com/docker/docker#test") - args := cloneArgs(u, "/tmp") - exp := []string{"clone", "--recursive", "git://github.com/docker/docker", "/tmp"} - if !reflect.DeepEqual(args, exp) { - t.Fatalf("Expected %v, got %v", exp, args) - } -} - -func gitGetConfig(name string) string { - b, err := git([]string{"config", "--get", name}...) - if err != nil { - // since we are interested in empty or non empty string, - // we can safely ignore the err here. - return "" - } - return strings.TrimSpace(string(b)) -} - -func TestCheckoutGit(t *testing.T) { - root, err := ioutil.TempDir("", "docker-build-git-checkout") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(root) - - autocrlf := gitGetConfig("core.autocrlf") - if !(autocrlf == "true" || autocrlf == "false" || - autocrlf == "input" || autocrlf == "") { - t.Logf("unknown core.autocrlf value: \"%s\"", autocrlf) - } - eol := "\n" - if autocrlf == "true" { - eol = "\r\n" - } - - gitDir := filepath.Join(root, "repo") - _, err = git("init", gitDir) - if err != nil { - t.Fatal(err) - } - - if _, err = gitWithinDir(gitDir, "config", "user.email", "test@docker.com"); err != nil { - t.Fatal(err) - } - - if _, err = gitWithinDir(gitDir, "config", "user.name", "Docker test"); err != nil { - t.Fatal(err) - } - - if err = ioutil.WriteFile(filepath.Join(gitDir, "Dockerfile"), []byte("FROM scratch"), 0644); err != nil { - t.Fatal(err) - } - - subDir := filepath.Join(gitDir, "subdir") - if err = os.Mkdir(subDir, 0755); err != nil { - t.Fatal(err) - } - - if err = ioutil.WriteFile(filepath.Join(subDir, "Dockerfile"), []byte("FROM scratch\nEXPOSE 5000"), 0644); err != nil { - t.Fatal(err) - } - - if runtime.GOOS != "windows" { - if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil { - t.Fatal(err) - } - - if err = os.Symlink("/subdir", filepath.Join(gitDir, "absolutelink")); err != nil { - t.Fatal(err) - } - } - - if _, err = gitWithinDir(gitDir, "add", "-A"); err != nil { - t.Fatal(err) - } - - if _, err = gitWithinDir(gitDir, "commit", "-am", "First commit"); err != nil { - t.Fatal(err) - } - - if _, err = gitWithinDir(gitDir, "checkout", "-b", "test"); err != nil { - t.Fatal(err) - } - - if err = ioutil.WriteFile(filepath.Join(gitDir, "Dockerfile"), []byte("FROM scratch\nEXPOSE 3000"), 0644); err != nil { - t.Fatal(err) - } - - if err = ioutil.WriteFile(filepath.Join(subDir, "Dockerfile"), []byte("FROM busybox\nEXPOSE 5000"), 0644); err != nil { - t.Fatal(err) - } - - if _, err = gitWithinDir(gitDir, "add", "-A"); err != nil { - t.Fatal(err) - } - - if _, err = gitWithinDir(gitDir, "commit", "-am", "Branch commit"); err != nil { - t.Fatal(err) - } - - if _, err = gitWithinDir(gitDir, "checkout", "master"); err != nil { - t.Fatal(err) - } - - type singleCase struct { - frag string - exp string - fail bool - } - - cases := []singleCase{ - {"", "FROM scratch", false}, - {"master", "FROM scratch", false}, - {":subdir", "FROM scratch" + eol + "EXPOSE 5000", false}, - {":nosubdir", "", true}, // missing directory error - {":Dockerfile", "", true}, // not a directory error - {"master:nosubdir", "", true}, - {"master:subdir", "FROM scratch" + eol + "EXPOSE 5000", false}, - {"master:../subdir", "", true}, - {"test", "FROM scratch" + eol + "EXPOSE 3000", false}, - {"test:", "FROM scratch" + eol + "EXPOSE 3000", false}, - {"test:subdir", "FROM busybox" + eol + "EXPOSE 5000", false}, - } - - if runtime.GOOS != "windows" { - // Windows GIT (2.7.1 x64) does not support parentlink/absolutelink. Sample output below - // git --work-tree .\repo --git-dir .\repo\.git add -A - // error: readlink("absolutelink"): Function not implemented - // error: unable to index file absolutelink - // fatal: adding files failed - cases = append(cases, singleCase{frag: "master:absolutelink", exp: "FROM scratch" + eol + "EXPOSE 5000", fail: false}) - cases = append(cases, singleCase{frag: "master:parentlink", exp: "FROM scratch" + eol + "EXPOSE 5000", fail: false}) - } - - for _, c := range cases { - r, err := checkoutGit(c.frag, gitDir) - - fail := err != nil - if fail != c.fail { - t.Fatalf("Expected %v failure, error was %v\n", c.fail, err) - } - if c.fail { - continue - } - - b, err := ioutil.ReadFile(filepath.Join(r, "Dockerfile")) - if err != nil { - t.Fatal(err) - } - - if string(b) != c.exp { - t.Fatalf("Expected %v, was %v\n", c.exp, string(b)) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/graphdb/conn_sqlite3_linux.go b/vendor/github.com/docker/docker/pkg/graphdb/conn_sqlite3_linux.go deleted file mode 100644 index 8e61ff3..0000000 --- a/vendor/github.com/docker/docker/pkg/graphdb/conn_sqlite3_linux.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build cgo - -package graphdb - -import ( - "database/sql" - - _ "github.com/mattn/go-sqlite3" // registers sqlite -) - -// NewSqliteConn opens a connection to a sqlite -// database. -func NewSqliteConn(root string) (*Database, error) { - conn, err := sql.Open("sqlite3", root) - if err != nil { - return nil, err - } - return NewDatabase(conn) -} diff --git a/vendor/github.com/docker/docker/pkg/graphdb/graphdb_linux.go b/vendor/github.com/docker/docker/pkg/graphdb/graphdb_linux.go deleted file mode 100644 index eca433f..0000000 --- a/vendor/github.com/docker/docker/pkg/graphdb/graphdb_linux.go +++ /dev/null @@ -1,551 +0,0 @@ -package graphdb - -import ( - "database/sql" - "fmt" - "path" - "strings" - "sync" -) - -const ( - createEntityTable = ` - CREATE TABLE IF NOT EXISTS entity ( - id text NOT NULL PRIMARY KEY - );` - - createEdgeTable = ` - CREATE TABLE IF NOT EXISTS edge ( - "entity_id" text NOT NULL, - "parent_id" text NULL, - "name" text NOT NULL, - CONSTRAINT "parent_fk" FOREIGN KEY ("parent_id") REFERENCES "entity" ("id"), - CONSTRAINT "entity_fk" FOREIGN KEY ("entity_id") REFERENCES "entity" ("id") - ); - ` - - createEdgeIndices = ` - CREATE UNIQUE INDEX IF NOT EXISTS "name_parent_ix" ON "edge" (parent_id, name); - ` -) - -// Entity with a unique id. -type Entity struct { - id string -} - -// An Edge connects two entities together. -type Edge struct { - EntityID string - Name string - ParentID string -} - -// Entities stores the list of entities. -type Entities map[string]*Entity - -// Edges stores the relationships between entities. -type Edges []*Edge - -// WalkFunc is a function invoked to process an individual entity. -type WalkFunc func(fullPath string, entity *Entity) error - -// Database is a graph database for storing entities and their relationships. -type Database struct { - conn *sql.DB - mux sync.RWMutex -} - -// IsNonUniqueNameError processes the error to check if it's caused by -// a constraint violation. -// This is necessary because the error isn't the same across various -// sqlite versions. -func IsNonUniqueNameError(err error) bool { - str := err.Error() - // sqlite 3.7.17-1ubuntu1 returns: - // Set failure: Abort due to constraint violation: columns parent_id, name are not unique - if strings.HasSuffix(str, "name are not unique") { - return true - } - // sqlite-3.8.3-1.fc20 returns: - // Set failure: Abort due to constraint violation: UNIQUE constraint failed: edge.parent_id, edge.name - if strings.Contains(str, "UNIQUE constraint failed") && strings.Contains(str, "edge.name") { - return true - } - // sqlite-3.6.20-1.el6 returns: - // Set failure: Abort due to constraint violation: constraint failed - if strings.HasSuffix(str, "constraint failed") { - return true - } - return false -} - -// NewDatabase creates a new graph database initialized with a root entity. -func NewDatabase(conn *sql.DB) (*Database, error) { - if conn == nil { - return nil, fmt.Errorf("Database connection cannot be nil") - } - db := &Database{conn: conn} - - // Create root entities - tx, err := conn.Begin() - if err != nil { - return nil, err - } - - if _, err := tx.Exec(createEntityTable); err != nil { - return nil, err - } - if _, err := tx.Exec(createEdgeTable); err != nil { - return nil, err - } - if _, err := tx.Exec(createEdgeIndices); err != nil { - return nil, err - } - - if _, err := tx.Exec("DELETE FROM entity where id = ?", "0"); err != nil { - tx.Rollback() - return nil, err - } - - if _, err := tx.Exec("INSERT INTO entity (id) VALUES (?);", "0"); err != nil { - tx.Rollback() - return nil, err - } - - if _, err := tx.Exec("DELETE FROM edge where entity_id=? and name=?", "0", "/"); err != nil { - tx.Rollback() - return nil, err - } - - if _, err := tx.Exec("INSERT INTO edge (entity_id, name) VALUES(?,?);", "0", "/"); err != nil { - tx.Rollback() - return nil, err - } - - if err := tx.Commit(); err != nil { - return nil, err - } - - return db, nil -} - -// Close the underlying connection to the database. -func (db *Database) Close() error { - return db.conn.Close() -} - -// Set the entity id for a given path. -func (db *Database) Set(fullPath, id string) (*Entity, error) { - db.mux.Lock() - defer db.mux.Unlock() - - tx, err := db.conn.Begin() - if err != nil { - return nil, err - } - - var entityID string - if err := tx.QueryRow("SELECT id FROM entity WHERE id = ?;", id).Scan(&entityID); err != nil { - if err == sql.ErrNoRows { - if _, err := tx.Exec("INSERT INTO entity (id) VALUES(?);", id); err != nil { - tx.Rollback() - return nil, err - } - } else { - tx.Rollback() - return nil, err - } - } - e := &Entity{id} - - parentPath, name := splitPath(fullPath) - if err := db.setEdge(parentPath, name, e, tx); err != nil { - tx.Rollback() - return nil, err - } - - if err := tx.Commit(); err != nil { - return nil, err - } - return e, nil -} - -// Exists returns true if a name already exists in the database. -func (db *Database) Exists(name string) bool { - db.mux.RLock() - defer db.mux.RUnlock() - - e, err := db.get(name) - if err != nil { - return false - } - return e != nil -} - -func (db *Database) setEdge(parentPath, name string, e *Entity, tx *sql.Tx) error { - parent, err := db.get(parentPath) - if err != nil { - return err - } - if parent.id == e.id { - return fmt.Errorf("Cannot set self as child") - } - - if _, err := tx.Exec("INSERT INTO edge (parent_id, name, entity_id) VALUES (?,?,?);", parent.id, name, e.id); err != nil { - return err - } - return nil -} - -// RootEntity returns the root "/" entity for the database. -func (db *Database) RootEntity() *Entity { - return &Entity{ - id: "0", - } -} - -// Get returns the entity for a given path. -func (db *Database) Get(name string) *Entity { - db.mux.RLock() - defer db.mux.RUnlock() - - e, err := db.get(name) - if err != nil { - return nil - } - return e -} - -func (db *Database) get(name string) (*Entity, error) { - e := db.RootEntity() - // We always know the root name so return it if - // it is requested - if name == "/" { - return e, nil - } - - parts := split(name) - for i := 1; i < len(parts); i++ { - p := parts[i] - if p == "" { - continue - } - - next := db.child(e, p) - if next == nil { - return nil, fmt.Errorf("Cannot find child for %s", name) - } - e = next - } - return e, nil - -} - -// List all entities by from the name. -// The key will be the full path of the entity. -func (db *Database) List(name string, depth int) Entities { - db.mux.RLock() - defer db.mux.RUnlock() - - out := Entities{} - e, err := db.get(name) - if err != nil { - return out - } - - children, err := db.children(e, name, depth, nil) - if err != nil { - return out - } - - for _, c := range children { - out[c.FullPath] = c.Entity - } - return out -} - -// Walk through the child graph of an entity, calling walkFunc for each child entity. -// It is safe for walkFunc to call graph functions. -func (db *Database) Walk(name string, walkFunc WalkFunc, depth int) error { - children, err := db.Children(name, depth) - if err != nil { - return err - } - - // Note: the database lock must not be held while calling walkFunc - for _, c := range children { - if err := walkFunc(c.FullPath, c.Entity); err != nil { - return err - } - } - return nil -} - -// Children returns the children of the specified entity. -func (db *Database) Children(name string, depth int) ([]WalkMeta, error) { - db.mux.RLock() - defer db.mux.RUnlock() - - e, err := db.get(name) - if err != nil { - return nil, err - } - - return db.children(e, name, depth, nil) -} - -// Parents returns the parents of a specified entity. -func (db *Database) Parents(name string) ([]string, error) { - db.mux.RLock() - defer db.mux.RUnlock() - - e, err := db.get(name) - if err != nil { - return nil, err - } - return db.parents(e) -} - -// Refs returns the reference count for a specified id. -func (db *Database) Refs(id string) int { - db.mux.RLock() - defer db.mux.RUnlock() - - var count int - if err := db.conn.QueryRow("SELECT COUNT(*) FROM edge WHERE entity_id = ?;", id).Scan(&count); err != nil { - return 0 - } - return count -} - -// RefPaths returns all the id's path references. -func (db *Database) RefPaths(id string) Edges { - db.mux.RLock() - defer db.mux.RUnlock() - - refs := Edges{} - - rows, err := db.conn.Query("SELECT name, parent_id FROM edge WHERE entity_id = ?;", id) - if err != nil { - return refs - } - defer rows.Close() - - for rows.Next() { - var name string - var parentID string - if err := rows.Scan(&name, &parentID); err != nil { - return refs - } - refs = append(refs, &Edge{ - EntityID: id, - Name: name, - ParentID: parentID, - }) - } - return refs -} - -// Delete the reference to an entity at a given path. -func (db *Database) Delete(name string) error { - db.mux.Lock() - defer db.mux.Unlock() - - if name == "/" { - return fmt.Errorf("Cannot delete root entity") - } - - parentPath, n := splitPath(name) - parent, err := db.get(parentPath) - if err != nil { - return err - } - - if _, err := db.conn.Exec("DELETE FROM edge WHERE parent_id = ? AND name = ?;", parent.id, n); err != nil { - return err - } - return nil -} - -// Purge removes the entity with the specified id -// Walk the graph to make sure all references to the entity -// are removed and return the number of references removed -func (db *Database) Purge(id string) (int, error) { - db.mux.Lock() - defer db.mux.Unlock() - - tx, err := db.conn.Begin() - if err != nil { - return -1, err - } - - // Delete all edges - rows, err := tx.Exec("DELETE FROM edge WHERE entity_id = ?;", id) - if err != nil { - tx.Rollback() - return -1, err - } - changes, err := rows.RowsAffected() - if err != nil { - return -1, err - } - - // Clear who's using this id as parent - refs, err := tx.Exec("DELETE FROM edge WHERE parent_id = ?;", id) - if err != nil { - tx.Rollback() - return -1, err - } - refsCount, err := refs.RowsAffected() - if err != nil { - return -1, err - } - - // Delete entity - if _, err := tx.Exec("DELETE FROM entity where id = ?;", id); err != nil { - tx.Rollback() - return -1, err - } - - if err := tx.Commit(); err != nil { - return -1, err - } - - return int(changes + refsCount), nil -} - -// Rename an edge for a given path -func (db *Database) Rename(currentName, newName string) error { - db.mux.Lock() - defer db.mux.Unlock() - - parentPath, name := splitPath(currentName) - newParentPath, newEdgeName := splitPath(newName) - - if parentPath != newParentPath { - return fmt.Errorf("Cannot rename when root paths do not match %s != %s", parentPath, newParentPath) - } - - parent, err := db.get(parentPath) - if err != nil { - return err - } - - rows, err := db.conn.Exec("UPDATE edge SET name = ? WHERE parent_id = ? AND name = ?;", newEdgeName, parent.id, name) - if err != nil { - return err - } - i, err := rows.RowsAffected() - if err != nil { - return err - } - if i == 0 { - return fmt.Errorf("Cannot locate edge for %s %s", parent.id, name) - } - return nil -} - -// WalkMeta stores the walk metadata. -type WalkMeta struct { - Parent *Entity - Entity *Entity - FullPath string - Edge *Edge -} - -func (db *Database) children(e *Entity, name string, depth int, entities []WalkMeta) ([]WalkMeta, error) { - if e == nil { - return entities, nil - } - - rows, err := db.conn.Query("SELECT entity_id, name FROM edge where parent_id = ?;", e.id) - if err != nil { - return nil, err - } - defer rows.Close() - - for rows.Next() { - var entityID, entityName string - if err := rows.Scan(&entityID, &entityName); err != nil { - return nil, err - } - child := &Entity{entityID} - edge := &Edge{ - ParentID: e.id, - Name: entityName, - EntityID: child.id, - } - - meta := WalkMeta{ - Parent: e, - Entity: child, - FullPath: path.Join(name, edge.Name), - Edge: edge, - } - - entities = append(entities, meta) - - if depth != 0 { - nDepth := depth - if depth != -1 { - nDepth-- - } - entities, err = db.children(child, meta.FullPath, nDepth, entities) - if err != nil { - return nil, err - } - } - } - - return entities, nil -} - -func (db *Database) parents(e *Entity) (parents []string, err error) { - if e == nil { - return parents, nil - } - - rows, err := db.conn.Query("SELECT parent_id FROM edge where entity_id = ?;", e.id) - if err != nil { - return nil, err - } - defer rows.Close() - - for rows.Next() { - var parentID string - if err := rows.Scan(&parentID); err != nil { - return nil, err - } - parents = append(parents, parentID) - } - - return parents, nil -} - -// Return the entity based on the parent path and name. -func (db *Database) child(parent *Entity, name string) *Entity { - var id string - if err := db.conn.QueryRow("SELECT entity_id FROM edge WHERE parent_id = ? AND name = ?;", parent.id, name).Scan(&id); err != nil { - return nil - } - return &Entity{id} -} - -// ID returns the id used to reference this entity. -func (e *Entity) ID() string { - return e.id -} - -// Paths returns the paths sorted by depth. -func (e Entities) Paths() []string { - out := make([]string, len(e)) - var i int - for k := range e { - out[i] = k - i++ - } - sortByDepth(out) - - return out -} diff --git a/vendor/github.com/docker/docker/pkg/graphdb/graphdb_linux_test.go b/vendor/github.com/docker/docker/pkg/graphdb/graphdb_linux_test.go deleted file mode 100644 index f0fb074..0000000 --- a/vendor/github.com/docker/docker/pkg/graphdb/graphdb_linux_test.go +++ /dev/null @@ -1,721 +0,0 @@ -package graphdb - -import ( - "database/sql" - "fmt" - "os" - "path" - "runtime" - "strconv" - "testing" - - _ "github.com/mattn/go-sqlite3" -) - -func newTestDb(t *testing.T) (*Database, string) { - p := path.Join(os.TempDir(), "sqlite.db") - conn, err := sql.Open("sqlite3", p) - db, err := NewDatabase(conn) - if err != nil { - t.Fatal(err) - } - return db, p -} - -func destroyTestDb(dbPath string) { - os.Remove(dbPath) -} - -func TestNewDatabase(t *testing.T) { - db, dbpath := newTestDb(t) - if db == nil { - t.Fatal("Database should not be nil") - } - db.Close() - defer destroyTestDb(dbpath) -} - -func TestCreateRootEntity(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - root := db.RootEntity() - if root == nil { - t.Fatal("Root entity should not be nil") - } -} - -func TestGetRootEntity(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - e := db.Get("/") - if e == nil { - t.Fatal("Entity should not be nil") - } - if e.ID() != "0" { - t.Fatalf("Entity id should be 0, got %s", e.ID()) - } -} - -func TestSetEntityWithDifferentName(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - db.Set("/test", "1") - if _, err := db.Set("/other", "1"); err != nil { - t.Fatal(err) - } -} - -func TestSetDuplicateEntity(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - if _, err := db.Set("/foo", "42"); err != nil { - t.Fatal(err) - } - if _, err := db.Set("/foo", "43"); err == nil { - t.Fatalf("Creating an entry with a duplicate path did not cause an error") - } -} - -func TestCreateChild(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - child, err := db.Set("/db", "1") - if err != nil { - t.Fatal(err) - } - if child == nil { - t.Fatal("Child should not be nil") - } - if child.ID() != "1" { - t.Fail() - } -} - -func TestParents(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - for i := 1; i < 6; i++ { - a := strconv.Itoa(i) - if _, err := db.Set("/"+a, a); err != nil { - t.Fatal(err) - } - } - - for i := 6; i < 11; i++ { - a := strconv.Itoa(i) - p := strconv.Itoa(i - 5) - - key := fmt.Sprintf("/%s/%s", p, a) - - if _, err := db.Set(key, a); err != nil { - t.Fatal(err) - } - - parents, err := db.Parents(key) - if err != nil { - t.Fatal(err) - } - - if len(parents) != 1 { - t.Fatalf("Expected 1 entry for %s got %d", key, len(parents)) - } - - if parents[0] != p { - t.Fatalf("ID %s received, %s expected", parents[0], p) - } - } -} - -func TestChildren(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - str := "/" - for i := 1; i < 6; i++ { - a := strconv.Itoa(i) - if _, err := db.Set(str+a, a); err != nil { - t.Fatal(err) - } - - str = str + a + "/" - } - - str = "/" - for i := 10; i < 30; i++ { // 20 entities - a := strconv.Itoa(i) - if _, err := db.Set(str+a, a); err != nil { - t.Fatal(err) - } - - str = str + a + "/" - } - entries, err := db.Children("/", 5) - if err != nil { - t.Fatal(err) - } - - if len(entries) != 11 { - t.Fatalf("Expect 11 entries for / got %d", len(entries)) - } - - entries, err = db.Children("/", 20) - if err != nil { - t.Fatal(err) - } - - if len(entries) != 25 { - t.Fatalf("Expect 25 entries for / got %d", len(entries)) - } -} - -func TestListAllRootChildren(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - for i := 1; i < 6; i++ { - a := strconv.Itoa(i) - if _, err := db.Set("/"+a, a); err != nil { - t.Fatal(err) - } - } - entries := db.List("/", -1) - if len(entries) != 5 { - t.Fatalf("Expect 5 entries for / got %d", len(entries)) - } -} - -func TestListAllSubChildren(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - _, err := db.Set("/webapp", "1") - if err != nil { - t.Fatal(err) - } - child2, err := db.Set("/db", "2") - if err != nil { - t.Fatal(err) - } - child4, err := db.Set("/logs", "4") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/db/logs", child4.ID()); err != nil { - t.Fatal(err) - } - - child3, err := db.Set("/sentry", "3") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/sentry", child3.ID()); err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/db", child2.ID()); err != nil { - t.Fatal(err) - } - - entries := db.List("/webapp", 1) - if len(entries) != 3 { - t.Fatalf("Expect 3 entries for / got %d", len(entries)) - } - - entries = db.List("/webapp", 0) - if len(entries) != 2 { - t.Fatalf("Expect 2 entries for / got %d", len(entries)) - } -} - -func TestAddSelfAsChild(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - child, err := db.Set("/test", "1") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/test/other", child.ID()); err == nil { - t.Fatal("Error should not be nil") - } -} - -func TestAddChildToNonExistentRoot(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - if _, err := db.Set("/myapp", "1"); err != nil { - t.Fatal(err) - } - - if _, err := db.Set("/myapp/proxy/db", "2"); err == nil { - t.Fatal("Error should not be nil") - } -} - -func TestWalkAll(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - _, err := db.Set("/webapp", "1") - if err != nil { - t.Fatal(err) - } - child2, err := db.Set("/db", "2") - if err != nil { - t.Fatal(err) - } - child4, err := db.Set("/db/logs", "4") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/logs", child4.ID()); err != nil { - t.Fatal(err) - } - - child3, err := db.Set("/sentry", "3") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/sentry", child3.ID()); err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/db", child2.ID()); err != nil { - t.Fatal(err) - } - - child5, err := db.Set("/gograph", "5") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/same-ref-diff-name", child5.ID()); err != nil { - t.Fatal(err) - } - - if err := db.Walk("/", func(p string, e *Entity) error { - t.Logf("Path: %s Entity: %s", p, e.ID()) - return nil - }, -1); err != nil { - t.Fatal(err) - } -} - -func TestGetEntityByPath(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - _, err := db.Set("/webapp", "1") - if err != nil { - t.Fatal(err) - } - child2, err := db.Set("/db", "2") - if err != nil { - t.Fatal(err) - } - child4, err := db.Set("/logs", "4") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/db/logs", child4.ID()); err != nil { - t.Fatal(err) - } - - child3, err := db.Set("/sentry", "3") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/sentry", child3.ID()); err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/db", child2.ID()); err != nil { - t.Fatal(err) - } - - child5, err := db.Set("/gograph", "5") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/same-ref-diff-name", child5.ID()); err != nil { - t.Fatal(err) - } - - entity := db.Get("/webapp/db/logs") - if entity == nil { - t.Fatal("Entity should not be nil") - } - if entity.ID() != "4" { - t.Fatalf("Expected to get entity with id 4, got %s", entity.ID()) - } -} - -func TestEnitiesPaths(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - _, err := db.Set("/webapp", "1") - if err != nil { - t.Fatal(err) - } - child2, err := db.Set("/db", "2") - if err != nil { - t.Fatal(err) - } - child4, err := db.Set("/logs", "4") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/db/logs", child4.ID()); err != nil { - t.Fatal(err) - } - - child3, err := db.Set("/sentry", "3") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/sentry", child3.ID()); err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/db", child2.ID()); err != nil { - t.Fatal(err) - } - - child5, err := db.Set("/gograph", "5") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/same-ref-diff-name", child5.ID()); err != nil { - t.Fatal(err) - } - - out := db.List("/", -1) - for _, p := range out.Paths() { - t.Log(p) - } -} - -func TestDeleteRootEntity(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - if err := db.Delete("/"); err == nil { - t.Fatal("Error should not be nil") - } -} - -func TestDeleteEntity(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - _, err := db.Set("/webapp", "1") - if err != nil { - t.Fatal(err) - } - child2, err := db.Set("/db", "2") - if err != nil { - t.Fatal(err) - } - child4, err := db.Set("/logs", "4") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/db/logs", child4.ID()); err != nil { - t.Fatal(err) - } - - child3, err := db.Set("/sentry", "3") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/sentry", child3.ID()); err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/db", child2.ID()); err != nil { - t.Fatal(err) - } - - child5, err := db.Set("/gograph", "5") - if err != nil { - t.Fatal(err) - } - if _, err := db.Set("/webapp/same-ref-diff-name", child5.ID()); err != nil { - t.Fatal(err) - } - - if err := db.Delete("/webapp/sentry"); err != nil { - t.Fatal(err) - } - entity := db.Get("/webapp/sentry") - if entity != nil { - t.Fatal("Entity /webapp/sentry should be nil") - } -} - -func TestCountRefs(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - db.Set("/webapp", "1") - - if db.Refs("1") != 1 { - t.Fatal("Expect reference count to be 1") - } - - db.Set("/db", "2") - db.Set("/webapp/db", "2") - if db.Refs("2") != 2 { - t.Fatal("Expect reference count to be 2") - } -} - -func TestPurgeId(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - db.Set("/webapp", "1") - - if c := db.Refs("1"); c != 1 { - t.Fatalf("Expect reference count to be 1, got %d", c) - } - - db.Set("/db", "2") - db.Set("/webapp/db", "2") - - count, err := db.Purge("2") - if err != nil { - t.Fatal(err) - } - if count != 2 { - t.Fatalf("Expected 2 references to be removed, got %d", count) - } -} - -// Regression test https://github.com/docker/docker/issues/12334 -func TestPurgeIdRefPaths(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - db.Set("/webapp", "1") - db.Set("/db", "2") - - db.Set("/db/webapp", "1") - - if c := db.Refs("1"); c != 2 { - t.Fatalf("Expected 2 reference for webapp, got %d", c) - } - if c := db.Refs("2"); c != 1 { - t.Fatalf("Expected 1 reference for db, got %d", c) - } - - if rp := db.RefPaths("2"); len(rp) != 1 { - t.Fatalf("Expected 1 reference path for db, got %d", len(rp)) - } - - count, err := db.Purge("2") - if err != nil { - t.Fatal(err) - } - - if count != 2 { - t.Fatalf("Expected 2 rows to be removed, got %d", count) - } - - if c := db.Refs("2"); c != 0 { - t.Fatalf("Expected 0 reference for db, got %d", c) - } - if c := db.Refs("1"); c != 1 { - t.Fatalf("Expected 1 reference for webapp, got %d", c) - } -} - -func TestRename(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - db.Set("/webapp", "1") - - if db.Refs("1") != 1 { - t.Fatal("Expect reference count to be 1") - } - - db.Set("/db", "2") - db.Set("/webapp/db", "2") - - if db.Get("/webapp/db") == nil { - t.Fatal("Cannot find entity at path /webapp/db") - } - - if err := db.Rename("/webapp/db", "/webapp/newdb"); err != nil { - t.Fatal(err) - } - if db.Get("/webapp/db") != nil { - t.Fatal("Entity should not exist at /webapp/db") - } - if db.Get("/webapp/newdb") == nil { - t.Fatal("Cannot find entity at path /webapp/newdb") - } - -} - -func TestCreateMultipleNames(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - db.Set("/db", "1") - if _, err := db.Set("/myapp", "1"); err != nil { - t.Fatal(err) - } - - db.Walk("/", func(p string, e *Entity) error { - t.Logf("%s\n", p) - return nil - }, -1) -} - -func TestRefPaths(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - db.Set("/webapp", "1") - - db.Set("/db", "2") - db.Set("/webapp/db", "2") - - refs := db.RefPaths("2") - if len(refs) != 2 { - t.Fatalf("Expected reference count to be 2, got %d", len(refs)) - } -} - -func TestExistsTrue(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - db.Set("/testing", "1") - - if !db.Exists("/testing") { - t.Fatalf("/tesing should exist") - } -} - -func TestExistsFalse(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - db.Set("/toerhe", "1") - - if db.Exists("/testing") { - t.Fatalf("/tesing should not exist") - } - -} - -func TestGetNameWithTrailingSlash(t *testing.T) { - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - db.Set("/todo", "1") - - e := db.Get("/todo/") - if e == nil { - t.Fatalf("Entity should not be nil") - } -} - -func TestConcurrentWrites(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - db, dbpath := newTestDb(t) - defer destroyTestDb(dbpath) - - errs := make(chan error, 2) - - save := func(name string, id string) { - if _, err := db.Set(fmt.Sprintf("/%s", name), id); err != nil { - errs <- err - } - errs <- nil - } - purge := func(id string) { - if _, err := db.Purge(id); err != nil { - errs <- err - } - errs <- nil - } - - save("/1", "1") - - go purge("1") - go save("/2", "2") - - any := false - for i := 0; i < 2; i++ { - if err := <-errs; err != nil { - any = true - t.Log(err) - } - } - if any { - t.Fail() - } -} diff --git a/vendor/github.com/docker/docker/pkg/graphdb/sort_linux.go b/vendor/github.com/docker/docker/pkg/graphdb/sort_linux.go deleted file mode 100644 index c07df07..0000000 --- a/vendor/github.com/docker/docker/pkg/graphdb/sort_linux.go +++ /dev/null @@ -1,27 +0,0 @@ -package graphdb - -import "sort" - -type pathSorter struct { - paths []string - by func(i, j string) bool -} - -func sortByDepth(paths []string) { - s := &pathSorter{paths, func(i, j string) bool { - return PathDepth(i) > PathDepth(j) - }} - sort.Sort(s) -} - -func (s *pathSorter) Len() int { - return len(s.paths) -} - -func (s *pathSorter) Swap(i, j int) { - s.paths[i], s.paths[j] = s.paths[j], s.paths[i] -} - -func (s *pathSorter) Less(i, j int) bool { - return s.by(s.paths[i], s.paths[j]) -} diff --git a/vendor/github.com/docker/docker/pkg/graphdb/sort_linux_test.go b/vendor/github.com/docker/docker/pkg/graphdb/sort_linux_test.go deleted file mode 100644 index ddf2266..0000000 --- a/vendor/github.com/docker/docker/pkg/graphdb/sort_linux_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package graphdb - -import ( - "testing" -) - -func TestSort(t *testing.T) { - paths := []string{ - "/", - "/myreallylongname", - "/app/db", - } - - sortByDepth(paths) - - if len(paths) != 3 { - t.Fatalf("Expected 3 parts got %d", len(paths)) - } - - if paths[0] != "/app/db" { - t.Fatalf("Expected /app/db got %s", paths[0]) - } - if paths[1] != "/myreallylongname" { - t.Fatalf("Expected /myreallylongname got %s", paths[1]) - } - if paths[2] != "/" { - t.Fatalf("Expected / got %s", paths[2]) - } -} diff --git a/vendor/github.com/docker/docker/pkg/graphdb/unsupported.go b/vendor/github.com/docker/docker/pkg/graphdb/unsupported.go deleted file mode 100644 index 2b8ba71..0000000 --- a/vendor/github.com/docker/docker/pkg/graphdb/unsupported.go +++ /dev/null @@ -1,3 +0,0 @@ -// +build !cgo !linux - -package graphdb diff --git a/vendor/github.com/docker/docker/pkg/graphdb/utils_linux.go b/vendor/github.com/docker/docker/pkg/graphdb/utils_linux.go deleted file mode 100644 index 9edd79c..0000000 --- a/vendor/github.com/docker/docker/pkg/graphdb/utils_linux.go +++ /dev/null @@ -1,32 +0,0 @@ -package graphdb - -import ( - "path" - "strings" -) - -// Split p on / -func split(p string) []string { - return strings.Split(p, "/") -} - -// PathDepth returns the depth or number of / in a given path -func PathDepth(p string) int { - parts := split(p) - if len(parts) == 2 && parts[1] == "" { - return 1 - } - return len(parts) -} - -func splitPath(p string) (parent, name string) { - if p[0] != '/' { - p = "/" + p - } - parent, name = path.Split(p) - l := len(parent) - if parent[l-1] == '/' { - parent = parent[:l-1] - } - return -} diff --git a/vendor/github.com/docker/docker/pkg/homedir/homedir.go b/vendor/github.com/docker/docker/pkg/homedir/homedir.go deleted file mode 100644 index 8154e83..0000000 --- a/vendor/github.com/docker/docker/pkg/homedir/homedir.go +++ /dev/null @@ -1,39 +0,0 @@ -package homedir - -import ( - "os" - "runtime" - - "github.com/opencontainers/runc/libcontainer/user" -) - -// Key returns the env var name for the user's home dir based on -// the platform being run on -func Key() string { - if runtime.GOOS == "windows" { - return "USERPROFILE" - } - return "HOME" -} - -// Get returns the home directory of the current user with the help of -// environment variables depending on the target operating system. -// Returned path should be used with "path/filepath" to form new paths. -func Get() string { - home := os.Getenv(Key()) - if home == "" && runtime.GOOS != "windows" { - if u, err := user.CurrentUser(); err == nil { - return u.Home - } - } - return home -} - -// GetShortcutString returns the string that is shortcut to user's home directory -// in the native shell of the platform running on. -func GetShortcutString() string { - if runtime.GOOS == "windows" { - return "%USERPROFILE%" // be careful while using in format functions - } - return "~" -} diff --git a/vendor/github.com/docker/docker/pkg/homedir/homedir_test.go b/vendor/github.com/docker/docker/pkg/homedir/homedir_test.go deleted file mode 100644 index 7a95cb2..0000000 --- a/vendor/github.com/docker/docker/pkg/homedir/homedir_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package homedir - -import ( - "path/filepath" - "testing" -) - -func TestGet(t *testing.T) { - home := Get() - if home == "" { - t.Fatal("returned home directory is empty") - } - - if !filepath.IsAbs(home) { - t.Fatalf("returned path is not absolute: %s", home) - } -} - -func TestGetShortcutString(t *testing.T) { - shortcut := GetShortcutString() - if shortcut == "" { - t.Fatal("returned shortcut string is empty") - } -} diff --git a/vendor/github.com/docker/docker/pkg/httputils/httputils.go b/vendor/github.com/docker/docker/pkg/httputils/httputils.go deleted file mode 100644 index d7dc438..0000000 --- a/vendor/github.com/docker/docker/pkg/httputils/httputils.go +++ /dev/null @@ -1,56 +0,0 @@ -package httputils - -import ( - "errors" - "fmt" - "net/http" - "regexp" - "strings" - - "github.com/docker/docker/pkg/jsonmessage" -) - -var ( - headerRegexp = regexp.MustCompile(`^(?:(.+)/(.+?))\((.+)\).*$`) - errInvalidHeader = errors.New("Bad header, should be in format `docker/version (platform)`") -) - -// Download requests a given URL and returns an io.Reader. -func Download(url string) (resp *http.Response, err error) { - if resp, err = http.Get(url); err != nil { - return nil, err - } - if resp.StatusCode >= 400 { - return nil, fmt.Errorf("Got HTTP status code >= 400: %s", resp.Status) - } - return resp, nil -} - -// NewHTTPRequestError returns a JSON response error. -func NewHTTPRequestError(msg string, res *http.Response) error { - return &jsonmessage.JSONError{ - Message: msg, - Code: res.StatusCode, - } -} - -// ServerHeader contains the server information. -type ServerHeader struct { - App string // docker - Ver string // 1.8.0-dev - OS string // windows or linux -} - -// ParseServerHeader extracts pieces from an HTTP server header -// which is in the format "docker/version (os)" eg docker/1.8.0-dev (windows). -func ParseServerHeader(hdr string) (*ServerHeader, error) { - matches := headerRegexp.FindStringSubmatch(hdr) - if len(matches) != 4 { - return nil, errInvalidHeader - } - return &ServerHeader{ - App: strings.TrimSpace(matches[1]), - Ver: strings.TrimSpace(matches[2]), - OS: strings.TrimSpace(matches[3]), - }, nil -} diff --git a/vendor/github.com/docker/docker/pkg/httputils/httputils_test.go b/vendor/github.com/docker/docker/pkg/httputils/httputils_test.go deleted file mode 100644 index d35d082..0000000 --- a/vendor/github.com/docker/docker/pkg/httputils/httputils_test.go +++ /dev/null @@ -1,115 +0,0 @@ -package httputils - -import ( - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "strings" - "testing" -) - -func TestDownload(t *testing.T) { - expected := "Hello, docker !" - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, expected) - })) - defer ts.Close() - response, err := Download(ts.URL) - if err != nil { - t.Fatal(err) - } - - actual, err := ioutil.ReadAll(response.Body) - response.Body.Close() - - if err != nil || string(actual) != expected { - t.Fatalf("Expected the response %q, got err:%v, response:%v, actual:%s", expected, err, response, string(actual)) - } -} - -func TestDownload400Errors(t *testing.T) { - expectedError := "Got HTTP status code >= 400: 403 Forbidden" - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // 403 - http.Error(w, "something failed (forbidden)", http.StatusForbidden) - })) - defer ts.Close() - // Expected status code = 403 - if _, err := Download(ts.URL); err == nil || err.Error() != expectedError { - t.Fatalf("Expected the the error %q, got %v", expectedError, err) - } -} - -func TestDownloadOtherErrors(t *testing.T) { - if _, err := Download("I'm not an url.."); err == nil || !strings.Contains(err.Error(), "unsupported protocol scheme") { - t.Fatalf("Expected an error with 'unsupported protocol scheme', got %v", err) - } -} - -func TestNewHTTPRequestError(t *testing.T) { - errorMessage := "Some error message" - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // 403 - http.Error(w, errorMessage, http.StatusForbidden) - })) - defer ts.Close() - httpResponse, err := http.Get(ts.URL) - if err != nil { - t.Fatal(err) - } - if err := NewHTTPRequestError(errorMessage, httpResponse); err.Error() != errorMessage { - t.Fatalf("Expected err to be %q, got %v", errorMessage, err) - } -} - -func TestParseServerHeader(t *testing.T) { - inputs := map[string][]string{ - "bad header": {"error"}, - "(bad header)": {"error"}, - "(without/spaces)": {"error"}, - "(header/with spaces)": {"error"}, - "foo/bar (baz)": {"foo", "bar", "baz"}, - "foo/bar": {"error"}, - "foo": {"error"}, - "foo/bar (baz space)": {"foo", "bar", "baz space"}, - " f f / b b ( b s ) ": {"f f", "b b", "b s"}, - "foo/bar (baz) ignore": {"foo", "bar", "baz"}, - "foo/bar ()": {"error"}, - "foo/bar()": {"error"}, - "foo/bar(baz)": {"foo", "bar", "baz"}, - "foo/bar/zzz(baz)": {"foo/bar", "zzz", "baz"}, - "foo/bar(baz/abc)": {"foo", "bar", "baz/abc"}, - "foo/bar(baz (abc))": {"foo", "bar", "baz (abc)"}, - } - - for header, values := range inputs { - serverHeader, err := ParseServerHeader(header) - if err != nil { - if err != errInvalidHeader { - t.Fatalf("Failed to parse %q, and got some unexpected error: %q", header, err) - } - if values[0] == "error" { - continue - } - t.Fatalf("Header %q failed to parse when it shouldn't have", header) - } - if values[0] == "error" { - t.Fatalf("Header %q parsed ok when it should have failed(%q).", header, serverHeader) - } - - if serverHeader.App != values[0] { - t.Fatalf("Expected serverHeader.App for %q to equal %q, got %q", header, values[0], serverHeader.App) - } - - if serverHeader.Ver != values[1] { - t.Fatalf("Expected serverHeader.Ver for %q to equal %q, got %q", header, values[1], serverHeader.Ver) - } - - if serverHeader.OS != values[2] { - t.Fatalf("Expected serverHeader.OS for %q to equal %q, got %q", header, values[2], serverHeader.OS) - } - - } - -} diff --git a/vendor/github.com/docker/docker/pkg/httputils/mimetype.go b/vendor/github.com/docker/docker/pkg/httputils/mimetype.go deleted file mode 100644 index d5cf34e..0000000 --- a/vendor/github.com/docker/docker/pkg/httputils/mimetype.go +++ /dev/null @@ -1,30 +0,0 @@ -package httputils - -import ( - "mime" - "net/http" -) - -// MimeTypes stores the MIME content type. -var MimeTypes = struct { - TextPlain string - Tar string - OctetStream string -}{"text/plain", "application/tar", "application/octet-stream"} - -// DetectContentType returns a best guess representation of the MIME -// content type for the bytes at c. The value detected by -// http.DetectContentType is guaranteed not be nil, defaulting to -// application/octet-stream when a better guess cannot be made. The -// result of this detection is then run through mime.ParseMediaType() -// which separates the actual MIME string from any parameters. -func DetectContentType(c []byte) (string, map[string]string, error) { - - ct := http.DetectContentType(c) - contentType, args, err := mime.ParseMediaType(ct) - if err != nil { - return "", nil, err - } - - return contentType, args, nil -} diff --git a/vendor/github.com/docker/docker/pkg/httputils/mimetype_test.go b/vendor/github.com/docker/docker/pkg/httputils/mimetype_test.go deleted file mode 100644 index 9de433e..0000000 --- a/vendor/github.com/docker/docker/pkg/httputils/mimetype_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package httputils - -import ( - "testing" -) - -func TestDetectContentType(t *testing.T) { - input := []byte("That is just a plain text") - - if contentType, _, err := DetectContentType(input); err != nil || contentType != "text/plain" { - t.Errorf("TestDetectContentType failed") - } -} diff --git a/vendor/github.com/docker/docker/pkg/httputils/resumablerequestreader.go b/vendor/github.com/docker/docker/pkg/httputils/resumablerequestreader.go deleted file mode 100644 index bebc860..0000000 --- a/vendor/github.com/docker/docker/pkg/httputils/resumablerequestreader.go +++ /dev/null @@ -1,95 +0,0 @@ -package httputils - -import ( - "fmt" - "io" - "net/http" - "time" - - "github.com/Sirupsen/logrus" -) - -type resumableRequestReader struct { - client *http.Client - request *http.Request - lastRange int64 - totalSize int64 - currentResponse *http.Response - failures uint32 - maxFailures uint32 -} - -// ResumableRequestReader makes it possible to resume reading a request's body transparently -// maxfail is the number of times we retry to make requests again (not resumes) -// totalsize is the total length of the body; auto detect if not provided -func ResumableRequestReader(c *http.Client, r *http.Request, maxfail uint32, totalsize int64) io.ReadCloser { - return &resumableRequestReader{client: c, request: r, maxFailures: maxfail, totalSize: totalsize} -} - -// ResumableRequestReaderWithInitialResponse makes it possible to resume -// reading the body of an already initiated request. -func ResumableRequestReaderWithInitialResponse(c *http.Client, r *http.Request, maxfail uint32, totalsize int64, initialResponse *http.Response) io.ReadCloser { - return &resumableRequestReader{client: c, request: r, maxFailures: maxfail, totalSize: totalsize, currentResponse: initialResponse} -} - -func (r *resumableRequestReader) Read(p []byte) (n int, err error) { - if r.client == nil || r.request == nil { - return 0, fmt.Errorf("client and request can't be nil\n") - } - isFreshRequest := false - if r.lastRange != 0 && r.currentResponse == nil { - readRange := fmt.Sprintf("bytes=%d-%d", r.lastRange, r.totalSize) - r.request.Header.Set("Range", readRange) - time.Sleep(5 * time.Second) - } - if r.currentResponse == nil { - r.currentResponse, err = r.client.Do(r.request) - isFreshRequest = true - } - if err != nil && r.failures+1 != r.maxFailures { - r.cleanUpResponse() - r.failures++ - time.Sleep(5 * time.Duration(r.failures) * time.Second) - return 0, nil - } else if err != nil { - r.cleanUpResponse() - return 0, err - } - if r.currentResponse.StatusCode == 416 && r.lastRange == r.totalSize && r.currentResponse.ContentLength == 0 { - r.cleanUpResponse() - return 0, io.EOF - } else if r.currentResponse.StatusCode != 206 && r.lastRange != 0 && isFreshRequest { - r.cleanUpResponse() - return 0, fmt.Errorf("the server doesn't support byte ranges") - } - if r.totalSize == 0 { - r.totalSize = r.currentResponse.ContentLength - } else if r.totalSize <= 0 { - r.cleanUpResponse() - return 0, fmt.Errorf("failed to auto detect content length") - } - n, err = r.currentResponse.Body.Read(p) - r.lastRange += int64(n) - if err != nil { - r.cleanUpResponse() - } - if err != nil && err != io.EOF { - logrus.Infof("encountered error during pull and clearing it before resume: %s", err) - err = nil - } - return n, err -} - -func (r *resumableRequestReader) Close() error { - r.cleanUpResponse() - r.client = nil - r.request = nil - return nil -} - -func (r *resumableRequestReader) cleanUpResponse() { - if r.currentResponse != nil { - r.currentResponse.Body.Close() - r.currentResponse = nil - } -} diff --git a/vendor/github.com/docker/docker/pkg/httputils/resumablerequestreader_test.go b/vendor/github.com/docker/docker/pkg/httputils/resumablerequestreader_test.go deleted file mode 100644 index 5a2906d..0000000 --- a/vendor/github.com/docker/docker/pkg/httputils/resumablerequestreader_test.go +++ /dev/null @@ -1,307 +0,0 @@ -package httputils - -import ( - "fmt" - "io" - "io/ioutil" - "net/http" - "net/http/httptest" - "strings" - "testing" -) - -func TestResumableRequestHeaderSimpleErrors(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "Hello, world !") - })) - defer ts.Close() - - client := &http.Client{} - - var req *http.Request - req, err := http.NewRequest("GET", ts.URL, nil) - if err != nil { - t.Fatal(err) - } - - expectedError := "client and request can't be nil\n" - resreq := &resumableRequestReader{} - _, err = resreq.Read([]byte{}) - if err == nil || err.Error() != expectedError { - t.Fatalf("Expected an error with '%s', got %v.", expectedError, err) - } - - resreq = &resumableRequestReader{ - client: client, - request: req, - totalSize: -1, - } - expectedError = "failed to auto detect content length" - _, err = resreq.Read([]byte{}) - if err == nil || err.Error() != expectedError { - t.Fatalf("Expected an error with '%s', got %v.", expectedError, err) - } - -} - -// Not too much failures, bails out after some wait -func TestResumableRequestHeaderNotTooMuchFailures(t *testing.T) { - client := &http.Client{} - - var badReq *http.Request - badReq, err := http.NewRequest("GET", "I'm not an url", nil) - if err != nil { - t.Fatal(err) - } - - resreq := &resumableRequestReader{ - client: client, - request: badReq, - failures: 0, - maxFailures: 2, - } - read, err := resreq.Read([]byte{}) - if err != nil || read != 0 { - t.Fatalf("Expected no error and no byte read, got err:%v, read:%v.", err, read) - } -} - -// Too much failures, returns the error -func TestResumableRequestHeaderTooMuchFailures(t *testing.T) { - client := &http.Client{} - - var badReq *http.Request - badReq, err := http.NewRequest("GET", "I'm not an url", nil) - if err != nil { - t.Fatal(err) - } - - resreq := &resumableRequestReader{ - client: client, - request: badReq, - failures: 0, - maxFailures: 1, - } - defer resreq.Close() - - expectedError := `Get I%27m%20not%20an%20url: unsupported protocol scheme ""` - read, err := resreq.Read([]byte{}) - if err == nil || err.Error() != expectedError || read != 0 { - t.Fatalf("Expected the error '%s', got err:%v, read:%v.", expectedError, err, read) - } -} - -type errorReaderCloser struct{} - -func (errorReaderCloser) Close() error { return nil } - -func (errorReaderCloser) Read(p []byte) (n int, err error) { - return 0, fmt.Errorf("An error occurred") -} - -// If an unknown error is encountered, return 0, nil and log it -func TestResumableRequestReaderWithReadError(t *testing.T) { - var req *http.Request - req, err := http.NewRequest("GET", "", nil) - if err != nil { - t.Fatal(err) - } - - client := &http.Client{} - - response := &http.Response{ - Status: "500 Internal Server", - StatusCode: 500, - ContentLength: 0, - Close: true, - Body: errorReaderCloser{}, - } - - resreq := &resumableRequestReader{ - client: client, - request: req, - currentResponse: response, - lastRange: 1, - totalSize: 1, - } - defer resreq.Close() - - buf := make([]byte, 1) - read, err := resreq.Read(buf) - if err != nil { - t.Fatal(err) - } - - if read != 0 { - t.Fatalf("Expected to have read nothing, but read %v", read) - } -} - -func TestResumableRequestReaderWithEOFWith416Response(t *testing.T) { - var req *http.Request - req, err := http.NewRequest("GET", "", nil) - if err != nil { - t.Fatal(err) - } - - client := &http.Client{} - - response := &http.Response{ - Status: "416 Requested Range Not Satisfiable", - StatusCode: 416, - ContentLength: 0, - Close: true, - Body: ioutil.NopCloser(strings.NewReader("")), - } - - resreq := &resumableRequestReader{ - client: client, - request: req, - currentResponse: response, - lastRange: 1, - totalSize: 1, - } - defer resreq.Close() - - buf := make([]byte, 1) - _, err = resreq.Read(buf) - if err == nil || err != io.EOF { - t.Fatalf("Expected an io.EOF error, got %v", err) - } -} - -func TestResumableRequestReaderWithServerDoesntSupportByteRanges(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("Range") == "" { - t.Fatalf("Expected a Range HTTP header, got nothing") - } - })) - defer ts.Close() - - var req *http.Request - req, err := http.NewRequest("GET", ts.URL, nil) - if err != nil { - t.Fatal(err) - } - - client := &http.Client{} - - resreq := &resumableRequestReader{ - client: client, - request: req, - lastRange: 1, - } - defer resreq.Close() - - buf := make([]byte, 2) - _, err = resreq.Read(buf) - if err == nil || err.Error() != "the server doesn't support byte ranges" { - t.Fatalf("Expected an error 'the server doesn't support byte ranges', got %v", err) - } -} - -func TestResumableRequestReaderWithZeroTotalSize(t *testing.T) { - - srvtxt := "some response text data" - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, srvtxt) - })) - defer ts.Close() - - var req *http.Request - req, err := http.NewRequest("GET", ts.URL, nil) - if err != nil { - t.Fatal(err) - } - - client := &http.Client{} - retries := uint32(5) - - resreq := ResumableRequestReader(client, req, retries, 0) - defer resreq.Close() - - data, err := ioutil.ReadAll(resreq) - if err != nil { - t.Fatal(err) - } - - resstr := strings.TrimSuffix(string(data), "\n") - - if resstr != srvtxt { - t.Errorf("resstr != srvtxt") - } -} - -func TestResumableRequestReader(t *testing.T) { - - srvtxt := "some response text data" - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, srvtxt) - })) - defer ts.Close() - - var req *http.Request - req, err := http.NewRequest("GET", ts.URL, nil) - if err != nil { - t.Fatal(err) - } - - client := &http.Client{} - retries := uint32(5) - imgSize := int64(len(srvtxt)) - - resreq := ResumableRequestReader(client, req, retries, imgSize) - defer resreq.Close() - - data, err := ioutil.ReadAll(resreq) - if err != nil { - t.Fatal(err) - } - - resstr := strings.TrimSuffix(string(data), "\n") - - if resstr != srvtxt { - t.Errorf("resstr != srvtxt") - } -} - -func TestResumableRequestReaderWithInitialResponse(t *testing.T) { - - srvtxt := "some response text data" - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, srvtxt) - })) - defer ts.Close() - - var req *http.Request - req, err := http.NewRequest("GET", ts.URL, nil) - if err != nil { - t.Fatal(err) - } - - client := &http.Client{} - retries := uint32(5) - imgSize := int64(len(srvtxt)) - - res, err := client.Do(req) - if err != nil { - t.Fatal(err) - } - - resreq := ResumableRequestReaderWithInitialResponse(client, req, retries, imgSize, res) - defer resreq.Close() - - data, err := ioutil.ReadAll(resreq) - if err != nil { - t.Fatal(err) - } - - resstr := strings.TrimSuffix(string(data), "\n") - - if resstr != srvtxt { - t.Errorf("resstr != srvtxt") - } -} diff --git a/vendor/github.com/docker/docker/pkg/idtools/idtools.go b/vendor/github.com/docker/docker/pkg/idtools/idtools.go deleted file mode 100644 index 6bca466..0000000 --- a/vendor/github.com/docker/docker/pkg/idtools/idtools.go +++ /dev/null @@ -1,197 +0,0 @@ -package idtools - -import ( - "bufio" - "fmt" - "os" - "sort" - "strconv" - "strings" -) - -// IDMap contains a single entry for user namespace range remapping. An array -// of IDMap entries represents the structure that will be provided to the Linux -// kernel for creating a user namespace. -type IDMap struct { - ContainerID int `json:"container_id"` - HostID int `json:"host_id"` - Size int `json:"size"` -} - -type subIDRange struct { - Start int - Length int -} - -type ranges []subIDRange - -func (e ranges) Len() int { return len(e) } -func (e ranges) Swap(i, j int) { e[i], e[j] = e[j], e[i] } -func (e ranges) Less(i, j int) bool { return e[i].Start < e[j].Start } - -const ( - subuidFileName string = "/etc/subuid" - subgidFileName string = "/etc/subgid" -) - -// MkdirAllAs creates a directory (include any along the path) and then modifies -// ownership to the requested uid/gid. If the directory already exists, this -// function will still change ownership to the requested uid/gid pair. -func MkdirAllAs(path string, mode os.FileMode, ownerUID, ownerGID int) error { - return mkdirAs(path, mode, ownerUID, ownerGID, true, true) -} - -// MkdirAllNewAs creates a directory (include any along the path) and then modifies -// ownership ONLY of newly created directories to the requested uid/gid. If the -// directories along the path exist, no change of ownership will be performed -func MkdirAllNewAs(path string, mode os.FileMode, ownerUID, ownerGID int) error { - return mkdirAs(path, mode, ownerUID, ownerGID, true, false) -} - -// MkdirAs creates a directory and then modifies ownership to the requested uid/gid. -// If the directory already exists, this function still changes ownership -func MkdirAs(path string, mode os.FileMode, ownerUID, ownerGID int) error { - return mkdirAs(path, mode, ownerUID, ownerGID, false, true) -} - -// GetRootUIDGID retrieves the remapped root uid/gid pair from the set of maps. -// If the maps are empty, then the root uid/gid will default to "real" 0/0 -func GetRootUIDGID(uidMap, gidMap []IDMap) (int, int, error) { - var uid, gid int - - if uidMap != nil { - xUID, err := ToHost(0, uidMap) - if err != nil { - return -1, -1, err - } - uid = xUID - } - if gidMap != nil { - xGID, err := ToHost(0, gidMap) - if err != nil { - return -1, -1, err - } - gid = xGID - } - return uid, gid, nil -} - -// ToContainer takes an id mapping, and uses it to translate a -// host ID to the remapped ID. If no map is provided, then the translation -// assumes a 1-to-1 mapping and returns the passed in id -func ToContainer(hostID int, idMap []IDMap) (int, error) { - if idMap == nil { - return hostID, nil - } - for _, m := range idMap { - if (hostID >= m.HostID) && (hostID <= (m.HostID + m.Size - 1)) { - contID := m.ContainerID + (hostID - m.HostID) - return contID, nil - } - } - return -1, fmt.Errorf("Host ID %d cannot be mapped to a container ID", hostID) -} - -// ToHost takes an id mapping and a remapped ID, and translates the -// ID to the mapped host ID. If no map is provided, then the translation -// assumes a 1-to-1 mapping and returns the passed in id # -func ToHost(contID int, idMap []IDMap) (int, error) { - if idMap == nil { - return contID, nil - } - for _, m := range idMap { - if (contID >= m.ContainerID) && (contID <= (m.ContainerID + m.Size - 1)) { - hostID := m.HostID + (contID - m.ContainerID) - return hostID, nil - } - } - return -1, fmt.Errorf("Container ID %d cannot be mapped to a host ID", contID) -} - -// CreateIDMappings takes a requested user and group name and -// using the data from /etc/sub{uid,gid} ranges, creates the -// proper uid and gid remapping ranges for that user/group pair -func CreateIDMappings(username, groupname string) ([]IDMap, []IDMap, error) { - subuidRanges, err := parseSubuid(username) - if err != nil { - return nil, nil, err - } - subgidRanges, err := parseSubgid(groupname) - if err != nil { - return nil, nil, err - } - if len(subuidRanges) == 0 { - return nil, nil, fmt.Errorf("No subuid ranges found for user %q", username) - } - if len(subgidRanges) == 0 { - return nil, nil, fmt.Errorf("No subgid ranges found for group %q", groupname) - } - - return createIDMap(subuidRanges), createIDMap(subgidRanges), nil -} - -func createIDMap(subidRanges ranges) []IDMap { - idMap := []IDMap{} - - // sort the ranges by lowest ID first - sort.Sort(subidRanges) - containerID := 0 - for _, idrange := range subidRanges { - idMap = append(idMap, IDMap{ - ContainerID: containerID, - HostID: idrange.Start, - Size: idrange.Length, - }) - containerID = containerID + idrange.Length - } - return idMap -} - -func parseSubuid(username string) (ranges, error) { - return parseSubidFile(subuidFileName, username) -} - -func parseSubgid(username string) (ranges, error) { - return parseSubidFile(subgidFileName, username) -} - -// parseSubidFile will read the appropriate file (/etc/subuid or /etc/subgid) -// and return all found ranges for a specified username. If the special value -// "ALL" is supplied for username, then all ranges in the file will be returned -func parseSubidFile(path, username string) (ranges, error) { - var rangeList ranges - - subidFile, err := os.Open(path) - if err != nil { - return rangeList, err - } - defer subidFile.Close() - - s := bufio.NewScanner(subidFile) - for s.Scan() { - if err := s.Err(); err != nil { - return rangeList, err - } - - text := strings.TrimSpace(s.Text()) - if text == "" || strings.HasPrefix(text, "#") { - continue - } - parts := strings.Split(text, ":") - if len(parts) != 3 { - return rangeList, fmt.Errorf("Cannot parse subuid/gid information: Format not correct for %s file", path) - } - if parts[0] == username || username == "ALL" { - startid, err := strconv.Atoi(parts[1]) - if err != nil { - return rangeList, fmt.Errorf("String to int conversion failed during subuid/gid parsing of %s: %v", path, err) - } - length, err := strconv.Atoi(parts[2]) - if err != nil { - return rangeList, fmt.Errorf("String to int conversion failed during subuid/gid parsing of %s: %v", path, err) - } - rangeList = append(rangeList, subIDRange{startid, length}) - } - } - return rangeList, nil -} diff --git a/vendor/github.com/docker/docker/pkg/idtools/idtools_unix.go b/vendor/github.com/docker/docker/pkg/idtools/idtools_unix.go deleted file mode 100644 index f9eb31c..0000000 --- a/vendor/github.com/docker/docker/pkg/idtools/idtools_unix.go +++ /dev/null @@ -1,207 +0,0 @@ -// +build !windows - -package idtools - -import ( - "bytes" - "fmt" - "io" - "os" - "path/filepath" - "strings" - "sync" - - "github.com/docker/docker/pkg/system" - "github.com/opencontainers/runc/libcontainer/user" -) - -var ( - entOnce sync.Once - getentCmd string -) - -func mkdirAs(path string, mode os.FileMode, ownerUID, ownerGID int, mkAll, chownExisting bool) error { - // make an array containing the original path asked for, plus (for mkAll == true) - // all path components leading up to the complete path that don't exist before we MkdirAll - // so that we can chown all of them properly at the end. If chownExisting is false, we won't - // chown the full directory path if it exists - var paths []string - if _, err := os.Stat(path); err != nil && os.IsNotExist(err) { - paths = []string{path} - } else if err == nil && chownExisting { - if err := os.Chown(path, ownerUID, ownerGID); err != nil { - return err - } - // short-circuit--we were called with an existing directory and chown was requested - return nil - } else if err == nil { - // nothing to do; directory path fully exists already and chown was NOT requested - return nil - } - - if mkAll { - // walk back to "/" looking for directories which do not exist - // and add them to the paths array for chown after creation - dirPath := path - for { - dirPath = filepath.Dir(dirPath) - if dirPath == "/" { - break - } - if _, err := os.Stat(dirPath); err != nil && os.IsNotExist(err) { - paths = append(paths, dirPath) - } - } - if err := system.MkdirAll(path, mode); err != nil && !os.IsExist(err) { - return err - } - } else { - if err := os.Mkdir(path, mode); err != nil && !os.IsExist(err) { - return err - } - } - // even if it existed, we will chown the requested path + any subpaths that - // didn't exist when we called MkdirAll - for _, pathComponent := range paths { - if err := os.Chown(pathComponent, ownerUID, ownerGID); err != nil { - return err - } - } - return nil -} - -// CanAccess takes a valid (existing) directory and a uid, gid pair and determines -// if that uid, gid pair has access (execute bit) to the directory -func CanAccess(path string, uid, gid int) bool { - statInfo, err := system.Stat(path) - if err != nil { - return false - } - fileMode := os.FileMode(statInfo.Mode()) - permBits := fileMode.Perm() - return accessible(statInfo.UID() == uint32(uid), - statInfo.GID() == uint32(gid), permBits) -} - -func accessible(isOwner, isGroup bool, perms os.FileMode) bool { - if isOwner && (perms&0100 == 0100) { - return true - } - if isGroup && (perms&0010 == 0010) { - return true - } - if perms&0001 == 0001 { - return true - } - return false -} - -// LookupUser uses traditional local system files lookup (from libcontainer/user) on a username, -// followed by a call to `getent` for supporting host configured non-files passwd and group dbs -func LookupUser(username string) (user.User, error) { - // first try a local system files lookup using existing capabilities - usr, err := user.LookupUser(username) - if err == nil { - return usr, nil - } - // local files lookup failed; attempt to call `getent` to query configured passwd dbs - usr, err = getentUser(fmt.Sprintf("%s %s", "passwd", username)) - if err != nil { - return user.User{}, err - } - return usr, nil -} - -// LookupUID uses traditional local system files lookup (from libcontainer/user) on a uid, -// followed by a call to `getent` for supporting host configured non-files passwd and group dbs -func LookupUID(uid int) (user.User, error) { - // first try a local system files lookup using existing capabilities - usr, err := user.LookupUid(uid) - if err == nil { - return usr, nil - } - // local files lookup failed; attempt to call `getent` to query configured passwd dbs - return getentUser(fmt.Sprintf("%s %d", "passwd", uid)) -} - -func getentUser(args string) (user.User, error) { - reader, err := callGetent(args) - if err != nil { - return user.User{}, err - } - users, err := user.ParsePasswd(reader) - if err != nil { - return user.User{}, err - } - if len(users) == 0 { - return user.User{}, fmt.Errorf("getent failed to find passwd entry for %q", strings.Split(args, " ")[1]) - } - return users[0], nil -} - -// LookupGroup uses traditional local system files lookup (from libcontainer/user) on a group name, -// followed by a call to `getent` for supporting host configured non-files passwd and group dbs -func LookupGroup(groupname string) (user.Group, error) { - // first try a local system files lookup using existing capabilities - group, err := user.LookupGroup(groupname) - if err == nil { - return group, nil - } - // local files lookup failed; attempt to call `getent` to query configured group dbs - return getentGroup(fmt.Sprintf("%s %s", "group", groupname)) -} - -// LookupGID uses traditional local system files lookup (from libcontainer/user) on a group ID, -// followed by a call to `getent` for supporting host configured non-files passwd and group dbs -func LookupGID(gid int) (user.Group, error) { - // first try a local system files lookup using existing capabilities - group, err := user.LookupGid(gid) - if err == nil { - return group, nil - } - // local files lookup failed; attempt to call `getent` to query configured group dbs - return getentGroup(fmt.Sprintf("%s %d", "group", gid)) -} - -func getentGroup(args string) (user.Group, error) { - reader, err := callGetent(args) - if err != nil { - return user.Group{}, err - } - groups, err := user.ParseGroup(reader) - if err != nil { - return user.Group{}, err - } - if len(groups) == 0 { - return user.Group{}, fmt.Errorf("getent failed to find groups entry for %q", strings.Split(args, " ")[1]) - } - return groups[0], nil -} - -func callGetent(args string) (io.Reader, error) { - entOnce.Do(func() { getentCmd, _ = resolveBinary("getent") }) - // if no `getent` command on host, can't do anything else - if getentCmd == "" { - return nil, fmt.Errorf("") - } - out, err := execCmd(getentCmd, args) - if err != nil { - exitCode, errC := system.GetExitCode(err) - if errC != nil { - return nil, err - } - switch exitCode { - case 1: - return nil, fmt.Errorf("getent reported invalid parameters/database unknown") - case 2: - terms := strings.Split(args, " ") - return nil, fmt.Errorf("getent unable to find entry %q in %s database", terms[1], terms[0]) - case 3: - return nil, fmt.Errorf("getent database doesn't support enumeration") - default: - return nil, err - } - - } - return bytes.NewReader(out), nil -} diff --git a/vendor/github.com/docker/docker/pkg/idtools/idtools_unix_test.go b/vendor/github.com/docker/docker/pkg/idtools/idtools_unix_test.go deleted file mode 100644 index 540d307..0000000 --- a/vendor/github.com/docker/docker/pkg/idtools/idtools_unix_test.go +++ /dev/null @@ -1,271 +0,0 @@ -// +build !windows - -package idtools - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "syscall" - "testing" -) - -type node struct { - uid int - gid int -} - -func TestMkdirAllAs(t *testing.T) { - dirName, err := ioutil.TempDir("", "mkdirall") - if err != nil { - t.Fatalf("Couldn't create temp dir: %v", err) - } - defer os.RemoveAll(dirName) - - testTree := map[string]node{ - "usr": {0, 0}, - "usr/bin": {0, 0}, - "lib": {33, 33}, - "lib/x86_64": {45, 45}, - "lib/x86_64/share": {1, 1}, - } - - if err := buildTree(dirName, testTree); err != nil { - t.Fatal(err) - } - - // test adding a directory to a pre-existing dir; only the new dir is owned by the uid/gid - if err := MkdirAllAs(filepath.Join(dirName, "usr", "share"), 0755, 99, 99); err != nil { - t.Fatal(err) - } - testTree["usr/share"] = node{99, 99} - verifyTree, err := readTree(dirName, "") - if err != nil { - t.Fatal(err) - } - if err := compareTrees(testTree, verifyTree); err != nil { - t.Fatal(err) - } - - // test 2-deep new directories--both should be owned by the uid/gid pair - if err := MkdirAllAs(filepath.Join(dirName, "lib", "some", "other"), 0755, 101, 101); err != nil { - t.Fatal(err) - } - testTree["lib/some"] = node{101, 101} - testTree["lib/some/other"] = node{101, 101} - verifyTree, err = readTree(dirName, "") - if err != nil { - t.Fatal(err) - } - if err := compareTrees(testTree, verifyTree); err != nil { - t.Fatal(err) - } - - // test a directory that already exists; should be chowned, but nothing else - if err := MkdirAllAs(filepath.Join(dirName, "usr"), 0755, 102, 102); err != nil { - t.Fatal(err) - } - testTree["usr"] = node{102, 102} - verifyTree, err = readTree(dirName, "") - if err != nil { - t.Fatal(err) - } - if err := compareTrees(testTree, verifyTree); err != nil { - t.Fatal(err) - } -} - -func TestMkdirAllNewAs(t *testing.T) { - - dirName, err := ioutil.TempDir("", "mkdirnew") - if err != nil { - t.Fatalf("Couldn't create temp dir: %v", err) - } - defer os.RemoveAll(dirName) - - testTree := map[string]node{ - "usr": {0, 0}, - "usr/bin": {0, 0}, - "lib": {33, 33}, - "lib/x86_64": {45, 45}, - "lib/x86_64/share": {1, 1}, - } - - if err := buildTree(dirName, testTree); err != nil { - t.Fatal(err) - } - - // test adding a directory to a pre-existing dir; only the new dir is owned by the uid/gid - if err := MkdirAllNewAs(filepath.Join(dirName, "usr", "share"), 0755, 99, 99); err != nil { - t.Fatal(err) - } - testTree["usr/share"] = node{99, 99} - verifyTree, err := readTree(dirName, "") - if err != nil { - t.Fatal(err) - } - if err := compareTrees(testTree, verifyTree); err != nil { - t.Fatal(err) - } - - // test 2-deep new directories--both should be owned by the uid/gid pair - if err := MkdirAllNewAs(filepath.Join(dirName, "lib", "some", "other"), 0755, 101, 101); err != nil { - t.Fatal(err) - } - testTree["lib/some"] = node{101, 101} - testTree["lib/some/other"] = node{101, 101} - verifyTree, err = readTree(dirName, "") - if err != nil { - t.Fatal(err) - } - if err := compareTrees(testTree, verifyTree); err != nil { - t.Fatal(err) - } - - // test a directory that already exists; should NOT be chowned - if err := MkdirAllNewAs(filepath.Join(dirName, "usr"), 0755, 102, 102); err != nil { - t.Fatal(err) - } - verifyTree, err = readTree(dirName, "") - if err != nil { - t.Fatal(err) - } - if err := compareTrees(testTree, verifyTree); err != nil { - t.Fatal(err) - } -} - -func TestMkdirAs(t *testing.T) { - - dirName, err := ioutil.TempDir("", "mkdir") - if err != nil { - t.Fatalf("Couldn't create temp dir: %v", err) - } - defer os.RemoveAll(dirName) - - testTree := map[string]node{ - "usr": {0, 0}, - } - if err := buildTree(dirName, testTree); err != nil { - t.Fatal(err) - } - - // test a directory that already exists; should just chown to the requested uid/gid - if err := MkdirAs(filepath.Join(dirName, "usr"), 0755, 99, 99); err != nil { - t.Fatal(err) - } - testTree["usr"] = node{99, 99} - verifyTree, err := readTree(dirName, "") - if err != nil { - t.Fatal(err) - } - if err := compareTrees(testTree, verifyTree); err != nil { - t.Fatal(err) - } - - // create a subdir under a dir which doesn't exist--should fail - if err := MkdirAs(filepath.Join(dirName, "usr", "bin", "subdir"), 0755, 102, 102); err == nil { - t.Fatalf("Trying to create a directory with Mkdir where the parent doesn't exist should have failed") - } - - // create a subdir under an existing dir; should only change the ownership of the new subdir - if err := MkdirAs(filepath.Join(dirName, "usr", "bin"), 0755, 102, 102); err != nil { - t.Fatal(err) - } - testTree["usr/bin"] = node{102, 102} - verifyTree, err = readTree(dirName, "") - if err != nil { - t.Fatal(err) - } - if err := compareTrees(testTree, verifyTree); err != nil { - t.Fatal(err) - } -} - -func buildTree(base string, tree map[string]node) error { - for path, node := range tree { - fullPath := filepath.Join(base, path) - if err := os.MkdirAll(fullPath, 0755); err != nil { - return fmt.Errorf("Couldn't create path: %s; error: %v", fullPath, err) - } - if err := os.Chown(fullPath, node.uid, node.gid); err != nil { - return fmt.Errorf("Couldn't chown path: %s; error: %v", fullPath, err) - } - } - return nil -} - -func readTree(base, root string) (map[string]node, error) { - tree := make(map[string]node) - - dirInfos, err := ioutil.ReadDir(base) - if err != nil { - return nil, fmt.Errorf("Couldn't read directory entries for %q: %v", base, err) - } - - for _, info := range dirInfos { - s := &syscall.Stat_t{} - if err := syscall.Stat(filepath.Join(base, info.Name()), s); err != nil { - return nil, fmt.Errorf("Can't stat file %q: %v", filepath.Join(base, info.Name()), err) - } - tree[filepath.Join(root, info.Name())] = node{int(s.Uid), int(s.Gid)} - if info.IsDir() { - // read the subdirectory - subtree, err := readTree(filepath.Join(base, info.Name()), filepath.Join(root, info.Name())) - if err != nil { - return nil, err - } - for path, nodeinfo := range subtree { - tree[path] = nodeinfo - } - } - } - return tree, nil -} - -func compareTrees(left, right map[string]node) error { - if len(left) != len(right) { - return fmt.Errorf("Trees aren't the same size") - } - for path, nodeLeft := range left { - if nodeRight, ok := right[path]; ok { - if nodeRight.uid != nodeLeft.uid || nodeRight.gid != nodeLeft.gid { - // mismatch - return fmt.Errorf("mismatched ownership for %q: expected: %d:%d, got: %d:%d", path, - nodeLeft.uid, nodeLeft.gid, nodeRight.uid, nodeRight.gid) - } - continue - } - return fmt.Errorf("right tree didn't contain path %q", path) - } - return nil -} - -func TestParseSubidFileWithNewlinesAndComments(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "parsesubid") - if err != nil { - t.Fatal(err) - } - fnamePath := filepath.Join(tmpDir, "testsubuid") - fcontent := `tss:100000:65536 -# empty default subuid/subgid file - -dockremap:231072:65536` - if err := ioutil.WriteFile(fnamePath, []byte(fcontent), 0644); err != nil { - t.Fatal(err) - } - ranges, err := parseSubidFile(fnamePath, "dockremap") - if err != nil { - t.Fatal(err) - } - if len(ranges) != 1 { - t.Fatalf("wanted 1 element in ranges, got %d instead", len(ranges)) - } - if ranges[0].Start != 231072 { - t.Fatalf("wanted 231072, got %d instead", ranges[0].Start) - } - if ranges[0].Length != 65536 { - t.Fatalf("wanted 65536, got %d instead", ranges[0].Length) - } -} diff --git a/vendor/github.com/docker/docker/pkg/idtools/idtools_windows.go b/vendor/github.com/docker/docker/pkg/idtools/idtools_windows.go deleted file mode 100644 index 49f67e7..0000000 --- a/vendor/github.com/docker/docker/pkg/idtools/idtools_windows.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build windows - -package idtools - -import ( - "os" - - "github.com/docker/docker/pkg/system" -) - -// Platforms such as Windows do not support the UID/GID concept. So make this -// just a wrapper around system.MkdirAll. -func mkdirAs(path string, mode os.FileMode, ownerUID, ownerGID int, mkAll, chownExisting bool) error { - if err := system.MkdirAll(path, mode); err != nil && !os.IsExist(err) { - return err - } - return nil -} - -// CanAccess takes a valid (existing) directory and a uid, gid pair and determines -// if that uid, gid pair has access (execute bit) to the directory -// Windows does not require/support this function, so always return true -func CanAccess(path string, uid, gid int) bool { - return true -} diff --git a/vendor/github.com/docker/docker/pkg/idtools/usergroupadd_linux.go b/vendor/github.com/docker/docker/pkg/idtools/usergroupadd_linux.go deleted file mode 100644 index 9da7975..0000000 --- a/vendor/github.com/docker/docker/pkg/idtools/usergroupadd_linux.go +++ /dev/null @@ -1,164 +0,0 @@ -package idtools - -import ( - "fmt" - "regexp" - "sort" - "strconv" - "strings" - "sync" -) - -// add a user and/or group to Linux /etc/passwd, /etc/group using standard -// Linux distribution commands: -// adduser --system --shell /bin/false --disabled-login --disabled-password --no-create-home --group -// useradd -r -s /bin/false - -var ( - once sync.Once - userCommand string - - cmdTemplates = map[string]string{ - "adduser": "--system --shell /bin/false --no-create-home --disabled-login --disabled-password --group %s", - "useradd": "-r -s /bin/false %s", - "usermod": "-%s %d-%d %s", - } - - idOutRegexp = regexp.MustCompile(`uid=([0-9]+).*gid=([0-9]+)`) - // default length for a UID/GID subordinate range - defaultRangeLen = 65536 - defaultRangeStart = 100000 - userMod = "usermod" -) - -// AddNamespaceRangesUser takes a username and uses the standard system -// utility to create a system user/group pair used to hold the -// /etc/sub{uid,gid} ranges which will be used for user namespace -// mapping ranges in containers. -func AddNamespaceRangesUser(name string) (int, int, error) { - if err := addUser(name); err != nil { - return -1, -1, fmt.Errorf("Error adding user %q: %v", name, err) - } - - // Query the system for the created uid and gid pair - out, err := execCmd("id", name) - if err != nil { - return -1, -1, fmt.Errorf("Error trying to find uid/gid for new user %q: %v", name, err) - } - matches := idOutRegexp.FindStringSubmatch(strings.TrimSpace(string(out))) - if len(matches) != 3 { - return -1, -1, fmt.Errorf("Can't find uid, gid from `id` output: %q", string(out)) - } - uid, err := strconv.Atoi(matches[1]) - if err != nil { - return -1, -1, fmt.Errorf("Can't convert found uid (%s) to int: %v", matches[1], err) - } - gid, err := strconv.Atoi(matches[2]) - if err != nil { - return -1, -1, fmt.Errorf("Can't convert found gid (%s) to int: %v", matches[2], err) - } - - // Now we need to create the subuid/subgid ranges for our new user/group (system users - // do not get auto-created ranges in subuid/subgid) - - if err := createSubordinateRanges(name); err != nil { - return -1, -1, fmt.Errorf("Couldn't create subordinate ID ranges: %v", err) - } - return uid, gid, nil -} - -func addUser(userName string) error { - once.Do(func() { - // set up which commands are used for adding users/groups dependent on distro - if _, err := resolveBinary("adduser"); err == nil { - userCommand = "adduser" - } else if _, err := resolveBinary("useradd"); err == nil { - userCommand = "useradd" - } - }) - if userCommand == "" { - return fmt.Errorf("Cannot add user; no useradd/adduser binary found") - } - args := fmt.Sprintf(cmdTemplates[userCommand], userName) - out, err := execCmd(userCommand, args) - if err != nil { - return fmt.Errorf("Failed to add user with error: %v; output: %q", err, string(out)) - } - return nil -} - -func createSubordinateRanges(name string) error { - - // first, we should verify that ranges weren't automatically created - // by the distro tooling - ranges, err := parseSubuid(name) - if err != nil { - return fmt.Errorf("Error while looking for subuid ranges for user %q: %v", name, err) - } - if len(ranges) == 0 { - // no UID ranges; let's create one - startID, err := findNextUIDRange() - if err != nil { - return fmt.Errorf("Can't find available subuid range: %v", err) - } - out, err := execCmd(userMod, fmt.Sprintf(cmdTemplates[userMod], "v", startID, startID+defaultRangeLen-1, name)) - if err != nil { - return fmt.Errorf("Unable to add subuid range to user: %q; output: %s, err: %v", name, out, err) - } - } - - ranges, err = parseSubgid(name) - if err != nil { - return fmt.Errorf("Error while looking for subgid ranges for user %q: %v", name, err) - } - if len(ranges) == 0 { - // no GID ranges; let's create one - startID, err := findNextGIDRange() - if err != nil { - return fmt.Errorf("Can't find available subgid range: %v", err) - } - out, err := execCmd(userMod, fmt.Sprintf(cmdTemplates[userMod], "w", startID, startID+defaultRangeLen-1, name)) - if err != nil { - return fmt.Errorf("Unable to add subgid range to user: %q; output: %s, err: %v", name, out, err) - } - } - return nil -} - -func findNextUIDRange() (int, error) { - ranges, err := parseSubuid("ALL") - if err != nil { - return -1, fmt.Errorf("Couldn't parse all ranges in /etc/subuid file: %v", err) - } - sort.Sort(ranges) - return findNextRangeStart(ranges) -} - -func findNextGIDRange() (int, error) { - ranges, err := parseSubgid("ALL") - if err != nil { - return -1, fmt.Errorf("Couldn't parse all ranges in /etc/subgid file: %v", err) - } - sort.Sort(ranges) - return findNextRangeStart(ranges) -} - -func findNextRangeStart(rangeList ranges) (int, error) { - startID := defaultRangeStart - for _, arange := range rangeList { - if wouldOverlap(arange, startID) { - startID = arange.Start + arange.Length - } - } - return startID, nil -} - -func wouldOverlap(arange subIDRange, ID int) bool { - low := ID - high := ID + defaultRangeLen - if (low >= arange.Start && low <= arange.Start+arange.Length) || - (high <= arange.Start+arange.Length && high >= arange.Start) { - return true - } - return false -} diff --git a/vendor/github.com/docker/docker/pkg/idtools/usergroupadd_unsupported.go b/vendor/github.com/docker/docker/pkg/idtools/usergroupadd_unsupported.go deleted file mode 100644 index d98b354..0000000 --- a/vendor/github.com/docker/docker/pkg/idtools/usergroupadd_unsupported.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !linux - -package idtools - -import "fmt" - -// AddNamespaceRangesUser takes a name and finds an unused uid, gid pair -// and calls the appropriate helper function to add the group and then -// the user to the group in /etc/group and /etc/passwd respectively. -func AddNamespaceRangesUser(name string) (int, int, error) { - return -1, -1, fmt.Errorf("No support for adding users or groups on this OS") -} diff --git a/vendor/github.com/docker/docker/pkg/idtools/utils_unix.go b/vendor/github.com/docker/docker/pkg/idtools/utils_unix.go deleted file mode 100644 index 9703ecb..0000000 --- a/vendor/github.com/docker/docker/pkg/idtools/utils_unix.go +++ /dev/null @@ -1,32 +0,0 @@ -// +build !windows - -package idtools - -import ( - "fmt" - "os/exec" - "path/filepath" - "strings" -) - -func resolveBinary(binname string) (string, error) { - binaryPath, err := exec.LookPath(binname) - if err != nil { - return "", err - } - resolvedPath, err := filepath.EvalSymlinks(binaryPath) - if err != nil { - return "", err - } - //only return no error if the final resolved binary basename - //matches what was searched for - if filepath.Base(resolvedPath) == binname { - return resolvedPath, nil - } - return "", fmt.Errorf("Binary %q does not resolve to a binary of that name in $PATH (%q)", binname, resolvedPath) -} - -func execCmd(cmd, args string) ([]byte, error) { - execCmd := exec.Command(cmd, strings.Split(args, " ")...) - return execCmd.CombinedOutput() -} diff --git a/vendor/github.com/docker/docker/pkg/integration/checker/checker.go b/vendor/github.com/docker/docker/pkg/integration/checker/checker.go deleted file mode 100644 index d1b703a..0000000 --- a/vendor/github.com/docker/docker/pkg/integration/checker/checker.go +++ /dev/null @@ -1,46 +0,0 @@ -// Package checker provides Docker specific implementations of the go-check.Checker interface. -package checker - -import ( - "github.com/go-check/check" - "github.com/vdemeester/shakers" -) - -// As a commodity, we bring all check.Checker variables into the current namespace to avoid having -// to think about check.X versus checker.X. -var ( - DeepEquals = check.DeepEquals - ErrorMatches = check.ErrorMatches - FitsTypeOf = check.FitsTypeOf - HasLen = check.HasLen - Implements = check.Implements - IsNil = check.IsNil - Matches = check.Matches - Not = check.Not - NotNil = check.NotNil - PanicMatches = check.PanicMatches - Panics = check.Panics - - Contains = shakers.Contains - ContainsAny = shakers.ContainsAny - Count = shakers.Count - Equals = shakers.Equals - EqualFold = shakers.EqualFold - False = shakers.False - GreaterOrEqualThan = shakers.GreaterOrEqualThan - GreaterThan = shakers.GreaterThan - HasPrefix = shakers.HasPrefix - HasSuffix = shakers.HasSuffix - Index = shakers.Index - IndexAny = shakers.IndexAny - IsAfter = shakers.IsAfter - IsBefore = shakers.IsBefore - IsBetween = shakers.IsBetween - IsLower = shakers.IsLower - IsUpper = shakers.IsUpper - LessOrEqualThan = shakers.LessOrEqualThan - LessThan = shakers.LessThan - TimeEquals = shakers.TimeEquals - True = shakers.True - TimeIgnore = shakers.TimeIgnore -) diff --git a/vendor/github.com/docker/docker/pkg/integration/cmd/command.go b/vendor/github.com/docker/docker/pkg/integration/cmd/command.go deleted file mode 100644 index 76d04e8..0000000 --- a/vendor/github.com/docker/docker/pkg/integration/cmd/command.go +++ /dev/null @@ -1,294 +0,0 @@ -package cmd - -import ( - "bytes" - "fmt" - "io" - "os/exec" - "path/filepath" - "runtime" - "strings" - "sync" - "time" - - "github.com/docker/docker/pkg/system" - "github.com/go-check/check" -) - -type testingT interface { - Fatalf(string, ...interface{}) -} - -const ( - // None is a token to inform Result.Assert that the output should be empty - None string = "" -) - -type lockedBuffer struct { - m sync.RWMutex - buf bytes.Buffer -} - -func (buf *lockedBuffer) Write(b []byte) (int, error) { - buf.m.Lock() - defer buf.m.Unlock() - return buf.buf.Write(b) -} - -func (buf *lockedBuffer) String() string { - buf.m.RLock() - defer buf.m.RUnlock() - return buf.buf.String() -} - -// Result stores the result of running a command -type Result struct { - Cmd *exec.Cmd - ExitCode int - Error error - // Timeout is true if the command was killed because it ran for too long - Timeout bool - outBuffer *lockedBuffer - errBuffer *lockedBuffer -} - -// Assert compares the Result against the Expected struct, and fails the test if -// any of the expcetations are not met. -func (r *Result) Assert(t testingT, exp Expected) { - err := r.Compare(exp) - if err == nil { - return - } - - _, file, line, _ := runtime.Caller(1) - t.Fatalf("at %s:%d\n%s", filepath.Base(file), line, err.Error()) -} - -// Compare returns an formatted error with the command, stdout, stderr, exit -// code, and any failed expectations -func (r *Result) Compare(exp Expected) error { - errors := []string{} - add := func(format string, args ...interface{}) { - errors = append(errors, fmt.Sprintf(format, args...)) - } - - if exp.ExitCode != r.ExitCode { - add("ExitCode was %d expected %d", r.ExitCode, exp.ExitCode) - } - if exp.Timeout != r.Timeout { - if exp.Timeout { - add("Expected command to timeout") - } else { - add("Expected command to finish, but it hit the timeout") - } - } - if !matchOutput(exp.Out, r.Stdout()) { - add("Expected stdout to contain %q", exp.Out) - } - if !matchOutput(exp.Err, r.Stderr()) { - add("Expected stderr to contain %q", exp.Err) - } - switch { - // If a non-zero exit code is expected there is going to be an error. - // Don't require an error message as well as an exit code because the - // error message is going to be "exit status which is not useful - case exp.Error == "" && exp.ExitCode != 0: - case exp.Error == "" && r.Error != nil: - add("Expected no error") - case exp.Error != "" && r.Error == nil: - add("Expected error to contain %q, but there was no error", exp.Error) - case exp.Error != "" && !strings.Contains(r.Error.Error(), exp.Error): - add("Expected error to contain %q", exp.Error) - } - - if len(errors) == 0 { - return nil - } - return fmt.Errorf("%s\nFailures:\n%s\n", r, strings.Join(errors, "\n")) -} - -func matchOutput(expected string, actual string) bool { - switch expected { - case None: - return actual == "" - default: - return strings.Contains(actual, expected) - } -} - -func (r *Result) String() string { - var timeout string - if r.Timeout { - timeout = " (timeout)" - } - - return fmt.Sprintf(` -Command: %s -ExitCode: %d%s, Error: %s -Stdout: %v -Stderr: %v -`, - strings.Join(r.Cmd.Args, " "), - r.ExitCode, - timeout, - r.Error, - r.Stdout(), - r.Stderr()) -} - -// Expected is the expected output from a Command. This struct is compared to a -// Result struct by Result.Assert(). -type Expected struct { - ExitCode int - Timeout bool - Error string - Out string - Err string -} - -// Success is the default expected result -var Success = Expected{} - -// Stdout returns the stdout of the process as a string -func (r *Result) Stdout() string { - return r.outBuffer.String() -} - -// Stderr returns the stderr of the process as a string -func (r *Result) Stderr() string { - return r.errBuffer.String() -} - -// Combined returns the stdout and stderr combined into a single string -func (r *Result) Combined() string { - return r.outBuffer.String() + r.errBuffer.String() -} - -// SetExitError sets Error and ExitCode based on Error -func (r *Result) SetExitError(err error) { - if err == nil { - return - } - r.Error = err - r.ExitCode = system.ProcessExitCode(err) -} - -type matches struct{} - -// Info returns the CheckerInfo -func (m *matches) Info() *check.CheckerInfo { - return &check.CheckerInfo{ - Name: "CommandMatches", - Params: []string{"result", "expected"}, - } -} - -// Check compares a result against the expected -func (m *matches) Check(params []interface{}, names []string) (bool, string) { - result, ok := params[0].(*Result) - if !ok { - return false, fmt.Sprintf("result must be a *Result, not %T", params[0]) - } - expected, ok := params[1].(Expected) - if !ok { - return false, fmt.Sprintf("expected must be an Expected, not %T", params[1]) - } - - err := result.Compare(expected) - if err == nil { - return true, "" - } - return false, err.Error() -} - -// Matches is a gocheck.Checker for comparing a Result against an Expected -var Matches = &matches{} - -// Cmd contains the arguments and options for a process to run as part of a test -// suite. -type Cmd struct { - Command []string - Timeout time.Duration - Stdin io.Reader - Stdout io.Writer - Dir string - Env []string -} - -// RunCmd runs a command and returns a Result -func RunCmd(cmd Cmd) *Result { - result := StartCmd(cmd) - if result.Error != nil { - return result - } - return WaitOnCmd(cmd.Timeout, result) -} - -// RunCommand parses a command line and runs it, returning a result -func RunCommand(command string, args ...string) *Result { - return RunCmd(Cmd{Command: append([]string{command}, args...)}) -} - -// StartCmd starts a command, but doesn't wait for it to finish -func StartCmd(cmd Cmd) *Result { - result := buildCmd(cmd) - if result.Error != nil { - return result - } - result.SetExitError(result.Cmd.Start()) - return result -} - -func buildCmd(cmd Cmd) *Result { - var execCmd *exec.Cmd - switch len(cmd.Command) { - case 1: - execCmd = exec.Command(cmd.Command[0]) - default: - execCmd = exec.Command(cmd.Command[0], cmd.Command[1:]...) - } - outBuffer := new(lockedBuffer) - errBuffer := new(lockedBuffer) - - execCmd.Stdin = cmd.Stdin - execCmd.Dir = cmd.Dir - execCmd.Env = cmd.Env - if cmd.Stdout != nil { - execCmd.Stdout = io.MultiWriter(outBuffer, cmd.Stdout) - } else { - execCmd.Stdout = outBuffer - } - execCmd.Stderr = errBuffer - return &Result{ - Cmd: execCmd, - outBuffer: outBuffer, - errBuffer: errBuffer, - } -} - -// WaitOnCmd waits for a command to complete. If timeout is non-nil then -// only wait until the timeout. -func WaitOnCmd(timeout time.Duration, result *Result) *Result { - if timeout == time.Duration(0) { - result.SetExitError(result.Cmd.Wait()) - return result - } - - done := make(chan error, 1) - // Wait for command to exit in a goroutine - go func() { - done <- result.Cmd.Wait() - }() - - select { - case <-time.After(timeout): - killErr := result.Cmd.Process.Kill() - if killErr != nil { - fmt.Printf("failed to kill (pid=%d): %v\n", result.Cmd.Process.Pid, killErr) - } - result.Timeout = true - case err := <-done: - result.SetExitError(err) - } - return result -} diff --git a/vendor/github.com/docker/docker/pkg/integration/cmd/command_test.go b/vendor/github.com/docker/docker/pkg/integration/cmd/command_test.go deleted file mode 100644 index df23442..0000000 --- a/vendor/github.com/docker/docker/pkg/integration/cmd/command_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package cmd - -import ( - "runtime" - "strings" - "testing" - "time" - - "github.com/docker/docker/pkg/testutil/assert" -) - -func TestRunCommand(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - - var cmd string - if runtime.GOOS == "solaris" { - cmd = "gls" - } else { - cmd = "ls" - } - result := RunCommand(cmd) - result.Assert(t, Expected{}) - - result = RunCommand("doesnotexists") - expectedError := `exec: "doesnotexists": executable file not found` - result.Assert(t, Expected{ExitCode: 127, Error: expectedError}) - - result = RunCommand(cmd, "-z") - result.Assert(t, Expected{ - ExitCode: 2, - Error: "exit status 2", - Err: "invalid option", - }) - assert.Contains(t, result.Combined(), "invalid option") -} - -func TestRunCommandWithCombined(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - - result := RunCommand("ls", "-a") - result.Assert(t, Expected{}) - - assert.Contains(t, result.Combined(), "..") - assert.Contains(t, result.Stdout(), "..") -} - -func TestRunCommandWithTimeoutFinished(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - - result := RunCmd(Cmd{ - Command: []string{"ls", "-a"}, - Timeout: 50 * time.Millisecond, - }) - result.Assert(t, Expected{Out: ".."}) -} - -func TestRunCommandWithTimeoutKilled(t *testing.T) { - // TODO Windows: Port this test - if runtime.GOOS == "windows" { - t.Skip("Needs porting to Windows") - } - - command := []string{"sh", "-c", "while true ; do echo 1 ; sleep .5 ; done"} - result := RunCmd(Cmd{Command: command, Timeout: 1250 * time.Millisecond}) - result.Assert(t, Expected{Timeout: true}) - - ones := strings.Split(result.Stdout(), "\n") - assert.Equal(t, len(ones), 4) -} - -func TestRunCommandWithErrors(t *testing.T) { - result := RunCommand("/foobar") - result.Assert(t, Expected{Error: "foobar", ExitCode: 127}) -} - -func TestRunCommandWithStdoutStderr(t *testing.T) { - result := RunCommand("echo", "hello", "world") - result.Assert(t, Expected{Out: "hello world\n", Err: None}) -} - -func TestRunCommandWithStdoutStderrError(t *testing.T) { - result := RunCommand("doesnotexists") - - expected := `exec: "doesnotexists": executable file not found` - result.Assert(t, Expected{Out: None, Err: None, ExitCode: 127, Error: expected}) - - switch runtime.GOOS { - case "windows": - expected = "ls: unknown option" - case "solaris": - expected = "gls: invalid option" - default: - expected = "ls: invalid option" - } - - var cmd string - if runtime.GOOS == "solaris" { - cmd = "gls" - } else { - cmd = "ls" - } - result = RunCommand(cmd, "-z") - result.Assert(t, Expected{ - Out: None, - Err: expected, - ExitCode: 2, - Error: "exit status 2", - }) -} diff --git a/vendor/github.com/docker/docker/pkg/integration/utils.go b/vendor/github.com/docker/docker/pkg/integration/utils.go deleted file mode 100644 index f2089c4..0000000 --- a/vendor/github.com/docker/docker/pkg/integration/utils.go +++ /dev/null @@ -1,227 +0,0 @@ -package integration - -import ( - "archive/tar" - "errors" - "fmt" - "io" - "os" - "os/exec" - "path/filepath" - "reflect" - "strings" - "syscall" - "time" - - icmd "github.com/docker/docker/pkg/integration/cmd" - "github.com/docker/docker/pkg/stringutils" - "github.com/docker/docker/pkg/system" -) - -// IsKilled process the specified error and returns whether the process was killed or not. -func IsKilled(err error) bool { - if exitErr, ok := err.(*exec.ExitError); ok { - status, ok := exitErr.Sys().(syscall.WaitStatus) - if !ok { - return false - } - // status.ExitStatus() is required on Windows because it does not - // implement Signal() nor Signaled(). Just check it had a bad exit - // status could mean it was killed (and in tests we do kill) - return (status.Signaled() && status.Signal() == os.Kill) || status.ExitStatus() != 0 - } - return false -} - -func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) { - exitCode = 0 - out, err := cmd.CombinedOutput() - exitCode = system.ProcessExitCode(err) - output = string(out) - return -} - -// RunCommandPipelineWithOutput runs the array of commands with the output -// of each pipelined with the following (like cmd1 | cmd2 | cmd3 would do). -// It returns the final output, the exitCode different from 0 and the error -// if something bad happened. -func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode int, err error) { - if len(cmds) < 2 { - return "", 0, errors.New("pipeline does not have multiple cmds") - } - - // connect stdin of each cmd to stdout pipe of previous cmd - for i, cmd := range cmds { - if i > 0 { - prevCmd := cmds[i-1] - cmd.Stdin, err = prevCmd.StdoutPipe() - - if err != nil { - return "", 0, fmt.Errorf("cannot set stdout pipe for %s: %v", cmd.Path, err) - } - } - } - - // start all cmds except the last - for _, cmd := range cmds[:len(cmds)-1] { - if err = cmd.Start(); err != nil { - return "", 0, fmt.Errorf("starting %s failed with error: %v", cmd.Path, err) - } - } - - defer func() { - var pipeErrMsgs []string - // wait all cmds except the last to release their resources - for _, cmd := range cmds[:len(cmds)-1] { - if pipeErr := cmd.Wait(); pipeErr != nil { - pipeErrMsgs = append(pipeErrMsgs, fmt.Sprintf("command %s failed with error: %v", cmd.Path, pipeErr)) - } - } - if len(pipeErrMsgs) > 0 && err == nil { - err = fmt.Errorf("pipelineError from Wait: %v", strings.Join(pipeErrMsgs, ", ")) - } - }() - - // wait on last cmd - return runCommandWithOutput(cmds[len(cmds)-1]) -} - -// ConvertSliceOfStringsToMap converts a slices of string in a map -// with the strings as key and an empty string as values. -func ConvertSliceOfStringsToMap(input []string) map[string]struct{} { - output := make(map[string]struct{}) - for _, v := range input { - output[v] = struct{}{} - } - return output -} - -// CompareDirectoryEntries compares two sets of FileInfo (usually taken from a directory) -// and returns an error if different. -func CompareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error { - var ( - e1Entries = make(map[string]struct{}) - e2Entries = make(map[string]struct{}) - ) - for _, e := range e1 { - e1Entries[e.Name()] = struct{}{} - } - for _, e := range e2 { - e2Entries[e.Name()] = struct{}{} - } - if !reflect.DeepEqual(e1Entries, e2Entries) { - return fmt.Errorf("entries differ") - } - return nil -} - -// ListTar lists the entries of a tar. -func ListTar(f io.Reader) ([]string, error) { - tr := tar.NewReader(f) - var entries []string - - for { - th, err := tr.Next() - if err == io.EOF { - // end of tar archive - return entries, nil - } - if err != nil { - return entries, err - } - entries = append(entries, th.Name) - } -} - -// RandomTmpDirPath provides a temporary path with rand string appended. -// does not create or checks if it exists. -func RandomTmpDirPath(s string, platform string) string { - tmp := "/tmp" - if platform == "windows" { - tmp = os.Getenv("TEMP") - } - path := filepath.Join(tmp, fmt.Sprintf("%s.%s", s, stringutils.GenerateRandomAlphaOnlyString(10))) - if platform == "windows" { - return filepath.FromSlash(path) // Using \ - } - return filepath.ToSlash(path) // Using / -} - -// ConsumeWithSpeed reads chunkSize bytes from reader before sleeping -// for interval duration. Returns total read bytes. Send true to the -// stop channel to return before reading to EOF on the reader. -func ConsumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) { - buffer := make([]byte, chunkSize) - for { - var readBytes int - readBytes, err = reader.Read(buffer) - n += readBytes - if err != nil { - if err == io.EOF { - err = nil - } - return - } - select { - case <-stop: - return - case <-time.After(interval): - } - } -} - -// ParseCgroupPaths parses 'procCgroupData', which is output of '/proc//cgroup', and returns -// a map which cgroup name as key and path as value. -func ParseCgroupPaths(procCgroupData string) map[string]string { - cgroupPaths := map[string]string{} - for _, line := range strings.Split(procCgroupData, "\n") { - parts := strings.Split(line, ":") - if len(parts) != 3 { - continue - } - cgroupPaths[parts[1]] = parts[2] - } - return cgroupPaths -} - -// ChannelBuffer holds a chan of byte array that can be populate in a goroutine. -type ChannelBuffer struct { - C chan []byte -} - -// Write implements Writer. -func (c *ChannelBuffer) Write(b []byte) (int, error) { - c.C <- b - return len(b), nil -} - -// Close closes the go channel. -func (c *ChannelBuffer) Close() error { - close(c.C) - return nil -} - -// ReadTimeout reads the content of the channel in the specified byte array with -// the specified duration as timeout. -func (c *ChannelBuffer) ReadTimeout(p []byte, n time.Duration) (int, error) { - select { - case b := <-c.C: - return copy(p[0:], b), nil - case <-time.After(n): - return -1, fmt.Errorf("timeout reading from channel") - } -} - -// RunAtDifferentDate runs the specified function with the given time. -// It changes the date of the system, which can led to weird behaviors. -func RunAtDifferentDate(date time.Time, block func()) { - // Layout for date. MMDDhhmmYYYY - const timeLayout = "010203042006" - // Ensure we bring time back to now - now := time.Now().Format(timeLayout) - defer icmd.RunCommand("date", now) - - icmd.RunCommand("date", date.Format(timeLayout)) - block() - return -} diff --git a/vendor/github.com/docker/docker/pkg/integration/utils_test.go b/vendor/github.com/docker/docker/pkg/integration/utils_test.go deleted file mode 100644 index 0b2ef4a..0000000 --- a/vendor/github.com/docker/docker/pkg/integration/utils_test.go +++ /dev/null @@ -1,363 +0,0 @@ -package integration - -import ( - "io" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "runtime" - "strings" - "testing" - "time" -) - -func TestIsKilledFalseWithNonKilledProcess(t *testing.T) { - var lsCmd *exec.Cmd - if runtime.GOOS != "windows" { - lsCmd = exec.Command("ls") - } else { - lsCmd = exec.Command("cmd", "/c", "dir") - } - - err := lsCmd.Run() - if IsKilled(err) { - t.Fatalf("Expected the ls command to not be killed, was.") - } -} - -func TestIsKilledTrueWithKilledProcess(t *testing.T) { - var longCmd *exec.Cmd - if runtime.GOOS != "windows" { - longCmd = exec.Command("top") - } else { - longCmd = exec.Command("powershell", "while ($true) { sleep 1 }") - } - - // Start a command - err := longCmd.Start() - if err != nil { - t.Fatal(err) - } - // Capture the error when *dying* - done := make(chan error, 1) - go func() { - done <- longCmd.Wait() - }() - // Then kill it - longCmd.Process.Kill() - // Get the error - err = <-done - if !IsKilled(err) { - t.Fatalf("Expected the command to be killed, was not.") - } -} - -func TestRunCommandPipelineWithOutputWithNotEnoughCmds(t *testing.T) { - _, _, err := RunCommandPipelineWithOutput(exec.Command("ls")) - expectedError := "pipeline does not have multiple cmds" - if err == nil || err.Error() != expectedError { - t.Fatalf("Expected an error with %s, got err:%s", expectedError, err) - } -} - -func TestRunCommandPipelineWithOutputErrors(t *testing.T) { - p := "$PATH" - if runtime.GOOS == "windows" { - p = "%PATH%" - } - cmd1 := exec.Command("ls") - cmd1.Stdout = os.Stdout - cmd2 := exec.Command("anything really") - _, _, err := RunCommandPipelineWithOutput(cmd1, cmd2) - if err == nil || err.Error() != "cannot set stdout pipe for anything really: exec: Stdout already set" { - t.Fatalf("Expected an error, got %v", err) - } - - cmdWithError := exec.Command("doesnotexists") - cmdCat := exec.Command("cat") - _, _, err = RunCommandPipelineWithOutput(cmdWithError, cmdCat) - if err == nil || err.Error() != `starting doesnotexists failed with error: exec: "doesnotexists": executable file not found in `+p { - t.Fatalf("Expected an error, got %v", err) - } -} - -func TestRunCommandPipelineWithOutput(t *testing.T) { - //TODO: Should run on Solaris - if runtime.GOOS == "solaris" { - t.Skip() - } - cmds := []*exec.Cmd{ - // Print 2 characters - exec.Command("echo", "-n", "11"), - // Count the number or char from stdin (previous command) - exec.Command("wc", "-m"), - } - out, exitCode, err := RunCommandPipelineWithOutput(cmds...) - expectedOutput := "2\n" - if out != expectedOutput || exitCode != 0 || err != nil { - t.Fatalf("Expected %s for commands %v, got out:%s, exitCode:%d, err:%v", expectedOutput, cmds, out, exitCode, err) - } -} - -func TestConvertSliceOfStringsToMap(t *testing.T) { - input := []string{"a", "b"} - actual := ConvertSliceOfStringsToMap(input) - for _, key := range input { - if _, ok := actual[key]; !ok { - t.Fatalf("Expected output to contains key %s, did not: %v", key, actual) - } - } -} - -func TestCompareDirectoryEntries(t *testing.T) { - tmpFolder, err := ioutil.TempDir("", "integration-cli-utils-compare-directories") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpFolder) - - file1 := filepath.Join(tmpFolder, "file1") - file2 := filepath.Join(tmpFolder, "file2") - os.Create(file1) - os.Create(file2) - - fi1, err := os.Stat(file1) - if err != nil { - t.Fatal(err) - } - fi1bis, err := os.Stat(file1) - if err != nil { - t.Fatal(err) - } - fi2, err := os.Stat(file2) - if err != nil { - t.Fatal(err) - } - - cases := []struct { - e1 []os.FileInfo - e2 []os.FileInfo - shouldError bool - }{ - // Empty directories - { - []os.FileInfo{}, - []os.FileInfo{}, - false, - }, - // Same FileInfos - { - []os.FileInfo{fi1}, - []os.FileInfo{fi1}, - false, - }, - // Different FileInfos but same names - { - []os.FileInfo{fi1}, - []os.FileInfo{fi1bis}, - false, - }, - // Different FileInfos, different names - { - []os.FileInfo{fi1}, - []os.FileInfo{fi2}, - true, - }, - } - for _, elt := range cases { - err := CompareDirectoryEntries(elt.e1, elt.e2) - if elt.shouldError && err == nil { - t.Fatalf("Should have return an error, did not with %v and %v", elt.e1, elt.e2) - } - if !elt.shouldError && err != nil { - t.Fatalf("Should have not returned an error, but did : %v with %v and %v", err, elt.e1, elt.e2) - } - } -} - -// FIXME make an "unhappy path" test for ListTar without "panicking" :-) -func TestListTar(t *testing.T) { - // TODO Windows: Figure out why this fails. Should be portable. - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows - needs further investigation") - } - tmpFolder, err := ioutil.TempDir("", "integration-cli-utils-list-tar") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpFolder) - - // Let's create a Tar file - srcFile := filepath.Join(tmpFolder, "src") - tarFile := filepath.Join(tmpFolder, "src.tar") - os.Create(srcFile) - cmd := exec.Command("sh", "-c", "tar cf "+tarFile+" "+srcFile) - _, err = cmd.CombinedOutput() - if err != nil { - t.Fatal(err) - } - - reader, err := os.Open(tarFile) - if err != nil { - t.Fatal(err) - } - defer reader.Close() - - entries, err := ListTar(reader) - if err != nil { - t.Fatal(err) - } - if len(entries) != 1 && entries[0] != "src" { - t.Fatalf("Expected a tar file with 1 entry (%s), got %v", srcFile, entries) - } -} - -func TestRandomTmpDirPath(t *testing.T) { - path := RandomTmpDirPath("something", runtime.GOOS) - - prefix := "/tmp/something" - if runtime.GOOS == "windows" { - prefix = os.Getenv("TEMP") + `\something` - } - expectedSize := len(prefix) + 11 - - if !strings.HasPrefix(path, prefix) { - t.Fatalf("Expected generated path to have '%s' as prefix, got %s'", prefix, path) - } - if len(path) != expectedSize { - t.Fatalf("Expected generated path to be %d, got %d", expectedSize, len(path)) - } -} - -func TestConsumeWithSpeed(t *testing.T) { - reader := strings.NewReader("1234567890") - chunksize := 2 - - bytes1, err := ConsumeWithSpeed(reader, chunksize, 1*time.Second, nil) - if err != nil { - t.Fatal(err) - } - - if bytes1 != 10 { - t.Fatalf("Expected to have read 10 bytes, got %d", bytes1) - } - -} - -func TestConsumeWithSpeedWithStop(t *testing.T) { - reader := strings.NewReader("1234567890") - chunksize := 2 - - stopIt := make(chan bool) - - go func() { - time.Sleep(1 * time.Millisecond) - stopIt <- true - }() - - bytes1, err := ConsumeWithSpeed(reader, chunksize, 20*time.Millisecond, stopIt) - if err != nil { - t.Fatal(err) - } - - if bytes1 != 2 { - t.Fatalf("Expected to have read 2 bytes, got %d", bytes1) - } - -} - -func TestParseCgroupPathsEmpty(t *testing.T) { - cgroupMap := ParseCgroupPaths("") - if len(cgroupMap) != 0 { - t.Fatalf("Expected an empty map, got %v", cgroupMap) - } - cgroupMap = ParseCgroupPaths("\n") - if len(cgroupMap) != 0 { - t.Fatalf("Expected an empty map, got %v", cgroupMap) - } - cgroupMap = ParseCgroupPaths("something:else\nagain:here") - if len(cgroupMap) != 0 { - t.Fatalf("Expected an empty map, got %v", cgroupMap) - } -} - -func TestParseCgroupPaths(t *testing.T) { - cgroupMap := ParseCgroupPaths("2:memory:/a\n1:cpuset:/b") - if len(cgroupMap) != 2 { - t.Fatalf("Expected a map with 2 entries, got %v", cgroupMap) - } - if value, ok := cgroupMap["memory"]; !ok || value != "/a" { - t.Fatalf("Expected cgroupMap to contains an entry for 'memory' with value '/a', got %v", cgroupMap) - } - if value, ok := cgroupMap["cpuset"]; !ok || value != "/b" { - t.Fatalf("Expected cgroupMap to contains an entry for 'cpuset' with value '/b', got %v", cgroupMap) - } -} - -func TestChannelBufferTimeout(t *testing.T) { - expected := "11" - - buf := &ChannelBuffer{make(chan []byte, 1)} - defer buf.Close() - - done := make(chan struct{}, 1) - go func() { - time.Sleep(100 * time.Millisecond) - io.Copy(buf, strings.NewReader(expected)) - done <- struct{}{} - }() - - // Wait long enough - b := make([]byte, 2) - _, err := buf.ReadTimeout(b, 50*time.Millisecond) - if err == nil && err.Error() != "timeout reading from channel" { - t.Fatalf("Expected an error, got %s", err) - } - <-done -} - -func TestChannelBuffer(t *testing.T) { - expected := "11" - - buf := &ChannelBuffer{make(chan []byte, 1)} - defer buf.Close() - - go func() { - time.Sleep(100 * time.Millisecond) - io.Copy(buf, strings.NewReader(expected)) - }() - - // Wait long enough - b := make([]byte, 2) - _, err := buf.ReadTimeout(b, 200*time.Millisecond) - if err != nil { - t.Fatal(err) - } - - if string(b) != expected { - t.Fatalf("Expected '%s', got '%s'", expected, string(b)) - } -} - -// FIXME doesn't work -// func TestRunAtDifferentDate(t *testing.T) { -// var date string - -// // Layout for date. MMDDhhmmYYYY -// const timeLayout = "20060102" -// expectedDate := "20100201" -// theDate, err := time.Parse(timeLayout, expectedDate) -// if err != nil { -// t.Fatal(err) -// } - -// RunAtDifferentDate(theDate, func() { -// cmd := exec.Command("date", "+%Y%M%d") -// out, err := cmd.Output() -// if err != nil { -// t.Fatal(err) -// } -// date = string(out) -// }) -// } diff --git a/vendor/github.com/docker/docker/pkg/ioutils/buffer.go b/vendor/github.com/docker/docker/pkg/ioutils/buffer.go deleted file mode 100644 index 3d737b3..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/buffer.go +++ /dev/null @@ -1,51 +0,0 @@ -package ioutils - -import ( - "errors" - "io" -) - -var errBufferFull = errors.New("buffer is full") - -type fixedBuffer struct { - buf []byte - pos int - lastRead int -} - -func (b *fixedBuffer) Write(p []byte) (int, error) { - n := copy(b.buf[b.pos:cap(b.buf)], p) - b.pos += n - - if n < len(p) { - if b.pos == cap(b.buf) { - return n, errBufferFull - } - return n, io.ErrShortWrite - } - return n, nil -} - -func (b *fixedBuffer) Read(p []byte) (int, error) { - n := copy(p, b.buf[b.lastRead:b.pos]) - b.lastRead += n - return n, nil -} - -func (b *fixedBuffer) Len() int { - return b.pos - b.lastRead -} - -func (b *fixedBuffer) Cap() int { - return cap(b.buf) -} - -func (b *fixedBuffer) Reset() { - b.pos = 0 - b.lastRead = 0 - b.buf = b.buf[:0] -} - -func (b *fixedBuffer) String() string { - return string(b.buf[b.lastRead:b.pos]) -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/buffer_test.go b/vendor/github.com/docker/docker/pkg/ioutils/buffer_test.go deleted file mode 100644 index 41098fa..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/buffer_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package ioutils - -import ( - "bytes" - "testing" -) - -func TestFixedBufferWrite(t *testing.T) { - buf := &fixedBuffer{buf: make([]byte, 0, 64)} - n, err := buf.Write([]byte("hello")) - if err != nil { - t.Fatal(err) - } - - if n != 5 { - t.Fatalf("expected 5 bytes written, got %d", n) - } - - if string(buf.buf[:5]) != "hello" { - t.Fatalf("expected \"hello\", got %q", string(buf.buf[:5])) - } - - n, err = buf.Write(bytes.Repeat([]byte{1}, 64)) - if err != errBufferFull { - t.Fatalf("expected errBufferFull, got %v - %v", err, buf.buf[:64]) - } -} - -func TestFixedBufferRead(t *testing.T) { - buf := &fixedBuffer{buf: make([]byte, 0, 64)} - if _, err := buf.Write([]byte("hello world")); err != nil { - t.Fatal(err) - } - - b := make([]byte, 5) - n, err := buf.Read(b) - if err != nil { - t.Fatal(err) - } - - if n != 5 { - t.Fatalf("expected 5 bytes read, got %d - %s", n, buf.String()) - } - - if string(b) != "hello" { - t.Fatalf("expected \"hello\", got %q", string(b)) - } - - n, err = buf.Read(b) - if err != nil { - t.Fatal(err) - } - - if n != 5 { - t.Fatalf("expected 5 bytes read, got %d", n) - } - - if string(b) != " worl" { - t.Fatalf("expected \" worl\", got %s", string(b)) - } - - b = b[:1] - n, err = buf.Read(b) - if err != nil { - t.Fatal(err) - } - - if n != 1 { - t.Fatalf("expected 1 byte read, got %d - %s", n, buf.String()) - } - - if string(b) != "d" { - t.Fatalf("expected \"d\", got %s", string(b)) - } -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/bytespipe.go b/vendor/github.com/docker/docker/pkg/ioutils/bytespipe.go deleted file mode 100644 index 72a04f3..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/bytespipe.go +++ /dev/null @@ -1,186 +0,0 @@ -package ioutils - -import ( - "errors" - "io" - "sync" -) - -// maxCap is the highest capacity to use in byte slices that buffer data. -const maxCap = 1e6 - -// minCap is the lowest capacity to use in byte slices that buffer data -const minCap = 64 - -// blockThreshold is the minimum number of bytes in the buffer which will cause -// a write to BytesPipe to block when allocating a new slice. -const blockThreshold = 1e6 - -var ( - // ErrClosed is returned when Write is called on a closed BytesPipe. - ErrClosed = errors.New("write to closed BytesPipe") - - bufPools = make(map[int]*sync.Pool) - bufPoolsLock sync.Mutex -) - -// BytesPipe is io.ReadWriteCloser which works similarly to pipe(queue). -// All written data may be read at most once. Also, BytesPipe allocates -// and releases new byte slices to adjust to current needs, so the buffer -// won't be overgrown after peak loads. -type BytesPipe struct { - mu sync.Mutex - wait *sync.Cond - buf []*fixedBuffer - bufLen int - closeErr error // error to return from next Read. set to nil if not closed. -} - -// NewBytesPipe creates new BytesPipe, initialized by specified slice. -// If buf is nil, then it will be initialized with slice which cap is 64. -// buf will be adjusted in a way that len(buf) == 0, cap(buf) == cap(buf). -func NewBytesPipe() *BytesPipe { - bp := &BytesPipe{} - bp.buf = append(bp.buf, getBuffer(minCap)) - bp.wait = sync.NewCond(&bp.mu) - return bp -} - -// Write writes p to BytesPipe. -// It can allocate new []byte slices in a process of writing. -func (bp *BytesPipe) Write(p []byte) (int, error) { - bp.mu.Lock() - - written := 0 -loop0: - for { - if bp.closeErr != nil { - bp.mu.Unlock() - return written, ErrClosed - } - - if len(bp.buf) == 0 { - bp.buf = append(bp.buf, getBuffer(64)) - } - // get the last buffer - b := bp.buf[len(bp.buf)-1] - - n, err := b.Write(p) - written += n - bp.bufLen += n - - // errBufferFull is an error we expect to get if the buffer is full - if err != nil && err != errBufferFull { - bp.wait.Broadcast() - bp.mu.Unlock() - return written, err - } - - // if there was enough room to write all then break - if len(p) == n { - break - } - - // more data: write to the next slice - p = p[n:] - - // make sure the buffer doesn't grow too big from this write - for bp.bufLen >= blockThreshold { - bp.wait.Wait() - if bp.closeErr != nil { - continue loop0 - } - } - - // add new byte slice to the buffers slice and continue writing - nextCap := b.Cap() * 2 - if nextCap > maxCap { - nextCap = maxCap - } - bp.buf = append(bp.buf, getBuffer(nextCap)) - } - bp.wait.Broadcast() - bp.mu.Unlock() - return written, nil -} - -// CloseWithError causes further reads from a BytesPipe to return immediately. -func (bp *BytesPipe) CloseWithError(err error) error { - bp.mu.Lock() - if err != nil { - bp.closeErr = err - } else { - bp.closeErr = io.EOF - } - bp.wait.Broadcast() - bp.mu.Unlock() - return nil -} - -// Close causes further reads from a BytesPipe to return immediately. -func (bp *BytesPipe) Close() error { - return bp.CloseWithError(nil) -} - -// Read reads bytes from BytesPipe. -// Data could be read only once. -func (bp *BytesPipe) Read(p []byte) (n int, err error) { - bp.mu.Lock() - if bp.bufLen == 0 { - if bp.closeErr != nil { - bp.mu.Unlock() - return 0, bp.closeErr - } - bp.wait.Wait() - if bp.bufLen == 0 && bp.closeErr != nil { - err := bp.closeErr - bp.mu.Unlock() - return 0, err - } - } - - for bp.bufLen > 0 { - b := bp.buf[0] - read, _ := b.Read(p) // ignore error since fixedBuffer doesn't really return an error - n += read - bp.bufLen -= read - - if b.Len() == 0 { - // it's empty so return it to the pool and move to the next one - returnBuffer(b) - bp.buf[0] = nil - bp.buf = bp.buf[1:] - } - - if len(p) == read { - break - } - - p = p[read:] - } - - bp.wait.Broadcast() - bp.mu.Unlock() - return -} - -func returnBuffer(b *fixedBuffer) { - b.Reset() - bufPoolsLock.Lock() - pool := bufPools[b.Cap()] - bufPoolsLock.Unlock() - if pool != nil { - pool.Put(b) - } -} - -func getBuffer(size int) *fixedBuffer { - bufPoolsLock.Lock() - pool, ok := bufPools[size] - if !ok { - pool = &sync.Pool{New: func() interface{} { return &fixedBuffer{buf: make([]byte, 0, size)} }} - bufPools[size] = pool - } - bufPoolsLock.Unlock() - return pool.Get().(*fixedBuffer) -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/bytespipe_test.go b/vendor/github.com/docker/docker/pkg/ioutils/bytespipe_test.go deleted file mode 100644 index 300fb5f..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/bytespipe_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package ioutils - -import ( - "crypto/sha1" - "encoding/hex" - "math/rand" - "testing" - "time" -) - -func TestBytesPipeRead(t *testing.T) { - buf := NewBytesPipe() - buf.Write([]byte("12")) - buf.Write([]byte("34")) - buf.Write([]byte("56")) - buf.Write([]byte("78")) - buf.Write([]byte("90")) - rd := make([]byte, 4) - n, err := buf.Read(rd) - if err != nil { - t.Fatal(err) - } - if n != 4 { - t.Fatalf("Wrong number of bytes read: %d, should be %d", n, 4) - } - if string(rd) != "1234" { - t.Fatalf("Read %s, but must be %s", rd, "1234") - } - n, err = buf.Read(rd) - if err != nil { - t.Fatal(err) - } - if n != 4 { - t.Fatalf("Wrong number of bytes read: %d, should be %d", n, 4) - } - if string(rd) != "5678" { - t.Fatalf("Read %s, but must be %s", rd, "5679") - } - n, err = buf.Read(rd) - if err != nil { - t.Fatal(err) - } - if n != 2 { - t.Fatalf("Wrong number of bytes read: %d, should be %d", n, 2) - } - if string(rd[:n]) != "90" { - t.Fatalf("Read %s, but must be %s", rd, "90") - } -} - -func TestBytesPipeWrite(t *testing.T) { - buf := NewBytesPipe() - buf.Write([]byte("12")) - buf.Write([]byte("34")) - buf.Write([]byte("56")) - buf.Write([]byte("78")) - buf.Write([]byte("90")) - if buf.buf[0].String() != "1234567890" { - t.Fatalf("Buffer %q, must be %q", buf.buf[0].String(), "1234567890") - } -} - -// Write and read in different speeds/chunk sizes and check valid data is read. -func TestBytesPipeWriteRandomChunks(t *testing.T) { - cases := []struct{ iterations, writesPerLoop, readsPerLoop int }{ - {100, 10, 1}, - {1000, 10, 5}, - {1000, 100, 0}, - {1000, 5, 6}, - {10000, 50, 25}, - } - - testMessage := []byte("this is a random string for testing") - // random slice sizes to read and write - writeChunks := []int{25, 35, 15, 20} - readChunks := []int{5, 45, 20, 25} - - for _, c := range cases { - // first pass: write directly to hash - hash := sha1.New() - for i := 0; i < c.iterations*c.writesPerLoop; i++ { - if _, err := hash.Write(testMessage[:writeChunks[i%len(writeChunks)]]); err != nil { - t.Fatal(err) - } - } - expected := hex.EncodeToString(hash.Sum(nil)) - - // write/read through buffer - buf := NewBytesPipe() - hash.Reset() - - done := make(chan struct{}) - - go func() { - // random delay before read starts - <-time.After(time.Duration(rand.Intn(10)) * time.Millisecond) - for i := 0; ; i++ { - p := make([]byte, readChunks[(c.iterations*c.readsPerLoop+i)%len(readChunks)]) - n, _ := buf.Read(p) - if n == 0 { - break - } - hash.Write(p[:n]) - } - - close(done) - }() - - for i := 0; i < c.iterations; i++ { - for w := 0; w < c.writesPerLoop; w++ { - buf.Write(testMessage[:writeChunks[(i*c.writesPerLoop+w)%len(writeChunks)]]) - } - } - buf.Close() - <-done - - actual := hex.EncodeToString(hash.Sum(nil)) - - if expected != actual { - t.Fatalf("BytesPipe returned invalid data. Expected checksum %v, got %v", expected, actual) - } - - } -} - -func BenchmarkBytesPipeWrite(b *testing.B) { - testData := []byte("pretty short line, because why not?") - for i := 0; i < b.N; i++ { - readBuf := make([]byte, 1024) - buf := NewBytesPipe() - go func() { - var err error - for err == nil { - _, err = buf.Read(readBuf) - } - }() - for j := 0; j < 1000; j++ { - buf.Write(testData) - } - buf.Close() - } -} - -func BenchmarkBytesPipeRead(b *testing.B) { - rd := make([]byte, 512) - for i := 0; i < b.N; i++ { - b.StopTimer() - buf := NewBytesPipe() - for j := 0; j < 500; j++ { - buf.Write(make([]byte, 1024)) - } - b.StartTimer() - for j := 0; j < 1000; j++ { - if n, _ := buf.Read(rd); n != 512 { - b.Fatalf("Wrong number of bytes: %d", n) - } - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/fmt.go b/vendor/github.com/docker/docker/pkg/ioutils/fmt.go deleted file mode 100644 index 0b04b0b..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/fmt.go +++ /dev/null @@ -1,22 +0,0 @@ -package ioutils - -import ( - "fmt" - "io" -) - -// FprintfIfNotEmpty prints the string value if it's not empty -func FprintfIfNotEmpty(w io.Writer, format, value string) (int, error) { - if value != "" { - return fmt.Fprintf(w, format, value) - } - return 0, nil -} - -// FprintfIfTrue prints the boolean value if it's true -func FprintfIfTrue(w io.Writer, format string, ok bool) (int, error) { - if ok { - return fmt.Fprintf(w, format, ok) - } - return 0, nil -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/fmt_test.go b/vendor/github.com/docker/docker/pkg/ioutils/fmt_test.go deleted file mode 100644 index 8968863..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/fmt_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package ioutils - -import "testing" - -func TestFprintfIfNotEmpty(t *testing.T) { - wc := NewWriteCounter(&NopWriter{}) - n, _ := FprintfIfNotEmpty(wc, "foo%s", "") - - if wc.Count != 0 || n != 0 { - t.Errorf("Wrong count: %v vs. %v vs. 0", wc.Count, n) - } - - n, _ = FprintfIfNotEmpty(wc, "foo%s", "bar") - if wc.Count != 6 || n != 6 { - t.Errorf("Wrong count: %v vs. %v vs. 6", wc.Count, n) - } -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/fswriters.go b/vendor/github.com/docker/docker/pkg/ioutils/fswriters.go deleted file mode 100644 index a56c462..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/fswriters.go +++ /dev/null @@ -1,162 +0,0 @@ -package ioutils - -import ( - "io" - "io/ioutil" - "os" - "path/filepath" -) - -// NewAtomicFileWriter returns WriteCloser so that writing to it writes to a -// temporary file and closing it atomically changes the temporary file to -// destination path. Writing and closing concurrently is not allowed. -func NewAtomicFileWriter(filename string, perm os.FileMode) (io.WriteCloser, error) { - f, err := ioutil.TempFile(filepath.Dir(filename), ".tmp-"+filepath.Base(filename)) - if err != nil { - return nil, err - } - - abspath, err := filepath.Abs(filename) - if err != nil { - return nil, err - } - return &atomicFileWriter{ - f: f, - fn: abspath, - perm: perm, - }, nil -} - -// AtomicWriteFile atomically writes data to a file named by filename. -func AtomicWriteFile(filename string, data []byte, perm os.FileMode) error { - f, err := NewAtomicFileWriter(filename, perm) - if err != nil { - return err - } - n, err := f.Write(data) - if err == nil && n < len(data) { - err = io.ErrShortWrite - f.(*atomicFileWriter).writeErr = err - } - if err1 := f.Close(); err == nil { - err = err1 - } - return err -} - -type atomicFileWriter struct { - f *os.File - fn string - writeErr error - perm os.FileMode -} - -func (w *atomicFileWriter) Write(dt []byte) (int, error) { - n, err := w.f.Write(dt) - if err != nil { - w.writeErr = err - } - return n, err -} - -func (w *atomicFileWriter) Close() (retErr error) { - defer func() { - if retErr != nil || w.writeErr != nil { - os.Remove(w.f.Name()) - } - }() - if err := w.f.Sync(); err != nil { - w.f.Close() - return err - } - if err := w.f.Close(); err != nil { - return err - } - if err := os.Chmod(w.f.Name(), w.perm); err != nil { - return err - } - if w.writeErr == nil { - return os.Rename(w.f.Name(), w.fn) - } - return nil -} - -// AtomicWriteSet is used to atomically write a set -// of files and ensure they are visible at the same time. -// Must be committed to a new directory. -type AtomicWriteSet struct { - root string -} - -// NewAtomicWriteSet creates a new atomic write set to -// atomically create a set of files. The given directory -// is used as the base directory for storing files before -// commit. If no temporary directory is given the system -// default is used. -func NewAtomicWriteSet(tmpDir string) (*AtomicWriteSet, error) { - td, err := ioutil.TempDir(tmpDir, "write-set-") - if err != nil { - return nil, err - } - - return &AtomicWriteSet{ - root: td, - }, nil -} - -// WriteFile writes a file to the set, guaranteeing the file -// has been synced. -func (ws *AtomicWriteSet) WriteFile(filename string, data []byte, perm os.FileMode) error { - f, err := ws.FileWriter(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm) - if err != nil { - return err - } - n, err := f.Write(data) - if err == nil && n < len(data) { - err = io.ErrShortWrite - } - if err1 := f.Close(); err == nil { - err = err1 - } - return err -} - -type syncFileCloser struct { - *os.File -} - -func (w syncFileCloser) Close() error { - err := w.File.Sync() - if err1 := w.File.Close(); err == nil { - err = err1 - } - return err -} - -// FileWriter opens a file writer inside the set. The file -// should be synced and closed before calling commit. -func (ws *AtomicWriteSet) FileWriter(name string, flag int, perm os.FileMode) (io.WriteCloser, error) { - f, err := os.OpenFile(filepath.Join(ws.root, name), flag, perm) - if err != nil { - return nil, err - } - return syncFileCloser{f}, nil -} - -// Cancel cancels the set and removes all temporary data -// created in the set. -func (ws *AtomicWriteSet) Cancel() error { - return os.RemoveAll(ws.root) -} - -// Commit moves all created files to the target directory. The -// target directory must not exist and the parent of the target -// directory must exist. -func (ws *AtomicWriteSet) Commit(target string) error { - return os.Rename(ws.root, target) -} - -// String returns the location the set is writing to. -func (ws *AtomicWriteSet) String() string { - return ws.root -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/fswriters_test.go b/vendor/github.com/docker/docker/pkg/ioutils/fswriters_test.go deleted file mode 100644 index c4d1419..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/fswriters_test.go +++ /dev/null @@ -1,132 +0,0 @@ -package ioutils - -import ( - "bytes" - "io/ioutil" - "os" - "path/filepath" - "runtime" - "testing" -) - -var ( - testMode os.FileMode = 0640 -) - -func init() { - // Windows does not support full Linux file mode - if runtime.GOOS == "windows" { - testMode = 0666 - } -} - -func TestAtomicWriteToFile(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "atomic-writers-test") - if err != nil { - t.Fatalf("Error when creating temporary directory: %s", err) - } - defer os.RemoveAll(tmpDir) - - expected := []byte("barbaz") - if err := AtomicWriteFile(filepath.Join(tmpDir, "foo"), expected, testMode); err != nil { - t.Fatalf("Error writing to file: %v", err) - } - - actual, err := ioutil.ReadFile(filepath.Join(tmpDir, "foo")) - if err != nil { - t.Fatalf("Error reading from file: %v", err) - } - - if bytes.Compare(actual, expected) != 0 { - t.Fatalf("Data mismatch, expected %q, got %q", expected, actual) - } - - st, err := os.Stat(filepath.Join(tmpDir, "foo")) - if err != nil { - t.Fatalf("Error statting file: %v", err) - } - if expected := os.FileMode(testMode); st.Mode() != expected { - t.Fatalf("Mode mismatched, expected %o, got %o", expected, st.Mode()) - } -} - -func TestAtomicWriteSetCommit(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "atomic-writerset-test") - if err != nil { - t.Fatalf("Error when creating temporary directory: %s", err) - } - defer os.RemoveAll(tmpDir) - - if err := os.Mkdir(filepath.Join(tmpDir, "tmp"), 0700); err != nil { - t.Fatalf("Error creating tmp directory: %s", err) - } - - targetDir := filepath.Join(tmpDir, "target") - ws, err := NewAtomicWriteSet(filepath.Join(tmpDir, "tmp")) - if err != nil { - t.Fatalf("Error creating atomic write set: %s", err) - } - - expected := []byte("barbaz") - if err := ws.WriteFile("foo", expected, testMode); err != nil { - t.Fatalf("Error writing to file: %v", err) - } - - if _, err := ioutil.ReadFile(filepath.Join(targetDir, "foo")); err == nil { - t.Fatalf("Expected error reading file where should not exist") - } - - if err := ws.Commit(targetDir); err != nil { - t.Fatalf("Error committing file: %s", err) - } - - actual, err := ioutil.ReadFile(filepath.Join(targetDir, "foo")) - if err != nil { - t.Fatalf("Error reading from file: %v", err) - } - - if bytes.Compare(actual, expected) != 0 { - t.Fatalf("Data mismatch, expected %q, got %q", expected, actual) - } - - st, err := os.Stat(filepath.Join(targetDir, "foo")) - if err != nil { - t.Fatalf("Error statting file: %v", err) - } - if expected := os.FileMode(testMode); st.Mode() != expected { - t.Fatalf("Mode mismatched, expected %o, got %o", expected, st.Mode()) - } - -} - -func TestAtomicWriteSetCancel(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "atomic-writerset-test") - if err != nil { - t.Fatalf("Error when creating temporary directory: %s", err) - } - defer os.RemoveAll(tmpDir) - - if err := os.Mkdir(filepath.Join(tmpDir, "tmp"), 0700); err != nil { - t.Fatalf("Error creating tmp directory: %s", err) - } - - ws, err := NewAtomicWriteSet(filepath.Join(tmpDir, "tmp")) - if err != nil { - t.Fatalf("Error creating atomic write set: %s", err) - } - - expected := []byte("barbaz") - if err := ws.WriteFile("foo", expected, testMode); err != nil { - t.Fatalf("Error writing to file: %v", err) - } - - if err := ws.Cancel(); err != nil { - t.Fatalf("Error committing file: %s", err) - } - - if _, err := ioutil.ReadFile(filepath.Join(tmpDir, "target", "foo")); err == nil { - t.Fatalf("Expected error reading file where should not exist") - } else if !os.IsNotExist(err) { - t.Fatalf("Unexpected error reading file: %s", err) - } -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/multireader.go b/vendor/github.com/docker/docker/pkg/ioutils/multireader.go deleted file mode 100644 index d7b9748..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/multireader.go +++ /dev/null @@ -1,223 +0,0 @@ -package ioutils - -import ( - "bytes" - "fmt" - "io" - "os" -) - -type pos struct { - idx int - offset int64 -} - -type multiReadSeeker struct { - readers []io.ReadSeeker - pos *pos - posIdx map[io.ReadSeeker]int -} - -func (r *multiReadSeeker) Seek(offset int64, whence int) (int64, error) { - var tmpOffset int64 - switch whence { - case os.SEEK_SET: - for i, rdr := range r.readers { - // get size of the current reader - s, err := rdr.Seek(0, os.SEEK_END) - if err != nil { - return -1, err - } - - if offset > tmpOffset+s { - if i == len(r.readers)-1 { - rdrOffset := s + (offset - tmpOffset) - if _, err := rdr.Seek(rdrOffset, os.SEEK_SET); err != nil { - return -1, err - } - r.pos = &pos{i, rdrOffset} - return offset, nil - } - - tmpOffset += s - continue - } - - rdrOffset := offset - tmpOffset - idx := i - - rdr.Seek(rdrOffset, os.SEEK_SET) - // make sure all following readers are at 0 - for _, rdr := range r.readers[i+1:] { - rdr.Seek(0, os.SEEK_SET) - } - - if rdrOffset == s && i != len(r.readers)-1 { - idx++ - rdrOffset = 0 - } - r.pos = &pos{idx, rdrOffset} - return offset, nil - } - case os.SEEK_END: - for _, rdr := range r.readers { - s, err := rdr.Seek(0, os.SEEK_END) - if err != nil { - return -1, err - } - tmpOffset += s - } - r.Seek(tmpOffset+offset, os.SEEK_SET) - return tmpOffset + offset, nil - case os.SEEK_CUR: - if r.pos == nil { - return r.Seek(offset, os.SEEK_SET) - } - // Just return the current offset - if offset == 0 { - return r.getCurOffset() - } - - curOffset, err := r.getCurOffset() - if err != nil { - return -1, err - } - rdr, rdrOffset, err := r.getReaderForOffset(curOffset + offset) - if err != nil { - return -1, err - } - - r.pos = &pos{r.posIdx[rdr], rdrOffset} - return curOffset + offset, nil - default: - return -1, fmt.Errorf("Invalid whence: %d", whence) - } - - return -1, fmt.Errorf("Error seeking for whence: %d, offset: %d", whence, offset) -} - -func (r *multiReadSeeker) getReaderForOffset(offset int64) (io.ReadSeeker, int64, error) { - - var offsetTo int64 - - for _, rdr := range r.readers { - size, err := getReadSeekerSize(rdr) - if err != nil { - return nil, -1, err - } - if offsetTo+size > offset { - return rdr, offset - offsetTo, nil - } - if rdr == r.readers[len(r.readers)-1] { - return rdr, offsetTo + offset, nil - } - offsetTo += size - } - - return nil, 0, nil -} - -func (r *multiReadSeeker) getCurOffset() (int64, error) { - var totalSize int64 - for _, rdr := range r.readers[:r.pos.idx+1] { - if r.posIdx[rdr] == r.pos.idx { - totalSize += r.pos.offset - break - } - - size, err := getReadSeekerSize(rdr) - if err != nil { - return -1, fmt.Errorf("error getting seeker size: %v", err) - } - totalSize += size - } - return totalSize, nil -} - -func (r *multiReadSeeker) getOffsetToReader(rdr io.ReadSeeker) (int64, error) { - var offset int64 - for _, r := range r.readers { - if r == rdr { - break - } - - size, err := getReadSeekerSize(rdr) - if err != nil { - return -1, err - } - offset += size - } - return offset, nil -} - -func (r *multiReadSeeker) Read(b []byte) (int, error) { - if r.pos == nil { - r.pos = &pos{0, 0} - } - - bLen := int64(len(b)) - buf := bytes.NewBuffer(nil) - var rdr io.ReadSeeker - - for _, rdr = range r.readers[r.pos.idx:] { - readBytes, err := io.CopyN(buf, rdr, bLen) - if err != nil && err != io.EOF { - return -1, err - } - bLen -= readBytes - - if bLen == 0 { - break - } - } - - rdrPos, err := rdr.Seek(0, os.SEEK_CUR) - if err != nil { - return -1, err - } - r.pos = &pos{r.posIdx[rdr], rdrPos} - return buf.Read(b) -} - -func getReadSeekerSize(rdr io.ReadSeeker) (int64, error) { - // save the current position - pos, err := rdr.Seek(0, os.SEEK_CUR) - if err != nil { - return -1, err - } - - // get the size - size, err := rdr.Seek(0, os.SEEK_END) - if err != nil { - return -1, err - } - - // reset the position - if _, err := rdr.Seek(pos, os.SEEK_SET); err != nil { - return -1, err - } - return size, nil -} - -// MultiReadSeeker returns a ReadSeeker that's the logical concatenation of the provided -// input readseekers. After calling this method the initial position is set to the -// beginning of the first ReadSeeker. At the end of a ReadSeeker, Read always advances -// to the beginning of the next ReadSeeker and returns EOF at the end of the last ReadSeeker. -// Seek can be used over the sum of lengths of all readseekers. -// -// When a MultiReadSeeker is used, no Read and Seek operations should be made on -// its ReadSeeker components. Also, users should make no assumption on the state -// of individual readseekers while the MultiReadSeeker is used. -func MultiReadSeeker(readers ...io.ReadSeeker) io.ReadSeeker { - if len(readers) == 1 { - return readers[0] - } - idx := make(map[io.ReadSeeker]int) - for i, rdr := range readers { - idx[rdr] = i - } - return &multiReadSeeker{ - readers: readers, - posIdx: idx, - } -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/multireader_test.go b/vendor/github.com/docker/docker/pkg/ioutils/multireader_test.go deleted file mode 100644 index 65309a9..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/multireader_test.go +++ /dev/null @@ -1,211 +0,0 @@ -package ioutils - -import ( - "bytes" - "encoding/binary" - "fmt" - "io" - "io/ioutil" - "os" - "strings" - "testing" -) - -func TestMultiReadSeekerReadAll(t *testing.T) { - str := "hello world" - s1 := strings.NewReader(str + " 1") - s2 := strings.NewReader(str + " 2") - s3 := strings.NewReader(str + " 3") - mr := MultiReadSeeker(s1, s2, s3) - - expectedSize := int64(s1.Len() + s2.Len() + s3.Len()) - - b, err := ioutil.ReadAll(mr) - if err != nil { - t.Fatal(err) - } - - expected := "hello world 1hello world 2hello world 3" - if string(b) != expected { - t.Fatalf("ReadAll failed, got: %q, expected %q", string(b), expected) - } - - size, err := mr.Seek(0, os.SEEK_END) - if err != nil { - t.Fatal(err) - } - if size != expectedSize { - t.Fatalf("reader size does not match, got %d, expected %d", size, expectedSize) - } - - // Reset the position and read again - pos, err := mr.Seek(0, os.SEEK_SET) - if err != nil { - t.Fatal(err) - } - if pos != 0 { - t.Fatalf("expected position to be set to 0, got %d", pos) - } - - b, err = ioutil.ReadAll(mr) - if err != nil { - t.Fatal(err) - } - - if string(b) != expected { - t.Fatalf("ReadAll failed, got: %q, expected %q", string(b), expected) - } -} - -func TestMultiReadSeekerReadEach(t *testing.T) { - str := "hello world" - s1 := strings.NewReader(str + " 1") - s2 := strings.NewReader(str + " 2") - s3 := strings.NewReader(str + " 3") - mr := MultiReadSeeker(s1, s2, s3) - - var totalBytes int64 - for i, s := range []*strings.Reader{s1, s2, s3} { - sLen := int64(s.Len()) - buf := make([]byte, s.Len()) - expected := []byte(fmt.Sprintf("%s %d", str, i+1)) - - if _, err := mr.Read(buf); err != nil && err != io.EOF { - t.Fatal(err) - } - - if !bytes.Equal(buf, expected) { - t.Fatalf("expected %q to be %q", string(buf), string(expected)) - } - - pos, err := mr.Seek(0, os.SEEK_CUR) - if err != nil { - t.Fatalf("iteration: %d, error: %v", i+1, err) - } - - // check that the total bytes read is the current position of the seeker - totalBytes += sLen - if pos != totalBytes { - t.Fatalf("expected current position to be: %d, got: %d, iteration: %d", totalBytes, pos, i+1) - } - - // This tests not only that SEEK_SET and SEEK_CUR give the same values, but that the next iteration is in the expected position as well - newPos, err := mr.Seek(pos, os.SEEK_SET) - if err != nil { - t.Fatal(err) - } - if newPos != pos { - t.Fatalf("expected to get same position when calling SEEK_SET with value from SEEK_CUR, cur: %d, set: %d", pos, newPos) - } - } -} - -func TestMultiReadSeekerReadSpanningChunks(t *testing.T) { - str := "hello world" - s1 := strings.NewReader(str + " 1") - s2 := strings.NewReader(str + " 2") - s3 := strings.NewReader(str + " 3") - mr := MultiReadSeeker(s1, s2, s3) - - buf := make([]byte, s1.Len()+3) - _, err := mr.Read(buf) - if err != nil { - t.Fatal(err) - } - - // expected is the contents of s1 + 3 bytes from s2, ie, the `hel` at the end of this string - expected := "hello world 1hel" - if string(buf) != expected { - t.Fatalf("expected %s to be %s", string(buf), expected) - } -} - -func TestMultiReadSeekerNegativeSeek(t *testing.T) { - str := "hello world" - s1 := strings.NewReader(str + " 1") - s2 := strings.NewReader(str + " 2") - s3 := strings.NewReader(str + " 3") - mr := MultiReadSeeker(s1, s2, s3) - - s1Len := s1.Len() - s2Len := s2.Len() - s3Len := s3.Len() - - s, err := mr.Seek(int64(-1*s3.Len()), os.SEEK_END) - if err != nil { - t.Fatal(err) - } - if s != int64(s1Len+s2Len) { - t.Fatalf("expected %d to be %d", s, s1.Len()+s2.Len()) - } - - buf := make([]byte, s3Len) - if _, err := mr.Read(buf); err != nil && err != io.EOF { - t.Fatal(err) - } - expected := fmt.Sprintf("%s %d", str, 3) - if string(buf) != fmt.Sprintf("%s %d", str, 3) { - t.Fatalf("expected %q to be %q", string(buf), expected) - } -} - -func TestMultiReadSeekerCurAfterSet(t *testing.T) { - str := "hello world" - s1 := strings.NewReader(str + " 1") - s2 := strings.NewReader(str + " 2") - s3 := strings.NewReader(str + " 3") - mr := MultiReadSeeker(s1, s2, s3) - - mid := int64(s1.Len() + s2.Len()/2) - - size, err := mr.Seek(mid, os.SEEK_SET) - if err != nil { - t.Fatal(err) - } - if size != mid { - t.Fatalf("reader size does not match, got %d, expected %d", size, mid) - } - - size, err = mr.Seek(3, os.SEEK_CUR) - if err != nil { - t.Fatal(err) - } - if size != mid+3 { - t.Fatalf("reader size does not match, got %d, expected %d", size, mid+3) - } - size, err = mr.Seek(5, os.SEEK_CUR) - if err != nil { - t.Fatal(err) - } - if size != mid+8 { - t.Fatalf("reader size does not match, got %d, expected %d", size, mid+8) - } - - size, err = mr.Seek(10, os.SEEK_CUR) - if err != nil { - t.Fatal(err) - } - if size != mid+18 { - t.Fatalf("reader size does not match, got %d, expected %d", size, mid+18) - } -} - -func TestMultiReadSeekerSmallReads(t *testing.T) { - readers := []io.ReadSeeker{} - for i := 0; i < 10; i++ { - integer := make([]byte, 4, 4) - binary.BigEndian.PutUint32(integer, uint32(i)) - readers = append(readers, bytes.NewReader(integer)) - } - - reader := MultiReadSeeker(readers...) - for i := 0; i < 10; i++ { - var integer uint32 - if err := binary.Read(reader, binary.BigEndian, &integer); err != nil { - t.Fatalf("Read from NewMultiReadSeeker failed: %v", err) - } - if uint32(i) != integer { - t.Fatalf("Read wrong value from NewMultiReadSeeker: %d != %d", i, integer) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/readers.go b/vendor/github.com/docker/docker/pkg/ioutils/readers.go deleted file mode 100644 index 63f3c07..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/readers.go +++ /dev/null @@ -1,154 +0,0 @@ -package ioutils - -import ( - "crypto/sha256" - "encoding/hex" - "io" - - "golang.org/x/net/context" -) - -type readCloserWrapper struct { - io.Reader - closer func() error -} - -func (r *readCloserWrapper) Close() error { - return r.closer() -} - -// NewReadCloserWrapper returns a new io.ReadCloser. -func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser { - return &readCloserWrapper{ - Reader: r, - closer: closer, - } -} - -type readerErrWrapper struct { - reader io.Reader - closer func() -} - -func (r *readerErrWrapper) Read(p []byte) (int, error) { - n, err := r.reader.Read(p) - if err != nil { - r.closer() - } - return n, err -} - -// NewReaderErrWrapper returns a new io.Reader. -func NewReaderErrWrapper(r io.Reader, closer func()) io.Reader { - return &readerErrWrapper{ - reader: r, - closer: closer, - } -} - -// HashData returns the sha256 sum of src. -func HashData(src io.Reader) (string, error) { - h := sha256.New() - if _, err := io.Copy(h, src); err != nil { - return "", err - } - return "sha256:" + hex.EncodeToString(h.Sum(nil)), nil -} - -// OnEOFReader wraps an io.ReadCloser and a function -// the function will run at the end of file or close the file. -type OnEOFReader struct { - Rc io.ReadCloser - Fn func() -} - -func (r *OnEOFReader) Read(p []byte) (n int, err error) { - n, err = r.Rc.Read(p) - if err == io.EOF { - r.runFunc() - } - return -} - -// Close closes the file and run the function. -func (r *OnEOFReader) Close() error { - err := r.Rc.Close() - r.runFunc() - return err -} - -func (r *OnEOFReader) runFunc() { - if fn := r.Fn; fn != nil { - fn() - r.Fn = nil - } -} - -// cancelReadCloser wraps an io.ReadCloser with a context for cancelling read -// operations. -type cancelReadCloser struct { - cancel func() - pR *io.PipeReader // Stream to read from - pW *io.PipeWriter -} - -// NewCancelReadCloser creates a wrapper that closes the ReadCloser when the -// context is cancelled. The returned io.ReadCloser must be closed when it is -// no longer needed. -func NewCancelReadCloser(ctx context.Context, in io.ReadCloser) io.ReadCloser { - pR, pW := io.Pipe() - - // Create a context used to signal when the pipe is closed - doneCtx, cancel := context.WithCancel(context.Background()) - - p := &cancelReadCloser{ - cancel: cancel, - pR: pR, - pW: pW, - } - - go func() { - _, err := io.Copy(pW, in) - select { - case <-ctx.Done(): - // If the context was closed, p.closeWithError - // was already called. Calling it again would - // change the error that Read returns. - default: - p.closeWithError(err) - } - in.Close() - }() - go func() { - for { - select { - case <-ctx.Done(): - p.closeWithError(ctx.Err()) - case <-doneCtx.Done(): - return - } - } - }() - - return p -} - -// Read wraps the Read method of the pipe that provides data from the wrapped -// ReadCloser. -func (p *cancelReadCloser) Read(buf []byte) (n int, err error) { - return p.pR.Read(buf) -} - -// closeWithError closes the wrapper and its underlying reader. It will -// cause future calls to Read to return err. -func (p *cancelReadCloser) closeWithError(err error) { - p.pW.CloseWithError(err) - p.cancel() -} - -// Close closes the wrapper its underlying reader. It will cause -// future calls to Read to return io.EOF. -func (p *cancelReadCloser) Close() error { - p.closeWithError(io.EOF) - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/readers_test.go b/vendor/github.com/docker/docker/pkg/ioutils/readers_test.go deleted file mode 100644 index 9abc105..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/readers_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package ioutils - -import ( - "fmt" - "io/ioutil" - "strings" - "testing" - "time" - - "golang.org/x/net/context" -) - -// Implement io.Reader -type errorReader struct{} - -func (r *errorReader) Read(p []byte) (int, error) { - return 0, fmt.Errorf("Error reader always fail.") -} - -func TestReadCloserWrapperClose(t *testing.T) { - reader := strings.NewReader("A string reader") - wrapper := NewReadCloserWrapper(reader, func() error { - return fmt.Errorf("This will be called when closing") - }) - err := wrapper.Close() - if err == nil || !strings.Contains(err.Error(), "This will be called when closing") { - t.Fatalf("readCloserWrapper should have call the anonymous func and thus, fail.") - } -} - -func TestReaderErrWrapperReadOnError(t *testing.T) { - called := false - reader := &errorReader{} - wrapper := NewReaderErrWrapper(reader, func() { - called = true - }) - _, err := wrapper.Read([]byte{}) - if err == nil || !strings.Contains(err.Error(), "Error reader always fail.") { - t.Fatalf("readErrWrapper should returned an error") - } - if !called { - t.Fatalf("readErrWrapper should have call the anonymous function on failure") - } -} - -func TestReaderErrWrapperRead(t *testing.T) { - reader := strings.NewReader("a string reader.") - wrapper := NewReaderErrWrapper(reader, func() { - t.Fatalf("readErrWrapper should not have called the anonymous function") - }) - // Read 20 byte (should be ok with the string above) - num, err := wrapper.Read(make([]byte, 20)) - if err != nil { - t.Fatal(err) - } - if num != 16 { - t.Fatalf("readerErrWrapper should have read 16 byte, but read %d", num) - } -} - -func TestHashData(t *testing.T) { - reader := strings.NewReader("hash-me") - actual, err := HashData(reader) - if err != nil { - t.Fatal(err) - } - expected := "sha256:4d11186aed035cc624d553e10db358492c84a7cd6b9670d92123c144930450aa" - if actual != expected { - t.Fatalf("Expecting %s, got %s", expected, actual) - } -} - -type perpetualReader struct{} - -func (p *perpetualReader) Read(buf []byte) (n int, err error) { - for i := 0; i != len(buf); i++ { - buf[i] = 'a' - } - return len(buf), nil -} - -func TestCancelReadCloser(t *testing.T) { - ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond) - cancelReadCloser := NewCancelReadCloser(ctx, ioutil.NopCloser(&perpetualReader{})) - for { - var buf [128]byte - _, err := cancelReadCloser.Read(buf[:]) - if err == context.DeadlineExceeded { - break - } else if err != nil { - t.Fatalf("got unexpected error: %v", err) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/temp_unix.go b/vendor/github.com/docker/docker/pkg/ioutils/temp_unix.go deleted file mode 100644 index 1539ad2..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/temp_unix.go +++ /dev/null @@ -1,10 +0,0 @@ -// +build !windows - -package ioutils - -import "io/ioutil" - -// TempDir on Unix systems is equivalent to ioutil.TempDir. -func TempDir(dir, prefix string) (string, error) { - return ioutil.TempDir(dir, prefix) -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/temp_windows.go b/vendor/github.com/docker/docker/pkg/ioutils/temp_windows.go deleted file mode 100644 index c258e5f..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/temp_windows.go +++ /dev/null @@ -1,18 +0,0 @@ -// +build windows - -package ioutils - -import ( - "io/ioutil" - - "github.com/docker/docker/pkg/longpath" -) - -// TempDir is the equivalent of ioutil.TempDir, except that the result is in Windows longpath format. -func TempDir(dir, prefix string) (string, error) { - tempDir, err := ioutil.TempDir(dir, prefix) - if err != nil { - return "", err - } - return longpath.AddPrefix(tempDir), nil -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/writeflusher.go b/vendor/github.com/docker/docker/pkg/ioutils/writeflusher.go deleted file mode 100644 index 52a4901..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/writeflusher.go +++ /dev/null @@ -1,92 +0,0 @@ -package ioutils - -import ( - "io" - "sync" -) - -// WriteFlusher wraps the Write and Flush operation ensuring that every write -// is a flush. In addition, the Close method can be called to intercept -// Read/Write calls if the targets lifecycle has already ended. -type WriteFlusher struct { - w io.Writer - flusher flusher - flushed chan struct{} - flushedOnce sync.Once - closed chan struct{} - closeLock sync.Mutex -} - -type flusher interface { - Flush() -} - -var errWriteFlusherClosed = io.EOF - -func (wf *WriteFlusher) Write(b []byte) (n int, err error) { - select { - case <-wf.closed: - return 0, errWriteFlusherClosed - default: - } - - n, err = wf.w.Write(b) - wf.Flush() // every write is a flush. - return n, err -} - -// Flush the stream immediately. -func (wf *WriteFlusher) Flush() { - select { - case <-wf.closed: - return - default: - } - - wf.flushedOnce.Do(func() { - close(wf.flushed) - }) - wf.flusher.Flush() -} - -// Flushed returns the state of flushed. -// If it's flushed, return true, or else it return false. -func (wf *WriteFlusher) Flushed() bool { - // BUG(stevvooe): Remove this method. Its use is inherently racy. Seems to - // be used to detect whether or a response code has been issued or not. - // Another hook should be used instead. - var flushed bool - select { - case <-wf.flushed: - flushed = true - default: - } - return flushed -} - -// Close closes the write flusher, disallowing any further writes to the -// target. After the flusher is closed, all calls to write or flush will -// result in an error. -func (wf *WriteFlusher) Close() error { - wf.closeLock.Lock() - defer wf.closeLock.Unlock() - - select { - case <-wf.closed: - return errWriteFlusherClosed - default: - close(wf.closed) - } - return nil -} - -// NewWriteFlusher returns a new WriteFlusher. -func NewWriteFlusher(w io.Writer) *WriteFlusher { - var fl flusher - if f, ok := w.(flusher); ok { - fl = f - } else { - fl = &NopFlusher{} - } - return &WriteFlusher{w: w, flusher: fl, closed: make(chan struct{}), flushed: make(chan struct{})} -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/writers.go b/vendor/github.com/docker/docker/pkg/ioutils/writers.go deleted file mode 100644 index ccc7f9c..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/writers.go +++ /dev/null @@ -1,66 +0,0 @@ -package ioutils - -import "io" - -// NopWriter represents a type which write operation is nop. -type NopWriter struct{} - -func (*NopWriter) Write(buf []byte) (int, error) { - return len(buf), nil -} - -type nopWriteCloser struct { - io.Writer -} - -func (w *nopWriteCloser) Close() error { return nil } - -// NopWriteCloser returns a nopWriteCloser. -func NopWriteCloser(w io.Writer) io.WriteCloser { - return &nopWriteCloser{w} -} - -// NopFlusher represents a type which flush operation is nop. -type NopFlusher struct{} - -// Flush is a nop operation. -func (f *NopFlusher) Flush() {} - -type writeCloserWrapper struct { - io.Writer - closer func() error -} - -func (r *writeCloserWrapper) Close() error { - return r.closer() -} - -// NewWriteCloserWrapper returns a new io.WriteCloser. -func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser { - return &writeCloserWrapper{ - Writer: r, - closer: closer, - } -} - -// WriteCounter wraps a concrete io.Writer and hold a count of the number -// of bytes written to the writer during a "session". -// This can be convenient when write return is masked -// (e.g., json.Encoder.Encode()) -type WriteCounter struct { - Count int64 - Writer io.Writer -} - -// NewWriteCounter returns a new WriteCounter. -func NewWriteCounter(w io.Writer) *WriteCounter { - return &WriteCounter{ - Writer: w, - } -} - -func (wc *WriteCounter) Write(p []byte) (count int, err error) { - count, err = wc.Writer.Write(p) - wc.Count += int64(count) - return -} diff --git a/vendor/github.com/docker/docker/pkg/ioutils/writers_test.go b/vendor/github.com/docker/docker/pkg/ioutils/writers_test.go deleted file mode 100644 index 564b1cd..0000000 --- a/vendor/github.com/docker/docker/pkg/ioutils/writers_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package ioutils - -import ( - "bytes" - "strings" - "testing" -) - -func TestWriteCloserWrapperClose(t *testing.T) { - called := false - writer := bytes.NewBuffer([]byte{}) - wrapper := NewWriteCloserWrapper(writer, func() error { - called = true - return nil - }) - if err := wrapper.Close(); err != nil { - t.Fatal(err) - } - if !called { - t.Fatalf("writeCloserWrapper should have call the anonymous function.") - } -} - -func TestNopWriteCloser(t *testing.T) { - writer := bytes.NewBuffer([]byte{}) - wrapper := NopWriteCloser(writer) - if err := wrapper.Close(); err != nil { - t.Fatal("NopWriteCloser always return nil on Close.") - } - -} - -func TestNopWriter(t *testing.T) { - nw := &NopWriter{} - l, err := nw.Write([]byte{'c'}) - if err != nil { - t.Fatal(err) - } - if l != 1 { - t.Fatalf("Expected 1 got %d", l) - } -} - -func TestWriteCounter(t *testing.T) { - dummy1 := "This is a dummy string." - dummy2 := "This is another dummy string." - totalLength := int64(len(dummy1) + len(dummy2)) - - reader1 := strings.NewReader(dummy1) - reader2 := strings.NewReader(dummy2) - - var buffer bytes.Buffer - wc := NewWriteCounter(&buffer) - - reader1.WriteTo(wc) - reader2.WriteTo(wc) - - if wc.Count != totalLength { - t.Errorf("Wrong count: %d vs. %d", wc.Count, totalLength) - } - - if buffer.String() != dummy1+dummy2 { - t.Error("Wrong message written") - } -} diff --git a/vendor/github.com/docker/docker/pkg/jsonlog/jsonlog.go b/vendor/github.com/docker/docker/pkg/jsonlog/jsonlog.go deleted file mode 100644 index 4734c31..0000000 --- a/vendor/github.com/docker/docker/pkg/jsonlog/jsonlog.go +++ /dev/null @@ -1,42 +0,0 @@ -package jsonlog - -import ( - "encoding/json" - "fmt" - "time" -) - -// JSONLog represents a log message, typically a single entry from a given log stream. -// JSONLogs can be easily serialized to and from JSON and support custom formatting. -type JSONLog struct { - // Log is the log message - Log string `json:"log,omitempty"` - // Stream is the log source - Stream string `json:"stream,omitempty"` - // Created is the created timestamp of log - Created time.Time `json:"time"` - // Attrs is the list of extra attributes provided by the user - Attrs map[string]string `json:"attrs,omitempty"` -} - -// Format returns the log formatted according to format -// If format is nil, returns the log message -// If format is json, returns the log marshaled in json format -// By default, returns the log with the log time formatted according to format. -func (jl *JSONLog) Format(format string) (string, error) { - if format == "" { - return jl.Log, nil - } - if format == "json" { - m, err := json.Marshal(jl) - return string(m), err - } - return fmt.Sprintf("%s %s", jl.Created.Format(format), jl.Log), nil -} - -// Reset resets the log to nil. -func (jl *JSONLog) Reset() { - jl.Log = "" - jl.Stream = "" - jl.Created = time.Time{} -} diff --git a/vendor/github.com/docker/docker/pkg/jsonlog/jsonlog_marshalling.go b/vendor/github.com/docker/docker/pkg/jsonlog/jsonlog_marshalling.go deleted file mode 100644 index 83ce684..0000000 --- a/vendor/github.com/docker/docker/pkg/jsonlog/jsonlog_marshalling.go +++ /dev/null @@ -1,178 +0,0 @@ -// This code was initially generated by ffjson -// This code was generated via the following steps: -// $ go get -u github.com/pquerna/ffjson -// $ make BIND_DIR=. shell -// $ ffjson pkg/jsonlog/jsonlog.go -// $ mv pkg/jsonglog/jsonlog_ffjson.go pkg/jsonlog/jsonlog_marshalling.go -// -// It has been modified to improve the performance of time marshalling to JSON -// and to clean it up. -// Should this code need to be regenerated when the JSONLog struct is changed, -// the relevant changes which have been made are: -// import ( -// "bytes" -//- -// "unicode/utf8" -// ) -// -// func (mj *JSONLog) MarshalJSON() ([]byte, error) { -//@@ -20,13 +16,13 @@ func (mj *JSONLog) MarshalJSON() ([]byte, error) { -// } -// return buf.Bytes(), nil -// } -//+ -// func (mj *JSONLog) MarshalJSONBuf(buf *bytes.Buffer) error { -//- var err error -//- var obj []byte -//- var first bool = true -//- _ = obj -//- _ = err -//- _ = first -//+ var ( -//+ err error -//+ timestamp string -//+ first bool = true -//+ ) -// buf.WriteString(`{`) -// if len(mj.Log) != 0 { -// if first == true { -//@@ -52,11 +48,11 @@ func (mj *JSONLog) MarshalJSONBuf(buf *bytes.Buffer) error { -// buf.WriteString(`,`) -// } -// buf.WriteString(`"time":`) -//- obj, err = mj.Created.MarshalJSON() -//+ timestamp, err = FastTimeMarshalJSON(mj.Created) -// if err != nil { -// return err -// } -//- buf.Write(obj) -//+ buf.WriteString(timestamp) -// buf.WriteString(`}`) -// return nil -// } -// @@ -81,9 +81,10 @@ func (mj *JSONLog) MarshalJSONBuf(buf *bytes.Buffer) error { -// if len(mj.Log) != 0 { -// - if first == true { -// - first = false -// - } else { -// - buf.WriteString(`,`) -// - } -// + first = false -// buf.WriteString(`"log":`) -// ffjsonWriteJSONString(buf, mj.Log) -// } - -package jsonlog - -import ( - "bytes" - "unicode/utf8" -) - -// MarshalJSON marshals the JSONLog. -func (mj *JSONLog) MarshalJSON() ([]byte, error) { - var buf bytes.Buffer - buf.Grow(1024) - if err := mj.MarshalJSONBuf(&buf); err != nil { - return nil, err - } - return buf.Bytes(), nil -} - -// MarshalJSONBuf marshals the JSONLog and stores the result to a bytes.Buffer. -func (mj *JSONLog) MarshalJSONBuf(buf *bytes.Buffer) error { - var ( - err error - timestamp string - first = true - ) - buf.WriteString(`{`) - if len(mj.Log) != 0 { - first = false - buf.WriteString(`"log":`) - ffjsonWriteJSONString(buf, mj.Log) - } - if len(mj.Stream) != 0 { - if first { - first = false - } else { - buf.WriteString(`,`) - } - buf.WriteString(`"stream":`) - ffjsonWriteJSONString(buf, mj.Stream) - } - if !first { - buf.WriteString(`,`) - } - buf.WriteString(`"time":`) - timestamp, err = FastTimeMarshalJSON(mj.Created) - if err != nil { - return err - } - buf.WriteString(timestamp) - buf.WriteString(`}`) - return nil -} - -func ffjsonWriteJSONString(buf *bytes.Buffer, s string) { - const hex = "0123456789abcdef" - - buf.WriteByte('"') - start := 0 - for i := 0; i < len(s); { - if b := s[i]; b < utf8.RuneSelf { - if 0x20 <= b && b != '\\' && b != '"' && b != '<' && b != '>' && b != '&' { - i++ - continue - } - if start < i { - buf.WriteString(s[start:i]) - } - switch b { - case '\\', '"': - buf.WriteByte('\\') - buf.WriteByte(b) - case '\n': - buf.WriteByte('\\') - buf.WriteByte('n') - case '\r': - buf.WriteByte('\\') - buf.WriteByte('r') - default: - - buf.WriteString(`\u00`) - buf.WriteByte(hex[b>>4]) - buf.WriteByte(hex[b&0xF]) - } - i++ - start = i - continue - } - c, size := utf8.DecodeRuneInString(s[i:]) - if c == utf8.RuneError && size == 1 { - if start < i { - buf.WriteString(s[start:i]) - } - buf.WriteString(`\ufffd`) - i += size - start = i - continue - } - - if c == '\u2028' || c == '\u2029' { - if start < i { - buf.WriteString(s[start:i]) - } - buf.WriteString(`\u202`) - buf.WriteByte(hex[c&0xF]) - i += size - start = i - continue - } - i += size - } - if start < len(s) { - buf.WriteString(s[start:]) - } - buf.WriteByte('"') -} diff --git a/vendor/github.com/docker/docker/pkg/jsonlog/jsonlog_marshalling_test.go b/vendor/github.com/docker/docker/pkg/jsonlog/jsonlog_marshalling_test.go deleted file mode 100644 index 3edb271..0000000 --- a/vendor/github.com/docker/docker/pkg/jsonlog/jsonlog_marshalling_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package jsonlog - -import ( - "regexp" - "testing" -) - -func TestJSONLogMarshalJSON(t *testing.T) { - logs := map[*JSONLog]string{ - &JSONLog{Log: `"A log line with \\"`}: `^{\"log\":\"\\\"A log line with \\\\\\\\\\\"\",\"time\":\".{20,}\"}$`, - &JSONLog{Log: "A log line"}: `^{\"log\":\"A log line\",\"time\":\".{20,}\"}$`, - &JSONLog{Log: "A log line with \r"}: `^{\"log\":\"A log line with \\r\",\"time\":\".{20,}\"}$`, - &JSONLog{Log: "A log line with & < >"}: `^{\"log\":\"A log line with \\u0026 \\u003c \\u003e\",\"time\":\".{20,}\"}$`, - &JSONLog{Log: "A log line with utf8 : 🚀 ψ ω β"}: `^{\"log\":\"A log line with utf8 : 🚀 ψ ω β\",\"time\":\".{20,}\"}$`, - &JSONLog{Stream: "stdout"}: `^{\"stream\":\"stdout\",\"time\":\".{20,}\"}$`, - &JSONLog{}: `^{\"time\":\".{20,}\"}$`, - // These ones are a little weird - &JSONLog{Log: "\u2028 \u2029"}: `^{\"log\":\"\\u2028 \\u2029\",\"time\":\".{20,}\"}$`, - &JSONLog{Log: string([]byte{0xaF})}: `^{\"log\":\"\\ufffd\",\"time\":\".{20,}\"}$`, - &JSONLog{Log: string([]byte{0x7F})}: `^{\"log\":\"\x7f\",\"time\":\".{20,}\"}$`, - } - for jsonLog, expression := range logs { - data, err := jsonLog.MarshalJSON() - if err != nil { - t.Fatal(err) - } - res := string(data) - t.Logf("Result of WriteLog: %q", res) - logRe := regexp.MustCompile(expression) - if !logRe.MatchString(res) { - t.Fatalf("Log line not in expected format [%v]: %q", expression, res) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/jsonlog/jsonlogbytes.go b/vendor/github.com/docker/docker/pkg/jsonlog/jsonlogbytes.go deleted file mode 100644 index df522c0..0000000 --- a/vendor/github.com/docker/docker/pkg/jsonlog/jsonlogbytes.go +++ /dev/null @@ -1,122 +0,0 @@ -package jsonlog - -import ( - "bytes" - "encoding/json" - "unicode/utf8" -) - -// JSONLogs is based on JSONLog. -// It allows marshalling JSONLog from Log as []byte -// and an already marshalled Created timestamp. -type JSONLogs struct { - Log []byte `json:"log,omitempty"` - Stream string `json:"stream,omitempty"` - Created string `json:"time"` - - // json-encoded bytes - RawAttrs json.RawMessage `json:"attrs,omitempty"` -} - -// MarshalJSONBuf is based on the same method from JSONLog -// It has been modified to take into account the necessary changes. -func (mj *JSONLogs) MarshalJSONBuf(buf *bytes.Buffer) error { - var first = true - - buf.WriteString(`{`) - if len(mj.Log) != 0 { - first = false - buf.WriteString(`"log":`) - ffjsonWriteJSONBytesAsString(buf, mj.Log) - } - if len(mj.Stream) != 0 { - if first == true { - first = false - } else { - buf.WriteString(`,`) - } - buf.WriteString(`"stream":`) - ffjsonWriteJSONString(buf, mj.Stream) - } - if len(mj.RawAttrs) > 0 { - if first { - first = false - } else { - buf.WriteString(`,`) - } - buf.WriteString(`"attrs":`) - buf.Write(mj.RawAttrs) - } - if !first { - buf.WriteString(`,`) - } - buf.WriteString(`"time":`) - buf.WriteString(mj.Created) - buf.WriteString(`}`) - return nil -} - -// This is based on ffjsonWriteJSONBytesAsString. It has been changed -// to accept a string passed as a slice of bytes. -func ffjsonWriteJSONBytesAsString(buf *bytes.Buffer, s []byte) { - const hex = "0123456789abcdef" - - buf.WriteByte('"') - start := 0 - for i := 0; i < len(s); { - if b := s[i]; b < utf8.RuneSelf { - if 0x20 <= b && b != '\\' && b != '"' && b != '<' && b != '>' && b != '&' { - i++ - continue - } - if start < i { - buf.Write(s[start:i]) - } - switch b { - case '\\', '"': - buf.WriteByte('\\') - buf.WriteByte(b) - case '\n': - buf.WriteByte('\\') - buf.WriteByte('n') - case '\r': - buf.WriteByte('\\') - buf.WriteByte('r') - default: - - buf.WriteString(`\u00`) - buf.WriteByte(hex[b>>4]) - buf.WriteByte(hex[b&0xF]) - } - i++ - start = i - continue - } - c, size := utf8.DecodeRune(s[i:]) - if c == utf8.RuneError && size == 1 { - if start < i { - buf.Write(s[start:i]) - } - buf.WriteString(`\ufffd`) - i += size - start = i - continue - } - - if c == '\u2028' || c == '\u2029' { - if start < i { - buf.Write(s[start:i]) - } - buf.WriteString(`\u202`) - buf.WriteByte(hex[c&0xF]) - i += size - start = i - continue - } - i += size - } - if start < len(s) { - buf.Write(s[start:]) - } - buf.WriteByte('"') -} diff --git a/vendor/github.com/docker/docker/pkg/jsonlog/jsonlogbytes_test.go b/vendor/github.com/docker/docker/pkg/jsonlog/jsonlogbytes_test.go deleted file mode 100644 index 6d6ad21..0000000 --- a/vendor/github.com/docker/docker/pkg/jsonlog/jsonlogbytes_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package jsonlog - -import ( - "bytes" - "regexp" - "testing" -) - -func TestJSONLogsMarshalJSONBuf(t *testing.T) { - logs := map[*JSONLogs]string{ - &JSONLogs{Log: []byte(`"A log line with \\"`)}: `^{\"log\":\"\\\"A log line with \\\\\\\\\\\"\",\"time\":}$`, - &JSONLogs{Log: []byte("A log line")}: `^{\"log\":\"A log line\",\"time\":}$`, - &JSONLogs{Log: []byte("A log line with \r")}: `^{\"log\":\"A log line with \\r\",\"time\":}$`, - &JSONLogs{Log: []byte("A log line with & < >")}: `^{\"log\":\"A log line with \\u0026 \\u003c \\u003e\",\"time\":}$`, - &JSONLogs{Log: []byte("A log line with utf8 : 🚀 ψ ω β")}: `^{\"log\":\"A log line with utf8 : 🚀 ψ ω β\",\"time\":}$`, - &JSONLogs{Stream: "stdout"}: `^{\"stream\":\"stdout\",\"time\":}$`, - &JSONLogs{Stream: "stdout", Log: []byte("A log line")}: `^{\"log\":\"A log line\",\"stream\":\"stdout\",\"time\":}$`, - &JSONLogs{Created: "time"}: `^{\"time\":time}$`, - &JSONLogs{}: `^{\"time\":}$`, - // These ones are a little weird - &JSONLogs{Log: []byte("\u2028 \u2029")}: `^{\"log\":\"\\u2028 \\u2029\",\"time\":}$`, - &JSONLogs{Log: []byte{0xaF}}: `^{\"log\":\"\\ufffd\",\"time\":}$`, - &JSONLogs{Log: []byte{0x7F}}: `^{\"log\":\"\x7f\",\"time\":}$`, - // with raw attributes - &JSONLogs{Log: []byte("A log line"), RawAttrs: []byte(`{"hello":"world","value":1234}`)}: `^{\"log\":\"A log line\",\"attrs\":{\"hello\":\"world\",\"value\":1234},\"time\":}$`, - } - for jsonLog, expression := range logs { - var buf bytes.Buffer - if err := jsonLog.MarshalJSONBuf(&buf); err != nil { - t.Fatal(err) - } - res := buf.String() - t.Logf("Result of WriteLog: %q", res) - logRe := regexp.MustCompile(expression) - if !logRe.MatchString(res) { - t.Fatalf("Log line not in expected format [%v]: %q", expression, res) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/jsonlog/time_marshalling.go b/vendor/github.com/docker/docker/pkg/jsonlog/time_marshalling.go deleted file mode 100644 index 2117338..0000000 --- a/vendor/github.com/docker/docker/pkg/jsonlog/time_marshalling.go +++ /dev/null @@ -1,27 +0,0 @@ -// Package jsonlog provides helper functions to parse and print time (time.Time) as JSON. -package jsonlog - -import ( - "errors" - "time" -) - -const ( - // RFC3339NanoFixed is our own version of RFC339Nano because we want one - // that pads the nano seconds part with zeros to ensure - // the timestamps are aligned in the logs. - RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00" - // JSONFormat is the format used by FastMarshalJSON - JSONFormat = `"` + time.RFC3339Nano + `"` -) - -// FastTimeMarshalJSON avoids one of the extra allocations that -// time.MarshalJSON is making. -func FastTimeMarshalJSON(t time.Time) (string, error) { - if y := t.Year(); y < 0 || y >= 10000 { - // RFC 3339 is clear that years are 4 digits exactly. - // See golang.org/issue/4556#c15 for more discussion. - return "", errors.New("time.MarshalJSON: year outside of range [0,9999]") - } - return t.Format(JSONFormat), nil -} diff --git a/vendor/github.com/docker/docker/pkg/jsonlog/time_marshalling_test.go b/vendor/github.com/docker/docker/pkg/jsonlog/time_marshalling_test.go deleted file mode 100644 index 02d0302..0000000 --- a/vendor/github.com/docker/docker/pkg/jsonlog/time_marshalling_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package jsonlog - -import ( - "testing" - "time" -) - -// Testing to ensure 'year' fields is between 0 and 9999 -func TestFastTimeMarshalJSONWithInvalidDate(t *testing.T) { - aTime := time.Date(-1, 1, 1, 0, 0, 0, 0, time.Local) - json, err := FastTimeMarshalJSON(aTime) - if err == nil { - t.Fatalf("FastTimeMarshalJSON should throw an error, but was '%v'", json) - } - anotherTime := time.Date(10000, 1, 1, 0, 0, 0, 0, time.Local) - json, err = FastTimeMarshalJSON(anotherTime) - if err == nil { - t.Fatalf("FastTimeMarshalJSON should throw an error, but was '%v'", json) - } - -} - -func TestFastTimeMarshalJSON(t *testing.T) { - aTime := time.Date(2015, 5, 29, 11, 1, 2, 3, time.UTC) - json, err := FastTimeMarshalJSON(aTime) - if err != nil { - t.Fatal(err) - } - expected := "\"2015-05-29T11:01:02.000000003Z\"" - if json != expected { - t.Fatalf("Expected %v, got %v", expected, json) - } - - location, err := time.LoadLocation("Europe/Paris") - if err != nil { - t.Fatal(err) - } - aTime = time.Date(2015, 5, 29, 11, 1, 2, 3, location) - json, err = FastTimeMarshalJSON(aTime) - if err != nil { - t.Fatal(err) - } - expected = "\"2015-05-29T11:01:02.000000003+02:00\"" - if json != expected { - t.Fatalf("Expected %v, got %v", expected, json) - } -} diff --git a/vendor/github.com/docker/docker/pkg/jsonmessage/jsonmessage.go b/vendor/github.com/docker/docker/pkg/jsonmessage/jsonmessage.go deleted file mode 100644 index 5481433..0000000 --- a/vendor/github.com/docker/docker/pkg/jsonmessage/jsonmessage.go +++ /dev/null @@ -1,225 +0,0 @@ -package jsonmessage - -import ( - "encoding/json" - "fmt" - "io" - "strings" - "time" - - "github.com/docker/docker/pkg/jsonlog" - "github.com/docker/docker/pkg/term" - "github.com/docker/go-units" -) - -// JSONError wraps a concrete Code and Message, `Code` is -// is an integer error code, `Message` is the error message. -type JSONError struct { - Code int `json:"code,omitempty"` - Message string `json:"message,omitempty"` -} - -func (e *JSONError) Error() string { - return e.Message -} - -// JSONProgress describes a Progress. terminalFd is the fd of the current terminal, -// Start is the initial value for the operation. Current is the current status and -// value of the progress made towards Total. Total is the end value describing when -// we made 100% progress for an operation. -type JSONProgress struct { - terminalFd uintptr - Current int64 `json:"current,omitempty"` - Total int64 `json:"total,omitempty"` - Start int64 `json:"start,omitempty"` -} - -func (p *JSONProgress) String() string { - var ( - width = 200 - pbBox string - numbersBox string - timeLeftBox string - ) - - ws, err := term.GetWinsize(p.terminalFd) - if err == nil { - width = int(ws.Width) - } - - if p.Current <= 0 && p.Total <= 0 { - return "" - } - current := units.HumanSize(float64(p.Current)) - if p.Total <= 0 { - return fmt.Sprintf("%8v", current) - } - total := units.HumanSize(float64(p.Total)) - percentage := int(float64(p.Current)/float64(p.Total)*100) / 2 - if percentage > 50 { - percentage = 50 - } - if width > 110 { - // this number can't be negative gh#7136 - numSpaces := 0 - if 50-percentage > 0 { - numSpaces = 50 - percentage - } - pbBox = fmt.Sprintf("[%s>%s] ", strings.Repeat("=", percentage), strings.Repeat(" ", numSpaces)) - } - - numbersBox = fmt.Sprintf("%8v/%v", current, total) - - if p.Current > p.Total { - // remove total display if the reported current is wonky. - numbersBox = fmt.Sprintf("%8v", current) - } - - if p.Current > 0 && p.Start > 0 && percentage < 50 { - fromStart := time.Now().UTC().Sub(time.Unix(p.Start, 0)) - perEntry := fromStart / time.Duration(p.Current) - left := time.Duration(p.Total-p.Current) * perEntry - left = (left / time.Second) * time.Second - - if width > 50 { - timeLeftBox = " " + left.String() - } - } - return pbBox + numbersBox + timeLeftBox -} - -// JSONMessage defines a message struct. It describes -// the created time, where it from, status, ID of the -// message. It's used for docker events. -type JSONMessage struct { - Stream string `json:"stream,omitempty"` - Status string `json:"status,omitempty"` - Progress *JSONProgress `json:"progressDetail,omitempty"` - ProgressMessage string `json:"progress,omitempty"` //deprecated - ID string `json:"id,omitempty"` - From string `json:"from,omitempty"` - Time int64 `json:"time,omitempty"` - TimeNano int64 `json:"timeNano,omitempty"` - Error *JSONError `json:"errorDetail,omitempty"` - ErrorMessage string `json:"error,omitempty"` //deprecated - // Aux contains out-of-band data, such as digests for push signing. - Aux *json.RawMessage `json:"aux,omitempty"` -} - -// Display displays the JSONMessage to `out`. `isTerminal` describes if `out` -// is a terminal. If this is the case, it will erase the entire current line -// when displaying the progressbar. -func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error { - if jm.Error != nil { - if jm.Error.Code == 401 { - return fmt.Errorf("Authentication is required.") - } - return jm.Error - } - var endl string - if isTerminal && jm.Stream == "" && jm.Progress != nil { - // [2K = erase entire current line - fmt.Fprintf(out, "%c[2K\r", 27) - endl = "\r" - } else if jm.Progress != nil && jm.Progress.String() != "" { //disable progressbar in non-terminal - return nil - } - if jm.TimeNano != 0 { - fmt.Fprintf(out, "%s ", time.Unix(0, jm.TimeNano).Format(jsonlog.RFC3339NanoFixed)) - } else if jm.Time != 0 { - fmt.Fprintf(out, "%s ", time.Unix(jm.Time, 0).Format(jsonlog.RFC3339NanoFixed)) - } - if jm.ID != "" { - fmt.Fprintf(out, "%s: ", jm.ID) - } - if jm.From != "" { - fmt.Fprintf(out, "(from %s) ", jm.From) - } - if jm.Progress != nil && isTerminal { - fmt.Fprintf(out, "%s %s%s", jm.Status, jm.Progress.String(), endl) - } else if jm.ProgressMessage != "" { //deprecated - fmt.Fprintf(out, "%s %s%s", jm.Status, jm.ProgressMessage, endl) - } else if jm.Stream != "" { - fmt.Fprintf(out, "%s%s", jm.Stream, endl) - } else { - fmt.Fprintf(out, "%s%s\n", jm.Status, endl) - } - return nil -} - -// DisplayJSONMessagesStream displays a json message stream from `in` to `out`, `isTerminal` -// describes if `out` is a terminal. If this is the case, it will print `\n` at the end of -// each line and move the cursor while displaying. -func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, isTerminal bool, auxCallback func(*json.RawMessage)) error { - var ( - dec = json.NewDecoder(in) - ids = make(map[string]int) - ) - for { - diff := 0 - var jm JSONMessage - if err := dec.Decode(&jm); err != nil { - if err == io.EOF { - break - } - return err - } - - if jm.Aux != nil { - if auxCallback != nil { - auxCallback(jm.Aux) - } - continue - } - - if jm.Progress != nil { - jm.Progress.terminalFd = terminalFd - } - if jm.ID != "" && (jm.Progress != nil || jm.ProgressMessage != "") { - line, ok := ids[jm.ID] - if !ok { - // NOTE: This approach of using len(id) to - // figure out the number of lines of history - // only works as long as we clear the history - // when we output something that's not - // accounted for in the map, such as a line - // with no ID. - line = len(ids) - ids[jm.ID] = line - if isTerminal { - fmt.Fprintf(out, "\n") - } - } - diff = len(ids) - line - if isTerminal && diff > 0 { - fmt.Fprintf(out, "%c[%dA", 27, diff) - } - } else { - // When outputting something that isn't progress - // output, clear the history of previous lines. We - // don't want progress entries from some previous - // operation to be updated (for example, pull -a - // with multiple tags). - ids = make(map[string]int) - } - err := jm.Display(out, isTerminal) - if jm.ID != "" && isTerminal && diff > 0 { - fmt.Fprintf(out, "%c[%dB", 27, diff) - } - if err != nil { - return err - } - } - return nil -} - -type stream interface { - io.Writer - FD() uintptr - IsTerminal() bool -} - -// DisplayJSONMessagesToStream prints json messages to the output stream -func DisplayJSONMessagesToStream(in io.Reader, stream stream, auxCallback func(*json.RawMessage)) error { - return DisplayJSONMessagesStream(in, stream, stream.FD(), stream.IsTerminal(), auxCallback) -} diff --git a/vendor/github.com/docker/docker/pkg/jsonmessage/jsonmessage_test.go b/vendor/github.com/docker/docker/pkg/jsonmessage/jsonmessage_test.go deleted file mode 100644 index c6c5b0e..0000000 --- a/vendor/github.com/docker/docker/pkg/jsonmessage/jsonmessage_test.go +++ /dev/null @@ -1,245 +0,0 @@ -package jsonmessage - -import ( - "bytes" - "fmt" - "strings" - "testing" - "time" - - "github.com/docker/docker/pkg/jsonlog" - "github.com/docker/docker/pkg/term" -) - -func TestError(t *testing.T) { - je := JSONError{404, "Not found"} - if je.Error() != "Not found" { - t.Fatalf("Expected 'Not found' got '%s'", je.Error()) - } -} - -func TestProgress(t *testing.T) { - termsz, err := term.GetWinsize(0) - if err != nil { - // we can safely ignore the err here - termsz = nil - } - jp := JSONProgress{} - if jp.String() != "" { - t.Fatalf("Expected empty string, got '%s'", jp.String()) - } - - expected := " 1 B" - jp2 := JSONProgress{Current: 1} - if jp2.String() != expected { - t.Fatalf("Expected %q, got %q", expected, jp2.String()) - } - - expectedStart := "[==========> ] 20 B/100 B" - if termsz != nil && termsz.Width <= 110 { - expectedStart = " 20 B/100 B" - } - jp3 := JSONProgress{Current: 20, Total: 100, Start: time.Now().Unix()} - // Just look at the start of the string - // (the remaining time is really hard to test -_-) - if jp3.String()[:len(expectedStart)] != expectedStart { - t.Fatalf("Expected to start with %q, got %q", expectedStart, jp3.String()) - } - - expected = "[=========================> ] 50 B/100 B" - if termsz != nil && termsz.Width <= 110 { - expected = " 50 B/100 B" - } - jp4 := JSONProgress{Current: 50, Total: 100} - if jp4.String() != expected { - t.Fatalf("Expected %q, got %q", expected, jp4.String()) - } - - // this number can't be negative gh#7136 - expected = "[==================================================>] 50 B" - if termsz != nil && termsz.Width <= 110 { - expected = " 50 B" - } - jp5 := JSONProgress{Current: 50, Total: 40} - if jp5.String() != expected { - t.Fatalf("Expected %q, got %q", expected, jp5.String()) - } -} - -func TestJSONMessageDisplay(t *testing.T) { - now := time.Now() - messages := map[JSONMessage][]string{ - // Empty - JSONMessage{}: {"\n", "\n"}, - // Status - JSONMessage{ - Status: "status", - }: { - "status\n", - "status\n", - }, - // General - JSONMessage{ - Time: now.Unix(), - ID: "ID", - From: "From", - Status: "status", - }: { - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(now.Unix(), 0).Format(jsonlog.RFC3339NanoFixed)), - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(now.Unix(), 0).Format(jsonlog.RFC3339NanoFixed)), - }, - // General, with nano precision time - JSONMessage{ - TimeNano: now.UnixNano(), - ID: "ID", - From: "From", - Status: "status", - }: { - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(jsonlog.RFC3339NanoFixed)), - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(jsonlog.RFC3339NanoFixed)), - }, - // General, with both times Nano is preferred - JSONMessage{ - Time: now.Unix(), - TimeNano: now.UnixNano(), - ID: "ID", - From: "From", - Status: "status", - }: { - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(jsonlog.RFC3339NanoFixed)), - fmt.Sprintf("%v ID: (from From) status\n", time.Unix(0, now.UnixNano()).Format(jsonlog.RFC3339NanoFixed)), - }, - // Stream over status - JSONMessage{ - Status: "status", - Stream: "stream", - }: { - "stream", - "stream", - }, - // With progress message - JSONMessage{ - Status: "status", - ProgressMessage: "progressMessage", - }: { - "status progressMessage", - "status progressMessage", - }, - // With progress, stream empty - JSONMessage{ - Status: "status", - Stream: "", - Progress: &JSONProgress{Current: 1}, - }: { - "", - fmt.Sprintf("%c[2K\rstatus 1 B\r", 27), - }, - } - - // The tests :) - for jsonMessage, expectedMessages := range messages { - // Without terminal - data := bytes.NewBuffer([]byte{}) - if err := jsonMessage.Display(data, false); err != nil { - t.Fatal(err) - } - if data.String() != expectedMessages[0] { - t.Fatalf("Expected [%v], got [%v]", expectedMessages[0], data.String()) - } - // With terminal - data = bytes.NewBuffer([]byte{}) - if err := jsonMessage.Display(data, true); err != nil { - t.Fatal(err) - } - if data.String() != expectedMessages[1] { - t.Fatalf("Expected [%v], got [%v]", expectedMessages[1], data.String()) - } - } -} - -// Test JSONMessage with an Error. It will return an error with the text as error, not the meaning of the HTTP code. -func TestJSONMessageDisplayWithJSONError(t *testing.T) { - data := bytes.NewBuffer([]byte{}) - jsonMessage := JSONMessage{Error: &JSONError{404, "Can't find it"}} - - err := jsonMessage.Display(data, true) - if err == nil || err.Error() != "Can't find it" { - t.Fatalf("Expected a JSONError 404, got [%v]", err) - } - - jsonMessage = JSONMessage{Error: &JSONError{401, "Anything"}} - err = jsonMessage.Display(data, true) - if err == nil || err.Error() != "Authentication is required." { - t.Fatalf("Expected an error [Authentication is required.], got [%v]", err) - } -} - -func TestDisplayJSONMessagesStreamInvalidJSON(t *testing.T) { - var ( - inFd uintptr - ) - data := bytes.NewBuffer([]byte{}) - reader := strings.NewReader("This is not a 'valid' JSON []") - inFd, _ = term.GetFdInfo(reader) - - if err := DisplayJSONMessagesStream(reader, data, inFd, false, nil); err == nil && err.Error()[:17] != "invalid character" { - t.Fatalf("Should have thrown an error (invalid character in ..), got [%v]", err) - } -} - -func TestDisplayJSONMessagesStream(t *testing.T) { - var ( - inFd uintptr - ) - - messages := map[string][]string{ - // empty string - "": { - "", - ""}, - // Without progress & ID - "{ \"status\": \"status\" }": { - "status\n", - "status\n", - }, - // Without progress, with ID - "{ \"id\": \"ID\",\"status\": \"status\" }": { - "ID: status\n", - fmt.Sprintf("ID: status\n"), - }, - // With progress - "{ \"id\": \"ID\", \"status\": \"status\", \"progress\": \"ProgressMessage\" }": { - "ID: status ProgressMessage", - fmt.Sprintf("\n%c[%dAID: status ProgressMessage%c[%dB", 27, 1, 27, 1), - }, - // With progressDetail - "{ \"id\": \"ID\", \"status\": \"status\", \"progressDetail\": { \"Current\": 1} }": { - "", // progressbar is disabled in non-terminal - fmt.Sprintf("\n%c[%dA%c[2K\rID: status 1 B\r%c[%dB", 27, 1, 27, 27, 1), - }, - } - for jsonMessage, expectedMessages := range messages { - data := bytes.NewBuffer([]byte{}) - reader := strings.NewReader(jsonMessage) - inFd, _ = term.GetFdInfo(reader) - - // Without terminal - if err := DisplayJSONMessagesStream(reader, data, inFd, false, nil); err != nil { - t.Fatal(err) - } - if data.String() != expectedMessages[0] { - t.Fatalf("Expected an [%v], got [%v]", expectedMessages[0], data.String()) - } - - // With terminal - data = bytes.NewBuffer([]byte{}) - reader = strings.NewReader(jsonMessage) - if err := DisplayJSONMessagesStream(reader, data, inFd, true, nil); err != nil { - t.Fatal(err) - } - if data.String() != expectedMessages[1] { - t.Fatalf("Expected an [%v], got [%v]", expectedMessages[1], data.String()) - } - } - -} diff --git a/vendor/github.com/docker/docker/pkg/listeners/listeners_solaris.go b/vendor/github.com/docker/docker/pkg/listeners/listeners_solaris.go deleted file mode 100644 index ff833e3..0000000 --- a/vendor/github.com/docker/docker/pkg/listeners/listeners_solaris.go +++ /dev/null @@ -1,31 +0,0 @@ -package listeners - -import ( - "crypto/tls" - "fmt" - "net" - - "github.com/docker/go-connections/sockets" -) - -// Init creates new listeners for the server. -func Init(proto, addr, socketGroup string, tlsConfig *tls.Config) (ls []net.Listener, err error) { - switch proto { - case "tcp": - l, err := sockets.NewTCPSocket(addr, tlsConfig) - if err != nil { - return nil, err - } - ls = append(ls, l) - case "unix": - l, err := sockets.NewUnixSocket(addr, socketGroup) - if err != nil { - return nil, fmt.Errorf("can't create unix socket %s: %v", addr, err) - } - ls = append(ls, l) - default: - return nil, fmt.Errorf("Invalid protocol format: %q", proto) - } - - return -} diff --git a/vendor/github.com/docker/docker/pkg/listeners/listeners_unix.go b/vendor/github.com/docker/docker/pkg/listeners/listeners_unix.go deleted file mode 100644 index 1bcae7a..0000000 --- a/vendor/github.com/docker/docker/pkg/listeners/listeners_unix.go +++ /dev/null @@ -1,94 +0,0 @@ -// +build !windows,!solaris - -package listeners - -import ( - "crypto/tls" - "fmt" - "net" - "strconv" - - "github.com/Sirupsen/logrus" - "github.com/coreos/go-systemd/activation" - "github.com/docker/go-connections/sockets" -) - -// Init creates new listeners for the server. -// TODO: Clean up the fact that socketGroup and tlsConfig aren't always used. -func Init(proto, addr, socketGroup string, tlsConfig *tls.Config) ([]net.Listener, error) { - ls := []net.Listener{} - - switch proto { - case "fd": - fds, err := listenFD(addr, tlsConfig) - if err != nil { - return nil, err - } - ls = append(ls, fds...) - case "tcp": - l, err := sockets.NewTCPSocket(addr, tlsConfig) - if err != nil { - return nil, err - } - ls = append(ls, l) - case "unix": - l, err := sockets.NewUnixSocket(addr, socketGroup) - if err != nil { - return nil, fmt.Errorf("can't create unix socket %s: %v", addr, err) - } - ls = append(ls, l) - default: - return nil, fmt.Errorf("invalid protocol format: %q", proto) - } - - return ls, nil -} - -// listenFD returns the specified socket activated files as a slice of -// net.Listeners or all of the activated files if "*" is given. -func listenFD(addr string, tlsConfig *tls.Config) ([]net.Listener, error) { - var ( - err error - listeners []net.Listener - ) - // socket activation - if tlsConfig != nil { - listeners, err = activation.TLSListeners(false, tlsConfig) - } else { - listeners, err = activation.Listeners(false) - } - if err != nil { - return nil, err - } - - if len(listeners) == 0 { - return nil, fmt.Errorf("no sockets found via socket activation: make sure the service was started by systemd") - } - - // default to all fds just like unix:// and tcp:// - if addr == "" || addr == "*" { - return listeners, nil - } - - fdNum, err := strconv.Atoi(addr) - if err != nil { - return nil, fmt.Errorf("failed to parse systemd fd address: should be a number: %v", addr) - } - fdOffset := fdNum - 3 - if len(listeners) < int(fdOffset)+1 { - return nil, fmt.Errorf("too few socket activated files passed in by systemd") - } - if listeners[fdOffset] == nil { - return nil, fmt.Errorf("failed to listen on systemd activated file: fd %d", fdOffset+3) - } - for i, ls := range listeners { - if i == fdOffset || ls == nil { - continue - } - if err := ls.Close(); err != nil { - // TODO: We shouldn't log inside a library. Remove this or error out. - logrus.Errorf("failed to close systemd activated file: fd %d: %v", fdOffset+3, err) - } - } - return []net.Listener{listeners[fdOffset]}, nil -} diff --git a/vendor/github.com/docker/docker/pkg/listeners/listeners_windows.go b/vendor/github.com/docker/docker/pkg/listeners/listeners_windows.go deleted file mode 100644 index 5b5a470..0000000 --- a/vendor/github.com/docker/docker/pkg/listeners/listeners_windows.go +++ /dev/null @@ -1,54 +0,0 @@ -package listeners - -import ( - "crypto/tls" - "fmt" - "net" - "strings" - - "github.com/Microsoft/go-winio" - "github.com/docker/go-connections/sockets" -) - -// Init creates new listeners for the server. -func Init(proto, addr, socketGroup string, tlsConfig *tls.Config) ([]net.Listener, error) { - ls := []net.Listener{} - - switch proto { - case "tcp": - l, err := sockets.NewTCPSocket(addr, tlsConfig) - if err != nil { - return nil, err - } - ls = append(ls, l) - - case "npipe": - // allow Administrators and SYSTEM, plus whatever additional users or groups were specified - sddl := "D:P(A;;GA;;;BA)(A;;GA;;;SY)" - if socketGroup != "" { - for _, g := range strings.Split(socketGroup, ",") { - sid, err := winio.LookupSidByName(g) - if err != nil { - return nil, err - } - sddl += fmt.Sprintf("(A;;GRGW;;;%s)", sid) - } - } - c := winio.PipeConfig{ - SecurityDescriptor: sddl, - MessageMode: true, // Use message mode so that CloseWrite() is supported - InputBufferSize: 65536, // Use 64KB buffers to improve performance - OutputBufferSize: 65536, - } - l, err := winio.ListenPipe(addr, &c) - if err != nil { - return nil, err - } - ls = append(ls, l) - - default: - return nil, fmt.Errorf("invalid protocol format: windows only supports tcp and npipe") - } - - return ls, nil -} diff --git a/vendor/github.com/docker/docker/pkg/locker/README.md b/vendor/github.com/docker/docker/pkg/locker/README.md deleted file mode 100644 index e84a815..0000000 --- a/vendor/github.com/docker/docker/pkg/locker/README.md +++ /dev/null @@ -1,65 +0,0 @@ -Locker -===== - -locker provides a mechanism for creating finer-grained locking to help -free up more global locks to handle other tasks. - -The implementation looks close to a sync.Mutex, however the user must provide a -reference to use to refer to the underlying lock when locking and unlocking, -and unlock may generate an error. - -If a lock with a given name does not exist when `Lock` is called, one is -created. -Lock references are automatically cleaned up on `Unlock` if nothing else is -waiting for the lock. - - -## Usage - -```go -package important - -import ( - "sync" - "time" - - "github.com/docker/docker/pkg/locker" -) - -type important struct { - locks *locker.Locker - data map[string]interface{} - mu sync.Mutex -} - -func (i *important) Get(name string) interface{} { - i.locks.Lock(name) - defer i.locks.Unlock(name) - return data[name] -} - -func (i *important) Create(name string, data interface{}) { - i.locks.Lock(name) - defer i.locks.Unlock(name) - - i.createImportant(data) - - s.mu.Lock() - i.data[name] = data - s.mu.Unlock() -} - -func (i *important) createImportant(data interface{}) { - time.Sleep(10 * time.Second) -} -``` - -For functions dealing with a given name, always lock at the beginning of the -function (or before doing anything with the underlying state), this ensures any -other function that is dealing with the same name will block. - -When needing to modify the underlying data, use the global lock to ensure nothing -else is modfying it at the same time. -Since name lock is already in place, no reads will occur while the modification -is being performed. - diff --git a/vendor/github.com/docker/docker/pkg/locker/locker.go b/vendor/github.com/docker/docker/pkg/locker/locker.go deleted file mode 100644 index 0b22ddf..0000000 --- a/vendor/github.com/docker/docker/pkg/locker/locker.go +++ /dev/null @@ -1,112 +0,0 @@ -/* -Package locker provides a mechanism for creating finer-grained locking to help -free up more global locks to handle other tasks. - -The implementation looks close to a sync.Mutex, however the user must provide a -reference to use to refer to the underlying lock when locking and unlocking, -and unlock may generate an error. - -If a lock with a given name does not exist when `Lock` is called, one is -created. -Lock references are automatically cleaned up on `Unlock` if nothing else is -waiting for the lock. -*/ -package locker - -import ( - "errors" - "sync" - "sync/atomic" -) - -// ErrNoSuchLock is returned when the requested lock does not exist -var ErrNoSuchLock = errors.New("no such lock") - -// Locker provides a locking mechanism based on the passed in reference name -type Locker struct { - mu sync.Mutex - locks map[string]*lockCtr -} - -// lockCtr is used by Locker to represent a lock with a given name. -type lockCtr struct { - mu sync.Mutex - // waiters is the number of waiters waiting to acquire the lock - // this is int32 instead of uint32 so we can add `-1` in `dec()` - waiters int32 -} - -// inc increments the number of waiters waiting for the lock -func (l *lockCtr) inc() { - atomic.AddInt32(&l.waiters, 1) -} - -// dec decrements the number of waiters waiting on the lock -func (l *lockCtr) dec() { - atomic.AddInt32(&l.waiters, -1) -} - -// count gets the current number of waiters -func (l *lockCtr) count() int32 { - return atomic.LoadInt32(&l.waiters) -} - -// Lock locks the mutex -func (l *lockCtr) Lock() { - l.mu.Lock() -} - -// Unlock unlocks the mutex -func (l *lockCtr) Unlock() { - l.mu.Unlock() -} - -// New creates a new Locker -func New() *Locker { - return &Locker{ - locks: make(map[string]*lockCtr), - } -} - -// Lock locks a mutex with the given name. If it doesn't exist, one is created -func (l *Locker) Lock(name string) { - l.mu.Lock() - if l.locks == nil { - l.locks = make(map[string]*lockCtr) - } - - nameLock, exists := l.locks[name] - if !exists { - nameLock = &lockCtr{} - l.locks[name] = nameLock - } - - // increment the nameLock waiters while inside the main mutex - // this makes sure that the lock isn't deleted if `Lock` and `Unlock` are called concurrently - nameLock.inc() - l.mu.Unlock() - - // Lock the nameLock outside the main mutex so we don't block other operations - // once locked then we can decrement the number of waiters for this lock - nameLock.Lock() - nameLock.dec() -} - -// Unlock unlocks the mutex with the given name -// If the given lock is not being waited on by any other callers, it is deleted -func (l *Locker) Unlock(name string) error { - l.mu.Lock() - nameLock, exists := l.locks[name] - if !exists { - l.mu.Unlock() - return ErrNoSuchLock - } - - if nameLock.count() == 0 { - delete(l.locks, name) - } - nameLock.Unlock() - - l.mu.Unlock() - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/locker/locker_test.go b/vendor/github.com/docker/docker/pkg/locker/locker_test.go deleted file mode 100644 index 5a297dd..0000000 --- a/vendor/github.com/docker/docker/pkg/locker/locker_test.go +++ /dev/null @@ -1,124 +0,0 @@ -package locker - -import ( - "sync" - "testing" - "time" -) - -func TestLockCounter(t *testing.T) { - l := &lockCtr{} - l.inc() - - if l.waiters != 1 { - t.Fatal("counter inc failed") - } - - l.dec() - if l.waiters != 0 { - t.Fatal("counter dec failed") - } -} - -func TestLockerLock(t *testing.T) { - l := New() - l.Lock("test") - ctr := l.locks["test"] - - if ctr.count() != 0 { - t.Fatalf("expected waiters to be 0, got :%d", ctr.waiters) - } - - chDone := make(chan struct{}) - go func() { - l.Lock("test") - close(chDone) - }() - - chWaiting := make(chan struct{}) - go func() { - for range time.Tick(1 * time.Millisecond) { - if ctr.count() == 1 { - close(chWaiting) - break - } - } - }() - - select { - case <-chWaiting: - case <-time.After(3 * time.Second): - t.Fatal("timed out waiting for lock waiters to be incremented") - } - - select { - case <-chDone: - t.Fatal("lock should not have returned while it was still held") - default: - } - - if err := l.Unlock("test"); err != nil { - t.Fatal(err) - } - - select { - case <-chDone: - case <-time.After(3 * time.Second): - t.Fatalf("lock should have completed") - } - - if ctr.count() != 0 { - t.Fatalf("expected waiters to be 0, got: %d", ctr.count()) - } -} - -func TestLockerUnlock(t *testing.T) { - l := New() - - l.Lock("test") - l.Unlock("test") - - chDone := make(chan struct{}) - go func() { - l.Lock("test") - close(chDone) - }() - - select { - case <-chDone: - case <-time.After(3 * time.Second): - t.Fatalf("lock should not be blocked") - } -} - -func TestLockerConcurrency(t *testing.T) { - l := New() - - var wg sync.WaitGroup - for i := 0; i <= 10000; i++ { - wg.Add(1) - go func() { - l.Lock("test") - // if there is a concurrency issue, will very likely panic here - l.Unlock("test") - wg.Done() - }() - } - - chDone := make(chan struct{}) - go func() { - wg.Wait() - close(chDone) - }() - - select { - case <-chDone: - case <-time.After(10 * time.Second): - t.Fatal("timeout waiting for locks to complete") - } - - // Since everything has unlocked this should not exist anymore - if ctr, exists := l.locks["test"]; exists { - t.Fatalf("lock should not exist: %v", ctr) - } -} diff --git a/vendor/github.com/docker/docker/pkg/longpath/longpath.go b/vendor/github.com/docker/docker/pkg/longpath/longpath.go deleted file mode 100644 index 9b15bff..0000000 --- a/vendor/github.com/docker/docker/pkg/longpath/longpath.go +++ /dev/null @@ -1,26 +0,0 @@ -// longpath introduces some constants and helper functions for handling long paths -// in Windows, which are expected to be prepended with `\\?\` and followed by either -// a drive letter, a UNC server\share, or a volume identifier. - -package longpath - -import ( - "strings" -) - -// Prefix is the longpath prefix for Windows file paths. -const Prefix = `\\?\` - -// AddPrefix will add the Windows long path prefix to the path provided if -// it does not already have it. -func AddPrefix(path string) string { - if !strings.HasPrefix(path, Prefix) { - if strings.HasPrefix(path, `\\`) { - // This is a UNC path, so we need to add 'UNC' to the path as well. - path = Prefix + `UNC` + path[1:] - } else { - path = Prefix + path - } - } - return path -} diff --git a/vendor/github.com/docker/docker/pkg/longpath/longpath_test.go b/vendor/github.com/docker/docker/pkg/longpath/longpath_test.go deleted file mode 100644 index 01865ef..0000000 --- a/vendor/github.com/docker/docker/pkg/longpath/longpath_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package longpath - -import ( - "strings" - "testing" -) - -func TestStandardLongPath(t *testing.T) { - c := `C:\simple\path` - longC := AddPrefix(c) - if !strings.EqualFold(longC, `\\?\C:\simple\path`) { - t.Errorf("Wrong long path returned. Original = %s ; Long = %s", c, longC) - } -} - -func TestUNCLongPath(t *testing.T) { - c := `\\server\share\path` - longC := AddPrefix(c) - if !strings.EqualFold(longC, `\\?\UNC\server\share\path`) { - t.Errorf("Wrong UNC long path returned. Original = %s ; Long = %s", c, longC) - } -} diff --git a/vendor/github.com/docker/docker/pkg/loopback/attach_loopback.go b/vendor/github.com/docker/docker/pkg/loopback/attach_loopback.go deleted file mode 100644 index 971f45e..0000000 --- a/vendor/github.com/docker/docker/pkg/loopback/attach_loopback.go +++ /dev/null @@ -1,137 +0,0 @@ -// +build linux - -package loopback - -import ( - "errors" - "fmt" - "os" - "syscall" - - "github.com/Sirupsen/logrus" -) - -// Loopback related errors -var ( - ErrAttachLoopbackDevice = errors.New("loopback attach failed") - ErrGetLoopbackBackingFile = errors.New("Unable to get loopback backing file") - ErrSetCapacity = errors.New("Unable set loopback capacity") -) - -func stringToLoopName(src string) [LoNameSize]uint8 { - var dst [LoNameSize]uint8 - copy(dst[:], src[:]) - return dst -} - -func getNextFreeLoopbackIndex() (int, error) { - f, err := os.OpenFile("/dev/loop-control", os.O_RDONLY, 0644) - if err != nil { - return 0, err - } - defer f.Close() - - index, err := ioctlLoopCtlGetFree(f.Fd()) - if index < 0 { - index = 0 - } - return index, err -} - -func openNextAvailableLoopback(index int, sparseFile *os.File) (loopFile *os.File, err error) { - // Start looking for a free /dev/loop - for { - target := fmt.Sprintf("/dev/loop%d", index) - index++ - - fi, err := os.Stat(target) - if err != nil { - if os.IsNotExist(err) { - logrus.Error("There are no more loopback devices available.") - } - return nil, ErrAttachLoopbackDevice - } - - if fi.Mode()&os.ModeDevice != os.ModeDevice { - logrus.Errorf("Loopback device %s is not a block device.", target) - continue - } - - // OpenFile adds O_CLOEXEC - loopFile, err = os.OpenFile(target, os.O_RDWR, 0644) - if err != nil { - logrus.Errorf("Error opening loopback device: %s", err) - return nil, ErrAttachLoopbackDevice - } - - // Try to attach to the loop file - if err := ioctlLoopSetFd(loopFile.Fd(), sparseFile.Fd()); err != nil { - loopFile.Close() - - // If the error is EBUSY, then try the next loopback - if err != syscall.EBUSY { - logrus.Errorf("Cannot set up loopback device %s: %s", target, err) - return nil, ErrAttachLoopbackDevice - } - - // Otherwise, we keep going with the loop - continue - } - // In case of success, we finished. Break the loop. - break - } - - // This can't happen, but let's be sure - if loopFile == nil { - logrus.Errorf("Unreachable code reached! Error attaching %s to a loopback device.", sparseFile.Name()) - return nil, ErrAttachLoopbackDevice - } - - return loopFile, nil -} - -// AttachLoopDevice attaches the given sparse file to the next -// available loopback device. It returns an opened *os.File. -func AttachLoopDevice(sparseName string) (loop *os.File, err error) { - - // Try to retrieve the next available loopback device via syscall. - // If it fails, we discard error and start looping for a - // loopback from index 0. - startIndex, err := getNextFreeLoopbackIndex() - if err != nil { - logrus.Debugf("Error retrieving the next available loopback: %s", err) - } - - // OpenFile adds O_CLOEXEC - sparseFile, err := os.OpenFile(sparseName, os.O_RDWR, 0644) - if err != nil { - logrus.Errorf("Error opening sparse file %s: %s", sparseName, err) - return nil, ErrAttachLoopbackDevice - } - defer sparseFile.Close() - - loopFile, err := openNextAvailableLoopback(startIndex, sparseFile) - if err != nil { - return nil, err - } - - // Set the status of the loopback device - loopInfo := &loopInfo64{ - loFileName: stringToLoopName(loopFile.Name()), - loOffset: 0, - loFlags: LoFlagsAutoClear, - } - - if err := ioctlLoopSetStatus64(loopFile.Fd(), loopInfo); err != nil { - logrus.Errorf("Cannot set up loopback device info: %s", err) - - // If the call failed, then free the loopback device - if err := ioctlLoopClrFd(loopFile.Fd()); err != nil { - logrus.Error("Error while cleaning up the loopback device") - } - loopFile.Close() - return nil, ErrAttachLoopbackDevice - } - - return loopFile, nil -} diff --git a/vendor/github.com/docker/docker/pkg/loopback/ioctl.go b/vendor/github.com/docker/docker/pkg/loopback/ioctl.go deleted file mode 100644 index 0714eb5..0000000 --- a/vendor/github.com/docker/docker/pkg/loopback/ioctl.go +++ /dev/null @@ -1,53 +0,0 @@ -// +build linux - -package loopback - -import ( - "syscall" - "unsafe" -) - -func ioctlLoopCtlGetFree(fd uintptr) (int, error) { - index, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, LoopCtlGetFree, 0) - if err != 0 { - return 0, err - } - return int(index), nil -} - -func ioctlLoopSetFd(loopFd, sparseFd uintptr) error { - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, loopFd, LoopSetFd, sparseFd); err != 0 { - return err - } - return nil -} - -func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *loopInfo64) error { - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, loopFd, LoopSetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 { - return err - } - return nil -} - -func ioctlLoopClrFd(loopFd uintptr) error { - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, loopFd, LoopClrFd, 0); err != 0 { - return err - } - return nil -} - -func ioctlLoopGetStatus64(loopFd uintptr) (*loopInfo64, error) { - loopInfo := &loopInfo64{} - - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, loopFd, LoopGetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 { - return nil, err - } - return loopInfo, nil -} - -func ioctlLoopSetCapacity(loopFd uintptr, value int) error { - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, loopFd, LoopSetCapacity, uintptr(value)); err != 0 { - return err - } - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/loopback/loop_wrapper.go b/vendor/github.com/docker/docker/pkg/loopback/loop_wrapper.go deleted file mode 100644 index e1100ce..0000000 --- a/vendor/github.com/docker/docker/pkg/loopback/loop_wrapper.go +++ /dev/null @@ -1,52 +0,0 @@ -// +build linux - -package loopback - -/* -#include // FIXME: present only for defines, maybe we can remove it? - -#ifndef LOOP_CTL_GET_FREE - #define LOOP_CTL_GET_FREE 0x4C82 -#endif - -#ifndef LO_FLAGS_PARTSCAN - #define LO_FLAGS_PARTSCAN 8 -#endif - -*/ -import "C" - -type loopInfo64 struct { - loDevice uint64 /* ioctl r/o */ - loInode uint64 /* ioctl r/o */ - loRdevice uint64 /* ioctl r/o */ - loOffset uint64 - loSizelimit uint64 /* bytes, 0 == max available */ - loNumber uint32 /* ioctl r/o */ - loEncryptType uint32 - loEncryptKeySize uint32 /* ioctl w/o */ - loFlags uint32 /* ioctl r/o */ - loFileName [LoNameSize]uint8 - loCryptName [LoNameSize]uint8 - loEncryptKey [LoKeySize]uint8 /* ioctl w/o */ - loInit [2]uint64 -} - -// IOCTL consts -const ( - LoopSetFd = C.LOOP_SET_FD - LoopCtlGetFree = C.LOOP_CTL_GET_FREE - LoopGetStatus64 = C.LOOP_GET_STATUS64 - LoopSetStatus64 = C.LOOP_SET_STATUS64 - LoopClrFd = C.LOOP_CLR_FD - LoopSetCapacity = C.LOOP_SET_CAPACITY -) - -// LOOP consts. -const ( - LoFlagsAutoClear = C.LO_FLAGS_AUTOCLEAR - LoFlagsReadOnly = C.LO_FLAGS_READ_ONLY - LoFlagsPartScan = C.LO_FLAGS_PARTSCAN - LoKeySize = C.LO_KEY_SIZE - LoNameSize = C.LO_NAME_SIZE -) diff --git a/vendor/github.com/docker/docker/pkg/loopback/loopback.go b/vendor/github.com/docker/docker/pkg/loopback/loopback.go deleted file mode 100644 index bc04792..0000000 --- a/vendor/github.com/docker/docker/pkg/loopback/loopback.go +++ /dev/null @@ -1,63 +0,0 @@ -// +build linux - -package loopback - -import ( - "fmt" - "os" - "syscall" - - "github.com/Sirupsen/logrus" -) - -func getLoopbackBackingFile(file *os.File) (uint64, uint64, error) { - loopInfo, err := ioctlLoopGetStatus64(file.Fd()) - if err != nil { - logrus.Errorf("Error get loopback backing file: %s", err) - return 0, 0, ErrGetLoopbackBackingFile - } - return loopInfo.loDevice, loopInfo.loInode, nil -} - -// SetCapacity reloads the size for the loopback device. -func SetCapacity(file *os.File) error { - if err := ioctlLoopSetCapacity(file.Fd(), 0); err != nil { - logrus.Errorf("Error loopbackSetCapacity: %s", err) - return ErrSetCapacity - } - return nil -} - -// FindLoopDeviceFor returns a loopback device file for the specified file which -// is backing file of a loop back device. -func FindLoopDeviceFor(file *os.File) *os.File { - stat, err := file.Stat() - if err != nil { - return nil - } - targetInode := stat.Sys().(*syscall.Stat_t).Ino - targetDevice := stat.Sys().(*syscall.Stat_t).Dev - - for i := 0; true; i++ { - path := fmt.Sprintf("/dev/loop%d", i) - - file, err := os.OpenFile(path, os.O_RDWR, 0) - if err != nil { - if os.IsNotExist(err) { - return nil - } - - // Ignore all errors until the first not-exist - // we want to continue looking for the file - continue - } - - dev, inode, err := getLoopbackBackingFile(file) - if err == nil && dev == targetDevice && inode == targetInode { - return file - } - file.Close() - } - - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/mount/flags.go b/vendor/github.com/docker/docker/pkg/mount/flags.go deleted file mode 100644 index 607dbed..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/flags.go +++ /dev/null @@ -1,149 +0,0 @@ -package mount - -import ( - "fmt" - "strings" -) - -var flags = map[string]struct { - clear bool - flag int -}{ - "defaults": {false, 0}, - "ro": {false, RDONLY}, - "rw": {true, RDONLY}, - "suid": {true, NOSUID}, - "nosuid": {false, NOSUID}, - "dev": {true, NODEV}, - "nodev": {false, NODEV}, - "exec": {true, NOEXEC}, - "noexec": {false, NOEXEC}, - "sync": {false, SYNCHRONOUS}, - "async": {true, SYNCHRONOUS}, - "dirsync": {false, DIRSYNC}, - "remount": {false, REMOUNT}, - "mand": {false, MANDLOCK}, - "nomand": {true, MANDLOCK}, - "atime": {true, NOATIME}, - "noatime": {false, NOATIME}, - "diratime": {true, NODIRATIME}, - "nodiratime": {false, NODIRATIME}, - "bind": {false, BIND}, - "rbind": {false, RBIND}, - "unbindable": {false, UNBINDABLE}, - "runbindable": {false, RUNBINDABLE}, - "private": {false, PRIVATE}, - "rprivate": {false, RPRIVATE}, - "shared": {false, SHARED}, - "rshared": {false, RSHARED}, - "slave": {false, SLAVE}, - "rslave": {false, RSLAVE}, - "relatime": {false, RELATIME}, - "norelatime": {true, RELATIME}, - "strictatime": {false, STRICTATIME}, - "nostrictatime": {true, STRICTATIME}, -} - -var validFlags = map[string]bool{ - "": true, - "size": true, - "mode": true, - "uid": true, - "gid": true, - "nr_inodes": true, - "nr_blocks": true, - "mpol": true, -} - -var propagationFlags = map[string]bool{ - "bind": true, - "rbind": true, - "unbindable": true, - "runbindable": true, - "private": true, - "rprivate": true, - "shared": true, - "rshared": true, - "slave": true, - "rslave": true, -} - -// MergeTmpfsOptions merge mount options to make sure there is no duplicate. -func MergeTmpfsOptions(options []string) ([]string, error) { - // We use collisions maps to remove duplicates. - // For flag, the key is the flag value (the key for propagation flag is -1) - // For data=value, the key is the data - flagCollisions := map[int]bool{} - dataCollisions := map[string]bool{} - - var newOptions []string - // We process in reverse order - for i := len(options) - 1; i >= 0; i-- { - option := options[i] - if option == "defaults" { - continue - } - if f, ok := flags[option]; ok && f.flag != 0 { - // There is only one propagation mode - key := f.flag - if propagationFlags[option] { - key = -1 - } - // Check to see if there is collision for flag - if !flagCollisions[key] { - // We prepend the option and add to collision map - newOptions = append([]string{option}, newOptions...) - flagCollisions[key] = true - } - continue - } - opt := strings.SplitN(option, "=", 2) - if len(opt) != 2 || !validFlags[opt[0]] { - return nil, fmt.Errorf("Invalid tmpfs option %q", opt) - } - if !dataCollisions[opt[0]] { - // We prepend the option and add to collision map - newOptions = append([]string{option}, newOptions...) - dataCollisions[opt[0]] = true - } - } - - return newOptions, nil -} - -// Parse fstab type mount options into mount() flags -// and device specific data -func parseOptions(options string) (int, string) { - var ( - flag int - data []string - ) - - for _, o := range strings.Split(options, ",") { - // If the option does not exist in the flags table or the flag - // is not supported on the platform, - // then it is a data value for a specific fs type - if f, exists := flags[o]; exists && f.flag != 0 { - if f.clear { - flag &= ^f.flag - } else { - flag |= f.flag - } - } else { - data = append(data, o) - } - } - return flag, strings.Join(data, ",") -} - -// ParseTmpfsOptions parse fstab type mount options into flags and data -func ParseTmpfsOptions(options string) (int, string, error) { - flags, data := parseOptions(options) - for _, o := range strings.Split(data, ",") { - opt := strings.SplitN(o, "=", 2) - if !validFlags[opt[0]] { - return 0, "", fmt.Errorf("Invalid tmpfs option %q", opt) - } - } - return flags, data, nil -} diff --git a/vendor/github.com/docker/docker/pkg/mount/flags_freebsd.go b/vendor/github.com/docker/docker/pkg/mount/flags_freebsd.go deleted file mode 100644 index f166cb2..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/flags_freebsd.go +++ /dev/null @@ -1,48 +0,0 @@ -// +build freebsd,cgo - -package mount - -/* -#include -*/ -import "C" - -const ( - // RDONLY will mount the filesystem as read-only. - RDONLY = C.MNT_RDONLY - - // NOSUID will not allow set-user-identifier or set-group-identifier bits to - // take effect. - NOSUID = C.MNT_NOSUID - - // NOEXEC will not allow execution of any binaries on the mounted file system. - NOEXEC = C.MNT_NOEXEC - - // SYNCHRONOUS will allow any I/O to the file system to be done synchronously. - SYNCHRONOUS = C.MNT_SYNCHRONOUS - - // NOATIME will not update the file access time when reading from a file. - NOATIME = C.MNT_NOATIME -) - -// These flags are unsupported. -const ( - BIND = 0 - DIRSYNC = 0 - MANDLOCK = 0 - NODEV = 0 - NODIRATIME = 0 - UNBINDABLE = 0 - RUNBINDABLE = 0 - PRIVATE = 0 - RPRIVATE = 0 - SHARED = 0 - RSHARED = 0 - SLAVE = 0 - RSLAVE = 0 - RBIND = 0 - RELATIVE = 0 - RELATIME = 0 - REMOUNT = 0 - STRICTATIME = 0 -) diff --git a/vendor/github.com/docker/docker/pkg/mount/flags_linux.go b/vendor/github.com/docker/docker/pkg/mount/flags_linux.go deleted file mode 100644 index dc696dc..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/flags_linux.go +++ /dev/null @@ -1,85 +0,0 @@ -package mount - -import ( - "syscall" -) - -const ( - // RDONLY will mount the file system read-only. - RDONLY = syscall.MS_RDONLY - - // NOSUID will not allow set-user-identifier or set-group-identifier bits to - // take effect. - NOSUID = syscall.MS_NOSUID - - // NODEV will not interpret character or block special devices on the file - // system. - NODEV = syscall.MS_NODEV - - // NOEXEC will not allow execution of any binaries on the mounted file system. - NOEXEC = syscall.MS_NOEXEC - - // SYNCHRONOUS will allow I/O to the file system to be done synchronously. - SYNCHRONOUS = syscall.MS_SYNCHRONOUS - - // DIRSYNC will force all directory updates within the file system to be done - // synchronously. This affects the following system calls: create, link, - // unlink, symlink, mkdir, rmdir, mknod and rename. - DIRSYNC = syscall.MS_DIRSYNC - - // REMOUNT will attempt to remount an already-mounted file system. This is - // commonly used to change the mount flags for a file system, especially to - // make a readonly file system writeable. It does not change device or mount - // point. - REMOUNT = syscall.MS_REMOUNT - - // MANDLOCK will force mandatory locks on a filesystem. - MANDLOCK = syscall.MS_MANDLOCK - - // NOATIME will not update the file access time when reading from a file. - NOATIME = syscall.MS_NOATIME - - // NODIRATIME will not update the directory access time. - NODIRATIME = syscall.MS_NODIRATIME - - // BIND remounts a subtree somewhere else. - BIND = syscall.MS_BIND - - // RBIND remounts a subtree and all possible submounts somewhere else. - RBIND = syscall.MS_BIND | syscall.MS_REC - - // UNBINDABLE creates a mount which cannot be cloned through a bind operation. - UNBINDABLE = syscall.MS_UNBINDABLE - - // RUNBINDABLE marks the entire mount tree as UNBINDABLE. - RUNBINDABLE = syscall.MS_UNBINDABLE | syscall.MS_REC - - // PRIVATE creates a mount which carries no propagation abilities. - PRIVATE = syscall.MS_PRIVATE - - // RPRIVATE marks the entire mount tree as PRIVATE. - RPRIVATE = syscall.MS_PRIVATE | syscall.MS_REC - - // SLAVE creates a mount which receives propagation from its master, but not - // vice versa. - SLAVE = syscall.MS_SLAVE - - // RSLAVE marks the entire mount tree as SLAVE. - RSLAVE = syscall.MS_SLAVE | syscall.MS_REC - - // SHARED creates a mount which provides the ability to create mirrors of - // that mount such that mounts and unmounts within any of the mirrors - // propagate to the other mirrors. - SHARED = syscall.MS_SHARED - - // RSHARED marks the entire mount tree as SHARED. - RSHARED = syscall.MS_SHARED | syscall.MS_REC - - // RELATIME updates inode access times relative to modify or change time. - RELATIME = syscall.MS_RELATIME - - // STRICTATIME allows to explicitly request full atime updates. This makes - // it possible for the kernel to default to relatime or noatime but still - // allow userspace to override it. - STRICTATIME = syscall.MS_STRICTATIME -) diff --git a/vendor/github.com/docker/docker/pkg/mount/flags_unsupported.go b/vendor/github.com/docker/docker/pkg/mount/flags_unsupported.go deleted file mode 100644 index 5564f7b..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/flags_unsupported.go +++ /dev/null @@ -1,30 +0,0 @@ -// +build !linux,!freebsd freebsd,!cgo solaris,!cgo - -package mount - -// These flags are unsupported. -const ( - BIND = 0 - DIRSYNC = 0 - MANDLOCK = 0 - NOATIME = 0 - NODEV = 0 - NODIRATIME = 0 - NOEXEC = 0 - NOSUID = 0 - UNBINDABLE = 0 - RUNBINDABLE = 0 - PRIVATE = 0 - RPRIVATE = 0 - SHARED = 0 - RSHARED = 0 - SLAVE = 0 - RSLAVE = 0 - RBIND = 0 - RELATIME = 0 - RELATIVE = 0 - REMOUNT = 0 - STRICTATIME = 0 - SYNCHRONOUS = 0 - RDONLY = 0 -) diff --git a/vendor/github.com/docker/docker/pkg/mount/mount.go b/vendor/github.com/docker/docker/pkg/mount/mount.go deleted file mode 100644 index 66ac4bf..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mount.go +++ /dev/null @@ -1,74 +0,0 @@ -package mount - -import ( - "time" -) - -// GetMounts retrieves a list of mounts for the current running process. -func GetMounts() ([]*Info, error) { - return parseMountTable() -} - -// Mounted determines if a specified mountpoint has been mounted. -// On Linux it looks at /proc/self/mountinfo and on Solaris at mnttab. -func Mounted(mountpoint string) (bool, error) { - entries, err := parseMountTable() - if err != nil { - return false, err - } - - // Search the table for the mountpoint - for _, e := range entries { - if e.Mountpoint == mountpoint { - return true, nil - } - } - return false, nil -} - -// Mount will mount filesystem according to the specified configuration, on the -// condition that the target path is *not* already mounted. Options must be -// specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See -// flags.go for supported option flags. -func Mount(device, target, mType, options string) error { - flag, _ := parseOptions(options) - if flag&REMOUNT != REMOUNT { - if mounted, err := Mounted(target); err != nil || mounted { - return err - } - } - return ForceMount(device, target, mType, options) -} - -// ForceMount will mount a filesystem according to the specified configuration, -// *regardless* if the target path is not already mounted. Options must be -// specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See -// flags.go for supported option flags. -func ForceMount(device, target, mType, options string) error { - flag, data := parseOptions(options) - if err := mount(device, target, mType, uintptr(flag), data); err != nil { - return err - } - return nil -} - -// Unmount will unmount the target filesystem, so long as it is mounted. -func Unmount(target string) error { - if mounted, err := Mounted(target); err != nil || !mounted { - return err - } - return ForceUnmount(target) -} - -// ForceUnmount will force an unmount of the target filesystem, regardless if -// it is mounted or not. -func ForceUnmount(target string) (err error) { - // Simple retry logic for unmount - for i := 0; i < 10; i++ { - if err = unmount(target, 0); err == nil { - return nil - } - time.Sleep(100 * time.Millisecond) - } - return -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mount_unix_test.go b/vendor/github.com/docker/docker/pkg/mount/mount_unix_test.go deleted file mode 100644 index 253aff3..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mount_unix_test.go +++ /dev/null @@ -1,162 +0,0 @@ -// +build !windows,!solaris - -package mount - -import ( - "os" - "path" - "testing" -) - -func TestMountOptionsParsing(t *testing.T) { - options := "noatime,ro,size=10k" - - flag, data := parseOptions(options) - - if data != "size=10k" { - t.Fatalf("Expected size=10 got %s", data) - } - - expectedFlag := NOATIME | RDONLY - - if flag != expectedFlag { - t.Fatalf("Expected %d got %d", expectedFlag, flag) - } -} - -func TestMounted(t *testing.T) { - tmp := path.Join(os.TempDir(), "mount-tests") - if err := os.MkdirAll(tmp, 0777); err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - - var ( - sourceDir = path.Join(tmp, "source") - targetDir = path.Join(tmp, "target") - sourcePath = path.Join(sourceDir, "file.txt") - targetPath = path.Join(targetDir, "file.txt") - ) - - os.Mkdir(sourceDir, 0777) - os.Mkdir(targetDir, 0777) - - f, err := os.Create(sourcePath) - if err != nil { - t.Fatal(err) - } - f.WriteString("hello") - f.Close() - - f, err = os.Create(targetPath) - if err != nil { - t.Fatal(err) - } - f.Close() - - if err := Mount(sourceDir, targetDir, "none", "bind,rw"); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(targetDir); err != nil { - t.Fatal(err) - } - }() - - mounted, err := Mounted(targetDir) - if err != nil { - t.Fatal(err) - } - if !mounted { - t.Fatalf("Expected %s to be mounted", targetDir) - } - if _, err := os.Stat(targetDir); err != nil { - t.Fatal(err) - } -} - -func TestMountReadonly(t *testing.T) { - tmp := path.Join(os.TempDir(), "mount-tests") - if err := os.MkdirAll(tmp, 0777); err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - - var ( - sourceDir = path.Join(tmp, "source") - targetDir = path.Join(tmp, "target") - sourcePath = path.Join(sourceDir, "file.txt") - targetPath = path.Join(targetDir, "file.txt") - ) - - os.Mkdir(sourceDir, 0777) - os.Mkdir(targetDir, 0777) - - f, err := os.Create(sourcePath) - if err != nil { - t.Fatal(err) - } - f.WriteString("hello") - f.Close() - - f, err = os.Create(targetPath) - if err != nil { - t.Fatal(err) - } - f.Close() - - if err := Mount(sourceDir, targetDir, "none", "bind,ro"); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(targetDir); err != nil { - t.Fatal(err) - } - }() - - f, err = os.OpenFile(targetPath, os.O_RDWR, 0777) - if err == nil { - t.Fatal("Should not be able to open a ro file as rw") - } -} - -func TestGetMounts(t *testing.T) { - mounts, err := GetMounts() - if err != nil { - t.Fatal(err) - } - - root := false - for _, entry := range mounts { - if entry.Mountpoint == "/" { - root = true - } - } - - if !root { - t.Fatal("/ should be mounted at least") - } -} - -func TestMergeTmpfsOptions(t *testing.T) { - options := []string{"noatime", "ro", "size=10k", "defaults", "atime", "defaults", "rw", "rprivate", "size=1024k", "slave"} - expected := []string{"atime", "rw", "size=1024k", "slave"} - merged, err := MergeTmpfsOptions(options) - if err != nil { - t.Fatal(err) - } - if len(expected) != len(merged) { - t.Fatalf("Expected %s got %s", expected, merged) - } - for index := range merged { - if merged[index] != expected[index] { - t.Fatalf("Expected %s for the %dth option, got %s", expected, index, merged) - } - } - - options = []string{"noatime", "ro", "size=10k", "atime", "rw", "rprivate", "size=1024k", "slave", "size"} - _, err = MergeTmpfsOptions(options) - if err == nil { - t.Fatal("Expected error got nil") - } -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mounter_freebsd.go b/vendor/github.com/docker/docker/pkg/mount/mounter_freebsd.go deleted file mode 100644 index bb870e6..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mounter_freebsd.go +++ /dev/null @@ -1,59 +0,0 @@ -package mount - -/* -#include -#include -#include -#include -#include -#include -*/ -import "C" - -import ( - "fmt" - "strings" - "syscall" - "unsafe" -) - -func allocateIOVecs(options []string) []C.struct_iovec { - out := make([]C.struct_iovec, len(options)) - for i, option := range options { - out[i].iov_base = unsafe.Pointer(C.CString(option)) - out[i].iov_len = C.size_t(len(option) + 1) - } - return out -} - -func mount(device, target, mType string, flag uintptr, data string) error { - isNullFS := false - - xs := strings.Split(data, ",") - for _, x := range xs { - if x == "bind" { - isNullFS = true - } - } - - options := []string{"fspath", target} - if isNullFS { - options = append(options, "fstype", "nullfs", "target", device) - } else { - options = append(options, "fstype", mType, "from", device) - } - rawOptions := allocateIOVecs(options) - for _, rawOption := range rawOptions { - defer C.free(rawOption.iov_base) - } - - if errno := C.nmount(&rawOptions[0], C.uint(len(options)), C.int(flag)); errno != 0 { - reason := C.GoString(C.strerror(*C.__error())) - return fmt.Errorf("Failed to call nmount: %s", reason) - } - return nil -} - -func unmount(target string, flag int) error { - return syscall.Unmount(target, flag) -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mounter_linux.go b/vendor/github.com/docker/docker/pkg/mount/mounter_linux.go deleted file mode 100644 index dd4280c..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mounter_linux.go +++ /dev/null @@ -1,21 +0,0 @@ -package mount - -import ( - "syscall" -) - -func mount(device, target, mType string, flag uintptr, data string) error { - if err := syscall.Mount(device, target, mType, flag, data); err != nil { - return err - } - - // If we have a bind mount or remount, remount... - if flag&syscall.MS_BIND == syscall.MS_BIND && flag&syscall.MS_RDONLY == syscall.MS_RDONLY { - return syscall.Mount(device, target, mType, flag|syscall.MS_REMOUNT, data) - } - return nil -} - -func unmount(target string, flag int) error { - return syscall.Unmount(target, flag) -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mounter_solaris.go b/vendor/github.com/docker/docker/pkg/mount/mounter_solaris.go deleted file mode 100644 index c684aa8..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mounter_solaris.go +++ /dev/null @@ -1,33 +0,0 @@ -// +build solaris,cgo - -package mount - -import ( - "golang.org/x/sys/unix" - "unsafe" -) - -// #include -// #include -// #include -// int Mount(const char *spec, const char *dir, int mflag, -// char *fstype, char *dataptr, int datalen, char *optptr, int optlen) { -// return mount(spec, dir, mflag, fstype, dataptr, datalen, optptr, optlen); -// } -import "C" - -func mount(device, target, mType string, flag uintptr, data string) error { - spec := C.CString(device) - dir := C.CString(target) - fstype := C.CString(mType) - _, err := C.Mount(spec, dir, C.int(flag), fstype, nil, 0, nil, 0) - C.free(unsafe.Pointer(spec)) - C.free(unsafe.Pointer(dir)) - C.free(unsafe.Pointer(fstype)) - return err -} - -func unmount(target string, flag int) error { - err := unix.Unmount(target, flag) - return err -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mounter_unsupported.go b/vendor/github.com/docker/docker/pkg/mount/mounter_unsupported.go deleted file mode 100644 index a2a3bb4..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mounter_unsupported.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !linux,!freebsd,!solaris freebsd,!cgo solaris,!cgo - -package mount - -func mount(device, target, mType string, flag uintptr, data string) error { - panic("Not implemented") -} - -func unmount(target string, flag int) error { - panic("Not implemented") -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mountinfo.go b/vendor/github.com/docker/docker/pkg/mount/mountinfo.go deleted file mode 100644 index e3fc353..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mountinfo.go +++ /dev/null @@ -1,40 +0,0 @@ -package mount - -// Info reveals information about a particular mounted filesystem. This -// struct is populated from the content in the /proc//mountinfo file. -type Info struct { - // ID is a unique identifier of the mount (may be reused after umount). - ID int - - // Parent indicates the ID of the mount parent (or of self for the top of the - // mount tree). - Parent int - - // Major indicates one half of the device ID which identifies the device class. - Major int - - // Minor indicates one half of the device ID which identifies a specific - // instance of device. - Minor int - - // Root of the mount within the filesystem. - Root string - - // Mountpoint indicates the mount point relative to the process's root. - Mountpoint string - - // Opts represents mount-specific options. - Opts string - - // Optional represents optional fields. - Optional string - - // Fstype indicates the type of filesystem, such as EXT3. - Fstype string - - // Source indicates filesystem specific information or "none". - Source string - - // VfsOpts represents per super block options. - VfsOpts string -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mountinfo_freebsd.go b/vendor/github.com/docker/docker/pkg/mount/mountinfo_freebsd.go deleted file mode 100644 index 4f32edc..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mountinfo_freebsd.go +++ /dev/null @@ -1,41 +0,0 @@ -package mount - -/* -#include -#include -#include -*/ -import "C" - -import ( - "fmt" - "reflect" - "unsafe" -) - -// Parse /proc/self/mountinfo because comparing Dev and ino does not work from -// bind mounts. -func parseMountTable() ([]*Info, error) { - var rawEntries *C.struct_statfs - - count := int(C.getmntinfo(&rawEntries, C.MNT_WAIT)) - if count == 0 { - return nil, fmt.Errorf("Failed to call getmntinfo") - } - - var entries []C.struct_statfs - header := (*reflect.SliceHeader)(unsafe.Pointer(&entries)) - header.Cap = count - header.Len = count - header.Data = uintptr(unsafe.Pointer(rawEntries)) - - var out []*Info - for _, entry := range entries { - var mountinfo Info - mountinfo.Mountpoint = C.GoString(&entry.f_mntonname[0]) - mountinfo.Source = C.GoString(&entry.f_mntfromname[0]) - mountinfo.Fstype = C.GoString(&entry.f_fstypename[0]) - out = append(out, &mountinfo) - } - return out, nil -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mountinfo_linux.go b/vendor/github.com/docker/docker/pkg/mount/mountinfo_linux.go deleted file mode 100644 index be69fee..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mountinfo_linux.go +++ /dev/null @@ -1,95 +0,0 @@ -// +build linux - -package mount - -import ( - "bufio" - "fmt" - "io" - "os" - "strings" -) - -const ( - /* 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue - (1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11) - - (1) mount ID: unique identifier of the mount (may be reused after umount) - (2) parent ID: ID of parent (or of self for the top of the mount tree) - (3) major:minor: value of st_dev for files on filesystem - (4) root: root of the mount within the filesystem - (5) mount point: mount point relative to the process's root - (6) mount options: per mount options - (7) optional fields: zero or more fields of the form "tag[:value]" - (8) separator: marks the end of the optional fields - (9) filesystem type: name of filesystem of the form "type[.subtype]" - (10) mount source: filesystem specific information or "none" - (11) super options: per super block options*/ - mountinfoFormat = "%d %d %d:%d %s %s %s %s" -) - -// Parse /proc/self/mountinfo because comparing Dev and ino does not work from -// bind mounts -func parseMountTable() ([]*Info, error) { - f, err := os.Open("/proc/self/mountinfo") - if err != nil { - return nil, err - } - defer f.Close() - - return parseInfoFile(f) -} - -func parseInfoFile(r io.Reader) ([]*Info, error) { - var ( - s = bufio.NewScanner(r) - out = []*Info{} - ) - - for s.Scan() { - if err := s.Err(); err != nil { - return nil, err - } - - var ( - p = &Info{} - text = s.Text() - optionalFields string - ) - - if _, err := fmt.Sscanf(text, mountinfoFormat, - &p.ID, &p.Parent, &p.Major, &p.Minor, - &p.Root, &p.Mountpoint, &p.Opts, &optionalFields); err != nil { - return nil, fmt.Errorf("Scanning '%s' failed: %s", text, err) - } - // Safe as mountinfo encodes mountpoints with spaces as \040. - index := strings.Index(text, " - ") - postSeparatorFields := strings.Fields(text[index+3:]) - if len(postSeparatorFields) < 3 { - return nil, fmt.Errorf("Error found less than 3 fields post '-' in %q", text) - } - - if optionalFields != "-" { - p.Optional = optionalFields - } - - p.Fstype = postSeparatorFields[0] - p.Source = postSeparatorFields[1] - p.VfsOpts = strings.Join(postSeparatorFields[2:], " ") - out = append(out, p) - } - return out, nil -} - -// PidMountInfo collects the mounts for a specific process ID. If the process -// ID is unknown, it is better to use `GetMounts` which will inspect -// "/proc/self/mountinfo" instead. -func PidMountInfo(pid int) ([]*Info, error) { - f, err := os.Open(fmt.Sprintf("/proc/%d/mountinfo", pid)) - if err != nil { - return nil, err - } - defer f.Close() - - return parseInfoFile(f) -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mountinfo_linux_test.go b/vendor/github.com/docker/docker/pkg/mount/mountinfo_linux_test.go deleted file mode 100644 index bd100e1..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mountinfo_linux_test.go +++ /dev/null @@ -1,476 +0,0 @@ -// +build linux - -package mount - -import ( - "bytes" - "testing" -) - -const ( - fedoraMountinfo = `15 35 0:3 / /proc rw,nosuid,nodev,noexec,relatime shared:5 - proc proc rw - 16 35 0:14 / /sys rw,nosuid,nodev,noexec,relatime shared:6 - sysfs sysfs rw,seclabel - 17 35 0:5 / /dev rw,nosuid shared:2 - devtmpfs devtmpfs rw,seclabel,size=8056484k,nr_inodes=2014121,mode=755 - 18 16 0:15 / /sys/kernel/security rw,nosuid,nodev,noexec,relatime shared:7 - securityfs securityfs rw - 19 16 0:13 / /sys/fs/selinux rw,relatime shared:8 - selinuxfs selinuxfs rw - 20 17 0:16 / /dev/shm rw,nosuid,nodev shared:3 - tmpfs tmpfs rw,seclabel - 21 17 0:10 / /dev/pts rw,nosuid,noexec,relatime shared:4 - devpts devpts rw,seclabel,gid=5,mode=620,ptmxmode=000 - 22 35 0:17 / /run rw,nosuid,nodev shared:21 - tmpfs tmpfs rw,seclabel,mode=755 - 23 16 0:18 / /sys/fs/cgroup rw,nosuid,nodev,noexec shared:9 - tmpfs tmpfs rw,seclabel,mode=755 - 24 23 0:19 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime shared:10 - cgroup cgroup rw,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd - 25 16 0:20 / /sys/fs/pstore rw,nosuid,nodev,noexec,relatime shared:20 - pstore pstore rw - 26 23 0:21 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:11 - cgroup cgroup rw,cpuset,clone_children - 27 23 0:22 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:12 - cgroup cgroup rw,cpuacct,cpu,clone_children - 28 23 0:23 / /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:13 - cgroup cgroup rw,memory,clone_children - 29 23 0:24 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime shared:14 - cgroup cgroup rw,devices,clone_children - 30 23 0:25 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:15 - cgroup cgroup rw,freezer,clone_children - 31 23 0:26 / /sys/fs/cgroup/net_cls rw,nosuid,nodev,noexec,relatime shared:16 - cgroup cgroup rw,net_cls,clone_children - 32 23 0:27 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:17 - cgroup cgroup rw,blkio,clone_children - 33 23 0:28 / /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime shared:18 - cgroup cgroup rw,perf_event,clone_children - 34 23 0:29 / /sys/fs/cgroup/hugetlb rw,nosuid,nodev,noexec,relatime shared:19 - cgroup cgroup rw,hugetlb,clone_children - 35 1 253:2 / / rw,relatime shared:1 - ext4 /dev/mapper/ssd-root--f20 rw,seclabel,data=ordered - 36 15 0:30 / /proc/sys/fs/binfmt_misc rw,relatime shared:22 - autofs systemd-1 rw,fd=38,pgrp=1,timeout=300,minproto=5,maxproto=5,direct - 37 17 0:12 / /dev/mqueue rw,relatime shared:23 - mqueue mqueue rw,seclabel - 38 35 0:31 / /tmp rw shared:24 - tmpfs tmpfs rw,seclabel - 39 17 0:32 / /dev/hugepages rw,relatime shared:25 - hugetlbfs hugetlbfs rw,seclabel - 40 16 0:7 / /sys/kernel/debug rw,relatime shared:26 - debugfs debugfs rw - 41 16 0:33 / /sys/kernel/config rw,relatime shared:27 - configfs configfs rw - 42 35 0:34 / /var/lib/nfs/rpc_pipefs rw,relatime shared:28 - rpc_pipefs sunrpc rw - 43 15 0:35 / /proc/fs/nfsd rw,relatime shared:29 - nfsd sunrpc rw - 45 35 8:17 / /boot rw,relatime shared:30 - ext4 /dev/sdb1 rw,seclabel,data=ordered - 46 35 253:4 / /home rw,relatime shared:31 - ext4 /dev/mapper/ssd-home rw,seclabel,data=ordered - 47 35 253:5 / /var/lib/libvirt/images rw,noatime,nodiratime shared:32 - ext4 /dev/mapper/ssd-virt rw,seclabel,discard,data=ordered - 48 35 253:12 / /mnt/old rw,relatime shared:33 - ext4 /dev/mapper/HelpDeskRHEL6-FedoraRoot rw,seclabel,data=ordered - 121 22 0:36 / /run/user/1000/gvfs rw,nosuid,nodev,relatime shared:104 - fuse.gvfsd-fuse gvfsd-fuse rw,user_id=1000,group_id=1000 - 124 16 0:37 / /sys/fs/fuse/connections rw,relatime shared:107 - fusectl fusectl rw - 165 38 253:3 / /tmp/mnt rw,relatime shared:147 - ext4 /dev/mapper/ssd-root rw,seclabel,data=ordered - 167 35 253:15 / /var/lib/docker/devicemapper/mnt/aae4076022f0e2b80a2afbf8fc6df450c52080191fcef7fb679a73e6f073e5c2 rw,relatime shared:149 - ext4 /dev/mapper/docker-253:2-425882-aae4076022f0e2b80a2afbf8fc6df450c52080191fcef7fb679a73e6f073e5c2 rw,seclabel,discard,stripe=16,data=ordered - 171 35 253:16 / /var/lib/docker/devicemapper/mnt/c71be651f114db95180e472f7871b74fa597ee70a58ccc35cb87139ddea15373 rw,relatime shared:153 - ext4 /dev/mapper/docker-253:2-425882-c71be651f114db95180e472f7871b74fa597ee70a58ccc35cb87139ddea15373 rw,seclabel,discard,stripe=16,data=ordered - 175 35 253:17 / /var/lib/docker/devicemapper/mnt/1bac6ab72862d2d5626560df6197cf12036b82e258c53d981fa29adce6f06c3c rw,relatime shared:157 - ext4 /dev/mapper/docker-253:2-425882-1bac6ab72862d2d5626560df6197cf12036b82e258c53d981fa29adce6f06c3c rw,seclabel,discard,stripe=16,data=ordered - 179 35 253:18 / /var/lib/docker/devicemapper/mnt/d710a357d77158e80d5b2c55710ae07c94e76d34d21ee7bae65ce5418f739b09 rw,relatime shared:161 - ext4 /dev/mapper/docker-253:2-425882-d710a357d77158e80d5b2c55710ae07c94e76d34d21ee7bae65ce5418f739b09 rw,seclabel,discard,stripe=16,data=ordered - 183 35 253:19 / /var/lib/docker/devicemapper/mnt/6479f52366114d5f518db6837254baab48fab39f2ac38d5099250e9a6ceae6c7 rw,relatime shared:165 - ext4 /dev/mapper/docker-253:2-425882-6479f52366114d5f518db6837254baab48fab39f2ac38d5099250e9a6ceae6c7 rw,seclabel,discard,stripe=16,data=ordered - 187 35 253:20 / /var/lib/docker/devicemapper/mnt/8d9df91c4cca5aef49eeb2725292aab324646f723a7feab56be34c2ad08268e1 rw,relatime shared:169 - ext4 /dev/mapper/docker-253:2-425882-8d9df91c4cca5aef49eeb2725292aab324646f723a7feab56be34c2ad08268e1 rw,seclabel,discard,stripe=16,data=ordered - 191 35 253:21 / /var/lib/docker/devicemapper/mnt/c8240b768603d32e920d365dc9d1dc2a6af46cd23e7ae819947f969e1b4ec661 rw,relatime shared:173 - ext4 /dev/mapper/docker-253:2-425882-c8240b768603d32e920d365dc9d1dc2a6af46cd23e7ae819947f969e1b4ec661 rw,seclabel,discard,stripe=16,data=ordered - 195 35 253:22 / /var/lib/docker/devicemapper/mnt/2eb3a01278380bbf3ed12d86ac629eaa70a4351301ee307a5cabe7b5f3b1615f rw,relatime shared:177 - ext4 /dev/mapper/docker-253:2-425882-2eb3a01278380bbf3ed12d86ac629eaa70a4351301ee307a5cabe7b5f3b1615f rw,seclabel,discard,stripe=16,data=ordered - 199 35 253:23 / /var/lib/docker/devicemapper/mnt/37a17fb7c9d9b80821235d5f2662879bd3483915f245f9b49cdaa0e38779b70b rw,relatime shared:181 - ext4 /dev/mapper/docker-253:2-425882-37a17fb7c9d9b80821235d5f2662879bd3483915f245f9b49cdaa0e38779b70b rw,seclabel,discard,stripe=16,data=ordered - 203 35 253:24 / /var/lib/docker/devicemapper/mnt/aea459ae930bf1de913e2f29428fd80ee678a1e962d4080019d9f9774331ee2b rw,relatime shared:185 - ext4 /dev/mapper/docker-253:2-425882-aea459ae930bf1de913e2f29428fd80ee678a1e962d4080019d9f9774331ee2b rw,seclabel,discard,stripe=16,data=ordered - 207 35 253:25 / /var/lib/docker/devicemapper/mnt/928ead0bc06c454bd9f269e8585aeae0a6bd697f46dc8754c2a91309bc810882 rw,relatime shared:189 - ext4 /dev/mapper/docker-253:2-425882-928ead0bc06c454bd9f269e8585aeae0a6bd697f46dc8754c2a91309bc810882 rw,seclabel,discard,stripe=16,data=ordered - 211 35 253:26 / /var/lib/docker/devicemapper/mnt/0f284d18481d671644706e7a7244cbcf63d590d634cc882cb8721821929d0420 rw,relatime shared:193 - ext4 /dev/mapper/docker-253:2-425882-0f284d18481d671644706e7a7244cbcf63d590d634cc882cb8721821929d0420 rw,seclabel,discard,stripe=16,data=ordered - 215 35 253:27 / /var/lib/docker/devicemapper/mnt/d9dd16722ab34c38db2733e23f69e8f4803ce59658250dd63e98adff95d04919 rw,relatime shared:197 - ext4 /dev/mapper/docker-253:2-425882-d9dd16722ab34c38db2733e23f69e8f4803ce59658250dd63e98adff95d04919 rw,seclabel,discard,stripe=16,data=ordered - 219 35 253:28 / /var/lib/docker/devicemapper/mnt/bc4500479f18c2c08c21ad5282e5f826a016a386177d9874c2764751c031d634 rw,relatime shared:201 - ext4 /dev/mapper/docker-253:2-425882-bc4500479f18c2c08c21ad5282e5f826a016a386177d9874c2764751c031d634 rw,seclabel,discard,stripe=16,data=ordered - 223 35 253:29 / /var/lib/docker/devicemapper/mnt/7770c8b24eb3d5cc159a065910076938910d307ab2f5d94e1dc3b24c06ee2c8a rw,relatime shared:205 - ext4 /dev/mapper/docker-253:2-425882-7770c8b24eb3d5cc159a065910076938910d307ab2f5d94e1dc3b24c06ee2c8a rw,seclabel,discard,stripe=16,data=ordered - 227 35 253:30 / /var/lib/docker/devicemapper/mnt/c280cd3d0bf0aa36b478b292279671624cceafc1a67eaa920fa1082601297adf rw,relatime shared:209 - ext4 /dev/mapper/docker-253:2-425882-c280cd3d0bf0aa36b478b292279671624cceafc1a67eaa920fa1082601297adf rw,seclabel,discard,stripe=16,data=ordered - 231 35 253:31 / /var/lib/docker/devicemapper/mnt/8b59a7d9340279f09fea67fd6ad89ddef711e9e7050eb647984f8b5ef006335f rw,relatime shared:213 - ext4 /dev/mapper/docker-253:2-425882-8b59a7d9340279f09fea67fd6ad89ddef711e9e7050eb647984f8b5ef006335f rw,seclabel,discard,stripe=16,data=ordered - 235 35 253:32 / /var/lib/docker/devicemapper/mnt/1a28059f29eda821578b1bb27a60cc71f76f846a551abefabce6efd0146dce9f rw,relatime shared:217 - ext4 /dev/mapper/docker-253:2-425882-1a28059f29eda821578b1bb27a60cc71f76f846a551abefabce6efd0146dce9f rw,seclabel,discard,stripe=16,data=ordered - 239 35 253:33 / /var/lib/docker/devicemapper/mnt/e9aa60c60128cad1 rw,relatime shared:221 - ext4 /dev/mapper/docker-253:2-425882-e9aa60c60128cad1 rw,seclabel,discard,stripe=16,data=ordered - 243 35 253:34 / /var/lib/docker/devicemapper/mnt/5fec11304b6f4713fea7b6ccdcc1adc0a1966187f590fe25a8227428a8df275d-init rw,relatime shared:225 - ext4 /dev/mapper/docker-253:2-425882-5fec11304b6f4713fea7b6ccdcc1adc0a1966187f590fe25a8227428a8df275d-init rw,seclabel,discard,stripe=16,data=ordered - 247 35 253:35 / /var/lib/docker/devicemapper/mnt/5fec11304b6f4713fea7b6ccdcc1adc0a1966187f590fe25a8227428a8df275d rw,relatime shared:229 - ext4 /dev/mapper/docker-253:2-425882-5fec11304b6f4713fea7b6ccdcc1adc0a1966187f590fe25a8227428a8df275d rw,seclabel,discard,stripe=16,data=ordered - 31 21 0:23 / /DATA/foo_bla_bla rw,relatime - cifs //foo/BLA\040BLA\040BLA/ rw,sec=ntlm,cache=loose,unc=\\foo\BLA BLA BLA,username=my_login,domain=mydomain.com,uid=12345678,forceuid,gid=12345678,forcegid,addr=10.1.30.10,file_mode=0755,dir_mode=0755,nounix,rsize=61440,wsize=65536,actimeo=1` - - ubuntuMountInfo = `15 20 0:14 / /sys rw,nosuid,nodev,noexec,relatime - sysfs sysfs rw -16 20 0:3 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw -17 20 0:5 / /dev rw,relatime - devtmpfs udev rw,size=1015140k,nr_inodes=253785,mode=755 -18 17 0:11 / /dev/pts rw,nosuid,noexec,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=000 -19 20 0:15 / /run rw,nosuid,noexec,relatime - tmpfs tmpfs rw,size=205044k,mode=755 -20 1 253:0 / / rw,relatime - ext4 /dev/disk/by-label/DOROOT rw,errors=remount-ro,data=ordered -21 15 0:16 / /sys/fs/cgroup rw,relatime - tmpfs none rw,size=4k,mode=755 -22 15 0:17 / /sys/fs/fuse/connections rw,relatime - fusectl none rw -23 15 0:6 / /sys/kernel/debug rw,relatime - debugfs none rw -24 15 0:10 / /sys/kernel/security rw,relatime - securityfs none rw -25 19 0:18 / /run/lock rw,nosuid,nodev,noexec,relatime - tmpfs none rw,size=5120k -26 21 0:19 / /sys/fs/cgroup/cpuset rw,relatime - cgroup cgroup rw,cpuset,clone_children -27 19 0:20 / /run/shm rw,nosuid,nodev,relatime - tmpfs none rw -28 21 0:21 / /sys/fs/cgroup/cpu rw,relatime - cgroup cgroup rw,cpu -29 19 0:22 / /run/user rw,nosuid,nodev,noexec,relatime - tmpfs none rw,size=102400k,mode=755 -30 15 0:23 / /sys/fs/pstore rw,relatime - pstore none rw -31 21 0:24 / /sys/fs/cgroup/cpuacct rw,relatime - cgroup cgroup rw,cpuacct -32 21 0:25 / /sys/fs/cgroup/memory rw,relatime - cgroup cgroup rw,memory -33 21 0:26 / /sys/fs/cgroup/devices rw,relatime - cgroup cgroup rw,devices -34 21 0:27 / /sys/fs/cgroup/freezer rw,relatime - cgroup cgroup rw,freezer -35 21 0:28 / /sys/fs/cgroup/blkio rw,relatime - cgroup cgroup rw,blkio -36 21 0:29 / /sys/fs/cgroup/perf_event rw,relatime - cgroup cgroup rw,perf_event -37 21 0:30 / /sys/fs/cgroup/hugetlb rw,relatime - cgroup cgroup rw,hugetlb -38 21 0:31 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime - cgroup systemd rw,name=systemd -39 20 0:32 / /var/lib/docker/aufs/mnt/b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc rw,relatime - aufs none rw,si=caafa54fdc06525 -40 20 0:33 / /var/lib/docker/aufs/mnt/2eed44ac7ce7c75af04f088ed6cb4ce9d164801e91d78c6db65d7ef6d572bba8-init rw,relatime - aufs none rw,si=caafa54f882b525 -41 20 0:34 / /var/lib/docker/aufs/mnt/2eed44ac7ce7c75af04f088ed6cb4ce9d164801e91d78c6db65d7ef6d572bba8 rw,relatime - aufs none rw,si=caafa54f8829525 -42 20 0:35 / /var/lib/docker/aufs/mnt/16f4d7e96dd612903f425bfe856762f291ff2e36a8ecd55a2209b7d7cd81c30b rw,relatime - aufs none rw,si=caafa54f882d525 -43 20 0:36 / /var/lib/docker/aufs/mnt/63ca08b75d7438a9469a5954e003f48ffede73541f6286ce1cb4d7dd4811da7e-init rw,relatime - aufs none rw,si=caafa54f882f525 -44 20 0:37 / /var/lib/docker/aufs/mnt/63ca08b75d7438a9469a5954e003f48ffede73541f6286ce1cb4d7dd4811da7e rw,relatime - aufs none rw,si=caafa54f88ba525 -45 20 0:38 / /var/lib/docker/aufs/mnt/283f35a910233c756409313be71ecd8fcfef0df57108b8d740b61b3e88860452 rw,relatime - aufs none rw,si=caafa54f88b8525 -46 20 0:39 / /var/lib/docker/aufs/mnt/2c6c7253d4090faa3886871fb21bd660609daeb0206588c0602007f7d0f254b1-init rw,relatime - aufs none rw,si=caafa54f88be525 -47 20 0:40 / /var/lib/docker/aufs/mnt/2c6c7253d4090faa3886871fb21bd660609daeb0206588c0602007f7d0f254b1 rw,relatime - aufs none rw,si=caafa54f882c525 -48 20 0:41 / /var/lib/docker/aufs/mnt/de2b538c97d6366cc80e8658547c923ea1d042f85580df379846f36a4df7049d rw,relatime - aufs none rw,si=caafa54f85bb525 -49 20 0:42 / /var/lib/docker/aufs/mnt/94a3d8ed7c27e5b0aa71eba46c736bfb2742afda038e74f2dd6035fb28415b49-init rw,relatime - aufs none rw,si=caafa54fdc00525 -50 20 0:43 / /var/lib/docker/aufs/mnt/94a3d8ed7c27e5b0aa71eba46c736bfb2742afda038e74f2dd6035fb28415b49 rw,relatime - aufs none rw,si=caafa54fbaec525 -51 20 0:44 / /var/lib/docker/aufs/mnt/6ac1cace985c9fc9bea32234de8b36dba49bdd5e29a2972b327ff939d78a6274 rw,relatime - aufs none rw,si=caafa54f8e1a525 -52 20 0:45 / /var/lib/docker/aufs/mnt/dff147033e3a0ef061e1de1ad34256b523d4a8c1fa6bba71a0ab538e8628ff0b-init rw,relatime - aufs none rw,si=caafa54f8e1d525 -53 20 0:46 / /var/lib/docker/aufs/mnt/dff147033e3a0ef061e1de1ad34256b523d4a8c1fa6bba71a0ab538e8628ff0b rw,relatime - aufs none rw,si=caafa54f8e1b525 -54 20 0:47 / /var/lib/docker/aufs/mnt/cabb117d997f0f93519185aea58389a9762770b7496ed0b74a3e4a083fa45902 rw,relatime - aufs none rw,si=caafa54f810a525 -55 20 0:48 / /var/lib/docker/aufs/mnt/e1c8a94ffaa9d532bbbdc6ef771ce8a6c2c06757806ecaf8b68e9108fec65f33-init rw,relatime - aufs none rw,si=caafa54f8529525 -56 20 0:49 / /var/lib/docker/aufs/mnt/e1c8a94ffaa9d532bbbdc6ef771ce8a6c2c06757806ecaf8b68e9108fec65f33 rw,relatime - aufs none rw,si=caafa54f852f525 -57 20 0:50 / /var/lib/docker/aufs/mnt/16a1526fa445b84ce84f89506d219e87fa488a814063baf045d88b02f21166b3 rw,relatime - aufs none rw,si=caafa54f9e1d525 -58 20 0:51 / /var/lib/docker/aufs/mnt/57b9c92e1e368fa7dbe5079f7462e917777829caae732828b003c355fe49da9f-init rw,relatime - aufs none rw,si=caafa54f854d525 -59 20 0:52 / /var/lib/docker/aufs/mnt/57b9c92e1e368fa7dbe5079f7462e917777829caae732828b003c355fe49da9f rw,relatime - aufs none rw,si=caafa54f854e525 -60 20 0:53 / /var/lib/docker/aufs/mnt/e370c3e286bea027917baa0e4d251262681a472a87056e880dfd0513516dffd9 rw,relatime - aufs none rw,si=caafa54f840a525 -61 20 0:54 / /var/lib/docker/aufs/mnt/6b00d3b4f32b41997ec07412b5e18204f82fbe643e7122251cdeb3582abd424e-init rw,relatime - aufs none rw,si=caafa54f8408525 -62 20 0:55 / /var/lib/docker/aufs/mnt/6b00d3b4f32b41997ec07412b5e18204f82fbe643e7122251cdeb3582abd424e rw,relatime - aufs none rw,si=caafa54f8409525 -63 20 0:56 / /var/lib/docker/aufs/mnt/abd0b5ea5d355a67f911475e271924a5388ee60c27185fcd60d095afc4a09dc7 rw,relatime - aufs none rw,si=caafa54f9eb1525 -64 20 0:57 / /var/lib/docker/aufs/mnt/336222effc3f7b89867bb39ff7792ae5412c35c749f127c29159d046b6feedd2-init rw,relatime - aufs none rw,si=caafa54f85bf525 -65 20 0:58 / /var/lib/docker/aufs/mnt/336222effc3f7b89867bb39ff7792ae5412c35c749f127c29159d046b6feedd2 rw,relatime - aufs none rw,si=caafa54f85b8525 -66 20 0:59 / /var/lib/docker/aufs/mnt/912e1bf28b80a09644503924a8a1a4fb8ed10b808ca847bda27a369919aa52fa rw,relatime - aufs none rw,si=caafa54fbaea525 -67 20 0:60 / /var/lib/docker/aufs/mnt/386f722875013b4a875118367abc783fc6617a3cb7cf08b2b4dcf550b4b9c576-init rw,relatime - aufs none rw,si=caafa54f8472525 -68 20 0:61 / /var/lib/docker/aufs/mnt/386f722875013b4a875118367abc783fc6617a3cb7cf08b2b4dcf550b4b9c576 rw,relatime - aufs none rw,si=caafa54f8474525 -69 20 0:62 / /var/lib/docker/aufs/mnt/5aaebb79ef3097dfca377889aeb61a0c9d5e3795117d2b08d0751473c671dfb2 rw,relatime - aufs none rw,si=caafa54f8c5e525 -70 20 0:63 / /var/lib/docker/aufs/mnt/5ba3e493279d01277d583600b81c7c079e691b73c3a2bdea8e4b12a35a418be2-init rw,relatime - aufs none rw,si=caafa54f8c3b525 -71 20 0:64 / /var/lib/docker/aufs/mnt/5ba3e493279d01277d583600b81c7c079e691b73c3a2bdea8e4b12a35a418be2 rw,relatime - aufs none rw,si=caafa54f8c3d525 -72 20 0:65 / /var/lib/docker/aufs/mnt/2777f0763da4de93f8bebbe1595cc77f739806a158657b033eca06f827b6028a rw,relatime - aufs none rw,si=caafa54f8c3e525 -73 20 0:66 / /var/lib/docker/aufs/mnt/5d7445562acf73c6f0ae34c3dd0921d7457de1ba92a587d9e06a44fa209eeb3e-init rw,relatime - aufs none rw,si=caafa54f8c39525 -74 20 0:67 / /var/lib/docker/aufs/mnt/5d7445562acf73c6f0ae34c3dd0921d7457de1ba92a587d9e06a44fa209eeb3e rw,relatime - aufs none rw,si=caafa54f854f525 -75 20 0:68 / /var/lib/docker/aufs/mnt/06400b526ec18b66639c96efc41a84f4ae0b117cb28dafd56be420651b4084a0 rw,relatime - aufs none rw,si=caafa54f840b525 -76 20 0:69 / /var/lib/docker/aufs/mnt/e051d45ec42d8e3e1cc57bb39871a40de486dc123522e9c067fbf2ca6a357785-init rw,relatime - aufs none rw,si=caafa54fdddf525 -77 20 0:70 / /var/lib/docker/aufs/mnt/e051d45ec42d8e3e1cc57bb39871a40de486dc123522e9c067fbf2ca6a357785 rw,relatime - aufs none rw,si=caafa54f854b525 -78 20 0:71 / /var/lib/docker/aufs/mnt/1ff414fa93fd61ec81b0ab7b365a841ff6545accae03cceac702833aaeaf718f rw,relatime - aufs none rw,si=caafa54f8d85525 -79 20 0:72 / /var/lib/docker/aufs/mnt/c661b2f871dd5360e46a2aebf8f970f6d39a2ff64e06979aa0361227c88128b8-init rw,relatime - aufs none rw,si=caafa54f8da3525 -80 20 0:73 / /var/lib/docker/aufs/mnt/c661b2f871dd5360e46a2aebf8f970f6d39a2ff64e06979aa0361227c88128b8 rw,relatime - aufs none rw,si=caafa54f8da2525 -81 20 0:74 / /var/lib/docker/aufs/mnt/b68b1d4fe4d30016c552398e78b379a39f651661d8e1fa5f2460c24a5e723420 rw,relatime - aufs none rw,si=caafa54f8d81525 -82 20 0:75 / /var/lib/docker/aufs/mnt/c5c5979c936cd0153a4c626fa9d69ce4fce7d924cc74fa68b025d2f585031739-init rw,relatime - aufs none rw,si=caafa54f8da1525 -83 20 0:76 / /var/lib/docker/aufs/mnt/c5c5979c936cd0153a4c626fa9d69ce4fce7d924cc74fa68b025d2f585031739 rw,relatime - aufs none rw,si=caafa54f8da0525 -84 20 0:77 / /var/lib/docker/aufs/mnt/53e10b0329afc0e0d3322d31efaed4064139dc7027fe6ae445cffd7104bcc94f rw,relatime - aufs none rw,si=caafa54f8c35525 -85 20 0:78 / /var/lib/docker/aufs/mnt/3bfafd09ff2603e2165efacc2215c1f51afabba6c42d04a68cc2df0e8cc31494-init rw,relatime - aufs none rw,si=caafa54f8db8525 -86 20 0:79 / /var/lib/docker/aufs/mnt/3bfafd09ff2603e2165efacc2215c1f51afabba6c42d04a68cc2df0e8cc31494 rw,relatime - aufs none rw,si=caafa54f8dba525 -87 20 0:80 / /var/lib/docker/aufs/mnt/90fdd2c03eeaf65311f88f4200e18aef6d2772482712d9aea01cd793c64781b5 rw,relatime - aufs none rw,si=caafa54f8315525 -88 20 0:81 / /var/lib/docker/aufs/mnt/7bdf2591c06c154ceb23f5e74b1d03b18fbf6fe96e35fbf539b82d446922442f-init rw,relatime - aufs none rw,si=caafa54f8fc6525 -89 20 0:82 / /var/lib/docker/aufs/mnt/7bdf2591c06c154ceb23f5e74b1d03b18fbf6fe96e35fbf539b82d446922442f rw,relatime - aufs none rw,si=caafa54f8468525 -90 20 0:83 / /var/lib/docker/aufs/mnt/8cf9a993f50f3305abad3da268c0fc44ff78a1e7bba595ef9de963497496c3f9 rw,relatime - aufs none rw,si=caafa54f8c59525 -91 20 0:84 / /var/lib/docker/aufs/mnt/ecc896fd74b21840a8d35e8316b92a08b1b9c83d722a12acff847e9f0ff17173-init rw,relatime - aufs none rw,si=caafa54f846a525 -92 20 0:85 / /var/lib/docker/aufs/mnt/ecc896fd74b21840a8d35e8316b92a08b1b9c83d722a12acff847e9f0ff17173 rw,relatime - aufs none rw,si=caafa54f846b525 -93 20 0:86 / /var/lib/docker/aufs/mnt/d8c8288ec920439a48b5796bab5883ee47a019240da65e8d8f33400c31bac5df rw,relatime - aufs none rw,si=caafa54f8dbf525 -94 20 0:87 / /var/lib/docker/aufs/mnt/ecba66710bcd03199b9398e46c005cd6b68d0266ec81dc8b722a29cc417997c6-init rw,relatime - aufs none rw,si=caafa54f810f525 -95 20 0:88 / /var/lib/docker/aufs/mnt/ecba66710bcd03199b9398e46c005cd6b68d0266ec81dc8b722a29cc417997c6 rw,relatime - aufs none rw,si=caafa54fbae9525 -96 20 0:89 / /var/lib/docker/aufs/mnt/befc1c67600df449dddbe796c0d06da7caff1d2bbff64cde1f0ba82d224996b5 rw,relatime - aufs none rw,si=caafa54f8dab525 -97 20 0:90 / /var/lib/docker/aufs/mnt/c9f470e73d2742629cdc4084a1b2c1a8302914f2aa0d0ec4542371df9a050562-init rw,relatime - aufs none rw,si=caafa54fdc02525 -98 20 0:91 / /var/lib/docker/aufs/mnt/c9f470e73d2742629cdc4084a1b2c1a8302914f2aa0d0ec4542371df9a050562 rw,relatime - aufs none rw,si=caafa54f9eb0525 -99 20 0:92 / /var/lib/docker/aufs/mnt/2a31f10029f04ff9d4381167a9b739609853d7220d55a56cb654779a700ee246 rw,relatime - aufs none rw,si=caafa54f8c37525 -100 20 0:93 / /var/lib/docker/aufs/mnt/8c4261b8e3e4b21ebba60389bd64b6261217e7e6b9fd09e201d5a7f6760f6927-init rw,relatime - aufs none rw,si=caafa54fd173525 -101 20 0:94 / /var/lib/docker/aufs/mnt/8c4261b8e3e4b21ebba60389bd64b6261217e7e6b9fd09e201d5a7f6760f6927 rw,relatime - aufs none rw,si=caafa54f8108525 -102 20 0:95 / /var/lib/docker/aufs/mnt/eaa0f57403a3dc685268f91df3fbcd7a8423cee50e1a9ee5c3e1688d9d676bb4 rw,relatime - aufs none rw,si=caafa54f852d525 -103 20 0:96 / /var/lib/docker/aufs/mnt/9cfe69a2cbffd9bfc7f396d4754f6fe5cc457ef417b277797be3762dfe955a6b-init rw,relatime - aufs none rw,si=caafa54f8d80525 -104 20 0:97 / /var/lib/docker/aufs/mnt/9cfe69a2cbffd9bfc7f396d4754f6fe5cc457ef417b277797be3762dfe955a6b rw,relatime - aufs none rw,si=caafa54f8fc3525 -105 20 0:98 / /var/lib/docker/aufs/mnt/d1b322ae17613c6adee84e709641a9244ac56675244a89a64dc0075075fcbb83 rw,relatime - aufs none rw,si=caafa54f8c58525 -106 20 0:99 / /var/lib/docker/aufs/mnt/d46c2a8e9da7e91ab34fd9c192851c246a4e770a46720bda09e55c7554b9dbbd-init rw,relatime - aufs none rw,si=caafa54f8c63525 -107 20 0:100 / /var/lib/docker/aufs/mnt/d46c2a8e9da7e91ab34fd9c192851c246a4e770a46720bda09e55c7554b9dbbd rw,relatime - aufs none rw,si=caafa54f8c67525 -108 20 0:101 / /var/lib/docker/aufs/mnt/bc9d2a264158f83a617a069bf17cbbf2a2ba453db7d3951d9dc63cc1558b1c2b rw,relatime - aufs none rw,si=caafa54f8dbe525 -109 20 0:102 / /var/lib/docker/aufs/mnt/9e6abb8d72bbeb4d5cf24b96018528015ba830ce42b4859965bd482cbd034e99-init rw,relatime - aufs none rw,si=caafa54f9e0d525 -110 20 0:103 / /var/lib/docker/aufs/mnt/9e6abb8d72bbeb4d5cf24b96018528015ba830ce42b4859965bd482cbd034e99 rw,relatime - aufs none rw,si=caafa54f9e1b525 -111 20 0:104 / /var/lib/docker/aufs/mnt/d4dca7b02569c732e740071e1c654d4ad282de5c41edb619af1f0aafa618be26 rw,relatime - aufs none rw,si=caafa54f8dae525 -112 20 0:105 / /var/lib/docker/aufs/mnt/fea63da40fa1c5ffbad430dde0bc64a8fc2edab09a051fff55b673c40a08f6b7-init rw,relatime - aufs none rw,si=caafa54f8c5c525 -113 20 0:106 / /var/lib/docker/aufs/mnt/fea63da40fa1c5ffbad430dde0bc64a8fc2edab09a051fff55b673c40a08f6b7 rw,relatime - aufs none rw,si=caafa54fd172525 -114 20 0:107 / /var/lib/docker/aufs/mnt/e60c57499c0b198a6734f77f660cdbbd950a5b78aa23f470ca4f0cfcc376abef rw,relatime - aufs none rw,si=caafa54909c4525 -115 20 0:108 / /var/lib/docker/aufs/mnt/099c78e7ccd9c8717471bb1bbfff838c0a9913321ba2f214fbeaf92c678e5b35-init rw,relatime - aufs none rw,si=caafa54909c3525 -116 20 0:109 / /var/lib/docker/aufs/mnt/099c78e7ccd9c8717471bb1bbfff838c0a9913321ba2f214fbeaf92c678e5b35 rw,relatime - aufs none rw,si=caafa54909c7525 -117 20 0:110 / /var/lib/docker/aufs/mnt/2997be666d58b9e71469759bcb8bd9608dad0e533a1a7570a896919ba3388825 rw,relatime - aufs none rw,si=caafa54f8557525 -118 20 0:111 / /var/lib/docker/aufs/mnt/730694eff438ef20569df38dfb38a920969d7ff2170cc9aa7cb32a7ed8147a93-init rw,relatime - aufs none rw,si=caafa54c6e88525 -119 20 0:112 / /var/lib/docker/aufs/mnt/730694eff438ef20569df38dfb38a920969d7ff2170cc9aa7cb32a7ed8147a93 rw,relatime - aufs none rw,si=caafa54c6e8e525 -120 20 0:113 / /var/lib/docker/aufs/mnt/a672a1e2f2f051f6e19ed1dfbe80860a2d774174c49f7c476695f5dd1d5b2f67 rw,relatime - aufs none rw,si=caafa54c6e15525 -121 20 0:114 / /var/lib/docker/aufs/mnt/aba3570e17859f76cf29d282d0d150659c6bd80780fdc52a465ba05245c2a420-init rw,relatime - aufs none rw,si=caafa54f8dad525 -122 20 0:115 / /var/lib/docker/aufs/mnt/aba3570e17859f76cf29d282d0d150659c6bd80780fdc52a465ba05245c2a420 rw,relatime - aufs none rw,si=caafa54f8d84525 -123 20 0:116 / /var/lib/docker/aufs/mnt/2abc86007aca46fb4a817a033e2a05ccacae40b78ea4b03f8ea616b9ada40e2e rw,relatime - aufs none rw,si=caafa54c6e8b525 -124 20 0:117 / /var/lib/docker/aufs/mnt/36352f27f7878e648367a135bd1ec3ed497adcb8ac13577ee892a0bd921d2374-init rw,relatime - aufs none rw,si=caafa54c6e8d525 -125 20 0:118 / /var/lib/docker/aufs/mnt/36352f27f7878e648367a135bd1ec3ed497adcb8ac13577ee892a0bd921d2374 rw,relatime - aufs none rw,si=caafa54f8c34525 -126 20 0:119 / /var/lib/docker/aufs/mnt/2f95ca1a629cea8363b829faa727dd52896d5561f2c96ddee4f697ea2fc872c2 rw,relatime - aufs none rw,si=caafa54c6e8a525 -127 20 0:120 / /var/lib/docker/aufs/mnt/f108c8291654f179ef143a3e07de2b5a34adbc0b28194a0ab17742b6db9a7fb2-init rw,relatime - aufs none rw,si=caafa54f8e19525 -128 20 0:121 / /var/lib/docker/aufs/mnt/f108c8291654f179ef143a3e07de2b5a34adbc0b28194a0ab17742b6db9a7fb2 rw,relatime - aufs none rw,si=caafa54fa8c6525 -129 20 0:122 / /var/lib/docker/aufs/mnt/c1d04dfdf8cccb3676d5a91e84e9b0781ce40623d127d038bcfbe4c761b27401 rw,relatime - aufs none rw,si=caafa54f8c30525 -130 20 0:123 / /var/lib/docker/aufs/mnt/3f4898ffd0e1239aeebf1d1412590cdb7254207fa3883663e2c40cf772e5f05a-init rw,relatime - aufs none rw,si=caafa54c6e1a525 -131 20 0:124 / /var/lib/docker/aufs/mnt/3f4898ffd0e1239aeebf1d1412590cdb7254207fa3883663e2c40cf772e5f05a rw,relatime - aufs none rw,si=caafa54c6e1c525 -132 20 0:125 / /var/lib/docker/aufs/mnt/5ae3b6fccb1539fc02d420e86f3e9637bef5b711fed2ca31a2f426c8f5deddbf rw,relatime - aufs none rw,si=caafa54c4fea525 -133 20 0:126 / /var/lib/docker/aufs/mnt/310bfaf80d57020f2e73b06aeffb0b9b0ca2f54895f88bf5e4d1529ccac58fe0-init rw,relatime - aufs none rw,si=caafa54c6e1e525 -134 20 0:127 / /var/lib/docker/aufs/mnt/310bfaf80d57020f2e73b06aeffb0b9b0ca2f54895f88bf5e4d1529ccac58fe0 rw,relatime - aufs none rw,si=caafa54fa8c0525 -135 20 0:128 / /var/lib/docker/aufs/mnt/f382bd5aaccaf2d04a59089ac7cb12ec87efd769fd0c14d623358fbfd2a3f896 rw,relatime - aufs none rw,si=caafa54c4fec525 -136 20 0:129 / /var/lib/docker/aufs/mnt/50d45e9bb2d779bc6362824085564c7578c231af5ae3b3da116acf7e17d00735-init rw,relatime - aufs none rw,si=caafa54c4fef525 -137 20 0:130 / /var/lib/docker/aufs/mnt/50d45e9bb2d779bc6362824085564c7578c231af5ae3b3da116acf7e17d00735 rw,relatime - aufs none rw,si=caafa54c4feb525 -138 20 0:131 / /var/lib/docker/aufs/mnt/a9c5ee0854dc083b6bf62b7eb1e5291aefbb10702289a446471ce73aba0d5d7d rw,relatime - aufs none rw,si=caafa54909c6525 -139 20 0:134 / /var/lib/docker/aufs/mnt/03a613e7bd5078819d1fd92df4e671c0127559a5e0b5a885cc8d5616875162f0-init rw,relatime - aufs none rw,si=caafa54804fe525 -140 20 0:135 / /var/lib/docker/aufs/mnt/03a613e7bd5078819d1fd92df4e671c0127559a5e0b5a885cc8d5616875162f0 rw,relatime - aufs none rw,si=caafa54804fa525 -141 20 0:136 / /var/lib/docker/aufs/mnt/7ec3277e5c04c907051caf9c9c35889f5fcd6463e5485971b25404566830bb70 rw,relatime - aufs none rw,si=caafa54804f9525 -142 20 0:139 / /var/lib/docker/aufs/mnt/26b5b5d71d79a5b2bfcf8bc4b2280ee829f261eb886745dd90997ed410f7e8b8-init rw,relatime - aufs none rw,si=caafa54c6ef6525 -143 20 0:140 / /var/lib/docker/aufs/mnt/26b5b5d71d79a5b2bfcf8bc4b2280ee829f261eb886745dd90997ed410f7e8b8 rw,relatime - aufs none rw,si=caafa54c6ef5525 -144 20 0:356 / /var/lib/docker/aufs/mnt/e6ecde9e2c18cd3c75f424c67b6d89685cfee0fc67abf2cb6bdc0867eb998026 rw,relatime - aufs none rw,si=caafa548068e525` - - gentooMountinfo = `15 1 8:6 / / rw,noatime,nodiratime - ext4 /dev/sda6 rw,data=ordered -16 15 0:3 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw -17 15 0:14 / /run rw,nosuid,nodev,relatime - tmpfs tmpfs rw,size=3292172k,mode=755 -18 15 0:5 / /dev rw,nosuid,relatime - devtmpfs udev rw,size=10240k,nr_inodes=4106451,mode=755 -19 18 0:12 / /dev/mqueue rw,nosuid,nodev,noexec,relatime - mqueue mqueue rw -20 18 0:10 / /dev/pts rw,nosuid,noexec,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=000 -21 18 0:15 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw -22 15 0:16 / /sys rw,nosuid,nodev,noexec,relatime - sysfs sysfs rw -23 22 0:7 / /sys/kernel/debug rw,nosuid,nodev,noexec,relatime - debugfs debugfs rw -24 22 0:17 / /sys/fs/cgroup rw,nosuid,nodev,noexec,relatime - tmpfs cgroup_root rw,size=10240k,mode=755 -25 24 0:18 / /sys/fs/cgroup/openrc rw,nosuid,nodev,noexec,relatime - cgroup openrc rw,release_agent=/lib64/rc/sh/cgroup-release-agent.sh,name=openrc -26 24 0:19 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime - cgroup cpuset rw,cpuset,clone_children -27 24 0:20 / /sys/fs/cgroup/cpu rw,nosuid,nodev,noexec,relatime - cgroup cpu rw,cpu,clone_children -28 24 0:21 / /sys/fs/cgroup/cpuacct rw,nosuid,nodev,noexec,relatime - cgroup cpuacct rw,cpuacct,clone_children -29 24 0:22 / /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime - cgroup memory rw,memory,clone_children -30 24 0:23 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime - cgroup devices rw,devices,clone_children -31 24 0:24 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime - cgroup freezer rw,freezer,clone_children -32 24 0:25 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime - cgroup blkio rw,blkio,clone_children -33 15 8:1 / /boot rw,noatime,nodiratime - vfat /dev/sda1 rw,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro -34 15 8:18 / /mnt/xfs rw,noatime,nodiratime - xfs /dev/sdb2 rw,attr2,inode64,noquota -35 15 0:26 / /tmp rw,relatime - tmpfs tmpfs rw -36 16 0:27 / /proc/sys/fs/binfmt_misc rw,nosuid,nodev,noexec,relatime - binfmt_misc binfmt_misc rw -42 15 0:33 / /var/lib/nfs/rpc_pipefs rw,relatime - rpc_pipefs rpc_pipefs rw -43 16 0:34 / /proc/fs/nfsd rw,nosuid,nodev,noexec,relatime - nfsd nfsd rw -44 15 0:35 / /home/tianon/.gvfs rw,nosuid,nodev,relatime - fuse.gvfs-fuse-daemon gvfs-fuse-daemon rw,user_id=1000,group_id=1000 -68 15 0:3336 / /var/lib/docker/aufs/mnt/3597a1a6d6298c1decc339ebb90aad6f7d6ba2e15af3131b1f85e7ee4787a0cd rw,relatime - aufs none rw,si=9b4a7640128db39c -86 68 8:6 /var/lib/docker/containers/3597a1a6d6298c1decc339ebb90aad6f7d6ba2e15af3131b1f85e7ee4787a0cd/config.env /var/lib/docker/aufs/mnt/3597a1a6d6298c1decc339ebb90aad6f7d6ba2e15af3131b1f85e7ee4787a0cd/.dockerenv rw,noatime,nodiratime - ext4 /dev/sda6 rw,data=ordered -87 68 8:6 /etc/resolv.conf /var/lib/docker/aufs/mnt/3597a1a6d6298c1decc339ebb90aad6f7d6ba2e15af3131b1f85e7ee4787a0cd/etc/resolv.conf rw,noatime,nodiratime - ext4 /dev/sda6 rw,data=ordered -88 68 8:6 /var/lib/docker/containers/3597a1a6d6298c1decc339ebb90aad6f7d6ba2e15af3131b1f85e7ee4787a0cd/hostname /var/lib/docker/aufs/mnt/3597a1a6d6298c1decc339ebb90aad6f7d6ba2e15af3131b1f85e7ee4787a0cd/etc/hostname rw,noatime,nodiratime - ext4 /dev/sda6 rw,data=ordered -89 68 8:6 /var/lib/docker/containers/3597a1a6d6298c1decc339ebb90aad6f7d6ba2e15af3131b1f85e7ee4787a0cd/hosts /var/lib/docker/aufs/mnt/3597a1a6d6298c1decc339ebb90aad6f7d6ba2e15af3131b1f85e7ee4787a0cd/etc/hosts rw,noatime,nodiratime - ext4 /dev/sda6 rw,data=ordered -38 15 0:3384 / /var/lib/docker/aufs/mnt/0292005a9292401bb5197657f2b682d97d8edcb3b72b5e390d2a680139985b55 rw,relatime - aufs none rw,si=9b4a7642b584939c -39 15 0:3385 / /var/lib/docker/aufs/mnt/59db98c889de5f71b70cfb82c40cbe47b64332f0f56042a2987a9e5df6e5e3aa rw,relatime - aufs none rw,si=9b4a7642b584e39c -40 15 0:3386 / /var/lib/docker/aufs/mnt/0545f0f2b6548eb9601d08f35a08f5a0a385407d36027a28f58e06e9f61e0278 rw,relatime - aufs none rw,si=9b4a7642b584b39c -41 15 0:3387 / /var/lib/docker/aufs/mnt/d882cfa16d1aa8fe0331a36e79be3d80b151e49f24fc39a39c3fed1735d5feb5 rw,relatime - aufs none rw,si=9b4a76453040039c -45 15 0:3388 / /var/lib/docker/aufs/mnt/055ca3befcb1626e74f5344b3398724ff05c0de0e20021683d04305c9e70a3f6 rw,relatime - aufs none rw,si=9b4a76453040739c -46 15 0:3389 / /var/lib/docker/aufs/mnt/b899e4567a351745d4285e7f1c18fdece75d877deb3041981cd290be348b7aa6 rw,relatime - aufs none rw,si=9b4a7647def4039c -47 15 0:3390 / /var/lib/docker/aufs/mnt/067ca040292c58954c5129f953219accfae0d40faca26b4d05e76ca76a998f16 rw,relatime - aufs none rw,si=9b4a7647def4239c -48 15 0:3391 / /var/lib/docker/aufs/mnt/8c995e7cb6e5082742daeea720e340b021d288d25d92e0412c03d200df308a11 rw,relatime - aufs none rw,si=9b4a764479c1639c -49 15 0:3392 / /var/lib/docker/aufs/mnt/07cc54dfae5b45300efdacdd53cc72c01b9044956a86ce7bff42d087e426096d rw,relatime - aufs none rw,si=9b4a764479c1739c -50 15 0:3393 / /var/lib/docker/aufs/mnt/0a9c95cf4c589c05b06baa79150b0cc1d8e7102759fe3ce4afaabb8247ca4f85 rw,relatime - aufs none rw,si=9b4a7644059c839c -51 15 0:3394 / /var/lib/docker/aufs/mnt/468fa98cececcf4e226e8370f18f4f848d63faf287fb8321a07f73086441a3a0 rw,relatime - aufs none rw,si=9b4a7644059ca39c -52 15 0:3395 / /var/lib/docker/aufs/mnt/0b826192231c5ce066fffb5beff4397337b5fc19a377aa7c6282c7c0ce7f111f rw,relatime - aufs none rw,si=9b4a764479c1339c -53 15 0:3396 / /var/lib/docker/aufs/mnt/93b8ba1b772fbe79709b909c43ea4b2c30d712e53548f467db1ffdc7a384f196 rw,relatime - aufs none rw,si=9b4a7640798a739c -54 15 0:3397 / /var/lib/docker/aufs/mnt/0c0d0acfb506859b12ef18cdfef9ebed0b43a611482403564224bde9149d373c rw,relatime - aufs none rw,si=9b4a7640798a039c -55 15 0:3398 / /var/lib/docker/aufs/mnt/33648c39ab6c7c74af0243d6d6a81b052e9e25ad1e04b19892eb2dde013e358b rw,relatime - aufs none rw,si=9b4a7644b439b39c -56 15 0:3399 / /var/lib/docker/aufs/mnt/0c12bea97a1c958a3c739fb148536c1c89351d48e885ecda8f0499b5cc44407e rw,relatime - aufs none rw,si=9b4a7640798a239c -57 15 0:3400 / /var/lib/docker/aufs/mnt/ed443988ce125f172d7512e84a4de2627405990fd767a16adefa8ce700c19ce8 rw,relatime - aufs none rw,si=9b4a7644c8ed339c -59 15 0:3402 / /var/lib/docker/aufs/mnt/f61612c324ff3c924d3f7a82fb00a0f8d8f73c248c41897061949e9f5ab7e3b1 rw,relatime - aufs none rw,si=9b4a76442810c39c -60 15 0:3403 / /var/lib/docker/aufs/mnt/0f1ee55c6c4e25027b80de8e64b8b6fb542b3b41aa0caab9261da75752e22bfd rw,relatime - aufs none rw,si=9b4a76442810e39c -61 15 0:3404 / /var/lib/docker/aufs/mnt/956f6cc4af5785cb3ee6963dcbca668219437d9b28f513290b1453ac64a34f97 rw,relatime - aufs none rw,si=9b4a7644303ec39c -62 15 0:3405 / /var/lib/docker/aufs/mnt/1099769158c4b4773e2569e38024e8717e400f87a002c41d8cf47cb81b051ba6 rw,relatime - aufs none rw,si=9b4a7644303ee39c -63 15 0:3406 / /var/lib/docker/aufs/mnt/11890ceb98d4442595b676085cd7b21550ab85c5df841e0fba997ff54e3d522d rw,relatime - aufs none rw,si=9b4a7644303ed39c -64 15 0:3407 / /var/lib/docker/aufs/mnt/acdb90dc378e8ed2420b43a6d291f1c789a081cd1904018780cc038fcd7aae53 rw,relatime - aufs none rw,si=9b4a76434be2139c -65 15 0:3408 / /var/lib/docker/aufs/mnt/120e716f19d4714fbe63cc1ed246204f2c1106eefebc6537ba2587d7e7711959 rw,relatime - aufs none rw,si=9b4a76434be2339c -66 15 0:3409 / /var/lib/docker/aufs/mnt/b197b7fffb61d89e0ba1c40de9a9fc0d912e778b3c1bd828cf981ff37c1963bc rw,relatime - aufs none rw,si=9b4a76434be2039c -70 15 0:3412 / /var/lib/docker/aufs/mnt/1434b69d2e1bb18a9f0b96b9cdac30132b2688f5d1379f68a39a5e120c2f93eb rw,relatime - aufs none rw,si=9b4a76434be2639c -71 15 0:3413 / /var/lib/docker/aufs/mnt/16006e83caf33ab5eb0cd6afc92ea2ee8edeff897496b0bb3ec3a75b767374b3 rw,relatime - aufs none rw,si=9b4a7644d790439c -72 15 0:3414 / /var/lib/docker/aufs/mnt/55bfa5f44e94d27f91f79ba901b118b15098449165c87abf1b53ffff147ff164 rw,relatime - aufs none rw,si=9b4a7644d790239c -73 15 0:3415 / /var/lib/docker/aufs/mnt/1912b97a07ab21ccd98a2a27bc779bf3cf364a3138afa3c3e6f7f169a3c3eab5 rw,relatime - aufs none rw,si=9b4a76441822739c -76 15 0:3418 / /var/lib/docker/aufs/mnt/1a7c3292e8879bd91ffd9282e954f643b1db5683093574c248ff14a9609f2f56 rw,relatime - aufs none rw,si=9b4a76438cb7239c -77 15 0:3419 / /var/lib/docker/aufs/mnt/bb1faaf0d076ddba82c2318305a85f490dafa4e8a8640a8db8ed657c439120cc rw,relatime - aufs none rw,si=9b4a76438cb7339c -78 15 0:3420 / /var/lib/docker/aufs/mnt/1ab869f21d2241a73ac840c7f988490313f909ac642eba71d092204fec66dd7c rw,relatime - aufs none rw,si=9b4a76438cb7639c -79 15 0:3421 / /var/lib/docker/aufs/mnt/fd7245b2cfe3890fa5f5b452260e4edf9e7fb7746532ed9d83f7a0d7dbaa610e rw,relatime - aufs none rw,si=9b4a7644bdc0139c -80 15 0:3422 / /var/lib/docker/aufs/mnt/1e5686c5301f26b9b3cd24e322c608913465cc6c5d0dcd7c5e498d1314747d61 rw,relatime - aufs none rw,si=9b4a7644bdc0639c -81 15 0:3423 / /var/lib/docker/aufs/mnt/52edf6ee6e40bfec1e9301a4d4a92ab83d144e2ae4ce5099e99df6138cb844bf rw,relatime - aufs none rw,si=9b4a7644bdc0239c -82 15 0:3424 / /var/lib/docker/aufs/mnt/1ea10fb7085d28cda4904657dff0454e52598d28e1d77e4f2965bbc3666e808f rw,relatime - aufs none rw,si=9b4a76438cb7139c -83 15 0:3425 / /var/lib/docker/aufs/mnt/9c03e98c3593946dbd4087f8d83f9ca262f4a2efdc952ce60690838b9ba6c526 rw,relatime - aufs none rw,si=9b4a76443020639c -84 15 0:3426 / /var/lib/docker/aufs/mnt/220a2344d67437602c6d2cee9a98c46be13f82c2a8063919dd2fad52bf2fb7dd rw,relatime - aufs none rw,si=9b4a76434bff339c -94 15 0:3427 / /var/lib/docker/aufs/mnt/3b32876c5b200312c50baa476ff342248e88c8ea96e6a1032cd53a88738a1cf2 rw,relatime - aufs none rw,si=9b4a76434bff139c -95 15 0:3428 / /var/lib/docker/aufs/mnt/23ee2b8b0d4ae8db6f6d1e168e2c6f79f8a18f953b09f65e0d22cc1e67a3a6fa rw,relatime - aufs none rw,si=9b4a7646c305c39c -96 15 0:3429 / /var/lib/docker/aufs/mnt/e86e6daa70b61b57945fa178222615f3c3d6bcef12c9f28e9f8623d44dc2d429 rw,relatime - aufs none rw,si=9b4a7646c305f39c -97 15 0:3430 / /var/lib/docker/aufs/mnt/2413d07623e80860bb2e9e306fbdee699afd07525785c025c591231e864aa162 rw,relatime - aufs none rw,si=9b4a76434bff039c -98 15 0:3431 / /var/lib/docker/aufs/mnt/adfd622eb22340fc80b429e5564b125668e260bf9068096c46dd59f1386a4b7d rw,relatime - aufs none rw,si=9b4a7646a7a1039c -102 15 0:3435 / /var/lib/docker/aufs/mnt/27cd92e7a91d02e2d6b44d16679a00fb6d169b19b88822891084e7fd1a84882d rw,relatime - aufs none rw,si=9b4a7646f25ec39c -103 15 0:3436 / /var/lib/docker/aufs/mnt/27dfdaf94cfbf45055c748293c37dd68d9140240bff4c646cb09216015914a88 rw,relatime - aufs none rw,si=9b4a7646732f939c -104 15 0:3437 / /var/lib/docker/aufs/mnt/5ed7524aff68dfbf0fc601cbaeac01bab14391850a973dabf3653282a627920f rw,relatime - aufs none rw,si=9b4a7646732f839c -105 15 0:3438 / /var/lib/docker/aufs/mnt/2a0d4767e536beb5785b60e071e3ac8e5e812613ab143a9627bee77d0c9ab062 rw,relatime - aufs none rw,si=9b4a7646732fe39c -106 15 0:3439 / /var/lib/docker/aufs/mnt/dea3fc045d9f4ae51ba952450b948a822cf85c39411489ca5224f6d9a8d02bad rw,relatime - aufs none rw,si=9b4a764012ad839c -107 15 0:3440 / /var/lib/docker/aufs/mnt/2d140a787160798da60cb67c21b1210054ad4dafecdcf832f015995b9aa99cfd rw,relatime - aufs none rw,si=9b4a764012add39c -108 15 0:3441 / /var/lib/docker/aufs/mnt/cb190b2a8e984475914430fbad2382e0d20b9b659f8ef83ae8d170cc672e519c rw,relatime - aufs none rw,si=9b4a76454d9c239c -109 15 0:3442 / /var/lib/docker/aufs/mnt/2f4a012d5a7ffd90256a6e9aa479054b3dddbc3c6a343f26dafbf3196890223b rw,relatime - aufs none rw,si=9b4a76454d9c439c -110 15 0:3443 / /var/lib/docker/aufs/mnt/63cc77904b80c4ffbf49cb974c5d8733dc52ad7640d3ae87554b325d7312d87f rw,relatime - aufs none rw,si=9b4a76454d9c339c -111 15 0:3444 / /var/lib/docker/aufs/mnt/30333e872c451482ea2d235ff2192e875bd234006b238ae2bdde3b91a86d7522 rw,relatime - aufs none rw,si=9b4a76422cebf39c -112 15 0:3445 / /var/lib/docker/aufs/mnt/6c54fc1125da3925cae65b5c9a98f3be55b0a2c2666082e5094a4ba71beb5bff rw,relatime - aufs none rw,si=9b4a7646dd5a439c -113 15 0:3446 / /var/lib/docker/aufs/mnt/3087d48cb01cda9d0a83a9ca301e6ea40e8593d18c4921be4794c91a420ab9a3 rw,relatime - aufs none rw,si=9b4a7646dd5a739c -114 15 0:3447 / /var/lib/docker/aufs/mnt/cc2607462a8f55b179a749b144c3fdbb50678e1a4f3065ea04e283e9b1f1d8e2 rw,relatime - aufs none rw,si=9b4a7646dd5a239c -117 15 0:3450 / /var/lib/docker/aufs/mnt/310c5e8392b29e8658a22e08d96d63936633b7e2c38e8d220047928b00a03d24 rw,relatime - aufs none rw,si=9b4a7647932d739c -118 15 0:3451 / /var/lib/docker/aufs/mnt/38a1f0029406ba9c3b6058f2f406d8a1d23c855046cf355c91d87d446fcc1460 rw,relatime - aufs none rw,si=9b4a76445abc939c -119 15 0:3452 / /var/lib/docker/aufs/mnt/42e109ab7914ae997a11ccd860fd18e4d488c50c044c3240423ce15774b8b62e rw,relatime - aufs none rw,si=9b4a76445abca39c -120 15 0:3453 / /var/lib/docker/aufs/mnt/365d832af0402d052b389c1e9c0d353b48487533d20cd4351df8e24ec4e4f9d8 rw,relatime - aufs none rw,si=9b4a7644066aa39c -121 15 0:3454 / /var/lib/docker/aufs/mnt/d3fa8a24d695b6cda9b64f96188f701963d28bef0473343f8b212df1a2cf1d2b rw,relatime - aufs none rw,si=9b4a7644066af39c -122 15 0:3455 / /var/lib/docker/aufs/mnt/37d4f491919abc49a15d0c7a7cc8383f087573525d7d288accd14f0b4af9eae0 rw,relatime - aufs none rw,si=9b4a7644066ad39c -123 15 0:3456 / /var/lib/docker/aufs/mnt/93902707fe12cbdd0068ce73f2baad4b3a299189b1b19cb5f8a2025e106ae3f5 rw,relatime - aufs none rw,si=9b4a76444445f39c -126 15 0:3459 / /var/lib/docker/aufs/mnt/3b49291670a625b9bbb329ffba99bf7fa7abff80cefef040f8b89e2b3aad4f9f rw,relatime - aufs none rw,si=9b4a7640798a339c -127 15 0:3460 / /var/lib/docker/aufs/mnt/8d9c7b943cc8f854f4d0d4ec19f7c16c13b0cc4f67a41472a072648610cecb59 rw,relatime - aufs none rw,si=9b4a76427383039c -128 15 0:3461 / /var/lib/docker/aufs/mnt/3b6c90036526c376307df71d49c9f5fce334c01b926faa6a78186842de74beac rw,relatime - aufs none rw,si=9b4a7644badd439c -130 15 0:3463 / /var/lib/docker/aufs/mnt/7b24158eeddfb5d31b7e932e406ea4899fd728344335ff8e0765e89ddeb351dd rw,relatime - aufs none rw,si=9b4a7644badd539c -131 15 0:3464 / /var/lib/docker/aufs/mnt/3ead6dd5773765c74850cf6c769f21fe65c29d622ffa712664f9f5b80364ce27 rw,relatime - aufs none rw,si=9b4a7642f469939c -132 15 0:3465 / /var/lib/docker/aufs/mnt/3f825573b29547744a37b65597a9d6d15a8350be4429b7038d126a4c9a8e178f rw,relatime - aufs none rw,si=9b4a7642f469c39c -133 15 0:3466 / /var/lib/docker/aufs/mnt/f67aaaeb3681e5dcb99a41f847087370bd1c206680cb8c7b6a9819fd6c97a331 rw,relatime - aufs none rw,si=9b4a7647cc25939c -134 15 0:3467 / /var/lib/docker/aufs/mnt/41afe6cfb3c1fc2280b869db07699da88552786e28793f0bc048a265c01bd942 rw,relatime - aufs none rw,si=9b4a7647cc25c39c -135 15 0:3468 / /var/lib/docker/aufs/mnt/b8092ea59da34a40b120e8718c3ae9fa8436996edc4fc50e4b99c72dfd81e1af rw,relatime - aufs none rw,si=9b4a76445abc439c -136 15 0:3469 / /var/lib/docker/aufs/mnt/42c69d2cc179e2684458bb8596a9da6dad182c08eae9b74d5f0e615b399f75a5 rw,relatime - aufs none rw,si=9b4a76455ddbe39c -137 15 0:3470 / /var/lib/docker/aufs/mnt/ea0871954acd2d62a211ac60e05969622044d4c74597870c4f818fbb0c56b09b rw,relatime - aufs none rw,si=9b4a76455ddbf39c -138 15 0:3471 / /var/lib/docker/aufs/mnt/4307906b275ab3fc971786b3841ae3217ac85b6756ddeb7ad4ba09cd044c2597 rw,relatime - aufs none rw,si=9b4a76455ddb839c -139 15 0:3472 / /var/lib/docker/aufs/mnt/4390b872928c53500a5035634f3421622ed6299dc1472b631fc45de9f56dc180 rw,relatime - aufs none rw,si=9b4a76402f2fd39c -140 15 0:3473 / /var/lib/docker/aufs/mnt/6bb41e78863b85e4aa7da89455314855c8c3bda64e52a583bab15dc1fa2e80c2 rw,relatime - aufs none rw,si=9b4a76402f2fa39c -141 15 0:3474 / /var/lib/docker/aufs/mnt/4444f583c2a79c66608f4673a32c9c812154f027045fbd558c2d69920c53f835 rw,relatime - aufs none rw,si=9b4a764479dbd39c -142 15 0:3475 / /var/lib/docker/aufs/mnt/6f11883af4a05ea362e0c54df89058da4859f977efd07b6f539e1f55c1d2a668 rw,relatime - aufs none rw,si=9b4a76402f30b39c -143 15 0:3476 / /var/lib/docker/aufs/mnt/453490dd32e7c2e9ef906f995d8fb3c2753923d1a5e0ba3fd3296e2e4dc238e7 rw,relatime - aufs none rw,si=9b4a76402f30c39c -144 15 0:3477 / /var/lib/docker/aufs/mnt/45e5945735ee102b5e891c91650c57ec4b52bb53017d68f02d50ea8a6e230610 rw,relatime - aufs none rw,si=9b4a76423260739c -147 15 0:3480 / /var/lib/docker/aufs/mnt/4727a64a5553a1125f315b96bed10d3073d6988225a292cce732617c925b56ab rw,relatime - aufs none rw,si=9b4a76443030339c -150 15 0:3483 / /var/lib/docker/aufs/mnt/4e348b5187b9a567059306afc72d42e0ec5c893b0d4abd547526d5f9b6fb4590 rw,relatime - aufs none rw,si=9b4a7644f5d8c39c -151 15 0:3484 / /var/lib/docker/aufs/mnt/4efc616bfbc3f906718b052da22e4335f8e9f91ee9b15866ed3a8029645189ef rw,relatime - aufs none rw,si=9b4a7644f5d8939c -152 15 0:3485 / /var/lib/docker/aufs/mnt/83e730ae9754d5adb853b64735472d98dfa17136b8812ac9cfcd1eba7f4e7d2d rw,relatime - aufs none rw,si=9b4a76469aa7139c -153 15 0:3486 / /var/lib/docker/aufs/mnt/4fc5ba8a5b333be2b7eefacccb626772eeec0ae8a6975112b56c9fb36c0d342f rw,relatime - aufs none rw,si=9b4a7640128dc39c -154 15 0:3487 / /var/lib/docker/aufs/mnt/50200d5edff5dfe8d1ef3c78b0bbd709793ac6e936aa16d74ff66f7ea577b6f9 rw,relatime - aufs none rw,si=9b4a7640128da39c -155 15 0:3488 / /var/lib/docker/aufs/mnt/51e5e51604361448f0b9777f38329f414bc5ba9cf238f26d465ff479bd574b61 rw,relatime - aufs none rw,si=9b4a76444f68939c -156 15 0:3489 / /var/lib/docker/aufs/mnt/52a142149aa98bba83df8766bbb1c629a97b9799944ead90dd206c4bdf0b8385 rw,relatime - aufs none rw,si=9b4a76444f68b39c -157 15 0:3490 / /var/lib/docker/aufs/mnt/52dd21a94a00f58a1ed489312fcfffb91578089c76c5650364476f1d5de031bc rw,relatime - aufs none rw,si=9b4a76444f68f39c -158 15 0:3491 / /var/lib/docker/aufs/mnt/ee562415ddaad353ed22c88d0ca768a0c74bfba6333b6e25c46849ee22d990da rw,relatime - aufs none rw,si=9b4a7640128d839c -159 15 0:3492 / /var/lib/docker/aufs/mnt/db47a9e87173f7554f550c8a01891de79cf12acdd32e01f95c1a527a08bdfb2c rw,relatime - aufs none rw,si=9b4a764405a1d39c -160 15 0:3493 / /var/lib/docker/aufs/mnt/55e827bf6d44d930ec0b827c98356eb8b68c3301e2d60d1429aa72e05b4c17df rw,relatime - aufs none rw,si=9b4a764405a1a39c -162 15 0:3495 / /var/lib/docker/aufs/mnt/578dc4e0a87fc37ec081ca098430499a59639c09f6f12a8f48de29828a091aa6 rw,relatime - aufs none rw,si=9b4a76406d7d439c -163 15 0:3496 / /var/lib/docker/aufs/mnt/728cc1cb04fa4bc6f7bf7a90980beda6d8fc0beb71630874c0747b994efb0798 rw,relatime - aufs none rw,si=9b4a76444f20e39c -164 15 0:3497 / /var/lib/docker/aufs/mnt/5850cc4bd9b55aea46c7ad598f1785117607974084ea643580f58ce3222e683a rw,relatime - aufs none rw,si=9b4a7644a824239c -165 15 0:3498 / /var/lib/docker/aufs/mnt/89443b3f766d5a37bc8b84e29da8b84e6a3ea8486d3cf154e2aae1816516e4a8 rw,relatime - aufs none rw,si=9b4a7644a824139c -166 15 0:3499 / /var/lib/docker/aufs/mnt/f5ae8fd5a41a337907d16515bc3162525154b59c32314c695ecd092c3b47943d rw,relatime - aufs none rw,si=9b4a7644a824439c -167 15 0:3500 / /var/lib/docker/aufs/mnt/5a430854f2a03a9e5f7cbc9f3fb46a8ebca526a5b3f435236d8295e5998798f5 rw,relatime - aufs none rw,si=9b4a7647fc82439c -168 15 0:3501 / /var/lib/docker/aufs/mnt/eda16901ae4cead35070c39845cbf1e10bd6b8cb0ffa7879ae2d8a186e460f91 rw,relatime - aufs none rw,si=9b4a76441e0df39c -169 15 0:3502 / /var/lib/docker/aufs/mnt/5a593721430c2a51b119ff86a7e06ea2b37e3b4131f8f1344d402b61b0c8d868 rw,relatime - aufs none rw,si=9b4a764248bad39c -170 15 0:3503 / /var/lib/docker/aufs/mnt/d662ad0a30fbfa902e0962108685b9330597e1ee2abb16dc9462eb5a67fdd23f rw,relatime - aufs none rw,si=9b4a764248bae39c -171 15 0:3504 / /var/lib/docker/aufs/mnt/5bc9de5c79812843fb36eee96bef1ddba812407861f572e33242f4ee10da2c15 rw,relatime - aufs none rw,si=9b4a764248ba839c -172 15 0:3505 / /var/lib/docker/aufs/mnt/5e763de8e9b0f7d58d2e12a341e029ab4efb3b99788b175090d8209e971156c1 rw,relatime - aufs none rw,si=9b4a764248baa39c -173 15 0:3506 / /var/lib/docker/aufs/mnt/b4431dc2739936f1df6387e337f5a0c99cf051900c896bd7fd46a870ce61c873 rw,relatime - aufs none rw,si=9b4a76401263539c -174 15 0:3507 / /var/lib/docker/aufs/mnt/5f37830e5a02561ab8c67ea3113137ba69f67a60e41c05cb0e7a0edaa1925b24 rw,relatime - aufs none rw,si=9b4a76401263639c -184 15 0:3508 / /var/lib/docker/aufs/mnt/62ea10b957e6533538a4633a1e1d678502f50ddcdd354b2ca275c54dd7a7793a rw,relatime - aufs none rw,si=9b4a76401263039c -187 15 0:3509 / /var/lib/docker/aufs/mnt/d56ee9d44195fe390e042fda75ec15af5132adb6d5c69468fa8792f4e54a6953 rw,relatime - aufs none rw,si=9b4a76401263239c -188 15 0:3510 / /var/lib/docker/aufs/mnt/6a300930673174549c2b62f36c933f0332a20735978c007c805a301f897146c5 rw,relatime - aufs none rw,si=9b4a76455d4c539c -189 15 0:3511 / /var/lib/docker/aufs/mnt/64496c45c84d348c24d410015456d101601c30cab4d1998c395591caf7e57a70 rw,relatime - aufs none rw,si=9b4a76455d4c639c -190 15 0:3512 / /var/lib/docker/aufs/mnt/65a6a645883fe97a7422cd5e71ebe0bc17c8e6302a5361edf52e89747387e908 rw,relatime - aufs none rw,si=9b4a76455d4c039c -191 15 0:3513 / /var/lib/docker/aufs/mnt/672be40695f7b6e13b0a3ed9fc996c73727dede3481f58155950fcfad57ed616 rw,relatime - aufs none rw,si=9b4a76455d4c239c -192 15 0:3514 / /var/lib/docker/aufs/mnt/d42438acb2bfb2169e1c0d8e917fc824f7c85d336dadb0b0af36dfe0f001b3ba rw,relatime - aufs none rw,si=9b4a7642bfded39c -193 15 0:3515 / /var/lib/docker/aufs/mnt/b48a54abf26d01cb2ddd908b1ed6034d17397c1341bf0eb2b251a3e5b79be854 rw,relatime - aufs none rw,si=9b4a7642bfdee39c -194 15 0:3516 / /var/lib/docker/aufs/mnt/76f27134491f052bfb87f59092126e53ef875d6851990e59195a9da16a9412f8 rw,relatime - aufs none rw,si=9b4a7642bfde839c -195 15 0:3517 / /var/lib/docker/aufs/mnt/6bd626a5462b4f8a8e1cc7d10351326dca97a59b2758e5ea549a4f6350ce8a90 rw,relatime - aufs none rw,si=9b4a7642bfdea39c -196 15 0:3518 / /var/lib/docker/aufs/mnt/f1fe3549dbd6f5ca615e9139d9b53f0c83a3b825565df37628eacc13e70cbd6d rw,relatime - aufs none rw,si=9b4a7642bfdf539c -197 15 0:3519 / /var/lib/docker/aufs/mnt/6d0458c8426a9e93d58d0625737e6122e725c9408488ed9e3e649a9984e15c34 rw,relatime - aufs none rw,si=9b4a7642bfdf639c -198 15 0:3520 / /var/lib/docker/aufs/mnt/6e4c97db83aa82145c9cf2bafc20d500c0b5389643b689e3ae84188c270a48c5 rw,relatime - aufs none rw,si=9b4a7642bfdf039c -199 15 0:3521 / /var/lib/docker/aufs/mnt/eb94d6498f2c5969eaa9fa11ac2934f1ab90ef88e2d002258dca08e5ba74ea27 rw,relatime - aufs none rw,si=9b4a7642bfdf239c -200 15 0:3522 / /var/lib/docker/aufs/mnt/fe3f88f0c511608a2eec5f13a98703aa16e55dbf930309723d8a37101f539fe1 rw,relatime - aufs none rw,si=9b4a7642bfc3539c -201 15 0:3523 / /var/lib/docker/aufs/mnt/6f40c229fb9cad85fabf4b64a2640a5403ec03fe5ac1a57d0609fb8b606b9c83 rw,relatime - aufs none rw,si=9b4a7642bfc3639c -202 15 0:3524 / /var/lib/docker/aufs/mnt/7513e9131f7a8acf58ff15248237feb767c78732ca46e159f4d791e6ef031dbc rw,relatime - aufs none rw,si=9b4a7642bfc3039c -203 15 0:3525 / /var/lib/docker/aufs/mnt/79f48b00aa713cdf809c6bb7c7cb911b66e9a8076c81d6c9d2504139984ea2da rw,relatime - aufs none rw,si=9b4a7642bfc3239c -204 15 0:3526 / /var/lib/docker/aufs/mnt/c3680418350d11358f0a96c676bc5aa74fa00a7c89e629ef5909d3557b060300 rw,relatime - aufs none rw,si=9b4a7642f47cd39c -205 15 0:3527 / /var/lib/docker/aufs/mnt/7a1744dd350d7fcc0cccb6f1757ca4cbe5453f203a5888b0f1014d96ad5a5ef9 rw,relatime - aufs none rw,si=9b4a7642f47ce39c -206 15 0:3528 / /var/lib/docker/aufs/mnt/7fa99662db046be9f03c33c35251afda9ccdc0085636bbba1d90592cec3ff68d rw,relatime - aufs none rw,si=9b4a7642f47c839c -207 15 0:3529 / /var/lib/docker/aufs/mnt/f815021ef20da9c9b056bd1d52d8aaf6e2c0c19f11122fc793eb2b04eb995e35 rw,relatime - aufs none rw,si=9b4a7642f47ca39c -208 15 0:3530 / /var/lib/docker/aufs/mnt/801086ae3110192d601dfcebdba2db92e86ce6b6a9dba6678ea04488e4513669 rw,relatime - aufs none rw,si=9b4a7642dc6dd39c -209 15 0:3531 / /var/lib/docker/aufs/mnt/822ba7db69f21daddda87c01cfbfbf73013fc03a879daf96d16cdde6f9b1fbd6 rw,relatime - aufs none rw,si=9b4a7642dc6de39c -210 15 0:3532 / /var/lib/docker/aufs/mnt/834227c1a950fef8cae3827489129d0dd220541e60c6b731caaa765bf2e6a199 rw,relatime - aufs none rw,si=9b4a7642dc6d839c -211 15 0:3533 / /var/lib/docker/aufs/mnt/83dccbc385299bd1c7cf19326e791b33a544eea7b4cdfb6db70ea94eed4389fb rw,relatime - aufs none rw,si=9b4a7642dc6da39c -212 15 0:3534 / /var/lib/docker/aufs/mnt/f1b8e6f0e7c8928b5dcdab944db89306ebcae3e0b32f9ff40d2daa8329f21600 rw,relatime - aufs none rw,si=9b4a7645a126039c -213 15 0:3535 / /var/lib/docker/aufs/mnt/970efb262c7a020c2404cbcc5b3259efba0d110a786079faeef05bc2952abf3a rw,relatime - aufs none rw,si=9b4a7644c8ed139c -214 15 0:3536 / /var/lib/docker/aufs/mnt/84b6d73af7450f3117a77e15a5ca1255871fea6182cd8e8a7be6bc744be18c2c rw,relatime - aufs none rw,si=9b4a76406559139c -215 15 0:3537 / /var/lib/docker/aufs/mnt/88be2716e026bc681b5e63fe7942068773efbd0b6e901ca7ba441412006a96b6 rw,relatime - aufs none rw,si=9b4a76406559339c -216 15 0:3538 / /var/lib/docker/aufs/mnt/c81939aa166ce50cd8bca5cfbbcc420a78e0318dd5cd7c755209b9166a00a752 rw,relatime - aufs none rw,si=9b4a76406559239c -217 15 0:3539 / /var/lib/docker/aufs/mnt/e0f241645d64b7dc5ff6a8414087cca226be08fb54ce987d1d1f6350c57083aa rw,relatime - aufs none rw,si=9b4a7647cfc0f39c -218 15 0:3540 / /var/lib/docker/aufs/mnt/e10e2bf75234ed51d8a6a4bb39e465404fecbe318e54400d3879cdb2b0679c78 rw,relatime - aufs none rw,si=9b4a7647cfc0939c -219 15 0:3541 / /var/lib/docker/aufs/mnt/8f71d74c8cfc3228b82564aa9f09b2e576cff0083ddfb6aa5cb350346063f080 rw,relatime - aufs none rw,si=9b4a7647cfc0a39c -220 15 0:3542 / /var/lib/docker/aufs/mnt/9159f1eba2aef7f5205cc18d015cda7f5933cd29bba3b1b8aed5ccb5824c69ee rw,relatime - aufs none rw,si=9b4a76468cedd39c -221 15 0:3543 / /var/lib/docker/aufs/mnt/932cad71e652e048e500d9fbb5b8ea4fc9a269d42a3134ce527ceef42a2be56b rw,relatime - aufs none rw,si=9b4a76468cede39c -222 15 0:3544 / /var/lib/docker/aufs/mnt/bf1e1b5f529e8943cc0144ee86dbaaa37885c1ddffcef29537e0078ee7dd316a rw,relatime - aufs none rw,si=9b4a76468ced839c -223 15 0:3545 / /var/lib/docker/aufs/mnt/949d93ecf3322e09f858ce81d5f4b434068ec44ff84c375de03104f7b45ee955 rw,relatime - aufs none rw,si=9b4a76468ceda39c -224 15 0:3546 / /var/lib/docker/aufs/mnt/d65c6087f92dc2a3841b5251d2fe9ca07d4c6e5b021597692479740816e4e2a1 rw,relatime - aufs none rw,si=9b4a7645a126239c -225 15 0:3547 / /var/lib/docker/aufs/mnt/98a0153119d0651c193d053d254f6e16a68345a141baa80c87ae487e9d33f290 rw,relatime - aufs none rw,si=9b4a7640787cf39c -226 15 0:3548 / /var/lib/docker/aufs/mnt/99daf7fe5847c017392f6e59aa9706b3dfdd9e6d1ba11dae0f7fffde0a60b5e5 rw,relatime - aufs none rw,si=9b4a7640787c839c -227 15 0:3549 / /var/lib/docker/aufs/mnt/9ad1f2fe8a5599d4e10c5a6effa7f03d932d4e92ee13149031a372087a359079 rw,relatime - aufs none rw,si=9b4a7640787ca39c -228 15 0:3550 / /var/lib/docker/aufs/mnt/c26d64494da782ddac26f8370d86ac93e7c1666d88a7b99110fc86b35ea6a85d rw,relatime - aufs none rw,si=9b4a7642fc6b539c -229 15 0:3551 / /var/lib/docker/aufs/mnt/a49e4a8275133c230ec640997f35f172312eb0ea5bd2bbe10abf34aae98f30eb rw,relatime - aufs none rw,si=9b4a7642fc6b639c -230 15 0:3552 / /var/lib/docker/aufs/mnt/b5e2740c867ed843025f49d84e8d769de9e8e6039b3c8cb0735b5bf358994bc7 rw,relatime - aufs none rw,si=9b4a7642fc6b039c -231 15 0:3553 / /var/lib/docker/aufs/mnt/a826fdcf3a7039b30570054579b65763db605a314275d7aef31b872c13311b4b rw,relatime - aufs none rw,si=9b4a7642fc6b239c -232 15 0:3554 / /var/lib/docker/aufs/mnt/addf3025babf5e43b5a3f4a0da7ad863dda3c01fb8365c58fd8d28bb61dc11bc rw,relatime - aufs none rw,si=9b4a76407871d39c -233 15 0:3555 / /var/lib/docker/aufs/mnt/c5b6c6813ab3e5ebdc6d22cb2a3d3106a62095f2c298be52b07a3b0fa20ff690 rw,relatime - aufs none rw,si=9b4a76407871e39c -234 15 0:3556 / /var/lib/docker/aufs/mnt/af0609eaaf64e2392060cb46f5a9f3d681a219bb4c651d4f015bf573fbe6c4cf rw,relatime - aufs none rw,si=9b4a76407871839c -235 15 0:3557 / /var/lib/docker/aufs/mnt/e7f20e3c37ecad39cd90a97cd3549466d0d106ce4f0a930b8495442634fa4a1f rw,relatime - aufs none rw,si=9b4a76407871a39c -237 15 0:3559 / /var/lib/docker/aufs/mnt/b57a53d440ffd0c1295804fa68cdde35d2fed5409484627e71b9c37e4249fd5c rw,relatime - aufs none rw,si=9b4a76444445a39c -238 15 0:3560 / /var/lib/docker/aufs/mnt/b5e7d7b8f35e47efbba3d80c5d722f5e7bd43e54c824e54b4a4b351714d36d42 rw,relatime - aufs none rw,si=9b4a7647932d439c -239 15 0:3561 / /var/lib/docker/aufs/mnt/f1b136def157e9465640658f277f3347de593c6ae76412a2e79f7002f091cae2 rw,relatime - aufs none rw,si=9b4a76445abcd39c -240 15 0:3562 / /var/lib/docker/aufs/mnt/b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc rw,relatime - aufs none rw,si=9b4a7644403b339c -241 15 0:3563 / /var/lib/docker/aufs/mnt/b89b140cdbc95063761864e0a23346207fa27ee4c5c63a1ae85c9069a9d9cf1d rw,relatime - aufs none rw,si=9b4a7644aa19739c -242 15 0:3564 / /var/lib/docker/aufs/mnt/bc6a69ed51c07f5228f6b4f161c892e6a949c0e7e86a9c3432049d4c0e5cd298 rw,relatime - aufs none rw,si=9b4a7644aa19139c -243 15 0:3565 / /var/lib/docker/aufs/mnt/be4e2ba3f136933e239f7cf3d136f484fb9004f1fbdfee24a62a2c7b0ab30670 rw,relatime - aufs none rw,si=9b4a7644aa19339c -244 15 0:3566 / /var/lib/docker/aufs/mnt/e04ca1a4a5171e30d20f0c92f90a50b8b6f8600af5459c4b4fb25e42e864dfe1 rw,relatime - aufs none rw,si=9b4a7647932d139c -245 15 0:3567 / /var/lib/docker/aufs/mnt/be61576b31db893129aaffcd3dcb5ce35e49c4b71b30c392a78609a45c7323d8 rw,relatime - aufs none rw,si=9b4a7642d85f739c -246 15 0:3568 / /var/lib/docker/aufs/mnt/dda42c191e56becf672327658ab84fcb563322db3764b91c2fefe4aaef04c624 rw,relatime - aufs none rw,si=9b4a7642d85f139c -247 15 0:3569 / /var/lib/docker/aufs/mnt/c0a7995053330f3d88969247a2e72b07e2dd692133f5668a4a35ea3905561072 rw,relatime - aufs none rw,si=9b4a7642d85f339c -249 15 0:3571 / /var/lib/docker/aufs/mnt/c3594b2e5f08c59ff5ed338a1ba1eceeeb1f7fc5d180068338110c00b1eb8502 rw,relatime - aufs none rw,si=9b4a7642738c739c -250 15 0:3572 / /var/lib/docker/aufs/mnt/c58dce03a0ab0a7588393880379dc3bce9f96ec08ed3f99cf1555260ff0031e8 rw,relatime - aufs none rw,si=9b4a7642738c139c -251 15 0:3573 / /var/lib/docker/aufs/mnt/c73e9f1d109c9d14cb36e1c7489df85649be3911116d76c2fd3648ec8fd94e23 rw,relatime - aufs none rw,si=9b4a7642738c339c -252 15 0:3574 / /var/lib/docker/aufs/mnt/c9eef28c344877cd68aa09e543c0710ab2b305a0ff96dbb859bfa7808c3e8d01 rw,relatime - aufs none rw,si=9b4a7642d85f439c -253 15 0:3575 / /var/lib/docker/aufs/mnt/feb67148f548d70cb7484f2aaad2a86051cd6867a561741a2f13b552457d666e rw,relatime - aufs none rw,si=9b4a76468c55739c -254 15 0:3576 / /var/lib/docker/aufs/mnt/cdf1f96c36d35a96041a896bf398ec0f7dc3b0fb0643612a0f4b6ff96e04e1bb rw,relatime - aufs none rw,si=9b4a76468c55139c -255 15 0:3577 / /var/lib/docker/aufs/mnt/ec6e505872353268451ac4bc034c1df00f3bae4a3ea2261c6e48f7bd5417c1b3 rw,relatime - aufs none rw,si=9b4a76468c55339c -256 15 0:3578 / /var/lib/docker/aufs/mnt/d6dc8aca64efd90e0bc10274001882d0efb310d42ccbf5712b99b169053b8b1a rw,relatime - aufs none rw,si=9b4a7642738c439c -257 15 0:3579 / /var/lib/docker/aufs/mnt/d712594e2ff6eaeb895bfd150d694bd1305fb927e7a186b2dab7df2ea95f8f81 rw,relatime - aufs none rw,si=9b4a76401268f39c -259 15 0:3581 / /var/lib/docker/aufs/mnt/dbfa1174cd78cde2d7410eae442af0b416c4a0e6f87ed4ff1e9f169a0029abc0 rw,relatime - aufs none rw,si=9b4a76401268b39c -260 15 0:3582 / /var/lib/docker/aufs/mnt/e883f5a82316d7856fbe93ee8c0af5a920b7079619dd95c4ffd88bbd309d28dd rw,relatime - aufs none rw,si=9b4a76468c55439c -261 15 0:3583 / /var/lib/docker/aufs/mnt/fdec3eff581c4fc2b09f87befa2fa021f3f2d373bea636a87f1fb5b367d6347a rw,relatime - aufs none rw,si=9b4a7644aa1af39c -262 15 0:3584 / /var/lib/docker/aufs/mnt/ef764e26712184653067ecf7afea18a80854c41331ca0f0ef03e1bacf90a6ffc rw,relatime - aufs none rw,si=9b4a7644aa1a939c -263 15 0:3585 / /var/lib/docker/aufs/mnt/f3176b40c41fce8ce6942936359a2001a6f1b5c1bb40ee224186db0789ec2f76 rw,relatime - aufs none rw,si=9b4a7644aa1ab39c -264 15 0:3586 / /var/lib/docker/aufs/mnt/f5daf06785d3565c6dd18ea7d953d9a8b9606107781e63270fe0514508736e6a rw,relatime - aufs none rw,si=9b4a76401268c39c -58 15 0:3587 / /var/lib/docker/aufs/mnt/cde8c40f6524b7361af4f5ad05bb857dc9ee247c20852ba666195c0739e3a2b8-init rw,relatime - aufs none rw,si=9b4a76444445839c -67 15 0:3588 / /var/lib/docker/aufs/mnt/cde8c40f6524b7361af4f5ad05bb857dc9ee247c20852ba666195c0739e3a2b8 rw,relatime - aufs none rw,si=9b4a7644badd339c -265 15 0:3610 / /var/lib/docker/aufs/mnt/e812472cd2c8c4748d1ef71fac4e77e50d661b9349abe66ce3e23511ed44f414 rw,relatime - aufs none rw,si=9b4a76427937d39c -270 15 0:3615 / /var/lib/docker/aufs/mnt/997636e7c5c9d0d1376a217e295c14c205350b62bc12052804fb5f90abe6f183 rw,relatime - aufs none rw,si=9b4a76406540739c -273 15 0:3618 / /var/lib/docker/aufs/mnt/d5794d080417b6e52e69227c3873e0e4c1ff0d5a845ebe3860ec2f89a47a2a1e rw,relatime - aufs none rw,si=9b4a76454814039c -278 15 0:3623 / /var/lib/docker/aufs/mnt/586bdd48baced671bb19bc4d294ec325f26c55545ae267db426424f157d59c48 rw,relatime - aufs none rw,si=9b4a7644b439f39c -281 15 0:3626 / /var/lib/docker/aufs/mnt/69739d022f89f8586908bbd5edbbdd95ea5256356f177f9ffcc6ef9c0ea752d2 rw,relatime - aufs none rw,si=9b4a7644a0f1b39c -286 15 0:3631 / /var/lib/docker/aufs/mnt/ff28c27d5f894363993622de26d5dd352dba072f219e4691d6498c19bbbc15a9 rw,relatime - aufs none rw,si=9b4a7642265b339c -289 15 0:3634 / /var/lib/docker/aufs/mnt/aa128fe0e64fdede333aa48fd9de39530c91a9244a0f0649a3c411c61e372daa rw,relatime - aufs none rw,si=9b4a764012ada39c -99 15 8:33 / /media/REMOVE\040ME rw,nosuid,nodev,relatime - fuseblk /dev/sdc1 rw,user_id=0,group_id=0,allow_other,blksize=4096` -) - -func TestParseFedoraMountinfo(t *testing.T) { - r := bytes.NewBuffer([]byte(fedoraMountinfo)) - _, err := parseInfoFile(r) - if err != nil { - t.Fatal(err) - } -} - -func TestParseUbuntuMountinfo(t *testing.T) { - r := bytes.NewBuffer([]byte(ubuntuMountInfo)) - _, err := parseInfoFile(r) - if err != nil { - t.Fatal(err) - } -} - -func TestParseGentooMountinfo(t *testing.T) { - r := bytes.NewBuffer([]byte(gentooMountinfo)) - _, err := parseInfoFile(r) - if err != nil { - t.Fatal(err) - } -} - -func TestParseFedoraMountinfoFields(t *testing.T) { - r := bytes.NewBuffer([]byte(fedoraMountinfo)) - infos, err := parseInfoFile(r) - if err != nil { - t.Fatal(err) - } - expectedLength := 58 - if len(infos) != expectedLength { - t.Fatalf("Expected %d entries, got %d", expectedLength, len(infos)) - } - mi := Info{ - ID: 15, - Parent: 35, - Major: 0, - Minor: 3, - Root: "/", - Mountpoint: "/proc", - Opts: "rw,nosuid,nodev,noexec,relatime", - Optional: "shared:5", - Fstype: "proc", - Source: "proc", - VfsOpts: "rw", - } - - if *infos[0] != mi { - t.Fatalf("expected %#v, got %#v", mi, infos[0]) - } -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mountinfo_solaris.go b/vendor/github.com/docker/docker/pkg/mount/mountinfo_solaris.go deleted file mode 100644 index ad9ab57..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mountinfo_solaris.go +++ /dev/null @@ -1,37 +0,0 @@ -// +build solaris,cgo - -package mount - -/* -#include -#include -*/ -import "C" - -import ( - "fmt" -) - -func parseMountTable() ([]*Info, error) { - mnttab := C.fopen(C.CString(C.MNTTAB), C.CString("r")) - if mnttab == nil { - return nil, fmt.Errorf("Failed to open %s", C.MNTTAB) - } - - var out []*Info - var mp C.struct_mnttab - - ret := C.getmntent(mnttab, &mp) - for ret == 0 { - var mountinfo Info - mountinfo.Mountpoint = C.GoString(mp.mnt_mountp) - mountinfo.Source = C.GoString(mp.mnt_special) - mountinfo.Fstype = C.GoString(mp.mnt_fstype) - mountinfo.Opts = C.GoString(mp.mnt_mntopts) - out = append(out, &mountinfo) - ret = C.getmntent(mnttab, &mp) - } - - C.fclose(mnttab) - return out, nil -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mountinfo_unsupported.go b/vendor/github.com/docker/docker/pkg/mount/mountinfo_unsupported.go deleted file mode 100644 index 7fbcf19..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mountinfo_unsupported.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !windows,!linux,!freebsd,!solaris freebsd,!cgo solaris,!cgo - -package mount - -import ( - "fmt" - "runtime" -) - -func parseMountTable() ([]*Info, error) { - return nil, fmt.Errorf("mount.parseMountTable is not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) -} diff --git a/vendor/github.com/docker/docker/pkg/mount/mountinfo_windows.go b/vendor/github.com/docker/docker/pkg/mount/mountinfo_windows.go deleted file mode 100644 index dab8a37..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/mountinfo_windows.go +++ /dev/null @@ -1,6 +0,0 @@ -package mount - -func parseMountTable() ([]*Info, error) { - // Do NOT return an error! - return nil, nil -} diff --git a/vendor/github.com/docker/docker/pkg/mount/sharedsubtree_linux.go b/vendor/github.com/docker/docker/pkg/mount/sharedsubtree_linux.go deleted file mode 100644 index 8ceec84..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/sharedsubtree_linux.go +++ /dev/null @@ -1,69 +0,0 @@ -// +build linux - -package mount - -// MakeShared ensures a mounted filesystem has the SHARED mount option enabled. -// See the supported options in flags.go for further reference. -func MakeShared(mountPoint string) error { - return ensureMountedAs(mountPoint, "shared") -} - -// MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled. -// See the supported options in flags.go for further reference. -func MakeRShared(mountPoint string) error { - return ensureMountedAs(mountPoint, "rshared") -} - -// MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled. -// See the supported options in flags.go for further reference. -func MakePrivate(mountPoint string) error { - return ensureMountedAs(mountPoint, "private") -} - -// MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option -// enabled. See the supported options in flags.go for further reference. -func MakeRPrivate(mountPoint string) error { - return ensureMountedAs(mountPoint, "rprivate") -} - -// MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled. -// See the supported options in flags.go for further reference. -func MakeSlave(mountPoint string) error { - return ensureMountedAs(mountPoint, "slave") -} - -// MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled. -// See the supported options in flags.go for further reference. -func MakeRSlave(mountPoint string) error { - return ensureMountedAs(mountPoint, "rslave") -} - -// MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option -// enabled. See the supported options in flags.go for further reference. -func MakeUnbindable(mountPoint string) error { - return ensureMountedAs(mountPoint, "unbindable") -} - -// MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount -// option enabled. See the supported options in flags.go for further reference. -func MakeRUnbindable(mountPoint string) error { - return ensureMountedAs(mountPoint, "runbindable") -} - -func ensureMountedAs(mountPoint, options string) error { - mounted, err := Mounted(mountPoint) - if err != nil { - return err - } - - if !mounted { - if err := Mount(mountPoint, mountPoint, "none", "bind,rw"); err != nil { - return err - } - } - if _, err = Mounted(mountPoint); err != nil { - return err - } - - return ForceMount("", mountPoint, "none", options) -} diff --git a/vendor/github.com/docker/docker/pkg/mount/sharedsubtree_linux_test.go b/vendor/github.com/docker/docker/pkg/mount/sharedsubtree_linux_test.go deleted file mode 100644 index c183794..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/sharedsubtree_linux_test.go +++ /dev/null @@ -1,331 +0,0 @@ -// +build linux - -package mount - -import ( - "os" - "path" - "syscall" - "testing" -) - -// nothing is propagated in or out -func TestSubtreePrivate(t *testing.T) { - tmp := path.Join(os.TempDir(), "mount-tests") - if err := os.MkdirAll(tmp, 0777); err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - - var ( - sourceDir = path.Join(tmp, "source") - targetDir = path.Join(tmp, "target") - outside1Dir = path.Join(tmp, "outside1") - outside2Dir = path.Join(tmp, "outside2") - - outside1Path = path.Join(outside1Dir, "file.txt") - outside2Path = path.Join(outside2Dir, "file.txt") - outside1CheckPath = path.Join(targetDir, "a", "file.txt") - outside2CheckPath = path.Join(sourceDir, "b", "file.txt") - ) - if err := os.MkdirAll(path.Join(sourceDir, "a"), 0777); err != nil { - t.Fatal(err) - } - if err := os.MkdirAll(path.Join(sourceDir, "b"), 0777); err != nil { - t.Fatal(err) - } - if err := os.Mkdir(targetDir, 0777); err != nil { - t.Fatal(err) - } - if err := os.Mkdir(outside1Dir, 0777); err != nil { - t.Fatal(err) - } - if err := os.Mkdir(outside2Dir, 0777); err != nil { - t.Fatal(err) - } - - if err := createFile(outside1Path); err != nil { - t.Fatal(err) - } - if err := createFile(outside2Path); err != nil { - t.Fatal(err) - } - - // mount the shared directory to a target - if err := Mount(sourceDir, targetDir, "none", "bind,rw"); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(targetDir); err != nil { - t.Fatal(err) - } - }() - - // next, make the target private - if err := MakePrivate(targetDir); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(targetDir); err != nil { - t.Fatal(err) - } - }() - - // mount in an outside path to a mounted path inside the _source_ - if err := Mount(outside1Dir, path.Join(sourceDir, "a"), "none", "bind,rw"); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(path.Join(sourceDir, "a")); err != nil { - t.Fatal(err) - } - }() - - // check that this file _does_not_ show in the _target_ - if _, err := os.Stat(outside1CheckPath); err != nil && !os.IsNotExist(err) { - t.Fatal(err) - } else if err == nil { - t.Fatalf("%q should not be visible, but is", outside1CheckPath) - } - - // next mount outside2Dir into the _target_ - if err := Mount(outside2Dir, path.Join(targetDir, "b"), "none", "bind,rw"); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(path.Join(targetDir, "b")); err != nil { - t.Fatal(err) - } - }() - - // check that this file _does_not_ show in the _source_ - if _, err := os.Stat(outside2CheckPath); err != nil && !os.IsNotExist(err) { - t.Fatal(err) - } else if err == nil { - t.Fatalf("%q should not be visible, but is", outside2CheckPath) - } -} - -// Testing that when a target is a shared mount, -// then child mounts propagate to the source -func TestSubtreeShared(t *testing.T) { - tmp := path.Join(os.TempDir(), "mount-tests") - if err := os.MkdirAll(tmp, 0777); err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - - var ( - sourceDir = path.Join(tmp, "source") - targetDir = path.Join(tmp, "target") - outsideDir = path.Join(tmp, "outside") - - outsidePath = path.Join(outsideDir, "file.txt") - sourceCheckPath = path.Join(sourceDir, "a", "file.txt") - ) - - if err := os.MkdirAll(path.Join(sourceDir, "a"), 0777); err != nil { - t.Fatal(err) - } - if err := os.Mkdir(targetDir, 0777); err != nil { - t.Fatal(err) - } - if err := os.Mkdir(outsideDir, 0777); err != nil { - t.Fatal(err) - } - - if err := createFile(outsidePath); err != nil { - t.Fatal(err) - } - - // mount the source as shared - if err := MakeShared(sourceDir); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(sourceDir); err != nil { - t.Fatal(err) - } - }() - - // mount the shared directory to a target - if err := Mount(sourceDir, targetDir, "none", "bind,rw"); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(targetDir); err != nil { - t.Fatal(err) - } - }() - - // mount in an outside path to a mounted path inside the target - if err := Mount(outsideDir, path.Join(targetDir, "a"), "none", "bind,rw"); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(path.Join(targetDir, "a")); err != nil { - t.Fatal(err) - } - }() - - // NOW, check that the file from the outside directory is available in the source directory - if _, err := os.Stat(sourceCheckPath); err != nil { - t.Fatal(err) - } -} - -// testing that mounts to a shared source show up in the slave target, -// and that mounts into a slave target do _not_ show up in the shared source -func TestSubtreeSharedSlave(t *testing.T) { - tmp := path.Join(os.TempDir(), "mount-tests") - if err := os.MkdirAll(tmp, 0777); err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - - var ( - sourceDir = path.Join(tmp, "source") - targetDir = path.Join(tmp, "target") - outside1Dir = path.Join(tmp, "outside1") - outside2Dir = path.Join(tmp, "outside2") - - outside1Path = path.Join(outside1Dir, "file.txt") - outside2Path = path.Join(outside2Dir, "file.txt") - outside1CheckPath = path.Join(targetDir, "a", "file.txt") - outside2CheckPath = path.Join(sourceDir, "b", "file.txt") - ) - if err := os.MkdirAll(path.Join(sourceDir, "a"), 0777); err != nil { - t.Fatal(err) - } - if err := os.MkdirAll(path.Join(sourceDir, "b"), 0777); err != nil { - t.Fatal(err) - } - if err := os.Mkdir(targetDir, 0777); err != nil { - t.Fatal(err) - } - if err := os.Mkdir(outside1Dir, 0777); err != nil { - t.Fatal(err) - } - if err := os.Mkdir(outside2Dir, 0777); err != nil { - t.Fatal(err) - } - - if err := createFile(outside1Path); err != nil { - t.Fatal(err) - } - if err := createFile(outside2Path); err != nil { - t.Fatal(err) - } - - // mount the source as shared - if err := MakeShared(sourceDir); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(sourceDir); err != nil { - t.Fatal(err) - } - }() - - // mount the shared directory to a target - if err := Mount(sourceDir, targetDir, "none", "bind,rw"); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(targetDir); err != nil { - t.Fatal(err) - } - }() - - // next, make the target slave - if err := MakeSlave(targetDir); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(targetDir); err != nil { - t.Fatal(err) - } - }() - - // mount in an outside path to a mounted path inside the _source_ - if err := Mount(outside1Dir, path.Join(sourceDir, "a"), "none", "bind,rw"); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(path.Join(sourceDir, "a")); err != nil { - t.Fatal(err) - } - }() - - // check that this file _does_ show in the _target_ - if _, err := os.Stat(outside1CheckPath); err != nil { - t.Fatal(err) - } - - // next mount outside2Dir into the _target_ - if err := Mount(outside2Dir, path.Join(targetDir, "b"), "none", "bind,rw"); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(path.Join(targetDir, "b")); err != nil { - t.Fatal(err) - } - }() - - // check that this file _does_not_ show in the _source_ - if _, err := os.Stat(outside2CheckPath); err != nil && !os.IsNotExist(err) { - t.Fatal(err) - } else if err == nil { - t.Fatalf("%q should not be visible, but is", outside2CheckPath) - } -} - -func TestSubtreeUnbindable(t *testing.T) { - tmp := path.Join(os.TempDir(), "mount-tests") - if err := os.MkdirAll(tmp, 0777); err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) - - var ( - sourceDir = path.Join(tmp, "source") - targetDir = path.Join(tmp, "target") - ) - if err := os.MkdirAll(sourceDir, 0777); err != nil { - t.Fatal(err) - } - if err := os.MkdirAll(targetDir, 0777); err != nil { - t.Fatal(err) - } - - // next, make the source unbindable - if err := MakeUnbindable(sourceDir); err != nil { - t.Fatal(err) - } - defer func() { - if err := Unmount(sourceDir); err != nil { - t.Fatal(err) - } - }() - - // then attempt to mount it to target. It should fail - if err := Mount(sourceDir, targetDir, "none", "bind,rw"); err != nil && err != syscall.EINVAL { - t.Fatal(err) - } else if err == nil { - t.Fatalf("%q should not have been bindable", sourceDir) - } - defer func() { - if err := Unmount(targetDir); err != nil { - t.Fatal(err) - } - }() -} - -func createFile(path string) error { - f, err := os.Create(path) - if err != nil { - return err - } - f.WriteString("hello world!") - return f.Close() -} diff --git a/vendor/github.com/docker/docker/pkg/mount/sharedsubtree_solaris.go b/vendor/github.com/docker/docker/pkg/mount/sharedsubtree_solaris.go deleted file mode 100644 index 09f6b03..0000000 --- a/vendor/github.com/docker/docker/pkg/mount/sharedsubtree_solaris.go +++ /dev/null @@ -1,58 +0,0 @@ -// +build solaris - -package mount - -// MakeShared ensures a mounted filesystem has the SHARED mount option enabled. -// See the supported options in flags.go for further reference. -func MakeShared(mountPoint string) error { - return ensureMountedAs(mountPoint, "shared") -} - -// MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled. -// See the supported options in flags.go for further reference. -func MakeRShared(mountPoint string) error { - return ensureMountedAs(mountPoint, "rshared") -} - -// MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled. -// See the supported options in flags.go for further reference. -func MakePrivate(mountPoint string) error { - return ensureMountedAs(mountPoint, "private") -} - -// MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option -// enabled. See the supported options in flags.go for further reference. -func MakeRPrivate(mountPoint string) error { - return ensureMountedAs(mountPoint, "rprivate") -} - -// MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled. -// See the supported options in flags.go for further reference. -func MakeSlave(mountPoint string) error { - return ensureMountedAs(mountPoint, "slave") -} - -// MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled. -// See the supported options in flags.go for further reference. -func MakeRSlave(mountPoint string) error { - return ensureMountedAs(mountPoint, "rslave") -} - -// MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option -// enabled. See the supported options in flags.go for further reference. -func MakeUnbindable(mountPoint string) error { - return ensureMountedAs(mountPoint, "unbindable") -} - -// MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount -// option enabled. See the supported options in flags.go for further reference. -func MakeRUnbindable(mountPoint string) error { - return ensureMountedAs(mountPoint, "runbindable") -} - -func ensureMountedAs(mountPoint, options string) error { - // TODO: Solaris does not support bind mounts. - // Evaluate lofs and also look at the relevant - // mount flags to be supported. - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/namesgenerator/cmd/names-generator/main.go b/vendor/github.com/docker/docker/pkg/namesgenerator/cmd/names-generator/main.go deleted file mode 100644 index 18a939b..0000000 --- a/vendor/github.com/docker/docker/pkg/namesgenerator/cmd/names-generator/main.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/docker/docker/pkg/namesgenerator" -) - -func main() { - fmt.Println(namesgenerator.GetRandomName(0)) -} diff --git a/vendor/github.com/docker/docker/pkg/namesgenerator/names-generator.go b/vendor/github.com/docker/docker/pkg/namesgenerator/names-generator.go deleted file mode 100644 index cfb8157..0000000 --- a/vendor/github.com/docker/docker/pkg/namesgenerator/names-generator.go +++ /dev/null @@ -1,590 +0,0 @@ -package namesgenerator - -import ( - "fmt" - - "github.com/docker/docker/pkg/random" -) - -var ( - left = [...]string{ - "admiring", - "adoring", - "affectionate", - "agitated", - "amazing", - "angry", - "awesome", - "blissful", - "boring", - "brave", - "clever", - "cocky", - "compassionate", - "competent", - "condescending", - "confident", - "cranky", - "dazzling", - "determined", - "distracted", - "dreamy", - "eager", - "ecstatic", - "elastic", - "elated", - "elegant", - "eloquent", - "epic", - "fervent", - "festive", - "flamboyant", - "focused", - "friendly", - "frosty", - "gallant", - "gifted", - "goofy", - "gracious", - "happy", - "hardcore", - "heuristic", - "hopeful", - "hungry", - "infallible", - "inspiring", - "jolly", - "jovial", - "keen", - "kickass", - "kind", - "laughing", - "loving", - "lucid", - "mystifying", - "modest", - "musing", - "naughty", - "nervous", - "nifty", - "nostalgic", - "objective", - "optimistic", - "peaceful", - "pedantic", - "pensive", - "practical", - "priceless", - "quirky", - "quizzical", - "relaxed", - "reverent", - "romantic", - "sad", - "serene", - "sharp", - "silly", - "sleepy", - "stoic", - "stupefied", - "suspicious", - "tender", - "thirsty", - "trusting", - "unruffled", - "upbeat", - "vibrant", - "vigilant", - "wizardly", - "wonderful", - "xenodochial", - "youthful", - "zealous", - "zen", - } - - // Docker, starting from 0.7.x, generates names from notable scientists and hackers. - // Please, for any amazing man that you add to the list, consider adding an equally amazing woman to it, and vice versa. - right = [...]string{ - // Muhammad ibn Jābir al-Ḥarrānī al-Battānī was a founding father of astronomy. https://en.wikipedia.org/wiki/Mu%E1%B8%A5ammad_ibn_J%C4%81bir_al-%E1%B8%A4arr%C4%81n%C4%AB_al-Batt%C4%81n%C4%AB - "albattani", - - // Frances E. Allen, became the first female IBM Fellow in 1989. In 2006, she became the first female recipient of the ACM's Turing Award. https://en.wikipedia.org/wiki/Frances_E._Allen - "allen", - - // June Almeida - Scottish virologist who took the first pictures of the rubella virus - https://en.wikipedia.org/wiki/June_Almeida - "almeida", - - // Maria Gaetana Agnesi - Italian mathematician, philosopher, theologian and humanitarian. She was the first woman to write a mathematics handbook and the first woman appointed as a Mathematics Professor at a University. https://en.wikipedia.org/wiki/Maria_Gaetana_Agnesi - "agnesi", - - // Archimedes was a physicist, engineer and mathematician who invented too many things to list them here. https://en.wikipedia.org/wiki/Archimedes - "archimedes", - - // Maria Ardinghelli - Italian translator, mathematician and physicist - https://en.wikipedia.org/wiki/Maria_Ardinghelli - "ardinghelli", - - // Aryabhata - Ancient Indian mathematician-astronomer during 476-550 CE https://en.wikipedia.org/wiki/Aryabhata - "aryabhata", - - // Wanda Austin - Wanda Austin is the President and CEO of The Aerospace Corporation, a leading architect for the US security space programs. https://en.wikipedia.org/wiki/Wanda_Austin - "austin", - - // Charles Babbage invented the concept of a programmable computer. https://en.wikipedia.org/wiki/Charles_Babbage. - "babbage", - - // Stefan Banach - Polish mathematician, was one of the founders of modern functional analysis. https://en.wikipedia.org/wiki/Stefan_Banach - "banach", - - // John Bardeen co-invented the transistor - https://en.wikipedia.org/wiki/John_Bardeen - "bardeen", - - // Jean Bartik, born Betty Jean Jennings, was one of the original programmers for the ENIAC computer. https://en.wikipedia.org/wiki/Jean_Bartik - "bartik", - - // Laura Bassi, the world's first female professor https://en.wikipedia.org/wiki/Laura_Bassi - "bassi", - - // Hugh Beaver, British engineer, founder of the Guinness Book of World Records https://en.wikipedia.org/wiki/Hugh_Beaver - "beaver", - - // Alexander Graham Bell - an eminent Scottish-born scientist, inventor, engineer and innovator who is credited with inventing the first practical telephone - https://en.wikipedia.org/wiki/Alexander_Graham_Bell - "bell", - - // Homi J Bhabha - was an Indian nuclear physicist, founding director, and professor of physics at the Tata Institute of Fundamental Research. Colloquially known as "father of Indian nuclear programme"- https://en.wikipedia.org/wiki/Homi_J._Bhabha - "bhabha", - - // Bhaskara II - Ancient Indian mathematician-astronomer whose work on calculus predates Newton and Leibniz by over half a millennium - https://en.wikipedia.org/wiki/Bh%C4%81skara_II#Calculus - "bhaskara", - - // Elizabeth Blackwell - American doctor and first American woman to receive a medical degree - https://en.wikipedia.org/wiki/Elizabeth_Blackwell - "blackwell", - - // Niels Bohr is the father of quantum theory. https://en.wikipedia.org/wiki/Niels_Bohr. - "bohr", - - // Kathleen Booth, she's credited with writing the first assembly language. https://en.wikipedia.org/wiki/Kathleen_Booth - "booth", - - // Anita Borg - Anita Borg was the founding director of the Institute for Women and Technology (IWT). https://en.wikipedia.org/wiki/Anita_Borg - "borg", - - // Satyendra Nath Bose - He provided the foundation for Bose–Einstein statistics and the theory of the Bose–Einstein condensate. - https://en.wikipedia.org/wiki/Satyendra_Nath_Bose - "bose", - - // Evelyn Boyd Granville - She was one of the first African-American woman to receive a Ph.D. in mathematics; she earned it in 1949 from Yale University. https://en.wikipedia.org/wiki/Evelyn_Boyd_Granville - "boyd", - - // Brahmagupta - Ancient Indian mathematician during 598-670 CE who gave rules to compute with zero - https://en.wikipedia.org/wiki/Brahmagupta#Zero - "brahmagupta", - - // Walter Houser Brattain co-invented the transistor - https://en.wikipedia.org/wiki/Walter_Houser_Brattain - "brattain", - - // Emmett Brown invented time travel. https://en.wikipedia.org/wiki/Emmett_Brown (thanks Brian Goff) - "brown", - - // Rachel Carson - American marine biologist and conservationist, her book Silent Spring and other writings are credited with advancing the global environmental movement. https://en.wikipedia.org/wiki/Rachel_Carson - "carson", - - // Subrahmanyan Chandrasekhar - Astrophysicist known for his mathematical theory on different stages and evolution in structures of the stars. He has won nobel prize for physics - https://en.wikipedia.org/wiki/Subrahmanyan_Chandrasekhar - "chandrasekhar", - - //Claude Shannon - The father of information theory and founder of digital circuit design theory. (https://en.wikipedia.org/wiki/Claude_Shannon) - "shannon", - - // Joan Clarke - Bletchley Park code breaker during the Second World War who pioneered techniques that remained top secret for decades. Also an accomplished numismatist https://en.wikipedia.org/wiki/Joan_Clarke - "clarke", - - // Jane Colden - American botanist widely considered the first female American botanist - https://en.wikipedia.org/wiki/Jane_Colden - "colden", - - // Gerty Theresa Cori - American biochemist who became the third woman—and first American woman—to win a Nobel Prize in science, and the first woman to be awarded the Nobel Prize in Physiology or Medicine. Cori was born in Prague. https://en.wikipedia.org/wiki/Gerty_Cori - "cori", - - // Seymour Roger Cray was an American electrical engineer and supercomputer architect who designed a series of computers that were the fastest in the world for decades. https://en.wikipedia.org/wiki/Seymour_Cray - "cray", - - // This entry reflects a husband and wife team who worked together: - // Joan Curran was a Welsh scientist who developed radar and invented chaff, a radar countermeasure. https://en.wikipedia.org/wiki/Joan_Curran - // Samuel Curran was an Irish physicist who worked alongside his wife during WWII and invented the proximity fuse. https://en.wikipedia.org/wiki/Samuel_Curran - "curran", - - // Marie Curie discovered radioactivity. https://en.wikipedia.org/wiki/Marie_Curie. - "curie", - - // Charles Darwin established the principles of natural evolution. https://en.wikipedia.org/wiki/Charles_Darwin. - "darwin", - - // Leonardo Da Vinci invented too many things to list here. https://en.wikipedia.org/wiki/Leonardo_da_Vinci. - "davinci", - - // Edsger Wybe Dijkstra was a Dutch computer scientist and mathematical scientist. https://en.wikipedia.org/wiki/Edsger_W._Dijkstra. - "dijkstra", - - // Donna Dubinsky - played an integral role in the development of personal digital assistants (PDAs) serving as CEO of Palm, Inc. and co-founding Handspring. https://en.wikipedia.org/wiki/Donna_Dubinsky - "dubinsky", - - // Annie Easley - She was a leading member of the team which developed software for the Centaur rocket stage and one of the first African-Americans in her field. https://en.wikipedia.org/wiki/Annie_Easley - "easley", - - // Thomas Alva Edison, prolific inventor https://en.wikipedia.org/wiki/Thomas_Edison - "edison", - - // Albert Einstein invented the general theory of relativity. https://en.wikipedia.org/wiki/Albert_Einstein - "einstein", - - // Gertrude Elion - American biochemist, pharmacologist and the 1988 recipient of the Nobel Prize in Medicine - https://en.wikipedia.org/wiki/Gertrude_Elion - "elion", - - // Douglas Engelbart gave the mother of all demos: https://en.wikipedia.org/wiki/Douglas_Engelbart - "engelbart", - - // Euclid invented geometry. https://en.wikipedia.org/wiki/Euclid - "euclid", - - // Leonhard Euler invented large parts of modern mathematics. https://de.wikipedia.org/wiki/Leonhard_Euler - "euler", - - // Pierre de Fermat pioneered several aspects of modern mathematics. https://en.wikipedia.org/wiki/Pierre_de_Fermat - "fermat", - - // Enrico Fermi invented the first nuclear reactor. https://en.wikipedia.org/wiki/Enrico_Fermi. - "fermi", - - // Richard Feynman was a key contributor to quantum mechanics and particle physics. https://en.wikipedia.org/wiki/Richard_Feynman - "feynman", - - // Benjamin Franklin is famous for his experiments in electricity and the invention of the lightning rod. - "franklin", - - // Galileo was a founding father of modern astronomy, and faced politics and obscurantism to establish scientific truth. https://en.wikipedia.org/wiki/Galileo_Galilei - "galileo", - - // William Henry "Bill" Gates III is an American business magnate, philanthropist, investor, computer programmer, and inventor. https://en.wikipedia.org/wiki/Bill_Gates - "gates", - - // Adele Goldberg, was one of the designers and developers of the Smalltalk language. https://en.wikipedia.org/wiki/Adele_Goldberg_(computer_scientist) - "goldberg", - - // Adele Goldstine, born Adele Katz, wrote the complete technical description for the first electronic digital computer, ENIAC. https://en.wikipedia.org/wiki/Adele_Goldstine - "goldstine", - - // Shafi Goldwasser is a computer scientist known for creating theoretical foundations of modern cryptography. Winner of 2012 ACM Turing Award. https://en.wikipedia.org/wiki/Shafi_Goldwasser - "goldwasser", - - // James Golick, all around gangster. - "golick", - - // Jane Goodall - British primatologist, ethologist, and anthropologist who is considered to be the world's foremost expert on chimpanzees - https://en.wikipedia.org/wiki/Jane_Goodall - "goodall", - - // Lois Haibt - American computer scientist, part of the team at IBM that developed FORTRAN - https://en.wikipedia.org/wiki/Lois_Haibt - "haibt", - - // Margaret Hamilton - Director of the Software Engineering Division of the MIT Instrumentation Laboratory, which developed on-board flight software for the Apollo space program. https://en.wikipedia.org/wiki/Margaret_Hamilton_(scientist) - "hamilton", - - // Stephen Hawking pioneered the field of cosmology by combining general relativity and quantum mechanics. https://en.wikipedia.org/wiki/Stephen_Hawking - "hawking", - - // Werner Heisenberg was a founding father of quantum mechanics. https://en.wikipedia.org/wiki/Werner_Heisenberg - "heisenberg", - - // Jaroslav Heyrovský was the inventor of the polarographic method, father of the electroanalytical method, and recipient of the Nobel Prize in 1959. His main field of work was polarography. https://en.wikipedia.org/wiki/Jaroslav_Heyrovsk%C3%BD - "heyrovsky", - - // Dorothy Hodgkin was a British biochemist, credited with the development of protein crystallography. She was awarded the Nobel Prize in Chemistry in 1964. https://en.wikipedia.org/wiki/Dorothy_Hodgkin - "hodgkin", - - // Erna Schneider Hoover revolutionized modern communication by inventing a computerized telephone switching method. https://en.wikipedia.org/wiki/Erna_Schneider_Hoover - "hoover", - - // Grace Hopper developed the first compiler for a computer programming language and is credited with popularizing the term "debugging" for fixing computer glitches. https://en.wikipedia.org/wiki/Grace_Hopper - "hopper", - - // Frances Hugle, she was an American scientist, engineer, and inventor who contributed to the understanding of semiconductors, integrated circuitry, and the unique electrical principles of microscopic materials. https://en.wikipedia.org/wiki/Frances_Hugle - "hugle", - - // Hypatia - Greek Alexandrine Neoplatonist philosopher in Egypt who was one of the earliest mothers of mathematics - https://en.wikipedia.org/wiki/Hypatia - "hypatia", - - // Yeong-Sil Jang was a Korean scientist and astronomer during the Joseon Dynasty; he invented the first metal printing press and water gauge. https://en.wikipedia.org/wiki/Jang_Yeong-sil - "jang", - - // Betty Jennings - one of the original programmers of the ENIAC. https://en.wikipedia.org/wiki/ENIAC - https://en.wikipedia.org/wiki/Jean_Bartik - "jennings", - - // Mary Lou Jepsen, was the founder and chief technology officer of One Laptop Per Child (OLPC), and the founder of Pixel Qi. https://en.wikipedia.org/wiki/Mary_Lou_Jepsen - "jepsen", - - // Irène Joliot-Curie - French scientist who was awarded the Nobel Prize for Chemistry in 1935. Daughter of Marie and Pierre Curie. https://en.wikipedia.org/wiki/Ir%C3%A8ne_Joliot-Curie - "joliot", - - // Karen Spärck Jones came up with the concept of inverse document frequency, which is used in most search engines today. https://en.wikipedia.org/wiki/Karen_Sp%C3%A4rck_Jones - "jones", - - // A. P. J. Abdul Kalam - is an Indian scientist aka Missile Man of India for his work on the development of ballistic missile and launch vehicle technology - https://en.wikipedia.org/wiki/A._P._J._Abdul_Kalam - "kalam", - - // Susan Kare, created the icons and many of the interface elements for the original Apple Macintosh in the 1980s, and was an original employee of NeXT, working as the Creative Director. https://en.wikipedia.org/wiki/Susan_Kare - "kare", - - // Mary Kenneth Keller, Sister Mary Kenneth Keller became the first American woman to earn a PhD in Computer Science in 1965. https://en.wikipedia.org/wiki/Mary_Kenneth_Keller - "keller", - - // Har Gobind Khorana - Indian-American biochemist who shared the 1968 Nobel Prize for Physiology - https://en.wikipedia.org/wiki/Har_Gobind_Khorana - "khorana", - - // Jack Kilby invented silicone integrated circuits and gave Silicon Valley its name. - https://en.wikipedia.org/wiki/Jack_Kilby - "kilby", - - // Maria Kirch - German astronomer and first woman to discover a comet - https://en.wikipedia.org/wiki/Maria_Margarethe_Kirch - "kirch", - - // Donald Knuth - American computer scientist, author of "The Art of Computer Programming" and creator of the TeX typesetting system. https://en.wikipedia.org/wiki/Donald_Knuth - "knuth", - - // Sophie Kowalevski - Russian mathematician responsible for important original contributions to analysis, differential equations and mechanics - https://en.wikipedia.org/wiki/Sofia_Kovalevskaya - "kowalevski", - - // Marie-Jeanne de Lalande - French astronomer, mathematician and cataloguer of stars - https://en.wikipedia.org/wiki/Marie-Jeanne_de_Lalande - "lalande", - - // Hedy Lamarr - Actress and inventor. The principles of her work are now incorporated into modern Wi-Fi, CDMA and Bluetooth technology. https://en.wikipedia.org/wiki/Hedy_Lamarr - "lamarr", - - // Leslie B. Lamport - American computer scientist. Lamport is best known for his seminal work in distributed systems and was the winner of the 2013 Turing Award. https://en.wikipedia.org/wiki/Leslie_Lamport - "lamport", - - // Mary Leakey - British paleoanthropologist who discovered the first fossilized Proconsul skull - https://en.wikipedia.org/wiki/Mary_Leakey - "leakey", - - // Henrietta Swan Leavitt - she was an American astronomer who discovered the relation between the luminosity and the period of Cepheid variable stars. https://en.wikipedia.org/wiki/Henrietta_Swan_Leavitt - "leavitt", - - //Daniel Lewin - Mathematician, Akamai co-founder, soldier, 9/11 victim-- Developed optimization techniques for routing traffic on the internet. Died attempting to stop the 9-11 hijackers. https://en.wikipedia.org/wiki/Daniel_Lewin - "lewin", - - // Ruth Lichterman - one of the original programmers of the ENIAC. https://en.wikipedia.org/wiki/ENIAC - https://en.wikipedia.org/wiki/Ruth_Teitelbaum - "lichterman", - - // Barbara Liskov - co-developed the Liskov substitution principle. Liskov was also the winner of the Turing Prize in 2008. - https://en.wikipedia.org/wiki/Barbara_Liskov - "liskov", - - // Ada Lovelace invented the first algorithm. https://en.wikipedia.org/wiki/Ada_Lovelace (thanks James Turnbull) - "lovelace", - - // Auguste and Louis Lumière - the first filmmakers in history - https://en.wikipedia.org/wiki/Auguste_and_Louis_Lumi%C3%A8re - "lumiere", - - // Mahavira - Ancient Indian mathematician during 9th century AD who discovered basic algebraic identities - https://en.wikipedia.org/wiki/Mah%C4%81v%C4%ABra_(mathematician) - "mahavira", - - // Maria Mayer - American theoretical physicist and Nobel laureate in Physics for proposing the nuclear shell model of the atomic nucleus - https://en.wikipedia.org/wiki/Maria_Mayer - "mayer", - - // John McCarthy invented LISP: https://en.wikipedia.org/wiki/John_McCarthy_(computer_scientist) - "mccarthy", - - // Barbara McClintock - a distinguished American cytogeneticist, 1983 Nobel Laureate in Physiology or Medicine for discovering transposons. https://en.wikipedia.org/wiki/Barbara_McClintock - "mcclintock", - - // Malcolm McLean invented the modern shipping container: https://en.wikipedia.org/wiki/Malcom_McLean - "mclean", - - // Kay McNulty - one of the original programmers of the ENIAC. https://en.wikipedia.org/wiki/ENIAC - https://en.wikipedia.org/wiki/Kathleen_Antonelli - "mcnulty", - - // Lise Meitner - Austrian/Swedish physicist who was involved in the discovery of nuclear fission. The element meitnerium is named after her - https://en.wikipedia.org/wiki/Lise_Meitner - "meitner", - - // Carla Meninsky, was the game designer and programmer for Atari 2600 games Dodge 'Em and Warlords. https://en.wikipedia.org/wiki/Carla_Meninsky - "meninsky", - - // Johanna Mestorf - German prehistoric archaeologist and first female museum director in Germany - https://en.wikipedia.org/wiki/Johanna_Mestorf - "mestorf", - - // Marvin Minsky - Pioneer in Artificial Intelligence, co-founder of the MIT's AI Lab, won the Turing Award in 1969. https://en.wikipedia.org/wiki/Marvin_Minsky - "minsky", - - // Maryam Mirzakhani - an Iranian mathematician and the first woman to win the Fields Medal. https://en.wikipedia.org/wiki/Maryam_Mirzakhani - "mirzakhani", - - // Samuel Morse - contributed to the invention of a single-wire telegraph system based on European telegraphs and was a co-developer of the Morse code - https://en.wikipedia.org/wiki/Samuel_Morse - "morse", - - // Ian Murdock - founder of the Debian project - https://en.wikipedia.org/wiki/Ian_Murdock - "murdock", - - // Isaac Newton invented classic mechanics and modern optics. https://en.wikipedia.org/wiki/Isaac_Newton - "newton", - - // Florence Nightingale, more prominently known as a nurse, was also the first female member of the Royal Statistical Society and a pioneer in statistical graphics https://en.wikipedia.org/wiki/Florence_Nightingale#Statistics_and_sanitary_reform - "nightingale", - - // Alfred Nobel - a Swedish chemist, engineer, innovator, and armaments manufacturer (inventor of dynamite) - https://en.wikipedia.org/wiki/Alfred_Nobel - "nobel", - - // Emmy Noether, German mathematician. Noether's Theorem is named after her. https://en.wikipedia.org/wiki/Emmy_Noether - "noether", - - // Poppy Northcutt. Poppy Northcutt was the first woman to work as part of NASA’s Mission Control. http://www.businessinsider.com/poppy-northcutt-helped-apollo-astronauts-2014-12?op=1 - "northcutt", - - // Robert Noyce invented silicone integrated circuits and gave Silicon Valley its name. - https://en.wikipedia.org/wiki/Robert_Noyce - "noyce", - - // Panini - Ancient Indian linguist and grammarian from 4th century CE who worked on the world's first formal system - https://en.wikipedia.org/wiki/P%C4%81%E1%B9%87ini#Comparison_with_modern_formal_systems - "panini", - - // Ambroise Pare invented modern surgery. https://en.wikipedia.org/wiki/Ambroise_Par%C3%A9 - "pare", - - // Louis Pasteur discovered vaccination, fermentation and pasteurization. https://en.wikipedia.org/wiki/Louis_Pasteur. - "pasteur", - - // Cecilia Payne-Gaposchkin was an astronomer and astrophysicist who, in 1925, proposed in her Ph.D. thesis an explanation for the composition of stars in terms of the relative abundances of hydrogen and helium. https://en.wikipedia.org/wiki/Cecilia_Payne-Gaposchkin - "payne", - - // Radia Perlman is a software designer and network engineer and most famous for her invention of the spanning-tree protocol (STP). https://en.wikipedia.org/wiki/Radia_Perlman - "perlman", - - // Rob Pike was a key contributor to Unix, Plan 9, the X graphic system, utf-8, and the Go programming language. https://en.wikipedia.org/wiki/Rob_Pike - "pike", - - // Henri Poincaré made fundamental contributions in several fields of mathematics. https://en.wikipedia.org/wiki/Henri_Poincar%C3%A9 - "poincare", - - // Laura Poitras is a director and producer whose work, made possible by open source crypto tools, advances the causes of truth and freedom of information by reporting disclosures by whistleblowers such as Edward Snowden. https://en.wikipedia.org/wiki/Laura_Poitras - "poitras", - - // Claudius Ptolemy - a Greco-Egyptian writer of Alexandria, known as a mathematician, astronomer, geographer, astrologer, and poet of a single epigram in the Greek Anthology - https://en.wikipedia.org/wiki/Ptolemy - "ptolemy", - - // C. V. Raman - Indian physicist who won the Nobel Prize in 1930 for proposing the Raman effect. - https://en.wikipedia.org/wiki/C._V._Raman - "raman", - - // Srinivasa Ramanujan - Indian mathematician and autodidact who made extraordinary contributions to mathematical analysis, number theory, infinite series, and continued fractions. - https://en.wikipedia.org/wiki/Srinivasa_Ramanujan - "ramanujan", - - // Sally Kristen Ride was an American physicist and astronaut. She was the first American woman in space, and the youngest American astronaut. https://en.wikipedia.org/wiki/Sally_Ride - "ride", - - // Rita Levi-Montalcini - Won Nobel Prize in Physiology or Medicine jointly with colleague Stanley Cohen for the discovery of nerve growth factor (https://en.wikipedia.org/wiki/Rita_Levi-Montalcini) - "montalcini", - - // Dennis Ritchie - co-creator of UNIX and the C programming language. - https://en.wikipedia.org/wiki/Dennis_Ritchie - "ritchie", - - // Wilhelm Conrad Röntgen - German physicist who was awarded the first Nobel Prize in Physics in 1901 for the discovery of X-rays (Röntgen rays). https://en.wikipedia.org/wiki/Wilhelm_R%C3%B6ntgen - "roentgen", - - // Rosalind Franklin - British biophysicist and X-ray crystallographer whose research was critical to the understanding of DNA - https://en.wikipedia.org/wiki/Rosalind_Franklin - "rosalind", - - // Meghnad Saha - Indian astrophysicist best known for his development of the Saha equation, used to describe chemical and physical conditions in stars - https://en.wikipedia.org/wiki/Meghnad_Saha - "saha", - - // Jean E. Sammet developed FORMAC, the first widely used computer language for symbolic manipulation of mathematical formulas. https://en.wikipedia.org/wiki/Jean_E._Sammet - "sammet", - - // Carol Shaw - Originally an Atari employee, Carol Shaw is said to be the first female video game designer. https://en.wikipedia.org/wiki/Carol_Shaw_(video_game_designer) - "shaw", - - // Dame Stephanie "Steve" Shirley - Founded a software company in 1962 employing women working from home. https://en.wikipedia.org/wiki/Steve_Shirley - "shirley", - - // William Shockley co-invented the transistor - https://en.wikipedia.org/wiki/William_Shockley - "shockley", - - // Françoise Barré-Sinoussi - French virologist and Nobel Prize Laureate in Physiology or Medicine; her work was fundamental in identifying HIV as the cause of AIDS. https://en.wikipedia.org/wiki/Fran%C3%A7oise_Barr%C3%A9-Sinoussi - "sinoussi", - - // Betty Snyder - one of the original programmers of the ENIAC. https://en.wikipedia.org/wiki/ENIAC - https://en.wikipedia.org/wiki/Betty_Holberton - "snyder", - - // Frances Spence - one of the original programmers of the ENIAC. https://en.wikipedia.org/wiki/ENIAC - https://en.wikipedia.org/wiki/Frances_Spence - "spence", - - // Richard Matthew Stallman - the founder of the Free Software movement, the GNU project, the Free Software Foundation, and the League for Programming Freedom. He also invented the concept of copyleft to protect the ideals of this movement, and enshrined this concept in the widely-used GPL (General Public License) for software. https://en.wikiquote.org/wiki/Richard_Stallman - "stallman", - - // Michael Stonebraker is a database research pioneer and architect of Ingres, Postgres, VoltDB and SciDB. Winner of 2014 ACM Turing Award. https://en.wikipedia.org/wiki/Michael_Stonebraker - "stonebraker", - - // Janese Swanson (with others) developed the first of the Carmen Sandiego games. She went on to found Girl Tech. https://en.wikipedia.org/wiki/Janese_Swanson - "swanson", - - // Aaron Swartz was influential in creating RSS, Markdown, Creative Commons, Reddit, and much of the internet as we know it today. He was devoted to freedom of information on the web. https://en.wikiquote.org/wiki/Aaron_Swartz - "swartz", - - // Bertha Swirles was a theoretical physicist who made a number of contributions to early quantum theory. https://en.wikipedia.org/wiki/Bertha_Swirles - "swirles", - - // Nikola Tesla invented the AC electric system and every gadget ever used by a James Bond villain. https://en.wikipedia.org/wiki/Nikola_Tesla - "tesla", - - // Ken Thompson - co-creator of UNIX and the C programming language - https://en.wikipedia.org/wiki/Ken_Thompson - "thompson", - - // Linus Torvalds invented Linux and Git. https://en.wikipedia.org/wiki/Linus_Torvalds - "torvalds", - - // Alan Turing was a founding father of computer science. https://en.wikipedia.org/wiki/Alan_Turing. - "turing", - - // Varahamihira - Ancient Indian mathematician who discovered trigonometric formulae during 505-587 CE - https://en.wikipedia.org/wiki/Var%C4%81hamihira#Contributions - "varahamihira", - - // Sir Mokshagundam Visvesvaraya - is a notable Indian engineer. He is a recipient of the Indian Republic's highest honour, the Bharat Ratna, in 1955. On his birthday, 15 September is celebrated as Engineer's Day in India in his memory - https://en.wikipedia.org/wiki/Visvesvaraya - "visvesvaraya", - - // Christiane Nüsslein-Volhard - German biologist, won Nobel Prize in Physiology or Medicine in 1995 for research on the genetic control of embryonic development. https://en.wikipedia.org/wiki/Christiane_N%C3%BCsslein-Volhard - "volhard", - - // Marlyn Wescoff - one of the original programmers of the ENIAC. https://en.wikipedia.org/wiki/ENIAC - https://en.wikipedia.org/wiki/Marlyn_Meltzer - "wescoff", - - // Andrew Wiles - Notable British mathematician who proved the enigmatic Fermat's Last Theorem - https://en.wikipedia.org/wiki/Andrew_Wiles - "wiles", - - // Roberta Williams, did pioneering work in graphical adventure games for personal computers, particularly the King's Quest series. https://en.wikipedia.org/wiki/Roberta_Williams - "williams", - - // Sophie Wilson designed the first Acorn Micro-Computer and the instruction set for ARM processors. https://en.wikipedia.org/wiki/Sophie_Wilson - "wilson", - - // Jeannette Wing - co-developed the Liskov substitution principle. - https://en.wikipedia.org/wiki/Jeannette_Wing - "wing", - - // Steve Wozniak invented the Apple I and Apple II. https://en.wikipedia.org/wiki/Steve_Wozniak - "wozniak", - - // The Wright brothers, Orville and Wilbur - credited with inventing and building the world's first successful airplane and making the first controlled, powered and sustained heavier-than-air human flight - https://en.wikipedia.org/wiki/Wright_brothers - "wright", - - // Rosalyn Sussman Yalow - Rosalyn Sussman Yalow was an American medical physicist, and a co-winner of the 1977 Nobel Prize in Physiology or Medicine for development of the radioimmunoassay technique. https://en.wikipedia.org/wiki/Rosalyn_Sussman_Yalow - "yalow", - - // Ada Yonath - an Israeli crystallographer, the first woman from the Middle East to win a Nobel prize in the sciences. https://en.wikipedia.org/wiki/Ada_Yonath - "yonath", - } -) - -// GetRandomName generates a random name from the list of adjectives and surnames in this package -// formatted as "adjective_surname". For example 'focused_turing'. If retry is non-zero, a random -// integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3` -func GetRandomName(retry int) string { - rnd := random.Rand -begin: - name := fmt.Sprintf("%s_%s", left[rnd.Intn(len(left))], right[rnd.Intn(len(right))]) - if name == "boring_wozniak" /* Steve Wozniak is not boring */ { - goto begin - } - - if retry > 0 { - name = fmt.Sprintf("%s%d", name, rnd.Intn(10)) - } - return name -} diff --git a/vendor/github.com/docker/docker/pkg/namesgenerator/names-generator_test.go b/vendor/github.com/docker/docker/pkg/namesgenerator/names-generator_test.go deleted file mode 100644 index d1a9497..0000000 --- a/vendor/github.com/docker/docker/pkg/namesgenerator/names-generator_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package namesgenerator - -import ( - "strings" - "testing" -) - -func TestNameFormat(t *testing.T) { - name := GetRandomName(0) - if !strings.Contains(name, "_") { - t.Fatalf("Generated name does not contain an underscore") - } - if strings.ContainsAny(name, "0123456789") { - t.Fatalf("Generated name contains numbers!") - } -} - -func TestNameRetries(t *testing.T) { - name := GetRandomName(1) - if !strings.Contains(name, "_") { - t.Fatalf("Generated name does not contain an underscore") - } - if !strings.ContainsAny(name, "0123456789") { - t.Fatalf("Generated name doesn't contain a number") - } - -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel.go b/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel.go deleted file mode 100644 index 7738fc7..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel.go +++ /dev/null @@ -1,74 +0,0 @@ -// +build !windows - -// Package kernel provides helper function to get, parse and compare kernel -// versions for different platforms. -package kernel - -import ( - "errors" - "fmt" -) - -// VersionInfo holds information about the kernel. -type VersionInfo struct { - Kernel int // Version of the kernel (e.g. 4.1.2-generic -> 4) - Major int // Major part of the kernel version (e.g. 4.1.2-generic -> 1) - Minor int // Minor part of the kernel version (e.g. 4.1.2-generic -> 2) - Flavor string // Flavor of the kernel version (e.g. 4.1.2-generic -> generic) -} - -func (k *VersionInfo) String() string { - return fmt.Sprintf("%d.%d.%d%s", k.Kernel, k.Major, k.Minor, k.Flavor) -} - -// CompareKernelVersion compares two kernel.VersionInfo structs. -// Returns -1 if a < b, 0 if a == b, 1 it a > b -func CompareKernelVersion(a, b VersionInfo) int { - if a.Kernel < b.Kernel { - return -1 - } else if a.Kernel > b.Kernel { - return 1 - } - - if a.Major < b.Major { - return -1 - } else if a.Major > b.Major { - return 1 - } - - if a.Minor < b.Minor { - return -1 - } else if a.Minor > b.Minor { - return 1 - } - - return 0 -} - -// ParseRelease parses a string and creates a VersionInfo based on it. -func ParseRelease(release string) (*VersionInfo, error) { - var ( - kernel, major, minor, parsed int - flavor, partial string - ) - - // Ignore error from Sscanf to allow an empty flavor. Instead, just - // make sure we got all the version numbers. - parsed, _ = fmt.Sscanf(release, "%d.%d%s", &kernel, &major, &partial) - if parsed < 2 { - return nil, errors.New("Can't parse kernel version " + release) - } - - // sometimes we have 3.12.25-gentoo, but sometimes we just have 3.12-1-amd64 - parsed, _ = fmt.Sscanf(partial, ".%d%s", &minor, &flavor) - if parsed < 1 { - flavor = partial - } - - return &VersionInfo{ - Kernel: kernel, - Major: major, - Minor: minor, - Flavor: flavor, - }, nil -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_darwin.go b/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_darwin.go deleted file mode 100644 index 71f205b..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_darwin.go +++ /dev/null @@ -1,56 +0,0 @@ -// +build darwin - -// Package kernel provides helper function to get, parse and compare kernel -// versions for different platforms. -package kernel - -import ( - "fmt" - "os/exec" - "strings" - - "github.com/mattn/go-shellwords" -) - -// GetKernelVersion gets the current kernel version. -func GetKernelVersion() (*VersionInfo, error) { - release, err := getRelease() - if err != nil { - return nil, err - } - - return ParseRelease(release) -} - -// getRelease uses `system_profiler SPSoftwareDataType` to get OSX kernel version -func getRelease() (string, error) { - cmd := exec.Command("system_profiler", "SPSoftwareDataType") - osName, err := cmd.Output() - if err != nil { - return "", err - } - - var release string - data := strings.Split(string(osName), "\n") - for _, line := range data { - if strings.Contains(line, "Kernel Version") { - // It has the format like ' Kernel Version: Darwin 14.5.0' - content := strings.SplitN(line, ":", 2) - if len(content) != 2 { - return "", fmt.Errorf("Kernel Version is invalid") - } - - prettyNames, err := shellwords.Parse(content[1]) - if err != nil { - return "", fmt.Errorf("Kernel Version is invalid: %s", err.Error()) - } - - if len(prettyNames) != 2 { - return "", fmt.Errorf("Kernel Version needs to be 'Darwin x.x.x' ") - } - release = prettyNames[1] - } - } - - return release, nil -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_unix.go b/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_unix.go deleted file mode 100644 index 744d5e1..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_unix.go +++ /dev/null @@ -1,45 +0,0 @@ -// +build linux freebsd solaris - -// Package kernel provides helper function to get, parse and compare kernel -// versions for different platforms. -package kernel - -import ( - "bytes" - - "github.com/Sirupsen/logrus" -) - -// GetKernelVersion gets the current kernel version. -func GetKernelVersion() (*VersionInfo, error) { - uts, err := uname() - if err != nil { - return nil, err - } - - release := make([]byte, len(uts.Release)) - - i := 0 - for _, c := range uts.Release { - release[i] = byte(c) - i++ - } - - // Remove the \x00 from the release for Atoi to parse correctly - release = release[:bytes.IndexByte(release, 0)] - - return ParseRelease(string(release)) -} - -// CheckKernelVersion checks if current kernel is newer than (or equal to) -// the given version. -func CheckKernelVersion(k, major, minor int) bool { - if v, err := GetKernelVersion(); err != nil { - logrus.Warnf("error getting kernel version: %s", err) - } else { - if CompareKernelVersion(*v, VersionInfo{Kernel: k, Major: major, Minor: minor}) < 0 { - return false - } - } - return true -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_unix_test.go b/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_unix_test.go deleted file mode 100644 index dc8c0e3..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_unix_test.go +++ /dev/null @@ -1,96 +0,0 @@ -// +build !windows - -package kernel - -import ( - "fmt" - "testing" -) - -func assertParseRelease(t *testing.T, release string, b *VersionInfo, result int) { - var ( - a *VersionInfo - ) - a, _ = ParseRelease(release) - - if r := CompareKernelVersion(*a, *b); r != result { - t.Fatalf("Unexpected kernel version comparison result for (%v,%v). Found %d, expected %d", release, b, r, result) - } - if a.Flavor != b.Flavor { - t.Fatalf("Unexpected parsed kernel flavor. Found %s, expected %s", a.Flavor, b.Flavor) - } -} - -// TestParseRelease tests the ParseRelease() function -func TestParseRelease(t *testing.T) { - assertParseRelease(t, "3.8.0", &VersionInfo{Kernel: 3, Major: 8, Minor: 0}, 0) - assertParseRelease(t, "3.4.54.longterm-1", &VersionInfo{Kernel: 3, Major: 4, Minor: 54, Flavor: ".longterm-1"}, 0) - assertParseRelease(t, "3.4.54.longterm-1", &VersionInfo{Kernel: 3, Major: 4, Minor: 54, Flavor: ".longterm-1"}, 0) - assertParseRelease(t, "3.8.0-19-generic", &VersionInfo{Kernel: 3, Major: 8, Minor: 0, Flavor: "-19-generic"}, 0) - assertParseRelease(t, "3.12.8tag", &VersionInfo{Kernel: 3, Major: 12, Minor: 8, Flavor: "tag"}, 0) - assertParseRelease(t, "3.12-1-amd64", &VersionInfo{Kernel: 3, Major: 12, Minor: 0, Flavor: "-1-amd64"}, 0) - assertParseRelease(t, "3.8.0", &VersionInfo{Kernel: 4, Major: 8, Minor: 0}, -1) - // Errors - invalids := []string{ - "3", - "a", - "a.a", - "a.a.a-a", - } - for _, invalid := range invalids { - expectedMessage := fmt.Sprintf("Can't parse kernel version %v", invalid) - if _, err := ParseRelease(invalid); err == nil || err.Error() != expectedMessage { - - } - } -} - -func assertKernelVersion(t *testing.T, a, b VersionInfo, result int) { - if r := CompareKernelVersion(a, b); r != result { - t.Fatalf("Unexpected kernel version comparison result. Found %d, expected %d", r, result) - } -} - -// TestCompareKernelVersion tests the CompareKernelVersion() function -func TestCompareKernelVersion(t *testing.T) { - assertKernelVersion(t, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - 0) - assertKernelVersion(t, - VersionInfo{Kernel: 2, Major: 6, Minor: 0}, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - -1) - assertKernelVersion(t, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - VersionInfo{Kernel: 2, Major: 6, Minor: 0}, - 1) - assertKernelVersion(t, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - 0) - assertKernelVersion(t, - VersionInfo{Kernel: 3, Major: 8, Minor: 5}, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - 1) - assertKernelVersion(t, - VersionInfo{Kernel: 3, Major: 0, Minor: 20}, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - -1) - assertKernelVersion(t, - VersionInfo{Kernel: 3, Major: 7, Minor: 20}, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - -1) - assertKernelVersion(t, - VersionInfo{Kernel: 3, Major: 8, Minor: 20}, - VersionInfo{Kernel: 3, Major: 7, Minor: 0}, - 1) - assertKernelVersion(t, - VersionInfo{Kernel: 3, Major: 8, Minor: 20}, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - 1) - assertKernelVersion(t, - VersionInfo{Kernel: 3, Major: 8, Minor: 0}, - VersionInfo{Kernel: 3, Major: 8, Minor: 20}, - -1) -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_windows.go b/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_windows.go deleted file mode 100644 index 80fab8f..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/kernel/kernel_windows.go +++ /dev/null @@ -1,69 +0,0 @@ -// +build windows - -package kernel - -import ( - "fmt" - "syscall" - "unsafe" -) - -// VersionInfo holds information about the kernel. -type VersionInfo struct { - kvi string // Version of the kernel (e.g. 6.1.7601.17592 -> 6) - major int // Major part of the kernel version (e.g. 6.1.7601.17592 -> 1) - minor int // Minor part of the kernel version (e.g. 6.1.7601.17592 -> 7601) - build int // Build number of the kernel version (e.g. 6.1.7601.17592 -> 17592) -} - -func (k *VersionInfo) String() string { - return fmt.Sprintf("%d.%d %d (%s)", k.major, k.minor, k.build, k.kvi) -} - -// GetKernelVersion gets the current kernel version. -func GetKernelVersion() (*VersionInfo, error) { - - var ( - h syscall.Handle - dwVersion uint32 - err error - ) - - KVI := &VersionInfo{"Unknown", 0, 0, 0} - - if err = syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, - syscall.StringToUTF16Ptr(`SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\`), - 0, - syscall.KEY_READ, - &h); err != nil { - return KVI, err - } - defer syscall.RegCloseKey(h) - - var buf [1 << 10]uint16 - var typ uint32 - n := uint32(len(buf) * 2) // api expects array of bytes, not uint16 - - if err = syscall.RegQueryValueEx(h, - syscall.StringToUTF16Ptr("BuildLabEx"), - nil, - &typ, - (*byte)(unsafe.Pointer(&buf[0])), - &n); err != nil { - return KVI, err - } - - KVI.kvi = syscall.UTF16ToString(buf[:]) - - // Important - docker.exe MUST be manifested for this API to return - // the correct information. - if dwVersion, err = syscall.GetVersion(); err != nil { - return KVI, err - } - - KVI.major = int(dwVersion & 0xFF) - KVI.minor = int((dwVersion & 0XFF00) >> 8) - KVI.build = int((dwVersion & 0xFFFF0000) >> 16) - - return KVI, nil -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/kernel/uname_linux.go b/vendor/github.com/docker/docker/pkg/parsers/kernel/uname_linux.go deleted file mode 100644 index bb9b326..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/kernel/uname_linux.go +++ /dev/null @@ -1,19 +0,0 @@ -package kernel - -import ( - "syscall" -) - -// Utsname represents the system name structure. -// It is passthrough for syscall.Utsname in order to make it portable with -// other platforms where it is not available. -type Utsname syscall.Utsname - -func uname() (*syscall.Utsname, error) { - uts := &syscall.Utsname{} - - if err := syscall.Uname(uts); err != nil { - return nil, err - } - return uts, nil -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/kernel/uname_solaris.go b/vendor/github.com/docker/docker/pkg/parsers/kernel/uname_solaris.go deleted file mode 100644 index 49370bd..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/kernel/uname_solaris.go +++ /dev/null @@ -1,14 +0,0 @@ -package kernel - -import ( - "golang.org/x/sys/unix" -) - -func uname() (*unix.Utsname, error) { - uts := &unix.Utsname{} - - if err := unix.Uname(uts); err != nil { - return nil, err - } - return uts, nil -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/kernel/uname_unsupported.go b/vendor/github.com/docker/docker/pkg/parsers/kernel/uname_unsupported.go deleted file mode 100644 index 1da3f23..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/kernel/uname_unsupported.go +++ /dev/null @@ -1,18 +0,0 @@ -// +build !linux,!solaris - -package kernel - -import ( - "errors" -) - -// Utsname represents the system name structure. -// It is defined here to make it portable as it is available on linux but not -// on windows. -type Utsname struct { - Release [65]byte -} - -func uname() (*Utsname, error) { - return nil, errors.New("Kernel version detection is available only on linux") -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_linux.go b/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_linux.go deleted file mode 100644 index e04a349..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_linux.go +++ /dev/null @@ -1,77 +0,0 @@ -// Package operatingsystem provides helper function to get the operating system -// name for different platforms. -package operatingsystem - -import ( - "bufio" - "bytes" - "fmt" - "io/ioutil" - "os" - "strings" - - "github.com/mattn/go-shellwords" -) - -var ( - // file to use to detect if the daemon is running in a container - proc1Cgroup = "/proc/1/cgroup" - - // file to check to determine Operating System - etcOsRelease = "/etc/os-release" - - // used by stateless systems like Clear Linux - altOsRelease = "/usr/lib/os-release" -) - -// GetOperatingSystem gets the name of the current operating system. -func GetOperatingSystem() (string, error) { - osReleaseFile, err := os.Open(etcOsRelease) - if err != nil { - if !os.IsNotExist(err) { - return "", fmt.Errorf("Error opening %s: %v", etcOsRelease, err) - } - osReleaseFile, err = os.Open(altOsRelease) - if err != nil { - return "", fmt.Errorf("Error opening %s: %v", altOsRelease, err) - } - } - defer osReleaseFile.Close() - - var prettyName string - scanner := bufio.NewScanner(osReleaseFile) - for scanner.Scan() { - line := scanner.Text() - if strings.HasPrefix(line, "PRETTY_NAME=") { - data := strings.SplitN(line, "=", 2) - prettyNames, err := shellwords.Parse(data[1]) - if err != nil { - return "", fmt.Errorf("PRETTY_NAME is invalid: %s", err.Error()) - } - if len(prettyNames) != 1 { - return "", fmt.Errorf("PRETTY_NAME needs to be enclosed by quotes if they have spaces: %s", data[1]) - } - prettyName = prettyNames[0] - } - } - if prettyName != "" { - return prettyName, nil - } - // If not set, defaults to PRETTY_NAME="Linux" - // c.f. http://www.freedesktop.org/software/systemd/man/os-release.html - return "Linux", nil -} - -// IsContainerized returns true if we are running inside a container. -func IsContainerized() (bool, error) { - b, err := ioutil.ReadFile(proc1Cgroup) - if err != nil { - return false, err - } - for _, line := range bytes.Split(b, []byte{'\n'}) { - if len(line) > 0 && !bytes.HasSuffix(line, []byte{'/'}) && !bytes.HasSuffix(line, []byte("init.scope")) { - return true, nil - } - } - return false, nil -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_solaris.go b/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_solaris.go deleted file mode 100644 index d08ad14..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_solaris.go +++ /dev/null @@ -1,37 +0,0 @@ -// +build solaris,cgo - -package operatingsystem - -/* -#include -*/ -import "C" - -import ( - "bytes" - "errors" - "io/ioutil" -) - -var etcOsRelease = "/etc/release" - -// GetOperatingSystem gets the name of the current operating system. -func GetOperatingSystem() (string, error) { - b, err := ioutil.ReadFile(etcOsRelease) - if err != nil { - return "", err - } - if i := bytes.Index(b, []byte("\n")); i >= 0 { - b = bytes.Trim(b[:i], " ") - return string(b), nil - } - return "", errors.New("release not found") -} - -// IsContainerized returns true if we are running inside a container. -func IsContainerized() (bool, error) { - if C.getzoneid() != 0 { - return true, nil - } - return false, nil -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_unix.go b/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_unix.go deleted file mode 100644 index bc91c3c..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_unix.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build freebsd darwin - -package operatingsystem - -import ( - "errors" - "os/exec" -) - -// GetOperatingSystem gets the name of the current operating system. -func GetOperatingSystem() (string, error) { - cmd := exec.Command("uname", "-s") - osName, err := cmd.Output() - if err != nil { - return "", err - } - return string(osName), nil -} - -// IsContainerized returns true if we are running inside a container. -// No-op on FreeBSD and Darwin, always returns false. -func IsContainerized() (bool, error) { - // TODO: Implement jail detection for freeBSD - return false, errors.New("Cannot detect if we are in container") -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_unix_test.go b/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_unix_test.go deleted file mode 100644 index e7120c6..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_unix_test.go +++ /dev/null @@ -1,247 +0,0 @@ -// +build linux freebsd - -package operatingsystem - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func TestGetOperatingSystem(t *testing.T) { - var backup = etcOsRelease - - invalids := []struct { - content string - errorExpected string - }{ - { - `PRETTY_NAME=Source Mage GNU/Linux -PRETTY_NAME=Ubuntu 14.04.LTS`, - "PRETTY_NAME needs to be enclosed by quotes if they have spaces: Source Mage GNU/Linux", - }, - { - `PRETTY_NAME="Ubuntu Linux -PRETTY_NAME=Ubuntu 14.04.LTS`, - "PRETTY_NAME is invalid: invalid command line string", - }, - { - `PRETTY_NAME=Ubuntu' -PRETTY_NAME=Ubuntu 14.04.LTS`, - "PRETTY_NAME is invalid: invalid command line string", - }, - { - `PRETTY_NAME' -PRETTY_NAME=Ubuntu 14.04.LTS`, - "PRETTY_NAME needs to be enclosed by quotes if they have spaces: Ubuntu 14.04.LTS", - }, - } - - valids := []struct { - content string - expected string - }{ - { - `NAME="Ubuntu" -PRETTY_NAME_AGAIN="Ubuntu 14.04.LTS" -VERSION="14.04, Trusty Tahr" -ID=ubuntu -ID_LIKE=debian -VERSION_ID="14.04" -HOME_URL="http://www.ubuntu.com/" -SUPPORT_URL="http://help.ubuntu.com/" -BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"`, - "Linux", - }, - { - `NAME="Ubuntu" -VERSION="14.04, Trusty Tahr" -ID=ubuntu -ID_LIKE=debian -VERSION_ID="14.04" -HOME_URL="http://www.ubuntu.com/" -SUPPORT_URL="http://help.ubuntu.com/" -BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"`, - "Linux", - }, - { - `NAME=Gentoo -ID=gentoo -PRETTY_NAME="Gentoo/Linux" -ANSI_COLOR="1;32" -HOME_URL="http://www.gentoo.org/" -SUPPORT_URL="http://www.gentoo.org/main/en/support.xml" -BUG_REPORT_URL="https://bugs.gentoo.org/" -`, - "Gentoo/Linux", - }, - { - `NAME="Ubuntu" -VERSION="14.04, Trusty Tahr" -ID=ubuntu -ID_LIKE=debian -PRETTY_NAME="Ubuntu 14.04 LTS" -VERSION_ID="14.04" -HOME_URL="http://www.ubuntu.com/" -SUPPORT_URL="http://help.ubuntu.com/" -BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"`, - "Ubuntu 14.04 LTS", - }, - { - `NAME="Ubuntu" -VERSION="14.04, Trusty Tahr" -ID=ubuntu -ID_LIKE=debian -PRETTY_NAME='Ubuntu 14.04 LTS'`, - "Ubuntu 14.04 LTS", - }, - { - `PRETTY_NAME=Source -NAME="Source Mage"`, - "Source", - }, - { - `PRETTY_NAME=Source -PRETTY_NAME="Source Mage"`, - "Source Mage", - }, - } - - dir := os.TempDir() - etcOsRelease = filepath.Join(dir, "etcOsRelease") - - defer func() { - os.Remove(etcOsRelease) - etcOsRelease = backup - }() - - for _, elt := range invalids { - if err := ioutil.WriteFile(etcOsRelease, []byte(elt.content), 0600); err != nil { - t.Fatalf("failed to write to %s: %v", etcOsRelease, err) - } - s, err := GetOperatingSystem() - if err == nil || err.Error() != elt.errorExpected { - t.Fatalf("Expected an error %q, got %q (err: %v)", elt.errorExpected, s, err) - } - } - - for _, elt := range valids { - if err := ioutil.WriteFile(etcOsRelease, []byte(elt.content), 0600); err != nil { - t.Fatalf("failed to write to %s: %v", etcOsRelease, err) - } - s, err := GetOperatingSystem() - if err != nil || s != elt.expected { - t.Fatalf("Expected %q, got %q (err: %v)", elt.expected, s, err) - } - } -} - -func TestIsContainerized(t *testing.T) { - var ( - backup = proc1Cgroup - nonContainerizedProc1Cgroupsystemd226 = []byte(`9:memory:/init.scope -8:net_cls,net_prio:/ -7:cpuset:/ -6:freezer:/ -5:devices:/init.scope -4:blkio:/init.scope -3:cpu,cpuacct:/init.scope -2:perf_event:/ -1:name=systemd:/init.scope -`) - nonContainerizedProc1Cgroup = []byte(`14:name=systemd:/ -13:hugetlb:/ -12:net_prio:/ -11:perf_event:/ -10:bfqio:/ -9:blkio:/ -8:net_cls:/ -7:freezer:/ -6:devices:/ -5:memory:/ -4:cpuacct:/ -3:cpu:/ -2:cpuset:/ -`) - containerizedProc1Cgroup = []byte(`9:perf_event:/docker/3cef1b53c50b0fa357d994f8a1a8cd783c76bbf4f5dd08b226e38a8bd331338d -8:blkio:/docker/3cef1b53c50b0fa357d994f8a1a8cd783c76bbf4f5dd08b226e38a8bd331338d -7:net_cls:/ -6:freezer:/docker/3cef1b53c50b0fa357d994f8a1a8cd783c76bbf4f5dd08b226e38a8bd331338d -5:devices:/docker/3cef1b53c50b0fa357d994f8a1a8cd783c76bbf4f5dd08b226e38a8bd331338d -4:memory:/docker/3cef1b53c50b0fa357d994f8a1a8cd783c76bbf4f5dd08b226e38a8bd331338d -3:cpuacct:/docker/3cef1b53c50b0fa357d994f8a1a8cd783c76bbf4f5dd08b226e38a8bd331338d -2:cpu:/docker/3cef1b53c50b0fa357d994f8a1a8cd783c76bbf4f5dd08b226e38a8bd331338d -1:cpuset:/`) - ) - - dir := os.TempDir() - proc1Cgroup = filepath.Join(dir, "proc1Cgroup") - - defer func() { - os.Remove(proc1Cgroup) - proc1Cgroup = backup - }() - - if err := ioutil.WriteFile(proc1Cgroup, nonContainerizedProc1Cgroup, 0600); err != nil { - t.Fatalf("failed to write to %s: %v", proc1Cgroup, err) - } - inContainer, err := IsContainerized() - if err != nil { - t.Fatal(err) - } - if inContainer { - t.Fatal("Wrongly assuming containerized") - } - - if err := ioutil.WriteFile(proc1Cgroup, nonContainerizedProc1Cgroupsystemd226, 0600); err != nil { - t.Fatalf("failed to write to %s: %v", proc1Cgroup, err) - } - inContainer, err = IsContainerized() - if err != nil { - t.Fatal(err) - } - if inContainer { - t.Fatal("Wrongly assuming containerized for systemd /init.scope cgroup layout") - } - - if err := ioutil.WriteFile(proc1Cgroup, containerizedProc1Cgroup, 0600); err != nil { - t.Fatalf("failed to write to %s: %v", proc1Cgroup, err) - } - inContainer, err = IsContainerized() - if err != nil { - t.Fatal(err) - } - if !inContainer { - t.Fatal("Wrongly assuming non-containerized") - } -} - -func TestOsReleaseFallback(t *testing.T) { - var backup = etcOsRelease - var altBackup = altOsRelease - dir := os.TempDir() - etcOsRelease = filepath.Join(dir, "etcOsRelease") - altOsRelease = filepath.Join(dir, "altOsRelease") - - defer func() { - os.Remove(dir) - etcOsRelease = backup - altOsRelease = altBackup - }() - content := `NAME=Gentoo -ID=gentoo -PRETTY_NAME="Gentoo/Linux" -ANSI_COLOR="1;32" -HOME_URL="http://www.gentoo.org/" -SUPPORT_URL="http://www.gentoo.org/main/en/support.xml" -BUG_REPORT_URL="https://bugs.gentoo.org/" -` - if err := ioutil.WriteFile(altOsRelease, []byte(content), 0600); err != nil { - t.Fatalf("failed to write to %s: %v", etcOsRelease, err) - } - s, err := GetOperatingSystem() - if err != nil || s != "Gentoo/Linux" { - t.Fatalf("Expected %q, got %q (err: %v)", "Gentoo/Linux", s, err) - } -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_windows.go b/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_windows.go deleted file mode 100644 index 3c86b6a..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/operatingsystem/operatingsystem_windows.go +++ /dev/null @@ -1,49 +0,0 @@ -package operatingsystem - -import ( - "syscall" - "unsafe" -) - -// See https://code.google.com/p/go/source/browse/src/pkg/mime/type_windows.go?r=d14520ac25bf6940785aabb71f5be453a286f58c -// for a similar sample - -// GetOperatingSystem gets the name of the current operating system. -func GetOperatingSystem() (string, error) { - - var h syscall.Handle - - // Default return value - ret := "Unknown Operating System" - - if err := syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, - syscall.StringToUTF16Ptr(`SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\`), - 0, - syscall.KEY_READ, - &h); err != nil { - return ret, err - } - defer syscall.RegCloseKey(h) - - var buf [1 << 10]uint16 - var typ uint32 - n := uint32(len(buf) * 2) // api expects array of bytes, not uint16 - - if err := syscall.RegQueryValueEx(h, - syscall.StringToUTF16Ptr("ProductName"), - nil, - &typ, - (*byte)(unsafe.Pointer(&buf[0])), - &n); err != nil { - return ret, err - } - ret = syscall.UTF16ToString(buf[:]) - - return ret, nil -} - -// IsContainerized returns true if we are running inside a container. -// No-op on Windows, always returns false. -func IsContainerized() (bool, error) { - return false, nil -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/parsers.go b/vendor/github.com/docker/docker/pkg/parsers/parsers.go deleted file mode 100644 index acc8971..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/parsers.go +++ /dev/null @@ -1,69 +0,0 @@ -// Package parsers provides helper functions to parse and validate different type -// of string. It can be hosts, unix addresses, tcp addresses, filters, kernel -// operating system versions. -package parsers - -import ( - "fmt" - "strconv" - "strings" -) - -// ParseKeyValueOpt parses and validates the specified string as a key/value pair (key=value) -func ParseKeyValueOpt(opt string) (string, string, error) { - parts := strings.SplitN(opt, "=", 2) - if len(parts) != 2 { - return "", "", fmt.Errorf("Unable to parse key/value option: %s", opt) - } - return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]), nil -} - -// ParseUintList parses and validates the specified string as the value -// found in some cgroup file (e.g. `cpuset.cpus`, `cpuset.mems`), which could be -// one of the formats below. Note that duplicates are actually allowed in the -// input string. It returns a `map[int]bool` with available elements from `val` -// set to `true`. -// Supported formats: -// 7 -// 1-6 -// 0,3-4,7,8-10 -// 0-0,0,1-7 -// 03,1-3 <- this is gonna get parsed as [1,2,3] -// 3,2,1 -// 0-2,3,1 -func ParseUintList(val string) (map[int]bool, error) { - if val == "" { - return map[int]bool{}, nil - } - - availableInts := make(map[int]bool) - split := strings.Split(val, ",") - errInvalidFormat := fmt.Errorf("invalid format: %s", val) - - for _, r := range split { - if !strings.Contains(r, "-") { - v, err := strconv.Atoi(r) - if err != nil { - return nil, errInvalidFormat - } - availableInts[v] = true - } else { - split := strings.SplitN(r, "-", 2) - min, err := strconv.Atoi(split[0]) - if err != nil { - return nil, errInvalidFormat - } - max, err := strconv.Atoi(split[1]) - if err != nil { - return nil, errInvalidFormat - } - if max < min { - return nil, errInvalidFormat - } - for i := min; i <= max; i++ { - availableInts[i] = true - } - } - } - return availableInts, nil -} diff --git a/vendor/github.com/docker/docker/pkg/parsers/parsers_test.go b/vendor/github.com/docker/docker/pkg/parsers/parsers_test.go deleted file mode 100644 index 7f19e90..0000000 --- a/vendor/github.com/docker/docker/pkg/parsers/parsers_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package parsers - -import ( - "reflect" - "testing" -) - -func TestParseKeyValueOpt(t *testing.T) { - invalids := map[string]string{ - "": "Unable to parse key/value option: ", - "key": "Unable to parse key/value option: key", - } - for invalid, expectedError := range invalids { - if _, _, err := ParseKeyValueOpt(invalid); err == nil || err.Error() != expectedError { - t.Fatalf("Expected error %v for %v, got %v", expectedError, invalid, err) - } - } - valids := map[string][]string{ - "key=value": {"key", "value"}, - " key = value ": {"key", "value"}, - "key=value1=value2": {"key", "value1=value2"}, - " key = value1 = value2 ": {"key", "value1 = value2"}, - } - for valid, expectedKeyValue := range valids { - key, value, err := ParseKeyValueOpt(valid) - if err != nil { - t.Fatal(err) - } - if key != expectedKeyValue[0] || value != expectedKeyValue[1] { - t.Fatalf("Expected {%v: %v} got {%v: %v}", expectedKeyValue[0], expectedKeyValue[1], key, value) - } - } -} - -func TestParseUintList(t *testing.T) { - valids := map[string]map[int]bool{ - "": {}, - "7": {7: true}, - "1-6": {1: true, 2: true, 3: true, 4: true, 5: true, 6: true}, - "0-7": {0: true, 1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true}, - "0,3-4,7,8-10": {0: true, 3: true, 4: true, 7: true, 8: true, 9: true, 10: true}, - "0-0,0,1-4": {0: true, 1: true, 2: true, 3: true, 4: true}, - "03,1-3": {1: true, 2: true, 3: true}, - "3,2,1": {1: true, 2: true, 3: true}, - "0-2,3,1": {0: true, 1: true, 2: true, 3: true}, - } - for k, v := range valids { - out, err := ParseUintList(k) - if err != nil { - t.Fatalf("Expected not to fail, got %v", err) - } - if !reflect.DeepEqual(out, v) { - t.Fatalf("Expected %v, got %v", v, out) - } - } - - invalids := []string{ - "this", - "1--", - "1-10,,10", - "10-1", - "-1", - "-1,0", - } - for _, v := range invalids { - if out, err := ParseUintList(v); err == nil { - t.Fatalf("Expected failure with %s but got %v", v, out) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/pidfile/pidfile.go b/vendor/github.com/docker/docker/pkg/pidfile/pidfile.go deleted file mode 100644 index d832fea..0000000 --- a/vendor/github.com/docker/docker/pkg/pidfile/pidfile.go +++ /dev/null @@ -1,56 +0,0 @@ -// Package pidfile provides structure and helper functions to create and remove -// PID file. A PID file is usually a file used to store the process ID of a -// running process. -package pidfile - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strconv" - "strings" - - "github.com/docker/docker/pkg/system" -) - -// PIDFile is a file used to store the process ID of a running process. -type PIDFile struct { - path string -} - -func checkPIDFileAlreadyExists(path string) error { - if pidByte, err := ioutil.ReadFile(path); err == nil { - pidString := strings.TrimSpace(string(pidByte)) - if pid, err := strconv.Atoi(pidString); err == nil { - if processExists(pid) { - return fmt.Errorf("pid file found, ensure docker is not running or delete %s", path) - } - } - } - return nil -} - -// New creates a PIDfile using the specified path. -func New(path string) (*PIDFile, error) { - if err := checkPIDFileAlreadyExists(path); err != nil { - return nil, err - } - // Note MkdirAll returns nil if a directory already exists - if err := system.MkdirAll(filepath.Dir(path), os.FileMode(0755)); err != nil { - return nil, err - } - if err := ioutil.WriteFile(path, []byte(fmt.Sprintf("%d", os.Getpid())), 0644); err != nil { - return nil, err - } - - return &PIDFile{path: path}, nil -} - -// Remove removes the PIDFile. -func (file PIDFile) Remove() error { - if err := os.Remove(file.path); err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/pidfile/pidfile_darwin.go b/vendor/github.com/docker/docker/pkg/pidfile/pidfile_darwin.go deleted file mode 100644 index 5c1cd7a..0000000 --- a/vendor/github.com/docker/docker/pkg/pidfile/pidfile_darwin.go +++ /dev/null @@ -1,18 +0,0 @@ -// +build darwin - -package pidfile - -import ( - "syscall" -) - -func processExists(pid int) bool { - // OS X does not have a proc filesystem. - // Use kill -0 pid to judge if the process exists. - err := syscall.Kill(pid, 0) - if err != nil { - return false - } - - return true -} diff --git a/vendor/github.com/docker/docker/pkg/pidfile/pidfile_test.go b/vendor/github.com/docker/docker/pkg/pidfile/pidfile_test.go deleted file mode 100644 index 73e8af7..0000000 --- a/vendor/github.com/docker/docker/pkg/pidfile/pidfile_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package pidfile - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func TestNewAndRemove(t *testing.T) { - dir, err := ioutil.TempDir(os.TempDir(), "test-pidfile") - if err != nil { - t.Fatal("Could not create test directory") - } - - path := filepath.Join(dir, "testfile") - file, err := New(path) - if err != nil { - t.Fatal("Could not create test file", err) - } - - _, err = New(path) - if err == nil { - t.Fatal("Test file creation not blocked") - } - - if err := file.Remove(); err != nil { - t.Fatal("Could not delete created test file") - } -} - -func TestRemoveInvalidPath(t *testing.T) { - file := PIDFile{path: filepath.Join("foo", "bar")} - - if err := file.Remove(); err == nil { - t.Fatal("Non-existing file doesn't give an error on delete") - } -} diff --git a/vendor/github.com/docker/docker/pkg/pidfile/pidfile_unix.go b/vendor/github.com/docker/docker/pkg/pidfile/pidfile_unix.go deleted file mode 100644 index 1bf5221..0000000 --- a/vendor/github.com/docker/docker/pkg/pidfile/pidfile_unix.go +++ /dev/null @@ -1,16 +0,0 @@ -// +build !windows,!darwin - -package pidfile - -import ( - "os" - "path/filepath" - "strconv" -) - -func processExists(pid int) bool { - if _, err := os.Stat(filepath.Join("/proc", strconv.Itoa(pid))); err == nil { - return true - } - return false -} diff --git a/vendor/github.com/docker/docker/pkg/pidfile/pidfile_windows.go b/vendor/github.com/docker/docker/pkg/pidfile/pidfile_windows.go deleted file mode 100644 index ae489c6..0000000 --- a/vendor/github.com/docker/docker/pkg/pidfile/pidfile_windows.go +++ /dev/null @@ -1,23 +0,0 @@ -package pidfile - -import "syscall" - -const ( - processQueryLimitedInformation = 0x1000 - - stillActive = 259 -) - -func processExists(pid int) bool { - h, err := syscall.OpenProcess(processQueryLimitedInformation, false, uint32(pid)) - if err != nil { - return false - } - var c uint32 - err = syscall.GetExitCodeProcess(h, &c) - syscall.Close(h) - if err != nil { - return c == stillActive - } - return true -} diff --git a/vendor/github.com/docker/docker/pkg/platform/architecture_linux.go b/vendor/github.com/docker/docker/pkg/platform/architecture_linux.go deleted file mode 100644 index 2cdc2c5..0000000 --- a/vendor/github.com/docker/docker/pkg/platform/architecture_linux.go +++ /dev/null @@ -1,16 +0,0 @@ -// Package platform provides helper function to get the runtime architecture -// for different platforms. -package platform - -import ( - "syscall" -) - -// runtimeArchitecture gets the name of the current architecture (x86, x86_64, …) -func runtimeArchitecture() (string, error) { - utsname := &syscall.Utsname{} - if err := syscall.Uname(utsname); err != nil { - return "", err - } - return charsToString(utsname.Machine), nil -} diff --git a/vendor/github.com/docker/docker/pkg/platform/architecture_unix.go b/vendor/github.com/docker/docker/pkg/platform/architecture_unix.go deleted file mode 100644 index 45bbcf1..0000000 --- a/vendor/github.com/docker/docker/pkg/platform/architecture_unix.go +++ /dev/null @@ -1,20 +0,0 @@ -// +build freebsd solaris darwin - -// Package platform provides helper function to get the runtime architecture -// for different platforms. -package platform - -import ( - "os/exec" - "strings" -) - -// runtimeArchitecture gets the name of the current architecture (x86, x86_64, i86pc, sun4v, ...) -func runtimeArchitecture() (string, error) { - cmd := exec.Command("/usr/bin/uname", "-m") - machine, err := cmd.Output() - if err != nil { - return "", err - } - return strings.TrimSpace(string(machine)), nil -} diff --git a/vendor/github.com/docker/docker/pkg/platform/architecture_windows.go b/vendor/github.com/docker/docker/pkg/platform/architecture_windows.go deleted file mode 100644 index c5f684d..0000000 --- a/vendor/github.com/docker/docker/pkg/platform/architecture_windows.go +++ /dev/null @@ -1,60 +0,0 @@ -package platform - -import ( - "fmt" - "syscall" - "unsafe" - - "golang.org/x/sys/windows" -) - -var ( - modkernel32 = windows.NewLazySystemDLL("kernel32.dll") - procGetSystemInfo = modkernel32.NewProc("GetSystemInfo") -) - -// see http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx -type systeminfo struct { - wProcessorArchitecture uint16 - wReserved uint16 - dwPageSize uint32 - lpMinimumApplicationAddress uintptr - lpMaximumApplicationAddress uintptr - dwActiveProcessorMask uintptr - dwNumberOfProcessors uint32 - dwProcessorType uint32 - dwAllocationGranularity uint32 - wProcessorLevel uint16 - wProcessorRevision uint16 -} - -// Constants -const ( - ProcessorArchitecture64 = 9 // PROCESSOR_ARCHITECTURE_AMD64 - ProcessorArchitectureIA64 = 6 // PROCESSOR_ARCHITECTURE_IA64 - ProcessorArchitecture32 = 0 // PROCESSOR_ARCHITECTURE_INTEL - ProcessorArchitectureArm = 5 // PROCESSOR_ARCHITECTURE_ARM -) - -// runtimeArchitecture gets the name of the current architecture (x86, x86_64, …) -func runtimeArchitecture() (string, error) { - var sysinfo systeminfo - syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0) - switch sysinfo.wProcessorArchitecture { - case ProcessorArchitecture64, ProcessorArchitectureIA64: - return "x86_64", nil - case ProcessorArchitecture32: - return "i686", nil - case ProcessorArchitectureArm: - return "arm", nil - default: - return "", fmt.Errorf("Unknown processor architecture") - } -} - -// NumProcs returns the number of processors on the system -func NumProcs() uint32 { - var sysinfo systeminfo - syscall.Syscall(procGetSystemInfo.Addr(), 1, uintptr(unsafe.Pointer(&sysinfo)), 0, 0) - return sysinfo.dwNumberOfProcessors -} diff --git a/vendor/github.com/docker/docker/pkg/platform/platform.go b/vendor/github.com/docker/docker/pkg/platform/platform.go deleted file mode 100644 index e4b0312..0000000 --- a/vendor/github.com/docker/docker/pkg/platform/platform.go +++ /dev/null @@ -1,23 +0,0 @@ -package platform - -import ( - "runtime" - - "github.com/Sirupsen/logrus" -) - -var ( - // Architecture holds the runtime architecture of the process. - Architecture string - // OSType holds the runtime operating system type (Linux, …) of the process. - OSType string -) - -func init() { - var err error - Architecture, err = runtimeArchitecture() - if err != nil { - logrus.Errorf("Could not read system architecture info: %v", err) - } - OSType = runtime.GOOS -} diff --git a/vendor/github.com/docker/docker/pkg/platform/utsname_int8.go b/vendor/github.com/docker/docker/pkg/platform/utsname_int8.go deleted file mode 100644 index 5dcbadf..0000000 --- a/vendor/github.com/docker/docker/pkg/platform/utsname_int8.go +++ /dev/null @@ -1,18 +0,0 @@ -// +build linux,386 linux,amd64 linux,arm64 -// see golang's sources src/syscall/ztypes_linux_*.go that use int8 - -package platform - -// Convert the OS/ARCH-specific utsname.Machine to string -// given as an array of signed int8 -func charsToString(ca [65]int8) string { - s := make([]byte, len(ca)) - var lens int - for ; lens < len(ca); lens++ { - if ca[lens] == 0 { - break - } - s[lens] = uint8(ca[lens]) - } - return string(s[0:lens]) -} diff --git a/vendor/github.com/docker/docker/pkg/platform/utsname_uint8.go b/vendor/github.com/docker/docker/pkg/platform/utsname_uint8.go deleted file mode 100644 index c9875cf..0000000 --- a/vendor/github.com/docker/docker/pkg/platform/utsname_uint8.go +++ /dev/null @@ -1,18 +0,0 @@ -// +build linux,arm linux,ppc64 linux,ppc64le s390x -// see golang's sources src/syscall/ztypes_linux_*.go that use uint8 - -package platform - -// Convert the OS/ARCH-specific utsname.Machine to string -// given as an array of unsigned uint8 -func charsToString(ca [65]uint8) string { - s := make([]byte, len(ca)) - var lens int - for ; lens < len(ca); lens++ { - if ca[lens] == 0 { - break - } - s[lens] = ca[lens] - } - return string(s[0:lens]) -} diff --git a/vendor/github.com/docker/docker/pkg/plugingetter/getter.go b/vendor/github.com/docker/docker/pkg/plugingetter/getter.go deleted file mode 100644 index dde5f66..0000000 --- a/vendor/github.com/docker/docker/pkg/plugingetter/getter.go +++ /dev/null @@ -1,35 +0,0 @@ -package plugingetter - -import "github.com/docker/docker/pkg/plugins" - -const ( - // LOOKUP doesn't update RefCount - LOOKUP = 0 - // ACQUIRE increments RefCount - ACQUIRE = 1 - // RELEASE decrements RefCount - RELEASE = -1 -) - -// CompatPlugin is a abstraction to handle both v2(new) and v1(legacy) plugins. -type CompatPlugin interface { - Client() *plugins.Client - Name() string - BasePath() string - IsV1() bool -} - -// CountedPlugin is a plugin which is reference counted. -type CountedPlugin interface { - Acquire() - Release() - CompatPlugin -} - -// PluginGetter is the interface implemented by Store -type PluginGetter interface { - Get(name, capability string, mode int) (CompatPlugin, error) - GetAllByCap(capability string) ([]CompatPlugin, error) - GetAllManagedPluginsByCap(capability string) []CompatPlugin - Handle(capability string, callback func(string, *plugins.Client)) -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/client.go b/vendor/github.com/docker/docker/pkg/plugins/client.go deleted file mode 100644 index e8e730e..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/client.go +++ /dev/null @@ -1,205 +0,0 @@ -package plugins - -import ( - "bytes" - "encoding/json" - "io" - "io/ioutil" - "net/http" - "net/url" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/plugins/transport" - "github.com/docker/go-connections/sockets" - "github.com/docker/go-connections/tlsconfig" -) - -const ( - defaultTimeOut = 30 -) - -func newTransport(addr string, tlsConfig *tlsconfig.Options) (transport.Transport, error) { - tr := &http.Transport{} - - if tlsConfig != nil { - c, err := tlsconfig.Client(*tlsConfig) - if err != nil { - return nil, err - } - tr.TLSClientConfig = c - } - - u, err := url.Parse(addr) - if err != nil { - return nil, err - } - socket := u.Host - if socket == "" { - // valid local socket addresses have the host empty. - socket = u.Path - } - if err := sockets.ConfigureTransport(tr, u.Scheme, socket); err != nil { - return nil, err - } - scheme := httpScheme(u) - - return transport.NewHTTPTransport(tr, scheme, socket), nil -} - -// NewClient creates a new plugin client (http). -func NewClient(addr string, tlsConfig *tlsconfig.Options) (*Client, error) { - clientTransport, err := newTransport(addr, tlsConfig) - if err != nil { - return nil, err - } - return newClientWithTransport(clientTransport, 0), nil -} - -// NewClientWithTimeout creates a new plugin client (http). -func NewClientWithTimeout(addr string, tlsConfig *tlsconfig.Options, timeoutInSecs int) (*Client, error) { - clientTransport, err := newTransport(addr, tlsConfig) - if err != nil { - return nil, err - } - return newClientWithTransport(clientTransport, timeoutInSecs), nil -} - -// newClientWithTransport creates a new plugin client with a given transport. -func newClientWithTransport(tr transport.Transport, timeoutInSecs int) *Client { - return &Client{ - http: &http.Client{ - Transport: tr, - Timeout: time.Duration(timeoutInSecs) * time.Second, - }, - requestFactory: tr, - } -} - -// Client represents a plugin client. -type Client struct { - http *http.Client // http client to use - requestFactory transport.RequestFactory -} - -// Call calls the specified method with the specified arguments for the plugin. -// It will retry for 30 seconds if a failure occurs when calling. -func (c *Client) Call(serviceMethod string, args interface{}, ret interface{}) error { - var buf bytes.Buffer - if args != nil { - if err := json.NewEncoder(&buf).Encode(args); err != nil { - return err - } - } - body, err := c.callWithRetry(serviceMethod, &buf, true) - if err != nil { - return err - } - defer body.Close() - if ret != nil { - if err := json.NewDecoder(body).Decode(&ret); err != nil { - logrus.Errorf("%s: error reading plugin resp: %v", serviceMethod, err) - return err - } - } - return nil -} - -// Stream calls the specified method with the specified arguments for the plugin and returns the response body -func (c *Client) Stream(serviceMethod string, args interface{}) (io.ReadCloser, error) { - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(args); err != nil { - return nil, err - } - return c.callWithRetry(serviceMethod, &buf, true) -} - -// SendFile calls the specified method, and passes through the IO stream -func (c *Client) SendFile(serviceMethod string, data io.Reader, ret interface{}) error { - body, err := c.callWithRetry(serviceMethod, data, true) - if err != nil { - return err - } - defer body.Close() - if err := json.NewDecoder(body).Decode(&ret); err != nil { - logrus.Errorf("%s: error reading plugin resp: %v", serviceMethod, err) - return err - } - return nil -} - -func (c *Client) callWithRetry(serviceMethod string, data io.Reader, retry bool) (io.ReadCloser, error) { - req, err := c.requestFactory.NewRequest(serviceMethod, data) - if err != nil { - return nil, err - } - - var retries int - start := time.Now() - - for { - resp, err := c.http.Do(req) - if err != nil { - if !retry { - return nil, err - } - - timeOff := backoff(retries) - if abort(start, timeOff) { - return nil, err - } - retries++ - logrus.Warnf("Unable to connect to plugin: %s%s: %v, retrying in %v", req.URL.Host, req.URL.Path, err, timeOff) - time.Sleep(timeOff) - continue - } - - if resp.StatusCode != http.StatusOK { - b, err := ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - return nil, &statusError{resp.StatusCode, serviceMethod, err.Error()} - } - - // Plugins' Response(s) should have an Err field indicating what went - // wrong. Try to unmarshal into ResponseErr. Otherwise fallback to just - // return the string(body) - type responseErr struct { - Err string - } - remoteErr := responseErr{} - if err := json.Unmarshal(b, &remoteErr); err == nil { - if remoteErr.Err != "" { - return nil, &statusError{resp.StatusCode, serviceMethod, remoteErr.Err} - } - } - // old way... - return nil, &statusError{resp.StatusCode, serviceMethod, string(b)} - } - return resp.Body, nil - } -} - -func backoff(retries int) time.Duration { - b, max := 1, defaultTimeOut - for b < max && retries > 0 { - b *= 2 - retries-- - } - if b > max { - b = max - } - return time.Duration(b) * time.Second -} - -func abort(start time.Time, timeOff time.Duration) bool { - return timeOff+time.Since(start) >= time.Duration(defaultTimeOut)*time.Second -} - -func httpScheme(u *url.URL) string { - scheme := u.Scheme - if scheme != "https" { - scheme = "http" - } - return scheme -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/client_test.go b/vendor/github.com/docker/docker/pkg/plugins/client_test.go deleted file mode 100644 index 9faad86..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/client_test.go +++ /dev/null @@ -1,134 +0,0 @@ -package plugins - -import ( - "io" - "net/http" - "net/http/httptest" - "net/url" - "reflect" - "testing" - "time" - - "github.com/docker/docker/pkg/plugins/transport" - "github.com/docker/go-connections/tlsconfig" -) - -var ( - mux *http.ServeMux - server *httptest.Server -) - -func setupRemotePluginServer() string { - mux = http.NewServeMux() - server = httptest.NewServer(mux) - return server.URL -} - -func teardownRemotePluginServer() { - if server != nil { - server.Close() - } -} - -func TestFailedConnection(t *testing.T) { - c, _ := NewClient("tcp://127.0.0.1:1", &tlsconfig.Options{InsecureSkipVerify: true}) - _, err := c.callWithRetry("Service.Method", nil, false) - if err == nil { - t.Fatal("Unexpected successful connection") - } -} - -func TestEchoInputOutput(t *testing.T) { - addr := setupRemotePluginServer() - defer teardownRemotePluginServer() - - m := Manifest{[]string{"VolumeDriver", "NetworkDriver"}} - - mux.HandleFunc("/Test.Echo", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - t.Fatalf("Expected POST, got %s\n", r.Method) - } - - header := w.Header() - header.Set("Content-Type", transport.VersionMimetype) - - io.Copy(w, r.Body) - }) - - c, _ := NewClient(addr, &tlsconfig.Options{InsecureSkipVerify: true}) - var output Manifest - err := c.Call("Test.Echo", m, &output) - if err != nil { - t.Fatal(err) - } - - if !reflect.DeepEqual(output, m) { - t.Fatalf("Expected %v, was %v\n", m, output) - } - err = c.Call("Test.Echo", nil, nil) - if err != nil { - t.Fatal(err) - } -} - -func TestBackoff(t *testing.T) { - cases := []struct { - retries int - expTimeOff time.Duration - }{ - {0, time.Duration(1)}, - {1, time.Duration(2)}, - {2, time.Duration(4)}, - {4, time.Duration(16)}, - {6, time.Duration(30)}, - {10, time.Duration(30)}, - } - - for _, c := range cases { - s := c.expTimeOff * time.Second - if d := backoff(c.retries); d != s { - t.Fatalf("Retry %v, expected %v, was %v\n", c.retries, s, d) - } - } -} - -func TestAbortRetry(t *testing.T) { - cases := []struct { - timeOff time.Duration - expAbort bool - }{ - {time.Duration(1), false}, - {time.Duration(2), false}, - {time.Duration(10), false}, - {time.Duration(30), true}, - {time.Duration(40), true}, - } - - for _, c := range cases { - s := c.timeOff * time.Second - if a := abort(time.Now(), s); a != c.expAbort { - t.Fatalf("Duration %v, expected %v, was %v\n", c.timeOff, s, a) - } - } -} - -func TestClientScheme(t *testing.T) { - cases := map[string]string{ - "tcp://127.0.0.1:8080": "http", - "unix:///usr/local/plugins/foo": "http", - "http://127.0.0.1:8080": "http", - "https://127.0.0.1:8080": "https", - } - - for addr, scheme := range cases { - u, err := url.Parse(addr) - if err != nil { - t.Fatal(err) - } - s := httpScheme(u) - - if s != scheme { - t.Fatalf("URL scheme mismatch, expected %s, got %s", scheme, s) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/discovery.go b/vendor/github.com/docker/docker/pkg/plugins/discovery.go deleted file mode 100644 index e99581c..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/discovery.go +++ /dev/null @@ -1,131 +0,0 @@ -package plugins - -import ( - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "net/url" - "os" - "path/filepath" - "strings" - "sync" -) - -var ( - // ErrNotFound plugin not found - ErrNotFound = errors.New("plugin not found") - socketsPath = "/run/docker/plugins" -) - -// localRegistry defines a registry that is local (using unix socket). -type localRegistry struct{} - -func newLocalRegistry() localRegistry { - return localRegistry{} -} - -// Scan scans all the plugin paths and returns all the names it found -func Scan() ([]string, error) { - var names []string - if err := filepath.Walk(socketsPath, func(path string, fi os.FileInfo, err error) error { - if err != nil { - return nil - } - - if fi.Mode()&os.ModeSocket != 0 { - name := strings.TrimSuffix(fi.Name(), filepath.Ext(fi.Name())) - names = append(names, name) - } - return nil - }); err != nil { - return nil, err - } - - for _, path := range specsPaths { - if err := filepath.Walk(path, func(p string, fi os.FileInfo, err error) error { - if err != nil || fi.IsDir() { - return nil - } - name := strings.TrimSuffix(fi.Name(), filepath.Ext(fi.Name())) - names = append(names, name) - return nil - }); err != nil { - return nil, err - } - } - return names, nil -} - -// Plugin returns the plugin registered with the given name (or returns an error). -func (l *localRegistry) Plugin(name string) (*Plugin, error) { - socketpaths := pluginPaths(socketsPath, name, ".sock") - - for _, p := range socketpaths { - if fi, err := os.Stat(p); err == nil && fi.Mode()&os.ModeSocket != 0 { - return NewLocalPlugin(name, "unix://"+p), nil - } - } - - var txtspecpaths []string - for _, p := range specsPaths { - txtspecpaths = append(txtspecpaths, pluginPaths(p, name, ".spec")...) - txtspecpaths = append(txtspecpaths, pluginPaths(p, name, ".json")...) - } - - for _, p := range txtspecpaths { - if _, err := os.Stat(p); err == nil { - if strings.HasSuffix(p, ".json") { - return readPluginJSONInfo(name, p) - } - return readPluginInfo(name, p) - } - } - return nil, ErrNotFound -} - -func readPluginInfo(name, path string) (*Plugin, error) { - content, err := ioutil.ReadFile(path) - if err != nil { - return nil, err - } - addr := strings.TrimSpace(string(content)) - - u, err := url.Parse(addr) - if err != nil { - return nil, err - } - - if len(u.Scheme) == 0 { - return nil, fmt.Errorf("Unknown protocol") - } - - return NewLocalPlugin(name, addr), nil -} - -func readPluginJSONInfo(name, path string) (*Plugin, error) { - f, err := os.Open(path) - if err != nil { - return nil, err - } - defer f.Close() - - var p Plugin - if err := json.NewDecoder(f).Decode(&p); err != nil { - return nil, err - } - p.name = name - if p.TLSConfig != nil && len(p.TLSConfig.CAFile) == 0 { - p.TLSConfig.InsecureSkipVerify = true - } - p.activateWait = sync.NewCond(&sync.Mutex{}) - - return &p, nil -} - -func pluginPaths(base, name, ext string) []string { - return []string{ - filepath.Join(base, name+ext), - filepath.Join(base, name, name+ext), - } -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/discovery_test.go b/vendor/github.com/docker/docker/pkg/plugins/discovery_test.go deleted file mode 100644 index 03f9d00..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/discovery_test.go +++ /dev/null @@ -1,152 +0,0 @@ -package plugins - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func Setup(t *testing.T) (string, func()) { - tmpdir, err := ioutil.TempDir("", "docker-test") - if err != nil { - t.Fatal(err) - } - backup := socketsPath - socketsPath = tmpdir - specsPaths = []string{tmpdir} - - return tmpdir, func() { - socketsPath = backup - os.RemoveAll(tmpdir) - } -} - -func TestFileSpecPlugin(t *testing.T) { - tmpdir, unregister := Setup(t) - defer unregister() - - cases := []struct { - path string - name string - addr string - fail bool - }{ - // TODO Windows: Factor out the unix:// variants. - {filepath.Join(tmpdir, "echo.spec"), "echo", "unix://var/lib/docker/plugins/echo.sock", false}, - {filepath.Join(tmpdir, "echo", "echo.spec"), "echo", "unix://var/lib/docker/plugins/echo.sock", false}, - {filepath.Join(tmpdir, "foo.spec"), "foo", "tcp://localhost:8080", false}, - {filepath.Join(tmpdir, "foo", "foo.spec"), "foo", "tcp://localhost:8080", false}, - {filepath.Join(tmpdir, "bar.spec"), "bar", "localhost:8080", true}, // unknown transport - } - - for _, c := range cases { - if err := os.MkdirAll(filepath.Dir(c.path), 0755); err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(c.path, []byte(c.addr), 0644); err != nil { - t.Fatal(err) - } - - r := newLocalRegistry() - p, err := r.Plugin(c.name) - if c.fail && err == nil { - continue - } - - if err != nil { - t.Fatal(err) - } - - if p.name != c.name { - t.Fatalf("Expected plugin `%s`, got %s\n", c.name, p.name) - } - - if p.Addr != c.addr { - t.Fatalf("Expected plugin addr `%s`, got %s\n", c.addr, p.Addr) - } - - if p.TLSConfig.InsecureSkipVerify != true { - t.Fatalf("Expected TLS verification to be skipped") - } - } -} - -func TestFileJSONSpecPlugin(t *testing.T) { - tmpdir, unregister := Setup(t) - defer unregister() - - p := filepath.Join(tmpdir, "example.json") - spec := `{ - "Name": "plugin-example", - "Addr": "https://example.com/docker/plugin", - "TLSConfig": { - "CAFile": "/usr/shared/docker/certs/example-ca.pem", - "CertFile": "/usr/shared/docker/certs/example-cert.pem", - "KeyFile": "/usr/shared/docker/certs/example-key.pem" - } -}` - - if err := ioutil.WriteFile(p, []byte(spec), 0644); err != nil { - t.Fatal(err) - } - - r := newLocalRegistry() - plugin, err := r.Plugin("example") - if err != nil { - t.Fatal(err) - } - - if expected, actual := "example", plugin.name; expected != actual { - t.Fatalf("Expected plugin %q, got %s\n", expected, actual) - } - - if plugin.Addr != "https://example.com/docker/plugin" { - t.Fatalf("Expected plugin addr `https://example.com/docker/plugin`, got %s\n", plugin.Addr) - } - - if plugin.TLSConfig.CAFile != "/usr/shared/docker/certs/example-ca.pem" { - t.Fatalf("Expected plugin CA `/usr/shared/docker/certs/example-ca.pem`, got %s\n", plugin.TLSConfig.CAFile) - } - - if plugin.TLSConfig.CertFile != "/usr/shared/docker/certs/example-cert.pem" { - t.Fatalf("Expected plugin Certificate `/usr/shared/docker/certs/example-cert.pem`, got %s\n", plugin.TLSConfig.CertFile) - } - - if plugin.TLSConfig.KeyFile != "/usr/shared/docker/certs/example-key.pem" { - t.Fatalf("Expected plugin Key `/usr/shared/docker/certs/example-key.pem`, got %s\n", plugin.TLSConfig.KeyFile) - } -} - -func TestFileJSONSpecPluginWithoutTLSConfig(t *testing.T) { - tmpdir, unregister := Setup(t) - defer unregister() - - p := filepath.Join(tmpdir, "example.json") - spec := `{ - "Name": "plugin-example", - "Addr": "https://example.com/docker/plugin" -}` - - if err := ioutil.WriteFile(p, []byte(spec), 0644); err != nil { - t.Fatal(err) - } - - r := newLocalRegistry() - plugin, err := r.Plugin("example") - if err != nil { - t.Fatal(err) - } - - if expected, actual := "example", plugin.name; expected != actual { - t.Fatalf("Expected plugin %q, got %s\n", expected, actual) - } - - if plugin.Addr != "https://example.com/docker/plugin" { - t.Fatalf("Expected plugin addr `https://example.com/docker/plugin`, got %s\n", plugin.Addr) - } - - if plugin.TLSConfig != nil { - t.Fatalf("Expected plugin TLSConfig nil, got %v\n", plugin.TLSConfig) - } -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/discovery_unix.go b/vendor/github.com/docker/docker/pkg/plugins/discovery_unix.go deleted file mode 100644 index 693a47e..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/discovery_unix.go +++ /dev/null @@ -1,5 +0,0 @@ -// +build !windows - -package plugins - -var specsPaths = []string{"/etc/docker/plugins", "/usr/lib/docker/plugins"} diff --git a/vendor/github.com/docker/docker/pkg/plugins/discovery_unix_test.go b/vendor/github.com/docker/docker/pkg/plugins/discovery_unix_test.go deleted file mode 100644 index 3e2d506..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/discovery_unix_test.go +++ /dev/null @@ -1,61 +0,0 @@ -// +build !windows - -package plugins - -import ( - "fmt" - "net" - "os" - "path/filepath" - "reflect" - "testing" -) - -func TestLocalSocket(t *testing.T) { - // TODO Windows: Enable a similar version for Windows named pipes - tmpdir, unregister := Setup(t) - defer unregister() - - cases := []string{ - filepath.Join(tmpdir, "echo.sock"), - filepath.Join(tmpdir, "echo", "echo.sock"), - } - - for _, c := range cases { - if err := os.MkdirAll(filepath.Dir(c), 0755); err != nil { - t.Fatal(err) - } - - l, err := net.Listen("unix", c) - if err != nil { - t.Fatal(err) - } - - r := newLocalRegistry() - p, err := r.Plugin("echo") - if err != nil { - t.Fatal(err) - } - - pp, err := r.Plugin("echo") - if err != nil { - t.Fatal(err) - } - if !reflect.DeepEqual(p, pp) { - t.Fatalf("Expected %v, was %v\n", p, pp) - } - - if p.name != "echo" { - t.Fatalf("Expected plugin `echo`, got %s\n", p.name) - } - - addr := fmt.Sprintf("unix://%s", c) - if p.Addr != addr { - t.Fatalf("Expected plugin addr `%s`, got %s\n", addr, p.Addr) - } - if p.TLSConfig.InsecureSkipVerify != true { - t.Fatalf("Expected TLS verification to be skipped") - } - l.Close() - } -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/discovery_windows.go b/vendor/github.com/docker/docker/pkg/plugins/discovery_windows.go deleted file mode 100644 index d7c1fe4..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/discovery_windows.go +++ /dev/null @@ -1,8 +0,0 @@ -package plugins - -import ( - "os" - "path/filepath" -) - -var specsPaths = []string{filepath.Join(os.Getenv("programdata"), "docker", "plugins")} diff --git a/vendor/github.com/docker/docker/pkg/plugins/errors.go b/vendor/github.com/docker/docker/pkg/plugins/errors.go deleted file mode 100644 index 7988471..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/errors.go +++ /dev/null @@ -1,33 +0,0 @@ -package plugins - -import ( - "fmt" - "net/http" -) - -type statusError struct { - status int - method string - err string -} - -// Error returns a formatted string for this error type -func (e *statusError) Error() string { - return fmt.Sprintf("%s: %v", e.method, e.err) -} - -// IsNotFound indicates if the passed in error is from an http.StatusNotFound from the plugin -func IsNotFound(err error) bool { - return isStatusError(err, http.StatusNotFound) -} - -func isStatusError(err error, status int) bool { - if err == nil { - return false - } - e, ok := err.(*statusError) - if !ok { - return false - } - return e.status == status -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/plugin_test.go b/vendor/github.com/docker/docker/pkg/plugins/plugin_test.go deleted file mode 100644 index b19c0d5..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/plugin_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package plugins - -import ( - "errors" - "path/filepath" - "runtime" - "sync" - "testing" - "time" -) - -// regression test for deadlock in handlers -func TestPluginAddHandler(t *testing.T) { - // make a plugin which is pre-activated - p := &Plugin{activateWait: sync.NewCond(&sync.Mutex{})} - p.Manifest = &Manifest{Implements: []string{"bananas"}} - storage.plugins["qwerty"] = p - - testActive(t, p) - Handle("bananas", func(_ string, _ *Client) {}) - testActive(t, p) -} - -func TestPluginWaitBadPlugin(t *testing.T) { - p := &Plugin{activateWait: sync.NewCond(&sync.Mutex{})} - p.activateErr = errors.New("some junk happened") - testActive(t, p) -} - -func testActive(t *testing.T, p *Plugin) { - done := make(chan struct{}) - go func() { - p.waitActive() - close(done) - }() - - select { - case <-time.After(100 * time.Millisecond): - _, f, l, _ := runtime.Caller(1) - t.Fatalf("%s:%d: deadlock in waitActive", filepath.Base(f), l) - case <-done: - } - -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/README.md b/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/README.md deleted file mode 100644 index 0418a3e..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/README.md +++ /dev/null @@ -1,58 +0,0 @@ -Plugin RPC Generator -==================== - -Generates go code from a Go interface definition for proxying between the plugin -API and the subsystem being extended. - -## Usage - -Given an interface definition: - -```go -type volumeDriver interface { - Create(name string, opts opts) (err error) - Remove(name string) (err error) - Path(name string) (mountpoint string, err error) - Mount(name string) (mountpoint string, err error) - Unmount(name string) (err error) -} -``` - -**Note**: All function options and return values must be named in the definition. - -Run the generator: - -```bash -$ pluginrpc-gen --type volumeDriver --name VolumeDriver -i volumes/drivers/extpoint.go -o volumes/drivers/proxy.go -``` - -Where: -- `--type` is the name of the interface to use -- `--name` is the subsystem that the plugin "Implements" -- `-i` is the input file containing the interface definition -- `-o` is the output file where the the generated code should go - -**Note**: The generated code will use the same package name as the one defined in the input file - -Optionally, you can skip functions on the interface that should not be -implemented in the generated proxy code by passing in the function name to `--skip`. -This flag can be specified multiple times. - -You can also add build tags that should be prepended to the generated code by -supplying `--tag`. This flag can be specified multiple times. - -## Known issues - -## go-generate - -You can also use this with go-generate, which is pretty awesome. -To do so, place the code at the top of the file which contains the interface -definition (i.e., the input file): - -```go -//go:generate pluginrpc-gen -i $GOFILE -o proxy.go -type volumeDriver -name VolumeDriver -``` - -Then cd to the package dir and run `go generate` - -**Note**: the `pluginrpc-gen` binary must be within your `$PATH` diff --git a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/fixtures/foo.go b/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/fixtures/foo.go deleted file mode 100644 index 5695dcc..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/fixtures/foo.go +++ /dev/null @@ -1,89 +0,0 @@ -package foo - -import ( - "fmt" - - aliasedio "io" - - "github.com/docker/docker/pkg/plugins/pluginrpc-gen/fixtures/otherfixture" -) - -var ( - errFakeImport = fmt.Errorf("just to import fmt for imports tests") -) - -type wobble struct { - Some string - Val string - Inception *wobble -} - -// Fooer is an empty interface used for tests. -type Fooer interface{} - -// Fooer2 is an interface used for tests. -type Fooer2 interface { - Foo() -} - -// Fooer3 is an interface used for tests. -type Fooer3 interface { - Foo() - Bar(a string) - Baz(a string) (err error) - Qux(a, b string) (val string, err error) - Wobble() (w *wobble) - Wiggle() (w wobble) - WiggleWobble(a []*wobble, b []wobble, c map[string]*wobble, d map[*wobble]wobble, e map[string][]wobble, f []*otherfixture.Spaceship) (g map[*wobble]wobble, h [][]*wobble, i otherfixture.Spaceship, j *otherfixture.Spaceship, k map[*otherfixture.Spaceship]otherfixture.Spaceship, l []otherfixture.Spaceship) -} - -// Fooer4 is an interface used for tests. -type Fooer4 interface { - Foo() error -} - -// Bar is an interface used for tests. -type Bar interface { - Boo(a string, b string) (s string, err error) -} - -// Fooer5 is an interface used for tests. -type Fooer5 interface { - Foo() - Bar -} - -// Fooer6 is an interface used for tests. -type Fooer6 interface { - Foo(a otherfixture.Spaceship) -} - -// Fooer7 is an interface used for tests. -type Fooer7 interface { - Foo(a *otherfixture.Spaceship) -} - -// Fooer8 is an interface used for tests. -type Fooer8 interface { - Foo(a map[string]otherfixture.Spaceship) -} - -// Fooer9 is an interface used for tests. -type Fooer9 interface { - Foo(a map[string]*otherfixture.Spaceship) -} - -// Fooer10 is an interface used for tests. -type Fooer10 interface { - Foo(a []otherfixture.Spaceship) -} - -// Fooer11 is an interface used for tests. -type Fooer11 interface { - Foo(a []*otherfixture.Spaceship) -} - -// Fooer12 is an interface used for tests. -type Fooer12 interface { - Foo(a aliasedio.Reader) -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/fixtures/otherfixture/spaceship.go b/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/fixtures/otherfixture/spaceship.go deleted file mode 100644 index 1937d17..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/fixtures/otherfixture/spaceship.go +++ /dev/null @@ -1,4 +0,0 @@ -package otherfixture - -// Spaceship is a fixture for tests -type Spaceship struct{} diff --git a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/main.go b/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/main.go deleted file mode 100644 index e77a7d4..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/main.go +++ /dev/null @@ -1,91 +0,0 @@ -package main - -import ( - "bytes" - "flag" - "fmt" - "go/format" - "io/ioutil" - "os" - "unicode" - "unicode/utf8" -) - -type stringSet struct { - values map[string]struct{} -} - -func (s stringSet) String() string { - return "" -} - -func (s stringSet) Set(value string) error { - s.values[value] = struct{}{} - return nil -} -func (s stringSet) GetValues() map[string]struct{} { - return s.values -} - -var ( - typeName = flag.String("type", "", "interface type to generate plugin rpc proxy for") - rpcName = flag.String("name", *typeName, "RPC name, set if different from type") - inputFile = flag.String("i", "", "input file path") - outputFile = flag.String("o", *inputFile+"_proxy.go", "output file path") - - skipFuncs map[string]struct{} - flSkipFuncs = stringSet{make(map[string]struct{})} - - flBuildTags = stringSet{make(map[string]struct{})} -) - -func errorOut(msg string, err error) { - if err == nil { - return - } - fmt.Fprintf(os.Stderr, "%s: %v\n", msg, err) - os.Exit(1) -} - -func checkFlags() error { - if *outputFile == "" { - return fmt.Errorf("missing required flag `-o`") - } - if *inputFile == "" { - return fmt.Errorf("missing required flag `-i`") - } - return nil -} - -func main() { - flag.Var(flSkipFuncs, "skip", "skip parsing for function") - flag.Var(flBuildTags, "tag", "build tags to add to generated files") - flag.Parse() - skipFuncs = flSkipFuncs.GetValues() - - errorOut("error", checkFlags()) - - pkg, err := Parse(*inputFile, *typeName) - errorOut(fmt.Sprintf("error parsing requested type %s", *typeName), err) - - var analysis = struct { - InterfaceType string - RPCName string - BuildTags map[string]struct{} - *ParsedPkg - }{toLower(*typeName), *rpcName, flBuildTags.GetValues(), pkg} - var buf bytes.Buffer - - errorOut("parser error", generatedTempl.Execute(&buf, analysis)) - src, err := format.Source(buf.Bytes()) - errorOut("error formatting generated source:\n"+buf.String(), err) - errorOut("error writing file", ioutil.WriteFile(*outputFile, src, 0644)) -} - -func toLower(s string) string { - if s == "" { - return "" - } - r, n := utf8.DecodeRuneInString(s) - return string(unicode.ToLower(r)) + s[n:] -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/parser.go b/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/parser.go deleted file mode 100644 index 6c547e1..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/parser.go +++ /dev/null @@ -1,263 +0,0 @@ -package main - -import ( - "errors" - "fmt" - "go/ast" - "go/parser" - "go/token" - "path" - "reflect" - "strings" -) - -var errBadReturn = errors.New("found return arg with no name: all args must be named") - -type errUnexpectedType struct { - expected string - actual interface{} -} - -func (e errUnexpectedType) Error() string { - return fmt.Sprintf("got wrong type expecting %s, got: %v", e.expected, reflect.TypeOf(e.actual)) -} - -// ParsedPkg holds information about a package that has been parsed, -// its name and the list of functions. -type ParsedPkg struct { - Name string - Functions []function - Imports []importSpec -} - -type function struct { - Name string - Args []arg - Returns []arg - Doc string -} - -type arg struct { - Name string - ArgType string - PackageSelector string -} - -func (a *arg) String() string { - return a.Name + " " + a.ArgType -} - -type importSpec struct { - Name string - Path string -} - -func (s *importSpec) String() string { - var ss string - if len(s.Name) != 0 { - ss += s.Name - } - ss += s.Path - return ss -} - -// Parse parses the given file for an interface definition with the given name. -func Parse(filePath string, objName string) (*ParsedPkg, error) { - fs := token.NewFileSet() - pkg, err := parser.ParseFile(fs, filePath, nil, parser.AllErrors) - if err != nil { - return nil, err - } - p := &ParsedPkg{} - p.Name = pkg.Name.Name - obj, exists := pkg.Scope.Objects[objName] - if !exists { - return nil, fmt.Errorf("could not find object %s in %s", objName, filePath) - } - if obj.Kind != ast.Typ { - return nil, fmt.Errorf("exected type, got %s", obj.Kind) - } - spec, ok := obj.Decl.(*ast.TypeSpec) - if !ok { - return nil, errUnexpectedType{"*ast.TypeSpec", obj.Decl} - } - iface, ok := spec.Type.(*ast.InterfaceType) - if !ok { - return nil, errUnexpectedType{"*ast.InterfaceType", spec.Type} - } - - p.Functions, err = parseInterface(iface) - if err != nil { - return nil, err - } - - // figure out what imports will be needed - imports := make(map[string]importSpec) - for _, f := range p.Functions { - args := append(f.Args, f.Returns...) - for _, arg := range args { - if len(arg.PackageSelector) == 0 { - continue - } - - for _, i := range pkg.Imports { - if i.Name != nil { - if i.Name.Name != arg.PackageSelector { - continue - } - imports[i.Path.Value] = importSpec{Name: arg.PackageSelector, Path: i.Path.Value} - break - } - - _, name := path.Split(i.Path.Value) - splitName := strings.Split(name, "-") - if len(splitName) > 1 { - name = splitName[len(splitName)-1] - } - // import paths have quotes already added in, so need to remove them for name comparison - name = strings.TrimPrefix(name, `"`) - name = strings.TrimSuffix(name, `"`) - if name == arg.PackageSelector { - imports[i.Path.Value] = importSpec{Path: i.Path.Value} - break - } - } - } - } - - for _, spec := range imports { - p.Imports = append(p.Imports, spec) - } - - return p, nil -} - -func parseInterface(iface *ast.InterfaceType) ([]function, error) { - var functions []function - for _, field := range iface.Methods.List { - switch f := field.Type.(type) { - case *ast.FuncType: - method, err := parseFunc(field) - if err != nil { - return nil, err - } - if method == nil { - continue - } - functions = append(functions, *method) - case *ast.Ident: - spec, ok := f.Obj.Decl.(*ast.TypeSpec) - if !ok { - return nil, errUnexpectedType{"*ast.TypeSpec", f.Obj.Decl} - } - iface, ok := spec.Type.(*ast.InterfaceType) - if !ok { - return nil, errUnexpectedType{"*ast.TypeSpec", spec.Type} - } - funcs, err := parseInterface(iface) - if err != nil { - fmt.Println(err) - continue - } - functions = append(functions, funcs...) - default: - return nil, errUnexpectedType{"*astFuncType or *ast.Ident", f} - } - } - return functions, nil -} - -func parseFunc(field *ast.Field) (*function, error) { - f := field.Type.(*ast.FuncType) - method := &function{Name: field.Names[0].Name} - if _, exists := skipFuncs[method.Name]; exists { - fmt.Println("skipping:", method.Name) - return nil, nil - } - if f.Params != nil { - args, err := parseArgs(f.Params.List) - if err != nil { - return nil, err - } - method.Args = args - } - if f.Results != nil { - returns, err := parseArgs(f.Results.List) - if err != nil { - return nil, fmt.Errorf("error parsing function returns for %q: %v", method.Name, err) - } - method.Returns = returns - } - return method, nil -} - -func parseArgs(fields []*ast.Field) ([]arg, error) { - var args []arg - for _, f := range fields { - if len(f.Names) == 0 { - return nil, errBadReturn - } - for _, name := range f.Names { - p, err := parseExpr(f.Type) - if err != nil { - return nil, err - } - args = append(args, arg{name.Name, p.value, p.pkg}) - } - } - return args, nil -} - -type parsedExpr struct { - value string - pkg string -} - -func parseExpr(e ast.Expr) (parsedExpr, error) { - var parsed parsedExpr - switch i := e.(type) { - case *ast.Ident: - parsed.value += i.Name - case *ast.StarExpr: - p, err := parseExpr(i.X) - if err != nil { - return parsed, err - } - parsed.value += "*" - parsed.value += p.value - parsed.pkg = p.pkg - case *ast.SelectorExpr: - p, err := parseExpr(i.X) - if err != nil { - return parsed, err - } - parsed.pkg = p.value - parsed.value += p.value + "." - parsed.value += i.Sel.Name - case *ast.MapType: - parsed.value += "map[" - p, err := parseExpr(i.Key) - if err != nil { - return parsed, err - } - parsed.value += p.value - parsed.value += "]" - p, err = parseExpr(i.Value) - if err != nil { - return parsed, err - } - parsed.value += p.value - parsed.pkg = p.pkg - case *ast.ArrayType: - parsed.value += "[]" - p, err := parseExpr(i.Elt) - if err != nil { - return parsed, err - } - parsed.value += p.value - parsed.pkg = p.pkg - default: - return parsed, errUnexpectedType{"*ast.Ident or *ast.StarExpr", i} - } - return parsed, nil -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/parser_test.go b/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/parser_test.go deleted file mode 100644 index a1b1ac9..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/parser_test.go +++ /dev/null @@ -1,222 +0,0 @@ -package main - -import ( - "fmt" - "path/filepath" - "runtime" - "strings" - "testing" -) - -const testFixture = "fixtures/foo.go" - -func TestParseEmptyInterface(t *testing.T) { - pkg, err := Parse(testFixture, "Fooer") - if err != nil { - t.Fatal(err) - } - - assertName(t, "foo", pkg.Name) - assertNum(t, 0, len(pkg.Functions)) -} - -func TestParseNonInterfaceType(t *testing.T) { - _, err := Parse(testFixture, "wobble") - if _, ok := err.(errUnexpectedType); !ok { - t.Fatal("expected type error when parsing non-interface type") - } -} - -func TestParseWithOneFunction(t *testing.T) { - pkg, err := Parse(testFixture, "Fooer2") - if err != nil { - t.Fatal(err) - } - - assertName(t, "foo", pkg.Name) - assertNum(t, 1, len(pkg.Functions)) - assertName(t, "Foo", pkg.Functions[0].Name) - assertNum(t, 0, len(pkg.Functions[0].Args)) - assertNum(t, 0, len(pkg.Functions[0].Returns)) -} - -func TestParseWithMultipleFuncs(t *testing.T) { - pkg, err := Parse(testFixture, "Fooer3") - if err != nil { - t.Fatal(err) - } - - assertName(t, "foo", pkg.Name) - assertNum(t, 7, len(pkg.Functions)) - - f := pkg.Functions[0] - assertName(t, "Foo", f.Name) - assertNum(t, 0, len(f.Args)) - assertNum(t, 0, len(f.Returns)) - - f = pkg.Functions[1] - assertName(t, "Bar", f.Name) - assertNum(t, 1, len(f.Args)) - assertNum(t, 0, len(f.Returns)) - arg := f.Args[0] - assertName(t, "a", arg.Name) - assertName(t, "string", arg.ArgType) - - f = pkg.Functions[2] - assertName(t, "Baz", f.Name) - assertNum(t, 1, len(f.Args)) - assertNum(t, 1, len(f.Returns)) - arg = f.Args[0] - assertName(t, "a", arg.Name) - assertName(t, "string", arg.ArgType) - arg = f.Returns[0] - assertName(t, "err", arg.Name) - assertName(t, "error", arg.ArgType) - - f = pkg.Functions[3] - assertName(t, "Qux", f.Name) - assertNum(t, 2, len(f.Args)) - assertNum(t, 2, len(f.Returns)) - arg = f.Args[0] - assertName(t, "a", f.Args[0].Name) - assertName(t, "string", f.Args[0].ArgType) - arg = f.Args[1] - assertName(t, "b", arg.Name) - assertName(t, "string", arg.ArgType) - arg = f.Returns[0] - assertName(t, "val", arg.Name) - assertName(t, "string", arg.ArgType) - arg = f.Returns[1] - assertName(t, "err", arg.Name) - assertName(t, "error", arg.ArgType) - - f = pkg.Functions[4] - assertName(t, "Wobble", f.Name) - assertNum(t, 0, len(f.Args)) - assertNum(t, 1, len(f.Returns)) - arg = f.Returns[0] - assertName(t, "w", arg.Name) - assertName(t, "*wobble", arg.ArgType) - - f = pkg.Functions[5] - assertName(t, "Wiggle", f.Name) - assertNum(t, 0, len(f.Args)) - assertNum(t, 1, len(f.Returns)) - arg = f.Returns[0] - assertName(t, "w", arg.Name) - assertName(t, "wobble", arg.ArgType) - - f = pkg.Functions[6] - assertName(t, "WiggleWobble", f.Name) - assertNum(t, 6, len(f.Args)) - assertNum(t, 6, len(f.Returns)) - expectedArgs := [][]string{ - {"a", "[]*wobble"}, - {"b", "[]wobble"}, - {"c", "map[string]*wobble"}, - {"d", "map[*wobble]wobble"}, - {"e", "map[string][]wobble"}, - {"f", "[]*otherfixture.Spaceship"}, - } - for i, arg := range f.Args { - assertName(t, expectedArgs[i][0], arg.Name) - assertName(t, expectedArgs[i][1], arg.ArgType) - } - expectedReturns := [][]string{ - {"g", "map[*wobble]wobble"}, - {"h", "[][]*wobble"}, - {"i", "otherfixture.Spaceship"}, - {"j", "*otherfixture.Spaceship"}, - {"k", "map[*otherfixture.Spaceship]otherfixture.Spaceship"}, - {"l", "[]otherfixture.Spaceship"}, - } - for i, ret := range f.Returns { - assertName(t, expectedReturns[i][0], ret.Name) - assertName(t, expectedReturns[i][1], ret.ArgType) - } -} - -func TestParseWithUnamedReturn(t *testing.T) { - _, err := Parse(testFixture, "Fooer4") - if !strings.HasSuffix(err.Error(), errBadReturn.Error()) { - t.Fatalf("expected ErrBadReturn, got %v", err) - } -} - -func TestEmbeddedInterface(t *testing.T) { - pkg, err := Parse(testFixture, "Fooer5") - if err != nil { - t.Fatal(err) - } - - assertName(t, "foo", pkg.Name) - assertNum(t, 2, len(pkg.Functions)) - - f := pkg.Functions[0] - assertName(t, "Foo", f.Name) - assertNum(t, 0, len(f.Args)) - assertNum(t, 0, len(f.Returns)) - - f = pkg.Functions[1] - assertName(t, "Boo", f.Name) - assertNum(t, 2, len(f.Args)) - assertNum(t, 2, len(f.Returns)) - - arg := f.Args[0] - assertName(t, "a", arg.Name) - assertName(t, "string", arg.ArgType) - - arg = f.Args[1] - assertName(t, "b", arg.Name) - assertName(t, "string", arg.ArgType) - - arg = f.Returns[0] - assertName(t, "s", arg.Name) - assertName(t, "string", arg.ArgType) - - arg = f.Returns[1] - assertName(t, "err", arg.Name) - assertName(t, "error", arg.ArgType) -} - -func TestParsedImports(t *testing.T) { - cases := []string{"Fooer6", "Fooer7", "Fooer8", "Fooer9", "Fooer10", "Fooer11"} - for _, testCase := range cases { - pkg, err := Parse(testFixture, testCase) - if err != nil { - t.Fatal(err) - } - - assertNum(t, 1, len(pkg.Imports)) - importPath := strings.Split(pkg.Imports[0].Path, "/") - assertName(t, "otherfixture\"", importPath[len(importPath)-1]) - assertName(t, "", pkg.Imports[0].Name) - } -} - -func TestAliasedImports(t *testing.T) { - pkg, err := Parse(testFixture, "Fooer12") - if err != nil { - t.Fatal(err) - } - - assertNum(t, 1, len(pkg.Imports)) - assertName(t, "aliasedio", pkg.Imports[0].Name) -} - -func assertName(t *testing.T, expected, actual string) { - if expected != actual { - fatalOut(t, fmt.Sprintf("expected name to be `%s`, got: %s", expected, actual)) - } -} - -func assertNum(t *testing.T, expected, actual int) { - if expected != actual { - fatalOut(t, fmt.Sprintf("expected number to be %d, got: %d", expected, actual)) - } -} - -func fatalOut(t *testing.T, msg string) { - _, file, ln, _ := runtime.Caller(2) - t.Fatalf("%s:%d: %s", filepath.Base(file), ln, msg) -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/template.go b/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/template.go deleted file mode 100644 index 50ed929..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/pluginrpc-gen/template.go +++ /dev/null @@ -1,118 +0,0 @@ -package main - -import ( - "strings" - "text/template" -) - -func printArgs(args []arg) string { - var argStr []string - for _, arg := range args { - argStr = append(argStr, arg.String()) - } - return strings.Join(argStr, ", ") -} - -func buildImports(specs []importSpec) string { - if len(specs) == 0 { - return `import "errors"` - } - imports := "import(\n" - imports += "\t\"errors\"\n" - for _, i := range specs { - imports += "\t" + i.String() + "\n" - } - imports += ")" - return imports -} - -func marshalType(t string) string { - switch t { - case "error": - // convert error types to plain strings to ensure the values are encoded/decoded properly - return "string" - default: - return t - } -} - -func isErr(t string) bool { - switch t { - case "error": - return true - default: - return false - } -} - -// Need to use this helper due to issues with go-vet -func buildTag(s string) string { - return "+build " + s -} - -var templFuncs = template.FuncMap{ - "printArgs": printArgs, - "marshalType": marshalType, - "isErr": isErr, - "lower": strings.ToLower, - "title": title, - "tag": buildTag, - "imports": buildImports, -} - -func title(s string) string { - if strings.ToLower(s) == "id" { - return "ID" - } - return strings.Title(s) -} - -var generatedTempl = template.Must(template.New("rpc_cient").Funcs(templFuncs).Parse(` -// generated code - DO NOT EDIT -{{ range $k, $v := .BuildTags }} - // {{ tag $k }} {{ end }} - -package {{ .Name }} - -{{ imports .Imports }} - -type client interface{ - Call(string, interface{}, interface{}) error -} - -type {{ .InterfaceType }}Proxy struct { - client -} - -{{ range .Functions }} - type {{ $.InterfaceType }}Proxy{{ .Name }}Request struct{ - {{ range .Args }} - {{ title .Name }} {{ .ArgType }} {{ end }} - } - - type {{ $.InterfaceType }}Proxy{{ .Name }}Response struct{ - {{ range .Returns }} - {{ title .Name }} {{ marshalType .ArgType }} {{ end }} - } - - func (pp *{{ $.InterfaceType }}Proxy) {{ .Name }}({{ printArgs .Args }}) ({{ printArgs .Returns }}) { - var( - req {{ $.InterfaceType }}Proxy{{ .Name }}Request - ret {{ $.InterfaceType }}Proxy{{ .Name }}Response - ) - {{ range .Args }} - req.{{ title .Name }} = {{ lower .Name }} {{ end }} - if err = pp.Call("{{ $.RPCName }}.{{ .Name }}", req, &ret); err != nil { - return - } - {{ range $r := .Returns }} - {{ if isErr .ArgType }} - if ret.{{ title .Name }} != "" { - {{ lower .Name }} = errors.New(ret.{{ title .Name }}) - } {{ end }} - {{ if isErr .ArgType | not }} {{ lower .Name }} = ret.{{ title .Name }} {{ end }} {{ end }} - - return - } -{{ end }} -`)) diff --git a/vendor/github.com/docker/docker/pkg/plugins/plugins.go b/vendor/github.com/docker/docker/pkg/plugins/plugins.go deleted file mode 100644 index c0059cb..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/plugins.go +++ /dev/null @@ -1,329 +0,0 @@ -// Package plugins provides structures and helper functions to manage Docker -// plugins. -// -// Docker discovers plugins by looking for them in the plugin directory whenever -// a user or container tries to use one by name. UNIX domain socket files must -// be located under /run/docker/plugins, whereas spec files can be located -// either under /etc/docker/plugins or /usr/lib/docker/plugins. This is handled -// by the Registry interface, which lets you list all plugins or get a plugin by -// its name if it exists. -// -// The plugins need to implement an HTTP server and bind this to the UNIX socket -// or the address specified in the spec files. -// A handshake is send at /Plugin.Activate, and plugins are expected to return -// a Manifest with a list of of Docker subsystems which this plugin implements. -// -// In order to use a plugins, you can use the ``Get`` with the name of the -// plugin and the subsystem it implements. -// -// plugin, err := plugins.Get("example", "VolumeDriver") -// if err != nil { -// return fmt.Errorf("Error looking up volume plugin example: %v", err) -// } -package plugins - -import ( - "errors" - "sync" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/go-connections/tlsconfig" -) - -var ( - // ErrNotImplements is returned if the plugin does not implement the requested driver. - ErrNotImplements = errors.New("Plugin does not implement the requested driver") -) - -type plugins struct { - sync.Mutex - plugins map[string]*Plugin -} - -type extpointHandlers struct { - sync.RWMutex - extpointHandlers map[string][]func(string, *Client) -} - -var ( - storage = plugins{plugins: make(map[string]*Plugin)} - handlers = extpointHandlers{extpointHandlers: make(map[string][]func(string, *Client))} -) - -// Manifest lists what a plugin implements. -type Manifest struct { - // List of subsystem the plugin implements. - Implements []string -} - -// Plugin is the definition of a docker plugin. -type Plugin struct { - // Name of the plugin - name string - // Address of the plugin - Addr string - // TLS configuration of the plugin - TLSConfig *tlsconfig.Options - // Client attached to the plugin - client *Client - // Manifest of the plugin (see above) - Manifest *Manifest `json:"-"` - - // wait for activation to finish - activateWait *sync.Cond - // error produced by activation - activateErr error - // keeps track of callback handlers run against this plugin - handlersRun bool -} - -// Name returns the name of the plugin. -func (p *Plugin) Name() string { - return p.name -} - -// Client returns a ready-to-use plugin client that can be used to communicate with the plugin. -func (p *Plugin) Client() *Client { - return p.client -} - -// IsV1 returns true for V1 plugins and false otherwise. -func (p *Plugin) IsV1() bool { - return true -} - -// NewLocalPlugin creates a new local plugin. -func NewLocalPlugin(name, addr string) *Plugin { - return &Plugin{ - name: name, - Addr: addr, - // TODO: change to nil - TLSConfig: &tlsconfig.Options{InsecureSkipVerify: true}, - activateWait: sync.NewCond(&sync.Mutex{}), - } -} - -func (p *Plugin) activate() error { - p.activateWait.L.Lock() - - if p.activated() { - p.runHandlers() - p.activateWait.L.Unlock() - return p.activateErr - } - - p.activateErr = p.activateWithLock() - - p.runHandlers() - p.activateWait.L.Unlock() - p.activateWait.Broadcast() - return p.activateErr -} - -// runHandlers runs the registered handlers for the implemented plugin types -// This should only be run after activation, and while the activation lock is held. -func (p *Plugin) runHandlers() { - if !p.activated() { - return - } - - handlers.RLock() - if !p.handlersRun { - for _, iface := range p.Manifest.Implements { - hdlrs, handled := handlers.extpointHandlers[iface] - if !handled { - continue - } - for _, handler := range hdlrs { - handler(p.name, p.client) - } - } - p.handlersRun = true - } - handlers.RUnlock() - -} - -// activated returns if the plugin has already been activated. -// This should only be called with the activation lock held -func (p *Plugin) activated() bool { - return p.Manifest != nil -} - -func (p *Plugin) activateWithLock() error { - c, err := NewClient(p.Addr, p.TLSConfig) - if err != nil { - return err - } - p.client = c - - m := new(Manifest) - if err = p.client.Call("Plugin.Activate", nil, m); err != nil { - return err - } - - p.Manifest = m - return nil -} - -func (p *Plugin) waitActive() error { - p.activateWait.L.Lock() - for !p.activated() && p.activateErr == nil { - p.activateWait.Wait() - } - p.activateWait.L.Unlock() - return p.activateErr -} - -func (p *Plugin) implements(kind string) bool { - if p.Manifest == nil { - return false - } - for _, driver := range p.Manifest.Implements { - if driver == kind { - return true - } - } - return false -} - -func load(name string) (*Plugin, error) { - return loadWithRetry(name, true) -} - -func loadWithRetry(name string, retry bool) (*Plugin, error) { - registry := newLocalRegistry() - start := time.Now() - - var retries int - for { - pl, err := registry.Plugin(name) - if err != nil { - if !retry { - return nil, err - } - - timeOff := backoff(retries) - if abort(start, timeOff) { - return nil, err - } - retries++ - logrus.Warnf("Unable to locate plugin: %s, retrying in %v", name, timeOff) - time.Sleep(timeOff) - continue - } - - storage.Lock() - if pl, exists := storage.plugins[name]; exists { - storage.Unlock() - return pl, pl.activate() - } - storage.plugins[name] = pl - storage.Unlock() - - err = pl.activate() - - if err != nil { - storage.Lock() - delete(storage.plugins, name) - storage.Unlock() - } - - return pl, err - } -} - -func get(name string) (*Plugin, error) { - storage.Lock() - pl, ok := storage.plugins[name] - storage.Unlock() - if ok { - return pl, pl.activate() - } - return load(name) -} - -// Get returns the plugin given the specified name and requested implementation. -func Get(name, imp string) (*Plugin, error) { - pl, err := get(name) - if err != nil { - return nil, err - } - if err := pl.waitActive(); err == nil && pl.implements(imp) { - logrus.Debugf("%s implements: %s", name, imp) - return pl, nil - } - return nil, ErrNotImplements -} - -// Handle adds the specified function to the extpointHandlers. -func Handle(iface string, fn func(string, *Client)) { - handlers.Lock() - hdlrs, ok := handlers.extpointHandlers[iface] - if !ok { - hdlrs = []func(string, *Client){} - } - - hdlrs = append(hdlrs, fn) - handlers.extpointHandlers[iface] = hdlrs - - storage.Lock() - for _, p := range storage.plugins { - p.activateWait.L.Lock() - if p.activated() && p.implements(iface) { - p.handlersRun = false - } - p.activateWait.L.Unlock() - } - storage.Unlock() - - handlers.Unlock() -} - -// GetAll returns all the plugins for the specified implementation -func GetAll(imp string) ([]*Plugin, error) { - pluginNames, err := Scan() - if err != nil { - return nil, err - } - - type plLoad struct { - pl *Plugin - err error - } - - chPl := make(chan *plLoad, len(pluginNames)) - var wg sync.WaitGroup - for _, name := range pluginNames { - storage.Lock() - pl, ok := storage.plugins[name] - storage.Unlock() - if ok { - chPl <- &plLoad{pl, nil} - continue - } - - wg.Add(1) - go func(name string) { - defer wg.Done() - pl, err := loadWithRetry(name, false) - chPl <- &plLoad{pl, err} - }(name) - } - - wg.Wait() - close(chPl) - - var out []*Plugin - for pl := range chPl { - if pl.err != nil { - logrus.Error(pl.err) - continue - } - if err := pl.pl.waitActive(); err == nil && pl.pl.implements(imp) { - out = append(out, pl.pl) - } - } - return out, nil -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/plugins_linux.go b/vendor/github.com/docker/docker/pkg/plugins/plugins_linux.go deleted file mode 100644 index 9c5a0b5..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/plugins_linux.go +++ /dev/null @@ -1,7 +0,0 @@ -package plugins - -// BasePath returns the path to which all paths returned by the plugin are relative to. -// For v1 plugins, this always returns the host's root directory. -func (p *Plugin) BasePath() string { - return "/" -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/plugins_windows.go b/vendor/github.com/docker/docker/pkg/plugins/plugins_windows.go deleted file mode 100644 index 3c8d8fe..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/plugins_windows.go +++ /dev/null @@ -1,8 +0,0 @@ -package plugins - -// BasePath returns the path to which all paths returned by the plugin are relative to. -// For Windows v1 plugins, this returns an empty string, since the plugin is already aware -// of the absolute path of the mount. -func (p *Plugin) BasePath() string { - return "" -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/transport/http.go b/vendor/github.com/docker/docker/pkg/plugins/transport/http.go deleted file mode 100644 index 5be146a..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/transport/http.go +++ /dev/null @@ -1,36 +0,0 @@ -package transport - -import ( - "io" - "net/http" -) - -// httpTransport holds an http.RoundTripper -// and information about the scheme and address the transport -// sends request to. -type httpTransport struct { - http.RoundTripper - scheme string - addr string -} - -// NewHTTPTransport creates a new httpTransport. -func NewHTTPTransport(r http.RoundTripper, scheme, addr string) Transport { - return httpTransport{ - RoundTripper: r, - scheme: scheme, - addr: addr, - } -} - -// NewRequest creates a new http.Request and sets the URL -// scheme and address with the transport's fields. -func (t httpTransport) NewRequest(path string, data io.Reader) (*http.Request, error) { - req, err := newHTTPRequest(path, data) - if err != nil { - return nil, err - } - req.URL.Scheme = t.scheme - req.URL.Host = t.addr - return req, nil -} diff --git a/vendor/github.com/docker/docker/pkg/plugins/transport/transport.go b/vendor/github.com/docker/docker/pkg/plugins/transport/transport.go deleted file mode 100644 index d7f1e21..0000000 --- a/vendor/github.com/docker/docker/pkg/plugins/transport/transport.go +++ /dev/null @@ -1,36 +0,0 @@ -package transport - -import ( - "io" - "net/http" - "strings" -) - -// VersionMimetype is the Content-Type the engine sends to plugins. -const VersionMimetype = "application/vnd.docker.plugins.v1.2+json" - -// RequestFactory defines an interface that -// transports can implement to create new requests. -type RequestFactory interface { - NewRequest(path string, data io.Reader) (*http.Request, error) -} - -// Transport defines an interface that plugin transports -// must implement. -type Transport interface { - http.RoundTripper - RequestFactory -} - -// newHTTPRequest creates a new request with a path and a body. -func newHTTPRequest(path string, data io.Reader) (*http.Request, error) { - if !strings.HasPrefix(path, "/") { - path = "/" + path - } - req, err := http.NewRequest("POST", path, data) - if err != nil { - return nil, err - } - req.Header.Add("Accept", VersionMimetype) - return req, nil -} diff --git a/vendor/github.com/docker/docker/pkg/pools/pools.go b/vendor/github.com/docker/docker/pkg/pools/pools.go deleted file mode 100644 index 5c5aead..0000000 --- a/vendor/github.com/docker/docker/pkg/pools/pools.go +++ /dev/null @@ -1,116 +0,0 @@ -// Package pools provides a collection of pools which provide various -// data types with buffers. These can be used to lower the number of -// memory allocations and reuse buffers. -// -// New pools should be added to this package to allow them to be -// shared across packages. -// -// Utility functions which operate on pools should be added to this -// package to allow them to be reused. -package pools - -import ( - "bufio" - "io" - "sync" - - "github.com/docker/docker/pkg/ioutils" -) - -var ( - // BufioReader32KPool is a pool which returns bufio.Reader with a 32K buffer. - BufioReader32KPool = newBufioReaderPoolWithSize(buffer32K) - // BufioWriter32KPool is a pool which returns bufio.Writer with a 32K buffer. - BufioWriter32KPool = newBufioWriterPoolWithSize(buffer32K) -) - -const buffer32K = 32 * 1024 - -// BufioReaderPool is a bufio reader that uses sync.Pool. -type BufioReaderPool struct { - pool sync.Pool -} - -// newBufioReaderPoolWithSize is unexported because new pools should be -// added here to be shared where required. -func newBufioReaderPoolWithSize(size int) *BufioReaderPool { - return &BufioReaderPool{ - pool: sync.Pool{ - New: func() interface{} { return bufio.NewReaderSize(nil, size) }, - }, - } -} - -// Get returns a bufio.Reader which reads from r. The buffer size is that of the pool. -func (bufPool *BufioReaderPool) Get(r io.Reader) *bufio.Reader { - buf := bufPool.pool.Get().(*bufio.Reader) - buf.Reset(r) - return buf -} - -// Put puts the bufio.Reader back into the pool. -func (bufPool *BufioReaderPool) Put(b *bufio.Reader) { - b.Reset(nil) - bufPool.pool.Put(b) -} - -// Copy is a convenience wrapper which uses a buffer to avoid allocation in io.Copy. -func Copy(dst io.Writer, src io.Reader) (written int64, err error) { - buf := BufioReader32KPool.Get(src) - written, err = io.Copy(dst, buf) - BufioReader32KPool.Put(buf) - return -} - -// NewReadCloserWrapper returns a wrapper which puts the bufio.Reader back -// into the pool and closes the reader if it's an io.ReadCloser. -func (bufPool *BufioReaderPool) NewReadCloserWrapper(buf *bufio.Reader, r io.Reader) io.ReadCloser { - return ioutils.NewReadCloserWrapper(r, func() error { - if readCloser, ok := r.(io.ReadCloser); ok { - readCloser.Close() - } - bufPool.Put(buf) - return nil - }) -} - -// BufioWriterPool is a bufio writer that uses sync.Pool. -type BufioWriterPool struct { - pool sync.Pool -} - -// newBufioWriterPoolWithSize is unexported because new pools should be -// added here to be shared where required. -func newBufioWriterPoolWithSize(size int) *BufioWriterPool { - return &BufioWriterPool{ - pool: sync.Pool{ - New: func() interface{} { return bufio.NewWriterSize(nil, size) }, - }, - } -} - -// Get returns a bufio.Writer which writes to w. The buffer size is that of the pool. -func (bufPool *BufioWriterPool) Get(w io.Writer) *bufio.Writer { - buf := bufPool.pool.Get().(*bufio.Writer) - buf.Reset(w) - return buf -} - -// Put puts the bufio.Writer back into the pool. -func (bufPool *BufioWriterPool) Put(b *bufio.Writer) { - b.Reset(nil) - bufPool.pool.Put(b) -} - -// NewWriteCloserWrapper returns a wrapper which puts the bufio.Writer back -// into the pool and closes the writer if it's an io.Writecloser. -func (bufPool *BufioWriterPool) NewWriteCloserWrapper(buf *bufio.Writer, w io.Writer) io.WriteCloser { - return ioutils.NewWriteCloserWrapper(w, func() error { - buf.Flush() - if writeCloser, ok := w.(io.WriteCloser); ok { - writeCloser.Close() - } - bufPool.Put(buf) - return nil - }) -} diff --git a/vendor/github.com/docker/docker/pkg/pools/pools_test.go b/vendor/github.com/docker/docker/pkg/pools/pools_test.go deleted file mode 100644 index 1661b78..0000000 --- a/vendor/github.com/docker/docker/pkg/pools/pools_test.go +++ /dev/null @@ -1,161 +0,0 @@ -package pools - -import ( - "bufio" - "bytes" - "io" - "strings" - "testing" -) - -func TestBufioReaderPoolGetWithNoReaderShouldCreateOne(t *testing.T) { - reader := BufioReader32KPool.Get(nil) - if reader == nil { - t.Fatalf("BufioReaderPool should have create a bufio.Reader but did not.") - } -} - -func TestBufioReaderPoolPutAndGet(t *testing.T) { - sr := bufio.NewReader(strings.NewReader("foobar")) - reader := BufioReader32KPool.Get(sr) - if reader == nil { - t.Fatalf("BufioReaderPool should not return a nil reader.") - } - // verify the first 3 byte - buf1 := make([]byte, 3) - _, err := reader.Read(buf1) - if err != nil { - t.Fatal(err) - } - if actual := string(buf1); actual != "foo" { - t.Fatalf("The first letter should have been 'foo' but was %v", actual) - } - BufioReader32KPool.Put(reader) - // Try to read the next 3 bytes - _, err = sr.Read(make([]byte, 3)) - if err == nil || err != io.EOF { - t.Fatalf("The buffer should have been empty, issue an EOF error.") - } -} - -type simpleReaderCloser struct { - io.Reader - closed bool -} - -func (r *simpleReaderCloser) Close() error { - r.closed = true - return nil -} - -func TestNewReadCloserWrapperWithAReadCloser(t *testing.T) { - br := bufio.NewReader(strings.NewReader("")) - sr := &simpleReaderCloser{ - Reader: strings.NewReader("foobar"), - closed: false, - } - reader := BufioReader32KPool.NewReadCloserWrapper(br, sr) - if reader == nil { - t.Fatalf("NewReadCloserWrapper should not return a nil reader.") - } - // Verify the content of reader - buf := make([]byte, 3) - _, err := reader.Read(buf) - if err != nil { - t.Fatal(err) - } - if actual := string(buf); actual != "foo" { - t.Fatalf("The first 3 letter should have been 'foo' but were %v", actual) - } - reader.Close() - // Read 3 more bytes "bar" - _, err = reader.Read(buf) - if err != nil { - t.Fatal(err) - } - if actual := string(buf); actual != "bar" { - t.Fatalf("The first 3 letter should have been 'bar' but were %v", actual) - } - if !sr.closed { - t.Fatalf("The ReaderCloser should have been closed, it is not.") - } -} - -func TestBufioWriterPoolGetWithNoReaderShouldCreateOne(t *testing.T) { - writer := BufioWriter32KPool.Get(nil) - if writer == nil { - t.Fatalf("BufioWriterPool should have create a bufio.Writer but did not.") - } -} - -func TestBufioWriterPoolPutAndGet(t *testing.T) { - buf := new(bytes.Buffer) - bw := bufio.NewWriter(buf) - writer := BufioWriter32KPool.Get(bw) - if writer == nil { - t.Fatalf("BufioReaderPool should not return a nil writer.") - } - written, err := writer.Write([]byte("foobar")) - if err != nil { - t.Fatal(err) - } - if written != 6 { - t.Fatalf("Should have written 6 bytes, but wrote %v bytes", written) - } - // Make sure we Flush all the way ? - writer.Flush() - bw.Flush() - if len(buf.Bytes()) != 6 { - t.Fatalf("The buffer should contain 6 bytes ('foobar') but contains %v ('%v')", buf.Bytes(), string(buf.Bytes())) - } - // Reset the buffer - buf.Reset() - BufioWriter32KPool.Put(writer) - // Try to write something - if _, err = writer.Write([]byte("barfoo")); err != nil { - t.Fatal(err) - } - // If we now try to flush it, it should panic (the writer is nil) - // recover it - defer func() { - if r := recover(); r == nil { - t.Fatal("Trying to flush the writter should have 'paniced', did not.") - } - }() - writer.Flush() -} - -type simpleWriterCloser struct { - io.Writer - closed bool -} - -func (r *simpleWriterCloser) Close() error { - r.closed = true - return nil -} - -func TestNewWriteCloserWrapperWithAWriteCloser(t *testing.T) { - buf := new(bytes.Buffer) - bw := bufio.NewWriter(buf) - sw := &simpleWriterCloser{ - Writer: new(bytes.Buffer), - closed: false, - } - bw.Flush() - writer := BufioWriter32KPool.NewWriteCloserWrapper(bw, sw) - if writer == nil { - t.Fatalf("BufioReaderPool should not return a nil writer.") - } - written, err := writer.Write([]byte("foobar")) - if err != nil { - t.Fatal(err) - } - if written != 6 { - t.Fatalf("Should have written 6 bytes, but wrote %v bytes", written) - } - writer.Close() - if !sw.closed { - t.Fatalf("The ReaderCloser should have been closed, it is not.") - } -} diff --git a/vendor/github.com/docker/docker/pkg/progress/progress.go b/vendor/github.com/docker/docker/pkg/progress/progress.go deleted file mode 100644 index fcf3117..0000000 --- a/vendor/github.com/docker/docker/pkg/progress/progress.go +++ /dev/null @@ -1,84 +0,0 @@ -package progress - -import ( - "fmt" -) - -// Progress represents the progress of a transfer. -type Progress struct { - ID string - - // Progress contains a Message or... - Message string - - // ...progress of an action - Action string - Current int64 - Total int64 - - // Aux contains extra information not presented to the user, such as - // digests for push signing. - Aux interface{} - - LastUpdate bool -} - -// Output is an interface for writing progress information. It's -// like a writer for progress, but we don't call it Writer because -// that would be confusing next to ProgressReader (also, because it -// doesn't implement the io.Writer interface). -type Output interface { - WriteProgress(Progress) error -} - -type chanOutput chan<- Progress - -func (out chanOutput) WriteProgress(p Progress) error { - out <- p - return nil -} - -// ChanOutput returns an Output that writes progress updates to the -// supplied channel. -func ChanOutput(progressChan chan<- Progress) Output { - return chanOutput(progressChan) -} - -type discardOutput struct{} - -func (discardOutput) WriteProgress(Progress) error { - return nil -} - -// DiscardOutput returns an Output that discards progress -func DiscardOutput() Output { - return discardOutput{} -} - -// Update is a convenience function to write a progress update to the channel. -func Update(out Output, id, action string) { - out.WriteProgress(Progress{ID: id, Action: action}) -} - -// Updatef is a convenience function to write a printf-formatted progress update -// to the channel. -func Updatef(out Output, id, format string, a ...interface{}) { - Update(out, id, fmt.Sprintf(format, a...)) -} - -// Message is a convenience function to write a progress message to the channel. -func Message(out Output, id, message string) { - out.WriteProgress(Progress{ID: id, Message: message}) -} - -// Messagef is a convenience function to write a printf-formatted progress -// message to the channel. -func Messagef(out Output, id, format string, a ...interface{}) { - Message(out, id, fmt.Sprintf(format, a...)) -} - -// Aux sends auxiliary information over a progress interface, which will not be -// formatted for the UI. This is used for things such as push signing. -func Aux(out Output, a interface{}) { - out.WriteProgress(Progress{Aux: a}) -} diff --git a/vendor/github.com/docker/docker/pkg/progress/progressreader.go b/vendor/github.com/docker/docker/pkg/progress/progressreader.go deleted file mode 100644 index 6b3927e..0000000 --- a/vendor/github.com/docker/docker/pkg/progress/progressreader.go +++ /dev/null @@ -1,66 +0,0 @@ -package progress - -import ( - "io" - "time" - - "golang.org/x/time/rate" -) - -// Reader is a Reader with progress bar. -type Reader struct { - in io.ReadCloser // Stream to read from - out Output // Where to send progress bar to - size int64 - current int64 - lastUpdate int64 - id string - action string - rateLimiter *rate.Limiter -} - -// NewProgressReader creates a new ProgressReader. -func NewProgressReader(in io.ReadCloser, out Output, size int64, id, action string) *Reader { - return &Reader{ - in: in, - out: out, - size: size, - id: id, - action: action, - rateLimiter: rate.NewLimiter(rate.Every(100*time.Millisecond), 1), - } -} - -func (p *Reader) Read(buf []byte) (n int, err error) { - read, err := p.in.Read(buf) - p.current += int64(read) - updateEvery := int64(1024 * 512) //512kB - if p.size > 0 { - // Update progress for every 1% read if 1% < 512kB - if increment := int64(0.01 * float64(p.size)); increment < updateEvery { - updateEvery = increment - } - } - if p.current-p.lastUpdate > updateEvery || err != nil { - p.updateProgress(err != nil && read == 0) - p.lastUpdate = p.current - } - - return read, err -} - -// Close closes the progress reader and its underlying reader. -func (p *Reader) Close() error { - if p.current < p.size { - // print a full progress bar when closing prematurely - p.current = p.size - p.updateProgress(false) - } - return p.in.Close() -} - -func (p *Reader) updateProgress(last bool) { - if last || p.current == p.size || p.rateLimiter.Allow() { - p.out.WriteProgress(Progress{ID: p.id, Action: p.action, Current: p.current, Total: p.size, LastUpdate: last}) - } -} diff --git a/vendor/github.com/docker/docker/pkg/progress/progressreader_test.go b/vendor/github.com/docker/docker/pkg/progress/progressreader_test.go deleted file mode 100644 index b14d401..0000000 --- a/vendor/github.com/docker/docker/pkg/progress/progressreader_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package progress - -import ( - "bytes" - "io" - "io/ioutil" - "testing" -) - -func TestOutputOnPrematureClose(t *testing.T) { - content := []byte("TESTING") - reader := ioutil.NopCloser(bytes.NewReader(content)) - progressChan := make(chan Progress, 10) - - pr := NewProgressReader(reader, ChanOutput(progressChan), int64(len(content)), "Test", "Read") - - part := make([]byte, 4, 4) - _, err := io.ReadFull(pr, part) - if err != nil { - pr.Close() - t.Fatal(err) - } - -drainLoop: - for { - select { - case <-progressChan: - default: - break drainLoop - } - } - - pr.Close() - - select { - case <-progressChan: - default: - t.Fatalf("Expected some output when closing prematurely") - } -} - -func TestCompleteSilently(t *testing.T) { - content := []byte("TESTING") - reader := ioutil.NopCloser(bytes.NewReader(content)) - progressChan := make(chan Progress, 10) - - pr := NewProgressReader(reader, ChanOutput(progressChan), int64(len(content)), "Test", "Read") - - out, err := ioutil.ReadAll(pr) - if err != nil { - pr.Close() - t.Fatal(err) - } - if string(out) != "TESTING" { - pr.Close() - t.Fatalf("Unexpected output %q from reader", string(out)) - } - -drainLoop: - for { - select { - case <-progressChan: - default: - break drainLoop - } - } - - pr.Close() - - select { - case <-progressChan: - t.Fatalf("Should have closed silently when read is complete") - default: - } -} diff --git a/vendor/github.com/docker/docker/pkg/promise/promise.go b/vendor/github.com/docker/docker/pkg/promise/promise.go deleted file mode 100644 index dd52b90..0000000 --- a/vendor/github.com/docker/docker/pkg/promise/promise.go +++ /dev/null @@ -1,11 +0,0 @@ -package promise - -// Go is a basic promise implementation: it wraps calls a function in a goroutine, -// and returns a channel which will later return the function's return value. -func Go(f func() error) chan error { - ch := make(chan error, 1) - go func() { - ch <- f() - }() - return ch -} diff --git a/vendor/github.com/docker/docker/pkg/pubsub/publisher.go b/vendor/github.com/docker/docker/pkg/pubsub/publisher.go deleted file mode 100644 index 0936461..0000000 --- a/vendor/github.com/docker/docker/pkg/pubsub/publisher.go +++ /dev/null @@ -1,111 +0,0 @@ -package pubsub - -import ( - "sync" - "time" -) - -var wgPool = sync.Pool{New: func() interface{} { return new(sync.WaitGroup) }} - -// NewPublisher creates a new pub/sub publisher to broadcast messages. -// The duration is used as the send timeout as to not block the publisher publishing -// messages to other clients if one client is slow or unresponsive. -// The buffer is used when creating new channels for subscribers. -func NewPublisher(publishTimeout time.Duration, buffer int) *Publisher { - return &Publisher{ - buffer: buffer, - timeout: publishTimeout, - subscribers: make(map[subscriber]topicFunc), - } -} - -type subscriber chan interface{} -type topicFunc func(v interface{}) bool - -// Publisher is basic pub/sub structure. Allows to send events and subscribe -// to them. Can be safely used from multiple goroutines. -type Publisher struct { - m sync.RWMutex - buffer int - timeout time.Duration - subscribers map[subscriber]topicFunc -} - -// Len returns the number of subscribers for the publisher -func (p *Publisher) Len() int { - p.m.RLock() - i := len(p.subscribers) - p.m.RUnlock() - return i -} - -// Subscribe adds a new subscriber to the publisher returning the channel. -func (p *Publisher) Subscribe() chan interface{} { - return p.SubscribeTopic(nil) -} - -// SubscribeTopic adds a new subscriber that filters messages sent by a topic. -func (p *Publisher) SubscribeTopic(topic topicFunc) chan interface{} { - ch := make(chan interface{}, p.buffer) - p.m.Lock() - p.subscribers[ch] = topic - p.m.Unlock() - return ch -} - -// Evict removes the specified subscriber from receiving any more messages. -func (p *Publisher) Evict(sub chan interface{}) { - p.m.Lock() - delete(p.subscribers, sub) - close(sub) - p.m.Unlock() -} - -// Publish sends the data in v to all subscribers currently registered with the publisher. -func (p *Publisher) Publish(v interface{}) { - p.m.RLock() - if len(p.subscribers) == 0 { - p.m.RUnlock() - return - } - - wg := wgPool.Get().(*sync.WaitGroup) - for sub, topic := range p.subscribers { - wg.Add(1) - go p.sendTopic(sub, topic, v, wg) - } - wg.Wait() - wgPool.Put(wg) - p.m.RUnlock() -} - -// Close closes the channels to all subscribers registered with the publisher. -func (p *Publisher) Close() { - p.m.Lock() - for sub := range p.subscribers { - delete(p.subscribers, sub) - close(sub) - } - p.m.Unlock() -} - -func (p *Publisher) sendTopic(sub subscriber, topic topicFunc, v interface{}, wg *sync.WaitGroup) { - defer wg.Done() - if topic != nil && !topic(v) { - return - } - - // send under a select as to not block if the receiver is unavailable - if p.timeout > 0 { - select { - case sub <- v: - case <-time.After(p.timeout): - } - return - } - - select { - case sub <- v: - default: - } -} diff --git a/vendor/github.com/docker/docker/pkg/pubsub/publisher_test.go b/vendor/github.com/docker/docker/pkg/pubsub/publisher_test.go deleted file mode 100644 index d6b0a1d..0000000 --- a/vendor/github.com/docker/docker/pkg/pubsub/publisher_test.go +++ /dev/null @@ -1,142 +0,0 @@ -package pubsub - -import ( - "fmt" - "testing" - "time" -) - -func TestSendToOneSub(t *testing.T) { - p := NewPublisher(100*time.Millisecond, 10) - c := p.Subscribe() - - p.Publish("hi") - - msg := <-c - if msg.(string) != "hi" { - t.Fatalf("expected message hi but received %v", msg) - } -} - -func TestSendToMultipleSubs(t *testing.T) { - p := NewPublisher(100*time.Millisecond, 10) - subs := []chan interface{}{} - subs = append(subs, p.Subscribe(), p.Subscribe(), p.Subscribe()) - - p.Publish("hi") - - for _, c := range subs { - msg := <-c - if msg.(string) != "hi" { - t.Fatalf("expected message hi but received %v", msg) - } - } -} - -func TestEvictOneSub(t *testing.T) { - p := NewPublisher(100*time.Millisecond, 10) - s1 := p.Subscribe() - s2 := p.Subscribe() - - p.Evict(s1) - p.Publish("hi") - if _, ok := <-s1; ok { - t.Fatal("expected s1 to not receive the published message") - } - - msg := <-s2 - if msg.(string) != "hi" { - t.Fatalf("expected message hi but received %v", msg) - } -} - -func TestClosePublisher(t *testing.T) { - p := NewPublisher(100*time.Millisecond, 10) - subs := []chan interface{}{} - subs = append(subs, p.Subscribe(), p.Subscribe(), p.Subscribe()) - p.Close() - - for _, c := range subs { - if _, ok := <-c; ok { - t.Fatal("expected all subscriber channels to be closed") - } - } -} - -const sampleText = "test" - -type testSubscriber struct { - dataCh chan interface{} - ch chan error -} - -func (s *testSubscriber) Wait() error { - return <-s.ch -} - -func newTestSubscriber(p *Publisher) *testSubscriber { - ts := &testSubscriber{ - dataCh: p.Subscribe(), - ch: make(chan error), - } - go func() { - for data := range ts.dataCh { - s, ok := data.(string) - if !ok { - ts.ch <- fmt.Errorf("Unexpected type %T", data) - break - } - if s != sampleText { - ts.ch <- fmt.Errorf("Unexpected text %s", s) - break - } - } - close(ts.ch) - }() - return ts -} - -// for testing with -race -func TestPubSubRace(t *testing.T) { - p := NewPublisher(0, 1024) - var subs [](*testSubscriber) - for j := 0; j < 50; j++ { - subs = append(subs, newTestSubscriber(p)) - } - for j := 0; j < 1000; j++ { - p.Publish(sampleText) - } - time.AfterFunc(1*time.Second, func() { - for _, s := range subs { - p.Evict(s.dataCh) - } - }) - for _, s := range subs { - s.Wait() - } -} - -func BenchmarkPubSub(b *testing.B) { - for i := 0; i < b.N; i++ { - b.StopTimer() - p := NewPublisher(0, 1024) - var subs [](*testSubscriber) - for j := 0; j < 50; j++ { - subs = append(subs, newTestSubscriber(p)) - } - b.StartTimer() - for j := 0; j < 1000; j++ { - p.Publish(sampleText) - } - time.AfterFunc(1*time.Second, func() { - for _, s := range subs { - p.Evict(s.dataCh) - } - }) - for _, s := range subs { - if err := s.Wait(); err != nil { - b.Fatal(err) - } - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/random/random.go b/vendor/github.com/docker/docker/pkg/random/random.go deleted file mode 100644 index 70de4d1..0000000 --- a/vendor/github.com/docker/docker/pkg/random/random.go +++ /dev/null @@ -1,71 +0,0 @@ -package random - -import ( - cryptorand "crypto/rand" - "io" - "math" - "math/big" - "math/rand" - "sync" - "time" -) - -// Rand is a global *rand.Rand instance, which initialized with NewSource() source. -var Rand = rand.New(NewSource()) - -// Reader is a global, shared instance of a pseudorandom bytes generator. -// It doesn't consume entropy. -var Reader io.Reader = &reader{rnd: Rand} - -// copypaste from standard math/rand -type lockedSource struct { - lk sync.Mutex - src rand.Source -} - -func (r *lockedSource) Int63() (n int64) { - r.lk.Lock() - n = r.src.Int63() - r.lk.Unlock() - return -} - -func (r *lockedSource) Seed(seed int64) { - r.lk.Lock() - r.src.Seed(seed) - r.lk.Unlock() -} - -// NewSource returns math/rand.Source safe for concurrent use and initialized -// with current unix-nano timestamp -func NewSource() rand.Source { - var seed int64 - if cryptoseed, err := cryptorand.Int(cryptorand.Reader, big.NewInt(math.MaxInt64)); err != nil { - // This should not happen, but worst-case fallback to time-based seed. - seed = time.Now().UnixNano() - } else { - seed = cryptoseed.Int64() - } - return &lockedSource{ - src: rand.NewSource(seed), - } -} - -type reader struct { - rnd *rand.Rand -} - -func (r *reader) Read(b []byte) (int, error) { - i := 0 - for { - val := r.rnd.Int63() - for val > 0 { - b[i] = byte(val) - i++ - if i == len(b) { - return i, nil - } - val >>= 8 - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/random/random_test.go b/vendor/github.com/docker/docker/pkg/random/random_test.go deleted file mode 100644 index cf405f7..0000000 --- a/vendor/github.com/docker/docker/pkg/random/random_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package random - -import ( - "math/rand" - "sync" - "testing" -) - -// for go test -v -race -func TestConcurrency(t *testing.T) { - rnd := rand.New(NewSource()) - var wg sync.WaitGroup - - for i := 0; i < 10; i++ { - wg.Add(1) - go func() { - rnd.Int63() - wg.Done() - }() - } - wg.Wait() -} diff --git a/vendor/github.com/docker/docker/pkg/reexec/README.md b/vendor/github.com/docker/docker/pkg/reexec/README.md deleted file mode 100644 index 45592ce..0000000 --- a/vendor/github.com/docker/docker/pkg/reexec/README.md +++ /dev/null @@ -1,5 +0,0 @@ -## reexec - -The `reexec` package facilitates the busybox style reexec of the docker binary that we require because -of the forking limitations of using Go. Handlers can be registered with a name and the argv 0 of -the exec of the binary will be used to find and execute custom init paths. diff --git a/vendor/github.com/docker/docker/pkg/reexec/command_linux.go b/vendor/github.com/docker/docker/pkg/reexec/command_linux.go deleted file mode 100644 index 34ae2a9..0000000 --- a/vendor/github.com/docker/docker/pkg/reexec/command_linux.go +++ /dev/null @@ -1,28 +0,0 @@ -// +build linux - -package reexec - -import ( - "os/exec" - "syscall" -) - -// Self returns the path to the current process's binary. -// Returns "/proc/self/exe". -func Self() string { - return "/proc/self/exe" -} - -// Command returns *exec.Cmd which has Path as current binary. Also it setting -// SysProcAttr.Pdeathsig to SIGTERM. -// This will use the in-memory version (/proc/self/exe) of the current binary, -// it is thus safe to delete or replace the on-disk binary (os.Args[0]). -func Command(args ...string) *exec.Cmd { - return &exec.Cmd{ - Path: Self(), - Args: args, - SysProcAttr: &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGTERM, - }, - } -} diff --git a/vendor/github.com/docker/docker/pkg/reexec/command_unix.go b/vendor/github.com/docker/docker/pkg/reexec/command_unix.go deleted file mode 100644 index 778a720..0000000 --- a/vendor/github.com/docker/docker/pkg/reexec/command_unix.go +++ /dev/null @@ -1,23 +0,0 @@ -// +build freebsd solaris darwin - -package reexec - -import ( - "os/exec" -) - -// Self returns the path to the current process's binary. -// Uses os.Args[0]. -func Self() string { - return naiveSelf() -} - -// Command returns *exec.Cmd which has Path as current binary. -// For example if current binary is "docker" at "/usr/bin/", then cmd.Path will -// be set to "/usr/bin/docker". -func Command(args ...string) *exec.Cmd { - return &exec.Cmd{ - Path: Self(), - Args: args, - } -} diff --git a/vendor/github.com/docker/docker/pkg/reexec/command_unsupported.go b/vendor/github.com/docker/docker/pkg/reexec/command_unsupported.go deleted file mode 100644 index 76edd82..0000000 --- a/vendor/github.com/docker/docker/pkg/reexec/command_unsupported.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !linux,!windows,!freebsd,!solaris,!darwin - -package reexec - -import ( - "os/exec" -) - -// Command is unsupported on operating systems apart from Linux, Windows, Solaris and Darwin. -func Command(args ...string) *exec.Cmd { - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/reexec/command_windows.go b/vendor/github.com/docker/docker/pkg/reexec/command_windows.go deleted file mode 100644 index ca871c4..0000000 --- a/vendor/github.com/docker/docker/pkg/reexec/command_windows.go +++ /dev/null @@ -1,23 +0,0 @@ -// +build windows - -package reexec - -import ( - "os/exec" -) - -// Self returns the path to the current process's binary. -// Uses os.Args[0]. -func Self() string { - return naiveSelf() -} - -// Command returns *exec.Cmd which has Path as current binary. -// For example if current binary is "docker.exe" at "C:\", then cmd.Path will -// be set to "C:\docker.exe". -func Command(args ...string) *exec.Cmd { - return &exec.Cmd{ - Path: Self(), - Args: args, - } -} diff --git a/vendor/github.com/docker/docker/pkg/reexec/reexec.go b/vendor/github.com/docker/docker/pkg/reexec/reexec.go deleted file mode 100644 index c56671d..0000000 --- a/vendor/github.com/docker/docker/pkg/reexec/reexec.go +++ /dev/null @@ -1,47 +0,0 @@ -package reexec - -import ( - "fmt" - "os" - "os/exec" - "path/filepath" -) - -var registeredInitializers = make(map[string]func()) - -// Register adds an initialization func under the specified name -func Register(name string, initializer func()) { - if _, exists := registeredInitializers[name]; exists { - panic(fmt.Sprintf("reexec func already registered under name %q", name)) - } - - registeredInitializers[name] = initializer -} - -// Init is called as the first part of the exec process and returns true if an -// initialization function was called. -func Init() bool { - initializer, exists := registeredInitializers[os.Args[0]] - if exists { - initializer() - - return true - } - return false -} - -func naiveSelf() string { - name := os.Args[0] - if filepath.Base(name) == name { - if lp, err := exec.LookPath(name); err == nil { - return lp - } - } - // handle conversion of relative paths to absolute - if absName, err := filepath.Abs(name); err == nil { - return absName - } - // if we couldn't get absolute name, return original - // (NOTE: Go only errors on Abs() if os.Getwd fails) - return name -} diff --git a/vendor/github.com/docker/docker/pkg/registrar/registrar.go b/vendor/github.com/docker/docker/pkg/registrar/registrar.go deleted file mode 100644 index 1e75ee9..0000000 --- a/vendor/github.com/docker/docker/pkg/registrar/registrar.go +++ /dev/null @@ -1,127 +0,0 @@ -// Package registrar provides name registration. It reserves a name to a given key. -package registrar - -import ( - "errors" - "sync" -) - -var ( - // ErrNameReserved is an error which is returned when a name is requested to be reserved that already is reserved - ErrNameReserved = errors.New("name is reserved") - // ErrNameNotReserved is an error which is returned when trying to find a name that is not reserved - ErrNameNotReserved = errors.New("name is not reserved") - // ErrNoSuchKey is returned when trying to find the names for a key which is not known - ErrNoSuchKey = errors.New("provided key does not exist") -) - -// Registrar stores indexes a list of keys and their registered names as well as indexes names and the key that they are registered to -// Names must be unique. -// Registrar is safe for concurrent access. -type Registrar struct { - idx map[string][]string - names map[string]string - mu sync.Mutex -} - -// NewRegistrar creates a new Registrar with the an empty index -func NewRegistrar() *Registrar { - return &Registrar{ - idx: make(map[string][]string), - names: make(map[string]string), - } -} - -// Reserve registers a key to a name -// Reserve is idempotent -// Attempting to reserve a key to a name that already exists results in an `ErrNameReserved` -// A name reservation is globally unique -func (r *Registrar) Reserve(name, key string) error { - r.mu.Lock() - defer r.mu.Unlock() - - if k, exists := r.names[name]; exists { - if k != key { - return ErrNameReserved - } - return nil - } - - r.idx[key] = append(r.idx[key], name) - r.names[name] = key - return nil -} - -// Release releases the reserved name -// Once released, a name can be reserved again -func (r *Registrar) Release(name string) { - r.mu.Lock() - defer r.mu.Unlock() - - key, exists := r.names[name] - if !exists { - return - } - - for i, n := range r.idx[key] { - if n != name { - continue - } - r.idx[key] = append(r.idx[key][:i], r.idx[key][i+1:]...) - break - } - - delete(r.names, name) - - if len(r.idx[key]) == 0 { - delete(r.idx, key) - } -} - -// Delete removes all reservations for the passed in key. -// All names reserved to this key are released. -func (r *Registrar) Delete(key string) { - r.mu.Lock() - for _, name := range r.idx[key] { - delete(r.names, name) - } - delete(r.idx, key) - r.mu.Unlock() -} - -// GetNames lists all the reserved names for the given key -func (r *Registrar) GetNames(key string) ([]string, error) { - r.mu.Lock() - defer r.mu.Unlock() - - names, exists := r.idx[key] - if !exists { - return nil, ErrNoSuchKey - } - return names, nil -} - -// Get returns the key that the passed in name is reserved to -func (r *Registrar) Get(name string) (string, error) { - r.mu.Lock() - key, exists := r.names[name] - r.mu.Unlock() - - if !exists { - return "", ErrNameNotReserved - } - return key, nil -} - -// GetAll returns all registered names -func (r *Registrar) GetAll() map[string][]string { - out := make(map[string][]string) - - r.mu.Lock() - // copy index into out - for id, names := range r.idx { - out[id] = names - } - r.mu.Unlock() - return out -} diff --git a/vendor/github.com/docker/docker/pkg/registrar/registrar_test.go b/vendor/github.com/docker/docker/pkg/registrar/registrar_test.go deleted file mode 100644 index 0c1ef31..0000000 --- a/vendor/github.com/docker/docker/pkg/registrar/registrar_test.go +++ /dev/null @@ -1,119 +0,0 @@ -package registrar - -import ( - "reflect" - "testing" -) - -func TestReserve(t *testing.T) { - r := NewRegistrar() - - obj := "test1" - if err := r.Reserve("test", obj); err != nil { - t.Fatal(err) - } - - if err := r.Reserve("test", obj); err != nil { - t.Fatal(err) - } - - obj2 := "test2" - err := r.Reserve("test", obj2) - if err == nil { - t.Fatalf("expected error when reserving an already reserved name to another object") - } - if err != ErrNameReserved { - t.Fatal("expected `ErrNameReserved` error when attempting to reserve an already reserved name") - } -} - -func TestRelease(t *testing.T) { - r := NewRegistrar() - obj := "testing" - - if err := r.Reserve("test", obj); err != nil { - t.Fatal(err) - } - r.Release("test") - r.Release("test") // Ensure there is no panic here - - if err := r.Reserve("test", obj); err != nil { - t.Fatal(err) - } -} - -func TestGetNames(t *testing.T) { - r := NewRegistrar() - obj := "testing" - names := []string{"test1", "test2"} - - for _, name := range names { - if err := r.Reserve(name, obj); err != nil { - t.Fatal(err) - } - } - r.Reserve("test3", "other") - - names2, err := r.GetNames(obj) - if err != nil { - t.Fatal(err) - } - - if !reflect.DeepEqual(names, names2) { - t.Fatalf("Exepected: %v, Got: %v", names, names2) - } -} - -func TestDelete(t *testing.T) { - r := NewRegistrar() - obj := "testing" - names := []string{"test1", "test2"} - for _, name := range names { - if err := r.Reserve(name, obj); err != nil { - t.Fatal(err) - } - } - - r.Reserve("test3", "other") - r.Delete(obj) - - _, err := r.GetNames(obj) - if err == nil { - t.Fatal("expected error getting names for deleted key") - } - - if err != ErrNoSuchKey { - t.Fatal("expected `ErrNoSuchKey`") - } -} - -func TestGet(t *testing.T) { - r := NewRegistrar() - obj := "testing" - name := "test" - - _, err := r.Get(name) - if err == nil { - t.Fatal("expected error when key does not exist") - } - if err != ErrNameNotReserved { - t.Fatal(err) - } - - if err := r.Reserve(name, obj); err != nil { - t.Fatal(err) - } - - if _, err = r.Get(name); err != nil { - t.Fatal(err) - } - - r.Delete(obj) - _, err = r.Get(name) - if err == nil { - t.Fatal("expected error when key does not exist") - } - if err != ErrNameNotReserved { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/pkg/signal/README.md b/vendor/github.com/docker/docker/pkg/signal/README.md deleted file mode 100644 index 2b237a5..0000000 --- a/vendor/github.com/docker/docker/pkg/signal/README.md +++ /dev/null @@ -1 +0,0 @@ -This package provides helper functions for dealing with signals across various operating systems \ No newline at end of file diff --git a/vendor/github.com/docker/docker/pkg/signal/signal.go b/vendor/github.com/docker/docker/pkg/signal/signal.go deleted file mode 100644 index 68bb77c..0000000 --- a/vendor/github.com/docker/docker/pkg/signal/signal.go +++ /dev/null @@ -1,54 +0,0 @@ -// Package signal provides helper functions for dealing with signals across -// various operating systems. -package signal - -import ( - "fmt" - "os" - "os/signal" - "strconv" - "strings" - "syscall" -) - -// CatchAll catches all signals and relays them to the specified channel. -func CatchAll(sigc chan os.Signal) { - handledSigs := []os.Signal{} - for _, s := range SignalMap { - handledSigs = append(handledSigs, s) - } - signal.Notify(sigc, handledSigs...) -} - -// StopCatch stops catching the signals and closes the specified channel. -func StopCatch(sigc chan os.Signal) { - signal.Stop(sigc) - close(sigc) -} - -// ParseSignal translates a string to a valid syscall signal. -// It returns an error if the signal map doesn't include the given signal. -func ParseSignal(rawSignal string) (syscall.Signal, error) { - s, err := strconv.Atoi(rawSignal) - if err == nil { - if s == 0 { - return -1, fmt.Errorf("Invalid signal: %s", rawSignal) - } - return syscall.Signal(s), nil - } - signal, ok := SignalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")] - if !ok { - return -1, fmt.Errorf("Invalid signal: %s", rawSignal) - } - return signal, nil -} - -// ValidSignalForPlatform returns true if a signal is valid on the platform -func ValidSignalForPlatform(sig syscall.Signal) bool { - for _, v := range SignalMap { - if v == sig { - return true - } - } - return false -} diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_darwin.go b/vendor/github.com/docker/docker/pkg/signal/signal_darwin.go deleted file mode 100644 index 946de87..0000000 --- a/vendor/github.com/docker/docker/pkg/signal/signal_darwin.go +++ /dev/null @@ -1,41 +0,0 @@ -package signal - -import ( - "syscall" -) - -// SignalMap is a map of Darwin signals. -var SignalMap = map[string]syscall.Signal{ - "ABRT": syscall.SIGABRT, - "ALRM": syscall.SIGALRM, - "BUG": syscall.SIGBUS, - "CHLD": syscall.SIGCHLD, - "CONT": syscall.SIGCONT, - "EMT": syscall.SIGEMT, - "FPE": syscall.SIGFPE, - "HUP": syscall.SIGHUP, - "ILL": syscall.SIGILL, - "INFO": syscall.SIGINFO, - "INT": syscall.SIGINT, - "IO": syscall.SIGIO, - "IOT": syscall.SIGIOT, - "KILL": syscall.SIGKILL, - "PIPE": syscall.SIGPIPE, - "PROF": syscall.SIGPROF, - "QUIT": syscall.SIGQUIT, - "SEGV": syscall.SIGSEGV, - "STOP": syscall.SIGSTOP, - "SYS": syscall.SIGSYS, - "TERM": syscall.SIGTERM, - "TRAP": syscall.SIGTRAP, - "TSTP": syscall.SIGTSTP, - "TTIN": syscall.SIGTTIN, - "TTOU": syscall.SIGTTOU, - "URG": syscall.SIGURG, - "USR1": syscall.SIGUSR1, - "USR2": syscall.SIGUSR2, - "VTALRM": syscall.SIGVTALRM, - "WINCH": syscall.SIGWINCH, - "XCPU": syscall.SIGXCPU, - "XFSZ": syscall.SIGXFSZ, -} diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_freebsd.go b/vendor/github.com/docker/docker/pkg/signal/signal_freebsd.go deleted file mode 100644 index 6b9569b..0000000 --- a/vendor/github.com/docker/docker/pkg/signal/signal_freebsd.go +++ /dev/null @@ -1,43 +0,0 @@ -package signal - -import ( - "syscall" -) - -// SignalMap is a map of FreeBSD signals. -var SignalMap = map[string]syscall.Signal{ - "ABRT": syscall.SIGABRT, - "ALRM": syscall.SIGALRM, - "BUF": syscall.SIGBUS, - "CHLD": syscall.SIGCHLD, - "CONT": syscall.SIGCONT, - "EMT": syscall.SIGEMT, - "FPE": syscall.SIGFPE, - "HUP": syscall.SIGHUP, - "ILL": syscall.SIGILL, - "INFO": syscall.SIGINFO, - "INT": syscall.SIGINT, - "IO": syscall.SIGIO, - "IOT": syscall.SIGIOT, - "KILL": syscall.SIGKILL, - "LWP": syscall.SIGLWP, - "PIPE": syscall.SIGPIPE, - "PROF": syscall.SIGPROF, - "QUIT": syscall.SIGQUIT, - "SEGV": syscall.SIGSEGV, - "STOP": syscall.SIGSTOP, - "SYS": syscall.SIGSYS, - "TERM": syscall.SIGTERM, - "THR": syscall.SIGTHR, - "TRAP": syscall.SIGTRAP, - "TSTP": syscall.SIGTSTP, - "TTIN": syscall.SIGTTIN, - "TTOU": syscall.SIGTTOU, - "URG": syscall.SIGURG, - "USR1": syscall.SIGUSR1, - "USR2": syscall.SIGUSR2, - "VTALRM": syscall.SIGVTALRM, - "WINCH": syscall.SIGWINCH, - "XCPU": syscall.SIGXCPU, - "XFSZ": syscall.SIGXFSZ, -} diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_linux.go b/vendor/github.com/docker/docker/pkg/signal/signal_linux.go deleted file mode 100644 index d418cbe..0000000 --- a/vendor/github.com/docker/docker/pkg/signal/signal_linux.go +++ /dev/null @@ -1,80 +0,0 @@ -package signal - -import ( - "syscall" -) - -const ( - sigrtmin = 34 - sigrtmax = 64 -) - -// SignalMap is a map of Linux signals. -var SignalMap = map[string]syscall.Signal{ - "ABRT": syscall.SIGABRT, - "ALRM": syscall.SIGALRM, - "BUS": syscall.SIGBUS, - "CHLD": syscall.SIGCHLD, - "CLD": syscall.SIGCLD, - "CONT": syscall.SIGCONT, - "FPE": syscall.SIGFPE, - "HUP": syscall.SIGHUP, - "ILL": syscall.SIGILL, - "INT": syscall.SIGINT, - "IO": syscall.SIGIO, - "IOT": syscall.SIGIOT, - "KILL": syscall.SIGKILL, - "PIPE": syscall.SIGPIPE, - "POLL": syscall.SIGPOLL, - "PROF": syscall.SIGPROF, - "PWR": syscall.SIGPWR, - "QUIT": syscall.SIGQUIT, - "SEGV": syscall.SIGSEGV, - "STKFLT": syscall.SIGSTKFLT, - "STOP": syscall.SIGSTOP, - "SYS": syscall.SIGSYS, - "TERM": syscall.SIGTERM, - "TRAP": syscall.SIGTRAP, - "TSTP": syscall.SIGTSTP, - "TTIN": syscall.SIGTTIN, - "TTOU": syscall.SIGTTOU, - "UNUSED": syscall.SIGUNUSED, - "URG": syscall.SIGURG, - "USR1": syscall.SIGUSR1, - "USR2": syscall.SIGUSR2, - "VTALRM": syscall.SIGVTALRM, - "WINCH": syscall.SIGWINCH, - "XCPU": syscall.SIGXCPU, - "XFSZ": syscall.SIGXFSZ, - "RTMIN": sigrtmin, - "RTMIN+1": sigrtmin + 1, - "RTMIN+2": sigrtmin + 2, - "RTMIN+3": sigrtmin + 3, - "RTMIN+4": sigrtmin + 4, - "RTMIN+5": sigrtmin + 5, - "RTMIN+6": sigrtmin + 6, - "RTMIN+7": sigrtmin + 7, - "RTMIN+8": sigrtmin + 8, - "RTMIN+9": sigrtmin + 9, - "RTMIN+10": sigrtmin + 10, - "RTMIN+11": sigrtmin + 11, - "RTMIN+12": sigrtmin + 12, - "RTMIN+13": sigrtmin + 13, - "RTMIN+14": sigrtmin + 14, - "RTMIN+15": sigrtmin + 15, - "RTMAX-14": sigrtmax - 14, - "RTMAX-13": sigrtmax - 13, - "RTMAX-12": sigrtmax - 12, - "RTMAX-11": sigrtmax - 11, - "RTMAX-10": sigrtmax - 10, - "RTMAX-9": sigrtmax - 9, - "RTMAX-8": sigrtmax - 8, - "RTMAX-7": sigrtmax - 7, - "RTMAX-6": sigrtmax - 6, - "RTMAX-5": sigrtmax - 5, - "RTMAX-4": sigrtmax - 4, - "RTMAX-3": sigrtmax - 3, - "RTMAX-2": sigrtmax - 2, - "RTMAX-1": sigrtmax - 1, - "RTMAX": sigrtmax, -} diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_solaris.go b/vendor/github.com/docker/docker/pkg/signal/signal_solaris.go deleted file mode 100644 index 89576b9..0000000 --- a/vendor/github.com/docker/docker/pkg/signal/signal_solaris.go +++ /dev/null @@ -1,42 +0,0 @@ -package signal - -import ( - "syscall" -) - -// SignalMap is a map of Solaris signals. -// SIGINFO and SIGTHR not defined for Solaris -var SignalMap = map[string]syscall.Signal{ - "ABRT": syscall.SIGABRT, - "ALRM": syscall.SIGALRM, - "BUF": syscall.SIGBUS, - "CHLD": syscall.SIGCHLD, - "CONT": syscall.SIGCONT, - "EMT": syscall.SIGEMT, - "FPE": syscall.SIGFPE, - "HUP": syscall.SIGHUP, - "ILL": syscall.SIGILL, - "INT": syscall.SIGINT, - "IO": syscall.SIGIO, - "IOT": syscall.SIGIOT, - "KILL": syscall.SIGKILL, - "LWP": syscall.SIGLWP, - "PIPE": syscall.SIGPIPE, - "PROF": syscall.SIGPROF, - "QUIT": syscall.SIGQUIT, - "SEGV": syscall.SIGSEGV, - "STOP": syscall.SIGSTOP, - "SYS": syscall.SIGSYS, - "TERM": syscall.SIGTERM, - "TRAP": syscall.SIGTRAP, - "TSTP": syscall.SIGTSTP, - "TTIN": syscall.SIGTTIN, - "TTOU": syscall.SIGTTOU, - "URG": syscall.SIGURG, - "USR1": syscall.SIGUSR1, - "USR2": syscall.SIGUSR2, - "VTALRM": syscall.SIGVTALRM, - "WINCH": syscall.SIGWINCH, - "XCPU": syscall.SIGXCPU, - "XFSZ": syscall.SIGXFSZ, -} diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_unix.go b/vendor/github.com/docker/docker/pkg/signal/signal_unix.go deleted file mode 100644 index 5d058fd..0000000 --- a/vendor/github.com/docker/docker/pkg/signal/signal_unix.go +++ /dev/null @@ -1,21 +0,0 @@ -// +build !windows - -package signal - -import ( - "syscall" -) - -// Signals used in cli/command (no windows equivalent, use -// invalid signals so they don't get handled) - -const ( - // SIGCHLD is a signal sent to a process when a child process terminates, is interrupted, or resumes after being interrupted. - SIGCHLD = syscall.SIGCHLD - // SIGWINCH is a signal sent to a process when its controlling terminal changes its size - SIGWINCH = syscall.SIGWINCH - // SIGPIPE is a signal sent to a process when a pipe is written to before the other end is open for reading - SIGPIPE = syscall.SIGPIPE - // DefaultStopSignal is the syscall signal used to stop a container in unix systems. - DefaultStopSignal = "SIGTERM" -) diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_unsupported.go b/vendor/github.com/docker/docker/pkg/signal/signal_unsupported.go deleted file mode 100644 index c592d37..0000000 --- a/vendor/github.com/docker/docker/pkg/signal/signal_unsupported.go +++ /dev/null @@ -1,10 +0,0 @@ -// +build !linux,!darwin,!freebsd,!windows,!solaris - -package signal - -import ( - "syscall" -) - -// SignalMap is an empty map of signals for unsupported platform. -var SignalMap = map[string]syscall.Signal{} diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_windows.go b/vendor/github.com/docker/docker/pkg/signal/signal_windows.go deleted file mode 100644 index 440f270..0000000 --- a/vendor/github.com/docker/docker/pkg/signal/signal_windows.go +++ /dev/null @@ -1,28 +0,0 @@ -// +build windows - -package signal - -import ( - "syscall" -) - -// Signals used in cli/command (no windows equivalent, use -// invalid signals so they don't get handled) -const ( - SIGCHLD = syscall.Signal(0xff) - SIGWINCH = syscall.Signal(0xff) - SIGPIPE = syscall.Signal(0xff) - // DefaultStopSignal is the syscall signal used to stop a container in windows systems. - DefaultStopSignal = "15" -) - -// SignalMap is a map of "supported" signals. As per the comment in GOLang's -// ztypes_windows.go: "More invented values for signals". Windows doesn't -// really support signals in any way, shape or form that Unix does. -// -// We have these so that docker kill can be used to gracefully (TERM) and -// forcibly (KILL) terminate a container on Windows. -var SignalMap = map[string]syscall.Signal{ - "KILL": syscall.SIGKILL, - "TERM": syscall.SIGTERM, -} diff --git a/vendor/github.com/docker/docker/pkg/signal/trap.go b/vendor/github.com/docker/docker/pkg/signal/trap.go deleted file mode 100644 index 638a1ab..0000000 --- a/vendor/github.com/docker/docker/pkg/signal/trap.go +++ /dev/null @@ -1,103 +0,0 @@ -package signal - -import ( - "fmt" - "os" - gosignal "os/signal" - "path/filepath" - "runtime" - "strings" - "sync/atomic" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - "github.com/pkg/errors" -) - -// Trap sets up a simplified signal "trap", appropriate for common -// behavior expected from a vanilla unix command-line tool in general -// (and the Docker engine in particular). -// -// * If SIGINT or SIGTERM are received, `cleanup` is called, then the process is terminated. -// * If SIGINT or SIGTERM are received 3 times before cleanup is complete, then cleanup is -// skipped and the process is terminated immediately (allows force quit of stuck daemon) -// * A SIGQUIT always causes an exit without cleanup, with a goroutine dump preceding exit. -// * Ignore SIGPIPE events. These are generated by systemd when journald is restarted while -// the docker daemon is not restarted and also running under systemd. -// Fixes https://github.com/docker/docker/issues/19728 -// -func Trap(cleanup func()) { - c := make(chan os.Signal, 1) - // we will handle INT, TERM, QUIT, SIGPIPE here - signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGPIPE} - gosignal.Notify(c, signals...) - go func() { - interruptCount := uint32(0) - for sig := range c { - if sig == syscall.SIGPIPE { - continue - } - - go func(sig os.Signal) { - logrus.Infof("Processing signal '%v'", sig) - switch sig { - case os.Interrupt, syscall.SIGTERM: - if atomic.LoadUint32(&interruptCount) < 3 { - // Initiate the cleanup only once - if atomic.AddUint32(&interruptCount, 1) == 1 { - // Call the provided cleanup handler - cleanup() - os.Exit(0) - } else { - return - } - } else { - // 3 SIGTERM/INT signals received; force exit without cleanup - logrus.Info("Forcing docker daemon shutdown without cleanup; 3 interrupts received") - } - case syscall.SIGQUIT: - DumpStacks("") - logrus.Info("Forcing docker daemon shutdown without cleanup on SIGQUIT") - } - //for the SIGINT/TERM, and SIGQUIT non-clean shutdown case, exit with 128 + signal # - os.Exit(128 + int(sig.(syscall.Signal))) - }(sig) - } - }() -} - -const stacksLogNameTemplate = "goroutine-stacks-%s.log" - -// DumpStacks appends the runtime stack into file in dir and returns full path -// to that file. -func DumpStacks(dir string) (string, error) { - var ( - buf []byte - stackSize int - ) - bufferLen := 16384 - for stackSize == len(buf) { - buf = make([]byte, bufferLen) - stackSize = runtime.Stack(buf, true) - bufferLen *= 2 - } - buf = buf[:stackSize] - var f *os.File - if dir != "" { - path := filepath.Join(dir, fmt.Sprintf(stacksLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1))) - var err error - f, err = os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666) - if err != nil { - return "", errors.Wrap(err, "failed to open file to write the goroutine stacks") - } - defer f.Close() - defer f.Sync() - } else { - f = os.Stderr - } - if _, err := f.Write(buf); err != nil { - return "", errors.Wrap(err, "failed to write goroutine stacks") - } - return f.Name(), nil -} diff --git a/vendor/github.com/docker/docker/pkg/stdcopy/stdcopy.go b/vendor/github.com/docker/docker/pkg/stdcopy/stdcopy.go deleted file mode 100644 index be20765..0000000 --- a/vendor/github.com/docker/docker/pkg/stdcopy/stdcopy.go +++ /dev/null @@ -1,174 +0,0 @@ -package stdcopy - -import ( - "bytes" - "encoding/binary" - "errors" - "fmt" - "io" - "sync" -) - -// StdType is the type of standard stream -// a writer can multiplex to. -type StdType byte - -const ( - // Stdin represents standard input stream type. - Stdin StdType = iota - // Stdout represents standard output stream type. - Stdout - // Stderr represents standard error steam type. - Stderr - - stdWriterPrefixLen = 8 - stdWriterFdIndex = 0 - stdWriterSizeIndex = 4 - - startingBufLen = 32*1024 + stdWriterPrefixLen + 1 -) - -var bufPool = &sync.Pool{New: func() interface{} { return bytes.NewBuffer(nil) }} - -// stdWriter is wrapper of io.Writer with extra customized info. -type stdWriter struct { - io.Writer - prefix byte -} - -// Write sends the buffer to the underneath writer. -// It inserts the prefix header before the buffer, -// so stdcopy.StdCopy knows where to multiplex the output. -// It makes stdWriter to implement io.Writer. -func (w *stdWriter) Write(p []byte) (n int, err error) { - if w == nil || w.Writer == nil { - return 0, errors.New("Writer not instantiated") - } - if p == nil { - return 0, nil - } - - header := [stdWriterPrefixLen]byte{stdWriterFdIndex: w.prefix} - binary.BigEndian.PutUint32(header[stdWriterSizeIndex:], uint32(len(p))) - buf := bufPool.Get().(*bytes.Buffer) - buf.Write(header[:]) - buf.Write(p) - - n, err = w.Writer.Write(buf.Bytes()) - n -= stdWriterPrefixLen - if n < 0 { - n = 0 - } - - buf.Reset() - bufPool.Put(buf) - return -} - -// NewStdWriter instantiates a new Writer. -// Everything written to it will be encapsulated using a custom format, -// and written to the underlying `w` stream. -// This allows multiple write streams (e.g. stdout and stderr) to be muxed into a single connection. -// `t` indicates the id of the stream to encapsulate. -// It can be stdcopy.Stdin, stdcopy.Stdout, stdcopy.Stderr. -func NewStdWriter(w io.Writer, t StdType) io.Writer { - return &stdWriter{ - Writer: w, - prefix: byte(t), - } -} - -// StdCopy is a modified version of io.Copy. -// -// StdCopy will demultiplex `src`, assuming that it contains two streams, -// previously multiplexed together using a StdWriter instance. -// As it reads from `src`, StdCopy will write to `dstout` and `dsterr`. -// -// StdCopy will read until it hits EOF on `src`. It will then return a nil error. -// In other words: if `err` is non nil, it indicates a real underlying error. -// -// `written` will hold the total number of bytes written to `dstout` and `dsterr`. -func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) { - var ( - buf = make([]byte, startingBufLen) - bufLen = len(buf) - nr, nw int - er, ew error - out io.Writer - frameSize int - ) - - for { - // Make sure we have at least a full header - for nr < stdWriterPrefixLen { - var nr2 int - nr2, er = src.Read(buf[nr:]) - nr += nr2 - if er == io.EOF { - if nr < stdWriterPrefixLen { - return written, nil - } - break - } - if er != nil { - return 0, er - } - } - - // Check the first byte to know where to write - switch StdType(buf[stdWriterFdIndex]) { - case Stdin: - fallthrough - case Stdout: - // Write on stdout - out = dstout - case Stderr: - // Write on stderr - out = dsterr - default: - return 0, fmt.Errorf("Unrecognized input header: %d", buf[stdWriterFdIndex]) - } - - // Retrieve the size of the frame - frameSize = int(binary.BigEndian.Uint32(buf[stdWriterSizeIndex : stdWriterSizeIndex+4])) - - // Check if the buffer is big enough to read the frame. - // Extend it if necessary. - if frameSize+stdWriterPrefixLen > bufLen { - buf = append(buf, make([]byte, frameSize+stdWriterPrefixLen-bufLen+1)...) - bufLen = len(buf) - } - - // While the amount of bytes read is less than the size of the frame + header, we keep reading - for nr < frameSize+stdWriterPrefixLen { - var nr2 int - nr2, er = src.Read(buf[nr:]) - nr += nr2 - if er == io.EOF { - if nr < frameSize+stdWriterPrefixLen { - return written, nil - } - break - } - if er != nil { - return 0, er - } - } - - // Write the retrieved frame (without header) - nw, ew = out.Write(buf[stdWriterPrefixLen : frameSize+stdWriterPrefixLen]) - if ew != nil { - return 0, ew - } - // If the frame has not been fully written: error - if nw != frameSize { - return 0, io.ErrShortWrite - } - written += int64(nw) - - // Move the rest of the buffer to the beginning - copy(buf, buf[frameSize+stdWriterPrefixLen:]) - // Move the index - nr -= frameSize + stdWriterPrefixLen - } -} diff --git a/vendor/github.com/docker/docker/pkg/stdcopy/stdcopy_test.go b/vendor/github.com/docker/docker/pkg/stdcopy/stdcopy_test.go deleted file mode 100644 index 3137a75..0000000 --- a/vendor/github.com/docker/docker/pkg/stdcopy/stdcopy_test.go +++ /dev/null @@ -1,260 +0,0 @@ -package stdcopy - -import ( - "bytes" - "errors" - "io" - "io/ioutil" - "strings" - "testing" -) - -func TestNewStdWriter(t *testing.T) { - writer := NewStdWriter(ioutil.Discard, Stdout) - if writer == nil { - t.Fatalf("NewStdWriter with an invalid StdType should not return nil.") - } -} - -func TestWriteWithUnitializedStdWriter(t *testing.T) { - writer := stdWriter{ - Writer: nil, - prefix: byte(Stdout), - } - n, err := writer.Write([]byte("Something here")) - if n != 0 || err == nil { - t.Fatalf("Should fail when given an uncomplete or uninitialized StdWriter") - } -} - -func TestWriteWithNilBytes(t *testing.T) { - writer := NewStdWriter(ioutil.Discard, Stdout) - n, err := writer.Write(nil) - if err != nil { - t.Fatalf("Shouldn't have fail when given no data") - } - if n > 0 { - t.Fatalf("Write should have written 0 byte, but has written %d", n) - } -} - -func TestWrite(t *testing.T) { - writer := NewStdWriter(ioutil.Discard, Stdout) - data := []byte("Test StdWrite.Write") - n, err := writer.Write(data) - if err != nil { - t.Fatalf("Error while writing with StdWrite") - } - if n != len(data) { - t.Fatalf("Write should have written %d byte but wrote %d.", len(data), n) - } -} - -type errWriter struct { - n int - err error -} - -func (f *errWriter) Write(buf []byte) (int, error) { - return f.n, f.err -} - -func TestWriteWithWriterError(t *testing.T) { - expectedError := errors.New("expected") - expectedReturnedBytes := 10 - writer := NewStdWriter(&errWriter{ - n: stdWriterPrefixLen + expectedReturnedBytes, - err: expectedError}, Stdout) - data := []byte("This won't get written, sigh") - n, err := writer.Write(data) - if err != expectedError { - t.Fatalf("Didn't get expected error.") - } - if n != expectedReturnedBytes { - t.Fatalf("Didn't get expected written bytes %d, got %d.", - expectedReturnedBytes, n) - } -} - -func TestWriteDoesNotReturnNegativeWrittenBytes(t *testing.T) { - writer := NewStdWriter(&errWriter{n: -1}, Stdout) - data := []byte("This won't get written, sigh") - actual, _ := writer.Write(data) - if actual != 0 { - t.Fatalf("Expected returned written bytes equal to 0, got %d", actual) - } -} - -func getSrcBuffer(stdOutBytes, stdErrBytes []byte) (buffer *bytes.Buffer, err error) { - buffer = new(bytes.Buffer) - dstOut := NewStdWriter(buffer, Stdout) - _, err = dstOut.Write(stdOutBytes) - if err != nil { - return - } - dstErr := NewStdWriter(buffer, Stderr) - _, err = dstErr.Write(stdErrBytes) - return -} - -func TestStdCopyWriteAndRead(t *testing.T) { - stdOutBytes := []byte(strings.Repeat("o", startingBufLen)) - stdErrBytes := []byte(strings.Repeat("e", startingBufLen)) - buffer, err := getSrcBuffer(stdOutBytes, stdErrBytes) - if err != nil { - t.Fatal(err) - } - written, err := StdCopy(ioutil.Discard, ioutil.Discard, buffer) - if err != nil { - t.Fatal(err) - } - expectedTotalWritten := len(stdOutBytes) + len(stdErrBytes) - if written != int64(expectedTotalWritten) { - t.Fatalf("Expected to have total of %d bytes written, got %d", expectedTotalWritten, written) - } -} - -type customReader struct { - n int - err error - totalCalls int - correctCalls int - src *bytes.Buffer -} - -func (f *customReader) Read(buf []byte) (int, error) { - f.totalCalls++ - if f.totalCalls <= f.correctCalls { - return f.src.Read(buf) - } - return f.n, f.err -} - -func TestStdCopyReturnsErrorReadingHeader(t *testing.T) { - expectedError := errors.New("error") - reader := &customReader{ - err: expectedError} - written, err := StdCopy(ioutil.Discard, ioutil.Discard, reader) - if written != 0 { - t.Fatalf("Expected 0 bytes read, got %d", written) - } - if err != expectedError { - t.Fatalf("Didn't get expected error") - } -} - -func TestStdCopyReturnsErrorReadingFrame(t *testing.T) { - expectedError := errors.New("error") - stdOutBytes := []byte(strings.Repeat("o", startingBufLen)) - stdErrBytes := []byte(strings.Repeat("e", startingBufLen)) - buffer, err := getSrcBuffer(stdOutBytes, stdErrBytes) - if err != nil { - t.Fatal(err) - } - reader := &customReader{ - correctCalls: 1, - n: stdWriterPrefixLen + 1, - err: expectedError, - src: buffer} - written, err := StdCopy(ioutil.Discard, ioutil.Discard, reader) - if written != 0 { - t.Fatalf("Expected 0 bytes read, got %d", written) - } - if err != expectedError { - t.Fatalf("Didn't get expected error") - } -} - -func TestStdCopyDetectsCorruptedFrame(t *testing.T) { - stdOutBytes := []byte(strings.Repeat("o", startingBufLen)) - stdErrBytes := []byte(strings.Repeat("e", startingBufLen)) - buffer, err := getSrcBuffer(stdOutBytes, stdErrBytes) - if err != nil { - t.Fatal(err) - } - reader := &customReader{ - correctCalls: 1, - n: stdWriterPrefixLen + 1, - err: io.EOF, - src: buffer} - written, err := StdCopy(ioutil.Discard, ioutil.Discard, reader) - if written != startingBufLen { - t.Fatalf("Expected %d bytes read, got %d", startingBufLen, written) - } - if err != nil { - t.Fatal("Didn't get nil error") - } -} - -func TestStdCopyWithInvalidInputHeader(t *testing.T) { - dstOut := NewStdWriter(ioutil.Discard, Stdout) - dstErr := NewStdWriter(ioutil.Discard, Stderr) - src := strings.NewReader("Invalid input") - _, err := StdCopy(dstOut, dstErr, src) - if err == nil { - t.Fatal("StdCopy with invalid input header should fail.") - } -} - -func TestStdCopyWithCorruptedPrefix(t *testing.T) { - data := []byte{0x01, 0x02, 0x03} - src := bytes.NewReader(data) - written, err := StdCopy(nil, nil, src) - if err != nil { - t.Fatalf("StdCopy should not return an error with corrupted prefix.") - } - if written != 0 { - t.Fatalf("StdCopy should have written 0, but has written %d", written) - } -} - -func TestStdCopyReturnsWriteErrors(t *testing.T) { - stdOutBytes := []byte(strings.Repeat("o", startingBufLen)) - stdErrBytes := []byte(strings.Repeat("e", startingBufLen)) - buffer, err := getSrcBuffer(stdOutBytes, stdErrBytes) - if err != nil { - t.Fatal(err) - } - expectedError := errors.New("expected") - - dstOut := &errWriter{err: expectedError} - - written, err := StdCopy(dstOut, ioutil.Discard, buffer) - if written != 0 { - t.Fatalf("StdCopy should have written 0, but has written %d", written) - } - if err != expectedError { - t.Fatalf("Didn't get expected error, got %v", err) - } -} - -func TestStdCopyDetectsNotFullyWrittenFrames(t *testing.T) { - stdOutBytes := []byte(strings.Repeat("o", startingBufLen)) - stdErrBytes := []byte(strings.Repeat("e", startingBufLen)) - buffer, err := getSrcBuffer(stdOutBytes, stdErrBytes) - if err != nil { - t.Fatal(err) - } - dstOut := &errWriter{n: startingBufLen - 10} - - written, err := StdCopy(dstOut, ioutil.Discard, buffer) - if written != 0 { - t.Fatalf("StdCopy should have return 0 written bytes, but returned %d", written) - } - if err != io.ErrShortWrite { - t.Fatalf("Didn't get expected io.ErrShortWrite error") - } -} - -func BenchmarkWrite(b *testing.B) { - w := NewStdWriter(ioutil.Discard, Stdout) - data := []byte("Test line for testing stdwriter performance\n") - data = bytes.Repeat(data, 100) - b.SetBytes(int64(len(data))) - b.ResetTimer() - for i := 0; i < b.N; i++ { - if _, err := w.Write(data); err != nil { - b.Fatal(err) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/streamformatter/streamformatter.go b/vendor/github.com/docker/docker/pkg/streamformatter/streamformatter.go deleted file mode 100644 index ce6ea79..0000000 --- a/vendor/github.com/docker/docker/pkg/streamformatter/streamformatter.go +++ /dev/null @@ -1,172 +0,0 @@ -// Package streamformatter provides helper functions to format a stream. -package streamformatter - -import ( - "encoding/json" - "fmt" - "io" - - "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/pkg/progress" -) - -// StreamFormatter formats a stream, optionally using JSON. -type StreamFormatter struct { - json bool -} - -// NewStreamFormatter returns a simple StreamFormatter -func NewStreamFormatter() *StreamFormatter { - return &StreamFormatter{} -} - -// NewJSONStreamFormatter returns a StreamFormatter configured to stream json -func NewJSONStreamFormatter() *StreamFormatter { - return &StreamFormatter{true} -} - -const streamNewline = "\r\n" - -var streamNewlineBytes = []byte(streamNewline) - -// FormatStream formats the specified stream. -func (sf *StreamFormatter) FormatStream(str string) []byte { - if sf.json { - b, err := json.Marshal(&jsonmessage.JSONMessage{Stream: str}) - if err != nil { - return sf.FormatError(err) - } - return append(b, streamNewlineBytes...) - } - return []byte(str + "\r") -} - -// FormatStatus formats the specified objects according to the specified format (and id). -func (sf *StreamFormatter) FormatStatus(id, format string, a ...interface{}) []byte { - str := fmt.Sprintf(format, a...) - if sf.json { - b, err := json.Marshal(&jsonmessage.JSONMessage{ID: id, Status: str}) - if err != nil { - return sf.FormatError(err) - } - return append(b, streamNewlineBytes...) - } - return []byte(str + streamNewline) -} - -// FormatError formats the specified error. -func (sf *StreamFormatter) FormatError(err error) []byte { - if sf.json { - jsonError, ok := err.(*jsonmessage.JSONError) - if !ok { - jsonError = &jsonmessage.JSONError{Message: err.Error()} - } - if b, err := json.Marshal(&jsonmessage.JSONMessage{Error: jsonError, ErrorMessage: err.Error()}); err == nil { - return append(b, streamNewlineBytes...) - } - return []byte("{\"error\":\"format error\"}" + streamNewline) - } - return []byte("Error: " + err.Error() + streamNewline) -} - -// FormatProgress formats the progress information for a specified action. -func (sf *StreamFormatter) FormatProgress(id, action string, progress *jsonmessage.JSONProgress, aux interface{}) []byte { - if progress == nil { - progress = &jsonmessage.JSONProgress{} - } - if sf.json { - var auxJSON *json.RawMessage - if aux != nil { - auxJSONBytes, err := json.Marshal(aux) - if err != nil { - return nil - } - auxJSON = new(json.RawMessage) - *auxJSON = auxJSONBytes - } - b, err := json.Marshal(&jsonmessage.JSONMessage{ - Status: action, - ProgressMessage: progress.String(), - Progress: progress, - ID: id, - Aux: auxJSON, - }) - if err != nil { - return nil - } - return append(b, streamNewlineBytes...) - } - endl := "\r" - if progress.String() == "" { - endl += "\n" - } - return []byte(action + " " + progress.String() + endl) -} - -// NewProgressOutput returns a progress.Output object that can be passed to -// progress.NewProgressReader. -func (sf *StreamFormatter) NewProgressOutput(out io.Writer, newLines bool) progress.Output { - return &progressOutput{ - sf: sf, - out: out, - newLines: newLines, - } -} - -type progressOutput struct { - sf *StreamFormatter - out io.Writer - newLines bool -} - -// WriteProgress formats progress information from a ProgressReader. -func (out *progressOutput) WriteProgress(prog progress.Progress) error { - var formatted []byte - if prog.Message != "" { - formatted = out.sf.FormatStatus(prog.ID, prog.Message) - } else { - jsonProgress := jsonmessage.JSONProgress{Current: prog.Current, Total: prog.Total} - formatted = out.sf.FormatProgress(prog.ID, prog.Action, &jsonProgress, prog.Aux) - } - _, err := out.out.Write(formatted) - if err != nil { - return err - } - - if out.newLines && prog.LastUpdate { - _, err = out.out.Write(out.sf.FormatStatus("", "")) - return err - } - - return nil -} - -// StdoutFormatter is a streamFormatter that writes to the standard output. -type StdoutFormatter struct { - io.Writer - *StreamFormatter -} - -func (sf *StdoutFormatter) Write(buf []byte) (int, error) { - formattedBuf := sf.StreamFormatter.FormatStream(string(buf)) - n, err := sf.Writer.Write(formattedBuf) - if n != len(formattedBuf) { - return n, io.ErrShortWrite - } - return len(buf), err -} - -// StderrFormatter is a streamFormatter that writes to the standard error. -type StderrFormatter struct { - io.Writer - *StreamFormatter -} - -func (sf *StderrFormatter) Write(buf []byte) (int, error) { - formattedBuf := sf.StreamFormatter.FormatStream("\033[91m" + string(buf) + "\033[0m") - n, err := sf.Writer.Write(formattedBuf) - if n != len(formattedBuf) { - return n, io.ErrShortWrite - } - return len(buf), err -} diff --git a/vendor/github.com/docker/docker/pkg/streamformatter/streamformatter_test.go b/vendor/github.com/docker/docker/pkg/streamformatter/streamformatter_test.go deleted file mode 100644 index 93ec90f..0000000 --- a/vendor/github.com/docker/docker/pkg/streamformatter/streamformatter_test.go +++ /dev/null @@ -1,108 +0,0 @@ -package streamformatter - -import ( - "encoding/json" - "errors" - "reflect" - "strings" - "testing" - - "github.com/docker/docker/pkg/jsonmessage" -) - -func TestFormatStream(t *testing.T) { - sf := NewStreamFormatter() - res := sf.FormatStream("stream") - if string(res) != "stream"+"\r" { - t.Fatalf("%q", res) - } -} - -func TestFormatJSONStatus(t *testing.T) { - sf := NewStreamFormatter() - res := sf.FormatStatus("ID", "%s%d", "a", 1) - if string(res) != "a1\r\n" { - t.Fatalf("%q", res) - } -} - -func TestFormatSimpleError(t *testing.T) { - sf := NewStreamFormatter() - res := sf.FormatError(errors.New("Error for formatter")) - if string(res) != "Error: Error for formatter\r\n" { - t.Fatalf("%q", res) - } -} - -func TestJSONFormatStream(t *testing.T) { - sf := NewJSONStreamFormatter() - res := sf.FormatStream("stream") - if string(res) != `{"stream":"stream"}`+"\r\n" { - t.Fatalf("%q", res) - } -} - -func TestJSONFormatStatus(t *testing.T) { - sf := NewJSONStreamFormatter() - res := sf.FormatStatus("ID", "%s%d", "a", 1) - if string(res) != `{"status":"a1","id":"ID"}`+"\r\n" { - t.Fatalf("%q", res) - } -} - -func TestJSONFormatSimpleError(t *testing.T) { - sf := NewJSONStreamFormatter() - res := sf.FormatError(errors.New("Error for formatter")) - if string(res) != `{"errorDetail":{"message":"Error for formatter"},"error":"Error for formatter"}`+"\r\n" { - t.Fatalf("%q", res) - } -} - -func TestJSONFormatJSONError(t *testing.T) { - sf := NewJSONStreamFormatter() - err := &jsonmessage.JSONError{Code: 50, Message: "Json error"} - res := sf.FormatError(err) - if string(res) != `{"errorDetail":{"code":50,"message":"Json error"},"error":"Json error"}`+"\r\n" { - t.Fatalf("%q", res) - } -} - -func TestJSONFormatProgress(t *testing.T) { - sf := NewJSONStreamFormatter() - progress := &jsonmessage.JSONProgress{ - Current: 15, - Total: 30, - Start: 1, - } - res := sf.FormatProgress("id", "action", progress, nil) - msg := &jsonmessage.JSONMessage{} - if err := json.Unmarshal(res, msg); err != nil { - t.Fatal(err) - } - if msg.ID != "id" { - t.Fatalf("ID must be 'id', got: %s", msg.ID) - } - if msg.Status != "action" { - t.Fatalf("Status must be 'action', got: %s", msg.Status) - } - - // The progress will always be in the format of: - // [=========================> ] 15 B/30 B 404933h7m11s - // The last entry '404933h7m11s' is the timeLeftBox. - // However, the timeLeftBox field may change as progress.String() depends on time.Now(). - // Therefore, we have to strip the timeLeftBox from the strings to do the comparison. - - // Compare the progress strings before the timeLeftBox - expectedProgress := "[=========================> ] 15 B/30 B" - // if terminal column is <= 110, expectedProgressShort is expected. - expectedProgressShort := " 15 B/30 B" - if !(strings.HasPrefix(msg.ProgressMessage, expectedProgress) || - strings.HasPrefix(msg.ProgressMessage, expectedProgressShort)) { - t.Fatalf("ProgressMessage without the timeLeftBox must be %s or %s, got: %s", - expectedProgress, expectedProgressShort, msg.ProgressMessage) - } - - if !reflect.DeepEqual(msg.Progress, progress) { - t.Fatal("Original progress not equals progress from FormatProgress") - } -} diff --git a/vendor/github.com/docker/docker/pkg/stringid/README.md b/vendor/github.com/docker/docker/pkg/stringid/README.md deleted file mode 100644 index 37a5098..0000000 --- a/vendor/github.com/docker/docker/pkg/stringid/README.md +++ /dev/null @@ -1 +0,0 @@ -This package provides helper functions for dealing with string identifiers diff --git a/vendor/github.com/docker/docker/pkg/stringid/stringid.go b/vendor/github.com/docker/docker/pkg/stringid/stringid.go deleted file mode 100644 index fa35d8b..0000000 --- a/vendor/github.com/docker/docker/pkg/stringid/stringid.go +++ /dev/null @@ -1,69 +0,0 @@ -// Package stringid provides helper functions for dealing with string identifiers -package stringid - -import ( - "crypto/rand" - "encoding/hex" - "io" - "regexp" - "strconv" - "strings" - - "github.com/docker/docker/pkg/random" -) - -const shortLen = 12 - -var validShortID = regexp.MustCompile("^[a-z0-9]{12}$") - -// IsShortID determines if an arbitrary string *looks like* a short ID. -func IsShortID(id string) bool { - return validShortID.MatchString(id) -} - -// TruncateID returns a shorthand version of a string identifier for convenience. -// A collision with other shorthands is very unlikely, but possible. -// In case of a collision a lookup with TruncIndex.Get() will fail, and the caller -// will need to use a longer prefix, or the full-length Id. -func TruncateID(id string) string { - if i := strings.IndexRune(id, ':'); i >= 0 { - id = id[i+1:] - } - if len(id) > shortLen { - id = id[:shortLen] - } - return id -} - -func generateID(crypto bool) string { - b := make([]byte, 32) - r := random.Reader - if crypto { - r = rand.Reader - } - for { - if _, err := io.ReadFull(r, b); err != nil { - panic(err) // This shouldn't happen - } - id := hex.EncodeToString(b) - // if we try to parse the truncated for as an int and we don't have - // an error then the value is all numeric and causes issues when - // used as a hostname. ref #3869 - if _, err := strconv.ParseInt(TruncateID(id), 10, 64); err == nil { - continue - } - return id - } -} - -// GenerateRandomID returns a unique id. -func GenerateRandomID() string { - return generateID(true) -} - -// GenerateNonCryptoID generates unique id without using cryptographically -// secure sources of random. -// It helps you to save entropy. -func GenerateNonCryptoID() string { - return generateID(false) -} diff --git a/vendor/github.com/docker/docker/pkg/stringid/stringid_test.go b/vendor/github.com/docker/docker/pkg/stringid/stringid_test.go deleted file mode 100644 index 8ff6b43..0000000 --- a/vendor/github.com/docker/docker/pkg/stringid/stringid_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package stringid - -import ( - "strings" - "testing" -) - -func TestGenerateRandomID(t *testing.T) { - id := GenerateRandomID() - - if len(id) != 64 { - t.Fatalf("Id returned is incorrect: %s", id) - } -} - -func TestGenerateNonCryptoID(t *testing.T) { - id := GenerateNonCryptoID() - - if len(id) != 64 { - t.Fatalf("Id returned is incorrect: %s", id) - } -} - -func TestShortenId(t *testing.T) { - id := "90435eec5c4e124e741ef731e118be2fc799a68aba0466ec17717f24ce2ae6a2" - truncID := TruncateID(id) - if truncID != "90435eec5c4e" { - t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID) - } -} - -func TestShortenSha256Id(t *testing.T) { - id := "sha256:4e38e38c8ce0b8d9041a9c4fefe786631d1416225e13b0bfe8cfa2321aec4bba" - truncID := TruncateID(id) - if truncID != "4e38e38c8ce0" { - t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID) - } -} - -func TestShortenIdEmpty(t *testing.T) { - id := "" - truncID := TruncateID(id) - if len(truncID) > len(id) { - t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID) - } -} - -func TestShortenIdInvalid(t *testing.T) { - id := "1234" - truncID := TruncateID(id) - if len(truncID) != len(id) { - t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID) - } -} - -func TestIsShortIDNonHex(t *testing.T) { - id := "some non-hex value" - if IsShortID(id) { - t.Fatalf("%s is not a short ID", id) - } -} - -func TestIsShortIDNotCorrectSize(t *testing.T) { - id := strings.Repeat("a", shortLen+1) - if IsShortID(id) { - t.Fatalf("%s is not a short ID", id) - } - id = strings.Repeat("a", shortLen-1) - if IsShortID(id) { - t.Fatalf("%s is not a short ID", id) - } -} diff --git a/vendor/github.com/docker/docker/pkg/stringutils/README.md b/vendor/github.com/docker/docker/pkg/stringutils/README.md deleted file mode 100644 index b3e4545..0000000 --- a/vendor/github.com/docker/docker/pkg/stringutils/README.md +++ /dev/null @@ -1 +0,0 @@ -This package provides helper functions for dealing with strings diff --git a/vendor/github.com/docker/docker/pkg/stringutils/stringutils.go b/vendor/github.com/docker/docker/pkg/stringutils/stringutils.go deleted file mode 100644 index 8e1c812..0000000 --- a/vendor/github.com/docker/docker/pkg/stringutils/stringutils.go +++ /dev/null @@ -1,101 +0,0 @@ -// Package stringutils provides helper functions for dealing with strings. -package stringutils - -import ( - "bytes" - "math/rand" - "strings" - - "github.com/docker/docker/pkg/random" -) - -// GenerateRandomAlphaOnlyString generates an alphabetical random string with length n. -func GenerateRandomAlphaOnlyString(n int) string { - // make a really long string - letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") - b := make([]byte, n) - for i := range b { - b[i] = letters[random.Rand.Intn(len(letters))] - } - return string(b) -} - -// GenerateRandomASCIIString generates an ASCII random string with length n. -func GenerateRandomASCIIString(n int) string { - chars := "abcdefghijklmnopqrstuvwxyz" + - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + - "~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:` " - res := make([]byte, n) - for i := 0; i < n; i++ { - res[i] = chars[rand.Intn(len(chars))] - } - return string(res) -} - -// Ellipsis truncates a string to fit within maxlen, and appends ellipsis (...). -// For maxlen of 3 and lower, no ellipsis is appended. -func Ellipsis(s string, maxlen int) string { - r := []rune(s) - if len(r) <= maxlen { - return s - } - if maxlen <= 3 { - return string(r[:maxlen]) - } - return string(r[:maxlen-3]) + "..." -} - -// Truncate truncates a string to maxlen. -func Truncate(s string, maxlen int) string { - r := []rune(s) - if len(r) <= maxlen { - return s - } - return string(r[:maxlen]) -} - -// InSlice tests whether a string is contained in a slice of strings or not. -// Comparison is case insensitive -func InSlice(slice []string, s string) bool { - for _, ss := range slice { - if strings.ToLower(s) == strings.ToLower(ss) { - return true - } - } - return false -} - -func quote(word string, buf *bytes.Buffer) { - // Bail out early for "simple" strings - if word != "" && !strings.ContainsAny(word, "\\'\"`${[|&;<>()~*?! \t\n") { - buf.WriteString(word) - return - } - - buf.WriteString("'") - - for i := 0; i < len(word); i++ { - b := word[i] - if b == '\'' { - // Replace literal ' with a close ', a \', and a open ' - buf.WriteString("'\\''") - } else { - buf.WriteByte(b) - } - } - - buf.WriteString("'") -} - -// ShellQuoteArguments takes a list of strings and escapes them so they will be -// handled right when passed as arguments to a program via a shell -func ShellQuoteArguments(args []string) string { - var buf bytes.Buffer - for i, arg := range args { - if i != 0 { - buf.WriteByte(' ') - } - quote(arg, &buf) - } - return buf.String() -} diff --git a/vendor/github.com/docker/docker/pkg/stringutils/stringutils_test.go b/vendor/github.com/docker/docker/pkg/stringutils/stringutils_test.go deleted file mode 100644 index 8af2bdc..0000000 --- a/vendor/github.com/docker/docker/pkg/stringutils/stringutils_test.go +++ /dev/null @@ -1,121 +0,0 @@ -package stringutils - -import "testing" - -func testLengthHelper(generator func(int) string, t *testing.T) { - expectedLength := 20 - s := generator(expectedLength) - if len(s) != expectedLength { - t.Fatalf("Length of %s was %d but expected length %d", s, len(s), expectedLength) - } -} - -func testUniquenessHelper(generator func(int) string, t *testing.T) { - repeats := 25 - set := make(map[string]struct{}, repeats) - for i := 0; i < repeats; i = i + 1 { - str := generator(64) - if len(str) != 64 { - t.Fatalf("Id returned is incorrect: %s", str) - } - if _, ok := set[str]; ok { - t.Fatalf("Random number is repeated") - } - set[str] = struct{}{} - } -} - -func isASCII(s string) bool { - for _, c := range s { - if c > 127 { - return false - } - } - return true -} - -func TestGenerateRandomAlphaOnlyStringLength(t *testing.T) { - testLengthHelper(GenerateRandomAlphaOnlyString, t) -} - -func TestGenerateRandomAlphaOnlyStringUniqueness(t *testing.T) { - testUniquenessHelper(GenerateRandomAlphaOnlyString, t) -} - -func TestGenerateRandomAsciiStringLength(t *testing.T) { - testLengthHelper(GenerateRandomASCIIString, t) -} - -func TestGenerateRandomAsciiStringUniqueness(t *testing.T) { - testUniquenessHelper(GenerateRandomASCIIString, t) -} - -func TestGenerateRandomAsciiStringIsAscii(t *testing.T) { - str := GenerateRandomASCIIString(64) - if !isASCII(str) { - t.Fatalf("%s contained non-ascii characters", str) - } -} - -func TestEllipsis(t *testing.T) { - str := "t🐳ststring" - newstr := Ellipsis(str, 3) - if newstr != "t🐳s" { - t.Fatalf("Expected t🐳s, got %s", newstr) - } - newstr = Ellipsis(str, 8) - if newstr != "t🐳sts..." { - t.Fatalf("Expected tests..., got %s", newstr) - } - newstr = Ellipsis(str, 20) - if newstr != "t🐳ststring" { - t.Fatalf("Expected t🐳ststring, got %s", newstr) - } -} - -func TestTruncate(t *testing.T) { - str := "t🐳ststring" - newstr := Truncate(str, 4) - if newstr != "t🐳st" { - t.Fatalf("Expected t🐳st, got %s", newstr) - } - newstr = Truncate(str, 20) - if newstr != "t🐳ststring" { - t.Fatalf("Expected t🐳ststring, got %s", newstr) - } -} - -func TestInSlice(t *testing.T) { - slice := []string{"t🐳st", "in", "slice"} - - test := InSlice(slice, "t🐳st") - if !test { - t.Fatalf("Expected string t🐳st to be in slice") - } - test = InSlice(slice, "SLICE") - if !test { - t.Fatalf("Expected string SLICE to be in slice") - } - test = InSlice(slice, "notinslice") - if test { - t.Fatalf("Expected string notinslice not to be in slice") - } -} - -func TestShellQuoteArgumentsEmpty(t *testing.T) { - actual := ShellQuoteArguments([]string{}) - expected := "" - if actual != expected { - t.Fatalf("Expected an empty string") - } -} - -func TestShellQuoteArguments(t *testing.T) { - simpleString := "simpleString" - complexString := "This is a 'more' complex $tring with some special char *" - actual := ShellQuoteArguments([]string{simpleString, complexString}) - expected := "simpleString 'This is a '\\''more'\\'' complex $tring with some special char *'" - if actual != expected { - t.Fatalf("Expected \"%v\", got \"%v\"", expected, actual) - } -} diff --git a/vendor/github.com/docker/docker/pkg/symlink/LICENSE.APACHE b/vendor/github.com/docker/docker/pkg/symlink/LICENSE.APACHE deleted file mode 100644 index 34c4ea7..0000000 --- a/vendor/github.com/docker/docker/pkg/symlink/LICENSE.APACHE +++ /dev/null @@ -1,191 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - Copyright 2014-2016 Docker, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/docker/docker/pkg/symlink/LICENSE.BSD b/vendor/github.com/docker/docker/pkg/symlink/LICENSE.BSD deleted file mode 100644 index 9b4f4a2..0000000 --- a/vendor/github.com/docker/docker/pkg/symlink/LICENSE.BSD +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2014-2016 The Docker & Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/docker/docker/pkg/symlink/README.md b/vendor/github.com/docker/docker/pkg/symlink/README.md deleted file mode 100644 index 8dba54f..0000000 --- a/vendor/github.com/docker/docker/pkg/symlink/README.md +++ /dev/null @@ -1,6 +0,0 @@ -Package symlink implements EvalSymlinksInScope which is an extension of filepath.EvalSymlinks, -as well as a Windows long-path aware version of filepath.EvalSymlinks -from the [Go standard library](https://golang.org/pkg/path/filepath). - -The code from filepath.EvalSymlinks has been adapted in fs.go. -Please read the LICENSE.BSD file that governs fs.go and LICENSE.APACHE for fs_test.go. diff --git a/vendor/github.com/docker/docker/pkg/symlink/fs.go b/vendor/github.com/docker/docker/pkg/symlink/fs.go deleted file mode 100644 index f6bc223..0000000 --- a/vendor/github.com/docker/docker/pkg/symlink/fs.go +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE.BSD file. - -// This code is a modified version of path/filepath/symlink.go from the Go standard library. - -package symlink - -import ( - "bytes" - "errors" - "os" - "path/filepath" - "strings" - - "github.com/docker/docker/pkg/system" -) - -// FollowSymlinkInScope is a wrapper around evalSymlinksInScope that returns an -// absolute path. This function handles paths in a platform-agnostic manner. -func FollowSymlinkInScope(path, root string) (string, error) { - path, err := filepath.Abs(filepath.FromSlash(path)) - if err != nil { - return "", err - } - root, err = filepath.Abs(filepath.FromSlash(root)) - if err != nil { - return "", err - } - return evalSymlinksInScope(path, root) -} - -// evalSymlinksInScope will evaluate symlinks in `path` within a scope `root` and return -// a result guaranteed to be contained within the scope `root`, at the time of the call. -// Symlinks in `root` are not evaluated and left as-is. -// Errors encountered while attempting to evaluate symlinks in path will be returned. -// Non-existing paths are valid and do not constitute an error. -// `path` has to contain `root` as a prefix, or else an error will be returned. -// Trying to break out from `root` does not constitute an error. -// -// Example: -// If /foo/bar -> /outside, -// FollowSymlinkInScope("/foo/bar", "/foo") == "/foo/outside" instead of "/oustide" -// -// IMPORTANT: it is the caller's responsibility to call evalSymlinksInScope *after* relevant symlinks -// are created and not to create subsequently, additional symlinks that could potentially make a -// previously-safe path, unsafe. Example: if /foo/bar does not exist, evalSymlinksInScope("/foo/bar", "/foo") -// would return "/foo/bar". If one makes /foo/bar a symlink to /baz subsequently, then "/foo/bar" should -// no longer be considered safely contained in "/foo". -func evalSymlinksInScope(path, root string) (string, error) { - root = filepath.Clean(root) - if path == root { - return path, nil - } - if !strings.HasPrefix(path, root) { - return "", errors.New("evalSymlinksInScope: " + path + " is not in " + root) - } - const maxIter = 255 - originalPath := path - // given root of "/a" and path of "/a/b/../../c" we want path to be "/b/../../c" - path = path[len(root):] - if root == string(filepath.Separator) { - path = string(filepath.Separator) + path - } - if !strings.HasPrefix(path, string(filepath.Separator)) { - return "", errors.New("evalSymlinksInScope: " + path + " is not in " + root) - } - path = filepath.Clean(path) - // consume path by taking each frontmost path element, - // expanding it if it's a symlink, and appending it to b - var b bytes.Buffer - // b here will always be considered to be the "current absolute path inside - // root" when we append paths to it, we also append a slash and use - // filepath.Clean after the loop to trim the trailing slash - for n := 0; path != ""; n++ { - if n > maxIter { - return "", errors.New("evalSymlinksInScope: too many links in " + originalPath) - } - - // find next path component, p - i := strings.IndexRune(path, filepath.Separator) - var p string - if i == -1 { - p, path = path, "" - } else { - p, path = path[:i], path[i+1:] - } - - if p == "" { - continue - } - - // this takes a b.String() like "b/../" and a p like "c" and turns it - // into "/b/../c" which then gets filepath.Cleaned into "/c" and then - // root gets prepended and we Clean again (to remove any trailing slash - // if the first Clean gave us just "/") - cleanP := filepath.Clean(string(filepath.Separator) + b.String() + p) - if isDriveOrRoot(cleanP) { - // never Lstat "/" itself, or drive letters on Windows - b.Reset() - continue - } - fullP := filepath.Clean(root + cleanP) - - fi, err := os.Lstat(fullP) - if os.IsNotExist(err) { - // if p does not exist, accept it - b.WriteString(p) - b.WriteRune(filepath.Separator) - continue - } - if err != nil { - return "", err - } - if fi.Mode()&os.ModeSymlink == 0 { - b.WriteString(p) - b.WriteRune(filepath.Separator) - continue - } - - // it's a symlink, put it at the front of path - dest, err := os.Readlink(fullP) - if err != nil { - return "", err - } - if system.IsAbs(dest) { - b.Reset() - } - path = dest + string(filepath.Separator) + path - } - - // see note above on "fullP := ..." for why this is double-cleaned and - // what's happening here - return filepath.Clean(root + filepath.Clean(string(filepath.Separator)+b.String())), nil -} - -// EvalSymlinks returns the path name after the evaluation of any symbolic -// links. -// If path is relative the result will be relative to the current directory, -// unless one of the components is an absolute symbolic link. -// This version has been updated to support long paths prepended with `\\?\`. -func EvalSymlinks(path string) (string, error) { - return evalSymlinks(path) -} diff --git a/vendor/github.com/docker/docker/pkg/symlink/fs_unix.go b/vendor/github.com/docker/docker/pkg/symlink/fs_unix.go deleted file mode 100644 index 2270827..0000000 --- a/vendor/github.com/docker/docker/pkg/symlink/fs_unix.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build !windows - -package symlink - -import ( - "path/filepath" -) - -func evalSymlinks(path string) (string, error) { - return filepath.EvalSymlinks(path) -} - -func isDriveOrRoot(p string) bool { - return p == string(filepath.Separator) -} diff --git a/vendor/github.com/docker/docker/pkg/symlink/fs_unix_test.go b/vendor/github.com/docker/docker/pkg/symlink/fs_unix_test.go deleted file mode 100644 index 7085c0b..0000000 --- a/vendor/github.com/docker/docker/pkg/symlink/fs_unix_test.go +++ /dev/null @@ -1,407 +0,0 @@ -// +build !windows - -// Licensed under the Apache License, Version 2.0; See LICENSE.APACHE - -package symlink - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -// TODO Windows: This needs some serious work to port to Windows. For now, -// turning off testing in this package. - -type dirOrLink struct { - path string - target string -} - -func makeFs(tmpdir string, fs []dirOrLink) error { - for _, s := range fs { - s.path = filepath.Join(tmpdir, s.path) - if s.target == "" { - os.MkdirAll(s.path, 0755) - continue - } - if err := os.MkdirAll(filepath.Dir(s.path), 0755); err != nil { - return err - } - if err := os.Symlink(s.target, s.path); err != nil && !os.IsExist(err) { - return err - } - } - return nil -} - -func testSymlink(tmpdir, path, expected, scope string) error { - rewrite, err := FollowSymlinkInScope(filepath.Join(tmpdir, path), filepath.Join(tmpdir, scope)) - if err != nil { - return err - } - expected, err = filepath.Abs(filepath.Join(tmpdir, expected)) - if err != nil { - return err - } - if expected != rewrite { - return fmt.Errorf("Expected %q got %q", expected, rewrite) - } - return nil -} - -func TestFollowSymlinkAbsolute(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkAbsolute") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/d", target: "/b"}}); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "testdata/fs/a/d/c/data", "testdata/b/c/data", "testdata"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkRelativePath(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkRelativePath") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/i", target: "a"}}); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "testdata/fs/i", "testdata/fs/a", "testdata"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkSkipSymlinksOutsideScope(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkSkipSymlinksOutsideScope") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - if err := makeFs(tmpdir, []dirOrLink{ - {path: "linkdir", target: "realdir"}, - {path: "linkdir/foo/bar"}, - }); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "linkdir/foo/bar", "linkdir/foo/bar", "linkdir/foo"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkInvalidScopePathPair(t *testing.T) { - if _, err := FollowSymlinkInScope("toto", "testdata"); err == nil { - t.Fatal("expected an error") - } -} - -func TestFollowSymlinkLastLink(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkLastLink") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/d", target: "/b"}}); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "testdata/fs/a/d", "testdata/b", "testdata"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkRelativeLinkChangeScope(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkRelativeLinkChangeScope") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/e", target: "../b"}}); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "testdata/fs/a/e/c/data", "testdata/fs/b/c/data", "testdata"); err != nil { - t.Fatal(err) - } - // avoid letting allowing symlink e lead us to ../b - // normalize to the "testdata/fs/a" - if err := testSymlink(tmpdir, "testdata/fs/a/e", "testdata/fs/a/b", "testdata/fs/a"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkDeepRelativeLinkChangeScope(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkDeepRelativeLinkChangeScope") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/a/f", target: "../../../../test"}}); err != nil { - t.Fatal(err) - } - // avoid letting symlink f lead us out of the "testdata" scope - // we don't normalize because symlink f is in scope and there is no - // information leak - if err := testSymlink(tmpdir, "testdata/fs/a/f", "testdata/test", "testdata"); err != nil { - t.Fatal(err) - } - // avoid letting symlink f lead us out of the "testdata/fs" scope - // we don't normalize because symlink f is in scope and there is no - // information leak - if err := testSymlink(tmpdir, "testdata/fs/a/f", "testdata/fs/test", "testdata/fs"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkRelativeLinkChain(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkRelativeLinkChain") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - // avoid letting symlink g (pointed at by symlink h) take out of scope - // TODO: we should probably normalize to scope here because ../[....]/root - // is out of scope and we leak information - if err := makeFs(tmpdir, []dirOrLink{ - {path: "testdata/fs/b/h", target: "../g"}, - {path: "testdata/fs/g", target: "../../../../../../../../../../../../root"}, - }); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "testdata/fs/b/h", "testdata/root", "testdata"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkBreakoutPath(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkBreakoutPath") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - // avoid letting symlink -> ../directory/file escape from scope - // normalize to "testdata/fs/j" - if err := makeFs(tmpdir, []dirOrLink{{path: "testdata/fs/j/k", target: "../i/a"}}); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "testdata/fs/j/k", "testdata/fs/j/i/a", "testdata/fs/j"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkToRoot(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkToRoot") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - // make sure we don't allow escaping to / - // normalize to dir - if err := makeFs(tmpdir, []dirOrLink{{path: "foo", target: "/"}}); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "foo", "", ""); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkSlashDotdot(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkSlashDotdot") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - tmpdir = filepath.Join(tmpdir, "dir", "subdir") - - // make sure we don't allow escaping to / - // normalize to dir - if err := makeFs(tmpdir, []dirOrLink{{path: "foo", target: "/../../"}}); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "foo", "", ""); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkDotdot(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkDotdot") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - tmpdir = filepath.Join(tmpdir, "dir", "subdir") - - // make sure we stay in scope without leaking information - // this also checks for escaping to / - // normalize to dir - if err := makeFs(tmpdir, []dirOrLink{{path: "foo", target: "../../"}}); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "foo", "", ""); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkRelativePath2(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkRelativePath2") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - if err := makeFs(tmpdir, []dirOrLink{{path: "bar/foo", target: "baz/target"}}); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "bar/foo", "bar/baz/target", ""); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkScopeLink(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkScopeLink") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - if err := makeFs(tmpdir, []dirOrLink{ - {path: "root2"}, - {path: "root", target: "root2"}, - {path: "root2/foo", target: "../bar"}, - }); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "root/foo", "root/bar", "root"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkRootScope(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkRootScope") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - expected, err := filepath.EvalSymlinks(tmpdir) - if err != nil { - t.Fatal(err) - } - rewrite, err := FollowSymlinkInScope(tmpdir, "/") - if err != nil { - t.Fatal(err) - } - if rewrite != expected { - t.Fatalf("expected %q got %q", expected, rewrite) - } -} - -func TestFollowSymlinkEmpty(t *testing.T) { - res, err := FollowSymlinkInScope("", "") - if err != nil { - t.Fatal(err) - } - wd, err := os.Getwd() - if err != nil { - t.Fatal(err) - } - if res != wd { - t.Fatalf("expected %q got %q", wd, res) - } -} - -func TestFollowSymlinkCircular(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkCircular") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - if err := makeFs(tmpdir, []dirOrLink{{path: "root/foo", target: "foo"}}); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "root/foo", "", "root"); err == nil { - t.Fatal("expected an error for foo -> foo") - } - - if err := makeFs(tmpdir, []dirOrLink{ - {path: "root/bar", target: "baz"}, - {path: "root/baz", target: "../bak"}, - {path: "root/bak", target: "/bar"}, - }); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "root/foo", "", "root"); err == nil { - t.Fatal("expected an error for bar -> baz -> bak -> bar") - } -} - -func TestFollowSymlinkComplexChainWithTargetPathsContainingLinks(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkComplexChainWithTargetPathsContainingLinks") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - if err := makeFs(tmpdir, []dirOrLink{ - {path: "root2"}, - {path: "root", target: "root2"}, - {path: "root/a", target: "r/s"}, - {path: "root/r", target: "../root/t"}, - {path: "root/root/t/s/b", target: "/../u"}, - {path: "root/u/c", target: "."}, - {path: "root/u/x/y", target: "../v"}, - {path: "root/u/v", target: "/../w"}, - }); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "root/a/b/c/x/y/z", "root/w/z", "root"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkBreakoutNonExistent(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkBreakoutNonExistent") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - if err := makeFs(tmpdir, []dirOrLink{ - {path: "root/slash", target: "/"}, - {path: "root/sym", target: "/idontexist/../slash"}, - }); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "root/sym/file", "root/file", "root"); err != nil { - t.Fatal(err) - } -} - -func TestFollowSymlinkNoLexicalCleaning(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "TestFollowSymlinkNoLexicalCleaning") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpdir) - - if err := makeFs(tmpdir, []dirOrLink{ - {path: "root/sym", target: "/foo/bar"}, - {path: "root/hello", target: "/sym/../baz"}, - }); err != nil { - t.Fatal(err) - } - if err := testSymlink(tmpdir, "root/hello", "root/foo/baz", "root"); err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/pkg/symlink/fs_windows.go b/vendor/github.com/docker/docker/pkg/symlink/fs_windows.go deleted file mode 100644 index 241e531..0000000 --- a/vendor/github.com/docker/docker/pkg/symlink/fs_windows.go +++ /dev/null @@ -1,169 +0,0 @@ -package symlink - -import ( - "bytes" - "errors" - "os" - "path/filepath" - "strings" - "syscall" - - "github.com/docker/docker/pkg/longpath" -) - -func toShort(path string) (string, error) { - p, err := syscall.UTF16FromString(path) - if err != nil { - return "", err - } - b := p // GetShortPathName says we can reuse buffer - n, err := syscall.GetShortPathName(&p[0], &b[0], uint32(len(b))) - if err != nil { - return "", err - } - if n > uint32(len(b)) { - b = make([]uint16, n) - if _, err = syscall.GetShortPathName(&p[0], &b[0], uint32(len(b))); err != nil { - return "", err - } - } - return syscall.UTF16ToString(b), nil -} - -func toLong(path string) (string, error) { - p, err := syscall.UTF16FromString(path) - if err != nil { - return "", err - } - b := p // GetLongPathName says we can reuse buffer - n, err := syscall.GetLongPathName(&p[0], &b[0], uint32(len(b))) - if err != nil { - return "", err - } - if n > uint32(len(b)) { - b = make([]uint16, n) - n, err = syscall.GetLongPathName(&p[0], &b[0], uint32(len(b))) - if err != nil { - return "", err - } - } - b = b[:n] - return syscall.UTF16ToString(b), nil -} - -func evalSymlinks(path string) (string, error) { - path, err := walkSymlinks(path) - if err != nil { - return "", err - } - - p, err := toShort(path) - if err != nil { - return "", err - } - p, err = toLong(p) - if err != nil { - return "", err - } - // syscall.GetLongPathName does not change the case of the drive letter, - // but the result of EvalSymlinks must be unique, so we have - // EvalSymlinks(`c:\a`) == EvalSymlinks(`C:\a`). - // Make drive letter upper case. - if len(p) >= 2 && p[1] == ':' && 'a' <= p[0] && p[0] <= 'z' { - p = string(p[0]+'A'-'a') + p[1:] - } else if len(p) >= 6 && p[5] == ':' && 'a' <= p[4] && p[4] <= 'z' { - p = p[:3] + string(p[4]+'A'-'a') + p[5:] - } - return filepath.Clean(p), nil -} - -const utf8RuneSelf = 0x80 - -func walkSymlinks(path string) (string, error) { - const maxIter = 255 - originalPath := path - // consume path by taking each frontmost path element, - // expanding it if it's a symlink, and appending it to b - var b bytes.Buffer - for n := 0; path != ""; n++ { - if n > maxIter { - return "", errors.New("EvalSymlinks: too many links in " + originalPath) - } - - // A path beginning with `\\?\` represents the root, so automatically - // skip that part and begin processing the next segment. - if strings.HasPrefix(path, longpath.Prefix) { - b.WriteString(longpath.Prefix) - path = path[4:] - continue - } - - // find next path component, p - var i = -1 - for j, c := range path { - if c < utf8RuneSelf && os.IsPathSeparator(uint8(c)) { - i = j - break - } - } - var p string - if i == -1 { - p, path = path, "" - } else { - p, path = path[:i], path[i+1:] - } - - if p == "" { - if b.Len() == 0 { - // must be absolute path - b.WriteRune(filepath.Separator) - } - continue - } - - // If this is the first segment after the long path prefix, accept the - // current segment as a volume root or UNC share and move on to the next. - if b.String() == longpath.Prefix { - b.WriteString(p) - b.WriteRune(filepath.Separator) - continue - } - - fi, err := os.Lstat(b.String() + p) - if err != nil { - return "", err - } - if fi.Mode()&os.ModeSymlink == 0 { - b.WriteString(p) - if path != "" || (b.Len() == 2 && len(p) == 2 && p[1] == ':') { - b.WriteRune(filepath.Separator) - } - continue - } - - // it's a symlink, put it at the front of path - dest, err := os.Readlink(b.String() + p) - if err != nil { - return "", err - } - if filepath.IsAbs(dest) || os.IsPathSeparator(dest[0]) { - b.Reset() - } - path = dest + string(filepath.Separator) + path - } - return filepath.Clean(b.String()), nil -} - -func isDriveOrRoot(p string) bool { - if p == string(filepath.Separator) { - return true - } - - length := len(p) - if length >= 2 { - if p[length-1] == ':' && (('a' <= p[length-2] && p[length-2] <= 'z') || ('A' <= p[length-2] && p[length-2] <= 'Z')) { - return true - } - } - return false -} diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/README.md b/vendor/github.com/docker/docker/pkg/sysinfo/README.md deleted file mode 100644 index c1530ce..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/README.md +++ /dev/null @@ -1 +0,0 @@ -SysInfo stores information about which features a kernel supports. diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/numcpu.go b/vendor/github.com/docker/docker/pkg/sysinfo/numcpu.go deleted file mode 100644 index aeb1a3a..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/numcpu.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !linux,!windows - -package sysinfo - -import ( - "runtime" -) - -// NumCPU returns the number of CPUs -func NumCPU() int { - return runtime.NumCPU() -} diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/numcpu_linux.go b/vendor/github.com/docker/docker/pkg/sysinfo/numcpu_linux.go deleted file mode 100644 index 5eacd35..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/numcpu_linux.go +++ /dev/null @@ -1,43 +0,0 @@ -// +build linux - -package sysinfo - -import ( - "runtime" - "syscall" - "unsafe" -) - -// numCPU queries the system for the count of threads available -// for use to this process. -// -// Issues two syscalls. -// Returns 0 on errors. Use |runtime.NumCPU| in that case. -func numCPU() int { - // Gets the affinity mask for a process: The very one invoking this function. - pid, _, _ := syscall.RawSyscall(syscall.SYS_GETPID, 0, 0, 0) - - var mask [1024 / 64]uintptr - _, _, err := syscall.RawSyscall(syscall.SYS_SCHED_GETAFFINITY, pid, uintptr(len(mask)*8), uintptr(unsafe.Pointer(&mask[0]))) - if err != 0 { - return 0 - } - - // For every available thread a bit is set in the mask. - ncpu := 0 - for _, e := range mask { - if e == 0 { - continue - } - ncpu += int(popcnt(uint64(e))) - } - return ncpu -} - -// NumCPU returns the number of CPUs which are currently online -func NumCPU() int { - if ncpu := numCPU(); ncpu > 0 { - return ncpu - } - return runtime.NumCPU() -} diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/numcpu_windows.go b/vendor/github.com/docker/docker/pkg/sysinfo/numcpu_windows.go deleted file mode 100644 index 1d89dd5..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/numcpu_windows.go +++ /dev/null @@ -1,37 +0,0 @@ -// +build windows - -package sysinfo - -import ( - "runtime" - "unsafe" - - "golang.org/x/sys/windows" -) - -var ( - kernel32 = windows.NewLazySystemDLL("kernel32.dll") - getCurrentProcess = kernel32.NewProc("GetCurrentProcess") - getProcessAffinityMask = kernel32.NewProc("GetProcessAffinityMask") -) - -func numCPU() int { - // Gets the affinity mask for a process - var mask, sysmask uintptr - currentProcess, _, _ := getCurrentProcess.Call() - ret, _, _ := getProcessAffinityMask.Call(currentProcess, uintptr(unsafe.Pointer(&mask)), uintptr(unsafe.Pointer(&sysmask))) - if ret == 0 { - return 0 - } - // For every available thread a bit is set in the mask. - ncpu := int(popcnt(uint64(mask))) - return ncpu -} - -// NumCPU returns the number of CPUs which are currently online -func NumCPU() int { - if ncpu := numCPU(); ncpu > 0 { - return ncpu - } - return runtime.NumCPU() -} diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo.go b/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo.go deleted file mode 100644 index f046de4..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo.go +++ /dev/null @@ -1,144 +0,0 @@ -package sysinfo - -import "github.com/docker/docker/pkg/parsers" - -// SysInfo stores information about which features a kernel supports. -// TODO Windows: Factor out platform specific capabilities. -type SysInfo struct { - // Whether the kernel supports AppArmor or not - AppArmor bool - // Whether the kernel supports Seccomp or not - Seccomp bool - - cgroupMemInfo - cgroupCPUInfo - cgroupBlkioInfo - cgroupCpusetInfo - cgroupPids - - // Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work - IPv4ForwardingDisabled bool - - // Whether bridge-nf-call-iptables is supported or not - BridgeNFCallIPTablesDisabled bool - - // Whether bridge-nf-call-ip6tables is supported or not - BridgeNFCallIP6TablesDisabled bool - - // Whether the cgroup has the mountpoint of "devices" or not - CgroupDevicesEnabled bool -} - -type cgroupMemInfo struct { - // Whether memory limit is supported or not - MemoryLimit bool - - // Whether swap limit is supported or not - SwapLimit bool - - // Whether soft limit is supported or not - MemoryReservation bool - - // Whether OOM killer disable is supported or not - OomKillDisable bool - - // Whether memory swappiness is supported or not - MemorySwappiness bool - - // Whether kernel memory limit is supported or not - KernelMemory bool -} - -type cgroupCPUInfo struct { - // Whether CPU shares is supported or not - CPUShares bool - - // Whether CPU CFS(Completely Fair Scheduler) period is supported or not - CPUCfsPeriod bool - - // Whether CPU CFS(Completely Fair Scheduler) quota is supported or not - CPUCfsQuota bool - - // Whether CPU real-time period is supported or not - CPURealtimePeriod bool - - // Whether CPU real-time runtime is supported or not - CPURealtimeRuntime bool -} - -type cgroupBlkioInfo struct { - // Whether Block IO weight is supported or not - BlkioWeight bool - - // Whether Block IO weight_device is supported or not - BlkioWeightDevice bool - - // Whether Block IO read limit in bytes per second is supported or not - BlkioReadBpsDevice bool - - // Whether Block IO write limit in bytes per second is supported or not - BlkioWriteBpsDevice bool - - // Whether Block IO read limit in IO per second is supported or not - BlkioReadIOpsDevice bool - - // Whether Block IO write limit in IO per second is supported or not - BlkioWriteIOpsDevice bool -} - -type cgroupCpusetInfo struct { - // Whether Cpuset is supported or not - Cpuset bool - - // Available Cpuset's cpus - Cpus string - - // Available Cpuset's memory nodes - Mems string -} - -type cgroupPids struct { - // Whether Pids Limit is supported or not - PidsLimit bool -} - -// IsCpusetCpusAvailable returns `true` if the provided string set is contained -// in cgroup's cpuset.cpus set, `false` otherwise. -// If error is not nil a parsing error occurred. -func (c cgroupCpusetInfo) IsCpusetCpusAvailable(provided string) (bool, error) { - return isCpusetListAvailable(provided, c.Cpus) -} - -// IsCpusetMemsAvailable returns `true` if the provided string set is contained -// in cgroup's cpuset.mems set, `false` otherwise. -// If error is not nil a parsing error occurred. -func (c cgroupCpusetInfo) IsCpusetMemsAvailable(provided string) (bool, error) { - return isCpusetListAvailable(provided, c.Mems) -} - -func isCpusetListAvailable(provided, available string) (bool, error) { - parsedProvided, err := parsers.ParseUintList(provided) - if err != nil { - return false, err - } - parsedAvailable, err := parsers.ParseUintList(available) - if err != nil { - return false, err - } - for k := range parsedProvided { - if !parsedAvailable[k] { - return false, nil - } - } - return true, nil -} - -// Returns bit count of 1, used by NumCPU -func popcnt(x uint64) (n byte) { - x -= (x >> 1) & 0x5555555555555555 - x = (x>>2)&0x3333333333333333 + x&0x3333333333333333 - x += x >> 4 - x &= 0x0f0f0f0f0f0f0f0f - x *= 0x0101010101010101 - return byte(x >> 56) -} diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_linux.go b/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_linux.go deleted file mode 100644 index 7ad84a8..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_linux.go +++ /dev/null @@ -1,259 +0,0 @@ -package sysinfo - -import ( - "fmt" - "io/ioutil" - "os" - "path" - "strings" - "syscall" - - "github.com/Sirupsen/logrus" - "github.com/opencontainers/runc/libcontainer/cgroups" -) - -const ( - // SeccompModeFilter refers to the syscall argument SECCOMP_MODE_FILTER. - SeccompModeFilter = uintptr(2) -) - -func findCgroupMountpoints() (map[string]string, error) { - cgMounts, err := cgroups.GetCgroupMounts(false) - if err != nil { - return nil, fmt.Errorf("Failed to parse cgroup information: %v", err) - } - mps := make(map[string]string) - for _, m := range cgMounts { - for _, ss := range m.Subsystems { - mps[ss] = m.Mountpoint - } - } - return mps, nil -} - -// New returns a new SysInfo, using the filesystem to detect which features -// the kernel supports. If `quiet` is `false` warnings are printed in logs -// whenever an error occurs or misconfigurations are present. -func New(quiet bool) *SysInfo { - sysInfo := &SysInfo{} - cgMounts, err := findCgroupMountpoints() - if err != nil { - logrus.Warnf("Failed to parse cgroup information: %v", err) - } else { - sysInfo.cgroupMemInfo = checkCgroupMem(cgMounts, quiet) - sysInfo.cgroupCPUInfo = checkCgroupCPU(cgMounts, quiet) - sysInfo.cgroupBlkioInfo = checkCgroupBlkioInfo(cgMounts, quiet) - sysInfo.cgroupCpusetInfo = checkCgroupCpusetInfo(cgMounts, quiet) - sysInfo.cgroupPids = checkCgroupPids(quiet) - } - - _, ok := cgMounts["devices"] - sysInfo.CgroupDevicesEnabled = ok - - sysInfo.IPv4ForwardingDisabled = !readProcBool("/proc/sys/net/ipv4/ip_forward") - sysInfo.BridgeNFCallIPTablesDisabled = !readProcBool("/proc/sys/net/bridge/bridge-nf-call-iptables") - sysInfo.BridgeNFCallIP6TablesDisabled = !readProcBool("/proc/sys/net/bridge/bridge-nf-call-ip6tables") - - // Check if AppArmor is supported. - if _, err := os.Stat("/sys/kernel/security/apparmor"); !os.IsNotExist(err) { - sysInfo.AppArmor = true - } - - // Check if Seccomp is supported, via CONFIG_SECCOMP. - if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_GET_SECCOMP, 0, 0); err != syscall.EINVAL { - // Make sure the kernel has CONFIG_SECCOMP_FILTER. - if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_SECCOMP, SeccompModeFilter, 0); err != syscall.EINVAL { - sysInfo.Seccomp = true - } - } - - return sysInfo -} - -// checkCgroupMem reads the memory information from the memory cgroup mount point. -func checkCgroupMem(cgMounts map[string]string, quiet bool) cgroupMemInfo { - mountPoint, ok := cgMounts["memory"] - if !ok { - if !quiet { - logrus.Warn("Your kernel does not support cgroup memory limit") - } - return cgroupMemInfo{} - } - - swapLimit := cgroupEnabled(mountPoint, "memory.memsw.limit_in_bytes") - if !quiet && !swapLimit { - logrus.Warn("Your kernel does not support swap memory limit") - } - memoryReservation := cgroupEnabled(mountPoint, "memory.soft_limit_in_bytes") - if !quiet && !memoryReservation { - logrus.Warn("Your kernel does not support memory reservation") - } - oomKillDisable := cgroupEnabled(mountPoint, "memory.oom_control") - if !quiet && !oomKillDisable { - logrus.Warn("Your kernel does not support oom control") - } - memorySwappiness := cgroupEnabled(mountPoint, "memory.swappiness") - if !quiet && !memorySwappiness { - logrus.Warn("Your kernel does not support memory swappiness") - } - kernelMemory := cgroupEnabled(mountPoint, "memory.kmem.limit_in_bytes") - if !quiet && !kernelMemory { - logrus.Warn("Your kernel does not support kernel memory limit") - } - - return cgroupMemInfo{ - MemoryLimit: true, - SwapLimit: swapLimit, - MemoryReservation: memoryReservation, - OomKillDisable: oomKillDisable, - MemorySwappiness: memorySwappiness, - KernelMemory: kernelMemory, - } -} - -// checkCgroupCPU reads the cpu information from the cpu cgroup mount point. -func checkCgroupCPU(cgMounts map[string]string, quiet bool) cgroupCPUInfo { - mountPoint, ok := cgMounts["cpu"] - if !ok { - if !quiet { - logrus.Warn("Unable to find cpu cgroup in mounts") - } - return cgroupCPUInfo{} - } - - cpuShares := cgroupEnabled(mountPoint, "cpu.shares") - if !quiet && !cpuShares { - logrus.Warn("Your kernel does not support cgroup cpu shares") - } - - cpuCfsPeriod := cgroupEnabled(mountPoint, "cpu.cfs_period_us") - if !quiet && !cpuCfsPeriod { - logrus.Warn("Your kernel does not support cgroup cfs period") - } - - cpuCfsQuota := cgroupEnabled(mountPoint, "cpu.cfs_quota_us") - if !quiet && !cpuCfsQuota { - logrus.Warn("Your kernel does not support cgroup cfs quotas") - } - - cpuRealtimePeriod := cgroupEnabled(mountPoint, "cpu.rt_period_us") - if !quiet && !cpuRealtimePeriod { - logrus.Warn("Your kernel does not support cgroup rt period") - } - - cpuRealtimeRuntime := cgroupEnabled(mountPoint, "cpu.rt_runtime_us") - if !quiet && !cpuRealtimeRuntime { - logrus.Warn("Your kernel does not support cgroup rt runtime") - } - - return cgroupCPUInfo{ - CPUShares: cpuShares, - CPUCfsPeriod: cpuCfsPeriod, - CPUCfsQuota: cpuCfsQuota, - CPURealtimePeriod: cpuRealtimePeriod, - CPURealtimeRuntime: cpuRealtimeRuntime, - } -} - -// checkCgroupBlkioInfo reads the blkio information from the blkio cgroup mount point. -func checkCgroupBlkioInfo(cgMounts map[string]string, quiet bool) cgroupBlkioInfo { - mountPoint, ok := cgMounts["blkio"] - if !ok { - if !quiet { - logrus.Warn("Unable to find blkio cgroup in mounts") - } - return cgroupBlkioInfo{} - } - - weight := cgroupEnabled(mountPoint, "blkio.weight") - if !quiet && !weight { - logrus.Warn("Your kernel does not support cgroup blkio weight") - } - - weightDevice := cgroupEnabled(mountPoint, "blkio.weight_device") - if !quiet && !weightDevice { - logrus.Warn("Your kernel does not support cgroup blkio weight_device") - } - - readBpsDevice := cgroupEnabled(mountPoint, "blkio.throttle.read_bps_device") - if !quiet && !readBpsDevice { - logrus.Warn("Your kernel does not support cgroup blkio throttle.read_bps_device") - } - - writeBpsDevice := cgroupEnabled(mountPoint, "blkio.throttle.write_bps_device") - if !quiet && !writeBpsDevice { - logrus.Warn("Your kernel does not support cgroup blkio throttle.write_bps_device") - } - readIOpsDevice := cgroupEnabled(mountPoint, "blkio.throttle.read_iops_device") - if !quiet && !readIOpsDevice { - logrus.Warn("Your kernel does not support cgroup blkio throttle.read_iops_device") - } - - writeIOpsDevice := cgroupEnabled(mountPoint, "blkio.throttle.write_iops_device") - if !quiet && !writeIOpsDevice { - logrus.Warn("Your kernel does not support cgroup blkio throttle.write_iops_device") - } - return cgroupBlkioInfo{ - BlkioWeight: weight, - BlkioWeightDevice: weightDevice, - BlkioReadBpsDevice: readBpsDevice, - BlkioWriteBpsDevice: writeBpsDevice, - BlkioReadIOpsDevice: readIOpsDevice, - BlkioWriteIOpsDevice: writeIOpsDevice, - } -} - -// checkCgroupCpusetInfo reads the cpuset information from the cpuset cgroup mount point. -func checkCgroupCpusetInfo(cgMounts map[string]string, quiet bool) cgroupCpusetInfo { - mountPoint, ok := cgMounts["cpuset"] - if !ok { - if !quiet { - logrus.Warn("Unable to find cpuset cgroup in mounts") - } - return cgroupCpusetInfo{} - } - - cpus, err := ioutil.ReadFile(path.Join(mountPoint, "cpuset.cpus")) - if err != nil { - return cgroupCpusetInfo{} - } - - mems, err := ioutil.ReadFile(path.Join(mountPoint, "cpuset.mems")) - if err != nil { - return cgroupCpusetInfo{} - } - - return cgroupCpusetInfo{ - Cpuset: true, - Cpus: strings.TrimSpace(string(cpus)), - Mems: strings.TrimSpace(string(mems)), - } -} - -// checkCgroupPids reads the pids information from the pids cgroup mount point. -func checkCgroupPids(quiet bool) cgroupPids { - _, err := cgroups.FindCgroupMountpoint("pids") - if err != nil { - if !quiet { - logrus.Warn(err) - } - return cgroupPids{} - } - - return cgroupPids{ - PidsLimit: true, - } -} - -func cgroupEnabled(mountPoint, name string) bool { - _, err := os.Stat(path.Join(mountPoint, name)) - return err == nil -} - -func readProcBool(path string) bool { - val, err := ioutil.ReadFile(path) - if err != nil { - return false - } - return strings.TrimSpace(string(val)) == "1" -} diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_linux_test.go b/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_linux_test.go deleted file mode 100644 index fae0fdf..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_linux_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package sysinfo - -import ( - "io/ioutil" - "os" - "path" - "path/filepath" - "testing" -) - -func TestReadProcBool(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "test-sysinfo-proc") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpDir) - - procFile := filepath.Join(tmpDir, "read-proc-bool") - if err := ioutil.WriteFile(procFile, []byte("1"), 644); err != nil { - t.Fatal(err) - } - - if !readProcBool(procFile) { - t.Fatal("expected proc bool to be true, got false") - } - - if err := ioutil.WriteFile(procFile, []byte("0"), 644); err != nil { - t.Fatal(err) - } - if readProcBool(procFile) { - t.Fatal("expected proc bool to be false, got false") - } - - if readProcBool(path.Join(tmpDir, "no-exist")) { - t.Fatal("should be false for non-existent entry") - } - -} - -func TestCgroupEnabled(t *testing.T) { - cgroupDir, err := ioutil.TempDir("", "cgroup-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(cgroupDir) - - if cgroupEnabled(cgroupDir, "test") { - t.Fatal("cgroupEnabled should be false") - } - - if err := ioutil.WriteFile(path.Join(cgroupDir, "test"), []byte{}, 644); err != nil { - t.Fatal(err) - } - - if !cgroupEnabled(cgroupDir, "test") { - t.Fatal("cgroupEnabled should be true") - } -} diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_solaris.go b/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_solaris.go deleted file mode 100644 index c858d57..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_solaris.go +++ /dev/null @@ -1,121 +0,0 @@ -// +build solaris,cgo - -package sysinfo - -import ( - "bytes" - "os/exec" - "strconv" - "strings" -) - -/* -#cgo LDFLAGS: -llgrp -#include -#include -#include -int getLgrpCount() { - lgrp_cookie_t lgrpcookie = LGRP_COOKIE_NONE; - uint_t nlgrps; - - if ((lgrpcookie = lgrp_init(LGRP_VIEW_OS)) == LGRP_COOKIE_NONE) { - return -1; - } - nlgrps = lgrp_nlgrps(lgrpcookie); - return nlgrps; -} -*/ -import "C" - -// IsCPUSharesAvailable returns whether CPUShares setting is supported. -// We need FSS to be set as default scheduling class to support CPU Shares -func IsCPUSharesAvailable() bool { - cmd := exec.Command("/usr/sbin/dispadmin", "-d") - outBuf := new(bytes.Buffer) - errBuf := new(bytes.Buffer) - cmd.Stderr = errBuf - cmd.Stdout = outBuf - - if err := cmd.Run(); err != nil { - return false - } - return (strings.Contains(outBuf.String(), "FSS")) -} - -// New returns a new SysInfo, using the filesystem to detect which features -// the kernel supports. -//NOTE Solaris: If we change the below capabilities be sure -// to update verifyPlatformContainerSettings() in daemon_solaris.go -func New(quiet bool) *SysInfo { - sysInfo := &SysInfo{} - sysInfo.cgroupMemInfo = setCgroupMem(quiet) - sysInfo.cgroupCPUInfo = setCgroupCPU(quiet) - sysInfo.cgroupBlkioInfo = setCgroupBlkioInfo(quiet) - sysInfo.cgroupCpusetInfo = setCgroupCPUsetInfo(quiet) - - sysInfo.IPv4ForwardingDisabled = false - - sysInfo.AppArmor = false - - return sysInfo -} - -// setCgroupMem reads the memory information for Solaris. -func setCgroupMem(quiet bool) cgroupMemInfo { - - return cgroupMemInfo{ - MemoryLimit: true, - SwapLimit: true, - MemoryReservation: false, - OomKillDisable: false, - MemorySwappiness: false, - KernelMemory: false, - } -} - -// setCgroupCPU reads the cpu information for Solaris. -func setCgroupCPU(quiet bool) cgroupCPUInfo { - - return cgroupCPUInfo{ - CPUShares: true, - CPUCfsPeriod: false, - CPUCfsQuota: true, - CPURealtimePeriod: false, - CPURealtimeRuntime: false, - } -} - -// blkio switches are not supported in Solaris. -func setCgroupBlkioInfo(quiet bool) cgroupBlkioInfo { - - return cgroupBlkioInfo{ - BlkioWeight: false, - BlkioWeightDevice: false, - } -} - -// setCgroupCPUsetInfo reads the cpuset information for Solaris. -func setCgroupCPUsetInfo(quiet bool) cgroupCpusetInfo { - - return cgroupCpusetInfo{ - Cpuset: true, - Cpus: getCPUCount(), - Mems: getLgrpCount(), - } -} - -func getCPUCount() string { - ncpus := C.sysconf(C._SC_NPROCESSORS_ONLN) - if ncpus <= 0 { - return "" - } - return strconv.FormatInt(int64(ncpus), 16) -} - -func getLgrpCount() string { - nlgrps := C.getLgrpCount() - if nlgrps <= 0 { - return "" - } - return strconv.FormatInt(int64(nlgrps), 16) -} diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_test.go b/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_test.go deleted file mode 100644 index b61fbcf..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package sysinfo - -import "testing" - -func TestIsCpusetListAvailable(t *testing.T) { - cases := []struct { - provided string - available string - res bool - err bool - }{ - {"1", "0-4", true, false}, - {"01,3", "0-4", true, false}, - {"", "0-7", true, false}, - {"1--42", "0-7", false, true}, - {"1-42", "00-1,8,,9", false, true}, - {"1,41-42", "43,45", false, false}, - {"0-3", "", false, false}, - } - for _, c := range cases { - r, err := isCpusetListAvailable(c.provided, c.available) - if (c.err && err == nil) && r != c.res { - t.Fatalf("Expected pair: %v, %v for %s, %s. Got %v, %v instead", c.res, c.err, c.provided, c.available, (c.err && err == nil), r) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_unix.go b/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_unix.go deleted file mode 100644 index 45f3ef1..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_unix.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build !linux,!solaris,!windows - -package sysinfo - -// New returns an empty SysInfo for non linux nor solaris for now. -func New(quiet bool) *SysInfo { - sysInfo := &SysInfo{} - return sysInfo -} diff --git a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_windows.go b/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_windows.go deleted file mode 100644 index 4e6255b..0000000 --- a/vendor/github.com/docker/docker/pkg/sysinfo/sysinfo_windows.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build windows - -package sysinfo - -// New returns an empty SysInfo for windows for now. -func New(quiet bool) *SysInfo { - sysInfo := &SysInfo{} - return sysInfo -} diff --git a/vendor/github.com/docker/docker/pkg/system/chtimes.go b/vendor/github.com/docker/docker/pkg/system/chtimes.go deleted file mode 100644 index 7637f12..0000000 --- a/vendor/github.com/docker/docker/pkg/system/chtimes.go +++ /dev/null @@ -1,52 +0,0 @@ -package system - -import ( - "os" - "syscall" - "time" - "unsafe" -) - -var ( - maxTime time.Time -) - -func init() { - if unsafe.Sizeof(syscall.Timespec{}.Nsec) == 8 { - // This is a 64 bit timespec - // os.Chtimes limits time to the following - maxTime = time.Unix(0, 1<<63-1) - } else { - // This is a 32 bit timespec - maxTime = time.Unix(1<<31-1, 0) - } -} - -// Chtimes changes the access time and modified time of a file at the given path -func Chtimes(name string, atime time.Time, mtime time.Time) error { - unixMinTime := time.Unix(0, 0) - unixMaxTime := maxTime - - // If the modified time is prior to the Unix Epoch, or after the - // end of Unix Time, os.Chtimes has undefined behavior - // default to Unix Epoch in this case, just in case - - if atime.Before(unixMinTime) || atime.After(unixMaxTime) { - atime = unixMinTime - } - - if mtime.Before(unixMinTime) || mtime.After(unixMaxTime) { - mtime = unixMinTime - } - - if err := os.Chtimes(name, atime, mtime); err != nil { - return err - } - - // Take platform specific action for setting create time. - if err := setCTime(name, mtime); err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/chtimes_test.go b/vendor/github.com/docker/docker/pkg/system/chtimes_test.go deleted file mode 100644 index 5c87df3..0000000 --- a/vendor/github.com/docker/docker/pkg/system/chtimes_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package system - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" - "time" -) - -// prepareTempFile creates a temporary file in a temporary directory. -func prepareTempFile(t *testing.T) (string, string) { - dir, err := ioutil.TempDir("", "docker-system-test") - if err != nil { - t.Fatal(err) - } - - file := filepath.Join(dir, "exist") - if err := ioutil.WriteFile(file, []byte("hello"), 0644); err != nil { - t.Fatal(err) - } - return file, dir -} - -// TestChtimes tests Chtimes on a tempfile. Test only mTime, because aTime is OS dependent -func TestChtimes(t *testing.T) { - file, dir := prepareTempFile(t) - defer os.RemoveAll(dir) - - beforeUnixEpochTime := time.Unix(0, 0).Add(-100 * time.Second) - unixEpochTime := time.Unix(0, 0) - afterUnixEpochTime := time.Unix(100, 0) - unixMaxTime := maxTime - - // Test both aTime and mTime set to Unix Epoch - Chtimes(file, unixEpochTime, unixEpochTime) - - f, err := os.Stat(file) - if err != nil { - t.Fatal(err) - } - - if f.ModTime() != unixEpochTime { - t.Fatalf("Expected: %s, got: %s", unixEpochTime, f.ModTime()) - } - - // Test aTime before Unix Epoch and mTime set to Unix Epoch - Chtimes(file, beforeUnixEpochTime, unixEpochTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - if f.ModTime() != unixEpochTime { - t.Fatalf("Expected: %s, got: %s", unixEpochTime, f.ModTime()) - } - - // Test aTime set to Unix Epoch and mTime before Unix Epoch - Chtimes(file, unixEpochTime, beforeUnixEpochTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - if f.ModTime() != unixEpochTime { - t.Fatalf("Expected: %s, got: %s", unixEpochTime, f.ModTime()) - } - - // Test both aTime and mTime set to after Unix Epoch (valid time) - Chtimes(file, afterUnixEpochTime, afterUnixEpochTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - if f.ModTime() != afterUnixEpochTime { - t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, f.ModTime()) - } - - // Test both aTime and mTime set to Unix max time - Chtimes(file, unixMaxTime, unixMaxTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - if f.ModTime().Truncate(time.Second) != unixMaxTime.Truncate(time.Second) { - t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), f.ModTime().Truncate(time.Second)) - } -} diff --git a/vendor/github.com/docker/docker/pkg/system/chtimes_unix.go b/vendor/github.com/docker/docker/pkg/system/chtimes_unix.go deleted file mode 100644 index 09d58bc..0000000 --- a/vendor/github.com/docker/docker/pkg/system/chtimes_unix.go +++ /dev/null @@ -1,14 +0,0 @@ -// +build !windows - -package system - -import ( - "time" -) - -//setCTime will set the create time on a file. On Unix, the create -//time is updated as a side effect of setting the modified time, so -//no action is required. -func setCTime(path string, ctime time.Time) error { - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/chtimes_unix_test.go b/vendor/github.com/docker/docker/pkg/system/chtimes_unix_test.go deleted file mode 100644 index 6ec9a71..0000000 --- a/vendor/github.com/docker/docker/pkg/system/chtimes_unix_test.go +++ /dev/null @@ -1,91 +0,0 @@ -// +build !windows - -package system - -import ( - "os" - "syscall" - "testing" - "time" -) - -// TestChtimesLinux tests Chtimes access time on a tempfile on Linux -func TestChtimesLinux(t *testing.T) { - file, dir := prepareTempFile(t) - defer os.RemoveAll(dir) - - beforeUnixEpochTime := time.Unix(0, 0).Add(-100 * time.Second) - unixEpochTime := time.Unix(0, 0) - afterUnixEpochTime := time.Unix(100, 0) - unixMaxTime := maxTime - - // Test both aTime and mTime set to Unix Epoch - Chtimes(file, unixEpochTime, unixEpochTime) - - f, err := os.Stat(file) - if err != nil { - t.Fatal(err) - } - - stat := f.Sys().(*syscall.Stat_t) - aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) - if aTime != unixEpochTime { - t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime) - } - - // Test aTime before Unix Epoch and mTime set to Unix Epoch - Chtimes(file, beforeUnixEpochTime, unixEpochTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - stat = f.Sys().(*syscall.Stat_t) - aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) - if aTime != unixEpochTime { - t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime) - } - - // Test aTime set to Unix Epoch and mTime before Unix Epoch - Chtimes(file, unixEpochTime, beforeUnixEpochTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - stat = f.Sys().(*syscall.Stat_t) - aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) - if aTime != unixEpochTime { - t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime) - } - - // Test both aTime and mTime set to after Unix Epoch (valid time) - Chtimes(file, afterUnixEpochTime, afterUnixEpochTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - stat = f.Sys().(*syscall.Stat_t) - aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) - if aTime != afterUnixEpochTime { - t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, aTime) - } - - // Test both aTime and mTime set to Unix max time - Chtimes(file, unixMaxTime, unixMaxTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - stat = f.Sys().(*syscall.Stat_t) - aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) - if aTime.Truncate(time.Second) != unixMaxTime.Truncate(time.Second) { - t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), aTime.Truncate(time.Second)) - } -} diff --git a/vendor/github.com/docker/docker/pkg/system/chtimes_windows.go b/vendor/github.com/docker/docker/pkg/system/chtimes_windows.go deleted file mode 100644 index 2945868..0000000 --- a/vendor/github.com/docker/docker/pkg/system/chtimes_windows.go +++ /dev/null @@ -1,27 +0,0 @@ -// +build windows - -package system - -import ( - "syscall" - "time" -) - -//setCTime will set the create time on a file. On Windows, this requires -//calling SetFileTime and explicitly including the create time. -func setCTime(path string, ctime time.Time) error { - ctimespec := syscall.NsecToTimespec(ctime.UnixNano()) - pathp, e := syscall.UTF16PtrFromString(path) - if e != nil { - return e - } - h, e := syscall.CreateFile(pathp, - syscall.FILE_WRITE_ATTRIBUTES, syscall.FILE_SHARE_WRITE, nil, - syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0) - if e != nil { - return e - } - defer syscall.Close(h) - c := syscall.NsecToFiletime(syscall.TimespecToNsec(ctimespec)) - return syscall.SetFileTime(h, &c, nil, nil) -} diff --git a/vendor/github.com/docker/docker/pkg/system/chtimes_windows_test.go b/vendor/github.com/docker/docker/pkg/system/chtimes_windows_test.go deleted file mode 100644 index 72d8a10..0000000 --- a/vendor/github.com/docker/docker/pkg/system/chtimes_windows_test.go +++ /dev/null @@ -1,86 +0,0 @@ -// +build windows - -package system - -import ( - "os" - "syscall" - "testing" - "time" -) - -// TestChtimesWindows tests Chtimes access time on a tempfile on Windows -func TestChtimesWindows(t *testing.T) { - file, dir := prepareTempFile(t) - defer os.RemoveAll(dir) - - beforeUnixEpochTime := time.Unix(0, 0).Add(-100 * time.Second) - unixEpochTime := time.Unix(0, 0) - afterUnixEpochTime := time.Unix(100, 0) - unixMaxTime := maxTime - - // Test both aTime and mTime set to Unix Epoch - Chtimes(file, unixEpochTime, unixEpochTime) - - f, err := os.Stat(file) - if err != nil { - t.Fatal(err) - } - - aTime := time.Unix(0, f.Sys().(*syscall.Win32FileAttributeData).LastAccessTime.Nanoseconds()) - if aTime != unixEpochTime { - t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime) - } - - // Test aTime before Unix Epoch and mTime set to Unix Epoch - Chtimes(file, beforeUnixEpochTime, unixEpochTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - aTime = time.Unix(0, f.Sys().(*syscall.Win32FileAttributeData).LastAccessTime.Nanoseconds()) - if aTime != unixEpochTime { - t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime) - } - - // Test aTime set to Unix Epoch and mTime before Unix Epoch - Chtimes(file, unixEpochTime, beforeUnixEpochTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - aTime = time.Unix(0, f.Sys().(*syscall.Win32FileAttributeData).LastAccessTime.Nanoseconds()) - if aTime != unixEpochTime { - t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime) - } - - // Test both aTime and mTime set to after Unix Epoch (valid time) - Chtimes(file, afterUnixEpochTime, afterUnixEpochTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - aTime = time.Unix(0, f.Sys().(*syscall.Win32FileAttributeData).LastAccessTime.Nanoseconds()) - if aTime != afterUnixEpochTime { - t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, aTime) - } - - // Test both aTime and mTime set to Unix max time - Chtimes(file, unixMaxTime, unixMaxTime) - - f, err = os.Stat(file) - if err != nil { - t.Fatal(err) - } - - aTime = time.Unix(0, f.Sys().(*syscall.Win32FileAttributeData).LastAccessTime.Nanoseconds()) - if aTime.Truncate(time.Second) != unixMaxTime.Truncate(time.Second) { - t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), aTime.Truncate(time.Second)) - } -} diff --git a/vendor/github.com/docker/docker/pkg/system/errors.go b/vendor/github.com/docker/docker/pkg/system/errors.go deleted file mode 100644 index 2883189..0000000 --- a/vendor/github.com/docker/docker/pkg/system/errors.go +++ /dev/null @@ -1,10 +0,0 @@ -package system - -import ( - "errors" -) - -var ( - // ErrNotSupportedPlatform means the platform is not supported. - ErrNotSupportedPlatform = errors.New("platform and architecture is not supported") -) diff --git a/vendor/github.com/docker/docker/pkg/system/events_windows.go b/vendor/github.com/docker/docker/pkg/system/events_windows.go deleted file mode 100644 index 3ec6d22..0000000 --- a/vendor/github.com/docker/docker/pkg/system/events_windows.go +++ /dev/null @@ -1,85 +0,0 @@ -package system - -// This file implements syscalls for Win32 events which are not implemented -// in golang. - -import ( - "syscall" - "unsafe" - - "golang.org/x/sys/windows" -) - -var ( - procCreateEvent = modkernel32.NewProc("CreateEventW") - procOpenEvent = modkernel32.NewProc("OpenEventW") - procSetEvent = modkernel32.NewProc("SetEvent") - procResetEvent = modkernel32.NewProc("ResetEvent") - procPulseEvent = modkernel32.NewProc("PulseEvent") -) - -// CreateEvent implements win32 CreateEventW func in golang. It will create an event object. -func CreateEvent(eventAttributes *syscall.SecurityAttributes, manualReset bool, initialState bool, name string) (handle syscall.Handle, err error) { - namep, _ := syscall.UTF16PtrFromString(name) - var _p1 uint32 - if manualReset { - _p1 = 1 - } - var _p2 uint32 - if initialState { - _p2 = 1 - } - r0, _, e1 := procCreateEvent.Call(uintptr(unsafe.Pointer(eventAttributes)), uintptr(_p1), uintptr(_p2), uintptr(unsafe.Pointer(namep))) - use(unsafe.Pointer(namep)) - handle = syscall.Handle(r0) - if handle == syscall.InvalidHandle { - err = e1 - } - return -} - -// OpenEvent implements win32 OpenEventW func in golang. It opens an event object. -func OpenEvent(desiredAccess uint32, inheritHandle bool, name string) (handle syscall.Handle, err error) { - namep, _ := syscall.UTF16PtrFromString(name) - var _p1 uint32 - if inheritHandle { - _p1 = 1 - } - r0, _, e1 := procOpenEvent.Call(uintptr(desiredAccess), uintptr(_p1), uintptr(unsafe.Pointer(namep))) - use(unsafe.Pointer(namep)) - handle = syscall.Handle(r0) - if handle == syscall.InvalidHandle { - err = e1 - } - return -} - -// SetEvent implements win32 SetEvent func in golang. -func SetEvent(handle syscall.Handle) (err error) { - return setResetPulse(handle, procSetEvent) -} - -// ResetEvent implements win32 ResetEvent func in golang. -func ResetEvent(handle syscall.Handle) (err error) { - return setResetPulse(handle, procResetEvent) -} - -// PulseEvent implements win32 PulseEvent func in golang. -func PulseEvent(handle syscall.Handle) (err error) { - return setResetPulse(handle, procPulseEvent) -} - -func setResetPulse(handle syscall.Handle, proc *windows.LazyProc) (err error) { - r0, _, _ := proc.Call(uintptr(handle)) - if r0 != 0 { - err = syscall.Errno(r0) - } - return -} - -var temp unsafe.Pointer - -// use ensures a variable is kept alive without the GC freeing while still needed -func use(p unsafe.Pointer) { - temp = p -} diff --git a/vendor/github.com/docker/docker/pkg/system/exitcode.go b/vendor/github.com/docker/docker/pkg/system/exitcode.go deleted file mode 100644 index 60f0514..0000000 --- a/vendor/github.com/docker/docker/pkg/system/exitcode.go +++ /dev/null @@ -1,33 +0,0 @@ -package system - -import ( - "fmt" - "os/exec" - "syscall" -) - -// GetExitCode returns the ExitStatus of the specified error if its type is -// exec.ExitError, returns 0 and an error otherwise. -func GetExitCode(err error) (int, error) { - exitCode := 0 - if exiterr, ok := err.(*exec.ExitError); ok { - if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok { - return procExit.ExitStatus(), nil - } - } - return exitCode, fmt.Errorf("failed to get exit code") -} - -// ProcessExitCode process the specified error and returns the exit status code -// if the error was of type exec.ExitError, returns nothing otherwise. -func ProcessExitCode(err error) (exitCode int) { - if err != nil { - var exiterr error - if exitCode, exiterr = GetExitCode(err); exiterr != nil { - // TODO: Fix this so we check the error's text. - // we've failed to retrieve exit code, so we set it to 127 - exitCode = 127 - } - } - return -} diff --git a/vendor/github.com/docker/docker/pkg/system/filesys.go b/vendor/github.com/docker/docker/pkg/system/filesys.go deleted file mode 100644 index 810c794..0000000 --- a/vendor/github.com/docker/docker/pkg/system/filesys.go +++ /dev/null @@ -1,54 +0,0 @@ -// +build !windows - -package system - -import ( - "os" - "path/filepath" -) - -// MkdirAllWithACL is a wrapper for MkdirAll that creates a directory -// ACL'd for Builtin Administrators and Local System. -func MkdirAllWithACL(path string, perm os.FileMode) error { - return MkdirAll(path, perm) -} - -// MkdirAll creates a directory named path along with any necessary parents, -// with permission specified by attribute perm for all dir created. -func MkdirAll(path string, perm os.FileMode) error { - return os.MkdirAll(path, perm) -} - -// IsAbs is a platform-specific wrapper for filepath.IsAbs. -func IsAbs(path string) bool { - return filepath.IsAbs(path) -} - -// The functions below here are wrappers for the equivalents in the os package. -// They are passthrough on Unix platforms, and only relevant on Windows. - -// CreateSequential creates the named file with mode 0666 (before umask), truncating -// it if it already exists. If successful, methods on the returned -// File can be used for I/O; the associated file descriptor has mode -// O_RDWR. -// If there is an error, it will be of type *PathError. -func CreateSequential(name string) (*os.File, error) { - return os.Create(name) -} - -// OpenSequential opens the named file for reading. If successful, methods on -// the returned file can be used for reading; the associated file -// descriptor has mode O_RDONLY. -// If there is an error, it will be of type *PathError. -func OpenSequential(name string) (*os.File, error) { - return os.Open(name) -} - -// OpenFileSequential is the generalized open call; most users will use Open -// or Create instead. It opens the named file with specified flag -// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, -// methods on the returned File can be used for I/O. -// If there is an error, it will be of type *PathError. -func OpenFileSequential(name string, flag int, perm os.FileMode) (*os.File, error) { - return os.OpenFile(name, flag, perm) -} diff --git a/vendor/github.com/docker/docker/pkg/system/filesys_windows.go b/vendor/github.com/docker/docker/pkg/system/filesys_windows.go deleted file mode 100644 index 6094f01..0000000 --- a/vendor/github.com/docker/docker/pkg/system/filesys_windows.go +++ /dev/null @@ -1,236 +0,0 @@ -// +build windows - -package system - -import ( - "os" - "path/filepath" - "regexp" - "strings" - "syscall" - "unsafe" - - winio "github.com/Microsoft/go-winio" -) - -// MkdirAllWithACL is a wrapper for MkdirAll that creates a directory -// ACL'd for Builtin Administrators and Local System. -func MkdirAllWithACL(path string, perm os.FileMode) error { - return mkdirall(path, true) -} - -// MkdirAll implementation that is volume path aware for Windows. -func MkdirAll(path string, _ os.FileMode) error { - return mkdirall(path, false) -} - -// mkdirall is a custom version of os.MkdirAll modified for use on Windows -// so that it is both volume path aware, and can create a directory with -// a DACL. -func mkdirall(path string, adminAndLocalSystem bool) error { - if re := regexp.MustCompile(`^\\\\\?\\Volume{[a-z0-9-]+}$`); re.MatchString(path) { - return nil - } - - // The rest of this method is largely copied from os.MkdirAll and should be kept - // as-is to ensure compatibility. - - // Fast path: if we can tell whether path is a directory or file, stop with success or error. - dir, err := os.Stat(path) - if err == nil { - if dir.IsDir() { - return nil - } - return &os.PathError{ - Op: "mkdir", - Path: path, - Err: syscall.ENOTDIR, - } - } - - // Slow path: make sure parent exists and then call Mkdir for path. - i := len(path) - for i > 0 && os.IsPathSeparator(path[i-1]) { // Skip trailing path separator. - i-- - } - - j := i - for j > 0 && !os.IsPathSeparator(path[j-1]) { // Scan backward over element. - j-- - } - - if j > 1 { - // Create parent - err = mkdirall(path[0:j-1], false) - if err != nil { - return err - } - } - - // Parent now exists; invoke os.Mkdir or mkdirWithACL and use its result. - if adminAndLocalSystem { - err = mkdirWithACL(path) - } else { - err = os.Mkdir(path, 0) - } - - if err != nil { - // Handle arguments like "foo/." by - // double-checking that directory doesn't exist. - dir, err1 := os.Lstat(path) - if err1 == nil && dir.IsDir() { - return nil - } - return err - } - return nil -} - -// mkdirWithACL creates a new directory. If there is an error, it will be of -// type *PathError. . -// -// This is a modified and combined version of os.Mkdir and syscall.Mkdir -// in golang to cater for creating a directory am ACL permitting full -// access, with inheritance, to any subfolder/file for Built-in Administrators -// and Local System. -func mkdirWithACL(name string) error { - sa := syscall.SecurityAttributes{Length: 0} - sddl := "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)" - sd, err := winio.SddlToSecurityDescriptor(sddl) - if err != nil { - return &os.PathError{Op: "mkdir", Path: name, Err: err} - } - sa.Length = uint32(unsafe.Sizeof(sa)) - sa.InheritHandle = 1 - sa.SecurityDescriptor = uintptr(unsafe.Pointer(&sd[0])) - - namep, err := syscall.UTF16PtrFromString(name) - if err != nil { - return &os.PathError{Op: "mkdir", Path: name, Err: err} - } - - e := syscall.CreateDirectory(namep, &sa) - if e != nil { - return &os.PathError{Op: "mkdir", Path: name, Err: e} - } - return nil -} - -// IsAbs is a platform-specific wrapper for filepath.IsAbs. On Windows, -// golang filepath.IsAbs does not consider a path \windows\system32 as absolute -// as it doesn't start with a drive-letter/colon combination. However, in -// docker we need to verify things such as WORKDIR /windows/system32 in -// a Dockerfile (which gets translated to \windows\system32 when being processed -// by the daemon. This SHOULD be treated as absolute from a docker processing -// perspective. -func IsAbs(path string) bool { - if !filepath.IsAbs(path) { - if !strings.HasPrefix(path, string(os.PathSeparator)) { - return false - } - } - return true -} - -// The origin of the functions below here are the golang OS and syscall packages, -// slightly modified to only cope with files, not directories due to the -// specific use case. -// -// The alteration is to allow a file on Windows to be opened with -// FILE_FLAG_SEQUENTIAL_SCAN (particular for docker load), to avoid eating -// the standby list, particularly when accessing large files such as layer.tar. - -// CreateSequential creates the named file with mode 0666 (before umask), truncating -// it if it already exists. If successful, methods on the returned -// File can be used for I/O; the associated file descriptor has mode -// O_RDWR. -// If there is an error, it will be of type *PathError. -func CreateSequential(name string) (*os.File, error) { - return OpenFileSequential(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0) -} - -// OpenSequential opens the named file for reading. If successful, methods on -// the returned file can be used for reading; the associated file -// descriptor has mode O_RDONLY. -// If there is an error, it will be of type *PathError. -func OpenSequential(name string) (*os.File, error) { - return OpenFileSequential(name, os.O_RDONLY, 0) -} - -// OpenFileSequential is the generalized open call; most users will use Open -// or Create instead. -// If there is an error, it will be of type *PathError. -func OpenFileSequential(name string, flag int, _ os.FileMode) (*os.File, error) { - if name == "" { - return nil, &os.PathError{Op: "open", Path: name, Err: syscall.ENOENT} - } - r, errf := syscallOpenFileSequential(name, flag, 0) - if errf == nil { - return r, nil - } - return nil, &os.PathError{Op: "open", Path: name, Err: errf} -} - -func syscallOpenFileSequential(name string, flag int, _ os.FileMode) (file *os.File, err error) { - r, e := syscallOpenSequential(name, flag|syscall.O_CLOEXEC, 0) - if e != nil { - return nil, e - } - return os.NewFile(uintptr(r), name), nil -} - -func makeInheritSa() *syscall.SecurityAttributes { - var sa syscall.SecurityAttributes - sa.Length = uint32(unsafe.Sizeof(sa)) - sa.InheritHandle = 1 - return &sa -} - -func syscallOpenSequential(path string, mode int, _ uint32) (fd syscall.Handle, err error) { - if len(path) == 0 { - return syscall.InvalidHandle, syscall.ERROR_FILE_NOT_FOUND - } - pathp, err := syscall.UTF16PtrFromString(path) - if err != nil { - return syscall.InvalidHandle, err - } - var access uint32 - switch mode & (syscall.O_RDONLY | syscall.O_WRONLY | syscall.O_RDWR) { - case syscall.O_RDONLY: - access = syscall.GENERIC_READ - case syscall.O_WRONLY: - access = syscall.GENERIC_WRITE - case syscall.O_RDWR: - access = syscall.GENERIC_READ | syscall.GENERIC_WRITE - } - if mode&syscall.O_CREAT != 0 { - access |= syscall.GENERIC_WRITE - } - if mode&syscall.O_APPEND != 0 { - access &^= syscall.GENERIC_WRITE - access |= syscall.FILE_APPEND_DATA - } - sharemode := uint32(syscall.FILE_SHARE_READ | syscall.FILE_SHARE_WRITE) - var sa *syscall.SecurityAttributes - if mode&syscall.O_CLOEXEC == 0 { - sa = makeInheritSa() - } - var createmode uint32 - switch { - case mode&(syscall.O_CREAT|syscall.O_EXCL) == (syscall.O_CREAT | syscall.O_EXCL): - createmode = syscall.CREATE_NEW - case mode&(syscall.O_CREAT|syscall.O_TRUNC) == (syscall.O_CREAT | syscall.O_TRUNC): - createmode = syscall.CREATE_ALWAYS - case mode&syscall.O_CREAT == syscall.O_CREAT: - createmode = syscall.OPEN_ALWAYS - case mode&syscall.O_TRUNC == syscall.O_TRUNC: - createmode = syscall.TRUNCATE_EXISTING - default: - createmode = syscall.OPEN_EXISTING - } - // Use FILE_FLAG_SEQUENTIAL_SCAN rather than FILE_ATTRIBUTE_NORMAL as implemented in golang. - //https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx - const fileFlagSequentialScan = 0x08000000 // FILE_FLAG_SEQUENTIAL_SCAN - h, e := syscall.CreateFile(pathp, access, sharemode, sa, createmode, fileFlagSequentialScan, 0) - return h, e -} diff --git a/vendor/github.com/docker/docker/pkg/system/lstat.go b/vendor/github.com/docker/docker/pkg/system/lstat.go deleted file mode 100644 index bd23c4d..0000000 --- a/vendor/github.com/docker/docker/pkg/system/lstat.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build !windows - -package system - -import ( - "syscall" -) - -// Lstat takes a path to a file and returns -// a system.StatT type pertaining to that file. -// -// Throws an error if the file does not exist -func Lstat(path string) (*StatT, error) { - s := &syscall.Stat_t{} - if err := syscall.Lstat(path, s); err != nil { - return nil, err - } - return fromStatT(s) -} diff --git a/vendor/github.com/docker/docker/pkg/system/lstat_unix_test.go b/vendor/github.com/docker/docker/pkg/system/lstat_unix_test.go deleted file mode 100644 index 062cf53..0000000 --- a/vendor/github.com/docker/docker/pkg/system/lstat_unix_test.go +++ /dev/null @@ -1,30 +0,0 @@ -// +build linux freebsd - -package system - -import ( - "os" - "testing" -) - -// TestLstat tests Lstat for existing and non existing files -func TestLstat(t *testing.T) { - file, invalid, _, dir := prepareFiles(t) - defer os.RemoveAll(dir) - - statFile, err := Lstat(file) - if err != nil { - t.Fatal(err) - } - if statFile == nil { - t.Fatal("returned empty stat for existing file") - } - - statInvalid, err := Lstat(invalid) - if err == nil { - t.Fatal("did not return error for non-existing file") - } - if statInvalid != nil { - t.Fatal("returned non-nil stat for non-existing file") - } -} diff --git a/vendor/github.com/docker/docker/pkg/system/lstat_windows.go b/vendor/github.com/docker/docker/pkg/system/lstat_windows.go deleted file mode 100644 index 49e87eb..0000000 --- a/vendor/github.com/docker/docker/pkg/system/lstat_windows.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build windows - -package system - -import ( - "os" -) - -// Lstat calls os.Lstat to get a fileinfo interface back. -// This is then copied into our own locally defined structure. -// Note the Linux version uses fromStatT to do the copy back, -// but that not strictly necessary when already in an OS specific module. -func Lstat(path string) (*StatT, error) { - fi, err := os.Lstat(path) - if err != nil { - return nil, err - } - - return &StatT{ - name: fi.Name(), - size: fi.Size(), - mode: fi.Mode(), - modTime: fi.ModTime(), - isDir: fi.IsDir()}, nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/meminfo.go b/vendor/github.com/docker/docker/pkg/system/meminfo.go deleted file mode 100644 index 3b6e947..0000000 --- a/vendor/github.com/docker/docker/pkg/system/meminfo.go +++ /dev/null @@ -1,17 +0,0 @@ -package system - -// MemInfo contains memory statistics of the host system. -type MemInfo struct { - // Total usable RAM (i.e. physical RAM minus a few reserved bits and the - // kernel binary code). - MemTotal int64 - - // Amount of free memory. - MemFree int64 - - // Total amount of swap space available. - SwapTotal int64 - - // Amount of swap space that is currently unused. - SwapFree int64 -} diff --git a/vendor/github.com/docker/docker/pkg/system/meminfo_linux.go b/vendor/github.com/docker/docker/pkg/system/meminfo_linux.go deleted file mode 100644 index 385f1d5..0000000 --- a/vendor/github.com/docker/docker/pkg/system/meminfo_linux.go +++ /dev/null @@ -1,65 +0,0 @@ -package system - -import ( - "bufio" - "io" - "os" - "strconv" - "strings" - - "github.com/docker/go-units" -) - -// ReadMemInfo retrieves memory statistics of the host system and returns a -// MemInfo type. -func ReadMemInfo() (*MemInfo, error) { - file, err := os.Open("/proc/meminfo") - if err != nil { - return nil, err - } - defer file.Close() - return parseMemInfo(file) -} - -// parseMemInfo parses the /proc/meminfo file into -// a MemInfo object given an io.Reader to the file. -// Throws error if there are problems reading from the file -func parseMemInfo(reader io.Reader) (*MemInfo, error) { - meminfo := &MemInfo{} - scanner := bufio.NewScanner(reader) - for scanner.Scan() { - // Expected format: ["MemTotal:", "1234", "kB"] - parts := strings.Fields(scanner.Text()) - - // Sanity checks: Skip malformed entries. - if len(parts) < 3 || parts[2] != "kB" { - continue - } - - // Convert to bytes. - size, err := strconv.Atoi(parts[1]) - if err != nil { - continue - } - bytes := int64(size) * units.KiB - - switch parts[0] { - case "MemTotal:": - meminfo.MemTotal = bytes - case "MemFree:": - meminfo.MemFree = bytes - case "SwapTotal:": - meminfo.SwapTotal = bytes - case "SwapFree:": - meminfo.SwapFree = bytes - } - - } - - // Handle errors that may have occurred during the reading of the file. - if err := scanner.Err(); err != nil { - return nil, err - } - - return meminfo, nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/meminfo_solaris.go b/vendor/github.com/docker/docker/pkg/system/meminfo_solaris.go deleted file mode 100644 index 7f4f84f..0000000 --- a/vendor/github.com/docker/docker/pkg/system/meminfo_solaris.go +++ /dev/null @@ -1,128 +0,0 @@ -// +build solaris,cgo - -package system - -import ( - "fmt" - "unsafe" -) - -// #cgo LDFLAGS: -lkstat -// #include -// #include -// #include -// #include -// #include -// #include -// struct swaptable *allocSwaptable(int num) { -// struct swaptable *st; -// struct swapent *swapent; -// st = (struct swaptable *)malloc(num * sizeof(swapent_t) + sizeof (int)); -// swapent = st->swt_ent; -// for (int i = 0; i < num; i++,swapent++) { -// swapent->ste_path = (char *)malloc(MAXPATHLEN * sizeof (char)); -// } -// st->swt_n = num; -// return st; -//} -// void freeSwaptable (struct swaptable *st) { -// struct swapent *swapent = st->swt_ent; -// for (int i = 0; i < st->swt_n; i++,swapent++) { -// free(swapent->ste_path); -// } -// free(st); -// } -// swapent_t getSwapEnt(swapent_t *ent, int i) { -// return ent[i]; -// } -// int64_t getPpKernel() { -// int64_t pp_kernel = 0; -// kstat_ctl_t *ksc; -// kstat_t *ks; -// kstat_named_t *knp; -// kid_t kid; -// -// if ((ksc = kstat_open()) == NULL) { -// return -1; -// } -// if ((ks = kstat_lookup(ksc, "unix", 0, "system_pages")) == NULL) { -// return -1; -// } -// if (((kid = kstat_read(ksc, ks, NULL)) == -1) || -// ((knp = kstat_data_lookup(ks, "pp_kernel")) == NULL)) { -// return -1; -// } -// switch (knp->data_type) { -// case KSTAT_DATA_UINT64: -// pp_kernel = knp->value.ui64; -// break; -// case KSTAT_DATA_UINT32: -// pp_kernel = knp->value.ui32; -// break; -// } -// pp_kernel *= sysconf(_SC_PAGESIZE); -// return (pp_kernel > 0 ? pp_kernel : -1); -// } -import "C" - -// Get the system memory info using sysconf same as prtconf -func getTotalMem() int64 { - pagesize := C.sysconf(C._SC_PAGESIZE) - npages := C.sysconf(C._SC_PHYS_PAGES) - return int64(pagesize * npages) -} - -func getFreeMem() int64 { - pagesize := C.sysconf(C._SC_PAGESIZE) - npages := C.sysconf(C._SC_AVPHYS_PAGES) - return int64(pagesize * npages) -} - -// ReadMemInfo retrieves memory statistics of the host system and returns a -// MemInfo type. -func ReadMemInfo() (*MemInfo, error) { - - ppKernel := C.getPpKernel() - MemTotal := getTotalMem() - MemFree := getFreeMem() - SwapTotal, SwapFree, err := getSysSwap() - - if ppKernel < 0 || MemTotal < 0 || MemFree < 0 || SwapTotal < 0 || - SwapFree < 0 { - return nil, fmt.Errorf("error getting system memory info %v\n", err) - } - - meminfo := &MemInfo{} - // Total memory is total physical memory less than memory locked by kernel - meminfo.MemTotal = MemTotal - int64(ppKernel) - meminfo.MemFree = MemFree - meminfo.SwapTotal = SwapTotal - meminfo.SwapFree = SwapFree - - return meminfo, nil -} - -func getSysSwap() (int64, int64, error) { - var tSwap int64 - var fSwap int64 - var diskblksPerPage int64 - num, err := C.swapctl(C.SC_GETNSWP, nil) - if err != nil { - return -1, -1, err - } - st := C.allocSwaptable(num) - _, err = C.swapctl(C.SC_LIST, unsafe.Pointer(st)) - if err != nil { - C.freeSwaptable(st) - return -1, -1, err - } - - diskblksPerPage = int64(C.sysconf(C._SC_PAGESIZE) >> C.DEV_BSHIFT) - for i := 0; i < int(num); i++ { - swapent := C.getSwapEnt(&st.swt_ent[0], C.int(i)) - tSwap += int64(swapent.ste_pages) * diskblksPerPage - fSwap += int64(swapent.ste_free) * diskblksPerPage - } - C.freeSwaptable(st) - return tSwap, fSwap, nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/meminfo_unix_test.go b/vendor/github.com/docker/docker/pkg/system/meminfo_unix_test.go deleted file mode 100644 index 44f5562..0000000 --- a/vendor/github.com/docker/docker/pkg/system/meminfo_unix_test.go +++ /dev/null @@ -1,40 +0,0 @@ -// +build linux freebsd - -package system - -import ( - "strings" - "testing" - - "github.com/docker/go-units" -) - -// TestMemInfo tests parseMemInfo with a static meminfo string -func TestMemInfo(t *testing.T) { - const input = ` - MemTotal: 1 kB - MemFree: 2 kB - SwapTotal: 3 kB - SwapFree: 4 kB - Malformed1: - Malformed2: 1 - Malformed3: 2 MB - Malformed4: X kB - ` - meminfo, err := parseMemInfo(strings.NewReader(input)) - if err != nil { - t.Fatal(err) - } - if meminfo.MemTotal != 1*units.KiB { - t.Fatalf("Unexpected MemTotal: %d", meminfo.MemTotal) - } - if meminfo.MemFree != 2*units.KiB { - t.Fatalf("Unexpected MemFree: %d", meminfo.MemFree) - } - if meminfo.SwapTotal != 3*units.KiB { - t.Fatalf("Unexpected SwapTotal: %d", meminfo.SwapTotal) - } - if meminfo.SwapFree != 4*units.KiB { - t.Fatalf("Unexpected SwapFree: %d", meminfo.SwapFree) - } -} diff --git a/vendor/github.com/docker/docker/pkg/system/meminfo_unsupported.go b/vendor/github.com/docker/docker/pkg/system/meminfo_unsupported.go deleted file mode 100644 index 3ce019d..0000000 --- a/vendor/github.com/docker/docker/pkg/system/meminfo_unsupported.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !linux,!windows,!solaris - -package system - -// ReadMemInfo is not supported on platforms other than linux and windows. -func ReadMemInfo() (*MemInfo, error) { - return nil, ErrNotSupportedPlatform -} diff --git a/vendor/github.com/docker/docker/pkg/system/meminfo_windows.go b/vendor/github.com/docker/docker/pkg/system/meminfo_windows.go deleted file mode 100644 index 883944a..0000000 --- a/vendor/github.com/docker/docker/pkg/system/meminfo_windows.go +++ /dev/null @@ -1,45 +0,0 @@ -package system - -import ( - "unsafe" - - "golang.org/x/sys/windows" -) - -var ( - modkernel32 = windows.NewLazySystemDLL("kernel32.dll") - - procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx") -) - -// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366589(v=vs.85).aspx -// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366770(v=vs.85).aspx -type memorystatusex struct { - dwLength uint32 - dwMemoryLoad uint32 - ullTotalPhys uint64 - ullAvailPhys uint64 - ullTotalPageFile uint64 - ullAvailPageFile uint64 - ullTotalVirtual uint64 - ullAvailVirtual uint64 - ullAvailExtendedVirtual uint64 -} - -// ReadMemInfo retrieves memory statistics of the host system and returns a -// MemInfo type. -func ReadMemInfo() (*MemInfo, error) { - msi := &memorystatusex{ - dwLength: 64, - } - r1, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(msi))) - if r1 == 0 { - return &MemInfo{}, nil - } - return &MemInfo{ - MemTotal: int64(msi.ullTotalPhys), - MemFree: int64(msi.ullAvailPhys), - SwapTotal: int64(msi.ullTotalPageFile), - SwapFree: int64(msi.ullAvailPageFile), - }, nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/mknod.go b/vendor/github.com/docker/docker/pkg/system/mknod.go deleted file mode 100644 index 7395818..0000000 --- a/vendor/github.com/docker/docker/pkg/system/mknod.go +++ /dev/null @@ -1,22 +0,0 @@ -// +build !windows - -package system - -import ( - "syscall" -) - -// Mknod creates a filesystem node (file, device special file or named pipe) named path -// with attributes specified by mode and dev. -func Mknod(path string, mode uint32, dev int) error { - return syscall.Mknod(path, mode, dev) -} - -// Mkdev is used to build the value of linux devices (in /dev/) which specifies major -// and minor number of the newly created device special file. -// Linux device nodes are a bit weird due to backwards compat with 16 bit device nodes. -// They are, from low to high: the lower 8 bits of the minor, then 12 bits of the major, -// then the top 12 bits of the minor. -func Mkdev(major int64, minor int64) uint32 { - return uint32(((minor & 0xfff00) << 12) | ((major & 0xfff) << 8) | (minor & 0xff)) -} diff --git a/vendor/github.com/docker/docker/pkg/system/mknod_windows.go b/vendor/github.com/docker/docker/pkg/system/mknod_windows.go deleted file mode 100644 index 2e863c0..0000000 --- a/vendor/github.com/docker/docker/pkg/system/mknod_windows.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build windows - -package system - -// Mknod is not implemented on Windows. -func Mknod(path string, mode uint32, dev int) error { - return ErrNotSupportedPlatform -} - -// Mkdev is not implemented on Windows. -func Mkdev(major int64, minor int64) uint32 { - panic("Mkdev not implemented on Windows.") -} diff --git a/vendor/github.com/docker/docker/pkg/system/path_unix.go b/vendor/github.com/docker/docker/pkg/system/path_unix.go deleted file mode 100644 index c607c4d..0000000 --- a/vendor/github.com/docker/docker/pkg/system/path_unix.go +++ /dev/null @@ -1,14 +0,0 @@ -// +build !windows - -package system - -// DefaultPathEnv is unix style list of directories to search for -// executables. Each directory is separated from the next by a colon -// ':' character . -const DefaultPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - -// CheckSystemDriveAndRemoveDriveLetter verifies that a path, if it includes a drive letter, -// is the system drive. This is a no-op on Linux. -func CheckSystemDriveAndRemoveDriveLetter(path string) (string, error) { - return path, nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/path_windows.go b/vendor/github.com/docker/docker/pkg/system/path_windows.go deleted file mode 100644 index cbfe2c1..0000000 --- a/vendor/github.com/docker/docker/pkg/system/path_windows.go +++ /dev/null @@ -1,37 +0,0 @@ -// +build windows - -package system - -import ( - "fmt" - "path/filepath" - "strings" -) - -// DefaultPathEnv is deliberately empty on Windows as the default path will be set by -// the container. Docker has no context of what the default path should be. -const DefaultPathEnv = "" - -// CheckSystemDriveAndRemoveDriveLetter verifies and manipulates a Windows path. -// This is used, for example, when validating a user provided path in docker cp. -// If a drive letter is supplied, it must be the system drive. The drive letter -// is always removed. Also, it translates it to OS semantics (IOW / to \). We -// need the path in this syntax so that it can ultimately be contatenated with -// a Windows long-path which doesn't support drive-letters. Examples: -// C: --> Fail -// C:\ --> \ -// a --> a -// /a --> \a -// d:\ --> Fail -func CheckSystemDriveAndRemoveDriveLetter(path string) (string, error) { - if len(path) == 2 && string(path[1]) == ":" { - return "", fmt.Errorf("No relative path specified in %q", path) - } - if !filepath.IsAbs(path) || len(path) < 2 { - return filepath.FromSlash(path), nil - } - if string(path[1]) == ":" && !strings.EqualFold(string(path[0]), "c") { - return "", fmt.Errorf("The specified path is not on the system drive (C:)") - } - return filepath.FromSlash(path[2:]), nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/path_windows_test.go b/vendor/github.com/docker/docker/pkg/system/path_windows_test.go deleted file mode 100644 index eccb26a..0000000 --- a/vendor/github.com/docker/docker/pkg/system/path_windows_test.go +++ /dev/null @@ -1,78 +0,0 @@ -// +build windows - -package system - -import "testing" - -// TestCheckSystemDriveAndRemoveDriveLetter tests CheckSystemDriveAndRemoveDriveLetter -func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) { - // Fails if not C drive. - path, err := CheckSystemDriveAndRemoveDriveLetter(`d:\`) - if err == nil || (err != nil && err.Error() != "The specified path is not on the system drive (C:)") { - t.Fatalf("Expected error for d:") - } - - // Single character is unchanged - if path, err = CheckSystemDriveAndRemoveDriveLetter("z"); err != nil { - t.Fatalf("Single character should pass") - } - if path != "z" { - t.Fatalf("Single character should be unchanged") - } - - // Two characters without colon is unchanged - if path, err = CheckSystemDriveAndRemoveDriveLetter("AB"); err != nil { - t.Fatalf("2 characters without colon should pass") - } - if path != "AB" { - t.Fatalf("2 characters without colon should be unchanged") - } - - // Abs path without drive letter - if path, err = CheckSystemDriveAndRemoveDriveLetter(`\l`); err != nil { - t.Fatalf("abs path no drive letter should pass") - } - if path != `\l` { - t.Fatalf("abs path without drive letter should be unchanged") - } - - // Abs path without drive letter, linux style - if path, err = CheckSystemDriveAndRemoveDriveLetter(`/l`); err != nil { - t.Fatalf("abs path no drive letter linux style should pass") - } - if path != `\l` { - t.Fatalf("abs path without drive letter linux failed %s", path) - } - - // Drive-colon should be stripped - if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:\`); err != nil { - t.Fatalf("An absolute path should pass") - } - if path != `\` { - t.Fatalf(`An absolute path should have been shortened to \ %s`, path) - } - - // Verify with a linux-style path - if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:/`); err != nil { - t.Fatalf("An absolute path should pass") - } - if path != `\` { - t.Fatalf(`A linux style absolute path should have been shortened to \ %s`, path) - } - - // Failure on c: - if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:`); err == nil { - t.Fatalf("c: should fail") - } - if err.Error() != `No relative path specified in "c:"` { - t.Fatalf(path, err) - } - - // Failure on d: - if path, err = CheckSystemDriveAndRemoveDriveLetter(`d:`); err == nil { - t.Fatalf("c: should fail") - } - if err.Error() != `No relative path specified in "d:"` { - t.Fatalf(path, err) - } -} diff --git a/vendor/github.com/docker/docker/pkg/system/stat.go b/vendor/github.com/docker/docker/pkg/system/stat.go deleted file mode 100644 index 087034c..0000000 --- a/vendor/github.com/docker/docker/pkg/system/stat.go +++ /dev/null @@ -1,53 +0,0 @@ -// +build !windows - -package system - -import ( - "syscall" -) - -// StatT type contains status of a file. It contains metadata -// like permission, owner, group, size, etc about a file. -type StatT struct { - mode uint32 - uid uint32 - gid uint32 - rdev uint64 - size int64 - mtim syscall.Timespec -} - -// Mode returns file's permission mode. -func (s StatT) Mode() uint32 { - return s.mode -} - -// UID returns file's user id of owner. -func (s StatT) UID() uint32 { - return s.uid -} - -// GID returns file's group id of owner. -func (s StatT) GID() uint32 { - return s.gid -} - -// Rdev returns file's device ID (if it's special file). -func (s StatT) Rdev() uint64 { - return s.rdev -} - -// Size returns file's size. -func (s StatT) Size() int64 { - return s.size -} - -// Mtim returns file's last modification time. -func (s StatT) Mtim() syscall.Timespec { - return s.mtim -} - -// GetLastModification returns file's last modification time. -func (s StatT) GetLastModification() syscall.Timespec { - return s.Mtim() -} diff --git a/vendor/github.com/docker/docker/pkg/system/stat_darwin.go b/vendor/github.com/docker/docker/pkg/system/stat_darwin.go deleted file mode 100644 index f0742f5..0000000 --- a/vendor/github.com/docker/docker/pkg/system/stat_darwin.go +++ /dev/null @@ -1,32 +0,0 @@ -package system - -import ( - "syscall" -) - -// fromStatT creates a system.StatT type from a syscall.Stat_t type -func fromStatT(s *syscall.Stat_t) (*StatT, error) { - return &StatT{size: s.Size, - mode: uint32(s.Mode), - uid: s.Uid, - gid: s.Gid, - rdev: uint64(s.Rdev), - mtim: s.Mtimespec}, nil -} - -// FromStatT loads a system.StatT from a syscall.Stat_t. -func FromStatT(s *syscall.Stat_t) (*StatT, error) { - return fromStatT(s) -} - -// Stat takes a path to a file and returns -// a system.StatT type pertaining to that file. -// -// Throws an error if the file does not exist -func Stat(path string) (*StatT, error) { - s := &syscall.Stat_t{} - if err := syscall.Stat(path, s); err != nil { - return nil, err - } - return fromStatT(s) -} diff --git a/vendor/github.com/docker/docker/pkg/system/stat_freebsd.go b/vendor/github.com/docker/docker/pkg/system/stat_freebsd.go deleted file mode 100644 index d0fb6f1..0000000 --- a/vendor/github.com/docker/docker/pkg/system/stat_freebsd.go +++ /dev/null @@ -1,27 +0,0 @@ -package system - -import ( - "syscall" -) - -// fromStatT converts a syscall.Stat_t type to a system.Stat_t type -func fromStatT(s *syscall.Stat_t) (*StatT, error) { - return &StatT{size: s.Size, - mode: uint32(s.Mode), - uid: s.Uid, - gid: s.Gid, - rdev: uint64(s.Rdev), - mtim: s.Mtimespec}, nil -} - -// Stat takes a path to a file and returns -// a system.Stat_t type pertaining to that file. -// -// Throws an error if the file does not exist -func Stat(path string) (*StatT, error) { - s := &syscall.Stat_t{} - if err := syscall.Stat(path, s); err != nil { - return nil, err - } - return fromStatT(s) -} diff --git a/vendor/github.com/docker/docker/pkg/system/stat_linux.go b/vendor/github.com/docker/docker/pkg/system/stat_linux.go deleted file mode 100644 index 8b1eded..0000000 --- a/vendor/github.com/docker/docker/pkg/system/stat_linux.go +++ /dev/null @@ -1,33 +0,0 @@ -package system - -import ( - "syscall" -) - -// fromStatT converts a syscall.Stat_t type to a system.Stat_t type -func fromStatT(s *syscall.Stat_t) (*StatT, error) { - return &StatT{size: s.Size, - mode: s.Mode, - uid: s.Uid, - gid: s.Gid, - rdev: s.Rdev, - mtim: s.Mtim}, nil -} - -// FromStatT exists only on linux, and loads a system.StatT from a -// syscal.Stat_t. -func FromStatT(s *syscall.Stat_t) (*StatT, error) { - return fromStatT(s) -} - -// Stat takes a path to a file and returns -// a system.StatT type pertaining to that file. -// -// Throws an error if the file does not exist -func Stat(path string) (*StatT, error) { - s := &syscall.Stat_t{} - if err := syscall.Stat(path, s); err != nil { - return nil, err - } - return fromStatT(s) -} diff --git a/vendor/github.com/docker/docker/pkg/system/stat_openbsd.go b/vendor/github.com/docker/docker/pkg/system/stat_openbsd.go deleted file mode 100644 index 3c3b71f..0000000 --- a/vendor/github.com/docker/docker/pkg/system/stat_openbsd.go +++ /dev/null @@ -1,15 +0,0 @@ -package system - -import ( - "syscall" -) - -// fromStatT creates a system.StatT type from a syscall.Stat_t type -func fromStatT(s *syscall.Stat_t) (*StatT, error) { - return &StatT{size: s.Size, - mode: uint32(s.Mode), - uid: s.Uid, - gid: s.Gid, - rdev: uint64(s.Rdev), - mtim: s.Mtim}, nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/stat_solaris.go b/vendor/github.com/docker/docker/pkg/system/stat_solaris.go deleted file mode 100644 index 0216985..0000000 --- a/vendor/github.com/docker/docker/pkg/system/stat_solaris.go +++ /dev/null @@ -1,34 +0,0 @@ -// +build solaris - -package system - -import ( - "syscall" -) - -// fromStatT creates a system.StatT type from a syscall.Stat_t type -func fromStatT(s *syscall.Stat_t) (*StatT, error) { - return &StatT{size: s.Size, - mode: uint32(s.Mode), - uid: s.Uid, - gid: s.Gid, - rdev: uint64(s.Rdev), - mtim: s.Mtim}, nil -} - -// FromStatT loads a system.StatT from a syscal.Stat_t. -func FromStatT(s *syscall.Stat_t) (*StatT, error) { - return fromStatT(s) -} - -// Stat takes a path to a file and returns -// a system.StatT type pertaining to that file. -// -// Throws an error if the file does not exist -func Stat(path string) (*StatT, error) { - s := &syscall.Stat_t{} - if err := syscall.Stat(path, s); err != nil { - return nil, err - } - return fromStatT(s) -} diff --git a/vendor/github.com/docker/docker/pkg/system/stat_unix_test.go b/vendor/github.com/docker/docker/pkg/system/stat_unix_test.go deleted file mode 100644 index dee8d30..0000000 --- a/vendor/github.com/docker/docker/pkg/system/stat_unix_test.go +++ /dev/null @@ -1,39 +0,0 @@ -// +build linux freebsd - -package system - -import ( - "os" - "syscall" - "testing" -) - -// TestFromStatT tests fromStatT for a tempfile -func TestFromStatT(t *testing.T) { - file, _, _, dir := prepareFiles(t) - defer os.RemoveAll(dir) - - stat := &syscall.Stat_t{} - err := syscall.Lstat(file, stat) - - s, err := fromStatT(stat) - if err != nil { - t.Fatal(err) - } - - if stat.Mode != s.Mode() { - t.Fatal("got invalid mode") - } - if stat.Uid != s.UID() { - t.Fatal("got invalid uid") - } - if stat.Gid != s.GID() { - t.Fatal("got invalid gid") - } - if stat.Rdev != s.Rdev() { - t.Fatal("got invalid rdev") - } - if stat.Mtim != s.Mtim() { - t.Fatal("got invalid mtim") - } -} diff --git a/vendor/github.com/docker/docker/pkg/system/stat_unsupported.go b/vendor/github.com/docker/docker/pkg/system/stat_unsupported.go deleted file mode 100644 index 5d85f52..0000000 --- a/vendor/github.com/docker/docker/pkg/system/stat_unsupported.go +++ /dev/null @@ -1,17 +0,0 @@ -// +build !linux,!windows,!freebsd,!solaris,!openbsd,!darwin - -package system - -import ( - "syscall" -) - -// fromStatT creates a system.StatT type from a syscall.Stat_t type -func fromStatT(s *syscall.Stat_t) (*StatT, error) { - return &StatT{size: s.Size, - mode: uint32(s.Mode), - uid: s.Uid, - gid: s.Gid, - rdev: uint64(s.Rdev), - mtim: s.Mtimespec}, nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/stat_windows.go b/vendor/github.com/docker/docker/pkg/system/stat_windows.go deleted file mode 100644 index 39490c6..0000000 --- a/vendor/github.com/docker/docker/pkg/system/stat_windows.go +++ /dev/null @@ -1,43 +0,0 @@ -// +build windows - -package system - -import ( - "os" - "time" -) - -// StatT type contains status of a file. It contains metadata -// like name, permission, size, etc about a file. -type StatT struct { - name string - size int64 - mode os.FileMode - modTime time.Time - isDir bool -} - -// Name returns file's name. -func (s StatT) Name() string { - return s.name -} - -// Size returns file's size. -func (s StatT) Size() int64 { - return s.size -} - -// Mode returns file's permission mode. -func (s StatT) Mode() os.FileMode { - return s.mode -} - -// ModTime returns file's last modification time. -func (s StatT) ModTime() time.Time { - return s.modTime -} - -// IsDir returns whether file is actually a directory. -func (s StatT) IsDir() bool { - return s.isDir -} diff --git a/vendor/github.com/docker/docker/pkg/system/syscall_unix.go b/vendor/github.com/docker/docker/pkg/system/syscall_unix.go deleted file mode 100644 index 3ae9128..0000000 --- a/vendor/github.com/docker/docker/pkg/system/syscall_unix.go +++ /dev/null @@ -1,17 +0,0 @@ -// +build linux freebsd - -package system - -import "syscall" - -// Unmount is a platform-specific helper function to call -// the unmount syscall. -func Unmount(dest string) error { - return syscall.Unmount(dest, 0) -} - -// CommandLineToArgv should not be used on Unix. -// It simply returns commandLine in the only element in the returned array. -func CommandLineToArgv(commandLine string) ([]string, error) { - return []string{commandLine}, nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/syscall_windows.go b/vendor/github.com/docker/docker/pkg/system/syscall_windows.go deleted file mode 100644 index 1f31187..0000000 --- a/vendor/github.com/docker/docker/pkg/system/syscall_windows.go +++ /dev/null @@ -1,105 +0,0 @@ -package system - -import ( - "syscall" - "unsafe" - - "github.com/Sirupsen/logrus" -) - -var ( - ntuserApiset = syscall.NewLazyDLL("ext-ms-win-ntuser-window-l1-1-0") - procGetVersionExW = modkernel32.NewProc("GetVersionExW") -) - -// OSVersion is a wrapper for Windows version information -// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx -type OSVersion struct { - Version uint32 - MajorVersion uint8 - MinorVersion uint8 - Build uint16 -} - -// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx -type osVersionInfoEx struct { - OSVersionInfoSize uint32 - MajorVersion uint32 - MinorVersion uint32 - BuildNumber uint32 - PlatformID uint32 - CSDVersion [128]uint16 - ServicePackMajor uint16 - ServicePackMinor uint16 - SuiteMask uint16 - ProductType byte - Reserve byte -} - -// GetOSVersion gets the operating system version on Windows. Note that -// docker.exe must be manifested to get the correct version information. -func GetOSVersion() OSVersion { - var err error - osv := OSVersion{} - osv.Version, err = syscall.GetVersion() - if err != nil { - // GetVersion never fails. - panic(err) - } - osv.MajorVersion = uint8(osv.Version & 0xFF) - osv.MinorVersion = uint8(osv.Version >> 8 & 0xFF) - osv.Build = uint16(osv.Version >> 16) - return osv -} - -// IsWindowsClient returns true if the SKU is client -// @engine maintainers - this function should not be removed or modified as it -// is used to enforce licensing restrictions on Windows. -func IsWindowsClient() bool { - osviex := &osVersionInfoEx{OSVersionInfoSize: 284} - r1, _, err := procGetVersionExW.Call(uintptr(unsafe.Pointer(osviex))) - if r1 == 0 { - logrus.Warnf("GetVersionExW failed - assuming server SKU: %v", err) - return false - } - const verNTWorkstation = 0x00000001 - return osviex.ProductType == verNTWorkstation -} - -// Unmount is a platform-specific helper function to call -// the unmount syscall. Not supported on Windows -func Unmount(dest string) error { - return nil -} - -// CommandLineToArgv wraps the Windows syscall to turn a commandline into an argument array. -func CommandLineToArgv(commandLine string) ([]string, error) { - var argc int32 - - argsPtr, err := syscall.UTF16PtrFromString(commandLine) - if err != nil { - return nil, err - } - - argv, err := syscall.CommandLineToArgv(argsPtr, &argc) - if err != nil { - return nil, err - } - defer syscall.LocalFree(syscall.Handle(uintptr(unsafe.Pointer(argv)))) - - newArgs := make([]string, argc) - for i, v := range (*argv)[:argc] { - newArgs[i] = string(syscall.UTF16ToString((*v)[:])) - } - - return newArgs, nil -} - -// HasWin32KSupport determines whether containers that depend on win32k can -// run on this machine. Win32k is the driver used to implement windowing. -func HasWin32KSupport() bool { - // For now, check for ntuser API support on the host. In the future, a host - // may support win32k in containers even if the host does not support ntuser - // APIs. - return ntuserApiset.Load() == nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/syscall_windows_test.go b/vendor/github.com/docker/docker/pkg/system/syscall_windows_test.go deleted file mode 100644 index 4886b2b..0000000 --- a/vendor/github.com/docker/docker/pkg/system/syscall_windows_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package system - -import "testing" - -func TestHasWin32KSupport(t *testing.T) { - s := HasWin32KSupport() // make sure this doesn't panic - - t.Logf("win32k: %v", s) // will be different on different platforms -- informative only -} diff --git a/vendor/github.com/docker/docker/pkg/system/umask.go b/vendor/github.com/docker/docker/pkg/system/umask.go deleted file mode 100644 index 3d0146b..0000000 --- a/vendor/github.com/docker/docker/pkg/system/umask.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build !windows - -package system - -import ( - "syscall" -) - -// Umask sets current process's file mode creation mask to newmask -// and returns oldmask. -func Umask(newmask int) (oldmask int, err error) { - return syscall.Umask(newmask), nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/umask_windows.go b/vendor/github.com/docker/docker/pkg/system/umask_windows.go deleted file mode 100644 index 13f1de1..0000000 --- a/vendor/github.com/docker/docker/pkg/system/umask_windows.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build windows - -package system - -// Umask is not supported on the windows platform. -func Umask(newmask int) (oldmask int, err error) { - // should not be called on cli code path - return 0, ErrNotSupportedPlatform -} diff --git a/vendor/github.com/docker/docker/pkg/system/utimes_freebsd.go b/vendor/github.com/docker/docker/pkg/system/utimes_freebsd.go deleted file mode 100644 index e2eac3b..0000000 --- a/vendor/github.com/docker/docker/pkg/system/utimes_freebsd.go +++ /dev/null @@ -1,22 +0,0 @@ -package system - -import ( - "syscall" - "unsafe" -) - -// LUtimesNano is used to change access and modification time of the specified path. -// It's used for symbol link file because syscall.UtimesNano doesn't support a NOFOLLOW flag atm. -func LUtimesNano(path string, ts []syscall.Timespec) error { - var _path *byte - _path, err := syscall.BytePtrFromString(path) - if err != nil { - return err - } - - if _, _, err := syscall.Syscall(syscall.SYS_LUTIMES, uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), 0); err != 0 && err != syscall.ENOSYS { - return err - } - - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/utimes_linux.go b/vendor/github.com/docker/docker/pkg/system/utimes_linux.go deleted file mode 100644 index fc8a1ab..0000000 --- a/vendor/github.com/docker/docker/pkg/system/utimes_linux.go +++ /dev/null @@ -1,26 +0,0 @@ -package system - -import ( - "syscall" - "unsafe" -) - -// LUtimesNano is used to change access and modification time of the specified path. -// It's used for symbol link file because syscall.UtimesNano doesn't support a NOFOLLOW flag atm. -func LUtimesNano(path string, ts []syscall.Timespec) error { - // These are not currently available in syscall - atFdCwd := -100 - atSymLinkNoFollow := 0x100 - - var _path *byte - _path, err := syscall.BytePtrFromString(path) - if err != nil { - return err - } - - if _, _, err := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(atFdCwd), uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), uintptr(atSymLinkNoFollow), 0, 0); err != 0 && err != syscall.ENOSYS { - return err - } - - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/utimes_unix_test.go b/vendor/github.com/docker/docker/pkg/system/utimes_unix_test.go deleted file mode 100644 index a73ed11..0000000 --- a/vendor/github.com/docker/docker/pkg/system/utimes_unix_test.go +++ /dev/null @@ -1,68 +0,0 @@ -// +build linux freebsd - -package system - -import ( - "io/ioutil" - "os" - "path/filepath" - "syscall" - "testing" -) - -// prepareFiles creates files for testing in the temp directory -func prepareFiles(t *testing.T) (string, string, string, string) { - dir, err := ioutil.TempDir("", "docker-system-test") - if err != nil { - t.Fatal(err) - } - - file := filepath.Join(dir, "exist") - if err := ioutil.WriteFile(file, []byte("hello"), 0644); err != nil { - t.Fatal(err) - } - - invalid := filepath.Join(dir, "doesnt-exist") - - symlink := filepath.Join(dir, "symlink") - if err := os.Symlink(file, symlink); err != nil { - t.Fatal(err) - } - - return file, invalid, symlink, dir -} - -func TestLUtimesNano(t *testing.T) { - file, invalid, symlink, dir := prepareFiles(t) - defer os.RemoveAll(dir) - - before, err := os.Stat(file) - if err != nil { - t.Fatal(err) - } - - ts := []syscall.Timespec{{Sec: 0, Nsec: 0}, {Sec: 0, Nsec: 0}} - if err := LUtimesNano(symlink, ts); err != nil { - t.Fatal(err) - } - - symlinkInfo, err := os.Lstat(symlink) - if err != nil { - t.Fatal(err) - } - if before.ModTime().Unix() == symlinkInfo.ModTime().Unix() { - t.Fatal("The modification time of the symlink should be different") - } - - fileInfo, err := os.Stat(file) - if err != nil { - t.Fatal(err) - } - if before.ModTime().Unix() != fileInfo.ModTime().Unix() { - t.Fatal("The modification time of the file should be same") - } - - if err := LUtimesNano(invalid, ts); err == nil { - t.Fatal("Doesn't return an error on a non-existing file") - } -} diff --git a/vendor/github.com/docker/docker/pkg/system/utimes_unsupported.go b/vendor/github.com/docker/docker/pkg/system/utimes_unsupported.go deleted file mode 100644 index 1397145..0000000 --- a/vendor/github.com/docker/docker/pkg/system/utimes_unsupported.go +++ /dev/null @@ -1,10 +0,0 @@ -// +build !linux,!freebsd - -package system - -import "syscall" - -// LUtimesNano is only supported on linux and freebsd. -func LUtimesNano(path string, ts []syscall.Timespec) error { - return ErrNotSupportedPlatform -} diff --git a/vendor/github.com/docker/docker/pkg/system/xattrs_linux.go b/vendor/github.com/docker/docker/pkg/system/xattrs_linux.go deleted file mode 100644 index d2e2c05..0000000 --- a/vendor/github.com/docker/docker/pkg/system/xattrs_linux.go +++ /dev/null @@ -1,63 +0,0 @@ -package system - -import ( - "syscall" - "unsafe" -) - -// Lgetxattr retrieves the value of the extended attribute identified by attr -// and associated with the given path in the file system. -// It will returns a nil slice and nil error if the xattr is not set. -func Lgetxattr(path string, attr string) ([]byte, error) { - pathBytes, err := syscall.BytePtrFromString(path) - if err != nil { - return nil, err - } - attrBytes, err := syscall.BytePtrFromString(attr) - if err != nil { - return nil, err - } - - dest := make([]byte, 128) - destBytes := unsafe.Pointer(&dest[0]) - sz, _, errno := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) - if errno == syscall.ENODATA { - return nil, nil - } - if errno == syscall.ERANGE { - dest = make([]byte, sz) - destBytes := unsafe.Pointer(&dest[0]) - sz, _, errno = syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) - } - if errno != 0 { - return nil, errno - } - - return dest[:sz], nil -} - -var _zero uintptr - -// Lsetxattr sets the value of the extended attribute identified by attr -// and associated with the given path in the file system. -func Lsetxattr(path string, attr string, data []byte, flags int) error { - pathBytes, err := syscall.BytePtrFromString(path) - if err != nil { - return err - } - attrBytes, err := syscall.BytePtrFromString(attr) - if err != nil { - return err - } - var dataBytes unsafe.Pointer - if len(data) > 0 { - dataBytes = unsafe.Pointer(&data[0]) - } else { - dataBytes = unsafe.Pointer(&_zero) - } - _, _, errno := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(dataBytes), uintptr(len(data)), uintptr(flags), 0) - if errno != 0 { - return errno - } - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/system/xattrs_unsupported.go b/vendor/github.com/docker/docker/pkg/system/xattrs_unsupported.go deleted file mode 100644 index 0114f22..0000000 --- a/vendor/github.com/docker/docker/pkg/system/xattrs_unsupported.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build !linux - -package system - -// Lgetxattr is not supported on platforms other than linux. -func Lgetxattr(path string, attr string) ([]byte, error) { - return nil, ErrNotSupportedPlatform -} - -// Lsetxattr is not supported on platforms other than linux. -func Lsetxattr(path string, attr string, data []byte, flags int) error { - return ErrNotSupportedPlatform -} diff --git a/vendor/github.com/docker/docker/pkg/tailfile/tailfile.go b/vendor/github.com/docker/docker/pkg/tailfile/tailfile.go deleted file mode 100644 index 09eb393..0000000 --- a/vendor/github.com/docker/docker/pkg/tailfile/tailfile.go +++ /dev/null @@ -1,66 +0,0 @@ -// Package tailfile provides helper functions to read the nth lines of any -// ReadSeeker. -package tailfile - -import ( - "bytes" - "errors" - "io" - "os" -) - -const blockSize = 1024 - -var eol = []byte("\n") - -// ErrNonPositiveLinesNumber is an error returned if the lines number was negative. -var ErrNonPositiveLinesNumber = errors.New("The number of lines to extract from the file must be positive") - -//TailFile returns last n lines of reader f (could be a fil). -func TailFile(f io.ReadSeeker, n int) ([][]byte, error) { - if n <= 0 { - return nil, ErrNonPositiveLinesNumber - } - size, err := f.Seek(0, os.SEEK_END) - if err != nil { - return nil, err - } - block := -1 - var data []byte - var cnt int - for { - var b []byte - step := int64(block * blockSize) - left := size + step // how many bytes to beginning - if left < 0 { - if _, err := f.Seek(0, os.SEEK_SET); err != nil { - return nil, err - } - b = make([]byte, blockSize+left) - if _, err := f.Read(b); err != nil { - return nil, err - } - data = append(b, data...) - break - } else { - b = make([]byte, blockSize) - if _, err := f.Seek(left, os.SEEK_SET); err != nil { - return nil, err - } - if _, err := f.Read(b); err != nil { - return nil, err - } - data = append(b, data...) - } - cnt += bytes.Count(b, eol) - if cnt > n { - break - } - block-- - } - lines := bytes.Split(data, eol) - if n < len(lines) { - return lines[len(lines)-n-1 : len(lines)-1], nil - } - return lines[:len(lines)-1], nil -} diff --git a/vendor/github.com/docker/docker/pkg/tailfile/tailfile_test.go b/vendor/github.com/docker/docker/pkg/tailfile/tailfile_test.go deleted file mode 100644 index 31217c0..0000000 --- a/vendor/github.com/docker/docker/pkg/tailfile/tailfile_test.go +++ /dev/null @@ -1,148 +0,0 @@ -package tailfile - -import ( - "io/ioutil" - "os" - "testing" -) - -func TestTailFile(t *testing.T) { - f, err := ioutil.TempFile("", "tail-test") - if err != nil { - t.Fatal(err) - } - defer f.Close() - defer os.RemoveAll(f.Name()) - testFile := []byte(`first line -second line -third line -fourth line -fifth line -next first line -next second line -next third line -next fourth line -next fifth line -last first line -next first line -next second line -next third line -next fourth line -next fifth line -next first line -next second line -next third line -next fourth line -next fifth line -last second line -last third line -last fourth line -last fifth line -truncated line`) - if _, err := f.Write(testFile); err != nil { - t.Fatal(err) - } - if _, err := f.Seek(0, os.SEEK_SET); err != nil { - t.Fatal(err) - } - expected := []string{"last fourth line", "last fifth line"} - res, err := TailFile(f, 2) - if err != nil { - t.Fatal(err) - } - for i, l := range res { - t.Logf("%s", l) - if expected[i] != string(l) { - t.Fatalf("Expected line %s, got %s", expected[i], l) - } - } -} - -func TestTailFileManyLines(t *testing.T) { - f, err := ioutil.TempFile("", "tail-test") - if err != nil { - t.Fatal(err) - } - defer f.Close() - defer os.RemoveAll(f.Name()) - testFile := []byte(`first line -second line -truncated line`) - if _, err := f.Write(testFile); err != nil { - t.Fatal(err) - } - if _, err := f.Seek(0, os.SEEK_SET); err != nil { - t.Fatal(err) - } - expected := []string{"first line", "second line"} - res, err := TailFile(f, 10000) - if err != nil { - t.Fatal(err) - } - for i, l := range res { - t.Logf("%s", l) - if expected[i] != string(l) { - t.Fatalf("Expected line %s, got %s", expected[i], l) - } - } -} - -func TestTailEmptyFile(t *testing.T) { - f, err := ioutil.TempFile("", "tail-test") - if err != nil { - t.Fatal(err) - } - defer f.Close() - defer os.RemoveAll(f.Name()) - res, err := TailFile(f, 10000) - if err != nil { - t.Fatal(err) - } - if len(res) != 0 { - t.Fatal("Must be empty slice from empty file") - } -} - -func TestTailNegativeN(t *testing.T) { - f, err := ioutil.TempFile("", "tail-test") - if err != nil { - t.Fatal(err) - } - defer f.Close() - defer os.RemoveAll(f.Name()) - testFile := []byte(`first line -second line -truncated line`) - if _, err := f.Write(testFile); err != nil { - t.Fatal(err) - } - if _, err := f.Seek(0, os.SEEK_SET); err != nil { - t.Fatal(err) - } - if _, err := TailFile(f, -1); err != ErrNonPositiveLinesNumber { - t.Fatalf("Expected ErrNonPositiveLinesNumber, got %s", err) - } - if _, err := TailFile(f, 0); err != ErrNonPositiveLinesNumber { - t.Fatalf("Expected ErrNonPositiveLinesNumber, got %s", err) - } -} - -func BenchmarkTail(b *testing.B) { - f, err := ioutil.TempFile("", "tail-test") - if err != nil { - b.Fatal(err) - } - defer f.Close() - defer os.RemoveAll(f.Name()) - for i := 0; i < 10000; i++ { - if _, err := f.Write([]byte("tailfile pretty interesting line\n")); err != nil { - b.Fatal(err) - } - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - if _, err := TailFile(f, 1000); err != nil { - b.Fatal(err) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/tarsum/builder_context.go b/vendor/github.com/docker/docker/pkg/tarsum/builder_context.go deleted file mode 100644 index b42983e..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/builder_context.go +++ /dev/null @@ -1,21 +0,0 @@ -package tarsum - -// BuilderContext is an interface extending TarSum by adding the Remove method. -// In general there was concern about adding this method to TarSum itself -// so instead it is being added just to "BuilderContext" which will then -// only be used during the .dockerignore file processing -// - see builder/evaluator.go -type BuilderContext interface { - TarSum - Remove(string) -} - -func (bc *tarSum) Remove(filename string) { - for i, fis := range bc.sums { - if fis.Name() == filename { - bc.sums = append(bc.sums[:i], bc.sums[i+1:]...) - // Note, we don't just return because there could be - // more than one with this name - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/tarsum/builder_context_test.go b/vendor/github.com/docker/docker/pkg/tarsum/builder_context_test.go deleted file mode 100644 index f54bf3a..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/builder_context_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package tarsum - -import ( - "io" - "io/ioutil" - "os" - "testing" -) - -// Try to remove tarsum (in the BuilderContext) that do not exists, won't change a thing -func TestTarSumRemoveNonExistent(t *testing.T) { - filename := "testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar" - reader, err := os.Open(filename) - if err != nil { - t.Fatal(err) - } - defer reader.Close() - - ts, err := NewTarSum(reader, false, Version0) - if err != nil { - t.Fatal(err) - } - - // Read and discard bytes so that it populates sums - _, err = io.Copy(ioutil.Discard, ts) - if err != nil { - t.Errorf("failed to read from %s: %s", filename, err) - } - - expected := len(ts.GetSums()) - - ts.(BuilderContext).Remove("") - ts.(BuilderContext).Remove("Anything") - - if len(ts.GetSums()) != expected { - t.Fatalf("Expected %v sums, go %v.", expected, ts.GetSums()) - } -} - -// Remove a tarsum (in the BuilderContext) -func TestTarSumRemove(t *testing.T) { - filename := "testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar" - reader, err := os.Open(filename) - if err != nil { - t.Fatal(err) - } - defer reader.Close() - - ts, err := NewTarSum(reader, false, Version0) - if err != nil { - t.Fatal(err) - } - - // Read and discard bytes so that it populates sums - _, err = io.Copy(ioutil.Discard, ts) - if err != nil { - t.Errorf("failed to read from %s: %s", filename, err) - } - - expected := len(ts.GetSums()) - 1 - - ts.(BuilderContext).Remove("etc/sudoers") - - if len(ts.GetSums()) != expected { - t.Fatalf("Expected %v sums, go %v.", expected, len(ts.GetSums())) - } -} diff --git a/vendor/github.com/docker/docker/pkg/tarsum/fileinfosums.go b/vendor/github.com/docker/docker/pkg/tarsum/fileinfosums.go deleted file mode 100644 index 5abf5e7..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/fileinfosums.go +++ /dev/null @@ -1,126 +0,0 @@ -package tarsum - -import "sort" - -// FileInfoSumInterface provides an interface for accessing file checksum -// information within a tar file. This info is accessed through interface -// so the actual name and sum cannot be melded with. -type FileInfoSumInterface interface { - // File name - Name() string - // Checksum of this particular file and its headers - Sum() string - // Position of file in the tar - Pos() int64 -} - -type fileInfoSum struct { - name string - sum string - pos int64 -} - -func (fis fileInfoSum) Name() string { - return fis.name -} -func (fis fileInfoSum) Sum() string { - return fis.sum -} -func (fis fileInfoSum) Pos() int64 { - return fis.pos -} - -// FileInfoSums provides a list of FileInfoSumInterfaces. -type FileInfoSums []FileInfoSumInterface - -// GetFile returns the first FileInfoSumInterface with a matching name. -func (fis FileInfoSums) GetFile(name string) FileInfoSumInterface { - for i := range fis { - if fis[i].Name() == name { - return fis[i] - } - } - return nil -} - -// GetAllFile returns a FileInfoSums with all matching names. -func (fis FileInfoSums) GetAllFile(name string) FileInfoSums { - f := FileInfoSums{} - for i := range fis { - if fis[i].Name() == name { - f = append(f, fis[i]) - } - } - return f -} - -// GetDuplicatePaths returns a FileInfoSums with all duplicated paths. -func (fis FileInfoSums) GetDuplicatePaths() (dups FileInfoSums) { - seen := make(map[string]int, len(fis)) // allocate earl. no need to grow this map. - for i := range fis { - f := fis[i] - if _, ok := seen[f.Name()]; ok { - dups = append(dups, f) - } else { - seen[f.Name()] = 0 - } - } - return dups -} - -// Len returns the size of the FileInfoSums. -func (fis FileInfoSums) Len() int { return len(fis) } - -// Swap swaps two FileInfoSum values if a FileInfoSums list. -func (fis FileInfoSums) Swap(i, j int) { fis[i], fis[j] = fis[j], fis[i] } - -// SortByPos sorts FileInfoSums content by position. -func (fis FileInfoSums) SortByPos() { - sort.Sort(byPos{fis}) -} - -// SortByNames sorts FileInfoSums content by name. -func (fis FileInfoSums) SortByNames() { - sort.Sort(byName{fis}) -} - -// SortBySums sorts FileInfoSums content by sums. -func (fis FileInfoSums) SortBySums() { - dups := fis.GetDuplicatePaths() - if len(dups) > 0 { - sort.Sort(bySum{fis, dups}) - } else { - sort.Sort(bySum{fis, nil}) - } -} - -// byName is a sort.Sort helper for sorting by file names. -// If names are the same, order them by their appearance in the tar archive -type byName struct{ FileInfoSums } - -func (bn byName) Less(i, j int) bool { - if bn.FileInfoSums[i].Name() == bn.FileInfoSums[j].Name() { - return bn.FileInfoSums[i].Pos() < bn.FileInfoSums[j].Pos() - } - return bn.FileInfoSums[i].Name() < bn.FileInfoSums[j].Name() -} - -// bySum is a sort.Sort helper for sorting by the sums of all the fileinfos in the tar archive -type bySum struct { - FileInfoSums - dups FileInfoSums -} - -func (bs bySum) Less(i, j int) bool { - if bs.dups != nil && bs.FileInfoSums[i].Name() == bs.FileInfoSums[j].Name() { - return bs.FileInfoSums[i].Pos() < bs.FileInfoSums[j].Pos() - } - return bs.FileInfoSums[i].Sum() < bs.FileInfoSums[j].Sum() -} - -// byPos is a sort.Sort helper for sorting by the sums of all the fileinfos by their original order -type byPos struct{ FileInfoSums } - -func (bp byPos) Less(i, j int) bool { - return bp.FileInfoSums[i].Pos() < bp.FileInfoSums[j].Pos() -} diff --git a/vendor/github.com/docker/docker/pkg/tarsum/fileinfosums_test.go b/vendor/github.com/docker/docker/pkg/tarsum/fileinfosums_test.go deleted file mode 100644 index bb700d8..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/fileinfosums_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package tarsum - -import "testing" - -func newFileInfoSums() FileInfoSums { - return FileInfoSums{ - fileInfoSum{name: "file3", sum: "2abcdef1234567890", pos: 2}, - fileInfoSum{name: "dup1", sum: "deadbeef1", pos: 5}, - fileInfoSum{name: "file1", sum: "0abcdef1234567890", pos: 0}, - fileInfoSum{name: "file4", sum: "3abcdef1234567890", pos: 3}, - fileInfoSum{name: "dup1", sum: "deadbeef0", pos: 4}, - fileInfoSum{name: "file2", sum: "1abcdef1234567890", pos: 1}, - } -} - -func TestSortFileInfoSums(t *testing.T) { - dups := newFileInfoSums().GetAllFile("dup1") - if len(dups) != 2 { - t.Errorf("expected length 2, got %d", len(dups)) - } - dups.SortByNames() - if dups[0].Pos() != 4 { - t.Errorf("sorted dups should be ordered by position. Expected 4, got %d", dups[0].Pos()) - } - - fis := newFileInfoSums() - expected := "0abcdef1234567890" - fis.SortBySums() - got := fis[0].Sum() - if got != expected { - t.Errorf("Expected %q, got %q", expected, got) - } - - fis = newFileInfoSums() - expected = "dup1" - fis.SortByNames() - gotFis := fis[0] - if gotFis.Name() != expected { - t.Errorf("Expected %q, got %q", expected, gotFis.Name()) - } - // since a duplicate is first, ensure it is ordered first by position too - if gotFis.Pos() != 4 { - t.Errorf("Expected %d, got %d", 4, gotFis.Pos()) - } - - fis = newFileInfoSums() - fis.SortByPos() - if fis[0].Pos() != 0 { - t.Errorf("sorted fileInfoSums by Pos should order them by position.") - } - - fis = newFileInfoSums() - expected = "deadbeef1" - gotFileInfoSum := fis.GetFile("dup1") - if gotFileInfoSum.Sum() != expected { - t.Errorf("Expected %q, got %q", expected, gotFileInfoSum) - } - if fis.GetFile("noPresent") != nil { - t.Errorf("Should have return nil if name not found.") - } - -} diff --git a/vendor/github.com/docker/docker/pkg/tarsum/tarsum.go b/vendor/github.com/docker/docker/pkg/tarsum/tarsum.go deleted file mode 100644 index 154788d..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/tarsum.go +++ /dev/null @@ -1,295 +0,0 @@ -// Package tarsum provides algorithms to perform checksum calculation on -// filesystem layers. -// -// The transportation of filesystems, regarding Docker, is done with tar(1) -// archives. There are a variety of tar serialization formats [2], and a key -// concern here is ensuring a repeatable checksum given a set of inputs from a -// generic tar archive. Types of transportation include distribution to and from a -// registry endpoint, saving and loading through commands or Docker daemon APIs, -// transferring the build context from client to Docker daemon, and committing the -// filesystem of a container to become an image. -// -// As tar archives are used for transit, but not preserved in many situations, the -// focus of the algorithm is to ensure the integrity of the preserved filesystem, -// while maintaining a deterministic accountability. This includes neither -// constraining the ordering or manipulation of the files during the creation or -// unpacking of the archive, nor include additional metadata state about the file -// system attributes. -package tarsum - -import ( - "archive/tar" - "bytes" - "compress/gzip" - "crypto" - "crypto/sha256" - "encoding/hex" - "errors" - "fmt" - "hash" - "io" - "path" - "strings" -) - -const ( - buf8K = 8 * 1024 - buf16K = 16 * 1024 - buf32K = 32 * 1024 -) - -// NewTarSum creates a new interface for calculating a fixed time checksum of a -// tar archive. -// -// This is used for calculating checksums of layers of an image, in some cases -// including the byte payload of the image's json metadata as well, and for -// calculating the checksums for buildcache. -func NewTarSum(r io.Reader, dc bool, v Version) (TarSum, error) { - return NewTarSumHash(r, dc, v, DefaultTHash) -} - -// NewTarSumHash creates a new TarSum, providing a THash to use rather than -// the DefaultTHash. -func NewTarSumHash(r io.Reader, dc bool, v Version, tHash THash) (TarSum, error) { - headerSelector, err := getTarHeaderSelector(v) - if err != nil { - return nil, err - } - ts := &tarSum{Reader: r, DisableCompression: dc, tarSumVersion: v, headerSelector: headerSelector, tHash: tHash} - err = ts.initTarSum() - return ts, err -} - -// NewTarSumForLabel creates a new TarSum using the provided TarSum version+hash label. -func NewTarSumForLabel(r io.Reader, disableCompression bool, label string) (TarSum, error) { - parts := strings.SplitN(label, "+", 2) - if len(parts) != 2 { - return nil, errors.New("tarsum label string should be of the form: {tarsum_version}+{hash_name}") - } - - versionName, hashName := parts[0], parts[1] - - version, ok := tarSumVersionsByName[versionName] - if !ok { - return nil, fmt.Errorf("unknown TarSum version name: %q", versionName) - } - - hashConfig, ok := standardHashConfigs[hashName] - if !ok { - return nil, fmt.Errorf("unknown TarSum hash name: %q", hashName) - } - - tHash := NewTHash(hashConfig.name, hashConfig.hash.New) - - return NewTarSumHash(r, disableCompression, version, tHash) -} - -// TarSum is the generic interface for calculating fixed time -// checksums of a tar archive. -type TarSum interface { - io.Reader - GetSums() FileInfoSums - Sum([]byte) string - Version() Version - Hash() THash -} - -// tarSum struct is the structure for a Version0 checksum calculation. -type tarSum struct { - io.Reader - tarR *tar.Reader - tarW *tar.Writer - writer writeCloseFlusher - bufTar *bytes.Buffer - bufWriter *bytes.Buffer - bufData []byte - h hash.Hash - tHash THash - sums FileInfoSums - fileCounter int64 - currentFile string - finished bool - first bool - DisableCompression bool // false by default. When false, the output gzip compressed. - tarSumVersion Version // this field is not exported so it can not be mutated during use - headerSelector tarHeaderSelector // handles selecting and ordering headers for files in the archive -} - -func (ts tarSum) Hash() THash { - return ts.tHash -} - -func (ts tarSum) Version() Version { - return ts.tarSumVersion -} - -// THash provides a hash.Hash type generator and its name. -type THash interface { - Hash() hash.Hash - Name() string -} - -// NewTHash is a convenience method for creating a THash. -func NewTHash(name string, h func() hash.Hash) THash { - return simpleTHash{n: name, h: h} -} - -type tHashConfig struct { - name string - hash crypto.Hash -} - -var ( - // NOTE: DO NOT include MD5 or SHA1, which are considered insecure. - standardHashConfigs = map[string]tHashConfig{ - "sha256": {name: "sha256", hash: crypto.SHA256}, - "sha512": {name: "sha512", hash: crypto.SHA512}, - } -) - -// DefaultTHash is default TarSum hashing algorithm - "sha256". -var DefaultTHash = NewTHash("sha256", sha256.New) - -type simpleTHash struct { - n string - h func() hash.Hash -} - -func (sth simpleTHash) Name() string { return sth.n } -func (sth simpleTHash) Hash() hash.Hash { return sth.h() } - -func (ts *tarSum) encodeHeader(h *tar.Header) error { - for _, elem := range ts.headerSelector.selectHeaders(h) { - if _, err := ts.h.Write([]byte(elem[0] + elem[1])); err != nil { - return err - } - } - return nil -} - -func (ts *tarSum) initTarSum() error { - ts.bufTar = bytes.NewBuffer([]byte{}) - ts.bufWriter = bytes.NewBuffer([]byte{}) - ts.tarR = tar.NewReader(ts.Reader) - ts.tarW = tar.NewWriter(ts.bufTar) - if !ts.DisableCompression { - ts.writer = gzip.NewWriter(ts.bufWriter) - } else { - ts.writer = &nopCloseFlusher{Writer: ts.bufWriter} - } - if ts.tHash == nil { - ts.tHash = DefaultTHash - } - ts.h = ts.tHash.Hash() - ts.h.Reset() - ts.first = true - ts.sums = FileInfoSums{} - return nil -} - -func (ts *tarSum) Read(buf []byte) (int, error) { - if ts.finished { - return ts.bufWriter.Read(buf) - } - if len(ts.bufData) < len(buf) { - switch { - case len(buf) <= buf8K: - ts.bufData = make([]byte, buf8K) - case len(buf) <= buf16K: - ts.bufData = make([]byte, buf16K) - case len(buf) <= buf32K: - ts.bufData = make([]byte, buf32K) - default: - ts.bufData = make([]byte, len(buf)) - } - } - buf2 := ts.bufData[:len(buf)] - - n, err := ts.tarR.Read(buf2) - if err != nil { - if err == io.EOF { - if _, err := ts.h.Write(buf2[:n]); err != nil { - return 0, err - } - if !ts.first { - ts.sums = append(ts.sums, fileInfoSum{name: ts.currentFile, sum: hex.EncodeToString(ts.h.Sum(nil)), pos: ts.fileCounter}) - ts.fileCounter++ - ts.h.Reset() - } else { - ts.first = false - } - - currentHeader, err := ts.tarR.Next() - if err != nil { - if err == io.EOF { - if err := ts.tarW.Close(); err != nil { - return 0, err - } - if _, err := io.Copy(ts.writer, ts.bufTar); err != nil { - return 0, err - } - if err := ts.writer.Close(); err != nil { - return 0, err - } - ts.finished = true - return n, nil - } - return n, err - } - ts.currentFile = path.Clean(currentHeader.Name) - if err := ts.encodeHeader(currentHeader); err != nil { - return 0, err - } - if err := ts.tarW.WriteHeader(currentHeader); err != nil { - return 0, err - } - if _, err := ts.tarW.Write(buf2[:n]); err != nil { - return 0, err - } - ts.tarW.Flush() - if _, err := io.Copy(ts.writer, ts.bufTar); err != nil { - return 0, err - } - ts.writer.Flush() - - return ts.bufWriter.Read(buf) - } - return n, err - } - - // Filling the hash buffer - if _, err = ts.h.Write(buf2[:n]); err != nil { - return 0, err - } - - // Filling the tar writer - if _, err = ts.tarW.Write(buf2[:n]); err != nil { - return 0, err - } - ts.tarW.Flush() - - // Filling the output writer - if _, err = io.Copy(ts.writer, ts.bufTar); err != nil { - return 0, err - } - ts.writer.Flush() - - return ts.bufWriter.Read(buf) -} - -func (ts *tarSum) Sum(extra []byte) string { - ts.sums.SortBySums() - h := ts.tHash.Hash() - if extra != nil { - h.Write(extra) - } - for _, fis := range ts.sums { - h.Write([]byte(fis.Sum())) - } - checksum := ts.Version().String() + "+" + ts.tHash.Name() + ":" + hex.EncodeToString(h.Sum(nil)) - return checksum -} - -func (ts *tarSum) GetSums() FileInfoSums { - return ts.sums -} diff --git a/vendor/github.com/docker/docker/pkg/tarsum/tarsum_spec.md b/vendor/github.com/docker/docker/pkg/tarsum/tarsum_spec.md deleted file mode 100644 index 89b2e49..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/tarsum_spec.md +++ /dev/null @@ -1,230 +0,0 @@ -page_title: TarSum checksum specification -page_description: Documentation for algorithms used in the TarSum checksum calculation -page_keywords: docker, checksum, validation, tarsum - -# TarSum Checksum Specification - -## Abstract - -This document describes the algorithms used in performing the TarSum checksum -calculation on filesystem layers, the need for this method over existing -methods, and the versioning of this calculation. - -## Warning - -This checksum algorithm is for best-effort comparison of file trees with fuzzy logic. - -This is _not_ a cryptographic attestation, and should not be considered secure. - -## Introduction - -The transportation of filesystems, regarding Docker, is done with tar(1) -archives. There are a variety of tar serialization formats [2], and a key -concern here is ensuring a repeatable checksum given a set of inputs from a -generic tar archive. Types of transportation include distribution to and from a -registry endpoint, saving and loading through commands or Docker daemon APIs, -transferring the build context from client to Docker daemon, and committing the -filesystem of a container to become an image. - -As tar archives are used for transit, but not preserved in many situations, the -focus of the algorithm is to ensure the integrity of the preserved filesystem, -while maintaining a deterministic accountability. This includes neither -constraining the ordering or manipulation of the files during the creation or -unpacking of the archive, nor include additional metadata state about the file -system attributes. - -## Intended Audience - -This document is outlining the methods used for consistent checksum calculation -for filesystems transported via tar archives. - -Auditing these methodologies is an open and iterative process. This document -should accommodate the review of source code. Ultimately, this document should -be the starting point of further refinements to the algorithm and its future -versions. - -## Concept - -The checksum mechanism must ensure the integrity and assurance of the -filesystem payload. - -## Checksum Algorithm Profile - -A checksum mechanism must define the following operations and attributes: - -* Associated hashing cipher - used to checksum each file payload and attribute - information. -* Checksum list - each file of the filesystem archive has its checksum - calculated from the payload and attributes of the file. The final checksum is - calculated from this list, with specific ordering. -* Version - as the algorithm adapts to requirements, there are behaviors of the - algorithm to manage by versioning. -* Archive being calculated - the tar archive having its checksum calculated - -## Elements of TarSum checksum - -The calculated sum output is a text string. The elements included in the output -of the calculated sum comprise the information needed for validation of the sum -(TarSum version and hashing cipher used) and the expected checksum in hexadecimal -form. - -There are two delimiters used: -* '+' separates TarSum version from hashing cipher -* ':' separates calculation mechanics from expected hash - -Example: - -``` - "tarsum.v1+sha256:220a60ecd4a3c32c282622a625a54db9ba0ff55b5ba9c29c7064a2bc358b6a3e" - | | \ | - | | \ | - |_version_|_cipher__|__ | - | \ | - |_calculation_mechanics_|______________________expected_sum_______________________| -``` - -## Versioning - -Versioning was introduced [0] to accommodate differences in calculation needed, -and ability to maintain reverse compatibility. - -The general algorithm will be describe further in the 'Calculation'. - -### Version0 - -This is the initial version of TarSum. - -Its element in the TarSum checksum string is `tarsum`. - -### Version1 - -Its element in the TarSum checksum is `tarsum.v1`. - -The notable changes in this version: -* Exclusion of file `mtime` from the file information headers, in each file - checksum calculation -* Inclusion of extended attributes (`xattrs`. Also seen as `SCHILY.xattr.` prefixed Pax - tar file info headers) keys and values in each file checksum calculation - -### VersionDev - -*Do not use unless validating refinements to the checksum algorithm* - -Its element in the TarSum checksum is `tarsum.dev`. - -This is a floating place holder for a next version and grounds for testing -changes. The methods used for calculation are subject to change without notice, -and this version is for testing and not for production use. - -## Ciphers - -The official default and standard hashing cipher used in the calculation mechanic -is `sha256`. This refers to SHA256 hash algorithm as defined in FIPS 180-4. - -Though the TarSum algorithm itself is not exclusively bound to the single -hashing cipher `sha256`, support for alternate hashing ciphers was later added -[1]. Use cases for alternate cipher could include future-proofing TarSum -checksum format and using faster cipher hashes for tar filesystem checksums. - -## Calculation - -### Requirement - -As mentioned earlier, the calculation is such that it takes into consideration -the lifecycle of the tar archive. In that the tar archive is not an immutable, -permanent artifact. Otherwise options like relying on a known hashing cipher -checksum of the archive itself would be reliable enough. The tar archive of the -filesystem is used as a transportation medium for Docker images, and the -archive is discarded once its contents are extracted. Therefore, for consistent -validation items such as order of files in the tar archive and time stamps are -subject to change once an image is received. - -### Process - -The method is typically iterative due to reading tar info headers from the -archive stream, though this is not a strict requirement. - -#### Files - -Each file in the tar archive have their contents (headers and body) checksummed -individually using the designated associated hashing cipher. The ordered -headers of the file are written to the checksum calculation first, and then the -payload of the file body. - -The resulting checksum of the file is appended to the list of file sums. The -sum is encoded as a string of the hexadecimal digest. Additionally, the file -name and position in the archive is kept as reference for special ordering. - -#### Headers - -The following headers are read, in this -order ( and the corresponding representation of its value): -* 'name' - string -* 'mode' - string of the base10 integer -* 'uid' - string of the integer -* 'gid' - string of the integer -* 'size' - string of the integer -* 'mtime' (_Version0 only_) - string of integer of the seconds since 1970-01-01 00:00:00 UTC -* 'typeflag' - string of the char -* 'linkname' - string -* 'uname' - string -* 'gname' - string -* 'devmajor' - string of the integer -* 'devminor' - string of the integer - -For >= Version1, the extended attribute headers ("SCHILY.xattr." prefixed pax -headers) included after the above list. These xattrs key/values are first -sorted by the keys. - -#### Header Format - -The ordered headers are written to the hash in the format of - - "{.key}{.value}" - -with no newline. - -#### Body - -After the order headers of the file have been added to the checksum for the -file, the body of the file is written to the hash. - -#### List of file sums - -The list of file sums is sorted by the string of the hexadecimal digest. - -If there are two files in the tar with matching paths, the order of occurrence -for that path is reflected for the sums of the corresponding file header and -body. - -#### Final Checksum - -Begin with a fresh or initial state of the associated hash cipher. If there is -additional payload to include in the TarSum calculation for the archive, it is -written first. Then each checksum from the ordered list of file sums is written -to the hash. - -The resulting digest is formatted per the Elements of TarSum checksum, -including the TarSum version, the associated hash cipher and the hexadecimal -encoded checksum digest. - -## Security Considerations - -The initial version of TarSum has undergone one update that could invalidate -handcrafted tar archives. The tar archive format supports appending of files -with same names as prior files in the archive. The latter file will clobber the -prior file of the same path. Due to this the algorithm now accounts for files -with matching paths, and orders the list of file sums accordingly [3]. - -## Footnotes - -* [0] Versioning https://github.com/docker/docker/commit/747f89cd327db9d50251b17797c4d825162226d0 -* [1] Alternate ciphers https://github.com/docker/docker/commit/4e9925d780665149b8bc940d5ba242ada1973c4e -* [2] Tar http://en.wikipedia.org/wiki/Tar_%28computing%29 -* [3] Name collision https://github.com/docker/docker/commit/c5e6362c53cbbc09ddbabd5a7323e04438b57d31 - -## Acknowledgments - -Joffrey F (shin-) and Guillaume J. Charmes (creack) on the initial work of the -TarSum calculation. - diff --git a/vendor/github.com/docker/docker/pkg/tarsum/tarsum_test.go b/vendor/github.com/docker/docker/pkg/tarsum/tarsum_test.go deleted file mode 100644 index 86df0e2..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/tarsum_test.go +++ /dev/null @@ -1,664 +0,0 @@ -package tarsum - -import ( - "archive/tar" - "bytes" - "compress/gzip" - "crypto/md5" - "crypto/rand" - "crypto/sha1" - "crypto/sha256" - "crypto/sha512" - "encoding/hex" - "fmt" - "io" - "io/ioutil" - "os" - "strings" - "testing" -) - -type testLayer struct { - filename string - options *sizedOptions - jsonfile string - gzip bool - tarsum string - version Version - hash THash -} - -var testLayers = []testLayer{ - { - filename: "testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar", - jsonfile: "testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/json", - version: Version0, - tarsum: "tarsum+sha256:4095cc12fa5fdb1ab2760377e1cd0c4ecdd3e61b4f9b82319d96fcea6c9a41c6"}, - { - filename: "testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar", - jsonfile: "testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/json", - version: VersionDev, - tarsum: "tarsum.dev+sha256:db56e35eec6ce65ba1588c20ba6b1ea23743b59e81fb6b7f358ccbde5580345c"}, - { - filename: "testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar", - jsonfile: "testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/json", - gzip: true, - tarsum: "tarsum+sha256:4095cc12fa5fdb1ab2760377e1cd0c4ecdd3e61b4f9b82319d96fcea6c9a41c6"}, - { - // Tests existing version of TarSum when xattrs are present - filename: "testdata/xattr/layer.tar", - jsonfile: "testdata/xattr/json", - version: Version0, - tarsum: "tarsum+sha256:07e304a8dbcb215b37649fde1a699f8aeea47e60815707f1cdf4d55d25ff6ab4"}, - { - // Tests next version of TarSum when xattrs are present - filename: "testdata/xattr/layer.tar", - jsonfile: "testdata/xattr/json", - version: VersionDev, - tarsum: "tarsum.dev+sha256:6c58917892d77b3b357b0f9ad1e28e1f4ae4de3a8006bd3beb8beda214d8fd16"}, - { - filename: "testdata/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer.tar", - jsonfile: "testdata/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json", - tarsum: "tarsum+sha256:c66bd5ec9f87b8f4c6135ca37684618f486a3dd1d113b138d0a177bfa39c2571"}, - { - options: &sizedOptions{1, 1024 * 1024, false, false}, // a 1mb file (in memory) - tarsum: "tarsum+sha256:8bf12d7e67c51ee2e8306cba569398b1b9f419969521a12ffb9d8875e8836738"}, - { - // this tar has two files with the same path - filename: "testdata/collision/collision-0.tar", - tarsum: "tarsum+sha256:08653904a68d3ab5c59e65ef58c49c1581caa3c34744f8d354b3f575ea04424a"}, - { - // this tar has the same two files (with the same path), but reversed order. ensuring is has different hash than above - filename: "testdata/collision/collision-1.tar", - tarsum: "tarsum+sha256:b51c13fbefe158b5ce420d2b930eef54c5cd55c50a2ee4abdddea8fa9f081e0d"}, - { - // this tar has newer of collider-0.tar, ensuring is has different hash - filename: "testdata/collision/collision-2.tar", - tarsum: "tarsum+sha256:381547080919bb82691e995508ae20ed33ce0f6948d41cafbeb70ce20c73ee8e"}, - { - // this tar has newer of collider-1.tar, ensuring is has different hash - filename: "testdata/collision/collision-3.tar", - tarsum: "tarsum+sha256:f886e431c08143164a676805205979cd8fa535dfcef714db5515650eea5a7c0f"}, - { - options: &sizedOptions{1, 1024 * 1024, false, false}, // a 1mb file (in memory) - tarsum: "tarsum+md5:0d7529ec7a8360155b48134b8e599f53", - hash: md5THash, - }, - { - options: &sizedOptions{1, 1024 * 1024, false, false}, // a 1mb file (in memory) - tarsum: "tarsum+sha1:f1fee39c5925807ff75ef1925e7a23be444ba4df", - hash: sha1Hash, - }, - { - options: &sizedOptions{1, 1024 * 1024, false, false}, // a 1mb file (in memory) - tarsum: "tarsum+sha224:6319390c0b061d639085d8748b14cd55f697cf9313805218b21cf61c", - hash: sha224Hash, - }, - { - options: &sizedOptions{1, 1024 * 1024, false, false}, // a 1mb file (in memory) - tarsum: "tarsum+sha384:a578ce3ce29a2ae03b8ed7c26f47d0f75b4fc849557c62454be4b5ffd66ba021e713b48ce71e947b43aab57afd5a7636", - hash: sha384Hash, - }, - { - options: &sizedOptions{1, 1024 * 1024, false, false}, // a 1mb file (in memory) - tarsum: "tarsum+sha512:e9bfb90ca5a4dfc93c46ee061a5cf9837de6d2fdf82544d6460d3147290aecfabf7b5e415b9b6e72db9b8941f149d5d69fb17a394cbfaf2eac523bd9eae21855", - hash: sha512Hash, - }, -} - -type sizedOptions struct { - num int64 - size int64 - isRand bool - realFile bool -} - -// make a tar: -// * num is the number of files the tar should have -// * size is the bytes per file -// * isRand is whether the contents of the files should be a random chunk (otherwise it's all zeros) -// * realFile will write to a TempFile, instead of an in memory buffer -func sizedTar(opts sizedOptions) io.Reader { - var ( - fh io.ReadWriter - err error - ) - if opts.realFile { - fh, err = ioutil.TempFile("", "tarsum") - if err != nil { - return nil - } - } else { - fh = bytes.NewBuffer([]byte{}) - } - tarW := tar.NewWriter(fh) - defer tarW.Close() - for i := int64(0); i < opts.num; i++ { - err := tarW.WriteHeader(&tar.Header{ - Name: fmt.Sprintf("/testdata%d", i), - Mode: 0755, - Uid: 0, - Gid: 0, - Size: opts.size, - }) - if err != nil { - return nil - } - var rBuf []byte - if opts.isRand { - rBuf = make([]byte, 8) - _, err = rand.Read(rBuf) - if err != nil { - return nil - } - } else { - rBuf = []byte{0, 0, 0, 0, 0, 0, 0, 0} - } - - for i := int64(0); i < opts.size/int64(8); i++ { - tarW.Write(rBuf) - } - } - return fh -} - -func emptyTarSum(gzip bool) (TarSum, error) { - reader, writer := io.Pipe() - tarWriter := tar.NewWriter(writer) - - // Immediately close tarWriter and write-end of the - // Pipe in a separate goroutine so we don't block. - go func() { - tarWriter.Close() - writer.Close() - }() - - return NewTarSum(reader, !gzip, Version0) -} - -// Test errors on NewTarsumForLabel -func TestNewTarSumForLabelInvalid(t *testing.T) { - reader := strings.NewReader("") - - if _, err := NewTarSumForLabel(reader, true, "invalidlabel"); err == nil { - t.Fatalf("Expected an error, got nothing.") - } - - if _, err := NewTarSumForLabel(reader, true, "invalid+sha256"); err == nil { - t.Fatalf("Expected an error, got nothing.") - } - if _, err := NewTarSumForLabel(reader, true, "tarsum.v1+invalid"); err == nil { - t.Fatalf("Expected an error, got nothing.") - } -} - -func TestNewTarSumForLabel(t *testing.T) { - - layer := testLayers[0] - - reader, err := os.Open(layer.filename) - if err != nil { - t.Fatal(err) - } - defer reader.Close() - - label := strings.Split(layer.tarsum, ":")[0] - ts, err := NewTarSumForLabel(reader, false, label) - if err != nil { - t.Fatal(err) - } - - // Make sure it actually worked by reading a little bit of it - nbByteToRead := 8 * 1024 - dBuf := make([]byte, nbByteToRead) - _, err = ts.Read(dBuf) - if err != nil { - t.Errorf("failed to read %vKB from %s: %s", nbByteToRead, layer.filename, err) - } -} - -// TestEmptyTar tests that tarsum does not fail to read an empty tar -// and correctly returns the hex digest of an empty hash. -func TestEmptyTar(t *testing.T) { - // Test without gzip. - ts, err := emptyTarSum(false) - if err != nil { - t.Fatal(err) - } - - zeroBlock := make([]byte, 1024) - buf := new(bytes.Buffer) - - n, err := io.Copy(buf, ts) - if err != nil { - t.Fatal(err) - } - - if n != int64(len(zeroBlock)) || !bytes.Equal(buf.Bytes(), zeroBlock) { - t.Fatalf("tarSum did not write the correct number of zeroed bytes: %d", n) - } - - expectedSum := ts.Version().String() + "+sha256:" + hex.EncodeToString(sha256.New().Sum(nil)) - resultSum := ts.Sum(nil) - - if resultSum != expectedSum { - t.Fatalf("expected [%s] but got [%s]", expectedSum, resultSum) - } - - // Test with gzip. - ts, err = emptyTarSum(true) - if err != nil { - t.Fatal(err) - } - buf.Reset() - - n, err = io.Copy(buf, ts) - if err != nil { - t.Fatal(err) - } - - bufgz := new(bytes.Buffer) - gz := gzip.NewWriter(bufgz) - n, err = io.Copy(gz, bytes.NewBuffer(zeroBlock)) - gz.Close() - gzBytes := bufgz.Bytes() - - if n != int64(len(zeroBlock)) || !bytes.Equal(buf.Bytes(), gzBytes) { - t.Fatalf("tarSum did not write the correct number of gzipped-zeroed bytes: %d", n) - } - - resultSum = ts.Sum(nil) - - if resultSum != expectedSum { - t.Fatalf("expected [%s] but got [%s]", expectedSum, resultSum) - } - - // Test without ever actually writing anything. - if ts, err = NewTarSum(bytes.NewReader([]byte{}), true, Version0); err != nil { - t.Fatal(err) - } - - resultSum = ts.Sum(nil) - - if resultSum != expectedSum { - t.Fatalf("expected [%s] but got [%s]", expectedSum, resultSum) - } -} - -var ( - md5THash = NewTHash("md5", md5.New) - sha1Hash = NewTHash("sha1", sha1.New) - sha224Hash = NewTHash("sha224", sha256.New224) - sha384Hash = NewTHash("sha384", sha512.New384) - sha512Hash = NewTHash("sha512", sha512.New) -) - -// Test all the build-in read size : buf8K, buf16K, buf32K and more -func TestTarSumsReadSize(t *testing.T) { - // Test always on the same layer (that is big enough) - layer := testLayers[0] - - for i := 0; i < 5; i++ { - - reader, err := os.Open(layer.filename) - if err != nil { - t.Fatal(err) - } - defer reader.Close() - - ts, err := NewTarSum(reader, false, layer.version) - if err != nil { - t.Fatal(err) - } - - // Read and discard bytes so that it populates sums - nbByteToRead := (i + 1) * 8 * 1024 - dBuf := make([]byte, nbByteToRead) - _, err = ts.Read(dBuf) - if err != nil { - t.Errorf("failed to read %vKB from %s: %s", nbByteToRead, layer.filename, err) - continue - } - } -} - -func TestTarSums(t *testing.T) { - for _, layer := range testLayers { - var ( - fh io.Reader - err error - ) - if len(layer.filename) > 0 { - fh, err = os.Open(layer.filename) - if err != nil { - t.Errorf("failed to open %s: %s", layer.filename, err) - continue - } - } else if layer.options != nil { - fh = sizedTar(*layer.options) - } else { - // What else is there to test? - t.Errorf("what to do with %#v", layer) - continue - } - if file, ok := fh.(*os.File); ok { - defer file.Close() - } - - var ts TarSum - if layer.hash == nil { - // double negatives! - ts, err = NewTarSum(fh, !layer.gzip, layer.version) - } else { - ts, err = NewTarSumHash(fh, !layer.gzip, layer.version, layer.hash) - } - if err != nil { - t.Errorf("%q :: %q", err, layer.filename) - continue - } - - // Read variable number of bytes to test dynamic buffer - dBuf := make([]byte, 1) - _, err = ts.Read(dBuf) - if err != nil { - t.Errorf("failed to read 1B from %s: %s", layer.filename, err) - continue - } - dBuf = make([]byte, 16*1024) - _, err = ts.Read(dBuf) - if err != nil { - t.Errorf("failed to read 16KB from %s: %s", layer.filename, err) - continue - } - - // Read and discard remaining bytes - _, err = io.Copy(ioutil.Discard, ts) - if err != nil { - t.Errorf("failed to copy from %s: %s", layer.filename, err) - continue - } - var gotSum string - if len(layer.jsonfile) > 0 { - jfh, err := os.Open(layer.jsonfile) - if err != nil { - t.Errorf("failed to open %s: %s", layer.jsonfile, err) - continue - } - defer jfh.Close() - - buf, err := ioutil.ReadAll(jfh) - if err != nil { - t.Errorf("failed to readAll %s: %s", layer.jsonfile, err) - continue - } - gotSum = ts.Sum(buf) - } else { - gotSum = ts.Sum(nil) - } - - if layer.tarsum != gotSum { - t.Errorf("expecting [%s], but got [%s]", layer.tarsum, gotSum) - } - var expectedHashName string - if layer.hash != nil { - expectedHashName = layer.hash.Name() - } else { - expectedHashName = DefaultTHash.Name() - } - if expectedHashName != ts.Hash().Name() { - t.Errorf("expecting hash [%v], but got [%s]", expectedHashName, ts.Hash().Name()) - } - } -} - -func TestIteration(t *testing.T) { - headerTests := []struct { - expectedSum string // TODO(vbatts) it would be nice to get individual sums of each - version Version - hdr *tar.Header - data []byte - }{ - { - "tarsum+sha256:626c4a2e9a467d65c33ae81f7f3dedd4de8ccaee72af73223c4bc4718cbc7bbd", - Version0, - &tar.Header{ - Name: "file.txt", - Size: 0, - Typeflag: tar.TypeReg, - Devminor: 0, - Devmajor: 0, - }, - []byte(""), - }, - { - "tarsum.dev+sha256:6ffd43a1573a9913325b4918e124ee982a99c0f3cba90fc032a65f5e20bdd465", - VersionDev, - &tar.Header{ - Name: "file.txt", - Size: 0, - Typeflag: tar.TypeReg, - Devminor: 0, - Devmajor: 0, - }, - []byte(""), - }, - { - "tarsum.dev+sha256:b38166c059e11fb77bef30bf16fba7584446e80fcc156ff46d47e36c5305d8ef", - VersionDev, - &tar.Header{ - Name: "another.txt", - Uid: 1000, - Gid: 1000, - Uname: "slartibartfast", - Gname: "users", - Size: 4, - Typeflag: tar.TypeReg, - Devminor: 0, - Devmajor: 0, - }, - []byte("test"), - }, - { - "tarsum.dev+sha256:4cc2e71ac5d31833ab2be9b4f7842a14ce595ec96a37af4ed08f87bc374228cd", - VersionDev, - &tar.Header{ - Name: "xattrs.txt", - Uid: 1000, - Gid: 1000, - Uname: "slartibartfast", - Gname: "users", - Size: 4, - Typeflag: tar.TypeReg, - Xattrs: map[string]string{ - "user.key1": "value1", - "user.key2": "value2", - }, - }, - []byte("test"), - }, - { - "tarsum.dev+sha256:65f4284fa32c0d4112dd93c3637697805866415b570587e4fd266af241503760", - VersionDev, - &tar.Header{ - Name: "xattrs.txt", - Uid: 1000, - Gid: 1000, - Uname: "slartibartfast", - Gname: "users", - Size: 4, - Typeflag: tar.TypeReg, - Xattrs: map[string]string{ - "user.KEY1": "value1", // adding different case to ensure different sum - "user.key2": "value2", - }, - }, - []byte("test"), - }, - { - "tarsum+sha256:c12bb6f1303a9ddbf4576c52da74973c00d14c109bcfa76b708d5da1154a07fa", - Version0, - &tar.Header{ - Name: "xattrs.txt", - Uid: 1000, - Gid: 1000, - Uname: "slartibartfast", - Gname: "users", - Size: 4, - Typeflag: tar.TypeReg, - Xattrs: map[string]string{ - "user.NOT": "CALCULATED", - }, - }, - []byte("test"), - }, - } - for _, htest := range headerTests { - s, err := renderSumForHeader(htest.version, htest.hdr, htest.data) - if err != nil { - t.Fatal(err) - } - - if s != htest.expectedSum { - t.Errorf("expected sum: %q, got: %q", htest.expectedSum, s) - } - } - -} - -func renderSumForHeader(v Version, h *tar.Header, data []byte) (string, error) { - buf := bytes.NewBuffer(nil) - // first build our test tar - tw := tar.NewWriter(buf) - if err := tw.WriteHeader(h); err != nil { - return "", err - } - if _, err := tw.Write(data); err != nil { - return "", err - } - tw.Close() - - ts, err := NewTarSum(buf, true, v) - if err != nil { - return "", err - } - tr := tar.NewReader(ts) - for { - hdr, err := tr.Next() - if hdr == nil || err == io.EOF { - // Signals the end of the archive. - break - } - if err != nil { - return "", err - } - if _, err = io.Copy(ioutil.Discard, tr); err != nil { - return "", err - } - } - return ts.Sum(nil), nil -} - -func Benchmark9kTar(b *testing.B) { - buf := bytes.NewBuffer([]byte{}) - fh, err := os.Open("testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar") - if err != nil { - b.Error(err) - return - } - defer fh.Close() - - n, err := io.Copy(buf, fh) - if err != nil { - b.Error(err) - return - } - - reader := bytes.NewReader(buf.Bytes()) - - b.SetBytes(n) - b.ResetTimer() - for i := 0; i < b.N; i++ { - reader.Seek(0, 0) - ts, err := NewTarSum(reader, true, Version0) - if err != nil { - b.Error(err) - return - } - io.Copy(ioutil.Discard, ts) - ts.Sum(nil) - } -} - -func Benchmark9kTarGzip(b *testing.B) { - buf := bytes.NewBuffer([]byte{}) - fh, err := os.Open("testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar") - if err != nil { - b.Error(err) - return - } - defer fh.Close() - - n, err := io.Copy(buf, fh) - if err != nil { - b.Error(err) - return - } - - reader := bytes.NewReader(buf.Bytes()) - - b.SetBytes(n) - b.ResetTimer() - for i := 0; i < b.N; i++ { - reader.Seek(0, 0) - ts, err := NewTarSum(reader, false, Version0) - if err != nil { - b.Error(err) - return - } - io.Copy(ioutil.Discard, ts) - ts.Sum(nil) - } -} - -// this is a single big file in the tar archive -func Benchmark1mbSingleFileTar(b *testing.B) { - benchmarkTar(b, sizedOptions{1, 1024 * 1024, true, true}, false) -} - -// this is a single big file in the tar archive -func Benchmark1mbSingleFileTarGzip(b *testing.B) { - benchmarkTar(b, sizedOptions{1, 1024 * 1024, true, true}, true) -} - -// this is 1024 1k files in the tar archive -func Benchmark1kFilesTar(b *testing.B) { - benchmarkTar(b, sizedOptions{1024, 1024, true, true}, false) -} - -// this is 1024 1k files in the tar archive -func Benchmark1kFilesTarGzip(b *testing.B) { - benchmarkTar(b, sizedOptions{1024, 1024, true, true}, true) -} - -func benchmarkTar(b *testing.B, opts sizedOptions, isGzip bool) { - var fh *os.File - tarReader := sizedTar(opts) - if br, ok := tarReader.(*os.File); ok { - fh = br - } - defer os.Remove(fh.Name()) - defer fh.Close() - - b.SetBytes(opts.size * opts.num) - b.ResetTimer() - for i := 0; i < b.N; i++ { - ts, err := NewTarSum(fh, !isGzip, Version0) - if err != nil { - b.Error(err) - return - } - io.Copy(ioutil.Discard, ts) - ts.Sum(nil) - fh.Seek(0, 0) - } -} diff --git a/vendor/github.com/docker/docker/pkg/tarsum/testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/json b/vendor/github.com/docker/docker/pkg/tarsum/testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/json deleted file mode 100644 index 48e2af3..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/json +++ /dev/null @@ -1 +0,0 @@ -{"id":"46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457","parent":"def3f9165934325dfd027c86530b2ea49bb57a0963eb1336b3a0415ff6fd56de","created":"2014-04-07T02:45:52.610504484Z","container":"e0f07f8d72cae171a3dcc35859960e7e956e0628bce6fedc4122bf55b2c287c7","container_config":{"Hostname":"88807319f25e","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":null,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["HOME=/","PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh","-c","sed -ri 's/^(%wheel.*)(ALL)$/\\1NOPASSWD: \\2/' /etc/sudoers"],"Image":"def3f9165934325dfd027c86530b2ea49bb57a0963eb1336b3a0415ff6fd56de","Volumes":null,"WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"OnBuild":[]},"docker_version":"0.9.1-dev","config":{"Hostname":"88807319f25e","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":null,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["HOME=/","PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":null,"Image":"def3f9165934325dfd027c86530b2ea49bb57a0963eb1336b3a0415ff6fd56de","Volumes":null,"WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"OnBuild":[]},"architecture":"amd64","os":"linux","Size":3425} \ No newline at end of file diff --git a/vendor/github.com/docker/docker/pkg/tarsum/testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar b/vendor/github.com/docker/docker/pkg/tarsum/testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar deleted file mode 100644 index dfd5c20..0000000 Binary files a/vendor/github.com/docker/docker/pkg/tarsum/testdata/46af0962ab5afeb5ce6740d4d91652e69206fc991fd5328c1a94d364ad00e457/layer.tar and /dev/null differ diff --git a/vendor/github.com/docker/docker/pkg/tarsum/testdata/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json b/vendor/github.com/docker/docker/pkg/tarsum/testdata/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json deleted file mode 100644 index af57be0..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/testdata/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json +++ /dev/null @@ -1 +0,0 @@ -{"id":"511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158","comment":"Imported from -","created":"2013-06-13T14:03:50.821769-07:00","container_config":{"Hostname":"","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":null,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":null,"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"OnBuild":null},"docker_version":"0.4.0","architecture":"x86_64","Size":0} \ No newline at end of file diff --git a/vendor/github.com/docker/docker/pkg/tarsum/testdata/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer.tar b/vendor/github.com/docker/docker/pkg/tarsum/testdata/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer.tar deleted file mode 100644 index 880b3f2..0000000 Binary files a/vendor/github.com/docker/docker/pkg/tarsum/testdata/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer.tar and /dev/null differ diff --git a/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-0.tar b/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-0.tar deleted file mode 100644 index 1c636b3..0000000 Binary files a/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-0.tar and /dev/null differ diff --git a/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-1.tar b/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-1.tar deleted file mode 100644 index b411be9..0000000 Binary files a/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-1.tar and /dev/null differ diff --git a/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-2.tar b/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-2.tar deleted file mode 100644 index 7b5c04a..0000000 Binary files a/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-2.tar and /dev/null differ diff --git a/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-3.tar b/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-3.tar deleted file mode 100644 index f8c6458..0000000 Binary files a/vendor/github.com/docker/docker/pkg/tarsum/testdata/collision/collision-3.tar and /dev/null differ diff --git a/vendor/github.com/docker/docker/pkg/tarsum/testdata/xattr/json b/vendor/github.com/docker/docker/pkg/tarsum/testdata/xattr/json deleted file mode 100644 index 288441a..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/testdata/xattr/json +++ /dev/null @@ -1 +0,0 @@ -{"id":"4439c3c7f847954100b42b267e7e5529cac1d6934db082f65795c5ca2e594d93","parent":"73b164f4437db87e96e90083c73a6592f549646ae2ec00ed33c6b9b49a5c4470","created":"2014-05-16T17:19:44.091534414Z","container":"5f92fb06cc58f357f0cde41394e2bbbb664e663974b2ac1693ab07b7a306749b","container_config":{"Hostname":"9565c6517a0e","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"Cpuset":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":null,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["HOME=/","PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh","-c","setcap 'cap_setgid,cap_setuid+ep' ./file \u0026\u0026 getcap ./file"],"Image":"73b164f4437db87e96e90083c73a6592f549646ae2ec00ed33c6b9b49a5c4470","Volumes":null,"WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"OnBuild":[]},"docker_version":"0.11.1-dev","config":{"Hostname":"9565c6517a0e","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"Cpuset":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":null,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["HOME=/","PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":null,"Image":"73b164f4437db87e96e90083c73a6592f549646ae2ec00ed33c6b9b49a5c4470","Volumes":null,"WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"OnBuild":[]},"architecture":"amd64","os":"linux","Size":0} \ No newline at end of file diff --git a/vendor/github.com/docker/docker/pkg/tarsum/testdata/xattr/layer.tar b/vendor/github.com/docker/docker/pkg/tarsum/testdata/xattr/layer.tar deleted file mode 100644 index 819351d..0000000 Binary files a/vendor/github.com/docker/docker/pkg/tarsum/testdata/xattr/layer.tar and /dev/null differ diff --git a/vendor/github.com/docker/docker/pkg/tarsum/versioning.go b/vendor/github.com/docker/docker/pkg/tarsum/versioning.go deleted file mode 100644 index 2882286..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/versioning.go +++ /dev/null @@ -1,150 +0,0 @@ -package tarsum - -import ( - "archive/tar" - "errors" - "sort" - "strconv" - "strings" -) - -// Version is used for versioning of the TarSum algorithm -// based on the prefix of the hash used -// i.e. "tarsum+sha256:e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b" -type Version int - -// Prefix of "tarsum" -const ( - Version0 Version = iota - Version1 - // VersionDev this constant will be either the latest or an unsettled next-version of the TarSum calculation - VersionDev -) - -// VersionLabelForChecksum returns the label for the given tarsum -// checksum, i.e., everything before the first `+` character in -// the string or an empty string if no label separator is found. -func VersionLabelForChecksum(checksum string) string { - // Checksums are in the form: {versionLabel}+{hashID}:{hex} - sepIndex := strings.Index(checksum, "+") - if sepIndex < 0 { - return "" - } - return checksum[:sepIndex] -} - -// GetVersions gets a list of all known tarsum versions. -func GetVersions() []Version { - v := []Version{} - for k := range tarSumVersions { - v = append(v, k) - } - return v -} - -var ( - tarSumVersions = map[Version]string{ - Version0: "tarsum", - Version1: "tarsum.v1", - VersionDev: "tarsum.dev", - } - tarSumVersionsByName = map[string]Version{ - "tarsum": Version0, - "tarsum.v1": Version1, - "tarsum.dev": VersionDev, - } -) - -func (tsv Version) String() string { - return tarSumVersions[tsv] -} - -// GetVersionFromTarsum returns the Version from the provided string. -func GetVersionFromTarsum(tarsum string) (Version, error) { - tsv := tarsum - if strings.Contains(tarsum, "+") { - tsv = strings.SplitN(tarsum, "+", 2)[0] - } - for v, s := range tarSumVersions { - if s == tsv { - return v, nil - } - } - return -1, ErrNotVersion -} - -// Errors that may be returned by functions in this package -var ( - ErrNotVersion = errors.New("string does not include a TarSum Version") - ErrVersionNotImplemented = errors.New("TarSum Version is not yet implemented") -) - -// tarHeaderSelector is the interface which different versions -// of tarsum should use for selecting and ordering tar headers -// for each item in the archive. -type tarHeaderSelector interface { - selectHeaders(h *tar.Header) (orderedHeaders [][2]string) -} - -type tarHeaderSelectFunc func(h *tar.Header) (orderedHeaders [][2]string) - -func (f tarHeaderSelectFunc) selectHeaders(h *tar.Header) (orderedHeaders [][2]string) { - return f(h) -} - -func v0TarHeaderSelect(h *tar.Header) (orderedHeaders [][2]string) { - return [][2]string{ - {"name", h.Name}, - {"mode", strconv.FormatInt(h.Mode, 10)}, - {"uid", strconv.Itoa(h.Uid)}, - {"gid", strconv.Itoa(h.Gid)}, - {"size", strconv.FormatInt(h.Size, 10)}, - {"mtime", strconv.FormatInt(h.ModTime.UTC().Unix(), 10)}, - {"typeflag", string([]byte{h.Typeflag})}, - {"linkname", h.Linkname}, - {"uname", h.Uname}, - {"gname", h.Gname}, - {"devmajor", strconv.FormatInt(h.Devmajor, 10)}, - {"devminor", strconv.FormatInt(h.Devminor, 10)}, - } -} - -func v1TarHeaderSelect(h *tar.Header) (orderedHeaders [][2]string) { - // Get extended attributes. - xAttrKeys := make([]string, len(h.Xattrs)) - for k := range h.Xattrs { - xAttrKeys = append(xAttrKeys, k) - } - sort.Strings(xAttrKeys) - - // Make the slice with enough capacity to hold the 11 basic headers - // we want from the v0 selector plus however many xattrs we have. - orderedHeaders = make([][2]string, 0, 11+len(xAttrKeys)) - - // Copy all headers from v0 excluding the 'mtime' header (the 5th element). - v0headers := v0TarHeaderSelect(h) - orderedHeaders = append(orderedHeaders, v0headers[0:5]...) - orderedHeaders = append(orderedHeaders, v0headers[6:]...) - - // Finally, append the sorted xattrs. - for _, k := range xAttrKeys { - orderedHeaders = append(orderedHeaders, [2]string{k, h.Xattrs[k]}) - } - - return -} - -var registeredHeaderSelectors = map[Version]tarHeaderSelectFunc{ - Version0: v0TarHeaderSelect, - Version1: v1TarHeaderSelect, - VersionDev: v1TarHeaderSelect, -} - -func getTarHeaderSelector(v Version) (tarHeaderSelector, error) { - headerSelector, ok := registeredHeaderSelectors[v] - if !ok { - return nil, ErrVersionNotImplemented - } - - return headerSelector, nil -} diff --git a/vendor/github.com/docker/docker/pkg/tarsum/versioning_test.go b/vendor/github.com/docker/docker/pkg/tarsum/versioning_test.go deleted file mode 100644 index 88e0a57..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/versioning_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package tarsum - -import ( - "testing" -) - -func TestVersionLabelForChecksum(t *testing.T) { - version := VersionLabelForChecksum("tarsum+sha256:deadbeef") - if version != "tarsum" { - t.Fatalf("Version should have been 'tarsum', was %v", version) - } - version = VersionLabelForChecksum("tarsum.v1+sha256:deadbeef") - if version != "tarsum.v1" { - t.Fatalf("Version should have been 'tarsum.v1', was %v", version) - } - version = VersionLabelForChecksum("something+somethingelse") - if version != "something" { - t.Fatalf("Version should have been 'something', was %v", version) - } - version = VersionLabelForChecksum("invalidChecksum") - if version != "" { - t.Fatalf("Version should have been empty, was %v", version) - } -} - -func TestVersion(t *testing.T) { - expected := "tarsum" - var v Version - if v.String() != expected { - t.Errorf("expected %q, got %q", expected, v.String()) - } - - expected = "tarsum.v1" - v = 1 - if v.String() != expected { - t.Errorf("expected %q, got %q", expected, v.String()) - } - - expected = "tarsum.dev" - v = 2 - if v.String() != expected { - t.Errorf("expected %q, got %q", expected, v.String()) - } -} - -func TestGetVersion(t *testing.T) { - testSet := []struct { - Str string - Expected Version - }{ - {"tarsum+sha256:e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b", Version0}, - {"tarsum+sha256", Version0}, - {"tarsum", Version0}, - {"tarsum.dev", VersionDev}, - {"tarsum.dev+sha256:deadbeef", VersionDev}, - } - - for _, ts := range testSet { - v, err := GetVersionFromTarsum(ts.Str) - if err != nil { - t.Fatalf("%q : %s", err, ts.Str) - } - if v != ts.Expected { - t.Errorf("expected %d (%q), got %d (%q)", ts.Expected, ts.Expected, v, v) - } - } - - // test one that does not exist, to ensure it errors - str := "weak+md5:abcdeabcde" - _, err := GetVersionFromTarsum(str) - if err != ErrNotVersion { - t.Fatalf("%q : %s", err, str) - } -} - -func TestGetVersions(t *testing.T) { - expected := []Version{ - Version0, - Version1, - VersionDev, - } - versions := GetVersions() - if len(versions) != len(expected) { - t.Fatalf("Expected %v versions, got %v", len(expected), len(versions)) - } - if !containsVersion(versions, expected[0]) || !containsVersion(versions, expected[1]) || !containsVersion(versions, expected[2]) { - t.Fatalf("Expected [%v], got [%v]", expected, versions) - } -} - -func containsVersion(versions []Version, version Version) bool { - for _, v := range versions { - if v == version { - return true - } - } - return false -} diff --git a/vendor/github.com/docker/docker/pkg/tarsum/writercloser.go b/vendor/github.com/docker/docker/pkg/tarsum/writercloser.go deleted file mode 100644 index 9727ecd..0000000 --- a/vendor/github.com/docker/docker/pkg/tarsum/writercloser.go +++ /dev/null @@ -1,22 +0,0 @@ -package tarsum - -import ( - "io" -) - -type writeCloseFlusher interface { - io.WriteCloser - Flush() error -} - -type nopCloseFlusher struct { - io.Writer -} - -func (n *nopCloseFlusher) Close() error { - return nil -} - -func (n *nopCloseFlusher) Flush() error { - return nil -} diff --git a/vendor/github.com/docker/docker/pkg/term/ascii.go b/vendor/github.com/docker/docker/pkg/term/ascii.go deleted file mode 100644 index f5262bc..0000000 --- a/vendor/github.com/docker/docker/pkg/term/ascii.go +++ /dev/null @@ -1,66 +0,0 @@ -package term - -import ( - "fmt" - "strings" -) - -// ASCII list the possible supported ASCII key sequence -var ASCII = []string{ - "ctrl-@", - "ctrl-a", - "ctrl-b", - "ctrl-c", - "ctrl-d", - "ctrl-e", - "ctrl-f", - "ctrl-g", - "ctrl-h", - "ctrl-i", - "ctrl-j", - "ctrl-k", - "ctrl-l", - "ctrl-m", - "ctrl-n", - "ctrl-o", - "ctrl-p", - "ctrl-q", - "ctrl-r", - "ctrl-s", - "ctrl-t", - "ctrl-u", - "ctrl-v", - "ctrl-w", - "ctrl-x", - "ctrl-y", - "ctrl-z", - "ctrl-[", - "ctrl-\\", - "ctrl-]", - "ctrl-^", - "ctrl-_", -} - -// ToBytes converts a string representing a suite of key-sequence to the corresponding ASCII code. -func ToBytes(keys string) ([]byte, error) { - codes := []byte{} -next: - for _, key := range strings.Split(keys, ",") { - if len(key) != 1 { - for code, ctrl := range ASCII { - if ctrl == key { - codes = append(codes, byte(code)) - continue next - } - } - if key == "DEL" { - codes = append(codes, 127) - } else { - return nil, fmt.Errorf("Unknown character: '%s'", key) - } - } else { - codes = append(codes, byte(key[0])) - } - } - return codes, nil -} diff --git a/vendor/github.com/docker/docker/pkg/term/ascii_test.go b/vendor/github.com/docker/docker/pkg/term/ascii_test.go deleted file mode 100644 index 4a1e7f3..0000000 --- a/vendor/github.com/docker/docker/pkg/term/ascii_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package term - -import "testing" - -func TestToBytes(t *testing.T) { - codes, err := ToBytes("ctrl-a,a") - if err != nil { - t.Fatal(err) - } - if len(codes) != 2 { - t.Fatalf("Expected 2 codes, got %d", len(codes)) - } - if codes[0] != 1 || codes[1] != 97 { - t.Fatalf("Expected '1' '97', got '%d' '%d'", codes[0], codes[1]) - } - - codes, err = ToBytes("shift-z") - if err == nil { - t.Fatalf("Expected error, got none") - } - - codes, err = ToBytes("ctrl-@,ctrl-[,~,ctrl-o") - if err != nil { - t.Fatal(err) - } - if len(codes) != 4 { - t.Fatalf("Expected 4 codes, got %d", len(codes)) - } - if codes[0] != 0 || codes[1] != 27 || codes[2] != 126 || codes[3] != 15 { - t.Fatalf("Expected '0' '27' '126', '15', got '%d' '%d' '%d' '%d'", codes[0], codes[1], codes[2], codes[3]) - } - - codes, err = ToBytes("DEL,+") - if err != nil { - t.Fatal(err) - } - if len(codes) != 2 { - t.Fatalf("Expected 2 codes, got %d", len(codes)) - } - if codes[0] != 127 || codes[1] != 43 { - t.Fatalf("Expected '127 '43'', got '%d' '%d'", codes[0], codes[1]) - } -} diff --git a/vendor/github.com/docker/docker/pkg/term/tc_linux_cgo.go b/vendor/github.com/docker/docker/pkg/term/tc_linux_cgo.go deleted file mode 100644 index 59dac5b..0000000 --- a/vendor/github.com/docker/docker/pkg/term/tc_linux_cgo.go +++ /dev/null @@ -1,50 +0,0 @@ -// +build linux,cgo - -package term - -import ( - "syscall" - "unsafe" -) - -// #include -import "C" - -// Termios is the Unix API for terminal I/O. -// It is passthrough for syscall.Termios in order to make it portable with -// other platforms where it is not available or handled differently. -type Termios syscall.Termios - -// MakeRaw put the terminal connected to the given file descriptor into raw -// mode and returns the previous state of the terminal so that it can be -// restored. -func MakeRaw(fd uintptr) (*State, error) { - var oldState State - if err := tcget(fd, &oldState.termios); err != 0 { - return nil, err - } - - newState := oldState.termios - - C.cfmakeraw((*C.struct_termios)(unsafe.Pointer(&newState))) - if err := tcset(fd, &newState); err != 0 { - return nil, err - } - return &oldState, nil -} - -func tcget(fd uintptr, p *Termios) syscall.Errno { - ret, err := C.tcgetattr(C.int(fd), (*C.struct_termios)(unsafe.Pointer(p))) - if ret != 0 { - return err.(syscall.Errno) - } - return 0 -} - -func tcset(fd uintptr, p *Termios) syscall.Errno { - ret, err := C.tcsetattr(C.int(fd), C.TCSANOW, (*C.struct_termios)(unsafe.Pointer(p))) - if ret != 0 { - return err.(syscall.Errno) - } - return 0 -} diff --git a/vendor/github.com/docker/docker/pkg/term/tc_other.go b/vendor/github.com/docker/docker/pkg/term/tc_other.go deleted file mode 100644 index 750d7c3..0000000 --- a/vendor/github.com/docker/docker/pkg/term/tc_other.go +++ /dev/null @@ -1,20 +0,0 @@ -// +build !windows -// +build !linux !cgo -// +build !solaris !cgo - -package term - -import ( - "syscall" - "unsafe" -) - -func tcget(fd uintptr, p *Termios) syscall.Errno { - _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(p))) - return err -} - -func tcset(fd uintptr, p *Termios) syscall.Errno { - _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(p))) - return err -} diff --git a/vendor/github.com/docker/docker/pkg/term/tc_solaris_cgo.go b/vendor/github.com/docker/docker/pkg/term/tc_solaris_cgo.go deleted file mode 100644 index c9139d0..0000000 --- a/vendor/github.com/docker/docker/pkg/term/tc_solaris_cgo.go +++ /dev/null @@ -1,63 +0,0 @@ -// +build solaris,cgo - -package term - -import ( - "syscall" - "unsafe" -) - -// #include -import "C" - -// Termios is the Unix API for terminal I/O. -// It is passthrough for syscall.Termios in order to make it portable with -// other platforms where it is not available or handled differently. -type Termios syscall.Termios - -// MakeRaw put the terminal connected to the given file descriptor into raw -// mode and returns the previous state of the terminal so that it can be -// restored. -func MakeRaw(fd uintptr) (*State, error) { - var oldState State - if err := tcget(fd, &oldState.termios); err != 0 { - return nil, err - } - - newState := oldState.termios - - newState.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON | syscall.IXANY) - newState.Oflag &^= syscall.OPOST - newState.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN) - newState.Cflag &^= (syscall.CSIZE | syscall.PARENB) - newState.Cflag |= syscall.CS8 - - /* - VMIN is the minimum number of characters that needs to be read in non-canonical mode for it to be returned - Since VMIN is overloaded with another element in canonical mode when we switch modes it defaults to 4. It - needs to be explicitly set to 1. - */ - newState.Cc[C.VMIN] = 1 - newState.Cc[C.VTIME] = 0 - - if err := tcset(fd, &newState); err != 0 { - return nil, err - } - return &oldState, nil -} - -func tcget(fd uintptr, p *Termios) syscall.Errno { - ret, err := C.tcgetattr(C.int(fd), (*C.struct_termios)(unsafe.Pointer(p))) - if ret != 0 { - return err.(syscall.Errno) - } - return 0 -} - -func tcset(fd uintptr, p *Termios) syscall.Errno { - ret, err := C.tcsetattr(C.int(fd), C.TCSANOW, (*C.struct_termios)(unsafe.Pointer(p))) - if ret != 0 { - return err.(syscall.Errno) - } - return 0 -} diff --git a/vendor/github.com/docker/docker/pkg/term/term.go b/vendor/github.com/docker/docker/pkg/term/term.go deleted file mode 100644 index fe59faa..0000000 --- a/vendor/github.com/docker/docker/pkg/term/term.go +++ /dev/null @@ -1,123 +0,0 @@ -// +build !windows - -// Package term provides structures and helper functions to work with -// terminal (state, sizes). -package term - -import ( - "errors" - "fmt" - "io" - "os" - "os/signal" - "syscall" -) - -var ( - // ErrInvalidState is returned if the state of the terminal is invalid. - ErrInvalidState = errors.New("Invalid terminal state") -) - -// State represents the state of the terminal. -type State struct { - termios Termios -} - -// Winsize represents the size of the terminal window. -type Winsize struct { - Height uint16 - Width uint16 - x uint16 - y uint16 -} - -// StdStreams returns the standard streams (stdin, stdout, stedrr). -func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) { - return os.Stdin, os.Stdout, os.Stderr -} - -// GetFdInfo returns the file descriptor for an os.File and indicates whether the file represents a terminal. -func GetFdInfo(in interface{}) (uintptr, bool) { - var inFd uintptr - var isTerminalIn bool - if file, ok := in.(*os.File); ok { - inFd = file.Fd() - isTerminalIn = IsTerminal(inFd) - } - return inFd, isTerminalIn -} - -// IsTerminal returns true if the given file descriptor is a terminal. -func IsTerminal(fd uintptr) bool { - var termios Termios - return tcget(fd, &termios) == 0 -} - -// RestoreTerminal restores the terminal connected to the given file descriptor -// to a previous state. -func RestoreTerminal(fd uintptr, state *State) error { - if state == nil { - return ErrInvalidState - } - if err := tcset(fd, &state.termios); err != 0 { - return err - } - return nil -} - -// SaveState saves the state of the terminal connected to the given file descriptor. -func SaveState(fd uintptr) (*State, error) { - var oldState State - if err := tcget(fd, &oldState.termios); err != 0 { - return nil, err - } - - return &oldState, nil -} - -// DisableEcho applies the specified state to the terminal connected to the file -// descriptor, with echo disabled. -func DisableEcho(fd uintptr, state *State) error { - newState := state.termios - newState.Lflag &^= syscall.ECHO - - if err := tcset(fd, &newState); err != 0 { - return err - } - handleInterrupt(fd, state) - return nil -} - -// SetRawTerminal puts the terminal connected to the given file descriptor into -// raw mode and returns the previous state. On UNIX, this puts both the input -// and output into raw mode. On Windows, it only puts the input into raw mode. -func SetRawTerminal(fd uintptr) (*State, error) { - oldState, err := MakeRaw(fd) - if err != nil { - return nil, err - } - handleInterrupt(fd, oldState) - return oldState, err -} - -// SetRawTerminalOutput puts the output of terminal connected to the given file -// descriptor into raw mode. On UNIX, this does nothing and returns nil for the -// state. On Windows, it disables LF -> CRLF translation. -func SetRawTerminalOutput(fd uintptr) (*State, error) { - return nil, nil -} - -func handleInterrupt(fd uintptr, state *State) { - sigchan := make(chan os.Signal, 1) - signal.Notify(sigchan, os.Interrupt) - go func() { - for range sigchan { - // quit cleanly and the new terminal item is on a new line - fmt.Println() - signal.Stop(sigchan) - close(sigchan) - RestoreTerminal(fd, state) - os.Exit(1) - } - }() -} diff --git a/vendor/github.com/docker/docker/pkg/term/term_solaris.go b/vendor/github.com/docker/docker/pkg/term/term_solaris.go deleted file mode 100644 index 112debb..0000000 --- a/vendor/github.com/docker/docker/pkg/term/term_solaris.go +++ /dev/null @@ -1,41 +0,0 @@ -// +build solaris - -package term - -import ( - "syscall" - "unsafe" -) - -/* -#include -#include -#include - -// Small wrapper to get rid of variadic args of ioctl() -int my_ioctl(int fd, int cmd, struct winsize *ws) { - return ioctl(fd, cmd, ws); -} -*/ -import "C" - -// GetWinsize returns the window size based on the specified file descriptor. -func GetWinsize(fd uintptr) (*Winsize, error) { - ws := &Winsize{} - ret, err := C.my_ioctl(C.int(fd), C.int(syscall.TIOCGWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws))) - // Skip retval = 0 - if ret == 0 { - return ws, nil - } - return ws, err -} - -// SetWinsize tries to set the specified window size for the specified file descriptor. -func SetWinsize(fd uintptr, ws *Winsize) error { - ret, err := C.my_ioctl(C.int(fd), C.int(syscall.TIOCSWINSZ), (*C.struct_winsize)(unsafe.Pointer(ws))) - // Skip retval = 0 - if ret == 0 { - return nil - } - return err -} diff --git a/vendor/github.com/docker/docker/pkg/term/term_unix.go b/vendor/github.com/docker/docker/pkg/term/term_unix.go deleted file mode 100644 index ddf87a0..0000000 --- a/vendor/github.com/docker/docker/pkg/term/term_unix.go +++ /dev/null @@ -1,29 +0,0 @@ -// +build !solaris,!windows - -package term - -import ( - "syscall" - "unsafe" -) - -// GetWinsize returns the window size based on the specified file descriptor. -func GetWinsize(fd uintptr) (*Winsize, error) { - ws := &Winsize{} - _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(ws))) - // Skipp errno = 0 - if err == 0 { - return ws, nil - } - return ws, err -} - -// SetWinsize tries to set the specified window size for the specified file descriptor. -func SetWinsize(fd uintptr, ws *Winsize) error { - _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCSWINSZ), uintptr(unsafe.Pointer(ws))) - // Skipp errno = 0 - if err == 0 { - return nil - } - return err -} diff --git a/vendor/github.com/docker/docker/pkg/term/term_windows.go b/vendor/github.com/docker/docker/pkg/term/term_windows.go deleted file mode 100644 index a91f07e..0000000 --- a/vendor/github.com/docker/docker/pkg/term/term_windows.go +++ /dev/null @@ -1,233 +0,0 @@ -// +build windows - -package term - -import ( - "io" - "os" - "os/signal" - "syscall" - - "github.com/Azure/go-ansiterm/winterm" - "github.com/docker/docker/pkg/term/windows" -) - -// State holds the console mode for the terminal. -type State struct { - mode uint32 -} - -// Winsize is used for window size. -type Winsize struct { - Height uint16 - Width uint16 -} - -const ( - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx - enableVirtualTerminalInput = 0x0200 - enableVirtualTerminalProcessing = 0x0004 - disableNewlineAutoReturn = 0x0008 -) - -// vtInputSupported is true if enableVirtualTerminalInput is supported by the console -var vtInputSupported bool - -// StdStreams returns the standard streams (stdin, stdout, stedrr). -func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) { - // Turn on VT handling on all std handles, if possible. This might - // fail, in which case we will fall back to terminal emulation. - var emulateStdin, emulateStdout, emulateStderr bool - fd := os.Stdin.Fd() - if mode, err := winterm.GetConsoleMode(fd); err == nil { - // Validate that enableVirtualTerminalInput is supported, but do not set it. - if err = winterm.SetConsoleMode(fd, mode|enableVirtualTerminalInput); err != nil { - emulateStdin = true - } else { - vtInputSupported = true - } - // Unconditionally set the console mode back even on failure because SetConsoleMode - // remembers invalid bits on input handles. - winterm.SetConsoleMode(fd, mode) - } - - fd = os.Stdout.Fd() - if mode, err := winterm.GetConsoleMode(fd); err == nil { - // Validate disableNewlineAutoReturn is supported, but do not set it. - if err = winterm.SetConsoleMode(fd, mode|enableVirtualTerminalProcessing|disableNewlineAutoReturn); err != nil { - emulateStdout = true - } else { - winterm.SetConsoleMode(fd, mode|enableVirtualTerminalProcessing) - } - } - - fd = os.Stderr.Fd() - if mode, err := winterm.GetConsoleMode(fd); err == nil { - // Validate disableNewlineAutoReturn is supported, but do not set it. - if err = winterm.SetConsoleMode(fd, mode|enableVirtualTerminalProcessing|disableNewlineAutoReturn); err != nil { - emulateStderr = true - } else { - winterm.SetConsoleMode(fd, mode|enableVirtualTerminalProcessing) - } - } - - if os.Getenv("ConEmuANSI") == "ON" || os.Getenv("ConsoleZVersion") != "" { - // The ConEmu and ConsoleZ terminals emulate ANSI on output streams well. - emulateStdin = true - emulateStdout = false - emulateStderr = false - } - - if emulateStdin { - stdIn = windows.NewAnsiReader(syscall.STD_INPUT_HANDLE) - } else { - stdIn = os.Stdin - } - - if emulateStdout { - stdOut = windows.NewAnsiWriter(syscall.STD_OUTPUT_HANDLE) - } else { - stdOut = os.Stdout - } - - if emulateStderr { - stdErr = windows.NewAnsiWriter(syscall.STD_ERROR_HANDLE) - } else { - stdErr = os.Stderr - } - - return -} - -// GetFdInfo returns the file descriptor for an os.File and indicates whether the file represents a terminal. -func GetFdInfo(in interface{}) (uintptr, bool) { - return windows.GetHandleInfo(in) -} - -// GetWinsize returns the window size based on the specified file descriptor. -func GetWinsize(fd uintptr) (*Winsize, error) { - info, err := winterm.GetConsoleScreenBufferInfo(fd) - if err != nil { - return nil, err - } - - winsize := &Winsize{ - Width: uint16(info.Window.Right - info.Window.Left + 1), - Height: uint16(info.Window.Bottom - info.Window.Top + 1), - } - - return winsize, nil -} - -// IsTerminal returns true if the given file descriptor is a terminal. -func IsTerminal(fd uintptr) bool { - return windows.IsConsole(fd) -} - -// RestoreTerminal restores the terminal connected to the given file descriptor -// to a previous state. -func RestoreTerminal(fd uintptr, state *State) error { - return winterm.SetConsoleMode(fd, state.mode) -} - -// SaveState saves the state of the terminal connected to the given file descriptor. -func SaveState(fd uintptr) (*State, error) { - mode, e := winterm.GetConsoleMode(fd) - if e != nil { - return nil, e - } - - return &State{mode: mode}, nil -} - -// DisableEcho disables echo for the terminal connected to the given file descriptor. -// -- See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx -func DisableEcho(fd uintptr, state *State) error { - mode := state.mode - mode &^= winterm.ENABLE_ECHO_INPUT - mode |= winterm.ENABLE_PROCESSED_INPUT | winterm.ENABLE_LINE_INPUT - err := winterm.SetConsoleMode(fd, mode) - if err != nil { - return err - } - - // Register an interrupt handler to catch and restore prior state - restoreAtInterrupt(fd, state) - return nil -} - -// SetRawTerminal puts the terminal connected to the given file descriptor into -// raw mode and returns the previous state. On UNIX, this puts both the input -// and output into raw mode. On Windows, it only puts the input into raw mode. -func SetRawTerminal(fd uintptr) (*State, error) { - state, err := MakeRaw(fd) - if err != nil { - return nil, err - } - - // Register an interrupt handler to catch and restore prior state - restoreAtInterrupt(fd, state) - return state, err -} - -// SetRawTerminalOutput puts the output of terminal connected to the given file -// descriptor into raw mode. On UNIX, this does nothing and returns nil for the -// state. On Windows, it disables LF -> CRLF translation. -func SetRawTerminalOutput(fd uintptr) (*State, error) { - state, err := SaveState(fd) - if err != nil { - return nil, err - } - - // Ignore failures, since disableNewlineAutoReturn might not be supported on this - // version of Windows. - winterm.SetConsoleMode(fd, state.mode|disableNewlineAutoReturn) - return state, err -} - -// MakeRaw puts the terminal (Windows Console) connected to the given file descriptor into raw -// mode and returns the previous state of the terminal so that it can be restored. -func MakeRaw(fd uintptr) (*State, error) { - state, err := SaveState(fd) - if err != nil { - return nil, err - } - - mode := state.mode - - // See - // -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx - // -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx - - // Disable these modes - mode &^= winterm.ENABLE_ECHO_INPUT - mode &^= winterm.ENABLE_LINE_INPUT - mode &^= winterm.ENABLE_MOUSE_INPUT - mode &^= winterm.ENABLE_WINDOW_INPUT - mode &^= winterm.ENABLE_PROCESSED_INPUT - - // Enable these modes - mode |= winterm.ENABLE_EXTENDED_FLAGS - mode |= winterm.ENABLE_INSERT_MODE - mode |= winterm.ENABLE_QUICK_EDIT_MODE - if vtInputSupported { - mode |= enableVirtualTerminalInput - } - - err = winterm.SetConsoleMode(fd, mode) - if err != nil { - return nil, err - } - return state, nil -} - -func restoreAtInterrupt(fd uintptr, state *State) { - sigchan := make(chan os.Signal, 1) - signal.Notify(sigchan, os.Interrupt) - - go func() { - _ = <-sigchan - RestoreTerminal(fd, state) - os.Exit(0) - }() -} diff --git a/vendor/github.com/docker/docker/pkg/term/termios_darwin.go b/vendor/github.com/docker/docker/pkg/term/termios_darwin.go deleted file mode 100644 index 480db90..0000000 --- a/vendor/github.com/docker/docker/pkg/term/termios_darwin.go +++ /dev/null @@ -1,69 +0,0 @@ -package term - -import ( - "syscall" - "unsafe" -) - -const ( - getTermios = syscall.TIOCGETA - setTermios = syscall.TIOCSETA -) - -// Termios magic numbers, passthrough to the ones defined in syscall. -const ( - IGNBRK = syscall.IGNBRK - PARMRK = syscall.PARMRK - INLCR = syscall.INLCR - IGNCR = syscall.IGNCR - ECHONL = syscall.ECHONL - CSIZE = syscall.CSIZE - ICRNL = syscall.ICRNL - ISTRIP = syscall.ISTRIP - PARENB = syscall.PARENB - ECHO = syscall.ECHO - ICANON = syscall.ICANON - ISIG = syscall.ISIG - IXON = syscall.IXON - BRKINT = syscall.BRKINT - INPCK = syscall.INPCK - OPOST = syscall.OPOST - CS8 = syscall.CS8 - IEXTEN = syscall.IEXTEN -) - -// Termios is the Unix API for terminal I/O. -type Termios struct { - Iflag uint64 - Oflag uint64 - Cflag uint64 - Lflag uint64 - Cc [20]byte - Ispeed uint64 - Ospeed uint64 -} - -// MakeRaw put the terminal connected to the given file descriptor into raw -// mode and returns the previous state of the terminal so that it can be -// restored. -func MakeRaw(fd uintptr) (*State, error) { - var oldState State - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { - return nil, err - } - - newState := oldState.termios - newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) - newState.Oflag &^= OPOST - newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) - newState.Cflag &^= (CSIZE | PARENB) - newState.Cflag |= CS8 - newState.Cc[syscall.VMIN] = 1 - newState.Cc[syscall.VTIME] = 0 - - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 { - return nil, err - } - - return &oldState, nil -} diff --git a/vendor/github.com/docker/docker/pkg/term/termios_freebsd.go b/vendor/github.com/docker/docker/pkg/term/termios_freebsd.go deleted file mode 100644 index ed843ad..0000000 --- a/vendor/github.com/docker/docker/pkg/term/termios_freebsd.go +++ /dev/null @@ -1,69 +0,0 @@ -package term - -import ( - "syscall" - "unsafe" -) - -const ( - getTermios = syscall.TIOCGETA - setTermios = syscall.TIOCSETA -) - -// Termios magic numbers, passthrough to the ones defined in syscall. -const ( - IGNBRK = syscall.IGNBRK - PARMRK = syscall.PARMRK - INLCR = syscall.INLCR - IGNCR = syscall.IGNCR - ECHONL = syscall.ECHONL - CSIZE = syscall.CSIZE - ICRNL = syscall.ICRNL - ISTRIP = syscall.ISTRIP - PARENB = syscall.PARENB - ECHO = syscall.ECHO - ICANON = syscall.ICANON - ISIG = syscall.ISIG - IXON = syscall.IXON - BRKINT = syscall.BRKINT - INPCK = syscall.INPCK - OPOST = syscall.OPOST - CS8 = syscall.CS8 - IEXTEN = syscall.IEXTEN -) - -// Termios is the Unix API for terminal I/O. -type Termios struct { - Iflag uint32 - Oflag uint32 - Cflag uint32 - Lflag uint32 - Cc [20]byte - Ispeed uint32 - Ospeed uint32 -} - -// MakeRaw put the terminal connected to the given file descriptor into raw -// mode and returns the previous state of the terminal so that it can be -// restored. -func MakeRaw(fd uintptr) (*State, error) { - var oldState State - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { - return nil, err - } - - newState := oldState.termios - newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) - newState.Oflag &^= OPOST - newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) - newState.Cflag &^= (CSIZE | PARENB) - newState.Cflag |= CS8 - newState.Cc[syscall.VMIN] = 1 - newState.Cc[syscall.VTIME] = 0 - - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 { - return nil, err - } - - return &oldState, nil -} diff --git a/vendor/github.com/docker/docker/pkg/term/termios_linux.go b/vendor/github.com/docker/docker/pkg/term/termios_linux.go deleted file mode 100644 index 22921b6..0000000 --- a/vendor/github.com/docker/docker/pkg/term/termios_linux.go +++ /dev/null @@ -1,47 +0,0 @@ -// +build !cgo - -package term - -import ( - "syscall" - "unsafe" -) - -const ( - getTermios = syscall.TCGETS - setTermios = syscall.TCSETS -) - -// Termios is the Unix API for terminal I/O. -type Termios struct { - Iflag uint32 - Oflag uint32 - Cflag uint32 - Lflag uint32 - Cc [20]byte - Ispeed uint32 - Ospeed uint32 -} - -// MakeRaw put the terminal connected to the given file descriptor into raw -// mode and returns the previous state of the terminal so that it can be -// restored. -func MakeRaw(fd uintptr) (*State, error) { - var oldState State - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { - return nil, err - } - - newState := oldState.termios - - newState.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON) - newState.Oflag &^= syscall.OPOST - newState.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN) - newState.Cflag &^= (syscall.CSIZE | syscall.PARENB) - newState.Cflag |= syscall.CS8 - - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 { - return nil, err - } - return &oldState, nil -} diff --git a/vendor/github.com/docker/docker/pkg/term/termios_openbsd.go b/vendor/github.com/docker/docker/pkg/term/termios_openbsd.go deleted file mode 100644 index ed843ad..0000000 --- a/vendor/github.com/docker/docker/pkg/term/termios_openbsd.go +++ /dev/null @@ -1,69 +0,0 @@ -package term - -import ( - "syscall" - "unsafe" -) - -const ( - getTermios = syscall.TIOCGETA - setTermios = syscall.TIOCSETA -) - -// Termios magic numbers, passthrough to the ones defined in syscall. -const ( - IGNBRK = syscall.IGNBRK - PARMRK = syscall.PARMRK - INLCR = syscall.INLCR - IGNCR = syscall.IGNCR - ECHONL = syscall.ECHONL - CSIZE = syscall.CSIZE - ICRNL = syscall.ICRNL - ISTRIP = syscall.ISTRIP - PARENB = syscall.PARENB - ECHO = syscall.ECHO - ICANON = syscall.ICANON - ISIG = syscall.ISIG - IXON = syscall.IXON - BRKINT = syscall.BRKINT - INPCK = syscall.INPCK - OPOST = syscall.OPOST - CS8 = syscall.CS8 - IEXTEN = syscall.IEXTEN -) - -// Termios is the Unix API for terminal I/O. -type Termios struct { - Iflag uint32 - Oflag uint32 - Cflag uint32 - Lflag uint32 - Cc [20]byte - Ispeed uint32 - Ospeed uint32 -} - -// MakeRaw put the terminal connected to the given file descriptor into raw -// mode and returns the previous state of the terminal so that it can be -// restored. -func MakeRaw(fd uintptr) (*State, error) { - var oldState State - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { - return nil, err - } - - newState := oldState.termios - newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) - newState.Oflag &^= OPOST - newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) - newState.Cflag &^= (CSIZE | PARENB) - newState.Cflag |= CS8 - newState.Cc[syscall.VMIN] = 1 - newState.Cc[syscall.VTIME] = 0 - - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 { - return nil, err - } - - return &oldState, nil -} diff --git a/vendor/github.com/docker/docker/pkg/term/windows/ansi_reader.go b/vendor/github.com/docker/docker/pkg/term/windows/ansi_reader.go deleted file mode 100644 index cb0b883..0000000 --- a/vendor/github.com/docker/docker/pkg/term/windows/ansi_reader.go +++ /dev/null @@ -1,263 +0,0 @@ -// +build windows - -package windows - -import ( - "bytes" - "errors" - "fmt" - "io" - "os" - "strings" - "unsafe" - - ansiterm "github.com/Azure/go-ansiterm" - "github.com/Azure/go-ansiterm/winterm" -) - -const ( - escapeSequence = ansiterm.KEY_ESC_CSI -) - -// ansiReader wraps a standard input file (e.g., os.Stdin) providing ANSI sequence translation. -type ansiReader struct { - file *os.File - fd uintptr - buffer []byte - cbBuffer int - command []byte -} - -// NewAnsiReader returns an io.ReadCloser that provides VT100 terminal emulation on top of a -// Windows console input handle. -func NewAnsiReader(nFile int) io.ReadCloser { - initLogger() - file, fd := winterm.GetStdFile(nFile) - return &ansiReader{ - file: file, - fd: fd, - command: make([]byte, 0, ansiterm.ANSI_MAX_CMD_LENGTH), - buffer: make([]byte, 0), - } -} - -// Close closes the wrapped file. -func (ar *ansiReader) Close() (err error) { - return ar.file.Close() -} - -// Fd returns the file descriptor of the wrapped file. -func (ar *ansiReader) Fd() uintptr { - return ar.fd -} - -// Read reads up to len(p) bytes of translated input events into p. -func (ar *ansiReader) Read(p []byte) (int, error) { - if len(p) == 0 { - return 0, nil - } - - // Previously read bytes exist, read as much as we can and return - if len(ar.buffer) > 0 { - logger.Debugf("Reading previously cached bytes") - - originalLength := len(ar.buffer) - copiedLength := copy(p, ar.buffer) - - if copiedLength == originalLength { - ar.buffer = make([]byte, 0, len(p)) - } else { - ar.buffer = ar.buffer[copiedLength:] - } - - logger.Debugf("Read from cache p[%d]: % x", copiedLength, p) - return copiedLength, nil - } - - // Read and translate key events - events, err := readInputEvents(ar.fd, len(p)) - if err != nil { - return 0, err - } else if len(events) == 0 { - logger.Debug("No input events detected") - return 0, nil - } - - keyBytes := translateKeyEvents(events, []byte(escapeSequence)) - - // Save excess bytes and right-size keyBytes - if len(keyBytes) > len(p) { - logger.Debugf("Received %d keyBytes, only room for %d bytes", len(keyBytes), len(p)) - ar.buffer = keyBytes[len(p):] - keyBytes = keyBytes[:len(p)] - } else if len(keyBytes) == 0 { - logger.Debug("No key bytes returned from the translator") - return 0, nil - } - - copiedLength := copy(p, keyBytes) - if copiedLength != len(keyBytes) { - return 0, errors.New("unexpected copy length encountered") - } - - logger.Debugf("Read p[%d]: % x", copiedLength, p) - logger.Debugf("Read keyBytes[%d]: % x", copiedLength, keyBytes) - return copiedLength, nil -} - -// readInputEvents polls until at least one event is available. -func readInputEvents(fd uintptr, maxBytes int) ([]winterm.INPUT_RECORD, error) { - // Determine the maximum number of records to retrieve - // -- Cast around the type system to obtain the size of a single INPUT_RECORD. - // unsafe.Sizeof requires an expression vs. a type-reference; the casting - // tricks the type system into believing it has such an expression. - recordSize := int(unsafe.Sizeof(*((*winterm.INPUT_RECORD)(unsafe.Pointer(&maxBytes))))) - countRecords := maxBytes / recordSize - if countRecords > ansiterm.MAX_INPUT_EVENTS { - countRecords = ansiterm.MAX_INPUT_EVENTS - } else if countRecords == 0 { - countRecords = 1 - } - logger.Debugf("[windows] readInputEvents: Reading %v records (buffer size %v, record size %v)", countRecords, maxBytes, recordSize) - - // Wait for and read input events - events := make([]winterm.INPUT_RECORD, countRecords) - nEvents := uint32(0) - eventsExist, err := winterm.WaitForSingleObject(fd, winterm.WAIT_INFINITE) - if err != nil { - return nil, err - } - - if eventsExist { - err = winterm.ReadConsoleInput(fd, events, &nEvents) - if err != nil { - return nil, err - } - } - - // Return a slice restricted to the number of returned records - logger.Debugf("[windows] readInputEvents: Read %v events", nEvents) - return events[:nEvents], nil -} - -// KeyEvent Translation Helpers - -var arrowKeyMapPrefix = map[uint16]string{ - winterm.VK_UP: "%s%sA", - winterm.VK_DOWN: "%s%sB", - winterm.VK_RIGHT: "%s%sC", - winterm.VK_LEFT: "%s%sD", -} - -var keyMapPrefix = map[uint16]string{ - winterm.VK_UP: "\x1B[%sA", - winterm.VK_DOWN: "\x1B[%sB", - winterm.VK_RIGHT: "\x1B[%sC", - winterm.VK_LEFT: "\x1B[%sD", - winterm.VK_HOME: "\x1B[1%s~", // showkey shows ^[[1 - winterm.VK_END: "\x1B[4%s~", // showkey shows ^[[4 - winterm.VK_INSERT: "\x1B[2%s~", - winterm.VK_DELETE: "\x1B[3%s~", - winterm.VK_PRIOR: "\x1B[5%s~", - winterm.VK_NEXT: "\x1B[6%s~", - winterm.VK_F1: "", - winterm.VK_F2: "", - winterm.VK_F3: "\x1B[13%s~", - winterm.VK_F4: "\x1B[14%s~", - winterm.VK_F5: "\x1B[15%s~", - winterm.VK_F6: "\x1B[17%s~", - winterm.VK_F7: "\x1B[18%s~", - winterm.VK_F8: "\x1B[19%s~", - winterm.VK_F9: "\x1B[20%s~", - winterm.VK_F10: "\x1B[21%s~", - winterm.VK_F11: "\x1B[23%s~", - winterm.VK_F12: "\x1B[24%s~", -} - -// translateKeyEvents converts the input events into the appropriate ANSI string. -func translateKeyEvents(events []winterm.INPUT_RECORD, escapeSequence []byte) []byte { - var buffer bytes.Buffer - for _, event := range events { - if event.EventType == winterm.KEY_EVENT && event.KeyEvent.KeyDown != 0 { - buffer.WriteString(keyToString(&event.KeyEvent, escapeSequence)) - } - } - - return buffer.Bytes() -} - -// keyToString maps the given input event record to the corresponding string. -func keyToString(keyEvent *winterm.KEY_EVENT_RECORD, escapeSequence []byte) string { - if keyEvent.UnicodeChar == 0 { - return formatVirtualKey(keyEvent.VirtualKeyCode, keyEvent.ControlKeyState, escapeSequence) - } - - _, alt, control := getControlKeys(keyEvent.ControlKeyState) - if control { - // TODO(azlinux): Implement following control sequences - // -D Signals the end of input from the keyboard; also exits current shell. - // -H Deletes the first character to the left of the cursor. Also called the ERASE key. - // -Q Restarts printing after it has been stopped with -s. - // -S Suspends printing on the screen (does not stop the program). - // -U Deletes all characters on the current line. Also called the KILL key. - // -E Quits current command and creates a core - - } - - // +Key generates ESC N Key - if !control && alt { - return ansiterm.KEY_ESC_N + strings.ToLower(string(keyEvent.UnicodeChar)) - } - - return string(keyEvent.UnicodeChar) -} - -// formatVirtualKey converts a virtual key (e.g., up arrow) into the appropriate ANSI string. -func formatVirtualKey(key uint16, controlState uint32, escapeSequence []byte) string { - shift, alt, control := getControlKeys(controlState) - modifier := getControlKeysModifier(shift, alt, control) - - if format, ok := arrowKeyMapPrefix[key]; ok { - return fmt.Sprintf(format, escapeSequence, modifier) - } - - if format, ok := keyMapPrefix[key]; ok { - return fmt.Sprintf(format, modifier) - } - - return "" -} - -// getControlKeys extracts the shift, alt, and ctrl key states. -func getControlKeys(controlState uint32) (shift, alt, control bool) { - shift = 0 != (controlState & winterm.SHIFT_PRESSED) - alt = 0 != (controlState & (winterm.LEFT_ALT_PRESSED | winterm.RIGHT_ALT_PRESSED)) - control = 0 != (controlState & (winterm.LEFT_CTRL_PRESSED | winterm.RIGHT_CTRL_PRESSED)) - return shift, alt, control -} - -// getControlKeysModifier returns the ANSI modifier for the given combination of control keys. -func getControlKeysModifier(shift, alt, control bool) string { - if shift && alt && control { - return ansiterm.KEY_CONTROL_PARAM_8 - } - if alt && control { - return ansiterm.KEY_CONTROL_PARAM_7 - } - if shift && control { - return ansiterm.KEY_CONTROL_PARAM_6 - } - if control { - return ansiterm.KEY_CONTROL_PARAM_5 - } - if shift && alt { - return ansiterm.KEY_CONTROL_PARAM_4 - } - if alt { - return ansiterm.KEY_CONTROL_PARAM_3 - } - if shift { - return ansiterm.KEY_CONTROL_PARAM_2 - } - return "" -} diff --git a/vendor/github.com/docker/docker/pkg/term/windows/ansi_writer.go b/vendor/github.com/docker/docker/pkg/term/windows/ansi_writer.go deleted file mode 100644 index a3ce569..0000000 --- a/vendor/github.com/docker/docker/pkg/term/windows/ansi_writer.go +++ /dev/null @@ -1,64 +0,0 @@ -// +build windows - -package windows - -import ( - "io" - "os" - - ansiterm "github.com/Azure/go-ansiterm" - "github.com/Azure/go-ansiterm/winterm" -) - -// ansiWriter wraps a standard output file (e.g., os.Stdout) providing ANSI sequence translation. -type ansiWriter struct { - file *os.File - fd uintptr - infoReset *winterm.CONSOLE_SCREEN_BUFFER_INFO - command []byte - escapeSequence []byte - inAnsiSequence bool - parser *ansiterm.AnsiParser -} - -// NewAnsiWriter returns an io.Writer that provides VT100 terminal emulation on top of a -// Windows console output handle. -func NewAnsiWriter(nFile int) io.Writer { - initLogger() - file, fd := winterm.GetStdFile(nFile) - info, err := winterm.GetConsoleScreenBufferInfo(fd) - if err != nil { - return nil - } - - parser := ansiterm.CreateParser("Ground", winterm.CreateWinEventHandler(fd, file)) - logger.Infof("newAnsiWriter: parser %p", parser) - - aw := &ansiWriter{ - file: file, - fd: fd, - infoReset: info, - command: make([]byte, 0, ansiterm.ANSI_MAX_CMD_LENGTH), - escapeSequence: []byte(ansiterm.KEY_ESC_CSI), - parser: parser, - } - - logger.Infof("newAnsiWriter: aw.parser %p", aw.parser) - logger.Infof("newAnsiWriter: %v", aw) - return aw -} - -func (aw *ansiWriter) Fd() uintptr { - return aw.fd -} - -// Write writes len(p) bytes from p to the underlying data stream. -func (aw *ansiWriter) Write(p []byte) (total int, err error) { - if len(p) == 0 { - return 0, nil - } - - logger.Infof("Write: % x", p) - logger.Infof("Write: %s", string(p)) - return aw.parser.Parse(p) -} diff --git a/vendor/github.com/docker/docker/pkg/term/windows/console.go b/vendor/github.com/docker/docker/pkg/term/windows/console.go deleted file mode 100644 index ca5c3b2..0000000 --- a/vendor/github.com/docker/docker/pkg/term/windows/console.go +++ /dev/null @@ -1,35 +0,0 @@ -// +build windows - -package windows - -import ( - "os" - - "github.com/Azure/go-ansiterm/winterm" -) - -// GetHandleInfo returns file descriptor and bool indicating whether the file is a console. -func GetHandleInfo(in interface{}) (uintptr, bool) { - switch t := in.(type) { - case *ansiReader: - return t.Fd(), true - case *ansiWriter: - return t.Fd(), true - } - - var inFd uintptr - var isTerminal bool - - if file, ok := in.(*os.File); ok { - inFd = file.Fd() - isTerminal = IsConsole(inFd) - } - return inFd, isTerminal -} - -// IsConsole returns true if the given file descriptor is a Windows Console. -// The code assumes that GetConsoleMode will return an error for file descriptors that are not a console. -func IsConsole(fd uintptr) bool { - _, e := winterm.GetConsoleMode(fd) - return e == nil -} diff --git a/vendor/github.com/docker/docker/pkg/term/windows/windows.go b/vendor/github.com/docker/docker/pkg/term/windows/windows.go deleted file mode 100644 index ce4cb59..0000000 --- a/vendor/github.com/docker/docker/pkg/term/windows/windows.go +++ /dev/null @@ -1,33 +0,0 @@ -// These files implement ANSI-aware input and output streams for use by the Docker Windows client. -// When asked for the set of standard streams (e.g., stdin, stdout, stderr), the code will create -// and return pseudo-streams that convert ANSI sequences to / from Windows Console API calls. - -package windows - -import ( - "io/ioutil" - "os" - "sync" - - ansiterm "github.com/Azure/go-ansiterm" - "github.com/Sirupsen/logrus" -) - -var logger *logrus.Logger -var initOnce sync.Once - -func initLogger() { - initOnce.Do(func() { - logFile := ioutil.Discard - - if isDebugEnv := os.Getenv(ansiterm.LogEnv); isDebugEnv == "1" { - logFile, _ = os.Create("ansiReaderWriter.log") - } - - logger = &logrus.Logger{ - Out: logFile, - Formatter: new(logrus.TextFormatter), - Level: logrus.DebugLevel, - } - }) -} diff --git a/vendor/github.com/docker/docker/pkg/term/windows/windows_test.go b/vendor/github.com/docker/docker/pkg/term/windows/windows_test.go deleted file mode 100644 index 52aeab5..0000000 --- a/vendor/github.com/docker/docker/pkg/term/windows/windows_test.go +++ /dev/null @@ -1,3 +0,0 @@ -// This file is necessary to pass the Docker tests. - -package windows diff --git a/vendor/github.com/docker/docker/pkg/testutil/assert/assert.go b/vendor/github.com/docker/docker/pkg/testutil/assert/assert.go deleted file mode 100644 index 6da8518..0000000 --- a/vendor/github.com/docker/docker/pkg/testutil/assert/assert.go +++ /dev/null @@ -1,97 +0,0 @@ -// Package assert contains functions for making assertions in unit tests -package assert - -import ( - "fmt" - "path/filepath" - "reflect" - "runtime" - "strings" - - "github.com/davecgh/go-spew/spew" -) - -// TestingT is an interface which defines the methods of testing.T that are -// required by this package -type TestingT interface { - Fatalf(string, ...interface{}) -} - -// Equal compare the actual value to the expected value and fails the test if -// they are not equal. -func Equal(t TestingT, actual, expected interface{}) { - if expected != actual { - fatal(t, "Expected '%v' (%T) got '%v' (%T)", expected, expected, actual, actual) - } -} - -//EqualStringSlice compares two slices and fails the test if they do not contain -// the same items. -func EqualStringSlice(t TestingT, actual, expected []string) { - if len(actual) != len(expected) { - fatal(t, "Expected (length %d): %q\nActual (length %d): %q", - len(expected), expected, len(actual), actual) - } - for i, item := range actual { - if item != expected[i] { - fatal(t, "Slices differ at element %d, expected %q got %q", - i, expected[i], item) - } - } -} - -// NilError asserts that the error is nil, otherwise it fails the test. -func NilError(t TestingT, err error) { - if err != nil { - fatal(t, "Expected no error, got: %s", err.Error()) - } -} - -// DeepEqual compare the actual value to the expected value and fails the test if -// they are not "deeply equal". -func DeepEqual(t TestingT, actual, expected interface{}) { - if !reflect.DeepEqual(actual, expected) { - fatal(t, "Expected (%T):\n%v\n\ngot (%T):\n%s\n", - expected, spew.Sdump(expected), actual, spew.Sdump(actual)) - } -} - -// Error asserts that error is not nil, and contains the expected text, -// otherwise it fails the test. -func Error(t TestingT, err error, contains string) { - if err == nil { - fatal(t, "Expected an error, but error was nil") - } - - if !strings.Contains(err.Error(), contains) { - fatal(t, "Expected error to contain '%s', got '%s'", contains, err.Error()) - } -} - -// Contains asserts that the string contains a substring, otherwise it fails the -// test. -func Contains(t TestingT, actual, contains string) { - if !strings.Contains(actual, contains) { - fatal(t, "Expected '%s' to contain '%s'", actual, contains) - } -} - -// NotNil fails the test if the object is nil -func NotNil(t TestingT, obj interface{}) { - if obj == nil { - fatal(t, "Expected non-nil value.") - } -} - -func fatal(t TestingT, format string, args ...interface{}) { - t.Fatalf(errorSource()+format, args...) -} - -// See testing.decorate() -func errorSource() string { - _, filename, line, ok := runtime.Caller(3) - if !ok { - return "" - } - return fmt.Sprintf("%s:%d: ", filepath.Base(filename), line) -} diff --git a/vendor/github.com/docker/docker/pkg/testutil/pkg.go b/vendor/github.com/docker/docker/pkg/testutil/pkg.go deleted file mode 100644 index 110b2e6..0000000 --- a/vendor/github.com/docker/docker/pkg/testutil/pkg.go +++ /dev/null @@ -1 +0,0 @@ -package testutil diff --git a/vendor/github.com/docker/docker/pkg/testutil/tempfile/tempfile.go b/vendor/github.com/docker/docker/pkg/testutil/tempfile/tempfile.go deleted file mode 100644 index 0e09d99..0000000 --- a/vendor/github.com/docker/docker/pkg/testutil/tempfile/tempfile.go +++ /dev/null @@ -1,36 +0,0 @@ -package tempfile - -import ( - "io/ioutil" - "os" - - "github.com/docker/docker/pkg/testutil/assert" -) - -// TempFile is a temporary file that can be used with unit tests. TempFile -// reduces the boilerplate setup required in each test case by handling -// setup errors. -type TempFile struct { - File *os.File -} - -// NewTempFile returns a new temp file with contents -func NewTempFile(t assert.TestingT, prefix string, content string) *TempFile { - file, err := ioutil.TempFile("", prefix+"-") - assert.NilError(t, err) - - _, err = file.Write([]byte(content)) - assert.NilError(t, err) - file.Close() - return &TempFile{File: file} -} - -// Name returns the filename -func (f *TempFile) Name() string { - return f.File.Name() -} - -// Remove removes the file -func (f *TempFile) Remove() { - os.Remove(f.Name()) -} diff --git a/vendor/github.com/docker/docker/pkg/tlsconfig/tlsconfig_clone.go b/vendor/github.com/docker/docker/pkg/tlsconfig/tlsconfig_clone.go deleted file mode 100644 index e4dec3a..0000000 --- a/vendor/github.com/docker/docker/pkg/tlsconfig/tlsconfig_clone.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build go1.8 - -package tlsconfig - -import "crypto/tls" - -// Clone returns a clone of tls.Config. This function is provided for -// compatibility for go1.7 that doesn't include this method in stdlib. -func Clone(c *tls.Config) *tls.Config { - return c.Clone() -} diff --git a/vendor/github.com/docker/docker/pkg/tlsconfig/tlsconfig_clone_go16.go b/vendor/github.com/docker/docker/pkg/tlsconfig/tlsconfig_clone_go16.go deleted file mode 100644 index 0b81665..0000000 --- a/vendor/github.com/docker/docker/pkg/tlsconfig/tlsconfig_clone_go16.go +++ /dev/null @@ -1,31 +0,0 @@ -// +build go1.6,!go1.7 - -package tlsconfig - -import "crypto/tls" - -// Clone returns a clone of tls.Config. This function is provided for -// compatibility for go1.6 that doesn't include this method in stdlib. -func Clone(c *tls.Config) *tls.Config { - return &tls.Config{ - Rand: c.Rand, - Time: c.Time, - Certificates: c.Certificates, - NameToCertificate: c.NameToCertificate, - GetCertificate: c.GetCertificate, - RootCAs: c.RootCAs, - NextProtos: c.NextProtos, - ServerName: c.ServerName, - ClientAuth: c.ClientAuth, - ClientCAs: c.ClientCAs, - InsecureSkipVerify: c.InsecureSkipVerify, - CipherSuites: c.CipherSuites, - PreferServerCipherSuites: c.PreferServerCipherSuites, - SessionTicketsDisabled: c.SessionTicketsDisabled, - SessionTicketKey: c.SessionTicketKey, - ClientSessionCache: c.ClientSessionCache, - MinVersion: c.MinVersion, - MaxVersion: c.MaxVersion, - CurvePreferences: c.CurvePreferences, - } -} diff --git a/vendor/github.com/docker/docker/pkg/tlsconfig/tlsconfig_clone_go17.go b/vendor/github.com/docker/docker/pkg/tlsconfig/tlsconfig_clone_go17.go deleted file mode 100644 index 0d5b448..0000000 --- a/vendor/github.com/docker/docker/pkg/tlsconfig/tlsconfig_clone_go17.go +++ /dev/null @@ -1,33 +0,0 @@ -// +build go1.7,!go1.8 - -package tlsconfig - -import "crypto/tls" - -// Clone returns a clone of tls.Config. This function is provided for -// compatibility for go1.7 that doesn't include this method in stdlib. -func Clone(c *tls.Config) *tls.Config { - return &tls.Config{ - Rand: c.Rand, - Time: c.Time, - Certificates: c.Certificates, - NameToCertificate: c.NameToCertificate, - GetCertificate: c.GetCertificate, - RootCAs: c.RootCAs, - NextProtos: c.NextProtos, - ServerName: c.ServerName, - ClientAuth: c.ClientAuth, - ClientCAs: c.ClientCAs, - InsecureSkipVerify: c.InsecureSkipVerify, - CipherSuites: c.CipherSuites, - PreferServerCipherSuites: c.PreferServerCipherSuites, - SessionTicketsDisabled: c.SessionTicketsDisabled, - SessionTicketKey: c.SessionTicketKey, - ClientSessionCache: c.ClientSessionCache, - MinVersion: c.MinVersion, - MaxVersion: c.MaxVersion, - CurvePreferences: c.CurvePreferences, - DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled, - Renegotiation: c.Renegotiation, - } -} diff --git a/vendor/github.com/docker/docker/pkg/truncindex/truncindex.go b/vendor/github.com/docker/docker/pkg/truncindex/truncindex.go deleted file mode 100644 index 02610b8..0000000 --- a/vendor/github.com/docker/docker/pkg/truncindex/truncindex.go +++ /dev/null @@ -1,137 +0,0 @@ -// Package truncindex provides a general 'index tree', used by Docker -// in order to be able to reference containers by only a few unambiguous -// characters of their id. -package truncindex - -import ( - "errors" - "fmt" - "strings" - "sync" - - "github.com/tchap/go-patricia/patricia" -) - -var ( - // ErrEmptyPrefix is an error returned if the prefix was empty. - ErrEmptyPrefix = errors.New("Prefix can't be empty") - - // ErrIllegalChar is returned when a space is in the ID - ErrIllegalChar = errors.New("illegal character: ' '") - - // ErrNotExist is returned when ID or its prefix not found in index. - ErrNotExist = errors.New("ID does not exist") -) - -// ErrAmbiguousPrefix is returned if the prefix was ambiguous -// (multiple ids for the prefix). -type ErrAmbiguousPrefix struct { - prefix string -} - -func (e ErrAmbiguousPrefix) Error() string { - return fmt.Sprintf("Multiple IDs found with provided prefix: %s", e.prefix) -} - -// TruncIndex allows the retrieval of string identifiers by any of their unique prefixes. -// This is used to retrieve image and container IDs by more convenient shorthand prefixes. -type TruncIndex struct { - sync.RWMutex - trie *patricia.Trie - ids map[string]struct{} -} - -// NewTruncIndex creates a new TruncIndex and initializes with a list of IDs. -func NewTruncIndex(ids []string) (idx *TruncIndex) { - idx = &TruncIndex{ - ids: make(map[string]struct{}), - - // Change patricia max prefix per node length, - // because our len(ID) always 64 - trie: patricia.NewTrie(patricia.MaxPrefixPerNode(64)), - } - for _, id := range ids { - idx.addID(id) - } - return -} - -func (idx *TruncIndex) addID(id string) error { - if strings.Contains(id, " ") { - return ErrIllegalChar - } - if id == "" { - return ErrEmptyPrefix - } - if _, exists := idx.ids[id]; exists { - return fmt.Errorf("id already exists: '%s'", id) - } - idx.ids[id] = struct{}{} - if inserted := idx.trie.Insert(patricia.Prefix(id), struct{}{}); !inserted { - return fmt.Errorf("failed to insert id: %s", id) - } - return nil -} - -// Add adds a new ID to the TruncIndex. -func (idx *TruncIndex) Add(id string) error { - idx.Lock() - defer idx.Unlock() - if err := idx.addID(id); err != nil { - return err - } - return nil -} - -// Delete removes an ID from the TruncIndex. If there are multiple IDs -// with the given prefix, an error is thrown. -func (idx *TruncIndex) Delete(id string) error { - idx.Lock() - defer idx.Unlock() - if _, exists := idx.ids[id]; !exists || id == "" { - return fmt.Errorf("no such id: '%s'", id) - } - delete(idx.ids, id) - if deleted := idx.trie.Delete(patricia.Prefix(id)); !deleted { - return fmt.Errorf("no such id: '%s'", id) - } - return nil -} - -// Get retrieves an ID from the TruncIndex. If there are multiple IDs -// with the given prefix, an error is thrown. -func (idx *TruncIndex) Get(s string) (string, error) { - if s == "" { - return "", ErrEmptyPrefix - } - var ( - id string - ) - subTreeVisitFunc := func(prefix patricia.Prefix, item patricia.Item) error { - if id != "" { - // we haven't found the ID if there are two or more IDs - id = "" - return ErrAmbiguousPrefix{prefix: string(prefix)} - } - id = string(prefix) - return nil - } - - idx.RLock() - defer idx.RUnlock() - if err := idx.trie.VisitSubtree(patricia.Prefix(s), subTreeVisitFunc); err != nil { - return "", err - } - if id != "" { - return id, nil - } - return "", ErrNotExist -} - -// Iterate iterates over all stored IDs, and passes each of them to the given handler. -func (idx *TruncIndex) Iterate(handler func(id string)) { - idx.trie.Visit(func(prefix patricia.Prefix, item patricia.Item) error { - handler(string(prefix)) - return nil - }) -} diff --git a/vendor/github.com/docker/docker/pkg/truncindex/truncindex_test.go b/vendor/github.com/docker/docker/pkg/truncindex/truncindex_test.go deleted file mode 100644 index 8197baf..0000000 --- a/vendor/github.com/docker/docker/pkg/truncindex/truncindex_test.go +++ /dev/null @@ -1,429 +0,0 @@ -package truncindex - -import ( - "math/rand" - "testing" - - "github.com/docker/docker/pkg/stringid" -) - -// Test the behavior of TruncIndex, an index for querying IDs from a non-conflicting prefix. -func TestTruncIndex(t *testing.T) { - ids := []string{} - index := NewTruncIndex(ids) - // Get on an empty index - if _, err := index.Get("foobar"); err == nil { - t.Fatal("Get on an empty index should return an error") - } - - // Spaces should be illegal in an id - if err := index.Add("I have a space"); err == nil { - t.Fatalf("Adding an id with ' ' should return an error") - } - - id := "99b36c2c326ccc11e726eee6ee78a0baf166ef96" - // Add an id - if err := index.Add(id); err != nil { - t.Fatal(err) - } - - // Add an empty id (should fail) - if err := index.Add(""); err == nil { - t.Fatalf("Adding an empty id should return an error") - } - - // Get a non-existing id - assertIndexGet(t, index, "abracadabra", "", true) - // Get an empty id - assertIndexGet(t, index, "", "", true) - // Get the exact id - assertIndexGet(t, index, id, id, false) - // The first letter should match - assertIndexGet(t, index, id[:1], id, false) - // The first half should match - assertIndexGet(t, index, id[:len(id)/2], id, false) - // The second half should NOT match - assertIndexGet(t, index, id[len(id)/2:], "", true) - - id2 := id[:6] + "blabla" - // Add an id - if err := index.Add(id2); err != nil { - t.Fatal(err) - } - // Both exact IDs should work - assertIndexGet(t, index, id, id, false) - assertIndexGet(t, index, id2, id2, false) - - // 6 characters or less should conflict - assertIndexGet(t, index, id[:6], "", true) - assertIndexGet(t, index, id[:4], "", true) - assertIndexGet(t, index, id[:1], "", true) - - // An ambiguous id prefix should return an error - if _, err := index.Get(id[:4]); err == nil { - t.Fatal("An ambiguous id prefix should return an error") - } - - // 7 characters should NOT conflict - assertIndexGet(t, index, id[:7], id, false) - assertIndexGet(t, index, id2[:7], id2, false) - - // Deleting a non-existing id should return an error - if err := index.Delete("non-existing"); err == nil { - t.Fatalf("Deleting a non-existing id should return an error") - } - - // Deleting an empty id should return an error - if err := index.Delete(""); err == nil { - t.Fatal("Deleting an empty id should return an error") - } - - // Deleting id2 should remove conflicts - if err := index.Delete(id2); err != nil { - t.Fatal(err) - } - // id2 should no longer work - assertIndexGet(t, index, id2, "", true) - assertIndexGet(t, index, id2[:7], "", true) - assertIndexGet(t, index, id2[:11], "", true) - - // conflicts between id and id2 should be gone - assertIndexGet(t, index, id[:6], id, false) - assertIndexGet(t, index, id[:4], id, false) - assertIndexGet(t, index, id[:1], id, false) - - // non-conflicting substrings should still not conflict - assertIndexGet(t, index, id[:7], id, false) - assertIndexGet(t, index, id[:15], id, false) - assertIndexGet(t, index, id, id, false) - - assertIndexIterate(t) -} - -func assertIndexIterate(t *testing.T) { - ids := []string{ - "19b36c2c326ccc11e726eee6ee78a0baf166ef96", - "28b36c2c326ccc11e726eee6ee78a0baf166ef96", - "37b36c2c326ccc11e726eee6ee78a0baf166ef96", - "46b36c2c326ccc11e726eee6ee78a0baf166ef96", - } - - index := NewTruncIndex(ids) - - index.Iterate(func(targetId string) { - for _, id := range ids { - if targetId == id { - return - } - } - - t.Fatalf("An unknown ID '%s'", targetId) - }) -} - -func assertIndexGet(t *testing.T, index *TruncIndex, input, expectedResult string, expectError bool) { - if result, err := index.Get(input); err != nil && !expectError { - t.Fatalf("Unexpected error getting '%s': %s", input, err) - } else if err == nil && expectError { - t.Fatalf("Getting '%s' should return an error, not '%s'", input, result) - } else if result != expectedResult { - t.Fatalf("Getting '%s' returned '%s' instead of '%s'", input, result, expectedResult) - } -} - -func BenchmarkTruncIndexAdd100(b *testing.B) { - var testSet []string - for i := 0; i < 100; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - } - } -} - -func BenchmarkTruncIndexAdd250(b *testing.B) { - var testSet []string - for i := 0; i < 250; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - } - } -} - -func BenchmarkTruncIndexAdd500(b *testing.B) { - var testSet []string - for i := 0; i < 500; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - } - } -} - -func BenchmarkTruncIndexGet100(b *testing.B) { - var testSet []string - var testKeys []string - for i := 0; i < 100; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - l := rand.Intn(12) + 12 - testKeys = append(testKeys, id[:l]) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - for _, id := range testKeys { - if res, err := index.Get(id); err != nil { - b.Fatal(res, err) - } - } - } -} - -func BenchmarkTruncIndexGet250(b *testing.B) { - var testSet []string - var testKeys []string - for i := 0; i < 250; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - l := rand.Intn(12) + 12 - testKeys = append(testKeys, id[:l]) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - for _, id := range testKeys { - if res, err := index.Get(id); err != nil { - b.Fatal(res, err) - } - } - } -} - -func BenchmarkTruncIndexGet500(b *testing.B) { - var testSet []string - var testKeys []string - for i := 0; i < 500; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - l := rand.Intn(12) + 12 - testKeys = append(testKeys, id[:l]) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - for _, id := range testKeys { - if res, err := index.Get(id); err != nil { - b.Fatal(res, err) - } - } - } -} - -func BenchmarkTruncIndexDelete100(b *testing.B) { - var testSet []string - for i := 0; i < 100; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - b.StopTimer() - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - } - b.StartTimer() - for _, id := range testSet { - if err := index.Delete(id); err != nil { - b.Fatal(err) - } - } - } -} - -func BenchmarkTruncIndexDelete250(b *testing.B) { - var testSet []string - for i := 0; i < 250; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - b.StopTimer() - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - } - b.StartTimer() - for _, id := range testSet { - if err := index.Delete(id); err != nil { - b.Fatal(err) - } - } - } -} - -func BenchmarkTruncIndexDelete500(b *testing.B) { - var testSet []string - for i := 0; i < 500; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - b.StopTimer() - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - } - b.StartTimer() - for _, id := range testSet { - if err := index.Delete(id); err != nil { - b.Fatal(err) - } - } - } -} - -func BenchmarkTruncIndexNew100(b *testing.B) { - var testSet []string - for i := 0; i < 100; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - NewTruncIndex(testSet) - } -} - -func BenchmarkTruncIndexNew250(b *testing.B) { - var testSet []string - for i := 0; i < 250; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - NewTruncIndex(testSet) - } -} - -func BenchmarkTruncIndexNew500(b *testing.B) { - var testSet []string - for i := 0; i < 500; i++ { - testSet = append(testSet, stringid.GenerateNonCryptoID()) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - NewTruncIndex(testSet) - } -} - -func BenchmarkTruncIndexAddGet100(b *testing.B) { - var testSet []string - var testKeys []string - for i := 0; i < 500; i++ { - id := stringid.GenerateNonCryptoID() - testSet = append(testSet, id) - l := rand.Intn(12) + 12 - testKeys = append(testKeys, id[:l]) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - } - for _, id := range testKeys { - if res, err := index.Get(id); err != nil { - b.Fatal(res, err) - } - } - } -} - -func BenchmarkTruncIndexAddGet250(b *testing.B) { - var testSet []string - var testKeys []string - for i := 0; i < 500; i++ { - id := stringid.GenerateNonCryptoID() - testSet = append(testSet, id) - l := rand.Intn(12) + 12 - testKeys = append(testKeys, id[:l]) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - } - for _, id := range testKeys { - if res, err := index.Get(id); err != nil { - b.Fatal(res, err) - } - } - } -} - -func BenchmarkTruncIndexAddGet500(b *testing.B) { - var testSet []string - var testKeys []string - for i := 0; i < 500; i++ { - id := stringid.GenerateNonCryptoID() - testSet = append(testSet, id) - l := rand.Intn(12) + 12 - testKeys = append(testKeys, id[:l]) - } - b.ResetTimer() - for i := 0; i < b.N; i++ { - index := NewTruncIndex([]string{}) - for _, id := range testSet { - if err := index.Add(id); err != nil { - b.Fatal(err) - } - } - for _, id := range testKeys { - if res, err := index.Get(id); err != nil { - b.Fatal(res, err) - } - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/urlutil/urlutil.go b/vendor/github.com/docker/docker/pkg/urlutil/urlutil.go deleted file mode 100644 index 4415287..0000000 --- a/vendor/github.com/docker/docker/pkg/urlutil/urlutil.go +++ /dev/null @@ -1,50 +0,0 @@ -// Package urlutil provides helper function to check urls kind. -// It supports http urls, git urls and transport url (tcp://, …) -package urlutil - -import ( - "regexp" - "strings" -) - -var ( - validPrefixes = map[string][]string{ - "url": {"http://", "https://"}, - "git": {"git://", "github.com/", "git@"}, - "transport": {"tcp://", "tcp+tls://", "udp://", "unix://", "unixgram://"}, - } - urlPathWithFragmentSuffix = regexp.MustCompile(".git(?:#.+)?$") -) - -// IsURL returns true if the provided str is an HTTP(S) URL. -func IsURL(str string) bool { - return checkURL(str, "url") -} - -// IsGitURL returns true if the provided str is a git repository URL. -func IsGitURL(str string) bool { - if IsURL(str) && urlPathWithFragmentSuffix.MatchString(str) { - return true - } - return checkURL(str, "git") -} - -// IsGitTransport returns true if the provided str is a git transport by inspecting -// the prefix of the string for known protocols used in git. -func IsGitTransport(str string) bool { - return IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@") -} - -// IsTransportURL returns true if the provided str is a transport (tcp, tcp+tls, udp, unix) URL. -func IsTransportURL(str string) bool { - return checkURL(str, "transport") -} - -func checkURL(str, kind string) bool { - for _, prefix := range validPrefixes[kind] { - if strings.HasPrefix(str, prefix) { - return true - } - } - return false -} diff --git a/vendor/github.com/docker/docker/pkg/urlutil/urlutil_test.go b/vendor/github.com/docker/docker/pkg/urlutil/urlutil_test.go deleted file mode 100644 index 75eb464..0000000 --- a/vendor/github.com/docker/docker/pkg/urlutil/urlutil_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package urlutil - -import "testing" - -var ( - gitUrls = []string{ - "git://github.com/docker/docker", - "git@github.com:docker/docker.git", - "git@bitbucket.org:atlassianlabs/atlassian-docker.git", - "https://github.com/docker/docker.git", - "http://github.com/docker/docker.git", - "http://github.com/docker/docker.git#branch", - "http://github.com/docker/docker.git#:dir", - } - incompleteGitUrls = []string{ - "github.com/docker/docker", - } - invalidGitUrls = []string{ - "http://github.com/docker/docker.git:#branch", - } - transportUrls = []string{ - "tcp://example.com", - "tcp+tls://example.com", - "udp://example.com", - "unix:///example", - "unixgram:///example", - } -) - -func TestValidGitTransport(t *testing.T) { - for _, url := range gitUrls { - if IsGitTransport(url) == false { - t.Fatalf("%q should be detected as valid Git prefix", url) - } - } - - for _, url := range incompleteGitUrls { - if IsGitTransport(url) == true { - t.Fatalf("%q should not be detected as valid Git prefix", url) - } - } -} - -func TestIsGIT(t *testing.T) { - for _, url := range gitUrls { - if IsGitURL(url) == false { - t.Fatalf("%q should be detected as valid Git url", url) - } - } - - for _, url := range incompleteGitUrls { - if IsGitURL(url) == false { - t.Fatalf("%q should be detected as valid Git url", url) - } - } - - for _, url := range invalidGitUrls { - if IsGitURL(url) == true { - t.Fatalf("%q should not be detected as valid Git prefix", url) - } - } -} - -func TestIsTransport(t *testing.T) { - for _, url := range transportUrls { - if IsTransportURL(url) == false { - t.Fatalf("%q should be detected as valid Transport url", url) - } - } -} diff --git a/vendor/github.com/docker/docker/pkg/useragent/README.md b/vendor/github.com/docker/docker/pkg/useragent/README.md deleted file mode 100644 index d9cb367..0000000 --- a/vendor/github.com/docker/docker/pkg/useragent/README.md +++ /dev/null @@ -1 +0,0 @@ -This package provides helper functions to pack version information into a single User-Agent header. diff --git a/vendor/github.com/docker/docker/pkg/useragent/useragent.go b/vendor/github.com/docker/docker/pkg/useragent/useragent.go deleted file mode 100644 index 1137db5..0000000 --- a/vendor/github.com/docker/docker/pkg/useragent/useragent.go +++ /dev/null @@ -1,55 +0,0 @@ -// Package useragent provides helper functions to pack -// version information into a single User-Agent header. -package useragent - -import ( - "strings" -) - -// VersionInfo is used to model UserAgent versions. -type VersionInfo struct { - Name string - Version string -} - -func (vi *VersionInfo) isValid() bool { - const stopChars = " \t\r\n/" - name := vi.Name - vers := vi.Version - if len(name) == 0 || strings.ContainsAny(name, stopChars) { - return false - } - if len(vers) == 0 || strings.ContainsAny(vers, stopChars) { - return false - } - return true -} - -// AppendVersions converts versions to a string and appends the string to the string base. -// -// Each VersionInfo will be converted to a string in the format of -// "product/version", where the "product" is get from the name field, while -// version is get from the version field. Several pieces of version information -// will be concatenated and separated by space. -// -// Example: -// AppendVersions("base", VersionInfo{"foo", "1.0"}, VersionInfo{"bar", "2.0"}) -// results in "base foo/1.0 bar/2.0". -func AppendVersions(base string, versions ...VersionInfo) string { - if len(versions) == 0 { - return base - } - - verstrs := make([]string, 0, 1+len(versions)) - if len(base) > 0 { - verstrs = append(verstrs, base) - } - - for _, v := range versions { - if !v.isValid() { - continue - } - verstrs = append(verstrs, v.Name+"/"+v.Version) - } - return strings.Join(verstrs, " ") -} diff --git a/vendor/github.com/docker/docker/pkg/useragent/useragent_test.go b/vendor/github.com/docker/docker/pkg/useragent/useragent_test.go deleted file mode 100644 index 0ad7243..0000000 --- a/vendor/github.com/docker/docker/pkg/useragent/useragent_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package useragent - -import "testing" - -func TestVersionInfo(t *testing.T) { - vi := VersionInfo{"foo", "bar"} - if !vi.isValid() { - t.Fatalf("VersionInfo should be valid") - } - vi = VersionInfo{"", "bar"} - if vi.isValid() { - t.Fatalf("Expected VersionInfo to be invalid") - } - vi = VersionInfo{"foo", ""} - if vi.isValid() { - t.Fatalf("Expected VersionInfo to be invalid") - } -} - -func TestAppendVersions(t *testing.T) { - vis := []VersionInfo{ - {"foo", "1.0"}, - {"bar", "0.1"}, - {"pi", "3.1.4"}, - } - v := AppendVersions("base", vis...) - expect := "base foo/1.0 bar/0.1 pi/3.1.4" - if v != expect { - t.Fatalf("expected %q, got %q", expect, v) - } -} diff --git a/vendor/github.com/docker/docker/plugin/backend_linux.go b/vendor/github.com/docker/docker/plugin/backend_linux.go deleted file mode 100644 index 33200d8..0000000 --- a/vendor/github.com/docker/docker/plugin/backend_linux.go +++ /dev/null @@ -1,790 +0,0 @@ -// +build linux - -package plugin - -import ( - "archive/tar" - "compress/gzip" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net/http" - "os" - "path" - "path/filepath" - "sort" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/distribution/manifest/schema2" - "github.com/docker/docker/api/types" - "github.com/docker/docker/distribution" - progressutils "github.com/docker/docker/distribution/utils" - "github.com/docker/docker/distribution/xfer" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/chrootarchive" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/pools" - "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/plugin/v2" - "github.com/docker/docker/reference" - "github.com/pkg/errors" - "golang.org/x/net/context" -) - -// Disable deactivates a plugin. This means resources (volumes, networks) cant use them. -func (pm *Manager) Disable(refOrID string, config *types.PluginDisableConfig) error { - p, err := pm.config.Store.GetV2Plugin(refOrID) - if err != nil { - return err - } - pm.mu.RLock() - c := pm.cMap[p] - pm.mu.RUnlock() - - if !config.ForceDisable && p.GetRefCount() > 0 { - return fmt.Errorf("plugin %s is in use", p.Name()) - } - - if err := pm.disable(p, c); err != nil { - return err - } - pm.config.LogPluginEvent(p.GetID(), refOrID, "disable") - return nil -} - -// Enable activates a plugin, which implies that they are ready to be used by containers. -func (pm *Manager) Enable(refOrID string, config *types.PluginEnableConfig) error { - p, err := pm.config.Store.GetV2Plugin(refOrID) - if err != nil { - return err - } - - c := &controller{timeoutInSecs: config.Timeout} - if err := pm.enable(p, c, false); err != nil { - return err - } - pm.config.LogPluginEvent(p.GetID(), refOrID, "enable") - return nil -} - -// Inspect examines a plugin config -func (pm *Manager) Inspect(refOrID string) (tp *types.Plugin, err error) { - p, err := pm.config.Store.GetV2Plugin(refOrID) - if err != nil { - return nil, err - } - - return &p.PluginObj, nil -} - -func (pm *Manager) pull(ctx context.Context, ref reference.Named, config *distribution.ImagePullConfig, outStream io.Writer) error { - if outStream != nil { - // Include a buffer so that slow client connections don't affect - // transfer performance. - progressChan := make(chan progress.Progress, 100) - - writesDone := make(chan struct{}) - - defer func() { - close(progressChan) - <-writesDone - }() - - var cancelFunc context.CancelFunc - ctx, cancelFunc = context.WithCancel(ctx) - - go func() { - progressutils.WriteDistributionProgress(cancelFunc, outStream, progressChan) - close(writesDone) - }() - - config.ProgressOutput = progress.ChanOutput(progressChan) - } else { - config.ProgressOutput = progress.DiscardOutput() - } - return distribution.Pull(ctx, ref, config) -} - -type tempConfigStore struct { - config []byte - configDigest digest.Digest -} - -func (s *tempConfigStore) Put(c []byte) (digest.Digest, error) { - dgst := digest.FromBytes(c) - - s.config = c - s.configDigest = dgst - - return dgst, nil -} - -func (s *tempConfigStore) Get(d digest.Digest) ([]byte, error) { - if d != s.configDigest { - return nil, digest.ErrDigestNotFound - } - return s.config, nil -} - -func (s *tempConfigStore) RootFSFromConfig(c []byte) (*image.RootFS, error) { - return configToRootFS(c) -} - -func computePrivileges(c types.PluginConfig) (types.PluginPrivileges, error) { - var privileges types.PluginPrivileges - if c.Network.Type != "null" && c.Network.Type != "bridge" && c.Network.Type != "" { - privileges = append(privileges, types.PluginPrivilege{ - Name: "network", - Description: "permissions to access a network", - Value: []string{c.Network.Type}, - }) - } - for _, mount := range c.Mounts { - if mount.Source != nil { - privileges = append(privileges, types.PluginPrivilege{ - Name: "mount", - Description: "host path to mount", - Value: []string{*mount.Source}, - }) - } - } - for _, device := range c.Linux.Devices { - if device.Path != nil { - privileges = append(privileges, types.PluginPrivilege{ - Name: "device", - Description: "host device to access", - Value: []string{*device.Path}, - }) - } - } - if c.Linux.AllowAllDevices { - privileges = append(privileges, types.PluginPrivilege{ - Name: "allow-all-devices", - Description: "allow 'rwm' access to all devices", - Value: []string{"true"}, - }) - } - if len(c.Linux.Capabilities) > 0 { - privileges = append(privileges, types.PluginPrivilege{ - Name: "capabilities", - Description: "list of additional capabilities required", - Value: c.Linux.Capabilities, - }) - } - - return privileges, nil -} - -// Privileges pulls a plugin config and computes the privileges required to install it. -func (pm *Manager) Privileges(ctx context.Context, ref reference.Named, metaHeader http.Header, authConfig *types.AuthConfig) (types.PluginPrivileges, error) { - // create image store instance - cs := &tempConfigStore{} - - // DownloadManager not defined because only pulling configuration. - pluginPullConfig := &distribution.ImagePullConfig{ - Config: distribution.Config{ - MetaHeaders: metaHeader, - AuthConfig: authConfig, - RegistryService: pm.config.RegistryService, - ImageEventLogger: func(string, string, string) {}, - ImageStore: cs, - }, - Schema2Types: distribution.PluginTypes, - } - - if err := pm.pull(ctx, ref, pluginPullConfig, nil); err != nil { - return nil, err - } - - if cs.config == nil { - return nil, errors.New("no configuration pulled") - } - var config types.PluginConfig - if err := json.Unmarshal(cs.config, &config); err != nil { - return nil, err - } - - return computePrivileges(config) -} - -// Upgrade upgrades a plugin -func (pm *Manager) Upgrade(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *types.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer) (err error) { - p, err := pm.config.Store.GetV2Plugin(name) - if err != nil { - return errors.Wrap(err, "plugin must be installed before upgrading") - } - - if p.IsEnabled() { - return fmt.Errorf("plugin must be disabled before upgrading") - } - - pm.muGC.RLock() - defer pm.muGC.RUnlock() - - // revalidate because Pull is public - nameref, err := reference.ParseNamed(name) - if err != nil { - return errors.Wrapf(err, "failed to parse %q", name) - } - name = reference.WithDefaultTag(nameref).String() - - tmpRootFSDir, err := ioutil.TempDir(pm.tmpDir(), ".rootfs") - defer os.RemoveAll(tmpRootFSDir) - - dm := &downloadManager{ - tmpDir: tmpRootFSDir, - blobStore: pm.blobStore, - } - - pluginPullConfig := &distribution.ImagePullConfig{ - Config: distribution.Config{ - MetaHeaders: metaHeader, - AuthConfig: authConfig, - RegistryService: pm.config.RegistryService, - ImageEventLogger: pm.config.LogPluginEvent, - ImageStore: dm, - }, - DownloadManager: dm, // todo: reevaluate if possible to substitute distribution/xfer dependencies instead - Schema2Types: distribution.PluginTypes, - } - - err = pm.pull(ctx, ref, pluginPullConfig, outStream) - if err != nil { - go pm.GC() - return err - } - - if err := pm.upgradePlugin(p, dm.configDigest, dm.blobs, tmpRootFSDir, &privileges); err != nil { - return err - } - p.PluginObj.PluginReference = ref.String() - return nil -} - -// Pull pulls a plugin, check if the correct privileges are provided and install the plugin. -func (pm *Manager) Pull(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *types.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer) (err error) { - pm.muGC.RLock() - defer pm.muGC.RUnlock() - - // revalidate because Pull is public - nameref, err := reference.ParseNamed(name) - if err != nil { - return errors.Wrapf(err, "failed to parse %q", name) - } - name = reference.WithDefaultTag(nameref).String() - - if err := pm.config.Store.validateName(name); err != nil { - return err - } - - tmpRootFSDir, err := ioutil.TempDir(pm.tmpDir(), ".rootfs") - defer os.RemoveAll(tmpRootFSDir) - - dm := &downloadManager{ - tmpDir: tmpRootFSDir, - blobStore: pm.blobStore, - } - - pluginPullConfig := &distribution.ImagePullConfig{ - Config: distribution.Config{ - MetaHeaders: metaHeader, - AuthConfig: authConfig, - RegistryService: pm.config.RegistryService, - ImageEventLogger: pm.config.LogPluginEvent, - ImageStore: dm, - }, - DownloadManager: dm, // todo: reevaluate if possible to substitute distribution/xfer dependencies instead - Schema2Types: distribution.PluginTypes, - } - - err = pm.pull(ctx, ref, pluginPullConfig, outStream) - if err != nil { - go pm.GC() - return err - } - - p, err := pm.createPlugin(name, dm.configDigest, dm.blobs, tmpRootFSDir, &privileges) - if err != nil { - return err - } - p.PluginObj.PluginReference = ref.String() - - return nil -} - -// List displays the list of plugins and associated metadata. -func (pm *Manager) List() ([]types.Plugin, error) { - plugins := pm.config.Store.GetAll() - out := make([]types.Plugin, 0, len(plugins)) - for _, p := range plugins { - out = append(out, p.PluginObj) - } - return out, nil -} - -// Push pushes a plugin to the store. -func (pm *Manager) Push(ctx context.Context, name string, metaHeader http.Header, authConfig *types.AuthConfig, outStream io.Writer) error { - p, err := pm.config.Store.GetV2Plugin(name) - if err != nil { - return err - } - - ref, err := reference.ParseNamed(p.Name()) - if err != nil { - return errors.Wrapf(err, "plugin has invalid name %v for push", p.Name()) - } - - var po progress.Output - if outStream != nil { - // Include a buffer so that slow client connections don't affect - // transfer performance. - progressChan := make(chan progress.Progress, 100) - - writesDone := make(chan struct{}) - - defer func() { - close(progressChan) - <-writesDone - }() - - var cancelFunc context.CancelFunc - ctx, cancelFunc = context.WithCancel(ctx) - - go func() { - progressutils.WriteDistributionProgress(cancelFunc, outStream, progressChan) - close(writesDone) - }() - - po = progress.ChanOutput(progressChan) - } else { - po = progress.DiscardOutput() - } - - // TODO: replace these with manager - is := &pluginConfigStore{ - pm: pm, - plugin: p, - } - ls := &pluginLayerProvider{ - pm: pm, - plugin: p, - } - rs := &pluginReference{ - name: ref, - pluginID: p.Config, - } - - uploadManager := xfer.NewLayerUploadManager(3) - - imagePushConfig := &distribution.ImagePushConfig{ - Config: distribution.Config{ - MetaHeaders: metaHeader, - AuthConfig: authConfig, - ProgressOutput: po, - RegistryService: pm.config.RegistryService, - ReferenceStore: rs, - ImageEventLogger: pm.config.LogPluginEvent, - ImageStore: is, - RequireSchema2: true, - }, - ConfigMediaType: schema2.MediaTypePluginConfig, - LayerStore: ls, - UploadManager: uploadManager, - } - - return distribution.Push(ctx, ref, imagePushConfig) -} - -type pluginReference struct { - name reference.Named - pluginID digest.Digest -} - -func (r *pluginReference) References(id digest.Digest) []reference.Named { - if r.pluginID != id { - return nil - } - return []reference.Named{r.name} -} - -func (r *pluginReference) ReferencesByName(ref reference.Named) []reference.Association { - return []reference.Association{ - { - Ref: r.name, - ID: r.pluginID, - }, - } -} - -func (r *pluginReference) Get(ref reference.Named) (digest.Digest, error) { - if r.name.String() != ref.String() { - return digest.Digest(""), reference.ErrDoesNotExist - } - return r.pluginID, nil -} - -func (r *pluginReference) AddTag(ref reference.Named, id digest.Digest, force bool) error { - // Read only, ignore - return nil -} -func (r *pluginReference) AddDigest(ref reference.Canonical, id digest.Digest, force bool) error { - // Read only, ignore - return nil -} -func (r *pluginReference) Delete(ref reference.Named) (bool, error) { - // Read only, ignore - return false, nil -} - -type pluginConfigStore struct { - pm *Manager - plugin *v2.Plugin -} - -func (s *pluginConfigStore) Put([]byte) (digest.Digest, error) { - return digest.Digest(""), errors.New("cannot store config on push") -} - -func (s *pluginConfigStore) Get(d digest.Digest) ([]byte, error) { - if s.plugin.Config != d { - return nil, errors.New("plugin not found") - } - rwc, err := s.pm.blobStore.Get(d) - if err != nil { - return nil, err - } - defer rwc.Close() - return ioutil.ReadAll(rwc) -} - -func (s *pluginConfigStore) RootFSFromConfig(c []byte) (*image.RootFS, error) { - return configToRootFS(c) -} - -type pluginLayerProvider struct { - pm *Manager - plugin *v2.Plugin -} - -func (p *pluginLayerProvider) Get(id layer.ChainID) (distribution.PushLayer, error) { - rootFS := rootFSFromPlugin(p.plugin.PluginObj.Config.Rootfs) - var i int - for i = 1; i <= len(rootFS.DiffIDs); i++ { - if layer.CreateChainID(rootFS.DiffIDs[:i]) == id { - break - } - } - if i > len(rootFS.DiffIDs) { - return nil, errors.New("layer not found") - } - return &pluginLayer{ - pm: p.pm, - diffIDs: rootFS.DiffIDs[:i], - blobs: p.plugin.Blobsums[:i], - }, nil -} - -type pluginLayer struct { - pm *Manager - diffIDs []layer.DiffID - blobs []digest.Digest -} - -func (l *pluginLayer) ChainID() layer.ChainID { - return layer.CreateChainID(l.diffIDs) -} - -func (l *pluginLayer) DiffID() layer.DiffID { - return l.diffIDs[len(l.diffIDs)-1] -} - -func (l *pluginLayer) Parent() distribution.PushLayer { - if len(l.diffIDs) == 1 { - return nil - } - return &pluginLayer{ - pm: l.pm, - diffIDs: l.diffIDs[:len(l.diffIDs)-1], - blobs: l.blobs[:len(l.diffIDs)-1], - } -} - -func (l *pluginLayer) Open() (io.ReadCloser, error) { - return l.pm.blobStore.Get(l.blobs[len(l.diffIDs)-1]) -} - -func (l *pluginLayer) Size() (int64, error) { - return l.pm.blobStore.Size(l.blobs[len(l.diffIDs)-1]) -} - -func (l *pluginLayer) MediaType() string { - return schema2.MediaTypeLayer -} - -func (l *pluginLayer) Release() { - // Nothing needs to be release, no references held -} - -// Remove deletes plugin's root directory. -func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error { - p, err := pm.config.Store.GetV2Plugin(name) - pm.mu.RLock() - c := pm.cMap[p] - pm.mu.RUnlock() - - if err != nil { - return err - } - - if !config.ForceRemove { - if p.GetRefCount() > 0 { - return fmt.Errorf("plugin %s is in use", p.Name()) - } - if p.IsEnabled() { - return fmt.Errorf("plugin %s is enabled", p.Name()) - } - } - - if p.IsEnabled() { - if err := pm.disable(p, c); err != nil { - logrus.Errorf("failed to disable plugin '%s': %s", p.Name(), err) - } - } - - defer func() { - go pm.GC() - }() - - id := p.GetID() - pm.config.Store.Remove(p) - pluginDir := filepath.Join(pm.config.Root, id) - if err := recursiveUnmount(pm.config.Root); err != nil { - logrus.WithField("dir", pm.config.Root).WithField("id", id).Warn(err) - } - if err := os.RemoveAll(pluginDir); err != nil { - logrus.Warnf("unable to remove %q from plugin remove: %v", pluginDir, err) - } - pm.config.LogPluginEvent(id, name, "remove") - return nil -} - -func getMounts(root string) ([]string, error) { - infos, err := mount.GetMounts() - if err != nil { - return nil, errors.Wrap(err, "failed to read mount table while performing recursive unmount") - } - - var mounts []string - for _, m := range infos { - if strings.HasPrefix(m.Mountpoint, root) { - mounts = append(mounts, m.Mountpoint) - } - } - - return mounts, nil -} - -func recursiveUnmount(root string) error { - mounts, err := getMounts(root) - if err != nil { - return err - } - - // sort in reverse-lexicographic order so the root mount will always be last - sort.Sort(sort.Reverse(sort.StringSlice(mounts))) - - for i, m := range mounts { - if err := mount.Unmount(m); err != nil { - if i == len(mounts)-1 { - return errors.Wrapf(err, "error performing recursive unmount on %s", root) - } - logrus.WithError(err).WithField("mountpoint", m).Warn("could not unmount") - } - } - - return nil -} - -// Set sets plugin args -func (pm *Manager) Set(name string, args []string) error { - p, err := pm.config.Store.GetV2Plugin(name) - if err != nil { - return err - } - if err := p.Set(args); err != nil { - return err - } - return pm.save(p) -} - -// CreateFromContext creates a plugin from the given pluginDir which contains -// both the rootfs and the config.json and a repoName with optional tag. -func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *types.PluginCreateOptions) (err error) { - pm.muGC.RLock() - defer pm.muGC.RUnlock() - - ref, err := reference.ParseNamed(options.RepoName) - if err != nil { - return errors.Wrapf(err, "failed to parse reference %v", options.RepoName) - } - if _, ok := ref.(reference.Canonical); ok { - return errors.Errorf("canonical references are not permitted") - } - taggedRef := reference.WithDefaultTag(ref) - name := taggedRef.String() - - if err := pm.config.Store.validateName(name); err != nil { // fast check, real check is in createPlugin() - return err - } - - tmpRootFSDir, err := ioutil.TempDir(pm.tmpDir(), ".rootfs") - defer os.RemoveAll(tmpRootFSDir) - if err != nil { - return errors.Wrap(err, "failed to create temp directory") - } - var configJSON []byte - rootFS := splitConfigRootFSFromTar(tarCtx, &configJSON) - - rootFSBlob, err := pm.blobStore.New() - if err != nil { - return err - } - defer rootFSBlob.Close() - gzw := gzip.NewWriter(rootFSBlob) - layerDigester := digest.Canonical.New() - rootFSReader := io.TeeReader(rootFS, io.MultiWriter(gzw, layerDigester.Hash())) - - if err := chrootarchive.Untar(rootFSReader, tmpRootFSDir, nil); err != nil { - return err - } - if err := rootFS.Close(); err != nil { - return err - } - - if configJSON == nil { - return errors.New("config not found") - } - - if err := gzw.Close(); err != nil { - return errors.Wrap(err, "error closing gzip writer") - } - - var config types.PluginConfig - if err := json.Unmarshal(configJSON, &config); err != nil { - return errors.Wrap(err, "failed to parse config") - } - - if err := pm.validateConfig(config); err != nil { - return err - } - - pm.mu.Lock() - defer pm.mu.Unlock() - - rootFSBlobsum, err := rootFSBlob.Commit() - if err != nil { - return err - } - defer func() { - if err != nil { - go pm.GC() - } - }() - - config.Rootfs = &types.PluginConfigRootfs{ - Type: "layers", - DiffIds: []string{layerDigester.Digest().String()}, - } - - configBlob, err := pm.blobStore.New() - if err != nil { - return err - } - defer configBlob.Close() - if err := json.NewEncoder(configBlob).Encode(config); err != nil { - return errors.Wrap(err, "error encoding json config") - } - configBlobsum, err := configBlob.Commit() - if err != nil { - return err - } - - p, err := pm.createPlugin(name, configBlobsum, []digest.Digest{rootFSBlobsum}, tmpRootFSDir, nil) - if err != nil { - return err - } - p.PluginObj.PluginReference = taggedRef.String() - - pm.config.LogPluginEvent(p.PluginObj.ID, name, "create") - - return nil -} - -func (pm *Manager) validateConfig(config types.PluginConfig) error { - return nil // TODO: -} - -func splitConfigRootFSFromTar(in io.ReadCloser, config *[]byte) io.ReadCloser { - pr, pw := io.Pipe() - go func() { - tarReader := tar.NewReader(in) - tarWriter := tar.NewWriter(pw) - defer in.Close() - - hasRootFS := false - - for { - hdr, err := tarReader.Next() - if err == io.EOF { - if !hasRootFS { - pw.CloseWithError(errors.Wrap(err, "no rootfs found")) - return - } - // Signals end of archive. - tarWriter.Close() - pw.Close() - return - } - if err != nil { - pw.CloseWithError(errors.Wrap(err, "failed to read from tar")) - return - } - - content := io.Reader(tarReader) - name := path.Clean(hdr.Name) - if path.IsAbs(name) { - name = name[1:] - } - if name == configFileName { - dt, err := ioutil.ReadAll(content) - if err != nil { - pw.CloseWithError(errors.Wrapf(err, "failed to read %s", configFileName)) - return - } - *config = dt - } - if parts := strings.Split(name, "/"); len(parts) != 0 && parts[0] == rootFSFileName { - hdr.Name = path.Clean(path.Join(parts[1:]...)) - if hdr.Typeflag == tar.TypeLink && strings.HasPrefix(strings.ToLower(hdr.Linkname), rootFSFileName+"/") { - hdr.Linkname = hdr.Linkname[len(rootFSFileName)+1:] - } - if err := tarWriter.WriteHeader(hdr); err != nil { - pw.CloseWithError(errors.Wrap(err, "error writing tar header")) - return - } - if _, err := pools.Copy(tarWriter, content); err != nil { - pw.CloseWithError(errors.Wrap(err, "error copying tar data")) - return - } - hasRootFS = true - } else { - io.Copy(ioutil.Discard, content) - } - } - }() - return pr -} diff --git a/vendor/github.com/docker/docker/plugin/backend_unsupported.go b/vendor/github.com/docker/docker/plugin/backend_unsupported.go deleted file mode 100644 index 66e6dab..0000000 --- a/vendor/github.com/docker/docker/plugin/backend_unsupported.go +++ /dev/null @@ -1,71 +0,0 @@ -// +build !linux - -package plugin - -import ( - "errors" - "io" - "net/http" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/reference" - "golang.org/x/net/context" -) - -var errNotSupported = errors.New("plugins are not supported on this platform") - -// Disable deactivates a plugin, which implies that they cannot be used by containers. -func (pm *Manager) Disable(name string, config *types.PluginDisableConfig) error { - return errNotSupported -} - -// Enable activates a plugin, which implies that they are ready to be used by containers. -func (pm *Manager) Enable(name string, config *types.PluginEnableConfig) error { - return errNotSupported -} - -// Inspect examines a plugin config -func (pm *Manager) Inspect(refOrID string) (tp *types.Plugin, err error) { - return nil, errNotSupported -} - -// Privileges pulls a plugin config and computes the privileges required to install it. -func (pm *Manager) Privileges(ctx context.Context, ref reference.Named, metaHeader http.Header, authConfig *types.AuthConfig) (types.PluginPrivileges, error) { - return nil, errNotSupported -} - -// Pull pulls a plugin, check if the correct privileges are provided and install the plugin. -func (pm *Manager) Pull(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *types.AuthConfig, privileges types.PluginPrivileges, out io.Writer) error { - return errNotSupported -} - -// Upgrade pulls a plugin, check if the correct privileges are provided and install the plugin. -func (pm *Manager) Upgrade(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *types.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer) error { - return errNotSupported -} - -// List displays the list of plugins and associated metadata. -func (pm *Manager) List() ([]types.Plugin, error) { - return nil, errNotSupported -} - -// Push pushes a plugin to the store. -func (pm *Manager) Push(ctx context.Context, name string, metaHeader http.Header, authConfig *types.AuthConfig, out io.Writer) error { - return errNotSupported -} - -// Remove deletes plugin's root directory. -func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error { - return errNotSupported -} - -// Set sets plugin args -func (pm *Manager) Set(name string, args []string) error { - return errNotSupported -} - -// CreateFromContext creates a plugin from the given pluginDir which contains -// both the rootfs and the config.json and a repoName with optional tag. -func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *types.PluginCreateOptions) error { - return errNotSupported -} diff --git a/vendor/github.com/docker/docker/plugin/blobstore.go b/vendor/github.com/docker/docker/plugin/blobstore.go deleted file mode 100644 index dc9e598..0000000 --- a/vendor/github.com/docker/docker/plugin/blobstore.go +++ /dev/null @@ -1,181 +0,0 @@ -package plugin - -import ( - "io" - "io/ioutil" - "os" - "path/filepath" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/distribution/xfer" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/progress" - "github.com/pkg/errors" - "golang.org/x/net/context" -) - -type blobstore interface { - New() (WriteCommitCloser, error) - Get(dgst digest.Digest) (io.ReadCloser, error) - Size(dgst digest.Digest) (int64, error) -} - -type basicBlobStore struct { - path string -} - -func newBasicBlobStore(p string) (*basicBlobStore, error) { - tmpdir := filepath.Join(p, "tmp") - if err := os.MkdirAll(tmpdir, 0700); err != nil { - return nil, errors.Wrapf(err, "failed to mkdir %v", p) - } - return &basicBlobStore{path: p}, nil -} - -func (b *basicBlobStore) New() (WriteCommitCloser, error) { - f, err := ioutil.TempFile(filepath.Join(b.path, "tmp"), ".insertion") - if err != nil { - return nil, errors.Wrap(err, "failed to create temp file") - } - return newInsertion(f), nil -} - -func (b *basicBlobStore) Get(dgst digest.Digest) (io.ReadCloser, error) { - return os.Open(filepath.Join(b.path, string(dgst.Algorithm()), dgst.Hex())) -} - -func (b *basicBlobStore) Size(dgst digest.Digest) (int64, error) { - stat, err := os.Stat(filepath.Join(b.path, string(dgst.Algorithm()), dgst.Hex())) - if err != nil { - return 0, err - } - return stat.Size(), nil -} - -func (b *basicBlobStore) gc(whitelist map[digest.Digest]struct{}) { - for _, alg := range []string{string(digest.Canonical)} { - items, err := ioutil.ReadDir(filepath.Join(b.path, alg)) - if err != nil { - continue - } - for _, fi := range items { - if _, exists := whitelist[digest.Digest(alg+":"+fi.Name())]; !exists { - p := filepath.Join(b.path, alg, fi.Name()) - err := os.RemoveAll(p) - logrus.Debugf("cleaned up blob %v: %v", p, err) - } - } - } - -} - -// WriteCommitCloser defines object that can be committed to blobstore. -type WriteCommitCloser interface { - io.WriteCloser - Commit() (digest.Digest, error) -} - -type insertion struct { - io.Writer - f *os.File - digester digest.Digester - closed bool -} - -func newInsertion(tempFile *os.File) *insertion { - digester := digest.Canonical.New() - return &insertion{f: tempFile, digester: digester, Writer: io.MultiWriter(tempFile, digester.Hash())} -} - -func (i *insertion) Commit() (digest.Digest, error) { - p := i.f.Name() - d := filepath.Join(filepath.Join(p, "../../")) - i.f.Sync() - defer os.RemoveAll(p) - if err := i.f.Close(); err != nil { - return "", err - } - i.closed = true - dgst := i.digester.Digest() - if err := os.MkdirAll(filepath.Join(d, string(dgst.Algorithm())), 0700); err != nil { - return "", errors.Wrapf(err, "failed to mkdir %v", d) - } - if err := os.Rename(p, filepath.Join(d, string(dgst.Algorithm()), dgst.Hex())); err != nil { - return "", errors.Wrapf(err, "failed to rename %v", p) - } - return dgst, nil -} - -func (i *insertion) Close() error { - if i.closed { - return nil - } - defer os.RemoveAll(i.f.Name()) - return i.f.Close() -} - -type downloadManager struct { - blobStore blobstore - tmpDir string - blobs []digest.Digest - configDigest digest.Digest -} - -func (dm *downloadManager) Download(ctx context.Context, initialRootFS image.RootFS, layers []xfer.DownloadDescriptor, progressOutput progress.Output) (image.RootFS, func(), error) { - for _, l := range layers { - b, err := dm.blobStore.New() - if err != nil { - return initialRootFS, nil, err - } - defer b.Close() - rc, _, err := l.Download(ctx, progressOutput) - if err != nil { - return initialRootFS, nil, errors.Wrap(err, "failed to download") - } - defer rc.Close() - r := io.TeeReader(rc, b) - inflatedLayerData, err := archive.DecompressStream(r) - if err != nil { - return initialRootFS, nil, err - } - digester := digest.Canonical.New() - if _, err := archive.ApplyLayer(dm.tmpDir, io.TeeReader(inflatedLayerData, digester.Hash())); err != nil { - return initialRootFS, nil, err - } - initialRootFS.Append(layer.DiffID(digester.Digest())) - d, err := b.Commit() - if err != nil { - return initialRootFS, nil, err - } - dm.blobs = append(dm.blobs, d) - } - return initialRootFS, nil, nil -} - -func (dm *downloadManager) Put(dt []byte) (digest.Digest, error) { - b, err := dm.blobStore.New() - if err != nil { - return "", err - } - defer b.Close() - n, err := b.Write(dt) - if err != nil { - return "", err - } - if n != len(dt) { - return "", io.ErrShortWrite - } - d, err := b.Commit() - dm.configDigest = d - return d, err -} - -func (dm *downloadManager) Get(d digest.Digest) ([]byte, error) { - return nil, digest.ErrDigestNotFound -} -func (dm *downloadManager) RootFSFromConfig(c []byte) (*image.RootFS, error) { - return configToRootFS(c) -} diff --git a/vendor/github.com/docker/docker/plugin/defs.go b/vendor/github.com/docker/docker/plugin/defs.go deleted file mode 100644 index 927f639..0000000 --- a/vendor/github.com/docker/docker/plugin/defs.go +++ /dev/null @@ -1,26 +0,0 @@ -package plugin - -import ( - "sync" - - "github.com/docker/docker/pkg/plugins" - "github.com/docker/docker/plugin/v2" -) - -// Store manages the plugin inventory in memory and on-disk -type Store struct { - sync.RWMutex - plugins map[string]*v2.Plugin - /* handlers are necessary for transition path of legacy plugins - * to the new model. Legacy plugins use Handle() for registering an - * activation callback.*/ - handlers map[string][]func(string, *plugins.Client) -} - -// NewStore creates a Store. -func NewStore(libRoot string) *Store { - return &Store{ - plugins: make(map[string]*v2.Plugin), - handlers: make(map[string][]func(string, *plugins.Client)), - } -} diff --git a/vendor/github.com/docker/docker/plugin/manager.go b/vendor/github.com/docker/docker/plugin/manager.go deleted file mode 100644 index f260aa6..0000000 --- a/vendor/github.com/docker/docker/plugin/manager.go +++ /dev/null @@ -1,347 +0,0 @@ -package plugin - -import ( - "encoding/json" - "io" - "io/ioutil" - "os" - "path/filepath" - "reflect" - "regexp" - "strings" - "sync" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types" - "github.com/docker/docker/image" - "github.com/docker/docker/layer" - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/plugin/v2" - "github.com/docker/docker/reference" - "github.com/docker/docker/registry" - "github.com/pkg/errors" -) - -const configFileName = "config.json" -const rootFSFileName = "rootfs" - -var validFullID = regexp.MustCompile(`^([a-f0-9]{64})$`) - -func (pm *Manager) restorePlugin(p *v2.Plugin) error { - if p.IsEnabled() { - return pm.restore(p) - } - return nil -} - -type eventLogger func(id, name, action string) - -// ManagerConfig defines configuration needed to start new manager. -type ManagerConfig struct { - Store *Store // remove - Executor libcontainerd.Remote - RegistryService registry.Service - LiveRestoreEnabled bool // TODO: remove - LogPluginEvent eventLogger - Root string - ExecRoot string -} - -// Manager controls the plugin subsystem. -type Manager struct { - config ManagerConfig - mu sync.RWMutex // protects cMap - muGC sync.RWMutex // protects blobstore deletions - cMap map[*v2.Plugin]*controller - containerdClient libcontainerd.Client - blobStore *basicBlobStore -} - -// controller represents the manager's control on a plugin. -type controller struct { - restart bool - exitChan chan bool - timeoutInSecs int -} - -// pluginRegistryService ensures that all resolved repositories -// are of the plugin class. -type pluginRegistryService struct { - registry.Service -} - -func (s pluginRegistryService) ResolveRepository(name reference.Named) (repoInfo *registry.RepositoryInfo, err error) { - repoInfo, err = s.Service.ResolveRepository(name) - if repoInfo != nil { - repoInfo.Class = "plugin" - } - return -} - -// NewManager returns a new plugin manager. -func NewManager(config ManagerConfig) (*Manager, error) { - if config.RegistryService != nil { - config.RegistryService = pluginRegistryService{config.RegistryService} - } - manager := &Manager{ - config: config, - } - if err := os.MkdirAll(manager.config.Root, 0700); err != nil { - return nil, errors.Wrapf(err, "failed to mkdir %v", manager.config.Root) - } - if err := os.MkdirAll(manager.config.ExecRoot, 0700); err != nil { - return nil, errors.Wrapf(err, "failed to mkdir %v", manager.config.ExecRoot) - } - if err := os.MkdirAll(manager.tmpDir(), 0700); err != nil { - return nil, errors.Wrapf(err, "failed to mkdir %v", manager.tmpDir()) - } - var err error - manager.containerdClient, err = config.Executor.Client(manager) // todo: move to another struct - if err != nil { - return nil, errors.Wrap(err, "failed to create containerd client") - } - manager.blobStore, err = newBasicBlobStore(filepath.Join(manager.config.Root, "storage/blobs")) - if err != nil { - return nil, err - } - - manager.cMap = make(map[*v2.Plugin]*controller) - if err := manager.reload(); err != nil { - return nil, errors.Wrap(err, "failed to restore plugins") - } - return manager, nil -} - -func (pm *Manager) tmpDir() string { - return filepath.Join(pm.config.Root, "tmp") -} - -// StateChanged updates plugin internals using libcontainerd events. -func (pm *Manager) StateChanged(id string, e libcontainerd.StateInfo) error { - logrus.Debugf("plugin state changed %s %#v", id, e) - - switch e.State { - case libcontainerd.StateExit: - p, err := pm.config.Store.GetV2Plugin(id) - if err != nil { - return err - } - - pm.mu.RLock() - c := pm.cMap[p] - - if c.exitChan != nil { - close(c.exitChan) - } - restart := c.restart - pm.mu.RUnlock() - - os.RemoveAll(filepath.Join(pm.config.ExecRoot, id)) - - if p.PropagatedMount != "" { - if err := mount.Unmount(p.PropagatedMount); err != nil { - logrus.Warnf("Could not unmount %s: %v", p.PropagatedMount, err) - } - propRoot := filepath.Join(filepath.Dir(p.Rootfs), "propagated-mount") - if err := mount.Unmount(propRoot); err != nil { - logrus.Warn("Could not unmount %s: %v", propRoot, err) - } - } - - if restart { - pm.enable(p, c, true) - } - } - - return nil -} - -func (pm *Manager) reload() error { // todo: restore - dir, err := ioutil.ReadDir(pm.config.Root) - if err != nil { - return errors.Wrapf(err, "failed to read %v", pm.config.Root) - } - plugins := make(map[string]*v2.Plugin) - for _, v := range dir { - if validFullID.MatchString(v.Name()) { - p, err := pm.loadPlugin(v.Name()) - if err != nil { - return err - } - plugins[p.GetID()] = p - } - } - - pm.config.Store.SetAll(plugins) - - var wg sync.WaitGroup - wg.Add(len(plugins)) - for _, p := range plugins { - c := &controller{} // todo: remove this - pm.cMap[p] = c - go func(p *v2.Plugin) { - defer wg.Done() - if err := pm.restorePlugin(p); err != nil { - logrus.Errorf("failed to restore plugin '%s': %s", p.Name(), err) - return - } - - if p.Rootfs != "" { - p.Rootfs = filepath.Join(pm.config.Root, p.PluginObj.ID, "rootfs") - } - - // We should only enable rootfs propagation for certain plugin types that need it. - for _, typ := range p.PluginObj.Config.Interface.Types { - if (typ.Capability == "volumedriver" || typ.Capability == "graphdriver") && typ.Prefix == "docker" && strings.HasPrefix(typ.Version, "1.") { - if p.PluginObj.Config.PropagatedMount != "" { - propRoot := filepath.Join(filepath.Dir(p.Rootfs), "propagated-mount") - - // check if we need to migrate an older propagated mount from before - // these mounts were stored outside the plugin rootfs - if _, err := os.Stat(propRoot); os.IsNotExist(err) { - if _, err := os.Stat(p.PropagatedMount); err == nil { - // make sure nothing is mounted here - // don't care about errors - mount.Unmount(p.PropagatedMount) - if err := os.Rename(p.PropagatedMount, propRoot); err != nil { - logrus.WithError(err).WithField("dir", propRoot).Error("error migrating propagated mount storage") - } - if err := os.MkdirAll(p.PropagatedMount, 0755); err != nil { - logrus.WithError(err).WithField("dir", p.PropagatedMount).Error("error migrating propagated mount storage") - } - } - } - - if err := os.MkdirAll(propRoot, 0755); err != nil { - logrus.Errorf("failed to create PropagatedMount directory at %s: %v", propRoot, err) - } - // TODO: sanitize PropagatedMount and prevent breakout - p.PropagatedMount = filepath.Join(p.Rootfs, p.PluginObj.Config.PropagatedMount) - if err := os.MkdirAll(p.PropagatedMount, 0755); err != nil { - logrus.Errorf("failed to create PropagatedMount directory at %s: %v", p.PropagatedMount, err) - return - } - } - } - } - - pm.save(p) - requiresManualRestore := !pm.config.LiveRestoreEnabled && p.IsEnabled() - - if requiresManualRestore { - // if liveRestore is not enabled, the plugin will be stopped now so we should enable it - if err := pm.enable(p, c, true); err != nil { - logrus.Errorf("failed to enable plugin '%s': %s", p.Name(), err) - } - } - }(p) - } - wg.Wait() - return nil -} - -func (pm *Manager) loadPlugin(id string) (*v2.Plugin, error) { - p := filepath.Join(pm.config.Root, id, configFileName) - dt, err := ioutil.ReadFile(p) - if err != nil { - return nil, errors.Wrapf(err, "error reading %v", p) - } - var plugin v2.Plugin - if err := json.Unmarshal(dt, &plugin); err != nil { - return nil, errors.Wrapf(err, "error decoding %v", p) - } - return &plugin, nil -} - -func (pm *Manager) save(p *v2.Plugin) error { - pluginJSON, err := json.Marshal(p) - if err != nil { - return errors.Wrap(err, "failed to marshal plugin json") - } - if err := ioutils.AtomicWriteFile(filepath.Join(pm.config.Root, p.GetID(), configFileName), pluginJSON, 0600); err != nil { - return errors.Wrap(err, "failed to write atomically plugin json") - } - return nil -} - -// GC cleans up unrefrenced blobs. This is recommended to run in a goroutine -func (pm *Manager) GC() { - pm.muGC.Lock() - defer pm.muGC.Unlock() - - whitelist := make(map[digest.Digest]struct{}) - for _, p := range pm.config.Store.GetAll() { - whitelist[p.Config] = struct{}{} - for _, b := range p.Blobsums { - whitelist[b] = struct{}{} - } - } - - pm.blobStore.gc(whitelist) -} - -type logHook struct{ id string } - -func (logHook) Levels() []logrus.Level { - return logrus.AllLevels -} - -func (l logHook) Fire(entry *logrus.Entry) error { - entry.Data = logrus.Fields{"plugin": l.id} - return nil -} - -func attachToLog(id string) func(libcontainerd.IOPipe) error { - return func(iop libcontainerd.IOPipe) error { - iop.Stdin.Close() - - logger := logrus.New() - logger.Hooks.Add(logHook{id}) - // TODO: cache writer per id - w := logger.Writer() - go func() { - io.Copy(w, iop.Stdout) - }() - go func() { - // TODO: update logrus and use logger.WriterLevel - io.Copy(w, iop.Stderr) - }() - return nil - } -} - -func validatePrivileges(requiredPrivileges, privileges types.PluginPrivileges) error { - // todo: make a better function that doesn't check order - if !reflect.DeepEqual(privileges, requiredPrivileges) { - return errors.New("incorrect privileges") - } - return nil -} - -func configToRootFS(c []byte) (*image.RootFS, error) { - var pluginConfig types.PluginConfig - if err := json.Unmarshal(c, &pluginConfig); err != nil { - return nil, err - } - // validation for empty rootfs is in distribution code - if pluginConfig.Rootfs == nil { - return nil, nil - } - - return rootFSFromPlugin(pluginConfig.Rootfs), nil -} - -func rootFSFromPlugin(pluginfs *types.PluginConfigRootfs) *image.RootFS { - rootFS := image.RootFS{ - Type: pluginfs.Type, - DiffIDs: make([]layer.DiffID, len(pluginfs.DiffIds)), - } - for i := range pluginfs.DiffIds { - rootFS.DiffIDs[i] = layer.DiffID(pluginfs.DiffIds[i]) - } - - return &rootFS -} diff --git a/vendor/github.com/docker/docker/plugin/manager_linux.go b/vendor/github.com/docker/docker/plugin/manager_linux.go deleted file mode 100644 index ad66616..0000000 --- a/vendor/github.com/docker/docker/plugin/manager_linux.go +++ /dev/null @@ -1,284 +0,0 @@ -// +build linux - -package plugin - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - "syscall" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types" - "github.com/docker/docker/daemon/initlayer" - "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/pkg/plugins" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/plugin/v2" - specs "github.com/opencontainers/runtime-spec/specs-go" - "github.com/pkg/errors" -) - -func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error { - p.Rootfs = filepath.Join(pm.config.Root, p.PluginObj.ID, "rootfs") - if p.IsEnabled() && !force { - return fmt.Errorf("plugin %s is already enabled", p.Name()) - } - spec, err := p.InitSpec(pm.config.ExecRoot) - if err != nil { - return err - } - - c.restart = true - c.exitChan = make(chan bool) - - pm.mu.Lock() - pm.cMap[p] = c - pm.mu.Unlock() - - var propRoot string - if p.PropagatedMount != "" { - propRoot = filepath.Join(filepath.Dir(p.Rootfs), "propagated-mount") - - if err := os.MkdirAll(propRoot, 0755); err != nil { - logrus.Errorf("failed to create PropagatedMount directory at %s: %v", propRoot, err) - } - - if err := mount.MakeRShared(propRoot); err != nil { - return errors.Wrap(err, "error setting up propagated mount dir") - } - - if err := mount.Mount(propRoot, p.PropagatedMount, "none", "rbind"); err != nil { - return errors.Wrap(err, "error creating mount for propagated mount") - } - } - - if err := initlayer.Setup(filepath.Join(pm.config.Root, p.PluginObj.ID, rootFSFileName), 0, 0); err != nil { - return errors.WithStack(err) - } - - if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec), attachToLog(p.GetID())); err != nil { - if p.PropagatedMount != "" { - if err := mount.Unmount(p.PropagatedMount); err != nil { - logrus.Warnf("Could not unmount %s: %v", p.PropagatedMount, err) - } - if err := mount.Unmount(propRoot); err != nil { - logrus.Warnf("Could not unmount %s: %v", propRoot, err) - } - } - return errors.WithStack(err) - } - - return pm.pluginPostStart(p, c) -} - -func (pm *Manager) pluginPostStart(p *v2.Plugin, c *controller) error { - client, err := plugins.NewClientWithTimeout("unix://"+filepath.Join(pm.config.ExecRoot, p.GetID(), p.GetSocket()), nil, c.timeoutInSecs) - if err != nil { - c.restart = false - shutdownPlugin(p, c, pm.containerdClient) - return errors.WithStack(err) - } - - p.SetPClient(client) - pm.config.Store.SetState(p, true) - pm.config.Store.CallHandler(p) - - return pm.save(p) -} - -func (pm *Manager) restore(p *v2.Plugin) error { - if err := pm.containerdClient.Restore(p.GetID(), attachToLog(p.GetID())); err != nil { - return err - } - - if pm.config.LiveRestoreEnabled { - c := &controller{} - if pids, _ := pm.containerdClient.GetPidsForContainer(p.GetID()); len(pids) == 0 { - // plugin is not running, so follow normal startup procedure - return pm.enable(p, c, true) - } - - c.exitChan = make(chan bool) - c.restart = true - pm.mu.Lock() - pm.cMap[p] = c - pm.mu.Unlock() - return pm.pluginPostStart(p, c) - } - - return nil -} - -func shutdownPlugin(p *v2.Plugin, c *controller, containerdClient libcontainerd.Client) { - pluginID := p.GetID() - - err := containerdClient.Signal(pluginID, int(syscall.SIGTERM)) - if err != nil { - logrus.Errorf("Sending SIGTERM to plugin failed with error: %v", err) - } else { - select { - case <-c.exitChan: - logrus.Debug("Clean shutdown of plugin") - case <-time.After(time.Second * 10): - logrus.Debug("Force shutdown plugin") - if err := containerdClient.Signal(pluginID, int(syscall.SIGKILL)); err != nil { - logrus.Errorf("Sending SIGKILL to plugin failed with error: %v", err) - } - } - } -} - -func (pm *Manager) disable(p *v2.Plugin, c *controller) error { - if !p.IsEnabled() { - return fmt.Errorf("plugin %s is already disabled", p.Name()) - } - - c.restart = false - shutdownPlugin(p, c, pm.containerdClient) - pm.config.Store.SetState(p, false) - return pm.save(p) -} - -// Shutdown stops all plugins and called during daemon shutdown. -func (pm *Manager) Shutdown() { - plugins := pm.config.Store.GetAll() - for _, p := range plugins { - pm.mu.RLock() - c := pm.cMap[p] - pm.mu.RUnlock() - - if pm.config.LiveRestoreEnabled && p.IsEnabled() { - logrus.Debug("Plugin active when liveRestore is set, skipping shutdown") - continue - } - if pm.containerdClient != nil && p.IsEnabled() { - c.restart = false - shutdownPlugin(p, c, pm.containerdClient) - } - } -} - -func (pm *Manager) upgradePlugin(p *v2.Plugin, configDigest digest.Digest, blobsums []digest.Digest, tmpRootFSDir string, privileges *types.PluginPrivileges) (err error) { - config, err := pm.setupNewPlugin(configDigest, blobsums, privileges) - if err != nil { - return err - } - - pdir := filepath.Join(pm.config.Root, p.PluginObj.ID) - orig := filepath.Join(pdir, "rootfs") - backup := orig + "-old" - if err := os.Rename(orig, backup); err != nil { - return err - } - - defer func() { - if err != nil { - if rmErr := os.RemoveAll(orig); rmErr != nil && !os.IsNotExist(rmErr) { - logrus.WithError(rmErr).WithField("dir", backup).Error("error cleaning up after failed upgrade") - return - } - - if err := os.Rename(backup, orig); err != nil { - err = errors.Wrap(err, "error restoring old plugin root on upgrade failure") - } - if rmErr := os.RemoveAll(tmpRootFSDir); rmErr != nil && !os.IsNotExist(rmErr) { - logrus.WithError(rmErr).WithField("plugin", p.Name()).Errorf("error cleaning up plugin upgrade dir: %s", tmpRootFSDir) - } - } else { - if rmErr := os.RemoveAll(backup); rmErr != nil && !os.IsNotExist(rmErr) { - logrus.WithError(rmErr).WithField("dir", backup).Error("error cleaning up old plugin root after successful upgrade") - } - - p.Config = configDigest - p.Blobsums = blobsums - } - }() - - if err := os.Rename(tmpRootFSDir, orig); err != nil { - return errors.Wrap(err, "error upgrading") - } - - p.PluginObj.Config = config - err = pm.save(p) - return errors.Wrap(err, "error saving upgraded plugin config") -} - -func (pm *Manager) setupNewPlugin(configDigest digest.Digest, blobsums []digest.Digest, privileges *types.PluginPrivileges) (types.PluginConfig, error) { - configRC, err := pm.blobStore.Get(configDigest) - if err != nil { - return types.PluginConfig{}, err - } - defer configRC.Close() - - var config types.PluginConfig - dec := json.NewDecoder(configRC) - if err := dec.Decode(&config); err != nil { - return types.PluginConfig{}, errors.Wrapf(err, "failed to parse config") - } - if dec.More() { - return types.PluginConfig{}, errors.New("invalid config json") - } - - requiredPrivileges, err := computePrivileges(config) - if err != nil { - return types.PluginConfig{}, err - } - if privileges != nil { - if err := validatePrivileges(requiredPrivileges, *privileges); err != nil { - return types.PluginConfig{}, err - } - } - - return config, nil -} - -// createPlugin creates a new plugin. take lock before calling. -func (pm *Manager) createPlugin(name string, configDigest digest.Digest, blobsums []digest.Digest, rootFSDir string, privileges *types.PluginPrivileges) (p *v2.Plugin, err error) { - if err := pm.config.Store.validateName(name); err != nil { // todo: this check is wrong. remove store - return nil, err - } - - config, err := pm.setupNewPlugin(configDigest, blobsums, privileges) - if err != nil { - return nil, err - } - - p = &v2.Plugin{ - PluginObj: types.Plugin{ - Name: name, - ID: stringid.GenerateRandomID(), - Config: config, - }, - Config: configDigest, - Blobsums: blobsums, - } - p.InitEmptySettings() - - pdir := filepath.Join(pm.config.Root, p.PluginObj.ID) - if err := os.MkdirAll(pdir, 0700); err != nil { - return nil, errors.Wrapf(err, "failed to mkdir %v", pdir) - } - - defer func() { - if err != nil { - os.RemoveAll(pdir) - } - }() - - if err := os.Rename(rootFSDir, filepath.Join(pdir, rootFSFileName)); err != nil { - return nil, errors.Wrap(err, "failed to rename rootfs") - } - - if err := pm.save(p); err != nil { - return nil, err - } - - pm.config.Store.Add(p) // todo: remove - - return p, nil -} diff --git a/vendor/github.com/docker/docker/plugin/manager_solaris.go b/vendor/github.com/docker/docker/plugin/manager_solaris.go deleted file mode 100644 index 72ccae7..0000000 --- a/vendor/github.com/docker/docker/plugin/manager_solaris.go +++ /dev/null @@ -1,28 +0,0 @@ -package plugin - -import ( - "fmt" - - "github.com/docker/docker/plugin/v2" - specs "github.com/opencontainers/runtime-spec/specs-go" -) - -func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error { - return fmt.Errorf("Not implemented") -} - -func (pm *Manager) initSpec(p *v2.Plugin) (*specs.Spec, error) { - return nil, fmt.Errorf("Not implemented") -} - -func (pm *Manager) disable(p *v2.Plugin, c *controller) error { - return fmt.Errorf("Not implemented") -} - -func (pm *Manager) restore(p *v2.Plugin) error { - return fmt.Errorf("Not implemented") -} - -// Shutdown plugins -func (pm *Manager) Shutdown() { -} diff --git a/vendor/github.com/docker/docker/plugin/manager_windows.go b/vendor/github.com/docker/docker/plugin/manager_windows.go deleted file mode 100644 index 4469a67..0000000 --- a/vendor/github.com/docker/docker/plugin/manager_windows.go +++ /dev/null @@ -1,30 +0,0 @@ -// +build windows - -package plugin - -import ( - "fmt" - - "github.com/docker/docker/plugin/v2" - specs "github.com/opencontainers/runtime-spec/specs-go" -) - -func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error { - return fmt.Errorf("Not implemented") -} - -func (pm *Manager) initSpec(p *v2.Plugin) (*specs.Spec, error) { - return nil, fmt.Errorf("Not implemented") -} - -func (pm *Manager) disable(p *v2.Plugin, c *controller) error { - return fmt.Errorf("Not implemented") -} - -func (pm *Manager) restore(p *v2.Plugin) error { - return fmt.Errorf("Not implemented") -} - -// Shutdown plugins -func (pm *Manager) Shutdown() { -} diff --git a/vendor/github.com/docker/docker/plugin/store.go b/vendor/github.com/docker/docker/plugin/store.go deleted file mode 100644 index b7a96a9..0000000 --- a/vendor/github.com/docker/docker/plugin/store.go +++ /dev/null @@ -1,263 +0,0 @@ -package plugin - -import ( - "fmt" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/plugingetter" - "github.com/docker/docker/pkg/plugins" - "github.com/docker/docker/plugin/v2" - "github.com/docker/docker/reference" - "github.com/pkg/errors" -) - -/* allowV1PluginsFallback determines daemon's support for V1 plugins. - * When the time comes to remove support for V1 plugins, flipping - * this bool is all that will be needed. - */ -const allowV1PluginsFallback bool = true - -/* defaultAPIVersion is the version of the plugin API for volume, network, - IPAM and authz. This is a very stable API. When we update this API, then - pluginType should include a version. eg "networkdriver/2.0". -*/ -const defaultAPIVersion string = "1.0" - -// ErrNotFound indicates that a plugin was not found locally. -type ErrNotFound string - -func (name ErrNotFound) Error() string { return fmt.Sprintf("plugin %q not found", string(name)) } - -// ErrAmbiguous indicates that a plugin was not found locally. -type ErrAmbiguous string - -func (name ErrAmbiguous) Error() string { - return fmt.Sprintf("multiple plugins found for %q", string(name)) -} - -// GetV2Plugin retreives a plugin by name, id or partial ID. -func (ps *Store) GetV2Plugin(refOrID string) (*v2.Plugin, error) { - ps.RLock() - defer ps.RUnlock() - - id, err := ps.resolvePluginID(refOrID) - if err != nil { - return nil, err - } - - p, idOk := ps.plugins[id] - if !idOk { - return nil, errors.WithStack(ErrNotFound(id)) - } - - return p, nil -} - -// validateName returns error if name is already reserved. always call with lock and full name -func (ps *Store) validateName(name string) error { - for _, p := range ps.plugins { - if p.Name() == name { - return errors.Errorf("plugin %q already exists", name) - } - } - return nil -} - -// GetAll retreives all plugins. -func (ps *Store) GetAll() map[string]*v2.Plugin { - ps.RLock() - defer ps.RUnlock() - return ps.plugins -} - -// SetAll initialized plugins during daemon restore. -func (ps *Store) SetAll(plugins map[string]*v2.Plugin) { - ps.Lock() - defer ps.Unlock() - ps.plugins = plugins -} - -func (ps *Store) getAllByCap(capability string) []plugingetter.CompatPlugin { - ps.RLock() - defer ps.RUnlock() - - result := make([]plugingetter.CompatPlugin, 0, 1) - for _, p := range ps.plugins { - if p.IsEnabled() { - if _, err := p.FilterByCap(capability); err == nil { - result = append(result, p) - } - } - } - return result -} - -// SetState sets the active state of the plugin and updates plugindb. -func (ps *Store) SetState(p *v2.Plugin, state bool) { - ps.Lock() - defer ps.Unlock() - - p.PluginObj.Enabled = state -} - -// Add adds a plugin to memory and plugindb. -// An error will be returned if there is a collision. -func (ps *Store) Add(p *v2.Plugin) error { - ps.Lock() - defer ps.Unlock() - - if v, exist := ps.plugins[p.GetID()]; exist { - return fmt.Errorf("plugin %q has the same ID %s as %q", p.Name(), p.GetID(), v.Name()) - } - ps.plugins[p.GetID()] = p - return nil -} - -// Remove removes a plugin from memory and plugindb. -func (ps *Store) Remove(p *v2.Plugin) { - ps.Lock() - delete(ps.plugins, p.GetID()) - ps.Unlock() -} - -// Get returns an enabled plugin matching the given name and capability. -func (ps *Store) Get(name, capability string, mode int) (plugingetter.CompatPlugin, error) { - var ( - p *v2.Plugin - err error - ) - - // Lookup using new model. - if ps != nil { - p, err = ps.GetV2Plugin(name) - if err == nil { - p.AddRefCount(mode) - if p.IsEnabled() { - return p.FilterByCap(capability) - } - // Plugin was found but it is disabled, so we should not fall back to legacy plugins - // but we should error out right away - return nil, ErrNotFound(name) - } - if _, ok := errors.Cause(err).(ErrNotFound); !ok { - return nil, err - } - } - - // Lookup using legacy model. - if allowV1PluginsFallback { - p, err := plugins.Get(name, capability) - if err != nil { - return nil, fmt.Errorf("legacy plugin: %v", err) - } - return p, nil - } - - return nil, err -} - -// GetAllManagedPluginsByCap returns a list of managed plugins matching the given capability. -func (ps *Store) GetAllManagedPluginsByCap(capability string) []plugingetter.CompatPlugin { - return ps.getAllByCap(capability) -} - -// GetAllByCap returns a list of enabled plugins matching the given capability. -func (ps *Store) GetAllByCap(capability string) ([]plugingetter.CompatPlugin, error) { - result := make([]plugingetter.CompatPlugin, 0, 1) - - /* Daemon start always calls plugin.Init thereby initializing a store. - * So store on experimental builds can never be nil, even while - * handling legacy plugins. However, there are legacy plugin unit - * tests where the volume subsystem directly talks with the plugin, - * bypassing the daemon. For such tests, this check is necessary. - */ - if ps != nil { - ps.RLock() - result = ps.getAllByCap(capability) - ps.RUnlock() - } - - // Lookup with legacy model - if allowV1PluginsFallback { - pl, err := plugins.GetAll(capability) - if err != nil { - return nil, fmt.Errorf("legacy plugin: %v", err) - } - for _, p := range pl { - result = append(result, p) - } - } - return result, nil -} - -// Handle sets a callback for a given capability. It is only used by network -// and ipam drivers during plugin registration. The callback registers the -// driver with the subsystem (network, ipam). -func (ps *Store) Handle(capability string, callback func(string, *plugins.Client)) { - pluginType := fmt.Sprintf("docker.%s/%s", strings.ToLower(capability), defaultAPIVersion) - - // Register callback with new plugin model. - ps.Lock() - handlers, ok := ps.handlers[pluginType] - if !ok { - handlers = []func(string, *plugins.Client){} - } - handlers = append(handlers, callback) - ps.handlers[pluginType] = handlers - ps.Unlock() - - // Register callback with legacy plugin model. - if allowV1PluginsFallback { - plugins.Handle(capability, callback) - } -} - -// CallHandler calls the registered callback. It is invoked during plugin enable. -func (ps *Store) CallHandler(p *v2.Plugin) { - for _, typ := range p.GetTypes() { - for _, handler := range ps.handlers[typ.String()] { - handler(p.Name(), p.Client()) - } - } -} - -func (ps *Store) resolvePluginID(idOrName string) (string, error) { - ps.RLock() // todo: fix - defer ps.RUnlock() - - if validFullID.MatchString(idOrName) { - return idOrName, nil - } - - ref, err := reference.ParseNamed(idOrName) - if err != nil { - return "", errors.WithStack(ErrNotFound(idOrName)) - } - if _, ok := ref.(reference.Canonical); ok { - logrus.Warnf("canonical references cannot be resolved: %v", ref.String()) - return "", errors.WithStack(ErrNotFound(idOrName)) - } - - fullRef := reference.WithDefaultTag(ref) - - for _, p := range ps.plugins { - if p.PluginObj.Name == fullRef.String() { - return p.PluginObj.ID, nil - } - } - - var found *v2.Plugin - for id, p := range ps.plugins { // this can be optimized - if strings.HasPrefix(id, idOrName) { - if found != nil { - return "", errors.WithStack(ErrAmbiguous(idOrName)) - } - found = p - } - } - if found == nil { - return "", errors.WithStack(ErrNotFound(idOrName)) - } - return found.PluginObj.ID, nil -} diff --git a/vendor/github.com/docker/docker/plugin/store_test.go b/vendor/github.com/docker/docker/plugin/store_test.go deleted file mode 100644 index 6b1f6a9..0000000 --- a/vendor/github.com/docker/docker/plugin/store_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package plugin - -import ( - "testing" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/plugin/v2" -) - -func TestFilterByCapNeg(t *testing.T) { - p := v2.Plugin{PluginObj: types.Plugin{Name: "test:latest"}} - iType := types.PluginInterfaceType{"volumedriver", "docker", "1.0"} - i := types.PluginConfigInterface{"plugins.sock", []types.PluginInterfaceType{iType}} - p.PluginObj.Config.Interface = i - - _, err := p.FilterByCap("foobar") - if err == nil { - t.Fatalf("expected inadequate error, got %v", err) - } -} - -func TestFilterByCapPos(t *testing.T) { - p := v2.Plugin{PluginObj: types.Plugin{Name: "test:latest"}} - - iType := types.PluginInterfaceType{"volumedriver", "docker", "1.0"} - i := types.PluginConfigInterface{"plugins.sock", []types.PluginInterfaceType{iType}} - p.PluginObj.Config.Interface = i - - _, err := p.FilterByCap("volumedriver") - if err != nil { - t.Fatalf("expected no error, got %v", err) - } -} diff --git a/vendor/github.com/docker/docker/plugin/v2/plugin.go b/vendor/github.com/docker/docker/plugin/v2/plugin.go deleted file mode 100644 index 93b489a..0000000 --- a/vendor/github.com/docker/docker/plugin/v2/plugin.go +++ /dev/null @@ -1,244 +0,0 @@ -package v2 - -import ( - "fmt" - "strings" - "sync" - - "github.com/docker/distribution/digest" - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/plugingetter" - "github.com/docker/docker/pkg/plugins" -) - -// Plugin represents an individual plugin. -type Plugin struct { - mu sync.RWMutex - PluginObj types.Plugin `json:"plugin"` // todo: embed struct - pClient *plugins.Client - refCount int - PropagatedMount string // TODO: make private - Rootfs string // TODO: make private - - Config digest.Digest - Blobsums []digest.Digest -} - -const defaultPluginRuntimeDestination = "/run/docker/plugins" - -// ErrInadequateCapability indicates that the plugin did not have the requested capability. -type ErrInadequateCapability struct { - cap string -} - -func (e ErrInadequateCapability) Error() string { - return fmt.Sprintf("plugin does not provide %q capability", e.cap) -} - -// BasePath returns the path to which all paths returned by the plugin are relative to. -// For Plugin objects this returns the host path of the plugin container's rootfs. -func (p *Plugin) BasePath() string { - return p.Rootfs -} - -// Client returns the plugin client. -func (p *Plugin) Client() *plugins.Client { - p.mu.RLock() - defer p.mu.RUnlock() - - return p.pClient -} - -// SetPClient set the plugin client. -func (p *Plugin) SetPClient(client *plugins.Client) { - p.mu.Lock() - defer p.mu.Unlock() - - p.pClient = client -} - -// IsV1 returns true for V1 plugins and false otherwise. -func (p *Plugin) IsV1() bool { - return false -} - -// Name returns the plugin name. -func (p *Plugin) Name() string { - return p.PluginObj.Name -} - -// FilterByCap query the plugin for a given capability. -func (p *Plugin) FilterByCap(capability string) (*Plugin, error) { - capability = strings.ToLower(capability) - for _, typ := range p.PluginObj.Config.Interface.Types { - if typ.Capability == capability && typ.Prefix == "docker" { - return p, nil - } - } - return nil, ErrInadequateCapability{capability} -} - -// InitEmptySettings initializes empty settings for a plugin. -func (p *Plugin) InitEmptySettings() { - p.PluginObj.Settings.Mounts = make([]types.PluginMount, len(p.PluginObj.Config.Mounts)) - copy(p.PluginObj.Settings.Mounts, p.PluginObj.Config.Mounts) - p.PluginObj.Settings.Devices = make([]types.PluginDevice, len(p.PluginObj.Config.Linux.Devices)) - copy(p.PluginObj.Settings.Devices, p.PluginObj.Config.Linux.Devices) - p.PluginObj.Settings.Env = make([]string, 0, len(p.PluginObj.Config.Env)) - for _, env := range p.PluginObj.Config.Env { - if env.Value != nil { - p.PluginObj.Settings.Env = append(p.PluginObj.Settings.Env, fmt.Sprintf("%s=%s", env.Name, *env.Value)) - } - } - p.PluginObj.Settings.Args = make([]string, len(p.PluginObj.Config.Args.Value)) - copy(p.PluginObj.Settings.Args, p.PluginObj.Config.Args.Value) -} - -// Set is used to pass arguments to the plugin. -func (p *Plugin) Set(args []string) error { - p.mu.Lock() - defer p.mu.Unlock() - - if p.PluginObj.Enabled { - return fmt.Errorf("cannot set on an active plugin, disable plugin before setting") - } - - sets, err := newSettables(args) - if err != nil { - return err - } - - // TODO(vieux): lots of code duplication here, needs to be refactored. - -next: - for _, s := range sets { - // range over all the envs in the config - for _, env := range p.PluginObj.Config.Env { - // found the env in the config - if env.Name == s.name { - // is it settable ? - if ok, err := s.isSettable(allowedSettableFieldsEnv, env.Settable); err != nil { - return err - } else if !ok { - return fmt.Errorf("%q is not settable", s.prettyName()) - } - // is it, so lets update the settings in memory - updateSettingsEnv(&p.PluginObj.Settings.Env, &s) - continue next - } - } - - // range over all the mounts in the config - for _, mount := range p.PluginObj.Config.Mounts { - // found the mount in the config - if mount.Name == s.name { - // is it settable ? - if ok, err := s.isSettable(allowedSettableFieldsMounts, mount.Settable); err != nil { - return err - } else if !ok { - return fmt.Errorf("%q is not settable", s.prettyName()) - } - - // it is, so lets update the settings in memory - *mount.Source = s.value - continue next - } - } - - // range over all the devices in the config - for _, device := range p.PluginObj.Config.Linux.Devices { - // found the device in the config - if device.Name == s.name { - // is it settable ? - if ok, err := s.isSettable(allowedSettableFieldsDevices, device.Settable); err != nil { - return err - } else if !ok { - return fmt.Errorf("%q is not settable", s.prettyName()) - } - - // it is, so lets update the settings in memory - *device.Path = s.value - continue next - } - } - - // found the name in the config - if p.PluginObj.Config.Args.Name == s.name { - // is it settable ? - if ok, err := s.isSettable(allowedSettableFieldsArgs, p.PluginObj.Config.Args.Settable); err != nil { - return err - } else if !ok { - return fmt.Errorf("%q is not settable", s.prettyName()) - } - - // it is, so lets update the settings in memory - p.PluginObj.Settings.Args = strings.Split(s.value, " ") - continue next - } - - return fmt.Errorf("setting %q not found in the plugin configuration", s.name) - } - - return nil -} - -// IsEnabled returns the active state of the plugin. -func (p *Plugin) IsEnabled() bool { - p.mu.RLock() - defer p.mu.RUnlock() - - return p.PluginObj.Enabled -} - -// GetID returns the plugin's ID. -func (p *Plugin) GetID() string { - p.mu.RLock() - defer p.mu.RUnlock() - - return p.PluginObj.ID -} - -// GetSocket returns the plugin socket. -func (p *Plugin) GetSocket() string { - p.mu.RLock() - defer p.mu.RUnlock() - - return p.PluginObj.Config.Interface.Socket -} - -// GetTypes returns the interface types of a plugin. -func (p *Plugin) GetTypes() []types.PluginInterfaceType { - p.mu.RLock() - defer p.mu.RUnlock() - - return p.PluginObj.Config.Interface.Types -} - -// GetRefCount returns the reference count. -func (p *Plugin) GetRefCount() int { - p.mu.RLock() - defer p.mu.RUnlock() - - return p.refCount -} - -// AddRefCount adds to reference count. -func (p *Plugin) AddRefCount(count int) { - p.mu.Lock() - defer p.mu.Unlock() - - p.refCount += count -} - -// Acquire increments the plugin's reference count -// This should be followed up by `Release()` when the plugin is no longer in use. -func (p *Plugin) Acquire() { - p.AddRefCount(plugingetter.ACQUIRE) -} - -// Release decrements the plugin's reference count -// This should only be called when the plugin is no longer in use, e.g. with -// via `Acquire()` or getter.Get("name", "type", plugingetter.ACQUIRE) -func (p *Plugin) Release() { - p.AddRefCount(plugingetter.RELEASE) -} diff --git a/vendor/github.com/docker/docker/plugin/v2/plugin_linux.go b/vendor/github.com/docker/docker/plugin/v2/plugin_linux.go deleted file mode 100644 index e980e7f..0000000 --- a/vendor/github.com/docker/docker/plugin/v2/plugin_linux.go +++ /dev/null @@ -1,121 +0,0 @@ -// +build linux - -package v2 - -import ( - "os" - "path/filepath" - "strings" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/oci" - "github.com/docker/docker/pkg/system" - specs "github.com/opencontainers/runtime-spec/specs-go" - "github.com/pkg/errors" -) - -// InitSpec creates an OCI spec from the plugin's config. -func (p *Plugin) InitSpec(execRoot string) (*specs.Spec, error) { - s := oci.DefaultSpec() - s.Root = specs.Root{ - Path: p.Rootfs, - Readonly: false, // TODO: all plugins should be readonly? settable in config? - } - - userMounts := make(map[string]struct{}, len(p.PluginObj.Settings.Mounts)) - for _, m := range p.PluginObj.Settings.Mounts { - userMounts[m.Destination] = struct{}{} - } - - execRoot = filepath.Join(execRoot, p.PluginObj.ID) - if err := os.MkdirAll(execRoot, 0700); err != nil { - return nil, errors.WithStack(err) - } - - mounts := append(p.PluginObj.Config.Mounts, types.PluginMount{ - Source: &execRoot, - Destination: defaultPluginRuntimeDestination, - Type: "bind", - Options: []string{"rbind", "rshared"}, - }) - - if p.PluginObj.Config.Network.Type != "" { - // TODO: if net == bridge, use libnetwork controller to create a new plugin-specific bridge, bind mount /etc/hosts and /etc/resolv.conf look at the docker code (allocateNetwork, initialize) - if p.PluginObj.Config.Network.Type == "host" { - oci.RemoveNamespace(&s, specs.NamespaceType("network")) - } - etcHosts := "/etc/hosts" - resolvConf := "/etc/resolv.conf" - mounts = append(mounts, - types.PluginMount{ - Source: &etcHosts, - Destination: etcHosts, - Type: "bind", - Options: []string{"rbind", "ro"}, - }, - types.PluginMount{ - Source: &resolvConf, - Destination: resolvConf, - Type: "bind", - Options: []string{"rbind", "ro"}, - }) - } - - for _, mnt := range mounts { - m := specs.Mount{ - Destination: mnt.Destination, - Type: mnt.Type, - Options: mnt.Options, - } - if mnt.Source == nil { - return nil, errors.New("mount source is not specified") - } - m.Source = *mnt.Source - s.Mounts = append(s.Mounts, m) - } - - for i, m := range s.Mounts { - if strings.HasPrefix(m.Destination, "/dev/") { - if _, ok := userMounts[m.Destination]; ok { - s.Mounts = append(s.Mounts[:i], s.Mounts[i+1:]...) - } - } - } - - if p.PluginObj.Config.PropagatedMount != "" { - p.PropagatedMount = filepath.Join(p.Rootfs, p.PluginObj.Config.PropagatedMount) - s.Linux.RootfsPropagation = "rshared" - } - - if p.PluginObj.Config.Linux.AllowAllDevices { - rwm := "rwm" - s.Linux.Resources.Devices = []specs.DeviceCgroup{{Allow: true, Access: &rwm}} - } - for _, dev := range p.PluginObj.Settings.Devices { - path := *dev.Path - d, dPermissions, err := oci.DevicesFromPath(path, path, "rwm") - if err != nil { - return nil, errors.WithStack(err) - } - s.Linux.Devices = append(s.Linux.Devices, d...) - s.Linux.Resources.Devices = append(s.Linux.Resources.Devices, dPermissions...) - } - - envs := make([]string, 1, len(p.PluginObj.Settings.Env)+1) - envs[0] = "PATH=" + system.DefaultPathEnv - envs = append(envs, p.PluginObj.Settings.Env...) - - args := append(p.PluginObj.Config.Entrypoint, p.PluginObj.Settings.Args...) - cwd := p.PluginObj.Config.WorkDir - if len(cwd) == 0 { - cwd = "/" - } - s.Process.Terminal = false - s.Process.Args = args - s.Process.Cwd = cwd - s.Process.Env = envs - - s.Process.Capabilities = append(s.Process.Capabilities, p.PluginObj.Config.Linux.Capabilities...) - - return &s, nil -} diff --git a/vendor/github.com/docker/docker/plugin/v2/plugin_unsupported.go b/vendor/github.com/docker/docker/plugin/v2/plugin_unsupported.go deleted file mode 100644 index e60fb83..0000000 --- a/vendor/github.com/docker/docker/plugin/v2/plugin_unsupported.go +++ /dev/null @@ -1,14 +0,0 @@ -// +build !linux - -package v2 - -import ( - "errors" - - specs "github.com/opencontainers/runtime-spec/specs-go" -) - -// InitSpec creates an OCI spec from the plugin's config. -func (p *Plugin) InitSpec(execRoot string) (*specs.Spec, error) { - return nil, errors.New("not supported") -} diff --git a/vendor/github.com/docker/docker/plugin/v2/settable.go b/vendor/github.com/docker/docker/plugin/v2/settable.go deleted file mode 100644 index 79c6bef..0000000 --- a/vendor/github.com/docker/docker/plugin/v2/settable.go +++ /dev/null @@ -1,102 +0,0 @@ -package v2 - -import ( - "errors" - "fmt" - "strings" -) - -type settable struct { - name string - field string - value string -} - -var ( - allowedSettableFieldsEnv = []string{"value"} - allowedSettableFieldsArgs = []string{"value"} - allowedSettableFieldsDevices = []string{"path"} - allowedSettableFieldsMounts = []string{"source"} - - errMultipleFields = errors.New("multiple fields are settable, one must be specified") - errInvalidFormat = errors.New("invalid format, must be [.][=]") -) - -func newSettables(args []string) ([]settable, error) { - sets := make([]settable, 0, len(args)) - for _, arg := range args { - set, err := newSettable(arg) - if err != nil { - return nil, err - } - sets = append(sets, set) - } - return sets, nil -} - -func newSettable(arg string) (settable, error) { - var set settable - if i := strings.Index(arg, "="); i == 0 { - return set, errInvalidFormat - } else if i < 0 { - set.name = arg - } else { - set.name = arg[:i] - set.value = arg[i+1:] - } - - if i := strings.LastIndex(set.name, "."); i > 0 { - set.field = set.name[i+1:] - set.name = arg[:i] - } - - return set, nil -} - -// prettyName return name.field if there is a field, otherwise name. -func (set *settable) prettyName() string { - if set.field != "" { - return fmt.Sprintf("%s.%s", set.name, set.field) - } - return set.name -} - -func (set *settable) isSettable(allowedSettableFields []string, settable []string) (bool, error) { - if set.field == "" { - if len(settable) == 1 { - // if field is not specified and there only one settable, default to it. - set.field = settable[0] - } else if len(settable) > 1 { - return false, errMultipleFields - } - } - - isAllowed := false - for _, allowedSettableField := range allowedSettableFields { - if set.field == allowedSettableField { - isAllowed = true - break - } - } - - if isAllowed { - for _, settableField := range settable { - if set.field == settableField { - return true, nil - } - } - } - - return false, nil -} - -func updateSettingsEnv(env *[]string, set *settable) { - for i, e := range *env { - if parts := strings.SplitN(e, "=", 2); parts[0] == set.name { - (*env)[i] = fmt.Sprintf("%s=%s", set.name, set.value) - return - } - } - - *env = append(*env, fmt.Sprintf("%s=%s", set.name, set.value)) -} diff --git a/vendor/github.com/docker/docker/plugin/v2/settable_test.go b/vendor/github.com/docker/docker/plugin/v2/settable_test.go deleted file mode 100644 index 7183f3a..0000000 --- a/vendor/github.com/docker/docker/plugin/v2/settable_test.go +++ /dev/null @@ -1,91 +0,0 @@ -package v2 - -import ( - "reflect" - "testing" -) - -func TestNewSettable(t *testing.T) { - contexts := []struct { - arg string - name string - field string - value string - err error - }{ - {"name=value", "name", "", "value", nil}, - {"name", "name", "", "", nil}, - {"name.field=value", "name", "field", "value", nil}, - {"name.field", "name", "field", "", nil}, - {"=value", "", "", "", errInvalidFormat}, - {"=", "", "", "", errInvalidFormat}, - } - - for _, c := range contexts { - s, err := newSettable(c.arg) - if err != c.err { - t.Fatalf("expected error to be %v, got %v", c.err, err) - } - - if s.name != c.name { - t.Fatalf("expected name to be %q, got %q", c.name, s.name) - } - - if s.field != c.field { - t.Fatalf("expected field to be %q, got %q", c.field, s.field) - } - - if s.value != c.value { - t.Fatalf("expected value to be %q, got %q", c.value, s.value) - } - - } -} - -func TestIsSettable(t *testing.T) { - contexts := []struct { - allowedSettableFields []string - set settable - settable []string - result bool - err error - }{ - {allowedSettableFieldsEnv, settable{}, []string{}, false, nil}, - {allowedSettableFieldsEnv, settable{field: "value"}, []string{}, false, nil}, - {allowedSettableFieldsEnv, settable{}, []string{"value"}, true, nil}, - {allowedSettableFieldsEnv, settable{field: "value"}, []string{"value"}, true, nil}, - {allowedSettableFieldsEnv, settable{field: "foo"}, []string{"value"}, false, nil}, - {allowedSettableFieldsEnv, settable{field: "foo"}, []string{"foo"}, false, nil}, - {allowedSettableFieldsEnv, settable{}, []string{"value1", "value2"}, false, errMultipleFields}, - } - - for _, c := range contexts { - if res, err := c.set.isSettable(c.allowedSettableFields, c.settable); res != c.result { - t.Fatalf("expected result to be %t, got %t", c.result, res) - } else if err != c.err { - t.Fatalf("expected error to be %v, got %v", c.err, err) - } - } -} - -func TestUpdateSettinsEnv(t *testing.T) { - contexts := []struct { - env []string - set settable - newEnv []string - }{ - {[]string{}, settable{name: "DEBUG", value: "1"}, []string{"DEBUG=1"}}, - {[]string{"DEBUG=0"}, settable{name: "DEBUG", value: "1"}, []string{"DEBUG=1"}}, - {[]string{"FOO=0"}, settable{name: "DEBUG", value: "1"}, []string{"FOO=0", "DEBUG=1"}}, - {[]string{"FOO=0", "DEBUG=0"}, settable{name: "DEBUG", value: "1"}, []string{"FOO=0", "DEBUG=1"}}, - {[]string{"FOO=0", "DEBUG=0", "BAR=1"}, settable{name: "DEBUG", value: "1"}, []string{"FOO=0", "DEBUG=1", "BAR=1"}}, - } - - for _, c := range contexts { - updateSettingsEnv(&c.env, &c.set) - - if !reflect.DeepEqual(c.env, c.newEnv) { - t.Fatalf("expected env to be %q, got %q", c.newEnv, c.env) - } - } -} diff --git a/vendor/github.com/docker/docker/poule.yml b/vendor/github.com/docker/docker/poule.yml deleted file mode 100644 index 61aab45..0000000 --- a/vendor/github.com/docker/docker/poule.yml +++ /dev/null @@ -1,88 +0,0 @@ -# Add a "status/0-triage" to every newly opened pull request. -- triggers: - pull_request: [ opened ] - operations: - - type: label - settings: { - patterns: { - status/0-triage: [ ".*" ], - } - } - -# For every newly created or modified issue, assign label based on matching regexp using the `label` -# operation, as well as an Engine-specific version label using `version-label`. -- triggers: - issues: [ edited, opened, reopened ] - operations: - - type: label - settings: { - patterns: { - area/builder: [ "dockerfile", "docker build" ], - area/distribution: [ "docker login", "docker logout", "docker pull", "docker push", "docker search" ], - area/plugins: [ "docker plugin" ], - area/networking: [ "docker network", "ipvs", "vxlan" ], - area/runtime: [ "oci runtime error" ], - area/security/trust: [ "docker_content_trust" ], - area/swarm: [ "docker node", "docker service", "docker swarm" ], - platform/desktop: [ "docker for mac", "docker for windows" ], - platform/freebsd: [ "freebsd" ], - platform/windows: [ "nanoserver", "windowsservercore", "windows server" ], - } - } - - type: version-label - -# When a pull request is closed, attach it to the currently active milestone. -- triggers: - pull_request: [ closed ] - operations: - - type: version-milestone - -# Labeling a PR with `rebuild/` triggers a rebuild job for the associated -# configuration. The label is automatically removed after the rebuild is initiated. There's no such -# thing as "templating" in this configuration, so we need one operation for each type of -# configuration that can be triggered. -- triggers: - pull_request: [ labeled ] - operations: - - type: rebuild - settings: { - # When configurations are empty, the `rebuild` operation rebuilds all the currently - # known statuses for that pull request. - configurations: [], - label: "rebuild/*", - } - - type: rebuild - settings: { - configurations: [ arm ], - label: "rebuild/arm", - } - - type: rebuild - settings: { - configurations: [ experimental ], - label: "rebuild/experimental", - } - - type: rebuild - settings: { - configurations: [ janky ], - label: "rebuild/janky", - } - - type: rebuild - settings: { - configurations: [ userns ], - label: "rebuild/userns", - } - - type: rebuild - settings: { - configurations: [ vendor ], - label: "rebuild/vendor", - } - - type: rebuild - settings: { - configurations: [ win2lin ], - label: "rebuild/win2lin", - } - - type: rebuild - settings: { - configurations: [ windowsRS1 ], - label: "rebuild/windowsRS1", - } diff --git a/vendor/github.com/docker/docker/profiles/apparmor/apparmor.go b/vendor/github.com/docker/docker/profiles/apparmor/apparmor.go deleted file mode 100644 index 5132ebe..0000000 --- a/vendor/github.com/docker/docker/profiles/apparmor/apparmor.go +++ /dev/null @@ -1,122 +0,0 @@ -// +build linux - -package apparmor - -import ( - "bufio" - "io" - "io/ioutil" - "os" - "path" - "strings" - - "github.com/docker/docker/pkg/aaparser" - "github.com/docker/docker/utils/templates" -) - -var ( - // profileDirectory is the file store for apparmor profiles and macros. - profileDirectory = "/etc/apparmor.d" -) - -// profileData holds information about the given profile for generation. -type profileData struct { - // Name is profile name. - Name string - // Imports defines the apparmor functions to import, before defining the profile. - Imports []string - // InnerImports defines the apparmor functions to import in the profile. - InnerImports []string - // Version is the {major, minor, patch} version of apparmor_parser as a single number. - Version int -} - -// generateDefault creates an apparmor profile from ProfileData. -func (p *profileData) generateDefault(out io.Writer) error { - compiled, err := templates.NewParse("apparmor_profile", baseTemplate) - if err != nil { - return err - } - - if macroExists("tunables/global") { - p.Imports = append(p.Imports, "#include ") - } else { - p.Imports = append(p.Imports, "@{PROC}=/proc/") - } - - if macroExists("abstractions/base") { - p.InnerImports = append(p.InnerImports, "#include ") - } - - ver, err := aaparser.GetVersion() - if err != nil { - return err - } - p.Version = ver - - if err := compiled.Execute(out, p); err != nil { - return err - } - return nil -} - -// macrosExists checks if the passed macro exists. -func macroExists(m string) bool { - _, err := os.Stat(path.Join(profileDirectory, m)) - return err == nil -} - -// InstallDefault generates a default profile in a temp directory determined by -// os.TempDir(), then loads the profile into the kernel using 'apparmor_parser'. -func InstallDefault(name string) error { - p := profileData{ - Name: name, - } - - // Install to a temporary directory. - f, err := ioutil.TempFile("", name) - if err != nil { - return err - } - profilePath := f.Name() - - defer f.Close() - defer os.Remove(profilePath) - - if err := p.generateDefault(f); err != nil { - f.Close() - return err - } - - if err := aaparser.LoadProfile(profilePath); err != nil { - return err - } - - return nil -} - -// IsLoaded checks if a profile with the given name has been loaded into the -// kernel. -func IsLoaded(name string) (bool, error) { - file, err := os.Open("/sys/kernel/security/apparmor/profiles") - if err != nil { - return false, err - } - defer file.Close() - - r := bufio.NewReader(file) - for { - p, err := r.ReadString('\n') - if err == io.EOF { - break - } - if err != nil { - return false, err - } - if strings.HasPrefix(p, name+" ") { - return true, nil - } - } - - return false, nil -} diff --git a/vendor/github.com/docker/docker/profiles/apparmor/template.go b/vendor/github.com/docker/docker/profiles/apparmor/template.go deleted file mode 100644 index c5ea458..0000000 --- a/vendor/github.com/docker/docker/profiles/apparmor/template.go +++ /dev/null @@ -1,46 +0,0 @@ -// +build linux - -package apparmor - -// baseTemplate defines the default apparmor profile for containers. -const baseTemplate = ` -{{range $value := .Imports}} -{{$value}} -{{end}} - -profile {{.Name}} flags=(attach_disconnected,mediate_deleted) { -{{range $value := .InnerImports}} - {{$value}} -{{end}} - - network, - capability, - file, - umount, - - deny @{PROC}/* w, # deny write for all files directly in /proc (not in a subdir) - # deny write to files not in /proc//** or /proc/sys/** - deny @{PROC}/{[^1-9],[^1-9][^0-9],[^1-9s][^0-9y][^0-9s],[^1-9][^0-9][^0-9][^0-9]*}/** w, - deny @{PROC}/sys/[^k]** w, # deny /proc/sys except /proc/sys/k* (effectively /proc/sys/kernel) - deny @{PROC}/sys/kernel/{?,??,[^s][^h][^m]**} w, # deny everything except shm* in /proc/sys/kernel/ - deny @{PROC}/sysrq-trigger rwklx, - deny @{PROC}/mem rwklx, - deny @{PROC}/kmem rwklx, - deny @{PROC}/kcore rwklx, - - deny mount, - - deny /sys/[^f]*/** wklx, - deny /sys/f[^s]*/** wklx, - deny /sys/fs/[^c]*/** wklx, - deny /sys/fs/c[^g]*/** wklx, - deny /sys/fs/cg[^r]*/** wklx, - deny /sys/firmware/** rwklx, - deny /sys/kernel/security/** rwklx, - -{{if ge .Version 208095}} - # suppress ptrace denials when using 'docker ps' or using 'ps' inside a container - ptrace (trace,read) peer={{.Name}}, -{{end}} -} -` diff --git a/vendor/github.com/docker/docker/profiles/seccomp/default.json b/vendor/github.com/docker/docker/profiles/seccomp/default.json deleted file mode 100755 index ac129d3..0000000 --- a/vendor/github.com/docker/docker/profiles/seccomp/default.json +++ /dev/null @@ -1,698 +0,0 @@ -{ - "defaultAction": "SCMP_ACT_ERRNO", - "archMap": [ - { - "architecture": "SCMP_ARCH_X86_64", - "subArchitectures": [ - "SCMP_ARCH_X86", - "SCMP_ARCH_X32" - ] - }, - { - "architecture": "SCMP_ARCH_AARCH64", - "subArchitectures": [ - "SCMP_ARCH_ARM" - ] - }, - { - "architecture": "SCMP_ARCH_MIPS64", - "subArchitectures": [ - "SCMP_ARCH_MIPS", - "SCMP_ARCH_MIPS64N32" - ] - }, - { - "architecture": "SCMP_ARCH_MIPS64N32", - "subArchitectures": [ - "SCMP_ARCH_MIPS", - "SCMP_ARCH_MIPS64" - ] - }, - { - "architecture": "SCMP_ARCH_MIPSEL64", - "subArchitectures": [ - "SCMP_ARCH_MIPSEL", - "SCMP_ARCH_MIPSEL64N32" - ] - }, - { - "architecture": "SCMP_ARCH_MIPSEL64N32", - "subArchitectures": [ - "SCMP_ARCH_MIPSEL", - "SCMP_ARCH_MIPSEL64" - ] - }, - { - "architecture": "SCMP_ARCH_S390X", - "subArchitectures": [ - "SCMP_ARCH_S390" - ] - } - ], - "syscalls": [ - { - "names": [ - "accept", - "accept4", - "access", - "alarm", - "alarm", - "bind", - "brk", - "capget", - "capset", - "chdir", - "chmod", - "chown", - "chown32", - "clock_getres", - "clock_gettime", - "clock_nanosleep", - "close", - "connect", - "copy_file_range", - "creat", - "dup", - "dup2", - "dup3", - "epoll_create", - "epoll_create1", - "epoll_ctl", - "epoll_ctl_old", - "epoll_pwait", - "epoll_wait", - "epoll_wait_old", - "eventfd", - "eventfd2", - "execve", - "execveat", - "exit", - "exit_group", - "faccessat", - "fadvise64", - "fadvise64_64", - "fallocate", - "fanotify_mark", - "fchdir", - "fchmod", - "fchmodat", - "fchown", - "fchown32", - "fchownat", - "fcntl", - "fcntl64", - "fdatasync", - "fgetxattr", - "flistxattr", - "flock", - "fork", - "fremovexattr", - "fsetxattr", - "fstat", - "fstat64", - "fstatat64", - "fstatfs", - "fstatfs64", - "fsync", - "ftruncate", - "ftruncate64", - "futex", - "futimesat", - "getcpu", - "getcwd", - "getdents", - "getdents64", - "getegid", - "getegid32", - "geteuid", - "geteuid32", - "getgid", - "getgid32", - "getgroups", - "getgroups32", - "getitimer", - "getpeername", - "getpgid", - "getpgrp", - "getpid", - "getppid", - "getpriority", - "getrandom", - "getresgid", - "getresgid32", - "getresuid", - "getresuid32", - "getrlimit", - "get_robust_list", - "getrusage", - "getsid", - "getsockname", - "getsockopt", - "get_thread_area", - "gettid", - "gettimeofday", - "getuid", - "getuid32", - "getxattr", - "inotify_add_watch", - "inotify_init", - "inotify_init1", - "inotify_rm_watch", - "io_cancel", - "ioctl", - "io_destroy", - "io_getevents", - "ioprio_get", - "ioprio_set", - "io_setup", - "io_submit", - "ipc", - "kill", - "lchown", - "lchown32", - "lgetxattr", - "link", - "linkat", - "listen", - "listxattr", - "llistxattr", - "_llseek", - "lremovexattr", - "lseek", - "lsetxattr", - "lstat", - "lstat64", - "madvise", - "memfd_create", - "mincore", - "mkdir", - "mkdirat", - "mknod", - "mknodat", - "mlock", - "mlock2", - "mlockall", - "mmap", - "mmap2", - "mprotect", - "mq_getsetattr", - "mq_notify", - "mq_open", - "mq_timedreceive", - "mq_timedsend", - "mq_unlink", - "mremap", - "msgctl", - "msgget", - "msgrcv", - "msgsnd", - "msync", - "munlock", - "munlockall", - "munmap", - "nanosleep", - "newfstatat", - "_newselect", - "open", - "openat", - "pause", - "pipe", - "pipe2", - "poll", - "ppoll", - "prctl", - "pread64", - "preadv", - "prlimit64", - "pselect6", - "pwrite64", - "pwritev", - "read", - "readahead", - "readlink", - "readlinkat", - "readv", - "recv", - "recvfrom", - "recvmmsg", - "recvmsg", - "remap_file_pages", - "removexattr", - "rename", - "renameat", - "renameat2", - "restart_syscall", - "rmdir", - "rt_sigaction", - "rt_sigpending", - "rt_sigprocmask", - "rt_sigqueueinfo", - "rt_sigreturn", - "rt_sigsuspend", - "rt_sigtimedwait", - "rt_tgsigqueueinfo", - "sched_getaffinity", - "sched_getattr", - "sched_getparam", - "sched_get_priority_max", - "sched_get_priority_min", - "sched_getscheduler", - "sched_rr_get_interval", - "sched_setaffinity", - "sched_setattr", - "sched_setparam", - "sched_setscheduler", - "sched_yield", - "seccomp", - "select", - "semctl", - "semget", - "semop", - "semtimedop", - "send", - "sendfile", - "sendfile64", - "sendmmsg", - "sendmsg", - "sendto", - "setfsgid", - "setfsgid32", - "setfsuid", - "setfsuid32", - "setgid", - "setgid32", - "setgroups", - "setgroups32", - "setitimer", - "setpgid", - "setpriority", - "setregid", - "setregid32", - "setresgid", - "setresgid32", - "setresuid", - "setresuid32", - "setreuid", - "setreuid32", - "setrlimit", - "set_robust_list", - "setsid", - "setsockopt", - "set_thread_area", - "set_tid_address", - "setuid", - "setuid32", - "setxattr", - "shmat", - "shmctl", - "shmdt", - "shmget", - "shutdown", - "sigaltstack", - "signalfd", - "signalfd4", - "sigreturn", - "socket", - "socketcall", - "socketpair", - "splice", - "stat", - "stat64", - "statfs", - "statfs64", - "symlink", - "symlinkat", - "sync", - "sync_file_range", - "syncfs", - "sysinfo", - "syslog", - "tee", - "tgkill", - "time", - "timer_create", - "timer_delete", - "timerfd_create", - "timerfd_gettime", - "timerfd_settime", - "timer_getoverrun", - "timer_gettime", - "timer_settime", - "times", - "tkill", - "truncate", - "truncate64", - "ugetrlimit", - "umask", - "uname", - "unlink", - "unlinkat", - "utime", - "utimensat", - "utimes", - "vfork", - "vmsplice", - "wait4", - "waitid", - "waitpid", - "write", - "writev" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": {}, - "excludes": {} - }, - { - "names": [ - "personality" - ], - "action": "SCMP_ACT_ALLOW", - "args": [ - { - "index": 0, - "value": 0, - "valueTwo": 0, - "op": "SCMP_CMP_EQ" - } - ], - "comment": "", - "includes": {}, - "excludes": {} - }, - { - "names": [ - "personality" - ], - "action": "SCMP_ACT_ALLOW", - "args": [ - { - "index": 0, - "value": 8, - "valueTwo": 0, - "op": "SCMP_CMP_EQ" - } - ], - "comment": "", - "includes": {}, - "excludes": {} - }, - { - "names": [ - "personality" - ], - "action": "SCMP_ACT_ALLOW", - "args": [ - { - "index": 0, - "value": 4294967295, - "valueTwo": 0, - "op": "SCMP_CMP_EQ" - } - ], - "comment": "", - "includes": {}, - "excludes": {} - }, - { - "names": [ - "arm_fadvise64_64", - "arm_sync_file_range", - "breakpoint", - "cacheflush", - "set_tls" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "arches": [ - "arm", - "arm64" - ] - }, - "excludes": {} - }, - { - "names": [ - "arch_prctl" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "arches": [ - "amd64", - "x32" - ] - }, - "excludes": {} - }, - { - "names": [ - "modify_ldt" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "arches": [ - "amd64", - "x32", - "x86" - ] - }, - "excludes": {} - }, - { - "names": [ - "s390_pci_mmio_read", - "s390_pci_mmio_write", - "s390_runtime_instr" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "arches": [ - "s390", - "s390x" - ] - }, - "excludes": {} - }, - { - "names": [ - "open_by_handle_at" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "caps": [ - "CAP_DAC_READ_SEARCH" - ] - }, - "excludes": {} - }, - { - "names": [ - "bpf", - "clone", - "fanotify_init", - "lookup_dcookie", - "mount", - "name_to_handle_at", - "perf_event_open", - "setdomainname", - "sethostname", - "setns", - "umount", - "umount2", - "unshare" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "caps": [ - "CAP_SYS_ADMIN" - ] - }, - "excludes": {} - }, - { - "names": [ - "clone" - ], - "action": "SCMP_ACT_ALLOW", - "args": [ - { - "index": 0, - "value": 2080505856, - "valueTwo": 0, - "op": "SCMP_CMP_MASKED_EQ" - } - ], - "comment": "", - "includes": {}, - "excludes": { - "caps": [ - "CAP_SYS_ADMIN" - ], - "arches": [ - "s390", - "s390x" - ] - } - }, - { - "names": [ - "clone" - ], - "action": "SCMP_ACT_ALLOW", - "args": [ - { - "index": 1, - "value": 2080505856, - "valueTwo": 0, - "op": "SCMP_CMP_MASKED_EQ" - } - ], - "comment": "s390 parameter ordering for clone is different", - "includes": { - "arches": [ - "s390", - "s390x" - ] - }, - "excludes": { - "caps": [ - "CAP_SYS_ADMIN" - ] - } - }, - { - "names": [ - "reboot" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "caps": [ - "CAP_SYS_BOOT" - ] - }, - "excludes": {} - }, - { - "names": [ - "chroot" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "caps": [ - "CAP_SYS_CHROOT" - ] - }, - "excludes": {} - }, - { - "names": [ - "delete_module", - "init_module", - "finit_module", - "query_module" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "caps": [ - "CAP_SYS_MODULE" - ] - }, - "excludes": {} - }, - { - "names": [ - "acct" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "caps": [ - "CAP_SYS_PACCT" - ] - }, - "excludes": {} - }, - { - "names": [ - "kcmp", - "process_vm_readv", - "process_vm_writev", - "ptrace" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "caps": [ - "CAP_SYS_PTRACE" - ] - }, - "excludes": {} - }, - { - "names": [ - "iopl", - "ioperm" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "caps": [ - "CAP_SYS_RAWIO" - ] - }, - "excludes": {} - }, - { - "names": [ - "settimeofday", - "stime", - "adjtimex" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "caps": [ - "CAP_SYS_TIME" - ] - }, - "excludes": {} - }, - { - "names": [ - "vhangup" - ], - "action": "SCMP_ACT_ALLOW", - "args": [], - "comment": "", - "includes": { - "caps": [ - "CAP_SYS_TTY_CONFIG" - ] - }, - "excludes": {} - } - ] -} \ No newline at end of file diff --git a/vendor/github.com/docker/docker/profiles/seccomp/fixtures/example.json b/vendor/github.com/docker/docker/profiles/seccomp/fixtures/example.json deleted file mode 100755 index 674ca50..0000000 --- a/vendor/github.com/docker/docker/profiles/seccomp/fixtures/example.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "defaultAction": "SCMP_ACT_ERRNO", - "syscalls": [ - { - "name": "clone", - "action": "SCMP_ACT_ALLOW", - "args": [ - { - "index": 0, - "value": 2080505856, - "valueTwo": 0, - "op": "SCMP_CMP_MASKED_EQ" - } - ] - }, - { - "name": "open", - "action": "SCMP_ACT_ALLOW", - "args": [] - }, - { - "name": "close", - "action": "SCMP_ACT_ALLOW", - "args": [] - } - ] -} diff --git a/vendor/github.com/docker/docker/profiles/seccomp/generate.go b/vendor/github.com/docker/docker/profiles/seccomp/generate.go deleted file mode 100644 index 32f22bb..0000000 --- a/vendor/github.com/docker/docker/profiles/seccomp/generate.go +++ /dev/null @@ -1,32 +0,0 @@ -// +build ignore - -package main - -import ( - "encoding/json" - "io/ioutil" - "os" - "path/filepath" - - "github.com/docker/docker/profiles/seccomp" -) - -// saves the default seccomp profile as a json file so people can use it as a -// base for their own custom profiles -func main() { - wd, err := os.Getwd() - if err != nil { - panic(err) - } - f := filepath.Join(wd, "default.json") - - // write the default profile to the file - b, err := json.MarshalIndent(seccomp.DefaultProfile(), "", "\t") - if err != nil { - panic(err) - } - - if err := ioutil.WriteFile(f, b, 0644); err != nil { - panic(err) - } -} diff --git a/vendor/github.com/docker/docker/profiles/seccomp/seccomp.go b/vendor/github.com/docker/docker/profiles/seccomp/seccomp.go deleted file mode 100644 index a54ef50..0000000 --- a/vendor/github.com/docker/docker/profiles/seccomp/seccomp.go +++ /dev/null @@ -1,150 +0,0 @@ -// +build linux - -package seccomp - -import ( - "encoding/json" - "errors" - "fmt" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/stringutils" - "github.com/opencontainers/runtime-spec/specs-go" - libseccomp "github.com/seccomp/libseccomp-golang" -) - -//go:generate go run -tags 'seccomp' generate.go - -// GetDefaultProfile returns the default seccomp profile. -func GetDefaultProfile(rs *specs.Spec) (*specs.Seccomp, error) { - return setupSeccomp(DefaultProfile(), rs) -} - -// LoadProfile takes a file path and decodes the seccomp profile. -func LoadProfile(body string, rs *specs.Spec) (*specs.Seccomp, error) { - var config types.Seccomp - if err := json.Unmarshal([]byte(body), &config); err != nil { - return nil, fmt.Errorf("Decoding seccomp profile failed: %v", err) - } - return setupSeccomp(&config, rs) -} - -var nativeToSeccomp = map[string]types.Arch{ - "amd64": types.ArchX86_64, - "arm64": types.ArchAARCH64, - "mips64": types.ArchMIPS64, - "mips64n32": types.ArchMIPS64N32, - "mipsel64": types.ArchMIPSEL64, - "mipsel64n32": types.ArchMIPSEL64N32, - "s390x": types.ArchS390X, -} - -func setupSeccomp(config *types.Seccomp, rs *specs.Spec) (*specs.Seccomp, error) { - if config == nil { - return nil, nil - } - - // No default action specified, no syscalls listed, assume seccomp disabled - if config.DefaultAction == "" && len(config.Syscalls) == 0 { - return nil, nil - } - - newConfig := &specs.Seccomp{} - - var arch string - var native, err = libseccomp.GetNativeArch() - if err == nil { - arch = native.String() - } - - if len(config.Architectures) != 0 && len(config.ArchMap) != 0 { - return nil, errors.New("'architectures' and 'archMap' were specified in the seccomp profile, use either 'architectures' or 'archMap'") - } - - // if config.Architectures == 0 then libseccomp will figure out the architecture to use - if len(config.Architectures) != 0 { - for _, a := range config.Architectures { - newConfig.Architectures = append(newConfig.Architectures, specs.Arch(a)) - } - } - - if len(config.ArchMap) != 0 { - for _, a := range config.ArchMap { - seccompArch, ok := nativeToSeccomp[arch] - if ok { - if a.Arch == seccompArch { - newConfig.Architectures = append(newConfig.Architectures, specs.Arch(a.Arch)) - for _, sa := range a.SubArches { - newConfig.Architectures = append(newConfig.Architectures, specs.Arch(sa)) - } - break - } - } - } - } - - newConfig.DefaultAction = specs.Action(config.DefaultAction) - -Loop: - // Loop through all syscall blocks and convert them to libcontainer format after filtering them - for _, call := range config.Syscalls { - if len(call.Excludes.Arches) > 0 { - if stringutils.InSlice(call.Excludes.Arches, arch) { - continue Loop - } - } - if len(call.Excludes.Caps) > 0 { - for _, c := range call.Excludes.Caps { - if stringutils.InSlice(rs.Process.Capabilities, c) { - continue Loop - } - } - } - if len(call.Includes.Arches) > 0 { - if !stringutils.InSlice(call.Includes.Arches, arch) { - continue Loop - } - } - if len(call.Includes.Caps) > 0 { - for _, c := range call.Includes.Caps { - if !stringutils.InSlice(rs.Process.Capabilities, c) { - continue Loop - } - } - } - - if call.Name != "" && len(call.Names) != 0 { - return nil, errors.New("'name' and 'names' were specified in the seccomp profile, use either 'name' or 'names'") - } - - if call.Name != "" { - newConfig.Syscalls = append(newConfig.Syscalls, createSpecsSyscall(call.Name, call.Action, call.Args)) - } - - for _, n := range call.Names { - newConfig.Syscalls = append(newConfig.Syscalls, createSpecsSyscall(n, call.Action, call.Args)) - } - } - - return newConfig, nil -} - -func createSpecsSyscall(name string, action types.Action, args []*types.Arg) specs.Syscall { - newCall := specs.Syscall{ - Name: name, - Action: specs.Action(action), - } - - // Loop through all the arguments of the syscall and convert them - for _, arg := range args { - newArg := specs.Arg{ - Index: arg.Index, - Value: arg.Value, - ValueTwo: arg.ValueTwo, - Op: specs.Operator(arg.Op), - } - - newCall.Args = append(newCall.Args, newArg) - } - return newCall -} diff --git a/vendor/github.com/docker/docker/profiles/seccomp/seccomp_default.go b/vendor/github.com/docker/docker/profiles/seccomp/seccomp_default.go deleted file mode 100644 index b84de82..0000000 --- a/vendor/github.com/docker/docker/profiles/seccomp/seccomp_default.go +++ /dev/null @@ -1,604 +0,0 @@ -// +build linux,seccomp - -package seccomp - -import ( - "syscall" - - "github.com/docker/docker/api/types" -) - -func arches() []types.Architecture { - return []types.Architecture{ - { - Arch: types.ArchX86_64, - SubArches: []types.Arch{types.ArchX86, types.ArchX32}, - }, - { - Arch: types.ArchAARCH64, - SubArches: []types.Arch{types.ArchARM}, - }, - { - Arch: types.ArchMIPS64, - SubArches: []types.Arch{types.ArchMIPS, types.ArchMIPS64N32}, - }, - { - Arch: types.ArchMIPS64N32, - SubArches: []types.Arch{types.ArchMIPS, types.ArchMIPS64}, - }, - { - Arch: types.ArchMIPSEL64, - SubArches: []types.Arch{types.ArchMIPSEL, types.ArchMIPSEL64N32}, - }, - { - Arch: types.ArchMIPSEL64N32, - SubArches: []types.Arch{types.ArchMIPSEL, types.ArchMIPSEL64}, - }, - { - Arch: types.ArchS390X, - SubArches: []types.Arch{types.ArchS390}, - }, - } -} - -// DefaultProfile defines the whitelist for the default seccomp profile. -func DefaultProfile() *types.Seccomp { - syscalls := []*types.Syscall{ - { - Names: []string{ - "accept", - "accept4", - "access", - "alarm", - "alarm", - "bind", - "brk", - "capget", - "capset", - "chdir", - "chmod", - "chown", - "chown32", - "clock_getres", - "clock_gettime", - "clock_nanosleep", - "close", - "connect", - "copy_file_range", - "creat", - "dup", - "dup2", - "dup3", - "epoll_create", - "epoll_create1", - "epoll_ctl", - "epoll_ctl_old", - "epoll_pwait", - "epoll_wait", - "epoll_wait_old", - "eventfd", - "eventfd2", - "execve", - "execveat", - "exit", - "exit_group", - "faccessat", - "fadvise64", - "fadvise64_64", - "fallocate", - "fanotify_mark", - "fchdir", - "fchmod", - "fchmodat", - "fchown", - "fchown32", - "fchownat", - "fcntl", - "fcntl64", - "fdatasync", - "fgetxattr", - "flistxattr", - "flock", - "fork", - "fremovexattr", - "fsetxattr", - "fstat", - "fstat64", - "fstatat64", - "fstatfs", - "fstatfs64", - "fsync", - "ftruncate", - "ftruncate64", - "futex", - "futimesat", - "getcpu", - "getcwd", - "getdents", - "getdents64", - "getegid", - "getegid32", - "geteuid", - "geteuid32", - "getgid", - "getgid32", - "getgroups", - "getgroups32", - "getitimer", - "getpeername", - "getpgid", - "getpgrp", - "getpid", - "getppid", - "getpriority", - "getrandom", - "getresgid", - "getresgid32", - "getresuid", - "getresuid32", - "getrlimit", - "get_robust_list", - "getrusage", - "getsid", - "getsockname", - "getsockopt", - "get_thread_area", - "gettid", - "gettimeofday", - "getuid", - "getuid32", - "getxattr", - "inotify_add_watch", - "inotify_init", - "inotify_init1", - "inotify_rm_watch", - "io_cancel", - "ioctl", - "io_destroy", - "io_getevents", - "ioprio_get", - "ioprio_set", - "io_setup", - "io_submit", - "ipc", - "kill", - "lchown", - "lchown32", - "lgetxattr", - "link", - "linkat", - "listen", - "listxattr", - "llistxattr", - "_llseek", - "lremovexattr", - "lseek", - "lsetxattr", - "lstat", - "lstat64", - "madvise", - "memfd_create", - "mincore", - "mkdir", - "mkdirat", - "mknod", - "mknodat", - "mlock", - "mlock2", - "mlockall", - "mmap", - "mmap2", - "mprotect", - "mq_getsetattr", - "mq_notify", - "mq_open", - "mq_timedreceive", - "mq_timedsend", - "mq_unlink", - "mremap", - "msgctl", - "msgget", - "msgrcv", - "msgsnd", - "msync", - "munlock", - "munlockall", - "munmap", - "nanosleep", - "newfstatat", - "_newselect", - "open", - "openat", - "pause", - "pipe", - "pipe2", - "poll", - "ppoll", - "prctl", - "pread64", - "preadv", - "prlimit64", - "pselect6", - "pwrite64", - "pwritev", - "read", - "readahead", - "readlink", - "readlinkat", - "readv", - "recv", - "recvfrom", - "recvmmsg", - "recvmsg", - "remap_file_pages", - "removexattr", - "rename", - "renameat", - "renameat2", - "restart_syscall", - "rmdir", - "rt_sigaction", - "rt_sigpending", - "rt_sigprocmask", - "rt_sigqueueinfo", - "rt_sigreturn", - "rt_sigsuspend", - "rt_sigtimedwait", - "rt_tgsigqueueinfo", - "sched_getaffinity", - "sched_getattr", - "sched_getparam", - "sched_get_priority_max", - "sched_get_priority_min", - "sched_getscheduler", - "sched_rr_get_interval", - "sched_setaffinity", - "sched_setattr", - "sched_setparam", - "sched_setscheduler", - "sched_yield", - "seccomp", - "select", - "semctl", - "semget", - "semop", - "semtimedop", - "send", - "sendfile", - "sendfile64", - "sendmmsg", - "sendmsg", - "sendto", - "setfsgid", - "setfsgid32", - "setfsuid", - "setfsuid32", - "setgid", - "setgid32", - "setgroups", - "setgroups32", - "setitimer", - "setpgid", - "setpriority", - "setregid", - "setregid32", - "setresgid", - "setresgid32", - "setresuid", - "setresuid32", - "setreuid", - "setreuid32", - "setrlimit", - "set_robust_list", - "setsid", - "setsockopt", - "set_thread_area", - "set_tid_address", - "setuid", - "setuid32", - "setxattr", - "shmat", - "shmctl", - "shmdt", - "shmget", - "shutdown", - "sigaltstack", - "signalfd", - "signalfd4", - "sigreturn", - "socket", - "socketcall", - "socketpair", - "splice", - "stat", - "stat64", - "statfs", - "statfs64", - "symlink", - "symlinkat", - "sync", - "sync_file_range", - "syncfs", - "sysinfo", - "syslog", - "tee", - "tgkill", - "time", - "timer_create", - "timer_delete", - "timerfd_create", - "timerfd_gettime", - "timerfd_settime", - "timer_getoverrun", - "timer_gettime", - "timer_settime", - "times", - "tkill", - "truncate", - "truncate64", - "ugetrlimit", - "umask", - "uname", - "unlink", - "unlinkat", - "utime", - "utimensat", - "utimes", - "vfork", - "vmsplice", - "wait4", - "waitid", - "waitpid", - "write", - "writev", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - }, - { - Names: []string{"personality"}, - Action: types.ActAllow, - Args: []*types.Arg{ - { - Index: 0, - Value: 0x0, - Op: types.OpEqualTo, - }, - }, - }, - { - Names: []string{"personality"}, - Action: types.ActAllow, - Args: []*types.Arg{ - { - Index: 0, - Value: 0x0008, - Op: types.OpEqualTo, - }, - }, - }, - { - Names: []string{"personality"}, - Action: types.ActAllow, - Args: []*types.Arg{ - { - Index: 0, - Value: 0xffffffff, - Op: types.OpEqualTo, - }, - }, - }, - { - Names: []string{ - "arm_fadvise64_64", - "arm_sync_file_range", - "breakpoint", - "cacheflush", - "set_tls", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Arches: []string{"arm", "arm64"}, - }, - }, - { - Names: []string{ - "arch_prctl", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Arches: []string{"amd64", "x32"}, - }, - }, - { - Names: []string{ - "modify_ldt", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Arches: []string{"amd64", "x32", "x86"}, - }, - }, - { - Names: []string{ - "s390_pci_mmio_read", - "s390_pci_mmio_write", - "s390_runtime_instr", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Arches: []string{"s390", "s390x"}, - }, - }, - { - Names: []string{ - "open_by_handle_at", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Caps: []string{"CAP_DAC_READ_SEARCH"}, - }, - }, - { - Names: []string{ - "bpf", - "clone", - "fanotify_init", - "lookup_dcookie", - "mount", - "name_to_handle_at", - "perf_event_open", - "setdomainname", - "sethostname", - "setns", - "umount", - "umount2", - "unshare", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Caps: []string{"CAP_SYS_ADMIN"}, - }, - }, - { - Names: []string{ - "clone", - }, - Action: types.ActAllow, - Args: []*types.Arg{ - { - Index: 0, - Value: syscall.CLONE_NEWNS | syscall.CLONE_NEWUTS | syscall.CLONE_NEWIPC | syscall.CLONE_NEWUSER | syscall.CLONE_NEWPID | syscall.CLONE_NEWNET, - ValueTwo: 0, - Op: types.OpMaskedEqual, - }, - }, - Excludes: types.Filter{ - Caps: []string{"CAP_SYS_ADMIN"}, - Arches: []string{"s390", "s390x"}, - }, - }, - { - Names: []string{ - "clone", - }, - Action: types.ActAllow, - Args: []*types.Arg{ - { - Index: 1, - Value: syscall.CLONE_NEWNS | syscall.CLONE_NEWUTS | syscall.CLONE_NEWIPC | syscall.CLONE_NEWUSER | syscall.CLONE_NEWPID | syscall.CLONE_NEWNET, - ValueTwo: 0, - Op: types.OpMaskedEqual, - }, - }, - Comment: "s390 parameter ordering for clone is different", - Includes: types.Filter{ - Arches: []string{"s390", "s390x"}, - }, - Excludes: types.Filter{ - Caps: []string{"CAP_SYS_ADMIN"}, - }, - }, - { - Names: []string{ - "reboot", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Caps: []string{"CAP_SYS_BOOT"}, - }, - }, - { - Names: []string{ - "chroot", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Caps: []string{"CAP_SYS_CHROOT"}, - }, - }, - { - Names: []string{ - "delete_module", - "init_module", - "finit_module", - "query_module", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Caps: []string{"CAP_SYS_MODULE"}, - }, - }, - { - Names: []string{ - "acct", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Caps: []string{"CAP_SYS_PACCT"}, - }, - }, - { - Names: []string{ - "kcmp", - "process_vm_readv", - "process_vm_writev", - "ptrace", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Caps: []string{"CAP_SYS_PTRACE"}, - }, - }, - { - Names: []string{ - "iopl", - "ioperm", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Caps: []string{"CAP_SYS_RAWIO"}, - }, - }, - { - Names: []string{ - "settimeofday", - "stime", - "adjtimex", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Caps: []string{"CAP_SYS_TIME"}, - }, - }, - { - Names: []string{ - "vhangup", - }, - Action: types.ActAllow, - Args: []*types.Arg{}, - Includes: types.Filter{ - Caps: []string{"CAP_SYS_TTY_CONFIG"}, - }, - }, - } - - return &types.Seccomp{ - DefaultAction: types.ActErrno, - ArchMap: arches(), - Syscalls: syscalls, - } -} diff --git a/vendor/github.com/docker/docker/profiles/seccomp/seccomp_test.go b/vendor/github.com/docker/docker/profiles/seccomp/seccomp_test.go deleted file mode 100644 index 1346921..0000000 --- a/vendor/github.com/docker/docker/profiles/seccomp/seccomp_test.go +++ /dev/null @@ -1,32 +0,0 @@ -// +build linux - -package seccomp - -import ( - "io/ioutil" - "testing" - - "github.com/docker/docker/oci" -) - -func TestLoadProfile(t *testing.T) { - f, err := ioutil.ReadFile("fixtures/example.json") - if err != nil { - t.Fatal(err) - } - rs := oci.DefaultSpec() - if _, err := LoadProfile(string(f), &rs); err != nil { - t.Fatal(err) - } -} - -func TestLoadDefaultProfile(t *testing.T) { - f, err := ioutil.ReadFile("default.json") - if err != nil { - t.Fatal(err) - } - rs := oci.DefaultSpec() - if _, err := LoadProfile(string(f), &rs); err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/profiles/seccomp/seccomp_unsupported.go b/vendor/github.com/docker/docker/profiles/seccomp/seccomp_unsupported.go deleted file mode 100644 index f84b20b..0000000 --- a/vendor/github.com/docker/docker/profiles/seccomp/seccomp_unsupported.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build linux,!seccomp - -package seccomp - -import ( - "github.com/docker/docker/api/types" - "github.com/opencontainers/runtime-spec/specs-go" -) - -// DefaultProfile returns a nil pointer on unsupported systems. -func DefaultProfile(rs *specs.Spec) *types.Seccomp { - return nil -} diff --git a/vendor/github.com/docker/docker/project/ARM.md b/vendor/github.com/docker/docker/project/ARM.md deleted file mode 100644 index c4d21bf..0000000 --- a/vendor/github.com/docker/docker/project/ARM.md +++ /dev/null @@ -1,45 +0,0 @@ -# ARM support - -The ARM support should be considered experimental. It will be extended step by step in the coming weeks. - -Building a Docker Development Image works in the same fashion as for Intel platform (x86-64). -Currently we have initial support for 32bit ARMv7 devices. - -To work with the Docker Development Image you have to clone the Docker/Docker repo on a supported device. -It needs to have a Docker Engine installed to build the Docker Development Image. - -From the root of the Docker/Docker repo one can use make to execute the following make targets: -- make validate -- make binary -- make build -- make deb -- make bundles -- make default -- make shell -- make test-unit -- make test-integration-cli -- make - -The Makefile does include logic to determine on which OS and architecture the Docker Development Image is built. -Based on OS and architecture it chooses the correct Dockerfile. -For the ARM 32bit architecture it uses `Dockerfile.armhf`. - -So for example in order to build a Docker binary one has to -1. clone the Docker/Docker repository on an ARM device `git clone git@github.com:docker/docker.git` -2. change into the checked out repository with `cd docker` -3. execute `make binary` to create a Docker Engine binary for ARM - -## Kernel modules -A few libnetwork integration tests require that the kernel be -configured with "dummy" network interface and has the module -loaded. However, the dummy module may be not loaded automatically. - -To load the kernel module permanently, run these commands as `root`. - - modprobe dummy - echo "dummy" >> /etc/modules - -On some systems you also have to sync your kernel modules. - - oc-sync-kernel-modules - depmod diff --git a/vendor/github.com/docker/docker/project/BRANCHES-AND-TAGS.md b/vendor/github.com/docker/docker/project/BRANCHES-AND-TAGS.md deleted file mode 100644 index 1c6f232..0000000 --- a/vendor/github.com/docker/docker/project/BRANCHES-AND-TAGS.md +++ /dev/null @@ -1,35 +0,0 @@ -Branches and tags -================= - -Note: details of the release process for the Engine are documented in the -[RELEASE-CHECKLIST](https://github.com/docker/docker/blob/master/project/RELEASE-CHECKLIST.md). - -# Branches - -The docker/docker repository should normally have only three living branches at all time, including -the regular `master` branch: - -## `docs` branch - -The `docs` branch supports documentation updates between product releases. This branch allow us to -decouple documentation releases from product releases. - -## `release` branch - -The `release` branch contains the last _released_ version of the code for the project. - -The `release` branch is only updated at each public release of the project. The mechanism for this -is that the release is materialized by a pull request against the `release` branch which lives for -the duration of the code freeze period. When this pull request is merged, the `release` branch gets -updated, and its new state is tagged accordingly. - -# Tags - -Any public release of a compiled binary, with the logical exception of nightly builds, should have -a corresponding tag in the repository. - -The general format of a tag is `vX.Y.Z[-suffix[N]]`: - -- All of `X`, `Y`, `Z` must be specified (example: `v1.0.0`) -- First release candidate for version `1.8.0` should be tagged `v1.8.0-rc1` -- Second alpha release of a product should be tagged `v1.0.0-alpha1` diff --git a/vendor/github.com/docker/docker/project/CONTRIBUTORS.md b/vendor/github.com/docker/docker/project/CONTRIBUTORS.md deleted file mode 120000 index 44fcc63..0000000 --- a/vendor/github.com/docker/docker/project/CONTRIBUTORS.md +++ /dev/null @@ -1 +0,0 @@ -../CONTRIBUTING.md \ No newline at end of file diff --git a/vendor/github.com/docker/docker/project/GOVERNANCE.md b/vendor/github.com/docker/docker/project/GOVERNANCE.md deleted file mode 100644 index 6ae7baf..0000000 --- a/vendor/github.com/docker/docker/project/GOVERNANCE.md +++ /dev/null @@ -1,17 +0,0 @@ -# Docker Governance Advisory Board Meetings - -In the spirit of openness, Docker created a Governance Advisory Board, and committed to make all materials and notes from the meetings of this group public. -All output from the meetings should be considered proposals only, and are subject to the review and approval of the community and the project leadership. - -The materials from the first Docker Governance Advisory Board meeting, held on October 28, 2014, are available at -[Google Docs Folder](https://goo.gl/Alfj8r) - -These include: - -* First Meeting Notes -* DGAB Charter -* Presentation 1: Introductory Presentation, including State of The Project -* Presentation 2: Overall Contribution Structure/Docker Project Core Proposal -* Presentation 3: Long Term Roadmap/Statement of Direction - - diff --git a/vendor/github.com/docker/docker/project/IRC-ADMINISTRATION.md b/vendor/github.com/docker/docker/project/IRC-ADMINISTRATION.md deleted file mode 100644 index 824a14b..0000000 --- a/vendor/github.com/docker/docker/project/IRC-ADMINISTRATION.md +++ /dev/null @@ -1,37 +0,0 @@ -# Freenode IRC Administration Guidelines and Tips - -This is not meant to be a general "Here's how to IRC" document, so if you're -looking for that, check Google instead. ♥ - -If you've been charged with helping maintain one of Docker's now many IRC -channels, this might turn out to be useful. If there's information that you -wish you'd known about how a particular channel is organized, you should add -deets here! :) - -## `ChanServ` - -Most channel maintenance happens by talking to Freenode's `ChanServ` bot. For -example, `/msg ChanServ ACCESS LIST` will show you a list of everyone -with "access" privileges for a particular channel. - -A similar command is used to give someone a particular access level. For -example, to add a new maintainer to the `#docker-maintainers` access list so -that they can contribute to the discussions (after they've been merged -appropriately in a `MAINTAINERS` file, of course), one would use `/msg ChanServ -ACCESS #docker-maintainers ADD maintainer`. - -To setup a new channel with a similar `maintainer` access template, use a -command like `/msg ChanServ TEMPLATE maintainer +AV` (`+A` for letting -them view the `ACCESS LIST`, `+V` for auto-voice; see `/msg ChanServ HELP FLAGS` -for more details). - -## Troubleshooting - -The most common cause of not-getting-auto-`+v` woes is people not being -`IDENTIFY`ed with `NickServ` (or their current nickname not being `GROUP`ed with -their main nickname) -- often manifested by `ChanServ` responding to an `ACCESS -ADD` request with something like `xyz is not registered.`. - -This is easily fixed by doing `/msg NickServ IDENTIFY OldNick SecretPassword` -followed by `/msg NickServ GROUP` to group the two nicknames together. See -`/msg NickServ HELP GROUP` for more information. diff --git a/vendor/github.com/docker/docker/project/ISSUE-TRIAGE.md b/vendor/github.com/docker/docker/project/ISSUE-TRIAGE.md deleted file mode 100644 index 95cb2f1..0000000 --- a/vendor/github.com/docker/docker/project/ISSUE-TRIAGE.md +++ /dev/null @@ -1,132 +0,0 @@ -Triaging of issues ------------------- - -Triage provides an important way to contribute to an open source project. Triage helps ensure issues resolve quickly by: - -- Describing the issue's intent and purpose is conveyed precisely. This is necessary because it can be difficult for an issue to explain how an end user experiences a problem and what actions they took. -- Giving a contributor the information they need before they commit to resolving an issue. -- Lowering the issue count by preventing duplicate issues. -- Streamlining the development process by preventing duplicate discussions. - -If you don't have time to code, consider helping with triage. The community will thank you for saving them time by spending some of yours. - -### 1. Ensure the issue contains basic information - -Before triaging an issue very far, make sure that the issue's author provided the standard issue information. This will help you make an educated recommendation on how this to categorize the issue. Standard information that *must* be included in most issues are things such as: - -- the output of `docker version` -- the output of `docker info` -- the output of `uname -a` -- a reproducible case if this is a bug, Dockerfiles FTW -- host distribution and version ( ubuntu 14.04, RHEL, fedora 23 ) -- page URL if this is a docs issue or the name of a man page - -Depending on the issue, you might not feel all this information is needed. Use your best judgement. If you cannot triage an issue using what its author provided, explain kindly to the author that they must provide the above information to clarify the problem. - -If the author provides the standard information but you are still unable to triage the issue, request additional information. Do this kindly and politely because you are asking for more of the author's time. - -If the author does not respond requested information within the timespan of a week, close the issue with a kind note stating that the author can request for the issue to be -reopened when the necessary information is provided. - -### 2. Classify the Issue - -An issue can have multiple of the following labels. Typically, a properly classified issues should -have: - -- One label identifying its kind (`kind/*`). -- One or multiple labels identifying the functional areas of interest (`area/*`). -- Where applicable, one label categorizing its difficulty (`exp/*`). - -#### Issue kind - -| Kind | Description | -|------------------|---------------------------------------------------------------------------------------------------------------------------------| -| kind/bug | Bugs are bugs. The cause may or may not be known at triage time so debugging should be taken account into the time estimate. | -| kind/enhancement | Enhancement are not bugs or new features but can drastically improve usability or performance of a project component. | -| kind/feature | Functionality or other elements that the project does not currently support. Features are new and shiny. | -| kind/question | Contains a user or contributor question requiring a response. | - -#### Functional area - -| Area | -|---------------------------| -| area/api | -| area/builder | -| area/bundles | -| area/cli | -| area/daemon | -| area/distribution | -| area/docs | -| area/kernel | -| area/logging | -| area/networking | -| area/plugins | -| area/project | -| area/runtime | -| area/security | -| area/security/apparmor | -| area/security/seccomp | -| area/security/selinux | -| area/security/trust | -| area/storage | -| area/storage/aufs | -| area/storage/btrfs | -| area/storage/devicemapper | -| area/storage/overlay | -| area/storage/zfs | -| area/swarm | -| area/testing | -| area/volumes | - -#### Platform - -| Platform | -|---------------------------| -| platform/arm | -| platform/darwin | -| platform/ibm-power | -| platform/ibm-z | -| platform/windows | - -#### Experience level - -Experience level is a way for a contributor to find an issue based on their -skill set. Experience types are applied to the issue or pull request using -labels. - -| Level | Experience level guideline | -|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| exp/beginner | New to Docker, and possibly Golang, and is looking to help while learning the basics. | -| exp/intermediate | Comfortable with golang and understands the core concepts of Docker and looking to dive deeper into the project. | -| exp/expert | Proficient with Docker and Golang and has been following, and active in, the community to understand the rationale behind design decisions and where the project is headed. | - -As the table states, these labels are meant as guidelines. You might have -written a whole plugin for Docker in a personal project and never contributed to -Docker. With that kind of experience, you could take on an exp/expert level task. - -#### Triage status - -To communicate the triage status with other collaborators, you can apply status -labels to issues. These labels prevent duplicating effort. - -| Status | Description | -|-------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| status/confirmed | You triaged the issue, and were able to reproduce the issue. Always leave a comment how you reproduced, so that the person working on resolving the issue has a way to set up a test-case. -| status/accepted | Apply to enhancements / feature requests that we think are good to have. Adding this label helps contributors find things to work on. -| status/more-info-needed | Apply this to issues that are missing information (e.g. no `docker version` or `docker info` output, or no steps to reproduce), or require feedback from the reporter. If the issue is not updated after a week, it can generally be closed. -| status/needs-attention | Apply this label if an issue (or PR) needs more eyes. - -### 3. Prioritizing issue - -When, and only when, an issue is attached to a specific milestone, the issue can be labeled with the -following labels to indicate their degree of priority (from more urgent to less urgent). - -| Priority | Description | -|-------------|-----------------------------------------------------------------------------------------------------------------------------------| -| priority/P0 | Urgent: Security, critical bugs, blocking issues. P0 basically means drop everything you are doing until this issue is addressed. | -| priority/P1 | Important: P1 issues are a top priority and a must-have for the next release. | -| priority/P2 | Normal priority: default priority applied. | -| priority/P3 | Best effort: those are nice to have / minor issues. | - -And that's it. That should be all the information required for a new or existing contributor to come in an resolve an issue. diff --git a/vendor/github.com/docker/docker/project/PACKAGE-REPO-MAINTENANCE.md b/vendor/github.com/docker/docker/project/PACKAGE-REPO-MAINTENANCE.md deleted file mode 100644 index 3763f87..0000000 --- a/vendor/github.com/docker/docker/project/PACKAGE-REPO-MAINTENANCE.md +++ /dev/null @@ -1,74 +0,0 @@ -# Apt & Yum Repository Maintenance -## A maintainer's guide to managing Docker's package repos - -### How to clean up old experimental debs and rpms - -We release debs and rpms for experimental nightly, so these can build up. -To remove old experimental debs and rpms, and _ONLY_ keep the latest, follow the -steps below. - -1. Checkout docker master - -2. Run clean scripts - -```bash -docker build --rm --force-rm -t docker-dev:master . -docker run --rm -it --privileged \ - -v /path/to/your/repos/dir:/volumes/repos \ - -v $HOME/.gnupg:/root/.gnupg \ - -e GPG_PASSPHRASE \ - -e DOCKER_RELEASE_DIR=/volumes/repos \ - docker-dev:master hack/make.sh clean-apt-repo clean-yum-repo generate-index-listing sign-repos -``` - -3. Upload the changed repos to `s3` (if you host on s3) - -4. Purge the cache, PURGE the cache, PURGE THE CACHE! - -### How to get out of a sticky situation - -Sh\*t happens. We know. Below are steps to get out of any "hash-sum mismatch" or -"gpg sig error" or the likes error that might happen to the apt repo. - -**NOTE:** These are apt repo specific, have had no experimence with anything similar -happening to the yum repo in the past so you can rest easy. - -For each step listed below, move on to the next if the previous didn't work. -Otherwise CELEBRATE! - -1. Purge the cache. - -2. Did you remember to sign the debs after releasing? - -Re-sign the repo with your gpg key: - -```bash -docker build --rm --force-rm -t docker-dev:master . -docker run --rm -it --privileged \ - -v /path/to/your/repos/dir:/volumes/repos \ - -v $HOME/.gnupg:/root/.gnupg \ - -e GPG_PASSPHRASE \ - -e DOCKER_RELEASE_DIR=/volumes/repos \ - docker-dev:master hack/make.sh sign-repos -``` - -Upload the changed repo to `s3` (if that is where you host) - -PURGE THE CACHE. - -3. Run Jess' magical, save all, only in case of extreme emergencies, "you are -going to have to break this glass to get it" script. - -```bash -docker build --rm --force-rm -t docker-dev:master . -docker run --rm -it --privileged \ - -v /path/to/your/repos/dir:/volumes/repos \ - -v $HOME/.gnupg:/root/.gnupg \ - -e GPG_PASSPHRASE \ - -e DOCKER_RELEASE_DIR=/volumes/repos \ - docker-dev:master hack/make.sh update-apt-repo generate-index-listing sign-repos -``` - -4. Upload the changed repo to `s3` (if that is where you host) - -PURGE THE CACHE. diff --git a/vendor/github.com/docker/docker/project/PACKAGERS.md b/vendor/github.com/docker/docker/project/PACKAGERS.md deleted file mode 100644 index 46ea8e7..0000000 --- a/vendor/github.com/docker/docker/project/PACKAGERS.md +++ /dev/null @@ -1,307 +0,0 @@ -# Dear Packager, - -If you are looking to make Docker available on your favorite software -distribution, this document is for you. It summarizes the requirements for -building and running the Docker client and the Docker daemon. - -## Getting Started - -We want to help you package Docker successfully. Before doing any packaging, a -good first step is to introduce yourself on the [docker-dev mailing -list](https://groups.google.com/d/forum/docker-dev), explain what you're trying -to achieve, and tell us how we can help. Don't worry, we don't bite! There might -even be someone already working on packaging for the same distro! - -You can also join the IRC channel - #docker and #docker-dev on Freenode are both -active and friendly. - -We like to refer to Tianon ("@tianon" on GitHub and "tianon" on IRC) as our -"Packagers Relations", since he's always working to make sure our packagers have -a good, healthy upstream to work with (both in our communication and in our -build scripts). If you're having any kind of trouble, feel free to ping him -directly. He also likes to keep track of what distributions we have packagers -for, so feel free to reach out to him even just to say "Hi!" - -## Package Name - -If possible, your package should be called "docker". If that name is already -taken, a second choice is "docker-engine". Another possible choice is "docker.io". - -## Official Build vs Distro Build - -The Docker project maintains its own build and release toolchain. It is pretty -neat and entirely based on Docker (surprise!). This toolchain is the canonical -way to build Docker. We encourage you to give it a try, and if the circumstances -allow you to use it, we recommend that you do. - -You might not be able to use the official build toolchain - usually because your -distribution has a toolchain and packaging policy of its own. We get it! Your -house, your rules. The rest of this document should give you the information you -need to package Docker your way, without denaturing it in the process. - -## Build Dependencies - -To build Docker, you will need the following: - -* A recent version of Git and Mercurial -* Go version 1.6 or later -* A clean checkout of the source added to a valid [Go - workspace](https://golang.org/doc/code.html#Workspaces) under the path - *src/github.com/docker/docker* (unless you plan to use `AUTO_GOPATH`, - explained in more detail below) - -To build the Docker daemon, you will additionally need: - -* An amd64/x86_64 machine running Linux -* SQLite version 3.7.9 or later -* libdevmapper version 1.02.68-cvs (2012-01-26) or later from lvm2 version - 2.02.89 or later -* btrfs-progs version 3.16.1 or later (unless using an older version is - absolutely necessary, in which case 3.8 is the minimum) -* libseccomp version 2.2.1 or later (for build tag seccomp) - -Be sure to also check out Docker's Dockerfile for the most up-to-date list of -these build-time dependencies. - -### Go Dependencies - -All Go dependencies are vendored under "./vendor". They are used by the official -build, so the source of truth for the current version of each dependency is -whatever is in "./vendor". - -To use the vendored dependencies, simply make sure the path to "./vendor" is -included in `GOPATH` (or use `AUTO_GOPATH`, as explained below). - -If you would rather (or must, due to distro policy) package these dependencies -yourself, take a look at "vendor.conf" for an easy-to-parse list of the -exact version for each. - -NOTE: if you're not able to package the exact version (to the exact commit) of a -given dependency, please get in touch so we can remediate! Who knows what -discrepancies can be caused by even the slightest deviation. We promise to do -our best to make everybody happy. - -## Stripping Binaries - -Please, please, please do not strip any compiled binaries. This is really -important. - -In our own testing, stripping the resulting binaries sometimes results in a -binary that appears to work, but more often causes random panics, segfaults, and -other issues. Even if the binary appears to work, please don't strip. - -See the following quotes from Dave Cheney, which explain this position better -from the upstream Golang perspective. - -### [go issue #5855, comment #3](https://code.google.com/p/go/issues/detail?id=5855#c3) - -> Super super important: Do not strip go binaries or archives. It isn't tested, -> often breaks, and doesn't work. - -### [launchpad golang issue #1200255, comment #8](https://bugs.launchpad.net/ubuntu/+source/golang/+bug/1200255/comments/8) - -> To quote myself: "Please do not strip Go binaries, it is not supported, not -> tested, is often broken, and doesn't do what you want" -> -> To unpack that a bit -> -> * not supported, as in, we don't support it, and recommend against it when -> asked -> * not tested, we don't test stripped binaries as part of the build CI process -> * is often broken, stripping a go binary will produce anywhere from no, to -> subtle, to outright execution failure, see above - -### [launchpad golang issue #1200255, comment #13](https://bugs.launchpad.net/ubuntu/+source/golang/+bug/1200255/comments/13) - -> To clarify my previous statements. -> -> * I do not disagree with the debian policy, it is there for a good reason -> * Having said that, it stripping Go binaries doesn't work, and nobody is -> looking at making it work, so there is that. -> -> Thanks for patching the build formula. - -## Building Docker - -Please use our build script ("./hack/make.sh") for all your compilation of -Docker. If there's something you need that it isn't doing, or something it could -be doing to make your life as a packager easier, please get in touch with Tianon -and help us rectify the situation. Chances are good that other packagers have -probably run into the same problems and a fix might already be in the works, but -none of us will know for sure unless you harass Tianon about it. :) - -All the commands listed within this section should be run with the Docker source -checkout as the current working directory. - -### `AUTO_GOPATH` - -If you'd rather not be bothered with the hassles that setting up `GOPATH` -appropriately can be, and prefer to just get a "build that works", you should -add something similar to this to whatever script or process you're using to -build Docker: - -```bash -export AUTO_GOPATH=1 -``` - -This will cause the build scripts to set up a reasonable `GOPATH` that -automatically and properly includes both docker/docker from the local -directory, and the local "./vendor" directory as necessary. - -### `DOCKER_BUILDTAGS` - -If you're building a binary that may need to be used on platforms that include -AppArmor, you will need to set `DOCKER_BUILDTAGS` as follows: -```bash -export DOCKER_BUILDTAGS='apparmor' -``` - -If you're building a binary that may need to be used on platforms that include -SELinux, you will need to use the `selinux` build tag: -```bash -export DOCKER_BUILDTAGS='selinux' -``` - -If you're building a binary that may need to be used on platforms that include -seccomp, you will need to use the `seccomp` build tag: -```bash -export DOCKER_BUILDTAGS='seccomp' -``` - -There are build tags for disabling graphdrivers as well. By default, support -for all graphdrivers are built in. - -To disable btrfs: -```bash -export DOCKER_BUILDTAGS='exclude_graphdriver_btrfs' -``` - -To disable devicemapper: -```bash -export DOCKER_BUILDTAGS='exclude_graphdriver_devicemapper' -``` - -To disable aufs: -```bash -export DOCKER_BUILDTAGS='exclude_graphdriver_aufs' -``` - -NOTE: if you need to set more than one build tag, space separate them: -```bash -export DOCKER_BUILDTAGS='apparmor selinux exclude_graphdriver_aufs' -``` - -### Static Daemon - -If it is feasible within the constraints of your distribution, you should -seriously consider packaging Docker as a single static binary. A good comparison -is Busybox, which is often packaged statically as a feature to enable mass -portability. Because of the unique way Docker operates, being similarly static -is a "feature". - -To build a static Docker daemon binary, run the following command (first -ensuring that all the necessary libraries are available in static form for -linking - see the "Build Dependencies" section above, and the relevant lines -within Docker's own Dockerfile that set up our official build environment): - -```bash -./hack/make.sh binary -``` - -This will create a static binary under -"./bundles/$VERSION/binary/docker-$VERSION", where "$VERSION" is the contents of -the file "./VERSION". This binary is usually installed somewhere like -"/usr/bin/docker". - -### Dynamic Daemon / Client-only Binary - -If you are only interested in a Docker client binary, you can build using: - -```bash -./hack/make.sh binary-client -``` - -If you need to (due to distro policy, distro library availability, or for other -reasons) create a dynamically compiled daemon binary, or if you are only -interested in creating a client binary for Docker, use something similar to the -following: - -```bash -./hack/make.sh dynbinary-client -``` - -This will create "./bundles/$VERSION/dynbinary-client/docker-$VERSION", which for -client-only builds is the important file to grab and install as appropriate. - -## System Dependencies - -### Runtime Dependencies - -To function properly, the Docker daemon needs the following software to be -installed and available at runtime: - -* iptables version 1.4 or later -* procps (or similar provider of a "ps" executable) -* e2fsprogs version 1.4.12 or later (in use: mkfs.ext4, tune2fs) -* xfsprogs (in use: mkfs.xfs) -* XZ Utils version 4.9 or later -* a [properly - mounted](https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount) - cgroupfs hierarchy (having a single, all-encompassing "cgroup" mount point - [is](https://github.com/docker/docker/issues/2683) - [not](https://github.com/docker/docker/issues/3485) - [sufficient](https://github.com/docker/docker/issues/4568)) - -Additionally, the Docker client needs the following software to be installed and -available at runtime: - -* Git version 1.7 or later - -### Kernel Requirements - -The Docker daemon has very specific kernel requirements. Most pre-packaged -kernels already include the necessary options enabled. If you are building your -own kernel, you will either need to discover the options necessary via trial and -error, or check out the [Gentoo -ebuild](https://github.com/tianon/docker-overlay/blob/master/app-emulation/docker/docker-9999.ebuild), -in which a list is maintained (and if there are any issues or discrepancies in -that list, please contact Tianon so they can be rectified). - -Note that in client mode, there are no specific kernel requirements, and that -the client will even run on alternative platforms such as Mac OS X / Darwin. - -### Optional Dependencies - -Some of Docker's features are activated by using optional command-line flags or -by having support for them in the kernel or userspace. A few examples include: - -* AUFS graph driver (requires AUFS patches/support enabled in the kernel, and at - least the "auplink" utility from aufs-tools) -* BTRFS graph driver (requires BTRFS support enabled in the kernel) -* ZFS graph driver (requires userspace zfs-utils and a corresponding kernel module) -* Libseccomp to allow running seccomp profiles with containers - -## Daemon Init Script - -Docker expects to run as a daemon at machine startup. Your package will need to -include a script for your distro's process supervisor of choice. Be sure to -check out the "contrib/init" folder in case a suitable init script already -exists (and if one does not, contact Tianon about whether it might be -appropriate for your distro's init script to live there too!). - -In general, Docker should be run as root, similar to the following: - -```bash -docker daemon -``` - -Generally, a `DOCKER_OPTS` variable of some kind is available for adding more -flags (such as changing the graph driver to use BTRFS, switching the location of -"/var/lib/docker", etc). - -## Communicate - -As a final note, please do feel free to reach out to Tianon at any time for -pretty much anything. He really does love hearing from our packagers and wants -to make sure we're not being a "hostile upstream". As should be a given, we -appreciate the work our packagers do to make sure we have broad distribution! diff --git a/vendor/github.com/docker/docker/project/PATCH-RELEASES.md b/vendor/github.com/docker/docker/project/PATCH-RELEASES.md deleted file mode 100644 index 548db9a..0000000 --- a/vendor/github.com/docker/docker/project/PATCH-RELEASES.md +++ /dev/null @@ -1,68 +0,0 @@ -# Docker patch (bugfix) release process - -Patch releases (the 'Z' in vX.Y.Z) are intended to fix major issues in a -release. Docker open source projects follow these procedures when creating a -patch release; - -After each release (both "major" (vX.Y.0) and "patch" releases (vX.Y.Z)), a -patch release milestone (vX.Y.Z + 1) is created. - -The creation of a patch release milestone is no obligation to actually -*create* a patch release. The purpose of these milestones is to collect -issues and pull requests that can *justify* a patch release; - -- Any maintainer is allowed to add issues and PR's to the milestone, when - doing so, preferably leave a comment on the issue or PR explaining *why* - you think it should be considered for inclusion in a patch release. -- Issues introduced in version vX.Y.0 get added to milestone X.Y.Z+1 -- Only *regressions* should be added. Issues *discovered* in version vX.Y.0, - but already present in version vX.Y-1.Z should not be added, unless - critical. -- Patch releases can *only* contain bug-fixes. New features should - *never* be added to a patch release. - -The release captain of the "major" (X.Y.0) release, is also responsible for -patch releases. The release captain, together with another maintainer, will -review issues and PRs on the milestone, and assigns `priority/`labels. These -review sessions take place on a weekly basis, more frequent if needed: - -- A P0 priority is assigned to critical issues. A maintainer *must* be - assigned to these issues. Maintainers should strive to fix a P0 within a week. -- A P1 priority is assigned to major issues, but not critical. A maintainer - *must* be assigned to these issues. -- P2 and P3 priorities are assigned to other issues. A maintainer can be - assigned. -- Non-critical issues and PR's can be removed from the milestone. Minor - changes, such as typo-fixes or omissions in the documentation can be - considered for inclusion in a patch release. - -## Deciding if a patch release should be done - -- Only a P0 can justify to proceed with the patch release. -- P1, P2, and P3 issues/PR's should not influence the decision, and - should be moved to the X.Y.Z+1 milestone, or removed from the - milestone. - -> **Note**: If the next "major" release is imminent, the release captain -> can decide to cancel a patch release, and include the patches in the -> upcoming major release. - -> **Note**: Security releases are also "patch releases", but follow -> a different procedure. Security releases are developed in a private -> repository, released and tested under embargo before they become -> publicly available. - -## Deciding on the content of a patch release - -When the criteria for moving forward with a patch release are met, the release -manager will decide on the exact content of the release. - -- Fixes to all P0 issues *must* be included in the release. -- Fixes to *some* P1, P2, and P3 issues *may* be included as part of the patch - release depending on the severity of the issue and the risk associated with - the patch. - -Any code delivered as part of a patch release should make life easier for a -significant amount of users with zero chance of degrading anybody's experience. -A good rule of thumb for that is to limit cherry-picking to small patches, which -fix well-understood issues, and which come with verifiable tests. diff --git a/vendor/github.com/docker/docker/project/PRINCIPLES.md b/vendor/github.com/docker/docker/project/PRINCIPLES.md deleted file mode 100644 index 53f0301..0000000 --- a/vendor/github.com/docker/docker/project/PRINCIPLES.md +++ /dev/null @@ -1,19 +0,0 @@ -# Docker principles - -In the design and development of Docker we try to follow these principles: - -(Work in progress) - -* Don't try to replace every tool. Instead, be an ingredient to improve them. -* Less code is better. -* Fewer components are better. Do you really need to add one more class? -* 50 lines of straightforward, readable code is better than 10 lines of magic that nobody can understand. -* Don't do later what you can do now. "//FIXME: refactor" is not acceptable in new code. -* When hesitating between 2 options, choose the one that is easier to reverse. -* No is temporary, Yes is forever. If you're not sure about a new feature, say no. You can change your mind later. -* Containers must be portable to the greatest possible number of machines. Be suspicious of any change which makes machines less interchangeable. -* The less moving parts in a container, the better. -* Don't merge it unless you document it. -* Don't document it unless you can keep it up-to-date. -* Don't merge it unless you test it! -* Everyone's problem is slightly different. Focus on the part that is the same for everyone, and solve that. diff --git a/vendor/github.com/docker/docker/project/README.md b/vendor/github.com/docker/docker/project/README.md deleted file mode 100644 index 3ed68cf..0000000 --- a/vendor/github.com/docker/docker/project/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Hacking on Docker - -The `project/` directory holds information and tools for everyone involved in the process of creating and -distributing Docker, specifically: - -## Guides - -If you're a *contributor* or aspiring contributor, you should read [CONTRIBUTORS.md](../CONTRIBUTING.md). - -If you're a *maintainer* or aspiring maintainer, you should read [MAINTAINERS](../MAINTAINERS). - -If you're a *packager* or aspiring packager, you should read [PACKAGERS.md](./PACKAGERS.md). - -If you're a maintainer in charge of a *release*, you should read [RELEASE-CHECKLIST.md](./RELEASE-CHECKLIST.md). - -## Roadmap - -A high-level roadmap is available at [ROADMAP.md](../ROADMAP.md). - - -## Build tools - -[hack/make.sh](../hack/make.sh) is the primary build tool for docker. It is used for compiling the official binary, -running the test suite, and pushing releases. diff --git a/vendor/github.com/docker/docker/project/RELEASE-CHECKLIST.md b/vendor/github.com/docker/docker/project/RELEASE-CHECKLIST.md deleted file mode 100644 index 84848ca..0000000 --- a/vendor/github.com/docker/docker/project/RELEASE-CHECKLIST.md +++ /dev/null @@ -1,518 +0,0 @@ -# Release Checklist -## A maintainer's guide to releasing Docker - -So you're in charge of a Docker release? Cool. Here's what to do. - -If your experience deviates from this document, please document the changes -to keep it up-to-date. - -It is important to note that this document assumes that the git remote in your -repository that corresponds to "https://github.com/docker/docker" is named -"origin". If yours is not (for example, if you've chosen to name it "upstream" -or something similar instead), be sure to adjust the listed snippets for your -local environment accordingly. If you are not sure what your upstream remote is -named, use a command like `git remote -v` to find out. - -If you don't have an upstream remote, you can add one easily using something -like: - -```bash -export GITHUBUSER="YOUR_GITHUB_USER" -git remote add origin https://github.com/docker/docker.git -git remote add $GITHUBUSER git@github.com:$GITHUBUSER/docker.git -``` - -### 1. Pull from master and create a release branch - -All releases version numbers will be of the form: vX.Y.Z where X is the major -version number, Y is the minor version number and Z is the patch release version number. - -#### Major releases - -The release branch name is just vX.Y because it's going to be the basis for all .Z releases. - -```bash -export BASE=vX.Y -export VERSION=vX.Y.Z -git fetch origin -git checkout --track origin/master -git checkout -b release/$BASE -``` - -This new branch is going to be the base for the release. We need to push it to origin so we -can track the cherry-picked changes and the version bump: - -```bash -git push origin release/$BASE -``` - -When you have the major release branch in origin, we need to create the bump fork branch -that we'll push to our fork: - -```bash -git checkout -b bump_$VERSION -``` - -#### Patch releases - -If we have the release branch in origin, we can create the forked bump branch from it directly: - -```bash -export VERSION=vX.Y.Z -export PATCH=vX.Y.Z+1 -git fetch origin -git checkout --track origin/release/$BASE -git checkout -b bump_$PATCH -``` - -We cherry-pick only the commits we want into the bump branch: - -```bash -# get the commits ids we want to cherry-pick -git log -# cherry-pick the commits starting from the oldest one, without including merge commits -git cherry-pick -s -x -git cherry-pick -s -x -... -``` - -### 2. Update the VERSION files and API version on master - -We don't want to stop contributions to master just because we are releasing. -So, after the release branch is up, we bump the VERSION and API version to mark -the start of the "next" release. - -#### 2.1 Update the VERSION files - -Update the content of the `VERSION` file to be the next minor (incrementing Y) -and add the `-dev` suffix. For example, after the release branch for 1.5.0 is -created, the `VERSION` file gets updated to `1.6.0-dev` (as in "1.6.0 in the -making"). - -#### 2.2 Update API version on master - -We don't want API changes to go to the now frozen API version. Create a new -entry in `docs/reference/api/` by copying the latest and bumping the version -number (in both the file's name and content), and submit this in a PR against -master. - -### 3. Update CHANGELOG.md - -You can run this command for reference with git 2.0: - -```bash -git fetch --tags -LAST_VERSION=$(git tag -l --sort=-version:refname "v*" | grep -E 'v[0-9\.]+$' | head -1) -git log --stat $LAST_VERSION..bump_$VERSION -``` - -If you don't have git 2.0 but have a sort command that supports `-V`: -```bash -git fetch --tags -LAST_VERSION=$(git tag -l | grep -E 'v[0-9\.]+$' | sort -rV | head -1) -git log --stat $LAST_VERSION..bump_$VERSION -``` - -If releasing a major version (X or Y increased in vX.Y.Z), simply listing notable user-facing features is sufficient. -```markdown -#### Notable features since -* New docker command to do something useful -* Engine API change (deprecating old version) -* Performance improvements in some usecases -* ... -``` - -For minor releases (only Z increases in vX.Y.Z), provide a list of user-facing changes. -Each change should be listed under a category heading formatted as `#### CATEGORY`. - -`CATEGORY` should describe which part of the project is affected. - Valid categories are: - * Builder - * Documentation - * Hack - * Packaging - * Engine API - * Runtime - * Other (please use this category sparingly) - -Each change should be formatted as `BULLET DESCRIPTION`, given: - -* BULLET: either `-`, `+` or `*`, to indicate a bugfix, new feature or - upgrade, respectively. - -* DESCRIPTION: a concise description of the change that is relevant to the - end-user, using the present tense. Changes should be described in terms - of how they affect the user, for example "Add new feature X which allows Y", - "Fix bug which caused X", "Increase performance of Y". - -EXAMPLES: - -```markdown -## 0.3.6 (1995-12-25) - -#### Builder - -+ 'docker build -t FOO .' applies the tag FOO to the newly built image - -#### Engine API - -- Fix a bug in the optional unix socket transport - -#### Runtime - -* Improve detection of kernel version -``` - -If you need a list of contributors between the last major release and the -current bump branch, use something like: -```bash -git log --format='%aN <%aE>' v0.7.0...bump_v0.8.0 | sort -uf -``` -Obviously, you'll need to adjust version numbers as necessary. If you just need -a count, add a simple `| wc -l`. - -### 4. Change the contents of the VERSION file - -Before the big thing, you'll want to make successive release candidates and get -people to test. The release candidate number `N` should be part of the version: - -```bash -export RC_VERSION=${VERSION}-rcN -echo ${RC_VERSION#v} > VERSION -``` - -### 5. Test the docs - -Make sure that your tree includes documentation for any modified or -new features, syntax or semantic changes. - -To test locally: - -```bash -make docs -``` - -To make a shared test at https://beta-docs.docker.io: - -(You will need the `awsconfig` file added to the `docs/` dir) - -```bash -make AWS_S3_BUCKET=beta-docs.docker.io BUILD_ROOT=yes docs-release -``` - -### 6. Commit and create a pull request to the "release" branch - -```bash -git add VERSION CHANGELOG.md -git commit -m "Bump version to $VERSION" -git push $GITHUBUSER bump_$VERSION -echo "https://github.com/$GITHUBUSER/docker/compare/docker:release/$BASE...$GITHUBUSER:bump_$VERSION?expand=1" -``` - -That last command will give you the proper link to visit to ensure that you -open the PR against the "release" branch instead of accidentally against -"master" (like so many brave souls before you already have). - -### 7. Create a PR to update the AUTHORS file for the release - -Update the AUTHORS file, by running the `hack/generate-authors.sh` on the -release branch. To prevent duplicate entries, you may need to update the -`.mailmap` file accordingly. - -### 8. Build release candidate rpms and debs - -**NOTE**: It will be a lot faster if you pass a different graphdriver with -`DOCKER_GRAPHDRIVER` than `vfs`. - -```bash -docker build -t docker . -docker run \ - --rm -t --privileged \ - -e DOCKER_GRAPHDRIVER=aufs \ - -v $(pwd)/bundles:/go/src/github.com/docker/docker/bundles \ - docker \ - hack/make.sh binary build-deb build-rpm -``` - -### 9. Publish release candidate rpms and debs - -With the rpms and debs you built from the last step you can release them on the -same server, or ideally, move them to a dedicated release box via scp into -another docker/docker directory in bundles. This next step assumes you have -a checkout of the docker source code at the same commit you used to build, with -the artifacts from the last step in `bundles`. - -**NOTE:** If you put a space before the command your `.bash_history` will not -save it. (for the `GPG_PASSPHRASE`). - -```bash -docker build -t docker . -docker run --rm -it --privileged \ - -v /volumes/repos:/volumes/repos \ - -v $(pwd)/bundles:/go/src/github.com/docker/docker/bundles \ - -v $HOME/.gnupg:/root/.gnupg \ - -e DOCKER_RELEASE_DIR=/volumes/repos \ - -e GPG_PASSPHRASE \ - -e KEEPBUNDLE=1 \ - docker \ - hack/make.sh release-deb release-rpm sign-repos generate-index-listing -``` - -### 10. Upload the changed repos to wherever you host - -For example, above we bind mounted `/volumes/repos` as the storage for -`DOCKER_RELEASE_DIR`. In this case `/volumes/repos/apt` can be synced with -a specific s3 bucket for the apt repo and `/volumes/repos/yum` can be synced with -a s3 bucket for the yum repo. - -### 11. Publish release candidate binaries - -To run this you will need access to the release credentials. Get them from the -Core maintainers. - -```bash -docker build -t docker . - -# static binaries are still pushed to s3 -docker run \ - -e AWS_S3_BUCKET=test.docker.com \ - -e AWS_ACCESS_KEY_ID \ - -e AWS_SECRET_ACCESS_KEY \ - -e AWS_DEFAULT_REGION \ - -i -t --privileged \ - docker \ - hack/release.sh -``` - -It will run the test suite, build the binaries and upload to the specified bucket, -so this is a good time to verify that you're running against **test**.docker.com. - -### 12. Purge the cache! - -After the binaries are uploaded to test.docker.com and the packages are on -apt.dockerproject.org and yum.dockerproject.org, make sure -they get tested in both Ubuntu and Debian for any obvious installation -issues or runtime issues. - -If everything looks good, it's time to create a git tag for this candidate: - -```bash -git tag -a $RC_VERSION -m $RC_VERSION bump_$VERSION -git push origin $RC_VERSION -``` - -Announcing on multiple medias is the best way to get some help testing! An easy -way to get some useful links for sharing: - -```bash -echo "Ubuntu/Debian: curl -sSL https://test.docker.com/ | sh" -echo "Linux 64bit binary: https://test.docker.com/builds/Linux/x86_64/docker-${VERSION#v}" -echo "Darwin/OSX 64bit client binary: https://test.docker.com/builds/Darwin/x86_64/docker-${VERSION#v}" -echo "Linux 64bit tgz: https://test.docker.com/builds/Linux/x86_64/docker-${VERSION#v}.tgz" -echo "Windows 64bit client binary: https://test.docker.com/builds/Windows/x86_64/docker-${VERSION#v}.exe" -echo "Windows 32bit client binary: https://test.docker.com/builds/Windows/i386/docker-${VERSION#v}.exe" -``` - -We recommend announcing the release candidate on: - -- IRC on #docker, #docker-dev, #docker-maintainers -- In a comment on the pull request to notify subscribed people on GitHub -- The [docker-dev](https://groups.google.com/forum/#!forum/docker-dev) group -- The [docker-maintainers](https://groups.google.com/a/dockerproject.org/forum/#!forum/maintainers) group -- Any social media that can bring some attention to the release candidate - -### 13. Iterate on successive release candidates - -Spend several days along with the community explicitly investing time and -resources to try and break Docker in every possible way, documenting any -findings pertinent to the release. This time should be spent testing and -finding ways in which the release might have caused various features or upgrade -environments to have issues, not coding. During this time, the release is in -code freeze, and any additional code changes will be pushed out to the next -release. - -It should include various levels of breaking Docker, beyond just using Docker -by the book. - -Any issues found may still remain issues for this release, but they should be -documented and give appropriate warnings. - -During this phase, the `bump_$VERSION` branch will keep evolving as you will -produce new release candidates. The frequency of new candidates is up to the -release manager: use your best judgement taking into account the severity of -reported issues, testers availability, and time to scheduled release date. - -Each time you'll want to produce a new release candidate, you will start by -adding commits to the branch, usually by cherry-picking from master: - -```bash -git cherry-pick -s -x -m0 -``` - -You want your "bump commit" (the one that updates the CHANGELOG and VERSION -files) to remain on top, so you'll have to `git rebase -i` to bring it back up. - -Now that your bump commit is back on top, you will need to update the CHANGELOG -file (if appropriate for this particular release candidate), and update the -VERSION file to increment the RC number: - -```bash -export RC_VERSION=$VERSION-rcN -echo $RC_VERSION > VERSION -``` - -You can now amend your last commit and update the bump branch: - -```bash -git commit --amend -git push -f $GITHUBUSER bump_$VERSION -``` - -Repeat step 6 to tag the code, publish new binaries, announce availability, and -get help testing. - -### 14. Finalize the bump branch - -When you're happy with the quality of a release candidate, you can move on and -create the real thing. - -You will first have to amend the "bump commit" to drop the release candidate -suffix in the VERSION file: - -```bash -echo $VERSION > VERSION -git add VERSION -git commit --amend -``` - -You will then repeat step 6 to publish the binaries to test - -### 15. Get 2 other maintainers to validate the pull request - -### 16. Build final rpms and debs - -```bash -docker build -t docker . -docker run \ - --rm -t --privileged \ - -v $(pwd)/bundles:/go/src/github.com/docker/docker/bundles \ - docker \ - hack/make.sh binary build-deb build-rpm -``` - -### 17. Publish final rpms and debs - -With the rpms and debs you built from the last step you can release them on the -same server, or ideally, move them to a dedicated release box via scp into -another docker/docker directory in bundles. This next step assumes you have -a checkout of the docker source code at the same commit you used to build, with -the artifacts from the last step in `bundles`. - -**NOTE:** If you put a space before the command your `.bash_history` will not -save it. (for the `GPG_PASSPHRASE`). - -```bash -docker build -t docker . -docker run --rm -it --privileged \ - -v /volumes/repos:/volumes/repos \ - -v $(pwd)/bundles:/go/src/github.com/docker/docker/bundles \ - -v $HOME/.gnupg:/root/.gnupg \ - -e DOCKER_RELEASE_DIR=/volumes/repos \ - -e GPG_PASSPHRASE \ - -e KEEPBUNDLE=1 \ - docker \ - hack/make.sh release-deb release-rpm sign-repos generate-index-listing -``` - -### 18. Upload the changed repos to wherever you host - -For example, above we bind mounted `/volumes/repos` as the storage for -`DOCKER_RELEASE_DIR`. In this case `/volumes/repos/apt` can be synced with -a specific s3 bucket for the apt repo and `/volumes/repos/yum` can be synced with -a s3 bucket for the yum repo. - -### 19. Publish final binaries - -Once they're tested and reasonably believed to be working, run against -get.docker.com: - -```bash -docker build -t docker . -# static binaries are still pushed to s3 -docker run \ - -e AWS_S3_BUCKET=get.docker.com \ - -e AWS_ACCESS_KEY_ID \ - -e AWS_SECRET_ACCESS_KEY \ - -e AWS_DEFAULT_REGION \ - -i -t --privileged \ - docker \ - hack/release.sh -``` - -### 20. Purge the cache! - -### 21. Apply tag and create release - -It's very important that we don't make the tag until after the official -release is uploaded to get.docker.com! - -```bash -git tag -a $VERSION -m $VERSION bump_$VERSION -git push origin $VERSION -``` - -Once the tag is pushed, go to GitHub and create a [new release](https://github.com/docker/docker/releases/new). -If the tag is for an RC make sure you check `This is a pre-release` at the bottom of the form. - -Select the tag that you just pushed as the version and paste the changelog in the description of the release. -You can see examples in this two links: - -https://github.com/docker/docker/releases/tag/v1.8.0 -https://github.com/docker/docker/releases/tag/v1.8.0-rc3 - -### 22. Go to github to merge the `bump_$VERSION` branch into release - -Don't forget to push that pretty blue button to delete the leftover -branch afterwards! - -### 23. Update the docs branch - -You will need to point the docs branch to the newly created release tag: - -```bash -git checkout origin/docs -git reset --hard origin/$VERSION -git push -f origin docs -``` - -The docs will appear on https://docs.docker.com/ (though there may be cached -versions, so its worth checking http://docs.docker.com.s3-website-us-east-1.amazonaws.com/). -For more information about documentation releases, see `docs/README.md`. - -Note that the new docs will not appear live on the site until the cache (a complex, -distributed CDN system) is flushed. The `make docs-release` command will do this -_if_ the `DISTRIBUTION_ID` is set correctly - this will take at least 15 minutes to run -and you can check its progress with the CDN Cloudfront Chrome addon. - -### 24. Create a new pull request to merge your bump commit back into master - -```bash -git checkout master -git fetch -git reset --hard origin/master -git cherry-pick -s -x $VERSION -git push $GITHUBUSER merge_release_$VERSION -echo "https://github.com/$GITHUBUSER/docker/compare/docker:master...$GITHUBUSER:merge_release_$VERSION?expand=1" -``` - -Again, get two maintainers to validate, then merge, then push that pretty -blue button to delete your branch. - -### 25. Rejoice and Evangelize! - -Congratulations! You're done. - -Go forth and announce the glad tidings of the new release in `#docker`, -`#docker-dev`, on the [dev mailing list](https://groups.google.com/forum/#!forum/docker-dev), -the [announce mailing list](https://groups.google.com/forum/#!forum/docker-announce), -and on Twitter! diff --git a/vendor/github.com/docker/docker/project/RELEASE-PROCESS.md b/vendor/github.com/docker/docker/project/RELEASE-PROCESS.md deleted file mode 100644 index d764e9d..0000000 --- a/vendor/github.com/docker/docker/project/RELEASE-PROCESS.md +++ /dev/null @@ -1,78 +0,0 @@ -# Docker Release Process - -This document describes how the Docker project is released. The Docker project -release process targets the Engine, Compose, Kitematic, Machine, Swarm, -Distribution, Notary and their underlying dependencies (libnetwork, libkv, -etc...). - -Step-by-step technical details of the process are described in -[RELEASE-CHECKLIST.md](https://github.com/docker/docker/blob/master/project/RELEASE-CHECKLIST.md). - -## Release cycle - -The Docker project follows a **time-based release cycle** and ships every nine -weeks. A release cycle starts the same day the previous release cycle ends. - -The first six weeks of the cycle are dedicated to development and review. During -this phase, new features and bugfixes submitted to any of the projects are -**eligible** to be shipped as part of the next release. No changeset submitted -during this period is however guaranteed to be merged for the current release -cycle. - -## The freeze period - -Six weeks after the beginning of the cycle, the codebase is officially frozen -and the codebase reaches a state close to the final release. A Release Candidate -(RC) gets created at the same time. The freeze period is used to find bugs and -get feedback on the state of the RC before the release. - -During this freeze period, while the `master` branch will continue its normal -development cycle, no new features are accepted into the RC. As bugs are fixed -in `master` the release owner will selectively 'cherry-pick' critical ones to -be included into the RC. As the RC changes, new ones are made available for the -community to test and review. - -This period lasts for three weeks. - -## How to maximize chances of being merged before the freeze date? - -First of all, there is never a guarantee that a specific changeset is going to -be merged. However there are different actions to follow to maximize the chances -for a changeset to be merged: - -- The team gives priority to review the PRs aligned with the Roadmap (usually -defined by a ROADMAP.md file at the root of the repository). -- The earlier a PR is opened, the more time the maintainers have to review. For -example, if a PR is opened the day before the freeze date, it’s very unlikely -that it will be merged for the release. -- Constant communication with the maintainers (mailing-list, IRC, Github issues, -etc.) allows to get early feedback on the design before getting into the -implementation, which usually reduces the time needed to discuss a changeset. -- If the code is commented, fully tested and by extension follows every single -rules defined by the [CONTRIBUTING guide]( -https://github.com/docker/docker/blob/master/CONTRIBUTING.md), this will help -the maintainers by speeding up the review. - -## The release - -At the end of the freeze (nine weeks after the start of the cycle), all the -projects are released together. - -``` - Codebase Release -Start of is frozen (end of the -the Cycle (7th week) 9th week) -+---------------------------------------+---------------------+ -| | | -| Development phase | Freeze phase | -| | | -+---------------------------------------+---------------------+ - 6 weeks 3 weeks -<---------------------------------------><--------------------> -``` - -## Exceptions - -If a critical issue is found at the end of the freeze period and more time is -needed to address it, the release will be pushed back. When a release gets -pushed back, the next release cycle gets delayed as well. diff --git a/vendor/github.com/docker/docker/project/REVIEWING.md b/vendor/github.com/docker/docker/project/REVIEWING.md deleted file mode 100644 index 51ef4c5..0000000 --- a/vendor/github.com/docker/docker/project/REVIEWING.md +++ /dev/null @@ -1,246 +0,0 @@ -# Pull request reviewing process - -## Labels - -Labels are carefully picked to optimize for: - - - Readability: maintainers must immediately know the state of a PR - - Filtering simplicity: different labels represent many different aspects of - the reviewing work, and can even be targeted at different maintainers groups. - -A pull request should only be attributed labels documented in this section: other labels that may -exist on the repository should apply to issues. - -### DCO labels - - * `dco/no`: automatically set by a bot when one of the commits lacks proper signature - -### Status labels - - * `status/0-triage` - * `status/1-design-review` - * `status/2-code-review` - * `status/3-docs-review` - * `status/4-ready-to-merge` - -Special status labels: - - * `status/failing-ci`: indicates that the PR in its current state fails the test suite - * `status/needs-attention`: calls for a collective discussion during a review session - -### Impact labels (apply to merged pull requests) - - * `impact/api` - * `impact/changelog` - * `impact/cli` - * `impact/deprecation` - * `impact/distribution` - * `impact/dockerfile` - -### Process labels (apply to merged pull requests) - -Process labels are to assist in preparing (patch) releases. These labels should only be used for pull requests. - -Label | Use for -------------------------------- | ------------------------------------------------------------------------- -`process/cherry-pick` | PRs that should be cherry-picked in the bump/release branch. These pull-requests must also be assigned to a milestone. -`process/cherry-picked` | PRs that have been cherry-picked. This label is helpful to find PR's that have been added to release-candidates, and to update the change log -`process/docs-cherry-pick` | PRs that should be cherry-picked in the docs branch. Only apply this label for changes that apply to the *current* release, and generic documentation fixes, such as Markdown and spelling fixes. -`process/docs-cherry-picked` | PRs that have been cherry-picked in the docs branch -`process/merge-to-master` | PRs that are opened directly on the bump/release branch, but also need to be merged back to "master" -`process/merged-to-master` | PRs that have been merged back to "master" - - -## Workflow - -An opened pull request can be in 1 of 5 distinct states, for each of which there is a corresponding -label that needs to be applied. - -### Triage - `status/0-triage` - -Maintainers are expected to triage new incoming pull requests by removing the `status/0-triage` -label and adding the correct labels (e.g. `status/1-design-review`) before any other interaction -with the PR. The starting label may potentially skip some steps depending on the kind of pull -request: use your best judgement. - -Maintainers should perform an initial, high-level, overview of the pull request before moving it to -the next appropriate stage: - - - Has DCO - - Contains sufficient justification (e.g., usecases) for the proposed change - - References the Github issue it fixes (if any) in the commit or the first Github comment - -Possible transitions from this state: - - * Close: e.g., unresponsive contributor without DCO - * `status/1-design-review`: general case - * `status/2-code-review`: e.g. trivial bugfix - * `status/3-docs-review`: non-proposal documentation-only change - -### Design review - `status/1-design-review` - -Maintainers are expected to comment on the design of the pull request. Review of documentation is -expected only in the context of design validation, not for stylistic changes. - -Ideally, documentation should reflect the expected behavior of the code. No code review should -take place in this step. - -There are no strict rules on the way a design is validated: we usually aim for a consensus, -although a single maintainer approval is often sufficient for obviously reasonable changes. In -general, strong disagreement expressed by any of the maintainers should not be taken lightly. - -Once design is approved, a maintainer should make sure to remove this label and add the next one. - -Possible transitions from this state: - - * Close: design rejected - * `status/2-code-review`: general case - * `status/3-docs-review`: proposals with only documentation changes - -### Code review - `status/2-code-review` - -Maintainers are expected to review the code and ensure that it is good quality and in accordance -with the documentation in the PR. - -New testcases are expected to be added. Ideally, those testcases should fail when the new code is -absent, and pass when present. The testcases should strive to test as many variants, code paths, as -possible to ensure maximum coverage. - -Changes to code must be reviewed and approved (LGTM'd) by a minimum of two code maintainers. When -the author of a PR is a maintainer, he still needs the approval of two other maintainers. - -Once code is approved according to the rules of the subsystem, a maintainer should make sure to -remove this label and add the next one. If documentation is absent but expected, maintainers should -ask for documentation and move to status `status/3-docs-review` for docs maintainer to follow. - -Possible transitions from this state: - - * Close - * `status/1-design-review`: new design concerns are raised - * `status/3-docs-review`: general case - * `status/4-ready-to-merge`: change not impacting documentation - -### Docs review - `status/3-docs-review` - -Maintainers are expected to review the documentation in its bigger context, ensuring consistency, -completeness, validity, and breadth of coverage across all existing and new documentation. - -They should ask for any editorial change that makes the documentation more consistent and easier to -understand. - -The docker/docker repository only contains _reference documentation_, all -"narrative" documentation is kept in a [unified documentation -repository](https://github.com/docker/docker.github.io). Reviewers must -therefore verify which parts of the documentation need to be updated. Any -contribution that may require changing the narrative should get the -`impact/documentation` label: this is the signal for documentation maintainers -that a change will likely need to happen on the unified documentation -repository. When in doubt, it’s better to add the label and leave it to -documentation maintainers to decide whether it’s ok to skip. In all cases, -leave a comment to explain what documentation changes you think might be needed. - -- If the pull request does not impact the documentation at all, the docs review - step is skipped, and the pull request is ready to merge. -- If the changes in - the pull request require changes to the reference documentation (either - command-line reference, or API reference), those changes must be included as - part of the pull request and will be reviewed now. Keep in mind that the - narrative documentation may contain output examples of commands, so may need - to be updated as well, in which case the `impact/documentation` label must - be applied. -- If the PR has the `impact/documentation` label, merging is delayed until a - documentation maintainer acknowledges that a corresponding documentation PR - (or issue) is opened on the documentation repository. Once a documentation - maintainer acknowledges the change, she/he will move the PR to `status/4-merge` - for a code maintainer to push the green button. - -Changes and additions to docs must be reviewed and approved (LGTM'd) by a minimum of two docs -sub-project maintainers. If the docs change originates with a docs maintainer, only one additional -LGTM is required (since we assume a docs maintainer approves of their own PR). - -Once documentation is approved, a maintainer should make sure to remove this label and -add the next one. - -Possible transitions from this state: - - * Close - * `status/1-design-review`: new design concerns are raised - * `status/2-code-review`: requires more code changes - * `status/4-ready-to-merge`: general case - -### Merge - `status/4-ready-to-merge` - -Maintainers are expected to merge this pull request as soon as possible. They can ask for a rebase -or carry the pull request themselves. - -Possible transitions from this state: - - * Merge: general case - * Close: carry PR - -After merging a pull request, the maintainer should consider applying one or multiple impact labels -to ease future classification: - - * `impact/api` signifies the patch impacted the Engine API - * `impact/changelog` signifies the change is significant enough to make it in the changelog - * `impact/cli` signifies the patch impacted a CLI command - * `impact/dockerfile` signifies the patch impacted the Dockerfile syntax - * `impact/deprecation` signifies the patch participates in deprecating an existing feature - -### Close - -If a pull request is closed it is expected that sufficient justification will be provided. In -particular, if there are alternative ways of achieving the same net result then those needs to be -spelled out. If the pull request is trying to solve a use case that is not one that we (as a -community) want to support then a justification for why should be provided. - -The number of maintainers it takes to decide and close a PR is deliberately left unspecified. We -assume that the group of maintainers is bound by mutual trust and respect, and that opposition from -any single maintainer should be taken into consideration. Similarly, we expect maintainers to -justify their reasoning and to accept debating. - -## Escalation process - -Despite the previously described reviewing process, some PR might not show any progress for various -reasons: - - - No strong opinion for or against the proposed patch - - Debates about the proper way to solve the problem at hand - - Lack of consensus - - ... - -All these will eventually lead to stalled PR, where no apparent progress is made across several -weeks, or even months. - -Maintainers should use their best judgement and apply the `status/needs-attention` label. It must -be used sparingly, as each PR with such label will be discussed by a group of maintainers during a -review session. The goal of that session is to agree on one of the following outcomes for the PR: - - * Close, explaining the rationale for not pursuing further - * Continue, either by pushing the PR further in the workflow, or by deciding to carry the patch - (ideally, a maintainer should be immediately assigned to make sure that the PR keeps continued - attention) - * Escalate to Solomon by formulating a few specific questions on which his answers will allow - maintainers to decide. - -## Milestones - -Typically, every merged pull request get shipped naturally with the next release cut from the -`master` branch (either the next minor or major version, as indicated by the -[`VERSION`](https://github.com/docker/docker/blob/master/VERSION) file at the root of the -repository). However, the time-based nature of the release process provides no guarantee that a -given pull request will get merged in time. In other words, all open pull requests are implicitly -considered part of the next minor or major release milestone, and this won't be materialized on -GitHub. - -A merged pull request must be attached to the milestone corresponding to the release in which it -will be shipped: this is both useful for tracking, and to help the release manager with the -changelog generation. - -An open pull request may exceptionally get attached to a milestone to express a particular intent to -get it merged in time for that release. This may for example be the case for an important feature to -be included in a minor release, or a critical bugfix to be included in a patch release. - -Finally, and as documented by the [`PATCH-RELEASES.md`](PATCH-RELEASES.md) process, the existence of -a milestone is not a guarantee that a release will happen, as some milestones will be created purely -for the purpose of bookkeeping diff --git a/vendor/github.com/docker/docker/project/TOOLS.md b/vendor/github.com/docker/docker/project/TOOLS.md deleted file mode 100644 index 26303c3..0000000 --- a/vendor/github.com/docker/docker/project/TOOLS.md +++ /dev/null @@ -1,63 +0,0 @@ -# Tools - -This page describes the tools we use and infrastructure that is in place for -the Docker project. - -### CI - -The Docker project uses [Jenkins](https://jenkins.dockerproject.org/) as our -continuous integration server. Each Pull Request to Docker is tested by running the -equivalent of `make all`. We chose Jenkins because we can host it ourselves and -we run Docker in Docker to test. - -#### Leeroy - -Leeroy is a Go application which integrates Jenkins with -GitHub pull requests. Leeroy uses -[GitHub hooks](https://developer.github.com/v3/repos/hooks/) -to listen for pull request notifications and starts jobs on your Jenkins -server. Using the Jenkins -[notification plugin][https://wiki.jenkins-ci.org/display/JENKINS/Notification+Plugin], -Leeroy updates the pull request using GitHub's -[status API](https://developer.github.com/v3/repos/statuses/) -with pending, success, failure, or error statuses. - -The leeroy repository is maintained at -[github.com/docker/leeroy](https://github.com/docker/leeroy). - -#### GordonTheTurtle IRC Bot - -The GordonTheTurtle IRC Bot lives in the -[#docker-maintainers](https://botbot.me/freenode/docker-maintainers/) channel -on Freenode. He is built in Go and is based off the project at -[github.com/fabioxgn/go-bot](https://github.com/fabioxgn/go-bot). - -His main command is `!rebuild`, which rebuilds a given Pull Request for a repository. -This command works by integrating with Leroy. He has a few other commands too, such -as `!gif` or `!godoc`, but we are always looking for more fun commands to add. - -The gordon-bot repository is maintained at -[github.com/docker/gordon-bot](https://github.com/docker/gordon-bot) - -### NSQ - -We use [NSQ](https://github.com/bitly/nsq) for various aspects of the project -infrastructure. - -#### Hooks - -The hooks project, -[github.com/crosbymichael/hooks](https://github.com/crosbymichael/hooks), -is a small Go application that manages web hooks from github, hub.docker.com, or -other third party services. - -It can be used for listening to github webhooks & pushing them to a queue, -archiving hooks to rethinkdb for processing, and broadcasting hooks to various -jobs. - -#### Docker Master Binaries - -One of the things queued from the Hooks are the building of the Master -Binaries. This happens on every push to the master branch of Docker. The -repository for this is maintained at -[github.com/docker/docker-bb](https://github.com/docker/docker-bb). diff --git a/vendor/github.com/docker/docker/reference/reference.go b/vendor/github.com/docker/docker/reference/reference.go deleted file mode 100644 index 996fc50..0000000 --- a/vendor/github.com/docker/docker/reference/reference.go +++ /dev/null @@ -1,216 +0,0 @@ -package reference - -import ( - "errors" - "fmt" - "strings" - - "github.com/docker/distribution/digest" - distreference "github.com/docker/distribution/reference" - "github.com/docker/docker/image/v1" -) - -const ( - // DefaultTag defines the default tag used when performing images related actions and no tag or digest is specified - DefaultTag = "latest" - // DefaultHostname is the default built-in hostname - DefaultHostname = "docker.io" - // LegacyDefaultHostname is automatically converted to DefaultHostname - LegacyDefaultHostname = "index.docker.io" - // DefaultRepoPrefix is the prefix used for default repositories in default host - DefaultRepoPrefix = "library/" -) - -// Named is an object with a full name -type Named interface { - // Name returns normalized repository name, like "ubuntu". - Name() string - // String returns full reference, like "ubuntu@sha256:abcdef..." - String() string - // FullName returns full repository name with hostname, like "docker.io/library/ubuntu" - FullName() string - // Hostname returns hostname for the reference, like "docker.io" - Hostname() string - // RemoteName returns the repository component of the full name, like "library/ubuntu" - RemoteName() string -} - -// NamedTagged is an object including a name and tag. -type NamedTagged interface { - Named - Tag() string -} - -// Canonical reference is an object with a fully unique -// name including a name with hostname and digest -type Canonical interface { - Named - Digest() digest.Digest -} - -// ParseNamed parses s and returns a syntactically valid reference implementing -// the Named interface. The reference must have a name, otherwise an error is -// returned. -// If an error was encountered it is returned, along with a nil Reference. -func ParseNamed(s string) (Named, error) { - named, err := distreference.ParseNamed(s) - if err != nil { - return nil, fmt.Errorf("Error parsing reference: %q is not a valid repository/tag: %s", s, err) - } - r, err := WithName(named.Name()) - if err != nil { - return nil, err - } - if canonical, isCanonical := named.(distreference.Canonical); isCanonical { - return WithDigest(r, canonical.Digest()) - } - if tagged, isTagged := named.(distreference.NamedTagged); isTagged { - return WithTag(r, tagged.Tag()) - } - return r, nil -} - -// TrimNamed removes any tag or digest from the named reference -func TrimNamed(ref Named) Named { - return &namedRef{distreference.TrimNamed(ref)} -} - -// WithName returns a named object representing the given string. If the input -// is invalid ErrReferenceInvalidFormat will be returned. -func WithName(name string) (Named, error) { - name, err := normalize(name) - if err != nil { - return nil, err - } - if err := validateName(name); err != nil { - return nil, err - } - r, err := distreference.WithName(name) - if err != nil { - return nil, err - } - return &namedRef{r}, nil -} - -// WithTag combines the name from "name" and the tag from "tag" to form a -// reference incorporating both the name and the tag. -func WithTag(name Named, tag string) (NamedTagged, error) { - r, err := distreference.WithTag(name, tag) - if err != nil { - return nil, err - } - return &taggedRef{namedRef{r}}, nil -} - -// WithDigest combines the name from "name" and the digest from "digest" to form -// a reference incorporating both the name and the digest. -func WithDigest(name Named, digest digest.Digest) (Canonical, error) { - r, err := distreference.WithDigest(name, digest) - if err != nil { - return nil, err - } - return &canonicalRef{namedRef{r}}, nil -} - -type namedRef struct { - distreference.Named -} -type taggedRef struct { - namedRef -} -type canonicalRef struct { - namedRef -} - -func (r *namedRef) FullName() string { - hostname, remoteName := splitHostname(r.Name()) - return hostname + "/" + remoteName -} -func (r *namedRef) Hostname() string { - hostname, _ := splitHostname(r.Name()) - return hostname -} -func (r *namedRef) RemoteName() string { - _, remoteName := splitHostname(r.Name()) - return remoteName -} -func (r *taggedRef) Tag() string { - return r.namedRef.Named.(distreference.NamedTagged).Tag() -} -func (r *canonicalRef) Digest() digest.Digest { - return r.namedRef.Named.(distreference.Canonical).Digest() -} - -// WithDefaultTag adds a default tag to a reference if it only has a repo name. -func WithDefaultTag(ref Named) Named { - if IsNameOnly(ref) { - ref, _ = WithTag(ref, DefaultTag) - } - return ref -} - -// IsNameOnly returns true if reference only contains a repo name. -func IsNameOnly(ref Named) bool { - if _, ok := ref.(NamedTagged); ok { - return false - } - if _, ok := ref.(Canonical); ok { - return false - } - return true -} - -// ParseIDOrReference parses string for an image ID or a reference. ID can be -// without a default prefix. -func ParseIDOrReference(idOrRef string) (digest.Digest, Named, error) { - if err := v1.ValidateID(idOrRef); err == nil { - idOrRef = "sha256:" + idOrRef - } - if dgst, err := digest.ParseDigest(idOrRef); err == nil { - return dgst, nil, nil - } - ref, err := ParseNamed(idOrRef) - return "", ref, err -} - -// splitHostname splits a repository name to hostname and remotename string. -// If no valid hostname is found, the default hostname is used. Repository name -// needs to be already validated before. -func splitHostname(name string) (hostname, remoteName string) { - i := strings.IndexRune(name, '/') - if i == -1 || (!strings.ContainsAny(name[:i], ".:") && name[:i] != "localhost") { - hostname, remoteName = DefaultHostname, name - } else { - hostname, remoteName = name[:i], name[i+1:] - } - if hostname == LegacyDefaultHostname { - hostname = DefaultHostname - } - if hostname == DefaultHostname && !strings.ContainsRune(remoteName, '/') { - remoteName = DefaultRepoPrefix + remoteName - } - return -} - -// normalize returns a repository name in its normalized form, meaning it -// will not contain default hostname nor library/ prefix for official images. -func normalize(name string) (string, error) { - host, remoteName := splitHostname(name) - if strings.ToLower(remoteName) != remoteName { - return "", errors.New("invalid reference format: repository name must be lowercase") - } - if host == DefaultHostname { - if strings.HasPrefix(remoteName, DefaultRepoPrefix) { - return strings.TrimPrefix(remoteName, DefaultRepoPrefix), nil - } - return remoteName, nil - } - return name, nil -} - -func validateName(name string) error { - if err := v1.ValidateID(name); err == nil { - return fmt.Errorf("Invalid repository name (%s), cannot specify 64-byte hexadecimal strings", name) - } - return nil -} diff --git a/vendor/github.com/docker/docker/reference/reference_test.go b/vendor/github.com/docker/docker/reference/reference_test.go deleted file mode 100644 index ff35ba3..0000000 --- a/vendor/github.com/docker/docker/reference/reference_test.go +++ /dev/null @@ -1,275 +0,0 @@ -package reference - -import ( - "testing" - - "github.com/docker/distribution/digest" -) - -func TestValidateReferenceName(t *testing.T) { - validRepoNames := []string{ - "docker/docker", - "library/debian", - "debian", - "docker.io/docker/docker", - "docker.io/library/debian", - "docker.io/debian", - "index.docker.io/docker/docker", - "index.docker.io/library/debian", - "index.docker.io/debian", - "127.0.0.1:5000/docker/docker", - "127.0.0.1:5000/library/debian", - "127.0.0.1:5000/debian", - "thisisthesongthatneverendsitgoesonandonandonthisisthesongthatnev", - } - invalidRepoNames := []string{ - "https://github.com/docker/docker", - "docker/Docker", - "-docker", - "-docker/docker", - "-docker.io/docker/docker", - "docker///docker", - "docker.io/docker/Docker", - "docker.io/docker///docker", - "1a3f5e7d9c1b3a5f7e9d1c3b5a7f9e1d3c5b7a9f1e3d5d7c9b1a3f5e7d9c1b3a", - "docker.io/1a3f5e7d9c1b3a5f7e9d1c3b5a7f9e1d3c5b7a9f1e3d5d7c9b1a3f5e7d9c1b3a", - } - - for _, name := range invalidRepoNames { - _, err := ParseNamed(name) - if err == nil { - t.Fatalf("Expected invalid repo name for %q", name) - } - } - - for _, name := range validRepoNames { - _, err := ParseNamed(name) - if err != nil { - t.Fatalf("Error parsing repo name %s, got: %q", name, err) - } - } -} - -func TestValidateRemoteName(t *testing.T) { - validRepositoryNames := []string{ - // Sanity check. - "docker/docker", - - // Allow 64-character non-hexadecimal names (hexadecimal names are forbidden). - "thisisthesongthatneverendsitgoesonandonandonthisisthesongthatnev", - - // Allow embedded hyphens. - "docker-rules/docker", - - // Allow multiple hyphens as well. - "docker---rules/docker", - - //Username doc and image name docker being tested. - "doc/docker", - - // single character names are now allowed. - "d/docker", - "jess/t", - - // Consecutive underscores. - "dock__er/docker", - } - for _, repositoryName := range validRepositoryNames { - _, err := ParseNamed(repositoryName) - if err != nil { - t.Errorf("Repository name should be valid: %v. Error: %v", repositoryName, err) - } - } - - invalidRepositoryNames := []string{ - // Disallow capital letters. - "docker/Docker", - - // Only allow one slash. - "docker///docker", - - // Disallow 64-character hexadecimal. - "1a3f5e7d9c1b3a5f7e9d1c3b5a7f9e1d3c5b7a9f1e3d5d7c9b1a3f5e7d9c1b3a", - - // Disallow leading and trailing hyphens in namespace. - "-docker/docker", - "docker-/docker", - "-docker-/docker", - - // Don't allow underscores everywhere (as opposed to hyphens). - "____/____", - - "_docker/_docker", - - // Disallow consecutive periods. - "dock..er/docker", - "dock_.er/docker", - "dock-.er/docker", - - // No repository. - "docker/", - - //namespace too long - "this_is_not_a_valid_namespace_because_its_lenth_is_greater_than_255_this_is_not_a_valid_namespace_because_its_lenth_is_greater_than_255_this_is_not_a_valid_namespace_because_its_lenth_is_greater_than_255_this_is_not_a_valid_namespace_because_its_lenth_is_greater_than_255/docker", - } - for _, repositoryName := range invalidRepositoryNames { - if _, err := ParseNamed(repositoryName); err == nil { - t.Errorf("Repository name should be invalid: %v", repositoryName) - } - } -} - -func TestParseRepositoryInfo(t *testing.T) { - type tcase struct { - RemoteName, NormalizedName, FullName, AmbiguousName, Hostname string - } - - tcases := []tcase{ - { - RemoteName: "fooo/bar", - NormalizedName: "fooo/bar", - FullName: "docker.io/fooo/bar", - AmbiguousName: "index.docker.io/fooo/bar", - Hostname: "docker.io", - }, - { - RemoteName: "library/ubuntu", - NormalizedName: "ubuntu", - FullName: "docker.io/library/ubuntu", - AmbiguousName: "library/ubuntu", - Hostname: "docker.io", - }, - { - RemoteName: "nonlibrary/ubuntu", - NormalizedName: "nonlibrary/ubuntu", - FullName: "docker.io/nonlibrary/ubuntu", - AmbiguousName: "", - Hostname: "docker.io", - }, - { - RemoteName: "other/library", - NormalizedName: "other/library", - FullName: "docker.io/other/library", - AmbiguousName: "", - Hostname: "docker.io", - }, - { - RemoteName: "private/moonbase", - NormalizedName: "127.0.0.1:8000/private/moonbase", - FullName: "127.0.0.1:8000/private/moonbase", - AmbiguousName: "", - Hostname: "127.0.0.1:8000", - }, - { - RemoteName: "privatebase", - NormalizedName: "127.0.0.1:8000/privatebase", - FullName: "127.0.0.1:8000/privatebase", - AmbiguousName: "", - Hostname: "127.0.0.1:8000", - }, - { - RemoteName: "private/moonbase", - NormalizedName: "example.com/private/moonbase", - FullName: "example.com/private/moonbase", - AmbiguousName: "", - Hostname: "example.com", - }, - { - RemoteName: "privatebase", - NormalizedName: "example.com/privatebase", - FullName: "example.com/privatebase", - AmbiguousName: "", - Hostname: "example.com", - }, - { - RemoteName: "private/moonbase", - NormalizedName: "example.com:8000/private/moonbase", - FullName: "example.com:8000/private/moonbase", - AmbiguousName: "", - Hostname: "example.com:8000", - }, - { - RemoteName: "privatebasee", - NormalizedName: "example.com:8000/privatebasee", - FullName: "example.com:8000/privatebasee", - AmbiguousName: "", - Hostname: "example.com:8000", - }, - { - RemoteName: "library/ubuntu-12.04-base", - NormalizedName: "ubuntu-12.04-base", - FullName: "docker.io/library/ubuntu-12.04-base", - AmbiguousName: "index.docker.io/library/ubuntu-12.04-base", - Hostname: "docker.io", - }, - } - - for _, tcase := range tcases { - refStrings := []string{tcase.NormalizedName, tcase.FullName} - if tcase.AmbiguousName != "" { - refStrings = append(refStrings, tcase.AmbiguousName) - } - - var refs []Named - for _, r := range refStrings { - named, err := ParseNamed(r) - if err != nil { - t.Fatal(err) - } - refs = append(refs, named) - named, err = WithName(r) - if err != nil { - t.Fatal(err) - } - refs = append(refs, named) - } - - for _, r := range refs { - if expected, actual := tcase.NormalizedName, r.Name(); expected != actual { - t.Fatalf("Invalid normalized reference for %q. Expected %q, got %q", r, expected, actual) - } - if expected, actual := tcase.FullName, r.FullName(); expected != actual { - t.Fatalf("Invalid normalized reference for %q. Expected %q, got %q", r, expected, actual) - } - if expected, actual := tcase.Hostname, r.Hostname(); expected != actual { - t.Fatalf("Invalid hostname for %q. Expected %q, got %q", r, expected, actual) - } - if expected, actual := tcase.RemoteName, r.RemoteName(); expected != actual { - t.Fatalf("Invalid remoteName for %q. Expected %q, got %q", r, expected, actual) - } - - } - } -} - -func TestParseReferenceWithTagAndDigest(t *testing.T) { - ref, err := ParseNamed("busybox:latest@sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa") - if err != nil { - t.Fatal(err) - } - if _, isTagged := ref.(NamedTagged); isTagged { - t.Fatalf("Reference from %q should not support tag", ref) - } - if _, isCanonical := ref.(Canonical); !isCanonical { - t.Fatalf("Reference from %q should not support digest", ref) - } - if expected, actual := "busybox@sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa", ref.String(); actual != expected { - t.Fatalf("Invalid parsed reference for %q: expected %q, got %q", ref, expected, actual) - } -} - -func TestInvalidReferenceComponents(t *testing.T) { - if _, err := WithName("-foo"); err == nil { - t.Fatal("Expected WithName to detect invalid name") - } - ref, err := WithName("busybox") - if err != nil { - t.Fatal(err) - } - if _, err := WithTag(ref, "-foo"); err == nil { - t.Fatal("Expected WithName to detect invalid tag") - } - if _, err := WithDigest(ref, digest.Digest("foo")); err == nil { - t.Fatal("Expected WithName to detect invalid digest") - } -} diff --git a/vendor/github.com/docker/docker/reference/store.go b/vendor/github.com/docker/docker/reference/store.go deleted file mode 100644 index 71ca236..0000000 --- a/vendor/github.com/docker/docker/reference/store.go +++ /dev/null @@ -1,286 +0,0 @@ -package reference - -import ( - "encoding/json" - "errors" - "fmt" - "os" - "path/filepath" - "sort" - "sync" - - "github.com/docker/distribution/digest" - "github.com/docker/docker/pkg/ioutils" -) - -var ( - // ErrDoesNotExist is returned if a reference is not found in the - // store. - ErrDoesNotExist = errors.New("reference does not exist") -) - -// An Association is a tuple associating a reference with an image ID. -type Association struct { - Ref Named - ID digest.Digest -} - -// Store provides the set of methods which can operate on a tag store. -type Store interface { - References(id digest.Digest) []Named - ReferencesByName(ref Named) []Association - AddTag(ref Named, id digest.Digest, force bool) error - AddDigest(ref Canonical, id digest.Digest, force bool) error - Delete(ref Named) (bool, error) - Get(ref Named) (digest.Digest, error) -} - -type store struct { - mu sync.RWMutex - // jsonPath is the path to the file where the serialized tag data is - // stored. - jsonPath string - // Repositories is a map of repositories, indexed by name. - Repositories map[string]repository - // referencesByIDCache is a cache of references indexed by ID, to speed - // up References. - referencesByIDCache map[digest.Digest]map[string]Named -} - -// Repository maps tags to digests. The key is a stringified Reference, -// including the repository name. -type repository map[string]digest.Digest - -type lexicalRefs []Named - -func (a lexicalRefs) Len() int { return len(a) } -func (a lexicalRefs) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a lexicalRefs) Less(i, j int) bool { return a[i].String() < a[j].String() } - -type lexicalAssociations []Association - -func (a lexicalAssociations) Len() int { return len(a) } -func (a lexicalAssociations) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (a lexicalAssociations) Less(i, j int) bool { return a[i].Ref.String() < a[j].Ref.String() } - -// NewReferenceStore creates a new reference store, tied to a file path where -// the set of references are serialized in JSON format. -func NewReferenceStore(jsonPath string) (Store, error) { - abspath, err := filepath.Abs(jsonPath) - if err != nil { - return nil, err - } - - store := &store{ - jsonPath: abspath, - Repositories: make(map[string]repository), - referencesByIDCache: make(map[digest.Digest]map[string]Named), - } - // Load the json file if it exists, otherwise create it. - if err := store.reload(); os.IsNotExist(err) { - if err := store.save(); err != nil { - return nil, err - } - } else if err != nil { - return nil, err - } - return store, nil -} - -// AddTag adds a tag reference to the store. If force is set to true, existing -// references can be overwritten. This only works for tags, not digests. -func (store *store) AddTag(ref Named, id digest.Digest, force bool) error { - if _, isCanonical := ref.(Canonical); isCanonical { - return errors.New("refusing to create a tag with a digest reference") - } - return store.addReference(WithDefaultTag(ref), id, force) -} - -// AddDigest adds a digest reference to the store. -func (store *store) AddDigest(ref Canonical, id digest.Digest, force bool) error { - return store.addReference(ref, id, force) -} - -func (store *store) addReference(ref Named, id digest.Digest, force bool) error { - if ref.Name() == string(digest.Canonical) { - return errors.New("refusing to create an ambiguous tag using digest algorithm as name") - } - - store.mu.Lock() - defer store.mu.Unlock() - - repository, exists := store.Repositories[ref.Name()] - if !exists || repository == nil { - repository = make(map[string]digest.Digest) - store.Repositories[ref.Name()] = repository - } - - refStr := ref.String() - oldID, exists := repository[refStr] - - if exists { - // force only works for tags - if digested, isDigest := ref.(Canonical); isDigest { - return fmt.Errorf("Cannot overwrite digest %s", digested.Digest().String()) - } - - if !force { - return fmt.Errorf("Conflict: Tag %s is already set to image %s, if you want to replace it, please use -f option", ref.String(), oldID.String()) - } - - if store.referencesByIDCache[oldID] != nil { - delete(store.referencesByIDCache[oldID], refStr) - if len(store.referencesByIDCache[oldID]) == 0 { - delete(store.referencesByIDCache, oldID) - } - } - } - - repository[refStr] = id - if store.referencesByIDCache[id] == nil { - store.referencesByIDCache[id] = make(map[string]Named) - } - store.referencesByIDCache[id][refStr] = ref - - return store.save() -} - -// Delete deletes a reference from the store. It returns true if a deletion -// happened, or false otherwise. -func (store *store) Delete(ref Named) (bool, error) { - ref = WithDefaultTag(ref) - - store.mu.Lock() - defer store.mu.Unlock() - - repoName := ref.Name() - - repository, exists := store.Repositories[repoName] - if !exists { - return false, ErrDoesNotExist - } - - refStr := ref.String() - if id, exists := repository[refStr]; exists { - delete(repository, refStr) - if len(repository) == 0 { - delete(store.Repositories, repoName) - } - if store.referencesByIDCache[id] != nil { - delete(store.referencesByIDCache[id], refStr) - if len(store.referencesByIDCache[id]) == 0 { - delete(store.referencesByIDCache, id) - } - } - return true, store.save() - } - - return false, ErrDoesNotExist -} - -// Get retrieves an item from the store by reference -func (store *store) Get(ref Named) (digest.Digest, error) { - ref = WithDefaultTag(ref) - - store.mu.RLock() - defer store.mu.RUnlock() - - repository, exists := store.Repositories[ref.Name()] - if !exists || repository == nil { - return "", ErrDoesNotExist - } - - id, exists := repository[ref.String()] - if !exists { - return "", ErrDoesNotExist - } - - return id, nil -} - -// References returns a slice of references to the given ID. The slice -// will be nil if there are no references to this ID. -func (store *store) References(id digest.Digest) []Named { - store.mu.RLock() - defer store.mu.RUnlock() - - // Convert the internal map to an array for two reasons: - // 1) We must not return a mutable - // 2) It would be ugly to expose the extraneous map keys to callers. - - var references []Named - for _, ref := range store.referencesByIDCache[id] { - references = append(references, ref) - } - - sort.Sort(lexicalRefs(references)) - - return references -} - -// ReferencesByName returns the references for a given repository name. -// If there are no references known for this repository name, -// ReferencesByName returns nil. -func (store *store) ReferencesByName(ref Named) []Association { - store.mu.RLock() - defer store.mu.RUnlock() - - repository, exists := store.Repositories[ref.Name()] - if !exists { - return nil - } - - var associations []Association - for refStr, refID := range repository { - ref, err := ParseNamed(refStr) - if err != nil { - // Should never happen - return nil - } - associations = append(associations, - Association{ - Ref: ref, - ID: refID, - }) - } - - sort.Sort(lexicalAssociations(associations)) - - return associations -} - -func (store *store) save() error { - // Store the json - jsonData, err := json.Marshal(store) - if err != nil { - return err - } - return ioutils.AtomicWriteFile(store.jsonPath, jsonData, 0600) -} - -func (store *store) reload() error { - f, err := os.Open(store.jsonPath) - if err != nil { - return err - } - defer f.Close() - if err := json.NewDecoder(f).Decode(&store); err != nil { - return err - } - - for _, repository := range store.Repositories { - for refStr, refID := range repository { - ref, err := ParseNamed(refStr) - if err != nil { - // Should never happen - continue - } - if store.referencesByIDCache[refID] == nil { - store.referencesByIDCache[refID] = make(map[string]Named) - } - store.referencesByIDCache[refID][refStr] = ref - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/reference/store_test.go b/vendor/github.com/docker/docker/reference/store_test.go deleted file mode 100644 index dd1d253..0000000 --- a/vendor/github.com/docker/docker/reference/store_test.go +++ /dev/null @@ -1,356 +0,0 @@ -package reference - -import ( - "bytes" - "io/ioutil" - "os" - "path/filepath" - "strings" - "testing" - - "github.com/docker/distribution/digest" -) - -var ( - saveLoadTestCases = map[string]digest.Digest{ - "registry:5000/foobar:HEAD": "sha256:470022b8af682154f57a2163d030eb369549549cba00edc69e1b99b46bb924d6", - "registry:5000/foobar:alternate": "sha256:ae300ebc4a4f00693702cfb0a5e0b7bc527b353828dc86ad09fb95c8a681b793", - "registry:5000/foobar:latest": "sha256:6153498b9ac00968d71b66cca4eac37e990b5f9eb50c26877eb8799c8847451b", - "registry:5000/foobar:master": "sha256:6c9917af4c4e05001b346421959d7ea81b6dc9d25718466a37a6add865dfd7fc", - "jess/hollywood:latest": "sha256:ae7a5519a0a55a2d4ef20ddcbd5d0ca0888a1f7ab806acc8e2a27baf46f529fe", - "registry@sha256:367eb40fd0330a7e464777121e39d2f5b3e8e23a1e159342e53ab05c9e4d94e6": "sha256:24126a56805beb9711be5f4590cc2eb55ab8d4a85ebd618eed72bb19fc50631c", - "busybox:latest": "sha256:91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", - } - - marshalledSaveLoadTestCases = []byte(`{"Repositories":{"busybox":{"busybox:latest":"sha256:91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c"},"jess/hollywood":{"jess/hollywood:latest":"sha256:ae7a5519a0a55a2d4ef20ddcbd5d0ca0888a1f7ab806acc8e2a27baf46f529fe"},"registry":{"registry@sha256:367eb40fd0330a7e464777121e39d2f5b3e8e23a1e159342e53ab05c9e4d94e6":"sha256:24126a56805beb9711be5f4590cc2eb55ab8d4a85ebd618eed72bb19fc50631c"},"registry:5000/foobar":{"registry:5000/foobar:HEAD":"sha256:470022b8af682154f57a2163d030eb369549549cba00edc69e1b99b46bb924d6","registry:5000/foobar:alternate":"sha256:ae300ebc4a4f00693702cfb0a5e0b7bc527b353828dc86ad09fb95c8a681b793","registry:5000/foobar:latest":"sha256:6153498b9ac00968d71b66cca4eac37e990b5f9eb50c26877eb8799c8847451b","registry:5000/foobar:master":"sha256:6c9917af4c4e05001b346421959d7ea81b6dc9d25718466a37a6add865dfd7fc"}}}`) -) - -func TestLoad(t *testing.T) { - jsonFile, err := ioutil.TempFile("", "tag-store-test") - if err != nil { - t.Fatalf("error creating temp file: %v", err) - } - defer os.RemoveAll(jsonFile.Name()) - - // Write canned json to the temp file - _, err = jsonFile.Write(marshalledSaveLoadTestCases) - if err != nil { - t.Fatalf("error writing to temp file: %v", err) - } - jsonFile.Close() - - store, err := NewReferenceStore(jsonFile.Name()) - if err != nil { - t.Fatalf("error creating tag store: %v", err) - } - - for refStr, expectedID := range saveLoadTestCases { - ref, err := ParseNamed(refStr) - if err != nil { - t.Fatalf("failed to parse reference: %v", err) - } - id, err := store.Get(ref) - if err != nil { - t.Fatalf("could not find reference %s: %v", refStr, err) - } - if id != expectedID { - t.Fatalf("expected %s - got %s", expectedID, id) - } - } -} - -func TestSave(t *testing.T) { - jsonFile, err := ioutil.TempFile("", "tag-store-test") - if err != nil { - t.Fatalf("error creating temp file: %v", err) - } - _, err = jsonFile.Write([]byte(`{}`)) - jsonFile.Close() - defer os.RemoveAll(jsonFile.Name()) - - store, err := NewReferenceStore(jsonFile.Name()) - if err != nil { - t.Fatalf("error creating tag store: %v", err) - } - - for refStr, id := range saveLoadTestCases { - ref, err := ParseNamed(refStr) - if err != nil { - t.Fatalf("failed to parse reference: %v", err) - } - if canonical, ok := ref.(Canonical); ok { - err = store.AddDigest(canonical, id, false) - if err != nil { - t.Fatalf("could not add digest reference %s: %v", refStr, err) - } - } else { - err = store.AddTag(ref, id, false) - if err != nil { - t.Fatalf("could not add reference %s: %v", refStr, err) - } - } - } - - jsonBytes, err := ioutil.ReadFile(jsonFile.Name()) - if err != nil { - t.Fatalf("could not read json file: %v", err) - } - - if !bytes.Equal(jsonBytes, marshalledSaveLoadTestCases) { - t.Fatalf("save output did not match expectations\nexpected:\n%s\ngot:\n%s", marshalledSaveLoadTestCases, jsonBytes) - } -} - -func TestAddDeleteGet(t *testing.T) { - jsonFile, err := ioutil.TempFile("", "tag-store-test") - if err != nil { - t.Fatalf("error creating temp file: %v", err) - } - _, err = jsonFile.Write([]byte(`{}`)) - jsonFile.Close() - defer os.RemoveAll(jsonFile.Name()) - - store, err := NewReferenceStore(jsonFile.Name()) - if err != nil { - t.Fatalf("error creating tag store: %v", err) - } - - testImageID1 := digest.Digest("sha256:9655aef5fd742a1b4e1b7b163aa9f1c76c186304bf39102283d80927c916ca9c") - testImageID2 := digest.Digest("sha256:9655aef5fd742a1b4e1b7b163aa9f1c76c186304bf39102283d80927c916ca9d") - testImageID3 := digest.Digest("sha256:9655aef5fd742a1b4e1b7b163aa9f1c76c186304bf39102283d80927c916ca9e") - - // Try adding a reference with no tag or digest - nameOnly, err := WithName("username/repo") - if err != nil { - t.Fatalf("could not parse reference: %v", err) - } - if err = store.AddTag(nameOnly, testImageID1, false); err != nil { - t.Fatalf("error adding to store: %v", err) - } - - // Add a few references - ref1, err := ParseNamed("username/repo1:latest") - if err != nil { - t.Fatalf("could not parse reference: %v", err) - } - if err = store.AddTag(ref1, testImageID1, false); err != nil { - t.Fatalf("error adding to store: %v", err) - } - - ref2, err := ParseNamed("username/repo1:old") - if err != nil { - t.Fatalf("could not parse reference: %v", err) - } - if err = store.AddTag(ref2, testImageID2, false); err != nil { - t.Fatalf("error adding to store: %v", err) - } - - ref3, err := ParseNamed("username/repo1:alias") - if err != nil { - t.Fatalf("could not parse reference: %v", err) - } - if err = store.AddTag(ref3, testImageID1, false); err != nil { - t.Fatalf("error adding to store: %v", err) - } - - ref4, err := ParseNamed("username/repo2:latest") - if err != nil { - t.Fatalf("could not parse reference: %v", err) - } - if err = store.AddTag(ref4, testImageID2, false); err != nil { - t.Fatalf("error adding to store: %v", err) - } - - ref5, err := ParseNamed("username/repo3@sha256:58153dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c") - if err != nil { - t.Fatalf("could not parse reference: %v", err) - } - if err = store.AddDigest(ref5.(Canonical), testImageID2, false); err != nil { - t.Fatalf("error adding to store: %v", err) - } - - // Attempt to overwrite with force == false - if err = store.AddTag(ref4, testImageID3, false); err == nil || !strings.HasPrefix(err.Error(), "Conflict:") { - t.Fatalf("did not get expected error on overwrite attempt - got %v", err) - } - // Repeat to overwrite with force == true - if err = store.AddTag(ref4, testImageID3, true); err != nil { - t.Fatalf("failed to force tag overwrite: %v", err) - } - - // Check references so far - id, err := store.Get(nameOnly) - if err != nil { - t.Fatalf("Get returned error: %v", err) - } - if id != testImageID1 { - t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID1.String()) - } - - id, err = store.Get(ref1) - if err != nil { - t.Fatalf("Get returned error: %v", err) - } - if id != testImageID1 { - t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID1.String()) - } - - id, err = store.Get(ref2) - if err != nil { - t.Fatalf("Get returned error: %v", err) - } - if id != testImageID2 { - t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID2.String()) - } - - id, err = store.Get(ref3) - if err != nil { - t.Fatalf("Get returned error: %v", err) - } - if id != testImageID1 { - t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID1.String()) - } - - id, err = store.Get(ref4) - if err != nil { - t.Fatalf("Get returned error: %v", err) - } - if id != testImageID3 { - t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID3.String()) - } - - id, err = store.Get(ref5) - if err != nil { - t.Fatalf("Get returned error: %v", err) - } - if id != testImageID2 { - t.Fatalf("id mismatch: got %s instead of %s", id.String(), testImageID3.String()) - } - - // Get should return ErrDoesNotExist for a nonexistent repo - nonExistRepo, err := ParseNamed("username/nonexistrepo:latest") - if err != nil { - t.Fatalf("could not parse reference: %v", err) - } - if _, err = store.Get(nonExistRepo); err != ErrDoesNotExist { - t.Fatal("Expected ErrDoesNotExist from Get") - } - - // Get should return ErrDoesNotExist for a nonexistent tag - nonExistTag, err := ParseNamed("username/repo1:nonexist") - if err != nil { - t.Fatalf("could not parse reference: %v", err) - } - if _, err = store.Get(nonExistTag); err != ErrDoesNotExist { - t.Fatal("Expected ErrDoesNotExist from Get") - } - - // Check References - refs := store.References(testImageID1) - if len(refs) != 3 { - t.Fatal("unexpected number of references") - } - // Looking for the references in this order verifies that they are - // returned lexically sorted. - if refs[0].String() != ref3.String() { - t.Fatalf("unexpected reference: %v", refs[0].String()) - } - if refs[1].String() != ref1.String() { - t.Fatalf("unexpected reference: %v", refs[1].String()) - } - if refs[2].String() != nameOnly.String()+":latest" { - t.Fatalf("unexpected reference: %v", refs[2].String()) - } - - // Check ReferencesByName - repoName, err := WithName("username/repo1") - if err != nil { - t.Fatalf("could not parse reference: %v", err) - } - associations := store.ReferencesByName(repoName) - if len(associations) != 3 { - t.Fatal("unexpected number of associations") - } - // Looking for the associations in this order verifies that they are - // returned lexically sorted. - if associations[0].Ref.String() != ref3.String() { - t.Fatalf("unexpected reference: %v", associations[0].Ref.String()) - } - if associations[0].ID != testImageID1 { - t.Fatalf("unexpected reference: %v", associations[0].Ref.String()) - } - if associations[1].Ref.String() != ref1.String() { - t.Fatalf("unexpected reference: %v", associations[1].Ref.String()) - } - if associations[1].ID != testImageID1 { - t.Fatalf("unexpected reference: %v", associations[1].Ref.String()) - } - if associations[2].Ref.String() != ref2.String() { - t.Fatalf("unexpected reference: %v", associations[2].Ref.String()) - } - if associations[2].ID != testImageID2 { - t.Fatalf("unexpected reference: %v", associations[2].Ref.String()) - } - - // Delete should return ErrDoesNotExist for a nonexistent repo - if _, err = store.Delete(nonExistRepo); err != ErrDoesNotExist { - t.Fatal("Expected ErrDoesNotExist from Delete") - } - - // Delete should return ErrDoesNotExist for a nonexistent tag - if _, err = store.Delete(nonExistTag); err != ErrDoesNotExist { - t.Fatal("Expected ErrDoesNotExist from Delete") - } - - // Delete a few references - if deleted, err := store.Delete(ref1); err != nil || deleted != true { - t.Fatal("Delete failed") - } - if _, err := store.Get(ref1); err != ErrDoesNotExist { - t.Fatal("Expected ErrDoesNotExist from Get") - } - if deleted, err := store.Delete(ref5); err != nil || deleted != true { - t.Fatal("Delete failed") - } - if _, err := store.Get(ref5); err != ErrDoesNotExist { - t.Fatal("Expected ErrDoesNotExist from Get") - } - if deleted, err := store.Delete(nameOnly); err != nil || deleted != true { - t.Fatal("Delete failed") - } - if _, err := store.Get(nameOnly); err != ErrDoesNotExist { - t.Fatal("Expected ErrDoesNotExist from Get") - } -} - -func TestInvalidTags(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "tag-store-test") - defer os.RemoveAll(tmpDir) - - store, err := NewReferenceStore(filepath.Join(tmpDir, "repositories.json")) - if err != nil { - t.Fatalf("error creating tag store: %v", err) - } - id := digest.Digest("sha256:470022b8af682154f57a2163d030eb369549549cba00edc69e1b99b46bb924d6") - - // sha256 as repo name - ref, err := ParseNamed("sha256:abc") - if err != nil { - t.Fatal(err) - } - err = store.AddTag(ref, id, true) - if err == nil { - t.Fatalf("expected setting tag %q to fail", ref) - } - - // setting digest as a tag - ref, err = ParseNamed("registry@sha256:367eb40fd0330a7e464777121e39d2f5b3e8e23a1e159342e53ab05c9e4d94e6") - if err != nil { - t.Fatal(err) - } - err = store.AddTag(ref, id, true) - if err == nil { - t.Fatalf("expected setting digest %q to fail", ref) - } - -} diff --git a/vendor/github.com/docker/docker/registry/auth.go b/vendor/github.com/docker/docker/registry/auth.go deleted file mode 100644 index 8cadd51..0000000 --- a/vendor/github.com/docker/docker/registry/auth.go +++ /dev/null @@ -1,303 +0,0 @@ -package registry - -import ( - "fmt" - "io/ioutil" - "net/http" - "net/url" - "strings" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/registry/client/auth" - "github.com/docker/distribution/registry/client/auth/challenge" - "github.com/docker/distribution/registry/client/transport" - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" -) - -const ( - // AuthClientID is used the ClientID used for the token server - AuthClientID = "docker" -) - -// loginV1 tries to register/login to the v1 registry server. -func loginV1(authConfig *types.AuthConfig, apiEndpoint APIEndpoint, userAgent string) (string, string, error) { - registryEndpoint, err := apiEndpoint.ToV1Endpoint(userAgent, nil) - if err != nil { - return "", "", err - } - - serverAddress := registryEndpoint.String() - - logrus.Debugf("attempting v1 login to registry endpoint %s", serverAddress) - - if serverAddress == "" { - return "", "", fmt.Errorf("Server Error: Server Address not set.") - } - - loginAgainstOfficialIndex := serverAddress == IndexServer - - req, err := http.NewRequest("GET", serverAddress+"users/", nil) - if err != nil { - return "", "", err - } - req.SetBasicAuth(authConfig.Username, authConfig.Password) - resp, err := registryEndpoint.client.Do(req) - if err != nil { - // fallback when request could not be completed - return "", "", fallbackError{ - err: err, - } - } - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return "", "", err - } - if resp.StatusCode == http.StatusOK { - return "Login Succeeded", "", nil - } else if resp.StatusCode == http.StatusUnauthorized { - if loginAgainstOfficialIndex { - return "", "", fmt.Errorf("Wrong login/password, please try again. Haven't got a Docker ID? Create one at https://hub.docker.com") - } - return "", "", fmt.Errorf("Wrong login/password, please try again") - } else if resp.StatusCode == http.StatusForbidden { - if loginAgainstOfficialIndex { - return "", "", fmt.Errorf("Login: Account is not active. Please check your e-mail for a confirmation link.") - } - // *TODO: Use registry configuration to determine what this says, if anything? - return "", "", fmt.Errorf("Login: Account is not active. Please see the documentation of the registry %s for instructions how to activate it.", serverAddress) - } else if resp.StatusCode == http.StatusInternalServerError { // Issue #14326 - logrus.Errorf("%s returned status code %d. Response Body :\n%s", req.URL.String(), resp.StatusCode, body) - return "", "", fmt.Errorf("Internal Server Error") - } - return "", "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body, - resp.StatusCode, resp.Header) -} - -type loginCredentialStore struct { - authConfig *types.AuthConfig -} - -func (lcs loginCredentialStore) Basic(*url.URL) (string, string) { - return lcs.authConfig.Username, lcs.authConfig.Password -} - -func (lcs loginCredentialStore) RefreshToken(*url.URL, string) string { - return lcs.authConfig.IdentityToken -} - -func (lcs loginCredentialStore) SetRefreshToken(u *url.URL, service, token string) { - lcs.authConfig.IdentityToken = token -} - -type staticCredentialStore struct { - auth *types.AuthConfig -} - -// NewStaticCredentialStore returns a credential store -// which always returns the same credential values. -func NewStaticCredentialStore(auth *types.AuthConfig) auth.CredentialStore { - return staticCredentialStore{ - auth: auth, - } -} - -func (scs staticCredentialStore) Basic(*url.URL) (string, string) { - if scs.auth == nil { - return "", "" - } - return scs.auth.Username, scs.auth.Password -} - -func (scs staticCredentialStore) RefreshToken(*url.URL, string) string { - if scs.auth == nil { - return "" - } - return scs.auth.IdentityToken -} - -func (scs staticCredentialStore) SetRefreshToken(*url.URL, string, string) { -} - -type fallbackError struct { - err error -} - -func (err fallbackError) Error() string { - return err.err.Error() -} - -// loginV2 tries to login to the v2 registry server. The given registry -// endpoint will be pinged to get authorization challenges. These challenges -// will be used to authenticate against the registry to validate credentials. -func loginV2(authConfig *types.AuthConfig, endpoint APIEndpoint, userAgent string) (string, string, error) { - logrus.Debugf("attempting v2 login to registry endpoint %s", strings.TrimRight(endpoint.URL.String(), "/")+"/v2/") - - modifiers := DockerHeaders(userAgent, nil) - authTransport := transport.NewTransport(NewTransport(endpoint.TLSConfig), modifiers...) - - credentialAuthConfig := *authConfig - creds := loginCredentialStore{ - authConfig: &credentialAuthConfig, - } - - loginClient, foundV2, err := v2AuthHTTPClient(endpoint.URL, authTransport, modifiers, creds, nil) - if err != nil { - return "", "", err - } - - endpointStr := strings.TrimRight(endpoint.URL.String(), "/") + "/v2/" - req, err := http.NewRequest("GET", endpointStr, nil) - if err != nil { - if !foundV2 { - err = fallbackError{err: err} - } - return "", "", err - } - - resp, err := loginClient.Do(req) - if err != nil { - if !foundV2 { - err = fallbackError{err: err} - } - return "", "", err - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - // TODO(dmcgowan): Attempt to further interpret result, status code and error code string - err := fmt.Errorf("login attempt to %s failed with status: %d %s", endpointStr, resp.StatusCode, http.StatusText(resp.StatusCode)) - if !foundV2 { - err = fallbackError{err: err} - } - return "", "", err - } - - return "Login Succeeded", credentialAuthConfig.IdentityToken, nil - -} - -func v2AuthHTTPClient(endpoint *url.URL, authTransport http.RoundTripper, modifiers []transport.RequestModifier, creds auth.CredentialStore, scopes []auth.Scope) (*http.Client, bool, error) { - challengeManager, foundV2, err := PingV2Registry(endpoint, authTransport) - if err != nil { - if !foundV2 { - err = fallbackError{err: err} - } - return nil, foundV2, err - } - - tokenHandlerOptions := auth.TokenHandlerOptions{ - Transport: authTransport, - Credentials: creds, - OfflineAccess: true, - ClientID: AuthClientID, - Scopes: scopes, - } - tokenHandler := auth.NewTokenHandlerWithOptions(tokenHandlerOptions) - basicHandler := auth.NewBasicHandler(creds) - modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler)) - tr := transport.NewTransport(authTransport, modifiers...) - - return &http.Client{ - Transport: tr, - Timeout: 15 * time.Second, - }, foundV2, nil - -} - -// ConvertToHostname converts a registry url which has http|https prepended -// to just an hostname. -func ConvertToHostname(url string) string { - stripped := url - if strings.HasPrefix(url, "http://") { - stripped = strings.TrimPrefix(url, "http://") - } else if strings.HasPrefix(url, "https://") { - stripped = strings.TrimPrefix(url, "https://") - } - - nameParts := strings.SplitN(stripped, "/", 2) - - return nameParts[0] -} - -// ResolveAuthConfig matches an auth configuration to a server address or a URL -func ResolveAuthConfig(authConfigs map[string]types.AuthConfig, index *registrytypes.IndexInfo) types.AuthConfig { - configKey := GetAuthConfigKey(index) - // First try the happy case - if c, found := authConfigs[configKey]; found || index.Official { - return c - } - - // Maybe they have a legacy config file, we will iterate the keys converting - // them to the new format and testing - for registry, ac := range authConfigs { - if configKey == ConvertToHostname(registry) { - return ac - } - } - - // When all else fails, return an empty auth config - return types.AuthConfig{} -} - -// PingResponseError is used when the response from a ping -// was received but invalid. -type PingResponseError struct { - Err error -} - -func (err PingResponseError) Error() string { - return err.Err.Error() -} - -// PingV2Registry attempts to ping a v2 registry and on success return a -// challenge manager for the supported authentication types and -// whether v2 was confirmed by the response. If a response is received but -// cannot be interpreted a PingResponseError will be returned. -func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (challenge.Manager, bool, error) { - var ( - foundV2 = false - v2Version = auth.APIVersion{ - Type: "registry", - Version: "2.0", - } - ) - - pingClient := &http.Client{ - Transport: transport, - Timeout: 15 * time.Second, - } - endpointStr := strings.TrimRight(endpoint.String(), "/") + "/v2/" - req, err := http.NewRequest("GET", endpointStr, nil) - if err != nil { - return nil, false, err - } - resp, err := pingClient.Do(req) - if err != nil { - return nil, false, err - } - defer resp.Body.Close() - - versions := auth.APIVersions(resp, DefaultRegistryVersionHeader) - for _, pingVersion := range versions { - if pingVersion == v2Version { - // The version header indicates we're definitely - // talking to a v2 registry. So don't allow future - // fallbacks to the v1 protocol. - - foundV2 = true - break - } - } - - challengeManager := challenge.NewSimpleManager() - if err := challengeManager.AddResponse(resp); err != nil { - return nil, foundV2, PingResponseError{ - Err: err, - } - } - - return challengeManager, foundV2, nil -} diff --git a/vendor/github.com/docker/docker/registry/auth_test.go b/vendor/github.com/docker/docker/registry/auth_test.go deleted file mode 100644 index 9ab71aa..0000000 --- a/vendor/github.com/docker/docker/registry/auth_test.go +++ /dev/null @@ -1,124 +0,0 @@ -// +build !solaris - -// TODO: Support Solaris - -package registry - -import ( - "testing" - - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" -) - -func buildAuthConfigs() map[string]types.AuthConfig { - authConfigs := map[string]types.AuthConfig{} - - for _, registry := range []string{"testIndex", IndexServer} { - authConfigs[registry] = types.AuthConfig{ - Username: "docker-user", - Password: "docker-pass", - } - } - - return authConfigs -} - -func TestSameAuthDataPostSave(t *testing.T) { - authConfigs := buildAuthConfigs() - authConfig := authConfigs["testIndex"] - if authConfig.Username != "docker-user" { - t.Fail() - } - if authConfig.Password != "docker-pass" { - t.Fail() - } - if authConfig.Auth != "" { - t.Fail() - } -} - -func TestResolveAuthConfigIndexServer(t *testing.T) { - authConfigs := buildAuthConfigs() - indexConfig := authConfigs[IndexServer] - - officialIndex := ®istrytypes.IndexInfo{ - Official: true, - } - privateIndex := ®istrytypes.IndexInfo{ - Official: false, - } - - resolved := ResolveAuthConfig(authConfigs, officialIndex) - assertEqual(t, resolved, indexConfig, "Expected ResolveAuthConfig to return IndexServer") - - resolved = ResolveAuthConfig(authConfigs, privateIndex) - assertNotEqual(t, resolved, indexConfig, "Expected ResolveAuthConfig to not return IndexServer") -} - -func TestResolveAuthConfigFullURL(t *testing.T) { - authConfigs := buildAuthConfigs() - - registryAuth := types.AuthConfig{ - Username: "foo-user", - Password: "foo-pass", - } - localAuth := types.AuthConfig{ - Username: "bar-user", - Password: "bar-pass", - } - officialAuth := types.AuthConfig{ - Username: "baz-user", - Password: "baz-pass", - } - authConfigs[IndexServer] = officialAuth - - expectedAuths := map[string]types.AuthConfig{ - "registry.example.com": registryAuth, - "localhost:8000": localAuth, - "registry.com": localAuth, - } - - validRegistries := map[string][]string{ - "registry.example.com": { - "https://registry.example.com/v1/", - "http://registry.example.com/v1/", - "registry.example.com", - "registry.example.com/v1/", - }, - "localhost:8000": { - "https://localhost:8000/v1/", - "http://localhost:8000/v1/", - "localhost:8000", - "localhost:8000/v1/", - }, - "registry.com": { - "https://registry.com/v1/", - "http://registry.com/v1/", - "registry.com", - "registry.com/v1/", - }, - } - - for configKey, registries := range validRegistries { - configured, ok := expectedAuths[configKey] - if !ok { - t.Fail() - } - index := ®istrytypes.IndexInfo{ - Name: configKey, - } - for _, registry := range registries { - authConfigs[registry] = configured - resolved := ResolveAuthConfig(authConfigs, index) - if resolved.Username != configured.Username || resolved.Password != configured.Password { - t.Errorf("%s -> %v != %v\n", registry, resolved, configured) - } - delete(authConfigs, registry) - resolved = ResolveAuthConfig(authConfigs, index) - if resolved.Username == configured.Username || resolved.Password == configured.Password { - t.Errorf("%s -> %v == %v\n", registry, resolved, configured) - } - } - } -} diff --git a/vendor/github.com/docker/docker/registry/config.go b/vendor/github.com/docker/docker/registry/config.go deleted file mode 100644 index 9a4f6a9..0000000 --- a/vendor/github.com/docker/docker/registry/config.go +++ /dev/null @@ -1,305 +0,0 @@ -package registry - -import ( - "errors" - "fmt" - "net" - "net/url" - "strings" - - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/opts" - "github.com/docker/docker/reference" - "github.com/spf13/pflag" -) - -// ServiceOptions holds command line options. -type ServiceOptions struct { - Mirrors []string `json:"registry-mirrors,omitempty"` - InsecureRegistries []string `json:"insecure-registries,omitempty"` - - // V2Only controls access to legacy registries. If it is set to true via the - // command line flag the daemon will not attempt to contact v1 legacy registries - V2Only bool `json:"disable-legacy-registry,omitempty"` -} - -// serviceConfig holds daemon configuration for the registry service. -type serviceConfig struct { - registrytypes.ServiceConfig - V2Only bool -} - -var ( - // DefaultNamespace is the default namespace - DefaultNamespace = "docker.io" - // DefaultRegistryVersionHeader is the name of the default HTTP header - // that carries Registry version info - DefaultRegistryVersionHeader = "Docker-Distribution-Api-Version" - - // IndexHostname is the index hostname - IndexHostname = "index.docker.io" - // IndexServer is used for user auth and image search - IndexServer = "https://" + IndexHostname + "/v1/" - // IndexName is the name of the index - IndexName = "docker.io" - - // NotaryServer is the endpoint serving the Notary trust server - NotaryServer = "https://notary.docker.io" - - // DefaultV2Registry is the URI of the default v2 registry - DefaultV2Registry = &url.URL{ - Scheme: "https", - Host: "registry-1.docker.io", - } -) - -var ( - // ErrInvalidRepositoryName is an error returned if the repository name did - // not have the correct form - ErrInvalidRepositoryName = errors.New("Invalid repository name (ex: \"registry.domain.tld/myrepos\")") - - emptyServiceConfig = newServiceConfig(ServiceOptions{}) -) - -// for mocking in unit tests -var lookupIP = net.LookupIP - -// InstallCliFlags adds command-line options to the top-level flag parser for -// the current process. -func (options *ServiceOptions) InstallCliFlags(flags *pflag.FlagSet) { - mirrors := opts.NewNamedListOptsRef("registry-mirrors", &options.Mirrors, ValidateMirror) - insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, ValidateIndexName) - - flags.Var(mirrors, "registry-mirror", "Preferred Docker registry mirror") - flags.Var(insecureRegistries, "insecure-registry", "Enable insecure registry communication") - - options.installCliPlatformFlags(flags) -} - -// newServiceConfig returns a new instance of ServiceConfig -func newServiceConfig(options ServiceOptions) *serviceConfig { - config := &serviceConfig{ - ServiceConfig: registrytypes.ServiceConfig{ - InsecureRegistryCIDRs: make([]*registrytypes.NetIPNet, 0), - IndexConfigs: make(map[string]*registrytypes.IndexInfo, 0), - // Hack: Bypass setting the mirrors to IndexConfigs since they are going away - // and Mirrors are only for the official registry anyways. - Mirrors: options.Mirrors, - }, - V2Only: options.V2Only, - } - - config.LoadInsecureRegistries(options.InsecureRegistries) - - return config -} - -// LoadInsecureRegistries loads insecure registries to config -func (config *serviceConfig) LoadInsecureRegistries(registries []string) error { - // Localhost is by default considered as an insecure registry - // This is a stop-gap for people who are running a private registry on localhost (especially on Boot2docker). - // - // TODO: should we deprecate this once it is easier for people to set up a TLS registry or change - // daemon flags on boot2docker? - registries = append(registries, "127.0.0.0/8") - - // Store original InsecureRegistryCIDRs and IndexConfigs - // Clean InsecureRegistryCIDRs and IndexConfigs in config, as passed registries has all insecure registry info. - originalCIDRs := config.ServiceConfig.InsecureRegistryCIDRs - originalIndexInfos := config.ServiceConfig.IndexConfigs - - config.ServiceConfig.InsecureRegistryCIDRs = make([]*registrytypes.NetIPNet, 0) - config.ServiceConfig.IndexConfigs = make(map[string]*registrytypes.IndexInfo, 0) - -skip: - for _, r := range registries { - // validate insecure registry - if _, err := ValidateIndexName(r); err != nil { - // before returning err, roll back to original data - config.ServiceConfig.InsecureRegistryCIDRs = originalCIDRs - config.ServiceConfig.IndexConfigs = originalIndexInfos - return err - } - // Check if CIDR was passed to --insecure-registry - _, ipnet, err := net.ParseCIDR(r) - if err == nil { - // Valid CIDR. If ipnet is already in config.InsecureRegistryCIDRs, skip. - data := (*registrytypes.NetIPNet)(ipnet) - for _, value := range config.InsecureRegistryCIDRs { - if value.IP.String() == data.IP.String() && value.Mask.String() == data.Mask.String() { - continue skip - } - } - // ipnet is not found, add it in config.InsecureRegistryCIDRs - config.InsecureRegistryCIDRs = append(config.InsecureRegistryCIDRs, data) - - } else { - // Assume `host:port` if not CIDR. - config.IndexConfigs[r] = ®istrytypes.IndexInfo{ - Name: r, - Mirrors: make([]string, 0), - Secure: false, - Official: false, - } - } - } - - // Configure public registry. - config.IndexConfigs[IndexName] = ®istrytypes.IndexInfo{ - Name: IndexName, - Mirrors: config.Mirrors, - Secure: true, - Official: true, - } - - return nil -} - -// isSecureIndex returns false if the provided indexName is part of the list of insecure registries -// Insecure registries accept HTTP and/or accept HTTPS with certificates from unknown CAs. -// -// The list of insecure registries can contain an element with CIDR notation to specify a whole subnet. -// If the subnet contains one of the IPs of the registry specified by indexName, the latter is considered -// insecure. -// -// indexName should be a URL.Host (`host:port` or `host`) where the `host` part can be either a domain name -// or an IP address. If it is a domain name, then it will be resolved in order to check if the IP is contained -// in a subnet. If the resolving is not successful, isSecureIndex will only try to match hostname to any element -// of insecureRegistries. -func isSecureIndex(config *serviceConfig, indexName string) bool { - // Check for configured index, first. This is needed in case isSecureIndex - // is called from anything besides newIndexInfo, in order to honor per-index configurations. - if index, ok := config.IndexConfigs[indexName]; ok { - return index.Secure - } - - host, _, err := net.SplitHostPort(indexName) - if err != nil { - // assume indexName is of the form `host` without the port and go on. - host = indexName - } - - addrs, err := lookupIP(host) - if err != nil { - ip := net.ParseIP(host) - if ip != nil { - addrs = []net.IP{ip} - } - - // if ip == nil, then `host` is neither an IP nor it could be looked up, - // either because the index is unreachable, or because the index is behind an HTTP proxy. - // So, len(addrs) == 0 and we're not aborting. - } - - // Try CIDR notation only if addrs has any elements, i.e. if `host`'s IP could be determined. - for _, addr := range addrs { - for _, ipnet := range config.InsecureRegistryCIDRs { - // check if the addr falls in the subnet - if (*net.IPNet)(ipnet).Contains(addr) { - return false - } - } - } - - return true -} - -// ValidateMirror validates an HTTP(S) registry mirror -func ValidateMirror(val string) (string, error) { - uri, err := url.Parse(val) - if err != nil { - return "", fmt.Errorf("%s is not a valid URI", val) - } - - if uri.Scheme != "http" && uri.Scheme != "https" { - return "", fmt.Errorf("Unsupported scheme %s", uri.Scheme) - } - - if uri.Path != "" || uri.RawQuery != "" || uri.Fragment != "" { - return "", fmt.Errorf("Unsupported path/query/fragment at end of the URI") - } - - return fmt.Sprintf("%s://%s/", uri.Scheme, uri.Host), nil -} - -// ValidateIndexName validates an index name. -func ValidateIndexName(val string) (string, error) { - if val == reference.LegacyDefaultHostname { - val = reference.DefaultHostname - } - if strings.HasPrefix(val, "-") || strings.HasSuffix(val, "-") { - return "", fmt.Errorf("Invalid index name (%s). Cannot begin or end with a hyphen.", val) - } - return val, nil -} - -func validateNoScheme(reposName string) error { - if strings.Contains(reposName, "://") { - // It cannot contain a scheme! - return ErrInvalidRepositoryName - } - return nil -} - -// newIndexInfo returns IndexInfo configuration from indexName -func newIndexInfo(config *serviceConfig, indexName string) (*registrytypes.IndexInfo, error) { - var err error - indexName, err = ValidateIndexName(indexName) - if err != nil { - return nil, err - } - - // Return any configured index info, first. - if index, ok := config.IndexConfigs[indexName]; ok { - return index, nil - } - - // Construct a non-configured index info. - index := ®istrytypes.IndexInfo{ - Name: indexName, - Mirrors: make([]string, 0), - Official: false, - } - index.Secure = isSecureIndex(config, indexName) - return index, nil -} - -// GetAuthConfigKey special-cases using the full index address of the official -// index as the AuthConfig key, and uses the (host)name[:port] for private indexes. -func GetAuthConfigKey(index *registrytypes.IndexInfo) string { - if index.Official { - return IndexServer - } - return index.Name -} - -// newRepositoryInfo validates and breaks down a repository name into a RepositoryInfo -func newRepositoryInfo(config *serviceConfig, name reference.Named) (*RepositoryInfo, error) { - index, err := newIndexInfo(config, name.Hostname()) - if err != nil { - return nil, err - } - official := !strings.ContainsRune(name.Name(), '/') - return &RepositoryInfo{ - Named: name, - Index: index, - Official: official, - }, nil -} - -// ParseRepositoryInfo performs the breakdown of a repository name into a RepositoryInfo, but -// lacks registry configuration. -func ParseRepositoryInfo(reposName reference.Named) (*RepositoryInfo, error) { - return newRepositoryInfo(emptyServiceConfig, reposName) -} - -// ParseSearchIndexInfo will use repository name to get back an indexInfo. -func ParseSearchIndexInfo(reposName string) (*registrytypes.IndexInfo, error) { - indexName, _ := splitReposSearchTerm(reposName) - - indexInfo, err := newIndexInfo(emptyServiceConfig, indexName) - if err != nil { - return nil, err - } - return indexInfo, nil -} diff --git a/vendor/github.com/docker/docker/registry/config_test.go b/vendor/github.com/docker/docker/registry/config_test.go deleted file mode 100644 index 25578a7..0000000 --- a/vendor/github.com/docker/docker/registry/config_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package registry - -import ( - "testing" -) - -func TestValidateMirror(t *testing.T) { - valid := []string{ - "http://mirror-1.com", - "https://mirror-1.com", - "http://localhost", - "https://localhost", - "http://localhost:5000", - "https://localhost:5000", - "http://127.0.0.1", - "https://127.0.0.1", - "http://127.0.0.1:5000", - "https://127.0.0.1:5000", - } - - invalid := []string{ - "!invalid!://%as%", - "ftp://mirror-1.com", - "http://mirror-1.com/", - "http://mirror-1.com/?q=foo", - "http://mirror-1.com/v1/", - "http://mirror-1.com/v1/?q=foo", - "http://mirror-1.com/v1/?q=foo#frag", - "http://mirror-1.com?q=foo", - "https://mirror-1.com#frag", - "https://mirror-1.com/", - "https://mirror-1.com/#frag", - "https://mirror-1.com/v1/", - "https://mirror-1.com/v1/#", - "https://mirror-1.com?q", - } - - for _, address := range valid { - if ret, err := ValidateMirror(address); err != nil || ret == "" { - t.Errorf("ValidateMirror(`"+address+"`) got %s %s", ret, err) - } - } - - for _, address := range invalid { - if ret, err := ValidateMirror(address); err == nil || ret != "" { - t.Errorf("ValidateMirror(`"+address+"`) got %s %s", ret, err) - } - } -} diff --git a/vendor/github.com/docker/docker/registry/config_unix.go b/vendor/github.com/docker/docker/registry/config_unix.go deleted file mode 100644 index d692e8e..0000000 --- a/vendor/github.com/docker/docker/registry/config_unix.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build !windows - -package registry - -import ( - "github.com/spf13/pflag" -) - -var ( - // CertsDir is the directory where certificates are stored - CertsDir = "/etc/docker/certs.d" -) - -// cleanPath is used to ensure that a directory name is valid on the target -// platform. It will be passed in something *similar* to a URL such as -// https:/index.docker.io/v1. Not all platforms support directory names -// which contain those characters (such as : on Windows) -func cleanPath(s string) string { - return s -} - -// installCliPlatformFlags handles any platform specific flags for the service. -func (options *ServiceOptions) installCliPlatformFlags(flags *pflag.FlagSet) { - flags.BoolVar(&options.V2Only, "disable-legacy-registry", false, "Disable contacting legacy registries") -} diff --git a/vendor/github.com/docker/docker/registry/config_windows.go b/vendor/github.com/docker/docker/registry/config_windows.go deleted file mode 100644 index d1b313d..0000000 --- a/vendor/github.com/docker/docker/registry/config_windows.go +++ /dev/null @@ -1,25 +0,0 @@ -package registry - -import ( - "os" - "path/filepath" - "strings" - - "github.com/spf13/pflag" -) - -// CertsDir is the directory where certificates are stored -var CertsDir = os.Getenv("programdata") + `\docker\certs.d` - -// cleanPath is used to ensure that a directory name is valid on the target -// platform. It will be passed in something *similar* to a URL such as -// https:\index.docker.io\v1. Not all platforms support directory names -// which contain those characters (such as : on Windows) -func cleanPath(s string) string { - return filepath.FromSlash(strings.Replace(s, ":", "", -1)) -} - -// installCliPlatformFlags handles any platform specific flags for the service. -func (options *ServiceOptions) installCliPlatformFlags(flags *pflag.FlagSet) { - // No Windows specific flags. -} diff --git a/vendor/github.com/docker/docker/registry/endpoint_test.go b/vendor/github.com/docker/docker/registry/endpoint_test.go deleted file mode 100644 index 8451d3f..0000000 --- a/vendor/github.com/docker/docker/registry/endpoint_test.go +++ /dev/null @@ -1,78 +0,0 @@ -package registry - -import ( - "net/http" - "net/http/httptest" - "net/url" - "testing" -) - -func TestEndpointParse(t *testing.T) { - testData := []struct { - str string - expected string - }{ - {IndexServer, IndexServer}, - {"http://0.0.0.0:5000/v1/", "http://0.0.0.0:5000/v1/"}, - {"http://0.0.0.0:5000", "http://0.0.0.0:5000/v1/"}, - {"0.0.0.0:5000", "https://0.0.0.0:5000/v1/"}, - {"http://0.0.0.0:5000/nonversion/", "http://0.0.0.0:5000/nonversion/v1/"}, - {"http://0.0.0.0:5000/v0/", "http://0.0.0.0:5000/v0/v1/"}, - } - for _, td := range testData { - e, err := newV1EndpointFromStr(td.str, nil, "", nil) - if err != nil { - t.Errorf("%q: %s", td.str, err) - } - if e == nil { - t.Logf("something's fishy, endpoint for %q is nil", td.str) - continue - } - if e.String() != td.expected { - t.Errorf("expected %q, got %q", td.expected, e.String()) - } - } -} - -func TestEndpointParseInvalid(t *testing.T) { - testData := []string{ - "http://0.0.0.0:5000/v2/", - } - for _, td := range testData { - e, err := newV1EndpointFromStr(td, nil, "", nil) - if err == nil { - t.Errorf("expected error parsing %q: parsed as %q", td, e) - } - } -} - -// Ensure that a registry endpoint that responds with a 401 only is determined -// to be a valid v1 registry endpoint -func TestValidateEndpoint(t *testing.T) { - requireBasicAuthHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Add("WWW-Authenticate", `Basic realm="localhost"`) - w.WriteHeader(http.StatusUnauthorized) - }) - - // Make a test server which should validate as a v1 server. - testServer := httptest.NewServer(requireBasicAuthHandler) - defer testServer.Close() - - testServerURL, err := url.Parse(testServer.URL) - if err != nil { - t.Fatal(err) - } - - testEndpoint := V1Endpoint{ - URL: testServerURL, - client: HTTPClient(NewTransport(nil)), - } - - if err = validateEndpoint(&testEndpoint); err != nil { - t.Fatal(err) - } - - if testEndpoint.URL.Scheme != "http" { - t.Fatalf("expecting to validate endpoint as http, got url %s", testEndpoint.String()) - } -} diff --git a/vendor/github.com/docker/docker/registry/endpoint_v1.go b/vendor/github.com/docker/docker/registry/endpoint_v1.go deleted file mode 100644 index 6bcf8c9..0000000 --- a/vendor/github.com/docker/docker/registry/endpoint_v1.go +++ /dev/null @@ -1,198 +0,0 @@ -package registry - -import ( - "crypto/tls" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "net/url" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/registry/client/transport" - registrytypes "github.com/docker/docker/api/types/registry" -) - -// V1Endpoint stores basic information about a V1 registry endpoint. -type V1Endpoint struct { - client *http.Client - URL *url.URL - IsSecure bool -} - -// NewV1Endpoint parses the given address to return a registry endpoint. -func NewV1Endpoint(index *registrytypes.IndexInfo, userAgent string, metaHeaders http.Header) (*V1Endpoint, error) { - tlsConfig, err := newTLSConfig(index.Name, index.Secure) - if err != nil { - return nil, err - } - - endpoint, err := newV1EndpointFromStr(GetAuthConfigKey(index), tlsConfig, userAgent, metaHeaders) - if err != nil { - return nil, err - } - - if err := validateEndpoint(endpoint); err != nil { - return nil, err - } - - return endpoint, nil -} - -func validateEndpoint(endpoint *V1Endpoint) error { - logrus.Debugf("pinging registry endpoint %s", endpoint) - - // Try HTTPS ping to registry - endpoint.URL.Scheme = "https" - if _, err := endpoint.Ping(); err != nil { - if endpoint.IsSecure { - // If registry is secure and HTTPS failed, show user the error and tell them about `--insecure-registry` - // in case that's what they need. DO NOT accept unknown CA certificates, and DO NOT fallback to HTTP. - return fmt.Errorf("invalid registry endpoint %s: %v. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry %s` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/%s/ca.crt", endpoint, err, endpoint.URL.Host, endpoint.URL.Host) - } - - // If registry is insecure and HTTPS failed, fallback to HTTP. - logrus.Debugf("Error from registry %q marked as insecure: %v. Insecurely falling back to HTTP", endpoint, err) - endpoint.URL.Scheme = "http" - - var err2 error - if _, err2 = endpoint.Ping(); err2 == nil { - return nil - } - - return fmt.Errorf("invalid registry endpoint %q. HTTPS attempt: %v. HTTP attempt: %v", endpoint, err, err2) - } - - return nil -} - -func newV1Endpoint(address url.URL, tlsConfig *tls.Config, userAgent string, metaHeaders http.Header) (*V1Endpoint, error) { - endpoint := &V1Endpoint{ - IsSecure: (tlsConfig == nil || !tlsConfig.InsecureSkipVerify), - URL: new(url.URL), - } - - *endpoint.URL = address - - // TODO(tiborvass): make sure a ConnectTimeout transport is used - tr := NewTransport(tlsConfig) - endpoint.client = HTTPClient(transport.NewTransport(tr, DockerHeaders(userAgent, metaHeaders)...)) - return endpoint, nil -} - -// trimV1Address trims the version off the address and returns the -// trimmed address or an error if there is a non-V1 version. -func trimV1Address(address string) (string, error) { - var ( - chunks []string - apiVersionStr string - ) - - if strings.HasSuffix(address, "/") { - address = address[:len(address)-1] - } - - chunks = strings.Split(address, "/") - apiVersionStr = chunks[len(chunks)-1] - if apiVersionStr == "v1" { - return strings.Join(chunks[:len(chunks)-1], "/"), nil - } - - for k, v := range apiVersions { - if k != APIVersion1 && apiVersionStr == v { - return "", fmt.Errorf("unsupported V1 version path %s", apiVersionStr) - } - } - - return address, nil -} - -func newV1EndpointFromStr(address string, tlsConfig *tls.Config, userAgent string, metaHeaders http.Header) (*V1Endpoint, error) { - if !strings.HasPrefix(address, "http://") && !strings.HasPrefix(address, "https://") { - address = "https://" + address - } - - address, err := trimV1Address(address) - if err != nil { - return nil, err - } - - uri, err := url.Parse(address) - if err != nil { - return nil, err - } - - endpoint, err := newV1Endpoint(*uri, tlsConfig, userAgent, metaHeaders) - if err != nil { - return nil, err - } - - return endpoint, nil -} - -// Get the formatted URL for the root of this registry Endpoint -func (e *V1Endpoint) String() string { - return e.URL.String() + "/v1/" -} - -// Path returns a formatted string for the URL -// of this endpoint with the given path appended. -func (e *V1Endpoint) Path(path string) string { - return e.URL.String() + "/v1/" + path -} - -// Ping returns a PingResult which indicates whether the registry is standalone or not. -func (e *V1Endpoint) Ping() (PingResult, error) { - logrus.Debugf("attempting v1 ping for registry endpoint %s", e) - - if e.String() == IndexServer { - // Skip the check, we know this one is valid - // (and we never want to fallback to http in case of error) - return PingResult{Standalone: false}, nil - } - - req, err := http.NewRequest("GET", e.Path("_ping"), nil) - if err != nil { - return PingResult{Standalone: false}, err - } - - resp, err := e.client.Do(req) - if err != nil { - return PingResult{Standalone: false}, err - } - - defer resp.Body.Close() - - jsonString, err := ioutil.ReadAll(resp.Body) - if err != nil { - return PingResult{Standalone: false}, fmt.Errorf("error while reading the http response: %s", err) - } - - // If the header is absent, we assume true for compatibility with earlier - // versions of the registry. default to true - info := PingResult{ - Standalone: true, - } - if err := json.Unmarshal(jsonString, &info); err != nil { - logrus.Debugf("Error unmarshalling the _ping PingResult: %s", err) - // don't stop here. Just assume sane defaults - } - if hdr := resp.Header.Get("X-Docker-Registry-Version"); hdr != "" { - logrus.Debugf("Registry version header: '%s'", hdr) - info.Version = hdr - } - logrus.Debugf("PingResult.Version: %q", info.Version) - - standalone := resp.Header.Get("X-Docker-Registry-Standalone") - logrus.Debugf("Registry standalone header: '%s'", standalone) - // Accepted values are "true" (case-insensitive) and "1". - if strings.EqualFold(standalone, "true") || standalone == "1" { - info.Standalone = true - } else if len(standalone) > 0 { - // there is a header set, and it is not "true" or "1", so assume fails - info.Standalone = false - } - logrus.Debugf("PingResult.Standalone: %t", info.Standalone) - return info, nil -} diff --git a/vendor/github.com/docker/docker/registry/registry.go b/vendor/github.com/docker/docker/registry/registry.go deleted file mode 100644 index 17fa97c..0000000 --- a/vendor/github.com/docker/docker/registry/registry.go +++ /dev/null @@ -1,191 +0,0 @@ -// Package registry contains client primitives to interact with a remote Docker registry. -package registry - -import ( - "crypto/tls" - "errors" - "fmt" - "io/ioutil" - "net" - "net/http" - "os" - "path/filepath" - "strings" - "time" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/registry/client/transport" - "github.com/docker/go-connections/sockets" - "github.com/docker/go-connections/tlsconfig" -) - -var ( - // ErrAlreadyExists is an error returned if an image being pushed - // already exists on the remote side - ErrAlreadyExists = errors.New("Image already exists") -) - -func newTLSConfig(hostname string, isSecure bool) (*tls.Config, error) { - // PreferredServerCipherSuites should have no effect - tlsConfig := tlsconfig.ServerDefault() - - tlsConfig.InsecureSkipVerify = !isSecure - - if isSecure && CertsDir != "" { - hostDir := filepath.Join(CertsDir, cleanPath(hostname)) - logrus.Debugf("hostDir: %s", hostDir) - if err := ReadCertsDirectory(tlsConfig, hostDir); err != nil { - return nil, err - } - } - - return tlsConfig, nil -} - -func hasFile(files []os.FileInfo, name string) bool { - for _, f := range files { - if f.Name() == name { - return true - } - } - return false -} - -// ReadCertsDirectory reads the directory for TLS certificates -// including roots and certificate pairs and updates the -// provided TLS configuration. -func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error { - fs, err := ioutil.ReadDir(directory) - if err != nil && !os.IsNotExist(err) { - return err - } - - for _, f := range fs { - if strings.HasSuffix(f.Name(), ".crt") { - if tlsConfig.RootCAs == nil { - systemPool, err := tlsconfig.SystemCertPool() - if err != nil { - return fmt.Errorf("unable to get system cert pool: %v", err) - } - tlsConfig.RootCAs = systemPool - } - logrus.Debugf("crt: %s", filepath.Join(directory, f.Name())) - data, err := ioutil.ReadFile(filepath.Join(directory, f.Name())) - if err != nil { - return err - } - tlsConfig.RootCAs.AppendCertsFromPEM(data) - } - if strings.HasSuffix(f.Name(), ".cert") { - certName := f.Name() - keyName := certName[:len(certName)-5] + ".key" - logrus.Debugf("cert: %s", filepath.Join(directory, f.Name())) - if !hasFile(fs, keyName) { - return fmt.Errorf("Missing key %s for client certificate %s. Note that CA certificates should use the extension .crt.", keyName, certName) - } - cert, err := tls.LoadX509KeyPair(filepath.Join(directory, certName), filepath.Join(directory, keyName)) - if err != nil { - return err - } - tlsConfig.Certificates = append(tlsConfig.Certificates, cert) - } - if strings.HasSuffix(f.Name(), ".key") { - keyName := f.Name() - certName := keyName[:len(keyName)-4] + ".cert" - logrus.Debugf("key: %s", filepath.Join(directory, f.Name())) - if !hasFile(fs, certName) { - return fmt.Errorf("Missing client certificate %s for key %s", certName, keyName) - } - } - } - - return nil -} - -// DockerHeaders returns request modifiers with a User-Agent and metaHeaders -func DockerHeaders(userAgent string, metaHeaders http.Header) []transport.RequestModifier { - modifiers := []transport.RequestModifier{} - if userAgent != "" { - modifiers = append(modifiers, transport.NewHeaderRequestModifier(http.Header{ - "User-Agent": []string{userAgent}, - })) - } - if metaHeaders != nil { - modifiers = append(modifiers, transport.NewHeaderRequestModifier(metaHeaders)) - } - return modifiers -} - -// HTTPClient returns an HTTP client structure which uses the given transport -// and contains the necessary headers for redirected requests -func HTTPClient(transport http.RoundTripper) *http.Client { - return &http.Client{ - Transport: transport, - CheckRedirect: addRequiredHeadersToRedirectedRequests, - } -} - -func trustedLocation(req *http.Request) bool { - var ( - trusteds = []string{"docker.com", "docker.io"} - hostname = strings.SplitN(req.Host, ":", 2)[0] - ) - if req.URL.Scheme != "https" { - return false - } - - for _, trusted := range trusteds { - if hostname == trusted || strings.HasSuffix(hostname, "."+trusted) { - return true - } - } - return false -} - -// addRequiredHeadersToRedirectedRequests adds the necessary redirection headers -// for redirected requests -func addRequiredHeadersToRedirectedRequests(req *http.Request, via []*http.Request) error { - if via != nil && via[0] != nil { - if trustedLocation(req) && trustedLocation(via[0]) { - req.Header = via[0].Header - return nil - } - for k, v := range via[0].Header { - if k != "Authorization" { - for _, vv := range v { - req.Header.Add(k, vv) - } - } - } - } - return nil -} - -// NewTransport returns a new HTTP transport. If tlsConfig is nil, it uses the -// default TLS configuration. -func NewTransport(tlsConfig *tls.Config) *http.Transport { - if tlsConfig == nil { - tlsConfig = tlsconfig.ServerDefault() - } - - direct := &net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - DualStack: true, - } - - base := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: direct.Dial, - TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: tlsConfig, - // TODO(dmcgowan): Call close idle connections when complete and use keep alive - DisableKeepAlives: true, - } - - proxyDialer, err := sockets.DialerFromEnvironment(direct) - if err == nil { - base.Dial = proxyDialer.Dial - } - return base -} diff --git a/vendor/github.com/docker/docker/registry/registry_mock_test.go b/vendor/github.com/docker/docker/registry/registry_mock_test.go deleted file mode 100644 index 21fc1fd..0000000 --- a/vendor/github.com/docker/docker/registry/registry_mock_test.go +++ /dev/null @@ -1,478 +0,0 @@ -// +build !solaris - -package registry - -import ( - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "net/http/httptest" - "net/url" - "strconv" - "strings" - "testing" - "time" - - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/reference" - "github.com/gorilla/mux" - - "github.com/Sirupsen/logrus" -) - -var ( - testHTTPServer *httptest.Server - testHTTPSServer *httptest.Server - testLayers = map[string]map[string]string{ - "77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20": { - "json": `{"id":"77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20", - "comment":"test base image","created":"2013-03-23T12:53:11.10432-07:00", - "container_config":{"Hostname":"","User":"","Memory":0,"MemorySwap":0, - "CpuShares":0,"AttachStdin":false,"AttachStdout":false,"AttachStderr":false, - "Tty":false,"OpenStdin":false,"StdinOnce":false, - "Env":null,"Cmd":null,"Dns":null,"Image":"","Volumes":null, - "VolumesFrom":"","Entrypoint":null},"Size":424242}`, - "checksum_simple": "sha256:1ac330d56e05eef6d438586545ceff7550d3bdcb6b19961f12c5ba714ee1bb37", - "checksum_tarsum": "tarsum+sha256:4409a0685741ca86d38df878ed6f8cbba4c99de5dc73cd71aef04be3bb70be7c", - "ancestry": `["77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20"]`, - "layer": string([]byte{ - 0x1f, 0x8b, 0x08, 0x08, 0x0e, 0xb0, 0xee, 0x51, 0x02, 0x03, 0x6c, 0x61, 0x79, 0x65, - 0x72, 0x2e, 0x74, 0x61, 0x72, 0x00, 0xed, 0xd2, 0x31, 0x0e, 0xc2, 0x30, 0x0c, 0x05, - 0x50, 0xcf, 0x9c, 0xc2, 0x27, 0x48, 0xed, 0x38, 0x4e, 0xce, 0x13, 0x44, 0x2b, 0x66, - 0x62, 0x24, 0x8e, 0x4f, 0xa0, 0x15, 0x63, 0xb6, 0x20, 0x21, 0xfc, 0x96, 0xbf, 0x78, - 0xb0, 0xf5, 0x1d, 0x16, 0x98, 0x8e, 0x88, 0x8a, 0x2a, 0xbe, 0x33, 0xef, 0x49, 0x31, - 0xed, 0x79, 0x40, 0x8e, 0x5c, 0x44, 0x85, 0x88, 0x33, 0x12, 0x73, 0x2c, 0x02, 0xa8, - 0xf0, 0x05, 0xf7, 0x66, 0xf5, 0xd6, 0x57, 0x69, 0xd7, 0x7a, 0x19, 0xcd, 0xf5, 0xb1, - 0x6d, 0x1b, 0x1f, 0xf9, 0xba, 0xe3, 0x93, 0x3f, 0x22, 0x2c, 0xb6, 0x36, 0x0b, 0xf6, - 0xb0, 0xa9, 0xfd, 0xe7, 0x94, 0x46, 0xfd, 0xeb, 0xd1, 0x7f, 0x2c, 0xc4, 0xd2, 0xfb, - 0x97, 0xfe, 0x02, 0x80, 0xe4, 0xfd, 0x4f, 0x77, 0xae, 0x6d, 0x3d, 0x81, 0x73, 0xce, - 0xb9, 0x7f, 0xf3, 0x04, 0x41, 0xc1, 0xab, 0xc6, 0x00, 0x0a, 0x00, 0x00, - }), - }, - "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d": { - "json": `{"id":"42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d", - "parent":"77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20", - "comment":"test base image","created":"2013-03-23T12:55:11.10432-07:00", - "container_config":{"Hostname":"","User":"","Memory":0,"MemorySwap":0, - "CpuShares":0,"AttachStdin":false,"AttachStdout":false,"AttachStderr":false, - "Tty":false,"OpenStdin":false,"StdinOnce":false, - "Env":null,"Cmd":null,"Dns":null,"Image":"","Volumes":null, - "VolumesFrom":"","Entrypoint":null},"Size":424242}`, - "checksum_simple": "sha256:bea7bf2e4bacd479344b737328db47b18880d09096e6674165533aa994f5e9f2", - "checksum_tarsum": "tarsum+sha256:68fdb56fb364f074eec2c9b3f85ca175329c4dcabc4a6a452b7272aa613a07a2", - "ancestry": `["42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d", - "77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20"]`, - "layer": string([]byte{ - 0x1f, 0x8b, 0x08, 0x08, 0xbd, 0xb3, 0xee, 0x51, 0x02, 0x03, 0x6c, 0x61, 0x79, 0x65, - 0x72, 0x2e, 0x74, 0x61, 0x72, 0x00, 0xed, 0xd1, 0x31, 0x0e, 0xc2, 0x30, 0x0c, 0x05, - 0x50, 0xcf, 0x9c, 0xc2, 0x27, 0x48, 0x9d, 0x38, 0x8e, 0xcf, 0x53, 0x51, 0xaa, 0x56, - 0xea, 0x44, 0x82, 0xc4, 0xf1, 0x09, 0xb4, 0xea, 0x98, 0x2d, 0x48, 0x08, 0xbf, 0xe5, - 0x2f, 0x1e, 0xfc, 0xf5, 0xdd, 0x00, 0xdd, 0x11, 0x91, 0x8a, 0xe0, 0x27, 0xd3, 0x9e, - 0x14, 0xe2, 0x9e, 0x07, 0xf4, 0xc1, 0x2b, 0x0b, 0xfb, 0xa4, 0x82, 0xe4, 0x3d, 0x93, - 0x02, 0x0a, 0x7c, 0xc1, 0x23, 0x97, 0xf1, 0x5e, 0x5f, 0xc9, 0xcb, 0x38, 0xb5, 0xee, - 0xea, 0xd9, 0x3c, 0xb7, 0x4b, 0xbe, 0x7b, 0x9c, 0xf9, 0x23, 0xdc, 0x50, 0x6e, 0xb9, - 0xb8, 0xf2, 0x2c, 0x5d, 0xf7, 0x4f, 0x31, 0xb6, 0xf6, 0x4f, 0xc7, 0xfe, 0x41, 0x55, - 0x63, 0xdd, 0x9f, 0x89, 0x09, 0x90, 0x6c, 0xff, 0xee, 0xae, 0xcb, 0xba, 0x4d, 0x17, - 0x30, 0xc6, 0x18, 0xf3, 0x67, 0x5e, 0xc1, 0xed, 0x21, 0x5d, 0x00, 0x0a, 0x00, 0x00, - }), - }, - } - testRepositories = map[string]map[string]string{ - "foo42/bar": { - "latest": "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d", - "test": "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d", - }, - } - mockHosts = map[string][]net.IP{ - "": {net.ParseIP("0.0.0.0")}, - "localhost": {net.ParseIP("127.0.0.1"), net.ParseIP("::1")}, - "example.com": {net.ParseIP("42.42.42.42")}, - "other.com": {net.ParseIP("43.43.43.43")}, - } -) - -func init() { - r := mux.NewRouter() - - // /v1/ - r.HandleFunc("/v1/_ping", handlerGetPing).Methods("GET") - r.HandleFunc("/v1/images/{image_id:[^/]+}/{action:json|layer|ancestry}", handlerGetImage).Methods("GET") - r.HandleFunc("/v1/images/{image_id:[^/]+}/{action:json|layer|checksum}", handlerPutImage).Methods("PUT") - r.HandleFunc("/v1/repositories/{repository:.+}/tags", handlerGetDeleteTags).Methods("GET", "DELETE") - r.HandleFunc("/v1/repositories/{repository:.+}/tags/{tag:.+}", handlerGetTag).Methods("GET") - r.HandleFunc("/v1/repositories/{repository:.+}/tags/{tag:.+}", handlerPutTag).Methods("PUT") - r.HandleFunc("/v1/users{null:.*}", handlerUsers).Methods("GET", "POST", "PUT") - r.HandleFunc("/v1/repositories/{repository:.+}{action:/images|/}", handlerImages).Methods("GET", "PUT", "DELETE") - r.HandleFunc("/v1/repositories/{repository:.+}/auth", handlerAuth).Methods("PUT") - r.HandleFunc("/v1/search", handlerSearch).Methods("GET") - - // /v2/ - r.HandleFunc("/v2/version", handlerGetPing).Methods("GET") - - testHTTPServer = httptest.NewServer(handlerAccessLog(r)) - testHTTPSServer = httptest.NewTLSServer(handlerAccessLog(r)) - - // override net.LookupIP - lookupIP = func(host string) ([]net.IP, error) { - if host == "127.0.0.1" { - // I believe in future Go versions this will fail, so let's fix it later - return net.LookupIP(host) - } - for h, addrs := range mockHosts { - if host == h { - return addrs, nil - } - for _, addr := range addrs { - if addr.String() == host { - return []net.IP{addr}, nil - } - } - } - return nil, errors.New("lookup: no such host") - } -} - -func handlerAccessLog(handler http.Handler) http.Handler { - logHandler := func(w http.ResponseWriter, r *http.Request) { - logrus.Debugf("%s \"%s %s\"", r.RemoteAddr, r.Method, r.URL) - handler.ServeHTTP(w, r) - } - return http.HandlerFunc(logHandler) -} - -func makeURL(req string) string { - return testHTTPServer.URL + req -} - -func makeHTTPSURL(req string) string { - return testHTTPSServer.URL + req -} - -func makeIndex(req string) *registrytypes.IndexInfo { - index := ®istrytypes.IndexInfo{ - Name: makeURL(req), - } - return index -} - -func makeHTTPSIndex(req string) *registrytypes.IndexInfo { - index := ®istrytypes.IndexInfo{ - Name: makeHTTPSURL(req), - } - return index -} - -func makePublicIndex() *registrytypes.IndexInfo { - index := ®istrytypes.IndexInfo{ - Name: IndexServer, - Secure: true, - Official: true, - } - return index -} - -func makeServiceConfig(mirrors []string, insecureRegistries []string) *serviceConfig { - options := ServiceOptions{ - Mirrors: mirrors, - InsecureRegistries: insecureRegistries, - } - - return newServiceConfig(options) -} - -func writeHeaders(w http.ResponseWriter) { - h := w.Header() - h.Add("Server", "docker-tests/mock") - h.Add("Expires", "-1") - h.Add("Content-Type", "application/json") - h.Add("Pragma", "no-cache") - h.Add("Cache-Control", "no-cache") - h.Add("X-Docker-Registry-Version", "0.0.0") - h.Add("X-Docker-Registry-Config", "mock") -} - -func writeResponse(w http.ResponseWriter, message interface{}, code int) { - writeHeaders(w) - w.WriteHeader(code) - body, err := json.Marshal(message) - if err != nil { - io.WriteString(w, err.Error()) - return - } - w.Write(body) -} - -func readJSON(r *http.Request, dest interface{}) error { - body, err := ioutil.ReadAll(r.Body) - if err != nil { - return err - } - return json.Unmarshal(body, dest) -} - -func apiError(w http.ResponseWriter, message string, code int) { - body := map[string]string{ - "error": message, - } - writeResponse(w, body, code) -} - -func assertEqual(t *testing.T, a interface{}, b interface{}, message string) { - if a == b { - return - } - if len(message) == 0 { - message = fmt.Sprintf("%v != %v", a, b) - } - t.Fatal(message) -} - -func assertNotEqual(t *testing.T, a interface{}, b interface{}, message string) { - if a != b { - return - } - if len(message) == 0 { - message = fmt.Sprintf("%v == %v", a, b) - } - t.Fatal(message) -} - -// Similar to assertEqual, but does not stop test -func checkEqual(t *testing.T, a interface{}, b interface{}, messagePrefix string) { - if a == b { - return - } - message := fmt.Sprintf("%v != %v", a, b) - if len(messagePrefix) != 0 { - message = messagePrefix + ": " + message - } - t.Error(message) -} - -// Similar to assertNotEqual, but does not stop test -func checkNotEqual(t *testing.T, a interface{}, b interface{}, messagePrefix string) { - if a != b { - return - } - message := fmt.Sprintf("%v == %v", a, b) - if len(messagePrefix) != 0 { - message = messagePrefix + ": " + message - } - t.Error(message) -} - -func requiresAuth(w http.ResponseWriter, r *http.Request) bool { - writeCookie := func() { - value := fmt.Sprintf("FAKE-SESSION-%d", time.Now().UnixNano()) - cookie := &http.Cookie{Name: "session", Value: value, MaxAge: 3600} - http.SetCookie(w, cookie) - //FIXME(sam): this should be sent only on Index routes - value = fmt.Sprintf("FAKE-TOKEN-%d", time.Now().UnixNano()) - w.Header().Add("X-Docker-Token", value) - } - if len(r.Cookies()) > 0 { - writeCookie() - return true - } - if len(r.Header.Get("Authorization")) > 0 { - writeCookie() - return true - } - w.Header().Add("WWW-Authenticate", "token") - apiError(w, "Wrong auth", 401) - return false -} - -func handlerGetPing(w http.ResponseWriter, r *http.Request) { - writeResponse(w, true, 200) -} - -func handlerGetImage(w http.ResponseWriter, r *http.Request) { - if !requiresAuth(w, r) { - return - } - vars := mux.Vars(r) - layer, exists := testLayers[vars["image_id"]] - if !exists { - http.NotFound(w, r) - return - } - writeHeaders(w) - layerSize := len(layer["layer"]) - w.Header().Add("X-Docker-Size", strconv.Itoa(layerSize)) - io.WriteString(w, layer[vars["action"]]) -} - -func handlerPutImage(w http.ResponseWriter, r *http.Request) { - if !requiresAuth(w, r) { - return - } - vars := mux.Vars(r) - imageID := vars["image_id"] - action := vars["action"] - layer, exists := testLayers[imageID] - if !exists { - if action != "json" { - http.NotFound(w, r) - return - } - layer = make(map[string]string) - testLayers[imageID] = layer - } - if checksum := r.Header.Get("X-Docker-Checksum"); checksum != "" { - if checksum != layer["checksum_simple"] && checksum != layer["checksum_tarsum"] { - apiError(w, "Wrong checksum", 400) - return - } - } - body, err := ioutil.ReadAll(r.Body) - if err != nil { - apiError(w, fmt.Sprintf("Error: %s", err), 500) - return - } - layer[action] = string(body) - writeResponse(w, true, 200) -} - -func handlerGetDeleteTags(w http.ResponseWriter, r *http.Request) { - if !requiresAuth(w, r) { - return - } - repositoryName, err := reference.WithName(mux.Vars(r)["repository"]) - if err != nil { - apiError(w, "Could not parse repository", 400) - return - } - tags, exists := testRepositories[repositoryName.String()] - if !exists { - apiError(w, "Repository not found", 404) - return - } - if r.Method == "DELETE" { - delete(testRepositories, repositoryName.String()) - writeResponse(w, true, 200) - return - } - writeResponse(w, tags, 200) -} - -func handlerGetTag(w http.ResponseWriter, r *http.Request) { - if !requiresAuth(w, r) { - return - } - vars := mux.Vars(r) - repositoryName, err := reference.WithName(vars["repository"]) - if err != nil { - apiError(w, "Could not parse repository", 400) - return - } - tagName := vars["tag"] - tags, exists := testRepositories[repositoryName.String()] - if !exists { - apiError(w, "Repository not found", 404) - return - } - tag, exists := tags[tagName] - if !exists { - apiError(w, "Tag not found", 404) - return - } - writeResponse(w, tag, 200) -} - -func handlerPutTag(w http.ResponseWriter, r *http.Request) { - if !requiresAuth(w, r) { - return - } - vars := mux.Vars(r) - repositoryName, err := reference.WithName(vars["repository"]) - if err != nil { - apiError(w, "Could not parse repository", 400) - return - } - tagName := vars["tag"] - tags, exists := testRepositories[repositoryName.String()] - if !exists { - tags = make(map[string]string) - testRepositories[repositoryName.String()] = tags - } - tagValue := "" - readJSON(r, tagValue) - tags[tagName] = tagValue - writeResponse(w, true, 200) -} - -func handlerUsers(w http.ResponseWriter, r *http.Request) { - code := 200 - if r.Method == "POST" { - code = 201 - } else if r.Method == "PUT" { - code = 204 - } - writeResponse(w, "", code) -} - -func handlerImages(w http.ResponseWriter, r *http.Request) { - u, _ := url.Parse(testHTTPServer.URL) - w.Header().Add("X-Docker-Endpoints", fmt.Sprintf("%s , %s ", u.Host, "test.example.com")) - w.Header().Add("X-Docker-Token", fmt.Sprintf("FAKE-SESSION-%d", time.Now().UnixNano())) - if r.Method == "PUT" { - if strings.HasSuffix(r.URL.Path, "images") { - writeResponse(w, "", 204) - return - } - writeResponse(w, "", 200) - return - } - if r.Method == "DELETE" { - writeResponse(w, "", 204) - return - } - images := []map[string]string{} - for imageID, layer := range testLayers { - image := make(map[string]string) - image["id"] = imageID - image["checksum"] = layer["checksum_tarsum"] - image["Tag"] = "latest" - images = append(images, image) - } - writeResponse(w, images, 200) -} - -func handlerAuth(w http.ResponseWriter, r *http.Request) { - writeResponse(w, "OK", 200) -} - -func handlerSearch(w http.ResponseWriter, r *http.Request) { - result := ®istrytypes.SearchResults{ - Query: "fakequery", - NumResults: 1, - Results: []registrytypes.SearchResult{{Name: "fakeimage", StarCount: 42}}, - } - writeResponse(w, result, 200) -} - -func TestPing(t *testing.T) { - res, err := http.Get(makeURL("/v1/_ping")) - if err != nil { - t.Fatal(err) - } - assertEqual(t, res.StatusCode, 200, "") - assertEqual(t, res.Header.Get("X-Docker-Registry-Config"), "mock", - "This is not a Mocked Registry") -} - -/* Uncomment this to test Mocked Registry locally with curl - * WARNING: Don't push on the repos uncommented, it'll block the tests - * -func TestWait(t *testing.T) { - logrus.Println("Test HTTP server ready and waiting:", testHTTPServer.URL) - c := make(chan int) - <-c -} - -//*/ diff --git a/vendor/github.com/docker/docker/registry/registry_test.go b/vendor/github.com/docker/docker/registry/registry_test.go deleted file mode 100644 index 786dfbe..0000000 --- a/vendor/github.com/docker/docker/registry/registry_test.go +++ /dev/null @@ -1,875 +0,0 @@ -// +build !solaris - -package registry - -import ( - "fmt" - "net/http" - "net/http/httputil" - "net/url" - "strings" - "testing" - - "github.com/docker/distribution/registry/client/transport" - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/reference" -) - -var ( - token = []string{"fake-token"} -) - -const ( - imageID = "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d" - REPO = "foo42/bar" -) - -func spawnTestRegistrySession(t *testing.T) *Session { - authConfig := &types.AuthConfig{} - endpoint, err := NewV1Endpoint(makeIndex("/v1/"), "", nil) - if err != nil { - t.Fatal(err) - } - userAgent := "docker test client" - var tr http.RoundTripper = debugTransport{NewTransport(nil), t.Log} - tr = transport.NewTransport(AuthTransport(tr, authConfig, false), DockerHeaders(userAgent, nil)...) - client := HTTPClient(tr) - r, err := NewSession(client, authConfig, endpoint) - if err != nil { - t.Fatal(err) - } - // In a normal scenario for the v1 registry, the client should send a `X-Docker-Token: true` - // header while authenticating, in order to retrieve a token that can be later used to - // perform authenticated actions. - // - // The mock v1 registry does not support that, (TODO(tiborvass): support it), instead, - // it will consider authenticated any request with the header `X-Docker-Token: fake-token`. - // - // Because we know that the client's transport is an `*authTransport` we simply cast it, - // in order to set the internal cached token to the fake token, and thus send that fake token - // upon every subsequent requests. - r.client.Transport.(*authTransport).token = token - return r -} - -func TestPingRegistryEndpoint(t *testing.T) { - testPing := func(index *registrytypes.IndexInfo, expectedStandalone bool, assertMessage string) { - ep, err := NewV1Endpoint(index, "", nil) - if err != nil { - t.Fatal(err) - } - regInfo, err := ep.Ping() - if err != nil { - t.Fatal(err) - } - - assertEqual(t, regInfo.Standalone, expectedStandalone, assertMessage) - } - - testPing(makeIndex("/v1/"), true, "Expected standalone to be true (default)") - testPing(makeHTTPSIndex("/v1/"), true, "Expected standalone to be true (default)") - testPing(makePublicIndex(), false, "Expected standalone to be false for public index") -} - -func TestEndpoint(t *testing.T) { - // Simple wrapper to fail test if err != nil - expandEndpoint := func(index *registrytypes.IndexInfo) *V1Endpoint { - endpoint, err := NewV1Endpoint(index, "", nil) - if err != nil { - t.Fatal(err) - } - return endpoint - } - - assertInsecureIndex := func(index *registrytypes.IndexInfo) { - index.Secure = true - _, err := NewV1Endpoint(index, "", nil) - assertNotEqual(t, err, nil, index.Name+": Expected error for insecure index") - assertEqual(t, strings.Contains(err.Error(), "insecure-registry"), true, index.Name+": Expected insecure-registry error for insecure index") - index.Secure = false - } - - assertSecureIndex := func(index *registrytypes.IndexInfo) { - index.Secure = true - _, err := NewV1Endpoint(index, "", nil) - assertNotEqual(t, err, nil, index.Name+": Expected cert error for secure index") - assertEqual(t, strings.Contains(err.Error(), "certificate signed by unknown authority"), true, index.Name+": Expected cert error for secure index") - index.Secure = false - } - - index := ®istrytypes.IndexInfo{} - index.Name = makeURL("/v1/") - endpoint := expandEndpoint(index) - assertEqual(t, endpoint.String(), index.Name, "Expected endpoint to be "+index.Name) - assertInsecureIndex(index) - - index.Name = makeURL("") - endpoint = expandEndpoint(index) - assertEqual(t, endpoint.String(), index.Name+"/v1/", index.Name+": Expected endpoint to be "+index.Name+"/v1/") - assertInsecureIndex(index) - - httpURL := makeURL("") - index.Name = strings.SplitN(httpURL, "://", 2)[1] - endpoint = expandEndpoint(index) - assertEqual(t, endpoint.String(), httpURL+"/v1/", index.Name+": Expected endpoint to be "+httpURL+"/v1/") - assertInsecureIndex(index) - - index.Name = makeHTTPSURL("/v1/") - endpoint = expandEndpoint(index) - assertEqual(t, endpoint.String(), index.Name, "Expected endpoint to be "+index.Name) - assertSecureIndex(index) - - index.Name = makeHTTPSURL("") - endpoint = expandEndpoint(index) - assertEqual(t, endpoint.String(), index.Name+"/v1/", index.Name+": Expected endpoint to be "+index.Name+"/v1/") - assertSecureIndex(index) - - httpsURL := makeHTTPSURL("") - index.Name = strings.SplitN(httpsURL, "://", 2)[1] - endpoint = expandEndpoint(index) - assertEqual(t, endpoint.String(), httpsURL+"/v1/", index.Name+": Expected endpoint to be "+httpsURL+"/v1/") - assertSecureIndex(index) - - badEndpoints := []string{ - "http://127.0.0.1/v1/", - "https://127.0.0.1/v1/", - "http://127.0.0.1", - "https://127.0.0.1", - "127.0.0.1", - } - for _, address := range badEndpoints { - index.Name = address - _, err := NewV1Endpoint(index, "", nil) - checkNotEqual(t, err, nil, "Expected error while expanding bad endpoint") - } -} - -func TestGetRemoteHistory(t *testing.T) { - r := spawnTestRegistrySession(t) - hist, err := r.GetRemoteHistory(imageID, makeURL("/v1/")) - if err != nil { - t.Fatal(err) - } - assertEqual(t, len(hist), 2, "Expected 2 images in history") - assertEqual(t, hist[0], imageID, "Expected "+imageID+"as first ancestry") - assertEqual(t, hist[1], "77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20", - "Unexpected second ancestry") -} - -func TestLookupRemoteImage(t *testing.T) { - r := spawnTestRegistrySession(t) - err := r.LookupRemoteImage(imageID, makeURL("/v1/")) - assertEqual(t, err, nil, "Expected error of remote lookup to nil") - if err := r.LookupRemoteImage("abcdef", makeURL("/v1/")); err == nil { - t.Fatal("Expected error of remote lookup to not nil") - } -} - -func TestGetRemoteImageJSON(t *testing.T) { - r := spawnTestRegistrySession(t) - json, size, err := r.GetRemoteImageJSON(imageID, makeURL("/v1/")) - if err != nil { - t.Fatal(err) - } - assertEqual(t, size, int64(154), "Expected size 154") - if len(json) == 0 { - t.Fatal("Expected non-empty json") - } - - _, _, err = r.GetRemoteImageJSON("abcdef", makeURL("/v1/")) - if err == nil { - t.Fatal("Expected image not found error") - } -} - -func TestGetRemoteImageLayer(t *testing.T) { - r := spawnTestRegistrySession(t) - data, err := r.GetRemoteImageLayer(imageID, makeURL("/v1/"), 0) - if err != nil { - t.Fatal(err) - } - if data == nil { - t.Fatal("Expected non-nil data result") - } - - _, err = r.GetRemoteImageLayer("abcdef", makeURL("/v1/"), 0) - if err == nil { - t.Fatal("Expected image not found error") - } -} - -func TestGetRemoteTag(t *testing.T) { - r := spawnTestRegistrySession(t) - repoRef, err := reference.ParseNamed(REPO) - if err != nil { - t.Fatal(err) - } - tag, err := r.GetRemoteTag([]string{makeURL("/v1/")}, repoRef, "test") - if err != nil { - t.Fatal(err) - } - assertEqual(t, tag, imageID, "Expected tag test to map to "+imageID) - - bazRef, err := reference.ParseNamed("foo42/baz") - if err != nil { - t.Fatal(err) - } - _, err = r.GetRemoteTag([]string{makeURL("/v1/")}, bazRef, "foo") - if err != ErrRepoNotFound { - t.Fatal("Expected ErrRepoNotFound error when fetching tag for bogus repo") - } -} - -func TestGetRemoteTags(t *testing.T) { - r := spawnTestRegistrySession(t) - repoRef, err := reference.ParseNamed(REPO) - if err != nil { - t.Fatal(err) - } - tags, err := r.GetRemoteTags([]string{makeURL("/v1/")}, repoRef) - if err != nil { - t.Fatal(err) - } - assertEqual(t, len(tags), 2, "Expected two tags") - assertEqual(t, tags["latest"], imageID, "Expected tag latest to map to "+imageID) - assertEqual(t, tags["test"], imageID, "Expected tag test to map to "+imageID) - - bazRef, err := reference.ParseNamed("foo42/baz") - if err != nil { - t.Fatal(err) - } - _, err = r.GetRemoteTags([]string{makeURL("/v1/")}, bazRef) - if err != ErrRepoNotFound { - t.Fatal("Expected ErrRepoNotFound error when fetching tags for bogus repo") - } -} - -func TestGetRepositoryData(t *testing.T) { - r := spawnTestRegistrySession(t) - parsedURL, err := url.Parse(makeURL("/v1/")) - if err != nil { - t.Fatal(err) - } - host := "http://" + parsedURL.Host + "/v1/" - repoRef, err := reference.ParseNamed(REPO) - if err != nil { - t.Fatal(err) - } - data, err := r.GetRepositoryData(repoRef) - if err != nil { - t.Fatal(err) - } - assertEqual(t, len(data.ImgList), 2, "Expected 2 images in ImgList") - assertEqual(t, len(data.Endpoints), 2, - fmt.Sprintf("Expected 2 endpoints in Endpoints, found %d instead", len(data.Endpoints))) - assertEqual(t, data.Endpoints[0], host, - fmt.Sprintf("Expected first endpoint to be %s but found %s instead", host, data.Endpoints[0])) - assertEqual(t, data.Endpoints[1], "http://test.example.com/v1/", - fmt.Sprintf("Expected first endpoint to be http://test.example.com/v1/ but found %s instead", data.Endpoints[1])) - -} - -func TestPushImageJSONRegistry(t *testing.T) { - r := spawnTestRegistrySession(t) - imgData := &ImgData{ - ID: "77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20", - Checksum: "sha256:1ac330d56e05eef6d438586545ceff7550d3bdcb6b19961f12c5ba714ee1bb37", - } - - err := r.PushImageJSONRegistry(imgData, []byte{0x42, 0xdf, 0x0}, makeURL("/v1/")) - if err != nil { - t.Fatal(err) - } -} - -func TestPushImageLayerRegistry(t *testing.T) { - r := spawnTestRegistrySession(t) - layer := strings.NewReader("") - _, _, err := r.PushImageLayerRegistry(imageID, layer, makeURL("/v1/"), []byte{}) - if err != nil { - t.Fatal(err) - } -} - -func TestParseRepositoryInfo(t *testing.T) { - type staticRepositoryInfo struct { - Index *registrytypes.IndexInfo - RemoteName string - CanonicalName string - LocalName string - Official bool - } - - expectedRepoInfos := map[string]staticRepositoryInfo{ - "fooo/bar": { - Index: ®istrytypes.IndexInfo{ - Name: IndexName, - Official: true, - }, - RemoteName: "fooo/bar", - LocalName: "fooo/bar", - CanonicalName: "docker.io/fooo/bar", - Official: false, - }, - "library/ubuntu": { - Index: ®istrytypes.IndexInfo{ - Name: IndexName, - Official: true, - }, - RemoteName: "library/ubuntu", - LocalName: "ubuntu", - CanonicalName: "docker.io/library/ubuntu", - Official: true, - }, - "nonlibrary/ubuntu": { - Index: ®istrytypes.IndexInfo{ - Name: IndexName, - Official: true, - }, - RemoteName: "nonlibrary/ubuntu", - LocalName: "nonlibrary/ubuntu", - CanonicalName: "docker.io/nonlibrary/ubuntu", - Official: false, - }, - "ubuntu": { - Index: ®istrytypes.IndexInfo{ - Name: IndexName, - Official: true, - }, - RemoteName: "library/ubuntu", - LocalName: "ubuntu", - CanonicalName: "docker.io/library/ubuntu", - Official: true, - }, - "other/library": { - Index: ®istrytypes.IndexInfo{ - Name: IndexName, - Official: true, - }, - RemoteName: "other/library", - LocalName: "other/library", - CanonicalName: "docker.io/other/library", - Official: false, - }, - "127.0.0.1:8000/private/moonbase": { - Index: ®istrytypes.IndexInfo{ - Name: "127.0.0.1:8000", - Official: false, - }, - RemoteName: "private/moonbase", - LocalName: "127.0.0.1:8000/private/moonbase", - CanonicalName: "127.0.0.1:8000/private/moonbase", - Official: false, - }, - "127.0.0.1:8000/privatebase": { - Index: ®istrytypes.IndexInfo{ - Name: "127.0.0.1:8000", - Official: false, - }, - RemoteName: "privatebase", - LocalName: "127.0.0.1:8000/privatebase", - CanonicalName: "127.0.0.1:8000/privatebase", - Official: false, - }, - "localhost:8000/private/moonbase": { - Index: ®istrytypes.IndexInfo{ - Name: "localhost:8000", - Official: false, - }, - RemoteName: "private/moonbase", - LocalName: "localhost:8000/private/moonbase", - CanonicalName: "localhost:8000/private/moonbase", - Official: false, - }, - "localhost:8000/privatebase": { - Index: ®istrytypes.IndexInfo{ - Name: "localhost:8000", - Official: false, - }, - RemoteName: "privatebase", - LocalName: "localhost:8000/privatebase", - CanonicalName: "localhost:8000/privatebase", - Official: false, - }, - "example.com/private/moonbase": { - Index: ®istrytypes.IndexInfo{ - Name: "example.com", - Official: false, - }, - RemoteName: "private/moonbase", - LocalName: "example.com/private/moonbase", - CanonicalName: "example.com/private/moonbase", - Official: false, - }, - "example.com/privatebase": { - Index: ®istrytypes.IndexInfo{ - Name: "example.com", - Official: false, - }, - RemoteName: "privatebase", - LocalName: "example.com/privatebase", - CanonicalName: "example.com/privatebase", - Official: false, - }, - "example.com:8000/private/moonbase": { - Index: ®istrytypes.IndexInfo{ - Name: "example.com:8000", - Official: false, - }, - RemoteName: "private/moonbase", - LocalName: "example.com:8000/private/moonbase", - CanonicalName: "example.com:8000/private/moonbase", - Official: false, - }, - "example.com:8000/privatebase": { - Index: ®istrytypes.IndexInfo{ - Name: "example.com:8000", - Official: false, - }, - RemoteName: "privatebase", - LocalName: "example.com:8000/privatebase", - CanonicalName: "example.com:8000/privatebase", - Official: false, - }, - "localhost/private/moonbase": { - Index: ®istrytypes.IndexInfo{ - Name: "localhost", - Official: false, - }, - RemoteName: "private/moonbase", - LocalName: "localhost/private/moonbase", - CanonicalName: "localhost/private/moonbase", - Official: false, - }, - "localhost/privatebase": { - Index: ®istrytypes.IndexInfo{ - Name: "localhost", - Official: false, - }, - RemoteName: "privatebase", - LocalName: "localhost/privatebase", - CanonicalName: "localhost/privatebase", - Official: false, - }, - IndexName + "/public/moonbase": { - Index: ®istrytypes.IndexInfo{ - Name: IndexName, - Official: true, - }, - RemoteName: "public/moonbase", - LocalName: "public/moonbase", - CanonicalName: "docker.io/public/moonbase", - Official: false, - }, - "index." + IndexName + "/public/moonbase": { - Index: ®istrytypes.IndexInfo{ - Name: IndexName, - Official: true, - }, - RemoteName: "public/moonbase", - LocalName: "public/moonbase", - CanonicalName: "docker.io/public/moonbase", - Official: false, - }, - "ubuntu-12.04-base": { - Index: ®istrytypes.IndexInfo{ - Name: IndexName, - Official: true, - }, - RemoteName: "library/ubuntu-12.04-base", - LocalName: "ubuntu-12.04-base", - CanonicalName: "docker.io/library/ubuntu-12.04-base", - Official: true, - }, - IndexName + "/ubuntu-12.04-base": { - Index: ®istrytypes.IndexInfo{ - Name: IndexName, - Official: true, - }, - RemoteName: "library/ubuntu-12.04-base", - LocalName: "ubuntu-12.04-base", - CanonicalName: "docker.io/library/ubuntu-12.04-base", - Official: true, - }, - "index." + IndexName + "/ubuntu-12.04-base": { - Index: ®istrytypes.IndexInfo{ - Name: IndexName, - Official: true, - }, - RemoteName: "library/ubuntu-12.04-base", - LocalName: "ubuntu-12.04-base", - CanonicalName: "docker.io/library/ubuntu-12.04-base", - Official: true, - }, - } - - for reposName, expectedRepoInfo := range expectedRepoInfos { - named, err := reference.WithName(reposName) - if err != nil { - t.Error(err) - } - - repoInfo, err := ParseRepositoryInfo(named) - if err != nil { - t.Error(err) - } else { - checkEqual(t, repoInfo.Index.Name, expectedRepoInfo.Index.Name, reposName) - checkEqual(t, repoInfo.RemoteName(), expectedRepoInfo.RemoteName, reposName) - checkEqual(t, repoInfo.Name(), expectedRepoInfo.LocalName, reposName) - checkEqual(t, repoInfo.FullName(), expectedRepoInfo.CanonicalName, reposName) - checkEqual(t, repoInfo.Index.Official, expectedRepoInfo.Index.Official, reposName) - checkEqual(t, repoInfo.Official, expectedRepoInfo.Official, reposName) - } - } -} - -func TestNewIndexInfo(t *testing.T) { - testIndexInfo := func(config *serviceConfig, expectedIndexInfos map[string]*registrytypes.IndexInfo) { - for indexName, expectedIndexInfo := range expectedIndexInfos { - index, err := newIndexInfo(config, indexName) - if err != nil { - t.Fatal(err) - } else { - checkEqual(t, index.Name, expectedIndexInfo.Name, indexName+" name") - checkEqual(t, index.Official, expectedIndexInfo.Official, indexName+" is official") - checkEqual(t, index.Secure, expectedIndexInfo.Secure, indexName+" is secure") - checkEqual(t, len(index.Mirrors), len(expectedIndexInfo.Mirrors), indexName+" mirrors") - } - } - } - - config := newServiceConfig(ServiceOptions{}) - noMirrors := []string{} - expectedIndexInfos := map[string]*registrytypes.IndexInfo{ - IndexName: { - Name: IndexName, - Official: true, - Secure: true, - Mirrors: noMirrors, - }, - "index." + IndexName: { - Name: IndexName, - Official: true, - Secure: true, - Mirrors: noMirrors, - }, - "example.com": { - Name: "example.com", - Official: false, - Secure: true, - Mirrors: noMirrors, - }, - "127.0.0.1:5000": { - Name: "127.0.0.1:5000", - Official: false, - Secure: false, - Mirrors: noMirrors, - }, - } - testIndexInfo(config, expectedIndexInfos) - - publicMirrors := []string{"http://mirror1.local", "http://mirror2.local"} - config = makeServiceConfig(publicMirrors, []string{"example.com"}) - - expectedIndexInfos = map[string]*registrytypes.IndexInfo{ - IndexName: { - Name: IndexName, - Official: true, - Secure: true, - Mirrors: publicMirrors, - }, - "index." + IndexName: { - Name: IndexName, - Official: true, - Secure: true, - Mirrors: publicMirrors, - }, - "example.com": { - Name: "example.com", - Official: false, - Secure: false, - Mirrors: noMirrors, - }, - "example.com:5000": { - Name: "example.com:5000", - Official: false, - Secure: true, - Mirrors: noMirrors, - }, - "127.0.0.1": { - Name: "127.0.0.1", - Official: false, - Secure: false, - Mirrors: noMirrors, - }, - "127.0.0.1:5000": { - Name: "127.0.0.1:5000", - Official: false, - Secure: false, - Mirrors: noMirrors, - }, - "other.com": { - Name: "other.com", - Official: false, - Secure: true, - Mirrors: noMirrors, - }, - } - testIndexInfo(config, expectedIndexInfos) - - config = makeServiceConfig(nil, []string{"42.42.0.0/16"}) - expectedIndexInfos = map[string]*registrytypes.IndexInfo{ - "example.com": { - Name: "example.com", - Official: false, - Secure: false, - Mirrors: noMirrors, - }, - "example.com:5000": { - Name: "example.com:5000", - Official: false, - Secure: false, - Mirrors: noMirrors, - }, - "127.0.0.1": { - Name: "127.0.0.1", - Official: false, - Secure: false, - Mirrors: noMirrors, - }, - "127.0.0.1:5000": { - Name: "127.0.0.1:5000", - Official: false, - Secure: false, - Mirrors: noMirrors, - }, - "other.com": { - Name: "other.com", - Official: false, - Secure: true, - Mirrors: noMirrors, - }, - } - testIndexInfo(config, expectedIndexInfos) -} - -func TestMirrorEndpointLookup(t *testing.T) { - containsMirror := func(endpoints []APIEndpoint) bool { - for _, pe := range endpoints { - if pe.URL.Host == "my.mirror" { - return true - } - } - return false - } - s := DefaultService{config: makeServiceConfig([]string{"my.mirror"}, nil)} - - imageName, err := reference.WithName(IndexName + "/test/image") - if err != nil { - t.Error(err) - } - pushAPIEndpoints, err := s.LookupPushEndpoints(imageName.Hostname()) - if err != nil { - t.Fatal(err) - } - if containsMirror(pushAPIEndpoints) { - t.Fatal("Push endpoint should not contain mirror") - } - - pullAPIEndpoints, err := s.LookupPullEndpoints(imageName.Hostname()) - if err != nil { - t.Fatal(err) - } - if !containsMirror(pullAPIEndpoints) { - t.Fatal("Pull endpoint should contain mirror") - } -} - -func TestPushRegistryTag(t *testing.T) { - r := spawnTestRegistrySession(t) - repoRef, err := reference.ParseNamed(REPO) - if err != nil { - t.Fatal(err) - } - err = r.PushRegistryTag(repoRef, imageID, "stable", makeURL("/v1/")) - if err != nil { - t.Fatal(err) - } -} - -func TestPushImageJSONIndex(t *testing.T) { - r := spawnTestRegistrySession(t) - imgData := []*ImgData{ - { - ID: "77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20", - Checksum: "sha256:1ac330d56e05eef6d438586545ceff7550d3bdcb6b19961f12c5ba714ee1bb37", - }, - { - ID: "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d", - Checksum: "sha256:bea7bf2e4bacd479344b737328db47b18880d09096e6674165533aa994f5e9f2", - }, - } - repoRef, err := reference.ParseNamed(REPO) - if err != nil { - t.Fatal(err) - } - repoData, err := r.PushImageJSONIndex(repoRef, imgData, false, nil) - if err != nil { - t.Fatal(err) - } - if repoData == nil { - t.Fatal("Expected RepositoryData object") - } - repoData, err = r.PushImageJSONIndex(repoRef, imgData, true, []string{r.indexEndpoint.String()}) - if err != nil { - t.Fatal(err) - } - if repoData == nil { - t.Fatal("Expected RepositoryData object") - } -} - -func TestSearchRepositories(t *testing.T) { - r := spawnTestRegistrySession(t) - results, err := r.SearchRepositories("fakequery", 25) - if err != nil { - t.Fatal(err) - } - if results == nil { - t.Fatal("Expected non-nil SearchResults object") - } - assertEqual(t, results.NumResults, 1, "Expected 1 search results") - assertEqual(t, results.Query, "fakequery", "Expected 'fakequery' as query") - assertEqual(t, results.Results[0].StarCount, 42, "Expected 'fakeimage' to have 42 stars") -} - -func TestTrustedLocation(t *testing.T) { - for _, url := range []string{"http://example.com", "https://example.com:7777", "http://docker.io", "http://test.docker.com", "https://fakedocker.com"} { - req, _ := http.NewRequest("GET", url, nil) - if trustedLocation(req) == true { - t.Fatalf("'%s' shouldn't be detected as a trusted location", url) - } - } - - for _, url := range []string{"https://docker.io", "https://test.docker.com:80"} { - req, _ := http.NewRequest("GET", url, nil) - if trustedLocation(req) == false { - t.Fatalf("'%s' should be detected as a trusted location", url) - } - } -} - -func TestAddRequiredHeadersToRedirectedRequests(t *testing.T) { - for _, urls := range [][]string{ - {"http://docker.io", "https://docker.com"}, - {"https://foo.docker.io:7777", "http://bar.docker.com"}, - {"https://foo.docker.io", "https://example.com"}, - } { - reqFrom, _ := http.NewRequest("GET", urls[0], nil) - reqFrom.Header.Add("Content-Type", "application/json") - reqFrom.Header.Add("Authorization", "super_secret") - reqTo, _ := http.NewRequest("GET", urls[1], nil) - - addRequiredHeadersToRedirectedRequests(reqTo, []*http.Request{reqFrom}) - - if len(reqTo.Header) != 1 { - t.Fatalf("Expected 1 headers, got %d", len(reqTo.Header)) - } - - if reqTo.Header.Get("Content-Type") != "application/json" { - t.Fatal("'Content-Type' should be 'application/json'") - } - - if reqTo.Header.Get("Authorization") != "" { - t.Fatal("'Authorization' should be empty") - } - } - - for _, urls := range [][]string{ - {"https://docker.io", "https://docker.com"}, - {"https://foo.docker.io:7777", "https://bar.docker.com"}, - } { - reqFrom, _ := http.NewRequest("GET", urls[0], nil) - reqFrom.Header.Add("Content-Type", "application/json") - reqFrom.Header.Add("Authorization", "super_secret") - reqTo, _ := http.NewRequest("GET", urls[1], nil) - - addRequiredHeadersToRedirectedRequests(reqTo, []*http.Request{reqFrom}) - - if len(reqTo.Header) != 2 { - t.Fatalf("Expected 2 headers, got %d", len(reqTo.Header)) - } - - if reqTo.Header.Get("Content-Type") != "application/json" { - t.Fatal("'Content-Type' should be 'application/json'") - } - - if reqTo.Header.Get("Authorization") != "super_secret" { - t.Fatal("'Authorization' should be 'super_secret'") - } - } -} - -func TestIsSecureIndex(t *testing.T) { - tests := []struct { - addr string - insecureRegistries []string - expected bool - }{ - {IndexName, nil, true}, - {"example.com", []string{}, true}, - {"example.com", []string{"example.com"}, false}, - {"localhost", []string{"localhost:5000"}, false}, - {"localhost:5000", []string{"localhost:5000"}, false}, - {"localhost", []string{"example.com"}, false}, - {"127.0.0.1:5000", []string{"127.0.0.1:5000"}, false}, - {"localhost", nil, false}, - {"localhost:5000", nil, false}, - {"127.0.0.1", nil, false}, - {"localhost", []string{"example.com"}, false}, - {"127.0.0.1", []string{"example.com"}, false}, - {"example.com", nil, true}, - {"example.com", []string{"example.com"}, false}, - {"127.0.0.1", []string{"example.com"}, false}, - {"127.0.0.1:5000", []string{"example.com"}, false}, - {"example.com:5000", []string{"42.42.0.0/16"}, false}, - {"example.com", []string{"42.42.0.0/16"}, false}, - {"example.com:5000", []string{"42.42.42.42/8"}, false}, - {"127.0.0.1:5000", []string{"127.0.0.0/8"}, false}, - {"42.42.42.42:5000", []string{"42.1.1.1/8"}, false}, - {"invalid.domain.com", []string{"42.42.0.0/16"}, true}, - {"invalid.domain.com", []string{"invalid.domain.com"}, false}, - {"invalid.domain.com:5000", []string{"invalid.domain.com"}, true}, - {"invalid.domain.com:5000", []string{"invalid.domain.com:5000"}, false}, - } - for _, tt := range tests { - config := makeServiceConfig(nil, tt.insecureRegistries) - if sec := isSecureIndex(config, tt.addr); sec != tt.expected { - t.Errorf("isSecureIndex failed for %q %v, expected %v got %v", tt.addr, tt.insecureRegistries, tt.expected, sec) - } - } -} - -type debugTransport struct { - http.RoundTripper - log func(...interface{}) -} - -func (tr debugTransport) RoundTrip(req *http.Request) (*http.Response, error) { - dump, err := httputil.DumpRequestOut(req, false) - if err != nil { - tr.log("could not dump request") - } - tr.log(string(dump)) - resp, err := tr.RoundTripper.RoundTrip(req) - if err != nil { - return nil, err - } - dump, err = httputil.DumpResponse(resp, false) - if err != nil { - tr.log("could not dump response") - } - tr.log(string(dump)) - return resp, err -} diff --git a/vendor/github.com/docker/docker/registry/service.go b/vendor/github.com/docker/docker/registry/service.go deleted file mode 100644 index 596a9c7..0000000 --- a/vendor/github.com/docker/docker/registry/service.go +++ /dev/null @@ -1,304 +0,0 @@ -package registry - -import ( - "crypto/tls" - "fmt" - "net/http" - "net/url" - "strings" - "sync" - - "golang.org/x/net/context" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/registry/client/auth" - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/reference" -) - -const ( - // DefaultSearchLimit is the default value for maximum number of returned search results. - DefaultSearchLimit = 25 -) - -// Service is the interface defining what a registry service should implement. -type Service interface { - Auth(ctx context.Context, authConfig *types.AuthConfig, userAgent string) (status, token string, err error) - LookupPullEndpoints(hostname string) (endpoints []APIEndpoint, err error) - LookupPushEndpoints(hostname string) (endpoints []APIEndpoint, err error) - ResolveRepository(name reference.Named) (*RepositoryInfo, error) - Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error) - ServiceConfig() *registrytypes.ServiceConfig - TLSConfig(hostname string) (*tls.Config, error) - LoadInsecureRegistries([]string) error -} - -// DefaultService is a registry service. It tracks configuration data such as a list -// of mirrors. -type DefaultService struct { - config *serviceConfig - mu sync.Mutex -} - -// NewService returns a new instance of DefaultService ready to be -// installed into an engine. -func NewService(options ServiceOptions) *DefaultService { - return &DefaultService{ - config: newServiceConfig(options), - } -} - -// ServiceConfig returns the public registry service configuration. -func (s *DefaultService) ServiceConfig() *registrytypes.ServiceConfig { - s.mu.Lock() - defer s.mu.Unlock() - - servConfig := registrytypes.ServiceConfig{ - InsecureRegistryCIDRs: make([]*(registrytypes.NetIPNet), 0), - IndexConfigs: make(map[string]*(registrytypes.IndexInfo)), - Mirrors: make([]string, 0), - } - - // construct a new ServiceConfig which will not retrieve s.Config directly, - // and look up items in s.config with mu locked - servConfig.InsecureRegistryCIDRs = append(servConfig.InsecureRegistryCIDRs, s.config.ServiceConfig.InsecureRegistryCIDRs...) - - for key, value := range s.config.ServiceConfig.IndexConfigs { - servConfig.IndexConfigs[key] = value - } - - servConfig.Mirrors = append(servConfig.Mirrors, s.config.ServiceConfig.Mirrors...) - - return &servConfig -} - -// LoadInsecureRegistries loads insecure registries for Service -func (s *DefaultService) LoadInsecureRegistries(registries []string) error { - s.mu.Lock() - defer s.mu.Unlock() - - return s.config.LoadInsecureRegistries(registries) -} - -// Auth contacts the public registry with the provided credentials, -// and returns OK if authentication was successful. -// It can be used to verify the validity of a client's credentials. -func (s *DefaultService) Auth(ctx context.Context, authConfig *types.AuthConfig, userAgent string) (status, token string, err error) { - // TODO Use ctx when searching for repositories - serverAddress := authConfig.ServerAddress - if serverAddress == "" { - serverAddress = IndexServer - } - if !strings.HasPrefix(serverAddress, "https://") && !strings.HasPrefix(serverAddress, "http://") { - serverAddress = "https://" + serverAddress - } - u, err := url.Parse(serverAddress) - if err != nil { - return "", "", fmt.Errorf("unable to parse server address: %v", err) - } - - endpoints, err := s.LookupPushEndpoints(u.Host) - if err != nil { - return "", "", err - } - - for _, endpoint := range endpoints { - login := loginV2 - if endpoint.Version == APIVersion1 { - login = loginV1 - } - - status, token, err = login(authConfig, endpoint, userAgent) - if err == nil { - return - } - if fErr, ok := err.(fallbackError); ok { - err = fErr.err - logrus.Infof("Error logging in to %s endpoint, trying next endpoint: %v", endpoint.Version, err) - continue - } - return "", "", err - } - - return "", "", err -} - -// splitReposSearchTerm breaks a search term into an index name and remote name -func splitReposSearchTerm(reposName string) (string, string) { - nameParts := strings.SplitN(reposName, "/", 2) - var indexName, remoteName string - if len(nameParts) == 1 || (!strings.Contains(nameParts[0], ".") && - !strings.Contains(nameParts[0], ":") && nameParts[0] != "localhost") { - // This is a Docker Index repos (ex: samalba/hipache or ubuntu) - // 'docker.io' - indexName = IndexName - remoteName = reposName - } else { - indexName = nameParts[0] - remoteName = nameParts[1] - } - return indexName, remoteName -} - -// Search queries the public registry for images matching the specified -// search terms, and returns the results. -func (s *DefaultService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error) { - // TODO Use ctx when searching for repositories - if err := validateNoScheme(term); err != nil { - return nil, err - } - - indexName, remoteName := splitReposSearchTerm(term) - - // Search is a long-running operation, just lock s.config to avoid block others. - s.mu.Lock() - index, err := newIndexInfo(s.config, indexName) - s.mu.Unlock() - - if err != nil { - return nil, err - } - - // *TODO: Search multiple indexes. - endpoint, err := NewV1Endpoint(index, userAgent, http.Header(headers)) - if err != nil { - return nil, err - } - - var client *http.Client - if authConfig != nil && authConfig.IdentityToken != "" && authConfig.Username != "" { - creds := NewStaticCredentialStore(authConfig) - scopes := []auth.Scope{ - auth.RegistryScope{ - Name: "catalog", - Actions: []string{"search"}, - }, - } - - modifiers := DockerHeaders(userAgent, nil) - v2Client, foundV2, err := v2AuthHTTPClient(endpoint.URL, endpoint.client.Transport, modifiers, creds, scopes) - if err != nil { - if fErr, ok := err.(fallbackError); ok { - logrus.Errorf("Cannot use identity token for search, v2 auth not supported: %v", fErr.err) - } else { - return nil, err - } - } else if foundV2 { - // Copy non transport http client features - v2Client.Timeout = endpoint.client.Timeout - v2Client.CheckRedirect = endpoint.client.CheckRedirect - v2Client.Jar = endpoint.client.Jar - - logrus.Debugf("using v2 client for search to %s", endpoint.URL) - client = v2Client - } - } - - if client == nil { - client = endpoint.client - if err := authorizeClient(client, authConfig, endpoint); err != nil { - return nil, err - } - } - - r := newSession(client, authConfig, endpoint) - - if index.Official { - localName := remoteName - if strings.HasPrefix(localName, "library/") { - // If pull "library/foo", it's stored locally under "foo" - localName = strings.SplitN(localName, "/", 2)[1] - } - - return r.SearchRepositories(localName, limit) - } - return r.SearchRepositories(remoteName, limit) -} - -// ResolveRepository splits a repository name into its components -// and configuration of the associated registry. -func (s *DefaultService) ResolveRepository(name reference.Named) (*RepositoryInfo, error) { - s.mu.Lock() - defer s.mu.Unlock() - return newRepositoryInfo(s.config, name) -} - -// APIEndpoint represents a remote API endpoint -type APIEndpoint struct { - Mirror bool - URL *url.URL - Version APIVersion - Official bool - TrimHostname bool - TLSConfig *tls.Config -} - -// ToV1Endpoint returns a V1 API endpoint based on the APIEndpoint -func (e APIEndpoint) ToV1Endpoint(userAgent string, metaHeaders http.Header) (*V1Endpoint, error) { - return newV1Endpoint(*e.URL, e.TLSConfig, userAgent, metaHeaders) -} - -// TLSConfig constructs a client TLS configuration based on server defaults -func (s *DefaultService) TLSConfig(hostname string) (*tls.Config, error) { - s.mu.Lock() - defer s.mu.Unlock() - - return newTLSConfig(hostname, isSecureIndex(s.config, hostname)) -} - -// tlsConfig constructs a client TLS configuration based on server defaults -func (s *DefaultService) tlsConfig(hostname string) (*tls.Config, error) { - return newTLSConfig(hostname, isSecureIndex(s.config, hostname)) -} - -func (s *DefaultService) tlsConfigForMirror(mirrorURL *url.URL) (*tls.Config, error) { - return s.tlsConfig(mirrorURL.Host) -} - -// LookupPullEndpoints creates a list of endpoints to try to pull from, in order of preference. -// It gives preference to v2 endpoints over v1, mirrors over the actual -// registry, and HTTPS over plain HTTP. -func (s *DefaultService) LookupPullEndpoints(hostname string) (endpoints []APIEndpoint, err error) { - s.mu.Lock() - defer s.mu.Unlock() - - return s.lookupEndpoints(hostname) -} - -// LookupPushEndpoints creates a list of endpoints to try to push to, in order of preference. -// It gives preference to v2 endpoints over v1, and HTTPS over plain HTTP. -// Mirrors are not included. -func (s *DefaultService) LookupPushEndpoints(hostname string) (endpoints []APIEndpoint, err error) { - s.mu.Lock() - defer s.mu.Unlock() - - allEndpoints, err := s.lookupEndpoints(hostname) - if err == nil { - for _, endpoint := range allEndpoints { - if !endpoint.Mirror { - endpoints = append(endpoints, endpoint) - } - } - } - return endpoints, err -} - -func (s *DefaultService) lookupEndpoints(hostname string) (endpoints []APIEndpoint, err error) { - endpoints, err = s.lookupV2Endpoints(hostname) - if err != nil { - return nil, err - } - - if s.config.V2Only { - return endpoints, nil - } - - legacyEndpoints, err := s.lookupV1Endpoints(hostname) - if err != nil { - return nil, err - } - endpoints = append(endpoints, legacyEndpoints...) - - return endpoints, nil -} diff --git a/vendor/github.com/docker/docker/registry/service_v1.go b/vendor/github.com/docker/docker/registry/service_v1.go deleted file mode 100644 index 1d251ae..0000000 --- a/vendor/github.com/docker/docker/registry/service_v1.go +++ /dev/null @@ -1,40 +0,0 @@ -package registry - -import "net/url" - -func (s *DefaultService) lookupV1Endpoints(hostname string) (endpoints []APIEndpoint, err error) { - if hostname == DefaultNamespace || hostname == DefaultV2Registry.Host || hostname == IndexHostname { - return []APIEndpoint{}, nil - } - - tlsConfig, err := s.tlsConfig(hostname) - if err != nil { - return nil, err - } - - endpoints = []APIEndpoint{ - { - URL: &url.URL{ - Scheme: "https", - Host: hostname, - }, - Version: APIVersion1, - TrimHostname: true, - TLSConfig: tlsConfig, - }, - } - - if tlsConfig.InsecureSkipVerify { - endpoints = append(endpoints, APIEndpoint{ // or this - URL: &url.URL{ - Scheme: "http", - Host: hostname, - }, - Version: APIVersion1, - TrimHostname: true, - // used to check if supposed to be secure via InsecureSkipVerify - TLSConfig: tlsConfig, - }) - } - return endpoints, nil -} diff --git a/vendor/github.com/docker/docker/registry/service_v1_test.go b/vendor/github.com/docker/docker/registry/service_v1_test.go deleted file mode 100644 index bd15dff..0000000 --- a/vendor/github.com/docker/docker/registry/service_v1_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package registry - -import "testing" - -func TestLookupV1Endpoints(t *testing.T) { - s := NewService(ServiceOptions{}) - - cases := []struct { - hostname string - expectedLen int - }{ - {"example.com", 1}, - {DefaultNamespace, 0}, - {DefaultV2Registry.Host, 0}, - {IndexHostname, 0}, - } - - for _, c := range cases { - if ret, err := s.lookupV1Endpoints(c.hostname); err != nil || len(ret) != c.expectedLen { - t.Errorf("lookupV1Endpoints(`"+c.hostname+"`) returned %+v and %+v", ret, err) - } - } -} diff --git a/vendor/github.com/docker/docker/registry/service_v2.go b/vendor/github.com/docker/docker/registry/service_v2.go deleted file mode 100644 index 228d745..0000000 --- a/vendor/github.com/docker/docker/registry/service_v2.go +++ /dev/null @@ -1,78 +0,0 @@ -package registry - -import ( - "net/url" - "strings" - - "github.com/docker/go-connections/tlsconfig" -) - -func (s *DefaultService) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, err error) { - tlsConfig := tlsconfig.ServerDefault() - if hostname == DefaultNamespace || hostname == IndexHostname { - // v2 mirrors - for _, mirror := range s.config.Mirrors { - if !strings.HasPrefix(mirror, "http://") && !strings.HasPrefix(mirror, "https://") { - mirror = "https://" + mirror - } - mirrorURL, err := url.Parse(mirror) - if err != nil { - return nil, err - } - mirrorTLSConfig, err := s.tlsConfigForMirror(mirrorURL) - if err != nil { - return nil, err - } - endpoints = append(endpoints, APIEndpoint{ - URL: mirrorURL, - // guess mirrors are v2 - Version: APIVersion2, - Mirror: true, - TrimHostname: true, - TLSConfig: mirrorTLSConfig, - }) - } - // v2 registry - endpoints = append(endpoints, APIEndpoint{ - URL: DefaultV2Registry, - Version: APIVersion2, - Official: true, - TrimHostname: true, - TLSConfig: tlsConfig, - }) - - return endpoints, nil - } - - tlsConfig, err = s.tlsConfig(hostname) - if err != nil { - return nil, err - } - - endpoints = []APIEndpoint{ - { - URL: &url.URL{ - Scheme: "https", - Host: hostname, - }, - Version: APIVersion2, - TrimHostname: true, - TLSConfig: tlsConfig, - }, - } - - if tlsConfig.InsecureSkipVerify { - endpoints = append(endpoints, APIEndpoint{ - URL: &url.URL{ - Scheme: "http", - Host: hostname, - }, - Version: APIVersion2, - TrimHostname: true, - // used to check if supposed to be secure via InsecureSkipVerify - TLSConfig: tlsConfig, - }) - } - - return endpoints, nil -} diff --git a/vendor/github.com/docker/docker/registry/session.go b/vendor/github.com/docker/docker/registry/session.go deleted file mode 100644 index 72e286a..0000000 --- a/vendor/github.com/docker/docker/registry/session.go +++ /dev/null @@ -1,783 +0,0 @@ -package registry - -import ( - "bytes" - "crypto/sha256" - "errors" - "sync" - // this is required for some certificates - _ "crypto/sha512" - "encoding/hex" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net/http" - "net/http/cookiejar" - "net/url" - "strconv" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/docker/api/types" - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/pkg/httputils" - "github.com/docker/docker/pkg/ioutils" - "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/tarsum" - "github.com/docker/docker/reference" -) - -var ( - // ErrRepoNotFound is returned if the repository didn't exist on the - // remote side - ErrRepoNotFound = errors.New("Repository not found") -) - -// A Session is used to communicate with a V1 registry -type Session struct { - indexEndpoint *V1Endpoint - client *http.Client - // TODO(tiborvass): remove authConfig - authConfig *types.AuthConfig - id string -} - -type authTransport struct { - http.RoundTripper - *types.AuthConfig - - alwaysSetBasicAuth bool - token []string - - mu sync.Mutex // guards modReq - modReq map[*http.Request]*http.Request // original -> modified -} - -// AuthTransport handles the auth layer when communicating with a v1 registry (private or official) -// -// For private v1 registries, set alwaysSetBasicAuth to true. -// -// For the official v1 registry, if there isn't already an Authorization header in the request, -// but there is an X-Docker-Token header set to true, then Basic Auth will be used to set the Authorization header. -// After sending the request with the provided base http.RoundTripper, if an X-Docker-Token header, representing -// a token, is present in the response, then it gets cached and sent in the Authorization header of all subsequent -// requests. -// -// If the server sends a token without the client having requested it, it is ignored. -// -// This RoundTripper also has a CancelRequest method important for correct timeout handling. -func AuthTransport(base http.RoundTripper, authConfig *types.AuthConfig, alwaysSetBasicAuth bool) http.RoundTripper { - if base == nil { - base = http.DefaultTransport - } - return &authTransport{ - RoundTripper: base, - AuthConfig: authConfig, - alwaysSetBasicAuth: alwaysSetBasicAuth, - modReq: make(map[*http.Request]*http.Request), - } -} - -// cloneRequest returns a clone of the provided *http.Request. -// The clone is a shallow copy of the struct and its Header map. -func cloneRequest(r *http.Request) *http.Request { - // shallow copy of the struct - r2 := new(http.Request) - *r2 = *r - // deep copy of the Header - r2.Header = make(http.Header, len(r.Header)) - for k, s := range r.Header { - r2.Header[k] = append([]string(nil), s...) - } - - return r2 -} - -// RoundTrip changes an HTTP request's headers to add the necessary -// authentication-related headers -func (tr *authTransport) RoundTrip(orig *http.Request) (*http.Response, error) { - // Authorization should not be set on 302 redirect for untrusted locations. - // This logic mirrors the behavior in addRequiredHeadersToRedirectedRequests. - // As the authorization logic is currently implemented in RoundTrip, - // a 302 redirect is detected by looking at the Referrer header as go http package adds said header. - // This is safe as Docker doesn't set Referrer in other scenarios. - if orig.Header.Get("Referer") != "" && !trustedLocation(orig) { - return tr.RoundTripper.RoundTrip(orig) - } - - req := cloneRequest(orig) - tr.mu.Lock() - tr.modReq[orig] = req - tr.mu.Unlock() - - if tr.alwaysSetBasicAuth { - if tr.AuthConfig == nil { - return nil, errors.New("unexpected error: empty auth config") - } - req.SetBasicAuth(tr.Username, tr.Password) - return tr.RoundTripper.RoundTrip(req) - } - - // Don't override - if req.Header.Get("Authorization") == "" { - if req.Header.Get("X-Docker-Token") == "true" && tr.AuthConfig != nil && len(tr.Username) > 0 { - req.SetBasicAuth(tr.Username, tr.Password) - } else if len(tr.token) > 0 { - req.Header.Set("Authorization", "Token "+strings.Join(tr.token, ",")) - } - } - resp, err := tr.RoundTripper.RoundTrip(req) - if err != nil { - delete(tr.modReq, orig) - return nil, err - } - if len(resp.Header["X-Docker-Token"]) > 0 { - tr.token = resp.Header["X-Docker-Token"] - } - resp.Body = &ioutils.OnEOFReader{ - Rc: resp.Body, - Fn: func() { - tr.mu.Lock() - delete(tr.modReq, orig) - tr.mu.Unlock() - }, - } - return resp, nil -} - -// CancelRequest cancels an in-flight request by closing its connection. -func (tr *authTransport) CancelRequest(req *http.Request) { - type canceler interface { - CancelRequest(*http.Request) - } - if cr, ok := tr.RoundTripper.(canceler); ok { - tr.mu.Lock() - modReq := tr.modReq[req] - delete(tr.modReq, req) - tr.mu.Unlock() - cr.CancelRequest(modReq) - } -} - -func authorizeClient(client *http.Client, authConfig *types.AuthConfig, endpoint *V1Endpoint) error { - var alwaysSetBasicAuth bool - - // If we're working with a standalone private registry over HTTPS, send Basic Auth headers - // alongside all our requests. - if endpoint.String() != IndexServer && endpoint.URL.Scheme == "https" { - info, err := endpoint.Ping() - if err != nil { - return err - } - if info.Standalone && authConfig != nil { - logrus.Debugf("Endpoint %s is eligible for private registry. Enabling decorator.", endpoint.String()) - alwaysSetBasicAuth = true - } - } - - // Annotate the transport unconditionally so that v2 can - // properly fallback on v1 when an image is not found. - client.Transport = AuthTransport(client.Transport, authConfig, alwaysSetBasicAuth) - - jar, err := cookiejar.New(nil) - if err != nil { - return errors.New("cookiejar.New is not supposed to return an error") - } - client.Jar = jar - - return nil -} - -func newSession(client *http.Client, authConfig *types.AuthConfig, endpoint *V1Endpoint) *Session { - return &Session{ - authConfig: authConfig, - client: client, - indexEndpoint: endpoint, - id: stringid.GenerateRandomID(), - } -} - -// NewSession creates a new session -// TODO(tiborvass): remove authConfig param once registry client v2 is vendored -func NewSession(client *http.Client, authConfig *types.AuthConfig, endpoint *V1Endpoint) (*Session, error) { - if err := authorizeClient(client, authConfig, endpoint); err != nil { - return nil, err - } - - return newSession(client, authConfig, endpoint), nil -} - -// ID returns this registry session's ID. -func (r *Session) ID() string { - return r.id -} - -// GetRemoteHistory retrieves the history of a given image from the registry. -// It returns a list of the parent's JSON files (including the requested image). -func (r *Session) GetRemoteHistory(imgID, registry string) ([]string, error) { - res, err := r.client.Get(registry + "images/" + imgID + "/ancestry") - if err != nil { - return nil, err - } - defer res.Body.Close() - if res.StatusCode != 200 { - if res.StatusCode == 401 { - return nil, errcode.ErrorCodeUnauthorized.WithArgs() - } - return nil, httputils.NewHTTPRequestError(fmt.Sprintf("Server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res) - } - - var history []string - if err := json.NewDecoder(res.Body).Decode(&history); err != nil { - return nil, fmt.Errorf("Error while reading the http response: %v", err) - } - - logrus.Debugf("Ancestry: %v", history) - return history, nil -} - -// LookupRemoteImage checks if an image exists in the registry -func (r *Session) LookupRemoteImage(imgID, registry string) error { - res, err := r.client.Get(registry + "images/" + imgID + "/json") - if err != nil { - return err - } - res.Body.Close() - if res.StatusCode != 200 { - return httputils.NewHTTPRequestError(fmt.Sprintf("HTTP code %d", res.StatusCode), res) - } - return nil -} - -// GetRemoteImageJSON retrieves an image's JSON metadata from the registry. -func (r *Session) GetRemoteImageJSON(imgID, registry string) ([]byte, int64, error) { - res, err := r.client.Get(registry + "images/" + imgID + "/json") - if err != nil { - return nil, -1, fmt.Errorf("Failed to download json: %s", err) - } - defer res.Body.Close() - if res.StatusCode != 200 { - return nil, -1, httputils.NewHTTPRequestError(fmt.Sprintf("HTTP code %d", res.StatusCode), res) - } - // if the size header is not present, then set it to '-1' - imageSize := int64(-1) - if hdr := res.Header.Get("X-Docker-Size"); hdr != "" { - imageSize, err = strconv.ParseInt(hdr, 10, 64) - if err != nil { - return nil, -1, err - } - } - - jsonString, err := ioutil.ReadAll(res.Body) - if err != nil { - return nil, -1, fmt.Errorf("Failed to parse downloaded json: %v (%s)", err, jsonString) - } - return jsonString, imageSize, nil -} - -// GetRemoteImageLayer retrieves an image layer from the registry -func (r *Session) GetRemoteImageLayer(imgID, registry string, imgSize int64) (io.ReadCloser, error) { - var ( - statusCode = 0 - res *http.Response - err error - imageURL = fmt.Sprintf("%simages/%s/layer", registry, imgID) - ) - - req, err := http.NewRequest("GET", imageURL, nil) - if err != nil { - return nil, fmt.Errorf("Error while getting from the server: %v", err) - } - statusCode = 0 - res, err = r.client.Do(req) - if err != nil { - logrus.Debugf("Error contacting registry %s: %v", registry, err) - // the only case err != nil && res != nil is https://golang.org/src/net/http/client.go#L515 - if res != nil { - if res.Body != nil { - res.Body.Close() - } - statusCode = res.StatusCode - } - return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)", - statusCode, imgID) - } - - if res.StatusCode != 200 { - res.Body.Close() - return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)", - res.StatusCode, imgID) - } - - if res.Header.Get("Accept-Ranges") == "bytes" && imgSize > 0 { - logrus.Debug("server supports resume") - return httputils.ResumableRequestReaderWithInitialResponse(r.client, req, 5, imgSize, res), nil - } - logrus.Debug("server doesn't support resume") - return res.Body, nil -} - -// GetRemoteTag retrieves the tag named in the askedTag argument from the given -// repository. It queries each of the registries supplied in the registries -// argument, and returns data from the first one that answers the query -// successfully. -func (r *Session) GetRemoteTag(registries []string, repositoryRef reference.Named, askedTag string) (string, error) { - repository := repositoryRef.RemoteName() - - if strings.Count(repository, "/") == 0 { - // This will be removed once the registry supports auto-resolution on - // the "library" namespace - repository = "library/" + repository - } - for _, host := range registries { - endpoint := fmt.Sprintf("%srepositories/%s/tags/%s", host, repository, askedTag) - res, err := r.client.Get(endpoint) - if err != nil { - return "", err - } - - logrus.Debugf("Got status code %d from %s", res.StatusCode, endpoint) - defer res.Body.Close() - - if res.StatusCode == 404 { - return "", ErrRepoNotFound - } - if res.StatusCode != 200 { - continue - } - - var tagID string - if err := json.NewDecoder(res.Body).Decode(&tagID); err != nil { - return "", err - } - return tagID, nil - } - return "", fmt.Errorf("Could not reach any registry endpoint") -} - -// GetRemoteTags retrieves all tags from the given repository. It queries each -// of the registries supplied in the registries argument, and returns data from -// the first one that answers the query successfully. It returns a map with -// tag names as the keys and image IDs as the values. -func (r *Session) GetRemoteTags(registries []string, repositoryRef reference.Named) (map[string]string, error) { - repository := repositoryRef.RemoteName() - - if strings.Count(repository, "/") == 0 { - // This will be removed once the registry supports auto-resolution on - // the "library" namespace - repository = "library/" + repository - } - for _, host := range registries { - endpoint := fmt.Sprintf("%srepositories/%s/tags", host, repository) - res, err := r.client.Get(endpoint) - if err != nil { - return nil, err - } - - logrus.Debugf("Got status code %d from %s", res.StatusCode, endpoint) - defer res.Body.Close() - - if res.StatusCode == 404 { - return nil, ErrRepoNotFound - } - if res.StatusCode != 200 { - continue - } - - result := make(map[string]string) - if err := json.NewDecoder(res.Body).Decode(&result); err != nil { - return nil, err - } - return result, nil - } - return nil, fmt.Errorf("Could not reach any registry endpoint") -} - -func buildEndpointsList(headers []string, indexEp string) ([]string, error) { - var endpoints []string - parsedURL, err := url.Parse(indexEp) - if err != nil { - return nil, err - } - var urlScheme = parsedURL.Scheme - // The registry's URL scheme has to match the Index' - for _, ep := range headers { - epList := strings.Split(ep, ",") - for _, epListElement := range epList { - endpoints = append( - endpoints, - fmt.Sprintf("%s://%s/v1/", urlScheme, strings.TrimSpace(epListElement))) - } - } - return endpoints, nil -} - -// GetRepositoryData returns lists of images and endpoints for the repository -func (r *Session) GetRepositoryData(name reference.Named) (*RepositoryData, error) { - repositoryTarget := fmt.Sprintf("%srepositories/%s/images", r.indexEndpoint.String(), name.RemoteName()) - - logrus.Debugf("[registry] Calling GET %s", repositoryTarget) - - req, err := http.NewRequest("GET", repositoryTarget, nil) - if err != nil { - return nil, err - } - // this will set basic auth in r.client.Transport and send cached X-Docker-Token headers for all subsequent requests - req.Header.Set("X-Docker-Token", "true") - res, err := r.client.Do(req) - if err != nil { - // check if the error is because of i/o timeout - // and return a non-obtuse error message for users - // "Get https://index.docker.io/v1/repositories/library/busybox/images: i/o timeout" - // was a top search on the docker user forum - if isTimeout(err) { - return nil, fmt.Errorf("Network timed out while trying to connect to %s. You may want to check your internet connection or if you are behind a proxy.", repositoryTarget) - } - return nil, fmt.Errorf("Error while pulling image: %v", err) - } - defer res.Body.Close() - if res.StatusCode == 401 { - return nil, errcode.ErrorCodeUnauthorized.WithArgs() - } - // TODO: Right now we're ignoring checksums in the response body. - // In the future, we need to use them to check image validity. - if res.StatusCode == 404 { - return nil, httputils.NewHTTPRequestError(fmt.Sprintf("HTTP code: %d", res.StatusCode), res) - } else if res.StatusCode != 200 { - errBody, err := ioutil.ReadAll(res.Body) - if err != nil { - logrus.Debugf("Error reading response body: %s", err) - } - return nil, httputils.NewHTTPRequestError(fmt.Sprintf("Error: Status %d trying to pull repository %s: %q", res.StatusCode, name.RemoteName(), errBody), res) - } - - var endpoints []string - if res.Header.Get("X-Docker-Endpoints") != "" { - endpoints, err = buildEndpointsList(res.Header["X-Docker-Endpoints"], r.indexEndpoint.String()) - if err != nil { - return nil, err - } - } else { - // Assume the endpoint is on the same host - endpoints = append(endpoints, fmt.Sprintf("%s://%s/v1/", r.indexEndpoint.URL.Scheme, req.URL.Host)) - } - - remoteChecksums := []*ImgData{} - if err := json.NewDecoder(res.Body).Decode(&remoteChecksums); err != nil { - return nil, err - } - - // Forge a better object from the retrieved data - imgsData := make(map[string]*ImgData, len(remoteChecksums)) - for _, elem := range remoteChecksums { - imgsData[elem.ID] = elem - } - - return &RepositoryData{ - ImgList: imgsData, - Endpoints: endpoints, - }, nil -} - -// PushImageChecksumRegistry uploads checksums for an image -func (r *Session) PushImageChecksumRegistry(imgData *ImgData, registry string) error { - u := registry + "images/" + imgData.ID + "/checksum" - - logrus.Debugf("[registry] Calling PUT %s", u) - - req, err := http.NewRequest("PUT", u, nil) - if err != nil { - return err - } - req.Header.Set("X-Docker-Checksum", imgData.Checksum) - req.Header.Set("X-Docker-Checksum-Payload", imgData.ChecksumPayload) - - res, err := r.client.Do(req) - if err != nil { - return fmt.Errorf("Failed to upload metadata: %v", err) - } - defer res.Body.Close() - if len(res.Cookies()) > 0 { - r.client.Jar.SetCookies(req.URL, res.Cookies()) - } - if res.StatusCode != 200 { - errBody, err := ioutil.ReadAll(res.Body) - if err != nil { - return fmt.Errorf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err) - } - var jsonBody map[string]string - if err := json.Unmarshal(errBody, &jsonBody); err != nil { - errBody = []byte(err.Error()) - } else if jsonBody["error"] == "Image already exists" { - return ErrAlreadyExists - } - return fmt.Errorf("HTTP code %d while uploading metadata: %q", res.StatusCode, errBody) - } - return nil -} - -// PushImageJSONRegistry pushes JSON metadata for a local image to the registry -func (r *Session) PushImageJSONRegistry(imgData *ImgData, jsonRaw []byte, registry string) error { - - u := registry + "images/" + imgData.ID + "/json" - - logrus.Debugf("[registry] Calling PUT %s", u) - - req, err := http.NewRequest("PUT", u, bytes.NewReader(jsonRaw)) - if err != nil { - return err - } - req.Header.Add("Content-type", "application/json") - - res, err := r.client.Do(req) - if err != nil { - return fmt.Errorf("Failed to upload metadata: %s", err) - } - defer res.Body.Close() - if res.StatusCode == 401 && strings.HasPrefix(registry, "http://") { - return httputils.NewHTTPRequestError("HTTP code 401, Docker will not send auth headers over HTTP.", res) - } - if res.StatusCode != 200 { - errBody, err := ioutil.ReadAll(res.Body) - if err != nil { - return httputils.NewHTTPRequestError(fmt.Sprintf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err), res) - } - var jsonBody map[string]string - if err := json.Unmarshal(errBody, &jsonBody); err != nil { - errBody = []byte(err.Error()) - } else if jsonBody["error"] == "Image already exists" { - return ErrAlreadyExists - } - return httputils.NewHTTPRequestError(fmt.Sprintf("HTTP code %d while uploading metadata: %q", res.StatusCode, errBody), res) - } - return nil -} - -// PushImageLayerRegistry sends the checksum of an image layer to the registry -func (r *Session) PushImageLayerRegistry(imgID string, layer io.Reader, registry string, jsonRaw []byte) (checksum string, checksumPayload string, err error) { - u := registry + "images/" + imgID + "/layer" - - logrus.Debugf("[registry] Calling PUT %s", u) - - tarsumLayer, err := tarsum.NewTarSum(layer, false, tarsum.Version0) - if err != nil { - return "", "", err - } - h := sha256.New() - h.Write(jsonRaw) - h.Write([]byte{'\n'}) - checksumLayer := io.TeeReader(tarsumLayer, h) - - req, err := http.NewRequest("PUT", u, checksumLayer) - if err != nil { - return "", "", err - } - req.Header.Add("Content-Type", "application/octet-stream") - req.ContentLength = -1 - req.TransferEncoding = []string{"chunked"} - res, err := r.client.Do(req) - if err != nil { - return "", "", fmt.Errorf("Failed to upload layer: %v", err) - } - if rc, ok := layer.(io.Closer); ok { - if err := rc.Close(); err != nil { - return "", "", err - } - } - defer res.Body.Close() - - if res.StatusCode != 200 { - errBody, err := ioutil.ReadAll(res.Body) - if err != nil { - return "", "", httputils.NewHTTPRequestError(fmt.Sprintf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err), res) - } - return "", "", httputils.NewHTTPRequestError(fmt.Sprintf("Received HTTP code %d while uploading layer: %q", res.StatusCode, errBody), res) - } - - checksumPayload = "sha256:" + hex.EncodeToString(h.Sum(nil)) - return tarsumLayer.Sum(jsonRaw), checksumPayload, nil -} - -// PushRegistryTag pushes a tag on the registry. -// Remote has the format '/ -func (r *Session) PushRegistryTag(remote reference.Named, revision, tag, registry string) error { - // "jsonify" the string - revision = "\"" + revision + "\"" - path := fmt.Sprintf("repositories/%s/tags/%s", remote.RemoteName(), tag) - - req, err := http.NewRequest("PUT", registry+path, strings.NewReader(revision)) - if err != nil { - return err - } - req.Header.Add("Content-type", "application/json") - req.ContentLength = int64(len(revision)) - res, err := r.client.Do(req) - if err != nil { - return err - } - res.Body.Close() - if res.StatusCode != 200 && res.StatusCode != 201 { - return httputils.NewHTTPRequestError(fmt.Sprintf("Internal server error: %d trying to push tag %s on %s", res.StatusCode, tag, remote.RemoteName()), res) - } - return nil -} - -// PushImageJSONIndex uploads an image list to the repository -func (r *Session) PushImageJSONIndex(remote reference.Named, imgList []*ImgData, validate bool, regs []string) (*RepositoryData, error) { - cleanImgList := []*ImgData{} - if validate { - for _, elem := range imgList { - if elem.Checksum != "" { - cleanImgList = append(cleanImgList, elem) - } - } - } else { - cleanImgList = imgList - } - - imgListJSON, err := json.Marshal(cleanImgList) - if err != nil { - return nil, err - } - var suffix string - if validate { - suffix = "images" - } - u := fmt.Sprintf("%srepositories/%s/%s", r.indexEndpoint.String(), remote.RemoteName(), suffix) - logrus.Debugf("[registry] PUT %s", u) - logrus.Debugf("Image list pushed to index:\n%s", imgListJSON) - headers := map[string][]string{ - "Content-type": {"application/json"}, - // this will set basic auth in r.client.Transport and send cached X-Docker-Token headers for all subsequent requests - "X-Docker-Token": {"true"}, - } - if validate { - headers["X-Docker-Endpoints"] = regs - } - - // Redirect if necessary - var res *http.Response - for { - if res, err = r.putImageRequest(u, headers, imgListJSON); err != nil { - return nil, err - } - if !shouldRedirect(res) { - break - } - res.Body.Close() - u = res.Header.Get("Location") - logrus.Debugf("Redirected to %s", u) - } - defer res.Body.Close() - - if res.StatusCode == 401 { - return nil, errcode.ErrorCodeUnauthorized.WithArgs() - } - - var tokens, endpoints []string - if !validate { - if res.StatusCode != 200 && res.StatusCode != 201 { - errBody, err := ioutil.ReadAll(res.Body) - if err != nil { - logrus.Debugf("Error reading response body: %s", err) - } - return nil, httputils.NewHTTPRequestError(fmt.Sprintf("Error: Status %d trying to push repository %s: %q", res.StatusCode, remote.RemoteName(), errBody), res) - } - tokens = res.Header["X-Docker-Token"] - logrus.Debugf("Auth token: %v", tokens) - - if res.Header.Get("X-Docker-Endpoints") == "" { - return nil, fmt.Errorf("Index response didn't contain any endpoints") - } - endpoints, err = buildEndpointsList(res.Header["X-Docker-Endpoints"], r.indexEndpoint.String()) - if err != nil { - return nil, err - } - } else { - if res.StatusCode != 204 { - errBody, err := ioutil.ReadAll(res.Body) - if err != nil { - logrus.Debugf("Error reading response body: %s", err) - } - return nil, httputils.NewHTTPRequestError(fmt.Sprintf("Error: Status %d trying to push checksums %s: %q", res.StatusCode, remote.RemoteName(), errBody), res) - } - } - - return &RepositoryData{ - Endpoints: endpoints, - }, nil -} - -func (r *Session) putImageRequest(u string, headers map[string][]string, body []byte) (*http.Response, error) { - req, err := http.NewRequest("PUT", u, bytes.NewReader(body)) - if err != nil { - return nil, err - } - req.ContentLength = int64(len(body)) - for k, v := range headers { - req.Header[k] = v - } - response, err := r.client.Do(req) - if err != nil { - return nil, err - } - return response, nil -} - -func shouldRedirect(response *http.Response) bool { - return response.StatusCode >= 300 && response.StatusCode < 400 -} - -// SearchRepositories performs a search against the remote repository -func (r *Session) SearchRepositories(term string, limit int) (*registrytypes.SearchResults, error) { - if limit < 1 || limit > 100 { - return nil, fmt.Errorf("Limit %d is outside the range of [1, 100]", limit) - } - logrus.Debugf("Index server: %s", r.indexEndpoint) - u := r.indexEndpoint.String() + "search?q=" + url.QueryEscape(term) + "&n=" + url.QueryEscape(fmt.Sprintf("%d", limit)) - - req, err := http.NewRequest("GET", u, nil) - if err != nil { - return nil, fmt.Errorf("Error while getting from the server: %v", err) - } - // Have the AuthTransport send authentication, when logged in. - req.Header.Set("X-Docker-Token", "true") - res, err := r.client.Do(req) - if err != nil { - return nil, err - } - defer res.Body.Close() - if res.StatusCode != 200 { - return nil, httputils.NewHTTPRequestError(fmt.Sprintf("Unexpected status code %d", res.StatusCode), res) - } - result := new(registrytypes.SearchResults) - return result, json.NewDecoder(res.Body).Decode(result) -} - -// GetAuthConfig returns the authentication settings for a session -// TODO(tiborvass): remove this once registry client v2 is vendored -func (r *Session) GetAuthConfig(withPasswd bool) *types.AuthConfig { - password := "" - if withPasswd { - password = r.authConfig.Password - } - return &types.AuthConfig{ - Username: r.authConfig.Username, - Password: password, - } -} - -func isTimeout(err error) bool { - type timeout interface { - Timeout() bool - } - e := err - switch urlErr := err.(type) { - case *url.Error: - e = urlErr.Err - } - t, ok := e.(timeout) - return ok && t.Timeout() -} diff --git a/vendor/github.com/docker/docker/registry/types.go b/vendor/github.com/docker/docker/registry/types.go deleted file mode 100644 index 49c123a..0000000 --- a/vendor/github.com/docker/docker/registry/types.go +++ /dev/null @@ -1,73 +0,0 @@ -package registry - -import ( - registrytypes "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/reference" -) - -// RepositoryData tracks the image list, list of endpoints, and list of tokens -// for a repository -type RepositoryData struct { - // ImgList is a list of images in the repository - ImgList map[string]*ImgData - // Endpoints is a list of endpoints returned in X-Docker-Endpoints - Endpoints []string - // Tokens is currently unused (remove it?) - Tokens []string -} - -// ImgData is used to transfer image checksums to and from the registry -type ImgData struct { - // ID is an opaque string that identifies the image - ID string `json:"id"` - Checksum string `json:"checksum,omitempty"` - ChecksumPayload string `json:"-"` - Tag string `json:",omitempty"` -} - -// PingResult contains the information returned when pinging a registry. It -// indicates the registry's version and whether the registry claims to be a -// standalone registry. -type PingResult struct { - // Version is the registry version supplied by the registry in an HTTP - // header - Version string `json:"version"` - // Standalone is set to true if the registry indicates it is a - // standalone registry in the X-Docker-Registry-Standalone - // header - Standalone bool `json:"standalone"` -} - -// APIVersion is an integral representation of an API version (presently -// either 1 or 2) -type APIVersion int - -func (av APIVersion) String() string { - return apiVersions[av] -} - -// API Version identifiers. -const ( - _ = iota - APIVersion1 APIVersion = iota - APIVersion2 -) - -var apiVersions = map[APIVersion]string{ - APIVersion1: "v1", - APIVersion2: "v2", -} - -// RepositoryInfo describes a repository -type RepositoryInfo struct { - reference.Named - // Index points to registry information - Index *registrytypes.IndexInfo - // Official indicates whether the repository is considered official. - // If the registry is official, and the normalized name does not - // contain a '/' (e.g. "foo"), then it is considered an official repo. - Official bool - // Class represents the class of the repository, such as "plugin" - // or "image". - Class string -} diff --git a/vendor/github.com/docker/docker/restartmanager/restartmanager.go b/vendor/github.com/docker/docker/restartmanager/restartmanager.go deleted file mode 100644 index 570fc93..0000000 --- a/vendor/github.com/docker/docker/restartmanager/restartmanager.go +++ /dev/null @@ -1,128 +0,0 @@ -package restartmanager - -import ( - "errors" - "fmt" - "sync" - "time" - - "github.com/docker/docker/api/types/container" -) - -const ( - backoffMultiplier = 2 - defaultTimeout = 100 * time.Millisecond -) - -// ErrRestartCanceled is returned when the restart manager has been -// canceled and will no longer restart the container. -var ErrRestartCanceled = errors.New("restart canceled") - -// RestartManager defines object that controls container restarting rules. -type RestartManager interface { - Cancel() error - ShouldRestart(exitCode uint32, hasBeenManuallyStopped bool, executionDuration time.Duration) (bool, chan error, error) -} - -type restartManager struct { - sync.Mutex - sync.Once - policy container.RestartPolicy - restartCount int - timeout time.Duration - active bool - cancel chan struct{} - canceled bool -} - -// New returns a new restartmanager based on a policy. -func New(policy container.RestartPolicy, restartCount int) RestartManager { - return &restartManager{policy: policy, restartCount: restartCount, cancel: make(chan struct{})} -} - -func (rm *restartManager) SetPolicy(policy container.RestartPolicy) { - rm.Lock() - rm.policy = policy - rm.Unlock() -} - -func (rm *restartManager) ShouldRestart(exitCode uint32, hasBeenManuallyStopped bool, executionDuration time.Duration) (bool, chan error, error) { - if rm.policy.IsNone() { - return false, nil, nil - } - rm.Lock() - unlockOnExit := true - defer func() { - if unlockOnExit { - rm.Unlock() - } - }() - - if rm.canceled { - return false, nil, ErrRestartCanceled - } - - if rm.active { - return false, nil, fmt.Errorf("invalid call on active restartmanager") - } - // if the container ran for more than 10s, regardless of status and policy reset the - // the timeout back to the default. - if executionDuration.Seconds() >= 10 { - rm.timeout = 0 - } - if rm.timeout == 0 { - rm.timeout = defaultTimeout - } else { - rm.timeout *= backoffMultiplier - } - - var restart bool - switch { - case rm.policy.IsAlways(): - restart = true - case rm.policy.IsUnlessStopped() && !hasBeenManuallyStopped: - restart = true - case rm.policy.IsOnFailure(): - // the default value of 0 for MaximumRetryCount means that we will not enforce a maximum count - if max := rm.policy.MaximumRetryCount; max == 0 || rm.restartCount < max { - restart = exitCode != 0 - } - } - - if !restart { - rm.active = false - return false, nil, nil - } - - rm.restartCount++ - - unlockOnExit = false - rm.active = true - rm.Unlock() - - ch := make(chan error) - go func() { - select { - case <-rm.cancel: - ch <- ErrRestartCanceled - close(ch) - case <-time.After(rm.timeout): - rm.Lock() - close(ch) - rm.active = false - rm.Unlock() - } - }() - - return true, ch, nil -} - -func (rm *restartManager) Cancel() error { - rm.Do(func() { - rm.Lock() - rm.canceled = true - close(rm.cancel) - rm.Unlock() - }) - return nil -} diff --git a/vendor/github.com/docker/docker/restartmanager/restartmanager_test.go b/vendor/github.com/docker/docker/restartmanager/restartmanager_test.go deleted file mode 100644 index 20eced5..0000000 --- a/vendor/github.com/docker/docker/restartmanager/restartmanager_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package restartmanager - -import ( - "testing" - "time" - - "github.com/docker/docker/api/types/container" -) - -func TestRestartManagerTimeout(t *testing.T) { - rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager) - should, _, err := rm.ShouldRestart(0, false, 1*time.Second) - if err != nil { - t.Fatal(err) - } - if !should { - t.Fatal("container should be restarted") - } - if rm.timeout != 100*time.Millisecond { - t.Fatalf("restart manager should have a timeout of 100ms but has %s", rm.timeout) - } -} - -func TestRestartManagerTimeoutReset(t *testing.T) { - rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager) - rm.timeout = 5 * time.Second - _, _, err := rm.ShouldRestart(0, false, 10*time.Second) - if err != nil { - t.Fatal(err) - } - if rm.timeout != 100*time.Millisecond { - t.Fatalf("restart manager should have a timeout of 100ms but has %s", rm.timeout) - } -} diff --git a/vendor/github.com/docker/docker/runconfig/compare.go b/vendor/github.com/docker/docker/runconfig/compare.go deleted file mode 100644 index 708922f..0000000 --- a/vendor/github.com/docker/docker/runconfig/compare.go +++ /dev/null @@ -1,61 +0,0 @@ -package runconfig - -import "github.com/docker/docker/api/types/container" - -// Compare two Config struct. Do not compare the "Image" nor "Hostname" fields -// If OpenStdin is set, then it differs -func Compare(a, b *container.Config) bool { - if a == nil || b == nil || - a.OpenStdin || b.OpenStdin { - return false - } - if a.AttachStdout != b.AttachStdout || - a.AttachStderr != b.AttachStderr || - a.User != b.User || - a.OpenStdin != b.OpenStdin || - a.Tty != b.Tty { - return false - } - - if len(a.Cmd) != len(b.Cmd) || - len(a.Env) != len(b.Env) || - len(a.Labels) != len(b.Labels) || - len(a.ExposedPorts) != len(b.ExposedPorts) || - len(a.Entrypoint) != len(b.Entrypoint) || - len(a.Volumes) != len(b.Volumes) { - return false - } - - for i := 0; i < len(a.Cmd); i++ { - if a.Cmd[i] != b.Cmd[i] { - return false - } - } - for i := 0; i < len(a.Env); i++ { - if a.Env[i] != b.Env[i] { - return false - } - } - for k, v := range a.Labels { - if v != b.Labels[k] { - return false - } - } - for k := range a.ExposedPorts { - if _, exists := b.ExposedPorts[k]; !exists { - return false - } - } - - for i := 0; i < len(a.Entrypoint); i++ { - if a.Entrypoint[i] != b.Entrypoint[i] { - return false - } - } - for key := range a.Volumes { - if _, exists := b.Volumes[key]; !exists { - return false - } - } - return true -} diff --git a/vendor/github.com/docker/docker/runconfig/compare_test.go b/vendor/github.com/docker/docker/runconfig/compare_test.go deleted file mode 100644 index 6370d7a..0000000 --- a/vendor/github.com/docker/docker/runconfig/compare_test.go +++ /dev/null @@ -1,126 +0,0 @@ -package runconfig - -import ( - "testing" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/strslice" - "github.com/docker/go-connections/nat" -) - -// Just to make life easier -func newPortNoError(proto, port string) nat.Port { - p, _ := nat.NewPort(proto, port) - return p -} - -func TestCompare(t *testing.T) { - ports1 := make(nat.PortSet) - ports1[newPortNoError("tcp", "1111")] = struct{}{} - ports1[newPortNoError("tcp", "2222")] = struct{}{} - ports2 := make(nat.PortSet) - ports2[newPortNoError("tcp", "3333")] = struct{}{} - ports2[newPortNoError("tcp", "4444")] = struct{}{} - ports3 := make(nat.PortSet) - ports3[newPortNoError("tcp", "1111")] = struct{}{} - ports3[newPortNoError("tcp", "2222")] = struct{}{} - ports3[newPortNoError("tcp", "5555")] = struct{}{} - volumes1 := make(map[string]struct{}) - volumes1["/test1"] = struct{}{} - volumes2 := make(map[string]struct{}) - volumes2["/test2"] = struct{}{} - volumes3 := make(map[string]struct{}) - volumes3["/test1"] = struct{}{} - volumes3["/test3"] = struct{}{} - envs1 := []string{"ENV1=value1", "ENV2=value2"} - envs2 := []string{"ENV1=value1", "ENV3=value3"} - entrypoint1 := strslice.StrSlice{"/bin/sh", "-c"} - entrypoint2 := strslice.StrSlice{"/bin/sh", "-d"} - entrypoint3 := strslice.StrSlice{"/bin/sh", "-c", "echo"} - cmd1 := strslice.StrSlice{"/bin/sh", "-c"} - cmd2 := strslice.StrSlice{"/bin/sh", "-d"} - cmd3 := strslice.StrSlice{"/bin/sh", "-c", "echo"} - labels1 := map[string]string{"LABEL1": "value1", "LABEL2": "value2"} - labels2 := map[string]string{"LABEL1": "value1", "LABEL2": "value3"} - labels3 := map[string]string{"LABEL1": "value1", "LABEL2": "value2", "LABEL3": "value3"} - - sameConfigs := map[*container.Config]*container.Config{ - // Empty config - &container.Config{}: {}, - // Does not compare hostname, domainname & image - &container.Config{ - Hostname: "host1", - Domainname: "domain1", - Image: "image1", - User: "user", - }: { - Hostname: "host2", - Domainname: "domain2", - Image: "image2", - User: "user", - }, - // only OpenStdin - &container.Config{OpenStdin: false}: {OpenStdin: false}, - // only env - &container.Config{Env: envs1}: {Env: envs1}, - // only cmd - &container.Config{Cmd: cmd1}: {Cmd: cmd1}, - // only labels - &container.Config{Labels: labels1}: {Labels: labels1}, - // only exposedPorts - &container.Config{ExposedPorts: ports1}: {ExposedPorts: ports1}, - // only entrypoints - &container.Config{Entrypoint: entrypoint1}: {Entrypoint: entrypoint1}, - // only volumes - &container.Config{Volumes: volumes1}: {Volumes: volumes1}, - } - differentConfigs := map[*container.Config]*container.Config{ - nil: nil, - &container.Config{ - Hostname: "host1", - Domainname: "domain1", - Image: "image1", - User: "user1", - }: { - Hostname: "host1", - Domainname: "domain1", - Image: "image1", - User: "user2", - }, - // only OpenStdin - &container.Config{OpenStdin: false}: {OpenStdin: true}, - &container.Config{OpenStdin: true}: {OpenStdin: false}, - // only env - &container.Config{Env: envs1}: {Env: envs2}, - // only cmd - &container.Config{Cmd: cmd1}: {Cmd: cmd2}, - // not the same number of parts - &container.Config{Cmd: cmd1}: {Cmd: cmd3}, - // only labels - &container.Config{Labels: labels1}: {Labels: labels2}, - // not the same number of labels - &container.Config{Labels: labels1}: {Labels: labels3}, - // only exposedPorts - &container.Config{ExposedPorts: ports1}: {ExposedPorts: ports2}, - // not the same number of ports - &container.Config{ExposedPorts: ports1}: {ExposedPorts: ports3}, - // only entrypoints - &container.Config{Entrypoint: entrypoint1}: {Entrypoint: entrypoint2}, - // not the same number of parts - &container.Config{Entrypoint: entrypoint1}: {Entrypoint: entrypoint3}, - // only volumes - &container.Config{Volumes: volumes1}: {Volumes: volumes2}, - // not the same number of labels - &container.Config{Volumes: volumes1}: {Volumes: volumes3}, - } - for config1, config2 := range sameConfigs { - if !Compare(config1, config2) { - t.Fatalf("Compare should be true for [%v] and [%v]", config1, config2) - } - } - for config1, config2 := range differentConfigs { - if Compare(config1, config2) { - t.Fatalf("Compare should be false for [%v] and [%v]", config1, config2) - } - } -} diff --git a/vendor/github.com/docker/docker/runconfig/config.go b/vendor/github.com/docker/docker/runconfig/config.go deleted file mode 100644 index 508681c..0000000 --- a/vendor/github.com/docker/docker/runconfig/config.go +++ /dev/null @@ -1,97 +0,0 @@ -package runconfig - -import ( - "encoding/json" - "fmt" - "io" - - "github.com/docker/docker/api/types/container" - networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/pkg/sysinfo" - "github.com/docker/docker/volume" -) - -// ContainerDecoder implements httputils.ContainerDecoder -// calling DecodeContainerConfig. -type ContainerDecoder struct{} - -// DecodeConfig makes ContainerDecoder to implement httputils.ContainerDecoder -func (r ContainerDecoder) DecodeConfig(src io.Reader) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) { - return DecodeContainerConfig(src) -} - -// DecodeHostConfig makes ContainerDecoder to implement httputils.ContainerDecoder -func (r ContainerDecoder) DecodeHostConfig(src io.Reader) (*container.HostConfig, error) { - return DecodeHostConfig(src) -} - -// DecodeContainerConfig decodes a json encoded config into a ContainerConfigWrapper -// struct and returns both a Config and a HostConfig struct -// Be aware this function is not checking whether the resulted structs are nil, -// it's your business to do so -func DecodeContainerConfig(src io.Reader) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) { - var w ContainerConfigWrapper - - decoder := json.NewDecoder(src) - if err := decoder.Decode(&w); err != nil { - return nil, nil, nil, err - } - - hc := w.getHostConfig() - - // Perform platform-specific processing of Volumes and Binds. - if w.Config != nil && hc != nil { - - // Initialize the volumes map if currently nil - if w.Config.Volumes == nil { - w.Config.Volumes = make(map[string]struct{}) - } - - // Now validate all the volumes and binds - if err := validateMountSettings(w.Config, hc); err != nil { - return nil, nil, nil, err - } - } - - // Certain parameters need daemon-side validation that cannot be done - // on the client, as only the daemon knows what is valid for the platform. - if err := ValidateNetMode(w.Config, hc); err != nil { - return nil, nil, nil, err - } - - // Validate isolation - if err := ValidateIsolation(hc); err != nil { - return nil, nil, nil, err - } - - // Validate QoS - if err := ValidateQoS(hc); err != nil { - return nil, nil, nil, err - } - - // Validate Resources - if err := ValidateResources(hc, sysinfo.New(true)); err != nil { - return nil, nil, nil, err - } - return w.Config, hc, w.NetworkingConfig, nil -} - -// validateMountSettings validates each of the volumes and bind settings -// passed by the caller to ensure they are valid. -func validateMountSettings(c *container.Config, hc *container.HostConfig) error { - // it is ok to have len(hc.Mounts) > 0 && (len(hc.Binds) > 0 || len (c.Volumes) > 0 || len (hc.Tmpfs) > 0 ) - - // Ensure all volumes and binds are valid. - for spec := range c.Volumes { - if _, err := volume.ParseMountRaw(spec, hc.VolumeDriver); err != nil { - return fmt.Errorf("invalid volume spec %q: %v", spec, err) - } - } - for _, spec := range hc.Binds { - if _, err := volume.ParseMountRaw(spec, hc.VolumeDriver); err != nil { - return fmt.Errorf("invalid bind mount spec %q: %v", spec, err) - } - } - - return nil -} diff --git a/vendor/github.com/docker/docker/runconfig/config_test.go b/vendor/github.com/docker/docker/runconfig/config_test.go deleted file mode 100644 index f1f9de5..0000000 --- a/vendor/github.com/docker/docker/runconfig/config_test.go +++ /dev/null @@ -1,139 +0,0 @@ -package runconfig - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "runtime" - "strings" - "testing" - - "github.com/docker/docker/api/types/container" - networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/api/types/strslice" -) - -type f struct { - file string - entrypoint strslice.StrSlice -} - -func TestDecodeContainerConfig(t *testing.T) { - - var ( - fixtures []f - image string - ) - - //TODO: Should run for Solaris - if runtime.GOOS == "solaris" { - t.Skip() - } - - if runtime.GOOS != "windows" { - image = "ubuntu" - fixtures = []f{ - {"fixtures/unix/container_config_1_14.json", strslice.StrSlice{}}, - {"fixtures/unix/container_config_1_17.json", strslice.StrSlice{"bash"}}, - {"fixtures/unix/container_config_1_19.json", strslice.StrSlice{"bash"}}, - } - } else { - image = "windows" - fixtures = []f{ - {"fixtures/windows/container_config_1_19.json", strslice.StrSlice{"cmd"}}, - } - } - - for _, f := range fixtures { - b, err := ioutil.ReadFile(f.file) - if err != nil { - t.Fatal(err) - } - - c, h, _, err := DecodeContainerConfig(bytes.NewReader(b)) - if err != nil { - t.Fatal(fmt.Errorf("Error parsing %s: %v", f, err)) - } - - if c.Image != image { - t.Fatalf("Expected %s image, found %s\n", image, c.Image) - } - - if len(c.Entrypoint) != len(f.entrypoint) { - t.Fatalf("Expected %v, found %v\n", f.entrypoint, c.Entrypoint) - } - - if h != nil && h.Memory != 1000 { - t.Fatalf("Expected memory to be 1000, found %d\n", h.Memory) - } - } -} - -// TestDecodeContainerConfigIsolation validates isolation passed -// to the daemon in the hostConfig structure. Note this is platform specific -// as to what level of container isolation is supported. -func TestDecodeContainerConfigIsolation(t *testing.T) { - - // An invalid isolation level - if _, _, _, err := callDecodeContainerConfigIsolation("invalid"); err != nil { - if !strings.Contains(err.Error(), `invalid --isolation: "invalid"`) { - t.Fatal(err) - } - } - - // Blank isolation (== default) - if _, _, _, err := callDecodeContainerConfigIsolation(""); err != nil { - t.Fatal("Blank isolation should have succeeded") - } - - // Default isolation - if _, _, _, err := callDecodeContainerConfigIsolation("default"); err != nil { - t.Fatal("default isolation should have succeeded") - } - - // Process isolation (Valid on Windows only) - if runtime.GOOS == "windows" { - if _, _, _, err := callDecodeContainerConfigIsolation("process"); err != nil { - t.Fatal("process isolation should have succeeded") - } - } else { - if _, _, _, err := callDecodeContainerConfigIsolation("process"); err != nil { - if !strings.Contains(err.Error(), `invalid --isolation: "process"`) { - t.Fatal(err) - } - } - } - - // Hyper-V Containers isolation (Valid on Windows only) - if runtime.GOOS == "windows" { - if _, _, _, err := callDecodeContainerConfigIsolation("hyperv"); err != nil { - t.Fatal("hyperv isolation should have succeeded") - } - } else { - if _, _, _, err := callDecodeContainerConfigIsolation("hyperv"); err != nil { - if !strings.Contains(err.Error(), `invalid --isolation: "hyperv"`) { - t.Fatal(err) - } - } - } -} - -// callDecodeContainerConfigIsolation is a utility function to call -// DecodeContainerConfig for validating isolation -func callDecodeContainerConfigIsolation(isolation string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) { - var ( - b []byte - err error - ) - w := ContainerConfigWrapper{ - Config: &container.Config{}, - HostConfig: &container.HostConfig{ - NetworkMode: "none", - Isolation: container.Isolation(isolation)}, - } - if b, err = json.Marshal(w); err != nil { - return nil, nil, nil, fmt.Errorf("Error on marshal %s", err.Error()) - } - return DecodeContainerConfig(bytes.NewReader(b)) -} diff --git a/vendor/github.com/docker/docker/runconfig/config_unix.go b/vendor/github.com/docker/docker/runconfig/config_unix.go deleted file mode 100644 index 4ccfc73..0000000 --- a/vendor/github.com/docker/docker/runconfig/config_unix.go +++ /dev/null @@ -1,59 +0,0 @@ -// +build !windows - -package runconfig - -import ( - "github.com/docker/docker/api/types/container" - networktypes "github.com/docker/docker/api/types/network" -) - -// ContainerConfigWrapper is a Config wrapper that holds the container Config (portable) -// and the corresponding HostConfig (non-portable). -type ContainerConfigWrapper struct { - *container.Config - InnerHostConfig *container.HostConfig `json:"HostConfig,omitempty"` - Cpuset string `json:",omitempty"` // Deprecated. Exported for backwards compatibility. - NetworkingConfig *networktypes.NetworkingConfig `json:"NetworkingConfig,omitempty"` - *container.HostConfig // Deprecated. Exported to read attributes from json that are not in the inner host config structure. -} - -// getHostConfig gets the HostConfig of the Config. -// It's mostly there to handle Deprecated fields of the ContainerConfigWrapper -func (w *ContainerConfigWrapper) getHostConfig() *container.HostConfig { - hc := w.HostConfig - - if hc == nil && w.InnerHostConfig != nil { - hc = w.InnerHostConfig - } else if w.InnerHostConfig != nil { - if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 { - w.InnerHostConfig.Memory = hc.Memory - } - if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 { - w.InnerHostConfig.MemorySwap = hc.MemorySwap - } - if hc.CPUShares != 0 && w.InnerHostConfig.CPUShares == 0 { - w.InnerHostConfig.CPUShares = hc.CPUShares - } - if hc.CpusetCpus != "" && w.InnerHostConfig.CpusetCpus == "" { - w.InnerHostConfig.CpusetCpus = hc.CpusetCpus - } - - if hc.VolumeDriver != "" && w.InnerHostConfig.VolumeDriver == "" { - w.InnerHostConfig.VolumeDriver = hc.VolumeDriver - } - - hc = w.InnerHostConfig - } - - if hc != nil { - if w.Cpuset != "" && hc.CpusetCpus == "" { - hc.CpusetCpus = w.Cpuset - } - } - - // Make sure NetworkMode has an acceptable value. We do this to ensure - // backwards compatible API behavior. - hc = SetDefaultNetModeIfBlank(hc) - - return hc -} diff --git a/vendor/github.com/docker/docker/runconfig/config_windows.go b/vendor/github.com/docker/docker/runconfig/config_windows.go deleted file mode 100644 index f2361b5..0000000 --- a/vendor/github.com/docker/docker/runconfig/config_windows.go +++ /dev/null @@ -1,19 +0,0 @@ -package runconfig - -import ( - "github.com/docker/docker/api/types/container" - networktypes "github.com/docker/docker/api/types/network" -) - -// ContainerConfigWrapper is a Config wrapper that holds the container Config (portable) -// and the corresponding HostConfig (non-portable). -type ContainerConfigWrapper struct { - *container.Config - HostConfig *container.HostConfig `json:"HostConfig,omitempty"` - NetworkingConfig *networktypes.NetworkingConfig `json:"NetworkingConfig,omitempty"` -} - -// getHostConfig gets the HostConfig of the Config. -func (w *ContainerConfigWrapper) getHostConfig() *container.HostConfig { - return w.HostConfig -} diff --git a/vendor/github.com/docker/docker/runconfig/errors.go b/vendor/github.com/docker/docker/runconfig/errors.go deleted file mode 100644 index bb72c16..0000000 --- a/vendor/github.com/docker/docker/runconfig/errors.go +++ /dev/null @@ -1,46 +0,0 @@ -package runconfig - -import ( - "fmt" - - "github.com/docker/docker/api/errors" -) - -var ( - // ErrConflictContainerNetworkAndLinks conflict between --net=container and links - ErrConflictContainerNetworkAndLinks = fmt.Errorf("Conflicting options: container type network can't be used with links. This would result in undefined behavior") - // ErrConflictUserDefinedNetworkAndLinks conflict between --net= and links - ErrConflictUserDefinedNetworkAndLinks = fmt.Errorf("Conflicting options: networking can't be used with links. This would result in undefined behavior") - // ErrConflictSharedNetwork conflict between private and other networks - ErrConflictSharedNetwork = fmt.Errorf("Container sharing network namespace with another container or host cannot be connected to any other network") - // ErrConflictHostNetwork conflict from being disconnected from host network or connected to host network. - ErrConflictHostNetwork = fmt.Errorf("Container cannot be disconnected from host network or connected to host network") - // ErrConflictNoNetwork conflict between private and other networks - ErrConflictNoNetwork = fmt.Errorf("Container cannot be connected to multiple networks with one of the networks in private (none) mode") - // ErrConflictNetworkAndDNS conflict between --dns and the network mode - ErrConflictNetworkAndDNS = fmt.Errorf("Conflicting options: dns and the network mode") - // ErrConflictNetworkHostname conflict between the hostname and the network mode - ErrConflictNetworkHostname = fmt.Errorf("Conflicting options: hostname and the network mode") - // ErrConflictHostNetworkAndLinks conflict between --net=host and links - ErrConflictHostNetworkAndLinks = fmt.Errorf("Conflicting options: host type networking can't be used with links. This would result in undefined behavior") - // ErrConflictContainerNetworkAndMac conflict between the mac address and the network mode - ErrConflictContainerNetworkAndMac = fmt.Errorf("Conflicting options: mac-address and the network mode") - // ErrConflictNetworkHosts conflict between add-host and the network mode - ErrConflictNetworkHosts = fmt.Errorf("Conflicting options: custom host-to-IP mapping and the network mode") - // ErrConflictNetworkPublishPorts conflict between the publish options and the network mode - ErrConflictNetworkPublishPorts = fmt.Errorf("Conflicting options: port publishing and the container type network mode") - // ErrConflictNetworkExposePorts conflict between the expose option and the network mode - ErrConflictNetworkExposePorts = fmt.Errorf("Conflicting options: port exposing and the container type network mode") - // ErrUnsupportedNetworkAndIP conflict between network mode and requested ip address - ErrUnsupportedNetworkAndIP = fmt.Errorf("User specified IP address is supported on user defined networks only") - // ErrUnsupportedNetworkNoSubnetAndIP conflict between network with no configured subnet and requested ip address - ErrUnsupportedNetworkNoSubnetAndIP = fmt.Errorf("User specified IP address is supported only when connecting to networks with user configured subnets") - // ErrUnsupportedNetworkAndAlias conflict between network mode and alias - ErrUnsupportedNetworkAndAlias = fmt.Errorf("Network-scoped alias is supported only for containers in user defined networks") - // ErrConflictUTSHostname conflict between the hostname and the UTS mode - ErrConflictUTSHostname = fmt.Errorf("Conflicting options: hostname and the UTS mode") -) - -func conflictError(err error) error { - return errors.NewRequestConflictError(err) -} diff --git a/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_config_1_14.json b/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_config_1_14.json deleted file mode 100644 index b08334c..0000000 --- a/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_config_1_14.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "Hostname":"", - "Domainname": "", - "User":"", - "Memory": 1000, - "MemorySwap":0, - "CpuShares": 512, - "Cpuset": "0,1", - "AttachStdin":false, - "AttachStdout":true, - "AttachStderr":true, - "PortSpecs":null, - "Tty":false, - "OpenStdin":false, - "StdinOnce":false, - "Env":null, - "Cmd":[ - "bash" - ], - "Image":"ubuntu", - "Volumes":{ - "/tmp": {} - }, - "WorkingDir":"", - "NetworkDisabled": false, - "ExposedPorts":{ - "22/tcp": {} - }, - "RestartPolicy": { "Name": "always" } -} diff --git a/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_config_1_17.json b/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_config_1_17.json deleted file mode 100644 index 0d78087..0000000 --- a/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_config_1_17.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "Hostname": "", - "Domainname": "", - "User": "", - "Memory": 1000, - "MemorySwap": 0, - "CpuShares": 512, - "Cpuset": "0,1", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Entrypoint": "bash", - "Image": "ubuntu", - "Volumes": { - "/tmp": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "SecurityOpt": [""], - "HostConfig": { - "Binds": ["/tmp:/tmp"], - "Links": ["redis3:redis"], - "LxcConf": {"lxc.utsname":"docker"}, - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsSearch": [""], - "DnsOptions": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [] - } -} diff --git a/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_config_1_19.json b/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_config_1_19.json deleted file mode 100644 index de49cf3..0000000 --- a/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_config_1_19.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Entrypoint": "bash", - "Image": "ubuntu", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "/tmp": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "HostConfig": { - "Binds": ["/tmp:/tmp"], - "Links": ["redis3:redis"], - "LxcConf": {"lxc.utsname":"docker"}, - "Memory": 1000, - "MemorySwap": 0, - "CpuShares": 512, - "CpusetCpus": "0,1", - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsSearch": [""], - "DnsOptions": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [""], - "CgroupParent": "" - } -} diff --git a/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_hostconfig_1_14.json b/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_hostconfig_1_14.json deleted file mode 100644 index c72ac91..0000000 --- a/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_hostconfig_1_14.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "Binds": ["/tmp:/tmp"], - "ContainerIDFile": "", - "LxcConf": [], - "Privileged": false, - "PortBindings": { - "80/tcp": [ - { - "HostIp": "0.0.0.0", - "HostPort": "49153" - } - ] - }, - "Links": ["/name:alias"], - "PublishAllPorts": false, - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"] -} diff --git a/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_hostconfig_1_19.json b/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_hostconfig_1_19.json deleted file mode 100644 index 5ca8aa7..0000000 --- a/vendor/github.com/docker/docker/runconfig/fixtures/unix/container_hostconfig_1_19.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "Binds": ["/tmp:/tmp"], - "Links": ["redis3:redis"], - "LxcConf": {"lxc.utsname":"docker"}, - "Memory": 0, - "MemorySwap": 0, - "CpuShares": 512, - "CpuPeriod": 100000, - "CpusetCpus": "0,1", - "CpusetMems": "0,1", - "BlkioWeight": 300, - "OomKillDisable": false, - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsSearch": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "bridge", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [""], - "CgroupParent": "" -} diff --git a/vendor/github.com/docker/docker/runconfig/fixtures/windows/container_config_1_19.json b/vendor/github.com/docker/docker/runconfig/fixtures/windows/container_config_1_19.json deleted file mode 100644 index 724320c..0000000 --- a/vendor/github.com/docker/docker/runconfig/fixtures/windows/container_config_1_19.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "Hostname": "", - "Domainname": "", - "User": "", - "AttachStdin": false, - "AttachStdout": true, - "AttachStderr": true, - "Tty": false, - "OpenStdin": false, - "StdinOnce": false, - "Env": null, - "Cmd": [ - "date" - ], - "Entrypoint": "cmd", - "Image": "windows", - "Labels": { - "com.example.vendor": "Acme", - "com.example.license": "GPL", - "com.example.version": "1.0" - }, - "Volumes": { - "c:/windows": {} - }, - "WorkingDir": "", - "NetworkDisabled": false, - "MacAddress": "12:34:56:78:9a:bc", - "ExposedPorts": { - "22/tcp": {} - }, - "HostConfig": { - "Binds": ["c:/windows:d:/tmp"], - "Links": ["redis3:redis"], - "LxcConf": {"lxc.utsname":"docker"}, - "Memory": 1000, - "MemorySwap": 0, - "CpuShares": 512, - "CpusetCpus": "0,1", - "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, - "PublishAllPorts": false, - "Privileged": false, - "ReadonlyRootfs": false, - "Dns": ["8.8.8.8"], - "DnsSearch": [""], - "DnsOptions": [""], - "ExtraHosts": null, - "VolumesFrom": ["parent", "other:ro"], - "CapAdd": ["NET_ADMIN"], - "CapDrop": ["MKNOD"], - "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, - "NetworkMode": "default", - "Devices": [], - "Ulimits": [{}], - "LogConfig": { "Type": "json-file", "Config": {} }, - "SecurityOpt": [""], - "CgroupParent": "" - } -} diff --git a/vendor/github.com/docker/docker/runconfig/hostconfig.go b/vendor/github.com/docker/docker/runconfig/hostconfig.go deleted file mode 100644 index 2b81d02..0000000 --- a/vendor/github.com/docker/docker/runconfig/hostconfig.go +++ /dev/null @@ -1,35 +0,0 @@ -package runconfig - -import ( - "encoding/json" - "io" - - "github.com/docker/docker/api/types/container" -) - -// DecodeHostConfig creates a HostConfig based on the specified Reader. -// It assumes the content of the reader will be JSON, and decodes it. -func DecodeHostConfig(src io.Reader) (*container.HostConfig, error) { - decoder := json.NewDecoder(src) - - var w ContainerConfigWrapper - if err := decoder.Decode(&w); err != nil { - return nil, err - } - - hc := w.getHostConfig() - return hc, nil -} - -// SetDefaultNetModeIfBlank changes the NetworkMode in a HostConfig structure -// to default if it is not populated. This ensures backwards compatibility after -// the validation of the network mode was moved from the docker CLI to the -// docker daemon. -func SetDefaultNetModeIfBlank(hc *container.HostConfig) *container.HostConfig { - if hc != nil { - if hc.NetworkMode == container.NetworkMode("") { - hc.NetworkMode = container.NetworkMode("default") - } - } - return hc -} diff --git a/vendor/github.com/docker/docker/runconfig/hostconfig_solaris.go b/vendor/github.com/docker/docker/runconfig/hostconfig_solaris.go deleted file mode 100644 index 83ad32e..0000000 --- a/vendor/github.com/docker/docker/runconfig/hostconfig_solaris.go +++ /dev/null @@ -1,41 +0,0 @@ -package runconfig - -import ( - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/sysinfo" -) - -// DefaultDaemonNetworkMode returns the default network stack the daemon should -// use. -func DefaultDaemonNetworkMode() container.NetworkMode { - return container.NetworkMode("bridge") -} - -// IsPreDefinedNetwork indicates if a network is predefined by the daemon -func IsPreDefinedNetwork(network string) bool { - return false -} - -// ValidateNetMode ensures that the various combinations of requested -// network settings are valid. -func ValidateNetMode(c *container.Config, hc *container.HostConfig) error { - // We may not be passed a host config, such as in the case of docker commit - return nil -} - -// ValidateIsolation performs platform specific validation of the -// isolation level in the hostconfig structure. -// This setting is currently discarded for Solaris so this is a no-op. -func ValidateIsolation(hc *container.HostConfig) error { - return nil -} - -// ValidateQoS performs platform specific validation of the QoS settings -func ValidateQoS(hc *container.HostConfig) error { - return nil -} - -// ValidateResources performs platform specific validation of the resource settings -func ValidateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error { - return nil -} diff --git a/vendor/github.com/docker/docker/runconfig/hostconfig_test.go b/vendor/github.com/docker/docker/runconfig/hostconfig_test.go deleted file mode 100644 index a6a2b34..0000000 --- a/vendor/github.com/docker/docker/runconfig/hostconfig_test.go +++ /dev/null @@ -1,283 +0,0 @@ -// +build !windows - -package runconfig - -import ( - "bytes" - "fmt" - "io/ioutil" - "testing" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/sysinfo" -) - -// TODO Windows: This will need addressing for a Windows daemon. -func TestNetworkModeTest(t *testing.T) { - networkModes := map[container.NetworkMode][]bool{ - // private, bridge, host, container, none, default - "": {true, false, false, false, false, false}, - "something:weird": {true, false, false, false, false, false}, - "bridge": {true, true, false, false, false, false}, - DefaultDaemonNetworkMode(): {true, true, false, false, false, false}, - "host": {false, false, true, false, false, false}, - "container:name": {false, false, false, true, false, false}, - "none": {true, false, false, false, true, false}, - "default": {true, false, false, false, false, true}, - } - networkModeNames := map[container.NetworkMode]string{ - "": "", - "something:weird": "something:weird", - "bridge": "bridge", - DefaultDaemonNetworkMode(): "bridge", - "host": "host", - "container:name": "container", - "none": "none", - "default": "default", - } - for networkMode, state := range networkModes { - if networkMode.IsPrivate() != state[0] { - t.Fatalf("NetworkMode.IsPrivate for %v should have been %v but was %v", networkMode, state[0], networkMode.IsPrivate()) - } - if networkMode.IsBridge() != state[1] { - t.Fatalf("NetworkMode.IsBridge for %v should have been %v but was %v", networkMode, state[1], networkMode.IsBridge()) - } - if networkMode.IsHost() != state[2] { - t.Fatalf("NetworkMode.IsHost for %v should have been %v but was %v", networkMode, state[2], networkMode.IsHost()) - } - if networkMode.IsContainer() != state[3] { - t.Fatalf("NetworkMode.IsContainer for %v should have been %v but was %v", networkMode, state[3], networkMode.IsContainer()) - } - if networkMode.IsNone() != state[4] { - t.Fatalf("NetworkMode.IsNone for %v should have been %v but was %v", networkMode, state[4], networkMode.IsNone()) - } - if networkMode.IsDefault() != state[5] { - t.Fatalf("NetworkMode.IsDefault for %v should have been %v but was %v", networkMode, state[5], networkMode.IsDefault()) - } - if networkMode.NetworkName() != networkModeNames[networkMode] { - t.Fatalf("Expected name %v, got %v", networkModeNames[networkMode], networkMode.NetworkName()) - } - } -} - -func TestIpcModeTest(t *testing.T) { - ipcModes := map[container.IpcMode][]bool{ - // private, host, container, valid - "": {true, false, false, true}, - "something:weird": {true, false, false, false}, - ":weird": {true, false, false, true}, - "host": {false, true, false, true}, - "container:name": {false, false, true, true}, - "container:name:something": {false, false, true, false}, - "container:": {false, false, true, false}, - } - for ipcMode, state := range ipcModes { - if ipcMode.IsPrivate() != state[0] { - t.Fatalf("IpcMode.IsPrivate for %v should have been %v but was %v", ipcMode, state[0], ipcMode.IsPrivate()) - } - if ipcMode.IsHost() != state[1] { - t.Fatalf("IpcMode.IsHost for %v should have been %v but was %v", ipcMode, state[1], ipcMode.IsHost()) - } - if ipcMode.IsContainer() != state[2] { - t.Fatalf("IpcMode.IsContainer for %v should have been %v but was %v", ipcMode, state[2], ipcMode.IsContainer()) - } - if ipcMode.Valid() != state[3] { - t.Fatalf("IpcMode.Valid for %v should have been %v but was %v", ipcMode, state[3], ipcMode.Valid()) - } - } - containerIpcModes := map[container.IpcMode]string{ - "": "", - "something": "", - "something:weird": "weird", - "container": "", - "container:": "", - "container:name": "name", - "container:name1:name2": "name1:name2", - } - for ipcMode, container := range containerIpcModes { - if ipcMode.Container() != container { - t.Fatalf("Expected %v for %v but was %v", container, ipcMode, ipcMode.Container()) - } - } -} - -func TestUTSModeTest(t *testing.T) { - utsModes := map[container.UTSMode][]bool{ - // private, host, valid - "": {true, false, true}, - "something:weird": {true, false, false}, - "host": {false, true, true}, - "host:name": {true, false, true}, - } - for utsMode, state := range utsModes { - if utsMode.IsPrivate() != state[0] { - t.Fatalf("UtsMode.IsPrivate for %v should have been %v but was %v", utsMode, state[0], utsMode.IsPrivate()) - } - if utsMode.IsHost() != state[1] { - t.Fatalf("UtsMode.IsHost for %v should have been %v but was %v", utsMode, state[1], utsMode.IsHost()) - } - if utsMode.Valid() != state[2] { - t.Fatalf("UtsMode.Valid for %v should have been %v but was %v", utsMode, state[2], utsMode.Valid()) - } - } -} - -func TestUsernsModeTest(t *testing.T) { - usrensMode := map[container.UsernsMode][]bool{ - // private, host, valid - "": {true, false, true}, - "something:weird": {true, false, false}, - "host": {false, true, true}, - "host:name": {true, false, true}, - } - for usernsMode, state := range usrensMode { - if usernsMode.IsPrivate() != state[0] { - t.Fatalf("UsernsMode.IsPrivate for %v should have been %v but was %v", usernsMode, state[0], usernsMode.IsPrivate()) - } - if usernsMode.IsHost() != state[1] { - t.Fatalf("UsernsMode.IsHost for %v should have been %v but was %v", usernsMode, state[1], usernsMode.IsHost()) - } - if usernsMode.Valid() != state[2] { - t.Fatalf("UsernsMode.Valid for %v should have been %v but was %v", usernsMode, state[2], usernsMode.Valid()) - } - } -} - -func TestPidModeTest(t *testing.T) { - pidModes := map[container.PidMode][]bool{ - // private, host, valid - "": {true, false, true}, - "something:weird": {true, false, false}, - "host": {false, true, true}, - "host:name": {true, false, true}, - } - for pidMode, state := range pidModes { - if pidMode.IsPrivate() != state[0] { - t.Fatalf("PidMode.IsPrivate for %v should have been %v but was %v", pidMode, state[0], pidMode.IsPrivate()) - } - if pidMode.IsHost() != state[1] { - t.Fatalf("PidMode.IsHost for %v should have been %v but was %v", pidMode, state[1], pidMode.IsHost()) - } - if pidMode.Valid() != state[2] { - t.Fatalf("PidMode.Valid for %v should have been %v but was %v", pidMode, state[2], pidMode.Valid()) - } - } -} - -func TestRestartPolicy(t *testing.T) { - restartPolicies := map[container.RestartPolicy][]bool{ - // none, always, failure - container.RestartPolicy{}: {true, false, false}, - container.RestartPolicy{"something", 0}: {false, false, false}, - container.RestartPolicy{"no", 0}: {true, false, false}, - container.RestartPolicy{"always", 0}: {false, true, false}, - container.RestartPolicy{"on-failure", 0}: {false, false, true}, - } - for restartPolicy, state := range restartPolicies { - if restartPolicy.IsNone() != state[0] { - t.Fatalf("RestartPolicy.IsNone for %v should have been %v but was %v", restartPolicy, state[0], restartPolicy.IsNone()) - } - if restartPolicy.IsAlways() != state[1] { - t.Fatalf("RestartPolicy.IsAlways for %v should have been %v but was %v", restartPolicy, state[1], restartPolicy.IsAlways()) - } - if restartPolicy.IsOnFailure() != state[2] { - t.Fatalf("RestartPolicy.IsOnFailure for %v should have been %v but was %v", restartPolicy, state[2], restartPolicy.IsOnFailure()) - } - } -} -func TestDecodeHostConfig(t *testing.T) { - fixtures := []struct { - file string - }{ - {"fixtures/unix/container_hostconfig_1_14.json"}, - {"fixtures/unix/container_hostconfig_1_19.json"}, - } - - for _, f := range fixtures { - b, err := ioutil.ReadFile(f.file) - if err != nil { - t.Fatal(err) - } - - c, err := DecodeHostConfig(bytes.NewReader(b)) - if err != nil { - t.Fatal(fmt.Errorf("Error parsing %s: %v", f, err)) - } - - if c.Privileged != false { - t.Fatalf("Expected privileged false, found %v\n", c.Privileged) - } - - if l := len(c.Binds); l != 1 { - t.Fatalf("Expected 1 bind, found %d\n", l) - } - - if len(c.CapAdd) != 1 && c.CapAdd[0] != "NET_ADMIN" { - t.Fatalf("Expected CapAdd NET_ADMIN, got %v", c.CapAdd) - } - - if len(c.CapDrop) != 1 && c.CapDrop[0] != "NET_ADMIN" { - t.Fatalf("Expected CapDrop MKNOD, got %v", c.CapDrop) - } - } -} - -func TestValidateResources(t *testing.T) { - type resourceTest struct { - ConfigCPURealtimePeriod int64 - ConfigCPURealtimeRuntime int64 - SysInfoCPURealtimePeriod bool - SysInfoCPURealtimeRuntime bool - ErrorExpected bool - FailureMsg string - } - - tests := []resourceTest{ - { - ConfigCPURealtimePeriod: 1000, - ConfigCPURealtimeRuntime: 1000, - SysInfoCPURealtimePeriod: true, - SysInfoCPURealtimeRuntime: true, - ErrorExpected: false, - FailureMsg: "Expected valid configuration", - }, - { - ConfigCPURealtimePeriod: 5000, - ConfigCPURealtimeRuntime: 5000, - SysInfoCPURealtimePeriod: false, - SysInfoCPURealtimeRuntime: true, - ErrorExpected: true, - FailureMsg: "Expected failure when cpu-rt-period is set but kernel doesn't support it", - }, - { - ConfigCPURealtimePeriod: 5000, - ConfigCPURealtimeRuntime: 5000, - SysInfoCPURealtimePeriod: true, - SysInfoCPURealtimeRuntime: false, - ErrorExpected: true, - FailureMsg: "Expected failure when cpu-rt-runtime is set but kernel doesn't support it", - }, - { - ConfigCPURealtimePeriod: 5000, - ConfigCPURealtimeRuntime: 10000, - SysInfoCPURealtimePeriod: true, - SysInfoCPURealtimeRuntime: false, - ErrorExpected: true, - FailureMsg: "Expected failure when cpu-rt-runtime is greater than cpu-rt-period", - }, - } - - for _, rt := range tests { - var hc container.HostConfig - hc.Resources.CPURealtimePeriod = rt.ConfigCPURealtimePeriod - hc.Resources.CPURealtimeRuntime = rt.ConfigCPURealtimeRuntime - - var si sysinfo.SysInfo - si.CPURealtimePeriod = rt.SysInfoCPURealtimePeriod - si.CPURealtimeRuntime = rt.SysInfoCPURealtimeRuntime - - if err := ValidateResources(&hc, &si); (err != nil) != rt.ErrorExpected { - t.Fatal(rt.FailureMsg, err) - } - } -} diff --git a/vendor/github.com/docker/docker/runconfig/hostconfig_unix.go b/vendor/github.com/docker/docker/runconfig/hostconfig_unix.go deleted file mode 100644 index 6e2b7f5..0000000 --- a/vendor/github.com/docker/docker/runconfig/hostconfig_unix.go +++ /dev/null @@ -1,129 +0,0 @@ -// +build !windows,!solaris - -package runconfig - -import ( - "fmt" - "runtime" - "strings" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/sysinfo" -) - -// DefaultDaemonNetworkMode returns the default network stack the daemon should -// use. -func DefaultDaemonNetworkMode() container.NetworkMode { - return container.NetworkMode("bridge") -} - -// IsPreDefinedNetwork indicates if a network is predefined by the daemon -func IsPreDefinedNetwork(network string) bool { - n := container.NetworkMode(network) - return n.IsBridge() || n.IsHost() || n.IsNone() || n.IsDefault() || network == "ingress" -} - -// ValidateNetMode ensures that the various combinations of requested -// network settings are valid. -func ValidateNetMode(c *container.Config, hc *container.HostConfig) error { - // We may not be passed a host config, such as in the case of docker commit - if hc == nil { - return nil - } - parts := strings.Split(string(hc.NetworkMode), ":") - if parts[0] == "container" { - if len(parts) < 2 || parts[1] == "" { - return fmt.Errorf("--net: invalid net mode: invalid container format container:") - } - } - - if hc.NetworkMode.IsContainer() && c.Hostname != "" { - return ErrConflictNetworkHostname - } - - if hc.UTSMode.IsHost() && c.Hostname != "" { - return ErrConflictUTSHostname - } - - if hc.NetworkMode.IsHost() && len(hc.Links) > 0 { - return ErrConflictHostNetworkAndLinks - } - - if hc.NetworkMode.IsContainer() && len(hc.Links) > 0 { - return ErrConflictContainerNetworkAndLinks - } - - if hc.NetworkMode.IsContainer() && len(hc.DNS) > 0 { - return ErrConflictNetworkAndDNS - } - - if hc.NetworkMode.IsContainer() && len(hc.ExtraHosts) > 0 { - return ErrConflictNetworkHosts - } - - if (hc.NetworkMode.IsContainer() || hc.NetworkMode.IsHost()) && c.MacAddress != "" { - return ErrConflictContainerNetworkAndMac - } - - if hc.NetworkMode.IsContainer() && (len(hc.PortBindings) > 0 || hc.PublishAllPorts == true) { - return ErrConflictNetworkPublishPorts - } - - if hc.NetworkMode.IsContainer() && len(c.ExposedPorts) > 0 { - return ErrConflictNetworkExposePorts - } - return nil -} - -// ValidateIsolation performs platform specific validation of -// isolation in the hostconfig structure. Linux only supports "default" -// which is LXC container isolation -func ValidateIsolation(hc *container.HostConfig) error { - // We may not be passed a host config, such as in the case of docker commit - if hc == nil { - return nil - } - if !hc.Isolation.IsValid() { - return fmt.Errorf("invalid --isolation: %q - %s only supports 'default'", hc.Isolation, runtime.GOOS) - } - return nil -} - -// ValidateQoS performs platform specific validation of the QoS settings -func ValidateQoS(hc *container.HostConfig) error { - // We may not be passed a host config, such as in the case of docker commit - if hc == nil { - return nil - } - - if hc.IOMaximumBandwidth != 0 { - return fmt.Errorf("invalid QoS settings: %s does not support --io-maxbandwidth", runtime.GOOS) - } - - if hc.IOMaximumIOps != 0 { - return fmt.Errorf("invalid QoS settings: %s does not support --io-maxiops", runtime.GOOS) - } - return nil -} - -// ValidateResources performs platform specific validation of the resource settings -// cpu-rt-runtime and cpu-rt-period can not be greater than their parent, cpu-rt-runtime requires sys_nice -func ValidateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error { - // We may not be passed a host config, such as in the case of docker commit - if hc == nil { - return nil - } - - if hc.Resources.CPURealtimePeriod > 0 && !si.CPURealtimePeriod { - return fmt.Errorf("invalid --cpu-rt-period: Your kernel does not support cgroup rt period") - } - - if hc.Resources.CPURealtimeRuntime > 0 && !si.CPURealtimeRuntime { - return fmt.Errorf("invalid --cpu-rt-runtime: Your kernel does not support cgroup rt runtime") - } - - if hc.Resources.CPURealtimePeriod != 0 && hc.Resources.CPURealtimeRuntime != 0 && hc.Resources.CPURealtimeRuntime > hc.Resources.CPURealtimePeriod { - return fmt.Errorf("invalid --cpu-rt-runtime: rt runtime cannot be higher than rt period") - } - return nil -} diff --git a/vendor/github.com/docker/docker/runconfig/hostconfig_windows.go b/vendor/github.com/docker/docker/runconfig/hostconfig_windows.go deleted file mode 100644 index 91bd6dc..0000000 --- a/vendor/github.com/docker/docker/runconfig/hostconfig_windows.go +++ /dev/null @@ -1,68 +0,0 @@ -package runconfig - -import ( - "fmt" - "strings" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/sysinfo" -) - -// DefaultDaemonNetworkMode returns the default network stack the daemon should -// use. -func DefaultDaemonNetworkMode() container.NetworkMode { - return container.NetworkMode("nat") -} - -// IsPreDefinedNetwork indicates if a network is predefined by the daemon -func IsPreDefinedNetwork(network string) bool { - return !container.NetworkMode(network).IsUserDefined() -} - -// ValidateNetMode ensures that the various combinations of requested -// network settings are valid. -func ValidateNetMode(c *container.Config, hc *container.HostConfig) error { - if hc == nil { - return nil - } - parts := strings.Split(string(hc.NetworkMode), ":") - if len(parts) > 1 { - return fmt.Errorf("invalid --net: %s", hc.NetworkMode) - } - return nil -} - -// ValidateIsolation performs platform specific validation of the -// isolation in the hostconfig structure. Windows supports 'default' (or -// blank), 'process', or 'hyperv'. -func ValidateIsolation(hc *container.HostConfig) error { - // We may not be passed a host config, such as in the case of docker commit - if hc == nil { - return nil - } - if !hc.Isolation.IsValid() { - return fmt.Errorf("invalid --isolation: %q. Windows supports 'default', 'process', or 'hyperv'", hc.Isolation) - } - return nil -} - -// ValidateQoS performs platform specific validation of the Qos settings -func ValidateQoS(hc *container.HostConfig) error { - return nil -} - -// ValidateResources performs platform specific validation of the resource settings -func ValidateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error { - // We may not be passed a host config, such as in the case of docker commit - if hc == nil { - return nil - } - - if hc.Resources.CPURealtimePeriod != 0 { - return fmt.Errorf("invalid --cpu-rt-period: Windows does not support this feature") - } - if hc.Resources.CPURealtimeRuntime != 0 { - return fmt.Errorf("invalid --cpu-rt-runtime: Windows does not support this feature") - } - return nil -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/envfile.go b/vendor/github.com/docker/docker/runconfig/opts/envfile.go deleted file mode 100644 index f723799..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/envfile.go +++ /dev/null @@ -1,81 +0,0 @@ -package opts - -import ( - "bufio" - "bytes" - "fmt" - "os" - "strings" - "unicode" - "unicode/utf8" -) - -// ParseEnvFile reads a file with environment variables enumerated by lines -// -// ``Environment variable names used by the utilities in the Shell and -// Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase -// letters, digits, and the '_' (underscore) from the characters defined in -// Portable Character Set and do not begin with a digit. *But*, other -// characters may be permitted by an implementation; applications shall -// tolerate the presence of such names.'' -// -- http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html -// -// As of #16585, it's up to application inside docker to validate or not -// environment variables, that's why we just strip leading whitespace and -// nothing more. -func ParseEnvFile(filename string) ([]string, error) { - fh, err := os.Open(filename) - if err != nil { - return []string{}, err - } - defer fh.Close() - - lines := []string{} - scanner := bufio.NewScanner(fh) - currentLine := 0 - utf8bom := []byte{0xEF, 0xBB, 0xBF} - for scanner.Scan() { - scannedBytes := scanner.Bytes() - if !utf8.Valid(scannedBytes) { - return []string{}, fmt.Errorf("env file %s contains invalid utf8 bytes at line %d: %v", filename, currentLine+1, scannedBytes) - } - // We trim UTF8 BOM - if currentLine == 0 { - scannedBytes = bytes.TrimPrefix(scannedBytes, utf8bom) - } - // trim the line from all leading whitespace first - line := strings.TrimLeftFunc(string(scannedBytes), unicode.IsSpace) - currentLine++ - // line is not empty, and not starting with '#' - if len(line) > 0 && !strings.HasPrefix(line, "#") { - data := strings.SplitN(line, "=", 2) - - // trim the front of a variable, but nothing else - variable := strings.TrimLeft(data[0], whiteSpaces) - if strings.ContainsAny(variable, whiteSpaces) { - return []string{}, ErrBadEnvVariable{fmt.Sprintf("variable '%s' has white spaces", variable)} - } - - if len(data) > 1 { - - // pass the value through, no trimming - lines = append(lines, fmt.Sprintf("%s=%s", variable, data[1])) - } else { - // if only a pass-through variable is given, clean it up. - lines = append(lines, fmt.Sprintf("%s=%s", strings.TrimSpace(line), os.Getenv(line))) - } - } - } - return lines, scanner.Err() -} - -var whiteSpaces = " \t" - -// ErrBadEnvVariable typed error for bad environment variable -type ErrBadEnvVariable struct { - msg string -} - -func (e ErrBadEnvVariable) Error() string { - return fmt.Sprintf("poorly formatted environment: %s", e.msg) -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/envfile_test.go b/vendor/github.com/docker/docker/runconfig/opts/envfile_test.go deleted file mode 100644 index 5dd7078..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/envfile_test.go +++ /dev/null @@ -1,142 +0,0 @@ -package opts - -import ( - "bufio" - "fmt" - "io/ioutil" - "os" - "reflect" - "strings" - "testing" -) - -func tmpFileWithContent(content string, t *testing.T) string { - tmpFile, err := ioutil.TempFile("", "envfile-test") - if err != nil { - t.Fatal(err) - } - defer tmpFile.Close() - - tmpFile.WriteString(content) - return tmpFile.Name() -} - -// Test ParseEnvFile for a file with a few well formatted lines -func TestParseEnvFileGoodFile(t *testing.T) { - content := `foo=bar - baz=quux -# comment - -_foobar=foobaz -with.dots=working -and_underscore=working too -` - // Adding a newline + a line with pure whitespace. - // This is being done like this instead of the block above - // because it's common for editors to trim trailing whitespace - // from lines, which becomes annoying since that's the - // exact thing we need to test. - content += "\n \t " - tmpFile := tmpFileWithContent(content, t) - defer os.Remove(tmpFile) - - lines, err := ParseEnvFile(tmpFile) - if err != nil { - t.Fatal(err) - } - - expectedLines := []string{ - "foo=bar", - "baz=quux", - "_foobar=foobaz", - "with.dots=working", - "and_underscore=working too", - } - - if !reflect.DeepEqual(lines, expectedLines) { - t.Fatal("lines not equal to expected_lines") - } -} - -// Test ParseEnvFile for an empty file -func TestParseEnvFileEmptyFile(t *testing.T) { - tmpFile := tmpFileWithContent("", t) - defer os.Remove(tmpFile) - - lines, err := ParseEnvFile(tmpFile) - if err != nil { - t.Fatal(err) - } - - if len(lines) != 0 { - t.Fatal("lines not empty; expected empty") - } -} - -// Test ParseEnvFile for a non existent file -func TestParseEnvFileNonExistentFile(t *testing.T) { - _, err := ParseEnvFile("foo_bar_baz") - if err == nil { - t.Fatal("ParseEnvFile succeeded; expected failure") - } - if _, ok := err.(*os.PathError); !ok { - t.Fatalf("Expected a PathError, got [%v]", err) - } -} - -// Test ParseEnvFile for a badly formatted file -func TestParseEnvFileBadlyFormattedFile(t *testing.T) { - content := `foo=bar - f =quux -` - - tmpFile := tmpFileWithContent(content, t) - defer os.Remove(tmpFile) - - _, err := ParseEnvFile(tmpFile) - if err == nil { - t.Fatalf("Expected an ErrBadEnvVariable, got nothing") - } - if _, ok := err.(ErrBadEnvVariable); !ok { - t.Fatalf("Expected an ErrBadEnvVariable, got [%v]", err) - } - expectedMessage := "poorly formatted environment: variable 'f ' has white spaces" - if err.Error() != expectedMessage { - t.Fatalf("Expected [%v], got [%v]", expectedMessage, err.Error()) - } -} - -// Test ParseEnvFile for a file with a line exceeding bufio.MaxScanTokenSize -func TestParseEnvFileLineTooLongFile(t *testing.T) { - content := strings.Repeat("a", bufio.MaxScanTokenSize+42) - content = fmt.Sprint("foo=", content) - - tmpFile := tmpFileWithContent(content, t) - defer os.Remove(tmpFile) - - _, err := ParseEnvFile(tmpFile) - if err == nil { - t.Fatal("ParseEnvFile succeeded; expected failure") - } -} - -// ParseEnvFile with a random file, pass through -func TestParseEnvFileRandomFile(t *testing.T) { - content := `first line -another invalid line` - tmpFile := tmpFileWithContent(content, t) - defer os.Remove(tmpFile) - - _, err := ParseEnvFile(tmpFile) - - if err == nil { - t.Fatalf("Expected an ErrBadEnvVariable, got nothing") - } - if _, ok := err.(ErrBadEnvVariable); !ok { - t.Fatalf("Expected an ErrBadEnvvariable, got [%v]", err) - } - expectedMessage := "poorly formatted environment: variable 'first line' has white spaces" - if err.Error() != expectedMessage { - t.Fatalf("Expected [%v], got [%v]", expectedMessage, err.Error()) - } -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/fixtures/utf16.env b/vendor/github.com/docker/docker/runconfig/opts/fixtures/utf16.env deleted file mode 100755 index 3a73358..0000000 Binary files a/vendor/github.com/docker/docker/runconfig/opts/fixtures/utf16.env and /dev/null differ diff --git a/vendor/github.com/docker/docker/runconfig/opts/fixtures/utf16be.env b/vendor/github.com/docker/docker/runconfig/opts/fixtures/utf16be.env deleted file mode 100755 index e523da7..0000000 Binary files a/vendor/github.com/docker/docker/runconfig/opts/fixtures/utf16be.env and /dev/null differ diff --git a/vendor/github.com/docker/docker/runconfig/opts/fixtures/utf8.env b/vendor/github.com/docker/docker/runconfig/opts/fixtures/utf8.env deleted file mode 100755 index 1ce4505..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/fixtures/utf8.env +++ /dev/null @@ -1,3 +0,0 @@ -FOO=BAR -HELLO=您好 -BAR=FOO \ No newline at end of file diff --git a/vendor/github.com/docker/docker/runconfig/opts/fixtures/valid.env b/vendor/github.com/docker/docker/runconfig/opts/fixtures/valid.env deleted file mode 100644 index 3afbdc8..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/fixtures/valid.env +++ /dev/null @@ -1 +0,0 @@ -ENV1=value1 diff --git a/vendor/github.com/docker/docker/runconfig/opts/fixtures/valid.label b/vendor/github.com/docker/docker/runconfig/opts/fixtures/valid.label deleted file mode 100644 index b4208bd..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/fixtures/valid.label +++ /dev/null @@ -1 +0,0 @@ -LABEL1=value1 diff --git a/vendor/github.com/docker/docker/runconfig/opts/opts.go b/vendor/github.com/docker/docker/runconfig/opts/opts.go deleted file mode 100644 index cae0432..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/opts.go +++ /dev/null @@ -1,83 +0,0 @@ -package opts - -import ( - "fmt" - "net" - "os" - "runtime" - "strings" - - fopts "github.com/docker/docker/opts" -) - -// ValidateAttach validates that the specified string is a valid attach option. -func ValidateAttach(val string) (string, error) { - s := strings.ToLower(val) - for _, str := range []string{"stdin", "stdout", "stderr"} { - if s == str { - return s, nil - } - } - return val, fmt.Errorf("valid streams are STDIN, STDOUT and STDERR") -} - -// ValidateEnv validates an environment variable and returns it. -// If no value is specified, it returns the current value using os.Getenv. -// -// As on ParseEnvFile and related to #16585, environment variable names -// are not validate what so ever, it's up to application inside docker -// to validate them or not. -// -// The only validation here is to check if name is empty, per #25099 -func ValidateEnv(val string) (string, error) { - arr := strings.Split(val, "=") - if arr[0] == "" { - return "", fmt.Errorf("invalid environment variable: %s", val) - } - if len(arr) > 1 { - return val, nil - } - if !doesEnvExist(val) { - return val, nil - } - return fmt.Sprintf("%s=%s", val, os.Getenv(val)), nil -} - -func doesEnvExist(name string) bool { - for _, entry := range os.Environ() { - parts := strings.SplitN(entry, "=", 2) - if runtime.GOOS == "windows" { - // Environment variable are case-insensitive on Windows. PaTh, path and PATH are equivalent. - if strings.EqualFold(parts[0], name) { - return true - } - } - if parts[0] == name { - return true - } - } - return false -} - -// ValidateExtraHost validates that the specified string is a valid extrahost and returns it. -// ExtraHost is in the form of name:ip where the ip has to be a valid ip (IPv4 or IPv6). -func ValidateExtraHost(val string) (string, error) { - // allow for IPv6 addresses in extra hosts by only splitting on first ":" - arr := strings.SplitN(val, ":", 2) - if len(arr) != 2 || len(arr[0]) == 0 { - return "", fmt.Errorf("bad format for add-host: %q", val) - } - if _, err := fopts.ValidateIPAddress(arr[1]); err != nil { - return "", fmt.Errorf("invalid IP address in add-host: %q", arr[1]) - } - return val, nil -} - -// ValidateMACAddress validates a MAC address. -func ValidateMACAddress(val string) (string, error) { - _, err := net.ParseMAC(strings.TrimSpace(val)) - if err != nil { - return "", err - } - return val, nil -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/opts_test.go b/vendor/github.com/docker/docker/runconfig/opts/opts_test.go deleted file mode 100644 index 43f8730..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/opts_test.go +++ /dev/null @@ -1,113 +0,0 @@ -package opts - -import ( - "fmt" - "os" - "runtime" - "strings" - "testing" -) - -func TestValidateAttach(t *testing.T) { - valid := []string{ - "stdin", - "stdout", - "stderr", - "STDIN", - "STDOUT", - "STDERR", - } - if _, err := ValidateAttach("invalid"); err == nil { - t.Fatalf("Expected error with [valid streams are STDIN, STDOUT and STDERR], got nothing") - } - - for _, attach := range valid { - value, err := ValidateAttach(attach) - if err != nil { - t.Fatal(err) - } - if value != strings.ToLower(attach) { - t.Fatalf("Expected [%v], got [%v]", attach, value) - } - } -} - -func TestValidateEnv(t *testing.T) { - valids := map[string]string{ - "a": "a", - "something": "something", - "_=a": "_=a", - "env1=value1": "env1=value1", - "_env1=value1": "_env1=value1", - "env2=value2=value3": "env2=value2=value3", - "env3=abc!qwe": "env3=abc!qwe", - "env_4=value 4": "env_4=value 4", - "PATH": fmt.Sprintf("PATH=%v", os.Getenv("PATH")), - "PATH=something": "PATH=something", - "asd!qwe": "asd!qwe", - "1asd": "1asd", - "123": "123", - "some space": "some space", - " some space before": " some space before", - "some space after ": "some space after ", - } - // Environment variables are case in-sensitive on Windows - if runtime.GOOS == "windows" { - valids["PaTh"] = fmt.Sprintf("PaTh=%v", os.Getenv("PATH")) - } - for value, expected := range valids { - actual, err := ValidateEnv(value) - if err != nil { - t.Fatal(err) - } - if actual != expected { - t.Fatalf("Expected [%v], got [%v]", expected, actual) - } - } -} - -func TestValidateExtraHosts(t *testing.T) { - valid := []string{ - `myhost:192.168.0.1`, - `thathost:10.0.2.1`, - `anipv6host:2003:ab34:e::1`, - `ipv6local:::1`, - } - - invalid := map[string]string{ - `myhost:192.notanipaddress.1`: `invalid IP`, - `thathost-nosemicolon10.0.0.1`: `bad format`, - `anipv6host:::::1`: `invalid IP`, - `ipv6local:::0::`: `invalid IP`, - } - - for _, extrahost := range valid { - if _, err := ValidateExtraHost(extrahost); err != nil { - t.Fatalf("ValidateExtraHost(`"+extrahost+"`) should succeed: error %v", err) - } - } - - for extraHost, expectedError := range invalid { - if _, err := ValidateExtraHost(extraHost); err == nil { - t.Fatalf("ValidateExtraHost(`%q`) should have failed validation", extraHost) - } else { - if !strings.Contains(err.Error(), expectedError) { - t.Fatalf("ValidateExtraHost(`%q`) error should contain %q", extraHost, expectedError) - } - } - } -} - -func TestValidateMACAddress(t *testing.T) { - if _, err := ValidateMACAddress(`92:d0:c6:0a:29:33`); err != nil { - t.Fatalf("ValidateMACAddress(`92:d0:c6:0a:29:33`) got %s", err) - } - - if _, err := ValidateMACAddress(`92:d0:c6:0a:33`); err == nil { - t.Fatalf("ValidateMACAddress(`92:d0:c6:0a:33`) succeeded; expected failure on invalid MAC") - } - - if _, err := ValidateMACAddress(`random invalid string`); err == nil { - t.Fatalf("ValidateMACAddress(`random invalid string`) succeeded; expected failure on invalid MAC") - } -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/parse.go b/vendor/github.com/docker/docker/runconfig/opts/parse.go deleted file mode 100644 index 71a8927..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/parse.go +++ /dev/null @@ -1,995 +0,0 @@ -package opts - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "path" - "strconv" - "strings" - "time" - - "github.com/docker/docker/api/types/container" - networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/api/types/strslice" - "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/signal" - "github.com/docker/go-connections/nat" - units "github.com/docker/go-units" - "github.com/spf13/pflag" -) - -// ContainerOptions is a data object with all the options for creating a container -type ContainerOptions struct { - attach opts.ListOpts - volumes opts.ListOpts - tmpfs opts.ListOpts - blkioWeightDevice WeightdeviceOpt - deviceReadBps ThrottledeviceOpt - deviceWriteBps ThrottledeviceOpt - links opts.ListOpts - aliases opts.ListOpts - linkLocalIPs opts.ListOpts - deviceReadIOps ThrottledeviceOpt - deviceWriteIOps ThrottledeviceOpt - env opts.ListOpts - labels opts.ListOpts - devices opts.ListOpts - ulimits *UlimitOpt - sysctls *opts.MapOpts - publish opts.ListOpts - expose opts.ListOpts - dns opts.ListOpts - dnsSearch opts.ListOpts - dnsOptions opts.ListOpts - extraHosts opts.ListOpts - volumesFrom opts.ListOpts - envFile opts.ListOpts - capAdd opts.ListOpts - capDrop opts.ListOpts - groupAdd opts.ListOpts - securityOpt opts.ListOpts - storageOpt opts.ListOpts - labelsFile opts.ListOpts - loggingOpts opts.ListOpts - privileged bool - pidMode string - utsMode string - usernsMode string - publishAll bool - stdin bool - tty bool - oomKillDisable bool - oomScoreAdj int - containerIDFile string - entrypoint string - hostname string - memoryString string - memoryReservation string - memorySwap string - kernelMemory string - user string - workingDir string - cpuCount int64 - cpuShares int64 - cpuPercent int64 - cpuPeriod int64 - cpuRealtimePeriod int64 - cpuRealtimeRuntime int64 - cpuQuota int64 - cpus opts.NanoCPUs - cpusetCpus string - cpusetMems string - blkioWeight uint16 - ioMaxBandwidth string - ioMaxIOps uint64 - swappiness int64 - netMode string - macAddress string - ipv4Address string - ipv6Address string - ipcMode string - pidsLimit int64 - restartPolicy string - readonlyRootfs bool - loggingDriver string - cgroupParent string - volumeDriver string - stopSignal string - stopTimeout int - isolation string - shmSize string - noHealthcheck bool - healthCmd string - healthInterval time.Duration - healthTimeout time.Duration - healthRetries int - runtime string - autoRemove bool - init bool - initPath string - credentialSpec string - - Image string - Args []string -} - -// AddFlags adds all command line flags that will be used by Parse to the FlagSet -func AddFlags(flags *pflag.FlagSet) *ContainerOptions { - copts := &ContainerOptions{ - aliases: opts.NewListOpts(nil), - attach: opts.NewListOpts(ValidateAttach), - blkioWeightDevice: NewWeightdeviceOpt(ValidateWeightDevice), - capAdd: opts.NewListOpts(nil), - capDrop: opts.NewListOpts(nil), - dns: opts.NewListOpts(opts.ValidateIPAddress), - dnsOptions: opts.NewListOpts(nil), - dnsSearch: opts.NewListOpts(opts.ValidateDNSSearch), - deviceReadBps: NewThrottledeviceOpt(ValidateThrottleBpsDevice), - deviceReadIOps: NewThrottledeviceOpt(ValidateThrottleIOpsDevice), - deviceWriteBps: NewThrottledeviceOpt(ValidateThrottleBpsDevice), - deviceWriteIOps: NewThrottledeviceOpt(ValidateThrottleIOpsDevice), - devices: opts.NewListOpts(ValidateDevice), - env: opts.NewListOpts(ValidateEnv), - envFile: opts.NewListOpts(nil), - expose: opts.NewListOpts(nil), - extraHosts: opts.NewListOpts(ValidateExtraHost), - groupAdd: opts.NewListOpts(nil), - labels: opts.NewListOpts(ValidateEnv), - labelsFile: opts.NewListOpts(nil), - linkLocalIPs: opts.NewListOpts(nil), - links: opts.NewListOpts(ValidateLink), - loggingOpts: opts.NewListOpts(nil), - publish: opts.NewListOpts(nil), - securityOpt: opts.NewListOpts(nil), - storageOpt: opts.NewListOpts(nil), - sysctls: opts.NewMapOpts(nil, opts.ValidateSysctl), - tmpfs: opts.NewListOpts(nil), - ulimits: NewUlimitOpt(nil), - volumes: opts.NewListOpts(nil), - volumesFrom: opts.NewListOpts(nil), - } - - // General purpose flags - flags.VarP(&copts.attach, "attach", "a", "Attach to STDIN, STDOUT or STDERR") - flags.Var(&copts.devices, "device", "Add a host device to the container") - flags.VarP(&copts.env, "env", "e", "Set environment variables") - flags.Var(&copts.envFile, "env-file", "Read in a file of environment variables") - flags.StringVar(&copts.entrypoint, "entrypoint", "", "Overwrite the default ENTRYPOINT of the image") - flags.Var(&copts.groupAdd, "group-add", "Add additional groups to join") - flags.StringVarP(&copts.hostname, "hostname", "h", "", "Container host name") - flags.BoolVarP(&copts.stdin, "interactive", "i", false, "Keep STDIN open even if not attached") - flags.VarP(&copts.labels, "label", "l", "Set meta data on a container") - flags.Var(&copts.labelsFile, "label-file", "Read in a line delimited file of labels") - flags.BoolVar(&copts.readonlyRootfs, "read-only", false, "Mount the container's root filesystem as read only") - flags.StringVar(&copts.restartPolicy, "restart", "no", "Restart policy to apply when a container exits") - flags.StringVar(&copts.stopSignal, "stop-signal", signal.DefaultStopSignal, fmt.Sprintf("Signal to stop a container, %v by default", signal.DefaultStopSignal)) - flags.IntVar(&copts.stopTimeout, "stop-timeout", 0, "Timeout (in seconds) to stop a container") - flags.SetAnnotation("stop-timeout", "version", []string{"1.25"}) - flags.Var(copts.sysctls, "sysctl", "Sysctl options") - flags.BoolVarP(&copts.tty, "tty", "t", false, "Allocate a pseudo-TTY") - flags.Var(copts.ulimits, "ulimit", "Ulimit options") - flags.StringVarP(&copts.user, "user", "u", "", "Username or UID (format: [:])") - flags.StringVarP(&copts.workingDir, "workdir", "w", "", "Working directory inside the container") - flags.BoolVar(&copts.autoRemove, "rm", false, "Automatically remove the container when it exits") - - // Security - flags.Var(&copts.capAdd, "cap-add", "Add Linux capabilities") - flags.Var(&copts.capDrop, "cap-drop", "Drop Linux capabilities") - flags.BoolVar(&copts.privileged, "privileged", false, "Give extended privileges to this container") - flags.Var(&copts.securityOpt, "security-opt", "Security Options") - flags.StringVar(&copts.usernsMode, "userns", "", "User namespace to use") - flags.StringVar(&copts.credentialSpec, "credentialspec", "", "Credential spec for managed service account (Windows only)") - - // Network and port publishing flag - flags.Var(&copts.extraHosts, "add-host", "Add a custom host-to-IP mapping (host:ip)") - flags.Var(&copts.dns, "dns", "Set custom DNS servers") - // We allow for both "--dns-opt" and "--dns-option", although the latter is the recommended way. - // This is to be consistent with service create/update - flags.Var(&copts.dnsOptions, "dns-opt", "Set DNS options") - flags.Var(&copts.dnsOptions, "dns-option", "Set DNS options") - flags.MarkHidden("dns-opt") - flags.Var(&copts.dnsSearch, "dns-search", "Set custom DNS search domains") - flags.Var(&copts.expose, "expose", "Expose a port or a range of ports") - flags.StringVar(&copts.ipv4Address, "ip", "", "Container IPv4 address (e.g. 172.30.100.104)") - flags.StringVar(&copts.ipv6Address, "ip6", "", "Container IPv6 address (e.g. 2001:db8::33)") - flags.Var(&copts.links, "link", "Add link to another container") - flags.Var(&copts.linkLocalIPs, "link-local-ip", "Container IPv4/IPv6 link-local addresses") - flags.StringVar(&copts.macAddress, "mac-address", "", "Container MAC address (e.g. 92:d0:c6:0a:29:33)") - flags.VarP(&copts.publish, "publish", "p", "Publish a container's port(s) to the host") - flags.BoolVarP(&copts.publishAll, "publish-all", "P", false, "Publish all exposed ports to random ports") - // We allow for both "--net" and "--network", although the latter is the recommended way. - flags.StringVar(&copts.netMode, "net", "default", "Connect a container to a network") - flags.StringVar(&copts.netMode, "network", "default", "Connect a container to a network") - flags.MarkHidden("net") - // We allow for both "--net-alias" and "--network-alias", although the latter is the recommended way. - flags.Var(&copts.aliases, "net-alias", "Add network-scoped alias for the container") - flags.Var(&copts.aliases, "network-alias", "Add network-scoped alias for the container") - flags.MarkHidden("net-alias") - - // Logging and storage - flags.StringVar(&copts.loggingDriver, "log-driver", "", "Logging driver for the container") - flags.StringVar(&copts.volumeDriver, "volume-driver", "", "Optional volume driver for the container") - flags.Var(&copts.loggingOpts, "log-opt", "Log driver options") - flags.Var(&copts.storageOpt, "storage-opt", "Storage driver options for the container") - flags.Var(&copts.tmpfs, "tmpfs", "Mount a tmpfs directory") - flags.Var(&copts.volumesFrom, "volumes-from", "Mount volumes from the specified container(s)") - flags.VarP(&copts.volumes, "volume", "v", "Bind mount a volume") - - // Health-checking - flags.StringVar(&copts.healthCmd, "health-cmd", "", "Command to run to check health") - flags.DurationVar(&copts.healthInterval, "health-interval", 0, "Time between running the check (ns|us|ms|s|m|h) (default 0s)") - flags.IntVar(&copts.healthRetries, "health-retries", 0, "Consecutive failures needed to report unhealthy") - flags.DurationVar(&copts.healthTimeout, "health-timeout", 0, "Maximum time to allow one check to run (ns|us|ms|s|m|h) (default 0s)") - flags.BoolVar(&copts.noHealthcheck, "no-healthcheck", false, "Disable any container-specified HEALTHCHECK") - - // Resource management - flags.Uint16Var(&copts.blkioWeight, "blkio-weight", 0, "Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)") - flags.Var(&copts.blkioWeightDevice, "blkio-weight-device", "Block IO weight (relative device weight)") - flags.StringVar(&copts.containerIDFile, "cidfile", "", "Write the container ID to the file") - flags.StringVar(&copts.cpusetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)") - flags.StringVar(&copts.cpusetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)") - flags.Int64Var(&copts.cpuCount, "cpu-count", 0, "CPU count (Windows only)") - flags.Int64Var(&copts.cpuPercent, "cpu-percent", 0, "CPU percent (Windows only)") - flags.Int64Var(&copts.cpuPeriod, "cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period") - flags.Int64Var(&copts.cpuQuota, "cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota") - flags.Int64Var(&copts.cpuRealtimePeriod, "cpu-rt-period", 0, "Limit CPU real-time period in microseconds") - flags.Int64Var(&copts.cpuRealtimeRuntime, "cpu-rt-runtime", 0, "Limit CPU real-time runtime in microseconds") - flags.Int64VarP(&copts.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)") - flags.Var(&copts.cpus, "cpus", "Number of CPUs") - flags.Var(&copts.deviceReadBps, "device-read-bps", "Limit read rate (bytes per second) from a device") - flags.Var(&copts.deviceReadIOps, "device-read-iops", "Limit read rate (IO per second) from a device") - flags.Var(&copts.deviceWriteBps, "device-write-bps", "Limit write rate (bytes per second) to a device") - flags.Var(&copts.deviceWriteIOps, "device-write-iops", "Limit write rate (IO per second) to a device") - flags.StringVar(&copts.ioMaxBandwidth, "io-maxbandwidth", "", "Maximum IO bandwidth limit for the system drive (Windows only)") - flags.Uint64Var(&copts.ioMaxIOps, "io-maxiops", 0, "Maximum IOps limit for the system drive (Windows only)") - flags.StringVar(&copts.kernelMemory, "kernel-memory", "", "Kernel memory limit") - flags.StringVarP(&copts.memoryString, "memory", "m", "", "Memory limit") - flags.StringVar(&copts.memoryReservation, "memory-reservation", "", "Memory soft limit") - flags.StringVar(&copts.memorySwap, "memory-swap", "", "Swap limit equal to memory plus swap: '-1' to enable unlimited swap") - flags.Int64Var(&copts.swappiness, "memory-swappiness", -1, "Tune container memory swappiness (0 to 100)") - flags.BoolVar(&copts.oomKillDisable, "oom-kill-disable", false, "Disable OOM Killer") - flags.IntVar(&copts.oomScoreAdj, "oom-score-adj", 0, "Tune host's OOM preferences (-1000 to 1000)") - flags.Int64Var(&copts.pidsLimit, "pids-limit", 0, "Tune container pids limit (set -1 for unlimited)") - - // Low-level execution (cgroups, namespaces, ...) - flags.StringVar(&copts.cgroupParent, "cgroup-parent", "", "Optional parent cgroup for the container") - flags.StringVar(&copts.ipcMode, "ipc", "", "IPC namespace to use") - flags.StringVar(&copts.isolation, "isolation", "", "Container isolation technology") - flags.StringVar(&copts.pidMode, "pid", "", "PID namespace to use") - flags.StringVar(&copts.shmSize, "shm-size", "", "Size of /dev/shm, default value is 64MB") - flags.StringVar(&copts.utsMode, "uts", "", "UTS namespace to use") - flags.StringVar(&copts.runtime, "runtime", "", "Runtime to use for this container") - - flags.BoolVar(&copts.init, "init", false, "Run an init inside the container that forwards signals and reaps processes") - flags.StringVar(&copts.initPath, "init-path", "", "Path to the docker-init binary") - return copts -} - -// Parse parses the args for the specified command and generates a Config, -// a HostConfig and returns them with the specified command. -// If the specified args are not valid, it will return an error. -func Parse(flags *pflag.FlagSet, copts *ContainerOptions) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) { - var ( - attachStdin = copts.attach.Get("stdin") - attachStdout = copts.attach.Get("stdout") - attachStderr = copts.attach.Get("stderr") - ) - - // Validate the input mac address - if copts.macAddress != "" { - if _, err := ValidateMACAddress(copts.macAddress); err != nil { - return nil, nil, nil, fmt.Errorf("%s is not a valid mac address", copts.macAddress) - } - } - if copts.stdin { - attachStdin = true - } - // If -a is not set, attach to stdout and stderr - if copts.attach.Len() == 0 { - attachStdout = true - attachStderr = true - } - - var err error - - var memory int64 - if copts.memoryString != "" { - memory, err = units.RAMInBytes(copts.memoryString) - if err != nil { - return nil, nil, nil, err - } - } - - var memoryReservation int64 - if copts.memoryReservation != "" { - memoryReservation, err = units.RAMInBytes(copts.memoryReservation) - if err != nil { - return nil, nil, nil, err - } - } - - var memorySwap int64 - if copts.memorySwap != "" { - if copts.memorySwap == "-1" { - memorySwap = -1 - } else { - memorySwap, err = units.RAMInBytes(copts.memorySwap) - if err != nil { - return nil, nil, nil, err - } - } - } - - var kernelMemory int64 - if copts.kernelMemory != "" { - kernelMemory, err = units.RAMInBytes(copts.kernelMemory) - if err != nil { - return nil, nil, nil, err - } - } - - swappiness := copts.swappiness - if swappiness != -1 && (swappiness < 0 || swappiness > 100) { - return nil, nil, nil, fmt.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness) - } - - var shmSize int64 - if copts.shmSize != "" { - shmSize, err = units.RAMInBytes(copts.shmSize) - if err != nil { - return nil, nil, nil, err - } - } - - // TODO FIXME units.RAMInBytes should have a uint64 version - var maxIOBandwidth int64 - if copts.ioMaxBandwidth != "" { - maxIOBandwidth, err = units.RAMInBytes(copts.ioMaxBandwidth) - if err != nil { - return nil, nil, nil, err - } - if maxIOBandwidth < 0 { - return nil, nil, nil, fmt.Errorf("invalid value: %s. Maximum IO Bandwidth must be positive", copts.ioMaxBandwidth) - } - } - - var binds []string - volumes := copts.volumes.GetMap() - // add any bind targets to the list of container volumes - for bind := range copts.volumes.GetMap() { - if arr := volumeSplitN(bind, 2); len(arr) > 1 { - // after creating the bind mount we want to delete it from the copts.volumes values because - // we do not want bind mounts being committed to image configs - binds = append(binds, bind) - // We should delete from the map (`volumes`) here, as deleting from copts.volumes will not work if - // there are duplicates entries. - delete(volumes, bind) - } - } - - // Can't evaluate options passed into --tmpfs until we actually mount - tmpfs := make(map[string]string) - for _, t := range copts.tmpfs.GetAll() { - if arr := strings.SplitN(t, ":", 2); len(arr) > 1 { - tmpfs[arr[0]] = arr[1] - } else { - tmpfs[arr[0]] = "" - } - } - - var ( - runCmd strslice.StrSlice - entrypoint strslice.StrSlice - ) - - if len(copts.Args) > 0 { - runCmd = strslice.StrSlice(copts.Args) - } - - if copts.entrypoint != "" { - entrypoint = strslice.StrSlice{copts.entrypoint} - } else if flags.Changed("entrypoint") { - // if `--entrypoint=` is parsed then Entrypoint is reset - entrypoint = []string{""} - } - - ports, portBindings, err := nat.ParsePortSpecs(copts.publish.GetAll()) - if err != nil { - return nil, nil, nil, err - } - - // Merge in exposed ports to the map of published ports - for _, e := range copts.expose.GetAll() { - if strings.Contains(e, ":") { - return nil, nil, nil, fmt.Errorf("invalid port format for --expose: %s", e) - } - //support two formats for expose, original format /[] or /[] - proto, port := nat.SplitProtoPort(e) - //parse the start and end port and create a sequence of ports to expose - //if expose a port, the start and end port are the same - start, end, err := nat.ParsePortRange(port) - if err != nil { - return nil, nil, nil, fmt.Errorf("invalid range format for --expose: %s, error: %s", e, err) - } - for i := start; i <= end; i++ { - p, err := nat.NewPort(proto, strconv.FormatUint(i, 10)) - if err != nil { - return nil, nil, nil, err - } - if _, exists := ports[p]; !exists { - ports[p] = struct{}{} - } - } - } - - // parse device mappings - deviceMappings := []container.DeviceMapping{} - for _, device := range copts.devices.GetAll() { - deviceMapping, err := ParseDevice(device) - if err != nil { - return nil, nil, nil, err - } - deviceMappings = append(deviceMappings, deviceMapping) - } - - // collect all the environment variables for the container - envVariables, err := ReadKVStrings(copts.envFile.GetAll(), copts.env.GetAll()) - if err != nil { - return nil, nil, nil, err - } - - // collect all the labels for the container - labels, err := ReadKVStrings(copts.labelsFile.GetAll(), copts.labels.GetAll()) - if err != nil { - return nil, nil, nil, err - } - - ipcMode := container.IpcMode(copts.ipcMode) - if !ipcMode.Valid() { - return nil, nil, nil, fmt.Errorf("--ipc: invalid IPC mode") - } - - pidMode := container.PidMode(copts.pidMode) - if !pidMode.Valid() { - return nil, nil, nil, fmt.Errorf("--pid: invalid PID mode") - } - - utsMode := container.UTSMode(copts.utsMode) - if !utsMode.Valid() { - return nil, nil, nil, fmt.Errorf("--uts: invalid UTS mode") - } - - usernsMode := container.UsernsMode(copts.usernsMode) - if !usernsMode.Valid() { - return nil, nil, nil, fmt.Errorf("--userns: invalid USER mode") - } - - restartPolicy, err := ParseRestartPolicy(copts.restartPolicy) - if err != nil { - return nil, nil, nil, err - } - - loggingOpts, err := parseLoggingOpts(copts.loggingDriver, copts.loggingOpts.GetAll()) - if err != nil { - return nil, nil, nil, err - } - - securityOpts, err := parseSecurityOpts(copts.securityOpt.GetAll()) - if err != nil { - return nil, nil, nil, err - } - - storageOpts, err := parseStorageOpts(copts.storageOpt.GetAll()) - if err != nil { - return nil, nil, nil, err - } - - // Healthcheck - var healthConfig *container.HealthConfig - haveHealthSettings := copts.healthCmd != "" || - copts.healthInterval != 0 || - copts.healthTimeout != 0 || - copts.healthRetries != 0 - if copts.noHealthcheck { - if haveHealthSettings { - return nil, nil, nil, fmt.Errorf("--no-healthcheck conflicts with --health-* options") - } - test := strslice.StrSlice{"NONE"} - healthConfig = &container.HealthConfig{Test: test} - } else if haveHealthSettings { - var probe strslice.StrSlice - if copts.healthCmd != "" { - args := []string{"CMD-SHELL", copts.healthCmd} - probe = strslice.StrSlice(args) - } - if copts.healthInterval < 0 { - return nil, nil, nil, fmt.Errorf("--health-interval cannot be negative") - } - if copts.healthTimeout < 0 { - return nil, nil, nil, fmt.Errorf("--health-timeout cannot be negative") - } - - healthConfig = &container.HealthConfig{ - Test: probe, - Interval: copts.healthInterval, - Timeout: copts.healthTimeout, - Retries: copts.healthRetries, - } - } - - resources := container.Resources{ - CgroupParent: copts.cgroupParent, - Memory: memory, - MemoryReservation: memoryReservation, - MemorySwap: memorySwap, - MemorySwappiness: &copts.swappiness, - KernelMemory: kernelMemory, - OomKillDisable: &copts.oomKillDisable, - NanoCPUs: copts.cpus.Value(), - CPUCount: copts.cpuCount, - CPUPercent: copts.cpuPercent, - CPUShares: copts.cpuShares, - CPUPeriod: copts.cpuPeriod, - CpusetCpus: copts.cpusetCpus, - CpusetMems: copts.cpusetMems, - CPUQuota: copts.cpuQuota, - CPURealtimePeriod: copts.cpuRealtimePeriod, - CPURealtimeRuntime: copts.cpuRealtimeRuntime, - PidsLimit: copts.pidsLimit, - BlkioWeight: copts.blkioWeight, - BlkioWeightDevice: copts.blkioWeightDevice.GetList(), - BlkioDeviceReadBps: copts.deviceReadBps.GetList(), - BlkioDeviceWriteBps: copts.deviceWriteBps.GetList(), - BlkioDeviceReadIOps: copts.deviceReadIOps.GetList(), - BlkioDeviceWriteIOps: copts.deviceWriteIOps.GetList(), - IOMaximumIOps: copts.ioMaxIOps, - IOMaximumBandwidth: uint64(maxIOBandwidth), - Ulimits: copts.ulimits.GetList(), - Devices: deviceMappings, - } - - config := &container.Config{ - Hostname: copts.hostname, - ExposedPorts: ports, - User: copts.user, - Tty: copts.tty, - // TODO: deprecated, it comes from -n, --networking - // it's still needed internally to set the network to disabled - // if e.g. bridge is none in daemon opts, and in inspect - NetworkDisabled: false, - OpenStdin: copts.stdin, - AttachStdin: attachStdin, - AttachStdout: attachStdout, - AttachStderr: attachStderr, - Env: envVariables, - Cmd: runCmd, - Image: copts.Image, - Volumes: volumes, - MacAddress: copts.macAddress, - Entrypoint: entrypoint, - WorkingDir: copts.workingDir, - Labels: ConvertKVStringsToMap(labels), - Healthcheck: healthConfig, - } - if flags.Changed("stop-signal") { - config.StopSignal = copts.stopSignal - } - if flags.Changed("stop-timeout") { - config.StopTimeout = &copts.stopTimeout - } - - hostConfig := &container.HostConfig{ - Binds: binds, - ContainerIDFile: copts.containerIDFile, - OomScoreAdj: copts.oomScoreAdj, - AutoRemove: copts.autoRemove, - Privileged: copts.privileged, - PortBindings: portBindings, - Links: copts.links.GetAll(), - PublishAllPorts: copts.publishAll, - // Make sure the dns fields are never nil. - // New containers don't ever have those fields nil, - // but pre created containers can still have those nil values. - // See https://github.com/docker/docker/pull/17779 - // for a more detailed explanation on why we don't want that. - DNS: copts.dns.GetAllOrEmpty(), - DNSSearch: copts.dnsSearch.GetAllOrEmpty(), - DNSOptions: copts.dnsOptions.GetAllOrEmpty(), - ExtraHosts: copts.extraHosts.GetAll(), - VolumesFrom: copts.volumesFrom.GetAll(), - NetworkMode: container.NetworkMode(copts.netMode), - IpcMode: ipcMode, - PidMode: pidMode, - UTSMode: utsMode, - UsernsMode: usernsMode, - CapAdd: strslice.StrSlice(copts.capAdd.GetAll()), - CapDrop: strslice.StrSlice(copts.capDrop.GetAll()), - GroupAdd: copts.groupAdd.GetAll(), - RestartPolicy: restartPolicy, - SecurityOpt: securityOpts, - StorageOpt: storageOpts, - ReadonlyRootfs: copts.readonlyRootfs, - LogConfig: container.LogConfig{Type: copts.loggingDriver, Config: loggingOpts}, - VolumeDriver: copts.volumeDriver, - Isolation: container.Isolation(copts.isolation), - ShmSize: shmSize, - Resources: resources, - Tmpfs: tmpfs, - Sysctls: copts.sysctls.GetAll(), - Runtime: copts.runtime, - } - - // only set this value if the user provided the flag, else it should default to nil - if flags.Changed("init") { - hostConfig.Init = &copts.init - } - - // When allocating stdin in attached mode, close stdin at client disconnect - if config.OpenStdin && config.AttachStdin { - config.StdinOnce = true - } - - networkingConfig := &networktypes.NetworkingConfig{ - EndpointsConfig: make(map[string]*networktypes.EndpointSettings), - } - - if copts.ipv4Address != "" || copts.ipv6Address != "" || copts.linkLocalIPs.Len() > 0 { - epConfig := &networktypes.EndpointSettings{} - networkingConfig.EndpointsConfig[string(hostConfig.NetworkMode)] = epConfig - - epConfig.IPAMConfig = &networktypes.EndpointIPAMConfig{ - IPv4Address: copts.ipv4Address, - IPv6Address: copts.ipv6Address, - } - - if copts.linkLocalIPs.Len() > 0 { - epConfig.IPAMConfig.LinkLocalIPs = make([]string, copts.linkLocalIPs.Len()) - copy(epConfig.IPAMConfig.LinkLocalIPs, copts.linkLocalIPs.GetAll()) - } - } - - if hostConfig.NetworkMode.IsUserDefined() && len(hostConfig.Links) > 0 { - epConfig := networkingConfig.EndpointsConfig[string(hostConfig.NetworkMode)] - if epConfig == nil { - epConfig = &networktypes.EndpointSettings{} - } - epConfig.Links = make([]string, len(hostConfig.Links)) - copy(epConfig.Links, hostConfig.Links) - networkingConfig.EndpointsConfig[string(hostConfig.NetworkMode)] = epConfig - } - - if copts.aliases.Len() > 0 { - epConfig := networkingConfig.EndpointsConfig[string(hostConfig.NetworkMode)] - if epConfig == nil { - epConfig = &networktypes.EndpointSettings{} - } - epConfig.Aliases = make([]string, copts.aliases.Len()) - copy(epConfig.Aliases, copts.aliases.GetAll()) - networkingConfig.EndpointsConfig[string(hostConfig.NetworkMode)] = epConfig - } - - return config, hostConfig, networkingConfig, nil -} - -// ReadKVStrings reads a file of line terminated key=value pairs, and overrides any keys -// present in the file with additional pairs specified in the override parameter -func ReadKVStrings(files []string, override []string) ([]string, error) { - envVariables := []string{} - for _, ef := range files { - parsedVars, err := ParseEnvFile(ef) - if err != nil { - return nil, err - } - envVariables = append(envVariables, parsedVars...) - } - // parse the '-e' and '--env' after, to allow override - envVariables = append(envVariables, override...) - - return envVariables, nil -} - -// ConvertKVStringsToMap converts ["key=value"] to {"key":"value"} -func ConvertKVStringsToMap(values []string) map[string]string { - result := make(map[string]string, len(values)) - for _, value := range values { - kv := strings.SplitN(value, "=", 2) - if len(kv) == 1 { - result[kv[0]] = "" - } else { - result[kv[0]] = kv[1] - } - } - - return result -} - -// ConvertKVStringsToMapWithNil converts ["key=value"] to {"key":"value"} -// but set unset keys to nil - meaning the ones with no "=" in them. -// We use this in cases where we need to distinguish between -// FOO= and FOO -// where the latter case just means FOO was mentioned but not given a value -func ConvertKVStringsToMapWithNil(values []string) map[string]*string { - result := make(map[string]*string, len(values)) - for _, value := range values { - kv := strings.SplitN(value, "=", 2) - if len(kv) == 1 { - result[kv[0]] = nil - } else { - result[kv[0]] = &kv[1] - } - } - - return result -} - -func parseLoggingOpts(loggingDriver string, loggingOpts []string) (map[string]string, error) { - loggingOptsMap := ConvertKVStringsToMap(loggingOpts) - if loggingDriver == "none" && len(loggingOpts) > 0 { - return map[string]string{}, fmt.Errorf("invalid logging opts for driver %s", loggingDriver) - } - return loggingOptsMap, nil -} - -// takes a local seccomp daemon, reads the file contents for sending to the daemon -func parseSecurityOpts(securityOpts []string) ([]string, error) { - for key, opt := range securityOpts { - con := strings.SplitN(opt, "=", 2) - if len(con) == 1 && con[0] != "no-new-privileges" { - if strings.Contains(opt, ":") { - con = strings.SplitN(opt, ":", 2) - } else { - return securityOpts, fmt.Errorf("Invalid --security-opt: %q", opt) - } - } - if con[0] == "seccomp" && con[1] != "unconfined" { - f, err := ioutil.ReadFile(con[1]) - if err != nil { - return securityOpts, fmt.Errorf("opening seccomp profile (%s) failed: %v", con[1], err) - } - b := bytes.NewBuffer(nil) - if err := json.Compact(b, f); err != nil { - return securityOpts, fmt.Errorf("compacting json for seccomp profile (%s) failed: %v", con[1], err) - } - securityOpts[key] = fmt.Sprintf("seccomp=%s", b.Bytes()) - } - } - - return securityOpts, nil -} - -// parses storage options per container into a map -func parseStorageOpts(storageOpts []string) (map[string]string, error) { - m := make(map[string]string) - for _, option := range storageOpts { - if strings.Contains(option, "=") { - opt := strings.SplitN(option, "=", 2) - m[opt[0]] = opt[1] - } else { - return nil, fmt.Errorf("invalid storage option") - } - } - return m, nil -} - -// ParseRestartPolicy returns the parsed policy or an error indicating what is incorrect -func ParseRestartPolicy(policy string) (container.RestartPolicy, error) { - p := container.RestartPolicy{} - - if policy == "" { - return p, nil - } - - parts := strings.Split(policy, ":") - - if len(parts) > 2 { - return p, fmt.Errorf("invalid restart policy format") - } - if len(parts) == 2 { - count, err := strconv.Atoi(parts[1]) - if err != nil { - return p, fmt.Errorf("maximum retry count must be an integer") - } - - p.MaximumRetryCount = count - } - - p.Name = parts[0] - - return p, nil -} - -// ParseDevice parses a device mapping string to a container.DeviceMapping struct -func ParseDevice(device string) (container.DeviceMapping, error) { - src := "" - dst := "" - permissions := "rwm" - arr := strings.Split(device, ":") - switch len(arr) { - case 3: - permissions = arr[2] - fallthrough - case 2: - if ValidDeviceMode(arr[1]) { - permissions = arr[1] - } else { - dst = arr[1] - } - fallthrough - case 1: - src = arr[0] - default: - return container.DeviceMapping{}, fmt.Errorf("invalid device specification: %s", device) - } - - if dst == "" { - dst = src - } - - deviceMapping := container.DeviceMapping{ - PathOnHost: src, - PathInContainer: dst, - CgroupPermissions: permissions, - } - return deviceMapping, nil -} - -// ParseLink parses and validates the specified string as a link format (name:alias) -func ParseLink(val string) (string, string, error) { - if val == "" { - return "", "", fmt.Errorf("empty string specified for links") - } - arr := strings.Split(val, ":") - if len(arr) > 2 { - return "", "", fmt.Errorf("bad format for links: %s", val) - } - if len(arr) == 1 { - return val, val, nil - } - // This is kept because we can actually get a HostConfig with links - // from an already created container and the format is not `foo:bar` - // but `/foo:/c1/bar` - if strings.HasPrefix(arr[0], "/") { - _, alias := path.Split(arr[1]) - return arr[0][1:], alias, nil - } - return arr[0], arr[1], nil -} - -// ValidateLink validates that the specified string has a valid link format (containerName:alias). -func ValidateLink(val string) (string, error) { - if _, _, err := ParseLink(val); err != nil { - return val, err - } - return val, nil -} - -// ValidDeviceMode checks if the mode for device is valid or not. -// Valid mode is a composition of r (read), w (write), and m (mknod). -func ValidDeviceMode(mode string) bool { - var legalDeviceMode = map[rune]bool{ - 'r': true, - 'w': true, - 'm': true, - } - if mode == "" { - return false - } - for _, c := range mode { - if !legalDeviceMode[c] { - return false - } - legalDeviceMode[c] = false - } - return true -} - -// ValidateDevice validates a path for devices -// It will make sure 'val' is in the form: -// [host-dir:]container-path[:mode] -// It also validates the device mode. -func ValidateDevice(val string) (string, error) { - return validatePath(val, ValidDeviceMode) -} - -func validatePath(val string, validator func(string) bool) (string, error) { - var containerPath string - var mode string - - if strings.Count(val, ":") > 2 { - return val, fmt.Errorf("bad format for path: %s", val) - } - - split := strings.SplitN(val, ":", 3) - if split[0] == "" { - return val, fmt.Errorf("bad format for path: %s", val) - } - switch len(split) { - case 1: - containerPath = split[0] - val = path.Clean(containerPath) - case 2: - if isValid := validator(split[1]); isValid { - containerPath = split[0] - mode = split[1] - val = fmt.Sprintf("%s:%s", path.Clean(containerPath), mode) - } else { - containerPath = split[1] - val = fmt.Sprintf("%s:%s", split[0], path.Clean(containerPath)) - } - case 3: - containerPath = split[1] - mode = split[2] - if isValid := validator(split[2]); !isValid { - return val, fmt.Errorf("bad mode specified: %s", mode) - } - val = fmt.Sprintf("%s:%s:%s", split[0], containerPath, mode) - } - - if !path.IsAbs(containerPath) { - return val, fmt.Errorf("%s is not an absolute path", containerPath) - } - return val, nil -} - -// volumeSplitN splits raw into a maximum of n parts, separated by a separator colon. -// A separator colon is the last `:` character in the regex `[:\\]?[a-zA-Z]:` (note `\\` is `\` escaped). -// In Windows driver letter appears in two situations: -// a. `^[a-zA-Z]:` (A colon followed by `^[a-zA-Z]:` is OK as colon is the separator in volume option) -// b. A string in the format like `\\?\C:\Windows\...` (UNC). -// Therefore, a driver letter can only follow either a `:` or `\\` -// This allows to correctly split strings such as `C:\foo:D:\:rw` or `/tmp/q:/foo`. -func volumeSplitN(raw string, n int) []string { - var array []string - if len(raw) == 0 || raw[0] == ':' { - // invalid - return nil - } - // numberOfParts counts the number of parts separated by a separator colon - numberOfParts := 0 - // left represents the left-most cursor in raw, updated at every `:` character considered as a separator. - left := 0 - // right represents the right-most cursor in raw incremented with the loop. Note this - // starts at index 1 as index 0 is already handle above as a special case. - for right := 1; right < len(raw); right++ { - // stop parsing if reached maximum number of parts - if n >= 0 && numberOfParts >= n { - break - } - if raw[right] != ':' { - continue - } - potentialDriveLetter := raw[right-1] - if (potentialDriveLetter >= 'A' && potentialDriveLetter <= 'Z') || (potentialDriveLetter >= 'a' && potentialDriveLetter <= 'z') { - if right > 1 { - beforePotentialDriveLetter := raw[right-2] - // Only `:` or `\\` are checked (`/` could fall into the case of `/tmp/q:/foo`) - if beforePotentialDriveLetter != ':' && beforePotentialDriveLetter != '\\' { - // e.g. `C:` is not preceded by any delimiter, therefore it was not a drive letter but a path ending with `C:`. - array = append(array, raw[left:right]) - left = right + 1 - numberOfParts++ - } - // else, `C:` is considered as a drive letter and not as a delimiter, so we continue parsing. - } - // if right == 1, then `C:` is the beginning of the raw string, therefore `:` is again not considered a delimiter and we continue parsing. - } else { - // if `:` is not preceded by a potential drive letter, then consider it as a delimiter. - array = append(array, raw[left:right]) - left = right + 1 - numberOfParts++ - } - } - // need to take care of the last part - if left < len(raw) { - if n >= 0 && numberOfParts >= n { - // if the maximum number of parts is reached, just append the rest to the last part - // left-1 is at the last `:` that needs to be included since not considered a separator. - array[n-1] += raw[left-1:] - } else { - array = append(array, raw[left:]) - } - } - return array -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/parse_test.go b/vendor/github.com/docker/docker/runconfig/opts/parse_test.go deleted file mode 100644 index a1be379..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/parse_test.go +++ /dev/null @@ -1,894 +0,0 @@ -package opts - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "os" - "runtime" - "strings" - "testing" - "time" - - "github.com/docker/docker/api/types/container" - networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/runconfig" - "github.com/docker/go-connections/nat" - "github.com/spf13/pflag" -) - -func parseRun(args []string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) { - flags := pflag.NewFlagSet("run", pflag.ContinueOnError) - flags.SetOutput(ioutil.Discard) - flags.Usage = nil - copts := AddFlags(flags) - if err := flags.Parse(args); err != nil { - return nil, nil, nil, err - } - return Parse(flags, copts) -} - -func parse(t *testing.T, args string) (*container.Config, *container.HostConfig, error) { - config, hostConfig, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) - return config, hostConfig, err -} - -func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) { - config, hostConfig, err := parse(t, args) - if err != nil { - t.Fatal(err) - } - return config, hostConfig -} - -func TestParseRunLinks(t *testing.T) { - if _, hostConfig := mustParse(t, "--link a:b"); len(hostConfig.Links) == 0 || hostConfig.Links[0] != "a:b" { - t.Fatalf("Error parsing links. Expected []string{\"a:b\"}, received: %v", hostConfig.Links) - } - if _, hostConfig := mustParse(t, "--link a:b --link c:d"); len(hostConfig.Links) < 2 || hostConfig.Links[0] != "a:b" || hostConfig.Links[1] != "c:d" { - t.Fatalf("Error parsing links. Expected []string{\"a:b\", \"c:d\"}, received: %v", hostConfig.Links) - } - if _, hostConfig := mustParse(t, ""); len(hostConfig.Links) != 0 { - t.Fatalf("Error parsing links. No link expected, received: %v", hostConfig.Links) - } -} - -func TestParseRunAttach(t *testing.T) { - if config, _ := mustParse(t, "-a stdin"); !config.AttachStdin || config.AttachStdout || config.AttachStderr { - t.Fatalf("Error parsing attach flags. Expect only Stdin enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr) - } - if config, _ := mustParse(t, "-a stdin -a stdout"); !config.AttachStdin || !config.AttachStdout || config.AttachStderr { - t.Fatalf("Error parsing attach flags. Expect only Stdin and Stdout enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr) - } - if config, _ := mustParse(t, "-a stdin -a stdout -a stderr"); !config.AttachStdin || !config.AttachStdout || !config.AttachStderr { - t.Fatalf("Error parsing attach flags. Expect all attach enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr) - } - if config, _ := mustParse(t, ""); config.AttachStdin || !config.AttachStdout || !config.AttachStderr { - t.Fatalf("Error parsing attach flags. Expect Stdin disabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr) - } - if config, _ := mustParse(t, "-i"); !config.AttachStdin || !config.AttachStdout || !config.AttachStderr { - t.Fatalf("Error parsing attach flags. Expect Stdin enabled. Received: in: %v, out: %v, err: %v", config.AttachStdin, config.AttachStdout, config.AttachStderr) - } - - if _, _, err := parse(t, "-a"); err == nil { - t.Fatalf("Error parsing attach flags, `-a` should be an error but is not") - } - if _, _, err := parse(t, "-a invalid"); err == nil { - t.Fatalf("Error parsing attach flags, `-a invalid` should be an error but is not") - } - if _, _, err := parse(t, "-a invalid -a stdout"); err == nil { - t.Fatalf("Error parsing attach flags, `-a stdout -a invalid` should be an error but is not") - } - if _, _, err := parse(t, "-a stdout -a stderr -d"); err == nil { - t.Fatalf("Error parsing attach flags, `-a stdout -a stderr -d` should be an error but is not") - } - if _, _, err := parse(t, "-a stdin -d"); err == nil { - t.Fatalf("Error parsing attach flags, `-a stdin -d` should be an error but is not") - } - if _, _, err := parse(t, "-a stdout -d"); err == nil { - t.Fatalf("Error parsing attach flags, `-a stdout -d` should be an error but is not") - } - if _, _, err := parse(t, "-a stderr -d"); err == nil { - t.Fatalf("Error parsing attach flags, `-a stderr -d` should be an error but is not") - } - if _, _, err := parse(t, "-d --rm"); err == nil { - t.Fatalf("Error parsing attach flags, `-d --rm` should be an error but is not") - } -} - -func TestParseRunVolumes(t *testing.T) { - - // A single volume - arr, tryit := setupPlatformVolume([]string{`/tmp`}, []string{`c:\tmp`}) - if config, hostConfig := mustParse(t, tryit); hostConfig.Binds != nil { - t.Fatalf("Error parsing volume flags, %q should not mount-bind anything. Received %v", tryit, hostConfig.Binds) - } else if _, exists := config.Volumes[arr[0]]; !exists { - t.Fatalf("Error parsing volume flags, %q is missing from volumes. Received %v", tryit, config.Volumes) - } - - // Two volumes - arr, tryit = setupPlatformVolume([]string{`/tmp`, `/var`}, []string{`c:\tmp`, `c:\var`}) - if config, hostConfig := mustParse(t, tryit); hostConfig.Binds != nil { - t.Fatalf("Error parsing volume flags, %q should not mount-bind anything. Received %v", tryit, hostConfig.Binds) - } else if _, exists := config.Volumes[arr[0]]; !exists { - t.Fatalf("Error parsing volume flags, %s is missing from volumes. Received %v", arr[0], config.Volumes) - } else if _, exists := config.Volumes[arr[1]]; !exists { - t.Fatalf("Error parsing volume flags, %s is missing from volumes. Received %v", arr[1], config.Volumes) - } - - // A single bind-mount - arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp`}, []string{os.Getenv("TEMP") + `:c:\containerTmp`}) - if config, hostConfig := mustParse(t, tryit); hostConfig.Binds == nil || hostConfig.Binds[0] != arr[0] { - t.Fatalf("Error parsing volume flags, %q should mount-bind the path before the colon into the path after the colon. Received %v %v", arr[0], hostConfig.Binds, config.Volumes) - } - - // Two bind-mounts. - arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp`, `/hostVar:/containerVar`}, []string{os.Getenv("ProgramData") + `:c:\ContainerPD`, os.Getenv("TEMP") + `:c:\containerTmp`}) - if _, hostConfig := mustParse(t, tryit); hostConfig.Binds == nil || compareRandomizedStrings(hostConfig.Binds[0], hostConfig.Binds[1], arr[0], arr[1]) != nil { - t.Fatalf("Error parsing volume flags, `%s and %s` did not mount-bind correctly. Received %v", arr[0], arr[1], hostConfig.Binds) - } - - // Two bind-mounts, first read-only, second read-write. - // TODO Windows: The Windows version uses read-write as that's the only mode it supports. Can change this post TP4 - arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp:ro`, `/hostVar:/containerVar:rw`}, []string{os.Getenv("TEMP") + `:c:\containerTmp:rw`, os.Getenv("ProgramData") + `:c:\ContainerPD:rw`}) - if _, hostConfig := mustParse(t, tryit); hostConfig.Binds == nil || compareRandomizedStrings(hostConfig.Binds[0], hostConfig.Binds[1], arr[0], arr[1]) != nil { - t.Fatalf("Error parsing volume flags, `%s and %s` did not mount-bind correctly. Received %v", arr[0], arr[1], hostConfig.Binds) - } - - // Similar to previous test but with alternate modes which are only supported by Linux - if runtime.GOOS != "windows" { - arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp:ro,Z`, `/hostVar:/containerVar:rw,Z`}, []string{}) - if _, hostConfig := mustParse(t, tryit); hostConfig.Binds == nil || compareRandomizedStrings(hostConfig.Binds[0], hostConfig.Binds[1], arr[0], arr[1]) != nil { - t.Fatalf("Error parsing volume flags, `%s and %s` did not mount-bind correctly. Received %v", arr[0], arr[1], hostConfig.Binds) - } - - arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp:Z`, `/hostVar:/containerVar:z`}, []string{}) - if _, hostConfig := mustParse(t, tryit); hostConfig.Binds == nil || compareRandomizedStrings(hostConfig.Binds[0], hostConfig.Binds[1], arr[0], arr[1]) != nil { - t.Fatalf("Error parsing volume flags, `%s and %s` did not mount-bind correctly. Received %v", arr[0], arr[1], hostConfig.Binds) - } - } - - // One bind mount and one volume - arr, tryit = setupPlatformVolume([]string{`/hostTmp:/containerTmp`, `/containerVar`}, []string{os.Getenv("TEMP") + `:c:\containerTmp`, `c:\containerTmp`}) - if config, hostConfig := mustParse(t, tryit); hostConfig.Binds == nil || len(hostConfig.Binds) > 1 || hostConfig.Binds[0] != arr[0] { - t.Fatalf("Error parsing volume flags, %s and %s should only one and only one bind mount %s. Received %s", arr[0], arr[1], arr[0], hostConfig.Binds) - } else if _, exists := config.Volumes[arr[1]]; !exists { - t.Fatalf("Error parsing volume flags %s and %s. %s is missing from volumes. Received %v", arr[0], arr[1], arr[1], config.Volumes) - } - - // Root to non-c: drive letter (Windows specific) - if runtime.GOOS == "windows" { - arr, tryit = setupPlatformVolume([]string{}, []string{os.Getenv("SystemDrive") + `\:d:`}) - if config, hostConfig := mustParse(t, tryit); hostConfig.Binds == nil || len(hostConfig.Binds) > 1 || hostConfig.Binds[0] != arr[0] || len(config.Volumes) != 0 { - t.Fatalf("Error parsing %s. Should have a single bind mount and no volumes", arr[0]) - } - } - -} - -// This tests the cases for binds which are generated through -// DecodeContainerConfig rather than Parse() -func TestDecodeContainerConfigVolumes(t *testing.T) { - - // Root to root - bindsOrVols, _ := setupPlatformVolume([]string{`/:/`}, []string{os.Getenv("SystemDrive") + `\:c:\`}) - if _, _, err := callDecodeContainerConfig(nil, bindsOrVols); err == nil { - t.Fatalf("binds %v should have failed", bindsOrVols) - } - if _, _, err := callDecodeContainerConfig(bindsOrVols, nil); err == nil { - t.Fatalf("volume %v should have failed", bindsOrVols) - } - - // No destination path - bindsOrVols, _ = setupPlatformVolume([]string{`/tmp:`}, []string{os.Getenv("TEMP") + `\:`}) - if _, _, err := callDecodeContainerConfig(nil, bindsOrVols); err == nil { - t.Fatalf("binds %v should have failed", bindsOrVols) - } - if _, _, err := callDecodeContainerConfig(bindsOrVols, nil); err == nil { - t.Fatalf("volume %v should have failed", bindsOrVols) - } - - // // No destination path or mode - bindsOrVols, _ = setupPlatformVolume([]string{`/tmp::`}, []string{os.Getenv("TEMP") + `\::`}) - if _, _, err := callDecodeContainerConfig(nil, bindsOrVols); err == nil { - t.Fatalf("binds %v should have failed", bindsOrVols) - } - if _, _, err := callDecodeContainerConfig(bindsOrVols, nil); err == nil { - t.Fatalf("volume %v should have failed", bindsOrVols) - } - - // A whole lot of nothing - bindsOrVols = []string{`:`} - if _, _, err := callDecodeContainerConfig(nil, bindsOrVols); err == nil { - t.Fatalf("binds %v should have failed", bindsOrVols) - } - if _, _, err := callDecodeContainerConfig(bindsOrVols, nil); err == nil { - t.Fatalf("volume %v should have failed", bindsOrVols) - } - - // A whole lot of nothing with no mode - bindsOrVols = []string{`::`} - if _, _, err := callDecodeContainerConfig(nil, bindsOrVols); err == nil { - t.Fatalf("binds %v should have failed", bindsOrVols) - } - if _, _, err := callDecodeContainerConfig(bindsOrVols, nil); err == nil { - t.Fatalf("volume %v should have failed", bindsOrVols) - } - - // Too much including an invalid mode - wTmp := os.Getenv("TEMP") - bindsOrVols, _ = setupPlatformVolume([]string{`/tmp:/tmp:/tmp:/tmp`}, []string{wTmp + ":" + wTmp + ":" + wTmp + ":" + wTmp}) - if _, _, err := callDecodeContainerConfig(nil, bindsOrVols); err == nil { - t.Fatalf("binds %v should have failed", bindsOrVols) - } - if _, _, err := callDecodeContainerConfig(bindsOrVols, nil); err == nil { - t.Fatalf("volume %v should have failed", bindsOrVols) - } - - // Windows specific error tests - if runtime.GOOS == "windows" { - // Volume which does not include a drive letter - bindsOrVols = []string{`\tmp`} - if _, _, err := callDecodeContainerConfig(nil, bindsOrVols); err == nil { - t.Fatalf("binds %v should have failed", bindsOrVols) - } - if _, _, err := callDecodeContainerConfig(bindsOrVols, nil); err == nil { - t.Fatalf("volume %v should have failed", bindsOrVols) - } - - // Root to C-Drive - bindsOrVols = []string{os.Getenv("SystemDrive") + `\:c:`} - if _, _, err := callDecodeContainerConfig(nil, bindsOrVols); err == nil { - t.Fatalf("binds %v should have failed", bindsOrVols) - } - if _, _, err := callDecodeContainerConfig(bindsOrVols, nil); err == nil { - t.Fatalf("volume %v should have failed", bindsOrVols) - } - - // Container path that does not include a drive letter - bindsOrVols = []string{`c:\windows:\somewhere`} - if _, _, err := callDecodeContainerConfig(nil, bindsOrVols); err == nil { - t.Fatalf("binds %v should have failed", bindsOrVols) - } - if _, _, err := callDecodeContainerConfig(bindsOrVols, nil); err == nil { - t.Fatalf("volume %v should have failed", bindsOrVols) - } - } - - // Linux-specific error tests - if runtime.GOOS != "windows" { - // Just root - bindsOrVols = []string{`/`} - if _, _, err := callDecodeContainerConfig(nil, bindsOrVols); err == nil { - t.Fatalf("binds %v should have failed", bindsOrVols) - } - if _, _, err := callDecodeContainerConfig(bindsOrVols, nil); err == nil { - t.Fatalf("volume %v should have failed", bindsOrVols) - } - - // A single volume that looks like a bind mount passed in Volumes. - // This should be handled as a bind mount, not a volume. - vols := []string{`/foo:/bar`} - if config, hostConfig, err := callDecodeContainerConfig(vols, nil); err != nil { - t.Fatal("Volume /foo:/bar should have succeeded as a volume name") - } else if hostConfig.Binds != nil { - t.Fatalf("Error parsing volume flags, /foo:/bar should not mount-bind anything. Received %v", hostConfig.Binds) - } else if _, exists := config.Volumes[vols[0]]; !exists { - t.Fatalf("Error parsing volume flags, /foo:/bar is missing from volumes. Received %v", config.Volumes) - } - - } -} - -// callDecodeContainerConfig is a utility function used by TestDecodeContainerConfigVolumes -// to call DecodeContainerConfig. It effectively does what a client would -// do when calling the daemon by constructing a JSON stream of a -// ContainerConfigWrapper which is populated by the set of volume specs -// passed into it. It returns a config and a hostconfig which can be -// validated to ensure DecodeContainerConfig has manipulated the structures -// correctly. -func callDecodeContainerConfig(volumes []string, binds []string) (*container.Config, *container.HostConfig, error) { - var ( - b []byte - err error - c *container.Config - h *container.HostConfig - ) - w := runconfig.ContainerConfigWrapper{ - Config: &container.Config{ - Volumes: map[string]struct{}{}, - }, - HostConfig: &container.HostConfig{ - NetworkMode: "none", - Binds: binds, - }, - } - for _, v := range volumes { - w.Config.Volumes[v] = struct{}{} - } - if b, err = json.Marshal(w); err != nil { - return nil, nil, fmt.Errorf("Error on marshal %s", err.Error()) - } - c, h, _, err = runconfig.DecodeContainerConfig(bytes.NewReader(b)) - if err != nil { - return nil, nil, fmt.Errorf("Error parsing %s: %v", string(b), err) - } - if c == nil || h == nil { - return nil, nil, fmt.Errorf("Empty config or hostconfig") - } - - return c, h, err -} - -// check if (a == c && b == d) || (a == d && b == c) -// because maps are randomized -func compareRandomizedStrings(a, b, c, d string) error { - if a == c && b == d { - return nil - } - if a == d && b == c { - return nil - } - return fmt.Errorf("strings don't match") -} - -// setupPlatformVolume takes two arrays of volume specs - a Unix style -// spec and a Windows style spec. Depending on the platform being unit tested, -// it returns one of them, along with a volume string that would be passed -// on the docker CLI (eg -v /bar -v /foo). -func setupPlatformVolume(u []string, w []string) ([]string, string) { - var a []string - if runtime.GOOS == "windows" { - a = w - } else { - a = u - } - s := "" - for _, v := range a { - s = s + "-v " + v + " " - } - return a, s -} - -// Simple parse with MacAddress validation -func TestParseWithMacAddress(t *testing.T) { - invalidMacAddress := "--mac-address=invalidMacAddress" - validMacAddress := "--mac-address=92:d0:c6:0a:29:33" - if _, _, _, err := parseRun([]string{invalidMacAddress, "img", "cmd"}); err != nil && err.Error() != "invalidMacAddress is not a valid mac address" { - t.Fatalf("Expected an error with %v mac-address, got %v", invalidMacAddress, err) - } - if config, _ := mustParse(t, validMacAddress); config.MacAddress != "92:d0:c6:0a:29:33" { - t.Fatalf("Expected the config to have '92:d0:c6:0a:29:33' as MacAddress, got '%v'", config.MacAddress) - } -} - -func TestParseWithMemory(t *testing.T) { - invalidMemory := "--memory=invalid" - validMemory := "--memory=1G" - if _, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"}); err != nil && err.Error() != "invalid size: 'invalid'" { - t.Fatalf("Expected an error with '%v' Memory, got '%v'", invalidMemory, err) - } - if _, hostconfig := mustParse(t, validMemory); hostconfig.Memory != 1073741824 { - t.Fatalf("Expected the config to have '1G' as Memory, got '%v'", hostconfig.Memory) - } -} - -func TestParseWithMemorySwap(t *testing.T) { - invalidMemory := "--memory-swap=invalid" - validMemory := "--memory-swap=1G" - anotherValidMemory := "--memory-swap=-1" - if _, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"}); err == nil || err.Error() != "invalid size: 'invalid'" { - t.Fatalf("Expected an error with '%v' MemorySwap, got '%v'", invalidMemory, err) - } - if _, hostconfig := mustParse(t, validMemory); hostconfig.MemorySwap != 1073741824 { - t.Fatalf("Expected the config to have '1073741824' as MemorySwap, got '%v'", hostconfig.MemorySwap) - } - if _, hostconfig := mustParse(t, anotherValidMemory); hostconfig.MemorySwap != -1 { - t.Fatalf("Expected the config to have '-1' as MemorySwap, got '%v'", hostconfig.MemorySwap) - } -} - -func TestParseHostname(t *testing.T) { - validHostnames := map[string]string{ - "hostname": "hostname", - "host-name": "host-name", - "hostname123": "hostname123", - "123hostname": "123hostname", - "hostname-of-63-bytes-long-should-be-valid-and-without-any-error": "hostname-of-63-bytes-long-should-be-valid-and-without-any-error", - } - hostnameWithDomain := "--hostname=hostname.domainname" - hostnameWithDomainTld := "--hostname=hostname.domainname.tld" - for hostname, expectedHostname := range validHostnames { - if config, _ := mustParse(t, fmt.Sprintf("--hostname=%s", hostname)); config.Hostname != expectedHostname { - t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname) - } - } - if config, _ := mustParse(t, hostnameWithDomain); config.Hostname != "hostname.domainname" && config.Domainname != "" { - t.Fatalf("Expected the config to have 'hostname' as hostname.domainname, got '%v'", config.Hostname) - } - if config, _ := mustParse(t, hostnameWithDomainTld); config.Hostname != "hostname.domainname.tld" && config.Domainname != "" { - t.Fatalf("Expected the config to have 'hostname' as hostname.domainname.tld, got '%v'", config.Hostname) - } -} - -func TestParseWithExpose(t *testing.T) { - invalids := map[string]string{ - ":": "invalid port format for --expose: :", - "8080:9090": "invalid port format for --expose: 8080:9090", - "/tcp": "invalid range format for --expose: /tcp, error: Empty string specified for ports.", - "/udp": "invalid range format for --expose: /udp, error: Empty string specified for ports.", - "NaN/tcp": `invalid range format for --expose: NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`, - "NaN-NaN/tcp": `invalid range format for --expose: NaN-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`, - "8080-NaN/tcp": `invalid range format for --expose: 8080-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`, - "1234567890-8080/tcp": `invalid range format for --expose: 1234567890-8080/tcp, error: strconv.ParseUint: parsing "1234567890": value out of range`, - } - valids := map[string][]nat.Port{ - "8080/tcp": {"8080/tcp"}, - "8080/udp": {"8080/udp"}, - "8080/ncp": {"8080/ncp"}, - "8080-8080/udp": {"8080/udp"}, - "8080-8082/tcp": {"8080/tcp", "8081/tcp", "8082/tcp"}, - } - for expose, expectedError := range invalids { - if _, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"}); err == nil || err.Error() != expectedError { - t.Fatalf("Expected error '%v' with '--expose=%v', got '%v'", expectedError, expose, err) - } - } - for expose, exposedPorts := range valids { - config, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if len(config.ExposedPorts) != len(exposedPorts) { - t.Fatalf("Expected %v exposed port, got %v", len(exposedPorts), len(config.ExposedPorts)) - } - for _, port := range exposedPorts { - if _, ok := config.ExposedPorts[port]; !ok { - t.Fatalf("Expected %v, got %v", exposedPorts, config.ExposedPorts) - } - } - } - // Merge with actual published port - config, _, _, err := parseRun([]string{"--publish=80", "--expose=80-81/tcp", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if len(config.ExposedPorts) != 2 { - t.Fatalf("Expected 2 exposed ports, got %v", config.ExposedPorts) - } - ports := []nat.Port{"80/tcp", "81/tcp"} - for _, port := range ports { - if _, ok := config.ExposedPorts[port]; !ok { - t.Fatalf("Expected %v, got %v", ports, config.ExposedPorts) - } - } -} - -func TestParseDevice(t *testing.T) { - valids := map[string]container.DeviceMapping{ - "/dev/snd": { - PathOnHost: "/dev/snd", - PathInContainer: "/dev/snd", - CgroupPermissions: "rwm", - }, - "/dev/snd:rw": { - PathOnHost: "/dev/snd", - PathInContainer: "/dev/snd", - CgroupPermissions: "rw", - }, - "/dev/snd:/something": { - PathOnHost: "/dev/snd", - PathInContainer: "/something", - CgroupPermissions: "rwm", - }, - "/dev/snd:/something:rw": { - PathOnHost: "/dev/snd", - PathInContainer: "/something", - CgroupPermissions: "rw", - }, - } - for device, deviceMapping := range valids { - _, hostconfig, _, err := parseRun([]string{fmt.Sprintf("--device=%v", device), "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if len(hostconfig.Devices) != 1 { - t.Fatalf("Expected 1 devices, got %v", hostconfig.Devices) - } - if hostconfig.Devices[0] != deviceMapping { - t.Fatalf("Expected %v, got %v", deviceMapping, hostconfig.Devices) - } - } - -} - -func TestParseModes(t *testing.T) { - // ipc ko - if _, _, _, err := parseRun([]string{"--ipc=container:", "img", "cmd"}); err == nil || err.Error() != "--ipc: invalid IPC mode" { - t.Fatalf("Expected an error with message '--ipc: invalid IPC mode', got %v", err) - } - // ipc ok - _, hostconfig, _, err := parseRun([]string{"--ipc=host", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if !hostconfig.IpcMode.Valid() { - t.Fatalf("Expected a valid IpcMode, got %v", hostconfig.IpcMode) - } - // pid ko - if _, _, _, err := parseRun([]string{"--pid=container:", "img", "cmd"}); err == nil || err.Error() != "--pid: invalid PID mode" { - t.Fatalf("Expected an error with message '--pid: invalid PID mode', got %v", err) - } - // pid ok - _, hostconfig, _, err = parseRun([]string{"--pid=host", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if !hostconfig.PidMode.Valid() { - t.Fatalf("Expected a valid PidMode, got %v", hostconfig.PidMode) - } - // uts ko - if _, _, _, err := parseRun([]string{"--uts=container:", "img", "cmd"}); err == nil || err.Error() != "--uts: invalid UTS mode" { - t.Fatalf("Expected an error with message '--uts: invalid UTS mode', got %v", err) - } - // uts ok - _, hostconfig, _, err = parseRun([]string{"--uts=host", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if !hostconfig.UTSMode.Valid() { - t.Fatalf("Expected a valid UTSMode, got %v", hostconfig.UTSMode) - } - // shm-size ko - if _, _, _, err = parseRun([]string{"--shm-size=a128m", "img", "cmd"}); err == nil || err.Error() != "invalid size: 'a128m'" { - t.Fatalf("Expected an error with message 'invalid size: a128m', got %v", err) - } - // shm-size ok - _, hostconfig, _, err = parseRun([]string{"--shm-size=128m", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if hostconfig.ShmSize != 134217728 { - t.Fatalf("Expected a valid ShmSize, got %d", hostconfig.ShmSize) - } -} - -func TestParseRestartPolicy(t *testing.T) { - invalids := map[string]string{ - "always:2:3": "invalid restart policy format", - "on-failure:invalid": "maximum retry count must be an integer", - } - valids := map[string]container.RestartPolicy{ - "": {}, - "always": { - Name: "always", - MaximumRetryCount: 0, - }, - "on-failure:1": { - Name: "on-failure", - MaximumRetryCount: 1, - }, - } - for restart, expectedError := range invalids { - if _, _, _, err := parseRun([]string{fmt.Sprintf("--restart=%s", restart), "img", "cmd"}); err == nil || err.Error() != expectedError { - t.Fatalf("Expected an error with message '%v' for %v, got %v", expectedError, restart, err) - } - } - for restart, expected := range valids { - _, hostconfig, _, err := parseRun([]string{fmt.Sprintf("--restart=%v", restart), "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if hostconfig.RestartPolicy != expected { - t.Fatalf("Expected %v, got %v", expected, hostconfig.RestartPolicy) - } - } -} - -func TestParseHealth(t *testing.T) { - checkOk := func(args ...string) *container.HealthConfig { - config, _, _, err := parseRun(args) - if err != nil { - t.Fatalf("%#v: %v", args, err) - } - return config.Healthcheck - } - checkError := func(expected string, args ...string) { - config, _, _, err := parseRun(args) - if err == nil { - t.Fatalf("Expected error, but got %#v", config) - } - if err.Error() != expected { - t.Fatalf("Expected %#v, got %#v", expected, err) - } - } - health := checkOk("--no-healthcheck", "img", "cmd") - if health == nil || len(health.Test) != 1 || health.Test[0] != "NONE" { - t.Fatalf("--no-healthcheck failed: %#v", health) - } - - health = checkOk("--health-cmd=/check.sh -q", "img", "cmd") - if len(health.Test) != 2 || health.Test[0] != "CMD-SHELL" || health.Test[1] != "/check.sh -q" { - t.Fatalf("--health-cmd: got %#v", health.Test) - } - if health.Timeout != 0 { - t.Fatalf("--health-cmd: timeout = %f", health.Timeout) - } - - checkError("--no-healthcheck conflicts with --health-* options", - "--no-healthcheck", "--health-cmd=/check.sh -q", "img", "cmd") - - health = checkOk("--health-timeout=2s", "--health-retries=3", "--health-interval=4.5s", "img", "cmd") - if health.Timeout != 2*time.Second || health.Retries != 3 || health.Interval != 4500*time.Millisecond { - t.Fatalf("--health-*: got %#v", health) - } -} - -func TestParseLoggingOpts(t *testing.T) { - // logging opts ko - if _, _, _, err := parseRun([]string{"--log-driver=none", "--log-opt=anything", "img", "cmd"}); err == nil || err.Error() != "invalid logging opts for driver none" { - t.Fatalf("Expected an error with message 'invalid logging opts for driver none', got %v", err) - } - // logging opts ok - _, hostconfig, _, err := parseRun([]string{"--log-driver=syslog", "--log-opt=something", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if hostconfig.LogConfig.Type != "syslog" || len(hostconfig.LogConfig.Config) != 1 { - t.Fatalf("Expected a 'syslog' LogConfig with one config, got %v", hostconfig.RestartPolicy) - } -} - -func TestParseEnvfileVariables(t *testing.T) { - e := "open nonexistent: no such file or directory" - if runtime.GOOS == "windows" { - e = "open nonexistent: The system cannot find the file specified." - } - // env ko - if _, _, _, err := parseRun([]string{"--env-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != e { - t.Fatalf("Expected an error with message '%s', got %v", e, err) - } - // env ok - config, _, _, err := parseRun([]string{"--env-file=fixtures/valid.env", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if len(config.Env) != 1 || config.Env[0] != "ENV1=value1" { - t.Fatalf("Expected a config with [ENV1=value1], got %v", config.Env) - } - config, _, _, err = parseRun([]string{"--env-file=fixtures/valid.env", "--env=ENV2=value2", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if len(config.Env) != 2 || config.Env[0] != "ENV1=value1" || config.Env[1] != "ENV2=value2" { - t.Fatalf("Expected a config with [ENV1=value1 ENV2=value2], got %v", config.Env) - } -} - -func TestParseEnvfileVariablesWithBOMUnicode(t *testing.T) { - // UTF8 with BOM - config, _, _, err := parseRun([]string{"--env-file=fixtures/utf8.env", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - env := []string{"FOO=BAR", "HELLO=" + string([]byte{0xe6, 0x82, 0xa8, 0xe5, 0xa5, 0xbd}), "BAR=FOO"} - if len(config.Env) != len(env) { - t.Fatalf("Expected a config with %d env variables, got %v: %v", len(env), len(config.Env), config.Env) - } - for i, v := range env { - if config.Env[i] != v { - t.Fatalf("Expected a config with [%s], got %v", v, []byte(config.Env[i])) - } - } - - // UTF16 with BOM - e := "contains invalid utf8 bytes at line" - if _, _, _, err := parseRun([]string{"--env-file=fixtures/utf16.env", "img", "cmd"}); err == nil || !strings.Contains(err.Error(), e) { - t.Fatalf("Expected an error with message '%s', got %v", e, err) - } - // UTF16BE with BOM - if _, _, _, err := parseRun([]string{"--env-file=fixtures/utf16be.env", "img", "cmd"}); err == nil || !strings.Contains(err.Error(), e) { - t.Fatalf("Expected an error with message '%s', got %v", e, err) - } -} - -func TestParseLabelfileVariables(t *testing.T) { - e := "open nonexistent: no such file or directory" - if runtime.GOOS == "windows" { - e = "open nonexistent: The system cannot find the file specified." - } - // label ko - if _, _, _, err := parseRun([]string{"--label-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != e { - t.Fatalf("Expected an error with message '%s', got %v", e, err) - } - // label ok - config, _, _, err := parseRun([]string{"--label-file=fixtures/valid.label", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if len(config.Labels) != 1 || config.Labels["LABEL1"] != "value1" { - t.Fatalf("Expected a config with [LABEL1:value1], got %v", config.Labels) - } - config, _, _, err = parseRun([]string{"--label-file=fixtures/valid.label", "--label=LABEL2=value2", "img", "cmd"}) - if err != nil { - t.Fatal(err) - } - if len(config.Labels) != 2 || config.Labels["LABEL1"] != "value1" || config.Labels["LABEL2"] != "value2" { - t.Fatalf("Expected a config with [LABEL1:value1 LABEL2:value2], got %v", config.Labels) - } -} - -func TestParseEntryPoint(t *testing.T) { - config, _, _, err := parseRun([]string{"--entrypoint=anything", "cmd", "img"}) - if err != nil { - t.Fatal(err) - } - if len(config.Entrypoint) != 1 && config.Entrypoint[0] != "anything" { - t.Fatalf("Expected entrypoint 'anything', got %v", config.Entrypoint) - } -} - -func TestValidateLink(t *testing.T) { - valid := []string{ - "name", - "dcdfbe62ecd0:alias", - "7a67485460b7642516a4ad82ecefe7f57d0c4916f530561b71a50a3f9c4e33da", - "angry_torvalds:linus", - } - invalid := map[string]string{ - "": "empty string specified for links", - "too:much:of:it": "bad format for links: too:much:of:it", - } - - for _, link := range valid { - if _, err := ValidateLink(link); err != nil { - t.Fatalf("ValidateLink(`%q`) should succeed: error %q", link, err) - } - } - - for link, expectedError := range invalid { - if _, err := ValidateLink(link); err == nil { - t.Fatalf("ValidateLink(`%q`) should have failed validation", link) - } else { - if !strings.Contains(err.Error(), expectedError) { - t.Fatalf("ValidateLink(`%q`) error should contain %q", link, expectedError) - } - } - } -} - -func TestParseLink(t *testing.T) { - name, alias, err := ParseLink("name:alias") - if err != nil { - t.Fatalf("Expected not to error out on a valid name:alias format but got: %v", err) - } - if name != "name" { - t.Fatalf("Link name should have been name, got %s instead", name) - } - if alias != "alias" { - t.Fatalf("Link alias should have been alias, got %s instead", alias) - } - // short format definition - name, alias, err = ParseLink("name") - if err != nil { - t.Fatalf("Expected not to error out on a valid name only format but got: %v", err) - } - if name != "name" { - t.Fatalf("Link name should have been name, got %s instead", name) - } - if alias != "name" { - t.Fatalf("Link alias should have been name, got %s instead", alias) - } - // empty string link definition is not allowed - if _, _, err := ParseLink(""); err == nil || !strings.Contains(err.Error(), "empty string specified for links") { - t.Fatalf("Expected error 'empty string specified for links' but got: %v", err) - } - // more than two colons are not allowed - if _, _, err := ParseLink("link:alias:wrong"); err == nil || !strings.Contains(err.Error(), "bad format for links: link:alias:wrong") { - t.Fatalf("Expected error 'bad format for links: link:alias:wrong' but got: %v", err) - } -} - -func TestValidateDevice(t *testing.T) { - valid := []string{ - "/home", - "/home:/home", - "/home:/something/else", - "/with space", - "/home:/with space", - "relative:/absolute-path", - "hostPath:/containerPath:r", - "/hostPath:/containerPath:rw", - "/hostPath:/containerPath:mrw", - } - invalid := map[string]string{ - "": "bad format for path: ", - "./": "./ is not an absolute path", - "../": "../ is not an absolute path", - "/:../": "../ is not an absolute path", - "/:path": "path is not an absolute path", - ":": "bad format for path: :", - "/tmp:": " is not an absolute path", - ":test": "bad format for path: :test", - ":/test": "bad format for path: :/test", - "tmp:": " is not an absolute path", - ":test:": "bad format for path: :test:", - "::": "bad format for path: ::", - ":::": "bad format for path: :::", - "/tmp:::": "bad format for path: /tmp:::", - ":/tmp::": "bad format for path: :/tmp::", - "path:ro": "ro is not an absolute path", - "path:rr": "rr is not an absolute path", - "a:/b:ro": "bad mode specified: ro", - "a:/b:rr": "bad mode specified: rr", - } - - for _, path := range valid { - if _, err := ValidateDevice(path); err != nil { - t.Fatalf("ValidateDevice(`%q`) should succeed: error %q", path, err) - } - } - - for path, expectedError := range invalid { - if _, err := ValidateDevice(path); err == nil { - t.Fatalf("ValidateDevice(`%q`) should have failed validation", path) - } else { - if err.Error() != expectedError { - t.Fatalf("ValidateDevice(`%q`) error should contain %q, got %q", path, expectedError, err.Error()) - } - } - } -} - -func TestVolumeSplitN(t *testing.T) { - for _, x := range []struct { - input string - n int - expected []string - }{ - {`C:\foo:d:`, -1, []string{`C:\foo`, `d:`}}, - {`:C:\foo:d:`, -1, nil}, - {`/foo:/bar:ro`, 3, []string{`/foo`, `/bar`, `ro`}}, - {`/foo:/bar:ro`, 2, []string{`/foo`, `/bar:ro`}}, - {`C:\foo\:/foo`, -1, []string{`C:\foo\`, `/foo`}}, - - {`d:\`, -1, []string{`d:\`}}, - {`d:`, -1, []string{`d:`}}, - {`d:\path`, -1, []string{`d:\path`}}, - {`d:\path with space`, -1, []string{`d:\path with space`}}, - {`d:\pathandmode:rw`, -1, []string{`d:\pathandmode`, `rw`}}, - {`c:\:d:\`, -1, []string{`c:\`, `d:\`}}, - {`c:\windows\:d:`, -1, []string{`c:\windows\`, `d:`}}, - {`c:\windows:d:\s p a c e`, -1, []string{`c:\windows`, `d:\s p a c e`}}, - {`c:\windows:d:\s p a c e:RW`, -1, []string{`c:\windows`, `d:\s p a c e`, `RW`}}, - {`c:\program files:d:\s p a c e i n h o s t d i r`, -1, []string{`c:\program files`, `d:\s p a c e i n h o s t d i r`}}, - {`0123456789name:d:`, -1, []string{`0123456789name`, `d:`}}, - {`MiXeDcAsEnAmE:d:`, -1, []string{`MiXeDcAsEnAmE`, `d:`}}, - {`name:D:`, -1, []string{`name`, `D:`}}, - {`name:D::rW`, -1, []string{`name`, `D:`, `rW`}}, - {`name:D::RW`, -1, []string{`name`, `D:`, `RW`}}, - {`c:/:d:/forward/slashes/are/good/too`, -1, []string{`c:/`, `d:/forward/slashes/are/good/too`}}, - {`c:\Windows`, -1, []string{`c:\Windows`}}, - {`c:\Program Files (x86)`, -1, []string{`c:\Program Files (x86)`}}, - - {``, -1, nil}, - {`.`, -1, []string{`.`}}, - {`..\`, -1, []string{`..\`}}, - {`c:\:..\`, -1, []string{`c:\`, `..\`}}, - {`c:\:d:\:xyzzy`, -1, []string{`c:\`, `d:\`, `xyzzy`}}, - - // Cover directories with one-character name - {`/tmp/x/y:/foo/x/y`, -1, []string{`/tmp/x/y`, `/foo/x/y`}}, - } { - res := volumeSplitN(x.input, x.n) - if len(res) < len(x.expected) { - t.Fatalf("input: %v, expected: %v, got: %v", x.input, x.expected, res) - } - for i, e := range res { - if e != x.expected[i] { - t.Fatalf("input: %v, expected: %v, got: %v", x.input, x.expected, res) - } - } - } -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/runtime.go b/vendor/github.com/docker/docker/runconfig/opts/runtime.go deleted file mode 100644 index 4361b3c..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/runtime.go +++ /dev/null @@ -1,79 +0,0 @@ -package opts - -import ( - "fmt" - "strings" - - "github.com/docker/docker/api/types" -) - -// RuntimeOpt defines a map of Runtimes -type RuntimeOpt struct { - name string - stockRuntimeName string - values *map[string]types.Runtime -} - -// NewNamedRuntimeOpt creates a new RuntimeOpt -func NewNamedRuntimeOpt(name string, ref *map[string]types.Runtime, stockRuntime string) *RuntimeOpt { - if ref == nil { - ref = &map[string]types.Runtime{} - } - return &RuntimeOpt{name: name, values: ref, stockRuntimeName: stockRuntime} -} - -// Name returns the name of the NamedListOpts in the configuration. -func (o *RuntimeOpt) Name() string { - return o.name -} - -// Set validates and updates the list of Runtimes -func (o *RuntimeOpt) Set(val string) error { - parts := strings.SplitN(val, "=", 2) - if len(parts) != 2 { - return fmt.Errorf("invalid runtime argument: %s", val) - } - - parts[0] = strings.TrimSpace(parts[0]) - parts[1] = strings.TrimSpace(parts[1]) - if parts[0] == "" || parts[1] == "" { - return fmt.Errorf("invalid runtime argument: %s", val) - } - - parts[0] = strings.ToLower(parts[0]) - if parts[0] == o.stockRuntimeName { - return fmt.Errorf("runtime name '%s' is reserved", o.stockRuntimeName) - } - - if _, ok := (*o.values)[parts[0]]; ok { - return fmt.Errorf("runtime '%s' was already defined", parts[0]) - } - - (*o.values)[parts[0]] = types.Runtime{Path: parts[1]} - - return nil -} - -// String returns Runtime values as a string. -func (o *RuntimeOpt) String() string { - var out []string - for k := range *o.values { - out = append(out, k) - } - - return fmt.Sprintf("%v", out) -} - -// GetMap returns a map of Runtimes (name: path) -func (o *RuntimeOpt) GetMap() map[string]types.Runtime { - if o.values != nil { - return *o.values - } - - return map[string]types.Runtime{} -} - -// Type returns the type of the option -func (o *RuntimeOpt) Type() string { - return "runtime" -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/throttledevice.go b/vendor/github.com/docker/docker/runconfig/opts/throttledevice.go deleted file mode 100644 index 5024324..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/throttledevice.go +++ /dev/null @@ -1,111 +0,0 @@ -package opts - -import ( - "fmt" - "strconv" - "strings" - - "github.com/docker/docker/api/types/blkiodev" - "github.com/docker/go-units" -) - -// ValidatorThrottleFctType defines a validator function that returns a validated struct and/or an error. -type ValidatorThrottleFctType func(val string) (*blkiodev.ThrottleDevice, error) - -// ValidateThrottleBpsDevice validates that the specified string has a valid device-rate format. -func ValidateThrottleBpsDevice(val string) (*blkiodev.ThrottleDevice, error) { - split := strings.SplitN(val, ":", 2) - if len(split) != 2 { - return nil, fmt.Errorf("bad format: %s", val) - } - if !strings.HasPrefix(split[0], "/dev/") { - return nil, fmt.Errorf("bad format for device path: %s", val) - } - rate, err := units.RAMInBytes(split[1]) - if err != nil { - return nil, fmt.Errorf("invalid rate for device: %s. The correct format is :[]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb", val) - } - if rate < 0 { - return nil, fmt.Errorf("invalid rate for device: %s. The correct format is :[]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb", val) - } - - return &blkiodev.ThrottleDevice{ - Path: split[0], - Rate: uint64(rate), - }, nil -} - -// ValidateThrottleIOpsDevice validates that the specified string has a valid device-rate format. -func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, error) { - split := strings.SplitN(val, ":", 2) - if len(split) != 2 { - return nil, fmt.Errorf("bad format: %s", val) - } - if !strings.HasPrefix(split[0], "/dev/") { - return nil, fmt.Errorf("bad format for device path: %s", val) - } - rate, err := strconv.ParseUint(split[1], 10, 64) - if err != nil { - return nil, fmt.Errorf("invalid rate for device: %s. The correct format is :. Number must be a positive integer", val) - } - if rate < 0 { - return nil, fmt.Errorf("invalid rate for device: %s. The correct format is :. Number must be a positive integer", val) - } - - return &blkiodev.ThrottleDevice{ - Path: split[0], - Rate: uint64(rate), - }, nil -} - -// ThrottledeviceOpt defines a map of ThrottleDevices -type ThrottledeviceOpt struct { - values []*blkiodev.ThrottleDevice - validator ValidatorThrottleFctType -} - -// NewThrottledeviceOpt creates a new ThrottledeviceOpt -func NewThrottledeviceOpt(validator ValidatorThrottleFctType) ThrottledeviceOpt { - values := []*blkiodev.ThrottleDevice{} - return ThrottledeviceOpt{ - values: values, - validator: validator, - } -} - -// Set validates a ThrottleDevice and sets its name as a key in ThrottledeviceOpt -func (opt *ThrottledeviceOpt) Set(val string) error { - var value *blkiodev.ThrottleDevice - if opt.validator != nil { - v, err := opt.validator(val) - if err != nil { - return err - } - value = v - } - (opt.values) = append((opt.values), value) - return nil -} - -// String returns ThrottledeviceOpt values as a string. -func (opt *ThrottledeviceOpt) String() string { - var out []string - for _, v := range opt.values { - out = append(out, v.String()) - } - - return fmt.Sprintf("%v", out) -} - -// GetList returns a slice of pointers to ThrottleDevices. -func (opt *ThrottledeviceOpt) GetList() []*blkiodev.ThrottleDevice { - var throttledevice []*blkiodev.ThrottleDevice - throttledevice = append(throttledevice, opt.values...) - - return throttledevice -} - -// Type returns the option type -func (opt *ThrottledeviceOpt) Type() string { - return "throttled-device" -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/ulimit.go b/vendor/github.com/docker/docker/runconfig/opts/ulimit.go deleted file mode 100644 index 5adfe30..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/ulimit.go +++ /dev/null @@ -1,57 +0,0 @@ -package opts - -import ( - "fmt" - - "github.com/docker/go-units" -) - -// UlimitOpt defines a map of Ulimits -type UlimitOpt struct { - values *map[string]*units.Ulimit -} - -// NewUlimitOpt creates a new UlimitOpt -func NewUlimitOpt(ref *map[string]*units.Ulimit) *UlimitOpt { - if ref == nil { - ref = &map[string]*units.Ulimit{} - } - return &UlimitOpt{ref} -} - -// Set validates a Ulimit and sets its name as a key in UlimitOpt -func (o *UlimitOpt) Set(val string) error { - l, err := units.ParseUlimit(val) - if err != nil { - return err - } - - (*o.values)[l.Name] = l - - return nil -} - -// String returns Ulimit values as a string. -func (o *UlimitOpt) String() string { - var out []string - for _, v := range *o.values { - out = append(out, v.String()) - } - - return fmt.Sprintf("%v", out) -} - -// GetList returns a slice of pointers to Ulimits. -func (o *UlimitOpt) GetList() []*units.Ulimit { - var ulimits []*units.Ulimit - for _, v := range *o.values { - ulimits = append(ulimits, v) - } - - return ulimits -} - -// Type returns the option type -func (o *UlimitOpt) Type() string { - return "ulimit" -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/ulimit_test.go b/vendor/github.com/docker/docker/runconfig/opts/ulimit_test.go deleted file mode 100644 index 0aa3fac..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/ulimit_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package opts - -import ( - "testing" - - "github.com/docker/go-units" -) - -func TestUlimitOpt(t *testing.T) { - ulimitMap := map[string]*units.Ulimit{ - "nofile": {"nofile", 1024, 512}, - } - - ulimitOpt := NewUlimitOpt(&ulimitMap) - - expected := "[nofile=512:1024]" - if ulimitOpt.String() != expected { - t.Fatalf("Expected %v, got %v", expected, ulimitOpt) - } - - // Valid ulimit append to opts - if err := ulimitOpt.Set("core=1024:1024"); err != nil { - t.Fatal(err) - } - - // Invalid ulimit type returns an error and do not append to opts - if err := ulimitOpt.Set("notavalidtype=1024:1024"); err == nil { - t.Fatalf("Expected error on invalid ulimit type") - } - expected = "[nofile=512:1024 core=1024:1024]" - expected2 := "[core=1024:1024 nofile=512:1024]" - result := ulimitOpt.String() - if result != expected && result != expected2 { - t.Fatalf("Expected %v or %v, got %v", expected, expected2, ulimitOpt) - } - - // And test GetList - ulimits := ulimitOpt.GetList() - if len(ulimits) != 2 { - t.Fatalf("Expected a ulimit list of 2, got %v", ulimits) - } -} diff --git a/vendor/github.com/docker/docker/runconfig/opts/weightdevice.go b/vendor/github.com/docker/docker/runconfig/opts/weightdevice.go deleted file mode 100644 index 2a5da6d..0000000 --- a/vendor/github.com/docker/docker/runconfig/opts/weightdevice.go +++ /dev/null @@ -1,89 +0,0 @@ -package opts - -import ( - "fmt" - "strconv" - "strings" - - "github.com/docker/docker/api/types/blkiodev" -) - -// ValidatorWeightFctType defines a validator function that returns a validated struct and/or an error. -type ValidatorWeightFctType func(val string) (*blkiodev.WeightDevice, error) - -// ValidateWeightDevice validates that the specified string has a valid device-weight format. -func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error) { - split := strings.SplitN(val, ":", 2) - if len(split) != 2 { - return nil, fmt.Errorf("bad format: %s", val) - } - if !strings.HasPrefix(split[0], "/dev/") { - return nil, fmt.Errorf("bad format for device path: %s", val) - } - weight, err := strconv.ParseUint(split[1], 10, 0) - if err != nil { - return nil, fmt.Errorf("invalid weight for device: %s", val) - } - if weight > 0 && (weight < 10 || weight > 1000) { - return nil, fmt.Errorf("invalid weight for device: %s", val) - } - - return &blkiodev.WeightDevice{ - Path: split[0], - Weight: uint16(weight), - }, nil -} - -// WeightdeviceOpt defines a map of WeightDevices -type WeightdeviceOpt struct { - values []*blkiodev.WeightDevice - validator ValidatorWeightFctType -} - -// NewWeightdeviceOpt creates a new WeightdeviceOpt -func NewWeightdeviceOpt(validator ValidatorWeightFctType) WeightdeviceOpt { - values := []*blkiodev.WeightDevice{} - return WeightdeviceOpt{ - values: values, - validator: validator, - } -} - -// Set validates a WeightDevice and sets its name as a key in WeightdeviceOpt -func (opt *WeightdeviceOpt) Set(val string) error { - var value *blkiodev.WeightDevice - if opt.validator != nil { - v, err := opt.validator(val) - if err != nil { - return err - } - value = v - } - (opt.values) = append((opt.values), value) - return nil -} - -// String returns WeightdeviceOpt values as a string. -func (opt *WeightdeviceOpt) String() string { - var out []string - for _, v := range opt.values { - out = append(out, v.String()) - } - - return fmt.Sprintf("%v", out) -} - -// GetList returns a slice of pointers to WeightDevices. -func (opt *WeightdeviceOpt) GetList() []*blkiodev.WeightDevice { - var weightdevice []*blkiodev.WeightDevice - for _, v := range opt.values { - weightdevice = append(weightdevice, v) - } - - return weightdevice -} - -// Type returns the option type -func (opt *WeightdeviceOpt) Type() string { - return "weighted-device" -} diff --git a/vendor/github.com/docker/docker/utils/debug.go b/vendor/github.com/docker/docker/utils/debug.go deleted file mode 100644 index d203891..0000000 --- a/vendor/github.com/docker/docker/utils/debug.go +++ /dev/null @@ -1,26 +0,0 @@ -package utils - -import ( - "os" - - "github.com/Sirupsen/logrus" -) - -// EnableDebug sets the DEBUG env var to true -// and makes the logger to log at debug level. -func EnableDebug() { - os.Setenv("DEBUG", "1") - logrus.SetLevel(logrus.DebugLevel) -} - -// DisableDebug sets the DEBUG env var to false -// and makes the logger to log at info level. -func DisableDebug() { - os.Setenv("DEBUG", "") - logrus.SetLevel(logrus.InfoLevel) -} - -// IsDebugEnabled checks whether the debug flag is set or not. -func IsDebugEnabled() bool { - return os.Getenv("DEBUG") != "" -} diff --git a/vendor/github.com/docker/docker/utils/debug_test.go b/vendor/github.com/docker/docker/utils/debug_test.go deleted file mode 100644 index 6f9c4df..0000000 --- a/vendor/github.com/docker/docker/utils/debug_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package utils - -import ( - "os" - "testing" - - "github.com/Sirupsen/logrus" -) - -func TestEnableDebug(t *testing.T) { - defer func() { - os.Setenv("DEBUG", "") - logrus.SetLevel(logrus.InfoLevel) - }() - EnableDebug() - if os.Getenv("DEBUG") != "1" { - t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG")) - } - if logrus.GetLevel() != logrus.DebugLevel { - t.Fatalf("expected log level %v, got %v\n", logrus.DebugLevel, logrus.GetLevel()) - } -} - -func TestDisableDebug(t *testing.T) { - DisableDebug() - if os.Getenv("DEBUG") != "" { - t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG")) - } - if logrus.GetLevel() != logrus.InfoLevel { - t.Fatalf("expected log level %v, got %v\n", logrus.InfoLevel, logrus.GetLevel()) - } -} - -func TestDebugEnabled(t *testing.T) { - EnableDebug() - if !IsDebugEnabled() { - t.Fatal("expected debug enabled, got false") - } - DisableDebug() - if IsDebugEnabled() { - t.Fatal("expected debug disabled, got true") - } -} diff --git a/vendor/github.com/docker/docker/utils/names.go b/vendor/github.com/docker/docker/utils/names.go deleted file mode 100644 index 6320628..0000000 --- a/vendor/github.com/docker/docker/utils/names.go +++ /dev/null @@ -1,9 +0,0 @@ -package utils - -import "regexp" - -// RestrictedNameChars collects the characters allowed to represent a name, normally used to validate container and volume names. -const RestrictedNameChars = `[a-zA-Z0-9][a-zA-Z0-9_.-]` - -// RestrictedNamePattern is a regular expression to validate names against the collection of restricted characters. -var RestrictedNamePattern = regexp.MustCompile(`^` + RestrictedNameChars + `+$`) diff --git a/vendor/github.com/docker/docker/utils/process_unix.go b/vendor/github.com/docker/docker/utils/process_unix.go deleted file mode 100644 index fc0b1c8..0000000 --- a/vendor/github.com/docker/docker/utils/process_unix.go +++ /dev/null @@ -1,22 +0,0 @@ -// +build linux freebsd solaris - -package utils - -import ( - "syscall" -) - -// IsProcessAlive returns true if process with a given pid is running. -func IsProcessAlive(pid int) bool { - err := syscall.Kill(pid, syscall.Signal(0)) - if err == nil || err == syscall.EPERM { - return true - } - - return false -} - -// KillProcess force-stops a process. -func KillProcess(pid int) { - syscall.Kill(pid, syscall.SIGKILL) -} diff --git a/vendor/github.com/docker/docker/utils/process_windows.go b/vendor/github.com/docker/docker/utils/process_windows.go deleted file mode 100644 index 03cb855..0000000 --- a/vendor/github.com/docker/docker/utils/process_windows.go +++ /dev/null @@ -1,20 +0,0 @@ -package utils - -// IsProcessAlive returns true if process with a given pid is running. -func IsProcessAlive(pid int) bool { - // TODO Windows containerd. Not sure this is needed - // p, err := os.FindProcess(pid) - // if err == nil { - // return true - // } - return false -} - -// KillProcess force-stops a process. -func KillProcess(pid int) { - // TODO Windows containerd. Not sure this is needed - // p, err := os.FindProcess(pid) - // if err == nil { - // p.Kill() - // } -} diff --git a/vendor/github.com/docker/docker/utils/templates/templates.go b/vendor/github.com/docker/docker/utils/templates/templates.go deleted file mode 100644 index 91c376f..0000000 --- a/vendor/github.com/docker/docker/utils/templates/templates.go +++ /dev/null @@ -1,42 +0,0 @@ -package templates - -import ( - "encoding/json" - "strings" - "text/template" -) - -// basicFunctions are the set of initial -// functions provided to every template. -var basicFunctions = template.FuncMap{ - "json": func(v interface{}) string { - a, _ := json.Marshal(v) - return string(a) - }, - "split": strings.Split, - "join": strings.Join, - "title": strings.Title, - "lower": strings.ToLower, - "upper": strings.ToUpper, - "pad": padWithSpace, -} - -// Parse creates a new annonymous template with the basic functions -// and parses the given format. -func Parse(format string) (*template.Template, error) { - return NewParse("", format) -} - -// NewParse creates a new tagged template with the basic functions -// and parses the given format. -func NewParse(tag, format string) (*template.Template, error) { - return template.New(tag).Funcs(basicFunctions).Parse(format) -} - -// padWithSpace adds whitespace to the input if the input is non-empty -func padWithSpace(source string, prefix, suffix int) string { - if source == "" { - return source - } - return strings.Repeat(" ", prefix) + source + strings.Repeat(" ", suffix) -} diff --git a/vendor/github.com/docker/docker/utils/templates/templates_test.go b/vendor/github.com/docker/docker/utils/templates/templates_test.go deleted file mode 100644 index dd42901..0000000 --- a/vendor/github.com/docker/docker/utils/templates/templates_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package templates - -import ( - "bytes" - "testing" -) - -func TestParseStringFunctions(t *testing.T) { - tm, err := Parse(`{{join (split . ":") "/"}}`) - if err != nil { - t.Fatal(err) - } - - var b bytes.Buffer - if err := tm.Execute(&b, "text:with:colon"); err != nil { - t.Fatal(err) - } - want := "text/with/colon" - if b.String() != want { - t.Fatalf("expected %s, got %s", want, b.String()) - } -} - -func TestNewParse(t *testing.T) { - tm, err := NewParse("foo", "this is a {{ . }}") - if err != nil { - t.Fatal(err) - } - - var b bytes.Buffer - if err := tm.Execute(&b, "string"); err != nil { - t.Fatal(err) - } - want := "this is a string" - if b.String() != want { - t.Fatalf("expected %s, got %s", want, b.String()) - } -} diff --git a/vendor/github.com/docker/docker/utils/utils.go b/vendor/github.com/docker/docker/utils/utils.go deleted file mode 100644 index d3dd00a..0000000 --- a/vendor/github.com/docker/docker/utils/utils.go +++ /dev/null @@ -1,87 +0,0 @@ -package utils - -import ( - "fmt" - "io/ioutil" - "os" - "runtime" - "strings" - - "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/stringid" -) - -var globalTestID string - -// TestDirectory creates a new temporary directory and returns its path. -// The contents of directory at path `templateDir` is copied into the -// new directory. -func TestDirectory(templateDir string) (dir string, err error) { - if globalTestID == "" { - globalTestID = stringid.GenerateNonCryptoID()[:4] - } - prefix := fmt.Sprintf("docker-test%s-%s-", globalTestID, GetCallerName(2)) - if prefix == "" { - prefix = "docker-test-" - } - dir, err = ioutil.TempDir("", prefix) - if err = os.Remove(dir); err != nil { - return - } - if templateDir != "" { - if err = archive.CopyWithTar(templateDir, dir); err != nil { - return - } - } - return -} - -// GetCallerName introspects the call stack and returns the name of the -// function `depth` levels down in the stack. -func GetCallerName(depth int) string { - // Use the caller function name as a prefix. - // This helps trace temp directories back to their test. - pc, _, _, _ := runtime.Caller(depth + 1) - callerLongName := runtime.FuncForPC(pc).Name() - parts := strings.Split(callerLongName, ".") - callerShortName := parts[len(parts)-1] - return callerShortName -} - -// ReplaceOrAppendEnvValues returns the defaults with the overrides either -// replaced by env key or appended to the list -func ReplaceOrAppendEnvValues(defaults, overrides []string) []string { - cache := make(map[string]int, len(defaults)) - for i, e := range defaults { - parts := strings.SplitN(e, "=", 2) - cache[parts[0]] = i - } - - for _, value := range overrides { - // Values w/o = means they want this env to be removed/unset. - if !strings.Contains(value, "=") { - if i, exists := cache[value]; exists { - defaults[i] = "" // Used to indicate it should be removed - } - continue - } - - // Just do a normal set/update - parts := strings.SplitN(value, "=", 2) - if i, exists := cache[parts[0]]; exists { - defaults[i] = value - } else { - defaults = append(defaults, value) - } - } - - // Now remove all entries that we want to "unset" - for i := 0; i < len(defaults); i++ { - if defaults[i] == "" { - defaults = append(defaults[:i], defaults[i+1:]...) - i-- - } - } - - return defaults -} diff --git a/vendor/github.com/docker/docker/utils/utils_test.go b/vendor/github.com/docker/docker/utils/utils_test.go deleted file mode 100644 index ab3911e..0000000 --- a/vendor/github.com/docker/docker/utils/utils_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package utils - -import "testing" - -func TestReplaceAndAppendEnvVars(t *testing.T) { - var ( - d = []string{"HOME=/"} - o = []string{"HOME=/root", "TERM=xterm"} - ) - - env := ReplaceOrAppendEnvValues(d, o) - if len(env) != 2 { - t.Fatalf("expected len of 2 got %d", len(env)) - } - if env[0] != "HOME=/root" { - t.Fatalf("expected HOME=/root got '%s'", env[0]) - } - if env[1] != "TERM=xterm" { - t.Fatalf("expected TERM=xterm got '%s'", env[1]) - } -} diff --git a/vendor/github.com/docker/docker/vendor.conf b/vendor/github.com/docker/docker/vendor.conf deleted file mode 100644 index bb7718b..0000000 --- a/vendor/github.com/docker/docker/vendor.conf +++ /dev/null @@ -1,140 +0,0 @@ -# the following lines are in sorted order, FYI -github.com/Azure/go-ansiterm 388960b655244e76e24c75f48631564eaefade62 -github.com/Microsoft/hcsshim v0.5.9 -github.com/Microsoft/go-winio v0.3.8 -github.com/Sirupsen/logrus v0.11.0 -github.com/davecgh/go-spew 6d212800a42e8ab5c146b8ace3490ee17e5225f9 -github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a -github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git -github.com/gorilla/context v1.1 -github.com/gorilla/mux v1.1 -github.com/kr/pty 5cf931ef8f -github.com/mattn/go-shellwords v1.0.0 -github.com/mattn/go-sqlite3 v1.1.0 -github.com/tchap/go-patricia v2.2.6 -github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3 -# forked golang.org/x/net package includes a patch for lazy loading trace templates -golang.org/x/net 2beffdc2e92c8a3027590f898fe88f69af48a3f8 https://github.com/tonistiigi/net.git -golang.org/x/sys 8f0908ab3b2457e2e15403d3697c9ef5cb4b57a9 -github.com/docker/go-units 8a7beacffa3009a9ac66bad506b18ffdd110cf97 -github.com/docker/go-connections ecb4cb2dd420ada7df7f2593d6c25441f65f69f2 - -github.com/RackSec/srslog 456df3a81436d29ba874f3590eeeee25d666f8a5 -github.com/imdario/mergo 0.2.1 - -#get libnetwork packages -github.com/docker/libnetwork 45b40861e677e37cf27bc184eca5af92f8cdd32d -github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894 -github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80 -github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec -github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b -github.com/hashicorp/memberlist 88ac4de0d1a0ca6def284b571342db3b777a4c37 -github.com/hashicorp/go-multierror fcdddc395df1ddf4247c69bd436e84cfa0733f7e -github.com/hashicorp/serf 598c54895cc5a7b1a24a398d635e8c0ea0959870 -github.com/docker/libkv 1d8431073ae03cdaedb198a89722f3aab6d418ef -github.com/vishvananda/netns 604eaf189ee867d8c147fafc28def2394e878d25 -github.com/vishvananda/netlink 482f7a52b758233521878cb6c5904b6bd63f3457 -github.com/BurntSushi/toml f706d00e3de6abe700c994cdd545a1a4915af060 -github.com/samuel/go-zookeeper d0e0d8e11f318e000a8cc434616d69e329edc374 -github.com/deckarep/golang-set ef32fa3046d9f249d399f98ebaf9be944430fd1d -github.com/coreos/etcd 3a49cbb769ebd8d1dd25abb1e83386e9883a5707 -github.com/ugorji/go f1f1a805ed361a0e078bb537e4ea78cd37dcf065 -github.com/hashicorp/consul v0.5.2 -github.com/boltdb/bolt fff57c100f4dea1905678da7e90d92429dff2904 -github.com/miekg/dns 75e6e86cc601825c5dbcd4e0c209eab180997cd7 - -# get graph and distribution packages -github.com/docker/distribution 28602af35aceda2f8d571bad7ca37a54cf0250bc -github.com/vbatts/tar-split v0.10.1 - -# get go-zfs packages -github.com/mistifyio/go-zfs 22c9b32c84eb0d0c6f4043b6e90fc94073de92fa -github.com/pborman/uuid v1.0 - -# get desired notary commit, might also need to be updated in Dockerfile -github.com/docker/notary v0.4.2 - -google.golang.org/grpc v1.0.2 -github.com/miekg/pkcs11 df8ae6ca730422dba20c768ff38ef7d79077a59f -github.com/docker/go v1.5.1-1-1-gbaf439e -github.com/agl/ed25519 d2b94fd789ea21d12fac1a4443dd3a3f79cda72c - -# When updating, also update RUNC_COMMIT in hack/dockerfile/binaries-commits accordingly -github.com/opencontainers/runc 9df8b306d01f59d3a8029be411de015b7304dd8f https://github.com/docker/runc.git # libcontainer -github.com/opencontainers/runtime-spec 1c7c27d043c2a5e513a44084d2b10d77d1402b8c # specs -github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0 -# libcontainer deps (see src/github.com/opencontainers/runc/Godeps/Godeps.json) -github.com/coreos/go-systemd v4 -github.com/godbus/dbus v4.0.0 -github.com/syndtr/gocapability 2c00daeb6c3b45114c80ac44119e7b8801fdd852 -github.com/golang/protobuf 1f49d83d9aa00e6ce4fc8258c71cc7786aec968a - -# gelf logging driver deps -github.com/Graylog2/go-gelf aab2f594e4585d43468ac57287b0dece9d806883 - -github.com/fluent/fluent-logger-golang v1.2.1 -# fluent-logger-golang deps -github.com/philhofer/fwd 899e4efba8eaa1fea74175308f3fae18ff3319fa -github.com/tinylib/msgp 75ee40d2601edf122ef667e2a07d600d4c44490c - -# fsnotify -github.com/fsnotify/fsnotify v1.2.11 - -# awslogs deps -github.com/aws/aws-sdk-go v1.4.22 -github.com/go-ini/ini 060d7da055ba6ec5ea7a31f116332fe5efa04ce0 -github.com/jmespath/go-jmespath 0b12d6b521d83fc7f755e7cfc1b1fbdd35a01a74 - -# logentries -github.com/bsphere/le_go d3308aafe090956bc89a65f0769f58251a1b4f03 - -# gcplogs deps -golang.org/x/oauth2 2baa8a1b9338cf13d9eeb27696d761155fa480be -google.golang.org/api dc6d2353af16e2a2b0ff6986af051d473a4ed468 -google.golang.org/cloud dae7e3d993bc3812a2185af60552bb6b847e52a0 - -# native credentials -github.com/docker/docker-credential-helpers f72c04f1d8e71959a6d103f808c50ccbad79b9fd - -# containerd -github.com/docker/containerd aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1 -github.com/tonistiigi/fifo 1405643975692217d6720f8b54aeee1bf2cd5cf4 - -# cluster -github.com/docker/swarmkit 1c7f003d75f091d5f7051ed982594420e4515f77 -github.com/golang/mock bd3c8e81be01eef76d4b503f5e687d2d1354d2d9 -github.com/gogo/protobuf v0.3 -github.com/cloudflare/cfssl 7fb22c8cba7ecaf98e4082d22d65800cf45e042a -github.com/google/certificate-transparency d90e65c3a07988180c5b1ece71791c0b6506826e -golang.org/x/crypto 3fbbcd23f1cb824e69491a5930cfeff09b12f4d2 -golang.org/x/time a4bde12657593d5e90d0533a3e4fd95e635124cb -github.com/mreiferson/go-httpclient 63fe23f7434723dc904c901043af07931f293c47 -github.com/hashicorp/go-memdb 608dda3b1410a73eaf3ac8b517c9ae7ebab6aa87 -github.com/hashicorp/go-immutable-radix 8e8ed81f8f0bf1bdd829593fdd5c29922c1ea990 -github.com/hashicorp/golang-lru a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4 -github.com/coreos/pkg fa29b1d70f0beaddd4c7021607cc3c3be8ce94b8 -github.com/pivotal-golang/clock 3fd3c1944c59d9742e1cd333672181cd1a6f9fa0 -github.com/prometheus/client_golang 52437c81da6b127a9925d17eb3a382a2e5fd395e -github.com/beorn7/perks 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 -github.com/prometheus/client_model fa8ad6fec33561be4280a8f0514318c79d7f6cb6 -github.com/prometheus/common ebdfc6da46522d58825777cf1f90490a5b1ef1d8 -github.com/prometheus/procfs abf152e5f3e97f2fafac028d2cc06c1feb87ffa5 -bitbucket.org/ww/goautoneg 75cd24fc2f2c2a2088577d12123ddee5f54e0675 -github.com/matttproud/golang_protobuf_extensions fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a -github.com/pkg/errors 839d9e913e063e28dfd0e6c7b7512793e0a48be9 - -# cli -github.com/spf13/cobra v1.5 https://github.com/dnephin/cobra.git -github.com/spf13/pflag dabebe21bf790f782ea4c7bbd2efc430de182afd -github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 -github.com/flynn-archive/go-shlex 3f9db97f856818214da2e1057f8ad84803971cff - -# metrics -github.com/docker/go-metrics 86138d05f285fd9737a99bee2d9be30866b59d72 - -# composefile -github.com/mitchellh/mapstructure f3009df150dadf309fdee4a54ed65c124afad715 -github.com/xeipuuv/gojsonpointer e0fe6f68307607d540ed8eac07a342c33fa1b54a -github.com/xeipuuv/gojsonreference e02fc20de94c78484cd5ffb007f8af96be030a45 -github.com/xeipuuv/gojsonschema 93e72a773fade158921402d6a24c819b48aba29d -gopkg.in/yaml.v2 a83829b6f1293c91addabc89d0571c246397bbf4 diff --git a/vendor/github.com/docker/docker/volume/drivers/adapter.go b/vendor/github.com/docker/docker/volume/drivers/adapter.go deleted file mode 100644 index 62ef7df..0000000 --- a/vendor/github.com/docker/docker/volume/drivers/adapter.go +++ /dev/null @@ -1,177 +0,0 @@ -package volumedrivers - -import ( - "errors" - "path/filepath" - "strings" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/volume" -) - -var ( - errNoSuchVolume = errors.New("no such volume") -) - -type volumeDriverAdapter struct { - name string - baseHostPath string - capabilities *volume.Capability - proxy *volumeDriverProxy -} - -func (a *volumeDriverAdapter) Name() string { - return a.name -} - -func (a *volumeDriverAdapter) Create(name string, opts map[string]string) (volume.Volume, error) { - if err := a.proxy.Create(name, opts); err != nil { - return nil, err - } - return &volumeAdapter{ - proxy: a.proxy, - name: name, - driverName: a.name, - baseHostPath: a.baseHostPath, - }, nil -} - -func (a *volumeDriverAdapter) Remove(v volume.Volume) error { - return a.proxy.Remove(v.Name()) -} - -func hostPath(baseHostPath, path string) string { - if baseHostPath != "" { - path = filepath.Join(baseHostPath, path) - } - return path -} - -func (a *volumeDriverAdapter) List() ([]volume.Volume, error) { - ls, err := a.proxy.List() - if err != nil { - return nil, err - } - - var out []volume.Volume - for _, vp := range ls { - out = append(out, &volumeAdapter{ - proxy: a.proxy, - name: vp.Name, - baseHostPath: a.baseHostPath, - driverName: a.name, - eMount: hostPath(a.baseHostPath, vp.Mountpoint), - }) - } - return out, nil -} - -func (a *volumeDriverAdapter) Get(name string) (volume.Volume, error) { - v, err := a.proxy.Get(name) - if err != nil { - return nil, err - } - - // plugin may have returned no volume and no error - if v == nil { - return nil, errNoSuchVolume - } - - return &volumeAdapter{ - proxy: a.proxy, - name: v.Name, - driverName: a.Name(), - eMount: v.Mountpoint, - status: v.Status, - baseHostPath: a.baseHostPath, - }, nil -} - -func (a *volumeDriverAdapter) Scope() string { - cap := a.getCapabilities() - return cap.Scope -} - -func (a *volumeDriverAdapter) getCapabilities() volume.Capability { - if a.capabilities != nil { - return *a.capabilities - } - cap, err := a.proxy.Capabilities() - if err != nil { - // `GetCapabilities` is a not a required endpoint. - // On error assume it's a local-only driver - logrus.Warnf("Volume driver %s returned an error while trying to query its capabilities, using default capabilties: %v", a.name, err) - return volume.Capability{Scope: volume.LocalScope} - } - - // don't spam the warn log below just because the plugin didn't provide a scope - if len(cap.Scope) == 0 { - cap.Scope = volume.LocalScope - } - - cap.Scope = strings.ToLower(cap.Scope) - if cap.Scope != volume.LocalScope && cap.Scope != volume.GlobalScope { - logrus.Warnf("Volume driver %q returned an invalid scope: %q", a.Name(), cap.Scope) - cap.Scope = volume.LocalScope - } - - a.capabilities = &cap - return cap -} - -type volumeAdapter struct { - proxy *volumeDriverProxy - name string - baseHostPath string - driverName string - eMount string // ephemeral host volume path - status map[string]interface{} -} - -type proxyVolume struct { - Name string - Mountpoint string - Status map[string]interface{} -} - -func (a *volumeAdapter) Name() string { - return a.name -} - -func (a *volumeAdapter) DriverName() string { - return a.driverName -} - -func (a *volumeAdapter) Path() string { - if len(a.eMount) == 0 { - mountpoint, _ := a.proxy.Path(a.name) - a.eMount = hostPath(a.baseHostPath, mountpoint) - } - return a.eMount -} - -func (a *volumeAdapter) CachedPath() string { - return a.eMount -} - -func (a *volumeAdapter) Mount(id string) (string, error) { - mountpoint, err := a.proxy.Mount(a.name, id) - a.eMount = hostPath(a.baseHostPath, mountpoint) - return a.eMount, err -} - -func (a *volumeAdapter) Unmount(id string) error { - err := a.proxy.Unmount(a.name, id) - if err == nil { - a.eMount = "" - } - return err -} - -func (a *volumeAdapter) Status() map[string]interface{} { - out := make(map[string]interface{}, len(a.status)) - for k, v := range a.status { - out[k] = v - } - return out -} diff --git a/vendor/github.com/docker/docker/volume/drivers/extpoint.go b/vendor/github.com/docker/docker/volume/drivers/extpoint.go deleted file mode 100644 index 576dee8..0000000 --- a/vendor/github.com/docker/docker/volume/drivers/extpoint.go +++ /dev/null @@ -1,215 +0,0 @@ -//go:generate pluginrpc-gen -i $GOFILE -o proxy.go -type volumeDriver -name VolumeDriver - -package volumedrivers - -import ( - "fmt" - "sync" - - "github.com/docker/docker/pkg/locker" - getter "github.com/docker/docker/pkg/plugingetter" - "github.com/docker/docker/volume" -) - -// currently created by hand. generation tool would generate this like: -// $ extpoint-gen Driver > volume/extpoint.go - -var drivers = &driverExtpoint{ - extensions: make(map[string]volume.Driver), - driverLock: &locker.Locker{}, -} - -const extName = "VolumeDriver" - -// NewVolumeDriver returns a driver has the given name mapped on the given client. -func NewVolumeDriver(name string, baseHostPath string, c client) volume.Driver { - proxy := &volumeDriverProxy{c} - return &volumeDriverAdapter{name: name, baseHostPath: baseHostPath, proxy: proxy} -} - -// volumeDriver defines the available functions that volume plugins must implement. -// This interface is only defined to generate the proxy objects. -// It's not intended to be public or reused. -type volumeDriver interface { - // Create a volume with the given name - Create(name string, opts map[string]string) (err error) - // Remove the volume with the given name - Remove(name string) (err error) - // Get the mountpoint of the given volume - Path(name string) (mountpoint string, err error) - // Mount the given volume and return the mountpoint - Mount(name, id string) (mountpoint string, err error) - // Unmount the given volume - Unmount(name, id string) (err error) - // List lists all the volumes known to the driver - List() (volumes []*proxyVolume, err error) - // Get retrieves the volume with the requested name - Get(name string) (volume *proxyVolume, err error) - // Capabilities gets the list of capabilities of the driver - Capabilities() (capabilities volume.Capability, err error) -} - -type driverExtpoint struct { - extensions map[string]volume.Driver - sync.Mutex - driverLock *locker.Locker - plugingetter getter.PluginGetter -} - -// RegisterPluginGetter sets the plugingetter -func RegisterPluginGetter(plugingetter getter.PluginGetter) { - drivers.plugingetter = plugingetter -} - -// Register associates the given driver to the given name, checking if -// the name is already associated -func Register(extension volume.Driver, name string) bool { - if name == "" { - return false - } - - drivers.Lock() - defer drivers.Unlock() - - _, exists := drivers.extensions[name] - if exists { - return false - } - - if err := validateDriver(extension); err != nil { - return false - } - - drivers.extensions[name] = extension - - return true -} - -// Unregister dissociates the name from its driver, if the association exists. -func Unregister(name string) bool { - drivers.Lock() - defer drivers.Unlock() - - _, exists := drivers.extensions[name] - if !exists { - return false - } - delete(drivers.extensions, name) - return true -} - -// lookup returns the driver associated with the given name. If a -// driver with the given name has not been registered it checks if -// there is a VolumeDriver plugin available with the given name. -func lookup(name string, mode int) (volume.Driver, error) { - drivers.driverLock.Lock(name) - defer drivers.driverLock.Unlock(name) - - drivers.Lock() - ext, ok := drivers.extensions[name] - drivers.Unlock() - if ok { - return ext, nil - } - if drivers.plugingetter != nil { - p, err := drivers.plugingetter.Get(name, extName, mode) - if err != nil { - return nil, fmt.Errorf("Error looking up volume plugin %s: %v", name, err) - } - - d := NewVolumeDriver(p.Name(), p.BasePath(), p.Client()) - if err := validateDriver(d); err != nil { - return nil, err - } - - if p.IsV1() { - drivers.Lock() - drivers.extensions[name] = d - drivers.Unlock() - } - return d, nil - } - return nil, fmt.Errorf("Error looking up volume plugin %s", name) -} - -func validateDriver(vd volume.Driver) error { - scope := vd.Scope() - if scope != volume.LocalScope && scope != volume.GlobalScope { - return fmt.Errorf("Driver %q provided an invalid capability scope: %s", vd.Name(), scope) - } - return nil -} - -// GetDriver returns a volume driver by its name. -// If the driver is empty, it looks for the local driver. -func GetDriver(name string) (volume.Driver, error) { - if name == "" { - name = volume.DefaultDriverName - } - return lookup(name, getter.LOOKUP) -} - -// CreateDriver returns a volume driver by its name and increments RefCount. -// If the driver is empty, it looks for the local driver. -func CreateDriver(name string) (volume.Driver, error) { - if name == "" { - name = volume.DefaultDriverName - } - return lookup(name, getter.ACQUIRE) -} - -// RemoveDriver returns a volume driver by its name and decrements RefCount.. -// If the driver is empty, it looks for the local driver. -func RemoveDriver(name string) (volume.Driver, error) { - if name == "" { - name = volume.DefaultDriverName - } - return lookup(name, getter.RELEASE) -} - -// GetDriverList returns list of volume drivers registered. -// If no driver is registered, empty string list will be returned. -func GetDriverList() []string { - var driverList []string - drivers.Lock() - for driverName := range drivers.extensions { - driverList = append(driverList, driverName) - } - drivers.Unlock() - return driverList -} - -// GetAllDrivers lists all the registered drivers -func GetAllDrivers() ([]volume.Driver, error) { - var plugins []getter.CompatPlugin - if drivers.plugingetter != nil { - var err error - plugins, err = drivers.plugingetter.GetAllByCap(extName) - if err != nil { - return nil, fmt.Errorf("error listing plugins: %v", err) - } - } - var ds []volume.Driver - - drivers.Lock() - defer drivers.Unlock() - - for _, d := range drivers.extensions { - ds = append(ds, d) - } - - for _, p := range plugins { - name := p.Name() - ext, ok := drivers.extensions[name] - if ok { - continue - } - - ext = NewVolumeDriver(name, p.BasePath(), p.Client()) - if p.IsV1() { - drivers.extensions[name] = ext - } - ds = append(ds, ext) - } - return ds, nil -} diff --git a/vendor/github.com/docker/docker/volume/drivers/extpoint_test.go b/vendor/github.com/docker/docker/volume/drivers/extpoint_test.go deleted file mode 100644 index 428b075..0000000 --- a/vendor/github.com/docker/docker/volume/drivers/extpoint_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package volumedrivers - -import ( - "testing" - - volumetestutils "github.com/docker/docker/volume/testutils" -) - -func TestGetDriver(t *testing.T) { - _, err := GetDriver("missing") - if err == nil { - t.Fatal("Expected error, was nil") - } - Register(volumetestutils.NewFakeDriver("fake"), "fake") - - d, err := GetDriver("fake") - if err != nil { - t.Fatal(err) - } - if d.Name() != "fake" { - t.Fatalf("Expected fake driver, got %s\n", d.Name()) - } -} diff --git a/vendor/github.com/docker/docker/volume/drivers/proxy.go b/vendor/github.com/docker/docker/volume/drivers/proxy.go deleted file mode 100644 index b23db62..0000000 --- a/vendor/github.com/docker/docker/volume/drivers/proxy.go +++ /dev/null @@ -1,242 +0,0 @@ -// generated code - DO NOT EDIT - -package volumedrivers - -import ( - "errors" - - "github.com/docker/docker/volume" -) - -type client interface { - Call(string, interface{}, interface{}) error -} - -type volumeDriverProxy struct { - client -} - -type volumeDriverProxyCreateRequest struct { - Name string - Opts map[string]string -} - -type volumeDriverProxyCreateResponse struct { - Err string -} - -func (pp *volumeDriverProxy) Create(name string, opts map[string]string) (err error) { - var ( - req volumeDriverProxyCreateRequest - ret volumeDriverProxyCreateResponse - ) - - req.Name = name - req.Opts = opts - if err = pp.Call("VolumeDriver.Create", req, &ret); err != nil { - return - } - - if ret.Err != "" { - err = errors.New(ret.Err) - } - - return -} - -type volumeDriverProxyRemoveRequest struct { - Name string -} - -type volumeDriverProxyRemoveResponse struct { - Err string -} - -func (pp *volumeDriverProxy) Remove(name string) (err error) { - var ( - req volumeDriverProxyRemoveRequest - ret volumeDriverProxyRemoveResponse - ) - - req.Name = name - if err = pp.Call("VolumeDriver.Remove", req, &ret); err != nil { - return - } - - if ret.Err != "" { - err = errors.New(ret.Err) - } - - return -} - -type volumeDriverProxyPathRequest struct { - Name string -} - -type volumeDriverProxyPathResponse struct { - Mountpoint string - Err string -} - -func (pp *volumeDriverProxy) Path(name string) (mountpoint string, err error) { - var ( - req volumeDriverProxyPathRequest - ret volumeDriverProxyPathResponse - ) - - req.Name = name - if err = pp.Call("VolumeDriver.Path", req, &ret); err != nil { - return - } - - mountpoint = ret.Mountpoint - - if ret.Err != "" { - err = errors.New(ret.Err) - } - - return -} - -type volumeDriverProxyMountRequest struct { - Name string - ID string -} - -type volumeDriverProxyMountResponse struct { - Mountpoint string - Err string -} - -func (pp *volumeDriverProxy) Mount(name string, id string) (mountpoint string, err error) { - var ( - req volumeDriverProxyMountRequest - ret volumeDriverProxyMountResponse - ) - - req.Name = name - req.ID = id - if err = pp.Call("VolumeDriver.Mount", req, &ret); err != nil { - return - } - - mountpoint = ret.Mountpoint - - if ret.Err != "" { - err = errors.New(ret.Err) - } - - return -} - -type volumeDriverProxyUnmountRequest struct { - Name string - ID string -} - -type volumeDriverProxyUnmountResponse struct { - Err string -} - -func (pp *volumeDriverProxy) Unmount(name string, id string) (err error) { - var ( - req volumeDriverProxyUnmountRequest - ret volumeDriverProxyUnmountResponse - ) - - req.Name = name - req.ID = id - if err = pp.Call("VolumeDriver.Unmount", req, &ret); err != nil { - return - } - - if ret.Err != "" { - err = errors.New(ret.Err) - } - - return -} - -type volumeDriverProxyListRequest struct { -} - -type volumeDriverProxyListResponse struct { - Volumes []*proxyVolume - Err string -} - -func (pp *volumeDriverProxy) List() (volumes []*proxyVolume, err error) { - var ( - req volumeDriverProxyListRequest - ret volumeDriverProxyListResponse - ) - - if err = pp.Call("VolumeDriver.List", req, &ret); err != nil { - return - } - - volumes = ret.Volumes - - if ret.Err != "" { - err = errors.New(ret.Err) - } - - return -} - -type volumeDriverProxyGetRequest struct { - Name string -} - -type volumeDriverProxyGetResponse struct { - Volume *proxyVolume - Err string -} - -func (pp *volumeDriverProxy) Get(name string) (volume *proxyVolume, err error) { - var ( - req volumeDriverProxyGetRequest - ret volumeDriverProxyGetResponse - ) - - req.Name = name - if err = pp.Call("VolumeDriver.Get", req, &ret); err != nil { - return - } - - volume = ret.Volume - - if ret.Err != "" { - err = errors.New(ret.Err) - } - - return -} - -type volumeDriverProxyCapabilitiesRequest struct { -} - -type volumeDriverProxyCapabilitiesResponse struct { - Capabilities volume.Capability - Err string -} - -func (pp *volumeDriverProxy) Capabilities() (capabilities volume.Capability, err error) { - var ( - req volumeDriverProxyCapabilitiesRequest - ret volumeDriverProxyCapabilitiesResponse - ) - - if err = pp.Call("VolumeDriver.Capabilities", req, &ret); err != nil { - return - } - - capabilities = ret.Capabilities - - if ret.Err != "" { - err = errors.New(ret.Err) - } - - return -} diff --git a/vendor/github.com/docker/docker/volume/drivers/proxy_test.go b/vendor/github.com/docker/docker/volume/drivers/proxy_test.go deleted file mode 100644 index b78c46a..0000000 --- a/vendor/github.com/docker/docker/volume/drivers/proxy_test.go +++ /dev/null @@ -1,132 +0,0 @@ -package volumedrivers - -import ( - "fmt" - "net/http" - "net/http/httptest" - "net/url" - "strings" - "testing" - - "github.com/docker/docker/pkg/plugins" - "github.com/docker/go-connections/tlsconfig" -) - -func TestVolumeRequestError(t *testing.T) { - mux := http.NewServeMux() - server := httptest.NewServer(mux) - defer server.Close() - - mux.HandleFunc("/VolumeDriver.Create", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintln(w, `{"Err": "Cannot create volume"}`) - }) - - mux.HandleFunc("/VolumeDriver.Remove", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintln(w, `{"Err": "Cannot remove volume"}`) - }) - - mux.HandleFunc("/VolumeDriver.Mount", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintln(w, `{"Err": "Cannot mount volume"}`) - }) - - mux.HandleFunc("/VolumeDriver.Unmount", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintln(w, `{"Err": "Cannot unmount volume"}`) - }) - - mux.HandleFunc("/VolumeDriver.Path", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintln(w, `{"Err": "Unknown volume"}`) - }) - - mux.HandleFunc("/VolumeDriver.List", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintln(w, `{"Err": "Cannot list volumes"}`) - }) - - mux.HandleFunc("/VolumeDriver.Get", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - fmt.Fprintln(w, `{"Err": "Cannot get volume"}`) - }) - - mux.HandleFunc("/VolumeDriver.Capabilities", func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1+json") - http.Error(w, "error", 500) - }) - - u, _ := url.Parse(server.URL) - client, err := plugins.NewClient("tcp://"+u.Host, &tlsconfig.Options{InsecureSkipVerify: true}) - if err != nil { - t.Fatal(err) - } - - driver := volumeDriverProxy{client} - - if err = driver.Create("volume", nil); err == nil { - t.Fatal("Expected error, was nil") - } - - if !strings.Contains(err.Error(), "Cannot create volume") { - t.Fatalf("Unexpected error: %v\n", err) - } - - _, err = driver.Mount("volume", "123") - if err == nil { - t.Fatal("Expected error, was nil") - } - - if !strings.Contains(err.Error(), "Cannot mount volume") { - t.Fatalf("Unexpected error: %v\n", err) - } - - err = driver.Unmount("volume", "123") - if err == nil { - t.Fatal("Expected error, was nil") - } - - if !strings.Contains(err.Error(), "Cannot unmount volume") { - t.Fatalf("Unexpected error: %v\n", err) - } - - err = driver.Remove("volume") - if err == nil { - t.Fatal("Expected error, was nil") - } - - if !strings.Contains(err.Error(), "Cannot remove volume") { - t.Fatalf("Unexpected error: %v\n", err) - } - - _, err = driver.Path("volume") - if err == nil { - t.Fatal("Expected error, was nil") - } - - if !strings.Contains(err.Error(), "Unknown volume") { - t.Fatalf("Unexpected error: %v\n", err) - } - - _, err = driver.List() - if err == nil { - t.Fatal("Expected error, was nil") - } - if !strings.Contains(err.Error(), "Cannot list volumes") { - t.Fatalf("Unexpected error: %v\n", err) - } - - _, err = driver.Get("volume") - if err == nil { - t.Fatal("Expected error, was nil") - } - if !strings.Contains(err.Error(), "Cannot get volume") { - t.Fatalf("Unexpected error: %v\n", err) - } - - _, err = driver.Capabilities() - if err == nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/volume/local/local.go b/vendor/github.com/docker/docker/volume/local/local.go deleted file mode 100644 index 62c45e6..0000000 --- a/vendor/github.com/docker/docker/volume/local/local.go +++ /dev/null @@ -1,364 +0,0 @@ -// Package local provides the default implementation for volumes. It -// is used to mount data volume containers and directories local to -// the host server. -package local - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "reflect" - "strings" - "sync" - - "github.com/pkg/errors" - - "github.com/Sirupsen/logrus" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/mount" - "github.com/docker/docker/utils" - "github.com/docker/docker/volume" -) - -// VolumeDataPathName is the name of the directory where the volume data is stored. -// It uses a very distinctive name to avoid collisions migrating data between -// Docker versions. -const ( - VolumeDataPathName = "_data" - volumesPathName = "volumes" -) - -var ( - // ErrNotFound is the typed error returned when the requested volume name can't be found - ErrNotFound = fmt.Errorf("volume not found") - // volumeNameRegex ensures the name assigned for the volume is valid. - // This name is used to create the bind directory, so we need to avoid characters that - // would make the path to escape the root directory. - volumeNameRegex = utils.RestrictedNamePattern -) - -type validationError struct { - error -} - -func (validationError) IsValidationError() bool { - return true -} - -type activeMount struct { - count uint64 - mounted bool -} - -// New instantiates a new Root instance with the provided scope. Scope -// is the base path that the Root instance uses to store its -// volumes. The base path is created here if it does not exist. -func New(scope string, rootUID, rootGID int) (*Root, error) { - rootDirectory := filepath.Join(scope, volumesPathName) - - if err := idtools.MkdirAllAs(rootDirectory, 0700, rootUID, rootGID); err != nil { - return nil, err - } - - r := &Root{ - scope: scope, - path: rootDirectory, - volumes: make(map[string]*localVolume), - rootUID: rootUID, - rootGID: rootGID, - } - - dirs, err := ioutil.ReadDir(rootDirectory) - if err != nil { - return nil, err - } - - mountInfos, err := mount.GetMounts() - if err != nil { - logrus.Debugf("error looking up mounts for local volume cleanup: %v", err) - } - - for _, d := range dirs { - if !d.IsDir() { - continue - } - - name := filepath.Base(d.Name()) - v := &localVolume{ - driverName: r.Name(), - name: name, - path: r.DataPath(name), - } - r.volumes[name] = v - optsFilePath := filepath.Join(rootDirectory, name, "opts.json") - if b, err := ioutil.ReadFile(optsFilePath); err == nil { - opts := optsConfig{} - if err := json.Unmarshal(b, &opts); err != nil { - return nil, errors.Wrapf(err, "error while unmarshaling volume options for volume: %s", name) - } - // Make sure this isn't an empty optsConfig. - // This could be empty due to buggy behavior in older versions of Docker. - if !reflect.DeepEqual(opts, optsConfig{}) { - v.opts = &opts - } - - // unmount anything that may still be mounted (for example, from an unclean shutdown) - for _, info := range mountInfos { - if info.Mountpoint == v.path { - mount.Unmount(v.path) - break - } - } - } - } - - return r, nil -} - -// Root implements the Driver interface for the volume package and -// manages the creation/removal of volumes. It uses only standard vfs -// commands to create/remove dirs within its provided scope. -type Root struct { - m sync.Mutex - scope string - path string - volumes map[string]*localVolume - rootUID int - rootGID int -} - -// List lists all the volumes -func (r *Root) List() ([]volume.Volume, error) { - var ls []volume.Volume - r.m.Lock() - for _, v := range r.volumes { - ls = append(ls, v) - } - r.m.Unlock() - return ls, nil -} - -// DataPath returns the constructed path of this volume. -func (r *Root) DataPath(volumeName string) string { - return filepath.Join(r.path, volumeName, VolumeDataPathName) -} - -// Name returns the name of Root, defined in the volume package in the DefaultDriverName constant. -func (r *Root) Name() string { - return volume.DefaultDriverName -} - -// Create creates a new volume.Volume with the provided name, creating -// the underlying directory tree required for this volume in the -// process. -func (r *Root) Create(name string, opts map[string]string) (volume.Volume, error) { - if err := r.validateName(name); err != nil { - return nil, err - } - - r.m.Lock() - defer r.m.Unlock() - - v, exists := r.volumes[name] - if exists { - return v, nil - } - - path := r.DataPath(name) - if err := idtools.MkdirAllAs(path, 0755, r.rootUID, r.rootGID); err != nil { - if os.IsExist(err) { - return nil, fmt.Errorf("volume already exists under %s", filepath.Dir(path)) - } - return nil, errors.Wrapf(err, "error while creating volume path '%s'", path) - } - - var err error - defer func() { - if err != nil { - os.RemoveAll(filepath.Dir(path)) - } - }() - - v = &localVolume{ - driverName: r.Name(), - name: name, - path: path, - } - - if len(opts) != 0 { - if err = setOpts(v, opts); err != nil { - return nil, err - } - var b []byte - b, err = json.Marshal(v.opts) - if err != nil { - return nil, err - } - if err = ioutil.WriteFile(filepath.Join(filepath.Dir(path), "opts.json"), b, 600); err != nil { - return nil, errors.Wrap(err, "error while persisting volume options") - } - } - - r.volumes[name] = v - return v, nil -} - -// Remove removes the specified volume and all underlying data. If the -// given volume does not belong to this driver and an error is -// returned. The volume is reference counted, if all references are -// not released then the volume is not removed. -func (r *Root) Remove(v volume.Volume) error { - r.m.Lock() - defer r.m.Unlock() - - lv, ok := v.(*localVolume) - if !ok { - return fmt.Errorf("unknown volume type %T", v) - } - - realPath, err := filepath.EvalSymlinks(lv.path) - if err != nil { - if !os.IsNotExist(err) { - return err - } - realPath = filepath.Dir(lv.path) - } - - if !r.scopedPath(realPath) { - return fmt.Errorf("Unable to remove a directory of out the Docker root %s: %s", r.scope, realPath) - } - - if err := removePath(realPath); err != nil { - return err - } - - delete(r.volumes, lv.name) - return removePath(filepath.Dir(lv.path)) -} - -func removePath(path string) error { - if err := os.RemoveAll(path); err != nil { - if os.IsNotExist(err) { - return nil - } - return errors.Wrapf(err, "error removing volume path '%s'", path) - } - return nil -} - -// Get looks up the volume for the given name and returns it if found -func (r *Root) Get(name string) (volume.Volume, error) { - r.m.Lock() - v, exists := r.volumes[name] - r.m.Unlock() - if !exists { - return nil, ErrNotFound - } - return v, nil -} - -// Scope returns the local volume scope -func (r *Root) Scope() string { - return volume.LocalScope -} - -func (r *Root) validateName(name string) error { - if len(name) == 1 { - return validationError{fmt.Errorf("volume name is too short, names should be at least two alphanumeric characters")} - } - if !volumeNameRegex.MatchString(name) { - return validationError{fmt.Errorf("%q includes invalid characters for a local volume name, only %q are allowed. If you intented to pass a host directory, use absolute path", name, utils.RestrictedNameChars)} - } - return nil -} - -// localVolume implements the Volume interface from the volume package and -// represents the volumes created by Root. -type localVolume struct { - m sync.Mutex - // unique name of the volume - name string - // path is the path on the host where the data lives - path string - // driverName is the name of the driver that created the volume. - driverName string - // opts is the parsed list of options used to create the volume - opts *optsConfig - // active refcounts the active mounts - active activeMount -} - -// Name returns the name of the given Volume. -func (v *localVolume) Name() string { - return v.name -} - -// DriverName returns the driver that created the given Volume. -func (v *localVolume) DriverName() string { - return v.driverName -} - -// Path returns the data location. -func (v *localVolume) Path() string { - return v.path -} - -// Mount implements the localVolume interface, returning the data location. -func (v *localVolume) Mount(id string) (string, error) { - v.m.Lock() - defer v.m.Unlock() - if v.opts != nil { - if !v.active.mounted { - if err := v.mount(); err != nil { - return "", err - } - v.active.mounted = true - } - v.active.count++ - } - return v.path, nil -} - -// Umount is for satisfying the localVolume interface and does not do anything in this driver. -func (v *localVolume) Unmount(id string) error { - v.m.Lock() - defer v.m.Unlock() - if v.opts != nil { - v.active.count-- - if v.active.count == 0 { - if err := mount.Unmount(v.path); err != nil { - v.active.count++ - return errors.Wrapf(err, "error while unmounting volume path '%s'", v.path) - } - v.active.mounted = false - } - } - return nil -} - -func validateOpts(opts map[string]string) error { - for opt := range opts { - if !validOpts[opt] { - return validationError{fmt.Errorf("invalid option key: %q", opt)} - } - } - return nil -} - -func (v *localVolume) Status() map[string]interface{} { - return nil -} - -// getAddress finds out address/hostname from options -func getAddress(opts string) string { - optsList := strings.Split(opts, ",") - for i := 0; i < len(optsList); i++ { - if strings.HasPrefix(optsList[i], "addr=") { - addr := (strings.SplitN(optsList[i], "=", 2)[1]) - return addr - } - } - return "" -} diff --git a/vendor/github.com/docker/docker/volume/local/local_test.go b/vendor/github.com/docker/docker/volume/local/local_test.go deleted file mode 100644 index f5a519b..0000000 --- a/vendor/github.com/docker/docker/volume/local/local_test.go +++ /dev/null @@ -1,344 +0,0 @@ -package local - -import ( - "io/ioutil" - "os" - "path/filepath" - "reflect" - "runtime" - "strings" - "testing" - - "github.com/docker/docker/pkg/mount" -) - -func TestGetAddress(t *testing.T) { - cases := map[string]string{ - "addr=11.11.11.1": "11.11.11.1", - " ": "", - "addr=": "", - "addr=2001:db8::68": "2001:db8::68", - } - for name, success := range cases { - v := getAddress(name) - if v != success { - t.Errorf("Test case failed for %s actual: %s expected : %s", name, v, success) - } - } - -} - -func TestRemove(t *testing.T) { - // TODO Windows: Investigate why this test fails on Windows under CI - // but passes locally. - if runtime.GOOS == "windows" { - t.Skip("Test failing on Windows CI") - } - rootDir, err := ioutil.TempDir("", "local-volume-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(rootDir) - - r, err := New(rootDir, 0, 0) - if err != nil { - t.Fatal(err) - } - - vol, err := r.Create("testing", nil) - if err != nil { - t.Fatal(err) - } - - if err := r.Remove(vol); err != nil { - t.Fatal(err) - } - - vol, err = r.Create("testing2", nil) - if err != nil { - t.Fatal(err) - } - if err := os.RemoveAll(vol.Path()); err != nil { - t.Fatal(err) - } - - if err := r.Remove(vol); err != nil { - t.Fatal(err) - } - - if _, err := os.Stat(vol.Path()); err != nil && !os.IsNotExist(err) { - t.Fatal("volume dir not removed") - } - - if l, _ := r.List(); len(l) != 0 { - t.Fatal("expected there to be no volumes") - } -} - -func TestInitializeWithVolumes(t *testing.T) { - rootDir, err := ioutil.TempDir("", "local-volume-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(rootDir) - - r, err := New(rootDir, 0, 0) - if err != nil { - t.Fatal(err) - } - - vol, err := r.Create("testing", nil) - if err != nil { - t.Fatal(err) - } - - r, err = New(rootDir, 0, 0) - if err != nil { - t.Fatal(err) - } - - v, err := r.Get(vol.Name()) - if err != nil { - t.Fatal(err) - } - - if v.Path() != vol.Path() { - t.Fatal("expected to re-initialize root with existing volumes") - } -} - -func TestCreate(t *testing.T) { - rootDir, err := ioutil.TempDir("", "local-volume-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(rootDir) - - r, err := New(rootDir, 0, 0) - if err != nil { - t.Fatal(err) - } - - cases := map[string]bool{ - "name": true, - "name-with-dash": true, - "name_with_underscore": true, - "name/with/slash": false, - "name/with/../../slash": false, - "./name": false, - "../name": false, - "./": false, - "../": false, - "~": false, - ".": false, - "..": false, - "...": false, - } - - for name, success := range cases { - v, err := r.Create(name, nil) - if success { - if err != nil { - t.Fatal(err) - } - if v.Name() != name { - t.Fatalf("Expected volume with name %s, got %s", name, v.Name()) - } - } else { - if err == nil { - t.Fatalf("Expected error creating volume with name %s, got nil", name) - } - } - } - - r, err = New(rootDir, 0, 0) - if err != nil { - t.Fatal(err) - } -} - -func TestValidateName(t *testing.T) { - r := &Root{} - names := map[string]bool{ - "x": false, - "/testvol": false, - "thing.d": true, - "hello-world": true, - "./hello": false, - ".hello": false, - } - - for vol, expected := range names { - err := r.validateName(vol) - if expected && err != nil { - t.Fatalf("expected %s to be valid got %v", vol, err) - } - if !expected && err == nil { - t.Fatalf("expected %s to be invalid", vol) - } - } -} - -func TestCreateWithOpts(t *testing.T) { - if runtime.GOOS == "windows" || runtime.GOOS == "solaris" { - t.Skip() - } - rootDir, err := ioutil.TempDir("", "local-volume-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(rootDir) - - r, err := New(rootDir, 0, 0) - if err != nil { - t.Fatal(err) - } - - if _, err := r.Create("test", map[string]string{"invalidopt": "notsupported"}); err == nil { - t.Fatal("expected invalid opt to cause error") - } - - vol, err := r.Create("test", map[string]string{"device": "tmpfs", "type": "tmpfs", "o": "size=1m,uid=1000"}) - if err != nil { - t.Fatal(err) - } - v := vol.(*localVolume) - - dir, err := v.Mount("1234") - if err != nil { - t.Fatal(err) - } - defer func() { - if err := v.Unmount("1234"); err != nil { - t.Fatal(err) - } - }() - - mountInfos, err := mount.GetMounts() - if err != nil { - t.Fatal(err) - } - - var found bool - for _, info := range mountInfos { - if info.Mountpoint == dir { - found = true - if info.Fstype != "tmpfs" { - t.Fatalf("expected tmpfs mount, got %q", info.Fstype) - } - if info.Source != "tmpfs" { - t.Fatalf("expected tmpfs mount, got %q", info.Source) - } - if !strings.Contains(info.VfsOpts, "uid=1000") { - t.Fatalf("expected mount info to have uid=1000: %q", info.VfsOpts) - } - if !strings.Contains(info.VfsOpts, "size=1024k") { - t.Fatalf("expected mount info to have size=1024k: %q", info.VfsOpts) - } - break - } - } - - if !found { - t.Fatal("mount not found") - } - - if v.active.count != 1 { - t.Fatalf("Expected active mount count to be 1, got %d", v.active.count) - } - - // test double mount - if _, err := v.Mount("1234"); err != nil { - t.Fatal(err) - } - if v.active.count != 2 { - t.Fatalf("Expected active mount count to be 2, got %d", v.active.count) - } - - if err := v.Unmount("1234"); err != nil { - t.Fatal(err) - } - if v.active.count != 1 { - t.Fatalf("Expected active mount count to be 1, got %d", v.active.count) - } - - mounted, err := mount.Mounted(v.path) - if err != nil { - t.Fatal(err) - } - if !mounted { - t.Fatal("expected mount to still be active") - } - - r, err = New(rootDir, 0, 0) - if err != nil { - t.Fatal(err) - } - - v2, exists := r.volumes["test"] - if !exists { - t.Fatal("missing volume on restart") - } - - if !reflect.DeepEqual(v.opts, v2.opts) { - t.Fatal("missing volume options on restart") - } -} - -func TestRealodNoOpts(t *testing.T) { - rootDir, err := ioutil.TempDir("", "volume-test-reload-no-opts") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(rootDir) - - r, err := New(rootDir, 0, 0) - if err != nil { - t.Fatal(err) - } - - if _, err := r.Create("test1", nil); err != nil { - t.Fatal(err) - } - if _, err := r.Create("test2", nil); err != nil { - t.Fatal(err) - } - // make sure a file with `null` (.e.g. empty opts map from older daemon) is ok - if err := ioutil.WriteFile(filepath.Join(rootDir, "test2"), []byte("null"), 600); err != nil { - t.Fatal(err) - } - - if _, err := r.Create("test3", nil); err != nil { - t.Fatal(err) - } - // make sure an empty opts file doesn't break us too - if err := ioutil.WriteFile(filepath.Join(rootDir, "test3"), nil, 600); err != nil { - t.Fatal(err) - } - - if _, err := r.Create("test4", map[string]string{}); err != nil { - t.Fatal(err) - } - - r, err = New(rootDir, 0, 0) - if err != nil { - t.Fatal(err) - } - - for _, name := range []string{"test1", "test2", "test3", "test4"} { - v, err := r.Get(name) - if err != nil { - t.Fatal(err) - } - lv, ok := v.(*localVolume) - if !ok { - t.Fatalf("expected *localVolume got: %v", reflect.TypeOf(v)) - } - if lv.opts != nil { - t.Fatalf("expected opts to be nil, got: %v", lv.opts) - } - if _, err := lv.Mount("1234"); err != nil { - t.Fatal(err) - } - } -} diff --git a/vendor/github.com/docker/docker/volume/local/local_unix.go b/vendor/github.com/docker/docker/volume/local/local_unix.go deleted file mode 100644 index fb08862..0000000 --- a/vendor/github.com/docker/docker/volume/local/local_unix.go +++ /dev/null @@ -1,87 +0,0 @@ -// +build linux freebsd solaris - -// Package local provides the default implementation for volumes. It -// is used to mount data volume containers and directories local to -// the host server. -package local - -import ( - "fmt" - "net" - "path/filepath" - "strings" - - "github.com/pkg/errors" - - "github.com/docker/docker/pkg/mount" -) - -var ( - oldVfsDir = filepath.Join("vfs", "dir") - - validOpts = map[string]bool{ - "type": true, // specify the filesystem type for mount, e.g. nfs - "o": true, // generic mount options - "device": true, // device to mount from - } -) - -type optsConfig struct { - MountType string - MountOpts string - MountDevice string -} - -func (o *optsConfig) String() string { - return fmt.Sprintf("type='%s' device='%s' o='%s'", o.MountType, o.MountDevice, o.MountOpts) -} - -// scopedPath verifies that the path where the volume is located -// is under Docker's root and the valid local paths. -func (r *Root) scopedPath(realPath string) bool { - // Volumes path for Docker version >= 1.7 - if strings.HasPrefix(realPath, filepath.Join(r.scope, volumesPathName)) && realPath != filepath.Join(r.scope, volumesPathName) { - return true - } - - // Volumes path for Docker version < 1.7 - if strings.HasPrefix(realPath, filepath.Join(r.scope, oldVfsDir)) { - return true - } - - return false -} - -func setOpts(v *localVolume, opts map[string]string) error { - if len(opts) == 0 { - return nil - } - if err := validateOpts(opts); err != nil { - return err - } - - v.opts = &optsConfig{ - MountType: opts["type"], - MountOpts: opts["o"], - MountDevice: opts["device"], - } - return nil -} - -func (v *localVolume) mount() error { - if v.opts.MountDevice == "" { - return fmt.Errorf("missing device in volume options") - } - mountOpts := v.opts.MountOpts - if v.opts.MountType == "nfs" { - if addrValue := getAddress(v.opts.MountOpts); addrValue != "" && net.ParseIP(addrValue).To4() == nil { - ipAddr, err := net.ResolveIPAddr("ip", addrValue) - if err != nil { - return errors.Wrapf(err, "error resolving passed in nfs address") - } - mountOpts = strings.Replace(mountOpts, "addr="+addrValue, "addr="+ipAddr.String(), 1) - } - } - err := mount.Mount(v.opts.MountDevice, v.path, v.opts.MountType, mountOpts) - return errors.Wrapf(err, "error while mounting volume with options: %s", v.opts) -} diff --git a/vendor/github.com/docker/docker/volume/local/local_windows.go b/vendor/github.com/docker/docker/volume/local/local_windows.go deleted file mode 100644 index 1bdb368..0000000 --- a/vendor/github.com/docker/docker/volume/local/local_windows.go +++ /dev/null @@ -1,34 +0,0 @@ -// Package local provides the default implementation for volumes. It -// is used to mount data volume containers and directories local to -// the host server. -package local - -import ( - "fmt" - "path/filepath" - "strings" -) - -type optsConfig struct{} - -var validOpts map[string]bool - -// scopedPath verifies that the path where the volume is located -// is under Docker's root and the valid local paths. -func (r *Root) scopedPath(realPath string) bool { - if strings.HasPrefix(realPath, filepath.Join(r.scope, volumesPathName)) && realPath != filepath.Join(r.scope, volumesPathName) { - return true - } - return false -} - -func setOpts(v *localVolume, opts map[string]string) error { - if len(opts) > 0 { - return fmt.Errorf("options are not supported on this platform") - } - return nil -} - -func (v *localVolume) mount() error { - return nil -} diff --git a/vendor/github.com/docker/docker/volume/store/db.go b/vendor/github.com/docker/docker/volume/store/db.go deleted file mode 100644 index c5fd164..0000000 --- a/vendor/github.com/docker/docker/volume/store/db.go +++ /dev/null @@ -1,88 +0,0 @@ -package store - -import ( - "encoding/json" - - "github.com/Sirupsen/logrus" - "github.com/boltdb/bolt" - "github.com/pkg/errors" -) - -var volumeBucketName = []byte("volumes") - -type volumeMetadata struct { - Name string - Driver string - Labels map[string]string - Options map[string]string -} - -func (s *VolumeStore) setMeta(name string, meta volumeMetadata) error { - return s.db.Update(func(tx *bolt.Tx) error { - return setMeta(tx, name, meta) - }) -} - -func setMeta(tx *bolt.Tx, name string, meta volumeMetadata) error { - metaJSON, err := json.Marshal(meta) - if err != nil { - return err - } - b := tx.Bucket(volumeBucketName) - return errors.Wrap(b.Put([]byte(name), metaJSON), "error setting volume metadata") -} - -func (s *VolumeStore) getMeta(name string) (volumeMetadata, error) { - var meta volumeMetadata - err := s.db.View(func(tx *bolt.Tx) error { - return getMeta(tx, name, &meta) - }) - return meta, err -} - -func getMeta(tx *bolt.Tx, name string, meta *volumeMetadata) error { - b := tx.Bucket(volumeBucketName) - val := b.Get([]byte(name)) - if string(val) == "" { - return nil - } - if err := json.Unmarshal(val, meta); err != nil { - return errors.Wrap(err, "error unmarshaling volume metadata") - } - return nil -} - -func (s *VolumeStore) removeMeta(name string) error { - return s.db.Update(func(tx *bolt.Tx) error { - return removeMeta(tx, name) - }) -} - -func removeMeta(tx *bolt.Tx, name string) error { - b := tx.Bucket(volumeBucketName) - return errors.Wrap(b.Delete([]byte(name)), "error removing volume metadata") -} - -// listMeta is used during restore to get the list of volume metadata -// from the on-disk database. -// Any errors that occur are only logged. -func listMeta(tx *bolt.Tx) []volumeMetadata { - var ls []volumeMetadata - b := tx.Bucket(volumeBucketName) - b.ForEach(func(k, v []byte) error { - if len(v) == 0 { - // don't try to unmarshal an empty value - return nil - } - - var m volumeMetadata - if err := json.Unmarshal(v, &m); err != nil { - // Just log the error - logrus.Errorf("Error while reading volume metadata for volume %q: %v", string(k), err) - return nil - } - ls = append(ls, m) - return nil - }) - return ls -} diff --git a/vendor/github.com/docker/docker/volume/store/errors.go b/vendor/github.com/docker/docker/volume/store/errors.go deleted file mode 100644 index 980175f..0000000 --- a/vendor/github.com/docker/docker/volume/store/errors.go +++ /dev/null @@ -1,76 +0,0 @@ -package store - -import ( - "strings" - - "github.com/pkg/errors" -) - -var ( - // errVolumeInUse is a typed error returned when trying to remove a volume that is currently in use by a container - errVolumeInUse = errors.New("volume is in use") - // errNoSuchVolume is a typed error returned if the requested volume doesn't exist in the volume store - errNoSuchVolume = errors.New("no such volume") - // errInvalidName is a typed error returned when creating a volume with a name that is not valid on the platform - errInvalidName = errors.New("volume name is not valid on this platform") - // errNameConflict is a typed error returned on create when a volume exists with the given name, but for a different driver - errNameConflict = errors.New("volume name must be unique") -) - -// OpErr is the error type returned by functions in the store package. It describes -// the operation, volume name, and error. -type OpErr struct { - // Err is the error that occurred during the operation. - Err error - // Op is the operation which caused the error, such as "create", or "list". - Op string - // Name is the name of the resource being requested for this op, typically the volume name or the driver name. - Name string - // Refs is the list of references associated with the resource. - Refs []string -} - -// Error satisfies the built-in error interface type. -func (e *OpErr) Error() string { - if e == nil { - return "" - } - s := e.Op - if e.Name != "" { - s = s + " " + e.Name - } - - s = s + ": " + e.Err.Error() - if len(e.Refs) > 0 { - s = s + " - " + "[" + strings.Join(e.Refs, ", ") + "]" - } - return s -} - -// IsInUse returns a boolean indicating whether the error indicates that a -// volume is in use -func IsInUse(err error) bool { - return isErr(err, errVolumeInUse) -} - -// IsNotExist returns a boolean indicating whether the error indicates that the volume does not exist -func IsNotExist(err error) bool { - return isErr(err, errNoSuchVolume) -} - -// IsNameConflict returns a boolean indicating whether the error indicates that a -// volume name is already taken -func IsNameConflict(err error) bool { - return isErr(err, errNameConflict) -} - -func isErr(err error, expected error) bool { - err = errors.Cause(err) - switch pe := err.(type) { - case nil: - return false - case *OpErr: - err = errors.Cause(pe.Err) - } - return err == expected -} diff --git a/vendor/github.com/docker/docker/volume/store/restore.go b/vendor/github.com/docker/docker/volume/store/restore.go deleted file mode 100644 index c0c5b51..0000000 --- a/vendor/github.com/docker/docker/volume/store/restore.go +++ /dev/null @@ -1,83 +0,0 @@ -package store - -import ( - "sync" - - "github.com/Sirupsen/logrus" - "github.com/boltdb/bolt" - "github.com/docker/docker/volume" - "github.com/docker/docker/volume/drivers" -) - -// restore is called when a new volume store is created. -// It's primary purpose is to ensure that all drivers' refcounts are set based -// on known volumes after a restart. -// This only attempts to track volumes that are actually stored in the on-disk db. -// It does not probe the available drivers to find anything that may have been added -// out of band. -func (s *VolumeStore) restore() { - var ls []volumeMetadata - s.db.View(func(tx *bolt.Tx) error { - ls = listMeta(tx) - return nil - }) - - chRemove := make(chan *volumeMetadata, len(ls)) - var wg sync.WaitGroup - for _, meta := range ls { - wg.Add(1) - // this is potentially a very slow operation, so do it in a goroutine - go func(meta volumeMetadata) { - defer wg.Done() - - var v volume.Volume - var err error - if meta.Driver != "" { - v, err = lookupVolume(meta.Driver, meta.Name) - if err != nil && err != errNoSuchVolume { - logrus.WithError(err).WithField("driver", meta.Driver).WithField("volume", meta.Name).Warn("Error restoring volume") - return - } - if v == nil { - // doesn't exist in the driver, remove it from the db - chRemove <- &meta - return - } - } else { - v, err = s.getVolume(meta.Name) - if err != nil { - if err == errNoSuchVolume { - chRemove <- &meta - } - return - } - - meta.Driver = v.DriverName() - if err := s.setMeta(v.Name(), meta); err != nil { - logrus.WithError(err).WithField("driver", meta.Driver).WithField("volume", v.Name()).Warn("Error updating volume metadata on restore") - } - } - - // increment driver refcount - volumedrivers.CreateDriver(meta.Driver) - - // cache the volume - s.globalLock.Lock() - s.options[v.Name()] = meta.Options - s.labels[v.Name()] = meta.Labels - s.names[v.Name()] = v - s.globalLock.Unlock() - }(meta) - } - - wg.Wait() - close(chRemove) - s.db.Update(func(tx *bolt.Tx) error { - for meta := range chRemove { - if err := removeMeta(tx, meta.Name); err != nil { - logrus.WithField("volume", meta.Name).Warnf("Error removing stale entry from volume db: %v", err) - } - } - return nil - }) -} diff --git a/vendor/github.com/docker/docker/volume/store/store.go b/vendor/github.com/docker/docker/volume/store/store.go deleted file mode 100644 index 38afd86..0000000 --- a/vendor/github.com/docker/docker/volume/store/store.go +++ /dev/null @@ -1,649 +0,0 @@ -package store - -import ( - "net" - "os" - "path/filepath" - "sync" - "time" - - "github.com/pkg/errors" - - "github.com/Sirupsen/logrus" - "github.com/boltdb/bolt" - "github.com/docker/docker/pkg/locker" - "github.com/docker/docker/volume" - "github.com/docker/docker/volume/drivers" -) - -const ( - volumeDataDir = "volumes" -) - -type volumeWrapper struct { - volume.Volume - labels map[string]string - scope string - options map[string]string -} - -func (v volumeWrapper) Options() map[string]string { - options := map[string]string{} - for key, value := range v.options { - options[key] = value - } - return options -} - -func (v volumeWrapper) Labels() map[string]string { - return v.labels -} - -func (v volumeWrapper) Scope() string { - return v.scope -} - -func (v volumeWrapper) CachedPath() string { - if vv, ok := v.Volume.(interface { - CachedPath() string - }); ok { - return vv.CachedPath() - } - return v.Volume.Path() -} - -// New initializes a VolumeStore to keep -// reference counting of volumes in the system. -func New(rootPath string) (*VolumeStore, error) { - vs := &VolumeStore{ - locks: &locker.Locker{}, - names: make(map[string]volume.Volume), - refs: make(map[string][]string), - labels: make(map[string]map[string]string), - options: make(map[string]map[string]string), - } - - if rootPath != "" { - // initialize metadata store - volPath := filepath.Join(rootPath, volumeDataDir) - if err := os.MkdirAll(volPath, 750); err != nil { - return nil, err - } - - dbPath := filepath.Join(volPath, "metadata.db") - - var err error - vs.db, err = bolt.Open(dbPath, 0600, &bolt.Options{Timeout: 1 * time.Second}) - if err != nil { - return nil, errors.Wrap(err, "error while opening volume store metadata database") - } - - // initialize volumes bucket - if err := vs.db.Update(func(tx *bolt.Tx) error { - if _, err := tx.CreateBucketIfNotExists(volumeBucketName); err != nil { - return errors.Wrap(err, "error while setting up volume store metadata database") - } - return nil - }); err != nil { - return nil, err - } - } - - vs.restore() - - return vs, nil -} - -func (s *VolumeStore) getNamed(name string) (volume.Volume, bool) { - s.globalLock.RLock() - v, exists := s.names[name] - s.globalLock.RUnlock() - return v, exists -} - -func (s *VolumeStore) setNamed(v volume.Volume, ref string) { - s.globalLock.Lock() - s.names[v.Name()] = v - if len(ref) > 0 { - s.refs[v.Name()] = append(s.refs[v.Name()], ref) - } - s.globalLock.Unlock() -} - -// getRefs gets the list of refs for a given name -// Callers of this function are expected to hold the name lock. -func (s *VolumeStore) getRefs(name string) []string { - s.globalLock.RLock() - refs := s.refs[name] - s.globalLock.RUnlock() - return refs -} - -// Purge allows the cleanup of internal data on docker in case -// the internal data is out of sync with volumes driver plugins. -func (s *VolumeStore) Purge(name string) { - s.globalLock.Lock() - v, exists := s.names[name] - if exists { - if _, err := volumedrivers.RemoveDriver(v.DriverName()); err != nil { - logrus.Error("Error dereferencing volume driver: %v", err) - } - } - if err := s.removeMeta(name); err != nil { - logrus.Errorf("Error removing volume metadata for volume %q: %v", name, err) - } - delete(s.names, name) - delete(s.refs, name) - delete(s.labels, name) - delete(s.options, name) - s.globalLock.Unlock() -} - -// VolumeStore is a struct that stores the list of volumes available and keeps track of their usage counts -type VolumeStore struct { - // locks ensures that only one action is being performed on a particular volume at a time without locking the entire store - // since actions on volumes can be quite slow, this ensures the store is free to handle requests for other volumes. - locks *locker.Locker - // globalLock is used to protect access to mutable structures used by the store object - globalLock sync.RWMutex - // names stores the volume name -> volume relationship. - // This is used for making lookups faster so we don't have to probe all drivers - names map[string]volume.Volume - // refs stores the volume name and the list of things referencing it - refs map[string][]string - // labels stores volume labels for each volume - labels map[string]map[string]string - // options stores volume options for each volume - options map[string]map[string]string - db *bolt.DB -} - -// List proxies to all registered volume drivers to get the full list of volumes -// If a driver returns a volume that has name which conflicts with another volume from a different driver, -// the first volume is chosen and the conflicting volume is dropped. -func (s *VolumeStore) List() ([]volume.Volume, []string, error) { - vols, warnings, err := s.list() - if err != nil { - return nil, nil, &OpErr{Err: err, Op: "list"} - } - var out []volume.Volume - - for _, v := range vols { - name := normaliseVolumeName(v.Name()) - - s.locks.Lock(name) - storedV, exists := s.getNamed(name) - // Note: it's not safe to populate the cache here because the volume may have been - // deleted before we acquire a lock on its name - if exists && storedV.DriverName() != v.DriverName() { - logrus.Warnf("Volume name %s already exists for driver %s, not including volume returned by %s", v.Name(), storedV.DriverName(), v.DriverName()) - s.locks.Unlock(v.Name()) - continue - } - - out = append(out, v) - s.locks.Unlock(v.Name()) - } - return out, warnings, nil -} - -// list goes through each volume driver and asks for its list of volumes. -func (s *VolumeStore) list() ([]volume.Volume, []string, error) { - var ( - ls []volume.Volume - warnings []string - ) - - drivers, err := volumedrivers.GetAllDrivers() - if err != nil { - return nil, nil, err - } - - type vols struct { - vols []volume.Volume - err error - driverName string - } - chVols := make(chan vols, len(drivers)) - - for _, vd := range drivers { - go func(d volume.Driver) { - vs, err := d.List() - if err != nil { - chVols <- vols{driverName: d.Name(), err: &OpErr{Err: err, Name: d.Name(), Op: "list"}} - return - } - for i, v := range vs { - s.globalLock.RLock() - vs[i] = volumeWrapper{v, s.labels[v.Name()], d.Scope(), s.options[v.Name()]} - s.globalLock.RUnlock() - } - - chVols <- vols{vols: vs} - }(vd) - } - - badDrivers := make(map[string]struct{}) - for i := 0; i < len(drivers); i++ { - vs := <-chVols - - if vs.err != nil { - warnings = append(warnings, vs.err.Error()) - badDrivers[vs.driverName] = struct{}{} - logrus.Warn(vs.err) - } - ls = append(ls, vs.vols...) - } - - if len(badDrivers) > 0 { - s.globalLock.RLock() - for _, v := range s.names { - if _, exists := badDrivers[v.DriverName()]; exists { - ls = append(ls, v) - } - } - s.globalLock.RUnlock() - } - return ls, warnings, nil -} - -// CreateWithRef creates a volume with the given name and driver and stores the ref -// This ensures there's no race between creating a volume and then storing a reference. -func (s *VolumeStore) CreateWithRef(name, driverName, ref string, opts, labels map[string]string) (volume.Volume, error) { - name = normaliseVolumeName(name) - s.locks.Lock(name) - defer s.locks.Unlock(name) - - v, err := s.create(name, driverName, opts, labels) - if err != nil { - return nil, &OpErr{Err: err, Name: name, Op: "create"} - } - - s.setNamed(v, ref) - return v, nil -} - -// Create creates a volume with the given name and driver. -// This is just like CreateWithRef() except we don't store a reference while holding the lock. -func (s *VolumeStore) Create(name, driverName string, opts, labels map[string]string) (volume.Volume, error) { - return s.CreateWithRef(name, driverName, "", opts, labels) -} - -// checkConflict checks the local cache for name collisions with the passed in name, -// for existing volumes with the same name but in a different driver. -// This is used by `Create` as a best effort to prevent name collisions for volumes. -// If a matching volume is found that is not a conflict that is returned so the caller -// does not need to perform an additional lookup. -// When no matching volume is found, both returns will be nil -// -// Note: This does not probe all the drivers for name collisions because v1 plugins -// are very slow, particularly if the plugin is down, and cause other issues, -// particularly around locking the store. -// TODO(cpuguy83): With v2 plugins this shouldn't be a problem. Could also potentially -// use a connect timeout for this kind of check to ensure we aren't blocking for a -// long time. -func (s *VolumeStore) checkConflict(name, driverName string) (volume.Volume, error) { - // check the local cache - v, _ := s.getNamed(name) - if v == nil { - return nil, nil - } - - vDriverName := v.DriverName() - var conflict bool - if driverName != "" { - // Retrieve canonical driver name to avoid inconsistencies (for example - // "plugin" vs. "plugin:latest") - vd, err := volumedrivers.GetDriver(driverName) - if err != nil { - return nil, err - } - - if vDriverName != vd.Name() { - conflict = true - } - } - - // let's check if the found volume ref - // is stale by checking with the driver if it still exists - exists, err := volumeExists(v) - if err != nil { - return nil, errors.Wrapf(errNameConflict, "found reference to volume '%s' in driver '%s', but got an error while checking the driver: %v", name, vDriverName, err) - } - - if exists { - if conflict { - return nil, errors.Wrapf(errNameConflict, "driver '%s' already has volume '%s'", vDriverName, name) - } - return v, nil - } - - if len(s.getRefs(v.Name())) > 0 { - // Containers are referencing this volume but it doesn't seem to exist anywhere. - // Return a conflict error here, the user can fix this with `docker volume rm -f` - return nil, errors.Wrapf(errNameConflict, "found references to volume '%s' in driver '%s' but the volume was not found in the driver -- you may need to remove containers referencing this volume or force remove the volume to re-create it", name, vDriverName) - } - - // doesn't exist, so purge it from the cache - s.Purge(name) - return nil, nil -} - -// volumeExists returns if the volume is still present in the driver. -// An error is returned if there was an issue communicating with the driver. -func volumeExists(v volume.Volume) (bool, error) { - exists, err := lookupVolume(v.DriverName(), v.Name()) - if err != nil { - return false, err - } - return exists != nil, nil -} - -// create asks the given driver to create a volume with the name/opts. -// If a volume with the name is already known, it will ask the stored driver for the volume. -// If the passed in driver name does not match the driver name which is stored -// for the given volume name, an error is returned after checking if the reference is stale. -// If the reference is stale, it will be purged and this create can continue. -// It is expected that callers of this function hold any necessary locks. -func (s *VolumeStore) create(name, driverName string, opts, labels map[string]string) (volume.Volume, error) { - // Validate the name in a platform-specific manner - valid, err := volume.IsVolumeNameValid(name) - if err != nil { - return nil, err - } - if !valid { - return nil, &OpErr{Err: errInvalidName, Name: name, Op: "create"} - } - - v, err := s.checkConflict(name, driverName) - if err != nil { - return nil, err - } - - if v != nil { - return v, nil - } - - // Since there isn't a specified driver name, let's see if any of the existing drivers have this volume name - if driverName == "" { - v, _ := s.getVolume(name) - if v != nil { - return v, nil - } - } - - vd, err := volumedrivers.CreateDriver(driverName) - - if err != nil { - return nil, &OpErr{Op: "create", Name: name, Err: err} - } - - logrus.Debugf("Registering new volume reference: driver %q, name %q", vd.Name(), name) - - if v, _ := vd.Get(name); v != nil { - return v, nil - } - v, err = vd.Create(name, opts) - if err != nil { - return nil, err - } - s.globalLock.Lock() - s.labels[name] = labels - s.options[name] = opts - s.globalLock.Unlock() - - metadata := volumeMetadata{ - Name: name, - Driver: vd.Name(), - Labels: labels, - Options: opts, - } - - if err := s.setMeta(name, metadata); err != nil { - return nil, err - } - return volumeWrapper{v, labels, vd.Scope(), opts}, nil -} - -// GetWithRef gets a volume with the given name from the passed in driver and stores the ref -// This is just like Get(), but we store the reference while holding the lock. -// This makes sure there are no races between checking for the existence of a volume and adding a reference for it -func (s *VolumeStore) GetWithRef(name, driverName, ref string) (volume.Volume, error) { - name = normaliseVolumeName(name) - s.locks.Lock(name) - defer s.locks.Unlock(name) - - vd, err := volumedrivers.GetDriver(driverName) - if err != nil { - return nil, &OpErr{Err: err, Name: name, Op: "get"} - } - - v, err := vd.Get(name) - if err != nil { - return nil, &OpErr{Err: err, Name: name, Op: "get"} - } - - s.setNamed(v, ref) - - s.globalLock.RLock() - defer s.globalLock.RUnlock() - return volumeWrapper{v, s.labels[name], vd.Scope(), s.options[name]}, nil -} - -// Get looks if a volume with the given name exists and returns it if so -func (s *VolumeStore) Get(name string) (volume.Volume, error) { - name = normaliseVolumeName(name) - s.locks.Lock(name) - defer s.locks.Unlock(name) - - v, err := s.getVolume(name) - if err != nil { - return nil, &OpErr{Err: err, Name: name, Op: "get"} - } - s.setNamed(v, "") - return v, nil -} - -// getVolume requests the volume, if the driver info is stored it just accesses that driver, -// if the driver is unknown it probes all drivers until it finds the first volume with that name. -// it is expected that callers of this function hold any necessary locks -func (s *VolumeStore) getVolume(name string) (volume.Volume, error) { - var meta volumeMetadata - meta, err := s.getMeta(name) - if err != nil { - return nil, err - } - - driverName := meta.Driver - if driverName == "" { - s.globalLock.RLock() - v, exists := s.names[name] - s.globalLock.RUnlock() - if exists { - meta.Driver = v.DriverName() - if err := s.setMeta(name, meta); err != nil { - return nil, err - } - } - } - - if meta.Driver != "" { - vol, err := lookupVolume(meta.Driver, name) - if err != nil { - return nil, err - } - if vol == nil { - s.Purge(name) - return nil, errNoSuchVolume - } - - var scope string - vd, err := volumedrivers.GetDriver(meta.Driver) - if err == nil { - scope = vd.Scope() - } - return volumeWrapper{vol, meta.Labels, scope, meta.Options}, nil - } - - logrus.Debugf("Probing all drivers for volume with name: %s", name) - drivers, err := volumedrivers.GetAllDrivers() - if err != nil { - return nil, err - } - - for _, d := range drivers { - v, err := d.Get(name) - if err != nil || v == nil { - continue - } - meta.Driver = v.DriverName() - if err := s.setMeta(name, meta); err != nil { - return nil, err - } - return volumeWrapper{v, meta.Labels, d.Scope(), meta.Options}, nil - } - return nil, errNoSuchVolume -} - -// lookupVolume gets the specified volume from the specified driver. -// This will only return errors related to communications with the driver. -// If the driver returns an error that is not communication related the -// error is logged but not returned. -// If the volume is not found it will return `nil, nil`` -func lookupVolume(driverName, volumeName string) (volume.Volume, error) { - vd, err := volumedrivers.GetDriver(driverName) - if err != nil { - return nil, errors.Wrapf(err, "error while checking if volume %q exists in driver %q", volumeName, driverName) - } - v, err := vd.Get(volumeName) - if err != nil { - err = errors.Cause(err) - if _, ok := err.(net.Error); ok { - return nil, errors.Wrapf(err, "error while checking if volume %q exists in driver %q", v.Name(), v.DriverName()) - } - - // At this point, the error could be anything from the driver, such as "no such volume" - // Let's not check an error here, and instead check if the driver returned a volume - logrus.WithError(err).WithField("driver", driverName).WithField("volume", volumeName).Warnf("Error while looking up volume") - } - return v, nil -} - -// Remove removes the requested volume. A volume is not removed if it has any refs -func (s *VolumeStore) Remove(v volume.Volume) error { - name := normaliseVolumeName(v.Name()) - s.locks.Lock(name) - defer s.locks.Unlock(name) - - refs := s.getRefs(name) - if len(refs) > 0 { - return &OpErr{Err: errVolumeInUse, Name: v.Name(), Op: "remove", Refs: refs} - } - - vd, err := volumedrivers.GetDriver(v.DriverName()) - if err != nil { - return &OpErr{Err: err, Name: vd.Name(), Op: "remove"} - } - - logrus.Debugf("Removing volume reference: driver %s, name %s", v.DriverName(), name) - vol := unwrapVolume(v) - if err := vd.Remove(vol); err != nil { - return &OpErr{Err: err, Name: name, Op: "remove"} - } - - s.Purge(name) - return nil -} - -// Dereference removes the specified reference to the volume -func (s *VolumeStore) Dereference(v volume.Volume, ref string) { - s.locks.Lock(v.Name()) - defer s.locks.Unlock(v.Name()) - - s.globalLock.Lock() - defer s.globalLock.Unlock() - var refs []string - - for _, r := range s.refs[v.Name()] { - if r != ref { - refs = append(refs, r) - } - } - s.refs[v.Name()] = refs -} - -// Refs gets the current list of refs for the given volume -func (s *VolumeStore) Refs(v volume.Volume) []string { - s.locks.Lock(v.Name()) - defer s.locks.Unlock(v.Name()) - - refs := s.getRefs(v.Name()) - refsOut := make([]string, len(refs)) - copy(refsOut, refs) - return refsOut -} - -// FilterByDriver returns the available volumes filtered by driver name -func (s *VolumeStore) FilterByDriver(name string) ([]volume.Volume, error) { - vd, err := volumedrivers.GetDriver(name) - if err != nil { - return nil, &OpErr{Err: err, Name: name, Op: "list"} - } - ls, err := vd.List() - if err != nil { - return nil, &OpErr{Err: err, Name: name, Op: "list"} - } - for i, v := range ls { - options := map[string]string{} - s.globalLock.RLock() - for key, value := range s.options[v.Name()] { - options[key] = value - } - ls[i] = volumeWrapper{v, s.labels[v.Name()], vd.Scope(), options} - s.globalLock.RUnlock() - } - return ls, nil -} - -// FilterByUsed returns the available volumes filtered by if they are in use or not. -// `used=true` returns only volumes that are being used, while `used=false` returns -// only volumes that are not being used. -func (s *VolumeStore) FilterByUsed(vols []volume.Volume, used bool) []volume.Volume { - return s.filter(vols, func(v volume.Volume) bool { - s.locks.Lock(v.Name()) - l := len(s.getRefs(v.Name())) - s.locks.Unlock(v.Name()) - if (used && l > 0) || (!used && l == 0) { - return true - } - return false - }) -} - -// filterFunc defines a function to allow filter volumes in the store -type filterFunc func(vol volume.Volume) bool - -// filter returns the available volumes filtered by a filterFunc function -func (s *VolumeStore) filter(vols []volume.Volume, f filterFunc) []volume.Volume { - var ls []volume.Volume - for _, v := range vols { - if f(v) { - ls = append(ls, v) - } - } - return ls -} - -func unwrapVolume(v volume.Volume) volume.Volume { - if vol, ok := v.(volumeWrapper); ok { - return vol.Volume - } - - return v -} - -// Shutdown releases all resources used by the volume store -// It does not make any changes to volumes, drivers, etc. -func (s *VolumeStore) Shutdown() error { - return s.db.Close() -} diff --git a/vendor/github.com/docker/docker/volume/store/store_test.go b/vendor/github.com/docker/docker/volume/store/store_test.go deleted file mode 100644 index b52f720..0000000 --- a/vendor/github.com/docker/docker/volume/store/store_test.go +++ /dev/null @@ -1,234 +0,0 @@ -package store - -import ( - "errors" - "io/ioutil" - "os" - "strings" - "testing" - - "github.com/docker/docker/volume/drivers" - volumetestutils "github.com/docker/docker/volume/testutils" -) - -func TestCreate(t *testing.T) { - volumedrivers.Register(volumetestutils.NewFakeDriver("fake"), "fake") - defer volumedrivers.Unregister("fake") - dir, err := ioutil.TempDir("", "test-create") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) - - s, err := New(dir) - if err != nil { - t.Fatal(err) - } - v, err := s.Create("fake1", "fake", nil, nil) - if err != nil { - t.Fatal(err) - } - if v.Name() != "fake1" { - t.Fatalf("Expected fake1 volume, got %v", v) - } - if l, _, _ := s.List(); len(l) != 1 { - t.Fatalf("Expected 1 volume in the store, got %v: %v", len(l), l) - } - - if _, err := s.Create("none", "none", nil, nil); err == nil { - t.Fatalf("Expected unknown driver error, got nil") - } - - _, err = s.Create("fakeerror", "fake", map[string]string{"error": "create error"}, nil) - expected := &OpErr{Op: "create", Name: "fakeerror", Err: errors.New("create error")} - if err != nil && err.Error() != expected.Error() { - t.Fatalf("Expected create fakeError: create error, got %v", err) - } -} - -func TestRemove(t *testing.T) { - volumedrivers.Register(volumetestutils.NewFakeDriver("fake"), "fake") - volumedrivers.Register(volumetestutils.NewFakeDriver("noop"), "noop") - defer volumedrivers.Unregister("fake") - defer volumedrivers.Unregister("noop") - dir, err := ioutil.TempDir("", "test-remove") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) - s, err := New(dir) - if err != nil { - t.Fatal(err) - } - - // doing string compare here since this error comes directly from the driver - expected := "no such volume" - if err := s.Remove(volumetestutils.NoopVolume{}); err == nil || !strings.Contains(err.Error(), expected) { - t.Fatalf("Expected error %q, got %v", expected, err) - } - - v, err := s.CreateWithRef("fake1", "fake", "fake", nil, nil) - if err != nil { - t.Fatal(err) - } - - if err := s.Remove(v); !IsInUse(err) { - t.Fatalf("Expected ErrVolumeInUse error, got %v", err) - } - s.Dereference(v, "fake") - if err := s.Remove(v); err != nil { - t.Fatal(err) - } - if l, _, _ := s.List(); len(l) != 0 { - t.Fatalf("Expected 0 volumes in the store, got %v, %v", len(l), l) - } -} - -func TestList(t *testing.T) { - volumedrivers.Register(volumetestutils.NewFakeDriver("fake"), "fake") - volumedrivers.Register(volumetestutils.NewFakeDriver("fake2"), "fake2") - defer volumedrivers.Unregister("fake") - defer volumedrivers.Unregister("fake2") - dir, err := ioutil.TempDir("", "test-list") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) - - s, err := New(dir) - if err != nil { - t.Fatal(err) - } - if _, err := s.Create("test", "fake", nil, nil); err != nil { - t.Fatal(err) - } - if _, err := s.Create("test2", "fake2", nil, nil); err != nil { - t.Fatal(err) - } - - ls, _, err := s.List() - if err != nil { - t.Fatal(err) - } - if len(ls) != 2 { - t.Fatalf("expected 2 volumes, got: %d", len(ls)) - } - if err := s.Shutdown(); err != nil { - t.Fatal(err) - } - - // and again with a new store - s, err = New(dir) - if err != nil { - t.Fatal(err) - } - ls, _, err = s.List() - if err != nil { - t.Fatal(err) - } - if len(ls) != 2 { - t.Fatalf("expected 2 volumes, got: %d", len(ls)) - } -} - -func TestFilterByDriver(t *testing.T) { - volumedrivers.Register(volumetestutils.NewFakeDriver("fake"), "fake") - volumedrivers.Register(volumetestutils.NewFakeDriver("noop"), "noop") - defer volumedrivers.Unregister("fake") - defer volumedrivers.Unregister("noop") - dir, err := ioutil.TempDir("", "test-filter-driver") - if err != nil { - t.Fatal(err) - } - s, err := New(dir) - if err != nil { - t.Fatal(err) - } - - if _, err := s.Create("fake1", "fake", nil, nil); err != nil { - t.Fatal(err) - } - if _, err := s.Create("fake2", "fake", nil, nil); err != nil { - t.Fatal(err) - } - if _, err := s.Create("fake3", "noop", nil, nil); err != nil { - t.Fatal(err) - } - - if l, _ := s.FilterByDriver("fake"); len(l) != 2 { - t.Fatalf("Expected 2 volumes, got %v, %v", len(l), l) - } - - if l, _ := s.FilterByDriver("noop"); len(l) != 1 { - t.Fatalf("Expected 1 volume, got %v, %v", len(l), l) - } -} - -func TestFilterByUsed(t *testing.T) { - volumedrivers.Register(volumetestutils.NewFakeDriver("fake"), "fake") - volumedrivers.Register(volumetestutils.NewFakeDriver("noop"), "noop") - dir, err := ioutil.TempDir("", "test-filter-used") - if err != nil { - t.Fatal(err) - } - - s, err := New(dir) - if err != nil { - t.Fatal(err) - } - - if _, err := s.CreateWithRef("fake1", "fake", "volReference", nil, nil); err != nil { - t.Fatal(err) - } - if _, err := s.Create("fake2", "fake", nil, nil); err != nil { - t.Fatal(err) - } - - vols, _, err := s.List() - if err != nil { - t.Fatal(err) - } - - dangling := s.FilterByUsed(vols, false) - if len(dangling) != 1 { - t.Fatalf("expected 1 danging volume, got %v", len(dangling)) - } - if dangling[0].Name() != "fake2" { - t.Fatalf("expected danging volume fake2, got %s", dangling[0].Name()) - } - - used := s.FilterByUsed(vols, true) - if len(used) != 1 { - t.Fatalf("expected 1 used volume, got %v", len(used)) - } - if used[0].Name() != "fake1" { - t.Fatalf("expected used volume fake1, got %s", used[0].Name()) - } -} - -func TestDerefMultipleOfSameRef(t *testing.T) { - volumedrivers.Register(volumetestutils.NewFakeDriver("fake"), "fake") - dir, err := ioutil.TempDir("", "test-same-deref") - if err != nil { - t.Fatal(err) - } - - s, err := New(dir) - if err != nil { - t.Fatal(err) - } - - v, err := s.CreateWithRef("fake1", "fake", "volReference", nil, nil) - if err != nil { - t.Fatal(err) - } - - if _, err := s.GetWithRef("fake1", "fake", "volReference"); err != nil { - t.Fatal(err) - } - - s.Dereference(v, "volReference") - if err := s.Remove(v); err != nil { - t.Fatal(err) - } -} diff --git a/vendor/github.com/docker/docker/volume/store/store_unix.go b/vendor/github.com/docker/docker/volume/store/store_unix.go deleted file mode 100644 index 8ebc1f2..0000000 --- a/vendor/github.com/docker/docker/volume/store/store_unix.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build linux freebsd solaris - -package store - -// normaliseVolumeName is a platform specific function to normalise the name -// of a volume. This is a no-op on Unix-like platforms -func normaliseVolumeName(name string) string { - return name -} diff --git a/vendor/github.com/docker/docker/volume/store/store_windows.go b/vendor/github.com/docker/docker/volume/store/store_windows.go deleted file mode 100644 index 8601cdd..0000000 --- a/vendor/github.com/docker/docker/volume/store/store_windows.go +++ /dev/null @@ -1,12 +0,0 @@ -package store - -import "strings" - -// normaliseVolumeName is a platform specific function to normalise the name -// of a volume. On Windows, as NTFS is case insensitive, under -// c:\ProgramData\Docker\Volumes\, the folders John and john would be synonymous. -// Hence we can't allow the volume "John" and "john" to be created as separate -// volumes. -func normaliseVolumeName(name string) string { - return strings.ToLower(name) -} diff --git a/vendor/github.com/docker/docker/volume/testutils/testutils.go b/vendor/github.com/docker/docker/volume/testutils/testutils.go deleted file mode 100644 index 2dbac02..0000000 --- a/vendor/github.com/docker/docker/volume/testutils/testutils.go +++ /dev/null @@ -1,116 +0,0 @@ -package testutils - -import ( - "fmt" - - "github.com/docker/docker/volume" -) - -// NoopVolume is a volume that doesn't perform any operation -type NoopVolume struct{} - -// Name is the name of the volume -func (NoopVolume) Name() string { return "noop" } - -// DriverName is the name of the driver -func (NoopVolume) DriverName() string { return "noop" } - -// Path is the filesystem path to the volume -func (NoopVolume) Path() string { return "noop" } - -// Mount mounts the volume in the container -func (NoopVolume) Mount(_ string) (string, error) { return "noop", nil } - -// Unmount unmounts the volume from the container -func (NoopVolume) Unmount(_ string) error { return nil } - -// Status proivdes low-level details about the volume -func (NoopVolume) Status() map[string]interface{} { return nil } - -// FakeVolume is a fake volume with a random name -type FakeVolume struct { - name string - driverName string -} - -// NewFakeVolume creates a new fake volume for testing -func NewFakeVolume(name string, driverName string) volume.Volume { - return FakeVolume{name: name, driverName: driverName} -} - -// Name is the name of the volume -func (f FakeVolume) Name() string { return f.name } - -// DriverName is the name of the driver -func (f FakeVolume) DriverName() string { return f.driverName } - -// Path is the filesystem path to the volume -func (FakeVolume) Path() string { return "fake" } - -// Mount mounts the volume in the container -func (FakeVolume) Mount(_ string) (string, error) { return "fake", nil } - -// Unmount unmounts the volume from the container -func (FakeVolume) Unmount(_ string) error { return nil } - -// Status proivdes low-level details about the volume -func (FakeVolume) Status() map[string]interface{} { return nil } - -// FakeDriver is a driver that generates fake volumes -type FakeDriver struct { - name string - vols map[string]volume.Volume -} - -// NewFakeDriver creates a new FakeDriver with the specified name -func NewFakeDriver(name string) volume.Driver { - return &FakeDriver{ - name: name, - vols: make(map[string]volume.Volume), - } -} - -// Name is the name of the driver -func (d *FakeDriver) Name() string { return d.name } - -// Create initializes a fake volume. -// It returns an error if the options include an "error" key with a message -func (d *FakeDriver) Create(name string, opts map[string]string) (volume.Volume, error) { - if opts != nil && opts["error"] != "" { - return nil, fmt.Errorf(opts["error"]) - } - v := NewFakeVolume(name, d.name) - d.vols[name] = v - return v, nil -} - -// Remove deletes a volume. -func (d *FakeDriver) Remove(v volume.Volume) error { - if _, exists := d.vols[v.Name()]; !exists { - return fmt.Errorf("no such volume") - } - delete(d.vols, v.Name()) - return nil -} - -// List lists the volumes -func (d *FakeDriver) List() ([]volume.Volume, error) { - var vols []volume.Volume - for _, v := range d.vols { - vols = append(vols, v) - } - return vols, nil -} - -// Get gets the volume -func (d *FakeDriver) Get(name string) (volume.Volume, error) { - if v, exists := d.vols[name]; exists { - return v, nil - } - return nil, fmt.Errorf("no such volume") -} - -// Scope returns the local scope -func (*FakeDriver) Scope() string { - return "local" -} diff --git a/vendor/github.com/docker/docker/volume/validate.go b/vendor/github.com/docker/docker/volume/validate.go deleted file mode 100644 index 27a8c5d..0000000 --- a/vendor/github.com/docker/docker/volume/validate.go +++ /dev/null @@ -1,125 +0,0 @@ -package volume - -import ( - "errors" - "fmt" - "os" - "path/filepath" - - "github.com/docker/docker/api/types/mount" -) - -var errBindNotExist = errors.New("bind source path does not exist") - -type validateOpts struct { - skipBindSourceCheck bool - skipAbsolutePathCheck bool -} - -func validateMountConfig(mnt *mount.Mount, options ...func(*validateOpts)) error { - opts := validateOpts{} - for _, o := range options { - o(&opts) - } - - if len(mnt.Target) == 0 { - return &errMountConfig{mnt, errMissingField("Target")} - } - - if err := validateNotRoot(mnt.Target); err != nil { - return &errMountConfig{mnt, err} - } - - if !opts.skipAbsolutePathCheck { - if err := validateAbsolute(mnt.Target); err != nil { - return &errMountConfig{mnt, err} - } - } - - switch mnt.Type { - case mount.TypeBind: - if len(mnt.Source) == 0 { - return &errMountConfig{mnt, errMissingField("Source")} - } - // Don't error out just because the propagation mode is not supported on the platform - if opts := mnt.BindOptions; opts != nil { - if len(opts.Propagation) > 0 && len(propagationModes) > 0 { - if _, ok := propagationModes[opts.Propagation]; !ok { - return &errMountConfig{mnt, fmt.Errorf("invalid propagation mode: %s", opts.Propagation)} - } - } - } - if mnt.VolumeOptions != nil { - return &errMountConfig{mnt, errExtraField("VolumeOptions")} - } - - if err := validateAbsolute(mnt.Source); err != nil { - return &errMountConfig{mnt, err} - } - - // Do not allow binding to non-existent path - if !opts.skipBindSourceCheck { - fi, err := os.Stat(mnt.Source) - if err != nil { - if !os.IsNotExist(err) { - return &errMountConfig{mnt, err} - } - return &errMountConfig{mnt, errBindNotExist} - } - if err := validateStat(fi); err != nil { - return &errMountConfig{mnt, err} - } - } - case mount.TypeVolume: - if mnt.BindOptions != nil { - return &errMountConfig{mnt, errExtraField("BindOptions")} - } - - if len(mnt.Source) == 0 && mnt.ReadOnly { - return &errMountConfig{mnt, fmt.Errorf("must not set ReadOnly mode when using anonymous volumes")} - } - - if len(mnt.Source) != 0 { - if valid, err := IsVolumeNameValid(mnt.Source); !valid { - if err == nil { - err = errors.New("invalid volume name") - } - return &errMountConfig{mnt, err} - } - } - case mount.TypeTmpfs: - if len(mnt.Source) != 0 { - return &errMountConfig{mnt, errExtraField("Source")} - } - if _, err := ConvertTmpfsOptions(mnt.TmpfsOptions, mnt.ReadOnly); err != nil { - return &errMountConfig{mnt, err} - } - default: - return &errMountConfig{mnt, errors.New("mount type unknown")} - } - return nil -} - -type errMountConfig struct { - mount *mount.Mount - err error -} - -func (e *errMountConfig) Error() string { - return fmt.Sprintf("invalid mount config for type %q: %v", e.mount.Type, e.err.Error()) -} - -func errExtraField(name string) error { - return fmt.Errorf("field %s must not be specified", name) -} -func errMissingField(name string) error { - return fmt.Errorf("field %s must not be empty", name) -} - -func validateAbsolute(p string) error { - p = convertSlash(p) - if filepath.IsAbs(p) { - return nil - } - return fmt.Errorf("invalid mount path: '%s' mount path must be absolute", p) -} diff --git a/vendor/github.com/docker/docker/volume/validate_test.go b/vendor/github.com/docker/docker/volume/validate_test.go deleted file mode 100644 index 8732500..0000000 --- a/vendor/github.com/docker/docker/volume/validate_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package volume - -import ( - "errors" - "io/ioutil" - "os" - "strings" - "testing" - - "github.com/docker/docker/api/types/mount" -) - -func TestValidateMount(t *testing.T) { - testDir, err := ioutil.TempDir("", "test-validate-mount") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(testDir) - - cases := []struct { - input mount.Mount - expected error - }{ - {mount.Mount{Type: mount.TypeVolume}, errMissingField("Target")}, - {mount.Mount{Type: mount.TypeVolume, Target: testDestinationPath, Source: "hello"}, nil}, - {mount.Mount{Type: mount.TypeVolume, Target: testDestinationPath}, nil}, - {mount.Mount{Type: mount.TypeBind}, errMissingField("Target")}, - {mount.Mount{Type: mount.TypeBind, Target: testDestinationPath}, errMissingField("Source")}, - {mount.Mount{Type: mount.TypeBind, Target: testDestinationPath, Source: testSourcePath, VolumeOptions: &mount.VolumeOptions{}}, errExtraField("VolumeOptions")}, - {mount.Mount{Type: mount.TypeBind, Source: testSourcePath, Target: testDestinationPath}, errBindNotExist}, - {mount.Mount{Type: mount.TypeBind, Source: testDir, Target: testDestinationPath}, nil}, - {mount.Mount{Type: "invalid", Target: testDestinationPath}, errors.New("mount type unknown")}, - } - for i, x := range cases { - err := validateMountConfig(&x.input) - if err == nil && x.expected == nil { - continue - } - if (err == nil && x.expected != nil) || (x.expected == nil && err != nil) || !strings.Contains(err.Error(), x.expected.Error()) { - t.Fatalf("expected %q, got %q, case: %d", x.expected, err, i) - } - } -} diff --git a/vendor/github.com/docker/docker/volume/validate_test_unix.go b/vendor/github.com/docker/docker/volume/validate_test_unix.go deleted file mode 100644 index dd1de2f..0000000 --- a/vendor/github.com/docker/docker/volume/validate_test_unix.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !windows - -package volume - -var ( - testDestinationPath = "/foo" - testSourcePath = "/foo" -) diff --git a/vendor/github.com/docker/docker/volume/validate_test_windows.go b/vendor/github.com/docker/docker/volume/validate_test_windows.go deleted file mode 100644 index d5f86ac..0000000 --- a/vendor/github.com/docker/docker/volume/validate_test_windows.go +++ /dev/null @@ -1,6 +0,0 @@ -package volume - -var ( - testDestinationPath = `c:\foo` - testSourcePath = `c:\foo` -) diff --git a/vendor/github.com/docker/docker/volume/volume.go b/vendor/github.com/docker/docker/volume/volume.go deleted file mode 100644 index f3227fe..0000000 --- a/vendor/github.com/docker/docker/volume/volume.go +++ /dev/null @@ -1,323 +0,0 @@ -package volume - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "syscall" - - mounttypes "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/stringid" - "github.com/opencontainers/runc/libcontainer/label" - "github.com/pkg/errors" -) - -// DefaultDriverName is the driver name used for the driver -// implemented in the local package. -const DefaultDriverName = "local" - -// Scopes define if a volume has is cluster-wide (global) or local only. -// Scopes are returned by the volume driver when it is queried for capabilities and then set on a volume -const ( - LocalScope = "local" - GlobalScope = "global" -) - -// Driver is for creating and removing volumes. -type Driver interface { - // Name returns the name of the volume driver. - Name() string - // Create makes a new volume with the given id. - Create(name string, opts map[string]string) (Volume, error) - // Remove deletes the volume. - Remove(vol Volume) (err error) - // List lists all the volumes the driver has - List() ([]Volume, error) - // Get retrieves the volume with the requested name - Get(name string) (Volume, error) - // Scope returns the scope of the driver (e.g. `global` or `local`). - // Scope determines how the driver is handled at a cluster level - Scope() string -} - -// Capability defines a set of capabilities that a driver is able to handle. -type Capability struct { - // Scope is the scope of the driver, `global` or `local` - // A `global` scope indicates that the driver manages volumes across the cluster - // A `local` scope indicates that the driver only manages volumes resources local to the host - // Scope is declared by the driver - Scope string -} - -// Volume is a place to store data. It is backed by a specific driver, and can be mounted. -type Volume interface { - // Name returns the name of the volume - Name() string - // DriverName returns the name of the driver which owns this volume. - DriverName() string - // Path returns the absolute path to the volume. - Path() string - // Mount mounts the volume and returns the absolute path to - // where it can be consumed. - Mount(id string) (string, error) - // Unmount unmounts the volume when it is no longer in use. - Unmount(id string) error - // Status returns low-level status information about a volume - Status() map[string]interface{} -} - -// DetailedVolume wraps a Volume with user-defined labels, options, and cluster scope (e.g., `local` or `global`) -type DetailedVolume interface { - Labels() map[string]string - Options() map[string]string - Scope() string - Volume -} - -// MountPoint is the intersection point between a volume and a container. It -// specifies which volume is to be used and where inside a container it should -// be mounted. -type MountPoint struct { - // Source is the source path of the mount. - // E.g. `mount --bind /foo /bar`, `/foo` is the `Source`. - Source string - // Destination is the path relative to the container root (`/`) to the mount point - // It is where the `Source` is mounted to - Destination string - // RW is set to true when the mountpoint should be mounted as read-write - RW bool - // Name is the name reference to the underlying data defined by `Source` - // e.g., the volume name - Name string - // Driver is the volume driver used to create the volume (if it is a volume) - Driver string - // Type of mount to use, see `Type` definitions in github.com/docker/docker/api/types/mount - Type mounttypes.Type `json:",omitempty"` - // Volume is the volume providing data to this mountpoint. - // This is nil unless `Type` is set to `TypeVolume` - Volume Volume `json:"-"` - - // Mode is the comma separated list of options supplied by the user when creating - // the bind/volume mount. - // Note Mode is not used on Windows - Mode string `json:"Relabel,omitempty"` // Originally field was `Relabel`" - - // Propagation describes how the mounts are propagated from the host into the - // mount point, and vice-versa. - // See https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt - // Note Propagation is not used on Windows - Propagation mounttypes.Propagation `json:",omitempty"` // Mount propagation string - - // Specifies if data should be copied from the container before the first mount - // Use a pointer here so we can tell if the user set this value explicitly - // This allows us to error out when the user explicitly enabled copy but we can't copy due to the volume being populated - CopyData bool `json:"-"` - // ID is the opaque ID used to pass to the volume driver. - // This should be set by calls to `Mount` and unset by calls to `Unmount` - ID string `json:",omitempty"` - - // Sepc is a copy of the API request that created this mount. - Spec mounttypes.Mount -} - -// Setup sets up a mount point by either mounting the volume if it is -// configured, or creating the source directory if supplied. -func (m *MountPoint) Setup(mountLabel string, rootUID, rootGID int) (string, error) { - if m.Volume != nil { - id := m.ID - if id == "" { - id = stringid.GenerateNonCryptoID() - } - path, err := m.Volume.Mount(id) - if err != nil { - return "", errors.Wrapf(err, "error while mounting volume '%s'", m.Source) - } - m.ID = id - return path, nil - } - if len(m.Source) == 0 { - return "", fmt.Errorf("Unable to setup mount point, neither source nor volume defined") - } - // system.MkdirAll() produces an error if m.Source exists and is a file (not a directory), - if m.Type == mounttypes.TypeBind { - // idtools.MkdirAllNewAs() produces an error if m.Source exists and is a file (not a directory) - // also, makes sure that if the directory is created, the correct remapped rootUID/rootGID will own it - if err := idtools.MkdirAllNewAs(m.Source, 0755, rootUID, rootGID); err != nil { - if perr, ok := err.(*os.PathError); ok { - if perr.Err != syscall.ENOTDIR { - return "", errors.Wrapf(err, "error while creating mount source path '%s'", m.Source) - } - } - } - } - if label.RelabelNeeded(m.Mode) { - if err := label.Relabel(m.Source, mountLabel, label.IsShared(m.Mode)); err != nil { - return "", errors.Wrapf(err, "error setting label on mount source '%s'", m.Source) - } - } - return m.Source, nil -} - -// Path returns the path of a volume in a mount point. -func (m *MountPoint) Path() string { - if m.Volume != nil { - return m.Volume.Path() - } - return m.Source -} - -// ParseVolumesFrom ensures that the supplied volumes-from is valid. -func ParseVolumesFrom(spec string) (string, string, error) { - if len(spec) == 0 { - return "", "", fmt.Errorf("volumes-from specification cannot be an empty string") - } - - specParts := strings.SplitN(spec, ":", 2) - id := specParts[0] - mode := "rw" - - if len(specParts) == 2 { - mode = specParts[1] - if !ValidMountMode(mode) { - return "", "", errInvalidMode(mode) - } - // For now don't allow propagation properties while importing - // volumes from data container. These volumes will inherit - // the same propagation property as of the original volume - // in data container. This probably can be relaxed in future. - if HasPropagation(mode) { - return "", "", errInvalidMode(mode) - } - // Do not allow copy modes on volumes-from - if _, isSet := getCopyMode(mode); isSet { - return "", "", errInvalidMode(mode) - } - } - return id, mode, nil -} - -// ParseMountRaw parses a raw volume spec (e.g. `-v /foo:/bar:shared`) into a -// structured spec. Once the raw spec is parsed it relies on `ParseMountSpec` to -// validate the spec and create a MountPoint -func ParseMountRaw(raw, volumeDriver string) (*MountPoint, error) { - arr, err := splitRawSpec(convertSlash(raw)) - if err != nil { - return nil, err - } - - var spec mounttypes.Mount - var mode string - switch len(arr) { - case 1: - // Just a destination path in the container - spec.Target = arr[0] - case 2: - if ValidMountMode(arr[1]) { - // Destination + Mode is not a valid volume - volumes - // cannot include a mode. eg /foo:rw - return nil, errInvalidSpec(raw) - } - // Host Source Path or Name + Destination - spec.Source = arr[0] - spec.Target = arr[1] - case 3: - // HostSourcePath+DestinationPath+Mode - spec.Source = arr[0] - spec.Target = arr[1] - mode = arr[2] - default: - return nil, errInvalidSpec(raw) - } - - if !ValidMountMode(mode) { - return nil, errInvalidMode(mode) - } - - if filepath.IsAbs(spec.Source) { - spec.Type = mounttypes.TypeBind - } else { - spec.Type = mounttypes.TypeVolume - } - - spec.ReadOnly = !ReadWrite(mode) - - // cannot assume that if a volume driver is passed in that we should set it - if volumeDriver != "" && spec.Type == mounttypes.TypeVolume { - spec.VolumeOptions = &mounttypes.VolumeOptions{ - DriverConfig: &mounttypes.Driver{Name: volumeDriver}, - } - } - - if copyData, isSet := getCopyMode(mode); isSet { - if spec.VolumeOptions == nil { - spec.VolumeOptions = &mounttypes.VolumeOptions{} - } - spec.VolumeOptions.NoCopy = !copyData - } - if HasPropagation(mode) { - spec.BindOptions = &mounttypes.BindOptions{ - Propagation: GetPropagation(mode), - } - } - - mp, err := ParseMountSpec(spec, platformRawValidationOpts...) - if mp != nil { - mp.Mode = mode - } - if err != nil { - err = fmt.Errorf("%v: %v", errInvalidSpec(raw), err) - } - return mp, err -} - -// ParseMountSpec reads a mount config, validates it, and configures a mountpoint from it. -func ParseMountSpec(cfg mounttypes.Mount, options ...func(*validateOpts)) (*MountPoint, error) { - if err := validateMountConfig(&cfg, options...); err != nil { - return nil, err - } - mp := &MountPoint{ - RW: !cfg.ReadOnly, - Destination: clean(convertSlash(cfg.Target)), - Type: cfg.Type, - Spec: cfg, - } - - switch cfg.Type { - case mounttypes.TypeVolume: - if cfg.Source == "" { - mp.Name = stringid.GenerateNonCryptoID() - } else { - mp.Name = cfg.Source - } - mp.CopyData = DefaultCopyMode - - if cfg.VolumeOptions != nil { - if cfg.VolumeOptions.DriverConfig != nil { - mp.Driver = cfg.VolumeOptions.DriverConfig.Name - } - if cfg.VolumeOptions.NoCopy { - mp.CopyData = false - } - } - case mounttypes.TypeBind: - mp.Source = clean(convertSlash(cfg.Source)) - if cfg.BindOptions != nil { - if len(cfg.BindOptions.Propagation) > 0 { - mp.Propagation = cfg.BindOptions.Propagation - } - } - case mounttypes.TypeTmpfs: - // NOP - } - return mp, nil -} - -func errInvalidMode(mode string) error { - return fmt.Errorf("invalid mode: %v", mode) -} - -func errInvalidSpec(spec string) error { - return fmt.Errorf("invalid volume specification: '%s'", spec) -} diff --git a/vendor/github.com/docker/docker/volume/volume_copy.go b/vendor/github.com/docker/docker/volume/volume_copy.go deleted file mode 100644 index 77f06a0..0000000 --- a/vendor/github.com/docker/docker/volume/volume_copy.go +++ /dev/null @@ -1,23 +0,0 @@ -package volume - -import "strings" - -// {=isEnabled} -var copyModes = map[string]bool{ - "nocopy": false, -} - -func copyModeExists(mode string) bool { - _, exists := copyModes[mode] - return exists -} - -// GetCopyMode gets the copy mode from the mode string for mounts -func getCopyMode(mode string) (bool, bool) { - for _, o := range strings.Split(mode, ",") { - if isEnabled, exists := copyModes[o]; exists { - return isEnabled, true - } - } - return DefaultCopyMode, false -} diff --git a/vendor/github.com/docker/docker/volume/volume_copy_unix.go b/vendor/github.com/docker/docker/volume/volume_copy_unix.go deleted file mode 100644 index ad66e17..0000000 --- a/vendor/github.com/docker/docker/volume/volume_copy_unix.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !windows - -package volume - -const ( - // DefaultCopyMode is the copy mode used by default for normal/named volumes - DefaultCopyMode = true -) diff --git a/vendor/github.com/docker/docker/volume/volume_copy_windows.go b/vendor/github.com/docker/docker/volume/volume_copy_windows.go deleted file mode 100644 index 798638c..0000000 --- a/vendor/github.com/docker/docker/volume/volume_copy_windows.go +++ /dev/null @@ -1,6 +0,0 @@ -package volume - -const ( - // DefaultCopyMode is the copy mode used by default for normal/named volumes - DefaultCopyMode = false -) diff --git a/vendor/github.com/docker/docker/volume/volume_linux.go b/vendor/github.com/docker/docker/volume/volume_linux.go deleted file mode 100644 index d4b4d80..0000000 --- a/vendor/github.com/docker/docker/volume/volume_linux.go +++ /dev/null @@ -1,56 +0,0 @@ -// +build linux - -package volume - -import ( - "fmt" - "strings" - - mounttypes "github.com/docker/docker/api/types/mount" -) - -// ConvertTmpfsOptions converts *mounttypes.TmpfsOptions to the raw option string -// for mount(2). -func ConvertTmpfsOptions(opt *mounttypes.TmpfsOptions, readOnly bool) (string, error) { - var rawOpts []string - if readOnly { - rawOpts = append(rawOpts, "ro") - } - - if opt != nil && opt.Mode != 0 { - rawOpts = append(rawOpts, fmt.Sprintf("mode=%o", opt.Mode)) - } - - if opt != nil && opt.SizeBytes != 0 { - // calculate suffix here, making this linux specific, but that is - // okay, since API is that way anyways. - - // we do this by finding the suffix that divides evenly into the - // value, returing the value itself, with no suffix, if it fails. - // - // For the most part, we don't enforce any semantic to this values. - // The operating system will usually align this and enforce minimum - // and maximums. - var ( - size = opt.SizeBytes - suffix string - ) - for _, r := range []struct { - suffix string - divisor int64 - }{ - {"g", 1 << 30}, - {"m", 1 << 20}, - {"k", 1 << 10}, - } { - if size%r.divisor == 0 { - size = size / r.divisor - suffix = r.suffix - break - } - } - - rawOpts = append(rawOpts, fmt.Sprintf("size=%d%s", size, suffix)) - } - return strings.Join(rawOpts, ","), nil -} diff --git a/vendor/github.com/docker/docker/volume/volume_linux_test.go b/vendor/github.com/docker/docker/volume/volume_linux_test.go deleted file mode 100644 index 40ce552..0000000 --- a/vendor/github.com/docker/docker/volume/volume_linux_test.go +++ /dev/null @@ -1,51 +0,0 @@ -// +build linux - -package volume - -import ( - "strings" - "testing" - - mounttypes "github.com/docker/docker/api/types/mount" -) - -func TestConvertTmpfsOptions(t *testing.T) { - type testCase struct { - opt mounttypes.TmpfsOptions - readOnly bool - expectedSubstrings []string - unexpectedSubstrings []string - } - cases := []testCase{ - { - opt: mounttypes.TmpfsOptions{SizeBytes: 1024 * 1024, Mode: 0700}, - readOnly: false, - expectedSubstrings: []string{"size=1m", "mode=700"}, - unexpectedSubstrings: []string{"ro"}, - }, - { - opt: mounttypes.TmpfsOptions{}, - readOnly: true, - expectedSubstrings: []string{"ro"}, - unexpectedSubstrings: []string{}, - }, - } - for _, c := range cases { - data, err := ConvertTmpfsOptions(&c.opt, c.readOnly) - if err != nil { - t.Fatalf("could not convert %+v (readOnly: %v) to string: %v", - c.opt, c.readOnly, err) - } - t.Logf("data=%q", data) - for _, s := range c.expectedSubstrings { - if !strings.Contains(data, s) { - t.Fatalf("expected substring: %s, got %v (case=%+v)", s, data, c) - } - } - for _, s := range c.unexpectedSubstrings { - if strings.Contains(data, s) { - t.Fatalf("unexpected substring: %s, got %v (case=%+v)", s, data, c) - } - } - } -} diff --git a/vendor/github.com/docker/docker/volume/volume_propagation_linux.go b/vendor/github.com/docker/docker/volume/volume_propagation_linux.go deleted file mode 100644 index 1de57ab..0000000 --- a/vendor/github.com/docker/docker/volume/volume_propagation_linux.go +++ /dev/null @@ -1,47 +0,0 @@ -// +build linux - -package volume - -import ( - "strings" - - mounttypes "github.com/docker/docker/api/types/mount" -) - -// DefaultPropagationMode defines what propagation mode should be used by -// default if user has not specified one explicitly. -// propagation modes -const DefaultPropagationMode = mounttypes.PropagationRPrivate - -var propagationModes = map[mounttypes.Propagation]bool{ - mounttypes.PropagationPrivate: true, - mounttypes.PropagationRPrivate: true, - mounttypes.PropagationSlave: true, - mounttypes.PropagationRSlave: true, - mounttypes.PropagationShared: true, - mounttypes.PropagationRShared: true, -} - -// GetPropagation extracts and returns the mount propagation mode. If there -// are no specifications, then by default it is "private". -func GetPropagation(mode string) mounttypes.Propagation { - for _, o := range strings.Split(mode, ",") { - prop := mounttypes.Propagation(o) - if propagationModes[prop] { - return prop - } - } - return DefaultPropagationMode -} - -// HasPropagation checks if there is a valid propagation mode present in -// passed string. Returns true if a valid propagation mode specifier is -// present, false otherwise. -func HasPropagation(mode string) bool { - for _, o := range strings.Split(mode, ",") { - if propagationModes[mounttypes.Propagation(o)] { - return true - } - } - return false -} diff --git a/vendor/github.com/docker/docker/volume/volume_propagation_linux_test.go b/vendor/github.com/docker/docker/volume/volume_propagation_linux_test.go deleted file mode 100644 index 46d0265..0000000 --- a/vendor/github.com/docker/docker/volume/volume_propagation_linux_test.go +++ /dev/null @@ -1,65 +0,0 @@ -// +build linux - -package volume - -import ( - "strings" - "testing" -) - -func TestParseMountRawPropagation(t *testing.T) { - var ( - valid []string - invalid map[string]string - ) - - valid = []string{ - "/hostPath:/containerPath:shared", - "/hostPath:/containerPath:rshared", - "/hostPath:/containerPath:slave", - "/hostPath:/containerPath:rslave", - "/hostPath:/containerPath:private", - "/hostPath:/containerPath:rprivate", - "/hostPath:/containerPath:ro,shared", - "/hostPath:/containerPath:ro,slave", - "/hostPath:/containerPath:ro,private", - "/hostPath:/containerPath:ro,z,shared", - "/hostPath:/containerPath:ro,Z,slave", - "/hostPath:/containerPath:Z,ro,slave", - "/hostPath:/containerPath:slave,Z,ro", - "/hostPath:/containerPath:Z,slave,ro", - "/hostPath:/containerPath:slave,ro,Z", - "/hostPath:/containerPath:rslave,ro,Z", - "/hostPath:/containerPath:ro,rshared,Z", - "/hostPath:/containerPath:ro,Z,rprivate", - } - invalid = map[string]string{ - "/path:/path:ro,rshared,rslave": `invalid mode`, - "/path:/path:ro,z,rshared,rslave": `invalid mode`, - "/path:shared": "invalid volume specification", - "/path:slave": "invalid volume specification", - "/path:private": "invalid volume specification", - "name:/absolute-path:shared": "invalid volume specification", - "name:/absolute-path:rshared": "invalid volume specification", - "name:/absolute-path:slave": "invalid volume specification", - "name:/absolute-path:rslave": "invalid volume specification", - "name:/absolute-path:private": "invalid volume specification", - "name:/absolute-path:rprivate": "invalid volume specification", - } - - for _, path := range valid { - if _, err := ParseMountRaw(path, "local"); err != nil { - t.Fatalf("ParseMountRaw(`%q`) should succeed: error %q", path, err) - } - } - - for path, expectedError := range invalid { - if _, err := ParseMountRaw(path, "local"); err == nil { - t.Fatalf("ParseMountRaw(`%q`) should have failed validation. Err %v", path, err) - } else { - if !strings.Contains(err.Error(), expectedError) { - t.Fatalf("ParseMountRaw(`%q`) error should contain %q, got %v", path, expectedError, err.Error()) - } - } - } -} diff --git a/vendor/github.com/docker/docker/volume/volume_propagation_unsupported.go b/vendor/github.com/docker/docker/volume/volume_propagation_unsupported.go deleted file mode 100644 index 7311ffc..0000000 --- a/vendor/github.com/docker/docker/volume/volume_propagation_unsupported.go +++ /dev/null @@ -1,24 +0,0 @@ -// +build !linux - -package volume - -import mounttypes "github.com/docker/docker/api/types/mount" - -// DefaultPropagationMode is used only in linux. In other cases it returns -// empty string. -const DefaultPropagationMode mounttypes.Propagation = "" - -// propagation modes not supported on this platform. -var propagationModes = map[mounttypes.Propagation]bool{} - -// GetPropagation is not supported. Return empty string. -func GetPropagation(mode string) mounttypes.Propagation { - return DefaultPropagationMode -} - -// HasPropagation checks if there is a valid propagation mode present in -// passed string. Returns true if a valid propagation mode specifier is -// present, false otherwise. -func HasPropagation(mode string) bool { - return false -} diff --git a/vendor/github.com/docker/docker/volume/volume_test.go b/vendor/github.com/docker/docker/volume/volume_test.go deleted file mode 100644 index 54df380..0000000 --- a/vendor/github.com/docker/docker/volume/volume_test.go +++ /dev/null @@ -1,269 +0,0 @@ -package volume - -import ( - "io/ioutil" - "os" - "runtime" - "strings" - "testing" - - "github.com/docker/docker/api/types/mount" -) - -func TestParseMountRaw(t *testing.T) { - var ( - valid []string - invalid map[string]string - ) - - if runtime.GOOS == "windows" { - valid = []string{ - `d:\`, - `d:`, - `d:\path`, - `d:\path with space`, - // TODO Windows post TP5 - readonly support `d:\pathandmode:ro`, - `c:\:d:\`, - `c:\windows\:d:`, - `c:\windows:d:\s p a c e`, - `c:\windows:d:\s p a c e:RW`, - `c:\program files:d:\s p a c e i n h o s t d i r`, - `0123456789name:d:`, - `MiXeDcAsEnAmE:d:`, - `name:D:`, - `name:D::rW`, - `name:D::RW`, - // TODO Windows post TP5 - readonly support `name:D::RO`, - `c:/:d:/forward/slashes/are/good/too`, - // TODO Windows post TP5 - readonly support `c:/:d:/including with/spaces:ro`, - `c:\Windows`, // With capital - `c:\Program Files (x86)`, // With capitals and brackets - } - invalid = map[string]string{ - ``: "invalid volume specification: ", - `.`: "invalid volume specification: ", - `..\`: "invalid volume specification: ", - `c:\:..\`: "invalid volume specification: ", - `c:\:d:\:xyzzy`: "invalid volume specification: ", - `c:`: "cannot be `c:`", - `c:\`: "cannot be `c:`", - `c:\notexist:d:`: `source path does not exist`, - `c:\windows\system32\ntdll.dll:d:`: `source path must be a directory`, - `name<:d:`: `invalid volume specification`, - `name>:d:`: `invalid volume specification`, - `name::d:`: `invalid volume specification`, - `name":d:`: `invalid volume specification`, - `name\:d:`: `invalid volume specification`, - `name*:d:`: `invalid volume specification`, - `name|:d:`: `invalid volume specification`, - `name?:d:`: `invalid volume specification`, - `name/:d:`: `invalid volume specification`, - `d:\pathandmode:rw`: `invalid volume specification`, - `con:d:`: `cannot be a reserved word for Windows filenames`, - `PRN:d:`: `cannot be a reserved word for Windows filenames`, - `aUx:d:`: `cannot be a reserved word for Windows filenames`, - `nul:d:`: `cannot be a reserved word for Windows filenames`, - `com1:d:`: `cannot be a reserved word for Windows filenames`, - `com2:d:`: `cannot be a reserved word for Windows filenames`, - `com3:d:`: `cannot be a reserved word for Windows filenames`, - `com4:d:`: `cannot be a reserved word for Windows filenames`, - `com5:d:`: `cannot be a reserved word for Windows filenames`, - `com6:d:`: `cannot be a reserved word for Windows filenames`, - `com7:d:`: `cannot be a reserved word for Windows filenames`, - `com8:d:`: `cannot be a reserved word for Windows filenames`, - `com9:d:`: `cannot be a reserved word for Windows filenames`, - `lpt1:d:`: `cannot be a reserved word for Windows filenames`, - `lpt2:d:`: `cannot be a reserved word for Windows filenames`, - `lpt3:d:`: `cannot be a reserved word for Windows filenames`, - `lpt4:d:`: `cannot be a reserved word for Windows filenames`, - `lpt5:d:`: `cannot be a reserved word for Windows filenames`, - `lpt6:d:`: `cannot be a reserved word for Windows filenames`, - `lpt7:d:`: `cannot be a reserved word for Windows filenames`, - `lpt8:d:`: `cannot be a reserved word for Windows filenames`, - `lpt9:d:`: `cannot be a reserved word for Windows filenames`, - `c:\windows\system32\ntdll.dll`: `Only directories can be mapped on this platform`, - } - - } else { - valid = []string{ - "/home", - "/home:/home", - "/home:/something/else", - "/with space", - "/home:/with space", - "relative:/absolute-path", - "hostPath:/containerPath:ro", - "/hostPath:/containerPath:rw", - "/rw:/ro", - } - invalid = map[string]string{ - "": "invalid volume specification", - "./": "mount path must be absolute", - "../": "mount path must be absolute", - "/:../": "mount path must be absolute", - "/:path": "mount path must be absolute", - ":": "invalid volume specification", - "/tmp:": "invalid volume specification", - ":test": "invalid volume specification", - ":/test": "invalid volume specification", - "tmp:": "invalid volume specification", - ":test:": "invalid volume specification", - "::": "invalid volume specification", - ":::": "invalid volume specification", - "/tmp:::": "invalid volume specification", - ":/tmp::": "invalid volume specification", - "/path:rw": "invalid volume specification", - "/path:ro": "invalid volume specification", - "/rw:rw": "invalid volume specification", - "path:ro": "invalid volume specification", - "/path:/path:sw": `invalid mode`, - "/path:/path:rwz": `invalid mode`, - } - } - - for _, path := range valid { - if _, err := ParseMountRaw(path, "local"); err != nil { - t.Fatalf("ParseMountRaw(`%q`) should succeed: error %q", path, err) - } - } - - for path, expectedError := range invalid { - if mp, err := ParseMountRaw(path, "local"); err == nil { - t.Fatalf("ParseMountRaw(`%q`) should have failed validation. Err '%v' - MP: %v", path, err, mp) - } else { - if !strings.Contains(err.Error(), expectedError) { - t.Fatalf("ParseMountRaw(`%q`) error should contain %q, got %v", path, expectedError, err.Error()) - } - } - } -} - -// testParseMountRaw is a structure used by TestParseMountRawSplit for -// specifying test cases for the ParseMountRaw() function. -type testParseMountRaw struct { - bind string - driver string - expDest string - expSource string - expName string - expDriver string - expRW bool - fail bool -} - -func TestParseMountRawSplit(t *testing.T) { - var cases []testParseMountRaw - if runtime.GOOS == "windows" { - cases = []testParseMountRaw{ - {`c:\:d:`, "local", `d:`, `c:\`, ``, "", true, false}, - {`c:\:d:\`, "local", `d:\`, `c:\`, ``, "", true, false}, - // TODO Windows post TP5 - Add readonly support {`c:\:d:\:ro`, "local", `d:\`, `c:\`, ``, "", false, false}, - {`c:\:d:\:rw`, "local", `d:\`, `c:\`, ``, "", true, false}, - {`c:\:d:\:foo`, "local", `d:\`, `c:\`, ``, "", false, true}, - {`name:d::rw`, "local", `d:`, ``, `name`, "local", true, false}, - {`name:d:`, "local", `d:`, ``, `name`, "local", true, false}, - // TODO Windows post TP5 - Add readonly support {`name:d::ro`, "local", `d:`, ``, `name`, "local", false, false}, - {`name:c:`, "", ``, ``, ``, "", true, true}, - {`driver/name:c:`, "", ``, ``, ``, "", true, true}, - } - } else { - cases = []testParseMountRaw{ - {"/tmp:/tmp1", "", "/tmp1", "/tmp", "", "", true, false}, - {"/tmp:/tmp2:ro", "", "/tmp2", "/tmp", "", "", false, false}, - {"/tmp:/tmp3:rw", "", "/tmp3", "/tmp", "", "", true, false}, - {"/tmp:/tmp4:foo", "", "", "", "", "", false, true}, - {"name:/named1", "", "/named1", "", "name", "", true, false}, - {"name:/named2", "external", "/named2", "", "name", "external", true, false}, - {"name:/named3:ro", "local", "/named3", "", "name", "local", false, false}, - {"local/name:/tmp:rw", "", "/tmp", "", "local/name", "", true, false}, - {"/tmp:tmp", "", "", "", "", "", true, true}, - } - } - - for i, c := range cases { - t.Logf("case %d", i) - m, err := ParseMountRaw(c.bind, c.driver) - if c.fail { - if err == nil { - t.Fatalf("Expected error, was nil, for spec %s\n", c.bind) - } - continue - } - - if m == nil || err != nil { - t.Fatalf("ParseMountRaw failed for spec '%s', driver '%s', error '%v'", c.bind, c.driver, err.Error()) - continue - } - - if m.Destination != c.expDest { - t.Fatalf("Expected destination '%s, was %s', for spec '%s'", c.expDest, m.Destination, c.bind) - } - - if m.Source != c.expSource { - t.Fatalf("Expected source '%s', was '%s', for spec '%s'", c.expSource, m.Source, c.bind) - } - - if m.Name != c.expName { - t.Fatalf("Expected name '%s', was '%s' for spec '%s'", c.expName, m.Name, c.bind) - } - - if m.Driver != c.expDriver { - t.Fatalf("Expected driver '%s', was '%s', for spec '%s'", c.expDriver, m.Driver, c.bind) - } - - if m.RW != c.expRW { - t.Fatalf("Expected RW '%v', was '%v' for spec '%s'", c.expRW, m.RW, c.bind) - } - } -} - -func TestParseMountSpec(t *testing.T) { - type c struct { - input mount.Mount - expected MountPoint - } - testDir, err := ioutil.TempDir("", "test-mount-config") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(testDir) - - cases := []c{ - {mount.Mount{Type: mount.TypeBind, Source: testDir, Target: testDestinationPath, ReadOnly: true}, MountPoint{Type: mount.TypeBind, Source: testDir, Destination: testDestinationPath}}, - {mount.Mount{Type: mount.TypeBind, Source: testDir, Target: testDestinationPath}, MountPoint{Type: mount.TypeBind, Source: testDir, Destination: testDestinationPath, RW: true}}, - {mount.Mount{Type: mount.TypeBind, Source: testDir + string(os.PathSeparator), Target: testDestinationPath, ReadOnly: true}, MountPoint{Type: mount.TypeBind, Source: testDir, Destination: testDestinationPath}}, - {mount.Mount{Type: mount.TypeBind, Source: testDir, Target: testDestinationPath + string(os.PathSeparator), ReadOnly: true}, MountPoint{Type: mount.TypeBind, Source: testDir, Destination: testDestinationPath}}, - {mount.Mount{Type: mount.TypeVolume, Target: testDestinationPath}, MountPoint{Type: mount.TypeVolume, Destination: testDestinationPath, RW: true, CopyData: DefaultCopyMode}}, - {mount.Mount{Type: mount.TypeVolume, Target: testDestinationPath + string(os.PathSeparator)}, MountPoint{Type: mount.TypeVolume, Destination: testDestinationPath, RW: true, CopyData: DefaultCopyMode}}, - } - - for i, c := range cases { - t.Logf("case %d", i) - mp, err := ParseMountSpec(c.input) - if err != nil { - t.Fatal(err) - } - - if c.expected.Type != mp.Type { - t.Fatalf("Expected mount types to match. Expected: '%s', Actual: '%s'", c.expected.Type, mp.Type) - } - if c.expected.Destination != mp.Destination { - t.Fatalf("Expected mount destination to match. Expected: '%s', Actual: '%s'", c.expected.Destination, mp.Destination) - } - if c.expected.Source != mp.Source { - t.Fatalf("Expected mount source to match. Expected: '%s', Actual: '%s'", c.expected.Source, mp.Source) - } - if c.expected.RW != mp.RW { - t.Fatalf("Expected mount writable to match. Expected: '%v', Actual: '%v'", c.expected.RW, mp.RW) - } - if c.expected.Propagation != mp.Propagation { - t.Fatalf("Expected mount propagation to match. Expected: '%v', Actual: '%s'", c.expected.Propagation, mp.Propagation) - } - if c.expected.Driver != mp.Driver { - t.Fatalf("Expected mount driver to match. Expected: '%v', Actual: '%s'", c.expected.Driver, mp.Driver) - } - if c.expected.CopyData != mp.CopyData { - t.Fatalf("Expected mount copy data to match. Expected: '%v', Actual: '%v'", c.expected.CopyData, mp.CopyData) - } - } -} diff --git a/vendor/github.com/docker/docker/volume/volume_unix.go b/vendor/github.com/docker/docker/volume/volume_unix.go deleted file mode 100644 index 0256ebb..0000000 --- a/vendor/github.com/docker/docker/volume/volume_unix.go +++ /dev/null @@ -1,138 +0,0 @@ -// +build linux freebsd darwin solaris - -package volume - -import ( - "fmt" - "os" - "path/filepath" - "strings" - - mounttypes "github.com/docker/docker/api/types/mount" -) - -var platformRawValidationOpts = []func(o *validateOpts){ - // need to make sure to not error out if the bind source does not exist on unix - // this is supported for historical reasons, the path will be automatically - // created later. - func(o *validateOpts) { o.skipBindSourceCheck = true }, -} - -// read-write modes -var rwModes = map[string]bool{ - "rw": true, - "ro": true, -} - -// label modes -var labelModes = map[string]bool{ - "Z": true, - "z": true, -} - -// BackwardsCompatible decides whether this mount point can be -// used in old versions of Docker or not. -// Only bind mounts and local volumes can be used in old versions of Docker. -func (m *MountPoint) BackwardsCompatible() bool { - return len(m.Source) > 0 || m.Driver == DefaultDriverName -} - -// HasResource checks whether the given absolute path for a container is in -// this mount point. If the relative path starts with `../` then the resource -// is outside of this mount point, but we can't simply check for this prefix -// because it misses `..` which is also outside of the mount, so check both. -func (m *MountPoint) HasResource(absolutePath string) bool { - relPath, err := filepath.Rel(m.Destination, absolutePath) - return err == nil && relPath != ".." && !strings.HasPrefix(relPath, fmt.Sprintf("..%c", filepath.Separator)) -} - -// IsVolumeNameValid checks a volume name in a platform specific manner. -func IsVolumeNameValid(name string) (bool, error) { - return true, nil -} - -// ValidMountMode will make sure the mount mode is valid. -// returns if it's a valid mount mode or not. -func ValidMountMode(mode string) bool { - if mode == "" { - return true - } - - rwModeCount := 0 - labelModeCount := 0 - propagationModeCount := 0 - copyModeCount := 0 - - for _, o := range strings.Split(mode, ",") { - switch { - case rwModes[o]: - rwModeCount++ - case labelModes[o]: - labelModeCount++ - case propagationModes[mounttypes.Propagation(o)]: - propagationModeCount++ - case copyModeExists(o): - copyModeCount++ - default: - return false - } - } - - // Only one string for each mode is allowed. - if rwModeCount > 1 || labelModeCount > 1 || propagationModeCount > 1 || copyModeCount > 1 { - return false - } - return true -} - -// ReadWrite tells you if a mode string is a valid read-write mode or not. -// If there are no specifications w.r.t read write mode, then by default -// it returns true. -func ReadWrite(mode string) bool { - if !ValidMountMode(mode) { - return false - } - - for _, o := range strings.Split(mode, ",") { - if o == "ro" { - return false - } - } - return true -} - -func validateNotRoot(p string) error { - p = filepath.Clean(convertSlash(p)) - if p == "/" { - return fmt.Errorf("invalid specification: destination can't be '/'") - } - return nil -} - -func validateCopyMode(mode bool) error { - return nil -} - -func convertSlash(p string) string { - return filepath.ToSlash(p) -} - -func splitRawSpec(raw string) ([]string, error) { - if strings.Count(raw, ":") > 2 { - return nil, errInvalidSpec(raw) - } - - arr := strings.SplitN(raw, ":", 3) - if arr[0] == "" { - return nil, errInvalidSpec(raw) - } - return arr, nil -} - -func clean(p string) string { - return filepath.Clean(p) -} - -func validateStat(fi os.FileInfo) error { - return nil -} diff --git a/vendor/github.com/docker/docker/volume/volume_unsupported.go b/vendor/github.com/docker/docker/volume/volume_unsupported.go deleted file mode 100644 index ff9d6af..0000000 --- a/vendor/github.com/docker/docker/volume/volume_unsupported.go +++ /dev/null @@ -1,16 +0,0 @@ -// +build !linux - -package volume - -import ( - "fmt" - "runtime" - - mounttypes "github.com/docker/docker/api/types/mount" -) - -// ConvertTmpfsOptions converts *mounttypes.TmpfsOptions to the raw option string -// for mount(2). -func ConvertTmpfsOptions(opt *mounttypes.TmpfsOptions, readOnly bool) (string, error) { - return "", fmt.Errorf("%s does not support tmpfs", runtime.GOOS) -} diff --git a/vendor/github.com/docker/docker/volume/volume_windows.go b/vendor/github.com/docker/docker/volume/volume_windows.go deleted file mode 100644 index 22f6fc7..0000000 --- a/vendor/github.com/docker/docker/volume/volume_windows.go +++ /dev/null @@ -1,201 +0,0 @@ -package volume - -import ( - "fmt" - "os" - "path/filepath" - "regexp" - "strings" -) - -// read-write modes -var rwModes = map[string]bool{ - "rw": true, -} - -// read-only modes -var roModes = map[string]bool{ - "ro": true, -} - -var platformRawValidationOpts = []func(*validateOpts){ - // filepath.IsAbs is weird on Windows: - // `c:` is not considered an absolute path - // `c:\` is considered an absolute path - // In any case, the regex matching below ensures absolute paths - // TODO: consider this a bug with filepath.IsAbs (?) - func(o *validateOpts) { o.skipAbsolutePathCheck = true }, -} - -const ( - // Spec should be in the format [source:]destination[:mode] - // - // Examples: c:\foo bar:d:rw - // c:\foo:d:\bar - // myname:d: - // d:\ - // - // Explanation of this regex! Thanks @thaJeztah on IRC and gist for help. See - // https://gist.github.com/thaJeztah/6185659e4978789fb2b2. A good place to - // test is https://regex-golang.appspot.com/assets/html/index.html - // - // Useful link for referencing named capturing groups: - // http://stackoverflow.com/questions/20750843/using-named-matches-from-go-regex - // - // There are three match groups: source, destination and mode. - // - - // RXHostDir is the first option of a source - RXHostDir = `[a-z]:\\(?:[^\\/:*?"<>|\r\n]+\\?)*` - // RXName is the second option of a source - RXName = `[^\\/:*?"<>|\r\n]+` - // RXReservedNames are reserved names not possible on Windows - RXReservedNames = `(con)|(prn)|(nul)|(aux)|(com[1-9])|(lpt[1-9])` - - // RXSource is the combined possibilities for a source - RXSource = `((?P((` + RXHostDir + `)|(` + RXName + `))):)?` - - // Source. Can be either a host directory, a name, or omitted: - // HostDir: - // - Essentially using the folder solution from - // https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch08s18.html - // but adding case insensitivity. - // - Must be an absolute path such as c:\path - // - Can include spaces such as `c:\program files` - // - And then followed by a colon which is not in the capture group - // - And can be optional - // Name: - // - Must not contain invalid NTFS filename characters (https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx) - // - And then followed by a colon which is not in the capture group - // - And can be optional - - // RXDestination is the regex expression for the mount destination - RXDestination = `(?P([a-z]):((?:\\[^\\/:*?"<>\r\n]+)*\\?))` - // Destination (aka container path): - // - Variation on hostdir but can be a drive followed by colon as well - // - If a path, must be absolute. Can include spaces - // - Drive cannot be c: (explicitly checked in code, not RegEx) - - // RXMode is the regex expression for the mode of the mount - // Mode (optional): - // - Hopefully self explanatory in comparison to above regex's. - // - Colon is not in the capture group - RXMode = `(:(?P(?i)ro|rw))?` -) - -// BackwardsCompatible decides whether this mount point can be -// used in old versions of Docker or not. -// Windows volumes are never backwards compatible. -func (m *MountPoint) BackwardsCompatible() bool { - return false -} - -func splitRawSpec(raw string) ([]string, error) { - specExp := regexp.MustCompile(`^` + RXSource + RXDestination + RXMode + `$`) - match := specExp.FindStringSubmatch(strings.ToLower(raw)) - - // Must have something back - if len(match) == 0 { - return nil, errInvalidSpec(raw) - } - - var split []string - matchgroups := make(map[string]string) - // Pull out the sub expressions from the named capture groups - for i, name := range specExp.SubexpNames() { - matchgroups[name] = strings.ToLower(match[i]) - } - if source, exists := matchgroups["source"]; exists { - if source != "" { - split = append(split, source) - } - } - if destination, exists := matchgroups["destination"]; exists { - if destination != "" { - split = append(split, destination) - } - } - if mode, exists := matchgroups["mode"]; exists { - if mode != "" { - split = append(split, mode) - } - } - // Fix #26329. If the destination appears to be a file, and the source is null, - // it may be because we've fallen through the possible naming regex and hit a - // situation where the user intention was to map a file into a container through - // a local volume, but this is not supported by the platform. - if matchgroups["source"] == "" && matchgroups["destination"] != "" { - validName, err := IsVolumeNameValid(matchgroups["destination"]) - if err != nil { - return nil, err - } - if !validName { - if fi, err := os.Stat(matchgroups["destination"]); err == nil { - if !fi.IsDir() { - return nil, fmt.Errorf("file '%s' cannot be mapped. Only directories can be mapped on this platform", matchgroups["destination"]) - } - } - } - } - return split, nil -} - -// IsVolumeNameValid checks a volume name in a platform specific manner. -func IsVolumeNameValid(name string) (bool, error) { - nameExp := regexp.MustCompile(`^` + RXName + `$`) - if !nameExp.MatchString(name) { - return false, nil - } - nameExp = regexp.MustCompile(`^` + RXReservedNames + `$`) - if nameExp.MatchString(name) { - return false, fmt.Errorf("volume name %q cannot be a reserved word for Windows filenames", name) - } - return true, nil -} - -// ValidMountMode will make sure the mount mode is valid. -// returns if it's a valid mount mode or not. -func ValidMountMode(mode string) bool { - if mode == "" { - return true - } - return roModes[strings.ToLower(mode)] || rwModes[strings.ToLower(mode)] -} - -// ReadWrite tells you if a mode string is a valid read-write mode or not. -func ReadWrite(mode string) bool { - return rwModes[strings.ToLower(mode)] || mode == "" -} - -func validateNotRoot(p string) error { - p = strings.ToLower(convertSlash(p)) - if p == "c:" || p == `c:\` { - return fmt.Errorf("destination path cannot be `c:` or `c:\\`: %v", p) - } - return nil -} - -func validateCopyMode(mode bool) error { - if mode { - return fmt.Errorf("Windows does not support copying image path content") - } - return nil -} - -func convertSlash(p string) string { - return filepath.FromSlash(p) -} - -func clean(p string) string { - if match, _ := regexp.MatchString("^[a-z]:$", p); match { - return p - } - return filepath.Clean(p) -} - -func validateStat(fi os.FileInfo) error { - if !fi.IsDir() { - return fmt.Errorf("source path must be a directory") - } - return nil -} diff --git a/vendor/github.com/docker/machine/.dockerignore b/vendor/github.com/docker/machine/.dockerignore deleted file mode 100644 index 4a7598c..0000000 --- a/vendor/github.com/docker/machine/.dockerignore +++ /dev/null @@ -1,4 +0,0 @@ -docker-machine* -*.log -bin -cover \ No newline at end of file diff --git a/vendor/github.com/docker/machine/.gitignore b/vendor/github.com/docker/machine/.gitignore deleted file mode 100644 index 2c63e10..0000000 --- a/vendor/github.com/docker/machine/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -docker-machine* -*.log -*.iml -.idea/ -./bin -cover diff --git a/vendor/github.com/docker/machine/.godir b/vendor/github.com/docker/machine/.godir deleted file mode 100644 index 38ee32e..0000000 --- a/vendor/github.com/docker/machine/.godir +++ /dev/null @@ -1 +0,0 @@ -github.com/docker/machine diff --git a/vendor/github.com/docker/machine/.travis.yml b/vendor/github.com/docker/machine/.travis.yml deleted file mode 100644 index 9c30fd1..0000000 --- a/vendor/github.com/docker/machine/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -sudo: required -dist: trusty -language: bash -services: docker -env: - matrix: - - TARGET_OS=linux TARGET_ARCH=amd64 TARGETS="build validate" - - TARGET_OS=darwin TARGET_ARCH=amd64 TARGETS="build-x" - - TARGET_OS=windows TARGET_ARCH=amd64 TARGETS="build-x" - - TARGET_OS=linux TARGET_ARCH=arm TARGETS="build-x" - - TARGET_OS=linux TARGET_ARCH=arm64 TARGETS="build-x" -script: - - USE_CONTAINER=true make "$TARGETS" - - "[[ \"$(find bin -type f -name docker-machine*)\" != \"\" ]]" diff --git a/vendor/github.com/docker/machine/CHANGELOG.md b/vendor/github.com/docker/machine/CHANGELOG.md deleted file mode 100644 index 2adadc2..0000000 --- a/vendor/github.com/docker/machine/CHANGELOG.md +++ /dev/null @@ -1,791 +0,0 @@ -# Changelog - -# 0.13.0 (2017-10-12) - -General - -- Added new `docker-machine mount` command for mounting machine directories over SSHFS -- Improved some logging messages -- Fixed a bug with the `scp` command when using an identity file. --Fixed a parsing error that caused the boot2docker ISO cache to malfunction, forcing a new download everytime. - -Drivers - -- `azure` - - `docker-machine rm` now also cleans up the associated storage account if it has no remaining storage containers. - - The creation process will no longer recreate the associated subnet if it already it exists. -- `exoscale` - - Updated driver - - Removed default `docker-machine` affinity group if no other affinity group was specified -- `virtualbox` - - Fixed a bug where the machine would sometimes be assigned an invalid IP address at creation time. --`vmwaresphere` - - Added support for multiple networks - -# 0.12.2 (2017-7-12) - -General - -* The `scp` sub-command now allows to provide an optional `user@` to the address. -* Fixed bash completion on OS X - -Drivers - -* `amazonec2` - * Updated default AMIs to the latest version of Ubuntu 16.04 LTS - * Fixed a bug preventing proper machine removal -* `vmwarevsphere` - * Creating VMs on a DRS-enabled cluster should now work properly - * Fixed a bug that prevented provisioning -* `vmwarefusion` - * Fixed a bug that prevented provisioning -* `exoscale` - * Updated library - -# 0.12.1 (2017-6-30) - -General - -- Fixed an issue with the version comparison function that prevented machines created with Engine 17.06.0 from starting properly. - -# 0.12.0 (2017-6-5) - -General - -- Various bash completion improvements -- Bump Go to version 1.8.3 - -Drivers - -- `openstack` - - Enable `HTTP_PROXY` -- `digitalocean` - - Add support for tagging -- `virtualbox` - - Scope DHCP address range based on CIDR -- `generic` - - Increase default timeout -- `google` - - Add subnetwork support - -Provisioners - -- Remove restriction on `--engine-install-url` in default-to-boot2docker drivers (`virtualbox`, `vmwarefusion`, etc.) -- Reduce provisioning time of SUSE/openSUSE systems - -# 0.11.0 (2017-4-25) - -General - -- Various bugfixes and updated library dependencies -- new `docker-machine scp --delta` to invoke `rsync` behind the scenes for more efficient transfer - -Drivers - -- `digitalocean` - - Add support for tagging DigitalOcean instances. -- `google` - - Add support for subnetworks - -# 0.10.0 (2017-2-27) - -General - -- Various improvements to shell tab completion -- Add support for compiling on ARM64 architecture - -Drivers - -- Make `virtualbox` default driver -- `amazonec2` - - Update AMIs to latest version of Ubuntu 16.04 LTS -- `virtualbox` - - Fix parsing of `--virtualbox-share-folder` on Windows -- `google` - - Add `--google-open-port` flag to specify additional ports to open - -Provisioners - -- Machine now uses systemd drop-in files instead of over-writing the system units -- Add support for upgrade to new Docker versioning scheme -- Use `dockerd` only in Docker versions where it is available -- Support multiple architectures in SUSE provisioner - -# 0.9.0 (2017-1-17) - -General -- On Windows, the `COMPOSE_CONVERT_WINDOWS_PATHS` environment variable is now set by `docker-machine env` to improve Compose usability. -- Docker Machine can now be built on FreeBSD -- `docker-machine scp` non-22 port support -- `scp` supports SSH agent -- Bump Go version to 1.7.4 - -Drivers -- `amazonec2` - - Credentials can now be loaded from IAM instance profiles - - Add `--amazonec2-userdata` flag - - Add `--amazonec2-block-duration-minutes` flag - - Add support for `us-east-2` (Ohio) - - Update base images to Ubuntu 16.04 -- `azure` - - Add `--azure-dns` flag for specifying DNS names - - Add `--azure-storage-type` flag - - Allow using vnets from another resource group - - Add AzureGermanCloud support - - Add support for custom data - - Support Service Principal authentication - - Update base images to Ubuntu 16.04 -- `digitalocean` - - Add ability to speicify the private SSH key path -- `gce` - - Update base images to Ubuntu 16.04 -- `virtualbox` - - Shared folder location can be specified instead of "hardcoded" to `C:\Users` or `/Users` -- `openstack` - - Add support for `OS_CACERT` - -Provisioners -- OpenSUSE provisioner refactored to use properly supported 3rd party code - - -# 0.8.2 (2016-8-26) - -- Update Go version to 1.7.1 - -# 0.8.1 (2016-8-20) - -Provisioners -- Fix issue with generated systemd service file on RedHat family distros -Drivers -- `azure` - - Bump Ubuntu image to 16.04 - - Update docs with updated default parameters - - Change logging slightly - -# 0.8.0 (2016-6-14) - -General -- Fix issue with plugin heartbeat log repeating on disconnect -- Add `tcsh` support to `env --shell` -- Add `zsh` completion scripts -- Bump Go version to 1.6.2 - -Drivers -- `amazonec2` - - Workaround to prevent orphaned SSH keys -- `virtualbox` - - Add option for VM UI type (`--virtualbox-ui-type`) -- `vmwarefusion` - - Fix CPU option inconsistency -- `openstack` - - Expose user data parameter (`--openstack-user-data-file`) -- `generic` - - Copy public key to created Machine directory - -Provisioners -- Add Oracle Enterprise Linux support -- Fix port binding of Swarm master -- Add ability to create a manager instance which does not get scheduled on -- Introduce `--swarm-join-opt` to pass options to agent nodes -- Various SSH-related fixes -- Fix state for upgrade path - -# 0.7.0 (2016-4-13) - -General -- `DRIVER` environment variable now supported to supply value for `create --driver` flag -- Update to Go 1.6.1 -- SSH client has been refactored -- RC versions of Machine will now create and upgrade to boot2docker RCs instead - of stable versions if available - -Drivers -- `azure` - - Driver has been completely re-written to use resource templates and a significantly easier-to-use authentication model -- `digitalocean` - - New `--digitalocean-ssh-key-fingerprint` for using existing SSH keys instead of creating new ones -- `virtualbox` - - Fix issue with `bootlocal.sh` - - New `--virtualbox-nictype` flag to set driver for NAT network - - More robust host-only interface collision detection - - Add support for running VirtualBox on a Windows 32 bit host - - Change default DNS passthrough handling -- `amazonec2` - - Specifying multiple security groups to use is now supported -- `exoscale` - - Add support for user-data -- `hyperv` - - Machines can now be created by a non-administrator -- `rackspace` - - New `--rackspace-active-timeout` parameter -- `vmwarefusion` - - Bind mount shared folder directory by default -- `google` - - New `--google-use-internal-ip-only` parameter - -Provisioners -- General - - Support for specifying Docker engine port in some cases -- CentOS - - Now defaults to using upstream `get.docker.com` script instead of custom RPMs. -- boot2docker - - More robust eth* interface detection -- Swarm - - Add `--swarm-experimental` parameter to enable experimental Swarm features - - -# 0.6.0 (2016-02-04) - -+ Fix SSH wait before provisioning issue - -# 0.6.0-rc4 (2016-02-03) - -General - -+ `env` - + Fix shell auto detection - -Drivers - -+ `exoscale` - + Fix configuration of exoscale endpoint - -# 0.6.0-rc3 (2016-02-01) - -- Exit with code 3 if error is during pre-create check - -# 0.6.0-rc2 (2016-01-28) - -- Fix issue creating Swarms -- Fix `ls` header issue -- Add code to wait for Docker daemon before returning from `start` / `restart` -- Start porting integration tests to Go from BATS -- Add Appveyor for Windows tests -- Update CoreOS provisioner to use `docker daemon` -- Various documentation and error message fixes -- Add ability to create GCE machine using existing VM - -# 0.6.0-rc1 (2016-01-18) - -General - -- Update to Go 1.5.3 -- Short form of command invocations is now supported - - `docker-machine start`, `docker-machine stop` and others will now use - `default` as the machine name argument if one is not specified -- Fix issue with panics in drivers -- Machine now returns exit code 3 if the pre-create check fails. - - This is potentially useful for scripting `docker-machine`. -- `docker-machine provision` command added to allow re-running of provisioning - on instances. - - This allows users to re-run provisioning if it fails during `create` - instead of needing to completely start over. - -Provisioning - -- Most provisioners now use `docker daemon` instead of `docker -d` -- Swarm masters now run with replication enabled -- If `/var/lib` is a BTRFS partition, `btrfs` will now be used as the storage - driver for the instance - -Drivers - -- Amazon EC2 - - Default VPC will be used automatically if none is specified - - Credentials are now be read from the conventional `~/.aws/credentials` - file automatically - - Fix a few issues such as nil pointer dereferences -- VMware Fusion - - Try to get IP from multiple DHCP lease files -- OpenStack - - Only derive tenant ID if tenant name is supplied - -# 0.5.6 (2016-01-11) - -General - -- `create` - - Set swarm master to advertise on port 3376 - - Fix swarm restart policy - - Stop asking for ssh key passwords interactively -- `env` - - Improve documentation - - Fix bash on windows - - Automatic shell detection on Windows -- `help` - - Don't show the full path to `docker-machine.exe` on windows -- `ls` - - Allow custom format - - Improve documentation -- `restart` - - Improve documentation -- `rm` - - Improve documentation - - Better user experience when removing multiple hosts -- `version` - - Don't show the full path to `docker-machine.exe` on windows -- `start`, `stop`, `restart`, `kill` - - Better logs and homogeneous behaviour across all drivers - -Build - -- Introduce CI tests for external binary compatibility -- Add amazon EC2 integration test - -Misc - -- Improve BugSnags reports: better shell detection, better windows version detection -- Update DockerClient dependency -- Improve bash-completion script -- Improve documentation for bash-completion - -Drivers - -- Amazon EC2 - - Improve documentation - - Support optional tags - - Option to create EbsOptimized instances -- Google - - Fix remove when instance is stopped -- Openstack - - Flags to import and reuse existing nova keypairs -- VirtualBox - - Fix multiple bugs related to host-only adapters - - Retry commands when `VBoxManage` is not ready - - Reject VirtualBox versions older that 4.3 - - Fail with a clear message when Hyper-v installation prevents VirtualBox from working - - Print a warning for Boot2Docker v1.9.1, which is known to have an issue with AUFS -- Vmware Fusion - - Support soft links in VM paths - -Libmachine - -- Fix code sample that uses libmachine -- libmachine can be used in external applications - - -# 0.5.5 (2015-12-28) - -General - -- `env` - - Better error message if swarm is down - - Add quotes to command if there are spaces in the path - - Fix Powershell env hints - - Default to cmd shell on windows - - Detect fish shell -- `scp` - - Ignore empty ssh key -- `stop`, `start`, `kill` - - Add feedback to the user -- `rm` - - Now works when `config.json` is not found -- `ssh` - - Disable ControlPath - - Log which SSH client is used -- `ls` - - Listing is now faster by reducing calls to the driver - - Shows if the active machine is a swarm cluster - -Build - -- Automate 90% of the release process -- Upgrade to Go 1.5.2 -- Don't build 32bits binaries for Linux and OSX -- Prevent makefile from defaulting to using containers - -Misc - -- Update docker-machine version -- Updated the bash completion with new options added -- Bugsnag: Retrieve windows version on non-English OS - -Drivers - -- Amazon EC2 - - Convert API calls to official SDK - - Make DeviceName configurable -- Digital Ocean - - Custom SSH port support -- Generic - - Don't support `kill` since `stop` is not supported -- Google - - Coreos provisionning -- Hyper-V - - Lot's of code simplifications - - Pre-Check that the user is an Administrator - - Pre-Check that the virtual switch exists - - Add Environment variables for each flag - - Fix how Powershell is detected - - VSwitch name should be saved to config.json - - Add a flag to set the CPU count - - Close handle after copying boot2docker.iso into vm folder - will otherwise keep hyper-v from starting vm - - Update Boot2Docker cache in PreCreateCheck phase -- OpenStack - - Filter floating IPs by tenant ID -- Virtualbox - - Reject duplicate hostonlyifs Name/IP with clear message - - Detect when hostonlyif can't be created. Point to known working version of VirtualBox - - Don't create the VM if no hardware virtualization is available and add a flag to force create - - Add `VBox.log` to bugsnag crashreport - - Update Boot2Docker cache in PreCreateCheck phase - - Detect Incompatibility with Hyper-v -- VSphere - - Rewrite driver to work with govmomi instead of wrapping govc -- All - - Change host restart to use the driver implementation - - Fix truncated logs - - Increase heartbeat interval and timeout - -Provisioners - -- Download latest Boot2Docker if it is out-of-date -- Add swarm config to coreos -- All provisioners now honor `engine-install-url` - -# 0.5.4 (2015-12-28) - -This is a patch release to fix a regression with STDOUT/STDERR behavior (#2587). - -# 0.5.3 (2015-12-14) - -**Please note**: With this release Machine will be reverting back to distribution in a single binary, which is more efficient on bandwidth and hard disk space. All the core driver plugins are now included in the main binary. You will want to delete the old driver binaries that you might have in your path. - -e.g.: - -```console -$ rm /usr/local/bin/docker-machine-driver-{amazonec2,azure,digitalocean,exoscale,generic,google,hyperv,none,openstack,rackspace,softlayer,virtualbox,vmwarefusion,vmwarevcloudair,vmwarevsphere} -``` - -Non-core driver plugins should still work as intended (in externally distributed binaries of the form `docker-machine-driver-name`. Please report any issues you encounter them with externally loaded plugins. - -General - -- Optionally report crashes to Bugsnag to help us improve docker-machine -- Fix multiple nil dereferences in `docker-machine ls` command -- Improve the build and CI -- `docker-machine env` now supports emacs -- Run Swarm containers in provisioning step using Docker API instead of SSH/shell -- Show docker daemon version in `docker-machine ls` -- `docker-machine ls` can filter by engine label -- `docker-machine ls` filters are case insensitive -- `--timeout` flag for `docker-machine ls` -- Logs use `logrus` library -- Swarm container network is now `host` -- Added advertise flag to Swarm manager template -- Fix `help` flag for `docker-machine ssh` -- Add confirmation `-y` flag to `docker-machine rm` -- Fix `docker-machine config` for fish -- Embed all core drivers in `docker-machine` binary to reduce the bundle from 120M to 15M - -Drivers - -- Generic - - Support password protected ssh keys though ssh-agent - - Support DNS names -- Virtualbox - - Show a warning if virtualbox is too old - - Recognize yet another Hardware Virtualization issue pattern - - Fix Hardware Virtualization on Linux/AMD - - Add the `--virtualbox-host-dns-resolver` flag - - Allow virtualbox DNSProxy override -- Google - - Open firewall port for Swarm when needed -- VMware Fusion - - Explicitly set umask before invoking vmrun in vmwarefusion - - Activate the plugin only on OSX - - Add id/gid option to mount when using vmhgfs - - Fix for vSphere driver boot2docker ISO issues -- Digital Ocean - - Support for creating Droplets with Cloud-init User Data -- Openstack - - Sanitize keynames by replacing dots with underscores -- All - - Most base images are now set to `Ubuntu 15.10` - - Fix compatibility with drivers developed with docker-machine 0.5.0 - - Better error report for broken/incompatible drivers - - Don't break `config.json` configuration when the disk is full - -Provisioners - -- Increase timeout for installing boot2docker -- Support `Ubuntu 15.10` - -Misc - -- Improve the documentation -- Update known drivers list - -# 0.5.2 (2015-11-30) - -General - -- Bash autocompletion and helpers fixed -- Remove `RawDriver` from `config.json` - Driver parameters can now be edited - directly again in this file. -- Change fish `env` variable setting to be global -- Add `docker-machine version` command -- Move back to normal `codegangsta/cli` upstream -- `--tls-san` flag for extra SANs - -Drivers - -- Fix `GetURL` IPv6 compatibility -- Add documentation page for available 3rd party drivers -- VirtualBox - - Support for shared folders and virtualization detection on Linux hosts - - Improved detection of invalid host-only interface settings -- Google - - Update default images -- VMware Fusion - - Add option to disable shared folder -- Generic - - New environment variables for flags - -Provisioners - -- Support for Ubuntu >=15.04. This means Ubuntu machines can be created which - work with `overlay` driver of lib network. -- Fix issue with current netstat / daemon availability checking - -# 0.5.1 (2015-11-16) - -- Fixed boot2docker VM import regression -- Fix regression breaking `docker-machine env -u` to unset environment variables -- Enhanced virtualization capability detection and `VBoxManage` path detection -- Properly lock VirtualBox access when running several commands concurrently -- Allow plugins to write to STDOUT without `--debug` enabled -- Fix Rackspace driver regression -- Support colons in `docker-machine scp` filepaths -- Pass environment variables for provisioned Engines to Swarm as well -- Various enhancements around boot2docker ISO upgrade (progress bar, increased timeout) - -# 0.5.0 (2015-11-1) - -- General - - Add pluggable driver model - - Clean up code to be more modular and reusable in `libmachine` - - Add `--github-api-token` for situations where users are getting rate limited - by GitHub attempting to get the current `boot2docker.iso` version - - Various enhancements around the Makefile and build toolchain (still an active WIP) - - Disable SSH multiplex explicitly in commands run with the "External" client - - Show "-" for "inactive" machines instead of nothing - - Make daemon status detection more robust -- Provisioners - - New CoreOS, SUSE, and Arch Linux provisioners - - Fixes around package installation / upgrade code on Debian and Ubuntu -- CLI - - Support for regular expression pattern matching and matching by names in `ls --filter` - - `--no-proxy` flag for `env` (sets `NO_PROXY` in addition to other environment variables) -- Drivers - - `openstack` - - `--openstack-ip-version` parameter - - `--openstack-active-timeout` parameter - - `google` - - fix destructive behavior of `start` / `stop` - - `hyperv` - - fix issues with PowerShell - - `vmwarefusion` - - some issues with shared folders fixed - - `--vmwarefusion-configdrive-url` option for configuration via `cloud-init` - - `amazonec2` - - `--amazonec2-use-private-address` option to use private networking - - `virtualbox` - - Enhancements around robustness of the created host-only network - - Fix IPv6 network mask prefix parsing - - `--virtualbox-no-share` option to disable the automatic home directory mount - - `--virtualbox-hostonly-nictype` and `--virtualbox-hostonly-nicpromisc` for controlling settings around the created hostonly NIC - -# 0.4.1 (2015-08) - -- Fixes `upgrade` functionality on Debian based systems -- Fixes `upgrade` functionality on Ubuntu based systems - -# 0.4.0 (2015-08-11) - -## Updates - -- HTTP Proxy support for Docker Engine -- RedHat distros now use Docker Yum repositories -- Ability to set environment variables in the Docker Engine -- Internal libmachine updates for stability - -## Drivers - -- Google: - - Preemptible instances - - Static IP support - -## Fixes - -- Swarm Discovery Flag is verified -- Timeout added to `ls` command to prevent hangups -- SSH command failure now reports information about error -- Configuration migration updates - -# 0.3.0 (2015-06-18) - -## Features - -- Engine option configuration (ability to configure all engine options) -- Swarm option configuration (ability to configure all swarm options) -- New Provisioning system to allow for greater flexibility and stability for installing and configuring Docker -- New Provisioners - - Rancher OS - - RedHat Enterprise Linux 7.0+ (experimental) - - Fedora 21+ (experimental) - - Debian 8+ (experimental) -- PowerShell support (configure Windows Docker CLI) -- Command Prompt (cmd.exe) support (configure Windows Docker CLI) -- Filter command help by driver -- Ability to import Boot2Docker instances -- Boot2Docker CLI migration guide (experimental) -- Format option for `inspect` command -- New logging output format to improve readability and display across platforms -- Updated "active" machine concept - now is implicit according to `DOCKER_HOST` environment variable. Note: this removes the implicit "active" machine and can no longer be specified with the `active` command. You change the "active" host by using the `env` command instead. -- Specify Swarm version (`--swarm-image` flag) - -## Drivers - -- New: Exoscale Driver -- New: Generic Driver (provision any host with supported base OS and SSH) -- Amazon EC2 - - SSH user is configurable - - Support for Spot instances - - Add option to use private address only - - Base AMI updated to 20150417 -- Google - - Support custom disk types - - Updated base image to v20150316 -- Openstack - - Support for Keystone v3 domains -- Rackspace - - Misc fixes including environment variable for Flavor Id and stability -- Softlayer - - Enable local disk as provisioning option - - Fixes for SSH access errors - - Fixed bug where public IP would always be returned when requesting private - - Add support for specifying public and private VLAN IDs -- VirtualBox - - Use Intel network interface driver (adds great stability) - - Stability fixes for NAT access - - Use DNS pass through - - Default CPU to single core for improved performance - - Enable shared folder support for Windows hosts -- VMware Fusion - - Boot2Docker ISO updated - - Shared folder support - -## Fixes - -- Provisioning improvements to ensure Docker is available -- SSH improvements for provisioning stability -- Fixed SSH key generation bug on Windows -- Help formatting for improved readability - -## Breaking Changes - -- "Short-Form" name reference no longer supported Instead of "docker-machine " implying the active host you must now use docker-machine -- VMware shared folders require Boot2Docker 1.7 - -## Special Thanks - -We would like to thank all contributors. Machine would not be where it is -without you. We would also like to give special thanks to the following -contributors for outstanding contributions to the project: - -- @frapposelli for VMware updates and fixes -- @hairyhenderson for several improvements to Softlayer driver, inspect formatting and lots of fixes -- @ibuildthecloud for rancher os provisioning -- @sthulb for portable SSH library -- @vincentbernat for exoscale -- @zchee for Amazon updates and great doc updates - -# 0.2.0 (2015-04-16) - -Core Stability and Driver Updates - -## Core - -- Support for system proxy environment -- New command to regenerate TLS certificates - - Note: this will restart the Docker engine to apply -- Updates to driver operations (create, start, stop, etc) for better reliability -- New internal `libmachine` package for internal api (not ready for public usage) -- Updated Driver Interface - - [Driver Spec](https://github.com/docker/machine/blob/master/docs/DRIVER_SPEC.md) - - Removed host provisioning from Drivers to enable a more consistent install - - Removed SSH commands from each Driver for more consistent operations -- Swarm: machine now uses Swarm default binpacking strategy - -## Driver Updates - -- All drivers updated to new Driver interface -- Amazon EC2 - - Better checking for subnets on creation - - Support for using Private IPs in VPC - - Fixed bug with duplicate security group authorization with Swarm - - Support for IAM instance profile - - Fixed bug where IP was not properly detected upon stop -- DigitalOcean - - IPv6 support - - Backup option - - Private Networking -- Openstack / Rackspace - - Gophercloud updated to latest version - - New insecure flag to disable TLS (use with caution) -- Google - - Google source image updated - - Ability to specify auth token via file -- VMware Fusion - - Paravirtualized driver for disk (pvscsi) - - Enhanced paravirtualized NIC (vmxnet3) - - Power option updates - - SSH keys persistent across reboots - - Stop now gracefully stops VM - - vCPUs now match host CPUs -- SoftLayer - - Fixed provision bug where `curl` was not present -- VirtualBox - - Correct power operations with Saved VM state - - Fixed bug where image option was ignored - -## CLI - -- Auto-regeneration of TLS certificates when TLS error is detected - - Note: this will restart the Docker engine to apply -- Minor UI updates including improved sorting and updated command docs -- Bug with `config` and `env` with spaces fixed - - Note: you now must use `eval $(docker-machine env machine)` to load environment settings -- Updates to better support `fish` shell -- Use `--tlsverify` for both `config` and `env` commands -- Commands now use eval for better interoperability with shell - -## Testing - -- New integration test framework (bats) - -# 0.1.0 (2015-02-26) - -Initial beta release. - -- Provision Docker Engines using multiple drivers -- Provide light management for the machines - - Create, Start, Stop, Restart, Kill, Remove, SSH -- Configure the Docker Engine for secure communication (TLS) -- Easily switch target machine for fast configuration of Docker Engine client -- Provision Swarm clusters (experimental) - -## Included drivers - -- Amazon EC2 -- Digital Ocean -- Google -- Microsoft Azure -- Microsoft Hyper-V -- Openstack -- Rackspace -- VirtualBox -- VMware Fusion -- VMware vCloud Air -- VMware vSphere diff --git a/vendor/github.com/docker/machine/CONTRIBUTING.md b/vendor/github.com/docker/machine/CONTRIBUTING.md deleted file mode 100644 index f1fae83..0000000 --- a/vendor/github.com/docker/machine/CONTRIBUTING.md +++ /dev/null @@ -1,281 +0,0 @@ -# Contributing to machine - -[![GoDoc](https://godoc.org/github.com/docker/machine?status.png)](https://godoc.org/github.com/docker/machine) -[![Build Status](https://travis-ci.org/docker/machine.svg?branch=master)](https://travis-ci.org/docker/machine) -[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/docker/machine?svg=true)](https://ci.appveyor.com/project/dmp42/machine-fp5u5) -[![Coverage Status](https://coveralls.io/repos/docker/machine/badge.svg?branch=master&service=github)](https://coveralls.io/github/docker/machine?branch=master) - -Want to hack on Machine? Awesome! Here are instructions to get you -started. - -Machine is a part of the [Docker](https://www.docker.com) project, and follows -the same rules and principles. If you're already familiar with the way -Docker does things, you'll feel right at home. - -Otherwise, please read [Docker's contributions -guidelines](https://github.com/docker/docker/blob/master/CONTRIBUTING.md). - -# Building - -The requirements to build Machine are: - -1. A running instance of Docker or a Golang 1.6 development environment -2. The `bash` shell -3. [Make](https://www.gnu.org/software/make/) - -## Build using Docker containers - -To build the `docker-machine` binary using containers, simply run: - - $ export USE_CONTAINER=true - $ make build - -## Local Go development environment - -Make sure the source code directory is under a correct directory structure; -Example of cloning and preparing the correct environment `GOPATH`: - - $ mkdir docker-machine - $ cd docker-machine - $ export GOPATH="$PWD" - $ go get github.com/docker/machine - $ cd src/github.com/docker/machine - -If you want to use your existing workspace, make sure your `GOPATH` is set to -the directory that contains your `src` directory, e.g.: - - $ export GOPATH=/home/yourname/work - $ mkdir -p $GOPATH/src/github.com/docker - $ cd $GOPATH/src/github.com/docker && git clone git@github.com:docker/machine.git - $ cd machine - -At this point, simply run: - - $ make build - -## Built binary - -After the build is complete a `bin/docker-machine` binary will be created. - -You may call: - - $ make clean - -to clean-up build results. - -## Tests and validation - -We use the usual `go` tools for this, to run those commands you need at least the linter which you can -install with `go get -u github.com/golang/lint/golint` - -To run basic validation (dco, fmt), and the project unit tests, call: - - $ make test - -If you want more indepth validation (vet, lint), and all tests with race detection, call: - - $ make validate - -If you make a pull request, it is highly encouraged that you submit tests for -the code that you have added or modified in the same pull request. - -## Code Coverage - -To generate an html code coverage report of the Machine codebase, run: - - make coverage-serve - -And navigate to (hit `CTRL+C` to stop the server). - -### Native build - -Alternatively, if you are building natively, you can simply run: - - make coverage-html - - -## List of all targets - -### High-level targets - - make clean - make build - make test - make validate - -### Advanced build targets - -Build for all supported OSes and architectures (binaries will be in the `bin` project subfolder): - - make build-x - -Build for a specific list of OSes and architectures: - - TARGET_OS=linux TARGET_ARCH="amd64 arm" make build-x - -You can further control build options through the following environment variables: - - DEBUG=true # enable debug build - STATIC=true # build static (note: when cross-compiling, the build is always static) - VERBOSE=true # verbose output - PREFIX=folder # put binaries in another folder (not the default `./bin`) - -Scrub build results: - - make build-clean - -### Coverage targets - - make coverage-html - make coverage-serve - make coverage-send - make coverage-generate - make coverage-clean - -### Tests targets - - make test-short - make test-long - make test-integration - -### Validation targets - - make fmt - make vet - make lint - make dco - -### Restore, update and save dependencies - -When you make a fresh copy of the repo, all the dependecies are in `vendor/` directory for the builds to work. If you want to update the dependencies - -#### Restore the dependencies - - make dep-restore - - This uses godep to restores all the dependencies to your `$GOPATH`. Note that this changes the packages in your `$GOPATH` - -#### Add one ore more dependencies - - go get -u - -#### Save the dependencies to `vendor/` - - make dep-save - -4. Verify the changes in your repo, commit and submit a pull request - -## Integration Tests - -### Setup - -We use [BATS](https://github.com/sstephenson/bats) for integration testing, so, -first make sure to [install it](https://github.com/sstephenson/bats#installing-bats-from-source). - -### Basic Usage - -You first need to build, calling `make build`. - -You can then invoke integration tests calling `DRIVER=foo make test-integration TESTSUITE`, where `TESTSUITE` is -one of the `test/integration` subfolder, and `foo` is the specific driver you want to test. - -Examples: - -```console -$ DRIVER=virtualbox make test-integration test/integration/core/core-commands.bats - ✓ virtualbox: machine should not exist - ✓ virtualbox: create - ✓ virtualbox: ls - ✓ virtualbox: run busybox container - ✓ virtualbox: url - ✓ virtualbox: ip - ✓ virtualbox: ssh - ✓ virtualbox: docker commands with the socket should work - ✓ virtualbox: stop - ✓ virtualbox: machine should show stopped after stop - ✓ virtualbox: machine should now allow upgrade when stopped - ✓ virtualbox: start - ✓ virtualbox: machine should show running after start - ✓ virtualbox: kill - ✓ virtualbox: machine should show stopped after kill - ✓ virtualbox: restart - ✓ virtualbox: machine should show running after restart - -17 tests, 0 failures -Cleaning up machines... -Successfully removed bats-virtualbox-test -``` - -To invoke a directory of tests recursively: - -```console -$ DRIVER=virtualbox make test-integration test/integration/core/ -... -``` - -### Extra Create Arguments - -In some cases, for instance to test the creation of a specific base OS (e.g. -RHEL) as opposed to the default with the common tests, you may want to run -common tests with different create arguments than you get out of the box. - -Keep in mind that Machine supports environment variables for many of these -flags. So, for instance, you could run the command (substituting, of course, -the proper secrets): - - $ DRIVER=amazonec2 \ - AWS_VPC_ID=vpc-xxxxxxx \ - AWS_SECRET_ACCESS_KEY=yyyyyyyyyyyyy \ - AWS_ACCESS_KEY_ID=zzzzzzzzzzzzzzzz \ - AWS_AMI=ami-12663b7a \ - AWS_SSH_USER=ec2-user \ - make test-integration test/integration/core - -in order to run the core tests on Red Hat Enterprise Linux on Amazon. - -### Layout - -The `test/integration` directory is layed out to divide up tests based on the -areas which the test. If you are uncertain where to put yours, we are happy to -guide you. - -At the time of writing, there is: - -1. A `core` directory which contains tests that are applicable to all drivers. -2. A `drivers` directory which contains tests that are applicable only to - specific drivers with sub-directories for each provider. -3. A `cli` directory which is meant for testing functionality of the command - line interface, without much regard for driver-specific details. - -### Guidelines - -The best practices for writing integration tests on Docker Machine are still a -work in progress, but here are some general guidelines from the maintainers: - -1. Ideally, each test file should have only one concern. -2. Tests generally should not spin up more than one machine unless the test is - deliberately testing something which involves multiple machines, such as an `ls` - test which involves several machines, or a test intended to create and check - some property of a Swarm cluster. -3. BATS will print the output of commands executed during a test if the test - fails. This can be useful, for instance to dump the magic `$output` variable - that BATS provides and/or to get debugging information. -4. It is not strictly needed to clean up the machines as part of the test. The - BATS wrapper script has a hook to take care of cleaning up all created machines - after each test. - -# Drivers - -Docker Machine has several included drivers that supports provisioning hosts -in various providers. If you wish to contribute a driver, we ask the following -to ensure we keep the driver in a consistent and stable state: - -- Address issues filed against this driver in a timely manner -- Review PRs for the driver -- Be responsible for maintaining the infrastructure to run unit tests - and integration tests on the new supported environment -- Participate in a weekly driver maintainer meeting - - -Note: even if those are met does not guarantee a driver will be accepted. -If you have questions, please do not hesitate to contact us on IRC. diff --git a/vendor/github.com/docker/machine/Dockerfile b/vendor/github.com/docker/machine/Dockerfile deleted file mode 100644 index 6ea97d8..0000000 --- a/vendor/github.com/docker/machine/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:1.8.3 - -RUN apt-get update && apt-get install -y --no-install-recommends \ - openssh-client \ - rsync \ - fuse \ - sshfs \ - && rm -rf /var/lib/apt/lists/* - -RUN go get github.com/golang/lint/golint \ - github.com/mattn/goveralls \ - golang.org/x/tools/cover - -ENV USER root -WORKDIR /go/src/github.com/docker/machine - -COPY . ./ -RUN mkdir bin diff --git a/vendor/github.com/docker/machine/Godeps/Godeps.json b/vendor/github.com/docker/machine/Godeps/Godeps.json deleted file mode 100644 index 88178f4..0000000 --- a/vendor/github.com/docker/machine/Godeps/Godeps.json +++ /dev/null @@ -1,657 +0,0 @@ -{ - "ImportPath": "github.com/docker/machine", - "GoVersion": "go1.7", - "GodepVersion": "v79", - "Packages": [ - "github.com/docker/machine", - "github.com/docker/machine/cmd", - "github.com/docker/machine/commands", - "github.com/docker/machine/commands/commandstest", - "github.com/docker/machine/commands/mcndirs", - "github.com/docker/machine/drivers/amazonec2", - "github.com/docker/machine/drivers/azure", - "github.com/docker/machine/drivers/azure/azureutil", - "github.com/docker/machine/drivers/azure/logutil", - "github.com/docker/machine/drivers/digitalocean", - "github.com/docker/machine/drivers/driverutil", - "github.com/docker/machine/drivers/errdriver", - "github.com/docker/machine/drivers/exoscale", - "github.com/docker/machine/drivers/fakedriver", - "github.com/docker/machine/drivers/generic", - "github.com/docker/machine/drivers/google", - "github.com/docker/machine/drivers/hyperv", - "github.com/docker/machine/drivers/none", - "github.com/docker/machine/drivers/openstack", - "github.com/docker/machine/drivers/rackspace", - "github.com/docker/machine/drivers/softlayer", - "github.com/docker/machine/drivers/virtualbox", - "github.com/docker/machine/drivers/vmwarefusion", - "github.com/docker/machine/drivers/vmwarevcloudair", - "github.com/docker/machine/drivers/vmwarevsphere", - "github.com/docker/machine/its", - "github.com/docker/machine/its/cli", - "github.com/docker/machine/its/thirdparty", - "github.com/docker/machine/libmachine", - "github.com/docker/machine/libmachine/auth", - "github.com/docker/machine/libmachine/cert", - "github.com/docker/machine/libmachine/check", - "github.com/docker/machine/libmachine/crashreport", - "github.com/docker/machine/libmachine/drivers", - "github.com/docker/machine/libmachine/drivers/plugin", - "github.com/docker/machine/libmachine/drivers/plugin/localbinary", - "github.com/docker/machine/libmachine/drivers/rpc", - "github.com/docker/machine/libmachine/engine", - "github.com/docker/machine/libmachine/examples", - "github.com/docker/machine/libmachine/host", - "github.com/docker/machine/libmachine/hosttest", - "github.com/docker/machine/libmachine/libmachinetest", - "github.com/docker/machine/libmachine/log", - "github.com/docker/machine/libmachine/mcndockerclient", - "github.com/docker/machine/libmachine/mcnerror", - "github.com/docker/machine/libmachine/mcnflag", - "github.com/docker/machine/libmachine/mcnutils", - "github.com/docker/machine/libmachine/persist", - "github.com/docker/machine/libmachine/persist/persisttest", - "github.com/docker/machine/libmachine/provider", - "github.com/docker/machine/libmachine/provision", - "github.com/docker/machine/libmachine/provision/pkgaction", - "github.com/docker/machine/libmachine/provision/provisiontest", - "github.com/docker/machine/libmachine/provision/serviceaction", - "github.com/docker/machine/libmachine/shell", - "github.com/docker/machine/libmachine/ssh", - "github.com/docker/machine/libmachine/ssh/sshtest", - "github.com/docker/machine/libmachine/state", - "github.com/docker/machine/libmachine/swarm", - "github.com/docker/machine/libmachine/version", - "github.com/docker/machine/version" - ], - "Deps": [ - { - "ImportPath": "github.com/Azure/azure-sdk-for-go/arm/compute", - "Comment": "v5.0.0-beta", - "Rev": "91f3d4a4d024e3c0d4d9412916d05cf84504a616" - }, - { - "ImportPath": "github.com/Azure/azure-sdk-for-go/arm/network", - "Comment": "v5.0.0-beta", - "Rev": "91f3d4a4d024e3c0d4d9412916d05cf84504a616" - }, - { - "ImportPath": "github.com/Azure/azure-sdk-for-go/arm/resources/resources", - "Comment": "v5.0.0-beta", - "Rev": "91f3d4a4d024e3c0d4d9412916d05cf84504a616" - }, - { - "ImportPath": "github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions", - "Comment": "v5.0.0-beta", - "Rev": "91f3d4a4d024e3c0d4d9412916d05cf84504a616" - }, - { - "ImportPath": "github.com/Azure/azure-sdk-for-go/arm/storage", - "Comment": "v5.0.0-beta", - "Rev": "91f3d4a4d024e3c0d4d9412916d05cf84504a616" - }, - { - "ImportPath": "github.com/Azure/azure-sdk-for-go/storage", - "Comment": "v5.0.0-beta", - "Rev": "91f3d4a4d024e3c0d4d9412916d05cf84504a616" - }, - { - "ImportPath": "github.com/Azure/go-autorest/autorest", - "Comment": "v7.2.1", - "Rev": "0781901f19f1e7db3034d97ec57af753db0bf808" - }, - { - "ImportPath": "github.com/Azure/go-autorest/autorest/azure", - "Comment": "v7.2.1", - "Rev": "0781901f19f1e7db3034d97ec57af753db0bf808" - }, - { - "ImportPath": "github.com/Azure/go-autorest/autorest/date", - "Comment": "v7.2.1", - "Rev": "0781901f19f1e7db3034d97ec57af753db0bf808" - }, - { - "ImportPath": "github.com/Azure/go-autorest/autorest/to", - "Comment": "v7.2.1", - "Rev": "0781901f19f1e7db3034d97ec57af753db0bf808" - }, - { - "ImportPath": "github.com/Azure/go-autorest/autorest/validation", - "Comment": "v7.2.1", - "Rev": "0781901f19f1e7db3034d97ec57af753db0bf808" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/awserr", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/awsutil", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/client", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/client/metadata", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/corehandlers", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/credentials", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/credentials/endpointcreds", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/credentials/stscreds", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/defaults", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/ec2metadata", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/request", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/session", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/aws/signer/v4", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/private/endpoints", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/private/protocol", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/private/protocol/ec2query", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/private/protocol/query", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/private/protocol/query/queryutil", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/private/protocol/rest", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/private/waiter", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/service/ec2", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/aws/aws-sdk-go/service/sts", - "Comment": "v1.4.10", - "Rev": "ddfd17ec06eee10c24c5c474633273fd034afdda" - }, - { - "ImportPath": "github.com/bugsnag/bugsnag-go", - "Comment": "v1.0.5-19-g02e9528", - "Rev": "02e952891c52fbcb15f113d90633897355783b6e" - }, - { - "ImportPath": "github.com/bugsnag/bugsnag-go/errors", - "Comment": "v1.0.5-19-g02e9528", - "Rev": "02e952891c52fbcb15f113d90633897355783b6e" - }, - { - "ImportPath": "github.com/bugsnag/osext", - "Rev": "0dd3f918b21bec95ace9dc86c7e70266cfc5c702" - }, - { - "ImportPath": "github.com/bugsnag/panicwrap", - "Comment": "1.1.0", - "Rev": "aceac81c6e2f55f23844821679a0553b545e91df" - }, - { - "ImportPath": "github.com/cenkalti/backoff", - "Rev": "9831e1e25c874e0a0601b6dc43641071414eec7a" - }, - { - "ImportPath": "github.com/codegangsta/cli", - "Comment": "v1.11.0-6-g0302d39", - "Rev": "0302d3914d2a6ad61404584cdae6e6dbc9c03599" - }, - { - "ImportPath": "github.com/davecgh/go-spew/spew", - "Rev": "5215b55f46b2b919f50a1df0eaa5886afe4e3b3d" - }, - { - "ImportPath": "github.com/dgrijalva/jwt-go", - "Comment": "v3.0.0-8-g24c63f5", - "Rev": "24c63f56522a87ec5339cc3567883f1039378fdb" - }, - { - "ImportPath": "github.com/digitalocean/godo", - "Comment": "v1.0.0-3-gd59ed2f", - "Rev": "d59ed2fe842bbb3cbee91c9df8bb7659dc9ee86f" - }, - { - "ImportPath": "github.com/docker/docker/pkg/term", - "Comment": "v1.5.0", - "Rev": "a8a31eff10544860d2188dddabdee4d727545796" - }, - { - "ImportPath": "github.com/docker/go-units", - "Comment": "v0.1.0-21-g0bbddae", - "Rev": "0bbddae09c5a5419a8c6dcdd7ff90da3d450393b" - }, - { - "ImportPath": "github.com/go-ini/ini", - "Comment": "v0-56-g03e0e7d", - "Rev": "03e0e7d51a13a91c765d8d0161246bc14a38001a" - }, - { - "ImportPath": "github.com/golang/protobuf/proto", - "Rev": "3c84672111d91bb5ac31719e112f9f7126a0e26e" - }, - { - "ImportPath": "github.com/google/go-querystring/query", - "Rev": "30f7a39f4a218feb5325f3aebc60c32a572a8274" - }, - { - "ImportPath": "github.com/jmespath/go-jmespath", - "Comment": "0.2.2", - "Rev": "3433f3ea46d9f8019119e7dd41274e112a2359a9" - }, - { - "ImportPath": "github.com/mitchellh/mapstructure", - "Rev": "740c764bc6149d3f1806231418adb9f52c11bcbf" - }, - { - "ImportPath": "github.com/pmezard/go-difflib/difflib", - "Comment": "v1.0.0", - "Rev": "792786c7400a136282c1664665ae0a8db921c6c2" - }, - { - "ImportPath": "github.com/exoscale/egoscale", - "Rev": "325740036187ddae3a5b74be00fbbc70011c4d96" - }, - { - "ImportPath": "github.com/rackspace/gophercloud", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/floatingip", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/startstop", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/flavors", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/images", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/compute/v2/servers", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/identity/v2/tenants", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/identity/v2/tokens", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/identity/v3/tokens", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/floatingips", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/networks", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/networking/v2/ports", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/openstack/utils", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/pagination", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/rackspace", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/rackspace/identity/v2/tokens", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/testhelper", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/rackspace/gophercloud/testhelper/client", - "Comment": "v1.0.0-558-gce0f487", - "Rev": "ce0f487f6747ab43c4e4404722df25349385bebd" - }, - { - "ImportPath": "github.com/samalba/dockerclient", - "Rev": "f661dd4754aa5c52da85d04b5871ee0e11f4b59c" - }, - { - "ImportPath": "github.com/skarademir/naturalsort", - "Rev": "69a5d87bef620f77ee8508db30c846b3b84b111e" - }, - { - "ImportPath": "github.com/stretchr/objx", - "Rev": "1a9d0bb9f541897e62256577b352fdbc1fb4fd94" - }, - { - "ImportPath": "github.com/stretchr/testify/assert", - "Comment": "v1.1.3-4-g1f4a164", - "Rev": "1f4a1643a57e798696635ea4c126e9127adb7d3c" - }, - { - "ImportPath": "github.com/stretchr/testify/mock", - "Comment": "v1.1.3-4-g1f4a164", - "Rev": "1f4a1643a57e798696635ea4c126e9127adb7d3c" - }, - { - "ImportPath": "github.com/tent/http-link-go", - "Rev": "ac974c61c2f990f4115b119354b5e0b47550e888" - }, - { - "ImportPath": "github.com/vmware/govcloudair", - "Comment": "v0.0.2", - "Rev": "66a23eaabc61518f91769939ff541886fe1dceef" - }, - { - "ImportPath": "github.com/vmware/govcloudair/types/v56", - "Comment": "v0.0.2", - "Rev": "66a23eaabc61518f91769939ff541886fe1dceef" - }, - { - "ImportPath": "github.com/vmware/govmomi", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/find", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/guest", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/list", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/object", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/property", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/session", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/task", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/vim25", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/vim25/debug", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/vim25/methods", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/vim25/mo", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/vim25/progress", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/vim25/soap", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/vim25/types", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "github.com/vmware/govmomi/vim25/xml", - "Comment": "v0.6.2", - "Rev": "9051bd6b44125d9472e0c148b5965692ab283d4a" - }, - { - "ImportPath": "golang.org/x/crypto/curve25519", - "Rev": "51714a8c4ac1764f07ab4127d7f739351ced4759" - }, - { - "ImportPath": "golang.org/x/crypto/ssh", - "Rev": "51714a8c4ac1764f07ab4127d7f739351ced4759" - }, - { - "ImportPath": "golang.org/x/crypto/ssh/terminal", - "Rev": "51714a8c4ac1764f07ab4127d7f739351ced4759" - }, - { - "ImportPath": "golang.org/x/net/context", - "Rev": "4f2fc6c1e69d41baf187332ee08fbd2b296f21ed" - }, - { - "ImportPath": "golang.org/x/net/context/ctxhttp", - "Rev": "4f2fc6c1e69d41baf187332ee08fbd2b296f21ed" - }, - { - "ImportPath": "golang.org/x/oauth2", - "Rev": "442624c9ec9243441e83b374a9e22ac549b5c51d" - }, - { - "ImportPath": "golang.org/x/oauth2/google", - "Rev": "442624c9ec9243441e83b374a9e22ac549b5c51d" - }, - { - "ImportPath": "golang.org/x/oauth2/internal", - "Rev": "442624c9ec9243441e83b374a9e22ac549b5c51d" - }, - { - "ImportPath": "golang.org/x/oauth2/jws", - "Rev": "442624c9ec9243441e83b374a9e22ac549b5c51d" - }, - { - "ImportPath": "golang.org/x/oauth2/jwt", - "Rev": "442624c9ec9243441e83b374a9e22ac549b5c51d" - }, - { - "ImportPath": "golang.org/x/sys/windows/registry", - "Rev": "d9157a9621b69ad1d8d77a1933590c416593f24f" - }, - { - "ImportPath": "google.golang.org/api/compute/v1", - "Rev": "030d584ade5f79aa2ed0ce067e8f7da50c9a10d5" - }, - { - "ImportPath": "google.golang.org/api/gensupport", - "Rev": "030d584ade5f79aa2ed0ce067e8f7da50c9a10d5" - }, - { - "ImportPath": "google.golang.org/api/googleapi", - "Rev": "030d584ade5f79aa2ed0ce067e8f7da50c9a10d5" - }, - { - "ImportPath": "google.golang.org/api/googleapi/internal/uritemplates", - "Rev": "030d584ade5f79aa2ed0ce067e8f7da50c9a10d5" - }, - { - "ImportPath": "google.golang.org/appengine", - "Rev": "6a436539be38c296a8075a871cc536686b458371" - }, - { - "ImportPath": "google.golang.org/appengine/internal", - "Rev": "6a436539be38c296a8075a871cc536686b458371" - }, - { - "ImportPath": "google.golang.org/appengine/internal/app_identity", - "Rev": "6a436539be38c296a8075a871cc536686b458371" - }, - { - "ImportPath": "google.golang.org/appengine/internal/base", - "Rev": "6a436539be38c296a8075a871cc536686b458371" - }, - { - "ImportPath": "google.golang.org/appengine/internal/datastore", - "Rev": "6a436539be38c296a8075a871cc536686b458371" - }, - { - "ImportPath": "google.golang.org/appengine/internal/log", - "Rev": "6a436539be38c296a8075a871cc536686b458371" - }, - { - "ImportPath": "google.golang.org/appengine/internal/modules", - "Rev": "6a436539be38c296a8075a871cc536686b458371" - }, - { - "ImportPath": "google.golang.org/appengine/internal/remote_api", - "Rev": "6a436539be38c296a8075a871cc536686b458371" - }, - { - "ImportPath": "google.golang.org/cloud/compute/metadata", - "Rev": "975617b05ea8a58727e6c1a06b6161ff4185a9f2" - }, - { - "ImportPath": "google.golang.org/cloud/internal", - "Rev": "975617b05ea8a58727e6c1a06b6161ff4185a9f2" - }, - { - "ImportPath": "golang.org/x/crypto/ed25519", - "Rev": "51714a8c4ac1764f07ab4127d7f739351ced4759" - }, - { - "ImportPath": "golang.org/x/crypto/ed25519/internal/edwards25519", - "Rev": "51714a8c4ac1764f07ab4127d7f739351ced4759" - } - ] -} diff --git a/vendor/github.com/docker/machine/Godeps/Readme b/vendor/github.com/docker/machine/Godeps/Readme deleted file mode 100644 index 4cdaa53..0000000 --- a/vendor/github.com/docker/machine/Godeps/Readme +++ /dev/null @@ -1,5 +0,0 @@ -This directory tree is generated automatically by godep. - -Please do not edit. - -See https://github.com/tools/godep for more information. diff --git a/vendor/github.com/docker/machine/LICENSE b/vendor/github.com/docker/machine/LICENSE deleted file mode 100644 index 2744858..0000000 --- a/vendor/github.com/docker/machine/LICENSE +++ /dev/null @@ -1,191 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - Copyright 2014 Docker, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/docker/machine/MAINTAINERS b/vendor/github.com/docker/machine/MAINTAINERS deleted file mode 100644 index ce9bfa7..0000000 --- a/vendor/github.com/docker/machine/MAINTAINERS +++ /dev/null @@ -1,40 +0,0 @@ -# Machine maintainers file -# -# This file describes who runs the docker/machine project and how. -# This is a living document - if you see something out of date or missing, speak up! -# -# It is structured to be consumable by both humans and programs. -# To extract its contents programmatically, use any TOML-compliant parser. -# -# This file is compiled into the MAINTAINERS file in docker/opensource. -# -[Org] - [Org."Core maintainers"] - people = [ - "dgageot", - "jeanlaurent", - "shin-", - ] - -[people] - -# A reference list of all people associated with the project. -# All other sections should refer to people by their canonical key -# in the people section. - - # ADD YOURSELF HERE IN ALPHABETICAL ORDER - - [people.dgageot] - Name = "David Gageot" - Email = "david.gageot@docker.com" - GitHub = "dgageot" - - [people.jeanlaurent] - Name = "Jean-Laurent de Morlhon" - Email = "jeanlaurent@docker.com" - GitHub = "jeanlaurent" - - [people.shin-] - Name = "Joffrey F" - Email = "joffrey@docker.com" - GitHub = "shin-" diff --git a/vendor/github.com/docker/machine/Makefile b/vendor/github.com/docker/machine/Makefile deleted file mode 100644 index 5bbe5b0..0000000 --- a/vendor/github.com/docker/machine/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# Plain make targets if not requested inside a container -ifneq (,$(findstring test-integration,$(MAKECMDGOALS))) - include Makefile.inc - include mk/main.mk -else ifneq ($(USE_CONTAINER), true) - include Makefile.inc - include mk/main.mk -else -# Otherwise, with docker, swallow all targets and forward into a container -DOCKER_BUILD_DONE := "" - -test: .DEFAULT - -.DEFAULT: - @test ! -z "$(DOCKER_BUILD_DONE)" || ./script/build_in_container.sh $(MAKECMDGOALS) - $(eval DOCKER_BUILD_DONE := "done") - -endif diff --git a/vendor/github.com/docker/machine/Makefile.inc b/vendor/github.com/docker/machine/Makefile.inc deleted file mode 100644 index f09616b..0000000 --- a/vendor/github.com/docker/machine/Makefile.inc +++ /dev/null @@ -1,31 +0,0 @@ -# Project name, used to name the binaries -PKG_NAME := docker-machine - -# If true, disable optimizations and does NOT strip the binary -DEBUG ?= -# If true, "build" will produce a static binary (cross compile always produce static build regardless) -STATIC ?= -# If true, turn on verbose output for build -VERBOSE ?= -# Build tags -BUILDTAGS ?= -# Adjust number of parallel builds (XXX not used) -PARALLEL ?= -1 -# Coverage default directory -COVERAGE_DIR ?= cover -# Whether to perform targets inside a docker container, or natively on the host -USE_CONTAINER ?= - -# List of cross compilation targets -ifeq ($(TARGET_OS),) - TARGET_OS := darwin linux windows -endif - -ifeq ($(TARGET_ARCH),) - TARGET_ARCH := amd64 arm arm64 386 -endif - -# Output prefix, defaults to local directory if not specified -ifeq ($(PREFIX),) - PREFIX := $(shell pwd) -endif diff --git a/vendor/github.com/docker/machine/README.md b/vendor/github.com/docker/machine/README.md deleted file mode 100644 index ef64b66..0000000 --- a/vendor/github.com/docker/machine/README.md +++ /dev/null @@ -1,143 +0,0 @@ -# Docker Machine - -![](https://docs.docker.com/machine/img/logo.png) - -Machine lets you create Docker hosts on your computer, on cloud providers, and -inside your own data center. It creates servers, installs Docker on them, then -configures the Docker client to talk to them. - -It works a bit like this: - -```console -$ docker-machine create -d virtualbox default -Running pre-create checks... -Creating machine... -(default) Creating VirtualBox VM... -(default) Creating SSH key... -(default) Starting VM... -Waiting for machine to be running, this may take a few minutes... -Machine is running, waiting for SSH to be available... -Detecting operating system of created instance... -Detecting the provisioner... -Provisioning with boot2docker... -Copying certs to the local machine directory... -Copying certs to the remote machine... -Setting Docker configuration on the remote daemon... -Checking connection to Docker... -Docker is up and running! -To see how to connect Docker to this machine, run: docker-machine env default - -$ docker-machine ls -NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS -default - virtualbox Running tcp://192.168.99.188:2376 v1.9.1 - -$ eval "$(docker-machine env default)" - -$ docker run busybox echo hello world -Unable to find image 'busybox:latest' locally -511136ea3c5a: Pull complete -df7546f9f060: Pull complete -ea13149945cb: Pull complete -4986bf8c1536: Pull complete -hello world -``` - -In addition to local VMs, you can create and manage cloud servers: - -```console -$ docker-machine create -d digitalocean --digitalocean-access-token=secret staging -Creating SSH key... -Creating Digital Ocean droplet... -To see how to connect Docker to this machine, run: docker-machine env staging - -$ docker-machine ls -NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS -default - virtualbox Running tcp://192.168.99.188:2376 v1.9.1 -staging - digitalocean Running tcp://203.0.113.81:2376 v1.9.1 -``` - -## Installation and documentation - -Full documentation [is available here](https://docs.docker.com/machine/). - -## Contributing - -Want to hack on Machine? Please start with the [Contributing Guide](https://github.com/docker/machine/blob/master/CONTRIBUTING.md). - -## Driver Plugins - -In addition to the core driver plugins bundled alongside Docker Machine, users -can make and distribute their own plugin for any virtualization technology or -cloud provider. To browse the list of known Docker Machine plugins, please [see -this document in our -docs repo](https://github.com/docker/docker.github.io/blob/master/machine/AVAILABLE_DRIVER_PLUGINS.md). - -## Troubleshooting - -Docker Machine tries to do the right thing in a variety of scenarios but -sometimes things do not go according to plan. Here is a quick troubleshooting -guide which may help you to resolve of the issues you may be seeing. - -Note that some of the suggested solutions are only available on the Docker -Machine master branch. If you need them, consider compiling Docker Machine from -source. -#### `docker-machine` hangs - -A common issue with Docker Machine is that it will hang when attempting to start -up the virtual machine. Since starting the machine is part of the `create` -process, `create` is often where these types of errors show up. - -A hang could be due to a variety of factors, but the most common suspect is -networking. Consider the following: - -- Are you using a VPN? If so, try disconnecting and see if creation will - succeed without the VPN. Some VPN software aggressively controls routes and - you may need to [manually add the route](https://github.com/docker/machine/issues/1500#issuecomment-121134958). -- Are you connected to a proxy server, corporate or otherwise? If so, take a - look at the `--no-proxy` flag for `env` and at [setting environment variables - for the created Docker Engine](https://docs.docker.com/machine/reference/create/#specifying-configuration-options-for-the-created-docker-engine). -- Are there a lot of host-only interfaces listed by the command `VBoxManage list - hostonlyifs`? If so, this has sometimes been known to cause bugs. Consider - removing the ones you are not using (`VBoxManage hostonlyif remove name`) and - trying machine creation again. - -We are keenly aware of this as an issue and working towards a set of solutions -which is robust for all users, so please give us feedback and/or report issues, -workarounds, and desired workflows as you discover them. - -#### Machine creation errors out before finishing - -If you see messages such as "exit status 1" creating machines with VirtualBox, -this frequently indicates that there is an issue with VirtualBox itself. Please -[file an issue](https://github.com/docker/machine/issues/new) and include a link -to a [Github Gist](https://gist.github.com/) with the output of the VirtualBox -log (usually located at -`$HOME/.docker/machine/machines/machinename/machinename/Logs/VBox.log`), as well -as the output of running the Docker Machine command which is failing with the -global `--debug` flag enabled. This will help us to track down which versions -of VirtualBox are failing where, and under which conditions. - -If you see messages such as "exit status 255", this frequently indicates there -has been an issue with SSH. Please investigate your SSH configuration if you -have one, and/or [file an issue](https://github.com/docker/machine/issues). - -#### "You may be getting rate limited by Github" error message - -In order to `create` or `upgrade` virtual machines running Docker, Docker -Machine will check the Github API for the latest release of the [boot2docker -operating system](https://github.com/boot2docker/boot2docker). The Github API -allows for a small number of unauthenticated requests from a given client, but -if you share an IP address with many other users (e.g. in an office), you may -get rate limited by their API, and Docker Machine will error out with messages -indicating this. - -In order to work around this issue, you can [generate a -token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) -and pass it to Docker Machine using the global `--github-api-token` flag like -so: - -```console -$ docker-machine --github-api-token=token create -d virtualbox newbox -``` - -This should eliminate any issues you've been experiencing with rate limiting. diff --git a/vendor/github.com/docker/machine/ROADMAP.md b/vendor/github.com/docker/machine/ROADMAP.md deleted file mode 100644 index 7f9d4a9..0000000 --- a/vendor/github.com/docker/machine/ROADMAP.md +++ /dev/null @@ -1,34 +0,0 @@ -# Machine Roadmap - -Machine currently works really well for development and test environments. The -goal is to make it work better for provisioning and managing production -environments. - -This is not a simple task -- production is inherently far more complex than -development -- but there are three things which are big steps towards that goal: -**client/server architecture**, **swarm integration** and **flexible -provisioning**. - -(Note: this document is a high-level overview of where we are taking Machine. -For what is coming in specific releases, see our [upcoming -milestones](https://github.com/docker/machine/milestones).) - -### Docker Engine / Swarm Configuration - -Currently there are only a few things that can be configured in the Docker Engine and Swarm. This will enable more operations such as Engine labels and Swarm strategies. - -### Boot2Docker Migration Support - -Currently both Machine and Boot2Docker provider similar functionality. This will enable users to migrate from boot2docker to machine. - -### Expand Provisioner - -Machine currently supports running Boot2Docker for "local" providers and Ubuntu for "remote" providers. This will expand the provisioning capabilities to include other base operating systems such as Red Hat-like distributions and possibly other "just enough" operating systems. - -### Windows Experience - -Currently, the Machine on Windows experience is not as good as the Mac / Linux. There is no "recommended" path to use Machine and there are several inconsistencies on Windows such as logging and output formatting. - -# Project Planning - -An [Open-Source Planning Process](https://github.com/docker/machine/wiki/Open-Source-Planning-Process) is used to define the Roadmap. [Project Pages](https://github.com/docker/machine/wiki) define the goals for each Milestone and identify current progress. diff --git a/vendor/github.com/docker/machine/appveyor.yml b/vendor/github.com/docker/machine/appveyor.yml deleted file mode 100644 index cd1397a..0000000 --- a/vendor/github.com/docker/machine/appveyor.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: "{build}" - -skip_tags: true - -os: Windows Server 2012 R2 - -environment: - GOPATH: c:\gopath - -clone_folder: c:\gopath\src\github.com\docker\machine - -build_script: - - go build -i -o ./bin/docker-machine.exe ./cmd/machine.go - -test_script: - - powershell -Command go test -v ./libmachine/shell - -deploy: off diff --git a/vendor/github.com/docker/machine/circle.yml b/vendor/github.com/docker/machine/circle.yml deleted file mode 100644 index f8ce811..0000000 --- a/vendor/github.com/docker/machine/circle.yml +++ /dev/null @@ -1,30 +0,0 @@ -machine: - pre: - - bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/1.0.22/binscripts/gvm-installer) - - post: - - gvm install go1.7 -B --name=stable - - environment: - CHECKOUT: /home/ubuntu/$CIRCLE_PROJECT_REPONAME - BASE_DIR: src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME - BASE_STABLE: ../../../$HOME/.gvm/pkgsets/stable/global/$BASE_DIR - GO15VENDOREXPERIMENT: 1 - -dependencies: - override: - - > - gvm use stable && - mkdir -p "$(dirname $BASE_STABLE)" && - cp -R "$CHECKOUT" "$BASE_STABLE" - -test: - pre: - - gvm use stable && make build: - pwd: $BASE_STABLE - - gvm use stable && go get github.com/docker/docker-machine-driver-ci-test - - override: - - gvm use stable && PATH=../../../../bin:$PATH DRIVER=ci-test go test -v github.com/docker/machine/its/...: - pwd: $BASE_STABLE - timeout: 600 diff --git a/vendor/github.com/docker/machine/cmd/machine.go b/vendor/github.com/docker/machine/cmd/machine.go deleted file mode 100644 index a80cc33..0000000 --- a/vendor/github.com/docker/machine/cmd/machine.go +++ /dev/null @@ -1,215 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" - - "path/filepath" - - "github.com/codegangsta/cli" - "github.com/docker/machine/commands" - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/drivers/amazonec2" - "github.com/docker/machine/drivers/azure" - "github.com/docker/machine/drivers/digitalocean" - "github.com/docker/machine/drivers/exoscale" - "github.com/docker/machine/drivers/generic" - "github.com/docker/machine/drivers/google" - "github.com/docker/machine/drivers/hyperv" - "github.com/docker/machine/drivers/none" - "github.com/docker/machine/drivers/openstack" - "github.com/docker/machine/drivers/rackspace" - "github.com/docker/machine/drivers/softlayer" - "github.com/docker/machine/drivers/virtualbox" - "github.com/docker/machine/drivers/vmwarefusion" - "github.com/docker/machine/drivers/vmwarevcloudair" - "github.com/docker/machine/drivers/vmwarevsphere" - "github.com/docker/machine/libmachine/drivers/plugin" - "github.com/docker/machine/libmachine/drivers/plugin/localbinary" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/version" -) - -var AppHelpTemplate = `Usage: {{.Name}} {{if .Flags}}[OPTIONS] {{end}}COMMAND [arg...] - -{{.Usage}} - -Version: {{.Version}}{{if or .Author .Email}} - -Author:{{if .Author}} - {{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}} - {{.Email}}{{end}}{{end}} -{{if .Flags}} -Options: - {{range .Flags}}{{.}} - {{end}}{{end}} -Commands: - {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}} - {{end}} -Run '{{.Name}} COMMAND --help' for more information on a command. -` - -var CommandHelpTemplate = `Usage: docker-machine {{.Name}}{{if .Flags}} [OPTIONS]{{end}} [arg...] - -{{.Usage}}{{if .Description}} - -Description: - {{.Description}}{{end}}{{if .Flags}} - -Options: - {{range .Flags}} - {{.}}{{end}}{{ end }} -` - -func setDebugOutputLevel() { - // TODO: I'm not really a fan of this method and really would rather - // use -v / --verbose TBQH - for _, f := range os.Args { - if f == "-D" || f == "--debug" || f == "-debug" { - log.SetDebug(true) - } - } - - debugEnv := os.Getenv("MACHINE_DEBUG") - if debugEnv != "" { - showDebug, err := strconv.ParseBool(debugEnv) - if err != nil { - fmt.Fprintf(os.Stderr, "Error parsing boolean value from MACHINE_DEBUG: %s\n", err) - os.Exit(1) - } - log.SetDebug(showDebug) - } -} - -func main() { - if os.Getenv(localbinary.PluginEnvKey) == localbinary.PluginEnvVal { - driverName := os.Getenv(localbinary.PluginEnvDriverName) - runDriver(driverName) - return - } - - localbinary.CurrentBinaryIsDockerMachine = true - - setDebugOutputLevel() - cli.AppHelpTemplate = AppHelpTemplate - cli.CommandHelpTemplate = CommandHelpTemplate - app := cli.NewApp() - app.Name = filepath.Base(os.Args[0]) - app.Author = "Docker Machine Contributors" - app.Email = "https://github.com/docker/machine" - - app.Commands = commands.Commands - app.CommandNotFound = cmdNotFound - app.Usage = "Create and manage machines running Docker." - app.Version = version.FullVersion() - - log.Debug("Docker Machine Version: ", app.Version) - - app.Flags = []cli.Flag{ - cli.BoolFlag{ - Name: "debug, D", - Usage: "Enable debug mode", - }, - cli.StringFlag{ - EnvVar: "MACHINE_STORAGE_PATH", - Name: "storage-path, s", - Value: mcndirs.GetBaseDir(), - Usage: "Configures storage path", - }, - cli.StringFlag{ - EnvVar: "MACHINE_TLS_CA_CERT", - Name: "tls-ca-cert", - Usage: "CA to verify remotes against", - Value: "", - }, - cli.StringFlag{ - EnvVar: "MACHINE_TLS_CA_KEY", - Name: "tls-ca-key", - Usage: "Private key to generate certificates", - Value: "", - }, - cli.StringFlag{ - EnvVar: "MACHINE_TLS_CLIENT_CERT", - Name: "tls-client-cert", - Usage: "Client cert to use for TLS", - Value: "", - }, - cli.StringFlag{ - EnvVar: "MACHINE_TLS_CLIENT_KEY", - Name: "tls-client-key", - Usage: "Private key used in client TLS auth", - Value: "", - }, - cli.StringFlag{ - EnvVar: "MACHINE_GITHUB_API_TOKEN", - Name: "github-api-token", - Usage: "Token to use for requests to the Github API", - Value: "", - }, - cli.BoolFlag{ - EnvVar: "MACHINE_NATIVE_SSH", - Name: "native-ssh", - Usage: "Use the native (Go-based) SSH implementation.", - }, - cli.StringFlag{ - EnvVar: "MACHINE_BUGSNAG_API_TOKEN", - Name: "bugsnag-api-token", - Usage: "BugSnag API token for crash reporting", - Value: "", - }, - } - - if err := app.Run(os.Args); err != nil { - log.Error(err) - } -} - -func runDriver(driverName string) { - switch driverName { - case "amazonec2": - plugin.RegisterDriver(amazonec2.NewDriver("", "")) - case "azure": - plugin.RegisterDriver(azure.NewDriver("", "")) - case "digitalocean": - plugin.RegisterDriver(digitalocean.NewDriver("", "")) - case "exoscale": - plugin.RegisterDriver(exoscale.NewDriver("", "")) - case "generic": - plugin.RegisterDriver(generic.NewDriver("", "")) - case "google": - plugin.RegisterDriver(google.NewDriver("", "")) - case "hyperv": - plugin.RegisterDriver(hyperv.NewDriver("", "")) - case "none": - plugin.RegisterDriver(none.NewDriver("", "")) - case "openstack": - plugin.RegisterDriver(openstack.NewDriver("", "")) - case "rackspace": - plugin.RegisterDriver(rackspace.NewDriver("", "")) - case "softlayer": - plugin.RegisterDriver(softlayer.NewDriver("", "")) - case "virtualbox": - plugin.RegisterDriver(virtualbox.NewDriver("", "")) - case "vmwarefusion": - plugin.RegisterDriver(vmwarefusion.NewDriver("", "")) - case "vmwarevcloudair": - plugin.RegisterDriver(vmwarevcloudair.NewDriver("", "")) - case "vmwarevsphere": - plugin.RegisterDriver(vmwarevsphere.NewDriver("", "")) - default: - fmt.Fprintf(os.Stderr, "Unsupported driver: %s\n", driverName) - os.Exit(1) - } -} - -func cmdNotFound(c *cli.Context, command string) { - log.Errorf( - "%s: '%s' is not a %s command. See '%s --help'.", - c.App.Name, - command, - c.App.Name, - os.Args[0], - ) - os.Exit(1) -} diff --git a/vendor/github.com/docker/machine/cmd/machine_test.go b/vendor/github.com/docker/machine/cmd/machine_test.go deleted file mode 100644 index 0287158..0000000 --- a/vendor/github.com/docker/machine/cmd/machine_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "os" - "testing" - - "github.com/docker/machine/commands/mcndirs" -) - -func TestStorePathSetCorrectly(t *testing.T) { - mcndirs.BaseDir = "" - os.Args = []string{"docker-machine", "--storage-path", "/tmp/foo"} - main() - if mcndirs.BaseDir != "/tmp/foo" { - t.Fatal("Expected MACHINE_STORAGE_PATH environment variable to be /tmp/foo but was ", os.Getenv("MACHINE_STORAGE_PATH")) - } -} diff --git a/vendor/github.com/docker/machine/commands/active.go b/vendor/github.com/docker/machine/commands/active.go deleted file mode 100644 index 5941f83..0000000 --- a/vendor/github.com/docker/machine/commands/active.go +++ /dev/null @@ -1,60 +0,0 @@ -package commands - -import ( - "errors" - "fmt" - - "time" - - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/persist" - "github.com/docker/machine/libmachine/state" -) - -const ( - activeDefaultTimeout = 10 -) - -var ( - errNoActiveHost = errors.New("No active host found") - errActiveTimeout = errors.New("Error getting active host: timeout") -) - -func cmdActive(c CommandLine, api libmachine.API) error { - if len(c.Args()) > 0 { - return ErrTooManyArguments - } - - hosts, hostsInError, err := persist.LoadAllHosts(api) - if err != nil { - return fmt.Errorf("Error getting active host: %s", err) - } - - timeout := time.Duration(c.Int("timeout")) * time.Second - items := getHostListItems(hosts, hostsInError, timeout) - - active, err := activeHost(items) - - if err != nil { - return err - } - - fmt.Println(active.Name) - return nil -} - -func activeHost(items []HostListItem) (HostListItem, error) { - timeout := false - for _, item := range items { - if item.ActiveHost || item.ActiveSwarm { - return item, nil - } - if item.State == state.Timeout { - timeout = true - } - } - if timeout { - return HostListItem{}, errActiveTimeout - } - return HostListItem{}, errNoActiveHost -} diff --git a/vendor/github.com/docker/machine/commands/active_test.go b/vendor/github.com/docker/machine/commands/active_test.go deleted file mode 100644 index 08a18e6..0000000 --- a/vendor/github.com/docker/machine/commands/active_test.go +++ /dev/null @@ -1,110 +0,0 @@ -package commands - -import ( - "testing" - - "github.com/docker/machine/libmachine/state" - "github.com/stretchr/testify/assert" -) - -func TestCmdActiveNone(t *testing.T) { - hostListItems := []HostListItem{ - { - Name: "host1", - ActiveHost: false, - ActiveSwarm: false, - State: state.Running, - }, - { - Name: "host2", - ActiveHost: false, - ActiveSwarm: false, - State: state.Running, - }, - { - Name: "host3", - ActiveHost: false, - ActiveSwarm: false, - State: state.Running, - }, - } - _, err := activeHost(hostListItems) - assert.Equal(t, err, errNoActiveHost) -} - -func TestCmdActiveHost(t *testing.T) { - hostListItems := []HostListItem{ - { - Name: "host1", - ActiveHost: false, - ActiveSwarm: false, - State: state.Timeout, - }, - { - Name: "host2", - ActiveHost: true, - ActiveSwarm: false, - State: state.Running, - }, - { - Name: "host3", - ActiveHost: false, - ActiveSwarm: false, - State: state.Running, - }, - } - active, err := activeHost(hostListItems) - assert.Equal(t, err, nil) - assert.Equal(t, active.Name, "host2") -} - -func TestCmdActiveSwarm(t *testing.T) { - hostListItems := []HostListItem{ - { - Name: "host1", - ActiveHost: false, - ActiveSwarm: false, - State: state.Running, - }, - { - Name: "host2", - ActiveHost: false, - ActiveSwarm: false, - State: state.Running, - }, - { - Name: "host3", - ActiveHost: false, - ActiveSwarm: true, - State: state.Running, - }, - } - active, err := activeHost(hostListItems) - assert.Equal(t, err, nil) - assert.Equal(t, active.Name, "host3") -} - -func TestCmdActiveTimeout(t *testing.T) { - hostListItems := []HostListItem{ - { - Name: "host1", - ActiveHost: false, - ActiveSwarm: false, - State: state.Running, - }, - { - Name: "host2", - ActiveHost: false, - ActiveSwarm: false, - State: state.Running, - }, - { - Name: "host3", - ActiveHost: false, - ActiveSwarm: false, - State: state.Timeout, - }, - } - _, err := activeHost(hostListItems) - assert.Equal(t, err, errActiveTimeout) -} diff --git a/vendor/github.com/docker/machine/commands/commands.go b/vendor/github.com/docker/machine/commands/commands.go deleted file mode 100644 index 7da4f2e..0000000 --- a/vendor/github.com/docker/machine/commands/commands.go +++ /dev/null @@ -1,480 +0,0 @@ -package commands - -import ( - "errors" - "fmt" - "os" - "strings" - - "github.com/codegangsta/cli" - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/crashreport" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnerror" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/persist" - "github.com/docker/machine/libmachine/ssh" -) - -const ( - defaultMachineName = "default" -) - -var ( - ErrHostLoad = errors.New("All specified hosts had errors loading their configuration") - ErrNoDefault = fmt.Errorf("Error: No machine name(s) specified and no %q machine exists", defaultMachineName) - ErrNoMachineSpecified = errors.New("Error: Expected to get one or more machine names as arguments") - ErrExpectedOneMachine = errors.New("Error: Expected one machine name as an argument") - ErrTooManyArguments = errors.New("Error: Too many arguments given") - - osExit = func(code int) { os.Exit(code) } -) - -// CommandLine contains all the information passed to the commands on the command line. -type CommandLine interface { - ShowHelp() - - ShowVersion() - - Application() *cli.App - - Args() cli.Args - - IsSet(name string) bool - - Bool(name string) bool - - Int(name string) int - - String(name string) string - - StringSlice(name string) []string - - GlobalString(name string) string - - FlagNames() (names []string) - - Generic(name string) interface{} -} - -type contextCommandLine struct { - *cli.Context -} - -func (c *contextCommandLine) ShowHelp() { - cli.ShowCommandHelp(c.Context, c.Command.Name) -} - -func (c *contextCommandLine) ShowVersion() { - cli.ShowVersion(c.Context) -} - -func (c *contextCommandLine) Application() *cli.App { - return c.App -} - -// targetHost returns a specific host name if one is indicated by the first CLI -// arg, or the default host name if no host is specified. -func targetHost(c CommandLine, api libmachine.API) (string, error) { - if len(c.Args()) == 0 { - defaultExists, err := api.Exists(defaultMachineName) - if err != nil { - return "", fmt.Errorf("Error checking if host %q exists: %s", defaultMachineName, err) - } - - if defaultExists { - return defaultMachineName, nil - } - - return "", ErrNoDefault - } - - return c.Args()[0], nil -} - -func runAction(actionName string, c CommandLine, api libmachine.API) error { - var ( - hostsToLoad []string - ) - - // If user did not specify a machine name explicitly, use the 'default' - // machine if it exists. This allows short form commands such as - // 'docker-machine stop' for convenience. - if len(c.Args()) == 0 { - target, err := targetHost(c, api) - if err != nil { - return err - } - - hostsToLoad = []string{target} - } else { - hostsToLoad = c.Args() - } - - hosts, hostsInError := persist.LoadHosts(api, hostsToLoad) - - if len(hostsInError) > 0 { - errs := []error{} - for _, err := range hostsInError { - errs = append(errs, err) - } - return consolidateErrs(errs) - } - - if len(hosts) == 0 { - return ErrHostLoad - } - - if errs := runActionForeachMachine(actionName, hosts); len(errs) > 0 { - return consolidateErrs(errs) - } - - for _, h := range hosts { - if err := api.Save(h); err != nil { - return fmt.Errorf("Error saving host to store: %s", err) - } - } - - return nil -} - -func runCommand(command func(commandLine CommandLine, api libmachine.API) error) func(context *cli.Context) { - return func(context *cli.Context) { - api := libmachine.NewClient(mcndirs.GetBaseDir(), mcndirs.GetMachineCertDir()) - defer api.Close() - - if context.GlobalBool("native-ssh") { - api.SSHClientType = ssh.Native - } - api.GithubAPIToken = context.GlobalString("github-api-token") - api.Filestore.Path = context.GlobalString("storage-path") - - // TODO (nathanleclaire): These should ultimately be accessed - // through the libmachine client by the rest of the code and - // not through their respective modules. For now, however, - // they are also being set the way that they originally were - // set to preserve backwards compatibility. - mcndirs.BaseDir = api.Filestore.Path - mcnutils.GithubAPIToken = api.GithubAPIToken - ssh.SetDefaultClient(api.SSHClientType) - - if err := command(&contextCommandLine{context}, api); err != nil { - log.Error(err) - - if crashErr, ok := err.(crashreport.CrashError); ok { - crashReporter := crashreport.NewCrashReporter(mcndirs.GetBaseDir(), context.GlobalString("bugsnag-api-token")) - crashReporter.Send(crashErr) - - if _, ok := crashErr.Cause.(mcnerror.ErrDuringPreCreate); ok { - osExit(3) - return - } - } - - osExit(1) - return - } - } -} - -func confirmInput(msg string) (bool, error) { - fmt.Printf("%s (y/n): ", msg) - - var resp string - _, err := fmt.Scanln(&resp) - if err != nil { - return false, err - } - - confirmed := strings.Index(strings.ToLower(resp), "y") == 0 - return confirmed, nil -} - -var Commands = []cli.Command{ - { - Name: "active", - Usage: "Print which machine is active", - Action: runCommand(cmdActive), - Flags: []cli.Flag{ - cli.IntFlag{ - Name: "timeout, t", - Usage: fmt.Sprintf("Timeout in seconds, default to %ds", activeDefaultTimeout), - Value: activeDefaultTimeout, - }, - }, - }, - { - Name: "config", - Usage: "Print the connection config for machine", - Description: "Argument is a machine name.", - Action: runCommand(cmdConfig), - Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "swarm", - Usage: "Display the Swarm config instead of the Docker daemon", - }, - }, - }, - { - Flags: SharedCreateFlags, - Name: "create", - Usage: "Create a machine", - Description: fmt.Sprintf("Run '%s create --driver name --help' to include the create flags for that driver in the help text.", os.Args[0]), - Action: runCommand(cmdCreateOuter), - SkipFlagParsing: true, - }, - { - Name: "env", - Usage: "Display the commands to set up the environment for the Docker client", - Description: "Argument is a machine name.", - Action: runCommand(cmdEnv), - Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "swarm", - Usage: "Display the Swarm config instead of the Docker daemon", - }, - cli.StringFlag{ - Name: "shell", - Usage: "Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh], default is auto-detect", - }, - cli.BoolFlag{ - Name: "unset, u", - Usage: "Unset variables instead of setting them", - }, - cli.BoolFlag{ - Name: "no-proxy", - Usage: "Add machine IP to NO_PROXY environment variable", - }, - }, - }, - { - Name: "inspect", - Usage: "Inspect information about a machine", - Description: "Argument is a machine name.", - Action: runCommand(cmdInspect), - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "format, f", - Usage: "Format the output using the given go template.", - Value: "", - }, - }, - }, - { - Name: "ip", - Usage: "Get the IP address of a machine", - Description: "Argument(s) are one or more machine names.", - Action: runCommand(cmdIP), - }, - { - Name: "kill", - Usage: "Kill a machine", - Description: "Argument(s) are one or more machine names.", - Action: runCommand(cmdKill), - }, - { - Name: "ls", - Usage: "List machines", - Action: runCommand(cmdLs), - Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Enable quiet mode", - }, - cli.StringSliceFlag{ - Name: "filter", - Usage: "Filter output based on conditions provided", - Value: &cli.StringSlice{}, - }, - cli.IntFlag{ - Name: "timeout, t", - Usage: fmt.Sprintf("Timeout in seconds, default to %ds", lsDefaultTimeout), - Value: lsDefaultTimeout, - }, - cli.StringFlag{ - Name: "format, f", - Usage: "Pretty-print machines using a Go template", - }, - }, - }, - { - Name: "provision", - Usage: "Re-provision existing machines", - Action: runCommand(cmdProvision), - }, - { - Name: "regenerate-certs", - Usage: "Regenerate TLS Certificates for a machine", - Description: "Argument(s) are one or more machine names.", - Action: runCommand(cmdRegenerateCerts), - Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "force, f", - Usage: "Force rebuild and do not prompt", - }, - }, - }, - { - Name: "restart", - Usage: "Restart a machine", - Description: "Argument(s) are one or more machine names.", - Action: runCommand(cmdRestart), - }, - { - Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "force, f", - Usage: "Remove local configuration even if machine cannot be removed, also implies an automatic yes (`-y`)", - }, - cli.BoolFlag{ - Name: "y", - Usage: "Assumes automatic yes to proceed with remove, without prompting further user confirmation", - }, - }, - Name: "rm", - Usage: "Remove a machine", - Description: "Argument(s) are one or more machine names.", - Action: runCommand(cmdRm), - }, - { - Name: "ssh", - Usage: "Log into or run a command on a machine with SSH.", - Description: "Arguments are [machine-name] [command]", - Action: runCommand(cmdSSH), - SkipFlagParsing: true, - }, - { - Name: "scp", - Usage: "Copy files between machines", - Description: "Arguments are [[user@]machine:][path] [[user@]machine:][path].", - Action: runCommand(cmdScp), - Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "recursive, r", - Usage: "Copy files recursively (required to copy directories)", - }, - cli.BoolFlag{ - Name: "delta, d", - Usage: "Reduce amount of data sent over network by sending only the differences (uses rsync)", - }, - }, - }, - { - Name: "mount", - Usage: "Mount or unmount a directory from a machine with SSHFS.", - Description: "Arguments are [machine:][path] [mountpoint]", - Action: runCommand(cmdMount), - Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "unmount, u", - Usage: "Unmount instead of mount", - }, - }, - }, - { - Name: "start", - Usage: "Start a machine", - Description: "Argument(s) are one or more machine names.", - Action: runCommand(cmdStart), - }, - { - Name: "status", - Usage: "Get the status of a machine", - Description: "Argument is a machine name.", - Action: runCommand(cmdStatus), - }, - { - Name: "stop", - Usage: "Stop a machine", - Description: "Argument(s) are one or more machine names.", - Action: runCommand(cmdStop), - }, - { - Name: "upgrade", - Usage: "Upgrade a machine to the latest version of Docker", - Description: "Argument(s) are one or more machine names.", - Action: runCommand(cmdUpgrade), - }, - { - Name: "url", - Usage: "Get the URL of a machine", - Description: "Argument is a machine name.", - Action: runCommand(cmdURL), - }, - { - Name: "version", - Usage: "Show the Docker Machine version or a machine docker version", - Action: runCommand(cmdVersion), - }, -} - -func printIP(h *host.Host) func() error { - return func() error { - ip, err := h.Driver.GetIP() - if err != nil { - return fmt.Errorf("Error getting IP address: %s", err) - } - - fmt.Println(ip) - - return nil - } -} - -// machineCommand maps the command name to the corresponding machine command. -// We run commands concurrently and communicate back an error if there was one. -func machineCommand(actionName string, host *host.Host, errorChan chan<- error) { - // TODO: These actions should have their own type. - commands := map[string](func() error){ - "configureAuth": host.ConfigureAuth, - "start": host.Start, - "stop": host.Stop, - "restart": host.Restart, - "kill": host.Kill, - "upgrade": host.Upgrade, - "ip": printIP(host), - "provision": host.Provision, - } - - log.Debugf("command=%s machine=%s", actionName, host.Name) - - errorChan <- commands[actionName]() -} - -// runActionForeachMachine will run the command across multiple machines -func runActionForeachMachine(actionName string, machines []*host.Host) []error { - var ( - numConcurrentActions = 0 - errorChan = make(chan error) - errs = []error{} - ) - - for _, machine := range machines { - numConcurrentActions++ - go machineCommand(actionName, machine, errorChan) - } - - // TODO: We should probably only do 5-10 of these - // at a time, since otherwise cloud providers might - // rate limit us. - for i := 0; i < numConcurrentActions; i++ { - if err := <-errorChan; err != nil { - errs = append(errs, err) - } - } - - close(errorChan) - - return errs -} - -func consolidateErrs(errs []error) error { - finalErr := "" - for _, err := range errs { - finalErr = fmt.Sprintf("%s\n%s", finalErr, err) - } - - return errors.New(strings.TrimSpace(finalErr)) -} diff --git a/vendor/github.com/docker/machine/commands/commands_test.go b/vendor/github.com/docker/machine/commands/commands_test.go deleted file mode 100644 index 4b87101..0000000 --- a/vendor/github.com/docker/machine/commands/commands_test.go +++ /dev/null @@ -1,243 +0,0 @@ -package commands - -import ( - "errors" - "flag" - "testing" - - "github.com/codegangsta/cli" - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/crashreport" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/hosttest" - "github.com/docker/machine/libmachine/mcnerror" - "github.com/docker/machine/libmachine/provision" - "github.com/docker/machine/libmachine/state" - "github.com/stretchr/testify/assert" -) - -func TestRunActionForeachMachine(t *testing.T) { - defer provision.SetDetector(&provision.StandardDetector{}) - provision.SetDetector(&provision.FakeDetector{ - Provisioner: provision.NewNetstatProvisioner(), - }) - - // Assume a bunch of machines in randomly started or - // stopped states. - machines := []*host.Host{ - { - Name: "foo", - DriverName: "fakedriver", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - { - Name: "bar", - DriverName: "fakedriver", - Driver: &fakedriver.Driver{ - MockState: state.Stopped, - }, - }, - { - Name: "baz", - // Ssh, don't tell anyone but this - // driver only _thinks_ it's named - // virtualbox... (to test serial actions) - // It's actually FakeDriver! - DriverName: "virtualbox", - Driver: &fakedriver.Driver{ - MockState: state.Stopped, - }, - }, - { - Name: "spam", - DriverName: "virtualbox", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - { - Name: "eggs", - DriverName: "fakedriver", - Driver: &fakedriver.Driver{ - MockState: state.Stopped, - }, - }, - { - Name: "ham", - DriverName: "fakedriver", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - } - - runActionForeachMachine("start", machines) - - for _, machine := range machines { - machineState, _ := machine.Driver.GetState() - - assert.Equal(t, state.Running, machineState) - } - - runActionForeachMachine("stop", machines) - - for _, machine := range machines { - machineState, _ := machine.Driver.GetState() - - assert.Equal(t, state.Stopped, machineState) - } -} - -func TestPrintIPEmptyGivenLocalEngine(t *testing.T) { - stdoutGetter := commandstest.NewStdoutGetter() - defer stdoutGetter.Stop() - - host, _ := hosttest.GetDefaultTestHost() - err := printIP(host)() - - assert.NoError(t, err) - assert.Equal(t, "\n", stdoutGetter.Output()) -} - -func TestPrintIPPrintsGivenRemoteEngine(t *testing.T) { - stdoutGetter := commandstest.NewStdoutGetter() - defer stdoutGetter.Stop() - - host, _ := hosttest.GetDefaultTestHost() - host.Driver = &fakedriver.Driver{ - MockState: state.Running, - MockIP: "1.2.3.4", - } - err := printIP(host)() - - assert.NoError(t, err) - assert.Equal(t, "1.2.3.4\n", stdoutGetter.Output()) -} - -func TestConsolidateError(t *testing.T) { - cases := []struct { - inputErrs []error - expectedErr error - }{ - { - inputErrs: []error{ - errors.New("Couldn't remove host 'bar'"), - }, - expectedErr: errors.New("Couldn't remove host 'bar'"), - }, - { - inputErrs: []error{ - errors.New("Couldn't remove host 'bar'"), - errors.New("Couldn't remove host 'foo'"), - }, - expectedErr: errors.New("Couldn't remove host 'bar'\nCouldn't remove host 'foo'"), - }, - } - - for _, c := range cases { - assert.Equal(t, c.expectedErr, consolidateErrs(c.inputErrs)) - } -} - -type MockCrashReporter struct { - sent bool -} - -func (m *MockCrashReporter) Send(err crashreport.CrashError) error { - m.sent = true - return nil -} - -func TestSendCrashReport(t *testing.T) { - defer func(fnOsExit func(code int)) { osExit = fnOsExit }(osExit) - osExit = func(code int) {} - - defer func(factory func(baseDir string, apiKey string) crashreport.CrashReporter) { - crashreport.NewCrashReporter = factory - }(crashreport.NewCrashReporter) - - tests := []struct { - description string - err error - sent bool - }{ - { - description: "Should send crash error", - err: crashreport.CrashError{ - Cause: errors.New("BUG"), - Command: "command", - Context: "context", - DriverName: "virtualbox", - }, - sent: true, - }, - { - description: "Should not send standard error", - err: errors.New("BUG"), - sent: false, - }, - } - - for _, test := range tests { - mockCrashReporter := &MockCrashReporter{} - crashreport.NewCrashReporter = func(baseDir string, apiKey string) crashreport.CrashReporter { - return mockCrashReporter - } - - command := func(commandLine CommandLine, api libmachine.API) error { - return test.err - } - - context := cli.NewContext(cli.NewApp(), &flag.FlagSet{}, nil) - runCommand(command)(context) - - assert.Equal(t, test.sent, mockCrashReporter.sent, test.description) - } -} - -func TestReturnExitCode1onError(t *testing.T) { - command := func(commandLine CommandLine, api libmachine.API) error { - return errors.New("foo is not bar") - } - - exitCode := checkErrorCodeForCommand(command) - - assert.Equal(t, 1, exitCode) -} - -func TestReturnExitCode3onErrorDuringPreCreate(t *testing.T) { - command := func(commandLine CommandLine, api libmachine.API) error { - return crashreport.CrashError{ - Cause: mcnerror.ErrDuringPreCreate{ - Cause: errors.New("foo is not bar"), - }, - } - } - - exitCode := checkErrorCodeForCommand(command) - - assert.Equal(t, 3, exitCode) -} - -func checkErrorCodeForCommand(command func(commandLine CommandLine, api libmachine.API) error) int { - var setExitCode int - - originalOSExit := osExit - - defer func() { - osExit = originalOSExit - }() - - osExit = func(code int) { - setExitCode = code - } - - context := cli.NewContext(cli.NewApp(), &flag.FlagSet{}, nil) - runCommand(command)(context) - - return setExitCode -} diff --git a/vendor/github.com/docker/machine/commands/commandstest/fake_command_line.go b/vendor/github.com/docker/machine/commands/commandstest/fake_command_line.go deleted file mode 100644 index be9368e..0000000 --- a/vendor/github.com/docker/machine/commands/commandstest/fake_command_line.go +++ /dev/null @@ -1,100 +0,0 @@ -package commandstest - -import ( - "github.com/codegangsta/cli" -) - -type FakeFlagger struct { - Data map[string]interface{} -} - -type FakeCommandLine struct { - LocalFlags, GlobalFlags *FakeFlagger - HelpShown, VersionShown bool - CliArgs []string -} - -func (ff FakeFlagger) String(key string) string { - if value, ok := ff.Data[key]; ok { - return value.(string) - } - return "" -} - -func (ff FakeFlagger) StringSlice(key string) []string { - if value, ok := ff.Data[key]; ok { - return value.([]string) - } - return []string{} -} - -func (ff FakeFlagger) Int(key string) int { - if value, ok := ff.Data[key]; ok { - return value.(int) - } - return 0 -} - -func (ff FakeFlagger) Bool(key string) bool { - if value, ok := ff.Data[key]; ok { - return value.(bool) - } - return false -} - -func (fcli *FakeCommandLine) IsSet(key string) bool { - _, ok := fcli.LocalFlags.Data[key] - return ok -} - -func (fcli *FakeCommandLine) String(key string) string { - return fcli.LocalFlags.String(key) -} - -func (fcli *FakeCommandLine) StringSlice(key string) []string { - return fcli.LocalFlags.StringSlice(key) -} - -func (fcli *FakeCommandLine) Int(key string) int { - return fcli.LocalFlags.Int(key) -} - -func (fcli *FakeCommandLine) Bool(key string) bool { - if fcli.LocalFlags == nil { - return false - } - return fcli.LocalFlags.Bool(key) -} - -func (fcli *FakeCommandLine) GlobalString(key string) string { - return fcli.GlobalFlags.String(key) -} - -func (fcli *FakeCommandLine) Generic(name string) interface{} { - return fcli.LocalFlags.Data[name] -} - -func (fcli *FakeCommandLine) FlagNames() []string { - flagNames := []string{} - for key := range fcli.LocalFlags.Data { - flagNames = append(flagNames, key) - } - - return flagNames -} - -func (fcli *FakeCommandLine) ShowHelp() { - fcli.HelpShown = true -} - -func (fcli *FakeCommandLine) Application() *cli.App { - return cli.NewApp() -} - -func (fcli *FakeCommandLine) Args() cli.Args { - return fcli.CliArgs -} - -func (fcli *FakeCommandLine) ShowVersion() { - fcli.VersionShown = true -} diff --git a/vendor/github.com/docker/machine/commands/commandstest/stdout_capture.go b/vendor/github.com/docker/machine/commands/commandstest/stdout_capture.go deleted file mode 100644 index 926aed3..0000000 --- a/vendor/github.com/docker/machine/commands/commandstest/stdout_capture.go +++ /dev/null @@ -1,54 +0,0 @@ -package commandstest - -import ( - "bytes" - "io" - - "os" -) - -var ( - stdout *os.File -) - -func init() { - stdout = os.Stdout -} - -type StdoutGetter interface { - Output() string - Stop() -} - -type stdoutCapturer struct { - stdout *os.File - output chan string -} - -func NewStdoutGetter() StdoutGetter { - r, w, _ := os.Pipe() - os.Stdout = w - - output := make(chan string) - go func() { - var testOutput bytes.Buffer - io.Copy(&testOutput, r) - output <- testOutput.String() - }() - - return &stdoutCapturer{ - stdout: w, - output: output, - } -} - -func (c *stdoutCapturer) Output() string { - c.stdout.Close() - text := <-c.output - close(c.output) - return text -} - -func (c *stdoutCapturer) Stop() { - os.Stdout = stdout -} diff --git a/vendor/github.com/docker/machine/commands/config.go b/vendor/github.com/docker/machine/commands/config.go deleted file mode 100644 index 0f81217..0000000 --- a/vendor/github.com/docker/machine/commands/config.go +++ /dev/null @@ -1,46 +0,0 @@ -package commands - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/check" - "github.com/docker/machine/libmachine/log" -) - -func cmdConfig(c CommandLine, api libmachine.API) error { - // Ensure that log messages always go to stderr when this command is - // being run (it is intended to be run in a subshell) - log.SetOutWriter(os.Stderr) - - target, err := targetHost(c, api) - if err != nil { - return err - } - - host, err := api.Load(target) - if err != nil { - return err - } - - dockerHost, _, err := check.DefaultConnChecker.Check(host, c.Bool("swarm")) - if err != nil { - return fmt.Errorf("Error running connection boilerplate: %s", err) - } - - log.Debug(dockerHost) - - tlsCACert := filepath.Join(mcndirs.GetMachineDir(), host.Name, "ca.pem") - tlsCert := filepath.Join(mcndirs.GetMachineDir(), host.Name, "cert.pem") - tlsKey := filepath.Join(mcndirs.GetMachineDir(), host.Name, "key.pem") - - // TODO(nathanleclaire): These magic strings for the certificate file - // names should be cross-package constants. - fmt.Printf("--tlsverify\n--tlscacert=%q\n--tlscert=%q\n--tlskey=%q\n-H=%s\n", - tlsCACert, tlsCert, tlsKey, dockerHost) - - return nil -} diff --git a/vendor/github.com/docker/machine/commands/create.go b/vendor/github.com/docker/machine/commands/create.go deleted file mode 100644 index 1e17dee..0000000 --- a/vendor/github.com/docker/machine/commands/create.go +++ /dev/null @@ -1,462 +0,0 @@ -package commands - -import ( - "encoding/json" - "flag" - "fmt" - "os" - "path/filepath" - "regexp" - "sort" - "strings" - - "errors" - - "time" - - "github.com/codegangsta/cli" - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/crashreport" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/drivers/rpc" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnerror" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/swarm" -) - -var ( - errNoMachineName = errors.New("Error: No machine name specified") -) - -var ( - SharedCreateFlags = []cli.Flag{ - cli.StringFlag{ - Name: "driver, d", - Usage: "Driver to create machine with.", - Value: "virtualbox", - EnvVar: "MACHINE_DRIVER", - }, - cli.StringFlag{ - Name: "engine-install-url", - Usage: "Custom URL to use for engine installation", - Value: drivers.DefaultEngineInstallURL, - EnvVar: "MACHINE_DOCKER_INSTALL_URL", - }, - cli.StringSliceFlag{ - Name: "engine-opt", - Usage: "Specify arbitrary flags to include with the created engine in the form flag=value", - Value: &cli.StringSlice{}, - }, - cli.StringSliceFlag{ - Name: "engine-insecure-registry", - Usage: "Specify insecure registries to allow with the created engine", - Value: &cli.StringSlice{}, - }, - cli.StringSliceFlag{ - Name: "engine-registry-mirror", - Usage: "Specify registry mirrors to use", - Value: &cli.StringSlice{}, - EnvVar: "ENGINE_REGISTRY_MIRROR", - }, - cli.StringSliceFlag{ - Name: "engine-label", - Usage: "Specify labels for the created engine", - Value: &cli.StringSlice{}, - }, - cli.StringFlag{ - Name: "engine-storage-driver", - Usage: "Specify a storage driver to use with the engine", - }, - cli.StringSliceFlag{ - Name: "engine-env", - Usage: "Specify environment variables to set in the engine", - Value: &cli.StringSlice{}, - }, - cli.BoolFlag{ - Name: "swarm", - Usage: "Configure Machine to join a Swarm cluster", - }, - cli.StringFlag{ - Name: "swarm-image", - Usage: "Specify Docker image to use for Swarm", - Value: "swarm:latest", - EnvVar: "MACHINE_SWARM_IMAGE", - }, - cli.BoolFlag{ - Name: "swarm-master", - Usage: "Configure Machine to be a Swarm master", - }, - cli.StringFlag{ - Name: "swarm-discovery", - Usage: "Discovery service to use with Swarm", - Value: "", - }, - cli.StringFlag{ - Name: "swarm-strategy", - Usage: "Define a default scheduling strategy for Swarm", - Value: "spread", - }, - cli.StringSliceFlag{ - Name: "swarm-opt", - Usage: "Define arbitrary flags for Swarm master", - Value: &cli.StringSlice{}, - }, - cli.StringSliceFlag{ - Name: "swarm-join-opt", - Usage: "Define arbitrary flags for Swarm join", - Value: &cli.StringSlice{}, - }, - cli.StringFlag{ - Name: "swarm-host", - Usage: "ip/socket to listen on for Swarm master", - Value: "tcp://0.0.0.0:3376", - }, - cli.StringFlag{ - Name: "swarm-addr", - Usage: "addr to advertise for Swarm (default: detect and use the machine IP)", - Value: "", - }, - cli.BoolFlag{ - Name: "swarm-experimental", - Usage: "Enable Swarm experimental features", - }, - cli.StringSliceFlag{ - Name: "tls-san", - Usage: "Support extra SANs for TLS certs", - Value: &cli.StringSlice{}, - }, - } -) - -func cmdCreateInner(c CommandLine, api libmachine.API) error { - if len(c.Args()) > 1 { - return fmt.Errorf("Invalid command line. Found extra arguments %v", c.Args()[1:]) - } - - name := c.Args().First() - if name == "" { - c.ShowHelp() - return errNoMachineName - } - - validName := host.ValidateHostName(name) - if !validName { - return fmt.Errorf("Error creating machine: %s", mcnerror.ErrInvalidHostname) - } - - if err := validateSwarmDiscovery(c.String("swarm-discovery")); err != nil { - return fmt.Errorf("Error parsing swarm discovery: %s", err) - } - - // TODO: Fix hacky JSON solution - rawDriver, err := json.Marshal(&drivers.BaseDriver{ - MachineName: name, - StorePath: c.GlobalString("storage-path"), - }) - if err != nil { - return fmt.Errorf("Error attempting to marshal bare driver data: %s", err) - } - - driverName := c.String("driver") - h, err := api.NewHost(driverName, rawDriver) - if err != nil { - return fmt.Errorf("Error getting new host: %s", err) - } - - h.HostOptions = &host.Options{ - AuthOptions: &auth.Options{ - CertDir: mcndirs.GetMachineCertDir(), - CaCertPath: tlsPath(c, "tls-ca-cert", "ca.pem"), - CaPrivateKeyPath: tlsPath(c, "tls-ca-key", "ca-key.pem"), - ClientCertPath: tlsPath(c, "tls-client-cert", "cert.pem"), - ClientKeyPath: tlsPath(c, "tls-client-key", "key.pem"), - ServerCertPath: filepath.Join(mcndirs.GetMachineDir(), name, "server.pem"), - ServerKeyPath: filepath.Join(mcndirs.GetMachineDir(), name, "server-key.pem"), - StorePath: filepath.Join(mcndirs.GetMachineDir(), name), - ServerCertSANs: c.StringSlice("tls-san"), - }, - EngineOptions: &engine.Options{ - ArbitraryFlags: c.StringSlice("engine-opt"), - Env: c.StringSlice("engine-env"), - InsecureRegistry: c.StringSlice("engine-insecure-registry"), - Labels: c.StringSlice("engine-label"), - RegistryMirror: c.StringSlice("engine-registry-mirror"), - StorageDriver: c.String("engine-storage-driver"), - TLSVerify: true, - InstallURL: c.String("engine-install-url"), - }, - SwarmOptions: &swarm.Options{ - IsSwarm: c.Bool("swarm") || c.Bool("swarm-master"), - Image: c.String("swarm-image"), - Agent: c.Bool("swarm"), - Master: c.Bool("swarm-master"), - Discovery: c.String("swarm-discovery"), - Address: c.String("swarm-addr"), - Host: c.String("swarm-host"), - Strategy: c.String("swarm-strategy"), - ArbitraryFlags: c.StringSlice("swarm-opt"), - ArbitraryJoinFlags: c.StringSlice("swarm-join-opt"), - IsExperimental: c.Bool("swarm-experimental"), - }, - } - - exists, err := api.Exists(h.Name) - if err != nil { - return fmt.Errorf("Error checking if host exists: %s", err) - } - if exists { - return mcnerror.ErrHostAlreadyExists{ - Name: h.Name, - } - } - - // driverOpts is the actual data we send over the wire to set the - // driver parameters (an interface fulfilling drivers.DriverOptions, - // concrete type rpcdriver.RpcFlags). - mcnFlags := h.Driver.GetCreateFlags() - driverOpts := getDriverOpts(c, mcnFlags) - - if err := h.Driver.SetConfigFromFlags(driverOpts); err != nil { - return fmt.Errorf("Error setting machine configuration from flags provided: %s", err) - } - - if err := api.Create(h); err != nil { - // Wait for all the logs to reach the client - time.Sleep(2 * time.Second) - - vBoxLog := "" - if h.DriverName == "virtualbox" { - vBoxLog = filepath.Join(api.GetMachinesDir(), h.Name, h.Name, "Logs", "VBox.log") - } - - return crashreport.CrashError{ - Cause: err, - Command: "Create", - Context: "api.performCreate", - DriverName: h.DriverName, - LogFilePath: vBoxLog, - } - } - - if err := api.Save(h); err != nil { - return fmt.Errorf("Error attempting to save store: %s", err) - } - - log.Infof("To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: %s env %s", os.Args[0], name) - - return nil -} - -// The following function is needed because the CLI acrobatics that we're doing -// (with having an "outer" and "inner" function each with their own custom -// settings and flag parsing needs) are not well supported by codegangsta/cli. -// -// Instead of trying to make a convoluted series of flag parsing and relying on -// codegangsta/cli internals work well, we simply read the flags we're -// interested in from the outer function into module-level variables, and then -// use them from the "inner" function. -// -// I'm not very pleased about this, but it seems to be the only decent -// compromise without drastically modifying codegangsta/cli internals or our -// own CLI. -func flagHackLookup(flagName string) string { - // e.g. "-d" for "--driver" - flagPrefix := flagName[1:3] - - // TODO: Should we support -flag-name (single hyphen) syntax as well? - for i, arg := range os.Args { - if strings.Contains(arg, flagPrefix) { - // format '--driver foo' or '-d foo' - if arg == flagPrefix || arg == flagName { - if i+1 < len(os.Args) { - return os.Args[i+1] - } - } - - // format '--driver=foo' or '-d=foo' - if strings.HasPrefix(arg, flagPrefix+"=") || strings.HasPrefix(arg, flagName+"=") { - return strings.Split(arg, "=")[1] - } - } - } - - return "" -} - -func cmdCreateOuter(c CommandLine, api libmachine.API) error { - const ( - flagLookupMachineName = "flag-lookup" - ) - - // We didn't recognize the driver name. - driverName := flagHackLookup("--driver") - if driverName == "" { - //TODO: Check Environment have to include flagHackLookup function. - driverName = os.Getenv("MACHINE_DRIVER") - if driverName == "" { - driverName = "virtualbox" - } - } - - // TODO: Fix hacky JSON solution - rawDriver, err := json.Marshal(&drivers.BaseDriver{ - MachineName: flagLookupMachineName, - }) - if err != nil { - return fmt.Errorf("Error attempting to marshal bare driver data: %s", err) - } - - h, err := api.NewHost(driverName, rawDriver) - if err != nil { - return err - } - - // TODO: So much flag manipulation and voodoo here, it seems to be - // asking for trouble. - // - // mcnFlags is the data we get back over the wire (type mcnflag.Flag) - // to indicate which parameters are available. - mcnFlags := h.Driver.GetCreateFlags() - - // This bit will actually make "create" display the correct flags based - // on the requested driver. - cliFlags, err := convertMcnFlagsToCliFlags(mcnFlags) - if err != nil { - return fmt.Errorf("Error trying to convert provided driver flags to cli flags: %s", err) - } - - for i := range c.Application().Commands { - cmd := &c.Application().Commands[i] - if cmd.HasName("create") { - cmd = addDriverFlagsToCommand(cliFlags, cmd) - } - } - - return c.Application().Run(os.Args) -} - -func getDriverOpts(c CommandLine, mcnflags []mcnflag.Flag) drivers.DriverOptions { - // TODO: This function is pretty damn YOLO and would benefit from some - // sanity checking around types and assertions. - // - // But, we need it so that we can actually send the flags for creating - // a machine over the wire (cli.Context is a no go since there is so - // much stuff in it). - driverOpts := rpcdriver.RPCFlags{ - Values: make(map[string]interface{}), - } - - for _, f := range mcnflags { - driverOpts.Values[f.String()] = f.Default() - - // Hardcoded logic for boolean... :( - if f.Default() == nil { - driverOpts.Values[f.String()] = false - } - } - - for _, name := range c.FlagNames() { - getter, ok := c.Generic(name).(flag.Getter) - if ok { - driverOpts.Values[name] = getter.Get() - } else { - // TODO: This is pretty hacky. StringSlice is the only - // type so far we have to worry about which is not a - // Getter, though. - if c.IsSet(name) { - driverOpts.Values[name] = c.StringSlice(name) - } - } - } - - return driverOpts -} - -func convertMcnFlagsToCliFlags(mcnFlags []mcnflag.Flag) ([]cli.Flag, error) { - cliFlags := []cli.Flag{} - for _, f := range mcnFlags { - switch t := f.(type) { - // TODO: It seems pretty wrong to just default "nil" to this, - // but cli.BoolFlag doesn't have a "Value" field (false is - // always the default) - case *mcnflag.BoolFlag: - f := f.(*mcnflag.BoolFlag) - cliFlags = append(cliFlags, cli.BoolFlag{ - Name: f.Name, - EnvVar: f.EnvVar, - Usage: f.Usage, - }) - case *mcnflag.IntFlag: - f := f.(*mcnflag.IntFlag) - cliFlags = append(cliFlags, cli.IntFlag{ - Name: f.Name, - EnvVar: f.EnvVar, - Usage: f.Usage, - Value: f.Value, - }) - case *mcnflag.StringFlag: - f := f.(*mcnflag.StringFlag) - cliFlags = append(cliFlags, cli.StringFlag{ - Name: f.Name, - EnvVar: f.EnvVar, - Usage: f.Usage, - Value: f.Value, - }) - case *mcnflag.StringSliceFlag: - f := f.(*mcnflag.StringSliceFlag) - cliFlags = append(cliFlags, cli.StringSliceFlag{ - Name: f.Name, - EnvVar: f.EnvVar, - Usage: f.Usage, - - //TODO: Is this used with defaults? Can we convert the literal []string to cli.StringSlice properly? - Value: &cli.StringSlice{}, - }) - default: - log.Warn("Flag is ", f) - return nil, fmt.Errorf("Flag is unrecognized flag type: %T", t) - } - } - - return cliFlags, nil -} - -func addDriverFlagsToCommand(cliFlags []cli.Flag, cmd *cli.Command) *cli.Command { - cmd.Flags = append(SharedCreateFlags, cliFlags...) - cmd.SkipFlagParsing = false - cmd.Action = runCommand(cmdCreateInner) - sort.Sort(ByFlagName(cmd.Flags)) - - return cmd -} - -func validateSwarmDiscovery(discovery string) error { - if discovery == "" { - return nil - } - - matched, err := regexp.MatchString(`[^:]*://.*`, discovery) - if err != nil { - return err - } - - if matched { - return nil - } - - return fmt.Errorf("Swarm Discovery URL was in the wrong format: %s", discovery) -} - -func tlsPath(c CommandLine, flag string, defaultName string) string { - path := c.GlobalString(flag) - if path != "" { - return path - } - - return filepath.Join(mcndirs.GetMachineCertDir(), defaultName) -} diff --git a/vendor/github.com/docker/machine/commands/create_test.go b/vendor/github.com/docker/machine/commands/create_test.go deleted file mode 100644 index ae8fa43..0000000 --- a/vendor/github.com/docker/machine/commands/create_test.go +++ /dev/null @@ -1,119 +0,0 @@ -package commands - -import ( - "testing" - - "flag" - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/stretchr/testify/assert" -) - -func TestValidateSwarmDiscoveryErrorsGivenInvalidURL(t *testing.T) { - err := validateSwarmDiscovery("foo") - assert.Error(t, err) -} - -func TestValidateSwarmDiscoveryAcceptsEmptyString(t *testing.T) { - err := validateSwarmDiscovery("") - assert.NoError(t, err) -} - -func TestValidateSwarmDiscoveryAcceptsValidFormat(t *testing.T) { - err := validateSwarmDiscovery("token://deadbeefcafe") - assert.NoError(t, err) -} - -type fakeFlagGetter struct { - flag.Value - value interface{} -} - -func (ff fakeFlagGetter) Get() interface{} { - return ff.value -} - -var nilStringSlice []string - -var getDriverOptsFlags = []mcnflag.Flag{ - mcnflag.BoolFlag{ - Name: "bool", - }, - mcnflag.IntFlag{ - Name: "int", - }, - mcnflag.IntFlag{ - Name: "int_defaulted", - Value: 42, - }, - mcnflag.StringFlag{ - Name: "string", - }, - mcnflag.StringFlag{ - Name: "string_defaulted", - Value: "bob", - }, - mcnflag.StringSliceFlag{ - Name: "stringslice", - }, - mcnflag.StringSliceFlag{ - Name: "stringslice_defaulted", - Value: []string{"joe"}, - }, -} - -var getDriverOptsTests = []struct { - data map[string]interface{} - expected map[string]interface{} -}{ - { - expected: map[string]interface{}{ - "bool": false, - "int": 0, - "int_defaulted": 42, - "string": "", - "string_defaulted": "bob", - "stringslice": nilStringSlice, - "stringslice_defaulted": []string{"joe"}, - }, - }, - { - data: map[string]interface{}{ - "bool": fakeFlagGetter{value: true}, - "int": fakeFlagGetter{value: 42}, - "int_defaulted": fakeFlagGetter{value: 37}, - "string": fakeFlagGetter{value: "jake"}, - "string_defaulted": fakeFlagGetter{value: "george"}, - // NB: StringSlices are not flag.Getters. - "stringslice": []string{"ford"}, - "stringslice_defaulted": []string{"zaphod", "arthur"}, - }, - expected: map[string]interface{}{ - "bool": true, - "int": 42, - "int_defaulted": 37, - "string": "jake", - "string_defaulted": "george", - "stringslice": []string{"ford"}, - "stringslice_defaulted": []string{"zaphod", "arthur"}, - }, - }, -} - -func TestGetDriverOpts(t *testing.T) { - for _, tt := range getDriverOptsTests { - commandLine := &commandstest.FakeCommandLine{ - LocalFlags: &commandstest.FakeFlagger{ - Data: tt.data, - }, - } - driverOpts := getDriverOpts(commandLine, getDriverOptsFlags) - assert.Equal(t, tt.expected["bool"], driverOpts.Bool("bool")) - assert.Equal(t, tt.expected["int"], driverOpts.Int("int")) - assert.Equal(t, tt.expected["int_defaulted"], driverOpts.Int("int_defaulted")) - assert.Equal(t, tt.expected["string"], driverOpts.String("string")) - assert.Equal(t, tt.expected["string_defaulted"], driverOpts.String("string_defaulted")) - assert.Equal(t, tt.expected["stringslice"], driverOpts.StringSlice("stringslice")) - assert.Equal(t, tt.expected["stringslice_defaulted"], driverOpts.StringSlice("stringslice_defaulted")) - } -} diff --git a/vendor/github.com/docker/machine/commands/env.go b/vendor/github.com/docker/machine/commands/env.go deleted file mode 100644 index d0c9d16..0000000 --- a/vendor/github.com/docker/machine/commands/env.go +++ /dev/null @@ -1,275 +0,0 @@ -package commands - -import ( - "errors" - "fmt" - "os" - "path/filepath" - "runtime" - "strings" - "text/template" - - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/check" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/shell" -) - -const ( - envTmpl = `{{ .Prefix }}DOCKER_TLS_VERIFY{{ .Delimiter }}{{ .DockerTLSVerify }}{{ .Suffix }}{{ .Prefix }}DOCKER_HOST{{ .Delimiter }}{{ .DockerHost }}{{ .Suffix }}{{ .Prefix }}DOCKER_CERT_PATH{{ .Delimiter }}{{ .DockerCertPath }}{{ .Suffix }}{{ .Prefix }}DOCKER_MACHINE_NAME{{ .Delimiter }}{{ .MachineName }}{{ .Suffix }}{{ if .ComposePathsVar }}{{ .Prefix }}COMPOSE_CONVERT_WINDOWS_PATHS{{ .Delimiter }}true{{ .Suffix }}{{end}}{{ if .NoProxyVar }}{{ .Prefix }}{{ .NoProxyVar }}{{ .Delimiter }}{{ .NoProxyValue }}{{ .Suffix }}{{end}}{{ .UsageHint }}` -) - -var ( - errImproperUnsetEnvArgs = errors.New("Error: Expected no machine name when the -u flag is present") - defaultUsageHinter UsageHintGenerator - runtimeOS = func() string { return runtime.GOOS } -) - -func init() { - defaultUsageHinter = &EnvUsageHintGenerator{} -} - -type ShellConfig struct { - Prefix string - Delimiter string - Suffix string - DockerCertPath string - DockerHost string - DockerTLSVerify string - UsageHint string - MachineName string - NoProxyVar string - NoProxyValue string - ComposePathsVar bool -} - -func cmdEnv(c CommandLine, api libmachine.API) error { - var ( - err error - shellCfg *ShellConfig - ) - - // Ensure that log messages always go to stderr when this command is - // being run (it is intended to be run in a subshell) - log.SetOutWriter(os.Stderr) - - if c.Bool("unset") { - shellCfg, err = shellCfgUnset(c, api) - if err != nil { - return err - } - } else { - shellCfg, err = shellCfgSet(c, api) - if err != nil { - return err - } - } - - return executeTemplateStdout(shellCfg) -} - -func shellCfgSet(c CommandLine, api libmachine.API) (*ShellConfig, error) { - if len(c.Args()) > 1 { - return nil, ErrExpectedOneMachine - } - - target, err := targetHost(c, api) - if err != nil { - return nil, err - } - - host, err := api.Load(target) - if err != nil { - return nil, err - } - - dockerHost, _, err := check.DefaultConnChecker.Check(host, c.Bool("swarm")) - if err != nil { - return nil, fmt.Errorf("Error checking TLS connection: %s", err) - } - - userShell, err := getShell(c.String("shell")) - if err != nil { - return nil, err - } - - shellCfg := &ShellConfig{ - DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), host.Name), - DockerHost: dockerHost, - DockerTLSVerify: "1", - UsageHint: defaultUsageHinter.GenerateUsageHint(userShell, os.Args), - MachineName: host.Name, - } - - if c.Bool("no-proxy") { - ip, err := host.Driver.GetIP() - if err != nil { - return nil, fmt.Errorf("Error getting host IP: %s", err) - } - - noProxyVar, noProxyValue := findNoProxyFromEnv() - - // add the docker host to the no_proxy list idempotently - switch { - case noProxyValue == "": - noProxyValue = ip - case strings.Contains(noProxyValue, ip): - //ip already in no_proxy list, nothing to do - default: - noProxyValue = fmt.Sprintf("%s,%s", noProxyValue, ip) - } - - shellCfg.NoProxyVar = noProxyVar - shellCfg.NoProxyValue = noProxyValue - } - - if runtimeOS() == "windows" { - shellCfg.ComposePathsVar = true - } - - switch userShell { - case "fish": - shellCfg.Prefix = "set -gx " - shellCfg.Suffix = "\";\n" - shellCfg.Delimiter = " \"" - case "powershell": - shellCfg.Prefix = "$Env:" - shellCfg.Suffix = "\"\n" - shellCfg.Delimiter = " = \"" - case "cmd": - shellCfg.Prefix = "SET " - shellCfg.Suffix = "\n" - shellCfg.Delimiter = "=" - case "tcsh": - shellCfg.Prefix = "setenv " - shellCfg.Suffix = "\";\n" - shellCfg.Delimiter = " \"" - case "emacs": - shellCfg.Prefix = "(setenv \"" - shellCfg.Suffix = "\")\n" - shellCfg.Delimiter = "\" \"" - default: - shellCfg.Prefix = "export " - shellCfg.Suffix = "\"\n" - shellCfg.Delimiter = "=\"" - } - - return shellCfg, nil -} - -func shellCfgUnset(c CommandLine, api libmachine.API) (*ShellConfig, error) { - if len(c.Args()) != 0 { - return nil, errImproperUnsetEnvArgs - } - - userShell, err := getShell(c.String("shell")) - if err != nil { - return nil, err - } - - shellCfg := &ShellConfig{ - UsageHint: defaultUsageHinter.GenerateUsageHint(userShell, os.Args), - } - - if c.Bool("no-proxy") { - shellCfg.NoProxyVar, shellCfg.NoProxyValue = findNoProxyFromEnv() - } - - switch userShell { - case "fish": - shellCfg.Prefix = "set -e " - shellCfg.Suffix = ";\n" - shellCfg.Delimiter = "" - case "powershell": - shellCfg.Prefix = `Remove-Item Env:\\` - shellCfg.Suffix = "\n" - shellCfg.Delimiter = "" - case "cmd": - shellCfg.Prefix = "SET " - shellCfg.Suffix = "\n" - shellCfg.Delimiter = "=" - case "emacs": - shellCfg.Prefix = "(setenv \"" - shellCfg.Suffix = ")\n" - shellCfg.Delimiter = "\" nil" - case "tcsh": - shellCfg.Prefix = "unsetenv " - shellCfg.Suffix = ";\n" - shellCfg.Delimiter = "" - default: - shellCfg.Prefix = "unset " - shellCfg.Suffix = "\n" - shellCfg.Delimiter = "" - } - - return shellCfg, nil -} - -func executeTemplateStdout(shellCfg *ShellConfig) error { - t := template.New("envConfig") - tmpl, err := t.Parse(envTmpl) - if err != nil { - return err - } - - return tmpl.Execute(os.Stdout, shellCfg) -} - -func getShell(userShell string) (string, error) { - if userShell != "" { - return userShell, nil - } - return shell.Detect() -} - -func findNoProxyFromEnv() (string, string) { - // first check for an existing lower case no_proxy var - noProxyVar := "no_proxy" - noProxyValue := os.Getenv("no_proxy") - - // otherwise default to allcaps HTTP_PROXY - if noProxyValue == "" { - noProxyVar = "NO_PROXY" - noProxyValue = os.Getenv("NO_PROXY") - } - return noProxyVar, noProxyValue -} - -type UsageHintGenerator interface { - GenerateUsageHint(string, []string) string -} - -type EnvUsageHintGenerator struct{} - -func (g *EnvUsageHintGenerator) GenerateUsageHint(userShell string, args []string) string { - cmd := "" - comment := "#" - - dockerMachinePath := args[0] - if strings.Contains(dockerMachinePath, " ") || strings.Contains(dockerMachinePath, `\`) { - args[0] = fmt.Sprintf("\"%s\"", dockerMachinePath) - } - - commandLine := strings.Join(args, " ") - - switch userShell { - case "fish": - cmd = fmt.Sprintf("eval (%s)", commandLine) - case "powershell": - cmd = fmt.Sprintf("& %s | Invoke-Expression", commandLine) - case "cmd": - cmd = fmt.Sprintf("\t@FOR /f \"tokens=*\" %%i IN ('%s') DO @%%i", commandLine) - comment = "REM" - case "emacs": - cmd = fmt.Sprintf("(with-temp-buffer (shell-command \"%s\" (current-buffer)) (eval-buffer))", commandLine) - comment = ";;" - case "tcsh": - cmd = fmt.Sprintf("eval `%s`", commandLine) - comment = ":" - default: - cmd = fmt.Sprintf("eval $(%s)", commandLine) - } - - return fmt.Sprintf("%s Run this command to configure your shell: \n%s %s\n", comment, comment, cmd) -} diff --git a/vendor/github.com/docker/machine/commands/env_test.go b/vendor/github.com/docker/machine/commands/env_test.go deleted file mode 100644 index 545849f..0000000 --- a/vendor/github.com/docker/machine/commands/env_test.go +++ /dev/null @@ -1,688 +0,0 @@ -package commands - -import ( - "os" - "path/filepath" - "testing" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/check" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/libmachinetest" - "github.com/docker/machine/libmachine/state" - "github.com/stretchr/testify/assert" -) - -type FakeConnChecker struct { - DockerHost string - AuthOptions *auth.Options - Err error -} - -func (fcc *FakeConnChecker) Check(_ *host.Host, _ bool) (string, *auth.Options, error) { - return fcc.DockerHost, fcc.AuthOptions, fcc.Err -} - -type SimpleUsageHintGenerator struct { - Hint string -} - -func (suhg *SimpleUsageHintGenerator) GenerateUsageHint(_ string, _ []string) string { - return suhg.Hint -} - -func TestHints(t *testing.T) { - var tests = []struct { - userShell string - commandLine []string - expectedHints string - }{ - {"", []string{"machine", "env", "default"}, "# Run this command to configure your shell: \n# eval $(machine env default)\n"}, - {"", []string{"machine", "env", "--no-proxy", "default"}, "# Run this command to configure your shell: \n# eval $(machine env --no-proxy default)\n"}, - {"", []string{"machine", "env", "--swarm", "default"}, "# Run this command to configure your shell: \n# eval $(machine env --swarm default)\n"}, - {"", []string{"machine", "env", "--no-proxy", "--swarm", "default"}, "# Run this command to configure your shell: \n# eval $(machine env --no-proxy --swarm default)\n"}, - {"", []string{"machine", "env", "--unset"}, "# Run this command to configure your shell: \n# eval $(machine env --unset)\n"}, - {"", []string{`C:\\Program Files\docker-machine.exe`, "env", "default"}, "# Run this command to configure your shell: \n# eval $(\"C:\\\\Program Files\\docker-machine.exe\" env default)\n"}, - {"", []string{`C:\\Me\docker-machine.exe`, "env", "default"}, "# Run this command to configure your shell: \n# eval $(\"C:\\\\Me\\docker-machine.exe\" env default)\n"}, - - {"fish", []string{"./machine", "env", "--shell=fish", "default"}, "# Run this command to configure your shell: \n# eval (./machine env --shell=fish default)\n"}, - {"fish", []string{"./machine", "env", "--shell=fish", "--no-proxy", "default"}, "# Run this command to configure your shell: \n# eval (./machine env --shell=fish --no-proxy default)\n"}, - {"fish", []string{"./machine", "env", "--shell=fish", "--swarm", "default"}, "# Run this command to configure your shell: \n# eval (./machine env --shell=fish --swarm default)\n"}, - {"fish", []string{"./machine", "env", "--shell=fish", "--no-proxy", "--swarm", "default"}, "# Run this command to configure your shell: \n# eval (./machine env --shell=fish --no-proxy --swarm default)\n"}, - {"fish", []string{"./machine", "env", "--shell=fish", "--unset"}, "# Run this command to configure your shell: \n# eval (./machine env --shell=fish --unset)\n"}, - - {"powershell", []string{"./machine", "env", "--shell=powershell", "default"}, "# Run this command to configure your shell: \n# & ./machine env --shell=powershell default | Invoke-Expression\n"}, - {"powershell", []string{"./machine", "env", "--shell=powershell", "--no-proxy", "default"}, "# Run this command to configure your shell: \n# & ./machine env --shell=powershell --no-proxy default | Invoke-Expression\n"}, - {"powershell", []string{"./machine", "env", "--shell=powershell", "--swarm", "default"}, "# Run this command to configure your shell: \n# & ./machine env --shell=powershell --swarm default | Invoke-Expression\n"}, - {"powershell", []string{"./machine", "env", "--shell=powershell", "--no-proxy", "--swarm", "default"}, "# Run this command to configure your shell: \n# & ./machine env --shell=powershell --no-proxy --swarm default | Invoke-Expression\n"}, - {"powershell", []string{"./machine", "env", "--shell=powershell", "--unset"}, "# Run this command to configure your shell: \n# & ./machine env --shell=powershell --unset | Invoke-Expression\n"}, - {"powershell", []string{"./machine", "env", "--shell=powershell", "--unset"}, "# Run this command to configure your shell: \n# & ./machine env --shell=powershell --unset | Invoke-Expression\n"}, - {"powershell", []string{`C:\\Program Files\docker-machine.exe`, "env", "--shell=powershell", "default"}, "# Run this command to configure your shell: \n# & \"C:\\\\Program Files\\docker-machine.exe\" env --shell=powershell default | Invoke-Expression\n"}, - {"powershell", []string{`C:\\Me\docker-machine.exe`, "env", "--shell=powershell", "default"}, "# Run this command to configure your shell: \n# & \"C:\\\\Me\\docker-machine.exe\" env --shell=powershell default | Invoke-Expression\n"}, - - {"cmd", []string{"./machine", "env", "--shell=cmd", "default"}, "REM Run this command to configure your shell: \nREM \t@FOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd default') DO @%i\n"}, - {"cmd", []string{"./machine", "env", "--shell=cmd", "--no-proxy", "default"}, "REM Run this command to configure your shell: \nREM \t@FOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd --no-proxy default') DO @%i\n"}, - {"cmd", []string{"./machine", "env", "--shell=cmd", "--swarm", "default"}, "REM Run this command to configure your shell: \nREM \t@FOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd --swarm default') DO @%i\n"}, - {"cmd", []string{"./machine", "env", "--shell=cmd", "--no-proxy", "--swarm", "default"}, "REM Run this command to configure your shell: \nREM \t@FOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd --no-proxy --swarm default') DO @%i\n"}, - {"cmd", []string{"./machine", "env", "--shell=cmd", "--unset"}, "REM Run this command to configure your shell: \nREM \t@FOR /f \"tokens=*\" %i IN ('./machine env --shell=cmd --unset') DO @%i\n"}, - {"cmd", []string{`C:\\Program Files\docker-machine.exe`, "env", "--shell=cmd", "default"}, "REM Run this command to configure your shell: \nREM \t@FOR /f \"tokens=*\" %i IN ('\"C:\\\\Program Files\\docker-machine.exe\" env --shell=cmd default') DO @%i\n"}, - {"cmd", []string{`C:\\Me\docker-machine.exe`, "env", "--shell=cmd", "default"}, "REM Run this command to configure your shell: \nREM \t@FOR /f \"tokens=*\" %i IN ('\"C:\\\\Me\\docker-machine.exe\" env --shell=cmd default') DO @%i\n"}, - - {"emacs", []string{"./machine", "env", "--shell=emacs", "default"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs default\" (current-buffer)) (eval-buffer))\n"}, - {"emacs", []string{"./machine", "env", "--shell=emacs", "--no-proxy", "default"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --no-proxy default\" (current-buffer)) (eval-buffer))\n"}, - {"emacs", []string{"./machine", "env", "--shell=emacs", "--swarm", "default"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --swarm default\" (current-buffer)) (eval-buffer))\n"}, - {"emacs", []string{"./machine", "env", "--shell=emacs", "--no-proxy", "--swarm", "default"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --no-proxy --swarm default\" (current-buffer)) (eval-buffer))\n"}, - {"emacs", []string{"./machine", "env", "--shell=emacs", "--unset"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --unset\" (current-buffer)) (eval-buffer))\n"}, - - {"tcsh", []string{"./machine", "env", "--shell=tcsh", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh default`\n"}, - {"tcsh", []string{"./machine", "env", "--shell=tcsh", "--no-proxy", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --no-proxy default`\n"}, - {"tcsh", []string{"./machine", "env", "--shell=tcsh", "--swarm", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --swarm default`\n"}, - {"tcsh", []string{"./machine", "env", "--shell=tcsh", "--no-proxy", "--swarm", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --no-proxy --swarm default`\n"}, - {"tcsh", []string{"./machine", "env", "--shell=tcsh", "--unset"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --unset`\n"}, - } - - for _, test := range tests { - hints := defaultUsageHinter.GenerateUsageHint(test.userShell, test.commandLine) - assert.Equal(t, test.expectedHints, hints) - } -} - -func revertUsageHinter(uhg UsageHintGenerator) { - defaultUsageHinter = uhg -} - -func TestShellCfgSet(t *testing.T) { - const ( - usageHint = "This is a usage hint" - ) - - // TODO: This should be embedded in some kind of wrapper struct for all - // these `env` operations. - defer revertUsageHinter(defaultUsageHinter) - defaultUsageHinter = &SimpleUsageHintGenerator{usageHint} - isRuntimeWindows := runtimeOS() == "windows" - - var tests = []struct { - description string - commandLine CommandLine - api libmachine.API - connChecker check.ConnChecker - noProxyVar string - noProxyValue string - expectedShellCfg *ShellConfig - expectedErr error - }{ - { - description: "no host name specified", - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{}, - }, - commandLine: &commandstest.FakeCommandLine{ - CliArgs: nil, - }, - expectedShellCfg: nil, - expectedErr: ErrNoDefault, - }, - { - description: "bash shell set happy path without any flags set", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"quux"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "bash", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "quux", - }, - }, - }, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "export ", - Delimiter: "=\"", - Suffix: "\"\n", - DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), "quux"), - DockerHost: "tcp://1.2.3.4:2376", - DockerTLSVerify: "1", - UsageHint: usageHint, - MachineName: "quux", - ComposePathsVar: isRuntimeWindows, - }, - expectedErr: nil, - }, - { - description: "bash shell set happy path with 'default' vm", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "bash", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: defaultMachineName, - }, - }, - }, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "export ", - Delimiter: "=\"", - Suffix: "\"\n", - DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), defaultMachineName), - DockerHost: "tcp://1.2.3.4:2376", - DockerTLSVerify: "1", - UsageHint: usageHint, - MachineName: defaultMachineName, - ComposePathsVar: isRuntimeWindows, - }, - expectedErr: nil, - }, - { - description: "fish shell set happy path", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"quux"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "fish", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "quux", - }, - }, - }, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "set -gx ", - Suffix: "\";\n", - Delimiter: " \"", - DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), "quux"), - DockerHost: "tcp://1.2.3.4:2376", - DockerTLSVerify: "1", - UsageHint: usageHint, - MachineName: "quux", - ComposePathsVar: isRuntimeWindows, - }, - expectedErr: nil, - }, - { - description: "powershell set happy path", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"quux"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "powershell", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "quux", - }, - }, - }, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "$Env:", - Suffix: "\"\n", - Delimiter: " = \"", - DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), "quux"), - DockerHost: "tcp://1.2.3.4:2376", - DockerTLSVerify: "1", - UsageHint: usageHint, - MachineName: "quux", - ComposePathsVar: isRuntimeWindows, - }, - expectedErr: nil, - }, - { - description: "emacs set happy path", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"quux"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "emacs", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "quux", - }, - }, - }, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "(setenv \"", - Suffix: "\")\n", - Delimiter: "\" \"", - DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), "quux"), - DockerHost: "tcp://1.2.3.4:2376", - DockerTLSVerify: "1", - UsageHint: usageHint, - MachineName: "quux", - ComposePathsVar: isRuntimeWindows, - }, - expectedErr: nil, - }, - { - description: "cmd.exe happy path", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"quux"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "cmd", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "quux", - }, - }, - }, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "SET ", - Suffix: "\n", - Delimiter: "=", - DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), "quux"), - DockerHost: "tcp://1.2.3.4:2376", - DockerTLSVerify: "1", - UsageHint: usageHint, - MachineName: "quux", - ComposePathsVar: isRuntimeWindows, - }, - expectedErr: nil, - }, - { - description: "bash shell set happy path with --no-proxy flag; no existing environment variable set", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"quux"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "bash", - "swarm": false, - "no-proxy": true, - }, - }, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "quux", - Driver: &fakedriver.Driver{ - MockState: state.Running, - MockIP: "1.2.3.4", - }, - }, - }, - }, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "export ", - Delimiter: "=\"", - Suffix: "\"\n", - DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), "quux"), - DockerHost: "tcp://1.2.3.4:2376", - DockerTLSVerify: "1", - UsageHint: usageHint, - NoProxyVar: "NO_PROXY", - NoProxyValue: "1.2.3.4", // From FakeDriver - MachineName: "quux", - ComposePathsVar: isRuntimeWindows, - }, - noProxyVar: "NO_PROXY", - noProxyValue: "", - expectedErr: nil, - }, - { - description: "bash shell set happy path with --no-proxy flag; existing environment variable _is_ set", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"quux"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "bash", - "swarm": false, - "no-proxy": true, - }, - }, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "quux", - Driver: &fakedriver.Driver{ - MockState: state.Running, - MockIP: "1.2.3.4", - }, - }, - }, - }, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "export ", - Delimiter: "=\"", - Suffix: "\"\n", - DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), "quux"), - DockerHost: "tcp://1.2.3.4:2376", - DockerTLSVerify: "1", - UsageHint: usageHint, - NoProxyVar: "no_proxy", - NoProxyValue: "192.168.59.1,1.2.3.4", // From FakeDriver - MachineName: "quux", - ComposePathsVar: isRuntimeWindows, - }, - noProxyVar: "no_proxy", - noProxyValue: "192.168.59.1", - expectedErr: nil, - }, - } - - for _, test := range tests { - // TODO: Ideally this should not hit the environment at all but - // rather should go through an interface. - os.Setenv(test.noProxyVar, test.noProxyValue) - - t.Log(test.description) - - check.DefaultConnChecker = test.connChecker - shellCfg, err := shellCfgSet(test.commandLine, test.api) - assert.Equal(t, test.expectedShellCfg, shellCfg) - assert.Equal(t, test.expectedErr, err) - - os.Unsetenv(test.noProxyVar) - } -} - -func TestShellCfgSetWindowsRuntime(t *testing.T) { - const ( - usageHint = "This is a usage hint" - ) - - // TODO: This should be embedded in some kind of wrapper struct for all - // these `env` operations. - defer revertUsageHinter(defaultUsageHinter) - defaultUsageHinter = &SimpleUsageHintGenerator{usageHint} - - var tests = []struct { - description string - commandLine CommandLine - api libmachine.API - connChecker check.ConnChecker - noProxyVar string - noProxyValue string - expectedShellCfg *ShellConfig - expectedErr error - }{ - { - description: "powershell set happy path", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"quux"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "powershell", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "quux", - }, - }, - }, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "$Env:", - Suffix: "\"\n", - Delimiter: " = \"", - DockerCertPath: filepath.Join(mcndirs.GetMachineDir(), "quux"), - DockerHost: "tcp://1.2.3.4:2376", - DockerTLSVerify: "1", - UsageHint: usageHint, - MachineName: "quux", - ComposePathsVar: true, - }, - expectedErr: nil, - }, - } - - actualRuntimeOS := runtimeOS - runtimeOS = func() string { return "windows" } - defer func() { runtimeOS = actualRuntimeOS }() - - for _, test := range tests { - // TODO: Ideally this should not hit the environment at all but - // rather should go through an interface. - os.Setenv(test.noProxyVar, test.noProxyValue) - - t.Log(test.description) - - check.DefaultConnChecker = test.connChecker - shellCfg, err := shellCfgSet(test.commandLine, test.api) - assert.Equal(t, test.expectedShellCfg, shellCfg) - assert.Equal(t, test.expectedErr, err) - - os.Unsetenv(test.noProxyVar) - } -} - -func TestShellCfgUnset(t *testing.T) { - const ( - usageHint = "This is the unset usage hint" - ) - - defer revertUsageHinter(defaultUsageHinter) - defaultUsageHinter = &SimpleUsageHintGenerator{usageHint} - - var tests = []struct { - description string - commandLine CommandLine - api libmachine.API - connChecker check.ConnChecker - noProxyVar string - noProxyValue string - expectedShellCfg *ShellConfig - expectedErr error - }{ - { - description: "more than expected args passed in", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"foo", "bar"}, - }, - expectedShellCfg: nil, - expectedErr: errImproperUnsetEnvArgs, - }, - { - description: "bash shell unset happy path without any flags set", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: nil, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "bash", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{}, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "unset ", - Suffix: "\n", - Delimiter: "", - UsageHint: usageHint, - }, - expectedErr: nil, - }, - { - description: "fish shell unset happy path", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: nil, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "fish", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{}, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "set -e ", - Suffix: ";\n", - Delimiter: "", - UsageHint: usageHint, - }, - expectedErr: nil, - }, - { - description: "powershell unset happy path", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: nil, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "powershell", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{}, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: `Remove-Item Env:\\`, - Suffix: "\n", - Delimiter: "", - UsageHint: usageHint, - }, - expectedErr: nil, - }, - { - description: "cmd.exe unset happy path", - commandLine: &commandstest.FakeCommandLine{ - CliArgs: nil, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "shell": "cmd", - "swarm": false, - "no-proxy": false, - }, - }, - }, - api: &libmachinetest.FakeAPI{}, - connChecker: &FakeConnChecker{ - DockerHost: "tcp://1.2.3.4:2376", - AuthOptions: nil, - Err: nil, - }, - expectedShellCfg: &ShellConfig{ - Prefix: "SET ", - Suffix: "\n", - Delimiter: "=", - UsageHint: usageHint, - }, - expectedErr: nil, - }, - // TODO: There is kind of a funny bug (feature?) I discovered - // reasoning about unset() where if there was a NO_PROXY value - // set _before_ the original docker-machine env, it won't be - // restored (NO_PROXY won't be unset at all, it will stay the - // same). We should define expected behavior in this case. - } - - for _, test := range tests { - os.Setenv(test.noProxyVar, test.noProxyValue) - - t.Log(test.description) - - check.DefaultConnChecker = test.connChecker - shellCfg, err := shellCfgUnset(test.commandLine, test.api) - assert.Equal(t, test.expectedShellCfg, shellCfg) - assert.Equal(t, test.expectedErr, err) - - os.Setenv(test.noProxyVar, "") - } -} diff --git a/vendor/github.com/docker/machine/commands/flag_sort.go b/vendor/github.com/docker/machine/commands/flag_sort.go deleted file mode 100644 index 746043b..0000000 --- a/vendor/github.com/docker/machine/commands/flag_sort.go +++ /dev/null @@ -1,17 +0,0 @@ -package commands - -import "github.com/codegangsta/cli" - -type ByFlagName []cli.Flag - -func (flags ByFlagName) Len() int { - return len(flags) -} - -func (flags ByFlagName) Swap(i, j int) { - flags[i], flags[j] = flags[j], flags[i] -} - -func (flags ByFlagName) Less(i, j int) bool { - return flags[i].String() < flags[j].String() -} diff --git a/vendor/github.com/docker/machine/commands/inspect.go b/vendor/github.com/docker/machine/commands/inspect.go deleted file mode 100644 index c521501..0000000 --- a/vendor/github.com/docker/machine/commands/inspect.go +++ /dev/null @@ -1,72 +0,0 @@ -package commands - -import ( - "encoding/json" - "fmt" - "os" - "text/template" - - "github.com/docker/machine/libmachine" -) - -var funcMap = template.FuncMap{ - "json": func(v interface{}) string { - a, _ := json.Marshal(v) - return string(a) - }, - "prettyjson": func(v interface{}) string { - a, _ := json.MarshalIndent(v, "", " ") - return string(a) - }, -} - -func cmdInspect(c CommandLine, api libmachine.API) error { - if len(c.Args()) > 1 { - c.ShowHelp() - return ErrExpectedOneMachine - } - - target, err := targetHost(c, api) - if err != nil { - return err - } - - host, err := api.Load(target) - if err != nil { - return err - } - - tmplString := c.String("format") - if tmplString != "" { - var tmpl *template.Template - var err error - if tmpl, err = template.New("").Funcs(funcMap).Parse(tmplString); err != nil { - return fmt.Errorf("template parsing error: %v", err) - } - - jsonHost, err := json.Marshal(host) - if err != nil { - return err - } - - obj := make(map[string]interface{}) - if err := json.Unmarshal(jsonHost, &obj); err != nil { - return err - } - - if err := tmpl.Execute(os.Stdout, obj); err != nil { - return err - } - - os.Stdout.Write([]byte{'\n'}) - } else { - prettyJSON, err := json.MarshalIndent(host, "", " ") - if err != nil { - return err - } - - fmt.Println(string(prettyJSON)) - } - - return nil -} diff --git a/vendor/github.com/docker/machine/commands/inspect_test.go b/vendor/github.com/docker/machine/commands/inspect_test.go deleted file mode 100644 index 779ce35..0000000 --- a/vendor/github.com/docker/machine/commands/inspect_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package commands - -import ( - "testing" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/libmachinetest" - "github.com/stretchr/testify/assert" -) - -func TestCmdInspect(t *testing.T) { - testCases := []struct { - commandLine CommandLine - api libmachine.API - expectedErr error - }{ - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"foo", "bar"}, - }, - api: &libmachinetest.FakeAPI{}, - expectedErr: ErrExpectedOneMachine, - }, - } - - for _, tc := range testCases { - err := cmdInspect(tc.commandLine, tc.api) - assert.Equal(t, tc.expectedErr, err) - } -} diff --git a/vendor/github.com/docker/machine/commands/ip.go b/vendor/github.com/docker/machine/commands/ip.go deleted file mode 100644 index 13e45f6..0000000 --- a/vendor/github.com/docker/machine/commands/ip.go +++ /dev/null @@ -1,7 +0,0 @@ -package commands - -import "github.com/docker/machine/libmachine" - -func cmdIP(c CommandLine, api libmachine.API) error { - return runAction("ip", c, api) -} diff --git a/vendor/github.com/docker/machine/commands/ip_test.go b/vendor/github.com/docker/machine/commands/ip_test.go deleted file mode 100644 index 108b33b..0000000 --- a/vendor/github.com/docker/machine/commands/ip_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package commands - -import ( - "testing" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/libmachinetest" - "github.com/docker/machine/libmachine/state" - "github.com/stretchr/testify/assert" -) - -func TestCmdIPMissingMachineName(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{} - api := &libmachinetest.FakeAPI{} - - err := cmdURL(commandLine, api) - - assert.Equal(t, err, ErrNoDefault) -} - -func TestCmdIP(t *testing.T) { - testCases := []struct { - commandLine CommandLine - api libmachine.API - expectedErr error - expectedOut string - }{ - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"machine"}, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machine", - Driver: &fakedriver.Driver{ - MockState: state.Running, - MockIP: "1.2.3.4", - }, - }, - }, - }, - expectedErr: nil, - expectedOut: "1.2.3.4\n", - }, - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{}, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "default", - Driver: &fakedriver.Driver{ - MockState: state.Running, - MockIP: "1.2.3.4", - }, - }, - }, - }, - expectedErr: nil, - expectedOut: "1.2.3.4\n", - }, - } - - for _, tc := range testCases { - stdoutGetter := commandstest.NewStdoutGetter() - - err := cmdIP(tc.commandLine, tc.api) - - assert.Equal(t, tc.expectedErr, err) - assert.Equal(t, tc.expectedOut, stdoutGetter.Output()) - - stdoutGetter.Stop() - } -} diff --git a/vendor/github.com/docker/machine/commands/kill.go b/vendor/github.com/docker/machine/commands/kill.go deleted file mode 100644 index f8c2aac..0000000 --- a/vendor/github.com/docker/machine/commands/kill.go +++ /dev/null @@ -1,7 +0,0 @@ -package commands - -import "github.com/docker/machine/libmachine" - -func cmdKill(c CommandLine, api libmachine.API) error { - return runAction("kill", c, api) -} diff --git a/vendor/github.com/docker/machine/commands/kill_test.go b/vendor/github.com/docker/machine/commands/kill_test.go deleted file mode 100644 index 23c1ef5..0000000 --- a/vendor/github.com/docker/machine/commands/kill_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package commands - -import ( - "testing" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/libmachinetest" - "github.com/docker/machine/libmachine/state" - "github.com/stretchr/testify/assert" -) - -func TestCmdKillMissingMachineName(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{} - api := &libmachinetest.FakeAPI{} - - err := cmdKill(commandLine, api) - - assert.Equal(t, ErrNoDefault, err) -} - -func TestCmdKill(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machineToKill1", "machineToKill2"}, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machineToKill1", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - { - Name: "machineToKill2", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - { - Name: "machine", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - }, - } - - err := cmdKill(commandLine, api) - assert.NoError(t, err) - - assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToKill1")) - assert.Equal(t, state.Stopped, libmachinetest.State(api, "machineToKill2")) - assert.Equal(t, state.Running, libmachinetest.State(api, "machine")) -} diff --git a/vendor/github.com/docker/machine/commands/ls.go b/vendor/github.com/docker/machine/commands/ls.go deleted file mode 100644 index 1553595..0000000 --- a/vendor/github.com/docker/machine/commands/ls.go +++ /dev/null @@ -1,506 +0,0 @@ -package commands - -import ( - "errors" - "fmt" - "os" - "regexp" - "sort" - "strings" - "text/tabwriter" - "text/template" - "time" - - "io" - - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcndockerclient" - "github.com/docker/machine/libmachine/persist" - "github.com/docker/machine/libmachine/state" - "github.com/docker/machine/libmachine/swarm" - "github.com/skarademir/naturalsort" -) - -const ( - lsDefaultTimeout = 10 - tableFormatKey = "table" - lsDefaultFormat = "table {{ .Name }}\t{{ .Active }}\t{{ .DriverName}}\t{{ .State }}\t{{ .URL }}\t{{ .Swarm }}\t{{ .DockerVersion }}\t{{ .Error}}" -) - -var ( - headers = map[string]string{ - "Name": "NAME", - "Active": "ACTIVE", - "ActiveHost": "ACTIVE_HOST", - "ActiveSwarm": "ACTIVE_SWARM", - "DriverName": "DRIVER", - "State": "STATE", - "URL": "URL", - "SwarmOptions": "SWARM_OPTIONS", - "Swarm": "SWARM", - "EngineOptions": "ENGINE_OPTIONS", - "Error": "ERRORS", - "DockerVersion": "DOCKER", - "ResponseTime": "RESPONSE", - } -) - -type HostListItem struct { - Name string - Active string - ActiveHost bool - ActiveSwarm bool - DriverName string - State state.State - URL string - SwarmOptions *swarm.Options - Swarm string - EngineOptions *engine.Options - Error string - DockerVersion string - ResponseTime time.Duration -} - -// FilterOptions - -type FilterOptions struct { - SwarmName []string - DriverName []string - State []string - Name []string - Labels []string -} - -func cmdLs(c CommandLine, api libmachine.API) error { - filters, err := parseFilters(c.StringSlice("filter")) - if err != nil { - return err - } - - hostList, hostInError, err := persist.LoadAllHosts(api) - if err != nil { - return err - } - - hostList = filterHosts(hostList, filters) - - // Just print out the names if we're being quiet - if c.Bool("quiet") { - for _, host := range hostList { - fmt.Println(host.Name) - } - return nil - } - - template, table, err := parseFormat(c.String("format")) - if err != nil { - return err - } - - var w io.Writer - if table { - tabWriter := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0) - defer tabWriter.Flush() - - w = tabWriter - - if err := template.Execute(w, headers); err != nil { - return err - } - } else { - w = os.Stdout - } - - timeout := time.Duration(c.Int("timeout")) * time.Second - items := getHostListItems(hostList, hostInError, timeout) - - swarmMasters := make(map[string]string) - swarmInfo := make(map[string]string) - - for _, host := range hostList { - if host.HostOptions != nil { - swarmOptions := host.HostOptions.SwarmOptions - if swarmOptions.Master { - swarmMasters[swarmOptions.Discovery] = host.Name - } - - if swarmOptions.Discovery != "" { - swarmInfo[host.Name] = swarmOptions.Discovery - } - } - } - - for _, item := range items { - swarmColumn := "" - if item.SwarmOptions != nil && item.SwarmOptions.Discovery != "" { - swarmColumn = swarmMasters[item.SwarmOptions.Discovery] - if item.SwarmOptions.Master { - swarmColumn = fmt.Sprintf("%s (master)", swarmColumn) - } - } - item.Swarm = swarmColumn - - if err := template.Execute(w, item); err != nil { - return err - } - } - - return nil -} - -func parseFormat(format string) (*template.Template, bool, error) { - table := false - finalFormat := format - - if finalFormat == "" { - finalFormat = lsDefaultFormat - } - - if strings.HasPrefix(finalFormat, tableFormatKey) { - table = true - finalFormat = finalFormat[len(tableFormatKey):] - } - - finalFormat = strings.Trim(finalFormat, " ") - r := strings.NewReplacer(`\t`, "\t", `\n`, "\n") - finalFormat = r.Replace(finalFormat) - - template, err := template.New("").Parse(finalFormat + "\n") - if err != nil { - return nil, false, err - } - - return template, table, nil -} - -func parseFilters(filters []string) (FilterOptions, error) { - options := FilterOptions{} - for _, f := range filters { - kv := strings.SplitN(f, "=", 2) - if len(kv) != 2 { - return options, errors.New("Unsupported filter syntax") - } - key, value := strings.ToLower(kv[0]), kv[1] - - switch key { - case "swarm": - options.SwarmName = append(options.SwarmName, value) - case "driver": - options.DriverName = append(options.DriverName, value) - case "state": - options.State = append(options.State, value) - case "name": - options.Name = append(options.Name, value) - case "label": - options.Labels = append(options.Labels, value) - default: - return options, fmt.Errorf("Unsupported filter key '%s'", key) - } - } - return options, nil -} - -func filterHosts(hosts []*host.Host, filters FilterOptions) []*host.Host { - if len(filters.SwarmName) == 0 && - len(filters.DriverName) == 0 && - len(filters.State) == 0 && - len(filters.Name) == 0 && - len(filters.Labels) == 0 { - return hosts - } - - filteredHosts := []*host.Host{} - swarmMasters := getSwarmMasters(hosts) - - for _, h := range hosts { - if filterHost(h, filters, swarmMasters) { - filteredHosts = append(filteredHosts, h) - } - } - return filteredHosts -} - -func getSwarmMasters(hosts []*host.Host) map[string]string { - swarmMasters := make(map[string]string) - for _, h := range hosts { - if h.HostOptions != nil { - swarmOptions := h.HostOptions.SwarmOptions - if swarmOptions != nil && swarmOptions.Master { - swarmMasters[swarmOptions.Discovery] = h.Name - } - } - } - return swarmMasters -} - -func filterHost(host *host.Host, filters FilterOptions, swarmMasters map[string]string) bool { - swarmMatches := matchesSwarmName(host, filters.SwarmName, swarmMasters) - driverMatches := matchesDriverName(host, filters.DriverName) - stateMatches := matchesState(host, filters.State) - nameMatches := matchesName(host, filters.Name) - labelMatches := matchesLabel(host, filters.Labels) - - return swarmMatches && driverMatches && stateMatches && nameMatches && labelMatches -} - -func matchesSwarmName(host *host.Host, swarmNames []string, swarmMasters map[string]string) bool { - if len(swarmNames) == 0 { - return true - } - for _, n := range swarmNames { - if host.HostOptions != nil && host.HostOptions.SwarmOptions != nil { - if strings.EqualFold(n, swarmMasters[host.HostOptions.SwarmOptions.Discovery]) { - return true - } - } - } - return false -} - -func matchesDriverName(host *host.Host, driverNames []string) bool { - if len(driverNames) == 0 { - return true - } - for _, n := range driverNames { - if strings.EqualFold(host.DriverName, n) { - return true - } - } - return false -} - -func matchesState(host *host.Host, states []string) bool { - if len(states) == 0 { - return true - } - for _, n := range states { - s, err := host.Driver.GetState() - if err != nil { - log.Warn(err) - } - if strings.EqualFold(n, s.String()) { - return true - } - } - return false -} - -func matchesName(host *host.Host, names []string) bool { - if len(names) == 0 { - return true - } - for _, n := range names { - r, err := regexp.Compile(n) - if err != nil { - log.Error(err) - os.Exit(1) // TODO: Can we get rid of this call, and exit 'properly' ? - } - if r.MatchString(host.Driver.GetMachineName()) { - return true - } - } - return false -} - -func matchesLabel(host *host.Host, labels []string) bool { - if len(labels) == 0 { - return true - } - - var englabels = make(map[string]string, len(host.HostOptions.EngineOptions.Labels)) - - if host.HostOptions != nil && host.HostOptions.EngineOptions.Labels != nil { - for _, s := range host.HostOptions.EngineOptions.Labels { - kv := strings.SplitN(s, "=", 2) - englabels[kv[0]] = kv[1] - } - } - - for _, l := range labels { - kv := strings.SplitN(l, "=", 2) - if val, exists := englabels[kv[0]]; exists && strings.EqualFold(val, kv[1]) { - return true - } - } - return false -} - -// PERFORMANCE: The code of this function is complicated because we try -// to call the underlying drivers as less as possible to get the information -// we need. -func attemptGetHostState(h *host.Host, stateQueryChan chan<- HostListItem) { - requestBeginning := time.Now() - url := "" - currentState := state.None - dockerVersion := "Unknown" - hostError := "" - - url, err := h.URL() - - // PERFORMANCE: if we have the url, it's ok to assume the host is running - // This reduces the number of calls to the drivers - if err == nil { - if url != "" { - currentState = state.Running - } else { - currentState, err = h.Driver.GetState() - } - } else { - currentState, _ = h.Driver.GetState() - } - - if err == nil && url != "" { - // PERFORMANCE: Reuse the url instead of asking the host again. - // This reduces the number of calls to the drivers - dockerHost := &mcndockerclient.RemoteDocker{ - HostURL: url, - AuthOption: h.AuthOptions(), - } - dockerVersion, err = mcndockerclient.DockerVersion(dockerHost) - - if err != nil { - dockerVersion = "Unknown" - } else { - dockerVersion = fmt.Sprintf("v%s", dockerVersion) - } - } - - if err != nil { - hostError = err.Error() - } - if hostError == drivers.ErrHostIsNotRunning.Error() { - hostError = "" - } - - var swarmOptions *swarm.Options - var engineOptions *engine.Options - if h.HostOptions != nil { - swarmOptions = h.HostOptions.SwarmOptions - engineOptions = h.HostOptions.EngineOptions - } - - isMaster := false - swarmHost := "" - if swarmOptions != nil { - isMaster = swarmOptions.Master - swarmHost = swarmOptions.Host - } - - activeHost := isActive(currentState, url) - activeSwarm := isSwarmActive(currentState, url, isMaster, swarmHost) - active := "-" - if activeHost { - active = "*" - } - if activeSwarm { - active = "* (swarm)" - } - - stateQueryChan <- HostListItem{ - Name: h.Name, - Active: active, - ActiveHost: activeHost, - ActiveSwarm: activeSwarm, - DriverName: h.Driver.DriverName(), - State: currentState, - URL: url, - SwarmOptions: swarmOptions, - EngineOptions: engineOptions, - DockerVersion: dockerVersion, - Error: hostError, - ResponseTime: time.Now().Round(time.Millisecond).Sub(requestBeginning.Round(time.Millisecond)), - } -} - -func getHostState(h *host.Host, hostListItemsChan chan<- HostListItem, timeout time.Duration) { - // This channel is used to communicate the properties we are querying - // about the host in the case of a successful read. - stateQueryChan := make(chan HostListItem) - - go attemptGetHostState(h, stateQueryChan) - - select { - // If we get back useful information, great. Forward it straight to - // the original parent channel. - case hli := <-stateQueryChan: - hostListItemsChan <- hli - - // Otherwise, give up after a predetermined duration. - case <-time.After(timeout): - hostListItemsChan <- HostListItem{ - Name: h.Name, - DriverName: h.Driver.DriverName(), - State: state.Timeout, - ResponseTime: timeout, - } - } -} - -func getHostListItems(hostList []*host.Host, hostsInError map[string]error, timeout time.Duration) []HostListItem { - log.Debugf("timeout set to %s", timeout) - - hostListItems := []HostListItem{} - hostListItemsChan := make(chan HostListItem) - - for _, h := range hostList { - go getHostState(h, hostListItemsChan, timeout) - } - - for range hostList { - hostListItems = append(hostListItems, <-hostListItemsChan) - } - - close(hostListItemsChan) - - for name, err := range hostsInError { - hostListItems = append(hostListItems, newHostListItemInError(name, err)) - } - - sortHostListItemsByName(hostListItems) - return hostListItems -} - -func newHostListItemInError(name string, err error) HostListItem { - return HostListItem{ - Name: name, - DriverName: "not found", - State: state.Error, - Error: strings.Replace(err.Error(), "\n", "", -1), - } -} - -func sortHostListItemsByName(items []HostListItem) { - m := make(map[string]HostListItem, len(items)) - s := make([]string, len(items)) - for i, v := range items { - name := strings.ToLower(v.Name) - m[name] = v - s[i] = name - } - sort.Sort(naturalsort.NaturalSort(s)) - for i, v := range s { - items[i] = m[v] - } -} - -func isActive(currentState state.State, hostURL string) bool { - return currentState == state.Running && hostURL == os.Getenv("DOCKER_HOST") -} - -func isSwarmActive(currentState state.State, hostURL string, isMaster bool, swarmHost string) bool { - return isMaster && currentState == state.Running && toSwarmURL(hostURL, swarmHost) == os.Getenv("DOCKER_HOST") -} - -func urlPort(urlWithPort string) string { - parts := strings.Split(urlWithPort, ":") - return parts[len(parts)-1] -} - -func toSwarmURL(hostURL string, swarmHost string) string { - hostPort := urlPort(hostURL) - swarmPort := urlPort(swarmHost) - return strings.Replace(hostURL, ":"+hostPort, ":"+swarmPort, 1) -} diff --git a/vendor/github.com/docker/machine/commands/ls_test.go b/vendor/github.com/docker/machine/commands/ls_test.go deleted file mode 100644 index 3e8bf31..0000000 --- a/vendor/github.com/docker/machine/commands/ls_test.go +++ /dev/null @@ -1,535 +0,0 @@ -package commands - -import ( - "os" - "testing" - - "time" - - "errors" - - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/mcndockerclient" - "github.com/docker/machine/libmachine/state" - "github.com/docker/machine/libmachine/swarm" - "github.com/stretchr/testify/assert" -) - -func TestParseFiltersErrorsGivenInvalidFilter(t *testing.T) { - _, err := parseFilters([]string{"foo=bar"}) - assert.EqualError(t, err, "Unsupported filter key 'foo'") -} - -func TestParseFiltersSwarm(t *testing.T) { - actual, _ := parseFilters([]string{"swarm=foo"}) - assert.Equal(t, actual, FilterOptions{SwarmName: []string{"foo"}}) -} - -func TestParseFiltersDriver(t *testing.T) { - actual, _ := parseFilters([]string{"driver=bar"}) - assert.Equal(t, actual, FilterOptions{DriverName: []string{"bar"}}) -} - -func TestParseFiltersState(t *testing.T) { - actual, _ := parseFilters([]string{"state=Running"}) - assert.Equal(t, actual, FilterOptions{State: []string{"Running"}}) -} - -func TestParseFiltersName(t *testing.T) { - actual, _ := parseFilters([]string{"name=dev"}) - assert.Equal(t, actual, FilterOptions{Name: []string{"dev"}}) -} - -func TestParseFiltersLabel(t *testing.T) { - actual, err := parseFilters([]string{"label=com.example.foo=bar"}) - assert.EqualValues(t, actual, FilterOptions{Labels: []string{"com.example.foo=bar"}}) - assert.Nil(t, err, "returned err value must be Nil") -} - -func TestParseFiltersAll(t *testing.T) { - actual, _ := parseFilters([]string{"swarm=foo", "driver=bar", "state=Stopped", "name=dev"}) - assert.Equal(t, actual, FilterOptions{SwarmName: []string{"foo"}, DriverName: []string{"bar"}, State: []string{"Stopped"}, Name: []string{"dev"}}) -} - -func TestParseFiltersAllCase(t *testing.T) { - actual, err := parseFilters([]string{"sWarM=foo", "DrIver=bar", "StaTe=Stopped", "NAMe=dev", "LABEL=com=foo"}) - assert.Equal(t, actual, FilterOptions{SwarmName: []string{"foo"}, DriverName: []string{"bar"}, State: []string{"Stopped"}, Name: []string{"dev"}, Labels: []string{"com=foo"}}) - assert.Nil(t, err, "err should be nil") -} - -func TestParseFiltersDuplicates(t *testing.T) { - actual, _ := parseFilters([]string{"swarm=foo", "driver=bar", "name=mark", "swarm=baz", "driver=qux", "state=Running", "state=Starting", "name=time"}) - assert.Equal(t, actual, FilterOptions{SwarmName: []string{"foo", "baz"}, DriverName: []string{"bar", "qux"}, State: []string{"Running", "Starting"}, Name: []string{"mark", "time"}}) -} - -func TestParseFiltersValueWithEqual(t *testing.T) { - actual, _ := parseFilters([]string{"driver=bar=baz"}) - assert.Equal(t, actual, FilterOptions{DriverName: []string{"bar=baz"}}) -} - -func TestFilterHostsReturnsFiltersValuesCaseInsensitive(t *testing.T) { - opts := FilterOptions{ - SwarmName: []string{"fOo"}, - DriverName: []string{"ViRtUaLboX"}, - State: []string{"StOPpeD"}, - Labels: []string{"com.EXAMPLE.app=FOO"}, - } - hosts := []*host.Host{} - actual := filterHosts(hosts, opts) - assert.EqualValues(t, actual, hosts) -} -func TestFilterHostsReturnsSameGivenNoFilters(t *testing.T) { - opts := FilterOptions{} - hosts := []*host.Host{ - { - Name: "testhost", - DriverName: "fakedriver", - }, - } - actual := filterHosts(hosts, opts) - assert.EqualValues(t, actual, hosts) -} - -func TestFilterHostsReturnSetLabel(t *testing.T) { - opts := FilterOptions{ - Labels: []string{"com.class.foo=bar"}, - } - hosts := []*host.Host{ - { - Name: "testhost", - DriverName: "fakedriver", - HostOptions: &host.Options{ - EngineOptions: &engine.Options{ - Labels: []string{"com.class.foo=bar"}, - }, - }, - }, - } - actual := filterHosts(hosts, opts) - assert.EqualValues(t, actual, hosts) -} - -func TestFilterHostsReturnsEmptyGivenEmptyHosts(t *testing.T) { - opts := FilterOptions{ - SwarmName: []string{"foo"}, - } - hosts := []*host.Host{} - assert.Empty(t, filterHosts(hosts, opts)) -} - -func TestFilterHostsReturnsEmptyGivenNonMatchingFilters(t *testing.T) { - opts := FilterOptions{ - SwarmName: []string{"foo"}, - } - hosts := []*host.Host{ - { - Name: "testhost", - DriverName: "fakedriver", - }, - } - assert.Empty(t, filterHosts(hosts, opts)) -} - -func TestFilterHostsBySwarmName(t *testing.T) { - opts := FilterOptions{ - SwarmName: []string{"master"}, - } - master := - &host.Host{ - Name: "master", - HostOptions: &host.Options{ - SwarmOptions: &swarm.Options{Master: true, Discovery: "foo"}, - }, - } - node1 := - &host.Host{ - Name: "node1", - HostOptions: &host.Options{ - SwarmOptions: &swarm.Options{Master: false, Discovery: "foo"}, - }, - } - othermaster := - &host.Host{ - Name: "othermaster", - HostOptions: &host.Options{ - SwarmOptions: &swarm.Options{Master: true, Discovery: "bar"}, - }, - } - hosts := []*host.Host{master, node1, othermaster} - expected := []*host.Host{master, node1} - - assert.EqualValues(t, filterHosts(hosts, opts), expected) -} - -func TestFilterHostsByDriverName(t *testing.T) { - opts := FilterOptions{ - DriverName: []string{"fakedriver"}, - } - node1 := - &host.Host{ - Name: "node1", - DriverName: "fakedriver", - } - node2 := - &host.Host{ - Name: "node2", - DriverName: "virtualbox", - } - node3 := - &host.Host{ - Name: "node3", - DriverName: "fakedriver", - } - hosts := []*host.Host{node1, node2, node3} - expected := []*host.Host{node1, node3} - - assert.EqualValues(t, filterHosts(hosts, opts), expected) -} - -func TestFilterHostsByState(t *testing.T) { - opts := FilterOptions{ - State: []string{"Paused", "Saved", "Stopped"}, - } - node1 := - &host.Host{ - Name: "node1", - DriverName: "fakedriver", - Driver: &fakedriver.Driver{MockState: state.Paused}, - } - node2 := - &host.Host{ - Name: "node2", - DriverName: "virtualbox", - Driver: &fakedriver.Driver{MockState: state.Stopped}, - } - node3 := - &host.Host{ - Name: "node3", - DriverName: "fakedriver", - Driver: &fakedriver.Driver{MockState: state.Running}, - } - hosts := []*host.Host{node1, node2, node3} - expected := []*host.Host{node1, node2} - - assert.EqualValues(t, filterHosts(hosts, opts), expected) -} - -func TestFilterHostsByName(t *testing.T) { - opts := FilterOptions{ - Name: []string{"fire", "ice", "earth", "a.?r"}, - } - node1 := - &host.Host{ - Name: "fire", - DriverName: "fakedriver", - Driver: &fakedriver.Driver{MockState: state.Paused, MockName: "fire"}, - } - node2 := - &host.Host{ - Name: "ice", - DriverName: "adriver", - Driver: &fakedriver.Driver{MockState: state.Paused, MockName: "ice"}, - } - node3 := - &host.Host{ - Name: "air", - DriverName: "nodriver", - Driver: &fakedriver.Driver{MockState: state.Paused, MockName: "air"}, - } - node4 := - &host.Host{ - Name: "water", - DriverName: "falsedriver", - Driver: &fakedriver.Driver{MockState: state.Paused, MockName: "water"}, - } - hosts := []*host.Host{node1, node2, node3, node4} - expected := []*host.Host{node1, node2, node3} - - assert.EqualValues(t, filterHosts(hosts, opts), expected) -} - -func TestFilterHostsMultiFlags(t *testing.T) { - opts := FilterOptions{ - SwarmName: []string{}, - DriverName: []string{"fakedriver", "virtualbox"}, - } - node1 := - &host.Host{ - Name: "node1", - DriverName: "fakedriver", - } - node2 := - &host.Host{ - Name: "node2", - DriverName: "virtualbox", - } - node3 := - &host.Host{ - Name: "node3", - DriverName: "softlayer", - } - hosts := []*host.Host{node1, node2, node3} - expected := []*host.Host{node1, node2} - - assert.EqualValues(t, filterHosts(hosts, opts), expected) -} - -func TestFilterHostsDifferentFlagsProduceAND(t *testing.T) { - opts := FilterOptions{ - DriverName: []string{"virtualbox"}, - State: []string{"Running"}, - } - - hosts := []*host.Host{ - { - Name: "node1", - DriverName: "fakedriver", - Driver: &fakedriver.Driver{MockState: state.Paused}, - }, - { - Name: "node2", - DriverName: "virtualbox", - Driver: &fakedriver.Driver{MockState: state.Stopped}, - }, - { - Name: "node3", - DriverName: "fakedriver", - Driver: &fakedriver.Driver{MockState: state.Running}, - }, - } - - assert.Empty(t, filterHosts(hosts, opts)) -} - -func TestGetHostListItems(t *testing.T) { - defer func(versioner mcndockerclient.DockerVersioner) { mcndockerclient.CurrentDockerVersioner = versioner }(mcndockerclient.CurrentDockerVersioner) - mcndockerclient.CurrentDockerVersioner = &mcndockerclient.FakeDockerVersioner{Version: "1.9"} - - // TODO: Ideally this would mockable via interface instead. - defer func(host string) { os.Setenv("DOCKER_HOST", host) }(os.Getenv("DOCKER_HOST")) - os.Setenv("DOCKER_HOST", "tcp://active.host.com:2376") - - hosts := []*host.Host{ - { - Name: "foo", - Driver: &fakedriver.Driver{ - MockState: state.Running, - MockIP: "active.host.com", - }, - }, - { - Name: "bar100", - Driver: &fakedriver.Driver{ - MockState: state.Stopped, - }, - }, - { - Name: "bar10", - Driver: &fakedriver.Driver{ - MockState: state.Error, - }, - }, - } - - expected := []struct { - name string - state state.State - active bool - version string - error string - }{ - {"bar10", state.Error, false, "Unknown", "Unable to get ip"}, - {"bar100", state.Stopped, false, "Unknown", ""}, - {"foo", state.Running, true, "v1.9", ""}, - } - - items := getHostListItems(hosts, map[string]error{}, 10*time.Second) - - for i := range expected { - assert.Equal(t, expected[i].name, items[i].Name) - assert.Equal(t, expected[i].state, items[i].State) - assert.Equal(t, expected[i].active, items[i].ActiveHost) - assert.Equal(t, expected[i].version, items[i].DockerVersion) - assert.Equal(t, expected[i].error, items[i].Error) - } -} - -func TestGetHostListItemsEnvDockerHostUnset(t *testing.T) { - defer func(versioner mcndockerclient.DockerVersioner) { mcndockerclient.CurrentDockerVersioner = versioner }(mcndockerclient.CurrentDockerVersioner) - mcndockerclient.CurrentDockerVersioner = &mcndockerclient.FakeDockerVersioner{Version: "1.9"} - - defer func(host string) { os.Setenv("DOCKER_HOST", host) }(os.Getenv("DOCKER_HOST")) - os.Unsetenv("DOCKER_HOST") - - hosts := []*host.Host{ - { - Name: "foo", - Driver: &fakedriver.Driver{ - MockState: state.Running, - MockIP: "120.0.0.1", - }, - }, - { - Name: "bar", - Driver: &fakedriver.Driver{ - MockState: state.Stopped, - }, - }, - { - Name: "baz", - Driver: &fakedriver.Driver{ - MockState: state.Saved, - }, - }, - } - - expected := map[string]struct { - state state.State - active bool - }{ - "foo": {state.Running, false}, - "bar": {state.Stopped, false}, - "baz": {state.Saved, false}, - } - - items := getHostListItems(hosts, map[string]error{}, 10*time.Second) - - for _, item := range items { - expected := expected[item.Name] - - assert.Equal(t, expected.state, item.State) - assert.Equal(t, expected.active, item.ActiveHost) - } -} - -func TestIsActive(t *testing.T) { - cases := []struct { - dockerHost string - state state.State - expected bool - }{ - {"", state.Running, false}, - {"tcp://5.6.7.8:2376", state.Running, false}, - {"tcp://1.2.3.4:2376", state.Stopped, false}, - {"tcp://1.2.3.4:2376", state.Running, true}, - {"tcp://1.2.3.4:3376", state.Running, false}, - } - - for _, c := range cases { - os.Unsetenv("DOCKER_HOST") - if c.dockerHost != "" { - os.Setenv("DOCKER_HOST", c.dockerHost) - } - - actual := isActive(c.state, "tcp://1.2.3.4:2376") - - assert.Equal(t, c.expected, actual) - } -} - -func TestIsSwarmActive(t *testing.T) { - cases := []struct { - dockerHost string - state state.State - isMaster bool - expected bool - }{ - {"", state.Running, false, false}, - {"tcp://5.6.7.8:3376", state.Running, true, false}, - {"tcp://1.2.3.4:3376", state.Stopped, true, false}, - {"tcp://1.2.3.4:3376", state.Running, true, true}, - {"tcp://1.2.3.4:3376", state.Running, false, false}, - {"tcp://1.2.3.4:2376", state.Running, true, false}, - } - - for _, c := range cases { - os.Unsetenv("DOCKER_HOST") - if c.dockerHost != "" { - os.Setenv("DOCKER_HOST", c.dockerHost) - } - - actual := isSwarmActive(c.state, "tcp://1.2.3.4:2376", c.isMaster, "tcp://0.0.0.0:3376") - - assert.Equal(t, c.expected, actual) - } -} - -func TestGetHostStateTimeout(t *testing.T) { - hosts := []*host.Host{ - { - Name: "foo", - Driver: &fakedriver.Driver{ - MockState: state.Timeout, - }, - }, - } - - hostItem := getHostListItems(hosts, nil, time.Millisecond)[0] - - assert.Equal(t, "foo", hostItem.Name) - assert.Equal(t, state.Timeout, hostItem.State) - assert.Equal(t, "Driver", hostItem.DriverName) - assert.Equal(t, time.Millisecond, hostItem.ResponseTime) -} - -func TestGetHostStateError(t *testing.T) { - hosts := []*host.Host{ - { - Name: "foo", - Driver: &fakedriver.Driver{ - MockState: state.Error, - }, - }, - } - - hostItem := getHostListItems(hosts, nil, 10*time.Second)[0] - - assert.Equal(t, "foo", hostItem.Name) - assert.Equal(t, state.Error, hostItem.State) - assert.Equal(t, "Driver", hostItem.DriverName) - assert.Empty(t, hostItem.URL) - assert.Equal(t, "Unable to get ip", hostItem.Error) - assert.Nil(t, hostItem.SwarmOptions) -} - -func TestGetSomeHostInError(t *testing.T) { - defer func(versioner mcndockerclient.DockerVersioner) { mcndockerclient.CurrentDockerVersioner = versioner }(mcndockerclient.CurrentDockerVersioner) - mcndockerclient.CurrentDockerVersioner = &mcndockerclient.FakeDockerVersioner{Version: "1.9"} - - hosts := []*host.Host{ - { - Name: "foo", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - } - hostsInError := map[string]error{ - "bar": errors.New("invalid memory address or nil pointer dereference"), - } - - hostItems := getHostListItems(hosts, hostsInError, 10*time.Second) - assert.Equal(t, 2, len(hostItems)) - - hostItem := hostItems[0] - assert.Equal(t, "bar", hostItem.Name) - assert.Equal(t, state.Error, hostItem.State) - assert.Equal(t, "not found", hostItem.DriverName) - assert.Empty(t, hostItem.URL) - assert.Equal(t, "invalid memory address or nil pointer dereference", hostItem.Error) - assert.Nil(t, hostItem.SwarmOptions) - - hostItem = hostItems[1] - assert.Equal(t, "foo", hostItem.Name) - assert.Equal(t, state.Running, hostItem.State) -} - -func TestOnErrorWithMultilineComment(t *testing.T) { - err := errors.New("missing parameter: the request must contain the parameter InstanceId\n status code: 400") - - itemInError := newHostListItemInError("foo", err) - - assert.Equal(t, itemInError.Error, "missing parameter: the request must contain the parameter InstanceId status code: 400") -} diff --git a/vendor/github.com/docker/machine/commands/mcndirs/utils.go b/vendor/github.com/docker/machine/commands/mcndirs/utils.go deleted file mode 100644 index 3181e7c..0000000 --- a/vendor/github.com/docker/machine/commands/mcndirs/utils.go +++ /dev/null @@ -1,27 +0,0 @@ -package mcndirs - -import ( - "os" - "path/filepath" - - "github.com/docker/machine/libmachine/mcnutils" -) - -var ( - BaseDir = os.Getenv("MACHINE_STORAGE_PATH") -) - -func GetBaseDir() string { - if BaseDir == "" { - BaseDir = filepath.Join(mcnutils.GetHomeDir(), ".docker", "machine") - } - return BaseDir -} - -func GetMachineDir() string { - return filepath.Join(GetBaseDir(), "machines") -} - -func GetMachineCertDir() string { - return filepath.Join(GetBaseDir(), "certs") -} diff --git a/vendor/github.com/docker/machine/commands/mcndirs/utils_test.go b/vendor/github.com/docker/machine/commands/mcndirs/utils_test.go deleted file mode 100644 index 9fca65f..0000000 --- a/vendor/github.com/docker/machine/commands/mcndirs/utils_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package mcndirs - -import ( - "path" - "strings" - "testing" - - "github.com/docker/machine/libmachine/mcnutils" -) - -func TestGetBaseDir(t *testing.T) { - // reset any override env var - BaseDir = "" - - homeDir := mcnutils.GetHomeDir() - baseDir := GetBaseDir() - - if strings.Index(baseDir, homeDir) != 0 { - t.Fatalf("expected base dir with prefix %s; received %s", homeDir, baseDir) - } -} - -func TestGetCustomBaseDir(t *testing.T) { - root := "/tmp" - BaseDir = root - baseDir := GetBaseDir() - - if strings.Index(baseDir, root) != 0 { - t.Fatalf("expected base dir with prefix %s; received %s", root, baseDir) - } - BaseDir = "" -} - -func TestGetMachineDir(t *testing.T) { - root := "/tmp" - BaseDir = root - machineDir := GetMachineDir() - - if strings.Index(machineDir, root) != 0 { - t.Fatalf("expected machine dir with prefix %s; received %s", root, machineDir) - } - - path, filename := path.Split(machineDir) - if strings.Index(path, root) != 0 { - t.Fatalf("expected base path of %s; received %s", root, path) - } - if filename != "machines" { - t.Fatalf("expected machine dir \"machines\"; received %s", filename) - } - BaseDir = "" -} - -func TestGetMachineCertDir(t *testing.T) { - root := "/tmp" - BaseDir = root - clientDir := GetMachineCertDir() - - if strings.Index(clientDir, root) != 0 { - t.Fatalf("expected machine client cert dir with prefix %s; received %s", root, clientDir) - } - - path, filename := path.Split(clientDir) - if strings.Index(path, root) != 0 { - t.Fatalf("expected base path of %s; received %s", root, path) - } - if filename != "certs" { - t.Fatalf("expected machine client dir \"certs\"; received %s", filename) - } - BaseDir = "" -} diff --git a/vendor/github.com/docker/machine/commands/mount.go b/vendor/github.com/docker/machine/commands/mount.go deleted file mode 100644 index 947195a..0000000 --- a/vendor/github.com/docker/machine/commands/mount.go +++ /dev/null @@ -1,136 +0,0 @@ -package commands - -import ( - "errors" - "fmt" - "os" - "os/exec" - "strings" - - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/log" -) - -var ( - // TODO: possibly move this to ssh package - baseSSHFSArgs = []string{ - "-o", "StrictHostKeyChecking=no", - "-o", "UserKnownHostsFile=/dev/null", - "-o", "LogLevel=quiet", // suppress "Warning: Permanently added '[localhost]:2022' (ECDSA) to the list of known hosts." - } -) - -func cmdMount(c CommandLine, api libmachine.API) error { - args := c.Args() - if len(args) < 1 || len(args) > 2 { - c.ShowHelp() - return errWrongNumberArguments - } - - src := args[0] - dest := "" - if len(args) > 1 { - dest = args[1] - } - - hostInfoLoader := &storeHostInfoLoader{api} - - cmd, err := getMountCmd(src, dest, c.Bool("unmount"), hostInfoLoader) - if err != nil { - return err - } - - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - return cmd.Run() -} - -func getMountCmd(src, dest string, unmount bool, hostInfoLoader HostInfoLoader) (*exec.Cmd, error) { - var cmdPath string - var err error - if !unmount { - cmdPath, err = exec.LookPath("sshfs") - if err != nil { - return nil, errors.New("You must have a copy of the sshfs binary locally to use the mount feature") - } - } else { - cmdPath, err = exec.LookPath("fusermount") - if err != nil { - return nil, errors.New("You must have a copy of the fusermount binary locally to use the unmount option") - } - } - - srcHost, srcUser, srcPath, srcOpts, err := getInfoForSshfsArg(src, hostInfoLoader) - if err != nil { - return nil, err - } - - if dest == "" { - dest = srcPath - } - - sshArgs := baseSSHFSArgs - if srcHost.GetSSHKeyPath() != "" { - sshArgs = append(sshArgs, "-o", "IdentitiesOnly=yes") - } - - // Append needed -i / private key flags to command. - sshArgs = append(sshArgs, srcOpts...) - - // Append actual arguments for the sshfs command (i.e. docker@:/path) - locationArg, err := generateLocationArg(srcHost, srcUser, srcPath) - if err != nil { - return nil, err - } - - if !unmount { - sshArgs = append(sshArgs, locationArg) - sshArgs = append(sshArgs, dest) - } else { - sshArgs = []string{"-u"} - sshArgs = append(sshArgs, dest) - } - - cmd := exec.Command(cmdPath, sshArgs...) - log.Debug(*cmd) - return cmd, nil -} - -func getInfoForSshfsArg(hostAndPath string, hostInfoLoader HostInfoLoader) (h HostInfo, user string, path string, args []string, err error) { - // Path with hostname. e.g. "hostname:/usr/bin/cmatrix" - var hostName string - if parts := strings.SplitN(hostAndPath, ":", 2); len(parts) < 2 { - hostName = defaultMachineName - path = parts[0] - } else { - hostName = parts[0] - path = parts[1] - } - if hParts := strings.SplitN(hostName, "@", 2); len(hParts) == 2 { - user, hostName = hParts[0], hParts[1] - } - - // Remote path - h, err = hostInfoLoader.load(hostName) - if err != nil { - return nil, "", "", nil, fmt.Errorf("Error loading host: %s", err) - } - - args = []string{} - port, err := h.GetSSHPort() - if err == nil && port > 0 { - args = append(args, "-o", fmt.Sprintf("Port=%v", port)) - } - - if h.GetSSHKeyPath() != "" { - args = append(args, "-o", fmt.Sprintf("IdentityFile=%s", h.GetSSHKeyPath())) - } - - if user == "" { - user = h.GetSSHUsername() - } - - return -} diff --git a/vendor/github.com/docker/machine/commands/mount_test.go b/vendor/github.com/docker/machine/commands/mount_test.go deleted file mode 100644 index 8f27c3d..0000000 --- a/vendor/github.com/docker/machine/commands/mount_test.go +++ /dev/null @@ -1,84 +0,0 @@ -package commands - -import ( - "os/exec" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestGetMountCmd(t *testing.T) { - hostInfoLoader := MockHostInfoLoader{MockHostInfo{ - ip: "12.34.56.78", - sshPort: 234, - sshUsername: "root", - sshKeyPath: "/fake/keypath/id_rsa", - }} - - path, err := exec.LookPath("sshfs") - if err != nil { - t.Skip("sshfs not found (install sshfs ?)") - } - cmd, err := getMountCmd("myfunhost:/home/docker/foo", "/tmp/foo", false, &hostInfoLoader) - - expectedArgs := append( - baseSSHFSArgs, - "-o", - "IdentitiesOnly=yes", - "-o", - "Port=234", - "-o", - "IdentityFile=/fake/keypath/id_rsa", - "root@12.34.56.78:/home/docker/foo", - "/tmp/foo", - ) - expectedCmd := exec.Command(path, expectedArgs...) - - assert.Equal(t, expectedCmd, cmd) - assert.NoError(t, err) -} - -func TestGetMountCmdWithoutSshKey(t *testing.T) { - hostInfoLoader := MockHostInfoLoader{MockHostInfo{ - ip: "1.2.3.4", - sshUsername: "user", - }} - - path, err := exec.LookPath("sshfs") - if err != nil { - t.Skip("sshfs not found (install sshfs ?)") - } - cmd, err := getMountCmd("myfunhost:/home/docker/foo", "", false, &hostInfoLoader) - - expectedArgs := append( - baseSSHFSArgs, - "user@1.2.3.4:/home/docker/foo", - "/home/docker/foo", - ) - expectedCmd := exec.Command(path, expectedArgs...) - - assert.Equal(t, expectedCmd, cmd) - assert.NoError(t, err) -} - -func TestGetMountCmdUnmount(t *testing.T) { - hostInfoLoader := MockHostInfoLoader{MockHostInfo{ - ip: "1.2.3.4", - sshUsername: "user", - }} - - path, err := exec.LookPath("fusermount") - if err != nil { - t.Skip("fusermount not found (install fuse ?)") - } - cmd, err := getMountCmd("myfunhost:/home/docker/foo", "/tmp/foo", true, &hostInfoLoader) - - expectedArgs := []string{ - "-u", - "/tmp/foo", - } - expectedCmd := exec.Command(path, expectedArgs...) - - assert.Equal(t, expectedCmd, cmd) - assert.NoError(t, err) -} diff --git a/vendor/github.com/docker/machine/commands/provision.go b/vendor/github.com/docker/machine/commands/provision.go deleted file mode 100644 index d707041..0000000 --- a/vendor/github.com/docker/machine/commands/provision.go +++ /dev/null @@ -1,7 +0,0 @@ -package commands - -import "github.com/docker/machine/libmachine" - -func cmdProvision(c CommandLine, api libmachine.API) error { - return runAction("provision", c, api) -} diff --git a/vendor/github.com/docker/machine/commands/provision_test.go b/vendor/github.com/docker/machine/commands/provision_test.go deleted file mode 100644 index 53f1bb1..0000000 --- a/vendor/github.com/docker/machine/commands/provision_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package commands - -import ( - "testing" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/libmachinetest" - "github.com/docker/machine/libmachine/provision" - "github.com/docker/machine/libmachine/swarm" - "github.com/stretchr/testify/assert" -) - -func TestCmdProvision(t *testing.T) { - testCases := []struct { - commandLine CommandLine - api libmachine.API - expectedErr error - }{ - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"foo", "bar"}, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "foo", - Driver: &fakedriver.Driver{}, - HostOptions: &host.Options{ - EngineOptions: &engine.Options{}, - AuthOptions: &auth.Options{}, - SwarmOptions: &swarm.Options{}, - }, - }, - { - Name: "bar", - Driver: &fakedriver.Driver{}, - HostOptions: &host.Options{ - EngineOptions: &engine.Options{}, - AuthOptions: &auth.Options{}, - SwarmOptions: &swarm.Options{}, - }, - }, - }, - }, - expectedErr: nil, - }, - } - - provision.SetDetector(&provision.FakeDetector{ - Provisioner: provision.NewFakeProvisioner(nil), - }) - - // fakeprovisioner always returns "true" for compatible host, so we - // just need to register it. - provision.Register("fakeprovisioner", &provision.RegisteredProvisioner{ - New: provision.NewFakeProvisioner, - }) - - for _, tc := range testCases { - assert.Equal(t, tc.expectedErr, cmdProvision(tc.commandLine, tc.api)) - } -} diff --git a/vendor/github.com/docker/machine/commands/regeneratecerts.go b/vendor/github.com/docker/machine/commands/regeneratecerts.go deleted file mode 100644 index f801f72..0000000 --- a/vendor/github.com/docker/machine/commands/regeneratecerts.go +++ /dev/null @@ -1,23 +0,0 @@ -package commands - -import ( - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/log" -) - -func cmdRegenerateCerts(c CommandLine, api libmachine.API) error { - if !c.Bool("force") { - ok, err := confirmInput("Regenerate TLS machine certs? Warning: this is irreversible.") - if err != nil { - return err - } - - if !ok { - return nil - } - } - - log.Infof("Regenerating TLS certificates") - - return runAction("configureAuth", c, api) -} diff --git a/vendor/github.com/docker/machine/commands/restart.go b/vendor/github.com/docker/machine/commands/restart.go deleted file mode 100644 index 1b197f9..0000000 --- a/vendor/github.com/docker/machine/commands/restart.go +++ /dev/null @@ -1,16 +0,0 @@ -package commands - -import ( - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/log" -) - -func cmdRestart(c CommandLine, api libmachine.API) error { - if err := runAction("restart", c, api); err != nil { - return err - } - - log.Info("Restarted machines may have new IP addresses. You may need to re-run the `docker-machine env` command.") - - return nil -} diff --git a/vendor/github.com/docker/machine/commands/rm.go b/vendor/github.com/docker/machine/commands/rm.go deleted file mode 100644 index 2e282b5..0000000 --- a/vendor/github.com/docker/machine/commands/rm.go +++ /dev/null @@ -1,89 +0,0 @@ -package commands - -import ( - "fmt" - - "strings" - - "errors" - - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/log" -) - -func cmdRm(c CommandLine, api libmachine.API) error { - if len(c.Args()) == 0 { - c.ShowHelp() - return ErrNoMachineSpecified - } - - log.Info(fmt.Sprintf("About to remove %s", strings.Join(c.Args(), ", "))) - log.Warn("WARNING: This action will delete both local reference and remote instance.") - - force := c.Bool("force") - confirm := c.Bool("y") - var errorOccurred []string - - if !userConfirm(confirm, force) { - return nil - } - - for _, hostName := range c.Args() { - err := removeRemoteMachine(hostName, api) - if err != nil { - errorOccurred = collectError(fmt.Sprintf("Error removing host %q: %s", hostName, err), force, errorOccurred) - } - - if err == nil || force { - removeErr := removeLocalMachine(hostName, api) - if removeErr != nil { - errorOccurred = collectError(fmt.Sprintf("Can't remove \"%s\"", hostName), force, errorOccurred) - } else { - log.Infof("Successfully removed %s", hostName) - } - } - } - - if len(errorOccurred) > 0 && !force { - return errors.New(strings.Join(errorOccurred, "\n")) - } - - return nil -} - -func userConfirm(confirm bool, force bool) bool { - if confirm || force { - return true - } - - sure, err := confirmInput(fmt.Sprintf("Are you sure?")) - if err != nil { - return false - } - - return sure -} - -func removeRemoteMachine(hostName string, api libmachine.API) error { - currentHost, loaderr := api.Load(hostName) - if loaderr != nil { - return loaderr - } - - return currentHost.Driver.Remove() -} - -func removeLocalMachine(hostName string, api libmachine.API) error { - exist, _ := api.Exists(hostName) - if !exist { - return errors.New(hostName + " does not exist.") - } - return api.Remove(hostName) -} - -func collectError(message string, force bool, errorOccurred []string) []string { - if force { - log.Error(message) - } - return append(errorOccurred, message) -} diff --git a/vendor/github.com/docker/machine/commands/rm_test.go b/vendor/github.com/docker/machine/commands/rm_test.go deleted file mode 100644 index adfe6a2..0000000 --- a/vendor/github.com/docker/machine/commands/rm_test.go +++ /dev/null @@ -1,233 +0,0 @@ -package commands - -import ( - "testing" - - "errors" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/libmachinetest" - "github.com/stretchr/testify/assert" -) - -func TestCmdRmMissingMachineName(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{} - api := &libmachinetest.FakeAPI{} - - err := cmdRm(commandLine, api) - - assert.Equal(t, ErrNoMachineSpecified, err) - assert.True(t, commandLine.HelpShown) -} - -func TestCmdRm(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machineToRemove1", "machineToRemove2"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "y": true, - }, - }, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machineToRemove1", - Driver: &fakedriver.Driver{}, - }, - { - Name: "machineToRemove2", - Driver: &fakedriver.Driver{}, - }, - { - Name: "machine", - Driver: &fakedriver.Driver{}, - }, - }, - } - - err := cmdRm(commandLine, api) - assert.NoError(t, err) - - assert.False(t, libmachinetest.Exists(api, "machineToRemove1")) - assert.False(t, libmachinetest.Exists(api, "machineToRemove2")) - assert.True(t, libmachinetest.Exists(api, "machine")) -} - -func TestCmdRmforcefully(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machineToRemove1", "machineToRemove2"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "force": true, - }, - }, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machineToRemove1", - Driver: &fakedriver.Driver{}, - }, - { - Name: "machineToRemove2", - Driver: &fakedriver.Driver{}, - }, - }, - } - - err := cmdRm(commandLine, api) - assert.NoError(t, err) - - assert.False(t, libmachinetest.Exists(api, "machineToRemove1")) - assert.False(t, libmachinetest.Exists(api, "machineToRemove2")) -} - -func TestCmdRmforceDoesAutoConfirm(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machineToRemove1", "machineToRemove2"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "y": false, - "force": true, - }, - }, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machineToRemove1", - Driver: &fakedriver.Driver{}, - }, - { - Name: "machineToRemove2", - Driver: &fakedriver.Driver{}, - }, - }, - } - - err := cmdRm(commandLine, api) - assert.NoError(t, err) - - assert.False(t, libmachinetest.Exists(api, "machineToRemove1")) - assert.False(t, libmachinetest.Exists(api, "machineToRemove2")) -} - -func TestCmdRmforceConfirmUnset(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machineToRemove1"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "y": false, - "force": false, - }, - }, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machineToRemove1", - Driver: &fakedriver.Driver{}, - }, - }, - } - - err := cmdRm(commandLine, api) - assert.NoError(t, err) - - assert.True(t, libmachinetest.Exists(api, "machineToRemove1")) -} - -type DriverWithRemoveWhichFail struct { - fakedriver.Driver -} - -func (d *DriverWithRemoveWhichFail) Remove() error { - return errors.New("unknown error") -} - -func TestDontStopWhenADriverRemovalFails(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machineToRemove1", "machineToRemove2", "machineToRemove3"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "y": true, - }, - }, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machineToRemove1", - Driver: &fakedriver.Driver{}, - }, - { - Name: "machineToRemove2", - Driver: &DriverWithRemoveWhichFail{}, - }, - { - Name: "machineToRemove3", - Driver: &fakedriver.Driver{}, - }, - }, - } - - err := cmdRm(commandLine, api) - assert.EqualError(t, err, "Error removing host \"machineToRemove2\": unknown error") - - assert.False(t, libmachinetest.Exists(api, "machineToRemove1")) - assert.True(t, libmachinetest.Exists(api, "machineToRemove2")) - assert.False(t, libmachinetest.Exists(api, "machineToRemove3")) -} - -func TestForceRemoveEvenWhenItFails(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machineToRemove1"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "y": true, - "force": true, - }, - }, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machineToRemove1", - Driver: &DriverWithRemoveWhichFail{}, - }, - }, - } - - err := cmdRm(commandLine, api) - assert.NoError(t, err) - - assert.False(t, libmachinetest.Exists(api, "machineToRemove1")) -} - -func TestDontRemoveMachineIsRemovalFailsAndNotForced(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machineToRemove1"}, - LocalFlags: &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "y": true, - "force": false, - }, - }, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machineToRemove1", - Driver: &DriverWithRemoveWhichFail{}, - }, - }, - } - - err := cmdRm(commandLine, api) - assert.EqualError(t, err, "Error removing host \"machineToRemove1\": unknown error") - - assert.True(t, libmachinetest.Exists(api, "machineToRemove1")) -} diff --git a/vendor/github.com/docker/machine/commands/scp.go b/vendor/github.com/docker/machine/commands/scp.go deleted file mode 100644 index add9aa8..0000000 --- a/vendor/github.com/docker/machine/commands/scp.go +++ /dev/null @@ -1,209 +0,0 @@ -package commands - -import ( - "errors" - "fmt" - "os" - "os/exec" - "strings" - - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/persist" -) - -var ( - errWrongNumberArguments = errors.New("Improper number of arguments") - - // TODO: possibly move this to ssh package - baseSSHArgs = []string{ - "-o", "StrictHostKeyChecking=no", - "-o", "UserKnownHostsFile=/dev/null", - "-o", "LogLevel=quiet", // suppress "Warning: Permanently added '[localhost]:2022' (ECDSA) to the list of known hosts." - } -) - -// HostInfo gives the mandatory information to connect to a host. -type HostInfo interface { - GetMachineName() string - - GetSSHHostname() (string, error) - - GetSSHPort() (int, error) - - GetSSHUsername() string - - GetSSHKeyPath() string -} - -// HostInfoLoader loads host information. -type HostInfoLoader interface { - load(name string) (HostInfo, error) -} - -type storeHostInfoLoader struct { - store persist.Store -} - -func (s *storeHostInfoLoader) load(name string) (HostInfo, error) { - host, err := s.store.Load(name) - if err != nil { - return nil, fmt.Errorf("Error loading host: %s", err) - } - - return host.Driver, nil -} - -func cmdScp(c CommandLine, api libmachine.API) error { - args := c.Args() - if len(args) != 2 { - c.ShowHelp() - return errWrongNumberArguments - } - - src := args[0] - dest := args[1] - - hostInfoLoader := &storeHostInfoLoader{api} - - cmd, err := getScpCmd(src, dest, c.Bool("recursive"), c.Bool("delta"), hostInfoLoader) - if err != nil { - return err - } - - return runCmdWithStdIo(*cmd) -} - -func getScpCmd(src, dest string, recursive bool, delta bool, hostInfoLoader HostInfoLoader) (*exec.Cmd, error) { - var cmdPath string - var err error - if !delta { - cmdPath, err = exec.LookPath("scp") - if err != nil { - return nil, errors.New("You must have a copy of the scp binary locally to use the scp feature") - } - } else { - cmdPath, err = exec.LookPath("rsync") - if err != nil { - return nil, errors.New("You must have a copy of the rsync binary locally to use the --delta option") - } - } - - srcHost, srcUser, srcPath, srcOpts, err := getInfoForScpArg(src, hostInfoLoader) - if err != nil { - return nil, err - } - - destHost, destUser, destPath, destOpts, err := getInfoForScpArg(dest, hostInfoLoader) - if err != nil { - return nil, err - } - - // TODO: Check that "-3" flag is available in user's version of scp. - // It is on every system I've checked, but the manual mentioned it's "newer" - sshArgs := baseSSHArgs - if !delta { - sshArgs = append(sshArgs, "-3") - if recursive { - sshArgs = append(sshArgs, "-r") - } - } - - // Don't use ssh-agent if both hosts have explicit ssh keys - if !missesExplicitSSHKey(srcHost) && !missesExplicitSSHKey(destHost) { - sshArgs = append(sshArgs, "-o", "IdentitiesOnly=yes") - } - - // Append needed -i / private key flags to command. - sshArgs = append(sshArgs, srcOpts...) - sshArgs = append(sshArgs, destOpts...) - - // Append actual arguments for the scp command (i.e. docker@:/path) - locationArg, err := generateLocationArg(srcHost, srcUser, srcPath) - if err != nil { - return nil, err - } - - if delta { - sshArgs = append([]string{"-e"}, "ssh "+strings.Join(sshArgs, " ")) - if recursive { - sshArgs = append(sshArgs, "-r") - } - } - - sshArgs = append(sshArgs, locationArg) - locationArg, err = generateLocationArg(destHost, destUser, destPath) - if err != nil { - return nil, err - } - sshArgs = append(sshArgs, locationArg) - - cmd := exec.Command(cmdPath, sshArgs...) - log.Debug(*cmd) - return cmd, nil -} - -func missesExplicitSSHKey(hostInfo HostInfo) bool { - return hostInfo != nil && hostInfo.GetSSHKeyPath() == "" -} - -func getInfoForScpArg(hostAndPath string, hostInfoLoader HostInfoLoader) (h HostInfo, user string, path string, args []string, err error) { - // Local path. e.g. "/tmp/foo" - if !strings.Contains(hostAndPath, ":") { - return nil, "", hostAndPath, nil, nil - } - - // Path with hostname. e.g. "hostname:/usr/bin/cmatrix" - parts := strings.SplitN(hostAndPath, ":", 2) - hostName := parts[0] - if hParts := strings.SplitN(hostName, "@", 2); len(hParts) == 2 { - user, hostName = hParts[0], hParts[1] - } - path = parts[1] - if hostName == "localhost" { - return nil, "", path, nil, nil - } - - // Remote path - h, err = hostInfoLoader.load(hostName) - if err != nil { - return nil, "", "", nil, fmt.Errorf("Error loading host: %s", err) - } - - args = []string{} - port, err := h.GetSSHPort() - if err == nil && port > 0 { - args = append(args, "-o", fmt.Sprintf("Port=%v", port)) - } - - if h.GetSSHKeyPath() != "" { - args = append(args, "-o", fmt.Sprintf("IdentityFile=%q", h.GetSSHKeyPath())) - } - - return -} - -func generateLocationArg(hostInfo HostInfo, user, path string) (string, error) { - if hostInfo == nil { - return path, nil - } - - hostname, err := hostInfo.GetSSHHostname() - if err != nil { - return "", err - } - - if user == "" { - user = hostInfo.GetSSHUsername() - } - location := fmt.Sprintf("%s@%s:%s", user, hostname, path) - return location, nil -} - -func runCmdWithStdIo(cmd exec.Cmd) error { - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - return cmd.Run() -} diff --git a/vendor/github.com/docker/machine/commands/scp_test.go b/vendor/github.com/docker/machine/commands/scp_test.go deleted file mode 100644 index 1549792..0000000 --- a/vendor/github.com/docker/machine/commands/scp_test.go +++ /dev/null @@ -1,178 +0,0 @@ -package commands - -import ( - "os/exec" - "strings" - "testing" - - "github.com/stretchr/testify/assert" -) - -type MockHostInfo struct { - name string - ip string - sshPort int - sshUsername string - sshKeyPath string -} - -func (h *MockHostInfo) GetMachineName() string { - return h.name -} - -func (h *MockHostInfo) GetSSHHostname() (string, error) { - return h.ip, nil -} - -func (h *MockHostInfo) GetSSHPort() (int, error) { - return h.sshPort, nil -} - -func (h *MockHostInfo) GetSSHUsername() string { - return h.sshUsername -} - -func (h *MockHostInfo) GetSSHKeyPath() string { - return h.sshKeyPath -} - -type MockHostInfoLoader struct { - hostInfo MockHostInfo -} - -func (l *MockHostInfoLoader) load(name string) (HostInfo, error) { - info := l.hostInfo - info.name = name - return &info, nil -} - -func TestGetInfoForLocalScpArg(t *testing.T) { - host, user, path, opts, err := getInfoForScpArg("/tmp/foo", nil) - assert.Nil(t, host) - assert.Empty(t, user) - assert.Equal(t, "/tmp/foo", path) - assert.Nil(t, opts) - assert.NoError(t, err) - - host, user, path, opts, err = getInfoForScpArg("localhost:C:\\path", nil) - assert.Nil(t, host) - assert.Empty(t, user) - assert.Equal(t, "C:\\path", path) - assert.Nil(t, opts) - assert.NoError(t, err) -} - -func TestGetInfoForRemoteScpArg(t *testing.T) { - hostInfoLoader := MockHostInfoLoader{MockHostInfo{ - sshKeyPath: "/fake/keypath/id_rsa", - }} - - host, user, path, opts, err := getInfoForScpArg("myuser@myfunhost:/home/docker/foo", &hostInfoLoader) - assert.Equal(t, "myfunhost", host.GetMachineName()) - assert.Equal(t, "myuser", user) - assert.Equal(t, "/home/docker/foo", path) - assert.Equal(t, []string{"-o", `IdentityFile="/fake/keypath/id_rsa"`}, opts) - assert.NoError(t, err) - - host, user, path, opts, err = getInfoForScpArg("myfunhost:C:\\path", &hostInfoLoader) - assert.Equal(t, "myfunhost", host.GetMachineName()) - assert.Empty(t, user) - assert.Equal(t, "C:\\path", path) - assert.Equal(t, []string{"-o", `IdentityFile="/fake/keypath/id_rsa"`}, opts) - assert.NoError(t, err) -} - -func TestHostLocation(t *testing.T) { - arg, err := generateLocationArg(nil, "user1", "/home/docker/foo") - - assert.Equal(t, "/home/docker/foo", arg) - assert.NoError(t, err) -} - -func TestRemoteLocation(t *testing.T) { - hostInfo := MockHostInfo{ - ip: "12.34.56.78", - sshUsername: "root", - } - - arg, err := generateLocationArg(&hostInfo, "", "/home/docker/foo") - - assert.Equal(t, "root@12.34.56.78:/home/docker/foo", arg) - assert.NoError(t, err) - - argWithUser, err := generateLocationArg(&hostInfo, "user1", "/home/docker/foo") - - assert.Equal(t, "user1@12.34.56.78:/home/docker/foo", argWithUser) - assert.NoError(t, err) -} - -func TestGetScpCmd(t *testing.T) { - hostInfoLoader := MockHostInfoLoader{MockHostInfo{ - ip: "12.34.56.78", - sshPort: 234, - sshUsername: "root", - sshKeyPath: "/fake/keypath/id_rsa", - }} - - cmd, err := getScpCmd("/tmp/foo", "myfunhost:/home/docker/foo", true, false, &hostInfoLoader) - - expectedArgs := append( - baseSSHArgs, - "-3", - "-r", - "-o", - "IdentitiesOnly=yes", - "-o", - "Port=234", - "-o", - `IdentityFile="/fake/keypath/id_rsa"`, - "/tmp/foo", - "root@12.34.56.78:/home/docker/foo", - ) - expectedCmd := exec.Command("/usr/bin/scp", expectedArgs...) - - assert.Equal(t, expectedCmd, cmd) - assert.NoError(t, err) -} - -func TestGetScpCmdWithoutSshKey(t *testing.T) { - hostInfoLoader := MockHostInfoLoader{MockHostInfo{ - ip: "1.2.3.4", - sshUsername: "user", - }} - - cmd, err := getScpCmd("/tmp/foo", "myfunhost:/home/docker/foo", true, false, &hostInfoLoader) - - expectedArgs := append( - baseSSHArgs, - "-3", - "-r", - "/tmp/foo", - "user@1.2.3.4:/home/docker/foo", - ) - expectedCmd := exec.Command("/usr/bin/scp", expectedArgs...) - - assert.Equal(t, expectedCmd, cmd) - assert.NoError(t, err) -} - -func TestGetScpCmdWithDelta(t *testing.T) { - hostInfoLoader := MockHostInfoLoader{MockHostInfo{ - ip: "1.2.3.4", - sshUsername: "user", - }} - - cmd, err := getScpCmd("/tmp/foo", "myfunhost:/home/docker/foo", true, true, &hostInfoLoader) - - expectedArgs := append( - []string{"-e"}, - "ssh "+strings.Join(baseSSHArgs, " "), - "-r", - "/tmp/foo", - "user@1.2.3.4:/home/docker/foo", - ) - expectedCmd := exec.Command("/usr/bin/rsync", expectedArgs...) - - assert.Equal(t, expectedCmd, cmd) - assert.NoError(t, err) -} diff --git a/vendor/github.com/docker/machine/commands/ssh.go b/vendor/github.com/docker/machine/commands/ssh.go deleted file mode 100644 index 3c34174..0000000 --- a/vendor/github.com/docker/machine/commands/ssh.go +++ /dev/null @@ -1,51 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/state" -) - -type errStateInvalidForSSH struct { - HostName string -} - -func (e errStateInvalidForSSH) Error() string { - return fmt.Sprintf("Error: Cannot run SSH command: Host %q is not running", e.HostName) -} - -func cmdSSH(c CommandLine, api libmachine.API) error { - // Check for help flag -- Needed due to SkipFlagParsing - firstArg := c.Args().First() - if firstArg == "-help" || firstArg == "--help" || firstArg == "-h" { - c.ShowHelp() - return nil - } - - target, err := targetHost(c, api) - if err != nil { - return err - } - - host, err := api.Load(target) - if err != nil { - return err - } - - currentState, err := host.Driver.GetState() - if err != nil { - return err - } - - if currentState != state.Running { - return errStateInvalidForSSH{host.Name} - } - - client, err := host.CreateSSHClient() - if err != nil { - return err - } - - return client.Shell(c.Args().Tail()...) -} diff --git a/vendor/github.com/docker/machine/commands/ssh_test.go b/vendor/github.com/docker/machine/commands/ssh_test.go deleted file mode 100644 index ebfa10f..0000000 --- a/vendor/github.com/docker/machine/commands/ssh_test.go +++ /dev/null @@ -1,111 +0,0 @@ -package commands - -import ( - "testing" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/libmachinetest" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/ssh/sshtest" - "github.com/docker/machine/libmachine/state" - "github.com/stretchr/testify/assert" -) - -type FakeSSHClientCreator struct { - client ssh.Client -} - -func (fsc *FakeSSHClientCreator) CreateSSHClient(d drivers.Driver) (ssh.Client, error) { - if fsc.client == nil { - fsc.client = &sshtest.FakeClient{} - } - return fsc.client, nil -} - -func TestCmdSSH(t *testing.T) { - testCases := []struct { - commandLine CommandLine - api libmachine.API - expectedErr error - helpShown bool - clientCreator host.SSHClientCreator - expectedShell []string - }{ - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"-h"}, - }, - api: &libmachinetest.FakeAPI{}, - expectedErr: nil, - helpShown: true, - }, - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"--help"}, - }, - api: &libmachinetest.FakeAPI{}, - expectedErr: nil, - helpShown: true, - }, - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{}, - }, - api: &libmachinetest.FakeAPI{}, - expectedErr: ErrNoDefault, - }, - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"default", "df", "-h"}, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "default", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - }, - }, - expectedErr: nil, - clientCreator: &FakeSSHClientCreator{}, - expectedShell: []string{"df", "-h"}, - }, - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"default"}, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "default", - Driver: &fakedriver.Driver{ - MockState: state.Stopped, - }, - }, - }, - }, - expectedErr: errStateInvalidForSSH{"default"}, - }, - } - - for _, tc := range testCases { - host.SetSSHClientCreator(tc.clientCreator) - - err := cmdSSH(tc.commandLine, tc.api) - assert.Equal(t, err, tc.expectedErr) - - if fcl, ok := tc.commandLine.(*commandstest.FakeCommandLine); ok { - assert.Equal(t, tc.helpShown, fcl.HelpShown) - } - - if fcc, ok := tc.clientCreator.(*FakeSSHClientCreator); ok { - assert.Equal(t, tc.expectedShell, fcc.client.(*sshtest.FakeClient).ActivatedShell) - } - } -} diff --git a/vendor/github.com/docker/machine/commands/start.go b/vendor/github.com/docker/machine/commands/start.go deleted file mode 100644 index 09322f1..0000000 --- a/vendor/github.com/docker/machine/commands/start.go +++ /dev/null @@ -1,16 +0,0 @@ -package commands - -import ( - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/log" -) - -func cmdStart(c CommandLine, api libmachine.API) error { - if err := runAction("start", c, api); err != nil { - return err - } - - log.Info("Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.") - - return nil -} diff --git a/vendor/github.com/docker/machine/commands/status.go b/vendor/github.com/docker/machine/commands/status.go deleted file mode 100644 index 672b8da..0000000 --- a/vendor/github.com/docker/machine/commands/status.go +++ /dev/null @@ -1,32 +0,0 @@ -package commands - -import ( - "fmt" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/log" -) - -func cmdStatus(c CommandLine, api libmachine.API) error { - if len(c.Args()) > 1 { - return ErrExpectedOneMachine - } - - target, err := targetHost(c, api) - if err != nil { - return err - } - - host, err := api.Load(target) - if err != nil { - return err - } - - currentState, err := host.Driver.GetState() - if err != nil { - return fmt.Errorf("error getting state for host %s: %s", host.Name, err) - } - - log.Info(currentState) - - return nil -} diff --git a/vendor/github.com/docker/machine/commands/stop.go b/vendor/github.com/docker/machine/commands/stop.go deleted file mode 100644 index bd0cd38..0000000 --- a/vendor/github.com/docker/machine/commands/stop.go +++ /dev/null @@ -1,7 +0,0 @@ -package commands - -import "github.com/docker/machine/libmachine" - -func cmdStop(c CommandLine, api libmachine.API) error { - return runAction("stop", c, api) -} diff --git a/vendor/github.com/docker/machine/commands/stop_test.go b/vendor/github.com/docker/machine/commands/stop_test.go deleted file mode 100644 index 76af095..0000000 --- a/vendor/github.com/docker/machine/commands/stop_test.go +++ /dev/null @@ -1,103 +0,0 @@ -package commands - -import ( - "testing" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/libmachinetest" - "github.com/docker/machine/libmachine/state" - "github.com/stretchr/testify/assert" -) - -func TestCmdStop(t *testing.T) { - testCases := []struct { - commandLine CommandLine - api libmachine.API - expectedErr error - expectedStates map[string]state.State - }{ - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{}, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "default", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - }, - }, - expectedErr: nil, - expectedStates: map[string]state.State{ - "default": state.Stopped, - }, - }, - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{}, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "foobar", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - }, - }, - expectedErr: ErrNoDefault, - expectedStates: map[string]state.State{ - "foobar": state.Running, - }, - }, - { - commandLine: &commandstest.FakeCommandLine{ - CliArgs: []string{"machineToStop1", "machineToStop2"}, - }, - api: &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machineToStop1", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - { - Name: "machineToStop2", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - { - Name: "machine", - Driver: &fakedriver.Driver{ - MockState: state.Running, - }, - }, - }, - }, - expectedErr: nil, - expectedStates: map[string]state.State{ - "machineToStop1": state.Stopped, - "machineToStop2": state.Stopped, - "machine": state.Running, - }, - }, - } - - for _, tc := range testCases { - err := cmdStop(tc.commandLine, tc.api) - assert.Equal(t, tc.expectedErr, err) - - for hostName, expectedState := range tc.expectedStates { - assert.Equal(t, expectedState, libmachinetest.State(tc.api, hostName)) - } - } -} diff --git a/vendor/github.com/docker/machine/commands/upgrade.go b/vendor/github.com/docker/machine/commands/upgrade.go deleted file mode 100644 index 84282f1..0000000 --- a/vendor/github.com/docker/machine/commands/upgrade.go +++ /dev/null @@ -1,7 +0,0 @@ -package commands - -import "github.com/docker/machine/libmachine" - -func cmdUpgrade(c CommandLine, api libmachine.API) error { - return runAction("upgrade", c, api) -} diff --git a/vendor/github.com/docker/machine/commands/url.go b/vendor/github.com/docker/machine/commands/url.go deleted file mode 100644 index 8552e14..0000000 --- a/vendor/github.com/docker/machine/commands/url.go +++ /dev/null @@ -1,32 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/docker/machine/libmachine" -) - -func cmdURL(c CommandLine, api libmachine.API) error { - if len(c.Args()) > 1 { - return ErrExpectedOneMachine - } - - target, err := targetHost(c, api) - if err != nil { - return err - } - - host, err := api.Load(target) - if err != nil { - return err - } - - url, err := host.URL() - if err != nil { - return err - } - - fmt.Println(url) - - return nil -} diff --git a/vendor/github.com/docker/machine/commands/url_test.go b/vendor/github.com/docker/machine/commands/url_test.go deleted file mode 100644 index 02f7268..0000000 --- a/vendor/github.com/docker/machine/commands/url_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package commands - -import ( - "testing" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/libmachinetest" - "github.com/docker/machine/libmachine/state" - "github.com/stretchr/testify/assert" -) - -func TestCmdURLMissingMachineName(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{} - api := &libmachinetest.FakeAPI{} - - err := cmdURL(commandLine, api) - - assert.Equal(t, ErrNoDefault, err) -} - -func TestCmdURLTooManyNames(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machineToRemove1", "machineToRemove2"}, - } - api := &libmachinetest.FakeAPI{} - - err := cmdURL(commandLine, api) - - assert.EqualError(t, err, "Error: Expected one machine name as an argument") -} - -func TestCmdURL(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machine"}, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machine", - Driver: &fakedriver.Driver{ - MockState: state.Running, - MockIP: "120.0.0.1", - }, - }, - }, - } - - stdoutGetter := commandstest.NewStdoutGetter() - defer stdoutGetter.Stop() - - err := cmdURL(commandLine, api) - - assert.NoError(t, err) - assert.Equal(t, "tcp://120.0.0.1:2376\n", stdoutGetter.Output()) -} diff --git a/vendor/github.com/docker/machine/commands/version.go b/vendor/github.com/docker/machine/commands/version.go deleted file mode 100644 index a1a5390..0000000 --- a/vendor/github.com/docker/machine/commands/version.go +++ /dev/null @@ -1,40 +0,0 @@ -package commands - -import ( - "fmt" - - "io" - "os" - - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/mcndockerclient" -) - -func cmdVersion(c CommandLine, api libmachine.API) error { - return printVersion(c, api, os.Stdout) -} - -func printVersion(c CommandLine, api libmachine.API, out io.Writer) error { - if len(c.Args()) == 0 { - c.ShowVersion() - return nil - } - - if len(c.Args()) != 1 { - return ErrExpectedOneMachine - } - - host, err := api.Load(c.Args().First()) - if err != nil { - return err - } - - version, err := mcndockerclient.DockerVersion(host) - if err != nil { - return err - } - - fmt.Fprintln(out, version) - - return nil -} diff --git a/vendor/github.com/docker/machine/commands/version_test.go b/vendor/github.com/docker/machine/commands/version_test.go deleted file mode 100644 index 4978f8e..0000000 --- a/vendor/github.com/docker/machine/commands/version_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package commands - -import ( - "errors" - "testing" - - "bytes" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/libmachinetest" - "github.com/docker/machine/libmachine/mcndockerclient" - "github.com/stretchr/testify/assert" -) - -func TestCmdVersion(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{} - api := &libmachinetest.FakeAPI{} - - err := cmdVersion(commandLine, api) - - assert.True(t, commandLine.VersionShown) - assert.NoError(t, err) -} - -func TestCmdVersionTooManyNames(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machine1", "machine2"}, - } - api := &libmachinetest.FakeAPI{} - - err := cmdVersion(commandLine, api) - - assert.EqualError(t, err, "Error: Expected one machine name as an argument") -} - -func TestCmdVersionNotFound(t *testing.T) { - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"unknown"}, - } - api := &libmachinetest.FakeAPI{} - - err := cmdVersion(commandLine, api) - - assert.EqualError(t, err, `Docker machine "unknown" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.`) -} - -func TestCmdVersionOnHost(t *testing.T) { - defer func(versioner mcndockerclient.DockerVersioner) { mcndockerclient.CurrentDockerVersioner = versioner }(mcndockerclient.CurrentDockerVersioner) - mcndockerclient.CurrentDockerVersioner = &mcndockerclient.FakeDockerVersioner{Version: "1.9.1"} - - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machine"}, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machine", - }, - }, - } - - out := &bytes.Buffer{} - err := printVersion(commandLine, api, out) - - assert.NoError(t, err) - assert.Equal(t, "1.9.1\n", out.String()) -} - -func TestCmdVersionFailure(t *testing.T) { - defer func(versioner mcndockerclient.DockerVersioner) { mcndockerclient.CurrentDockerVersioner = versioner }(mcndockerclient.CurrentDockerVersioner) - mcndockerclient.CurrentDockerVersioner = &mcndockerclient.FakeDockerVersioner{Err: errors.New("connection failure")} - - commandLine := &commandstest.FakeCommandLine{ - CliArgs: []string{"machine"}, - } - api := &libmachinetest.FakeAPI{ - Hosts: []*host.Host{ - { - Name: "machine", - }, - }, - } - - out := &bytes.Buffer{} - err := printVersion(commandLine, api, out) - - assert.EqualError(t, err, "connection failure") -} diff --git a/vendor/github.com/docker/machine/contrib/completion/.gitignore b/vendor/github.com/docker/machine/contrib/completion/.gitignore deleted file mode 100644 index b9d4dad..0000000 --- a/vendor/github.com/docker/machine/contrib/completion/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!docker-machine* diff --git a/vendor/github.com/docker/machine/contrib/completion/bash/docker-machine-prompt.bash b/vendor/github.com/docker/machine/contrib/completion/bash/docker-machine-prompt.bash deleted file mode 100644 index 0a6e43a..0000000 --- a/vendor/github.com/docker/machine/contrib/completion/bash/docker-machine-prompt.bash +++ /dev/null @@ -1,47 +0,0 @@ -# -# bash prompt support for docker-machine -# -# This script allows you to see the active machine in your bash prompt. -# -# To enable: -# 1a. Copy this file somewhere and source it in your .bashrc -# source /some/where/docker-machine-prompt.bash -# 1b. Alternatively, just copy this file into into /etc/bash_completion.d -# 2. Change your PS1 to call __docker-machine-ps1 as command-substitution -# PS1='[\u@\h \W$(__docker_machine_ps1 " [%s]")]\$ ' -# -# Configuration: -# -# DOCKER_MACHINE_PS1_SHOWSTATUS -# When set, the machine status is indicated in the prompt. This can be slow, -# so use with care. -# - -__docker_machine_ps1 () { - local format=${1:- [%s]} - if test ${DOCKER_MACHINE_NAME}; then - local status - if test ${DOCKER_MACHINE_PS1_SHOWSTATUS:-false} = true; then - status=$(docker-machine status ${DOCKER_MACHINE_NAME}) - case ${status} in - Running) - status=' R' - ;; - Stopping) - status=' R->S' - ;; - Starting) - status=' S->R' - ;; - Error|Timeout) - status=' E' - ;; - *) - # Just consider everything elase as 'stopped' - status=' S' - ;; - esac - fi - printf -- "${format}" "${DOCKER_MACHINE_NAME}${status}" - fi -} diff --git a/vendor/github.com/docker/machine/contrib/completion/bash/docker-machine-wrapper.bash b/vendor/github.com/docker/machine/contrib/completion/bash/docker-machine-wrapper.bash deleted file mode 100644 index 89aabfa..0000000 --- a/vendor/github.com/docker/machine/contrib/completion/bash/docker-machine-wrapper.bash +++ /dev/null @@ -1,56 +0,0 @@ -# -# Function wrapper to docker-machine that adds a use subcommand. -# -# The use subcommand runs `eval "$(docker-machine env [args])"`, which is a lot -# less typing. -# -# To enable: -# 1a. Copy this file somewhere and source it in your .bashrc -# source /some/where/docker-machine-wrapper.bash -# 1b. Alternatively, just copy this file into into /etc/bash_completion.d -# -# Configuration: -# -# DOCKER_MACHINE_WRAPPED -# When set to a value other than true, this will disable the alias wrapper -# alias for docker-machine. This is useful if you don't want the wrapper, -# but it is installed by default by your installation. -# - -: ${DOCKER_MACHINE_WRAPPED:=true} - -__docker_machine_wrapper () { - if [[ "$1" == use ]]; then - # Special use wrapper - shift 1 - case "$1" in - -h|--help|"") - cat </dev/null "$@" -} - -# suppresses trailing whitespace -_docker_machine_nospace() { - # compopt is not available in ancient bash versions (OSX) - # so only call it if it's available - type compopt &>/dev/null && compopt -o nospace -} - -_docker_machine_machines() { - _docker_machine_q ls --format '{{.Name}}' "$@" -} - -_docker_machine_drivers() { - local drivers=( - amazonec2 - azure - digitalocean - exoscale - generic - google - hyperv - openstack - rackspace - softlayer - virtualbox - vmwarefusion - vmwarevcloudair - vmwarevsphere - ) - echo "${drivers[@]}" -} - -_docker_machine_value_of_option() { - local pattern="$1" - for (( i=2; i < ${cword}; ++i)); do - if [[ ${words[$i]} =~ ^($pattern)$ ]] ; then - echo ${words[$i + 1]} - break - fi - done -} - -# Returns `key` if we are currently completing the value of a map option -# (`key=value`) which matches the glob passed in as an argument. -# This function is needed for key-specific argument completions. -_docker_machine_map_key_of_current_option() { - local glob="$1" - - local key glob_pos - if [ "$cur" = "=" ] ; then # key= case - key="$prev" - glob_pos=$((cword - 2)) - elif [[ $cur == *=* ]] ; then # key=value case (OSX) - key=${cur%=*} - glob_pos=$((cword - 1)) - elif [ "$prev" = "=" ] ; then - key=${words[$cword - 2]} # key=value case - glob_pos=$((cword - 3)) - else - return - fi - - [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax - - [[ ${words[$glob_pos]} == $glob ]] && echo "$key" -} - -# --- completion functions --------------------------------------------------- - -_docker_machine_active() { - case "${prev}" in - --timeout|-t) - return - ;; - esac - - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help --timeout -t" -- "${cur}")) - fi -} - -_docker_machine_config() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help --swarm" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_create() { - case "${prev}" in - --driver|-d) - COMPREPLY=($(compgen -W "$(_docker_machine_drivers)" -- "${cur}")) - return - ;; - esac - - # driver specific options are only included in help output if --driver is given, - # so we have to pass that option when calling docker-machine to harvest options. - local driver="$(_docker_machine_value_of_option '--driver|-d')" - local parsed_options="$(_docker_machine_q create ${driver:+--driver $driver} --help | grep '^ -' | sed 's/^ //; s/[^a-z0-9-].*$//')" - if [[ ${cur} == -* ]]; then - COMPREPLY=($(compgen -W "${parsed_options} -d --help" -- "${cur}")) - fi -} - -_docker_machine_env() { - case "${prev}" in - --shell) - COMPREPLY=($(compgen -W "cmd fish powershell tcsh" -- "${cur}")) - return - ;; - esac - - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help --no-proxy --shell --swarm --unset -u" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -# See docker-machine-wrapper.bash for the use command -_docker_machine_use() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help --swarm --unset" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_inspect() { - case "${prev}" in - --format|-f) - return - ;; - esac - - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--format -f --help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_ip() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_kill() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_ls() { - local key=$(_docker_machine_map_key_of_current_option '--filter') - case "$key" in - driver) - COMPREPLY=($(compgen -W "$(_docker_machine_drivers)" -- "${cur##*=}")) - return - ;; - state) - COMPREPLY=($(compgen -W "Error Paused Running Saved Starting Stopped Stopping" -- "${cur##*=}")) - return - ;; - esac - - case "${prev}" in - --filter) - COMPREPLY=($(compgen -W "driver label name state swarm" -S= -- "${cur}")) - _docker_machine_nospace - return - ;; - --format|-f|--timeout|-t) - return - ;; - esac - - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--filter --format -f --help --quiet -q --timeout -t" -- "${cur}")) - fi -} - -_docker_machine_provision() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Running)" -- "${cur}")) - fi -} - -_docker_machine_regenerate_certs() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--force -f --help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Running)" -- "${cur}")) - fi -} - -_docker_machine_restart() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_rm() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--force -f --help -y" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_ssh() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_scp() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--delta -d --help --recursive -r" -- "${cur}")) - else - _filedir - # It would be really nice to ssh to the machine and ls to complete - # remote files. - COMPREPLY=($(compgen -W "$(_docker_machine_machines | sed 's/$/:/')" -- "${cur}") "${COMPREPLY[@]}") - fi -} - -_docker_machine_start() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Stopped)" -- "${cur}")) - fi -} - -_docker_machine_status() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_stop() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Running)" -- "${cur}")) - fi -} - -_docker_machine_upgrade() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_url() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_version() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "$(_docker_machine_machines)" -- "${cur}")) - fi -} - -_docker_machine_help() { - if [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "--help" -- "${cur}")) - else - COMPREPLY=($(compgen -W "${commands[*]}" -- "${cur}")) - fi -} - -_docker_machine_docker_machine() { - if [[ " ${wants_file[*]} " =~ " ${prev} " ]]; then - _filedir - elif [[ " ${wants_dir[*]} " =~ " ${prev} " ]]; then - _filedir -d - elif [[ "${cur}" == -* ]]; then - COMPREPLY=($(compgen -W "${flags[*]} ${wants_dir[*]} ${wants_file[*]}" -- "${cur}")) - else - COMPREPLY=($(compgen -W "${commands[*]}" -- "${cur}")) - fi -} - -_docker_machine() { - COMPREPLY=() - local commands=(active config create env inspect ip kill ls provision regenerate-certs restart rm ssh scp start status stop upgrade url version help) - - local flags=(--debug --native-ssh --github-api-token --bugsnag-api-token --help --version) - local wants_dir=(--storage-path) - local wants_file=(--tls-ca-cert --tls-ca-key --tls-client-cert --tls-client-key) - - # Add the use subcommand, if we have an alias loaded - if [[ ${DOCKER_MACHINE_WRAPPED} = true ]]; then - commands=("${commands[@]}" use) - fi - - local cur prev words cword - _get_comp_words_by_ref -n : cur prev words cword - local i - local command=docker-machine - - for (( i=1; i < ${cword}; ++i)); do - local word=${words[i]} - if [[ " ${wants_file[*]} ${wants_dir[*]} " =~ " ${word} " ]]; then - # skip the next option - (( ++i )) - elif [[ " ${commands[*]} " =~ " ${word} " ]]; then - command=${word} - fi - done - - local completion_func=_docker_machine_"${command//-/_}" - if declare -F "${completion_func}" > /dev/null; then - ${completion_func} - fi - - return 0 -} - -complete -F _docker_machine docker-machine docker-machine.exe diff --git a/vendor/github.com/docker/machine/contrib/completion/zsh/_docker-machine b/vendor/github.com/docker/machine/contrib/completion/zsh/_docker-machine deleted file mode 100644 index 7c19ba8..0000000 --- a/vendor/github.com/docker/machine/contrib/completion/zsh/_docker-machine +++ /dev/null @@ -1,359 +0,0 @@ -#compdef docker-machine -# Description -# ----------- -# zsh completion for docker-machine -# https://github.com/leonhartX/docker-machine-zsh-completion -# ------------------------------------------------------------------------- -# Version -# ------- -# 0.1.1 -# ------------------------------------------------------------------------- -# Authors -# ------- -# * Ke Xu -# ------------------------------------------------------------------------- -# Inspiration -# ----------- -# * @sdurrheimer docker-compose-zsh-completion https://github.com/sdurrheimer/docker-compose-zsh-completion -# * @ilkka _docker-machine - - -__docker-machine_get_hosts() { - [[ $PREFIX = -* ]] && return 1 - local state - declare -a hosts - state=$1; shift - if [[ $state != all ]]; then - hosts=(${(f)"$(_call_program commands docker-machine ls -q --filter state=$state)"}) - else - hosts=(${(f)"$(_call_program commands docker-machine ls -q)"}) - fi - _describe 'host' hosts "$@" && ret=0 - return ret -} - -__docker-machine_hosts_with_state() { - declare -a hosts - hosts=(${(f)"$(_call_program commands docker-machine ls -f '{{.Name}}\:{{.DriverName}}\({{.State}}\)\ {{.URL}}')"}) - _describe 'host' hosts -} - -__docker-machine_hosts_all() { - __docker-machine_get_hosts all "$@" -} - -__docker-machine_hosts_running() { - __docker-machine_get_hosts Running "$@" -} - -__docker-machine_get_swarm() { - declare -a swarms - swarms=(${(f)"$(_call_program commands docker-machine ls -f {{.Swarm}} | awk '{print $1}')"}) - _describe 'swarm' swarms -} - -__docker-machine_hosts_and_files() { - _alternative "hosts:host:__docker-machine_hosts_all -qS ':'" 'files:files:_path_files' -} - -__docker-machine_filters() { - [[ $PREFIX = -* ]] && return 1 - integer ret=1 - - if compset -P '*='; then - case "${${words[-1]%=*}#*=}" in - (driver) - _describe -t driver-filter-opts "driver filter" opts_driver && ret=0 - ;; - (swarm) - __docker-machine_get_swarm && ret=0 - ;; - (state) - opts_state=('Running' 'Paused' 'Saved' 'Stopped' 'Stopping' 'Starting' 'Error') - _describe -t state-filter-opts "state filter" opts_state && ret=0 - ;; - (name) - __docker-machine_hosts_all && ret=0 - ;; - (label) - _message 'label' && ret=0 - ;; - *) - _message 'value' && ret=0 - ;; - esac - else - opts=('driver' 'swarm' 'state' 'name' 'label') - _describe -t filter-opts "filter" opts -qS "=" && ret=0 - fi - return ret -} - -__get_swarm_discovery() { - declare -a masters serivces - local service - services=() - masters=($(docker-machine ls -f {{.Swarm}} |grep '(master)' |awk '{print $1}')) - for master in $masters; do - service=${${${(f)"$(_call_program commands docker-machine inspect -f '{{.HostOptions.SwarmOptions.Discovery}}:{{.Name}}' $master)"}/:/\\:}} - services=($services $service) - done - _describe -t services "swarm service" services && ret=0 - return ret -} - -__get_create_argument() { - typeset -g docker_machine_driver - if [[ CURRENT -le 2 ]]; then - docker_machine_driver="none" - elif [[ CURRENT > 2 && $words[CURRENT-2] = '-d' || $words[CURRENT-2] = '--driver' ]]; then - docker_machine_driver=$words[CURRENT-1] - elif [[ $words[CURRENT-1] =~ '^(-d|--driver)=' ]]; then - docker_machine_driver=${${words[CURRENT-1]}/*=/} - fi - local driver_opt_cmd - local -a opts_provider opts_common opts_read_argument - opts_read_argument=( - ": :->argument" - ) - opts_common=( - $opts_help \ - '(--driver -d)'{--driver=,-d=}'[Driver to create machine with]:dirver:->driver-option' \ - '--engine-install-url=[Custom URL to use for engine installation]:url' \ - '*--engine-opt=[Specify arbitrary flags to include with the created engine in the form flag=value]:flag' \ - '*--engine-insecure-registry=[Specify insecure registries to allow with the created engine]:registry' \ - '*--engine-registry-mirror=[Specify registry mirrors to use]:mirror' \ - '*--engine-label=[Specify labels for the created engine]:label' \ - '--engine-storage-driver=[Specify a storage driver to use with the engine]:storage-driver:->storage-driver-option' \ - '*--engine-env=[Specify environment variables to set in the engine]:environment' \ - '--swarm[Configure Machine with Swarm]' \ - '--swarm-image=[Specify Docker image to use for Swarm]:image' \ - '--swarm-master[Configure Machine to be a Swarm master]' \ - '--swarm-discovery=[Discovery service to use with Swarm]:service:->swarm-service' \ - '--swarm-strategy=[Define a default scheduling strategy for Swarm]:strategy:(spread binpack random)' \ - '*--swarm-opt=[Define arbitrary flags for swarm]:flag' \ - '*--swarm-join-opt=[Define arbitrary flags for Swarm join]:flag' \ - '--swarm-host=[ip/socket to listen on for Swarm master]:host' \ - '--swarm-addr=[addr to advertise for Swarm (default: detect and use the machine IP)]:address' \ - '--swarm-experimental[Enable Swarm experimental features]' \ - '*--tls-san=[Support extra SANs for TLS certs]:option' - ) - driver_opt_cmd="docker-machine create -d $docker_machine_driver | grep $docker_machine_driver | sed -e 's/\(--.*\)\ *\[\1[^]]*\]/*\1/g' -e 's/\(\[[^]]*\)/\\\\\\1\\\\/g' -e 's/\".*\"\(.*\)/\1/g' | awk '{printf \"%s[\", \$1; for(i=2;i<=NF;i++) {printf \"%s \", \$i}; print \"]\"}'" - if [[ $docker_machine_driver != "none" ]]; then - opts_provider=(${(f)"$(_call_program commands $driver_opt_cmd)"}) - _arguments \ - $opts_provider \ - $opts_read_argument \ - $opts_common && ret=0 - else - _arguments $opts_common && ret=0 - fi - case $state in - (driver-option) - _describe -t driver-option "driver" opts_driver && ret=0 - ;; - (storage-driver-option) - _describe -t storage-driver-option "storage driver" opts_storage_driver && ret=0 - ;; - (swarm-service) - __get_swarm_discovery && ret=0 - ;; - (argument) - ret=0 - ;; - esac - return ret -} - - -__docker-machine_subcommand() { - local -a opts_help - opts_help=("(- :)--help[Print usage]") - local -a opts_only_host opts_driver opts_storage_driver opts_stragery - opts_only_host=( - "$opts_help" - "*:host:__docker-machine_hosts_all" - ) - opts_driver=('amazonec2' 'azure' 'digitalocean' 'exoscale' 'generic' 'google' 'hyperv' 'none' 'openstack' 'rackspace' 'softlayer' 'virtualbox' 'vmwarefusion' 'vmwarevcloudair' 'vmwarevsphere') - opts_storage_driver=('overlay' 'aufs' 'btrfs' 'devicemapper' 'vfs' 'zfs') - integer ret=1 - - case "$words[1]" in - (active) - _arguments \ - $opts_help \ - '(--timeout -t)'{--timeout=,-t=}'[Timeout in seconds, default to 10s]:seconds' && ret=0 - ;; - (config) - _arguments \ - $opts_help \ - '--swarm[Display the Swarm config instead of the Docker daemon]' \ - "*:host:__docker-machine_hosts_all" && ret=0 - ;; - (create) - __get_create_argument - ;; - (env) - _arguments \ - $opts_help \ - '--swarm[Display the Swarm config instead of the Docker daemon]' \ - '--shell=[Force environment to be configured for a specified shell: \[fish, cmd, powershell\], default is auto-detect]:shell' \ - '(--unset -u)'{--unset,-u}'[Unset variables instead of setting them]' \ - '--no-proxy[Add machine IP to NO_PROXY environment variable]' \ - '*:host:__docker-machine_hosts_running' && ret=0 - ;; - (help) - _arguments ':subcommand:__docker-machine_commands' && ret=0 - ;; - (inspect) - _arguments \ - $opts_help \ - '(--format -f)'{--format=,-f=}'[Format the output using the given go template]:template' \ - '*:host:__docker-machine_hosts_all' && ret=0 - ;; - (ip) - _arguments \ - $opts_help \ - '*:host:__docker-machine_hosts_running' && ret=0 - ;; - (kill) - _arguments \ - $opts_help \ - '*:host:__docker-machine_hosts_with_state' && ret=0 - ;; - (ls) - _arguments \ - $opts_help \ - '(--quiet -q)'{--quiet,-q}'[Enable quiet mode]' \ - '*--filter=[Filter output based on conditions provided]:filter:->filter-options' \ - '(--timeout -t)'{--timeout=,-t=}'[Timeout in seconds, default to 10s]:seconds' \ - '(--format -f)'{--format=,-f=}'[Pretty-print machines using a Go template]:template' && ret=0 - case $state in - (filter-options) - __docker-machine_filters && ret=0 - ;; - esac - ;; - (provision) - _arguments $opts_only_host && ret=0 - ;; - (regenerate-certs) - _arguments \ - $opts_help \ - '(--force -f)'{--force,-f}'[Force rebuild and do not prompt]' \ - '*:host:__docker-machine_hosts_all' && ret=0 - ;; - (restart) - _arguments \ - $opts_help \ - '*:host:__docker-machine_hosts_with_state' && ret=0 - ;; - (rm) - _arguments \ - $opts_help \ - '(--force -f)'{--force,-f}'[Remove local configuration even if machine cannot be removed, also implies an automatic yes (`-y`)]' \ - '-y[Assumes automatic yes to proceed with remove, without prompting further user confirmation]' \ - '*:host:__docker-machine_hosts_with_state' && ret=0 - ;; - (scp) - _arguments \ - $opts_help \ - '(--recursive -r)'{--recursive,-r}'[Copy files recursively (required to copy directories))]' \ - '*:files:__docker-machine_hosts_and_files' && ret=0 - ;; - (ssh) - _arguments \ - $opts_help \ - '*:host:__docker-machine_hosts_running' && ret=0 - ;; - (start) - _arguments \ - $opts_help \ - '*:host:__docker-machine_hosts_with_state' && ret=0 - ;; - (status) - _arguments $opts_only_host && ret=0 - ;; - (stop) - _arguments \ - $opts_help \ - '*:host:__docker-machine_hosts_with_state' && ret=0 - ;; - (upgrade) - _arguments $opts_only_host && ret=0 - ;; - (url) - _arguments \ - $opts_help \ - '*:host:__docker-machine_hosts_running' && ret=0 - ;; - esac - - return ret -} - - -__docker-machine_commands() { - local cache_policy - - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy __docker-machine_caching_policy - fi - - if ( [[ ${+_docker_machine_subcommands} -eq 0 ]] || _cache_invalid docker_machine_subcommands) \ - && ! _retrieve_cache docker_machine_subcommands; - then - local -a lines - lines=(${(f)"$(_call_program commands docker-machine 2>&1)"}) - _docker_machine_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/$'\t'##/:}) - (( $#_docker_machine_subcommands > 0 )) && _store_cache docker_machine_subcommands _docker_machine_subcommands - fi - _describe -t docker-machine-commands "docker-machine command" _docker_machine_subcommands -} - -__docker-machine_caching_policy() { - oldp=( "$1"(Nmh+1) ) - (( $#oldp )) -} - -_docker-machine() { - if [[ $service != docker-machine ]]; then - _call_function - _$service - return - fi - - local curcontext="$curcontext" state line - integer ret=1 - typeset -A opt_args - - _arguments -C \ - "(- :)"{-h,--help}"[Show help]" \ - "(-D --debug)"{-D,--debug}"[Enable debug mode]" \ - '(-s --stroage-path)'{-s,--storage-path}'[Configures storage path]:file:_files' \ - '--tls-ca-cert[CA to verify remotes against]:file:_files' \ - '--tls-ca-key[Private key to generate certificates]:file:_files' \ - '--tls-client-cert[Client cert to use for TLS]:file:_files' \ - '--tls-client-key[Private key used in client TLS auth]:file:_files' \ - '--github-api-token[Token to use for requests to the Github API]' \ - '--native-ssh[Use the native (Go-based) SSH implementation.]' \ - '--bugsnag-api-token[BugSnag API token for crash reporting]' \ - '(- :)'{-v,--version}'[Print the version]' \ - "(-): :->command" \ - "(-)*:: :->option-or-argument" && ret=0 - - case $state in - (command) - __docker-machine_commands && ret=0 - ;; - (option-or-argument) - curcontext=${curcontext%:*:*}:docker-machine-$words[1]: - __docker-machine_subcommand && ret=0 - ret=0 - ;; - esac - - return ret -} - -_docker-machine "$@" diff --git a/vendor/github.com/docker/machine/doc.go b/vendor/github.com/docker/machine/doc.go deleted file mode 100644 index 6ae3312..0000000 --- a/vendor/github.com/docker/machine/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -// Package machine defines interfaces to manage a variety of docker instances -// deployed on different backends (VMs, baremetal). -// The goal is to allow users get from zero to docker as fast as possible. -package machine diff --git a/vendor/github.com/docker/machine/docs/README.md b/vendor/github.com/docker/machine/docs/README.md deleted file mode 100644 index f743e5b..0000000 --- a/vendor/github.com/docker/machine/docs/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# The docs have been moved! - -The documentation for Docker Machine has been merged into -[the general documentation repo](https://github.com/docker/docker.github.io). - -The docs for Docker Machine are now here: -https://github.com/docker/docker.github.io/tree/master/machine - -Please submit pull requests for unpublished features on the `vnext-machine` branch (https://github.com/docker/docker.github.io/tree/vnext-machine). - -If you submit a PR to this codebase that has a docs impact, create a second docs PR on `docker.github.io`. Use the docs PR template provided (coming soon - watch this space). - -PRs for typos, additional information, etc. for already-published features should be labeled as `okay-to-publish` (we are still settling on a naming convention, will provide a label soon). You can submit these PRs either to `vnext-machine` or directly to `master` on `docker.github.io` - -As always, the docs in the general repo remain open-source and we appreciate -your feedback and pull requests! diff --git a/vendor/github.com/docker/machine/drivers/amazonec2/amazonec2.go b/vendor/github.com/docker/machine/drivers/amazonec2/amazonec2.go deleted file mode 100644 index f313043..0000000 --- a/vendor/github.com/docker/machine/drivers/amazonec2/amazonec2.go +++ /dev/null @@ -1,1204 +0,0 @@ -package amazonec2 - -import ( - "crypto/md5" - "crypto/rand" - "encoding/base64" - "errors" - "fmt" - "io" - "io/ioutil" - "net" - "net/url" - "strconv" - "strings" - "time" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/docker/machine/drivers/driverutil" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" -) - -const ( - driverName = "amazonec2" - ipRange = "0.0.0.0/0" - machineSecurityGroupName = "docker-machine" - defaultAmiId = "ami-c60b90d1" - defaultRegion = "us-east-1" - defaultInstanceType = "t2.micro" - defaultDeviceName = "/dev/sda1" - defaultRootSize = 16 - defaultVolumeType = "gp2" - defaultZone = "a" - defaultSecurityGroup = machineSecurityGroupName - defaultSSHUser = "ubuntu" - defaultSpotPrice = "0.50" - defaultBlockDurationMinutes = 0 -) - -const ( - keypairNotFoundCode = "InvalidKeyPair.NotFound" -) - -var ( - dockerPort = 2376 - swarmPort = 3376 - errorNoPrivateSSHKey = errors.New("using --amazonec2-keypair-name also requires --amazonec2-ssh-keypath") - errorMissingCredentials = errors.New("amazonec2 driver requires AWS credentials configured with the --amazonec2-access-key and --amazonec2-secret-key options, environment variables, ~/.aws/credentials, or an instance role") - errorNoVPCIdFound = errors.New("amazonec2 driver requires either the --amazonec2-subnet-id or --amazonec2-vpc-id option or an AWS Account with a default vpc-id") - errorNoSubnetsFound = errors.New("The desired subnet could not be located in this region. Is '--amazonec2-subnet-id' or AWS_SUBNET_ID configured correctly?") - errorDisableSSLWithoutCustomEndpoint = errors.New("using --amazonec2-insecure-transport also requires --amazonec2-endpoint") - errorReadingUserData = errors.New("unable to read --amazonec2-userdata file") -) - -type Driver struct { - *drivers.BaseDriver - clientFactory func() Ec2Client - awsCredentialsFactory func() awsCredentials - Id string - AccessKey string - SecretKey string - SessionToken string - Region string - AMI string - SSHKeyID int - // ExistingKey keeps track of whether the key was created by us or we used an existing one. If an existing one was used, we shouldn't delete it when the machine is deleted. - ExistingKey bool - KeyName string - InstanceId string - InstanceType string - PrivateIPAddress string - - // NB: SecurityGroupId expanded from single value to slice on 26 Feb 2016 - we maintain both for host storage backwards compatibility. - SecurityGroupId string - SecurityGroupIds []string - - // NB: SecurityGroupName expanded from single value to slice on 26 Feb 2016 - we maintain both for host storage backwards compatibility. - SecurityGroupName string - SecurityGroupNames []string - - OpenPorts []string - Tags string - ReservationId string - DeviceName string - RootSize int64 - VolumeType string - IamInstanceProfile string - VpcId string - SubnetId string - Zone string - keyPath string - RequestSpotInstance bool - SpotPrice string - BlockDurationMinutes int64 - PrivateIPOnly bool - UsePrivateIP bool - UseEbsOptimizedInstance bool - Monitoring bool - SSHPrivateKeyPath string - RetryCount int - Endpoint string - DisableSSL bool - UserDataFile string -} - -type clientFactory interface { - build(d *Driver) Ec2Client -} - -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - Name: "amazonec2-access-key", - Usage: "AWS Access Key", - EnvVar: "AWS_ACCESS_KEY_ID", - }, - mcnflag.StringFlag{ - Name: "amazonec2-secret-key", - Usage: "AWS Secret Key", - EnvVar: "AWS_SECRET_ACCESS_KEY", - }, - mcnflag.StringFlag{ - Name: "amazonec2-session-token", - Usage: "AWS Session Token", - EnvVar: "AWS_SESSION_TOKEN", - }, - mcnflag.StringFlag{ - Name: "amazonec2-ami", - Usage: "AWS machine image", - EnvVar: "AWS_AMI", - }, - mcnflag.StringFlag{ - Name: "amazonec2-region", - Usage: "AWS region", - Value: defaultRegion, - EnvVar: "AWS_DEFAULT_REGION", - }, - mcnflag.StringFlag{ - Name: "amazonec2-vpc-id", - Usage: "AWS VPC id", - EnvVar: "AWS_VPC_ID", - }, - mcnflag.StringFlag{ - Name: "amazonec2-zone", - Usage: "AWS zone for instance (i.e. a,b,c,d,e)", - Value: defaultZone, - EnvVar: "AWS_ZONE", - }, - mcnflag.StringFlag{ - Name: "amazonec2-subnet-id", - Usage: "AWS VPC subnet id", - EnvVar: "AWS_SUBNET_ID", - }, - mcnflag.StringSliceFlag{ - Name: "amazonec2-security-group", - Usage: "AWS VPC security group", - Value: []string{defaultSecurityGroup}, - EnvVar: "AWS_SECURITY_GROUP", - }, - mcnflag.StringSliceFlag{ - Name: "amazonec2-open-port", - Usage: "Make the specified port number accessible from the Internet", - }, - mcnflag.StringFlag{ - Name: "amazonec2-tags", - Usage: "AWS Tags (e.g. key1,value1,key2,value2)", - EnvVar: "AWS_TAGS", - }, - mcnflag.StringFlag{ - Name: "amazonec2-instance-type", - Usage: "AWS instance type", - Value: defaultInstanceType, - EnvVar: "AWS_INSTANCE_TYPE", - }, - mcnflag.StringFlag{ - Name: "amazonec2-device-name", - Usage: "AWS root device name", - Value: defaultDeviceName, - EnvVar: "AWS_DEVICE_NAME", - }, - mcnflag.IntFlag{ - Name: "amazonec2-root-size", - Usage: "AWS root disk size (in GB)", - Value: defaultRootSize, - EnvVar: "AWS_ROOT_SIZE", - }, - mcnflag.StringFlag{ - Name: "amazonec2-volume-type", - Usage: "Amazon EBS volume type", - Value: defaultVolumeType, - EnvVar: "AWS_VOLUME_TYPE", - }, - mcnflag.StringFlag{ - Name: "amazonec2-iam-instance-profile", - Usage: "AWS IAM Instance Profile", - EnvVar: "AWS_INSTANCE_PROFILE", - }, - mcnflag.StringFlag{ - Name: "amazonec2-ssh-user", - Usage: "Set the name of the ssh user", - Value: defaultSSHUser, - EnvVar: "AWS_SSH_USER", - }, - mcnflag.BoolFlag{ - Name: "amazonec2-request-spot-instance", - Usage: "Set this flag to request spot instance", - }, - mcnflag.StringFlag{ - Name: "amazonec2-spot-price", - Usage: "AWS spot instance bid price (in dollar)", - Value: defaultSpotPrice, - }, - mcnflag.IntFlag{ - Name: "amazonec2-block-duration-minutes", - Usage: "AWS spot instance duration in minutes (60, 120, 180, 240, 300, or 360)", - Value: defaultBlockDurationMinutes, - }, - mcnflag.BoolFlag{ - Name: "amazonec2-private-address-only", - Usage: "Only use a private IP address", - }, - mcnflag.BoolFlag{ - Name: "amazonec2-use-private-address", - Usage: "Force the usage of private IP address", - }, - mcnflag.BoolFlag{ - Name: "amazonec2-monitoring", - Usage: "Set this flag to enable CloudWatch monitoring", - }, - mcnflag.BoolFlag{ - Name: "amazonec2-use-ebs-optimized-instance", - Usage: "Create an EBS optimized instance", - }, - mcnflag.StringFlag{ - Name: "amazonec2-ssh-keypath", - Usage: "SSH Key for Instance", - EnvVar: "AWS_SSH_KEYPATH", - }, - mcnflag.StringFlag{ - Name: "amazonec2-keypair-name", - Usage: "AWS keypair to use; requires --amazonec2-ssh-keypath", - EnvVar: "AWS_KEYPAIR_NAME", - }, - mcnflag.IntFlag{ - Name: "amazonec2-retries", - Usage: "Set retry count for recoverable failures (use -1 to disable)", - Value: 5, - }, - mcnflag.StringFlag{ - Name: "amazonec2-endpoint", - Usage: "Optional endpoint URL (hostname only or fully qualified URI)", - Value: "", - EnvVar: "AWS_ENDPOINT", - }, - mcnflag.BoolFlag{ - Name: "amazonec2-insecure-transport", - Usage: "Disable SSL when sending requests", - EnvVar: "AWS_INSECURE_TRANSPORT", - }, - mcnflag.StringFlag{ - Name: "amazonec2-userdata", - Usage: "path to file with cloud-init user data", - EnvVar: "AWS_USERDATA", - }, - } -} - -func NewDriver(hostName, storePath string) *Driver { - id := generateId() - driver := &Driver{ - Id: id, - AMI: defaultAmiId, - Region: defaultRegion, - InstanceType: defaultInstanceType, - RootSize: defaultRootSize, - Zone: defaultZone, - SecurityGroupNames: []string{defaultSecurityGroup}, - SpotPrice: defaultSpotPrice, - BlockDurationMinutes: defaultBlockDurationMinutes, - BaseDriver: &drivers.BaseDriver{ - SSHUser: defaultSSHUser, - MachineName: hostName, - StorePath: storePath, - }, - } - - driver.clientFactory = driver.buildClient - driver.awsCredentialsFactory = driver.buildCredentials - - return driver -} - -func (d *Driver) buildClient() Ec2Client { - config := aws.NewConfig() - alogger := AwsLogger() - config = config.WithRegion(d.Region) - config = config.WithCredentials(d.awsCredentialsFactory().Credentials()) - config = config.WithLogger(alogger) - config = config.WithLogLevel(aws.LogDebugWithHTTPBody) - config = config.WithMaxRetries(d.RetryCount) - if d.Endpoint != "" { - config = config.WithEndpoint(d.Endpoint) - config = config.WithDisableSSL(d.DisableSSL) - } - return ec2.New(session.New(config)) -} - -func (d *Driver) buildCredentials() awsCredentials { - return NewAWSCredentials(d.AccessKey, d.SecretKey, d.SessionToken) -} - -func (d *Driver) getClient() Ec2Client { - return d.clientFactory() -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.Endpoint = flags.String("amazonec2-endpoint") - - region, err := validateAwsRegion(flags.String("amazonec2-region")) - if err != nil && d.Endpoint == "" { - return err - } - - image := flags.String("amazonec2-ami") - if len(image) == 0 { - image = regionDetails[region].AmiId - } - - d.AccessKey = flags.String("amazonec2-access-key") - d.SecretKey = flags.String("amazonec2-secret-key") - d.SessionToken = flags.String("amazonec2-session-token") - d.Region = region - d.AMI = image - d.RequestSpotInstance = flags.Bool("amazonec2-request-spot-instance") - d.SpotPrice = flags.String("amazonec2-spot-price") - d.BlockDurationMinutes = int64(flags.Int("amazonec2-block-duration-minutes")) - d.InstanceType = flags.String("amazonec2-instance-type") - d.VpcId = flags.String("amazonec2-vpc-id") - d.SubnetId = flags.String("amazonec2-subnet-id") - d.SecurityGroupNames = flags.StringSlice("amazonec2-security-group") - d.Tags = flags.String("amazonec2-tags") - zone := flags.String("amazonec2-zone") - d.Zone = zone[:] - d.DeviceName = flags.String("amazonec2-device-name") - d.RootSize = int64(flags.Int("amazonec2-root-size")) - d.VolumeType = flags.String("amazonec2-volume-type") - d.IamInstanceProfile = flags.String("amazonec2-iam-instance-profile") - d.SSHUser = flags.String("amazonec2-ssh-user") - d.SSHPort = 22 - d.PrivateIPOnly = flags.Bool("amazonec2-private-address-only") - d.UsePrivateIP = flags.Bool("amazonec2-use-private-address") - d.Monitoring = flags.Bool("amazonec2-monitoring") - d.UseEbsOptimizedInstance = flags.Bool("amazonec2-use-ebs-optimized-instance") - d.SSHPrivateKeyPath = flags.String("amazonec2-ssh-keypath") - d.KeyName = flags.String("amazonec2-keypair-name") - d.ExistingKey = flags.String("amazonec2-keypair-name") != "" - d.SetSwarmConfigFromFlags(flags) - d.RetryCount = flags.Int("amazonec2-retries") - d.OpenPorts = flags.StringSlice("amazonec2-open-port") - d.UserDataFile = flags.String("amazonec2-userdata") - - d.DisableSSL = flags.Bool("amazonec2-insecure-transport") - - if d.DisableSSL && d.Endpoint == "" { - return errorDisableSSLWithoutCustomEndpoint - } - - if d.KeyName != "" && d.SSHPrivateKeyPath == "" { - return errorNoPrivateSSHKey - } - - _, err = d.awsCredentialsFactory().Credentials().Get() - if err != nil { - return errorMissingCredentials - } - - if d.VpcId == "" { - d.VpcId, err = d.getDefaultVPCId() - if err != nil { - log.Warnf("Couldn't determine your account Default VPC ID : %q", err) - } - } - - if d.SubnetId == "" && d.VpcId == "" { - return errorNoVPCIdFound - } - - if d.SubnetId != "" && d.VpcId != "" { - subnetFilter := []*ec2.Filter{ - { - Name: aws.String("subnet-id"), - Values: []*string{&d.SubnetId}, - }, - } - - subnets, err := d.getClient().DescribeSubnets(&ec2.DescribeSubnetsInput{ - Filters: subnetFilter, - }) - if err != nil { - return err - } - - if subnets == nil || len(subnets.Subnets) == 0 { - return errorNoSubnetsFound - } - - if *subnets.Subnets[0].VpcId != d.VpcId { - return fmt.Errorf("SubnetId: %s does not belong to VpcId: %s", d.SubnetId, d.VpcId) - } - } - - if d.isSwarmMaster() { - u, err := url.Parse(d.SwarmHost) - if err != nil { - return fmt.Errorf("error parsing swarm host: %s", err) - } - - parts := strings.Split(u.Host, ":") - port, err := strconv.Atoi(parts[1]) - if err != nil { - return err - } - - swarmPort = port - } - - return nil -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return driverName -} - -func (d *Driver) checkPrereqs() error { - // check for existing keypair - keyName := d.KeyName - keyShouldExist := true - if keyName == "" { - keyName = d.MachineName - keyShouldExist = false - } - - key, err := d.getClient().DescribeKeyPairs(&ec2.DescribeKeyPairsInput{ - KeyNames: []*string{&keyName}, - }) - if err != nil { - if awsErr, ok := err.(awserr.Error); ok { - if awsErr.Code() == keypairNotFoundCode && keyShouldExist { - return fmt.Errorf("There is no keypair with the name %s. Please verify the key name provided.", keyName) - } - if awsErr.Code() == keypairNotFoundCode && !keyShouldExist { - // Not a real error for 'NotFound' since we're checking existence - } - } else { - return err - } - } - - // In case we got a result with an empty set of keys - if err == nil && len(key.KeyPairs) != 0 { - if !keyShouldExist { - return fmt.Errorf("There is already a keypair with the name %s. Please either remove that keypair or use a different machine name.", d.MachineName) - } - // otherwise we found the key: success - } - - regionZone := d.getRegionZone() - if d.SubnetId == "" { - filters := []*ec2.Filter{ - { - Name: aws.String("availability-zone"), - Values: []*string{®ionZone}, - }, - { - Name: aws.String("vpc-id"), - Values: []*string{&d.VpcId}, - }, - } - - subnets, err := d.getClient().DescribeSubnets(&ec2.DescribeSubnetsInput{ - Filters: filters, - }) - if err != nil { - return err - } - - if len(subnets.Subnets) == 0 { - return fmt.Errorf("unable to find a subnet in the zone: %s", regionZone) - } - - d.SubnetId = *subnets.Subnets[0].SubnetId - - // try to find default - if len(subnets.Subnets) > 1 { - for _, subnet := range subnets.Subnets { - if subnet.DefaultForAz != nil && *subnet.DefaultForAz { - d.SubnetId = *subnet.SubnetId - break - } - } - } - } - - return nil -} - -func (d *Driver) PreCreateCheck() error { - return d.checkPrereqs() -} - -func (d *Driver) instanceIpAvailable() bool { - ip, err := d.GetIP() - if err != nil { - log.Debug(err) - } - if ip != "" { - d.IPAddress = ip - log.Debugf("Got the IP Address, it's %q", d.IPAddress) - return true - } - return false -} - -func makePointerSlice(stackSlice []string) []*string { - pointerSlice := []*string{} - for i := range stackSlice { - pointerSlice = append(pointerSlice, &stackSlice[i]) - } - return pointerSlice -} - -// Support migrating single string Driver fields to slices. -func migrateStringToSlice(value string, values []string) (result []string) { - if value != "" { - result = append(result, value) - } - result = append(result, values...) - return -} - -func (d *Driver) securityGroupNames() (ids []string) { - return migrateStringToSlice(d.SecurityGroupName, d.SecurityGroupNames) -} - -func (d *Driver) securityGroupIds() (ids []string) { - return migrateStringToSlice(d.SecurityGroupId, d.SecurityGroupIds) -} - -func (d *Driver) Base64UserData() (userdata string, err error) { - if d.UserDataFile != "" { - buf, ioerr := ioutil.ReadFile(d.UserDataFile) - if ioerr != nil { - log.Warnf("failed to read user data file %q: %s", d.UserDataFile, ioerr) - err = errorReadingUserData - return - } - userdata = base64.StdEncoding.EncodeToString(buf) - } - return -} - -func (d *Driver) Create() error { - if err := d.checkPrereqs(); err != nil { - return err - } - - log.Infof("Launching instance...") - - if err := d.createKeyPair(); err != nil { - return fmt.Errorf("unable to create key pair: %s", err) - } - - if err := d.configureSecurityGroups(d.securityGroupNames()); err != nil { - return err - } - - var userdata string - if b64, err := d.Base64UserData(); err != nil { - return err - } else { - userdata = b64 - } - - bdm := &ec2.BlockDeviceMapping{ - DeviceName: aws.String(d.DeviceName), - Ebs: &ec2.EbsBlockDevice{ - VolumeSize: aws.Int64(d.RootSize), - VolumeType: aws.String(d.VolumeType), - DeleteOnTermination: aws.Bool(true), - }, - } - netSpecs := []*ec2.InstanceNetworkInterfaceSpecification{{ - DeviceIndex: aws.Int64(0), // eth0 - Groups: makePointerSlice(d.securityGroupIds()), - SubnetId: &d.SubnetId, - AssociatePublicIpAddress: aws.Bool(!d.PrivateIPOnly), - }} - - regionZone := d.getRegionZone() - log.Debugf("launching instance in subnet %s", d.SubnetId) - - var instance *ec2.Instance - - if d.RequestSpotInstance { - req := ec2.RequestSpotInstancesInput{ - LaunchSpecification: &ec2.RequestSpotLaunchSpecification{ - ImageId: &d.AMI, - Placement: &ec2.SpotPlacement{ - AvailabilityZone: ®ionZone, - }, - KeyName: &d.KeyName, - InstanceType: &d.InstanceType, - NetworkInterfaces: netSpecs, - Monitoring: &ec2.RunInstancesMonitoringEnabled{Enabled: aws.Bool(d.Monitoring)}, - IamInstanceProfile: &ec2.IamInstanceProfileSpecification{ - Name: &d.IamInstanceProfile, - }, - EbsOptimized: &d.UseEbsOptimizedInstance, - BlockDeviceMappings: []*ec2.BlockDeviceMapping{bdm}, - UserData: &userdata, - }, - InstanceCount: aws.Int64(1), - SpotPrice: &d.SpotPrice, - } - if d.BlockDurationMinutes != 0 { - req.BlockDurationMinutes = &d.BlockDurationMinutes - } - - spotInstanceRequest, err := d.getClient().RequestSpotInstances(&req) - if err != nil { - return fmt.Errorf("Error request spot instance: %s", err) - } - - log.Info("Waiting for spot instance...") - err = d.getClient().WaitUntilSpotInstanceRequestFulfilled(&ec2.DescribeSpotInstanceRequestsInput{ - SpotInstanceRequestIds: []*string{spotInstanceRequest.SpotInstanceRequests[0].SpotInstanceRequestId}, - }) - if err != nil { - return fmt.Errorf("Error fulfilling spot request: %v", err) - } - log.Info("Created spot instance request %v", *spotInstanceRequest.SpotInstanceRequests[0].SpotInstanceRequestId) - // resolve instance id - for i := 0; i < 3; i++ { - // Even though the waiter succeeded, eventual consistency means we could - // get a describe output that does not include this information. Try a - // few times just in case - var resolvedSpotInstance *ec2.DescribeSpotInstanceRequestsOutput - resolvedSpotInstance, err = d.getClient().DescribeSpotInstanceRequests(&ec2.DescribeSpotInstanceRequestsInput{ - SpotInstanceRequestIds: []*string{spotInstanceRequest.SpotInstanceRequests[0].SpotInstanceRequestId}, - }) - if err != nil { - // Unexpected; no need to retry - return fmt.Errorf("Error describing previously made spot instance request: %v", err) - } - maybeInstanceId := resolvedSpotInstance.SpotInstanceRequests[0].InstanceId - if maybeInstanceId != nil { - var instances *ec2.DescribeInstancesOutput - instances, err = d.getClient().DescribeInstances(&ec2.DescribeInstancesInput{ - InstanceIds: []*string{maybeInstanceId}, - }) - if err != nil { - // Retry if we get an id from spot instance but EC2 doesn't recognize it yet; see above, eventual consistency possible - continue - } - instance = instances.Reservations[0].Instances[0] - err = nil - break - } - time.Sleep(5 * time.Second) - } - - if err != nil { - return fmt.Errorf("Error resolving spot instance to real instance: %v", err) - } - } else { - inst, err := d.getClient().RunInstances(&ec2.RunInstancesInput{ - ImageId: &d.AMI, - MinCount: aws.Int64(1), - MaxCount: aws.Int64(1), - Placement: &ec2.Placement{ - AvailabilityZone: ®ionZone, - }, - KeyName: &d.KeyName, - InstanceType: &d.InstanceType, - NetworkInterfaces: netSpecs, - Monitoring: &ec2.RunInstancesMonitoringEnabled{Enabled: aws.Bool(d.Monitoring)}, - IamInstanceProfile: &ec2.IamInstanceProfileSpecification{ - Name: &d.IamInstanceProfile, - }, - EbsOptimized: &d.UseEbsOptimizedInstance, - BlockDeviceMappings: []*ec2.BlockDeviceMapping{bdm}, - UserData: &userdata, - }) - - if err != nil { - return fmt.Errorf("Error launching instance: %s", err) - } - instance = inst.Instances[0] - } - - d.InstanceId = *instance.InstanceId - - log.Debug("waiting for ip address to become available") - if err := mcnutils.WaitFor(d.instanceIpAvailable); err != nil { - return err - } - - if instance.PrivateIpAddress != nil { - d.PrivateIPAddress = *instance.PrivateIpAddress - } - - d.waitForInstance() - - log.Debugf("created instance ID %s, IP address %s, Private IP address %s", - d.InstanceId, - d.IPAddress, - d.PrivateIPAddress, - ) - - log.Debug("Settings tags for instance") - err := d.configureTags(d.Tags) - - if err != nil { - return fmt.Errorf("Unable to tag instance %s: %s", d.InstanceId, err) - } - - return nil -} - -func (d *Driver) GetURL() (string, error) { - if err := drivers.MustBeRunning(d); err != nil { - return "", err - } - - ip, err := d.GetIP() - if err != nil { - return "", err - } - if ip == "" { - return "", nil - } - - return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, strconv.Itoa(dockerPort))), nil -} - -func (d *Driver) GetIP() (string, error) { - inst, err := d.getInstance() - if err != nil { - return "", err - } - - if d.PrivateIPOnly { - if inst.PrivateIpAddress == nil { - return "", fmt.Errorf("No private IP for instance %v", *inst.InstanceId) - } - return *inst.PrivateIpAddress, nil - } - - if d.UsePrivateIP { - if inst.PrivateIpAddress == nil { - return "", fmt.Errorf("No private IP for instance %v", *inst.InstanceId) - } - return *inst.PrivateIpAddress, nil - } - - if inst.PublicIpAddress == nil { - return "", fmt.Errorf("No IP for instance %v", *inst.InstanceId) - } - return *inst.PublicIpAddress, nil -} - -func (d *Driver) GetState() (state.State, error) { - inst, err := d.getInstance() - if err != nil { - return state.Error, err - } - switch *inst.State.Name { - case ec2.InstanceStateNamePending: - return state.Starting, nil - case ec2.InstanceStateNameRunning: - return state.Running, nil - case ec2.InstanceStateNameStopping: - return state.Stopping, nil - case ec2.InstanceStateNameShuttingDown: - return state.Stopping, nil - case ec2.InstanceStateNameStopped: - return state.Stopped, nil - case ec2.InstanceStateNameTerminated: - return state.Error, nil - default: - log.Warnf("unrecognized instance state: %v", *inst.State.Name) - return state.Error, nil - } -} - -func (d *Driver) GetSSHHostname() (string, error) { - // TODO: use @nathanleclaire retry func here (ehazlett) - return d.GetIP() -} - -func (d *Driver) GetSSHUsername() string { - if d.SSHUser == "" { - d.SSHUser = defaultSSHUser - } - - return d.SSHUser -} - -func (d *Driver) Start() error { - _, err := d.getClient().StartInstances(&ec2.StartInstancesInput{ - InstanceIds: []*string{&d.InstanceId}, - }) - if err != nil { - return err - } - - return d.waitForInstance() -} - -func (d *Driver) Stop() error { - _, err := d.getClient().StopInstances(&ec2.StopInstancesInput{ - InstanceIds: []*string{&d.InstanceId}, - Force: aws.Bool(false), - }) - return err -} - -func (d *Driver) Restart() error { - _, err := d.getClient().RebootInstances(&ec2.RebootInstancesInput{ - InstanceIds: []*string{&d.InstanceId}, - }) - return err -} - -func (d *Driver) Kill() error { - _, err := d.getClient().StopInstances(&ec2.StopInstancesInput{ - InstanceIds: []*string{&d.InstanceId}, - Force: aws.Bool(true), - }) - return err -} - -func (d *Driver) Remove() error { - multierr := mcnutils.MultiError{ - Errs: []error{}, - } - - if err := d.terminate(); err != nil { - multierr.Errs = append(multierr.Errs, err) - } - - if !d.ExistingKey { - if err := d.deleteKeyPair(); err != nil { - multierr.Errs = append(multierr.Errs, err) - } - } - - if len(multierr.Errs) == 0 { - return nil - } - - return multierr -} - -func (d *Driver) getInstance() (*ec2.Instance, error) { - instances, err := d.getClient().DescribeInstances(&ec2.DescribeInstancesInput{ - InstanceIds: []*string{&d.InstanceId}, - }) - if err != nil { - return nil, err - } - return instances.Reservations[0].Instances[0], nil -} - -func (d *Driver) instanceIsRunning() bool { - st, err := d.GetState() - if err != nil { - log.Debug(err) - } - if st == state.Running { - return true - } - return false -} - -func (d *Driver) waitForInstance() error { - if err := mcnutils.WaitFor(d.instanceIsRunning); err != nil { - return err - } - - return nil -} - -func (d *Driver) createKeyPair() error { - keyPath := "" - - if d.SSHPrivateKeyPath == "" { - log.Debugf("Creating New SSH Key") - if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { - return err - } - keyPath = d.GetSSHKeyPath() - } else { - log.Debugf("Using SSHPrivateKeyPath: %s", d.SSHPrivateKeyPath) - if err := mcnutils.CopyFile(d.SSHPrivateKeyPath, d.GetSSHKeyPath()); err != nil { - return err - } - if err := mcnutils.CopyFile(d.SSHPrivateKeyPath+".pub", d.GetSSHKeyPath()+".pub"); err != nil { - return err - } - if d.KeyName != "" { - log.Debugf("Using existing EC2 key pair: %s", d.KeyName) - return nil - } - keyPath = d.SSHPrivateKeyPath - } - - publicKey, err := ioutil.ReadFile(keyPath + ".pub") - if err != nil { - return err - } - - keyName := d.MachineName - - log.Debugf("creating key pair: %s", keyName) - _, err = d.getClient().ImportKeyPair(&ec2.ImportKeyPairInput{ - KeyName: &keyName, - PublicKeyMaterial: publicKey, - }) - if err != nil { - return err - } - d.KeyName = keyName - return nil -} - -func (d *Driver) terminate() error { - if d.InstanceId == "" { - return fmt.Errorf("unknown instance") - } - - log.Debugf("terminating instance: %s", d.InstanceId) - _, err := d.getClient().TerminateInstances(&ec2.TerminateInstancesInput{ - InstanceIds: []*string{&d.InstanceId}, - }) - - if err != nil { - if strings.HasPrefix(err.Error(), "unknown instance") || - strings.HasPrefix(err.Error(), "InvalidInstanceID.NotFound") { - log.Warn("Remote instance does not exist, proceeding with removing local reference") - return nil - } - - return fmt.Errorf("unable to terminate instance: %s", err) - } - return nil -} - -func (d *Driver) isSwarmMaster() bool { - return d.SwarmMaster -} - -func (d *Driver) securityGroupAvailableFunc(id string) func() bool { - return func() bool { - - securityGroup, err := d.getClient().DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{ - GroupIds: []*string{&id}, - }) - if err == nil && len(securityGroup.SecurityGroups) > 0 { - return true - } else if err == nil { - log.Debugf("No security group with id %v found", id) - return false - } - log.Debug(err) - return false - } -} - -func (d *Driver) configureTags(tagGroups string) error { - - tags := []*ec2.Tag{} - tags = append(tags, &ec2.Tag{ - Key: aws.String("Name"), - Value: &d.MachineName, - }) - - if tagGroups != "" { - t := strings.Split(tagGroups, ",") - if len(t) > 0 && len(t)%2 != 0 { - log.Warnf("Tags are not key value in pairs. %d elements found", len(t)) - } - for i := 0; i < len(t)-1; i += 2 { - tags = append(tags, &ec2.Tag{ - Key: &t[i], - Value: &t[i+1], - }) - } - } - - _, err := d.getClient().CreateTags(&ec2.CreateTagsInput{ - Resources: []*string{&d.InstanceId}, - Tags: tags, - }) - - if err != nil { - return err - } - - return nil -} - -func (d *Driver) configureSecurityGroups(groupNames []string) error { - if len(groupNames) == 0 { - log.Debugf("no security groups to configure in %s", d.VpcId) - return nil - } - - log.Debugf("configuring security groups in %s", d.VpcId) - - filters := []*ec2.Filter{ - { - Name: aws.String("group-name"), - Values: makePointerSlice(groupNames), - }, - { - Name: aws.String("vpc-id"), - Values: []*string{&d.VpcId}, - }, - } - groups, err := d.getClient().DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{ - Filters: filters, - }) - if err != nil { - return err - } - - var groupsByName = make(map[string]*ec2.SecurityGroup) - for _, securityGroup := range groups.SecurityGroups { - groupsByName[*securityGroup.GroupName] = securityGroup - } - - for _, groupName := range groupNames { - var group *ec2.SecurityGroup - securityGroup, ok := groupsByName[groupName] - if ok { - log.Debugf("found existing security group (%s) in %s", groupName, d.VpcId) - group = securityGroup - } else { - log.Debugf("creating security group (%s) in %s", groupName, d.VpcId) - groupResp, err := d.getClient().CreateSecurityGroup(&ec2.CreateSecurityGroupInput{ - GroupName: aws.String(groupName), - Description: aws.String("Docker Machine"), - VpcId: aws.String(d.VpcId), - }) - if err != nil { - return err - } - // Manually translate into the security group construct - group = &ec2.SecurityGroup{ - GroupId: groupResp.GroupId, - VpcId: aws.String(d.VpcId), - GroupName: aws.String(groupName), - } - // wait until created (dat eventual consistency) - log.Debugf("waiting for group (%s) to become available", *group.GroupId) - if err := mcnutils.WaitFor(d.securityGroupAvailableFunc(*group.GroupId)); err != nil { - return err - } - } - d.SecurityGroupIds = append(d.SecurityGroupIds, *group.GroupId) - - perms, err := d.configureSecurityGroupPermissions(group) - if err != nil { - return err - } - - if len(perms) != 0 { - log.Debugf("authorizing group %s with permissions: %v", groupNames, perms) - _, err := d.getClient().AuthorizeSecurityGroupIngress(&ec2.AuthorizeSecurityGroupIngressInput{ - GroupId: group.GroupId, - IpPermissions: perms, - }) - if err != nil { - return err - } - } - } - - return nil -} - -func (d *Driver) configureSecurityGroupPermissions(group *ec2.SecurityGroup) ([]*ec2.IpPermission, error) { - hasPorts := make(map[string]bool) - for _, p := range group.IpPermissions { - if p.FromPort != nil { - hasPorts[fmt.Sprintf("%d/%s", *p.FromPort, *p.IpProtocol)] = true - } - } - - perms := []*ec2.IpPermission{} - - if !hasPorts["22/tcp"] { - perms = append(perms, &ec2.IpPermission{ - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64(22), - ToPort: aws.Int64(22), - IpRanges: []*ec2.IpRange{{CidrIp: aws.String(ipRange)}}, - }) - } - - if !hasPorts[fmt.Sprintf("%d/tcp", dockerPort)] { - perms = append(perms, &ec2.IpPermission{ - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64(int64(dockerPort)), - ToPort: aws.Int64(int64(dockerPort)), - IpRanges: []*ec2.IpRange{{CidrIp: aws.String(ipRange)}}, - }) - } - - if !hasPorts[fmt.Sprintf("%d/tcp", swarmPort)] && d.SwarmMaster { - perms = append(perms, &ec2.IpPermission{ - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64(int64(swarmPort)), - ToPort: aws.Int64(int64(swarmPort)), - IpRanges: []*ec2.IpRange{{CidrIp: aws.String(ipRange)}}, - }) - } - - for _, p := range d.OpenPorts { - port, protocol := driverutil.SplitPortProto(p) - portNum, err := strconv.ParseInt(port, 10, 0) - if err != nil { - return nil, fmt.Errorf("invalid port number %s: %s", port, err) - } - if !hasPorts[fmt.Sprintf("%s/%s", port, protocol)] { - perms = append(perms, &ec2.IpPermission{ - IpProtocol: aws.String(protocol), - FromPort: aws.Int64(portNum), - ToPort: aws.Int64(portNum), - IpRanges: []*ec2.IpRange{{CidrIp: aws.String(ipRange)}}, - }) - } - } - - log.Debugf("configuring security group authorization for %s", ipRange) - - return perms, nil -} - -func (d *Driver) deleteKeyPair() error { - log.Debugf("deleting key pair: %s", d.KeyName) - - _, err := d.getClient().DeleteKeyPair(&ec2.DeleteKeyPairInput{ - KeyName: &d.KeyName, - }) - if err != nil { - return err - } - - return nil -} - -func (d *Driver) getDefaultVPCId() (string, error) { - output, err := d.getClient().DescribeAccountAttributes(&ec2.DescribeAccountAttributesInput{}) - if err != nil { - return "", err - } - - for _, attribute := range output.AccountAttributes { - if *attribute.AttributeName == "default-vpc" { - return *attribute.AttributeValues[0].AttributeValue, nil - } - } - - return "", errors.New("No default-vpc attribute") -} - -func (d *Driver) getRegionZone() string { - if d.Endpoint == "" { - return d.Region + d.Zone - } - return d.Zone -} - -func generateId() string { - rb := make([]byte, 10) - _, err := rand.Read(rb) - if err != nil { - log.Warnf("Unable to generate id: %s", err) - } - - h := md5.New() - io.WriteString(h, string(rb)) - return fmt.Sprintf("%x", h.Sum(nil)) -} diff --git a/vendor/github.com/docker/machine/drivers/amazonec2/amazonec2_test.go b/vendor/github.com/docker/machine/drivers/amazonec2/amazonec2_test.go deleted file mode 100644 index e464ad3..0000000 --- a/vendor/github.com/docker/machine/drivers/amazonec2/amazonec2_test.go +++ /dev/null @@ -1,526 +0,0 @@ -package amazonec2 - -import ( - "testing" - - "errors" - "reflect" - - "io/ioutil" - "os" - "path/filepath" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/docker/machine/commands/commandstest" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" -) - -const ( - testSSHPort = int64(22) - testDockerPort = int64(2376) - testSwarmPort = int64(3376) -) - -var ( - securityGroup = &ec2.SecurityGroup{ - GroupName: aws.String("test-group"), - GroupId: aws.String("12345"), - VpcId: aws.String("12345"), - } -) - -func TestConfigureSecurityGroupPermissionsEmpty(t *testing.T) { - driver := NewTestDriver() - - perms, err := driver.configureSecurityGroupPermissions(securityGroup) - - assert.Nil(t, err) - assert.Len(t, perms, 2) -} - -func TestConfigureSecurityGroupPermissionsSshOnly(t *testing.T) { - driver := NewTestDriver() - group := securityGroup - group.IpPermissions = []*ec2.IpPermission{ - { - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64(int64(testSSHPort)), - ToPort: aws.Int64(int64(testSSHPort)), - }, - } - - perms, err := driver.configureSecurityGroupPermissions(group) - - assert.Nil(t, err) - assert.Len(t, perms, 1) - assert.Equal(t, testDockerPort, *perms[0].FromPort) -} - -func TestConfigureSecurityGroupPermissionsDockerOnly(t *testing.T) { - driver := NewTestDriver() - group := securityGroup - group.IpPermissions = []*ec2.IpPermission{ - { - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64((testDockerPort)), - ToPort: aws.Int64((testDockerPort)), - }, - } - - perms, err := driver.configureSecurityGroupPermissions(group) - - assert.Nil(t, err) - assert.Len(t, perms, 1) - assert.Equal(t, testSSHPort, *perms[0].FromPort) -} - -func TestConfigureSecurityGroupPermissionsDockerAndSsh(t *testing.T) { - driver := NewTestDriver() - group := securityGroup - group.IpPermissions = []*ec2.IpPermission{ - { - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64(testSSHPort), - ToPort: aws.Int64(testSSHPort), - }, - { - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64(testDockerPort), - ToPort: aws.Int64(testDockerPort), - }, - } - - perms, err := driver.configureSecurityGroupPermissions(group) - - assert.Nil(t, err) - assert.Empty(t, perms) -} - -func TestConfigureSecurityGroupPermissionsOpenPorts(t *testing.T) { - driver := NewTestDriver() - driver.OpenPorts = []string{"8888/tcp", "8080/udp", "9090"} - perms, err := driver.configureSecurityGroupPermissions(&ec2.SecurityGroup{}) - - assert.NoError(t, err) - assert.Len(t, perms, 5) - assert.Equal(t, aws.Int64(int64(8888)), perms[2].ToPort) - assert.Equal(t, aws.String("tcp"), perms[2].IpProtocol) - assert.Equal(t, aws.Int64(int64(8080)), perms[3].ToPort) - assert.Equal(t, aws.String("udp"), perms[3].IpProtocol) - assert.Equal(t, aws.Int64(int64(9090)), perms[4].ToPort) - assert.Equal(t, aws.String("tcp"), perms[4].IpProtocol) -} - -func TestConfigureSecurityGroupPermissionsOpenPortsSkipExisting(t *testing.T) { - driver := NewTestDriver() - group := securityGroup - group.IpPermissions = []*ec2.IpPermission{ - { - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64(8888), - ToPort: aws.Int64(testSSHPort), - }, - { - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64(8080), - ToPort: aws.Int64(testSSHPort), - }, - } - driver.OpenPorts = []string{"8888/tcp", "8080/udp", "8080"} - perms, err := driver.configureSecurityGroupPermissions(group) - assert.NoError(t, err) - assert.Len(t, perms, 3) - assert.Equal(t, aws.Int64(int64(8080)), perms[2].ToPort) - assert.Equal(t, aws.String("udp"), perms[2].IpProtocol) -} - -func TestConfigureSecurityGroupPermissionsInvalidOpenPorts(t *testing.T) { - driver := NewTestDriver() - driver.OpenPorts = []string{"2222/tcp", "abc1"} - perms, err := driver.configureSecurityGroupPermissions(&ec2.SecurityGroup{}) - - assert.Error(t, err) - assert.Nil(t, perms) -} - -func TestConfigureSecurityGroupPermissionsWithSwarm(t *testing.T) { - driver := NewTestDriver() - driver.SwarmMaster = true - group := securityGroup - group.IpPermissions = []*ec2.IpPermission{ - { - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64(testSSHPort), - ToPort: aws.Int64(testSSHPort), - }, - { - IpProtocol: aws.String("tcp"), - FromPort: aws.Int64(testDockerPort), - ToPort: aws.Int64(testDockerPort), - }, - } - - perms, err := driver.configureSecurityGroupPermissions(group) - - assert.Nil(t, err) - assert.Len(t, perms, 1) - assert.Equal(t, testSwarmPort, *perms[0].FromPort) -} - -func TestValidateAwsRegionValid(t *testing.T) { - regions := []string{"eu-west-1", "eu-central-1"} - - for _, region := range regions { - validatedRegion, err := validateAwsRegion(region) - - assert.NoError(t, err) - assert.Equal(t, region, validatedRegion) - } -} - -func TestValidateAwsRegionInvalid(t *testing.T) { - regions := []string{"eu-central-2"} - - for _, region := range regions { - _, err := validateAwsRegion(region) - - assert.EqualError(t, err, "Invalid region specified") - } -} - -func TestFindDefaultVPC(t *testing.T) { - driver := NewDriver("machineFoo", "path") - driver.clientFactory = func() Ec2Client { - return &fakeEC2WithLogin{} - } - - vpc, err := driver.getDefaultVPCId() - - assert.Equal(t, "vpc-9999", vpc) - assert.NoError(t, err) -} - -func TestDefaultVPCIsMissing(t *testing.T) { - driver := NewDriver("machineFoo", "path") - driver.clientFactory = func() Ec2Client { - return &fakeEC2WithDescribe{ - output: &ec2.DescribeAccountAttributesOutput{ - AccountAttributes: []*ec2.AccountAttribute{}, - }, - } - } - - vpc, err := driver.getDefaultVPCId() - - assert.EqualError(t, err, "No default-vpc attribute") - assert.Empty(t, vpc) -} - -func TestGetRegionZoneForDefaultEndpoint(t *testing.T) { - driver := NewCustomTestDriver(&fakeEC2WithLogin{}) - driver.awsCredentialsFactory = NewValidAwsCredentials - options := &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "name": "test", - "amazonec2-region": "us-east-1", - "amazonec2-zone": "e", - }, - } - - err := driver.SetConfigFromFlags(options) - - regionZone := driver.getRegionZone() - - assert.Equal(t, "us-east-1e", regionZone) - assert.NoError(t, err) -} - -func TestGetRegionZoneForCustomEndpoint(t *testing.T) { - driver := NewCustomTestDriver(&fakeEC2WithLogin{}) - driver.awsCredentialsFactory = NewValidAwsCredentials - options := &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "name": "test", - "amazonec2-endpoint": "https://someurl", - "amazonec2-region": "custom-endpoint", - "amazonec2-zone": "custom-zone", - }, - } - - err := driver.SetConfigFromFlags(options) - - regionZone := driver.getRegionZone() - - assert.Equal(t, "custom-zone", regionZone) - assert.NoError(t, err) -} - -func TestDescribeAccountAttributeFails(t *testing.T) { - driver := NewDriver("machineFoo", "path") - driver.clientFactory = func() Ec2Client { - return &fakeEC2WithDescribe{ - err: errors.New("Not Found"), - } - } - - vpc, err := driver.getDefaultVPCId() - - assert.EqualError(t, err, "Not Found") - assert.Empty(t, vpc) -} - -func TestAwsCredentialsAreRequired(t *testing.T) { - driver := NewTestDriver() - driver.awsCredentialsFactory = NewErrorAwsCredentials - - options := &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "name": "test", - "amazonec2-region": "us-east-1", - "amazonec2-zone": "e", - }, - } - - err := driver.SetConfigFromFlags(options) - assert.Equal(t, err, errorMissingCredentials) -} - -func TestValidAwsCredentialsAreAccepted(t *testing.T) { - driver := NewCustomTestDriver(&fakeEC2WithLogin{}) - driver.awsCredentialsFactory = NewValidAwsCredentials - options := &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "name": "test", - "amazonec2-region": "us-east-1", - "amazonec2-zone": "e", - }, - } - - err := driver.SetConfigFromFlags(options) - assert.NoError(t, err) -} - -func TestEndpointIsMandatoryWhenSSLDisabled(t *testing.T) { - driver := NewTestDriver() - driver.awsCredentialsFactory = NewValidAwsCredentials - options := &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "name": "test", - "amazonec2-access-key": "foobar", - "amazonec2-region": "us-east-1", - "amazonec2-zone": "e", - "amazonec2-insecure-transport": true, - }, - } - - err := driver.SetConfigFromFlags(options) - - assert.Equal(t, err, errorDisableSSLWithoutCustomEndpoint) -} - -var values = []string{ - "bob", - "jake", - "jill", -} - -var pointerSliceTests = []struct { - input []string - expected []*string -}{ - {[]string{}, []*string{}}, - {[]string{values[1]}, []*string{&values[1]}}, - {[]string{values[0], values[2], values[2]}, []*string{&values[0], &values[2], &values[2]}}, -} - -func TestMakePointerSlice(t *testing.T) { - for _, tt := range pointerSliceTests { - actual := makePointerSlice(tt.input) - assert.Equal(t, tt.expected, actual) - } -} - -var securityGroupNameTests = []struct { - groupName string - groupNames []string - expected []string -}{ - {groupName: "bob", expected: []string{"bob"}}, - {groupNames: []string{"bill"}, expected: []string{"bill"}}, - {groupName: "bob", groupNames: []string{"bill"}, expected: []string{"bob", "bill"}}, -} - -func TestMergeSecurityGroupName(t *testing.T) { - for _, tt := range securityGroupNameTests { - d := Driver{SecurityGroupName: tt.groupName, SecurityGroupNames: tt.groupNames} - assert.Equal(t, tt.expected, d.securityGroupNames()) - } -} - -var securityGroupIdTests = []struct { - groupId string - groupIds []string - expected []string -}{ - {groupId: "id", expected: []string{"id"}}, - {groupIds: []string{"id"}, expected: []string{"id"}}, - {groupId: "id1", groupIds: []string{"id2"}, expected: []string{"id1", "id2"}}, -} - -func TestMergeSecurityGroupId(t *testing.T) { - for _, tt := range securityGroupIdTests { - d := Driver{SecurityGroupId: tt.groupId, SecurityGroupIds: tt.groupIds} - assert.Equal(t, tt.expected, d.securityGroupIds()) - } -} - -func matchGroupLookup(expected []string) interface{} { - return func(input *ec2.DescribeSecurityGroupsInput) bool { - actual := []string{} - for _, filter := range input.Filters { - if *filter.Name == "group-name" { - for _, groupName := range filter.Values { - actual = append(actual, *groupName) - } - } - } - return reflect.DeepEqual(expected, actual) - } -} - -func ipPermission(port int64) *ec2.IpPermission { - return &ec2.IpPermission{ - FromPort: aws.Int64(port), - ToPort: aws.Int64(port), - IpProtocol: aws.String("tcp"), - IpRanges: []*ec2.IpRange{{CidrIp: aws.String(ipRange)}}, - } -} - -func TestConfigureSecurityGroupsEmpty(t *testing.T) { - recorder := fakeEC2SecurityGroupTestRecorder{} - - driver := NewCustomTestDriver(&recorder) - err := driver.configureSecurityGroups([]string{}) - - assert.Nil(t, err) - recorder.AssertExpectations(t) -} - -func TestConfigureSecurityGroupsMixed(t *testing.T) { - groups := []string{"existingGroup", "newGroup"} - recorder := fakeEC2SecurityGroupTestRecorder{} - - // First, a check is made for which groups already exist. - initialLookupResult := ec2.DescribeSecurityGroupsOutput{SecurityGroups: []*ec2.SecurityGroup{ - { - GroupName: aws.String("existingGroup"), - GroupId: aws.String("existingGroupId"), - IpPermissions: []*ec2.IpPermission{ipPermission(testSSHPort)}, - }, - }} - recorder.On("DescribeSecurityGroups", mock.MatchedBy(matchGroupLookup(groups))).Return( - &initialLookupResult, nil) - - // An ingress permission is added to the existing group. - recorder.On("AuthorizeSecurityGroupIngress", &ec2.AuthorizeSecurityGroupIngressInput{ - GroupId: aws.String("existingGroupId"), - IpPermissions: []*ec2.IpPermission{ipPermission(testDockerPort)}, - }).Return( - &ec2.AuthorizeSecurityGroupIngressOutput{}, nil) - - // The new security group is created. - recorder.On("CreateSecurityGroup", &ec2.CreateSecurityGroupInput{ - GroupName: aws.String("newGroup"), - Description: aws.String("Docker Machine"), - VpcId: aws.String(""), - }).Return( - &ec2.CreateSecurityGroupOutput{GroupId: aws.String("newGroupId")}, nil) - - // Ensuring the new security group exists. - postCreateLookupResult := ec2.DescribeSecurityGroupsOutput{SecurityGroups: []*ec2.SecurityGroup{ - { - GroupName: aws.String("newGroup"), - GroupId: aws.String("newGroupId"), - }, - }} - recorder.On("DescribeSecurityGroups", - &ec2.DescribeSecurityGroupsInput{GroupIds: []*string{aws.String("newGroupId")}}).Return( - &postCreateLookupResult, nil) - - // Permissions are added to the new security group. - recorder.On("AuthorizeSecurityGroupIngress", &ec2.AuthorizeSecurityGroupIngressInput{ - GroupId: aws.String("newGroupId"), - IpPermissions: []*ec2.IpPermission{ipPermission(testSSHPort), ipPermission(testDockerPort)}, - }).Return( - &ec2.AuthorizeSecurityGroupIngressOutput{}, nil) - - driver := NewCustomTestDriver(&recorder) - err := driver.configureSecurityGroups(groups) - - assert.Nil(t, err) - recorder.AssertExpectations(t) -} - -func TestConfigureSecurityGroupsErrLookupExist(t *testing.T) { - groups := []string{"group"} - recorder := fakeEC2SecurityGroupTestRecorder{} - - lookupExistErr := errors.New("lookup failed") - recorder.On("DescribeSecurityGroups", mock.MatchedBy(matchGroupLookup(groups))).Return( - nil, lookupExistErr) - - driver := NewCustomTestDriver(&recorder) - err := driver.configureSecurityGroups(groups) - - assert.Exactly(t, lookupExistErr, err) - recorder.AssertExpectations(t) -} - -func TestBase64UserDataIsEmptyIfNoFileProvided(t *testing.T) { - driver := NewTestDriver() - - userdata, err := driver.Base64UserData() - - assert.NoError(t, err) - assert.Empty(t, userdata) -} - -func TestBase64UserDataGeneratesErrorIfFileNotFound(t *testing.T) { - dir, err := ioutil.TempDir("", "awsuserdata") - assert.NoError(t, err, "Unable to create temporary directory.") - - defer os.RemoveAll(dir) - userdata_path := filepath.Join(dir, "does-not-exist.yml") - - driver := NewTestDriver() - driver.UserDataFile = userdata_path - - _, ud_err := driver.Base64UserData() - assert.Equal(t, ud_err, errorReadingUserData) -} - -func TestBase64UserDataIsCorrectWhenFileProvided(t *testing.T) { - dir, err := ioutil.TempDir("", "awsuserdata") - assert.NoError(t, err, "Unable to create temporary directory.") - - defer os.RemoveAll(dir) - - userdata_path := filepath.Join(dir, "test-userdata.yml") - - content := []byte("#cloud-config\nhostname: userdata-test\nfqdn: userdata-test.amazonec2.driver\n") - contentBase64 := "I2Nsb3VkLWNvbmZpZwpob3N0bmFtZTogdXNlcmRhdGEtdGVzdApmcWRuOiB1c2VyZGF0YS10ZXN0LmFtYXpvbmVjMi5kcml2ZXIK" - - err = ioutil.WriteFile(userdata_path, content, 0666) - assert.NoError(t, err, "Unable to create temporary userdata file.") - - driver := NewTestDriver() - driver.UserDataFile = userdata_path - - userdata, ud_err := driver.Base64UserData() - - assert.NoError(t, ud_err) - assert.Equal(t, contentBase64, userdata) -} diff --git a/vendor/github.com/docker/machine/drivers/amazonec2/awscredentials.go b/vendor/github.com/docker/machine/drivers/amazonec2/awscredentials.go deleted file mode 100644 index ef04c6c..0000000 --- a/vendor/github.com/docker/machine/drivers/amazonec2/awscredentials.go +++ /dev/null @@ -1,63 +0,0 @@ -package amazonec2 - -import ( - "github.com/aws/aws-sdk-go/aws/credentials" - "github.com/aws/aws-sdk-go/aws/session" -) - -type awsCredentials interface { - Credentials() *credentials.Credentials -} - -type ProviderFactory interface { - NewStaticProvider(id, secret, token string) credentials.Provider -} - -type defaultAWSCredentials struct { - AccessKey string - SecretKey string - SessionToken string - providerFactory ProviderFactory - fallbackProvider awsCredentials -} - -func NewAWSCredentials(id, secret, token string) *defaultAWSCredentials { - creds := defaultAWSCredentials{ - AccessKey: id, - SecretKey: secret, - SessionToken: token, - fallbackProvider: &AwsDefaultCredentialsProvider{}, - providerFactory: &defaultProviderFactory{}, - } - return &creds -} - -func (c *defaultAWSCredentials) Credentials() *credentials.Credentials { - providers := []credentials.Provider{} - if c.AccessKey != "" && c.SecretKey != "" { - providers = append(providers, c.providerFactory.NewStaticProvider(c.AccessKey, c.SecretKey, c.SessionToken)) - } - if c.fallbackProvider != nil { - fallbackCreds, err := c.fallbackProvider.Credentials().Get() - if err == nil { - providers = append(providers, &credentials.StaticProvider{Value: fallbackCreds}) - } - } - return credentials.NewChainCredentials(providers) -} - -type AwsDefaultCredentialsProvider struct{} - -func (c *AwsDefaultCredentialsProvider) Credentials() *credentials.Credentials { - return session.New().Config.Credentials -} - -type defaultProviderFactory struct{} - -func (c *defaultProviderFactory) NewStaticProvider(id, secret, token string) credentials.Provider { - return &credentials.StaticProvider{Value: credentials.Value{ - AccessKeyID: id, - SecretAccessKey: secret, - SessionToken: token, - }} -} diff --git a/vendor/github.com/docker/machine/drivers/amazonec2/awscredentials_test.go b/vendor/github.com/docker/machine/drivers/amazonec2/awscredentials_test.go deleted file mode 100644 index 7a64e46..0000000 --- a/vendor/github.com/docker/machine/drivers/amazonec2/awscredentials_test.go +++ /dev/null @@ -1,100 +0,0 @@ -package amazonec2 - -import ( - "github.com/stretchr/testify/assert" - "testing" -) - -func TestAccessKeyIsMandatoryWhenSystemCredentialsAreNotPresent(t *testing.T) { - awsCreds := NewAWSCredentials("", "", "") - awsCreds.fallbackProvider = nil - - _, err := awsCreds.Credentials().Get() - assert.Error(t, err) -} - -func TestAccessKeyIsMandatoryEvenIfSecretKeyIsPassedWhenSystemCredentialsAreNotPresent(t *testing.T) { - awsCreds := NewAWSCredentials("", "secret", "") - awsCreds.fallbackProvider = nil - - _, err := awsCreds.Credentials().Get() - assert.Error(t, err) -} - -func TestSecretKeyIsMandatoryWhenSystemCredentialsAreNotPresent(t *testing.T) { - awsCreds := NewAWSCredentials("access", "", "") - awsCreds.fallbackProvider = nil - - _, err := awsCreds.Credentials().Get() - assert.Error(t, err) -} - -func TestFallbackCredentialsAreLoadedWhenAccessKeyAndSecretKeyAreMissing(t *testing.T) { - awsCreds := NewAWSCredentials("", "", "") - awsCreds.fallbackProvider = &fallbackCredentials{} - - creds, err := awsCreds.Credentials().Get() - - assert.NoError(t, err) - assert.Equal(t, "fallback_access", creds.AccessKeyID) - assert.Equal(t, "fallback_secret", creds.SecretAccessKey) - assert.Equal(t, "fallback_token", creds.SessionToken) -} - -func TestFallbackCredentialsAreLoadedWhenAccessKeyIsMissing(t *testing.T) { - awsCreds := NewAWSCredentials("", "secret", "") - awsCreds.fallbackProvider = &fallbackCredentials{} - - creds, err := awsCreds.Credentials().Get() - - assert.NoError(t, err) - assert.Equal(t, "fallback_access", creds.AccessKeyID) - assert.Equal(t, "fallback_secret", creds.SecretAccessKey) - assert.Equal(t, "fallback_token", creds.SessionToken) -} - -func TestFallbackCredentialsAreLoadedWhenSecretKeyIsMissing(t *testing.T) { - awsCreds := NewAWSCredentials("access", "", "") - awsCreds.fallbackProvider = &fallbackCredentials{} - - creds, err := awsCreds.Credentials().Get() - - assert.NoError(t, err) - assert.Equal(t, "fallback_access", creds.AccessKeyID) - assert.Equal(t, "fallback_secret", creds.SecretAccessKey) - assert.Equal(t, "fallback_token", creds.SessionToken) -} - -func TestOptionCredentialsAreLoadedWhenAccessKeyAndSecretKeyAreProvided(t *testing.T) { - awsCreds := NewAWSCredentials("access", "secret", "") - awsCreds.fallbackProvider = &fallbackCredentials{} - - creds, err := awsCreds.Credentials().Get() - - assert.NoError(t, err) - assert.Equal(t, "access", creds.AccessKeyID) - assert.Equal(t, "secret", creds.SecretAccessKey) - assert.Equal(t, "", creds.SessionToken) -} - -func TestFallbackCredentialsAreLoadedIfStaticCredentialsGenerateError(t *testing.T) { - awsCreds := NewAWSCredentials("access", "secret", "token") - awsCreds.fallbackProvider = &fallbackCredentials{} - awsCreds.providerFactory = &errorCredentialsProvider{} - - creds, err := awsCreds.Credentials().Get() - - assert.NoError(t, err) - assert.Equal(t, "fallback_access", creds.AccessKeyID) - assert.Equal(t, "fallback_secret", creds.SecretAccessKey) - assert.Equal(t, "fallback_token", creds.SessionToken) -} - -func TestErrorGeneratedWhenAllProvidersGenerateErrors(t *testing.T) { - awsCreds := NewAWSCredentials("access", "secret", "token") - awsCreds.fallbackProvider = &errorFallbackCredentials{} - awsCreds.providerFactory = &errorCredentialsProvider{} - - _, err := awsCreds.Credentials().Get() - assert.Error(t, err) -} diff --git a/vendor/github.com/docker/machine/drivers/amazonec2/ec2client.go b/vendor/github.com/docker/machine/drivers/amazonec2/ec2client.go deleted file mode 100644 index ecb2a50..0000000 --- a/vendor/github.com/docker/machine/drivers/amazonec2/ec2client.go +++ /dev/null @@ -1,51 +0,0 @@ -package amazonec2 - -import "github.com/aws/aws-sdk-go/service/ec2" - -type Ec2Client interface { - DescribeAccountAttributes(input *ec2.DescribeAccountAttributesInput) (*ec2.DescribeAccountAttributesOutput, error) - - DescribeSubnets(input *ec2.DescribeSubnetsInput) (*ec2.DescribeSubnetsOutput, error) - - CreateTags(input *ec2.CreateTagsInput) (*ec2.CreateTagsOutput, error) - - //SecurityGroup - - CreateSecurityGroup(input *ec2.CreateSecurityGroupInput) (*ec2.CreateSecurityGroupOutput, error) - - AuthorizeSecurityGroupIngress(input *ec2.AuthorizeSecurityGroupIngressInput) (*ec2.AuthorizeSecurityGroupIngressOutput, error) - - DescribeSecurityGroups(input *ec2.DescribeSecurityGroupsInput) (*ec2.DescribeSecurityGroupsOutput, error) - - DeleteSecurityGroup(input *ec2.DeleteSecurityGroupInput) (*ec2.DeleteSecurityGroupOutput, error) - - //KeyPair - - DeleteKeyPair(input *ec2.DeleteKeyPairInput) (*ec2.DeleteKeyPairOutput, error) - - ImportKeyPair(input *ec2.ImportKeyPairInput) (*ec2.ImportKeyPairOutput, error) - - DescribeKeyPairs(input *ec2.DescribeKeyPairsInput) (*ec2.DescribeKeyPairsOutput, error) - - //Instances - - DescribeInstances(input *ec2.DescribeInstancesInput) (*ec2.DescribeInstancesOutput, error) - - StartInstances(input *ec2.StartInstancesInput) (*ec2.StartInstancesOutput, error) - - RebootInstances(input *ec2.RebootInstancesInput) (*ec2.RebootInstancesOutput, error) - - StopInstances(input *ec2.StopInstancesInput) (*ec2.StopInstancesOutput, error) - - RunInstances(input *ec2.RunInstancesInput) (*ec2.Reservation, error) - - TerminateInstances(input *ec2.TerminateInstancesInput) (*ec2.TerminateInstancesOutput, error) - - //SpotInstances - - RequestSpotInstances(input *ec2.RequestSpotInstancesInput) (*ec2.RequestSpotInstancesOutput, error) - - DescribeSpotInstanceRequests(input *ec2.DescribeSpotInstanceRequestsInput) (*ec2.DescribeSpotInstanceRequestsOutput, error) - - WaitUntilSpotInstanceRequestFulfilled(input *ec2.DescribeSpotInstanceRequestsInput) error -} diff --git a/vendor/github.com/docker/machine/drivers/amazonec2/logger.go b/vendor/github.com/docker/machine/drivers/amazonec2/logger.go deleted file mode 100644 index a0dd929..0000000 --- a/vendor/github.com/docker/machine/drivers/amazonec2/logger.go +++ /dev/null @@ -1,21 +0,0 @@ -package amazonec2 - -import ( - "github.com/aws/aws-sdk-go/aws" - "log" - "os" -) - -type awslogger struct { - logger *log.Logger -} - -func AwsLogger() aws.Logger { - return &awslogger{ - logger: log.New(os.Stderr, "", log.LstdFlags), - } -} - -func (l awslogger) Log(args ...interface{}) { - l.logger.Println(args...) -} diff --git a/vendor/github.com/docker/machine/drivers/amazonec2/region.go b/vendor/github.com/docker/machine/drivers/amazonec2/region.go deleted file mode 100644 index 177e7d0..0000000 --- a/vendor/github.com/docker/machine/drivers/amazonec2/region.go +++ /dev/null @@ -1,51 +0,0 @@ -package amazonec2 - -import ( - "errors" -) - -type region struct { - AmiId string -} - -// Ubuntu 16.04 LTS 20170619.1 hvm:ebs-ssd (amd64) -// See https://cloud-images.ubuntu.com/locator/ec2/ -var regionDetails map[string]*region = map[string]*region{ - "ap-northeast-1": {"ami-785c491f"}, - "ap-northeast-2": {"ami-94d20dfa"}, - "ap-southeast-1": {"ami-2378f540"}, - "ap-southeast-2": {"ami-e94e5e8a"}, - "ap-south-1": {"ami-49e59a26"}, - "ca-central-1": {"ami-7ed56a1a"}, - "cn-north-1": {"ami-a163b4cc"}, // Note: this is 20170303 - "eu-central-1": {"ami-1c45e273"}, - "eu-west-1": {"ami-6d48500b"}, - "eu-west-2": {"ami-cc7066a8"}, - "sa-east-1": {"ami-34afc458"}, - "us-east-1": {"ami-d15a75c7"}, - "us-east-2": {"ami-8b92b4ee"}, - "us-west-1": {"ami-73f7da13"}, - "us-west-2": {"ami-835b4efa"}, - "us-gov-west-1": {"ami-939412f2"}, - "custom-endpoint": {""}, -} - -func awsRegionsList() []string { - var list []string - - for k := range regionDetails { - list = append(list, k) - } - - return list -} - -func validateAwsRegion(region string) (string, error) { - for _, v := range awsRegionsList() { - if v == region { - return region, nil - } - } - - return "", errors.New("Invalid region specified") -} diff --git a/vendor/github.com/docker/machine/drivers/amazonec2/stub_test.go b/vendor/github.com/docker/machine/drivers/amazonec2/stub_test.go deleted file mode 100644 index 6dd6386..0000000 --- a/vendor/github.com/docker/machine/drivers/amazonec2/stub_test.go +++ /dev/null @@ -1,149 +0,0 @@ -package amazonec2 - -import ( - "errors" - - "github.com/aws/aws-sdk-go/aws/credentials" - "github.com/aws/aws-sdk-go/service/ec2" - - "github.com/stretchr/testify/mock" -) - -type fakeEC2 struct { - *ec2.EC2 -} - -type errorProvider struct{} - -func (p *errorProvider) Retrieve() (credentials.Value, error) { - return credentials.Value{}, errors.New("bad credentials") -} - -func (p *errorProvider) IsExpired() bool { - return true -} - -type okProvider struct { - accessKeyID string - secretAccessKey string - sessionToken string -} - -func (p *okProvider) Retrieve() (credentials.Value, error) { - return credentials.Value{ - AccessKeyID: p.accessKeyID, - SecretAccessKey: p.secretAccessKey, - SessionToken: p.sessionToken, - }, nil -} - -func (p *okProvider) IsExpired() bool { - return true -} - -type fallbackCredentials struct{} - -func (c *fallbackCredentials) Credentials() *credentials.Credentials { - return credentials.NewStaticCredentials("fallback_access", "fallback_secret", "fallback_token") -} - -func NewValidAwsCredentials() awsCredentials { - return &fallbackCredentials{} -} - -type errorFallbackCredentials struct{} - -func (c *errorFallbackCredentials) Credentials() *credentials.Credentials { - return credentials.NewCredentials(&errorProvider{}) -} - -func NewErrorAwsCredentials() awsCredentials { - return &errorFallbackCredentials{} -} - -type errorCredentialsProvider struct{} - -func (c *errorCredentialsProvider) NewStaticProvider(id, secret, token string) credentials.Provider { - return &errorProvider{} -} - -type fakeEC2WithDescribe struct { - *fakeEC2 - output *ec2.DescribeAccountAttributesOutput - err error -} - -func (f *fakeEC2WithDescribe) DescribeAccountAttributes(input *ec2.DescribeAccountAttributesInput) (*ec2.DescribeAccountAttributesOutput, error) { - return f.output, f.err -} - -type fakeEC2WithLogin struct { - *fakeEC2 -} - -func (f *fakeEC2WithLogin) DescribeAccountAttributes(input *ec2.DescribeAccountAttributesInput) (*ec2.DescribeAccountAttributesOutput, error) { - defaultVpc := "default-vpc" - vpcName := "vpc-9999" - - return &ec2.DescribeAccountAttributesOutput{ - AccountAttributes: []*ec2.AccountAttribute{ - { - AttributeName: &defaultVpc, - AttributeValues: []*ec2.AccountAttributeValue{ - {AttributeValue: &vpcName}, - }, - }, - }, - }, nil -} - -type fakeEC2SecurityGroupTestRecorder struct { - *fakeEC2 - mock.Mock -} - -func (f *fakeEC2SecurityGroupTestRecorder) DescribeSecurityGroups(input *ec2.DescribeSecurityGroupsInput) (*ec2.DescribeSecurityGroupsOutput, error) { - result := f.Called(input) - err := result.Error(1) - value, ok := result.Get(0).(*ec2.DescribeSecurityGroupsOutput) - if !ok && err == nil { - return nil, errors.New("Type assertion to DescribeSecurityGroupsOutput failed") - } - return value, err -} - -func (f *fakeEC2SecurityGroupTestRecorder) CreateSecurityGroup(input *ec2.CreateSecurityGroupInput) (*ec2.CreateSecurityGroupOutput, error) { - result := f.Called(input) - err := result.Error(1) - value, ok := result.Get(0).(*ec2.CreateSecurityGroupOutput) - if !ok && err == nil { - return nil, errors.New("Type assertion to CreateSecurityGroupOutput failed") - } - return value, err -} - -func (f *fakeEC2SecurityGroupTestRecorder) AuthorizeSecurityGroupIngress(input *ec2.AuthorizeSecurityGroupIngressInput) (*ec2.AuthorizeSecurityGroupIngressOutput, error) { - result := f.Called(input) - err := result.Error(1) - value, ok := result.Get(0).(*ec2.AuthorizeSecurityGroupIngressOutput) - if !ok && err == nil { - return nil, errors.New("Type assertion to AuthorizeSecurityGroupIngressInput failed") - } - return value, err -} - -func NewTestDriver() *Driver { - driver := NewDriver("machineFoo", "path") - driver.clientFactory = func() Ec2Client { - return &fakeEC2{} - } - return driver -} - -func NewCustomTestDriver(ec2Client Ec2Client) *Driver { - driver := NewDriver("machineFoo", "path") - driver.clientFactory = func() Ec2Client { - return ec2Client - } - return driver -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azure.go b/vendor/github.com/docker/machine/drivers/azure/azure.go deleted file mode 100644 index f37a8fc..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azure.go +++ /dev/null @@ -1,566 +0,0 @@ -package azure - -import ( - "encoding/base64" - "errors" - "fmt" - "io/ioutil" - "net" - "net/url" - "os" - - "github.com/docker/machine/drivers/azure/azureutil" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/state" - - "github.com/Azure/azure-sdk-for-go/arm/storage" -) - -const ( - defaultAzureEnvironment = "AzurePublicCloud" - defaultAzureResourceGroup = "docker-machine" - defaultAzureSize = "Standard_A2" - defaultAzureLocation = "westus" - defaultSSHUser = "docker-user" // 'root' not allowed on Azure - defaultDockerPort = 2376 - defaultAzureImage = "canonical:UbuntuServer:16.04.0-LTS:latest" - defaultAzureVNet = "docker-machine-vnet" - defaultAzureSubnet = "docker-machine" - defaultAzureSubnetPrefix = "192.168.0.0/16" - defaultStorageType = string(storage.StandardLRS) - defaultAzureAvailabilitySet = "docker-machine" -) - -const ( - flAzureEnvironment = "azure-environment" - flAzureSubscriptionID = "azure-subscription-id" - flAzureResourceGroup = "azure-resource-group" - flAzureSSHUser = "azure-ssh-user" - flAzureDockerPort = "azure-docker-port" - flAzureLocation = "azure-location" - flAzureSize = "azure-size" - flAzureImage = "azure-image" - flAzureVNet = "azure-vnet" - flAzureSubnet = "azure-subnet" - flAzureSubnetPrefix = "azure-subnet-prefix" - flAzureAvailabilitySet = "azure-availability-set" - flAzurePorts = "azure-open-port" - flAzurePrivateIPAddr = "azure-private-ip-address" - flAzureUsePrivateIP = "azure-use-private-ip" - flAzureStaticPublicIP = "azure-static-public-ip" - flAzureNoPublicIP = "azure-no-public-ip" - flAzureDNSLabel = "azure-dns" - flAzureStorageType = "azure-storage-type" - flAzureCustomData = "azure-custom-data" - flAzureClientID = "azure-client-id" - flAzureClientSecret = "azure-client-secret" -) - -const ( - driverName = "azure" - sshPort = 22 -) - -// Driver represents Azure Docker Machine Driver. -type Driver struct { - *drivers.BaseDriver - - ClientID string // service principal account name - ClientSecret string // service principal account password - - Environment string - SubscriptionID string - ResourceGroup string - - DockerPort int - Location string - Size string - Image string - VirtualNetwork string - SubnetName string - SubnetPrefix string - AvailabilitySet string - StorageType string - - OpenPorts []string - PrivateIPAddr string - UsePrivateIP bool - NoPublicIP bool - DNSLabel string - StaticPublicIP bool - CustomDataFile string - - // Ephemeral fields - ctx *azureutil.DeploymentContext - resolvedIP string // cache -} - -// NewDriver returns a new driver instance. -func NewDriver(hostName, storePath string) drivers.Driver { - // NOTE(ahmetalpbalkan): any driver initialization I do here gets lost - // afterwards, especially for non-Create RPC calls. Therefore I am mostly - // making rest of the driver stateless by just relying on the following - // piece of info. - d := &Driver{ - BaseDriver: &drivers.BaseDriver{ - SSHUser: defaultSSHUser, - MachineName: hostName, - StorePath: storePath, - }, - } - return d -} - -// GetCreateFlags returns list of create flags driver accepts. -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - Name: flAzureEnvironment, - Usage: "Azure environment (e.g. AzurePublicCloud, AzureChinaCloud)", - EnvVar: "AZURE_ENVIRONMENT", - Value: defaultAzureEnvironment, - }, - mcnflag.StringFlag{ - Name: flAzureSubscriptionID, - Usage: "Azure Subscription ID", - EnvVar: "AZURE_SUBSCRIPTION_ID", - }, - mcnflag.StringFlag{ - Name: flAzureResourceGroup, - Usage: "Azure Resource Group name (will be created if missing)", - EnvVar: "AZURE_RESOURCE_GROUP", - Value: defaultAzureResourceGroup, - }, - mcnflag.StringFlag{ - Name: flAzureSSHUser, - Usage: "Username for SSH login", - EnvVar: "AZURE_SSH_USER", - Value: defaultSSHUser, - }, - mcnflag.IntFlag{ - Name: flAzureDockerPort, - Usage: "Port number for Docker engine", - EnvVar: "AZURE_DOCKER_PORT", - Value: defaultDockerPort, - }, - mcnflag.StringFlag{ - Name: flAzureLocation, - Usage: "Azure region to create the virtual machine", - EnvVar: "AZURE_LOCATION", - Value: defaultAzureLocation, - }, - mcnflag.StringFlag{ - Name: flAzureSize, - Usage: "Size for Azure Virtual Machine", - EnvVar: "AZURE_SIZE", - Value: defaultAzureSize, - }, - mcnflag.StringFlag{ - Name: flAzureImage, - Usage: "Azure virtual machine OS image", - EnvVar: "AZURE_IMAGE", - Value: defaultAzureImage, - }, - mcnflag.StringFlag{ - Name: flAzureVNet, - Usage: "Azure Virtual Network name to connect the virtual machine (in [resourcegroup:]name format)", - EnvVar: "AZURE_VNET", - Value: defaultAzureVNet, - }, - mcnflag.StringFlag{ - Name: flAzureSubnet, - Usage: "Azure Subnet Name to be used within the Virtual Network", - EnvVar: "AZURE_SUBNET", - Value: defaultAzureSubnet, - }, - mcnflag.StringFlag{ - Name: flAzureSubnetPrefix, - Usage: "Private CIDR block to be used for the new subnet, should comply RFC 1918", - EnvVar: "AZURE_SUBNET_PREFIX", - Value: defaultAzureSubnetPrefix, - }, - mcnflag.StringFlag{ - Name: flAzureAvailabilitySet, - Usage: "Azure Availability Set to place the virtual machine into", - EnvVar: "AZURE_AVAILABILITY_SET", - Value: defaultAzureAvailabilitySet, - }, - mcnflag.StringFlag{ - Name: flAzureCustomData, - EnvVar: "AZURE_CUSTOM_DATA_FILE", - Usage: "Path to file with custom-data", - }, - mcnflag.StringFlag{ - Name: flAzurePrivateIPAddr, - Usage: "Specify a static private IP address for the machine", - }, - mcnflag.StringFlag{ - Name: flAzureStorageType, - Usage: "Type of Storage Account to host the OS Disk for the machine", - EnvVar: "AZURE_STORAGE_TYPE", - Value: defaultStorageType, - }, - mcnflag.BoolFlag{ - Name: flAzureUsePrivateIP, - Usage: "Use private IP address of the machine to connect", - }, - mcnflag.BoolFlag{ - Name: flAzureNoPublicIP, - Usage: "Do not create a public IP address for the machine", - }, - mcnflag.BoolFlag{ - Name: flAzureStaticPublicIP, - Usage: "Assign a static public IP address to the machine", - }, - mcnflag.StringFlag{ - Name: flAzureDNSLabel, - Usage: "A unique DNS label for the public IP adddress", - EnvVar: "AZURE_DNS_LABEL", - }, - mcnflag.StringSliceFlag{ - Name: flAzurePorts, - Usage: "Make the specified port number accessible from the Internet", - }, - mcnflag.StringFlag{ - Name: flAzureClientID, - Usage: "Azure Service Principal Account ID (optional, browser auth is used if not specified)", - EnvVar: "AZURE_CLIENT_ID", - }, - mcnflag.StringFlag{ - Name: flAzureClientSecret, - Usage: "Azure Service Principal Account password (optional, browser auth is used if not specified)", - EnvVar: "AZURE_CLIENT_SECRET", - }, - } -} - -// SetConfigFromFlags initializes driver values from the command line values -// and checks if the arguments have values. -func (d *Driver) SetConfigFromFlags(fl drivers.DriverOptions) error { - // Initialize driver context for machine - d.ctx = &azureutil.DeploymentContext{} - - // Required string flags - flags := []struct { - target *string - flag string - }{ - {&d.BaseDriver.SSHUser, flAzureSSHUser}, - {&d.SubscriptionID, flAzureSubscriptionID}, - {&d.ResourceGroup, flAzureResourceGroup}, - {&d.Location, flAzureLocation}, - {&d.Size, flAzureSize}, - {&d.Image, flAzureImage}, - {&d.VirtualNetwork, flAzureVNet}, - {&d.SubnetName, flAzureSubnet}, - {&d.SubnetPrefix, flAzureSubnetPrefix}, - {&d.AvailabilitySet, flAzureAvailabilitySet}, - {&d.StorageType, flAzureStorageType}, - } - for _, f := range flags { - *f.target = fl.String(f.flag) - if *f.target == "" { - return requiredOptionError(f.flag) - } - } - - // Optional flags or Flags of other types - d.Environment = fl.String(flAzureEnvironment) - d.OpenPorts = fl.StringSlice(flAzurePorts) - d.PrivateIPAddr = fl.String(flAzurePrivateIPAddr) - d.UsePrivateIP = fl.Bool(flAzureUsePrivateIP) - d.NoPublicIP = fl.Bool(flAzureNoPublicIP) - d.StaticPublicIP = fl.Bool(flAzureStaticPublicIP) - d.DockerPort = fl.Int(flAzureDockerPort) - d.DNSLabel = fl.String(flAzureDNSLabel) - d.CustomDataFile = fl.String(flAzureCustomData) - - d.ClientID = fl.String(flAzureClientID) - d.ClientSecret = fl.String(flAzureClientSecret) - - // Set flags on the BaseDriver - d.BaseDriver.SSHPort = sshPort - d.SetSwarmConfigFromFlags(fl) - - log.Debug("Set configuration from flags.") - return nil -} - -// DriverName returns the name of the driver. -func (d *Driver) DriverName() string { return driverName } - -// PreCreateCheck validates if driver values are valid to create the machine. -func (d *Driver) PreCreateCheck() (err error) { - if d.CustomDataFile != "" { - if _, err := os.Stat(d.CustomDataFile); os.IsNotExist(err) { - return fmt.Errorf("custom-data file %s could not be found", d.CustomDataFile) - } - } - - c, err := d.newAzureClient() - if err != nil { - return err - } - - // Register used resource providers with current Azure subscription. - if err := c.RegisterResourceProviders( - "Microsoft.Compute", - "Microsoft.Network", - "Microsoft.Storage"); err != nil { - return err - } - - // Validate if firewall rules can be read correctly - d.ctx.FirewallRules, err = d.getSecurityRules(d.OpenPorts) - if err != nil { - return err - } - - // Check if virtual machine exists. An existing virtual machine cannot be updated. - log.Debug("Checking if Virtual Machine already exists.") - if exists, err := c.VirtualMachineExists(d.ResourceGroup, d.naming().VM()); err != nil { - return err - } else if exists { - return fmt.Errorf("Virtual Machine with name %s already exists in resource group %q", d.naming().VM(), d.ResourceGroup) - } - - // NOTE(ahmetalpbalkan) we could have done more checks here but Azure often - // returns meaningful error messages and it would be repeating the backend - // logic on the client side. Some examples: - // - Deployment of a machine to an existing Virtual Network fails if - // virtual network is in a different region. - // - Changing IP Address space of a subnet would fail if there are machines - // running in the Virtual Network. - log.Info("Completed machine pre-create checks.") - return nil -} - -// Create creates the virtual machine. -func (d *Driver) Create() error { - // NOTE(ahmetalpbalkan): We can probably parallelize the sh*t out of this. - // However that would lead to a concurrency logic and while creation of a - // resource fails, other ones would be kicked off, which could lead to a - // resource leak. This is slower but safer. - c, err := d.newAzureClient() - if err != nil { - return err - } - - var customData string - if d.CustomDataFile != "" { - buf, err := ioutil.ReadFile(d.CustomDataFile) - if err != nil { - return err - } - customData = base64.StdEncoding.EncodeToString(buf) - } - - if err := c.CreateResourceGroup(d.ResourceGroup, d.Location); err != nil { - return err - } - if err := c.CreateAvailabilitySetIfNotExists(d.ctx, d.ResourceGroup, d.AvailabilitySet, d.Location); err != nil { - return err - } - if err := c.CreateNetworkSecurityGroup(d.ctx, d.ResourceGroup, d.naming().NSG(), d.Location, d.ctx.FirewallRules); err != nil { - return err - } - vnetResourceGroup, vNetName := parseVirtualNetwork(d.VirtualNetwork, d.ResourceGroup) - if err := c.CreateVirtualNetworkIfNotExists(vnetResourceGroup, vNetName, d.Location); err != nil { - return err - } - if err := c.CreateSubnet(d.ctx, vnetResourceGroup, vNetName, d.SubnetName, d.SubnetPrefix); err != nil { - return err - } - if d.NoPublicIP { - log.Info("Not creating a public IP address.") - } else { - if err := c.CreatePublicIPAddress(d.ctx, d.ResourceGroup, d.naming().IP(), d.Location, d.StaticPublicIP, d.DNSLabel); err != nil { - return err - } - } - if err := c.CreateNetworkInterface(d.ctx, d.ResourceGroup, d.naming().NIC(), d.Location, - d.ctx.PublicIPAddressID, d.ctx.SubnetID, d.ctx.NetworkSecurityGroupID, d.PrivateIPAddr); err != nil { - return err - } - if err := c.CreateStorageAccount(d.ctx, d.ResourceGroup, d.Location, storage.SkuName(d.StorageType)); err != nil { - return err - } - if err := d.generateSSHKey(d.ctx); err != nil { - return err - } - err = c.CreateVirtualMachine(d.ResourceGroup, d.naming().VM(), d.Location, d.Size, d.ctx.AvailabilitySetID, - d.ctx.NetworkInterfaceID, d.BaseDriver.SSHUser, d.ctx.SSHPublicKey, d.Image, customData, d.ctx.StorageAccount) - return err -} - -// Remove deletes the virtual machine and resources associated to it. -func (d *Driver) Remove() error { - if err := d.checkLegacyDriver(false); err != nil { - return err - } - - // NOTE(ahmetalpbalkan): - // - remove attempts are best effort and if a resource is already gone, we - // continue removing other resources instead of failing. - // - we can probably do a lot of parallelization here but a sequential - // logic works fine too. If we were to detach the NIC from the VM and - // then delete the VM, this could enable some parallelization. - - log.Info("NOTICE: Please check Azure portal/CLI to make sure you have no leftover resources to avoid unexpected charges.") - c, err := d.newAzureClient() - if err != nil { - return err - } - if err := c.DeleteVirtualMachineIfExists(d.ResourceGroup, d.naming().VM()); err != nil { - return err - } - if err := c.DeleteNetworkInterfaceIfExists(d.ResourceGroup, d.naming().NIC()); err != nil { - return err - } - if err := c.DeletePublicIPAddressIfExists(d.ResourceGroup, d.naming().IP()); err != nil { - return err - } - if err := c.DeleteNetworkSecurityGroupIfExists(d.ResourceGroup, d.naming().NSG()); err != nil { - return err - } - if err := c.CleanupAvailabilitySetIfExists(d.ResourceGroup, d.AvailabilitySet); err != nil { - return err - } - if err := c.CleanupSubnetIfExists(d.ResourceGroup, d.VirtualNetwork, d.SubnetName); err != nil { - return err - } - err = c.CleanupVirtualNetworkIfExists(d.ResourceGroup, d.VirtualNetwork) - return err -} - -// GetIP returns public IP address or hostname of the machine instance. -func (d *Driver) GetIP() (string, error) { - if err := d.checkLegacyDriver(true); err != nil { - return "", err - } - - if d.resolvedIP == "" { - ip, err := d.ipAddress() - if err != nil { - return "", err - } - d.resolvedIP = ip - } - log.Debugf("Machine IP address resolved to: %s", d.resolvedIP) - return d.resolvedIP, nil -} - -// GetSSHHostname returns an IP address or hostname for the machine instance. -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -// GetURL returns a socket address to connect to Docker engine of the machine -// instance. -func (d *Driver) GetURL() (string, error) { - if err := drivers.MustBeRunning(d); err != nil { - return "", err - } - - // NOTE (ahmetalpbalkan) I noticed that this is not used until machine is - // actually created and provisioned. By then GetIP() should be returning - // a non-empty IP address as the VM is already allocated and connected to. - ip, err := d.GetIP() - if err != nil { - return "", err - } - u := (&url.URL{ - Scheme: "tcp", - Host: net.JoinHostPort(ip, fmt.Sprintf("%d", d.DockerPort)), - }).String() - log.Debugf("Machine URL is resolved to: %s", u) - return u, nil -} - -// GetState returns the state of the virtual machine role instance. -func (d *Driver) GetState() (state.State, error) { - if err := d.checkLegacyDriver(true); err != nil { - return state.None, err - } - - c, err := d.newAzureClient() - if err != nil { - return state.None, err - } - powerState, err := c.GetVirtualMachinePowerState( - d.ResourceGroup, d.naming().VM()) - if err != nil { - return state.None, err - } - - machineState := machineStateForVMPowerState(powerState) - log.Debugf("Determined Azure PowerState=%q, docker-machine state=%q", - powerState, machineState) - return machineState, nil -} - -// Start issues a power on for the virtual machine instance. -func (d *Driver) Start() error { - if err := d.checkLegacyDriver(true); err != nil { - return err - } - - c, err := d.newAzureClient() - if err != nil { - return err - } - return c.StartVirtualMachine(d.ResourceGroup, d.naming().VM()) -} - -// Stop issues a power off for the virtual machine instance. -func (d *Driver) Stop() error { - if err := d.checkLegacyDriver(true); err != nil { - return err - } - - c, err := d.newAzureClient() - if err != nil { - return err - } - log.Info("NOTICE: Stopping an Azure Virtual Machine is just going to power it off, not deallocate.") - log.Info("NOTICE: You should remove the machine if you would like to avoid unexpected costs.") - return c.StopVirtualMachine(d.ResourceGroup, d.naming().VM()) -} - -// Restart reboots the virtual machine instance. -func (d *Driver) Restart() error { - if err := d.checkLegacyDriver(true); err != nil { - return err - } - - // NOTE(ahmetalpbalkan) Azure will always keep the VM in Running state - // during the restart operation. Hence we rely on returned async operation - // polling to make sure the reboot is waited upon. - c, err := d.newAzureClient() - if err != nil { - return err - } - return c.RestartVirtualMachine(d.ResourceGroup, d.naming().VM()) -} - -// Kill stops the virtual machine role instance. -func (d *Driver) Kill() error { - // NOTE(ahmetalpbalkan) In Azure, there is no kill option for virtual - // machines, Stop() is the closest option. - log.Debug("Azure does not implement kill. Calling Stop instead.") - return d.Stop() -} - -// checkLegacyDriver errors out if it encounters an Azure VM created with the -// legacy (<=0.6.0) docker-machine Azure driver. -func (d *Driver) checkLegacyDriver(short bool) error { - if d.ResourceGroup == "" { - if short { - return errors.New("new azure driver cannot manage old VMs, downgrade to v0.6.0") - } - return errors.New("new azure driver uses the new Azure Resource Manager APIs and therefore cannot manage this existing machine created with old azure driver. Please downgrade to docker-machine 0.6.0 to continue using these machines or to remove them") - } - return nil -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/auth.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/auth.go deleted file mode 100644 index 2e0abb8..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/auth.go +++ /dev/null @@ -1,246 +0,0 @@ -package azureutil - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" - "github.com/docker/machine/drivers/azure/logutil" -) - -// Azure driver allows two authentication methods: -// -// 1. OAuth Device Flow -// -// Azure Active Directory implements OAuth 2.0 Device Flow described here: -// https://tools.ietf.org/html/draft-denniss-oauth-device-flow-00. It is simple -// for users to authenticate through a browser and requires re-authenticating -// every 2 weeks. -// -// Device auth prints a message to the screen telling the user to click on URL -// and approve the app on the browser, meanwhile the client polls the auth API -// for a token. Once we have token, we save it locally to a file with proper -// permissions and when the token expires (in Azure case typically 1 hour) SDK -// will automatically refresh the specified token and will call the refresh -// callback function we implement here. This way we will always be storing a -// token with a refresh_token saved on the machine. -// -// 2. Azure Service Principal Account -// -// This is designed for headless authentication to Azure APIs but requires more -// steps from user to create a Service Principal Account and provide its -// credentials to the machine driver. - -var ( - // AD app id for docker-machine driver in various Azure realms - appIDs = map[string]string{ - azure.PublicCloud.Name: "637ddaba-219b-43b8-bf19-8cea500cf273", - azure.ChinaCloud.Name: "bb5eed6f-120b-4365-8fd9-ab1a3fba5698", - azure.GermanCloud.Name: "aabac5f7-dd47-47ef-824c-e0d57598cada", - } -) - -// AuthenticateDeviceFlow fetches a token from the local file cache or initiates a consent -// flow and waits for token to be obtained. Obtained token is stored in a file cache for -// future use and refreshing. -func AuthenticateDeviceFlow(env azure.Environment, subscriptionID string) (*azure.ServicePrincipalToken, error) { - // First we locate the tenant ID of the subscription as we store tokens per - // tenant (which could have multiple subscriptions) - tenantID, err := loadOrFindTenantID(env, subscriptionID) - if err != nil { - return nil, err - } - oauthCfg, err := env.OAuthConfigForTenant(tenantID) - if err != nil { - return nil, fmt.Errorf("Failed to obtain oauth config for azure environment: %v", err) - } - - tokenPath := tokenCachePath(tenantID) - saveToken := mkTokenCallback(tokenPath) - saveTokenCallback := func(t azure.Token) error { - log.Debug("Azure token expired. Saving the refreshed token...") - return saveToken(t) - } - f := logutil.Fields{"path": tokenPath} - - appID, ok := appIDs[env.Name] - if !ok { - return nil, fmt.Errorf("docker-machine application not set up for Azure environment %q", env.Name) - } - scope := getScope(env) - - // Lookup the token cache file for an existing token. - spt, err := tokenFromFile(*oauthCfg, tokenPath, appID, scope, saveTokenCallback) - if err != nil { - return nil, err - } - if spt != nil { - log.Debug("Auth token found in file.", f) - - // NOTE(ahmetalpbalkan): The token file we found might be containing an - // expired access_token. In that case, the first call to Azure SDK will - // attempt to refresh the token using refresh_token –which might have - // expired[1], in that case we will get an error and we shall remove the - // token file and initiate token flow again so that the user would not - // need removing the token cache file manually. - // - // [1]: for device flow auth, the expiration date of refresh_token is - // not returned in AAD /token response, we just know it is 14 - // days. Therefore user’s token will go stale every 14 days and we - // will delete the token file, re-initiate the device flow. Service - // Principal Account tokens are not subject to this limitation. - log.Debug("Validating the token.") - if err := validateToken(env, spt); err != nil { - log.Debug(fmt.Sprintf("Error: %v", err)) - log.Debug(fmt.Sprintf("Deleting %s", tokenPath)) - if err := os.RemoveAll(tokenPath); err != nil { - return nil, fmt.Errorf("Error deleting stale token file: %v", err) - } - } else { - log.Debug("Token works.") - return spt, nil - } - } - - log.Debug("Obtaining a token.", f) - spt, err = deviceFlowAuth(*oauthCfg, appID, scope) - if err != nil { - return nil, err - } - log.Debug("Obtained a token.") - if err := saveToken(spt.Token); err != nil { - log.Error("Error occurred saving token to cache file.") - return nil, err - } - return spt, nil -} - -// AuthenticateServicePrincipal uses given service principal credentials to return a -// service principal token. Generated token is not stored in a cache file or refreshed. -func AuthenticateServicePrincipal(env azure.Environment, subscriptionID, spID, spPassword string) (*azure.ServicePrincipalToken, error) { - tenantID, err := loadOrFindTenantID(env, subscriptionID) - if err != nil { - return nil, err - } - oauthCfg, err := env.OAuthConfigForTenant(tenantID) - if err != nil { - return nil, fmt.Errorf("Failed to obtain oauth config for azure environment: %v", err) - } - - spt, err := azure.NewServicePrincipalToken(*oauthCfg, spID, spPassword, getScope(env)) - if err != nil { - return nil, fmt.Errorf("Failed to create service principal token: %+v", err) - } - return spt, nil -} - -// tokenFromFile returns a token from the specified file if it is found, otherwise -// returns nil. Any error retrieving or creating the token is returned as an error. -func tokenFromFile(oauthCfg azure.OAuthConfig, tokenPath, clientID, resource string, - callback azure.TokenRefreshCallback) (*azure.ServicePrincipalToken, error) { - log.Debug("Loading auth token from file", logutil.Fields{"path": tokenPath}) - if _, err := os.Stat(tokenPath); err != nil { - if os.IsNotExist(err) { // file not found - return nil, nil - } - return nil, err - } - - token, err := azure.LoadToken(tokenPath) - if err != nil { - return nil, fmt.Errorf("Failed to load token from file: %v", err) - } - - spt, err := azure.NewServicePrincipalTokenFromManualToken(oauthCfg, clientID, resource, *token, callback) - if err != nil { - return nil, fmt.Errorf("Error constructing service principal token: %v", err) - } - return spt, nil -} - -// deviceFlowAuth prints a message to the screen for user to take action to -// consent application on a browser and in the meanwhile the authentication -// endpoint is polled until user gives consent, denies or the flow times out. -// Returned token must be saved. -func deviceFlowAuth(oauthCfg azure.OAuthConfig, clientID, resource string) (*azure.ServicePrincipalToken, error) { - cl := oauthClient() - deviceCode, err := azure.InitiateDeviceAuth(&cl, oauthCfg, clientID, resource) - if err != nil { - return nil, fmt.Errorf("Failed to start device auth: %v", err) - } - log.Debug("Retrieved device code.", logutil.Fields{ - "expires_in": to.Int64(deviceCode.ExpiresIn), - "interval": to.Int64(deviceCode.Interval), - }) - - // Example message: “To sign in, open https://aka.ms/devicelogin and enter - // the code 0000000 to authenticate.” - log.Infof("Microsoft Azure: %s", to.String(deviceCode.Message)) - - token, err := azure.WaitForUserCompletion(&cl, deviceCode) - if err != nil { - return nil, fmt.Errorf("Failed to complete device auth: %v", err) - } - - spt, err := azure.NewServicePrincipalTokenFromManualToken(oauthCfg, clientID, resource, *token) - if err != nil { - return nil, fmt.Errorf("Error constructing service principal token: %v", err) - } - return spt, nil -} - -// azureCredsPath returns the directory the azure credentials are stored in. -func azureCredsPath() string { - return filepath.Join(mcnutils.GetHomeDir(), ".docker", "machine", "credentials", "azure") -} - -// tokenCachePath returns the full path the OAuth 2.0 token should be saved at -// for given tenant ID. -func tokenCachePath(tenantID string) string { - return filepath.Join(azureCredsPath(), fmt.Sprintf("%s.json", tenantID)) -} - -// tenantIDPath returns the full path the tenant ID for the given subscription -// should be saved at.f -func tenantIDPath(subscriptionID string) string { - return filepath.Join(azureCredsPath(), fmt.Sprintf("%s.tenantid", subscriptionID)) -} - -// mkTokenCallback returns a callback function that can be used to save the -// token initially or register to the Azure SDK to be called when the token is -// refreshed. -func mkTokenCallback(path string) azure.TokenRefreshCallback { - return func(t azure.Token) error { - if err := azure.SaveToken(path, 0600, t); err != nil { - return err - } - log.Debug("Saved token to file.") - return nil - } -} - -// validateToken makes a call to Azure SDK with given token, essentially making -// sure if the access_token valid, if not it uses SDK’s functionality to -// automatically refresh the token using refresh_token (which might have -// expired). This check is essentially to make sure refresh_token is good. -func validateToken(env azure.Environment, token *azure.ServicePrincipalToken) error { - c := subscriptionsClient(env.ResourceManagerEndpoint) - c.Authorizer = token - _, err := c.List() - if err != nil { - return fmt.Errorf("Token validity check failed: %v", err) - } - return nil -} - -// getScope returns the API scope for authentication tokens. -func getScope(env azure.Environment) string { - // for AzurePublicCloud (https://management.core.windows.net/), this old - // Service Management scope covers both ASM and ARM. - return env.ServiceManagementEndpoint -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/authorizer.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/authorizer.go deleted file mode 100644 index 8ea1a35..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/authorizer.go +++ /dev/null @@ -1,15 +0,0 @@ -package azureutil - -import ( - "fmt" - - "github.com/Azure/go-autorest/autorest" -) - -// accessToken is interim autorest.Authorizer until we figure out oauth token -// handling. It holds the access token. -type accessToken string - -func (a accessToken) WithAuthorization() autorest.PrepareDecorator { - return autorest.WithHeader("Authorization", fmt.Sprintf("Bearer %s", string(a))) -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/azureutil.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/azureutil.go deleted file mode 100644 index 84d8491..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/azureutil.go +++ /dev/null @@ -1,807 +0,0 @@ -package azureutil - -import ( - "errors" - "fmt" - "net/http" - "net/url" - "strings" - "time" - - "github.com/docker/machine/drivers/azure/logutil" - "github.com/docker/machine/libmachine/log" - - "github.com/Azure/azure-sdk-for-go/arm/compute" - "github.com/Azure/azure-sdk-for-go/arm/network" - "github.com/Azure/azure-sdk-for-go/arm/resources/resources" - "github.com/Azure/azure-sdk-for-go/arm/storage" - blobstorage "github.com/Azure/azure-sdk-for-go/storage" - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" -) - -const ( - storageAccountPrefix = "vhds" // do not contaminate to user's existing storage accounts - fmtOSDiskContainer = "vhd-%s" // place vhds of VMs in separate containers for ease of cleanup - fmtOSDiskBlobName = "%s-os-disk.vhd" - fmtOSDiskResourceName = "%s-os-disk" - defaultStorageAPIVersion = blobstorage.DefaultAPIVersion -) - -var ( - // Private IPv4 address space per RFC 1918. - defaultVnetAddressPrefixes = []string{ - "192.168.0.0/16", - "10.0.0.0/8", - "172.16.0.0/12"} - - // Polling interval for VM power state check. - powerStatePollingInterval = time.Second * 5 - waitStartTimeout = time.Minute * 10 - waitPowerOffTimeout = time.Minute * 5 -) - -type AzureClient struct { - env azure.Environment - subscriptionID string - auth autorest.Authorizer -} - -func New(env azure.Environment, subsID string, auth autorest.Authorizer) *AzureClient { - return &AzureClient{env, subsID, auth} -} - -// RegisterResourceProviders registers current subscription to the specified -// resource provider namespaces if they are not already registered. Namespaces -// are case-insensitive. -func (a AzureClient) RegisterResourceProviders(namespaces ...string) error { - l, err := a.providersClient().List(nil, "") - if err != nil { - return err - } - if l.Value == nil { - return errors.New("resource providers list is returned as nil") - } - - m := make(map[string]bool) - for _, p := range *l.Value { - m[strings.ToLower(to.String(p.Namespace))] = to.String(p.RegistrationState) == "Registered" - } - - for _, ns := range namespaces { - registered, ok := m[strings.ToLower(ns)] - if !ok { - return fmt.Errorf("unknown resource provider %q", ns) - } - if registered { - log.Debugf("Already registered for %q", ns) - } else { - log.Info("Registering subscription to resource provider.", logutil.Fields{ - "ns": ns, - "subs": a.subscriptionID, - }) - if _, err := a.providersClient().Register(ns); err != nil { - return err - } - } - } - return nil -} - -// CreateResourceGroup creates a Resource Group if not exists -func (a AzureClient) CreateResourceGroup(name, location string) error { - if ok, err := a.resourceGroupExists(name); err != nil { - return err - } else if ok { - log.Infof("Resource group %q already exists.", name) - return nil - } - - log.Info("Creating resource group.", logutil.Fields{ - "name": name, - "location": location}) - _, err := a.resourceGroupsClient().CreateOrUpdate(name, - resources.ResourceGroup{ - Location: to.StringPtr(location), - }) - return err -} - -func (a AzureClient) resourceGroupExists(name string) (bool, error) { - log.Info("Querying existing resource group.", logutil.Fields{"name": name}) - _, err := a.resourceGroupsClient().Get(name) - return checkResourceExistsFromError(err) -} - -func (a AzureClient) CreateNetworkSecurityGroup(ctx *DeploymentContext, resourceGroup, name, location string, rules *[]network.SecurityRule) error { - log.Info("Configuring network security group.", logutil.Fields{ - "name": name, - "location": location}) - _, err := a.securityGroupsClient().CreateOrUpdate(resourceGroup, name, - network.SecurityGroup{ - Location: to.StringPtr(location), - Properties: &network.SecurityGroupPropertiesFormat{ - SecurityRules: rules, - }, - }, nil) - if err != nil { - return err - } - nsg, err := a.securityGroupsClient().Get(resourceGroup, name, "") - ctx.NetworkSecurityGroupID = to.String(nsg.ID) - return err -} - -func (a AzureClient) DeleteNetworkSecurityGroupIfExists(resourceGroup, name string) error { - return deleteResourceIfExists("Network Security Group", name, - func() error { - _, err := a.securityGroupsClient().Get(resourceGroup, name, "") - return err - }, - func() (autorest.Response, error) { return a.securityGroupsClient().Delete(resourceGroup, name, nil) }) -} - -func (a AzureClient) CreatePublicIPAddress(ctx *DeploymentContext, resourceGroup, name, location string, isStatic bool, dnsLabel string) error { - log.Info("Creating public IP address.", logutil.Fields{ - "name": name, - "static": isStatic}) - - var ipType network.IPAllocationMethod - if isStatic { - ipType = network.Static - } else { - ipType = network.Dynamic - } - - var dns *network.PublicIPAddressDNSSettings - if dnsLabel != "" { - dns = &network.PublicIPAddressDNSSettings{ - DomainNameLabel: to.StringPtr(dnsLabel), - } - } - - _, err := a.publicIPAddressClient().CreateOrUpdate(resourceGroup, name, - network.PublicIPAddress{ - Location: to.StringPtr(location), - Properties: &network.PublicIPAddressPropertiesFormat{ - PublicIPAllocationMethod: ipType, - DNSSettings: dns, - }, - }, nil) - if err != nil { - return err - } - ip, err := a.publicIPAddressClient().Get(resourceGroup, name, "") - ctx.PublicIPAddressID = to.String(ip.ID) - return err -} - -func (a AzureClient) DeletePublicIPAddressIfExists(resourceGroup, name string) error { - return deleteResourceIfExists("Public IP", name, - func() error { - _, err := a.publicIPAddressClient().Get(resourceGroup, name, "") - return err - }, - func() (autorest.Response, error) { return a.publicIPAddressClient().Delete(resourceGroup, name, nil) }) -} - -func (a AzureClient) CreateVirtualNetworkIfNotExists(resourceGroup, name, location string) error { - f := logutil.Fields{ - "name": name, - "rg": resourceGroup, - "location": location, - } - - log.Info("Querying if virtual network already exists.", f) - - if exists, err := a.virtualNetworkExists(resourceGroup, name); err != nil { - return err - } else if exists { - log.Info("Virtual network already exists.", f) - return nil - } - - log.Info("Creating virtual network.", f) - _, err := a.virtualNetworksClient().CreateOrUpdate(resourceGroup, name, - network.VirtualNetwork{ - Location: to.StringPtr(location), - Properties: &network.VirtualNetworkPropertiesFormat{ - AddressSpace: &network.AddressSpace{ - AddressPrefixes: to.StringSlicePtr(defaultVnetAddressPrefixes), - }, - }, - }, nil) - return err -} - -func (a AzureClient) virtualNetworkExists(resourceGroup, name string) (bool, error) { - _, err := a.virtualNetworksClient().Get(resourceGroup, name, "") - return checkResourceExistsFromError(err) -} - -// CleanupVirtualNetworkIfExists removes a subnet if there are no subnets -// attached to it. Note that this method is not safe for multiple concurrent -// writers, in case of races, deployment of a machine could fail or resource -// might not be cleaned up. -func (a AzureClient) CleanupVirtualNetworkIfExists(resourceGroup, name string) error { - return a.cleanupResourceIfExists(&vnetCleanup{rg: resourceGroup, name: name}) -} - -func (a AzureClient) GetSubnet(resourceGroup, virtualNetwork, name string) (network.Subnet, error) { - return a.subnetsClient().Get(resourceGroup, virtualNetwork, name, "") -} - -// CreateSubnet creates or updates a subnet if it does not already exist. -func (a AzureClient) CreateSubnet(ctx *DeploymentContext, resourceGroup, virtualNetwork, name, subnetPrefix string) error { - subnet, err := a.GetSubnet(resourceGroup, virtualNetwork, name) - if err == nil { - log.Info("Subnet already exists.") - ctx.SubnetID = to.String(subnet.ID) - return err - } - - // If the subnet is not found, create it - if err.(autorest.DetailedError).StatusCode == 404 { - log.Info("Configuring subnet.", logutil.Fields{ - "name": name, - "vnet": virtualNetwork, - "cidr": subnetPrefix}) - _, err = a.subnetsClient().CreateOrUpdate(resourceGroup, virtualNetwork, name, - network.Subnet{ - Properties: &network.SubnetPropertiesFormat{ - AddressPrefix: to.StringPtr(subnetPrefix), - }, - }, nil) - - if err != nil { - return err - } - - subnet, err = a.subnetsClient().Get(resourceGroup, virtualNetwork, name, "") - ctx.SubnetID = to.String(subnet.ID) - return err - } - - log.Warn("Create subnet operation error %v: ", err) - return err - -} - -// CleanupSubnetIfExists removes a subnet if there are no IP configurations -// (through NICs) are attached to it. Note that this method is not safe for -// multiple concurrent writers, in case of races, deployment of a machine could -// fail or resource might not be cleaned up. -func (a AzureClient) CleanupSubnetIfExists(resourceGroup, virtualNetwork, name string) error { - return a.cleanupResourceIfExists(&subnetCleanup{ - rg: resourceGroup, vnet: virtualNetwork, name: name, - }) -} - -func (a AzureClient) CreateNetworkInterface(ctx *DeploymentContext, resourceGroup, name, location, publicIPAddressID, subnetID, nsgID, privateIPAddress string) error { - // NOTE(ahmetalpbalkan) This method is expected to fail if the user - // specified Azure location is different than location of the virtual - // network as Azure does not support cross-region virtual networks. In this - // situation, user will get an explanatory API error from Azure. - log.Info("Creating network interface.", logutil.Fields{"name": name}) - - var publicIP *network.PublicIPAddress - if publicIPAddressID != "" { - publicIP = &network.PublicIPAddress{ID: to.StringPtr(publicIPAddressID)} - } - - var privateIPAllocMethod = network.Dynamic - if privateIPAddress != "" { - privateIPAllocMethod = network.Static - } - _, err := a.networkInterfacesClient().CreateOrUpdate(resourceGroup, name, network.Interface{ - Location: to.StringPtr(location), - Properties: &network.InterfacePropertiesFormat{ - NetworkSecurityGroup: &network.SecurityGroup{ - ID: to.StringPtr(nsgID), - }, - IPConfigurations: &[]network.InterfaceIPConfiguration{ - { - Name: to.StringPtr("ip"), - Properties: &network.InterfaceIPConfigurationPropertiesFormat{ - PrivateIPAddress: to.StringPtr(privateIPAddress), - PrivateIPAllocationMethod: privateIPAllocMethod, - PublicIPAddress: publicIP, - Subnet: &network.Subnet{ - ID: to.StringPtr(subnetID), - }, - }, - }, - }, - }, - }, nil) - if err != nil { - return err - } - nic, err := a.networkInterfacesClient().Get(resourceGroup, name, "") - ctx.NetworkInterfaceID = to.String(nic.ID) - return err -} - -func (a AzureClient) DeleteNetworkInterfaceIfExists(resourceGroup, name string) error { - return deleteResourceIfExists("Network Interface", name, - func() error { - _, err := a.networkInterfacesClient().Get(resourceGroup, name, "") - return err - }, - func() (autorest.Response, error) { return a.networkInterfacesClient().Delete(resourceGroup, name, nil) }) -} - -func (a AzureClient) CreateStorageAccount(ctx *DeploymentContext, resourceGroup, location string, storageType storage.SkuName) error { - s, err := a.findOrCreateStorageAccount(resourceGroup, location, storageType) - ctx.StorageAccount = s - return err -} - -func (a AzureClient) findOrCreateStorageAccount(resourceGroup, location string, storageType storage.SkuName) (*storage.AccountProperties, error) { - prefix := storageAccountPrefix - if s, err := a.findStorageAccount(resourceGroup, location, prefix, storageType); err != nil { - return nil, err - } else if s != nil { - return s, nil - } - - log.Debug("No eligible storage account found.", logutil.Fields{ - "location": location, - "sku": storageType}) - return a.createStorageAccount(resourceGroup, location, storageType) -} - -func (a AzureClient) findStorageAccount(resourceGroup, location, prefix string, storageType storage.SkuName) (*storage.AccountProperties, error) { - f := logutil.Fields{ - "sku": storageType, - "prefix": prefix, - "location": location} - log.Debug("Querying existing storage accounts.", f) - l, err := a.storageAccountsClient().ListByResourceGroup(resourceGroup) - if err != nil { - return nil, err - } - - if l.Value != nil { - for _, v := range *l.Value { - log.Debug("Iterating...", logutil.Fields{ - "name": to.String(v.Name), - "sku": storageType, - "location": to.String(v.Location), - }) - if to.String(v.Location) == location && v.Sku.Name == storageType && strings.HasPrefix(to.String(v.Name), prefix) { - log.Debug("Found eligible storage account.", logutil.Fields{"name": to.String(v.Name)}) - log.Info("Using existing storage account.", logutil.Fields{ - "name": to.String(v.Name), - "sku": storageType, - }) - return v.Properties, nil - } - } - } - log.Debug("No account matching the pattern is found.", f) - return nil, err -} - -func (a AzureClient) createStorageAccount(resourceGroup, location string, storageType storage.SkuName) (*storage.AccountProperties, error) { - name := randomAzureStorageAccountName() // if it's not random enough, then you're unlucky - - f := logutil.Fields{ - "name": name, - "location": location, - "sku": storageType, - } - - log.Info("Creating storage account.", f) - _, err := a.storageAccountsClient().Create(resourceGroup, name, - storage.AccountCreateParameters{ - Location: to.StringPtr(location), - Sku: &storage.Sku{Name: storageType}, - }, nil) - if err != nil { - return nil, err - } - - s, err := a.storageAccountsClient().GetProperties(resourceGroup, name) - if err != nil { - return nil, err - } - return s.Properties, nil -} - -func (a AzureClient) VirtualMachineExists(resourceGroup, name string) (bool, error) { - _, err := a.virtualMachinesClient().Get(resourceGroup, name, "") - return checkResourceExistsFromError(err) -} - -func (a AzureClient) DeleteVirtualMachineIfExists(resourceGroup, name string) error { - var vmRef compute.VirtualMachine - err := deleteResourceIfExists("Virtual Machine", name, - func() error { - vm, err := a.virtualMachinesClient().Get(resourceGroup, name, "") - vmRef = vm - return err - }, - func() (autorest.Response, error) { return a.virtualMachinesClient().Delete(resourceGroup, name, nil) }) - if err != nil { - return err - } - - // Remove disk - if vmRef.Properties != nil { - vhdURL := to.String(vmRef.Properties.StorageProfile.OsDisk.Vhd.URI) - return a.removeOSDiskBlob(resourceGroup, name, vhdURL) - } - return nil -} - -func (a AzureClient) removeOSDiskBlob(resourceGroup, vmName, vhdURL string) error { - // NOTE(ahmetalpbalkan) Currently Azure APIs do not offer a Delete Virtual - // Machine functionality which deletes the attached disks along with the VM - // as well. Therefore we find out the storage account from OS disk URL and - // fetch storage account keys to delete the container containing the disk. - log.Debug("Attempting to remove OS disk.", logutil.Fields{"vm": vmName}) - log.Debugf("OS Disk vhd URL: %q", vhdURL) - - vhdContainer := osDiskStorageContainerName(vmName) - - storageAccount, blobServiceBaseURL := extractStorageAccountFromVHDURL(vhdURL) - if storageAccount == "" { - log.Warn("Could not extract the storage account name from URL. Please clean up the disk yourself.") - return nil - } - log.Debug("Fetching storage account keys.", logutil.Fields{ - "account": storageAccount, - "storageBase": blobServiceBaseURL, - }) - resp, err := a.storageAccountsClient().ListKeys(resourceGroup, storageAccount) - if err != nil { - return err - } - - if resp.Keys == nil || len(*resp.Keys) < 1 { - return errors.New("Returned storage keys list response does not contain any keys") - } - storageAccountKey := to.String(((*resp.Keys)[0]).Value) - bs, err := blobstorage.NewClient(storageAccount, storageAccountKey, blobServiceBaseURL, defaultStorageAPIVersion, true) - if err != nil { - return fmt.Errorf("Error constructing blob storage client :%v", err) - } - - f := logutil.Fields{ - "account": storageAccount, - "container": vhdContainer} - log.Debug("Removing container of disk blobs.", f) - ok, err := bs.GetBlobService().DeleteContainerIfExists(vhdContainer) // HTTP round-trip will not be inspected - if err != nil { - log.Debugf("Container remove happened: %v", ok) - } - - cts, err := bs.GetBlobService().ListContainers(blobstorage.ListContainersParameters{}) - if err != nil { - return err - } - - if len(cts.Containers) == 0 { - log.Debugf("No storage containers left. Deleting virtual machine storage account.") - resp, err := a.storageAccountsClient().Delete(resourceGroup, storageAccount) - if err != nil { - return err - } - - log.Debugf("Storage account deletion happened: %v", resp.Response.Status) - } - - return err -} - -func (a AzureClient) CreateVirtualMachine(resourceGroup, name, location, size, availabilitySetID, networkInterfaceID, - username, sshPublicKey, imageName, customData string, storageAccount *storage.AccountProperties) error { - log.Info("Creating virtual machine.", logutil.Fields{ - "name": name, - "location": location, - "size": size, - "username": username, - "osImage": imageName, - }) - - img, err := parseImageName(imageName) - if err != nil { - return err - } - - var ( - osDiskBlobURL = osDiskStorageBlobURL(storageAccount, name) - sshKeyPath = fmt.Sprintf("/home/%s/.ssh/authorized_keys", username) - ) - log.Debugf("OS disk blob will be placed at: %s", osDiskBlobURL) - log.Debugf("SSH key will be placed at: %s", sshKeyPath) - - var osProfile = &compute.OSProfile{ - ComputerName: to.StringPtr(name), - AdminUsername: to.StringPtr(username), - LinuxConfiguration: &compute.LinuxConfiguration{ - DisablePasswordAuthentication: to.BoolPtr(true), - SSH: &compute.SSHConfiguration{ - PublicKeys: &[]compute.SSHPublicKey{ - { - Path: to.StringPtr(sshKeyPath), - KeyData: to.StringPtr(sshPublicKey), - }, - }, - }, - }, - } - - if customData != "" { - osProfile.CustomData = to.StringPtr(customData) - } - - _, err = a.virtualMachinesClient().CreateOrUpdate(resourceGroup, name, - compute.VirtualMachine{ - Location: to.StringPtr(location), - Properties: &compute.VirtualMachineProperties{ - AvailabilitySet: &compute.SubResource{ - ID: to.StringPtr(availabilitySetID), - }, - HardwareProfile: &compute.HardwareProfile{ - VMSize: compute.VirtualMachineSizeTypes(size), - }, - NetworkProfile: &compute.NetworkProfile{ - NetworkInterfaces: &[]compute.NetworkInterfaceReference{ - { - ID: to.StringPtr(networkInterfaceID), - }, - }, - }, - OsProfile: osProfile, - StorageProfile: &compute.StorageProfile{ - ImageReference: &compute.ImageReference{ - Publisher: to.StringPtr(img.publisher), - Offer: to.StringPtr(img.offer), - Sku: to.StringPtr(img.sku), - Version: to.StringPtr(img.version), - }, - OsDisk: &compute.OSDisk{ - Name: to.StringPtr(fmt.Sprintf(fmtOSDiskResourceName, name)), - Caching: compute.ReadWrite, - CreateOption: compute.FromImage, - Vhd: &compute.VirtualHardDisk{ - URI: to.StringPtr(osDiskBlobURL), - }, - }, - }, - }, - }, nil) - return err -} - -func (a AzureClient) GetVirtualMachinePowerState(resourceGroup, name string) (VMPowerState, error) { - log.Debug("Querying instance view for power state.") - vm, err := a.virtualMachinesClient().Get(resourceGroup, name, "instanceView") - if err != nil { - log.Errorf("Error querying instance view: %v", err) - return Unknown, err - } - return powerStateFromInstanceView(vm.Properties.InstanceView), nil -} - -func (a AzureClient) GetAvailabilitySet(resourceGroup, name string) (compute.AvailabilitySet, error) { - return a.availabilitySetsClient().Get(resourceGroup, name) -} - -func (a AzureClient) CreateAvailabilitySetIfNotExists(ctx *DeploymentContext, resourceGroup, name, location string) error { - f := logutil.Fields{"name": name} - log.Info("Configuring availability set.", f) - as, err := a.availabilitySetsClient().CreateOrUpdate(resourceGroup, name, - compute.AvailabilitySet{ - Location: to.StringPtr(location), - }) - ctx.AvailabilitySetID = to.String(as.ID) - return err -} - -// CleanupAvailabilitySetIfExists removes an availability set if there are no -// virtual machines attached to it. Note that this method is not safe for -// multiple concurrent writers, in case of races, deployment of a machine could -// fail or resource might not be cleaned up. -func (a AzureClient) CleanupAvailabilitySetIfExists(resourceGroup, name string) error { - return a.cleanupResourceIfExists(&avSetCleanup{rg: resourceGroup, name: name}) -} - -// GetPublicIPAddress attempts to get public IP address from the Public IP -// resource. If IP address is not allocated yet, returns empty string. If -// useFqdn is set to true, the a FQDN hostname will be returned. -func (a AzureClient) GetPublicIPAddress(resourceGroup, name string, useFqdn bool) (string, error) { - f := logutil.Fields{"name": name} - log.Debug("Querying public IP address.", f) - ip, err := a.publicIPAddressClient().Get(resourceGroup, name, "") - if err != nil { - return "", err - } - if ip.Properties == nil { - log.Debug("publicIP.Properties is nil. Could not determine IP address", f) - return "", nil - } - - if useFqdn { // return FQDN value on public IP - log.Debug("Will attempt to return FQDN.", f) - if ip.Properties.DNSSettings == nil || ip.Properties.DNSSettings.Fqdn == nil { - return "", errors.New("FQDN not found on public IP address") - } - return to.String(ip.Properties.DNSSettings.Fqdn), nil - } - return to.String(ip.Properties.IPAddress), nil -} - -// GetPrivateIPAddress attempts to retrieve private IP address of the specified -// network interface name. If IP address is not allocated yet, returns empty -// string. -func (a AzureClient) GetPrivateIPAddress(resourceGroup, name string) (string, error) { - f := logutil.Fields{"name": name} - log.Debug("Querying network interface.", f) - nic, err := a.networkInterfacesClient().Get(resourceGroup, name, "") - if err != nil { - return "", err - } - if nic.Properties == nil || nic.Properties.IPConfigurations == nil || - len(*nic.Properties.IPConfigurations) == 0 { - log.Debug("No IPConfigurations found on NIC", f) - return "", nil - } - return to.String((*nic.Properties.IPConfigurations)[0].Properties.PrivateIPAddress), nil -} - -// StartVirtualMachine starts the virtual machine and waits until it reaches -// the goal state (running) or times out. -func (a AzureClient) StartVirtualMachine(resourceGroup, name string) error { - log.Info("Starting virtual machine.", logutil.Fields{"vm": name}) - if _, err := a.virtualMachinesClient().Start(resourceGroup, name, nil); err != nil { - return err - } - return a.waitVMPowerState(resourceGroup, name, Running, waitStartTimeout) -} - -// StopVirtualMachine power offs the virtual machine and waits until it reaches -// the goal state (stopped) or times out. -func (a AzureClient) StopVirtualMachine(resourceGroup, name string) error { - log.Info("Stopping virtual machine.", logutil.Fields{"vm": name}) - if _, err := a.virtualMachinesClient().PowerOff(resourceGroup, name, nil); err != nil { - return err - } - return a.waitVMPowerState(resourceGroup, name, Stopped, waitPowerOffTimeout) -} - -// RestartVirtualMachine restarts the virtual machine and waits until it reaches -// the goal state (stopped) or times out. -func (a AzureClient) RestartVirtualMachine(resourceGroup, name string) error { - log.Info("Restarting virtual machine.", logutil.Fields{"vm": name}) - if _, err := a.virtualMachinesClient().Restart(resourceGroup, name, nil); err != nil { - return err - } - return a.waitVMPowerState(resourceGroup, name, Running, waitStartTimeout) -} - -// deleteResourceIfExists is an utility method to determine if a resource exists -// from the error returned from its Get response. If so, deletes it. name is -// used only for logging purposes. -func deleteResourceIfExists(resourceType, name string, getFunc func() error, deleteFunc func() (autorest.Response, error)) error { - f := logutil.Fields{"name": name} - log.Debug(fmt.Sprintf("Querying if %s exists.", resourceType), f) - if exists, err := checkResourceExistsFromError(getFunc()); err != nil { - return err - } else if !exists { - log.Info(fmt.Sprintf("%s does not exist. Skipping.", resourceType), f) - return nil - } - log.Info(fmt.Sprintf("Removing %s resource.", resourceType), f) - _, err := deleteFunc() - return err -} - -// waitVMPowerState polls the Virtual Machine instance view until it reaches the -// specified goal power state or times out. If checking for virtual machine -// state fails or waiting times out, an error is returned. -func (a AzureClient) waitVMPowerState(resourceGroup, name string, goalState VMPowerState, timeout time.Duration) error { - // NOTE(ahmetalpbalkan): Azure APIs for Start and Stop are actually async - // operations on which our SDK blocks and does polling until the operation - // is complete. - // - // By the time the issued power cycle operation is complete, the VM will be - // already in the goal PowerState. Hence, this method will return in the - // first check, however there is no harm in being defensive. - log.Debug("Waiting until VM reaches goal power state.", logutil.Fields{ - "vm": name, - "goalState": goalState, - "timeout": timeout, - }) - - chErr := make(chan error) - go func(ch chan error) { - for { - select { - case <-ch: - // channel closed - return - default: - state, err := a.GetVirtualMachinePowerState(resourceGroup, name) - if err != nil { - ch <- err - return - } - if state != goalState { - log.Debug(fmt.Sprintf("Waiting %v...", powerStatePollingInterval), - logutil.Fields{ - "goalState": goalState, - "state": state, - }) - time.Sleep(powerStatePollingInterval) - } else { - log.Debug("Reached goal power state.", - logutil.Fields{"state": state}) - ch <- nil - return - } - } - } - }(chErr) - - select { - case <-time.After(timeout): - close(chErr) - return fmt.Errorf("Waiting for goal state %q timed out after %v", goalState, timeout) - case err := <-chErr: - return err - } -} - -// checkExistsFromError inspects an error and returns a true if err is nil, -// false if error is an autorest.Error with StatusCode=404 and will return the -// error back if error is another status code or another type of error. -func checkResourceExistsFromError(err error) (bool, error) { - if err == nil { - return true, nil - } - v, ok := err.(autorest.DetailedError) - if ok && v.StatusCode == http.StatusNotFound { - return false, nil - } - return false, v -} - -// osDiskStorageBlobURL gives the full url of the VHD blob where the OS disk for -// the given VM should be stored. -func osDiskStorageBlobURL(account *storage.AccountProperties, vmName string) string { - containerURL := osDiskStorageContainerURL(account, vmName) // has trailing slash - blobName := fmt.Sprintf(fmtOSDiskBlobName, vmName) - return containerURL + blobName -} - -// osDiskStorageContainerName returns the container name the OS disk for the VM -// should be saved. -func osDiskStorageContainerName(vm string) string { return fmt.Sprintf(fmtOSDiskContainer, vm) } - -// osDiskStorageContainerURL crafts a URL with a trailing slash pointing -// to the full Azure Blob Container URL for given VM name. -func osDiskStorageContainerURL(account *storage.AccountProperties, vmName string) string { - return fmt.Sprintf("%s%s/", to.String(account.PrimaryEndpoints.Blob), osDiskStorageContainerName(vmName)) -} - -// extractStorageAccountFromVHDURL parses a blob URL and extracts the Azure -// Storage account name from the URL, namely first subdomain of the hostname and -// the Azure Storage service base URL (e.g. core.windows.net). If it could not -// be parsed, returns empty string. -func extractStorageAccountFromVHDURL(vhdURL string) (string, string) { - u, err := url.Parse(vhdURL) - if err != nil { - log.Warn(fmt.Sprintf("URL parse error: %v", err), logutil.Fields{"url": vhdURL}) - return "", "" - } - parts := strings.SplitN(u.Host, ".", 2) - if len(parts) != 2 { - log.Warnf("Could not split account name and storage base URL: %s", vhdURL) - return "", "" - } - return parts[0], strings.TrimPrefix(parts[1], "blob.") // "blob." prefix will added by azure storage sdk -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/cleanup.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/cleanup.go deleted file mode 100644 index 431ec53..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/cleanup.go +++ /dev/null @@ -1,126 +0,0 @@ -package azureutil - -import ( - "fmt" - - "github.com/Azure/azure-sdk-for-go/arm/compute" - "github.com/Azure/azure-sdk-for-go/arm/network" - "github.com/docker/machine/drivers/azure/logutil" - "github.com/docker/machine/libmachine/log" -) - -type cleanupResource interface { - // Get retrieves if the resource and saves its reference to the instance - // for further using, returned error is used to determine if the resource - // exists - Get(a AzureClient) error - - // Delete deletes the resource - Delete(a AzureClient) error - - // HasAttachedResources checks the resource reference if it has dependent - // resources attached to it preventing it from being deleted. - HasAttachedResources() bool - - // ResourceType returns human-readable name of the type of the resource. - ResourceType() string - - // LogFields returns the logging fields used during cleanup logging. - LogFields() logutil.Fields -} - -// cleanupResourceIfExists checks if the resource exists, if it does and it -// does not have any attached resources, then deletes the resource. If the -// resource does not exist or is not eligible for cleanup, returns nil. If an -// error is encountered, returns the error. -func (a AzureClient) cleanupResourceIfExists(r cleanupResource) error { - f := r.LogFields() - log.Info(fmt.Sprintf("Attempting to clean up %s resource...", r.ResourceType()), f) - err := r.Get(a) - if exists, err := checkResourceExistsFromError(err); err != nil { - return err - } else if !exists { - log.Debug(fmt.Sprintf("%s resource does not exist. Skipping.", r.ResourceType()), f) - return nil - } - - if !r.HasAttachedResources() { - log.Debug(fmt.Sprintf("%s does not have any attached dependent resource.", r.ResourceType()), f) - log.Info(fmt.Sprintf("Removing %s resource...", r.ResourceType()), f) - return r.Delete(a) - } - log.Info(fmt.Sprintf("%s is still in use by other resources, skipping removal.", r.ResourceType()), f) - return nil -} - -// subnetCleanup manages cleanup of Subnet resources -type subnetCleanup struct { - rg, vnet, name string - ref network.Subnet -} - -func (c *subnetCleanup) Get(a AzureClient) (err error) { - c.ref, err = a.subnetsClient().Get(c.rg, c.vnet, c.name, "") - return err -} - -func (c *subnetCleanup) Delete(a AzureClient) error { - _, err := a.subnetsClient().Delete(c.rg, c.vnet, c.name, nil) - return err -} - -func (c *subnetCleanup) ResourceType() string { return "Subnet" } - -func (c *subnetCleanup) LogFields() logutil.Fields { return logutil.Fields{"name": c.name} } - -func (c *subnetCleanup) HasAttachedResources() bool { - return c.ref.Properties.IPConfigurations != nil && len(*c.ref.Properties.IPConfigurations) > 0 -} - -// vnetCleanup manages cleanup of Virtual Network resources. -type vnetCleanup struct { - rg, name string - ref network.VirtualNetwork -} - -func (c *vnetCleanup) Get(a AzureClient) (err error) { - c.ref, err = a.virtualNetworksClient().Get(c.rg, c.name, "") - return err -} - -func (c *vnetCleanup) Delete(a AzureClient) error { - _, err := a.virtualNetworksClient().Delete(c.rg, c.name, nil) - return err -} - -func (c *vnetCleanup) ResourceType() string { return "Virtual Network" } - -func (c *vnetCleanup) LogFields() logutil.Fields { return logutil.Fields{"name": c.name} } - -func (c *vnetCleanup) HasAttachedResources() bool { - return c.ref.Properties.Subnets != nil && len(*c.ref.Properties.Subnets) > 0 -} - -// avSetCleanup manages cleanup of Availability Set resources. -type avSetCleanup struct { - rg, name string - ref compute.AvailabilitySet -} - -func (c *avSetCleanup) Get(a AzureClient) (err error) { - c.ref, err = a.availabilitySetsClient().Get(c.rg, c.name) - return err -} - -func (c *avSetCleanup) Delete(a AzureClient) error { - _, err := a.availabilitySetsClient().Delete(c.rg, c.name) - return err -} - -func (c *avSetCleanup) ResourceType() string { return "Availability Set" } - -func (c *avSetCleanup) LogFields() logutil.Fields { return logutil.Fields{"name": c.name} } - -func (c *avSetCleanup) HasAttachedResources() bool { - return c.ref.Properties.VirtualMachines != nil && len(*c.ref.Properties.VirtualMachines) > 0 -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/clients.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/clients.go deleted file mode 100644 index 2da9907..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/clients.go +++ /dev/null @@ -1,137 +0,0 @@ -package azureutil - -import ( - "fmt" - "time" - - "github.com/docker/machine/version" - - "github.com/Azure/azure-sdk-for-go/arm/compute" - "github.com/Azure/azure-sdk-for-go/arm/network" - "github.com/Azure/azure-sdk-for-go/arm/resources/resources" - "github.com/Azure/azure-sdk-for-go/arm/resources/subscriptions" - "github.com/Azure/azure-sdk-for-go/arm/storage" - "github.com/Azure/go-autorest/autorest" -) - -// TODO(ahmetalpbalkan) Remove duplication around client creation. This is -// happening because we auto-generate our SDK and we don't have generics in Go. -// We are hoping to come up with a factory or some defaults instance to set -// these client configuration in a central place in azure-sdk-for-go. - -func oauthClient() autorest.Client { - c := autorest.NewClientWithUserAgent(fmt.Sprintf("docker-machine/%s", version.Version)) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - // TODO set user agent - return c -} - -func subscriptionsClient(baseURI string) subscriptions.Client { - c := subscriptions.NewClientWithBaseURI(baseURI) // used only for unauthenticated requests for generic subs IDs - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} - -func (a AzureClient) providersClient() resources.ProvidersClient { - c := resources.NewProvidersClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) - c.Authorizer = a.auth - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} - -func (a AzureClient) resourceGroupsClient() resources.GroupsClient { - c := resources.NewGroupsClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) - c.Authorizer = a.auth - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} - -func (a AzureClient) securityGroupsClient() network.SecurityGroupsClient { - c := network.NewSecurityGroupsClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) - c.Authorizer = a.auth - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} - -func (a AzureClient) virtualNetworksClient() network.VirtualNetworksClient { - c := network.NewVirtualNetworksClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) - c.Authorizer = a.auth - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} - -func (a AzureClient) subnetsClient() network.SubnetsClient { - c := network.NewSubnetsClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) - c.Authorizer = a.auth - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} - -func (a AzureClient) networkInterfacesClient() network.InterfacesClient { - c := network.NewInterfacesClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) - c.Authorizer = a.auth - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} - -func (a AzureClient) publicIPAddressClient() network.PublicIPAddressesClient { - c := network.NewPublicIPAddressesClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) - c.Authorizer = a.auth - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} - -func (a AzureClient) storageAccountsClient() storage.AccountsClient { - c := storage.NewAccountsClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) - c.Authorizer = a.auth - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} - -func (a AzureClient) virtualMachinesClient() compute.VirtualMachinesClient { - c := compute.NewVirtualMachinesClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) - c.Authorizer = a.auth - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} - -func (a AzureClient) availabilitySetsClient() compute.AvailabilitySetsClient { - c := compute.NewAvailabilitySetsClientWithBaseURI(a.env.ResourceManagerEndpoint, a.subscriptionID) - c.Authorizer = a.auth - c.Client.UserAgent += fmt.Sprintf(";docker-machine/%s", version.Version) - c.RequestInspector = withInspection() - c.ResponseInspector = byInspecting() - c.PollingDelay = time.Second * 5 - return c -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/context.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/context.go deleted file mode 100644 index 63d54af..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/context.go +++ /dev/null @@ -1,20 +0,0 @@ -package azureutil - -import ( - "github.com/Azure/azure-sdk-for-go/arm/network" - "github.com/Azure/azure-sdk-for-go/arm/storage" -) - -// DeploymentContext contains references to various sources created and then -// used in creating other resources. -type DeploymentContext struct { - VirtualNetworkExists bool - StorageAccount *storage.AccountProperties - PublicIPAddressID string - NetworkSecurityGroupID string - SubnetID string - NetworkInterfaceID string - SSHPublicKey string - AvailabilitySetID string - FirewallRules *[]network.SecurityRule -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/inspector.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/inspector.go deleted file mode 100644 index d992b69..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/inspector.go +++ /dev/null @@ -1,36 +0,0 @@ -package azureutil - -import ( - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/docker/machine/drivers/azure/logutil" - "github.com/docker/machine/libmachine/log" -) - -func withInspection() autorest.PrepareDecorator { - return func(p autorest.Preparer) autorest.Preparer { - return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) { - log.Debug("Azure request", logutil.Fields{ - "method": r.Method, - "request": r.URL.String(), - }) - return p.Prepare(r) - }) - } -} - -func byInspecting() autorest.RespondDecorator { - return func(r autorest.Responder) autorest.Responder { - return autorest.ResponderFunc(func(resp *http.Response) error { - log.Debug("Azure response", logutil.Fields{ - "status": resp.Status, - "method": resp.Request.Method, - "request": resp.Request.URL.String(), - "x-ms-request-id": azure.ExtractRequestID(resp), - }) - return r.Respond(resp) - }) - } -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/naming.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/naming.go deleted file mode 100644 index 9967fcf..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/naming.go +++ /dev/null @@ -1,21 +0,0 @@ -package azureutil - -import ( - "fmt" -) - -const ( - fmtNIC = "%s-nic" - fmtIP = "%s-ip" - fmtNSG = "%s-firewall" - fmtVM = "%s" -) - -// ResourceNaming provides methods to construct Azure resource names for a given -// machine name. -type ResourceNaming string - -func (r ResourceNaming) IP() string { return fmt.Sprintf(fmtIP, r) } -func (r ResourceNaming) NIC() string { return fmt.Sprintf(fmtNIC, r) } -func (r ResourceNaming) NSG() string { return fmt.Sprintf(fmtNSG, r) } -func (r ResourceNaming) VM() string { return fmt.Sprintf(fmtVM, r) } diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/powerstate.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/powerstate.go deleted file mode 100644 index 02e5499..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/powerstate.go +++ /dev/null @@ -1,93 +0,0 @@ -package azureutil - -import ( - "strings" - - "github.com/docker/machine/libmachine/log" - - "github.com/Azure/azure-sdk-for-go/arm/compute" - "github.com/Azure/go-autorest/autorest/to" -) - -type VMPowerState string - -const ( - // Unknown is returned when Azure does not provide a PowerState (happens - // when VM is just deployed or started transitioning to another state) or - // obtained PowerState is not one of the following. - Unknown VMPowerState = "" - - // Stopped indicates that VM is allocated and in powered off state or the VM - // has been just deployed for the first time. In this state, VM can be powered - // on or - Stopped VMPowerState = "stopped" - - // Stopping indicates that VM is about to go into powered off state. - Stopping VMPowerState = "stopping" - - // Starting indicates that VM is being created or powered on. - Starting VMPowerState = "starting" - - // Running indicates that VM is either powered on or being rebooted. VM - // stays in this state during the reboot operation. In this state VM can be - // stopped, restarted or deallocated. - Running VMPowerState = "running" - - // Deallocating indicates that the VM is being terminated. - Deallocating VMPowerState = "deallocating" - - // Deallocated indicates that the VM is being terminated. In this state, VM - // can be powered on or powered off. - Deallocated VMPowerState = "deallocated" -) - -const ( - powerStateCodePrefix = "PowerState/" -) - -// powerStateFromInstanceView reads the instance view response and extracts the -// power state status (if exists) from there. If no status is found or an -// unknown status has occurred, returns Unknown. -func powerStateFromInstanceView(instanceView *compute.VirtualMachineInstanceView) VMPowerState { - if instanceView == nil { - log.Debug("Retrieved nil instance view.") - return Unknown - } else if instanceView.Statuses == nil || len(*instanceView.Statuses) == 0 { - log.Debug("Retrieved nil or empty instanceView.statuses.") - return Unknown - } - statuses := *instanceView.Statuses - - // Filter statuses whose "code" starts with "PowerState/" - var s *compute.InstanceViewStatus - for _, v := range statuses { - log.Debugf("Matching pattern for code=%q", to.String(v.Code)) - if strings.HasPrefix(to.String(v.Code), powerStateCodePrefix) { - log.Debug("Power state found.") - s = &v - break - } - } - if s == nil { - log.Debug("No PowerState found in the instance view statuses.") - return Unknown - } - code := strings.TrimPrefix(to.String(s.Code), powerStateCodePrefix) - switch code { - case "stopped": - return Stopped - case "stopping": - return Stopping - case "starting": - return Starting - case "running": - return Running - case "deallocated": - return Deallocated - case "deallocating": - return Deallocating - default: - log.Warn("Encountered unknown PowerState for virtual machine: %q", code) - return Unknown - } -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/tenantid.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/tenantid.go deleted file mode 100644 index 0280152..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/tenantid.go +++ /dev/null @@ -1,123 +0,0 @@ -package azureutil - -import ( - "fmt" - "io/ioutil" - "net/http" - "os" - "path/filepath" - "regexp" - "strings" - - "github.com/docker/machine/drivers/azure/logutil" - "github.com/docker/machine/libmachine/log" - - "github.com/Azure/go-autorest/autorest/azure" -) - -// loadOrFindTenantID figures out the AAD tenant ID of the subscription by first -// looking at the cache file, if not exists, makes a network call to load it and -// cache it for future use. -func loadOrFindTenantID(env azure.Environment, subscriptionID string) (string, error) { - var tenantID string - - log.Debug("Looking up AAD Tenant ID.", logutil.Fields{ - "subs": subscriptionID}) - - // Load from cache - fp := tenantIDPath(subscriptionID) - b, err := ioutil.ReadFile(fp) - if err == nil { - tenantID = strings.TrimSpace(string(b)) - log.Debugf("Tenant ID loaded from file: %s", fp) - } else if os.IsNotExist(err) { - log.Debugf("Tenant ID file not found: %s", fp) - } else { - return "", fmt.Errorf("Failed to load tenant ID file: %v", err) - } - - // Handle cache miss - if tenantID == "" { - log.Debug("Making API call to find tenant ID") - t, err := findTenantID(env, subscriptionID) - if err != nil { - return "", err - } - tenantID = t - - // Cache the result - if err := saveTenantID(fp, tenantID); err != nil { - return "", fmt.Errorf("Failed to save tenant ID: %v", err) - } - log.Debugf("Cached tenant ID to file: %s", fp) - } - log.Debug("Found AAD Tenant ID.", logutil.Fields{ - "tenant": tenantID, - "subs": subscriptionID}) - return tenantID, nil -} - -// findTenantID figures out the AAD tenant ID of the subscription by making an -// unauthenticated request to the Get Subscription Details endpoint and parses -// the value from WWW-Authenticate header. -func findTenantID(env azure.Environment, subscriptionID string) (string, error) { - const hdrKey = "WWW-Authenticate" - c := subscriptionsClient(env.ResourceManagerEndpoint) - - // we expect this request to fail (err != nil), but we are only interested - // in headers, so surface the error if the Response is not present (i.e. - // network error etc) - subs, err := c.Get(subscriptionID) - if subs.Response.Response == nil { - return "", fmt.Errorf("Request failed: %v", err) - } - - // Expecting 401 StatusUnauthorized here, just read the header - if subs.StatusCode != http.StatusUnauthorized { - return "", fmt.Errorf("Unexpected response from Get Subscription: %v", err) - } - hdr := subs.Header.Get(hdrKey) - if hdr == "" { - return "", fmt.Errorf("Header %v not found in Get Subscription response", hdrKey) - } - - // Example value for hdr: - // Bearer authorization_uri="https://login.windows.net/996fe9d1-6171-40aa-945b-4c64b63bf655", error="invalid_token", error_description="The authentication failed because of missing 'Authorization' header." - r := regexp.MustCompile(`authorization_uri=".*/([0-9a-f\-]+)"`) - m := r.FindStringSubmatch(hdr) - if m == nil { - return "", fmt.Errorf("Could not find the tenant ID in header: %s %q", hdrKey, hdr) - } - return m[1], nil -} - -// saveTenantID performs an atomic write to the path with given tenantID contents. -func saveTenantID(path string, tenantID string) error { - var perm os.FileMode = 0600 - - dir := filepath.Dir(path) - if err := os.MkdirAll(dir, os.ModePerm); err != nil { - return fmt.Errorf("Failed to create directory %s: %v", dir, err) - } - - f, err := ioutil.TempFile(dir, "tenantid") - if err != nil { - return fmt.Errorf("Failed to create temp file: %v", err) - } - defer f.Close() - - fp := f.Name() - if _, err := f.Write([]byte(tenantID)); err != nil { - return fmt.Errorf("Failed to write tenant ID to file: %v", err) - } - f.Close() - - // atomic move by rename - if err := os.Rename(fp, path); err != nil { - return fmt.Errorf("Failed to rename file. src=%s dst=%s error=%v", fp, path, err) - } - if err := os.Chmod(path, perm); err != nil { - return fmt.Errorf("Failed to chmod the file %s: %v", path, err) - } - return nil -} diff --git a/vendor/github.com/docker/machine/drivers/azure/azureutil/util.go b/vendor/github.com/docker/machine/drivers/azure/azureutil/util.go deleted file mode 100644 index 55acc46..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/azureutil/util.go +++ /dev/null @@ -1,45 +0,0 @@ -package azureutil - -import ( - "fmt" - "math/rand" - "strings" - "time" -) - -/* Utilities */ - -// randomAzureStorageAccountName generates a valid storage account name prefixed -// with a predefined string. Availability of the name is not checked. Uses maximum -// length to maximise randomness. -func randomAzureStorageAccountName() string { - const ( - maxLen = 24 - chars = "0123456789abcdefghijklmnopqrstuvwxyz" - ) - return storageAccountPrefix + randomString(maxLen-len(storageAccountPrefix), chars) -} - -// randomString generates a random string of given length using specified alphabet. -func randomString(n int, alphabet string) string { - r := timeSeed() - b := make([]byte, n) - for i := range b { - b[i] = alphabet[r.Intn(len(alphabet))] - } - return string(b) -} - -// imageName holds various components of an OS image name identifier -type imageName struct{ publisher, offer, sku, version string } - -// parseImageName parses a publisher:offer:sku:version into those parts. -func parseImageName(image string) (imageName, error) { - l := strings.Split(image, ":") - if len(l) != 4 { - return imageName{}, fmt.Errorf("image name %q not a valid format", image) - } - return imageName{l[0], l[1], l[2], l[3]}, nil -} - -func timeSeed() *rand.Rand { return rand.New(rand.NewSource(time.Now().UTC().UnixNano())) } diff --git a/vendor/github.com/docker/machine/drivers/azure/logutil/logfields.go b/vendor/github.com/docker/machine/drivers/azure/logutil/logfields.go deleted file mode 100644 index b450594..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/logutil/logfields.go +++ /dev/null @@ -1,16 +0,0 @@ -package logutil - -import "fmt" - -type Fields map[string]interface{} - -func (f Fields) String() string { - var s string - for k, v := range f { - if sv, ok := v.(string); ok { - v = fmt.Sprintf("%q", sv) - } - s += fmt.Sprintf(" %s=%v", k, v) - } - return s -} diff --git a/vendor/github.com/docker/machine/drivers/azure/util.go b/vendor/github.com/docker/machine/drivers/azure/util.go deleted file mode 100644 index 2f1f64e..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/util.go +++ /dev/null @@ -1,230 +0,0 @@ -package azure - -import ( - "fmt" - "io/ioutil" - "net" - "net/url" - "strings" - - "github.com/Azure/azure-sdk-for-go/arm/network" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/to" - "github.com/docker/machine/drivers/azure/azureutil" - "github.com/docker/machine/drivers/azure/logutil" - "github.com/docker/machine/drivers/driverutil" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" -) - -var ( - environments = map[string]azure.Environment{ - azure.PublicCloud.Name: azure.PublicCloud, - azure.USGovernmentCloud.Name: azure.USGovernmentCloud, - azure.ChinaCloud.Name: azure.ChinaCloud, - azure.GermanCloud.Name: azure.GermanCloud, - } -) - -// requiredOptionError forms an error from the error indicating the option has -// to be provided with a value for this driver. -type requiredOptionError string - -func (r requiredOptionError) Error() string { - return fmt.Sprintf("%s driver requires the %q option.", driverName, string(r)) -} - -// newAzureClient creates an AzureClient helper from the Driver context and -// initiates authentication if required. -func (d *Driver) newAzureClient() (*azureutil.AzureClient, error) { - env, ok := environments[d.Environment] - if !ok { - valid := make([]string, 0, len(environments)) - for k := range environments { - valid = append(valid, k) - } - - return nil, fmt.Errorf("Invalid Azure environment: %q, supported values: %s", d.Environment, strings.Join(valid, ", ")) - } - - var ( - token *azure.ServicePrincipalToken - err error - ) - if d.ClientID != "" && d.ClientSecret != "" { // use Service Principal auth - log.Debug("Using Azure service principal authentication.") - token, err = azureutil.AuthenticateServicePrincipal(env, d.SubscriptionID, d.ClientID, d.ClientSecret) - if err != nil { - return nil, fmt.Errorf("Failed to authenticate using service principal credentials: %+v", err) - } - } else { // use browser-based device auth - log.Debug("Using Azure device flow authentication.") - token, err = azureutil.AuthenticateDeviceFlow(env, d.SubscriptionID) - if err != nil { - return nil, fmt.Errorf("Error creating Azure client: %v", err) - } - } - return azureutil.New(env, d.SubscriptionID, token), nil -} - -// generateSSHKey creates a ssh key pair locally and saves the public key file -// contents in OpenSSH format to the DeploymentContext. -func (d *Driver) generateSSHKey(ctx *azureutil.DeploymentContext) error { - privPath := d.GetSSHKeyPath() - pubPath := privPath + ".pub" - - log.Debug("Creating SSH key...", logutil.Fields{ - "pub": pubPath, - "priv": privPath, - }) - - if err := ssh.GenerateSSHKey(privPath); err != nil { - return err - } - log.Debug("SSH key pair generated.") - - publicKey, err := ioutil.ReadFile(pubPath) - ctx.SSHPublicKey = string(publicKey) - return err -} - -// getSecurityRules creates network security group rules based on driver -// configuration such as SSH port, docker port and swarm port. -func (d *Driver) getSecurityRules(extraPorts []string) (*[]network.SecurityRule, error) { - mkRule := func(priority int, name, description, srcPort, dstPort string, proto network.SecurityRuleProtocol) network.SecurityRule { - return network.SecurityRule{ - Name: to.StringPtr(name), - Properties: &network.SecurityRulePropertiesFormat{ - Description: to.StringPtr(description), - SourceAddressPrefix: to.StringPtr("*"), - DestinationAddressPrefix: to.StringPtr("*"), - SourcePortRange: to.StringPtr(srcPort), - DestinationPortRange: to.StringPtr(dstPort), - Access: network.Allow, - Direction: network.Inbound, - Protocol: proto, - Priority: to.Int32Ptr(int32(priority)), - }, - } - } - - log.Debugf("Docker port is configured as %d", d.DockerPort) - - // Base ports to be opened for any machine - rl := []network.SecurityRule{ - mkRule(100, "SSHAllowAny", "Allow ssh from public Internet", "*", fmt.Sprintf("%d", d.BaseDriver.SSHPort), network.TCP), - mkRule(300, "DockerAllowAny", "Allow docker engine access (TLS-protected)", "*", fmt.Sprintf("%d", d.DockerPort), network.TCP), - } - - // Open swarm port if configured - if d.BaseDriver.SwarmMaster { - swarmHost := d.BaseDriver.SwarmHost - log.Debugf("Swarm host is configured as %q", swarmHost) - u, err := url.Parse(swarmHost) - if err != nil { - return nil, fmt.Errorf("Cannot parse URL %q: %v", swarmHost, err) - } - _, swarmPort, err := net.SplitHostPort(u.Host) - if err != nil { - return nil, fmt.Errorf("Could not parse swarm port in %q: %v", u.Host, err) - } - rl = append(rl, mkRule(500, "DockerSwarmAllowAny", "Allow swarm manager access (TLS-protected)", "*", swarmPort, network.TCP)) - } else { - log.Debug("Swarm host is not configured.") - } - - // extra port numbers requested by user - basePri := 1000 - for i, p := range extraPorts { - port, protocol := driverutil.SplitPortProto(p) - proto, err := parseSecurityRuleProtocol(protocol) - if err != nil { - return nil, fmt.Errorf("cannot parse security rule protocol: %v", err) - } - log.Debugf("User-requested port to be opened on NSG: %v/%s", port, proto) - name := fmt.Sprintf("Port%s-%sAllowAny", port, proto) - name = strings.Replace(name, "*", "Asterisk", -1) - r := mkRule(basePri+i, name, "User requested port to be accessible from Internet via docker-machine", "*", port, proto) - rl = append(rl, r) - } - log.Debugf("Total NSG rules: %d", len(rl)) - - return &rl, nil -} - -func (d *Driver) naming() azureutil.ResourceNaming { - return azureutil.ResourceNaming(d.BaseDriver.MachineName) -} - -// ipAddress returns machine’s private or public IP address according to the -// configuration. If no IP address is found it returns empty string. -func (d *Driver) ipAddress() (ip string, err error) { - c, err := d.newAzureClient() - if err != nil { - return "", err - } - - var ipType string - if d.UsePrivateIP || d.NoPublicIP { - ipType = "Private" - ip, err = c.GetPrivateIPAddress(d.ResourceGroup, d.naming().NIC()) - } else { - ipType = "Public" - ip, err = c.GetPublicIPAddress(d.ResourceGroup, - d.naming().IP(), - d.DNSLabel != "") - } - - log.Debugf("Retrieving %s IP address...", ipType) - if err != nil { - return "", fmt.Errorf("Error querying %s IP: %v", ipType, err) - } - if ip == "" { - log.Debugf("%s IP address is not yet allocated.", ipType) - } - return ip, nil -} - -func machineStateForVMPowerState(ps azureutil.VMPowerState) state.State { - m := map[azureutil.VMPowerState]state.State{ - azureutil.Running: state.Running, - azureutil.Starting: state.Starting, - azureutil.Stopping: state.Stopping, - azureutil.Stopped: state.Stopped, - azureutil.Deallocating: state.Stopping, - azureutil.Deallocated: state.Stopped, - azureutil.Unknown: state.None, - } - - if v, ok := m[ps]; ok { - return v - } - log.Warnf("Azure PowerState %q does not map to a docker-machine state.", ps) - return state.None -} - -// parseVirtualNetwork parses Virtual Network input format "[resourcegroup:]name" -// into Resource Group (uses provided one if omitted) and Virtual Network Name -func parseVirtualNetwork(name string, defaultRG string) (string, string) { - l := strings.SplitN(name, ":", 2) - if len(l) == 2 { - return l[0], l[1] - } - return defaultRG, name -} - -// parseSecurityRuleProtocol parses a protocol string into a network.SecurityRuleProtocol -// and returns error if the protocol is not supported -func parseSecurityRuleProtocol(proto string) (network.SecurityRuleProtocol, error) { - switch strings.ToLower(proto) { - case "tcp": - return network.TCP, nil - case "udp": - return network.UDP, nil - case "*": - return network.Asterisk, nil - default: - return "", fmt.Errorf("invalid protocol %s", proto) - } -} diff --git a/vendor/github.com/docker/machine/drivers/azure/util_test.go b/vendor/github.com/docker/machine/drivers/azure/util_test.go deleted file mode 100644 index 58da224..0000000 --- a/vendor/github.com/docker/machine/drivers/azure/util_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package azure - -import ( - "testing" - - "github.com/Azure/azure-sdk-for-go/arm/network" - "github.com/stretchr/testify/assert" -) - -func TestParseSecurityRuleProtocol(t *testing.T) { - tests := []struct { - raw string - expectedProto network.SecurityRuleProtocol - expectedErr bool - }{ - {"tcp", network.TCP, false}, - {"udp", network.UDP, false}, - {"*", network.Asterisk, false}, - {"Invalid", "", true}, - } - - for _, tc := range tests { - proto, err := parseSecurityRuleProtocol(tc.raw) - assert.Equal(t, tc.expectedProto, proto) - if tc.expectedErr { - assert.Error(t, err) - } else { - assert.NoError(t, err) - } - } -} diff --git a/vendor/github.com/docker/machine/drivers/digitalocean/digitalocean.go b/vendor/github.com/docker/machine/drivers/digitalocean/digitalocean.go deleted file mode 100644 index f9d0a62..0000000 --- a/vendor/github.com/docker/machine/drivers/digitalocean/digitalocean.go +++ /dev/null @@ -1,427 +0,0 @@ -package digitalocean - -import ( - "context" - "fmt" - "io/ioutil" - "net" - "os" - "path" - "strings" - "time" - - "github.com/digitalocean/godo" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" - "golang.org/x/oauth2" -) - -type Driver struct { - *drivers.BaseDriver - AccessToken string - DropletID int - DropletName string - Image string - Region string - SSHKeyID int - SSHKeyFingerprint string - SSHKey string - Size string - IPv6 bool - Backups bool - PrivateNetworking bool - UserDataFile string - Tags string -} - -const ( - defaultSSHPort = 22 - defaultSSHUser = "root" - defaultImage = "ubuntu-16-04-x64" - defaultRegion = "nyc3" - defaultSize = "512mb" -) - -// GetCreateFlags registers the flags this driver adds to -// "docker hosts create" -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - EnvVar: "DIGITALOCEAN_ACCESS_TOKEN", - Name: "digitalocean-access-token", - Usage: "Digital Ocean access token", - }, - mcnflag.StringFlag{ - EnvVar: "DIGITALOCEAN_SSH_USER", - Name: "digitalocean-ssh-user", - Usage: "SSH username", - Value: defaultSSHUser, - }, - mcnflag.StringFlag{ - EnvVar: "DIGITALOCEAN_SSH_KEY_FINGERPRINT", - Name: "digitalocean-ssh-key-fingerprint", - Usage: "SSH key fingerprint", - }, - mcnflag.StringFlag{ - EnvVar: "DIGITALOCEAN_SSH_KEY_PATH", - Name: "digitalocean-ssh-key-path", - Usage: "SSH private key path ", - }, - mcnflag.IntFlag{ - EnvVar: "DIGITALOCEAN_SSH_PORT", - Name: "digitalocean-ssh-port", - Usage: "SSH port", - Value: defaultSSHPort, - }, - mcnflag.StringFlag{ - EnvVar: "DIGITALOCEAN_IMAGE", - Name: "digitalocean-image", - Usage: "Digital Ocean Image", - Value: defaultImage, - }, - mcnflag.StringFlag{ - EnvVar: "DIGITALOCEAN_REGION", - Name: "digitalocean-region", - Usage: "Digital Ocean region", - Value: defaultRegion, - }, - mcnflag.StringFlag{ - EnvVar: "DIGITALOCEAN_SIZE", - Name: "digitalocean-size", - Usage: "Digital Ocean size", - Value: defaultSize, - }, - mcnflag.BoolFlag{ - EnvVar: "DIGITALOCEAN_IPV6", - Name: "digitalocean-ipv6", - Usage: "enable ipv6 for droplet", - }, - mcnflag.BoolFlag{ - EnvVar: "DIGITALOCEAN_PRIVATE_NETWORKING", - Name: "digitalocean-private-networking", - Usage: "enable private networking for droplet", - }, - mcnflag.BoolFlag{ - EnvVar: "DIGITALOCEAN_BACKUPS", - Name: "digitalocean-backups", - Usage: "enable backups for droplet", - }, - mcnflag.StringFlag{ - EnvVar: "DIGITALOCEAN_USERDATA", - Name: "digitalocean-userdata", - Usage: "path to file with cloud-init user-data", - }, - mcnflag.StringFlag{ - EnvVar: "DIGITALOCEAN_TAGS", - Name: "digitalocean-tags", - Usage: "comma-separated list of tags to apply to the Droplet", - }, - } -} - -func NewDriver(hostName, storePath string) *Driver { - return &Driver{ - Image: defaultImage, - Size: defaultSize, - Region: defaultRegion, - BaseDriver: &drivers.BaseDriver{ - MachineName: hostName, - StorePath: storePath, - }, - } -} - -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "digitalocean" -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.AccessToken = flags.String("digitalocean-access-token") - d.Image = flags.String("digitalocean-image") - d.Region = flags.String("digitalocean-region") - d.Size = flags.String("digitalocean-size") - d.IPv6 = flags.Bool("digitalocean-ipv6") - d.PrivateNetworking = flags.Bool("digitalocean-private-networking") - d.Backups = flags.Bool("digitalocean-backups") - d.UserDataFile = flags.String("digitalocean-userdata") - d.SSHUser = flags.String("digitalocean-ssh-user") - d.SSHPort = flags.Int("digitalocean-ssh-port") - d.SSHKeyFingerprint = flags.String("digitalocean-ssh-key-fingerprint") - d.SSHKey = flags.String("digitalocean-ssh-key-path") - d.Tags = flags.String("digitalocean-tags") - - d.SetSwarmConfigFromFlags(flags) - - if d.AccessToken == "" { - return fmt.Errorf("digitalocean driver requires the --digitalocean-access-token option") - } - - return nil -} - -func (d *Driver) PreCreateCheck() error { - if d.UserDataFile != "" { - if _, err := os.Stat(d.UserDataFile); os.IsNotExist(err) { - return fmt.Errorf("user-data file %s could not be found", d.UserDataFile) - } - } - - if d.SSHKey != "" { - if d.SSHKeyFingerprint == "" { - return fmt.Errorf("ssh-key-fingerprint needs to be provided for %q", d.SSHKey) - } - - if _, err := os.Stat(d.SSHKey); os.IsNotExist(err) { - return fmt.Errorf("SSH key does not exist: %q", d.SSHKey) - } - } - - client := d.getClient() - regions, _, err := client.Regions.List(context.TODO(), nil) - if err != nil { - return err - } - for _, region := range regions { - if region.Slug == d.Region { - return nil - } - } - - return fmt.Errorf("digitalocean requires a valid region") -} - -func (d *Driver) Create() error { - var userdata string - if d.UserDataFile != "" { - buf, err := ioutil.ReadFile(d.UserDataFile) - if err != nil { - return err - } - userdata = string(buf) - } - - log.Infof("Creating SSH key...") - - key, err := d.createSSHKey() - if err != nil { - return err - } - - d.SSHKeyID = key.ID - - log.Infof("Creating Digital Ocean droplet...") - - client := d.getClient() - - createRequest := &godo.DropletCreateRequest{ - Image: godo.DropletCreateImage{Slug: d.Image}, - Name: d.MachineName, - Region: d.Region, - Size: d.Size, - IPv6: d.IPv6, - PrivateNetworking: d.PrivateNetworking, - Backups: d.Backups, - UserData: userdata, - SSHKeys: []godo.DropletCreateSSHKey{{ID: d.SSHKeyID}}, - Tags: d.getTags(), - } - - newDroplet, _, err := client.Droplets.Create(context.TODO(), createRequest) - if err != nil { - return err - } - - d.DropletID = newDroplet.ID - - log.Info("Waiting for IP address to be assigned to the Droplet...") - for { - newDroplet, _, err = client.Droplets.Get(context.TODO(), d.DropletID) - if err != nil { - return err - } - for _, network := range newDroplet.Networks.V4 { - if network.Type == "public" { - d.IPAddress = network.IPAddress - } - } - - if d.IPAddress != "" { - break - } - - time.Sleep(1 * time.Second) - } - - log.Debugf("Created droplet ID %d, IP address %s", - newDroplet.ID, - d.IPAddress) - - return nil -} - -func (d *Driver) createSSHKey() (*godo.Key, error) { - d.SSHKeyPath = d.GetSSHKeyPath() - - if d.SSHKeyFingerprint != "" { - key, resp, err := d.getClient().Keys.GetByFingerprint(context.TODO(), d.SSHKeyFingerprint) - if err != nil && resp.StatusCode == 404 { - return nil, fmt.Errorf("Digital Ocean SSH key with fingerprint %s doesn't exist", d.SSHKeyFingerprint) - } - - if d.SSHKey == "" { - log.Infof("Assuming Digital Ocean private SSH is located at ~/.ssh/id_rsa") - return key, nil - } - - if err := copySSHKey(d.SSHKey, d.SSHKeyPath); err != nil { - return nil, err - } - return key, nil - } - - if err := ssh.GenerateSSHKey(d.SSHKeyPath); err != nil { - return nil, err - } - - publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath()) - if err != nil { - return nil, err - } - - createRequest := &godo.KeyCreateRequest{ - Name: d.MachineName, - PublicKey: string(publicKey), - } - - key, _, err := d.getClient().Keys.Create(context.TODO(), createRequest) - if err != nil { - return key, err - } - - return key, nil -} - -func (d *Driver) GetURL() (string, error) { - if err := drivers.MustBeRunning(d); err != nil { - return "", err - } - - ip, err := d.GetIP() - if err != nil { - return "", err - } - - return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, "2376")), nil -} - -func (d *Driver) GetState() (state.State, error) { - droplet, _, err := d.getClient().Droplets.Get(context.TODO(), d.DropletID) - if err != nil { - return state.Error, err - } - switch droplet.Status { - case "new": - return state.Starting, nil - case "active": - return state.Running, nil - case "off": - return state.Stopped, nil - } - return state.None, nil -} - -func (d *Driver) Start() error { - _, _, err := d.getClient().DropletActions.PowerOn(context.TODO(), d.DropletID) - return err -} - -func (d *Driver) Stop() error { - _, _, err := d.getClient().DropletActions.Shutdown(context.TODO(), d.DropletID) - return err -} - -func (d *Driver) Restart() error { - _, _, err := d.getClient().DropletActions.Reboot(context.TODO(), d.DropletID) - return err -} - -func (d *Driver) Kill() error { - _, _, err := d.getClient().DropletActions.PowerOff(context.TODO(), d.DropletID) - return err -} - -func (d *Driver) Remove() error { - client := d.getClient() - if d.SSHKeyFingerprint == "" { - if resp, err := client.Keys.DeleteByID(context.TODO(), d.SSHKeyID); err != nil { - if resp.StatusCode == 404 { - log.Infof("Digital Ocean SSH key doesn't exist, assuming it is already deleted") - } else { - return err - } - } - } - if resp, err := client.Droplets.Delete(context.TODO(), d.DropletID); err != nil { - if resp.StatusCode == 404 { - log.Infof("Digital Ocean droplet doesn't exist, assuming it is already deleted") - } else { - return err - } - } - return nil -} - -func (d *Driver) getClient() *godo.Client { - token := &oauth2.Token{AccessToken: d.AccessToken} - tokenSource := oauth2.StaticTokenSource(token) - client := oauth2.NewClient(oauth2.NoContext, tokenSource) - - return godo.NewClient(client) -} - -func (d *Driver) getTags() []string { - var tagList []string - - for _, t := range strings.Split(d.Tags, ",") { - t = strings.TrimSpace(t) - if t != "" { - tagList = append(tagList, t) - } - } - - return tagList -} - -func (d *Driver) GetSSHKeyPath() string { - if d.SSHKey != "" { - d.SSHKeyPath = d.ResolveStorePath(path.Base(d.SSHKey)) - } else if d.SSHKeyPath == "" && d.SSHKeyFingerprint == "" { - d.SSHKeyPath = d.ResolveStorePath("id_rsa") - } - return d.SSHKeyPath -} - -func (d *Driver) publicSSHKeyPath() string { - return d.GetSSHKeyPath() + ".pub" -} - -func copySSHKey(src, dst string) error { - if err := mcnutils.CopyFile(src, dst); err != nil { - return fmt.Errorf("unable to copy ssh key: %s", err) - } - - if err := os.Chmod(dst, 0600); err != nil { - return fmt.Errorf("unable to set permissions on the ssh key: %s", err) - } - - return nil -} diff --git a/vendor/github.com/docker/machine/drivers/digitalocean/digitalocean_test.go b/vendor/github.com/docker/machine/drivers/digitalocean/digitalocean_test.go deleted file mode 100644 index 4cb1337..0000000 --- a/vendor/github.com/docker/machine/drivers/digitalocean/digitalocean_test.go +++ /dev/null @@ -1,115 +0,0 @@ -package digitalocean - -import ( - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -func TestSetConfigFromFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "digitalocean-access-token": "TOKEN", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) - - assert.Equal(t, driver.ResolveStorePath("id_rsa"), driver.GetSSHKeyPath()) -} - -func TestDefaultSSHUserAndPort(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "digitalocean-access-token": "TOKEN", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - assert.NoError(t, err) - - sshPort, err := driver.GetSSHPort() - assert.Equal(t, "root", driver.GetSSHUsername()) - assert.Equal(t, 22, sshPort) - assert.NoError(t, err) -} - -func TestCustomSSHUserAndPort(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "digitalocean-access-token": "TOKEN", - "digitalocean-ssh-user": "user", - "digitalocean-ssh-port": 2222, - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - assert.NoError(t, err) - - sshPort, err := driver.GetSSHPort() - assert.Equal(t, "user", driver.GetSSHUsername()) - assert.Equal(t, 2222, sshPort) - assert.NoError(t, err) -} - -func TestSSHKeyFingerprint(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "digitalocean-access-token": "TOKEN", - "digitalocean-ssh-key-fingerprint": "64:51:2b:9b:8b:f0:95:3c:f9:36:4d:8b:80:a8:8f:1e", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - assert.NoError(t, err) - - assert.Equal(t, "64:51:2b:9b:8b:f0:95:3c:f9:36:4d:8b:80:a8:8f:1e", driver.SSHKeyFingerprint) - assert.Equal(t, "", driver.GetSSHKeyPath()) -} - -func TestTags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "digitalocean-access-token": "TOKEN", - "digitalocean-tags": "docker,swarm, no-leading-space,,", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - assert.NoError(t, err) - assert.Equal(t, []string{"docker", "swarm", "no-leading-space"}, driver.getTags()) -} - -func TestTagsEmpty(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "digitalocean-access-token": "TOKEN", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - assert.NoError(t, err) - assert.Nil(t, driver.getTags()) -} diff --git a/vendor/github.com/docker/machine/drivers/driverutil/util.go b/vendor/github.com/docker/machine/drivers/driverutil/util.go deleted file mode 100644 index a75bc85..0000000 --- a/vendor/github.com/docker/machine/drivers/driverutil/util.go +++ /dev/null @@ -1,13 +0,0 @@ -package driverutil - -import "strings" - -// SplitPortProto splits a string in the format port/protocol, defaulting -// protocol to "tcp" if not provided. -func SplitPortProto(raw string) (port string, protocol string) { - parts := strings.SplitN(raw, "/", 2) - if len(parts) == 1 { - return parts[0], "tcp" - } - return parts[0], parts[1] -} diff --git a/vendor/github.com/docker/machine/drivers/driverutil/util_test.go b/vendor/github.com/docker/machine/drivers/driverutil/util_test.go deleted file mode 100644 index f442cc4..0000000 --- a/vendor/github.com/docker/machine/drivers/driverutil/util_test.go +++ /dev/null @@ -1,25 +0,0 @@ -package driverutil - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestSplitPortProtocol(t *testing.T) { - tests := []struct { - raw string - expectedPort string - expectedProto string - }{ - {"8080/tcp", "8080", "tcp"}, - {"90/udp", "90", "udp"}, - {"80", "80", "tcp"}, - } - - for _, tc := range tests { - port, proto := SplitPortProto(tc.raw) - assert.Equal(t, tc.expectedPort, port) - assert.Equal(t, tc.expectedProto, proto) - } -} diff --git a/vendor/github.com/docker/machine/drivers/errdriver/error.go b/vendor/github.com/docker/machine/drivers/errdriver/error.go deleted file mode 100644 index 5322037..0000000 --- a/vendor/github.com/docker/machine/drivers/errdriver/error.go +++ /dev/null @@ -1,104 +0,0 @@ -package errdriver - -import ( - "fmt" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/state" -) - -type Driver struct { - Name string -} - -type NotLoadable struct { - Name string -} - -func (e NotLoadable) Error() string { - return fmt.Sprintf("Driver %q not found. Do you have the plugin binary accessible in your PATH?", e.Name) -} - -func NewDriver(Name string) drivers.Driver { - return &Driver{ - Name: Name, - } -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "not-found" -} - -func (d *Driver) PreCreateCheck() error { - return NotLoadable{d.Name} -} - -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return nil -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - return NotLoadable{d.Name} -} - -func (d *Driver) GetURL() (string, error) { - return "", NotLoadable{d.Name} -} - -func (d *Driver) GetMachineName() string { - return d.Name -} - -func (d *Driver) GetIP() (string, error) { - return "1.2.3.4", NotLoadable{d.Name} -} - -func (d *Driver) GetSSHHostname() (string, error) { - return "", NotLoadable{d.Name} -} - -func (d *Driver) GetSSHKeyPath() string { - return "" -} - -func (d *Driver) GetSSHPort() (int, error) { - return 0, NotLoadable{d.Name} -} - -func (d *Driver) GetSSHUsername() string { - return "" -} - -func (d *Driver) GetState() (state.State, error) { - return state.Error, NotLoadable{d.Name} -} - -func (d *Driver) Create() error { - return NotLoadable{d.Name} -} - -func (d *Driver) Remove() error { - return NotLoadable{d.Name} -} - -func (d *Driver) Start() error { - return NotLoadable{d.Name} -} - -func (d *Driver) Stop() error { - return NotLoadable{d.Name} -} - -func (d *Driver) Restart() error { - return NotLoadable{d.Name} -} - -func (d *Driver) Kill() error { - return NotLoadable{d.Name} -} - -func (d *Driver) Upgrade() error { - return NotLoadable{d.Name} -} diff --git a/vendor/github.com/docker/machine/drivers/exoscale/exoscale.go b/vendor/github.com/docker/machine/drivers/exoscale/exoscale.go deleted file mode 100644 index f5e470e..0000000 --- a/vendor/github.com/docker/machine/drivers/exoscale/exoscale.go +++ /dev/null @@ -1,514 +0,0 @@ -package exoscale - -import ( - "errors" - "fmt" - "io/ioutil" - "net" - "os" - "strings" - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/state" - "github.com/exoscale/egoscale" -) - -type Driver struct { - *drivers.BaseDriver - URL string - APIKey string `json:"ApiKey"` - APISecretKey string `json:"ApiSecretKey"` - InstanceProfile string - DiskSize int - Image string - SecurityGroup string - AffinityGroup string - AvailabilityZone string - KeyPair string - PublicKey string - UserDataFile string - ID string `json:"Id"` -} - -const ( - defaultInstanceProfile = "small" - defaultDiskSize = 50 - defaultImage = "ubuntu-16.04" - defaultAvailabilityZone = "ch-dk-2" - defaultSSHUser = "ubuntu" -) - -// GetCreateFlags registers the flags this driver adds to -// "docker hosts create" -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - EnvVar: "EXOSCALE_ENDPOINT", - Name: "exoscale-url", - Usage: "exoscale API endpoint", - }, - mcnflag.StringFlag{ - EnvVar: "EXOSCALE_API_KEY", - Name: "exoscale-api-key", - Usage: "exoscale API key", - }, - mcnflag.StringFlag{ - EnvVar: "EXOSCALE_API_SECRET", - Name: "exoscale-api-secret-key", - Usage: "exoscale API secret key", - }, - mcnflag.StringFlag{ - EnvVar: "EXOSCALE_INSTANCE_PROFILE", - Name: "exoscale-instance-profile", - Value: defaultInstanceProfile, - Usage: "exoscale instance profile (small, medium, large, ...)", - }, - mcnflag.IntFlag{ - EnvVar: "EXOSCALE_DISK_SIZE", - Name: "exoscale-disk-size", - Value: defaultDiskSize, - Usage: "exoscale disk size (10, 50, 100, 200, 400)", - }, - mcnflag.StringFlag{ - EnvVar: "EXSOCALE_IMAGE", - Name: "exoscale-image", - Value: defaultImage, - Usage: "exoscale image template", - }, - mcnflag.StringSliceFlag{ - EnvVar: "EXOSCALE_SECURITY_GROUP", - Name: "exoscale-security-group", - Value: []string{}, - Usage: "exoscale security group", - }, - mcnflag.StringFlag{ - EnvVar: "EXOSCALE_AVAILABILITY_ZONE", - Name: "exoscale-availability-zone", - Value: defaultAvailabilityZone, - Usage: "exoscale availability zone", - }, - mcnflag.StringFlag{ - EnvVar: "EXOSCALE_SSH_USER", - Name: "exoscale-ssh-user", - Value: defaultSSHUser, - Usage: "Set the name of the ssh user", - }, - mcnflag.StringFlag{ - EnvVar: "EXOSCALE_USERDATA", - Name: "exoscale-userdata", - Usage: "path to file with cloud-init user-data", - }, - mcnflag.StringSliceFlag{ - EnvVar: "EXOSCALE_AFFINITY_GROUP", - Name: "exoscale-affinity-group", - Value: []string{}, - Usage: "exoscale affinity group", - }, - } -} - -func NewDriver(hostName, storePath string) drivers.Driver { - return &Driver{ - InstanceProfile: defaultInstanceProfile, - DiskSize: defaultDiskSize, - Image: defaultImage, - AvailabilityZone: defaultAvailabilityZone, - BaseDriver: &drivers.BaseDriver{ - MachineName: hostName, - StorePath: storePath, - }, - } -} - -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -func (d *Driver) GetSSHUsername() string { - if d.SSHUser == "" { - d.SSHUser = defaultSSHUser - } - - return d.SSHUser -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "exoscale" -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.URL = flags.String("exoscale-url") - d.APIKey = flags.String("exoscale-api-key") - d.APISecretKey = flags.String("exoscale-api-secret-key") - d.InstanceProfile = flags.String("exoscale-instance-profile") - d.DiskSize = flags.Int("exoscale-disk-size") - d.Image = flags.String("exoscale-image") - securityGroups := flags.StringSlice("exoscale-security-group") - if len(securityGroups) == 0 { - securityGroups = []string{"docker-machine"} - } - d.SecurityGroup = strings.Join(securityGroups, ",") - affinityGroups := flags.StringSlice("exoscale-affinity-group") - if len(affinityGroups) > 0 { - d.AffinityGroup = strings.Join(affinityGroups, ",") - } - d.AvailabilityZone = flags.String("exoscale-availability-zone") - d.SSHUser = flags.String("exoscale-ssh-user") - d.UserDataFile = flags.String("exoscale-userdata") - d.SetSwarmConfigFromFlags(flags) - - if d.URL == "" { - d.URL = "https://api.exoscale.ch/compute" - } - if d.APIKey == "" || d.APISecretKey == "" { - return errors.New("missing an API key (--exoscale-api-key) or API secret key (--exoscale-api-secret-key)") - } - - return nil -} - -func (d *Driver) PreCreateCheck() error { - if d.UserDataFile != "" { - if _, err := os.Stat(d.UserDataFile); os.IsNotExist(err) { - return fmt.Errorf("user-data file %s could not be found", d.UserDataFile) - } - } - - return nil -} - -func (d *Driver) GetURL() (string, error) { - if err := drivers.MustBeRunning(d); err != nil { - return "", err - } - - ip, err := d.GetIP() - if err != nil { - return "", err - } - - return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, "2376")), nil -} - -func (d *Driver) GetState() (state.State, error) { - client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey) - vm, err := client.GetVirtualMachine(d.ID) - if err != nil { - return state.Error, err - } - switch vm.State { - case "Starting": - return state.Starting, nil - case "Running": - return state.Running, nil - case "Stopping": - return state.Running, nil - case "Stopped": - return state.Stopped, nil - case "Destroyed": - return state.Stopped, nil - case "Expunging": - return state.Stopped, nil - case "Migrating": - return state.Paused, nil - case "Error": - return state.Error, nil - case "Unknown": - return state.Error, nil - case "Shutdowned": - return state.Stopped, nil - } - return state.None, nil -} - -func (d *Driver) createDefaultSecurityGroup(client *egoscale.Client, group string) (string, error) { - rules := []egoscale.SecurityGroupRule{ - { - SecurityGroupId: "", - Cidr: "0.0.0.0/0", - Protocol: "TCP", - Port: 22, - }, - { - SecurityGroupId: "", - Cidr: "0.0.0.0/0", - Protocol: "TCP", - Port: 2376, - }, - { - SecurityGroupId: "", - Cidr: "0.0.0.0/0", - Protocol: "TCP", - Port: 3376, - }, - { - SecurityGroupId: "", - Cidr: "0.0.0.0/0", - Protocol: "ICMP", - IcmpType: 8, - IcmpCode: 0, - }, - } - sgresp, err := client.CreateSecurityGroupWithRules( - group, - rules, - make([]egoscale.SecurityGroupRule, 0, 0)) - if err != nil { - return "", err - } - sg := sgresp.Id - return sg, nil -} - -func (d *Driver) createDefaultAffinityGroup(client *egoscale.Client, group string) (string, error) { - jobid, err := client.CreateAffinityGroup(group) - if err != nil { - return "", err - } - var resp *egoscale.QueryAsyncJobResultResponse - for i := 0; i <= 10; i++ { - resp, err = client.PollAsyncJob(jobid) - if err != nil { - fmt.Printf("got error: %+v\n", err) - } - - if resp.Jobstatus == 1 { - break - } - time.Sleep(5 * time.Second) - } - affinitygroups, err := client.GetAffinityGroups() - agid := affinitygroups[group] - return agid, nil -} - -func (d *Driver) Create() error { - userdata, err := d.getCloudInit() - if err != nil { - return err - } - - log.Infof("Querying exoscale for the requested parameters...") - client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey) - topology, err := client.GetTopology() - if err != nil { - return err - } - - // Availability zone UUID - zone, ok := topology.Zones[d.AvailabilityZone] - if !ok { - return fmt.Errorf("Availability zone %v doesn't exist", - d.AvailabilityZone) - } - log.Debugf("Availability zone %v = %s", d.AvailabilityZone, zone) - - // Image UUID - var tpl string - images, ok := topology.Images[strings.ToLower(d.Image)] - if ok { - tpl, ok = images[d.DiskSize] - } - if !ok { - return fmt.Errorf("Unable to find image %v with size %d", - d.Image, d.DiskSize) - } - log.Debugf("Image %v(%d) = %s", d.Image, d.DiskSize, tpl) - - // Profile UUID - profile, ok := topology.Profiles[strings.ToLower(d.InstanceProfile)] - if !ok { - return fmt.Errorf("Unable to find the %s profile", - d.InstanceProfile) - } - log.Debugf("Profile %v = %s", d.InstanceProfile, profile) - - // Security groups - securityGroups := strings.Split(d.SecurityGroup, ",") - sgs := make([]string, len(securityGroups)) - for idx, group := range securityGroups { - sg, ok := topology.SecurityGroups[group] - if !ok { - log.Infof("Security group %v does not exist, create it", - group) - sg, err = d.createDefaultSecurityGroup(client, group) - if err != nil { - return err - } - } - log.Debugf("Security group %v = %s", group, sg) - sgs[idx] = sg - } - - // Affinity Groups - affinityGroups := strings.Split(d.AffinityGroup, ",") - ags := make([]string, len(affinityGroups)) - for idx, group := range affinityGroups { - ag, ok := topology.AffinityGroups[group] - if !ok { - log.Infof("Affinity Group %v does not exist, create it", - group) - ag, err = d.createDefaultAffinityGroup(client, group) - if err != nil { - return err - } - } - log.Debugf("Affinity group %v = %s", group, ag) - ags[idx] = group - } - - log.Infof("Generate an SSH keypair...") - keypairName := fmt.Sprintf("docker-machine-%s", d.MachineName) - kpresp, err := client.CreateKeypair(keypairName) - if err != nil { - return err - } - err = ioutil.WriteFile(d.GetSSHKeyPath(), []byte(kpresp.Privatekey), 0600) - if err != nil { - return err - } - d.KeyPair = keypairName - - log.Infof("Spawn exoscale host...") - log.Debugf("Using the following cloud-init file:") - log.Debugf("%s", userdata) - - machineProfile := egoscale.MachineProfile{ - Template: tpl, - ServiceOffering: profile, - SecurityGroups: sgs, - Userdata: userdata, - Zone: zone, - Keypair: d.KeyPair, - Name: d.MachineName, - AffinityGroups: ags, - } - - cvmresp, err := client.CreateVirtualMachine(machineProfile) - if err != nil { - return err - } - - vm, err := d.waitForVM(client, cvmresp) - if err != nil { - return err - } - d.IPAddress = vm.Nic[0].Ipaddress - d.ID = vm.Id - - return nil -} - -func (d *Driver) Start() error { - client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey) - - svmresp, err := client.StartVirtualMachine(d.ID) - if err != nil { - return err - } - - return d.waitForJob(client, svmresp) -} - -func (d *Driver) Stop() error { - client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey) - - svmresp, err := client.StopVirtualMachine(d.ID) - if err != nil { - return err - } - - return d.waitForJob(client, svmresp) -} - -func (d *Driver) Restart() error { - client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey) - - svmresp, err := client.RebootVirtualMachine(d.ID) - if err != nil { - return err - } - - return d.waitForJob(client, svmresp) -} - -func (d *Driver) Kill() error { - return d.Stop() -} - -func (d *Driver) Remove() error { - client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey) - - // Destroy the SSH key - if _, err := client.DeleteKeypair(d.KeyPair); err != nil { - return err - } - - // Destroy the virtual machine - dvmresp, err := client.DestroyVirtualMachine(d.ID) - if err != nil { - return err - } - err = d.waitForJob(client, dvmresp) - return err -} - -func (d *Driver) jobIsDone(client *egoscale.Client, jobid string) (bool, error) { - resp, err := client.PollAsyncJob(jobid) - if err != nil { - return true, err - } - switch resp.Jobstatus { - case 0: // Job is still in progress - case 1: // Job has successfully completed - return true, nil - case 2: // Job has failed to complete - return true, fmt.Errorf("Operation failed to complete") - default: // Some other code - } - return false, nil -} - -func (d *Driver) waitForJob(client *egoscale.Client, jobid string) error { - log.Infof("Waiting for job to complete...") - return mcnutils.WaitForSpecificOrError(func() (bool, error) { - return d.jobIsDone(client, jobid) - }, 60, 2*time.Second) -} - -func (d *Driver) waitForVM(client *egoscale.Client, jobid string) (*egoscale.DeployVirtualMachineResponse, error) { - if err := d.waitForJob(client, jobid); err != nil { - return nil, err - } - resp, err := client.PollAsyncJob(jobid) - if err != nil { - return nil, err - } - vm, err := client.AsyncToVirtualMachine(*resp) - if err != nil { - return nil, err - } - - return vm, nil -} - -// Build a cloud-init user data string that will install and run -// docker. -func (d *Driver) getCloudInit() (string, error) { - if d.UserDataFile != "" { - buf, err := ioutil.ReadFile(d.UserDataFile) - if err != nil { - return "", err - } - return string(buf), nil - } - - return `#cloud-config -manage_etc_hosts: localhost -`, nil -} diff --git a/vendor/github.com/docker/machine/drivers/exoscale/exoscale_test.go b/vendor/github.com/docker/machine/drivers/exoscale/exoscale_test.go deleted file mode 100644 index 0638f3c..0000000 --- a/vendor/github.com/docker/machine/drivers/exoscale/exoscale_test.go +++ /dev/null @@ -1,25 +0,0 @@ -package exoscale - -import ( - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -func TestSetConfigFromFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "exoscale-api-key": "API_KEY", - "exoscale-api-secret-key": "API_SECRET_KEY", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) -} diff --git a/vendor/github.com/docker/machine/drivers/fakedriver/fakedriver.go b/vendor/github.com/docker/machine/drivers/fakedriver/fakedriver.go deleted file mode 100644 index 953db88..0000000 --- a/vendor/github.com/docker/machine/drivers/fakedriver/fakedriver.go +++ /dev/null @@ -1,109 +0,0 @@ -package fakedriver - -import ( - "fmt" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/state" -) - -type Driver struct { - *drivers.BaseDriver - MockState state.State - MockIP string - MockName string -} - -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{} -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "Driver" -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - return nil -} - -func (d *Driver) GetURL() (string, error) { - ip, err := d.GetIP() - if err != nil { - return "", err - } - if ip == "" { - return "", nil - } - return fmt.Sprintf("tcp://%s:2376", ip), nil -} - -func (d *Driver) GetMachineName() string { - return d.MockName -} - -func (d *Driver) GetIP() (string, error) { - if d.MockState == state.Error { - return "", fmt.Errorf("Unable to get ip") - } - if d.MockState == state.Timeout { - select {} // Loop forever - } - if d.MockState != state.Running { - return "", drivers.ErrHostIsNotRunning - } - return d.MockIP, nil -} - -func (d *Driver) GetSSHHostname() (string, error) { - return "", nil -} - -func (d *Driver) GetSSHKeyPath() string { - return "" -} - -func (d *Driver) GetSSHPort() (int, error) { - return 0, nil -} - -func (d *Driver) GetSSHUsername() string { - return "" -} - -func (d *Driver) GetState() (state.State, error) { - return d.MockState, nil -} - -func (d *Driver) Create() error { - return nil -} - -func (d *Driver) Start() error { - d.MockState = state.Running - return nil -} - -func (d *Driver) Stop() error { - d.MockState = state.Stopped - return nil -} - -func (d *Driver) Restart() error { - d.MockState = state.Running - return nil -} - -func (d *Driver) Kill() error { - d.MockState = state.Stopped - return nil -} - -func (d *Driver) Remove() error { - return nil -} - -func (d *Driver) Upgrade() error { - return nil -} diff --git a/vendor/github.com/docker/machine/drivers/generic/generic.go b/vendor/github.com/docker/machine/drivers/generic/generic.go deleted file mode 100644 index f51f3bf..0000000 --- a/vendor/github.com/docker/machine/drivers/generic/generic.go +++ /dev/null @@ -1,196 +0,0 @@ -package generic - -import ( - "errors" - "fmt" - "net" - "os" - "path" - "strconv" - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/state" -) - -type Driver struct { - *drivers.BaseDriver - EnginePort int - SSHKey string -} - -const ( - defaultTimeout = 15 * time.Second -) - -// GetCreateFlags registers the flags this driver adds to -// "docker hosts create" -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.IntFlag{ - Name: "generic-engine-port", - Usage: "Docker engine port", - Value: engine.DefaultPort, - EnvVar: "GENERIC_ENGINE_PORT", - }, - mcnflag.StringFlag{ - Name: "generic-ip-address", - Usage: "IP Address of machine", - EnvVar: "GENERIC_IP_ADDRESS", - }, - mcnflag.StringFlag{ - Name: "generic-ssh-user", - Usage: "SSH user", - Value: drivers.DefaultSSHUser, - EnvVar: "GENERIC_SSH_USER", - }, - mcnflag.StringFlag{ - Name: "generic-ssh-key", - Usage: "SSH private key path (if not provided, default SSH key will be used)", - Value: "", - EnvVar: "GENERIC_SSH_KEY", - }, - mcnflag.IntFlag{ - Name: "generic-ssh-port", - Usage: "SSH port", - Value: drivers.DefaultSSHPort, - EnvVar: "GENERIC_SSH_PORT", - }, - } -} - -// NewDriver creates and returns a new instance of the driver -func NewDriver(hostName, storePath string) drivers.Driver { - return &Driver{ - EnginePort: engine.DefaultPort, - BaseDriver: &drivers.BaseDriver{ - MachineName: hostName, - StorePath: storePath, - }, - } -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "generic" -} - -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -func (d *Driver) GetSSHUsername() string { - return d.SSHUser -} - -func (d *Driver) GetSSHKeyPath() string { - return d.SSHKeyPath -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.EnginePort = flags.Int("generic-engine-port") - d.IPAddress = flags.String("generic-ip-address") - d.SSHUser = flags.String("generic-ssh-user") - d.SSHKey = flags.String("generic-ssh-key") - d.SSHPort = flags.Int("generic-ssh-port") - - if d.IPAddress == "" { - return errors.New("generic driver requires the --generic-ip-address option") - } - - return nil -} - -func (d *Driver) PreCreateCheck() error { - if d.SSHKey != "" { - if _, err := os.Stat(d.SSHKey); os.IsNotExist(err) { - return fmt.Errorf("SSH key does not exist: %q", d.SSHKey) - } - - // TODO: validate the key is a valid key - } - - return nil -} - -func (d *Driver) Create() error { - if d.SSHKey == "" { - log.Info("No SSH key specified. Assuming an existing key at the default location.") - } else { - log.Info("Importing SSH key...") - - d.SSHKeyPath = d.ResolveStorePath(path.Base(d.SSHKey)) - if err := copySSHKey(d.SSHKey, d.SSHKeyPath); err != nil { - return err - } - - if err := copySSHKey(d.SSHKey+".pub", d.SSHKeyPath+".pub"); err != nil { - log.Infof("Couldn't copy SSH public key : %s", err) - } - } - - log.Debugf("IP: %s", d.IPAddress) - - return nil -} - -func (d *Driver) GetURL() (string, error) { - if err := drivers.MustBeRunning(d); err != nil { - return "", err - } - - ip, err := d.GetIP() - if err != nil { - return "", err - } - - return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, strconv.Itoa(d.EnginePort))), nil -} - -func (d *Driver) GetState() (state.State, error) { - address := net.JoinHostPort(d.IPAddress, strconv.Itoa(d.SSHPort)) - - _, err := net.DialTimeout("tcp", address, defaultTimeout) - if err != nil { - return state.Stopped, nil - } - - return state.Running, nil -} - -func (d *Driver) Start() error { - return errors.New("generic driver does not support start") -} - -func (d *Driver) Stop() error { - return errors.New("generic driver does not support stop") -} - -func (d *Driver) Restart() error { - _, err := drivers.RunSSHCommandFromDriver(d, "sudo shutdown -r now") - return err -} - -func (d *Driver) Kill() error { - return errors.New("generic driver does not support kill") -} - -func (d *Driver) Remove() error { - return nil -} - -func copySSHKey(src, dst string) error { - if err := mcnutils.CopyFile(src, dst); err != nil { - return fmt.Errorf("unable to copy ssh key: %s", err) - } - - if err := os.Chmod(dst, 0600); err != nil { - return fmt.Errorf("unable to set permissions on the ssh key: %s", err) - } - - return nil -} diff --git a/vendor/github.com/docker/machine/drivers/generic/generic_test.go b/vendor/github.com/docker/machine/drivers/generic/generic_test.go deleted file mode 100644 index 93caa79..0000000 --- a/vendor/github.com/docker/machine/drivers/generic/generic_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package generic - -import ( - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -func TestSetConfigFromFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "generic-engine-port": "3000", - "generic-ip-address": "localhost", - "generic-ssh-key": "path", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) -} diff --git a/vendor/github.com/docker/machine/drivers/google/compute_util.go b/vendor/github.com/docker/machine/drivers/google/compute_util.go deleted file mode 100644 index 612c173..0000000 --- a/vendor/github.com/docker/machine/drivers/google/compute_util.go +++ /dev/null @@ -1,480 +0,0 @@ -package google - -import ( - "fmt" - "io/ioutil" - "net/url" - "regexp" - "strings" - "time" - - "github.com/docker/machine/drivers/driverutil" - "github.com/docker/machine/libmachine/log" - raw "google.golang.org/api/compute/v1" - - "errors" - - "golang.org/x/oauth2" - "golang.org/x/oauth2/google" - "google.golang.org/api/googleapi" -) - -// ComputeUtil is used to wrap the raw GCE API code and store common parameters. -type ComputeUtil struct { - zone string - instanceName string - userName string - project string - diskTypeURL string - address string - network string - subnetwork string - preemptible bool - useInternalIP bool - useInternalIPOnly bool - service *raw.Service - zoneURL string - globalURL string - SwarmMaster bool - SwarmHost string - openPorts []string -} - -const ( - apiURL = "https://www.googleapis.com/compute/v1/projects/" - firewallRule = "docker-machines" - dockerPort = "2376" - firewallTargetTag = "docker-machine" -) - -// NewComputeUtil creates and initializes a ComputeUtil. -func newComputeUtil(driver *Driver) (*ComputeUtil, error) { - client, err := google.DefaultClient(oauth2.NoContext, raw.ComputeScope) - if err != nil { - return nil, err - } - - service, err := raw.New(client) - if err != nil { - return nil, err - } - - return &ComputeUtil{ - zone: driver.Zone, - instanceName: driver.MachineName, - userName: driver.SSHUser, - project: driver.Project, - diskTypeURL: driver.DiskType, - address: driver.Address, - network: driver.Network, - subnetwork: driver.Subnetwork, - preemptible: driver.Preemptible, - useInternalIP: driver.UseInternalIP, - useInternalIPOnly: driver.UseInternalIPOnly, - service: service, - zoneURL: apiURL + driver.Project + "/zones/" + driver.Zone, - globalURL: apiURL + driver.Project + "/global", - SwarmMaster: driver.SwarmMaster, - SwarmHost: driver.SwarmHost, - openPorts: driver.OpenPorts, - }, nil -} - -func (c *ComputeUtil) diskName() string { - return c.instanceName + "-disk" -} - -func (c *ComputeUtil) diskType() string { - return apiURL + c.project + "/zones/" + c.zone + "/diskTypes/" + c.diskTypeURL -} - -// disk returns the persistent disk attached to the vm. -func (c *ComputeUtil) disk() (*raw.Disk, error) { - return c.service.Disks.Get(c.project, c.zone, c.diskName()).Do() -} - -// deleteDisk deletes the persistent disk. -func (c *ComputeUtil) deleteDisk() error { - disk, _ := c.disk() - if disk == nil { - return nil - } - - log.Infof("Deleting disk.") - op, err := c.service.Disks.Delete(c.project, c.zone, c.diskName()).Do() - if err != nil { - return err - } - - log.Infof("Waiting for disk to delete.") - return c.waitForRegionalOp(op.Name) -} - -// staticAddress returns the external static IP address. -func (c *ComputeUtil) staticAddress() (string, error) { - // is the address a name? - isName, err := regexp.MatchString("[a-z]([-a-z0-9]*[a-z0-9])?", c.address) - if err != nil { - return "", err - } - - if !isName { - return c.address, nil - } - - // resolve the address by name - externalAddress, err := c.service.Addresses.Get(c.project, c.region(), c.address).Do() - if err != nil { - return "", err - } - - return externalAddress.Address, nil -} - -func (c *ComputeUtil) region() string { - return c.zone[:len(c.zone)-2] -} - -func (c *ComputeUtil) firewallRule() (*raw.Firewall, error) { - return c.service.Firewalls.Get(c.project, firewallRule).Do() -} - -func missingOpenedPorts(rule *raw.Firewall, ports []string) map[string][]string { - missing := map[string][]string{} - opened := map[string]bool{} - - for _, allowed := range rule.Allowed { - for _, allowedPort := range allowed.Ports { - opened[allowedPort+"/"+allowed.IPProtocol] = true - } - } - - for _, p := range ports { - port, proto := driverutil.SplitPortProto(p) - if !opened[port+"/"+proto] { - missing[proto] = append(missing[proto], port) - } - } - - return missing -} - -func (c *ComputeUtil) portsUsed() ([]string, error) { - ports := []string{dockerPort + "/tcp"} - - if c.SwarmMaster { - u, err := url.Parse(c.SwarmHost) - if err != nil { - return nil, fmt.Errorf("error authorizing port for swarm: %s", err) - } - - swarmPort := strings.Split(u.Host, ":")[1] - ports = append(ports, swarmPort+"/tcp") - } - for _, p := range c.openPorts { - port, proto := driverutil.SplitPortProto(p) - ports = append(ports, port+"/"+proto) - } - - return ports, nil -} - -// openFirewallPorts configures the firewall to open docker and swarm ports. -func (c *ComputeUtil) openFirewallPorts(d *Driver) error { - log.Infof("Opening firewall ports") - - create := false - rule, _ := c.firewallRule() - if rule == nil { - create = true - rule = &raw.Firewall{ - Name: firewallRule, - Allowed: []*raw.FirewallAllowed{}, - SourceRanges: []string{"0.0.0.0/0"}, - TargetTags: []string{firewallTargetTag}, - Network: c.globalURL + "/networks/" + d.Network, - } - } - - portsUsed, err := c.portsUsed() - if err != nil { - return err - } - - missingPorts := missingOpenedPorts(rule, portsUsed) - if len(missingPorts) == 0 { - return nil - } - for proto, ports := range missingPorts { - rule.Allowed = append(rule.Allowed, &raw.FirewallAllowed{ - IPProtocol: proto, - Ports: ports, - }) - } - - var op *raw.Operation - if create { - op, err = c.service.Firewalls.Insert(c.project, rule).Do() - } else { - op, err = c.service.Firewalls.Update(c.project, firewallRule, rule).Do() - } - - if err != nil { - return err - } - - return c.waitForGlobalOp(op.Name) -} - -// instance retrieves the instance. -func (c *ComputeUtil) instance() (*raw.Instance, error) { - return c.service.Instances.Get(c.project, c.zone, c.instanceName).Do() -} - -// createInstance creates a GCE VM instance. -func (c *ComputeUtil) createInstance(d *Driver) error { - log.Infof("Creating instance") - - instance := &raw.Instance{ - Name: c.instanceName, - Description: "docker host vm", - MachineType: c.zoneURL + "/machineTypes/" + d.MachineType, - Disks: []*raw.AttachedDisk{ - { - Boot: true, - AutoDelete: false, - Type: "PERSISTENT", - Mode: "READ_WRITE", - }, - }, - NetworkInterfaces: []*raw.NetworkInterface{ - { - Network: c.globalURL + "/networks/" + d.Network, - }, - }, - Tags: &raw.Tags{ - Items: parseTags(d), - }, - ServiceAccounts: []*raw.ServiceAccount{ - { - Email: "default", - Scopes: strings.Split(d.Scopes, ","), - }, - }, - Scheduling: &raw.Scheduling{ - Preemptible: c.preemptible, - }, - } - - if c.subnetwork != "" { - instance.NetworkInterfaces[0].Subnetwork = "projects/" + c.project + "/regions/" + c.region() + "/subnetworks/" + c.subnetwork - } - - if !c.useInternalIPOnly { - cfg := &raw.AccessConfig{ - Type: "ONE_TO_ONE_NAT", - } - instance.NetworkInterfaces[0].AccessConfigs = append(instance.NetworkInterfaces[0].AccessConfigs, cfg) - } - - if c.address != "" { - staticAddress, err := c.staticAddress() - if err != nil { - return err - } - - instance.NetworkInterfaces[0].AccessConfigs[0].NatIP = staticAddress - } - - disk, err := c.disk() - if disk == nil || err != nil { - instance.Disks[0].InitializeParams = &raw.AttachedDiskInitializeParams{ - DiskName: c.diskName(), - SourceImage: "https://www.googleapis.com/compute/v1/projects/" + d.MachineImage, - // The maximum supported disk size is 1000GB, the cast should be fine. - DiskSizeGb: int64(d.DiskSize), - DiskType: c.diskType(), - } - } else { - instance.Disks[0].Source = c.zoneURL + "/disks/" + c.instanceName + "-disk" - } - op, err := c.service.Instances.Insert(c.project, c.zone, instance).Do() - - if err != nil { - return err - } - - log.Infof("Waiting for Instance") - if err = c.waitForRegionalOp(op.Name); err != nil { - return err - } - - instance, err = c.instance() - if err != nil { - return err - } - - return c.uploadSSHKey(instance, d.GetSSHKeyPath()) -} - -// configureInstance configures an existing instance for use with Docker Machine. -func (c *ComputeUtil) configureInstance(d *Driver) error { - log.Infof("Configuring instance") - - instance, err := c.instance() - if err != nil { - return err - } - - if err := c.addFirewallTag(instance); err != nil { - return err - } - - return c.uploadSSHKey(instance, d.GetSSHKeyPath()) -} - -// addFirewallTag adds a tag to the instance to match the firewall rule. -func (c *ComputeUtil) addFirewallTag(instance *raw.Instance) error { - log.Infof("Adding tag for the firewall rule") - - tags := instance.Tags - for _, tag := range tags.Items { - if tag == firewallTargetTag { - return nil - } - } - - tags.Items = append(tags.Items, firewallTargetTag) - - op, err := c.service.Instances.SetTags(c.project, c.zone, instance.Name, tags).Do() - if err != nil { - return err - } - - return c.waitForRegionalOp(op.Name) -} - -// uploadSSHKey updates the instance metadata with the given ssh key. -func (c *ComputeUtil) uploadSSHKey(instance *raw.Instance, sshKeyPath string) error { - log.Infof("Uploading SSH Key") - - sshKey, err := ioutil.ReadFile(sshKeyPath + ".pub") - if err != nil { - return err - } - - metaDataValue := fmt.Sprintf("%s:%s %s\n", c.userName, strings.TrimSpace(string(sshKey)), c.userName) - - op, err := c.service.Instances.SetMetadata(c.project, c.zone, c.instanceName, &raw.Metadata{ - Fingerprint: instance.Metadata.Fingerprint, - Items: []*raw.MetadataItems{ - { - Key: "sshKeys", - Value: &metaDataValue, - }, - }, - }).Do() - - return c.waitForRegionalOp(op.Name) -} - -// parseTags computes the tags for the instance. -func parseTags(d *Driver) []string { - tags := []string{firewallTargetTag} - - if d.Tags != "" { - tags = append(tags, strings.Split(d.Tags, ",")...) - } - - return tags -} - -// deleteInstance deletes the instance, leaving the persistent disk. -func (c *ComputeUtil) deleteInstance() error { - log.Infof("Deleting instance.") - op, err := c.service.Instances.Delete(c.project, c.zone, c.instanceName).Do() - if err != nil { - return err - } - - log.Infof("Waiting for instance to delete.") - return c.waitForRegionalOp(op.Name) -} - -// stopInstance stops the instance. -func (c *ComputeUtil) stopInstance() error { - op, err := c.service.Instances.Stop(c.project, c.zone, c.instanceName).Do() - if err != nil { - return err - } - - log.Infof("Waiting for instance to stop.") - return c.waitForRegionalOp(op.Name) -} - -// startInstance starts the instance. -func (c *ComputeUtil) startInstance() error { - op, err := c.service.Instances.Start(c.project, c.zone, c.instanceName).Do() - if err != nil { - return err - } - - log.Infof("Waiting for instance to start.") - return c.waitForRegionalOp(op.Name) -} - -// waitForOp waits for the operation to finish. -func (c *ComputeUtil) waitForOp(opGetter func() (*raw.Operation, error)) error { - for { - op, err := opGetter() - if err != nil { - return err - } - - log.Debugf("Operation %q status: %s", op.Name, op.Status) - if op.Status == "DONE" { - if op.Error != nil { - return fmt.Errorf("Operation error: %v", *op.Error.Errors[0]) - } - break - } - time.Sleep(1 * time.Second) - } - return nil -} - -// waitForRegionalOp waits for the regional operation to finish. -func (c *ComputeUtil) waitForRegionalOp(name string) error { - return c.waitForOp(func() (*raw.Operation, error) { - return c.service.ZoneOperations.Get(c.project, c.zone, name).Do() - }) -} - -// waitForGlobalOp waits for the global operation to finish. -func (c *ComputeUtil) waitForGlobalOp(name string) error { - return c.waitForOp(func() (*raw.Operation, error) { - return c.service.GlobalOperations.Get(c.project, name).Do() - }) -} - -// ip retrieves and returns the external IP address of the instance. -func (c *ComputeUtil) ip() (string, error) { - instance, err := c.service.Instances.Get(c.project, c.zone, c.instanceName).Do() - if err != nil { - return "", unwrapGoogleError(err) - } - - nic := instance.NetworkInterfaces[0] - if c.useInternalIP { - return nic.NetworkIP, nil - } - return nic.AccessConfigs[0].NatIP, nil -} - -func unwrapGoogleError(err error) error { - if googleErr, ok := err.(*googleapi.Error); ok { - return errors.New(googleErr.Message) - } - - return err -} diff --git a/vendor/github.com/docker/machine/drivers/google/compute_util_test.go b/vendor/github.com/docker/machine/drivers/google/compute_util_test.go deleted file mode 100644 index c90b257..0000000 --- a/vendor/github.com/docker/machine/drivers/google/compute_util_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package google - -import ( - "testing" - - "github.com/stretchr/testify/assert" - raw "google.golang.org/api/compute/v1" -) - -func TestDefaultTag(t *testing.T) { - tags := parseTags(&Driver{Tags: ""}) - - assert.Equal(t, []string{"docker-machine"}, tags) -} - -func TestAdditionalTag(t *testing.T) { - tags := parseTags(&Driver{Tags: "tag1"}) - - assert.Equal(t, []string{"docker-machine", "tag1"}, tags) -} - -func TestAdditionalTags(t *testing.T) { - tags := parseTags(&Driver{Tags: "tag1,tag2"}) - - assert.Equal(t, []string{"docker-machine", "tag1", "tag2"}, tags) -} - -func TestPortsUsed(t *testing.T) { - var tests = []struct { - description string - computeUtil *ComputeUtil - expectedPorts []string - expectedError error - }{ - {"use docker port", &ComputeUtil{}, []string{"2376/tcp"}, nil}, - {"use docker and swarm port", &ComputeUtil{SwarmMaster: true, SwarmHost: "tcp://host:3376"}, []string{"2376/tcp", "3376/tcp"}, nil}, - {"use docker and non default swarm port", &ComputeUtil{SwarmMaster: true, SwarmHost: "tcp://host:4242"}, []string{"2376/tcp", "4242/tcp"}, nil}, - {"include additional ports", &ComputeUtil{openPorts: []string{"80", "2377/udp"}}, []string{"2376/tcp", "80/tcp", "2377/udp"}, nil}, - } - - for _, test := range tests { - ports, err := test.computeUtil.portsUsed() - - assert.Equal(t, test.expectedPorts, ports) - assert.Equal(t, test.expectedError, err) - } -} - -func TestMissingOpenedPorts(t *testing.T) { - var tests = []struct { - description string - allowed []*raw.FirewallAllowed - ports []string - expectedMissing map[string][]string - }{ - {"no port opened", []*raw.FirewallAllowed{}, []string{"2376"}, map[string][]string{"tcp": {"2376"}}}, - {"docker port opened", []*raw.FirewallAllowed{{IPProtocol: "tcp", Ports: []string{"2376"}}}, []string{"2376"}, map[string][]string{}}, - {"missing swarm port", []*raw.FirewallAllowed{{IPProtocol: "tcp", Ports: []string{"2376"}}}, []string{"2376", "3376"}, map[string][]string{"tcp": {"3376"}}}, - {"missing docker port", []*raw.FirewallAllowed{{IPProtocol: "tcp", Ports: []string{"3376"}}}, []string{"2376", "3376"}, map[string][]string{"tcp": {"2376"}}}, - {"both ports opened", []*raw.FirewallAllowed{{IPProtocol: "tcp", Ports: []string{"2376", "3376"}}}, []string{"2376", "3376"}, map[string][]string{}}, - {"more ports opened", []*raw.FirewallAllowed{{IPProtocol: "tcp", Ports: []string{"2376", "3376", "22", "1024-2048"}}}, []string{"2376", "3376"}, map[string][]string{}}, - {"additional missing", []*raw.FirewallAllowed{{IPProtocol: "tcp", Ports: []string{"2376", "2377/tcp"}}}, []string{"2377/udp", "80/tcp", "2376"}, map[string][]string{"tcp": {"80"}, "udp": {"2377"}}}, - } - - for _, test := range tests { - firewall := &raw.Firewall{Allowed: test.allowed} - - missingPorts := missingOpenedPorts(firewall, test.ports) - - assert.Equal(t, test.expectedMissing, missingPorts, test.description) - } -} diff --git a/vendor/github.com/docker/machine/drivers/google/google.go b/vendor/github.com/docker/machine/drivers/google/google.go deleted file mode 100644 index 9dc42ba..0000000 --- a/vendor/github.com/docker/machine/drivers/google/google.go +++ /dev/null @@ -1,414 +0,0 @@ -package google - -import ( - "errors" - "fmt" - "net" - "net/http" - "strings" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" - - "google.golang.org/api/googleapi" -) - -// Driver is a struct compatible with the docker.hosts.drivers.Driver interface. -type Driver struct { - *drivers.BaseDriver - Zone string - MachineType string - MachineImage string - DiskType string - Address string - Network string - Subnetwork string - Preemptible bool - UseInternalIP bool - UseInternalIPOnly bool - Scopes string - DiskSize int - Project string - Tags string - UseExisting bool - OpenPorts []string -} - -const ( - defaultZone = "us-central1-a" - defaultUser = "docker-user" - defaultMachineType = "n1-standard-1" - defaultImageName = "ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20170721" - defaultScopes = "https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write" - defaultDiskType = "pd-standard" - defaultDiskSize = 10 - defaultNetwork = "default" - defaultSubnetwork = "" -) - -// GetCreateFlags registers the flags this driver adds to -// "docker hosts create" -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - Name: "google-zone", - Usage: "GCE Zone", - Value: defaultZone, - EnvVar: "GOOGLE_ZONE", - }, - mcnflag.StringFlag{ - Name: "google-machine-type", - Usage: "GCE Machine Type", - Value: defaultMachineType, - EnvVar: "GOOGLE_MACHINE_TYPE", - }, - mcnflag.StringFlag{ - Name: "google-machine-image", - Usage: "GCE Machine Image Absolute URL", - Value: defaultImageName, - EnvVar: "GOOGLE_MACHINE_IMAGE", - }, - mcnflag.StringFlag{ - Name: "google-username", - Usage: "GCE User Name", - Value: defaultUser, - EnvVar: "GOOGLE_USERNAME", - }, - mcnflag.StringFlag{ - Name: "google-project", - Usage: "GCE Project", - EnvVar: "GOOGLE_PROJECT", - }, - mcnflag.StringFlag{ - Name: "google-scopes", - Usage: "GCE Scopes (comma-separated if multiple scopes)", - Value: defaultScopes, - EnvVar: "GOOGLE_SCOPES", - }, - mcnflag.IntFlag{ - Name: "google-disk-size", - Usage: "GCE Instance Disk Size (in GB)", - Value: defaultDiskSize, - EnvVar: "GOOGLE_DISK_SIZE", - }, - mcnflag.StringFlag{ - Name: "google-disk-type", - Usage: "GCE Instance Disk type", - Value: defaultDiskType, - EnvVar: "GOOGLE_DISK_TYPE", - }, - mcnflag.StringFlag{ - Name: "google-network", - Usage: "Specify network in which to provision vm", - Value: defaultNetwork, - EnvVar: "GOOGLE_NETWORK", - }, - mcnflag.StringFlag{ - Name: "google-subnetwork", - Usage: "Specify subnetwork in which to provision vm", - Value: defaultSubnetwork, - EnvVar: "GOOGLE_SUBNETWORK", - }, - mcnflag.StringFlag{ - Name: "google-address", - Usage: "GCE Instance External IP", - EnvVar: "GOOGLE_ADDRESS", - }, - mcnflag.BoolFlag{ - Name: "google-preemptible", - Usage: "GCE Instance Preemptibility", - EnvVar: "GOOGLE_PREEMPTIBLE", - }, - mcnflag.StringFlag{ - Name: "google-tags", - Usage: "GCE Instance Tags (comma-separated)", - EnvVar: "GOOGLE_TAGS", - Value: "", - }, - mcnflag.BoolFlag{ - Name: "google-use-internal-ip", - Usage: "Use internal GCE Instance IP rather than public one", - EnvVar: "GOOGLE_USE_INTERNAL_IP", - }, - mcnflag.BoolFlag{ - Name: "google-use-internal-ip-only", - Usage: "Configure GCE instance to not have an external IP address", - EnvVar: "GOOGLE_USE_INTERNAL_IP_ONLY", - }, - mcnflag.BoolFlag{ - Name: "google-use-existing", - Usage: "Don't create a new VM, use an existing one", - EnvVar: "GOOGLE_USE_EXISTING", - }, - mcnflag.StringSliceFlag{ - Name: "google-open-port", - Usage: "Make the specified port number accessible from the Internet, e.g, 8080/tcp", - }, - } -} - -// NewDriver creates a Driver with the specified storePath. -func NewDriver(machineName string, storePath string) *Driver { - return &Driver{ - Zone: defaultZone, - DiskType: defaultDiskType, - DiskSize: defaultDiskSize, - MachineType: defaultMachineType, - MachineImage: defaultImageName, - Network: defaultNetwork, - Subnetwork: defaultSubnetwork, - Scopes: defaultScopes, - BaseDriver: &drivers.BaseDriver{ - SSHUser: defaultUser, - MachineName: machineName, - StorePath: storePath, - }, - } -} - -// GetSSHHostname returns hostname for use with ssh -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -// GetSSHUsername returns username for use with ssh -func (d *Driver) GetSSHUsername() string { - if d.SSHUser == "" { - d.SSHUser = "docker-user" - } - return d.SSHUser -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "google" -} - -// SetConfigFromFlags initializes the driver based on the command line flags. -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.Project = flags.String("google-project") - if d.Project == "" { - return errors.New("no Google Cloud Project name specified (--google-project)") - } - - d.Zone = flags.String("google-zone") - d.UseExisting = flags.Bool("google-use-existing") - if !d.UseExisting { - d.MachineType = flags.String("google-machine-type") - d.MachineImage = flags.String("google-machine-image") - d.MachineImage = strings.TrimPrefix(d.MachineImage, "https://www.googleapis.com/compute/v1/projects/") - d.DiskSize = flags.Int("google-disk-size") - d.DiskType = flags.String("google-disk-type") - d.Address = flags.String("google-address") - d.Network = flags.String("google-network") - d.Subnetwork = flags.String("google-subnetwork") - d.Preemptible = flags.Bool("google-preemptible") - d.UseInternalIP = flags.Bool("google-use-internal-ip") || flags.Bool("google-use-internal-ip-only") - d.UseInternalIPOnly = flags.Bool("google-use-internal-ip-only") - d.Scopes = flags.String("google-scopes") - d.Tags = flags.String("google-tags") - d.OpenPorts = flags.StringSlice("google-open-port") - } - d.SSHUser = flags.String("google-username") - d.SSHPort = 22 - d.SetSwarmConfigFromFlags(flags) - - return nil -} - -// PreCreateCheck is called to enforce pre-creation steps -func (d *Driver) PreCreateCheck() error { - c, err := newComputeUtil(d) - if err != nil { - return err - } - - // Check that the project exists. It will also check the credentials - // at the same time. - log.Infof("Check that the project exists") - - if _, err = c.service.Projects.Get(d.Project).Do(); err != nil { - return fmt.Errorf("Project with ID %q not found. %v", d.Project, err) - } - - // Check if the instance already exists. There will be an error if the instance - // doesn't exist, so just check instance for nil. - log.Infof("Check if the instance already exists") - - instance, _ := c.instance() - if d.UseExisting { - if instance == nil { - return fmt.Errorf("unable to find instance %q in zone %q", d.MachineName, d.Zone) - } - } else { - if instance != nil { - return fmt.Errorf("instance %q already exists in zone %q", d.MachineName, d.Zone) - } - } - - return nil -} - -// Create creates a GCE VM instance acting as a docker host. -func (d *Driver) Create() error { - log.Infof("Generating SSH Key") - - if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { - return err - } - - log.Infof("Creating host...") - - c, err := newComputeUtil(d) - if err != nil { - return err - } - - if err := c.openFirewallPorts(d); err != nil { - return err - } - - if d.UseExisting { - return c.configureInstance(d) - } - return c.createInstance(d) -} - -// GetURL returns the URL of the remote docker daemon. -func (d *Driver) GetURL() (string, error) { - ip, err := d.GetIP() - if err != nil { - return "", err - } - - return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, "2376")), nil -} - -// GetIP returns the IP address of the GCE instance. -func (d *Driver) GetIP() (string, error) { - c, err := newComputeUtil(d) - if err != nil { - return "", err - } - - ip, err := c.ip() - if err != nil { - return "", err - } - if ip == "" { - return "", drivers.ErrHostIsNotRunning - } - - return ip, nil -} - -// GetState returns a docker.hosts.state.State value representing the current state of the host. -func (d *Driver) GetState() (state.State, error) { - c, err := newComputeUtil(d) - if err != nil { - return state.None, err - } - - // All we care about is whether the disk exists, so we just check disk for a nil value. - // There will be no error if disk is not nil. - instance, _ := c.instance() - if instance == nil { - disk, _ := c.disk() - if disk == nil { - return state.None, nil - } - return state.Stopped, nil - } - - switch instance.Status { - case "PROVISIONING", "STAGING": - return state.Starting, nil - case "RUNNING": - return state.Running, nil - case "STOPPING", "STOPPED", "TERMINATED": - return state.Stopped, nil - } - return state.None, nil -} - -// Start starts an existing GCE instance or create an instance with an existing disk. -func (d *Driver) Start() error { - c, err := newComputeUtil(d) - if err != nil { - return err - } - - instance, err := c.instance() - if err != nil { - if !strings.Contains(err.Error(), "notFound") { - return err - } - } - - if instance == nil { - if err = c.createInstance(d); err != nil { - return err - } - } else { - if err := c.startInstance(); err != nil { - return err - } - } - - d.IPAddress, err = d.GetIP() - return err -} - -// Stop stops an existing GCE instance. -func (d *Driver) Stop() error { - c, err := newComputeUtil(d) - if err != nil { - return err - } - - if err := c.stopInstance(); err != nil { - return err - } - - d.IPAddress = "" - return nil -} - -// Restart restarts a machine which is known to be running. -func (d *Driver) Restart() error { - if err := d.Stop(); err != nil { - return err - } - - return d.Start() -} - -// Kill stops an existing GCE instance. -func (d *Driver) Kill() error { - return d.Stop() -} - -// Remove deletes the GCE instance and the disk. -func (d *Driver) Remove() error { - c, err := newComputeUtil(d) - if err != nil { - return err - } - - if err := c.deleteInstance(); err != nil { - googleErr, ok := err.(*googleapi.Error) - if !ok { - return err - } - if googleErr.Code == http.StatusNotFound { - log.Warn("Remote instance does not exist, proceeding with removing local reference") - } else { - return err - } - } - - return c.deleteDisk() -} diff --git a/vendor/github.com/docker/machine/drivers/google/google_test.go b/vendor/github.com/docker/machine/drivers/google/google_test.go deleted file mode 100644 index b72035a..0000000 --- a/vendor/github.com/docker/machine/drivers/google/google_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package google - -import ( - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -func TestSetConfigFromFlags(t *testing.T) { - driver := NewDriver("", "") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "google-project": "PROJECT", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) -} diff --git a/vendor/github.com/docker/machine/drivers/hyperv/hyperv.go b/vendor/github.com/docker/machine/drivers/hyperv/hyperv.go deleted file mode 100644 index 6a46ab6..0000000 --- a/vendor/github.com/docker/machine/drivers/hyperv/hyperv.go +++ /dev/null @@ -1,468 +0,0 @@ -package hyperv - -import ( - "fmt" - "net" - "os" - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" -) - -type Driver struct { - *drivers.BaseDriver - Boot2DockerURL string - VSwitch string - DiskSize int - MemSize int - CPU int - MacAddr string - VLanID int -} - -const ( - defaultDiskSize = 20000 - defaultMemory = 1024 - defaultCPU = 1 - defaultVLanID = 0 -) - -// NewDriver creates a new Hyper-v driver with default settings. -func NewDriver(hostName, storePath string) *Driver { - return &Driver{ - DiskSize: defaultDiskSize, - MemSize: defaultMemory, - CPU: defaultCPU, - BaseDriver: &drivers.BaseDriver{ - MachineName: hostName, - StorePath: storePath, - }, - } -} - -// GetCreateFlags registers the flags this driver adds to -// "docker hosts create" -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - Name: "hyperv-boot2docker-url", - Usage: "URL of the boot2docker ISO. Defaults to the latest available version.", - EnvVar: "HYPERV_BOOT2DOCKER_URL", - }, - mcnflag.StringFlag{ - Name: "hyperv-virtual-switch", - Usage: "Virtual switch name. Defaults to first found.", - EnvVar: "HYPERV_VIRTUAL_SWITCH", - }, - mcnflag.IntFlag{ - Name: "hyperv-disk-size", - Usage: "Maximum size of dynamically expanding disk in MB.", - Value: defaultDiskSize, - EnvVar: "HYPERV_DISK_SIZE", - }, - mcnflag.IntFlag{ - Name: "hyperv-memory", - Usage: "Memory size for host in MB.", - Value: defaultMemory, - EnvVar: "HYPERV_MEMORY", - }, - mcnflag.IntFlag{ - Name: "hyperv-cpu-count", - Usage: "number of CPUs for the machine", - Value: defaultCPU, - EnvVar: "HYPERV_CPU_COUNT", - }, - mcnflag.StringFlag{ - Name: "hyperv-static-macaddress", - Usage: "Hyper-V network adapter's static MAC address.", - EnvVar: "HYPERV_STATIC_MACADDRESS", - }, - mcnflag.IntFlag{ - Name: "hyperv-vlan-id", - Usage: "Hyper-V network adapter's VLAN ID if any", - Value: defaultVLanID, - EnvVar: "HYPERV_VLAN_ID", - }, - } -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.Boot2DockerURL = flags.String("hyperv-boot2docker-url") - d.VSwitch = flags.String("hyperv-virtual-switch") - d.DiskSize = flags.Int("hyperv-disk-size") - d.MemSize = flags.Int("hyperv-memory") - d.CPU = flags.Int("hyperv-cpu-count") - d.MacAddr = flags.String("hyperv-static-macaddress") - d.VLanID = flags.Int("hyperv-vlan-id") - d.SSHUser = "docker" - d.SetSwarmConfigFromFlags(flags) - - return nil -} - -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "hyperv" -} - -func (d *Driver) GetURL() (string, error) { - ip, err := d.GetIP() - if err != nil { - return "", err - } - - if ip == "" { - return "", nil - } - - return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, "2376")), nil -} - -func (d *Driver) GetState() (state.State, error) { - stdout, err := cmdOut("(", "Get-VM", d.MachineName, ").state") - if err != nil { - return state.None, fmt.Errorf("Failed to find the VM status") - } - - resp := parseLines(stdout) - if len(resp) < 1 { - return state.None, nil - } - - switch resp[0] { - case "Running": - return state.Running, nil - case "Off": - return state.Stopped, nil - default: - return state.None, nil - } -} - -// PreCreateCheck checks that the machine creation process can be started safely. -func (d *Driver) PreCreateCheck() error { - // Check that powershell was found - if powershell == "" { - return ErrPowerShellNotFound - } - - // Check that hyperv is installed - if err := hypervAvailable(); err != nil { - return err - } - - // Check that the user is an Administrator - isAdmin, err := isAdministrator() - if err != nil { - return err - } - if !isAdmin { - return ErrNotAdministrator - } - - // Check that there is a virtual switch already configured - if _, err := d.chooseVirtualSwitch(); err != nil { - return err - } - - // Downloading boot2docker to cache should be done here to make sure - // that a download failure will not leave a machine half created. - b2dutils := mcnutils.NewB2dUtils(d.StorePath) - err = b2dutils.UpdateISOCache(d.Boot2DockerURL) - return err -} - -func (d *Driver) Create() error { - b2dutils := mcnutils.NewB2dUtils(d.StorePath) - if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil { - return err - } - - log.Infof("Creating SSH key...") - if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { - return err - } - - log.Infof("Creating VM...") - virtualSwitch, err := d.chooseVirtualSwitch() - if err != nil { - return err - } - - log.Infof("Using switch %q", virtualSwitch) - - diskImage, err := d.generateDiskImage() - if err != nil { - return err - } - - if err := cmd("New-VM", - d.MachineName, - "-Path", fmt.Sprintf("'%s'", d.ResolveStorePath(".")), - "-SwitchName", quote(virtualSwitch), - "-MemoryStartupBytes", toMb(d.MemSize)); err != nil { - return err - } - - if d.CPU > 1 { - if err := cmd("Set-VMProcessor", - d.MachineName, - "-Count", fmt.Sprintf("%d", d.CPU)); err != nil { - return err - } - } - - if d.MacAddr != "" { - if err := cmd("Set-VMNetworkAdapter", - "-VMName", d.MachineName, - "-StaticMacAddress", fmt.Sprintf("\"%s\"", d.MacAddr)); err != nil { - return err - } - } - - if d.VLanID > 0 { - if err := cmd("Set-VMNetworkAdapterVlan", - "-VMName", d.MachineName, - "-Access", - "-VlanId", fmt.Sprintf("%d", d.VLanID)); err != nil { - return err - } - } - - if err := cmd("Set-VMDvdDrive", - "-VMName", d.MachineName, - "-Path", quote(d.ResolveStorePath("boot2docker.iso"))); err != nil { - return err - } - - if err := cmd("Add-VMHardDiskDrive", - "-VMName", d.MachineName, - "-Path", quote(diskImage)); err != nil { - return err - } - - log.Infof("Starting VM...") - return d.Start() -} - -func (d *Driver) chooseVirtualSwitch() (string, error) { - stdout, err := cmdOut("(Get-VMSwitch).Name") - if err != nil { - return "", err - } - - switches := parseLines(stdout) - - if d.VSwitch == "" { - if len(switches) < 1 { - return "", fmt.Errorf("no vswitch found. A valid vswitch must be available for this command to run. Check https://docs.docker.com/machine/drivers/hyper-v/") - } - - return switches[0], nil - } - - found := false - for _, name := range switches { - if name == d.VSwitch { - found = true - break - } - } - - if !found { - return "", fmt.Errorf("vswitch %q not found", d.VSwitch) - } - - return d.VSwitch, nil -} - -// waitForIP waits until the host has a valid IP -func (d *Driver) waitForIP() (string, error) { - log.Infof("Waiting for host to start...") - - for { - ip, _ := d.GetIP() - if ip != "" { - return ip, nil - } - - time.Sleep(1 * time.Second) - } -} - -// waitStopped waits until the host is stopped -func (d *Driver) waitStopped() error { - log.Infof("Waiting for host to stop...") - - for { - s, err := d.GetState() - if err != nil { - return err - } - - if s != state.Running { - return nil - } - - time.Sleep(1 * time.Second) - } -} - -// Start starts an host -func (d *Driver) Start() error { - if err := cmd("Start-VM", d.MachineName); err != nil { - return err - } - - ip, err := d.waitForIP() - if err != nil { - return err - } - - d.IPAddress = ip - - return nil -} - -// Stop stops an host -func (d *Driver) Stop() error { - if err := cmd("Stop-VM", d.MachineName); err != nil { - return err - } - - if err := d.waitStopped(); err != nil { - return err - } - - d.IPAddress = "" - - return nil -} - -// Remove removes an host -func (d *Driver) Remove() error { - s, err := d.GetState() - if err != nil { - return err - } - - if s == state.Running { - if err := d.Kill(); err != nil { - return err - } - } - - return cmd("Remove-VM", d.MachineName, "-Force") -} - -// Restart stops and starts an host -func (d *Driver) Restart() error { - err := d.Stop() - if err != nil { - return err - } - - return d.Start() -} - -// Kill force stops an host -func (d *Driver) Kill() error { - if err := cmd("Stop-VM", d.MachineName, "-TurnOff"); err != nil { - return err - } - - if err := d.waitStopped(); err != nil { - return err - } - - d.IPAddress = "" - - return nil -} - -func (d *Driver) GetIP() (string, error) { - s, err := d.GetState() - if err != nil { - return "", err - } - if s != state.Running { - return "", drivers.ErrHostIsNotRunning - } - - stdout, err := cmdOut("((", "Get-VM", d.MachineName, ").networkadapters[0]).ipaddresses[0]") - if err != nil { - return "", err - } - - resp := parseLines(stdout) - if len(resp) < 1 { - return "", fmt.Errorf("IP not found") - } - - return resp[0], nil -} - -func (d *Driver) publicSSHKeyPath() string { - return d.GetSSHKeyPath() + ".pub" -} - -// generateDiskImage creates a small fixed vhd, put the tar in, convert to dynamic, then resize -func (d *Driver) generateDiskImage() (string, error) { - diskImage := d.ResolveStorePath("disk.vhd") - fixed := d.ResolveStorePath("fixed.vhd") - - // Resizing vhds requires administrator privileges - // incase the user is only a hyper-v admin then create the disk at the target size to avoid resizing. - isWindowsAdmin, err := isWindowsAdministrator() - if err != nil { - return "", err - } - fixedDiskSize := "10MB" - if !isWindowsAdmin { - fixedDiskSize = toMb(d.DiskSize) - } - - log.Infof("Creating VHD") - if err := cmd("New-VHD", "-Path", quote(fixed), "-SizeBytes", fixedDiskSize, "-Fixed"); err != nil { - return "", err - } - - tarBuf, err := mcnutils.MakeDiskImage(d.publicSSHKeyPath()) - if err != nil { - return "", err - } - - file, err := os.OpenFile(fixed, os.O_WRONLY, 0644) - if err != nil { - return "", err - } - defer file.Close() - - file.Seek(0, os.SEEK_SET) - _, err = file.Write(tarBuf.Bytes()) - if err != nil { - return "", err - } - file.Close() - - if err := cmd("Convert-VHD", "-Path", quote(fixed), "-DestinationPath", quote(diskImage), "-VHDType", "Dynamic", "-DeleteSource"); err != nil { - return "", err - } - - if isWindowsAdmin { - if err := cmd("Resize-VHD", "-Path", quote(diskImage), "-SizeBytes", toMb(d.DiskSize)); err != nil { - return "", err - } - } - - return diskImage, nil -} diff --git a/vendor/github.com/docker/machine/drivers/hyperv/hyperv_test.go b/vendor/github.com/docker/machine/drivers/hyperv/hyperv_test.go deleted file mode 100644 index d4d833e..0000000 --- a/vendor/github.com/docker/machine/drivers/hyperv/hyperv_test.go +++ /dev/null @@ -1,68 +0,0 @@ -package hyperv - -import ( - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -func TestSetConfigFromDefaultFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{}, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) - - sshPort, err := driver.GetSSHPort() - assert.Equal(t, 22, sshPort) - assert.NoError(t, err) - - assert.Equal(t, "", driver.Boot2DockerURL) - assert.Equal(t, "", driver.VSwitch) - assert.Equal(t, defaultDiskSize, driver.DiskSize) - assert.Equal(t, defaultMemory, driver.MemSize) - assert.Equal(t, defaultCPU, driver.CPU) - assert.Equal(t, "", driver.MacAddr) - assert.Equal(t, defaultVLanID, driver.VLanID) - assert.Equal(t, "docker", driver.GetSSHUsername()) -} - -func TestSetConfigFromCustomFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "hyperv-boot2docker-url": "B2D_URL", - "hyperv-virtual-switch": "TheSwitch", - "hyperv-disk-size": 100000, - "hyperv-memory": 4096, - "hyperv-cpu-count": 4, - "hyperv-static-macaddress": "00:0a:95:9d:68:16", - "hyperv-vlan-id": 2, - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) - - sshPort, err := driver.GetSSHPort() - assert.Equal(t, 22, sshPort) - assert.NoError(t, err) - - assert.Equal(t, "B2D_URL", driver.Boot2DockerURL) - assert.Equal(t, "TheSwitch", driver.VSwitch) - assert.Equal(t, 100000, driver.DiskSize) - assert.Equal(t, 4096, driver.MemSize) - assert.Equal(t, 4, driver.CPU) - assert.Equal(t, "00:0a:95:9d:68:16", driver.MacAddr) - assert.Equal(t, 2, driver.VLanID) - assert.Equal(t, "docker", driver.GetSSHUsername()) -} diff --git a/vendor/github.com/docker/machine/drivers/hyperv/powershell.go b/vendor/github.com/docker/machine/drivers/hyperv/powershell.go deleted file mode 100644 index b486cba..0000000 --- a/vendor/github.com/docker/machine/drivers/hyperv/powershell.go +++ /dev/null @@ -1,114 +0,0 @@ -package hyperv - -import ( - "bufio" - "bytes" - "errors" - "os/exec" - "strings" - - "fmt" - - "github.com/docker/machine/libmachine/log" -) - -var powershell string - -var ( - ErrPowerShellNotFound = errors.New("Powershell was not found in the path") - ErrNotAdministrator = errors.New("Hyper-v commands have to be run as an Administrator") - ErrNotInstalled = errors.New("Hyper-V PowerShell Module is not available") -) - -func init() { - powershell, _ = exec.LookPath("powershell.exe") -} - -func cmdOut(args ...string) (string, error) { - args = append([]string{"-NoProfile", "-NonInteractive"}, args...) - cmd := exec.Command(powershell, args...) - log.Debugf("[executing ==>] : %v %v", powershell, strings.Join(args, " ")) - var stdout bytes.Buffer - var stderr bytes.Buffer - cmd.Stdout = &stdout - cmd.Stderr = &stderr - err := cmd.Run() - log.Debugf("[stdout =====>] : %s", stdout.String()) - log.Debugf("[stderr =====>] : %s", stderr.String()) - return stdout.String(), err -} - -func cmd(args ...string) error { - _, err := cmdOut(args...) - return err -} - -func parseLines(stdout string) []string { - resp := []string{} - - s := bufio.NewScanner(strings.NewReader(stdout)) - for s.Scan() { - resp = append(resp, s.Text()) - } - - return resp -} - -func hypervAvailable() error { - stdout, err := cmdOut("@(Get-Command Get-VM).ModuleName") - if err != nil { - return err - } - - resp := parseLines(stdout) - if resp[0] != "Hyper-V" { - return ErrNotInstalled - } - - return nil -} - -func isAdministrator() (bool, error) { - hypervAdmin := isHypervAdministrator() - - if hypervAdmin { - return true, nil - } - - windowsAdmin, err := isWindowsAdministrator() - - if err != nil { - return false, err - } - - return windowsAdmin, nil -} - -func isHypervAdministrator() bool { - stdout, err := cmdOut(`@([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Hyper-V Administrators")`) - if err != nil { - log.Debug(err) - return false - } - - resp := parseLines(stdout) - return resp[0] == "True" -} - -func isWindowsAdministrator() (bool, error) { - stdout, err := cmdOut(`@([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")`) - if err != nil { - return false, err - } - - resp := parseLines(stdout) - return resp[0] == "True", nil -} - -func quote(text string) string { - return fmt.Sprintf("'%s'", text) -} - -func toMb(value int) string { - return fmt.Sprintf("%dMB", value) -} diff --git a/vendor/github.com/docker/machine/drivers/none/driver.go b/vendor/github.com/docker/machine/drivers/none/driver.go deleted file mode 100644 index 2e88dbe..0000000 --- a/vendor/github.com/docker/machine/drivers/none/driver.go +++ /dev/null @@ -1,113 +0,0 @@ -package none - -import ( - "fmt" - neturl "net/url" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/state" -) - -const driverName = "none" - -// Driver is the driver used when no driver is selected. It is used to -// connect to existing Docker hosts by specifying the URL of the host as -// an option. -type Driver struct { - *drivers.BaseDriver - URL string -} - -func NewDriver(hostName, storePath string) *Driver { - return &Driver{ - BaseDriver: &drivers.BaseDriver{ - MachineName: hostName, - StorePath: storePath, - }, - } -} - -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - Name: "url", - Usage: "URL of host when no driver is selected", - Value: "", - }, - } -} - -func (d *Driver) Create() error { - return nil -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return driverName -} - -func (d *Driver) GetIP() (string, error) { - return d.IPAddress, nil -} - -func (d *Driver) GetSSHHostname() (string, error) { - return "", nil -} - -func (d *Driver) GetSSHKeyPath() string { - return "" -} - -func (d *Driver) GetSSHPort() (int, error) { - return 0, nil -} - -func (d *Driver) GetSSHUsername() string { - return "" -} - -func (d *Driver) GetURL() (string, error) { - return d.URL, nil -} - -func (d *Driver) GetState() (state.State, error) { - return state.Running, nil -} - -func (d *Driver) Kill() error { - return fmt.Errorf("hosts without a driver cannot be killed") -} - -func (d *Driver) Remove() error { - return nil -} - -func (d *Driver) Restart() error { - return fmt.Errorf("hosts without a driver cannot be restarted") -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - url := flags.String("url") - - if url == "" { - return fmt.Errorf("--url option is required when no driver is selected") - } - - d.URL = url - u, err := neturl.Parse(url) - if err != nil { - return err - } - - d.IPAddress = u.Host - return nil -} - -func (d *Driver) Start() error { - return fmt.Errorf("hosts without a driver cannot be started") -} - -func (d *Driver) Stop() error { - return fmt.Errorf("hosts without a driver cannot be stopped") -} diff --git a/vendor/github.com/docker/machine/drivers/openstack/client.go b/vendor/github.com/docker/machine/drivers/openstack/client.go deleted file mode 100644 index 610274e..0000000 --- a/vendor/github.com/docker/machine/drivers/openstack/client.go +++ /dev/null @@ -1,602 +0,0 @@ -package openstack - -import ( - "crypto/tls" - "crypto/x509" - "fmt" - "io/ioutil" - "net/http" - "time" - - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/version" - "github.com/rackspace/gophercloud" - "github.com/rackspace/gophercloud/openstack" - compute_ips "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/floatingip" - "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs" - "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/startstop" - "github.com/rackspace/gophercloud/openstack/compute/v2/flavors" - "github.com/rackspace/gophercloud/openstack/compute/v2/images" - "github.com/rackspace/gophercloud/openstack/compute/v2/servers" - "github.com/rackspace/gophercloud/openstack/identity/v2/tenants" - "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" - "github.com/rackspace/gophercloud/openstack/networking/v2/networks" - "github.com/rackspace/gophercloud/openstack/networking/v2/ports" - "github.com/rackspace/gophercloud/pagination" -) - -type Client interface { - Authenticate(d *Driver) error - InitComputeClient(d *Driver) error - InitIdentityClient(d *Driver) error - InitNetworkClient(d *Driver) error - - CreateInstance(d *Driver) (string, error) - GetInstanceState(d *Driver) (string, error) - StartInstance(d *Driver) error - StopInstance(d *Driver) error - RestartInstance(d *Driver) error - DeleteInstance(d *Driver) error - WaitForInstanceStatus(d *Driver, status string) error - GetInstanceIPAddresses(d *Driver) ([]IPAddress, error) - GetPublicKey(keyPairName string) ([]byte, error) - CreateKeyPair(d *Driver, name string, publicKey string) error - DeleteKeyPair(d *Driver, name string) error - GetNetworkID(d *Driver) (string, error) - GetFlavorID(d *Driver) (string, error) - GetImageID(d *Driver) (string, error) - AssignFloatingIP(d *Driver, floatingIP *FloatingIP) error - GetFloatingIPs(d *Driver) ([]FloatingIP, error) - GetFloatingIPPoolID(d *Driver) (string, error) - GetInstancePortID(d *Driver) (string, error) - GetTenantID(d *Driver) (string, error) -} - -type GenericClient struct { - Provider *gophercloud.ProviderClient - Compute *gophercloud.ServiceClient - Identity *gophercloud.ServiceClient - Network *gophercloud.ServiceClient -} - -func (c *GenericClient) CreateInstance(d *Driver) (string, error) { - serverOpts := servers.CreateOpts{ - Name: d.MachineName, - FlavorRef: d.FlavorId, - ImageRef: d.ImageId, - UserData: d.UserData, - SecurityGroups: d.SecurityGroups, - AvailabilityZone: d.AvailabilityZone, - } - if d.NetworkId != "" { - serverOpts.Networks = []servers.Network{ - { - UUID: d.NetworkId, - }, - } - } - - log.Info("Creating machine...") - - server, err := servers.Create(c.Compute, keypairs.CreateOptsExt{ - serverOpts, - d.KeyPairName, - }).Extract() - if err != nil { - return "", err - } - return server.ID, nil -} - -const ( - Floating string = "floating" - Fixed string = "fixed" -) - -type IPAddress struct { - Network string - AddressType string - Address string - Version int - Mac string -} - -type FloatingIP struct { - Id string - Ip string - NetworkId string - PortId string - Pool string - MachineId string -} - -func (c *GenericClient) GetInstanceState(d *Driver) (string, error) { - server, err := c.GetServerDetail(d) - if err != nil { - return "", err - } - return server.Status, nil -} - -func (c *GenericClient) StartInstance(d *Driver) error { - if result := startstop.Start(c.Compute, d.MachineId); result.Err != nil { - return result.Err - } - return nil -} - -func (c *GenericClient) StopInstance(d *Driver) error { - if result := startstop.Stop(c.Compute, d.MachineId); result.Err != nil { - return result.Err - } - return nil -} - -func (c *GenericClient) RestartInstance(d *Driver) error { - if result := servers.Reboot(c.Compute, d.MachineId, servers.SoftReboot); result.Err != nil { - return result.Err - } - return nil -} - -func (c *GenericClient) DeleteInstance(d *Driver) error { - if result := servers.Delete(c.Compute, d.MachineId); result.Err != nil { - return result.Err - } - return nil -} - -func (c *GenericClient) WaitForInstanceStatus(d *Driver, status string) error { - return mcnutils.WaitForSpecificOrError(func() (bool, error) { - current, err := servers.Get(c.Compute, d.MachineId).Extract() - if err != nil { - return true, err - } - - if current.Status == "ERROR" { - return true, fmt.Errorf("Instance creation failed. Instance is in ERROR state") - } - - if current.Status == status { - return true, nil - } - - return false, nil - }, (d.ActiveTimeout / 4), 4*time.Second) -} - -func (c *GenericClient) GetInstanceIPAddresses(d *Driver) ([]IPAddress, error) { - server, err := c.GetServerDetail(d) - if err != nil { - return nil, err - } - addresses := []IPAddress{} - for network, networkAddresses := range server.Addresses { - for _, element := range networkAddresses.([]interface{}) { - address := element.(map[string]interface{}) - version, ok := address["version"].(float64) - if !ok { - // Assume IPv4 if no version present. - version = 4 - } - - addr := IPAddress{ - Network: network, - AddressType: Fixed, - Address: address["addr"].(string), - Version: int(version), - } - - if tp, ok := address["OS-EXT-IPS:type"]; ok { - addr.AddressType = tp.(string) - } - if mac, ok := address["OS-EXT-IPS-MAC:mac_addr"]; ok { - addr.Mac = mac.(string) - } - - addresses = append(addresses, addr) - } - } - - return addresses, nil -} - -func (c *GenericClient) GetNetworkID(d *Driver) (string, error) { - return c.getNetworkID(d, d.NetworkName) -} - -func (c *GenericClient) GetFloatingIPPoolID(d *Driver) (string, error) { - return c.getNetworkID(d, d.FloatingIpPool) -} - -func (c *GenericClient) getNetworkID(d *Driver, networkName string) (string, error) { - opts := networks.ListOpts{Name: networkName} - pager := networks.List(c.Network, opts) - networkID := "" - - err := pager.EachPage(func(page pagination.Page) (bool, error) { - networkList, err := networks.ExtractNetworks(page) - if err != nil { - return false, err - } - - for _, n := range networkList { - if n.Name == networkName { - networkID = n.ID - return false, nil - } - } - - return true, nil - }) - - return networkID, err -} - -func (c *GenericClient) GetFlavorID(d *Driver) (string, error) { - pager := flavors.ListDetail(c.Compute, nil) - flavorID := "" - - err := pager.EachPage(func(page pagination.Page) (bool, error) { - flavorList, err := flavors.ExtractFlavors(page) - if err != nil { - return false, err - } - - for _, f := range flavorList { - if f.Name == d.FlavorName { - flavorID = f.ID - return false, nil - } - } - - return true, nil - }) - - return flavorID, err -} - -func (c *GenericClient) GetImageID(d *Driver) (string, error) { - opts := images.ListOpts{Name: d.ImageName} - pager := images.ListDetail(c.Compute, opts) - imageID := "" - - err := pager.EachPage(func(page pagination.Page) (bool, error) { - imageList, err := images.ExtractImages(page) - if err != nil { - return false, err - } - - for _, i := range imageList { - if i.Name == d.ImageName { - imageID = i.ID - return false, nil - } - } - - return true, nil - }) - - return imageID, err -} - -func (c *GenericClient) GetTenantID(d *Driver) (string, error) { - pager := tenants.List(c.Identity, nil) - tenantId := "" - - err := pager.EachPage(func(page pagination.Page) (bool, error) { - tenantList, err := tenants.ExtractTenants(page) - if err != nil { - return false, err - } - - for _, i := range tenantList { - if i.Name == d.TenantName { - tenantId = i.ID - return false, nil - } - } - - return true, nil - }) - - return tenantId, err -} - -func (c *GenericClient) GetPublicKey(keyPairName string) ([]byte, error) { - kp, err := keypairs.Get(c.Compute, keyPairName).Extract() - if err != nil { - return nil, err - } - return []byte(kp.PublicKey), nil -} - -func (c *GenericClient) CreateKeyPair(d *Driver, name string, publicKey string) error { - opts := keypairs.CreateOpts{ - Name: name, - PublicKey: publicKey, - } - if result := keypairs.Create(c.Compute, opts); result.Err != nil { - return result.Err - } - return nil -} - -func (c *GenericClient) DeleteKeyPair(d *Driver, name string) error { - if result := keypairs.Delete(c.Compute, name); result.Err != nil { - return result.Err - } - return nil -} - -func (c *GenericClient) GetServerDetail(d *Driver) (*servers.Server, error) { - server, err := servers.Get(c.Compute, d.MachineId).Extract() - if err != nil { - return nil, err - } - return server, nil -} - -func (c *GenericClient) AssignFloatingIP(d *Driver, floatingIP *FloatingIP) error { - if d.ComputeNetwork { - return c.assignNovaFloatingIP(d, floatingIP) - } - return c.assignNeutronFloatingIP(d, floatingIP) -} - -func (c *GenericClient) assignNovaFloatingIP(d *Driver, floatingIP *FloatingIP) error { - if floatingIP.Ip == "" { - f, err := compute_ips.Create(c.Compute, compute_ips.CreateOpts{ - Pool: d.FloatingIpPool, - }).Extract() - if err != nil { - return err - } - floatingIP.Ip = f.IP - floatingIP.Pool = f.Pool - } - return compute_ips.Associate(c.Compute, d.MachineId, floatingIP.Ip).Err -} - -func (c *GenericClient) assignNeutronFloatingIP(d *Driver, floatingIP *FloatingIP) error { - portID, err := c.GetInstancePortID(d) - if err != nil { - return err - } - if floatingIP.Id == "" { - f, err := floatingips.Create(c.Network, floatingips.CreateOpts{ - FloatingNetworkID: d.FloatingIpPoolId, - PortID: portID, - }).Extract() - if err != nil { - return err - } - floatingIP.Id = f.ID - floatingIP.Ip = f.FloatingIP - floatingIP.NetworkId = f.FloatingNetworkID - floatingIP.PortId = f.PortID - return nil - } - _, err = floatingips.Update(c.Network, floatingIP.Id, floatingips.UpdateOpts{ - PortID: portID, - }).Extract() - if err != nil { - return err - } - return nil -} - -func (c *GenericClient) GetFloatingIPs(d *Driver) ([]FloatingIP, error) { - if d.ComputeNetwork { - return c.getNovaNetworkFloatingIPs(d) - } - return c.getNeutronNetworkFloatingIPs(d) -} - -func (c *GenericClient) getNovaNetworkFloatingIPs(d *Driver) ([]FloatingIP, error) { - pager := compute_ips.List(c.Compute) - - ips := []FloatingIP{} - err := pager.EachPage(func(page pagination.Page) (continue_paging bool, err error) { - continue_paging, err = true, nil - ipListing, err := compute_ips.ExtractFloatingIPs(page) - - for _, ip := range ipListing { - if ip.InstanceID == "" && ip.Pool == d.FloatingIpPool { - ips = append(ips, FloatingIP{ - Id: ip.ID, - Ip: ip.IP, - Pool: ip.Pool, - }) - } - } - return - }) - return ips, err -} - -func (c *GenericClient) getNeutronNetworkFloatingIPs(d *Driver) ([]FloatingIP, error) { - log.Debug("Listing floating IPs", map[string]string{ - "FloatingNetworkId": d.FloatingIpPoolId, - "TenantID": d.TenantId, - }) - pager := floatingips.List(c.Network, floatingips.ListOpts{ - FloatingNetworkID: d.FloatingIpPoolId, - TenantID: d.TenantId, - }) - - ips := []FloatingIP{} - err := pager.EachPage(func(page pagination.Page) (bool, error) { - floatingipList, err := floatingips.ExtractFloatingIPs(page) - if err != nil { - return false, err - } - for _, f := range floatingipList { - ips = append(ips, FloatingIP{ - Id: f.ID, - Ip: f.FloatingIP, - NetworkId: f.FloatingNetworkID, - PortId: f.PortID, - }) - } - return true, nil - }) - - if err != nil { - return nil, err - } - return ips, nil -} - -func (c *GenericClient) GetInstancePortID(d *Driver) (string, error) { - pager := ports.List(c.Network, ports.ListOpts{ - DeviceID: d.MachineId, - NetworkID: d.NetworkId, - }) - - var portID string - err := pager.EachPage(func(page pagination.Page) (bool, error) { - portList, err := ports.ExtractPorts(page) - if err != nil { - return false, err - } - for _, port := range portList { - portID = port.ID - return false, nil - } - return true, nil - }) - - if err != nil { - return "", err - } - return portID, nil -} - -func (c *GenericClient) InitComputeClient(d *Driver) error { - if c.Compute != nil { - return nil - } - - compute, err := openstack.NewComputeV2(c.Provider, gophercloud.EndpointOpts{ - Region: d.Region, - Availability: c.getEndpointType(d), - }) - if err != nil { - return err - } - c.Compute = compute - return nil -} - -func (c *GenericClient) InitIdentityClient(d *Driver) error { - if c.Identity != nil { - return nil - } - - identity := openstack.NewIdentityV2(c.Provider) - c.Identity = identity - return nil -} - -func (c *GenericClient) InitNetworkClient(d *Driver) error { - if c.Network != nil { - return nil - } - - network, err := openstack.NewNetworkV2(c.Provider, gophercloud.EndpointOpts{ - Region: d.Region, - Availability: c.getEndpointType(d), - }) - if err != nil { - return err - } - c.Network = network - return nil -} - -func (c *GenericClient) getEndpointType(d *Driver) gophercloud.Availability { - switch d.EndpointType { - case "internalURL": - return gophercloud.AvailabilityInternal - case "adminURL": - return gophercloud.AvailabilityAdmin - } - return gophercloud.AvailabilityPublic -} - -func (c *GenericClient) Authenticate(d *Driver) error { - if c.Provider != nil { - return nil - } - - log.Debug("Authenticating...", map[string]interface{}{ - "AuthUrl": d.AuthUrl, - "Insecure": d.Insecure, - "CaCert": d.CaCert, - "DomainID": d.DomainID, - "DomainName": d.DomainName, - "Username": d.Username, - "TenantName": d.TenantName, - "TenantID": d.TenantId, - }) - - opts := gophercloud.AuthOptions{ - IdentityEndpoint: d.AuthUrl, - DomainID: d.DomainID, - DomainName: d.DomainName, - Username: d.Username, - Password: d.Password, - TenantName: d.TenantName, - TenantID: d.TenantId, - AllowReauth: true, - } - - provider, err := openstack.NewClient(opts.IdentityEndpoint) - if err != nil { - return err - } - - c.Provider = provider - - c.Provider.UserAgent.Prepend(fmt.Sprintf("docker-machine/v%d", version.APIVersion)) - - err = c.SetTLSConfig(d) - if err != nil { - return err - } - - err = openstack.Authenticate(c.Provider, opts) - if err != nil { - return err - } - - return nil -} - -func (c *GenericClient) SetTLSConfig(d *Driver) error { - - config := &tls.Config{} - config.InsecureSkipVerify = d.Insecure - - if d.CaCert != "" { - // Use custom CA certificate(s) for root of trust - certpool := x509.NewCertPool() - pem, err := ioutil.ReadFile(d.CaCert) - if err != nil { - log.Error("Unable to read specified CA certificate(s)") - return err - } - - ok := certpool.AppendCertsFromPEM(pem) - if !ok { - return fmt.Errorf("Ill-formed CA certificate(s) PEM file") - } - config.RootCAs = certpool - } - - transport := &http.Transport{TLSClientConfig: config, Proxy: http.ProxyFromEnvironment} - c.Provider.HTTPClient.Transport = transport - return nil -} diff --git a/vendor/github.com/docker/machine/drivers/openstack/openstack.go b/vendor/github.com/docker/machine/drivers/openstack/openstack.go deleted file mode 100644 index 0eadb5a..0000000 --- a/vendor/github.com/docker/machine/drivers/openstack/openstack.go +++ /dev/null @@ -1,795 +0,0 @@ -package openstack - -import ( - "fmt" - "io/ioutil" - "net" - "strings" - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" -) - -type Driver struct { - *drivers.BaseDriver - AuthUrl string - ActiveTimeout int - Insecure bool - CaCert string - DomainID string - DomainName string - Username string - Password string - TenantName string - TenantId string - Region string - AvailabilityZone string - EndpointType string - MachineId string - FlavorName string - FlavorId string - ImageName string - ImageId string - KeyPairName string - NetworkName string - NetworkId string - UserData []byte - PrivateKeyFile string - SecurityGroups []string - FloatingIpPool string - ComputeNetwork bool - FloatingIpPoolId string - IpVersion int - client Client -} - -const ( - defaultSSHUser = "root" - defaultSSHPort = 22 - defaultActiveTimeout = 200 -) - -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - EnvVar: "OS_AUTH_URL", - Name: "openstack-auth-url", - Usage: "OpenStack authentication URL", - Value: "", - }, - mcnflag.BoolFlag{ - EnvVar: "OS_INSECURE", - Name: "openstack-insecure", - Usage: "Disable TLS credential checking.", - }, - mcnflag.StringFlag{ - EnvVar: "OS_CACERT", - Name: "openstack-cacert", - Usage: "CA certificate bundle to verify against", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_DOMAIN_ID", - Name: "openstack-domain-id", - Usage: "OpenStack domain ID (identity v3 only)", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_DOMAIN_NAME", - Name: "openstack-domain-name", - Usage: "OpenStack domain name (identity v3 only)", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_USERNAME", - Name: "openstack-username", - Usage: "OpenStack username", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_PASSWORD", - Name: "openstack-password", - Usage: "OpenStack password", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_TENANT_NAME", - Name: "openstack-tenant-name", - Usage: "OpenStack tenant name", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_TENANT_ID", - Name: "openstack-tenant-id", - Usage: "OpenStack tenant id", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_REGION_NAME", - Name: "openstack-region", - Usage: "OpenStack region name", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_AVAILABILITY_ZONE", - Name: "openstack-availability-zone", - Usage: "OpenStack availability zone", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_ENDPOINT_TYPE", - Name: "openstack-endpoint-type", - Usage: "OpenStack endpoint type (adminURL, internalURL or publicURL)", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_FLAVOR_ID", - Name: "openstack-flavor-id", - Usage: "OpenStack flavor id to use for the instance", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_FLAVOR_NAME", - Name: "openstack-flavor-name", - Usage: "OpenStack flavor name to use for the instance", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_IMAGE_ID", - Name: "openstack-image-id", - Usage: "OpenStack image id to use for the instance", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_IMAGE_NAME", - Name: "openstack-image-name", - Usage: "OpenStack image name to use for the instance", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_KEYPAIR_NAME", - Name: "openstack-keypair-name", - Usage: "OpenStack keypair to use to SSH to the instance", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_NETWORK_ID", - Name: "openstack-net-id", - Usage: "OpenStack network id the machine will be connected on", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_PRIVATE_KEY_FILE", - Name: "openstack-private-key-file", - Usage: "Private keyfile to use for SSH (absolute path)", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_USER_DATA_FILE", - Name: "openstack-user-data-file", - Usage: "File containing an openstack userdata script", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_NETWORK_NAME", - Name: "openstack-net-name", - Usage: "OpenStack network name the machine will be connected on", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_SECURITY_GROUPS", - Name: "openstack-sec-groups", - Usage: "OpenStack comma separated security groups for the machine", - Value: "", - }, - mcnflag.BoolFlag{ - EnvVar: "OS_NOVA_NETWORK", - Name: "openstack-nova-network", - Usage: "Use the nova networking services instead of neutron.", - }, - mcnflag.StringFlag{ - EnvVar: "OS_FLOATINGIP_POOL", - Name: "openstack-floatingip-pool", - Usage: "OpenStack floating IP pool to get an IP from to assign to the instance", - Value: "", - }, - mcnflag.IntFlag{ - EnvVar: "OS_IP_VERSION", - Name: "openstack-ip-version", - Usage: "OpenStack version of IP address assigned for the machine", - Value: 4, - }, - mcnflag.StringFlag{ - EnvVar: "OS_SSH_USER", - Name: "openstack-ssh-user", - Usage: "OpenStack SSH user", - Value: defaultSSHUser, - }, - mcnflag.IntFlag{ - EnvVar: "OS_SSH_PORT", - Name: "openstack-ssh-port", - Usage: "OpenStack SSH port", - Value: defaultSSHPort, - }, - mcnflag.IntFlag{ - EnvVar: "OS_ACTIVE_TIMEOUT", - Name: "openstack-active-timeout", - Usage: "OpenStack active timeout", - Value: defaultActiveTimeout, - }, - } -} - -func NewDriver(hostName, storePath string) drivers.Driver { - return NewDerivedDriver(hostName, storePath) -} - -func NewDerivedDriver(hostName, storePath string) *Driver { - return &Driver{ - client: &GenericClient{}, - ActiveTimeout: defaultActiveTimeout, - BaseDriver: &drivers.BaseDriver{ - SSHUser: defaultSSHUser, - SSHPort: defaultSSHPort, - MachineName: hostName, - StorePath: storePath, - }, - } -} - -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -func (d *Driver) SetClient(client Client) { - d.client = client -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "openstack" -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.AuthUrl = flags.String("openstack-auth-url") - d.ActiveTimeout = flags.Int("openstack-active-timeout") - d.Insecure = flags.Bool("openstack-insecure") - d.CaCert = flags.String("openstack-cacert") - d.DomainID = flags.String("openstack-domain-id") - d.DomainName = flags.String("openstack-domain-name") - d.Username = flags.String("openstack-username") - d.Password = flags.String("openstack-password") - d.TenantName = flags.String("openstack-tenant-name") - d.TenantId = flags.String("openstack-tenant-id") - d.Region = flags.String("openstack-region") - d.AvailabilityZone = flags.String("openstack-availability-zone") - d.EndpointType = flags.String("openstack-endpoint-type") - d.FlavorId = flags.String("openstack-flavor-id") - d.FlavorName = flags.String("openstack-flavor-name") - d.ImageId = flags.String("openstack-image-id") - d.ImageName = flags.String("openstack-image-name") - d.NetworkId = flags.String("openstack-net-id") - d.NetworkName = flags.String("openstack-net-name") - if flags.String("openstack-sec-groups") != "" { - d.SecurityGroups = strings.Split(flags.String("openstack-sec-groups"), ",") - } - d.FloatingIpPool = flags.String("openstack-floatingip-pool") - d.IpVersion = flags.Int("openstack-ip-version") - d.ComputeNetwork = flags.Bool("openstack-nova-network") - d.SSHUser = flags.String("openstack-ssh-user") - d.SSHPort = flags.Int("openstack-ssh-port") - d.KeyPairName = flags.String("openstack-keypair-name") - d.PrivateKeyFile = flags.String("openstack-private-key-file") - - if flags.String("openstack-user-data-file") != "" { - userData, err := ioutil.ReadFile(flags.String("openstack-user-data-file")) - if err == nil { - d.UserData = userData - } else { - return err - } - } - - d.SetSwarmConfigFromFlags(flags) - - return d.checkConfig() -} - -func (d *Driver) GetURL() (string, error) { - if err := drivers.MustBeRunning(d); err != nil { - return "", err - } - - ip, err := d.GetIP() - if err != nil { - return "", err - } - if ip == "" { - return "", nil - } - - return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, "2376")), nil -} - -func (d *Driver) GetIP() (string, error) { - if d.IPAddress != "" { - return d.IPAddress, nil - } - - log.Debug("Looking for the IP address...", map[string]string{"MachineId": d.MachineId}) - - if err := d.initCompute(); err != nil { - return "", err - } - - addressType := Fixed - if d.FloatingIpPool != "" { - addressType = Floating - } - - // Looking for the IP address in a retry loop to deal with OpenStack latency - for retryCount := 0; retryCount < 200; retryCount++ { - addresses, err := d.client.GetInstanceIPAddresses(d) - if err != nil { - return "", err - } - for _, a := range addresses { - if a.AddressType == addressType && a.Version == d.IpVersion { - return a.Address, nil - } - } - time.Sleep(2 * time.Second) - } - return "", fmt.Errorf("No IP found for the machine") -} - -func (d *Driver) GetState() (state.State, error) { - log.Debug("Get status for OpenStack instance...", map[string]string{"MachineId": d.MachineId}) - if err := d.initCompute(); err != nil { - return state.None, err - } - - s, err := d.client.GetInstanceState(d) - if err != nil { - return state.None, err - } - - log.Debug("State for OpenStack instance", map[string]string{ - "MachineId": d.MachineId, - "State": s, - }) - - switch s { - case "ACTIVE": - return state.Running, nil - case "PAUSED": - return state.Paused, nil - case "SUSPENDED": - return state.Saved, nil - case "SHUTOFF": - return state.Stopped, nil - case "BUILDING": - return state.Starting, nil - case "ERROR": - return state.Error, nil - } - return state.None, nil -} - -func (d *Driver) Create() error { - if err := d.resolveIds(); err != nil { - return err - } - if d.KeyPairName != "" { - if err := d.loadSSHKey(); err != nil { - return err - } - } else { - d.KeyPairName = fmt.Sprintf("%s-%s", d.MachineName, mcnutils.GenerateRandomID()) - if err := d.createSSHKey(); err != nil { - return err - } - } - if err := d.createMachine(); err != nil { - return err - } - if err := d.waitForInstanceActive(); err != nil { - return err - } - if d.FloatingIpPool != "" { - if err := d.assignFloatingIP(); err != nil { - return err - } - } - if err := d.lookForIPAddress(); err != nil { - return err - } - return nil -} - -func (d *Driver) Start() error { - if err := d.initCompute(); err != nil { - return err - } - - return d.client.StartInstance(d) -} - -func (d *Driver) Stop() error { - if err := d.initCompute(); err != nil { - return err - } - - return d.client.StopInstance(d) -} - -func (d *Driver) Restart() error { - if err := d.initCompute(); err != nil { - return err - } - - return d.client.RestartInstance(d) -} - -func (d *Driver) Kill() error { - return d.Stop() -} - -func (d *Driver) Remove() error { - log.Debug("deleting instance...", map[string]string{"MachineId": d.MachineId}) - log.Info("Deleting OpenStack instance...") - if err := d.initCompute(); err != nil { - return err - } - if err := d.client.DeleteInstance(d); err != nil { - return err - } - log.Debug("deleting key pair...", map[string]string{"Name": d.KeyPairName}) - // TODO (fsoppelsa) maybe we want to check this, in case of shared keypairs, before removal - if err := d.client.DeleteKeyPair(d, d.KeyPairName); err != nil { - return err - } - return nil -} - -const ( - errorMandatoryEnvOrOption string = "%s must be specified either using the environment variable %s or the CLI option %s" - errorMandatoryOption string = "%s must be specified using the CLI option %s" - errorExclusiveOptions string = "Either %s or %s must be specified, not both" - errorBothOptions string = "Both %s and %s must be specified" - errorMandatoryTenantNameOrID string = "Tenant id or name must be provided either using one of the environment variables OS_TENANT_ID and OS_TENANT_NAME or one of the CLI options --openstack-tenant-id and --openstack-tenant-name" - errorWrongEndpointType string = "Endpoint type must be 'publicURL', 'adminURL' or 'internalURL'" - errorUnknownFlavorName string = "Unable to find flavor named %s" - errorUnknownImageName string = "Unable to find image named %s" - errorUnknownNetworkName string = "Unable to find network named %s" - errorUnknownTenantName string = "Unable to find tenant named %s" -) - -func (d *Driver) checkConfig() error { - if d.AuthUrl == "" { - return fmt.Errorf(errorMandatoryEnvOrOption, "Authentication URL", "OS_AUTH_URL", "--openstack-auth-url") - } - if d.Username == "" { - return fmt.Errorf(errorMandatoryEnvOrOption, "Username", "OS_USERNAME", "--openstack-username") - } - if d.Password == "" { - return fmt.Errorf(errorMandatoryEnvOrOption, "Password", "OS_PASSWORD", "--openstack-password") - } - if d.TenantName == "" && d.TenantId == "" { - return fmt.Errorf(errorMandatoryTenantNameOrID) - } - - if d.FlavorName == "" && d.FlavorId == "" { - return fmt.Errorf(errorMandatoryOption, "Flavor name or Flavor id", "--openstack-flavor-name or --openstack-flavor-id") - } - if d.FlavorName != "" && d.FlavorId != "" { - return fmt.Errorf(errorExclusiveOptions, "Flavor name", "Flavor id") - } - - if d.ImageName == "" && d.ImageId == "" { - return fmt.Errorf(errorMandatoryOption, "Image name or Image id", "--openstack-image-name or --openstack-image-id") - } - if d.ImageName != "" && d.ImageId != "" { - return fmt.Errorf(errorExclusiveOptions, "Image name", "Image id") - } - - if d.NetworkName != "" && d.NetworkId != "" { - return fmt.Errorf(errorExclusiveOptions, "Network name", "Network id") - } - if d.EndpointType != "" && (d.EndpointType != "publicURL" && d.EndpointType != "adminURL" && d.EndpointType != "internalURL") { - return fmt.Errorf(errorWrongEndpointType) - } - if (d.KeyPairName != "" && d.PrivateKeyFile == "") || (d.KeyPairName == "" && d.PrivateKeyFile != "") { - return fmt.Errorf(errorBothOptions, "KeyPairName", "PrivateKeyFile") - } - return nil -} - -func (d *Driver) resolveIds() error { - if d.NetworkName != "" && !d.ComputeNetwork { - if err := d.initNetwork(); err != nil { - return err - } - - networkID, err := d.client.GetNetworkID(d) - - if err != nil { - return err - } - - if networkID == "" { - return fmt.Errorf(errorUnknownNetworkName, d.NetworkName) - } - - d.NetworkId = networkID - log.Debug("Found network id using its name", map[string]string{ - "Name": d.NetworkName, - "ID": d.NetworkId, - }) - } - - if d.FlavorName != "" { - if err := d.initCompute(); err != nil { - return err - } - flavorID, err := d.client.GetFlavorID(d) - - if err != nil { - return err - } - - if flavorID == "" { - return fmt.Errorf(errorUnknownFlavorName, d.FlavorName) - } - - d.FlavorId = flavorID - log.Debug("Found flavor id using its name", map[string]string{ - "Name": d.FlavorName, - "ID": d.FlavorId, - }) - } - - if d.ImageName != "" { - if err := d.initCompute(); err != nil { - return err - } - imageID, err := d.client.GetImageID(d) - - if err != nil { - return err - } - - if imageID == "" { - return fmt.Errorf(errorUnknownImageName, d.ImageName) - } - - d.ImageId = imageID - log.Debug("Found image id using its name", map[string]string{ - "Name": d.ImageName, - "ID": d.ImageId, - }) - } - - if d.FloatingIpPool != "" && !d.ComputeNetwork { - if err := d.initNetwork(); err != nil { - return err - } - f, err := d.client.GetFloatingIPPoolID(d) - - if err != nil { - return err - } - - if f == "" { - return fmt.Errorf(errorUnknownNetworkName, d.FloatingIpPool) - } - - d.FloatingIpPoolId = f - log.Debug("Found floating IP pool id using its name", map[string]string{ - "Name": d.FloatingIpPool, - "ID": d.FloatingIpPoolId, - }) - } - - if d.TenantName != "" && d.TenantId == "" { - if err := d.initIdentity(); err != nil { - return err - } - tenantId, err := d.client.GetTenantID(d) - - if err != nil { - return err - } - - if tenantId == "" { - return fmt.Errorf(errorUnknownTenantName, d.TenantName) - } - - d.TenantId = tenantId - log.Debug("Found tenant id using its name", map[string]string{ - "Name": d.TenantName, - "ID": d.TenantId, - }) - } - - return nil -} - -func (d *Driver) initCompute() error { - if err := d.client.Authenticate(d); err != nil { - return err - } - if err := d.client.InitComputeClient(d); err != nil { - return err - } - return nil -} - -func (d *Driver) initIdentity() error { - if err := d.client.Authenticate(d); err != nil { - return err - } - if err := d.client.InitIdentityClient(d); err != nil { - return err - } - return nil -} - -func (d *Driver) initNetwork() error { - if err := d.client.Authenticate(d); err != nil { - return err - } - if err := d.client.InitNetworkClient(d); err != nil { - return err - } - return nil -} - -func (d *Driver) loadSSHKey() error { - log.Debug("Loading Key Pair", d.KeyPairName) - if err := d.initCompute(); err != nil { - return err - } - log.Debug("Loading Private Key from", d.PrivateKeyFile) - privateKey, err := ioutil.ReadFile(d.PrivateKeyFile) - if err != nil { - return err - } - publicKey, err := d.client.GetPublicKey(d.KeyPairName) - if err != nil { - return err - } - if err := ioutil.WriteFile(d.privateSSHKeyPath(), privateKey, 0600); err != nil { - return err - } - if err := ioutil.WriteFile(d.publicSSHKeyPath(), publicKey, 0600); err != nil { - return err - } - - return nil -} - -func (d *Driver) createSSHKey() error { - sanitizeKeyPairName(&d.KeyPairName) - log.Debug("Creating Key Pair...", map[string]string{"Name": d.KeyPairName}) - if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { - return err - } - publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath()) - if err != nil { - return err - } - - if err := d.initCompute(); err != nil { - return err - } - if err := d.client.CreateKeyPair(d, d.KeyPairName, string(publicKey)); err != nil { - return err - } - return nil -} - -func (d *Driver) createMachine() error { - log.Debug("Creating OpenStack instance...", map[string]string{ - "FlavorId": d.FlavorId, - "ImageId": d.ImageId, - }) - - if err := d.initCompute(); err != nil { - return err - } - instanceID, err := d.client.CreateInstance(d) - if err != nil { - return err - } - d.MachineId = instanceID - return nil -} - -func (d *Driver) assignFloatingIP() error { - var err error - - if d.ComputeNetwork { - err = d.initCompute() - } else { - err = d.initNetwork() - } - - if err != nil { - return err - } - - ips, err := d.client.GetFloatingIPs(d) - if err != nil { - return err - } - - var floatingIP *FloatingIP - - log.Debugf("Looking for an available floating IP", map[string]string{ - "MachineId": d.MachineId, - "Pool": d.FloatingIpPool, - }) - - for _, ip := range ips { - if ip.PortId == "" { - log.Debug("Available floating IP found", map[string]string{ - "MachineId": d.MachineId, - "IP": ip.Ip, - }) - floatingIP = &ip - break - } - } - - if floatingIP == nil { - floatingIP = &FloatingIP{} - log.Debug("No available floating IP found. Allocating a new one...", map[string]string{"MachineId": d.MachineId}) - } else { - log.Debug("Assigning floating IP to the instance", map[string]string{"MachineId": d.MachineId}) - } - - if err := d.client.AssignFloatingIP(d, floatingIP); err != nil { - return err - } - d.IPAddress = floatingIP.Ip - return nil -} - -func (d *Driver) waitForInstanceActive() error { - log.Debug("Waiting for the OpenStack instance to be ACTIVE...", map[string]string{"MachineId": d.MachineId}) - if err := d.client.WaitForInstanceStatus(d, "ACTIVE"); err != nil { - return err - } - return nil -} - -func (d *Driver) lookForIPAddress() error { - ip, err := d.GetIP() - if err != nil { - return err - } - d.IPAddress = ip - log.Debug("IP address found", map[string]string{ - "IP": ip, - "MachineId": d.MachineId, - }) - return nil -} - -func (d *Driver) privateSSHKeyPath() string { - return d.GetSSHKeyPath() -} - -func (d *Driver) publicSSHKeyPath() string { - return d.GetSSHKeyPath() + ".pub" -} - -func sanitizeKeyPairName(s *string) { - *s = strings.Replace(*s, ".", "_", -1) -} diff --git a/vendor/github.com/docker/machine/drivers/openstack/openstack_test.go b/vendor/github.com/docker/machine/drivers/openstack/openstack_test.go deleted file mode 100644 index 49134c0..0000000 --- a/vendor/github.com/docker/machine/drivers/openstack/openstack_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package openstack - -import ( - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -func TestSetConfigFromFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "openstack-auth-url": "http://url", - "openstack-username": "user", - "openstack-password": "pwd", - "openstack-tenant-id": "ID", - "openstack-flavor-id": "ID", - "openstack-image-id": "ID", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) -} diff --git a/vendor/github.com/docker/machine/drivers/rackspace/client.go b/vendor/github.com/docker/machine/drivers/rackspace/client.go deleted file mode 100644 index b73263f..0000000 --- a/vendor/github.com/docker/machine/drivers/rackspace/client.go +++ /dev/null @@ -1,79 +0,0 @@ -package rackspace - -import ( - "fmt" - - "github.com/docker/machine/drivers/openstack" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/version" - "github.com/rackspace/gophercloud" - "github.com/rackspace/gophercloud/rackspace" -) - -func unsupportedOpErr(operation string) error { - return fmt.Errorf("Rackspace does not currently support the %s operation", operation) -} - -// Client is a Rackspace specialization of the generic OpenStack driver. -type Client struct { - openstack.GenericClient - driver *Driver -} - -// Authenticate creates a Rackspace-specific Gophercloud client. -func (c *Client) Authenticate(d *openstack.Driver) error { - if c.Provider != nil { - return nil - } - - log.Debug("Authenticating to Rackspace.", map[string]string{ - "Username": d.Username, - }) - - apiKey := c.driver.APIKey - opts := gophercloud.AuthOptions{ - Username: d.Username, - APIKey: apiKey, - } - - provider, err := rackspace.NewClient(rackspace.RackspaceUSIdentity) - if err != nil { - return err - } - - provider.UserAgent.Prepend(fmt.Sprintf("docker-machine/v%d", version.APIVersion)) - - err = rackspace.Authenticate(provider, opts) - if err != nil { - return err - } - - c.Provider = provider - - return nil -} - -// StartInstance is unfortunately not supported on Rackspace at this time. -func (c *Client) StartInstance(d *openstack.Driver) error { - return unsupportedOpErr("start") -} - -// StopInstance is unfortunately not support on Rackspace at this time. -func (c *Client) StopInstance(d *openstack.Driver) error { - return unsupportedOpErr("stop") -} - -// GetInstanceIPAddresses can be short-circuited with the server's AccessIPv4Addr on Rackspace. -func (c *Client) GetInstanceIPAddresses(d *openstack.Driver) ([]openstack.IPAddress, error) { - server, err := c.GetServerDetail(d) - if err != nil { - return nil, err - } - return []openstack.IPAddress{ - { - Network: "public", - Address: server.AccessIPv4, - AddressType: openstack.Fixed, - }, - }, nil -} diff --git a/vendor/github.com/docker/machine/drivers/rackspace/rackspace.go b/vendor/github.com/docker/machine/drivers/rackspace/rackspace.go deleted file mode 100644 index 5e6bb49..0000000 --- a/vendor/github.com/docker/machine/drivers/rackspace/rackspace.go +++ /dev/null @@ -1,158 +0,0 @@ -package rackspace - -import ( - "fmt" - - "github.com/docker/machine/drivers/openstack" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" -) - -// Driver is a machine driver for Rackspace. It's a specialization of the generic OpenStack one. -type Driver struct { - *openstack.Driver - - APIKey string -} - -const ( - defaultRegionName = "IAD" - defaultEndpointType = "publicURL" - defaultFlavorID = "general1-1" - defaultSSHUser = "root" - defaultSSHPort = 22 - defaultDockerInstall = "true" - defaultActiveTimeout = 300 -) - -// GetCreateFlags registers the "machine create" flags recognized by this driver, including -// their help text and defaults. -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - EnvVar: "OS_USERNAME", - Name: "rackspace-username", - Usage: "Rackspace account username", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_API_KEY", - Name: "rackspace-api-key", - Usage: "Rackspace API key", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "OS_REGION_NAME", - Name: "rackspace-region", - Usage: "Rackspace region name", - Value: defaultRegionName, - }, - mcnflag.StringFlag{ - EnvVar: "OS_ENDPOINT_TYPE", - Name: "rackspace-endpoint-type", - Usage: "Rackspace endpoint type (adminURL, internalURL or the default publicURL)", - Value: defaultEndpointType, - }, - mcnflag.StringFlag{ - EnvVar: "OS_IMAGE_ID", - Name: "rackspace-image-id", - Usage: "Rackspace image ID. Default: Ubuntu 16.04 LTS (Xenial Xerus) (PVHVM)", - }, - mcnflag.StringFlag{ - EnvVar: "OS_FLAVOR_ID", - Name: "rackspace-flavor-id", - Usage: "Rackspace flavor ID. Default: General Purpose 1GB", - Value: defaultFlavorID, - }, - mcnflag.StringFlag{ - EnvVar: "OS_SSH_USER", - Name: "rackspace-ssh-user", - Usage: "SSH user for the newly booted machine. Set to root by default", - Value: defaultSSHUser, - }, - mcnflag.IntFlag{ - EnvVar: "OS_SSH_PORT", - Name: "rackspace-ssh-port", - Usage: "SSH port for the newly booted machine. Set to 22 by default", - Value: defaultSSHPort, - }, - mcnflag.StringFlag{ - Name: "rackspace-docker-install", - Usage: "Set if docker have to be installed on the machine", - Value: defaultDockerInstall, - }, - mcnflag.IntFlag{ - EnvVar: "OS_ACTIVE_TIMEOUT", - Name: "rackspace-active-timeout", - Usage: "Rackspace active timeout", - Value: defaultActiveTimeout, - }, - } -} - -// NewDriver instantiates a Rackspace driver. -func NewDriver(machineName, storePath string) drivers.Driver { - log.Debug("Instantiating Rackspace driver.", map[string]string{"machineName": machineName}) - - inner := openstack.NewDerivedDriver(machineName, storePath) - driver := &Driver{ - Driver: inner, - } - inner.SetClient(&Client{ - driver: driver, - }) - - return driver -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "rackspace" -} - -func missingEnvOrOption(setting, envVar, opt string) error { - return fmt.Errorf( - "%s must be specified either using the environment variable %s or the CLI option %s", - setting, - envVar, - opt, - ) -} - -// SetConfigFromFlags assigns and verifies the command-line arguments presented to the driver. -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.ActiveTimeout = flags.Int("rackspace-active-timeout") - d.Username = flags.String("rackspace-username") - d.APIKey = flags.String("rackspace-api-key") - d.Region = flags.String("rackspace-region") - d.EndpointType = flags.String("rackspace-endpoint-type") - d.ImageId = flags.String("rackspace-image-id") - d.FlavorId = flags.String("rackspace-flavor-id") - d.SSHUser = flags.String("rackspace-ssh-user") - d.SSHPort = flags.Int("rackspace-ssh-port") - d.SetSwarmConfigFromFlags(flags) - - if d.Region == "" { - return missingEnvOrOption("Region", "OS_REGION_NAME", "--rackspace-region") - } - if d.Username == "" { - return missingEnvOrOption("Username", "OS_USERNAME", "--rackspace-username") - } - if d.APIKey == "" { - return missingEnvOrOption("API key", "OS_API_KEY", "--rackspace-api-key") - } - - if d.ImageId == "" { - // Default to the Ubuntu 16.04 image. - // This is done here, rather than in the option registration, to keep the default value - // from making "machine create --help" ugly. - d.ImageId = "821ba5f4-712d-4ec8-9c65-a3fa4bc500f9" - } - - if d.EndpointType != "publicURL" && d.EndpointType != "adminURL" && d.EndpointType != "internalURL" { - return fmt.Errorf("invalid endpoint type %q (must be publicURL, adminURL or internalURL)", d.EndpointType) - } - - return nil -} diff --git a/vendor/github.com/docker/machine/drivers/rackspace/rackspace_test.go b/vendor/github.com/docker/machine/drivers/rackspace/rackspace_test.go deleted file mode 100644 index 7924153..0000000 --- a/vendor/github.com/docker/machine/drivers/rackspace/rackspace_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package rackspace - -import ( - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -func TestSetConfigFromFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "rackspace-region": "REGION", - "rackspace-username": "user", - "rackspace-api-key": "KEY", - "rackspace-endpoint-type": "publicURL", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) -} diff --git a/vendor/github.com/docker/machine/drivers/softlayer/driver.go b/vendor/github.com/docker/machine/drivers/softlayer/driver.go deleted file mode 100644 index b2d37e8..0000000 --- a/vendor/github.com/docker/machine/drivers/softlayer/driver.go +++ /dev/null @@ -1,534 +0,0 @@ -package softlayer - -import ( - "fmt" - "io/ioutil" - "net" - "os" - "regexp" - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" -) - -const ( - APIEndpoint = "https://api.softlayer.com/rest/v3" -) - -type Driver struct { - *drivers.BaseDriver - deviceConfig *deviceConfig - Id int - Client *Client - SSHKeyID int -} - -type deviceConfig struct { - DiskSize int - Cpu int - Hostname string - Domain string - Region string - Memory int - Image string - HourlyBilling bool - LocalDisk bool - PrivateNet bool - PublicVLAN int - PrivateVLAN int - NetworkMaxSpeed int -} - -const ( - defaultMemory = 1024 - defaultDiskSize = 0 - defaultRegion = "dal01" - defaultCpus = 1 - defaultImage = "UBUNTU_LATEST" - defaultPublicVLANIP = 0 - defaultPrivateVLANIP = 0 - defaultNetworkMaxSpeed = 100 -) - -func NewDriver(hostName, storePath string) drivers.Driver { - return &Driver{ - Client: &Client{ - Endpoint: APIEndpoint, - }, - deviceConfig: &deviceConfig{ - HourlyBilling: true, - DiskSize: defaultDiskSize, - Image: defaultImage, - Memory: defaultMemory, - Cpu: defaultCpus, - Region: defaultRegion, - PrivateVLAN: defaultPrivateVLANIP, - PublicVLAN: defaultPublicVLANIP, - NetworkMaxSpeed: defaultNetworkMaxSpeed, - }, - BaseDriver: &drivers.BaseDriver{ - MachineName: hostName, - StorePath: storePath, - }, - } -} - -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - // Set hourly billing to true by default since codegangsta cli doesn't take default bool values - if os.Getenv("SOFTLAYER_HOURLY_BILLING") == "" { - os.Setenv("SOFTLAYER_HOURLY_BILLING", "true") - } - return []mcnflag.Flag{ - mcnflag.IntFlag{ - EnvVar: "SOFTLAYER_MEMORY", - Name: "softlayer-memory", - Usage: "Memory in MB for machine", - Value: defaultMemory, - }, - mcnflag.IntFlag{ - EnvVar: "SOFTLAYER_DISK_SIZE", - Name: "softlayer-disk-size", - Usage: "Disk size for machine, a value of 0 uses the default size on softlayer", - Value: defaultDiskSize, - }, - mcnflag.StringFlag{ - EnvVar: "SOFTLAYER_USER", - Name: "softlayer-user", - Usage: "softlayer user account name", - }, - mcnflag.StringFlag{ - EnvVar: "SOFTLAYER_API_KEY", - Name: "softlayer-api-key", - Usage: "softlayer user API key", - }, - mcnflag.StringFlag{ - EnvVar: "SOFTLAYER_REGION", - Name: "softlayer-region", - Usage: "softlayer region for machine", - Value: defaultRegion, - }, - mcnflag.IntFlag{ - EnvVar: "SOFTLAYER_CPU", - Name: "softlayer-cpu", - Usage: "number of CPU's for the machine", - Value: defaultCpus, - }, - mcnflag.StringFlag{ - EnvVar: "SOFTLAYER_HOSTNAME", - Name: "softlayer-hostname", - Usage: "hostname for the machine - defaults to machine name", - }, - mcnflag.StringFlag{ - EnvVar: "SOFTLAYER_DOMAIN", - Name: "softlayer-domain", - Usage: "domain name for machine", - }, - mcnflag.StringFlag{ - EnvVar: "SOFTLAYER_API_ENDPOINT", - Name: "softlayer-api-endpoint", - Usage: "softlayer api endpoint to use", - Value: APIEndpoint, - }, - mcnflag.BoolFlag{ - EnvVar: "SOFTLAYER_HOURLY_BILLING", - Name: "softlayer-hourly-billing", - Usage: "set hourly billing for machine - on by default", - }, - mcnflag.BoolFlag{ - EnvVar: "SOFTLAYER_LOCAL_DISK", - Name: "softlayer-local-disk", - Usage: "use machine local disk instead of softlayer SAN", - }, - mcnflag.BoolFlag{ - EnvVar: "SOFTLAYER_PRIVATE_NET", - Name: "softlayer-private-net-only", - Usage: "Use only private networking", - }, - mcnflag.StringFlag{ - EnvVar: "SOFTLAYER_IMAGE", - Name: "softlayer-image", - Usage: "OS image for machine", - Value: defaultImage, - }, - mcnflag.IntFlag{ - EnvVar: "SOFTLAYER_PUBLIC_VLAN_ID", - Name: "softlayer-public-vlan-id", - Usage: "", - }, - mcnflag.IntFlag{ - EnvVar: "SOFTLAYER_PRIVATE_VLAN_ID", - Name: "softlayer-private-vlan-id", - Usage: "", - }, - mcnflag.IntFlag{ - EnvVar: "SOFTLAYER_NETWORK_MAX_SPEED", - Name: "softlayer-network-max-speed", - Usage: "Max speed of public and private network", - Value: defaultNetworkMaxSpeed, - }, - } -} - -func validateDeviceConfig(c *deviceConfig) error { - if c.Domain == "" { - return fmt.Errorf("Missing required setting - --softlayer-domain") - } - - if c.Region == "" { - return fmt.Errorf("Missing required setting - --softlayer-region") - } - if c.Cpu < 1 { - return fmt.Errorf("Missing required setting - --softlayer-cpu") - } - - if c.PrivateNet && c.PublicVLAN > 0 { - return fmt.Errorf("Can not specify both --softlayer-private-net-only and --softlayer-public-vlan-id") - } - if c.PublicVLAN > 0 && c.PrivateVLAN == 0 { - return fmt.Errorf("Missing required setting - --softlayer-private-vlan-id (because --softlayer-public-vlan-id is specified)") - } - if c.PrivateVLAN > 0 && !c.PrivateNet && c.PublicVLAN == 0 { - return fmt.Errorf("Missing required setting - --softlayer-public-vlan-id (because --softlayer-private-vlan-id is specified)") - } - - return nil -} - -func validateClientConfig(c *Client) error { - if c.ApiKey == "" { - return fmt.Errorf("Missing required setting - --softlayer-api-key") - } - - if c.User == "" { - return fmt.Errorf("Missing required setting - --softlayer-user") - } - - if c.Endpoint == "" { - return fmt.Errorf("Missing required setting - --softlayer-api-endpoint") - } - - return nil -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - - d.Client = &Client{ - Endpoint: flags.String("softlayer-api-endpoint"), - User: flags.String("softlayer-user"), - ApiKey: flags.String("softlayer-api-key"), - } - - d.SetSwarmConfigFromFlags(flags) - d.SSHUser = "root" - d.SSHPort = 22 - - if err := validateClientConfig(d.Client); err != nil { - return err - } - - d.deviceConfig = &deviceConfig{ - Hostname: flags.String("softlayer-hostname"), - DiskSize: flags.Int("softlayer-disk-size"), - Cpu: flags.Int("softlayer-cpu"), - Domain: flags.String("softlayer-domain"), - Memory: flags.Int("softlayer-memory"), - PrivateNet: flags.Bool("softlayer-private-net-only"), - LocalDisk: flags.Bool("softlayer-local-disk"), - HourlyBilling: flags.Bool("softlayer-hourly-billing"), - Image: flags.String("softlayer-image"), - Region: flags.String("softlayer-region"), - PublicVLAN: flags.Int("softlayer-public-vlan-id"), - PrivateVLAN: flags.Int("softlayer-private-vlan-id"), - NetworkMaxSpeed: flags.Int("softlayer-network-max-speed"), - } - - if d.deviceConfig.Hostname == "" { - d.deviceConfig.Hostname = d.GetMachineName() - } - - return validateDeviceConfig(d.deviceConfig) -} - -func (d *Driver) getClient() *Client { - return d.Client -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "softlayer" -} - -func (d *Driver) GetURL() (string, error) { - if err := drivers.MustBeRunning(d); err != nil { - return "", err - } - - ip, err := d.GetIP() - if err != nil { - return "", err - } - if ip == "" { - return "", nil - } - - return "tcp://" + net.JoinHostPort(ip, "2376"), nil -} - -func (d *Driver) GetIP() (string, error) { - if d.IPAddress != "" { - return d.IPAddress, nil - } - if d.deviceConfig != nil && d.deviceConfig.PrivateNet == true { - return d.getClient().VirtualGuest().GetPrivateIP(d.Id) - } - - if os.Getenv("SOFTLAYER_DOCKER_ON_PRIVATE_IP") == "" { - os.Setenv("SOFTLAYER_DOCKER_ON_PRIVATE_IP", "false") - } - - if os.Getenv("SOFTLAYER_DOCKER_ON_PRIVATE_IP") == "true" { - return d.getClient().VirtualGuest().GetPrivateIP(d.Id) - } else { - return d.getClient().VirtualGuest().GetPublicIP(d.Id) - } -} - -func (d *Driver) GetState() (state.State, error) { - s, err := d.getClient().VirtualGuest().PowerState(d.Id) - if err != nil { - return state.None, err - } - var vmState state.State - switch s { - case "Running": - vmState = state.Running - case "Halted": - vmState = state.Stopped - default: - vmState = state.None - } - return vmState, nil -} - -func (d *Driver) GetActiveTransaction() (string, error) { - t, err := d.getClient().VirtualGuest().ActiveTransaction(d.Id) - if err != nil { - return "", err - } - return t, nil -} - -func (d *Driver) waitForStart() { - log.Infof("Waiting for host to become available") - for { - s, err := d.GetState() - if err != nil { - log.Debugf("Failed to GetState - %+v", err) - continue - } - - if s == state.Running { - break - } else { - log.Debugf("Still waiting - state is %s...", s) - } - time.Sleep(2 * time.Second) - } -} - -func (d *Driver) getIP() (string, error) { - log.Infof("Getting Host IP") - for { - var ( - ip string - err error - ) - if d.deviceConfig.PrivateNet { - ip, err = d.getClient().VirtualGuest().GetPrivateIP(d.Id) - } else { - ip, err = d.getClient().VirtualGuest().GetPublicIP(d.Id) - } - if err != nil { - time.Sleep(2 * time.Second) - continue - } - - // if docker daemon is expected to run on private IP - // it will overwrite settings from PrivateNet - if os.Getenv("SOFTLAYER_DOCKER_ON_PRIVATE_IP") == "" { - os.Setenv("SOFTLAYER_DOCKER_ON_PRIVATE_IP", "false") - } - - if os.Getenv("SOFTLAYER_DOCKER_ON_PRIVATE_IP") == "true" { - ip, err = d.getClient().VirtualGuest().GetPrivateIP(d.Id) - } else { - ip, err = d.getClient().VirtualGuest().GetPublicIP(d.Id) - } - - // not a perfect regex, but should be just fine for our needs - exp := regexp.MustCompile(`\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}`) - if exp.MatchString(ip) { - d.IPAddress = ip - return ip, nil - } - time.Sleep(2 * time.Second) - } -} - -func (d *Driver) waitForSetupTransactions() { - log.Infof("Waiting for host setup transactions to complete") - // sometimes we'll hit a case where there's no active transaction, but if - // we check again in a few seconds, it moves to the next transaction. We - // don't want to get false-positives, so we check a few times in a row to make sure! - noActiveCount, maxNoActiveCount := 0, 3 - for { - t, err := d.GetActiveTransaction() - if err != nil { - noActiveCount = 0 - log.Debugf("Failed to GetActiveTransaction - %+v", err) - continue - } - - if t == "" { - if noActiveCount == maxNoActiveCount { - break - } - noActiveCount++ - } else { - noActiveCount = 0 - log.Debugf("Still waiting - active transaction is %s...", t) - } - time.Sleep(2 * time.Second) - } -} - -func (d *Driver) Create() error { - spec := d.buildHostSpec() - - log.Infof("Creating SSH key...") - key, err := d.createSSHKey() - if err != nil { - return err - } - - log.Infof("SSH key %s (%d) created in SoftLayer", key.Label, key.Id) - d.SSHKeyID = key.Id - - spec.SshKeys = []*SSHKey{key} - - id, err := d.getClient().VirtualGuest().Create(spec) - if err != nil { - return fmt.Errorf("Error creating host: %q", err) - } - d.Id = id - d.getIP() - d.waitForStart() - d.waitForSetupTransactions() - - return nil -} - -func (d *Driver) buildHostSpec() *HostSpec { - spec := &HostSpec{ - Hostname: d.deviceConfig.Hostname, - Domain: d.deviceConfig.Domain, - Cpu: d.deviceConfig.Cpu, - Memory: d.deviceConfig.Memory, - Datacenter: Datacenter{Name: d.deviceConfig.Region}, - Os: d.deviceConfig.Image, - HourlyBilling: d.deviceConfig.HourlyBilling, - PrivateNetOnly: d.deviceConfig.PrivateNet, - LocalDisk: d.deviceConfig.LocalDisk, - } - - if d.deviceConfig.NetworkMaxSpeed > 0 { - spec.NetworkMaxSpeeds = []NetworkMaxSpeed{{MaxSpeed: d.deviceConfig.NetworkMaxSpeed}} - } - if d.deviceConfig.DiskSize > 0 { - spec.BlockDevices = []BlockDevice{{Device: "0", DiskImage: DiskImage{Capacity: d.deviceConfig.DiskSize}}} - } - if d.deviceConfig.PublicVLAN > 0 { - spec.PrimaryNetworkComponent = &NetworkComponent{ - NetworkVLAN: &NetworkVLAN{ - Id: d.deviceConfig.PublicVLAN, - }, - } - } - if d.deviceConfig.PrivateVLAN > 0 { - spec.PrimaryBackendNetworkComponent = &NetworkComponent{ - NetworkVLAN: &NetworkVLAN{ - Id: d.deviceConfig.PrivateVLAN, - }, - } - } - log.Debugf("Built host spec %#v", spec) - return spec -} - -func (d *Driver) createSSHKey() (*SSHKey, error) { - if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { - return nil, err - } - - publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath()) - if err != nil { - return nil, err - } - - key, err := d.getClient().SSHKey().Create(d.deviceConfig.Hostname, string(publicKey)) - if err != nil { - return nil, err - } - - return key, nil -} - -func (d *Driver) publicSSHKeyPath() string { - return d.GetSSHKeyPath() + ".pub" -} - -func (d *Driver) Remove() error { - log.Infof("Canceling SoftLayer instance %d...", d.Id) - var err error - for i := 0; i < 5; i++ { - if err = d.getClient().VirtualGuest().Cancel(d.Id); err != nil { - time.Sleep(2 * time.Second) - continue - } - break - } - if err != nil { - return err - } - - log.Infof("Removing SSH Key %d...", d.SSHKeyID) - if err = d.getClient().SSHKey().Delete(d.SSHKeyID); err != nil { - return err - } - - return nil -} - -func (d *Driver) Start() error { - return d.getClient().VirtualGuest().PowerOn(d.Id) -} - -func (d *Driver) Stop() error { - return d.getClient().VirtualGuest().PowerOff(d.Id) -} - -func (d *Driver) Restart() error { - return d.getClient().VirtualGuest().Reboot(d.Id) -} - -func (d *Driver) Kill() error { - return d.Stop() -} diff --git a/vendor/github.com/docker/machine/drivers/softlayer/driver_test.go b/vendor/github.com/docker/machine/drivers/softlayer/driver_test.go deleted file mode 100644 index ab8c6b4..0000000 --- a/vendor/github.com/docker/machine/drivers/softlayer/driver_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package softlayer - -import ( - "io/ioutil" - "os" - "testing" - - "github.com/docker/machine/commands/commandstest" - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -const ( - testStoreDir = ".store-test" - machineTestName = "test-host" - machineTestCaCert = "test-cert" - machineTestPrivateKey = "test-key" -) - -func cleanup() error { - return os.RemoveAll(testStoreDir) -} - -func getTestStorePath() (string, error) { - tmpDir, err := ioutil.TempDir("", "machine-test-") - if err != nil { - return "", err - } - mcndirs.BaseDir = tmpDir - return tmpDir, nil -} - -func getDefaultTestDriverFlags() *commandstest.FakeFlagger { - return &commandstest.FakeFlagger{ - Data: map[string]interface{}{ - "name": "test", - "url": "unix:///var/run/docker.sock", - "softlayer-api-key": "12345", - "softlayer-user": "abcdefg", - "softlayer-api-endpoint": "https://api.softlayer.com/rest/v3", - "softlayer-image": "MY_TEST_IMAGE", - }, - } -} - -func getTestDriver() (*Driver, error) { - storePath, err := getTestStorePath() - if err != nil { - return nil, err - } - defer cleanup() - - d := NewDriver(machineTestName, storePath) - d.SetConfigFromFlags(getDefaultTestDriverFlags()) - drv := d.(*Driver) - return drv, nil -} - -func TestSetConfigFromFlagsSetsImage(t *testing.T) { - d, err := getTestDriver() - - if assert.NoError(t, err) { - assert.Equal(t, "MY_TEST_IMAGE", d.deviceConfig.Image) - } -} - -func TestHostnameDefaultsToMachineName(t *testing.T) { - d, err := getTestDriver() - if assert.NoError(t, err) { - assert.Equal(t, machineTestName, d.deviceConfig.Hostname) - } -} - -func TestSetConfigFromFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "softlayer-api-key": "KEY", - "softlayer-user": "user", - "softlayer-api-endpoint": "ENDPOINT", - "softlayer-domain": "DOMAIN", - "softlayer-region": "REGION", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) -} diff --git a/vendor/github.com/docker/machine/drivers/softlayer/softlayer.go b/vendor/github.com/docker/machine/drivers/softlayer/softlayer.go deleted file mode 100644 index 5b12d70..0000000 --- a/vendor/github.com/docker/machine/drivers/softlayer/softlayer.go +++ /dev/null @@ -1,369 +0,0 @@ -package softlayer - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" -) - -type Client struct { - User string - ApiKey string - Endpoint string -} - -type HostSpec struct { - Hostname string `json:"hostname"` - Domain string `json:"domain"` - Cpu int `json:"startCpus"` - Memory int `json:"maxMemory"` - Datacenter Datacenter `json:"datacenter"` - SshKeys []*SSHKey `json:"sshKeys"` - BlockDevices []BlockDevice `json:"blockDevices"` - NetworkMaxSpeeds []NetworkMaxSpeed `json:"networkComponents"` - InstallScript string `json:"postInstallScriptUri"` - PrivateNetOnly bool `json:"privateNetworkOnlyFlag"` - Os string `json:"operatingSystemReferenceCode"` - HourlyBilling bool `json:"hourlyBillingFlag"` - LocalDisk bool `json:"localDiskFlag"` - PrimaryNetworkComponent *NetworkComponent `json:"primaryNetworkComponent,omitempty"` - PrimaryBackendNetworkComponent *NetworkComponent `json:"primaryBackendNetworkComponent,omitempty"` -} - -type NetworkMaxSpeed struct { - MaxSpeed int `json:"maxSpeed"` -} - -type NetworkComponent struct { - NetworkVLAN *NetworkVLAN `json:"networkVlan"` -} - -type NetworkVLAN struct { - Id int `json:"id"` -} - -type SSHKey struct { - Key string `json:"key,omitempty"` - Id int `json:"id,omitempty"` - Label string `json:"label,omitempty"` -} - -type BlockDevice struct { - Device string `json:"device"` - DiskImage DiskImage `json:"diskImage"` -} - -type DiskImage struct { - Capacity int `json:"capacity"` -} - -type Datacenter struct { - Name string `json:"name"` -} - -type sshKey struct { - *Client -} - -type VirtualGuest struct { - *Client -} - -func NewClient(user, key, endpoint string) *Client { - return &Client{User: user, ApiKey: key, Endpoint: endpoint} -} - -func (c *Client) isOkStatus(code int) bool { - codes := map[int]bool{ - 200: true, - 201: true, - 204: true, - 400: false, - 404: false, - 500: false, - 409: false, - 406: false, - } - - return codes[code] -} - -func (c *Client) newRequest(method, uri string, body interface{}) ([]byte, error) { - var ( - client = &http.Client{} - url = fmt.Sprintf("%s/%s", c.Endpoint, uri) - err error - req *http.Request - ) - - if body != nil { - bodyJSON, err := json.Marshal(body) - if err != nil { - return nil, err - } - req, err = http.NewRequest(method, url, bytes.NewBuffer(bodyJSON)) - } else { - req, err = http.NewRequest(method, url, nil) - } - - if err != nil { - return nil, fmt.Errorf("Error with request: %v - %q", url, err) - } - - req.SetBasicAuth(c.User, c.ApiKey) - req.Method = method - - resp, err := client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - data, err := ioutil.ReadAll(resp.Body) - if !c.isOkStatus(resp.StatusCode) { - type apiErr struct { - Err string `json:"error"` - } - var outErr apiErr - json.Unmarshal(data, &outErr) - return nil, fmt.Errorf("Error in response: %s", outErr.Err) - } - if err != nil { - return nil, err - } - - return data, nil -} - -func (c *Client) SSHKey() *sshKey { - return &sshKey{c} -} - -func (c *sshKey) namespace() string { - return "SoftLayer_Security_Ssh_Key" -} - -func (c *sshKey) Create(label, key string) (*SSHKey, error) { - var ( - method = "POST" - uri = c.namespace() - body = SSHKey{Key: key, Label: label} - ) - - data, err := c.newRequest(method, uri, map[string]interface{}{"parameters": []interface{}{body}}) - if err != nil { - return nil, err - } - - var k SSHKey - if err := json.Unmarshal(data, &k); err != nil { - return nil, err - } - - return &k, nil -} - -func (c *sshKey) Delete(id int) error { - var ( - method = "DELETE" - uri = fmt.Sprintf("%s/%v", c.namespace(), id) - ) - - _, err := c.newRequest(method, uri, nil) - if err != nil { - return err - } - return nil -} - -func (c *Client) VirtualGuest() *VirtualGuest { - return &VirtualGuest{c} -} - -func (c *VirtualGuest) namespace() string { - return "SoftLayer_Virtual_Guest" -} - -func (c *VirtualGuest) PowerState(id int) (string, error) { - type state struct { - KeyName string `json:"keyName"` - Name string `json:"name"` - } - var ( - method = "GET" - uri = fmt.Sprintf("%s/%v/getPowerState.json", c.namespace(), id) - ) - - data, err := c.newRequest(method, uri, nil) - if err != nil { - return "", err - } - var s state - if err := json.Unmarshal(data, &s); err != nil { - return "", err - } - - return s.Name, nil -} - -func (c *VirtualGuest) ActiveTransaction(id int) (string, error) { - type transactionStatus struct { - AverageDuration string `json:"averageDuration"` - FriendlyName string `json:"friendlyName"` - Name string `json:"name"` - } - type transaction struct { - CreateDate string `json:"createDate"` - ElapsedSeconds int `json:"elapsedSeconds"` - GuestID int `json:"guestId"` - HardwareID int `json:"hardwareId"` - ID int `json:"id"` - ModifyDate string `json:"modifyDate"` - StatusChangeDate string `json:"statusChangeDate"` - TransactionStatus transactionStatus `json:"transactionStatus"` - } - var ( - method = "GET" - uri = fmt.Sprintf("%s/%v/getActiveTransaction.json", c.namespace(), id) - ) - - data, err := c.newRequest(method, uri, nil) - if err != nil { - return "", err - } - var t transaction - if err := json.Unmarshal(data, &t); err != nil { - return "", err - } - - return t.TransactionStatus.Name, nil -} - -func (c *VirtualGuest) Create(spec *HostSpec) (int, error) { - var ( - method = "POST" - uri = c.namespace() + ".json" - ) - - data, err := c.newRequest(method, uri, map[string]interface{}{"parameters": []interface{}{spec}}) - if err != nil { - return -1, err - } - - type createResp struct { - ID int `json:"id"` - } - - var r createResp - if err := json.Unmarshal(data, &r); err != nil { - return -1, err - } - - return r.ID, nil -} - -func (c *VirtualGuest) Cancel(id int) error { - var ( - method = "DELETE" - uri = fmt.Sprintf("%s/%v", c.namespace(), id) - ) - - _, err := c.newRequest(method, uri, nil) - if err != nil { - return err - } - return nil -} - -func (c *VirtualGuest) PowerOn(id int) error { - var ( - method = "GET" - uri = fmt.Sprintf("%s/%v/powerOn.json", c.namespace(), id) - ) - - _, err := c.newRequest(method, uri, nil) - if err != nil { - return err - } - return nil -} - -func (c *VirtualGuest) PowerOff(id int) error { - var ( - method = "GET" - uri = fmt.Sprintf("%s/%v/powerOff.json", c.namespace(), id) - ) - - _, err := c.newRequest(method, uri, nil) - if err != nil { - return err - } - return nil -} - -func (c *VirtualGuest) Pause(id int) error { - var ( - method = "GET" - uri = fmt.Sprintf("%s/%v/pause.json", c.namespace(), id) - ) - - _, err := c.newRequest(method, uri, nil) - if err != nil { - return err - } - return nil -} - -func (c *VirtualGuest) Resume(id int) error { - var ( - method = "GET" - uri = fmt.Sprintf("%s/%v/resume.json", c.namespace(), id) - ) - - _, err := c.newRequest(method, uri, nil) - if err != nil { - return err - } - return nil -} - -func (c *VirtualGuest) Reboot(id int) error { - var ( - method = "GET" - uri = fmt.Sprintf("%s/%v/rebootSoft.json", c.namespace(), id) - ) - - _, err := c.newRequest(method, uri, nil) - if err != nil { - return err - } - return nil -} - -func (c *VirtualGuest) GetPublicIP(id int) (string, error) { - var ( - method = "GET" - uri = fmt.Sprintf("%s/%v/getPrimaryIpAddress.json", c.namespace(), id) - ) - - data, err := c.newRequest(method, uri, nil) - if err != nil { - return "", err - } - return strings.Replace(string(data), "\"", "", -1), nil -} - -func (c *VirtualGuest) GetPrivateIP(id int) (string, error) { - var ( - method = "GET" - uri = fmt.Sprintf("%s/%v/getPrimaryBackendIpAddress.json", c.namespace(), id) - ) - - data, err := c.newRequest(method, uri, nil) - if err != nil { - return "", err - } - return strings.Replace(string(data), "\"", "", -1), nil -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/disk.go b/vendor/github.com/docker/machine/drivers/virtualbox/disk.go deleted file mode 100644 index 82f064f..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/disk.go +++ /dev/null @@ -1,141 +0,0 @@ -package virtualbox - -import ( - "fmt" - "io" - "os" - "os/exec" - - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" -) - -type VirtualDisk struct { - UUID string - Path string -} - -type DiskCreator interface { - Create(size int, publicSSHKeyPath, diskPath string) error -} - -func NewDiskCreator() DiskCreator { - return &defaultDiskCreator{} -} - -type defaultDiskCreator struct{} - -// Make a boot2docker VM disk image. -func (c *defaultDiskCreator) Create(size int, publicSSHKeyPath, diskPath string) error { - log.Debugf("Creating %d MB hard disk image...", size) - - tarBuf, err := mcnutils.MakeDiskImage(publicSSHKeyPath) - if err != nil { - return err - } - - log.Debug("Calling inner createDiskImage") - - return createDiskImage(diskPath, size, tarBuf) -} - -// createDiskImage makes a disk image at dest with the given size in MB. If r is -// not nil, it will be read as a raw disk image to convert from. -func createDiskImage(dest string, size int, r io.Reader) error { - // Convert a raw image from stdin to the dest VMDK image. - sizeBytes := int64(size) << 20 // usually won't fit in 32-bit int (max 2GB) - // FIXME: why isn't this just using the vbm*() functions? - cmd := exec.Command(vboxManageCmd, "convertfromraw", "stdin", dest, - fmt.Sprintf("%d", sizeBytes), "--format", "VMDK") - - log.Debug(cmd) - - if os.Getenv("MACHINE_DEBUG") != "" { - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - } - - stdin, err := cmd.StdinPipe() - if err != nil { - return err - } - - log.Debug("Starting command") - - if err := cmd.Start(); err != nil { - return err - } - - log.Debug("Copying to stdin") - - n, err := io.Copy(stdin, r) - if err != nil { - return err - } - - log.Debug("Filling zeroes") - - // The total number of bytes written to stdin must match sizeBytes, or - // VBoxManage.exe on Windows will fail. Fill remaining with zeros. - if left := sizeBytes - n; left > 0 { - if err := zeroFill(stdin, left); err != nil { - return err - } - } - - log.Debug("Closing STDIN") - - // cmd won't exit until the stdin is closed. - if err := stdin.Close(); err != nil { - return err - } - - log.Debug("Waiting on cmd") - - return cmd.Wait() -} - -// zeroFill writes n zero bytes into w. -func zeroFill(w io.Writer, n int64) error { - const blocksize = 32 << 10 - zeros := make([]byte, blocksize) - var k int - var err error - for n > 0 { - if n > blocksize { - k, err = w.Write(zeros) - } else { - k, err = w.Write(zeros[:n]) - } - if err != nil { - return err - } - n -= int64(k) - } - return nil -} - -func getVMDiskInfo(name string, vbox VBoxManager) (*VirtualDisk, error) { - out, err := vbox.vbmOut("showvminfo", name, "--machinereadable") - if err != nil { - return nil, err - } - - disk := &VirtualDisk{} - - err = parseKeyValues(out, reEqualQuoteLine, func(key, val string) error { - switch key { - case "SATA-1-0": - disk.Path = val - case "SATA-ImageUUID-1-0": - disk.UUID = val - } - - return nil - }) - if err != nil { - return nil, err - } - - return disk, nil -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/disk_test.go b/vendor/github.com/docker/machine/drivers/virtualbox/disk_test.go deleted file mode 100644 index b6c5919..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/disk_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package virtualbox - -import ( - "errors" - "testing" - - "github.com/stretchr/testify/assert" -) - -const stdOutDiskInfo = ` -storagecontrollerbootable0="on" -"SATA-0-0"="/home/ehazlett/.boot2docker/boot2docker.iso" -"SATA-IsEjected"="off" -"SATA-1-0"="/home/ehazlett/vm/test/disk.vmdk" -"SATA-ImageUUID-1-0"="12345-abcdefg" -"SATA-2-0"="none" -nic1="nat"` - -func TestVMDiskInfo(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "showvminfo default --machinereadable", - stdOut: stdOutDiskInfo, - } - - disk, err := getVMDiskInfo("default", vbox) - - assert.Equal(t, "/home/ehazlett/vm/test/disk.vmdk", disk.Path) - assert.Equal(t, "12345-abcdefg", disk.UUID) - assert.NoError(t, err) -} - -func TestVMDiskInfoError(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "showvminfo default --machinereadable", - err: errors.New("BUG"), - } - - disk, err := getVMDiskInfo("default", vbox) - - assert.Nil(t, disk) - assert.EqualError(t, err, "BUG") -} - -func TestVMDiskInfoInvalidOutput(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "showvminfo default --machinereadable", - stdOut: "INVALID", - } - - disk, err := getVMDiskInfo("default", vbox) - - assert.Empty(t, disk.Path) - assert.Empty(t, disk.UUID) - assert.NoError(t, err) -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/ip.go b/vendor/github.com/docker/machine/drivers/virtualbox/ip.go deleted file mode 100644 index be22a4f..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/ip.go +++ /dev/null @@ -1,36 +0,0 @@ -package virtualbox - -import ( - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/mcnutils" -) - -// IPWaiter waits for an IP to be configured. -type IPWaiter interface { - Wait(d *Driver) error -} - -func NewIPWaiter() IPWaiter { - return &sshIPWaiter{} -} - -type sshIPWaiter struct{} - -func (w *sshIPWaiter) Wait(d *Driver) error { - // Wait for SSH over NAT to be available before returning to user - if err := drivers.WaitForSSH(d); err != nil { - return err - } - - // Bail if we don't get an IP from DHCP after a given number of seconds. - if err := mcnutils.WaitForSpecific(d.hostOnlyIPAvailable, 5, 4*time.Second); err != nil { - return err - } - - var err error - d.IPAddress, err = d.GetIP() - - return err -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/misc.go b/vendor/github.com/docker/machine/drivers/virtualbox/misc.go deleted file mode 100644 index 3972a95..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/misc.go +++ /dev/null @@ -1,112 +0,0 @@ -package virtualbox - -import ( - "bufio" - "math/rand" - "os" - - "time" - - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/ssh" -) - -// B2DUpdater describes the interactions with b2d. -type B2DUpdater interface { - UpdateISOCache(storePath, isoURL string) error - CopyIsoToMachineDir(storePath, machineName, isoURL string) error -} - -func NewB2DUpdater() B2DUpdater { - return &b2dUtilsUpdater{} -} - -type b2dUtilsUpdater struct{} - -func (u *b2dUtilsUpdater) CopyIsoToMachineDir(storePath, machineName, isoURL string) error { - return mcnutils.NewB2dUtils(storePath).CopyIsoToMachineDir(isoURL, machineName) -} - -func (u *b2dUtilsUpdater) UpdateISOCache(storePath, isoURL string) error { - return mcnutils.NewB2dUtils(storePath).UpdateISOCache(isoURL) -} - -// SSHKeyGenerator describes the generation of ssh keys. -type SSHKeyGenerator interface { - Generate(path string) error -} - -func NewSSHKeyGenerator() SSHKeyGenerator { - return &defaultSSHKeyGenerator{} -} - -type defaultSSHKeyGenerator struct{} - -func (g *defaultSSHKeyGenerator) Generate(path string) error { - return ssh.GenerateSSHKey(path) -} - -// LogsReader describes the reading of VBox.log -type LogsReader interface { - Read(path string) ([]string, error) -} - -func NewLogsReader() LogsReader { - return &vBoxLogsReader{} -} - -type vBoxLogsReader struct{} - -func (c *vBoxLogsReader) Read(path string) ([]string, error) { - file, err := os.Open(path) - if err != nil { - return []string{}, err - } - - defer file.Close() - - lines := []string{} - - scanner := bufio.NewScanner(file) - for scanner.Scan() { - lines = append(lines, scanner.Text()) - } - - return lines, nil -} - -// RandomInter returns random int values. -type RandomInter interface { - RandomInt(n int) int -} - -func NewRandomInter() RandomInter { - src := rand.NewSource(time.Now().UnixNano()) - - return &defaultRandomInter{ - rand: rand.New(src), - } -} - -type defaultRandomInter struct { - rand *rand.Rand -} - -func (d *defaultRandomInter) RandomInt(n int) int { - return d.rand.Intn(n) -} - -// Sleeper sleeps for given duration. -type Sleeper interface { - Sleep(d time.Duration) -} - -func NewSleeper() Sleeper { - return &defaultSleeper{} -} - -type defaultSleeper struct{} - -func (s *defaultSleeper) Sleep(d time.Duration) { - time.Sleep(d) -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/network.go b/vendor/github.com/docker/machine/drivers/virtualbox/network.go deleted file mode 100644 index 0526840..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/network.go +++ /dev/null @@ -1,415 +0,0 @@ -package virtualbox - -import ( - "errors" - "fmt" - "net" - "regexp" - "strings" - "time" - - "runtime" - - "github.com/docker/machine/libmachine/log" -) - -const ( - buggyNetmask = "0f000000" - dhcpPrefix = "HostInterfaceNetworking-" -) - -var ( - reHostOnlyAdapterCreated = regexp.MustCompile(`Interface '(.+)' was successfully created`) - errNewHostOnlyAdapterNotVisible = errors.New("The host-only adapter we just created is not visible. This is a well known VirtualBox bug. You might want to uninstall it and reinstall at least version 5.0.12 that is is supposed to fix this issue") -) - -// Host-only network. -type hostOnlyNetwork struct { - Name string - GUID string - DHCP bool - IPv4 net.IPNet - HwAddr net.HardwareAddr - Medium string - Status string - NetworkName string // referenced in DHCP.NetworkName -} - -// HostInterfaces returns host network interface info. By default delegates to net.Interfaces() -type HostInterfaces interface { - Interfaces() ([]net.Interface, error) - Addrs(iface *net.Interface) ([]net.Addr, error) -} - -func NewHostInterfaces() HostInterfaces { - return &defaultHostInterfaces{} -} - -type defaultHostInterfaces struct { -} - -func (ni *defaultHostInterfaces) Interfaces() ([]net.Interface, error) { - return net.Interfaces() -} - -func (ni *defaultHostInterfaces) Addrs(iface *net.Interface) ([]net.Addr, error) { - return iface.Addrs() -} - -// Save changes the configuration of the host-only network. -func (n *hostOnlyNetwork) Save(vbox VBoxManager) error { - if err := n.SaveIPv4(vbox); err != nil { - return err - } - - if n.DHCP { - vbox.vbm("hostonlyif", "ipconfig", n.Name, "--dhcp") // not implemented as of VirtualBox 4.3 - } - - return nil -} - -// SaveIPv4 changes the ipv4 configuration of the host-only network. -func (n *hostOnlyNetwork) SaveIPv4(vbox VBoxManager) error { - if n.IPv4.IP != nil && n.IPv4.Mask != nil { - if runtime.GOOS == "windows" { - log.Warn("Windows might ask for the permission to configure a network adapter. Sometimes, such confirmation window is minimized in the taskbar.") - } - - if err := vbox.vbm("hostonlyif", "ipconfig", n.Name, "--ip", n.IPv4.IP.String(), "--netmask", net.IP(n.IPv4.Mask).String()); err != nil { - return err - } - } - - return nil -} - -// createHostonlyAdapter creates a new host-only network. -func createHostonlyAdapter(vbox VBoxManager) (*hostOnlyNetwork, error) { - if runtime.GOOS == "windows" { - log.Warn("Windows might ask for the permission to create a network adapter. Sometimes, such confirmation window is minimized in the taskbar.") - } - - out, err := vbox.vbmOut("hostonlyif", "create") - if err != nil { - return nil, err - } - - res := reHostOnlyAdapterCreated.FindStringSubmatch(string(out)) - if res == nil { - return nil, errors.New("Failed to create host-only adapter") - } - - return &hostOnlyNetwork{Name: res[1]}, nil -} - -// listHostOnlyAdapters gets all host-only adapters in a map keyed by NetworkName. -func listHostOnlyAdapters(vbox VBoxManager) (map[string]*hostOnlyNetwork, error) { - out, err := vbox.vbmOut("list", "hostonlyifs") - if err != nil { - return nil, err - } - - byName := map[string]*hostOnlyNetwork{} - byIP := map[string]*hostOnlyNetwork{} - n := &hostOnlyNetwork{} - - err = parseKeyValues(out, reColonLine, func(key, val string) error { - switch key { - case "Name": - n.Name = val - case "GUID": - n.GUID = val - case "DHCP": - n.DHCP = (val != "Disabled") - case "IPAddress": - n.IPv4.IP = net.ParseIP(val) - case "NetworkMask": - n.IPv4.Mask = parseIPv4Mask(val) - case "HardwareAddress": - mac, err := net.ParseMAC(val) - if err != nil { - return err - } - n.HwAddr = mac - case "MediumType": - n.Medium = val - case "Status": - n.Status = val - case "VBoxNetworkName": - n.NetworkName = val - - if _, present := byName[n.NetworkName]; present { - return fmt.Errorf("VirtualBox is configured with multiple host-only adapters with the same name %q. Please remove one", n.NetworkName) - } - byName[n.NetworkName] = n - - if len(n.IPv4.IP) != 0 { - if _, present := byIP[n.IPv4.IP.String()]; present { - return fmt.Errorf("VirtualBox is configured with multiple host-only adapters with the same IP %q. Please remove one", n.IPv4.IP) - } - byIP[n.IPv4.IP.String()] = n - } - - n = &hostOnlyNetwork{} - } - - return nil - }) - if err != nil { - return nil, err - } - - return byName, nil -} - -func getHostOnlyAdapter(nets map[string]*hostOnlyNetwork, hostIP net.IP, netmask net.IPMask) *hostOnlyNetwork { - for _, n := range nets { - // Second part of this conditional handles a race where - // VirtualBox returns us the incorrect netmask value for the - // newly created adapter. - if hostIP.Equal(n.IPv4.IP) && - (netmask.String() == n.IPv4.Mask.String() || n.IPv4.Mask.String() == buggyNetmask) { - log.Debugf("Found: %s", n.Name) - return n - } - } - - log.Debug("Not found") - return nil -} - -func getOrCreateHostOnlyNetwork(hostIP net.IP, netmask net.IPMask, nets map[string]*hostOnlyNetwork, vbox VBoxManager) (*hostOnlyNetwork, error) { - // Search for an existing host-only adapter. - hostOnlyAdapter := getHostOnlyAdapter(nets, hostIP, netmask) - if hostOnlyAdapter != nil { - return hostOnlyAdapter, nil - } - - // No existing host-only adapter found. Create a new one. - _, err := createHostonlyAdapter(vbox) - if err != nil { - // Sometimes the host-only adapter fails to create. See https://www.virtualbox.org/ticket/14040 - // BUT, it is created in fact! So let's wait until it appears last in the list - log.Warnf("Creating a new host-only adapter produced an error: %s", err) - log.Warn("This is a known VirtualBox bug. Let's try to recover anyway...") - } - - // It can take some time for an adapter to appear. Let's poll. - hostOnlyAdapter, err = waitForNewHostOnlyNetwork(nets, vbox) - if err != nil { - // Sometimes, Vbox says it created it but then it cannot be found... - return nil, errNewHostOnlyAdapterNotVisible - } - - log.Warnf("Found a new host-only adapter: %q", hostOnlyAdapter.Name) - - hostOnlyAdapter.IPv4.IP = hostIP - hostOnlyAdapter.IPv4.Mask = netmask - if err := hostOnlyAdapter.Save(vbox); err != nil { - return nil, err - } - - return hostOnlyAdapter, nil -} - -func waitForNewHostOnlyNetwork(oldNets map[string]*hostOnlyNetwork, vbox VBoxManager) (*hostOnlyNetwork, error) { - for i := 0; i < 10; i++ { - time.Sleep(1 * time.Second) - - newNets, err := listHostOnlyAdapters(vbox) - if err != nil { - return nil, err - } - - for name, latestNet := range newNets { - if _, present := oldNets[name]; !present { - return latestNet, nil - } - } - } - - return nil, errors.New("Failed to find a new host-only adapter") -} - -// DHCP server info. -type dhcpServer struct { - NetworkName string - IPv4 net.IPNet - LowerIP net.IP - UpperIP net.IP - Enabled bool -} - -// removeOrphanDHCPServers removed the DHCP servers linked to no host-only adapter -func removeOrphanDHCPServers(vbox VBoxManager) error { - dhcps, err := listDHCPServers(vbox) - if err != nil { - return err - } - - if len(dhcps) == 0 { - return nil - } - - log.Debug("Removing orphan DHCP servers...") - - nets, err := listHostOnlyAdapters(vbox) - if err != nil { - return err - } - - for name := range dhcps { - if strings.HasPrefix(name, dhcpPrefix) { - if _, present := nets[name]; !present { - if err := vbox.vbm("dhcpserver", "remove", "--netname", name); err != nil { - log.Warnf("Unable to remove orphan dhcp server %q: %s", name, err) - } - } - } - } - - return nil -} - -// addHostOnlyDHCPServer adds a DHCP server to a host-only network. -func addHostOnlyDHCPServer(ifname string, d dhcpServer, vbox VBoxManager) error { - name := dhcpPrefix + ifname - - dhcps, err := listDHCPServers(vbox) - if err != nil { - return err - } - - // On some platforms (OSX), creating a host-only adapter adds a default dhcpserver, - // while on others (Windows?) it does not. - command := "add" - if dhcp, ok := dhcps[name]; ok { - command = "modify" - if (dhcp.IPv4.IP.Equal(d.IPv4.IP)) && (dhcp.IPv4.Mask.String() == d.IPv4.Mask.String()) && (dhcp.LowerIP.Equal(d.LowerIP)) && (dhcp.UpperIP.Equal(d.UpperIP)) && (dhcp.Enabled == d.Enabled) { - // dhcp is up to date - return nil - } - } - - args := []string{"dhcpserver", command, - "--netname", name, - "--ip", d.IPv4.IP.String(), - "--netmask", net.IP(d.IPv4.Mask).String(), - "--lowerip", d.LowerIP.String(), - "--upperip", d.UpperIP.String(), - } - if d.Enabled { - args = append(args, "--enable") - } else { - args = append(args, "--disable") - } - - if runtime.GOOS == "windows" { - log.Warn("Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.") - } - - return vbox.vbm(args...) -} - -// listDHCPServers lists all DHCP server settings in a map keyed by DHCP.NetworkName. -func listDHCPServers(vbox VBoxManager) (map[string]*dhcpServer, error) { - out, err := vbox.vbmOut("list", "dhcpservers") - if err != nil { - return nil, err - } - - m := map[string]*dhcpServer{} - dhcp := &dhcpServer{} - - err = parseKeyValues(out, reColonLine, func(key, val string) error { - switch key { - case "NetworkName": - dhcp = &dhcpServer{} - m[val] = dhcp - dhcp.NetworkName = val - case "IP": - dhcp.IPv4.IP = net.ParseIP(val) - case "upperIPAddress": - dhcp.UpperIP = net.ParseIP(val) - case "lowerIPAddress": - dhcp.LowerIP = net.ParseIP(val) - case "NetworkMask": - dhcp.IPv4.Mask = parseIPv4Mask(val) - case "Enabled": - dhcp.Enabled = (val == "Yes") - } - - return nil - }) - if err != nil { - return nil, err - } - - return m, nil -} - -// listHostInterfaces returns a map of net.IPNet addresses of host interfaces that are "UP" and not loopback adapters -// and not virtualbox host-only networks (given by excludeNets), keyed by CIDR string. -func listHostInterfaces(hif HostInterfaces, excludeNets map[string]*hostOnlyNetwork) (map[string]*net.IPNet, error) { - ifaces, err := hif.Interfaces() - if err != nil { - return nil, err - } - m := map[string]*net.IPNet{} - - for _, iface := range ifaces { - addrs, err := hif.Addrs(&iface) - if err != nil { - return nil, err - } - - // Check if an address of the interface is in the list of excluded addresses - ifaceExcluded := false - for _, a := range addrs { - switch ipnet := a.(type) { - case *net.IPNet: - _, excluded := excludeNets[ipnet.String()] - if excluded { - ifaceExcluded = true - break - } - } - } - - // If excluded, or not up, or a loopback interface, skip the interface - if ifaceExcluded || iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 { - continue - } - - // This is a host interface, so add all its addresses to the map - for _, a := range addrs { - switch ipnet := a.(type) { - case *net.IPNet: - m[ipnet.String()] = ipnet - } - } - } - return m, nil -} - -// checkIPNetCollision returns true if any host interfaces conflict with the host-only network mask passed as a parameter. -// This works with IPv4 or IPv6 ip addresses. -func checkIPNetCollision(hostonly *net.IPNet, hostIfaces map[string]*net.IPNet) (bool, error) { - for _, ifaceNet := range hostIfaces { - if hostonly.IP.Equal(ifaceNet.IP.Mask(ifaceNet.Mask)) { - return true, nil - } - } - return false, nil -} - -// parseIPv4Mask parses IPv4 netmask written in IP form (e.g. 255.255.255.0). -// This function should really belong to the net package. -func parseIPv4Mask(s string) net.IPMask { - mask := net.ParseIP(s) - if mask == nil { - return nil - } - return net.IPv4Mask(mask[12], mask[13], mask[14], mask[15]) -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/network_test.go b/vendor/github.com/docker/machine/drivers/virtualbox/network_test.go deleted file mode 100644 index bcddc1a..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/network_test.go +++ /dev/null @@ -1,406 +0,0 @@ -package virtualbox - -import ( - "net" - "reflect" - "testing" - - "github.com/stretchr/testify/assert" -) - -const ( - stdOutOneHostOnlyNetwork = ` -Name: vboxnet0 -GUID: 786f6276-656e-4074-8000-0a0027000000 -DHCP: Disabled -IPAddress: 192.168.99.1 -NetworkMask: 255.255.255.0 -IPV6Address: -IPV6NetworkMaskPrefixLength: 0 -HardwareAddress: 0a:00:27:00:00:00 -MediumType: Ethernet -Status: Up -VBoxNetworkName: HostInterfaceNetworking-vboxnet0 - -` - stdOutTwoHostOnlyNetwork = ` -Name: vboxnet0 -GUID: 786f6276-656e-4074-8000-0a0027000000 -DHCP: Disabled -IPAddress: 192.168.99.1 -NetworkMask: 255.255.255.0 -IPV6Address: -IPV6NetworkMaskPrefixLength: 0 -HardwareAddress: 0a:00:27:00:00:00 -MediumType: Ethernet -Status: Up -VBoxNetworkName: HostInterfaceNetworking-vboxnet0 - -Name: vboxnet1 -GUID: 786f6276-656e-4174-8000-0a0027000001 -DHCP: Disabled -IPAddress: 169.254.37.187 -NetworkMask: 255.255.255.0 -IPV6Address: -IPV6NetworkMaskPrefixLength: 0 -HardwareAddress: 0a:00:27:00:00:01 -MediumType: Ethernet -Status: Up -VBoxNetworkName: HostInterfaceNetworking-vboxnet1 -` - stdOutListTwoDHCPServers = ` -NetworkName: HostInterfaceNetworking-vboxnet0 -IP: 192.168.99.6 -NetworkMask: 255.255.255.0 -lowerIPAddress: 192.168.99.100 -upperIPAddress: 192.168.99.254 -Enabled: Yes - -NetworkName: HostInterfaceNetworking-vboxnet1 -IP: 192.168.99.7 -NetworkMask: 255.255.255.0 -lowerIPAddress: 192.168.99.100 -upperIPAddress: 192.168.99.254 -Enabled: No -` -) - -type mockHostInterfaces struct { - mockIfaces []net.Interface - mockAddrs map[string]net.Addr -} - -func newMockHostInterfaces() *mockHostInterfaces { - return &mockHostInterfaces{ - mockAddrs: make(map[string]net.Addr), - } -} - -func (mhi *mockHostInterfaces) Interfaces() ([]net.Interface, error) { - return mhi.mockIfaces, nil -} - -func (mhi *mockHostInterfaces) Addrs(iface *net.Interface) ([]net.Addr, error) { - return []net.Addr{mhi.mockAddrs[iface.Name]}, nil -} - -func (mhi *mockHostInterfaces) addMockIface(ip string, mask int, iplen int, name string, flags net.Flags) (*net.IPNet, error) { - iface := &net.Interface{Name: name, Flags: flags} - mhi.mockIfaces = append(mhi.mockIfaces, *iface) - - ipnet := &net.IPNet{IP: net.ParseIP(ip), Mask: net.CIDRMask(mask, 8*iplen)} - if ipnet.IP == nil { - return nil, &net.ParseError{Type: "IP address", Text: ip} - } - mhi.mockAddrs[name] = ipnet - return ipnet, nil -} - -// Tests that when we have a host only network which matches our expectations, -// it gets returned correctly. -func TestGetHostOnlyNetworkHappy(t *testing.T) { - cidr := "192.168.99.0/24" - ip, ipnet, err := net.ParseCIDR(cidr) - if err != nil { - t.Fatalf("Error parsing cidr: %s", err) - } - expectedHostOnlyNetwork := &hostOnlyNetwork{ - IPv4: *ipnet, - } - vboxNets := map[string]*hostOnlyNetwork{ - "HostInterfaceNetworking-vboxnet0": expectedHostOnlyNetwork, - } - - n := getHostOnlyAdapter(vboxNets, ip, ipnet.Mask) - if !reflect.DeepEqual(n, expectedHostOnlyNetwork) { - t.Fatalf("Expected result of calling getHostOnlyNetwork to be the same as expected but it was not:\nexpected: %+v\nactual: %+v\n", expectedHostOnlyNetwork, n) - } -} - -// Tests that we are able to properly detect when a host only network which -// matches our expectations can not be found. -func TestGetHostOnlyNetworkNotFound(t *testing.T) { - // Note that this has a different ip is different from "ip" below. - cidr := "192.168.99.0/24" - ip, ipnet, err := net.ParseCIDR(cidr) - if err != nil { - t.Fatalf("Error parsing cidr: %s", err) - } - - ip = net.ParseIP("192.168.59.0").To4() - - // Suppose a vbox net is created, but it doesn't align with our - // expectation. - vboxNet := &hostOnlyNetwork{ - IPv4: *ipnet, - } - vboxNets := map[string]*hostOnlyNetwork{ - "HostInterfaceNetworking-vboxnet0": vboxNet, - } - - n := getHostOnlyAdapter(vboxNets, ip, ipnet.Mask) - if n != nil { - t.Fatalf("Expected vbox net to be nil but it has a value: %+v\n", n) - } -} - -// Tests a special case where Virtualbox creates the host only network -// successfully but mis-reports the netmask. -func TestGetHostOnlyNetworkWindows10Bug(t *testing.T) { - cidr := "192.168.99.0/24" - ip, ipnet, err := net.ParseCIDR(cidr) - if err != nil { - t.Fatalf("Error parsing cidr: %s", err) - } - - // This is a faulty netmask: a VirtualBox bug causes it to be - // misreported. - ipnet.Mask = net.IPMask(net.ParseIP("15.0.0.0").To4()) - - expectedHostOnlyNetwork := &hostOnlyNetwork{ - IPv4: *ipnet, - } - - vboxNets := map[string]*hostOnlyNetwork{ - "HostInterfaceNetworking-vboxnet0": expectedHostOnlyNetwork, - } - - // The Mask that we are passing in will be the "legitimate" mask, so it - // must differ from the magic buggy mask. - n := getHostOnlyAdapter(vboxNets, ip, net.IPMask(net.ParseIP("255.255.255.0").To4())) - if !reflect.DeepEqual(n, expectedHostOnlyNetwork) { - t.Fatalf("Expected result of calling getHostOnlyNetwork to be the same as expected but it was not:\nexpected: %+v\nactual: %+v\n", expectedHostOnlyNetwork, n) - } -} - -func TestListHostOnlyNetworks(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "list hostonlyifs", - stdOut: stdOutOneHostOnlyNetwork, - } - - nets, err := listHostOnlyAdapters(vbox) - - assert.Equal(t, 1, len(nets)) - assert.NoError(t, err) - - net, present := nets["HostInterfaceNetworking-vboxnet0"] - - assert.True(t, present) - assert.Equal(t, "vboxnet0", net.Name) - assert.Equal(t, "786f6276-656e-4074-8000-0a0027000000", net.GUID) - assert.False(t, net.DHCP) - assert.Equal(t, "192.168.99.1", net.IPv4.IP.String()) - assert.Equal(t, "ffffff00", net.IPv4.Mask.String()) - assert.Equal(t, "0a:00:27:00:00:00", net.HwAddr.String()) - assert.Equal(t, "Ethernet", net.Medium) - assert.Equal(t, "Up", net.Status) - assert.Equal(t, "HostInterfaceNetworking-vboxnet0", net.NetworkName) -} - -func TestListTwoHostOnlyNetworks(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "list hostonlyifs", - stdOut: stdOutTwoHostOnlyNetwork, - } - - nets, err := listHostOnlyAdapters(vbox) - - assert.Equal(t, 2, len(nets)) - assert.NoError(t, err) - - net, present := nets["HostInterfaceNetworking-vboxnet1"] - - assert.True(t, present) - assert.Equal(t, "vboxnet1", net.Name) - assert.Equal(t, "786f6276-656e-4174-8000-0a0027000001", net.GUID) - assert.False(t, net.DHCP) - assert.Equal(t, "169.254.37.187", net.IPv4.IP.String()) - assert.Equal(t, "ffffff00", net.IPv4.Mask.String()) - assert.Equal(t, "0a:00:27:00:00:01", net.HwAddr.String()) - assert.Equal(t, "Ethernet", net.Medium) - assert.Equal(t, "Up", net.Status) - assert.Equal(t, "HostInterfaceNetworking-vboxnet1", net.NetworkName) -} - -func TestListHostOnlyNetworksDontRelyOnEmptyLinesForParsing(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "list hostonlyifs", - stdOut: `Name: vboxnet0 -VBoxNetworkName: HostInterfaceNetworking-vboxnet0 -Name: vboxnet1 -VBoxNetworkName: HostInterfaceNetworking-vboxnet1`, - } - - nets, err := listHostOnlyAdapters(vbox) - - assert.Equal(t, 2, len(nets)) - assert.NoError(t, err) - - net, present := nets["HostInterfaceNetworking-vboxnet1"] - assert.True(t, present) - assert.Equal(t, "vboxnet1", net.Name) - - net, present = nets["HostInterfaceNetworking-vboxnet0"] - assert.True(t, present) - assert.Equal(t, "vboxnet0", net.Name) -} - -func TestGetHostOnlyNetwork(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "list hostonlyifs", - stdOut: stdOutOneHostOnlyNetwork, - } - nets, err := listHostOnlyAdapters(vbox) - assert.NoError(t, err) - - net, err := getOrCreateHostOnlyNetwork(net.ParseIP("192.168.99.1"), parseIPv4Mask("255.255.255.0"), nets, vbox) - - assert.NotNil(t, net) - assert.Equal(t, "HostInterfaceNetworking-vboxnet0", net.NetworkName) - assert.NoError(t, err) -} - -func TestFailIfTwoNetworksHaveSameIP(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "list hostonlyifs", - stdOut: `Name: vboxnet0 -IPAddress: 192.168.99.1 -NetworkMask: 255.255.255.0 -VBoxNetworkName: HostInterfaceNetworking-vboxnet0 -Name: vboxnet1 -IPAddress: 192.168.99.1 -NetworkMask: 255.255.255.0 -VBoxNetworkName: HostInterfaceNetworking-vboxnet1`, - } - nets, err := listHostOnlyAdapters(vbox) - assert.Nil(t, nets) - assert.EqualError(t, err, `VirtualBox is configured with multiple host-only adapters with the same IP "192.168.99.1". Please remove one`) -} - -func TestFailIfTwoNetworksHaveSameName(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "list hostonlyifs", - stdOut: `Name: vboxnet0 -VBoxNetworkName: HostInterfaceNetworking-vboxnet0 -Name: vboxnet0 -VBoxNetworkName: HostInterfaceNetworking-vboxnet0`, - } - nets, err := listHostOnlyAdapters(vbox) - assert.Nil(t, nets) - assert.EqualError(t, err, `VirtualBox is configured with multiple host-only adapters with the same name "HostInterfaceNetworking-vboxnet0". Please remove one`) -} - -func TestGetDHCPServers(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "list dhcpservers", - stdOut: stdOutListTwoDHCPServers, - } - - servers, err := listDHCPServers(vbox) - - assert.Equal(t, 2, len(servers)) - assert.NoError(t, err) - - server, present := servers["HostInterfaceNetworking-vboxnet0"] - assert.True(t, present) - assert.Equal(t, "HostInterfaceNetworking-vboxnet0", server.NetworkName) - assert.Equal(t, "192.168.99.6", server.IPv4.IP.String()) - assert.Equal(t, "192.168.99.100", server.LowerIP.String()) - assert.Equal(t, "192.168.99.254", server.UpperIP.String()) - assert.Equal(t, "ffffff00", server.IPv4.Mask.String()) - assert.True(t, server.Enabled) - - server, present = servers["HostInterfaceNetworking-vboxnet1"] - assert.True(t, present) - assert.Equal(t, "HostInterfaceNetworking-vboxnet1", server.NetworkName) - assert.Equal(t, "192.168.99.7", server.IPv4.IP.String()) - assert.Equal(t, "192.168.99.100", server.LowerIP.String()) - assert.Equal(t, "192.168.99.254", server.UpperIP.String()) - assert.Equal(t, "ffffff00", server.IPv4.Mask.String()) - assert.False(t, server.Enabled) -} - -// Tests detection of a conflict between prospective vbox host-only network and an IPV6 host interface -func TestCheckIPNetCollisionIPv6(t *testing.T) { - m := map[string]*net.IPNet{} - _, vboxHostOnly, err := net.ParseCIDR("2607:f8b0:400e:c04:ffff:ffff:ffff:ffff/64") - assert.Nil(t, err) - - hostIP, hostNet, err := net.ParseCIDR("2001:4998:c:a06::2:4008/64") - assert.Nil(t, err) - m[hostIP.String()] = &net.IPNet{IP: hostIP, Mask: hostNet.Mask} - - result, err := checkIPNetCollision(vboxHostOnly, m) - assert.Nil(t, err) - assert.False(t, result) - - hostIP, hostNet, err = net.ParseCIDR("2607:f8b0:400e:c04::6a/64") - assert.Nil(t, err) - m[hostIP.String()] = &net.IPNet{IP: hostIP, Mask: hostNet.Mask} - - result, err = checkIPNetCollision(vboxHostOnly, m) - assert.Nil(t, err) - assert.True(t, result) -} - -// Tests detection of a conflict between prospective vbox host-only network and an IPV4 host interface -func TestCheckIPNetCollisionIPv4(t *testing.T) { - m := map[string]*net.IPNet{} - _, vboxHostOnly, err := net.ParseCIDR("192.168.99.1/24") - assert.NoError(t, err) - - hostIP, hostNet, err := net.ParseCIDR("10.10.10.42/24") - assert.NoError(t, err) - m[hostIP.String()] = &net.IPNet{IP: hostIP, Mask: hostNet.Mask} - - result, err := checkIPNetCollision(vboxHostOnly, m) - assert.NoError(t, err) - assert.False(t, result) - - hostIP, hostNet, err = net.ParseCIDR("192.168.99.22/24") - assert.NoError(t, err) - m[hostIP.String()] = &net.IPNet{IP: hostIP, Mask: hostNet.Mask} - - result, err = checkIPNetCollision(vboxHostOnly, m) - assert.NoError(t, err) - assert.True(t, result) -} - -// Tests functionality of listHostInterfaces and verifies only non-loopback, active and non-excluded interfaces are returned -func TestListHostInterfaces(t *testing.T) { - mhi := newMockHostInterfaces() - excludes := map[string]*hostOnlyNetwork{} - - en0, err := mhi.addMockIface("10.10.0.22", 24, net.IPv4len, "en0", net.FlagUp|net.FlagBroadcast) - assert.NoError(t, err) - _, err = mhi.addMockIface("10.10.1.11", 24, net.IPv4len, "en1", net.FlagBroadcast /*not up*/) - assert.NoError(t, err) - _, err = mhi.addMockIface("127.0.0.1", 24, net.IPv4len, "lo0", net.FlagUp|net.FlagLoopback) - assert.NoError(t, err) - en0ipv6, err := mhi.addMockIface("2001:4998:c:a06::2:4008", 64, net.IPv6len, "en0ipv6", net.FlagUp|net.FlagBroadcast) - assert.NoError(t, err) - vboxnet0, err := mhi.addMockIface("192.168.99.1", 24, net.IPv4len, "vboxnet0", net.FlagUp|net.FlagBroadcast) - assert.NoError(t, err) - notvboxnet0, err := mhi.addMockIface("192.168.99.42", 24, net.IPv4len, "en2", net.FlagUp|net.FlagBroadcast) - assert.NoError(t, err) - - excludes["192.168.99.1/24"] = &hostOnlyNetwork{IPv4: *vboxnet0, Name: "HostInterfaceNetworking-vboxnet0"} - - m, err := listHostInterfaces(mhi, excludes) - assert.NoError(t, err) - assert.NotEmpty(t, m) - - assert.Contains(t, m, "10.10.0.22/24") - assert.Equal(t, en0, m["10.10.0.22/24"]) - - assert.Contains(t, m, "2001:4998:c:a06::2:4008/64") - assert.Equal(t, en0ipv6, m["2001:4998:c:a06::2:4008/64"]) - - assert.Contains(t, m, "192.168.99.42/24") - assert.Equal(t, notvboxnet0, m["192.168.99.42/24"]) - - assert.NotContains(t, m, "10.10.1.11/24") - assert.NotContains(t, m, "127.0.0.1/24") - assert.NotContains(t, m, "192.168.99.1/24") -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/vbm.go b/vendor/github.com/docker/machine/drivers/virtualbox/vbm.go deleted file mode 100644 index ea6eb8d..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/vbm.go +++ /dev/null @@ -1,165 +0,0 @@ -package virtualbox - -import ( - "bufio" - "bytes" - "errors" - "fmt" - "os/exec" - "regexp" - "strings" - - "strconv" - - "time" - - "github.com/docker/machine/libmachine/log" -) - -const ( - retryCountOnObjectNotReadyError = 5 - objectNotReady = "error: The object is not ready" - retryDelay = 100 * time.Millisecond -) - -var ( - reColonLine = regexp.MustCompile(`(.+):\s+(.*)`) - reEqualLine = regexp.MustCompile(`(.+)=(.*)`) - reEqualQuoteLine = regexp.MustCompile(`"(.+)"="(.*)"`) - reMachineNotFound = regexp.MustCompile(`Could not find a registered machine named '(.+)'`) - - ErrMachineNotExist = errors.New("machine does not exist") - ErrVBMNotFound = errors.New("VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path") - - vboxManageCmd = detectVBoxManageCmd() -) - -// VBoxManager defines the interface to communicate to VirtualBox. -type VBoxManager interface { - vbm(args ...string) error - - vbmOut(args ...string) (string, error) - - vbmOutErr(args ...string) (string, string, error) -} - -// VBoxCmdManager communicates with VirtualBox through the commandline using `VBoxManage`. -type VBoxCmdManager struct { - runCmd func(cmd *exec.Cmd) error -} - -// NewVBoxManager creates a VBoxManager instance. -func NewVBoxManager() *VBoxCmdManager { - return &VBoxCmdManager{ - runCmd: func(cmd *exec.Cmd) error { return cmd.Run() }, - } -} - -func (v *VBoxCmdManager) vbm(args ...string) error { - _, _, err := v.vbmOutErr(args...) - return err -} - -func (v *VBoxCmdManager) vbmOut(args ...string) (string, error) { - stdout, _, err := v.vbmOutErr(args...) - return stdout, err -} - -func (v *VBoxCmdManager) vbmOutErr(args ...string) (string, string, error) { - return v.vbmOutErrRetry(retryCountOnObjectNotReadyError, args...) -} - -func (v *VBoxCmdManager) vbmOutErrRetry(retry int, args ...string) (string, string, error) { - cmd := exec.Command(vboxManageCmd, args...) - log.Debugf("COMMAND: %v %v", vboxManageCmd, strings.Join(args, " ")) - var stdout bytes.Buffer - var stderr bytes.Buffer - cmd.Stdout = &stdout - cmd.Stderr = &stderr - err := v.runCmd(cmd) - stderrStr := stderr.String() - if len(args) > 0 { - log.Debugf("STDOUT:\n{\n%v}", stdout.String()) - log.Debugf("STDERR:\n{\n%v}", stderrStr) - } - - if err != nil { - if ee, ok := err.(*exec.Error); ok && ee.Err == exec.ErrNotFound { - err = ErrVBMNotFound - } - } - - // Sometimes, we just need to retry... - if retry > 1 { - if strings.Contains(stderrStr, objectNotReady) { - time.Sleep(retryDelay) - return v.vbmOutErrRetry(retry-1, args...) - } - } - - if err == nil || strings.HasPrefix(err.Error(), "exit status ") { - // VBoxManage will sometimes not set the return code, but has a fatal error - // such as VBoxManage.exe: error: VT-x is not available. (VERR_VMX_NO_VMX) - if strings.Contains(stderrStr, "error:") { - err = fmt.Errorf("%v %v failed:\n%v", vboxManageCmd, strings.Join(args, " "), stderrStr) - } - } - - return stdout.String(), stderrStr, err -} - -func checkVBoxManageVersion(version string) error { - major, minor, err := parseVersion(version) - if (err != nil) || (major < 4) || (major == 4 && minor <= 2) { - return fmt.Errorf("We support Virtualbox starting with version 5. Your VirtualBox install is %q. Please upgrade at https://www.virtualbox.org", version) - } - - if major < 5 { - log.Warnf("You are using version %s of VirtualBox. If you encounter issues, you might want to upgrade to version 5 at https://www.virtualbox.org", version) - } - - return nil -} - -func parseVersion(version string) (int, int, error) { - parts := strings.Split(version, ".") - if len(parts) < 2 { - return 0, 0, fmt.Errorf("Invalid version: %q", version) - } - - major, err := strconv.Atoi(parts[0]) - if err != nil { - return 0, 0, fmt.Errorf("Invalid version: %q", version) - } - - minor, err := strconv.Atoi(parts[1]) - if err != nil { - return 0, 0, fmt.Errorf("Invalid version: %q", version) - } - - return major, minor, err -} - -func parseKeyValues(stdOut string, regexp *regexp.Regexp, callback func(key, val string) error) error { - r := strings.NewReader(stdOut) - s := bufio.NewScanner(r) - - for s.Scan() { - line := s.Text() - if line == "" { - continue - } - - res := regexp.FindStringSubmatch(line) - if res == nil { - continue - } - - key, val := res[1], res[2] - if err := callback(key, val); err != nil { - return err - } - } - - return s.Err() -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/vbm_test.go b/vendor/github.com/docker/machine/drivers/virtualbox/vbm_test.go deleted file mode 100644 index a1baa1b..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/vbm_test.go +++ /dev/null @@ -1,142 +0,0 @@ -package virtualbox - -import ( - "testing" - - "os/exec" - - "errors" - - "fmt" - - "github.com/stretchr/testify/assert" -) - -func TestValidCheckVBoxManageVersion(t *testing.T) { - var tests = []struct { - version string - }{ - {"5.1"}, - {"5.0.8r103449"}, - {"5.0"}, - {"4.10"}, - {"4.3.1"}, - } - - for _, test := range tests { - err := checkVBoxManageVersion(test.version) - - assert.NoError(t, err) - } -} - -func TestInvalidCheckVBoxManageVersion(t *testing.T) { - var tests = []struct { - version string - expectedError string - }{ - {"3.9", `We support Virtualbox starting with version 5. Your VirtualBox install is "3.9". Please upgrade at https://www.virtualbox.org`}, - {"4.0", `We support Virtualbox starting with version 5. Your VirtualBox install is "4.0". Please upgrade at https://www.virtualbox.org`}, - {"4.1.1", `We support Virtualbox starting with version 5. Your VirtualBox install is "4.1.1". Please upgrade at https://www.virtualbox.org`}, - {"4.2.36-104064", `We support Virtualbox starting with version 5. Your VirtualBox install is "4.2.36-104064". Please upgrade at https://www.virtualbox.org`}, - {"X.Y", `We support Virtualbox starting with version 5. Your VirtualBox install is "X.Y". Please upgrade at https://www.virtualbox.org`}, - {"", `We support Virtualbox starting with version 5. Your VirtualBox install is "". Please upgrade at https://www.virtualbox.org`}, - } - - for _, test := range tests { - err := checkVBoxManageVersion(test.version) - - assert.EqualError(t, err, test.expectedError) - } -} - -func TestVbmOutErr(t *testing.T) { - var cmdRun *exec.Cmd - vBoxManager := NewVBoxManager() - vBoxManager.runCmd = func(cmd *exec.Cmd) error { - cmdRun = cmd - fmt.Fprint(cmd.Stdout, "Printed to StdOut") - fmt.Fprint(cmd.Stderr, "Printed to StdErr") - return nil - } - - stdOut, stdErr, err := vBoxManager.vbmOutErr("arg1", "arg2") - - assert.Equal(t, []string{vboxManageCmd, "arg1", "arg2"}, cmdRun.Args) - assert.Equal(t, "Printed to StdOut", stdOut) - assert.Equal(t, "Printed to StdErr", stdErr) - assert.NoError(t, err) -} - -func TestVbmOutErrError(t *testing.T) { - vBoxManager := NewVBoxManager() - vBoxManager.runCmd = func(cmd *exec.Cmd) error { return errors.New("BUG") } - - _, _, err := vBoxManager.vbmOutErr("arg1", "arg2") - - assert.EqualError(t, err, "BUG") -} - -func TestVbmOutErrNotFound(t *testing.T) { - vBoxManager := NewVBoxManager() - vBoxManager.runCmd = func(cmd *exec.Cmd) error { return &exec.Error{Err: exec.ErrNotFound} } - - _, _, err := vBoxManager.vbmOutErr("arg1", "arg2") - - assert.Equal(t, ErrVBMNotFound, err) -} - -func TestVbmOutErrFailingWithExitStatus(t *testing.T) { - vBoxManager := NewVBoxManager() - vBoxManager.runCmd = func(cmd *exec.Cmd) error { - fmt.Fprint(cmd.Stderr, "error: Unable to run vbox") - return errors.New("exit status BUG") - } - - _, _, err := vBoxManager.vbmOutErr("arg1", "arg2", "arg3") - - assert.EqualError(t, err, vboxManageCmd+" arg1 arg2 arg3 failed:\nerror: Unable to run vbox") -} - -func TestVbmOutErrRetryOnce(t *testing.T) { - var cmdRun *exec.Cmd - var runCount int - vBoxManager := NewVBoxManager() - vBoxManager.runCmd = func(cmd *exec.Cmd) error { - cmdRun = cmd - - runCount++ - if runCount == 1 { - fmt.Fprint(cmd.Stderr, "error: The object is not ready") - return errors.New("Fail the first time it's called") - } - - fmt.Fprint(cmd.Stdout, "Printed to StdOut") - return nil - } - - stdOut, stdErr, err := vBoxManager.vbmOutErr("command", "arg") - - assert.Equal(t, 2, runCount) - assert.Equal(t, []string{vboxManageCmd, "command", "arg"}, cmdRun.Args) - assert.Equal(t, "Printed to StdOut", stdOut) - assert.Empty(t, stdErr) - assert.NoError(t, err) -} - -func TestVbmOutErrRetryMax(t *testing.T) { - var runCount int - vBoxManager := NewVBoxManager() - vBoxManager.runCmd = func(cmd *exec.Cmd) error { - runCount++ - fmt.Fprint(cmd.Stderr, "error: The object is not ready") - return errors.New("Always fail") - } - - stdOut, stdErr, err := vBoxManager.vbmOutErr("command", "arg") - - assert.Equal(t, 5, runCount) - assert.Empty(t, stdOut) - assert.Equal(t, "error: The object is not ready", stdErr) - assert.Error(t, err) -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox.go b/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox.go deleted file mode 100644 index 3d79e4e..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox.go +++ /dev/null @@ -1,1021 +0,0 @@ -package virtualbox - -import ( - "errors" - "fmt" - "net" - "os" - "os/exec" - "path/filepath" - "regexp" - "runtime" - "strconv" - "strings" - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/state" -) - -const ( - defaultCPU = 1 - defaultMemory = 1024 - defaultBoot2DockerURL = "" - defaultBoot2DockerImportVM = "" - defaultHostOnlyCIDR = "192.168.99.1/24" - defaultHostOnlyNictype = "82540EM" - defaultHostOnlyPromiscMode = "deny" - defaultUIType = "headless" - defaultHostOnlyNoDHCP = false - defaultDiskSize = 20000 - defaultDNSProxy = true - defaultDNSResolver = false -) - -var ( - ErrUnableToGenerateRandomIP = errors.New("unable to generate random IP") - ErrMustEnableVTX = errors.New("This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory") - ErrNotCompatibleWithHyperV = errors.New("This computer is running Hyper-V. VirtualBox won't boot a 64bits VM when Hyper-V is activated. Either use Hyper-V as a driver, or disable the Hyper-V hypervisor. (To skip this check, use --virtualbox-no-vtx-check)") - ErrNetworkAddrCidr = errors.New("host-only cidr must be specified with a host address, not a network address") - ErrNetworkAddrCollision = errors.New("host-only cidr conflicts with the network address of a host interface") -) - -type Driver struct { - *drivers.BaseDriver - VBoxManager - HostInterfaces - b2dUpdater B2DUpdater - sshKeyGenerator SSHKeyGenerator - diskCreator DiskCreator - logsReader LogsReader - ipWaiter IPWaiter - randomInter RandomInter - sleeper Sleeper - CPU int - Memory int - DiskSize int - NatNicType string - Boot2DockerURL string - Boot2DockerImportVM string - HostDNSResolver bool - HostOnlyCIDR string - HostOnlyNicType string - HostOnlyPromiscMode string - UIType string - HostOnlyNoDHCP bool - NoShare bool - DNSProxy bool - NoVTXCheck bool - ShareFolder string -} - -// NewDriver creates a new VirtualBox driver with default settings. -func NewDriver(hostName, storePath string) *Driver { - return &Driver{ - VBoxManager: NewVBoxManager(), - b2dUpdater: NewB2DUpdater(), - sshKeyGenerator: NewSSHKeyGenerator(), - diskCreator: NewDiskCreator(), - logsReader: NewLogsReader(), - ipWaiter: NewIPWaiter(), - randomInter: NewRandomInter(), - sleeper: NewSleeper(), - HostInterfaces: NewHostInterfaces(), - Memory: defaultMemory, - CPU: defaultCPU, - DiskSize: defaultDiskSize, - NatNicType: defaultHostOnlyNictype, - HostOnlyCIDR: defaultHostOnlyCIDR, - HostOnlyNicType: defaultHostOnlyNictype, - HostOnlyPromiscMode: defaultHostOnlyPromiscMode, - UIType: defaultUIType, - HostOnlyNoDHCP: defaultHostOnlyNoDHCP, - DNSProxy: defaultDNSProxy, - HostDNSResolver: defaultDNSResolver, - BaseDriver: &drivers.BaseDriver{ - MachineName: hostName, - StorePath: storePath, - }, - } -} - -// GetCreateFlags registers the flags this driver adds to -// "docker hosts create" -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.IntFlag{ - Name: "virtualbox-memory", - Usage: "Size of memory for host in MB", - Value: defaultMemory, - EnvVar: "VIRTUALBOX_MEMORY_SIZE", - }, - mcnflag.IntFlag{ - Name: "virtualbox-cpu-count", - Usage: "number of CPUs for the machine (-1 to use the number of CPUs available)", - Value: defaultCPU, - EnvVar: "VIRTUALBOX_CPU_COUNT", - }, - mcnflag.IntFlag{ - Name: "virtualbox-disk-size", - Usage: "Size of disk for host in MB", - Value: defaultDiskSize, - EnvVar: "VIRTUALBOX_DISK_SIZE", - }, - mcnflag.StringFlag{ - Name: "virtualbox-boot2docker-url", - Usage: "The URL of the boot2docker image. Defaults to the latest available version", - Value: defaultBoot2DockerURL, - EnvVar: "VIRTUALBOX_BOOT2DOCKER_URL", - }, - mcnflag.StringFlag{ - Name: "virtualbox-import-boot2docker-vm", - Usage: "The name of a Boot2Docker VM to import", - Value: defaultBoot2DockerImportVM, - EnvVar: "VIRTUALBOX_BOOT2DOCKER_IMPORT_VM", - }, - mcnflag.BoolFlag{ - Name: "virtualbox-host-dns-resolver", - Usage: "Use the host DNS resolver", - EnvVar: "VIRTUALBOX_HOST_DNS_RESOLVER", - }, - mcnflag.StringFlag{ - Name: "virtualbox-nat-nictype", - Usage: "Specify the Network Adapter Type", - Value: defaultHostOnlyNictype, - EnvVar: "VIRTUALBOX_NAT_NICTYPE", - }, - mcnflag.StringFlag{ - Name: "virtualbox-hostonly-cidr", - Usage: "Specify the Host Only CIDR", - Value: defaultHostOnlyCIDR, - EnvVar: "VIRTUALBOX_HOSTONLY_CIDR", - }, - mcnflag.StringFlag{ - Name: "virtualbox-hostonly-nictype", - Usage: "Specify the Host Only Network Adapter Type", - Value: defaultHostOnlyNictype, - EnvVar: "VIRTUALBOX_HOSTONLY_NIC_TYPE", - }, - mcnflag.StringFlag{ - Name: "virtualbox-hostonly-nicpromisc", - Usage: "Specify the Host Only Network Adapter Promiscuous Mode", - Value: defaultHostOnlyPromiscMode, - EnvVar: "VIRTUALBOX_HOSTONLY_NIC_PROMISC", - }, - mcnflag.StringFlag{ - Name: "virtualbox-ui-type", - Usage: "Specify the UI Type: (gui|sdl|headless|separate)", - Value: defaultUIType, - EnvVar: "VIRTUALBOX_UI_TYPE", - }, - mcnflag.BoolFlag{ - Name: "virtualbox-hostonly-no-dhcp", - Usage: "Disable the Host Only DHCP Server", - EnvVar: "VIRTUALBOX_HOSTONLY_NO_DHCP", - }, - mcnflag.BoolFlag{ - Name: "virtualbox-no-share", - Usage: "Disable the mount of your home directory", - EnvVar: "VIRTUALBOX_NO_SHARE", - }, - mcnflag.BoolFlag{ - Name: "virtualbox-no-dns-proxy", - Usage: "Disable proxying all DNS requests to the host", - EnvVar: "VIRTUALBOX_NO_DNS_PROXY", - }, - mcnflag.BoolFlag{ - Name: "virtualbox-no-vtx-check", - Usage: "Disable checking for the availability of hardware virtualization before the vm is started", - EnvVar: "VIRTUALBOX_NO_VTX_CHECK", - }, - mcnflag.StringFlag{ - EnvVar: "VIRTUALBOX_SHARE_FOLDER", - Name: "virtualbox-share-folder", - Usage: "Mount the specified directory instead of the default home location. Format: dir:name", - }, - } -} - -func (d *Driver) GetSSHHostname() (string, error) { - return "127.0.0.1", nil -} - -func (d *Driver) GetSSHUsername() string { - if d.SSHUser == "" { - d.SSHUser = "docker" - } - - return d.SSHUser -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "virtualbox" -} - -func (d *Driver) GetURL() (string, error) { - ip, err := d.GetIP() - if err != nil { - return "", err - } - if ip == "" { - return "", nil - } - return fmt.Sprintf("tcp://%s:2376", ip), nil -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.CPU = flags.Int("virtualbox-cpu-count") - d.Memory = flags.Int("virtualbox-memory") - d.DiskSize = flags.Int("virtualbox-disk-size") - d.Boot2DockerURL = flags.String("virtualbox-boot2docker-url") - d.SetSwarmConfigFromFlags(flags) - d.SSHUser = "docker" - d.Boot2DockerImportVM = flags.String("virtualbox-import-boot2docker-vm") - d.HostDNSResolver = flags.Bool("virtualbox-host-dns-resolver") - d.NatNicType = flags.String("virtualbox-nat-nictype") - d.HostOnlyCIDR = flags.String("virtualbox-hostonly-cidr") - d.HostOnlyNicType = flags.String("virtualbox-hostonly-nictype") - d.HostOnlyPromiscMode = flags.String("virtualbox-hostonly-nicpromisc") - d.UIType = flags.String("virtualbox-ui-type") - d.HostOnlyNoDHCP = flags.Bool("virtualbox-hostonly-no-dhcp") - d.NoShare = flags.Bool("virtualbox-no-share") - d.DNSProxy = !flags.Bool("virtualbox-no-dns-proxy") - d.NoVTXCheck = flags.Bool("virtualbox-no-vtx-check") - d.ShareFolder = flags.String("virtualbox-share-folder") - - return nil -} - -// PreCreateCheck checks that VBoxManage exists and works -func (d *Driver) PreCreateCheck() error { - // Check that VBoxManage exists and works - version, err := d.vbmOut("--version") - if err != nil { - return err - } - - // Check that VBoxManage is of a supported version - if err = checkVBoxManageVersion(strings.TrimSpace(version)); err != nil { - return err - } - - if !d.NoVTXCheck { - if isHyperVInstalled() { - return ErrNotCompatibleWithHyperV - } - - if d.IsVTXDisabled() { - return ErrMustEnableVTX - } - } - - // Downloading boot2docker to cache should be done here to make sure - // that a download failure will not leave a machine half created. - if err := d.b2dUpdater.UpdateISOCache(d.StorePath, d.Boot2DockerURL); err != nil { - return err - } - - // Check that Host-only interfaces are ok - if _, err = listHostOnlyAdapters(d.VBoxManager); err != nil { - return err - } - - return nil -} - -func (d *Driver) Create() error { - if err := d.CreateVM(); err != nil { - return err - } - - log.Info("Starting the VM...") - return d.Start() -} - -func (d *Driver) CreateVM() error { - if err := d.b2dUpdater.CopyIsoToMachineDir(d.StorePath, d.MachineName, d.Boot2DockerURL); err != nil { - return err - } - - log.Info("Creating VirtualBox VM...") - - // import b2d VM if requested - if d.Boot2DockerImportVM != "" { - name := d.Boot2DockerImportVM - - // make sure vm is stopped - _ = d.vbm("controlvm", name, "poweroff") - - diskInfo, err := getVMDiskInfo(name, d.VBoxManager) - if err != nil { - return err - } - - if _, err := os.Stat(diskInfo.Path); err != nil { - return err - } - - if err := d.vbm("clonehd", diskInfo.Path, d.diskPath()); err != nil { - return err - } - - log.Debugf("Importing VM settings...") - vmInfo, err := getVMInfo(name, d.VBoxManager) - if err != nil { - return err - } - - d.CPU = vmInfo.CPUs - d.Memory = vmInfo.Memory - - log.Debugf("Importing SSH key...") - keyPath := filepath.Join(mcnutils.GetHomeDir(), ".ssh", "id_boot2docker") - if err := mcnutils.CopyFile(keyPath, d.GetSSHKeyPath()); err != nil { - return err - } - } else { - log.Infof("Creating SSH key...") - if err := d.sshKeyGenerator.Generate(d.GetSSHKeyPath()); err != nil { - return err - } - - log.Debugf("Creating disk image...") - if err := d.diskCreator.Create(d.DiskSize, d.publicSSHKeyPath(), d.diskPath()); err != nil { - return err - } - } - - if err := d.vbm("createvm", - "--basefolder", d.ResolveStorePath("."), - "--name", d.MachineName, - "--register"); err != nil { - return err - } - - log.Debugf("VM CPUS: %d", d.CPU) - log.Debugf("VM Memory: %d", d.Memory) - - cpus := d.CPU - if cpus < 1 { - cpus = int(runtime.NumCPU()) - } - if cpus > 32 { - cpus = 32 - } - - hostDNSResolver := "off" - if d.HostDNSResolver { - hostDNSResolver = "on" - } - - dnsProxy := "off" - if d.DNSProxy { - dnsProxy = "on" - } - - var modifyFlags = []string{ - "modifyvm", d.MachineName, - "--firmware", "bios", - "--bioslogofadein", "off", - "--bioslogofadeout", "off", - "--bioslogodisplaytime", "0", - "--biosbootmenu", "disabled", - "--ostype", "Linux26_64", - "--cpus", fmt.Sprintf("%d", cpus), - "--memory", fmt.Sprintf("%d", d.Memory), - "--acpi", "on", - "--ioapic", "on", - "--rtcuseutc", "on", - "--natdnshostresolver1", hostDNSResolver, - "--natdnsproxy1", dnsProxy, - "--cpuhotplug", "off", - "--pae", "on", - "--hpet", "on", - "--hwvirtex", "on", - "--nestedpaging", "on", - "--largepages", "on", - "--vtxvpid", "on", - "--accelerate3d", "off", - "--boot1", "dvd"} - - if runtime.GOOS == "windows" && runtime.GOARCH == "386" { - modifyFlags = append(modifyFlags, "--longmode", "on") - } - - if err := d.vbm(modifyFlags...); err != nil { - return err - } - - if err := d.vbm("modifyvm", d.MachineName, - "--nic1", "nat", - "--nictype1", d.NatNicType, - "--cableconnected1", "on"); err != nil { - return err - } - - if err := d.vbm("storagectl", d.MachineName, - "--name", "SATA", - "--add", "sata", - "--hostiocache", "on"); err != nil { - return err - } - - if err := d.vbm("storageattach", d.MachineName, - "--storagectl", "SATA", - "--port", "0", - "--device", "0", - "--type", "dvddrive", - "--medium", d.ResolveStorePath("boot2docker.iso")); err != nil { - return err - } - - if err := d.vbm("storageattach", d.MachineName, - "--storagectl", "SATA", - "--port", "1", - "--device", "0", - "--type", "hdd", - "--medium", d.diskPath()); err != nil { - return err - } - - // let VBoxService do nice magic automounting (when it's used) - if err := d.vbm("guestproperty", "set", d.MachineName, "/VirtualBox/GuestAdd/SharedFolders/MountPrefix", "/"); err != nil { - return err - } - if err := d.vbm("guestproperty", "set", d.MachineName, "/VirtualBox/GuestAdd/SharedFolders/MountDir", "/"); err != nil { - return err - } - - shareName, shareDir := getShareDriveAndName() - - if d.ShareFolder != "" { - shareDir, shareName = parseShareFolder(d.ShareFolder) - } - - if shareDir != "" && !d.NoShare { - log.Debugf("setting up shareDir '%s' -> '%s'", shareDir, shareName) - if _, err := os.Stat(shareDir); err != nil && !os.IsNotExist(err) { - return err - } else if !os.IsNotExist(err) { - if shareName == "" { - // parts of the VBox internal code are buggy with share names that start with "/" - shareName = strings.TrimLeft(shareDir, "/") - // TODO do some basic Windows -> MSYS path conversion - // ie, s!^([a-z]+):[/\\]+!\1/!; s!\\!/!g - } - - // woo, shareDir exists! let's carry on! - if err := d.vbm("sharedfolder", "add", d.MachineName, "--name", shareName, "--hostpath", shareDir, "--automount"); err != nil { - return err - } - - // enable symlinks - if err := d.vbm("setextradata", d.MachineName, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/"+shareName, "1"); err != nil { - return err - } - } - } - - return nil -} - -func parseShareFolder(shareFolder string) (string, string) { - split := strings.Split(shareFolder, ":") - shareDir := strings.Join(split[:len(split)-1], ":") - shareName := split[len(split)-1] - return shareDir, shareName -} - -func (d *Driver) hostOnlyIPAvailable() bool { - ip, err := d.GetIP() - if err != nil { - log.Debugf("ERROR getting IP: %s", err) - return false - } - if ip == "" { - log.Debug("Strangely, there was no error attempting to get the IP, but it was still empty.") - return false - } - - log.Debugf("IP is %s", ip) - return true -} - -func (d *Driver) Start() error { - s, err := d.GetState() - if err != nil { - return err - } - - var hostOnlyAdapter *hostOnlyNetwork - if s == state.Stopped { - log.Infof("Check network to re-create if needed...") - - if hostOnlyAdapter, err = d.setupHostOnlyNetwork(d.MachineName); err != nil { - return fmt.Errorf("Error setting up host only network on machine start: %s", err) - } - } - - switch s { - case state.Stopped, state.Saved: - d.SSHPort, err = setPortForwarding(d, 1, "ssh", "tcp", 22, d.SSHPort) - if err != nil { - return err - } - - if err := d.vbm("startvm", d.MachineName, "--type", d.UIType); err != nil { - if lines, readErr := d.readVBoxLog(); readErr == nil && len(lines) > 0 { - return fmt.Errorf("Unable to start the VM: %s\nDetails: %s", err, lines[len(lines)-1]) - } - return fmt.Errorf("Unable to start the VM: %s", err) - } - case state.Paused: - if err := d.vbm("controlvm", d.MachineName, "resume", "--type", d.UIType); err != nil { - return err - } - log.Infof("Resuming VM ...") - default: - log.Infof("VM not in restartable state") - } - - if !d.NoVTXCheck { - // Verify that VT-X is not disabled in the started VM - vtxIsDisabled, err := d.IsVTXDisabledInTheVM() - if err != nil { - return fmt.Errorf("Checking if hardware virtualization is enabled failed: %s", err) - } - - if vtxIsDisabled { - return ErrMustEnableVTX - } - } - - log.Infof("Waiting for an IP...") - if err := d.ipWaiter.Wait(d); err != nil { - return err - } - - if hostOnlyAdapter == nil { - return nil - } - - // Check that the host-only adapter we just created can still be found - // Sometimes it is corrupted after the VM is started. - nets, err := listHostOnlyAdapters(d.VBoxManager) - if err != nil { - return err - } - - ip, network, err := parseAndValidateCIDR(d.HostOnlyCIDR) - if err != nil { - return err - } - - err = validateNoIPCollisions(d.HostInterfaces, network, nets) - if err != nil { - return err - } - - hostOnlyNet := getHostOnlyAdapter(nets, ip, network.Mask) - if hostOnlyNet != nil { - // OK, we found a valid host-only adapter - return nil - } - - // This happens a lot on windows. The adapter has an invalid IP and the VM has the same IP - log.Warn("The host-only adapter is corrupted. Let's stop the VM, fix the host-only adapter and restart the VM") - if err := d.Stop(); err != nil { - return err - } - - // We have to be sure the host-only adapter is not used by the VM - d.sleeper.Sleep(5 * time.Second) - - log.Debugf("Fixing %+v...", hostOnlyAdapter) - if err := hostOnlyAdapter.SaveIPv4(d.VBoxManager); err != nil { - return err - } - - // We have to be sure the adapter is updated before starting the VM - d.sleeper.Sleep(5 * time.Second) - - if err := d.vbm("startvm", d.MachineName, "--type", d.UIType); err != nil { - return fmt.Errorf("Unable to start the VM: %s", err) - } - - log.Infof("Waiting for an IP...") - return d.ipWaiter.Wait(d) -} - -func (d *Driver) Stop() error { - currentState, err := d.GetState() - if err != nil { - return err - } - - if currentState == state.Paused { - if err := d.vbm("controlvm", d.MachineName, "resume"); err != nil { // , "--type", d.UIType - return err - } - log.Infof("Resuming VM ...") - } - - if err := d.vbm("controlvm", d.MachineName, "acpipowerbutton"); err != nil { - return err - } - for { - s, err := d.GetState() - if err != nil { - return err - } - if s == state.Running { - d.sleeper.Sleep(1 * time.Second) - } else { - break - } - } - - d.IPAddress = "" - - return nil -} - -// Restart restarts a machine which is known to be running. -func (d *Driver) Restart() error { - if err := d.Stop(); err != nil { - return fmt.Errorf("Problem stopping the VM: %s", err) - } - - if err := d.Start(); err != nil { - return fmt.Errorf("Problem starting the VM: %s", err) - } - - d.IPAddress = "" - - return d.ipWaiter.Wait(d) -} - -func (d *Driver) Kill() error { - return d.vbm("controlvm", d.MachineName, "poweroff") -} - -func (d *Driver) Remove() error { - s, err := d.GetState() - if err == ErrMachineNotExist { - return nil - } - if err != nil { - return err - } - - if s != state.Stopped && s != state.Saved { - if err := d.Kill(); err != nil { - return err - } - } - - return d.vbm("unregistervm", "--delete", d.MachineName) -} - -func (d *Driver) GetState() (state.State, error) { - stdout, stderr, err := d.vbmOutErr("showvminfo", d.MachineName, "--machinereadable") - if err != nil { - if reMachineNotFound.FindString(stderr) != "" { - return state.Error, ErrMachineNotExist - } - return state.Error, err - } - re := regexp.MustCompile(`(?m)^VMState="(\w+)"`) - groups := re.FindStringSubmatch(stdout) - if len(groups) < 1 { - return state.None, nil - } - switch groups[1] { - case "running": - return state.Running, nil - case "paused": - return state.Paused, nil - case "saved": - return state.Saved, nil - case "poweroff", "aborted": - return state.Stopped, nil - } - return state.None, nil -} - -func (d *Driver) getHostOnlyMACAddress() (string, error) { - // Return the MAC address of the host-only adapter - // assigned to this machine. The returned address - // is lower-cased and does not contain colons. - - stdout, stderr, err := d.vbmOutErr("showvminfo", d.MachineName, "--machinereadable") - if err != nil { - if reMachineNotFound.FindString(stderr) != "" { - return "", ErrMachineNotExist - } - return "", err - } - - // First, we get the number of the host-only interface - re := regexp.MustCompile(`(?m)^hostonlyadapter([\d]+)`) - groups := re.FindStringSubmatch(stdout) - if len(groups) < 2 { - return "", errors.New("Machine does not have a host-only adapter") - } - - // Then we grab the MAC address based on that number - adapterNumber := groups[1] - re = regexp.MustCompile(fmt.Sprintf("(?m)^macaddress%s=\"(.*)\"", adapterNumber)) - groups = re.FindStringSubmatch(stdout) - if len(groups) < 2 { - return "", fmt.Errorf("Could not find MAC address for adapter %v", adapterNumber) - } - - return strings.ToLower(groups[1]), nil -} - -func (d *Driver) parseIPForMACFromIPAddr(ipAddrOutput string, macAddress string) (string, error) { - // Given the output of "ip addr show" on the VM, return the IPv4 address - // of the interface with the given MAC address. - - lines := strings.Split(ipAddrOutput, "\n") - returnNextIP := false - - for _, line := range lines { - line = strings.TrimSpace(line) - - if strings.HasPrefix(line, "link") { // line contains MAC address - vals := strings.Split(line, " ") - if len(vals) >= 2 { - macBlock := vals[1] - macWithoutColons := strings.Replace(macBlock, ":", "", -1) - if macWithoutColons == macAddress { // we are in the correct device block - returnNextIP = true - } - } - } else if strings.HasPrefix(line, "inet") && !strings.HasPrefix(line, "inet6") && returnNextIP { - vals := strings.Split(line, " ") - if len(vals) >= 2 { - return vals[1][:strings.Index(vals[1], "/")], nil - } - } - } - - return "", fmt.Errorf("Could not find matching IP for MAC address %v", macAddress) -} - -func (d *Driver) GetIP() (string, error) { - // DHCP is used to get the IP, so virtualbox hosts don't have IPs unless - // they are running - s, err := d.GetState() - if err != nil { - return "", err - } - if s != state.Running { - return "", drivers.ErrHostIsNotRunning - } - - macAddress, err := d.getHostOnlyMACAddress() - if err != nil { - return "", err - } - - log.Debugf("Host-only MAC: %s\n", macAddress) - - output, err := drivers.RunSSHCommandFromDriver(d, "ip addr show") - if err != nil { - return "", err - } - - log.Debugf("SSH returned: %s\nEND SSH\n", output) - - ipAddress, err := d.parseIPForMACFromIPAddr(output, macAddress) - if err != nil { - return "", err - } - - return ipAddress, nil -} - -func (d *Driver) publicSSHKeyPath() string { - return d.GetSSHKeyPath() + ".pub" -} - -func (d *Driver) diskPath() string { - return d.ResolveStorePath("disk.vmdk") -} - -func (d *Driver) setupHostOnlyNetwork(machineName string) (*hostOnlyNetwork, error) { - hostOnlyCIDR := d.HostOnlyCIDR - - // This is to assist in migrating from version 0.2 to 0.3 format - // it should be removed in a later release - if hostOnlyCIDR == "" { - hostOnlyCIDR = defaultHostOnlyCIDR - } - - ip, network, err := parseAndValidateCIDR(hostOnlyCIDR) - if err != nil { - return nil, err - } - - nets, err := listHostOnlyAdapters(d.VBoxManager) - if err != nil { - return nil, err - } - - err = validateNoIPCollisions(d.HostInterfaces, network, nets) - if err != nil { - return nil, err - } - - log.Debugf("Searching for hostonly interface for IPv4: %s and Mask: %s", ip, network.Mask) - hostOnlyAdapter, err := getOrCreateHostOnlyNetwork(ip, network.Mask, nets, d.VBoxManager) - if err != nil { - return nil, err - } - - if err := removeOrphanDHCPServers(d.VBoxManager); err != nil { - return nil, err - } - - dhcpAddr, err := getRandomIPinSubnet(d, ip) - if err != nil { - return nil, err - } - - lowerIP, upperIP := getDHCPAddressRange(dhcpAddr, network) - - log.Debugf("Adding/Modifying DHCP server %q with address range %q - %q...", dhcpAddr, lowerIP, upperIP) - - dhcp := dhcpServer{} - dhcp.IPv4.IP = dhcpAddr - dhcp.IPv4.Mask = network.Mask - dhcp.LowerIP = lowerIP - dhcp.UpperIP = upperIP - dhcp.Enabled = !d.HostOnlyNoDHCP - if err := addHostOnlyDHCPServer(hostOnlyAdapter.Name, dhcp, d.VBoxManager); err != nil { - return nil, err - } - - if err := d.vbm("modifyvm", machineName, - "--nic2", "hostonly", - "--nictype2", d.HostOnlyNicType, - "--nicpromisc2", d.HostOnlyPromiscMode, - "--hostonlyadapter2", hostOnlyAdapter.Name, - "--cableconnected2", "on"); err != nil { - return nil, err - } - - return hostOnlyAdapter, nil -} - -func getDHCPAddressRange(dhcpAddr net.IP, network *net.IPNet) (lowerIP net.IP, upperIP net.IP) { - nAddr := network.IP.To4() - ones, bits := network.Mask.Size() - - if ones <= 24 { - // For a /24 subnet, use the original behavior of allowing the address range - // between x.x.x.100 and x.x.x.254. - lowerIP = net.IPv4(nAddr[0], nAddr[1], nAddr[2], byte(100)) - upperIP = net.IPv4(nAddr[0], nAddr[1], nAddr[2], byte(254)) - return - } - - // Start the lowerIP range one address above the selected DHCP address. - lowerIP = net.IPv4(nAddr[0], nAddr[1], nAddr[2], dhcpAddr.To4()[3]+1) - - // The highest D-part of the address A.B.C.D in this subnet is at 2^n - 1, - // where n is the number of available bits in the subnet. Since the highest - // address is reserved for subnet broadcast, the highest *assignable* address - // is at (2^n - 1) - 1 == 2^n - 2. - maxAssignableSubnetAddress := (byte)((1 << (uint)(bits-ones)) - 2) - upperIP = net.IPv4(nAddr[0], nAddr[1], nAddr[2], maxAssignableSubnetAddress) - return -} - -func parseAndValidateCIDR(hostOnlyCIDR string) (net.IP, *net.IPNet, error) { - ip, network, err := net.ParseCIDR(hostOnlyCIDR) - if err != nil { - return nil, nil, err - } - - networkAddress := network.IP.To4() - if ip.Equal(networkAddress) { - return nil, nil, ErrNetworkAddrCidr - } - - return ip, network, nil -} - -// validateNoIPCollisions ensures no conflicts between the host's network interfaces and the vbox host-only network that -// will be used for machine vm instances. -func validateNoIPCollisions(hif HostInterfaces, hostOnlyNet *net.IPNet, currHostOnlyNets map[string]*hostOnlyNetwork) error { - hostOnlyByCIDR := map[string]*hostOnlyNetwork{} - //listHostOnlyAdapters returns a map w/ virtualbox net names as key. Rekey to CIDRs - for _, n := range currHostOnlyNets { - ipnet := net.IPNet{IP: n.IPv4.IP, Mask: n.IPv4.Mask} - hostOnlyByCIDR[ipnet.String()] = n - } - - m, err := listHostInterfaces(hif, hostOnlyByCIDR) - if err != nil { - return err - } - - collision, err := checkIPNetCollision(hostOnlyNet, m) - if err != nil { - return err - } - - if collision { - return ErrNetworkAddrCollision - } - return nil -} - -// Select an available port, trying the specified -// port first, falling back on an OS selected port. -func getAvailableTCPPort(port int) (int, error) { - for i := 0; i <= 10; i++ { - ln, err := net.Listen("tcp4", fmt.Sprintf("127.0.0.1:%d", port)) - if err != nil { - return 0, err - } - defer ln.Close() - addr := ln.Addr().String() - addrParts := strings.SplitN(addr, ":", 2) - p, err := strconv.Atoi(addrParts[1]) - if err != nil { - return 0, err - } - if p != 0 { - port = p - return port, nil - } - port = 0 // Throw away the port hint before trying again - time.Sleep(1) - } - return 0, fmt.Errorf("unable to allocate tcp port") -} - -// Setup a NAT port forwarding entry. -func setPortForwarding(d *Driver, interfaceNum int, mapName, protocol string, guestPort, desiredHostPort int) (int, error) { - actualHostPort, err := getAvailableTCPPort(desiredHostPort) - if err != nil { - return -1, err - } - if desiredHostPort != actualHostPort && desiredHostPort != 0 { - log.Debugf("NAT forwarding host port for guest port %d (%s) changed from %d to %d", - guestPort, mapName, desiredHostPort, actualHostPort) - } - cmd := fmt.Sprintf("--natpf%d", interfaceNum) - d.vbm("modifyvm", d.MachineName, cmd, "delete", mapName) - if err := d.vbm("modifyvm", d.MachineName, - cmd, fmt.Sprintf("%s,%s,127.0.0.1,%d,,%d", mapName, protocol, actualHostPort, guestPort)); err != nil { - return -1, err - } - return actualHostPort, nil -} - -// getRandomIPinSubnet returns a pseudo-random net.IP in the same -// subnet as the IP passed -func getRandomIPinSubnet(d *Driver, baseIP net.IP) (net.IP, error) { - var dhcpAddr net.IP - - nAddr := baseIP.To4() - // select pseudo-random DHCP addr; make sure not to clash with the host - // only try 5 times and bail if no random received - for i := 0; i < 5; i++ { - n := d.randomInter.RandomInt(24) + 1 - if byte(n) != nAddr[3] { - dhcpAddr = net.IPv4(nAddr[0], nAddr[1], nAddr[2], byte(n)) - break - } - } - - if dhcpAddr == nil { - return nil, ErrUnableToGenerateRandomIP - } - - return dhcpAddr, nil -} - -func detectVBoxManageCmdInPath() string { - cmd := "VBoxManage" - if path, err := exec.LookPath(cmd); err == nil { - return path - } - return cmd -} - -func (d *Driver) readVBoxLog() ([]string, error) { - logPath := filepath.Join(d.ResolveStorePath(d.MachineName), "Logs", "VBox.log") - log.Debugf("Checking vm logs: %s", logPath) - - return d.logsReader.Read(logPath) -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_darwin.go b/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_darwin.go deleted file mode 100644 index 6c100e1..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_darwin.go +++ /dev/null @@ -1,35 +0,0 @@ -package virtualbox - -import ( - "strings" - "syscall" - - "github.com/docker/machine/libmachine/log" -) - -// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start. -// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started. -func (d *Driver) IsVTXDisabled() bool { - features, err := syscall.Sysctl("machdep.cpu.features") - if err != nil { - log.Debugf("Couldn't check that VT-X/AMD-v is enabled. Will check that the vm is properly created: %v", err) - return false - } - return isVTXDisabled(features) -} - -func isVTXDisabled(features string) bool { - return !strings.Contains(features, "VMX") -} - -func detectVBoxManageCmd() string { - return detectVBoxManageCmdInPath() -} - -func getShareDriveAndName() (string, string) { - return "Users", "/Users" -} - -func isHyperVInstalled() bool { - return false -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_darwin_test.go b/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_darwin_test.go deleted file mode 100644 index b1e840e..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_darwin_test.go +++ /dev/null @@ -1,25 +0,0 @@ -package virtualbox - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -const ( - featuresWithVMX = "FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 VMX PBE SSE3 PCLMULQDQ DTES64 AVX1.0 RDRAND F16C" - featuresNoVMX = "FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 PBE SSE3 PCLMULQDQ DTES64 AVX1.0 RDRAND F16C" -) - -func TestShareName(t *testing.T) { - name, dir := getShareDriveAndName() - - assert.Equal(t, name, "Users") - assert.Equal(t, dir, "/Users") - -} - -func TestIsVTXEnabled(t *testing.T) { - assert.False(t, isVTXDisabled(featuresWithVMX)) - assert.True(t, isVTXDisabled(featuresNoVMX)) -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_freebsd.go b/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_freebsd.go deleted file mode 100644 index 0631ed5..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_freebsd.go +++ /dev/null @@ -1,45 +0,0 @@ -package virtualbox - -import ( - "bytes" - "io/ioutil" - - "github.com/docker/machine/libmachine/log" -) - -// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start. -// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started. -// We want to check that either vmx or svm flags are present in /proc/cpuinfo. -func (d *Driver) IsVTXDisabled() bool { - cpuinfo, err := ioutil.ReadFile("/proc/cpuinfo") - if err != nil { - log.Debugf("Couldn't check that VT-X/AMD-v is enabled. Will check that the vm is properly created: %v", err) - return false - } - return isVTXDisabled(cpuinfo) -} - -func isVTXDisabled(cpuinfo []byte) bool { - features := [2][]byte{ - {'v', 'm', 'x'}, - {'s', 'v', 'm'}, - } - for _, v := range features { - if bytes.Contains(cpuinfo, v) { - return false - } - } - return true -} - -func detectVBoxManageCmd() string { - return detectVBoxManageCmdInPath() -} - -func getShareDriveAndName() (string, string) { - return "hosthome", "/home" -} - -func isHyperVInstalled() bool { - return false -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_linux.go b/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_linux.go deleted file mode 100644 index 0631ed5..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_linux.go +++ /dev/null @@ -1,45 +0,0 @@ -package virtualbox - -import ( - "bytes" - "io/ioutil" - - "github.com/docker/machine/libmachine/log" -) - -// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start. -// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started. -// We want to check that either vmx or svm flags are present in /proc/cpuinfo. -func (d *Driver) IsVTXDisabled() bool { - cpuinfo, err := ioutil.ReadFile("/proc/cpuinfo") - if err != nil { - log.Debugf("Couldn't check that VT-X/AMD-v is enabled. Will check that the vm is properly created: %v", err) - return false - } - return isVTXDisabled(cpuinfo) -} - -func isVTXDisabled(cpuinfo []byte) bool { - features := [2][]byte{ - {'v', 'm', 'x'}, - {'s', 'v', 'm'}, - } - for _, v := range features { - if bytes.Contains(cpuinfo, v) { - return false - } - } - return true -} - -func detectVBoxManageCmd() string { - return detectVBoxManageCmdInPath() -} - -func getShareDriveAndName() (string, string) { - return "hosthome", "/home" -} - -func isHyperVInstalled() bool { - return false -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_linux_test.go b/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_linux_test.go deleted file mode 100644 index da4d452..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_linux_test.go +++ /dev/null @@ -1,115 +0,0 @@ -package virtualbox - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -const ( - amdCPUInfo = ` -processor : 0 -vendor_id : AuthenticAMD -cpu family : 20 -model : 1 -model name : AMD C-50 Processor -stepping : 0 -microcode : 0x5000026 -cpu MHz : 800.000 -cache size : 512 KB -physical id : 0 -siblings : 2 -core id : 0 -cpu cores : 2 -apicid : 0 -initial apicid : 0 -fpu : yes -fpu_exception : yes -cpuid level : 6 -wp : yes -flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc extd_apicid aperfmperf pni monitor ssse3 cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch ibs skinit wdt arat hw_pstate npt lbrv svm_lock nrip_save pausefilter vmmcall -bugs : fxsave_leak sysret_ss_attrs -bogomips : 1995.09 -TLB size : 1024 4K pages -clflush size : 64 -cache_alignment : 64 -address sizes : 36 bits physical, 48 bits virtual -power management: ts ttp tm stc 100mhzsteps hwpstate -` - intelCPUInfo = ` -processor : 0 -vendor_id : GenuineIntel -cpu family : 6 -model : 70 -model name : Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz -stepping : 1 -microcode : 0x19 -cpu MHz : 2294.688 -cache size : 6144 KB -physical id : 0 -siblings : 1 -core id : 0 -cpu cores : 1 -apicid : 0 -initial apicid : 0 -fpu : yes -fpu_exception : yes -cpuid level : 13 -wp : yes -flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr vmx pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq monitor ssse3 cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm -bugs : -bogomips : 4589.37 -clflush size : 64 -cache_alignment : 64 -address sizes : 39 bits physical, 48 bits virtual -power management: -` - - faultyCPUInfo = ` -processor : 0 -vendor_id : GenuineIntel -cpu family : 6 -model : 70 -model name : Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz -stepping : 1 -microcode : 0x19 -cpu MHz : 2294.688 -cache size : 6144 KB -physical id : 0 -siblings : 1 -core id : 0 -cpu cores : 1 -apicid : 0 -initial apicid : 0 -fpu : yes -fpu_exception : yes -cpuid level : 13 -wp : yes -flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq monitor ssse3 cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm -bugs : -bogomips : 4589.37 -clflush size : 64 -cache_alignment : 64 -address sizes : 39 bits physical, 48 bits virtual -power management: -` -) - -func TestShareName(t *testing.T) { - name, dir := getShareDriveAndName() - - assert.Equal(t, name, "hosthome") - assert.Equal(t, dir, "/home") -} - -func TestCpuInfoOnAMD(t *testing.T) { - assert.False(t, isVTXDisabled([]byte(amdCPUInfo))) -} - -func TestCpuInfoOnIntel(t *testing.T) { - assert.False(t, isVTXDisabled([]byte(intelCPUInfo))) -} - -func TestCpuInfoOnNone(t *testing.T) { - assert.True(t, isVTXDisabled([]byte(faultyCPUInfo))) -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_test.go b/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_test.go deleted file mode 100644 index 24899fe..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_test.go +++ /dev/null @@ -1,732 +0,0 @@ -package virtualbox - -import ( - "errors" - "fmt" - "net" - "reflect" - "runtime" - "strings" - "testing" - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/state" - "github.com/stretchr/testify/assert" -) - -type VBoxManagerMock struct { - args string - stdOut string - stdErr string - err error -} - -func (v *VBoxManagerMock) vbm(args ...string) error { - _, _, err := v.vbmOutErr(args...) - return err -} - -func (v *VBoxManagerMock) vbmOut(args ...string) (string, error) { - stdout, _, err := v.vbmOutErr(args...) - return stdout, err -} - -func (v *VBoxManagerMock) vbmOutErr(args ...string) (string, string, error) { - if strings.Join(args, " ") == v.args { - return v.stdOut, v.stdErr, v.err - } - return "", "", errors.New("Invalid args") -} - -func newTestDriver(name string) *Driver { - return NewDriver(name, "") -} - -func TestDriverName(t *testing.T) { - driverName := newTestDriver("default").DriverName() - - assert.Equal(t, "virtualbox", driverName) -} - -func TestSSHHostname(t *testing.T) { - hostname, err := newTestDriver("default").GetSSHHostname() - - assert.Equal(t, "127.0.0.1", hostname) - assert.NoError(t, err) -} - -func TestDefaultSSHUsername(t *testing.T) { - username := newTestDriver("default").GetSSHUsername() - - assert.Equal(t, "docker", username) -} - -var parseShareFolderTestCases = []struct { - shareFolder string - expectedShareDir string - expectedShareName string -}{ - {"dir:name", "dir", "name"}, - {"C:\\dir:name", "C:\\dir", "name"}, - {"C:\\:name", "C:\\", "name"}, -} - -func TestParseShareFolder(t *testing.T) { - for _, parseShareFolderTestCase := range parseShareFolderTestCases { - shareDir, shareName := parseShareFolder(parseShareFolderTestCase.shareFolder) - - assert.Equal(t, shareDir, parseShareFolderTestCase.expectedShareDir) - assert.Equal(t, shareName, parseShareFolderTestCase.expectedShareName) - } -} - -func TestState(t *testing.T) { - var tests = []struct { - stdOut string - state state.State - }{ - {`VMState="running"`, state.Running}, - {`VMState="paused"`, state.Paused}, - {`VMState="saved"`, state.Saved}, - {`VMState="poweroff"`, state.Stopped}, - {`VMState="aborted"`, state.Stopped}, - {`VMState="whatever"`, state.None}, - {`VMState=`, state.None}, - } - - for _, expected := range tests { - driver := newTestDriver("default") - driver.VBoxManager = &VBoxManagerMock{ - args: "showvminfo default --machinereadable", - stdOut: expected.stdOut, - } - - machineState, err := driver.GetState() - - assert.NoError(t, err) - assert.Equal(t, expected.state, machineState) - } -} - -func TestStateErrors(t *testing.T) { - var tests = []struct { - stdErr string - err error - finalErr error - }{ - {"Could not find a registered machine named 'unknown'", errors.New("Bug"), errors.New("machine does not exist")}, - {"", errors.New("Unexpected error"), errors.New("Unexpected error")}, - } - - for _, expected := range tests { - driver := newTestDriver("default") - driver.VBoxManager = &VBoxManagerMock{ - args: "showvminfo default --machinereadable", - stdErr: expected.stdErr, - err: expected.err, - } - - machineState, err := driver.GetState() - - assert.Equal(t, err, expected.finalErr) - assert.Equal(t, state.Error, machineState) - } -} - -func TestGetRandomIPinSubnet(t *testing.T) { - driver := newTestDriver("default") - - // test IP 1.2.3.4 - testIP := net.IPv4(byte(1), byte(2), byte(3), byte(4)) - newIP, err := getRandomIPinSubnet(driver, testIP) - if err != nil { - t.Fatal(err) - } - - if testIP.Equal(newIP) { - t.Fatalf("expected different IP (source %s); received %s", testIP.String(), newIP.String()) - } - - if newIP[0] != testIP[0] { - t.Fatalf("expected first octet of %d; received %d", testIP[0], newIP[0]) - } - - if newIP[1] != testIP[1] { - t.Fatalf("expected second octet of %d; received %d", testIP[1], newIP[1]) - } - - if newIP[2] != testIP[2] { - t.Fatalf("expected third octet of %d; received %d", testIP[2], newIP[2]) - } -} - -func TestGetHostOnlyMACAddress(t *testing.T) { - driver := newTestDriver("default") - driver.VBoxManager = &VBoxManagerMock{ - args: "showvminfo default --machinereadable", - stdOut: "unrelatedfield=whatever\nhostonlyadapter2=\"vboxnet1\"\nmacaddress2=\"004488AABBCC\"\n", - } - - result, err := driver.getHostOnlyMACAddress() - expected := "004488aabbcc" - assert.NoError(t, err) - assert.Equal(t, expected, result) -} - -func TestGetHostOnlyMACAddressWhenNoHostOnlyAdapter(t *testing.T) { - driver := newTestDriver("default") - driver.VBoxManager = &VBoxManagerMock{ - args: "showvminfo default --machinereadable", - stdOut: "unrelatedfield=whatever\n", - } - - result, err := driver.getHostOnlyMACAddress() - assert.Empty(t, result) - assert.Equal(t, err, errors.New("Machine does not have a host-only adapter")) -} - -func TestParseIPForMACFromIPAddr(t *testing.T) { - driver := newTestDriver("default") - - ipAddrOutput := "1: eth0:\n link/ether 00:44:88:aa:bb:cc\n inet 1.2.3.4/24\n2: eth1:\n link/ether 11:55:99:dd:ee:ff\n inet 5.6.7.8/24" - - result, err := driver.parseIPForMACFromIPAddr(ipAddrOutput, "004488aabbcc") - assert.NoError(t, err) - assert.Equal(t, result, "1.2.3.4") - - result, err = driver.parseIPForMACFromIPAddr(ipAddrOutput, "115599ddeeff") - assert.NoError(t, err) - assert.Equal(t, result, "5.6.7.8") - - result, err = driver.parseIPForMACFromIPAddr(ipAddrOutput, "000000000000") - assert.Empty(t, result) - assert.Equal(t, err, errors.New("Could not find matching IP for MAC address 000000000000")) -} - -func TestGetIPErrors(t *testing.T) { - var tests = []struct { - stdOut string - err error - finalErr error - }{ - {`VMState="poweroff"`, nil, errors.New("Host is not running")}, - {"", errors.New("Unable to get state"), errors.New("Unable to get state")}, - } - - for _, expected := range tests { - driver := newTestDriver("default") - driver.VBoxManager = &VBoxManagerMock{ - args: "showvminfo default --machinereadable", - stdOut: expected.stdOut, - err: expected.err, - } - - ip, err := driver.GetIP() - - assert.Empty(t, ip) - assert.Equal(t, err, expected.finalErr) - - url, err := driver.GetURL() - - assert.Empty(t, url) - assert.Equal(t, err, expected.finalErr) - } -} - -func TestParseValidCIDR(t *testing.T) { - ip, network, err := parseAndValidateCIDR("192.168.100.1/24") - - assert.Equal(t, "192.168.100.1", ip.String()) - assert.Equal(t, "192.168.100.0", network.IP.String()) - assert.Equal(t, "ffffff00", network.Mask.String()) - assert.NoError(t, err) -} - -func TestInvalidCIDR(t *testing.T) { - ip, network, err := parseAndValidateCIDR("192.168.100.1") - - assert.EqualError(t, err, "invalid CIDR address: 192.168.100.1") - assert.Nil(t, ip) - assert.Nil(t, network) -} - -func TestInvalidNetworkIpCIDR(t *testing.T) { - ip, network, err := parseAndValidateCIDR("192.168.100.0/24") - - assert.Equal(t, ErrNetworkAddrCidr, err) - assert.Nil(t, ip) - assert.Nil(t, network) -} - -// Tests detection of a conflict between an existing vbox host-only network and a host network interface. This -// scenario would happen if the docker-machine was created with the host on one network, and then the host gets -// moved to another network (e.g. different wifi routers) -func TestCIDRHostIFaceCollisionExisting(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "list hostonlyifs", - stdOut: stdOutTwoHostOnlyNetwork, - } - mhi := newMockHostInterfaces() - _, err := mhi.addMockIface("192.168.99.42", 24, net.IPv4len, "en0", net.FlagUp|net.FlagBroadcast) - assert.NoError(t, err) - - nets, err := listHostOnlyAdapters(vbox) - assert.NoError(t, err) - m, listErr := listHostInterfaces(mhi, nets) - assert.Nil(t, listErr) - assert.NotEmpty(t, m) - - _, network, cidrErr := net.ParseCIDR("192.168.99.1/24") - assert.Nil(t, cidrErr) - err = validateNoIPCollisions(mhi, network, nets) - assert.Equal(t, ErrNetworkAddrCollision, err) -} - -// Tests operation of validateNoIPCollisions when no conflicts exist. -func TestCIDRHostIFaceNoCollision(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "list hostonlyifs", - stdOut: stdOutTwoHostOnlyNetwork, - } - mhi := newMockHostInterfaces() - _, err := mhi.addMockIface("10.10.0.22", 24, net.IPv4len, "en0", net.FlagUp|net.FlagBroadcast) - assert.NoError(t, err) - - nets, err := listHostOnlyAdapters(vbox) - assert.NoError(t, err) - m, listErr := listHostInterfaces(mhi, nets) - assert.Nil(t, listErr) - assert.NotEmpty(t, m) - - _, network, cidrErr := net.ParseCIDR("192.168.99.1/24") - assert.Nil(t, cidrErr) - err = validateNoIPCollisions(mhi, network, nets) - assert.NoError(t, err) -} - -// Tests detection of a conflict between a potential vbox host-only network and a host network interface. -func TestCIDRHostIFaceCollision(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "list hostonlyifs", - stdOut: "", - } - mhi := newMockHostInterfaces() - _, err := mhi.addMockIface("192.168.99.42", 24, net.IPv4len, "en0", net.FlagUp|net.FlagBroadcast) - assert.NoError(t, err) - - nets, err := listHostOnlyAdapters(vbox) - assert.NoError(t, err) - m, listErr := listHostInterfaces(mhi, nets) - assert.Nil(t, listErr) - assert.NotEmpty(t, m) - - _, network, cidrErr := net.ParseCIDR("192.168.99.1/24") - assert.Nil(t, cidrErr) - err = validateNoIPCollisions(mhi, network, nets) - assert.Equal(t, ErrNetworkAddrCollision, err) -} - -// Tests the behavior of getDHCPAddressRange with a variety of subnets. -func TestGetDHCPAddressRange(t *testing.T) { - tests := []struct { - name string - dhcpAddrCIDR string - expectedLowerIP net.IP - expectedUpperIP net.IP - }{ - { - "Test /8 CIDR", - "10.0.0.14/8", - net.ParseIP("10.0.0.100"), - net.ParseIP("10.0.0.254"), - }, - { - "Test /24 CIDR", - "192.168.99.7/24", - net.ParseIP("192.168.99.100"), - net.ParseIP("192.168.99.254"), - }, - { - "Test /25 CIDR", - "100.121.20.19/25", - net.ParseIP("100.121.20.20"), - net.ParseIP("100.121.20.126"), - }, - { - "Test /28 CIDR", - "100.121.10.8/28", - net.ParseIP("100.121.10.9"), - net.ParseIP("100.121.10.14"), - }, - } - - getTestArgsFromCIDR := func(cidr string) (dhcpAddr net.IP, network *net.IPNet) { - var err error - dhcpAddr, network, err = net.ParseCIDR(cidr) - assert.NoError(t, err, "Invalid CIDR %s", cidr) - return - } - - for _, tt := range tests { - dhcpAddr, network := getTestArgsFromCIDR(tt.dhcpAddrCIDR) - t.Run(tt.name, func(t *testing.T) { - lowerIP, upperIP := getDHCPAddressRange(dhcpAddr, network) - if !reflect.DeepEqual(lowerIP, tt.expectedLowerIP) { - t.Errorf("getDHCPAddressRange() lowerIP = %v, want %v", lowerIP, tt.expectedLowerIP) - } - if !reflect.DeepEqual(upperIP, tt.expectedUpperIP) { - t.Errorf("getDHCPAddressRange() upperIP = %v, want %v", upperIP, tt.expectedUpperIP) - } - }) - } -} - -func TestSetConfigFromFlags(t *testing.T) { - driver := newTestDriver("default") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{}, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) -} - -type MockCreateOperations struct { - test *testing.T - expectedCalls []Call - call int -} - -type Call struct { - signature string - output string - err error -} - -func (v *MockCreateOperations) vbm(args ...string) error { - _, _, err := v.vbmOutErr(args...) - return err -} - -func (v *MockCreateOperations) vbmOut(args ...string) (string, error) { - stdout, _, err := v.vbmOutErr(args...) - return stdout, err -} - -func (v *MockCreateOperations) vbmOutErr(args ...string) (string, string, error) { - output, err := v.doCall("vbm " + strings.Join(args, " ")) - return output, "", err -} - -func (v *MockCreateOperations) UpdateISOCache(storePath, isoURL string) error { - _, err := v.doCall("UpdateISOCache " + storePath + " " + isoURL) - return err -} - -func (v *MockCreateOperations) CopyIsoToMachineDir(storePath, machineName, isoURL string) error { - _, err := v.doCall("CopyIsoToMachineDir " + storePath + " " + machineName + " " + isoURL) - return err -} - -func (v *MockCreateOperations) Generate(path string) error { - _, err := v.doCall("Generate " + path) - return err -} - -func (v *MockCreateOperations) Create(size int, publicSSHKeyPath, diskPath string) error { - _, err := v.doCall("Create " + fmt.Sprintf("%d %s %s", size, publicSSHKeyPath, diskPath)) - return err -} - -func (v *MockCreateOperations) Read(path string) ([]string, error) { - _, err := v.doCall("Read " + path) - return []string{}, err -} - -func (v *MockCreateOperations) Wait(d *Driver) error { - _, err := v.doCall("WaitIP") - return err -} - -func (v *MockCreateOperations) RandomInt(n int) int { - return 5 -} - -func (v *MockCreateOperations) Sleep(d time.Duration) { - v.doCall("Sleep " + fmt.Sprintf("%v", d)) -} - -func (v *MockCreateOperations) Interfaces() ([]net.Interface, error) { - _, err := v.doCall("Interfaces") - return []net.Interface{}, err -} - -func (v *MockCreateOperations) Addrs(iface *net.Interface) ([]net.Addr, error) { - _, err := v.doCall("Addrs " + fmt.Sprintf("%v", iface)) - return []net.Addr{}, err -} - -func (v *MockCreateOperations) expectCall(callSignature, output string, err error) { - v.expectedCalls = append(v.expectedCalls, Call{ - signature: callSignature, - output: output, - err: err, - }) -} - -func (v *MockCreateOperations) doCall(callSignature string) (string, error) { - if v.call >= len(v.expectedCalls) { - v.test.Fatal("Unexpected call", callSignature) - - } - - call := v.expectedCalls[v.call] - if call.signature != "IGNORE CALL" && (callSignature != call.signature) { - v.test.Fatal("Unexpected call", callSignature) - } - - v.call++ - - return call.output, call.err -} - -func mockCalls(t *testing.T, driver *Driver, expectedCalls []Call) { - mockOperations := &MockCreateOperations{ - test: t, - expectedCalls: expectedCalls, - } - - driver.Boot2DockerURL = "http://b2d.org" - driver.VBoxManager = mockOperations - driver.b2dUpdater = mockOperations - driver.sshKeyGenerator = mockOperations - driver.diskCreator = mockOperations - driver.logsReader = mockOperations - driver.ipWaiter = mockOperations - driver.randomInter = mockOperations - driver.sleeper = mockOperations - driver.HostInterfaces = mockOperations -} - -func TestCreateVM(t *testing.T) { - shareName, shareDir := getShareDriveAndName() - - modifyVMcommand := "vbm modifyvm default --firmware bios --bioslogofadein off --bioslogofadeout off --bioslogodisplaytime 0 --biosbootmenu disabled --ostype Linux26_64 --cpus 1 --memory 1024 --acpi on --ioapic on --rtcuseutc on --natdnshostresolver1 off --natdnsproxy1 on --cpuhotplug off --pae on --hpet on --hwvirtex on --nestedpaging on --largepages on --vtxvpid on --accelerate3d off --boot1 dvd" - if runtime.GOOS == "windows" && runtime.GOARCH == "386" { - modifyVMcommand += " --longmode on" - } - - driver := NewDriver("default", "path") - mockCalls(t, driver, []Call{ - {"CopyIsoToMachineDir path default http://b2d.org", "", nil}, - {"Generate path/machines/default/id_rsa", "", nil}, - {"Create 20000 path/machines/default/id_rsa.pub path/machines/default/disk.vmdk", "", nil}, - {"vbm createvm --basefolder path/machines/default --name default --register", "", nil}, - {modifyVMcommand, "", nil}, - {"vbm modifyvm default --nic1 nat --nictype1 82540EM --cableconnected1 on", "", nil}, - {"vbm storagectl default --name SATA --add sata --hostiocache on", "", nil}, - {"vbm storageattach default --storagectl SATA --port 0 --device 0 --type dvddrive --medium path/machines/default/boot2docker.iso", "", nil}, - {"vbm storageattach default --storagectl SATA --port 1 --device 0 --type hdd --medium path/machines/default/disk.vmdk", "", nil}, - {"vbm guestproperty set default /VirtualBox/GuestAdd/SharedFolders/MountPrefix /", "", nil}, - {"vbm guestproperty set default /VirtualBox/GuestAdd/SharedFolders/MountDir /", "", nil}, - {"vbm sharedfolder add default --name " + shareName + " --hostpath " + shareDir + " --automount", "", nil}, - {"vbm setextradata default VBoxInternal2/SharedFoldersEnableSymlinksCreate/" + shareName + " 1", "", nil}, - }) - - err := driver.CreateVM() - - assert.NoError(t, err) -} - -func TestCreateVMWithSpecificNatNicType(t *testing.T) { - shareName, shareDir := getShareDriveAndName() - - modifyVMcommand := "vbm modifyvm default --firmware bios --bioslogofadein off --bioslogofadeout off --bioslogodisplaytime 0 --biosbootmenu disabled --ostype Linux26_64 --cpus 1 --memory 1024 --acpi on --ioapic on --rtcuseutc on --natdnshostresolver1 off --natdnsproxy1 on --cpuhotplug off --pae on --hpet on --hwvirtex on --nestedpaging on --largepages on --vtxvpid on --accelerate3d off --boot1 dvd" - if runtime.GOOS == "windows" && runtime.GOARCH == "386" { - modifyVMcommand += " --longmode on" - } - - driver := NewDriver("default", "path") - driver.NatNicType = "Am79C973" - mockCalls(t, driver, []Call{ - {"CopyIsoToMachineDir path default http://b2d.org", "", nil}, - {"Generate path/machines/default/id_rsa", "", nil}, - {"Create 20000 path/machines/default/id_rsa.pub path/machines/default/disk.vmdk", "", nil}, - {"vbm createvm --basefolder path/machines/default --name default --register", "", nil}, - {modifyVMcommand, "", nil}, - {"vbm modifyvm default --nic1 nat --nictype1 Am79C973 --cableconnected1 on", "", nil}, - {"vbm storagectl default --name SATA --add sata --hostiocache on", "", nil}, - {"vbm storageattach default --storagectl SATA --port 0 --device 0 --type dvddrive --medium path/machines/default/boot2docker.iso", "", nil}, - {"vbm storageattach default --storagectl SATA --port 1 --device 0 --type hdd --medium path/machines/default/disk.vmdk", "", nil}, - {"vbm guestproperty set default /VirtualBox/GuestAdd/SharedFolders/MountPrefix /", "", nil}, - {"vbm guestproperty set default /VirtualBox/GuestAdd/SharedFolders/MountDir /", "", nil}, - {"vbm sharedfolder add default --name " + shareName + " --hostpath " + shareDir + " --automount", "", nil}, - {"vbm setextradata default VBoxInternal2/SharedFoldersEnableSymlinksCreate/" + shareName + " 1", "", nil}, - }) - - err := driver.CreateVM() - - assert.NoError(t, err) -} - -func TestStart(t *testing.T) { - driver := NewDriver("default", "path") - mockCalls(t, driver, []Call{ - {"vbm showvminfo default --machinereadable", `VMState="poweroff"`, nil}, - {"vbm list hostonlyifs", "", nil}, - {"Interfaces", "", nil}, - {"vbm hostonlyif create", "Interface 'VirtualBox Host-Only Ethernet Adapter' was successfully created", nil}, - {"vbm list hostonlyifs", ` -Name: VirtualBox Host-Only Ethernet Adapter -GUID: 786f6276-656e-4074-8000-0a0027000000 -DHCP: Disabled -IPAddress: 192.168.99.1 -NetworkMask: 255.255.255.0 -IPV6Address: -IPV6NetworkMaskPrefixLength: 0 -HardwareAddress: 0a:00:27:00:00:00 -MediumType: Ethernet -Status: Up -VBoxNetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter`, nil}, - {"vbm hostonlyif ipconfig VirtualBox Host-Only Ethernet Adapter --ip 192.168.99.1 --netmask 255.255.255.0", "", nil}, - {"vbm list dhcpservers", "", nil}, - {"vbm list dhcpservers", "", nil}, - {"vbm dhcpserver add --netname HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter --ip 192.168.99.6 --netmask 255.255.255.0 --lowerip 192.168.99.100 --upperip 192.168.99.254 --enable", "", nil}, - {"vbm modifyvm default --nic2 hostonly --nictype2 82540EM --nicpromisc2 deny --hostonlyadapter2 VirtualBox Host-Only Ethernet Adapter --cableconnected2 on", "", nil}, - {"IGNORE CALL", "", nil}, - {"IGNORE CALL", "", nil}, - {"vbm startvm default --type headless", "", nil}, - {"Read path/machines/default/default/Logs/VBox.log", "", nil}, - {"WaitIP", "", nil}, - {"vbm list hostonlyifs", ` -Name: VirtualBox Host-Only Ethernet Adapter -GUID: 786f6276-656e-4074-8000-0a0027000000 -DHCP: Disabled -IPAddress: 192.168.99.1 -NetworkMask: 255.255.255.0 -IPV6Address: -IPV6NetworkMaskPrefixLength: 0 -HardwareAddress: 0a:00:27:00:00:00 -MediumType: Ethernet -Status: Up -VBoxNetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter`, nil}, - {"Interfaces", "", nil}, - }) - - err := driver.Start() - - assert.NoError(t, err) -} - -func TestStartWithHostOnlyAdapterCreationBug(t *testing.T) { - driver := NewDriver("default", "path") - mockCalls(t, driver, []Call{ - {"vbm showvminfo default --machinereadable", `VMState="poweroff"`, nil}, - {"vbm list hostonlyifs", "", nil}, - {"Interfaces", "", nil}, - {"vbm hostonlyif create", "", errors.New("error: Failed to create the host-only adapter")}, - {"vbm list hostonlyifs", "", nil}, - {"vbm list hostonlyifs", ` -Name: VirtualBox Host-Only Ethernet Adapter -GUID: 786f6276-656e-4074-8000-0a0027000000 -DHCP: Disabled -IPAddress: 192.168.99.1 -NetworkMask: 255.255.255.0 -IPV6Address: -IPV6NetworkMaskPrefixLength: 0 -HardwareAddress: 0a:00:27:00:00:00 -MediumType: Ethernet -Status: Up -VBoxNetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter`, nil}, - {"vbm hostonlyif ipconfig VirtualBox Host-Only Ethernet Adapter --ip 192.168.99.1 --netmask 255.255.255.0", "", nil}, - {"vbm list dhcpservers", "", nil}, - {"vbm list dhcpservers", "", nil}, - {"vbm dhcpserver add --netname HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter --ip 192.168.99.6 --netmask 255.255.255.0 --lowerip 192.168.99.100 --upperip 192.168.99.254 --enable", "", nil}, - {"vbm modifyvm default --nic2 hostonly --nictype2 82540EM --nicpromisc2 deny --hostonlyadapter2 VirtualBox Host-Only Ethernet Adapter --cableconnected2 on", "", nil}, - {"IGNORE CALL", "", nil}, - {"IGNORE CALL", "", nil}, - {"vbm startvm default --type headless", "", nil}, - {"Read path/machines/default/default/Logs/VBox.log", "", nil}, - {"WaitIP", "", nil}, - {"vbm list hostonlyifs", ` -Name: VirtualBox Host-Only Ethernet Adapter -GUID: 786f6276-656e-4074-8000-0a0027000000 -DHCP: Disabled -IPAddress: 192.168.99.100 -NetworkMask: 255.255.255.0 -IPV6Address: -IPV6NetworkMaskPrefixLength: 0 -HardwareAddress: 0a:00:27:00:00:00 -MediumType: Ethernet -Status: Up -VBoxNetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter`, nil}, - {"Interfaces", "", nil}, - {"vbm showvminfo default --machinereadable", `VMState="running"`, nil}, - {"vbm controlvm default acpipowerbutton", "", nil}, - {"vbm showvminfo default --machinereadable", `VMState="stopped"`, nil}, - {"Sleep 5s", "", nil}, - {"vbm hostonlyif ipconfig VirtualBox Host-Only Ethernet Adapter --ip 192.168.99.1 --netmask 255.255.255.0", "", nil}, - {"Sleep 5s", "", nil}, - {"vbm startvm default --type headless", "", nil}, - {"WaitIP", "", nil}, - }) - - err := driver.Start() - - assert.NoError(t, err) -} - -func TestRemoveStopped(t *testing.T) { - driver := NewDriver("default", "path") - mockCalls(t, driver, []Call{ - {"vbm showvminfo default --machinereadable", `VMState="poweroff"`, nil}, - {"vbm unregistervm --delete default", "", nil}, - }) - - err := driver.Remove() - - assert.NoError(t, err) -} - -func TestRemoveStarted(t *testing.T) { - driver := NewDriver("default", "path") - mockCalls(t, driver, []Call{ - {"vbm showvminfo default --machinereadable", `VMState="running"`, nil}, - {"vbm controlvm default poweroff", "", nil}, - {"vbm unregistervm --delete default", "", nil}, - }) - - err := driver.Remove() - - assert.NoError(t, err) -} - -func TestRemoveSaved(t *testing.T) { - driver := NewDriver("default", "path") - mockCalls(t, driver, []Call{ - {"vbm showvminfo default --machinereadable", `VMState="saved"`, nil}, - {"vbm unregistervm --delete default", "", nil}, - }) - - err := driver.Remove() - - assert.NoError(t, err) -} - -func TestRemovePaused(t *testing.T) { - driver := NewDriver("default", "path") - mockCalls(t, driver, []Call{ - {"vbm showvminfo default --machinereadable", `VMState="running"`, nil}, - {"vbm controlvm default poweroff", "", nil}, - {"vbm unregistervm --delete default", "", nil}, - }) - - err := driver.Remove() - - assert.NoError(t, err) -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_windows.go b/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_windows.go deleted file mode 100644 index 4f025e8..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/virtualbox_windows.go +++ /dev/null @@ -1,119 +0,0 @@ -package virtualbox - -import ( - "strings" - - "fmt" - "os" - "os/exec" - "path/filepath" - - "github.com/docker/machine/libmachine/log" - "golang.org/x/sys/windows/registry" -) - -// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start. -// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started. -func (d *Driver) IsVTXDisabled() bool { - errmsg := "Couldn't check that VT-X/AMD-v is enabled. Will check that the vm is properly created: %v" - output, err := cmdOutput("wmic", "cpu", "get", "VirtualizationFirmwareEnabled") - if err != nil { - log.Debugf(errmsg, err) - return false - } - - disabled := strings.Contains(output, "FALSE") - return disabled -} - -// cmdOutput runs a shell command and returns its output. -func cmdOutput(name string, args ...string) (string, error) { - cmd := exec.Command(name, args...) - log.Debugf("COMMAND: %v %v", name, strings.Join(args, " ")) - - stdout, err := cmd.Output() - if err != nil { - return "", err - } - - log.Debugf("STDOUT:\n{\n%v}", string(stdout)) - - return string(stdout), nil -} - -func detectVBoxManageCmd() string { - cmd := "VBoxManage" - if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" { - if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil { - return path - } - } - - if p := os.Getenv("VBOX_MSI_INSTALL_PATH"); p != "" { - if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil { - return path - } - } - - // Look in default installation path for VirtualBox version > 5 - if path, err := exec.LookPath(filepath.Join("C:\\Program Files\\Oracle\\VirtualBox", cmd)); err == nil { - return path - } - - // Look in windows registry - if p, err := findVBoxInstallDirInRegistry(); err == nil { - if path, err := exec.LookPath(filepath.Join(p, cmd)); err == nil { - return path - } - } - - return detectVBoxManageCmdInPath() //fallback to path -} - -func findVBoxInstallDirInRegistry() (string, error) { - registryKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Oracle\VirtualBox`, registry.QUERY_VALUE) - if err != nil { - errorMessage := fmt.Sprintf("Can't find VirtualBox registry entries, is VirtualBox really installed properly? %s", err) - log.Debugf(errorMessage) - return "", fmt.Errorf(errorMessage) - } - - defer registryKey.Close() - - installDir, _, err := registryKey.GetStringValue("InstallDir") - if err != nil { - errorMessage := fmt.Sprintf("Can't find InstallDir registry key within VirtualBox registries entries, is VirtualBox really installed properly? %s", err) - log.Debugf(errorMessage) - return "", fmt.Errorf(errorMessage) - } - - return installDir, nil -} - -func getShareDriveAndName() (string, string) { - return "c/Users", "\\\\?\\c:\\Users" -} - -func isHyperVInstalled() bool { - // check if hyper-v is installed - _, err := exec.LookPath("vmms.exe") - if err != nil { - errmsg := "Hyper-V is not installed." - log.Debugf(errmsg, err) - return false - } - - // check to see if a hypervisor is present. if hyper-v is installed and enabled, - // display an error explaining the incompatibility between virtualbox and hyper-v. - output, err := cmdOutput("wmic", "computersystem", "get", "hypervisorpresent") - - if err != nil { - errmsg := "Could not check to see if Hyper-V is running." - log.Debugf(errmsg, err) - return false - } - - enabled := strings.Contains(output, "TRUE") - return enabled - -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/vm.go b/vendor/github.com/docker/machine/drivers/virtualbox/vm.go deleted file mode 100644 index cd95ada..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/vm.go +++ /dev/null @@ -1,41 +0,0 @@ -package virtualbox - -import "strconv" - -type VM struct { - CPUs int - Memory int -} - -func getVMInfo(name string, vbox VBoxManager) (*VM, error) { - out, err := vbox.vbmOut("showvminfo", name, "--machinereadable") - if err != nil { - return nil, err - } - - vm := &VM{} - - err = parseKeyValues(out, reEqualLine, func(key, val string) error { - switch key { - case "cpus": - v, err := strconv.Atoi(val) - if err != nil { - return err - } - vm.CPUs = v - case "memory": - v, err := strconv.Atoi(val) - if err != nil { - return err - } - vm.Memory = v - } - - return nil - }) - if err != nil { - return nil, err - } - - return vm, nil -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/vm_test.go b/vendor/github.com/docker/machine/drivers/virtualbox/vm_test.go deleted file mode 100644 index a90ffbf..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/vm_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package virtualbox - -import ( - "errors" - "testing" - - "github.com/stretchr/testify/assert" -) - -var stdOutVMInfo = ` -storagecontrollerbootable0="on" -memory=1024 -cpus=2 -"SATA-0-0"="/home/ehazlett/.boot2docker/boot2docker.iso" -"SATA-IsEjected"="off" -"SATA-1-0"="/home/ehazlett/vm/test/disk.vmdk" -"SATA-ImageUUID-1-0"="12345-abcdefg" -"SATA-2-0"="none" -nic1="nat"` - -func TestVMInfo(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "showvminfo host --machinereadable", - stdOut: stdOutVMInfo, - } - - vm, err := getVMInfo("host", vbox) - - assert.Equal(t, 2, vm.CPUs) - assert.Equal(t, 1024, vm.Memory) - assert.NoError(t, err) -} - -func TestVMInfoError(t *testing.T) { - vbox := &VBoxManagerMock{ - args: "showvminfo host --machinereadable", - err: errors.New("BUG"), - } - - vm, err := getVMInfo("host", vbox) - - assert.Nil(t, vm) - assert.EqualError(t, err, "BUG") -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/vtx.go b/vendor/github.com/docker/machine/drivers/virtualbox/vtx.go deleted file mode 100644 index 7adb631..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/vtx.go +++ /dev/null @@ -1,28 +0,0 @@ -package virtualbox - -import "strings" - -// IsVTXDisabledInTheVM checks if VT-X is disabled in the started vm. -func (d *Driver) IsVTXDisabledInTheVM() (bool, error) { - lines, err := d.readVBoxLog() - if err != nil { - return true, err - } - - for _, line := range lines { - if strings.Contains(line, "VT-x is disabled") && !strings.Contains(line, "Falling back to raw-mode: VT-x is disabled in the BIOS for all CPU modes") { - return true, nil - } - if strings.Contains(line, "the host CPU does NOT support HW virtualization") { - return true, nil - } - if strings.Contains(line, "VERR_VMX_UNABLE_TO_START_VM") { - return true, nil - } - if strings.Contains(line, "Power up failed") && strings.Contains(line, "VERR_VMX_NO_VMX") { - return true, nil - } - } - - return false, nil -} diff --git a/vendor/github.com/docker/machine/drivers/virtualbox/vtx_test.go b/vendor/github.com/docker/machine/drivers/virtualbox/vtx_test.go deleted file mode 100644 index da90b15..0000000 --- a/vendor/github.com/docker/machine/drivers/virtualbox/vtx_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package virtualbox - -import ( - "testing" - - "errors" - - "github.com/stretchr/testify/assert" -) - -type MockLogsReader struct { - content []string - err error -} - -func (r *MockLogsReader) Read(path string) ([]string, error) { - return r.content, r.err -} - -func TestIsVTXEnabledInTheVM(t *testing.T) { - driver := NewDriver("default", "path") - - var tests = []struct { - description string - content []string - err error - }{ - {"Empty log", []string{}, nil}, - {"Raw mode", []string{"Falling back to raw-mode: VT-x is disabled in the BIOS for all CPU modes"}, nil}, - {"Raw mode", []string{"HM: HMR3Init: Falling back to raw-mode: VT-x is not available"}, nil}, - } - - for _, test := range tests { - driver.logsReader = &MockLogsReader{ - content: test.content, - err: test.err, - } - - disabled, err := driver.IsVTXDisabledInTheVM() - - assert.False(t, disabled, test.description) - assert.Equal(t, test.err, err) - } -} - -func TestIsVTXDisabledInTheVM(t *testing.T) { - driver := NewDriver("default", "path") - - var tests = []struct { - description string - content []string - err error - }{ - {"VT-x Disabled", []string{"VT-x is disabled"}, nil}, - {"No HW virtualization", []string{"the host CPU does NOT support HW virtualization"}, nil}, - {"Unable to start VM", []string{"VERR_VMX_UNABLE_TO_START_VM"}, nil}, - {"Power up failed", []string{"00:00:00.318604 Power up failed (vrc=VERR_VMX_NO_VMX, rc=NS_ERROR_FAILURE (0X80004005))"}, nil}, - {"Unable to read log", nil, errors.New("Unable to read log")}, - } - - for _, test := range tests { - driver.logsReader = &MockLogsReader{ - content: test.content, - err: test.err, - } - - disabled, err := driver.IsVTXDisabledInTheVM() - - assert.True(t, disabled, test.description) - assert.Equal(t, test.err, err) - } -} diff --git a/vendor/github.com/docker/machine/drivers/vmwarefusion/fusion.go b/vendor/github.com/docker/machine/drivers/vmwarefusion/fusion.go deleted file mode 100644 index be433e5..0000000 --- a/vendor/github.com/docker/machine/drivers/vmwarefusion/fusion.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build !darwin - -package vmwarefusion - -import "github.com/docker/machine/libmachine/drivers" - -func NewDriver(hostName, storePath string) drivers.Driver { - return drivers.NewDriverNotSupported("vmwarefusion", hostName, storePath) -} diff --git a/vendor/github.com/docker/machine/drivers/vmwarefusion/fusion_darwin.go b/vendor/github.com/docker/machine/drivers/vmwarefusion/fusion_darwin.go deleted file mode 100644 index d83ecf9..0000000 --- a/vendor/github.com/docker/machine/drivers/vmwarefusion/fusion_darwin.go +++ /dev/null @@ -1,772 +0,0 @@ -/* - * Copyright 2014 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. - */ - -package vmwarefusion - -import ( - "archive/tar" - "bytes" - "fmt" - "io/ioutil" - "net" - "os" - "path/filepath" - "regexp" - "runtime" - "strings" - "text/template" - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" - cryptossh "golang.org/x/crypto/ssh" -) - -const ( - B2DUser = "docker" - B2DPass = "tcuser" - isoFilename = "boot2docker.iso" - isoConfigDrive = "configdrive.iso" -) - -// Driver for VMware Fusion -type Driver struct { - *drivers.BaseDriver - Memory int - DiskSize int - CPU int - ISO string - Boot2DockerURL string - - SSHPassword string - ConfigDriveISO string - ConfigDriveURL string - NoShare bool -} - -const ( - defaultSSHUser = B2DUser - defaultSSHPass = B2DPass - defaultDiskSize = 20000 - defaultCPU = 1 - defaultMemory = 1024 -) - -// GetCreateFlags registers the flags this driver adds to -// "docker hosts create" -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - EnvVar: "FUSION_BOOT2DOCKER_URL", - Name: "vmwarefusion-boot2docker-url", - Usage: "Fusion URL for boot2docker image", - Value: "", - }, - mcnflag.StringFlag{ - EnvVar: "FUSION_CONFIGDRIVE_URL", - Name: "vmwarefusion-configdrive-url", - Usage: "Fusion URL for cloud-init configdrive", - Value: "", - }, - mcnflag.IntFlag{ - EnvVar: "FUSION_CPU_COUNT", - Name: "vmwarefusion-cpu-count", - Usage: "number of CPUs for the machine (-1 to use the number of CPUs available)", - Value: defaultCPU, - }, - mcnflag.IntFlag{ - EnvVar: "FUSION_MEMORY_SIZE", - Name: "vmwarefusion-memory-size", - Usage: "Fusion size of memory for host VM (in MB)", - Value: defaultMemory, - }, - mcnflag.IntFlag{ - EnvVar: "FUSION_DISK_SIZE", - Name: "vmwarefusion-disk-size", - Usage: "Fusion size of disk for host VM (in MB)", - Value: defaultDiskSize, - }, - mcnflag.StringFlag{ - EnvVar: "FUSION_SSH_USER", - Name: "vmwarefusion-ssh-user", - Usage: "SSH user", - Value: defaultSSHUser, - }, - mcnflag.StringFlag{ - EnvVar: "FUSION_SSH_PASSWORD", - Name: "vmwarefusion-ssh-password", - Usage: "SSH password", - Value: defaultSSHPass, - }, - mcnflag.BoolFlag{ - EnvVar: "FUSION_NO_SHARE", - Name: "vmwarefusion-no-share", - Usage: "Disable the mount of your home directory", - }, - } -} - -func NewDriver(hostName, storePath string) drivers.Driver { - return &Driver{ - CPU: defaultCPU, - Memory: defaultMemory, - DiskSize: defaultDiskSize, - SSHPassword: defaultSSHPass, - BaseDriver: &drivers.BaseDriver{ - SSHUser: defaultSSHUser, - MachineName: hostName, - StorePath: storePath, - }, - } -} - -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -func (d *Driver) GetSSHUsername() string { - if d.SSHUser == "" { - d.SSHUser = "docker" - } - - return d.SSHUser -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "vmwarefusion" -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.Memory = flags.Int("vmwarefusion-memory-size") - d.CPU = flags.Int("vmwarefusion-cpu-count") - d.DiskSize = flags.Int("vmwarefusion-disk-size") - d.Boot2DockerURL = flags.String("vmwarefusion-boot2docker-url") - d.ConfigDriveURL = flags.String("vmwarefusion-configdrive-url") - d.ISO = d.ResolveStorePath(isoFilename) - d.ConfigDriveISO = d.ResolveStorePath(isoConfigDrive) - d.SetSwarmConfigFromFlags(flags) - d.SSHUser = flags.String("vmwarefusion-ssh-user") - d.SSHPassword = flags.String("vmwarefusion-ssh-password") - d.SSHPort = 22 - d.NoShare = flags.Bool("vmwarefusion-no-share") - - // We support a maximum of 16 cpu to be consistent with Virtual Hardware 10 - // specs. - if d.CPU < 1 { - d.CPU = int(runtime.NumCPU()) - } - if d.CPU > 16 { - d.CPU = 16 - } - - return nil -} - -func (d *Driver) GetURL() (string, error) { - ip, err := d.GetIP() - if err != nil { - return "", err - } - if ip == "" { - return "", nil - } - return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, "2376")), nil -} - -func (d *Driver) GetIP() (string, error) { - s, err := d.GetState() - if err != nil { - return "", err - } - if s != state.Running { - return "", drivers.ErrHostIsNotRunning - } - - // determine MAC address for VM - macaddr, err := d.getMacAddressFromVmx() - if err != nil { - return "", err - } - - // attempt to find the address in the vmnet configuration - if ip, err := d.getIPfromVmnetConfiguration(macaddr); err == nil { - return ip, err - } - - // address not found in vmnet so look for a DHCP lease - ip, err := d.getIPfromDHCPLease(macaddr) - if err != nil { - return "", err - } - - return ip, nil -} - -func (d *Driver) GetState() (state.State, error) { - // VMRUN only tells use if the vm is running or not - vmxp, err := filepath.EvalSymlinks(d.vmxPath()) - if err != nil { - return state.Error, err - } - if stdout, _, _ := vmrun("list"); strings.Contains(stdout, vmxp) { - return state.Running, nil - } - return state.Stopped, nil -} - -// PreCreateCheck checks that the machine creation process can be started safely. -func (d *Driver) PreCreateCheck() error { - // Downloading boot2docker to cache should be done here to make sure - // that a download failure will not leave a machine half created. - b2dutils := mcnutils.NewB2dUtils(d.StorePath) - if err := b2dutils.UpdateISOCache(d.Boot2DockerURL); err != nil { - return err - } - - return nil -} - -func (d *Driver) Create() error { - b2dutils := mcnutils.NewB2dUtils(d.StorePath) - if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil { - return err - } - - // download cloud-init config drive - if d.ConfigDriveURL != "" { - if err := b2dutils.DownloadISO(d.ResolveStorePath("."), isoConfigDrive, d.ConfigDriveURL); err != nil { - return err - } - } - - log.Infof("Creating SSH key...") - if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { - return err - } - - log.Infof("Creating VM...") - if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil { - return err - } - - if _, err := os.Stat(d.vmxPath()); err == nil { - return ErrMachineExist - } - - // Generate vmx config file from template - vmxt := template.Must(template.New("vmx").Parse(vmx)) - vmxfile, err := os.Create(d.vmxPath()) - if err != nil { - return err - } - vmxt.Execute(vmxfile, d) - - // Generate vmdk file - diskImg := d.ResolveStorePath(fmt.Sprintf("%s.vmdk", d.MachineName)) - if _, err := os.Stat(diskImg); err != nil { - if !os.IsNotExist(err) { - return err - } - - if err := vdiskmanager(diskImg, d.DiskSize); err != nil { - return err - } - } - - log.Infof("Starting %s...", d.MachineName) - vmrun("start", d.vmxPath(), "nogui") - - var ip string - - log.Infof("Waiting for VM to come online...") - for i := 1; i <= 60; i++ { - ip, err = d.GetIP() - if err != nil { - log.Debugf("Not there yet %d/%d, error: %s", i, 60, err) - time.Sleep(2 * time.Second) - continue - } - - if ip != "" { - log.Debugf("Got an ip: %s", ip) - conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, 22), time.Duration(2*time.Second)) - if err != nil { - log.Debugf("SSH Daemon not responding yet: %s", err) - time.Sleep(2 * time.Second) - continue - } - conn.Close() - break - } - } - - if ip == "" { - return fmt.Errorf("Machine didn't return an IP after 120 seconds, aborting") - } - - // we got an IP, let's copy ssh keys over - d.IPAddress = ip - - // Do not execute the rest of boot2docker specific configuration - // The upload of the public ssh key uses a ssh connection, - // this works without installed vmware client tools - if d.ConfigDriveURL != "" { - var keyfh *os.File - var keycontent []byte - - log.Infof("Copy public SSH key to %s [%s]", d.MachineName, d.IPAddress) - - // create .ssh folder in users home - if err := executeSSHCommand(fmt.Sprintf("mkdir -p /home/%s/.ssh", d.SSHUser), d); err != nil { - return err - } - - // read generated public ssh key - if keyfh, err = os.Open(d.publicSSHKeyPath()); err != nil { - return err - } - defer keyfh.Close() - - if keycontent, err = ioutil.ReadAll(keyfh); err != nil { - return err - } - - // add public ssh key to authorized_keys - if err := executeSSHCommand(fmt.Sprintf("echo '%s' > /home/%s/.ssh/authorized_keys", string(keycontent), d.SSHUser), d); err != nil { - return err - } - - // make it secure - if err := executeSSHCommand(fmt.Sprintf("chmod 600 /home/%s/.ssh/authorized_keys", d.SSHUser), d); err != nil { - return err - } - - log.Debugf("Leaving create sequence early, configdrive found") - return nil - } - - // Generate a tar keys bundle - if err := d.generateKeyBundle(); err != nil { - return err - } - - // Test if /var/lib/boot2docker exists - vmrun("-gu", B2DUser, "-gp", B2DPass, "directoryExistsInGuest", d.vmxPath(), "/var/lib/boot2docker") - - // Copy SSH keys bundle - vmrun("-gu", B2DUser, "-gp", B2DPass, "CopyFileFromHostToGuest", d.vmxPath(), d.ResolveStorePath("userdata.tar"), "/home/docker/userdata.tar") - - // Expand tar file. - vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", "sudo sh -c \"tar xvf /home/docker/userdata.tar -C /home/docker > /var/log/userdata.log 2>&1 && chown -R docker:staff /home/docker\"") - - // copy to /var/lib/boot2docker - vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", "sudo /bin/mv /home/docker/userdata.tar /var/lib/boot2docker/userdata.tar") - - // Enable Shared Folders - vmrun("-gu", B2DUser, "-gp", B2DPass, "enableSharedFolders", d.vmxPath()) - - var shareName, shareDir string // TODO configurable at some point - switch runtime.GOOS { - case "darwin": - shareName = "Users" - shareDir = "/Users" - // TODO "linux" and "windows" - } - - if shareDir != "" && !d.NoShare { - if _, err := os.Stat(shareDir); err != nil && !os.IsNotExist(err) { - return err - } else if !os.IsNotExist(err) { - // add shared folder, create mountpoint and mount it. - vmrun("-gu", B2DUser, "-gp", B2DPass, "addSharedFolder", d.vmxPath(), shareName, shareDir) - command := "[ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; sudo mount --bind /mnt/hgfs/" + shareDir + " " + shareDir + " || [ -f /usr/local/bin/vmhgfs-fuse ]&& sudo /usr/local/bin/vmhgfs-fuse -o allow_other .host:/" + shareName + " " + shareDir + " || sudo mount -t vmhgfs -o uid=$(id -u),gid=$(id -g) .host:/" + shareName + " " + shareDir - vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", command) - } - } - return nil -} - -func (d *Driver) Start() error { - vmrun("start", d.vmxPath(), "nogui") - - // Do not execute the rest of boot2docker specific configuration, exit here - if d.ConfigDriveURL != "" { - log.Debugf("Leaving start sequence early, configdrive found") - return nil - } - - log.Debugf("Mounting Shared Folders...") - var shareName, shareDir string // TODO configurable at some point - switch runtime.GOOS { - case "darwin": - shareName = "Users" - shareDir = "/Users" - // TODO "linux" and "windows" - } - - if shareDir != "" { - if _, err := os.Stat(shareDir); err != nil && !os.IsNotExist(err) { - return err - } else if !os.IsNotExist(err) { - // create mountpoint and mount shared folder - command := "[ ! -d " + shareDir + " ]&& sudo mkdir " + shareDir + "; sudo mount --bind /mnt/hgfs/" + shareDir + " " + shareDir + " || [ -f /usr/local/bin/vmhgfs-fuse ]&& sudo /usr/local/bin/vmhgfs-fuse -o allow_other .host:/" + shareName + " " + shareDir + " || sudo mount -t vmhgfs -o uid=$(id -u),gid=$(id -g) .host:/" + shareName + " " + shareDir - vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", command) - } - } - - return nil -} - -func (d *Driver) Stop() error { - _, _, err := vmrun("stop", d.vmxPath(), "nogui") - return err -} - -func (d *Driver) Restart() error { - // Stop VM gracefully - if err := d.Stop(); err != nil { - return err - } - // Start it again and mount shared folder - if err := d.Start(); err != nil { - return err - } - return nil -} - -func (d *Driver) Kill() error { - _, _, err := vmrun("stop", d.vmxPath(), "hard nogui") - return err -} - -func (d *Driver) Remove() error { - s, _ := d.GetState() - if s == state.Running { - if err := d.Kill(); err != nil { - return fmt.Errorf("Error stopping VM before deletion") - } - } - log.Infof("Deleting %s...", d.MachineName) - vmrun("deleteVM", d.vmxPath(), "nogui") - return nil -} - -func (d *Driver) Upgrade() error { - return fmt.Errorf("VMware Fusion does not currently support the upgrade operation") -} - -func (d *Driver) vmxPath() string { - return d.ResolveStorePath(fmt.Sprintf("%s.vmx", d.MachineName)) -} - -func (d *Driver) vmdkPath() string { - return d.ResolveStorePath(fmt.Sprintf("%s.vmdk", d.MachineName)) -} - -func (d *Driver) getMacAddressFromVmx() (string, error) { - var vmxfh *os.File - var vmxcontent []byte - var err error - - if vmxfh, err = os.Open(d.vmxPath()); err != nil { - return "", err - } - defer vmxfh.Close() - - if vmxcontent, err = ioutil.ReadAll(vmxfh); err != nil { - return "", err - } - - // Look for generatedAddress as we're passing a VMX with addressType = "generated". - var macaddr string - vmxparse := regexp.MustCompile(`^ethernet0.generatedAddress\s*=\s*"(.*?)"\s*$`) - for _, line := range strings.Split(string(vmxcontent), "\n") { - if matches := vmxparse.FindStringSubmatch(line); matches == nil { - continue - } else { - macaddr = strings.ToLower(matches[1]) - } - } - - if macaddr == "" { - return "", fmt.Errorf("couldn't find MAC address in VMX file %s", d.vmxPath()) - } - - log.Debugf("MAC address in VMX: %s", macaddr) - - return macaddr, nil -} - -func (d *Driver) getIPfromVmnetConfiguration(macaddr string) (string, error) { - - // DHCP lease table for NAT vmnet interface - confFiles, _ := filepath.Glob("/Library/Preferences/VMware Fusion/vmnet*/dhcpd.conf") - for _, conffile := range confFiles { - log.Debugf("Trying to find IP address in configuration file: %s", conffile) - if ipaddr, err := d.getIPfromVmnetConfigurationFile(conffile, macaddr); err == nil { - return ipaddr, err - } - } - - return "", fmt.Errorf("IP not found for MAC %s in vmnet configuration files", macaddr) -} - -func (d *Driver) getIPfromVmnetConfigurationFile(conffile, macaddr string) (string, error) { - var conffh *os.File - var confcontent []byte - - var currentip string - var lastipmatch string - var lastmacmatch string - - var err error - - if conffh, err = os.Open(conffile); err != nil { - return "", err - } - defer conffh.Close() - - if confcontent, err = ioutil.ReadAll(conffh); err != nil { - return "", err - } - - // find all occurrences of 'host .* { .. }' and extract - // out of the inner block the MAC and IP addresses - - // key = MAC, value = IP - m := make(map[string]string) - - // Begin of a host block, that contains the IP, MAC - hostbegin := regexp.MustCompile(`^host (.+?) {`) - // End of a host block - hostend := regexp.MustCompile(`^}`) - - // Get the IP address. - ip := regexp.MustCompile(`^\s*fixed-address (.+?);$`) - // Get the MAC address associated. - mac := regexp.MustCompile(`^\s*hardware ethernet (.+?);$`) - - // we use a block depth so that just in case inner blocks exists - // we are not being fooled by them - blockdepth := 0 - for _, line := range strings.Split(string(confcontent), "\n") { - - if matches := hostbegin.FindStringSubmatch(line); matches != nil { - blockdepth = blockdepth + 1 - continue - } - - // we are only in interested in endings if we in a block. Otherwise we will count - // ending of non host blocks as well - if matches := hostend.FindStringSubmatch(line); blockdepth > 0 && matches != nil { - blockdepth = blockdepth - 1 - - if blockdepth == 0 { - // add data - m[lastmacmatch] = lastipmatch - - // reset all temp var holders - lastipmatch = "" - lastmacmatch = "" - } - - continue - } - - // only if we are within the first level of a block - // we are looking for addresses to extract - if blockdepth == 1 { - if matches := ip.FindStringSubmatch(line); matches != nil { - lastipmatch = matches[1] - continue - } - - if matches := mac.FindStringSubmatch(line); matches != nil { - lastmacmatch = strings.ToLower(matches[1]) - continue - } - } - } - - log.Debugf("Following IPs found %s", m) - - // map is filled to now lets check if we have a MAC associated to an IP - currentip, ok := m[strings.ToLower(macaddr)] - - if !ok { - return "", fmt.Errorf("IP not found for MAC %s in vmnet configuration", macaddr) - } - - log.Debugf("IP found in vmnet configuration file: %s", currentip) - - return currentip, nil - -} - -func (d *Driver) getIPfromDHCPLease(macaddr string) (string, error) { - - // DHCP lease table for NAT vmnet interface - leasesFiles, _ := filepath.Glob("/var/db/vmware/*.leases") - for _, dhcpfile := range leasesFiles { - log.Debugf("Trying to find IP address in leases file: %s", dhcpfile) - if ipaddr, err := d.getIPfromDHCPLeaseFile(dhcpfile, macaddr); err == nil { - return ipaddr, err - } - } - - return "", fmt.Errorf("IP not found for MAC %s in DHCP leases", macaddr) -} - -func (d *Driver) getIPfromDHCPLeaseFile(dhcpfile, macaddr string) (string, error) { - - var dhcpfh *os.File - var dhcpcontent []byte - var lastipmatch string - var currentip string - var lastleaseendtime time.Time - var currentleadeendtime time.Time - var err error - - if dhcpfh, err = os.Open(dhcpfile); err != nil { - return "", err - } - defer dhcpfh.Close() - - if dhcpcontent, err = ioutil.ReadAll(dhcpfh); err != nil { - return "", err - } - - // Get the IP from the lease table. - leaseip := regexp.MustCompile(`^lease (.+?) {$`) - // Get the lease end date time. - leaseend := regexp.MustCompile(`^\s*ends \d (.+?);$`) - // Get the MAC address associated. - leasemac := regexp.MustCompile(`^\s*hardware ethernet (.+?);$`) - - for _, line := range strings.Split(string(dhcpcontent), "\n") { - - if matches := leaseip.FindStringSubmatch(line); matches != nil { - lastipmatch = matches[1] - continue - } - - if matches := leaseend.FindStringSubmatch(line); matches != nil { - lastleaseendtime, _ = time.Parse("2006/01/02 15:04:05", matches[1]) - continue - } - - if matches := leasemac.FindStringSubmatch(line); matches != nil && matches[1] == macaddr && currentleadeendtime.Before(lastleaseendtime) { - currentip = lastipmatch - currentleadeendtime = lastleaseendtime - } - } - - if currentip == "" { - return "", fmt.Errorf("IP not found for MAC %s in DHCP leases", macaddr) - } - - log.Debugf("IP found in DHCP lease table: %s", currentip) - - return currentip, nil -} - -func (d *Driver) publicSSHKeyPath() string { - return d.GetSSHKeyPath() + ".pub" -} - -// Make a boot2docker userdata.tar key bundle -func (d *Driver) generateKeyBundle() error { - log.Debugf("Creating Tar key bundle...") - - magicString := "boot2docker, this is vmware speaking" - - tf, err := os.Create(d.ResolveStorePath("userdata.tar")) - if err != nil { - return err - } - defer tf.Close() - var fileWriter = tf - - tw := tar.NewWriter(fileWriter) - defer tw.Close() - - // magicString first so we can figure out who originally wrote the tar. - file := &tar.Header{Name: magicString, Size: int64(len(magicString))} - if err := tw.WriteHeader(file); err != nil { - return err - } - if _, err := tw.Write([]byte(magicString)); err != nil { - return err - } - // .ssh/key.pub => authorized_keys - file = &tar.Header{Name: ".ssh", Typeflag: tar.TypeDir, Mode: 0700} - if err := tw.WriteHeader(file); err != nil { - return err - } - pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath()) - if err != nil { - return err - } - file = &tar.Header{Name: ".ssh/authorized_keys", Size: int64(len(pubKey)), Mode: 0644} - if err := tw.WriteHeader(file); err != nil { - return err - } - if _, err := tw.Write([]byte(pubKey)); err != nil { - return err - } - file = &tar.Header{Name: ".ssh/authorized_keys2", Size: int64(len(pubKey)), Mode: 0644} - if err := tw.WriteHeader(file); err != nil { - return err - } - if _, err := tw.Write([]byte(pubKey)); err != nil { - return err - } - if err := tw.Close(); err != nil { - return err - } - - return nil - -} - -// execute command over SSH with user / password authentication -func executeSSHCommand(command string, d *Driver) error { - log.Debugf("Execute executeSSHCommand: %s", command) - - config := &cryptossh.ClientConfig{ - User: d.SSHUser, - Auth: []cryptossh.AuthMethod{ - cryptossh.Password(d.SSHPassword), - }, - } - - client, err := cryptossh.Dial("tcp", fmt.Sprintf("%s:%d", d.IPAddress, d.SSHPort), config) - if err != nil { - log.Debugf("Failed to dial:", err) - return err - } - - session, err := client.NewSession() - if err != nil { - log.Debugf("Failed to create session: " + err.Error()) - return err - } - defer session.Close() - - var b bytes.Buffer - session.Stdout = &b - - if err := session.Run(command); err != nil { - log.Debugf("Failed to run: " + err.Error()) - return err - } - log.Debugf("Stdout from executeSSHCommand: %s", b.String()) - - return nil -} diff --git a/vendor/github.com/docker/machine/drivers/vmwarefusion/fusion_darwin_test.go b/vendor/github.com/docker/machine/drivers/vmwarefusion/fusion_darwin_test.go deleted file mode 100644 index da58950..0000000 --- a/vendor/github.com/docker/machine/drivers/vmwarefusion/fusion_darwin_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package vmwarefusion - -import ( - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -func TestSetConfigFromFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{}, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) -} diff --git a/vendor/github.com/docker/machine/drivers/vmwarefusion/vmrun_darwin.go b/vendor/github.com/docker/machine/drivers/vmwarefusion/vmrun_darwin.go deleted file mode 100644 index 3039ea1..0000000 --- a/vendor/github.com/docker/machine/drivers/vmwarefusion/vmrun_darwin.go +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2014 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. - */ - -package vmwarefusion - -import ( - "bytes" - "errors" - "fmt" - "os" - "os/exec" - "path/filepath" - "strings" - "syscall" - - "github.com/docker/machine/libmachine/log" -) - -var ( - vmrunbin = setVmwareCmd("vmrun") - vdiskmanbin = setVmwareCmd("vmware-vdiskmanager") -) - -var ( - ErrMachineExist = errors.New("machine already exists") - ErrMachineNotExist = errors.New("machine does not exist") - ErrVMRUNNotFound = errors.New("VMRUN not found") -) - -// detect the vmrun and vmware-vdiskmanager cmds' path if needed -func setVmwareCmd(cmd string) string { - if path, err := exec.LookPath(cmd); err == nil { - return path - } - return filepath.Join("/Applications/VMware Fusion.app/Contents/Library/", cmd) -} - -func vmrun(args ...string) (string, string, error) { - // vmrun with nogui on VMware Fusion through at least 8.0.1 doesn't work right - // if the umask is set to not allow world-readable permissions - _ = syscall.Umask(022) - cmd := exec.Command(vmrunbin, args...) - if os.Getenv("MACHINE_DEBUG") != "" { - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - } - - var stdout bytes.Buffer - var stderr bytes.Buffer - cmd.Stdout, cmd.Stderr = &stdout, &stderr - log.Debugf("executing: %v %v", vmrunbin, strings.Join(args, " ")) - - err := cmd.Run() - if err != nil { - if ee, ok := err.(*exec.Error); ok && ee == exec.ErrNotFound { - err = ErrVMRUNNotFound - } - } - - return stdout.String(), stderr.String(), err -} - -// Make a vmdk disk image with the given size (in MB). -func vdiskmanager(dest string, size int) error { - cmd := exec.Command(vdiskmanbin, "-c", "-t", "0", "-s", fmt.Sprintf("%dMB", size), "-a", "lsilogic", dest) - if os.Getenv("MACHINE_DEBUG") != "" { - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - } - - if stdout := cmd.Run(); stdout != nil { - if ee, ok := stdout.(*exec.Error); ok && ee == exec.ErrNotFound { - return ErrVMRUNNotFound - } - } - return nil -} diff --git a/vendor/github.com/docker/machine/drivers/vmwarefusion/vmx_darwin.go b/vendor/github.com/docker/machine/drivers/vmwarefusion/vmx_darwin.go deleted file mode 100644 index 0ca6e63..0000000 --- a/vendor/github.com/docker/machine/drivers/vmwarefusion/vmx_darwin.go +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2014 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. - */ - -package vmwarefusion - -const vmx = ` -.encoding = "UTF-8" -config.version = "8" -displayName = "{{.MachineName}}" -ethernet0.present = "TRUE" -ethernet0.connectionType = "nat" -ethernet0.virtualDev = "vmxnet3" -ethernet0.wakeOnPcktRcv = "FALSE" -ethernet0.addressType = "generated" -ethernet0.linkStatePropagation.enable = "TRUE" -pciBridge0.present = "TRUE" -pciBridge4.present = "TRUE" -pciBridge4.virtualDev = "pcieRootPort" -pciBridge4.functions = "8" -pciBridge5.present = "TRUE" -pciBridge5.virtualDev = "pcieRootPort" -pciBridge5.functions = "8" -pciBridge6.present = "TRUE" -pciBridge6.virtualDev = "pcieRootPort" -pciBridge6.functions = "8" -pciBridge7.present = "TRUE" -pciBridge7.virtualDev = "pcieRootPort" -pciBridge7.functions = "8" -pciBridge0.pciSlotNumber = "17" -pciBridge4.pciSlotNumber = "21" -pciBridge5.pciSlotNumber = "22" -pciBridge6.pciSlotNumber = "23" -pciBridge7.pciSlotNumber = "24" -scsi0.pciSlotNumber = "160" -usb.pciSlotNumber = "32" -ethernet0.pciSlotNumber = "192" -sound.pciSlotNumber = "33" -vmci0.pciSlotNumber = "35" -sata0.pciSlotNumber = "36" -floppy0.present = "FALSE" -guestOS = "other3xlinux-64" -hpet0.present = "TRUE" -sata0.present = "TRUE" -sata0:1.present = "TRUE" -sata0:1.fileName = "{{.ISO}}" -sata0:1.deviceType = "cdrom-image" -{{ if .ConfigDriveURL }} -sata0:2.present = "TRUE" -sata0:2.fileName = "{{.ConfigDriveISO}}" -sata0:2.deviceType = "cdrom-image" -{{ end }} -vmci0.present = "TRUE" -mem.hotadd = "TRUE" -memsize = "{{.Memory}}" -powerType.powerOff = "soft" -powerType.powerOn = "soft" -powerType.reset = "soft" -powerType.suspend = "soft" -scsi0.present = "TRUE" -scsi0.virtualDev = "pvscsi" -scsi0:0.fileName = "{{.MachineName}}.vmdk" -scsi0:0.present = "TRUE" -tools.synctime = "TRUE" -virtualHW.productCompatibility = "hosted" -virtualHW.version = "10" -msg.autoanswer = "TRUE" -uuid.action = "create" -numvcpus = "{{.CPU}}" -hgfs.mapRootShare = "FALSE" -hgfs.linkRootShare = "FALSE" -` diff --git a/vendor/github.com/docker/machine/drivers/vmwarevcloudair/vcloudair.go b/vendor/github.com/docker/machine/drivers/vmwarevcloudair/vcloudair.go deleted file mode 100644 index 1632951..0000000 --- a/vendor/github.com/docker/machine/drivers/vmwarevcloudair/vcloudair.go +++ /dev/null @@ -1,621 +0,0 @@ -/* - * Copyright 2014 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. - */ - -package vmwarevcloudair - -import ( - "fmt" - "io/ioutil" - "net" - "strconv" - "strings" - - "github.com/vmware/govcloudair" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" -) - -type Driver struct { - *drivers.BaseDriver - UserName string - UserPassword string - ComputeID string - VDCID string - OrgVDCNet string - EdgeGateway string - PublicIP string - Catalog string - CatalogItem string - DockerPort int - CPUCount int - MemorySize int - VAppID string -} - -const ( - defaultCatalog = "Public Catalog" - defaultCatalogItem = "Ubuntu Server 12.04 LTS (amd64 20150127)" - defaultCpus = 1 - defaultMemory = 2048 - defaultSSHPort = 22 - defaultDockerPort = 2376 -) - -// GetCreateFlags registers the flags this driver adds to -// "docker hosts create" -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.StringFlag{ - EnvVar: "VCLOUDAIR_USERNAME", - Name: "vmwarevcloudair-username", - Usage: "vCloud Air username", - }, - mcnflag.StringFlag{ - EnvVar: "VCLOUDAIR_PASSWORD", - Name: "vmwarevcloudair-password", - Usage: "vCloud Air password", - }, - mcnflag.StringFlag{ - EnvVar: "VCLOUDAIR_COMPUTEID", - Name: "vmwarevcloudair-computeid", - Usage: "vCloud Air Compute ID (if using Dedicated Cloud)", - }, - mcnflag.StringFlag{ - EnvVar: "VCLOUDAIR_VDCID", - Name: "vmwarevcloudair-vdcid", - Usage: "vCloud Air VDC ID", - }, - mcnflag.StringFlag{ - EnvVar: "VCLOUDAIR_ORGVDCNETWORK", - Name: "vmwarevcloudair-orgvdcnetwork", - Usage: "vCloud Air Org VDC Network (Default is -default-routed)", - }, - mcnflag.StringFlag{ - EnvVar: "VCLOUDAIR_EDGEGATEWAY", - Name: "vmwarevcloudair-edgegateway", - Usage: "vCloud Air Org Edge Gateway (Default is )", - }, - mcnflag.StringFlag{ - EnvVar: "VCLOUDAIR_PUBLICIP", - Name: "vmwarevcloudair-publicip", - Usage: "vCloud Air Org Public IP to use", - }, - mcnflag.StringFlag{ - EnvVar: "VCLOUDAIR_CATALOG", - Name: "vmwarevcloudair-catalog", - Usage: "vCloud Air Catalog (default is Public Catalog)", - Value: defaultCatalog, - }, - mcnflag.StringFlag{ - EnvVar: "VCLOUDAIR_CATALOGITEM", - Name: "vmwarevcloudair-catalogitem", - Usage: "vCloud Air Catalog Item (default is Ubuntu Precise)", - Value: defaultCatalogItem, - }, - mcnflag.IntFlag{ - EnvVar: "VCLOUDAIR_CPU_COUNT", - Name: "vmwarevcloudair-cpu-count", - Usage: "vCloud Air VM Cpu Count (default 1)", - Value: defaultCpus, - }, - mcnflag.IntFlag{ - EnvVar: "VCLOUDAIR_MEMORY_SIZE", - Name: "vmwarevcloudair-memory-size", - Usage: "vCloud Air VM Memory Size in MB (default 2048)", - Value: defaultMemory, - }, - mcnflag.IntFlag{ - EnvVar: "VCLOUDAIR_SSH_PORT", - Name: "vmwarevcloudair-ssh-port", - Usage: "vCloud Air SSH port", - Value: defaultSSHPort, - }, - mcnflag.IntFlag{ - EnvVar: "VCLOUDAIR_DOCKER_PORT", - Name: "vmwarevcloudair-docker-port", - Usage: "vCloud Air Docker port", - Value: defaultDockerPort, - }, - } -} - -func NewDriver(hostName, storePath string) drivers.Driver { - return &Driver{ - Catalog: defaultCatalog, - CatalogItem: defaultCatalogItem, - CPUCount: defaultCpus, - MemorySize: defaultMemory, - DockerPort: defaultDockerPort, - BaseDriver: &drivers.BaseDriver{ - SSHPort: defaultSSHPort, - MachineName: hostName, - StorePath: storePath, - }, - } -} - -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "vmwarevcloudair" -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - - d.UserName = flags.String("vmwarevcloudair-username") - d.UserPassword = flags.String("vmwarevcloudair-password") - d.VDCID = flags.String("vmwarevcloudair-vdcid") - d.PublicIP = flags.String("vmwarevcloudair-publicip") - d.SetSwarmConfigFromFlags(flags) - - // Check for required Params - if d.UserName == "" || d.UserPassword == "" || d.VDCID == "" || d.PublicIP == "" { - return fmt.Errorf("Please specify vcloudair mandatory params using options: -vmwarevcloudair-username -vmwarevcloudair-password -vmwarevcloudair-vdcid and -vmwarevcloudair-publicip") - } - - // If ComputeID is not set we're using a VPC, hence setting ComputeID = VDCID - if flags.String("vmwarevcloudair-computeid") == "" { - d.ComputeID = flags.String("vmwarevcloudair-vdcid") - } else { - d.ComputeID = flags.String("vmwarevcloudair-computeid") - } - - // If the Org VDC Network is empty, set it to the default routed network. - if flags.String("vmwarevcloudair-orgvdcnetwork") == "" { - d.OrgVDCNet = flags.String("vmwarevcloudair-vdcid") + "-default-routed" - } else { - d.OrgVDCNet = flags.String("vmwarevcloudair-orgvdcnetwork") - } - - // If the Edge Gateway is empty, just set it to the default edge gateway. - if flags.String("vmwarevcloudair-edgegateway") == "" { - d.EdgeGateway = flags.String("vmwarevcloudair-vdcid") - } else { - d.EdgeGateway = flags.String("vmwarevcloudair-edgegateway") - } - - d.Catalog = flags.String("vmwarevcloudair-catalog") - d.CatalogItem = flags.String("vmwarevcloudair-catalogitem") - - d.DockerPort = flags.Int("vmwarevcloudair-docker-port") - d.SSHUser = "root" - d.SSHPort = flags.Int("vmwarevcloudair-ssh-port") - d.CPUCount = flags.Int("vmwarevcloudair-cpu-count") - d.MemorySize = flags.Int("vmwarevcloudair-memory-size") - - return nil -} - -func (d *Driver) GetURL() (string, error) { - if err := drivers.MustBeRunning(d); err != nil { - return "", err - } - - return fmt.Sprintf("tcp://%s", net.JoinHostPort(d.PublicIP, strconv.Itoa(d.DockerPort))), nil -} - -func (d *Driver) GetIP() (string, error) { - return d.PublicIP, nil -} - -func (d *Driver) GetState() (state.State, error) { - p, err := govcloudair.NewClient() - if err != nil { - return state.Error, err - } - - log.Debug("Connecting to vCloud Air to fetch vApp Status...") - // Authenticate to vCloud Air - v, err := p.Authenticate(d.UserName, d.UserPassword, d.ComputeID, d.VDCID) - if err != nil { - return state.Error, err - } - - vapp, err := v.FindVAppByID(d.VAppID) - if err != nil { - return state.Error, err - } - - status, err := vapp.GetStatus() - if err != nil { - return state.Error, err - } - - if err = p.Disconnect(); err != nil { - return state.Error, err - } - - switch status { - case "POWERED_ON": - return state.Running, nil - case "POWERED_OFF": - return state.Stopped, nil - } - return state.None, nil -} - -func (d *Driver) Create() error { - key, err := d.createSSHKey() - if err != nil { - return err - } - - p, err := govcloudair.NewClient() - if err != nil { - return err - } - - log.Infof("Connecting to vCloud Air...") - // Authenticate to vCloud Air - v, err := p.Authenticate(d.UserName, d.UserPassword, d.ComputeID, d.VDCID) - if err != nil { - return err - } - - // Find VDC Network - net, err := v.FindVDCNetwork(d.OrgVDCNet) - if err != nil { - return err - } - - // Find our Edge Gateway - edge, err := v.FindEdgeGateway(d.EdgeGateway) - if err != nil { - return err - } - - // Get the Org our VDC belongs to - org, err := v.GetVDCOrg() - if err != nil { - return err - } - - // Find our Catalog - cat, err := org.FindCatalog(d.Catalog) - if err != nil { - return err - } - - // Find our Catalog Item - cati, err := cat.FindCatalogItem(d.CatalogItem) - if err != nil { - return err - } - - // Fetch the vApp Template in the Catalog Item - vapptemplate, err := cati.GetVAppTemplate() - if err != nil { - return err - } - - // Create a new empty vApp - vapp := govcloudair.NewVApp(p) - - log.Infof("Creating a new vApp: %s...", d.MachineName) - // Compose the vApp with ComposeVApp - task, err := vapp.ComposeVApp(net, vapptemplate, d.MachineName, "Container Host created with Docker Host") - if err != nil { - return err - } - - // Wait for the creation to be completed - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - task, err = vapp.ChangeCPUcount(d.CPUCount) - if err != nil { - return err - } - - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - task, err = vapp.ChangeMemorySize(d.MemorySize) - if err != nil { - return err - } - - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - sshCustomScript := "echo \"" + strings.TrimSpace(key) + "\" > /root/.ssh/authorized_keys" - - task, err = vapp.RunCustomizationScript(d.MachineName, sshCustomScript) - if err != nil { - return err - } - - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - task, err = vapp.PowerOn() - if err != nil { - return err - } - - log.Infof("Waiting for the VM to power on and run the customization script...") - - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - log.Infof("Creating NAT and Firewall Rules on %s...", d.EdgeGateway) - task, err = edge.Create1to1Mapping(vapp.VApp.Children.VM[0].NetworkConnectionSection.NetworkConnection.IPAddress, d.PublicIP, d.MachineName) - if err != nil { - return err - } - - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - log.Debugf("Disconnecting from vCloud Air...") - - if err = p.Disconnect(); err != nil { - return err - } - - // Set VAppID with ID of the created VApp - d.VAppID = vapp.VApp.ID - - d.IPAddress, err = d.GetIP() - return err -} - -func (d *Driver) Remove() error { - p, err := govcloudair.NewClient() - if err != nil { - return err - } - - log.Infof("Connecting to vCloud Air...") - // Authenticate to vCloud Air - v, err := p.Authenticate(d.UserName, d.UserPassword, d.ComputeID, d.VDCID) - if err != nil { - return err - } - - // Find our Edge Gateway - edge, err := v.FindEdgeGateway(d.EdgeGateway) - if err != nil { - return err - } - - vapp, err := v.FindVAppByID(d.VAppID) - if err != nil { - log.Infof("Can't find the vApp, assuming it was deleted already...") - return nil - } - - status, err := vapp.GetStatus() - if err != nil { - return err - } - - log.Infof("Removing NAT and Firewall Rules on %s...", d.EdgeGateway) - task, err := edge.Remove1to1Mapping(vapp.VApp.Children.VM[0].NetworkConnectionSection.NetworkConnection.IPAddress, d.PublicIP) - if err != nil { - return err - } - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - if status == "POWERED_ON" { - // If it's powered on, power it off before deleting - log.Infof("Powering Off %s...", d.MachineName) - task, err = vapp.PowerOff() - if err != nil { - return err - } - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - } - - log.Debugf("Undeploying %s...", d.MachineName) - task, err = vapp.Undeploy() - if err != nil { - return err - } - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - log.Infof("Deleting %s...", d.MachineName) - task, err = vapp.Delete() - if err != nil { - return err - } - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - err = p.Disconnect() - return err -} - -func (d *Driver) Start() error { - p, err := govcloudair.NewClient() - if err != nil { - return err - } - - log.Infof("Connecting to vCloud Air...") - // Authenticate to vCloud Air - v, err := p.Authenticate(d.UserName, d.UserPassword, d.ComputeID, d.VDCID) - if err != nil { - return err - } - - vapp, err := v.FindVAppByID(d.VAppID) - if err != nil { - return err - } - - status, err := vapp.GetStatus() - if err != nil { - return err - } - - if status == "POWERED_OFF" { - log.Infof("Starting %s...", d.MachineName) - task, err := vapp.PowerOn() - if err != nil { - return err - } - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - } - - if err = p.Disconnect(); err != nil { - return err - } - - d.IPAddress, err = d.GetIP() - return err -} - -func (d *Driver) Stop() error { - p, err := govcloudair.NewClient() - if err != nil { - return err - } - - log.Infof("Connecting to vCloud Air...") - // Authenticate to vCloud Air - v, err := p.Authenticate(d.UserName, d.UserPassword, d.ComputeID, d.VDCID) - if err != nil { - return err - } - - vapp, err := v.FindVAppByID(d.VAppID) - if err != nil { - return err - } - - task, err := vapp.Shutdown() - if err != nil { - return err - } - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - if err = p.Disconnect(); err != nil { - return err - } - - d.IPAddress = "" - - return nil -} - -func (d *Driver) Restart() error { - p, err := govcloudair.NewClient() - if err != nil { - return err - } - - log.Infof("Connecting to vCloud Air...") - // Authenticate to vCloud Air - v, err := p.Authenticate(d.UserName, d.UserPassword, d.ComputeID, d.VDCID) - if err != nil { - return err - } - - vapp, err := v.FindVAppByID(d.VAppID) - if err != nil { - return err - } - - task, err := vapp.Reset() - if err != nil { - return err - } - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - if err = p.Disconnect(); err != nil { - return err - } - - d.IPAddress, err = d.GetIP() - return err -} - -func (d *Driver) Kill() error { - p, err := govcloudair.NewClient() - if err != nil { - return err - } - - log.Infof("Connecting to vCloud Air...") - // Authenticate to vCloud Air - v, err := p.Authenticate(d.UserName, d.UserPassword, d.ComputeID, d.VDCID) - if err != nil { - return err - } - - vapp, err := v.FindVAppByID(d.VAppID) - if err != nil { - return err - } - - task, err := vapp.PowerOff() - if err != nil { - return err - } - if err = task.WaitTaskCompletion(); err != nil { - return err - } - - if err = p.Disconnect(); err != nil { - return err - } - - d.IPAddress = "" - - return nil -} - -// Helpers - -func generateVMName() string { - randomID := mcnutils.TruncateID(mcnutils.GenerateRandomID()) - return fmt.Sprintf("docker-host-%s", randomID) -} - -func (d *Driver) createSSHKey() (string, error) { - if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { - return "", err - } - - publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath()) - if err != nil { - return "", err - } - - return string(publicKey), nil -} - -func (d *Driver) publicSSHKeyPath() string { - return d.GetSSHKeyPath() + ".pub" -} diff --git a/vendor/github.com/docker/machine/drivers/vmwarevcloudair/vcloudlair_test.go b/vendor/github.com/docker/machine/drivers/vmwarevcloudair/vcloudlair_test.go deleted file mode 100644 index e92ee55..0000000 --- a/vendor/github.com/docker/machine/drivers/vmwarevcloudair/vcloudlair_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package vmwarevcloudair - -import ( - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -func TestSetConfigFromFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{ - "vmwarevcloudair-username": "root", - "vmwarevcloudair-password": "pwd", - "vmwarevcloudair-vdcid": "ID", - "vmwarevcloudair-publicip": "IP", - }, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) -} diff --git a/vendor/github.com/docker/machine/drivers/vmwarevsphere/vsphere.go b/vendor/github.com/docker/machine/drivers/vmwarevsphere/vsphere.go deleted file mode 100644 index 8ce00d1..0000000 --- a/vendor/github.com/docker/machine/drivers/vmwarevsphere/vsphere.go +++ /dev/null @@ -1,1003 +0,0 @@ -/* - * Copyright 2014 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. - */ - -package vmwarevsphere - -import ( - "archive/tar" - "encoding/base64" - "fmt" - "io/ioutil" - "net" - "net/url" - "os" - "strings" - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" - - "errors" - - "github.com/vmware/govmomi" - "github.com/vmware/govmomi/find" - "github.com/vmware/govmomi/guest" - "github.com/vmware/govmomi/object" - "github.com/vmware/govmomi/vim25/mo" - "github.com/vmware/govmomi/vim25/soap" - "github.com/vmware/govmomi/vim25/types" - "golang.org/x/net/context" -) - -const ( - // dockerBridgeIP is the default IP address of the docker0 bridge. - dockerBridgeIP = "172.17.0.1" - isoFilename = "boot2docker.iso" - // B2DUser is the guest User for tools login - B2DUser = "docker" - // B2DPass is the guest Pass for tools login - B2DPass = "tcuser" -) - -type Driver struct { - *drivers.BaseDriver - Memory int - DiskSize int - CPU int - ISO string - Boot2DockerURL string - CPUS int - - IP string - Port int - Username string - Password string - Network string - Networks []string - Datastore string - Datacenter string - Pool string - HostSystem string - CfgParams []string - CloudInit string - - SSHPassword string -} - -const ( - defaultSSHUser = B2DUser - defaultSSHPass = B2DPass - defaultCpus = 2 - defaultMemory = 2048 - defaultDiskSize = 20480 - defaultSDKPort = 443 -) - -// GetCreateFlags registers the flags this driver adds to -// "docker-machine create" -func (d *Driver) GetCreateFlags() []mcnflag.Flag { - return []mcnflag.Flag{ - mcnflag.IntFlag{ - EnvVar: "VSPHERE_CPU_COUNT", - Name: "vmwarevsphere-cpu-count", - Usage: "vSphere CPU number for docker VM", - Value: defaultCpus, - }, - mcnflag.IntFlag{ - EnvVar: "VSPHERE_MEMORY_SIZE", - Name: "vmwarevsphere-memory-size", - Usage: "vSphere size of memory for docker VM (in MB)", - Value: defaultMemory, - }, - mcnflag.IntFlag{ - EnvVar: "VSPHERE_DISK_SIZE", - Name: "vmwarevsphere-disk-size", - Usage: "vSphere size of disk for docker VM (in MB)", - Value: defaultDiskSize, - }, - mcnflag.StringFlag{ - EnvVar: "VSPHERE_BOOT2DOCKER_URL", - Name: "vmwarevsphere-boot2docker-url", - Usage: "vSphere URL for boot2docker image", - }, - mcnflag.StringFlag{ - EnvVar: "VSPHERE_VCENTER", - Name: "vmwarevsphere-vcenter", - Usage: "vSphere IP/hostname for vCenter", - }, - mcnflag.IntFlag{ - EnvVar: "VSPHERE_VCENTER_PORT", - Name: "vmwarevsphere-vcenter-port", - Usage: "vSphere Port for vCenter", - Value: defaultSDKPort, - }, - mcnflag.StringFlag{ - EnvVar: "VSPHERE_USERNAME", - Name: "vmwarevsphere-username", - Usage: "vSphere username", - }, - mcnflag.StringFlag{ - EnvVar: "VSPHERE_PASSWORD", - Name: "vmwarevsphere-password", - Usage: "vSphere password", - }, - mcnflag.StringSliceFlag{ - EnvVar: "VSPHERE_NETWORK", - Name: "vmwarevsphere-network", - Usage: "vSphere network where the docker VM will be attached", - }, - mcnflag.StringFlag{ - EnvVar: "VSPHERE_DATASTORE", - Name: "vmwarevsphere-datastore", - Usage: "vSphere datastore for docker VM", - }, - mcnflag.StringFlag{ - EnvVar: "VSPHERE_DATACENTER", - Name: "vmwarevsphere-datacenter", - Usage: "vSphere datacenter for docker VM", - }, - mcnflag.StringFlag{ - EnvVar: "VSPHERE_POOL", - Name: "vmwarevsphere-pool", - Usage: "vSphere resource pool for docker VM", - }, - mcnflag.StringFlag{ - EnvVar: "VSPHERE_HOSTSYSTEM", - Name: "vmwarevsphere-hostsystem", - Usage: "vSphere compute resource where the docker VM will be instantiated. This can be omitted if using a cluster with DRS.", - }, - mcnflag.StringSliceFlag{ - EnvVar: "VSPHERE_CFGPARAM", - Name: "vmwarevsphere-cfgparam", - Usage: "vSphere vm configuration parameters (used for guestinfo)", - }, - mcnflag.StringFlag{ - EnvVar: "VSPHERE_CLOUDINIT", - Name: "vmwarevsphere-cloudinit", - Usage: "vSphere cloud-init file or url to set in the guestinfo", - }, - } -} - -func NewDriver(hostName, storePath string) drivers.Driver { - return &Driver{ - CPUS: defaultCpus, - Memory: defaultMemory, - DiskSize: defaultDiskSize, - SSHPassword: defaultSSHPass, - Port: defaultSDKPort, - BaseDriver: &drivers.BaseDriver{ - SSHUser: defaultSSHUser, - MachineName: hostName, - StorePath: storePath, - }, - } -} - -func (d *Driver) GetSSHHostname() (string, error) { - return d.GetIP() -} - -func (d *Driver) GetSSHUsername() string { - if d.SSHUser == "" { - d.SSHUser = "docker" - } - - return d.SSHUser -} - -// DriverName returns the name of the driver -func (d *Driver) DriverName() string { - return "vmwarevsphere" -} - -func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { - d.SSHUser = "docker" - d.SSHPort = 22 - d.CPU = flags.Int("vmwarevsphere-cpu-count") - d.Memory = flags.Int("vmwarevsphere-memory-size") - d.DiskSize = flags.Int("vmwarevsphere-disk-size") - d.Boot2DockerURL = flags.String("vmwarevsphere-boot2docker-url") - d.IP = flags.String("vmwarevsphere-vcenter") - d.Port = flags.Int("vmwarevsphere-vcenter-port") - d.Username = flags.String("vmwarevsphere-username") - d.Password = flags.String("vmwarevsphere-password") - d.Networks = flags.StringSlice("vmwarevsphere-network") - d.Datastore = flags.String("vmwarevsphere-datastore") - d.Datacenter = flags.String("vmwarevsphere-datacenter") - d.Pool = flags.String("vmwarevsphere-pool") - d.HostSystem = flags.String("vmwarevsphere-hostsystem") - d.CfgParams = flags.StringSlice("vmwarevsphere-cfgparam") - d.CloudInit = flags.String("vmwarevsphere-cloudinit") - d.SetSwarmConfigFromFlags(flags) - - d.ISO = d.ResolveStorePath(isoFilename) - - return nil -} - -func (d *Driver) GetURL() (string, error) { - - ip, err := d.GetIP() - if err != nil { - return "", err - } - if ip == "" { - return "", nil - } - return fmt.Sprintf("tcp://%s", net.JoinHostPort(ip, "2376")), nil -} - -func (d *Driver) GetIP() (string, error) { - status, err := d.GetState() - if status != state.Running { - return "", drivers.ErrHostIsNotRunning - } - - // Create context - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - c, err := d.vsphereLogin(ctx) - if err != nil { - return "", err - } - defer c.Logout(ctx) - - vm, err := d.fetchVM(ctx, c, d.MachineName) - if err != nil { - return "", err - } - - configuredMacIPs, err := vm.WaitForNetIP(ctx, false) - if err != nil { - return "", err - } - - for _, ips := range configuredMacIPs { - if len(ips) >= 0 { - // Prefer IPv4 address, but fall back to first/IPv6 - preferredIP := ips[0] - for _, ip := range ips { - // In addition to non IPv4 addresses, try to filter - // out link local addresses and the default address of - // the Docker0 bridge - netIP := net.ParseIP(ip) - if netIP.To4() != nil && netIP.IsGlobalUnicast() && !netIP.Equal(net.ParseIP(dockerBridgeIP)) { - preferredIP = ip - break - } - } - return preferredIP, nil - } - } - - return "", errors.New("No IP despite waiting for one - check DHCP status") -} - -func (d *Driver) GetState() (state.State, error) { - - // Create context - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - c, err := d.vsphereLogin(ctx) - if err != nil { - return state.None, err - } - defer c.Logout(ctx) - - vm, err := d.fetchVM(ctx, c, d.MachineName) - if err != nil { - return state.None, err - } - - var mvm mo.VirtualMachine - - err = c.RetrieveOne(ctx, vm.Reference(), nil, &mvm) - if err != nil { - return state.None, nil - } - - s := mvm.Summary - - if strings.Contains(string(s.Runtime.PowerState), "poweredOn") { - return state.Running, nil - } else if strings.Contains(string(s.Runtime.PowerState), "poweredOff") { - return state.Stopped, nil - } - return state.None, nil -} - -// PreCreateCheck checks that the machine creation process can be started safely. -func (d *Driver) PreCreateCheck() error { - log.Debug("Connecting to vSphere for pre-create checks...") - // Create context - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - c, err := d.vsphereLogin(ctx) - if err != nil { - return err - } - defer c.Logout(ctx) - - // Create a new finder - f := find.NewFinder(c.Client, true) - - dc, err := f.DatacenterOrDefault(ctx, d.Datacenter) - if err != nil { - return err - } - - f.SetDatacenter(dc) - - if _, err := f.DatastoreOrDefault(ctx, d.Datastore); err != nil { - return err - } - - // TODO: if the user has both the VSPHERE_NETWORK defined and adds --vmwarevsphere-network - // both are used at the same time - probably should detect that and remove the one from ENV - if len(d.Networks) == 0 { - // machine assumes there will be a network - d.Networks = append(d.Networks, "VM Network") - } - for _, netName := range d.Networks { - if _, err := f.NetworkOrDefault(ctx, netName); err != nil { - return err - } - } - // d.Network needs to remain a string to cope with existing machines :/ - d.Network = d.Networks[0] - - var hs *object.HostSystem - if d.HostSystem != "" { - var err error - hs, err = f.HostSystemOrDefault(ctx, d.HostSystem) - if err != nil { - return err - } - } - - // ResourcePool - if d.Pool != "" { - // Find specified Resource Pool - if _, err := f.ResourcePool(ctx, d.Pool); err != nil { - return err - } - } else if hs != nil { - // Pick default Resource Pool for Host System - if _, err := hs.ResourcePool(ctx); err != nil { - return err - } - } else { - // Pick the default Resource Pool for the Datacenter. - if _, err := f.DefaultResourcePool(ctx); err != nil { - return err - } - } - - return nil -} - -// Create has the following implementation: -// 1. check whether the docker directory contains the boot2docker ISO -// 2. generate an SSH keypair and bundle it in a tar. -// 3. create a virtual machine with the boot2docker ISO mounted; -// 4. reconfigure the virtual machine network and disk size; -func (d *Driver) Create() error { - b2dutils := mcnutils.NewB2dUtils(d.StorePath) - if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil { - return err - } - - log.Infof("Generating SSH Keypair...") - if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { - return err - } - - // Create context - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - c, err := d.vsphereLogin(ctx) - if err != nil { - return err - } - defer c.Logout(ctx) - - // Create a new finder - f := find.NewFinder(c.Client, true) - - dc, err := f.DatacenterOrDefault(ctx, d.Datacenter) - if err != nil { - return err - } - - f.SetDatacenter(dc) - - dss, err := f.DatastoreOrDefault(ctx, d.Datastore) - if err != nil { - return err - } - - networks := make(map[string]object.NetworkReference) - for _, netName := range d.Networks { - net, err := f.NetworkOrDefault(ctx, netName) - if err != nil { - return err - } - networks[netName] = net - } - - var hs *object.HostSystem - if d.HostSystem != "" { - var err error - hs, err = f.HostSystemOrDefault(ctx, d.HostSystem) - if err != nil { - return err - } - } - - var rp *object.ResourcePool - if d.Pool != "" { - // Find specified Resource Pool - rp, err = f.ResourcePool(ctx, d.Pool) - if err != nil { - return err - } - } else if d.HostSystem != "" { - // Pick default Resource Pool for Host System - rp, err = hs.ResourcePool(ctx) - if err != nil { - return err - } - } else { - // Pick the default Resource Pool for the Datacenter. - rp, err = f.DefaultResourcePool(ctx) - if err != nil { - return err - } - } - - spec := types.VirtualMachineConfigSpec{ - Name: d.MachineName, - GuestId: "otherLinux64Guest", - Files: &types.VirtualMachineFileInfo{VmPathName: fmt.Sprintf("[%s]", dss.Name())}, - NumCPUs: int32(d.CPU), - MemoryMB: int64(d.Memory), - } - - scsi, err := object.SCSIControllerTypes().CreateSCSIController("pvscsi") - if err != nil { - return err - } - - spec.DeviceChange = append(spec.DeviceChange, &types.VirtualDeviceConfigSpec{ - Operation: types.VirtualDeviceConfigSpecOperationAdd, - Device: scsi, - }) - - log.Infof("Creating VM...") - folders, err := dc.Folders(ctx) - task, err := folders.VmFolder.CreateVM(ctx, spec, rp, hs) - if err != nil { - return err - } - - info, err := task.WaitForResult(ctx, nil) - if err != nil { - return err - } - - log.Infof("Uploading Boot2docker ISO ...") - dsurl, err := dss.URL(ctx, dc, fmt.Sprintf("%s/%s", d.MachineName, isoFilename)) - if err != nil { - return err - } - p := soap.DefaultUpload - if err = c.Client.UploadFile(d.ISO, dsurl, &p); err != nil { - return err - } - - // Retrieve the new VM - vm := object.NewVirtualMachine(c.Client, info.Result.(types.ManagedObjectReference)) - - devices, err := vm.Device(ctx) - if err != nil { - return err - } - - var add []types.BaseVirtualDevice - - controller, err := devices.FindDiskController("scsi") - if err != nil { - return err - } - - disk := devices.CreateDisk(controller, dss.Reference(), - dss.Path(fmt.Sprintf("%s/%s.vmdk", d.MachineName, d.MachineName))) - - // Convert MB to KB - disk.CapacityInKB = int64(d.DiskSize) * 1024 - - add = append(add, disk) - ide, err := devices.FindIDEController("") - if err != nil { - return err - } - - cdrom, err := devices.CreateCdrom(ide) - if err != nil { - return err - } - - add = append(add, devices.InsertIso(cdrom, dss.Path(fmt.Sprintf("%s/%s", d.MachineName, isoFilename)))) - - for _, netName := range d.Networks { - backing, err := networks[netName].EthernetCardBackingInfo(ctx) - if err != nil { - return err - } - - netdev, err := object.EthernetCardTypes().CreateEthernetCard("vmxnet3", backing) - if err != nil { - return err - } - - log.Infof("adding network: %s", netName) - add = append(add, netdev) - } - - log.Infof("Reconfiguring VM") - if vm.AddDevice(ctx, add...); err != nil { - return err - } - - // Adding some guestinfo data - var opts []types.BaseOptionValue - for _, param := range d.CfgParams { - v := strings.SplitN(param, "=", 2) - key := v[0] - value := "" - if len(v) > 1 { - value = v[1] - } - fmt.Printf("Setting %s to %s\n", key, value) - opts = append(opts, &types.OptionValue{ - Key: key, - Value: value, - }) - } - if d.CloudInit != "" { - if _, err := url.ParseRequestURI(d.CloudInit); err == nil { - log.Infof("setting guestinfo.cloud-init.data.url to %s\n", d.CloudInit) - opts = append(opts, &types.OptionValue{ - Key: "guestinfo.cloud-init.config.url", - Value: d.CloudInit, - }) - } else { - if _, err := os.Stat(d.CloudInit); err == nil { - if value, err := ioutil.ReadFile(d.CloudInit); err == nil { - log.Infof("setting guestinfo.cloud-init.data to encoded content of %s\n", d.CloudInit) - encoded := base64.StdEncoding.EncodeToString(value) - opts = append(opts, &types.OptionValue{ - Key: "guestinfo.cloud-init.config.data", - Value: encoded, - }) - opts = append(opts, &types.OptionValue{ - Key: "guestinfo.cloud-init.data.encoding", - Value: "base64", - }) - } - } - } - } - - task, err = vm.Reconfigure(ctx, types.VirtualMachineConfigSpec{ - ExtraConfig: opts, - }) - if err != nil { - return err - } - task.Wait(ctx) - - if err := d.Start(); err != nil { - return err - } - - log.Infof("Provisioning certs and ssh keys...") - // Generate a tar keys bundle - if err := d.generateKeyBundle(); err != nil { - return err - } - - opman := guest.NewOperationsManager(c.Client, vm.Reference()) - - fileman, err := opman.FileManager(ctx) - if err != nil { - return err - } - - src := d.ResolveStorePath("userdata.tar") - s, err := os.Stat(src) - if err != nil { - return err - } - - auth := AuthFlag{} - flag := FileAttrFlag{} - auth.auth.Username = B2DUser - auth.auth.Password = B2DPass - flag.SetPerms(0, 0, 660) - url, err := fileman.InitiateFileTransferToGuest(ctx, auth.Auth(), "/home/docker/userdata.tar", flag.Attr(), s.Size(), true) - if err != nil { - return err - } - u, err := c.Client.ParseURL(url) - if err != nil { - return err - } - if err = c.Client.UploadFile(src, u, nil); err != nil { - return err - } - - procman, err := opman.ProcessManager(ctx) - if err != nil { - return err - } - - // first, untar - only boot2docker has /var/lib/boot2docker - // TODO: don't hard-code to docker & staff - they are also just b2d - var env []string - guestspec := types.GuestProgramSpec{ - ProgramPath: "/usr/bin/sudo", - Arguments: "/usr/bin/sudo /bin/sh -c \"tar xvf /home/docker/userdata.tar -C /home/docker > /var/log/userdata.log 2>&1 && chown -R docker:staff /home/docker\"", - WorkingDirectory: "", - EnvVariables: env, - } - - _, err = procman.StartProgram(ctx, auth.Auth(), &guestspec) - if err != nil { - return err - } - - // now move to /var/lib/boot2docker if its there - guestspec = types.GuestProgramSpec{ - ProgramPath: "/usr/bin/sudo", - Arguments: "/bin/mv /home/docker/userdata.tar /var/lib/boot2docker/userdata.tar", - WorkingDirectory: "", - EnvVariables: env, - } - - _, err = procman.StartProgram(ctx, auth.Auth(), &guestspec) - if err != nil { - return err - } - - return nil -} - -func (d *Driver) Start() error { - machineState, err := d.GetState() - if err != nil { - return err - } - - switch machineState { - case state.Running: - log.Infof("VM %s has already been started", d.MachineName) - return nil - case state.Stopped: - // TODO add transactional or error handling in the following steps - // Create context - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - c, err := d.vsphereLogin(ctx) - if err != nil { - return err - } - defer c.Logout(ctx) - - vm, err := d.fetchVM(ctx, c, d.MachineName) - if err != nil { - return err - } - - task, err := vm.PowerOn(ctx) - if err != nil { - return err - } - - _, err = task.WaitForResult(ctx, nil) - if err != nil { - return err - } - - log.Infof("Waiting for VMware Tools to come online...") - if d.IPAddress, err = d.GetIP(); err != nil { - return err - } - } - return nil -} - -func (d *Driver) Stop() error { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - c, err := d.vsphereLogin(ctx) - if err != nil { - return err - } - defer c.Logout(ctx) - - vm, err := d.fetchVM(ctx, c, d.MachineName) - if err != nil { - return err - } - - if err := vm.ShutdownGuest(ctx); err != nil { - return err - } - - d.IPAddress = "" - - return nil -} - -func (d *Driver) Restart() error { - if err := d.Stop(); err != nil { - return err - } - - // Check for 120 seconds for the machine to stop - for i := 1; i <= 60; i++ { - machineState, err := d.GetState() - if err != nil { - return err - } - if machineState == state.Running { - log.Debugf("Not there yet %d/%d", i, 60) - time.Sleep(2 * time.Second) - continue - } - if machineState == state.Stopped { - break - } - } - - machineState, err := d.GetState() - // If the VM is still running after 120 seconds just kill it. - if machineState == state.Running { - if err = d.Kill(); err != nil { - return fmt.Errorf("can't stop VM: %s", err) - } - } - - return d.Start() -} - -func (d *Driver) Kill() error { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - c, err := d.vsphereLogin(ctx) - if err != nil { - return err - } - defer c.Logout(ctx) - - vm, err := d.fetchVM(ctx, c, d.MachineName) - if err != nil { - return err - } - - task, err := vm.PowerOff(ctx) - if err != nil { - return err - } - - _, err = task.WaitForResult(ctx, nil) - if err != nil { - return err - } - - d.IPAddress = "" - - return nil -} - -func (d *Driver) Remove() error { - machineState, err := d.GetState() - if err != nil { - return err - } - if machineState == state.Running { - if err = d.Kill(); err != nil { - return fmt.Errorf("can't stop VM: %s", err) - } - } - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - c, err := d.vsphereLogin(ctx) - if err != nil { - return err - } - defer c.Logout(ctx) - - // Create a new finder - f := find.NewFinder(c.Client, true) - - dc, err := f.DatacenterOrDefault(ctx, d.Datacenter) - if err != nil { - return err - } - - f.SetDatacenter(dc) - - dss, err := f.DatastoreOrDefault(ctx, d.Datastore) - if err != nil { - return err - } - - // Remove B2D Iso from VM folder - m := object.NewFileManager(c.Client) - task, err := m.DeleteDatastoreFile(ctx, dss.Path(fmt.Sprintf("%s/%s", d.MachineName, isoFilename)), dc) - if err != nil { - return err - } - - err = task.Wait(ctx) - if err != nil { - if types.IsFileNotFound(err) { - // Ignore error - return nil - } - } - - vm, err := d.fetchVM(ctx, c, d.MachineName) - if err != nil { - return err - } - - task, err = vm.Destroy(ctx) - if err != nil { - return err - } - - _, err = task.WaitForResult(ctx, nil) - if err != nil { - return err - } - return nil -} - -func (d *Driver) Upgrade() error { - return fmt.Errorf("upgrade is not supported for vsphere driver at this moment") -} - -func (d *Driver) publicSSHKeyPath() string { - return d.GetSSHKeyPath() + ".pub" -} - -// Make a boot2docker userdata.tar key bundle -func (d *Driver) generateKeyBundle() error { - log.Debugf("Creating Tar key bundle...") - - magicString := "boot2docker, this is vmware speaking" - - tf, err := os.Create(d.ResolveStorePath("userdata.tar")) - if err != nil { - return err - } - defer tf.Close() - var fileWriter = tf - - tw := tar.NewWriter(fileWriter) - defer tw.Close() - - // magicString first so we can figure out who originally wrote the tar. - file := &tar.Header{Name: magicString, Size: int64(len(magicString))} - if err := tw.WriteHeader(file); err != nil { - return err - } - if _, err := tw.Write([]byte(magicString)); err != nil { - return err - } - // .ssh/key.pub => authorized_keys - file = &tar.Header{Name: ".ssh", Typeflag: tar.TypeDir, Mode: 0700} - if err := tw.WriteHeader(file); err != nil { - return err - } - pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath()) - if err != nil { - return err - } - file = &tar.Header{Name: ".ssh/authorized_keys", Size: int64(len(pubKey)), Mode: 0644} - if err := tw.WriteHeader(file); err != nil { - return err - } - if _, err := tw.Write([]byte(pubKey)); err != nil { - return err - } - file = &tar.Header{Name: ".ssh/authorized_keys2", Size: int64(len(pubKey)), Mode: 0644} - if err := tw.WriteHeader(file); err != nil { - return err - } - if _, err := tw.Write([]byte(pubKey)); err != nil { - return err - } - err = tw.Close() - return err -} - -func (d *Driver) vsphereLogin(ctx context.Context) (*govmomi.Client, error) { - - // Parse URL from string - u, err := url.Parse(fmt.Sprintf("https://%s:%d/sdk", d.IP, d.Port)) - if err != nil { - return nil, err - } - // set username and password for the URL - u.User = url.UserPassword(d.Username, d.Password) - - // Connect and log in to ESX or vCenter - c, err := govmomi.NewClient(ctx, u, true) - if err != nil { - return nil, err - } - - return c, nil -} - -func (d *Driver) fetchVM(ctx context.Context, c *govmomi.Client, vmname string) (*object.VirtualMachine, error) { - - // Create a new finder - f := find.NewFinder(c.Client, true) - - var vm *object.VirtualMachine - var err error - - dc, err := f.DatacenterOrDefault(ctx, d.Datacenter) - if err != nil { - return vm, err - } - - f.SetDatacenter(dc) - - vm, err = f.VirtualMachine(ctx, vmname) - if err != nil { - return vm, err - } - return vm, nil -} - -type AuthFlag struct { - auth types.NamePasswordAuthentication -} - -func (f *AuthFlag) Auth() types.BaseGuestAuthentication { - return &f.auth -} - -type FileAttrFlag struct { - types.GuestPosixFileAttributes -} - -func (f *FileAttrFlag) SetPerms(owner, group, perms int) { - f.OwnerId = int32(owner) - f.GroupId = int32(group) - f.Permissions = int64(perms) -} - -func (f *FileAttrFlag) Attr() types.BaseGuestFileAttributes { - return &f.GuestPosixFileAttributes -} diff --git a/vendor/github.com/docker/machine/drivers/vmwarevsphere/vsphere_test.go b/vendor/github.com/docker/machine/drivers/vmwarevsphere/vsphere_test.go deleted file mode 100644 index d3d7af3..0000000 --- a/vendor/github.com/docker/machine/drivers/vmwarevsphere/vsphere_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package vmwarevsphere - -import ( - "testing" - - "github.com/docker/machine/libmachine/drivers" - "github.com/stretchr/testify/assert" -) - -func TestSetConfigFromFlags(t *testing.T) { - driver := NewDriver("default", "path") - - checkFlags := &drivers.CheckDriverOptions{ - FlagsValues: map[string]interface{}{}, - CreateFlags: driver.GetCreateFlags(), - } - - err := driver.SetConfigFromFlags(checkFlags) - - assert.NoError(t, err) - assert.Empty(t, checkFlags.InvalidFlags) -} diff --git a/vendor/github.com/docker/machine/experimental/README.md b/vendor/github.com/docker/machine/experimental/README.md deleted file mode 100644 index 633e33a..0000000 --- a/vendor/github.com/docker/machine/experimental/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# Docker Machine Experimental Features - -Docker Machine’s experimental features gives you access to bleeding edge features. By identifying experimental features, you can try out features early and give feedback to the Docker Machine maintainers. In this way, we hope to refine our feature designs by exposing them earlier to real-world usage. - -This page describes the experimental features in Docker Machine. Docker Machine is currently in beta. Neither it nor its experimental features are ready for production use. - -The information below describes each feature and the Github pull requests and -issues associated with it. If necessary, links are provided to additional -documentation on an issue. As an active Docker user and community member, -please feel free to provide any feedback on these features you wish. - -## Current experimental features - -Currently, you can experiment with [migrating a Boot2Docker created VM to Docker Machine](b2d_migration.md). Also, consider reviewing our [rough plan for the migration](b2d_migration_tasks.md). - -Additional experimental features include support for Red Hat, Debian, CentOS, Fedora, and RancherOS as base OSes. These features have no separate feature documentation. We simply encourage you to try them. - -## How to comment on an experimental feature - -Each feature's documentation includes a list of proposal pull requests or PRs associated with the feature. If you want to comment on or suggest a change to a feature, please add it to the existing feature PR. - -Issues or problems with a feature? Inquire for help on the `#docker-machine` IRC channel or in on the [Docker Google group](https://groups.google.com/forum/#!forum/docker-user). diff --git a/vendor/github.com/docker/machine/experimental/b2d_migration.md b/vendor/github.com/docker/machine/experimental/b2d_migration.md deleted file mode 100644 index 1fe85f9..0000000 --- a/vendor/github.com/docker/machine/experimental/b2d_migration.md +++ /dev/null @@ -1,62 +0,0 @@ -# Migrate from Boot2Docker CLI to Docker Machine - -This guide explains migrating from the Boot2Docker CLI to Docker Machine. - -This guide assumes basic knowledge of the Boot2Docker CLI and Docker Machine. If you are not familiar, please review those docs prior to migrating. - -There are a few differences between the Boot2Docker CLI commands and Machine. Please review the table below for the Boot2Docker command and the corresponding Machine command. You can also see details on Machine commands in the official [Docker Machine Docs](http://docs.docker.com/machine/#subcommands). - -# Migrating - -In order to migrate a Boot2Docker VM to Docker Machine, you must have Docker Machine installed. If you do not have Docker Machine, please see the [install docs](http://docs.docker.com/machine/#installation) before proceeding. - -> Note: when migrating to Docker Machine, this will also update Docker to the latest stable version - -To migrate a Boot2Docker VM, run the following command where `` is the name of your Boot2Docker VM and `` is the name of the new Machine (i.e. `dev`): - -> To get the name of your Boot2Docker VM, use the `boot2docker config` command. Default: `boot2docker-vm`. - - docker-machine create -d virtualbox --virtualbox-import-boot2docker-vm - -> Note: this will stop the Boot2Docker VM in order to safely copy the virtual disk - -You should see output similar to the following: - - $> docker-machine create -d virtualbox --virtualbox-import-boot2docker-vm boot2docker-vm dev - INFO[0000] Creating VirtualBox VM... - INFO[0001] Starting VirtualBox VM... - INFO[0001] Waiting for VM to start... - INFO[0035] "dev" has been created and is now the active machine. - INFO[0035] To point your Docker client at it, run this in your shell: eval "$(docker-machine env dev)" - -You now should have a Machine that contains all of the Docker data from the Boot2Docker VM. See the Docker Machine [usage docs](http://docs.docker.com/machine/#getting-started-with-docker-machine-using-a-local-vm) for details on working with Machine. - -# Cleanup - -When migrating a Boot2Docker VM to Docker Machine the Boot2Docker VM is left intact. Once you have verified that all of your Docker data (containers, images, etc) are in the new Machine, you can remove the Boot2Docker VM using `boot2docker delete`. - -# Command Comparison - -| boot2docker cli | machine | machine description | -| --------------- | ----------- | -------------------------------------------------------------------------------------- | -| init | create | creates a new docker host | -| up | start | starts a stopped machine | -| ssh | ssh | runs a command or interactive ssh session on the machine | -| save | - | n/a | -| down | stop | stops a running machine | -| poweroff | stop | stops a running machine | -| reset | restart | restarts a running machine | -| config | inspect (*) | shows details about machine | -| status | ls (**) | shows a list of all machines | -| info | inspect (*) | shows details about machine | -| ip | url (***) | shows the Docker URL for the machine | -| shellinit | env | shows the environment configuration needed to configure the Docker CLI for the machine | -| delete | rm | removes a machine | -| download | - | | -| upgrade | upgrade | upgrades Docker on the machine to the latest stable release | - -\* provides similar functionality but not exact - -** `ls` will show all machines including their status - -*** the `url` command reports the entire Docker URL including the IP / Hostname diff --git a/vendor/github.com/docker/machine/experimental/b2d_migration_tasks.md b/vendor/github.com/docker/machine/experimental/b2d_migration_tasks.md deleted file mode 100644 index 1e63363..0000000 --- a/vendor/github.com/docker/machine/experimental/b2d_migration_tasks.md +++ /dev/null @@ -1,49 +0,0 @@ - - -# Boot2Docker Migration - -This document is a rough guide to what will need to be completed to support -migrating from boot2docker-cli to Machine. It is not meant to be a user guide -but more so an internal guide to what we will want to support. - -## Existing Boot2Docker Instances - -We will need to import the disk to "migrate" the existing Docker data to the -new Machine. This should not be too much work as instead of creating the -virtual disk we will simply copy this one. From there, provisioning should -happen as normal (cert regeneration, option configuration, etc). - -## CLI - -Currently almost every b2d command has a comparable Machine command. I do not -feel we need to have the exact same naming but we will want to create a -migration user guide to inform the users of what is different. - -## Boot2Docker Host Alias - -Boot2Docker also modifies the local system host file to create a `boot2docker` -alias that can be used by the host system. We will need to decide if we want -to support this and, if so, how to implement. Perhaps local aliases for each -Machine name? - -## Installer and Initial Setup - -There is a Boot2Docker installer that assists the users in getting started. -It installs VirtualBox along with the b2d CLI. We will need something similar. -This will probably be part of a larger installation project with the various -Docker platform tools. - -## Updates - -Machine already supports the `upgrade` command to update the Machine instances. -I'm not sure if we want to add a mechanism to update the local Machine binary -and/or the Docker CLI binary as well. We will need to discuss. diff --git a/vendor/github.com/docker/machine/its/cli/create_rm_test.go b/vendor/github.com/docker/machine/its/cli/create_rm_test.go deleted file mode 100644 index dc00c8a..0000000 --- a/vendor/github.com/docker/machine/its/cli/create_rm_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package cli - -import ( - "testing" - - "github.com/docker/machine/its" -) - -func TestCreateRm(t *testing.T) { - test := its.NewTest(t) - defer test.TearDown() - - test.Run("non-existent driver fails", func() { - test.Machine("create -d bogus bogus").Should().Fail(`Driver "bogus" not found. Do you have the plugin binary "docker-machine-driver-bogus" accessible in your PATH?`) - }) - - test.Run("non-existent driver fails", func() { - test.Machine("create -d bogus bogus").Should().Fail(`Driver "bogus" not found. Do you have the plugin binary "docker-machine-driver-bogus" accessible in your PATH?`) - }) - - test.Run("create with no name fails", func() { - test.Machine("create -d none").Should().Fail(`Error: No machine name specified`) - }) - - test.Run("create with invalid name fails", func() { - test.Machine("create -d none --url none ∞").Should().Fail(`Error creating machine: Invalid hostname specified. Allowed hostname chars are: 0-9a-zA-Z . -`) - }) - - test.Run("create with invalid name fails", func() { - test.Machine("create -d none --url none -").Should().Fail(`Error creating machine: Invalid hostname specified. Allowed hostname chars are: 0-9a-zA-Z . -`) - }) - - test.Run("create with invalid name fails", func() { - test.Machine("create -d none --url none .").Should().Fail(`Error creating machine: Invalid hostname specified. Allowed hostname chars are: 0-9a-zA-Z . -`) - }) - - test.Run("create with invalid name fails", func() { - test.Machine("create -d none --url none ..").Should().Fail(`Error creating machine: Invalid hostname specified. Allowed hostname chars are: 0-9a-zA-Z . -`) - }) - - test.Run("create with weird but valid name succeeds", func() { - test.Machine("create -d none --url none a").Should().Succeed() - }) - - test.Run("fail with extra argument", func() { - test.Machine("create -d none --url none a extra").Should().Fail(`Invalid command line. Found extra arguments [extra]`) - }) - - test.Run("create with weird but valid name", func() { - test.Machine("create -d none --url none 0").Should().Succeed() - }) - - test.Run("rm with no name fails", func() { - test.Machine("rm -y").Should().Fail(`Error: Expected to get one or more machine names as arguments`) - }) - - test.Run("rm non existent machine fails", func() { - test.Machine("rm ∞ -y").Should().Fail(`Error removing host "∞": Docker machine "∞" does not exist.`) - }) - - test.Run("rm existing machine", func() { - test.Machine("rm 0 -y").Should().Succeed() - }) - - test.Run("rm ask user confirmation when -y is not provided", func() { - test.Machine("create -d none --url none ba").Should().Succeed() - test.Cmd("echo y | machine rm ba").Should().Succeed() - }) - - test.Run("rm deny user confirmation when -y is not provided", func() { - test.Machine("create -d none --url none ab").Should().Succeed() - test.Cmd("echo n | machine rm ab").Should().Succeed() - }) - - test.Run("rm never prompt user confirmation when -f is provided", func() { - test.Machine("create -d none --url none c").Should().Succeed() - test.Machine("rm -f c").Should().Succeed("Successfully removed c") - }) -} diff --git a/vendor/github.com/docker/machine/its/cli/driver_help_test.go b/vendor/github.com/docker/machine/its/cli/driver_help_test.go deleted file mode 100644 index ea69491..0000000 --- a/vendor/github.com/docker/machine/its/cli/driver_help_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package cli - -import ( - "testing" - - "github.com/docker/machine/its" -) - -func TestDriverHelp(t *testing.T) { - test := its.NewTest(t) - defer test.TearDown() - - test.SkipDriver("ci-test") - - test.Run("no --help flag or command specified", func() { - test.Machine("create -d $DRIVER").Should().Fail("Error: No machine name specified") - }) - - test.Run("-h flag specified", func() { - test.Machine("create -d $DRIVER -h").Should().Succeed(test.DriverName()) - }) - - test.Run("--help flag specified", func() { - test.Machine("create -d $DRIVER --help").Should().Succeed(test.DriverName()) - }) -} diff --git a/vendor/github.com/docker/machine/its/cli/help_test.go b/vendor/github.com/docker/machine/its/cli/help_test.go deleted file mode 100644 index 3a1d058..0000000 --- a/vendor/github.com/docker/machine/its/cli/help_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package cli - -import ( - "testing" - - "github.com/docker/machine/its" -) - -func TestHelp(t *testing.T) { - test := its.NewTest(t) - defer test.TearDown() - - test.Run("cli: show info", func() { - test.Machine("").Should().Succeed("Usage:", "Create and manage machines running Docker") - }) - - test.Run("cli: show active help", func() { - test.Machine("active -h").Should().Succeed("machine active") - }) - - test.Run("cli: show config help", func() { - test.Machine("config -h").Should().Succeed("machine config") - }) - - test.Run("cli: show create help", func() { - test.Machine("create -h").Should().Succeed("machine create") - }) - - test.Run("cli: show env help", func() { - test.Machine("env -h").Should().Succeed("machine env") - }) - - test.Run("cli: show inspect help", func() { - test.Machine("inspect -h").Should().Succeed("machine inspect") - }) - - test.Run("cli: show ip help", func() { - test.Machine("ip -h").Should().Succeed("machine ip") - }) - - test.Run("cli: show kill help", func() { - test.Machine("kill -h").Should().Succeed("machine kill") - }) - - test.Run("cli: show ls help", func() { - test.Machine("ls -h").Should().Succeed("machine ls") - }) - - test.Run("cli: show regenerate-certs help", func() { - test.Machine("regenerate-certs -h").Should().Succeed("machine regenerate-certs") - }) - - test.Run("cli: show restart help", func() { - test.Machine("restart -h").Should().Succeed("machine restart") - }) - - test.Run("cli: show rm help", func() { - test.Machine("rm -h").Should().Succeed("machine rm") - }) - - test.Run("cli: show scp help", func() { - test.Machine("scp -h").Should().Succeed("machine scp") - }) - - test.Run("cli: show ssh help", func() { - test.Machine("ssh -h").Should().Succeed("machine ssh") - }) - - test.Run("cli: show start help", func() { - test.Machine("start -h").Should().Succeed("machine start") - }) - - test.Run("cli: show status help", func() { - test.Machine("status -h").Should().Succeed("machine status") - }) - - test.Run("cli: show stop help", func() { - test.Machine("stop -h").Should().Succeed("machine stop") - }) - - test.Run("cli: show upgrade help", func() { - test.Machine("upgrade -h").Should().Succeed("machine upgrade") - }) - - test.Run("cli: show url help", func() { - test.Machine("url -h").Should().Succeed("machine url") - }) - - test.Run("cli: show version", func() { - test.Machine("-v").Should().Succeed("version") - }) - - test.Run("cli: show help", func() { - test.Machine("--help").Should().Succeed("Usage:") - }) -} diff --git a/vendor/github.com/docker/machine/its/cli/inspect_test.go b/vendor/github.com/docker/machine/its/cli/inspect_test.go deleted file mode 100644 index 6a632f2..0000000 --- a/vendor/github.com/docker/machine/its/cli/inspect_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package cli - -import ( - "testing" - - "github.com/docker/machine/its" -) - -func TestInspect(t *testing.T) { - test := its.NewTest(t) - defer test.TearDown() - - test.Run("inspect: show error in case of no args", func() { - test.Machine("inspect").Should().Fail(`Error: No machine name(s) specified and no "default" machine exists`) - }) -} diff --git a/vendor/github.com/docker/machine/its/cli/ls_test.go b/vendor/github.com/docker/machine/its/cli/ls_test.go deleted file mode 100644 index 239cd77..0000000 --- a/vendor/github.com/docker/machine/its/cli/ls_test.go +++ /dev/null @@ -1,189 +0,0 @@ -package cli - -import ( - "testing" - - "github.com/docker/machine/its" -) - -func TestLs(t *testing.T) { - test := its.NewTest(t) - defer test.TearDown() - - test.Run("setup", func() { - test.Machine("create -d none --url url5 --engine-label app=1 testmachine5").Should().Succeed() - test.Machine("create -d none --url url4 --engine-label foo=bar --engine-label app=1 testmachine4").Should().Succeed() - test.Machine("create -d none --url url3 testmachine3").Should().Succeed() - test.Machine("create -d none --url url2 testmachine2").Should().Succeed() - test.Machine("create -d none --url url1 testmachine").Should().Succeed() - }) - - test.Run("ls: no filter", func() { - test.Machine("ls").Should().Succeed(). - ContainLines(6). - MatchLine(0, "NAME[ ]+ACTIVE[ ]+DRIVER[ ]+STATE[ ]+URL[ ]+SWARM[ ]+DOCKER[ ]+ERRORS"). - MatchLine(1, "testmachine[ ]+-[ ]+none[ ]+Running[ ]+url1[ ]+Unknown[ ]+Unable to query docker version: .*"). - MatchLine(2, "testmachine2[ ]+-[ ]+none[ ]+Running[ ]+url2[ ]+Unknown[ ]+Unable to query docker version: .*"). - MatchLine(3, "testmachine3[ ]+-[ ]+none[ ]+Running[ ]+url3[ ]+Unknown[ ]+Unable to query docker version: .*"). - MatchLine(4, "testmachine4[ ]+-[ ]+none[ ]+Running[ ]+url4[ ]+Unknown[ ]+Unable to query docker version: .*"). - MatchLine(5, "testmachine5[ ]+-[ ]+none[ ]+Running[ ]+url5[ ]+Unknown[ ]+Unable to query docker version: .*") - }) - - test.Run("ls: filter on label", func() { - test.Machine("ls --filter label=foo=bar").Should().Succeed(). - ContainLines(2). - ContainLine(0, "NAME"). - ContainLine(1, "testmachine4") - }) - - test.Run("ls: multiple filters on label", func() { - test.Machine("ls --filter label=foo=bar --filter label=app=1").Should().Succeed(). - ContainLines(3). - ContainLine(0, "NAME"). - ContainLine(1, "testmachine4"). - ContainLine(2, "testmachine5") - }) - - test.Run("ls: non-existing filter on label", func() { - test.Machine("ls --filter label=invalid=filter").Should().Succeed(). - ContainLines(1). - ContainLine(0, "NAME") - }) - - test.Run("ls: filter on driver", func() { - test.Machine("ls --filter driver=none").Should().Succeed(). - ContainLines(6). - ContainLine(0, "NAME"). - ContainLine(1, "testmachine"). - ContainLine(2, "testmachine2"). - ContainLine(3, "testmachine3"). - ContainLine(4, "testmachine4"). - ContainLine(5, "testmachine5") - }) - - test.Run("ls: filter on driver", func() { - test.Machine("ls -q --filter driver=none").Should().Succeed(). - ContainLines(5). - EqualLine(0, "testmachine"). - EqualLine(1, "testmachine2"). - EqualLine(2, "testmachine3") - }) - - test.Run("ls: filter on state", func() { - test.Machine("ls --filter state=Running").Should().Succeed(). - ContainLines(6). - ContainLine(0, "NAME"). - ContainLine(1, "testmachine"). - ContainLine(2, "testmachine2"). - ContainLine(3, "testmachine3") - - test.Machine("ls -q --filter state=Running").Should().Succeed(). - ContainLines(5). - EqualLine(0, "testmachine"). - EqualLine(1, "testmachine2"). - EqualLine(2, "testmachine3") - - test.Machine("ls --filter state=None").Should().Succeed(). - ContainLines(1). - ContainLine(0, "NAME") - - test.Machine("ls --filter state=Paused").Should().Succeed(). - ContainLines(1). - ContainLine(0, "NAME") - - test.Machine("ls --filter state=Saved").Should().Succeed(). - ContainLines(1). - ContainLine(0, "NAME") - - test.Machine("ls --filter state=Stopped").Should().Succeed(). - ContainLines(1). - ContainLine(0, "NAME") - - test.Machine("ls --filter state=Stopping").Should().Succeed(). - ContainLines(1). - ContainLine(0, "NAME") - - test.Machine("ls --filter state=Starting").Should().Succeed(). - ContainLines(1). - ContainLine(0, "NAME") - - test.Machine("ls --filter state=Error").Should().Succeed(). - ContainLines(1). - ContainLine(0, "NAME") - }) - - test.Run("ls: filter on name", func() { - test.Machine("ls --filter name=testmachine2").Should().Succeed(). - ContainLines(2). - ContainLine(0, "NAME"). - ContainLine(1, "testmachine2") - - test.Machine("ls -q --filter name=testmachine3").Should().Succeed(). - ContainLines(1). - EqualLine(0, "testmachine3") - }) - - test.Run("ls: filter on name with regex", func() { - test.Machine("ls --filter name=^t.*e[3-5]").Should().Succeed(). - ContainLines(4). - ContainLine(0, "NAME"). - ContainLine(1, "testmachine3"). - ContainLine(2, "testmachine4"). - ContainLine(3, "testmachine5") - - test.Machine("ls -q --filter name=^t.*e[45]").Should().Succeed(). - ContainLines(2). - EqualLine(0, "testmachine4"). - EqualLine(1, "testmachine5") - }) - - test.Run("setup swarm", func() { - test.Machine("create -d none --url tcp://127.0.0.1:2375 --swarm --swarm-master --swarm-discovery token://deadbeef testswarm").Should().Succeed() - test.Machine("create -d none --url tcp://127.0.0.1:2375 --swarm --swarm-discovery token://deadbeef testswarm2").Should().Succeed() - test.Machine("create -d none --url tcp://127.0.0.1:2375 --swarm --swarm-discovery token://deadbeef testswarm3").Should().Succeed() - }) - - test.Run("ls: filter on swarm", func() { - test.Machine("ls --filter swarm=testswarm").Should().Succeed(). - ContainLines(4). - ContainLine(0, "NAME"). - ContainLine(1, "testswarm"). - ContainLine(2, "testswarm2"). - ContainLine(3, "testswarm3") - }) - - test.Run("ls: multi filter", func() { - test.Machine("ls -q --filter swarm=testswarm --filter name=^t.*e --filter driver=none --filter state=Running").Should().Succeed(). - ContainLines(3). - EqualLine(0, "testswarm"). - EqualLine(1, "testswarm2"). - EqualLine(2, "testswarm3") - }) - - test.Run("ls: format on driver", func() { - test.Machine("ls --format {{.DriverName}}").Should().Succeed(). - ContainLines(8). - EqualLine(0, "none"). - EqualLine(1, "none"). - EqualLine(2, "none"). - EqualLine(3, "none"). - EqualLine(4, "none"). - EqualLine(5, "none"). - EqualLine(6, "none"). - EqualLine(7, "none") - }) - - test.Run("ls: format on name and driver", func() { - test.Machine("ls --format 'table {{.Name}}: {{.DriverName}}'").Should().Succeed(). - ContainLines(9). - ContainLine(0, "NAME"). - EqualLine(1, "testmachine: none"). - EqualLine(2, "testmachine2: none"). - EqualLine(3, "testmachine3: none"). - EqualLine(4, "testmachine4: none"). - EqualLine(5, "testmachine5: none"). - EqualLine(6, "testswarm: none"). - EqualLine(7, "testswarm2: none"). - EqualLine(8, "testswarm3: none") - }) -} diff --git a/vendor/github.com/docker/machine/its/cli/status_test.go b/vendor/github.com/docker/machine/its/cli/status_test.go deleted file mode 100644 index 8bea4c0..0000000 --- a/vendor/github.com/docker/machine/its/cli/status_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package cli - -import ( - "testing" - - "github.com/docker/machine/its" -) - -func TestStatus(t *testing.T) { - test := its.NewTest(t) - defer test.TearDown() - - test.Run("status: show error in case of no args", func() { - test.Machine("status").Should().Fail(`Error: No machine name(s) specified and no "default" machine exists`) - }) -} diff --git a/vendor/github.com/docker/machine/its/cli/url_test.go b/vendor/github.com/docker/machine/its/cli/url_test.go deleted file mode 100644 index cd46a5b..0000000 --- a/vendor/github.com/docker/machine/its/cli/url_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package cli - -import ( - "testing" - - "github.com/docker/machine/its" -) - -func TestUrl(t *testing.T) { - test := its.NewTest(t) - defer test.TearDown() - - test.Run("url: show error in case of no args", func() { - test.Machine("url").Should().Fail(`Error: No machine name(s) specified and no "default" machine exists`) - }) -} diff --git a/vendor/github.com/docker/machine/its/tester.go b/vendor/github.com/docker/machine/its/tester.go deleted file mode 100644 index b5857e5..0000000 --- a/vendor/github.com/docker/machine/its/tester.go +++ /dev/null @@ -1,363 +0,0 @@ -package its - -import ( - "os/exec" - "regexp" - "strings" - "testing" - - "io/ioutil" - - "os" - - "fmt" - - "path/filepath" - "runtime" -) - -var ( - regexpCommandLine = regexp.MustCompile("('[^']*')|(\\S+)") -) - -type IntegrationTest interface { - RequireDriver(driverName string) - - SkipDriver(driverName string) - - SkipDrivers(driverNames ...string) - - ForceDriver(driverName string) - - Run(description string, action func()) - - Cmd(commandLine string) IntegrationTest - - Machine(commandLine string) IntegrationTest - - DriverName() string - - Should() Assertions - - TearDown() -} - -type Assertions interface { - Succeed(messages ...string) Assertions - - Fail(errorMessages ...string) Assertions - - ContainLines(count int) Assertions - - ContainLine(index int, text string) Assertions - - MatchLine(index int, template string) Assertions - - EqualLine(index int, text string) Assertions -} - -func NewTest(t *testing.T) IntegrationTest { - storagePath, _ := ioutil.TempDir("", "docker") - - return &dockerMachineTest{ - t: t, - storagePath: storagePath, - } -} - -type dockerMachineTest struct { - t *testing.T - storagePath string - dockerMachineBinary string - description string - skip bool - rawOutput string - lines []string - err error - fatal bool - failed bool -} - -func (dmt *dockerMachineTest) RequireDriver(driverName string) { - dmt.skipIf(dmt.DriverName() != driverName) -} - -func (dmt *dockerMachineTest) SkipDriver(driverName string) { - dmt.skipIf(dmt.DriverName() == driverName) -} - -func (dmt *dockerMachineTest) SkipDrivers(driverNames ...string) { - for _, driverName := range driverNames { - dmt.skipIf(dmt.DriverName() == driverName) - } -} - -func (dmt *dockerMachineTest) ForceDriver(driverName string) { - os.Setenv("DRIVER", driverName) -} - -func (dmt *dockerMachineTest) skipIf(condition bool) { - if condition { - dmt.skip = true - } -} - -func (dmt *dockerMachineTest) Run(description string, action func()) { - dmt.description = description - dmt.rawOutput = "" - dmt.lines = nil - dmt.err = nil - dmt.failed = false - - if dmt.skip { - fmt.Printf("%s %s\n", yellow("[SKIP]"), description) - } else { - fmt.Printf("%s %s", yellow("[..]"), description) - action() - - if dmt.fatal || dmt.failed { - fmt.Printf("\r%s %s\n", red("[KO]"), description) - } else { - fmt.Printf("\r%s %s\n", green("[OK]"), description) - } - } -} - -func red(message string) string { - if runtime.GOOS == "windows" { - return message - } - return "\033[1;31m" + message + "\033[0m" -} - -func green(message string) string { - if runtime.GOOS == "windows" { - return message - } - return "\033[1;32m" + message + "\033[0m" -} - -func yellow(message string) string { - if runtime.GOOS == "windows" { - return message - } - return "\033[1;33m" + message + "\033[0m" -} - -func (dmt *dockerMachineTest) DriverName() string { - driver := os.Getenv("DRIVER") - if driver != "" { - return driver - } - - return "virtualbox" -} - -func (dmt *dockerMachineTest) Should() Assertions { - return dmt -} - -func (dmt *dockerMachineTest) testedBinary() string { - if dmt.dockerMachineBinary != "" { - return dmt.dockerMachineBinary - } - - var binary string - if runtime.GOOS == "windows" { - binary = "docker-machine.exe" - } else { - binary = "docker-machine" - } - - _, file, _, _ := runtime.Caller(0) - dir := filepath.Dir(file) - - for dir != "/" { - path := filepath.Join(dir, "bin", binary) - - _, err := os.Stat(path) - if err == nil { - dmt.dockerMachineBinary = path - return path - } - - dir = filepath.Dir(dir) - } - - if !dmt.fatal { - dmt.fatal = true - dmt.t.Errorf("Binary not found: %s", binary) - } - - return "" -} - -func (dmt *dockerMachineTest) Cmd(commandLine string) IntegrationTest { - if dmt.fatal { - return dmt - } - - commandLine = dmt.replaceDriver(commandLine) - commandLine = dmt.replaceMachinePath(commandLine) - - return dmt.cmd("bash", "-c", commandLine) -} - -func (dmt *dockerMachineTest) Machine(commandLine string) IntegrationTest { - if dmt.fatal { - return dmt - } - - commandLine = dmt.replaceDriver(commandLine) - - return dmt.cmd(dmt.testedBinary(), parseFields(commandLine)...) -} - -func (dmt *dockerMachineTest) cmd(command string, args ...string) IntegrationTest { - cmd := exec.Command(command, args...) - cmd.Env = append(os.Environ(), "MACHINE_STORAGE_PATH="+dmt.storagePath) - - combinedOutput, err := cmd.CombinedOutput() - - dmt.rawOutput = string(combinedOutput) - dmt.lines = strings.Split(strings.TrimSpace(dmt.rawOutput), "\n") - dmt.err = err - - return dmt -} - -func (dmt *dockerMachineTest) replaceMachinePath(commandLine string) string { - return strings.Replace(commandLine, "machine", dmt.testedBinary(), -1) -} - -func (dmt *dockerMachineTest) replaceDriver(commandLine string) string { - return strings.Replace(commandLine, "$DRIVER", dmt.DriverName(), -1) -} - -func parseFields(commandLine string) []string { - fields := regexpCommandLine.FindAllString(commandLine, -1) - - for i := range fields { - if len(fields[i]) > 2 && strings.HasPrefix(fields[i], "'") && strings.HasSuffix(fields[i], "'") { - fields[i] = fields[i][1 : len(fields[i])-1] - } - } - - return fields -} - -func (dmt *dockerMachineTest) TearDown() { - machines := filepath.Join(dmt.storagePath, "machines") - - dirs, _ := ioutil.ReadDir(machines) - for _, dir := range dirs { - dmt.Cmd("machine rm -f " + dir.Name()) - } - - os.RemoveAll(dmt.storagePath) -} - -func (dmt *dockerMachineTest) ContainLines(count int) Assertions { - if dmt.fatal { - return dmt - } - - if count != len(dmt.lines) { - return dmt.failExpected("%d lines but got %d\n%s", count, len(dmt.lines), dmt.rawOutput) - } - - return dmt -} - -func (dmt *dockerMachineTest) ContainLine(index int, text string) Assertions { - if dmt.fatal { - return dmt - } - - if index >= len(dmt.lines) { - return dmt.failExpected("at least %d lines\nGot %d", index+1, len(dmt.lines)) - } - - if !strings.Contains(dmt.lines[index], text) { - return dmt.failExpected("line %d to contain '%s'\nGot '%s'", index, text, dmt.lines[index]) - } - - return dmt -} - -func (dmt *dockerMachineTest) MatchLine(index int, template string) Assertions { - if dmt.fatal { - return dmt - } - - if index >= len(dmt.lines) { - return dmt.failExpected("at least %d lines\nGot %d", index+1, len(dmt.lines)) - } - - if !regexp.MustCompile(template).MatchString(dmt.lines[index]) { - return dmt.failExpected("line %d to match '%s'\nGot '%s'", index, template, dmt.lines[index]) - } - - return dmt -} - -func (dmt *dockerMachineTest) EqualLine(index int, text string) Assertions { - if dmt.fatal { - return dmt - } - - if index >= len(dmt.lines) { - return dmt.failExpected("at least %d lines\nGot %d", index+1, len(dmt.lines)) - } - - if text != dmt.lines[index] { - return dmt.failExpected("line %d to be '%s'\nGot '%s'", index, text, dmt.lines[index]) - } - - return dmt -} - -func (dmt *dockerMachineTest) Succeed(messages ...string) Assertions { - if dmt.fatal { - return dmt - } - - if dmt.err != nil { - return dmt.failExpected("to succeed\nFailed with %s\n%s", dmt.err, dmt.rawOutput) - } - - for _, message := range messages { - if !strings.Contains(dmt.rawOutput, message) { - return dmt.failExpected("output to contain '%s'\nGot '%s'", message, dmt.rawOutput) - } - } - - return dmt -} - -func (dmt *dockerMachineTest) Fail(errorMessages ...string) Assertions { - if dmt.fatal { - return dmt - } - - if dmt.err == nil { - return dmt.failExpected("to fail\nGot success\n%s", dmt.rawOutput) - } - - for _, message := range errorMessages { - if !strings.Contains(dmt.rawOutput, message) { - return dmt.failExpected("output to contain '%s'\nGot '%s'", message, dmt.rawOutput) - } - } - - return dmt -} - -func (dmt *dockerMachineTest) failExpected(message string, args ...interface{}) Assertions { - allArgs := append([]interface{}{dmt.description}, args...) - - dmt.failed = true - dmt.t.Errorf("%s\nExpected "+message, allArgs...) - - return dmt -} diff --git a/vendor/github.com/docker/machine/its/thirdparty/commands_test.go b/vendor/github.com/docker/machine/its/thirdparty/commands_test.go deleted file mode 100644 index 945ece7..0000000 --- a/vendor/github.com/docker/machine/its/thirdparty/commands_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package thirdparty - -import ( - "testing" - - "github.com/docker/machine/its" -) - -func TestThirdPartyCompatibility(t *testing.T) { - test := its.NewTest(t) - defer test.TearDown() - - test.RequireDriver("ci-test") - - test.Run("create", func() { - test.Machine("create -d $DRIVER --url url default").Should().Succeed() - }) - - test.Run("ls", func() { - test.Machine("ls -q").Should().Succeed().ContainLines(1).EqualLine(0, "default") - }) - - test.Run("url", func() { - test.Machine("url default").Should().Succeed("url") - }) - - test.Run("status", func() { - test.Machine("status default").Should().Succeed("Running") - }) - - test.Run("rm", func() { - test.Machine("rm -y default").Should().Succeed() - }) -} diff --git a/vendor/github.com/docker/machine/libmachine/auth/auth.go b/vendor/github.com/docker/machine/libmachine/auth/auth.go deleted file mode 100644 index 86ae79d..0000000 --- a/vendor/github.com/docker/machine/libmachine/auth/auth.go +++ /dev/null @@ -1,18 +0,0 @@ -package auth - -type Options struct { - CertDir string - CaCertPath string - CaPrivateKeyPath string - CaCertRemotePath string - ServerCertPath string - ServerKeyPath string - ClientKeyPath string - ServerCertRemotePath string - ServerKeyRemotePath string - ClientCertPath string - ServerCertSANs []string - // StorePath is left in for historical reasons, but not really meant to - // be used directly. - StorePath string -} diff --git a/vendor/github.com/docker/machine/libmachine/cert/bootstrap.go b/vendor/github.com/docker/machine/libmachine/cert/bootstrap.go deleted file mode 100644 index ec5fe0e..0000000 --- a/vendor/github.com/docker/machine/libmachine/cert/bootstrap.go +++ /dev/null @@ -1,87 +0,0 @@ -package cert - -import ( - "errors" - "fmt" - "os" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" -) - -func BootstrapCertificates(authOptions *auth.Options) error { - certDir := authOptions.CertDir - caCertPath := authOptions.CaCertPath - caPrivateKeyPath := authOptions.CaPrivateKeyPath - clientCertPath := authOptions.ClientCertPath - clientKeyPath := authOptions.ClientKeyPath - - // TODO: I'm not super happy about this use of "org", the user should - // have to specify it explicitly instead of implicitly basing it on - // $USER. - caOrg := mcnutils.GetUsername() - org := caOrg + "." - - bits := 2048 - - if _, err := os.Stat(certDir); err != nil { - if os.IsNotExist(err) { - if err := os.MkdirAll(certDir, 0700); err != nil { - return fmt.Errorf("Creating machine certificate dir failed: %s", err) - } - } else { - return err - } - } - - if _, err := os.Stat(caCertPath); os.IsNotExist(err) { - log.Infof("Creating CA: %s", caCertPath) - - // check if the key path exists; if so, error - if _, err := os.Stat(caPrivateKeyPath); err == nil { - return errors.New("certificate authority key already exists") - } - - if err := GenerateCACertificate(caCertPath, caPrivateKeyPath, caOrg, bits); err != nil { - return fmt.Errorf("Generating CA certificate failed: %s", err) - } - } - - if _, err := os.Stat(clientCertPath); os.IsNotExist(err) { - log.Infof("Creating client certificate: %s", clientCertPath) - - if _, err := os.Stat(certDir); err != nil { - if os.IsNotExist(err) { - if err := os.Mkdir(certDir, 0700); err != nil { - return fmt.Errorf("failure creating machine client cert dir: %s", err) - } - } else { - return err - } - } - - // check if the key path exists; if so, error - if _, err := os.Stat(clientKeyPath); err == nil { - return errors.New("client key already exists") - } - - // Used to generate the client certificate. - certOptions := &Options{ - Hosts: []string{""}, - CertFile: clientCertPath, - KeyFile: clientKeyPath, - CAFile: caCertPath, - CAKeyFile: caPrivateKeyPath, - Org: org, - Bits: bits, - SwarmMaster: false, - } - - if err := GenerateCert(certOptions); err != nil { - return fmt.Errorf("failure generating client certificate: %s", err) - } - } - - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/cert/cert.go b/vendor/github.com/docker/machine/libmachine/cert/cert.go deleted file mode 100644 index eaa08a0..0000000 --- a/vendor/github.com/docker/machine/libmachine/cert/cert.go +++ /dev/null @@ -1,269 +0,0 @@ -package cert - -import ( - "crypto/rand" - "crypto/rsa" - "crypto/tls" - "crypto/x509" - "crypto/x509/pkix" - "encoding/pem" - "io/ioutil" - "math/big" - "net" - "os" - "time" - - "errors" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/log" -) - -var defaultGenerator = NewX509CertGenerator() - -type Options struct { - Hosts []string - CertFile, KeyFile, CAFile, CAKeyFile, Org string - Bits int - SwarmMaster bool -} - -type Generator interface { - GenerateCACertificate(certFile, keyFile, org string, bits int) error - GenerateCert(opts *Options) error - ReadTLSConfig(addr string, authOptions *auth.Options) (*tls.Config, error) - ValidateCertificate(addr string, authOptions *auth.Options) (bool, error) -} - -type X509CertGenerator struct{} - -func NewX509CertGenerator() Generator { - return &X509CertGenerator{} -} - -func GenerateCACertificate(certFile, keyFile, org string, bits int) error { - return defaultGenerator.GenerateCACertificate(certFile, keyFile, org, bits) -} - -func GenerateCert(opts *Options) error { - return defaultGenerator.GenerateCert(opts) -} - -func ValidateCertificate(addr string, authOptions *auth.Options) (bool, error) { - return defaultGenerator.ValidateCertificate(addr, authOptions) -} - -func ReadTLSConfig(addr string, authOptions *auth.Options) (*tls.Config, error) { - return defaultGenerator.ReadTLSConfig(addr, authOptions) -} - -func SetCertGenerator(cg Generator) { - defaultGenerator = cg -} - -func (xcg *X509CertGenerator) getTLSConfig(caCert, cert, key []byte, allowInsecure bool) (*tls.Config, error) { - // TLS config - var tlsConfig tls.Config - tlsConfig.InsecureSkipVerify = allowInsecure - certPool := x509.NewCertPool() - - ok := certPool.AppendCertsFromPEM(caCert) - if !ok { - return &tlsConfig, errors.New("There was an error reading certificate") - } - - tlsConfig.RootCAs = certPool - keypair, err := tls.X509KeyPair(cert, key) - if err != nil { - return &tlsConfig, err - } - tlsConfig.Certificates = []tls.Certificate{keypair} - - return &tlsConfig, nil -} - -func (xcg *X509CertGenerator) newCertificate(org string) (*x509.Certificate, error) { - now := time.Now() - // need to set notBefore slightly in the past to account for time - // skew in the VMs otherwise the certs sometimes are not yet valid - notBefore := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute()-5, 0, 0, time.Local) - notAfter := notBefore.Add(time.Hour * 24 * 1080) - - serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) - serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) - if err != nil { - return nil, err - } - - return &x509.Certificate{ - SerialNumber: serialNumber, - Subject: pkix.Name{ - Organization: []string{org}, - }, - NotBefore: notBefore, - NotAfter: notAfter, - - KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageKeyAgreement, - BasicConstraintsValid: true, - }, nil - -} - -// GenerateCACertificate generates a new certificate authority from the specified org -// and bit size and stores the resulting certificate and key file -// in the arguments. -func (xcg *X509CertGenerator) GenerateCACertificate(certFile, keyFile, org string, bits int) error { - template, err := xcg.newCertificate(org) - if err != nil { - return err - } - - template.IsCA = true - template.KeyUsage |= x509.KeyUsageCertSign - template.KeyUsage |= x509.KeyUsageKeyEncipherment - template.KeyUsage |= x509.KeyUsageKeyAgreement - - priv, err := rsa.GenerateKey(rand.Reader, bits) - if err != nil { - return err - } - - derBytes, err := x509.CreateCertificate(rand.Reader, template, template, &priv.PublicKey, priv) - if err != nil { - return err - } - - certOut, err := os.Create(certFile) - if err != nil { - return err - } - - pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) - certOut.Close() - - keyOut, err := os.OpenFile(keyFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - return err - - } - - pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)}) - keyOut.Close() - - return nil -} - -// GenerateCert generates a new certificate signed using the provided -// certificate authority files and stores the result in the certificate -// file and key provided. The provided host names are set to the -// appropriate certificate fields. -func (xcg *X509CertGenerator) GenerateCert(opts *Options) error { - template, err := xcg.newCertificate(opts.Org) - if err != nil { - return err - } - // client - if len(opts.Hosts) == 1 && opts.Hosts[0] == "" { - template.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth} - template.KeyUsage = x509.KeyUsageDigitalSignature - } else { // server - template.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth} - if opts.SwarmMaster { - // Extend the Swarm master's server certificate - // permissions to also be able to connect to downstream - // nodes as a client. - template.ExtKeyUsage = append(template.ExtKeyUsage, x509.ExtKeyUsageClientAuth) - } - for _, h := range opts.Hosts { - if ip := net.ParseIP(h); ip != nil { - template.IPAddresses = append(template.IPAddresses, ip) - } else { - template.DNSNames = append(template.DNSNames, h) - } - } - } - - tlsCert, err := tls.LoadX509KeyPair(opts.CAFile, opts.CAKeyFile) - if err != nil { - return err - } - - priv, err := rsa.GenerateKey(rand.Reader, opts.Bits) - if err != nil { - return err - } - - x509Cert, err := x509.ParseCertificate(tlsCert.Certificate[0]) - if err != nil { - return err - } - - derBytes, err := x509.CreateCertificate(rand.Reader, template, x509Cert, &priv.PublicKey, tlsCert.PrivateKey) - if err != nil { - return err - } - - certOut, err := os.Create(opts.CertFile) - if err != nil { - return err - } - - pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) - certOut.Close() - - keyOut, err := os.OpenFile(opts.KeyFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - return err - } - - pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)}) - keyOut.Close() - - return nil -} - -// ReadTLSConfig reads the tls config for a machine. -func (xcg *X509CertGenerator) ReadTLSConfig(addr string, authOptions *auth.Options) (*tls.Config, error) { - caCertPath := authOptions.CaCertPath - clientCertPath := authOptions.ClientCertPath - clientKeyPath := authOptions.ClientKeyPath - - log.Debugf("Reading CA certificate from %s", caCertPath) - caCert, err := ioutil.ReadFile(caCertPath) - if err != nil { - return nil, err - } - - log.Debugf("Reading client certificate from %s", clientCertPath) - clientCert, err := ioutil.ReadFile(clientCertPath) - if err != nil { - return nil, err - } - - log.Debugf("Reading client key from %s", clientKeyPath) - clientKey, err := ioutil.ReadFile(clientKeyPath) - if err != nil { - return nil, err - } - - return xcg.getTLSConfig(caCert, clientCert, clientKey, false) -} - -// ValidateCertificate validate the certificate installed on the vm. -func (xcg *X509CertGenerator) ValidateCertificate(addr string, authOptions *auth.Options) (bool, error) { - tlsConfig, err := xcg.ReadTLSConfig(addr, authOptions) - if err != nil { - return false, err - } - - dialer := &net.Dialer{ - Timeout: time.Second * 20, - } - - _, err = tls.DialWithDialer(dialer, "tcp", addr, tlsConfig) - if err != nil { - return false, err - } - - return true, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/cert/cert_test.go b/vendor/github.com/docker/machine/libmachine/cert/cert_test.go deleted file mode 100644 index f5b5ecb..0000000 --- a/vendor/github.com/docker/machine/libmachine/cert/cert_test.go +++ /dev/null @@ -1,81 +0,0 @@ -package cert - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func TestGenerateCACertificate(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "machine-test-") - if err != nil { - t.Fatal(err) - } - // cleanup - defer os.RemoveAll(tmpDir) - - caCertPath := filepath.Join(tmpDir, "ca.pem") - caKeyPath := filepath.Join(tmpDir, "key.pem") - testOrg := "test-org" - bits := 2048 - if err := GenerateCACertificate(caCertPath, caKeyPath, testOrg, bits); err != nil { - t.Fatal(err) - } - - if _, err := os.Stat(caCertPath); err != nil { - t.Fatal(err) - } - if _, err := os.Stat(caKeyPath); err != nil { - t.Fatal(err) - } -} - -func TestGenerateCert(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "machine-test-") - if err != nil { - t.Fatal(err) - } - // cleanup - defer os.RemoveAll(tmpDir) - - caCertPath := filepath.Join(tmpDir, "ca.pem") - caKeyPath := filepath.Join(tmpDir, "key.pem") - certPath := filepath.Join(tmpDir, "cert.pem") - keyPath := filepath.Join(tmpDir, "cert-key.pem") - testOrg := "test-org" - bits := 2048 - if err := GenerateCACertificate(caCertPath, caKeyPath, testOrg, bits); err != nil { - t.Fatal(err) - } - - if _, err := os.Stat(caCertPath); err != nil { - t.Fatal(err) - } - if _, err := os.Stat(caKeyPath); err != nil { - t.Fatal(err) - } - - opts := &Options{ - Hosts: []string{}, - CertFile: certPath, - CAKeyFile: caKeyPath, - CAFile: caCertPath, - KeyFile: keyPath, - Org: testOrg, - Bits: bits, - SwarmMaster: false, - } - - if err := GenerateCert(opts); err != nil { - t.Fatal(err) - } - - if _, err := os.Stat(certPath); err != nil { - t.Fatalf("certificate not created at %s", certPath) - } - - if _, err := os.Stat(keyPath); err != nil { - t.Fatalf("key not created at %s", keyPath) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/check/check.go b/vendor/github.com/docker/machine/libmachine/check/check.go deleted file mode 100644 index 49fbce2..0000000 --- a/vendor/github.com/docker/machine/libmachine/check/check.go +++ /dev/null @@ -1,118 +0,0 @@ -package check - -import ( - "errors" - "fmt" - "net/url" - "strings" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/cert" - "github.com/docker/machine/libmachine/host" -) - -var ( - DefaultConnChecker ConnChecker - ErrSwarmNotStarted = errors.New("Connection to Swarm cannot be checked but the certs are valid. Maybe swarm is not started") -) - -func init() { - DefaultConnChecker = &MachineConnChecker{} -} - -// ErrCertInvalid for when the cert is computed to be invalid. -type ErrCertInvalid struct { - wrappedErr error - hostURL string -} - -func (e ErrCertInvalid) Error() string { - return fmt.Sprintf(`There was an error validating certificates for host %q: %s -You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'. -Be advised that this will trigger a Docker daemon restart which might stop running containers. -`, e.hostURL, e.wrappedErr) -} - -type ConnChecker interface { - Check(*host.Host, bool) (dockerHost string, authOptions *auth.Options, err error) -} - -type MachineConnChecker struct{} - -func (mcc *MachineConnChecker) Check(h *host.Host, swarm bool) (string, *auth.Options, error) { - dockerHost, err := h.Driver.GetURL() - if err != nil { - return "", &auth.Options{}, err - } - - dockerURL := dockerHost - if swarm { - dockerURL, err = parseSwarm(dockerHost, h) - if err != nil { - return "", &auth.Options{}, err - } - } - - u, err := url.Parse(dockerURL) - if err != nil { - return "", &auth.Options{}, fmt.Errorf("Error parsing URL: %s", err) - } - - authOptions := h.AuthOptions() - - if err := checkCert(u.Host, authOptions); err != nil { - if swarm { - // Connection to the swarm port cannot be checked. Maybe it's just the swarm containers that are down - // TODO: check the containers and restart them - // Let's check the non-swarm connection to give a better error message to the user. - if _, _, err := mcc.Check(h, false); err == nil { - return "", &auth.Options{}, ErrSwarmNotStarted - } - } - - return "", &auth.Options{}, fmt.Errorf("Error checking and/or regenerating the certs: %s", err) - } - - return dockerURL, authOptions, nil -} - -func checkCert(hostURL string, authOptions *auth.Options) error { - valid, err := cert.ValidateCertificate(hostURL, authOptions) - if !valid || err != nil { - return ErrCertInvalid{ - wrappedErr: err, - hostURL: hostURL, - } - } - - return nil -} - -// TODO: This could use a unit test. -func parseSwarm(hostURL string, h *host.Host) (string, error) { - swarmOptions := h.HostOptions.SwarmOptions - - if !swarmOptions.Master { - return "", fmt.Errorf("%q is not a swarm master. The --swarm flag is intended for use with swarm masters", h.Name) - } - - u, err := url.Parse(swarmOptions.Host) - if err != nil { - return "", fmt.Errorf("There was an error parsing the url: %s", err) - } - parts := strings.Split(u.Host, ":") - swarmPort := parts[1] - - // get IP of machine to replace in case swarm host is 0.0.0.0 - mURL, err := url.Parse(hostURL) - if err != nil { - return "", fmt.Errorf("There was an error parsing the url: %s", err) - } - - mParts := strings.Split(mURL.Host, ":") - machineIP := mParts[0] - - hostURL = fmt.Sprintf("tcp://%s:%s", machineIP, swarmPort) - - return hostURL, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/check/check_test.go b/vendor/github.com/docker/machine/libmachine/check/check_test.go deleted file mode 100644 index 948c08a..0000000 --- a/vendor/github.com/docker/machine/libmachine/check/check_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package check - -import ( - "errors" - "testing" - - "crypto/tls" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/cert" - "github.com/stretchr/testify/assert" -) - -type FakeValidateCertificate struct { - IsValid bool - Err error -} - -type FakeCertGenerator struct { - fakeValidateCertificate *FakeValidateCertificate -} - -func (fcg FakeCertGenerator) GenerateCACertificate(certFile, keyFile, org string, bits int) error { - return nil -} - -func (fcg FakeCertGenerator) GenerateCert(opts *cert.Options) error { - return nil -} - -func (fcg FakeCertGenerator) ValidateCertificate(addr string, authOptions *auth.Options) (bool, error) { - return fcg.fakeValidateCertificate.IsValid, fcg.fakeValidateCertificate.Err -} - -func (fcg FakeCertGenerator) ReadTLSConfig(addr string, authOptions *auth.Options) (*tls.Config, error) { - return nil, nil -} - -func TestCheckCert(t *testing.T) { - errCertsExpired := errors.New("Certs have expired") - - cases := []struct { - hostURL string - authOptions *auth.Options - valid bool - checkErr error - expectedErr error - }{ - {"192.168.99.100:2376", &auth.Options{}, true, nil, nil}, - {"192.168.99.100:2376", &auth.Options{}, false, nil, ErrCertInvalid{wrappedErr: nil, hostURL: "192.168.99.100:2376"}}, - {"192.168.99.100:2376", &auth.Options{}, false, errCertsExpired, ErrCertInvalid{wrappedErr: errCertsExpired, hostURL: "192.168.99.100:2376"}}, - } - - for _, c := range cases { - fcg := FakeCertGenerator{fakeValidateCertificate: &FakeValidateCertificate{c.valid, c.checkErr}} - cert.SetCertGenerator(fcg) - err := checkCert(c.hostURL, c.authOptions) - assert.Equal(t, c.expectedErr, err) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/crashreport/crash_report.go b/vendor/github.com/docker/machine/libmachine/crashreport/crash_report.go deleted file mode 100644 index 1ac24a9..0000000 --- a/vendor/github.com/docker/machine/libmachine/crashreport/crash_report.go +++ /dev/null @@ -1,149 +0,0 @@ -package crashreport - -import ( - "fmt" - "os" - "runtime" - - "bytes" - - "os/exec" - - "path/filepath" - - "errors" - - "io/ioutil" - - "github.com/bugsnag/bugsnag-go" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/shell" - "github.com/docker/machine/version" -) - -const ( - defaultAPIKey = "a9697f9a010c33ee218a65e5b1f3b0c1" - noreportAPIKey = "no-report" -) - -type CrashReporter interface { - Send(err CrashError) error -} - -// CrashError describes an error that should be reported to bugsnag -type CrashError struct { - Cause error - Command string - Context string - DriverName string - LogFilePath string -} - -func (e CrashError) Error() string { - return e.Cause.Error() -} - -type BugsnagCrashReporter struct { - baseDir string - apiKey string -} - -// NewCrashReporter creates a new bugsnag based CrashReporter. Needs an apiKey. -var NewCrashReporter = func(baseDir string, apiKey string) CrashReporter { - if apiKey == "" { - apiKey = defaultAPIKey - } - - return &BugsnagCrashReporter{ - baseDir: baseDir, - apiKey: apiKey, - } -} - -// Send sends a crash report to bugsnag via an http call. -func (r *BugsnagCrashReporter) Send(err CrashError) error { - if r.noReportFileExist() || r.apiKey == noreportAPIKey { - log.Debug("Opting out of crash reporting.") - return nil - } - - if r.apiKey == "" { - return errors.New("no api key has been set") - } - - bugsnag.Configure(bugsnag.Configuration{ - APIKey: r.apiKey, - // XXX we need to abuse bugsnag metrics to get the OS/ARCH information as a usable filter - // Can do that with either "stage" or "hostname" - ReleaseStage: fmt.Sprintf("%s (%s)", runtime.GOOS, runtime.GOARCH), - ProjectPackages: []string{"github.com/docker/machine/[^v]*"}, - AppVersion: version.FullVersion(), - Synchronous: true, - PanicHandler: func() {}, - Logger: new(logger), - }) - - metaData := bugsnag.MetaData{} - - metaData.Add("app", "compiler", fmt.Sprintf("%s (%s)", runtime.Compiler, runtime.Version())) - metaData.Add("device", "os", runtime.GOOS) - metaData.Add("device", "arch", runtime.GOARCH) - - detectRunningShell(&metaData) - detectUname(&metaData) - detectOSVersion(&metaData) - addFile(err.LogFilePath, &metaData) - - var buffer bytes.Buffer - for _, message := range log.History() { - buffer.WriteString(message + "\n") - } - metaData.Add("history", "trace", buffer.String()) - - return bugsnag.Notify(err.Cause, metaData, bugsnag.SeverityError, bugsnag.Context{String: err.Context}, bugsnag.ErrorClass{Name: fmt.Sprintf("%s/%s", err.DriverName, err.Command)}) -} - -func (r *BugsnagCrashReporter) noReportFileExist() bool { - optOutFilePath := filepath.Join(r.baseDir, "no-error-report") - if _, err := os.Stat(optOutFilePath); os.IsNotExist(err) { - return false - } - return true -} - -func addFile(path string, metaData *bugsnag.MetaData) { - if path == "" { - return - } - file, err := os.Open(path) - if err != nil { - log.Debug(err) - return - } - data, err := ioutil.ReadAll(file) - if err != nil { - log.Debug(err) - return - } - metaData.Add("logfile", filepath.Base(path), string(data)) -} - -func detectRunningShell(metaData *bugsnag.MetaData) { - shell, err := shell.Detect() - if err == nil { - metaData.Add("device", "shell", shell) - } -} - -func detectUname(metaData *bugsnag.MetaData) { - cmd := exec.Command("uname", "-s") - output, err := cmd.Output() - if err != nil { - return - } - metaData.Add("device", "uname", string(output)) -} - -func detectOSVersion(metaData *bugsnag.MetaData) { - metaData.Add("device", "os version", localOSVersion()) -} diff --git a/vendor/github.com/docker/machine/libmachine/crashreport/crash_report_logger.go b/vendor/github.com/docker/machine/libmachine/crashreport/crash_report_logger.go deleted file mode 100644 index c124376..0000000 --- a/vendor/github.com/docker/machine/libmachine/crashreport/crash_report_logger.go +++ /dev/null @@ -1,9 +0,0 @@ -package crashreport - -import "github.com/docker/machine/libmachine/log" - -type logger struct{} - -func (d *logger) Printf(fmtString string, args ...interface{}) { - log.Debugf(fmtString, args) -} diff --git a/vendor/github.com/docker/machine/libmachine/crashreport/crash_report_test.go b/vendor/github.com/docker/machine/libmachine/crashreport/crash_report_test.go deleted file mode 100644 index b71e436..0000000 --- a/vendor/github.com/docker/machine/libmachine/crashreport/crash_report_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package crashreport - -import ( - "testing" - - "io/ioutil" - - "os" - "path/filepath" - - "github.com/bugsnag/bugsnag-go" - "github.com/stretchr/testify/assert" -) - -func TestFileIsNotReadWhenNotExisting(t *testing.T) { - metaData := bugsnag.MetaData{} - addFile("not existing", &metaData) - assert.Empty(t, metaData) -} - -func TestRead(t *testing.T) { - metaData := bugsnag.MetaData{} - content := "foo\nbar\nqix\n" - fileName := createTempFile(t, content) - defer os.Remove(fileName) - addFile(fileName, &metaData) - assert.Equal(t, "foo\nbar\nqix\n", metaData["logfile"][filepath.Base(fileName)]) -} - -func createTempFile(t *testing.T, content string) string { - file, err := ioutil.TempFile("", "") - if err != nil { - t.Fatal(err) - } - if err := ioutil.WriteFile(file.Name(), []byte(content), 0644); err != nil { - t.Fatal(err) - } - return file.Name() -} diff --git a/vendor/github.com/docker/machine/libmachine/crashreport/os_darwin.go b/vendor/github.com/docker/machine/libmachine/crashreport/os_darwin.go deleted file mode 100644 index 2e887e4..0000000 --- a/vendor/github.com/docker/machine/libmachine/crashreport/os_darwin.go +++ /dev/null @@ -1,12 +0,0 @@ -package crashreport - -import "os/exec" - -func localOSVersion() string { - command := exec.Command("bash", "-c", `sw_vers | grep ProductVersion | cut -d$'\t' -f2`) - output, err := command.Output() - if err != nil { - return "" - } - return string(output) -} diff --git a/vendor/github.com/docker/machine/libmachine/crashreport/os_freebsd.go b/vendor/github.com/docker/machine/libmachine/crashreport/os_freebsd.go deleted file mode 100644 index bea85cf..0000000 --- a/vendor/github.com/docker/machine/libmachine/crashreport/os_freebsd.go +++ /dev/null @@ -1,12 +0,0 @@ -package crashreport - -import "os/exec" - -func localOSVersion() string { - command := exec.Command("uname", "-r") - output, err := command.Output() - if err != nil { - return "" - } - return string(output) -} diff --git a/vendor/github.com/docker/machine/libmachine/crashreport/os_linux.go b/vendor/github.com/docker/machine/libmachine/crashreport/os_linux.go deleted file mode 100644 index 31b72a8..0000000 --- a/vendor/github.com/docker/machine/libmachine/crashreport/os_linux.go +++ /dev/null @@ -1,12 +0,0 @@ -package crashreport - -import "os/exec" - -func localOSVersion() string { - command := exec.Command("bash", "-c", `cat /etc/os-release | grep 'VERSION=' | cut -d'=' -f2`) - output, err := command.Output() - if err != nil { - return "" - } - return string(output) -} diff --git a/vendor/github.com/docker/machine/libmachine/crashreport/os_windows.go b/vendor/github.com/docker/machine/libmachine/crashreport/os_windows.go deleted file mode 100644 index fff0265..0000000 --- a/vendor/github.com/docker/machine/libmachine/crashreport/os_windows.go +++ /dev/null @@ -1,47 +0,0 @@ -package crashreport - -import ( - "os/exec" - "strings" -) - -func localOSVersion() string { - command := exec.Command("ver") - output, err := command.Output() - if err == nil { - return parseVerOutput(string(output)) - } - - command = exec.Command("systeminfo") - output, err = command.Output() - if err == nil { - return parseSystemInfoOutput(string(output)) - } - - return "" -} - -func parseSystemInfoOutput(output string) string { - lines := strings.Split(string(output), "\n") - for _, line := range lines { - if strings.HasPrefix(line, "OS Version:") { - return strings.TrimSpace(line[len("OS Version:"):]) - } - } - - // If we couldn't find the version, maybe the output is not in English - // Let's parse the fourth line since it seems to be the one always used - // for the version. - if len(lines) >= 4 { - parts := strings.Split(lines[3], ":") - if len(parts) == 2 { - return strings.TrimSpace(parts[1]) - } - } - - return "" -} - -func parseVerOutput(output string) string { - return strings.TrimSpace(output) -} diff --git a/vendor/github.com/docker/machine/libmachine/crashreport/os_windows_test.go b/vendor/github.com/docker/machine/libmachine/crashreport/os_windows_test.go deleted file mode 100644 index b9cdcdc..0000000 --- a/vendor/github.com/docker/machine/libmachine/crashreport/os_windows_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package crashreport - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestParseVerOutput(t *testing.T) { - output := ` - -Microsoft Windows [version 6.3.9600] - -` - - assert.Equal(t, "Microsoft Windows [version 6.3.9600]", parseVerOutput(output)) -} - -func TestParseSystemInfoOutput(t *testing.T) { - output := ` -Host Name: DESKTOP-3A5PULA -OS Name: Microsoft Windows 10 Enterprise -OS Version: 10.0.10240 N/A Build 10240 -OS Manufacturer: Microsoft Corporation -OS Configuration: Standalone Workstation -OS Build Type: Multiprocessor Free -Registered Owner: Windows User -` - - assert.Equal(t, "10.0.10240 N/A Build 10240", parseSystemInfoOutput(output)) -} - -func TestParseNonEnglishSystemInfoOutput(t *testing.T) { - output := ` -Ignored: ... -Ignored: ... -Version du Système: 10.0.10350 -` - - assert.Equal(t, "10.0.10350", parseSystemInfoOutput(output)) -} - -func TestParseInvalidSystemInfoOutput(t *testing.T) { - output := "Invalid" - - assert.Empty(t, parseSystemInfoOutput(output)) -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/base.go b/vendor/github.com/docker/machine/libmachine/drivers/base.go deleted file mode 100644 index 4ed0664..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/base.go +++ /dev/null @@ -1,94 +0,0 @@ -package drivers - -import ( - "errors" - "path/filepath" -) - -const ( - DefaultSSHUser = "root" - DefaultSSHPort = 22 - DefaultEngineInstallURL = "https://get.docker.com" -) - -// BaseDriver - Embed this struct into drivers to provide the common set -// of fields and functions. -type BaseDriver struct { - IPAddress string - MachineName string - SSHUser string - SSHPort int - SSHKeyPath string - StorePath string - SwarmMaster bool - SwarmHost string - SwarmDiscovery string -} - -// DriverName returns the name of the driver -func (d *BaseDriver) DriverName() string { - return "unknown" -} - -// GetMachineName returns the machine name -func (d *BaseDriver) GetMachineName() string { - return d.MachineName -} - -// GetIP returns the ip -func (d *BaseDriver) GetIP() (string, error) { - if d.IPAddress == "" { - return "", errors.New("IP address is not set") - } - return d.IPAddress, nil -} - -// GetSSHKeyPath returns the ssh key path -func (d *BaseDriver) GetSSHKeyPath() string { - if d.SSHKeyPath == "" { - d.SSHKeyPath = d.ResolveStorePath("id_rsa") - } - return d.SSHKeyPath -} - -// GetSSHPort returns the ssh port, 22 if not specified -func (d *BaseDriver) GetSSHPort() (int, error) { - if d.SSHPort == 0 { - d.SSHPort = DefaultSSHPort - } - - return d.SSHPort, nil -} - -// GetSSHUsername returns the ssh user name, root if not specified -func (d *BaseDriver) GetSSHUsername() string { - if d.SSHUser == "" { - d.SSHUser = DefaultSSHUser - } - return d.SSHUser -} - -// PreCreateCheck is called to enforce pre-creation steps -func (d *BaseDriver) PreCreateCheck() error { - return nil -} - -// ResolveStorePath returns the store path where the machine is -func (d *BaseDriver) ResolveStorePath(file string) string { - return filepath.Join(d.StorePath, "machines", d.MachineName, file) -} - -// SetSwarmConfigFromFlags configures the driver for swarm -func (d *BaseDriver) SetSwarmConfigFromFlags(flags DriverOptions) { - d.SwarmMaster = flags.Bool("swarm-master") - d.SwarmHost = flags.String("swarm-host") - d.SwarmDiscovery = flags.String("swarm-discovery") -} - -func EngineInstallURLFlagSet(flags DriverOptions) bool { - return EngineInstallURLSet(flags.String("engine-install-url")) -} - -func EngineInstallURLSet(url string) bool { - return url != DefaultEngineInstallURL && url != "" -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/base_test.go b/vendor/github.com/docker/machine/libmachine/drivers/base_test.go deleted file mode 100644 index 0b824aa..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/base_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package drivers - -import ( - "errors" - "testing" - - "github.com/docker/machine/libmachine/mcnflag" - "github.com/stretchr/testify/assert" -) - -func TestIP(t *testing.T) { - cases := []struct { - baseDriver *BaseDriver - expectedIP string - expectedErr error - }{ - {&BaseDriver{}, "", errors.New("IP address is not set")}, - {&BaseDriver{IPAddress: "2001:4860:0:2001::68"}, "2001:4860:0:2001::68", nil}, - {&BaseDriver{IPAddress: "192.168.0.1"}, "192.168.0.1", nil}, - {&BaseDriver{IPAddress: "::1"}, "::1", nil}, - {&BaseDriver{IPAddress: "hostname"}, "hostname", nil}, - } - - for _, c := range cases { - ip, err := c.baseDriver.GetIP() - assert.Equal(t, c.expectedIP, ip) - assert.Equal(t, c.expectedErr, err) - } -} - -func TestEngineInstallUrlFlagEmpty(t *testing.T) { - assert.False(t, EngineInstallURLFlagSet(&CheckDriverOptions{})) -} - -func createDriverOptionWithEngineInstall(url string) *CheckDriverOptions { - return &CheckDriverOptions{ - FlagsValues: map[string]interface{}{"engine-install-url": url}, - CreateFlags: []mcnflag.Flag{mcnflag.StringFlag{Name: "engine-install-url", Value: ""}}, - } -} - -func TestEngineInstallUrlFlagDefault(t *testing.T) { - options := createDriverOptionWithEngineInstall(DefaultEngineInstallURL) - assert.False(t, EngineInstallURLFlagSet(options)) -} - -func TestEngineInstallUrlFlagSet(t *testing.T) { - options := createDriverOptionWithEngineInstall("https://test.docker.com") - assert.True(t, EngineInstallURLFlagSet(options)) -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/check.go b/vendor/github.com/docker/machine/libmachine/drivers/check.go deleted file mode 100644 index 6772471..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/check.go +++ /dev/null @@ -1,84 +0,0 @@ -package drivers - -import "github.com/docker/machine/libmachine/mcnflag" - -// CheckDriverOptions implements DriverOptions and is used to validate flag parsing -type CheckDriverOptions struct { - FlagsValues map[string]interface{} - CreateFlags []mcnflag.Flag - InvalidFlags []string -} - -func (o *CheckDriverOptions) String(key string) string { - for _, flag := range o.CreateFlags { - if flag.String() == key { - f, ok := flag.(mcnflag.StringFlag) - if !ok { - o.InvalidFlags = append(o.InvalidFlags, flag.String()) - } - - value, present := o.FlagsValues[key].(string) - if present { - return value - } - return f.Value - } - } - - return "" -} - -func (o *CheckDriverOptions) StringSlice(key string) []string { - for _, flag := range o.CreateFlags { - if flag.String() == key { - f, ok := flag.(mcnflag.StringSliceFlag) - if !ok { - o.InvalidFlags = append(o.InvalidFlags, flag.String()) - } - - value, present := o.FlagsValues[key].([]string) - if present { - return value - } - return f.Value - } - } - - return nil -} - -func (o *CheckDriverOptions) Int(key string) int { - for _, flag := range o.CreateFlags { - if flag.String() == key { - f, ok := flag.(mcnflag.IntFlag) - if !ok { - o.InvalidFlags = append(o.InvalidFlags, flag.String()) - } - - value, present := o.FlagsValues[key].(int) - if present { - return value - } - return f.Value - } - } - - return 0 -} - -func (o *CheckDriverOptions) Bool(key string) bool { - for _, flag := range o.CreateFlags { - if flag.String() == key { - _, ok := flag.(mcnflag.BoolFlag) - if !ok { - o.InvalidFlags = append(o.InvalidFlags, flag.String()) - } - } - } - - value, present := o.FlagsValues[key].(bool) - if present { - return value - } - return false -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/drivers.go b/vendor/github.com/docker/machine/libmachine/drivers/drivers.go deleted file mode 100644 index dbc37d0..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/drivers.go +++ /dev/null @@ -1,109 +0,0 @@ -package drivers - -import ( - "errors" - - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/state" -) - -// Driver defines how a host is created and controlled. Different types of -// driver represent different ways hosts can be created (e.g. different -// hypervisors, different cloud providers) -type Driver interface { - // Create a host using the driver's config - Create() error - - // DriverName returns the name of the driver - DriverName() string - - // GetCreateFlags returns the mcnflag.Flag slice representing the flags - // that can be set, their descriptions and defaults. - GetCreateFlags() []mcnflag.Flag - - // GetIP returns an IP or hostname that this host is available at - // e.g. 1.2.3.4 or docker-host-d60b70a14d3a.cloudapp.net - GetIP() (string, error) - - // GetMachineName returns the name of the machine - GetMachineName() string - - // GetSSHHostname returns hostname for use with ssh - GetSSHHostname() (string, error) - - // GetSSHKeyPath returns key path for use with ssh - GetSSHKeyPath() string - - // GetSSHPort returns port for use with ssh - GetSSHPort() (int, error) - - // GetSSHUsername returns username for use with ssh - GetSSHUsername() string - - // GetURL returns a Docker compatible host URL for connecting to this host - // e.g. tcp://1.2.3.4:2376 - GetURL() (string, error) - - // GetState returns the state that the host is in (running, stopped, etc) - GetState() (state.State, error) - - // Kill stops a host forcefully - Kill() error - - // PreCreateCheck allows for pre-create operations to make sure a driver is ready for creation - PreCreateCheck() error - - // Remove a host - Remove() error - - // Restart a host. This may just call Stop(); Start() if the provider does not - // have any special restart behaviour. - Restart() error - - // SetConfigFromFlags configures the driver with the object that was returned - // by RegisterCreateFlags - SetConfigFromFlags(opts DriverOptions) error - - // Start a host - Start() error - - // Stop a host gracefully - Stop() error -} - -var ErrHostIsNotRunning = errors.New("Host is not running") - -type DriverOptions interface { - String(key string) string - StringSlice(key string) []string - Int(key string) int - Bool(key string) bool -} - -func MachineInState(d Driver, desiredState state.State) func() bool { - return func() bool { - currentState, err := d.GetState() - if err != nil { - log.Debugf("Error getting machine state: %s", err) - } - if currentState == desiredState { - return true - } - return false - } -} - -// MustBeRunning will return an error if the machine is not in a running state. -func MustBeRunning(d Driver) error { - s, err := d.GetState() - if err != nil { - return err - } - - if s != state.Running { - return ErrHostIsNotRunning - } - - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/notsupported.go b/vendor/github.com/docker/machine/libmachine/drivers/notsupported.go deleted file mode 100644 index 59a1d4e..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/notsupported.go +++ /dev/null @@ -1,89 +0,0 @@ -package drivers - -import ( - "fmt" - - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/state" -) - -type DriverNotSupported struct { - *BaseDriver - Name string -} - -type NotSupported struct { - DriverName string -} - -func (e NotSupported) Error() string { - return fmt.Sprintf("Driver %q not supported on this platform.", e.DriverName) -} - -// NewDriverNotSupported creates a placeholder Driver that replaces -// a driver that is not supported on a given platform. eg fusion on linux. -func NewDriverNotSupported(driverName, hostName, storePath string) Driver { - return &DriverNotSupported{ - BaseDriver: &BaseDriver{ - MachineName: hostName, - StorePath: storePath, - }, - Name: driverName, - } -} - -func (d *DriverNotSupported) DriverName() string { - return d.Name -} - -func (d *DriverNotSupported) PreCreateCheck() error { - return NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) GetCreateFlags() []mcnflag.Flag { - return nil -} - -func (d *DriverNotSupported) SetConfigFromFlags(flags DriverOptions) error { - return NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) GetURL() (string, error) { - return "", NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) GetSSHHostname() (string, error) { - return "", NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) GetState() (state.State, error) { - return state.Error, NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) Create() error { - return NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) Remove() error { - return NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) Start() error { - return NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) Stop() error { - return NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) Restart() error { - return NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) Kill() error { - return NotSupported{d.DriverName()} -} - -func (d *DriverNotSupported) Upgrade() error { - return NotSupported{d.DriverName()} -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/plugin/localbinary/plugin.go b/vendor/github.com/docker/machine/libmachine/drivers/plugin/localbinary/plugin.go deleted file mode 100644 index 59116dd..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/plugin/localbinary/plugin.go +++ /dev/null @@ -1,246 +0,0 @@ -package localbinary - -import ( - "bufio" - "fmt" - "io" - "os" - "os/exec" - "strings" - "time" - - "github.com/docker/machine/libmachine/log" -) - -var ( - // Timeout where we will bail if we're not able to properly contact the - // plugin server. - defaultTimeout = 10 * time.Second - CurrentBinaryIsDockerMachine = false - CoreDrivers = []string{"amazonec2", "azure", "digitalocean", - "exoscale", "generic", "google", "hyperv", "none", "openstack", - "rackspace", "softlayer", "virtualbox", "vmwarefusion", - "vmwarevcloudair", "vmwarevsphere"} -) - -const ( - pluginOut = "(%s) %s" - pluginErr = "(%s) DBG | %s" - PluginEnvKey = "MACHINE_PLUGIN_TOKEN" - PluginEnvVal = "42" - PluginEnvDriverName = "MACHINE_PLUGIN_DRIVER_NAME" -) - -type PluginStreamer interface { - // Return a channel for receiving the output of the stream line by - // line. - // - // It happens to be the case that we do this all inside of the main - // plugin struct today, but that may not be the case forever. - AttachStream(*bufio.Scanner) <-chan string -} - -type PluginServer interface { - // Get the address where the plugin server is listening. - Address() (string, error) - - // Serve kicks off the plugin server. - Serve() error - - // Close shuts down the initialized server. - Close() error -} - -type McnBinaryExecutor interface { - // Execute the driver plugin. Returns scanners for plugin binary - // stdout and stderr. - Start() (*bufio.Scanner, *bufio.Scanner, error) - - // Stop reading from the plugins in question. - Close() error -} - -// DriverPlugin interface wraps the underlying mechanics of starting a driver -// plugin server and then figuring out where it can be dialed. -type DriverPlugin interface { - PluginServer - PluginStreamer -} - -type Plugin struct { - Executor McnBinaryExecutor - Addr string - MachineName string - addrCh chan string - stopCh chan bool - timeout time.Duration -} - -type Executor struct { - pluginStdout, pluginStderr io.ReadCloser - DriverName string - cmd *exec.Cmd - binaryPath string -} - -type ErrPluginBinaryNotFound struct { - driverName string - driverPath string -} - -func (e ErrPluginBinaryNotFound) Error() string { - return fmt.Sprintf("Driver %q not found. Do you have the plugin binary %q accessible in your PATH?", e.driverName, e.driverPath) -} - -// driverPath finds the path of a driver binary by its name. -// + If the driver is a core driver, there is no separate driver binary. We reuse current binary if it's `docker-machine` -// or we assume `docker-machine` is in the PATH. -// + If the driver is NOT a core driver, then the separate binary must be in the PATH and it's name must be -// `docker-machine-driver-driverName` -func driverPath(driverName string) string { - for _, coreDriver := range CoreDrivers { - if coreDriver == driverName { - if CurrentBinaryIsDockerMachine { - return os.Args[0] - } - - return "docker-machine" - } - } - - return fmt.Sprintf("docker-machine-driver-%s", driverName) -} - -func NewPlugin(driverName string) (*Plugin, error) { - driverPath := driverPath(driverName) - binaryPath, err := exec.LookPath(driverPath) - if err != nil { - return nil, ErrPluginBinaryNotFound{driverName, driverPath} - } - - log.Debugf("Found binary path at %s", binaryPath) - - return &Plugin{ - stopCh: make(chan bool), - addrCh: make(chan string, 1), - Executor: &Executor{ - DriverName: driverName, - binaryPath: binaryPath, - }, - }, nil -} - -func (lbe *Executor) Start() (*bufio.Scanner, *bufio.Scanner, error) { - var err error - - log.Debugf("Launching plugin server for driver %s", lbe.DriverName) - - lbe.cmd = exec.Command(lbe.binaryPath) - - lbe.pluginStdout, err = lbe.cmd.StdoutPipe() - if err != nil { - return nil, nil, fmt.Errorf("Error getting cmd stdout pipe: %s", err) - } - - lbe.pluginStderr, err = lbe.cmd.StderrPipe() - if err != nil { - return nil, nil, fmt.Errorf("Error getting cmd stderr pipe: %s", err) - } - - outScanner := bufio.NewScanner(lbe.pluginStdout) - errScanner := bufio.NewScanner(lbe.pluginStderr) - - os.Setenv(PluginEnvKey, PluginEnvVal) - os.Setenv(PluginEnvDriverName, lbe.DriverName) - - if err := lbe.cmd.Start(); err != nil { - return nil, nil, fmt.Errorf("Error starting plugin binary: %s", err) - } - - return outScanner, errScanner, nil -} - -func (lbe *Executor) Close() error { - if err := lbe.cmd.Wait(); err != nil { - return fmt.Errorf("Error waiting for binary close: %s", err) - } - - return nil -} - -func stream(scanner *bufio.Scanner, streamOutCh chan<- string) { - for scanner.Scan() { - line := scanner.Text() - if err := scanner.Err(); err != nil { - log.Warnf("Scanning stream: %s", err) - } - streamOutCh <- strings.Trim(line, "\n") - } -} - -func (lbp *Plugin) AttachStream(scanner *bufio.Scanner) <-chan string { - streamOutCh := make(chan string) - go stream(scanner, streamOutCh) - return streamOutCh -} - -func (lbp *Plugin) execServer() error { - outScanner, errScanner, err := lbp.Executor.Start() - if err != nil { - return err - } - - // Scan just one line to get the address, then send it to the relevant - // channel. - outScanner.Scan() - addr := outScanner.Text() - if err := outScanner.Err(); err != nil { - return fmt.Errorf("Reading plugin address failed: %s", err) - } - - lbp.addrCh <- strings.TrimSpace(addr) - - stdOutCh := lbp.AttachStream(outScanner) - stdErrCh := lbp.AttachStream(errScanner) - - for { - select { - case out := <-stdOutCh: - log.Infof(pluginOut, lbp.MachineName, out) - case err := <-stdErrCh: - log.Debugf(pluginErr, lbp.MachineName, err) - case <-lbp.stopCh: - if err := lbp.Executor.Close(); err != nil { - return fmt.Errorf("Error closing local plugin binary: %s", err) - } - return nil - } - } -} - -func (lbp *Plugin) Serve() error { - return lbp.execServer() -} - -func (lbp *Plugin) Address() (string, error) { - if lbp.Addr == "" { - if lbp.timeout == 0 { - lbp.timeout = defaultTimeout - } - - select { - case lbp.Addr = <-lbp.addrCh: - log.Debugf("Plugin server listening at address %s", lbp.Addr) - close(lbp.addrCh) - return lbp.Addr, nil - case <-time.After(lbp.timeout): - return "", fmt.Errorf("Failed to dial the plugin server in %s", lbp.timeout) - } - } - return lbp.Addr, nil -} - -func (lbp *Plugin) Close() error { - lbp.stopCh <- true - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/plugin/localbinary/plugin_test.go b/vendor/github.com/docker/machine/libmachine/drivers/plugin/localbinary/plugin_test.go deleted file mode 100644 index 8d5dae0..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/plugin/localbinary/plugin_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package localbinary - -import ( - "bufio" - "fmt" - "io" - "testing" - "time" - - "os" - - "github.com/docker/machine/libmachine/log" - "github.com/stretchr/testify/assert" -) - -type FakeExecutor struct { - stdout, stderr io.ReadCloser - closed bool -} - -func (fe *FakeExecutor) Start() (*bufio.Scanner, *bufio.Scanner, error) { - return bufio.NewScanner(fe.stdout), bufio.NewScanner(fe.stderr), nil -} - -func (fe *FakeExecutor) Close() error { - fe.closed = true - return nil -} - -func TestLocalBinaryPluginAddress(t *testing.T) { - lbp := &Plugin{} - expectedAddr := "127.0.0.1:12345" - - lbp.addrCh = make(chan string, 1) - lbp.addrCh <- expectedAddr - - // Call the first time to read from the channel - addr, err := lbp.Address() - if err != nil { - t.Fatalf("Expected no error, instead got %s", err) - } - if addr != expectedAddr { - t.Fatal("Expected did not match actual address") - } - - // Call the second time to read the "cached" address value - addr, err = lbp.Address() - if err != nil { - t.Fatalf("Expected no error, instead got %s", err) - } - if addr != expectedAddr { - t.Fatal("Expected did not match actual address") - } -} - -func TestLocalBinaryPluginAddressTimeout(t *testing.T) { - if testing.Short() { - t.Skip("Skipping timeout test") - } - - lbp := &Plugin{ - addrCh: make(chan string, 1), - timeout: 1 * time.Second, - } - - addr, err := lbp.Address() - - assert.Empty(t, addr) - assert.EqualError(t, err, "Failed to dial the plugin server in 1s") -} - -func TestLocalBinaryPluginClose(t *testing.T) { - lbp := &Plugin{} - lbp.stopCh = make(chan bool, 1) - go lbp.Close() - stopped := <-lbp.stopCh - if !stopped { - t.Fatal("Close did not send a stop message on the proper channel") - } -} - -func TestExecServer(t *testing.T) { - logOutReader, logOutWriter := io.Pipe() - logErrReader, logErrWriter := io.Pipe() - - log.SetDebug(true) - log.SetOutWriter(logOutWriter) - log.SetErrWriter(logErrWriter) - - defer func() { - log.SetDebug(false) - log.SetOutWriter(os.Stdout) - log.SetErrWriter(os.Stderr) - }() - - stdoutReader, stdoutWriter := io.Pipe() - stderrReader, stderrWriter := io.Pipe() - - fe := &FakeExecutor{ - stdout: stdoutReader, - stderr: stderrReader, - } - - machineName := "test" - lbp := &Plugin{ - MachineName: machineName, - Executor: fe, - addrCh: make(chan string, 1), - stopCh: make(chan bool, 1), - } - - finalErr := make(chan error) - - // Start the docker-machine-foo plugin server - go func() { - finalErr <- lbp.execServer() - }() - - logOutScanner := bufio.NewScanner(logOutReader) - logErrScanner := bufio.NewScanner(logErrReader) - - // Write the ip address - expectedAddr := "127.0.0.1:12345" - if _, err := io.WriteString(stdoutWriter, expectedAddr+"\n"); err != nil { - t.Fatalf("Error attempting to write plugin address: %s", err) - } - - if addr := <-lbp.addrCh; addr != expectedAddr { - t.Fatalf("Expected to read the expected address properly in server but did not") - } - - // Write a log in stdout - expectedPluginOut := "Doing some fun plugin stuff..." - if _, err := io.WriteString(stdoutWriter, expectedPluginOut+"\n"); err != nil { - t.Fatalf("Error attempting to write to out in plugin: %s", err) - } - - expectedOut := fmt.Sprintf(pluginOut, machineName, expectedPluginOut) - if logOutScanner.Scan(); logOutScanner.Text() != expectedOut { - t.Fatalf("Output written to log was not what we expected\nexpected: %s\nactual: %s", expectedOut, logOutScanner.Text()) - } - - // Write a log in stderr - expectedPluginErr := "Uh oh, something in plugin went wrong..." - if _, err := io.WriteString(stderrWriter, expectedPluginErr+"\n"); err != nil { - t.Fatalf("Error attempting to write to err in plugin: %s", err) - } - - expectedErr := fmt.Sprintf(pluginErr, machineName, expectedPluginErr) - if logErrScanner.Scan(); logErrScanner.Text() != expectedErr { - t.Fatalf("Error written to log was not what we expected\nexpected: %s\nactual: %s", expectedErr, logErrScanner.Text()) - } - - lbp.Close() - - if err := <-finalErr; err != nil { - t.Fatalf("Error serving: %s", err) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/plugin/register_driver.go b/vendor/github.com/docker/machine/libmachine/drivers/plugin/register_driver.go deleted file mode 100644 index 27e0dbc..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/plugin/register_driver.go +++ /dev/null @@ -1,63 +0,0 @@ -package plugin - -import ( - "fmt" - "net" - "net/http" - "net/rpc" - "os" - "time" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/drivers/plugin/localbinary" - "github.com/docker/machine/libmachine/drivers/rpc" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/version" -) - -var ( - heartbeatTimeout = 10 * time.Second -) - -func RegisterDriver(d drivers.Driver) { - if os.Getenv(localbinary.PluginEnvKey) != localbinary.PluginEnvVal { - fmt.Fprintf(os.Stderr, `This is a Docker Machine plugin binary. -Plugin binaries are not intended to be invoked directly. -Please use this plugin through the main 'docker-machine' binary. -(API version: %d) -`, version.APIVersion) - os.Exit(1) - } - - log.SetDebug(true) - os.Setenv("MACHINE_DEBUG", "1") - - rpcd := rpcdriver.NewRPCServerDriver(d) - rpc.RegisterName(rpcdriver.RPCServiceNameV0, rpcd) - rpc.RegisterName(rpcdriver.RPCServiceNameV1, rpcd) - rpc.HandleHTTP() - - listener, err := net.Listen("tcp", "127.0.0.1:0") - if err != nil { - fmt.Fprintf(os.Stderr, "Error loading RPC server: %s\n", err) - os.Exit(1) - } - defer listener.Close() - - fmt.Println(listener.Addr()) - - go http.Serve(listener, nil) - - for { - select { - case <-rpcd.CloseCh: - log.Debug("Closing plugin on server side") - os.Exit(0) - case <-rpcd.HeartbeatCh: - continue - case <-time.After(heartbeatTimeout): - // TODO: Add heartbeat retry logic - os.Exit(1) - } - } -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/rpc/client_driver.go b/vendor/github.com/docker/machine/libmachine/drivers/rpc/client_driver.go deleted file mode 100644 index 5ce22cd..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/rpc/client_driver.go +++ /dev/null @@ -1,367 +0,0 @@ -package rpcdriver - -import ( - "fmt" - "net/rpc" - "sync" - "time" - - "io" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/drivers/plugin/localbinary" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/state" - "github.com/docker/machine/libmachine/version" -) - -var ( - heartbeatInterval = 5 * time.Second -) - -type RPCClientDriverFactory interface { - NewRPCClientDriver(driverName string, rawDriver []byte) (*RPCClientDriver, error) - io.Closer -} - -type DefaultRPCClientDriverFactory struct { - openedDrivers []*RPCClientDriver - openedDriversLock sync.Locker -} - -func NewRPCClientDriverFactory() RPCClientDriverFactory { - return &DefaultRPCClientDriverFactory{ - openedDrivers: []*RPCClientDriver{}, - openedDriversLock: &sync.Mutex{}, - } -} - -type RPCClientDriver struct { - plugin localbinary.DriverPlugin - heartbeatDoneCh chan bool - Client *InternalClient -} - -type RPCCall struct { - ServiceMethod string - Args interface{} - Reply interface{} -} - -type InternalClient struct { - MachineName string - RPCClient *rpc.Client - rpcServiceName string -} - -const ( - RPCServiceNameV0 = `RpcServerDriver` - RPCServiceNameV1 = `RPCServerDriver` - - HeartbeatMethod = `.Heartbeat` - GetVersionMethod = `.GetVersion` - CloseMethod = `.Close` - GetCreateFlagsMethod = `.GetCreateFlags` - SetConfigRawMethod = `.SetConfigRaw` - GetConfigRawMethod = `.GetConfigRaw` - DriverNameMethod = `.DriverName` - SetConfigFromFlagsMethod = `.SetConfigFromFlags` - GetURLMethod = `.GetURL` - GetMachineNameMethod = `.GetMachineName` - GetIPMethod = `.GetIP` - GetSSHHostnameMethod = `.GetSSHHostname` - GetSSHKeyPathMethod = `.GetSSHKeyPath` - GetSSHPortMethod = `.GetSSHPort` - GetSSHUsernameMethod = `.GetSSHUsername` - GetStateMethod = `.GetState` - PreCreateCheckMethod = `.PreCreateCheck` - CreateMethod = `.Create` - RemoveMethod = `.Remove` - StartMethod = `.Start` - StopMethod = `.Stop` - RestartMethod = `.Restart` - KillMethod = `.Kill` - UpgradeMethod = `.Upgrade` -) - -func (ic *InternalClient) Call(serviceMethod string, args interface{}, reply interface{}) error { - if serviceMethod != HeartbeatMethod { - log.Debugf("(%s) Calling %+v", ic.MachineName, serviceMethod) - } - return ic.RPCClient.Call(ic.rpcServiceName+serviceMethod, args, reply) -} - -func (ic *InternalClient) switchToV0() { - ic.rpcServiceName = RPCServiceNameV0 -} - -func NewInternalClient(rpcclient *rpc.Client) *InternalClient { - return &InternalClient{ - RPCClient: rpcclient, - rpcServiceName: RPCServiceNameV1, - } -} - -func (f *DefaultRPCClientDriverFactory) Close() error { - f.openedDriversLock.Lock() - defer f.openedDriversLock.Unlock() - - for _, openedDriver := range f.openedDrivers { - if err := openedDriver.close(); err != nil { - // No need to display an error. - // There's nothing we can do and it doesn't add value to the user. - } - } - f.openedDrivers = []*RPCClientDriver{} - - return nil -} - -func (f *DefaultRPCClientDriverFactory) NewRPCClientDriver(driverName string, rawDriver []byte) (*RPCClientDriver, error) { - mcnName := "" - - p, err := localbinary.NewPlugin(driverName) - if err != nil { - return nil, err - } - - go func() { - if err := p.Serve(); err != nil { - // TODO: Is this best approach? - log.Warn(err) - return - } - }() - - addr, err := p.Address() - if err != nil { - return nil, fmt.Errorf("Error attempting to get plugin server address for RPC: %s", err) - } - - rpcclient, err := rpc.DialHTTP("tcp", addr) - if err != nil { - return nil, err - } - - c := &RPCClientDriver{ - Client: NewInternalClient(rpcclient), - heartbeatDoneCh: make(chan bool), - } - - f.openedDriversLock.Lock() - f.openedDrivers = append(f.openedDrivers, c) - f.openedDriversLock.Unlock() - - var serverVersion int - if err := c.Client.Call(GetVersionMethod, struct{}{}, &serverVersion); err != nil { - // this is the first call we make to the server. We try to play nice with old pre 0.5.1 client, - // by gracefully trying old RPCServiceName, we do this only once, and keep the result for future calls. - log.Debugf(err.Error()) - log.Debugf("Client (%s) with %s does not work, re-attempting with %s", c.Client.MachineName, RPCServiceNameV1, RPCServiceNameV0) - c.Client.switchToV0() - if err := c.Client.Call(GetVersionMethod, struct{}{}, &serverVersion); err != nil { - return nil, err - } - } - - if serverVersion != version.APIVersion { - return nil, fmt.Errorf("Driver binary uses an incompatible API version (%d)", serverVersion) - } - log.Debug("Using API Version ", serverVersion) - - go func(c *RPCClientDriver) { - for { - select { - case <-c.heartbeatDoneCh: - return - case <-time.After(heartbeatInterval): - if err := c.Client.Call(HeartbeatMethod, struct{}{}, nil); err != nil { - log.Warnf("Wrapper Docker Machine process exiting due to closed plugin server (%s)", err) - if err := c.close(); err != nil { - log.Warn(err) - } - } - } - } - }(c) - - if err := c.SetConfigRaw(rawDriver); err != nil { - return nil, err - } - - mcnName = c.GetMachineName() - p.MachineName = mcnName - c.Client.MachineName = mcnName - c.plugin = p - - return c, nil -} - -func (c *RPCClientDriver) MarshalJSON() ([]byte, error) { - return c.GetConfigRaw() -} - -func (c *RPCClientDriver) UnmarshalJSON(data []byte) error { - return c.SetConfigRaw(data) -} - -func (c *RPCClientDriver) close() error { - c.heartbeatDoneCh <- true - close(c.heartbeatDoneCh) - - log.Debug("Making call to close driver server") - - if err := c.Client.Call(CloseMethod, struct{}{}, nil); err != nil { - log.Debugf("Failed to make call to close driver server: %s", err) - } else { - log.Debug("Successfully made call to close driver server") - } - - log.Debug("Making call to close connection to plugin binary") - - return c.plugin.Close() -} - -// Helper method to make requests which take no arguments and return simply a -// string, e.g. "GetIP". -func (c *RPCClientDriver) rpcStringCall(method string) (string, error) { - var info string - - if err := c.Client.Call(method, struct{}{}, &info); err != nil { - return "", err - } - - return info, nil -} - -func (c *RPCClientDriver) GetCreateFlags() []mcnflag.Flag { - var flags []mcnflag.Flag - - if err := c.Client.Call(GetCreateFlagsMethod, struct{}{}, &flags); err != nil { - log.Warnf("Error attempting call to get create flags: %s", err) - } - - return flags -} - -func (c *RPCClientDriver) SetConfigRaw(data []byte) error { - return c.Client.Call(SetConfigRawMethod, data, nil) -} - -func (c *RPCClientDriver) GetConfigRaw() ([]byte, error) { - var data []byte - - if err := c.Client.Call(GetConfigRawMethod, struct{}{}, &data); err != nil { - return nil, err - } - - return data, nil -} - -// DriverName returns the name of the driver -func (c *RPCClientDriver) DriverName() string { - driverName, err := c.rpcStringCall(DriverNameMethod) - if err != nil { - log.Warnf("Error attempting call to get driver name: %s", err) - } - - return driverName -} - -func (c *RPCClientDriver) SetConfigFromFlags(flags drivers.DriverOptions) error { - return c.Client.Call(SetConfigFromFlagsMethod, &flags, nil) -} - -func (c *RPCClientDriver) GetURL() (string, error) { - return c.rpcStringCall(GetURLMethod) -} - -func (c *RPCClientDriver) GetMachineName() string { - name, err := c.rpcStringCall(GetMachineNameMethod) - if err != nil { - log.Warnf("Error attempting call to get machine name: %s", err) - } - - return name -} - -func (c *RPCClientDriver) GetIP() (string, error) { - return c.rpcStringCall(GetIPMethod) -} - -func (c *RPCClientDriver) GetSSHHostname() (string, error) { - return c.rpcStringCall(GetSSHHostnameMethod) -} - -// GetSSHKeyPath returns the key path -// TODO: This method doesn't even make sense to have with RPC. -func (c *RPCClientDriver) GetSSHKeyPath() string { - path, err := c.rpcStringCall(GetSSHKeyPathMethod) - if err != nil { - log.Warnf("Error attempting call to get SSH key path: %s", err) - } - - return path -} - -func (c *RPCClientDriver) GetSSHPort() (int, error) { - var port int - - if err := c.Client.Call(GetSSHPortMethod, struct{}{}, &port); err != nil { - return 0, err - } - - return port, nil -} - -func (c *RPCClientDriver) GetSSHUsername() string { - username, err := c.rpcStringCall(GetSSHUsernameMethod) - if err != nil { - log.Warnf("Error attempting call to get SSH username: %s", err) - } - - return username -} - -func (c *RPCClientDriver) GetState() (state.State, error) { - var s state.State - - if err := c.Client.Call(GetStateMethod, struct{}{}, &s); err != nil { - return state.Error, err - } - - return s, nil -} - -func (c *RPCClientDriver) PreCreateCheck() error { - return c.Client.Call(PreCreateCheckMethod, struct{}{}, nil) -} - -func (c *RPCClientDriver) Create() error { - return c.Client.Call(CreateMethod, struct{}{}, nil) -} - -func (c *RPCClientDriver) Remove() error { - return c.Client.Call(RemoveMethod, struct{}{}, nil) -} - -func (c *RPCClientDriver) Start() error { - return c.Client.Call(StartMethod, struct{}{}, nil) -} - -func (c *RPCClientDriver) Stop() error { - return c.Client.Call(StopMethod, struct{}{}, nil) -} - -func (c *RPCClientDriver) Restart() error { - return c.Client.Call(RestartMethod, struct{}{}, nil) -} - -func (c *RPCClientDriver) Kill() error { - return c.Client.Call(KillMethod, struct{}{}, nil) -} - -func (c *RPCClientDriver) Upgrade() error { - return c.Client.Call(UpgradeMethod, struct{}{}, nil) -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/rpc/server_driver.go b/vendor/github.com/docker/machine/libmachine/drivers/rpc/server_driver.go deleted file mode 100644 index 6fb3f3d..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/rpc/server_driver.go +++ /dev/null @@ -1,227 +0,0 @@ -package rpcdriver - -import ( - "encoding/gob" - "encoding/json" - "fmt" - "runtime/debug" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/state" - "github.com/docker/machine/libmachine/version" -) - -type Stacker interface { - Stack() []byte -} - -type StandardStack struct{} - -func (ss *StandardStack) Stack() []byte { - return debug.Stack() -} - -var ( - stdStacker Stacker = &StandardStack{} -) - -func init() { - gob.Register(new(RPCFlags)) - gob.Register(new(mcnflag.IntFlag)) - gob.Register(new(mcnflag.StringFlag)) - gob.Register(new(mcnflag.StringSliceFlag)) - gob.Register(new(mcnflag.BoolFlag)) -} - -type RPCFlags struct { - Values map[string]interface{} -} - -func (r RPCFlags) Get(key string) interface{} { - val, ok := r.Values[key] - if !ok { - log.Warnf("Trying to access option %s which does not exist", key) - log.Warn("THIS ***WILL*** CAUSE UNEXPECTED BEHAVIOR") - } - return val -} - -func (r RPCFlags) String(key string) string { - val, ok := r.Get(key).(string) - if !ok { - log.Warnf("Type assertion did not go smoothly to string for key %s", key) - } - return val -} - -func (r RPCFlags) StringSlice(key string) []string { - val, ok := r.Get(key).([]string) - if !ok { - log.Warnf("Type assertion did not go smoothly to string slice for key %s", key) - } - return val -} - -func (r RPCFlags) Int(key string) int { - val, ok := r.Get(key).(int) - if !ok { - log.Warnf("Type assertion did not go smoothly to int for key %s", key) - } - return val -} - -func (r RPCFlags) Bool(key string) bool { - val, ok := r.Get(key).(bool) - if !ok { - log.Warnf("Type assertion did not go smoothly to bool for key %s", key) - } - return val -} - -type RPCServerDriver struct { - ActualDriver drivers.Driver - CloseCh chan bool - HeartbeatCh chan bool -} - -func NewRPCServerDriver(d drivers.Driver) *RPCServerDriver { - return &RPCServerDriver{ - ActualDriver: d, - CloseCh: make(chan bool), - HeartbeatCh: make(chan bool), - } -} - -func (r *RPCServerDriver) Close(_, _ *struct{}) error { - r.CloseCh <- true - return nil -} - -func (r *RPCServerDriver) GetVersion(_ *struct{}, reply *int) error { - *reply = version.APIVersion - return nil -} - -func (r *RPCServerDriver) GetConfigRaw(_ *struct{}, reply *[]byte) error { - driverData, err := json.Marshal(r.ActualDriver) - if err != nil { - return err - } - - *reply = driverData - - return nil -} - -func (r *RPCServerDriver) GetCreateFlags(_ *struct{}, reply *[]mcnflag.Flag) error { - *reply = r.ActualDriver.GetCreateFlags() - return nil -} - -func (r *RPCServerDriver) SetConfigRaw(data []byte, _ *struct{}) error { - return json.Unmarshal(data, &r.ActualDriver) -} - -func trapPanic(err *error) { - if r := recover(); r != nil { - *err = fmt.Errorf("Panic in the driver: %s\n%s", r.(error), stdStacker.Stack()) - } -} - -func (r *RPCServerDriver) Create(_, _ *struct{}) (err error) { - // In an ideal world, plugins wouldn't ever panic. However, panics - // have been known to happen and cause issues. Therefore, we recover - // and do not crash the RPC server completely in the case of a panic - // during create. - defer trapPanic(&err) - - err = r.ActualDriver.Create() - - return err -} - -func (r *RPCServerDriver) DriverName(_ *struct{}, reply *string) error { - *reply = r.ActualDriver.DriverName() - return nil -} - -func (r *RPCServerDriver) GetIP(_ *struct{}, reply *string) error { - ip, err := r.ActualDriver.GetIP() - *reply = ip - return err -} - -func (r *RPCServerDriver) GetMachineName(_ *struct{}, reply *string) error { - *reply = r.ActualDriver.GetMachineName() - return nil -} - -func (r *RPCServerDriver) GetSSHHostname(_ *struct{}, reply *string) error { - hostname, err := r.ActualDriver.GetSSHHostname() - *reply = hostname - return err -} - -func (r *RPCServerDriver) GetSSHKeyPath(_ *struct{}, reply *string) error { - *reply = r.ActualDriver.GetSSHKeyPath() - return nil -} - -// GetSSHPort returns port for use with ssh -func (r *RPCServerDriver) GetSSHPort(_ *struct{}, reply *int) error { - port, err := r.ActualDriver.GetSSHPort() - *reply = port - return err -} - -func (r *RPCServerDriver) GetSSHUsername(_ *struct{}, reply *string) error { - *reply = r.ActualDriver.GetSSHUsername() - return nil -} - -func (r *RPCServerDriver) GetURL(_ *struct{}, reply *string) error { - info, err := r.ActualDriver.GetURL() - *reply = info - return err -} - -func (r *RPCServerDriver) GetState(_ *struct{}, reply *state.State) error { - s, err := r.ActualDriver.GetState() - *reply = s - return err -} - -func (r *RPCServerDriver) Kill(_ *struct{}, _ *struct{}) error { - return r.ActualDriver.Kill() -} - -func (r *RPCServerDriver) PreCreateCheck(_ *struct{}, _ *struct{}) error { - return r.ActualDriver.PreCreateCheck() -} - -func (r *RPCServerDriver) Remove(_ *struct{}, _ *struct{}) error { - return r.ActualDriver.Remove() -} - -func (r *RPCServerDriver) Restart(_ *struct{}, _ *struct{}) error { - return r.ActualDriver.Restart() -} - -func (r *RPCServerDriver) SetConfigFromFlags(flags *drivers.DriverOptions, _ *struct{}) error { - return r.ActualDriver.SetConfigFromFlags(*flags) -} - -func (r *RPCServerDriver) Start(_ *struct{}, _ *struct{}) error { - return r.ActualDriver.Start() -} - -func (r *RPCServerDriver) Stop(_ *struct{}, _ *struct{}) error { - return r.ActualDriver.Stop() -} - -func (r *RPCServerDriver) Heartbeat(_ *struct{}, _ *struct{}) error { - r.HeartbeatCh <- true - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/rpc/server_driver_test.go b/vendor/github.com/docker/machine/libmachine/drivers/rpc/server_driver_test.go deleted file mode 100644 index 952684d..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/rpc/server_driver_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package rpcdriver - -import ( - "errors" - "testing" - - "github.com/docker/machine/drivers/fakedriver" - "github.com/stretchr/testify/assert" -) - -type panicDriver struct { - *fakedriver.Driver - panicErr error - returnErr error -} - -type FakeStacker struct { - trace []byte -} - -func (fs *FakeStacker) Stack() []byte { - return fs.trace -} - -func (p *panicDriver) Create() error { - if p.panicErr != nil { - panic(p.panicErr) - } - return p.returnErr -} - -func TestRPCServerDriverCreate(t *testing.T) { - testCases := []struct { - description string - expectedErr error - serverDriver *RPCServerDriver - stacker Stacker - }{ - { - description: "Happy path", - expectedErr: nil, - serverDriver: &RPCServerDriver{ - ActualDriver: &panicDriver{ - returnErr: nil, - }, - }, - }, - { - description: "Normal error, no panic", - expectedErr: errors.New("API not available"), - serverDriver: &RPCServerDriver{ - ActualDriver: &panicDriver{ - returnErr: errors.New("API not available"), - }, - }, - }, - { - description: "Panic happened during create", - expectedErr: errors.New("Panic in the driver: index out of range\nSTACK TRACE"), - serverDriver: &RPCServerDriver{ - ActualDriver: &panicDriver{ - panicErr: errors.New("index out of range"), - }, - }, - stacker: &FakeStacker{ - trace: []byte("STACK TRACE"), - }, - }, - } - - for _, tc := range testCases { - stdStacker = tc.stacker - assert.Equal(t, tc.expectedErr, tc.serverDriver.Create(nil, nil)) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/serial.go b/vendor/github.com/docker/machine/libmachine/drivers/serial.go deleted file mode 100644 index 056704e..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/serial.go +++ /dev/null @@ -1,172 +0,0 @@ -package drivers - -import ( - "sync" - - "encoding/json" - - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/state" -) - -var stdLock = &sync.Mutex{} - -// SerialDriver is a wrapper struct which is used to ensure that RPC calls -// to a driver only occur one at a time. -// Some providers, e.g. virtualbox, should not run driver operations at the -// same time as other driver instances of the same type. Otherwise, we scrape -// up against VirtualBox's own locking mechanisms. -// -// It would be preferable to simply have a lock around, say, the VBoxManage -// command, but with our current one-server-process-per-machine model it is -// impossible to dictate this locking on the server side. -type SerialDriver struct { - Driver - sync.Locker -} - -func NewSerialDriver(innerDriver Driver) Driver { - return newSerialDriverWithLock(innerDriver, stdLock) -} - -func newSerialDriverWithLock(innerDriver Driver, lock sync.Locker) Driver { - return &SerialDriver{ - Driver: innerDriver, - Locker: lock, - } -} - -// Create a host using the driver's config -func (d *SerialDriver) Create() error { - d.Lock() - defer d.Unlock() - return d.Driver.Create() -} - -// DriverName returns the name of the driver as it is registered -func (d *SerialDriver) DriverName() string { - d.Lock() - defer d.Unlock() - return d.Driver.DriverName() -} - -// GetCreateFlags returns the mcnflag.Flag slice representing the flags -// that can be set, their descriptions and defaults. -func (d *SerialDriver) GetCreateFlags() []mcnflag.Flag { - d.Lock() - defer d.Unlock() - return d.Driver.GetCreateFlags() -} - -// GetIP returns an IP or hostname that this host is available at -// e.g. 1.2.3.4 or docker-host-d60b70a14d3a.cloudapp.net -func (d *SerialDriver) GetIP() (string, error) { - d.Lock() - defer d.Unlock() - return d.Driver.GetIP() -} - -// GetMachineName returns the name of the machine -func (d *SerialDriver) GetMachineName() string { - d.Lock() - defer d.Unlock() - return d.Driver.GetMachineName() -} - -// GetSSHHostname returns hostname for use with ssh -func (d *SerialDriver) GetSSHHostname() (string, error) { - d.Lock() - defer d.Unlock() - return d.Driver.GetSSHHostname() -} - -// GetSSHKeyPath returns key path for use with ssh -func (d *SerialDriver) GetSSHKeyPath() string { - d.Lock() - defer d.Unlock() - return d.Driver.GetSSHKeyPath() -} - -// GetSSHPort returns port for use with ssh -func (d *SerialDriver) GetSSHPort() (int, error) { - d.Lock() - defer d.Unlock() - return d.Driver.GetSSHPort() -} - -// GetSSHUsername returns username for use with ssh -func (d *SerialDriver) GetSSHUsername() string { - d.Lock() - defer d.Unlock() - return d.Driver.GetSSHUsername() -} - -// GetURL returns a Docker compatible host URL for connecting to this host -// e.g. tcp://1.2.3.4:2376 -func (d *SerialDriver) GetURL() (string, error) { - d.Lock() - defer d.Unlock() - return d.Driver.GetURL() -} - -// GetState returns the state that the host is in (running, stopped, etc) -func (d *SerialDriver) GetState() (state.State, error) { - d.Lock() - defer d.Unlock() - return d.Driver.GetState() -} - -// Kill stops a host forcefully -func (d *SerialDriver) Kill() error { - d.Lock() - defer d.Unlock() - return d.Driver.Kill() -} - -// PreCreateCheck allows for pre-create operations to make sure a driver is ready for creation -func (d *SerialDriver) PreCreateCheck() error { - d.Lock() - defer d.Unlock() - return d.Driver.PreCreateCheck() -} - -// Remove a host -func (d *SerialDriver) Remove() error { - d.Lock() - defer d.Unlock() - return d.Driver.Remove() -} - -// Restart a host. This may just call Stop(); Start() if the provider does not -// have any special restart behaviour. -func (d *SerialDriver) Restart() error { - d.Lock() - defer d.Unlock() - return d.Driver.Restart() -} - -// SetConfigFromFlags configures the driver with the object that was returned -// by RegisterCreateFlags -func (d *SerialDriver) SetConfigFromFlags(opts DriverOptions) error { - d.Lock() - defer d.Unlock() - return d.Driver.SetConfigFromFlags(opts) -} - -// Start a host -func (d *SerialDriver) Start() error { - d.Lock() - defer d.Unlock() - return d.Driver.Start() -} - -// Stop a host gracefully -func (d *SerialDriver) Stop() error { - d.Lock() - defer d.Unlock() - return d.Driver.Stop() -} - -func (d *SerialDriver) MarshalJSON() ([]byte, error) { - return json.Marshal(d.Driver) -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/serial_test.go b/vendor/github.com/docker/machine/libmachine/drivers/serial_test.go deleted file mode 100644 index d0a06a4..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/serial_test.go +++ /dev/null @@ -1,296 +0,0 @@ -package drivers - -import ( - "testing" - - "github.com/docker/machine/libmachine/mcnflag" - "github.com/docker/machine/libmachine/state" - "github.com/stretchr/testify/assert" -) - -type CallRecorder struct { - calls []string -} - -func (c *CallRecorder) record(call string) { - c.calls = append(c.calls, call) -} - -type MockLocker struct { - calls *CallRecorder -} - -func (l *MockLocker) Lock() { - l.calls.record("Lock") -} - -func (l *MockLocker) Unlock() { - l.calls.record("Unlock") -} - -type MockDriver struct { - calls *CallRecorder - driverName string - flags []mcnflag.Flag - ip string - machineName string - sshHostname string - sshKeyPath string - sshPort int - sshUsername string - url string - state state.State -} - -func (d *MockDriver) Create() error { - d.calls.record("Create") - return nil -} - -func (d *MockDriver) DriverName() string { - d.calls.record("DriverName") - return d.driverName -} - -func (d *MockDriver) GetCreateFlags() []mcnflag.Flag { - d.calls.record("GetCreateFlags") - return d.flags -} - -func (d *MockDriver) GetIP() (string, error) { - d.calls.record("GetIP") - return d.ip, nil -} - -func (d *MockDriver) GetMachineName() string { - d.calls.record("GetMachineName") - return d.machineName -} - -func (d *MockDriver) GetSSHHostname() (string, error) { - d.calls.record("GetSSHHostname") - return d.sshHostname, nil -} - -func (d *MockDriver) GetSSHKeyPath() string { - d.calls.record("GetSSHKeyPath") - return d.sshKeyPath -} - -func (d *MockDriver) GetSSHPort() (int, error) { - d.calls.record("GetSSHPort") - return d.sshPort, nil -} - -func (d *MockDriver) GetSSHUsername() string { - d.calls.record("GetSSHUsername") - return d.sshUsername -} - -func (d *MockDriver) GetURL() (string, error) { - d.calls.record("GetURL") - return d.url, nil -} - -func (d *MockDriver) GetState() (state.State, error) { - d.calls.record("GetState") - return d.state, nil -} - -func (d *MockDriver) Kill() error { - d.calls.record("Kill") - return nil -} - -func (d *MockDriver) PreCreateCheck() error { - d.calls.record("PreCreateCheck") - return nil -} - -func (d *MockDriver) Remove() error { - d.calls.record("Remove") - return nil -} - -func (d *MockDriver) Restart() error { - d.calls.record("Restart") - return nil -} - -func (d *MockDriver) SetConfigFromFlags(opts DriverOptions) error { - d.calls.record("SetConfigFromFlags") - return nil -} - -func (d *MockDriver) Start() error { - d.calls.record("Start") - return nil -} - -func (d *MockDriver) Stop() error { - d.calls.record("Stop") - return nil -} - -func TestSerialDriverCreate(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{calls: callRecorder}, &MockLocker{calls: callRecorder}) - err := driver.Create() - - assert.NoError(t, err) - assert.Equal(t, []string{"Lock", "Create", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverDriverName(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{driverName: "DRIVER", calls: callRecorder}, &MockLocker{calls: callRecorder}) - driverName := driver.DriverName() - - assert.Equal(t, "DRIVER", driverName) - assert.Equal(t, []string{"Lock", "DriverName", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverGetIP(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{ip: "IP", calls: callRecorder}, &MockLocker{calls: callRecorder}) - ip, _ := driver.GetIP() - - assert.Equal(t, "IP", ip) - assert.Equal(t, []string{"Lock", "GetIP", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverGetMachineName(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{machineName: "MACHINE_NAME", calls: callRecorder}, &MockLocker{calls: callRecorder}) - machineName := driver.GetMachineName() - - assert.Equal(t, "MACHINE_NAME", machineName) - assert.Equal(t, []string{"Lock", "GetMachineName", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverGetSSHHostname(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{sshHostname: "SSH_HOSTNAME", calls: callRecorder}, &MockLocker{calls: callRecorder}) - sshHostname, _ := driver.GetSSHHostname() - - assert.Equal(t, "SSH_HOSTNAME", sshHostname) - assert.Equal(t, []string{"Lock", "GetSSHHostname", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverGetSSHKeyPath(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{sshKeyPath: "PATH", calls: callRecorder}, &MockLocker{calls: callRecorder}) - path := driver.GetSSHKeyPath() - - assert.Equal(t, "PATH", path) - assert.Equal(t, []string{"Lock", "GetSSHKeyPath", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverGetSSHPort(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{sshPort: 42, calls: callRecorder}, &MockLocker{calls: callRecorder}) - sshPort, _ := driver.GetSSHPort() - - assert.Equal(t, 42, sshPort) - assert.Equal(t, []string{"Lock", "GetSSHPort", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverGetSSHUsername(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{sshUsername: "SSH_USER", calls: callRecorder}, &MockLocker{calls: callRecorder}) - sshUsername := driver.GetSSHUsername() - - assert.Equal(t, "SSH_USER", sshUsername) - assert.Equal(t, []string{"Lock", "GetSSHUsername", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverGetURL(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{url: "URL", calls: callRecorder}, &MockLocker{calls: callRecorder}) - url, _ := driver.GetURL() - - assert.Equal(t, "URL", url) - assert.Equal(t, []string{"Lock", "GetURL", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverGetState(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{state: state.Running, calls: callRecorder}, &MockLocker{calls: callRecorder}) - machineState, _ := driver.GetState() - - assert.Equal(t, state.Running, machineState) - assert.Equal(t, []string{"Lock", "GetState", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverKill(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{calls: callRecorder}, &MockLocker{calls: callRecorder}) - driver.Kill() - - assert.Equal(t, []string{"Lock", "Kill", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverPreCreateCheck(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{calls: callRecorder}, &MockLocker{calls: callRecorder}) - driver.PreCreateCheck() - - assert.Equal(t, []string{"Lock", "PreCreateCheck", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverRemove(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{calls: callRecorder}, &MockLocker{calls: callRecorder}) - driver.Remove() - - assert.Equal(t, []string{"Lock", "Remove", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverRestart(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{calls: callRecorder}, &MockLocker{calls: callRecorder}) - driver.Restart() - - assert.Equal(t, []string{"Lock", "Restart", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverSetConfigFromFlags(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{calls: callRecorder}, &MockLocker{calls: callRecorder}) - driver.SetConfigFromFlags(nil) - - assert.Equal(t, []string{"Lock", "SetConfigFromFlags", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverStart(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{calls: callRecorder}, &MockLocker{calls: callRecorder}) - driver.Start() - - assert.Equal(t, []string{"Lock", "Start", "Unlock"}, callRecorder.calls) -} - -func TestSerialDriverStop(t *testing.T) { - callRecorder := &CallRecorder{} - - driver := newSerialDriverWithLock(&MockDriver{calls: callRecorder}, &MockLocker{calls: callRecorder}) - driver.Stop() - - assert.Equal(t, []string{"Lock", "Stop", "Unlock"}, callRecorder.calls) -} diff --git a/vendor/github.com/docker/machine/libmachine/drivers/utils.go b/vendor/github.com/docker/machine/libmachine/drivers/utils.go deleted file mode 100644 index b023f16..0000000 --- a/vendor/github.com/docker/machine/libmachine/drivers/utils.go +++ /dev/null @@ -1,73 +0,0 @@ -package drivers - -import ( - "fmt" - - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/ssh" -) - -func GetSSHClientFromDriver(d Driver) (ssh.Client, error) { - address, err := d.GetSSHHostname() - if err != nil { - return nil, err - } - - port, err := d.GetSSHPort() - if err != nil { - return nil, err - } - - var auth *ssh.Auth - if d.GetSSHKeyPath() == "" { - auth = &ssh.Auth{} - } else { - auth = &ssh.Auth{ - Keys: []string{d.GetSSHKeyPath()}, - } - } - - client, err := ssh.NewClient(d.GetSSHUsername(), address, port, auth) - return client, err - -} - -func RunSSHCommandFromDriver(d Driver, command string) (string, error) { - client, err := GetSSHClientFromDriver(d) - if err != nil { - return "", err - } - - log.Debugf("About to run SSH command:\n%s", command) - - output, err := client.Output(command) - log.Debugf("SSH cmd err, output: %v: %s", err, output) - if err != nil { - return "", fmt.Errorf(`ssh command error: -command : %s -err : %v -output : %s`, command, err, output) - } - - return output, nil -} - -func sshAvailableFunc(d Driver) func() bool { - return func() bool { - log.Debug("Getting to WaitForSSH function...") - if _, err := RunSSHCommandFromDriver(d, "exit 0"); err != nil { - log.Debugf("Error getting ssh command 'exit 0' : %s", err) - return false - } - return true - } -} - -func WaitForSSH(d Driver) error { - // Try to dial SSH for 30 seconds before timing out. - if err := mcnutils.WaitFor(sshAvailableFunc(d)); err != nil { - return fmt.Errorf("Too many retries waiting for SSH to be available. Last error: %s", err) - } - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/engine/engine.go b/vendor/github.com/docker/machine/libmachine/engine/engine.go deleted file mode 100644 index 2910432..0000000 --- a/vendor/github.com/docker/machine/libmachine/engine/engine.go +++ /dev/null @@ -1,21 +0,0 @@ -package engine - -const ( - DefaultPort = 2376 -) - -type Options struct { - ArbitraryFlags []string - DNS []string `json:"Dns"` - GraphDir string - Env []string - Ipv6 bool - InsecureRegistry []string - Labels []string - LogLevel string - StorageDriver string - SelinuxEnabled bool - TLSVerify bool `json:"TlsVerify"` - RegistryMirror []string - InstallURL string -} diff --git a/vendor/github.com/docker/machine/libmachine/examples/main.go b/vendor/github.com/docker/machine/libmachine/examples/main.go deleted file mode 100644 index 7decc83..0000000 --- a/vendor/github.com/docker/machine/libmachine/examples/main.go +++ /dev/null @@ -1,145 +0,0 @@ -package main - -import ( - "bufio" - "encoding/json" - "fmt" - "os" - - "github.com/docker/machine/drivers/virtualbox" - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/log" -) - -func usage() { - fmt.Println("Usage: go run main.go \n" + - "Available examples: create streaming.") - os.Exit(1) -} - -// Sample Virtualbox create independent of Machine CLI. -func create() { - log.SetDebug(true) - - client := libmachine.NewClient("/tmp/automatic", "/tmp/automatic/certs") - defer client.Close() - - hostName := "myfunhost" - - // Set some options on the provider... - driver := virtualbox.NewDriver(hostName, "/tmp/automatic") - driver.CPU = 2 - driver.Memory = 2048 - - data, err := json.Marshal(driver) - if err != nil { - log.Error(err) - return - } - - h, err := client.NewHost("virtualbox", data) - if err != nil { - log.Error(err) - return - } - - h.HostOptions.EngineOptions.StorageDriver = "overlay" - - if err := client.Create(h); err != nil { - log.Error(err) - return - } - - out, err := h.RunSSHCommand("df -h") - if err != nil { - log.Error(err) - return - } - - fmt.Printf("Results of your disk space query:\n%s\n", out) - - fmt.Println("Powering down machine now...") - if err := h.Stop(); err != nil { - log.Error(err) - return - } -} - -// Streaming the output of an SSH session in virtualbox. -func streaming() { - log.SetDebug(true) - - client := libmachine.NewClient("/tmp/automatic", "/tmp/automatic/certs") - defer client.Close() - - hostName := "myfunhost" - - // Set some options on the provider... - driver := virtualbox.NewDriver(hostName, "/tmp/automatic") - data, err := json.Marshal(driver) - if err != nil { - log.Error(err) - return - } - - h, err := client.NewHost("virtualbox", data) - if err != nil { - log.Error(err) - return - } - - if err := client.Create(h); err != nil { - log.Error(err) - return - } - - h.HostOptions.EngineOptions.StorageDriver = "overlay" - - sshClient, err := h.CreateSSHClient() - if err != nil { - log.Error(err) - return - } - - stdout, stderr, err := sshClient.Start("yes | head -n 10000") - if err != nil { - log.Error(err) - return - } - defer func() { - _ = stdout.Close() - _ = stderr.Close() - }() - - scanner := bufio.NewScanner(stdout) - for scanner.Scan() { - fmt.Println(scanner.Text()) - } - if err := scanner.Err(); err != nil { - log.Error(err) - } - if err := sshClient.Wait(); err != nil { - log.Error(err) - } - - fmt.Println("Powering down machine now...") - if err := h.Stop(); err != nil { - log.Error(err) - return - } -} - -func main() { - if len(os.Args) != 2 { - usage() - } - - switch os.Args[1] { - case "create": - create() - case "streaming": - streaming() - default: - usage() - } -} diff --git a/vendor/github.com/docker/machine/libmachine/host/host.go b/vendor/github.com/docker/machine/libmachine/host/host.go deleted file mode 100644 index 1f1e1bb..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/host.go +++ /dev/null @@ -1,277 +0,0 @@ -package host - -import ( - "regexp" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcndockerclient" - "github.com/docker/machine/libmachine/mcnerror" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/provision" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" - "github.com/docker/machine/libmachine/swarm" - "github.com/docker/machine/libmachine/versioncmp" -) - -var ( - validHostNamePattern = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9\-\.]*$`) - stdSSHClientCreator SSHClientCreator = &StandardSSHClientCreator{} -) - -type SSHClientCreator interface { - CreateSSHClient(d drivers.Driver) (ssh.Client, error) -} - -type StandardSSHClientCreator struct { - drivers.Driver -} - -func SetSSHClientCreator(creator SSHClientCreator) { - stdSSHClientCreator = creator -} - -type Host struct { - ConfigVersion int - Driver drivers.Driver - DriverName string - HostOptions *Options - Name string - RawDriver []byte `json:"-"` -} - -type Options struct { - Driver string - Memory int - Disk int - EngineOptions *engine.Options - SwarmOptions *swarm.Options - AuthOptions *auth.Options -} - -type Metadata struct { - ConfigVersion int - DriverName string - HostOptions Options -} - -func ValidateHostName(name string) bool { - return validHostNamePattern.MatchString(name) -} - -func (h *Host) RunSSHCommand(command string) (string, error) { - return drivers.RunSSHCommandFromDriver(h.Driver, command) -} - -func (h *Host) CreateSSHClient() (ssh.Client, error) { - return stdSSHClientCreator.CreateSSHClient(h.Driver) -} - -func (creator *StandardSSHClientCreator) CreateSSHClient(d drivers.Driver) (ssh.Client, error) { - addr, err := d.GetSSHHostname() - if err != nil { - return &ssh.ExternalClient{}, err - } - - port, err := d.GetSSHPort() - if err != nil { - return &ssh.ExternalClient{}, err - } - - auth := &ssh.Auth{} - if d.GetSSHKeyPath() != "" { - auth.Keys = []string{d.GetSSHKeyPath()} - } - - return ssh.NewClient(d.GetSSHUsername(), addr, port, auth) -} - -func (h *Host) runActionForState(action func() error, desiredState state.State) error { - if drivers.MachineInState(h.Driver, desiredState)() { - return mcnerror.ErrHostAlreadyInState{ - Name: h.Name, - State: desiredState, - } - } - - if err := action(); err != nil { - return err - } - - return mcnutils.WaitFor(drivers.MachineInState(h.Driver, desiredState)) -} - -func (h *Host) WaitForDocker() error { - provisioner, err := provision.DetectProvisioner(h.Driver) - if err != nil { - return err - } - - return provision.WaitForDocker(provisioner, engine.DefaultPort) -} - -func (h *Host) Start() error { - log.Infof("Starting %q...", h.Name) - if err := h.runActionForState(h.Driver.Start, state.Running); err != nil { - return err - } - - log.Infof("Machine %q was started.", h.Name) - - return h.WaitForDocker() -} - -func (h *Host) Stop() error { - log.Infof("Stopping %q...", h.Name) - if err := h.runActionForState(h.Driver.Stop, state.Stopped); err != nil { - return err - } - - log.Infof("Machine %q was stopped.", h.Name) - return nil -} - -func (h *Host) Kill() error { - log.Infof("Killing %q...", h.Name) - if err := h.runActionForState(h.Driver.Kill, state.Stopped); err != nil { - return err - } - - log.Infof("Machine %q was killed.", h.Name) - return nil -} - -func (h *Host) Restart() error { - log.Infof("Restarting %q...", h.Name) - if drivers.MachineInState(h.Driver, state.Stopped)() { - if err := h.Start(); err != nil { - return err - } - } else if drivers.MachineInState(h.Driver, state.Running)() { - if err := h.Driver.Restart(); err != nil { - return err - } - if err := mcnutils.WaitFor(drivers.MachineInState(h.Driver, state.Running)); err != nil { - return err - } - } - - return h.WaitForDocker() -} - -func (h *Host) DockerVersion() (string, error) { - url, err := h.Driver.GetURL() - if err != nil { - return "", err - } - - dockerHost := &mcndockerclient.RemoteDocker{ - HostURL: url, - AuthOption: h.AuthOptions(), - } - dockerVersion, err := mcndockerclient.DockerVersion(dockerHost) - if err != nil { - return "", err - } - - return dockerVersion, nil -} - -func (h *Host) Upgrade() error { - machineState, err := h.Driver.GetState() - if err != nil { - return err - } - - if machineState != state.Running { - log.Info("Starting machine so machine can be upgraded...") - if err := h.Start(); err != nil { - return err - } - } - - provisioner, err := provision.DetectProvisioner(h.Driver) - if err != nil { - return err - } - - dockerVersion, err := h.DockerVersion() - if err != nil { - return err - } - - // If we're upgrading from a pre-CE (e.g., 1.13.1) release to a CE - // release (e.g., 17.03.0-ce), we should simply uninstall and - // re-install from scratch, since the official package names will - // change from 'docker-engine' to 'docker-ce'. - if versioncmp.LessThanOrEqualTo(dockerVersion, provision.LastReleaseBeforeCEVersioning) && - // RancherOS and boot2docker, being 'static ISO builds', have - // an upgrade process which simply grabs the latest if it's - // different, and so do not need to jump through this hoop to - // upgrade safely. - provisioner.String() != "rancheros" && - provisioner.String() != "boot2docker" { - - // Name of package 'docker-engine' will fall through in this - // case, so that we execute, e.g., - // - // 'sudo apt-get purge -y docker-engine' - if err := provisioner.Package("docker-engine", pkgaction.Purge); err != nil { - return err - } - - // Then we kick off the normal provisioning process which will - // go off and install Docker (get.docker.com script should work - // fine to install Docker from scratch after removing the old - // packages, and images/containers etc. should be preserved in - // /var/lib/docker) - return h.Provision() - } - - log.Info("Upgrading docker...") - if err := provisioner.Package("docker", pkgaction.Upgrade); err != nil { - return err - } - - log.Info("Restarting docker...") - return provisioner.Service("docker", serviceaction.Restart) -} - -func (h *Host) URL() (string, error) { - return h.Driver.GetURL() -} - -func (h *Host) AuthOptions() *auth.Options { - if h.HostOptions == nil { - return nil - } - return h.HostOptions.AuthOptions -} - -func (h *Host) ConfigureAuth() error { - provisioner, err := provision.DetectProvisioner(h.Driver) - if err != nil { - return err - } - - // TODO: This is kind of a hack (or is it? I'm not really sure until - // we have more clearly defined outlook on what the responsibilities - // and modularity of the provisioners should be). - // - // Call provision to re-provision the certs properly. - return provisioner.Provision(swarm.Options{}, *h.HostOptions.AuthOptions, *h.HostOptions.EngineOptions) -} - -func (h *Host) Provision() error { - provisioner, err := provision.DetectProvisioner(h.Driver) - if err != nil { - return err - } - - return provisioner.Provision(*h.HostOptions.SwarmOptions, *h.HostOptions.AuthOptions, *h.HostOptions.EngineOptions) -} diff --git a/vendor/github.com/docker/machine/libmachine/host/host_test.go b/vendor/github.com/docker/machine/libmachine/host/host_test.go deleted file mode 100644 index a418506..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/host_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package host - -import ( - "testing" - - "github.com/docker/machine/drivers/fakedriver" - _ "github.com/docker/machine/drivers/none" - "github.com/docker/machine/libmachine/provision" - "github.com/docker/machine/libmachine/state" -) - -func TestValidateHostnameValid(t *testing.T) { - hosts := []string{ - "zomg", - "test-ing", - "some.h0st", - } - - for _, v := range hosts { - isValid := ValidateHostName(v) - if !isValid { - t.Fatalf("Thought a valid hostname was invalid: %s", v) - } - } -} - -func TestValidateHostnameInvalid(t *testing.T) { - hosts := []string{ - "zom_g", - "test$ing", - "some😄host", - } - - for _, v := range hosts { - isValid := ValidateHostName(v) - if isValid { - t.Fatalf("Thought an invalid hostname was valid: %s", v) - } - } -} - -func TestStart(t *testing.T) { - defer provision.SetDetector(&provision.StandardDetector{}) - provision.SetDetector(&provision.FakeDetector{ - Provisioner: provision.NewNetstatProvisioner(), - }) - - host := &Host{ - Driver: &fakedriver.Driver{ - MockState: state.Stopped, - }, - } - - if err := host.Start(); err != nil { - t.Fatalf("Expected no error but got one: %s", err) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/host/host_v0.go b/vendor/github.com/docker/machine/libmachine/host/host_v0.go deleted file mode 100644 index a36db5f..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/host_v0.go +++ /dev/null @@ -1,35 +0,0 @@ -package host - -import "github.com/docker/machine/libmachine/drivers" - -type V0 struct { - Name string `json:"-"` - Driver drivers.Driver - DriverName string - ConfigVersion int - HostOptions *Options - - StorePath string - CaCertPath string - PrivateKeyPath string - ServerCertPath string - ServerKeyPath string - ClientCertPath string - SwarmHost string - SwarmMaster bool - SwarmDiscovery string - ClientKeyPath string -} - -type MetadataV0 struct { - HostOptions Options - DriverName string - - ConfigVersion int - StorePath string - CaCertPath string - PrivateKeyPath string - ServerCertPath string - ServerKeyPath string - ClientCertPath string -} diff --git a/vendor/github.com/docker/machine/libmachine/host/host_v2.go b/vendor/github.com/docker/machine/libmachine/host/host_v2.go deleted file mode 100644 index 8157e5f..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/host_v2.go +++ /dev/null @@ -1,11 +0,0 @@ -package host - -import "github.com/docker/machine/libmachine/drivers" - -type V2 struct { - ConfigVersion int - Driver drivers.Driver - DriverName string - HostOptions *Options - Name string -} diff --git a/vendor/github.com/docker/machine/libmachine/host/migrate.go b/vendor/github.com/docker/machine/libmachine/host/migrate.go deleted file mode 100644 index 7134240..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/migrate.go +++ /dev/null @@ -1,120 +0,0 @@ -package host - -import ( - "encoding/json" - "errors" - "fmt" - "path/filepath" - - "github.com/docker/machine/drivers/none" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/version" -) - -var ( - errConfigFromFuture = errors.New("config version is from the future -- you should upgrade your Docker Machine client") -) - -type RawDataDriver struct { - *none.Driver - Data []byte // passed directly back when invoking json.Marshal on this type -} - -func (r *RawDataDriver) MarshalJSON() ([]byte, error) { - return r.Data, nil -} - -func (r *RawDataDriver) UnmarshalJSON(data []byte) error { - r.Data = data - return nil -} - -func getMigratedHostMetadata(data []byte) (*Metadata, error) { - // HostMetadata is for a "first pass" so we can then load the driver - var ( - hostMetadata *MetadataV0 - ) - - if err := json.Unmarshal(data, &hostMetadata); err != nil { - return &Metadata{}, err - } - - migratedHostMetadata := MigrateHostMetadataV0ToHostMetadataV1(hostMetadata) - - return migratedHostMetadata, nil -} - -func MigrateHost(h *Host, data []byte) (*Host, bool, error) { - var ( - migrationNeeded = false - migrationPerformed = false - hostV1 *V1 - hostV2 *V2 - ) - - migratedHostMetadata, err := getMigratedHostMetadata(data) - if err != nil { - return nil, false, err - } - - globalStorePath := filepath.Dir(filepath.Dir(migratedHostMetadata.HostOptions.AuthOptions.StorePath)) - - driver := &RawDataDriver{none.NewDriver(h.Name, globalStorePath), nil} - - if migratedHostMetadata.ConfigVersion > version.ConfigVersion { - return nil, false, errConfigFromFuture - } - - if migratedHostMetadata.ConfigVersion == version.ConfigVersion { - h.Driver = driver - if err := json.Unmarshal(data, &h); err != nil { - return nil, migrationPerformed, fmt.Errorf("Error unmarshalling most recent host version: %s", err) - } - } else { - migrationNeeded = true - } - - if migrationNeeded { - migrationPerformed = true - for h.ConfigVersion = migratedHostMetadata.ConfigVersion; h.ConfigVersion < version.ConfigVersion; h.ConfigVersion++ { - log.Debugf("Migrating to config v%d", h.ConfigVersion) - switch h.ConfigVersion { - case 0: - hostV0 := &V0{ - Driver: driver, - } - if err := json.Unmarshal(data, &hostV0); err != nil { - return nil, migrationPerformed, fmt.Errorf("Error unmarshalling host config version 0: %s", err) - } - hostV1 = MigrateHostV0ToHostV1(hostV0) - case 1: - if hostV1 == nil { - hostV1 = &V1{ - Driver: driver, - } - if err := json.Unmarshal(data, &hostV1); err != nil { - return nil, migrationPerformed, fmt.Errorf("Error unmarshalling host config version 1: %s", err) - } - } - hostV2 = MigrateHostV1ToHostV2(hostV1) - case 2: - if hostV2 == nil { - hostV2 = &V2{ - Driver: driver, - } - if err := json.Unmarshal(data, &hostV2); err != nil { - return nil, migrationPerformed, fmt.Errorf("Error unmarshalling host config version 2: %s", err) - } - } - h = MigrateHostV2ToHostV3(hostV2, data, globalStorePath) - driver.Data = h.RawDriver - h.Driver = driver - case 3: - } - } - } - - h.RawDriver = driver.Data - - return h, migrationPerformed, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/host/migrate_test.go b/vendor/github.com/docker/machine/libmachine/host/migrate_test.go deleted file mode 100644 index 7b839bb..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/migrate_test.go +++ /dev/null @@ -1,180 +0,0 @@ -package host - -import ( - "testing" - - "github.com/docker/machine/drivers/none" - "github.com/docker/machine/libmachine/auth" - "github.com/stretchr/testify/assert" -) - -func TestMigrateHost(t *testing.T) { - testCases := []struct { - description string - hostBefore *Host - rawData []byte - expectedHostAfter *Host - expectedMigrationPerformed bool - expectedMigrationError error - }{ - { - // Point of this test is largely that no matter what was in RawDriver - // before, it should load into the Host struct based on what is actually - // in the Driver field. - // - // Note that we don't check for the presence of RawDriver's literal "on - // disk" here. It's intentional. - description: "Config version 3 load with existing RawDriver on disk", - hostBefore: &Host{ - Name: "default", - }, - rawData: []byte(`{ - "ConfigVersion": 3, - "Driver": {"MachineName": "default"}, - "DriverName": "virtualbox", - "HostOptions": { - "Driver": "", - "Memory": 0, - "Disk": 0, - "AuthOptions": { - "StorePath": "/Users/nathanleclaire/.docker/machine/machines/default" - } - }, - "Name": "default", - "RawDriver": "eyJWQm94TWFuYWdlciI6e30sIklQQWRkcmVzcyI6IjE5Mi4xNjguOTkuMTAwIiwiTWFjaGluZU5hbWUiOiJkZWZhdWx0IiwiU1NIVXNlciI6ImRvY2tlciIsIlNTSFBvcnQiOjU4MTQ1LCJTU0hLZXlQYXRoIjoiL1VzZXJzL25hdGhhbmxlY2xhaXJlLy5kb2NrZXIvbWFjaGluZS9tYWNoaW5lcy9kZWZhdWx0L2lkX3JzYSIsIlN0b3JlUGF0aCI6Ii9Vc2Vycy9uYXRoYW5sZWNsYWlyZS8uZG9ja2VyL21hY2hpbmUiLCJTd2FybU1hc3RlciI6ZmFsc2UsIlN3YXJtSG9zdCI6InRjcDovLzAuMC4wLjA6MzM3NiIsIlN3YXJtRGlzY292ZXJ5IjoiIiwiQ1BVIjoxLCJNZW1vcnkiOjEwMjQsIkRpc2tTaXplIjoyMDAwMCwiQm9vdDJEb2NrZXJVUkwiOiIiLCJCb290MkRvY2tlckltcG9ydFZNIjoiIiwiSG9zdE9ubHlDSURSIjoiMTkyLjE2OC45OS4xLzI0IiwiSG9zdE9ubHlOaWNUeXBlIjoiODI1NDBFTSIsIkhvc3RPbmx5UHJvbWlzY01vZGUiOiJkZW55IiwiTm9TaGFyZSI6ZmFsc2V9" -}`), - expectedHostAfter: &Host{ - ConfigVersion: 3, - HostOptions: &Options{ - AuthOptions: &auth.Options{ - StorePath: "/Users/nathanleclaire/.docker/machine/machines/default", - }, - }, - Name: "default", - DriverName: "virtualbox", - RawDriver: []byte(`{"MachineName": "default"}`), - Driver: &RawDataDriver{ - Data: []byte(`{"MachineName": "default"}`), - - // TODO (nathanleclaire): The "." argument here is a already existing - // bug (or at least likely to cause them in the future) and most - // likely should be "/Users/nathanleclaire/.docker/machine" - // - // These default StorePath settings get over-written when we - // instantiate the plugin driver, but this seems entirely incidental. - Driver: none.NewDriver("default", "."), - }, - }, - expectedMigrationPerformed: false, - expectedMigrationError: nil, - }, - { - description: "Config version 4 (from the FUTURE) on disk", - hostBefore: &Host{ - Name: "default", - }, - rawData: []byte(`{ - "ConfigVersion": 4, - "Driver": {"MachineName": "default"}, - "DriverName": "virtualbox", - "HostOptions": { - "Driver": "", - "Memory": 0, - "Disk": 0, - "AuthOptions": { - "StorePath": "/Users/nathanleclaire/.docker/machine/machines/default" - } - }, - "Name": "default" -}`), - expectedHostAfter: nil, - expectedMigrationPerformed: false, - expectedMigrationError: errConfigFromFuture, - }, - { - description: "Config version 3 load WITHOUT any existing RawDriver field on disk", - hostBefore: &Host{ - Name: "default", - }, - rawData: []byte(`{ - "ConfigVersion": 3, - "Driver": {"MachineName": "default"}, - "DriverName": "virtualbox", - "HostOptions": { - "Driver": "", - "Memory": 0, - "Disk": 0, - "AuthOptions": { - "StorePath": "/Users/nathanleclaire/.docker/machine/machines/default" - } - }, - "Name": "default" -}`), - expectedHostAfter: &Host{ - ConfigVersion: 3, - HostOptions: &Options{ - AuthOptions: &auth.Options{ - StorePath: "/Users/nathanleclaire/.docker/machine/machines/default", - }, - }, - Name: "default", - DriverName: "virtualbox", - RawDriver: []byte(`{"MachineName": "default"}`), - Driver: &RawDataDriver{ - Data: []byte(`{"MachineName": "default"}`), - - // TODO: See note above. - Driver: none.NewDriver("default", "."), - }, - }, - expectedMigrationPerformed: false, - expectedMigrationError: nil, - }, - { - description: "Config version 2 load and migrate. Ensure StorePath gets set properly.", - hostBefore: &Host{ - Name: "default", - }, - rawData: []byte(`{ - "ConfigVersion": 2, - "Driver": {"MachineName": "default"}, - "DriverName": "virtualbox", - "HostOptions": { - "Driver": "", - "Memory": 0, - "Disk": 0, - "AuthOptions": { - "StorePath": "/Users/nathanleclaire/.docker/machine/machines/default" - } - }, - "StorePath": "/Users/nathanleclaire/.docker/machine/machines/default", - "Name": "default" -}`), - expectedHostAfter: &Host{ - ConfigVersion: 3, - HostOptions: &Options{ - AuthOptions: &auth.Options{ - StorePath: "/Users/nathanleclaire/.docker/machine/machines/default", - }, - }, - Name: "default", - DriverName: "virtualbox", - RawDriver: []byte(`{"MachineName":"default","StorePath":"/Users/nathanleclaire/.docker/machine"}`), - Driver: &RawDataDriver{ - Data: []byte(`{"MachineName":"default","StorePath":"/Users/nathanleclaire/.docker/machine"}`), - Driver: none.NewDriver("default", "/Users/nathanleclaire/.docker/machine"), - }, - }, - expectedMigrationPerformed: true, - expectedMigrationError: nil, - }, - } - - for _, tc := range testCases { - actualHostAfter, actualMigrationPerformed, actualMigrationError := MigrateHost(tc.hostBefore, tc.rawData) - - assert.Equal(t, tc.expectedHostAfter, actualHostAfter) - assert.Equal(t, tc.expectedMigrationPerformed, actualMigrationPerformed) - assert.Equal(t, tc.expectedMigrationError, actualMigrationError) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/host/migrate_v0_v1.go b/vendor/github.com/docker/machine/libmachine/host/migrate_v0_v1.go deleted file mode 100644 index 6460d38..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/migrate_v0_v1.go +++ /dev/null @@ -1,73 +0,0 @@ -package host - -import ( - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/swarm" -) - -// In the 0.1.0 => 0.2.0 transition, the JSON representation of -// machines changed from a "flat" to a more "nested" structure -// for various options and configuration settings. To preserve -// compatibility with existing machines, these migration functions -// have been introduced. They preserve backwards compat at the expense -// of some duplicated information. - -// MigrateHostV0ToHostV1 validates host config and modifies if needed -// this is used for configuration updates -func MigrateHostV0ToHostV1(hostV0 *V0) *V1 { - hostV1 := &V1{ - Driver: hostV0.Driver, - DriverName: hostV0.DriverName, - } - - hostV1.HostOptions = &OptionsV1{} - hostV1.HostOptions.EngineOptions = &engine.Options{ - TLSVerify: true, - InstallURL: "https://get.docker.com", - } - hostV1.HostOptions.SwarmOptions = &swarm.Options{ - Address: "", - Discovery: hostV0.SwarmDiscovery, - Host: hostV0.SwarmHost, - Master: hostV0.SwarmMaster, - } - hostV1.HostOptions.AuthOptions = &AuthOptionsV1{ - StorePath: hostV0.StorePath, - CaCertPath: hostV0.CaCertPath, - CaCertRemotePath: "", - ServerCertPath: hostV0.ServerCertPath, - ServerKeyPath: hostV0.ServerKeyPath, - ClientKeyPath: hostV0.ClientKeyPath, - ServerCertRemotePath: "", - ServerKeyRemotePath: "", - PrivateKeyPath: hostV0.PrivateKeyPath, - ClientCertPath: hostV0.ClientCertPath, - } - - return hostV1 -} - -// MigrateHostMetadataV0ToHostMetadataV1 fills nested host metadata and modifies if needed -// this is used for configuration updates -func MigrateHostMetadataV0ToHostMetadataV1(m *MetadataV0) *Metadata { - hostMetadata := &Metadata{} - hostMetadata.DriverName = m.DriverName - hostMetadata.HostOptions.EngineOptions = &engine.Options{} - hostMetadata.HostOptions.AuthOptions = &auth.Options{ - StorePath: m.StorePath, - CaCertPath: m.CaCertPath, - CaCertRemotePath: "", - ServerCertPath: m.ServerCertPath, - ServerKeyPath: m.ServerKeyPath, - ClientKeyPath: "", - ServerCertRemotePath: "", - ServerKeyRemotePath: "", - CaPrivateKeyPath: m.PrivateKeyPath, - ClientCertPath: m.ClientCertPath, - } - - hostMetadata.ConfigVersion = m.ConfigVersion - - return hostMetadata -} diff --git a/vendor/github.com/docker/machine/libmachine/host/migrate_v0_v1_test.go b/vendor/github.com/docker/machine/libmachine/host/migrate_v0_v1_test.go deleted file mode 100644 index 689c74b..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/migrate_v0_v1_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package host - -import ( - "reflect" - "testing" - - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/swarm" -) - -func TestMigrateHostV0ToV1(t *testing.T) { - mcndirs.BaseDir = "/tmp/migration" - originalHost := &V0{ - HostOptions: nil, - SwarmDiscovery: "token://foobar", - SwarmHost: "1.2.3.4:2376", - SwarmMaster: true, - CaCertPath: "/tmp/migration/certs/ca.pem", - PrivateKeyPath: "/tmp/migration/certs/ca-key.pem", - ClientCertPath: "/tmp/migration/certs/cert.pem", - ClientKeyPath: "/tmp/migration/certs/key.pem", - ServerCertPath: "/tmp/migration/certs/server.pem", - ServerKeyPath: "/tmp/migration/certs/server-key.pem", - } - hostOptions := &OptionsV1{ - SwarmOptions: &swarm.Options{ - Master: true, - Discovery: "token://foobar", - Host: "1.2.3.4:2376", - }, - AuthOptions: &AuthOptionsV1{ - CaCertPath: "/tmp/migration/certs/ca.pem", - PrivateKeyPath: "/tmp/migration/certs/ca-key.pem", - ClientCertPath: "/tmp/migration/certs/cert.pem", - ClientKeyPath: "/tmp/migration/certs/key.pem", - ServerCertPath: "/tmp/migration/certs/server.pem", - ServerKeyPath: "/tmp/migration/certs/server-key.pem", - }, - EngineOptions: &engine.Options{ - InstallURL: "https://get.docker.com", - TLSVerify: true, - }, - } - - expectedHost := &V1{ - HostOptions: hostOptions, - } - - host := MigrateHostV0ToHostV1(originalHost) - - if !reflect.DeepEqual(host, expectedHost) { - t.Logf("\n%+v\n%+v", host, expectedHost) - t.Logf("\n%+v\n%+v", host.HostOptions, expectedHost.HostOptions) - t.Fatal("Expected these structs to be equal, they were different") - } -} - -func TestMigrateHostMetadataV0ToV1(t *testing.T) { - metadata := &MetadataV0{ - HostOptions: Options{ - EngineOptions: nil, - AuthOptions: nil, - }, - StorePath: "/tmp/store", - CaCertPath: "/tmp/store/certs/ca.pem", - ServerCertPath: "/tmp/store/certs/server.pem", - } - expectedAuthOptions := &auth.Options{ - StorePath: "/tmp/store", - CaCertPath: "/tmp/store/certs/ca.pem", - ServerCertPath: "/tmp/store/certs/server.pem", - } - - expectedMetadata := &Metadata{ - HostOptions: Options{ - EngineOptions: &engine.Options{}, - AuthOptions: expectedAuthOptions, - }, - } - - m := MigrateHostMetadataV0ToHostMetadataV1(metadata) - - if !reflect.DeepEqual(m, expectedMetadata) { - t.Logf("\n%+v\n%+v", m, expectedMetadata) - t.Fatal("Expected these structs to be equal, they were different") - } -} diff --git a/vendor/github.com/docker/machine/libmachine/host/migrate_v0_v3_test.go b/vendor/github.com/docker/machine/libmachine/host/migrate_v0_v3_test.go deleted file mode 100644 index b5aecfd..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/migrate_v0_v3_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package host - -import "testing" - -var ( - v0conf = []byte(`{"DriverName":"virtualbox","Driver":{"IPAddress":"192.168.99.100","SSHUser":"docker","SSHPort":53507,"MachineName":"dev","CaCertPath":"/Users/ljrittle/.docker/machine/certs/ca.pem","PrivateKeyPath":"/Users/ljrittle/.docker/machine/certs/ca-key.pem","SwarmMaster":false,"SwarmHost":"tcp://0.0.0.0:3376","SwarmDiscovery":"","CPU":-1,"Memory":1024,"DiskSize":20000,"Boot2DockerURL":"","Boot2DockerImportVM":"","HostOnlyCIDR":""},"StorePath":"/Users/ljrittle/.docker/machine/machines/dev","HostOptions":{"Driver":"","Memory":0,"Disk":0,"EngineOptions":{"ArbitraryFlags":null,"Dns":null,"GraphDir":"","Ipv6":false,"InsecureRegistry":null,"Labels":null,"LogLevel":"","StorageDriver":"","SelinuxEnabled":false,"TlsCaCert":"","TlsCert":"","TlsKey":"","TlsVerify":false,"RegistryMirror":null,"InstallURL":""},"SwarmOptions":{"IsSwarm":false,"Address":"","Discovery":"","Master":false,"Host":"tcp://0.0.0.0:3376","Image":"","Strategy":"","Heartbeat":0,"Overcommit":0,"TlsCaCert":"","TlsCert":"","TlsKey":"","TlsVerify":false,"ArbitraryFlags":null},"AuthOptions":{"StorePath":"/Users/ljrittle/.docker/machine/machines/dev","CaCertPath":"/Users/ljrittle/.docker/machine/certs/ca.pem","CaCertRemotePath":"","ServerCertPath":"/Users/ljrittle/.docker/machine/certs/server.pem","ServerKeyPath":"/Users/ljrittle/.docker/machine/certs/server-key.pem","ClientKeyPath":"/Users/ljrittle/.docker/machine/certs/key.pem","ServerCertRemotePath":"","ServerKeyRemotePath":"","PrivateKeyPath":"/Users/ljrittle/.docker/machine/certs/ca-key.pem","ClientCertPath":"/Users/ljrittle/.docker/machine/certs/cert.pem"}}}`) -) - -func TestMigrateHostV0ToHostV3(t *testing.T) { - h := &Host{} - migratedHost, migrationPerformed, err := MigrateHost(h, v0conf) - if err != nil { - t.Fatalf("Error attempting to migrate host: %s", err) - } - - if !migrationPerformed { - t.Fatal("Expected a migration to be reported as performed but it was not") - } - - if migratedHost.DriverName != "virtualbox" { - t.Fatalf("Expected %q, got %q for the driver name", "virtualbox", migratedHost.DriverName) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/host/migrate_v1_v2.go b/vendor/github.com/docker/machine/libmachine/host/migrate_v1_v2.go deleted file mode 100644 index 6931993..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/migrate_v1_v2.go +++ /dev/null @@ -1,78 +0,0 @@ -package host - -import ( - "path/filepath" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/swarm" -) - -type AuthOptionsV1 struct { - StorePath string - CaCertPath string - CaCertRemotePath string - ServerCertPath string - ServerKeyPath string - ClientKeyPath string - ServerCertRemotePath string - ServerKeyRemotePath string - PrivateKeyPath string - ClientCertPath string -} - -type OptionsV1 struct { - Driver string - Memory int - Disk int - EngineOptions *engine.Options - SwarmOptions *swarm.Options - AuthOptions *AuthOptionsV1 -} - -type V1 struct { - ConfigVersion int - Driver drivers.Driver - DriverName string - HostOptions *OptionsV1 - Name string `json:"-"` - StorePath string -} - -func MigrateHostV1ToHostV2(hostV1 *V1) *V2 { - // Changed: Put StorePath directly in AuthOptions (for provisioning), - // and AuthOptions.PrivateKeyPath => AuthOptions.CaPrivateKeyPath - // Also, CertDir has been added. - - globalStorePath := filepath.Dir(filepath.Dir(hostV1.StorePath)) - - h := &V2{ - ConfigVersion: hostV1.ConfigVersion, - Driver: hostV1.Driver, - Name: hostV1.Driver.GetMachineName(), - DriverName: hostV1.DriverName, - HostOptions: &Options{ - Driver: hostV1.HostOptions.Driver, - Memory: hostV1.HostOptions.Memory, - Disk: hostV1.HostOptions.Disk, - EngineOptions: hostV1.HostOptions.EngineOptions, - SwarmOptions: hostV1.HostOptions.SwarmOptions, - AuthOptions: &auth.Options{ - CertDir: filepath.Join(globalStorePath, "certs"), - CaCertPath: hostV1.HostOptions.AuthOptions.CaCertPath, - CaPrivateKeyPath: hostV1.HostOptions.AuthOptions.PrivateKeyPath, - CaCertRemotePath: hostV1.HostOptions.AuthOptions.CaCertRemotePath, - ServerCertPath: hostV1.HostOptions.AuthOptions.ServerCertPath, - ServerKeyPath: hostV1.HostOptions.AuthOptions.ServerKeyPath, - ClientKeyPath: hostV1.HostOptions.AuthOptions.ClientKeyPath, - ServerCertRemotePath: hostV1.HostOptions.AuthOptions.ServerCertRemotePath, - ServerKeyRemotePath: hostV1.HostOptions.AuthOptions.ServerKeyRemotePath, - ClientCertPath: hostV1.HostOptions.AuthOptions.ClientCertPath, - StorePath: globalStorePath, - }, - }, - } - - return h -} diff --git a/vendor/github.com/docker/machine/libmachine/host/migrate_v1_v2_test.go b/vendor/github.com/docker/machine/libmachine/host/migrate_v1_v2_test.go deleted file mode 100644 index f7f99f4..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/migrate_v1_v2_test.go +++ /dev/null @@ -1,108 +0,0 @@ -package host - -import ( - "path/filepath" - "testing" -) - -var ( - v1conf = []byte(`{ - "ConfigVersion": 1, - "Driver": { - "IPAddress": "192.168.99.100", - "SSHUser": "docker", - "SSHPort": 64477, - "MachineName": "foobar", - "CaCertPath": "/Users/catbug/.docker/machine/certs/ca.pem", - "PrivateKeyPath": "/Users/catbug/.docker/machine/certs/ca-key.pem", - "SwarmMaster": false, - "SwarmHost": "tcp://0.0.0.0:3376", - "SwarmDiscovery": "", - "CPU": 1, - "Memory": 1024, - "DiskSize": 20000, - "Boot2DockerURL": "", - "Boot2DockerImportVM": "", - "HostOnlyCIDR": "192.168.99.1/24" - }, - "DriverName": "virtualbox", - "HostOptions": { - "Driver": "", - "Memory": 0, - "Disk": 0, - "EngineOptions": { - "ArbitraryFlags": [], - "Dns": null, - "GraphDir": "", - "Env": [], - "Ipv6": false, - "InsecureRegistry": [], - "Labels": [], - "LogLevel": "", - "StorageDriver": "", - "SelinuxEnabled": false, - "TlsCaCert": "", - "TlsCert": "", - "TlsKey": "", - "TlsVerify": true, - "RegistryMirror": [], - "InstallURL": "https://get.docker.com" - }, - "SwarmOptions": { - "IsSwarm": false, - "Address": "", - "Discovery": "", - "Master": false, - "Host": "tcp://0.0.0.0:3376", - "Image": "swarm:latest", - "Strategy": "spread", - "Heartbeat": 0, - "Overcommit": 0, - "TlsCaCert": "", - "TlsCert": "", - "TlsKey": "", - "TlsVerify": false, - "ArbitraryFlags": [] - }, - "AuthOptions": { - "StorePath": "", - "CaCertPath": "/Users/catbug/.docker/machine/certs/ca.pem", - "CaCertRemotePath": "", - "ServerCertPath": "/Users/catbug/.docker/machine/machines/foobar/server.pem", - "ServerKeyPath": "/Users/catbug/.docker/machine/machines/foobar/server-key.pem", - "ClientKeyPath": "/Users/catbug/.docker/machine/certs/key.pem", - "ServerCertRemotePath": "", - "ServerKeyRemotePath": "", - "PrivateKeyPath": "/Users/catbug/.docker/machine/certs/ca-key.pem", - "ClientCertPath": "/Users/catbug/.docker/machine/certs/cert.pem" - } - }, - "StorePath": "/Users/catbug/.docker/machine/machines/foobar" -}`) -) - -func TestMigrateHostV1ToHostV2(t *testing.T) { - h := &Host{} - expectedGlobalStorePath := "/Users/catbug/.docker/machine" - expectedCaPrivateKeyPath := "/Users/catbug/.docker/machine/certs/ca-key.pem" - migratedHost, migrationPerformed, err := MigrateHost(h, v1conf) - if err != nil { - t.Fatalf("Error attempting to migrate host: %s", err) - } - - if !migrationPerformed { - t.Fatal("Expected a migration to be reported as performed but it was not") - } - - if migratedHost.HostOptions.AuthOptions.StorePath != expectedGlobalStorePath { - t.Fatalf("Expected %q, got %q for the store path in AuthOptions", migratedHost.HostOptions.AuthOptions.StorePath, expectedGlobalStorePath) - } - - if migratedHost.HostOptions.AuthOptions.CaPrivateKeyPath != expectedCaPrivateKeyPath { - t.Fatalf("Expected %q, got %q for the private key path in AuthOptions", migratedHost.HostOptions.AuthOptions.CaPrivateKeyPath, expectedCaPrivateKeyPath) - } - - if migratedHost.HostOptions.AuthOptions.CertDir != filepath.Join(expectedGlobalStorePath, "certs") { - t.Fatalf("Expected %q, got %q for the cert dir in AuthOptions", migratedHost.HostOptions.AuthOptions.CaPrivateKeyPath, expectedGlobalStorePath) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/host/migrate_v2_v3.go b/vendor/github.com/docker/machine/libmachine/host/migrate_v2_v3.go deleted file mode 100644 index 12bcbe5..0000000 --- a/vendor/github.com/docker/machine/libmachine/host/migrate_v2_v3.go +++ /dev/null @@ -1,49 +0,0 @@ -package host - -import ( - "bytes" - "encoding/json" - - "github.com/docker/machine/libmachine/log" -) - -type RawHost struct { - Driver *json.RawMessage -} - -func MigrateHostV2ToHostV3(hostV2 *V2, data []byte, storePath string) *Host { - // Migrate to include RawDriver so that driver plugin will work - // smoothly. - rawHost := &RawHost{} - if err := json.Unmarshal(data, &rawHost); err != nil { - log.Warnf("Could not unmarshal raw host for RawDriver information: %s", err) - } - - m := make(map[string]interface{}) - - // Must migrate to include store path in driver since it was not - // previously stored in drivers directly - d := json.NewDecoder(bytes.NewReader(*rawHost.Driver)) - d.UseNumber() - if err := d.Decode(&m); err != nil { - log.Warnf("Could not unmarshal raw host into map[string]interface{}: %s", err) - } - - m["StorePath"] = storePath - - // Now back to []byte - rawDriver, err := json.Marshal(m) - if err != nil { - log.Warnf("Could not re-marshal raw driver: %s", err) - } - - h := &Host{ - ConfigVersion: 2, - DriverName: hostV2.DriverName, - Name: hostV2.Name, - HostOptions: hostV2.HostOptions, - RawDriver: rawDriver, - } - - return h -} diff --git a/vendor/github.com/docker/machine/libmachine/hosttest/default_test_host.go b/vendor/github.com/docker/machine/libmachine/hosttest/default_test_host.go deleted file mode 100644 index 143a120..0000000 --- a/vendor/github.com/docker/machine/libmachine/hosttest/default_test_host.go +++ /dev/null @@ -1,78 +0,0 @@ -package hosttest - -import ( - "github.com/docker/machine/drivers/none" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/swarm" - "github.com/docker/machine/libmachine/version" -) - -const ( - DefaultHostName = "test-host" - HostTestCaCert = "test-cert" - HostTestPrivateKey = "test-key" -) - -type DriverOptionsMock struct { - Data map[string]interface{} -} - -func (d DriverOptionsMock) String(key string) string { - return d.Data[key].(string) -} - -func (d DriverOptionsMock) StringSlice(key string) []string { - return d.Data[key].([]string) -} - -func (d DriverOptionsMock) Int(key string) int { - return d.Data[key].(int) -} - -func (d DriverOptionsMock) Bool(key string) bool { - return d.Data[key].(bool) -} - -func GetTestDriverFlags() *DriverOptionsMock { - flags := &DriverOptionsMock{ - Data: map[string]interface{}{ - "name": DefaultHostName, - "url": "unix:///var/run/docker.sock", - "swarm": false, - "swarm-host": "", - "swarm-master": false, - "swarm-discovery": "", - }, - } - return flags -} - -func GetDefaultTestHost() (*host.Host, error) { - hostOptions := &host.Options{ - EngineOptions: &engine.Options{}, - SwarmOptions: &swarm.Options{}, - AuthOptions: &auth.Options{ - CaCertPath: HostTestCaCert, - CaPrivateKeyPath: HostTestPrivateKey, - }, - } - - driver := none.NewDriver(DefaultHostName, "/tmp/artifacts") - - host := &host.Host{ - ConfigVersion: version.ConfigVersion, - Name: DefaultHostName, - Driver: driver, - DriverName: "none", - HostOptions: hostOptions, - } - - flags := GetTestDriverFlags() - if err := host.Driver.SetConfigFromFlags(flags); err != nil { - return nil, err - } - - return host, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/libmachine.go b/vendor/github.com/docker/machine/libmachine/libmachine.go deleted file mode 100644 index 986d4ff..0000000 --- a/vendor/github.com/docker/machine/libmachine/libmachine.go +++ /dev/null @@ -1,188 +0,0 @@ -package libmachine - -import ( - "fmt" - "path/filepath" - - "io" - - "github.com/docker/machine/drivers/errdriver" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/cert" - "github.com/docker/machine/libmachine/check" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/drivers/plugin/localbinary" - "github.com/docker/machine/libmachine/drivers/rpc" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnerror" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/persist" - "github.com/docker/machine/libmachine/provision" - "github.com/docker/machine/libmachine/ssh" - "github.com/docker/machine/libmachine/state" - "github.com/docker/machine/libmachine/swarm" - "github.com/docker/machine/libmachine/version" -) - -type API interface { - io.Closer - NewHost(driverName string, rawDriver []byte) (*host.Host, error) - Create(h *host.Host) error - persist.Store - GetMachinesDir() string -} - -type Client struct { - certsDir string - IsDebug bool - SSHClientType ssh.ClientType - GithubAPIToken string - *persist.Filestore - clientDriverFactory rpcdriver.RPCClientDriverFactory -} - -func NewClient(storePath, certsDir string) *Client { - return &Client{ - certsDir: certsDir, - IsDebug: false, - SSHClientType: ssh.External, - Filestore: persist.NewFilestore(storePath, certsDir, certsDir), - clientDriverFactory: rpcdriver.NewRPCClientDriverFactory(), - } -} - -func (api *Client) NewHost(driverName string, rawDriver []byte) (*host.Host, error) { - driver, err := api.clientDriverFactory.NewRPCClientDriver(driverName, rawDriver) - if err != nil { - return nil, err - } - - return &host.Host{ - ConfigVersion: version.ConfigVersion, - Name: driver.GetMachineName(), - Driver: driver, - DriverName: driver.DriverName(), - HostOptions: &host.Options{ - AuthOptions: &auth.Options{ - CertDir: api.certsDir, - CaCertPath: filepath.Join(api.certsDir, "ca.pem"), - CaPrivateKeyPath: filepath.Join(api.certsDir, "ca-key.pem"), - ClientCertPath: filepath.Join(api.certsDir, "cert.pem"), - ClientKeyPath: filepath.Join(api.certsDir, "key.pem"), - ServerCertPath: filepath.Join(api.GetMachinesDir(), "server.pem"), - ServerKeyPath: filepath.Join(api.GetMachinesDir(), "server-key.pem"), - }, - EngineOptions: &engine.Options{ - InstallURL: drivers.DefaultEngineInstallURL, - StorageDriver: "aufs", - TLSVerify: true, - }, - SwarmOptions: &swarm.Options{ - Host: "tcp://0.0.0.0:3376", - Image: "swarm:latest", - Strategy: "spread", - }, - }, - }, nil -} - -func (api *Client) Load(name string) (*host.Host, error) { - h, err := api.Filestore.Load(name) - if err != nil { - return nil, err - } - - d, err := api.clientDriverFactory.NewRPCClientDriver(h.DriverName, h.RawDriver) - if err != nil { - // Not being able to find a driver binary is a "known error" - if _, ok := err.(localbinary.ErrPluginBinaryNotFound); ok { - h.Driver = errdriver.NewDriver(h.DriverName) - return h, nil - } - return nil, err - } - - if h.DriverName == "virtualbox" { - h.Driver = drivers.NewSerialDriver(d) - } else { - h.Driver = d - } - - return h, nil -} - -// Create is the wrapper method which covers all of the boilerplate around -// actually creating, provisioning, and persisting an instance in the store. -func (api *Client) Create(h *host.Host) error { - if err := cert.BootstrapCertificates(h.AuthOptions()); err != nil { - return fmt.Errorf("Error generating certificates: %s", err) - } - - log.Info("Running pre-create checks...") - - if err := h.Driver.PreCreateCheck(); err != nil { - return mcnerror.ErrDuringPreCreate{ - Cause: err, - } - } - - if err := api.Save(h); err != nil { - return fmt.Errorf("Error saving host to store before attempting creation: %s", err) - } - - log.Info("Creating machine...") - - if err := api.performCreate(h); err != nil { - return fmt.Errorf("Error creating machine: %s", err) - } - - log.Debug("Reticulating splines...") - - return nil -} - -func (api *Client) performCreate(h *host.Host) error { - if err := h.Driver.Create(); err != nil { - return fmt.Errorf("Error in driver during machine creation: %s", err) - } - - if err := api.Save(h); err != nil { - return fmt.Errorf("Error saving host to store after attempting creation: %s", err) - } - - // TODO: Not really a fan of just checking "none" or "ci-test" here. - if h.Driver.DriverName() == "none" || h.Driver.DriverName() == "ci-test" { - return nil - } - - log.Info("Waiting for machine to be running, this may take a few minutes...") - if err := mcnutils.WaitFor(drivers.MachineInState(h.Driver, state.Running)); err != nil { - return fmt.Errorf("Error waiting for machine to be running: %s", err) - } - - log.Info("Detecting operating system of created instance...") - provisioner, err := provision.DetectProvisioner(h.Driver) - if err != nil { - return fmt.Errorf("Error detecting OS: %s", err) - } - - log.Infof("Provisioning with %s...", provisioner.String()) - if err := provisioner.Provision(*h.HostOptions.SwarmOptions, *h.HostOptions.AuthOptions, *h.HostOptions.EngineOptions); err != nil { - return fmt.Errorf("Error running provisioning: %s", err) - } - - // We should check the connection to docker here - log.Info("Checking connection to Docker...") - if _, _, err = check.DefaultConnChecker.Check(h, false); err != nil { - return fmt.Errorf("Error checking the host: %s", err) - } - - log.Info("Docker is up and running!") - return nil -} - -func (api *Client) Close() error { - return api.clientDriverFactory.Close() -} diff --git a/vendor/github.com/docker/machine/libmachine/libmachinetest/fake_api.go b/vendor/github.com/docker/machine/libmachine/libmachinetest/fake_api.go deleted file mode 100644 index 4566257..0000000 --- a/vendor/github.com/docker/machine/libmachine/libmachinetest/fake_api.go +++ /dev/null @@ -1,88 +0,0 @@ -package libmachinetest - -import ( - "github.com/docker/machine/libmachine" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/mcnerror" - "github.com/docker/machine/libmachine/state" -) - -type FakeAPI struct { - Hosts []*host.Host -} - -func (api *FakeAPI) NewPluginDriver(string, []byte) (drivers.Driver, error) { - return nil, nil -} - -func (api *FakeAPI) Close() error { - return nil -} - -func (api *FakeAPI) NewHost(driverName string, rawDriver []byte) (*host.Host, error) { - return nil, nil -} - -func (api *FakeAPI) Create(h *host.Host) error { - return nil -} - -func (api *FakeAPI) Exists(name string) (bool, error) { - for _, host := range api.Hosts { - if name == host.Name { - return true, nil - } - } - - return false, nil -} - -func (api *FakeAPI) List() ([]string, error) { - return []string{}, nil -} - -func (api *FakeAPI) Load(name string) (*host.Host, error) { - for _, host := range api.Hosts { - if name == host.Name { - return host, nil - } - } - - return nil, mcnerror.ErrHostDoesNotExist{ - Name: name, - } -} - -func (api *FakeAPI) Remove(name string) error { - newHosts := []*host.Host{} - - for _, host := range api.Hosts { - if name != host.Name { - newHosts = append(newHosts, host) - } - } - - api.Hosts = newHosts - - return nil -} - -func (api *FakeAPI) Save(host *host.Host) error { - return nil -} - -func (api FakeAPI) GetMachinesDir() string { - return "" -} - -func State(api libmachine.API, name string) state.State { - host, _ := api.Load(name) - machineState, _ := host.Driver.GetState() - return machineState -} - -func Exists(api libmachine.API, name string) bool { - exists, _ := api.Exists(name) - return exists -} diff --git a/vendor/github.com/docker/machine/libmachine/log/fmt_machine_logger.go b/vendor/github.com/docker/machine/libmachine/log/fmt_machine_logger.go deleted file mode 100644 index 285e699..0000000 --- a/vendor/github.com/docker/machine/libmachine/log/fmt_machine_logger.go +++ /dev/null @@ -1,84 +0,0 @@ -package log - -import ( - "fmt" - "io" - "os" -) - -type FmtMachineLogger struct { - outWriter io.Writer - errWriter io.Writer - debug bool - history *HistoryRecorder -} - -// NewFmtMachineLogger creates a MachineLogger implementation used by the drivers -func NewFmtMachineLogger() MachineLogger { - return &FmtMachineLogger{ - outWriter: os.Stdout, - errWriter: os.Stderr, - debug: false, - history: NewHistoryRecorder(), - } -} - -func (ml *FmtMachineLogger) SetDebug(debug bool) { - ml.debug = debug -} - -func (ml *FmtMachineLogger) SetOutWriter(out io.Writer) { - ml.outWriter = out -} - -func (ml *FmtMachineLogger) SetErrWriter(err io.Writer) { - ml.errWriter = err -} - -func (ml *FmtMachineLogger) Debug(args ...interface{}) { - ml.history.Record(args...) - if ml.debug { - fmt.Fprintln(ml.errWriter, args...) - } -} - -func (ml *FmtMachineLogger) Debugf(fmtString string, args ...interface{}) { - ml.history.Recordf(fmtString, args...) - if ml.debug { - fmt.Fprintf(ml.errWriter, fmtString+"\n", args...) - } -} - -func (ml *FmtMachineLogger) Error(args ...interface{}) { - ml.history.Record(args...) - fmt.Fprintln(ml.errWriter, args...) -} - -func (ml *FmtMachineLogger) Errorf(fmtString string, args ...interface{}) { - ml.history.Recordf(fmtString, args...) - fmt.Fprintf(ml.errWriter, fmtString+"\n", args...) -} - -func (ml *FmtMachineLogger) Info(args ...interface{}) { - ml.history.Record(args...) - fmt.Fprintln(ml.outWriter, args...) -} - -func (ml *FmtMachineLogger) Infof(fmtString string, args ...interface{}) { - ml.history.Recordf(fmtString, args...) - fmt.Fprintf(ml.outWriter, fmtString+"\n", args...) -} - -func (ml *FmtMachineLogger) Warn(args ...interface{}) { - ml.history.Record(args...) - fmt.Fprintln(ml.outWriter, args...) -} - -func (ml *FmtMachineLogger) Warnf(fmtString string, args ...interface{}) { - ml.history.Recordf(fmtString, args...) - fmt.Fprintf(ml.outWriter, fmtString+"\n", args...) -} - -func (ml *FmtMachineLogger) History() []string { - return ml.history.records -} diff --git a/vendor/github.com/docker/machine/libmachine/log/fmt_machine_logger_test.go b/vendor/github.com/docker/machine/libmachine/log/fmt_machine_logger_test.go deleted file mode 100644 index daa0d5a..0000000 --- a/vendor/github.com/docker/machine/libmachine/log/fmt_machine_logger_test.go +++ /dev/null @@ -1,97 +0,0 @@ -package log - -import ( - "bufio" - "io" - "io/ioutil" - "testing" - - "github.com/stretchr/testify/assert" -) - -func captureOutput(testLogger MachineLogger, lambda func()) string { - pipeReader, pipeWriter := io.Pipe() - scanner := bufio.NewScanner(pipeReader) - testLogger.SetOutWriter(pipeWriter) - go lambda() - scanner.Scan() - return scanner.Text() -} - -func captureError(testLogger MachineLogger, lambda func()) string { - pipeReader, pipeWriter := io.Pipe() - scanner := bufio.NewScanner(pipeReader) - testLogger.SetErrWriter(pipeWriter) - go lambda() - scanner.Scan() - return scanner.Text() -} - -func TestSetDebugToTrue(t *testing.T) { - testLogger := NewFmtMachineLogger().(*FmtMachineLogger) - testLogger.SetDebug(true) - assert.Equal(t, true, testLogger.debug) -} - -func TestSetDebugToFalse(t *testing.T) { - testLogger := NewFmtMachineLogger().(*FmtMachineLogger) - testLogger.SetDebug(true) - testLogger.SetDebug(false) - assert.Equal(t, false, testLogger.debug) -} - -func TestSetOut(t *testing.T) { - testLogger := NewFmtMachineLogger().(*FmtMachineLogger) - testLogger.SetOutWriter(ioutil.Discard) - assert.Equal(t, ioutil.Discard, testLogger.outWriter) -} - -func TestSetErr(t *testing.T) { - testLogger := NewFmtMachineLogger().(*FmtMachineLogger) - testLogger.SetErrWriter(ioutil.Discard) - assert.Equal(t, ioutil.Discard, testLogger.errWriter) -} - -func TestDebug(t *testing.T) { - testLogger := NewFmtMachineLogger() - testLogger.SetDebug(true) - - result := captureError(testLogger, func() { testLogger.Debug("debug") }) - - assert.Equal(t, result, "debug") -} - -func TestInfo(t *testing.T) { - testLogger := NewFmtMachineLogger() - - result := captureOutput(testLogger, func() { testLogger.Info("info") }) - - assert.Equal(t, result, "info") -} - -func TestWarn(t *testing.T) { - testLogger := NewFmtMachineLogger() - - result := captureOutput(testLogger, func() { testLogger.Warn("warn") }) - - assert.Equal(t, result, "warn") -} - -func TestError(t *testing.T) { - testLogger := NewFmtMachineLogger() - - result := captureError(testLogger, func() { testLogger.Error("error") }) - - assert.Equal(t, result, "error") -} - -func TestEntriesAreCollected(t *testing.T) { - testLogger := NewFmtMachineLogger() - testLogger.Debug("debug") - testLogger.Info("info") - testLogger.Error("error") - assert.Equal(t, 3, len(testLogger.History())) - assert.Equal(t, "debug", testLogger.History()[0]) - assert.Equal(t, "info", testLogger.History()[1]) - assert.Equal(t, "error", testLogger.History()[2]) -} diff --git a/vendor/github.com/docker/machine/libmachine/log/history_recorder.go b/vendor/github.com/docker/machine/libmachine/log/history_recorder.go deleted file mode 100644 index defdbad..0000000 --- a/vendor/github.com/docker/machine/libmachine/log/history_recorder.go +++ /dev/null @@ -1,34 +0,0 @@ -package log - -import ( - "fmt" - "sync" -) - -type HistoryRecorder struct { - lock *sync.Mutex - records []string -} - -func NewHistoryRecorder() *HistoryRecorder { - return &HistoryRecorder{ - lock: &sync.Mutex{}, - records: []string{}, - } -} - -func (ml *HistoryRecorder) History() []string { - return ml.records -} - -func (ml *HistoryRecorder) Record(args ...interface{}) { - ml.lock.Lock() - defer ml.lock.Unlock() - ml.records = append(ml.records, fmt.Sprint(args...)) -} - -func (ml *HistoryRecorder) Recordf(fmtString string, args ...interface{}) { - ml.lock.Lock() - defer ml.lock.Unlock() - ml.records = append(ml.records, fmt.Sprintf(fmtString, args...)) -} diff --git a/vendor/github.com/docker/machine/libmachine/log/history_recorder_test.go b/vendor/github.com/docker/machine/libmachine/log/history_recorder_test.go deleted file mode 100644 index 5e30520..0000000 --- a/vendor/github.com/docker/machine/libmachine/log/history_recorder_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package log - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestRecording(t *testing.T) { - recorder := NewHistoryRecorder() - recorder.Record("foo") - recorder.Record("bar") - recorder.Record("qix") - assert.Equal(t, recorder.History(), []string{"foo", "bar", "qix"}) -} - -func TestFormattedRecording(t *testing.T) { - recorder := NewHistoryRecorder() - recorder.Recordf("%s, %s and %s", "foo", "bar", "qix") - assert.Equal(t, recorder.History()[0], "foo, bar and qix") -} diff --git a/vendor/github.com/docker/machine/libmachine/log/log.go b/vendor/github.com/docker/machine/libmachine/log/log.go deleted file mode 100644 index 5a5823b..0000000 --- a/vendor/github.com/docker/machine/libmachine/log/log.go +++ /dev/null @@ -1,74 +0,0 @@ -package log - -import ( - "io" - "regexp" -) - -const redactedText = "" - -var ( - logger = NewFmtMachineLogger() - - // (?s) enables '.' to match '\n' -- see https://golang.org/pkg/regexp/syntax/ - certRegex = regexp.MustCompile("(?s)-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----") - keyRegex = regexp.MustCompile("(?s)-----BEGIN RSA PRIVATE KEY-----.*-----END RSA PRIVATE KEY-----") -) - -func stripSecrets(original []string) []string { - stripped := []string{} - for _, line := range original { - line = certRegex.ReplaceAllString(line, redactedText) - line = keyRegex.ReplaceAllString(line, redactedText) - stripped = append(stripped, line) - } - return stripped -} - -func Debug(args ...interface{}) { - logger.Debug(args...) -} - -func Debugf(fmtString string, args ...interface{}) { - logger.Debugf(fmtString, args...) -} - -func Error(args ...interface{}) { - logger.Error(args...) -} - -func Errorf(fmtString string, args ...interface{}) { - logger.Errorf(fmtString, args...) -} - -func Info(args ...interface{}) { - logger.Info(args...) -} - -func Infof(fmtString string, args ...interface{}) { - logger.Infof(fmtString, args...) -} - -func Warn(args ...interface{}) { - logger.Warn(args...) -} - -func Warnf(fmtString string, args ...interface{}) { - logger.Warnf(fmtString, args...) -} - -func SetDebug(debug bool) { - logger.SetDebug(debug) -} - -func SetOutWriter(out io.Writer) { - logger.SetOutWriter(out) -} - -func SetErrWriter(err io.Writer) { - logger.SetErrWriter(err) -} - -func History() []string { - return stripSecrets(logger.History()) -} diff --git a/vendor/github.com/docker/machine/libmachine/log/log_test.go b/vendor/github.com/docker/machine/libmachine/log/log_test.go deleted file mode 100644 index 2343ab9..0000000 --- a/vendor/github.com/docker/machine/libmachine/log/log_test.go +++ /dev/null @@ -1,91 +0,0 @@ -package log - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestStripSecrets(t *testing.T) { - testCases := []struct { - description string - input []string - expected []string - }{ - { - description: "Log that does contain certs should have them stripped", - input: []string{ - "Some mundane log lines", - "IP is foo.bar", - `Secret here: printf '%s' '-----BEGIN CERTIFICATE----- -MIIC4DCCAcigAwIBAgIRAMMHbb4WFRVYsCOIrfM3dqkwDQYJKoZIhvcNAQELBQAw -GTEXMBUGA1UEChMObmF0aGFubGVjbGFpcmUwHhcNMTUxMDEwMDE1MDAwWhcNMTgw -OTI0MDE1MDAwWjAZMRcwFQYDVQQKEw5uYXRoYW5sZWNsYWlyZTCCASIwDQYJKoZI -hvcNAQEBBQADggEPADCCAQoCggEBANLMyaAZPThE6lXtXYfUMZeF0pEfO4BQ7Rv8 -Q9/aIKwm8SlKNm+g+6+RoexsiaPXmAkqk04kg+f9WRgtUKC3nhaiUwTqx2HtxowY -Kp7VVW9QyzwCP1r04WTNTdICzhwM5GfaCMKLmibVUfh9GqIYg4Z6eFly7t0PaN1P -uaLClow1e4sWgAgkpIx7ko9ZtW+73knAnp9PPoH4KPBLS+sIPNGh62WsDlvQrOnq -KDiBPIAAMxu2UefIPeGe6xxFuCG89RoJYYsB627IaR8R8iGJMwjJsiAiObGu6z8M -lcWxT4dC+cEIDRu+XQmavJlAydBeHY6/gtJXzsyRExHTyDwi8xkCAwEAAaMjMCEw -DgYDVR0PAQH/BAQDAgKsMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQAD -ggEBAA5CBXPgjvxfY5bR+f6YfcDcKBWxOQ5zN+OH6jWpVzJMEUWp/ZvTQ1GcV1CT -J4HDMRUOL6lQigZDKR6OJ0g/pD4cDGEQlCuPDXx0O8eenxj9TQ+X+qdtxQNkgjId -QWj3k3JDHCh4BQ7h1ZJIg4SnGCUsrQQ+M8TS4Z0YZ/bZ6ZTktJgQgWMn9Uum1GN9 -hXJ/fa/E9OJuRxTXou7J0WwrV9aX9sEM9syOANR88PcA1fSE7+wNSdj5ZCfY6mQn -II9e8NZEf5ktPXCNi0LKI6R1berejwQI3KKHEFbdZ8SKn93HgDh/Ip/dFctj+zBt -CAlTWS3abehlCERn6Ze9IfZBtpI= ------END CERTIFICATE-----' | sudo tee /etc/docker/ca.pem`, - }, - expected: []string{ - "Some mundane log lines", - "IP is foo.bar", - `Secret here: printf '%s' '' | sudo tee /etc/docker/ca.pem`, - }, - }, - { - description: "Log that does contain private keys should have them stripped", - input: []string{ - "Some mundane log lines", - "IP is foo.bar", - `Secret here: printf '%s' '-----BEGIN RSA PRIVATE KEY----- -MIIC4DCCAcigAwIBAgIRAMMHbb4WFRVYsCOIrfM3dqkwDQYJKoZIhvcNAQELBQAw -GTEXMBUGA1UEChMObmF0aGFubGVjbGFpcmUwHhcNMTUxMDEwMDE1MDAwWhcNMTgw -OTI0MDE1MDAwWjAZMRcwFQYDVQQKEw5uYXRoYW5sZWNsYWlyZTCCASIwDQYJKoZI -hvcNAQEBBQADggEPADCCAQoCggEBANLMyaAZPThE6lXtXYfUMZeF0pEfO4BQ7Rv8 -Q9/aIKwm8SlKNm+g+6+RoexsiaPXmAkqk04kg+f9WRgtUKC3nhaiUwTqx2HtxowY -Kp7VVW9QyzwCP1r04WTNTdICzhwM5GfaCMKLmibVUfh9GqIYg4Z6eFly7t0PaN1P -uaLClow1e4sWgAgkpIx7ko9ZtW+73knAnp9PPoH4KPBLS+sIPNGh62WsDlvQrOnq -KDiBPIAAMxu2UefIPeGe6xxFuCG89RoJYYsB627IaR8R8iGJMwjJsiAiObGu6z8M -lcWxT4dC+cEIDRu+XQmavJlAydBeHY6/gtJXzsyRExHTyDwi8xkCAwEAAaMjMCEw -DgYDVR0PAQH/BAQDAgKsMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQAD -ggEBAA5CBXPgjvxfY5bR+f6YfcDcKBWxOQ5zN+OH6jWpVzJMEUWp/ZvTQ1GcV1CT -J4HDMRUOL6lQigZDKR6OJ0g/pD4cDGEQlCuPDXx0O8eenxj9TQ+X+qdtxQNkgjId -QWj3k3JDHCh4BQ7h1ZJIg4SnGCUsrQQ+M8TS4Z0YZ/bZ6ZTktJgQgWMn9Uum1GN9 -hXJ/fa/E9OJuRxTXou7J0WwrV9aX9sEM9syOANR88PcA1fSE7+wNSdj5ZCfY6mQn -II9e8NZEf5ktPXCNi0LKI6R1berejwQI3KKHEFbdZ8SKn93HgDh/Ip/dFctj+zBt -CAlTWS3abehlCERn6Ze9IfZBtpI= ------END RSA PRIVATE KEY-----' | sudo tee /etc/docker/server-key.pem`, - }, - expected: []string{ - "Some mundane log lines", - "IP is foo.bar", - `Secret here: printf '%s' '' | sudo tee /etc/docker/server-key.pem`, - }, - }, - { - description: "Log that does not contain secrets should not change", - input: []string{ - "Some mundane log lines", - "IP is foo.bar", - }, - expected: []string{ - "Some mundane log lines", - "IP is foo.bar", - }, - }, - } - - for _, tc := range testCases { - assert.Equal(t, tc.expected, stripSecrets(tc.input)) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/log/machine_logger.go b/vendor/github.com/docker/machine/libmachine/log/machine_logger.go deleted file mode 100644 index 19f613e..0000000 --- a/vendor/github.com/docker/machine/libmachine/log/machine_logger.go +++ /dev/null @@ -1,24 +0,0 @@ -package log - -import "io" - -type MachineLogger interface { - SetDebug(debug bool) - - SetOutWriter(io.Writer) - SetErrWriter(io.Writer) - - Debug(args ...interface{}) - Debugf(fmtString string, args ...interface{}) - - Error(args ...interface{}) - Errorf(fmtString string, args ...interface{}) - - Info(args ...interface{}) - Infof(fmtString string, args ...interface{}) - - Warn(args ...interface{}) - Warnf(fmtString string, args ...interface{}) - - History() []string -} diff --git a/vendor/github.com/docker/machine/libmachine/mcndockerclient/docker_client.go b/vendor/github.com/docker/machine/libmachine/mcndockerclient/docker_client.go deleted file mode 100644 index 828dc76..0000000 --- a/vendor/github.com/docker/machine/libmachine/mcndockerclient/docker_client.go +++ /dev/null @@ -1,47 +0,0 @@ -package mcndockerclient - -import ( - "fmt" - - "github.com/docker/machine/libmachine/cert" - "github.com/samalba/dockerclient" -) - -// DockerClient creates a docker client for a given host. -func DockerClient(dockerHost DockerHost) (*dockerclient.DockerClient, error) { - url, err := dockerHost.URL() - if err != nil { - return nil, err - } - - tlsConfig, err := cert.ReadTLSConfig(url, dockerHost.AuthOptions()) - if err != nil { - return nil, fmt.Errorf("Unable to read TLS config: %s", err) - } - - return dockerclient.NewDockerClient(url, tlsConfig) -} - -// CreateContainer creates a docker container. -func CreateContainer(dockerHost DockerHost, config *dockerclient.ContainerConfig, name string) error { - docker, err := DockerClient(dockerHost) - if err != nil { - return err - } - - if err = docker.PullImage(config.Image, nil); err != nil { - return fmt.Errorf("Unable to pull image: %s", err) - } - - var authConfig *dockerclient.AuthConfig - containerID, err := docker.CreateContainer(config, name, authConfig) - if err != nil { - return fmt.Errorf("Error while creating container: %s", err) - } - - if err = docker.StartContainer(containerID, &config.HostConfig); err != nil { - return fmt.Errorf("Error while starting container: %s", err) - } - - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/mcndockerclient/docker_host.go b/vendor/github.com/docker/machine/libmachine/mcndockerclient/docker_host.go deleted file mode 100644 index 43d774e..0000000 --- a/vendor/github.com/docker/machine/libmachine/mcndockerclient/docker_host.go +++ /dev/null @@ -1,41 +0,0 @@ -package mcndockerclient - -import ( - "fmt" - - "github.com/docker/machine/libmachine/auth" -) - -type URLer interface { - // URL returns the Docker host URL - URL() (string, error) -} - -type AuthOptionser interface { - // AuthOptions returns the authOptions - AuthOptions() *auth.Options -} - -type DockerHost interface { - URLer - AuthOptionser -} - -type RemoteDocker struct { - HostURL string - AuthOption *auth.Options -} - -// URL returns the Docker host URL -func (rd *RemoteDocker) URL() (string, error) { - if rd.HostURL == "" { - return "", fmt.Errorf("Docker Host URL not set") - } - - return rd.HostURL, nil -} - -// AuthOptions returns the authOptions -func (rd *RemoteDocker) AuthOptions() *auth.Options { - return rd.AuthOption -} diff --git a/vendor/github.com/docker/machine/libmachine/mcndockerclient/docker_versioner.go b/vendor/github.com/docker/machine/libmachine/mcndockerclient/docker_versioner.go deleted file mode 100644 index b8279c7..0000000 --- a/vendor/github.com/docker/machine/libmachine/mcndockerclient/docker_versioner.go +++ /dev/null @@ -1,29 +0,0 @@ -package mcndockerclient - -import "fmt" - -var CurrentDockerVersioner DockerVersioner = &defaultDockerVersioner{} - -type DockerVersioner interface { - DockerVersion(host DockerHost) (string, error) -} - -func DockerVersion(host DockerHost) (string, error) { - return CurrentDockerVersioner.DockerVersion(host) -} - -type defaultDockerVersioner struct{} - -func (dv *defaultDockerVersioner) DockerVersion(host DockerHost) (string, error) { - client, err := DockerClient(host) - if err != nil { - return "", fmt.Errorf("Unable to query docker version: %s", err) - } - - version, err := client.Version() - if err != nil { - return "", fmt.Errorf("Unable to query docker version: %s", err) - } - - return version.Version, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/mcndockerclient/fake_docker_versioner.go b/vendor/github.com/docker/machine/libmachine/mcndockerclient/fake_docker_versioner.go deleted file mode 100644 index 32c4bb4..0000000 --- a/vendor/github.com/docker/machine/libmachine/mcndockerclient/fake_docker_versioner.go +++ /dev/null @@ -1,14 +0,0 @@ -package mcndockerclient - -type FakeDockerVersioner struct { - Version string - Err error -} - -func (dv *FakeDockerVersioner) DockerVersion(host DockerHost) (string, error) { - if dv.Err != nil { - return "", dv.Err - } - - return dv.Version, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/mcnerror/errors.go b/vendor/github.com/docker/machine/libmachine/mcnerror/errors.go deleted file mode 100644 index 6efc3c5..0000000 --- a/vendor/github.com/docker/machine/libmachine/mcnerror/errors.go +++ /dev/null @@ -1,46 +0,0 @@ -package mcnerror - -import ( - "errors" - "fmt" - "strings" - - "github.com/docker/machine/libmachine/state" -) - -var ( - ErrInvalidHostname = errors.New("Invalid hostname specified. Allowed hostname chars are: 0-9a-zA-Z . -") -) - -type ErrHostDoesNotExist struct { - Name string -} - -func (e ErrHostDoesNotExist) Error() string { - return fmt.Sprintf("Docker machine %q does not exist. Use \"docker-machine ls\" to list machines. Use \"docker-machine create\" to add a new one.", e.Name) -} - -type ErrHostAlreadyExists struct { - Name string -} - -func (e ErrHostAlreadyExists) Error() string { - return fmt.Sprintf("Docker machine %q already exists", e.Name) -} - -type ErrDuringPreCreate struct { - Cause error -} - -func (e ErrDuringPreCreate) Error() string { - return fmt.Sprintf("Error with pre-create check: %q", e.Cause) -} - -type ErrHostAlreadyInState struct { - Name string - State state.State -} - -func (e ErrHostAlreadyInState) Error() string { - return fmt.Sprintf("Machine %q is already %s.", e.Name, strings.ToLower(e.State.String())) -} diff --git a/vendor/github.com/docker/machine/libmachine/mcnflag/flag.go b/vendor/github.com/docker/machine/libmachine/mcnflag/flag.go deleted file mode 100644 index ec24d13..0000000 --- a/vendor/github.com/docker/machine/libmachine/mcnflag/flag.go +++ /dev/null @@ -1,71 +0,0 @@ -package mcnflag - -import "fmt" - -type Flag interface { - fmt.Stringer - Default() interface{} -} - -type StringFlag struct { - Name string - Usage string - EnvVar string - Value string -} - -// TODO: Could this be done more succinctly using embedding? -func (f StringFlag) String() string { - return f.Name -} - -func (f StringFlag) Default() interface{} { - return f.Value -} - -type StringSliceFlag struct { - Name string - Usage string - EnvVar string - Value []string -} - -// TODO: Could this be done more succinctly using embedding? -func (f StringSliceFlag) String() string { - return f.Name -} - -func (f StringSliceFlag) Default() interface{} { - return f.Value -} - -type IntFlag struct { - Name string - Usage string - EnvVar string - Value int -} - -// TODO: Could this be done more succinctly using embedding? -func (f IntFlag) String() string { - return f.Name -} - -func (f IntFlag) Default() interface{} { - return f.Value -} - -type BoolFlag struct { - Name string - Usage string - EnvVar string -} - -// TODO: Could this be done more succinctly using embedding? -func (f BoolFlag) String() string { - return f.Name -} - -func (f BoolFlag) Default() interface{} { - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/mcnutils/b2d.go b/vendor/github.com/docker/machine/libmachine/mcnutils/b2d.go deleted file mode 100644 index f269195..0000000 --- a/vendor/github.com/docker/machine/libmachine/mcnutils/b2d.go +++ /dev/null @@ -1,542 +0,0 @@ -package mcnutils - -import ( - "archive/tar" - "bytes" - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "net/url" - "os" - "path/filepath" - "regexp" - "strings" - - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/version" -) - -const ( - defaultURL = "https://api.github.com/repos/boot2docker/boot2docker/releases" - defaultISOFilename = "boot2docker.iso" - defaultVolumeIDOffset = int64(0x8028) - versionPrefix = "-v" - defaultVolumeIDLength = 32 -) - -var ( - GithubAPIToken string -) - -var ( - errGitHubAPIResponse = errors.New(`failure getting a version tag from the Github API response (are you getting rate limited by Github?)`) -) - -var ( - AUFSBugB2DVersions = map[string]string{ - "v1.9.1": "https://github.com/docker/docker/issues/18180", - } -) - -func defaultTimeout(network, addr string) (net.Conn, error) { - return net.Dial(network, addr) -} - -func getClient() *http.Client { - transport := http.Transport{ - DisableKeepAlives: true, - Proxy: http.ProxyFromEnvironment, - Dial: defaultTimeout, - } - - return &http.Client{ - Transport: &transport, - } -} - -func getRequest(apiURL string) (*http.Request, error) { - req, err := http.NewRequest("GET", apiURL, nil) - if err != nil { - return nil, err - } - - if GithubAPIToken != "" { - req.Header.Add("Authorization", fmt.Sprintf("token %s", GithubAPIToken)) - } - - return req, nil -} - -// releaseGetter is a client that gets release information of a product and downloads it. -type releaseGetter interface { - // filename returns filename of the product. - filename() string - // getReleaseTag gets a release tag from the given URL. - getReleaseTag(apiURL string) (string, error) - // getReleaseURL gets the latest release download URL from the given URL. - getReleaseURL(apiURL string) (string, error) - // download downloads a file from the given dlURL and saves it under dir. - download(dir, file, dlURL string) error -} - -// b2dReleaseGetter implements the releaseGetter interface for getting the release of Boot2Docker. -type b2dReleaseGetter struct { - isoFilename string -} - -func (b *b2dReleaseGetter) filename() string { - if b == nil { - return "" - } - return b.isoFilename -} - -// getReleaseTag gets the release tag of Boot2Docker from apiURL. -func (*b2dReleaseGetter) getReleaseTag(apiURL string) (string, error) { - if apiURL == "" { - apiURL = defaultURL - } - - if !version.RC() { - // Just go straight to the convenience URL for "/latest" if we - // are a non-release candidate version. "/latest" won't return - // non-RCs, so that's what we use for stable releases of - // Machine. - apiURL = apiURL + "/latest" - } - - client := getClient() - req, err := getRequest(apiURL) - if err != nil { - return "", err - } - rsp, err := client.Do(req) - if err != nil { - return "", err - } - defer rsp.Body.Close() - - // If we call the API endpoint - // "/repos/boot2docker/boot2docker/releases" without specifying - // "/latest", we will receive a list of releases instead of a single - // one, and we should decode accordingly. - if version.RC() { - var tags []struct { - TagName string `json:"tag_name"` - } - if err := json.NewDecoder(rsp.Body).Decode(&tags); err != nil { - return "", err - } - t := tags[0] - if t.TagName == "" { - return "", errGitHubAPIResponse - } - return t.TagName, nil - } - - // Otherwise, we get back just one release, which we can decode to get - // the tag. - var t struct { - TagName string `json:"tag_name"` - } - if err := json.NewDecoder(rsp.Body).Decode(&t); err != nil { - return "", err - } - if t.TagName == "" { - return "", errGitHubAPIResponse - } - return t.TagName, nil -} - -// getReleaseURL gets the latest release URL of Boot2Docker. -func (b *b2dReleaseGetter) getReleaseURL(apiURL string) (string, error) { - if apiURL == "" { - apiURL = defaultURL - } - - // match github (enterprise) release urls: - // https://api.github.com/repos/../../releases or - // https://some.github.enterprise/api/v3/repos/../../releases - re := regexp.MustCompile("(https?)://([^/]+)(/api/v3)?/repos/([^/]+)/([^/]+)/releases") - matches := re.FindStringSubmatch(apiURL) - if len(matches) != 6 { - // does not match a github releases api URL - return apiURL, nil - } - - scheme, host, org, repo := matches[1], matches[2], matches[4], matches[5] - if host == "api.github.com" { - host = "github.com" - } - - tag, err := b.getReleaseTag(apiURL) - if err != nil { - return "", err - } - - log.Infof("Latest release for %s/%s/%s is %s", host, org, repo, tag) - bugURL, ok := AUFSBugB2DVersions[tag] - if ok { - log.Warnf(` -Boot2Docker %s has a known issue with AUFS. -See here for more details: %s -Consider specifying another storage driver (e.g. 'overlay') using '--engine-storage-driver' instead. -`, tag, bugURL) - } - url := fmt.Sprintf("%s://%s/%s/%s/releases/download/%s/%s", scheme, host, org, repo, tag, b.isoFilename) - return url, nil -} - -func (*b2dReleaseGetter) download(dir, file, isoURL string) error { - u, err := url.Parse(isoURL) - - var src io.ReadCloser - if u.Scheme == "file" || u.Scheme == "" { - s, err := os.Open(u.Path) - if err != nil { - return err - } - - src = s - } else { - client := getClient() - s, err := client.Get(isoURL) - if err != nil { - return err - } - - src = &ReaderWithProgress{ - ReadCloser: s.Body, - out: os.Stdout, - expectedLength: s.ContentLength, - } - } - - defer src.Close() - - // Download to a temp file first then rename it to avoid partial download. - f, err := ioutil.TempFile(dir, file+".tmp") - if err != nil { - return err - } - - defer func() { - if err := removeFileIfExists(f.Name()); err != nil { - log.Warnf("Error removing file: %s", err) - } - }() - - if _, err := io.Copy(f, src); err != nil { - return err - } - - if err := f.Close(); err != nil { - return err - } - - // Dest is the final path of the boot2docker.iso file. - dest := filepath.Join(dir, file) - - // Windows can't rename in place, so remove the old file before - // renaming the temporary downloaded file. - if err := removeFileIfExists(dest); err != nil { - return err - } - - return os.Rename(f.Name(), dest) -} - -// iso is an ISO volume. -type iso interface { - // path returns the path of the ISO. - path() string - // exists reports whether the ISO exists. - exists() bool - // version returns version information of the ISO. - version() (string, error) -} - -// b2dISO represents a Boot2Docker ISO. It implements the ISO interface. -type b2dISO struct { - // path of Boot2Docker ISO - commonIsoPath string - - // offset and length of ISO volume ID - // cf. http://serverfault.com/questions/361474/is-there-a-way-to-change-a-iso-files-volume-id-from-the-command-line - volumeIDOffset int64 - volumeIDLength int -} - -func (b *b2dISO) path() string { - if b == nil { - return "" - } - return b.commonIsoPath -} - -func (b *b2dISO) exists() bool { - if b == nil { - return false - } - - _, err := os.Stat(b.commonIsoPath) - return !os.IsNotExist(err) -} - -// version scans the volume ID in b and returns its version tag. -func (b *b2dISO) version() (string, error) { - if b == nil { - return "", nil - } - - iso, err := os.Open(b.commonIsoPath) - if err != nil { - return "", err - } - defer iso.Close() - - isoMetadata := make([]byte, b.volumeIDLength) - _, err = iso.ReadAt(isoMetadata, b.volumeIDOffset) - if err != nil { - return "", err - } - - trimmedVersion := strings.TrimSpace(string(isoMetadata)) - - versionIndex := strings.Index(trimmedVersion, versionPrefix) - if versionIndex == -1 { - return "", fmt.Errorf("Did not find prefix %q in version string", versionPrefix) - } - - // Original magic file string looks similar to this: "Boot2Docker-v0.1.0 " - // This will return "v0.1.0" given the above string - vers := trimmedVersion[versionIndex+1:] - - log.Debug("local Boot2Docker ISO version: ", vers) - return vers, nil -} - -func removeFileIfExists(name string) error { - if _, err := os.Stat(name); err == nil { - if err := os.Remove(name); err != nil { - return fmt.Errorf("Error removing temporary download file: %s", err) - } - } - return nil -} - -type B2dUtils struct { - releaseGetter - iso - storePath string - imgCachePath string -} - -func NewB2dUtils(storePath string) *B2dUtils { - imgCachePath := filepath.Join(storePath, "cache") - - return &B2dUtils{ - releaseGetter: &b2dReleaseGetter{isoFilename: defaultISOFilename}, - iso: &b2dISO{ - commonIsoPath: filepath.Join(imgCachePath, defaultISOFilename), - volumeIDOffset: defaultVolumeIDOffset, - volumeIDLength: defaultVolumeIDLength, - }, - storePath: storePath, - imgCachePath: imgCachePath, - } -} - -// DownloadISO downloads boot2docker ISO image for the given tag and save it at dest. -func (b *B2dUtils) DownloadISO(dir, file, isoURL string) error { - log.Infof("Downloading %s from %s...", b.path(), isoURL) - return b.download(dir, file, isoURL) -} - -type ReaderWithProgress struct { - io.ReadCloser - out io.Writer - bytesTransferred int64 - expectedLength int64 - nextPercentToPrint int64 -} - -func (r *ReaderWithProgress) Read(p []byte) (int, error) { - n, err := r.ReadCloser.Read(p) - - if n > 0 { - r.bytesTransferred += int64(n) - percentage := r.bytesTransferred * 100 / r.expectedLength - - for percentage >= r.nextPercentToPrint { - if r.nextPercentToPrint%10 == 0 { - fmt.Fprintf(r.out, "%d%%", r.nextPercentToPrint) - } else if r.nextPercentToPrint%2 == 0 { - fmt.Fprint(r.out, ".") - } - r.nextPercentToPrint += 2 - } - } - - return n, err -} - -func (r *ReaderWithProgress) Close() error { - fmt.Fprintln(r.out) - return r.ReadCloser.Close() -} - -func (b *B2dUtils) DownloadLatestBoot2Docker(apiURL string) error { - latestReleaseURL, err := b.getReleaseURL(apiURL) - if err != nil { - return err - } - - return b.DownloadISOFromURL(latestReleaseURL) -} - -func (b *B2dUtils) DownloadISOFromURL(latestReleaseURL string) error { - return b.DownloadISO(b.imgCachePath, b.filename(), latestReleaseURL) -} - -func (b *B2dUtils) UpdateISOCache(isoURL string) error { - // recreate the cache dir if it has been manually deleted - if _, err := os.Stat(b.imgCachePath); os.IsNotExist(err) { - log.Infof("Image cache directory does not exist, creating it at %s...", b.imgCachePath) - if err := os.Mkdir(b.imgCachePath, 0700); err != nil { - return err - } - } - - exists := b.exists() - - if isoURL != "" { - if exists { - // Warn that the b2d iso won't be updated if isoURL is set - log.Warnf("Boot2Docker URL was explicitly set to %q at create time, so Docker Machine cannot upgrade this machine to the latest version.", isoURL) - } - // Non-default B2D are not cached - return nil - } - - if !exists { - log.Info("No default Boot2Docker ISO found locally, downloading the latest release...") - return b.DownloadLatestBoot2Docker("") - } - - latest := b.isLatest() - if !latest { - log.Info("Default Boot2Docker ISO is out-of-date, downloading the latest release...") - return b.DownloadLatestBoot2Docker("") - } - - return nil -} - -func (b *B2dUtils) CopyIsoToMachineDir(isoURL, machineName string) error { - if err := b.UpdateISOCache(isoURL); err != nil { - return err - } - - // TODO: This is a bit off-color. - machineDir := filepath.Join(b.storePath, "machines", machineName) - machineIsoPath := filepath.Join(machineDir, b.filename()) - - // By default just copy the existing "cached" iso to the machine's directory... - if isoURL == "" { - log.Infof("Copying %s to %s...", b.path(), machineIsoPath) - return CopyFile(b.path(), machineIsoPath) - } - - // if ISO is specified, check if it matches a github releases url or fallback to a direct download - downloadURL, err := b.getReleaseURL(isoURL) - if err != nil { - return err - } - - return b.DownloadISO(machineDir, b.filename(), downloadURL) -} - -// isLatest checks the latest release tag and -// reports whether the local ISO cache is the latest version. -// -// It returns false if failing to get the local ISO version -// and true if failing to fetch the latest release tag. -func (b *B2dUtils) isLatest() bool { - localVer, err := b.version() - if err != nil { - log.Warn("Unable to get the local Boot2Docker ISO version: ", err) - return false - } - - latestVer, err := b.getReleaseTag("") - if err != nil { - log.Warn("Unable to get the latest Boot2Docker ISO release version: ", err) - return true - } - - return localVer == latestVer -} - -// MakeDiskImage makes a boot2docker VM disk image. -// See https://github.com/boot2docker/boot2docker/blob/master/rootfs/rootfs/etc/rc.d/automount -func MakeDiskImage(publicSSHKeyPath string) (*bytes.Buffer, error) { - magicString := "boot2docker, please format-me" - - buf := new(bytes.Buffer) - tw := tar.NewWriter(buf) - - // magicString first so the automount script knows to format the disk - file := &tar.Header{Name: magicString, Size: int64(len(magicString))} - - log.Debug("Writing magic tar header") - - if err := tw.WriteHeader(file); err != nil { - return nil, err - } - - if _, err := tw.Write([]byte(magicString)); err != nil { - return nil, err - } - - // .ssh/key.pub => authorized_keys - file = &tar.Header{Name: ".ssh", Typeflag: tar.TypeDir, Mode: 0700} - if err := tw.WriteHeader(file); err != nil { - return nil, err - } - - log.Debug("Writing SSH key tar header") - - pubKey, err := ioutil.ReadFile(publicSSHKeyPath) - if err != nil { - return nil, err - } - - file = &tar.Header{Name: ".ssh/authorized_keys", Size: int64(len(pubKey)), Mode: 0644} - if err := tw.WriteHeader(file); err != nil { - return nil, err - } - - if _, err := tw.Write([]byte(pubKey)); err != nil { - return nil, err - } - - file = &tar.Header{Name: ".ssh/authorized_keys2", Size: int64(len(pubKey)), Mode: 0644} - if err := tw.WriteHeader(file); err != nil { - return nil, err - } - - if _, err := tw.Write([]byte(pubKey)); err != nil { - return nil, err - } - - if err := tw.Close(); err != nil { - return nil, err - } - - return buf, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/mcnutils/b2d_test.go b/vendor/github.com/docker/machine/libmachine/mcnutils/b2d_test.go deleted file mode 100644 index cf1cfad..0000000 --- a/vendor/github.com/docker/machine/libmachine/mcnutils/b2d_test.go +++ /dev/null @@ -1,339 +0,0 @@ -package mcnutils - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "path/filepath" - "testing" - - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/version" - "github.com/stretchr/testify/assert" -) - -func TestGetReleaseURL(t *testing.T) { - testCases := []struct { - apiURL string - isoURL string - machineVersion string - response string - }{ - {"/repos/org/repo/releases/latest", "/org/repo/releases/download/v0.1/boot2docker.iso", "v0.7.0", `{"tag_name": "v0.1"}`}, - - // Note the difference in this one: It's an RC version. - {"/repos/org/repo/releases", "/org/repo/releases/download/v0.2-rc1/boot2docker.iso", "v0.7.0-rc2", `[{"tag_name": "v0.2-rc1"}, {"tag_name": "v0.1"}]`}, - - {"http://dummy.com/boot2docker.iso", "http://dummy.com/boot2docker.iso", "v0.7.0", `{"tag_name": "v0.1"}`}, - } - - for _, tt := range testCases { - testServer := newTestServer(tt.response) - - // TODO: Modifying this package level variable is not elegant, - // but it is effective. Ideally this should be exposed through - // an interface. - actualMachineVersion := version.Version - version.Version = tt.machineVersion - b := NewB2dUtils("/tmp/isos") - isoURL, err := b.getReleaseURL(testServer.URL + tt.apiURL) - - assert.NoError(t, err) - assert.Equal(t, testServer.URL+tt.isoURL, isoURL) - version.Version = actualMachineVersion - - testServer.Close() - } -} - -func TestGetReleaseURLError(t *testing.T) { - // GitHub API error response in case of rate limit - ts := newTestServer(`{"message": "API rate limit exceeded for 127.0.0.1.", - "documentation_url": "https://developer.github.com/v3/#rate-limiting"}`) - defer ts.Close() - - testCases := []struct { - apiURL string - }{ - {ts.URL + "/repos/org/repo/releases/latest"}, - {"http://127.0.0.1/repos/org/repo/releases/latest"}, // dummy API URL. cannot connect it. - } - - for _, tt := range testCases { - b := NewB2dUtils("/tmp/isos") - _, err := b.getReleaseURL(tt.apiURL) - - assert.Error(t, err) - } -} - -func TestVersion(t *testing.T) { - testCases := []string{ - "v0.1.0", - "v0.2.0-rc1", - } - - for _, vers := range testCases { - isopath, off, err := newDummyISO("", defaultISOFilename, vers) - - assert.NoError(t, err) - - b := &b2dISO{ - commonIsoPath: isopath, - volumeIDOffset: off, - volumeIDLength: defaultVolumeIDLength, - } - - got, err := b.version() - - assert.NoError(t, err) - assert.Equal(t, vers, string(got)) - removeFileIfExists(isopath) - } -} - -func TestDownloadISO(t *testing.T) { - testData := "test-download" - ts := newTestServer(testData) - defer ts.Close() - - filename := "test" - - tmpDir, err := ioutil.TempDir("", "machine-test-") - - assert.NoError(t, err) - - b := NewB2dUtils("/tmp/artifacts") - err = b.DownloadISO(tmpDir, filename, ts.URL) - - assert.NoError(t, err) - - data, err := ioutil.ReadFile(filepath.Join(tmpDir, filename)) - - assert.NoError(t, err) - assert.Equal(t, testData, string(data)) -} - -func TestGetRequest(t *testing.T) { - testCases := []struct { - token string - want string - }{ - {"", ""}, - {"CATBUG", "token CATBUG"}, - } - - for _, tt := range testCases { - GithubAPIToken = tt.token - - req, err := getRequest("http://some.github.api") - - assert.NoError(t, err) - assert.Equal(t, tt.want, req.Header.Get("Authorization")) - } -} - -type MockReadCloser struct { - blockLengths []int - currentBlock int -} - -func (r *MockReadCloser) Read(p []byte) (n int, err error) { - n = r.blockLengths[r.currentBlock] - r.currentBlock++ - return -} - -func (r *MockReadCloser) Close() error { - return nil -} - -func TestReaderWithProgress(t *testing.T) { - readCloser := MockReadCloser{blockLengths: []int{5, 45, 50}} - output := new(bytes.Buffer) - buffer := make([]byte, 100) - - readerWithProgress := ReaderWithProgress{ - ReadCloser: &readCloser, - out: output, - expectedLength: 100, - } - - readerWithProgress.Read(buffer) - assert.Equal(t, "0%..", output.String()) - - readerWithProgress.Read(buffer) - assert.Equal(t, "0%....10%....20%....30%....40%....50%", output.String()) - - readerWithProgress.Read(buffer) - assert.Equal(t, "0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%", output.String()) - - readerWithProgress.Close() - assert.Equal(t, "0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%\n", output.String()) -} - -type mockReleaseGetter struct { - ver string - apiErr error - verCh chan<- string -} - -func (m *mockReleaseGetter) filename() string { - return defaultISOFilename -} - -func (m *mockReleaseGetter) getReleaseTag(apiURL string) (string, error) { - return m.ver, m.apiErr -} - -func (m *mockReleaseGetter) getReleaseURL(apiURL string) (string, error) { - return "http://127.0.0.1/dummy", m.apiErr -} - -func (m *mockReleaseGetter) download(dir, file, isoURL string) error { - path := filepath.Join(dir, file) - var err error - if _, e := os.Stat(path); os.IsNotExist(e) { - err = ioutil.WriteFile(path, dummyISOData(" ", m.ver), 0644) - } - - // send a signal of downloading the latest version - m.verCh <- m.ver - return err -} - -type mockISO struct { - isopath string - exist bool - ver string - verCh <-chan string -} - -func (m *mockISO) path() string { - return m.isopath -} - -func (m *mockISO) exists() bool { - return m.exist -} - -func (m *mockISO) version() (string, error) { - select { - // receive version of a downloaded iso - case ver := <-m.verCh: - return ver, nil - default: - return m.ver, nil - } -} - -func TestCopyDefaultISOToMachine(t *testing.T) { - apiErr := errors.New("api error") - - testCases := []struct { - machineName string - create bool - localVer string - latestVer string - apiErr error - wantVer string - }{ - {"none", false, "", "v1.0.0", nil, "v1.0.0"}, // none => downloading - {"latest", true, "v1.0.0", "v1.0.0", nil, "v1.0.0"}, // latest iso => as is - {"old-badurl", true, "v0.1.0", "", apiErr, "v0.1.0"}, // old iso with bad api => as is - {"old", true, "v0.1.0", "v1.0.0", nil, "v1.0.0"}, // old iso => updating - } - - var isopath string - var err error - verCh := make(chan string, 1) - for _, tt := range testCases { - if tt.create { - isopath, _, err = newDummyISO("cache", defaultISOFilename, tt.localVer) - } else { - if dir, e := ioutil.TempDir("", "machine-test"); e == nil { - isopath = filepath.Join(dir, "cache", defaultISOFilename) - } - } - - // isopath: "$TMPDIR/machine-test-xxxxxx/cache/boot2docker.iso" - // tmpDir: "$TMPDIR/machine-test-xxxxxx" - imgCachePath := filepath.Dir(isopath) - storePath := filepath.Dir(imgCachePath) - - b := &B2dUtils{ - releaseGetter: &mockReleaseGetter{ - ver: tt.latestVer, - apiErr: tt.apiErr, - verCh: verCh, - }, - iso: &mockISO{ - isopath: isopath, - exist: tt.create, - ver: tt.localVer, - verCh: verCh, - }, - storePath: storePath, - imgCachePath: imgCachePath, - } - - dir := filepath.Join(storePath, "machines", tt.machineName) - err = os.MkdirAll(dir, 0700) - assert.NoError(t, err, "machine: %s", tt.machineName) - - err = b.CopyIsoToMachineDir("", tt.machineName) - assert.NoError(t, err) - - dest := filepath.Join(dir, b.filename()) - _, pathErr := os.Stat(dest) - - assert.NoError(t, err, "machine: %s", tt.machineName) - assert.True(t, !os.IsNotExist(pathErr), "machine: %s", tt.machineName) - - ver, err := b.version() - - assert.NoError(t, err, "machine: %s", tt.machineName) - assert.Equal(t, tt.wantVer, ver, "machine: %s", tt.machineName) - - err = removeFileIfExists(isopath) - assert.NoError(t, err, "machine: %s", tt.machineName) - } -} - -// newTestServer creates a new httptest.Server that returns respText as a response body. -func newTestServer(respText string) *httptest.Server { - return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(respText)) - })) -} - -// newDummyISO creates a dummy ISO file that contains the given version info, -// and returns its path and offset value to fetch the version info. -func newDummyISO(dir, name, version string) (string, int64, error) { - tmpDir, err := ioutil.TempDir("", "machine-test-") - if err != nil { - return "", 0, err - } - - tmpDir = filepath.Join(tmpDir, dir) - if e := os.MkdirAll(tmpDir, 755); e != nil { - return "", 0, err - } - - isopath := filepath.Join(tmpDir, name) - log.Info("TEST: dummy ISO created at ", isopath) - - // dummy ISO data mimicking the real byte data of a Boot2Docker ISO image - padding := " " - data := dummyISOData(padding, version) - return isopath, int64(len(padding)), ioutil.WriteFile(isopath, data, 0644) -} - -// dummyISOData returns mock data that contains given padding and version. -func dummyISOData(padding, version string) []byte { - return []byte(fmt.Sprintf("%sBoot2Docker-%s ", padding, version)) -} diff --git a/vendor/github.com/docker/machine/libmachine/mcnutils/utils.go b/vendor/github.com/docker/machine/libmachine/mcnutils/utils.go deleted file mode 100644 index a3992ed..0000000 --- a/vendor/github.com/docker/machine/libmachine/mcnutils/utils.go +++ /dev/null @@ -1,133 +0,0 @@ -package mcnutils - -import ( - "crypto/rand" - "encoding/hex" - "fmt" - "io" - "os" - "runtime" - "strconv" - "time" -) - -type MultiError struct { - Errs []error -} - -func (e MultiError) Error() string { - aggregate := "" - for _, err := range e.Errs { - aggregate += err.Error() + "\n" - } - return aggregate -} - -// GetHomeDir returns the home directory -// TODO: Having this here just strikes me as dangerous, but some of the drivers -// depend on it ;_; -func GetHomeDir() string { - if runtime.GOOS == "windows" { - return os.Getenv("USERPROFILE") - } - return os.Getenv("HOME") -} - -func GetUsername() string { - u := "unknown" - osUser := "" - - switch runtime.GOOS { - case "darwin", "linux": - osUser = os.Getenv("USER") - case "windows": - osUser = os.Getenv("USERNAME") - } - - if osUser != "" { - u = osUser - } - - return u -} - -func CopyFile(src, dst string) error { - in, err := os.Open(src) - if err != nil { - return err - } - - defer in.Close() - - out, err := os.Create(dst) - if err != nil { - return err - } - - defer out.Close() - - if _, err = io.Copy(out, in); err != nil { - return err - } - - fi, err := os.Stat(src) - if err != nil { - return err - } - - return os.Chmod(dst, fi.Mode()) -} - -func WaitForSpecificOrError(f func() (bool, error), maxAttempts int, waitInterval time.Duration) error { - for i := 0; i < maxAttempts; i++ { - stop, err := f() - if err != nil { - return err - } - if stop { - return nil - } - time.Sleep(waitInterval) - } - return fmt.Errorf("Maximum number of retries (%d) exceeded", maxAttempts) -} - -func WaitForSpecific(f func() bool, maxAttempts int, waitInterval time.Duration) error { - return WaitForSpecificOrError(func() (bool, error) { - return f(), nil - }, maxAttempts, waitInterval) -} - -func WaitFor(f func() bool) error { - return WaitForSpecific(f, 60, 3*time.Second) -} - -// TruncateID returns a shorten id -// Following two functions are from github.com/docker/docker/utils module. It -// was way overkill to include the whole module, so we just have these bits -// that we're using here. -func TruncateID(id string) string { - shortLen := 12 - if len(id) < shortLen { - shortLen = len(id) - } - return id[:shortLen] -} - -// GenerateRandomID returns an unique id -func GenerateRandomID() string { - for { - id := make([]byte, 32) - if _, err := io.ReadFull(rand.Reader, id); err != nil { - panic(err) // This shouldn't happen - } - value := hex.EncodeToString(id) - // if we try to parse the truncated for as an int and we don't have - // an error then the value is all numeric and causes issues when - // used as a hostname. ref #3869 - if _, err := strconv.ParseInt(TruncateID(value), 10, 64); err == nil { - continue - } - return value - } -} diff --git a/vendor/github.com/docker/machine/libmachine/mcnutils/utils_test.go b/vendor/github.com/docker/machine/libmachine/mcnutils/utils_test.go deleted file mode 100644 index 036e2b7..0000000 --- a/vendor/github.com/docker/machine/libmachine/mcnutils/utils_test.go +++ /dev/null @@ -1,101 +0,0 @@ -package mcnutils - -import ( - "io/ioutil" - "os" - "path/filepath" - "runtime" - "testing" -) - -func TestCopyFile(t *testing.T) { - testStr := "test-machine" - - srcFile, err := ioutil.TempFile("", "machine-test-") - if err != nil { - t.Fatal(err) - } - srcFi, err := srcFile.Stat() - if err != nil { - t.Fatal(err) - } - - srcFile.Write([]byte(testStr)) - srcFile.Close() - - srcFilePath := filepath.Join(os.TempDir(), srcFi.Name()) - - destFile, err := ioutil.TempFile("", "machine-copy-test-") - if err != nil { - t.Fatal(err) - } - - destFi, err := destFile.Stat() - if err != nil { - t.Fatal(err) - } - - destFile.Close() - - destFilePath := filepath.Join(os.TempDir(), destFi.Name()) - - if err := CopyFile(srcFilePath, destFilePath); err != nil { - t.Fatal(err) - } - - data, err := ioutil.ReadFile(destFilePath) - if err != nil { - t.Fatal(err) - } - - if string(data) != testStr { - t.Fatalf("expected data \"%s\"; received \"%s\"", testStr, string(data)) - } -} - -func TestGetUsername(t *testing.T) { - currentUser := "unknown" - switch runtime.GOOS { - case "darwin", "linux": - currentUser = os.Getenv("USER") - case "windows": - currentUser = os.Getenv("USERNAME") - } - - username := GetUsername() - if username != currentUser { - t.Fatalf("expected username %s; received %s", currentUser, username) - } -} - -func TestGenerateRandomID(t *testing.T) { - id := GenerateRandomID() - - if len(id) != 64 { - t.Fatalf("Id returned is incorrect: %s", id) - } -} - -func TestShortenId(t *testing.T) { - id := GenerateRandomID() - truncID := TruncateID(id) - if len(truncID) != 12 { - t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID) - } -} - -func TestShortenIdEmpty(t *testing.T) { - id := "" - truncID := TruncateID(id) - if len(truncID) > len(id) { - t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID) - } -} - -func TestShortenIdInvalid(t *testing.T) { - id := "1234" - truncID := TruncateID(id) - if len(truncID) != len(id) { - t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/persist/filestore.go b/vendor/github.com/docker/machine/libmachine/persist/filestore.go deleted file mode 100644 index ea79f44..0000000 --- a/vendor/github.com/docker/machine/libmachine/persist/filestore.go +++ /dev/null @@ -1,161 +0,0 @@ -package persist - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strings" - - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/mcnerror" -) - -type Filestore struct { - Path string - CaCertPath string - CaPrivateKeyPath string -} - -func NewFilestore(path, caCertPath, caPrivateKeyPath string) *Filestore { - return &Filestore{ - Path: path, - CaCertPath: caCertPath, - CaPrivateKeyPath: caPrivateKeyPath, - } -} - -func (s Filestore) GetMachinesDir() string { - return filepath.Join(s.Path, "machines") -} - -func (s Filestore) saveToFile(data []byte, file string) error { - if _, err := os.Stat(file); os.IsNotExist(err) { - return ioutil.WriteFile(file, data, 0600) - } - - tmpfi, err := ioutil.TempFile(filepath.Dir(file), "config.json.tmp") - if err != nil { - return err - } - defer os.Remove(tmpfi.Name()) - - if err = ioutil.WriteFile(tmpfi.Name(), data, 0600); err != nil { - return err - } - - if err = tmpfi.Close(); err != nil { - return err - } - - if err = os.Remove(file); err != nil { - return err - } - - err = os.Rename(tmpfi.Name(), file) - return err -} - -func (s Filestore) Save(host *host.Host) error { - data, err := json.MarshalIndent(host, "", " ") - if err != nil { - return err - } - - hostPath := filepath.Join(s.GetMachinesDir(), host.Name) - - // Ensure that the directory we want to save to exists. - if err := os.MkdirAll(hostPath, 0700); err != nil { - return err - } - - return s.saveToFile(data, filepath.Join(hostPath, "config.json")) -} - -func (s Filestore) Remove(name string) error { - hostPath := filepath.Join(s.GetMachinesDir(), name) - return os.RemoveAll(hostPath) -} - -func (s Filestore) List() ([]string, error) { - dir, err := ioutil.ReadDir(s.GetMachinesDir()) - if err != nil && !os.IsNotExist(err) { - return nil, err - } - - hostNames := []string{} - - for _, file := range dir { - if file.IsDir() && !strings.HasPrefix(file.Name(), ".") { - hostNames = append(hostNames, file.Name()) - } - } - - return hostNames, nil -} - -func (s Filestore) Exists(name string) (bool, error) { - _, err := os.Stat(filepath.Join(s.GetMachinesDir(), name)) - - if os.IsNotExist(err) { - return false, nil - } else if err == nil { - return true, nil - } - - return false, err -} - -func (s Filestore) loadConfig(h *host.Host) error { - data, err := ioutil.ReadFile(filepath.Join(s.GetMachinesDir(), h.Name, "config.json")) - if err != nil { - return err - } - - // Remember the machine name so we don't have to pass it through each - // struct in the migration. - name := h.Name - - migratedHost, migrationPerformed, err := host.MigrateHost(h, data) - if err != nil { - return fmt.Errorf("Error getting migrated host: %s", err) - } - - *h = *migratedHost - - h.Name = name - - // If we end up performing a migration, we should save afterwards so we don't have to do it again on subsequent invocations. - if migrationPerformed { - if err := s.saveToFile(data, filepath.Join(s.GetMachinesDir(), h.Name, "config.json.bak")); err != nil { - return fmt.Errorf("Error attempting to save backup after migration: %s", err) - } - - if err := s.Save(h); err != nil { - return fmt.Errorf("Error saving config after migration was performed: %s", err) - } - } - - return nil -} - -func (s Filestore) Load(name string) (*host.Host, error) { - hostPath := filepath.Join(s.GetMachinesDir(), name) - - if _, err := os.Stat(hostPath); os.IsNotExist(err) { - return nil, mcnerror.ErrHostDoesNotExist{ - Name: name, - } - } - - host := &host.Host{ - Name: name, - } - - if err := s.loadConfig(host); err != nil { - return nil, err - } - - return host, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/persist/filestore_test.go b/vendor/github.com/docker/machine/libmachine/persist/filestore_test.go deleted file mode 100644 index 243d565..0000000 --- a/vendor/github.com/docker/machine/libmachine/persist/filestore_test.go +++ /dev/null @@ -1,249 +0,0 @@ -package persist - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "regexp" - "testing" - - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/drivers/none" - "github.com/docker/machine/libmachine/host" - "github.com/docker/machine/libmachine/hosttest" -) - -func cleanup() { - os.RemoveAll(os.Getenv("MACHINE_STORAGE_PATH")) -} - -func getTestStore() Filestore { - tmpDir, err := ioutil.TempDir("", "machine-test-") - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - mcndirs.BaseDir = tmpDir - - return Filestore{ - Path: tmpDir, - CaCertPath: filepath.Join(tmpDir, "certs", "ca-cert.pem"), - CaPrivateKeyPath: filepath.Join(tmpDir, "certs", "ca-key.pem"), - } -} - -func TestStoreSave(t *testing.T) { - defer cleanup() - - store := getTestStore() - - h, err := hosttest.GetDefaultTestHost() - if err != nil { - t.Fatal(err) - } - - if err := store.Save(h); err != nil { - t.Fatal(err) - } - - path := filepath.Join(store.GetMachinesDir(), h.Name) - if _, err := os.Stat(path); os.IsNotExist(err) { - t.Fatalf("Host path doesn't exist: %s", path) - } - - files, _ := ioutil.ReadDir(path) - for _, f := range files { - r, err := regexp.Compile("config.json.tmp*") - if err != nil { - t.Fatalf("Failed to compile regexp string") - } - if r.MatchString(f.Name()) { - t.Fatalf("Failed to remove temp filestore:%s", f.Name()) - } - } -} - -func TestStoreSaveOmitRawDriver(t *testing.T) { - defer cleanup() - - store := getTestStore() - - h, err := hosttest.GetDefaultTestHost() - if err != nil { - t.Fatal(err) - } - - if err := store.Save(h); err != nil { - t.Fatal(err) - } - - configJSONPath := filepath.Join(store.GetMachinesDir(), h.Name, "config.json") - - f, err := os.Open(configJSONPath) - if err != nil { - t.Fatal(err) - } - - configData, err := ioutil.ReadAll(f) - if err != nil { - t.Fatal(err) - } - - fakeHost := make(map[string]interface{}) - - if err := json.Unmarshal(configData, &fakeHost); err != nil { - t.Fatal(err) - } - - if rawDriver, ok := fakeHost["RawDriver"]; ok { - t.Fatal("Should not have gotten a value for RawDriver reading host from disk but got one: ", rawDriver) - } - -} - -func TestStoreRemove(t *testing.T) { - defer cleanup() - - store := getTestStore() - - h, err := hosttest.GetDefaultTestHost() - if err != nil { - t.Fatal(err) - } - - if err := store.Save(h); err != nil { - t.Fatal(err) - } - - path := filepath.Join(store.GetMachinesDir(), h.Name) - if _, err := os.Stat(path); os.IsNotExist(err) { - t.Fatalf("Host path doesn't exist: %s", path) - } - - err = store.Remove(h.Name) - if err != nil { - t.Fatal(err) - } - - if _, err := os.Stat(path); err == nil { - t.Fatalf("Host path still exists after remove: %s", path) - } -} - -func TestStoreList(t *testing.T) { - defer cleanup() - - store := getTestStore() - - h, err := hosttest.GetDefaultTestHost() - if err != nil { - t.Fatal(err) - } - - if err := store.Save(h); err != nil { - t.Fatal(err) - } - - hosts, err := store.List() - if len(hosts) != 1 { - t.Fatalf("List returned %d items, expected 1", len(hosts)) - } - - if hosts[0] != h.Name { - t.Fatalf("hosts[0] name is incorrect, got: %s", hosts[0]) - } -} - -func TestStoreExists(t *testing.T) { - defer cleanup() - store := getTestStore() - - h, err := hosttest.GetDefaultTestHost() - if err != nil { - t.Fatal(err) - } - - exists, err := store.Exists(h.Name) - if exists { - t.Fatal("Host should not exist before saving") - } - - if err := store.Save(h); err != nil { - t.Fatal(err) - } - - exists, err = store.Exists(h.Name) - if err != nil { - t.Fatal(err) - } - - if !exists { - t.Fatal("Host should exist after saving") - } - - if err := store.Remove(h.Name); err != nil { - t.Fatal(err) - } - - exists, err = store.Exists(h.Name) - if err != nil { - t.Fatal(err) - } - - if exists { - t.Fatal("Host should not exist after removing") - } -} - -func TestStoreLoad(t *testing.T) { - defer cleanup() - - expectedURL := "unix:///foo/baz" - flags := hosttest.GetTestDriverFlags() - flags.Data["url"] = expectedURL - - store := getTestStore() - - h, err := hosttest.GetDefaultTestHost() - if err != nil { - t.Fatal(err) - } - - if err := h.Driver.SetConfigFromFlags(flags); err != nil { - t.Fatal(err) - } - - if err := store.Save(h); err != nil { - t.Fatal(err) - } - - h, err = store.Load(h.Name) - if err != nil { - t.Fatal(err) - } - - rawDataDriver, ok := h.Driver.(*host.RawDataDriver) - if !ok { - t.Fatal("Expected driver loaded from store to be of type *host.RawDataDriver and it was not") - } - - realDriver := none.NewDriver(h.Name, store.Path) - - if err := json.Unmarshal(rawDataDriver.Data, &realDriver); err != nil { - t.Fatalf("Error unmarshaling rawDataDriver data into concrete 'none' driver: %s", err) - } - - h.Driver = realDriver - - actualURL, err := h.URL() - if err != nil { - t.Fatal(err) - } - - if actualURL != expectedURL { - t.Fatalf("GetURL is not %q, got %q", expectedURL, actualURL) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/persist/persisttest/fakestore.go b/vendor/github.com/docker/machine/libmachine/persist/persisttest/fakestore.go deleted file mode 100644 index 96c42ce..0000000 --- a/vendor/github.com/docker/machine/libmachine/persist/persisttest/fakestore.go +++ /dev/null @@ -1,63 +0,0 @@ -package persisttest - -import "github.com/docker/machine/libmachine/host" - -type FakeStore struct { - Hosts []*host.Host - ExistsErr, ListErr, LoadErr, RemoveErr, SaveErr error -} - -func (fs *FakeStore) Exists(name string) (bool, error) { - if fs.ExistsErr != nil { - return false, fs.ExistsErr - } - for _, h := range fs.Hosts { - if h.Name == name { - return true, nil - } - } - - return false, nil -} - -func (fs *FakeStore) List() ([]string, error) { - names := []string{} - for _, h := range fs.Hosts { - names = append(names, h.Name) - } - return names, fs.ListErr -} - -func (fs *FakeStore) Load(name string) (*host.Host, error) { - if fs.LoadErr != nil { - return nil, fs.LoadErr - } - for _, h := range fs.Hosts { - if h.Name == name { - return h, nil - } - } - - return nil, nil -} - -func (fs *FakeStore) Remove(name string) error { - if fs.RemoveErr != nil { - return fs.RemoveErr - } - for i, h := range fs.Hosts { - if h.Name == name { - fs.Hosts = append(fs.Hosts[:i], fs.Hosts[i+1:]...) - return nil - } - } - return nil -} - -func (fs *FakeStore) Save(host *host.Host) error { - if fs.SaveErr == nil { - fs.Hosts = append(fs.Hosts, host) - return nil - } - return fs.SaveErr -} diff --git a/vendor/github.com/docker/machine/libmachine/persist/persisttest/fakestore_test.go b/vendor/github.com/docker/machine/libmachine/persist/persisttest/fakestore_test.go deleted file mode 100644 index 9fbffd9..0000000 --- a/vendor/github.com/docker/machine/libmachine/persist/persisttest/fakestore_test.go +++ /dev/null @@ -1,124 +0,0 @@ -package persisttest - -import ( - "fmt" - "reflect" - "testing" - - "github.com/docker/machine/libmachine/host" -) - -func TestExists(t *testing.T) { - store := FakeStore{ - Hosts: []*host.Host{{Name: "my-host"}}, - } - exist, err := store.Exists("my-host") - if err != nil { - t.Fatal(err) - } - if exist == false { - t.Fatal("Expected host 'my-host' to exist") - } - exist, err = store.Exists("not-found") - if err != nil { - t.Fatal(err) - } - if exist == true { - t.Fatal("Expected host 'not-found' to no exist") - } - store.ExistsErr = fmt.Errorf("error checking host") - exist, err = store.Exists("my-host") - if err != store.ExistsErr { - t.Fatalf("Expected err %s.", store.ExistsErr) - } -} - -func TestList(t *testing.T) { - store := FakeStore{ - Hosts: []*host.Host{{Name: "my-host"}, {Name: "my-host-2"}}, - } - list, err := store.List() - if err != nil { - t.Fatal(err) - } - expected := []string{"my-host", "my-host-2"} - if !reflect.DeepEqual(list, expected) { - t.Fatalf("Expected hosts to be %s. Got %s.", expected, list) - } - store.ListErr = fmt.Errorf("error listing") - list, err = store.List() - if err != store.ListErr { - t.Fatal(err) - } -} - -func TestLoad(t *testing.T) { - expectedHost := &host.Host{Name: "my-host"} - store := FakeStore{ - Hosts: []*host.Host{expectedHost}, - } - h, err := store.Load("my-host") - if err != nil { - t.Fatal(err) - } - if !reflect.DeepEqual(expectedHost, h) { - t.Fatalf("Wrong host. Expected %v. Got %v.", expectedHost, h) - } - h, err = store.Load("not-found") - if err != nil { - t.Fatal(err) - } - if h != nil { - t.Fatalf("Expected nil host. Got %v.", h) - } - store.LoadErr = fmt.Errorf("error loading") - h, err = store.Load("my-host") - if err != store.LoadErr { - t.Fatalf("Wrong error. Expected %s. Got %s.", store.LoadErr, err) - } - if h != nil { - t.Fatalf("Expected nil host. Got %v.", h) - } -} - -func TestRemove(t *testing.T) { - store := FakeStore{ - Hosts: []*host.Host{{Name: "my-host"}}, - } - err := store.Remove("not-found") - if err != nil { - t.Fatal(err) - } - err = store.Remove("my-host") - if err != nil { - t.Fatal(err) - } - if len(store.Hosts) != 0 { - t.Fatalf("Expected hosts length to be zero. Got %d", len(store.Hosts)) - } - store.RemoveErr = fmt.Errorf("error removing") - err = store.Remove("my-host") - if err != store.RemoveErr { - t.Fatal(err) - } -} - -func TestSave(t *testing.T) { - store := FakeStore{} - err := store.Save(&host.Host{Name: "my-host"}) - if err != nil { - t.Fatal(err) - } - expectedHosts := []*host.Host{{Name: "my-host"}} - if !reflect.DeepEqual(store.Hosts, expectedHosts) { - t.Fatalf("Expected hosts to be %v. Got %v.", expectedHosts, store.Hosts) - } - store.SaveErr = fmt.Errorf("error saving") - err = store.Save(&host.Host{Name: "new-host"}) - if err != store.SaveErr { - t.Fatal(err) - } - if !reflect.DeepEqual(store.Hosts, expectedHosts) { - t.Fatalf("Expected hosts to be %v. Got %v.", expectedHosts, store.Hosts) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/persist/store.go b/vendor/github.com/docker/machine/libmachine/persist/store.go deleted file mode 100644 index 1d9d489..0000000 --- a/vendor/github.com/docker/machine/libmachine/persist/store.go +++ /dev/null @@ -1,47 +0,0 @@ -package persist - -import ( - "github.com/docker/machine/libmachine/host" -) - -type Store interface { - // Exists returns whether a machine exists or not - Exists(name string) (bool, error) - - // List returns a list of all hosts in the store - List() ([]string, error) - - // Load loads a host by name - Load(name string) (*host.Host, error) - - // Remove removes a machine from the store - Remove(name string) error - - // Save persists a machine in the store - Save(host *host.Host) error -} - -func LoadHosts(s Store, hostNames []string) ([]*host.Host, map[string]error) { - loadedHosts := []*host.Host{} - errors := map[string]error{} - - for _, hostName := range hostNames { - h, err := s.Load(hostName) - if err != nil { - errors[hostName] = err - } else { - loadedHosts = append(loadedHosts, h) - } - } - - return loadedHosts, errors -} - -func LoadAllHosts(s Store) ([]*host.Host, map[string]error, error) { - hostNames, err := s.List() - if err != nil { - return nil, nil, err - } - loadedHosts, hostInError := LoadHosts(s, hostNames) - return loadedHosts, hostInError, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/provider/provider.go b/vendor/github.com/docker/machine/libmachine/provider/provider.go deleted file mode 100644 index 294c283..0000000 --- a/vendor/github.com/docker/machine/libmachine/provider/provider.go +++ /dev/null @@ -1,13 +0,0 @@ -package provider - -import "github.com/docker/machine/libmachine/host" - -type Provider interface { - // IsValid checks whether or not the Provider can successfully create - // machines. If the check does not pass, the provider is no good. - IsValid() bool - - // Create calls out to the driver this provider is associated with, to - // actually create the resource. - Create() (host.Host, error) -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/arch.go b/vendor/github.com/docker/machine/libmachine/provision/arch.go deleted file mode 100644 index 6a73998..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/arch.go +++ /dev/null @@ -1,152 +0,0 @@ -package provision - -import ( - "fmt" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/swarm" -) - -func init() { - Register("Arch", &RegisteredProvisioner{ - New: NewArchProvisioner, - }) -} - -func NewArchProvisioner(d drivers.Driver) Provisioner { - return &ArchProvisioner{ - NewSystemdProvisioner("arch", d), - } -} - -type ArchProvisioner struct { - SystemdProvisioner -} - -func (provisioner *ArchProvisioner) String() string { - return "arch" -} - -func (provisioner *ArchProvisioner) CompatibleWithHost() bool { - return provisioner.OsReleaseInfo.ID == provisioner.OsReleaseID || provisioner.OsReleaseInfo.IDLike == provisioner.OsReleaseID -} - -func (provisioner *ArchProvisioner) Package(name string, action pkgaction.PackageAction) error { - var packageAction string - - updateMetadata := true - - switch action { - case pkgaction.Install, pkgaction.Upgrade: - packageAction = "S" - case pkgaction.Remove: - packageAction = "R" - updateMetadata = false - } - - switch name { - case "docker-engine": - name = "docker" - case "docker": - name = "docker" - } - - pacmanOpts := "-" + packageAction - if updateMetadata { - pacmanOpts = pacmanOpts + "y" - } - - pacmanOpts = pacmanOpts + " --noconfirm --noprogressbar" - - command := fmt.Sprintf("sudo -E pacman %s %s", pacmanOpts, name) - - log.Debugf("package: action=%s name=%s", action.String(), name) - - if _, err := provisioner.SSHCommand(command); err != nil { - return err - } - - return nil -} - -func (provisioner *ArchProvisioner) dockerDaemonResponding() bool { - log.Debug("checking docker daemon") - - if out, err := provisioner.SSHCommand("sudo docker version"); err != nil { - log.Warnf("Error getting SSH command to check if the daemon is up: %s", err) - log.Debugf("'sudo docker version' output:\n%s", out) - return false - } - - // The daemon is up if the command worked. Carry on. - return true -} - -func (provisioner *ArchProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - provisioner.SwarmOptions = swarmOptions - provisioner.AuthOptions = authOptions - provisioner.EngineOptions = engineOptions - swarmOptions.Env = engineOptions.Env - - storageDriver, err := decideStorageDriver(provisioner, "overlay", engineOptions.StorageDriver) - if err != nil { - return err - } - provisioner.EngineOptions.StorageDriver = storageDriver - - // HACK: since Arch does not come with sudo by default we install - log.Debug("Installing sudo") - if _, err := provisioner.SSHCommand("if ! type sudo; then pacman -Sy --noconfirm --noprogressbar sudo; fi"); err != nil { - return err - } - - log.Debug("Setting hostname") - if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { - return err - } - - log.Debug("Installing base packages") - for _, pkg := range provisioner.Packages { - if err := provisioner.Package(pkg, pkgaction.Install); err != nil { - return err - } - } - - log.Debug("Installing docker") - if err := provisioner.Package("docker", pkgaction.Install); err != nil { - return err - } - - log.Debug("Starting systemd docker service") - if err := provisioner.Service("docker", serviceaction.Start); err != nil { - return err - } - - log.Debug("Waiting for docker daemon") - if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil { - return err - } - - provisioner.AuthOptions = setRemoteAuthOptions(provisioner) - - log.Debug("Configuring auth") - if err := ConfigureAuth(provisioner); err != nil { - return err - } - - log.Debug("Configuring swarm") - if err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions); err != nil { - return err - } - - // enable in systemd - log.Debug("Enabling docker in systemd") - err = provisioner.Service("docker", serviceaction.Enable) - return err -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/arch_test.go b/vendor/github.com/docker/machine/libmachine/provision/arch_test.go deleted file mode 100644 index 4aa19b6..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/arch_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package provision - -import ( - "testing" - - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/provision/provisiontest" - "github.com/docker/machine/libmachine/swarm" -) - -func TestArchDefaultStorageDriver(t *testing.T) { - p := NewArchProvisioner(&fakedriver.Driver{}).(*ArchProvisioner) - p.SSHCommander = provisiontest.NewFakeSSHCommander(provisiontest.FakeSSHCommanderOptions{}) - p.Provision(swarm.Options{}, auth.Options{}, engine.Options{}) - if p.EngineOptions.StorageDriver != "overlay" { - t.Fatal("Default storage driver should be overlay") - } -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/boot2docker.go b/vendor/github.com/docker/machine/libmachine/provision/boot2docker.go deleted file mode 100644 index 7c5d651..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/boot2docker.go +++ /dev/null @@ -1,268 +0,0 @@ -package provision - -import ( - "bytes" - "encoding/json" - "fmt" - "net" - "path" - "text/template" - "time" - - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/state" - "github.com/docker/machine/libmachine/swarm" -) - -func init() { - Register("boot2docker", &RegisteredProvisioner{ - New: NewBoot2DockerProvisioner, - }) -} - -func NewBoot2DockerProvisioner(d drivers.Driver) Provisioner { - return &Boot2DockerProvisioner{ - Driver: d, - } -} - -type Boot2DockerProvisioner struct { - OsReleaseInfo *OsRelease - Driver drivers.Driver - AuthOptions auth.Options - EngineOptions engine.Options - SwarmOptions swarm.Options -} - -func (provisioner *Boot2DockerProvisioner) String() string { - return "boot2docker" -} - -func (provisioner *Boot2DockerProvisioner) Service(name string, action serviceaction.ServiceAction) error { - _, err := provisioner.SSHCommand(fmt.Sprintf("sudo /etc/init.d/%s %s", name, action.String())) - return err -} - -func (provisioner *Boot2DockerProvisioner) upgradeIso() error { - // TODO: Ideally, we should not read from mcndirs directory at all. - // The driver should be able to communicate how and where to place the - // relevant files. - b2dutils := mcnutils.NewB2dUtils(mcndirs.GetBaseDir()) - - // Check if the driver has specified a custom b2d url - jsonDriver, err := json.Marshal(provisioner.GetDriver()) - if err != nil { - return err - } - var d struct { - Boot2DockerURL string - } - json.Unmarshal(jsonDriver, &d) - - log.Info("Stopping machine to do the upgrade...") - - if err := provisioner.Driver.Stop(); err != nil { - return err - } - - if err := mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil { - return err - } - - machineName := provisioner.GetDriver().GetMachineName() - - log.Infof("Upgrading machine %q...", machineName) - - // Either download the latest version of the b2d url that was explicitly - // specified when creating the VM or copy the (updated) default ISO - if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, machineName); err != nil { - return err - } - - log.Infof("Starting machine back up...") - - if err := provisioner.Driver.Start(); err != nil { - return err - } - - return mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running)) -} - -func (provisioner *Boot2DockerProvisioner) Package(name string, action pkgaction.PackageAction) error { - if name == "docker" && action == pkgaction.Upgrade { - if err := provisioner.upgradeIso(); err != nil { - return err - } - } - return nil -} - -func (provisioner *Boot2DockerProvisioner) Hostname() (string, error) { - return provisioner.SSHCommand("hostname") -} - -func (provisioner *Boot2DockerProvisioner) SetHostname(hostname string) error { - if _, err := provisioner.SSHCommand(fmt.Sprintf( - "sudo /usr/bin/sethostname %s && echo %q | sudo tee /var/lib/boot2docker/etc/hostname", - hostname, - hostname, - )); err != nil { - return err - } - - return nil -} - -func (provisioner *Boot2DockerProvisioner) GetDockerOptionsDir() string { - return "/var/lib/boot2docker" -} - -func (provisioner *Boot2DockerProvisioner) GetAuthOptions() auth.Options { - return provisioner.AuthOptions -} - -func (provisioner *Boot2DockerProvisioner) GetSwarmOptions() swarm.Options { - return provisioner.SwarmOptions -} - -func (provisioner *Boot2DockerProvisioner) GenerateDockerOptions(dockerPort int) (*DockerOptions, error) { - var ( - engineCfg bytes.Buffer - ) - - driverNameLabel := fmt.Sprintf("provider=%s", provisioner.Driver.DriverName()) - provisioner.EngineOptions.Labels = append(provisioner.EngineOptions.Labels, driverNameLabel) - - engineConfigTmpl := ` -EXTRA_ARGS=' -{{ range .EngineOptions.Labels }}--label {{.}} -{{ end }}{{ range .EngineOptions.InsecureRegistry }}--insecure-registry {{.}} -{{ end }}{{ range .EngineOptions.RegistryMirror }}--registry-mirror {{.}} -{{ end }}{{ range .EngineOptions.ArbitraryFlags }}--{{.}} -{{ end }} -' -CACERT={{.AuthOptions.CaCertRemotePath}} -DOCKER_HOST='-H tcp://0.0.0.0:{{.DockerPort}}' -DOCKER_STORAGE={{.EngineOptions.StorageDriver}} -DOCKER_TLS=auto -SERVERKEY={{.AuthOptions.ServerKeyRemotePath}} -SERVERCERT={{.AuthOptions.ServerCertRemotePath}} - -{{range .EngineOptions.Env}}export \"{{ printf "%q" . }}\" -{{end}} -` - t, err := template.New("engineConfig").Parse(engineConfigTmpl) - if err != nil { - return nil, err - } - - engineConfigContext := EngineConfigContext{ - DockerPort: dockerPort, - AuthOptions: provisioner.AuthOptions, - EngineOptions: provisioner.EngineOptions, - } - - t.Execute(&engineCfg, engineConfigContext) - - daemonOptsDir := path.Join(provisioner.GetDockerOptionsDir(), "profile") - return &DockerOptions{ - EngineOptions: engineCfg.String(), - EngineOptionsPath: daemonOptsDir, - }, nil -} - -func (provisioner *Boot2DockerProvisioner) CompatibleWithHost() bool { - return provisioner.OsReleaseInfo.ID == "boot2docker" -} - -func (provisioner *Boot2DockerProvisioner) SetOsReleaseInfo(info *OsRelease) { - provisioner.OsReleaseInfo = info -} - -func (provisioner *Boot2DockerProvisioner) GetOsReleaseInfo() (*OsRelease, error) { - return provisioner.OsReleaseInfo, nil -} - -func (provisioner *Boot2DockerProvisioner) AttemptIPContact(dockerPort int) { - ip, err := provisioner.Driver.GetIP() - if err != nil { - log.Warnf("Could not get IP address for created machine: %s", err) - return - } - - if conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, dockerPort), 5*time.Second); err != nil { - log.Warnf(` -This machine has been allocated an IP address, but Docker Machine could not -reach it successfully. - -SSH for the machine should still work, but connecting to exposed ports, such as -the Docker daemon port (usually :%d), may not work properly. - -You may need to add the route manually, or use another related workaround. - -This could be due to a VPN, proxy, or host file configuration issue. - -You also might want to clear any VirtualBox host only interfaces you are not using.`, engine.DefaultPort) - } else { - conn.Close() - } -} - -func (provisioner *Boot2DockerProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - var ( - err error - ) - - defer func() { - if err == nil { - provisioner.AttemptIPContact(engine.DefaultPort) - } - }() - - provisioner.SwarmOptions = swarmOptions - provisioner.AuthOptions = authOptions - provisioner.EngineOptions = engineOptions - swarmOptions.Env = engineOptions.Env - - if provisioner.EngineOptions.StorageDriver == "" { - provisioner.EngineOptions.StorageDriver = "aufs" - } - - if err = provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { - return err - } - - // b2d hosts need to wait for the daemon to be up - // before continuing with provisioning - if err = WaitForDocker(provisioner, engine.DefaultPort); err != nil { - return err - } - - if err = makeDockerOptionsDir(provisioner); err != nil { - return err - } - - provisioner.AuthOptions = setRemoteAuthOptions(provisioner) - - if err = ConfigureAuth(provisioner); err != nil { - return err - } - - err = configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions) - return err -} - -func (provisioner *Boot2DockerProvisioner) SSHCommand(args string) (string, error) { - return drivers.RunSSHCommandFromDriver(provisioner.Driver, args) -} - -func (provisioner *Boot2DockerProvisioner) GetDriver() drivers.Driver { - return provisioner.Driver -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/centos.go b/vendor/github.com/docker/machine/libmachine/provision/centos.go deleted file mode 100644 index 11c01a3..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/centos.go +++ /dev/null @@ -1,25 +0,0 @@ -package provision - -import ( - "github.com/docker/machine/libmachine/drivers" -) - -func init() { - Register("Centos", &RegisteredProvisioner{ - New: NewCentosProvisioner, - }) -} - -func NewCentosProvisioner(d drivers.Driver) Provisioner { - return &CentosProvisioner{ - NewRedHatProvisioner("centos", d), - } -} - -type CentosProvisioner struct { - *RedHatProvisioner -} - -func (provisioner *CentosProvisioner) String() string { - return "centos" -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/configure_swarm.go b/vendor/github.com/docker/machine/libmachine/provision/configure_swarm.go deleted file mode 100644 index 5d7545c..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/configure_swarm.go +++ /dev/null @@ -1,149 +0,0 @@ -package provision - -import ( - "fmt" - "net/url" - "strconv" - "strings" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcndockerclient" - "github.com/docker/machine/libmachine/swarm" - "github.com/samalba/dockerclient" -) - -func configureSwarm(p Provisioner, swarmOptions swarm.Options, authOptions auth.Options) error { - if !swarmOptions.IsSwarm { - return nil - } - - log.Info("Configuring swarm...") - - ip, err := p.GetDriver().GetIP() - if err != nil { - return err - } - - u, err := url.Parse(swarmOptions.Host) - if err != nil { - return err - } - - enginePort := engine.DefaultPort - engineURL, err := p.GetDriver().GetURL() - if err != nil { - return err - } - - parts := strings.Split(engineURL, ":") - if len(parts) == 3 { - dPort, err := strconv.Atoi(parts[2]) - if err != nil { - return err - } - enginePort = dPort - } - - parts = strings.Split(u.Host, ":") - port := parts[1] - - dockerDir := p.GetDockerOptionsDir() - dockerHost := &mcndockerclient.RemoteDocker{ - HostURL: fmt.Sprintf("tcp://%s:%d", ip, enginePort), - AuthOption: &authOptions, - } - advertiseInfo := fmt.Sprintf("%s:%d", ip, enginePort) - - if swarmOptions.Master { - advertiseMasterInfo := fmt.Sprintf("%s:%s", ip, "3376") - cmd := fmt.Sprintf("manage --tlsverify --tlscacert=%s --tlscert=%s --tlskey=%s -H %s --strategy %s --advertise %s", - authOptions.CaCertRemotePath, - authOptions.ServerCertRemotePath, - authOptions.ServerKeyRemotePath, - swarmOptions.Host, - swarmOptions.Strategy, - advertiseMasterInfo, - ) - if swarmOptions.IsExperimental { - cmd = "--experimental " + cmd - } - - cmdMaster := strings.Fields(cmd) - for _, option := range swarmOptions.ArbitraryFlags { - cmdMaster = append(cmdMaster, "--"+option) - } - - //Discovery must be at end of command - cmdMaster = append(cmdMaster, swarmOptions.Discovery) - - hostBind := fmt.Sprintf("%s:%s", dockerDir, dockerDir) - masterHostConfig := dockerclient.HostConfig{ - RestartPolicy: dockerclient.RestartPolicy{ - Name: "always", - MaximumRetryCount: 0, - }, - Binds: []string{hostBind}, - PortBindings: map[string][]dockerclient.PortBinding{ - fmt.Sprintf("%s/tcp", port): { - { - HostIp: "0.0.0.0", - HostPort: port, - }, - }, - }, - } - - swarmMasterConfig := &dockerclient.ContainerConfig{ - Image: swarmOptions.Image, - Env: swarmOptions.Env, - ExposedPorts: map[string]struct{}{ - "2375/tcp": {}, - fmt.Sprintf("%s/tcp", port): {}, - }, - Cmd: cmdMaster, - HostConfig: masterHostConfig, - } - - err = mcndockerclient.CreateContainer(dockerHost, swarmMasterConfig, "swarm-agent-master") - if err != nil { - return err - } - } - - if swarmOptions.Agent { - workerHostConfig := dockerclient.HostConfig{ - RestartPolicy: dockerclient.RestartPolicy{ - Name: "always", - MaximumRetryCount: 0, - }, - } - - cmdWorker := []string{ - "join", - "--advertise", - advertiseInfo, - } - for _, option := range swarmOptions.ArbitraryJoinFlags { - cmdWorker = append(cmdWorker, "--"+option) - } - cmdWorker = append(cmdWorker, swarmOptions.Discovery) - - swarmWorkerConfig := &dockerclient.ContainerConfig{ - Image: swarmOptions.Image, - Env: swarmOptions.Env, - Cmd: cmdWorker, - HostConfig: workerHostConfig, - } - if swarmOptions.IsExperimental { - swarmWorkerConfig.Cmd = append([]string{"--experimental"}, swarmWorkerConfig.Cmd...) - } - - err = mcndockerclient.CreateContainer(dockerHost, swarmWorkerConfig, "swarm-agent") - if err != nil { - return err - } - } - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/coreos.go b/vendor/github.com/docker/machine/libmachine/provision/coreos.go deleted file mode 100644 index bbb798b..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/coreos.go +++ /dev/null @@ -1,132 +0,0 @@ -package provision - -import ( - "bytes" - "fmt" - "text/template" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/swarm" - "github.com/docker/machine/libmachine/versioncmp" -) - -const ( - hostTmpl = `sudo tee /var/tmp/hostname.yml << EOF -#cloud-config - -hostname: %s -EOF -` -) - -func init() { - Register("CoreOS", &RegisteredProvisioner{ - New: NewCoreOSProvisioner, - }) -} - -func NewCoreOSProvisioner(d drivers.Driver) Provisioner { - return &CoreOSProvisioner{ - NewSystemdProvisioner("coreos", d), - } -} - -type CoreOSProvisioner struct { - SystemdProvisioner -} - -func (provisioner *CoreOSProvisioner) String() string { - return "coreOS" -} - -func (provisioner *CoreOSProvisioner) SetHostname(hostname string) error { - log.Debugf("SetHostname: %s", hostname) - - if _, err := provisioner.SSHCommand(fmt.Sprintf(hostTmpl, hostname)); err != nil { - return err - } - - if _, err := provisioner.SSHCommand("sudo systemctl start system-cloudinit@var-tmp-hostname.yml.service"); err != nil { - return err - } - - return nil -} - -func (provisioner *CoreOSProvisioner) GenerateDockerOptions(dockerPort int) (*DockerOptions, error) { - var ( - engineCfg bytes.Buffer - ) - - driverNameLabel := fmt.Sprintf("provider=%s", provisioner.Driver.DriverName()) - provisioner.EngineOptions.Labels = append(provisioner.EngineOptions.Labels, driverNameLabel) - - dockerVersion, err := DockerClientVersion(provisioner) - if err != nil { - return nil, err - } - - arg := "daemon" - if versioncmp.GreaterThanOrEqualTo(dockerVersion, "1.12.0") { - arg = "" - } - - engineConfigTmpl := `[Service] -Environment=TMPDIR=/var/tmp -ExecStart= -ExecStart=/usr/lib/coreos/dockerd ` + arg + ` --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:{{.DockerPort}} --tlsverify --tlscacert {{.AuthOptions.CaCertRemotePath}} --tlscert {{.AuthOptions.ServerCertRemotePath}} --tlskey {{.AuthOptions.ServerKeyRemotePath}}{{ range .EngineOptions.Labels }} --label {{.}}{{ end }}{{ range .EngineOptions.InsecureRegistry }} --insecure-registry {{.}}{{ end }}{{ range .EngineOptions.RegistryMirror }} --registry-mirror {{.}}{{ end }}{{ range .EngineOptions.ArbitraryFlags }} --{{.}}{{ end }} \$DOCKER_OPTS \$DOCKER_OPT_BIP \$DOCKER_OPT_MTU \$DOCKER_OPT_IPMASQ -Environment={{range .EngineOptions.Env}}{{ printf "%q" . }} {{end}} -` - - t, err := template.New("engineConfig").Parse(engineConfigTmpl) - if err != nil { - return nil, err - } - - engineConfigContext := EngineConfigContext{ - DockerPort: dockerPort, - AuthOptions: provisioner.AuthOptions, - EngineOptions: provisioner.EngineOptions, - } - - t.Execute(&engineCfg, engineConfigContext) - - return &DockerOptions{ - EngineOptions: engineCfg.String(), - EngineOptionsPath: provisioner.DaemonOptionsFile, - }, nil -} - -func (provisioner *CoreOSProvisioner) Package(name string, action pkgaction.PackageAction) error { - return nil -} - -func (provisioner *CoreOSProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - provisioner.SwarmOptions = swarmOptions - provisioner.AuthOptions = authOptions - provisioner.EngineOptions = engineOptions - - if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { - return err - } - - if err := makeDockerOptionsDir(provisioner); err != nil { - return err - } - - log.Debugf("Preparing certificates") - provisioner.AuthOptions = setRemoteAuthOptions(provisioner) - - log.Debugf("Setting up certificates") - if err := ConfigureAuth(provisioner); err != nil { - return err - } - - log.Debug("Configuring swarm") - err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions) - return err -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/debian.go b/vendor/github.com/docker/machine/libmachine/provision/debian.go deleted file mode 100644 index c7cd476..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/debian.go +++ /dev/null @@ -1,143 +0,0 @@ -package provision - -import ( - "fmt" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/swarm" -) - -func init() { - Register("Debian", &RegisteredProvisioner{ - New: NewDebianProvisioner, - }) -} - -func NewDebianProvisioner(d drivers.Driver) Provisioner { - return &DebianProvisioner{ - NewSystemdProvisioner("debian", d), - } -} - -type DebianProvisioner struct { - SystemdProvisioner -} - -func (provisioner *DebianProvisioner) String() string { - return "debian" -} - -func (provisioner *DebianProvisioner) Package(name string, action pkgaction.PackageAction) error { - var packageAction string - - updateMetadata := true - - switch action { - case pkgaction.Install, pkgaction.Upgrade: - packageAction = "install" - case pkgaction.Remove: - packageAction = "remove" - updateMetadata = false - case pkgaction.Purge: - packageAction = "purge" - updateMetadata = false - } - - switch name { - case "docker": - name = "docker-engine" - } - - if updateMetadata { - if err := waitForLockAptGetUpdate(provisioner); err != nil { - return err - } - } - - command := fmt.Sprintf("DEBIAN_FRONTEND=noninteractive sudo -E apt-get %s -y %s", packageAction, name) - - log.Debugf("package: action=%s name=%s", action.String(), name) - - if _, err := provisioner.SSHCommand(command); err != nil { - return err - } - - return nil -} - -func (provisioner *DebianProvisioner) dockerDaemonResponding() bool { - log.Debug("checking docker daemon") - - if out, err := provisioner.SSHCommand("sudo docker version"); err != nil { - log.Warnf("Error getting SSH command to check if the daemon is up: %s", err) - log.Debugf("'sudo docker version' output:\n%s", out) - return false - } - - // The daemon is up if the command worked. Carry on. - return true -} - -func (provisioner *DebianProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - provisioner.SwarmOptions = swarmOptions - provisioner.AuthOptions = authOptions - provisioner.EngineOptions = engineOptions - swarmOptions.Env = engineOptions.Env - - storageDriver, err := decideStorageDriver(provisioner, "aufs", engineOptions.StorageDriver) - if err != nil { - return err - } - provisioner.EngineOptions.StorageDriver = storageDriver - - // HACK: since debian does not come with sudo by default we install - log.Debug("installing sudo") - if _, err := provisioner.SSHCommand("if ! type sudo; then apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y sudo; fi"); err != nil { - return err - } - - log.Debug("setting hostname") - if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { - return err - } - - log.Debug("installing base packages") - for _, pkg := range provisioner.Packages { - if err := provisioner.Package(pkg, pkgaction.Install); err != nil { - return err - } - } - - log.Debug("installing docker") - if err := installDockerGeneric(provisioner, engineOptions.InstallURL); err != nil { - return err - } - - log.Debug("waiting for docker daemon") - if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil { - return err - } - - provisioner.AuthOptions = setRemoteAuthOptions(provisioner) - - log.Debug("configuring auth") - if err := ConfigureAuth(provisioner); err != nil { - return err - } - - log.Debug("configuring swarm") - if err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions); err != nil { - return err - } - - // enable in systemd - log.Debug("enabling docker in systemd") - err = provisioner.Service("docker", serviceaction.Enable) - return err -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/debian_test.go b/vendor/github.com/docker/machine/libmachine/provision/debian_test.go deleted file mode 100644 index 2d1f944..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/debian_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package provision - -import ( - "testing" - - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/provision/provisiontest" - "github.com/docker/machine/libmachine/swarm" -) - -func TestDebianDefaultStorageDriver(t *testing.T) { - p := NewDebianProvisioner(&fakedriver.Driver{}).(*DebianProvisioner) - p.SSHCommander = provisiontest.NewFakeSSHCommander(provisiontest.FakeSSHCommanderOptions{}) - p.Provision(swarm.Options{}, auth.Options{}, engine.Options{}) - if p.EngineOptions.StorageDriver != "aufs" { - t.Fatal("Default storage driver should be aufs") - } -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/engine_config_context.go b/vendor/github.com/docker/machine/libmachine/provision/engine_config_context.go deleted file mode 100644 index 7a7e9a8..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/engine_config_context.go +++ /dev/null @@ -1,13 +0,0 @@ -package provision - -import ( - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" -) - -type EngineConfigContext struct { - DockerPort int - AuthOptions auth.Options - EngineOptions engine.Options - DockerOptionsDir string -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/errors.go b/vendor/github.com/docker/machine/libmachine/provision/errors.go deleted file mode 100644 index 46348b9..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/errors.go +++ /dev/null @@ -1,24 +0,0 @@ -package provision - -import ( - "errors" - "fmt" -) - -var ( - ErrDetectionFailed = errors.New("OS type not recognized") -) - -type ErrDaemonAvailable struct { - wrappedErr error -} - -func (e ErrDaemonAvailable) Error() string { - return fmt.Sprintf("Unable to verify the Docker daemon is listening: %s", e.wrappedErr) -} - -func NewErrDaemonAvailable(err error) ErrDaemonAvailable { - return ErrDaemonAvailable{ - wrappedErr: err, - } -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/fake_provisioner.go b/vendor/github.com/docker/machine/libmachine/provision/fake_provisioner.go deleted file mode 100644 index 7d4caae..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/fake_provisioner.go +++ /dev/null @@ -1,110 +0,0 @@ -package provision - -import ( - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/swarm" -) - -type FakeDetector struct { - Provisioner -} - -func (fd *FakeDetector) DetectProvisioner(d drivers.Driver) (Provisioner, error) { - return fd.Provisioner, nil -} - -type FakeProvisioner struct{} - -func NewFakeProvisioner(d drivers.Driver) Provisioner { - return &FakeProvisioner{} -} - -func (fp *FakeProvisioner) SSHCommand(args string) (string, error) { - return "", nil -} - -func (fp *FakeProvisioner) String() string { - return "fakeprovisioner" -} - -func (fp *FakeProvisioner) GenerateDockerOptions(dockerPort int) (*DockerOptions, error) { - return nil, nil -} - -func (fp *FakeProvisioner) GetDockerOptionsDir() string { - return "" -} - -func (fp *FakeProvisioner) GetAuthOptions() auth.Options { - return auth.Options{} -} - -func (fp *FakeProvisioner) GetSwarmOptions() swarm.Options { - return swarm.Options{} -} - -func (fp *FakeProvisioner) Package(name string, action pkgaction.PackageAction) error { - return nil -} - -func (fp *FakeProvisioner) Hostname() (string, error) { - return "", nil -} - -func (fp *FakeProvisioner) SetHostname(hostname string) error { - return nil -} - -func (fp *FakeProvisioner) CompatibleWithHost() bool { - return true -} - -func (fp *FakeProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - return nil -} - -func (fp *FakeProvisioner) Service(name string, action serviceaction.ServiceAction) error { - return nil -} - -func (fp *FakeProvisioner) GetDriver() drivers.Driver { - return nil -} - -func (fp *FakeProvisioner) SetOsReleaseInfo(info *OsRelease) {} - -func (fp *FakeProvisioner) GetOsReleaseInfo() (*OsRelease, error) { - return nil, nil -} - -type NetstatProvisioner struct { - *FakeProvisioner -} - -func (p *NetstatProvisioner) SSHCommand(args string) (string, error) { - return `Active Internet connections (servers and established) -Proto Recv-Q Send-Q Local Address Foreign Address State -tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN -tcp 0 72 192.168.25.141:ssh 192.168.25.1:63235 ESTABLISHED -tcp 0 0 :::2376 :::* LISTEN -tcp 0 0 :::ssh :::* LISTEN -Active UNIX domain sockets (servers and established) -Proto RefCnt Flags Type State I-Node Path -unix 2 [ ACC ] STREAM LISTENING 17990 /var/run/acpid.socket -unix 2 [ ACC ] SEQPACKET LISTENING 14233 /run/udev/control -unix 2 [ ACC ] STREAM LISTENING 19365 /var/run/docker.sock -unix 3 [ ] STREAM CONNECTED 19774 -unix 3 [ ] STREAM CONNECTED 19775 -unix 3 [ ] DGRAM 14243 -unix 3 [ ] DGRAM 14242`, nil -} - -func NewNetstatProvisioner() Provisioner { - return &NetstatProvisioner{ - &FakeProvisioner{}, - } -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/fedora.go b/vendor/github.com/docker/machine/libmachine/provision/fedora.go deleted file mode 100644 index 71989c0..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/fedora.go +++ /dev/null @@ -1,25 +0,0 @@ -package provision - -import ( - "github.com/docker/machine/libmachine/drivers" -) - -func init() { - Register("Fedora", &RegisteredProvisioner{ - New: NewFedoraProvisioner, - }) -} - -func NewFedoraProvisioner(d drivers.Driver) Provisioner { - return &FedoraProvisioner{ - NewRedHatProvisioner("fedora", d), - } -} - -type FedoraProvisioner struct { - *RedHatProvisioner -} - -func (provisioner *FedoraProvisioner) String() string { - return "fedora" -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/generic.go b/vendor/github.com/docker/machine/libmachine/provision/generic.go deleted file mode 100644 index 24ad1b5..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/generic.go +++ /dev/null @@ -1,138 +0,0 @@ -package provision - -import ( - "bytes" - "fmt" - "text/template" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/swarm" -) - -type GenericProvisioner struct { - SSHCommander - OsReleaseID string - DockerOptionsDir string - DaemonOptionsFile string - Packages []string - OsReleaseInfo *OsRelease - Driver drivers.Driver - AuthOptions auth.Options - EngineOptions engine.Options - SwarmOptions swarm.Options -} - -type GenericSSHCommander struct { - Driver drivers.Driver -} - -func (sshCmder GenericSSHCommander) SSHCommand(args string) (string, error) { - return drivers.RunSSHCommandFromDriver(sshCmder.Driver, args) -} - -func (provisioner *GenericProvisioner) Hostname() (string, error) { - return provisioner.SSHCommand("hostname") -} - -func (provisioner *GenericProvisioner) SetHostname(hostname string) error { - if _, err := provisioner.SSHCommand(fmt.Sprintf( - "sudo hostname %s && echo %q | sudo tee /etc/hostname", - hostname, - hostname, - )); err != nil { - return err - } - - // ubuntu/debian use 127.0.1.1 for non "localhost" loopback hostnames: https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_hostname_resolution - if _, err := provisioner.SSHCommand(fmt.Sprintf(` - if ! grep -xq '.*\s%s' /etc/hosts; then - if grep -xq '127.0.1.1\s.*' /etc/hosts; then - sudo sed -i 's/^127.0.1.1\s.*/127.0.1.1 %s/g' /etc/hosts; - else - echo '127.0.1.1 %s' | sudo tee -a /etc/hosts; - fi - fi`, - hostname, - hostname, - hostname, - )); err != nil { - return err - } - - return nil -} - -func (provisioner *GenericProvisioner) GetDockerOptionsDir() string { - return provisioner.DockerOptionsDir -} - -func (provisioner *GenericProvisioner) CompatibleWithHost() bool { - return provisioner.OsReleaseInfo.ID == provisioner.OsReleaseID -} - -func (provisioner *GenericProvisioner) GetAuthOptions() auth.Options { - return provisioner.AuthOptions -} - -func (provisioner *GenericProvisioner) GetSwarmOptions() swarm.Options { - return provisioner.SwarmOptions -} - -func (provisioner *GenericProvisioner) SetOsReleaseInfo(info *OsRelease) { - provisioner.OsReleaseInfo = info -} - -func (provisioner *GenericProvisioner) GetOsReleaseInfo() (*OsRelease, error) { - return provisioner.OsReleaseInfo, nil -} - -func (provisioner *GenericProvisioner) GenerateDockerOptions(dockerPort int) (*DockerOptions, error) { - var ( - engineCfg bytes.Buffer - ) - - driverNameLabel := fmt.Sprintf("provider=%s", provisioner.Driver.DriverName()) - provisioner.EngineOptions.Labels = append(provisioner.EngineOptions.Labels, driverNameLabel) - - engineConfigTmpl := ` -DOCKER_OPTS=' --H tcp://0.0.0.0:{{.DockerPort}} --H unix:///var/run/docker.sock ---storage-driver {{.EngineOptions.StorageDriver}} ---tlsverify ---tlscacert {{.AuthOptions.CaCertRemotePath}} ---tlscert {{.AuthOptions.ServerCertRemotePath}} ---tlskey {{.AuthOptions.ServerKeyRemotePath}} -{{ range .EngineOptions.Labels }}--label {{.}} -{{ end }}{{ range .EngineOptions.InsecureRegistry }}--insecure-registry {{.}} -{{ end }}{{ range .EngineOptions.RegistryMirror }}--registry-mirror {{.}} -{{ end }}{{ range .EngineOptions.ArbitraryFlags }}--{{.}} -{{ end }} -' -{{range .EngineOptions.Env}}export \"{{ printf "%q" . }}\" -{{end}} -` - t, err := template.New("engineConfig").Parse(engineConfigTmpl) - if err != nil { - return nil, err - } - - engineConfigContext := EngineConfigContext{ - DockerPort: dockerPort, - AuthOptions: provisioner.AuthOptions, - EngineOptions: provisioner.EngineOptions, - } - - t.Execute(&engineCfg, engineConfigContext) - - return &DockerOptions{ - EngineOptions: engineCfg.String(), - EngineOptionsPath: provisioner.DaemonOptionsFile, - }, nil -} - -func (provisioner *GenericProvisioner) GetDriver() drivers.Driver { - return provisioner.Driver -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/oraclelinux.go b/vendor/github.com/docker/machine/libmachine/provision/oraclelinux.go deleted file mode 100644 index 56d2637..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/oraclelinux.go +++ /dev/null @@ -1,25 +0,0 @@ -package provision - -import ( - "github.com/docker/machine/libmachine/drivers" -) - -func init() { - Register("OracleLinux", &RegisteredProvisioner{ - New: NewOracleLinuxProvisioner, - }) -} - -func NewOracleLinuxProvisioner(d drivers.Driver) Provisioner { - return &OracleLinuxProvisioner{ - NewRedHatProvisioner("ol", d), - } -} - -type OracleLinuxProvisioner struct { - *RedHatProvisioner -} - -func (provisioner *OracleLinuxProvisioner) String() string { - return "ol" -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/os_release.go b/vendor/github.com/docker/machine/libmachine/provision/os_release.go deleted file mode 100644 index 4c3bdf2..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/os_release.go +++ /dev/null @@ -1,91 +0,0 @@ -package provision - -import ( - "bufio" - "bytes" - "fmt" - "reflect" - "strings" - - "github.com/docker/machine/libmachine/log" -) - -// The /etc/os-release file contains operating system identification data -// See http://www.freedesktop.org/software/systemd/man/os-release.html for more details - -// OsRelease reflects values in /etc/os-release -// Values in this struct must always be string -// or the reflection will not work properly. -type OsRelease struct { - AnsiColor string `osr:"ANSI_COLOR"` - Name string `osr:"NAME"` - Version string `osr:"VERSION"` - Variant string `osr:"VARIANT"` - VariantID string `osr:"VARIANT_ID"` - ID string `osr:"ID"` - IDLike string `osr:"ID_LIKE"` - PrettyName string `osr:"PRETTY_NAME"` - VersionID string `osr:"VERSION_ID"` - HomeURL string `osr:"HOME_URL"` - SupportURL string `osr:"SUPPORT_URL"` - BugReportURL string `osr:"BUG_REPORT_URL"` -} - -func stripQuotes(val string) string { - if len(val) > 0 && val[0] == '"' { - return val[1 : len(val)-1] - } - return val -} - -func (osr *OsRelease) setIfPossible(key, val string) error { - v := reflect.ValueOf(osr).Elem() - for i := 0; i < v.NumField(); i++ { - fieldValue := v.Field(i) - fieldType := v.Type().Field(i) - originalName := fieldType.Tag.Get("osr") - if key == originalName && fieldValue.Kind() == reflect.String { - fieldValue.SetString(val) - return nil - } - } - return fmt.Errorf("Couldn't set key %s, no corresponding struct field found", key) -} - -func parseLine(osrLine string) (string, string, error) { - if osrLine == "" { - return "", "", nil - } - - vals := strings.Split(osrLine, "=") - if len(vals) != 2 { - return "", "", fmt.Errorf("Expected %s to split by '=' char into two strings, instead got %d strings", osrLine, len(vals)) - } - key := vals[0] - val := stripQuotes(vals[1]) - return key, val, nil -} - -func (osr *OsRelease) ParseOsRelease(osReleaseContents []byte) error { - r := bytes.NewReader(osReleaseContents) - scanner := bufio.NewScanner(r) - for scanner.Scan() { - key, val, err := parseLine(scanner.Text()) - if err != nil { - log.Warnf("Warning: got an invalid line error parsing /etc/os-release: %s", err) - continue - } - if err := osr.setIfPossible(key, val); err != nil { - log.Debug(err) - } - } - return nil -} - -func NewOsRelease(contents []byte) (*OsRelease, error) { - osr := &OsRelease{} - if err := osr.ParseOsRelease(contents); err != nil { - return nil, err - } - return osr, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/os_release_test.go b/vendor/github.com/docker/machine/libmachine/provision/os_release_test.go deleted file mode 100644 index 87ffefd..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/os_release_test.go +++ /dev/null @@ -1,211 +0,0 @@ -package provision - -import ( - "reflect" - "testing" -) - -func TestParseOsRelease(t *testing.T) { - // These example osr files stolen shamelessly from - // https://github.com/docker/docker/blob/master/pkg/parsers/operatingsystem/operatingsystem_test.go - // cheers @tiborvass - var ( - ubuntuTrusty = []byte(`NAME="Ubuntu" -VERSION="14.04, Trusty Tahr" -ID=ubuntu -ID_LIKE=debian -PRETTY_NAME="Ubuntu 14.04 LTS" -VERSION_ID="14.04" -HOME_URL="http://www.ubuntu.com/" -SUPPORT_URL="http://help.ubuntu.com/" -BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" -`) - gentoo = []byte(`NAME=Gentoo -ID=gentoo -PRETTY_NAME="Gentoo/Linux" -ANSI_COLOR="1;32" -HOME_URL="http://www.gentoo.org/" -SUPPORT_URL="http://www.gentoo.org/main/en/support.xml" -BUG_REPORT_URL="https://bugs.gentoo.org/" -`) - noPrettyName = []byte(`NAME="Ubuntu" -VERSION="14.04, Trusty Tahr" -ID=ubuntu -ID_LIKE=debian -VERSION_ID="14.04" -HOME_URL="http://www.ubuntu.com/" -SUPPORT_URL="http://help.ubuntu.com/" -BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" -`) - centos = []byte(`NAME="CentOS Linux" -VERSION="7 (Core)" -ID="centos" -ID_LIKE="rhel fedora" -VERSION_ID="7" -PRETTY_NAME="CentOS Linux 7 (Core)" -ANSI_COLOR="0;31" -HOME_URL="https://www.centos.org/" -BUG_REPORT_URL="https://bugs.centos.org/" -`) - fedora = []byte(`NAME=Fedora -VERSION="23 (Twenty Three)" -ID=fedora -VERSION_ID=23 -VARIANT="Server Edition" -VARIANT_ID=server -PRETTY_NAME="Fedora 23 (Twenty Three)" -ANSI_COLOR="0;34" -HOME_URL="https://fedoraproject.org/" -BUG_REPORT_URL="https://bugzilla.redhat.com/" -`) - ) - - osr, err := NewOsRelease(ubuntuTrusty) - if err != nil { - t.Fatalf("Unexpected error parsing os release: %s", err) - } - - expectedOsr := OsRelease{ - AnsiColor: "", - Name: "Ubuntu", - Version: "14.04, Trusty Tahr", - ID: "ubuntu", - IDLike: "debian", - PrettyName: "Ubuntu 14.04 LTS", - VersionID: "14.04", - HomeURL: "http://www.ubuntu.com/", - SupportURL: "http://help.ubuntu.com/", - BugReportURL: "http://bugs.launchpad.net/ubuntu/", - } - - if !reflect.DeepEqual(*osr, expectedOsr) { - t.Fatal("Error with ubuntu osr parsing: structs do not match") - } - - osr, err = NewOsRelease(gentoo) - if err != nil { - t.Fatalf("Unexpected error parsing os release: %s", err) - } - - expectedOsr = OsRelease{ - AnsiColor: "1;32", - Name: "Gentoo", - Version: "", - ID: "gentoo", - IDLike: "", - PrettyName: "Gentoo/Linux", - VersionID: "", - HomeURL: "http://www.gentoo.org/", - SupportURL: "http://www.gentoo.org/main/en/support.xml", - BugReportURL: "https://bugs.gentoo.org/", - } - - if !reflect.DeepEqual(*osr, expectedOsr) { - t.Fatal("Error with gentoo osr parsing: structs do not match") - } - - osr, err = NewOsRelease(noPrettyName) - if err != nil { - t.Fatalf("Unexpected error parsing os release: %s", err) - } - - expectedOsr = OsRelease{ - AnsiColor: "", - Name: "Ubuntu", - Version: "14.04, Trusty Tahr", - ID: "ubuntu", - IDLike: "debian", - PrettyName: "", - VersionID: "14.04", - HomeURL: "http://www.ubuntu.com/", - SupportURL: "http://help.ubuntu.com/", - BugReportURL: "http://bugs.launchpad.net/ubuntu/", - } - - if !reflect.DeepEqual(*osr, expectedOsr) { - t.Fatal("Error with noPrettyName osr parsing: structs do not match") - } - - osr, err = NewOsRelease(centos) - if err != nil { - t.Fatalf("Unexpected error parsing os release: %s", err) - } - - expectedOsr = OsRelease{ - Name: "CentOS Linux", - Version: "7 (Core)", - ID: "centos", - IDLike: "rhel fedora", - PrettyName: "CentOS Linux 7 (Core)", - AnsiColor: "0;31", - VersionID: "7", - HomeURL: "https://www.centos.org/", - BugReportURL: "https://bugs.centos.org/", - } - - if !reflect.DeepEqual(*osr, expectedOsr) { - t.Fatal("Error with centos osr parsing: structs do not match") - } - - osr, err = NewOsRelease(fedora) - if err != nil { - t.Fatalf("Unexpected error parsing os release: %s", err) - } - - expectedOsr = OsRelease{ - Name: "Fedora", - Version: "23 (Twenty Three)", - ID: "fedora", - PrettyName: "Fedora 23 (Twenty Three)", - Variant: "Server Edition", - VariantID: "server", - AnsiColor: "0;34", - VersionID: "23", - HomeURL: "https://fedoraproject.org/", - BugReportURL: "https://bugzilla.redhat.com/", - } - - if !reflect.DeepEqual(*osr, expectedOsr) { - t.Fatal("Error with fedora osr parsing: structs do not match") - } -} - -func TestParseLine(t *testing.T) { - var ( - withQuotes = "ID=\"ubuntu\"" - withoutQuotes = "ID=gentoo" - wtf = "LOTS=OF=EQUALS" - blank = "" - ) - - key, val, err := parseLine(withQuotes) - if key != "ID" { - t.Fatalf("Expected ID, got %s", key) - } - if val != "ubuntu" { - t.Fatalf("Expected ubuntu, got %s", val) - } - if err != nil { - t.Fatalf("Got error on parseLine with quotes: %s", err) - } - key, val, err = parseLine(withoutQuotes) - if key != "ID" { - t.Fatalf("Expected ID, got %s", key) - } - if val != "gentoo" { - t.Fatalf("Expected gentoo, got %s", val) - } - if err != nil { - t.Fatalf("Got error on parseLine without quotes: %s", err) - } - key, val, err = parseLine(wtf) - if err == nil { - t.Fatal("Expected to get an error on parseLine, got nil") - } - key, val, err = parseLine(blank) - if key != "" || val != "" { - t.Fatalf("Expected empty response on parseLine, got key: %s val: %s", key, val) - } else if err != nil { - t.Fatalf("Expected nil err response on parseLine, got %s", err) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/pkgaction/pkg_action.go b/vendor/github.com/docker/machine/libmachine/provision/pkgaction/pkg_action.go deleted file mode 100644 index b7cf7e3..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/pkgaction/pkg_action.go +++ /dev/null @@ -1,25 +0,0 @@ -package pkgaction - -type PackageAction int - -const ( - Install PackageAction = iota - Remove - Upgrade - Purge -) - -var packageActions = []string{ - "install", - "remove", - "upgrade", - "purge", -} - -func (s PackageAction) String() string { - if int(s) >= 0 && int(s) < len(packageActions) { - return packageActions[s] - } - - return "" -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/pkgaction/pkg_action_test.go b/vendor/github.com/docker/machine/libmachine/provision/pkgaction/pkg_action_test.go deleted file mode 100644 index 3ca8f28..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/pkgaction/pkg_action_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package pkgaction - -import "testing" - -func TestActionValue(t *testing.T) { - if Install.String() != "install" { - t.Fatalf("Expected %q but got %q", "install", Install.String()) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/provisioner.go b/vendor/github.com/docker/machine/libmachine/provision/provisioner.go deleted file mode 100644 index 81fc1eb..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/provisioner.go +++ /dev/null @@ -1,132 +0,0 @@ -package provision - -import ( - "fmt" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/swarm" -) - -var ( - provisioners = make(map[string]*RegisteredProvisioner) - detector Detector = &StandardDetector{} -) - -const ( - LastReleaseBeforeCEVersioning = "1.13.1" -) - -type SSHCommander interface { - // Short-hand for accessing an SSH command from the driver. - SSHCommand(args string) (string, error) -} - -type Detector interface { - DetectProvisioner(d drivers.Driver) (Provisioner, error) -} - -type StandardDetector struct{} - -func SetDetector(newDetector Detector) { - detector = newDetector -} - -// Provisioner defines distribution specific actions -type Provisioner interface { - fmt.Stringer - SSHCommander - - // Create the files for the daemon to consume configuration settings (return struct of content and path) - GenerateDockerOptions(dockerPort int) (*DockerOptions, error) - - // Get the directory where the settings files for docker are to be found - GetDockerOptionsDir() string - - // Return the auth options used to configure remote connection for the daemon. - GetAuthOptions() auth.Options - - // Get the swarm options associated with this host. - GetSwarmOptions() swarm.Options - - // Run a package action e.g. install - Package(name string, action pkgaction.PackageAction) error - - // Get Hostname - Hostname() (string, error) - - // Set hostname - SetHostname(hostname string) error - - // Figure out if this is the right provisioner to use based on /etc/os-release info - CompatibleWithHost() bool - - // Do the actual provisioning piece: - // 1. Set the hostname on the instance. - // 2. Install Docker if it is not present. - // 3. Configure the daemon to accept connections over TLS. - // 4. Copy the needed certificates to the server and local config dir. - // 5. Configure / activate swarm if applicable. - Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error - - // Perform action on a named service e.g. stop - Service(name string, action serviceaction.ServiceAction) error - - // Get the driver which is contained in the provisioner. - GetDriver() drivers.Driver - - // Set the OS Release info depending on how it's represented - // internally - SetOsReleaseInfo(info *OsRelease) - - // Get the OS Release info for the current provisioner - GetOsReleaseInfo() (*OsRelease, error) -} - -// RegisteredProvisioner creates a new provisioner -type RegisteredProvisioner struct { - New func(d drivers.Driver) Provisioner -} - -func Register(name string, p *RegisteredProvisioner) { - provisioners[name] = p -} - -func DetectProvisioner(d drivers.Driver) (Provisioner, error) { - return detector.DetectProvisioner(d) -} - -func (detector StandardDetector) DetectProvisioner(d drivers.Driver) (Provisioner, error) { - log.Info("Waiting for SSH to be available...") - if err := drivers.WaitForSSH(d); err != nil { - return nil, err - } - - log.Info("Detecting the provisioner...") - - osReleaseOut, err := drivers.RunSSHCommandFromDriver(d, "cat /etc/os-release") - if err != nil { - return nil, fmt.Errorf("Error getting SSH command: %s", err) - } - - osReleaseInfo, err := NewOsRelease([]byte(osReleaseOut)) - if err != nil { - return nil, fmt.Errorf("Error parsing /etc/os-release file: %s", err) - } - - for _, p := range provisioners { - provisioner := p.New(d) - provisioner.SetOsReleaseInfo(osReleaseInfo) - - if provisioner.CompatibleWithHost() { - log.Debugf("found compatible host: %s", osReleaseInfo.ID) - return provisioner, nil - } - } - - return nil, ErrDetectionFailed -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/provisiontest/sshcommander.go b/vendor/github.com/docker/machine/libmachine/provision/provisiontest/sshcommander.go deleted file mode 100644 index 3f9f8b7..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/provisiontest/sshcommander.go +++ /dev/null @@ -1,39 +0,0 @@ -//Package provisiontest provides utilities for testing provisioners -package provisiontest - -import "errors" - -//FakeSSHCommanderOptions is intended to create a FakeSSHCommander without actually knowing the underlying sshcommands by passing it to NewSSHCommander -type FakeSSHCommanderOptions struct { - //Result of the ssh command to look up the FilesystemType - FilesystemType string -} - -//FakeSSHCommander is an implementation of provision.SSHCommander to provide predictable responses set by testing code -//Extend it when needed -type FakeSSHCommander struct { - Responses map[string]string -} - -//NewFakeSSHCommander creates a FakeSSHCommander without actually knowing the underlying sshcommands -func NewFakeSSHCommander(options FakeSSHCommanderOptions) *FakeSSHCommander { - if options.FilesystemType == "" { - options.FilesystemType = "ext4" - } - sshCmder := &FakeSSHCommander{ - Responses: map[string]string{ - "stat -f -c %T /var/lib": options.FilesystemType + "\n", - }, - } - - return sshCmder -} - -//SSHCommand is an implementation of provision.SSHCommander.SSHCommand to provide predictable responses set by testing code -func (sshCmder *FakeSSHCommander) SSHCommand(args string) (string, error) { - response, commandRegistered := sshCmder.Responses[args] - if !commandRegistered { - return "", errors.New("Command not registered in FakeSSHCommander") - } - return response, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/provisiontest/sshcommander_test.go b/vendor/github.com/docker/machine/libmachine/provision/provisiontest/sshcommander_test.go deleted file mode 100644 index 037a454..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/provisiontest/sshcommander_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package provisiontest - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestCreateFakeSSHCommander(t *testing.T) { - sshCmder := NewFakeSSHCommander(FakeSSHCommanderOptions{FilesystemType: "btrfs"}) - output, err := sshCmder.SSHCommand("stat -f -c %T /var/lib") - if err != nil || output != "btrfs\n" { - t.Fatal("FakeSSHCommander should have returned btrfs and no error but returned '", output, "' and error", err) - } -} - -func TestStatSSHCommand(t *testing.T) { - sshCmder := FakeSSHCommander{ - Responses: map[string]string{"sshcommand": "sshcommandresponse"}, - } - - output, err := sshCmder.SSHCommand("sshcommand") - assert.NoError(t, err) - assert.Equal(t, "sshcommandresponse", output) - - output, err = sshCmder.SSHCommand("errorcommand") - assert.Error(t, err) -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/rancheros.go b/vendor/github.com/docker/machine/libmachine/provision/rancheros.go deleted file mode 100644 index a980b2b..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/rancheros.go +++ /dev/null @@ -1,250 +0,0 @@ -package provision - -import ( - "bufio" - "fmt" - "net/http" - "strings" - - "github.com/docker/machine/commands/mcndirs" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/state" - "github.com/docker/machine/libmachine/swarm" -) - -const ( - versionsURL = "http://releases.rancher.com/os/versions.yml" - isoURL = "https://github.com/rancherio/os/releases/download/%s/machine-rancheros.iso" - hostnameTmpl = `sudo mkdir -p /var/lib/rancher/conf/cloud-config.d/ -sudo tee /var/lib/rancher/conf/cloud-config.d/machine-hostname.yml << EOF -#cloud-config - -hostname: %s -EOF -` -) - -func init() { - Register("RancherOS", &RegisteredProvisioner{ - New: NewRancherProvisioner, - }) -} - -func NewRancherProvisioner(d drivers.Driver) Provisioner { - return &RancherProvisioner{ - GenericProvisioner{ - SSHCommander: GenericSSHCommander{Driver: d}, - DockerOptionsDir: "/var/lib/rancher/conf", - DaemonOptionsFile: "/var/lib/rancher/conf/docker", - OsReleaseID: "rancheros", - Driver: d, - }, - } -} - -type RancherProvisioner struct { - GenericProvisioner -} - -func (provisioner *RancherProvisioner) String() string { - return "rancheros" -} - -func (provisioner *RancherProvisioner) Service(name string, action serviceaction.ServiceAction) error { - command := fmt.Sprintf("sudo system-docker %s %s", action.String(), name) - - if _, err := provisioner.SSHCommand(command); err != nil { - return err - } - - return nil -} - -func (provisioner *RancherProvisioner) Package(name string, action pkgaction.PackageAction) error { - var packageAction string - - if name == "docker" && action == pkgaction.Upgrade { - return provisioner.upgrade() - } - - switch action { - case pkgaction.Install: - packageAction = "enabled" - case pkgaction.Remove: - packageAction = "disable" - case pkgaction.Upgrade: - // TODO: support upgrade - packageAction = "upgrade" - } - - command := fmt.Sprintf("sudo rancherctl service %s %s", packageAction, name) - - if _, err := provisioner.SSHCommand(command); err != nil { - return err - } - - return nil -} - -func (provisioner *RancherProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - log.Debugf("Running RancherOS provisioner on %s", provisioner.Driver.GetMachineName()) - - provisioner.SwarmOptions = swarmOptions - provisioner.AuthOptions = authOptions - provisioner.EngineOptions = engineOptions - swarmOptions.Env = engineOptions.Env - - if provisioner.EngineOptions.StorageDriver == "" { - provisioner.EngineOptions.StorageDriver = "overlay" - } else if provisioner.EngineOptions.StorageDriver != "overlay" { - return fmt.Errorf("Unsupported storage driver: %s", provisioner.EngineOptions.StorageDriver) - } - - log.Debugf("Setting hostname %s", provisioner.Driver.GetMachineName()) - if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { - return err - } - - for _, pkg := range provisioner.Packages { - log.Debugf("Installing package %s", pkg) - if err := provisioner.Package(pkg, pkgaction.Install); err != nil { - return err - } - } - - if engineOptions.InstallURL == drivers.DefaultEngineInstallURL { - log.Debugf("Skipping docker engine default: %s", engineOptions.InstallURL) - } else { - log.Debugf("Selecting docker engine: %s", engineOptions.InstallURL) - if err := selectDocker(provisioner, engineOptions.InstallURL); err != nil { - return err - } - } - - log.Debugf("Preparing certificates") - provisioner.AuthOptions = setRemoteAuthOptions(provisioner) - - log.Debugf("Setting up certificates") - if err := ConfigureAuth(provisioner); err != nil { - return err - } - - log.Debugf("Configuring swarm") - err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions) - return err -} - -func (provisioner *RancherProvisioner) SetHostname(hostname string) error { - // /etc/hosts is bind mounted from Docker, this is hack to that the generic provisioner doesn't try to mv /etc/hosts - if _, err := provisioner.SSHCommand("sed /127.0.1.1/d /etc/hosts > /tmp/hosts && cat /tmp/hosts | sudo tee /etc/hosts"); err != nil { - return err - } - - if err := provisioner.GenericProvisioner.SetHostname(hostname); err != nil { - return err - } - - if _, err := provisioner.SSHCommand(fmt.Sprintf(hostnameTmpl, hostname)); err != nil { - return err - } - - return nil -} - -func (provisioner *RancherProvisioner) upgrade() error { - switch provisioner.Driver.DriverName() { - case "virtualbox": - return provisioner.upgradeIso() - default: - log.Infof("Running upgrade") - if _, err := provisioner.SSHCommand("sudo rancherctl os upgrade -f --no-reboot"); err != nil { - return err - } - - log.Infof("Upgrade succeeded, rebooting") - // ignore errors here because the SSH connection will close - provisioner.SSHCommand("sudo reboot") - - return nil - } -} - -func (provisioner *RancherProvisioner) upgradeIso() error { - // Largely copied from Boot2Docker provisioner, we should find a way to share this code - log.Info("Stopping machine to do the upgrade...") - - if err := provisioner.Driver.Stop(); err != nil { - return err - } - - if err := mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil { - return err - } - - machineName := provisioner.GetDriver().GetMachineName() - - log.Infof("Upgrading machine %s...", machineName) - - // TODO: Ideally, we should not read from mcndirs directory at all. - // The driver should be able to communicate how and where to place the - // relevant files. - b2dutils := mcnutils.NewB2dUtils(mcndirs.GetBaseDir()) - - url, err := provisioner.getLatestISOURL() - if err != nil { - return err - } - - if err := b2dutils.DownloadISOFromURL(url); err != nil { - return err - } - - // Copy the latest version of boot2docker ISO to the machine's directory - if err := b2dutils.CopyIsoToMachineDir("", machineName); err != nil { - return err - } - - log.Infof("Starting machine back up...") - - if err := provisioner.Driver.Start(); err != nil { - return err - } - - return mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running)) -} - -func (provisioner *RancherProvisioner) getLatestISOURL() (string, error) { - log.Debugf("Reading %s", versionsURL) - resp, err := http.Get(versionsURL) - if err != nil { - return "", err - } - defer resp.Body.Close() - - // Don't want to pull in yaml parser, we'll do this manually - scanner := bufio.NewScanner(resp.Body) - for scanner.Scan() { - line := scanner.Text() - if strings.HasPrefix(line, "current: ") { - log.Debugf("Found %s", line) - return fmt.Sprintf(isoURL, strings.Split(line, ":")[2]), err - } - } - - return "", fmt.Errorf("Failed to find current version") -} - -func selectDocker(p Provisioner, baseURL string) error { - // TODO: detect if its a cloud-init, or a ros setting - and use that.. - if output, err := p.SSHCommand(fmt.Sprintf("wget -O- %s | sh -", baseURL)); err != nil { - return fmt.Errorf("error selecting docker: (%s) %s", err, output) - } - - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/redhat.go b/vendor/github.com/docker/machine/libmachine/provision/redhat.go deleted file mode 100644 index 3df0acd..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/redhat.go +++ /dev/null @@ -1,212 +0,0 @@ -package provision - -import ( - "bytes" - "errors" - "fmt" - "regexp" - "text/template" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/swarm" -) - -var ( - ErrUnknownYumOsRelease = errors.New("unknown OS for Yum repository") - engineConfigTemplate = `[Service] -ExecStart= -ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:{{.DockerPort}} -H unix:///var/run/docker.sock --storage-driver {{.EngineOptions.StorageDriver}} --tlsverify --tlscacert {{.AuthOptions.CaCertRemotePath}} --tlscert {{.AuthOptions.ServerCertRemotePath}} --tlskey {{.AuthOptions.ServerKeyRemotePath}} {{ range .EngineOptions.Labels }}--label {{.}} {{ end }}{{ range .EngineOptions.InsecureRegistry }}--insecure-registry {{.}} {{ end }}{{ range .EngineOptions.RegistryMirror }}--registry-mirror {{.}} {{ end }}{{ range .EngineOptions.ArbitraryFlags }}--{{.}} {{ end }} -Environment={{range .EngineOptions.Env}}{{ printf "%q" . }} {{end}} -` - majorVersionRE = regexp.MustCompile(`^(\d+)(\..*)?`) -) - -type PackageListInfo struct { - OsRelease string - OsReleaseVersion string -} - -func init() { - Register("RedHat", &RegisteredProvisioner{ - New: func(d drivers.Driver) Provisioner { - return NewRedHatProvisioner("rhel", d) - }, - }) -} - -func NewRedHatProvisioner(osReleaseID string, d drivers.Driver) *RedHatProvisioner { - systemdProvisioner := NewSystemdProvisioner(osReleaseID, d) - systemdProvisioner.SSHCommander = RedHatSSHCommander{Driver: d} - return &RedHatProvisioner{ - systemdProvisioner, - } -} - -type RedHatProvisioner struct { - SystemdProvisioner -} - -func (provisioner *RedHatProvisioner) String() string { - return "redhat" -} - -func (provisioner *RedHatProvisioner) SetHostname(hostname string) error { - // we have to have SetHostname here as well to use the RedHat provisioner - // SSHCommand to add the tty allocation - if _, err := provisioner.SSHCommand(fmt.Sprintf( - "sudo hostname %s && echo %q | sudo tee /etc/hostname", - hostname, - hostname, - )); err != nil { - return err - } - - if _, err := provisioner.SSHCommand(fmt.Sprintf( - "if grep -xq 127.0.1.1.* /etc/hosts; then sudo sed -i 's/^127.0.1.1.*/127.0.1.1 %s/g' /etc/hosts; else echo '127.0.1.1 %s' | sudo tee -a /etc/hosts; fi", - hostname, - hostname, - )); err != nil { - return err - } - - return nil -} - -func (provisioner *RedHatProvisioner) Package(name string, action pkgaction.PackageAction) error { - var packageAction string - - switch action { - case pkgaction.Install: - packageAction = "install" - case pkgaction.Remove: - packageAction = "remove" - case pkgaction.Purge: - packageAction = "remove" - case pkgaction.Upgrade: - packageAction = "upgrade" - } - - command := fmt.Sprintf("sudo -E yum %s -y %s", packageAction, name) - - if _, err := provisioner.SSHCommand(command); err != nil { - return err - } - - return nil -} - -func installDocker(provisioner *RedHatProvisioner) error { - if err := installDockerGeneric(provisioner, provisioner.EngineOptions.InstallURL); err != nil { - return err - } - - if err := provisioner.Service("docker", serviceaction.Restart); err != nil { - return err - } - - err := provisioner.Service("docker", serviceaction.Enable) - return err -} - -func (provisioner *RedHatProvisioner) dockerDaemonResponding() bool { - log.Debug("checking docker daemon") - - if out, err := provisioner.SSHCommand("sudo docker version"); err != nil { - log.Warnf("Error getting SSH command to check if the daemon is up: %s", err) - log.Debugf("'sudo docker version' output:\n%s", out) - return false - } - - // The daemon is up if the command worked. Carry on. - return true -} - -func (provisioner *RedHatProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - provisioner.SwarmOptions = swarmOptions - provisioner.AuthOptions = authOptions - provisioner.EngineOptions = engineOptions - swarmOptions.Env = engineOptions.Env - - // set default storage driver for redhat - storageDriver, err := decideStorageDriver(provisioner, "devicemapper", engineOptions.StorageDriver) - if err != nil { - return err - } - provisioner.EngineOptions.StorageDriver = storageDriver - - if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { - return err - } - - for _, pkg := range provisioner.Packages { - log.Debugf("installing base package: name=%s", pkg) - if err := provisioner.Package(pkg, pkgaction.Install); err != nil { - return err - } - } - - // update OS -- this is needed for libdevicemapper and the docker install - if _, err := provisioner.SSHCommand("sudo -E yum -y update -x docker-*"); err != nil { - return err - } - - // install docker - if err := installDocker(provisioner); err != nil { - return err - } - - if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil { - return err - } - - if err := makeDockerOptionsDir(provisioner); err != nil { - return err - } - - provisioner.AuthOptions = setRemoteAuthOptions(provisioner) - - if err := ConfigureAuth(provisioner); err != nil { - return err - } - - err = configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions) - return err -} - -func (provisioner *RedHatProvisioner) GenerateDockerOptions(dockerPort int) (*DockerOptions, error) { - var ( - engineCfg bytes.Buffer - configPath = provisioner.DaemonOptionsFile - ) - - driverNameLabel := fmt.Sprintf("provider=%s", provisioner.Driver.DriverName()) - provisioner.EngineOptions.Labels = append(provisioner.EngineOptions.Labels, driverNameLabel) - - // systemd / redhat will not load options if they are on newlines - // instead, it just continues with a different set of options; yeah... - t, err := template.New("engineConfig").Parse(engineConfigTemplate) - if err != nil { - return nil, err - } - - engineConfigContext := EngineConfigContext{ - DockerPort: dockerPort, - AuthOptions: provisioner.AuthOptions, - EngineOptions: provisioner.EngineOptions, - DockerOptionsDir: provisioner.DockerOptionsDir, - } - - t.Execute(&engineCfg, engineConfigContext) - - daemonOptsDir := configPath - return &DockerOptions{ - EngineOptions: engineCfg.String(), - EngineOptionsPath: daemonOptsDir, - }, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/redhat_ssh_commander.go b/vendor/github.com/docker/machine/libmachine/provision/redhat_ssh_commander.go deleted file mode 100644 index b94e27b..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/redhat_ssh_commander.go +++ /dev/null @@ -1,45 +0,0 @@ -package provision - -import ( - "fmt" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/ssh" -) - -type RedHatSSHCommander struct { - Driver drivers.Driver -} - -func (sshCmder RedHatSSHCommander) SSHCommand(args string) (string, error) { - client, err := drivers.GetSSHClientFromDriver(sshCmder.Driver) - if err != nil { - return "", err - } - - log.Debugf("About to run SSH command:\n%s", args) - - // redhat needs "-t" for tty allocation on ssh therefore we check for the - // external client and add as needed. - // Note: CentOS 7.0 needs multiple "-tt" to force tty allocation when ssh has - // no local tty. - var output string - switch c := client.(type) { - case *ssh.ExternalClient: - c.BaseArgs = append(c.BaseArgs, "-tt") - output, err = c.Output(args) - case *ssh.NativeClient: - output, err = c.OutputWithPty(args) - } - - log.Debugf("SSH cmd err, output: %v: %s", err, output) - if err != nil { - return "", fmt.Errorf(`something went wrong running an SSH command -command : %s -err : %v -output : %s`, args, err, output) - } - - return output, nil -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/redhat_test.go b/vendor/github.com/docker/machine/libmachine/provision/redhat_test.go deleted file mode 100644 index 2b35084..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/redhat_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package provision - -import ( - "testing" - - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/provision/provisiontest" - "github.com/docker/machine/libmachine/swarm" -) - -func TestRedHatDefaultStorageDriver(t *testing.T) { - p := NewRedHatProvisioner("", &fakedriver.Driver{}) - p.SSHCommander = provisiontest.NewFakeSSHCommander(provisiontest.FakeSSHCommanderOptions{}) - p.Provision(swarm.Options{}, auth.Options{}, engine.Options{}) - if p.EngineOptions.StorageDriver != "devicemapper" { - t.Fatal("Default storage driver should be devicemapper") - } -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/serviceaction/service_action.go b/vendor/github.com/docker/machine/libmachine/provision/serviceaction/service_action.go deleted file mode 100644 index b2e22e5..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/serviceaction/service_action.go +++ /dev/null @@ -1,29 +0,0 @@ -package serviceaction - -type ServiceAction int - -const ( - Restart ServiceAction = iota - Start - Stop - Enable - Disable - DaemonReload -) - -var serviceActions = []string{ - "restart", - "start", - "stop", - "enable", - "disable", - "daemon-reload", -} - -func (s ServiceAction) String() string { - if int(s) >= 0 && int(s) < len(serviceActions) { - return serviceActions[s] - } - - return "" -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/serviceaction/service_action_test.go b/vendor/github.com/docker/machine/libmachine/provision/serviceaction/service_action_test.go deleted file mode 100644 index b2072a5..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/serviceaction/service_action_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package serviceaction - -import "testing" - -func TestActionValue(t *testing.T) { - if Restart.String() != "restart" { - t.Fatalf("Expected %s but got %s", "install", Restart.String()) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/suse.go b/vendor/github.com/docker/machine/libmachine/provision/suse.go deleted file mode 100644 index b0ad944..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/suse.go +++ /dev/null @@ -1,207 +0,0 @@ -package provision - -import ( - "fmt" - "strings" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/swarm" -) - -func init() { - Register("openSUSE", &RegisteredProvisioner{ - New: NewOpenSUSEProvisioner, - }) - Register("SUSE Linux Enterprise Desktop", &RegisteredProvisioner{ - New: NewSLEDProvisioner, - }) - Register("SUSE Linux Enterprise Server", &RegisteredProvisioner{ - New: NewSLESProvisioner, - }) -} - -func NewSLEDProvisioner(d drivers.Driver) Provisioner { - return &SUSEProvisioner{ - NewSystemdProvisioner("sled", d), - } -} - -func NewSLESProvisioner(d drivers.Driver) Provisioner { - return &SUSEProvisioner{ - NewSystemdProvisioner("sles", d), - } -} - -func NewOpenSUSEProvisioner(d drivers.Driver) Provisioner { - return &SUSEProvisioner{ - NewSystemdProvisioner("openSUSE", d), - } -} - -type SUSEProvisioner struct { - SystemdProvisioner -} - -func (provisioner *SUSEProvisioner) CompatibleWithHost() bool { - return strings.ToLower(provisioner.OsReleaseInfo.ID) == strings.ToLower(provisioner.OsReleaseID) -} - -func (provisioner *SUSEProvisioner) String() string { - return "openSUSE" -} - -func (provisioner *SUSEProvisioner) Package(name string, action pkgaction.PackageAction) error { - var packageAction string - - switch action { - case pkgaction.Install: - packageAction = "in" - // This is an optimization that reduces the provisioning time of certain - // systems in a significant way. - // The invocation of "zypper in " causes the download of the metadata - // of all the repositories that have never been refreshed or that have - // automatic refresh toggled and have not been refreshed recently. - // Refreshing the repository metadata can take quite some time and can cause - // longer provisioning times for machines that have been pre-optimized for - // docker by including all the needed packages. - if _, err := provisioner.SSHCommand(fmt.Sprintf("rpm -q %s", name)); err == nil { - log.Debugf("%s is already installed, skipping operation", name) - return nil - } - case pkgaction.Remove: - packageAction = "rm" - case pkgaction.Upgrade: - packageAction = "up" - } - - command := fmt.Sprintf("sudo -E zypper -n %s %s", packageAction, name) - - log.Debugf("zypper: action=%s name=%s", action.String(), name) - - if _, err := provisioner.SSHCommand(command); err != nil { - return err - } - - return nil -} - -func (provisioner *SUSEProvisioner) dockerDaemonResponding() bool { - log.Debug("checking docker daemon") - - if out, err := provisioner.SSHCommand("sudo docker version"); err != nil { - log.Warnf("Error getting SSH command to check if the daemon is up: %s", err) - log.Debugf("'sudo docker version' output:\n%s", out) - return false - } - - // The daemon is up if the command worked. Carry on. - return true -} - -func (provisioner *SUSEProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - provisioner.SwarmOptions = swarmOptions - provisioner.AuthOptions = authOptions - provisioner.EngineOptions = engineOptions - swarmOptions.Env = engineOptions.Env - - // figure out the filesystem used by /var/lib/docker - fs, err := provisioner.SSHCommand("stat -f -c %T /var/lib/docker") - if err != nil { - // figure out the filesystem used by /var/lib - fs, err = provisioner.SSHCommand("stat -f -c %T /var/lib/") - if err != nil { - return err - } - } - graphDriver := "overlay" - if strings.Contains(fs, "btrfs") { - graphDriver = "btrfs" - } - - storageDriver, err := decideStorageDriver(provisioner, graphDriver, engineOptions.StorageDriver) - if err != nil { - return err - } - provisioner.EngineOptions.StorageDriver = storageDriver - - log.Debug("Setting hostname") - if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { - return err - } - - if strings.ToLower(provisioner.OsReleaseInfo.ID) != "opensuse" { - // This is a SLE machine, enable the containers module to have access - // to the docker packages - if _, err := provisioner.SSHCommand("sudo -E SUSEConnect -p sle-module-containers/12/$(uname -m) -r ''"); err != nil { - return fmt.Errorf( - "Error while adding the 'containers' module, make sure this machine is registered either against SUSE Customer Center (SCC) or to a local Subscription Management Tool (SMT): %v", - err) - } - } - - log.Debug("Installing base packages") - for _, pkg := range provisioner.Packages { - if err := provisioner.Package(pkg, pkgaction.Install); err != nil { - return err - } - } - - log.Debug("Installing docker") - if err := provisioner.Package("docker", pkgaction.Install); err != nil { - return err - } - - // create symlinks for containerd, containerd-shim and runc. - // We have to do that because machine overrides the openSUSE systemd - // unit of docker - if _, err := provisioner.SSHCommand("sudo -E ln -sf /usr/sbin/runc /usr/sbin/docker-runc"); err != nil { - return err - } - if _, err := provisioner.SSHCommand("sudo -E ln -sf /usr/sbin/containerd /usr/sbin/docker-containerd"); err != nil { - return err - } - if _, err := provisioner.SSHCommand("sudo -E ln -sf /usr/sbin/containerd-shim /usr/sbin/docker-containerd-shim"); err != nil { - return err - } - - // Is yast2 firewall installed? - if _, installed := provisioner.SSHCommand("rpm -q yast2-firewall"); installed == nil { - // Open the firewall port required by docker - if _, err := provisioner.SSHCommand("sudo -E /sbin/yast2 firewall services add ipprotocol=tcp tcpport=2376 zone=EXT"); err != nil { - return err - } - } - - log.Debug("Starting systemd docker service") - if err := provisioner.Service("docker", serviceaction.Start); err != nil { - return err - } - - log.Debug("Waiting for docker daemon") - if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil { - return err - } - - provisioner.AuthOptions = setRemoteAuthOptions(provisioner) - - log.Debug("Configuring auth") - if err := ConfigureAuth(provisioner); err != nil { - return err - } - - log.Debug("Configuring swarm") - if err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions); err != nil { - return err - } - - // enable in systemd - log.Debug("Enabling docker in systemd") - err = provisioner.Service("docker", serviceaction.Enable) - return err -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/systemd.go b/vendor/github.com/docker/machine/libmachine/provision/systemd.go deleted file mode 100644 index 90d0260..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/systemd.go +++ /dev/null @@ -1,101 +0,0 @@ -package provision - -import ( - "bytes" - "fmt" - "text/template" - - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/versioncmp" -) - -type SystemdProvisioner struct { - GenericProvisioner -} - -func (p *SystemdProvisioner) String() string { - return "redhat" -} - -func NewSystemdProvisioner(osReleaseID string, d drivers.Driver) SystemdProvisioner { - return SystemdProvisioner{ - GenericProvisioner{ - SSHCommander: GenericSSHCommander{Driver: d}, - DockerOptionsDir: "/etc/docker", - DaemonOptionsFile: "/etc/systemd/system/docker.service.d/10-machine.conf", - OsReleaseID: osReleaseID, - Packages: []string{ - "curl", - }, - Driver: d, - }, - } -} - -func (p *SystemdProvisioner) GenerateDockerOptions(dockerPort int) (*DockerOptions, error) { - var ( - engineCfg bytes.Buffer - ) - - driverNameLabel := fmt.Sprintf("provider=%s", p.Driver.DriverName()) - p.EngineOptions.Labels = append(p.EngineOptions.Labels, driverNameLabel) - - dockerVersion, err := DockerClientVersion(p) - if err != nil { - return nil, err - } - - arg := "dockerd" - if versioncmp.LessThan(dockerVersion, "1.12.0") { - arg = "docker daemon" - } - - engineConfigTmpl := `[Service] -ExecStart= -ExecStart=/usr/bin/` + arg + ` -H tcp://0.0.0.0:{{.DockerPort}} -H unix:///var/run/docker.sock --storage-driver {{.EngineOptions.StorageDriver}} --tlsverify --tlscacert {{.AuthOptions.CaCertRemotePath}} --tlscert {{.AuthOptions.ServerCertRemotePath}} --tlskey {{.AuthOptions.ServerKeyRemotePath}} {{ range .EngineOptions.Labels }}--label {{.}} {{ end }}{{ range .EngineOptions.InsecureRegistry }}--insecure-registry {{.}} {{ end }}{{ range .EngineOptions.RegistryMirror }}--registry-mirror {{.}} {{ end }}{{ range .EngineOptions.ArbitraryFlags }}--{{.}} {{ end }} -Environment={{range .EngineOptions.Env}}{{ printf "%q" . }} {{end}} -` - t, err := template.New("engineConfig").Parse(engineConfigTmpl) - if err != nil { - return nil, err - } - - engineConfigContext := EngineConfigContext{ - DockerPort: dockerPort, - AuthOptions: p.AuthOptions, - EngineOptions: p.EngineOptions, - } - - t.Execute(&engineCfg, engineConfigContext) - - return &DockerOptions{ - EngineOptions: engineCfg.String(), - EngineOptionsPath: p.DaemonOptionsFile, - }, nil -} - -func (p *SystemdProvisioner) Service(name string, action serviceaction.ServiceAction) error { - reloadDaemon := false - switch action { - case serviceaction.Start, serviceaction.Restart: - reloadDaemon = true - } - - // systemd needs reloaded when config changes on disk; we cannot - // be sure exactly when it changes from the provisioner so - // we call a reload on every restart to be safe - if reloadDaemon { - if _, err := p.SSHCommand("sudo systemctl daemon-reload"); err != nil { - return err - } - } - - command := fmt.Sprintf("sudo systemctl -f %s %s", action.String(), name) - - if _, err := p.SSHCommand(command); err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/ubuntu_systemd.go b/vendor/github.com/docker/machine/libmachine/provision/ubuntu_systemd.go deleted file mode 100644 index c4ccb8c..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/ubuntu_systemd.go +++ /dev/null @@ -1,153 +0,0 @@ -package provision - -import ( - "fmt" - "strconv" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/swarm" -) - -func init() { - Register("Ubuntu-SystemD", &RegisteredProvisioner{ - New: NewUbuntuSystemdProvisioner, - }) -} - -func NewUbuntuSystemdProvisioner(d drivers.Driver) Provisioner { - return &UbuntuSystemdProvisioner{ - NewSystemdProvisioner("ubuntu", d), - } -} - -type UbuntuSystemdProvisioner struct { - SystemdProvisioner -} - -func (provisioner *UbuntuSystemdProvisioner) String() string { - return "ubuntu(systemd)" -} - -func (provisioner *UbuntuSystemdProvisioner) CompatibleWithHost() bool { - const FirstUbuntuSystemdVersion = 15.04 - - isUbuntu := provisioner.OsReleaseInfo.ID == provisioner.OsReleaseID - if !isUbuntu { - return false - } - versionNumber, err := strconv.ParseFloat(provisioner.OsReleaseInfo.VersionID, 64) - if err != nil { - return false - } - return versionNumber >= FirstUbuntuSystemdVersion - -} - -func (provisioner *UbuntuSystemdProvisioner) Package(name string, action pkgaction.PackageAction) error { - var packageAction string - - updateMetadata := true - - switch action { - case pkgaction.Install, pkgaction.Upgrade: - packageAction = "install" - case pkgaction.Remove: - packageAction = "remove" - updateMetadata = false - case pkgaction.Purge: - packageAction = "purge" - updateMetadata = false - } - - switch name { - case "docker": - name = "docker-ce" - } - - if updateMetadata { - if err := waitForLockAptGetUpdate(provisioner); err != nil { - return err - } - } - - command := fmt.Sprintf("DEBIAN_FRONTEND=noninteractive sudo -E apt-get %s -y %s", packageAction, name) - - log.Debugf("package: action=%s name=%s", action.String(), name) - - if _, err := provisioner.SSHCommand(command); err != nil { - return err - } - - return nil -} - -func (provisioner *UbuntuSystemdProvisioner) dockerDaemonResponding() bool { - log.Debug("checking docker daemon") - - if out, err := provisioner.SSHCommand("sudo docker version"); err != nil { - log.Warnf("Error getting SSH command to check if the daemon is up: %s", err) - log.Debugf("'sudo docker version' output:\n%s", out) - return false - } - - // The daemon is up if the command worked. Carry on. - return true -} - -func (provisioner *UbuntuSystemdProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - provisioner.SwarmOptions = swarmOptions - provisioner.AuthOptions = authOptions - provisioner.EngineOptions = engineOptions - swarmOptions.Env = engineOptions.Env - - storageDriver, err := decideStorageDriver(provisioner, "aufs", engineOptions.StorageDriver) - if err != nil { - return err - } - provisioner.EngineOptions.StorageDriver = storageDriver - - log.Debug("setting hostname") - if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { - return err - } - - log.Debug("installing base packages") - for _, pkg := range provisioner.Packages { - if err := provisioner.Package(pkg, pkgaction.Install); err != nil { - return err - } - } - - log.Info("Installing Docker...") - if err := installDockerGeneric(provisioner, engineOptions.InstallURL); err != nil { - return err - } - - log.Debug("waiting for docker daemon") - if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil { - return err - } - - provisioner.AuthOptions = setRemoteAuthOptions(provisioner) - - log.Debug("configuring auth") - if err := ConfigureAuth(provisioner); err != nil { - return err - } - - log.Debug("configuring swarm") - if err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions); err != nil { - return err - } - - // enable in systemd - log.Debug("enabling docker in systemd") - err = provisioner.Service("docker", serviceaction.Enable) - return err -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/ubuntu_systemd_test.go b/vendor/github.com/docker/machine/libmachine/provision/ubuntu_systemd_test.go deleted file mode 100644 index c4417c8..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/ubuntu_systemd_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package provision - -import ( - "testing" - - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/provision/provisiontest" - "github.com/docker/machine/libmachine/swarm" -) - -func TestUbuntuSystemdCompatibleWithHost(t *testing.T) { - info := &OsRelease{ - ID: "ubuntu", - VersionID: "15.04", - } - p := NewUbuntuSystemdProvisioner(nil) - p.SetOsReleaseInfo(info) - - compatible := p.CompatibleWithHost() - - if !compatible { - t.Fatalf("expected to be compatible with ubuntu 15.04") - } - - info.VersionID = "14.04" - - compatible = p.CompatibleWithHost() - - if compatible { - t.Fatalf("expected to NOT be compatible with ubuntu 14.04") - } - -} - -func TestUbuntuSystemdDefaultStorageDriver(t *testing.T) { - p := NewUbuntuSystemdProvisioner(&fakedriver.Driver{}).(*UbuntuSystemdProvisioner) - p.SSHCommander = provisiontest.NewFakeSSHCommander(provisiontest.FakeSSHCommanderOptions{}) - p.Provision(swarm.Options{}, auth.Options{}, engine.Options{}) - if p.EngineOptions.StorageDriver != "aufs" { - t.Fatal("Default storage driver should be aufs") - } -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/ubuntu_upstart.go b/vendor/github.com/docker/machine/libmachine/provision/ubuntu_upstart.go deleted file mode 100644 index 979986e..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/ubuntu_upstart.go +++ /dev/null @@ -1,162 +0,0 @@ -package provision - -import ( - "fmt" - "strconv" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/drivers" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/swarm" -) - -func init() { - Register("Ubuntu-UpStart", &RegisteredProvisioner{ - New: NewUbuntuProvisioner, - }) -} - -func NewUbuntuProvisioner(d drivers.Driver) Provisioner { - return &UbuntuProvisioner{ - GenericProvisioner{ - SSHCommander: GenericSSHCommander{Driver: d}, - DockerOptionsDir: "/etc/docker", - DaemonOptionsFile: "/etc/default/docker", - OsReleaseID: "ubuntu", - Packages: []string{ - "curl", - }, - Driver: d, - }, - } -} - -type UbuntuProvisioner struct { - GenericProvisioner -} - -func (provisioner *UbuntuProvisioner) String() string { - return "ubuntu(upstart)" -} - -func (provisioner *UbuntuProvisioner) CompatibleWithHost() bool { - const FirstUbuntuSystemdVersion = 15.04 - isUbuntu := provisioner.OsReleaseInfo.ID == provisioner.OsReleaseID - if !isUbuntu { - return false - } - versionNumber, err := strconv.ParseFloat(provisioner.OsReleaseInfo.VersionID, 64) - if err != nil { - return false - } - - return versionNumber < FirstUbuntuSystemdVersion - -} - -func (provisioner *UbuntuProvisioner) Service(name string, action serviceaction.ServiceAction) error { - command := fmt.Sprintf("sudo service %s %s", name, action.String()) - - if _, err := provisioner.SSHCommand(command); err != nil { - return err - } - - return nil -} - -func (provisioner *UbuntuProvisioner) Package(name string, action pkgaction.PackageAction) error { - var packageAction string - - updateMetadata := true - - switch action { - case pkgaction.Install, pkgaction.Upgrade: - packageAction = "install" - case pkgaction.Remove, pkgaction.Purge: - packageAction = "remove" - updateMetadata = false - } - - switch name { - case "docker": - name = "docker-engine" - } - - if updateMetadata { - if err := waitForLockAptGetUpdate(provisioner); err != nil { - return err - } - } - - command := fmt.Sprintf("DEBIAN_FRONTEND=noninteractive sudo -E apt-get %s -y -o Dpkg::Options::=\"--force-confnew\" %s", packageAction, name) - - log.Debugf("package: action=%s name=%s", action.String(), name) - - if _, err := provisioner.SSHCommand(command); err != nil { - return err - } - - return nil -} - -func (provisioner *UbuntuProvisioner) dockerDaemonResponding() bool { - log.Debug("checking docker daemon") - - if out, err := provisioner.SSHCommand("sudo docker version"); err != nil { - log.Warnf("Error getting SSH command to check if the daemon is up: %s", err) - log.Debugf("'sudo docker version' output:\n%s", out) - return false - } - - // The daemon is up if the command worked. Carry on. - return true -} - -func (provisioner *UbuntuProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - provisioner.SwarmOptions = swarmOptions - provisioner.AuthOptions = authOptions - provisioner.EngineOptions = engineOptions - swarmOptions.Env = engineOptions.Env - - storageDriver, err := decideStorageDriver(provisioner, "aufs", engineOptions.StorageDriver) - if err != nil { - return err - } - provisioner.EngineOptions.StorageDriver = storageDriver - - if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil { - return err - } - - for _, pkg := range provisioner.Packages { - if err := provisioner.Package(pkg, pkgaction.Install); err != nil { - return err - } - } - - log.Info("Installing Docker...") - if err := installDockerGeneric(provisioner, engineOptions.InstallURL); err != nil { - return err - } - - if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil { - return err - } - - if err := makeDockerOptionsDir(provisioner); err != nil { - return err - } - - provisioner.AuthOptions = setRemoteAuthOptions(provisioner) - - if err := ConfigureAuth(provisioner); err != nil { - return err - } - - err = configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions) - return err -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/ubuntu_upstart_test.go b/vendor/github.com/docker/machine/libmachine/provision/ubuntu_upstart_test.go deleted file mode 100644 index dc99d96..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/ubuntu_upstart_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package provision - -import ( - "testing" - - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/provision/provisiontest" - "github.com/docker/machine/libmachine/swarm" -) - -func TestUbuntuCompatibleWithHost(t *testing.T) { - info := &OsRelease{ - ID: "ubuntu", - VersionID: "14.04", - } - p := NewUbuntuProvisioner(nil) - p.SetOsReleaseInfo(info) - - compatible := p.CompatibleWithHost() - - if !compatible { - t.Fatalf("expected to be compatible with ubuntu 14.04") - } - - info.VersionID = "15.04" - - compatible = p.CompatibleWithHost() - - if compatible { - t.Fatalf("expected to NOT be compatible with ubuntu 15.04") - } - -} - -func TestUbuntuDefaultStorageDriver(t *testing.T) { - p := NewUbuntuProvisioner(&fakedriver.Driver{}).(*UbuntuProvisioner) - p.SSHCommander = provisiontest.NewFakeSSHCommander(provisiontest.FakeSSHCommanderOptions{}) - p.Provision(swarm.Options{}, auth.Options{}, engine.Options{}) - if p.EngineOptions.StorageDriver != "aufs" { - t.Fatal("Default storage driver should be aufs") - } -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/utils.go b/vendor/github.com/docker/machine/libmachine/provision/utils.go deleted file mode 100644 index 09483d9..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/utils.go +++ /dev/null @@ -1,318 +0,0 @@ -package provision - -import ( - "fmt" - "io/ioutil" - "net/url" - "path" - "path/filepath" - "regexp" - "strconv" - "strings" - "time" - - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/cert" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "github.com/docker/machine/libmachine/provision/serviceaction" -) - -type DockerOptions struct { - EngineOptions string - EngineOptionsPath string -} - -func installDockerGeneric(p Provisioner, baseURL string) error { - // install docker - until cloudinit we use ubuntu everywhere so we - // just install it using the docker repos - if output, err := p.SSHCommand(fmt.Sprintf("if ! type docker; then curl -sSL %s | sh -; fi", baseURL)); err != nil { - return fmt.Errorf("error installing docker: %s", output) - } - - return nil -} - -func makeDockerOptionsDir(p Provisioner) error { - dockerDir := p.GetDockerOptionsDir() - if _, err := p.SSHCommand(fmt.Sprintf("sudo mkdir -p %s", dockerDir)); err != nil { - return err - } - - return nil -} - -func setRemoteAuthOptions(p Provisioner) auth.Options { - dockerDir := p.GetDockerOptionsDir() - authOptions := p.GetAuthOptions() - - // due to windows clients, we cannot use filepath.Join as the paths - // will be mucked on the linux hosts - authOptions.CaCertRemotePath = path.Join(dockerDir, "ca.pem") - authOptions.ServerCertRemotePath = path.Join(dockerDir, "server.pem") - authOptions.ServerKeyRemotePath = path.Join(dockerDir, "server-key.pem") - - return authOptions -} - -func ConfigureAuth(p Provisioner) error { - var ( - err error - ) - - driver := p.GetDriver() - machineName := driver.GetMachineName() - authOptions := p.GetAuthOptions() - swarmOptions := p.GetSwarmOptions() - org := mcnutils.GetUsername() + "." + machineName - bits := 2048 - - ip, err := driver.GetIP() - if err != nil { - return err - } - - log.Info("Copying certs to the local machine directory...") - - if err := mcnutils.CopyFile(authOptions.CaCertPath, filepath.Join(authOptions.StorePath, "ca.pem")); err != nil { - return fmt.Errorf("Copying ca.pem to machine dir failed: %s", err) - } - - if err := mcnutils.CopyFile(authOptions.ClientCertPath, filepath.Join(authOptions.StorePath, "cert.pem")); err != nil { - return fmt.Errorf("Copying cert.pem to machine dir failed: %s", err) - } - - if err := mcnutils.CopyFile(authOptions.ClientKeyPath, filepath.Join(authOptions.StorePath, "key.pem")); err != nil { - return fmt.Errorf("Copying key.pem to machine dir failed: %s", err) - } - - // The Host IP is always added to the certificate's SANs list - hosts := append(authOptions.ServerCertSANs, ip, "localhost") - log.Debugf("generating server cert: %s ca-key=%s private-key=%s org=%s san=%s", - authOptions.ServerCertPath, - authOptions.CaCertPath, - authOptions.CaPrivateKeyPath, - org, - hosts, - ) - - // TODO: Switch to passing just authOptions to this func - // instead of all these individual fields - err = cert.GenerateCert(&cert.Options{ - Hosts: hosts, - CertFile: authOptions.ServerCertPath, - KeyFile: authOptions.ServerKeyPath, - CAFile: authOptions.CaCertPath, - CAKeyFile: authOptions.CaPrivateKeyPath, - Org: org, - Bits: bits, - SwarmMaster: swarmOptions.Master, - }) - - if err != nil { - return fmt.Errorf("error generating server cert: %s", err) - } - - if err := p.Service("docker", serviceaction.Stop); err != nil { - return err - } - - if _, err := p.SSHCommand(`if [ ! -z "$(ip link show docker0)" ]; then sudo ip link delete docker0; fi`); err != nil { - return err - } - - // upload certs and configure TLS auth - caCert, err := ioutil.ReadFile(authOptions.CaCertPath) - if err != nil { - return err - } - - serverCert, err := ioutil.ReadFile(authOptions.ServerCertPath) - if err != nil { - return err - } - serverKey, err := ioutil.ReadFile(authOptions.ServerKeyPath) - if err != nil { - return err - } - - log.Info("Copying certs to the remote machine...") - - // printf will choke if we don't pass a format string because of the - // dashes, so that's the reason for the '%%s' - certTransferCmdFmt := "printf '%%s' '%s' | sudo tee %s" - - // These ones are for Jessie and Mike <3 <3 <3 - if _, err := p.SSHCommand(fmt.Sprintf(certTransferCmdFmt, string(caCert), authOptions.CaCertRemotePath)); err != nil { - return err - } - - if _, err := p.SSHCommand(fmt.Sprintf(certTransferCmdFmt, string(serverCert), authOptions.ServerCertRemotePath)); err != nil { - return err - } - - if _, err := p.SSHCommand(fmt.Sprintf(certTransferCmdFmt, string(serverKey), authOptions.ServerKeyRemotePath)); err != nil { - return err - } - - dockerURL, err := driver.GetURL() - if err != nil { - return err - } - u, err := url.Parse(dockerURL) - if err != nil { - return err - } - dockerPort := engine.DefaultPort - parts := strings.Split(u.Host, ":") - if len(parts) == 2 { - dPort, err := strconv.Atoi(parts[1]) - if err != nil { - return err - } - dockerPort = dPort - } - - dkrcfg, err := p.GenerateDockerOptions(dockerPort) - if err != nil { - return err - } - - log.Info("Setting Docker configuration on the remote daemon...") - - if _, err = p.SSHCommand(fmt.Sprintf("sudo mkdir -p %s && printf %%s \"%s\" | sudo tee %s", path.Dir(dkrcfg.EngineOptionsPath), dkrcfg.EngineOptions, dkrcfg.EngineOptionsPath)); err != nil { - return err - } - - if err := p.Service("docker", serviceaction.Start); err != nil { - return err - } - - return WaitForDocker(p, dockerPort) -} - -func matchNetstatOut(reDaemonListening, netstatOut string) bool { - // TODO: I would really prefer this be a Scanner directly on - // the STDOUT of the executed command than to do all the string - // manipulation hokey-pokey. - // - // TODO: Unit test this matching. - for _, line := range strings.Split(netstatOut, "\n") { - match, err := regexp.MatchString(reDaemonListening, line) - if err != nil { - log.Warnf("Regex warning: %s", err) - } - if match && line != "" { - return true - } - } - - return false -} - -func decideStorageDriver(p Provisioner, defaultDriver, suppliedDriver string) (string, error) { - if suppliedDriver != "" { - return suppliedDriver, nil - } - bestSuitedDriver := "" - - defer func() { - if bestSuitedDriver != "" { - log.Debugf("No storagedriver specified, using %s\n", bestSuitedDriver) - } - }() - - if defaultDriver != "aufs" { - bestSuitedDriver = defaultDriver - } else { - remoteFilesystemType, err := getFilesystemType(p, "/var/lib") - if err != nil { - return "", err - } - if remoteFilesystemType == "btrfs" { - bestSuitedDriver = "btrfs" - } else { - bestSuitedDriver = "aufs" - } - } - return bestSuitedDriver, nil - -} - -func getFilesystemType(p Provisioner, directory string) (string, error) { - statCommandOutput, err := p.SSHCommand("stat -f -c %T " + directory) - if err != nil { - err = fmt.Errorf("Error looking up filesystem type: %s", err) - return "", err - } - - fstype := strings.TrimSpace(statCommandOutput) - return fstype, nil -} - -func checkDaemonUp(p Provisioner, dockerPort int) func() bool { - reDaemonListening := fmt.Sprintf(":%d\\s+.*:.*", dockerPort) - return func() bool { - // HACK: Check netstat's output to see if anyone's listening on the Docker API port. - netstatOut, err := p.SSHCommand("netstat -tln") - if err != nil { - log.Warnf("Error running SSH command: %s", err) - return false - } - - return matchNetstatOut(reDaemonListening, netstatOut) - } -} - -func WaitForDocker(p Provisioner, dockerPort int) error { - if err := mcnutils.WaitForSpecific(checkDaemonUp(p, dockerPort), 10, 3*time.Second); err != nil { - return NewErrDaemonAvailable(err) - } - - return nil -} - -// DockerClientVersion returns the version of the Docker client on the host -// that ssh is connected to, e.g. "1.12.1". -func DockerClientVersion(ssh SSHCommander) (string, error) { - // `docker version --format {{.Client.Version}}` would be preferable, but - // that fails if the server isn't running yet. - // - // output is expected to be something like - // - // Docker version 1.12.1, build 7a86f89 - output, err := ssh.SSHCommand("docker --version") - if err != nil { - return "", err - } - - words := strings.Fields(output) - if len(words) < 3 || words[0] != "Docker" || words[1] != "version" { - return "", fmt.Errorf("DockerClientVersion: cannot parse version string from %q", output) - } - - return strings.TrimRight(words[2], ","), nil -} - -func waitForLockAptGetUpdate(ssh SSHCommander) error { - var sshErr error - err := mcnutils.WaitFor(func() bool { - _, sshErr = ssh.SSHCommand("sudo apt-get update") - if sshErr != nil { - if strings.Contains(sshErr.Error(), "Could not get lock") { - sshErr = nil - return false - } - return true - } - return true - }) - if sshErr != nil { - return fmt.Errorf("Error running apt-get update: %s", sshErr) - } - if err != nil { - return fmt.Errorf("Failed to obtain apt-get update lock: %s", err) - } - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/provision/utils_test.go b/vendor/github.com/docker/machine/libmachine/provision/utils_test.go deleted file mode 100644 index e005c51..0000000 --- a/vendor/github.com/docker/machine/libmachine/provision/utils_test.go +++ /dev/null @@ -1,264 +0,0 @@ -package provision - -import ( - "fmt" - "regexp" - "strings" - "testing" - - "github.com/docker/machine/drivers/fakedriver" - "github.com/docker/machine/libmachine/auth" - "github.com/docker/machine/libmachine/engine" - "github.com/docker/machine/libmachine/provision/pkgaction" - "github.com/docker/machine/libmachine/provision/provisiontest" - "github.com/docker/machine/libmachine/provision/serviceaction" - "github.com/docker/machine/libmachine/swarm" - "github.com/stretchr/testify/assert" -) - -var ( - reDaemonListening = ":2376\\s+.*:.*" -) - -func TestMatchNetstatOutMissing(t *testing.T) { - nsOut := `Active Internet connections (servers and established) -Proto Recv-Q Send-Q Local Address Foreign Address State -tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -tcp 0 0 0.0.0.0:237 0.0.0.0:* LISTEN -tcp6 0 0 :::22 :::* LISTEN -tcp6 0 0 :::23760 :::* LISTEN` - if matchNetstatOut(reDaemonListening, nsOut) { - t.Fatal("Expected not to match the netstat output as showing the daemon listening but got a match") - } -} - -func TestMatchNetstatOutPresent(t *testing.T) { - nsOut := `Active Internet connections (servers and established) -Proto Recv-Q Send-Q Local Address Foreign Address State -tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -tcp6 0 0 :::2376 :::* LISTEN -tcp6 0 0 :::22 :::* LISTEN` - if !matchNetstatOut(reDaemonListening, nsOut) { - t.Fatal("Expected to match the netstat output as showing the daemon listening but didn't") - } -} - -func TestGenerateDockerOptionsBoot2Docker(t *testing.T) { - p := &Boot2DockerProvisioner{ - Driver: &fakedriver.Driver{}, - } - dockerPort := 1234 - p.AuthOptions = auth.Options{ - CaCertRemotePath: "/test/ca-cert", - ServerKeyRemotePath: "/test/server-key", - ServerCertRemotePath: "/test/server-cert", - } - engineConfigPath := "/var/lib/boot2docker/profile" - - dockerCfg, err := p.GenerateDockerOptions(dockerPort) - if err != nil { - t.Fatal(err) - } - - if dockerCfg.EngineOptionsPath != engineConfigPath { - t.Fatalf("expected engine path %s; received %s", engineConfigPath, dockerCfg.EngineOptionsPath) - } - - if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("-H tcp://0.0.0.0:%d", dockerPort)) == -1 { - t.Fatalf("-H docker port invalid; expected %d", dockerPort) - } - - if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("CACERT=%s", p.AuthOptions.CaCertRemotePath)) == -1 { - t.Fatalf("CACERT option invalid; expected %s", p.AuthOptions.CaCertRemotePath) - } - - if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("SERVERKEY=%s", p.AuthOptions.ServerKeyRemotePath)) == -1 { - t.Fatalf("SERVERKEY option invalid; expected %s", p.AuthOptions.ServerKeyRemotePath) - } - - if strings.Index(dockerCfg.EngineOptions, fmt.Sprintf("SERVERCERT=%s", p.AuthOptions.ServerCertRemotePath)) == -1 { - t.Fatalf("SERVERCERT option invalid; expected %s", p.AuthOptions.ServerCertRemotePath) - } -} - -func TestMachinePortBoot2Docker(t *testing.T) { - p := &Boot2DockerProvisioner{ - Driver: &fakedriver.Driver{}, - } - dockerPort := engine.DefaultPort - bindURL := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort) - p.AuthOptions = auth.Options{ - CaCertRemotePath: "/test/ca-cert", - ServerKeyRemotePath: "/test/server-key", - ServerCertRemotePath: "/test/server-cert", - } - - cfg, err := p.GenerateDockerOptions(dockerPort) - if err != nil { - t.Fatal(err) - } - re := regexp.MustCompile("-H tcp://.*:(.+)") - m := re.FindStringSubmatch(cfg.EngineOptions) - if len(m) == 0 { - t.Errorf("could not find port %d in engine config", dockerPort) - } - - b := m[0] - u := strings.Split(b, " ") - url := u[1] - url = strings.Replace(url, "'", "", -1) - url = strings.Replace(url, "\\\"", "", -1) - if url != bindURL { - t.Errorf("expected url %s; received %s", bindURL, url) - } -} - -func TestMachineCustomPortBoot2Docker(t *testing.T) { - p := &Boot2DockerProvisioner{ - Driver: &fakedriver.Driver{}, - } - dockerPort := 3376 - bindURL := fmt.Sprintf("tcp://0.0.0.0:%d", dockerPort) - p.AuthOptions = auth.Options{ - CaCertRemotePath: "/test/ca-cert", - ServerKeyRemotePath: "/test/server-key", - ServerCertRemotePath: "/test/server-cert", - } - - cfg, err := p.GenerateDockerOptions(dockerPort) - if err != nil { - t.Fatal(err) - } - - re := regexp.MustCompile("-H tcp://.*:(.+)") - m := re.FindStringSubmatch(cfg.EngineOptions) - if len(m) == 0 { - t.Errorf("could not find port %d in engine config", dockerPort) - } - - b := m[0] - u := strings.Split(b, " ") - url := u[1] - url = strings.Replace(url, "'", "", -1) - url = strings.Replace(url, "\\\"", "", -1) - if url != bindURL { - t.Errorf("expected url %s; received %s", bindURL, url) - } -} - -func TestUbuntuSystemdDaemonBinary(t *testing.T) { - p := NewUbuntuSystemdProvisioner(&fakedriver.Driver{}).(*UbuntuSystemdProvisioner) - cases := []struct { - output, want string - }{ - {"Docker version 1.9.1\n", "docker daemon"}, - {"Docker version 1.11.2\n", "docker daemon"}, - {"Docker version 1.12.0\n", "dockerd"}, - {"Docker version 1.13.0\n", "dockerd"}, - } - - sshCmder := &provisiontest.FakeSSHCommander{ - Responses: make(map[string]string), - } - p.SSHCommander = sshCmder - - for _, tc := range cases { - sshCmder.Responses["docker --version"] = tc.output - opts, err := p.GenerateDockerOptions(1234) - if err != nil { - t.Fatal(err) - } - if !strings.Contains(opts.EngineOptions, tc.want) { - t.Fatal("incorrect docker daemon binary in engine options") - } - } -} - -type fakeProvisioner struct { - GenericProvisioner -} - -func (provisioner *fakeProvisioner) Package(name string, action pkgaction.PackageAction) error { - return nil -} - -func (provisioner *fakeProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error { - return nil -} - -func (provisioner *fakeProvisioner) Service(name string, action serviceaction.ServiceAction) error { - return nil -} - -func (provisioner *fakeProvisioner) String() string { - return "fake" -} - -func TestDecideStorageDriver(t *testing.T) { - var tests = []struct { - suppliedDriver string - defaultDriver string - remoteFilesystemType string - expectedDriver string - }{ - {"", "aufs", "ext4", "aufs"}, - {"", "aufs", "btrfs", "btrfs"}, - {"", "overlay", "btrfs", "overlay"}, - {"devicemapper", "aufs", "ext4", "devicemapper"}, - {"devicemapper", "aufs", "btrfs", "devicemapper"}, - } - - p := &fakeProvisioner{GenericProvisioner{ - Driver: &fakedriver.Driver{}, - }} - for _, test := range tests { - p.SSHCommander = provisiontest.NewFakeSSHCommander( - provisiontest.FakeSSHCommanderOptions{ - FilesystemType: test.remoteFilesystemType, - }, - ) - storageDriver, err := decideStorageDriver(p, test.defaultDriver, test.suppliedDriver) - assert.NoError(t, err) - assert.Equal(t, test.expectedDriver, storageDriver) - } -} - -func TestGetFilesystemType(t *testing.T) { - p := &fakeProvisioner{GenericProvisioner{ - Driver: &fakedriver.Driver{}, - }} - p.SSHCommander = &provisiontest.FakeSSHCommander{ - Responses: map[string]string{ - "stat -f -c %T /var/lib": "btrfs\n", - }, - } - fsType, err := getFilesystemType(p, "/var/lib") - assert.NoError(t, err) - assert.Equal(t, "btrfs", fsType) -} - -func TestDockerClientVersion(t *testing.T) { - cases := []struct { - output, want string - }{ - {"Docker version 1.9.1, build a34a1d5\n", "1.9.1"}, - {"Docker version 1.9.1\n", "1.9.1"}, - {"Docker version 1.13.0-rc1, build deadbeef\n", "1.13.0-rc1"}, - {"Docker version 1.13.0-dev, build deadbeef\n", "1.13.0-dev"}, - } - - sshCmder := &provisiontest.FakeSSHCommander{ - Responses: make(map[string]string), - } - - for _, tc := range cases { - sshCmder.Responses["docker --version"] = tc.output - got, err := DockerClientVersion(sshCmder) - if err != nil { - t.Fatal(err) - } - if got != tc.want { - t.Errorf("Unexpected version string from %q; got %q, want %q", tc.output, tc.want, got) - } - } -} diff --git a/vendor/github.com/docker/machine/libmachine/shell/shell.go b/vendor/github.com/docker/machine/libmachine/shell/shell.go deleted file mode 100644 index d0a271c..0000000 --- a/vendor/github.com/docker/machine/libmachine/shell/shell.go +++ /dev/null @@ -1,26 +0,0 @@ -// +build !windows - -package shell - -import ( - "errors" - "fmt" - "os" - "path/filepath" -) - -var ( - ErrUnknownShell = errors.New("Error: Unknown shell") -) - -// Detect detects user's current shell. -func Detect() (string, error) { - shell := os.Getenv("SHELL") - - if shell == "" { - fmt.Printf("The default lines below are for a sh/bash shell, you can specify the shell you're using, with the --shell flag.\n\n") - return "", ErrUnknownShell - } - - return filepath.Base(shell), nil -} diff --git a/vendor/github.com/docker/machine/libmachine/shell/shell_test.go b/vendor/github.com/docker/machine/libmachine/shell/shell_test.go deleted file mode 100644 index 97ef34f..0000000 --- a/vendor/github.com/docker/machine/libmachine/shell/shell_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package shell - -import ( - "os" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestDetectBash(t *testing.T) { - defer func(shell string) { os.Setenv("SHELL", shell) }(os.Getenv("SHELL")) - os.Setenv("SHELL", "/bin/bash") - - shell, err := Detect() - - assert.Equal(t, "bash", shell) - assert.NoError(t, err) -} - -func TestDetectFish(t *testing.T) { - defer func(shell string) { os.Setenv("SHELL", shell) }(os.Getenv("SHELL")) - os.Setenv("SHELL", "/bin/fish") - - shell, err := Detect() - - assert.Equal(t, "fish", shell) - assert.NoError(t, err) -} diff --git a/vendor/github.com/docker/machine/libmachine/shell/shell_unix_test.go b/vendor/github.com/docker/machine/libmachine/shell/shell_unix_test.go deleted file mode 100644 index b938207..0000000 --- a/vendor/github.com/docker/machine/libmachine/shell/shell_unix_test.go +++ /dev/null @@ -1,20 +0,0 @@ -// +build !windows - -package shell - -import ( - "os" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestUnknownShell(t *testing.T) { - defer func(shell string) { os.Setenv("SHELL", shell) }(os.Getenv("SHELL")) - os.Setenv("SHELL", "") - - shell, err := Detect() - - assert.Equal(t, err, ErrUnknownShell) - assert.Empty(t, shell) -} diff --git a/vendor/github.com/docker/machine/libmachine/shell/shell_windows.go b/vendor/github.com/docker/machine/libmachine/shell/shell_windows.go deleted file mode 100644 index 89cd2c8..0000000 --- a/vendor/github.com/docker/machine/libmachine/shell/shell_windows.go +++ /dev/null @@ -1,84 +0,0 @@ -package shell - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "syscall" - "unsafe" -) - -// re-implementation of private function in https://github.com/golang/go/blob/master/src/syscall/syscall_windows.go#L945 -func getProcessEntry(pid int) (pe *syscall.ProcessEntry32, err error) { - snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0) - if err != nil { - return nil, err - } - defer syscall.CloseHandle(syscall.Handle(snapshot)) - - var processEntry syscall.ProcessEntry32 - processEntry.Size = uint32(unsafe.Sizeof(processEntry)) - err = syscall.Process32First(snapshot, &processEntry) - if err != nil { - return nil, err - } - - for { - if processEntry.ProcessID == uint32(pid) { - pe = &processEntry - return - } - - err = syscall.Process32Next(snapshot, &processEntry) - if err != nil { - return nil, err - } - } -} - -// getNameAndItsPpid returns the exe file name its parent process id. -func getNameAndItsPpid(pid int) (exefile string, parentid int, err error) { - pe, err := getProcessEntry(pid) - if err != nil { - return "", 0, err - } - - name := syscall.UTF16ToString(pe.ExeFile[:]) - return name, int(pe.ParentProcessID), nil -} - -func Detect() (string, error) { - shell := os.Getenv("SHELL") - - if shell == "" { - shell, shellppid, err := getNameAndItsPpid(os.Getppid()) - if err != nil { - return "cmd", err // defaulting to cmd - } - if strings.Contains(strings.ToLower(shell), "powershell") { - return "powershell", nil - } else if strings.Contains(strings.ToLower(shell), "cmd") { - return "cmd", nil - } else { - shell, _, err := getNameAndItsPpid(shellppid) - if err != nil { - return "cmd", err // defaulting to cmd - } - if strings.Contains(strings.ToLower(shell), "powershell") { - return "powershell", nil - } else if strings.Contains(strings.ToLower(shell), "cmd") { - return "cmd", nil - } else { - fmt.Printf("You can further specify your shell with either 'cmd' or 'powershell' with the --shell flag.\n\n") - return "cmd", nil // this could be either powershell or cmd, defaulting to cmd - } - } - } - - if os.Getenv("__fish_bin_dir") != "" { - return "fish", nil - } - - return filepath.Base(shell), nil -} diff --git a/vendor/github.com/docker/machine/libmachine/shell/shell_windows_test.go b/vendor/github.com/docker/machine/libmachine/shell/shell_windows_test.go deleted file mode 100644 index 81c0c50..0000000 --- a/vendor/github.com/docker/machine/libmachine/shell/shell_windows_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package shell - -import ( - "os" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestDetect(t *testing.T) { - defer func(shell string) { os.Setenv("SHELL", shell) }(os.Getenv("SHELL")) - os.Setenv("SHELL", "") - - shell, err := Detect() - - assert.Equal(t, "powershell", shell) - assert.NoError(t, err) -} - -func TestGetNameAndItsPpidOfCurrent(t *testing.T) { - shell, shellppid, err := getNameAndItsPpid(os.Getpid()) - - assert.Equal(t, "shell.test.exe", shell) - assert.Equal(t, os.Getppid(), shellppid) - assert.NoError(t, err) -} - -func TestGetNameAndItsPpidOfParent(t *testing.T) { - shell, _, err := getNameAndItsPpid(os.Getppid()) - - assert.Equal(t, "go.exe", shell) - assert.NoError(t, err) -} - -func TestGetNameAndItsPpidOfGrandParent(t *testing.T) { - shell, shellppid, err := getNameAndItsPpid(os.Getppid()) - shell, shellppid, err = getNameAndItsPpid(shellppid) - - assert.Equal(t, "powershell.exe", shell) - assert.NoError(t, err) -} diff --git a/vendor/github.com/docker/machine/libmachine/ssh/client.go b/vendor/github.com/docker/machine/libmachine/ssh/client.go deleted file mode 100644 index abd4705..0000000 --- a/vendor/github.com/docker/machine/libmachine/ssh/client.go +++ /dev/null @@ -1,443 +0,0 @@ -package ssh - -import ( - "fmt" - "io" - "io/ioutil" - "net" - "os" - "os/exec" - "runtime" - "strconv" - "strings" - - "github.com/docker/docker/pkg/term" - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - "golang.org/x/crypto/ssh" - "golang.org/x/crypto/ssh/terminal" -) - -type Client interface { - Output(command string) (string, error) - Shell(args ...string) error - - // Start starts the specified command without waiting for it to finish. You - // have to call the Wait function for that. - // - // The first two io.ReadCloser are the standard output and the standard - // error of the executing command respectively. The returned error follows - // the same logic as in the exec.Cmd.Start function. - Start(command string) (io.ReadCloser, io.ReadCloser, error) - - // Wait waits for the command started by the Start function to exit. The - // returned error follows the same logic as in the exec.Cmd.Wait function. - Wait() error -} - -type ExternalClient struct { - BaseArgs []string - BinaryPath string - cmd *exec.Cmd -} - -type NativeClient struct { - Config ssh.ClientConfig - Hostname string - Port int - openSession *ssh.Session - openClient *ssh.Client -} - -type Auth struct { - Passwords []string - Keys []string -} - -type ClientType string - -const ( - maxDialAttempts = 10 -) - -const ( - External ClientType = "external" - Native ClientType = "native" -) - -var ( - baseSSHArgs = []string{ - "-F", "/dev/null", - "-o", "PasswordAuthentication=no", - "-o", "StrictHostKeyChecking=no", - "-o", "UserKnownHostsFile=/dev/null", - "-o", "LogLevel=quiet", // suppress "Warning: Permanently added '[localhost]:2022' (ECDSA) to the list of known hosts." - "-o", "ConnectionAttempts=3", // retry 3 times if SSH connection fails - "-o", "ConnectTimeout=10", // timeout after 10 seconds - "-o", "ControlMaster=no", // disable ssh multiplexing - "-o", "ControlPath=none", - } - defaultClientType = External -) - -func SetDefaultClient(clientType ClientType) { - // Allow over-riding of default client type, so that even if ssh binary - // is found in PATH we can still use the Go native implementation if - // desired. - switch clientType { - case External: - defaultClientType = External - case Native: - defaultClientType = Native - } -} - -func NewClient(user string, host string, port int, auth *Auth) (Client, error) { - sshBinaryPath, err := exec.LookPath("ssh") - if err != nil { - log.Debug("SSH binary not found, using native Go implementation") - client, err := NewNativeClient(user, host, port, auth) - log.Debug(client) - return client, err - } - - if defaultClientType == Native { - log.Debug("Using SSH client type: native") - client, err := NewNativeClient(user, host, port, auth) - log.Debug(client) - return client, err - } - - log.Debug("Using SSH client type: external") - client, err := NewExternalClient(sshBinaryPath, user, host, port, auth) - log.Debug(client) - return client, err -} - -func NewNativeClient(user, host string, port int, auth *Auth) (Client, error) { - config, err := NewNativeConfig(user, auth) - if err != nil { - return nil, fmt.Errorf("Error getting config for native Go SSH: %s", err) - } - - return &NativeClient{ - Config: config, - Hostname: host, - Port: port, - }, nil -} - -func NewNativeConfig(user string, auth *Auth) (ssh.ClientConfig, error) { - var ( - authMethods []ssh.AuthMethod - ) - - for _, k := range auth.Keys { - key, err := ioutil.ReadFile(k) - if err != nil { - return ssh.ClientConfig{}, err - } - - privateKey, err := ssh.ParsePrivateKey(key) - if err != nil { - return ssh.ClientConfig{}, err - } - - authMethods = append(authMethods, ssh.PublicKeys(privateKey)) - } - - for _, p := range auth.Passwords { - authMethods = append(authMethods, ssh.Password(p)) - } - - return ssh.ClientConfig{ - User: user, - Auth: authMethods, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil -} - -func (client *NativeClient) dialSuccess() bool { - conn, err := ssh.Dial("tcp", net.JoinHostPort(client.Hostname, strconv.Itoa(client.Port)), &client.Config) - if err != nil { - log.Debugf("Error dialing TCP: %s", err) - return false - } - closeConn(conn) - return true -} - -func (client *NativeClient) session(command string) (*ssh.Client, *ssh.Session, error) { - if err := mcnutils.WaitFor(client.dialSuccess); err != nil { - return nil, nil, fmt.Errorf("Error attempting SSH client dial: %s", err) - } - - conn, err := ssh.Dial("tcp", net.JoinHostPort(client.Hostname, strconv.Itoa(client.Port)), &client.Config) - if err != nil { - return nil, nil, fmt.Errorf("Mysterious error dialing TCP for SSH (we already succeeded at least once) : %s", err) - } - session, err := conn.NewSession() - - return conn, session, err -} - -func (client *NativeClient) Output(command string) (string, error) { - conn, session, err := client.session(command) - if err != nil { - return "", nil - } - defer closeConn(conn) - defer session.Close() - - output, err := session.CombinedOutput(command) - - return string(output), err -} - -func (client *NativeClient) OutputWithPty(command string) (string, error) { - conn, session, err := client.session(command) - if err != nil { - return "", nil - } - defer closeConn(conn) - defer session.Close() - - fd := int(os.Stdout.Fd()) - - termWidth, termHeight, err := terminal.GetSize(fd) - if err != nil { - return "", err - } - - modes := ssh.TerminalModes{ - ssh.ECHO: 0, - ssh.TTY_OP_ISPEED: 14400, - ssh.TTY_OP_OSPEED: 14400, - } - - // request tty -- fixes error with hosts that use - // "Defaults requiretty" in /etc/sudoers - I'm looking at you RedHat - if err := session.RequestPty("xterm", termHeight, termWidth, modes); err != nil { - return "", err - } - - output, err := session.CombinedOutput(command) - - return string(output), err -} - -func (client *NativeClient) Start(command string) (io.ReadCloser, io.ReadCloser, error) { - conn, session, err := client.session(command) - if err != nil { - return nil, nil, err - } - - stdout, err := session.StdoutPipe() - if err != nil { - return nil, nil, err - } - stderr, err := session.StderrPipe() - if err != nil { - return nil, nil, err - } - if err := session.Start(command); err != nil { - return nil, nil, err - } - - client.openClient = conn - client.openSession = session - return ioutil.NopCloser(stdout), ioutil.NopCloser(stderr), nil -} - -func (client *NativeClient) Wait() error { - err := client.openSession.Wait() - if err != nil { - return err - } - - _ = client.openSession.Close() - - err = client.openClient.Close() - if err != nil { - return err - } - - client.openSession = nil - client.openClient = nil - return nil -} - -func (client *NativeClient) Shell(args ...string) error { - var ( - termWidth, termHeight int - ) - conn, err := ssh.Dial("tcp", net.JoinHostPort(client.Hostname, strconv.Itoa(client.Port)), &client.Config) - if err != nil { - return err - } - defer closeConn(conn) - - session, err := conn.NewSession() - if err != nil { - return err - } - - defer session.Close() - - session.Stdout = os.Stdout - session.Stderr = os.Stderr - session.Stdin = os.Stdin - - modes := ssh.TerminalModes{ - ssh.ECHO: 1, - } - - fd := os.Stdin.Fd() - - if term.IsTerminal(fd) { - oldState, err := term.MakeRaw(fd) - if err != nil { - return err - } - - defer term.RestoreTerminal(fd, oldState) - - winsize, err := term.GetWinsize(fd) - if err != nil { - termWidth = 80 - termHeight = 24 - } else { - termWidth = int(winsize.Width) - termHeight = int(winsize.Height) - } - } - - if err := session.RequestPty("xterm", termHeight, termWidth, modes); err != nil { - return err - } - - if len(args) == 0 { - if err := session.Shell(); err != nil { - return err - } - session.Wait() - } else { - session.Run(strings.Join(args, " ")) - } - - return nil -} - -func NewExternalClient(sshBinaryPath, user, host string, port int, auth *Auth) (*ExternalClient, error) { - client := &ExternalClient{ - BinaryPath: sshBinaryPath, - } - - args := append(baseSSHArgs, fmt.Sprintf("%s@%s", user, host)) - - // If no identities are explicitly provided, also look at the identities - // offered by ssh-agent - if len(auth.Keys) > 0 { - args = append(args, "-o", "IdentitiesOnly=yes") - } - - // Specify which private keys to use to authorize the SSH request. - for _, privateKeyPath := range auth.Keys { - if privateKeyPath != "" { - // Check each private key before use it - fi, err := os.Stat(privateKeyPath) - if err != nil { - // Abort if key not accessible - return nil, err - } - if runtime.GOOS != "windows" { - mode := fi.Mode() - log.Debugf("Using SSH private key: %s (%s)", privateKeyPath, mode) - // Private key file should have strict permissions - perm := mode.Perm() - if perm&0400 == 0 { - return nil, fmt.Errorf("'%s' is not readable", privateKeyPath) - } - if perm&0077 != 0 { - return nil, fmt.Errorf("permissions %#o for '%s' are too open", perm, privateKeyPath) - } - } - args = append(args, "-i", privateKeyPath) - } - } - - // Set which port to use for SSH. - args = append(args, "-p", fmt.Sprintf("%d", port)) - - client.BaseArgs = args - - return client, nil -} - -func getSSHCmd(binaryPath string, args ...string) *exec.Cmd { - return exec.Command(binaryPath, args...) -} - -func (client *ExternalClient) Output(command string) (string, error) { - args := append(client.BaseArgs, command) - cmd := getSSHCmd(client.BinaryPath, args...) - output, err := cmd.CombinedOutput() - return string(output), err -} - -func (client *ExternalClient) Shell(args ...string) error { - args = append(client.BaseArgs, args...) - cmd := getSSHCmd(client.BinaryPath, args...) - - log.Debug(cmd) - - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - return cmd.Run() -} - -func (client *ExternalClient) Start(command string) (io.ReadCloser, io.ReadCloser, error) { - args := append(client.BaseArgs, command) - cmd := getSSHCmd(client.BinaryPath, args...) - - log.Debug(cmd) - - stdout, err := cmd.StdoutPipe() - if err != nil { - return nil, nil, err - } - stderr, err := cmd.StderrPipe() - if err != nil { - if closeErr := stdout.Close(); closeErr != nil { - return nil, nil, fmt.Errorf("%s, %s", err, closeErr) - } - return nil, nil, err - } - if err := cmd.Start(); err != nil { - stdOutCloseErr := stdout.Close() - stdErrCloseErr := stderr.Close() - if stdOutCloseErr != nil || stdErrCloseErr != nil { - return nil, nil, fmt.Errorf("%s, %s, %s", - err, stdOutCloseErr, stdErrCloseErr) - } - return nil, nil, err - } - - client.cmd = cmd - return stdout, stderr, nil -} - -func (client *ExternalClient) Wait() error { - err := client.cmd.Wait() - client.cmd = nil - return err -} - -func closeConn(c io.Closer) { - err := c.Close() - if err != nil { - log.Debugf("Error closing SSH Client: %s", err) - } -} diff --git a/vendor/github.com/docker/machine/libmachine/ssh/client_test.go b/vendor/github.com/docker/machine/libmachine/ssh/client_test.go deleted file mode 100644 index 5610c1c..0000000 --- a/vendor/github.com/docker/machine/libmachine/ssh/client_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package ssh - -import ( - "fmt" - "io/ioutil" - "os" - "runtime" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestGetSSHCmdArgs(t *testing.T) { - cases := []struct { - binaryPath string - args []string - expectedArgs []string - }{ - { - binaryPath: "/usr/local/bin/ssh", - args: []string{ - "docker@localhost", - "apt-get install -y htop", - }, - expectedArgs: []string{ - "/usr/local/bin/ssh", - "docker@localhost", - "apt-get install -y htop", - }, - }, - { - binaryPath: "C:\\Program Files\\Git\\bin\\ssh.exe", - args: []string{ - "docker@localhost", - "sudo /usr/bin/sethostname foobar && echo 'foobar' | sudo tee /var/lib/boot2docker/etc/hostname", - }, - expectedArgs: []string{ - "C:\\Program Files\\Git\\bin\\ssh.exe", - "docker@localhost", - "sudo /usr/bin/sethostname foobar && echo 'foobar' | sudo tee /var/lib/boot2docker/etc/hostname", - }, - }, - } - - for _, c := range cases { - cmd := getSSHCmd(c.binaryPath, c.args...) - assert.Equal(t, cmd.Args, c.expectedArgs) - } -} - -func TestNewExternalClient(t *testing.T) { - keyFile, err := ioutil.TempFile("", "docker-machine-tests-dummy-private-key") - if err != nil { - t.Fatal(err) - } - defer keyFile.Close() - - keyFilename := keyFile.Name() - defer os.Remove(keyFilename) - - cases := []struct { - sshBinaryPath string - user string - host string - port int - auth *Auth - perm os.FileMode - expectedError string - skipOS string - }{ - { - auth: &Auth{Keys: []string{"/tmp/private-key-not-exist"}}, - expectedError: "stat /tmp/private-key-not-exist: no such file or directory", - skipOS: "none", - }, - { - auth: &Auth{Keys: []string{keyFilename}}, - perm: 0400, - skipOS: "windows", - }, - { - auth: &Auth{Keys: []string{keyFilename}}, - perm: 0100, - expectedError: fmt.Sprintf("'%s' is not readable", keyFilename), - skipOS: "windows", - }, - { - auth: &Auth{Keys: []string{keyFilename}}, - perm: 0644, - expectedError: fmt.Sprintf("permissions 0644 for '%s' are too open", keyFilename), - skipOS: "windows", - }, - } - - for _, c := range cases { - if runtime.GOOS != c.skipOS { - keyFile.Chmod(c.perm) - _, err := NewExternalClient(c.sshBinaryPath, c.user, c.host, c.port, c.auth) - if c.expectedError != "" { - assert.EqualError(t, err, c.expectedError) - } else { - assert.Equal(t, err, nil) - } - } - } -} diff --git a/vendor/github.com/docker/machine/libmachine/ssh/keys.go b/vendor/github.com/docker/machine/libmachine/ssh/keys.go deleted file mode 100644 index 24ae20c..0000000 --- a/vendor/github.com/docker/machine/libmachine/ssh/keys.go +++ /dev/null @@ -1,124 +0,0 @@ -package ssh - -import ( - "crypto/md5" - "crypto/rand" - "crypto/rsa" - "crypto/x509" - "encoding/base64" - "encoding/pem" - "errors" - "fmt" - "io" - "os" - "runtime" - - gossh "golang.org/x/crypto/ssh" -) - -var ( - ErrKeyGeneration = errors.New("Unable to generate key") - ErrValidation = errors.New("Unable to validate key") - ErrPublicKey = errors.New("Unable to convert public key") - ErrUnableToWriteFile = errors.New("Unable to write file") -) - -type KeyPair struct { - PrivateKey []byte - PublicKey []byte -} - -// NewKeyPair generates a new SSH keypair -// This will return a private & public key encoded as DER. -func NewKeyPair() (keyPair *KeyPair, err error) { - priv, err := rsa.GenerateKey(rand.Reader, 2048) - if err != nil { - return nil, ErrKeyGeneration - } - - if err := priv.Validate(); err != nil { - return nil, ErrValidation - } - - privDer := x509.MarshalPKCS1PrivateKey(priv) - - pubSSH, err := gossh.NewPublicKey(&priv.PublicKey) - if err != nil { - return nil, ErrPublicKey - } - - return &KeyPair{ - PrivateKey: privDer, - PublicKey: gossh.MarshalAuthorizedKey(pubSSH), - }, nil -} - -// WriteToFile writes keypair to files -func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) error { - files := []struct { - File string - Type string - Value []byte - }{ - { - File: privateKeyPath, - Value: pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Headers: nil, Bytes: kp.PrivateKey}), - }, - { - File: publicKeyPath, - Value: kp.PublicKey, - }, - } - - for _, v := range files { - f, err := os.Create(v.File) - if err != nil { - return ErrUnableToWriteFile - } - - if _, err := f.Write(v.Value); err != nil { - return ErrUnableToWriteFile - } - - // windows does not support chmod - switch runtime.GOOS { - case "darwin", "linux", "freebsd": - if err := f.Chmod(0600); err != nil { - return err - } - } - } - - return nil -} - -// Fingerprint calculates the fingerprint of the public key -func (kp *KeyPair) Fingerprint() string { - b, _ := base64.StdEncoding.DecodeString(string(kp.PublicKey)) - h := md5.New() - - io.WriteString(h, string(b)) - - return fmt.Sprintf("%x", h.Sum(nil)) -} - -// GenerateSSHKey generates SSH keypair based on path of the private key -// The public key would be generated to the same path with ".pub" added -func GenerateSSHKey(path string) error { - if _, err := os.Stat(path); err != nil { - if !os.IsNotExist(err) { - return fmt.Errorf("Desired directory for SSH keys does not exist: %s", err) - } - - kp, err := NewKeyPair() - if err != nil { - return fmt.Errorf("Error generating key pair: %s", err) - } - - if err := kp.WriteToFile(path, fmt.Sprintf("%s.pub", path)); err != nil { - return fmt.Errorf("Error writing keys to file(s): %s", err) - } - } - - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/ssh/keys_test.go b/vendor/github.com/docker/machine/libmachine/ssh/keys_test.go deleted file mode 100644 index 07e3b83..0000000 --- a/vendor/github.com/docker/machine/libmachine/ssh/keys_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package ssh - -import ( - "encoding/pem" - "testing" -) - -func TestNewKeyPair(t *testing.T) { - pair, err := NewKeyPair() - if err != nil { - t.Fatal(err) - } - - if privPem := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Headers: nil, Bytes: pair.PrivateKey}); len(privPem) == 0 { - t.Fatal("No PEM returned") - } - - if fingerprint := pair.Fingerprint(); len(fingerprint) == 0 { - t.Fatal("Unable to generate fingerprint") - } -} diff --git a/vendor/github.com/docker/machine/libmachine/ssh/ssh_test.go b/vendor/github.com/docker/machine/libmachine/ssh/ssh_test.go deleted file mode 100644 index 8722dc7..0000000 --- a/vendor/github.com/docker/machine/libmachine/ssh/ssh_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package ssh - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func TestGenerateSSHKey(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "machine-test-") - if err != nil { - t.Fatal(err) - } - - filename := filepath.Join(tmpDir, "sshkey") - - if err := GenerateSSHKey(filename); err != nil { - t.Fatal(err) - } - - if _, err := os.Stat(filename); err != nil { - t.Fatalf("expected ssh key at %s", filename) - } - - // cleanup - _ = os.RemoveAll(tmpDir) -} diff --git a/vendor/github.com/docker/machine/libmachine/ssh/sshtest/fake_client.go b/vendor/github.com/docker/machine/libmachine/ssh/sshtest/fake_client.go deleted file mode 100644 index 2b333b5..0000000 --- a/vendor/github.com/docker/machine/libmachine/ssh/sshtest/fake_client.go +++ /dev/null @@ -1,31 +0,0 @@ -package sshtest - -import "io" - -type CmdResult struct { - Out string - Err error -} - -type FakeClient struct { - ActivatedShell []string - Outputs map[string]CmdResult -} - -func (fsc *FakeClient) Output(command string) (string, error) { - outerr := fsc.Outputs[command] - return outerr.Out, outerr.Err -} - -func (fsc *FakeClient) Shell(args ...string) error { - fsc.ActivatedShell = args - return nil -} - -func (fsc *FakeClient) Start(command string) (io.ReadCloser, io.ReadCloser, error) { - return nil, nil, nil -} - -func (fsc *FakeClient) Wait() error { - return nil -} diff --git a/vendor/github.com/docker/machine/libmachine/state/state.go b/vendor/github.com/docker/machine/libmachine/state/state.go deleted file mode 100644 index 385a173..0000000 --- a/vendor/github.com/docker/machine/libmachine/state/state.go +++ /dev/null @@ -1,36 +0,0 @@ -package state - -// State represents the state of a host -type State int - -const ( - None State = iota - Running - Paused - Saved - Stopped - Stopping - Starting - Error - Timeout -) - -var states = []string{ - "", - "Running", - "Paused", - "Saved", - "Stopped", - "Stopping", - "Starting", - "Error", - "Timeout", -} - -// Given a State type, returns its string representation -func (s State) String() string { - if int(s) >= 0 && int(s) < len(states) { - return states[s] - } - return "" -} diff --git a/vendor/github.com/docker/machine/libmachine/state/state_test.go b/vendor/github.com/docker/machine/libmachine/state/state_test.go deleted file mode 100644 index b53bb70..0000000 --- a/vendor/github.com/docker/machine/libmachine/state/state_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package state - -import ( - "testing" -) - -func TestDaemonCreate(t *testing.T) { - if None.String() != "" { - t.Fatal("None state should be empty string") - } - if Running.String() != "Running" { - t.Fatal("Running state should be 'Running'") - } - if Error.String() != "Error" { - t.Fatal("Error state should be 'Error'") - } -} diff --git a/vendor/github.com/docker/machine/libmachine/swarm/swarm.go b/vendor/github.com/docker/machine/libmachine/swarm/swarm.go deleted file mode 100644 index ee45288..0000000 --- a/vendor/github.com/docker/machine/libmachine/swarm/swarm.go +++ /dev/null @@ -1,22 +0,0 @@ -package swarm - -const ( - DiscoveryServiceEndpoint = "https://discovery-stage.hub.docker.com/v1" -) - -type Options struct { - IsSwarm bool - Address string - Discovery string - Agent bool - Master bool - Host string - Image string - Strategy string - Heartbeat int - Overcommit float64 - ArbitraryFlags []string - ArbitraryJoinFlags []string - Env []string - IsExperimental bool -} diff --git a/vendor/github.com/docker/machine/libmachine/version/version.go b/vendor/github.com/docker/machine/libmachine/version/version.go deleted file mode 100644 index 3cacffd..0000000 --- a/vendor/github.com/docker/machine/libmachine/version/version.go +++ /dev/null @@ -1,11 +0,0 @@ -package version - -var ( - // APIVersion dictates which version of the libmachine API this is. - APIVersion = 1 - - // ConfigVersion dictates which version of the config.json format is - // used. It needs to be bumped if there is a breaking change, and - // therefore migration, introduced to the config file format. - ConfigVersion = 3 -) diff --git a/vendor/github.com/docker/machine/libmachine/versioncmp/compare.go b/vendor/github.com/docker/machine/libmachine/versioncmp/compare.go deleted file mode 100644 index 2df82ce..0000000 --- a/vendor/github.com/docker/machine/libmachine/versioncmp/compare.go +++ /dev/null @@ -1,121 +0,0 @@ -// Package versioncmp provides functions for comparing version strings. -// -// Version strings are dot-separated integers with an optional -// pre-release suffix. A pre-release suffix is an arbitrary string with a -// leading dash character. All functions ignore these suffixes, so "1.2" and -// "1.2-rc" are considered equivalent. -package versioncmp - -import ( - "strconv" - "strings" -) - -const ( - rcString = "-rc" - ceEdition = "-ce" -) - -// compare compares two versions of Docker to decipher which came first. -// -// compare returns -1 if v1 < v2, 1 if v1 > v2, 0 otherwise. -func compare(v1, v2 string) int { - // Replace RC string with "." to make the RC number appear as simply - // another sub-version. - v1 = strings.Replace(v1, rcString, ".", -1) - v2 = strings.Replace(v2, rcString, ".", -1) - - // All releases before the community edition (differentiated by - // presence of the "ce" string in the version string) are "less than" - // any community edition release (first occurring in March 2017). - if strings.Contains(v1, ceEdition) && !strings.Contains(v2, ceEdition) { - return 1 - } - if !strings.Contains(v1, ceEdition) && strings.Contains(v2, ceEdition) { - return -1 - } - - // Without this tag, both are pre-CE versions. - if !strings.Contains(v1, ceEdition) && !strings.Contains(v2, ceEdition) { - return compareNumeric(v1, v2) - } - - return compareCE(v1, v2) -} - -// compareCE ("Community Edition") will differentiate between versions of -// Docker that use the versioning scheme -// {{release-year}}.{{release-month}}-{{ce|ee}}-{{rcnum|""}} -// -// This will be every release after 1.13.1. -func compareCE(v1, v2 string) int { - return compareNumeric( - strings.Replace(v1, ceEdition, "", -1), - strings.Replace(v2, ceEdition, "", -1), - ) -} - -// compareNumeric compares two version that use pre-17.03 Docker. -// -// Non-numeric segments in either argument are considered equal, so -// compare("1.a", "1.b") == 0, but compare("2.a", "1.b") == 1. -func compareNumeric(v1, v2 string) int { - if n := strings.IndexByte(v1, '-'); n != -1 { - v1 = v1[:n] - } - if n := strings.IndexByte(v2, '-'); n != -1 { - v2 = v2[:n] - } - var ( - currTab = strings.Split(v1, ".") - otherTab = strings.Split(v2, ".") - ) - - max := len(currTab) - if len(otherTab) > max { - max = len(otherTab) - } - for i := 0; i < max; i++ { - var currInt, otherInt int - - if len(currTab) > i { - currInt, _ = strconv.Atoi(currTab[i]) - } - if len(otherTab) > i { - otherInt, _ = strconv.Atoi(otherTab[i]) - } - if currInt > otherInt { - return 1 - } - if otherInt > currInt { - return -1 - } - } - return 0 -} - -// LessThan checks if a version is less than another. -func LessThan(v, other string) bool { - return compare(v, other) == -1 -} - -// LessThanOrEqualTo checks if a version is less than or equal to another. -func LessThanOrEqualTo(v, other string) bool { - return compare(v, other) <= 0 -} - -// GreaterThan checks if a version is greater than another. -func GreaterThan(v, other string) bool { - return compare(v, other) == 1 -} - -// GreaterThanOrEqualTo checks if a version is greater than or equal to -// another. -func GreaterThanOrEqualTo(v, other string) bool { - return compare(v, other) >= 0 -} - -// Equal checks if a version is equal to another. -func Equal(v, other string) bool { - return compare(v, other) == 0 -} diff --git a/vendor/github.com/docker/machine/libmachine/versioncmp/compare_test.go b/vendor/github.com/docker/machine/libmachine/versioncmp/compare_test.go deleted file mode 100644 index cd7a9d9..0000000 --- a/vendor/github.com/docker/machine/libmachine/versioncmp/compare_test.go +++ /dev/null @@ -1,237 +0,0 @@ -package versioncmp - -import ( - "testing" -) - -func TestCompare(t *testing.T) { - cases := []struct { - v1, v2 string - want int - }{ - {"1.12", "1.12", 0}, - {"1.0.0", "1", 0}, - {"1", "1.0.0", 0}, - {"1.05.00.0156", "1.0.221.9289", 1}, - {"1", "1.0.1", -1}, - {"1.0.1", "1", 1}, - {"1.0.1", "1.0.2", -1}, - {"1.0.2", "1.0.3", -1}, - {"1.0.3", "1.1", -1}, - {"1.1", "1.1.1", -1}, - {"1.a", "1.b", 0}, - {"1.a", "2.b", -1}, - {"1.1", "1.1.0", 0}, - {"1.1.1", "1.1.2", -1}, - {"1.1.2", "1.2", -1}, - {"1.12.1", "1.13.0-rc1", -1}, - {"1.13.0-rc1", "1.13.0-rc2", -1}, - {"1.13.0-rc1", "1.13.1-rc1", -1}, - {"17.03.0-ce", "17.03.0-ce", 0}, - {"17.03.1-ce", "17.03.2-ce", -1}, - {"17.06.6-ce", "17.09.2-ce", -1}, - {"17.03.0-ce", "17.06.0-ce", -1}, - {"17.03.0-ce-rc2", "17.03.0-ce-rc1", 1}, - {"17.03.0-ce-rc1", "18.03.0-ce-rc1", -1}, - {"17.06.0-ce-rc2", "1.12.0", 1}, - {"1.12.0", "17.06.0-ce-rc2", -1}, - } - - for _, tc := range cases { - if got := compare(tc.v1, tc.v2); got != tc.want { - t.Errorf("compare(%q, %q) == %d, want %d", tc.v1, tc.v2, got, tc.want) - } - } -} - -func TestLessThan(t *testing.T) { - cases := []struct { - v1, v2 string - want bool - }{ - {"1.12", "1.12", false}, - {"1.0.0", "1", false}, - {"1", "1.0.0", false}, - {"1.05.00.0156", "1.0.221.9289", false}, - {"1", "1.0.1", true}, - {"1.0.1", "1", false}, - {"1.0.1", "1.0.2", true}, - {"1.0.2", "1.0.3", true}, - {"1.0.3", "1.1", true}, - {"1.1", "1.1.1", true}, - {"1.a", "1.b", false}, - {"1.a", "2.b", true}, - {"1.1", "1.1.0", false}, - {"1.1.1", "1.1.2", true}, - {"1.1.2", "1.2", true}, - {"1.12.1", "1.13.0-rc1", true}, - {"1.13.0-rc1", "1.13.0-rc2", true}, - {"1.13.0-rc1", "1.13.1-rc1", true}, - {"17.03.0-ce", "17.03.0-ce", false}, - {"17.03.1-ce", "17.03.2-ce", true}, - {"17.06.6-ce", "17.09.2-ce", true}, - {"17.03.0-ce", "17.06.0-ce", true}, - {"17.03.0-ce-rc2", "17.03.0-ce-rc1", false}, - {"17.03.0-ce-rc1", "18.03.0-ce-rc1", true}, - {"17.06.0-ce", "1.12.0", false}, - } - for _, tc := range cases { - if got := LessThan(tc.v1, tc.v2); got != tc.want { - t.Errorf("LessThan(%q, %q) == %v, want %v", tc.v1, tc.v2, got, tc.want) - } - } -} - -func TestLessThanOrEqualTo(t *testing.T) { - cases := []struct { - v1, v2 string - want bool - }{ - {"1.12", "1.12", true}, - {"1.0.0", "1", true}, - {"1", "1.0.0", true}, - {"1.05.00.0156", "1.0.221.9289", false}, - {"1", "1.0.1", true}, - {"1.0.1", "1", false}, - {"1.0.1", "1.0.2", true}, - {"1.0.2", "1.0.3", true}, - {"1.0.3", "1.1", true}, - {"1.1", "1.1.1", true}, - {"1.a", "1.b", true}, - {"1.a", "2.b", true}, - {"1.1", "1.1.0", true}, - {"1.1.1", "1.1.2", true}, - {"1.1.2", "1.2", true}, - {"1.12.1", "1.13.0-rc1", true}, - {"1.13.0-rc1", "1.13.0-rc2", true}, - {"1.13.0-rc1", "1.13.1-rc1", true}, - {"17.03.0-ce", "17.03.0-ce", true}, - {"17.03.1-ce", "17.03.2-ce", true}, - {"17.06.6-ce", "17.09.2-ce", true}, - {"17.03.0-ce", "17.06.0-ce", true}, - {"17.03.0-ce-rc2", "17.03.0-ce-rc1", false}, - {"17.03.0-ce-rc1", "18.03.0-ce-rc1", true}, - {"17.06.0-ce", "1.12.0", false}, - } - for _, tc := range cases { - if got := LessThanOrEqualTo(tc.v1, tc.v2); got != tc.want { - t.Errorf("LessThanOrEqualTo(%q, %q) == %v, want %v", tc.v1, tc.v2, got, tc.want) - } - } -} - -func TestGreaterThan(t *testing.T) { - cases := []struct { - v1, v2 string - want bool - }{ - {"1.12", "1.12", false}, - {"1.0.0", "1", false}, - {"1", "1.0.0", false}, - {"1.05.00.0156", "1.0.221.9289", true}, - {"1", "1.0.1", false}, - {"1.0.1", "1", true}, - {"1.0.1", "1.0.2", false}, - {"1.0.2", "1.0.3", false}, - {"1.0.3", "1.1", false}, - {"1.1", "1.1.1", false}, - {"1.a", "1.b", false}, - {"1.a", "2.b", false}, - {"1.1", "1.1.0", false}, - {"1.1.1", "1.1.2", false}, - {"1.1.2", "1.2", false}, - {"1.12.1", "1.13.0-rc1", false}, - {"1.13.0-rc1", "1.13.0-rc2", false}, - {"1.13.0-rc1", "1.13.1-rc1", false}, - {"17.03.0-ce", "17.03.0-ce", false}, - {"17.03.1-ce", "17.03.2-ce", false}, - {"17.06.6-ce", "17.09.2-ce", false}, - {"17.03.0-ce", "17.06.0-ce", false}, - {"17.03.0-ce-rc2", "17.03.0-ce-rc1", true}, - {"17.03.0-ce-rc1", "18.03.0-ce-rc1", false}, - {"17.06.0-ce", "1.12.0", true}, - } - for _, tc := range cases { - if got := GreaterThan(tc.v1, tc.v2); got != tc.want { - t.Errorf("GreaterThan(%q, %q) == %v, want %v", tc.v1, tc.v2, got, tc.want) - } - } -} - -func TestGreaterThanOrEqualTo(t *testing.T) { - cases := []struct { - v1, v2 string - want bool - }{ - {"1.12", "1.12", true}, - {"1.0.0", "1", true}, - {"1", "1.0.0", true}, - {"1.05.00.0156", "1.0.221.9289", true}, - {"1", "1.0.1", false}, - {"1.0.1", "1", true}, - {"1.0.1", "1.0.2", false}, - {"1.0.2", "1.0.3", false}, - {"1.0.3", "1.1", false}, - {"1.1", "1.1.1", false}, - {"1.a", "1.b", true}, - {"1.a", "2.b", false}, - {"1.1", "1.1.0", true}, - {"1.1.1", "1.1.2", false}, - {"1.1.2", "1.2", false}, - {"1.12.1", "1.13.0-rc1", false}, - {"1.13.0-rc1", "1.13.0-rc2", false}, - {"1.13.0-rc1", "1.13.1-rc1", false}, - {"17.03.0-ce", "17.03.0-ce", true}, - {"17.03.1-ce", "17.03.2-ce", false}, - {"17.06.6-ce", "17.09.2-ce", false}, - {"17.03.0-ce", "17.06.0-ce", false}, - {"17.03.0-ce-rc2", "17.03.0-ce-rc1", true}, - {"17.03.0-ce-rc1", "18.03.0-ce-rc1", false}, - {"17.06.0-ce", "1.12.0", true}, - } - for _, tc := range cases { - if got := GreaterThanOrEqualTo(tc.v1, tc.v2); got != tc.want { - t.Errorf("GreaterThanOrEqualTo(%q, %q) == %v, want %v", tc.v1, tc.v2, got, tc.want) - } - } -} - -func TestEqual(t *testing.T) { - cases := []struct { - v1, v2 string - want bool - }{ - {"1.12", "1.12", true}, - {"1.0.0", "1", true}, - {"1", "1.0.0", true}, - {"1.05.00.0156", "1.0.221.9289", false}, - {"1", "1.0.1", false}, - {"1.0.1", "1", false}, - {"1.0.1", "1.0.2", false}, - {"1.0.2", "1.0.3", false}, - {"1.0.3", "1.1", false}, - {"1.1", "1.1.1", false}, - {"1.a", "1.b", true}, - {"1.a", "2.b", false}, - {"1.1", "1.1.0", true}, - {"1.1.1", "1.1.2", false}, - {"1.1.2", "1.2", false}, - {"1.12.1", "1.13.0-rc1", false}, - {"1.13.0-rc1", "1.13.0-rc2", false}, - {"1.13.0-rc1", "1.13.1-rc1", false}, - {"17.03.0-ce", "17.03.0-ce", true}, - {"17.03.1-ce", "17.03.2-ce", false}, - {"17.06.6-ce", "17.09.2-ce", false}, - {"17.03.0-ce", "17.06.0-ce", false}, - {"17.03.0-ce-rc2", "17.03.0-ce-rc1", false}, - {"17.03.0-ce-rc1", "18.03.0-ce-rc1", false}, - {"17.06.0-ce-rc2", "1.12.0", false}, - {"1.12.0", "17.06.0-ce-rc2", false}, - {"17.06.0-ce", "1.12.0", false}, - } - for _, tc := range cases { - if got := Equal(tc.v1, tc.v2); got != tc.want { - t.Errorf("Equal(%q, %q) == %v, want %v", tc.v1, tc.v2, got, tc.want) - } - } -} diff --git a/vendor/github.com/docker/machine/mk/build.mk b/vendor/github.com/docker/machine/mk/build.mk deleted file mode 100644 index adbe6a6..0000000 --- a/vendor/github.com/docker/machine/mk/build.mk +++ /dev/null @@ -1,36 +0,0 @@ -extension = $(patsubst windows,.exe,$(filter windows,$(1))) - -# Valid target combinations -VALID_OS_ARCH := "[darwin/amd64][linux/amd64][linux/arm][linux/arm64][windows/amd64][windows/386]" - -os.darwin := Darwin -os.linux := Linux -os.windows := Windows - -arch.amd64 := x86_64 -arch.arm := armhf -arch.arm64 := aarch64 -arch.386 := i386 - -define gocross - $(if $(findstring [$(1)/$(2)],$(VALID_OS_ARCH)), \ - GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 \ - $(GO) build \ - -o $(PREFIX)/bin/$(PKG_NAME)-${os.$(1)}-${arch.$(2)}$(call extension,$(GOOS)) \ - -a $(VERBOSE_GO) -tags "static_build netgo $(BUILDTAGS)" -installsuffix netgo \ - -ldflags "$(GO_LDFLAGS) -extldflags -static" $(GO_GCFLAGS) ./cmd/machine.go;) -endef - -build-clean: - rm -Rf $(PREFIX)/bin/* - -build-x: $(shell find . -type f -name '*.go') - $(foreach GOARCH,$(TARGET_ARCH),$(foreach GOOS,$(TARGET_OS),$(call gocross,$(GOOS),$(GOARCH)))) - -$(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)): $(shell find . -type f -name '*.go') - $(GO) build \ - -o $@ \ - $(VERBOSE_GO) -tags "$(BUILDTAGS)" \ - -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) ./cmd/machine.go - -build: $(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)) diff --git a/vendor/github.com/docker/machine/mk/coverage.mk b/vendor/github.com/docker/machine/mk/coverage.mk deleted file mode 100644 index 9e18ada..0000000 --- a/vendor/github.com/docker/machine/mk/coverage.mk +++ /dev/null @@ -1,45 +0,0 @@ -# COVERAGE_OUTPUT dir is a temp dir (OSX/Linux compatible), unless explicitly specified through env COVERAGE_DIR -COVERAGE_OUTPUT := $(COVERAGE_DIR) -ifeq ($(COVERAGE_OUTPUT),) - COVERAGE_OUTPUT := $(shell mktemp -d 2>/dev/null || mktemp -d -t machine-coverage) -endif - -# Final cover file, html, and mode -COVERAGE_PROFILE := $(COVERAGE_OUTPUT)/profile.out -COVERAGE_HTML := $(COVERAGE_OUTPUT)/index.html -COVERAGE_MODE := set - -# Goveralls dependency -GOVERALLS_BIN := $(GOPATH)/bin/goveralls -GOVERALLS := $(shell [ -x $(GOVERALLS_BIN) ] && echo $(GOVERALLS_BIN) || echo '') - -# Generate coverage -coverage-generate: $(COVERAGE_PROFILE) - -# Send the results to coveralls -coverage-send: $(COVERAGE_PROFILE) - $(if $(GOVERALLS), , $(error Please install goveralls: go get github.com/mattn/goveralls)) - @$(GOVERALLS) -service travis-ci -coverprofile="$(COVERAGE_PROFILE)" - -# Generate html report -coverage-html: $(COVERAGE_HTML) - @open "$(COVERAGE_HTML)" - -# Serve over http - useful only if building remote/headless -coverage-serve: $(COVERAGE_HTML) - @cd "$(COVERAGE_OUTPUT)" && python -m SimpleHTTPServer 8000 - -# Clean up coverage coverage output -coverage-clean: - @rm -Rf "$(COVERAGE_OUTPUT)/coverage" - @rm -f "$(COVERAGE_HTML)" - @rm -f "$(COVERAGE_PROFILE)" - -$(COVERAGE_PROFILE): $(shell find . -type f -name '*.go') - @mkdir -p "$(COVERAGE_OUTPUT)/coverage" - @$(foreach PKG,$(PKGS), go test $(VERBOSE_GO) -tags "$(BUILDTAGS)" -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_OUTPUT)/coverage/`echo $(PKG) | tr "/" "-"`.cover" "$(PKG)";) - @echo "mode: $(COVERAGE_MODE)" > "$(COVERAGE_PROFILE)" - @grep -h -v "^mode:" "$(COVERAGE_OUTPUT)/coverage"/*.cover >> "$(COVERAGE_PROFILE)" - -$(COVERAGE_HTML): $(COVERAGE_PROFILE) - $(GO) tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_HTML)" diff --git a/vendor/github.com/docker/machine/mk/dev.mk b/vendor/github.com/docker/machine/mk/dev.mk deleted file mode 100644 index 8f19b80..0000000 --- a/vendor/github.com/docker/machine/mk/dev.mk +++ /dev/null @@ -1,9 +0,0 @@ -dep-save: - $(if $(GODEP), , \ - $(error Please install godep: go get github.com/tools/godep)) - $(GODEP) save $(shell go list ./... | grep -v vendor/) - -dep-restore: - $(if $(GODEP), , \ - $(error Please install godep: go get github.com/tools/godep)) - $(GODEP) restore -v diff --git a/vendor/github.com/docker/machine/mk/main.mk b/vendor/github.com/docker/machine/mk/main.mk deleted file mode 100644 index 28f85d2..0000000 --- a/vendor/github.com/docker/machine/mk/main.mk +++ /dev/null @@ -1,58 +0,0 @@ -# Initialize version and gc flags -GO_LDFLAGS := -X `go list ./version`.GitCommit=`git rev-parse --short HEAD 2>/dev/null` -GO_GCFLAGS := - -# Full package list -PKGS := $(shell go list -tags "$(BUILDTAGS)" ./... | grep -v "/vendor/" | grep -v "/cmd") - -# Resolving binary dependencies for specific targets -GOLINT_BIN := $(GOPATH)/bin/golint -GOLINT := $(shell [ -x $(GOLINT_BIN) ] && echo $(GOLINT_BIN) || echo '') - -GODEP_BIN := $(GOPATH)/bin/godep -GODEP := $(shell [ -x $(GODEP_BIN) ] && echo $(GODEP_BIN) || echo '') - -# Honor debug -ifeq ($(DEBUG),true) - # Disable function inlining and variable registerization - GO_GCFLAGS := -gcflags "-N -l" -else - # Turn of DWARF debugging information and strip the binary otherwise - GO_LDFLAGS := $(GO_LDFLAGS) -w -s -endif - -# Honor static -ifeq ($(STATIC),true) - # Append to the version - GO_LDFLAGS := $(GO_LDFLAGS) -extldflags -static -endif - -# Honor verbose -VERBOSE_GO := -GO := go -ifeq ($(VERBOSE),true) - VERBOSE_GO := -v -endif - -include mk/build.mk -include mk/coverage.mk -include mk/dev.mk -include mk/test.mk -include mk/validate.mk - -.all_build: build build-clean build-x -.all_coverage: coverage-generate coverage-html coverage-send coverage-serve coverage-clean -.all_release: release-checksum release -.all_test: test-short test-long test-integration -.all_validate: dco fmt vet lint - -default: build - -install: - cp $(PREFIX)/bin/$(PKG_NAME) /usr/local/bin - -clean: coverage-clean build-clean -test: dco fmt test-short lint vet -validate: dco fmt lint vet test-long - -.PHONY: .all_build .all_coverage .all_release .all_test .all_validate test build validate clean diff --git a/vendor/github.com/docker/machine/mk/test.mk b/vendor/github.com/docker/machine/mk/test.mk deleted file mode 100644 index c0c9df9..0000000 --- a/vendor/github.com/docker/machine/mk/test.mk +++ /dev/null @@ -1,11 +0,0 @@ -# Quick test. You can bypass long tests using: `if testing.Short() { t.Skip("Skipping in short mode.") }` -test-short: - $(GO) test $(VERBOSE_GO) -test.short -tags "$(BUILDTAGS)" $(PKGS) - -# Runs long tests also, plus race detection -test-long: - $(GO) test $(VERBOSE_GO) -race -tags "$(BUILDTAGS)" $(PKGS) - -test-integration: build - $(eval TESTSUITE=$(filter-out $@,$(MAKECMDGOALS))) - test/integration/run-bats.sh $(TESTSUITE) diff --git a/vendor/github.com/docker/machine/mk/validate.mk b/vendor/github.com/docker/machine/mk/validate.mk deleted file mode 100644 index fac20cb..0000000 --- a/vendor/github.com/docker/machine/mk/validate.mk +++ /dev/null @@ -1,20 +0,0 @@ -# Validate DCO on all history -mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) -current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path)))) - -# XXX vendorized script miss exec bit, hence the gymnastic -# plus the path resolution... -# TODO migrate away from the shell script and have a make equivalent instead -dco: - @echo `bash $(current_dir)/../script/validate-dco` - -fmt: - @test -z "$$(gofmt -s -l . 2>&1 | grep -v vendor/ | tee /dev/stderr)" - -vet: - @test -z "$$(go vet $(PKGS) 2>&1 | tee /dev/stderr)" - -lint: - $(if $(GOLINT), , \ - $(error Please install golint: go get -u github.com/golang/lint/golint)) - @test -z "$$($(GOLINT) ./... 2>&1 | grep -v vendor/ | grep -v "cli/" | grep -v "amazonec2/" |grep -v "openstack/" |grep -v "softlayer/" | grep -v "should have comment" | tee /dev/stderr)" diff --git a/vendor/github.com/docker/machine/script/.validate b/vendor/github.com/docker/machine/script/.validate deleted file mode 100644 index fd52677..0000000 --- a/vendor/github.com/docker/machine/script/.validate +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -if [ -z "$VALIDATE_UPSTREAM" ]; then - # this is kind of an expensive check, so let's not do this twice if we - # are running more than one validate bundlescript - - VALIDATE_REPO='https://github.com/docker/machine.git' - VALIDATE_BRANCH='master' - - if [ "$TRAVIS" = 'true' -a "$TRAVIS_PULL_REQUEST" != 'false' ]; then - VALIDATE_REPO="https://github.com/${TRAVIS_REPO_SLUG}.git" - VALIDATE_BRANCH="${TRAVIS_BRANCH}" - fi - - VALIDATE_HEAD="$(git rev-parse --verify HEAD)" - - git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH" - VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)" - - VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD" - VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD" - - validate_diff() { - if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then - git diff "$VALIDATE_COMMIT_DIFF" "$@" - fi - } - validate_log() { - if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then - git log "$VALIDATE_COMMIT_LOG" "$@" - fi - } -fi diff --git a/vendor/github.com/docker/machine/script/build_in_container.sh b/vendor/github.com/docker/machine/script/build_in_container.sh deleted file mode 100755 index 130bb84..0000000 --- a/vendor/github.com/docker/machine/script/build_in_container.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -set -e - -DOCKER_IMAGE_NAME="docker-machine-build" -DOCKER_CONTAINER_NAME="docker-machine-build-container" - -if [[ $(docker ps -a | grep $DOCKER_CONTAINER_NAME) != "" ]]; then - docker rm -f $DOCKER_CONTAINER_NAME 2>/dev/null -fi - -docker build -t $DOCKER_IMAGE_NAME . - -docker run --name $DOCKER_CONTAINER_NAME \ - -e DEBUG \ - -e STATIC \ - -e VERBOSE \ - -e BUILDTAGS \ - -e PARALLEL \ - -e COVERAGE_DIR \ - -e TARGET_OS \ - -e TARGET_ARCH \ - -e PREFIX \ - -e TRAVIS_JOB_ID \ - -e TRAVIS_PULL_REQUEST \ - $DOCKER_IMAGE_NAME \ - make "$@" - -if [[ "$@" == *"clean"* ]] && [[ -d bin ]]; then - rm -Rf bin -fi - -docker cp $DOCKER_CONTAINER_NAME:/go/src/github.com/docker/machine/bin . diff --git a/vendor/github.com/docker/machine/script/release.sh b/vendor/github.com/docker/machine/script/release.sh deleted file mode 100755 index e937b8c..0000000 --- a/vendor/github.com/docker/machine/script/release.sh +++ /dev/null @@ -1,260 +0,0 @@ -#!/bin/bash - -GITHUB_USER=docker -GITHUB_REPO=machine -PROJECT_URL="git@github.com:${GITHUB_USER}/${GITHUB_REPO}" - -function usage { - echo "Usage: " - echo " GITHUB_TOKEN=XXXXX ${0} [X.Y.Z]" -} - -function display { - echo "🐳 $1" - echo -} - -function checkError { - if [[ "$?" -ne 0 ]]; then - echo "😡 $1" - exit 1 - fi -} - -function createMachine { - docker-machine rm -f release 2> /dev/null - docker-machine create -d virtualbox --virtualbox-cpu-count=2 --virtualbox-memory=2048 release -} - -if [[ -z "${GITHUB_TOKEN}" ]]; then - echo "GITHUB_TOKEN missing" - usage - exit 1 -fi - -VERSION=$1 - -if [[ -z "${VERSION}" ]]; then - echo "Missing version argument" - usage - exit 1 -fi - -if [[ ! "${VERSION}" =~ ^[0-9]\.[0-9]+(\.[0-9])+(-rc[1-9][0-9]*)?$ ]]; then - echo "Invalid version. It should look like 0.5.1, 0.6 or 0.5.1-rc2" - exit 1 -fi - -command -v git > /dev/null 2>&1 -checkError "You obviously need git, please consider installing it..." - -command -v github-release > /dev/null 2>&1 -checkError "github-release is not installed, go get -u github.com/aktau/github-release or check https://github.com/aktau/github-release, aborting." - -command -v openssl > /dev/null 2>&1 -checkError "You need openssl to generate binaries signature, brew install it, aborting." - -command -v docker-machine > /dev/null 2>&1 -checkError "You must have a docker-machine in your path" - -GITHUB_VERSION="v${VERSION}" -RELEASE_DIR="$(dirname "$(git rev-parse --show-toplevel)")/release-${VERSION}" -GITHUB_RELEASE_FILE="github-release-${VERSION}.md" - -LAST_RELEASE_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1)) -checkError "Unable to find current version tag" - -display "Starting release from ${LAST_RELEASE_VERSION} to ${GITHUB_VERSION} on ${PROJECT_URL} with token ${GITHUB_TOKEN}" -if [[ "${GITHUB_USER}" == "docker" ]]; then - display "THIS IS A REAL RELEASE, on OFFICIAL DOCKER REPO" -fi -while true; do - read -p "🐳 Do you want to proceed with this release? (y/n) > " yn - echo "" - case $yn in - [Yy]* ) break;; - [Nn]* ) exit;; - * ) echo "😡 Please answer yes or no.";; - esac -done - -display "Checking machine 'release' status" -MACHINE_STATUS=$(docker-machine status release) -if [[ "$?" -ne 0 ]]; then - display "Machine 'release' does not exist, creating it" - createMachine -else - if [[ "${MACHINE_STATUS}" != "Running" ]]; then - display "Machine 'release' is not running, trying to start it" - docker-machine start release - docker-machine env release - if [[ "$?" -ne 0 ]]; then - display "Machine 'release' could not be started, removing and creating a fresh new one" - createMachine - fi - display "Loosing 5 seconds to the VirtualBox gods" - sleep 5 - fi -fi - -eval "$(docker-machine env release)" -checkError "Machine 'release' is in a weird state, aborting" - -if [[ -d "${RELEASE_DIR}" ]]; then - display "Cleaning up ${RELEASE_DIR}" - rm -rdf "${RELEASE_DIR}" - checkError "Can't clean up ${RELEASE_DIR}. You should do it manually and retry" -fi - -display "Cloning into ${RELEASE_DIR} from ${PROJECT_URL}" - -mkdir -p "${RELEASE_DIR}" -checkError "Can't create ${RELEASE_DIR}, aborting" -git clone -q "${PROJECT_URL}" "${RELEASE_DIR}" -checkError "Can't clone into ${RELEASE_DIR}, aborting" - -cd "${RELEASE_DIR}" - -display "Bump version number to ${VERSION}" - -# Why 'sed' and then 'mv' instead of 'sed -i'? BSD / GNU sed compatibility. -# Macs have BSD sed by default, Linux has GNU sed. See -# http://unix.stackexchange.com/questions/92895/how-to-achieve-portability-with-sed-i-in-place-editing -sed -e "s/Version = \".*\"$/Version = \"${VERSION}\"/g" version/version.go >version/version.go.new -checkError "Unable to change version in version/version.go" -mv -- version/version.go.new version/version.go - -git add version/version.go -git commit -q -m"Bump version to ${VERSION}" -s -checkError "Can't git commit the version upgrade, aborting" - -display "Building in-container style" -USE_CONTAINER=true make clean build validate build-x -checkError "Build error, aborting" - -display "Generating github release" -cp -f script/release/github-release-template.md "${GITHUB_RELEASE_FILE}" -checkError "Can't find github release template" -CONTRIBUTORS=$(git log "${LAST_RELEASE_VERSION}".. --format="%aN" --reverse | sort | uniq | awk '{printf "- %s\n", $0 }') -CHANGELOG=$(git log "${LAST_RELEASE_VERSION}".. --oneline | grep -v 'Merge pull request') - -CHECKSUM="" -rm -f sha256sum.txt md5sum.txt -for file in $(ls bin/docker-machine-*); do - SHA256=$(openssl dgst -sha256 < "${file}") - MD5=$(openssl dgst -md5 < "${file}") - LINE=$(printf "\n * **%s**\n * sha256 \`%s\`\n * md5 \`%s\`\n\n" "$(basename ${file})" "${SHA256}" "${MD5}") - CHECKSUM="${CHECKSUM}${LINE}" - echo "${SHA256} ${file:4}" >> sha256sum.txt - echo "${MD5} ${file:4}" >> md5sum.txt -done - -TEMPLATE=$(cat "${GITHUB_RELEASE_FILE}") -echo "${TEMPLATE//\{\{VERSION\}\}/$GITHUB_VERSION}" > "${GITHUB_RELEASE_FILE}" -checkError "Couldn't replace [ ${GITHUB_VERSION} ]" - -TEMPLATE=$(cat "${GITHUB_RELEASE_FILE}") -echo "${TEMPLATE//\{\{CHANGELOG\}\}/$CHANGELOG}" > "${GITHUB_RELEASE_FILE}" -checkError "Couldn't replace [ ${CHANGELOG} ]" - -TEMPLATE=$(cat "${GITHUB_RELEASE_FILE}") -echo "${TEMPLATE//\{\{CONTRIBUTORS\}\}/$CONTRIBUTORS}" > "${GITHUB_RELEASE_FILE}" -checkError "Couldn't replace [ ${CONTRIBUTORS} ]" - -TEMPLATE=$(cat "${GITHUB_RELEASE_FILE}") -echo "${TEMPLATE//\{\{CHECKSUM\}\}/$CHECKSUM}" > "${GITHUB_RELEASE_FILE}" -checkError "Couldn't replace [ ${CHECKSUM} ]" - -RELEASE_DOCUMENTATION="$(cat ${GITHUB_RELEASE_FILE})" - -display "Tagging and pushing tags" -git remote | grep -q remote.prod.url -if [[ "$?" -ne 0 ]]; then - display "Adding 'remote.prod.url' remote git url" - git remote add remote.prod.url "${PROJECT_URL}" -fi - -display "Checking if remote tag ${GITHUB_VERSION} already exists" -git ls-remote --tags 2> /dev/null | grep -q "${GITHUB_VERSION}" # returns 0 if found, 1 if not -if [[ "$?" -ne 1 ]]; then - display "Deleting previous tag ${GITHUB_VERSION}" - git tag -d "${GITHUB_VERSION}" &> /dev/null - git push -q origin :refs/tags/"${GITHUB_VERSION}" -else - echo "Tag ${GITHUB_VERSION} does not exist... yet" -fi - -display "Tagging release on github" -git tag "${GITHUB_VERSION}" -git push -q remote.prod.url "${GITHUB_VERSION}" -checkError "Could not push to remote url" - -display "Checking if release already exists" -github-release info \ - --security-token "${GITHUB_TOKEN}" \ - --user "${GITHUB_USER}" \ - --repo "${GITHUB_REPO}" \ - --tag "${GITHUB_VERSION}" > /dev/null 2>&1 - -if [[ "$?" -ne 1 ]]; then - display "Release already exists, cleaning it up" - github-release delete \ - --security-token "${GITHUB_TOKEN}" \ - --user "${GITHUB_USER}" \ - --repo "${GITHUB_REPO}" \ - --tag "${GITHUB_VERSION}" - checkError "Could not delete release, aborting" -fi - -display "Creating release on github" -github-release release \ - --security-token "${GITHUB_TOKEN}" \ - --user "${GITHUB_USER}" \ - --repo "${GITHUB_REPO}" \ - --tag "${GITHUB_VERSION}" \ - --name "${GITHUB_VERSION}" \ - --description "${RELEASE_DOCUMENTATION}" \ - --pre-release -checkError "Could not create release, aborting" - -display "Uploading binaries" -for file in $(ls bin/docker-machine-*); do - display "Uploading ${file}..." - github-release upload \ - --security-token "${GITHUB_TOKEN}" \ - --user "${GITHUB_USER}" \ - --repo "${GITHUB_REPO}" \ - --tag "${GITHUB_VERSION}" \ - --name "$(basename "${file}")" \ - --file "${file}" - if [[ "$?" -ne 0 ]]; then - display "Could not upload ${file}, continuing with others" - fi -done - -display "Uploading sha256sum.txt and md5sum.txt" -for file in sha256sum.txt md5sum.txt; do - display "Uploading ${file}..." - github-release upload \ - --security-token "${GITHUB_TOKEN}" \ - --user "${GITHUB_USER}" \ - --repo "${GITHUB_REPO}" \ - --tag "${GITHUB_VERSION}" \ - --name "$(basename "${file}")" \ - --file "${file}" - if [[ "$?" -ne 0 ]]; then - display "Could not upload ${file}, continuing with others" - fi -done - -git remote rm remote.prod.url - -rm ${GITHUB_RELEASE_FILE} - -echo "There is a couple of tasks your still need to do manually:" -echo " 1. Open the release notes created for you on github https://github.com/${GITHUB_USER}/${GITHUB_REPO}/releases/tag/${GITHUB_VERSION}, you'll have a chance to enhance commit details a bit" -echo " 2. Once you're happy with your release notes on github, copy the list of changes to the CHANGELOG.md" -echo " 3. Update the documentation branch" -echo " 4. Test the binaries linked from the github release page" -echo " 5. Change version/version.go to the next dev version" -echo " 6. Party !!" diff --git a/vendor/github.com/docker/machine/script/release/github-release-template.md b/vendor/github.com/docker/machine/script/release/github-release-template.md deleted file mode 100644 index 3c7051f..0000000 --- a/vendor/github.com/docker/machine/script/release/github-release-template.md +++ /dev/null @@ -1,49 +0,0 @@ -## Installation - -If you're a Mac or Windows user, the [Docker Toolbox](https://www.docker.com/docker-toolbox) will install Docker Machine {{VERSION}} for you, alongside the latest versions of the Docker Engine, Compose and Kitematic. - -You can use the usual commands to install or upgrade: - -On OS X -```console -$ curl -L https://github.com/docker/machine/releases/download/{{VERSION}}/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine && \ - chmod +x /usr/local/bin/docker-machine -``` -On Linux -```console -$ curl -L https://github.com/docker/machine/releases/download/{{VERSION}}/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && - chmod +x /tmp/docker-machine && - sudo cp /tmp/docker-machine /usr/local/bin/docker-machine -``` -On Windows with git bash -```console -$ if [[ ! -d "$HOME/bin" ]]; then mkdir -p "$HOME/bin"; fi && \ -curl -L https://github.com/docker/machine/releases/download/{{VERSION}}/docker-machine-Windows-x86_64.exe > "$HOME/bin/docker-machine.exe" && \ -chmod +x "$HOME/bin/docker-machine.exe" -``` - -Otherwise, download one of the releases from the [release page](https://github.com/docker/machine/releases/) directly. - -See the install [docs](https://docs.docker.com/machine/install-machine/) for more install options and instructions. - -## Changelog - -*Edit the changelog below by hand* - -{{CHANGELOG}} - -## Thank You - -Thank you very much to our active users and contributors. If you have filed detailed bug reports, THANK YOU! -Please continue to do so if you encounter any issues. It's your hard work that makes Docker Machine better. - -The following authors contributed changes to this release: - -{{CONTRIBUTORS}} - -Great thanks to all of the above! We appreciate it. Keep up the great work! - -## Checksums - -{{CHECKSUM}} - diff --git a/vendor/github.com/docker/machine/script/validate-dco b/vendor/github.com/docker/machine/script/validate-dco deleted file mode 100755 index 1c75d91..0000000 --- a/vendor/github.com/docker/machine/script/validate-dco +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -source "$(dirname "$BASH_SOURCE")/.validate" - -adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }') -dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }') -notDocs="$(validate_diff --numstat | awk '$3 !~ /^docs\// { print $3 }')" - -: ${adds:=0} -: ${dels:=0} - -# "Username may only contain alphanumeric characters or dashes and cannot begin with a dash" -githubUsernameRegex='[a-zA-Z0-9][a-zA-Z0-9-]+' - -# https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work -dcoPrefix='Signed-off-by:' -dcoRegex="^(Docker-DCO-1.1-)?$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)>( \\(github: ($githubUsernameRegex)\\))?$" - -check_dco() { - grep -qE "$dcoRegex" -} - -if [ $adds -eq 0 -a $dels -eq 0 ]; then - echo '0 adds, 0 deletions; nothing to validate! :)' -elif [ -z "$notDocs" -a $adds -le 1 -a $dels -le 1 ]; then - echo 'Congratulations! DCO small-patch-exception material!' -else - commits=( $(validate_log --format='format:%H%n') ) - badCommits=() - for commit in "${commits[@]}"; do - if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then - # no content (ie, Merge commit, etc) - continue - fi - if ! git log -1 --format='format:%B' "$commit" | check_dco; then - badCommits+=( "$commit" ) - fi - done - if [ ${#badCommits[@]} -eq 0 ]; then - echo "Congratulations! All commits are properly signed with the DCO!" - else - { - echo "These commits do not have a proper '$dcoPrefix' marker:" - for commit in "${badCommits[@]}"; do - echo " - $commit" - done - echo - echo 'Please amend each commit to include a properly formatted DCO marker.' - echo - echo 'Visit the following URL for information about the Docker DCO:' - echo ' https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work' - echo - } >&2 - false - fi -fi diff --git a/vendor/github.com/docker/machine/test/integration/.gitignore b/vendor/github.com/docker/machine/test/integration/.gitignore deleted file mode 100644 index 9bb348e..0000000 --- a/vendor/github.com/docker/machine/test/integration/.gitignore +++ /dev/null @@ -1 +0,0 @@ -env-* diff --git a/vendor/github.com/docker/machine/test/integration/amazonec2/amazon.bats b/vendor/github.com/docker/machine/test/integration/amazonec2/amazon.bats deleted file mode 100644 index 2801943..0000000 --- a/vendor/github.com/docker/machine/test/integration/amazonec2/amazon.bats +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER amazonec2 - -use_disposable_machine - -require_env AWS_ACCESS_KEY_ID -require_env AWS_SECRET_ACCESS_KEY - -@test "$DRIVER: Should Create a default host" { - run machine create -d amazonec2 $NAME - echo ${output} - [ "$status" -eq 0 ] -} diff --git a/vendor/github.com/docker/machine/test/integration/amazonec2/create-ebsinstance.bats b/vendor/github.com/docker/machine/test/integration/amazonec2/create-ebsinstance.bats deleted file mode 100644 index 2b2661b..0000000 --- a/vendor/github.com/docker/machine/test/integration/amazonec2/create-ebsinstance.bats +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER amazonec2 - -use_disposable_machine - -require_env AWS_ACCESS_KEY_ID -require_env AWS_SECRET_ACCESS_KEY -require_env AWS_VPC_ID - -require_env AWS_DEFAULT_REGION -require_env AWS_ZONE - -@test "$DRIVER: Should Create an EBS Optimized Instance" { - #Use Instance Type that supports EBS Optimize - run machine create -d amazonec2 --amazonec2-instance-type=m4.large --amazonec2-use-ebs-optimized-instance $NAME - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: Check the machine is up" { - run docker $(machine config $NAME) run --rm -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION -e AWS_ZONE=$AWS_ZONE -e AWS_VPC_ID=$AWS_VPC_ID blendle/aws-cli ec2 describe-instances --filters Name=tag:Name,Values=$NAME Name=instance-state-name,Values=running --query 'Reservations[0].Instances[0].EbsOptimized' --output text - echo ${output} - [[ ${lines[*]:-1} =~ "True" ]] -} \ No newline at end of file diff --git a/vendor/github.com/docker/machine/test/integration/amazonec2/createwithkeypair.bats b/vendor/github.com/docker/machine/test/integration/amazonec2/createwithkeypair.bats deleted file mode 100644 index c62486c..0000000 --- a/vendor/github.com/docker/machine/test/integration/amazonec2/createwithkeypair.bats +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER amazonec2 - -use_disposable_machine - -require_env AWS_ACCESS_KEY_ID - -require_env AWS_SECRET_ACCESS_KEY - -export AWS_SSH_DIR="$MACHINE_STORAGE_PATH/mcnkeys" - -export AWS_SSH_KEYPATH=$AWS_SSH_DIR/id_rsa - -@test "$DRIVER: Should Create Instance with Pre existing SSH Key" { - - mkdir -p $AWS_SSH_DIR - - run ssh-keygen -f $AWS_SSH_KEYPATH -t rsa -N '' - - machine create -d amazonec2 $NAME - - run diff $AWS_SSH_KEYPATH $MACHINE_STORAGE_PATH/machines/$NAME/id_rsa - [[ $output == "" ]] - - run diff $AWS_SSH_KEYPATH.pub $MACHINE_STORAGE_PATH/machines/$NAME/id_rsa.pub - [[ $output == "" ]] - - -} \ No newline at end of file diff --git a/vendor/github.com/docker/machine/test/integration/core/certs-extra-san.bats b/vendor/github.com/docker/machine/test/integration/core/certs-extra-san.bats deleted file mode 100644 index 0e91d78..0000000 --- a/vendor/github.com/docker/machine/test/integration/core/certs-extra-san.bats +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -use_disposable_machine - -@test "$DRIVER: create" { - run machine create --tls-san foo.bar.tld --tls-san 10.42.42.42 -d $DRIVER $NAME - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: verify that server cert contains the extra SANs" { - machine ssh $NAME -- openssl x509 -in /var/lib/boot2docker/server.pem -text | grep 'DNS:foo.bar.tld' - machine ssh $NAME -- openssl x509 -in /var/lib/boot2docker/server.pem -text | grep 'IP Address:10.42.42.42' -} - -@test "$DRIVER: verify that server cert SANs are still there after 'regenerate-certs'" { - machine regenerate-certs -f $NAME - machine ssh $NAME -- openssl x509 -in /var/lib/boot2docker/server.pem -text | grep 'DNS:foo.bar.tld' - machine ssh $NAME -- openssl x509 -in /var/lib/boot2docker/server.pem -text | grep 'IP Address:10.42.42.42' -} diff --git a/vendor/github.com/docker/machine/test/integration/core/core-commands.bats b/vendor/github.com/docker/machine/test/integration/core/core-commands.bats deleted file mode 100644 index ba96456..0000000 --- a/vendor/github.com/docker/machine/test/integration/core/core-commands.bats +++ /dev/null @@ -1,155 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -use_shared_machine - -@test "$DRIVER: machine should not exist" { - run machine inspect UNKNOWN - echo ${output} - [ "$status" -eq 1 ] - [[ ${lines[0]} =~ "Host does not exist: \"UNKNOWN\"" ]] -} - -@test "$DRIVER: appears with ls" { - run machine ls -q - echo ${output} - [ "$status" -eq 0 ] - [[ ${lines[0]} == "$NAME" ]] -} - -@test "$DRIVER: has status 'started' appearing in ls" { - run machine ls -q --filter state=Running - echo ${output} - [ "$status" -eq 0 ] - [[ ${lines[0]} == "$NAME" ]] -} - -@test "$DRIVER: create with same name again fails" { - run machine create -d $DRIVER $NAME - echo ${output} - [ "$status" -eq 1 ] - [[ ${lines[0]} == "Host already exists: \"$NAME\"" ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - echo ${output} - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: version" { - run machine version $NAME - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: docker commands with the socket should work" { - run machine ssh $NAME -- sudo docker version - echo ${output} -} - -@test "$DRIVER: stop" { - run machine stop $NAME - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after stop" { - run machine ls - echo ${output} - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: url should show an error when machine is stopped" { - run machine url $NAME - echo ${output} - [ "$status" -eq 1 ] - [[ ${output} == *"Host is not running"* ]] -} - -@test "$DRIVER: env should show an error when machine is stopped" { - run machine env $NAME - echo ${output} - [ "$status" -eq 1 ] - [[ ${output} == *"Host is not running"* ]] -} - -@test "$DRIVER: version should show an error when machine is stopped" { - run machine version $NAME - echo ${output} - [ "$status" -eq 1 ] - [[ ${output} == *"Host is not running"* ]] -} - -@test "$DRIVER: machine should upgrade even when machine is stopped" { - run machine upgrade $NAME - echo ${output} - [[ "$status" -eq 0 ]] -} - -@test "$DRIVER: start should show an error after upgrade" { - run machine start $NAME - echo ${output} - [ "$status" -eq 1 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls --timeout 20 - echo ${output} - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: kill" { - run machine kill $NAME - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after kill" { - run machine ls - echo ${output} - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls --timeout 20 - echo ${output} - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: status" { - run machine status $NAME - echo ${output} - [ "$status" -eq 0 ] - [[ ${output} == *"Running"* ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/core/crashreport.bats b/vendor/github.com/docker/machine/test/integration/core/crashreport.bats deleted file mode 100644 index bbc9184..0000000 --- a/vendor/github.com/docker/machine/test/integration/core/crashreport.bats +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER virtualbox - -use_disposable_machine - -@test "$DRIVER: should send bugsnag report" { - # we exploit a 'bug' where vboxmanage wont allow a machine created with 1mb of RAM - run machine --bugsnag-api-token nonexisting -D create -d virtualbox --virtualbox-memory 1 $NAME - echo ${output} - [ "$status" -eq 1 ] - [[ ${output} == *"notifying bugsnag"* ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/core/engine-options.bats b/vendor/github.com/docker/machine/test/integration/core/engine-options.bats deleted file mode 100644 index 73153be..0000000 --- a/vendor/github.com/docker/machine/test/integration/core/engine-options.bats +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -use_disposable_machine - -@test "$DRIVER: create with supported engine options" { - run machine create -d $DRIVER \ - --engine-label spam=eggs \ - --engine-storage-driver overlay \ - --engine-insecure-registry registry.myco.com \ - --engine-env=TEST=VALUE \ - --engine-opt log-driver=none \ - $NAME - echo "$output" - [ $status -eq 0 ] -} - -@test "$DRIVER: check for engine label" { - spamlabel=$(docker $(machine config $NAME) info | grep spam) - [[ $spamlabel =~ "spam=eggs" ]] -} - -@test "$DRIVER: check for engine storage driver" { - storage_driver_info=$(docker $(machine config $NAME) info | grep "Storage Driver") - [[ $storage_driver_info =~ "overlay" ]] -} - -@test "$DRIVER: test docker process envs" { - # get pid of docker process, check process envs for set Environment Variable from above test - run machine ssh $NAME 'sudo cat /proc/$(pgrep -f "docker [d]aemon")/environ' - echo ${output} - [ $status -eq 0 ] - [[ "${output}" =~ "TEST=VALUE" ]] -} - -@test "$DRIVER: check created engine option (log driver)" { - docker $(machine config $NAME) run --name nolog busybox echo this should not be logged - run docker $(machine config $NAME) inspect -f '{{.HostConfig.LogConfig.Type}}' nolog - echo ${output} - [ ${output} == "none" ] -} diff --git a/vendor/github.com/docker/machine/test/integration/core/env_shell.bats b/vendor/github.com/docker/machine/test/integration/core/env_shell.bats deleted file mode 100755 index a251e47..0000000 --- a/vendor/github.com/docker/machine/test/integration/core/env_shell.bats +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -use_shared_machine - -@test "$DRIVER: test basic bash / zsh notation" { - run machine env $NAME - [[ ${lines[0]} == "export DOCKER_TLS_VERIFY=\"1\"" ]] - [[ ${lines[1]} == "export DOCKER_HOST=\"$(machine url $NAME)\"" ]] - [[ ${lines[2]} == "export DOCKER_CERT_PATH=\"$MACHINE_STORAGE_PATH/machines/$NAME\"" ]] - [[ ${lines[3]} == "export DOCKER_MACHINE_NAME=\"$NAME\"" ]] -} - -@test "$DRIVER: test powershell notation" { - run machine env --shell powershell --no-proxy $NAME - [[ ${lines[0]} == "\$Env:DOCKER_TLS_VERIFY = \"1\"" ]] - [[ ${lines[1]} == "\$Env:DOCKER_HOST = \"$(machine url $NAME)\"" ]] - [[ ${lines[2]} == "\$Env:DOCKER_CERT_PATH = \"$MACHINE_STORAGE_PATH/machines/$NAME\"" ]] - [[ ${lines[3]} == "\$Env:DOCKER_MACHINE_NAME = \"$NAME\"" ]] - [[ ${lines[4]} == "\$Env:NO_PROXY = \"$(machine ip $NAME)\"" ]] -} - -@test "$DRIVER: test bash / zsh notation with no-proxy" { - run machine env --no-proxy $NAME - [[ ${lines[0]} == "export DOCKER_TLS_VERIFY=\"1\"" ]] - [[ ${lines[1]} == "export DOCKER_HOST=\"$(machine url $NAME)\"" ]] - [[ ${lines[2]} == "export DOCKER_CERT_PATH=\"$MACHINE_STORAGE_PATH/machines/$NAME\"" ]] - [[ ${lines[3]} == "export DOCKER_MACHINE_NAME=\"$NAME\"" ]] - [[ ${lines[4]} == "export NO_PROXY=\"$(machine ip $NAME)\"" ]] -} - -@test "$DRIVER: test cmd.exe notation" { - run machine env --shell cmd --no-proxy $NAME - [[ ${lines[0]} == "SET DOCKER_TLS_VERIFY=1" ]] - [[ ${lines[1]} == "SET DOCKER_HOST=$(machine url $NAME)" ]] - [[ ${lines[2]} == "SET DOCKER_CERT_PATH=$MACHINE_STORAGE_PATH/machines/$NAME" ]] - [[ ${lines[3]} == "SET DOCKER_MACHINE_NAME=$NAME" ]] - [[ ${lines[4]} == "SET NO_PROXY=$(machine ip $NAME)" ]] -} - -@test "$DRIVER: test fish notation" { - run machine env --shell fish --no-proxy $NAME - [[ ${lines[0]} == "set -gx DOCKER_TLS_VERIFY \"1\";" ]] - [[ ${lines[1]} == "set -gx DOCKER_HOST \"$(machine url $NAME)\";" ]] - [[ ${lines[2]} == "set -gx DOCKER_CERT_PATH \"$MACHINE_STORAGE_PATH/machines/$NAME\";" ]] - [[ ${lines[3]} == "set -gx DOCKER_MACHINE_NAME \"$NAME\";" ]] - [[ ${lines[4]} == "set -gx NO_PROXY \"$(machine ip $NAME)\";" ]] -} - -@test "$DRIVER: test emacs notation" { - run machine env --shell emacs --no-proxy $NAME - [[ ${lines[0]} == "(setenv \"DOCKER_TLS_VERIFY\" \"1\")" ]] - [[ ${lines[1]} == "(setenv \"DOCKER_HOST\" \"$(machine url $NAME)\")" ]] - [[ ${lines[2]} == "(setenv \"DOCKER_CERT_PATH\" \"$MACHINE_STORAGE_PATH/machines/$NAME\")" ]] - [[ ${lines[3]} == "(setenv \"DOCKER_MACHINE_NAME\" \"$NAME\")" ]] - [[ ${lines[4]} == "(setenv \"NO_PROXY\" \"$(machine ip $NAME)\")" ]] -} - -@test "$DRIVER: test no proxy with NO_PROXY already set" { - export NO_PROXY=localhost - run machine env --no-proxy $NAME - [[ ${lines[4]} == "export NO_PROXY=\"localhost,$(machine ip $NAME)\"" ]] -} - -@test "$DRIVER: test unset with an args should fail" { - run machine env -u $NAME - [ "$status" -eq 1 ] - [[ ${lines} == "Error: Expected no machine name when the -u flag is present" ]] -} - - -@test "$DRIVER: test bash/zsh unset" { - run machine env -u - [[ ${lines[0]} == "unset DOCKER_TLS_VERIFY" ]] - [[ ${lines[1]} == "unset DOCKER_HOST" ]] - [[ ${lines[2]} == "unset DOCKER_CERT_PATH" ]] - [[ ${lines[3]} == "unset DOCKER_MACHINE_NAME" ]] -} - -@test "$DRIVER: test unset killing no proxy" { - run machine env --no-proxy -u - [[ ${lines[0]} == "unset DOCKER_TLS_VERIFY" ]] - [[ ${lines[1]} == "unset DOCKER_HOST" ]] - [[ ${lines[2]} == "unset DOCKER_CERT_PATH" ]] - [[ ${lines[3]} == "unset DOCKER_MACHINE_NAME" ]] - [[ ${lines[4]} == "unset NO_PROXY" ]] -} - -@test "$DRIVER: unset powershell" { - run machine env --shell powershell -u - [[ ${lines[0]} == 'Remove-Item Env:\\DOCKER_TLS_VERIFY' ]] - [[ ${lines[1]} == 'Remove-Item Env:\\DOCKER_HOST' ]] - [[ ${lines[2]} == 'Remove-Item Env:\\DOCKER_CERT_PATH' ]] - [[ ${lines[3]} == 'Remove-Item Env:\\DOCKER_MACHINE_NAME' ]] -} - -@test "$DRIVER: unset with fish shell" { - run machine env --shell fish -u - [[ ${lines[0]} == "set -e DOCKER_TLS_VERIFY;" ]] - [[ ${lines[1]} == "set -e DOCKER_HOST;" ]] - [[ ${lines[2]} == "set -e DOCKER_CERT_PATH;" ]] - [[ ${lines[3]} == "set -e DOCKER_MACHINE_NAME;" ]] -} - -@test "$DRIVER: unset with cmd shell" { - run machine env --shell cmd -u - [[ ${lines[0]} == "SET DOCKER_TLS_VERIFY=" ]] - [[ ${lines[1]} == "SET DOCKER_HOST=" ]] - [[ ${lines[2]} == "SET DOCKER_CERT_PATH=" ]] - [[ ${lines[3]} == "SET DOCKER_MACHINE_NAME=" ]] -} - -@test "$DRIVER: unset with emacs shell" { - run machine env --shell emacs -u - [[ ${lines[0]} == "(setenv \"DOCKER_TLS_VERIFY\" nil)" ]] - [[ ${lines[1]} == "(setenv \"DOCKER_HOST\" nil)" ]] - [[ ${lines[2]} == "(setenv \"DOCKER_CERT_PATH\" nil)" ]] - [[ ${lines[3]} == "(setenv \"DOCKER_MACHINE_NAME\" nil)" ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/core/inspect_format.bats b/vendor/github.com/docker/machine/test/integration/core/inspect_format.bats deleted file mode 100644 index 41996de..0000000 --- a/vendor/github.com/docker/machine/test/integration/core/inspect_format.bats +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -use_shared_machine - -@test "$DRIVER: inspect format template" { - run machine inspect -f '{{.DriverName}}' $NAME - [[ "$output" == "$DRIVER" ]] -} - -@test "$DRIVER: inspect format template json directive" { - run machine inspect -f '{{json .DriverName}}' $NAME - [[ "$output" == "\"$DRIVER\"" ]] -} - -@test "$DRIVER: inspect format template pretty json directive" { - linecount=$(machine inspect -f '{{prettyjson .Driver}}' $NAME | wc -l) - [[ "$linecount" -gt 1 ]] -} - -@test "$DRIVER: check .Driver output is not flawed" { - only_if_env DRIVER virtualbox - run machine inspect -f '{{.Driver.SSHUser}}' $NAME - [ "$status" -eq 0 ] - [[ ${output} == "docker" ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/core/regenerate-certs.bats b/vendor/github.com/docker/machine/test/integration/core/regenerate-certs.bats deleted file mode 100644 index 121bdec..0000000 --- a/vendor/github.com/docker/machine/test/integration/core/regenerate-certs.bats +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -use_shared_machine - -@test "$DRIVER: regenerate the certs" { - run machine regenerate-certs -f $NAME - [[ ${status} -eq 0 ]] -} - -@test "$DRIVER: make sure docker still works" { - run docker $(machine config $NAME) version - [[ ${status} -eq 0 ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/core/scp.bats b/vendor/github.com/docker/machine/test/integration/core/scp.bats deleted file mode 100644 index 6e00c51..0000000 --- a/vendor/github.com/docker/machine/test/integration/core/scp.bats +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -use_shared_machine -export SECOND_MACHINE="$NAME-2" - -@test "$DRIVER: test machine scp command from remote to host" { - machine ssh $NAME 'echo A file created remotely! >/tmp/foo.txt' - machine scp $NAME:/tmp/foo.txt . - [[ $(cat foo.txt) == "A file created remotely!" ]] -} - -@test "$DRIVER: test machine scp command from host to remote" { - teardown () { - rm foo.txt - } - echo A file created locally! >foo.txt - machine scp foo.txt $NAME:/tmp/foo.txt - [[ $(machine ssh $NAME cat /tmp/foo.txt) == "A file created locally!" ]] -} - -@test "$DRIVER: create machine to test transferring files from machine to machine" { - run machine create -d $DRIVER $SECOND_MACHINE - [[ ${status} -eq 0 ]] -} - -@test "$DRIVER: scp from one machine to another" { - run machine ssh $NAME 'echo A file hopping around! >/tmp/foo.txt' - run machine scp $NAME:/tmp/foo.txt $SECOND_MACHINE:/tmp/foo.txt - [[ $(machine ssh ${SECOND_MACHINE} cat /tmp/foo.txt) == "A file hopping around!" ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/core/ssh-backends.bats b/vendor/github.com/docker/machine/test/integration/core/ssh-backends.bats deleted file mode 100644 index b1b5f59..0000000 --- a/vendor/github.com/docker/machine/test/integration/core/ssh-backends.bats +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -use_shared_machine - -@test "$DRIVER: test external ssh backend" { - run machine ssh $NAME df -h - [[ "$status" -eq 0 ]] -} - -@test "$DRIVER: test command did what it purported to -- external ssh" { - run machine ssh $NAME echo foo - [[ "$output" == "foo" ]] -} - -@test "$DRIVER: test native ssh backend" { - run machine --native-ssh ssh $NAME df -h - [[ "$status" -eq 0 ]] -} - -@test "$DRIVER: test command did what it purported to -- native ssh" { - run machine --native-ssh ssh $NAME echo foo - [[ "$output" =~ "foo" ]] -} - -@test "$DRIVER: ensure that ssh extra arguments work" { - # don't run this test if we can't use external SSH - which ssh - if [[ $? -ne 0 ]]; then - skip - fi - - # this will not fare well if -C doesn't get interpreted as "use compression" - # like intended - run machine ssh $NAME -C echo foo - - [[ "$status" -eq 0 ]] - [[ "$output" == "foo" ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/core/swarm-options.bats b/vendor/github.com/docker/machine/test/integration/core/swarm-options.bats deleted file mode 100644 index 6c21982..0000000 --- a/vendor/github.com/docker/machine/test/integration/core/swarm-options.bats +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -export TOKEN=$(curl -sS -X POST "https://discovery.hub.docker.com/v1/clusters") - -@test "create swarm master" { - run machine create -d $DRIVER --swarm --swarm-master --swarm-discovery "token://$TOKEN" --swarm-strategy binpack --swarm-opt heartbeat=5s queenbee - echo ${output} - [[ "$status" -eq 0 ]] -} - -@test "create swarm node" { - run machine create -d $DRIVER --swarm --swarm-discovery "token://$TOKEN" workerbee - [[ "$status" -eq 0 ]] -} - -@test "ensure strategy is correct" { - strategy=$(docker $(machine config --swarm queenbee) info | grep "Strategy:" | awk '{ print $2 }') - echo ${strategy} - [[ "$strategy" == "binpack" ]] -} - -@test "ensure heartbeat" { - heartbeat_arg=$(docker $(machine config queenbee) inspect -f '{{index .Args}}' swarm-agent-master) - echo ${heartbeat_arg} - [[ "$heartbeat_arg" =~ "--heartbeat=5s" ]] -} - -@test "ls command should not show as swarm active if normal active" { - eval $(machine env queenbee) - run machine ls --filter name=queenbee - [[ ${lines[1]} != *"* (swarm)"* ]] -} - -@test "ls command should show as swarm active" { - eval $(machine env --swarm queenbee) - run machine ls --filter name=queenbee - echo ${output} - [[ ${lines[1]} == *"* (swarm)"* ]] -} - -@test "active command should show the host as active if normal active" { - eval $(machine env queenbee) - run machine active - echo ${output} - [[ ${lines[0]} == "queenbee" ]] -} - -@test "active command should show the host as active if swarm active" { - eval $(machine env --swarm queenbee) - run machine active - echo ${output} - [[ ${lines[0]} == "queenbee" ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/helpers.bash b/vendor/github.com/docker/machine/test/integration/helpers.bash deleted file mode 100644 index 7138ed7..0000000 --- a/vendor/github.com/docker/machine/test/integration/helpers.bash +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -function echo_to_log { - echo "$BATS_TEST_NAME ----------- -$output ----------- - -" >> ${BATS_LOG} -} - -function teardown { - echo_to_log -} - -function errecho { - >&2 echo "$@" -} - -function only_if_env { - if [[ ${!1} != "$2" ]]; then - errecho "This test requires the $1 environment variable to be set to $2. Skipping..." - skip - fi -} - -function require_env { - if [[ -z ${!1} ]]; then - errecho "This test requires the $1 environment variable to be set in order to run." - exit 1 - fi -} - -function use_disposable_machine { - if [[ -z "$NAME" ]]; then - export NAME="bats-$DRIVER-test-$(date +%s)" - fi -} - -function use_shared_machine { - if [[ -z "$NAME" ]]; then - export NAME="$SHARED_NAME" - if [[ $(machine ls -q --filter name=$NAME | wc -l) -eq 0 ]]; then - machine create -d $DRIVER $NAME &>/dev/null - fi - fi -} - -# Make sure these aren't set while tests run (can cause confusing behavior) -unset DOCKER_HOST DOCKER_TLS_VERIFY DOCKER_CERT_DIR diff --git a/vendor/github.com/docker/machine/test/integration/run-bats.sh b/vendor/github.com/docker/machine/test/integration/run-bats.sh deleted file mode 100755 index 0693717..0000000 --- a/vendor/github.com/docker/machine/test/integration/run-bats.sh +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# Wrapper script to run bats tests for various drivers. -# Usage: DRIVER=[driver] ./run-bats.sh [subtest] - -function quiet_run () { - if [[ "$VERBOSE" == "1" ]]; then - "$@" - else - "$@" &>/dev/null - fi -} - -function cleanup_machines() { - for MACHINE_NAME in $(machine ls -q); do - if [[ "$MACHINE_NAME" != "$SHARED_NAME" ]] || [[ "$1" == "ALL" ]]; then - quiet_run machine rm -f $MACHINE_NAME - fi - done -} - -function cleanup_store() { - if [[ -d "$MACHINE_STORAGE_PATH" ]]; then - rm -r "$MACHINE_STORAGE_PATH" - fi -} - -function machine() { - "$MACHINE_ROOT"/bin/"$MACHINE_BIN_NAME" "$@" -} - -function run_bats() { - for bats_file in $(find "$1" -name \*.bats); do - echo "=> $bats_file" - - # BATS returns non-zero to indicate the tests have failed, we shouldn't - # necessarily bail in this case, so that's the reason for the e toggle. - set +e - bats "$bats_file" - if [[ $? -ne 0 ]]; then - EXIT_STATUS=1 - fi - set -e - - echo - - if [[ "$NO_SHARE_MACHINES" == "1" ]]; then - cleanup_machines "ALL" - else - cleanup_machines "NON-SHARED" - fi - done -} - -# Set this ourselves in case bats call fails -EXIT_STATUS=0 -export BATS_FILE="$1" - -# Check we're not running bash 3.x -if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then - echo "Bash 4.1 or later is required to run these tests" - exit 1 -fi - -# If bash 4.x, check the minor version is 1 or later -if [ "${BASH_VERSINFO[0]}" -eq 4 ] && [ "${BASH_VERSINFO[1]}" -lt 1 ]; then - echo "Bash 4.1 or later is required to run these tests" - exit 1 -fi - -if [[ -z "$DRIVER" ]]; then - echo "You must specify the DRIVER environment variable." - exit 1 -fi - -if [[ -z "$BATS_FILE" ]]; then - echo "You must specify a bats test to run." - exit 1 -fi - -if [[ ! -e "$BATS_FILE" ]]; then - echo "Requested bats file or directory not found: $BATS_FILE" - exit 1 -fi - -# TODO: Should the script bail out if these are set already? -export BASE_TEST_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -export MACHINE_ROOT="$BASE_TEST_DIR/../.." -export MACHINE_STORAGE_PATH="/tmp/machine-bats-test-$DRIVER" -export MACHINE_BIN_NAME=docker-machine -export BATS_LOG="$MACHINE_ROOT/bats.log" -export B2D_LOCATION=~/.docker/machine/cache/boot2docker.iso -export SHARED_NAME="bats-$DRIVER-test-shared-$(date +%s)" -export MACHINE_BUGSNAG_API_TOKEN=no-report - -# This function gets used in the integration tests, so export it. -export -f machine - -> "$BATS_LOG" - -cleanup_machines "ALL" -cleanup_store - -if [[ -f "$B2D_LOCATION" ]]; then - if [[ "$B2D_CACHE" == "1" ]]; then - mkdir -p "${MACHINE_STORAGE_PATH}/cache" - cp $B2D_LOCATION "${MACHINE_STORAGE_PATH}/cache/boot2docker.iso" - else - echo "INFO: Run the tests with B2D_CACHE=1 to avoid downloading the boot2docker iso each time." - fi -fi - -run_bats "$BATS_FILE" - -cleanup_machines "ALL" -cleanup_store - -exit ${EXIT_STATUS} diff --git a/vendor/github.com/docker/machine/test/integration/virtualbox/certs-checksum.bats b/vendor/github.com/docker/machine/test/integration/virtualbox/certs-checksum.bats deleted file mode 100644 index 4e35c4a..0000000 --- a/vendor/github.com/docker/machine/test/integration/virtualbox/certs-checksum.bats +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER virtualbox - -use_shared_machine - -@test "$DRIVER: verify that server cert checksum matches local checksum" { - # TODO: This test is tightly coupled to VirtualBox right now, but should be - # available for all providers ideally. - # - # TODO: Does this test work OK on Linux? cc @ehazlett - # - # Have to create this directory and file or else the OpenSSL checksum will barf. - machine ssh $NAME -- sudo mkdir -p /usr/local/ssl - machine ssh $NAME -- sudo touch /usr/local/ssl/openssl.cnf - - SERVER_CHECKSUM=$(machine ssh $NAME -- openssl dgst -sha256 /var/lib/boot2docker/ca.pem | awk '{ print $2 }') - LOCAL_CHECKSUM=$(openssl dgst -sha256 $MACHINE_STORAGE_PATH/certs/ca.pem | awk '{ print $2 }') - echo ${SERVER_CHECKSUM} - echo ${LOCAL_CHECKSUM} - [[ ${SERVER_CHECKSUM} == ${LOCAL_CHECKSUM} ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/virtualbox/create-with-upgrading.bats b/vendor/github.com/docker/machine/test/integration/virtualbox/create-with-upgrading.bats deleted file mode 100644 index ad8e277..0000000 --- a/vendor/github.com/docker/machine/test/integration/virtualbox/create-with-upgrading.bats +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER virtualbox - -use_disposable_machine - -export CACHE_DIR="$MACHINE_STORAGE_PATH/cache" -export ISO_PATH="$CACHE_DIR/boot2docker.iso" -export OLD_ISO_URL="https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso" - -@test "$DRIVER: download the old version iso" { - run mkdir -p $CACHE_DIR - run curl $OLD_ISO_URL -L -o $ISO_PATH - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: create with upgrading" { - run machine create -d $DRIVER $NAME - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: create is correct version" { - SERVER_VERSION=$(docker $(machine config $NAME) version | grep 'Server version' | awk '{ print $3; }') - [[ "$SERVER_VERSION" != "1.4.1" ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/virtualbox/custom-mem-disk.bats b/vendor/github.com/docker/machine/test/integration/virtualbox/custom-mem-disk.bats deleted file mode 100644 index 5828b4f..0000000 --- a/vendor/github.com/docker/machine/test/integration/virtualbox/custom-mem-disk.bats +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER virtualbox - -use_disposable_machine - -# Default memsize is 1024MB and disksize is 20000MB -# These values are defined in drivers/virtualbox/virtualbox.go -export DEFAULT_MEMSIZE=1024 -export DEFAULT_DISKSIZE=20000 -export CUSTOM_MEMSIZE=1536 -export CUSTOM_DISKSIZE=10000 -export CUSTOM_CPUCOUNT=1 - -function findDiskSize() { - # SATA-0-0 is usually the boot2disk.iso image - # We assume that SATA 1-0 is root disk VMDK and grab this UUID - # e.g. "SATA-ImageUUID-1-0"="fb5f33a7-e4e3-4cb9-877c-f9415ae2adea" - # TODO(slashk): does this work on Windows ? - run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep SATA-ImageUUID-1-0 | cut -d'=' -f2" - run bash -c "VBoxManage showhdinfo $output | grep "Capacity:" | awk -F' ' '{ print $2 }'" -} - -function findMemorySize() { - run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep memory= | cut -d'=' -f2" -} - -function findCPUCount() { - run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep cpus= | cut -d'=' -f2" -} - -@test "$DRIVER: create with custom disk, cpu count and memory size flags" { - run machine create -d $DRIVER --virtualbox-cpu-count $CUSTOM_CPUCOUNT --virtualbox-disk-size $CUSTOM_DISKSIZE --virtualbox-memory $CUSTOM_MEMSIZE $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: check custom machine memory size" { - findMemorySize - [[ ${output} == "$CUSTOM_MEMSIZE" ]] -} - -@test "$DRIVER: check custom machine disksize" { - findDiskSize - [[ ${output} == *"$CUSTOM_DISKSIZE"* ]] -} - -@test "$DRIVER: check custom machine cpucount" { - findCPUCount - [[ ${output} == "$CUSTOM_CPUCOUNT" ]] -} - -@test "$DRIVER: machine should show running after create" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/virtualbox/dns.bats b/vendor/github.com/docker/machine/test/integration/virtualbox/dns.bats deleted file mode 100644 index 7b7afca..0000000 --- a/vendor/github.com/docker/machine/test/integration/virtualbox/dns.bats +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER virtualbox - -use_disposable_machine - -@test "$DRIVER: Create a vm with a dns proxy set" { - run machine create -d $DRIVER --virtualbox-dns-proxy=true $NAME - [[ ${status} -eq 0 ]] -} - -@test "$DRIVER: Check DNSProxy flag is properly set during machine creation" { - run bash -c "cat ${MACHINE_STORAGE_PATH}/machines/$NAME/$NAME/Logs/VBox.log | grep DNSProxy | grep '(1)'" - [[ ${status} -eq 0 ]] -} \ No newline at end of file diff --git a/vendor/github.com/docker/machine/test/integration/virtualbox/guards.bats b/vendor/github.com/docker/machine/test/integration/virtualbox/guards.bats deleted file mode 100644 index e10d858..0000000 --- a/vendor/github.com/docker/machine/test/integration/virtualbox/guards.bats +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER virtualbox - -use_disposable_machine - -@test "$DRIVER: Should not allow machine creation with bad ISO" { - run machine create -d virtualbox --virtualbox-boot2docker-url http://dev.null:9111/bad.iso $NAME - [[ ${status} -eq 1 ]] -} - -@test "$DRIVER: Should not allow machine creation with engine-install-url" { - run machine create --engine-install-url https://test.docker.com -d virtualbox $NAME - [[ ${output} == *"--engine-install-url cannot be used"* ]] -} \ No newline at end of file diff --git a/vendor/github.com/docker/machine/test/integration/virtualbox/pause-save-start.bats b/vendor/github.com/docker/machine/test/integration/virtualbox/pause-save-start.bats deleted file mode 100644 index 2102aef..0000000 --- a/vendor/github.com/docker/machine/test/integration/virtualbox/pause-save-start.bats +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER virtualbox - -use_shared_machine - -@test "$DRIVER: VBoxManage pause" { - run VBoxManage controlvm $NAME pause - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show paused after VBoxManage pause" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Paused"* ]] -} - -@test "$DRIVER: start after paused" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: VBoxManage savestate" { - run VBoxManage controlvm $NAME savestate - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show saved after VBoxManage savestate" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] - [[ ${lines[1]} == *"Saved"* ]] -} - -@test "$DRIVER: start after saved" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} diff --git a/vendor/github.com/docker/machine/test/integration/virtualbox/upgrade.bats b/vendor/github.com/docker/machine/test/integration/virtualbox/upgrade.bats deleted file mode 100644 index dc906b7..0000000 --- a/vendor/github.com/docker/machine/test/integration/virtualbox/upgrade.bats +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -only_if_env DRIVER virtualbox - -use_disposable_machine - -export OLD_ISO_URL="https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso" - -@test "$DRIVER: create for upgrade" { - run machine create -d virtualbox --virtualbox-boot2docker-url $OLD_ISO_URL $NAME -} - -@test "$DRIVER: verify that docker version is old" { - # Have to run this over SSH due to client/server mismatch restriction - SERVER_VERSION=$(machine ssh $NAME docker version | grep 'Server version' | awk '{ print $3; }') - [[ "$SERVER_VERSION" == "1.4.1" ]] -} - -@test "$DRIVER: upgrade" { - run machine upgrade $NAME - echo ${output} - [ "$status" -eq 0 ] -} - -@test "$DRIVER: upgrade is correct version" { - SERVER_VERSION=$(docker $(machine config $NAME) version | grep 'Server version' | awk '{ print $3; }') - [[ "$SERVER_VERSION" != "1.4.1" ]] -} diff --git a/vendor/github.com/docker/machine/test/provision/rancheros.bats b/vendor/github.com/docker/machine/test/provision/rancheros.bats deleted file mode 100644 index 62c726f..0000000 --- a/vendor/github.com/docker/machine/test/provision/rancheros.bats +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - - -# this should move to the makefile - -if [[ "$DRIVER" != "virtualbox" ]]; then - exit 0 -fi - -export RANCHEROS_VERSION="v0.3.1" -export RANCHEROS_ISO="https://github.com/rancherio/os/releases/download/$RANCHEROS_VERSION/machine-rancheros.iso" - -@test "$DRIVER: create with RancherOS ISO" { - VIRTUALBOX_BOOT2DOCKER_URL="$RANCHEROS_ISO" run ${BASE_TEST_DIR}/run-bats.sh ${BASE_TEST_DIR}/core - echo ${output} - [ ${status} -eq 0 ] -} diff --git a/vendor/github.com/docker/machine/test/provision/redhat.bats b/vendor/github.com/docker/machine/test/provision/redhat.bats deleted file mode 100644 index f2b249a..0000000 --- a/vendor/github.com/docker/machine/test/provision/redhat.bats +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bats - -load ${BASE_TEST_DIR}/helpers.bash - -# this should move to the makefile - -if [[ "$DRIVER" != "amazonec2" ]]; then - exit 0 -fi - -require_env AWS_VPC_ID -require_env AWS_ACCESS_KEY_ID -require_env AWS_SECRET_ACCESS_KEY - -@test "$DRIVER: create using RedHat AMI" { - # Oh snap, recursive stuff!! - AWS_AMI=ami-12663b7a AWS_SSH_USER=ec2-user run ${BASE_TEST_DIR}/run-bats.sh ${BASE_TEST_DIR}/core - echo ${output} - [ ${status} -eq 0 ] -} diff --git a/vendor/github.com/docker/machine/version/version.go b/vendor/github.com/docker/machine/version/version.go deleted file mode 100644 index cbe1d23..0000000 --- a/vendor/github.com/docker/machine/version/version.go +++ /dev/null @@ -1,23 +0,0 @@ -package version - -import ( - "fmt" - "strings" -) - -var ( - Version = "0.13.0" - - // GitCommit will be overwritten automatically by the build system - GitCommit = "HEAD" -) - -// FullVersion formats the version to be printed -func FullVersion() string { - return fmt.Sprintf("%s, build %s", Version, GitCommit) -} - -// RC checks if the Machine version is a release candidate or not -func RC() bool { - return strings.Contains(Version, "rc") -} diff --git a/vendor/github.com/hashicorp/errwrap/LICENSE b/vendor/github.com/hashicorp/errwrap/LICENSE deleted file mode 100644 index c33dcc7..0000000 --- a/vendor/github.com/hashicorp/errwrap/LICENSE +++ /dev/null @@ -1,354 +0,0 @@ -Mozilla Public License, version 2.0 - -1. Definitions - -1.1. “Contributor” - - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. - -1.2. “Contributor Version” - - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor’s Contribution. - -1.3. “Contribution” - - means Covered Software of a particular Contributor. - -1.4. “Covered Software” - - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. - -1.5. “Incompatible With Secondary Licenses” - means - - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or - - b. that the Covered Software was made available under the terms of version - 1.1 or earlier of the License, but not also under the terms of a - Secondary License. - -1.6. “Executable Form” - - means any form of the work other than Source Code Form. - -1.7. “Larger Work” - - means a work that combines Covered Software with other material, in a separate - file or files, that is not Covered Software. - -1.8. “License” - - means this document. - -1.9. “Licensable” - - means having the right to grant, to the maximum extent possible, whether at the - time of the initial grant or subsequently, any and all of the rights conveyed by - this License. - -1.10. “Modifications” - - means any of the following: - - a. any file in Source Code Form that results from an addition to, deletion - from, or modification of the contents of Covered Software; or - - b. any new file in Source Code Form that contains any Covered Software. - -1.11. “Patent Claims” of a Contributor - - means any patent claim(s), including without limitation, method, process, - and apparatus claims, in any patent Licensable by such Contributor that - would be infringed, but for the grant of the License, by the making, - using, selling, offering for sale, having made, import, or transfer of - either its Contributions or its Contributor Version. - -1.12. “Secondary License” - - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. - -1.13. “Source Code Form” - - means the form of the work preferred for making modifications. - -1.14. “You” (or “Your”) - - means an individual or a legal entity exercising rights under this - License. For legal entities, “You” includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, “control” means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. - - -2. License Grants and Conditions - -2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or as - part of a Larger Work; and - - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its Contributions - or its Contributor Version. - -2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution become - effective for each Contribution on the date the Contributor first distributes - such Contribution. - -2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under this - License. No additional rights or licenses will be implied from the distribution - or licensing of Covered Software under this License. Notwithstanding Section - 2.1(b) above, no patent license is granted by a Contributor: - - a. for any code that a Contributor has removed from Covered Software; or - - b. for infringements caused by: (i) Your and any other third party’s - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - c. under Patent Claims infringed by Covered Software in the absence of its - Contributions. - - This License does not grant any rights in the trademarks, service marks, or - logos of any Contributor (except as may be necessary to comply with the - notice requirements in Section 3.4). - -2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this License - (see Section 10.2) or under the terms of a Secondary License (if permitted - under the terms of Section 3.3). - -2.5. Representation - - Each Contributor represents that the Contributor believes its Contributions - are its original creation(s) or it has sufficient rights to grant the - rights to its Contributions conveyed by this License. - -2.6. Fair Use - - This License is not intended to limit any rights You have under applicable - copyright doctrines of fair use, fair dealing, or other equivalents. - -2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. - - -3. Responsibilities - -3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under the - terms of this License. You must inform recipients that the Source Code Form - of the Covered Software is governed by the terms of this License, and how - they can obtain a copy of this License. You may not attempt to alter or - restrict the recipients’ rights in the Source Code Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this License, - or sublicense it under different terms, provided that the license for - the Executable Form does not attempt to limit or alter the recipients’ - rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for the - Covered Software. If the Larger Work is a combination of Covered Software - with a work governed by one or more Secondary Licenses, and the Covered - Software is not Incompatible With Secondary Licenses, this License permits - You to additionally distribute such Covered Software under the terms of - such Secondary License(s), so that the recipient of the Larger Work may, at - their option, further distribute the Covered Software under the terms of - either this License or such Secondary License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices (including - copyright notices, patent notices, disclaimers of warranty, or limitations - of liability) contained within the Source Code Form of the Covered - Software, except that You may alter any license notices to the extent - required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on behalf - of any Contributor. You must make it absolutely clear that any such - warranty, support, indemnity, or liability obligation is offered by You - alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, judicial - order, or regulation then You must: (a) comply with the terms of this License - to the maximum extent possible; and (b) describe the limitations and the code - they affect. Such description must be placed in a text file included with all - distributions of the Covered Software under this License. Except to the - extent prohibited by statute or regulation, such description must be - sufficiently detailed for a recipient of ordinary skill to be able to - understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You - fail to comply with any of its terms. However, if You become compliant, - then the rights granted under this License from a particular Contributor - are reinstated (a) provisionally, unless and until such Contributor - explicitly and finally terminates Your grants, and (b) on an ongoing basis, - if such Contributor fails to notify You of the non-compliance by some - reasonable means prior to 60 days after You have come back into compliance. - Moreover, Your grants from a particular Contributor are reinstated on an - ongoing basis if such Contributor notifies You of the non-compliance by - some reasonable means, this is the first time You have received notice of - non-compliance with this License from such Contributor, and You become - compliant prior to 30 days after Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, counter-claims, - and cross-claims) alleging that a Contributor Version directly or - indirectly infringes any patent, then the rights granted to You by any and - all Contributors for the Covered Software under Section 2.1 of this License - shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user - license agreements (excluding distributors and resellers) which have been - validly granted by You or Your distributors under this License prior to - termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an “as is” basis, without - warranty of any kind, either expressed, implied, or statutory, including, - without limitation, warranties that the Covered Software is free of defects, - merchantable, fit for a particular purpose or non-infringing. The entire - risk as to the quality and performance of the Covered Software is with You. - Should any Covered Software prove defective in any respect, You (not any - Contributor) assume the cost of any necessary servicing, repair, or - correction. This disclaimer of warranty constitutes an essential part of this - License. No use of any Covered Software is authorized under this License - except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from such - party’s negligence to the extent applicable law prohibits such limitation. - Some jurisdictions do not allow the exclusion or limitation of incidental or - consequential damages, so this exclusion and limitation may not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts of - a jurisdiction where the defendant maintains its principal place of business - and such litigation shall be governed by laws of that jurisdiction, without - reference to its conflict-of-law provisions. Nothing in this Section shall - prevent a party’s ability to bring cross-claims or counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject matter - hereof. If any provision of this License is held to be unenforceable, such - provision shall be reformed only to the extent necessary to make it - enforceable. Any law or regulation which provides that the language of a - contract shall be construed against the drafter shall not be used to construe - this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version of - the License under which You originally received the Covered Software, or - under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a modified - version of this License if you rename the license and remove any - references to the name of the license steward (except to note that such - modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses - If You choose to distribute Source Code Form that is Incompatible With - Secondary Licenses under the terms of this version of the License, the - notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, then -You may include the notice in a location (such as a LICENSE file in a relevant -directory) where a recipient would be likely to look for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - “Incompatible With Secondary Licenses” Notice - - This Source Code Form is “Incompatible - With Secondary Licenses”, as defined by - the Mozilla Public License, v. 2.0. - diff --git a/vendor/github.com/hashicorp/errwrap/README.md b/vendor/github.com/hashicorp/errwrap/README.md deleted file mode 100644 index 1c95f59..0000000 --- a/vendor/github.com/hashicorp/errwrap/README.md +++ /dev/null @@ -1,89 +0,0 @@ -# errwrap - -`errwrap` is a package for Go that formalizes the pattern of wrapping errors -and checking if an error contains another error. - -There is a common pattern in Go of taking a returned `error` value and -then wrapping it (such as with `fmt.Errorf`) before returning it. The problem -with this pattern is that you completely lose the original `error` structure. - -Arguably the _correct_ approach is that you should make a custom structure -implementing the `error` interface, and have the original error as a field -on that structure, such [as this example](http://golang.org/pkg/os/#PathError). -This is a good approach, but you have to know the entire chain of possible -rewrapping that happens, when you might just care about one. - -`errwrap` formalizes this pattern (it doesn't matter what approach you use -above) by giving a single interface for wrapping errors, checking if a specific -error is wrapped, and extracting that error. - -## Installation and Docs - -Install using `go get github.com/hashicorp/errwrap`. - -Full documentation is available at -http://godoc.org/github.com/hashicorp/errwrap - -## Usage - -#### Basic Usage - -Below is a very basic example of its usage: - -```go -// A function that always returns an error, but wraps it, like a real -// function might. -func tryOpen() error { - _, err := os.Open("/i/dont/exist") - if err != nil { - return errwrap.Wrapf("Doesn't exist: {{err}}", err) - } - - return nil -} - -func main() { - err := tryOpen() - - // We can use the Contains helpers to check if an error contains - // another error. It is safe to do this with a nil error, or with - // an error that doesn't even use the errwrap package. - if errwrap.Contains(err, ErrNotExist) { - // Do something - } - if errwrap.ContainsType(err, new(os.PathError)) { - // Do something - } - - // Or we can use the associated `Get` functions to just extract - // a specific error. This would return nil if that specific error doesn't - // exist. - perr := errwrap.GetType(err, new(os.PathError)) -} -``` - -#### Custom Types - -If you're already making custom types that properly wrap errors, then -you can get all the functionality of `errwraps.Contains` and such by -implementing the `Wrapper` interface with just one function. Example: - -```go -type AppError { - Code ErrorCode - Err error -} - -func (e *AppError) WrappedErrors() []error { - return []error{e.Err} -} -``` - -Now this works: - -```go -err := &AppError{Err: fmt.Errorf("an error")} -if errwrap.ContainsType(err, fmt.Errorf("")) { - // This will work! -} -``` diff --git a/vendor/github.com/hashicorp/errwrap/errwrap.go b/vendor/github.com/hashicorp/errwrap/errwrap.go deleted file mode 100644 index a733bef..0000000 --- a/vendor/github.com/hashicorp/errwrap/errwrap.go +++ /dev/null @@ -1,169 +0,0 @@ -// Package errwrap implements methods to formalize error wrapping in Go. -// -// All of the top-level functions that take an `error` are built to be able -// to take any error, not just wrapped errors. This allows you to use errwrap -// without having to type-check and type-cast everywhere. -package errwrap - -import ( - "errors" - "reflect" - "strings" -) - -// WalkFunc is the callback called for Walk. -type WalkFunc func(error) - -// Wrapper is an interface that can be implemented by custom types to -// have all the Contains, Get, etc. functions in errwrap work. -// -// When Walk reaches a Wrapper, it will call the callback for every -// wrapped error in addition to the wrapper itself. Since all the top-level -// functions in errwrap use Walk, this means that all those functions work -// with your custom type. -type Wrapper interface { - WrappedErrors() []error -} - -// Wrap defines that outer wraps inner, returning an error type that -// can be cleanly used with the other methods in this package, such as -// Contains, GetAll, etc. -// -// This function won't modify the error message at all (the outer message -// will be used). -func Wrap(outer, inner error) error { - return &wrappedError{ - Outer: outer, - Inner: inner, - } -} - -// Wrapf wraps an error with a formatting message. This is similar to using -// `fmt.Errorf` to wrap an error. If you're using `fmt.Errorf` to wrap -// errors, you should replace it with this. -// -// format is the format of the error message. The string '{{err}}' will -// be replaced with the original error message. -func Wrapf(format string, err error) error { - outerMsg := "" - if err != nil { - outerMsg = err.Error() - } - - outer := errors.New(strings.Replace( - format, "{{err}}", outerMsg, -1)) - - return Wrap(outer, err) -} - -// Contains checks if the given error contains an error with the -// message msg. If err is not a wrapped error, this will always return -// false unless the error itself happens to match this msg. -func Contains(err error, msg string) bool { - return len(GetAll(err, msg)) > 0 -} - -// ContainsType checks if the given error contains an error with -// the same concrete type as v. If err is not a wrapped error, this will -// check the err itself. -func ContainsType(err error, v interface{}) bool { - return len(GetAllType(err, v)) > 0 -} - -// Get is the same as GetAll but returns the deepest matching error. -func Get(err error, msg string) error { - es := GetAll(err, msg) - if len(es) > 0 { - return es[len(es)-1] - } - - return nil -} - -// GetType is the same as GetAllType but returns the deepest matching error. -func GetType(err error, v interface{}) error { - es := GetAllType(err, v) - if len(es) > 0 { - return es[len(es)-1] - } - - return nil -} - -// GetAll gets all the errors that might be wrapped in err with the -// given message. The order of the errors is such that the outermost -// matching error (the most recent wrap) is index zero, and so on. -func GetAll(err error, msg string) []error { - var result []error - - Walk(err, func(err error) { - if err.Error() == msg { - result = append(result, err) - } - }) - - return result -} - -// GetAllType gets all the errors that are the same type as v. -// -// The order of the return value is the same as described in GetAll. -func GetAllType(err error, v interface{}) []error { - var result []error - - var search string - if v != nil { - search = reflect.TypeOf(v).String() - } - Walk(err, func(err error) { - var needle string - if err != nil { - needle = reflect.TypeOf(err).String() - } - - if needle == search { - result = append(result, err) - } - }) - - return result -} - -// Walk walks all the wrapped errors in err and calls the callback. If -// err isn't a wrapped error, this will be called once for err. If err -// is a wrapped error, the callback will be called for both the wrapper -// that implements error as well as the wrapped error itself. -func Walk(err error, cb WalkFunc) { - if err == nil { - return - } - - switch e := err.(type) { - case *wrappedError: - cb(e.Outer) - Walk(e.Inner, cb) - case Wrapper: - cb(err) - - for _, err := range e.WrappedErrors() { - Walk(err, cb) - } - default: - cb(err) - } -} - -// wrappedError is an implementation of error that has both the -// outer and inner errors. -type wrappedError struct { - Outer error - Inner error -} - -func (w *wrappedError) Error() string { - return w.Outer.Error() -} - -func (w *wrappedError) WrappedErrors() []error { - return []error{w.Outer, w.Inner} -} diff --git a/vendor/github.com/hashicorp/errwrap/errwrap_test.go b/vendor/github.com/hashicorp/errwrap/errwrap_test.go deleted file mode 100644 index 5ae5f8e..0000000 --- a/vendor/github.com/hashicorp/errwrap/errwrap_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package errwrap - -import ( - "fmt" - "testing" -) - -func TestWrappedError_impl(t *testing.T) { - var _ error = new(wrappedError) -} - -func TestGetAll(t *testing.T) { - cases := []struct { - Err error - Msg string - Len int - }{ - {}, - { - fmt.Errorf("foo"), - "foo", - 1, - }, - { - fmt.Errorf("bar"), - "foo", - 0, - }, - { - Wrapf("bar", fmt.Errorf("foo")), - "foo", - 1, - }, - { - Wrapf("{{err}}", fmt.Errorf("foo")), - "foo", - 2, - }, - { - Wrapf("bar", Wrapf("baz", fmt.Errorf("foo"))), - "foo", - 1, - }, - } - - for i, tc := range cases { - actual := GetAll(tc.Err, tc.Msg) - if len(actual) != tc.Len { - t.Fatalf("%d: bad: %#v", i, actual) - } - for _, v := range actual { - if v.Error() != tc.Msg { - t.Fatalf("%d: bad: %#v", i, actual) - } - } - } -} - -func TestGetAllType(t *testing.T) { - cases := []struct { - Err error - Type interface{} - Len int - }{ - {}, - { - fmt.Errorf("foo"), - "foo", - 0, - }, - { - fmt.Errorf("bar"), - fmt.Errorf("foo"), - 1, - }, - { - Wrapf("bar", fmt.Errorf("foo")), - fmt.Errorf("baz"), - 2, - }, - { - Wrapf("bar", Wrapf("baz", fmt.Errorf("foo"))), - Wrapf("", nil), - 0, - }, - } - - for i, tc := range cases { - actual := GetAllType(tc.Err, tc.Type) - if len(actual) != tc.Len { - t.Fatalf("%d: bad: %#v", i, actual) - } - } -} diff --git a/vendor/github.com/joyent/triton-go/.gitignore b/vendor/github.com/joyent/triton-go/.gitignore deleted file mode 100644 index b5dbd64..0000000 --- a/vendor/github.com/joyent/triton-go/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -*.dll -*.exe -.DS_Store -bin/ -pkg/ -.vagrant/ -*.backup -*.log -*.bak -*~ -*# -.*.swp -.idea/ -*.test -*.iml -Notes.md diff --git a/vendor/github.com/joyent/triton-go/CHANGELOG.md b/vendor/github.com/joyent/triton-go/CHANGELOG.md deleted file mode 100644 index df4a0fb..0000000 --- a/vendor/github.com/joyent/triton-go/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -## 0.2.0 (November 2) - -- Introduce CloudAPI's Ping under compute -- Introduce CloudAPI's RebootMachine under compute instances -- tools: Introduce unit testing and scripts for linting, etc. - -## 0.1.0 (November 2) - -- Initial release of a versioned SDK diff --git a/vendor/github.com/joyent/triton-go/GNUmakefile b/vendor/github.com/joyent/triton-go/GNUmakefile deleted file mode 100644 index cca7f67..0000000 --- a/vendor/github.com/joyent/triton-go/GNUmakefile +++ /dev/null @@ -1,47 +0,0 @@ -TEST?=$$(go list ./... |grep -Ev 'vendor|examples|testutils') -GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor) - -default: vet errcheck test - -tools:: ## Download and install all dev/code tools - @echo "==> Installing dev tools" - go get -u github.com/golang/dep/cmd/dep - go get -u github.com/golang/lint/golint - go get -u github.com/kisielk/errcheck - @echo "==> Installing test package dependencies" - go test -i $(TEST) || exit 1 - -test:: ## Run unit tests - @echo "==> Running unit tests" - @echo $(TEST) | \ - xargs -t go test -v $(TESTARGS) -timeout=30s -parallel=1 | grep -Ev 'TRITON_TEST|TestAcc' - -testacc:: ## Run acceptance tests - @echo "==> Running acceptance tests" - TRITON_TEST=1 go test $(TEST) -v $(TESTARGS) -run -timeout 120m - -vet:: ## Check for unwanted code constructs - @echo "go vet ." - @go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \ - echo ""; \ - echo "Vet found suspicious constructs. Please check the reported constructs"; \ - echo "and fix them if necessary before submitting the code for review."; \ - exit 1; \ - fi - -lint:: ## Lint and vet code by common Go standards - @bash $(CURDIR)/scripts/lint.sh - -fmt:: ## Format as canonical Go code - gofmt -w $(GOFMT_FILES) - -fmtcheck:: ## Check if code format is canonical Go - @bash $(CURDIR)/scripts/gofmtcheck.sh - -errcheck:: ## Check for unhandled errors - @bash $(CURDIR)/scripts/errcheck.sh - -.PHONY: help -help:: ## Display this help message - @echo "GNU make(1) targets:" - @grep -E '^[a-zA-Z_.-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' diff --git a/vendor/github.com/joyent/triton-go/Gopkg.lock b/vendor/github.com/joyent/triton-go/Gopkg.lock deleted file mode 100644 index b61936a..0000000 --- a/vendor/github.com/joyent/triton-go/Gopkg.lock +++ /dev/null @@ -1,39 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - branch = "master" - name = "github.com/abdullin/seq" - packages = ["."] - revision = "d5467c17e7afe8d8f08f556c6c811a50c3feb28d" - -[[projects]] - name = "github.com/davecgh/go-spew" - packages = ["spew"] - revision = "346938d642f2ec3594ed81d874461961cd0faa76" - version = "v1.1.0" - -[[projects]] - branch = "master" - name = "github.com/hashicorp/errwrap" - packages = ["."] - revision = "7554cd9344cec97297fa6649b055a8c98c2a1e55" - -[[projects]] - branch = "master" - name = "github.com/sean-/seed" - packages = ["."] - revision = "e2103e2c35297fb7e17febb81e49b312087a2372" - -[[projects]] - branch = "master" - name = "golang.org/x/crypto" - packages = ["curve25519","ed25519","ed25519/internal/edwards25519","ssh","ssh/agent"] - revision = "bd6f299fb381e4c3393d1c4b1f0b94f5e77650c8" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "28853a8970ee33112a9e7998b18e658bed04d177537ec69db678189f0b8a9a7d" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/vendor/github.com/joyent/triton-go/Gopkg.toml b/vendor/github.com/joyent/triton-go/Gopkg.toml deleted file mode 100644 index 3b85ddf..0000000 --- a/vendor/github.com/joyent/triton-go/Gopkg.toml +++ /dev/null @@ -1,42 +0,0 @@ - -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - branch = "master" - name = "github.com/abdullin/seq" - -[[constraint]] - name = "github.com/davecgh/go-spew" - version = "1.1.0" - -[[constraint]] - branch = "master" - name = "github.com/hashicorp/errwrap" - -[[constraint]] - branch = "master" - name = "github.com/sean-/seed" - -[[constraint]] - branch = "master" - name = "golang.org/x/crypto" diff --git a/vendor/github.com/joyent/triton-go/LICENSE b/vendor/github.com/joyent/triton-go/LICENSE deleted file mode 100644 index 14e2f77..0000000 --- a/vendor/github.com/joyent/triton-go/LICENSE +++ /dev/null @@ -1,373 +0,0 @@ -Mozilla Public License Version 2.0 -================================== - -1. Definitions --------------- - -1.1. "Contributor" - means each individual or legal entity that creates, contributes to - the creation of, or owns Covered Software. - -1.2. "Contributor Version" - means the combination of the Contributions of others (if any) used - by a Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - means Source Code Form to which the initial Contributor has attached - the notice in Exhibit A, the Executable Form of such Source Code - Form, and Modifications of such Source Code Form, in each case - including portions thereof. - -1.5. "Incompatible With Secondary Licenses" - means - - (a) that the initial Contributor has attached the notice described - in Exhibit B to the Covered Software; or - - (b) that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the - terms of a Secondary License. - -1.6. "Executable Form" - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - means a work that combines Covered Software with other material, in - a separate file or files, that is not Covered Software. - -1.8. "License" - means this document. - -1.9. "Licensable" - means having the right to grant, to the maximum extent possible, - whether at the time of the initial grant or subsequently, any and - all of the rights conveyed by this License. - -1.10. "Modifications" - means any of the following: - - (a) any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered - Software; or - - (b) any new file in Source Code Form that contains any Covered - Software. - -1.11. "Patent Claims" of a Contributor - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the - License, by the making, using, selling, offering for sale, having - made, import, or transfer of either its Contributions or its - Contributor Version. - -1.12. "Secondary License" - means either the GNU General Public License, Version 2.0, the GNU - Lesser General Public License, Version 2.1, the GNU Affero General - Public License, Version 3.0, or any later versions of those - licenses. - -1.13. "Source Code Form" - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that - controls, is controlled by, or is under common control with You. For - purposes of this definition, "control" means (a) the power, direct - or indirect, to cause the direction or management of such entity, - whether by contract or otherwise, or (b) ownership of more than - fifty percent (50%) of the outstanding shares or beneficial - ownership of such entity. - -2. License Grants and Conditions --------------------------------- - -2.1. Grants - -Each Contributor hereby grants You a world-wide, royalty-free, -non-exclusive license: - -(a) under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - -(b) under Patent Claims of such Contributor to make, use, sell, offer - for sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - -The licenses granted in Section 2.1 with respect to any Contribution -become effective for each Contribution on the date the Contributor first -distributes such Contribution. - -2.3. Limitations on Grant Scope - -The licenses granted in this Section 2 are the only rights granted under -this License. No additional rights or licenses will be implied from the -distribution or licensing of Covered Software under this License. -Notwithstanding Section 2.1(b) above, no patent license is granted by a -Contributor: - -(a) for any code that a Contributor has removed from Covered Software; - or - -(b) for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - -(c) under Patent Claims infringed by Covered Software in the absence of - its Contributions. - -This License does not grant any rights in the trademarks, service marks, -or logos of any Contributor (except as may be necessary to comply with -the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - -No Contributor makes additional grants as a result of Your choice to -distribute the Covered Software under a subsequent version of this -License (see Section 10.2) or under the terms of a Secondary License (if -permitted under the terms of Section 3.3). - -2.5. Representation - -Each Contributor represents that the Contributor believes its -Contributions are its original creation(s) or it has sufficient rights -to grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - -This License is not intended to limit any rights You have under -applicable copyright doctrines of fair use, fair dealing, or other -equivalents. - -2.7. Conditions - -Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted -in Section 2.1. - -3. Responsibilities -------------------- - -3.1. Distribution of Source Form - -All distribution of Covered Software in Source Code Form, including any -Modifications that You create or to which You contribute, must be under -the terms of this License. You must inform recipients that the Source -Code Form of the Covered Software is governed by the terms of this -License, and how they can obtain a copy of this License. You may not -attempt to alter or restrict the recipients' rights in the Source Code -Form. - -3.2. Distribution of Executable Form - -If You distribute Covered Software in Executable Form then: - -(a) such Covered Software must also be made available in Source Code - Form, as described in Section 3.1, and You must inform recipients of - the Executable Form how they can obtain a copy of such Source Code - Form by reasonable means in a timely manner, at a charge no more - than the cost of distribution to the recipient; and - -(b) You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter - the recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - -You may create and distribute a Larger Work under terms of Your choice, -provided that You also comply with the requirements of this License for -the Covered Software. If the Larger Work is a combination of Covered -Software with a work governed by one or more Secondary Licenses, and the -Covered Software is not Incompatible With Secondary Licenses, this -License permits You to additionally distribute such Covered Software -under the terms of such Secondary License(s), so that the recipient of -the Larger Work may, at their option, further distribute the Covered -Software under the terms of either this License or such Secondary -License(s). - -3.4. Notices - -You may not remove or alter the substance of any license notices -(including copyright notices, patent notices, disclaimers of warranty, -or limitations of liability) contained within the Source Code Form of -the Covered Software, except that You may alter any license notices to -the extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - -You may choose to offer, and to charge a fee for, warranty, support, -indemnity or liability obligations to one or more recipients of Covered -Software. However, You may do so only on Your own behalf, and not on -behalf of any Contributor. You must make it absolutely clear that any -such warranty, support, indemnity, or liability obligation is offered by -You alone, and You hereby agree to indemnify every Contributor for any -liability incurred by such Contributor as a result of warranty, support, -indemnity or liability terms You offer. You may include additional -disclaimers of warranty and limitations of liability specific to any -jurisdiction. - -4. Inability to Comply Due to Statute or Regulation ---------------------------------------------------- - -If it is impossible for You to comply with any of the terms of this -License with respect to some or all of the Covered Software due to -statute, judicial order, or regulation then You must: (a) comply with -the terms of this License to the maximum extent possible; and (b) -describe the limitations and the code they affect. Such description must -be placed in a text file included with all distributions of the Covered -Software under this License. Except to the extent prohibited by statute -or regulation, such description must be sufficiently detailed for a -recipient of ordinary skill to be able to understand it. - -5. Termination --------------- - -5.1. The rights granted under this License will terminate automatically -if You fail to comply with any of its terms. However, if You become -compliant, then the rights granted under this License from a particular -Contributor are reinstated (a) provisionally, unless and until such -Contributor explicitly and finally terminates Your grants, and (b) on an -ongoing basis, if such Contributor fails to notify You of the -non-compliance by some reasonable means prior to 60 days after You have -come back into compliance. Moreover, Your grants from a particular -Contributor are reinstated on an ongoing basis if such Contributor -notifies You of the non-compliance by some reasonable means, this is the -first time You have received notice of non-compliance with this License -from such Contributor, and You become compliant prior to 30 days after -Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent -infringement claim (excluding declaratory judgment actions, -counter-claims, and cross-claims) alleging that a Contributor Version -directly or indirectly infringes any patent, then the rights granted to -You by any and all Contributors for the Covered Software under Section -2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all -end user license agreements (excluding distributors and resellers) which -have been validly granted by You or Your distributors under this License -prior to termination shall survive termination. - -************************************************************************ -* * -* 6. Disclaimer of Warranty * -* ------------------------- * -* * -* Covered Software is provided under this License on an "as is" * -* basis, without warranty of any kind, either expressed, implied, or * -* statutory, including, without limitation, warranties that the * -* Covered Software is free of defects, merchantable, fit for a * -* particular purpose or non-infringing. The entire risk as to the * -* quality and performance of the Covered Software is with You. * -* Should any Covered Software prove defective in any respect, You * -* (not any Contributor) assume the cost of any necessary servicing, * -* repair, or correction. This disclaimer of warranty constitutes an * -* essential part of this License. No use of any Covered Software is * -* authorized under this License except under this disclaimer. * -* * -************************************************************************ - -************************************************************************ -* * -* 7. Limitation of Liability * -* -------------------------- * -* * -* Under no circumstances and under no legal theory, whether tort * -* (including negligence), contract, or otherwise, shall any * -* Contributor, or anyone who distributes Covered Software as * -* permitted above, be liable to You for any direct, indirect, * -* special, incidental, or consequential damages of any character * -* including, without limitation, damages for lost profits, loss of * -* goodwill, work stoppage, computer failure or malfunction, or any * -* and all other commercial damages or losses, even if such party * -* shall have been informed of the possibility of such damages. This * -* limitation of liability shall not apply to liability for death or * -* personal injury resulting from such party's negligence to the * -* extent applicable law prohibits such limitation. Some * -* jurisdictions do not allow the exclusion or limitation of * -* incidental or consequential damages, so this exclusion and * -* limitation may not apply to You. * -* * -************************************************************************ - -8. Litigation -------------- - -Any litigation relating to this License may be brought only in the -courts of a jurisdiction where the defendant maintains its principal -place of business and such litigation shall be governed by laws of that -jurisdiction, without reference to its conflict-of-law provisions. -Nothing in this Section shall prevent a party's ability to bring -cross-claims or counter-claims. - -9. Miscellaneous ----------------- - -This License represents the complete agreement concerning the subject -matter hereof. If any provision of this License is held to be -unenforceable, such provision shall be reformed only to the extent -necessary to make it enforceable. Any law or regulation which provides -that the language of a contract shall be construed against the drafter -shall not be used to construe this License against a Contributor. - -10. Versions of the License ---------------------------- - -10.1. New Versions - -Mozilla Foundation is the license steward. Except as provided in Section -10.3, no one other than the license steward has the right to modify or -publish new versions of this License. Each version will be given a -distinguishing version number. - -10.2. Effect of New Versions - -You may distribute the Covered Software under the terms of the version -of the License under which You originally received the Covered Software, -or under the terms of any subsequent version published by the license -steward. - -10.3. Modified Versions - -If you create software not governed by this License, and you want to -create a new license for such software, you may create and use a -modified version of this License if you rename the license and remove -any references to the name of the license steward (except to note that -such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary -Licenses - -If You choose to distribute Source Code Form that is Incompatible With -Secondary Licenses under the terms of this version of the License, the -notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice -------------------------------------------- - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular -file, then You may include the notice in a location (such as a LICENSE -file in a relevant directory) where a recipient would be likely to look -for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice ---------------------------------------------------------- - - This Source Code Form is "Incompatible With Secondary Licenses", as - defined by the Mozilla Public License, v. 2.0. diff --git a/vendor/github.com/joyent/triton-go/README.md b/vendor/github.com/joyent/triton-go/README.md deleted file mode 100644 index 1089c72..0000000 --- a/vendor/github.com/joyent/triton-go/README.md +++ /dev/null @@ -1,215 +0,0 @@ -# triton-go - -`triton-go` is an idiomatic library exposing a client SDK for Go applications -using Joyent's Triton Compute and Storage (Manta) APIs. - -## Usage - -Triton uses [HTTP Signature][4] to sign the Date header in each HTTP request -made to the Triton API. Currently, requests can be signed using either a private -key file loaded from disk (using an [`authentication.PrivateKeySigner`][5]), or -using a key stored with the local SSH Agent (using an [`SSHAgentSigner`][6]. - -To construct a Signer, use the `New*` range of methods in the `authentication` -package. In the case of `authentication.NewSSHAgentSigner`, the parameters are -the fingerprint of the key with which to sign, and the account name (normally -stored in the `SDC_ACCOUNT` environment variable). For example: - -``` -const fingerprint := "a4:c6:f3:75:80:27:e0:03:a9:98:79:ef:c5:0a:06:11" -sshKeySigner, err := authentication.NewSSHAgentSigner(fingerprint, "AccountName") -if err != nil { - log.Fatalf("NewSSHAgentSigner: %s", err) -} -``` - -An appropriate key fingerprint can be generated using `ssh-keygen`. - -``` -ssh-keygen -Emd5 -lf ~/.ssh/id_rsa.pub | cut -d " " -f 2 | sed 's/MD5://' -``` - -Each top level package, `account`, `compute`, `identity`, `network`, all have -their own seperate client. In order to initialize a package client, simply pass -the global `triton.ClientConfig` struct into the client's constructor function. - -```go - config := &triton.ClientConfig{ - TritonURL: os.Getenv("SDC_URL"), - MantaURL: os.Getenv("MANTA_URL"), - AccountName: accountName, - Signers: []authentication.Signer{sshKeySigner}, - } - - c, err := compute.NewClient(config) - if err != nil { - log.Fatalf("compute.NewClient: %s", err) - } -``` - -Constructing `compute.Client` returns an interface which exposes `compute` API -resources. The same goes for all other packages. Reference their unique -documentation for more information. - -The same `triton.ClientConfig` will initialize the Manta `storage` client as -well... - -```go - c, err := storage.NewClient(config) - if err != nil { - log.Fatalf("storage.NewClient: %s", err) - } -``` - -## Error Handling - -If an error is returned by the HTTP API, the `error` returned from the function -will contain an instance of `compute.TritonError` in the chain. Error wrapping -is performed using the [errwrap][7] library from HashiCorp. - -## Acceptance Tests - -Acceptance Tests run directly against the Triton API, so you will need either a -local installation of Triton or an account with Joyent's Public Cloud offering -in order to run them. The tests create real resources (and thus cost real -money)! - -In order to run acceptance tests, the following environment variables must be -set: - -- `TRITON_TEST` - must be set to any value in order to indicate desire to create - resources -- `SDC_URL` - the base endpoint for the Triton API -- `SDC_ACCOUNT` - the account name for the Triton API -- `SDC_KEY_ID` - the fingerprint of the SSH key identifying the key - -Additionally, you may set `SDC_KEY_MATERIAL` to the contents of an unencrypted -private key. If this is set, the PrivateKeySigner (see above) will be used - if -not the SSHAgentSigner will be used. - -### Example Run - -The verbose output has been removed for brevity here. - -``` -$ HTTP_PROXY=http://localhost:8888 \ - TRITON_TEST=1 \ - SDC_URL=https://us-sw-1.api.joyent.com \ - SDC_ACCOUNT=AccountName \ - SDC_KEY_ID=a4:c6:f3:75:80:27:e0:03:a9:98:79:ef:c5:0a:06:11 \ - go test -v -run "TestAccKey" -=== RUN TestAccKey_Create ---- PASS: TestAccKey_Create (12.46s) -=== RUN TestAccKey_Get ---- PASS: TestAccKey_Get (4.30s) -=== RUN TestAccKey_Delete ---- PASS: TestAccKey_Delete (15.08s) -PASS -ok github.com/joyent/triton-go 31.861s -``` - -## Example API - -There's an `examples/` directory available with sample code setup for many of -the APIs within this library. Most of these can be run using `go run` and -referencing your SSH key file use by your active `triton` CLI profile. - -```sh -$ eval "$(triton env us-sw-1)" -$ SDC_KEY_FILE=~/.ssh/triton-id_rsa go run examples/compute/instances.go -``` - -The following is a complete example of how to initialize the `compute` package -client and list all instances under an account. More detailed usage of this -library follows. - -```go - - -package main - -import ( - "context" - "fmt" - "io/ioutil" - "log" - "os" - "time" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/compute" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: {{err}}", err) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: {{err}}", err) - } - } - - config := &triton.ClientConfig{ - TritonURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - c, err := compute.NewClient(config) - if err != nil { - log.Fatalf("compute.NewClient: %s", err) - } - - listInput := &compute.ListInstancesInput{} - instances, err := c.Instances().List(context.Background(), listInput) - if err != nil { - log.Fatalf("compute.Instances.List: %v", err) - } - numInstances := 0 - for _, instance := range instances { - numInstances++ - fmt.Println(fmt.Sprintf("-- Instance: %v", instance.Name)) - } -} - -``` - -[4]: https://github.com/joyent/node-http-signature/blob/master/http_signing.md -[5]: https://godoc.org/github.com/joyent/triton-go/authentication -[6]: https://godoc.org/github.com/joyent/triton-go/authentication -[7]: https://github.com/hashicorp/go-errwrap diff --git a/vendor/github.com/joyent/triton-go/account/account.go b/vendor/github.com/joyent/triton-go/account/account.go deleted file mode 100644 index cb71dd7..0000000 --- a/vendor/github.com/joyent/triton-go/account/account.go +++ /dev/null @@ -1,95 +0,0 @@ -package account - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type Account struct { - ID string `json:"id"` - Login string `json:"login"` - Email string `json:"email"` - CompanyName string `json:"companyName"` - FirstName string `json:"firstName"` - LastName string `json:"lastName"` - Address string `json:"address"` - PostalCode string `json:"postalCode"` - City string `json:"city"` - State string `json:"state"` - Country string `json:"country"` - Phone string `json:"phone"` - Created time.Time `json:"created"` - Updated time.Time `json:"updated"` - TritonCNSEnabled bool `json:"triton_cns_enabled"` -} - -type GetInput struct{} - -func (c AccountClient) Get(ctx context.Context, input *GetInput) (*Account, error) { - path := fmt.Sprintf("/%s", c.Client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.Client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetAccount request: {{err}}", err) - } - - var result *Account - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding GetAccount response: {{err}}", err) - } - - return result, nil -} - -type UpdateInput struct { - Email string `json:"email,omitempty"` - CompanyName string `json:"companyName,omitempty"` - FirstName string `json:"firstName,omitempty"` - LastName string `json:"lastName,omitempty"` - Address string `json:"address,omitempty"` - PostalCode string `json:"postalCode,omitempty"` - City string `json:"city,omitempty"` - State string `json:"state,omitempty"` - Country string `json:"country,omitempty"` - Phone string `json:"phone,omitempty"` - TritonCNSEnabled bool `json:"triton_cns_enabled,omitempty"` -} - -// UpdateAccount updates your account details with the given parameters. -// TODO(jen20) Work out a safe way to test this -func (c AccountClient) Update(ctx context.Context, input *UpdateInput) (*Account, error) { - path := fmt.Sprintf("/%s", c.Client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.Client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing UpdateAccount request: {{err}}", err) - } - - var result *Account - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding UpdateAccount response: {{err}}", err) - } - - return result, nil -} diff --git a/vendor/github.com/joyent/triton-go/account/account_test.go b/vendor/github.com/joyent/triton-go/account/account_test.go deleted file mode 100644 index af9da63..0000000 --- a/vendor/github.com/joyent/triton-go/account/account_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package account - -import ( - "context" - "testing" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/testutils" -) - -func TestAccAccount_Get(t *testing.T) { - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "account", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "account", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*AccountClient) - ctx := context.Background() - input := &GetInput{} - return c.Get(ctx, input) - }, - }, - - &testutils.StepAssertSet{ - StateBagKey: "account", - Keys: []string{"ID", "Login", "Email"}, - }, - }, - }) -} diff --git a/vendor/github.com/joyent/triton-go/account/client.go b/vendor/github.com/joyent/triton-go/account/client.go deleted file mode 100644 index d8d5623..0000000 --- a/vendor/github.com/joyent/triton-go/account/client.go +++ /dev/null @@ -1,39 +0,0 @@ -package account - -import ( - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/client" -) - -type AccountClient struct { - Client *client.Client -} - -func newAccountClient(client *client.Client) *AccountClient { - return &AccountClient{ - Client: client, - } -} - -// NewClient returns a new client for working with Account endpoints and -// resources within CloudAPI -func NewClient(config *triton.ClientConfig) (*AccountClient, error) { - // TODO: Utilize config interface within the function itself - client, err := client.New(config.TritonURL, config.MantaURL, config.AccountName, config.Signers...) - if err != nil { - return nil, err - } - return newAccountClient(client), nil -} - -// Config returns a c used for accessing functions pertaining -// to Config functionality in the Triton API. -func (c *AccountClient) Config() *ConfigClient { - return &ConfigClient{c.Client} -} - -// Keys returns a Compute client used for accessing functions pertaining to SSH -// key functionality in the Triton API. -func (c *AccountClient) Keys() *KeysClient { - return &KeysClient{c.Client} -} diff --git a/vendor/github.com/joyent/triton-go/account/config.go b/vendor/github.com/joyent/triton-go/account/config.go deleted file mode 100644 index 05cf130..0000000 --- a/vendor/github.com/joyent/triton-go/account/config.go +++ /dev/null @@ -1,77 +0,0 @@ -package account - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type ConfigClient struct { - client *client.Client -} - -// Config represents configuration for your account. -type Config struct { - // DefaultNetwork is the network that docker containers are provisioned on. - DefaultNetwork string `json:"default_network"` -} - -type GetConfigInput struct{} - -// GetConfig outputs configuration for your account. -func (c *ConfigClient) Get(ctx context.Context, input *GetConfigInput) (*Config, error) { - path := fmt.Sprintf("/%s/config", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetConfig request: {{err}}", err) - } - - var result *Config - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding GetConfig response: {{err}}", err) - } - - return result, nil -} - -type UpdateConfigInput struct { - // DefaultNetwork is the network that docker containers are provisioned on. - DefaultNetwork string `json:"default_network"` -} - -// UpdateConfig updates configuration values for your account. -func (c *ConfigClient) Update(ctx context.Context, input *UpdateConfigInput) (*Config, error) { - path := fmt.Sprintf("/%s/config", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodPut, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing UpdateConfig request: {{err}}", err) - } - - var result *Config - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding UpdateConfig response: {{err}}", err) - } - - return result, nil -} diff --git a/vendor/github.com/joyent/triton-go/account/config_test.go b/vendor/github.com/joyent/triton-go/account/config_test.go deleted file mode 100644 index 3e0f5cb..0000000 --- a/vendor/github.com/joyent/triton-go/account/config_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package account - -import ( - "context" - "testing" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/testutils" -) - -func TestAccConfig_Get(t *testing.T) { - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "config", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "config", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*AccountClient) - ctx := context.Background() - input := &GetConfigInput{} - return c.Config().Get(ctx, input) - }, - }, - &testutils.StepAssertSet{ - StateBagKey: "config", - Keys: []string{"DefaultNetwork"}, - }, - }, - }) -} diff --git a/vendor/github.com/joyent/triton-go/account/keys.go b/vendor/github.com/joyent/triton-go/account/keys.go deleted file mode 100644 index f40788d..0000000 --- a/vendor/github.com/joyent/triton-go/account/keys.go +++ /dev/null @@ -1,137 +0,0 @@ -package account - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type KeysClient struct { - client *client.Client -} - -// Key represents a public key -type Key struct { - // Name of the key - Name string `json:"name"` - - // Key fingerprint - Fingerprint string `json:"fingerprint"` - - // OpenSSH-formatted public key - Key string `json:"key"` -} - -type ListKeysInput struct{} - -// ListKeys lists all public keys we have on record for the specified -// account. -func (c *KeysClient) List(ctx context.Context, _ *ListKeysInput) ([]*Key, error) { - path := fmt.Sprintf("/%s/keys", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListKeys request: {{err}}", err) - } - - var result []*Key - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListKeys response: {{err}}", err) - } - - return result, nil -} - -type GetKeyInput struct { - KeyName string -} - -func (c *KeysClient) Get(ctx context.Context, input *GetKeyInput) (*Key, error) { - path := fmt.Sprintf("/%s/keys/%s", c.client.AccountName, input.KeyName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetKey request: {{err}}", err) - } - - var result *Key - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding GetKey response: {{err}}", err) - } - - return result, nil -} - -type DeleteKeyInput struct { - KeyName string -} - -func (c *KeysClient) Delete(ctx context.Context, input *DeleteKeyInput) error { - path := fmt.Sprintf("/%s/keys/%s", c.client.AccountName, input.KeyName) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteKey request: {{err}}", err) - } - - return nil -} - -// CreateKeyInput represents the option that can be specified -// when creating a new key. -type CreateKeyInput struct { - // Name of the key. Optional. - Name string `json:"name,omitempty"` - - // OpenSSH-formatted public key. - Key string `json:"key"` -} - -// CreateKey uploads a new OpenSSH key to Triton for use in HTTP signing and SSH. -func (c *KeysClient) Create(ctx context.Context, input *CreateKeyInput) (*Key, error) { - path := fmt.Sprintf("/%s/keys", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing CreateKey request: {{err}}", err) - } - - var result *Key - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding CreateKey response: {{err}}", err) - } - - return result, nil -} diff --git a/vendor/github.com/joyent/triton-go/account/keys_test.go b/vendor/github.com/joyent/triton-go/account/keys_test.go deleted file mode 100644 index cd6c8d1..0000000 --- a/vendor/github.com/joyent/triton-go/account/keys_test.go +++ /dev/null @@ -1,182 +0,0 @@ -package account - -import ( - "context" - "testing" - - "github.com/abdullin/seq" - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/testutils" -) - -func TestAccKey_Create(t *testing.T) { - keyName := testutils.RandPrefixString("TestAccCreateKey", 32) - - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "key", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "key", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*AccountClient) - ctx := context.Background() - input := &CreateKeyInput{ - Name: keyName, - Key: testAccCreateKeyMaterial, - } - return c.Keys().Create(ctx, input) - }, - CleanupFunc: func(client interface{}, callState interface{}) { - c := client.(*AccountClient) - ctx := context.Background() - input := &DeleteKeyInput{ - KeyName: keyName, - } - c.Keys().Delete(ctx, input) - }, - }, - &testutils.StepAssert{ - StateBagKey: "key", - Assertions: seq.Map{ - "name": keyName, - "key": testAccCreateKeyMaterial, - "fingerprint": testAccCreateKeyFingerprint, - }, - }, - }, - }) -} - -func TestAccKey_Get(t *testing.T) { - keyName := testutils.RandPrefixString("TestAccGetKey", 32) - - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "key", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "key", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*AccountClient) - ctx := context.Background() - input := &CreateKeyInput{ - Name: keyName, - Key: testAccCreateKeyMaterial, - } - return c.Keys().Create(ctx, input) - }, - CleanupFunc: func(client interface{}, callState interface{}) { - c := client.(*AccountClient) - ctx := context.Background() - input := &DeleteKeyInput{ - KeyName: keyName, - } - c.Keys().Delete(ctx, input) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "getKey", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*AccountClient) - ctx := context.Background() - input := &GetKeyInput{ - KeyName: keyName, - } - return c.Keys().Get(ctx, input) - }, - }, - - &testutils.StepAssert{ - StateBagKey: "getKey", - Assertions: seq.Map{ - "name": keyName, - "key": testAccCreateKeyMaterial, - "fingerprint": testAccCreateKeyFingerprint, - }, - }, - }, - }) -} - -func TestAccKey_Delete(t *testing.T) { - keyName := testutils.RandPrefixString("TestAccGetKey", 32) - - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "key", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "key", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*AccountClient) - ctx := context.Background() - input := &CreateKeyInput{ - Name: keyName, - Key: testAccCreateKeyMaterial, - } - return c.Keys().Create(ctx, input) - }, - CleanupFunc: func(client interface{}, callState interface{}) { - c := client.(*AccountClient) - ctx := context.Background() - input := &DeleteKeyInput{ - KeyName: keyName, - } - c.Keys().Delete(ctx, input) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "noop", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*AccountClient) - ctx := context.Background() - input := &DeleteKeyInput{ - KeyName: keyName, - } - return nil, c.Keys().Delete(ctx, input) - }, - }, - - &testutils.StepAPICall{ - ErrorKey: "getKeyError", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*AccountClient) - ctx := context.Background() - input := &GetKeyInput{ - KeyName: keyName, - } - return c.Keys().Get(ctx, input) - }, - }, - - &testutils.StepAssertTritonError{ - ErrorKey: "getKeyError", - Code: "ResourceNotFound", - }, - }, - }) -} - -const testAccCreateKeyMaterial = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBOJ5z6jTdY3SYK2Nc+MQLSQstAOzxFqDN00MJ9SMhJea8ZQbZFlhCAZBFE4TUBDI3zXBxFjygh84lb1QlNu1dmZeoQ10MThuowZllBAfg9Eb5RkXqLvDdYh9+rLdEdUL4+aiYZ8JYtQ+K5ZnogZoxdzNQ3WnVhMGJIrj1zcRveUSvQ6tMhaEQDxDWrAMDLxnLI/6SNmkhdF1ZKE8iQ+BnazYp0vg5jAzkHzEYJY9kFUOubupOxio93B9OTkpQ0jZD+J9iR1t8Me3JdhHy85inaAFc0fkjznDYluV8aqfIprD/WE9grQ/GfEYfsvQdQr1ljLBJZdad7DvnKqU0M4vJ James@jn-mpb15` -const testAccCreateKeyFingerprint = `ab:f4:8f:bc:26:e1:cf:1d:06:a3:9d:40:39:7c:5a:78` diff --git a/vendor/github.com/joyent/triton-go/authentication/dummy.go b/vendor/github.com/joyent/triton-go/authentication/dummy.go deleted file mode 100644 index cd16273..0000000 --- a/vendor/github.com/joyent/triton-go/authentication/dummy.go +++ /dev/null @@ -1,72 +0,0 @@ -package authentication - -// DON'T USE THIS OUTSIDE TESTING ~ This key was only created to use for -// internal unit testing. It should never be used for acceptance testing either. -// -// This is just a randomly generated key pair. -var Dummy = struct { - Fingerprint string - PrivateKey []byte - PublicKey []byte - Signer Signer -}{ - "9f:d6:65:fc:d6:60:dc:d0:4e:db:2d:75:f7:92:8c:31", - []byte(`-----BEGIN RSA PRIVATE KEY----- -MIIJKAIBAAKCAgEAui9lNjCJahHeFSFC6HXi/CNX588C/L2gJUx65bnNphVC98hW -1wzoRvPXHx5aWnb7lEbpNhP6B0UoCBDTaPgt9hHfD/oNQ+6HT1QpDIGfZmXI91/t -cjGVSBbxN7WaYt/HsPrGjbalwvQPChN53sMVmFkMTEDR5G3zOBOAGrOimlCT80wI -2S5Xg0spd8jjKM5I1swDR0xtuDWnHTR1Ohin+pEQIE6glLTfYq7oQx6nmMXXBNmk -+SaPD1FAyjkF/81im2EHXBygNEwraVrDcAxK2mKlU2XMJiogQKNYWlm3UkbNB6WP -Le12+Ka02rmIVsSqIpc/ZCBraAlCaSWlYCkU+vJ2hH/+ypy5bXNlbaTiWZK+vuI7 -PC87T50yLNeXVuNZAynzDpBCvsjiiHrB/ZFRfVfF6PviV8CV+m7GTzfAwJhVeSbl -rR6nts16K0HTD48v57DU0b0t5VOvC7cWPShs+afdSL3Z8ReL5EWMgU1wfvtycRKe -hiDVGj3Ms2cf83RIANr387G+1LcTQYP7JJuB7Svy5j+R6+HjI0cgu4EMUPdWfCNG -GyrlxwJNtPmUSfasH1xUKpqr7dC+0sN4/gfJw75WTAYrATkPzexoYNaMsGDfhuoh -kYa3Tn2q1g3kqhsX/R0Fd5d8d5qc137qcRCxiZYz9f3bVkXQbhYmO9da3KsCAwEA -AQKCAgAeEAURqOinPddUJhi9nDtYZwSMo3piAORY4W5+pW+1P32esLSE6MqgmkLD -/YytSsT4fjKtzq/yeJIsKztXmasiLmSMGd4Gd/9VKcuu/0cTq5+1gcG/TI5EI6Az -VJlnGacOxo9E1pcRUYMUJ2zoMSvNe6NmtJivf6lkBpIKvbKlpBkfkclj9/2db4d0 -lfVH43cTZ8Gnw4l70v320z+Sb+S/qqil7swy9rmTH5bVL5/0JQ3A9LuUl0tGN+J0 -RJzZXvprCFG958leaGYiDsu7zeBQPtlfC/LYvriSd02O2SmmmVQFxg/GZK9vGsvc -/VQsXnjyOOW9bxaop8YXYELBsiB21ipTHzOwoqHT8wFnjgU9Y/7iZIv7YbZKQsCS -DrwdlZ/Yw90wiif+ldYryIVinWfytt6ERv4Dgezc98+1XPi1Z/WB74/lIaDXFl3M -3ypjtvLYbKew2IkIjeAwjvZJg/QpC/50RrrPtVDgeAI1Ni01ikixUhMYsHJ1kRih -0tqLvLqSPoHmr6luFlaoKdc2eBqb+8U6K/TrXhKtT7BeUFiSbvnVfdbrH9r+AY/2 -zYtG6llzkE5DH8ZR3Qp+dx7QEDtvYhGftWhx9uasd79AN7CuGYnL54YFLKGRrWKN -ylysqfUyOQYiitdWdNCw9PP2vGRx5JAsMMSy+ft18jjTJvNQ0QKCAQEA28M11EE6 -MpnHxfyP00Dl1+3wl2lRyNXZnZ4hgkk1f83EJGpoB2amiMTF8P1qJb7US1fXtf7l -gkJMMk6t6iccexV1/NBh/7tDZHH/v4HPirFTXQFizflaghD8dEADy9DY4BpQYFRe -8zGsv4/4U0txCXkUIfKcENt/FtXv2T9blJT6cDV0yTx9IAyd4Kor7Ly2FIYroSME -uqnOQt5PwB+2qkE+9hdg4xBhFs9sW5dvyBvQvlBfX/xOmMw2ygH6vsaJlNfZ5VPa -EP/wFP/qHyhDlCfbHdL6qF2//wUoM2QM9RgBdZNhcKU7zWuf7Ev199tmlLC5O14J -PkQxUGftMfmWxQKCAQEA2OLKD8dwOzpwGJiPQdBmGpwCamfcCY4nDwqEaCu4vY1R -OJR+rpYdC2hgl5PTXWH7qzJVdT/ZAz2xUQOgB1hD3Ltk7DQ+EZIA8+vJdaicQOme -vfpMPNDxCEX9ee0AXAmAC3aET82B4cMFnjXjl1WXLLTowF/Jp/hMorm6tl2m15A2 -oTyWlB/i/W/cxHl2HFWK7o8uCNoKpKJjheNYn+emEcH1bkwrk8sxQ78cBNmqe/gk -MLgu8qfXQ0LLKIL7wqmIUHeUpkepOod8uXcTmmN2X9saCIwFKx4Jal5hh5v5cy0G -MkyZcUIhhnmzr7lXbepauE5V2Sj5Qp040AfRVjZcrwKCAQANe8OwuzPL6P2F20Ij -zwaLIhEx6QdYkC5i6lHaAY3jwoc3SMQLODQdjh0q9RFvMW8rFD+q7fG89T5hk8w9 -4ppvvthXY52vqBixcAEmCdvnAYxA15XtV1BDTLGAnHDfL3gu/85QqryMpU6ZDkdJ -LQbJcwFWN+F1c1Iv335w0N9YlW9sNQtuUWTH8544K5i4VLfDOJwyrchbf5GlLqir -/AYkGg634KVUKSwbzywxzm/QUkyTcLD5Xayg2V6/NDHjRKEqXbgDxwpJIrrjPvRp -ZvoGfA+Im+o/LElcZz+ZL5lP7GIiiaFf3PN3XhQY1mxIAdEgbFthFhrxFBQGf+ng -uBSVAoIBAHl12K8pg8LHoUtE9MVoziWMxRWOAH4ha+JSg4BLK/SLlbbYAnIHg1CG -LcH1eWNMokJnt9An54KXJBw4qYAzgB23nHdjcncoivwPSg1oVclMjCfcaqGMac+2 -UpPblF32vAyvXL3MWzZxn03Q5Bo2Rqk0zzwc6LP2rARdeyDyJaOHEfEOG03s5ZQE -91/YnbqUdW/QI3m1kkxM3Ot4PIOgmTJMqwQQCD+GhZppBmn49C7k8m+OVkxyjm0O -lPOlFxUXGE3oCgltDGrIwaKj+wh1Ny/LZjLvJ13UPnWhUYE+al6EEnpMx4nT/S5w -LZ71bu8RVajtxcoN1jnmDpECL8vWOeUCggEBAIEuKoY7pVHfs5gr5dXfQeVZEtqy -LnSdsd37/aqQZRlUpVmBrPNl1JBLiEVhk2SL3XJIDU4Er7f0idhtYLY3eE7wqZ4d -38Iaj5tv3zBc/wb1bImPgOgXCH7QrrbW7uTiYMLScuUbMR4uSpfubLaV8Zc9WHT8 -kTJ2pKKtA1GPJ4V7HCIxuTjD2iyOK1CRkaqSC+5VUuq5gHf92CEstv9AIvvy5cWg -gnfBQoS89m3aO035henSfRFKVJkHaEoasj8hB3pwl9FGZUJp1c2JxiKzONqZhyGa -6tcIAM3od0QtAfDJ89tWJ5D31W8KNNysobFSQxZ62WgLUUtXrkN1LGodxGQ= ------END RSA PRIVATE KEY-----`), - []byte(`ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC6L2U2MIlqEd4VIULodeL8I1fnzwL8vaAlTHrluc2mFUL3yFbXDOhG89cfHlpadvuURuk2E/oHRSgIENNo+C32Ed8P+g1D7odPVCkMgZ9mZcj3X+1yMZVIFvE3tZpi38ew+saNtqXC9A8KE3newxWYWQxMQNHkbfM4E4Aas6KaUJPzTAjZLleDSyl3yOMozkjWzANHTG24NacdNHU6GKf6kRAgTqCUtN9iruhDHqeYxdcE2aT5Jo8PUUDKOQX/zWKbYQdcHKA0TCtpWsNwDEraYqVTZcwmKiBAo1haWbdSRs0HpY8t7Xb4prTauYhWxKoilz9kIGtoCUJpJaVgKRT68naEf/7KnLltc2VtpOJZkr6+4js8LztPnTIs15dW41kDKfMOkEK+yOKIesH9kVF9V8Xo++JXwJX6bsZPN8DAmFV5JuWtHqe2zXorQdMPjy/nsNTRvS3lU68LtxY9KGz5p91IvdnxF4vkRYyBTXB++3JxEp6GINUaPcyzZx/zdEgA2vfzsb7UtxNBg/skm4HtK/LmP5Hr4eMjRyC7gQxQ91Z8I0YbKuXHAk20+ZRJ9qwfXFQqmqvt0L7Sw3j+B8nDvlZMBisBOQ/N7Ghg1oywYN+G6iGRhrdOfarWDeSqGxf9HQV3l3x3mpzXfupxELGJljP1/dtWRdBuFiY711rcqw== test-dummy-20171002140848`), - nil, -} - -func init() { - testSigner, _ := NewTestSigner() - Dummy.Signer = testSigner -} diff --git a/vendor/github.com/joyent/triton-go/authentication/ecdsa_signature.go b/vendor/github.com/joyent/triton-go/authentication/ecdsa_signature.go deleted file mode 100644 index 8aaba97..0000000 --- a/vendor/github.com/joyent/triton-go/authentication/ecdsa_signature.go +++ /dev/null @@ -1,66 +0,0 @@ -package authentication - -import ( - "encoding/asn1" - "encoding/base64" - "fmt" - "math/big" - - "github.com/hashicorp/errwrap" - "golang.org/x/crypto/ssh" -) - -type ecdsaSignature struct { - hashAlgorithm string - R *big.Int - S *big.Int -} - -func (s *ecdsaSignature) SignatureType() string { - return fmt.Sprintf("ecdsa-%s", s.hashAlgorithm) -} - -func (s *ecdsaSignature) String() string { - toEncode := struct { - R *big.Int - S *big.Int - }{ - R: s.R, - S: s.S, - } - - signatureBytes, err := asn1.Marshal(toEncode) - if err != nil { - panic(fmt.Sprintf("Error marshaling signature: %s", err)) - } - - return base64.StdEncoding.EncodeToString(signatureBytes) -} - -func newECDSASignature(signatureBlob []byte) (*ecdsaSignature, error) { - var ecSig struct { - R *big.Int - S *big.Int - } - - if err := ssh.Unmarshal(signatureBlob, &ecSig); err != nil { - return nil, errwrap.Wrapf("Error unmarshaling signature: {{err}}", err) - } - - rValue := ecSig.R.Bytes() - var hashAlgorithm string - switch len(rValue) { - case 31, 32: - hashAlgorithm = "sha256" - case 65, 66: - hashAlgorithm = "sha512" - default: - return nil, fmt.Errorf("Unsupported key length: %d", len(rValue)) - } - - return &ecdsaSignature{ - hashAlgorithm: hashAlgorithm, - R: ecSig.R, - S: ecSig.S, - }, nil -} diff --git a/vendor/github.com/joyent/triton-go/authentication/private_key_signer.go b/vendor/github.com/joyent/triton-go/authentication/private_key_signer.go deleted file mode 100644 index 43bc286..0000000 --- a/vendor/github.com/joyent/triton-go/authentication/private_key_signer.go +++ /dev/null @@ -1,106 +0,0 @@ -package authentication - -import ( - "crypto" - "crypto/rand" - "crypto/rsa" - "crypto/x509" - "encoding/base64" - "encoding/pem" - "errors" - "fmt" - "strings" - - "github.com/hashicorp/errwrap" - "golang.org/x/crypto/ssh" -) - -type PrivateKeySigner struct { - formattedKeyFingerprint string - keyFingerprint string - algorithm string - accountName string - hashFunc crypto.Hash - - privateKey *rsa.PrivateKey -} - -func NewPrivateKeySigner(keyFingerprint string, privateKeyMaterial []byte, accountName string) (*PrivateKeySigner, error) { - keyFingerprintMD5 := strings.Replace(keyFingerprint, ":", "", -1) - - block, _ := pem.Decode(privateKeyMaterial) - if block == nil { - return nil, errors.New("Error PEM-decoding private key material: nil block received") - } - - rsakey, err := x509.ParsePKCS1PrivateKey(block.Bytes) - if err != nil { - return nil, errwrap.Wrapf("Error parsing private key: {{err}}", err) - } - - sshPublicKey, err := ssh.NewPublicKey(rsakey.Public()) - if err != nil { - return nil, errwrap.Wrapf("Error parsing SSH key from private key: {{err}}", err) - } - - matchKeyFingerprint := formatPublicKeyFingerprint(sshPublicKey, false) - displayKeyFingerprint := formatPublicKeyFingerprint(sshPublicKey, true) - if matchKeyFingerprint != keyFingerprintMD5 { - return nil, errors.New("Private key file does not match public key fingerprint") - } - - signer := &PrivateKeySigner{ - formattedKeyFingerprint: displayKeyFingerprint, - keyFingerprint: keyFingerprint, - accountName: accountName, - - hashFunc: crypto.SHA1, - privateKey: rsakey, - } - - _, algorithm, err := signer.SignRaw("HelloWorld") - if err != nil { - return nil, fmt.Errorf("Cannot sign using ssh agent: %s", err) - } - signer.algorithm = algorithm - - return signer, nil -} - -func (s *PrivateKeySigner) Sign(dateHeader string) (string, error) { - const headerName = "date" - - hash := s.hashFunc.New() - hash.Write([]byte(fmt.Sprintf("%s: %s", headerName, dateHeader))) - digest := hash.Sum(nil) - - signed, err := rsa.SignPKCS1v15(rand.Reader, s.privateKey, s.hashFunc, digest) - if err != nil { - return "", errwrap.Wrapf("Error signing date header: {{err}}", err) - } - signedBase64 := base64.StdEncoding.EncodeToString(signed) - - keyID := fmt.Sprintf("/%s/keys/%s", s.accountName, s.formattedKeyFingerprint) - return fmt.Sprintf(authorizationHeaderFormat, keyID, "rsa-sha1", headerName, signedBase64), nil -} - -func (s *PrivateKeySigner) SignRaw(toSign string) (string, string, error) { - hash := s.hashFunc.New() - hash.Write([]byte(toSign)) - digest := hash.Sum(nil) - - signed, err := rsa.SignPKCS1v15(rand.Reader, s.privateKey, s.hashFunc, digest) - if err != nil { - return "", "", errwrap.Wrapf("Error signing date header: {{err}}", err) - } - signedBase64 := base64.StdEncoding.EncodeToString(signed) - return signedBase64, "rsa-sha1", nil -} - -func (s *PrivateKeySigner) KeyFingerprint() string { - return s.formattedKeyFingerprint -} - -func (s *PrivateKeySigner) DefaultAlgorithm() string { - return s.algorithm -} diff --git a/vendor/github.com/joyent/triton-go/authentication/rsa_signature.go b/vendor/github.com/joyent/triton-go/authentication/rsa_signature.go deleted file mode 100644 index 8d513f6..0000000 --- a/vendor/github.com/joyent/triton-go/authentication/rsa_signature.go +++ /dev/null @@ -1,25 +0,0 @@ -package authentication - -import ( - "encoding/base64" -) - -type rsaSignature struct { - hashAlgorithm string - signature []byte -} - -func (s *rsaSignature) SignatureType() string { - return s.hashAlgorithm -} - -func (s *rsaSignature) String() string { - return base64.StdEncoding.EncodeToString(s.signature) -} - -func newRSASignature(signatureBlob []byte) (*rsaSignature, error) { - return &rsaSignature{ - hashAlgorithm: "rsa-sha1", - signature: signatureBlob, - }, nil -} diff --git a/vendor/github.com/joyent/triton-go/authentication/signature.go b/vendor/github.com/joyent/triton-go/authentication/signature.go deleted file mode 100644 index e6a52df..0000000 --- a/vendor/github.com/joyent/triton-go/authentication/signature.go +++ /dev/null @@ -1,27 +0,0 @@ -package authentication - -import ( - "regexp" - "fmt" -) - -type httpAuthSignature interface { - SignatureType() string - String() string -} - -func keyFormatToKeyType(keyFormat string) (string, error) { - if keyFormat == "ssh-rsa" { - return "rsa", nil - } - - if keyFormat == "ssh-ed25519" { - return "ed25519", nil - } - - if regexp.MustCompile("^ecdsa-sha2-*").Match([]byte(keyFormat)) { - return "ecdsa", nil - } - - return "", fmt.Errorf("Unknown key format: %s", keyFormat) -} diff --git a/vendor/github.com/joyent/triton-go/authentication/signer.go b/vendor/github.com/joyent/triton-go/authentication/signer.go deleted file mode 100644 index 6e3d31d..0000000 --- a/vendor/github.com/joyent/triton-go/authentication/signer.go +++ /dev/null @@ -1,10 +0,0 @@ -package authentication - -const authorizationHeaderFormat = `Signature keyId="%s",algorithm="%s",headers="%s",signature="%s"` - -type Signer interface { - DefaultAlgorithm() string - KeyFingerprint() string - Sign(dateHeader string) (string, error) - SignRaw(toSign string) (string, string, error) -} diff --git a/vendor/github.com/joyent/triton-go/authentication/ssh_agent_signer.go b/vendor/github.com/joyent/triton-go/authentication/ssh_agent_signer.go deleted file mode 100644 index 3da4a68..0000000 --- a/vendor/github.com/joyent/triton-go/authentication/ssh_agent_signer.go +++ /dev/null @@ -1,170 +0,0 @@ -package authentication - -import ( - "crypto/md5" - "crypto/sha256" - "encoding/base64" - "errors" - "fmt" - "net" - "os" - "strings" - - "github.com/hashicorp/errwrap" - "golang.org/x/crypto/ssh" - "golang.org/x/crypto/ssh/agent" -) - -var ( - ErrUnsetEnvVar = errors.New("SSH_AUTH_SOCK is not set") -) - -type SSHAgentSigner struct { - formattedKeyFingerprint string - keyFingerprint string - algorithm string - accountName string - keyIdentifier string - - agent agent.Agent - key ssh.PublicKey -} - -func NewSSHAgentSigner(keyFingerprint, accountName string) (*SSHAgentSigner, error) { - sshAgentAddress, agentOk := os.LookupEnv("SSH_AUTH_SOCK") - if !agentOk { - return nil, ErrUnsetEnvVar - } - - conn, err := net.Dial("unix", sshAgentAddress) - if err != nil { - return nil, errwrap.Wrapf("Error dialing SSH agent: {{err}}", err) - } - - ag := agent.NewClient(conn) - - signer := &SSHAgentSigner{ - keyFingerprint: keyFingerprint, - accountName: accountName, - agent: ag, - } - - matchingKey, err := signer.MatchKey() - if err != nil { - return nil, err - } - signer.key = matchingKey - signer.formattedKeyFingerprint = formatPublicKeyFingerprint(signer.key, true) - signer.keyIdentifier = fmt.Sprintf("/%s/keys/%s", signer.accountName, signer.formattedKeyFingerprint) - - _, algorithm, err := signer.SignRaw("HelloWorld") - if err != nil { - return nil, fmt.Errorf("Cannot sign using ssh agent: %s", err) - } - signer.algorithm = algorithm - - return signer, nil -} - -func (s *SSHAgentSigner) MatchKey() (ssh.PublicKey, error) { - keys, err := s.agent.List() - if err != nil { - return nil, errwrap.Wrapf("Error listing keys in SSH Agent: %s", err) - } - - keyFingerprintStripped := strings.TrimPrefix(s.keyFingerprint, "MD5:") - keyFingerprintStripped = strings.TrimPrefix(keyFingerprintStripped, "SHA256:") - keyFingerprintStripped = strings.Replace(keyFingerprintStripped, ":", "", -1) - - var matchingKey ssh.PublicKey - for _, key := range keys { - keyMD5 := md5.New() - keyMD5.Write(key.Marshal()) - finalizedMD5 := fmt.Sprintf("%x", keyMD5.Sum(nil)) - - keySHA256 := sha256.New() - keySHA256.Write(key.Marshal()) - finalizedSHA256 := base64.RawStdEncoding.EncodeToString(keySHA256.Sum(nil)) - - if keyFingerprintStripped == finalizedMD5 || keyFingerprintStripped == finalizedSHA256 { - matchingKey = key - } - } - - if matchingKey == nil { - return nil, fmt.Errorf("No key in the SSH Agent matches fingerprint: %s", s.keyFingerprint) - } - - return matchingKey, nil -} - -func (s *SSHAgentSigner) Sign(dateHeader string) (string, error) { - const headerName = "date" - - signature, err := s.agent.Sign(s.key, []byte(fmt.Sprintf("%s: %s", headerName, dateHeader))) - if err != nil { - return "", errwrap.Wrapf("Error signing date header: {{err}}", err) - } - - keyFormat, err := keyFormatToKeyType(signature.Format) - if err != nil { - return "", errwrap.Wrapf("Error reading signature: {{err}}", err) - } - - var authSignature httpAuthSignature - switch keyFormat { - case "rsa": - authSignature, err = newRSASignature(signature.Blob) - if err != nil { - return "", errwrap.Wrapf("Error reading signature: {{err}}", err) - } - case "ecdsa": - authSignature, err = newECDSASignature(signature.Blob) - if err != nil { - return "", errwrap.Wrapf("Error reading signature: {{err}}", err) - } - default: - return "", fmt.Errorf("Unsupported algorithm from SSH agent: %s", signature.Format) - } - - return fmt.Sprintf(authorizationHeaderFormat, s.keyIdentifier, - authSignature.SignatureType(), headerName, authSignature.String()), nil -} - -func (s *SSHAgentSigner) SignRaw(toSign string) (string, string, error) { - signature, err := s.agent.Sign(s.key, []byte(toSign)) - if err != nil { - return "", "", errwrap.Wrapf("Error signing string: {{err}}", err) - } - - keyFormat, err := keyFormatToKeyType(signature.Format) - if err != nil { - return "", "", errwrap.Wrapf("Error reading signature: {{err}}", err) - } - - var authSignature httpAuthSignature - switch keyFormat { - case "rsa": - authSignature, err = newRSASignature(signature.Blob) - if err != nil { - return "", "", errwrap.Wrapf("Error reading signature: {{err}}", err) - } - case "ecdsa": - authSignature, err = newECDSASignature(signature.Blob) - if err != nil { - return "", "", errwrap.Wrapf("Error reading signature: {{err}}", err) - } - default: - return "", "", fmt.Errorf("Unsupported algorithm from SSH agent: %s", signature.Format) - } - - return authSignature.String(), authSignature.SignatureType(), nil -} - -func (s *SSHAgentSigner) KeyFingerprint() string { - return s.formattedKeyFingerprint -} - -func (s *SSHAgentSigner) DefaultAlgorithm() string { - return s.algorithm -} diff --git a/vendor/github.com/joyent/triton-go/authentication/test_signer.go b/vendor/github.com/joyent/triton-go/authentication/test_signer.go deleted file mode 100644 index a9c2c82..0000000 --- a/vendor/github.com/joyent/triton-go/authentication/test_signer.go +++ /dev/null @@ -1,27 +0,0 @@ -package authentication - -// TestSigner represents an authentication key signer which we can use for -// testing purposes only. This will largely be a stub to send through client -// unit tests. -type TestSigner struct{} - -// NewTestSigner constructs a new instance of test signer -func NewTestSigner() (Signer, error) { - return &TestSigner{}, nil -} - -func (s *TestSigner) DefaultAlgorithm() string { - return "" -} - -func (s *TestSigner) KeyFingerprint() string { - return "" -} - -func (s *TestSigner) Sign(dateHeader string) (string, error) { - return "", nil -} - -func (s *TestSigner) SignRaw(toSign string) (string, string, error) { - return "", "", nil -} diff --git a/vendor/github.com/joyent/triton-go/authentication/util.go b/vendor/github.com/joyent/triton-go/authentication/util.go deleted file mode 100644 index 7c298b6..0000000 --- a/vendor/github.com/joyent/triton-go/authentication/util.go +++ /dev/null @@ -1,29 +0,0 @@ -package authentication - -import ( - "crypto/md5" - "fmt" - "strings" - - "golang.org/x/crypto/ssh" -) - -// formatPublicKeyFingerprint produces the MD5 fingerprint of the given SSH -// public key. If display is true, the fingerprint is formatted with colons -// between each byte, as per the output of OpenSSL. -func formatPublicKeyFingerprint(key ssh.PublicKey, display bool) string { - publicKeyFingerprint := md5.New() - publicKeyFingerprint.Write(key.Marshal()) - publicKeyFingerprintString := fmt.Sprintf("%x", publicKeyFingerprint.Sum(nil)) - - if !display { - return publicKeyFingerprintString - } - - formatted := "" - for i := 0; i < len(publicKeyFingerprintString); i = i + 2 { - formatted = fmt.Sprintf("%s%s:", formatted, publicKeyFingerprintString[i:i+2]) - } - - return strings.TrimSuffix(formatted, ":") -} diff --git a/vendor/github.com/joyent/triton-go/client/client.go b/vendor/github.com/joyent/triton-go/client/client.go deleted file mode 100644 index df69780..0000000 --- a/vendor/github.com/joyent/triton-go/client/client.go +++ /dev/null @@ -1,413 +0,0 @@ -package client - -import ( - "bytes" - "context" - "crypto/tls" - "encoding/json" - "errors" - "io" - "net" - "net/http" - "net/url" - "os" - "time" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/authentication" -) - -const nilContext = "nil context" - -var ( - ErrDefaultAuth = errors.New("default SSH agent authentication requires SDC_KEY_ID and SSH_AUTH_SOCK") - ErrAccountName = errors.New("missing account name for Triton/Manta") - ErrMissingURL = errors.New("missing Triton and/or Manta URL") - - BadTritonURL = "invalid format of triton URL" - BadMantaURL = "invalid format of manta URL" -) - -// Client represents a connection to the Triton Compute or Object Storage APIs. -type Client struct { - HTTPClient *http.Client - Authorizers []authentication.Signer - TritonURL url.URL - MantaURL url.URL - AccountName string -} - -// New is used to construct a Client in order to make API -// requests to the Triton API. -// -// At least one signer must be provided - example signers include -// authentication.PrivateKeySigner and authentication.SSHAgentSigner. -func New(tritonURL string, mantaURL string, accountName string, signers ...authentication.Signer) (*Client, error) { - if accountName == "" { - return nil, ErrAccountName - } - - if tritonURL == "" && mantaURL == "" { - return nil, ErrMissingURL - } - - cloudURL, err := url.Parse(tritonURL) - if err != nil { - return nil, errwrap.Wrapf(BadTritonURL+": {{err}}", err) - } - - storageURL, err := url.Parse(mantaURL) - if err != nil { - return nil, errwrap.Wrapf(BadMantaURL+": {{err}}", err) - } - - authorizers := make([]authentication.Signer, 0) - for _, key := range signers { - if key != nil { - authorizers = append(authorizers, key) - } - } - - newClient := &Client{ - HTTPClient: &http.Client{ - Transport: httpTransport(false), - CheckRedirect: doNotFollowRedirects, - }, - Authorizers: authorizers, - TritonURL: *cloudURL, - MantaURL: *storageURL, - AccountName: accountName, - } - - // Default to constructing an SSHAgentSigner if there are no other signers - // passed into NewClient and there's an SDC_KEY_ID and SSH_AUTH_SOCK - // available in the user's environ(7). - if len(newClient.Authorizers) == 0 { - if err := newClient.DefaultAuth(); err != nil { - return nil, err - } - } - - return newClient, nil -} - -// initDefaultAuth provides a default key signer for a client. This should only -// be used internally if the client has no other key signer for authenticating -// with Triton. We first look for both `SDC_KEY_ID` and `SSH_AUTH_SOCK` in the -// user's environ(7). If so we default to the SSH agent key signer. -func (c *Client) DefaultAuth() error { - if keyID, keyOk := os.LookupEnv("SDC_KEY_ID"); keyOk { - defaultSigner, err := authentication.NewSSHAgentSigner(keyID, c.AccountName) - if err != nil { - return errwrap.Wrapf("problem initializing NewSSHAgentSigner: {{err}}", err) - } - c.Authorizers = append(c.Authorizers, defaultSigner) - } else { - return ErrDefaultAuth - } - return nil -} - -// InsecureSkipTLSVerify turns off TLS verification for the client connection. This -// allows connection to an endpoint with a certificate which was signed by a non- -// trusted CA, such as self-signed certificates. This can be useful when connecting -// to temporary Triton installations such as Triton Cloud-On-A-Laptop. -func (c *Client) InsecureSkipTLSVerify() { - if c.HTTPClient == nil { - return - } - - c.HTTPClient.Transport = httpTransport(true) -} - -func httpTransport(insecureSkipTLSVerify bool) *http.Transport { - return &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - }).Dial, - TLSHandshakeTimeout: 10 * time.Second, - DisableKeepAlives: true, - MaxIdleConnsPerHost: -1, - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: insecureSkipTLSVerify, - }, - } -} - -func doNotFollowRedirects(*http.Request, []*http.Request) error { - return http.ErrUseLastResponse -} - -// TODO(justinwr): Deprecated? -// func (c *Client) FormatURL(path string) string { -// return fmt.Sprintf("%s%s", c.Endpoint, path) -// } - -func (c *Client) DecodeError(statusCode int, body io.Reader) error { - err := &TritonError{ - StatusCode: statusCode, - } - - errorDecoder := json.NewDecoder(body) - if err := errorDecoder.Decode(err); err != nil { - return errwrap.Wrapf("Error decoding error response: {{err}}", err) - } - - return err -} - -// ----------------------------------------------------------------------------- - -type RequestInput struct { - Method string - Path string - Query *url.Values - Headers *http.Header - Body interface{} -} - -func (c *Client) ExecuteRequestURIParams(ctx context.Context, inputs RequestInput) (io.ReadCloser, error) { - method := inputs.Method - path := inputs.Path - body := inputs.Body - query := inputs.Query - - var requestBody io.ReadSeeker - if body != nil { - marshaled, err := json.MarshalIndent(body, "", " ") - if err != nil { - return nil, err - } - requestBody = bytes.NewReader(marshaled) - } - - endpoint := c.TritonURL - endpoint.Path = path - if query != nil { - endpoint.RawQuery = query.Encode() - } - - req, err := http.NewRequest(method, endpoint.String(), requestBody) - if err != nil { - return nil, errwrap.Wrapf("Error constructing HTTP request: {{err}}", err) - } - - dateHeader := time.Now().UTC().Format(time.RFC1123) - req.Header.Set("date", dateHeader) - - // NewClient ensures there's always an authorizer (unless this is called - // outside that constructor). - authHeader, err := c.Authorizers[0].Sign(dateHeader) - if err != nil { - return nil, errwrap.Wrapf("Error signing HTTP request: {{err}}", err) - } - req.Header.Set("Authorization", authHeader) - req.Header.Set("Accept", "application/json") - req.Header.Set("Accept-Version", "8") - req.Header.Set("User-Agent", "triton-go Client API") - - if body != nil { - req.Header.Set("Content-Type", "application/json") - } - - resp, err := c.HTTPClient.Do(req.WithContext(ctx)) - if err != nil { - return nil, errwrap.Wrapf("Error executing HTTP request: {{err}}", err) - } - - if resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices { - return resp.Body, nil - } - - return nil, c.DecodeError(resp.StatusCode, resp.Body) -} - -func (c *Client) ExecuteRequest(ctx context.Context, inputs RequestInput) (io.ReadCloser, error) { - return c.ExecuteRequestURIParams(ctx, inputs) -} - -func (c *Client) ExecuteRequestRaw(ctx context.Context, inputs RequestInput) (*http.Response, error) { - method := inputs.Method - path := inputs.Path - body := inputs.Body - - var requestBody io.ReadSeeker - if body != nil { - marshaled, err := json.MarshalIndent(body, "", " ") - if err != nil { - return nil, err - } - requestBody = bytes.NewReader(marshaled) - } - - endpoint := c.TritonURL - endpoint.Path = path - - req, err := http.NewRequest(method, endpoint.String(), requestBody) - if err != nil { - return nil, errwrap.Wrapf("Error constructing HTTP request: {{err}}", err) - } - - dateHeader := time.Now().UTC().Format(time.RFC1123) - req.Header.Set("date", dateHeader) - - // NewClient ensures there's always an authorizer (unless this is called - // outside that constructor). - authHeader, err := c.Authorizers[0].Sign(dateHeader) - if err != nil { - return nil, errwrap.Wrapf("Error signing HTTP request: {{err}}", err) - } - req.Header.Set("Authorization", authHeader) - req.Header.Set("Accept", "application/json") - req.Header.Set("Accept-Version", "8") - req.Header.Set("User-Agent", "triton-go c API") - - if body != nil { - req.Header.Set("Content-Type", "application/json") - } - - resp, err := c.HTTPClient.Do(req.WithContext(ctx)) - if err != nil { - return nil, errwrap.Wrapf("Error executing HTTP request: {{err}}", err) - } - - return resp, nil -} - -func (c *Client) ExecuteRequestStorage(ctx context.Context, inputs RequestInput) (io.ReadCloser, http.Header, error) { - method := inputs.Method - path := inputs.Path - query := inputs.Query - headers := inputs.Headers - body := inputs.Body - - endpoint := c.MantaURL - endpoint.Path = path - - var requestBody io.ReadSeeker - if body != nil { - marshaled, err := json.MarshalIndent(body, "", " ") - if err != nil { - return nil, nil, err - } - requestBody = bytes.NewReader(marshaled) - } - - req, err := http.NewRequest(method, endpoint.String(), requestBody) - if err != nil { - return nil, nil, errwrap.Wrapf("Error constructing HTTP request: {{err}}", err) - } - - if body != nil && (headers == nil || headers.Get("Content-Type") == "") { - req.Header.Set("Content-Type", "application/json") - } - if headers != nil { - for key, values := range *headers { - for _, value := range values { - req.Header.Set(key, value) - } - } - } - - dateHeader := time.Now().UTC().Format(time.RFC1123) - req.Header.Set("date", dateHeader) - - authHeader, err := c.Authorizers[0].Sign(dateHeader) - if err != nil { - return nil, nil, errwrap.Wrapf("Error signing HTTP request: {{err}}", err) - } - req.Header.Set("Authorization", authHeader) - req.Header.Set("Accept", "*/*") - req.Header.Set("User-Agent", "manta-go client API") - - if query != nil { - req.URL.RawQuery = query.Encode() - } - - resp, err := c.HTTPClient.Do(req.WithContext(ctx)) - if err != nil { - return nil, nil, errwrap.Wrapf("Error executing HTTP request: {{err}}", err) - } - - if resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices { - return resp.Body, resp.Header, nil - } - - mantaError := &MantaError{ - StatusCode: resp.StatusCode, - } - - errorDecoder := json.NewDecoder(resp.Body) - if err := errorDecoder.Decode(mantaError); err != nil { - return nil, nil, errwrap.Wrapf("Error decoding error response: {{err}}", err) - } - return nil, nil, mantaError -} - -type RequestNoEncodeInput struct { - Method string - Path string - Query *url.Values - Headers *http.Header - Body io.ReadSeeker -} - -func (c *Client) ExecuteRequestNoEncode(ctx context.Context, inputs RequestNoEncodeInput) (io.ReadCloser, http.Header, error) { - method := inputs.Method - path := inputs.Path - query := inputs.Query - headers := inputs.Headers - body := inputs.Body - - endpoint := c.MantaURL - endpoint.Path = path - - req, err := http.NewRequest(method, endpoint.String(), body) - if err != nil { - return nil, nil, errwrap.Wrapf("Error constructing HTTP request: {{err}}", err) - } - - if headers != nil { - for key, values := range *headers { - for _, value := range values { - req.Header.Set(key, value) - } - } - } - - dateHeader := time.Now().UTC().Format(time.RFC1123) - req.Header.Set("date", dateHeader) - - authHeader, err := c.Authorizers[0].Sign(dateHeader) - if err != nil { - return nil, nil, errwrap.Wrapf("Error signing HTTP request: {{err}}", err) - } - req.Header.Set("Authorization", authHeader) - req.Header.Set("Accept", "*/*") - req.Header.Set("User-Agent", "manta-go client API") - - if query != nil { - req.URL.RawQuery = query.Encode() - } - - resp, err := c.HTTPClient.Do(req.WithContext(ctx)) - if err != nil { - return nil, nil, errwrap.Wrapf("Error executing HTTP request: {{err}}", err) - } - - if resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices { - return resp.Body, resp.Header, nil - } - - mantaError := &MantaError{ - StatusCode: resp.StatusCode, - } - - errorDecoder := json.NewDecoder(resp.Body) - if err := errorDecoder.Decode(mantaError); err != nil { - return nil, nil, errwrap.Wrapf("Error decoding error response: {{err}}", err) - } - return nil, nil, mantaError -} diff --git a/vendor/github.com/joyent/triton-go/client/client_test.go b/vendor/github.com/joyent/triton-go/client/client_test.go deleted file mode 100644 index 0a16500..0000000 --- a/vendor/github.com/joyent/triton-go/client/client_test.go +++ /dev/null @@ -1,94 +0,0 @@ -package client - -import ( - "os" - "strings" - "testing" - - auth "github.com/joyent/triton-go/authentication" -) - -const BadURL = "**ftp://man($$" - -func TestNew(t *testing.T) { - tritonURL := "http://triton.test.org" - mantaURL := "http://manta.test.org" - accountName := "test.user" - signer, _ := auth.NewTestSigner() - - tests := []struct { - name string - tritonURL string - mantaURL string - accountName string - signer auth.Signer - err interface{} - }{ - {"default", tritonURL, mantaURL, accountName, signer, nil}, - {"missing url", "", "", accountName, signer, ErrMissingURL}, - {"bad tritonURL", BadURL, mantaURL, accountName, signer, BadTritonURL}, - {"bad mantaURL", tritonURL, BadURL, accountName, signer, BadMantaURL}, - {"missing accountName", tritonURL, mantaURL, "", signer, ErrAccountName}, - {"missing signer", tritonURL, mantaURL, accountName, nil, ErrDefaultAuth}, - } - - for _, test := range tests { - os.Unsetenv("SDC_KEY_ID") - os.Unsetenv("MANTA_KEY_ID") - os.Unsetenv("SSH_AUTH_SOCK") - - t.Run(test.name, func(t *testing.T) { - _, err := New( - test.tritonURL, - test.mantaURL, - test.accountName, - test.signer, - ) - if test.err != nil { - if err == nil { - t.Error("expected error not to be nil") - return - } - - switch test.err.(type) { - case error: - testErr := test.err.(error) - if err.Error() != testErr.Error() { - t.Errorf("expected error: received %v", err) - } - case string: - testErr := test.err.(string) - if !strings.Contains(err.Error(), testErr) { - t.Errorf("expected error: received %v", err) - } - } - return - } - if err != nil { - t.Errorf("expected error to be nil: received %v", err) - } - }) - } - - t.Run("default SSH agent auth", func(t *testing.T) { - os.Unsetenv("SSH_AUTH_SOCK") - err := os.Setenv("SDC_KEY_ID", auth.Dummy.Fingerprint) - defer os.Unsetenv("SDC_KEY_ID") - if err != nil { - t.Errorf("expected error to not be nil: received %v", err) - } - - _, err = New( - tritonURL, - mantaURL, - accountName, - nil, - ) - if err == nil { - t.Error("expected error to not be nil") - } - if !strings.Contains(err.Error(), "problem initializing NewSSHAgentSigner") { - t.Errorf("expected error to be from NewSSHAgentSigner: received '%v'", err) - } - }) -} diff --git a/vendor/github.com/joyent/triton-go/client/errors.go b/vendor/github.com/joyent/triton-go/client/errors.go deleted file mode 100644 index 1fc64a0..0000000 --- a/vendor/github.com/joyent/triton-go/client/errors.go +++ /dev/null @@ -1,190 +0,0 @@ -package client - -import ( - "fmt" - - "github.com/hashicorp/errwrap" -) - -// ClientError represents an error code and message along with the status code -// of the HTTP request which resulted in the error message. -type ClientError struct { - StatusCode int - Code string - Message string -} - -// Error implements interface Error on the TritonError type. -func (e ClientError) Error() string { - return fmt.Sprintf("%s: %s", e.Code, e.Message) -} - -// MantaError represents an error code and message along with -// the status code of the HTTP request which resulted in the error -// message. Error codes used by the Manta API are listed at -// https://apidocs.joyent.com/manta/api.html#errors -type MantaError struct { - StatusCode int - Code string `json:"code"` - Message string `json:"message"` -} - -// Error implements interface Error on the MantaError type. -func (e MantaError) Error() string { - return fmt.Sprintf("%s: %s", e.Code, e.Message) -} - -// TritonError represents an error code and message along with -// the status code of the HTTP request which resulted in the error -// message. Error codes used by the Triton API are listed at -// https://apidocs.joyent.com/cloudapi/#cloudapi-http-responses -type TritonError struct { - StatusCode int - Code string `json:"code"` - Message string `json:"message"` -} - -// Error implements interface Error on the TritonError type. -func (e TritonError) Error() string { - return fmt.Sprintf("%s: %s", e.Code, e.Message) -} - -func IsAuthSchemeError(err error) bool { - return isSpecificError(err, "AuthScheme") -} -func IsAuthorizationError(err error) bool { - return isSpecificError(err, "Authorization") -} -func IsBadRequestError(err error) bool { - return isSpecificError(err, "BadRequest") -} -func IsChecksumError(err error) bool { - return isSpecificError(err, "Checksum") -} -func IsConcurrentRequestError(err error) bool { - return isSpecificError(err, "ConcurrentRequest") -} -func IsContentLengthError(err error) bool { - return isSpecificError(err, "ContentLength") -} -func IsContentMD5MismatchError(err error) bool { - return isSpecificError(err, "ContentMD5Mismatch") -} -func IsEntityExistsError(err error) bool { - return isSpecificError(err, "EntityExists") -} -func IsInvalidArgumentError(err error) bool { - return isSpecificError(err, "InvalidArgument") -} -func IsInvalidAuthTokenError(err error) bool { - return isSpecificError(err, "InvalidAuthToken") -} -func IsInvalidCredentialsError(err error) bool { - return isSpecificError(err, "InvalidCredentials") -} -func IsInvalidDurabilityLevelError(err error) bool { - return isSpecificError(err, "InvalidDurabilityLevel") -} -func IsInvalidKeyIdError(err error) bool { - return isSpecificError(err, "InvalidKeyId") -} -func IsInvalidJobError(err error) bool { - return isSpecificError(err, "InvalidJob") -} -func IsInvalidLinkError(err error) bool { - return isSpecificError(err, "InvalidLink") -} -func IsInvalidLimitError(err error) bool { - return isSpecificError(err, "InvalidLimit") -} -func IsInvalidSignatureError(err error) bool { - return isSpecificError(err, "InvalidSignature") -} -func IsInvalidUpdateError(err error) bool { - return isSpecificError(err, "InvalidUpdate") -} -func IsDirectoryDoesNotExistError(err error) bool { - return isSpecificError(err, "DirectoryDoesNotExist") -} -func IsDirectoryExistsError(err error) bool { - return isSpecificError(err, "DirectoryExists") -} -func IsDirectoryNotEmptyError(err error) bool { - return isSpecificError(err, "DirectoryNotEmpty") -} -func IsDirectoryOperationError(err error) bool { - return isSpecificError(err, "DirectoryOperation") -} -func IsInternalError(err error) bool { - return isSpecificError(err, "Internal") -} -func IsJobNotFoundError(err error) bool { - return isSpecificError(err, "JobNotFound") -} -func IsJobStateError(err error) bool { - return isSpecificError(err, "JobState") -} -func IsKeyDoesNotExistError(err error) bool { - return isSpecificError(err, "KeyDoesNotExist") -} -func IsNotAcceptableError(err error) bool { - return isSpecificError(err, "NotAcceptable") -} -func IsNotEnoughSpaceError(err error) bool { - return isSpecificError(err, "NotEnoughSpace") -} -func IsLinkNotFoundError(err error) bool { - return isSpecificError(err, "LinkNotFound") -} -func IsLinkNotObjectError(err error) bool { - return isSpecificError(err, "LinkNotObject") -} -func IsLinkRequiredError(err error) bool { - return isSpecificError(err, "LinkRequired") -} -func IsParentNotDirectoryError(err error) bool { - return isSpecificError(err, "ParentNotDirectory") -} -func IsPreconditionFailedError(err error) bool { - return isSpecificError(err, "PreconditionFailed") -} -func IsPreSignedRequestError(err error) bool { - return isSpecificError(err, "PreSignedRequest") -} -func IsRequestEntityTooLargeError(err error) bool { - return isSpecificError(err, "RequestEntityTooLarge") -} -func IsResourceNotFoundError(err error) bool { - return isSpecificError(err, "ResourceNotFound") -} -func IsRootDirectoryError(err error) bool { - return isSpecificError(err, "RootDirectory") -} -func IsServiceUnavailableError(err error) bool { - return isSpecificError(err, "ServiceUnavailable") -} -func IsSSLRequiredError(err error) bool { - return isSpecificError(err, "SSLRequired") -} -func IsUploadTimeoutError(err error) bool { - return isSpecificError(err, "UploadTimeout") -} -func IsUserDoesNotExistError(err error) bool { - return isSpecificError(err, "UserDoesNotExist") -} - -// isSpecificError checks whether the error represented by err wraps -// an underlying MantaError with code errorCode. -func isSpecificError(err error, errorCode string) bool { - tritonErrorInterface := errwrap.GetType(err.(error), &MantaError{}) - if tritonErrorInterface == nil { - return false - } - - tritonErr := tritonErrorInterface.(*MantaError) - if tritonErr.Code == errorCode { - return true - } - - return false -} diff --git a/vendor/github.com/joyent/triton-go/compute/client.go b/vendor/github.com/joyent/triton-go/compute/client.go deleted file mode 100644 index 8ce726c..0000000 --- a/vendor/github.com/joyent/triton-go/compute/client.go +++ /dev/null @@ -1,57 +0,0 @@ -package compute - -import ( - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/client" -) - -type ComputeClient struct { - Client *client.Client -} - -func newComputeClient(client *client.Client) *ComputeClient { - return &ComputeClient{ - Client: client, - } -} - -// NewClient returns a new client for working with Compute endpoints and -// resources within CloudAPI -func NewClient(config *triton.ClientConfig) (*ComputeClient, error) { - // TODO: Utilize config interface within the function itself - client, err := client.New(config.TritonURL, config.MantaURL, config.AccountName, config.Signers...) - if err != nil { - return nil, err - } - return newComputeClient(client), nil -} - -// Datacenters returns a Compute client used for accessing functions pertaining -// to DataCenter functionality in the Triton API. -func (c *ComputeClient) Datacenters() *DataCentersClient { - return &DataCentersClient{c.Client} -} - -// Images returns a Compute client used for accessing functions pertaining to -// Images functionality in the Triton API. -func (c *ComputeClient) Images() *ImagesClient { - return &ImagesClient{c.Client} -} - -// Machines returns a Compute client used for accessing functions pertaining to -// machine functionality in the Triton API. -func (c *ComputeClient) Instances() *InstancesClient { - return &InstancesClient{c.Client} -} - -// Packages returns a Compute client used for accessing functions pertaining to -// Packages functionality in the Triton API. -func (c *ComputeClient) Packages() *PackagesClient { - return &PackagesClient{c.Client} -} - -// Services returns a Compute client used for accessing functions pertaining to -// Services functionality in the Triton API. -func (c *ComputeClient) Services() *ServicesClient { - return &ServicesClient{c.Client} -} diff --git a/vendor/github.com/joyent/triton-go/compute/datacenters.go b/vendor/github.com/joyent/triton-go/compute/datacenters.go deleted file mode 100644 index 365474e..0000000 --- a/vendor/github.com/joyent/triton-go/compute/datacenters.go +++ /dev/null @@ -1,97 +0,0 @@ -package compute - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - "sort" - - "context" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type DataCentersClient struct { - client *client.Client -} - -type DataCenter struct { - Name string `json:"name"` - URL string `json:"url"` -} - -type ListDataCentersInput struct{} - -func (c *DataCentersClient) List(ctx context.Context, _ *ListDataCentersInput) ([]*DataCenter, error) { - path := fmt.Sprintf("/%s/datacenters", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing List request: {{err}}", err) - } - - var intermediate map[string]string - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&intermediate); err != nil { - return nil, errwrap.Wrapf("Error decoding List response: {{err}}", err) - } - - keys := make([]string, len(intermediate)) - i := 0 - for k := range intermediate { - keys[i] = k - i++ - } - sort.Strings(keys) - - result := make([]*DataCenter, len(intermediate)) - i = 0 - for _, key := range keys { - result[i] = &DataCenter{ - Name: key, - URL: intermediate[key], - } - i++ - } - - return result, nil -} - -type GetDataCenterInput struct { - Name string -} - -func (c *DataCentersClient) Get(ctx context.Context, input *GetDataCenterInput) (*DataCenter, error) { - path := fmt.Sprintf("/%s/datacenters/%s", c.client.AccountName, input.Name) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - resp, err := c.client.ExecuteRequestRaw(ctx, reqInputs) - if err != nil { - return nil, errwrap.Wrapf("Error executing Get request: {{err}}", err) - } - - if resp.StatusCode != http.StatusFound { - return nil, fmt.Errorf("Error executing Get request: expected status code 302, got %d", - resp.StatusCode) - } - - location := resp.Header.Get("Location") - if location == "" { - return nil, errors.New("Error decoding Get response: no Location header") - } - - return &DataCenter{ - Name: input.Name, - URL: location, - }, nil -} diff --git a/vendor/github.com/joyent/triton-go/compute/datacenters_test.go b/vendor/github.com/joyent/triton-go/compute/datacenters_test.go deleted file mode 100644 index 9df0db4..0000000 --- a/vendor/github.com/joyent/triton-go/compute/datacenters_test.go +++ /dev/null @@ -1,103 +0,0 @@ -package compute - -import ( - "context" - "fmt" - "testing" - - "github.com/abdullin/seq" - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/testutils" -) - -// Note that this is specific to Joyent Public Cloud and will not pass on -// private installations of Triton. -func TestAccDataCenters_Get(t *testing.T) { - const dataCenterName = "us-east-1" - const dataCenterURL = "https://us-east-1.api.joyentcloud.com" - - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "datacenter", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "datacenter", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - ctx := context.Background() - input := &GetDataCenterInput{ - Name: dataCenterName, - } - return c.Datacenters().Get(ctx, input) - }, - }, - - &testutils.StepAssert{ - StateBagKey: "datacenter", - Assertions: seq.Map{ - "name": dataCenterName, - "url": dataCenterURL, - }, - }, - }, - }) -} - -// Note that this is specific to Joyent Public Cloud and will not pass on -// private installations of Triton. -func TestAccDataCenters_List(t *testing.T) { - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "datacenter", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "datacenters", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - ctx := context.Background() - input := &ListDataCentersInput{} - return c.Datacenters().List(ctx, input) - }, - }, - - &testutils.StepAssertFunc{ - AssertFunc: func(state testutils.TritonStateBag) error { - dcs, ok := state.GetOk("datacenters") - if !ok { - return fmt.Errorf("State key %q not found", "datacenters") - } - - toFind := []string{"us-east-1", "eu-ams-1"} - for _, dcName := range toFind { - found := false - for _, dc := range dcs.([]*DataCenter) { - if dc.Name == dcName { - found = true - if dc.URL == "" { - return fmt.Errorf("%q has no URL", dc.Name) - } - } - } - if !found { - return fmt.Errorf("Did not find DC %q", dcName) - } - } - - return nil - }, - }, - }, - }) -} diff --git a/vendor/github.com/joyent/triton-go/compute/errors.go b/vendor/github.com/joyent/triton-go/compute/errors.go deleted file mode 100644 index db31472..0000000 --- a/vendor/github.com/joyent/triton-go/compute/errors.go +++ /dev/null @@ -1,121 +0,0 @@ -package compute - -import ( - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -// IsBadRequest tests whether err wraps a client.TritonError with -// code BadRequest -func IsBadRequest(err error) bool { - return isSpecificError(err, "BadRequest") -} - -// IsInternalError tests whether err wraps a client.TritonError with -// code InternalError -func IsInternalError(err error) bool { - return isSpecificError(err, "InternalError") -} - -// IsInUseError tests whether err wraps a client.TritonError with -// code InUseError -func IsInUseError(err error) bool { - return isSpecificError(err, "InUseError") -} - -// IsInvalidArgument tests whether err wraps a client.TritonError with -// code InvalidArgument -func IsInvalidArgument(err error) bool { - return isSpecificError(err, "InvalidArgument") -} - -// IsInvalidCredentials tests whether err wraps a client.TritonError with -// code InvalidCredentials -func IsInvalidCredentials(err error) bool { - return isSpecificError(err, "InvalidCredentials") -} - -// IsInvalidHeader tests whether err wraps a client.TritonError with -// code InvalidHeader -func IsInvalidHeader(err error) bool { - return isSpecificError(err, "InvalidHeader") -} - -// IsInvalidVersion tests whether err wraps a client.TritonError with -// code InvalidVersion -func IsInvalidVersion(err error) bool { - return isSpecificError(err, "InvalidVersion") -} - -// IsMissingParameter tests whether err wraps a client.TritonError with -// code MissingParameter -func IsMissingParameter(err error) bool { - return isSpecificError(err, "MissingParameter") -} - -// IsNotAuthorized tests whether err wraps a client.TritonError with -// code NotAuthorized -func IsNotAuthorized(err error) bool { - return isSpecificError(err, "NotAuthorized") -} - -// IsRequestThrottled tests whether err wraps a client.TritonError with -// code RequestThrottled -func IsRequestThrottled(err error) bool { - return isSpecificError(err, "RequestThrottled") -} - -// IsRequestTooLarge tests whether err wraps a client.TritonError with -// code RequestTooLarge -func IsRequestTooLarge(err error) bool { - return isSpecificError(err, "RequestTooLarge") -} - -// IsRequestMoved tests whether err wraps a client.TritonError with -// code RequestMoved -func IsRequestMoved(err error) bool { - return isSpecificError(err, "RequestMoved") -} - -// IsResourceFound tests whether err wraps a client.TritonError with code ResourceFound -func IsResourceFound(err error) bool { - return isSpecificError(err, "ResourceFound") -} - -// IsResourceNotFound tests whether err wraps a client.TritonError with -// code ResourceNotFound -func IsResourceNotFound(err error) bool { - return isSpecificError(err, "ResourceNotFound") -} - -// IsUnknownError tests whether err wraps a client.TritonError with -// code UnknownError -func IsUnknownError(err error) bool { - return isSpecificError(err, "UnknownError") -} - -// IsEmptyResponse tests whether err wraps a client.TritonError with code -// EmptyResponse -func IsEmptyResponse(err error) bool { - return isSpecificError(err, "EmptyResponse") -} - -// isSpecificError checks whether the error represented by err wraps -// an underlying client.TritonError with code errorCode. -func isSpecificError(err error, errorCode string) bool { - if err == nil { - return false - } - - tritonErrorInterface := errwrap.GetType(err.(error), &client.TritonError{}) - if tritonErrorInterface == nil { - return false - } - - tritonErr := tritonErrorInterface.(*client.TritonError) - if tritonErr.Code == errorCode { - return true - } - - return false -} diff --git a/vendor/github.com/joyent/triton-go/compute/images.go b/vendor/github.com/joyent/triton-go/compute/images.go deleted file mode 100644 index b60f05e..0000000 --- a/vendor/github.com/joyent/triton-go/compute/images.go +++ /dev/null @@ -1,262 +0,0 @@ -package compute - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - "time" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type ImagesClient struct { - client *client.Client -} - -type ImageFile struct { - Compression string `json:"compression"` - SHA1 string `json:"sha1"` - Size int64 `json:"size"` -} - -type Image struct { - ID string `json:"id"` - Name string `json:"name"` - OS string `json:"os"` - Description string `json:"description"` - Version string `json:"version"` - Type string `json:"type"` - Requirements map[string]interface{} `json:"requirements"` - Homepage string `json:"homepage"` - Files []*ImageFile `json:"files"` - PublishedAt time.Time `json:"published_at"` - Owner string `json:"owner"` - Public bool `json:"public"` - State string `json:"state"` - Tags map[string]string `json:"tags"` - EULA string `json:"eula"` - ACL []string `json:"acl"` - Error client.TritonError `json:"error"` -} - -type ListImagesInput struct { - Name string - OS string - Version string - Public bool - State string - Owner string - Type string -} - -func (c *ImagesClient) List(ctx context.Context, input *ListImagesInput) ([]*Image, error) { - path := fmt.Sprintf("/%s/images", c.client.AccountName) - - query := &url.Values{} - if input.Name != "" { - query.Set("name", input.Name) - } - if input.OS != "" { - query.Set("os", input.OS) - } - if input.Version != "" { - query.Set("version", input.Version) - } - if input.Public { - query.Set("public", "true") - } - if input.State != "" { - query.Set("state", input.State) - } - if input.Owner != "" { - query.Set("owner", input.Owner) - } - if input.Type != "" { - query.Set("type", input.Type) - } - - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - Query: query, - } - respReader, err := c.client.ExecuteRequestURIParams(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing List request: {{err}}", err) - } - - var result []*Image - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding List response: {{err}}", err) - } - - return result, nil -} - -type GetImageInput struct { - ImageID string -} - -func (c *ImagesClient) Get(ctx context.Context, input *GetImageInput) (*Image, error) { - path := fmt.Sprintf("/%s/images/%s", c.client.AccountName, input.ImageID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing Get request: {{err}}", err) - } - - var result *Image - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding Get response: {{err}}", err) - } - - return result, nil -} - -type DeleteImageInput struct { - ImageID string -} - -func (c *ImagesClient) Delete(ctx context.Context, input *DeleteImageInput) error { - path := fmt.Sprintf("/%s/images/%s", c.client.AccountName, input.ImageID) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing Delete request: {{err}}", err) - } - - return nil -} - -type ExportImageInput struct { - ImageID string - MantaPath string -} - -type MantaLocation struct { - MantaURL string `json:"manta_url"` - ImagePath string `json:"image_path"` - ManifestPath string `json:"manifest_path"` -} - -func (c *ImagesClient) Export(ctx context.Context, input *ExportImageInput) (*MantaLocation, error) { - path := fmt.Sprintf("/%s/images/%s", c.client.AccountName, input.ImageID) - query := &url.Values{} - query.Set("action", "export") - query.Set("manta_path", input.MantaPath) - - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - Query: query, - } - respReader, err := c.client.ExecuteRequestURIParams(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing Get request: {{err}}", err) - } - - var result *MantaLocation - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding Get response: {{err}}", err) - } - - return result, nil -} - -type CreateImageFromMachineInput struct { - MachineID string `json:"machine"` - Name string `json:"name"` - Version string `json:"version,omitempty"` - Description string `json:"description,omitempty"` - HomePage string `json:"homepage,omitempty"` - EULA string `json:"eula,omitempty"` - ACL []string `json:"acl,omitempty"` - Tags map[string]string `json:"tags,omitempty"` -} - -func (c *ImagesClient) CreateFromMachine(ctx context.Context, input *CreateImageFromMachineInput) (*Image, error) { - path := fmt.Sprintf("/%s/images", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing CreateFromMachine request: {{err}}", err) - } - - var result *Image - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding CreateFromMachine response: {{err}}", err) - } - - return result, nil -} - -type UpdateImageInput struct { - ImageID string `json:"-"` - Name string `json:"name"` - Version string `json:"version,omitempty"` - Description string `json:"description,omitempty"` - HomePage string `json:"homepage,omitempty"` - EULA string `json:"eula,omitempty"` - ACL []string `json:"acl,omitempty"` - Tags map[string]string `json:"tags,omitempty"` -} - -func (c *ImagesClient) Update(ctx context.Context, input *UpdateImageInput) (*Image, error) { - path := fmt.Sprintf("/%s/images/%s", c.client.AccountName, input.ImageID) - query := &url.Values{} - query.Set("action", "update") - - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Query: query, - Body: input, - } - respReader, err := c.client.ExecuteRequestURIParams(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing Update request: {{err}}", err) - } - - var result *Image - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding Update response: {{err}}", err) - } - - return result, nil -} diff --git a/vendor/github.com/joyent/triton-go/compute/images_test.go b/vendor/github.com/joyent/triton-go/compute/images_test.go deleted file mode 100644 index 8336c49..0000000 --- a/vendor/github.com/joyent/triton-go/compute/images_test.go +++ /dev/null @@ -1,206 +0,0 @@ -package compute - -import ( - "fmt" - "testing" - "time" - - "context" - - "github.com/abdullin/seq" - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/testutils" -) - -func TestAccImagesList(t *testing.T) { - const stateKey = "images" - const image1Id = "95f6c9a6-a2bd-11e2-b753-dbf2651bf890" - const image2Id = "70e3ae72-96b6-11e6-9056-9737fd4d0764" - - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: stateKey, - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: stateKey, - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - ctx := context.Background() - input := &ListImagesInput{} - return c.Images().List(ctx, input) - }, - }, - - &testutils.StepAssertFunc{ - AssertFunc: func(state testutils.TritonStateBag) error { - images, ok := state.GetOk(stateKey) - if !ok { - return fmt.Errorf("State key %q not found", stateKey) - } - - toFind := []string{image1Id, image2Id} - for _, imageID := range toFind { - found := false - for _, image := range images.([]*Image) { - if image.ID == imageID { - found = true - state.Put(imageID, image) - } - } - if !found { - return fmt.Errorf("Did not find Image %q", imageID) - } - } - - return nil - }, - }, - - &testutils.StepAssert{ - StateBagKey: image1Id, - Assertions: seq.Map{ - "name": "ws2012std", - "owner": "9dce1460-0c4c-4417-ab8b-25ca478c5a78", - "requirements.min_memory": 3840, - "requirements.min_ram": 3840, - }, - }, - - &testutils.StepAssert{ - StateBagKey: image2Id, - Assertions: seq.Map{ - "name": "base-64", - "owner": "9dce1460-0c4c-4417-ab8b-25ca478c5a78", - "tags.role": "os", - "tags.group": "base-64", - }, - }, - }, - }) -} - -func TestAccImagesListInput(t *testing.T) { - const stateKey = "images" - const image1Id = "5cdc6dde-d6ad-11e5-8b11-8337e6f86725" - - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: stateKey, - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: stateKey, - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - ctx := context.Background() - input := &ListImagesInput{ - Name: "ubuntu-14.04", - Type: "lx-dataset", - Version: "20160219", - } - return c.Images().List(ctx, input) - }, - }, - - &testutils.StepAssertFunc{ - AssertFunc: func(state testutils.TritonStateBag) error { - images, ok := state.GetOk(stateKey) - if !ok { - return fmt.Errorf("State key %q not found", stateKey) - } - - toFind := []string{image1Id} - for _, imageID := range toFind { - found := false - for _, image := range images.([]*Image) { - if image.ID == imageID { - found = true - state.Put(imageID, image) - } - } - if !found { - return fmt.Errorf("Did not find Image %q", imageID) - } - } - - return nil - }, - }, - - &testutils.StepAssert{ - StateBagKey: image1Id, - Assertions: seq.Map{ - "id": "5cdc6dde-d6ad-11e5-8b11-8337e6f86725", - "name": "ubuntu-14.04", - "owner": "9dce1460-0c4c-4417-ab8b-25ca478c5a78", - "tags.kernel_version": "3.13.0", - }, - }, - }, - }) -} - -func TestAccImagesGet(t *testing.T) { - const stateKey = "image" - const imageId = "95f6c9a6-a2bd-11e2-b753-dbf2651bf890" - publishedAt, err := time.Parse(time.RFC3339, "2013-04-11T21:05:28Z") - if err != nil { - t.Fatal("Reference time does not parse as RFC3339") - } - - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: stateKey, - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: stateKey, - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - ctx := context.Background() - input := &GetImageInput{ - ImageID: imageId, - } - return c.Images().Get(ctx, input) - }, - }, - - &testutils.StepAssert{ - StateBagKey: stateKey, - Assertions: seq.Map{ - "name": "ws2012std", - "version": "1.0.1", - "os": "windows", - "requirements.min_memory": 3840, - "requirements.min_ram": 3840, - "type": "zvol", - "description": "Windows Server 2012 Standard 64-bit image.", - "files[0].compression": "gzip", - "files[0].sha1": "fe35a3b70f0a6f8e5252b05a35ee397d37d15185", - "files[0].size": 3985823590, - "tags.role": "os", - "published_at": publishedAt, - "owner": "9dce1460-0c4c-4417-ab8b-25ca478c5a78", - "public": true, - "state": "active", - }, - }, - }, - }) -} diff --git a/vendor/github.com/joyent/triton-go/compute/instances.go b/vendor/github.com/joyent/triton-go/compute/instances.go deleted file mode 100644 index f866080..0000000 --- a/vendor/github.com/joyent/triton-go/compute/instances.go +++ /dev/null @@ -1,1046 +0,0 @@ -package compute - -import ( - "context" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "net/url" - "strings" - "time" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type InstancesClient struct { - client *client.Client -} - -const ( - CNSTagDisable = "triton.cns.disable" - CNSTagReversePTR = "triton.cns.reverse_ptr" - CNSTagServices = "triton.cns.services" -) - -// InstanceCNS is a container for the CNS-specific attributes. In the API these -// values are embedded within a Instance's Tags attribute, however they are -// exposed to the caller as their native types. -type InstanceCNS struct { - Disable bool - ReversePTR string - Services []string -} - -type Instance struct { - ID string `json:"id"` - Name string `json:"name"` - Type string `json:"type"` - Brand string `json:"brand"` - State string `json:"state"` - Image string `json:"image"` - Memory int `json:"memory"` - Disk int `json:"disk"` - Metadata map[string]string `json:"metadata"` - Tags map[string]interface{} `json:"tags"` - Created time.Time `json:"created"` - Updated time.Time `json:"updated"` - Docker bool `json:"docker"` - IPs []string `json:"ips"` - Networks []string `json:"networks"` - PrimaryIP string `json:"primaryIp"` - FirewallEnabled bool `json:"firewall_enabled"` - ComputeNode string `json:"compute_node"` - Package string `json:"package"` - DomainNames []string `json:"dns_names"` - CNS InstanceCNS -} - -// _Instance is a private facade over Instance that handles the necessary API -// overrides from VMAPI's machine endpoint(s). -type _Instance struct { - Instance - Tags map[string]interface{} `json:"tags"` -} - -type NIC struct { - IP string `json:"ip"` - MAC string `json:"mac"` - Primary bool `json:"primary"` - Netmask string `json:"netmask"` - Gateway string `json:"gateway"` - State string `json:"state"` - Network string `json:"network"` -} - -type GetInstanceInput struct { - ID string -} - -func (gmi *GetInstanceInput) Validate() error { - if gmi.ID == "" { - return fmt.Errorf("machine ID can not be empty") - } - - return nil -} - -func (c *InstancesClient) Get(ctx context.Context, input *GetInstanceInput) (*Instance, error) { - if err := input.Validate(); err != nil { - return nil, errwrap.Wrapf("unable to get machine: {{err}}", err) - } - - path := fmt.Sprintf("/%s/machines/%s", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - response, err := c.client.ExecuteRequestRaw(ctx, reqInputs) - if response != nil { - defer response.Body.Close() - } - if response == nil || response.StatusCode == http.StatusNotFound || response.StatusCode == http.StatusGone { - return nil, &client.TritonError{ - StatusCode: response.StatusCode, - Code: "ResourceNotFound", - } - } - if err != nil { - return nil, errwrap.Wrapf("Error executing Get request: {{err}}", - c.client.DecodeError(response.StatusCode, response.Body)) - } - - var result *_Instance - decoder := json.NewDecoder(response.Body) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding Get response: {{err}}", err) - } - - native, err := result.toNative() - if err != nil { - return nil, errwrap.Wrapf("unable to convert API response for instances to native type: {{err}}", err) - } - - return native, nil -} - -type ListInstancesInput struct { - Brand string - Alias string - Name string - Image string - State string - Memory uint16 - Limit uint16 - Offset uint16 - Tags []string // query by arbitrary tags prefixed with "tag." - Tombstone bool - Docker bool - Credentials bool -} - -func (c *InstancesClient) List(ctx context.Context, input *ListInstancesInput) ([]*Instance, error) { - path := fmt.Sprintf("/%s/machines", c.client.AccountName) - - query := &url.Values{} - if input.Brand != "" { - query.Set("brand", input.Brand) - } - if input.Name != "" { - query.Set("name", input.Name) - } - if input.Image != "" { - query.Set("image", input.Image) - } - if input.State != "" { - query.Set("state", input.State) - } - if input.Memory >= 1 && input.Memory <= 1000 { - query.Set("memory", fmt.Sprintf("%d", input.Memory)) - } - if input.Limit >= 1 { - query.Set("limit", fmt.Sprintf("%d", input.Limit)) - } - if input.Offset >= 0 { - query.Set("offset", fmt.Sprintf("%d", input.Offset)) - } - if input.Tombstone { - query.Set("tombstone", "true") - } - if input.Docker { - query.Set("docker", "true") - } - if input.Credentials { - query.Set("credentials", "true") - } - - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - Query: query, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if err != nil { - return nil, errwrap.Wrapf("Error executing List request: {{err}}", err) - } - - var results []*_Instance - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&results); err != nil { - return nil, errwrap.Wrapf("Error decoding List response: {{err}}", err) - } - - machines := make([]*Instance, 0, len(results)) - for _, machineAPI := range results { - native, err := machineAPI.toNative() - if err != nil { - return nil, errwrap.Wrapf("unable to convert API response for instances to native type: {{err}}", err) - } - machines = append(machines, native) - } - - return machines, nil -} - -type CreateInstanceInput struct { - Name string - Package string - Image string - Networks []string - Affinity []string - LocalityStrict bool - LocalityNear []string - LocalityFar []string - Metadata map[string]string - Tags map[string]string - FirewallEnabled bool - CNS InstanceCNS -} - -func (input *CreateInstanceInput) toAPI() (map[string]interface{}, error) { - const numExtraParams = 8 - result := make(map[string]interface{}, numExtraParams+len(input.Metadata)+len(input.Tags)) - - result["firewall_enabled"] = input.FirewallEnabled - - if input.Name != "" { - result["name"] = input.Name - } - - if input.Package != "" { - result["package"] = input.Package - } - - if input.Image != "" { - result["image"] = input.Image - } - - if len(input.Networks) > 0 { - result["networks"] = input.Networks - } - - // validate that affinity and locality are not included together - hasAffinity := len(input.Affinity) > 0 - hasLocality := len(input.LocalityNear) > 0 || len(input.LocalityFar) > 0 - if hasAffinity && hasLocality { - return nil, fmt.Errorf("Cannot include both Affinity and Locality") - } - - // affinity takes precendence over locality regardless - if len(input.Affinity) > 0 { - result["affinity"] = input.Affinity - } else { - locality := struct { - Strict bool `json:"strict"` - Near []string `json:"near,omitempty"` - Far []string `json:"far,omitempty"` - }{ - Strict: input.LocalityStrict, - Near: input.LocalityNear, - Far: input.LocalityFar, - } - result["locality"] = locality - } - - for key, value := range input.Tags { - result[fmt.Sprintf("tag.%s", key)] = value - } - - // NOTE(justinwr): CNSTagServices needs to be a tag if available. No other - // CNS tags will be handled at this time. - input.CNS.toTags(result) - if val, found := result[CNSTagServices]; found { - result["tag."+CNSTagServices] = val - delete(result, CNSTagServices) - } - - for key, value := range input.Metadata { - result[fmt.Sprintf("metadata.%s", key)] = value - } - - return result, nil -} - -func (c *InstancesClient) Create(ctx context.Context, input *CreateInstanceInput) (*Instance, error) { - path := fmt.Sprintf("/%s/machines", c.client.AccountName) - body, err := input.toAPI() - if err != nil { - return nil, errwrap.Wrapf("Error preparing Create request: {{err}}", err) - } - - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: body, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing Create request: {{err}}", err) - } - - var result *Instance - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding Create response: {{err}}", err) - } - - return result, nil -} - -type DeleteInstanceInput struct { - ID string -} - -func (c *InstancesClient) Delete(ctx context.Context, input *DeleteInstanceInput) error { - path := fmt.Sprintf("/%s/machines/%s", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - response, err := c.client.ExecuteRequestRaw(ctx, reqInputs) - if response == nil { - return fmt.Errorf("Delete request has empty response") - } - if response.Body != nil { - defer response.Body.Close() - } - if response.StatusCode == http.StatusNotFound || response.StatusCode == http.StatusGone { - return nil - } - if err != nil { - return errwrap.Wrapf("Error executing Delete request: {{err}}", - c.client.DecodeError(response.StatusCode, response.Body)) - } - - return nil -} - -type DeleteTagsInput struct { - ID string -} - -func (c *InstancesClient) DeleteTags(ctx context.Context, input *DeleteTagsInput) error { - path := fmt.Sprintf("/%s/machines/%s/tags", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - response, err := c.client.ExecuteRequestRaw(ctx, reqInputs) - if response == nil { - return fmt.Errorf("DeleteTags request has empty response") - } - if response.Body != nil { - defer response.Body.Close() - } - if response.StatusCode == http.StatusNotFound { - return nil - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteTags request: {{err}}", - c.client.DecodeError(response.StatusCode, response.Body)) - } - - return nil -} - -type DeleteTagInput struct { - ID string - Key string -} - -func (c *InstancesClient) DeleteTag(ctx context.Context, input *DeleteTagInput) error { - path := fmt.Sprintf("/%s/machines/%s/tags/%s", c.client.AccountName, input.ID, input.Key) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - response, err := c.client.ExecuteRequestRaw(ctx, reqInputs) - if response == nil { - return fmt.Errorf("DeleteTag request has empty response") - } - if response.Body != nil { - defer response.Body.Close() - } - if response.StatusCode == http.StatusNotFound { - return nil - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteTag request: {{err}}", - c.client.DecodeError(response.StatusCode, response.Body)) - } - - return nil -} - -type RenameInstanceInput struct { - ID string - Name string -} - -func (c *InstancesClient) Rename(ctx context.Context, input *RenameInstanceInput) error { - path := fmt.Sprintf("/%s/machines/%s", c.client.AccountName, input.ID) - - params := &url.Values{} - params.Set("action", "rename") - params.Set("name", input.Name) - - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Query: params, - } - respReader, err := c.client.ExecuteRequestURIParams(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing Rename request: {{err}}", err) - } - - return nil -} - -type ReplaceTagsInput struct { - ID string - Tags map[string]string - CNS InstanceCNS -} - -// toAPI is used to join Tags and CNS tags into the same JSON object before -// sending an API request to the API gateway. -func (input ReplaceTagsInput) toAPI() map[string]interface{} { - result := map[string]interface{}{} - for key, value := range input.Tags { - result[key] = value - } - input.CNS.toTags(result) - return result -} - -func (c *InstancesClient) ReplaceTags(ctx context.Context, input *ReplaceTagsInput) error { - path := fmt.Sprintf("/%s/machines/%s/tags", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodPut, - Path: path, - Body: input.toAPI(), - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing ReplaceTags request: {{err}}", err) - } - - return nil -} - -type AddTagsInput struct { - ID string - Tags map[string]string -} - -func (c *InstancesClient) AddTags(ctx context.Context, input *AddTagsInput) error { - path := fmt.Sprintf("/%s/machines/%s/tags", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input.Tags, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing AddTags request: {{err}}", err) - } - - return nil -} - -type GetTagInput struct { - ID string - Key string -} - -func (c *InstancesClient) GetTag(ctx context.Context, input *GetTagInput) (string, error) { - path := fmt.Sprintf("/%s/machines/%s/tags/%s", c.client.AccountName, input.ID, input.Key) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return "", errwrap.Wrapf("Error executing GetTag request: {{err}}", err) - } - - var result string - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return "", errwrap.Wrapf("Error decoding GetTag response: {{err}}", err) - } - - return result, nil -} - -type ListTagsInput struct { - ID string -} - -func (c *InstancesClient) ListTags(ctx context.Context, input *ListTagsInput) (map[string]interface{}, error) { - path := fmt.Sprintf("/%s/machines/%s/tags", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListTags request: {{err}}", err) - } - - var result map[string]interface{} - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListTags response: {{err}}", err) - } - - _, tags := tagsExtractMeta(result) - return tags, nil -} - -type GetMetadataInput struct { - ID string - Key string -} - -// GetMetadata returns a single metadata entry associated with an instance. -func (c *InstancesClient) GetMetadata(ctx context.Context, input *GetMetadataInput) (string, error) { - if input.Key == "" { - return "", fmt.Errorf("Missing metadata Key from input: %s", input.Key) - } - - path := fmt.Sprintf("/%s/machines/%s/metadata/%s", c.client.AccountName, input.ID, input.Key) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - response, err := c.client.ExecuteRequestRaw(ctx, reqInputs) - if response != nil { - defer response.Body.Close() - } - if response.StatusCode == http.StatusNotFound || response.StatusCode == http.StatusGone { - return "", &client.TritonError{ - StatusCode: response.StatusCode, - Code: "ResourceNotFound", - } - } - if err != nil { - return "", errwrap.Wrapf("Error executing Get request: {{err}}", - c.client.DecodeError(response.StatusCode, response.Body)) - } - - body, err := ioutil.ReadAll(response.Body) - if err != nil { - return "", errwrap.Wrapf("Error unwrapping request body: {{err}}", - c.client.DecodeError(response.StatusCode, response.Body)) - } - - return fmt.Sprintf("%s", body), nil -} - -type ListMetadataInput struct { - ID string - Credentials bool -} - -func (c *InstancesClient) ListMetadata(ctx context.Context, input *ListMetadataInput) (map[string]string, error) { - path := fmt.Sprintf("/%s/machines/%s/metadata", c.client.AccountName, input.ID) - - query := &url.Values{} - if input.Credentials { - query.Set("credentials", "true") - } - - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - Query: query, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListMetadata request: {{err}}", err) - } - - var result map[string]string - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListMetadata response: {{err}}", err) - } - - return result, nil -} - -type UpdateMetadataInput struct { - ID string - Metadata map[string]string -} - -func (c *InstancesClient) UpdateMetadata(ctx context.Context, input *UpdateMetadataInput) (map[string]string, error) { - path := fmt.Sprintf("/%s/machines/%s/metadata", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input.Metadata, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing UpdateMetadata request: {{err}}", err) - } - - var result map[string]string - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding UpdateMetadata response: {{err}}", err) - } - - return result, nil -} - -type DeleteMetadataInput struct { - ID string - Key string -} - -// DeleteMetadata deletes a single metadata key from an instance -func (c *InstancesClient) DeleteMetadata(ctx context.Context, input *DeleteMetadataInput) error { - if input.Key == "" { - return fmt.Errorf("Missing metadata Key from input: %s", input.Key) - } - - path := fmt.Sprintf("/%s/machines/%s/metadata/%s", c.client.AccountName, input.ID, input.Key) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteMetadata request: {{err}}", err) - } - - return nil -} - -type DeleteAllMetadataInput struct { - ID string -} - -// DeleteAllMetadata deletes all metadata keys from this instance -func (c *InstancesClient) DeleteAllMetadata(ctx context.Context, input *DeleteAllMetadataInput) error { - path := fmt.Sprintf("/%s/machines/%s/metadata", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteAllMetadata request: {{err}}", err) - } - - return nil -} - -type ResizeInstanceInput struct { - ID string - Package string -} - -func (c *InstancesClient) Resize(ctx context.Context, input *ResizeInstanceInput) error { - path := fmt.Sprintf("/%s/machines/%s", c.client.AccountName, input.ID) - - params := &url.Values{} - params.Set("action", "resize") - params.Set("package", input.Package) - - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Query: params, - } - respReader, err := c.client.ExecuteRequestURIParams(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing Resize request: {{err}}", err) - } - - return nil -} - -type EnableFirewallInput struct { - ID string -} - -func (c *InstancesClient) EnableFirewall(ctx context.Context, input *EnableFirewallInput) error { - path := fmt.Sprintf("/%s/machines/%s", c.client.AccountName, input.ID) - - params := &url.Values{} - params.Set("action", "enable_firewall") - - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Query: params, - } - respReader, err := c.client.ExecuteRequestURIParams(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing EnableFirewall request: {{err}}", err) - } - - return nil -} - -type DisableFirewallInput struct { - ID string -} - -func (c *InstancesClient) DisableFirewall(ctx context.Context, input *DisableFirewallInput) error { - path := fmt.Sprintf("/%s/machines/%s", c.client.AccountName, input.ID) - - params := &url.Values{} - params.Set("action", "disable_firewall") - - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Query: params, - } - respReader, err := c.client.ExecuteRequestURIParams(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing DisableFirewall request: {{err}}", err) - } - - return nil -} - -type ListNICsInput struct { - InstanceID string -} - -func (c *InstancesClient) ListNICs(ctx context.Context, input *ListNICsInput) ([]*NIC, error) { - path := fmt.Sprintf("/%s/machines/%s/nics", c.client.AccountName, input.InstanceID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListNICs request: {{err}}", err) - } - - var result []*NIC - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListNICs response: {{err}}", err) - } - - return result, nil -} - -type GetNICInput struct { - InstanceID string - MAC string -} - -func (c *InstancesClient) GetNIC(ctx context.Context, input *GetNICInput) (*NIC, error) { - mac := strings.Replace(input.MAC, ":", "", -1) - path := fmt.Sprintf("/%s/machines/%s/nics/%s", c.client.AccountName, input.InstanceID, mac) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - response, err := c.client.ExecuteRequestRaw(ctx, reqInputs) - if response != nil { - defer response.Body.Close() - } - switch response.StatusCode { - case http.StatusNotFound: - return nil, &client.TritonError{ - StatusCode: response.StatusCode, - Code: "ResourceNotFound", - } - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetNIC request: {{err}}", err) - } - - var result *NIC - decoder := json.NewDecoder(response.Body) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListNICs response: {{err}}", err) - } - - return result, nil -} - -type AddNICInput struct { - InstanceID string `json:"-"` - Network string `json:"network"` -} - -// AddNIC asynchronously adds a NIC to a given instance. If a NIC for a given -// network already exists, a ResourceFound error will be returned. The status -// of the addition of a NIC can be polled by calling GetNIC()'s and testing NIC -// until its state is set to "running". Only one NIC per network may exist. -// Warning: this operation causes the instance to restart. -func (c *InstancesClient) AddNIC(ctx context.Context, input *AddNICInput) (*NIC, error) { - path := fmt.Sprintf("/%s/machines/%s/nics", c.client.AccountName, input.InstanceID) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - response, err := c.client.ExecuteRequestRaw(ctx, reqInputs) - if response != nil { - defer response.Body.Close() - } - switch response.StatusCode { - case http.StatusFound: - return nil, &client.TritonError{ - StatusCode: response.StatusCode, - Code: "ResourceFound", - Message: response.Header.Get("Location"), - } - } - if err != nil { - return nil, errwrap.Wrapf("Error executing AddNIC request: {{err}}", err) - } - - var result *NIC - decoder := json.NewDecoder(response.Body) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding AddNIC response: {{err}}", err) - } - - return result, nil -} - -type RemoveNICInput struct { - InstanceID string - MAC string -} - -// RemoveNIC removes a given NIC from a machine asynchronously. The status of -// the removal can be polled via GetNIC(). When GetNIC() returns a 404, the NIC -// has been removed from the instance. Warning: this operation causes the -// machine to restart. -func (c *InstancesClient) RemoveNIC(ctx context.Context, input *RemoveNICInput) error { - mac := strings.Replace(input.MAC, ":", "", -1) - path := fmt.Sprintf("/%s/machines/%s/nics/%s", c.client.AccountName, input.InstanceID, mac) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - response, err := c.client.ExecuteRequestRaw(ctx, reqInputs) - if response != nil { - defer response.Body.Close() - } - switch response.StatusCode { - case http.StatusNotFound: - return &client.TritonError{ - StatusCode: response.StatusCode, - Code: "ResourceNotFound", - } - } - if err != nil { - return errwrap.Wrapf("Error executing RemoveNIC request: {{err}}", err) - } - - return nil -} - -type StopInstanceInput struct { - InstanceID string -} - -func (c *InstancesClient) Stop(ctx context.Context, input *StopInstanceInput) error { - path := fmt.Sprintf("/%s/machines/%s", c.client.AccountName, input.InstanceID) - - params := &url.Values{} - params.Set("action", "stop") - - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Query: params, - } - respReader, err := c.client.ExecuteRequestURIParams(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing Stop request: {{err}}", err) - } - - return nil -} - -type StartInstanceInput struct { - InstanceID string -} - -func (c *InstancesClient) Start(ctx context.Context, input *StartInstanceInput) error { - path := fmt.Sprintf("/%s/machines/%s", c.client.AccountName, input.InstanceID) - - params := &url.Values{} - params.Set("action", "start") - - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Query: params, - } - respReader, err := c.client.ExecuteRequestURIParams(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing Start request: {{err}}", err) - } - - return nil -} - -type RebootInstanceInput struct { - InstanceID string -} - -func (c *InstancesClient) Reboot(ctx context.Context, input *RebootInstanceInput) error { - path := fmt.Sprintf("/%s/machines/%s", c.client.AccountName, input.InstanceID) - - params := &url.Values{} - params.Set("action", "reboot") - - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Query: params, - } - respReader, err := c.client.ExecuteRequestURIParams(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing Start request: {{err}}", err) - } - - return nil -} - -var reservedInstanceCNSTags = map[string]struct{}{ - CNSTagDisable: {}, - CNSTagReversePTR: {}, - CNSTagServices: {}, -} - -// tagsExtractMeta() extracts all of the misc parameters from Tags and returns a -// clean CNS and Tags struct. -func tagsExtractMeta(tags map[string]interface{}) (InstanceCNS, map[string]interface{}) { - nativeCNS := InstanceCNS{} - nativeTags := make(map[string]interface{}, len(tags)) - for k, raw := range tags { - if _, found := reservedInstanceCNSTags[k]; found { - switch k { - case CNSTagDisable: - b := raw.(bool) - nativeCNS.Disable = b - case CNSTagReversePTR: - s := raw.(string) - nativeCNS.ReversePTR = s - case CNSTagServices: - nativeCNS.Services = strings.Split(raw.(string), ",") - default: - // TODO(seanc@): should assert, logic fail - } - } else { - nativeTags[k] = raw - } - } - - return nativeCNS, nativeTags -} - -// toNative() exports a given _Instance (API representation) to its native object -// format. -func (api *_Instance) toNative() (*Instance, error) { - m := Instance(api.Instance) - m.CNS, m.Tags = tagsExtractMeta(api.Tags) - return &m, nil -} - -// toTags() injects its state information into a Tags map suitable for use to -// submit an API call to the vmapi machine endpoint -func (cns *InstanceCNS) toTags(m map[string]interface{}) { - if cns.Disable { - // NOTE(justinwr): The JSON encoder and API require the CNSTagDisable - // attribute to be an actual boolean, not a bool string. - m[CNSTagDisable] = cns.Disable - } - if cns.ReversePTR != "" { - m[CNSTagReversePTR] = cns.ReversePTR - } - if len(cns.Services) > 0 { - m[CNSTagServices] = strings.Join(cns.Services, ",") - } -} diff --git a/vendor/github.com/joyent/triton-go/compute/instances_test.go b/vendor/github.com/joyent/triton-go/compute/instances_test.go deleted file mode 100644 index 3811710..0000000 --- a/vendor/github.com/joyent/triton-go/compute/instances_test.go +++ /dev/null @@ -1,478 +0,0 @@ -package compute - -import ( - "context" - "errors" - "fmt" - "log" - "math/rand" - "os" - "reflect" - "testing" - "time" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/network" - "github.com/joyent/triton-go/testutils" -) - -func getAnyInstanceID(t *testing.T, client *ComputeClient) (string, error) { - ctx := context.Background() - input := &ListInstancesInput{} - instances, err := client.Instances().List(ctx, input) - if err != nil { - return "", err - } - - for _, m := range instances { - if len(m.ID) > 0 { - return m.ID, nil - } - } - - t.Skip() - return "", errors.New("no machines configured") -} - -func RandInt() int { - reseed() - return rand.New(rand.NewSource(time.Now().UnixNano())).Int() -} - -func RandWithPrefix(name string) string { - return fmt.Sprintf("%s-%d", name, RandInt()) -} - -// Seeds random with current timestamp -func reseed() { - rand.Seed(time.Now().UTC().UnixNano()) -} - -func TestAccInstances_Create(t *testing.T) { - testInstanceName := RandWithPrefix("acctest") - - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "instances", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - computeClient, err := NewClient(config) - if err != nil { - return nil, err - } - - networkClient, err := network.NewClient(config) - if err != nil { - return nil, err - } - - return []interface{}{ - computeClient, - networkClient, - }, nil - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "instances", - CallFunc: func(client interface{}) (interface{}, error) { - clients := client.([]interface{}) - c := clients[0].(*ComputeClient) - n := clients[1].(*network.NetworkClient) - - images, err := c.Images().List(context.Background(), &ListImagesInput{ - Name: "ubuntu-16.04", - Version: "20170403", - }) - img := images[0] - - var net *network.Network - networkName := "Joyent-SDC-Private" - nets, err := n.List(context.Background(), &network.ListInput{}) - if err != nil { - return nil, err - } - for _, found := range nets { - if found.Name == networkName { - net = found - } - } - - input := &CreateInstanceInput{ - Name: testInstanceName, - Package: "g4-highcpu-128M", - Image: img.ID, - Networks: []string{net.Id}, - Metadata: map[string]string{ - "metadata1": "value1", - }, - Tags: map[string]string{ - "tag1": "value1", - }, - CNS: InstanceCNS{ - Services: []string{"testapp", "testweb"}, - }, - } - created, err := c.Instances().Create(context.Background(), input) - if err != nil { - return nil, err - } - - state := make(chan *Instance, 1) - go func(createdID string, c *ComputeClient) { - for { - time.Sleep(1 * time.Second) - instance, err := c.Instances().Get(context.Background(), &GetInstanceInput{ - ID: createdID, - }) - if err != nil { - log.Fatalf("Get(): %v", err) - } - if instance.State == "running" { - state <- instance - } - } - }(created.ID, c) - - select { - case instance := <-state: - return instance, nil - case <-time.After(5 * time.Minute): - return nil, fmt.Errorf("Timed out waiting for instance to provision") - } - }, - CleanupFunc: func(client interface{}, stateBag interface{}) { - instance, instOk := stateBag.(*Instance) - if !instOk { - log.Println("Expected instance to be Instance") - return - } - - if instance.Name != testInstanceName { - log.Printf("Expected instance to be named %s: found %s\n", - testInstanceName, instance.Name) - return - } - - clients := client.([]interface{}) - c, clientOk := clients[0].(*ComputeClient) - if !clientOk { - log.Println("Expected client to be ComputeClient") - return - } - - err := c.Instances().Delete(context.Background(), &DeleteInstanceInput{ - ID: instance.ID, - }) - if err != nil { - log.Printf("Could not delete instance %s\n", instance.Name) - } - return - }, - }, - - &testutils.StepAssertFunc{ - AssertFunc: func(state testutils.TritonStateBag) error { - instanceRaw, found := state.GetOk("instances") - if !found { - return fmt.Errorf("State key %q not found", "instances") - } - instance, ok := instanceRaw.(*Instance) - if !ok { - return errors.New("Expected state to include instance") - } - - if instance.State != "running" { - return fmt.Errorf("Expected instance state to be \"running\": found %s", - instance.State) - } - if instance.ID == "" { - return fmt.Errorf("Expected instance ID: found \"\"") - } - if instance.Name == "" { - return fmt.Errorf("Expected instance Name: found \"\"") - } - if instance.Memory != 128 { - return fmt.Errorf("Expected instance Memory to be 128: found \"%d\"", - instance.Memory) - } - - metadataVal, metaOk := instance.Metadata["metadata1"] - if !metaOk { - return fmt.Errorf("Expected instance to have Metadata: found \"%v\"", - instance.Metadata) - } - if metadataVal != "value1" { - return fmt.Errorf("Expected instance Metadata \"metadata1\" to equal \"value1\": found \"%s\"", - metadataVal) - } - - tagVal, tagOk := instance.Tags["tag1"] - if !tagOk { - return fmt.Errorf("Expected instance to have Tags: found \"%v\"", - instance.Tags) - } - if tagVal != "value1" { - return fmt.Errorf("Expected instance Tag \"tag1\" to equal \"value1\": found \"%s\"", - tagVal) - } - - services := []string{"testapp", "testweb"} - if !reflect.DeepEqual(instance.CNS.Services, services) { - return fmt.Errorf("Expected instance CNS Services \"%s\", to equal \"%v\"", - instance.CNS.Services, services) - } - return nil - }, - }, - }, - }) -} - -func TestAccInstances_Get(t *testing.T) { - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "instances", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "instances", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - - instanceID, err := getAnyInstanceID(t, c) - if err != nil { - return nil, err - } - - ctx := context.Background() - input := &GetInstanceInput{ - ID: instanceID, - } - return c.Instances().Get(ctx, input) - }, - }, - - &testutils.StepAssertSet{ - StateBagKey: "instances", - Keys: []string{"ID", "Name", "Type", "Tags"}, - }, - }, - }) -} - -// FIXME(seanc@): TestAccMachine_ListMachineTags assumes that any machine ID -// returned from getAnyInstanceID will have at least one tag. -func TestAccInstances_ListTags(t *testing.T) { - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "instances", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "instances", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - - instanceID, err := getAnyInstanceID(t, c) - if err != nil { - return nil, err - } - - ctx := context.Background() - input := &ListTagsInput{ - ID: instanceID, - } - return c.Instances().ListTags(ctx, input) - }, - }, - - &testutils.StepAssertFunc{ - AssertFunc: func(state testutils.TritonStateBag) error { - tagsRaw, found := state.GetOk("instances") - if !found { - return fmt.Errorf("State key %q not found", "instances") - } - - tags := tagsRaw.(map[string]interface{}) - if len(tags) == 0 { - return errors.New("Expected at least one tag on machine") - } - return nil - }, - }, - }, - }) -} - -func TestAccInstances_UpdateMetadata(t *testing.T) { - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "instances", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "instances", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - - instanceID, err := getAnyInstanceID(t, c) - if err != nil { - return nil, err - } - - ctx := context.Background() - input := &UpdateMetadataInput{ - ID: instanceID, - Metadata: map[string]string{ - "tester": os.Getenv("USER"), - }, - } - return c.Instances().UpdateMetadata(ctx, input) - }, - }, - - &testutils.StepAssertFunc{ - AssertFunc: func(state testutils.TritonStateBag) error { - mdataRaw, found := state.GetOk("instances") - if !found { - return fmt.Errorf("State key %q not found", "instances") - } - - mdata := mdataRaw.(map[string]string) - if len(mdata) == 0 { - return errors.New("Expected metadata on machine") - } - - if mdata["tester"] != os.Getenv("USER") { - return errors.New("Expected test metadata to equal environ $USER") - } - return nil - }, - }, - }, - }) -} - -func TestAccInstances_ListMetadata(t *testing.T) { - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "instances", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "instances", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - - instanceID, err := getAnyInstanceID(t, c) - if err != nil { - return nil, err - } - - ctx := context.Background() - input := &ListMetadataInput{ - ID: instanceID, - } - return c.Instances().ListMetadata(ctx, input) - }, - }, - - &testutils.StepAssertFunc{ - AssertFunc: func(state testutils.TritonStateBag) error { - mdataRaw, found := state.GetOk("instances") - if !found { - return fmt.Errorf("State key %q not found", "instances") - } - - mdata := mdataRaw.(map[string]string) - if len(mdata) == 0 { - return errors.New("Expected metadata on machine") - } - - if mdata["root_authorized_keys"] == "" { - return errors.New("Expected test metadata to have key") - } - return nil - }, - }, - }, - }) -} - -func TestAccInstances_GetMetadata(t *testing.T) { - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "instances", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "instances", - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - - instanceID, err := getAnyInstanceID(t, c) - if err != nil { - return nil, err - } - - ctx := context.Background() - input := &UpdateMetadataInput{ - ID: instanceID, - Metadata: map[string]string{ - "testkey": os.Getenv("USER"), - }, - } - _, err = c.Instances().UpdateMetadata(ctx, input) - if err != nil { - return nil, err - } - - ctx2 := context.Background() - input2 := &GetMetadataInput{ - ID: instanceID, - Key: "testkey", - } - return c.Instances().GetMetadata(ctx2, input2) - }, - }, - - &testutils.StepAssertFunc{ - AssertFunc: func(state testutils.TritonStateBag) error { - mdataValue := state.Get("instances") - retValue := fmt.Sprintf("\"%s\"", os.Getenv("USER")) - if mdataValue != retValue { - return errors.New("Expected test metadata to equal environ \"$USER\"") - } - return nil - }, - }, - }, - }) -} diff --git a/vendor/github.com/joyent/triton-go/compute/packages.go b/vendor/github.com/joyent/triton-go/compute/packages.go deleted file mode 100644 index f18407e..0000000 --- a/vendor/github.com/joyent/triton-go/compute/packages.go +++ /dev/null @@ -1,91 +0,0 @@ -package compute - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type PackagesClient struct { - client *client.Client -} - -type Package struct { - ID string `json:"id"` - Name string `json:"name"` - Memory int64 `json:"memory"` - Disk int64 `json:"disk"` - Swap int64 `json:"swap"` - LWPs int64 `json:"lwps"` - VCPUs int64 `json:"vcpus"` - Version string `json:"version"` - Group string `json:"group"` - Description string `json:"description"` - Default bool `json:"default"` -} - -type ListPackagesInput struct { - Name string `json:"name"` - Memory int64 `json:"memory"` - Disk int64 `json:"disk"` - Swap int64 `json:"swap"` - LWPs int64 `json:"lwps"` - VCPUs int64 `json:"vcpus"` - Version string `json:"version"` - Group string `json:"group"` -} - -func (c *PackagesClient) List(ctx context.Context, input *ListPackagesInput) ([]*Package, error) { - path := fmt.Sprintf("/%s/packages", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing List request: {{err}}", err) - } - - var result []*Package - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding List response: {{err}}", err) - } - - return result, nil -} - -type GetPackageInput struct { - ID string -} - -func (c *PackagesClient) Get(ctx context.Context, input *GetPackageInput) (*Package, error) { - path := fmt.Sprintf("/%s/packages/%s", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing Get request: {{err}}", err) - } - - var result *Package - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding Get response: {{err}}", err) - } - - return result, nil -} diff --git a/vendor/github.com/joyent/triton-go/compute/ping.go b/vendor/github.com/joyent/triton-go/compute/ping.go deleted file mode 100644 index c0f62df..0000000 --- a/vendor/github.com/joyent/triton-go/compute/ping.go +++ /dev/null @@ -1,56 +0,0 @@ -package compute - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -const pingEndpoint = "/--ping" - -type CloudAPI struct { - Versions []string `json:"versions"` -} - -type PingOutput struct { - Ping string `json:"ping"` - CloudAPI CloudAPI `json:"cloudapi"` -} - -// Ping sends a request to the '/--ping' endpoint and returns a `pong` as well -// as a list of API version numbers your instance of CloudAPI is presenting. -func (c *ComputeClient) Ping(ctx context.Context) (*PingOutput, error) { - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: pingEndpoint, - } - response, err := c.Client.ExecuteRequestRaw(ctx, reqInputs) - if response == nil { - return nil, fmt.Errorf("Ping request has empty response") - } - if response.Body != nil { - defer response.Body.Close() - } - if response.StatusCode == http.StatusNotFound || response.StatusCode == http.StatusGone { - return nil, &client.TritonError{ - StatusCode: response.StatusCode, - Code: "ResourceNotFound", - } - } - if err != nil { - return nil, errwrap.Wrapf("Error executing Get request: {{err}}", - c.Client.DecodeError(response.StatusCode, response.Body)) - } - - var result *PingOutput - decoder := json.NewDecoder(response.Body) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding Get response: {{err}}", err) - } - - return result, nil -} diff --git a/vendor/github.com/joyent/triton-go/compute/ping_test.go b/vendor/github.com/joyent/triton-go/compute/ping_test.go deleted file mode 100644 index b95816e..0000000 --- a/vendor/github.com/joyent/triton-go/compute/ping_test.go +++ /dev/null @@ -1,190 +0,0 @@ -package compute_test - -import ( - "context" - "errors" - "io/ioutil" - "net/http" - "reflect" - "strings" - "testing" - - "github.com/joyent/triton-go/compute" - "github.com/joyent/triton-go/testutils" -) - -var ( - mockVersions = []string{"7.0.0", "7.1.0", "7.2.0", "7.3.0", "8.0.0"} - testError = errors.New("we got the funk") - defaultHeader = http.Header{} - blankError = "Ping request has empty response" -) - -func TestPing(t *testing.T) { - computeClient := MockComputeClient() - - do := func(ctx context.Context, pc *compute.ComputeClient) (*compute.PingOutput, error) { - defer testutils.DeactivateClient() - - ping, err := pc.Ping(ctx) - if err != nil { - return nil, err - } - return ping, nil - } - - t.Run("successful", func(t *testing.T) { - testutils.RegisterResponder("GET", "/--ping", pingSuccessFunc) - - resp, err := do(context.Background(), computeClient) - if err != nil { - t.Fatal(err) - } - - if resp.Ping != "pong" { - t.Errorf("ping was not pong: expected %s", resp.Ping) - } - - if !reflect.DeepEqual(resp.CloudAPI.Versions, mockVersions) { - t.Errorf("ping did not contain CloudAPI versions: expected %s", mockVersions) - } - }) - - t.Run("EOF decode", func(t *testing.T) { - testutils.RegisterResponder("GET", "/--ping", pingEmptyFunc) - - _, err := do(context.Background(), computeClient) - if err == nil { - t.Fatal(err) - } - - if !strings.Contains(err.Error(), "EOF") { - t.Errorf("expected error to contain EOF: found %s", err) - } - }) - - t.Run("error", func(t *testing.T) { - testutils.RegisterResponder("GET", "/--ping", pingErrorFunc) - - out, err := do(context.Background(), computeClient) - if err == nil { - t.Fatal(err) - } - if out != nil { - t.Error("expected pingOut to be nil") - } - - if err.Error() != blankError { - t.Errorf("expected error to equal testError: found %s", err) - } - }) - - t.Run("404", func(t *testing.T) { - testutils.RegisterResponder("GET", "/--ping", ping404Func) - - _, err := do(context.Background(), computeClient) - if err == nil { - t.Fatal(err) - } - - if !strings.Contains(err.Error(), "ResourceNotFound") { - t.Errorf("expected error to be a 404: found %s", err) - } - }) - - t.Run("410", func(t *testing.T) { - testutils.RegisterResponder("GET", "/--ping", ping410Func) - - _, err := do(context.Background(), computeClient) - if err == nil { - t.Fatal(err) - } - - if !strings.Contains(err.Error(), "ResourceNotFound") { - t.Errorf("expected error to be a 410: found %s", err) - } - }) - - t.Run("bad decode", func(t *testing.T) { - testutils.RegisterResponder("GET", "/--ping", pingDecodeFunc) - - _, err := do(context.Background(), computeClient) - if err == nil { - t.Fatal(err) - } - - if !strings.Contains(err.Error(), "invalid character") { - t.Errorf("expected decode to fail: found %s", err) - } - }) -} - -func pingSuccessFunc(req *http.Request) (*http.Response, error) { - header := http.Header{} - header.Add("Content-Type", "application/json") - - body := strings.NewReader(`{ - "ping": "pong", - "cloudapi": { - "versions": ["7.0.0", "7.1.0", "7.2.0", "7.3.0", "8.0.0"] - } -}`) - return &http.Response{ - StatusCode: 200, - Header: header, - Body: ioutil.NopCloser(body), - }, nil -} - -func pingEmptyFunc(req *http.Request) (*http.Response, error) { - header := http.Header{} - header.Add("Content-Type", "application/json") - return &http.Response{ - StatusCode: 200, - Header: header, - Body: ioutil.NopCloser(strings.NewReader("")), - }, nil -} - -func ping404Func(req *http.Request) (*http.Response, error) { - header := http.Header{} - header.Add("Content-Type", "application/json") - return &http.Response{ - StatusCode: 404, - Header: header, - }, nil -} - -func ping410Func(req *http.Request) (*http.Response, error) { - header := http.Header{} - header.Add("Content-Type", "application/json") - return &http.Response{ - StatusCode: 410, - Header: header, - }, nil -} - -func pingErrorFunc(req *http.Request) (*http.Response, error) { - return nil, testError -} - -func pingDecodeFunc(req *http.Request) (*http.Response, error) { - header := http.Header{} - header.Add("Content-Type", "application/json") - - body := strings.NewReader(`{ -(ham!(// -}`) - - return &http.Response{ - StatusCode: 200, - Header: header, - Body: ioutil.NopCloser(body), - }, nil -} - -func MockComputeClient() *compute.ComputeClient { - return &compute.ComputeClient{ - Client: testutils.DefaultMockClient, - } -} diff --git a/vendor/github.com/joyent/triton-go/compute/services.go b/vendor/github.com/joyent/triton-go/compute/services.go deleted file mode 100644 index af1b017..0000000 --- a/vendor/github.com/joyent/triton-go/compute/services.go +++ /dev/null @@ -1,64 +0,0 @@ -package compute - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "sort" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type ServicesClient struct { - client *client.Client -} - -type Service struct { - Name string - Endpoint string -} - -type ListServicesInput struct{} - -func (c *ServicesClient) List(ctx context.Context, _ *ListServicesInput) ([]*Service, error) { - path := fmt.Sprintf("/%s/services", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing List request: {{err}}", err) - } - - var intermediate map[string]string - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&intermediate); err != nil { - return nil, errwrap.Wrapf("Error decoding List response: {{err}}", err) - } - - keys := make([]string, len(intermediate)) - i := 0 - for k := range intermediate { - keys[i] = k - i++ - } - sort.Strings(keys) - - result := make([]*Service, len(intermediate)) - i = 0 - for _, key := range keys { - result[i] = &Service{ - Name: key, - Endpoint: intermediate[key], - } - i++ - } - - return result, nil -} diff --git a/vendor/github.com/joyent/triton-go/compute/services_test.go b/vendor/github.com/joyent/triton-go/compute/services_test.go deleted file mode 100644 index c8a5cd6..0000000 --- a/vendor/github.com/joyent/triton-go/compute/services_test.go +++ /dev/null @@ -1,63 +0,0 @@ -package compute - -import ( - "context" - "fmt" - "testing" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/testutils" -) - -func TestAccServicesList(t *testing.T) { - const stateKey = "services" - - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: stateKey, - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: stateKey, - CallFunc: func(client interface{}) (interface{}, error) { - c := client.(*ComputeClient) - ctx := context.Background() - input := &ListServicesInput{} - return c.Services().List(ctx, input) - }, - }, - - &testutils.StepAssertFunc{ - AssertFunc: func(state testutils.TritonStateBag) error { - services, ok := state.GetOk(stateKey) - if !ok { - return fmt.Errorf("State key %q not found", stateKey) - } - - toFind := []string{"docker"} - for _, serviceName := range toFind { - found := false - for _, service := range services.([]*Service) { - if service.Name == serviceName { - found = true - if service.Endpoint == "" { - return fmt.Errorf("%q has no Endpoint", service.Name) - } - } - } - if !found { - return fmt.Errorf("Did not find Service %q", serviceName) - } - } - - return nil - }, - }, - }, - }) -} diff --git a/vendor/github.com/joyent/triton-go/examples/account/account_info.go b/vendor/github.com/joyent/triton-go/examples/account/account_info.go deleted file mode 100644 index 06badbe..0000000 --- a/vendor/github.com/joyent/triton-go/examples/account/account_info.go +++ /dev/null @@ -1,96 +0,0 @@ -package main - -import ( - "context" - "fmt" - "io/ioutil" - "log" - "os" - - "encoding/pem" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/account" - "github.com/joyent/triton-go/authentication" -) - -func printAccount(acct *account.Account) { - fmt.Println("Account ID:", acct.ID) - fmt.Println("Account Email:", acct.Email) - fmt.Println("Account Login:", acct.Login) -} - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - TritonURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - a, err := account.NewClient(config) - if err != nil { - log.Fatalf("compute.NewClient: %s", err) - } - - acct, err := a.Get(context.Background(), &account.GetInput{}) - if err != nil { - log.Fatalf("account.Get: %v", err) - } - - fmt.Println("New ----") - printAccount(acct) - - input := &account.UpdateInput{ - CompanyName: fmt.Sprintf("%s-old", acct.CompanyName), - } - - updatedAcct, err := a.Update(context.Background(), input) - if err != nil { - log.Fatalf("account.Update: %v", err) - } - - fmt.Println("New ----") - printAccount(updatedAcct) -} diff --git a/vendor/github.com/joyent/triton-go/examples/account/config.go b/vendor/github.com/joyent/triton-go/examples/account/config.go deleted file mode 100644 index d681e66..0000000 --- a/vendor/github.com/joyent/triton-go/examples/account/config.go +++ /dev/null @@ -1,109 +0,0 @@ -package main - -import ( - "context" - "fmt" - "io/ioutil" - "log" - "os" - - "encoding/pem" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/account" - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/network" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - TritonURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - nc, err := network.NewClient(config) - if err != nil { - log.Fatalf("network.NewClient: %s", err) - } - - ac, err := account.NewClient(config) - if err != nil { - log.Fatalf("account.NewClient: %s", err) - } - - cfg, err := ac.Config().Get(context.Background(), &account.GetConfigInput{}) - if err != nil { - log.Fatalf("account.Config.Get: %v", err) - } - currentNet := cfg.DefaultNetwork - fmt.Println("Current Network:", currentNet) - - var defaultNet string - networks, err := nc.List(context.Background(), &network.ListInput{}) - if err != nil { - log.Fatalf("network.List: %s", err) - } - for _, iterNet := range networks { - if iterNet.Id != currentNet { - defaultNet = iterNet.Id - } - } - fmt.Println("Chosen Network:", defaultNet) - - input := &account.UpdateConfigInput{ - DefaultNetwork: defaultNet, - } - _, err = ac.Config().Update(context.Background(), input) - if err != nil { - log.Fatalf("account.Config.Update: %v", err) - } - - cfg, err = ac.Config().Get(context.Background(), &account.GetConfigInput{}) - if err != nil { - log.Fatalf("account.Config.Get: %v", err) - } - fmt.Println("Default Network:", cfg.DefaultNetwork) -} diff --git a/vendor/github.com/joyent/triton-go/examples/account/keys.go b/vendor/github.com/joyent/triton-go/examples/account/keys.go deleted file mode 100644 index 2949589..0000000 --- a/vendor/github.com/joyent/triton-go/examples/account/keys.go +++ /dev/null @@ -1,92 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - "os" - - "encoding/pem" - "io/ioutil" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/account" - "github.com/joyent/triton-go/authentication" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - TritonURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - a, err := account.NewClient(config) - if err != nil { - log.Fatalf("failed to init a new account client: %s", err) - } - - keys, err := a.Keys().List(context.Background(), &account.ListKeysInput{}) - if err != nil { - log.Fatalf("failed to list keys: %v", err) - } - - for _, key := range keys { - fmt.Println("Key Name:", key.Name) - } - - if key := keys[0]; key != nil { - input := &account.GetKeyInput{ - KeyName: key.Name, - } - - key, err := a.Keys().Get(context.Background(), input) - if err != nil { - log.Fatalf("failed to get key: %v", err) - } - - fmt.Println("First Key:", key.Key) - } -} diff --git a/vendor/github.com/joyent/triton-go/examples/compute/create_instance.go b/vendor/github.com/joyent/triton-go/examples/compute/create_instance.go deleted file mode 100644 index bf2e8a3..0000000 --- a/vendor/github.com/joyent/triton-go/examples/compute/create_instance.go +++ /dev/null @@ -1,150 +0,0 @@ -package main - -import ( - "context" - "encoding/pem" - "fmt" - "io/ioutil" - "log" - "os" - "time" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/compute" - "github.com/joyent/triton-go/network" -) - -const ( - PackageName = "g4-highcpu-512M" - ImageName = "ubuntu-16.04" - ImageVersion = "20170403" - NetworkName = "Joyent-SDC-Private" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - TritonURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - c, err := compute.NewClient(config) - if err != nil { - log.Fatalf("Compute NewClient(): %s", err) - } - n, err := network.NewClient(config) - if err != nil { - log.Fatalf("Network NewClient(): %s", err) - } - - images, err := c.Images().List(context.Background(), &compute.ListImagesInput{ - Name: ImageName, - Version: ImageVersion, - }) - img := images[0] - - var net *network.Network - nets, err := n.List(context.Background(), &network.ListInput{}) - if err != nil { - log.Fatalf("Network List(): %s", err) - } - for _, found := range nets { - if found.Name == NetworkName { - net = found - } - } - - // Create a new instance using our input attributes... - // https://github.com/joyent/triton-go/blob/master/compute/instances.go#L206 - createInput := &compute.CreateInstanceInput{ - Name: "go-test1", - Package: PackageName, - Image: img.ID, - Networks: []string{net.Id}, - Metadata: map[string]string{ - "user-script": "", - }, - Tags: map[string]string{ - "tag1": "value1", - }, - CNS: compute.InstanceCNS{ - Services: []string{"frontend", "web"}, - }, - } - startTime := time.Now() - created, err := c.Instances().Create(context.Background(), createInput) - if err != nil { - log.Fatalf("Create(): %v", err) - } - - // Wait for provisioning to complete... - state := make(chan *compute.Instance, 1) - go func(createdID string, c *compute.ComputeClient) { - for { - time.Sleep(1 * time.Second) - instance, err := c.Instances().Get(context.Background(), &compute.GetInstanceInput{ - ID: createdID, - }) - if err != nil { - log.Fatalf("Get(): %v", err) - } - if instance.State == "running" { - state <- instance - } else { - fmt.Print(".") - } - } - }(created.ID, c) - - select { - case instance := <-state: - fmt.Printf("\nDuration: %s\n", time.Since(startTime)) - fmt.Println("Name:", instance.Name) - fmt.Println("State:", instance.State) - case <-time.After(5 * time.Minute): - fmt.Println("Timed out") - } -} diff --git a/vendor/github.com/joyent/triton-go/examples/compute/instances.go b/vendor/github.com/joyent/triton-go/examples/compute/instances.go deleted file mode 100644 index f1ce9d2..0000000 --- a/vendor/github.com/joyent/triton-go/examples/compute/instances.go +++ /dev/null @@ -1,80 +0,0 @@ -package main - -import ( - "context" - "encoding/pem" - "fmt" - "io/ioutil" - "log" - "os" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/compute" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - TritonURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - c, err := compute.NewClient(config) - if err != nil { - log.Fatalf("compute.NewClient: %s", err) - } - - listInput := &compute.ListInstancesInput{} - instances, err := c.Instances().List(context.Background(), listInput) - if err != nil { - log.Fatalf("compute.Instances.List: %v", err) - } - numInstances := 0 - for _, instance := range instances { - numInstances++ - fmt.Println(fmt.Sprintf("-- Instance: %v", instance.Name)) - } -} diff --git a/vendor/github.com/joyent/triton-go/examples/network/create_fabric.go b/vendor/github.com/joyent/triton-go/examples/network/create_fabric.go deleted file mode 100644 index 5d27098..0000000 --- a/vendor/github.com/joyent/triton-go/examples/network/create_fabric.go +++ /dev/null @@ -1,113 +0,0 @@ -package main - -import ( - "context" - "encoding/pem" - "fmt" - "io/ioutil" - "log" - "os" - "time" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/network" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - TritonURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - n, err := network.NewClient(config) - if err != nil { - log.Fatalf("Network NewClient(): %s", err) - } - - fabric, err := n.Fabrics().Create(context.Background(), &network.CreateFabricInput{ - FabricVLANID: 2, - Name: "testnet", - Description: "This is a test network", - Subnet: "10.50.1.0/24", - ProvisionStartIP: "10.50.1.10", - ProvisionEndIP: "10.50.1.240", - }) - if err != nil { - panic(err) - } - - fmt.Println("Fabric was successfully created!") - fmt.Println("Name:", fabric.Name) - time.Sleep(5 * time.Second) - - err = n.Fabrics().Delete(context.Background(), &network.DeleteFabricInput{ - FabricVLANID: 2, - NetworkID: fabric.Id, - }) - if err != nil { - panic(err) - } - - fmt.Println("Fabric was successfully deleted!") - time.Sleep(5 * time.Second) - - fwrule, err := n.Firewall().CreateRule(context.Background(), &network.CreateRuleInput{ - Enabled: false, - Rule: "FROM any TO tag \"bone-thug\" = \"basket-ball\" ALLOW udp PORT 8600", - }) - - fmt.Println("Firewall Rule was successfully added!") - time.Sleep(5 * time.Second) - - err = n.Firewall().DeleteRule(context.Background(), &network.DeleteRuleInput{ - ID: fwrule.ID, - }) - - fmt.Println("Firewall Rule was successfully deleted!") - time.Sleep(5 * time.Second) - -} diff --git a/vendor/github.com/joyent/triton-go/examples/storage/createjob.go b/vendor/github.com/joyent/triton-go/examples/storage/createjob.go deleted file mode 100644 index c3ec2f8..0000000 --- a/vendor/github.com/joyent/triton-go/examples/storage/createjob.go +++ /dev/null @@ -1,171 +0,0 @@ -package main - -import ( - "bufio" - "context" - "fmt" - "io/ioutil" - "log" - "os" - "time" - - "encoding/pem" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/storage" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - MantaURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - client, err := storage.NewClient(config) - if err != nil { - log.Fatalf("NewClient: %s", err) - } - - job, err := client.Jobs().Create(context.Background(), &storage.CreateJobInput{ - Name: "WordCount", - Phases: []*storage.JobPhase{ - { - Type: "map", - Exec: "wc", - }, - { - Type: "reduce", - Exec: "awk '{ l += $1; w += $2; c += $3 } END { print l, w, c }'", - }, - }, - }) - if err != nil { - log.Fatalf("CreateJob: %s", err) - } - - fmt.Printf("Job ID: %s\n", job.JobID) - - err = client.Jobs().AddInputs(context.Background(), &storage.AddJobInputsInput{ - JobID: job.JobID, - ObjectPaths: []string{ - fmt.Sprintf("/%s/stor/books/treasure_island.txt", accountName), - fmt.Sprintf("/%s/stor/books/moby_dick.txt", accountName), - fmt.Sprintf("/%s/stor/books/huck_finn.txt", accountName), - fmt.Sprintf("/%s/stor/books/dracula.txt", accountName), - }, - }) - if err != nil { - log.Fatalf("AddJobInputs: %s", err) - } - - err = client.Jobs().AddInputs(context.Background(), &storage.AddJobInputsInput{ - JobID: job.JobID, - ObjectPaths: []string{ - fmt.Sprintf("/%s/stor/books/sherlock_holmes.txt", accountName), - }, - }) - if err != nil { - log.Fatalf("AddJobInputs: %s", err) - } - - gjo, err := client.Jobs().Get(context.Background(), &storage.GetJobInput{ - JobID: job.JobID, - }) - if err != nil { - log.Fatalf("GetJob: %s", err) - } - - fmt.Printf("%+v\n", gjo.Job) - fmt.Printf("%+v\n", gjo.Job.Stats) - - err = client.Jobs().EndInput(context.Background(), &storage.EndJobInputInput{ - JobID: job.JobID, - }) - if err != nil { - log.Fatalf("EndJobInput: %s", err) - } - - jobs, err := client.Jobs().List(context.Background(), &storage.ListJobsInput{}) - if err != nil { - log.Fatalf("ListJobs: %s", err) - } - - fmt.Printf("Number of jobs: %d\n", jobs.ResultSetSize) - for _, j := range jobs.Jobs { - fmt.Printf(" - %s\n", j.ID) - } - - gjio, err := client.Jobs().GetInput(context.Background(), &storage.GetJobInputInput{ - JobID: job.JobID, - }) - if err != nil { - log.Fatalf("GetJobInput: %s", err) - } - defer gjio.Items.Close() - - fmt.Printf("Result set size: %d\n", gjio.ResultSetSize) - outputsScanner := bufio.NewScanner(gjio.Items) - for outputsScanner.Scan() { - fmt.Printf(" - %s\n", outputsScanner.Text()) - } - - time.Sleep(10 * time.Second) - - gjoo, err := client.Jobs().GetOutput(context.Background(), &storage.GetJobOutputInput{ - JobID: job.JobID, - }) - if err != nil { - log.Fatalf("GetJobOutput: %s", err) - } - defer gjoo.Items.Close() - - fmt.Printf("Result set size: %d\n", gjoo.ResultSetSize) - outputsScanner = bufio.NewScanner(gjoo.Items) - for outputsScanner.Scan() { - fmt.Printf(" - %s\n", outputsScanner.Text()) - } -} diff --git a/vendor/github.com/joyent/triton-go/examples/storage/getobject.go b/vendor/github.com/joyent/triton-go/examples/storage/getobject.go deleted file mode 100644 index d892dac..0000000 --- a/vendor/github.com/joyent/triton-go/examples/storage/getobject.go +++ /dev/null @@ -1,90 +0,0 @@ -package main - -import ( - "context" - "fmt" - "io/ioutil" - "log" - "os" - - "encoding/pem" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/storage" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - MantaURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - client, err := storage.NewClient(config) - if err != nil { - log.Fatalf("NewClient: %s", err) - } - - obj, err := client.Objects().Get(context.Background(), &storage.GetObjectInput{ - ObjectPath: "/stor/books/dracula.txt", - }) - if err != nil { - log.Fatalf("compute.Objects.Get: %s", err) - } - - body, err := ioutil.ReadAll(obj.ObjectReader) - if err != nil { - log.Fatalf("compute.Objects.Get: %s", err) - } - defer obj.ObjectReader.Close() - - fmt.Printf("Content-Length: %d\n", obj.ContentLength) - fmt.Printf("Content-MD5: %s\n", obj.ContentMD5) - fmt.Printf("Content-Type: %s\n", obj.ContentType) - fmt.Printf("ETag: %s\n", obj.ETag) - fmt.Printf("Date-Modified: %s\n", obj.LastModified.String()) - fmt.Printf("Length: %d\n", len(body)) -} diff --git a/vendor/github.com/joyent/triton-go/examples/storage/mls.go b/vendor/github.com/joyent/triton-go/examples/storage/mls.go deleted file mode 100644 index 02cfe88..0000000 --- a/vendor/github.com/joyent/triton-go/examples/storage/mls.go +++ /dev/null @@ -1,79 +0,0 @@ -package main - -import ( - "context" - "io/ioutil" - "log" - "os" - - "encoding/pem" - - "github.com/davecgh/go-spew/spew" - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/storage" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - MantaURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - client, err := storage.NewClient(config) - if err != nil { - log.Fatalf("NewClient: %s", err) - } - - ctx := context.Background() - input := &storage.ListDirectoryInput{} - output, err := client.Dir().List(ctx, input) - if err != nil { - log.Fatalf("storage.Dir.List: %s", err) - } - - spew.Dump(output) -} diff --git a/vendor/github.com/joyent/triton-go/examples/storage/putobject.go b/vendor/github.com/joyent/triton-go/examples/storage/putobject.go deleted file mode 100644 index 4ada47b..0000000 --- a/vendor/github.com/joyent/triton-go/examples/storage/putobject.go +++ /dev/null @@ -1,85 +0,0 @@ -package main - -import ( - "context" - "fmt" - "io/ioutil" - "log" - "os" - - "encoding/pem" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/storage" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - MantaURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - client, err := storage.NewClient(config) - if err != nil { - log.Fatalf("NewClient: %s", err) - } - - reader, err := os.Open("/tmp/foo.txt") - if err != nil { - log.Fatalf("os.Open: %s", err) - } - defer reader.Close() - - err = client.Objects().Put(context.Background(), &storage.PutObjectInput{ - ObjectPath: "/stor/foo.txt", - ObjectReader: reader, - }) - if err != nil { - log.Fatalf("storage.Objects.Put: %s", err) - } - fmt.Println("Successfully uploaded /tmp/foo.txt!") -} diff --git a/vendor/github.com/joyent/triton-go/examples/storage/signUrl.go b/vendor/github.com/joyent/triton-go/examples/storage/signUrl.go deleted file mode 100644 index efd863e..0000000 --- a/vendor/github.com/joyent/triton-go/examples/storage/signUrl.go +++ /dev/null @@ -1,82 +0,0 @@ -package main - -import ( - "encoding/pem" - "io/ioutil" - "log" - "os" - - "net/http" - "time" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/storage" -) - -func main() { - keyID := os.Getenv("SDC_KEY_ID") - accountName := os.Getenv("SDC_ACCOUNT") - keyMaterial := os.Getenv("SDC_KEY_MATERIAL") - - var signer authentication.Signer - var err error - - if keyMaterial == "" { - signer, err = authentication.NewSSHAgentSigner(keyID, accountName) - if err != nil { - log.Fatalf("Error Creating SSH Agent Signer: %s", err.Error()) - } - } else { - var keyBytes []byte - if _, err = os.Stat(keyMaterial); err == nil { - keyBytes, err = ioutil.ReadFile(keyMaterial) - if err != nil { - log.Fatalf("Error reading key material from %s: %s", - keyMaterial, err) - } - block, _ := pem.Decode(keyBytes) - if block == nil { - log.Fatalf( - "Failed to read key material '%s': no key found", keyMaterial) - } - - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - log.Fatalf( - "Failed to read key '%s': password protected keys are\n"+ - "not currently supported. Please decrypt the key prior to use.", keyMaterial) - } - - } else { - keyBytes = []byte(keyMaterial) - } - - signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName) - if err != nil { - log.Fatalf("Error Creating SSH Private Key Signer: %s", err.Error()) - } - } - - config := &triton.ClientConfig{ - MantaURL: os.Getenv("SDC_URL"), - AccountName: accountName, - Signers: []authentication.Signer{signer}, - } - - client, err := storage.NewClient(config) - if err != nil { - log.Fatalf("NewClient: %s", err) - } - - input := &storage.SignURLInput{ - ObjectPath: "/stor/books/treasure_island.txt", - Method: http.MethodGet, - ValidityPeriod: 5 * time.Minute, - } - signed, err := client.SignURL(input) - if err != nil { - log.Fatalf("SignURL: %s", err) - } - - log.Printf("Signed URL: %s", signed.SignedURL("http")) -} diff --git a/vendor/github.com/joyent/triton-go/identity/client.go b/vendor/github.com/joyent/triton-go/identity/client.go deleted file mode 100644 index 846d533..0000000 --- a/vendor/github.com/joyent/triton-go/identity/client.go +++ /dev/null @@ -1,33 +0,0 @@ -package identity - -import ( - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/client" -) - -type IdentityClient struct { - Client *client.Client -} - -func newIdentityClient(client *client.Client) *IdentityClient { - return &IdentityClient{ - Client: client, - } -} - -// NewClient returns a new client for working with Identity endpoints and -// resources within CloudAPI -func NewClient(config *triton.ClientConfig) (*IdentityClient, error) { - // TODO: Utilize config interface within the function itself - client, err := client.New(config.TritonURL, config.MantaURL, config.AccountName, config.Signers...) - if err != nil { - return nil, err - } - return newIdentityClient(client), nil -} - -// Roles returns a Compute client used for accessing functions pertaining to -// Role functionality in the Triton API. -func (c *IdentityClient) Roles() *RolesClient { - return &RolesClient{c.Client} -} diff --git a/vendor/github.com/joyent/triton-go/identity/roles.go b/vendor/github.com/joyent/triton-go/identity/roles.go deleted file mode 100644 index b7be5d4..0000000 --- a/vendor/github.com/joyent/triton-go/identity/roles.go +++ /dev/null @@ -1,181 +0,0 @@ -package identity - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type RolesClient struct { - client *client.Client -} - -type Role struct { - ID string `json:"id"` - Name string `json:"name"` - Policies []string `json:"policies"` - Members []string `json:"members"` - DefaultMembers []string `json:"default_members"` -} - -type ListRolesInput struct{} - -func (c *RolesClient) List(ctx context.Context, _ *ListRolesInput) ([]*Role, error) { - path := fmt.Sprintf("/%s/roles", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListRoles request: {{err}}", err) - } - - var result []*Role - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListRoles response: {{err}}", err) - } - - return result, nil -} - -type GetRoleInput struct { - RoleID string -} - -func (c *RolesClient) Get(ctx context.Context, input *GetRoleInput) (*Role, error) { - path := fmt.Sprintf("/%s/roles/%s", c.client.AccountName, input.RoleID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetRole request: {{err}}", err) - } - - var result *Role - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding GetRole response: {{err}}", err) - } - - return result, nil -} - -// CreateRoleInput represents the options that can be specified -// when creating a new role. -type CreateRoleInput struct { - // Name of the role. Required. - Name string `json:"name"` - - // This account's policies to be given to this role. Optional. - Policies []string `json:"policies,omitempty"` - - // This account's user logins to be added to this role. Optional. - Members []string `json:"members,omitempty"` - - // This account's user logins to be added to this role and have - // it enabled by default. Optional. - DefaultMembers []string `json:"default_members,omitempty"` -} - -func (c *RolesClient) Create(ctx context.Context, input *CreateRoleInput) (*Role, error) { - path := fmt.Sprintf("/%s/roles", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing CreateRole request: {{err}}", err) - } - - var result *Role - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding CreateRole response: {{err}}", err) - } - - return result, nil -} - -// UpdateRoleInput represents the options that can be specified -// when updating a role. Anything but ID can be modified. -type UpdateRoleInput struct { - // ID of the role to modify. Required. - RoleID string `json:"id"` - - // Name of the role. Required. - Name string `json:"name"` - - // This account's policies to be given to this role. Optional. - Policies []string `json:"policies,omitempty"` - - // This account's user logins to be added to this role. Optional. - Members []string `json:"members,omitempty"` - - // This account's user logins to be added to this role and have - // it enabled by default. Optional. - DefaultMembers []string `json:"default_members,omitempty"` -} - -func (c *RolesClient) Update(ctx context.Context, input *UpdateRoleInput) (*Role, error) { - path := fmt.Sprintf("/%s/roles/%s", c.client.AccountName, input.RoleID) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing UpdateRole request: {{err}}", err) - } - - var result *Role - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding UpdateRole response: {{err}}", err) - } - - return result, nil -} - -type DeleteRoleInput struct { - RoleID string -} - -func (c *RolesClient) Delete(ctx context.Context, input *DeleteRoleInput) error { - path := fmt.Sprintf("/%s/roles/%s", c.client.AccountName, input.RoleID) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteRole request: {{err}}", err) - } - - return nil -} diff --git a/vendor/github.com/joyent/triton-go/network/client.go b/vendor/github.com/joyent/triton-go/network/client.go deleted file mode 100644 index dbc25a8..0000000 --- a/vendor/github.com/joyent/triton-go/network/client.go +++ /dev/null @@ -1,39 +0,0 @@ -package network - -import ( - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/client" -) - -type NetworkClient struct { - Client *client.Client -} - -func newNetworkClient(client *client.Client) *NetworkClient { - return &NetworkClient{ - Client: client, - } -} - -// NewClient returns a new client for working with Network endpoints and -// resources within CloudAPI -func NewClient(config *triton.ClientConfig) (*NetworkClient, error) { - // TODO: Utilize config interface within the function itself - client, err := client.New(config.TritonURL, config.MantaURL, config.AccountName, config.Signers...) - if err != nil { - return nil, err - } - return newNetworkClient(client), nil -} - -// Fabrics returns a FabricsClient used for accessing functions pertaining to -// Fabric functionality in the Triton API. -func (c *NetworkClient) Fabrics() *FabricsClient { - return &FabricsClient{c.Client} -} - -// Firewall returns a FirewallClient client used for accessing functions -// pertaining to firewall functionality in the Triton API. -func (c *NetworkClient) Firewall() *FirewallClient { - return &FirewallClient{c.Client} -} diff --git a/vendor/github.com/joyent/triton-go/network/fabrics.go b/vendor/github.com/joyent/triton-go/network/fabrics.go deleted file mode 100644 index 20f1d2f..0000000 --- a/vendor/github.com/joyent/triton-go/network/fabrics.go +++ /dev/null @@ -1,269 +0,0 @@ -package network - -import ( - "encoding/json" - "fmt" - "net/http" - - "context" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type FabricsClient struct { - client *client.Client -} - -type FabricVLAN struct { - Name string `json:"name"` - ID int `json:"vlan_id"` - Description string `json:"description"` -} - -type ListVLANsInput struct{} - -func (c *FabricsClient) ListVLANs(ctx context.Context, _ *ListVLANsInput) ([]*FabricVLAN, error) { - path := fmt.Sprintf("/%s/fabrics/default/vlans", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListVLANs request: {{err}}", err) - } - - var result []*FabricVLAN - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListVLANs response: {{err}}", err) - } - - return result, nil -} - -type CreateVLANInput struct { - Name string `json:"name"` - ID int `json:"vlan_id"` - Description string `json:"description,omitempty"` -} - -func (c *FabricsClient) CreateVLAN(ctx context.Context, input *CreateVLANInput) (*FabricVLAN, error) { - path := fmt.Sprintf("/%s/fabrics/default/vlans", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing CreateVLAN request: {{err}}", err) - } - - var result *FabricVLAN - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding CreateVLAN response: {{err}}", err) - } - - return result, nil -} - -type UpdateVLANInput struct { - ID int `json:"-"` - Name string `json:"name"` - Description string `json:"description"` -} - -func (c *FabricsClient) UpdateVLAN(ctx context.Context, input *UpdateVLANInput) (*FabricVLAN, error) { - path := fmt.Sprintf("/%s/fabrics/default/vlans/%d", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodPut, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing UpdateVLAN request: {{err}}", err) - } - - var result *FabricVLAN - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding UpdateVLAN response: {{err}}", err) - } - - return result, nil -} - -type GetVLANInput struct { - ID int `json:"-"` -} - -func (c *FabricsClient) GetVLAN(ctx context.Context, input *GetVLANInput) (*FabricVLAN, error) { - path := fmt.Sprintf("/%s/fabrics/default/vlans/%d", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetVLAN request: {{err}}", err) - } - - var result *FabricVLAN - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding GetVLAN response: {{err}}", err) - } - - return result, nil -} - -type DeleteVLANInput struct { - ID int `json:"-"` -} - -func (c *FabricsClient) DeleteVLAN(ctx context.Context, input *DeleteVLANInput) error { - path := fmt.Sprintf("/%s/fabrics/default/vlans/%d", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteVLAN request: {{err}}", err) - } - - return nil -} - -type ListFabricsInput struct { - FabricVLANID int `json:"-"` -} - -func (c *FabricsClient) List(ctx context.Context, input *ListFabricsInput) ([]*Network, error) { - path := fmt.Sprintf("/%s/fabrics/default/vlans/%d/networks", c.client.AccountName, input.FabricVLANID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListFabrics request: {{err}}", err) - } - - var result []*Network - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListFabrics response: {{err}}", err) - } - - return result, nil -} - -type CreateFabricInput struct { - FabricVLANID int `json:"-"` - Name string `json:"name"` - Description string `json:"description,omitempty"` - Subnet string `json:"subnet"` - ProvisionStartIP string `json:"provision_start_ip"` - ProvisionEndIP string `json:"provision_end_ip"` - Gateway string `json:"gateway,omitempty"` - Resolvers []string `json:"resolvers,omitempty"` - Routes map[string]string `json:"routes,omitempty"` - InternetNAT bool `json:"internet_nat"` -} - -func (c *FabricsClient) Create(ctx context.Context, input *CreateFabricInput) (*Network, error) { - path := fmt.Sprintf("/%s/fabrics/default/vlans/%d/networks", c.client.AccountName, input.FabricVLANID) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing CreateFabric request: {{err}}", err) - } - - var result *Network - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding CreateFabric response: {{err}}", err) - } - - return result, nil -} - -type GetFabricInput struct { - FabricVLANID int `json:"-"` - NetworkID string `json:"-"` -} - -func (c *FabricsClient) Get(ctx context.Context, input *GetFabricInput) (*Network, error) { - path := fmt.Sprintf("/%s/fabrics/default/vlans/%d/networks/%s", c.client.AccountName, input.FabricVLANID, input.NetworkID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetFabric request: {{err}}", err) - } - - var result *Network - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding GetFabric response: {{err}}", err) - } - - return result, nil -} - -type DeleteFabricInput struct { - FabricVLANID int `json:"-"` - NetworkID string `json:"-"` -} - -func (c *FabricsClient) Delete(ctx context.Context, input *DeleteFabricInput) error { - path := fmt.Sprintf("/%s/fabrics/default/vlans/%d/networks/%s", c.client.AccountName, input.FabricVLANID, input.NetworkID) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteFabric request: {{err}}", err) - } - - return nil -} diff --git a/vendor/github.com/joyent/triton-go/network/firewall.go b/vendor/github.com/joyent/triton-go/network/firewall.go deleted file mode 100644 index 6005470..0000000 --- a/vendor/github.com/joyent/triton-go/network/firewall.go +++ /dev/null @@ -1,250 +0,0 @@ -package network - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type FirewallClient struct { - client *client.Client -} - -// FirewallRule represents a firewall rule -type FirewallRule struct { - // ID is a unique identifier for this rule - ID string `json:"id"` - - // Enabled indicates if the rule is enabled - Enabled bool `json:"enabled"` - - // Rule is the firewall rule text - Rule string `json:"rule"` - - // Global indicates if the rule is global. Optional. - Global bool `json:"global"` - - // Description is a human-readable description for the rule. Optional - Description string `json:"description"` -} - -type ListRulesInput struct{} - -func (c *FirewallClient) ListRules(ctx context.Context, _ *ListRulesInput) ([]*FirewallRule, error) { - path := fmt.Sprintf("/%s/fwrules", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListRules request: {{err}}", err) - } - - var result []*FirewallRule - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListRules response: {{err}}", err) - } - - return result, nil -} - -type GetRuleInput struct { - ID string -} - -func (c *FirewallClient) GetRule(ctx context.Context, input *GetRuleInput) (*FirewallRule, error) { - path := fmt.Sprintf("/%s/fwrules/%s", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetRule request: {{err}}", err) - } - - var result *FirewallRule - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding GetRule response: {{err}}", err) - } - - return result, nil -} - -type CreateRuleInput struct { - Enabled bool `json:"enabled"` - Rule string `json:"rule"` - Description string `json:"description,omitempty"` -} - -func (c *FirewallClient) CreateRule(ctx context.Context, input *CreateRuleInput) (*FirewallRule, error) { - path := fmt.Sprintf("/%s/fwrules", c.client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing CreateRule request: {{err}}", err) - } - - var result *FirewallRule - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding CreateRule response: {{err}}", err) - } - - return result, nil -} - -type UpdateRuleInput struct { - ID string `json:"-"` - Enabled bool `json:"enabled"` - Rule string `json:"rule"` - Description string `json:"description,omitempty"` -} - -func (c *FirewallClient) UpdateRule(ctx context.Context, input *UpdateRuleInput) (*FirewallRule, error) { - path := fmt.Sprintf("/%s/fwrules/%s", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing UpdateRule request: {{err}}", err) - } - - var result *FirewallRule - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding UpdateRule response: {{err}}", err) - } - - return result, nil -} - -type EnableRuleInput struct { - ID string `json:"-"` -} - -func (c *FirewallClient) EnableRule(ctx context.Context, input *EnableRuleInput) (*FirewallRule, error) { - path := fmt.Sprintf("/%s/fwrules/%s/enable", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing EnableRule request: {{err}}", err) - } - - var result *FirewallRule - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding EnableRule response: {{err}}", err) - } - - return result, nil -} - -type DisableRuleInput struct { - ID string `json:"-"` -} - -func (c *FirewallClient) DisableRule(ctx context.Context, input *DisableRuleInput) (*FirewallRule, error) { - path := fmt.Sprintf("/%s/fwrules/%s/disable", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing DisableRule request: {{err}}", err) - } - - var result *FirewallRule - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding DisableRule response: {{err}}", err) - } - - return result, nil -} - -type DeleteRuleInput struct { - ID string -} - -func (c *FirewallClient) DeleteRule(ctx context.Context, input *DeleteRuleInput) error { - path := fmt.Sprintf("/%s/fwrules/%s", c.client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteRule request: {{err}}", err) - } - - return nil -} - -type ListMachineRulesInput struct { - MachineID string -} - -func (c *FirewallClient) ListMachineRules(ctx context.Context, input *ListMachineRulesInput) ([]*FirewallRule, error) { - path := fmt.Sprintf("/%s/machines/%s/firewallrules", c.client.AccountName, input.MachineID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListMachineRules request: {{err}}", err) - } - - var result []*FirewallRule - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListRules response: {{err}}", err) - } - - return result, nil -} diff --git a/vendor/github.com/joyent/triton-go/network/network.go b/vendor/github.com/joyent/triton-go/network/network.go deleted file mode 100644 index d853e04..0000000 --- a/vendor/github.com/joyent/triton-go/network/network.go +++ /dev/null @@ -1,78 +0,0 @@ -package network - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type Network struct { - Id string `json:"id"` - Name string `json:"name"` - Public bool `json:"public"` - Fabric bool `json:"fabric"` - Description string `json:"description"` - Subnet string `json:"subnet"` - ProvisioningStartIP string `json:"provision_start_ip"` - ProvisioningEndIP string `json:"provision_end_ip"` - Gateway string `json:"gateway"` - Resolvers []string `json:"resolvers"` - Routes map[string]string `json:"routes"` - InternetNAT bool `json:"internet_nat"` -} - -type ListInput struct{} - -func (c *NetworkClient) List(ctx context.Context, _ *ListInput) ([]*Network, error) { - path := fmt.Sprintf("/%s/networks", c.Client.AccountName) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.Client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListNetworks request: {{err}}", err) - } - - var result []*Network - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding ListNetworks response: {{err}}", err) - } - - return result, nil -} - -type GetInput struct { - ID string -} - -func (c *NetworkClient) Get(ctx context.Context, input *GetInput) (*Network, error) { - path := fmt.Sprintf("/%s/networks/%s", c.Client.AccountName, input.ID) - reqInputs := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respReader, err := c.Client.ExecuteRequest(ctx, reqInputs) - if respReader != nil { - defer respReader.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetNetwork request: {{err}}", err) - } - - var result *Network - decoder := json.NewDecoder(respReader) - if err = decoder.Decode(&result); err != nil { - return nil, errwrap.Wrapf("Error decoding GetNetwork response: {{err}}", err) - } - - return result, nil -} diff --git a/vendor/github.com/joyent/triton-go/network/networks_test.go b/vendor/github.com/joyent/triton-go/network/networks_test.go deleted file mode 100644 index 94f5b43..0000000 --- a/vendor/github.com/joyent/triton-go/network/networks_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package network - -import ( - "context" - "fmt" - "testing" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/testutils" -) - -// Note that this is specific to Joyent Public Cloud and will not pass on -// private installations of Triton. -func TestAccNetworks_List(t *testing.T) { - testutils.AccTest(t, testutils.TestCase{ - Steps: []testutils.Step{ - - &testutils.StepClient{ - StateBagKey: "datacenter", - CallFunc: func(config *triton.ClientConfig) (interface{}, error) { - return NewClient(config) - }, - }, - - &testutils.StepAPICall{ - StateBagKey: "networks", - CallFunc: func(client interface{}) (interface{}, error) { - ctx := context.Background() - input := &ListInput{} - if c, ok := client.(*NetworkClient); ok { - return c.List(ctx, input) - } - return nil, fmt.Errorf("Bad client initialization") - }, - }, - - &testutils.StepAssertFunc{ - AssertFunc: func(state testutils.TritonStateBag) error { - dcs, ok := state.GetOk("networks") - if !ok { - return fmt.Errorf("State key %q not found", "networks") - } - - toFind := []string{"Joyent-SDC-Private", "Joyent-SDC-Public"} - for _, dcName := range toFind { - found := false - for _, dc := range dcs.([]*Network) { - if dc.Name == dcName { - found = true - if dc.Id == "" { - return fmt.Errorf("%q has no ID", dc.Name) - } - } - } - if !found { - return fmt.Errorf("Did not find Network %q", dcName) - } - } - - return nil - }, - }, - }, - }) -} diff --git a/vendor/github.com/joyent/triton-go/scripts/errcheck.sh b/vendor/github.com/joyent/triton-go/scripts/errcheck.sh deleted file mode 100755 index acc1ac4..0000000 --- a/vendor/github.com/joyent/triton-go/scripts/errcheck.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -# Check gofmt -echo "==> Checking for unchecked errors" -err_files=$(errcheck -ignoretests \ - -ignore 'bytes:.*' \ - -ignore 'io:Close|Write' \ - $(go list ./...| grep -Ev 'vendor|examples|testutils')) - -if [[ -n ${err_files} ]]; then - echo 'Unchecked errors found in the following places:' - echo "${err_files}" - echo "Please handle returned errors. You can check directly with \`make errcheck\`" - exit 1 -fi - -exit 0 diff --git a/vendor/github.com/joyent/triton-go/scripts/gofmtcheck.sh b/vendor/github.com/joyent/triton-go/scripts/gofmtcheck.sh deleted file mode 100755 index cf9c111..0000000 --- a/vendor/github.com/joyent/triton-go/scripts/gofmtcheck.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -# Check gofmt -echo "==> Checking that code complies with gofmt requirements" -gofmt_files=$(gofmt -l `find . -name '*.go' | grep -Ev 'vendor|examples'`) -if [[ -n ${gofmt_files} ]]; then - echo 'gofmt needs running on the following files:' - echo "${gofmt_files}" - echo "You can use the command: \`make fmt\` to reformat code." - exit 1 -fi - -exit 0 diff --git a/vendor/github.com/joyent/triton-go/scripts/lint.sh b/vendor/github.com/joyent/triton-go/scripts/lint.sh deleted file mode 100644 index 05561b0..0000000 --- a/vendor/github.com/joyent/triton-go/scripts/lint.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -result=0 -for pkg in $(go list ./...| grep -Ev 'vendor|examples|testutils') -do - golint -set_exit_status "$pkg" || result=1 - go vet "$pkg" || result=1 -done -exit $result diff --git a/vendor/github.com/joyent/triton-go/storage/client.go b/vendor/github.com/joyent/triton-go/storage/client.go deleted file mode 100644 index 36e87e6..0000000 --- a/vendor/github.com/joyent/triton-go/storage/client.go +++ /dev/null @@ -1,51 +0,0 @@ -package storage - -import ( - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/client" -) - -type StorageClient struct { - Client *client.Client -} - -func newStorageClient(client *client.Client) *StorageClient { - return &StorageClient{ - Client: client, - } -} - -// NewClient returns a new client for working with Storage endpoints and -// resources within CloudAPI -func NewClient(config *triton.ClientConfig) (*StorageClient, error) { - // TODO: Utilize config interface within the function itself - client, err := client.New(config.TritonURL, config.MantaURL, config.AccountName, config.Signers...) - if err != nil { - return nil, err - } - return newStorageClient(client), nil -} - -// Dir returns a DirectoryClient used for accessing functions pertaining to -// Directories functionality of the Manta API. -func (c *StorageClient) Dir() *DirectoryClient { - return &DirectoryClient{c.Client} -} - -// Jobs returns a JobClient used for accessing functions pertaining to Jobs -// functionality of the Triton Object Storage API. -func (c *StorageClient) Jobs() *JobClient { - return &JobClient{c.Client} -} - -// Objects returns an ObjectsClient used for accessing functions pertaining to -// Objects functionality of the Triton Object Storage API. -func (c *StorageClient) Objects() *ObjectsClient { - return &ObjectsClient{c.Client} -} - -// SnapLinks returns an SnapLinksClient used for accessing functions pertaining to -// SnapLinks functionality of the Triton Object Storage API. -func (c *StorageClient) SnapLinks() *SnapLinksClient { - return &SnapLinksClient{c.Client} -} diff --git a/vendor/github.com/joyent/triton-go/storage/directory.go b/vendor/github.com/joyent/triton-go/storage/directory.go deleted file mode 100644 index dd93d5f..0000000 --- a/vendor/github.com/joyent/triton-go/storage/directory.go +++ /dev/null @@ -1,144 +0,0 @@ -package storage - -import ( - "context" - "encoding/json" - "fmt" - "io" - "net/http" - "net/url" - "strconv" - "time" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type DirectoryClient struct { - client *client.Client -} - -// DirectoryEntry represents an object or directory in Manta. -type DirectoryEntry struct { - ETag string `json:"etag"` - ModifiedTime time.Time `json:"mtime"` - Name string `json:"name"` - Size uint64 `json:"size"` - Type string `json:"type"` -} - -// ListDirectoryInput represents parameters to a ListDirectory operation. -type ListDirectoryInput struct { - DirectoryName string - Limit uint64 - Marker string -} - -// ListDirectoryOutput contains the outputs of a ListDirectory operation. -type ListDirectoryOutput struct { - Entries []*DirectoryEntry - ResultSetSize uint64 -} - -// List lists the contents of a directory on the Triton Object Store service. -func (s *DirectoryClient) List(ctx context.Context, input *ListDirectoryInput) (*ListDirectoryOutput, error) { - path := fmt.Sprintf("/%s%s", s.client.AccountName, input.DirectoryName) - query := &url.Values{} - if input.Limit != 0 { - query.Set("limit", strconv.FormatUint(input.Limit, 10)) - } - if input.Marker != "" { - query.Set("manta_path", input.Marker) - } - - reqInput := client.RequestInput{ - Method: http.MethodGet, - Path: path, - Query: query, - } - respBody, respHeader, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListDirectory request: {{err}}", err) - } - - var results []*DirectoryEntry - for { - current := &DirectoryEntry{} - decoder := json.NewDecoder(respBody) - if err = decoder.Decode(¤t); err != nil { - if err == io.EOF { - break - } - return nil, errwrap.Wrapf("Error decoding ListDirectory response: {{err}}", err) - } - results = append(results, current) - } - - output := &ListDirectoryOutput{ - Entries: results, - } - - resultSetSize, err := strconv.ParseUint(respHeader.Get("Result-Set-Size"), 10, 64) - if err == nil { - output.ResultSetSize = resultSetSize - } - - return output, nil -} - -// PutDirectoryInput represents parameters to a PutDirectory operation. -type PutDirectoryInput struct { - DirectoryName string -} - -// Put puts a directoy into the Triton Object Storage service is an idempotent -// create-or-update operation. Your private namespace starts at /:login, and you -// can create any nested set of directories or objects within it. -func (s *DirectoryClient) Put(ctx context.Context, input *PutDirectoryInput) error { - path := fmt.Sprintf("/%s%s", s.client.AccountName, input.DirectoryName) - headers := &http.Header{} - headers.Set("Content-Type", "application/json; type=directory") - - reqInput := client.RequestInput{ - Method: http.MethodPut, - Path: path, - Headers: headers, - } - respBody, _, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing PutDirectory request: {{err}}", err) - } - - return nil -} - -// DeleteDirectoryInput represents parameters to a DeleteDirectory operation. -type DeleteDirectoryInput struct { - DirectoryName string -} - -// Delete deletes a directory on the Triton Object Storage. The directory must -// be empty. -func (s *DirectoryClient) Delete(ctx context.Context, input *DeleteDirectoryInput) error { - path := fmt.Sprintf("/%s%s", s.client.AccountName, input.DirectoryName) - - reqInput := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - respBody, _, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteDirectory request: {{err}}", err) - } - - return nil -} diff --git a/vendor/github.com/joyent/triton-go/storage/job.go b/vendor/github.com/joyent/triton-go/storage/job.go deleted file mode 100644 index c7be80c..0000000 --- a/vendor/github.com/joyent/triton-go/storage/job.go +++ /dev/null @@ -1,440 +0,0 @@ -package storage - -import ( - "context" - "encoding/json" - "fmt" - "io" - "net/http" - "net/url" - "strconv" - "strings" - "time" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type JobClient struct { - client *client.Client -} - -const ( - JobStateDone = "done" - JobStateRunning = "running" -) - -// JobPhase represents the specification for a map or reduce phase of a Manta -// job. -type JobPhase struct { - // Type is the type of phase. Must be `map` or `reduce`. - Type string `json:"type,omitempty"` - - // Assets is an array of objects to be placed in your compute zones. - Assets []string `json:"assets,omitempty"` - - // Exec is the shell statement to execute. It may be any valid shell - // command, including pipelines and other shell syntax. You can also - // execute programs stored in the service by including them in "assets" - // and referencing them as /assets/$manta_path. - Exec string `json:"exec"` - - // Init is a shell statement to execute in each compute zone before - // any tasks are executed. The same constraints apply as to Exec. - Init string `json:"init"` - - // ReducerCount is an optional number of reducers for this phase. The - // default value if not specified is 1. The maximum value is 1024. - ReducerCount uint `json:"count,omitempty"` - - // Memory is the amount of DRAM in MB to be allocated to the compute - // zone. Valid values are 256, 512, 1024, 2048, 4096 or 8192. - Memory uint64 `json:"memory,omitempty"` - - // Disk is the amount of disk space in GB to be allocated to the compute - // zone. Valid values are 2, 4, 8, 16, 32, 64, 128, 256, 512 or 1024. - Disk uint64 `json:"disk,omitempty"` -} - -// JobSummary represents the summary of a compute job in Manta. -type JobSummary struct { - ModifiedTime time.Time `json:"mtime"` - ID string `json:"name"` -} - -// Job represents a compute job in Manta. -type Job struct { - ID string `json:"id"` - Name string `json:"name"` - Phases []*JobPhase `json:"phases"` - State string `json:"state"` - Cancelled bool `json:"cancelled"` - InputDone bool `json:"inputDone"` - CreatedTime time.Time `json:"timeCreated"` - DoneTime time.Time `json:"timeDone"` - Transient bool `json:"transient"` - Stats *JobStats `json:"stats"` -} - -// JobStats represents statistics for a compute job in Manta. -type JobStats struct { - Errors uint64 `json:"errors"` - Outputs uint64 `json:"outputs"` - Retries uint64 `json:"retries"` - Tasks uint64 `json:"tasks"` - TasksDone uint64 `json:"tasksDone"` -} - -// CreateJobInput represents parameters to a CreateJob operation. -type CreateJobInput struct { - Name string `json:"name"` - Phases []*JobPhase `json:"phases"` -} - -// CreateJobOutput contains the outputs of a CreateJob operation. -type CreateJobOutput struct { - JobID string -} - -// CreateJob submits a new job to be executed. This call is not -// idempotent, so calling it twice will create two jobs. -func (s *JobClient) Create(ctx context.Context, input *CreateJobInput) (*CreateJobOutput, error) { - path := fmt.Sprintf("/%s/jobs", s.client.AccountName) - - reqInput := client.RequestInput{ - Method: http.MethodPost, - Path: path, - Body: input, - } - respBody, respHeaders, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing CreateJob request: {{err}}", err) - } - - jobURI := respHeaders.Get("Location") - parts := strings.Split(jobURI, "/") - jobID := parts[len(parts)-1] - - response := &CreateJobOutput{ - JobID: jobID, - } - - return response, nil -} - -// AddJobInputs represents parameters to a AddJobInputs operation. -type AddJobInputsInput struct { - JobID string - ObjectPaths []string -} - -// AddJobInputs submits inputs to an already created job. -func (s *JobClient) AddInputs(ctx context.Context, input *AddJobInputsInput) error { - path := fmt.Sprintf("/%s/jobs/%s/live/in", s.client.AccountName, input.JobID) - headers := &http.Header{} - headers.Set("Content-Type", "text/plain") - - reader := strings.NewReader(strings.Join(input.ObjectPaths, "\n")) - - reqInput := client.RequestNoEncodeInput{ - Method: http.MethodPost, - Path: path, - Headers: headers, - Body: reader, - } - respBody, _, err := s.client.ExecuteRequestNoEncode(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing AddJobInputs request: {{err}}", err) - } - - return nil -} - -// EndJobInputInput represents parameters to a EndJobInput operation. -type EndJobInputInput struct { - JobID string -} - -// EndJobInput submits inputs to an already created job. -func (s *JobClient) EndInput(ctx context.Context, input *EndJobInputInput) error { - path := fmt.Sprintf("/%s/jobs/%s/live/in/end", s.client.AccountName, input.JobID) - - reqInput := client.RequestNoEncodeInput{ - Method: http.MethodPost, - Path: path, - } - respBody, _, err := s.client.ExecuteRequestNoEncode(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing EndJobInput request: {{err}}", err) - } - - return nil -} - -// CancelJobInput represents parameters to a CancelJob operation. -type CancelJobInput struct { - JobID string -} - -// CancelJob cancels a job from doing any further work. Cancellation -// is asynchronous and "best effort"; there is no guarantee the job -// will actually stop. For example, short jobs where input is already -// closed will likely still run to completion. -// -// This is however useful when: -// - input is still open -// - you have a long-running job -func (s *JobClient) Cancel(ctx context.Context, input *CancelJobInput) error { - path := fmt.Sprintf("/%s/jobs/%s/live/cancel", s.client.AccountName, input.JobID) - - reqInput := client.RequestNoEncodeInput{ - Method: http.MethodPost, - Path: path, - } - respBody, _, err := s.client.ExecuteRequestNoEncode(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing CancelJob request: {{err}}", err) - } - - return nil -} - -// ListJobsInput represents parameters to a ListJobs operation. -type ListJobsInput struct { - RunningOnly bool - Limit uint64 - Marker string -} - -// ListJobsOutput contains the outputs of a ListJobs operation. -type ListJobsOutput struct { - Jobs []*JobSummary - ResultSetSize uint64 -} - -// ListJobs returns the list of jobs you currently have. -func (s *JobClient) List(ctx context.Context, input *ListJobsInput) (*ListJobsOutput, error) { - path := fmt.Sprintf("/%s/jobs", s.client.AccountName) - query := &url.Values{} - if input.RunningOnly { - query.Set("state", "running") - } - if input.Limit != 0 { - query.Set("limit", strconv.FormatUint(input.Limit, 10)) - } - if input.Marker != "" { - query.Set("manta_path", input.Marker) - } - - reqInput := client.RequestInput{ - Method: http.MethodGet, - Path: path, - Query: query, - } - respBody, respHeader, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing ListJobs request: {{err}}", err) - } - - var results []*JobSummary - for { - current := &JobSummary{} - decoder := json.NewDecoder(respBody) - if err = decoder.Decode(¤t); err != nil { - if err == io.EOF { - break - } - return nil, errwrap.Wrapf("Error decoding ListJobs response: {{err}}", err) - } - results = append(results, current) - } - - output := &ListJobsOutput{ - Jobs: results, - } - - resultSetSize, err := strconv.ParseUint(respHeader.Get("Result-Set-Size"), 10, 64) - if err == nil { - output.ResultSetSize = resultSetSize - } - - return output, nil -} - -// GetJobInput represents parameters to a GetJob operation. -type GetJobInput struct { - JobID string -} - -// GetJobOutput contains the outputs of a GetJob operation. -type GetJobOutput struct { - Job *Job -} - -// GetJob returns the list of jobs you currently have. -func (s *JobClient) Get(ctx context.Context, input *GetJobInput) (*GetJobOutput, error) { - path := fmt.Sprintf("/%s/jobs/%s/live/status", s.client.AccountName, input.JobID) - - reqInput := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respBody, _, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetJob request: {{err}}", err) - } - - job := &Job{} - decoder := json.NewDecoder(respBody) - if err = decoder.Decode(&job); err != nil { - return nil, errwrap.Wrapf("Error decoding GetJob response: {{err}}", err) - } - - return &GetJobOutput{ - Job: job, - }, nil -} - -// GetJobOutputInput represents parameters to a GetJobOutput operation. -type GetJobOutputInput struct { - JobID string -} - -// GetJobOutputOutput contains the outputs for a GetJobOutput operation. It is your -// responsibility to ensure that the io.ReadCloser Items is closed. -type GetJobOutputOutput struct { - ResultSetSize uint64 - Items io.ReadCloser -} - -// GetJobOutput returns the current "live" set of outputs from a job. Think of -// this like `tail -f`. If error is nil (i.e. the operation is successful), it is -// your responsibility to close the io.ReadCloser named Items in the output. -func (s *JobClient) GetOutput(ctx context.Context, input *GetJobOutputInput) (*GetJobOutputOutput, error) { - path := fmt.Sprintf("/%s/jobs/%s/live/out", s.client.AccountName, input.JobID) - - reqInput := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respBody, respHeader, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetJobOutput request: {{err}}", err) - } - - output := &GetJobOutputOutput{ - Items: respBody, - } - - resultSetSize, err := strconv.ParseUint(respHeader.Get("Result-Set-Size"), 10, 64) - if err == nil { - output.ResultSetSize = resultSetSize - } - - return output, nil -} - -// GetJobInputInput represents parameters to a GetJobOutput operation. -type GetJobInputInput struct { - JobID string -} - -// GetJobInputOutput contains the outputs for a GetJobOutput operation. It is your -// responsibility to ensure that the io.ReadCloser Items is closed. -type GetJobInputOutput struct { - ResultSetSize uint64 - Items io.ReadCloser -} - -// GetJobInput returns the current "live" set of inputs from a job. Think of -// this like `tail -f`. If error is nil (i.e. the operation is successful), it is -// your responsibility to close the io.ReadCloser named Items in the output. -func (s *JobClient) GetInput(ctx context.Context, input *GetJobInputInput) (*GetJobInputOutput, error) { - path := fmt.Sprintf("/%s/jobs/%s/live/in", s.client.AccountName, input.JobID) - - reqInput := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respBody, respHeader, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetJobInput request: {{err}}", err) - } - - output := &GetJobInputOutput{ - Items: respBody, - } - - resultSetSize, err := strconv.ParseUint(respHeader.Get("Result-Set-Size"), 10, 64) - if err == nil { - output.ResultSetSize = resultSetSize - } - - return output, nil -} - -// GetJobFailuresInput represents parameters to a GetJobFailures operation. -type GetJobFailuresInput struct { - JobID string -} - -// GetJobFailuresOutput contains the outputs for a GetJobFailures operation. It is your -// responsibility to ensure that the io.ReadCloser Items is closed. -type GetJobFailuresOutput struct { - ResultSetSize uint64 - Items io.ReadCloser -} - -// GetJobFailures returns the current "live" set of outputs from a job. Think of -// this like `tail -f`. If error is nil (i.e. the operation is successful), it is -// your responsibility to close the io.ReadCloser named Items in the output. -func (s *JobClient) GetFailures(ctx context.Context, input *GetJobFailuresInput) (*GetJobFailuresOutput, error) { - path := fmt.Sprintf("/%s/jobs/%s/live/fail", s.client.AccountName, input.JobID) - - reqInput := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respBody, respHeader, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return nil, errwrap.Wrapf("Error executing GetJobFailures request: {{err}}", err) - } - - output := &GetJobFailuresOutput{ - Items: respBody, - } - - resultSetSize, err := strconv.ParseUint(respHeader.Get("Result-Set-Size"), 10, 64) - if err == nil { - output.ResultSetSize = resultSetSize - } - - return output, nil -} diff --git a/vendor/github.com/joyent/triton-go/storage/objects.go b/vendor/github.com/joyent/triton-go/storage/objects.go deleted file mode 100644 index afdd5e9..0000000 --- a/vendor/github.com/joyent/triton-go/storage/objects.go +++ /dev/null @@ -1,208 +0,0 @@ -package storage - -import ( - "context" - "errors" - "fmt" - "io" - "net/http" - "net/url" - "strconv" - "strings" - "time" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type ObjectsClient struct { - client *client.Client -} - -// GetObjectInput represents parameters to a GetObject operation. -type GetObjectInput struct { - ObjectPath string -} - -// GetObjectOutput contains the outputs for a GetObject operation. It is your -// responsibility to ensure that the io.ReadCloser ObjectReader is closed. -type GetObjectOutput struct { - ContentLength uint64 - ContentType string - LastModified time.Time - ContentMD5 string - ETag string - Metadata map[string]string - ObjectReader io.ReadCloser -} - -// GetObject retrieves an object from the Manta service. If error is nil (i.e. -// the call returns successfully), it is your responsibility to close the io.ReadCloser -// named ObjectReader in the operation output. -func (s *ObjectsClient) Get(ctx context.Context, input *GetObjectInput) (*GetObjectOutput, error) { - path := fmt.Sprintf("/%s%s", s.client.AccountName, input.ObjectPath) - - reqInput := client.RequestInput{ - Method: http.MethodGet, - Path: path, - } - respBody, respHeaders, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if err != nil { - return nil, errwrap.Wrapf("Error executing GetDirectory request: {{err}}", err) - } - - response := &GetObjectOutput{ - ContentType: respHeaders.Get("Content-Type"), - ContentMD5: respHeaders.Get("Content-MD5"), - ETag: respHeaders.Get("Etag"), - ObjectReader: respBody, - } - - lastModified, err := time.Parse(time.RFC1123, respHeaders.Get("Last-Modified")) - if err == nil { - response.LastModified = lastModified - } - - contentLength, err := strconv.ParseUint(respHeaders.Get("Content-Length"), 10, 64) - if err == nil { - response.ContentLength = contentLength - } - - metadata := map[string]string{} - for key, values := range respHeaders { - if strings.HasPrefix(key, "m-") { - metadata[key] = strings.Join(values, ", ") - } - } - response.Metadata = metadata - - return response, nil -} - -// DeleteObjectInput represents parameters to a DeleteObject operation. -type DeleteObjectInput struct { - ObjectPath string -} - -// DeleteObject deletes an object. -func (s *ObjectsClient) Delete(ctx context.Context, input *DeleteObjectInput) error { - path := fmt.Sprintf("/%s%s", s.client.AccountName, input.ObjectPath) - - reqInput := client.RequestInput{ - Method: http.MethodDelete, - Path: path, - } - respBody, _, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing DeleteObject request: {{err}}", err) - } - - return nil -} - -// PutObjectMetadataInput represents parameters to a PutObjectMetadata operation. -type PutObjectMetadataInput struct { - ObjectPath string - ContentType string - Metadata map[string]string -} - -// PutObjectMetadata allows you to overwrite the HTTP headers for an already -// existing object, without changing the data. Note this is an idempotent "replace" -// operation, so you must specify the complete set of HTTP headers you want -// stored on each request. -// -// You cannot change "critical" headers: -// - Content-Length -// - Content-MD5 -// - Durability-Level -func (s *ObjectsClient) PutMetadata(ctx context.Context, input *PutObjectMetadataInput) error { - path := fmt.Sprintf("/%s%s", s.client.AccountName, input.ObjectPath) - query := &url.Values{} - query.Set("metadata", "true") - - headers := &http.Header{} - headers.Set("Content-Type", input.ContentType) - for key, value := range input.Metadata { - headers.Set(key, value) - } - - reqInput := client.RequestInput{ - Method: http.MethodPut, - Path: path, - Query: query, - Headers: headers, - } - respBody, _, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing PutObjectMetadata request: {{err}}", err) - } - - return nil -} - -// PutObjectInput represents parameters to a PutObject operation. -type PutObjectInput struct { - ObjectPath string - DurabilityLevel uint64 - ContentType string - ContentMD5 string - IfMatch string - IfModifiedSince *time.Time - ContentLength uint64 - MaxContentLength uint64 - ObjectReader io.ReadSeeker -} - -func (s *ObjectsClient) Put(ctx context.Context, input *PutObjectInput) error { - path := fmt.Sprintf("/%s%s", s.client.AccountName, input.ObjectPath) - - if input.MaxContentLength != 0 && input.ContentLength != 0 { - return errors.New("ContentLength and MaxContentLength may not both be set to non-zero values.") - } - - headers := &http.Header{} - if input.DurabilityLevel != 0 { - headers.Set("Durability-Level", strconv.FormatUint(input.DurabilityLevel, 10)) - } - if input.ContentType != "" { - headers.Set("Content-Type", input.ContentType) - } - if input.ContentMD5 != "" { - headers.Set("Content-MD$", input.ContentMD5) - } - if input.IfMatch != "" { - headers.Set("If-Match", input.IfMatch) - } - if input.IfModifiedSince != nil { - headers.Set("If-Modified-Since", input.IfModifiedSince.Format(time.RFC1123)) - } - if input.ContentLength != 0 { - headers.Set("Content-Length", strconv.FormatUint(input.ContentLength, 10)) - } - if input.MaxContentLength != 0 { - headers.Set("Max-Content-Length", strconv.FormatUint(input.MaxContentLength, 10)) - } - - reqInput := client.RequestNoEncodeInput{ - Method: http.MethodPut, - Path: path, - Headers: headers, - Body: input.ObjectReader, - } - respBody, _, err := s.client.ExecuteRequestNoEncode(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing PutObjectMetadata request: {{err}}", err) - } - - return nil -} diff --git a/vendor/github.com/joyent/triton-go/storage/signing.go b/vendor/github.com/joyent/triton-go/storage/signing.go deleted file mode 100644 index b88005c..0000000 --- a/vendor/github.com/joyent/triton-go/storage/signing.go +++ /dev/null @@ -1,81 +0,0 @@ -package storage - -import ( - "bytes" - "fmt" - "net/url" - "strconv" - "strings" - "time" - - "github.com/hashicorp/errwrap" -) - -// SignURLInput represents parameters to a SignURL operation. -type SignURLInput struct { - ValidityPeriod time.Duration - Method string - ObjectPath string -} - -// SignURLOutput contains the outputs of a SignURL operation. To simply -// access the signed URL, use the SignedURL method. -type SignURLOutput struct { - host string - objectPath string - Method string - Algorithm string - Signature string - Expires string - KeyID string -} - -// SignedURL returns a signed URL for the given scheme. Valid schemes are -// `http` and `https`. -func (output *SignURLOutput) SignedURL(scheme string) string { - query := &url.Values{} - query.Set("algorithm", output.Algorithm) - query.Set("expires", output.Expires) - query.Set("keyId", output.KeyID) - query.Set("signature", output.Signature) - - sUrl := url.URL{} - sUrl.Scheme = scheme - sUrl.Host = output.host - sUrl.Path = output.objectPath - sUrl.RawQuery = query.Encode() - - return sUrl.String() -} - -// SignURL creates a time-expiring URL that can be shared with others. -// This is useful to generate HTML links, for example. -func (s *StorageClient) SignURL(input *SignURLInput) (*SignURLOutput, error) { - output := &SignURLOutput{ - host: s.Client.MantaURL.Host, - objectPath: fmt.Sprintf("/%s%s", s.Client.AccountName, input.ObjectPath), - Method: input.Method, - Algorithm: strings.ToUpper(s.Client.Authorizers[0].DefaultAlgorithm()), - Expires: strconv.FormatInt(time.Now().Add(input.ValidityPeriod).Unix(), 10), - KeyID: fmt.Sprintf("/%s/keys/%s", s.Client.AccountName, s.Client.Authorizers[0].KeyFingerprint()), - } - - toSign := bytes.Buffer{} - toSign.WriteString(input.Method + "\n") - toSign.WriteString(s.Client.MantaURL.Host + "\n") - toSign.WriteString(fmt.Sprintf("/%s%s\n", s.Client.AccountName, input.ObjectPath)) - - query := &url.Values{} - query.Set("algorithm", output.Algorithm) - query.Set("expires", output.Expires) - query.Set("keyId", output.KeyID) - toSign.WriteString(query.Encode()) - - signature, _, err := s.Client.Authorizers[0].SignRaw(toSign.String()) - if err != nil { - return nil, errwrap.Wrapf("Error signing string: {{err}}", err) - } - - output.Signature = signature - return output, nil -} diff --git a/vendor/github.com/joyent/triton-go/storage/snaplink.go b/vendor/github.com/joyent/triton-go/storage/snaplink.go deleted file mode 100644 index 1330f0a..0000000 --- a/vendor/github.com/joyent/triton-go/storage/snaplink.go +++ /dev/null @@ -1,46 +0,0 @@ -package storage - -import ( - "context" - "fmt" - "net/http" - - "github.com/hashicorp/errwrap" - "github.com/joyent/triton-go/client" -) - -type SnapLinksClient struct { - client *client.Client -} - -// PutSnapLinkInput represents parameters to a PutSnapLink operation. -type PutSnapLinkInput struct { - LinkPath string - SourcePath string -} - -// PutSnapLink creates a SnapLink to an object. -func (s *SnapLinksClient) Put(ctx context.Context, input *PutSnapLinkInput) error { - linkPath := fmt.Sprintf("/%s%s", s.client.AccountName, input.LinkPath) - sourcePath := fmt.Sprintf("/%s%s", s.client.AccountName, input.SourcePath) - headers := &http.Header{} - headers.Set("Content-Type", "application/json; type=link") - headers.Set("location", sourcePath) - headers.Set("Accept", "~1.0") - headers.Set("Accept-Version", "application/json, */*") - - reqInput := client.RequestInput{ - Method: http.MethodPut, - Path: linkPath, - Headers: headers, - } - respBody, _, err := s.client.ExecuteRequestStorage(ctx, reqInput) - if respBody != nil { - defer respBody.Close() - } - if err != nil { - return errwrap.Wrapf("Error executing PutSnapLink request: {{err}}", err) - } - - return nil -} diff --git a/vendor/github.com/joyent/triton-go/testutils/basic_runner.go b/vendor/github.com/joyent/triton-go/testutils/basic_runner.go deleted file mode 100644 index 9d3a285..0000000 --- a/vendor/github.com/joyent/triton-go/testutils/basic_runner.go +++ /dev/null @@ -1,101 +0,0 @@ -package testutils - -import ( - "log" - "sync" - "sync/atomic" -) - -type runState int32 - -const ( - stateIdle runState = iota - stateRunning - stateCancelling -) - -type basicRunner struct { - Steps []Step - - cancelCh chan struct{} - doneCh chan struct{} - state runState - l sync.Mutex -} - -func (b *basicRunner) Run(state TritonStateBag) { - b.l.Lock() - if b.state != stateIdle { - panic("already running") - } - - cancelCh := make(chan struct{}) - doneCh := make(chan struct{}) - b.cancelCh = cancelCh - b.doneCh = doneCh - b.state = stateRunning - b.l.Unlock() - - defer func() { - b.l.Lock() - b.cancelCh = nil - b.doneCh = nil - b.state = stateIdle - close(doneCh) - b.l.Unlock() - }() - - // This goroutine listens for cancels and puts the StateCancelled key - // as quickly as possible into the state bag to mark it. - go func() { - select { - case <-cancelCh: - // Flag cancel and wait for finish - state.Put(StateCancelled, true) - <-doneCh - case <-doneCh: - } - }() - - for _, step := range b.Steps { - // We also check for cancellation here since we can't be sure - // the goroutine that is running to set it actually ran. - if runState(atomic.LoadInt32((*int32)(&b.state))) == stateCancelling { - state.Put(StateCancelled, true) - break - } - - action := step.Run(state) - defer step.Cleanup(state) - - if _, ok := state.GetOk(StateCancelled); ok { - break - } - - if action == Halt { - log.Println("[INFO] Halt requested by current step") - state.Put(StateHalted, true) - break - } - } -} - -func (b *basicRunner) Cancel() { - b.l.Lock() - switch b.state { - case stateIdle: - // Not running, so Cancel is... done. - b.l.Unlock() - return - case stateRunning: - // Running, so mark that we cancelled and set the state - close(b.cancelCh) - b.state = stateCancelling - fallthrough - case stateCancelling: - // Already cancelling, so just wait until we're done - ch := b.doneCh - b.l.Unlock() - <-ch - } -} diff --git a/vendor/github.com/joyent/triton-go/testutils/mock_http.go b/vendor/github.com/joyent/triton-go/testutils/mock_http.go deleted file mode 100644 index ffe1ef6..0000000 --- a/vendor/github.com/joyent/triton-go/testutils/mock_http.go +++ /dev/null @@ -1,111 +0,0 @@ -package testutils - -import ( - "errors" - "net/http" - - "github.com/joyent/triton-go/authentication" - "github.com/joyent/triton-go/client" -) - -// Responders are callbacks that receive http requests and return a mocked -// response. -type Responder func(*http.Request) (*http.Response, error) - -// NoResponderFound is returned when no responders are found for a given HTTP -// method and URL. -var NoResponderFound = errors.New("no responder found") - -// MockTransport implements http.RoundTripper, which fulfills single http -// requests issued by an http.Client. This implementation doesn't actually make -// the call, instead defering to the registered list of responders. -type MockTransport struct { - FailNoResponder bool - responders map[string]Responder -} - -// RoundTrip is required to implement http.MockTransport. Instead of fulfilling -// the given request, the internal list of responders is consulted to handle the -// request. If no responder is found an error is returned, which is the -// equivalent of a network error. -func (m *MockTransport) RoundTrip(req *http.Request) (*http.Response, error) { - key := req.Method + " " + req.URL.String() - - // scan through the responders and find one that matches our key - for k, r := range m.responders { - if k != key { - continue - } - return r(req) - } - - // if we've been told to error when no match was found - if m.FailNoResponder { - return nil, NoResponderFound - } - - // fallback to the default roundtripper - return http.DefaultTransport.RoundTrip(req) -} - -// RegisterResponder adds a new responder, associated with a given HTTP method -// and URL. When a request comes in that matches, the responder will be called -// and the response returned to the client. -func (m *MockTransport) RegisterResponder(method, url string, responder Responder) { - m.responders[method+" "+url] = responder -} - -// Clear clears out all the mock responders that have been set on a particular -// MockTransport object. This comes in especially handy when utilizing the -// global DefaultMockTRansport and is utilized by the DeactivateClient func. -func (m *MockTransport) Clear() { - m.responders = make(map[string]Responder) -} - -// DefaultMockTransport allows users to easily and globally alter the default -// RoundTripper for all http requests. -var DefaultMockTransport = &MockTransport{ - responders: make(map[string]Responder), -} - -// Activate replaces the `Transport` on the `http.Client` with our -// `DefaultMockTransport`. -func ActivateClient(failNoResponder bool) { - DefaultMockTransport.FailNoResponder = failNoResponder - http.DefaultClient.Transport = DefaultMockTransport -} - -// Deactivate replaces our `DefaultMockTransport` with the -// `http.DefaultTransport`. -func DeactivateClient() { - DefaultMockTransport.Clear() - http.DefaultClient.Transport = http.DefaultTransport -} - -// RegisterResponder adds a responder to the `DefaultMockTransport` responder -// table. -func RegisterResponder(method, url string, responder Responder) { - DefaultMockTransport.RegisterResponder(method, url, responder) -} - -// DefaultMockClient uses NewMockClient to construct a mocked out client.Client -var DefaultMockClient = NewMockClient() - -// NewMockClient returns a new client.Client that includes our -// DefaultMockTransport which allows us to attach custom HTTP client request -// responders. -func NewMockClient() *client.Client { - testSigner, _ := authentication.NewTestSigner() - - httpClient := &http.Client{ - Transport: DefaultMockTransport, - CheckRedirect: func(_ *http.Request, _ []*http.Request) error { - return http.ErrUseLastResponse - }, - } - - return &client.Client{ - Authorizers: []authentication.Signer{testSigner}, - HTTPClient: httpClient, - } -} diff --git a/vendor/github.com/joyent/triton-go/testutils/random.go b/vendor/github.com/joyent/triton-go/testutils/random.go deleted file mode 100644 index dddf33a..0000000 --- a/vendor/github.com/joyent/triton-go/testutils/random.go +++ /dev/null @@ -1,44 +0,0 @@ -package testutils - -import ( - "fmt" - "math/rand" - - "github.com/sean-/seed" -) - -func init() { - seed.Init() -} - -// RandString generates a random alphanumeric string of the length specified -func RandString(strlen int) string { - return RandStringFromCharSet(strlen, CharSetAlphaNum) -} - -// RandPrefixString generates a random alphanumeric string of the length specified -// with the given prefix -func RandPrefixString(prefix string, strlen int) string { - requiredLength := strlen - len(prefix) - return fmt.Sprintf("%s%s", prefix, RandString(requiredLength)) -} - -// RandStringFromCharSet generates a random string by selecting characters from -// the charset provided -func RandStringFromCharSet(strlen int, charSet string) string { - result := make([]byte, strlen) - for i := 0; i < strlen; i++ { - result[i] = charSet[rand.Intn(len(charSet))] - } - return string(result) -} - -const ( - // CharSetAlphaNum is the alphanumeric character set for use with - // RandStringFromCharSet - CharSetAlphaNum = "abcdefghijklmnopqrstuvwxyz012346789" - - // CharSetAlpha is the alphabetical character set for use with - // RandStringFromCharSet - CharSetAlpha = "abcdefghijklmnopqrstuvwxyz" -) diff --git a/vendor/github.com/joyent/triton-go/testutils/runner.go b/vendor/github.com/joyent/triton-go/testutils/runner.go deleted file mode 100644 index 70d3428..0000000 --- a/vendor/github.com/joyent/triton-go/testutils/runner.go +++ /dev/null @@ -1,110 +0,0 @@ -package testutils - -import ( - "errors" - "fmt" - "log" - "os" - "testing" - - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/authentication" -) - -const TestEnvVar = "TRITON_TEST" - -type TestCase struct { - Steps []Step - State TritonStateBag -} - -func AccTest(t *testing.T, c TestCase) { - // We only run acceptance tests if an env var is set because they're - // slow and generally require some outside configuration. - if os.Getenv(TestEnvVar) == "" { - t.Skip(fmt.Sprintf( - "Acceptance tests skipped unless env '%s' set", - TestEnvVar)) - return - } - - // We require verbose mode so that the user knows what is going on. - if !testing.Verbose() { - t.Fatal("Acceptance tests must be run with the -v flag on tests") - return - } - - sdcURL := os.Getenv("SDC_URL") - sdcAccount := os.Getenv("SDC_ACCOUNT") - sdcKeyId := os.Getenv("SDC_KEY_ID") - sdcKeyMaterial := os.Getenv("SDC_KEY_MATERIAL") - mantaURL := os.Getenv("MANTA_URL") - - var prerollErrors []error - if sdcURL == "" { - prerollErrors = append(prerollErrors, - errors.New("The SDC_URL environment variable must be set to run acceptance tests")) - } - if sdcAccount == "" { - prerollErrors = append(prerollErrors, - errors.New("The SDC_ACCOUNT environment variable must be set to run acceptance tests")) - } - if sdcKeyId == "" { - prerollErrors = append(prerollErrors, - errors.New("The SDC_KEY_ID environment variable must be set to run acceptance tests")) - } - if len(prerollErrors) > 0 { - for _, err := range prerollErrors { - t.Error(err) - } - t.FailNow() - } - - var signer authentication.Signer - var err error - if sdcKeyMaterial != "" { - log.Println("[INFO] Creating Triton Client with Private Key Signer...") - signer, err = authentication.NewPrivateKeySigner(sdcKeyId, []byte(sdcKeyMaterial), sdcAccount) - if err != nil { - t.Fatalf("Error creating private key signer: %s", err) - } - } else { - log.Println("[INFO] Creating Triton Client with SSH Key Signer...") - signer, err = authentication.NewSSHAgentSigner(sdcKeyId, sdcAccount) - if err != nil { - t.Fatalf("Error creating SSH Agent signer: %s", err) - } - } - - // Old world... we spun up a universal client. This is pushed deeper into - // the process within `testutils.StepClient`. - // - // client, err := NewClient(sdcURL, sdcAccount, signer) - // if err != nil { - // t.Fatalf("Error creating Triton Client: %s", err) - // } - - config := &triton.ClientConfig{ - TritonURL: sdcURL, - MantaURL: mantaURL, - AccountName: sdcAccount, - Signers: []authentication.Signer{signer}, - } - - state := &basicTritonStateBag{ - TritonConfig: config, - } - - runner := &basicRunner{ - Steps: c.Steps, - } - - runner.Run(state) - - if errs := state.ErrorsOrNil(); errs != nil { - for _, err := range errs { - t.Error(err) - } - t.Fatal("\n\nThere may be dangling resources in your Triton account!") - } -} diff --git a/vendor/github.com/joyent/triton-go/testutils/statebag.go b/vendor/github.com/joyent/triton-go/testutils/statebag.go deleted file mode 100644 index 747b311..0000000 --- a/vendor/github.com/joyent/triton-go/testutils/statebag.go +++ /dev/null @@ -1,107 +0,0 @@ -package testutils - -import ( - "sync" - - triton "github.com/joyent/triton-go" -) - -type TritonStateBag interface { - Get(string) interface{} - GetOk(string) (interface{}, bool) - Put(string, interface{}) - Remove(string) - - Config() *triton.ClientConfig - - Client() interface{} - PutClient(interface{}) - - AppendError(error) - ErrorsOrNil() []error -} - -// TritonStateBag implements StateBag by using a normal map underneath -// protected by a RWMutex. -type basicTritonStateBag struct { - TritonConfig *triton.ClientConfig - TritonClient interface{} - - errors []error - data map[string]interface{} - - l sync.RWMutex - once sync.Once -} - -func (b *basicTritonStateBag) Config() *triton.ClientConfig { - b.l.RLock() - defer b.l.RUnlock() - - return b.TritonConfig -} - -func (b *basicTritonStateBag) Client() interface{} { - b.l.RLock() - defer b.l.RUnlock() - - return b.TritonClient -} - -func (b *basicTritonStateBag) PutClient(client interface{}) { - b.l.Lock() - defer b.l.Unlock() - - b.TritonClient = client -} - -func (b *basicTritonStateBag) AppendError(err error) { - b.l.Lock() - defer b.l.Unlock() - - if b.errors == nil { - b.errors = make([]error, 0, 1) - } - - b.errors = append(b.errors, err) -} - -func (b *basicTritonStateBag) ErrorsOrNil() []error { - b.l.RLock() - defer b.l.RUnlock() - - return b.errors -} - -func (b *basicTritonStateBag) Get(k string) interface{} { - result, _ := b.GetOk(k) - return result -} - -func (b *basicTritonStateBag) GetOk(k string) (interface{}, bool) { - b.l.RLock() - defer b.l.RUnlock() - - result, ok := b.data[k] - return result, ok -} - -func (b *basicTritonStateBag) Put(k string, v interface{}) { - b.l.Lock() - defer b.l.Unlock() - - // Make sure the map is initialized one time, on write - b.once.Do(func() { - b.data = make(map[string]interface{}) - }) - - // Write the data - b.data[k] = v -} - -func (b *basicTritonStateBag) Remove(k string) { - b.l.Lock() - defer b.l.Unlock() - - delete(b.data, k) -} diff --git a/vendor/github.com/joyent/triton-go/testutils/step.go b/vendor/github.com/joyent/triton-go/testutils/step.go deleted file mode 100644 index f004b86..0000000 --- a/vendor/github.com/joyent/triton-go/testutils/step.go +++ /dev/null @@ -1,19 +0,0 @@ -package testutils - -type StepAction uint - -const ( - Continue StepAction = iota - Halt -) - -const ( - StateCancelled = "cancelled" - StateHalted = "halted" -) - -type Step interface { - Run(TritonStateBag) StepAction - - Cleanup(TritonStateBag) -} diff --git a/vendor/github.com/joyent/triton-go/testutils/steps.go b/vendor/github.com/joyent/triton-go/testutils/steps.go deleted file mode 100644 index ee3b6d7..0000000 --- a/vendor/github.com/joyent/triton-go/testutils/steps.go +++ /dev/null @@ -1,214 +0,0 @@ -package testutils - -import ( - "errors" - "fmt" - "log" - "os" - "reflect" - - "github.com/abdullin/seq" - "github.com/hashicorp/errwrap" - triton "github.com/joyent/triton-go" - "github.com/joyent/triton-go/client" -) - -type StepClient struct { - StateBagKey string - ErrorKey string - CallFunc func(config *triton.ClientConfig) (interface{}, error) - CleanupFunc func(client interface{}, callState interface{}) -} - -func (s *StepClient) Run(state TritonStateBag) StepAction { - client, err := s.CallFunc(state.Config()) - if err != nil { - if s.ErrorKey == "" { - state.AppendError(err) - return Halt - } - - state.Put(s.ErrorKey, err) - return Continue - } - - state.PutClient(client) - return Continue -} - -func (s *StepClient) Cleanup(state TritonStateBag) { - return -} - -type StepAPICall struct { - StateBagKey string - ErrorKey string - CallFunc func(client interface{}) (interface{}, error) - CleanupFunc func(client interface{}, callState interface{}) -} - -func (s *StepAPICall) Run(state TritonStateBag) StepAction { - result, err := s.CallFunc(state.Client()) - if err != nil { - if s.ErrorKey == "" { - state.AppendError(err) - return Halt - } - - state.Put(s.ErrorKey, err) - return Continue - } - - state.Put(s.StateBagKey, result) - return Continue -} - -func (s *StepAPICall) Cleanup(state TritonStateBag) { - if s.CleanupFunc == nil { - return - } - - if callState, ok := state.GetOk(s.StateBagKey); ok { - s.CleanupFunc(state.Client(), callState) - } else { - log.Print("[INFO] No state for API call, calling cleanup with nil call state") - s.CleanupFunc(state.Client(), nil) - } -} - -type AssertFunc func(TritonStateBag) error - -type StepAssertFunc struct { - AssertFunc AssertFunc -} - -func (s *StepAssertFunc) Run(state TritonStateBag) StepAction { - if s.AssertFunc == nil { - state.AppendError(errors.New("StepAssertFunc may not have a nil AssertFunc")) - return Halt - } - - err := s.AssertFunc(state) - if err != nil { - state.AppendError(err) - return Halt - } - - return Continue -} - -func (s *StepAssertFunc) Cleanup(state TritonStateBag) { - return -} - -type StepAssert struct { - StateBagKey string - Assertions seq.Map -} - -func (s *StepAssert) Run(state TritonStateBag) StepAction { - actual, ok := state.GetOk(s.StateBagKey) - if !ok { - state.AppendError(fmt.Errorf("Key %q not found in state", s.StateBagKey)) - } - - for k, v := range s.Assertions { - path := fmt.Sprintf("%s.%s", s.StateBagKey, k) - if os.Getenv("TRITON_VERBOSE_TESTS") != "" { - log.Printf("[INFO] Asserting %q has value \"%v\"", path, v) - } else { - vPrefix := fmt.Sprintf("%v", v) - if len(vPrefix) > 15 { - vPrefix = fmt.Sprintf("%s...", vPrefix[:15]) - } - log.Printf("[INFO] Asserting %q has value \"%s\"", path, vPrefix) - } - } - - result := s.Assertions.Test(actual) - - if result.Ok() { - return Continue - } - - for _, v := range result.Issues { - err := fmt.Sprintf("Expected %q to be \"%v\" but got %q", - v.Path, - v.ExpectedValue, - v.ActualValue, - ) - state.AppendError(fmt.Errorf(err)) - } - - return Halt -} - -func (s *StepAssert) Cleanup(state TritonStateBag) { - return -} - -type StepAssertSet struct { - StateBagKey string - Keys []string -} - -func (s *StepAssertSet) Run(state TritonStateBag) StepAction { - actual, ok := state.GetOk(s.StateBagKey) - if !ok { - state.AppendError(fmt.Errorf("Key %q not found in state", s.StateBagKey)) - } - - var pass = true - for _, key := range s.Keys { - r := reflect.ValueOf(actual) - f := reflect.Indirect(r).FieldByName(key) - - log.Printf("[INFO] Asserting %q has a non-zero value", key) - if f.Interface() == reflect.Zero(reflect.TypeOf(f)).Interface() { - err := fmt.Sprintf("Expected %q to have a non-zero value", key) - state.AppendError(fmt.Errorf(err)) - pass = false - } - } - - if !pass { - return Halt - } - - return Continue -} - -func (s *StepAssertSet) Cleanup(state TritonStateBag) { - return -} - -type StepAssertTritonError struct { - ErrorKey string - Code string -} - -func (s *StepAssertTritonError) Run(state TritonStateBag) StepAction { - err, ok := state.GetOk(s.ErrorKey) - if !ok { - state.AppendError(fmt.Errorf("Expected TritonError %q to be in state", s.Code)) - return Halt - } - - tritonErrorInterface := errwrap.GetType(err.(error), &client.TritonError{}) - if tritonErrorInterface == nil { - state.AppendError(errors.New("Expected a TritonError in wrapped error chain")) - return Halt - } - - tritonErr := tritonErrorInterface.(*client.TritonError) - if tritonErr.Code == s.Code { - return Continue - } - - state.AppendError(fmt.Errorf("Expected TritonError code %q to be in state key %q, was %q", s.Code, s.ErrorKey, tritonErr.Code)) - return Halt -} - -func (s *StepAssertTritonError) Cleanup(state TritonStateBag) { - return -} diff --git a/vendor/github.com/joyent/triton-go/triton.go b/vendor/github.com/joyent/triton-go/triton.go deleted file mode 100644 index b5bacd2..0000000 --- a/vendor/github.com/joyent/triton-go/triton.go +++ /dev/null @@ -1,18 +0,0 @@ -package triton - -import ( - "github.com/joyent/triton-go/authentication" -) - -// Universal package used for defining configuration used across all client -// constructors. - -// ClientConfig is a placeholder/input struct around the behavior of configuring -// a client constructor through the implementation's runtime environment -// (SDC/MANTA env vars). -type ClientConfig struct { - TritonURL string - MantaURL string - AccountName string - Signers []authentication.Signer -}